From ec19a2de8abe24373b0883bad0f32ce7996b3e0d Mon Sep 17 00:00:00 2001 From: zdm Date: Wed, 24 Jan 2024 12:50:17 +0200 Subject: [PATCH] fix: linted --- build/lib/sqlite.js | 8 +++---- lib/database.js | 4 ++-- lib/methods/aggregate.js | 8 +++---- lib/methods/backup.js | 2 +- lib/methods/function.js | 2 +- lib/methods/pragma.js | 2 +- lib/methods/serialize.js | 2 +- lib/methods/table.js | 48 +++++++++++++++++++------------------- lib/methods/transaction.js | 2 +- lib/methods/wrappers.js | 22 ++++++++--------- lib/util.js | 4 ++-- 11 files changed, 52 insertions(+), 52 deletions(-) diff --git a/build/lib/sqlite.js b/build/lib/sqlite.js index b13f6e0..2e4c851 100644 --- a/build/lib/sqlite.js +++ b/build/lib/sqlite.js @@ -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; @@ -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 ); } @@ -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 ); diff --git a/lib/database.js b/lib/database.js index 6167892..e0e8801 100644 --- a/lib/database.js +++ b/lib/database.js @@ -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, } ); } @@ -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; diff --git a/lib/methods/aggregate.js b/lib/methods/aggregate.js index e86c6b5..f61a3a1 100644 --- a/lib/methods/aggregate.js +++ b/lib/methods/aggregate.js @@ -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; }; diff --git a/lib/methods/backup.js b/lib/methods/backup.js index e48160c..cb61272 100644 --- a/lib/methods/backup.js +++ b/lib/methods/backup.js @@ -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 ) => { diff --git a/lib/methods/function.js b/lib/methods/function.js index 7259cb1..b01a89f 100644 --- a/lib/methods/function.js +++ b/lib/methods/function.js @@ -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; } diff --git a/lib/methods/pragma.js b/lib/methods/pragma.js index 6061b4d..33bbf53 100644 --- a/lib/methods/pragma.js +++ b/lib/methods/pragma.js @@ -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(); } diff --git a/lib/methods/serialize.js b/lib/methods/serialize.js index 6ee473e..a9925a2 100644 --- a/lib/methods/serialize.js +++ b/lib/methods/serialize.js @@ -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 ); } diff --git a/lib/methods/table.js b/lib/methods/table.js index c2af063..e2c8357 100644 --- a/lib/methods/table.js +++ b/lib/methods/table.js @@ -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; } @@ -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 ); @@ -43,28 +43,28 @@ 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 @@ -72,21 +72,21 @@ function parseTableDefinition ( def, verb, moduleName ) { 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` ); } } @@ -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; } @@ -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 ) { @@ -137,7 +137,7 @@ 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` ); } } }; @@ -145,11 +145,11 @@ function wrapGenerator ( generator, columnMap, moduleName ) { 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 ]; } } @@ -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` ); } } @@ -174,7 +174,7 @@ function inferParameters ( { length } ) { } const params = []; for ( let i = 0; i < length; ++i ) { - params.push( `$${i + 1}` ); + params.push( `$${ i + 1 }` ); } return params; } @@ -182,5 +182,5 @@ function inferParameters ( { length } ) { 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; diff --git a/lib/methods/transaction.js b/lib/methods/transaction.js index 19f9938..20ba27d 100644 --- a/lib/methods/transaction.js +++ b/lib/methods/transaction.js @@ -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; diff --git a/lib/methods/wrappers.js b/lib/methods/wrappers.js index 06c1465..6c16eba 100644 --- a/lib/methods/wrappers.js +++ b/lib/methods/wrappers.js @@ -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, }, diff --git a/lib/util.js b/lib/util.js index 09d3a70..dc399bc 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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; }