@powersync/shared-internals 0.0.0-tmp.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 (153) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +5 -0
  3. package/dist/bundle.cjs +11787 -0
  4. package/dist/bundle.cjs.map +1 -0
  5. package/dist/bundle.mjs +11757 -0
  6. package/dist/bundle.mjs.map +1 -0
  7. package/dist/bundle.node.cjs +9418 -0
  8. package/dist/bundle.node.cjs.map +1 -0
  9. package/dist/bundle.node.mjs +9388 -0
  10. package/dist/bundle.node.mjs.map +1 -0
  11. package/dist/index.d.cts +1159 -0
  12. package/dist/websockets.mjs +7558 -0
  13. package/dist/websockets.mjs.map +1 -0
  14. package/dist/websockets.node.mjs +5189 -0
  15. package/dist/websockets.node.mjs.map +1 -0
  16. package/legacy/sync_protocol.d.ts +103 -0
  17. package/lib/client/BasePowerSyncDatabase.d.ts +147 -0
  18. package/lib/client/BasePowerSyncDatabase.js +622 -0
  19. package/lib/client/BasePowerSyncDatabase.js.map +1 -0
  20. package/lib/client/ConnectionManager.d.ts +116 -0
  21. package/lib/client/ConnectionManager.js +306 -0
  22. package/lib/client/ConnectionManager.js.map +1 -0
  23. package/lib/client/CustomQuery.d.ts +21 -0
  24. package/lib/client/CustomQuery.js +43 -0
  25. package/lib/client/CustomQuery.js.map +1 -0
  26. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +42 -0
  27. package/lib/client/sync/bucket/BucketStorageAdapter.js +23 -0
  28. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +1 -0
  29. package/lib/client/sync/bucket/CrudEntry.d.ts +46 -0
  30. package/lib/client/sync/bucket/CrudEntry.js +60 -0
  31. package/lib/client/sync/bucket/CrudEntry.js.map +1 -0
  32. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +33 -0
  33. package/lib/client/sync/bucket/SqliteBucketStorage.js +166 -0
  34. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -0
  35. package/lib/client/sync/options.d.ts +9 -0
  36. package/lib/client/sync/options.js +16 -0
  37. package/lib/client/sync/options.js.map +1 -0
  38. package/lib/client/sync/stream/AbstractRemote.d.ts +125 -0
  39. package/lib/client/sync/stream/AbstractRemote.js +265 -0
  40. package/lib/client/sync/stream/AbstractRemote.js.map +1 -0
  41. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +138 -0
  42. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +611 -0
  43. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -0
  44. package/lib/client/sync/stream/WebSocketSupport.d.ts +26 -0
  45. package/lib/client/sync/stream/WebSocketSupport.js +198 -0
  46. package/lib/client/sync/stream/WebSocketSupport.js.map +1 -0
  47. package/lib/client/sync/stream/WebsocketClientTransport.d.ts +15 -0
  48. package/lib/client/sync/stream/WebsocketClientTransport.js +62 -0
  49. package/lib/client/sync/stream/WebsocketClientTransport.js.map +1 -0
  50. package/lib/client/sync/stream/core-instruction.d.ts +75 -0
  51. package/lib/client/sync/stream/core-instruction.js +4 -0
  52. package/lib/client/sync/stream/core-instruction.js.map +1 -0
  53. package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +6 -0
  54. package/lib/client/triggers/MemoryTriggerClaimManager.js +21 -0
  55. package/lib/client/triggers/MemoryTriggerClaimManager.js.map +1 -0
  56. package/lib/client/triggers/TriggerManagerImpl.d.ts +68 -0
  57. package/lib/client/triggers/TriggerManagerImpl.js +415 -0
  58. package/lib/client/triggers/TriggerManagerImpl.js.map +1 -0
  59. package/lib/client/watched/AbstractQueryProcessor.d.ts +68 -0
  60. package/lib/client/watched/AbstractQueryProcessor.js +155 -0
  61. package/lib/client/watched/AbstractQueryProcessor.js.map +1 -0
  62. package/lib/client/watched/DifferentialQueryProcessor.d.ts +50 -0
  63. package/lib/client/watched/DifferentialQueryProcessor.js +174 -0
  64. package/lib/client/watched/DifferentialQueryProcessor.js.map +1 -0
  65. package/lib/client/watched/OnChangeQueryProcessor.d.ts +22 -0
  66. package/lib/client/watched/OnChangeQueryProcessor.js +80 -0
  67. package/lib/client/watched/OnChangeQueryProcessor.js.map +1 -0
  68. package/lib/client/watched/WatchedQuery.d.ts +9 -0
  69. package/lib/client/watched/WatchedQuery.js +12 -0
  70. package/lib/client/watched/WatchedQuery.js.map +1 -0
  71. package/lib/constants.d.ts +5 -0
  72. package/lib/constants.js +6 -0
  73. package/lib/constants.js.map +1 -0
  74. package/lib/db/ConnectionClosedError.d.ts +12 -0
  75. package/lib/db/ConnectionClosedError.js +23 -0
  76. package/lib/db/ConnectionClosedError.js.map +1 -0
  77. package/lib/db/crud/SyncProgress.d.ts +10 -0
  78. package/lib/db/crud/SyncProgress.js +33 -0
  79. package/lib/db/crud/SyncProgress.js.map +1 -0
  80. package/lib/db/crud/SyncStatus.d.ts +48 -0
  81. package/lib/db/crud/SyncStatus.js +178 -0
  82. package/lib/db/crud/SyncStatus.js.map +1 -0
  83. package/lib/db/openDatabase.d.ts +7 -0
  84. package/lib/db/openDatabase.js +22 -0
  85. package/lib/db/openDatabase.js.map +1 -0
  86. package/lib/index.d.ts +22 -0
  87. package/lib/index.js +22 -0
  88. package/lib/index.js.map +1 -0
  89. package/lib/utils/AbortOperation.d.ts +11 -0
  90. package/lib/utils/AbortOperation.js +21 -0
  91. package/lib/utils/AbortOperation.js.map +1 -0
  92. package/lib/utils/ControlledExecutor.d.ts +31 -0
  93. package/lib/utils/ControlledExecutor.js +54 -0
  94. package/lib/utils/ControlledExecutor.js.map +1 -0
  95. package/lib/utils/MetaBaseObserver.d.ts +11 -0
  96. package/lib/utils/MetaBaseObserver.js +51 -0
  97. package/lib/utils/MetaBaseObserver.js.map +1 -0
  98. package/lib/utils/async.d.ts +46 -0
  99. package/lib/utils/async.js +147 -0
  100. package/lib/utils/async.js.map +1 -0
  101. package/lib/utils/compatibility.d.ts +8 -0
  102. package/lib/utils/compatibility.js +9 -0
  103. package/lib/utils/compatibility.js.map +1 -0
  104. package/lib/utils/mutex.d.ts +42 -0
  105. package/lib/utils/mutex.js +150 -0
  106. package/lib/utils/mutex.js.map +1 -0
  107. package/lib/utils/parseQuery.d.ts +12 -0
  108. package/lib/utils/parseQuery.js +20 -0
  109. package/lib/utils/parseQuery.js.map +1 -0
  110. package/lib/utils/queue.d.ts +16 -0
  111. package/lib/utils/queue.js +42 -0
  112. package/lib/utils/queue.js.map +1 -0
  113. package/lib/utils/stream_transform.d.ts +41 -0
  114. package/lib/utils/stream_transform.js +211 -0
  115. package/lib/utils/stream_transform.js.map +1 -0
  116. package/lib/version.d.ts +1 -0
  117. package/lib/version.js +4 -0
  118. package/lib/version.js.map +1 -0
  119. package/package.json +65 -0
  120. package/src/client/BasePowerSyncDatabase.ts +853 -0
  121. package/src/client/ConnectionManager.ts +419 -0
  122. package/src/client/CustomQuery.ts +60 -0
  123. package/src/client/sync/bucket/BucketStorageAdapter.ts +51 -0
  124. package/src/client/sync/bucket/CrudEntry.ts +116 -0
  125. package/src/client/sync/bucket/SqliteBucketStorage.ts +213 -0
  126. package/src/client/sync/options.ts +24 -0
  127. package/src/client/sync/stream/AbstractRemote.ts +369 -0
  128. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +795 -0
  129. package/src/client/sync/stream/WebSocketSupport.ts +259 -0
  130. package/src/client/sync/stream/WebsocketClientTransport.ts +82 -0
  131. package/src/client/sync/stream/core-instruction.ts +78 -0
  132. package/src/client/triggers/MemoryTriggerClaimManager.ts +25 -0
  133. package/src/client/triggers/TriggerManagerImpl.ts +538 -0
  134. package/src/client/watched/AbstractQueryProcessor.ts +231 -0
  135. package/src/client/watched/DifferentialQueryProcessor.ts +226 -0
  136. package/src/client/watched/OnChangeQueryProcessor.ts +108 -0
  137. package/src/client/watched/WatchedQuery.ts +14 -0
  138. package/src/constants.ts +6 -0
  139. package/src/db/ConnectionClosedError.ts +25 -0
  140. package/src/db/crud/SyncProgress.ts +39 -0
  141. package/src/db/crud/SyncStatus.ts +234 -0
  142. package/src/db/openDatabase.ts +23 -0
  143. package/src/index.ts +24 -0
  144. package/src/utils/AbortOperation.ts +19 -0
  145. package/src/utils/ControlledExecutor.ts +78 -0
  146. package/src/utils/MetaBaseObserver.ts +65 -0
  147. package/src/utils/async.ts +185 -0
  148. package/src/utils/compatibility.ts +9 -0
  149. package/src/utils/mutex.ts +186 -0
  150. package/src/utils/parseQuery.ts +31 -0
  151. package/src/utils/queue.ts +48 -0
  152. package/src/utils/stream_transform.ts +260 -0
  153. package/src/version.ts +3 -0
@@ -0,0 +1,50 @@
1
+ import { DifferentialWatchedQuery, DifferentialWatchedQueryComparator, DifferentialWatchedQuerySettings, WatchedQueryDifferential } from '@powersync/common';
2
+ import { AbstractQueryProcessor, AbstractQueryProcessorOptions, LinkQueryOptions } from './AbstractQueryProcessor.js';
3
+ /**
4
+ * @internal
5
+ */
6
+ export interface DifferentialQueryProcessorOptions<RowType> extends AbstractQueryProcessorOptions<RowType[], DifferentialWatchedQuerySettings<RowType>> {
7
+ rowComparator?: DifferentialWatchedQueryComparator<RowType>;
8
+ }
9
+ type DataHashMap<RowType> = Map<string, {
10
+ hash: string;
11
+ item: RowType;
12
+ }>;
13
+ /**
14
+ * An empty differential result set.
15
+ * This is used as the initial state for differential incrementally watched queries.
16
+ *
17
+ * @internal
18
+ */
19
+ export declare const EMPTY_DIFFERENTIAL: {
20
+ added: never[];
21
+ all: never[];
22
+ removed: never[];
23
+ updated: never[];
24
+ unchanged: never[];
25
+ };
26
+ /**
27
+ * Default implementation of the {@link DifferentialWatchedQueryComparator} for watched queries.
28
+ * It keys items by their `id` property if available, alternatively it uses JSON stringification
29
+ * of the entire item for the key and comparison.
30
+ *
31
+ * @internal
32
+ */
33
+ export declare const DEFAULT_ROW_COMPARATOR: DifferentialWatchedQueryComparator<any>;
34
+ /**
35
+ * Uses the PowerSync onChange event to trigger watched queries.
36
+ * Results are emitted on every change of the relevant tables.
37
+ * @internal
38
+ */
39
+ export declare class DifferentialQueryProcessor<RowType> extends AbstractQueryProcessor<ReadonlyArray<Readonly<RowType>>, DifferentialWatchedQuerySettings<RowType>> implements DifferentialWatchedQuery<RowType> {
40
+ protected options: DifferentialQueryProcessorOptions<RowType>;
41
+ protected comparator: DifferentialWatchedQueryComparator<RowType>;
42
+ constructor(options: DifferentialQueryProcessorOptions<RowType>);
43
+ protected differentiate(current: RowType[], previousMap: DataHashMap<RowType>): {
44
+ diff: WatchedQueryDifferential<RowType>;
45
+ map: DataHashMap<RowType>;
46
+ hasChanged: boolean;
47
+ };
48
+ protected linkQuery(options: LinkQueryOptions<WatchedQueryDifferential<RowType>>): Promise<void>;
49
+ }
50
+ export {};
@@ -0,0 +1,174 @@
1
+ import { AbstractQueryProcessor } from './AbstractQueryProcessor.js';
2
+ /**
3
+ * An empty differential result set.
4
+ * This is used as the initial state for differential incrementally watched queries.
5
+ *
6
+ * @internal
7
+ */
8
+ export const EMPTY_DIFFERENTIAL = {
9
+ added: [],
10
+ all: [],
11
+ removed: [],
12
+ updated: [],
13
+ unchanged: []
14
+ };
15
+ /**
16
+ * Default implementation of the {@link DifferentialWatchedQueryComparator} for watched queries.
17
+ * It keys items by their `id` property if available, alternatively it uses JSON stringification
18
+ * of the entire item for the key and comparison.
19
+ *
20
+ * @internal
21
+ */
22
+ export const DEFAULT_ROW_COMPARATOR = {
23
+ keyBy: (item) => {
24
+ if (item && typeof item == 'object' && typeof item['id'] == 'string') {
25
+ return item['id'];
26
+ }
27
+ return JSON.stringify(item);
28
+ },
29
+ compareBy: (item) => JSON.stringify(item)
30
+ };
31
+ /**
32
+ * Uses the PowerSync onChange event to trigger watched queries.
33
+ * Results are emitted on every change of the relevant tables.
34
+ * @internal
35
+ */
36
+ export class DifferentialQueryProcessor extends AbstractQueryProcessor {
37
+ options;
38
+ comparator;
39
+ constructor(options) {
40
+ super(options);
41
+ this.options = options;
42
+ this.comparator = options.rowComparator ?? DEFAULT_ROW_COMPARATOR;
43
+ }
44
+ /*
45
+ * @returns If the sets are equal
46
+ */
47
+ differentiate(current, previousMap) {
48
+ const { keyBy, compareBy } = this.comparator;
49
+ let hasChanged = false;
50
+ const currentMap = new Map();
51
+ const removedTracker = new Set(previousMap.keys());
52
+ // Allow mutating to populate the data temporarily.
53
+ const diff = {
54
+ all: [],
55
+ added: [],
56
+ removed: [],
57
+ updated: [],
58
+ unchanged: []
59
+ };
60
+ /**
61
+ * Looping over the current result set array is important to preserve
62
+ * the ordering of the result set.
63
+ * We can replace items in the current array with previous object references if they are equal.
64
+ */
65
+ for (const item of current) {
66
+ const key = keyBy(item);
67
+ const hash = compareBy(item);
68
+ currentMap.set(key, { hash, item });
69
+ const previousItem = previousMap.get(key);
70
+ if (!previousItem) {
71
+ // New item
72
+ hasChanged = true;
73
+ diff.added.push(item);
74
+ diff.all.push(item);
75
+ }
76
+ else {
77
+ // Existing item
78
+ if (hash == previousItem.hash) {
79
+ diff.unchanged.push(previousItem.item);
80
+ // Use the previous object reference
81
+ diff.all.push(previousItem.item);
82
+ // update the map to preserve the reference
83
+ currentMap.set(key, previousItem);
84
+ }
85
+ else {
86
+ hasChanged = true;
87
+ diff.updated.push({ current: item, previous: previousItem.item });
88
+ // Use the new reference
89
+ diff.all.push(item);
90
+ }
91
+ }
92
+ // The item is present, we don't consider it removed
93
+ removedTracker.delete(key);
94
+ }
95
+ diff.removed = Array.from(removedTracker).map((key) => previousMap.get(key).item);
96
+ hasChanged = hasChanged || diff.removed.length > 0;
97
+ return {
98
+ diff,
99
+ hasChanged,
100
+ map: currentMap
101
+ };
102
+ }
103
+ async linkQuery(options) {
104
+ const { db, watchOptions } = this.options;
105
+ const { abortSignal } = options;
106
+ const compiledQuery = watchOptions.query.compile();
107
+ const tables = await db.resolveTables(compiledQuery.sql, compiledQuery.parameters, {
108
+ tables: options.settings.triggerOnTables
109
+ });
110
+ let currentMap = new Map();
111
+ // populate the currentMap from the placeholder data
112
+ this.state.data.forEach((item) => {
113
+ currentMap.set(this.comparator.keyBy(item), {
114
+ hash: this.comparator.compareBy(item),
115
+ item
116
+ });
117
+ });
118
+ db.onChangeWithCallback({
119
+ onChange: async () => {
120
+ if (this.closed || abortSignal.aborted) {
121
+ return;
122
+ }
123
+ // This fires for each change of the relevant tables
124
+ try {
125
+ if (this.reportFetching && !this.state.isFetching) {
126
+ await this.updateState({ isFetching: true });
127
+ }
128
+ const partialStateUpdate = {};
129
+ // Always run the query if an underlying table has changed
130
+ const result = await watchOptions.query.execute({
131
+ sql: compiledQuery.sql,
132
+ // Allows casting from ReadOnlyArray[unknown] to Array<unknown>
133
+ // This allows simpler compatibility with PowerSync queries
134
+ parameters: [...compiledQuery.parameters],
135
+ db: this.options.db
136
+ });
137
+ if (abortSignal.aborted) {
138
+ return;
139
+ }
140
+ if (this.reportFetching) {
141
+ partialStateUpdate.isFetching = false;
142
+ }
143
+ if (this.state.isLoading) {
144
+ partialStateUpdate.isLoading = false;
145
+ }
146
+ const { diff, hasChanged, map } = this.differentiate(result, currentMap);
147
+ // Update for future comparisons
148
+ currentMap = map;
149
+ if (hasChanged) {
150
+ await this.iterateAsyncListenersWithError((l) => l.onDiff?.(diff));
151
+ Object.assign(partialStateUpdate, {
152
+ data: diff.all
153
+ });
154
+ }
155
+ if (this.state.error) {
156
+ partialStateUpdate.error = null;
157
+ }
158
+ if (Object.keys(partialStateUpdate).length > 0) {
159
+ await this.updateState(partialStateUpdate);
160
+ }
161
+ }
162
+ catch (error) {
163
+ await this.updateState({ error });
164
+ }
165
+ }
166
+ }, {
167
+ signal: abortSignal,
168
+ tables,
169
+ throttleMs: watchOptions.throttleMs,
170
+ triggerImmediate: true // used to emit the initial state
171
+ });
172
+ }
173
+ }
174
+ //# sourceMappingURL=DifferentialQueryProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DifferentialQueryProcessor.js","sourceRoot":"","sources":["../../../src/client/watched/DifferentialQueryProcessor.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,sBAAsB,EAIvB,MAAM,6BAA6B,CAAC;AAcrC;;;;;GAKG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kBAAkB,EAAE;4BAChC,IAAI,EAAE,IAAI,CAAC,GAAG;yBACf,CAAC,CAAC;oBACL,CAAC;oBAED,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;wBACrB,kBAAkB,CAAC,KAAK,GAAG,IAAI,CAAC;oBAClC,CAAC;oBAED,IAAI,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBAC/C,MAAM,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;oBAC7C,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAU,EAAE,CAAC;oBACpB,MAAM,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC;SACF,EACD;YACE,MAAM,EAAE,WAAW;YACnB,MAAM;YACN,UAAU,EAAE,YAAY,CAAC,UAAU;YACnC,gBAAgB,EAAE,IAAI,CAAC,iCAAiC;SACzD,CACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ import { WatchedQueryComparator, WatchedQuerySettings } from '@powersync/common';
2
+ import { AbstractQueryProcessor, AbstractQueryProcessorOptions, LinkQueryOptions } from './AbstractQueryProcessor.js';
3
+ /**
4
+ * @internal
5
+ */
6
+ export interface OnChangeQueryProcessorOptions<Data> extends AbstractQueryProcessorOptions<Data, WatchedQuerySettings<Data>> {
7
+ comparator?: WatchedQueryComparator<Data>;
8
+ }
9
+ /**
10
+ * Uses the PowerSync onChange event to trigger watched queries.
11
+ * Results are emitted on every change of the relevant tables.
12
+ * @internal
13
+ */
14
+ export declare class OnChangeQueryProcessor<Data> extends AbstractQueryProcessor<Data, WatchedQuerySettings<Data>> {
15
+ protected options: OnChangeQueryProcessorOptions<Data>;
16
+ constructor(options: OnChangeQueryProcessorOptions<Data>);
17
+ /**
18
+ * @returns If the sets are equal
19
+ */
20
+ protected checkEquality(current: Data, previous: Data): boolean;
21
+ protected linkQuery(options: LinkQueryOptions<Data>): Promise<void>;
22
+ }
@@ -0,0 +1,80 @@
1
+ import { AbstractQueryProcessor } from './AbstractQueryProcessor.js';
2
+ /**
3
+ * Uses the PowerSync onChange event to trigger watched queries.
4
+ * Results are emitted on every change of the relevant tables.
5
+ * @internal
6
+ */
7
+ export class OnChangeQueryProcessor extends AbstractQueryProcessor {
8
+ options;
9
+ constructor(options) {
10
+ super(options);
11
+ this.options = options;
12
+ }
13
+ /**
14
+ * @returns If the sets are equal
15
+ */
16
+ checkEquality(current, previous) {
17
+ // Use the provided comparator if available. Assume values are unique if not available.
18
+ return this.options.comparator?.checkEquality?.(current, previous) ?? false;
19
+ }
20
+ async linkQuery(options) {
21
+ const { db, watchOptions } = this.options;
22
+ const { abortSignal } = options;
23
+ const compiledQuery = watchOptions.query.compile();
24
+ const tables = await db.resolveTables(compiledQuery.sql, compiledQuery.parameters, {
25
+ tables: options.settings.triggerOnTables
26
+ });
27
+ db.onChangeWithCallback({
28
+ onChange: async () => {
29
+ if (this.closed || abortSignal.aborted) {
30
+ return;
31
+ }
32
+ // This fires for each change of the relevant tables
33
+ try {
34
+ if (this.reportFetching && !this.state.isFetching) {
35
+ await this.updateState({ isFetching: true });
36
+ }
37
+ const partialStateUpdate = {};
38
+ // Always run the query if an underlying table has changed
39
+ const result = await watchOptions.query.execute({
40
+ sql: compiledQuery.sql,
41
+ // Allows casting from ReadOnlyArray[unknown] to Array<unknown>
42
+ // This allows simpler compatibility with PowerSync queries
43
+ parameters: [...compiledQuery.parameters],
44
+ db: this.options.db
45
+ });
46
+ if (abortSignal.aborted) {
47
+ return;
48
+ }
49
+ if (this.reportFetching) {
50
+ partialStateUpdate.isFetching = false;
51
+ }
52
+ if (this.state.isLoading) {
53
+ partialStateUpdate.isLoading = false;
54
+ }
55
+ // Check if the result has changed
56
+ if (!this.checkEquality(result, this.state.data)) {
57
+ Object.assign(partialStateUpdate, {
58
+ data: result
59
+ });
60
+ }
61
+ if (this.state.error) {
62
+ partialStateUpdate.error = null;
63
+ }
64
+ if (Object.keys(partialStateUpdate).length > 0) {
65
+ await this.updateState(partialStateUpdate);
66
+ }
67
+ }
68
+ catch (error) {
69
+ await this.updateState({ error });
70
+ }
71
+ }
72
+ }, {
73
+ signal: abortSignal,
74
+ tables,
75
+ throttleMs: watchOptions.throttleMs,
76
+ triggerImmediate: true // used to emit the initial state
77
+ });
78
+ }
79
+ }
80
+ //# sourceMappingURL=OnChangeQueryProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OnChangeQueryProcessor.js","sourceRoot":"","sources":["../../../src/client/watched/OnChangeQueryProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,EAIvB,MAAM,6BAA6B,CAAC;AAYrC;;;;GAIG;AACH,MAAM,OAAO,sBAA6B,SAAQ,sBAAwD;IAClF;IAAtB,YAAsB,OAA4C;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QADK,YAAO,GAAP,OAAO,CAAqC;IAElE,CAAC;IAED;;OAEG;IACO,aAAa,CAAC,OAAa,EAAE,QAAc;QACnD,uFAAuF;QACvF,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,aAAa,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,KAAK,CAAC;IAC9E,CAAC;IAES,KAAK,CAAC,SAAS,CAAC,OAA+B;QACvD,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAC1C,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;QAEhC,MAAM,aAAa,GAAG,YAAY,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACnD,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,aAAa,CAAC,GAAG,EAAE,aAAa,CAAC,UAAmB,EAAE;YAC1F,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,eAAe;SACzC,CAAC,CAAC;QAEH,EAAE,CAAC,oBAAoB,CAC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AkB,CAAC,KAAK,GAAG,IAAI,CAAC;oBAClC,CAAC;oBAED,IAAI,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBAC/C,MAAM,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;oBAC7C,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAU,EAAE,CAAC;oBACpB,MAAM,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC;SACF,EACD;YACE,MAAM,EAAE,WAAW;YACnB,MAAM;YACN,UAAU,EAAE,YAAY,CAAC,UAAU;YACnC,gBAAgB,EAAE,IAAI,CAAC,iCAAiC;SACzD,CACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import { WatchedQueryOptions } from '@powersync/common';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const DEFAULT_WATCH_THROTTLE_MS = 30;
6
+ /**
7
+ * @internal
8
+ */
9
+ export declare const DEFAULT_WATCH_QUERY_OPTIONS: WatchedQueryOptions;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @internal
3
+ */
4
+ export const DEFAULT_WATCH_THROTTLE_MS = 30;
5
+ /**
6
+ * @internal
7
+ */
8
+ export const DEFAULT_WATCH_QUERY_OPTIONS = {
9
+ throttleMs: DEFAULT_WATCH_THROTTLE_MS,
10
+ reportFetching: true
11
+ };
12
+ //# sourceMappingURL=WatchedQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WatchedQuery.js","sourceRoot":"","sources":["../../../src/client/watched/WatchedQuery.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE5C;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAwB;IAC9D,UAAU,EAAE,yBAAyB;IACrC,cAAc,EAAE,IAAI;CACrB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @internal The priority used by the core extension to indicate that a full sync was completed.
3
+ */
4
+ export declare const FULL_SYNC_PRIORITY = 2147483647;
5
+ export declare const MAX_OP_ID = "9223372036854775807";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @internal The priority used by the core extension to indicate that a full sync was completed.
3
+ */
4
+ export const FULL_SYNC_PRIORITY = 2147483647;
5
+ export const MAX_OP_ID = '9223372036854775807';
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;AAE7C,MAAM,CAAC,MAAM,SAAS,GAAG,qBAAqB,CAAC"}
@@ -0,0 +1,12 @@
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
+ * @internal
7
+ */
8
+ export declare class ConnectionClosedError extends Error {
9
+ static NAME: string;
10
+ static MATCHES(input: any): boolean;
11
+ constructor(message: string);
12
+ }
@@ -0,0 +1,23 @@
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
+ * @internal
7
+ */
8
+ export class ConnectionClosedError extends Error {
9
+ static NAME = 'ConnectionClosedError';
10
+ static MATCHES(input) {
11
+ /**
12
+ * If there are weird package issues which cause multiple versions of classes to be present, the instanceof
13
+ * check might fail. This also performs a failsafe check.
14
+ * This might also happen if the Error is serialized and parsed over a bridging channel like a MessagePort.
15
+ */
16
+ return (input instanceof ConnectionClosedError || (input instanceof Error && input.name == ConnectionClosedError.NAME));
17
+ }
18
+ constructor(message) {
19
+ super(message);
20
+ this.name = ConnectionClosedError.NAME;
21
+ }
22
+ }
23
+ //# sourceMappingURL=ConnectionClosedError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConnectionClosedError.js","sourceRoot":"","sources":["../../src/db/ConnectionClosedError.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;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"}
@@ -0,0 +1,10 @@
1
+ import { ProgressWithOperations, SyncProgress } from '@powersync/common';
2
+ import { DownloadProgress } from '../../client/sync/stream/core-instruction.js';
3
+ export declare class SyncProgressImpl implements SyncProgress {
4
+ protected internal: DownloadProgress;
5
+ totalOperations: number;
6
+ downloadedOperations: number;
7
+ downloadedFraction: number;
8
+ constructor(internal: DownloadProgress);
9
+ untilPriority(priority: number): ProgressWithOperations;
10
+ }
@@ -0,0 +1,33 @@
1
+ // (bucket, progress) pairs
2
+ import { FULL_SYNC_PRIORITY } from '../../constants.js';
3
+ export class SyncProgressImpl {
4
+ internal;
5
+ totalOperations;
6
+ downloadedOperations;
7
+ downloadedFraction;
8
+ constructor(internal) {
9
+ this.internal = internal;
10
+ const untilCompletion = this.untilPriority(FULL_SYNC_PRIORITY);
11
+ this.totalOperations = untilCompletion.totalOperations;
12
+ this.downloadedOperations = untilCompletion.downloadedOperations;
13
+ this.downloadedFraction = untilCompletion.downloadedFraction;
14
+ }
15
+ untilPriority(priority) {
16
+ let total = 0;
17
+ let downloaded = 0;
18
+ for (const progress of Object.values(this.internal.buckets)) {
19
+ // Include higher-priority buckets, which are represented by lower numbers.
20
+ if (progress.priority <= priority) {
21
+ downloaded += progress.since_last;
22
+ total += progress.target_count - progress.at_last;
23
+ }
24
+ }
25
+ let progress = total == 0 ? 0.0 : downloaded / total;
26
+ return {
27
+ totalOperations: total,
28
+ downloadedOperations: downloaded,
29
+ downloadedFraction: progress
30
+ };
31
+ }
32
+ }
33
+ //# sourceMappingURL=SyncProgress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SyncProgress.js","sourceRoot":"","sources":["../../../src/db/crud/SyncProgress.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAG3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,MAAM,OAAO,gBAAgB;IAKL;IAJtB,eAAe,CAAS;IACxB,oBAAoB,CAAS;IAC7B,kBAAkB,CAAS;IAE3B,YAAsB,QAA0B;QAA1B,aAAQ,GAAR,QAAQ,CAAkB;QAC9C,MAAM,eAAe,GAAG,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;QAE/D,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC,eAAe,CAAC;QACvD,IAAI,CAAC,oBAAoB,GAAG,eAAe,CAAC,oBAAoB,CAAC;QACjE,IAAI,CAAC,kBAAkB,GAAG,eAAe,CAAC,kBAAkB,CAAC;IAC/D,CAAC;IAED,aAAa,CAAC,QAAgB;QAC5B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,UAAU,GAAG,CAAC,CAAC;QAEnB,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC5D,2EAA2E;YAC3E,IAAI,QAAQ,CAAC,QAAQ,IAAI,QAAQ,EAAE,CAAC;gBAClC,UAAU,IAAI,QAAQ,CAAC,UAAU,CAAC;gBAClC,KAAK,IAAI,QAAQ,CAAC,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC;YACpD,CAAC;QACH,CAAC;QAED,IAAI,QAAQ,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,CAAC;QACrD,OAAO;YACL,eAAe,EAAE,KAAK;YACtB,oBAAoB,EAAE,UAAU;YAChC,kBAAkB,EAAE,QAAQ;SAC7B,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,48 @@
1
+ import { SyncDataFlowStatus, SyncPriorityStatus, SyncProgress, SyncStatus, SyncStreamDescription, SyncStreamStatus } from '@powersync/common';
2
+ import { CoreSyncStatus } from '../../client/sync/stream/core-instruction.js';
3
+ /**
4
+ * The {@link SyncStatus} subset not managed by the Rust client in {@link CoreSyncStatus}.
5
+ *
6
+ * This includes the upload state and JS errors.
7
+ */
8
+ export interface JavaScriptSyncState {
9
+ uploading?: boolean;
10
+ downloadError?: Error;
11
+ uploadError?: Error;
12
+ }
13
+ export declare class SyncStatusSnapshot implements SyncStatus {
14
+ readonly core: CoreSyncStatus | null;
15
+ readonly jsState: JavaScriptSyncState;
16
+ constructor(core: CoreSyncStatus | null, jsState: JavaScriptSyncState);
17
+ get connected(): boolean;
18
+ get connecting(): boolean;
19
+ get downloading(): boolean;
20
+ get uploading(): boolean;
21
+ get downloadError(): Error | undefined;
22
+ get uploadError(): Error | undefined;
23
+ get dataFlowStatus(): SyncDataFlowStatus;
24
+ get lastSyncedAt(): Date | undefined;
25
+ get hasSynced(): boolean | undefined;
26
+ get syncStreams(): SyncStreamStatus[] | undefined;
27
+ forStream(stream: SyncStreamDescription): SyncStreamStatus | undefined;
28
+ get priorityStatusEntries(): SyncPriorityStatus[] | undefined;
29
+ get downloadProgress(): SyncProgress | null;
30
+ statusForPriority(priority: number): SyncPriorityStatus | undefined;
31
+ isEqual(status: SyncStatus): boolean;
32
+ getMessage(): string;
33
+ /**
34
+ * Serializes the SyncStatus instance to a plain object.
35
+ *
36
+ * @returns A plain object representation of the sync status
37
+ */
38
+ toJSON(): SyncStatusJson;
39
+ /**
40
+ * Not all errors are serializable over a MessagePort. E.g. some `DomExceptions` fail to be passed across workers.
41
+ * This explicitly serializes errors in the SyncStatus.
42
+ */
43
+ serializeError(error?: Error): Error | undefined;
44
+ }
45
+ export interface SyncStatusJson {
46
+ core: CoreSyncStatus | null;
47
+ dataFlow: JavaScriptSyncState;
48
+ }