diff --git a/packages/kysely-driver/tsconfig.json b/packages/kysely-driver/tsconfig.json index 44dd2dfd..c902b0ed 100644 --- a/packages/kysely-driver/tsconfig.json +++ b/packages/kysely-driver/tsconfig.json @@ -5,11 +5,7 @@ "declaration": true /* Generates corresponding '.d.ts' file. */, "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, - "lib": [ - "DOM", - "ES2020", - "WebWorker" - ] /* Specify library files to be included in the compilation. */, + "lib": ["DOM", "ES2020", "WebWorker"] /* Specify library files to be included in the compilation. */, "module": "es2020" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, "outDir": "./lib" /* Redirect output structure to the directory. */, @@ -18,7 +14,10 @@ "strict": true /* Enable all strict type-checking options. */, "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ }, - "include": [ - "src/**/*", + "include": ["src/**/*"], + "references": [ + { + "path": "../powersync-sdk-common" + } ] } diff --git a/packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts b/packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts index 849fcd11..b1ac652c 100644 --- a/packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts +++ b/packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts @@ -114,7 +114,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver { + async getNextCrudTransaction(): Promise { return await this.readTransaction(async (tx) => { const first = await tx.getOptional( `SELECT id, tx_id, data FROM ${PSInternalTable.CRUD} ORDER BY id ASC LIMIT 1` @@ -543,7 +543,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver(`EXPLAIN ${sql}`, parameters); const rootPages = _.chain(explained) .filter((row) => row['opcode'] == 'OpenRead' && row['p3'] == 0 && _.isNumber(row['p2'])) .map((row) => row['p2']) @@ -571,10 +571,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver { - const watchedTables = options.tables ?? []; + const resolvedOptions = options ?? {}; + const watchedTables = resolvedOptions.tables ?? []; let throttledTableUpdates: string[] = []; - const throttleMs = options.throttleMs ?? DEFAULT_WATCH_THROTTLE_MS; + const throttleMs = resolvedOptions.throttleMs ?? DEFAULT_WATCH_THROTTLE_MS; return new EventIterator((eventOptions) => { const flushTableUpdates = _.throttle( @@ -593,7 +594,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver { - const { rawTableNames } = options; + const { rawTableNames } = resolvedOptions; const tables = isBatchedUpdateNotification(update) ? update.tables : [update.table]; @@ -613,7 +614,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver { + resolvedOptions.signal?.addEventListener('abort', () => { dispose(); eventOptions.stop(); // Maybe fail? @@ -626,7 +627,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver tx.execute(sql, params)); } diff --git a/packages/powersync-sdk-common/src/client/AbstractPowerSyncOpenFactory.ts b/packages/powersync-sdk-common/src/client/AbstractPowerSyncOpenFactory.ts index 2273605e..0e7135db 100644 --- a/packages/powersync-sdk-common/src/client/AbstractPowerSyncOpenFactory.ts +++ b/packages/powersync-sdk-common/src/client/AbstractPowerSyncOpenFactory.ts @@ -33,7 +33,6 @@ export abstract class AbstractPowerSyncDatabaseOpenFactory { generateOptions(): PowerSyncDatabaseOptions { return { database: this.openDB(), - schema: this.schema, ...this.options }; } diff --git a/packages/powersync-sdk-common/src/client/sync/bucket/CrudEntry.ts b/packages/powersync-sdk-common/src/client/sync/bucket/CrudEntry.ts index 3f8efdc2..64ef48ea 100644 --- a/packages/powersync-sdk-common/src/client/sync/bucket/CrudEntry.ts +++ b/packages/powersync-sdk-common/src/client/sync/bucket/CrudEntry.ts @@ -33,7 +33,7 @@ export type CrudEntryDataJSON = { }; /** - * The output JSOn seems to be a third type of JSON, not the same as the input JSON. + * The output JSON seems to be a third type of JSON, not the same as the input JSON. */ export type CrudEntryOutputJSON = { op_id: number; @@ -41,7 +41,7 @@ export type CrudEntryOutputJSON = { type: string; id: string; tx_id?: number; - data: Record; + data?: Record; }; /** diff --git a/packages/powersync-sdk-common/src/client/sync/bucket/SyncDataBucket.ts b/packages/powersync-sdk-common/src/client/sync/bucket/SyncDataBucket.ts index 5f6a9c7b..06e5b9fb 100644 --- a/packages/powersync-sdk-common/src/client/sync/bucket/SyncDataBucket.ts +++ b/packages/powersync-sdk-common/src/client/sync/bucket/SyncDataBucket.ts @@ -16,7 +16,7 @@ export class SyncDataBucket { return new SyncDataBucket( row.bucket, row.data.map((entry) => OplogEntry.fromRow(entry)), - row.has_more, + row.has_more ?? false, row.after, row.next_after ); diff --git a/packages/powersync-sdk-common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts b/packages/powersync-sdk-common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts index b5edd2bd..61afabb7 100644 --- a/packages/powersync-sdk-common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +++ b/packages/powersync-sdk-common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts @@ -46,7 +46,7 @@ export interface AbstractStreamingSyncImplementationOptions { } export interface StreamingSyncImplementationListener extends BaseListener { - statusChanged?: (status: SyncStatus) => void; + statusChanged?: ((status: SyncStatus) => void) | undefined; } export const DEFAULT_CRUD_UPLOAD_THROTTLE_MS = 1000; @@ -69,7 +69,7 @@ export abstract class AbstractStreamingSyncImplementation extends BaseObserver { + async *streamingSyncRequest(req: StreamingSyncRequest, signal?: AbortSignal): AsyncGenerator { const body = await this.options.remote.postStreaming('/sync/stream', req, {}, signal); const stream = ndjsonStream(body); const reader = stream.getReader(); diff --git a/packages/powersync-sdk-common/src/db/crud/SyncStatus.ts b/packages/powersync-sdk-common/src/db/crud/SyncStatus.ts index 49047503..f81d91b2 100644 --- a/packages/powersync-sdk-common/src/db/crud/SyncStatus.ts +++ b/packages/powersync-sdk-common/src/db/crud/SyncStatus.ts @@ -53,7 +53,7 @@ export class SyncStatus { } getMessage() { - const { dataFlow } = this.options; + const dataFlow = this.dataFlowStatus; return `SyncStatus { } export type BaseListener = { - [key: string]: (...event: any) => any; + [key: string]: ((...event: any) => any) | undefined; }; export class BaseObserver implements BaseObserverInterface { diff --git a/packages/powersync-sdk-common/src/utils/mutex.ts b/packages/powersync-sdk-common/src/utils/mutex.ts index 57b7226e..d1a06064 100644 --- a/packages/powersync-sdk-common/src/utils/mutex.ts +++ b/packages/powersync-sdk-common/src/utils/mutex.ts @@ -16,10 +16,12 @@ export async function mutexRunExclusive( timedOut = true; reject(new Error('Timeout waiting for lock')); }, timeout) - : null; + : undefined; mutex.runExclusive(async () => { - clearTimeout(timeoutId); + if (timeoutId) { + clearTimeout(timeoutId); + } if (timedOut) return; try { diff --git a/packages/powersync-sdk-common/tsconfig.json b/packages/powersync-sdk-common/tsconfig.json index fa91ee71..3f9b79e0 100644 --- a/packages/powersync-sdk-common/tsconfig.json +++ b/packages/powersync-sdk-common/tsconfig.json @@ -18,7 +18,8 @@ "noStrictGenericChecks": false, "resolveJsonModule": true, "skipLibCheck": true, - "target": "esnext" + "target": "esnext", + "strictNullChecks": true }, "include": ["src/**/*"] } diff --git a/packages/powersync-sdk-react-native/src/sync/stream/ReactNativeRemote.ts b/packages/powersync-sdk-react-native/src/sync/stream/ReactNativeRemote.ts index 1aeb626e..34b03e2a 100644 --- a/packages/powersync-sdk-react-native/src/sync/stream/ReactNativeRemote.ts +++ b/packages/powersync-sdk-react-native/src/sync/stream/ReactNativeRemote.ts @@ -90,7 +90,9 @@ export class ReactNativeRemote extends AbstractRemote { throw ex; }); - clearTimeout(timeout); + if (timeout != null) { + clearTimeout(timeout); + } if (!res.ok) { const text = await res.text(); @@ -108,7 +110,7 @@ export class ReactNativeRemote extends AbstractRemote { * The common SDK is a bit oblivious to `ReadableStream` classes. * This should be improved when moving to Websockets */ - const reader = res.body.getReader(); + const reader = res.body!.getReader(); const outputStream = new ReadableStream({ start(controller) { return processStream(); diff --git a/packages/powersync-sdk-react-native/src/sync/stream/ReactNativeStreamingSyncImplementation.ts b/packages/powersync-sdk-react-native/src/sync/stream/ReactNativeStreamingSyncImplementation.ts index 55eafaae..caa60d28 100644 --- a/packages/powersync-sdk-react-native/src/sync/stream/ReactNativeStreamingSyncImplementation.ts +++ b/packages/powersync-sdk-react-native/src/sync/stream/ReactNativeStreamingSyncImplementation.ts @@ -26,7 +26,7 @@ export class ReactNativeStreamingSyncImplementation extends AbstractStreamingSyn initLocks() { const { identifier } = this.options; if (identifier && LOCKS.has(identifier)) { - this.locks = LOCKS.get(identifier); + this.locks = LOCKS.get(identifier)!; return; } @@ -46,7 +46,7 @@ export class ReactNativeStreamingSyncImplementation extends AbstractStreamingSyn } return lock.acquire(lockOptions.type, async () => { if (lockOptions.signal?.aborted) { - return null; + throw new Error('Aborted'); } return lockOptions.callback(); diff --git a/packages/powersync-sdk-react-native/tsconfig.json b/packages/powersync-sdk-react-native/tsconfig.json index 098a75f4..f9151e9f 100644 --- a/packages/powersync-sdk-react-native/tsconfig.json +++ b/packages/powersync-sdk-react-native/tsconfig.json @@ -16,7 +16,8 @@ "noStrictGenericChecks": false, "resolveJsonModule": true, "skipLibCheck": true, - "target": "esnext" + "target": "esnext", + "strictNullChecks": true }, "references": [ { diff --git a/packages/powersync-sdk-web/tsconfig.json b/packages/powersync-sdk-web/tsconfig.json index 09f01794..40e6c558 100644 --- a/packages/powersync-sdk-web/tsconfig.json +++ b/packages/powersync-sdk-web/tsconfig.json @@ -15,7 +15,8 @@ "skipLibCheck": true /* Skip type checking of declaration files. */, "sourceMap": true /* Generates corresponding '.map' file. */, "strict": true /* Enable all strict type-checking options. */, - "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, + "strictNullChecks": true }, "include": ["src/**/*", "tests/**/*"] }