velocious 1.0.721 → 1.0.722
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/build/background-jobs/main.js +10 -2
- package/build/configuration-types.js +1 -1
- package/build/database/advisory-lock-reentrancy-node.js +9 -0
- package/build/database/advisory-lock-reentrancy.js +66 -0
- package/build/database/advisory-lock-runner.js +9 -12
- package/build/environment-handlers/node.js +1 -0
- package/build/src/background-jobs/main.d.ts.map +1 -1
- package/build/src/background-jobs/main.js +11 -4
- package/build/src/configuration-types.d.ts +2 -2
- package/build/src/configuration-types.js +2 -2
- package/build/src/database/advisory-lock-reentrancy-node.d.ts +2 -0
- package/build/src/database/advisory-lock-reentrancy-node.d.ts.map +1 -0
- package/build/src/database/advisory-lock-reentrancy-node.js +7 -0
- package/build/src/database/advisory-lock-reentrancy.d.ts +67 -0
- package/build/src/database/advisory-lock-reentrancy.d.ts.map +1 -0
- package/build/src/database/advisory-lock-reentrancy.js +60 -0
- package/build/src/database/advisory-lock-runner.d.ts +25 -33
- package/build/src/database/advisory-lock-runner.d.ts.map +1 -1
- package/build/src/database/advisory-lock-runner.js +10 -13
- package/build/src/environment-handlers/node.d.ts +1 -0
- package/build/src/environment-handlers/node.d.ts.map +1 -1
- package/build/src/environment-handlers/node.js +2 -1
- package/build/src/sync/sync-cursor.d.ts +30 -0
- package/build/src/sync/sync-cursor.d.ts.map +1 -0
- package/build/src/sync/sync-cursor.js +54 -0
- package/build/src/sync/sync-realtime-bridge.d.ts +127 -24
- package/build/src/sync/sync-realtime-bridge.d.ts.map +1 -1
- package/build/src/sync/sync-realtime-bridge.js +92 -56
- package/build/src/sync/sync-websocket-channel.d.ts +49 -0
- package/build/src/sync/sync-websocket-channel.d.ts.map +1 -1
- package/build/src/sync/sync-websocket-channel.js +138 -2
- package/build/sync/sync-cursor.js +56 -0
- package/build/sync/sync-realtime-bridge.js +97 -51
- package/build/sync/sync-websocket-channel.js +153 -1
- package/package.json +1 -1
- package/src/background-jobs/main.js +10 -2
- package/src/configuration-types.js +1 -1
- package/src/database/advisory-lock-reentrancy-node.js +9 -0
- package/src/database/advisory-lock-reentrancy.js +66 -0
- package/src/database/advisory-lock-runner.js +9 -12
- package/src/environment-handlers/node.js +1 -0
- package/src/sync/sync-cursor.js +56 -0
- package/src/sync/sync-realtime-bridge.js +97 -51
- package/src/sync/sync-websocket-channel.js +153 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type SyncCursor = import("./sync-api-client-types.js").SyncCursor;
|
|
2
|
+
/**
|
|
3
|
+
* @module sync-cursor
|
|
4
|
+
*
|
|
5
|
+
* Shared cursor helpers for the sync change feed: building a cursor from a
|
|
6
|
+
* serialized sync entry and ordering two cursors under the feed's stable order
|
|
7
|
+
* (server sequence when present, else updated-at then id). The server channel
|
|
8
|
+
* advances its per-subscription replay watermark with these across out-of-order
|
|
9
|
+
* live broadcasts, and the realtime bridge advances the persisted scope cursor
|
|
10
|
+
* monotonically on pushed changes.
|
|
11
|
+
*/
|
|
12
|
+
/** @typedef {import("./sync-api-client-types.js").SyncCursor} SyncCursor */
|
|
13
|
+
/**
|
|
14
|
+
* Builds a cursor from a serialized sync entry, or null when the entry carries
|
|
15
|
+
* no cursor identity (no updated-at).
|
|
16
|
+
* @param {Record<string, ReturnType<typeof JSON.parse>>} entry - Serialized sync entry.
|
|
17
|
+
* @returns {SyncCursor} Cursor for the entry, or null.
|
|
18
|
+
*/
|
|
19
|
+
export declare function cursorFromSyncEntry(entry: Record<string, ReturnType<typeof JSON.parse>>): SyncCursor;
|
|
20
|
+
/**
|
|
21
|
+
* Whether one cursor is strictly later than another under the change-feed order.
|
|
22
|
+
* A sequenced cursor is always later than an unsequenced one; both sequenced
|
|
23
|
+
* cursors order by server sequence; both unsequenced cursors order by updated-at
|
|
24
|
+
* then id.
|
|
25
|
+
* @param {SyncCursor} candidate - Candidate cursor.
|
|
26
|
+
* @param {SyncCursor} current - Current cursor.
|
|
27
|
+
* @returns {boolean} Whether the candidate is later.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isCursorAfter(candidate: SyncCursor, current: SyncCursor): boolean;
|
|
30
|
+
//# sourceMappingURL=sync-cursor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-cursor.d.ts","sourceRoot":"","sources":["../../../src/sync/sync-cursor.js"],"names":[],"mappings":"AAaI,YAA2D,UAAU,GAA3D,OAAO,4BAA4B,EAAE,UAAU,CAAY;AAXzE;;;;;;;;;GASG;AAEH,4EAA4E;AAE5E;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAH9B,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,CAGd,GAF5B,UAAU,CAYtB;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAJ5B,UAI4B,EAAE,OAAO,EAHrC,UAGqC,GAFnC,OAAO,CAenB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* @module sync-cursor
|
|
4
|
+
*
|
|
5
|
+
* Shared cursor helpers for the sync change feed: building a cursor from a
|
|
6
|
+
* serialized sync entry and ordering two cursors under the feed's stable order
|
|
7
|
+
* (server sequence when present, else updated-at then id). The server channel
|
|
8
|
+
* advances its per-subscription replay watermark with these across out-of-order
|
|
9
|
+
* live broadcasts, and the realtime bridge advances the persisted scope cursor
|
|
10
|
+
* monotonically on pushed changes.
|
|
11
|
+
*/
|
|
12
|
+
/** @typedef {import("./sync-api-client-types.js").SyncCursor} SyncCursor */
|
|
13
|
+
/**
|
|
14
|
+
* Builds a cursor from a serialized sync entry, or null when the entry carries
|
|
15
|
+
* no cursor identity (no updated-at).
|
|
16
|
+
* @param {Record<string, ReturnType<typeof JSON.parse>>} entry - Serialized sync entry.
|
|
17
|
+
* @returns {SyncCursor} Cursor for the entry, or null.
|
|
18
|
+
*/
|
|
19
|
+
export function cursorFromSyncEntry(entry) {
|
|
20
|
+
const updatedAt = entry.updatedAt;
|
|
21
|
+
if (typeof updatedAt !== "string" || updatedAt === "")
|
|
22
|
+
return null;
|
|
23
|
+
return {
|
|
24
|
+
id: entry.id === null || entry.id === undefined ? null : String(entry.id),
|
|
25
|
+
serverSequence: typeof entry.serverSequence === "number" ? entry.serverSequence : null,
|
|
26
|
+
updatedAt
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether one cursor is strictly later than another under the change-feed order.
|
|
31
|
+
* A sequenced cursor is always later than an unsequenced one; both sequenced
|
|
32
|
+
* cursors order by server sequence; both unsequenced cursors order by updated-at
|
|
33
|
+
* then id.
|
|
34
|
+
* @param {SyncCursor} candidate - Candidate cursor.
|
|
35
|
+
* @param {SyncCursor} current - Current cursor.
|
|
36
|
+
* @returns {boolean} Whether the candidate is later.
|
|
37
|
+
*/
|
|
38
|
+
export function isCursorAfter(candidate, current) {
|
|
39
|
+
if (!candidate)
|
|
40
|
+
return false;
|
|
41
|
+
if (!current)
|
|
42
|
+
return true;
|
|
43
|
+
if (candidate.serverSequence !== null && current.serverSequence !== null) {
|
|
44
|
+
return candidate.serverSequence > current.serverSequence;
|
|
45
|
+
}
|
|
46
|
+
if (candidate.serverSequence !== null)
|
|
47
|
+
return true;
|
|
48
|
+
if (current.serverSequence !== null)
|
|
49
|
+
return false;
|
|
50
|
+
if (candidate.updatedAt !== current.updatedAt)
|
|
51
|
+
return candidate.updatedAt > current.updatedAt;
|
|
52
|
+
return (candidate.id ?? "") > (current.id ?? "");
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3luYy1jdXJzb3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc3luYy9zeW5jLWN1cnNvci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxZQU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ZGF0ZWRBdCA+IGN1cnJlbnQudXBkYXRlZEF0XG5cbiAgcmV0dXJuIChjYW5kaWRhdGUuaWQgPz8gXCJcIikgPiAoY3VycmVudC5pZCA/PyBcIlwiKVxufVxuIl19
|
|
@@ -1,7 +1,113 @@
|
|
|
1
1
|
export type VelociousSyncRealtimeChannelDescriptor = import("../configuration-types.js").VelociousSyncRealtimeChannelDescriptor;
|
|
2
2
|
export type VelociousSyncRealtimeWebsocketClient = import("../configuration-types.js").VelociousSyncRealtimeWebsocketClient;
|
|
3
|
+
export type SyncRealtimeScopeRow = {
|
|
4
|
+
/**
|
|
5
|
+
* - Scope attribute conditions.
|
|
6
|
+
*/
|
|
7
|
+
conditions: Record<string, ReturnType<typeof JSON.parse>>;
|
|
8
|
+
/**
|
|
9
|
+
* - Persisted cursor JSON payload.
|
|
10
|
+
*/
|
|
11
|
+
cursorPayload: string | null;
|
|
12
|
+
/**
|
|
13
|
+
* - Scope row id.
|
|
14
|
+
*/
|
|
15
|
+
id: string;
|
|
16
|
+
/**
|
|
17
|
+
* - Scope resource type.
|
|
18
|
+
*/
|
|
19
|
+
resourceType: string | null;
|
|
20
|
+
/**
|
|
21
|
+
* - Fixed-size scope digest.
|
|
22
|
+
*/
|
|
23
|
+
scopeDigest: string;
|
|
24
|
+
/**
|
|
25
|
+
* - Scope state.
|
|
26
|
+
*/
|
|
27
|
+
state: string;
|
|
28
|
+
/**
|
|
29
|
+
* - Physical store identity.
|
|
30
|
+
*/
|
|
31
|
+
storeIdentity: string;
|
|
32
|
+
};
|
|
33
|
+
export type DerivedSyncChannel = {
|
|
34
|
+
/**
|
|
35
|
+
* - Channel name.
|
|
36
|
+
*/
|
|
37
|
+
channel: string;
|
|
38
|
+
/**
|
|
39
|
+
* - In-memory cursor watermark.
|
|
40
|
+
*/
|
|
41
|
+
cursor: import("./sync-api-client-types.js").SyncCursor;
|
|
42
|
+
/**
|
|
43
|
+
* - Default resource type for pushed changes.
|
|
44
|
+
*/
|
|
45
|
+
resourceType: string | null;
|
|
46
|
+
/**
|
|
47
|
+
* - Owning scope row, or null for legacy channels.
|
|
48
|
+
*/
|
|
49
|
+
scopeRow: SyncRealtimeScopeRow | null;
|
|
50
|
+
/**
|
|
51
|
+
* - Subscription handle.
|
|
52
|
+
*/
|
|
53
|
+
subscription: import("../configuration-types.js").VelociousSyncRealtimeSubscription;
|
|
54
|
+
};
|
|
55
|
+
export type DerivedSyncChannelDescriptor = {
|
|
56
|
+
/**
|
|
57
|
+
* - Channel name.
|
|
58
|
+
*/
|
|
59
|
+
channel: string;
|
|
60
|
+
/**
|
|
61
|
+
* - In-memory cursor watermark (null for legacy channels).
|
|
62
|
+
*/
|
|
63
|
+
cursor: import("./sync-api-client-types.js").SyncCursor;
|
|
64
|
+
/**
|
|
65
|
+
* - Subscribe params (without the framework-injected auth token).
|
|
66
|
+
*/
|
|
67
|
+
params: Record<string, ReturnType<typeof JSON.parse>>;
|
|
68
|
+
/**
|
|
69
|
+
* - Default resource type for pushed changes.
|
|
70
|
+
*/
|
|
71
|
+
resourceType: string | null;
|
|
72
|
+
/**
|
|
73
|
+
* - Owning scope row, or null for legacy channels.
|
|
74
|
+
*/
|
|
75
|
+
scopeRow: SyncRealtimeScopeRow | null;
|
|
76
|
+
};
|
|
3
77
|
/** @typedef {import("../configuration-types.js").VelociousSyncRealtimeChannelDescriptor} VelociousSyncRealtimeChannelDescriptor */
|
|
4
78
|
/** @typedef {import("../configuration-types.js").VelociousSyncRealtimeWebsocketClient} VelociousSyncRealtimeWebsocketClient */
|
|
79
|
+
/**
|
|
80
|
+
* The persisted scope row the bridge carries so it can advance the scope's cursor
|
|
81
|
+
* on applied pushes. Mirrors the framework-owned scope store row shape.
|
|
82
|
+
* @typedef {object} SyncRealtimeScopeRow
|
|
83
|
+
* @property {Record<string, ReturnType<typeof JSON.parse>>} conditions - Scope attribute conditions.
|
|
84
|
+
* @property {string | null} cursorPayload - Persisted cursor JSON payload.
|
|
85
|
+
* @property {string} id - Scope row id.
|
|
86
|
+
* @property {string | null} resourceType - Scope resource type.
|
|
87
|
+
* @property {string} scopeDigest - Fixed-size scope digest.
|
|
88
|
+
* @property {string} state - Scope state.
|
|
89
|
+
* @property {string} storeIdentity - Physical store identity.
|
|
90
|
+
*/
|
|
91
|
+
/**
|
|
92
|
+
* One derived channel subscription carrying its owning scope row (null for legacy
|
|
93
|
+
* app channels) and the in-memory cursor watermark advanced by applied pushes.
|
|
94
|
+
* @typedef {object} DerivedSyncChannel
|
|
95
|
+
* @property {string} channel - Channel name.
|
|
96
|
+
* @property {import("./sync-api-client-types.js").SyncCursor} cursor - In-memory cursor watermark.
|
|
97
|
+
* @property {string | null} resourceType - Default resource type for pushed changes.
|
|
98
|
+
* @property {SyncRealtimeScopeRow | null} scopeRow - Owning scope row, or null for legacy channels.
|
|
99
|
+
* @property {import("../configuration-types.js").VelociousSyncRealtimeSubscription} subscription - Subscription handle.
|
|
100
|
+
*/
|
|
101
|
+
/**
|
|
102
|
+
* One derived channel to subscribe, carrying its owning scope row and cursor for
|
|
103
|
+
* framework sync channel subscriptions (null scope row for legacy app channels).
|
|
104
|
+
* @typedef {object} DerivedSyncChannelDescriptor
|
|
105
|
+
* @property {string} channel - Channel name.
|
|
106
|
+
* @property {import("./sync-api-client-types.js").SyncCursor} cursor - In-memory cursor watermark (null for legacy channels).
|
|
107
|
+
* @property {Record<string, ReturnType<typeof JSON.parse>>} params - Subscribe params (without the framework-injected auth token).
|
|
108
|
+
* @property {string | null} resourceType - Default resource type for pushed changes.
|
|
109
|
+
* @property {SyncRealtimeScopeRow | null} scopeRow - Owning scope row, or null for legacy channels.
|
|
110
|
+
*/
|
|
5
111
|
/**
|
|
6
112
|
* Derived realtime push bridge for the sync client. Subscribes every declared
|
|
7
113
|
* pull scope to the framework sync channel ({@link VELOCIOUS_SYNC_CHANNEL})
|
|
@@ -17,12 +123,8 @@ export type VelociousSyncRealtimeWebsocketClient = import("../configuration-type
|
|
|
17
123
|
*/
|
|
18
124
|
export default class SyncRealtimeBridge {
|
|
19
125
|
syncClient: import("./sync-client.js").default;
|
|
20
|
-
/** @type {Array<
|
|
21
|
-
_channels: Array<
|
|
22
|
-
channel: string;
|
|
23
|
-
resourceType: string | null;
|
|
24
|
-
subscription: import("../configuration-types.js").VelociousSyncRealtimeSubscription;
|
|
25
|
-
}>;
|
|
126
|
+
/** @type {Array<DerivedSyncChannel>} */
|
|
127
|
+
_channels: Array<DerivedSyncChannel>;
|
|
26
128
|
/** @type {VelociousSyncRealtimeWebsocketClient | null} */
|
|
27
129
|
_client: VelociousSyncRealtimeWebsocketClient | null;
|
|
28
130
|
/** @type {boolean} Whether the bridge created its own client (deprecated per-cycle path) and must disconnect it on unsubscribe. A shared connection is never owned. */
|
|
@@ -32,8 +134,6 @@ export default class SyncRealtimeBridge {
|
|
|
32
134
|
/** @type {number} Subscription generation - bumped by unsubscribe so in-flight subscribes detect they became stale. */
|
|
33
135
|
_generation: number;
|
|
34
136
|
/** @type {Promise<void> | null} */
|
|
35
|
-
_scheduledPull: Promise<void> | null;
|
|
36
|
-
/** @type {Promise<void> | null} */
|
|
37
137
|
_subscribePromise: Promise<void> | null;
|
|
38
138
|
/** @type {"subscribed" | "subscribing" | "unsubscribed"} */
|
|
39
139
|
_state: "subscribed" | "subscribing" | "unsubscribed";
|
|
@@ -90,7 +190,7 @@ export default class SyncRealtimeBridge {
|
|
|
90
190
|
state: "subscribed" | "subscribing" | "unsubscribed";
|
|
91
191
|
};
|
|
92
192
|
/**
|
|
93
|
-
* Awaits all enqueued message applies
|
|
193
|
+
* Awaits all enqueued message applies (tests, shutdown flows).
|
|
94
194
|
* @returns {Promise<void>}
|
|
95
195
|
*/
|
|
96
196
|
waitForApplied(): Promise<void>;
|
|
@@ -115,9 +215,9 @@ export default class SyncRealtimeBridge {
|
|
|
115
215
|
* model-level static realtime declarations and the config channels callback.
|
|
116
216
|
* Fails loudly when nothing is subscribable.
|
|
117
217
|
* @param {ReturnType<typeof JSON.parse>} context - App context passed to the deprecated channels callback.
|
|
118
|
-
* @returns {Promise<Array<
|
|
218
|
+
* @returns {Promise<Array<DerivedSyncChannelDescriptor>>} Channel descriptors.
|
|
119
219
|
*/
|
|
120
|
-
channelDescriptors(context: ReturnType<typeof JSON.parse>): Promise<Array<
|
|
220
|
+
channelDescriptors(context: ReturnType<typeof JSON.parse>): Promise<Array<DerivedSyncChannelDescriptor>>;
|
|
121
221
|
/**
|
|
122
222
|
* Translates a persisted scope's condition keys to the model's attribute
|
|
123
223
|
* names so the framework channel subscription matches the publisher's
|
|
@@ -141,32 +241,35 @@ export default class SyncRealtimeBridge {
|
|
|
141
241
|
/**
|
|
142
242
|
* Chains one pushed message onto the serialized apply queue so changes apply
|
|
143
243
|
* in arrival order; failures go to the sync client's error reporting.
|
|
144
|
-
* @param {{body: ReturnType<typeof JSON.parse>, generation?: number
|
|
244
|
+
* @param {{body: ReturnType<typeof JSON.parse>, channel: DerivedSyncChannel, generation?: number}} args - Message args.
|
|
145
245
|
* @returns {void}
|
|
146
246
|
*/
|
|
147
|
-
enqueueApply({ body,
|
|
247
|
+
enqueueApply({ body, channel, generation }: {
|
|
148
248
|
body: ReturnType<typeof JSON.parse>;
|
|
249
|
+
channel: DerivedSyncChannel;
|
|
149
250
|
generation?: number;
|
|
150
|
-
resourceType: string | null;
|
|
151
251
|
}): void;
|
|
152
252
|
/**
|
|
153
253
|
* Applies one pushed message through the derived resource applier: drops
|
|
154
254
|
* own-device messages by echo origin, defaults the channel's resourceType onto
|
|
155
|
-
* envelopes without one,
|
|
156
|
-
*
|
|
255
|
+
* envelopes without one, fails loudly on unknown resource types, and advances
|
|
256
|
+
* the owning scope's cursor so a later replay resumes after the applied rows.
|
|
257
|
+
* @param {{body: ReturnType<typeof JSON.parse>, channel: DerivedSyncChannel}} args - Message args.
|
|
157
258
|
* @returns {Promise<void>}
|
|
158
259
|
*/
|
|
159
|
-
applyMessage({ body,
|
|
260
|
+
applyMessage({ body, channel }: {
|
|
160
261
|
body: ReturnType<typeof JSON.parse>;
|
|
161
|
-
|
|
262
|
+
channel: DerivedSyncChannel;
|
|
162
263
|
}): Promise<void>;
|
|
163
264
|
/**
|
|
164
|
-
*
|
|
165
|
-
* (
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* @
|
|
265
|
+
* Advances the owning scope's persisted cursor to the newest applied row,
|
|
266
|
+
* monotonically (never backwards) so an out-of-order or duplicate push cannot
|
|
267
|
+
* regress the cursor and re-deliver already-applied rows on a later replay.
|
|
268
|
+
* Legacy channels with no owning scope are skipped.
|
|
269
|
+
* @param {DerivedSyncChannel} channel - Channel owning the scope.
|
|
270
|
+
* @param {Array<ReturnType<typeof JSON.parse>>} syncPayloads - Applied sync entries.
|
|
271
|
+
* @returns {Promise<void>}
|
|
169
272
|
*/
|
|
170
|
-
|
|
273
|
+
advanceScopeCursor(channel: DerivedSyncChannel, syncPayloads: Array<ReturnType<typeof JSON.parse>>): Promise<void>;
|
|
171
274
|
}
|
|
172
275
|
//# sourceMappingURL=sync-realtime-bridge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-realtime-bridge.d.ts","sourceRoot":"","sources":["../../../src/sync/sync-realtime-bridge.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sync-realtime-bridge.d.ts","sourceRoot":"","sources":["../../../src/sync/sync-realtime-bridge.js"],"names":[],"mappings":"AASI,YAAsF,sCAAsC,GAAlH,OAAO,2BAA2B,EAAE,sCAAsC,CAAwC;AAC5H,YAAoF,oCAAoC,GAA9G,OAAO,2BAA2B,EAAE,oCAAoC,CAAsC;AAKzH,YAAkB,oBAAoB,GACtC;;;;IAA0D,UAAU,EAAzD,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CACxD;;;;IAA0B,aAAa,EAA5B,MAAM,GAAG,IAAI,CACxB;;;;IAAmB,EAAE,EAAV,MAAM,CACjB;;;;IAA0B,YAAY,EAA3B,MAAM,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