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