@prisma-next/mongo-contract 0.13.0-dev.9 → 0.14.0-dev.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.
@@ -0,0 +1,572 @@
1
+ import { CrossReferenceSchema } from "@prisma-next/contract/types";
2
+ import { type } from "arktype";
3
+ import { IRNodeBase, freezeNode } from "@prisma-next/framework-components/ir";
4
+ //#region src/contract-schema.ts
5
+ const ControlPolicySchema = type("'managed' | 'tolerated' | 'external' | 'observed'");
6
+ const ScalarFieldTypeSchema = type({
7
+ "+": "reject",
8
+ kind: "'scalar'",
9
+ codecId: "string",
10
+ "typeParams?": "Record<string, unknown>"
11
+ });
12
+ const ValueObjectFieldTypeSchema = type({
13
+ "+": "reject",
14
+ kind: "'valueObject'",
15
+ name: "string"
16
+ });
17
+ const UnionFieldTypeSchema = type({
18
+ "+": "reject",
19
+ kind: "'union'",
20
+ members: ScalarFieldTypeSchema.or(ValueObjectFieldTypeSchema).array()
21
+ });
22
+ const FieldSchema = type({
23
+ "+": "reject",
24
+ type: ScalarFieldTypeSchema.or(ValueObjectFieldTypeSchema).or(UnionFieldTypeSchema),
25
+ "nullable?": "boolean",
26
+ "many?": "boolean",
27
+ "dict?": "boolean"
28
+ }).pipe((field) => ({
29
+ ...field,
30
+ nullable: field.nullable ?? false
31
+ }));
32
+ const RelationSchema = type({
33
+ "+": "reject",
34
+ to: CrossReferenceSchema,
35
+ cardinality: "'1:1' | '1:N' | 'N:1'",
36
+ "on?": type({
37
+ "+": "reject",
38
+ localFields: "string[]",
39
+ targetFields: "string[]"
40
+ })
41
+ });
42
+ const StorageRelationEntrySchema = type({
43
+ "+": "reject",
44
+ field: "string"
45
+ });
46
+ const MongoJsonPrimitiveSchema = type.declare().type("string | number | boolean | null");
47
+ function isMongoJsonRecord(value) {
48
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
49
+ const prototype = Object.getPrototypeOf(value);
50
+ return prototype === Object.prototype || prototype === null;
51
+ }
52
+ function withUnseenReference(value, seen, visit) {
53
+ if (seen.has(value)) return false;
54
+ seen.add(value);
55
+ const result = visit();
56
+ seen.delete(value);
57
+ return result;
58
+ }
59
+ function isMongoJsonObject(value, seen) {
60
+ return isMongoJsonRecord(value) && withUnseenReference(value, seen, () => Object.values(value).every((entry) => isMongoJsonValue(entry, seen)));
61
+ }
62
+ function isMongoJsonValue(value, seen = /* @__PURE__ */ new WeakSet()) {
63
+ if (MongoJsonPrimitiveSchema.allows(value)) return true;
64
+ if (Array.isArray(value)) return withUnseenReference(value, seen, () => value.every((entry) => isMongoJsonValue(entry, seen)));
65
+ return isMongoJsonObject(value, seen);
66
+ }
67
+ const MongoJsonValueSchema = type("unknown").narrow((value, ctx) => isMongoJsonValue(value) ? true : ctx.mustBe("a JSON-serializable MongoJsonValue"));
68
+ const MongoJsonObjectSchema = type({ "[string]": "unknown" }).narrow((value, ctx) => isMongoJsonRecord(value) && Object.values(value).every((entry) => MongoJsonValueSchema.allows(entry)) ? true : ctx.mustBe("a JSON object with MongoJsonValue entries"));
69
+ const NumberRecordSchema = type({ "[string]": "number" });
70
+ const IndexFieldsSchema = type({
71
+ "+": "reject",
72
+ "[string]": "1 | -1 | \"text\" | \"2dsphere\" | \"2d\" | \"hashed\""
73
+ }).narrow((fields, ctx) => Object.keys(fields).length > 0 ? true : ctx.mustBe("an index field map with at least one entry"));
74
+ const CollationSchema = type({
75
+ "+": "reject",
76
+ "kind?": "'mongo-collation-options'",
77
+ locale: "string",
78
+ "caseLevel?": "boolean",
79
+ "caseFirst?": "\"off\" | \"upper\" | \"lower\"",
80
+ "strength?": "1 | 2 | 3 | 4 | 5",
81
+ "numericOrdering?": "boolean",
82
+ "alternate?": "\"non-ignorable\" | \"shifted\"",
83
+ "maxVariable?": "\"punct\" | \"space\"",
84
+ "backwards?": "boolean",
85
+ "normalization?": "boolean"
86
+ });
87
+ const IndexOptionDefaultsSchema = type({
88
+ "+": "reject",
89
+ "kind?": "'mongo-index-option-defaults'",
90
+ "storageEngine?": MongoJsonObjectSchema
91
+ });
92
+ const TimeSeriesCollectionOptionsSchema = type({
93
+ "+": "reject",
94
+ "kind?": "'mongo-time-series-collection-options'",
95
+ timeField: "string",
96
+ "metaField?": "string",
97
+ "granularity?": "\"seconds\" | \"minutes\" | \"hours\"",
98
+ "bucketMaxSpanSeconds?": "number",
99
+ "bucketRoundingSeconds?": "number"
100
+ });
101
+ const ClusteredCollectionOptionsSchema = type({
102
+ "+": "reject",
103
+ "kind?": "'mongo-clustered-collection-options'",
104
+ "name?": "string",
105
+ key: type({
106
+ "+": "reject",
107
+ "[string]": "1"
108
+ }).narrow((key, ctx) => Object.keys(key).length > 0 ? true : ctx.mustBe("a clustered index key map with at least one entry")),
109
+ unique: "boolean"
110
+ });
111
+ const ChangeStreamPreAndPostImagesSchema = type({
112
+ "+": "reject",
113
+ "kind?": "'mongo-change-stream-pre-and-post-images-options'",
114
+ enabled: "boolean"
115
+ });
116
+ type({
117
+ "+": "reject",
118
+ "capped?": "boolean",
119
+ "size?": "number",
120
+ "max?": "number",
121
+ "storageEngine?": MongoJsonObjectSchema,
122
+ "indexOptionDefaults?": IndexOptionDefaultsSchema,
123
+ "collation?": CollationSchema,
124
+ "timeseries?": TimeSeriesCollectionOptionsSchema,
125
+ "clusteredIndex?": ClusteredCollectionOptionsSchema,
126
+ "expireAfterSeconds?": "number",
127
+ "changeStreamPreAndPostImages?": ChangeStreamPreAndPostImagesSchema
128
+ });
129
+ const ModelStorageSchema = type({
130
+ "+": "reject",
131
+ "collection?": "string",
132
+ "relations?": type({ "[string]": StorageRelationEntrySchema })
133
+ });
134
+ const DiscriminatorSchema = type({
135
+ "+": "reject",
136
+ field: "string"
137
+ });
138
+ const VariantEntrySchema = type({
139
+ "+": "reject",
140
+ value: "string"
141
+ });
142
+ const ModelDefinitionSchema = type({
143
+ "+": "reject",
144
+ fields: type({ "[string]": FieldSchema }),
145
+ storage: ModelStorageSchema,
146
+ "relations?": type({ "[string]": RelationSchema }),
147
+ "discriminator?": DiscriminatorSchema,
148
+ "variants?": type({ "[string]": VariantEntrySchema }),
149
+ "base?": CrossReferenceSchema,
150
+ "owner?": "string"
151
+ });
152
+ type({
153
+ "+": "reject",
154
+ fields: IndexFieldsSchema,
155
+ "options?": type({
156
+ "+": "reject",
157
+ "kind?": "'mongo-index-options'",
158
+ "unique?": "boolean",
159
+ "name?": "string",
160
+ "partialFilterExpression?": MongoJsonObjectSchema,
161
+ "sparse?": "boolean",
162
+ "expireAfterSeconds?": "number",
163
+ "weights?": NumberRecordSchema,
164
+ "default_language?": "string",
165
+ "language_override?": "string",
166
+ "textIndexVersion?": "number",
167
+ "2dsphereIndexVersion?": "number",
168
+ "bits?": "number",
169
+ "min?": "number",
170
+ "max?": "number",
171
+ "bucketSize?": "number",
172
+ "hidden?": "boolean",
173
+ "collation?": CollationSchema,
174
+ "wildcardProjection?": type({
175
+ "+": "reject",
176
+ "[string]": "0 | 1"
177
+ })
178
+ })
179
+ });
180
+ const MongoStorageIndexSchema = type({
181
+ "+": "reject",
182
+ "kind?": "'mongo-index'",
183
+ keys: type({
184
+ "+": "reject",
185
+ field: "string",
186
+ direction: "1 | -1 | \"text\" | \"2dsphere\" | \"2d\" | \"hashed\""
187
+ }).array().atLeastLength(1),
188
+ "unique?": "boolean",
189
+ "sparse?": "boolean",
190
+ "expireAfterSeconds?": "number",
191
+ "partialFilterExpression?": "Record<string, unknown>",
192
+ "wildcardProjection?": "Record<string, 0 | 1>",
193
+ "collation?": "Record<string, unknown>",
194
+ "weights?": "Record<string, number>",
195
+ "default_language?": "string",
196
+ "language_override?": "string"
197
+ });
198
+ const MongoStorageValidatorSchema = type({
199
+ "+": "reject",
200
+ "kind?": "'mongo-validator'",
201
+ jsonSchema: "Record<string, unknown>",
202
+ validationLevel: "'strict' | 'moderate'",
203
+ validationAction: "'error' | 'warn'"
204
+ });
205
+ const MongoCollectionOptionsSchema = type({
206
+ "+": "reject",
207
+ "kind?": "'mongo-collection-options'",
208
+ "capped?": type({
209
+ "+": "reject",
210
+ size: "number",
211
+ "max?": "number"
212
+ }),
213
+ "storageEngine?": MongoJsonObjectSchema,
214
+ "indexOptionDefaults?": IndexOptionDefaultsSchema,
215
+ "timeseries?": type({
216
+ "+": "reject",
217
+ "kind?": "'mongo-time-series-collection-options'",
218
+ timeField: "string",
219
+ "metaField?": "string",
220
+ "granularity?": "'seconds' | 'minutes' | 'hours'",
221
+ "bucketMaxSpanSeconds?": "number",
222
+ "bucketRoundingSeconds?": "number"
223
+ }),
224
+ "collation?": "Record<string, unknown>",
225
+ "expireAfterSeconds?": "number",
226
+ "changeStreamPreAndPostImages?": ChangeStreamPreAndPostImagesSchema,
227
+ "clusteredIndex?": type({
228
+ "+": "reject",
229
+ "name?": "string"
230
+ })
231
+ });
232
+ const StorageCollectionSchema = type({
233
+ "+": "reject",
234
+ "kind?": "'mongo-collection'",
235
+ "indexes?": MongoStorageIndexSchema.array(),
236
+ "validator?": MongoStorageValidatorSchema,
237
+ "options?": MongoCollectionOptionsSchema,
238
+ "control?": ControlPolicySchema
239
+ });
240
+ function collectionEntrySchema(fragments) {
241
+ if (fragments === void 0 || fragments.size === 0) return StorageCollectionSchema;
242
+ return type("unknown").narrow((entry, ctx) => {
243
+ if (typeof entry !== "object" || entry === null || Array.isArray(entry)) return ctx.mustBe("an object");
244
+ const kind = entry.kind;
245
+ if (typeof kind === "string") {
246
+ const fragment = fragments.get(kind);
247
+ if (fragment !== void 0) {
248
+ const parsed = fragment(entry);
249
+ if (parsed instanceof type.errors) return ctx.reject({ expected: parsed.summary });
250
+ return true;
251
+ }
252
+ }
253
+ const parsed = StorageCollectionSchema(entry);
254
+ if (parsed instanceof type.errors) return ctx.reject({ expected: parsed.summary });
255
+ return true;
256
+ });
257
+ }
258
+ /**
259
+ * Builds the per-namespace envelope schema for Mongo storage. Pack
260
+ * contributions are keyed by the descriptor's `discriminator` and
261
+ * validate each entry by matching the entry's `kind` field. Mongo today
262
+ * has no pack contributions; the composition surface exists for symmetry
263
+ * with SQL and as the substrate for future entity kinds.
264
+ *
265
+ * `'kind?': 'string'` because `kind` is non-enumerable on built
266
+ * Mongo namespace IR classes and therefore absent from the wire shape; the
267
+ * type-side narrowing is enforced by the IR class, not by this validator.
268
+ */
269
+ function createMongoNamespaceEnvelopeSchema(fragments) {
270
+ return type({
271
+ "+": "reject",
272
+ id: "string",
273
+ "kind?": "string",
274
+ entries: type({ "collection?": type({ "[string]": collectionEntrySchema(fragments) }) })
275
+ }).narrow((ns, ctx) => {
276
+ if (typeof ns !== "object" || ns === null || Array.isArray(ns)) return ctx.mustBe("an object");
277
+ if (Object.hasOwn(ns, "collections") || Object.hasOwn(ns, "tables")) return ctx.reject({ expected: "namespace must use `entries: { collection? }`; flat `collections` / `tables` keys are no longer accepted" });
278
+ return true;
279
+ });
280
+ }
281
+ /**
282
+ * Builds the full Mongo contract schema. The per-namespace entry
283
+ * threading happens through {@link createMongoNamespaceEnvelopeSchema};
284
+ * the rest of the envelope is family-shared.
285
+ */
286
+ function createMongoContractSchema(fragments) {
287
+ const namespaceEnvelope = createMongoNamespaceEnvelopeSchema(fragments);
288
+ return type({
289
+ "+": "reject",
290
+ targetFamily: "'mongo'",
291
+ "schemaVersion?": "string",
292
+ "target?": "string",
293
+ "storageHash?": "string",
294
+ "profileHash?": "string",
295
+ roots: type({ "[string]": CrossReferenceSchema }),
296
+ "capabilities?": "Record<string, unknown>",
297
+ "extensionPacks?": "Record<string, unknown>",
298
+ "meta?": "Record<string, unknown>",
299
+ "defaultControlPolicy?": ControlPolicySchema,
300
+ "sources?": "Record<string, unknown>",
301
+ "_generated?": "Record<string, unknown>",
302
+ domain: type({ namespaces: type({ "[string]": type({
303
+ models: type({ "[string]": ModelDefinitionSchema }),
304
+ "valueObjects?": type({ "[string]": type({
305
+ "+": "reject",
306
+ fields: type({ "[string]": FieldSchema })
307
+ }) })
308
+ }) }) }),
309
+ storage: type({
310
+ "+": "reject",
311
+ namespaces: type({ "[string]": namespaceEnvelope }),
312
+ "storageHash?": "string"
313
+ })
314
+ });
315
+ }
316
+ const MongoContractSchema = createMongoContractSchema();
317
+ //#endregion
318
+ //#region src/ir/mongo-change-stream-pre-and-post-images-options.ts
319
+ /**
320
+ * Change-stream pre-and-post-images collection option. Lifted from a
321
+ * `type =` data shape to an AST class extending `IRNodeBase` per
322
+ * FR18. Single-field shape; the class exists for AST-pattern
323
+ * consistency (every nested data shape inside `MongoCollectionOptions`
324
+ * is an AST node so the verifier can walk uniformly).
325
+ */
326
+ var MongoChangeStreamPreAndPostImagesOptions = class extends IRNodeBase {
327
+ kind = "mongo-change-stream-pre-and-post-images-options";
328
+ enabled;
329
+ constructor(options) {
330
+ super();
331
+ this.enabled = options.enabled;
332
+ freezeNode(this);
333
+ }
334
+ };
335
+ //#endregion
336
+ //#region src/ir/mongo-collation-options.ts
337
+ /**
338
+ * Mongo Contract IR leaf for collection / index collation options.
339
+ *
340
+ * Lifted from a `type =` data shape to an AST class extending
341
+ * `IRNodeBase` per FR18 ("Mongo's Contract IR is fully unified under
342
+ * the AST-class pattern, layered family / target"). Single concrete class
343
+ * (no target subclass): collation options carry no target-specific
344
+ * variation at this layer — both Atlas and self-hosted Mongo consume the
345
+ * same option vocabulary.
346
+ *
347
+ * Undefined optional fields are not assigned, so `JSON.stringify` omits
348
+ * them from the canonical JSON output (matches the pre-lift data shape's
349
+ * round-trip behaviour, modulo the new `kind` discriminator).
350
+ */
351
+ var MongoCollationOptions = class extends IRNodeBase {
352
+ kind = "mongo-collation-options";
353
+ locale;
354
+ constructor(options) {
355
+ super();
356
+ this.locale = options.locale;
357
+ if (options.caseLevel !== void 0) this.caseLevel = options.caseLevel;
358
+ if (options.caseFirst !== void 0) this.caseFirst = options.caseFirst;
359
+ if (options.strength !== void 0) this.strength = options.strength;
360
+ if (options.numericOrdering !== void 0) this.numericOrdering = options.numericOrdering;
361
+ if (options.alternate !== void 0) this.alternate = options.alternate;
362
+ if (options.maxVariable !== void 0) this.maxVariable = options.maxVariable;
363
+ if (options.backwards !== void 0) this.backwards = options.backwards;
364
+ if (options.normalization !== void 0) this.normalization = options.normalization;
365
+ freezeNode(this);
366
+ }
367
+ };
368
+ //#endregion
369
+ //#region src/ir/mongo-index-option-defaults.ts
370
+ /**
371
+ * Collection-level default index options (the `indexOptionDefaults`
372
+ * collection-creation field on Mongo's `createCollection`). Lifted from
373
+ * a `type =` data shape to an AST class extending `IRNodeBase` per
374
+ * FR18 (Mongo Contract IR fully unified under the AST-class pattern).
375
+ *
376
+ * Carries `storageEngine` only — the underlying MongoDB option set is
377
+ * intentionally narrow at this layer; per-engine richer option vocabularies
378
+ * are out of scope for this project.
379
+ */
380
+ var MongoIndexOptionDefaults = class extends IRNodeBase {
381
+ kind = "mongo-index-option-defaults";
382
+ constructor(options = {}) {
383
+ super();
384
+ if (options.storageEngine !== void 0) this.storageEngine = options.storageEngine;
385
+ freezeNode(this);
386
+ }
387
+ };
388
+ //#endregion
389
+ //#region src/ir/mongo-time-series-collection-options.ts
390
+ /**
391
+ * Time-series collection options. Lifted from a `type =` data shape to
392
+ * an AST class extending `IRNodeBase` per FR18.
393
+ *
394
+ * MongoDB requires `timeField` for any time-series collection; the
395
+ * constructor enforces presence by type signature (`timeField: string`
396
+ * is required on the input).
397
+ */
398
+ var MongoTimeSeriesCollectionOptions = class extends IRNodeBase {
399
+ kind = "mongo-time-series-collection-options";
400
+ timeField;
401
+ constructor(options) {
402
+ super();
403
+ this.timeField = options.timeField;
404
+ if (options.metaField !== void 0) this.metaField = options.metaField;
405
+ if (options.granularity !== void 0) this.granularity = options.granularity;
406
+ if (options.bucketMaxSpanSeconds !== void 0) this.bucketMaxSpanSeconds = options.bucketMaxSpanSeconds;
407
+ if (options.bucketRoundingSeconds !== void 0) this.bucketRoundingSeconds = options.bucketRoundingSeconds;
408
+ freezeNode(this);
409
+ }
410
+ };
411
+ //#endregion
412
+ //#region src/ir/mongo-collection-options.ts
413
+ /**
414
+ * Mongo Contract IR node for collection-level creation options (the
415
+ * second argument to `db.createCollection(name, options)`). Lifted from
416
+ * the pre-M2R2 `MongoStorageCollectionOptions` storage interface to a
417
+ * class extending `IRNodeBase` per FR18.
418
+ *
419
+ * Single concrete family-layer class (no target subclass). The
420
+ * constructor accepts the storage JSON envelope shape ({@link
421
+ * MongoCollectionOptionsInput}) so the family-base hydration walker
422
+ * can pass arktype-validated objects directly to `new`. Authoring
423
+ * vocabulary is translated to this shape upstream in the contract-ts
424
+ * builder.
425
+ *
426
+ * Nested IR sub-shapes (collation, timeseries, …) are normalised to
427
+ * their respective IR class instances inside the constructor so
428
+ * downstream walks see a uniform AST regardless of whether the input
429
+ * was a JSON literal or an already-constructed class.
430
+ */
431
+ var MongoCollectionOptions = class extends IRNodeBase {
432
+ kind = "mongo-collection-options";
433
+ constructor(input = {}) {
434
+ super();
435
+ if (input.capped !== void 0) this.capped = {
436
+ size: input.capped.size,
437
+ ...input.capped.max != null && { max: input.capped.max }
438
+ };
439
+ if (input.storageEngine !== void 0) this.storageEngine = input.storageEngine;
440
+ if (input.indexOptionDefaults !== void 0) this.indexOptionDefaults = input.indexOptionDefaults instanceof MongoIndexOptionDefaults ? input.indexOptionDefaults : new MongoIndexOptionDefaults(input.indexOptionDefaults);
441
+ if (input.collation !== void 0) this.collation = input.collation instanceof MongoCollationOptions ? input.collation : new MongoCollationOptions(input.collation);
442
+ if (input.timeseries !== void 0) this.timeseries = input.timeseries instanceof MongoTimeSeriesCollectionOptions ? input.timeseries : new MongoTimeSeriesCollectionOptions(input.timeseries);
443
+ if (input.clusteredIndex !== void 0) this.clusteredIndex = input.clusteredIndex.name !== void 0 ? { name: input.clusteredIndex.name } : {};
444
+ if (input.expireAfterSeconds !== void 0) this.expireAfterSeconds = input.expireAfterSeconds;
445
+ if (input.changeStreamPreAndPostImages !== void 0) this.changeStreamPreAndPostImages = input.changeStreamPreAndPostImages instanceof MongoChangeStreamPreAndPostImagesOptions ? input.changeStreamPreAndPostImages : new MongoChangeStreamPreAndPostImagesOptions(input.changeStreamPreAndPostImages);
446
+ freezeNode(this);
447
+ }
448
+ };
449
+ //#endregion
450
+ //#region src/ir/mongo-index.ts
451
+ /**
452
+ * Mongo Contract IR node for a single collection index entry (one
453
+ * element of `MongoCollection.indexes`). Lifted from the
454
+ * pre-M2R2 `MongoStorageIndex` storage interface to a class extending
455
+ * `IRNodeBase` per FR18.
456
+ *
457
+ * Single concrete family-layer class (no target subclass). The spec's
458
+ * `MongoTargetIndex extends MongoIndex` pattern remains additive — a
459
+ * future Mongo target with target-specific index extensions is free to
460
+ * subclass; for the single Mongo target shipped today a concrete
461
+ * family-layer class is enough and avoids a target-import layering
462
+ * violation from the contract-ts builder.
463
+ */
464
+ var MongoIndex = class extends IRNodeBase {
465
+ kind = "mongo-index";
466
+ keys;
467
+ constructor(input) {
468
+ super();
469
+ this.keys = input.keys;
470
+ if (input.unique !== void 0) this.unique = input.unique;
471
+ if (input.sparse !== void 0) this.sparse = input.sparse;
472
+ if (input.expireAfterSeconds !== void 0) this.expireAfterSeconds = input.expireAfterSeconds;
473
+ if (input.partialFilterExpression !== void 0) this.partialFilterExpression = input.partialFilterExpression;
474
+ if (input.wildcardProjection !== void 0) this.wildcardProjection = input.wildcardProjection;
475
+ if (input.collation !== void 0) this.collation = input.collation;
476
+ if (input.weights !== void 0) this.weights = input.weights;
477
+ if (input.default_language !== void 0) this.default_language = input.default_language;
478
+ if (input.language_override !== void 0) this.language_override = input.language_override;
479
+ freezeNode(this);
480
+ }
481
+ };
482
+ //#endregion
483
+ //#region src/ir/mongo-validator.ts
484
+ /**
485
+ * Mongo Contract IR node for collection-level document validators (the
486
+ * `validator` field on Mongo's `createCollection`). Lifted from the
487
+ * pre-M2R2 `MongoStorageValidator` storage interface to a class extending
488
+ * `IRNodeBase` per FR18.
489
+ *
490
+ * Concrete at the family layer (no target subclass). The spec's
491
+ * abstract-family + target-concrete pattern (`MongoTargetValidator
492
+ * extends MongoValidator`) becomes meaningful when a second Mongo target
493
+ * introduces target-specific validator extensions (Atlas search rules,
494
+ * DocumentDB-specific levels, …); for the single Mongo target shipped
495
+ * today, a concrete family-layer class lets the PSL JSON-Schema deriver
496
+ * and the contract-ts builder construct instances directly without a
497
+ * target-import layering violation. Target subclassing remains additive
498
+ * — a future `MongoTargetValidator extends MongoValidator` is an
499
+ * additive change, not a breaking one.
500
+ */
501
+ var MongoValidator = class extends IRNodeBase {
502
+ kind = "mongo-validator";
503
+ jsonSchema;
504
+ validationLevel;
505
+ validationAction;
506
+ constructor(input) {
507
+ super();
508
+ this.jsonSchema = input.jsonSchema;
509
+ this.validationLevel = input.validationLevel;
510
+ this.validationAction = input.validationAction;
511
+ freezeNode(this);
512
+ }
513
+ };
514
+ //#endregion
515
+ //#region src/ir/mongo-collection.ts
516
+ /**
517
+ * Mongo Contract IR node for a single collection entry in a namespace's
518
+ * `collections` map. Lifted from the pre-M2R2
519
+ * `MongoStorageCollection` storage interface to a class extending
520
+ * `IRNodeBase` per FR18.
521
+ *
522
+ * Concrete at the family layer (no target subclass). The spec's
523
+ * `MongoTargetCollection extends MongoCollection` pattern remains
524
+ * additive: a future Mongo target with target-specific extensions is
525
+ * free to subclass without breaking the family-layer construction
526
+ * sites.
527
+ *
528
+ * The unprefixed name `MongoCollection` is now the contract IR class.
529
+ * Note that `@prisma-next/mongo-orm` also exports a (different)
530
+ * `MongoCollection<TContract, ModelName>` generic for the user-facing
531
+ * ORM query builder; the two live in separate packages and are
532
+ * resolved by import path. A source file that needs both should alias
533
+ * one (e.g. `import { MongoCollection as MongoContractCollection }
534
+ * from '@prisma-next/mongo-contract'`).
535
+ */
536
+ var MongoCollection = class extends IRNodeBase {
537
+ kind = "mongo-collection";
538
+ constructor(input = {}) {
539
+ super();
540
+ if (input.indexes !== void 0) this.indexes = input.indexes.map((idx) => idx instanceof MongoIndex ? idx : new MongoIndex(idx));
541
+ if (input.validator !== void 0) this.validator = input.validator instanceof MongoValidator ? input.validator : new MongoValidator(input.validator);
542
+ if (input.options !== void 0) this.options = input.options instanceof MongoCollectionOptions ? input.options : new MongoCollectionOptions(input.options);
543
+ if (input.control !== void 0) this.control = input.control;
544
+ freezeNode(this);
545
+ }
546
+ };
547
+ //#endregion
548
+ //#region src/entity-kinds.ts
549
+ const collectionEntityKind = {
550
+ kind: "collection",
551
+ schema: StorageCollectionSchema,
552
+ construct: (input) => new MongoCollection(input)
553
+ };
554
+ /**
555
+ * Assembles the `kind → descriptor` registry for Mongo namespaces: the built-in
556
+ * `collection` kind plus any target `packKinds`. This builds the lookup table —
557
+ * it does not touch contract data. `hydrateNamespaceEntities` later consumes
558
+ * this registry to turn a namespace's raw entries into IR instances. Throws on
559
+ * a duplicate kind.
560
+ */
561
+ function composeMongoEntityKinds(packKinds = []) {
562
+ const kinds = new Map([["collection", collectionEntityKind]]);
563
+ for (const descriptor of packKinds) {
564
+ if (kinds.has(descriptor.kind)) throw new Error(`composeMongoEntityKinds: duplicate entity kind "${descriptor.kind}" — each kind may be registered only once`);
565
+ kinds.set(descriptor.kind, descriptor);
566
+ }
567
+ return kinds;
568
+ }
569
+ //#endregion
570
+ export { MongoIndex as a, MongoIndexOptionDefaults as c, MongoContractSchema as d, createMongoContractSchema as f, MongoValidator as i, MongoCollationOptions as l, composeMongoEntityKinds as n, MongoCollectionOptions as o, createMongoNamespaceEnvelopeSchema as p, MongoCollection as r, MongoTimeSeriesCollectionOptions as s, collectionEntityKind as t, MongoChangeStreamPreAndPostImagesOptions as u };
571
+
572
+ //# sourceMappingURL=entity-kinds-C9KNr9IE.mjs.map