@prisma-next/mongo-contract 0.8.0 → 0.9.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.
- package/README.md +3 -3
- package/dist/index.d.mts +657 -96
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +392 -70
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/contract-schema.ts +16 -0
- package/src/contract-types.ts +24 -123
- package/src/exports/index.ts +46 -21
- package/src/ir/mongo-change-stream-pre-and-post-images-options.ts +23 -0
- package/src/ir/mongo-clustered-collection-options.ts +32 -0
- package/src/ir/mongo-collation-options.ts +66 -0
- package/src/ir/mongo-collection-options.ts +159 -0
- package/src/ir/mongo-collection.ts +71 -0
- package/src/ir/mongo-index-option-defaults.ts +27 -0
- package/src/ir/mongo-index-options.ts +91 -0
- package/src/ir/mongo-index.ts +64 -0
- package/src/ir/mongo-storage.ts +55 -0
- package/src/ir/mongo-time-series-collection-options.ts +40 -0
- package/src/ir/mongo-validator.ts +42 -0
- package/src/polymorphic-index-scope.ts +16 -6
- package/src/validate-mongo-contract.ts +0 -49
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/contract-
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/contract-schema.ts","../src/ir/mongo-change-stream-pre-and-post-images-options.ts","../src/ir/mongo-clustered-collection-options.ts","../src/ir/mongo-collation-options.ts","../src/ir/mongo-index-option-defaults.ts","../src/ir/mongo-time-series-collection-options.ts","../src/ir/mongo-collection-options.ts","../src/ir/mongo-index.ts","../src/ir/mongo-validator.ts","../src/ir/mongo-collection.ts","../src/ir/mongo-index-options.ts","../src/contract-types.ts","../src/ir/mongo-storage.ts","../src/polymorphic-index-scope.ts","../src/validate-storage.ts"],"mappings":";;;;;;cA+Ta,mBAAA,yCAAmB,UAAA;;;;;;;;;;;;;;;;;;;;;;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,QAAA,CAAS,MAAA,SAAe,eAAA;EAAA,SACrC,UAAA,EAAY,QAAA,CAAS,MAAA,SAAe,SAAA;cAEjC,KAAA,EAAO,iBAAA,CAAkB,KAAA;AAAA;;;KC7C3B,qBAAA;EAAA,SACD,kBAAA;EAAA,SACA,kBAAA;AAAA;AAAA,KAGC,gBAAA;EAAA,SACG,IAAA;EAAA,SAAqB,KAAA,EAAO,UAAA;AAAA;EAAA,SAC5B,IAAA;EAAA,SAA2B,MAAA;AAAA;AAAA,iBAe1B,iCAAA,CACd,KAAA,EAAO,UAAA,EACP,KAAA,EAAO,qBAAA,GACN,gBAAA;;;iBCzBa,oBAAA,CAAqB,QAAA,EAAU,aAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,47 +1,5 @@
|
|
|
1
|
-
import { validateContractDomain } from "@prisma-next/contract/validate-domain";
|
|
2
1
|
import { type } from "arktype";
|
|
3
|
-
|
|
4
|
-
function isScalarDiscriminatorValue(value) {
|
|
5
|
-
const t = typeof value;
|
|
6
|
-
return t === "string" || t === "number" || t === "boolean";
|
|
7
|
-
}
|
|
8
|
-
function formatValue(value) {
|
|
9
|
-
if (typeof value === "string") return JSON.stringify(value);
|
|
10
|
-
if (value === null) return "null";
|
|
11
|
-
if (Array.isArray(value)) return JSON.stringify(value);
|
|
12
|
-
if (typeof value === "object") return JSON.stringify(value);
|
|
13
|
-
return String(value);
|
|
14
|
-
}
|
|
15
|
-
function applyPolymorphicScopeToMongoIndex(index, scope) {
|
|
16
|
-
if (!isScalarDiscriminatorValue(scope.discriminatorValue)) return {
|
|
17
|
-
kind: "conflict",
|
|
18
|
-
reason: `Variant-scoped indexes require a scalar (string, number, or boolean) discriminator value for field "${scope.discriminatorField}", but received ${formatValue(scope.discriminatorValue)}.`
|
|
19
|
-
};
|
|
20
|
-
const existing = index.partialFilterExpression;
|
|
21
|
-
if (existing && Object.hasOwn(existing, scope.discriminatorField)) {
|
|
22
|
-
const existingValue = existing[scope.discriminatorField];
|
|
23
|
-
if (existingValue === scope.discriminatorValue) return {
|
|
24
|
-
kind: "ok",
|
|
25
|
-
index
|
|
26
|
-
};
|
|
27
|
-
return {
|
|
28
|
-
kind: "conflict",
|
|
29
|
-
reason: `Index partialFilterExpression sets "${scope.discriminatorField}" to ${formatValue(existingValue)}, which conflicts with the variant's discriminator value ${formatValue(scope.discriminatorValue)}.`
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
const merged = {
|
|
33
|
-
...existing ?? {},
|
|
34
|
-
[scope.discriminatorField]: scope.discriminatorValue
|
|
35
|
-
};
|
|
36
|
-
return {
|
|
37
|
-
kind: "ok",
|
|
38
|
-
index: {
|
|
39
|
-
...index,
|
|
40
|
-
partialFilterExpression: merged
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
//#endregion
|
|
2
|
+
import { IRNodeBase, freezeNode } from "@prisma-next/framework-components/ir";
|
|
45
3
|
//#region src/contract-schema.ts
|
|
46
4
|
const ScalarFieldTypeSchema = type({
|
|
47
5
|
"+": "reject",
|
|
@@ -113,6 +71,7 @@ const IndexFieldsSchema = type({
|
|
|
113
71
|
}).narrow((fields, ctx) => Object.keys(fields).length > 0 ? true : ctx.mustBe("an index field map with at least one entry"));
|
|
114
72
|
const CollationSchema = type({
|
|
115
73
|
"+": "reject",
|
|
74
|
+
"kind?": "'mongo-collation-options'",
|
|
116
75
|
locale: "string",
|
|
117
76
|
"caseLevel?": "boolean",
|
|
118
77
|
"caseFirst?": "\"off\" | \"upper\" | \"lower\"",
|
|
@@ -125,10 +84,12 @@ const CollationSchema = type({
|
|
|
125
84
|
});
|
|
126
85
|
const IndexOptionDefaultsSchema = type({
|
|
127
86
|
"+": "reject",
|
|
87
|
+
"kind?": "'mongo-index-option-defaults'",
|
|
128
88
|
"storageEngine?": MongoJsonObjectSchema
|
|
129
89
|
});
|
|
130
90
|
const TimeSeriesCollectionOptionsSchema = type({
|
|
131
91
|
"+": "reject",
|
|
92
|
+
"kind?": "'mongo-time-series-collection-options'",
|
|
132
93
|
timeField: "string",
|
|
133
94
|
"metaField?": "string",
|
|
134
95
|
"granularity?": "\"seconds\" | \"minutes\" | \"hours\"",
|
|
@@ -137,6 +98,7 @@ const TimeSeriesCollectionOptionsSchema = type({
|
|
|
137
98
|
});
|
|
138
99
|
const ClusteredCollectionOptionsSchema = type({
|
|
139
100
|
"+": "reject",
|
|
101
|
+
"kind?": "'mongo-clustered-collection-options'",
|
|
140
102
|
"name?": "string",
|
|
141
103
|
key: type({
|
|
142
104
|
"+": "reject",
|
|
@@ -146,6 +108,7 @@ const ClusteredCollectionOptionsSchema = type({
|
|
|
146
108
|
});
|
|
147
109
|
const ChangeStreamPreAndPostImagesSchema = type({
|
|
148
110
|
"+": "reject",
|
|
111
|
+
"kind?": "'mongo-change-stream-pre-and-post-images-options'",
|
|
149
112
|
enabled: "boolean"
|
|
150
113
|
});
|
|
151
114
|
type({
|
|
@@ -189,6 +152,7 @@ type({
|
|
|
189
152
|
fields: IndexFieldsSchema,
|
|
190
153
|
"options?": type({
|
|
191
154
|
"+": "reject",
|
|
155
|
+
"kind?": "'mongo-index-options'",
|
|
192
156
|
"unique?": "boolean",
|
|
193
157
|
"name?": "string",
|
|
194
158
|
"partialFilterExpression?": MongoJsonObjectSchema,
|
|
@@ -213,6 +177,7 @@ type({
|
|
|
213
177
|
});
|
|
214
178
|
const MongoStorageIndexSchema = type({
|
|
215
179
|
"+": "reject",
|
|
180
|
+
"kind?": "'mongo-index'",
|
|
216
181
|
keys: type({
|
|
217
182
|
"+": "reject",
|
|
218
183
|
field: "string",
|
|
@@ -230,24 +195,32 @@ const MongoStorageIndexSchema = type({
|
|
|
230
195
|
});
|
|
231
196
|
const MongoStorageValidatorSchema = type({
|
|
232
197
|
"+": "reject",
|
|
198
|
+
"kind?": "'mongo-validator'",
|
|
233
199
|
jsonSchema: "Record<string, unknown>",
|
|
234
200
|
validationLevel: "'strict' | 'moderate'",
|
|
235
201
|
validationAction: "'error' | 'warn'"
|
|
236
202
|
});
|
|
237
203
|
const MongoCollectionOptionsSchema = type({
|
|
238
204
|
"+": "reject",
|
|
205
|
+
"kind?": "'mongo-collection-options'",
|
|
239
206
|
"capped?": type({
|
|
240
207
|
"+": "reject",
|
|
241
208
|
size: "number",
|
|
242
209
|
"max?": "number"
|
|
243
210
|
}),
|
|
211
|
+
"storageEngine?": MongoJsonObjectSchema,
|
|
212
|
+
"indexOptionDefaults?": IndexOptionDefaultsSchema,
|
|
244
213
|
"timeseries?": type({
|
|
245
214
|
"+": "reject",
|
|
215
|
+
"kind?": "'mongo-time-series-collection-options'",
|
|
246
216
|
timeField: "string",
|
|
247
217
|
"metaField?": "string",
|
|
248
|
-
"granularity?": "'seconds' | 'minutes' | 'hours'"
|
|
218
|
+
"granularity?": "'seconds' | 'minutes' | 'hours'",
|
|
219
|
+
"bucketMaxSpanSeconds?": "number",
|
|
220
|
+
"bucketRoundingSeconds?": "number"
|
|
249
221
|
}),
|
|
250
222
|
"collation?": "Record<string, unknown>",
|
|
223
|
+
"expireAfterSeconds?": "number",
|
|
251
224
|
"changeStreamPreAndPostImages?": ChangeStreamPreAndPostImagesSchema,
|
|
252
225
|
"clusteredIndex?": type({
|
|
253
226
|
"+": "reject",
|
|
@@ -271,6 +244,7 @@ const MongoContractSchema = type({
|
|
|
271
244
|
"+": "reject",
|
|
272
245
|
collections: type({ "[string]": type({
|
|
273
246
|
"+": "reject",
|
|
247
|
+
"kind?": "'mongo-collection'",
|
|
274
248
|
"indexes?": MongoStorageIndexSchema.array(),
|
|
275
249
|
"validator?": MongoStorageValidatorSchema,
|
|
276
250
|
"options?": MongoCollectionOptionsSchema
|
|
@@ -284,6 +258,379 @@ const MongoContractSchema = type({
|
|
|
284
258
|
}) })
|
|
285
259
|
});
|
|
286
260
|
//#endregion
|
|
261
|
+
//#region src/ir/mongo-change-stream-pre-and-post-images-options.ts
|
|
262
|
+
/**
|
|
263
|
+
* Change-stream pre-and-post-images collection option. Lifted from a
|
|
264
|
+
* `type =` data shape to an AST class extending `IRNodeBase` per
|
|
265
|
+
* FR18. Single-field shape; the class exists for AST-pattern
|
|
266
|
+
* consistency (every nested data shape inside `MongoCollectionOptions`
|
|
267
|
+
* is an AST node so the verifier can walk uniformly).
|
|
268
|
+
*/
|
|
269
|
+
var MongoChangeStreamPreAndPostImagesOptions = class extends IRNodeBase {
|
|
270
|
+
kind = "mongo-change-stream-pre-and-post-images-options";
|
|
271
|
+
enabled;
|
|
272
|
+
constructor(options) {
|
|
273
|
+
super();
|
|
274
|
+
this.enabled = options.enabled;
|
|
275
|
+
freezeNode(this);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
//#endregion
|
|
279
|
+
//#region src/ir/mongo-clustered-collection-options.ts
|
|
280
|
+
/**
|
|
281
|
+
* Clustered-collection options (the `clusteredIndex` collection-creation
|
|
282
|
+
* field). Lifted from a `type =` data shape to an AST class extending
|
|
283
|
+
* `IRNodeBase` per FR18.
|
|
284
|
+
*
|
|
285
|
+
* MongoDB requires `key` and `unique` for any clustered collection; the
|
|
286
|
+
* constructor enforces presence by type signature.
|
|
287
|
+
*/
|
|
288
|
+
var MongoClusteredCollectionOptions = class extends IRNodeBase {
|
|
289
|
+
kind = "mongo-clustered-collection-options";
|
|
290
|
+
key;
|
|
291
|
+
unique;
|
|
292
|
+
constructor(options) {
|
|
293
|
+
super();
|
|
294
|
+
if (options.name !== void 0) this.name = options.name;
|
|
295
|
+
this.key = options.key;
|
|
296
|
+
this.unique = options.unique;
|
|
297
|
+
freezeNode(this);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/ir/mongo-collation-options.ts
|
|
302
|
+
/**
|
|
303
|
+
* Mongo Contract IR leaf for collection / index collation options.
|
|
304
|
+
*
|
|
305
|
+
* Lifted from a `type =` data shape to an AST class extending
|
|
306
|
+
* `IRNodeBase` per FR18 ("Mongo's Contract IR is fully unified under
|
|
307
|
+
* the AST-class pattern, layered family / target"). Single concrete class
|
|
308
|
+
* (no target subclass): collation options carry no target-specific
|
|
309
|
+
* variation at this layer — both Atlas and self-hosted Mongo consume the
|
|
310
|
+
* same option vocabulary.
|
|
311
|
+
*
|
|
312
|
+
* Undefined optional fields are not assigned, so `JSON.stringify` omits
|
|
313
|
+
* them from the canonical JSON output (matches the pre-lift data shape's
|
|
314
|
+
* round-trip behaviour, modulo the new `kind` discriminator).
|
|
315
|
+
*/
|
|
316
|
+
var MongoCollationOptions = class extends IRNodeBase {
|
|
317
|
+
kind = "mongo-collation-options";
|
|
318
|
+
locale;
|
|
319
|
+
constructor(options) {
|
|
320
|
+
super();
|
|
321
|
+
this.locale = options.locale;
|
|
322
|
+
if (options.caseLevel !== void 0) this.caseLevel = options.caseLevel;
|
|
323
|
+
if (options.caseFirst !== void 0) this.caseFirst = options.caseFirst;
|
|
324
|
+
if (options.strength !== void 0) this.strength = options.strength;
|
|
325
|
+
if (options.numericOrdering !== void 0) this.numericOrdering = options.numericOrdering;
|
|
326
|
+
if (options.alternate !== void 0) this.alternate = options.alternate;
|
|
327
|
+
if (options.maxVariable !== void 0) this.maxVariable = options.maxVariable;
|
|
328
|
+
if (options.backwards !== void 0) this.backwards = options.backwards;
|
|
329
|
+
if (options.normalization !== void 0) this.normalization = options.normalization;
|
|
330
|
+
freezeNode(this);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/ir/mongo-index-option-defaults.ts
|
|
335
|
+
/**
|
|
336
|
+
* Collection-level default index options (the `indexOptionDefaults`
|
|
337
|
+
* collection-creation field on Mongo's `createCollection`). Lifted from
|
|
338
|
+
* a `type =` data shape to an AST class extending `IRNodeBase` per
|
|
339
|
+
* FR18 (Mongo Contract IR fully unified under the AST-class pattern).
|
|
340
|
+
*
|
|
341
|
+
* Carries `storageEngine` only — the underlying MongoDB option set is
|
|
342
|
+
* intentionally narrow at this layer; per-engine richer option vocabularies
|
|
343
|
+
* are out of scope for this project.
|
|
344
|
+
*/
|
|
345
|
+
var MongoIndexOptionDefaults = class extends IRNodeBase {
|
|
346
|
+
kind = "mongo-index-option-defaults";
|
|
347
|
+
constructor(options = {}) {
|
|
348
|
+
super();
|
|
349
|
+
if (options.storageEngine !== void 0) this.storageEngine = options.storageEngine;
|
|
350
|
+
freezeNode(this);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
//#endregion
|
|
354
|
+
//#region src/ir/mongo-time-series-collection-options.ts
|
|
355
|
+
/**
|
|
356
|
+
* Time-series collection options. Lifted from a `type =` data shape to
|
|
357
|
+
* an AST class extending `IRNodeBase` per FR18.
|
|
358
|
+
*
|
|
359
|
+
* MongoDB requires `timeField` for any time-series collection; the
|
|
360
|
+
* constructor enforces presence by type signature (`timeField: string`
|
|
361
|
+
* is required on the input).
|
|
362
|
+
*/
|
|
363
|
+
var MongoTimeSeriesCollectionOptions = class extends IRNodeBase {
|
|
364
|
+
kind = "mongo-time-series-collection-options";
|
|
365
|
+
timeField;
|
|
366
|
+
constructor(options) {
|
|
367
|
+
super();
|
|
368
|
+
this.timeField = options.timeField;
|
|
369
|
+
if (options.metaField !== void 0) this.metaField = options.metaField;
|
|
370
|
+
if (options.granularity !== void 0) this.granularity = options.granularity;
|
|
371
|
+
if (options.bucketMaxSpanSeconds !== void 0) this.bucketMaxSpanSeconds = options.bucketMaxSpanSeconds;
|
|
372
|
+
if (options.bucketRoundingSeconds !== void 0) this.bucketRoundingSeconds = options.bucketRoundingSeconds;
|
|
373
|
+
freezeNode(this);
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
//#endregion
|
|
377
|
+
//#region src/ir/mongo-collection-options.ts
|
|
378
|
+
/**
|
|
379
|
+
* Mongo Contract IR node for collection-level creation options (the
|
|
380
|
+
* second argument to `db.createCollection(name, options)`). Lifted from
|
|
381
|
+
* the pre-M2R2 `MongoStorageCollectionOptions` storage interface to a
|
|
382
|
+
* class extending `IRNodeBase` per FR18.
|
|
383
|
+
*
|
|
384
|
+
* Single concrete family-layer class (no target subclass). The
|
|
385
|
+
* constructor accepts the storage JSON envelope shape ({@link
|
|
386
|
+
* MongoCollectionOptionsInput}) so the family-base hydration walker
|
|
387
|
+
* can pass arktype-validated objects directly to `new`. Authoring
|
|
388
|
+
* vocabulary is translated to this shape upstream in the contract-ts
|
|
389
|
+
* builder.
|
|
390
|
+
*
|
|
391
|
+
* Nested IR sub-shapes (collation, timeseries, …) are normalised to
|
|
392
|
+
* their respective IR class instances inside the constructor so
|
|
393
|
+
* downstream walks see a uniform AST regardless of whether the input
|
|
394
|
+
* was a JSON literal or an already-constructed class.
|
|
395
|
+
*/
|
|
396
|
+
var MongoCollectionOptions = class extends IRNodeBase {
|
|
397
|
+
kind = "mongo-collection-options";
|
|
398
|
+
constructor(input = {}) {
|
|
399
|
+
super();
|
|
400
|
+
if (input.capped !== void 0) this.capped = {
|
|
401
|
+
size: input.capped.size,
|
|
402
|
+
...input.capped.max != null && { max: input.capped.max }
|
|
403
|
+
};
|
|
404
|
+
if (input.storageEngine !== void 0) this.storageEngine = input.storageEngine;
|
|
405
|
+
if (input.indexOptionDefaults !== void 0) this.indexOptionDefaults = input.indexOptionDefaults instanceof MongoIndexOptionDefaults ? input.indexOptionDefaults : new MongoIndexOptionDefaults(input.indexOptionDefaults);
|
|
406
|
+
if (input.collation !== void 0) this.collation = input.collation instanceof MongoCollationOptions ? input.collation : new MongoCollationOptions(input.collation);
|
|
407
|
+
if (input.timeseries !== void 0) this.timeseries = input.timeseries instanceof MongoTimeSeriesCollectionOptions ? input.timeseries : new MongoTimeSeriesCollectionOptions(input.timeseries);
|
|
408
|
+
if (input.clusteredIndex !== void 0) this.clusteredIndex = input.clusteredIndex.name !== void 0 ? { name: input.clusteredIndex.name } : {};
|
|
409
|
+
if (input.expireAfterSeconds !== void 0) this.expireAfterSeconds = input.expireAfterSeconds;
|
|
410
|
+
if (input.changeStreamPreAndPostImages !== void 0) this.changeStreamPreAndPostImages = input.changeStreamPreAndPostImages instanceof MongoChangeStreamPreAndPostImagesOptions ? input.changeStreamPreAndPostImages : new MongoChangeStreamPreAndPostImagesOptions(input.changeStreamPreAndPostImages);
|
|
411
|
+
freezeNode(this);
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
//#endregion
|
|
415
|
+
//#region src/ir/mongo-index.ts
|
|
416
|
+
/**
|
|
417
|
+
* Mongo Contract IR node for a single collection index entry (one
|
|
418
|
+
* element of `MongoCollection.indexes`). Lifted from the
|
|
419
|
+
* pre-M2R2 `MongoStorageIndex` storage interface to a class extending
|
|
420
|
+
* `IRNodeBase` per FR18.
|
|
421
|
+
*
|
|
422
|
+
* Single concrete family-layer class (no target subclass). The spec's
|
|
423
|
+
* `MongoTargetIndex extends MongoIndex` pattern remains additive — a
|
|
424
|
+
* future Mongo target with target-specific index extensions is free to
|
|
425
|
+
* subclass; for the single Mongo target shipped today a concrete
|
|
426
|
+
* family-layer class is enough and avoids a target-import layering
|
|
427
|
+
* violation from the contract-ts builder.
|
|
428
|
+
*/
|
|
429
|
+
var MongoIndex = class extends IRNodeBase {
|
|
430
|
+
kind = "mongo-index";
|
|
431
|
+
keys;
|
|
432
|
+
constructor(input) {
|
|
433
|
+
super();
|
|
434
|
+
this.keys = input.keys;
|
|
435
|
+
if (input.unique !== void 0) this.unique = input.unique;
|
|
436
|
+
if (input.sparse !== void 0) this.sparse = input.sparse;
|
|
437
|
+
if (input.expireAfterSeconds !== void 0) this.expireAfterSeconds = input.expireAfterSeconds;
|
|
438
|
+
if (input.partialFilterExpression !== void 0) this.partialFilterExpression = input.partialFilterExpression;
|
|
439
|
+
if (input.wildcardProjection !== void 0) this.wildcardProjection = input.wildcardProjection;
|
|
440
|
+
if (input.collation !== void 0) this.collation = input.collation;
|
|
441
|
+
if (input.weights !== void 0) this.weights = input.weights;
|
|
442
|
+
if (input.default_language !== void 0) this.default_language = input.default_language;
|
|
443
|
+
if (input.language_override !== void 0) this.language_override = input.language_override;
|
|
444
|
+
freezeNode(this);
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
//#endregion
|
|
448
|
+
//#region src/ir/mongo-validator.ts
|
|
449
|
+
/**
|
|
450
|
+
* Mongo Contract IR node for collection-level document validators (the
|
|
451
|
+
* `validator` field on Mongo's `createCollection`). Lifted from the
|
|
452
|
+
* pre-M2R2 `MongoStorageValidator` storage interface to a class extending
|
|
453
|
+
* `IRNodeBase` per FR18.
|
|
454
|
+
*
|
|
455
|
+
* Concrete at the family layer (no target subclass). The spec's
|
|
456
|
+
* abstract-family + target-concrete pattern (`MongoTargetValidator
|
|
457
|
+
* extends MongoValidator`) becomes meaningful when a second Mongo target
|
|
458
|
+
* introduces target-specific validator extensions (Atlas search rules,
|
|
459
|
+
* DocumentDB-specific levels, …); for the single Mongo target shipped
|
|
460
|
+
* today, a concrete family-layer class lets the PSL JSON-Schema deriver
|
|
461
|
+
* and the contract-ts builder construct instances directly without a
|
|
462
|
+
* target-import layering violation. Target subclassing remains additive
|
|
463
|
+
* — a future `MongoTargetValidator extends MongoValidator` is an
|
|
464
|
+
* additive change, not a breaking one.
|
|
465
|
+
*/
|
|
466
|
+
var MongoValidator = class extends IRNodeBase {
|
|
467
|
+
kind = "mongo-validator";
|
|
468
|
+
jsonSchema;
|
|
469
|
+
validationLevel;
|
|
470
|
+
validationAction;
|
|
471
|
+
constructor(input) {
|
|
472
|
+
super();
|
|
473
|
+
this.jsonSchema = input.jsonSchema;
|
|
474
|
+
this.validationLevel = input.validationLevel;
|
|
475
|
+
this.validationAction = input.validationAction;
|
|
476
|
+
freezeNode(this);
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region src/ir/mongo-collection.ts
|
|
481
|
+
/**
|
|
482
|
+
* Mongo Contract IR node for a single collection entry in
|
|
483
|
+
* `contract.storage.collections`. Lifted from the pre-M2R2
|
|
484
|
+
* `MongoStorageCollection` storage interface to a class extending
|
|
485
|
+
* `IRNodeBase` per FR18.
|
|
486
|
+
*
|
|
487
|
+
* Concrete at the family layer (no target subclass). The spec's
|
|
488
|
+
* `MongoTargetCollection extends MongoCollection` pattern remains
|
|
489
|
+
* additive: a future Mongo target with target-specific extensions is
|
|
490
|
+
* free to subclass without breaking the family-layer construction
|
|
491
|
+
* sites.
|
|
492
|
+
*
|
|
493
|
+
* The unprefixed name `MongoCollection` is now the contract IR class.
|
|
494
|
+
* Note that `@prisma-next/mongo-orm` also exports a (different)
|
|
495
|
+
* `MongoCollection<TContract, ModelName>` generic for the user-facing
|
|
496
|
+
* ORM query builder; the two live in separate packages and are
|
|
497
|
+
* resolved by import path. A source file that needs both should alias
|
|
498
|
+
* one (e.g. `import { MongoCollection as MongoContractCollection }
|
|
499
|
+
* from '@prisma-next/mongo-contract'`).
|
|
500
|
+
*/
|
|
501
|
+
var MongoCollection = class extends IRNodeBase {
|
|
502
|
+
kind = "mongo-collection";
|
|
503
|
+
constructor(input = {}) {
|
|
504
|
+
super();
|
|
505
|
+
if (input.indexes !== void 0) this.indexes = input.indexes.map((idx) => idx instanceof MongoIndex ? idx : new MongoIndex(idx));
|
|
506
|
+
if (input.validator !== void 0) this.validator = input.validator instanceof MongoValidator ? input.validator : new MongoValidator(input.validator);
|
|
507
|
+
if (input.options !== void 0) this.options = input.options instanceof MongoCollectionOptions ? input.options : new MongoCollectionOptions(input.options);
|
|
508
|
+
freezeNode(this);
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
//#endregion
|
|
512
|
+
//#region src/ir/mongo-index-options.ts
|
|
513
|
+
/**
|
|
514
|
+
* Mongo Contract IR node for the per-index option vocabulary (the second
|
|
515
|
+
* argument to `db.collection.createIndex(keys, options)` minus the keys
|
|
516
|
+
* themselves). Lifted from a `type =` data shape to an AST class
|
|
517
|
+
* extending `IRNodeBase` per FR18.
|
|
518
|
+
*
|
|
519
|
+
* Nested `collation` is itself an IR class (`MongoCollationOptions`); the
|
|
520
|
+
* constructor accepts either a class instance or a data literal and
|
|
521
|
+
* normalises to the class form so downstream walks see a uniform IR tree.
|
|
522
|
+
*/
|
|
523
|
+
var MongoIndexOptions = class extends IRNodeBase {
|
|
524
|
+
kind = "mongo-index-options";
|
|
525
|
+
constructor(options = {}) {
|
|
526
|
+
super();
|
|
527
|
+
if (options.unique !== void 0) this.unique = options.unique;
|
|
528
|
+
if (options.name !== void 0) this.name = options.name;
|
|
529
|
+
if (options.partialFilterExpression !== void 0) this.partialFilterExpression = options.partialFilterExpression;
|
|
530
|
+
if (options.sparse !== void 0) this.sparse = options.sparse;
|
|
531
|
+
if (options.expireAfterSeconds !== void 0) this.expireAfterSeconds = options.expireAfterSeconds;
|
|
532
|
+
if (options.weights !== void 0) this.weights = options.weights;
|
|
533
|
+
if (options.default_language !== void 0) this.default_language = options.default_language;
|
|
534
|
+
if (options.language_override !== void 0) this.language_override = options.language_override;
|
|
535
|
+
if (options.textIndexVersion !== void 0) this.textIndexVersion = options.textIndexVersion;
|
|
536
|
+
if (options["2dsphereIndexVersion"] !== void 0) this["2dsphereIndexVersion"] = options["2dsphereIndexVersion"];
|
|
537
|
+
if (options.bits !== void 0) this.bits = options.bits;
|
|
538
|
+
if (options.min !== void 0) this.min = options.min;
|
|
539
|
+
if (options.max !== void 0) this.max = options.max;
|
|
540
|
+
if (options.bucketSize !== void 0) this.bucketSize = options.bucketSize;
|
|
541
|
+
if (options.hidden !== void 0) this.hidden = options.hidden;
|
|
542
|
+
if (options.collation !== void 0) this.collation = options.collation instanceof MongoCollationOptions ? options.collation : new MongoCollationOptions(options.collation);
|
|
543
|
+
if (options.wildcardProjection !== void 0) this.wildcardProjection = options.wildcardProjection;
|
|
544
|
+
freezeNode(this);
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
//#endregion
|
|
548
|
+
//#region src/ir/mongo-storage.ts
|
|
549
|
+
/**
|
|
550
|
+
* Mongo family storage IR class. Carries the family-shared
|
|
551
|
+
* `storage.collections` map alongside the framework-promised
|
|
552
|
+
* `namespaces` map — single concrete class at the family layer (the
|
|
553
|
+
* Mongo family has one target today, and the data shape is uniform
|
|
554
|
+
* across the family; no abstract base earns its existence yet).
|
|
555
|
+
*
|
|
556
|
+
* `namespaces` is supplied by the caller. The Mongo target wraps a
|
|
557
|
+
* deserialized `MongoContract` envelope at
|
|
558
|
+
* `MongoTargetContractSerializer.constructTargetContract`, providing
|
|
559
|
+
* the default `{ [UNSPECIFIED_NAMESPACE_ID]:
|
|
560
|
+
* MongoTargetUnspecifiedDatabase.instance }` map at that target-layer
|
|
561
|
+
* site. The foundation-layer class stays target-agnostic.
|
|
562
|
+
*
|
|
563
|
+
* Constructed instances are frozen via `freezeNode(this)`; instance
|
|
564
|
+
* fields are JSON-clean by construction (`storageHash`, `collections`,
|
|
565
|
+
* `namespaces` all enumerable own properties). The persisted on-disk
|
|
566
|
+
* envelope shape is target-owned: `MongoTargetContractSerializer.serializeContract`
|
|
567
|
+
* decides whether `namespaces` round-trips through JSON or is stripped
|
|
568
|
+
* for the JSON envelope.
|
|
569
|
+
*/
|
|
570
|
+
var MongoStorage = class extends IRNodeBase {
|
|
571
|
+
kind = "mongo-storage";
|
|
572
|
+
storageHash;
|
|
573
|
+
collections;
|
|
574
|
+
namespaces;
|
|
575
|
+
constructor(input) {
|
|
576
|
+
super();
|
|
577
|
+
this.storageHash = input.storageHash;
|
|
578
|
+
this.collections = input.collections;
|
|
579
|
+
this.namespaces = input.namespaces;
|
|
580
|
+
freezeNode(this);
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
//#endregion
|
|
584
|
+
//#region src/polymorphic-index-scope.ts
|
|
585
|
+
function isScalarDiscriminatorValue(value) {
|
|
586
|
+
const t = typeof value;
|
|
587
|
+
return t === "string" || t === "number" || t === "boolean";
|
|
588
|
+
}
|
|
589
|
+
function formatValue(value) {
|
|
590
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
591
|
+
if (value === null) return "null";
|
|
592
|
+
if (Array.isArray(value)) return JSON.stringify(value);
|
|
593
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
594
|
+
return String(value);
|
|
595
|
+
}
|
|
596
|
+
function applyPolymorphicScopeToMongoIndex(index, scope) {
|
|
597
|
+
if (!isScalarDiscriminatorValue(scope.discriminatorValue)) return {
|
|
598
|
+
kind: "conflict",
|
|
599
|
+
reason: `Variant-scoped indexes require a scalar (string, number, or boolean) discriminator value for field "${scope.discriminatorField}", but received ${formatValue(scope.discriminatorValue)}.`
|
|
600
|
+
};
|
|
601
|
+
const existing = index.partialFilterExpression;
|
|
602
|
+
if (existing && Object.hasOwn(existing, scope.discriminatorField)) {
|
|
603
|
+
const existingValue = existing[scope.discriminatorField];
|
|
604
|
+
if (existingValue === scope.discriminatorValue) return {
|
|
605
|
+
kind: "ok",
|
|
606
|
+
index
|
|
607
|
+
};
|
|
608
|
+
return {
|
|
609
|
+
kind: "conflict",
|
|
610
|
+
reason: `Index partialFilterExpression sets "${scope.discriminatorField}" to ${formatValue(existingValue)}, which conflicts with the variant's discriminator value ${formatValue(scope.discriminatorValue)}.`
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
const merged = {
|
|
614
|
+
...existing ?? {},
|
|
615
|
+
[scope.discriminatorField]: scope.discriminatorValue
|
|
616
|
+
};
|
|
617
|
+
return {
|
|
618
|
+
kind: "ok",
|
|
619
|
+
index: new MongoIndex({
|
|
620
|
+
keys: index.keys,
|
|
621
|
+
...index.unique !== void 0 && { unique: index.unique },
|
|
622
|
+
...index.sparse !== void 0 && { sparse: index.sparse },
|
|
623
|
+
...index.expireAfterSeconds !== void 0 && { expireAfterSeconds: index.expireAfterSeconds },
|
|
624
|
+
partialFilterExpression: merged,
|
|
625
|
+
...index.wildcardProjection !== void 0 && { wildcardProjection: index.wildcardProjection },
|
|
626
|
+
...index.collation !== void 0 && { collation: index.collation },
|
|
627
|
+
...index.weights !== void 0 && { weights: index.weights },
|
|
628
|
+
...index.default_language !== void 0 && { default_language: index.default_language },
|
|
629
|
+
...index.language_override !== void 0 && { language_override: index.language_override }
|
|
630
|
+
})
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
//#endregion
|
|
287
634
|
//#region src/validate-storage.ts
|
|
288
635
|
function validateMongoStorage(contract) {
|
|
289
636
|
const errors = [];
|
|
@@ -313,31 +660,6 @@ function validateMongoStorage(contract) {
|
|
|
313
660
|
if (errors.length > 0) throw new Error(`Contract storage validation failed:\n- ${errors.join("\n- ")}`);
|
|
314
661
|
}
|
|
315
662
|
//#endregion
|
|
316
|
-
|
|
317
|
-
function validateMongoContract(value) {
|
|
318
|
-
const parsed = MongoContractSchema(value);
|
|
319
|
-
if (parsed instanceof type.errors) throw new Error(`Contract structural validation failed: ${parsed.summary}`);
|
|
320
|
-
const contract = parsed;
|
|
321
|
-
validateContractDomain(contract);
|
|
322
|
-
validateMongoStorage(contract);
|
|
323
|
-
return {
|
|
324
|
-
contract,
|
|
325
|
-
indices: buildIndices(contract)
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
function buildIndices(contract) {
|
|
329
|
-
const variantToBase = {};
|
|
330
|
-
const modelToVariants = {};
|
|
331
|
-
for (const [modelName, model] of Object.entries(contract.models)) {
|
|
332
|
-
if (model.base) variantToBase[modelName] = model.base;
|
|
333
|
-
if (model.variants) modelToVariants[modelName] = Object.keys(model.variants);
|
|
334
|
-
}
|
|
335
|
-
return {
|
|
336
|
-
variantToBase,
|
|
337
|
-
modelToVariants
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
//#endregion
|
|
341
|
-
export { applyPolymorphicScopeToMongoIndex, validateMongoContract, validateMongoStorage };
|
|
663
|
+
export { MongoChangeStreamPreAndPostImagesOptions, MongoClusteredCollectionOptions, MongoCollationOptions, MongoCollection, MongoCollectionOptions, MongoContractSchema, MongoIndex, MongoIndexOptionDefaults, MongoIndexOptions, MongoStorage, MongoTimeSeriesCollectionOptions, MongoValidator, applyPolymorphicScopeToMongoIndex, validateMongoStorage };
|
|
342
664
|
|
|
343
665
|
//# sourceMappingURL=index.mjs.map
|