@prisma-next/mongo-contract 0.8.0 → 0.9.0-dev.2

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/dist/index.d.mts CHANGED
@@ -1,18 +1,269 @@
1
- import { Contract, ContractField, ContractModel, ContractValueObject, StorageBase } from "@prisma-next/contract/types";
1
+ import * as _$arktype from "arktype";
2
+ import { IRNodeBase, Namespace, Storage } from "@prisma-next/framework-components/ir";
3
+ import * as _$arktype_internal_variants_object_ts0 from "arktype/internal/variants/object.ts";
4
+ import { Contract, ContractField, ContractModel, ContractValueObject, StorageBase, StorageHashBase } from "@prisma-next/contract/types";
2
5
 
3
- //#region src/contract-types.d.ts
4
- type MongoIndexFieldValue = 1 | -1 | 'text' | '2dsphere' | '2d' | 'hashed';
5
- type MongoIndexFields = Record<string, MongoIndexFieldValue>;
6
- type MongoJsonPrimitive = string | number | boolean | null;
7
- type MongoJsonValue = MongoJsonPrimitive | readonly MongoJsonValue[] | MongoJsonObject;
8
- type MongoJsonObject = {
9
- readonly [key: string]: MongoJsonValue;
10
- };
6
+ //#region src/contract-schema.d.ts
7
+ declare const MongoContractSchema: _$arktype_internal_variants_object_ts0.ObjectType<{
8
+ targetFamily: "mongo";
9
+ roots: Record<string, string>;
10
+ storage: {
11
+ collections: {
12
+ [x: string]: {
13
+ kind?: "mongo-collection";
14
+ indexes?: {
15
+ keys: {
16
+ field: string;
17
+ direction: 1 | -1 | "text" | "2d" | "2dsphere" | "hashed";
18
+ }[];
19
+ kind?: "mongo-index";
20
+ unique?: boolean;
21
+ sparse?: boolean;
22
+ expireAfterSeconds?: number;
23
+ partialFilterExpression?: Record<string, unknown>;
24
+ wildcardProjection?: Record<string, 0 | 1>;
25
+ collation?: Record<string, unknown>;
26
+ weights?: Record<string, number>;
27
+ default_language?: string;
28
+ language_override?: string;
29
+ }[];
30
+ validator?: {
31
+ jsonSchema: Record<string, unknown>;
32
+ validationLevel: "strict" | "moderate";
33
+ validationAction: "error" | "warn";
34
+ kind?: "mongo-validator";
35
+ };
36
+ options?: {
37
+ kind?: "mongo-collection-options";
38
+ capped?: {
39
+ size: number;
40
+ max?: number;
41
+ };
42
+ storageEngine?: {
43
+ [x: string]: unknown;
44
+ };
45
+ indexOptionDefaults?: {
46
+ kind?: "mongo-index-option-defaults";
47
+ storageEngine?: {
48
+ [x: string]: unknown;
49
+ };
50
+ };
51
+ timeseries?: {
52
+ timeField: string;
53
+ kind?: "mongo-time-series-collection-options";
54
+ metaField?: string;
55
+ granularity?: "seconds" | "minutes" | "hours";
56
+ bucketMaxSpanSeconds?: number;
57
+ bucketRoundingSeconds?: number;
58
+ };
59
+ collation?: Record<string, unknown>;
60
+ expireAfterSeconds?: number;
61
+ changeStreamPreAndPostImages?: {
62
+ enabled: boolean;
63
+ kind?: "mongo-change-stream-pre-and-post-images-options";
64
+ };
65
+ clusteredIndex?: {
66
+ name?: string;
67
+ };
68
+ };
69
+ };
70
+ };
71
+ storageHash?: string;
72
+ };
73
+ models: {
74
+ [x: string]: {
75
+ fields: {
76
+ [x: string]: (In: {
77
+ type: {
78
+ kind: "scalar";
79
+ codecId: string;
80
+ typeParams?: Record<string, unknown>;
81
+ } | {
82
+ kind: "valueObject";
83
+ name: string;
84
+ } | {
85
+ kind: "union";
86
+ members: ({
87
+ kind: "scalar";
88
+ codecId: string;
89
+ typeParams?: Record<string, unknown>;
90
+ } | {
91
+ kind: "valueObject";
92
+ name: string;
93
+ })[];
94
+ };
95
+ nullable?: boolean;
96
+ many?: boolean;
97
+ dict?: boolean;
98
+ }) => _$arktype.Out<{
99
+ nullable: boolean;
100
+ type: {
101
+ kind: "scalar";
102
+ codecId: string;
103
+ typeParams?: Record<string, unknown>;
104
+ } | {
105
+ kind: "valueObject";
106
+ name: string;
107
+ } | {
108
+ kind: "union";
109
+ members: ({
110
+ kind: "scalar";
111
+ codecId: string;
112
+ typeParams?: Record<string, unknown>;
113
+ } | {
114
+ kind: "valueObject";
115
+ name: string;
116
+ })[];
117
+ };
118
+ many?: boolean;
119
+ dict?: boolean;
120
+ }>;
121
+ };
122
+ storage: {
123
+ collection?: string;
124
+ relations?: {
125
+ [x: string]: {
126
+ field: string;
127
+ };
128
+ };
129
+ };
130
+ relations?: {
131
+ [x: string]: {
132
+ to: string;
133
+ cardinality: "1:1" | "1:N" | "N:1";
134
+ on?: {
135
+ localFields: string[];
136
+ targetFields: string[];
137
+ };
138
+ };
139
+ };
140
+ discriminator?: {
141
+ field: string;
142
+ };
143
+ variants?: {
144
+ [x: string]: {
145
+ value: string;
146
+ };
147
+ };
148
+ base?: string;
149
+ owner?: string;
150
+ };
151
+ };
152
+ schemaVersion?: string;
153
+ target?: string;
154
+ storageHash?: string;
155
+ profileHash?: string;
156
+ capabilities?: Record<string, unknown>;
157
+ extensionPacks?: Record<string, unknown>;
158
+ meta?: Record<string, unknown>;
159
+ sources?: Record<string, unknown>;
160
+ _generated?: Record<string, unknown>;
161
+ valueObjects?: {
162
+ [x: string]: {
163
+ fields: {
164
+ [x: string]: (In: {
165
+ type: {
166
+ kind: "scalar";
167
+ codecId: string;
168
+ typeParams?: Record<string, unknown>;
169
+ } | {
170
+ kind: "valueObject";
171
+ name: string;
172
+ } | {
173
+ kind: "union";
174
+ members: ({
175
+ kind: "scalar";
176
+ codecId: string;
177
+ typeParams?: Record<string, unknown>;
178
+ } | {
179
+ kind: "valueObject";
180
+ name: string;
181
+ })[];
182
+ };
183
+ nullable?: boolean;
184
+ many?: boolean;
185
+ dict?: boolean;
186
+ }) => _$arktype.Out<{
187
+ nullable: boolean;
188
+ type: {
189
+ kind: "scalar";
190
+ codecId: string;
191
+ typeParams?: Record<string, unknown>;
192
+ } | {
193
+ kind: "valueObject";
194
+ name: string;
195
+ } | {
196
+ kind: "union";
197
+ members: ({
198
+ kind: "scalar";
199
+ codecId: string;
200
+ typeParams?: Record<string, unknown>;
201
+ } | {
202
+ kind: "valueObject";
203
+ name: string;
204
+ })[];
205
+ };
206
+ many?: boolean;
207
+ dict?: boolean;
208
+ }>;
209
+ };
210
+ };
211
+ };
212
+ }, {}>;
213
+ //#endregion
214
+ //#region src/ir/mongo-change-stream-pre-and-post-images-options.d.ts
215
+ interface MongoChangeStreamPreAndPostImagesOptionsInput {
216
+ readonly enabled: boolean;
217
+ }
218
+ /**
219
+ * Change-stream pre-and-post-images collection option. Lifted from a
220
+ * `type =` data shape to an AST class extending `IRNodeBase` per
221
+ * FR18. Single-field shape; the class exists for AST-pattern
222
+ * consistency (every nested data shape inside `MongoCollectionOptions`
223
+ * is an AST node so the verifier can walk uniformly).
224
+ */
225
+ declare class MongoChangeStreamPreAndPostImagesOptions extends IRNodeBase {
226
+ readonly kind: "mongo-change-stream-pre-and-post-images-options";
227
+ readonly enabled: boolean;
228
+ constructor(options: MongoChangeStreamPreAndPostImagesOptionsInput);
229
+ }
230
+ //#endregion
231
+ //#region src/ir/mongo-clustered-collection-options.d.ts
232
+ type MongoClusteredCollectionKey = Readonly<Record<string, 1>>;
233
+ interface MongoClusteredCollectionOptionsInput {
234
+ readonly name?: string;
235
+ readonly key: MongoClusteredCollectionKey;
236
+ readonly unique: boolean;
237
+ }
238
+ /**
239
+ * Clustered-collection options (the `clusteredIndex` collection-creation
240
+ * field). Lifted from a `type =` data shape to an AST class extending
241
+ * `IRNodeBase` per FR18.
242
+ *
243
+ * MongoDB requires `key` and `unique` for any clustered collection; the
244
+ * constructor enforces presence by type signature.
245
+ */
246
+ declare class MongoClusteredCollectionOptions extends IRNodeBase {
247
+ readonly kind: "mongo-clustered-collection-options";
248
+ readonly name?: string;
249
+ readonly key: MongoClusteredCollectionKey;
250
+ readonly unique: boolean;
251
+ constructor(options: MongoClusteredCollectionOptionsInput);
252
+ }
253
+ //#endregion
254
+ //#region src/ir/mongo-collation-options.d.ts
11
255
  type MongoCollationCaseFirst = 'off' | 'upper' | 'lower';
12
256
  type MongoCollationStrength = 1 | 2 | 3 | 4 | 5;
13
257
  type MongoCollationAlternate = 'non-ignorable' | 'shifted';
14
258
  type MongoCollationMaxVariable = 'punct' | 'space';
15
- type MongoCollationOptions = {
259
+ /**
260
+ * Authoring / hydration input shape for {@link MongoCollationOptions}. Carries
261
+ * the canonical data without the IR-class `kind` discriminator; the class
262
+ * fabricates `kind` so the authoring DSL and the SPI hydration walker can
263
+ * pass plain data literals through the constructor without forcing every
264
+ * call site to spell out `kind: 'mongo-collation-options'`.
265
+ */
266
+ interface MongoCollationOptionsInput {
16
267
  readonly locale: string;
17
268
  readonly caseLevel?: boolean;
18
269
  readonly caseFirst?: MongoCollationCaseFirst;
@@ -22,69 +273,209 @@ type MongoCollationOptions = {
22
273
  readonly maxVariable?: MongoCollationMaxVariable;
23
274
  readonly backwards?: boolean;
24
275
  readonly normalization?: boolean;
25
- };
26
- type MongoWildcardProjection = Readonly<Record<string, 0 | 1>>;
27
- type MongoIndexOptions = {
28
- readonly unique?: boolean;
29
- readonly name?: string;
30
- readonly partialFilterExpression?: MongoJsonObject;
31
- readonly sparse?: boolean;
32
- readonly expireAfterSeconds?: number;
33
- readonly weights?: Readonly<Record<string, number>>;
34
- readonly default_language?: string;
35
- readonly language_override?: string;
36
- readonly textIndexVersion?: number;
37
- readonly '2dsphereIndexVersion'?: number;
38
- readonly bits?: number;
39
- readonly min?: number;
40
- readonly max?: number;
41
- readonly bucketSize?: number;
42
- readonly hidden?: boolean;
43
- readonly collation?: MongoCollationOptions;
44
- readonly wildcardProjection?: MongoWildcardProjection;
45
- };
46
- type MongoIndex = {
47
- readonly fields: MongoIndexFields;
48
- readonly options?: MongoIndexOptions;
49
- };
50
- type MongoIndexOptionDefaults = {
276
+ }
277
+ /**
278
+ * Mongo Contract IR leaf for collection / index collation options.
279
+ *
280
+ * Lifted from a `type =` data shape to an AST class extending
281
+ * `IRNodeBase` per FR18 ("Mongo's Contract IR is fully unified under
282
+ * the AST-class pattern, layered family / target"). Single concrete class
283
+ * (no target subclass): collation options carry no target-specific
284
+ * variation at this layer — both Atlas and self-hosted Mongo consume the
285
+ * same option vocabulary.
286
+ *
287
+ * Undefined optional fields are not assigned, so `JSON.stringify` omits
288
+ * them from the canonical JSON output (matches the pre-lift data shape's
289
+ * round-trip behaviour, modulo the new `kind` discriminator).
290
+ */
291
+ declare class MongoCollationOptions extends IRNodeBase {
292
+ readonly kind: "mongo-collation-options";
293
+ readonly locale: string;
294
+ readonly caseLevel?: boolean;
295
+ readonly caseFirst?: MongoCollationCaseFirst;
296
+ readonly strength?: MongoCollationStrength;
297
+ readonly numericOrdering?: boolean;
298
+ readonly alternate?: MongoCollationAlternate;
299
+ readonly maxVariable?: MongoCollationMaxVariable;
300
+ readonly backwards?: boolean;
301
+ readonly normalization?: boolean;
302
+ constructor(options: MongoCollationOptionsInput);
303
+ }
304
+ //#endregion
305
+ //#region src/ir/mongo-index-option-defaults.d.ts
306
+ interface MongoIndexOptionDefaultsInput {
51
307
  readonly storageEngine?: MongoJsonObject;
52
- };
308
+ }
309
+ /**
310
+ * Collection-level default index options (the `indexOptionDefaults`
311
+ * collection-creation field on Mongo's `createCollection`). Lifted from
312
+ * a `type =` data shape to an AST class extending `IRNodeBase` per
313
+ * FR18 (Mongo Contract IR fully unified under the AST-class pattern).
314
+ *
315
+ * Carries `storageEngine` only — the underlying MongoDB option set is
316
+ * intentionally narrow at this layer; per-engine richer option vocabularies
317
+ * are out of scope for this project.
318
+ */
319
+ declare class MongoIndexOptionDefaults extends IRNodeBase {
320
+ readonly kind: "mongo-index-option-defaults";
321
+ readonly storageEngine?: MongoJsonObject;
322
+ constructor(options?: MongoIndexOptionDefaultsInput);
323
+ }
324
+ //#endregion
325
+ //#region src/ir/mongo-time-series-collection-options.d.ts
53
326
  type MongoTimeSeriesGranularity = 'seconds' | 'minutes' | 'hours';
54
- type MongoTimeSeriesCollectionOptions = {
327
+ interface MongoTimeSeriesCollectionOptionsInput {
55
328
  readonly timeField: string;
56
329
  readonly metaField?: string;
57
330
  readonly granularity?: MongoTimeSeriesGranularity;
58
331
  readonly bucketMaxSpanSeconds?: number;
59
332
  readonly bucketRoundingSeconds?: number;
60
- };
61
- type MongoClusteredCollectionKey = Readonly<Record<string, 1>>;
62
- type MongoClusteredCollectionOptions = {
333
+ }
334
+ /**
335
+ * Time-series collection options. Lifted from a `type =` data shape to
336
+ * an AST class extending `IRNodeBase` per FR18.
337
+ *
338
+ * MongoDB requires `timeField` for any time-series collection; the
339
+ * constructor enforces presence by type signature (`timeField: string`
340
+ * is required on the input).
341
+ */
342
+ declare class MongoTimeSeriesCollectionOptions extends IRNodeBase {
343
+ readonly kind: "mongo-time-series-collection-options";
344
+ readonly timeField: string;
345
+ readonly metaField?: string;
346
+ readonly granularity?: MongoTimeSeriesGranularity;
347
+ readonly bucketMaxSpanSeconds?: number;
348
+ readonly bucketRoundingSeconds?: number;
349
+ constructor(options: MongoTimeSeriesCollectionOptionsInput);
350
+ }
351
+ //#endregion
352
+ //#region src/ir/mongo-collection-options.d.ts
353
+ /**
354
+ * Storage-shape sub-shape: only `name` is persisted on the storage
355
+ * `clusteredIndex` field. The richer authoring vocabulary
356
+ * (`MongoClusteredCollectionOptions.key`, `…unique`) is intentionally
357
+ * not round-tripped through the on-disk JSON envelope — those fields
358
+ * are application-side configuration that informs collection creation
359
+ * but does not survive into the persisted collection options.
360
+ */
361
+ interface MongoStorageClusteredIndexShape {
63
362
  readonly name?: string;
64
- readonly key: MongoClusteredCollectionKey;
65
- readonly unique: boolean;
66
- };
67
- type MongoChangeStreamPreAndPostImagesOptions = {
68
- readonly enabled: boolean;
69
- };
70
- type MongoCollectionOptions = {
363
+ }
364
+ /**
365
+ * Storage-shape sub-shape: `capped` collections persist `size` (required)
366
+ * and optionally `max` document count. The authoring DSL surface uses a
367
+ * flat `capped: boolean` + separate `size` / `max` fields; builders
368
+ * translate that authoring vocabulary into this nested storage form
369
+ * before constructing {@link MongoCollectionOptions}.
370
+ */
371
+ interface MongoStorageCappedShape {
372
+ readonly size: number;
373
+ readonly max?: number;
374
+ }
375
+ /**
376
+ * Hydration / construction input shape for {@link MongoCollectionOptions}.
377
+ * Mirrors the on-disk storage JSON envelope exactly (nested `capped`,
378
+ * `clusteredIndex`, …) so the family-base serializer's hydration walker
379
+ * can hand an arktype-validated object literal straight to `new`.
380
+ * Nested IR-class fields may be supplied as either plain data literals
381
+ * (typical for JSON-derived input) or already-constructed class
382
+ * instances (typical when re-wrapping during a partial walk).
383
+ */
384
+ interface MongoCollectionOptionsInput {
385
+ readonly capped?: MongoStorageCappedShape;
386
+ readonly storageEngine?: MongoJsonObject;
387
+ readonly indexOptionDefaults?: MongoIndexOptionDefaults | MongoIndexOptionDefaultsInput;
388
+ readonly collation?: MongoCollationOptions | MongoCollationOptionsInput;
389
+ readonly timeseries?: MongoTimeSeriesCollectionOptions | MongoTimeSeriesCollectionOptionsInput;
390
+ readonly clusteredIndex?: MongoStorageClusteredIndexShape;
391
+ readonly expireAfterSeconds?: number;
392
+ readonly changeStreamPreAndPostImages?: MongoChangeStreamPreAndPostImagesOptions | MongoChangeStreamPreAndPostImagesOptionsInput;
393
+ }
394
+ /**
395
+ * Authoring-side flat vocabulary accepted by the contract-ts builder
396
+ * DSL (e.g. `capped: boolean` + separate `size` / `max` scalars). The
397
+ * builder translates this surface into a {@link MongoCollectionOptionsInput}
398
+ * before constructing {@link MongoCollectionOptions}. Kept as a
399
+ * standalone type so authoring DSL ergonomics do not leak into the
400
+ * storage IR construction contract.
401
+ */
402
+ interface MongoCollectionOptionsAuthoringInput {
71
403
  readonly capped?: boolean;
72
404
  readonly size?: number;
73
405
  readonly max?: number;
74
406
  readonly storageEngine?: MongoJsonObject;
407
+ readonly indexOptionDefaults?: MongoIndexOptionDefaults | MongoIndexOptionDefaultsInput;
408
+ readonly collation?: MongoCollationOptions | MongoCollationOptionsInput;
409
+ readonly timeseries?: MongoTimeSeriesCollectionOptions | MongoTimeSeriesCollectionOptionsInput;
410
+ readonly clusteredIndex?: MongoClusteredCollectionOptions | MongoClusteredCollectionOptionsInput;
411
+ readonly expireAfterSeconds?: number;
412
+ readonly changeStreamPreAndPostImages?: MongoChangeStreamPreAndPostImagesOptions | MongoChangeStreamPreAndPostImagesOptionsInput;
413
+ }
414
+ /**
415
+ * Mongo Contract IR node for collection-level creation options (the
416
+ * second argument to `db.createCollection(name, options)`). Lifted from
417
+ * the pre-M2R2 `MongoStorageCollectionOptions` storage interface to a
418
+ * class extending `IRNodeBase` per FR18.
419
+ *
420
+ * Single concrete family-layer class (no target subclass). The
421
+ * constructor accepts the storage JSON envelope shape ({@link
422
+ * MongoCollectionOptionsInput}) so the family-base hydration walker
423
+ * can pass arktype-validated objects directly to `new`. Authoring
424
+ * vocabulary is translated to this shape upstream in the contract-ts
425
+ * builder.
426
+ *
427
+ * Nested IR sub-shapes (collation, timeseries, …) are normalised to
428
+ * their respective IR class instances inside the constructor so
429
+ * downstream walks see a uniform AST regardless of whether the input
430
+ * was a JSON literal or an already-constructed class.
431
+ */
432
+ declare class MongoCollectionOptions extends IRNodeBase {
433
+ readonly kind: "mongo-collection-options";
434
+ readonly capped?: MongoStorageCappedShape;
435
+ readonly storageEngine?: MongoJsonObject;
75
436
  readonly indexOptionDefaults?: MongoIndexOptionDefaults;
76
437
  readonly collation?: MongoCollationOptions;
77
438
  readonly timeseries?: MongoTimeSeriesCollectionOptions;
78
- readonly clusteredIndex?: MongoClusteredCollectionOptions;
439
+ readonly clusteredIndex?: MongoStorageClusteredIndexShape;
79
440
  readonly expireAfterSeconds?: number;
80
441
  readonly changeStreamPreAndPostImages?: MongoChangeStreamPreAndPostImagesOptions;
81
- };
82
- type MongoIndexKeyDirection = 1 | -1 | 'text' | '2dsphere' | '2d' | 'hashed';
83
- interface MongoIndexKey {
84
- readonly field: string;
85
- readonly direction: MongoIndexKeyDirection;
442
+ constructor(input?: MongoCollectionOptionsInput);
443
+ }
444
+ //#endregion
445
+ //#region src/ir/mongo-index.d.ts
446
+ /**
447
+ * Hydration / construction input shape for {@link MongoIndex}. Mirrors
448
+ * the on-disk storage JSON envelope exactly so the family-base
449
+ * serializer's hydration walker can hand an arktype-validated literal
450
+ * straight to `new`.
451
+ */
452
+ interface MongoIndexInput {
453
+ readonly keys: ReadonlyArray<MongoIndexKey>;
454
+ readonly unique?: boolean;
455
+ readonly sparse?: boolean;
456
+ readonly expireAfterSeconds?: number;
457
+ readonly partialFilterExpression?: Record<string, unknown>;
458
+ readonly wildcardProjection?: Record<string, 0 | 1>;
459
+ readonly collation?: Record<string, unknown>;
460
+ readonly weights?: Record<string, number>;
461
+ readonly default_language?: string;
462
+ readonly language_override?: string;
86
463
  }
87
- interface MongoStorageIndex {
464
+ /**
465
+ * Mongo Contract IR node for a single collection index entry (one
466
+ * element of `MongoCollection.indexes`). Lifted from the
467
+ * pre-M2R2 `MongoStorageIndex` storage interface to a class extending
468
+ * `IRNodeBase` per FR18.
469
+ *
470
+ * Single concrete family-layer class (no target subclass). The spec's
471
+ * `MongoTargetIndex extends MongoIndex` pattern remains additive — a
472
+ * future Mongo target with target-specific index extensions is free to
473
+ * subclass; for the single Mongo target shipped today a concrete
474
+ * family-layer class is enough and avoids a target-import layering
475
+ * violation from the contract-ts builder.
476
+ */
477
+ declare class MongoIndex extends IRNodeBase {
478
+ readonly kind: "mongo-index";
88
479
  readonly keys: ReadonlyArray<MongoIndexKey>;
89
480
  readonly unique?: boolean;
90
481
  readonly sparse?: boolean;
@@ -95,38 +486,167 @@ interface MongoStorageIndex {
95
486
  readonly weights?: Record<string, number>;
96
487
  readonly default_language?: string;
97
488
  readonly language_override?: string;
489
+ constructor(input: MongoIndexInput);
98
490
  }
99
- interface MongoStorageValidator {
491
+ //#endregion
492
+ //#region src/ir/mongo-validator.d.ts
493
+ type MongoValidatorValidationLevel = 'strict' | 'moderate';
494
+ type MongoValidatorValidationAction = 'error' | 'warn';
495
+ interface MongoValidatorInput {
100
496
  readonly jsonSchema: Record<string, unknown>;
101
- readonly validationLevel: 'strict' | 'moderate';
102
- readonly validationAction: 'error' | 'warn';
497
+ readonly validationLevel: MongoValidatorValidationLevel;
498
+ readonly validationAction: MongoValidatorValidationAction;
103
499
  }
104
- interface MongoStorageCollectionOptions {
105
- readonly capped?: {
106
- size: number;
107
- max?: number;
108
- };
109
- readonly timeseries?: {
110
- timeField: string;
111
- metaField?: string;
112
- granularity?: 'seconds' | 'minutes' | 'hours';
113
- };
114
- readonly collation?: Record<string, unknown>;
115
- readonly changeStreamPreAndPostImages?: {
116
- enabled: boolean;
117
- };
118
- readonly clusteredIndex?: {
119
- name?: string;
120
- };
500
+ /**
501
+ * Mongo Contract IR node for collection-level document validators (the
502
+ * `validator` field on Mongo's `createCollection`). Lifted from the
503
+ * pre-M2R2 `MongoStorageValidator` storage interface to a class extending
504
+ * `IRNodeBase` per FR18.
505
+ *
506
+ * Concrete at the family layer (no target subclass). The spec's
507
+ * abstract-family + target-concrete pattern (`MongoTargetValidator
508
+ * extends MongoValidator`) becomes meaningful when a second Mongo target
509
+ * introduces target-specific validator extensions (Atlas search rules,
510
+ * DocumentDB-specific levels, …); for the single Mongo target shipped
511
+ * today, a concrete family-layer class lets the PSL JSON-Schema deriver
512
+ * and the contract-ts builder construct instances directly without a
513
+ * target-import layering violation. Target subclassing remains additive
514
+ * — a future `MongoTargetValidator extends MongoValidator` is an
515
+ * additive change, not a breaking one.
516
+ */
517
+ declare class MongoValidator extends IRNodeBase {
518
+ readonly kind: "mongo-validator";
519
+ readonly jsonSchema: Record<string, unknown>;
520
+ readonly validationLevel: MongoValidatorValidationLevel;
521
+ readonly validationAction: MongoValidatorValidationAction;
522
+ constructor(input: MongoValidatorInput);
523
+ }
524
+ //#endregion
525
+ //#region src/ir/mongo-collection.d.ts
526
+ /**
527
+ * Hydration / construction input shape for {@link MongoCollection}.
528
+ * Mirrors the on-disk storage JSON envelope exactly (the value held at
529
+ * `contract.storage.collections[<name>]`) so the family-base
530
+ * serializer's hydration walker can hand an arktype-validated literal
531
+ * straight to `new`. Nested IR-class fields may be supplied as either
532
+ * plain data literals (typical for JSON-derived input) or
533
+ * already-constructed class instances.
534
+ */
535
+ interface MongoCollectionInput {
536
+ readonly indexes?: ReadonlyArray<MongoIndex | MongoIndexInput>;
537
+ readonly validator?: MongoValidator | MongoValidatorInput;
538
+ readonly options?: MongoCollectionOptions | MongoCollectionOptionsInput;
121
539
  }
122
- interface MongoStorageCollection {
123
- readonly indexes?: ReadonlyArray<MongoStorageIndex>;
124
- readonly validator?: MongoStorageValidator;
125
- readonly options?: MongoStorageCollectionOptions;
540
+ /**
541
+ * Mongo Contract IR node for a single collection entry in
542
+ * `contract.storage.collections`. Lifted from the pre-M2R2
543
+ * `MongoStorageCollection` storage interface to a class extending
544
+ * `IRNodeBase` per FR18.
545
+ *
546
+ * Concrete at the family layer (no target subclass). The spec's
547
+ * `MongoTargetCollection extends MongoCollection` pattern remains
548
+ * additive: a future Mongo target with target-specific extensions is
549
+ * free to subclass without breaking the family-layer construction
550
+ * sites.
551
+ *
552
+ * The unprefixed name `MongoCollection` is now the contract IR class.
553
+ * Note that `@prisma-next/mongo-orm` also exports a (different)
554
+ * `MongoCollection<TContract, ModelName>` generic for the user-facing
555
+ * ORM query builder; the two live in separate packages and are
556
+ * resolved by import path. A source file that needs both should alias
557
+ * one (e.g. `import { MongoCollection as MongoContractCollection }
558
+ * from '@prisma-next/mongo-contract'`).
559
+ */
560
+ declare class MongoCollection extends IRNodeBase {
561
+ readonly kind: "mongo-collection";
562
+ readonly indexes?: ReadonlyArray<MongoIndex>;
563
+ readonly validator?: MongoValidator;
564
+ readonly options?: MongoCollectionOptions;
565
+ constructor(input?: MongoCollectionInput);
126
566
  }
127
- type MongoStorage<THash extends string = string> = StorageBase<THash> & {
128
- readonly collections: Record<string, MongoStorageCollection>;
567
+ //#endregion
568
+ //#region src/ir/mongo-index-options.d.ts
569
+ /**
570
+ * Authoring / hydration input shape for {@link MongoIndexOptions}. Carries
571
+ * the index option vocabulary as plain data without the IR-class `kind`
572
+ * discriminator. `collation` accepts either a class instance or its own
573
+ * input shape — the constructor normalises to the class form internally.
574
+ */
575
+ interface MongoIndexOptionsInput {
576
+ readonly unique?: boolean;
577
+ readonly name?: string;
578
+ readonly partialFilterExpression?: MongoJsonObject;
579
+ readonly sparse?: boolean;
580
+ readonly expireAfterSeconds?: number;
581
+ readonly weights?: Readonly<Record<string, number>>;
582
+ readonly default_language?: string;
583
+ readonly language_override?: string;
584
+ readonly textIndexVersion?: number;
585
+ readonly '2dsphereIndexVersion'?: number;
586
+ readonly bits?: number;
587
+ readonly min?: number;
588
+ readonly max?: number;
589
+ readonly bucketSize?: number;
590
+ readonly hidden?: boolean;
591
+ readonly collation?: MongoCollationOptions | MongoCollationOptionsInput;
592
+ readonly wildcardProjection?: MongoWildcardProjection;
593
+ }
594
+ /**
595
+ * Mongo Contract IR node for the per-index option vocabulary (the second
596
+ * argument to `db.collection.createIndex(keys, options)` minus the keys
597
+ * themselves). Lifted from a `type =` data shape to an AST class
598
+ * extending `IRNodeBase` per FR18.
599
+ *
600
+ * Nested `collation` is itself an IR class (`MongoCollationOptions`); the
601
+ * constructor accepts either a class instance or a data literal and
602
+ * normalises to the class form so downstream walks see a uniform IR tree.
603
+ */
604
+ declare class MongoIndexOptions extends IRNodeBase {
605
+ readonly kind: "mongo-index-options";
606
+ readonly unique?: boolean;
607
+ readonly name?: string;
608
+ readonly partialFilterExpression?: MongoJsonObject;
609
+ readonly sparse?: boolean;
610
+ readonly expireAfterSeconds?: number;
611
+ readonly weights?: Readonly<Record<string, number>>;
612
+ readonly default_language?: string;
613
+ readonly language_override?: string;
614
+ readonly textIndexVersion?: number;
615
+ readonly '2dsphereIndexVersion'?: number;
616
+ readonly bits?: number;
617
+ readonly min?: number;
618
+ readonly max?: number;
619
+ readonly bucketSize?: number;
620
+ readonly hidden?: boolean;
621
+ readonly collation?: MongoCollationOptions;
622
+ readonly wildcardProjection?: MongoWildcardProjection;
623
+ constructor(options?: MongoIndexOptionsInput);
624
+ }
625
+ //#endregion
626
+ //#region src/contract-types.d.ts
627
+ type MongoIndexFieldValue = 1 | -1 | 'text' | '2dsphere' | '2d' | 'hashed';
628
+ type MongoIndexFields = Record<string, MongoIndexFieldValue>;
629
+ type MongoJsonPrimitive = string | number | boolean | null;
630
+ type MongoJsonValue = MongoJsonPrimitive | readonly MongoJsonValue[] | MongoJsonObject;
631
+ type MongoJsonObject = {
632
+ readonly [key: string]: MongoJsonValue;
129
633
  };
634
+ type MongoWildcardProjection = Readonly<Record<string, 0 | 1>>;
635
+ /**
636
+ * Authoring-DSL shape for a single index entry on a model — the
637
+ * `indexes` array element accepted by the contract-ts builder. The
638
+ * builder translates these (with model context) into {@link MongoIndex}
639
+ * IR-class instances on `MongoCollection.indexes`.
640
+ */
641
+ type MongoIndexAuthoringInput = {
642
+ readonly fields: MongoIndexFields;
643
+ readonly options?: MongoIndexOptionsInput;
644
+ };
645
+ type MongoIndexKeyDirection = 1 | -1 | 'text' | '2dsphere' | '2d' | 'hashed';
646
+ interface MongoIndexKey {
647
+ readonly field: string;
648
+ readonly direction: MongoIndexKeyDirection;
649
+ }
130
650
  type MongoModelStorage = {
131
651
  readonly collection?: string;
132
652
  readonly relations?: Record<string, {
@@ -134,7 +654,19 @@ type MongoModelStorage = {
134
654
  }>;
135
655
  };
136
656
  type MongoModelDefinition = ContractModel<MongoModelStorage>;
137
- type MongoContract<S extends MongoStorage = MongoStorage, M extends Record<string, MongoModelDefinition> = Record<string, MongoModelDefinition>> = Contract<S, M>;
657
+ /**
658
+ * Data-shape constraint for the Mongo family's storage block. The
659
+ * runtime in-memory representation is the concrete {@link MongoStorage}
660
+ * class from `./ir/mongo-storage`; this type is the structural superset
661
+ * used as the generic-parameter constraint so consumers can name
662
+ * `MongoContract<...>` over either the raw JSON envelope (no
663
+ * `namespaces` field) or a fully-constructed class instance (with
664
+ * `namespaces`). The class structurally satisfies this shape.
665
+ */
666
+ type MongoStorageShape<THash extends string = string> = StorageBase<THash> & {
667
+ readonly collections: Record<string, MongoCollection>;
668
+ };
669
+ type MongoContract<S extends MongoStorageShape = MongoStorageShape, M extends Record<string, MongoModelDefinition> = Record<string, MongoModelDefinition>> = Contract<S, M>;
138
670
  type MongoTypeMaps<TCodecTypes extends Record<string, {
139
671
  output: unknown;
140
672
  }> = Record<string, {
@@ -184,6 +716,46 @@ type InferModelRow<TContract extends MongoContractWithTypeMaps<MongoContract, Mo
184
716
  output: unknown;
185
717
  }> = ExtractMongoCodecTypes<TContract>, TValueObjects extends Record<string, ContractValueObject> = ExtractValueObjects<TContract>> = { -readonly [FieldName in keyof TFields]: InferFieldType<TFields[FieldName], TValueObjects, TCodecTypes> };
186
718
  //#endregion
719
+ //#region src/ir/mongo-storage.d.ts
720
+ /**
721
+ * Construction input shape for {@link MongoStorage}. Mirrors the
722
+ * required runtime fields explicitly so the family-base serializer's
723
+ * hydration walker can hand the class a typed literal.
724
+ */
725
+ interface MongoStorageInput<THash extends string = string> {
726
+ readonly storageHash: StorageHashBase<THash>;
727
+ readonly collections: Readonly<Record<string, MongoCollection>>;
728
+ readonly namespaces: Readonly<Record<string, Namespace>>;
729
+ }
730
+ /**
731
+ * Mongo family storage IR class. Carries the family-shared
732
+ * `storage.collections` map alongside the framework-promised
733
+ * `namespaces` map — single concrete class at the family layer (the
734
+ * Mongo family has one target today, and the data shape is uniform
735
+ * across the family; no abstract base earns its existence yet).
736
+ *
737
+ * `namespaces` is supplied by the caller. The Mongo target wraps a
738
+ * deserialized `MongoContract` envelope at
739
+ * `MongoTargetContractSerializer.constructTargetContract`, providing
740
+ * the default `{ [UNSPECIFIED_NAMESPACE_ID]:
741
+ * MongoTargetUnspecifiedDatabase.instance }` map at that target-layer
742
+ * site. The foundation-layer class stays target-agnostic.
743
+ *
744
+ * Constructed instances are frozen via `freezeNode(this)`; instance
745
+ * fields are JSON-clean by construction (`storageHash`, `collections`,
746
+ * `namespaces` all enumerable own properties). The persisted on-disk
747
+ * envelope shape is target-owned: `MongoTargetContractSerializer.serializeContract`
748
+ * decides whether `namespaces` round-trips through JSON or is stripped
749
+ * for the JSON envelope.
750
+ */
751
+ declare class MongoStorage<THash extends string = string> extends IRNodeBase implements Storage {
752
+ readonly kind: "mongo-storage";
753
+ readonly storageHash: StorageHashBase<THash>;
754
+ readonly collections: Readonly<Record<string, MongoCollection>>;
755
+ readonly namespaces: Readonly<Record<string, Namespace>>;
756
+ constructor(input: MongoStorageInput<THash>);
757
+ }
758
+ //#endregion
187
759
  //#region src/polymorphic-index-scope.d.ts
188
760
  type PolymorphicIndexScope = {
189
761
  readonly discriminatorField: string;
@@ -191,26 +763,15 @@ type PolymorphicIndexScope = {
191
763
  };
192
764
  type ApplyScopeResult = {
193
765
  readonly kind: 'ok';
194
- readonly index: MongoStorageIndex;
766
+ readonly index: MongoIndex;
195
767
  } | {
196
768
  readonly kind: 'conflict';
197
769
  readonly reason: string;
198
770
  };
199
- declare function applyPolymorphicScopeToMongoIndex(index: MongoStorageIndex, scope: PolymorphicIndexScope): ApplyScopeResult;
200
- //#endregion
201
- //#region src/validate-mongo-contract.d.ts
202
- interface MongoContractIndices {
203
- readonly variantToBase: Record<string, string>;
204
- readonly modelToVariants: Record<string, string[]>;
205
- }
206
- interface ValidatedMongoContract<TContract extends MongoContract> {
207
- readonly contract: TContract;
208
- readonly indices: MongoContractIndices;
209
- }
210
- declare function validateMongoContract<TContract extends MongoContract>(value: unknown): ValidatedMongoContract<TContract>;
771
+ declare function applyPolymorphicScopeToMongoIndex(index: MongoIndex, scope: PolymorphicIndexScope): ApplyScopeResult;
211
772
  //#endregion
212
773
  //#region src/validate-storage.d.ts
213
774
  declare function validateMongoStorage(contract: MongoContract): void;
214
775
  //#endregion
215
- export { type ApplyScopeResult, type ExtractMongoCodecTypes, type ExtractMongoFieldInputTypes, type ExtractMongoFieldOutputTypes, type ExtractMongoTypeMaps, type InferModelRow, type MongoChangeStreamPreAndPostImagesOptions, type MongoClusteredCollectionKey, type MongoClusteredCollectionOptions, type MongoCollationAlternate, type MongoCollationCaseFirst, type MongoCollationMaxVariable, type MongoCollationOptions, type MongoCollationStrength, type MongoCollectionOptions, type MongoContract, type MongoContractIndices, type MongoContractWithTypeMaps, type MongoIndex, type MongoIndexFieldValue, type MongoIndexFields, type MongoIndexKey, type MongoIndexKeyDirection, type MongoIndexOptionDefaults, type MongoIndexOptions, type MongoJsonObject, type MongoJsonPrimitive, type MongoJsonValue, type MongoModelDefinition, type MongoModelStorage, type MongoStorage, type MongoStorageCollection, type MongoStorageCollectionOptions, type MongoStorageIndex, type MongoStorageValidator, type MongoTimeSeriesCollectionOptions, type MongoTimeSeriesGranularity, type MongoTypeMaps, type MongoTypeMapsPhantomKey, type MongoWildcardProjection, type PolymorphicIndexScope, type ValidatedMongoContract, applyPolymorphicScopeToMongoIndex, validateMongoContract, validateMongoStorage };
776
+ export { type ApplyScopeResult, type ExtractMongoCodecTypes, type ExtractMongoFieldInputTypes, type ExtractMongoFieldOutputTypes, type ExtractMongoTypeMaps, type InferModelRow, MongoChangeStreamPreAndPostImagesOptions, type MongoChangeStreamPreAndPostImagesOptionsInput, type MongoClusteredCollectionKey, MongoClusteredCollectionOptions, type MongoClusteredCollectionOptionsInput, type MongoCollationAlternate, type MongoCollationCaseFirst, type MongoCollationMaxVariable, MongoCollationOptions, type MongoCollationOptionsInput, type MongoCollationStrength, MongoCollection, type MongoCollectionInput, MongoCollectionOptions, type MongoCollectionOptionsAuthoringInput, type MongoCollectionOptionsInput, type MongoContract, MongoContractSchema, type MongoContractWithTypeMaps, MongoIndex, type MongoIndexAuthoringInput, type MongoIndexFieldValue, type MongoIndexFields, type MongoIndexInput, type MongoIndexKey, type MongoIndexKeyDirection, MongoIndexOptionDefaults, type MongoIndexOptionDefaultsInput, MongoIndexOptions, type MongoIndexOptionsInput, type MongoJsonObject, type MongoJsonPrimitive, type MongoJsonValue, type MongoModelDefinition, type MongoModelStorage, MongoStorage, type MongoStorageCappedShape, type MongoStorageClusteredIndexShape, type MongoStorageInput, type MongoStorageShape, MongoTimeSeriesCollectionOptions, type MongoTimeSeriesCollectionOptionsInput, type MongoTimeSeriesGranularity, type MongoTypeMaps, type MongoTypeMapsPhantomKey, MongoValidator, type MongoValidatorInput, type MongoValidatorValidationAction, type MongoValidatorValidationLevel, type MongoWildcardProjection, type PolymorphicIndexScope, applyPolymorphicScopeToMongoIndex, validateMongoStorage };
216
777
  //# sourceMappingURL=index.d.mts.map