@adaptivestone/framework 5.3.2 → 5.3.3
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/CHANGELOG.md +19 -0
- package/dist/models/User.d.ts +3 -4
- package/dist/modules/BaseModel.d.ts +18 -3
- package/dist/modules/BaseModel.js.map +1 -1
- package/dist/tests/setupFramework.d.ts +4 -0
- package/dist/tests/setupFramework.js +8 -1
- package/dist/tests/setupFramework.js.map +1 -1
- package/dist/tests/testHelpers.d.ts +28 -8
- package/dist/tests/testHelpers.js +27 -0
- package/dist/tests/testHelpers.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,25 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [5.3.3] - 2026-08-08
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **The shipped test bootstrap now accepts project `Server` options, so `bootHttp` runs under test.** `Server` takes exactly two things — `folders` and the `bootHttp` hook — and the test bootstrap passed only the first, hardcoding `new Server({ folders })`. Every project that wires app-wide HTTP behavior in `bootHttp` (error handlers via `registerErrorHandler`, ad-hoc routes, Express middleware) therefore ran its tests against a server that had none of it: a mapped 400 in production showed up as a 500 under test, with nothing reporting the difference. Declare them with `configureTestServer` from `tests/testHelpers.js`, at module scope in the preload that imports the setup glue:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { configureTestServer } from '@adaptivestone/framework/tests/testHelpers.js';
|
|
15
|
+
import '@adaptivestone/framework/tests/setupNodeTest.js';
|
|
16
|
+
|
|
17
|
+
configureTestServer({ bootHttp: (app) => { /* same wiring as production */ } });
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`folders` stays owned by the bootstrap (it resolves those from the `TEST_FOLDER_*` env vars). Calling it after the server has booted throws rather than silently doing nothing — a late call cannot retroactively wire the running server, and a silent skip is exactly the failure this fixes. Also closes a coverage hole: `bootHttp` shipped in 5.1 with no test exercising it end to end, for the same reason.
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- **Plain nested paths carried a phantom `_id` on hydrated documents.** Mongoose builds a subdocument, and generates an `_id` for it, only for the `{ type: { … } }` spelling; a plain nested object (`name: { first: String, last: String }`) is a path grouping that never gets an `_id` at runtime. `InferHydratedDocType` types both the same way, intersecting `{ _id: ObjectId }` onto nested paths too — so `doc.name._id` compiled for a value that is always `undefined`, and assigning the real runtime shape (`doc.name = { first: 'Ada' }`) was a type error on a property Mongoose will never persist, pushing consumers to `Omit<…, 'name'>` bridges or `unknown` casts at every nested-path call site. The framework's hydrated correction — which already strips the `_id` Mongoose adds to `_id: false` subdocuments — now also drops it from plain nested paths, at any depth, using the same no-`type`-wrapper discriminator the override pass uses. Real single-nested subdocuments keep their `_id`, and the raw/lean/create surfaces are untouched: those already matched runtime exactly. The framework's own `User.name` was affected.
|
|
25
|
+
|
|
7
26
|
## [5.3.2] - 2026-08-08
|
|
8
27
|
|
|
9
28
|
### Fixed
|
package/dist/models/User.d.ts
CHANGED
|
@@ -265,13 +265,12 @@ declare class User extends BaseModel {
|
|
|
265
265
|
*/
|
|
266
266
|
readonly getPublic: (this: UserPublicDoc) => {
|
|
267
267
|
avatar: string | null | undefined;
|
|
268
|
-
name:
|
|
268
|
+
name: Omit<{
|
|
269
|
+
_id: import("mongoose").Types.ObjectId;
|
|
269
270
|
first?: string | null | undefined;
|
|
270
271
|
last?: string | null | undefined;
|
|
271
272
|
nick?: string | null | undefined;
|
|
272
|
-
}
|
|
273
|
-
_id: import("mongoose").Types.ObjectId;
|
|
274
|
-
}) | null | undefined;
|
|
273
|
+
}, "_id"> | null | undefined;
|
|
275
274
|
email: string | null | undefined;
|
|
276
275
|
id: string;
|
|
277
276
|
isVerified: boolean;
|
|
@@ -127,6 +127,17 @@ type SchemaArrayElement<S> = NonNullable<S> extends readonly (infer E)[] ? E : N
|
|
|
127
127
|
type SchemaSingleNestedDefinition<S> = NonNullable<S> extends {
|
|
128
128
|
readonly type: infer Definition;
|
|
129
129
|
} ? Definition extends Schema ? never : Definition extends abstract new (...args: never[]) => unknown ? never : Definition extends readonly unknown[] ? never : Definition extends object ? Definition : never : never;
|
|
130
|
+
/**
|
|
131
|
+
* True for a *plain nested path* — an object of field definitions with no
|
|
132
|
+
* `type` key, e.g. `name: { first: String, last: String }`.
|
|
133
|
+
*
|
|
134
|
+
* Mongoose groups those paths under a prefix but never builds a subdocument for
|
|
135
|
+
* them, so they carry no `_id` at runtime (`doc.name._id` is `undefined`); only
|
|
136
|
+
* the `{ type: { … } }` spelling produces a real subdocument with a generated
|
|
137
|
+
* id. Anything with a `type` key, a leaf definition, or an array is therefore
|
|
138
|
+
* excluded here — same discriminator {@link SchemaSingleNestedDefinition} uses.
|
|
139
|
+
*/
|
|
140
|
+
type IsPlainNestedPath<S> = S extends object ? S extends readonly unknown[] ? false : IsLeafFieldDef<S> extends true ? false : 'type' extends keyof S ? false : true : false;
|
|
130
141
|
type HasDisabledSubdocumentId<S> = S extends {
|
|
131
142
|
readonly _id: false;
|
|
132
143
|
} ? true : S extends object ? IsLeafFieldDef<S> extends true ? false : S extends readonly (infer E)[] ? HasDisabledSubdocumentId<E> : true extends {
|
|
@@ -143,11 +154,15 @@ type CorrectHydratedSubdocumentElement<Raw, Schema> = CorrectRawSubdocumentEleme
|
|
|
143
154
|
readonly _id: false;
|
|
144
155
|
} ? mongoose.Types.Subdocument<never, unknown, CorrectedRaw> & Omit<Fields, '_id'> : mongoose.Types.Subdocument<ExtractProperty<Fields, '_id', mongoose.Types.ObjectId>, unknown, CorrectedRaw> & Fields : never : never;
|
|
145
156
|
/**
|
|
146
|
-
* Preserve Mongoose's hydrated array APIs while respecting inline `_id: false
|
|
147
|
-
*
|
|
157
|
+
* Preserve Mongoose's hydrated array APIs while respecting inline `_id: false`,
|
|
158
|
+
* and drop the `_id` Mongoose's hydrated inference adds to plain nested paths.
|
|
159
|
+
* Mongoose 9.9.1 otherwise exposes a required `_id: unknown` on `_id: false`
|
|
160
|
+
* subdocument elements, and intersects `{ _id: ObjectId }` onto every nested
|
|
161
|
+
* path — a field that never exists at runtime, and one that makes assigning the
|
|
162
|
+
* real runtime shape (`doc.name = { first: 'a' }`) a type error.
|
|
148
163
|
*/
|
|
149
164
|
type CorrectHydratedSubdocumentIds<Doc, Schema> = {
|
|
150
|
-
[K in keyof Doc]: K extends keyof Schema ? HasDisabledSubdocumentId<Schema[K]> extends true ? [SchemaArrayElement<Schema[K]>] extends [never] ? [SchemaSingleNestedDefinition<Schema[K]>] extends [never] ? Doc[K] : NonNullable<Doc[K]> extends object ? CorrectHydratedSubdocumentElement<InferRawDocType<MutableSchemaForInference<SchemaSingleNestedDefinition<Schema[K]>>>, SchemaSingleNestedDefinition<Schema[K]>> | Exclude<Doc[K], object> : Doc[K] : NonNullable<Doc[K]> extends mongoose.Types.DocumentArray<infer Raw, infer _Hydrated> ? mongoose.Types.DocumentArray<CorrectRawSubdocumentElement<Raw, SchemaArrayElement<Schema[K]>>, CorrectHydratedSubdocumentElement<Raw, SchemaArrayElement<Schema[K]>>> | Extract<Doc[K], null | undefined> : Doc[K] : Doc[K] : Doc[K];
|
|
165
|
+
[K in keyof Doc]: K extends keyof Schema ? IsPlainNestedPath<NonNullable<Schema[K]>> extends true ? NonNullable<Doc[K]> extends object ? Omit<CorrectHydratedSubdocumentIds<NonNullable<Doc[K]>, NonNullable<Schema[K]>>, '_id'> | Exclude<Doc[K], object> : Doc[K] : HasDisabledSubdocumentId<Schema[K]> extends true ? [SchemaArrayElement<Schema[K]>] extends [never] ? [SchemaSingleNestedDefinition<Schema[K]>] extends [never] ? Doc[K] : NonNullable<Doc[K]> extends object ? CorrectHydratedSubdocumentElement<InferRawDocType<MutableSchemaForInference<SchemaSingleNestedDefinition<Schema[K]>>>, SchemaSingleNestedDefinition<Schema[K]>> | Exclude<Doc[K], object> : Doc[K] : NonNullable<Doc[K]> extends mongoose.Types.DocumentArray<infer Raw, infer _Hydrated> ? mongoose.Types.DocumentArray<CorrectRawSubdocumentElement<Raw, SchemaArrayElement<Schema[K]>>, CorrectHydratedSubdocumentElement<Raw, SchemaArrayElement<Schema[K]>>> | Extract<Doc[K], null | undefined> : Doc[K] : Doc[K] : Doc[K];
|
|
151
166
|
};
|
|
152
167
|
/**
|
|
153
168
|
* Remove readonly modifiers introduced by `as const` before handing a schema
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseModel.js","sourceRoot":"","sources":["../../src/modules/BaseModel.ts"],"names":[],"mappings":"AAQA,OAAO,QAAQ,EAAE,EAAc,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"BaseModel.js","sourceRoot":"","sources":["../../src/modules/BaseModel.ts"],"names":[],"mappings":"AAQA,OAAO,QAAQ,EAAE,EAAc,MAAM,UAAU,CAAC;AA+mBhD,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAW,CAAC;AAG7E,gFAAgF;AAChF,MAAM,OAAO,SAAS;IACpB,MAAM,KAAK,WAAW;QACpB,OAAO,EAAW,CAAC;IACrB,CAAC;IAED,MAAM,KAAK,aAAa;QACtB,OAAO,EAAW,CAAC;IACrB,CAAC;IAED,MAAM,KAAK,oBAAoB;QAC7B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,KAAK,aAAa;QACtB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,KAAK,YAAY;QACrB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,OAAe;QAC9B,iBAAiB;IACnB,CAAC;IAED,wDAAwD;IACjD,MAAM,CAAC,UAAU;QACtB,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE;YACnD,GAAG,cAAc;YACjB,GAAI,IAAI,CAAC,aAA+B;YACxC,OAAO,EAAE,IAAI,CAAC,oBAAoB;YAClC,OAAO,EAAE,IAAI,CAAC,YAAY;YAC1B,QAAQ,EAAE,IAAI,CAAC,aAAa;SAC7B,CAAmC,CAAC;QAErC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAEvB,MAAM,aAAa,GAAG,QAAQ,CAAC,KAAK,CAClC,IAAI,CAAC,IAAI,EACT,MAAM,CACqB,CAAC;QAE9B,OAAO,aAAa,CAAC;IACvB,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CAAC,SAAkB;IACzD,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,IAAI,GAAG,SAA4D,CAAC;IAC1E,IAAI,OAAO,IAAI,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC;IACxC,CAAC;IAAC,MAAM,CAAC;QACP,+DAA+D;QAC/D,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
* framework `Server` against a fresh DB and tears it down.
|
|
12
12
|
* - `setTestRedisNamespace` / `clearTestRedisNamespace` — per test; isolate the
|
|
13
13
|
* cache/rate-limiter keyspace.
|
|
14
|
+
*
|
|
15
|
+
* Project `Server` options (notably the `bootHttp` hook) are declared with
|
|
16
|
+
* `configureTestServer` from `testHelpers.ts` before the server boots; this
|
|
17
|
+
* module owns only the `folders` config.
|
|
14
18
|
*/
|
|
15
19
|
import Server from '../server.ts';
|
|
16
20
|
/** Start an in-memory Mongo replica set and publish `TEST_MONGO_URI`. */
|
|
@@ -11,13 +11,17 @@
|
|
|
11
11
|
* framework `Server` against a fresh DB and tears it down.
|
|
12
12
|
* - `setTestRedisNamespace` / `clearTestRedisNamespace` — per test; isolate the
|
|
13
13
|
* cache/rate-limiter keyspace.
|
|
14
|
+
*
|
|
15
|
+
* Project `Server` options (notably the `bootHttp` hook) are declared with
|
|
16
|
+
* `configureTestServer` from `testHelpers.ts` before the server boots; this
|
|
17
|
+
* module owns only the `folders` config.
|
|
14
18
|
*/
|
|
15
19
|
import crypto from 'node:crypto';
|
|
16
20
|
import path from 'node:path';
|
|
17
21
|
import mongoose from 'mongoose'; // we do not need create indexes on tests
|
|
18
22
|
import { clearNamespace } from '../helpers/redis/clearNamespace.js';
|
|
19
23
|
import Server from '../server.js';
|
|
20
|
-
import { serverInstance, setServerInstance } from './testHelpers.js';
|
|
24
|
+
import { serverInstance, setServerInstance, takeTestServerOptions, } from './testHelpers.js';
|
|
21
25
|
mongoose.set('autoIndex', false);
|
|
22
26
|
const basePath = new URL('.', import.meta.url).pathname;
|
|
23
27
|
// ── Global Mongo lifecycle (once per test run) ──────────────────────────────
|
|
@@ -54,6 +58,9 @@ async function bootTestServer() {
|
|
|
54
58
|
process.env.LOGGER_CONSOLE_LEVEL = 'error';
|
|
55
59
|
process.env.AUTH_SALT = crypto.randomBytes(16).toString('hex');
|
|
56
60
|
const server = new Server({
|
|
61
|
+
// Project-declared options (`bootHttp`, …) so the test server wires itself
|
|
62
|
+
// the same way production does. Folders stay owned by the bootstrap.
|
|
63
|
+
...takeTestServerOptions(),
|
|
57
64
|
folders: {
|
|
58
65
|
config: process.env.TEST_FOLDER_CONFIG || path.resolve(basePath, '../config'),
|
|
59
66
|
controllers: process.env.TEST_FOLDER_CONTROLLERS ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupFramework.js","sourceRoot":"","sources":["../../src/tests/setupFramework.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"setupFramework.js","sourceRoot":"","sources":["../../src/tests/setupFramework.ts"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,CAAC;QAC7C,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,+BAA+B;IACjC,CAAC;AACH,CAAC"}
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import type UserModel from '../models/User.ts';
|
|
2
2
|
import type { GetModelTypeFromClass } from '../modules/BaseModel.ts';
|
|
3
3
|
import type Server from '../server.ts';
|
|
4
|
+
import type { ServerOptions } from '../server.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Server options a project can declare for the test server the shipped setup
|
|
7
|
+
* boots. `folders` is excluded — the bootstrap resolves those itself from the
|
|
8
|
+
* `TEST_FOLDER_*` env vars.
|
|
9
|
+
*/
|
|
10
|
+
export type TestServerOptions = Omit<ServerOptions, 'folders'>;
|
|
11
|
+
/**
|
|
12
|
+
* Declare `Server` options — notably the `bootHttp` hook — for the test server.
|
|
13
|
+
* Without this, app-wide HTTP wiring that production does in `bootHttp` is
|
|
14
|
+
* simply absent under test, so tests see the unwired behavior (a 500 where
|
|
15
|
+
* production returns the mapped status) with nothing reporting the difference.
|
|
16
|
+
*
|
|
17
|
+
* Call it at module scope in the preload that imports the framework setup glue,
|
|
18
|
+
* before any hook boots the server.
|
|
19
|
+
*/
|
|
20
|
+
export declare const configureTestServer: (options: TestServerOptions) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Read the declared options and close the window for further configuration.
|
|
23
|
+
* Called once by the test bootstrap as it constructs the `Server`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const takeTestServerOptions: () => TestServerOptions;
|
|
4
26
|
export declare let serverInstance: Server;
|
|
5
27
|
export declare let defaultUser: InstanceType<GetModelTypeFromClass<typeof UserModel>>;
|
|
6
28
|
export declare let defaultAuthToken: string;
|
|
@@ -58,13 +80,12 @@ export declare const createDefaultTestUser: () => Promise<false | {
|
|
|
58
80
|
createdAt: NativeDate;
|
|
59
81
|
updatedAt: NativeDate;
|
|
60
82
|
avatar?: string | null | undefined;
|
|
61
|
-
name?:
|
|
83
|
+
name?: Omit<{
|
|
84
|
+
_id: import("mongoose").Types.ObjectId;
|
|
62
85
|
first?: string | null | undefined;
|
|
63
86
|
last?: string | null | undefined;
|
|
64
87
|
nick?: string | null | undefined;
|
|
65
|
-
}
|
|
66
|
-
_id: import("mongoose").Types.ObjectId;
|
|
67
|
-
}) | null | undefined;
|
|
88
|
+
}, "_id"> | null | undefined;
|
|
68
89
|
password?: string | null | undefined;
|
|
69
90
|
email?: string | null | undefined;
|
|
70
91
|
sessionTokens: import("mongoose").Types.DocumentArray<{
|
|
@@ -154,13 +175,12 @@ export declare const createDefaultTestUser: () => Promise<false | {
|
|
|
154
175
|
}) => Promise<any>;
|
|
155
176
|
readonly getPublic: (this: import("../models/User.ts").UserPublicDoc) => {
|
|
156
177
|
avatar: string | null | undefined;
|
|
157
|
-
name:
|
|
178
|
+
name: Omit<{
|
|
179
|
+
_id: import("mongoose").Types.ObjectId;
|
|
158
180
|
first?: string | null | undefined;
|
|
159
181
|
last?: string | null | undefined;
|
|
160
182
|
nick?: string | null | undefined;
|
|
161
|
-
}
|
|
162
|
-
_id: import("mongoose").Types.ObjectId;
|
|
163
|
-
}) | null | undefined;
|
|
183
|
+
}, "_id"> | null | undefined;
|
|
164
184
|
email: string | null | undefined;
|
|
165
185
|
id: string;
|
|
166
186
|
isVerified: boolean;
|
|
@@ -1,4 +1,31 @@
|
|
|
1
1
|
import { appInstance } from '../helpers/appInstance.js';
|
|
2
|
+
let testServerOptions = {};
|
|
3
|
+
let areTestServerOptionsApplied = false;
|
|
4
|
+
/**
|
|
5
|
+
* Declare `Server` options — notably the `bootHttp` hook — for the test server.
|
|
6
|
+
* Without this, app-wide HTTP wiring that production does in `bootHttp` is
|
|
7
|
+
* simply absent under test, so tests see the unwired behavior (a 500 where
|
|
8
|
+
* production returns the mapped status) with nothing reporting the difference.
|
|
9
|
+
*
|
|
10
|
+
* Call it at module scope in the preload that imports the framework setup glue,
|
|
11
|
+
* before any hook boots the server.
|
|
12
|
+
*/
|
|
13
|
+
export const configureTestServer = (options) => {
|
|
14
|
+
if (areTestServerOptionsApplied) {
|
|
15
|
+
throw new Error('configureTestServer() must be called before the test server boots. ' +
|
|
16
|
+
'Call it at module scope in your test preload (the module that imports ' +
|
|
17
|
+
'@adaptivestone/framework/tests/setupNodeTest.js), not from a test hook.');
|
|
18
|
+
}
|
|
19
|
+
testServerOptions = { ...testServerOptions, ...options };
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Read the declared options and close the window for further configuration.
|
|
23
|
+
* Called once by the test bootstrap as it constructs the `Server`.
|
|
24
|
+
*/
|
|
25
|
+
export const takeTestServerOptions = () => {
|
|
26
|
+
areTestServerOptionsApplied = true;
|
|
27
|
+
return testServerOptions;
|
|
28
|
+
};
|
|
2
29
|
export let serverInstance;
|
|
3
30
|
export let defaultUser;
|
|
4
31
|
export let defaultAuthToken;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testHelpers.js","sourceRoot":"","sources":["../../src/tests/testHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"testHelpers.js","sourceRoot":"","sources":["../../src/tests/testHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAcxD,IAAI,iBAAiB,GAAsB,EAAE,CAAC;AAC9C,IAAI,2BAA2B,GAAG,KAAK,CAAC;AAExC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAA0B,EAAE,EAAE;IAChE,IAAI,2BAA2B,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,qEAAqE;YACnE,wEAAwE;YACxE,yEAAyE,CAC5E,CAAC;IACJ,CAAC;IACD,iBAAiB,GAAG,EAAE,GAAG,iBAAiB,EAAE,GAAG,OAAO,EAAE,CAAC;AAC3D,CAAC,CAAC;AAEF;;;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