Skip to content

Commit

Permalink
fix: linted
Browse files Browse the repository at this point in the history
  • Loading branch information
zdm committed Jan 24, 2024
1 parent b5296aa commit ec19a2d
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 52 deletions.
8 changes: 4 additions & 4 deletions build/lib/sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const USE_LATEST_SQLITE = true,
SQLITE_VERSION.split( "." )
.map( ( label, idx ) => ( !idx ? label : label.padStart( 2, "0" ) ) )
.join( "" ) + "00",
SQLITE_URL = `https://www.sqlite.org/${SQLITE_YEAR}/sqlite-amalgamation-${SQLITE_PRODUCT_VERSION}.zip`;
SQLITE_URL = `https://www.sqlite.org/${ SQLITE_YEAR }/sqlite-amalgamation-${ SQLITE_PRODUCT_VERSION }.zip`;

export default class ExternalResource extends ExternalResourceBuilder {
#cwd;
Expand Down Expand Up @@ -69,7 +69,7 @@ export default class ExternalResource extends ExternalResourceBuilder {

if ( !files.length ) return result( 500 );

fs.copyFileSync( this.#cwd + "/" + files[0], location + "/sqlite.node" );
fs.copyFileSync( this.#cwd + "/" + files[ 0 ], location + "/sqlite.node" );

return result( 200 );
}
Expand Down Expand Up @@ -99,13 +99,13 @@ export default class ExternalResource extends ExternalResourceBuilder {

this.#sqliteVersion =
"v" +
match[2]
match[ 2 ]
.split( /(\d)(\d\d)(\d\d)/ )
.slice( 1, 4 )
.map( label => +label )
.join( "." );

this.#sqliteUrl = "https://www.sqlite.org/" + match[1];
this.#sqliteUrl = "https://www.sqlite.org/" + match[ 1 ];
}

return result( 200 );
Expand Down
4 changes: 2 additions & 2 deletions lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function Database ( filenameGiven, options ) {
// }

Object.defineProperties( this, {
[util.cppdb]: { "value": new addon.Database( filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null ) },
[ util.cppdb ]: { "value": new addon.Database( filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null ) },
...wrappers.getters,
} );
}
Expand All @@ -98,6 +98,6 @@ Database.prototype.exec = wrappers.exec;
Database.prototype.close = wrappers.close;
Database.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
Database.prototype.unsafeMode = wrappers.unsafeMode;
Database.prototype[util.inspect] = inspect;
Database.prototype[ util.inspect ] = inspect;

export default Database;
8 changes: 4 additions & 4 deletions lib/methods/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export default function defineAggregate ( name, options ) {
if ( argCount > 100 ) throw new RangeError( "User-defined functions cannot have more than 100 arguments" );
}

this[cppdb].aggregate( start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly );
this[ cppdb ].aggregate( start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly );
return this;
}

const getFunctionOption = ( options, key, required ) => {
const value = key in options ? options[key] : null;
const value = key in options ? options[ key ] : null;
if ( typeof value === "function" ) return value;
if ( value != null ) throw new TypeError( `Expected the "${key}" option to be a function` );
if ( required ) throw new TypeError( `Missing required option "${key}"` );
if ( value != null ) throw new TypeError( `Expected the "${ key }" option to be a function` );
if ( required ) throw new TypeError( `Missing required option "${ key }"` );
return null;
};

Expand Down
2 changes: 1 addition & 1 deletion lib/methods/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default async function backup ( filename, options ) {
() => false,
() => true
);
return runBackup( this[cppdb].backup( this, attachedName, filename, isNewFile ), handler || null );
return runBackup( this[ cppdb ].backup( this, attachedName, filename, isNewFile ), handler || null );
}

const runBackup = ( backup, handler ) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/methods/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ export default function defineFunction ( name, options, fn ) {
if ( argCount > 100 ) throw new RangeError( "User-defined functions cannot have more than 100 arguments" );
}

this[cppdb].function( fn, name, argCount, safeIntegers, deterministic, directOnly );
this[ cppdb ].function( fn, name, argCount, safeIntegers, deterministic, directOnly );
return this;
}
2 changes: 1 addition & 1 deletion lib/methods/pragma.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export default function pragma ( source, options ) {
if ( typeof options !== "object" ) throw new TypeError( "Expected second argument to be an options object" );
const simple = getBooleanOption( options, "simple" );

const stmt = this[cppdb].prepare( `PRAGMA ${source}`, this, true );
const stmt = this[ cppdb ].prepare( `PRAGMA ${ source }`, this, true );
return simple ? stmt.pluck().get() : stmt.all();
}
2 changes: 1 addition & 1 deletion lib/methods/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export default function serialize ( options ) {
if ( typeof attachedName !== "string" ) throw new TypeError( 'Expected the "attached" option to be a string' );
if ( !attachedName ) throw new TypeError( 'The "attached" option cannot be an empty string' );

return this[cppdb].serialize( attachedName );
return this[ cppdb ].serialize( attachedName );
}
48 changes: 24 additions & 24 deletions lib/methods/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function defineTable ( name, factory ) {
factory = wrapFactory( factory );
}

this[cppdb].table( factory, name, eponymous );
this[ cppdb ].table( factory, name, eponymous );
return this;
}

Expand All @@ -32,7 +32,7 @@ function wrapFactory ( factory ) {
// Generate a new table definition by invoking the factory
const def = apply.call( factory, thisObject, args );
if ( typeof def !== "object" || def === null ) {
throw new TypeError( `Virtual table module "${moduleName}" did not return a table definition object` );
throw new TypeError( `Virtual table module "${ moduleName }" did not return a table definition object` );
}

return parseTableDefinition( def, "returned", moduleName );
Expand All @@ -43,50 +43,50 @@ function parseTableDefinition ( def, verb, moduleName ) {

// Validate required properties
if ( !hasOwnProperty.call( def, "rows" ) ) {
throw new TypeError( `Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property` );
throw new TypeError( `Virtual table module "${ moduleName }" ${ verb } a table definition without a "rows" property` );
}
if ( !hasOwnProperty.call( def, "columns" ) ) {
throw new TypeError( `Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property` );
throw new TypeError( `Virtual table module "${ moduleName }" ${ verb } a table definition without a "columns" property` );
}

// Validate "rows" property
const rows = def.rows;
if ( typeof rows !== "function" || Object.getPrototypeOf( rows ) !== GeneratorFunctionPrototype ) {
throw new TypeError( `Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)` );
throw new TypeError( `Virtual table module "${ moduleName }" ${ verb } a table definition with an invalid "rows" property (should be a generator function)` );
}

// Validate "columns" property
let columns = def.columns;
if ( !Array.isArray( columns ) || !( columns = [ ...columns ] ).every( x => typeof x === "string" ) ) {
throw new TypeError( `Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)` );
throw new TypeError( `Virtual table module "${ moduleName }" ${ verb } a table definition with an invalid "columns" property (should be an array of strings)` );
}
if ( columns.length !== new Set( columns ).size ) {
throw new TypeError( `Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names` );
throw new TypeError( `Virtual table module "${ moduleName }" ${ verb } a table definition with duplicate column names` );
}
if ( !columns.length ) {
throw new RangeError( `Virtual table module "${moduleName}" ${verb} a table definition with zero columns` );
throw new RangeError( `Virtual table module "${ moduleName }" ${ verb } a table definition with zero columns` );
}

// Validate "parameters" property
let parameters;
if ( hasOwnProperty.call( def, "parameters" ) ) {
parameters = def.parameters;
if ( !Array.isArray( parameters ) || !( parameters = [ ...parameters ] ).every( x => typeof x === "string" ) ) {
throw new TypeError( `Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)` );
throw new TypeError( `Virtual table module "${ moduleName }" ${ verb } a table definition with an invalid "parameters" property (should be an array of strings)` );
}
}
else {
parameters = inferParameters( rows );
}
if ( parameters.length !== new Set( parameters ).size ) {
throw new TypeError( `Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names` );
throw new TypeError( `Virtual table module "${ moduleName }" ${ verb } a table definition with duplicate parameter names` );
}
if ( parameters.length > 32 ) {
throw new RangeError( `Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters` );
throw new RangeError( `Virtual table module "${ moduleName }" ${ verb } a table definition with more than the maximum number of 32 parameters` );
}
for ( const parameter of parameters ) {
if ( columns.includes( parameter ) ) {
throw new TypeError( `Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter` );
throw new TypeError( `Virtual table module "${ moduleName }" ${ verb } a table definition with column "${ parameter }" which was ambiguously defined as both a column and parameter` );
}
}

Expand All @@ -95,7 +95,7 @@ function parseTableDefinition ( def, verb, moduleName ) {
if ( hasOwnProperty.call( def, "safeIntegers" ) ) {
const bool = def.safeIntegers;
if ( typeof bool !== "boolean" ) {
throw new TypeError( `Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)` );
throw new TypeError( `Virtual table module "${ moduleName }" ${ verb } a table definition with an invalid "safeIntegers" property (should be a boolean)` );
}
safeIntegers = +bool;
}
Expand All @@ -105,13 +105,13 @@ function parseTableDefinition ( def, verb, moduleName ) {
if ( hasOwnProperty.call( def, "directOnly" ) ) {
directOnly = def.directOnly;
if ( typeof directOnly !== "boolean" ) {
throw new TypeError( `Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)` );
throw new TypeError( `Virtual table module "${ moduleName }" ${ verb } a table definition with an invalid "directOnly" property (should be a boolean)` );
}
}

// Generate SQL for the virtual table definition
const columnDefinitions = [ ...parameters.map( identifier ).map( str => `${str} HIDDEN` ), ...columns.map( identifier ) ];
return [ `CREATE TABLE x(${columnDefinitions.join( ", " )});`, wrapGenerator( rows, new Map( columns.map( ( x, i ) => [ x, parameters.length + i ] ) ), moduleName ), parameters, safeIntegers, directOnly ];
const columnDefinitions = [ ...parameters.map( identifier ).map( str => `${ str } HIDDEN` ), ...columns.map( identifier ) ];
return [ `CREATE TABLE x(${ columnDefinitions.join( ", " ) });`, wrapGenerator( rows, new Map( columns.map( ( x, i ) => [ x, parameters.length + i ] ) ), moduleName ), parameters, safeIntegers, directOnly ];
}

function wrapGenerator ( generator, columnMap, moduleName ) {
Expand All @@ -137,19 +137,19 @@ function wrapGenerator ( generator, columnMap, moduleName ) {
yield output;
}
else {
throw new TypeError( `Virtual table module "${moduleName}" yielded something that isn't a valid row object` );
throw new TypeError( `Virtual table module "${ moduleName }" yielded something that isn't a valid row object` );
}
}
};
}

function extractRowArray ( row, output, columnCount, moduleName ) {
if ( row.length !== columnCount ) {
throw new TypeError( `Virtual table module "${moduleName}" yielded a row with an incorrect number of columns` );
throw new TypeError( `Virtual table module "${ moduleName }" yielded a row with an incorrect number of columns` );
}
const offset = output.length - columnCount;
for ( let i = 0; i < columnCount; ++i ) {
output[i + offset] = row[i];
output[ i + offset ] = row[ i ];
}
}

Expand All @@ -158,13 +158,13 @@ function extractRowObject ( row, output, columnMap, moduleName ) {
for ( const key of Object.keys( row ) ) {
const index = columnMap.get( key );
if ( index === undefined ) {
throw new TypeError( `Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"` );
throw new TypeError( `Virtual table module "${ moduleName }" yielded a row with an undeclared column "${ key }"` );
}
output[index] = row[key];
output[ index ] = row[ key ];
count += 1;
}
if ( count !== columnMap.size ) {
throw new TypeError( `Virtual table module "${moduleName}" yielded a row with missing columns` );
throw new TypeError( `Virtual table module "${ moduleName }" yielded a row with missing columns` );
}
}

Expand All @@ -174,13 +174,13 @@ function inferParameters ( { length } ) {
}
const params = [];
for ( let i = 0; i < length; ++i ) {
params.push( `$${i + 1}` );
params.push( `$${ i + 1 }` );
}
return params;
}

const { hasOwnProperty } = Object.prototype;
const { apply } = Function.prototype;
const GeneratorFunctionPrototype = Object.getPrototypeOf( function* () {} );
const identifier = str => `"${str.replace( /"/g, '""' )}"`;
const identifier = str => `"${ str.replace( /"/g, '""' ) }"`;
const defer = x => () => x;
2 changes: 1 addition & 1 deletion lib/methods/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const controllers = new WeakMap();
export default function transaction ( fn ) {
if ( typeof fn !== "function" ) throw new TypeError( "Expected first argument to be a function" );

const db = this[cppdb];
const db = this[ cppdb ];
const controller = getController( db, this );
const { apply } = Function.prototype;

Expand Down
22 changes: 11 additions & 11 deletions lib/methods/wrappers.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
import { cppdb } from "#lib/util";

export function prepare ( sql ) {
return this[cppdb].prepare( sql, this, false );
return this[ cppdb ].prepare( sql, this, false );
}

export function exec ( sql ) {
this[cppdb].exec( sql );
this[ cppdb ].exec( sql );
return this;
}

export function close () {
this[cppdb].close();
this[ cppdb ].close();
return this;
}

export function loadExtension ( ...args ) {
this[cppdb].loadExtension( ...args );
this[ cppdb ].loadExtension( ...args );
return this;
}

export function defaultSafeIntegers ( ...args ) {
this[cppdb].defaultSafeIntegers( ...args );
this[ cppdb ].defaultSafeIntegers( ...args );
return this;
}

export function unsafeMode ( ...args ) {
this[cppdb].unsafeMode( ...args );
this[ cppdb ].unsafeMode( ...args );
return this;
}

export const getters = {
"name": {
"get": function name () {
return this[cppdb].name;
return this[ cppdb ].name;
},
"enumerable": true,
},
"open": {
"get": function open () {
return this[cppdb].open;
return this[ cppdb ].open;
},
"enumerable": true,
},
"inTransaction": {
"get": function inTransaction () {
return this[cppdb].inTransaction;
return this[ cppdb ].inTransaction;
},
"enumerable": true,
},
"readonly": {
"get": function readonly () {
return this[cppdb].readonly;
return this[ cppdb ].readonly;
},
"enumerable": true,
},
"memory": {
"get": function memory () {
return this[cppdb].memory;
return this[ cppdb ].memory;
},
"enumerable": true,
},
Expand Down
4 changes: 2 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function getBooleanOption ( options, key ) {
let value = false;
if ( key in options && typeof ( value = options[key] ) !== "boolean" ) {
throw new TypeError( `Expected the "${key}" option to be a boolean` );
if ( key in options && typeof ( value = options[ key ] ) !== "boolean" ) {
throw new TypeError( `Expected the "${ key }" option to be a boolean` );
}
return value;
}
Expand Down

0 comments on commit ec19a2d

Please sign in to comment.