@adaptivestone/framework 5.0.0-rc.6 → 5.0.0-rc.7

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.
@@ -269,11 +269,33 @@ declare class User extends BaseModel {
269
269
  */
270
270
  readonly getPublic: (this: UserPublicDoc) => {
271
271
  avatar: string | null | undefined;
272
- name: {
272
+ name: import("../modules/BaseModel.ts").ApplyTsOverrides<{
273
273
  first?: string | null | undefined;
274
274
  last?: string | null | undefined;
275
275
  nick?: string | null | undefined;
276
- } | null | undefined;
276
+ }, {
277
+ readonly first: {
278
+ readonly type: StringConstructor;
279
+ readonly maxlength: 255;
280
+ };
281
+ readonly last: {
282
+ readonly type: StringConstructor;
283
+ readonly maxlength: 255;
284
+ };
285
+ readonly nick: {
286
+ readonly minlength: 3;
287
+ readonly maxlength: 255;
288
+ readonly type: StringConstructor;
289
+ readonly index: {
290
+ readonly unique: true;
291
+ readonly partialFilterExpression: {
292
+ readonly 'name.nick': {
293
+ readonly $type: "string";
294
+ };
295
+ };
296
+ };
297
+ };
298
+ }> | null | undefined;
277
299
  email: string | null | undefined;
278
300
  id: string;
279
301
  isVerified: boolean;
@@ -15,8 +15,42 @@ export type WithTimestamps<TOptions> = TOptions extends {
15
15
  export type ExtractProperty<T, K extends PropertyKey, Default = object> = T extends {
16
16
  [P in K]: infer R;
17
17
  } ? R : Default;
18
- export type GetModelSchemaTypeFromClass<T extends typeof BaseModel> = Schema<InferRawDocType<ExtractProperty<T, 'modelSchema'> & WithTimestamps<Merge<typeof defaultOptions, ExtractProperty<T, 'schemaOptions'>>>>, // TRawDocType
19
- Model<InferRawDocType<ExtractProperty<T, 'modelSchema'> & WithTimestamps<Merge<typeof defaultOptions, ExtractProperty<T, 'schemaOptions'>>>>, object, // TQueryHelpers
18
+ /**
19
+ * Phantom per-field type override. Intersect a schema field with this to type
20
+ * that field as `T` instead of the type Mongoose infers from `type:` — for
21
+ * fields a plugin reshapes at runtime (`mongoose-intl`, encrypted fields,
22
+ * custom getters), so the static type matches what's actually stored. `__tsType`
23
+ * is never set at runtime; only the compile-time type changes. Opt-in and a
24
+ * strict no-op for any field that doesn't carry the marker.
25
+ *
26
+ * @example
27
+ * // app-side, ideally behind a small factory:
28
+ * title: { type: String, intl: true } as { type: StringConstructor; intl: true } &
29
+ * TsTypeOverride<IntlSubDocValue<string>>;
30
+ */
31
+ export interface TsTypeOverride<T> {
32
+ readonly __tsType?: T;
33
+ }
34
+ /**
35
+ * Walk an inferred raw-doc type alongside its schema and replace each field
36
+ * marked with {@link TsTypeOverride} by the declared override type. Recurses
37
+ * into nested objects and subdocument arrays (a reshaped field can appear at any
38
+ * depth); leaves everything else — including arrays of primitives — untouched.
39
+ * A schema with no markers maps to a structurally identical type, so existing
40
+ * models are unaffected. The marker is detected by the *presence* of the
41
+ * `__tsType` key (not by `extends TsTypeOverride`, which an optional property
42
+ * would match on every field).
43
+ */
44
+ export type ApplyTsOverrides<Doc, Schema> = {
45
+ [K in keyof Doc]: K extends keyof Schema ? '__tsType' extends keyof Schema[K] ? Schema[K] extends TsTypeOverride<infer U> ? U : Doc[K] : NonNullable<Schema[K]> extends readonly (infer E)[] ? NonNullable<Doc[K]> extends readonly (infer D)[] ? D extends object ? ApplyTsOverrides<D, E>[] | Exclude<Doc[K], readonly unknown[]> : Doc[K] : Doc[K] : NonNullable<Schema[K]> extends object ? NonNullable<Doc[K]> extends object ? ApplyTsOverrides<NonNullable<Doc[K]>, NonNullable<Schema[K]>> | Exclude<Doc[K], object> : Doc[K] : Doc[K] : Doc[K];
46
+ };
47
+ /** The raw doc type Mongoose infers from a class's `modelSchema` + timestamps. */
48
+ type InferredRawDoc<T extends typeof BaseModel> = InferRawDocType<ExtractProperty<T, 'modelSchema'> & WithTimestamps<Merge<typeof defaultOptions, ExtractProperty<T, 'schemaOptions'>>>>;
49
+ /** {@link InferredRawDoc} with any per-field `__tsType` overrides applied
50
+ * (identical to it when the schema carries no markers). */
51
+ type OverriddenRawDoc<T extends typeof BaseModel> = ApplyTsOverrides<InferredRawDoc<T>, ExtractProperty<T, 'modelSchema'>>;
52
+ export type GetModelSchemaTypeFromClass<T extends typeof BaseModel> = Schema<OverriddenRawDoc<T>, // TRawDocType
53
+ Model<OverriddenRawDoc<T>, object, // TQueryHelpers
20
54
  ExtractProperty<T, 'modelInstanceMethods'>, // TInstanceMethods
21
55
  ExtractProperty<T, 'modelVirtuals'>>, // TModelType
22
56
  ExtractProperty<T, 'modelInstanceMethods'>, // TInstanceMethods
@@ -29,18 +63,18 @@ export type VirtualType<T> = {
29
63
  get: () => infer R;
30
64
  } ? R : never;
31
65
  };
32
- export type GetModelTypeFromClass<T extends typeof BaseModel> = Model<InferRawDocType<ExtractProperty<T, 'modelSchema'> & WithTimestamps<Merge<typeof defaultOptions, ExtractProperty<T, 'schemaOptions'>>>>, // TRawDocType
66
+ export type GetModelTypeFromClass<T extends typeof BaseModel> = Model<OverriddenRawDoc<T>, // TRawDocType
33
67
  object, // TQueryHelpers
34
68
  ExtractProperty<T, 'modelInstanceMethods'>, // TInstanceMethods
35
69
  ExtractProperty<T, 'modelVirtuals'>, // TVirtuals
36
- HydratedDocument<InferRawDocType<ExtractProperty<T, 'modelSchema'> & WithTimestamps<Merge<typeof defaultOptions, ExtractProperty<T, 'schemaOptions'>>>>, //TRawDocType
37
- //TRawDocType
70
+ HydratedDocument<OverriddenRawDoc<T>, // TRawDocType
71
+ // TRawDocType
38
72
  VirtualType<ExtractProperty<T, 'modelVirtuals'>> & ExtractProperty<T, 'modelInstanceMethods'> & {
39
73
  id: string;
40
74
  }, // TVirtuals & TInstanceMethods
41
75
  object, // TQueryHelpers
42
76
  ExtractProperty<T, 'modelVirtuals'>>, GetModelSchemaTypeFromClass<T>> & ExtractProperty<T, 'modelStatics'>;
43
- export type GetModelTypeLiteFromSchema<T extends typeof BaseModel.modelSchema, TOptions = object> = Model<InferRawDocType<T & WithTimestamps<Merge<typeof defaultOptions, TOptions>>>>;
77
+ export type GetModelTypeLiteFromSchema<T extends typeof BaseModel.modelSchema, TOptions = object> = Model<ApplyTsOverrides<InferRawDocType<T & WithTimestamps<Merge<typeof defaultOptions, TOptions>>>, T>>;
44
78
  export declare const defaultOptions: {
45
79
  readonly timestamps: true;
46
80
  readonly minimize: false;
@@ -55,3 +89,4 @@ export declare class BaseModel {
55
89
  static initHooks(_schema: Schema): void;
56
90
  static initialize<T extends typeof BaseModel>(this: T): GetModelTypeFromClass<T>;
57
91
  }
92
+ export {};
@@ -1 +1 @@
1
- {"version":3,"file":"BaseModel.js","sourceRoot":"","sources":["../../src/modules/BaseModel.ts"],"names":[],"mappings":"AAOA,OAAO,QAAQ,EAAE,EAAc,MAAM,UAAU,CAAC;AAgFhD,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,CA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IAAI,EACT,MAAM,CACqB,CAAC;QAE9B,OAAO,aAAa,CAAC;IACvB,CAAC;CACF"}
@@ -9,7 +9,7 @@ export declare const setDefaultUser: (userToSet: InstanceType<GetModelTypeFromCl
9
9
  export declare const setDefaultAuthToken: (tokenToSet: string) => void;
10
10
  export declare const getTestServerURL: (urlPart?: string) => string;
11
11
  export declare const createDefaultTestUser: () => Promise<false | {
12
- user: import("mongoose").Document<unknown, object, {
12
+ user: import("mongoose").Document<unknown, object, import("../modules/BaseModel.ts").ApplyTsOverrides<{
13
13
  isVerified: boolean;
14
14
  locale: string;
15
15
  createdAt?: NativeDate | null | undefined;
@@ -45,7 +45,71 @@ export declare const createDefaultTestUser: () => Promise<false | {
45
45
  languages?: string[] | null | undefined;
46
46
  } & {
47
47
  _id: import("mongoose").Types.ObjectId;
48
- }, {}, import("mongoose").DefaultSchemaOptions> & Omit<{
48
+ }, {
49
+ readonly avatar: {
50
+ readonly type: StringConstructor;
51
+ readonly maxlength: 255;
52
+ };
53
+ readonly name: {
54
+ readonly first: {
55
+ readonly type: StringConstructor;
56
+ readonly maxlength: 255;
57
+ };
58
+ readonly last: {
59
+ readonly type: StringConstructor;
60
+ readonly maxlength: 255;
61
+ };
62
+ readonly nick: {
63
+ readonly minlength: 3;
64
+ readonly maxlength: 255;
65
+ readonly type: StringConstructor;
66
+ readonly index: {
67
+ readonly unique: true;
68
+ readonly partialFilterExpression: {
69
+ readonly 'name.nick': {
70
+ readonly $type: "string";
71
+ };
72
+ };
73
+ };
74
+ };
75
+ };
76
+ readonly password: StringConstructor;
77
+ readonly email: {
78
+ readonly type: StringConstructor;
79
+ readonly maxlength: 255;
80
+ readonly index: {
81
+ readonly unique: true;
82
+ readonly partialFilterExpression: {
83
+ readonly email: {
84
+ readonly $type: "string";
85
+ };
86
+ };
87
+ };
88
+ };
89
+ readonly sessionTokens: readonly [{
90
+ readonly token: StringConstructor;
91
+ readonly valid: DateConstructor;
92
+ }];
93
+ readonly verificationTokens: readonly [{
94
+ readonly until: DateConstructor;
95
+ readonly token: StringConstructor;
96
+ }];
97
+ readonly passwordRecoveryTokens: readonly [{
98
+ readonly until: DateConstructor;
99
+ readonly token: StringConstructor;
100
+ }];
101
+ readonly permissions: readonly [StringConstructor];
102
+ readonly roles: readonly [StringConstructor];
103
+ readonly isVerified: {
104
+ readonly type: BooleanConstructor;
105
+ readonly default: false;
106
+ };
107
+ readonly locale: {
108
+ readonly type: StringConstructor;
109
+ readonly default: "en";
110
+ };
111
+ readonly languages: readonly [StringConstructor];
112
+ }>, {}, import("mongoose").DefaultSchemaOptions> & Omit<import("../modules/BaseModel.ts").ApplyTsOverrides<{
49
113
  isVerified: boolean;
50
114
  locale: string;
51
115
  createdAt?: NativeDate | null | undefined;
@@ -81,7 +145,71 @@ export declare const createDefaultTestUser: () => Promise<false | {
81
145
  languages?: string[] | null | undefined;
82
146
  } & {
83
147
  _id: import("mongoose").Types.ObjectId;
84
- } & Required<{
148
+ }, {
149
+ readonly avatar: {
150
+ readonly type: StringConstructor;
151
+ readonly maxlength: 255;
152
+ };
153
+ readonly name: {
154
+ readonly first: {
155
+ readonly type: StringConstructor;
156
+ readonly maxlength: 255;
157
+ };
158
+ readonly last: {
159
+ readonly type: StringConstructor;
160
+ readonly maxlength: 255;
161
+ };
162
+ readonly nick: {
163
+ readonly minlength: 3;
164
+ readonly maxlength: 255;
165
+ readonly type: StringConstructor;
166
+ readonly index: {
167
+ readonly unique: true;
168
+ readonly partialFilterExpression: {
169
+ readonly 'name.nick': {
170
+ readonly $type: "string";
171
+ };
172
+ };
173
+ };
174
+ };
175
+ };
176
+ readonly password: StringConstructor;
177
+ readonly email: {
178
+ readonly type: StringConstructor;
179
+ readonly maxlength: 255;
180
+ readonly index: {
181
+ readonly unique: true;
182
+ readonly partialFilterExpression: {
183
+ readonly email: {
184
+ readonly $type: "string";
185
+ };
186
+ };
187
+ };
188
+ };
189
+ readonly sessionTokens: readonly [{
190
+ readonly token: StringConstructor;
191
+ readonly valid: DateConstructor;
192
+ }];
193
+ readonly verificationTokens: readonly [{
194
+ readonly until: DateConstructor;
195
+ readonly token: StringConstructor;
196
+ }];
197
+ readonly passwordRecoveryTokens: readonly [{
198
+ readonly until: DateConstructor;
199
+ readonly token: StringConstructor;
200
+ }];
201
+ readonly permissions: readonly [StringConstructor];
202
+ readonly roles: readonly [StringConstructor];
203
+ readonly isVerified: {
204
+ readonly type: BooleanConstructor;
205
+ readonly default: false;
206
+ };
207
+ readonly locale: {
208
+ readonly type: StringConstructor;
209
+ readonly default: "en";
210
+ };
211
+ readonly languages: readonly [StringConstructor];
212
+ }> & Required<{
85
213
  _id: import("mongoose").Types.ObjectId;
86
214
  }> & {
87
215
  __v: number;
@@ -115,11 +243,33 @@ export declare const createDefaultTestUser: () => Promise<false | {
115
243
  }) => Promise<any>;
116
244
  readonly getPublic: (this: import("../models/User.ts").UserPublicDoc) => {
117
245
  avatar: string | null | undefined;
118
- name: {
246
+ name: import("../modules/BaseModel.ts").ApplyTsOverrides<{
119
247
  first?: string | null | undefined;
120
248
  last?: string | null | undefined;
121
249
  nick?: string | null | undefined;
122
- } | null | undefined;
250
+ }, {
251
+ readonly first: {
252
+ readonly type: StringConstructor;
253
+ readonly maxlength: 255;
254
+ };
255
+ readonly last: {
256
+ readonly type: StringConstructor;
257
+ readonly maxlength: 255;
258
+ };
259
+ readonly nick: {
260
+ readonly minlength: 3;
261
+ readonly maxlength: 255;
262
+ readonly type: StringConstructor;
263
+ readonly index: {
264
+ readonly unique: true;
265
+ readonly partialFilterExpression: {
266
+ readonly 'name.nick': {
267
+ readonly $type: "string";
268
+ };
269
+ };
270
+ };
271
+ };
272
+ }> | null | undefined;
123
273
  email: string | null | undefined;
124
274
  id: string;
125
275
  isVerified: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptivestone/framework",
3
- "version": "5.0.0-rc.6",
3
+ "version": "5.0.0-rc.7",
4
4
  "description": "Adaptive stone node js framework",
5
5
  "type": "module",
6
6
  "engines": {