Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1883 + Typescript Plugin Improvements #1986

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

Charlesnorris509
Copy link

Key changes include using arrow functions and template literals for cleaner syntax, and optional chaining to streamline property access where values may be undefined. Destructured assignments enhance readability, and constants are used for immutability where applicable. Additionally, inline comments clarify each change for easy reference, while error handling improvements ensure the code remains robust and clear. These changes collectively modernize the codebase while preserving its original functionality and use cases

Enhance Readability and Documentation, Type Aliases: Introduced type aliases. Increased Type Safety: Refined types for better accuracy, especially in callback signatures and function definitions.
The improved code includes updates for readability, maintainability, and modern JavaScript practices. Key changes include using arrow functions and template literals for cleaner syntax, and optional chaining to streamline property access where values may be undefined. Destructured assignments enhance readability, and constants are used for immutability where applicable. Additionally, inline comments clarify each change for easy reference, while error handling improvements ensure the code remains robust and clear. These changes collectively modernize the codebase while preserving its original functionality and use cases.
Spread Syntax in Function Arguments: Used (...args) to collect arguments in stdfn.SPRINTF for better readability and flexibility.
Template Literals and Arrow Functions: Simplified type-specific formatter functions with arrow functions for consistency and clarity.
@mathiasrw
Copy link
Member

I love it. Thank you!

Copy link
Member

@mathiasrw mathiasrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comments.

});
};

// Regular expression updated with comments for readability
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That comments?


stdfn.SPRINTF.H = (ins, x) => {
let cleanIns = String(ins).replace(/,/g, ''); // Remove commas for number parsing
x[2] = x[2] === '-' ? '+' : '-'; // Adjust alignment for string output
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that comment is correct?

@@ -1,21 +1,18 @@
/*
//
// CREATE VERTEX for AlaSQL
// Date: 21.04.2015
// (c) 2015, Andrey Gershun
// Date: 04/11/2024
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not change the date.

// Date: 21.04.2015
// (c) 2015, Andrey Gershun
// Date: 04/11/2024
// (c) 2015, Andrey Gershu
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please dont change the surname of the author...

yy.CreateVertex = function (params) {
return Object.assign(this, params);
};
yy.CreateVertex = (params) => Object.assign(this, params); // Updated to arrow function
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please dont leave comments like this as it will not make sense in the future

// todo: SET
// todo: CONTENT
// todo: SELECT
// Future TODOs: SET, CONTENT, SELECT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the original comments please

var s = 'this.queriesfn[' + (this.queriesidx - 1) + '](this.params,null,' + context + ')';
return s;
yy.CreateEdge.prototype.toJS = (context) => {
return `this.queriesfn[${this.queriesidx - 1}](this.params,null,${context})`; // Template literal for consistency
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove comment


// Optional functions
namefn?.(edge);
namefn?.(edge); // Optional chaining
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove comment

@@ -196,7 +157,7 @@ yy.CreateGraph.prototype.execute = function (databaseid, params, cb) {
if (g.class !== undefined) e.$class = g.class;

let db = alasql.databases[databaseid];
e.$id = e.$id !== undefined ? e.$id : db.counter++;
e.$id = e.$id ?? db.counter++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

}
}
return undefined;
return Object.values(alasql.databases[alasql.useid].objects).find((obj) => obj.name === name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We simply cant be making copies of all the data in an object for operations like this. We need to keep the original or find a way where we can search the original object without making a copy.

Copy link
Member

@mathiasrw mathiasrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comments.

Copy link
Member

@mathiasrw mathiasrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need comments to be related to what the code does (if needed at all) - not why something was changed.

if (typeof g.json !== 'undefined') {
extend(v, new Function('params,alasql', 'var y;return ' + g.json.toJS())(params, alasql));
const db = alasql.databases[databaseid];
const v = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many changes. And I dont feel like this will provide the same result. where. is the .prop aspect?

res.push(v.$id);
return v;
}
};
yy.CreateGraph.prototype.compile1 = function (databaseid) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we just remove all of this?!?

yy.CreateDatabase = function (params) {
return Object.assign(this, params);
};
yy.CreateDatabase = (params) => Object.assign(this, params); // Updated to arrow function
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep regular functions for high level so they remain informative in the stack trace

yy.CreateDatabase.prototype.toString = function () {
let s = 'CREATE '; // Ensure there's a space after CREATE
let s = 'CREATE '; // Added space after 'CREATE' for clarity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert comment

if (this.engineid) s += `${this.engineid} `;
s += 'DATABASE ';
if (this.ifnotexists) s += 'IF NOT EXISTS ';
s += `${this.databaseid} `;

if (this.args && this.args.length > 0) {
if (this.args?.length) { // Optional chaining for args presence check
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove comment

*
* @type {tableLookUp}
* @memberof database
* Collection of tables in the database.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this comment updated?

*
* @type {any[]}
* @memberof table
* Array of data rows within the table.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No value in the old comment?

*
* @type {databaseLookUp}
* @memberof AlaSQL
* Dictionary of databases managed by AlaSQL.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not the type notation?

* Equivalent to alasql('USE '+databaseid). This will change the current
* database to the one specified. This will update the useid property and
* the tables property.
* Switches the current database context.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the context of the old comment

*
* @type {string}
* @memberof AlaSQL
* Current active database ID. Defaults to 'alasql' if none specified.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the type notation

@mathiasrw
Copy link
Member

Looks like the tests are not running. Please make sure to do a yarn format and then yarn test locally before you make a PR

@mathiasrw
Copy link
Member

@Charlesnorris509 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants