@powersync/common 0.0.0-dev-20260504100448 → 0.0.0-dev-20260630141119
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/attachments/AttachmentContext.d.ts +9 -8
- package/lib/attachments/AttachmentContext.js +8 -3
- package/lib/attachments/AttachmentContext.js.map +1 -1
- package/lib/attachments/AttachmentErrorHandler.d.ts +6 -6
- package/lib/attachments/AttachmentQueue.d.ts +85 -36
- package/lib/attachments/AttachmentQueue.js +19 -21
- package/lib/attachments/AttachmentQueue.js.map +1 -1
- package/lib/attachments/AttachmentService.d.ts +3 -3
- package/lib/attachments/AttachmentService.js +4 -3
- package/lib/attachments/AttachmentService.js.map +1 -1
- package/lib/attachments/LocalStorageAdapter.d.ts +14 -8
- package/lib/attachments/LocalStorageAdapter.js +3 -0
- package/lib/attachments/LocalStorageAdapter.js.map +1 -1
- package/lib/attachments/RemoteStorageAdapter.d.ts +4 -4
- package/lib/attachments/Schema.d.ts +14 -6
- package/lib/attachments/Schema.js +8 -3
- package/lib/attachments/Schema.js.map +1 -1
- package/lib/attachments/SyncingService.d.ts +2 -2
- package/lib/attachments/SyncingService.js +8 -3
- package/lib/attachments/SyncingService.js.map +1 -1
- package/lib/attachments/WatchedAttachmentItem.d.ts +3 -1
- package/lib/client/{AbstractPowerSyncDatabase.d.ts → CommonPowerSyncDatabase.d.ts} +112 -238
- package/lib/client/CommonPowerSyncDatabase.js +2 -0
- package/lib/client/CommonPowerSyncDatabase.js.map +1 -0
- package/lib/client/Query.d.ts +9 -0
- package/lib/client/SQLOpenFactory.d.ts +44 -10
- package/lib/client/SQLOpenFactory.js +1 -19
- package/lib/client/SQLOpenFactory.js.map +1 -1
- package/lib/client/compilableQueryWatch.d.ts +8 -2
- package/lib/client/compilableQueryWatch.js +4 -2
- package/lib/client/compilableQueryWatch.js.map +1 -1
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +6 -3
- package/lib/client/connection/PowerSyncCredentials.d.ts +3 -0
- package/lib/client/runOnSchemaChange.d.ts +5 -2
- package/lib/client/runOnSchemaChange.js +3 -0
- package/lib/client/runOnSchemaChange.js.map +1 -1
- package/lib/client/sync/bucket/CrudBatch.d.ts +2 -0
- package/lib/client/sync/bucket/CrudBatch.js +2 -0
- package/lib/client/sync/bucket/CrudBatch.js.map +1 -1
- package/lib/client/sync/bucket/CrudEntry.d.ts +9 -31
- package/lib/client/sync/bucket/CrudEntry.js +2 -97
- package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
- package/lib/client/sync/bucket/CrudTransaction.d.ts +3 -0
- package/lib/client/sync/bucket/CrudTransaction.js +3 -0
- package/lib/client/sync/bucket/CrudTransaction.js.map +1 -1
- package/lib/client/sync/options.d.ts +65 -0
- package/lib/client/sync/options.js +25 -0
- package/lib/client/sync/options.js.map +1 -0
- package/lib/client/sync/stream/JsonValue.d.ts +3 -0
- package/lib/client/sync/sync-streams.d.ts +23 -8
- package/lib/client/triggers/TriggerManager.d.ts +28 -56
- package/lib/client/triggers/TriggerManager.js +2 -1
- package/lib/client/triggers/TriggerManager.js.map +1 -1
- package/lib/client/triggers/sanitizeSQL.d.ts +4 -0
- package/lib/client/triggers/sanitizeSQL.js +4 -0
- package/lib/client/triggers/sanitizeSQL.js.map +1 -1
- package/lib/client/watched/GetAllQuery.d.ts +7 -3
- package/lib/client/watched/GetAllQuery.js +3 -1
- package/lib/client/watched/GetAllQuery.js.map +1 -1
- package/lib/client/watched/WatchedQuery.d.ts +20 -6
- package/lib/client/watched/WatchedQuery.js +3 -5
- package/lib/client/watched/WatchedQuery.js.map +1 -1
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +15 -45
- package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -172
- package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +4 -22
- package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -82
- package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/comparators.d.ts +8 -0
- package/lib/client/watched/processors/comparators.js +4 -0
- package/lib/client/watched/processors/comparators.js.map +1 -1
- package/lib/db/DBAdapter.d.ts +90 -113
- package/lib/db/DBAdapter.js +70 -89
- package/lib/db/DBAdapter.js.map +1 -1
- package/lib/db/QueryResult.d.ts +104 -0
- package/lib/db/QueryResult.js +96 -0
- package/lib/db/QueryResult.js.map +1 -0
- package/lib/db/crud/SyncProgress.d.ts +7 -14
- package/lib/db/crud/SyncProgress.js +1 -60
- package/lib/db/crud/SyncProgress.js.map +1 -1
- package/lib/db/crud/SyncStatus.d.ts +54 -91
- package/lib/db/crud/SyncStatus.js +1 -245
- package/lib/db/crud/SyncStatus.js.map +1 -1
- package/lib/db/crud/UploadQueueStatus.d.ts +3 -0
- package/lib/db/crud/UploadQueueStatus.js +3 -0
- package/lib/db/crud/UploadQueueStatus.js.map +1 -1
- package/lib/db/schema/Column.d.ts +22 -1
- package/lib/db/schema/Column.js +10 -4
- package/lib/db/schema/Column.js.map +1 -1
- package/lib/db/schema/Index.d.ts +8 -3
- package/lib/db/schema/Index.js +4 -1
- package/lib/db/schema/Index.js.map +1 -1
- package/lib/db/schema/IndexedColumn.d.ts +8 -3
- package/lib/db/schema/IndexedColumn.js +4 -1
- package/lib/db/schema/IndexedColumn.js.map +1 -1
- package/lib/db/schema/RawTable.d.ts +7 -1
- package/lib/db/schema/Schema.d.ts +10 -29
- package/lib/db/schema/Schema.js +3 -1
- package/lib/db/schema/Schema.js.map +1 -1
- package/lib/db/schema/Table.d.ts +69 -91
- package/lib/db/schema/Table.js +88 -87
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/index.d.ts +6 -22
- package/lib/index.js +5 -22
- package/lib/index.js.map +1 -1
- package/lib/types/types.d.ts +6 -0
- package/lib/utils/BaseObserver.d.ts +12 -0
- package/lib/utils/BaseObserver.js +3 -0
- package/lib/utils/BaseObserver.js.map +1 -1
- package/lib/utils/Logger.d.ts +60 -22
- package/lib/utils/Logger.js +38 -30
- package/lib/utils/Logger.js.map +1 -1
- package/lib/utils/MetaBaseObserver.d.ts +11 -11
- package/lib/utils/MetaBaseObserver.js +1 -50
- package/lib/utils/MetaBaseObserver.js.map +1 -1
- package/lib/utils/mutex.d.ts +3 -45
- package/lib/utils/mutex.js +1 -153
- package/lib/utils/mutex.js.map +1 -1
- package/package.json +9 -46
- package/src/attachments/AttachmentContext.ts +15 -13
- package/src/attachments/AttachmentErrorHandler.ts +6 -6
- package/src/attachments/AttachmentQueue.ts +99 -42
- package/src/attachments/AttachmentService.ts +7 -6
- package/src/attachments/LocalStorageAdapter.ts +14 -8
- package/src/attachments/README.md +2 -0
- package/src/attachments/RemoteStorageAdapter.ts +4 -4
- package/src/attachments/Schema.ts +14 -6
- package/src/attachments/SyncingService.ts +10 -6
- package/src/attachments/WatchedAttachmentItem.ts +3 -1
- package/src/client/CommonPowerSyncDatabase.ts +540 -0
- package/src/client/Query.ts +9 -0
- package/src/client/SQLOpenFactory.ts +47 -19
- package/src/client/compilableQueryWatch.ts +9 -4
- package/src/client/connection/PowerSyncBackendConnector.ts +6 -3
- package/src/client/connection/PowerSyncCredentials.ts +3 -0
- package/src/client/runOnSchemaChange.ts +5 -2
- package/src/client/sync/bucket/CrudBatch.ts +2 -0
- package/src/client/sync/bucket/CrudEntry.ts +10 -101
- package/src/client/sync/bucket/CrudTransaction.ts +3 -0
- package/src/client/sync/options.ts +77 -0
- package/src/client/sync/stream/JsonValue.ts +3 -0
- package/src/client/sync/sync-streams.ts +23 -10
- package/src/client/triggers/TriggerManager.ts +29 -59
- package/src/client/triggers/sanitizeSQL.ts +5 -0
- package/src/client/watched/GetAllQuery.ts +8 -4
- package/src/client/watched/WatchedQuery.ts +20 -11
- package/src/client/watched/processors/DifferentialQueryProcessor.ts +19 -219
- package/src/client/watched/processors/OnChangeQueryProcessor.ts +4 -109
- package/src/client/watched/processors/comparators.ts +8 -0
- package/src/db/DBAdapter.ts +160 -175
- package/src/db/QueryResult.ts +195 -0
- package/src/db/crud/SyncProgress.ts +8 -43
- package/src/db/crud/SyncStatus.ts +66 -216
- package/src/db/crud/UploadQueueStatus.ts +3 -0
- package/src/db/schema/Column.ts +22 -5
- package/src/db/schema/Index.ts +9 -3
- package/src/db/schema/IndexedColumn.ts +9 -3
- package/src/db/schema/RawTable.ts +7 -1
- package/src/db/schema/Schema.ts +12 -7
- package/src/db/schema/Table.ts +130 -180
- package/src/index.ts +6 -22
- package/src/types/types.ts +6 -0
- package/src/utils/BaseObserver.ts +12 -0
- package/src/utils/Logger.ts +86 -31
- package/src/utils/MetaBaseObserver.ts +14 -60
- package/src/utils/mutex.ts +4 -189
- package/dist/bundle.cjs +0 -14136
- package/dist/bundle.cjs.map +0 -1
- package/dist/bundle.mjs +0 -14056
- package/dist/bundle.mjs.map +0 -1
- package/dist/bundle.node.cjs +0 -11613
- package/dist/bundle.node.cjs.map +0 -1
- package/dist/bundle.node.mjs +0 -11533
- package/dist/bundle.node.mjs.map +0 -1
- package/dist/index.d.cts +0 -4052
- package/legacy/sync_protocol.d.ts +0 -103
- package/lib/client/AbstractPowerSyncDatabase.js +0 -987
- package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
- package/lib/client/AbstractPowerSyncOpenFactory.d.ts +0 -22
- package/lib/client/AbstractPowerSyncOpenFactory.js +0 -25
- package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
- package/lib/client/ConnectionManager.d.ts +0 -112
- package/lib/client/ConnectionManager.js +0 -294
- package/lib/client/ConnectionManager.js.map +0 -1
- package/lib/client/CustomQuery.d.ts +0 -22
- package/lib/client/CustomQuery.js +0 -43
- package/lib/client/CustomQuery.js.map +0 -1
- package/lib/client/constants.d.ts +0 -1
- package/lib/client/constants.js +0 -2
- package/lib/client/constants.js.map +0 -1
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +0 -40
- package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -19
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -34
- package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -162
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +0 -151
- package/lib/client/sync/stream/AbstractRemote.js +0 -473
- package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -218
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -663
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +0 -1
- package/lib/client/sync/stream/WebsocketClientTransport.d.ts +0 -15
- package/lib/client/sync/stream/WebsocketClientTransport.js +0 -61
- package/lib/client/sync/stream/WebsocketClientTransport.js.map +0 -1
- package/lib/client/sync/stream/core-instruction.d.ts +0 -71
- package/lib/client/sync/stream/core-instruction.js +0 -27
- package/lib/client/sync/stream/core-instruction.js.map +0 -1
- package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +0 -6
- package/lib/client/triggers/MemoryTriggerClaimManager.js +0 -21
- package/lib/client/triggers/MemoryTriggerClaimManager.js.map +0 -1
- package/lib/client/triggers/TriggerManagerImpl.d.ts +0 -39
- package/lib/client/triggers/TriggerManagerImpl.js +0 -405
- package/lib/client/triggers/TriggerManagerImpl.js.map +0 -1
- package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +0 -68
- package/lib/client/watched/processors/AbstractQueryProcessor.js +0 -151
- package/lib/client/watched/processors/AbstractQueryProcessor.js.map +0 -1
- package/lib/db/ConnectionClosedError.d.ts +0 -10
- package/lib/db/ConnectionClosedError.js +0 -21
- package/lib/db/ConnectionClosedError.js.map +0 -1
- package/lib/db/schema/TableV2.d.ts +0 -9
- package/lib/db/schema/TableV2.js +0 -9
- package/lib/db/schema/TableV2.js.map +0 -1
- package/lib/utils/AbortOperation.d.ts +0 -9
- package/lib/utils/AbortOperation.js +0 -19
- package/lib/utils/AbortOperation.js.map +0 -1
- package/lib/utils/ControlledExecutor.d.ts +0 -25
- package/lib/utils/ControlledExecutor.js +0 -51
- package/lib/utils/ControlledExecutor.js.map +0 -1
- package/lib/utils/async.d.ts +0 -14
- package/lib/utils/async.js +0 -46
- package/lib/utils/async.js.map +0 -1
- package/lib/utils/parseQuery.d.ts +0 -6
- package/lib/utils/parseQuery.js +0 -17
- package/lib/utils/parseQuery.js.map +0 -1
- package/lib/utils/queue.d.ts +0 -16
- package/lib/utils/queue.js +0 -42
- package/lib/utils/queue.js.map +0 -1
- package/lib/utils/stream_transform.d.ts +0 -39
- package/lib/utils/stream_transform.js +0 -206
- package/lib/utils/stream_transform.js.map +0 -1
- package/src/client/AbstractPowerSyncDatabase.ts +0 -1362
- package/src/client/AbstractPowerSyncOpenFactory.ts +0 -39
- package/src/client/ConnectionManager.ts +0 -402
- package/src/client/CustomQuery.ts +0 -56
- package/src/client/constants.ts +0 -1
- package/src/client/sync/bucket/BucketStorageAdapter.ts +0 -49
- package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -199
- package/src/client/sync/stream/AbstractRemote.ts +0 -602
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -905
- package/src/client/sync/stream/WebsocketClientTransport.ts +0 -80
- package/src/client/sync/stream/core-instruction.ts +0 -98
- package/src/client/triggers/MemoryTriggerClaimManager.ts +0 -25
- package/src/client/triggers/TriggerManagerImpl.ts +0 -496
- package/src/client/watched/processors/AbstractQueryProcessor.ts +0 -226
- package/src/db/ConnectionClosedError.ts +0 -23
- package/src/db/schema/TableV2.ts +0 -9
- package/src/utils/AbortOperation.ts +0 -17
- package/src/utils/ControlledExecutor.ts +0 -72
- package/src/utils/async.ts +0 -50
- package/src/utils/parseQuery.ts +0 -25
- package/src/utils/queue.ts +0 -48
- package/src/utils/stream_transform.ts +0 -252
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thrown when an underlying database connection is closed.
|
|
3
|
-
* This is particularly relevant when worker connections are marked as closed while
|
|
4
|
-
* operations are still in progress.
|
|
5
|
-
*/
|
|
6
|
-
export class ConnectionClosedError extends Error {
|
|
7
|
-
static NAME = 'ConnectionClosedError';
|
|
8
|
-
static MATCHES(input) {
|
|
9
|
-
/**
|
|
10
|
-
* If there are weird package issues which cause multiple versions of classes to be present, the instanceof
|
|
11
|
-
* check might fail. This also performs a failsafe check.
|
|
12
|
-
* This might also happen if the Error is serialized and parsed over a bridging channel like a MessagePort.
|
|
13
|
-
*/
|
|
14
|
-
return (input instanceof ConnectionClosedError || (input instanceof Error && input.name == ConnectionClosedError.NAME));
|
|
15
|
-
}
|
|
16
|
-
constructor(message) {
|
|
17
|
-
super(message);
|
|
18
|
-
this.name = ConnectionClosedError.NAME;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=ConnectionClosedError.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionClosedError.js","sourceRoot":"","sources":["../../src/db/ConnectionClosedError.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,MAAM,CAAC,IAAI,GAAG,uBAAuB,CAAC;IAEtC,MAAM,CAAC,OAAO,CAAC,KAAU;QACvB;;;;WAIG;QACH,OAAO,CACL,KAAK,YAAY,qBAAqB,IAAI,CAAC,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,qBAAqB,CAAC,IAAI,CAAC,CAC/G,CAAC;IACJ,CAAC;IACD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC,IAAI,CAAC;IACzC,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ColumnsType } from './Column.js';
|
|
2
|
-
import { Table } from './Table.js';
|
|
3
|
-
/**
|
|
4
|
-
Generate a new table from the columns and indexes
|
|
5
|
-
@deprecated You should use {@link Table} instead as it now allows TableV2 syntax.
|
|
6
|
-
This will be removed in the next major release.
|
|
7
|
-
*/
|
|
8
|
-
export declare class TableV2<Columns extends ColumnsType = ColumnsType> extends Table<Columns> {
|
|
9
|
-
}
|
package/lib/db/schema/TableV2.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Table } from './Table.js';
|
|
2
|
-
/**
|
|
3
|
-
Generate a new table from the columns and indexes
|
|
4
|
-
@deprecated You should use {@link Table} instead as it now allows TableV2 syntax.
|
|
5
|
-
This will be removed in the next major release.
|
|
6
|
-
*/
|
|
7
|
-
export class TableV2 extends Table {
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=TableV2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TableV2.js","sourceRoot":"","sources":["../../../src/db/schema/TableV2.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;;EAIE;AACF,MAAM,OAAO,OAAmD,SAAQ,KAAc;CAAG"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calls to Abortcontroller.abort(reason: any) will result in the
|
|
3
|
-
* `reason` being thrown. This is not necessarily an error,
|
|
4
|
-
* but extends error for better logging purposes.
|
|
5
|
-
*/
|
|
6
|
-
export declare class AbortOperation extends Error {
|
|
7
|
-
protected reason: string;
|
|
8
|
-
constructor(reason: string);
|
|
9
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calls to Abortcontroller.abort(reason: any) will result in the
|
|
3
|
-
* `reason` being thrown. This is not necessarily an error,
|
|
4
|
-
* but extends error for better logging purposes.
|
|
5
|
-
*/
|
|
6
|
-
export class AbortOperation extends Error {
|
|
7
|
-
reason;
|
|
8
|
-
constructor(reason) {
|
|
9
|
-
super(reason);
|
|
10
|
-
this.reason = reason;
|
|
11
|
-
// Set the prototype explicitly
|
|
12
|
-
Object.setPrototypeOf(this, AbortOperation.prototype);
|
|
13
|
-
// Capture stack trace
|
|
14
|
-
if (Error.captureStackTrace) {
|
|
15
|
-
Error.captureStackTrace(this, AbortOperation);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=AbortOperation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AbortOperation.js","sourceRoot":"","sources":["../../src/utils/AbortOperation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACjB;IAAtB,YAAsB,MAAc;QAClC,KAAK,CAAC,MAAM,CAAC,CAAC;QADM,WAAM,GAAN,MAAM,CAAQ;QAElC,+BAA+B;QAC/B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;QAEtD,sBAAsB;QACtB,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export interface ControlledExecutorOptions {
|
|
2
|
-
/**
|
|
3
|
-
* If throttling is enabled, it ensures only one task runs at a time,
|
|
4
|
-
* and only one additional task can be scheduled to run after the current task completes. The pending task will be overwritten by the latest task.
|
|
5
|
-
* Enabled by default.
|
|
6
|
-
*/
|
|
7
|
-
throttleEnabled?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare class ControlledExecutor<T> {
|
|
10
|
-
private task;
|
|
11
|
-
/**
|
|
12
|
-
* Represents the currently running task, which could be a Promise or undefined if no task is running.
|
|
13
|
-
*/
|
|
14
|
-
private runningTask;
|
|
15
|
-
private pendingTaskParam;
|
|
16
|
-
/**
|
|
17
|
-
* Flag to determine if throttling is enabled, which controls whether tasks are queued or run immediately.
|
|
18
|
-
*/
|
|
19
|
-
private isThrottling;
|
|
20
|
-
private closed;
|
|
21
|
-
constructor(task: (param: T) => Promise<void> | void, options?: ControlledExecutorOptions);
|
|
22
|
-
schedule(param: T): void;
|
|
23
|
-
dispose(): void;
|
|
24
|
-
private execute;
|
|
25
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export class ControlledExecutor {
|
|
2
|
-
task;
|
|
3
|
-
/**
|
|
4
|
-
* Represents the currently running task, which could be a Promise or undefined if no task is running.
|
|
5
|
-
*/
|
|
6
|
-
runningTask;
|
|
7
|
-
pendingTaskParam;
|
|
8
|
-
/**
|
|
9
|
-
* Flag to determine if throttling is enabled, which controls whether tasks are queued or run immediately.
|
|
10
|
-
*/
|
|
11
|
-
isThrottling;
|
|
12
|
-
closed;
|
|
13
|
-
constructor(task, options) {
|
|
14
|
-
this.task = task;
|
|
15
|
-
const { throttleEnabled = true } = options ?? {};
|
|
16
|
-
this.isThrottling = throttleEnabled;
|
|
17
|
-
this.closed = false;
|
|
18
|
-
}
|
|
19
|
-
schedule(param) {
|
|
20
|
-
if (this.closed) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (!this.isThrottling) {
|
|
24
|
-
this.task(param);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (this.runningTask) {
|
|
28
|
-
// set or replace the pending task param with latest one
|
|
29
|
-
this.pendingTaskParam = param;
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
this.execute(param);
|
|
33
|
-
}
|
|
34
|
-
dispose() {
|
|
35
|
-
this.closed = true;
|
|
36
|
-
if (this.runningTask) {
|
|
37
|
-
this.runningTask = undefined;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async execute(param) {
|
|
41
|
-
this.runningTask = this.task(param);
|
|
42
|
-
await this.runningTask;
|
|
43
|
-
this.runningTask = undefined;
|
|
44
|
-
if (this.pendingTaskParam) {
|
|
45
|
-
const pendingParam = this.pendingTaskParam;
|
|
46
|
-
this.pendingTaskParam = undefined;
|
|
47
|
-
this.execute(pendingParam);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=ControlledExecutor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ControlledExecutor.js","sourceRoot":"","sources":["../../src/utils/ControlledExecutor.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,kBAAkB;IACrB,IAAI,CAAqC;IAEjD;;OAEG;IACK,WAAW,CAAqC;IAEhD,gBAAgB,CAAgB;IAExC;;OAEG;IACK,YAAY,CAAU;IAEtB,MAAM,CAAU;IAExB,YAAY,IAAwC,EAAE,OAAmC;QACvF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,MAAM,EAAE,eAAe,GAAG,IAAI,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QACjD,IAAI,CAAC,YAAY,GAAG,eAAe,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,QAAQ,CAAC,KAAQ;QACf,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO;QACT,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACjB,OAAO;QACT,CAAC;QAED,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,wDAAwD;YACxD,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC;YAC9B,OAAO;QACT,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAED,OAAO;QACL,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QAEnB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QAC/B,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,KAAQ;QAC5B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpC,MAAM,IAAI,CAAC,WAAW,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QAE7B,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC1B,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB,CAAC;YAC3C,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;YAElC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;CACF"}
|
package/lib/utils/async.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Throttle a function to be called at most once every "wait" milliseconds,
|
|
3
|
-
* on the trailing edge.
|
|
4
|
-
*
|
|
5
|
-
* Roughly equivalent to lodash/throttle with {leading: false, trailing: true}
|
|
6
|
-
*/
|
|
7
|
-
export declare function throttleTrailing(func: () => void, wait: number): () => void;
|
|
8
|
-
/**
|
|
9
|
-
* Throttle a function to be called at most once every "wait" milliseconds,
|
|
10
|
-
* on the leading and trailing edge.
|
|
11
|
-
*
|
|
12
|
-
* Roughly equivalent to lodash/throttle with {leading: true, trailing: true}
|
|
13
|
-
*/
|
|
14
|
-
export declare function throttleLeadingTrailing(func: () => void, wait: number): () => void;
|
package/lib/utils/async.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Throttle a function to be called at most once every "wait" milliseconds,
|
|
3
|
-
* on the trailing edge.
|
|
4
|
-
*
|
|
5
|
-
* Roughly equivalent to lodash/throttle with {leading: false, trailing: true}
|
|
6
|
-
*/
|
|
7
|
-
export function throttleTrailing(func, wait) {
|
|
8
|
-
let timeoutId = null;
|
|
9
|
-
const later = () => {
|
|
10
|
-
func();
|
|
11
|
-
timeoutId = null;
|
|
12
|
-
};
|
|
13
|
-
return function () {
|
|
14
|
-
if (timeoutId == null) {
|
|
15
|
-
timeoutId = setTimeout(later, wait);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Throttle a function to be called at most once every "wait" milliseconds,
|
|
21
|
-
* on the leading and trailing edge.
|
|
22
|
-
*
|
|
23
|
-
* Roughly equivalent to lodash/throttle with {leading: true, trailing: true}
|
|
24
|
-
*/
|
|
25
|
-
export function throttleLeadingTrailing(func, wait) {
|
|
26
|
-
let timeoutId = null;
|
|
27
|
-
let lastCallTime = 0;
|
|
28
|
-
const invokeFunction = () => {
|
|
29
|
-
func();
|
|
30
|
-
lastCallTime = Date.now();
|
|
31
|
-
timeoutId = null;
|
|
32
|
-
};
|
|
33
|
-
return function () {
|
|
34
|
-
const now = Date.now();
|
|
35
|
-
const timeToWait = wait - (now - lastCallTime);
|
|
36
|
-
if (timeToWait <= 0) {
|
|
37
|
-
// Leading edge: Call the function immediately if enough time has passed
|
|
38
|
-
invokeFunction();
|
|
39
|
-
}
|
|
40
|
-
else if (!timeoutId) {
|
|
41
|
-
// Set a timeout for the trailing edge if not already set
|
|
42
|
-
timeoutId = setTimeout(invokeFunction, timeToWait);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=async.js.map
|
package/lib/utils/async.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async.js","sourceRoot":"","sources":["../../src/utils/async.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAgB,EAAE,IAAY;IAC7D,IAAI,SAAS,GAAyC,IAAI,CAAC;IAE3D,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,IAAI,EAAE,CAAC;QACP,SAAS,GAAG,IAAI,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO;QACL,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,SAAS,GAAG,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACtC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAgB,EAAE,IAAY;IACpE,IAAI,SAAS,GAAyC,IAAI,CAAC;IAC3D,IAAI,YAAY,GAAW,CAAC,CAAC;IAE7B,MAAM,cAAc,GAAG,GAAG,EAAE;QAC1B,IAAI,EAAE,CAAC;QACP,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC1B,SAAS,GAAG,IAAI,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO;QACL,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,GAAG,GAAG,YAAY,CAAC,CAAC;QAE/C,IAAI,UAAU,IAAI,CAAC,EAAE,CAAC;YACpB,wEAAwE;YACxE,cAAc,EAAE,CAAC;QACnB,CAAC;aAAM,IAAI,CAAC,SAAS,EAAE,CAAC;YACtB,yDAAyD;YACzD,SAAS,GAAG,UAAU,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;QACrD,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/lib/utils/parseQuery.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const parseQuery = (query, parameters) => {
|
|
2
|
-
let sqlStatement;
|
|
3
|
-
if (typeof query == 'string') {
|
|
4
|
-
sqlStatement = query;
|
|
5
|
-
}
|
|
6
|
-
else {
|
|
7
|
-
const hasAdditionalParameters = parameters.length > 0;
|
|
8
|
-
if (hasAdditionalParameters) {
|
|
9
|
-
throw new Error('You cannot pass parameters to a compiled query.');
|
|
10
|
-
}
|
|
11
|
-
const compiled = query.compile();
|
|
12
|
-
sqlStatement = compiled.sql;
|
|
13
|
-
parameters = compiled.parameters;
|
|
14
|
-
}
|
|
15
|
-
return { sqlStatement, parameters: parameters };
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=parseQuery.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parseQuery.js","sourceRoot":"","sources":["../../src/utils/parseQuery.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAI,KAAkC,EAAE,UAAiB,EAAe,EAAE;IAClG,IAAI,YAAoB,CAAC;IAEzB,IAAI,OAAO,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC7B,YAAY,GAAG,KAAK,CAAC;IACvB,CAAC;SAAM,CAAC;QACN,MAAM,uBAAuB,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;QACtD,IAAI,uBAAuB,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QAED,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;QACjC,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC;QAC5B,UAAU,GAAG,QAAQ,CAAC,UAAmB,CAAC;IAC5C,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;AAClD,CAAC,CAAC"}
|
package/lib/utils/queue.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A simple fixed-capacity queue implementation.
|
|
3
|
-
*
|
|
4
|
-
* Unlike a naive queue implemented by `array.push()` and `array.shift()`, this avoids moving array elements around
|
|
5
|
-
* and is `O(1)` for {@link addLast} and {@link removeFirst}.
|
|
6
|
-
*/
|
|
7
|
-
export declare class Queue<T> {
|
|
8
|
-
private table;
|
|
9
|
-
private head;
|
|
10
|
-
private _length;
|
|
11
|
-
constructor(initialItems: Iterable<T>);
|
|
12
|
-
get isEmpty(): boolean;
|
|
13
|
-
get length(): number;
|
|
14
|
-
removeFirst(): T;
|
|
15
|
-
addLast(element: T): void;
|
|
16
|
-
}
|
package/lib/utils/queue.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A simple fixed-capacity queue implementation.
|
|
3
|
-
*
|
|
4
|
-
* Unlike a naive queue implemented by `array.push()` and `array.shift()`, this avoids moving array elements around
|
|
5
|
-
* and is `O(1)` for {@link addLast} and {@link removeFirst}.
|
|
6
|
-
*/
|
|
7
|
-
export class Queue {
|
|
8
|
-
table;
|
|
9
|
-
// Index of the first element in the table.
|
|
10
|
-
head;
|
|
11
|
-
// Amount of items currently in the queue.
|
|
12
|
-
_length;
|
|
13
|
-
constructor(initialItems) {
|
|
14
|
-
this.table = [...initialItems];
|
|
15
|
-
this.head = 0;
|
|
16
|
-
this._length = this.table.length;
|
|
17
|
-
}
|
|
18
|
-
get isEmpty() {
|
|
19
|
-
return this.length == 0;
|
|
20
|
-
}
|
|
21
|
-
get length() {
|
|
22
|
-
return this._length;
|
|
23
|
-
}
|
|
24
|
-
removeFirst() {
|
|
25
|
-
if (this.isEmpty) {
|
|
26
|
-
throw new Error('Queue is empty');
|
|
27
|
-
}
|
|
28
|
-
const result = this.table[this.head];
|
|
29
|
-
this._length--;
|
|
30
|
-
this.table[this.head] = undefined;
|
|
31
|
-
this.head = (this.head + 1) % this.table.length;
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
addLast(element) {
|
|
35
|
-
if (this.length == this.table.length) {
|
|
36
|
-
throw new Error('Queue is full');
|
|
37
|
-
}
|
|
38
|
-
this.table[(this.head + this._length) % this.table.length] = element;
|
|
39
|
-
this._length++;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=queue.js.map
|
package/lib/utils/queue.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../src/utils/queue.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,OAAO,KAAK;IACR,KAAK,CAAoB;IACjC,2CAA2C;IACnC,IAAI,CAAS;IACrB,0CAA0C;IAClC,OAAO,CAAS;IAExB,YAAY,YAA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-
* To keep data flow simple, we always pass an explicit cancellation token when subscribing to async streams. Once the
|
|
5
|
-
* {@link AbortSignal} aborts, iterators are supposed to clean up and then emit a final `{done: true}` event. This means
|
|
6
|
-
* that there's no way to distinguish between streams that have completed normally and streams that have been cancelled,
|
|
7
|
-
* but that is acceptable for our uses of this.
|
|
8
|
-
*/
|
|
9
|
-
export type SimpleAsyncIterator<T> = Pick<AsyncIterator<T>, 'next'>;
|
|
10
|
-
export declare const doneResult: IteratorReturnResult<any>;
|
|
11
|
-
export declare function valueResult<T>(value: T): {
|
|
12
|
-
done: boolean;
|
|
13
|
-
value: T;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* A variant of {@link Array.map} for async iterators.
|
|
17
|
-
*/
|
|
18
|
-
export declare function map<T1, T2>(source: SimpleAsyncIterator<T1>, map: (source: T1) => T2): SimpleAsyncIterator<T2>;
|
|
19
|
-
export interface InjectableIterator<T> extends SimpleAsyncIterator<T> {
|
|
20
|
-
inject(event: T): void;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Expands a source async iterator by allowing to inject events asynchronously.
|
|
24
|
-
*
|
|
25
|
-
* The resulting iterator will emit all events from its source. Additionally though, events can be injected. These
|
|
26
|
-
* events are dropped once the main iterator completes, but are otherwise forwarded.
|
|
27
|
-
*
|
|
28
|
-
* The iterator completes when its source completes, and it supports backpressure by only calling `next()` on the source
|
|
29
|
-
* in response to a `next()` call from downstream if no pending injected events can be dispatched.
|
|
30
|
-
*/
|
|
31
|
-
export declare function injectable<T>(source: SimpleAsyncIterator<T>): InjectableIterator<T>;
|
|
32
|
-
/**
|
|
33
|
-
* Splits a byte stream at line endings, emitting each line as a string.
|
|
34
|
-
*/
|
|
35
|
-
export declare function extractJsonLines(source: SimpleAsyncIterator<Uint8Array>, decoder: TextDecoder): SimpleAsyncIterator<string>;
|
|
36
|
-
/**
|
|
37
|
-
* Splits a concatenated stream of BSON objects by emitting individual objects.
|
|
38
|
-
*/
|
|
39
|
-
export declare function extractBsonObjects(source: SimpleAsyncIterator<Uint8Array>): SimpleAsyncIterator<Uint8Array>;
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
export const doneResult = { done: true, value: undefined };
|
|
2
|
-
export function valueResult(value) {
|
|
3
|
-
return { done: false, value };
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* A variant of {@link Array.map} for async iterators.
|
|
7
|
-
*/
|
|
8
|
-
export function map(source, map) {
|
|
9
|
-
return {
|
|
10
|
-
next: async () => {
|
|
11
|
-
const value = await source.next();
|
|
12
|
-
if (value.done) {
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
return { value: map(value.value) };
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Expands a source async iterator by allowing to inject events asynchronously.
|
|
23
|
-
*
|
|
24
|
-
* The resulting iterator will emit all events from its source. Additionally though, events can be injected. These
|
|
25
|
-
* events are dropped once the main iterator completes, but are otherwise forwarded.
|
|
26
|
-
*
|
|
27
|
-
* The iterator completes when its source completes, and it supports backpressure by only calling `next()` on the source
|
|
28
|
-
* in response to a `next()` call from downstream if no pending injected events can be dispatched.
|
|
29
|
-
*/
|
|
30
|
-
export function injectable(source) {
|
|
31
|
-
let sourceIsDone = false;
|
|
32
|
-
let waiter = undefined; // An active, waiting next() call.
|
|
33
|
-
// A pending upstream event that couldn't be dispatched because inject() has been called before it was resolved.
|
|
34
|
-
let pendingSourceEvent = null;
|
|
35
|
-
let pendingInjectedEvents = [];
|
|
36
|
-
const consumeWaiter = () => {
|
|
37
|
-
const pending = waiter;
|
|
38
|
-
waiter = undefined;
|
|
39
|
-
return pending;
|
|
40
|
-
};
|
|
41
|
-
const fetchFromSource = () => {
|
|
42
|
-
const resolveWaiter = (propagate) => {
|
|
43
|
-
const active = consumeWaiter();
|
|
44
|
-
if (active) {
|
|
45
|
-
propagate(active);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
pendingSourceEvent = propagate;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
const nextFromSource = source.next();
|
|
52
|
-
nextFromSource.then((value) => {
|
|
53
|
-
sourceIsDone = value.done == true;
|
|
54
|
-
resolveWaiter((w) => w.resolve(value));
|
|
55
|
-
}, (error) => {
|
|
56
|
-
resolveWaiter((w) => w.reject(error));
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
return {
|
|
60
|
-
next: () => {
|
|
61
|
-
return new Promise((resolve, reject) => {
|
|
62
|
-
// First priority: Dispatch ready upstream events.
|
|
63
|
-
if (sourceIsDone) {
|
|
64
|
-
return resolve(doneResult);
|
|
65
|
-
}
|
|
66
|
-
if (pendingSourceEvent) {
|
|
67
|
-
pendingSourceEvent({ resolve, reject });
|
|
68
|
-
pendingSourceEvent = null;
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
// Second priority: Dispatch injected events
|
|
72
|
-
if (pendingInjectedEvents.length) {
|
|
73
|
-
return resolve(valueResult(pendingInjectedEvents.shift()));
|
|
74
|
-
}
|
|
75
|
-
// Nothing pending? Fetch from source
|
|
76
|
-
waiter = { resolve, reject };
|
|
77
|
-
return fetchFromSource();
|
|
78
|
-
});
|
|
79
|
-
},
|
|
80
|
-
inject: (event) => {
|
|
81
|
-
const pending = consumeWaiter();
|
|
82
|
-
if (pending != null) {
|
|
83
|
-
pending.resolve(valueResult(event));
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
pendingInjectedEvents.push(event);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Splits a byte stream at line endings, emitting each line as a string.
|
|
93
|
-
*/
|
|
94
|
-
export function extractJsonLines(source, decoder) {
|
|
95
|
-
let buffer = '';
|
|
96
|
-
const pendingLines = [];
|
|
97
|
-
let isFinalEvent = false;
|
|
98
|
-
return {
|
|
99
|
-
next: async () => {
|
|
100
|
-
while (true) {
|
|
101
|
-
if (isFinalEvent) {
|
|
102
|
-
return doneResult;
|
|
103
|
-
}
|
|
104
|
-
{
|
|
105
|
-
const first = pendingLines.shift();
|
|
106
|
-
if (first) {
|
|
107
|
-
return { done: false, value: first };
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const { done, value } = await source.next();
|
|
111
|
-
if (done) {
|
|
112
|
-
const remaining = buffer.trim();
|
|
113
|
-
if (remaining.length != 0) {
|
|
114
|
-
isFinalEvent = true;
|
|
115
|
-
return { done: false, value: remaining };
|
|
116
|
-
}
|
|
117
|
-
return doneResult;
|
|
118
|
-
}
|
|
119
|
-
const data = decoder.decode(value, { stream: true });
|
|
120
|
-
buffer += data;
|
|
121
|
-
const lines = buffer.split('\n');
|
|
122
|
-
for (let i = 0; i < lines.length - 1; i++) {
|
|
123
|
-
const l = lines[i].trim();
|
|
124
|
-
if (l.length > 0) {
|
|
125
|
-
pendingLines.push(l);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
buffer = lines[lines.length - 1];
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Splits a concatenated stream of BSON objects by emitting individual objects.
|
|
135
|
-
*/
|
|
136
|
-
export function extractBsonObjects(source) {
|
|
137
|
-
// Fully read but not emitted yet.
|
|
138
|
-
const completedObjects = [];
|
|
139
|
-
// Whether source has returned { done: true }. We do the same once completed objects have been emitted.
|
|
140
|
-
let isDone = false;
|
|
141
|
-
const lengthBuffer = new DataView(new ArrayBuffer(4));
|
|
142
|
-
let objectBody = null;
|
|
143
|
-
// If we're parsing the length field, a number between 1 and 4 (inclusive) describing remaining bytes in the header.
|
|
144
|
-
// If we're consuming a document, the bytes remaining.
|
|
145
|
-
let remainingLength = 4;
|
|
146
|
-
return {
|
|
147
|
-
async next() {
|
|
148
|
-
while (true) {
|
|
149
|
-
// Before fetching new data from upstream, return completed objects.
|
|
150
|
-
if (completedObjects.length) {
|
|
151
|
-
return valueResult(completedObjects.shift());
|
|
152
|
-
}
|
|
153
|
-
if (isDone) {
|
|
154
|
-
return doneResult;
|
|
155
|
-
}
|
|
156
|
-
const upstreamEvent = await source.next();
|
|
157
|
-
if (upstreamEvent.done) {
|
|
158
|
-
isDone = true;
|
|
159
|
-
if (objectBody || remainingLength != 4) {
|
|
160
|
-
throw new Error('illegal end of stream in BSON object');
|
|
161
|
-
}
|
|
162
|
-
return doneResult;
|
|
163
|
-
}
|
|
164
|
-
const chunk = upstreamEvent.value;
|
|
165
|
-
for (let i = 0; i < chunk.length;) {
|
|
166
|
-
const availableInData = chunk.length - i;
|
|
167
|
-
if (objectBody) {
|
|
168
|
-
// We're in the middle of reading a BSON document.
|
|
169
|
-
const bytesToRead = Math.min(availableInData, remainingLength);
|
|
170
|
-
const copySource = new Uint8Array(chunk.buffer, chunk.byteOffset + i, bytesToRead);
|
|
171
|
-
objectBody.set(copySource, objectBody.length - remainingLength);
|
|
172
|
-
i += bytesToRead;
|
|
173
|
-
remainingLength -= bytesToRead;
|
|
174
|
-
if (remainingLength == 0) {
|
|
175
|
-
completedObjects.push(objectBody);
|
|
176
|
-
// Prepare to read another document, starting with its length
|
|
177
|
-
objectBody = null;
|
|
178
|
-
remainingLength = 4;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
// Copy up to 4 bytes into lengthBuffer, depending on how many we still need.
|
|
183
|
-
const bytesToRead = Math.min(availableInData, remainingLength);
|
|
184
|
-
for (let j = 0; j < bytesToRead; j++) {
|
|
185
|
-
lengthBuffer.setUint8(4 - remainingLength + j, chunk[i + j]);
|
|
186
|
-
}
|
|
187
|
-
i += bytesToRead;
|
|
188
|
-
remainingLength -= bytesToRead;
|
|
189
|
-
if (remainingLength == 0) {
|
|
190
|
-
// Transition from reading length header to reading document. Subtracting 4 because the length of the
|
|
191
|
-
// header is included in length.
|
|
192
|
-
const length = lengthBuffer.getInt32(0, true /* little endian */);
|
|
193
|
-
remainingLength = length - 4;
|
|
194
|
-
if (remainingLength < 1) {
|
|
195
|
-
throw new Error(`invalid length for bson: ${length}`);
|
|
196
|
-
}
|
|
197
|
-
objectBody = new Uint8Array(length);
|
|
198
|
-
new DataView(objectBody.buffer).setInt32(0, length, true);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
//# sourceMappingURL=stream_transform.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream_transform.js","sourceRoot":"","sources":["../../src/utils/stream_transform.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,UAAU,GAA8B,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAEtF,MAAM,UAAU,WAAW,CAAI,KAAQ;IACrC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,GAAG,CAAS,MAA+B,EAAE,GAAuB;IAClF,OAAO;QACL,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAClC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;gBACf,OAAO,KAAK,CAAC;YACf,CAAC;iBAAM,CAAC;gBACN,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAMD;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAI,MAA8B;IAG1D,IAAI,YAAY,GAAG,KAAK,CAAC;IACzB,IAAI,MAAM,GAAuB,SAAS,CAAC,CAAC,kCAAkC;IAC9E,gHAAgH;IAChH,IAAI,kBAAkB,GAAiC,IAAI,C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