@powersync/common 1.6.1

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 (93) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +6 -0
  3. package/lib/client/AbstractPowerSyncDatabase.d.ts +367 -0
  4. package/lib/client/AbstractPowerSyncDatabase.js +645 -0
  5. package/lib/client/AbstractPowerSyncDatabase.js.map +1 -0
  6. package/lib/client/AbstractPowerSyncOpenFactory.d.ts +29 -0
  7. package/lib/client/AbstractPowerSyncOpenFactory.js +25 -0
  8. package/lib/client/AbstractPowerSyncOpenFactory.js.map +1 -0
  9. package/lib/client/connection/PowerSyncBackendConnector.d.ts +23 -0
  10. package/lib/client/connection/PowerSyncBackendConnector.js +2 -0
  11. package/lib/client/connection/PowerSyncBackendConnector.js.map +1 -0
  12. package/lib/client/connection/PowerSyncCredentials.d.ts +5 -0
  13. package/lib/client/connection/PowerSyncCredentials.js +2 -0
  14. package/lib/client/connection/PowerSyncCredentials.js.map +1 -0
  15. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +71 -0
  16. package/lib/client/sync/bucket/BucketStorageAdapter.js +8 -0
  17. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +1 -0
  18. package/lib/client/sync/bucket/CrudBatch.d.ts +31 -0
  19. package/lib/client/sync/bucket/CrudBatch.js +26 -0
  20. package/lib/client/sync/bucket/CrudBatch.js.map +1 -0
  21. package/lib/client/sync/bucket/CrudEntry.d.ts +86 -0
  22. package/lib/client/sync/bucket/CrudEntry.js +85 -0
  23. package/lib/client/sync/bucket/CrudEntry.js.map +1 -0
  24. package/lib/client/sync/bucket/CrudTransaction.d.ts +29 -0
  25. package/lib/client/sync/bucket/CrudTransaction.js +25 -0
  26. package/lib/client/sync/bucket/CrudTransaction.js.map +1 -0
  27. package/lib/client/sync/bucket/OpType.d.ts +16 -0
  28. package/lib/client/sync/bucket/OpType.js +23 -0
  29. package/lib/client/sync/bucket/OpType.js.map +1 -0
  30. package/lib/client/sync/bucket/OplogEntry.d.ts +23 -0
  31. package/lib/client/sync/bucket/OplogEntry.js +34 -0
  32. package/lib/client/sync/bucket/OplogEntry.js.map +1 -0
  33. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +66 -0
  34. package/lib/client/sync/bucket/SqliteBucketStorage.js +299 -0
  35. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -0
  36. package/lib/client/sync/bucket/SyncDataBatch.d.ts +6 -0
  37. package/lib/client/sync/bucket/SyncDataBatch.js +12 -0
  38. package/lib/client/sync/bucket/SyncDataBatch.js.map +1 -0
  39. package/lib/client/sync/bucket/SyncDataBucket.d.ts +40 -0
  40. package/lib/client/sync/bucket/SyncDataBucket.js +41 -0
  41. package/lib/client/sync/bucket/SyncDataBucket.js.map +1 -0
  42. package/lib/client/sync/stream/AbstractRemote.d.ts +25 -0
  43. package/lib/client/sync/stream/AbstractRemote.js +43 -0
  44. package/lib/client/sync/stream/AbstractRemote.js.map +1 -0
  45. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +101 -0
  46. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +478 -0
  47. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -0
  48. package/lib/client/sync/stream/streaming-sync-types.d.ts +116 -0
  49. package/lib/client/sync/stream/streaming-sync-types.js +23 -0
  50. package/lib/client/sync/stream/streaming-sync-types.js.map +1 -0
  51. package/lib/db/Column.d.ts +19 -0
  52. package/lib/db/Column.js +26 -0
  53. package/lib/db/Column.js.map +1 -0
  54. package/lib/db/DBAdapter.d.ts +95 -0
  55. package/lib/db/DBAdapter.js +20 -0
  56. package/lib/db/DBAdapter.js.map +1 -0
  57. package/lib/db/crud/SyncStatus.d.ts +38 -0
  58. package/lib/db/crud/SyncStatus.js +58 -0
  59. package/lib/db/crud/SyncStatus.js.map +1 -0
  60. package/lib/db/crud/UploadQueueStatus.d.ts +20 -0
  61. package/lib/db/crud/UploadQueueStatus.js +25 -0
  62. package/lib/db/crud/UploadQueueStatus.js.map +1 -0
  63. package/lib/db/schema/Index.d.ts +22 -0
  64. package/lib/db/schema/Index.js +30 -0
  65. package/lib/db/schema/Index.js.map +1 -0
  66. package/lib/db/schema/IndexedColumn.d.ts +19 -0
  67. package/lib/db/schema/IndexedColumn.js +30 -0
  68. package/lib/db/schema/IndexedColumn.js.map +1 -0
  69. package/lib/db/schema/Schema.d.ts +38 -0
  70. package/lib/db/schema/Schema.js +38 -0
  71. package/lib/db/schema/Schema.js.map +1 -0
  72. package/lib/db/schema/Table.d.ts +51 -0
  73. package/lib/db/schema/Table.js +114 -0
  74. package/lib/db/schema/Table.js.map +1 -0
  75. package/lib/db/schema/TableV2.d.ts +30 -0
  76. package/lib/db/schema/TableV2.js +44 -0
  77. package/lib/db/schema/TableV2.js.map +1 -0
  78. package/lib/index.d.ts +30 -0
  79. package/lib/index.js +31 -0
  80. package/lib/index.js.map +1 -0
  81. package/lib/utils/AbortOperation.d.ts +9 -0
  82. package/lib/utils/AbortOperation.js +19 -0
  83. package/lib/utils/AbortOperation.js.map +1 -0
  84. package/lib/utils/BaseObserver.d.ts +20 -0
  85. package/lib/utils/BaseObserver.js +23 -0
  86. package/lib/utils/BaseObserver.js.map +1 -0
  87. package/lib/utils/mutex.d.ts +7 -0
  88. package/lib/utils/mutex.js +29 -0
  89. package/lib/utils/mutex.js.map +1 -0
  90. package/lib/utils/strings.d.ts +3 -0
  91. package/lib/utils/strings.js +10 -0
  92. package/lib/utils/strings.js.map +1 -0
  93. package/package.json +42 -0
@@ -0,0 +1,29 @@
1
+ import { DBAdapter } from '../db/DBAdapter';
2
+ import { Schema } from '../db/schema/Schema';
3
+ import { AbstractPowerSyncDatabase, PowerSyncDatabaseOptions } from './AbstractPowerSyncDatabase';
4
+ export interface PowerSyncOpenFactoryOptions extends Partial<PowerSyncDatabaseOptions> {
5
+ /** Schema used for the local database. */
6
+ schema: Schema;
7
+ /**
8
+ * Filename for the database.
9
+ */
10
+ dbFilename: string;
11
+ /**
12
+ * Directory where the database file is located.
13
+ */
14
+ dbLocation?: string;
15
+ }
16
+ export declare abstract class AbstractPowerSyncDatabaseOpenFactory {
17
+ protected options: PowerSyncOpenFactoryOptions;
18
+ constructor(options: PowerSyncOpenFactoryOptions);
19
+ /**
20
+ * Schema used for the local database.
21
+ */
22
+ get schema(): Schema<{
23
+ [x: string]: import("..").TableV2<any>;
24
+ }>;
25
+ protected abstract openDB(): DBAdapter;
26
+ generateOptions(): PowerSyncDatabaseOptions;
27
+ abstract generateInstance(options: PowerSyncDatabaseOptions): AbstractPowerSyncDatabase;
28
+ getInstance(): AbstractPowerSyncDatabase;
29
+ }
@@ -0,0 +1,25 @@
1
+ import Logger from 'js-logger';
2
+ export class AbstractPowerSyncDatabaseOpenFactory {
3
+ options;
4
+ constructor(options) {
5
+ this.options = options;
6
+ options.logger = options.logger ?? Logger.get(`PowerSync ${this.options.dbFilename}`);
7
+ }
8
+ /**
9
+ * Schema used for the local database.
10
+ */
11
+ get schema() {
12
+ return this.options.schema;
13
+ }
14
+ generateOptions() {
15
+ return {
16
+ database: this.openDB(),
17
+ ...this.options
18
+ };
19
+ }
20
+ getInstance() {
21
+ const options = this.generateOptions();
22
+ return this.generateInstance(options);
23
+ }
24
+ }
25
+ //# sourceMappingURL=AbstractPowerSyncOpenFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractPowerSyncOpenFactory.js","sourceRoot":"","sources":["../../src/client/AbstractPowerSyncOpenFactory.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,WAAW,CAAC;AAkB/B,MAAM,OAAgB,oCAAoC;IAClC;IAAtB,YAAsB,OAAoC;QAApC,YAAO,GAAP,OAAO,CAA6B;QACxD,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IACxF,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;IAID,eAAe;QACb,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE;YACvB,GAAG,IAAI,CAAC,OAAO;SAChB,CAAC;IACJ,CAAC;IAID,WAAW;QACT,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACvC,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;CACF"}
@@ -0,0 +1,23 @@
1
+ import { PowerSyncCredentials } from './PowerSyncCredentials';
2
+ import type { AbstractPowerSyncDatabase } from '../AbstractPowerSyncDatabase';
3
+ export interface PowerSyncBackendConnector {
4
+ /** Allows the PowerSync client to retrieve an authentication token from your backend
5
+ * which is used to authenticate against the PowerSync service.
6
+ *
7
+ * This should always fetch a fresh set of credentials - don't use cached
8
+ * values.
9
+ *
10
+ * Return null if the user is not signed in. Throw an error if credentials
11
+ * cannot be fetched due to a network error or other temporary error.
12
+ *
13
+ * This token is kept for the duration of a sync connection.
14
+ */
15
+ fetchCredentials: () => Promise<PowerSyncCredentials | null>;
16
+ /** Upload local changes to the app backend.
17
+ *
18
+ * Use {@link AbstractPowerSyncDatabase.getCrudBatch} to get a batch of changes to upload.
19
+ *
20
+ * Any thrown errors will result in a retry after the configured wait period (default: 5 seconds).
21
+ */
22
+ uploadData: (database: AbstractPowerSyncDatabase) => Promise<void>;
23
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PowerSyncBackendConnector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PowerSyncBackendConnector.js","sourceRoot":"","sources":["../../../src/client/connection/PowerSyncBackendConnector.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export interface PowerSyncCredentials {
2
+ endpoint: string;
3
+ token: string;
4
+ expiresAt?: Date;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PowerSyncCredentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PowerSyncCredentials.js","sourceRoot":"","sources":["../../../src/client/connection/PowerSyncCredentials.ts"],"names":[],"mappings":""}
@@ -0,0 +1,71 @@
1
+ import { OpId } from './CrudEntry';
2
+ import { CrudBatch } from './CrudBatch';
3
+ import { SyncDataBatch } from './SyncDataBatch';
4
+ import { BaseListener, BaseObserver, Disposable } from '../../../utils/BaseObserver';
5
+ export interface Checkpoint {
6
+ last_op_id: OpId;
7
+ buckets: BucketChecksum[];
8
+ write_checkpoint?: string;
9
+ }
10
+ export interface BucketState {
11
+ bucket: string;
12
+ op_id: string;
13
+ }
14
+ export interface ChecksumCache {
15
+ checksums: Map<string, {
16
+ checksum: BucketChecksum;
17
+ last_op_id: OpId;
18
+ }>;
19
+ lastOpId: OpId;
20
+ }
21
+ export interface SyncLocalDatabaseResult {
22
+ ready: boolean;
23
+ checkpointValid: boolean;
24
+ checkpointFailures?: string[];
25
+ }
26
+ export interface BucketChecksum {
27
+ bucket: string;
28
+ /**
29
+ * 32-bit unsigned hash.
30
+ */
31
+ checksum: number;
32
+ /**
33
+ * Count of operations - informational only.
34
+ */
35
+ count?: number;
36
+ }
37
+ export declare enum PSInternalTable {
38
+ DATA = "ps_data",
39
+ CRUD = "ps_crud",
40
+ BUCKETS = "ps_buckets",
41
+ OPLOG = "ps_oplog"
42
+ }
43
+ export interface BucketStorageListener extends BaseListener {
44
+ crudUpdate: () => void;
45
+ }
46
+ export interface BucketStorageAdapter extends BaseObserver<BucketStorageListener>, Disposable {
47
+ init(): Promise<void>;
48
+ saveSyncData(batch: SyncDataBatch): Promise<void>;
49
+ removeBuckets(buckets: string[]): Promise<void>;
50
+ setTargetCheckpoint(checkpoint: Checkpoint): Promise<void>;
51
+ startSession(): void;
52
+ getBucketStates(): Promise<BucketState[]>;
53
+ syncLocalDatabase(checkpoint: Checkpoint): Promise<{
54
+ checkpointValid: boolean;
55
+ ready: boolean;
56
+ failures?: any[];
57
+ }>;
58
+ hasCrud(): Promise<boolean>;
59
+ getCrudBatch(limit?: number): Promise<CrudBatch | null>;
60
+ hasCompletedSync(): Promise<boolean>;
61
+ updateLocalTarget(cb: () => Promise<string>): Promise<boolean>;
62
+ /**
63
+ * Exposed for tests only.
64
+ */
65
+ autoCompact(): Promise<void>;
66
+ /**
67
+ * Exposed for tests only.
68
+ */
69
+ forceCompact(): Promise<void>;
70
+ getMaxOpId(): string;
71
+ }
@@ -0,0 +1,8 @@
1
+ export var PSInternalTable;
2
+ (function (PSInternalTable) {
3
+ PSInternalTable["DATA"] = "ps_data";
4
+ PSInternalTable["CRUD"] = "ps_crud";
5
+ PSInternalTable["BUCKETS"] = "ps_buckets";
6
+ PSInternalTable["OPLOG"] = "ps_oplog";
7
+ })(PSInternalTable || (PSInternalTable = {}));
8
+ //# sourceMappingURL=BucketStorageAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BucketStorageAdapter.js","sourceRoot":"","sources":["../../../../src/client/sync/bucket/BucketStorageAdapter.ts"],"names":[],"mappings":"AAwCA,MAAM,CAAN,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,mCAAgB,CAAA;IAChB,mCAAgB,CAAA;IAChB,yCAAsB,CAAA;IACtB,qCAAkB,CAAA;AACpB,CAAC,EALW,eAAe,KAAf,eAAe,QAK1B"}
@@ -0,0 +1,31 @@
1
+ import { CrudEntry } from './CrudEntry';
2
+ /**
3
+ * A batch of client-side changes.
4
+ */
5
+ export declare class CrudBatch {
6
+ /**
7
+ * List of client-side changes.
8
+ */
9
+ crud: CrudEntry[];
10
+ /**
11
+ * true if there are more changes in the local queue.
12
+ */
13
+ haveMore: boolean;
14
+ /**
15
+ * Call to remove the changes from the local queue, once successfully uploaded.
16
+ */
17
+ complete: (writeCheckpoint?: string) => Promise<void>;
18
+ constructor(
19
+ /**
20
+ * List of client-side changes.
21
+ */
22
+ crud: CrudEntry[],
23
+ /**
24
+ * true if there are more changes in the local queue.
25
+ */
26
+ haveMore: boolean,
27
+ /**
28
+ * Call to remove the changes from the local queue, once successfully uploaded.
29
+ */
30
+ complete: (writeCheckpoint?: string) => Promise<void>);
31
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * A batch of client-side changes.
3
+ */
4
+ export class CrudBatch {
5
+ crud;
6
+ haveMore;
7
+ complete;
8
+ constructor(
9
+ /**
10
+ * List of client-side changes.
11
+ */
12
+ crud,
13
+ /**
14
+ * true if there are more changes in the local queue.
15
+ */
16
+ haveMore,
17
+ /**
18
+ * Call to remove the changes from the local queue, once successfully uploaded.
19
+ */
20
+ complete) {
21
+ this.crud = crud;
22
+ this.haveMore = haveMore;
23
+ this.complete = complete;
24
+ }
25
+ }
26
+ //# sourceMappingURL=CrudBatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CrudBatch.js","sourceRoot":"","sources":["../../../../src/client/sync/bucket/CrudBatch.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,SAAS;IAKX;IAIA;IAIA;IAZT;IACE;;OAEG;IACI,IAAiB;IACxB;;OAEG;IACI,QAAiB;IACxB;;OAEG;IACI,QAAqD;QARrD,SAAI,GAAJ,IAAI,CAAa;QAIjB,aAAQ,GAAR,QAAQ,CAAS;QAIjB,aAAQ,GAAR,QAAQ,CAA6C;IAC3D,CAAC;CACL"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * 64-bit unsigned integer stored as a string in base-10.
3
+ *
4
+ * Not sortable as a string.
5
+ */
6
+ export type OpId = string;
7
+ /**
8
+ * Type of local change.
9
+ */
10
+ export declare enum UpdateType {
11
+ /** Insert or replace existing row. All non-null columns are included in the data. Generated by INSERT statements. */
12
+ PUT = "PUT",
13
+ /** Update existing row. Contains the id, and value of each changed column. Generated by UPDATE statements. */
14
+ PATCH = "PATCH",
15
+ /** Delete existing row. Contains the id. Generated by DELETE statements. */
16
+ DELETE = "DELETE"
17
+ }
18
+ export type CrudEntryJSON = {
19
+ id: string;
20
+ data: string;
21
+ tx_id?: number;
22
+ };
23
+ export type CrudEntryDataJSON = {
24
+ data: Record<string, any>;
25
+ op: UpdateType;
26
+ type: string;
27
+ id: string;
28
+ };
29
+ /**
30
+ * The output JSON seems to be a third type of JSON, not the same as the input JSON.
31
+ */
32
+ export type CrudEntryOutputJSON = {
33
+ op_id: number;
34
+ op: UpdateType;
35
+ type: string;
36
+ id: string;
37
+ tx_id?: number;
38
+ data?: Record<string, any>;
39
+ };
40
+ /**
41
+ * A single client-side change.
42
+ */
43
+ export declare class CrudEntry {
44
+ /**
45
+ * Auto-incrementing client-side id.
46
+ */
47
+ clientId: number;
48
+ /**
49
+ * ID of the changed row.
50
+ */
51
+ id: string;
52
+ /**
53
+ * Type of change.
54
+ */
55
+ op: UpdateType;
56
+ /**
57
+ * Data associated with the change.
58
+ */
59
+ opData?: Record<string, any>;
60
+ /**
61
+ * Table that contained the change.
62
+ */
63
+ table: string;
64
+ /**
65
+ * Auto-incrementing transaction id. This is the same for all operations within the same transaction.
66
+ */
67
+ transactionId?: number;
68
+ static fromRow(dbRow: CrudEntryJSON): CrudEntry;
69
+ constructor(clientId: number, op: UpdateType, table: string, id: string, transactionId?: number, opData?: Record<string, any>);
70
+ /**
71
+ * Converts the change to JSON format.
72
+ */
73
+ toJSON(): CrudEntryOutputJSON;
74
+ equals(entry: CrudEntry): boolean;
75
+ /**
76
+ * The hash code for this object.
77
+ * @deprecated This should not be necessary in the JS SDK.
78
+ * Use the @see CrudEntry#equals method instead.
79
+ * TODO remove in the next major release.
80
+ */
81
+ hashCode(): string;
82
+ /**
83
+ * Generates an array for use in deep comparison operations
84
+ */
85
+ toComparisonArray(): (string | number | Record<string, any> | undefined)[];
86
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Type of local change.
3
+ */
4
+ export var UpdateType;
5
+ (function (UpdateType) {
6
+ /** Insert or replace existing row. All non-null columns are included in the data. Generated by INSERT statements. */
7
+ UpdateType["PUT"] = "PUT";
8
+ /** Update existing row. Contains the id, and value of each changed column. Generated by UPDATE statements. */
9
+ UpdateType["PATCH"] = "PATCH";
10
+ /** Delete existing row. Contains the id. Generated by DELETE statements. */
11
+ UpdateType["DELETE"] = "DELETE";
12
+ })(UpdateType || (UpdateType = {}));
13
+ /**
14
+ * A single client-side change.
15
+ */
16
+ export class CrudEntry {
17
+ /**
18
+ * Auto-incrementing client-side id.
19
+ */
20
+ clientId;
21
+ /**
22
+ * ID of the changed row.
23
+ */
24
+ id;
25
+ /**
26
+ * Type of change.
27
+ */
28
+ op;
29
+ /**
30
+ * Data associated with the change.
31
+ */
32
+ opData;
33
+ /**
34
+ * Table that contained the change.
35
+ */
36
+ table;
37
+ /**
38
+ * Auto-incrementing transaction id. This is the same for all operations within the same transaction.
39
+ */
40
+ transactionId;
41
+ static fromRow(dbRow) {
42
+ const data = JSON.parse(dbRow.data);
43
+ return new CrudEntry(parseInt(dbRow.id), data.op, data.type, data.id, dbRow.tx_id, data.data);
44
+ }
45
+ constructor(clientId, op, table, id, transactionId, opData) {
46
+ this.clientId = clientId;
47
+ this.id = id;
48
+ this.op = op;
49
+ this.opData = opData;
50
+ this.table = table;
51
+ this.transactionId = transactionId;
52
+ }
53
+ /**
54
+ * Converts the change to JSON format.
55
+ */
56
+ toJSON() {
57
+ return {
58
+ op_id: this.clientId,
59
+ op: this.op,
60
+ type: this.table,
61
+ id: this.id,
62
+ tx_id: this.transactionId,
63
+ data: this.opData
64
+ };
65
+ }
66
+ equals(entry) {
67
+ return JSON.stringify(this.toComparisonArray()) == JSON.stringify(entry.toComparisonArray());
68
+ }
69
+ /**
70
+ * The hash code for this object.
71
+ * @deprecated This should not be necessary in the JS SDK.
72
+ * Use the @see CrudEntry#equals method instead.
73
+ * TODO remove in the next major release.
74
+ */
75
+ hashCode() {
76
+ return JSON.stringify(this.toComparisonArray());
77
+ }
78
+ /**
79
+ * Generates an array for use in deep comparison operations
80
+ */
81
+ toComparisonArray() {
82
+ return [this.transactionId, this.clientId, this.op, this.table, this.id, this.opData];
83
+ }
84
+ }
85
+ //# sourceMappingURL=CrudEntry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CrudEntry.js","sourceRoot":"","sources":["../../../../src/client/sync/bucket/CrudEntry.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,CAAN,IAAY,UAOX;AAPD,WAAY,UAAU;IACpB,qHAAqH;IACrH,yBAAW,CAAA;IACX,8GAA8G;IAC9G,6BAAe,CAAA;IACf,4EAA4E;IAC5E,+BAAiB,CAAA;AACnB,CAAC,EAPW,UAAU,KAAV,UAAU,QAOrB;AA2BD;;GAEG;AACH,MAAM,OAAO,SAAS;IACpB;;OAEG;IACH,QAAQ,CAAS;IACjB;;OAEG;IACH,EAAE,CAAS;IACX;;OAEG;IACH,EAAE,CAAa;IACf;;OAEG;IACH,MAAM,CAAuB;IAC7B;;OAEG;IACH,KAAK,CAAS;IACd;;OAEG;IACH,aAAa,CAAU;IAEvB,MAAM,CAAC,OAAO,CAAC,KAAoB;QACjC,MAAM,IAAI,GAAsB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvD,OAAO,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAChG,CAAC;IAED,YACE,QAAgB,EAChB,EAAc,EACd,KAAa,EACb,EAAU,EACV,aAAsB,EACtB,MAA4B;QAE5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,QAAQ;YACpB,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,IAAI,CAAC,KAAK;YAChB,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,KAAK,EAAE,IAAI,CAAC,aAAa;YACzB,IAAI,EAAE,IAAI,CAAC,MAAM;SAClB,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,KAAgB;QACrB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC/F,CAAC;IAED;;;;;OAKG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACxF,CAAC;CACF"}
@@ -0,0 +1,29 @@
1
+ import { CrudBatch } from './CrudBatch';
2
+ import { CrudEntry } from './CrudEntry';
3
+ export declare class CrudTransaction extends CrudBatch {
4
+ /**
5
+ * List of client-side changes.
6
+ */
7
+ crud: CrudEntry[];
8
+ /**
9
+ * Call to remove the changes from the local queue, once successfully uploaded.
10
+ */
11
+ complete: (checkpoint?: string) => Promise<void>;
12
+ /**
13
+ * If null, this contains a list of changes recorded without an explicit transaction associated.
14
+ */
15
+ transactionId?: number | undefined;
16
+ constructor(
17
+ /**
18
+ * List of client-side changes.
19
+ */
20
+ crud: CrudEntry[],
21
+ /**
22
+ * Call to remove the changes from the local queue, once successfully uploaded.
23
+ */
24
+ complete: (checkpoint?: string) => Promise<void>,
25
+ /**
26
+ * If null, this contains a list of changes recorded without an explicit transaction associated.
27
+ */
28
+ transactionId?: number | undefined);
29
+ }
@@ -0,0 +1,25 @@
1
+ import { CrudBatch } from './CrudBatch';
2
+ export class CrudTransaction extends CrudBatch {
3
+ crud;
4
+ complete;
5
+ transactionId;
6
+ constructor(
7
+ /**
8
+ * List of client-side changes.
9
+ */
10
+ crud,
11
+ /**
12
+ * Call to remove the changes from the local queue, once successfully uploaded.
13
+ */
14
+ complete,
15
+ /**
16
+ * If null, this contains a list of changes recorded without an explicit transaction associated.
17
+ */
18
+ transactionId) {
19
+ super(crud, false, complete);
20
+ this.crud = crud;
21
+ this.complete = complete;
22
+ this.transactionId = transactionId;
23
+ }
24
+ }
25
+ //# sourceMappingURL=CrudTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CrudTransaction.js","sourceRoot":"","sources":["../../../../src/client/sync/bucket/CrudTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAKnC;IAIA;IAIA;IAZT;IACE;;OAEG;IACI,IAAiB;IACxB;;OAEG;IACI,QAAgD;IACvD;;OAEG;IACI,aAAsB;QAE7B,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QAVtB,SAAI,GAAJ,IAAI,CAAa;QAIjB,aAAQ,GAAR,QAAQ,CAAwC;QAIhD,kBAAa,GAAb,aAAa,CAAS;IAG/B,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ export declare enum OpTypeEnum {
2
+ CLEAR = 1,
3
+ MOVE = 2,
4
+ PUT = 3,
5
+ REMOVE = 4
6
+ }
7
+ export type OpTypeJSON = string;
8
+ /**
9
+ * Used internally for sync buckets.
10
+ */
11
+ export declare class OpType {
12
+ value: OpTypeEnum;
13
+ static fromJSON(jsonValue: OpTypeJSON): OpType;
14
+ constructor(value: OpTypeEnum);
15
+ toJSON(): string;
16
+ }
@@ -0,0 +1,23 @@
1
+ export var OpTypeEnum;
2
+ (function (OpTypeEnum) {
3
+ OpTypeEnum[OpTypeEnum["CLEAR"] = 1] = "CLEAR";
4
+ OpTypeEnum[OpTypeEnum["MOVE"] = 2] = "MOVE";
5
+ OpTypeEnum[OpTypeEnum["PUT"] = 3] = "PUT";
6
+ OpTypeEnum[OpTypeEnum["REMOVE"] = 4] = "REMOVE";
7
+ })(OpTypeEnum || (OpTypeEnum = {}));
8
+ /**
9
+ * Used internally for sync buckets.
10
+ */
11
+ export class OpType {
12
+ value;
13
+ static fromJSON(jsonValue) {
14
+ return new OpType(OpTypeEnum[jsonValue]);
15
+ }
16
+ constructor(value) {
17
+ this.value = value;
18
+ }
19
+ toJSON() {
20
+ return Object.entries(OpTypeEnum).find(([, value]) => value === this.value)[0];
21
+ }
22
+ }
23
+ //# sourceMappingURL=OpType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpType.js","sourceRoot":"","sources":["../../../../src/client/sync/bucket/OpType.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,6CAAS,CAAA;IACT,2CAAQ,CAAA;IACR,yCAAO,CAAA;IACP,+CAAU,CAAA;AACZ,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAID;;GAEG;AACH,MAAM,OAAO,MAAM;IAKE;IAJnB,MAAM,CAAC,QAAQ,CAAC,SAAqB;QACnC,OAAO,IAAI,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,YAAmB,KAAiB;QAAjB,UAAK,GAAL,KAAK,CAAY;IAAG,CAAC;IAExC,MAAM;QACJ,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,CAAE,CAAC,CAAC,CAAC,CAAC;IAClF,CAAC;CACF"}
@@ -0,0 +1,23 @@
1
+ import { OpId } from './CrudEntry';
2
+ import { OpType, OpTypeJSON } from './OpType';
3
+ export interface OplogEntryJSON {
4
+ checksum: number;
5
+ data?: string;
6
+ object_id?: string;
7
+ object_type?: string;
8
+ op_id: string;
9
+ op: OpTypeJSON;
10
+ subkey?: string | object;
11
+ }
12
+ export declare class OplogEntry {
13
+ op_id: OpId;
14
+ op: OpType;
15
+ checksum: number;
16
+ subkey: string;
17
+ object_type?: string | undefined;
18
+ object_id?: string | undefined;
19
+ data?: string | undefined;
20
+ static fromRow(row: OplogEntryJSON): OplogEntry;
21
+ constructor(op_id: OpId, op: OpType, checksum: number, subkey: string, object_type?: string | undefined, object_id?: string | undefined, data?: string | undefined);
22
+ toJSON(): OplogEntryJSON;
23
+ }
@@ -0,0 +1,34 @@
1
+ import { OpType } from './OpType';
2
+ export class OplogEntry {
3
+ op_id;
4
+ op;
5
+ checksum;
6
+ subkey;
7
+ object_type;
8
+ object_id;
9
+ data;
10
+ static fromRow(row) {
11
+ return new OplogEntry(row.op_id, OpType.fromJSON(row.op), row.checksum, typeof row.subkey == 'string' ? row.subkey : JSON.stringify(row.subkey), row.object_type, row.object_id, row.data);
12
+ }
13
+ constructor(op_id, op, checksum, subkey, object_type, object_id, data) {
14
+ this.op_id = op_id;
15
+ this.op = op;
16
+ this.checksum = checksum;
17
+ this.subkey = subkey;
18
+ this.object_type = object_type;
19
+ this.object_id = object_id;
20
+ this.data = data;
21
+ }
22
+ toJSON() {
23
+ return {
24
+ op_id: this.op_id,
25
+ op: this.op.toJSON(),
26
+ object_type: this.object_type,
27
+ object_id: this.object_id,
28
+ checksum: this.checksum,
29
+ data: this.data,
30
+ subkey: JSON.stringify(this.subkey)
31
+ };
32
+ }
33
+ }
34
+ //# sourceMappingURL=OplogEntry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OplogEntry.js","sourceRoot":"","sources":["../../../../src/client/sync/bucket/OplogEntry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAc,MAAM,UAAU,CAAC;AAY9C,MAAM,OAAO,UAAU;IAcZ;IACA;IACA;IACA;IACA;IACA;IACA;IAnBT,MAAM,CAAC,OAAO,CAAC,GAAmB;QAChC,OAAO,IAAI,UAAU,CACnB,GAAG,CAAC,KAAK,EACT,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,EACvB,GAAG,CAAC,QAAQ,EACZ,OAAO,GAAG,CAAC,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,EACvE,GAAG,CAAC,WAAW,EACf,GAAG,CAAC,SAAS,EACb,GAAG,CAAC,IAAI,CACT,CAAC;IACJ,CAAC;IAED,YACS,KAAW,EACX,EAAU,EACV,QAAgB,EAChB,MAAc,EACd,WAAoB,EACpB,SAAkB,EAClB,IAAa;QANb,UAAK,GAAL,KAAK,CAAM;QACX,OAAE,GAAF,EAAE,CAAQ;QACV,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,gBAAW,GAAX,WAAW,CAAS;QACpB,cAAS,GAAT,SAAS,CAAS;QAClB,SAAI,GAAJ,IAAI,CAAS;IACnB,CAAC;IAEJ,MAAM;QACJ,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE;YACpB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;SACpC,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,66 @@
1
+ import { Mutex } from 'async-mutex';
2
+ import { DBAdapter, Transaction } from '../../../db/DBAdapter';
3
+ import { BucketState, BucketStorageAdapter, BucketStorageListener, Checkpoint, SyncLocalDatabaseResult } from './BucketStorageAdapter';
4
+ import { CrudBatch } from './CrudBatch';
5
+ import { SyncDataBatch } from './SyncDataBatch';
6
+ import { ILogger } from 'js-logger';
7
+ import { BaseObserver } from '../../../utils/BaseObserver';
8
+ export declare class SqliteBucketStorage extends BaseObserver<BucketStorageListener> implements BucketStorageAdapter {
9
+ private db;
10
+ private mutex;
11
+ private logger;
12
+ static MAX_OP_ID: string;
13
+ tableNames: Set<string>;
14
+ private pendingBucketDeletes;
15
+ private _hasCompletedSync;
16
+ private updateListener;
17
+ /**
18
+ * Count up, and do a compact on startup.
19
+ */
20
+ private compactCounter;
21
+ constructor(db: DBAdapter, mutex: Mutex, logger?: ILogger);
22
+ init(): Promise<void>;
23
+ dispose(): Promise<void>;
24
+ getMaxOpId(): string;
25
+ /**
26
+ * Reset any caches.
27
+ */
28
+ startSession(): void;
29
+ getBucketStates(): Promise<BucketState[]>;
30
+ saveSyncData(batch: SyncDataBatch): Promise<void>;
31
+ removeBuckets(buckets: string[]): Promise<void>;
32
+ /**
33
+ * Mark a bucket for deletion.
34
+ */
35
+ private deleteBucket;
36
+ hasCompletedSync(): Promise<boolean>;
37
+ syncLocalDatabase(checkpoint: Checkpoint): Promise<SyncLocalDatabaseResult>;
38
+ /**
39
+ * Atomically update the local state to the current checkpoint.
40
+ *
41
+ * This includes creating new tables, dropping old tables, and copying data over from the oplog.
42
+ */
43
+ private updateObjectsFromBuckets;
44
+ validateChecksums(checkpoint: Checkpoint): Promise<SyncLocalDatabaseResult>;
45
+ /**
46
+ * Force a compact, for tests.
47
+ */
48
+ forceCompact(): Promise<void>;
49
+ autoCompact(): Promise<void>;
50
+ private deletePendingBuckets;
51
+ private clearRemoveOps;
52
+ updateLocalTarget(cb: () => Promise<string>): Promise<boolean>;
53
+ hasCrud(): Promise<boolean>;
54
+ /**
55
+ * Get a batch of objects to send to the server.
56
+ * When the objects are successfully sent to the server, call .complete()
57
+ */
58
+ getCrudBatch(limit?: number): Promise<CrudBatch | null>;
59
+ writeTransaction<T>(callback: (tx: Transaction) => Promise<T>, options?: {
60
+ timeoutMs: number;
61
+ }): Promise<T>;
62
+ /**
63
+ * Set a target checkpoint.
64
+ */
65
+ setTargetCheckpoint(checkpoint: Checkpoint): Promise<void>;
66
+ }