@superdurable/dex 0.1.3 → 0.1.4

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 (56) hide show
  1. package/README.md +55 -3
  2. package/dist/src/attribute-store-sync.d.ts +5 -0
  3. package/dist/src/attribute-store-sync.js +19 -0
  4. package/dist/src/attribute-store-sync.js.map +1 -0
  5. package/dist/src/blob-cache.d.ts +36 -0
  6. package/dist/src/blob-cache.js +13 -0
  7. package/dist/src/blob-cache.js.map +1 -1
  8. package/dist/src/client.d.ts +183 -4
  9. package/dist/src/client.js +152 -37
  10. package/dist/src/client.js.map +1 -1
  11. package/dist/src/codec.d.ts +73 -0
  12. package/dist/src/codec.js +23 -0
  13. package/dist/src/codec.js.map +1 -1
  14. package/dist/src/context.d.ts +80 -0
  15. package/dist/src/errors.d.ts +122 -6
  16. package/dist/src/errors.js +139 -9
  17. package/dist/src/errors.js.map +1 -1
  18. package/dist/src/flow.d.ts +36 -1
  19. package/dist/src/flow.js +96 -28
  20. package/dist/src/flow.js.map +1 -1
  21. package/dist/src/gen/dex.d.ts +58 -9
  22. package/dist/src/gen/dex.js +417 -55
  23. package/dist/src/gen/dex.js.map +1 -1
  24. package/dist/src/grpc-status.d.ts +5 -4
  25. package/dist/src/grpc-status.js +52 -6
  26. package/dist/src/grpc-status.js.map +1 -1
  27. package/dist/src/invocation-context.js +3 -0
  28. package/dist/src/invocation-context.js.map +1 -1
  29. package/dist/src/options.d.ts +150 -1
  30. package/dist/src/options.js +53 -0
  31. package/dist/src/options.js.map +1 -1
  32. package/dist/src/persistence.d.ts +103 -0
  33. package/dist/src/persistence.js +98 -0
  34. package/dist/src/persistence.js.map +1 -1
  35. package/dist/src/rpc.d.ts +53 -0
  36. package/dist/src/rpc.js +17 -0
  37. package/dist/src/rpc.js.map +1 -1
  38. package/dist/src/step.d.ts +162 -0
  39. package/dist/src/step.js +85 -0
  40. package/dist/src/step.js.map +1 -1
  41. package/dist/src/value-mapper.js +48 -18
  42. package/dist/src/value-mapper.js.map +1 -1
  43. package/dist/src/wait.d.ts +180 -0
  44. package/dist/src/wait.js +157 -0
  45. package/dist/src/wait.js.map +1 -1
  46. package/dist/src/worker-dispatcher.js +52 -26
  47. package/dist/src/worker-dispatcher.js.map +1 -1
  48. package/dist/src/worker.d.ts +30 -1
  49. package/dist/src/worker.js +48 -2
  50. package/dist/src/worker.js.map +1 -1
  51. package/native/linux-aarch64/dex_blob_cache_node.node +0 -0
  52. package/native/linux-x86_64/dex_blob_cache_node.node +0 -0
  53. package/native/macos-aarch64/dex_blob_cache_node.node +0 -0
  54. package/native/macos-x86_64/dex_blob_cache_node.node +0 -0
  55. package/native/windows-x86_64/dex_blob_cache_node.node +0 -0
  56. package/package.json +2 -1
@@ -1,45 +1,148 @@
1
1
  import type { Channel, ChannelMap } from "./wait.js";
2
2
  import type { Codec } from "./codec.js";
3
3
  import type { Context } from "./context.js";
4
+ /** Selects how Dex indexes an Attribute for Flow search. */
4
5
  export declare const IndexType: Readonly<{
6
+ /** Indexes an exact string value. */
5
7
  readonly KEYWORD: "keyword";
8
+ /** Indexes a string for tokenized full-text matching. */
6
9
  readonly FULL_TEXT: "fullText";
10
+ /** Indexes every string in an array as a keyword. */
7
11
  readonly KEYWORD_ARRAY: "keywordArray";
12
+ /** Indexes a signed 64-bit integer. */
8
13
  readonly INT: "int";
14
+ /** Indexes a finite floating-point number. */
9
15
  readonly DOUBLE: "double";
16
+ /** Indexes a Boolean value. */
10
17
  readonly BOOL: "bool";
18
+ /** Indexes a JavaScript Date value. */
11
19
  readonly DATETIME: "datetime";
12
20
  }>;
21
+ /** Represents a value from {@link IndexType}. */
13
22
  export type IndexType = (typeof IndexType)[keyof typeof IndexType];
23
+ /** Configures the search index for an Attribute or AttributeMap. */
14
24
  export interface AttributeIndex {
25
+ /** Value representation accepted by the search index. */
15
26
  readonly type: IndexType;
27
+ /** Physical search key; indexed AttributeMaps require an explicit key. */
16
28
  readonly indexKey?: string;
17
29
  }
30
+ /** Describes an Attribute lock acquired for a Step or RPC handler. */
18
31
  export interface AttributeLock {
32
+ /** Singleton Attribute or AttributeMap definition to lock. */
19
33
  readonly attribute: Attribute<unknown> | AttributeMap<unknown>;
34
+ /** AttributeMap instance; omitted for a singleton Attribute. */
20
35
  readonly instance?: string;
21
36
  }
37
+ /**
38
+ * Defines a typed, durable singleton value owned by a Flow.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * const status = new Attribute("status", stringCodec, {
43
+ * type: IndexType.KEYWORD,
44
+ * });
45
+ * const persistence: PersistenceSchema = { attributes: [status] };
46
+ * ```
47
+ * @typeParam T - Value encoded by the Attribute's codec.
48
+ */
22
49
  export declare class Attribute<T> {
23
50
  readonly name: string;
24
51
  readonly codec: Codec<T>;
25
52
  readonly index?: AttributeIndex | undefined;
53
+ /**
54
+ * Creates an Attribute definition for a PersistenceSchema.
55
+ * @param name - Non-empty logical name unique within the Flow.
56
+ * @param codec - Value codec used by handlers and Client calls.
57
+ * @param index - Optional visibility search index.
58
+ */
26
59
  constructor(name: string, codec: Codec<T>, index?: AttributeIndex | undefined);
60
+ /**
61
+ * Reads the current value from handler decision state.
62
+ * @param context - Current Step or RPC Context.
63
+ * @returns The decoded Attribute value.
64
+ */
27
65
  get(context: Context): T;
66
+ /**
67
+ * Stages a value to persist with the current decision.
68
+ * @param context - Current Step or RPC Context.
69
+ * @param value - Typed value to persist.
70
+ */
28
71
  set(context: Context, value: T): void;
72
+ /**
73
+ * Stages deletion in the current decision.
74
+ * @param context - Current Step or RPC Context.
75
+ */
29
76
  delete(context: Context): void;
77
+ /**
78
+ * Returns an immutable Attribute definition whose writes are projected to the Flow's Attribute Store.
79
+ *
80
+ * Projection is asynchronous and latest-state only. Deletion writes SQL `NULL`, projection failures do
81
+ * not roll back Flow Attribute writes, and the Flow must select a configured Attribute Store name.
82
+ * @returns A new synced definition; this definition remains unchanged.
83
+ */
84
+ syncToAttributeStore(): Attribute<T>;
85
+ /**
86
+ * Creates a lock request for this Attribute.
87
+ * @returns A lock for this singleton Attribute.
88
+ */
30
89
  lock(): AttributeLock;
31
90
  }
91
+ /**
92
+ * Defines a typed family of durable values keyed by map instance.
93
+ * @typeParam T - Value encoded for every map instance.
94
+ */
32
95
  export declare class AttributeMap<T> {
33
96
  readonly name: string;
34
97
  readonly codec: Codec<T>;
35
98
  readonly index?: AttributeIndex | undefined;
99
+ /**
100
+ * Creates an AttributeMap definition for a PersistenceSchema.
101
+ * @param name - Non-empty logical name unique within the Flow.
102
+ * @param codec - Value codec shared by every instance.
103
+ * @param index - Optional shared visibility search index.
104
+ */
36
105
  constructor(name: string, codec: Codec<T>, index?: AttributeIndex | undefined);
106
+ /**
107
+ * Reads one map instance from handler decision state.
108
+ * @param context - Current Step or RPC Context.
109
+ * @param instance - Non-empty logical map key.
110
+ * @returns The decoded instance value.
111
+ */
37
112
  get(context: Context, instance: string): T;
113
+ /**
114
+ * Stages one map-instance write.
115
+ * @param context - Current Step or RPC Context.
116
+ * @param instance - Non-empty logical map key.
117
+ * @param value - Typed value to persist.
118
+ */
38
119
  set(context: Context, instance: string, value: T): void;
120
+ /**
121
+ * Stages deletion of one map instance.
122
+ * @param context - Current Step or RPC Context.
123
+ * @param instance - Non-empty logical map key.
124
+ */
39
125
  delete(context: Context, instance: string): void;
126
+ /**
127
+ * Returns an immutable AttributeMap definition whose writes are projected to the Flow's Attribute Store.
128
+ *
129
+ * Projection is asynchronous and latest-state only. Each map instance uses its physical Attribute name.
130
+ * Deletion writes SQL `NULL`, projection failures do not roll back Flow Attribute writes, and the Flow
131
+ * must select a configured Attribute Store name.
132
+ * @returns A new synced definition; this definition remains unchanged.
133
+ */
134
+ syncToAttributeStore(): AttributeMap<T>;
135
+ /**
136
+ * Creates a lock request scoped to one map instance.
137
+ * @param instance - Non-empty logical map key.
138
+ * @returns A lock for the requested instance.
139
+ */
40
140
  lock(instance: string): AttributeLock;
41
141
  }
142
+ /** Declares the Attributes and Channels owned by a Flow type. */
42
143
  export interface PersistenceSchema {
144
+ /** Singleton and map Attribute definitions with unique names. */
43
145
  readonly attributes?: readonly (Attribute<unknown> | AttributeMap<unknown>)[];
146
+ /** Singleton and map Channel definitions with unique names. */
44
147
  readonly channels?: readonly (Channel<unknown> | ChannelMap<unknown>)[];
45
148
  }
@@ -5,58 +5,156 @@
5
5
  // See the LICENSE file in the repository root.
6
6
  //
7
7
  // SPDX-License-Identifier: LicenseRef-Super-Durable-1.0
8
+ import { markAttributeStoreSynced } from "./attribute-store-sync.js";
8
9
  import { requireName } from "./validation.js";
10
+ /** Selects how Dex indexes an Attribute for Flow search. */
9
11
  export const IndexType = Object.freeze({
12
+ /** Indexes an exact string value. */
10
13
  KEYWORD: "keyword",
14
+ /** Indexes a string for tokenized full-text matching. */
11
15
  FULL_TEXT: "fullText",
16
+ /** Indexes every string in an array as a keyword. */
12
17
  KEYWORD_ARRAY: "keywordArray",
18
+ /** Indexes a signed 64-bit integer. */
13
19
  INT: "int",
20
+ /** Indexes a finite floating-point number. */
14
21
  DOUBLE: "double",
22
+ /** Indexes a Boolean value. */
15
23
  BOOL: "bool",
24
+ /** Indexes a JavaScript Date value. */
16
25
  DATETIME: "datetime",
17
26
  });
27
+ /**
28
+ * Defines a typed, durable singleton value owned by a Flow.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const status = new Attribute("status", stringCodec, {
33
+ * type: IndexType.KEYWORD,
34
+ * });
35
+ * const persistence: PersistenceSchema = { attributes: [status] };
36
+ * ```
37
+ * @typeParam T - Value encoded by the Attribute's codec.
38
+ */
18
39
  export class Attribute {
19
40
  name;
20
41
  codec;
21
42
  index;
43
+ /**
44
+ * Creates an Attribute definition for a PersistenceSchema.
45
+ * @param name - Non-empty logical name unique within the Flow.
46
+ * @param codec - Value codec used by handlers and Client calls.
47
+ * @param index - Optional visibility search index.
48
+ */
22
49
  constructor(name, codec, index) {
23
50
  this.name = name;
24
51
  this.codec = codec;
25
52
  this.index = index;
26
53
  requireName(name);
27
54
  }
55
+ /**
56
+ * Reads the current value from handler decision state.
57
+ * @param context - Current Step or RPC Context.
58
+ * @returns The decoded Attribute value.
59
+ */
28
60
  get(context) {
29
61
  return context.getAttribute(this);
30
62
  }
63
+ /**
64
+ * Stages a value to persist with the current decision.
65
+ * @param context - Current Step or RPC Context.
66
+ * @param value - Typed value to persist.
67
+ */
31
68
  set(context, value) {
32
69
  context.setAttribute(this, value);
33
70
  }
71
+ /**
72
+ * Stages deletion in the current decision.
73
+ * @param context - Current Step or RPC Context.
74
+ */
34
75
  delete(context) {
35
76
  context.deleteAttribute(this);
36
77
  }
78
+ /**
79
+ * Returns an immutable Attribute definition whose writes are projected to the Flow's Attribute Store.
80
+ *
81
+ * Projection is asynchronous and latest-state only. Deletion writes SQL `NULL`, projection failures do
82
+ * not roll back Flow Attribute writes, and the Flow must select a configured Attribute Store name.
83
+ * @returns A new synced definition; this definition remains unchanged.
84
+ */
85
+ syncToAttributeStore() {
86
+ return markAttributeStoreSynced(new Attribute(this.name, this.codec, this.index));
87
+ }
88
+ /**
89
+ * Creates a lock request for this Attribute.
90
+ * @returns A lock for this singleton Attribute.
91
+ */
37
92
  lock() {
38
93
  return { attribute: this };
39
94
  }
40
95
  }
96
+ /**
97
+ * Defines a typed family of durable values keyed by map instance.
98
+ * @typeParam T - Value encoded for every map instance.
99
+ */
41
100
  export class AttributeMap {
42
101
  name;
43
102
  codec;
44
103
  index;
104
+ /**
105
+ * Creates an AttributeMap definition for a PersistenceSchema.
106
+ * @param name - Non-empty logical name unique within the Flow.
107
+ * @param codec - Value codec shared by every instance.
108
+ * @param index - Optional shared visibility search index.
109
+ */
45
110
  constructor(name, codec, index) {
46
111
  this.name = name;
47
112
  this.codec = codec;
48
113
  this.index = index;
49
114
  requireName(name);
50
115
  }
116
+ /**
117
+ * Reads one map instance from handler decision state.
118
+ * @param context - Current Step or RPC Context.
119
+ * @param instance - Non-empty logical map key.
120
+ * @returns The decoded instance value.
121
+ */
51
122
  get(context, instance) {
52
123
  return context.getAttribute(this, instance);
53
124
  }
125
+ /**
126
+ * Stages one map-instance write.
127
+ * @param context - Current Step or RPC Context.
128
+ * @param instance - Non-empty logical map key.
129
+ * @param value - Typed value to persist.
130
+ */
54
131
  set(context, instance, value) {
55
132
  context.setAttribute(this, value, instance);
56
133
  }
134
+ /**
135
+ * Stages deletion of one map instance.
136
+ * @param context - Current Step or RPC Context.
137
+ * @param instance - Non-empty logical map key.
138
+ */
57
139
  delete(context, instance) {
58
140
  context.deleteAttribute(this, instance);
59
141
  }
142
+ /**
143
+ * Returns an immutable AttributeMap definition whose writes are projected to the Flow's Attribute Store.
144
+ *
145
+ * Projection is asynchronous and latest-state only. Each map instance uses its physical Attribute name.
146
+ * Deletion writes SQL `NULL`, projection failures do not roll back Flow Attribute writes, and the Flow
147
+ * must select a configured Attribute Store name.
148
+ * @returns A new synced definition; this definition remains unchanged.
149
+ */
150
+ syncToAttributeStore() {
151
+ return markAttributeStoreSynced(new AttributeMap(this.name, this.codec, this.index));
152
+ }
153
+ /**
154
+ * Creates a lock request scoped to one map instance.
155
+ * @param instance - Non-empty logical map key.
156
+ * @returns A lock for the requested instance.
157
+ */
60
158
  lock(instance) {
61
159
  requireName(instance);
62
160
  return { attribute: this, instance };
@@ -1 +1 @@
1
- {"version":3,"file":"persistence.js","sourceRoot":"","sources":["../../src/persistence.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,uDAAuD;AACvD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,wDAAwD;AAKxD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,UAAU;IACrB,aAAa,EAAE,cAAc;IAC7B,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,UAAU;CACZ,CAAC,CAAC;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AAC,QAAgB;QAC1B,WAAW,CAAC,QAAQ,CAAC,CAAC;QACtB,OAAO,EAAE,SAAS,EAAE,IAA6B,EAAE,QAAQ,EAAE,CAAC;IAChE,CAAC;CACF"}
package/dist/src/rpc.d.ts CHANGED
@@ -3,16 +3,37 @@ import type { Context } from "./context.js";
3
3
  import type { Flow } from "./flow.js";
4
4
  import type { AttributeLock } from "./persistence.js";
5
5
  import type { StepMovement } from "./step.js";
6
+ /**
7
+ * Contains a typed RPC output and optional next-Step movements.
8
+ * @typeParam Output - Value decoded for the Client caller.
9
+ */
6
10
  export interface RPCResult<Output> {
11
+ /** Typed application result. */
7
12
  readonly output: Output;
13
+ /** Step movements applied atomically with handler persistence writes. */
8
14
  readonly nextSteps?: readonly StepMovement<unknown>[];
9
15
  }
16
+ /**
17
+ * Describes a typed, possibly asynchronous RPC handler.
18
+ * @typeParam Input - Handler input type.
19
+ * @typeParam Output - Handler output type.
20
+ */
10
21
  export type RPC<Input, Output> = (context: Context, input: Input) => RPCResult<Output> | Promise<RPCResult<Output>>;
22
+ /**
23
+ * Configures an RPC decorator's name, codecs, timeout, and Attribute locks.
24
+ * @typeParam Input - Handler input type.
25
+ * @typeParam Output - Handler output type.
26
+ */
11
27
  export interface RPCOptions<Input = unknown, Output = unknown> {
28
+ /** Protocol RPC name; uses the decorated method name when omitted. */
12
29
  readonly name?: string;
30
+ /** Required input codec for handlers that accept an input. */
13
31
  readonly inputCodec?: Codec<Input>;
32
+ /** Required output codec for handlers returning RPCResult. */
14
33
  readonly outputCodec?: Codec<Output>;
34
+ /** Non-negative handler timeout in milliseconds. */
15
35
  readonly timeoutMs?: number;
36
+ /** Attribute locks held for the entire invocation. */
16
37
  readonly lockAttributes?: readonly AttributeLock[];
17
38
  }
18
39
  export interface RegisteredRPC {
@@ -20,20 +41,52 @@ export interface RegisteredRPC {
20
41
  readonly name: string;
21
42
  readonly options: RPCOptions<any, any>;
22
43
  }
44
+ /**
45
+ * Decorates an RPC with both typed input and output.
46
+ * @typeParam Input - Handler input type.
47
+ * @typeParam Output - Handler output type.
48
+ * @param options - Required input/output codecs and optional RPC settings.
49
+ * @returns A stage-3 method decorator validated during Registry construction.
50
+ */
23
51
  export declare function rpc<Input, Output>(options: RPCOptions<Input, Output> & {
52
+ /** Required codec for the handler input. */
24
53
  readonly inputCodec: Codec<Input>;
54
+ /** Required codec for the RPCResult output. */
25
55
  readonly outputCodec: Codec<Output>;
26
56
  }): <This>(method: (this: This, context: Context, input: Input) => RPCResult<Output> | Promise<RPCResult<Output>>, context: ClassMethodDecoratorContext<This, (this: This, context: Context, input: Input) => RPCResult<Output> | Promise<RPCResult<Output>>>) => void;
57
+ /**
58
+ * Decorates an input-free RPC with typed output.
59
+ * @typeParam Output - Handler output type.
60
+ * @param options - Required output codec and optional RPC settings.
61
+ * @returns A stage-3 method decorator validated during Registry construction.
62
+ */
27
63
  export declare function rpc<Output>(options: RPCOptions<never, Output> & {
64
+ /** Input codecs are forbidden for an input-free handler. */
28
65
  readonly inputCodec?: never;
66
+ /** Required codec for the RPCResult output. */
29
67
  readonly outputCodec: Codec<Output>;
30
68
  }): <This>(method: (this: This, context: Context) => RPCResult<Output> | Promise<RPCResult<Output>>, context: ClassMethodDecoratorContext<This, (this: This, context: Context) => RPCResult<Output> | Promise<RPCResult<Output>>>) => void;
69
+ /**
70
+ * Decorates a typed-input RPC with no output.
71
+ * @typeParam Input - Handler input type.
72
+ * @param options - Required input codec and optional RPC settings.
73
+ * @returns A stage-3 method decorator validated during Registry construction.
74
+ */
31
75
  export declare function rpc<Input>(options: RPCOptions<Input, never> & {
76
+ /** Required codec for the handler input. */
32
77
  readonly inputCodec: Codec<Input>;
78
+ /** Output codecs are forbidden for a void handler. */
33
79
  readonly outputCodec?: never;
34
80
  }): <This>(method: (this: This, context: Context, input: Input) => void | Promise<void>, context: ClassMethodDecoratorContext<This, (this: This, context: Context, input: Input) => void | Promise<void>>) => void;
81
+ /**
82
+ * Decorates an input-free, output-free RPC.
83
+ * @param options - Optional name, timeout, and Attribute locks.
84
+ * @returns A stage-3 method decorator validated during Registry construction.
85
+ */
35
86
  export declare function rpc(options?: RPCOptions<never, never> & {
87
+ /** Input codecs are forbidden for an input-free handler. */
36
88
  readonly inputCodec?: never;
89
+ /** Output codecs are forbidden for a void handler. */
37
90
  readonly outputCodec?: never;
38
91
  }): <This>(method: (this: This, context: Context) => void | Promise<void>, context: ClassMethodDecoratorContext<This, (this: This, context: Context) => void | Promise<void>>) => void;
39
92
  export declare function registeredRPCs(flow: Flow<unknown>): readonly RegisteredRPC[];
package/dist/src/rpc.js CHANGED
@@ -7,6 +7,23 @@
7
7
  // SPDX-License-Identifier: LicenseRef-Super-Durable-1.0
8
8
  import { requireName } from "./validation.js";
9
9
  const rpcOptions = new WeakMap();
10
+ /**
11
+ * Creates a typed RPC method decorator.
12
+ *
13
+ * Registry construction validates handler shape, codecs, unique names, and locks.
14
+ * The handler receives Context and optional input, then returns RPCResult or void.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * @rpc({ inputCodec: stringCodec, outputCodec: booleanCodec, timeoutMs: 10_000 })
19
+ * async cancel(context: Context, reason: string): Promise<RPCResult<boolean>> {
20
+ * return { output: true };
21
+ * }
22
+ * ```
23
+ * @param options - Codecs and optional name, timeout, and lock settings.
24
+ * @returns A stage-3 method decorator.
25
+ * @throws {@link RangeError} when `timeoutMs` is negative.
26
+ */
10
27
  export function rpc(options = {}) {
11
28
  if (options.name !== undefined) {
12
29
  requireName(options.name);
@@ -1 +1 @@
1
- {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../src/rpc.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,uDAAuD;AACvD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,wDAAwD;AAOxD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AA0B9C,MAAM,UAAU,GAAG,IAAI,OAAO,EAAkC,CAAC;AAmDjE,MAAM,UAAU,GAAG,CAAC,UA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