@powersync/common 0.0.0-dev-20260202162549 → 0.0.0-dev-20260202163643
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/dist/bundle.cjs +14470 -0
- package/dist/bundle.cjs.map +1 -0
- package/dist/bundle.mjs +14379 -0
- package/dist/bundle.mjs.map +1 -0
- package/dist/bundle.node.cjs +11948 -0
- package/dist/bundle.node.cjs.map +1 -0
- package/dist/bundle.node.mjs +11857 -0
- package/dist/bundle.node.mjs.map +1 -0
- package/dist/index.d.cts +4272 -0
- package/lib/attachments/AttachmentContext.d.ts +86 -0
- package/lib/attachments/AttachmentContext.js +229 -0
- package/lib/attachments/AttachmentContext.js.map +1 -0
- package/lib/attachments/AttachmentErrorHandler.d.ts +31 -0
- package/lib/attachments/AttachmentErrorHandler.js +2 -0
- package/lib/attachments/AttachmentErrorHandler.js.map +1 -0
- package/lib/attachments/AttachmentQueue.d.ts +149 -0
- package/lib/attachments/AttachmentQueue.js +362 -0
- package/lib/attachments/AttachmentQueue.js.map +1 -0
- package/lib/attachments/AttachmentService.d.ts +29 -0
- package/lib/attachments/AttachmentService.js +56 -0
- package/lib/attachments/AttachmentService.js.map +1 -0
- package/lib/attachments/LocalStorageAdapter.d.ts +62 -0
- package/lib/attachments/LocalStorageAdapter.js +6 -0
- package/lib/attachments/LocalStorageAdapter.js.map +1 -0
- package/lib/attachments/RemoteStorageAdapter.d.ts +27 -0
- package/lib/attachments/RemoteStorageAdapter.js +2 -0
- package/lib/attachments/RemoteStorageAdapter.js.map +1 -0
- package/lib/attachments/Schema.d.ts +50 -0
- package/lib/attachments/Schema.js +62 -0
- package/lib/attachments/Schema.js.map +1 -0
- package/lib/attachments/SyncingService.d.ts +62 -0
- package/lib/attachments/SyncingService.js +168 -0
- package/lib/attachments/SyncingService.js.map +1 -0
- package/lib/attachments/WatchedAttachmentItem.d.ts +17 -0
- package/lib/attachments/WatchedAttachmentItem.js +2 -0
- package/lib/attachments/WatchedAttachmentItem.js.map +1 -0
- package/lib/client/AbstractPowerSyncDatabase.d.ts +615 -0
- package/lib/client/AbstractPowerSyncDatabase.js +983 -0
- package/lib/client/AbstractPowerSyncDatabase.js.map +1 -0
- package/lib/client/AbstractPowerSyncOpenFactory.d.ts +22 -0
- package/lib/client/AbstractPowerSyncOpenFactory.js +25 -0
- package/lib/client/AbstractPowerSyncOpenFactory.js.map +1 -0
- package/lib/client/ConnectionManager.d.ts +112 -0
- package/lib/client/ConnectionManager.js +294 -0
- package/lib/client/ConnectionManager.js.map +1 -0
- package/lib/client/CustomQuery.d.ts +22 -0
- package/lib/client/CustomQuery.js +43 -0
- package/lib/client/CustomQuery.js.map +1 -0
- package/lib/client/Query.d.ts +97 -0
- package/lib/client/Query.js +2 -0
- package/lib/client/Query.js.map +1 -0
- package/lib/client/SQLOpenFactory.d.ts +42 -0
- package/lib/client/SQLOpenFactory.js +20 -0
- package/lib/client/SQLOpenFactory.js.map +1 -0
- package/lib/client/compilableQueryWatch.d.ts +7 -0
- package/lib/client/compilableQueryWatch.js +38 -0
- package/lib/client/compilableQueryWatch.js.map +1 -0
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +23 -0
- package/lib/client/connection/PowerSyncBackendConnector.js +2 -0
- package/lib/client/connection/PowerSyncBackendConnector.js.map +1 -0
- package/lib/client/connection/PowerSyncCredentials.d.ts +5 -0
- package/lib/client/connection/PowerSyncCredentials.js +2 -0
- package/lib/client/connection/PowerSyncCredentials.js.map +1 -0
- package/lib/client/constants.d.ts +1 -0
- package/lib/client/constants.js +2 -0
- package/lib/client/constants.js.map +1 -0
- package/lib/client/runOnSchemaChange.d.ts +2 -0
- package/lib/client/runOnSchemaChange.js +24 -0
- package/lib/client/runOnSchemaChange.js.map +1 -0
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +102 -0
- package/lib/client/sync/bucket/BucketStorageAdapter.js +19 -0
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +1 -0
- package/lib/client/sync/bucket/CrudBatch.d.ts +31 -0
- package/lib/client/sync/bucket/CrudBatch.js +26 -0
- package/lib/client/sync/bucket/CrudBatch.js.map +1 -0
- package/lib/client/sync/bucket/CrudEntry.d.ts +95 -0
- package/lib/client/sync/bucket/CrudEntry.js +110 -0
- package/lib/client/sync/bucket/CrudEntry.js.map +1 -0
- package/lib/client/sync/bucket/CrudTransaction.d.ts +29 -0
- package/lib/client/sync/bucket/CrudTransaction.js +25 -0
- package/lib/client/sync/bucket/CrudTransaction.js.map +1 -0
- package/lib/client/sync/bucket/OpType.d.ts +16 -0
- package/lib/client/sync/bucket/OpType.js +23 -0
- package/lib/client/sync/bucket/OpType.js.map +1 -0
- package/lib/client/sync/bucket/OplogEntry.d.ts +23 -0
- package/lib/client/sync/bucket/OplogEntry.js +36 -0
- package/lib/client/sync/bucket/OplogEntry.js.map +1 -0
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +61 -0
- package/lib/client/sync/bucket/SqliteBucketStorage.js +324 -0
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -0
- package/lib/client/sync/bucket/SyncDataBatch.d.ts +6 -0
- package/lib/client/sync/bucket/SyncDataBatch.js +12 -0
- package/lib/client/sync/bucket/SyncDataBatch.js.map +1 -0
- package/lib/client/sync/bucket/SyncDataBucket.d.ts +40 -0
- package/lib/client/sync/bucket/SyncDataBucket.js +40 -0
- package/lib/client/sync/bucket/SyncDataBucket.js.map +1 -0
- package/lib/client/sync/stream/AbstractRemote.d.ts +140 -0
- package/lib/client/sync/stream/AbstractRemote.js +506 -0
- package/lib/client/sync/stream/AbstractRemote.js.map +1 -0
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +240 -0
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +990 -0
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -0
- package/lib/client/sync/stream/WebsocketClientTransport.d.ts +15 -0
- package/lib/client/sync/stream/WebsocketClientTransport.js +61 -0
- package/lib/client/sync/stream/WebsocketClientTransport.js.map +1 -0
- package/lib/client/sync/stream/core-instruction.d.ts +72 -0
- package/lib/client/sync/stream/core-instruction.js +27 -0
- package/lib/client/sync/stream/core-instruction.js.map +1 -0
- package/lib/client/sync/stream/streaming-sync-types.d.ts +143 -0
- package/lib/client/sync/stream/streaming-sync-types.js +26 -0
- package/lib/client/sync/stream/streaming-sync-types.js.map +1 -0
- package/lib/client/sync/sync-streams.d.ts +98 -0
- package/lib/client/sync/sync-streams.js +2 -0
- package/lib/client/sync/sync-streams.js.map +1 -0
- package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +6 -0
- package/lib/client/triggers/MemoryTriggerClaimManager.js +21 -0
- package/lib/client/triggers/MemoryTriggerClaimManager.js.map +1 -0
- package/lib/client/triggers/TriggerManager.d.ts +459 -0
- package/lib/client/triggers/TriggerManager.js +11 -0
- package/lib/client/triggers/TriggerManager.js.map +1 -0
- package/lib/client/triggers/TriggerManagerImpl.d.ts +39 -0
- package/lib/client/triggers/TriggerManagerImpl.js +393 -0
- package/lib/client/triggers/TriggerManagerImpl.js.map +1 -0
- package/lib/client/triggers/sanitizeSQL.d.ts +34 -0
- package/lib/client/triggers/sanitizeSQL.js +69 -0
- package/lib/client/triggers/sanitizeSQL.js.map +1 -0
- package/lib/client/watched/GetAllQuery.d.ts +32 -0
- package/lib/client/watched/GetAllQuery.js +25 -0
- package/lib/client/watched/GetAllQuery.js.map +1 -0
- package/lib/client/watched/WatchedQuery.d.ts +100 -0
- package/lib/client/watched/WatchedQuery.js +14 -0
- package/lib/client/watched/WatchedQuery.js.map +1 -0
- package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +68 -0
- package/lib/client/watched/processors/AbstractQueryProcessor.js +151 -0
- package/lib/client/watched/processors/AbstractQueryProcessor.js.map +1 -0
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +121 -0
- package/lib/client/watched/processors/DifferentialQueryProcessor.js +173 -0
- package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -0
- package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +33 -0
- package/lib/client/watched/processors/OnChangeQueryProcessor.js +83 -0
- package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -0
- package/lib/client/watched/processors/comparators.d.ts +30 -0
- package/lib/client/watched/processors/comparators.js +35 -0
- package/lib/client/watched/processors/comparators.js.map +1 -0
- package/lib/db/ConnectionClosedError.d.ts +10 -0
- package/lib/db/ConnectionClosedError.js +21 -0
- package/lib/db/ConnectionClosedError.js.map +1 -0
- package/lib/db/DBAdapter.d.ts +115 -0
- package/lib/db/DBAdapter.js +20 -0
- package/lib/db/DBAdapter.js.map +1 -0
- package/lib/db/crud/SyncProgress.d.ts +68 -0
- package/lib/db/crud/SyncProgress.js +61 -0
- package/lib/db/crud/SyncProgress.js.map +1 -0
- package/lib/db/crud/SyncStatus.d.ts +195 -0
- package/lib/db/crud/SyncStatus.js +250 -0
- package/lib/db/crud/SyncStatus.js.map +1 -0
- package/lib/db/crud/UploadQueueStatus.d.ts +20 -0
- package/lib/db/crud/UploadQueueStatus.js +25 -0
- package/lib/db/crud/UploadQueueStatus.js.map +1 -0
- package/lib/db/schema/Column.d.ts +30 -0
- package/lib/db/schema/Column.js +43 -0
- package/lib/db/schema/Column.js.map +1 -0
- package/lib/db/schema/Index.d.ts +22 -0
- package/lib/db/schema/Index.js +30 -0
- package/lib/db/schema/Index.js.map +1 -0
- package/lib/db/schema/IndexedColumn.d.ts +19 -0
- package/lib/db/schema/IndexedColumn.js +30 -0
- package/lib/db/schema/IndexedColumn.js.map +1 -0
- package/lib/db/schema/RawTable.d.ts +61 -0
- package/lib/db/schema/RawTable.js +33 -0
- package/lib/db/schema/RawTable.js.map +1 -0
- package/lib/db/schema/Schema.d.ts +54 -0
- package/lib/db/schema/Schema.js +61 -0
- package/lib/db/schema/Schema.js.map +1 -0
- package/lib/db/schema/Table.d.ts +157 -0
- package/lib/db/schema/Table.js +208 -0
- package/lib/db/schema/Table.js.map +1 -0
- package/lib/db/schema/TableV2.d.ts +9 -0
- package/lib/db/schema/TableV2.js +9 -0
- package/lib/db/schema/TableV2.js.map +1 -0
- package/lib/index.d.ts +62 -0
- package/lib/index.js +63 -0
- package/lib/index.js.map +1 -0
- package/lib/types/types.d.ts +8 -0
- package/lib/types/types.js +2 -0
- package/lib/types/types.js.map +1 -0
- package/lib/utils/AbortOperation.d.ts +9 -0
- package/lib/utils/AbortOperation.js +19 -0
- package/lib/utils/AbortOperation.js.map +1 -0
- package/lib/utils/BaseObserver.d.ts +18 -0
- package/lib/utils/BaseObserver.js +27 -0
- package/lib/utils/BaseObserver.js.map +1 -0
- package/lib/utils/ControlledExecutor.d.ts +25 -0
- package/lib/utils/ControlledExecutor.js +51 -0
- package/lib/utils/ControlledExecutor.js.map +1 -0
- package/lib/utils/DataStream.d.ts +62 -0
- package/lib/utils/DataStream.js +169 -0
- package/lib/utils/DataStream.js.map +1 -0
- package/lib/utils/Logger.d.ts +31 -0
- package/lib/utils/Logger.js +37 -0
- package/lib/utils/Logger.js.map +1 -0
- package/lib/utils/MetaBaseObserver.d.ts +29 -0
- package/lib/utils/MetaBaseObserver.js +51 -0
- package/lib/utils/MetaBaseObserver.js.map +1 -0
- package/lib/utils/async.d.ts +23 -0
- package/lib/utils/async.js +55 -0
- package/lib/utils/async.js.map +1 -0
- package/lib/utils/mutex.d.ts +7 -0
- package/lib/utils/mutex.js +29 -0
- package/lib/utils/mutex.js.map +1 -0
- package/lib/utils/parseQuery.d.ts +6 -0
- package/lib/utils/parseQuery.js +17 -0
- package/lib/utils/parseQuery.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { WatchCompatibleQuery, WatchedQuery, WatchedQueryOptions } from '../WatchedQuery.js';
|
|
2
|
+
import { AbstractQueryProcessor, AbstractQueryProcessorOptions, LinkQueryOptions } from './AbstractQueryProcessor.js';
|
|
3
|
+
import { WatchedQueryComparator } from './comparators.js';
|
|
4
|
+
/**
|
|
5
|
+
* Settings for {@link WatchedQuery} instances created via {@link Query#watch}.
|
|
6
|
+
*/
|
|
7
|
+
export interface WatchedQuerySettings<DataType> extends WatchedQueryOptions {
|
|
8
|
+
query: WatchCompatibleQuery<DataType>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* {@link WatchedQuery} returned from {@link Query#watch}.
|
|
12
|
+
*/
|
|
13
|
+
export type StandardWatchedQuery<DataType> = WatchedQuery<DataType, WatchedQuerySettings<DataType>>;
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export interface OnChangeQueryProcessorOptions<Data> extends AbstractQueryProcessorOptions<Data, WatchedQuerySettings<Data>> {
|
|
18
|
+
comparator?: WatchedQueryComparator<Data>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Uses the PowerSync onChange event to trigger watched queries.
|
|
22
|
+
* Results are emitted on every change of the relevant tables.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare class OnChangeQueryProcessor<Data> extends AbstractQueryProcessor<Data, WatchedQuerySettings<Data>> {
|
|
26
|
+
protected options: OnChangeQueryProcessorOptions<Data>;
|
|
27
|
+
constructor(options: OnChangeQueryProcessorOptions<Data>);
|
|
28
|
+
/**
|
|
29
|
+
* @returns If the sets are equal
|
|
30
|
+
*/
|
|
31
|
+
protected checkEquality(current: Data, previous: Data): boolean;
|
|
32
|
+
protected linkQuery(options: LinkQueryOptions<Data>): Promise<void>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
onError: async (error) => {
|
|
73
|
+
await this.updateState({ error });
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
76
|
+
signal: abortSignal,
|
|
77
|
+
tables,
|
|
78
|
+
throttleMs: watchOptions.throttleMs,
|
|
79
|
+
triggerImmediate: true // used to emit the initial state
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=OnChangeQueryProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OnChangeQueryProcessor.js","sourceRoot":"","sources":["../../../../src/client/watched/processors/OnChangeQueryProcessor.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A basic comparator for incrementally watched queries. This performs a single comparison which
|
|
3
|
+
* determines if the result set has changed. The {@link WatchedQuery} will only emit the new result
|
|
4
|
+
* if a change has been detected.
|
|
5
|
+
*/
|
|
6
|
+
export interface WatchedQueryComparator<Data> {
|
|
7
|
+
checkEquality: (current: Data, previous: Data) => boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Options for {@link ArrayComparator}
|
|
11
|
+
*/
|
|
12
|
+
export type ArrayComparatorOptions<ItemType> = {
|
|
13
|
+
/**
|
|
14
|
+
* Returns a string to uniquely identify an item in the array.
|
|
15
|
+
*/
|
|
16
|
+
compareBy: (item: ItemType) => string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* An efficient comparator for {@link WatchedQuery} created with {@link Query#watch}. This has the ability to determine if a query
|
|
20
|
+
* result has changes without necessarily processing all items in the result.
|
|
21
|
+
*/
|
|
22
|
+
export declare class ArrayComparator<ItemType> implements WatchedQueryComparator<ItemType[]> {
|
|
23
|
+
protected options: ArrayComparatorOptions<ItemType>;
|
|
24
|
+
constructor(options: ArrayComparatorOptions<ItemType>);
|
|
25
|
+
checkEquality(current: ItemType[], previous: ItemType[]): boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Watched query comparator that always reports changed result sets.
|
|
29
|
+
*/
|
|
30
|
+
export declare const FalsyComparator: WatchedQueryComparator<unknown>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An efficient comparator for {@link WatchedQuery} created with {@link Query#watch}. This has the ability to determine if a query
|
|
3
|
+
* result has changes without necessarily processing all items in the result.
|
|
4
|
+
*/
|
|
5
|
+
export class ArrayComparator {
|
|
6
|
+
options;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
10
|
+
checkEquality(current, previous) {
|
|
11
|
+
if (current.length === 0 && previous.length === 0) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
if (current.length !== previous.length) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const { compareBy } = this.options;
|
|
18
|
+
// At this point the lengths are equal
|
|
19
|
+
for (let i = 0; i < current.length; i++) {
|
|
20
|
+
const currentItem = compareBy(current[i]);
|
|
21
|
+
const previousItem = compareBy(previous[i]);
|
|
22
|
+
if (currentItem !== previousItem) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Watched query comparator that always reports changed result sets.
|
|
31
|
+
*/
|
|
32
|
+
export const FalsyComparator = {
|
|
33
|
+
checkEquality: () => false // Default comparator that always returns false
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=comparators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparators.js","sourceRoot":"","sources":["../../../../src/client/watched/processors/comparators.ts"],"names":[],"mappings":"AAmBA;;;GAGG;AACH,MAAM,OAAO,eAAe;IACJ;IAAtB,YAAsB,OAAyC;QAAzC,YAAO,GAAP,OAAO,CAAkC;IAAG,CAAC;IAEnE,aAAa,CAAC,OAAmB,EAAE,QAAoB;QACrD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;YACvC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAEnC,sCAAsC;QACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1C,MAAM,YAAY,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YAE5C,IAAI,WAAW,KAAK,YAAY,EAAE,CAAC;gBACjC,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAoC;IAC9D,aAAa,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,+CAA+C;CAC3E,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 declare class ConnectionClosedError extends Error {
|
|
7
|
+
static NAME: string;
|
|
8
|
+
static MATCHES(input: any): boolean;
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set of generic interfaces to allow PowerSync compatibility with
|
|
3
|
+
* different SQLite DB implementations.
|
|
4
|
+
*/
|
|
5
|
+
import { BaseListener, BaseObserverInterface } from '../utils/BaseObserver.js';
|
|
6
|
+
/**
|
|
7
|
+
* TODO most of these types could be exported to a common `types` package
|
|
8
|
+
* which is used by the DB adapter libraries as well.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Object returned by SQL Query executions.
|
|
12
|
+
*/
|
|
13
|
+
export type QueryResult = {
|
|
14
|
+
/** Represents the auto-generated row id if applicable. */
|
|
15
|
+
insertId?: number;
|
|
16
|
+
/** Number of affected rows if result of a update query. */
|
|
17
|
+
rowsAffected: number;
|
|
18
|
+
/** if status is undefined or 0 this object will contain the query results */
|
|
19
|
+
rows?: {
|
|
20
|
+
/** Raw array with all dataset */
|
|
21
|
+
_array: any[];
|
|
22
|
+
/** The length of the dataset */
|
|
23
|
+
length: number;
|
|
24
|
+
/** A convenience function to acess the index based the row object
|
|
25
|
+
* @param idx the row index
|
|
26
|
+
* @returns the row structure identified by column names
|
|
27
|
+
*/
|
|
28
|
+
item: (idx: number) => any;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export interface DBGetUtils {
|
|
32
|
+
/** Execute a read-only query and return results. */
|
|
33
|
+
getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
|
|
34
|
+
/** Execute a read-only query and return the first result, or null if the ResultSet is empty. */
|
|
35
|
+
getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
|
|
36
|
+
/** Execute a read-only query and return the first result, error if the ResultSet is empty. */
|
|
37
|
+
get<T>(sql: string, parameters?: any[]): Promise<T>;
|
|
38
|
+
}
|
|
39
|
+
export interface LockContext extends DBGetUtils {
|
|
40
|
+
/** Execute a single write statement. */
|
|
41
|
+
execute: (query: string, params?: any[] | undefined) => Promise<QueryResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Execute a single write statement and return raw results.
|
|
44
|
+
* Unlike `execute`, which returns an object with structured key-value pairs,
|
|
45
|
+
* `executeRaw` returns a nested array of raw values, where each row is
|
|
46
|
+
* represented as an array of column values without field names.
|
|
47
|
+
*
|
|
48
|
+
* Example result:
|
|
49
|
+
*
|
|
50
|
+
* ```[ [ '1', 'list 1', '33', 'Post content', '1' ] ]```
|
|
51
|
+
*
|
|
52
|
+
* Where as `execute`'s `rows._array` would have been:
|
|
53
|
+
*
|
|
54
|
+
* ```[ { id: '33', name: 'list 1', content: 'Post content', list_id: '1' } ]```
|
|
55
|
+
*/
|
|
56
|
+
executeRaw: (query: string, params?: any[] | undefined) => Promise<any[][]>;
|
|
57
|
+
}
|
|
58
|
+
export interface Transaction extends LockContext {
|
|
59
|
+
/** Commit multiple changes to the local DB using the Transaction context. */
|
|
60
|
+
commit: () => Promise<QueryResult>;
|
|
61
|
+
/** Roll back multiple attempted changes using the Transaction context. */
|
|
62
|
+
rollback: () => Promise<QueryResult>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Update table operation numbers from SQLite
|
|
66
|
+
*/
|
|
67
|
+
export declare enum RowUpdateType {
|
|
68
|
+
SQLITE_INSERT = 18,
|
|
69
|
+
SQLITE_DELETE = 9,
|
|
70
|
+
SQLITE_UPDATE = 23
|
|
71
|
+
}
|
|
72
|
+
export interface TableUpdateOperation {
|
|
73
|
+
opType: RowUpdateType;
|
|
74
|
+
rowId: number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Notification of an update to one or more tables, for the purpose of realtime change notifications.
|
|
78
|
+
*/
|
|
79
|
+
export interface UpdateNotification extends TableUpdateOperation {
|
|
80
|
+
table: string;
|
|
81
|
+
}
|
|
82
|
+
export interface BatchedUpdateNotification {
|
|
83
|
+
rawUpdates: UpdateNotification[];
|
|
84
|
+
tables: string[];
|
|
85
|
+
groupedUpdates: Record<string, TableUpdateOperation[]>;
|
|
86
|
+
}
|
|
87
|
+
export interface DBAdapterListener extends BaseListener {
|
|
88
|
+
/**
|
|
89
|
+
* Listener for table updates.
|
|
90
|
+
* Allows for single table updates in order to maintain API compatibility
|
|
91
|
+
* without the need for a major version bump
|
|
92
|
+
* The DB adapter can also batch update notifications if supported.
|
|
93
|
+
*/
|
|
94
|
+
tablesUpdated: (updateNotification: BatchedUpdateNotification | UpdateNotification) => void;
|
|
95
|
+
}
|
|
96
|
+
export interface DBLockOptions {
|
|
97
|
+
timeoutMs?: number;
|
|
98
|
+
}
|
|
99
|
+
export interface DBAdapter extends BaseObserverInterface<DBAdapterListener>, DBGetUtils {
|
|
100
|
+
close: () => void | Promise<void>;
|
|
101
|
+
execute: (query: string, params?: any[]) => Promise<QueryResult>;
|
|
102
|
+
executeRaw: (query: string, params?: any[]) => Promise<any[][]>;
|
|
103
|
+
executeBatch: (query: string, params?: any[][]) => Promise<QueryResult>;
|
|
104
|
+
name: string;
|
|
105
|
+
readLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
|
|
106
|
+
readTransaction: <T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) => Promise<T>;
|
|
107
|
+
writeLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
|
|
108
|
+
writeTransaction: <T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) => Promise<T>;
|
|
109
|
+
/**
|
|
110
|
+
* This method refreshes the schema information across all connections. This is for advanced use cases, and should generally not be needed.
|
|
111
|
+
*/
|
|
112
|
+
refreshSchema: () => Promise<void>;
|
|
113
|
+
}
|
|
114
|
+
export declare function isBatchedUpdateNotification(update: BatchedUpdateNotification | UpdateNotification): update is BatchedUpdateNotification;
|
|
115
|
+
export declare function extractTableUpdates(update: BatchedUpdateNotification | UpdateNotification): string[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set of generic interfaces to allow PowerSync compatibility with
|
|
3
|
+
* different SQLite DB implementations.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Update table operation numbers from SQLite
|
|
7
|
+
*/
|
|
8
|
+
export var RowUpdateType;
|
|
9
|
+
(function (RowUpdateType) {
|
|
10
|
+
RowUpdateType[RowUpdateType["SQLITE_INSERT"] = 18] = "SQLITE_INSERT";
|
|
11
|
+
RowUpdateType[RowUpdateType["SQLITE_DELETE"] = 9] = "SQLITE_DELETE";
|
|
12
|
+
RowUpdateType[RowUpdateType["SQLITE_UPDATE"] = 23] = "SQLITE_UPDATE";
|
|
13
|
+
})(RowUpdateType || (RowUpdateType = {}));
|
|
14
|
+
export function isBatchedUpdateNotification(update) {
|
|
15
|
+
return 'tables' in update;
|
|
16
|
+
}
|
|
17
|
+
export function extractTableUpdates(update) {
|
|
18
|
+
return isBatchedUpdateNotification(update) ? update.tables : [update.table];
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=DBAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DBAdapter.js","sourceRoot":"","sources":["../../src/db/DBAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmEH;;GAEG;AACH,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,oEAAkB,CAAA;IAClB,mEAAiB,CAAA;IACjB,oEAAkB,CAAA;AACpB,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAgDD,MAAM,UAAU,2BAA2B,CACzC,MAAsD;IAEtD,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAsD;IACxF,OAAO,2BAA2B,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { BucketProgress } from '../../client/sync/stream/core-instruction.js';
|
|
2
|
+
/** @internal */
|
|
3
|
+
export type InternalProgressInformation = Record<string, BucketProgress>;
|
|
4
|
+
/**
|
|
5
|
+
* @internal The priority used by the core extension to indicate that a full sync was completed.
|
|
6
|
+
*/
|
|
7
|
+
export declare const FULL_SYNC_PRIORITY = 2147483647;
|
|
8
|
+
/**
|
|
9
|
+
* Information about a progressing download made by the PowerSync SDK.
|
|
10
|
+
*
|
|
11
|
+
* To obtain these values, use {@link SyncProgress}, available through
|
|
12
|
+
* {@link SyncStatus#downloadProgress}.
|
|
13
|
+
*/
|
|
14
|
+
export interface ProgressWithOperations {
|
|
15
|
+
/**
|
|
16
|
+
* The total amount of operations to download for the current sync iteration
|
|
17
|
+
* to complete.
|
|
18
|
+
*/
|
|
19
|
+
totalOperations: number;
|
|
20
|
+
/**
|
|
21
|
+
* The amount of operations that have already been downloaded.
|
|
22
|
+
*/
|
|
23
|
+
downloadedOperations: number;
|
|
24
|
+
/**
|
|
25
|
+
* Relative progress, as {@link downloadedOperations} of {@link totalOperations}.
|
|
26
|
+
*
|
|
27
|
+
* This will be a number between `0.0` and `1.0` (inclusive).
|
|
28
|
+
*
|
|
29
|
+
* When this number reaches `1.0`, all changes have been received from the sync service.
|
|
30
|
+
* Actually applying these changes happens before the `downloadProgress` field is cleared from
|
|
31
|
+
* {@link SyncStatus}, so progress can stay at `1.0` for a short while before completing.
|
|
32
|
+
*/
|
|
33
|
+
downloadedFraction: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Provides realtime progress on how PowerSync is downloading rows.
|
|
37
|
+
*
|
|
38
|
+
* The progress until the next complete sync is available through the fields on {@link ProgressWithOperations},
|
|
39
|
+
* which this class implements.
|
|
40
|
+
* Additionally, the {@link SyncProgress.untilPriority} method can be used to otbain progress towards
|
|
41
|
+
* a specific priority (instead of the progress for the entire download).
|
|
42
|
+
*
|
|
43
|
+
* The reported progress always reflects the status towards the end of a sync iteration (after
|
|
44
|
+
* which a consistent snapshot of all buckets is available locally).
|
|
45
|
+
*
|
|
46
|
+
* In rare cases (in particular, when a [compacting](https://docs.powersync.com/usage/lifecycle-maintenance/compacting-buckets)
|
|
47
|
+
* operation takes place between syncs), it's possible for the returned numbers to be slightly
|
|
48
|
+
* inaccurate. For this reason, {@link SyncProgress} should be seen as an approximation of progress.
|
|
49
|
+
* The information returned is good enough to build progress bars, but not exact enough to track
|
|
50
|
+
* individual download counts.
|
|
51
|
+
*
|
|
52
|
+
* Also note that data is downloaded in bulk, which means that individual counters are unlikely
|
|
53
|
+
* to be updated one-by-one.
|
|
54
|
+
*/
|
|
55
|
+
export declare class SyncProgress implements ProgressWithOperations {
|
|
56
|
+
protected internal: InternalProgressInformation;
|
|
57
|
+
totalOperations: number;
|
|
58
|
+
downloadedOperations: number;
|
|
59
|
+
downloadedFraction: number;
|
|
60
|
+
constructor(internal: InternalProgressInformation);
|
|
61
|
+
/**
|
|
62
|
+
* Returns download progress towards all data up until the specified priority being received.
|
|
63
|
+
*
|
|
64
|
+
* The returned {@link ProgressWithOperations} tracks the target amount of operations that need
|
|
65
|
+
* to be downloaded in total and how many of them have already been received.
|
|
66
|
+
*/
|
|
67
|
+
untilPriority(priority: number): ProgressWithOperations;
|
|
68
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Provides realtime progress on how PowerSync is downloading rows.
|
|
7
|
+
*
|
|
8
|
+
* The progress until the next complete sync is available through the fields on {@link ProgressWithOperations},
|
|
9
|
+
* which this class implements.
|
|
10
|
+
* Additionally, the {@link SyncProgress.untilPriority} method can be used to otbain progress towards
|
|
11
|
+
* a specific priority (instead of the progress for the entire download).
|
|
12
|
+
*
|
|
13
|
+
* The reported progress always reflects the status towards the end of a sync iteration (after
|
|
14
|
+
* which a consistent snapshot of all buckets is available locally).
|
|
15
|
+
*
|
|
16
|
+
* In rare cases (in particular, when a [compacting](https://docs.powersync.com/usage/lifecycle-maintenance/compacting-buckets)
|
|
17
|
+
* operation takes place between syncs), it's possible for the returned numbers to be slightly
|
|
18
|
+
* inaccurate. For this reason, {@link SyncProgress} should be seen as an approximation of progress.
|
|
19
|
+
* The information returned is good enough to build progress bars, but not exact enough to track
|
|
20
|
+
* individual download counts.
|
|
21
|
+
*
|
|
22
|
+
* Also note that data is downloaded in bulk, which means that individual counters are unlikely
|
|
23
|
+
* to be updated one-by-one.
|
|
24
|
+
*/
|
|
25
|
+
export class SyncProgress {
|
|
26
|
+
internal;
|
|
27
|
+
totalOperations;
|
|
28
|
+
downloadedOperations;
|
|
29
|
+
downloadedFraction;
|
|
30
|
+
constructor(internal) {
|
|
31
|
+
this.internal = internal;
|
|
32
|
+
const untilCompletion = this.untilPriority(FULL_SYNC_PRIORITY);
|
|
33
|
+
this.totalOperations = untilCompletion.totalOperations;
|
|
34
|
+
this.downloadedOperations = untilCompletion.downloadedOperations;
|
|
35
|
+
this.downloadedFraction = untilCompletion.downloadedFraction;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns download progress towards all data up until the specified priority being received.
|
|
39
|
+
*
|
|
40
|
+
* The returned {@link ProgressWithOperations} tracks the target amount of operations that need
|
|
41
|
+
* to be downloaded in total and how many of them have already been received.
|
|
42
|
+
*/
|
|
43
|
+
untilPriority(priority) {
|
|
44
|
+
let total = 0;
|
|
45
|
+
let downloaded = 0;
|
|
46
|
+
for (const progress of Object.values(this.internal)) {
|
|
47
|
+
// Include higher-priority buckets, which are represented by lower numbers.
|
|
48
|
+
if (progress.priority <= priority) {
|
|
49
|
+
downloaded += progress.since_last;
|
|
50
|
+
total += progress.target_count - progress.at_last;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
let progress = total == 0 ? 0.0 : downloaded / total;
|
|
54
|
+
return {
|
|
55
|
+
totalOperations: total,
|
|
56
|
+
downloadedOperations: downloaded,
|
|
57
|
+
downloadedFraction: progress
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=SyncProgress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncProgress.js","sourceRoot":"","sources":["../../../src/db/crud/SyncProgress.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;AA+B7C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,YAAY;IAKD;IAJtB,eAAe,CAAS;IACxB,oBAAoB,CAAS;IAC7B,kBAAkB,CAAS;IAE3B,YAAsB,QAAqC;QAArC,aAAQ,GAAR,QAAQ,CAA6B;QACzD,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;;;;;OAKG;IACH,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,EAAE,CAAC;YACpD,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"}
|