Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build-packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ jobs:

- name: Build (prod)
run: pnpm build:packages:prod

- name: Build typescript
run: pnpm exec tsc -b
1 change: 0 additions & 1 deletion demos/example-capacitor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"noImplicitAny": true,
"strict": true,
"sourceMap": true,
"baseUrl": ".",
"outDir": "dist",
"moduleResolution": "NodeNext",
"resolveJsonModule": true,
Expand Down
1 change: 0 additions & 1 deletion demos/example-electron-node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"skipLibCheck": true,
"noImplicitAny": true,
"sourceMap": true,
"baseUrl": ".",
"outDir": "dist",
"moduleResolution": "bundler",
"paths": {
Expand Down
1 change: 0 additions & 1 deletion demos/example-electron/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"noImplicitAny": true,
"strict": true,
"sourceMap": true,
"baseUrl": ".",
"outDir": "dist",
"moduleResolution": "NodeNext",
"resolveJsonModule": true,
Expand Down
1 change: 0 additions & 1 deletion demos/example-node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
"outDir": "lib",
"strictNullChecks": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
DBAdapter,
PowerSyncDatabase,
PowerSyncDBListener,
Transaction,
WebPowerSyncDatabaseOptions,
PowerSyncBackendConnector
PowerSyncBackendConnector,
LockContext
} from '@powersync/web';

export enum OperationType {
Expand Down Expand Up @@ -68,11 +68,11 @@ export class TimedPowerSyncDatabase extends PowerSyncDatabase {
return this.timedOperation(OperationType.WRITE_TX, () => super.writeTransaction<T>(callback, lockTimeout));
}

async readLock<T>(callback: (db: DBAdapter) => Promise<T>) {
async readLock<T>(callback: (db: LockContext) => Promise<T>) {
return this.timedOperation(OperationType.READ, () => super.readLock<T>(callback));
}

async writeLock<T>(callback: (db: DBAdapter) => Promise<T>) {
async writeLock<T>(callback: (db: LockContext) => Promise<T>) {
return this.timedOperation(OperationType.WRITE, () => super.writeLock<T>(callback));
}

Expand Down
1 change: 0 additions & 1 deletion demos/react-native-supabase-group-chat/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true,
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
Expand Down
1 change: 0 additions & 1 deletion demos/tauri-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"noEmit": true,
"jsx": "react-jsx",
"strict": true,
"baseUrl": ".",
},
"include": ["src"]
}
1 change: 0 additions & 1 deletion demos/vue-supabase-todolist/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"baseUrl": ".",
/* Bundler mode */
"moduleResolution": "bundler",
"paths": {
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"docusaurus-plugin-typedoc": "^1.2.1",
"typedoc": "~0.27.6",
"typedoc-plugin-markdown": "~4.4.1",
"typescript": "^5.5.3"
"typescript": "catalog:"
},
"browserslist": {
"production": [
Expand Down
1 change: 0 additions & 1 deletion docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
// This file is not used in compilation. It is here just for a nice editor experience.
"extends": "@docusaurus/tsconfig",
"compilerOptions": {
"baseUrl": "."
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"build:packages:prod": "pnpm run --filter {./packages/**} -r build:prod",
"clean:packages": "pnpm run --filter {./packages/**} -r clean",
"watch:packages": "pnpm run --parallel --filter {./packages/**} -r build -w",
"watch:ts": "tsc -b -w --preserveWatchOutput",
"changeset:version": "pnpm changeset version && pnpm demos:update --all && pnpm install --lockfile-only --frozen-lockfile=false && pnpm -r postversion",
"build": "pnpm run -r build",
"ci:publish": "changeset publish && git push --follow-tags",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-sql-js/src/SQLJSAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class SqlJsConnectionPool extends BaseObserver<DBAdapterListener> implements Con
});
const existing = await this.options.persister?.readFile();
const db = new SQL.Database(existing);
this.dbP = db['db'];
this.dbP = (db as any)['db'] as number;
this._db = db;
return db;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/adapter-sql-js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.base",
"compilerOptions": {
"baseUrl": "./",
"jsx": "react",
"types": ["node"],
"rootDir": "src",
Expand All @@ -11,9 +10,13 @@
"module": "NodeNext",
"moduleResolution": "nodenext",
"preserveConstEnums": true,
"esModuleInterop": false,
"skipLibCheck": false,
"strictNullChecks": true
},
"references": [
{
"path": "../common"
}
],
"include": ["src/**/*"]
}
2 changes: 1 addition & 1 deletion packages/attachments-storage-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"expo-file-system": "^19.0.21",
"rollup": "4.14.3",
"rollup-plugin-dts": "^6.1.0",
"typescript": "^5.5.0"
"typescript": "catalog:"
},
"keywords": [
"powersync",
Expand Down
1 change: 0 additions & 1 deletion packages/attachments-storage-react-native/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.base",
"compilerOptions": {
"baseUrl": "./",
"rootDir": "src",
"module": "node16",
"moduleResolution": "node16",
Expand Down
8 changes: 4 additions & 4 deletions packages/attachments/src/AbstractAttachmentQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ export interface AttachmentQueueOptions {
onUploadError?: (attachment: AttachmentRecord, exception: any) => Promise<{ retry?: boolean }>;
}

export const DEFAULT_ATTACHMENT_QUEUE_OPTIONS: Partial<AttachmentQueueOptions> = {
export const DEFAULT_ATTACHMENT_QUEUE_OPTIONS = {
attachmentDirectoryName: ATTACHMENT_TABLE,
attachmentTableName: ATTACHMENT_TABLE,
syncInterval: 30_000,
cacheLimit: 100,
performInitialSync: true,
downloadAttachments: true
};
} satisfies Partial<AttachmentQueueOptions>;

export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions = AttachmentQueueOptions> {
uploading: boolean;
downloading: boolean;
initialSync: boolean;
options: T;
options: T & typeof DEFAULT_ATTACHMENT_QUEUE_OPTIONS;
downloadQueue: Set<string>;

constructor(options: T) {
Expand Down Expand Up @@ -470,7 +470,7 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
try {
this.logger.debug(`Downloading ${this.downloadQueue.size} attachments...`);
while (this.downloadQueue.size > 0) {
const id = this.downloadQueue.values().next().value;
const id = this.downloadQueue.values().next().value!;
this.downloadQueue.delete(id);
const record = await this.record(id);
if (!record) {
Expand Down
1 change: 0 additions & 1 deletion packages/attachments/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.base",
"compilerOptions": {
"baseUrl": "./",
"rootDir": "src",
"module": "nodenext",
"moduleResolution": "nodenext",
Expand Down
1 change: 1 addition & 0 deletions packages/capacitor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"moduleResolution": "nodenext",
"skipLibCheck": true,
"outDir": "dist/esm",
"rootDir": "src/",
"sourceMap": true,
"strict": true,
"target": "es2017"
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/attachments/AttachmentQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export class AttachmentQueue {
/** Cleanup function for status change listener */
private statusListenerDispose?: () => void;

private watchActiveAttachments: DifferentialWatchedQuery<AttachmentRecord>;
private watchActiveAttachments!: DifferentialWatchedQuery<AttachmentRecord>;

private watchAttachmentsAbortController: AbortController;
private watchAttachmentsAbortController!: AbortController;

/**
* Creates a new AttachmentQueue instance.
Expand Down
15 changes: 8 additions & 7 deletions packages/common/src/client/AbstractPowerSyncDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Logger, { ILogger } from 'js-logger';
import {
BatchedUpdateNotification,
DBAdapter,
LockContext,
QueryResult,
Transaction,
UpdateNotification,
Expand Down Expand Up @@ -442,15 +443,15 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
try {
const { version } = await this.database.get<{ version: string }>('SELECT powersync_rs_version() as version');
this.sdkVersion = version;
} catch (e) {
} catch (e: any) {
throw new Error(`The powersync extension is not loaded correctly. Details: ${e.message}`);
}
let versionInts: number[];
try {
versionInts = this.sdkVersion!.split(/[.\/]/)
.slice(0, 3)
.map((n) => parseInt(n));
} catch (e) {
} catch (e: any) {
throw new Error(
`Unsupported powersync extension version. Need >=0.4.10 <1.0.0, got: ${this.sdkVersion}. Details: ${e.message}`
);
Expand Down Expand Up @@ -894,7 +895,7 @@ SELECT * FROM crud_entries;
* Takes a read lock, without starting a transaction.
* In most cases, {@link readTransaction} should be used instead.
*/
async readLock<T>(callback: (db: DBAdapter) => Promise<T>) {
async readLock<T>(callback: (db: LockContext) => Promise<T>) {
await this.waitForReady();
return this.database.readLock(callback);
}
Expand All @@ -903,7 +904,7 @@ SELECT * FROM crud_entries;
* Takes a global lock, without starting a transaction.
* In most cases, {@link writeTransaction} should be used instead.
*/
async writeLock<T>(callback: (db: DBAdapter) => Promise<T>) {
async writeLock<T>(callback: (db: LockContext) => Promise<T>) {
await this.waitForReady();
return this.database.writeLock(callback);
}
Expand Down Expand Up @@ -1037,7 +1038,7 @@ SELECT * FROM crud_entries;
parameters
}),
execute: async ({ sql, parameters }) => {
const result = await this.getAll(sql, parameters);
const result = await this.getAll<Record<string, any>>(sql, parameters);
return mapper ? result.map(mapper) : (result as RowType[]);
}
};
Expand Down Expand Up @@ -1090,7 +1091,7 @@ SELECT * FROM crud_entries;
const watchedQuery = new OnChangeQueryProcessor({
db: this,
comparator,
placeholderData: null,
placeholderData: null as unknown as QueryResult, // FIXME
watchOptions: {
query: {
compile: () => ({
Expand Down Expand Up @@ -1275,7 +1276,7 @@ SELECT * FROM crud_entries;
try {
this.processTableUpdates(update, changedTables);
flushTableUpdates();
} catch (error) {
} catch (error: any) {
onError?.(error);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export class WebsocketClientTransport implements ClientTransport {
resolve(new WebsocketDuplexConnection(websocket, new Deserializer(), multiplexerDemultiplexerFactory));
};

const errorListener = (ev: ErrorEvent) => {
const errorListener = (event: Event) => {
const ev = event as ErrorEvent;

removeListeners();
// We add a default error in that case.
if (ev.error != null) {
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/client/triggers/TriggerManagerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export class TriggerManagerImpl implements TriggerManager {
const callbackResult = await options.onChange({
...tx,
destinationTable: destination,
withDiff: async <T>(query, params, options?: WithDiffOptions) => {
withDiff: async <T>(query: string, params: any, options?: WithDiffOptions) => {
// Wrap the query to expose the destination table
const operationIdSelect = options?.castOperationIdAsText
? 'id, operation, CAST(operation_id AS TEXT) as operation_id, timestamp, value, previous_value'
Expand All @@ -439,7 +439,7 @@ export class TriggerManagerImpl implements TriggerManager {
`;
return tx.getAll<T>(wrappedQuery, params);
},
withExtractedDiff: async <T>(query, params) => {
withExtractedDiff: async <T>(query: string, params: any) => {
// Wrap the query to expose the destination table
const wrappedQuery = /* sql */ `
WITH
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/client/watched/GetAllQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class GetAllQuery<RowType = unknown> implements WatchCompatibleQuery<RowT
async execute(options: { db: AbstractPowerSyncDatabase }): Promise<RowType[]> {
const { db } = options;
const { sql, parameters = [] } = this.compile();
const rawResult = await db.getAll<unknown>(sql, [...parameters]);
const rawResult = await db.getAll<Record<string, unknown>>(sql, [...parameters]);
if (this.options.mapper) {
return rawResult.map(this.options.mapper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ type WatchedQueryProcessorListener<Data> = WatchedQueryListener<Data>;
* @internal
*/
export abstract class AbstractQueryProcessor<
Data = unknown[],
Settings extends WatchedQueryOptions = WatchedQueryOptions
>
Data = unknown[],
Settings extends WatchedQueryOptions = WatchedQueryOptions
>
extends MetaBaseObserver<WatchedQueryProcessorListener<Data>>
implements WatchedQuery<Data, Settings>
{
Expand Down Expand Up @@ -199,7 +199,7 @@ export abstract class AbstractQueryProcessor<
protected async runWithReporting<T>(callback: () => Promise<T>): Promise<void> {
try {
await callback();
} catch (error) {
} catch (error: any) {
// This will update the error on the state and iterate error listeners
await this.updateState({ error });
}
Expand All @@ -213,7 +213,7 @@ export abstract class AbstractQueryProcessor<
) {
try {
await this.iterateAsyncListeners(async (l) => callback(l));
} catch (error) {
} catch (error: any) {
try {
await this.iterateAsyncListeners(async (l) => l.onError?.(error));
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ export interface DifferentialWatchedQuerySettings<RowType> extends DifferentialW
query: WatchCompatibleQuery<RowType[]>;
}

export interface DifferentialWatchedQueryListener<RowType>
extends WatchedQueryListener<ReadonlyArray<Readonly<RowType>>> {
export interface DifferentialWatchedQueryListener<RowType> extends WatchedQueryListener<
ReadonlyArray<Readonly<RowType>>
> {
onDiff?: (diff: WatchedQueryDifferential<RowType>) => void | Promise<void>;
}

Expand All @@ -97,8 +98,10 @@ export type DifferentialWatchedQuery<RowType> = WatchedQuery<
/**
* @internal
*/
export interface DifferentialQueryProcessorOptions<RowType>
extends AbstractQueryProcessorOptions<RowType[], DifferentialWatchedQuerySettings<RowType>> {
export interface DifferentialQueryProcessorOptions<RowType> extends AbstractQueryProcessorOptions<
RowType[],
DifferentialWatchedQuerySettings<RowType>
> {
rowComparator?: DifferentialWatchedQueryComparator<RowType>;
}

Expand Down Expand Up @@ -286,7 +289,7 @@ export class DifferentialQueryProcessor<RowType>
if (Object.keys(partialStateUpdate).length > 0) {
await this.updateState(partialStateUpdate);
}
} catch (error) {
} catch (error: any) {
await this.updateState({ error });
}
},
Expand Down
Loading
Loading