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
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
13 changes: 11 additions & 2 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 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
28 changes: 14 additions & 14 deletions packages/common/src/client/AbstractPowerSyncDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ import {
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';
} 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';
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';
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
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,12 +1,12 @@
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 @@ -15,8 +15,8 @@ import {
isStreamingSyncCheckpointComplete,
isStreamingSyncCheckpointDiff,
isStreamingSyncData
} from './streaming-sync-types';
import { throttleLeadingTrailing } from '../../../utils/throttle';
} from './streaming-sync-types.js';
import { throttleLeadingTrailing } from '../../../utils/throttle.js';

export enum LockType {
CRUD = 'crud',
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
36 changes: 17 additions & 19 deletions packages/common/src/db/schema/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
ColumnType,
ExtractColumnValueType,
MAX_AMOUNT_OF_COLUMNS
} from './Column';
import { Index } from './Index';
import { IndexedColumn } from './IndexedColumn';
import { TableV2 } from './TableV2';
} from './Column.js';
import { Index } from './Index.js';
import { IndexedColumn } from './IndexedColumn.js';
import { TableV2 } from './TableV2.js';

export interface TableOptions {
/**
Expand Down Expand Up @@ -114,20 +114,20 @@ export class Table<Columns extends ColumnsType = ColumnsType> {
*/
constructor(columns: Columns, options?: TableV2Options);
/**
* @deprecated This constructor will be removed in the next major release.
* Use the new constructor shown below instead as this does not show types.
* @example
* <caption>Use this instead</caption>
* ```javascript
* const table = new Table(
* {
* @deprecated This constructor will be removed in the next major release.
* Use the new constructor shown below instead as this does not show types.
* @example
* <caption>Use this instead</caption>
* ```javascript
* const table = new Table(
* {
* name: column.text,
* age: column.integer
* },
* { indexes: { nameIndex: ['name'] } }
* );
*```
*/
* },
* { indexes: { nameIndex: ['name'] } }
* );
*```
*/
constructor(options: TableOptions);
constructor(optionsOrColumns: Columns | TableOptions, v2Options?: TableV2Options) {
if (this.isTableV1(optionsOrColumns)) {
Expand Down Expand Up @@ -247,9 +247,7 @@ export class Table<Columns extends ColumnsType = ColumnsType> {
}

if (this.columns.length > MAX_AMOUNT_OF_COLUMNS) {
throw new Error(
`Table has too many columns. The maximum number of columns is ${MAX_AMOUNT_OF_COLUMNS}.`
);
throw new Error(`Table has too many columns. The maximum number of columns is ${MAX_AMOUNT_OF_COLUMNS}.`);
}

const columnNames = new Set<string>();
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/db/schema/TableV2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ColumnsType } from './Column';
import { Table } from './Table';
import { ColumnsType } from './Column.js';
import { Table } from './Table.js';

/**
Generate a new table from the columns and indexes
Expand Down
Loading
Loading