@powersync/common 1.51.0 → 1.53.0

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.
Files changed (91) hide show
  1. package/dist/bundle.cjs +510 -1129
  2. package/dist/bundle.cjs.map +1 -1
  3. package/dist/bundle.mjs +511 -1116
  4. package/dist/bundle.mjs.map +1 -1
  5. package/dist/bundle.node.cjs +508 -1129
  6. package/dist/bundle.node.cjs.map +1 -1
  7. package/dist/bundle.node.mjs +509 -1116
  8. package/dist/bundle.node.mjs.map +1 -1
  9. package/dist/index.d.cts +73 -433
  10. package/legacy/sync_protocol.d.ts +103 -0
  11. package/lib/client/AbstractPowerSyncDatabase.js +3 -3
  12. package/lib/client/AbstractPowerSyncDatabase.js.map +1 -1
  13. package/lib/client/ConnectionManager.js +1 -1
  14. package/lib/client/ConnectionManager.js.map +1 -1
  15. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +6 -64
  16. package/lib/client/sync/bucket/BucketStorageAdapter.js +4 -0
  17. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +1 -1
  18. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +1 -28
  19. package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -162
  20. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -1
  21. package/lib/client/sync/stream/AbstractRemote.d.ts +29 -18
  22. package/lib/client/sync/stream/AbstractRemote.js +155 -188
  23. package/lib/client/sync/stream/AbstractRemote.js.map +1 -1
  24. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +13 -35
  25. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +150 -448
  26. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -1
  27. package/lib/client/sync/stream/JsonValue.d.ts +7 -0
  28. package/lib/client/sync/stream/JsonValue.js +2 -0
  29. package/lib/client/sync/stream/JsonValue.js.map +1 -0
  30. package/lib/client/sync/stream/core-instruction.d.ts +14 -9
  31. package/lib/client/sync/stream/core-instruction.js +3 -0
  32. package/lib/client/sync/stream/core-instruction.js.map +1 -1
  33. package/lib/db/DBAdapter.d.ts +9 -0
  34. package/lib/db/DBAdapter.js +8 -1
  35. package/lib/db/DBAdapter.js.map +1 -1
  36. package/lib/db/crud/SyncStatus.d.ts +3 -4
  37. package/lib/db/crud/SyncStatus.js +0 -4
  38. package/lib/db/crud/SyncStatus.js.map +1 -1
  39. package/lib/db/schema/RawTable.d.ts +0 -5
  40. package/lib/db/schema/Schema.d.ts +0 -2
  41. package/lib/db/schema/Schema.js +0 -2
  42. package/lib/db/schema/Schema.js.map +1 -1
  43. package/lib/index.d.ts +2 -6
  44. package/lib/index.js +1 -6
  45. package/lib/index.js.map +1 -1
  46. package/lib/utils/async.d.ts +0 -9
  47. package/lib/utils/async.js +0 -9
  48. package/lib/utils/async.js.map +1 -1
  49. package/lib/utils/stream_transform.d.ts +39 -0
  50. package/lib/utils/stream_transform.js +206 -0
  51. package/lib/utils/stream_transform.js.map +1 -0
  52. package/package.json +15 -10
  53. package/src/client/AbstractPowerSyncDatabase.ts +3 -3
  54. package/src/client/ConnectionManager.ts +1 -1
  55. package/src/client/sync/bucket/BucketStorageAdapter.ts +6 -71
  56. package/src/client/sync/bucket/SqliteBucketStorage.ts +1 -197
  57. package/src/client/sync/stream/AbstractRemote.ts +183 -229
  58. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +181 -510
  59. package/src/client/sync/stream/JsonValue.ts +8 -0
  60. package/src/client/sync/stream/core-instruction.ts +15 -5
  61. package/src/db/DBAdapter.ts +20 -2
  62. package/src/db/crud/SyncStatus.ts +4 -5
  63. package/src/db/schema/RawTable.ts +0 -5
  64. package/src/db/schema/Schema.ts +0 -2
  65. package/src/index.ts +2 -6
  66. package/src/utils/async.ts +0 -11
  67. package/src/utils/stream_transform.ts +252 -0
  68. package/lib/client/sync/bucket/OpType.d.ts +0 -16
  69. package/lib/client/sync/bucket/OpType.js +0 -23
  70. package/lib/client/sync/bucket/OpType.js.map +0 -1
  71. package/lib/client/sync/bucket/OplogEntry.d.ts +0 -23
  72. package/lib/client/sync/bucket/OplogEntry.js +0 -36
  73. package/lib/client/sync/bucket/OplogEntry.js.map +0 -1
  74. package/lib/client/sync/bucket/SyncDataBatch.d.ts +0 -6
  75. package/lib/client/sync/bucket/SyncDataBatch.js +0 -12
  76. package/lib/client/sync/bucket/SyncDataBatch.js.map +0 -1
  77. package/lib/client/sync/bucket/SyncDataBucket.d.ts +0 -40
  78. package/lib/client/sync/bucket/SyncDataBucket.js +0 -40
  79. package/lib/client/sync/bucket/SyncDataBucket.js.map +0 -1
  80. package/lib/client/sync/stream/streaming-sync-types.d.ts +0 -143
  81. package/lib/client/sync/stream/streaming-sync-types.js +0 -26
  82. package/lib/client/sync/stream/streaming-sync-types.js.map +0 -1
  83. package/lib/utils/DataStream.d.ts +0 -62
  84. package/lib/utils/DataStream.js +0 -169
  85. package/lib/utils/DataStream.js.map +0 -1
  86. package/src/client/sync/bucket/OpType.ts +0 -23
  87. package/src/client/sync/bucket/OplogEntry.ts +0 -50
  88. package/src/client/sync/bucket/SyncDataBatch.ts +0 -11
  89. package/src/client/sync/bucket/SyncDataBucket.ts +0 -49
  90. package/src/client/sync/stream/streaming-sync-types.ts +0 -210
  91. package/src/utils/DataStream.ts +0 -222
@@ -1,143 +0,0 @@
1
- import { BucketChecksum, Checkpoint } from '../bucket/BucketStorageAdapter.js';
2
- import { CrudEntry, OpId } from '../bucket/CrudEntry.js';
3
- import { SyncDataBucketJSON } from '../bucket/SyncDataBucket.js';
4
- /**
5
- * For sync2.json
6
- */
7
- export interface ContinueCheckpointRequest {
8
- /**
9
- * Existing bucket states. Only these buckets are synchronized.
10
- */
11
- buckets: BucketRequest[];
12
- checkpoint_token: string;
13
- limit?: number;
14
- }
15
- export interface SyncNewCheckpointRequest {
16
- /**
17
- * Existing bucket states. Used if include_data is specified.
18
- */
19
- buckets?: BucketRequest[];
20
- request_checkpoint: {
21
- /**
22
- * Whether or not to include an initial data request.
23
- */
24
- include_data: boolean;
25
- /**
26
- * Whether or not to compute a checksum.
27
- */
28
- include_checksum: boolean;
29
- };
30
- limit?: number;
31
- }
32
- export type SyncRequest = ContinueCheckpointRequest | SyncNewCheckpointRequest;
33
- export interface SyncResponse {
34
- /**
35
- * Data for the buckets returned. May not have an an entry for each bucket in the request.
36
- */
37
- data?: SyncDataBucketJSON[];
38
- /**
39
- * True if the response limit has been reached, and another request must be made.
40
- */
41
- has_more: boolean;
42
- checkpoint_token?: string;
43
- checkpoint?: Checkpoint;
44
- }
45
- type JSONValue = string | number | boolean | null | undefined | JSONObject | JSONArray;
46
- interface JSONObject {
47
- [key: string]: JSONValue;
48
- }
49
- type JSONArray = JSONValue[];
50
- export type StreamingSyncRequestParameterType = JSONValue;
51
- export interface StreamingSyncRequest {
52
- /**
53
- * Existing bucket states.
54
- */
55
- buckets?: BucketRequest[];
56
- /**
57
- * If specified, limit the response to only include these buckets.
58
- */
59
- only?: string[];
60
- /**
61
- * Whether or not to compute a checksum for each checkpoint
62
- */
63
- include_checksum: boolean;
64
- /**
65
- * Changes the response to stringified data in each OplogEntry
66
- */
67
- raw_data: boolean;
68
- /**
69
- * Client parameters to be passed to the sync rules.
70
- */
71
- parameters?: Record<string, StreamingSyncRequestParameterType>;
72
- /**
73
- * Application metadata to be included in service logs.
74
- */
75
- app_metadata?: Record<string, string>;
76
- client_id?: string;
77
- }
78
- export interface StreamingSyncCheckpoint {
79
- checkpoint: Checkpoint;
80
- }
81
- export interface StreamingSyncCheckpointDiff {
82
- checkpoint_diff: {
83
- last_op_id: OpId;
84
- updated_buckets: BucketChecksum[];
85
- removed_buckets: string[];
86
- write_checkpoint?: string;
87
- };
88
- }
89
- export interface StreamingSyncDataJSON {
90
- data: SyncDataBucketJSON;
91
- }
92
- export interface StreamingSyncCheckpointComplete {
93
- checkpoint_complete: {
94
- last_op_id: OpId;
95
- };
96
- }
97
- export interface StreamingSyncCheckpointPartiallyComplete {
98
- partial_checkpoint_complete: {
99
- priority: number;
100
- last_op_id: OpId;
101
- };
102
- }
103
- export interface StreamingSyncKeepalive {
104
- /** If specified, token expires in this many seconds. */
105
- token_expires_in: number;
106
- }
107
- export type StreamingSyncLine = StreamingSyncDataJSON | StreamingSyncCheckpoint | StreamingSyncCheckpointDiff | StreamingSyncCheckpointComplete | StreamingSyncCheckpointPartiallyComplete | StreamingSyncKeepalive;
108
- export type CrudUploadNotification = {
109
- crud_upload_completed: null;
110
- };
111
- export type StreamingSyncLineOrCrudUploadComplete = StreamingSyncLine | CrudUploadNotification;
112
- export interface BucketRequest {
113
- name: string;
114
- /**
115
- * Base-10 number. Sync all data from this bucket with op_id > after.
116
- */
117
- after: OpId;
118
- }
119
- export declare function isStreamingSyncData(line: StreamingSyncLine): line is StreamingSyncDataJSON;
120
- export declare function isStreamingKeepalive(line: StreamingSyncLine): line is StreamingSyncKeepalive;
121
- export declare function isStreamingSyncCheckpoint(line: StreamingSyncLine): line is StreamingSyncCheckpoint;
122
- export declare function isStreamingSyncCheckpointComplete(line: StreamingSyncLine): line is StreamingSyncCheckpointComplete;
123
- export declare function isStreamingSyncCheckpointPartiallyComplete(line: StreamingSyncLine): line is StreamingSyncCheckpointPartiallyComplete;
124
- export declare function isStreamingSyncCheckpointDiff(line: StreamingSyncLine): line is StreamingSyncCheckpointDiff;
125
- export declare function isContinueCheckpointRequest(request: SyncRequest): request is ContinueCheckpointRequest;
126
- export declare function isSyncNewCheckpointRequest(request: SyncRequest): request is SyncNewCheckpointRequest;
127
- /**
128
- * For crud.json
129
- */
130
- export interface CrudRequest {
131
- data: CrudEntry[];
132
- }
133
- export interface CrudResponse {
134
- /**
135
- * A sync response with a checkpoint >= this checkpoint would contain all the changes in this request.
136
- *
137
- * Any earlier checkpoint may or may not contain these changes.
138
- *
139
- * May be empty when the request contains no ops.
140
- */
141
- checkpoint?: OpId;
142
- }
143
- export {};
@@ -1,26 +0,0 @@
1
- export function isStreamingSyncData(line) {
2
- return line.data != null;
3
- }
4
- export function isStreamingKeepalive(line) {
5
- return line.token_expires_in != null;
6
- }
7
- export function isStreamingSyncCheckpoint(line) {
8
- return line.checkpoint != null;
9
- }
10
- export function isStreamingSyncCheckpointComplete(line) {
11
- return line.checkpoint_complete != null;
12
- }
13
- export function isStreamingSyncCheckpointPartiallyComplete(line) {
14
- return line.partial_checkpoint_complete != null;
15
- }
16
- export function isStreamingSyncCheckpointDiff(line) {
17
- return line.checkpoint_diff != null;
18
- }
19
- export function isContinueCheckpointRequest(request) {
20
- return (Array.isArray(request.buckets) &&
21
- typeof request.checkpoint_token == 'string');
22
- }
23
- export function isSyncNewCheckpointRequest(request) {
24
- return typeof request.request_checkpoint == 'object';
25
- }
26
- //# sourceMappingURL=streaming-sync-types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"streaming-sync-types.js","sourceRoot":"","sources":["../../../../src/client/sync/stream/streaming-sync-types.ts"],"names":[],"mappings":"AA4JA,MAAM,UAAU,mBAAmB,CAAC,IAAuB;IACzD,OAAQ,IAA8B,CAAC,IAAI,IAAI,IAAI,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,IAAuB;IAC1D,OAAQ,IAA+B,CAAC,gBAAgB,IAAI,IAAI,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,IAAuB;IAC/D,OAAQ,IAAgC,CAAC,UAAU,IAAI,IAAI,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,iCAAiC,CAAC,IAAuB;IACvE,OAAQ,IAAwC,CAAC,mBAAmB,IAAI,IAAI,CAAC;AAC/E,CAAC;AAED,MAAM,UAAU,0CAA0C,CACxD,IAAuB;IAEvB,OAAQ,IAAiD,CAAC,2BAA2B,IAAI,IAAI,CAAC;AAChG,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,IAAuB;IACnE,OAAQ,IAAoC,CAAC,eAAe,IAAI,IAAI,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,OAAoB;IAC9D,OAAO,CACL,KAAK,CAAC,OAAO,CAAE,OAAqC,CAAC,OAAO,CAAC;QAC7D,OAAQ,OAAqC,CAAC,gBAAgB,IAAI,QAAQ,CAC3E,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,OAAoB;IAC7D,OAAO,OAAQ,OAAoC,CAAC,kBAAkB,IAAI,QAAQ,CAAC;AACrF,CAAC"}
@@ -1,62 +0,0 @@
1
- import { ILogger } from 'js-logger';
2
- import { BaseListener, BaseObserver } from './BaseObserver.js';
3
- export type DataStreamOptions<ParsedData, SourceData> = {
4
- mapLine?: (line: SourceData) => ParsedData;
5
- /**
6
- * Close the stream if any consumer throws an error
7
- */
8
- closeOnError?: boolean;
9
- pressure?: {
10
- highWaterMark?: number;
11
- lowWaterMark?: number;
12
- };
13
- logger?: ILogger;
14
- };
15
- export type DataStreamCallback<Data extends any = any> = (data: Data) => Promise<void>;
16
- export interface DataStreamListener<Data extends any = any> extends BaseListener {
17
- data: (data: Data) => Promise<void>;
18
- closed: () => void;
19
- error: (error: Error) => void;
20
- highWater: () => Promise<void>;
21
- lowWater: () => Promise<void>;
22
- }
23
- export declare const DEFAULT_PRESSURE_LIMITS: {
24
- highWater: number;
25
- lowWater: number;
26
- };
27
- /**
28
- * A very basic implementation of a data stream with backpressure support which does not use
29
- * native JS streams or async iterators.
30
- * This is handy for environments such as React Native which need polyfills for the above.
31
- */
32
- export declare class DataStream<ParsedData, SourceData = any> extends BaseObserver<DataStreamListener<ParsedData>> {
33
- protected options?: DataStreamOptions<ParsedData, SourceData> | undefined;
34
- dataQueue: SourceData[];
35
- protected isClosed: boolean;
36
- protected processingPromise: Promise<void> | null;
37
- protected notifyDataAdded: (() => void) | null;
38
- protected logger: ILogger;
39
- protected mapLine: (line: SourceData) => ParsedData;
40
- constructor(options?: DataStreamOptions<ParsedData, SourceData> | undefined);
41
- get highWatermark(): number;
42
- get lowWatermark(): number;
43
- get closed(): boolean;
44
- close(): Promise<void>;
45
- /**
46
- * Enqueues data for the consumers to read
47
- */
48
- enqueueData(data: SourceData): void;
49
- /**
50
- * Reads data once from the data stream
51
- * @returns a Data payload or Null if the stream closed.
52
- */
53
- read(): Promise<ParsedData | null>;
54
- /**
55
- * Executes a callback for each data item in the stream
56
- */
57
- forEach(callback: DataStreamCallback<ParsedData>): () => void;
58
- protected processQueue(): Promise<void> | undefined;
59
- protected hasDataReader(): boolean;
60
- protected _processQueue(): Promise<void>;
61
- protected iterateAsyncErrored(cb: (l: Partial<DataStreamListener<ParsedData>>) => Promise<void>): Promise<void>;
62
- }
@@ -1,169 +0,0 @@
1
- import Logger from 'js-logger';
2
- import { BaseObserver } from './BaseObserver.js';
3
- export const DEFAULT_PRESSURE_LIMITS = {
4
- highWater: 10,
5
- lowWater: 0
6
- };
7
- /**
8
- * A very basic implementation of a data stream with backpressure support which does not use
9
- * native JS streams or async iterators.
10
- * This is handy for environments such as React Native which need polyfills for the above.
11
- */
12
- export class DataStream extends BaseObserver {
13
- options;
14
- dataQueue;
15
- isClosed;
16
- processingPromise;
17
- notifyDataAdded;
18
- logger;
19
- mapLine;
20
- constructor(options) {
21
- super();
22
- this.options = options;
23
- this.processingPromise = null;
24
- this.isClosed = false;
25
- this.dataQueue = [];
26
- this.mapLine = options?.mapLine ?? ((line) => line);
27
- this.logger = options?.logger ?? Logger.get('DataStream');
28
- if (options?.closeOnError) {
29
- const l = this.registerListener({
30
- error: (ex) => {
31
- l?.();
32
- this.close();
33
- }
34
- });
35
- }
36
- }
37
- get highWatermark() {
38
- return this.options?.pressure?.highWaterMark ?? DEFAULT_PRESSURE_LIMITS.highWater;
39
- }
40
- get lowWatermark() {
41
- return this.options?.pressure?.lowWaterMark ?? DEFAULT_PRESSURE_LIMITS.lowWater;
42
- }
43
- get closed() {
44
- return this.isClosed;
45
- }
46
- async close() {
47
- this.isClosed = true;
48
- await this.processingPromise;
49
- this.iterateListeners((l) => l.closed?.());
50
- // Discard any data in the queue
51
- this.dataQueue = [];
52
- this.listeners.clear();
53
- }
54
- /**
55
- * Enqueues data for the consumers to read
56
- */
57
- enqueueData(data) {
58
- if (this.isClosed) {
59
- throw new Error('Cannot enqueue data into closed stream.');
60
- }
61
- this.dataQueue.push(data);
62
- this.notifyDataAdded?.();
63
- this.processQueue();
64
- }
65
- /**
66
- * Reads data once from the data stream
67
- * @returns a Data payload or Null if the stream closed.
68
- */
69
- async read() {
70
- if (this.closed) {
71
- return null;
72
- }
73
- // Wait for any pending processing to complete first.
74
- // This ensures we register our listener before calling processQueue(),
75
- // avoiding a race where processQueue() sees no reader and returns early.
76
- if (this.processingPromise) {
77
- await this.processingPromise;
78
- }
79
- // Re-check after await - stream may have closed while we were waiting
80
- if (this.closed) {
81
- return null;
82
- }
83
- return new Promise((resolve, reject) => {
84
- const l = this.registerListener({
85
- data: async (data) => {
86
- resolve(data);
87
- // Remove the listener
88
- l?.();
89
- },
90
- closed: () => {
91
- resolve(null);
92
- l?.();
93
- },
94
- error: (ex) => {
95
- reject(ex);
96
- l?.();
97
- }
98
- });
99
- this.processQueue();
100
- });
101
- }
102
- /**
103
- * Executes a callback for each data item in the stream
104
- */
105
- forEach(callback) {
106
- if (this.dataQueue.length <= this.lowWatermark) {
107
- this.iterateAsyncErrored(async (l) => l.lowWater?.());
108
- }
109
- return this.registerListener({
110
- data: callback
111
- });
112
- }
113
- processQueue() {
114
- if (this.processingPromise) {
115
- return;
116
- }
117
- const promise = (this.processingPromise = this._processQueue());
118
- promise.finally(() => {
119
- this.processingPromise = null;
120
- });
121
- return promise;
122
- }
123
- hasDataReader() {
124
- return Array.from(this.listeners.values()).some((l) => !!l.data);
125
- }
126
- async _processQueue() {
127
- /**
128
- * Allow listeners to mutate the queue before processing.
129
- * This allows for operations such as dropping or compressing data
130
- * on high water or requesting more data on low water.
131
- */
132
- if (this.dataQueue.length >= this.highWatermark) {
133
- await this.iterateAsyncErrored(async (l) => l.highWater?.());
134
- }
135
- if (this.isClosed || !this.hasDataReader()) {
136
- return;
137
- }
138
- if (this.dataQueue.length) {
139
- const data = this.dataQueue.shift();
140
- const mapped = this.mapLine(data);
141
- await this.iterateAsyncErrored(async (l) => l.data?.(mapped));
142
- }
143
- if (this.dataQueue.length <= this.lowWatermark) {
144
- const dataAdded = new Promise((resolve) => {
145
- this.notifyDataAdded = resolve;
146
- });
147
- await Promise.race([this.iterateAsyncErrored(async (l) => l.lowWater?.()), dataAdded]);
148
- this.notifyDataAdded = null;
149
- }
150
- if (this.dataQueue.length > 0) {
151
- setTimeout(() => this.processQueue());
152
- }
153
- }
154
- async iterateAsyncErrored(cb) {
155
- // Important: We need to copy the listeners, as calling a listener could result in adding another
156
- // listener, resulting in infinite loops.
157
- const listeners = Array.from(this.listeners.values());
158
- for (let i of listeners) {
159
- try {
160
- await cb(i);
161
- }
162
- catch (ex) {
163
- this.logger.error(ex);
164
- this.iterateListeners((l) => l.error?.(ex));
165
- }
166
- }
167
- }
168
- }
169
- //# sourceMappingURL=DataStream.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DataStream.js","sourceRoot":"","sources":["../../src/utils/DataStream.ts"],"names":[],"mappings":"AAAA,OAAO,MAAmB,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAgB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AA0B/D,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,SAAS,EAAE,EAAE;IACb,QAAQ,EAAE,CAAC;CACZ,CAAC;AAEF;;;;GAIG;AACH,MAAM,OAAO,UAAyC,SAAQ,YAA4C;IAYlF;IAXtB,SAAS,CAAe;IAEd,QAAQ,CAAU;IAElB,iBAAiB,CAAuB;IACxC,eAAe,CAAsB;IAErC,MAAM,CAAU;IAEhB,OAAO,CAAmC;IAEpD,YAAsB,OAAmD;QACvE,KAAK,EAAE,CAAC;QADY,YAAO,GAAP,OAAO,CAA4C;QAEvE,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAA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CAAC,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -1,23 +0,0 @@
1
- export enum OpTypeEnum {
2
- CLEAR = 1,
3
- MOVE = 2,
4
- PUT = 3,
5
- REMOVE = 4
6
- }
7
-
8
- export type OpTypeJSON = string;
9
-
10
- /**
11
- * Used internally for sync buckets.
12
- */
13
- export class OpType {
14
- static fromJSON(jsonValue: OpTypeJSON) {
15
- return new OpType(OpTypeEnum[jsonValue]);
16
- }
17
-
18
- constructor(public value: OpTypeEnum) {}
19
-
20
- toJSON() {
21
- return Object.entries(OpTypeEnum).find(([, value]) => value === this.value)![0];
22
- }
23
- }
@@ -1,50 +0,0 @@
1
- import { OpId } from './CrudEntry.js';
2
- import { OpType, OpTypeJSON } from './OpType.js';
3
-
4
- export interface OplogEntryJSON {
5
- checksum: number;
6
- data?: string;
7
- object_id?: string;
8
- object_type?: string;
9
- op_id: string;
10
- op: OpTypeJSON;
11
- subkey?: string;
12
- }
13
-
14
- export class OplogEntry {
15
- static fromRow(row: OplogEntryJSON) {
16
- return new OplogEntry(
17
- row.op_id,
18
- OpType.fromJSON(row.op),
19
- row.checksum,
20
- row.subkey,
21
- row.object_type,
22
- row.object_id,
23
- row.data
24
- );
25
- }
26
-
27
- constructor(
28
- public op_id: OpId,
29
- public op: OpType,
30
- public checksum: number,
31
- public subkey?: string,
32
- public object_type?: string,
33
- public object_id?: string,
34
- public data?: string
35
- ) {}
36
-
37
- toJSON(fixedKeyEncoding = false): OplogEntryJSON {
38
- return {
39
- op_id: this.op_id,
40
- op: this.op.toJSON(),
41
- object_type: this.object_type,
42
- object_id: this.object_id,
43
- checksum: this.checksum,
44
- data: this.data,
45
- // Older versions of the JS SDK used to always JSON.stringify here. That has always been wrong,
46
- // but we need to migrate gradually to not break existing databases.
47
- subkey: fixedKeyEncoding ? this.subkey : JSON.stringify(this.subkey)
48
- };
49
- }
50
- }
@@ -1,11 +0,0 @@
1
- import { SyncDataBucket } from './SyncDataBucket.js';
2
-
3
- // TODO JSON
4
-
5
- export class SyncDataBatch {
6
- static fromJSON(json: any) {
7
- return new SyncDataBatch(json.buckets.map((bucket: any) => SyncDataBucket.fromRow(bucket)));
8
- }
9
-
10
- constructor(public buckets: SyncDataBucket[]) {}
11
- }
@@ -1,49 +0,0 @@
1
- import { OpId } from './CrudEntry.js';
2
- import { OplogEntry, OplogEntryJSON } from './OplogEntry.js';
3
-
4
- export type SyncDataBucketJSON = {
5
- bucket: string;
6
- has_more?: boolean;
7
- after?: string;
8
- next_after?: string;
9
- data: OplogEntryJSON[];
10
- };
11
-
12
- export class SyncDataBucket {
13
- static fromRow(row: SyncDataBucketJSON) {
14
- return new SyncDataBucket(
15
- row.bucket,
16
- row.data.map((entry) => OplogEntry.fromRow(entry)),
17
- row.has_more ?? false,
18
- row.after,
19
- row.next_after
20
- );
21
- }
22
-
23
- constructor(
24
- public bucket: string,
25
- public data: OplogEntry[],
26
- /**
27
- * True if the response does not contain all the data for this bucket, and another request must be made.
28
- */
29
- public has_more: boolean,
30
- /**
31
- * The `after` specified in the request.
32
- */
33
- public after?: OpId,
34
- /**
35
- * Use this for the next request.
36
- */
37
- public next_after?: OpId
38
- ) {}
39
-
40
- toJSON(fixedKeyEncoding = false): SyncDataBucketJSON {
41
- return {
42
- bucket: this.bucket,
43
- has_more: this.has_more,
44
- after: this.after,
45
- next_after: this.next_after,
46
- data: this.data.map((entry) => entry.toJSON(fixedKeyEncoding))
47
- };
48
- }
49
- }