@adaptivestone/framework 5.3.0 → 5.3.1
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 +8 -0
- package/dist/modules/BaseModel.d.ts +18 -2
- package/dist/modules/BaseModel.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@ 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.1] - Unreleased
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- **Single-nested subdocuments dropped `TsTypeOverride` on the raw surface entirely.** A field marked `TsTypeOverride<…>` inside a subdocument declared in the `{ type: { … } }` form kept its plain inferred type on raw, lean and create surfaces — `lean.description.short` was `string` rather than the overridden locale map. `ApplyTsOverrides` recursed into the wrapper object, whose own keys are `type`/`_id`, so every inner key failed the `K extends keyof Schema` alignment and fell through unchanged. It now unwraps the single-nested definition before recursing. Plain nested paths (`organizer: { name: … }`, no `type` wrapper) were never affected, which is why this went unnoticed; `HasTsOverride` needed no change, as it walks every key blindly and already saw markers through the wrapper. Independent of `_id: false` — it affected every single-nested subdocument.
|
|
12
|
+
|
|
13
|
+
- **`_id: false` single-nested subdocuments exposed the RAW type override on their hydrated surface.** A field marked `TsTypeOverride<TRaw, THydrated>` inside a single-nested subdocument declared with `_id: false` resolved to `TRaw` on a hydrated document instead of `THydrated` — e.g. `doc.description.short` typed as the stored locale map rather than `string | LocaleMap`, forcing a cast at every read. `CorrectHydratedSubdocumentElement` re-derives the subdocument type from the schema and called `MaybeApplyOverrides` without a surface argument, which defaults to `'raw'`; it now passes `'hydrated'` explicitly, like the two top-level builders already did. Top-level fields were never affected, and the path only runs for `_id: false` schemas, so nothing else changes. Pinned by a new case in the `tsTypeOverride` tsc-gate fixture.
|
|
14
|
+
|
|
7
15
|
## [5.3.0] - 2026-08-08
|
|
8
16
|
|
|
9
17
|
### Added
|
|
@@ -88,8 +88,24 @@ type IsLeafFieldDef<S> = S extends Schema ? true : S extends abstract new (...ar
|
|
|
88
88
|
* would match on every field).
|
|
89
89
|
*/
|
|
90
90
|
export type ApplyTsOverrides<Doc, Schema, Surface extends TsOverrideSurface = 'raw'> = {
|
|
91
|
-
[K in keyof Doc]: K extends keyof Schema ? '__tsType' extends keyof Schema[K] ? TsOverrideFor<Schema[K], Surface> : NonNullable<Schema[K]> extends readonly (infer E)[] ? NonNullable<Doc[K]> extends mongoose.Types.DocumentArray<infer R, infer H> ? IsLeafFieldDef<E> extends true ? Doc[K] : mongoose.Types.DocumentArray<ApplyTsOverrides<R, E, 'raw'>, ApplyTsOverrides<NonNullable<Doc[K]>[number], E, 'hydrated'> extends mongoose.Types.Subdocument ? ApplyTsOverrides<NonNullable<Doc[K]>[number], E, 'hydrated'> : H> | Extract<Doc[K], null | undefined> : NonNullable<Doc[K]> extends readonly (infer D)[] ? D extends object ? IsLeafFieldDef<E> extends true ? Doc[K] : ApplyTsOverrides<D, E, Surface>[] | Exclude<Doc[K], readonly unknown[]> : Doc[K] : Doc[K] : NonNullable<Schema[K]> extends object ? NonNullable<Doc[K]> extends object ? IsLeafFieldDef<NonNullable<Schema[K]>> extends true ? Doc[K] : ApplyTsOverrides<NonNullable<Doc[K]>, NonNullable<Schema[K]
|
|
91
|
+
[K in keyof Doc]: K extends keyof Schema ? '__tsType' extends keyof Schema[K] ? TsOverrideFor<Schema[K], Surface> : NonNullable<Schema[K]> extends readonly (infer E)[] ? NonNullable<Doc[K]> extends mongoose.Types.DocumentArray<infer R, infer H> ? IsLeafFieldDef<E> extends true ? Doc[K] : mongoose.Types.DocumentArray<ApplyTsOverrides<R, E, 'raw'>, ApplyTsOverrides<NonNullable<Doc[K]>[number], E, 'hydrated'> extends mongoose.Types.Subdocument ? ApplyTsOverrides<NonNullable<Doc[K]>[number], E, 'hydrated'> : H> | Extract<Doc[K], null | undefined> : NonNullable<Doc[K]> extends readonly (infer D)[] ? D extends object ? IsLeafFieldDef<E> extends true ? Doc[K] : ApplyTsOverrides<D, E, Surface>[] | Exclude<Doc[K], readonly unknown[]> : Doc[K] : Doc[K] : NonNullable<Schema[K]> extends object ? NonNullable<Doc[K]> extends object ? IsLeafFieldDef<NonNullable<Schema[K]>> extends true ? Doc[K] : ApplyTsOverrides<NonNullable<Doc[K]>, SingleNestedDefinitionOrSelf<NonNullable<Schema[K]>>, Surface> | Exclude<Doc[K], object> : Doc[K] : Doc[K] : Doc[K];
|
|
92
92
|
};
|
|
93
|
+
/**
|
|
94
|
+
* The definition to recurse into for a nested field.
|
|
95
|
+
*
|
|
96
|
+
* A single-nested subdocument is declared `{ type: { … }, _id?: false }`, so its
|
|
97
|
+
* OWN keys are `type`/`_id` — recursing into the wrapper makes every inner key
|
|
98
|
+
* fail `K extends keyof Schema` and silently drops the override (the inner field
|
|
99
|
+
* keeps its plain inferred type). Unwrap to the inner definition so the keys line
|
|
100
|
+
* up with the inferred document. A plain nested path (`organizer: { name: … }`)
|
|
101
|
+
* has no `type` wrapper and recurses as itself.
|
|
102
|
+
*
|
|
103
|
+
* `HasTsOverride` needs no equivalent: it walks every key blindly, so it already
|
|
104
|
+
* sees markers through the wrapper.
|
|
105
|
+
*/
|
|
106
|
+
type SingleNestedDefinitionOrSelf<S> = [
|
|
107
|
+
SchemaSingleNestedDefinition<S>
|
|
108
|
+
] extends [never] ? S : SchemaSingleNestedDefinition<S>;
|
|
93
109
|
/**
|
|
94
110
|
* True when a schema carries at least one {@link TsTypeOverride} marker anywhere
|
|
95
111
|
* — at the top level, inside a nested object, or inside a subdocument array.
|
|
@@ -123,7 +139,7 @@ type CorrectRawSubdocumentElement<Doc, Schema> = Doc extends object ? Schema ext
|
|
|
123
139
|
type CorrectRawSubdocumentIds<Doc, Schema> = {
|
|
124
140
|
[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 ? CorrectRawSubdocumentElement<NonNullable<Doc[K]>, SchemaSingleNestedDefinition<Schema[K]>> | Exclude<Doc[K], object> : Doc[K] : NonNullable<Doc[K]> extends readonly (infer D)[] ? CorrectRawSubdocumentElement<D, SchemaArrayElement<Schema[K]>>[] | Exclude<Doc[K], readonly unknown[]> : Doc[K] : Doc[K] : Doc[K];
|
|
125
141
|
};
|
|
126
|
-
type CorrectHydratedSubdocumentElement<Raw, Schema> = CorrectRawSubdocumentElement<Raw, Schema> extends infer CorrectedRaw ? CorrectHydratedSubdocumentIds<MaybeApplyOverrides<InferHydratedDocType<MutableSchemaForInference<Schema>>, Schema>, Schema> extends infer Fields ? Schema extends {
|
|
142
|
+
type CorrectHydratedSubdocumentElement<Raw, Schema> = CorrectRawSubdocumentElement<Raw, Schema> extends infer CorrectedRaw ? CorrectHydratedSubdocumentIds<MaybeApplyOverrides<InferHydratedDocType<MutableSchemaForInference<Schema>>, Schema, 'hydrated'>, Schema> extends infer Fields ? Schema extends {
|
|
127
143
|
readonly _id: false;
|
|
128
144
|
} ? mongoose.Types.Subdocument<never, unknown, CorrectedRaw> & Omit<Fields, '_id'> : mongoose.Types.Subdocument<ExtractProperty<Fields, '_id', mongoose.Types.ObjectId>, unknown, CorrectedRaw> & Fields : never : never;
|
|
129
145
|
/**
|
|
@@ -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,UAA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