@replanejs/test-suite 0.8.19
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/LICENSE +21 -0
- package/dist/index.cjs +937 -0
- package/dist/index.d.cts +213 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +213 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +908 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { ConfigValue, Override, ReplaneAdmin } from "@replanejs/admin";
|
|
2
|
+
import { ReplaneClient } from "@replanejs/sdk";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Options for the test suite
|
|
8
|
+
*/
|
|
9
|
+
interface TestSuiteOptions {
|
|
10
|
+
/** Superadmin API key for creating workspaces */
|
|
11
|
+
superadminKey: string;
|
|
12
|
+
/** Base URL for the admin API (e.g., "http://localhost:8080") */
|
|
13
|
+
adminApiBaseUrl: string;
|
|
14
|
+
/** Base URL for the edge API (e.g., "http://localhost:8080") */
|
|
15
|
+
edgeApiBaseUrl: string;
|
|
16
|
+
/** Default timeout for waiting operations in ms (default: 5000) */
|
|
17
|
+
defaultTimeout?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Test context available in each test
|
|
21
|
+
*/
|
|
22
|
+
interface TestContext {
|
|
23
|
+
/** Admin client for managing resources */
|
|
24
|
+
admin: ReplaneAdmin;
|
|
25
|
+
/** Workspace ID created for this test run */
|
|
26
|
+
workspaceId: string;
|
|
27
|
+
/** Project ID created for this test run */
|
|
28
|
+
projectId: string;
|
|
29
|
+
/** Environment ID (production) for this project */
|
|
30
|
+
environmentId: string;
|
|
31
|
+
/** SDK key for connecting to edge API */
|
|
32
|
+
sdkKey: string;
|
|
33
|
+
/** Edge API base URL */
|
|
34
|
+
edgeApiBaseUrl: string;
|
|
35
|
+
/** Admin API base URL */
|
|
36
|
+
adminApiBaseUrl: string;
|
|
37
|
+
/** Default timeout for waiting operations */
|
|
38
|
+
defaultTimeout: number;
|
|
39
|
+
/**
|
|
40
|
+
* Sync the edge replica with the database
|
|
41
|
+
*/
|
|
42
|
+
sync(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Create a new SDK client connected to the edge API
|
|
45
|
+
*/
|
|
46
|
+
createClient<T extends object = Record<string, unknown>>(options?: {
|
|
47
|
+
context?: Record<string, string | number | boolean | null | undefined>;
|
|
48
|
+
defaults?: Partial<T>;
|
|
49
|
+
required?: (keyof T)[] | Partial<T>;
|
|
50
|
+
}): Promise<ReplaneClient<T>>;
|
|
51
|
+
/**
|
|
52
|
+
* Create a config in the test project
|
|
53
|
+
*/
|
|
54
|
+
createConfig(name: string, value: ConfigValue, options?: {
|
|
55
|
+
description?: string;
|
|
56
|
+
overrides?: Override[];
|
|
57
|
+
}): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Update a config in the test project
|
|
60
|
+
*/
|
|
61
|
+
updateConfig(name: string, value: ConfigValue, options?: {
|
|
62
|
+
description?: string;
|
|
63
|
+
overrides?: Override[];
|
|
64
|
+
}): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Delete a config in the test project
|
|
67
|
+
*/
|
|
68
|
+
deleteConfig(name: string): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=types.d.ts.map
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/test-suite.d.ts
|
|
73
|
+
/**
|
|
74
|
+
* Main test suite function
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { testSuite } from "@replanejs/test-suite";
|
|
79
|
+
*
|
|
80
|
+
* testSuite({
|
|
81
|
+
* superadminKey: process.env.SUPERADMIN_KEY!,
|
|
82
|
+
* adminApiBaseUrl: "http://localhost:8080",
|
|
83
|
+
* edgeApiBaseUrl: "http://localhost:8080",
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
declare function testSuite(options: TestSuiteOptions): void;
|
|
88
|
+
//# sourceMappingURL=test-suite.d.ts.map
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/utils.d.ts
|
|
91
|
+
/**
|
|
92
|
+
* Test utilities for waiting with early resolution
|
|
93
|
+
*/
|
|
94
|
+
interface Deferred<T> {
|
|
95
|
+
promise: Promise<T>;
|
|
96
|
+
resolve: (value: T) => void;
|
|
97
|
+
reject: (reason?: unknown) => void;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates a deferred promise that can be resolved/rejected externally
|
|
101
|
+
*/
|
|
102
|
+
declare function createDeferred<T>(): Deferred<T>;
|
|
103
|
+
/**
|
|
104
|
+
* Options for waitFor utility
|
|
105
|
+
*/
|
|
106
|
+
interface WaitForOptions {
|
|
107
|
+
/** Timeout in milliseconds (default: 5000) */
|
|
108
|
+
timeout?: number;
|
|
109
|
+
/** Custom error message on timeout */
|
|
110
|
+
timeoutMessage?: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Waits for a condition to be met or times out.
|
|
114
|
+
* Returns immediately when condition is satisfied.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* let value: string | null = null;
|
|
119
|
+
* client.subscribe("config", (v) => { value = v; });
|
|
120
|
+
*
|
|
121
|
+
* await waitFor(() => value !== null, { timeout: 2000 });
|
|
122
|
+
* expect(value).toBe("expected");
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare function waitFor(condition: () => boolean | Promise<boolean>, options?: WaitForOptions): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* A signal that can be awaited and triggered.
|
|
128
|
+
* Useful for waiting for async events in tests.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* const signal = createSignal<string>();
|
|
133
|
+
*
|
|
134
|
+
* client.subscribe("config", (value) => {
|
|
135
|
+
* signal.trigger(value);
|
|
136
|
+
* });
|
|
137
|
+
*
|
|
138
|
+
* const value = await signal.wait({ timeout: 2000 });
|
|
139
|
+
* expect(value).toBe("expected");
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
interface Signal<T> {
|
|
143
|
+
/** Wait for the signal to be triggered */
|
|
144
|
+
wait(options?: WaitForOptions): Promise<T>;
|
|
145
|
+
/** Trigger the signal with a value */
|
|
146
|
+
trigger(value: T): void;
|
|
147
|
+
/** Check if signal has been triggered */
|
|
148
|
+
isTriggered(): boolean;
|
|
149
|
+
/** Reset the signal to untriggered state */
|
|
150
|
+
reset(): void;
|
|
151
|
+
/** Get the triggered value (undefined if not triggered) */
|
|
152
|
+
getValue(): T | undefined;
|
|
153
|
+
}
|
|
154
|
+
declare function createSignal<T = void>(): Signal<T>;
|
|
155
|
+
/**
|
|
156
|
+
* A collector that accumulates values and can wait for a specific count.
|
|
157
|
+
* Useful for collecting multiple updates in tests.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* const collector = createCollector<string>();
|
|
162
|
+
*
|
|
163
|
+
* client.subscribe("config", (value) => {
|
|
164
|
+
* collector.push(value);
|
|
165
|
+
* });
|
|
166
|
+
*
|
|
167
|
+
* // Wait for 3 updates
|
|
168
|
+
* const values = await collector.waitForCount(3, { timeout: 5000 });
|
|
169
|
+
* expect(values).toEqual(["v1", "v2", "v3"]);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
interface Collector<T> {
|
|
173
|
+
/** Push a value to the collector */
|
|
174
|
+
push(value: T): void;
|
|
175
|
+
/** Get all collected values */
|
|
176
|
+
getValues(): T[];
|
|
177
|
+
/** Get the count of collected values */
|
|
178
|
+
count(): number;
|
|
179
|
+
/** Wait for at least N values to be collected */
|
|
180
|
+
waitForCount(count: number, options?: WaitForOptions): Promise<T[]>;
|
|
181
|
+
/** Wait for a value matching the predicate */
|
|
182
|
+
waitFor(predicate: (value: T) => boolean, options?: WaitForOptions): Promise<T>;
|
|
183
|
+
/** Clear all collected values */
|
|
184
|
+
clear(): void;
|
|
185
|
+
}
|
|
186
|
+
declare function createCollector<T>(): Collector<T>;
|
|
187
|
+
/**
|
|
188
|
+
* Delay for a specified time (use sparingly in tests)
|
|
189
|
+
*/
|
|
190
|
+
declare function delay(ms: number): Promise<void>;
|
|
191
|
+
/**
|
|
192
|
+
* Generate a unique test identifier
|
|
193
|
+
*/
|
|
194
|
+
declare function uniqueId(prefix?: string): string;
|
|
195
|
+
/**
|
|
196
|
+
* Sync the edge replica with the database.
|
|
197
|
+
* Requires TESTING_MODE=true on the server.
|
|
198
|
+
*
|
|
199
|
+
* This is useful in tests to ensure the edge replica has
|
|
200
|
+
* received all config changes before making assertions.
|
|
201
|
+
*
|
|
202
|
+
* @param request - The request object containing the edge API base URL and admin API key
|
|
203
|
+
* @param request.edgeApiBaseUrl - The base URL of the edge API (e.g., "http://localhost:8080")
|
|
204
|
+
* @param request.adminApiKey - The admin API key
|
|
205
|
+
*/
|
|
206
|
+
declare function syncReplica(request: {
|
|
207
|
+
edgeApiBaseUrl: string;
|
|
208
|
+
sdkKey: string;
|
|
209
|
+
}): Promise<void>;
|
|
210
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
211
|
+
//#endregion
|
|
212
|
+
export { type Collector, type Deferred, type Signal, type TestContext, type TestSuiteOptions, type WaitForOptions, createCollector, createDeferred, createSignal, delay, syncReplica, testSuite, uniqueId, waitFor };
|
|
213
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/test-suite.ts","../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;;;AAMA;AAciB,UAdA,gBAAA,CAcW;EAAA;EAAA,aAEnB,EAAA,MAAA;EAAY;EAmBJ,eAKiB,EAAA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hD;;;;;;;;;;;AAU8E;AAK9E;;;;AAA+C,UAf9B,SAe8B,CAAA,CAAA,CAAA,CAAA;EA4F/B;EAOA,IAAA,CAAA,KAAA,EAhHF,CAgHU,CAAA,EAAA,IAAA;EAeF;eA7HP;;;;wCAIyB,iBAAiB,QAAQ;;6BAEpC,yBAAyB,iBAAiB,QAAQ;;;;iBAK/D,sBAAsB,UAAU;;;;iBA4FhC,KAAA,cAAmB;;;;iBAOnB,QAAA;;;;;;;;;;;;iBAeM,WAAA;;;IAGlB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { ConfigValue, Override, ReplaneAdmin } from "@replanejs/admin";
|
|
2
|
+
import { ReplaneClient } from "@replanejs/sdk";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Options for the test suite
|
|
8
|
+
*/
|
|
9
|
+
interface TestSuiteOptions {
|
|
10
|
+
/** Superadmin API key for creating workspaces */
|
|
11
|
+
superadminKey: string;
|
|
12
|
+
/** Base URL for the admin API (e.g., "http://localhost:8080") */
|
|
13
|
+
adminApiBaseUrl: string;
|
|
14
|
+
/** Base URL for the edge API (e.g., "http://localhost:8080") */
|
|
15
|
+
edgeApiBaseUrl: string;
|
|
16
|
+
/** Default timeout for waiting operations in ms (default: 5000) */
|
|
17
|
+
defaultTimeout?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Test context available in each test
|
|
21
|
+
*/
|
|
22
|
+
interface TestContext {
|
|
23
|
+
/** Admin client for managing resources */
|
|
24
|
+
admin: ReplaneAdmin;
|
|
25
|
+
/** Workspace ID created for this test run */
|
|
26
|
+
workspaceId: string;
|
|
27
|
+
/** Project ID created for this test run */
|
|
28
|
+
projectId: string;
|
|
29
|
+
/** Environment ID (production) for this project */
|
|
30
|
+
environmentId: string;
|
|
31
|
+
/** SDK key for connecting to edge API */
|
|
32
|
+
sdkKey: string;
|
|
33
|
+
/** Edge API base URL */
|
|
34
|
+
edgeApiBaseUrl: string;
|
|
35
|
+
/** Admin API base URL */
|
|
36
|
+
adminApiBaseUrl: string;
|
|
37
|
+
/** Default timeout for waiting operations */
|
|
38
|
+
defaultTimeout: number;
|
|
39
|
+
/**
|
|
40
|
+
* Sync the edge replica with the database
|
|
41
|
+
*/
|
|
42
|
+
sync(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Create a new SDK client connected to the edge API
|
|
45
|
+
*/
|
|
46
|
+
createClient<T extends object = Record<string, unknown>>(options?: {
|
|
47
|
+
context?: Record<string, string | number | boolean | null | undefined>;
|
|
48
|
+
defaults?: Partial<T>;
|
|
49
|
+
required?: (keyof T)[] | Partial<T>;
|
|
50
|
+
}): Promise<ReplaneClient<T>>;
|
|
51
|
+
/**
|
|
52
|
+
* Create a config in the test project
|
|
53
|
+
*/
|
|
54
|
+
createConfig(name: string, value: ConfigValue, options?: {
|
|
55
|
+
description?: string;
|
|
56
|
+
overrides?: Override[];
|
|
57
|
+
}): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Update a config in the test project
|
|
60
|
+
*/
|
|
61
|
+
updateConfig(name: string, value: ConfigValue, options?: {
|
|
62
|
+
description?: string;
|
|
63
|
+
overrides?: Override[];
|
|
64
|
+
}): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Delete a config in the test project
|
|
67
|
+
*/
|
|
68
|
+
deleteConfig(name: string): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=types.d.ts.map
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/test-suite.d.ts
|
|
73
|
+
/**
|
|
74
|
+
* Main test suite function
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { testSuite } from "@replanejs/test-suite";
|
|
79
|
+
*
|
|
80
|
+
* testSuite({
|
|
81
|
+
* superadminKey: process.env.SUPERADMIN_KEY!,
|
|
82
|
+
* adminApiBaseUrl: "http://localhost:8080",
|
|
83
|
+
* edgeApiBaseUrl: "http://localhost:8080",
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
declare function testSuite(options: TestSuiteOptions): void;
|
|
88
|
+
//# sourceMappingURL=test-suite.d.ts.map
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/utils.d.ts
|
|
91
|
+
/**
|
|
92
|
+
* Test utilities for waiting with early resolution
|
|
93
|
+
*/
|
|
94
|
+
interface Deferred<T> {
|
|
95
|
+
promise: Promise<T>;
|
|
96
|
+
resolve: (value: T) => void;
|
|
97
|
+
reject: (reason?: unknown) => void;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates a deferred promise that can be resolved/rejected externally
|
|
101
|
+
*/
|
|
102
|
+
declare function createDeferred<T>(): Deferred<T>;
|
|
103
|
+
/**
|
|
104
|
+
* Options for waitFor utility
|
|
105
|
+
*/
|
|
106
|
+
interface WaitForOptions {
|
|
107
|
+
/** Timeout in milliseconds (default: 5000) */
|
|
108
|
+
timeout?: number;
|
|
109
|
+
/** Custom error message on timeout */
|
|
110
|
+
timeoutMessage?: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Waits for a condition to be met or times out.
|
|
114
|
+
* Returns immediately when condition is satisfied.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* let value: string | null = null;
|
|
119
|
+
* client.subscribe("config", (v) => { value = v; });
|
|
120
|
+
*
|
|
121
|
+
* await waitFor(() => value !== null, { timeout: 2000 });
|
|
122
|
+
* expect(value).toBe("expected");
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare function waitFor(condition: () => boolean | Promise<boolean>, options?: WaitForOptions): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* A signal that can be awaited and triggered.
|
|
128
|
+
* Useful for waiting for async events in tests.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* const signal = createSignal<string>();
|
|
133
|
+
*
|
|
134
|
+
* client.subscribe("config", (value) => {
|
|
135
|
+
* signal.trigger(value);
|
|
136
|
+
* });
|
|
137
|
+
*
|
|
138
|
+
* const value = await signal.wait({ timeout: 2000 });
|
|
139
|
+
* expect(value).toBe("expected");
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
interface Signal<T> {
|
|
143
|
+
/** Wait for the signal to be triggered */
|
|
144
|
+
wait(options?: WaitForOptions): Promise<T>;
|
|
145
|
+
/** Trigger the signal with a value */
|
|
146
|
+
trigger(value: T): void;
|
|
147
|
+
/** Check if signal has been triggered */
|
|
148
|
+
isTriggered(): boolean;
|
|
149
|
+
/** Reset the signal to untriggered state */
|
|
150
|
+
reset(): void;
|
|
151
|
+
/** Get the triggered value (undefined if not triggered) */
|
|
152
|
+
getValue(): T | undefined;
|
|
153
|
+
}
|
|
154
|
+
declare function createSignal<T = void>(): Signal<T>;
|
|
155
|
+
/**
|
|
156
|
+
* A collector that accumulates values and can wait for a specific count.
|
|
157
|
+
* Useful for collecting multiple updates in tests.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* const collector = createCollector<string>();
|
|
162
|
+
*
|
|
163
|
+
* client.subscribe("config", (value) => {
|
|
164
|
+
* collector.push(value);
|
|
165
|
+
* });
|
|
166
|
+
*
|
|
167
|
+
* // Wait for 3 updates
|
|
168
|
+
* const values = await collector.waitForCount(3, { timeout: 5000 });
|
|
169
|
+
* expect(values).toEqual(["v1", "v2", "v3"]);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
interface Collector<T> {
|
|
173
|
+
/** Push a value to the collector */
|
|
174
|
+
push(value: T): void;
|
|
175
|
+
/** Get all collected values */
|
|
176
|
+
getValues(): T[];
|
|
177
|
+
/** Get the count of collected values */
|
|
178
|
+
count(): number;
|
|
179
|
+
/** Wait for at least N values to be collected */
|
|
180
|
+
waitForCount(count: number, options?: WaitForOptions): Promise<T[]>;
|
|
181
|
+
/** Wait for a value matching the predicate */
|
|
182
|
+
waitFor(predicate: (value: T) => boolean, options?: WaitForOptions): Promise<T>;
|
|
183
|
+
/** Clear all collected values */
|
|
184
|
+
clear(): void;
|
|
185
|
+
}
|
|
186
|
+
declare function createCollector<T>(): Collector<T>;
|
|
187
|
+
/**
|
|
188
|
+
* Delay for a specified time (use sparingly in tests)
|
|
189
|
+
*/
|
|
190
|
+
declare function delay(ms: number): Promise<void>;
|
|
191
|
+
/**
|
|
192
|
+
* Generate a unique test identifier
|
|
193
|
+
*/
|
|
194
|
+
declare function uniqueId(prefix?: string): string;
|
|
195
|
+
/**
|
|
196
|
+
* Sync the edge replica with the database.
|
|
197
|
+
* Requires TESTING_MODE=true on the server.
|
|
198
|
+
*
|
|
199
|
+
* This is useful in tests to ensure the edge replica has
|
|
200
|
+
* received all config changes before making assertions.
|
|
201
|
+
*
|
|
202
|
+
* @param request - The request object containing the edge API base URL and admin API key
|
|
203
|
+
* @param request.edgeApiBaseUrl - The base URL of the edge API (e.g., "http://localhost:8080")
|
|
204
|
+
* @param request.adminApiKey - The admin API key
|
|
205
|
+
*/
|
|
206
|
+
declare function syncReplica(request: {
|
|
207
|
+
edgeApiBaseUrl: string;
|
|
208
|
+
sdkKey: string;
|
|
209
|
+
}): Promise<void>;
|
|
210
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
211
|
+
//#endregion
|
|
212
|
+
export { type Collector, type Deferred, type Signal, type TestContext, type TestSuiteOptions, type WaitForOptions, createCollector, createDeferred, createSignal, delay, syncReplica, testSuite, uniqueId, waitFor };
|
|
213
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/test-suite.ts","../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;;;AAMA;AAciB,UAdA,gBAAA,CAcW;EAAA;EAAA,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