Skip to content

Commit

Permalink
Merge branch 'main' into react-native-web-christiaan
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/web/package.json
#	pnpm-lock.yaml
  • Loading branch information
Chriztiaan committed Sep 16, 2024
2 parents 537ab8f + 86d6614 commit ccc9a5c
Show file tree
Hide file tree
Showing 35 changed files with 225 additions and 216 deletions.
7 changes: 7 additions & 0 deletions .changeset/ninety-hats-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@powersync/diagnostics-app': minor
'@powersync/common': minor
'@powersync/web': minor
---

Remove lodash dependency.
5 changes: 5 additions & 0 deletions .changeset/tough-impalas-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/common': minor
---

Correctly identify @powersync/common as an ES module
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
node_modules
lib
dist
tsconfig.tsbuildinfo
*.tsbuildinfo
.vscode
.DS_STORE
.idea
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ Deno.serve(async (req) => {
);
} catch (err) {
return new Response(
JSON.stringify({ error: String(err?.message ?? err) }, { status: 500, headers: responseHeaders })
JSON.stringify({ error: String(err?.message ?? err) }),
{ status: 500, headers: responseHeaders }
);
}
});
Expand Down
15 changes: 11 additions & 4 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
"access": "public"
},
"description": "API definitions for JourneyApps PowerSync",
"main": "dist/index.js",
"type": "module",
"main": "dist/bundle.mjs",
"module": "dist/bundle.mjs",
"types": "lib/index.d.ts",
"exports": {
".": {
"import": "./dist/bundle.mjs",
"default": "./dist/bundle.mjs",
"types": "./lib/index.d.ts"
}
},
"author": "JOURNEYAPPS",
"license": "Apache-2.0",
"files": [
Expand All @@ -24,7 +33,7 @@
"homepage": "https://docs.powersync.com",
"scripts": {
"build": "tsc -b && rollup -c rollup.config.mjs",
"clean": "rm -rf lib tsconfig.tsbuildinfo dist",
"clean": "rm -rf lib dist tsconfig.tsbuildinfo",
"test": "vitest"
},
"dependencies": {
Expand All @@ -36,7 +45,6 @@
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@types/lodash": "^4.14.197",
"@types/node": "^20.5.9",
"@types/uuid": "^9.0.1",
"async-mutex": "^0.4.0",
Expand All @@ -45,7 +53,6 @@
"can-ndjson-stream": "^1.0.2",
"cross-fetch": "^4.0.0",
"event-iterator": "^2.0.0",
"lodash": "^4.17.21",
"rollup": "4.14.3",
"rsocket-core": "1.0.0-alpha.3",
"rsocket-websocket-client": "1.0.0-alpha.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default (commandLineArgs) => {
return {
input: 'lib/index.js',
output: {
file: 'dist/index.js',
file: 'dist/bundle.mjs',
format: 'esm',
sourcemap: sourcemap
},
Expand Down
35 changes: 17 additions & 18 deletions packages/common/src/client/AbstractPowerSyncDatabase.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { Mutex } from 'async-mutex';
import { EventIterator } from 'event-iterator';
import Logger, { ILogger } from 'js-logger';
import throttle from 'lodash/throttle';
import {
BatchedUpdateNotification,
DBAdapter,
QueryResult,
Transaction,
UpdateNotification,
isBatchedUpdateNotification
} from '../db/DBAdapter';
import { SyncStatus } from '../db/crud/SyncStatus';
import { UploadQueueStats } from '../db/crud/UploadQueueStatus';
import { Schema } from '../db/schema/Schema';
import { BaseObserver } from '../utils/BaseObserver';
import { ControlledExecutor } from '../utils/ControlledExecutor';
import { mutexRunExclusive } from '../utils/mutex';
import { SQLOpenFactory, SQLOpenOptions, isDBAdapter, isSQLOpenFactory, isSQLOpenOptions } from './SQLOpenFactory';
import { PowerSyncBackendConnector } from './connection/PowerSyncBackendConnector';
import { BucketStorageAdapter, PSInternalTable } from './sync/bucket/BucketStorageAdapter';
import { CrudBatch } from './sync/bucket/CrudBatch';
import { CrudEntry, CrudEntryJSON } from './sync/bucket/CrudEntry';
import { CrudTransaction } from './sync/bucket/CrudTransaction';
} from '../db/DBAdapter.js';
import { SyncStatus } from '../db/crud/SyncStatus.js';
import { UploadQueueStats } from '../db/crud/UploadQueueStatus.js';
import { Schema } from '../db/schema/Schema.js';
import { BaseObserver } from '../utils/BaseObserver.js';
import { ControlledExecutor } from '../utils/ControlledExecutor.js';
import { mutexRunExclusive } from '../utils/mutex.js';
import { throttleTrailing } from '../utils/throttle.js';
import { SQLOpenFactory, SQLOpenOptions, isDBAdapter, isSQLOpenFactory, isSQLOpenOptions } from './SQLOpenFactory.js';
import { PowerSyncBackendConnector } from './connection/PowerSyncBackendConnector.js';
import { BucketStorageAdapter, PSInternalTable } from './sync/bucket/BucketStorageAdapter.js';
import { CrudBatch } from './sync/bucket/CrudBatch.js';
import { CrudEntry, CrudEntryJSON } from './sync/bucket/CrudEntry.js';
import { CrudTransaction } from './sync/bucket/CrudTransaction.js';
import {
DEFAULT_CRUD_UPLOAD_THROTTLE_MS,
PowerSyncConnectionOptions,
StreamingSyncImplementation,
StreamingSyncImplementationListener
} from './sync/stream/AbstractStreamingSyncImplementation';
} from './sync/stream/AbstractStreamingSyncImplementation.js';

export interface DisconnectAndClearOptions {
/** When set to false, data in local-only tables is preserved. */
Expand Down Expand Up @@ -898,14 +898,13 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
await onChange(e);
});

const flushTableUpdates = throttle(
const flushTableUpdates = throttleTrailing(
() =>
this.handleTableChanges(changedTables, watchedTables, (intersection) => {
if (resolvedOptions?.signal?.aborted) return;
executor.schedule({ changedTables: intersection });
}),
throttleMs,
{ leading: false, trailing: true }
throttleMs
);

const dispose = this.database.registerListener({
Expand Down
8 changes: 4 additions & 4 deletions packages/common/src/client/AbstractPowerSyncOpenFactory.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Logger from 'js-logger';
import { DBAdapter } from '../db/DBAdapter';
import { Schema } from '../db/schema/Schema';
import { AbstractPowerSyncDatabase, PowerSyncDatabaseOptions } from './AbstractPowerSyncDatabase';
import { SQLOpenOptions } from './SQLOpenFactory';
import { DBAdapter } from '../db/DBAdapter.js';
import { Schema } from '../db/schema/Schema.js';
import { AbstractPowerSyncDatabase, PowerSyncDatabaseOptions } from './AbstractPowerSyncDatabase.js';
import { SQLOpenOptions } from './SQLOpenFactory.js';

export interface PowerSyncOpenFactoryOptions extends Partial<PowerSyncDatabaseOptions>, SQLOpenOptions {
/** Schema used for the local database. */
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/client/SQLOpenFactory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DBAdapter } from '../db/DBAdapter';
import { DBAdapter } from '../db/DBAdapter.js';

export interface SQLOpenOptions {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PowerSyncCredentials } from './PowerSyncCredentials';
import type { AbstractPowerSyncDatabase } from '../AbstractPowerSyncDatabase';
import { PowerSyncCredentials } from './PowerSyncCredentials.js';
import type { AbstractPowerSyncDatabase } from '../AbstractPowerSyncDatabase.js';

export interface PowerSyncBackendConnector {
/** Allows the PowerSync client to retrieve an authentication token from your backend
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseListener, BaseObserver, Disposable } from '../../../utils/BaseObserver';
import { CrudBatch } from './CrudBatch';
import { CrudEntry, OpId } from './CrudEntry';
import { SyncDataBatch } from './SyncDataBatch';
import { BaseListener, BaseObserver, Disposable } from '../../../utils/BaseObserver.js';
import { CrudBatch } from './CrudBatch.js';
import { CrudEntry, OpId } from './CrudEntry.js';
import { SyncDataBatch } from './SyncDataBatch.js';

export interface Checkpoint {
last_op_id: OpId;
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/client/sync/bucket/CrudBatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CrudEntry } from './CrudEntry';
import { CrudEntry } from './CrudEntry.js';

/**
* A batch of client-side changes.
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/client/sync/bucket/CrudTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CrudBatch } from './CrudBatch';
import { CrudEntry } from './CrudEntry';
import { CrudBatch } from './CrudBatch.js';
import { CrudEntry } from './CrudEntry.js';

export class CrudTransaction extends CrudBatch {
constructor(
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/client/sync/bucket/OplogEntry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OpId } from './CrudEntry';
import { OpType, OpTypeJSON } from './OpType';
import { OpId } from './CrudEntry.js';
import { OpType, OpTypeJSON } from './OpType.js';

export interface OplogEntryJSON {
checksum: number;
Expand Down
15 changes: 7 additions & 8 deletions packages/common/src/client/sync/bucket/SqliteBucketStorage.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { Mutex } from 'async-mutex';
import Logger, { ILogger } from 'js-logger';
import { DBAdapter, Transaction, extractTableUpdates } from '../../../db/DBAdapter';
import { BaseObserver } from '../../../utils/BaseObserver';
import { DBAdapter, Transaction, extractTableUpdates } from '../../../db/DBAdapter.js';
import { BaseObserver } from '../../../utils/BaseObserver.js';
import { MAX_OP_ID } from '../../constants.js';
import {
BucketState,
BucketStorageAdapter,
BucketStorageListener,
Checkpoint,
PSInternalTable,
SyncLocalDatabaseResult
} from './BucketStorageAdapter';
import { CrudBatch } from './CrudBatch';
import { MAX_OP_ID } from '../../constants';
import { CrudEntry, CrudEntryJSON } from './CrudEntry';
import { OpTypeEnum } from './OpType';
import { SyncDataBatch } from './SyncDataBatch';
} from './BucketStorageAdapter.js';
import { CrudBatch } from './CrudBatch.js';
import { CrudEntry, CrudEntryJSON } from './CrudEntry.js';
import { SyncDataBatch } from './SyncDataBatch.js';

const COMPACT_OPERATION_INTERVAL = 1_000;

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/client/sync/bucket/SyncDataBatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SyncDataBucket } from './SyncDataBucket';
import { SyncDataBucket } from './SyncDataBucket.js';

// TODO JSON

Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/client/sync/bucket/SyncDataBucket.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OpId } from './CrudEntry';
import { OplogEntry, OplogEntryJSON } from './OplogEntry';
import { OpId } from './CrudEntry.js';
import { OplogEntry, OplogEntryJSON } from './OplogEntry.js';

export type SyncDataBucketJSON = {
bucket: string;
Expand Down
16 changes: 8 additions & 8 deletions packages/common/src/client/sync/stream/AbstractRemote.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Logger, { ILogger } from 'js-logger';
import { type fetch } from 'cross-fetch';
import { PowerSyncCredentials } from '../../connection/PowerSyncCredentials';
import { StreamingSyncLine, StreamingSyncRequest } from './streaming-sync-types';
import { DataStream } from '../../../utils/DataStream';
import type { BSON } from 'bson';
import { Buffer } from 'buffer';
import ndjsonStream from 'can-ndjson-stream';
import { type fetch } from 'cross-fetch';
import Logger, { ILogger } from 'js-logger';
import { RSocket, RSocketConnector, Requestable } from 'rsocket-core';
import { WebsocketClientTransport } from 'rsocket-websocket-client';
import type { BSON } from 'bson';
import { AbortOperation } from '../../../utils/AbortOperation';
import { Buffer } from 'buffer';
import { AbortOperation } from '../../../utils/AbortOperation.js';
import { DataStream } from '../../../utils/DataStream.js';
import { PowerSyncCredentials } from '../../connection/PowerSyncCredentials.js';
import { StreamingSyncLine, StreamingSyncRequest } from './streaming-sync-types.js';

import { version as POWERSYNC_JS_VERSION } from '../../../../package.json';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import throttle from 'lodash/throttle';

import Logger, { ILogger } from 'js-logger';

import { SyncStatus, SyncStatusOptions } from '../../../db/crud/SyncStatus';
import { AbortOperation } from '../../../utils/AbortOperation';
import { BaseListener, BaseObserver, Disposable } from '../../../utils/BaseObserver';
import { BucketChecksum, BucketStorageAdapter, Checkpoint } from '../bucket/BucketStorageAdapter';
import { CrudEntry } from '../bucket/CrudEntry';
import { SyncDataBucket } from '../bucket/SyncDataBucket';
import { AbstractRemote, SyncStreamOptions } from './AbstractRemote';
import { SyncStatus, SyncStatusOptions } from '../../../db/crud/SyncStatus.js';
import { AbortOperation } from '../../../utils/AbortOperation.js';
import { BaseListener, BaseObserver, Disposable } from '../../../utils/BaseObserver.js';
import { BucketChecksum, BucketStorageAdapter, Checkpoint } from '../bucket/BucketStorageAdapter.js';
import { CrudEntry } from '../bucket/CrudEntry.js';
import { SyncDataBucket } from '../bucket/SyncDataBucket.js';
import { AbstractRemote, SyncStreamOptions } from './AbstractRemote.js';
import {
BucketRequest,
StreamingSyncRequestParameterType,
Expand All @@ -17,7 +15,8 @@ import {
isStreamingSyncCheckpointComplete,
isStreamingSyncCheckpointDiff,
isStreamingSyncData
} from './streaming-sync-types';
} from './streaming-sync-types.js';
import { throttleLeadingTrailing } from '../../../utils/throttle.js';

export enum LockType {
CRUD = 'crud',
Expand Down Expand Up @@ -142,16 +141,12 @@ export abstract class AbstractStreamingSyncImplementation
});
this.abortController = null;

this.triggerCrudUpload = throttle(
() => {
if (!this.syncStatus.connected || this.syncStatus.dataFlowStatus.uploading) {
return;
}
this._uploadAllCrud();
},
this.options.crudUploadThrottleMs,
{ trailing: true }
);
this.triggerCrudUpload = throttleLeadingTrailing(() => {
if (!this.syncStatus.connected || this.syncStatus.dataFlowStatus.uploading) {
return;
}
this._uploadAllCrud();
}, this.options.crudUploadThrottleMs!);
}

async waitForReady() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BucketChecksum, Checkpoint } from '../bucket/BucketStorageAdapter';
import { CrudEntry, OpId } from '../bucket/CrudEntry';
import { SyncDataBucketJSON } from '../bucket/SyncDataBucket';
import { BucketChecksum, Checkpoint } from '../bucket/BucketStorageAdapter.js';
import { CrudEntry, OpId } from '../bucket/CrudEntry.js';
import { SyncDataBucketJSON } from '../bucket/SyncDataBucket.js';

/**
* For sync2.json
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/db/DBAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* different SQLite DB implementations.
*/

import { BaseListener, BaseObserverInterface } from '../utils/BaseObserver';
import { BaseListener, BaseObserverInterface } from '../utils/BaseObserver.js';

/**
* TODO most of these types could be exported to a common `types` package
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/db/schema/Index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IndexedColumn } from './IndexedColumn';
import { Table } from './Table';
import { IndexedColumn } from './IndexedColumn.js';
import { Table } from './Table.js';

export interface IndexOptions {
name: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/db/schema/IndexedColumn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ColumnType } from './Column';
import { Table } from './Table';
import { ColumnType } from './Column.js';
import { Table } from './Table.js';

export interface IndexColumnOptions {
name: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/db/schema/Schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RowType, Table } from './Table';
import { RowType, Table } from './Table.js';

type SchemaType = Record<string, Table<any>>;

Expand Down
Loading

0 comments on commit ccc9a5c

Please sign in to comment.