@prisma-next/mongo-contract 0.11.0 → 0.12.0
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/canonicalization-hooks.d.mts +9 -0
- package/dist/canonicalization-hooks.d.mts.map +1 -0
- package/dist/canonicalization-hooks.mjs +20 -0
- package/dist/canonicalization-hooks.mjs.map +1 -0
- package/dist/index.d.mts +20 -13
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +120 -96
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -8
- package/src/canonicalization-hooks.ts +27 -0
- package/src/contract-schema.ts +16 -10
- package/src/contract-types.ts +15 -7
- package/src/exports/canonicalization-hooks.ts +1 -0
- package/src/exports/index.ts +3 -0
- package/src/ir/build-mongo-namespace.ts +80 -0
- package/src/ir/mongo-storage.ts +7 -67
- package/src/validate-storage.ts +52 -45
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PreserveEmptyPredicate } from "@prisma-next/contract/hashing";
|
|
2
|
+
|
|
3
|
+
//#region src/canonicalization-hooks.d.ts
|
|
4
|
+
declare const mongoContractCanonicalizationHooks: {
|
|
5
|
+
readonly shouldPreserveEmpty: PreserveEmptyPredicate;
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { mongoContractCanonicalizationHooks };
|
|
9
|
+
//# sourceMappingURL=canonicalization-hooks.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonicalization-hooks.d.mts","names":[],"sources":["../src/canonicalization-hooks.ts"],"mappings":";;;cAsBa,kCAAA;EAAA,SACF,mBAAA,EAAqB,sBAAsB;AAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createPreserveEmptyPredicate } from "@prisma-next/contract/hashing-utils";
|
|
2
|
+
//#region src/canonicalization-hooks.ts
|
|
3
|
+
const matchesPreserveEmptyPattern = createPreserveEmptyPredicate([[
|
|
4
|
+
"storage",
|
|
5
|
+
"namespaces",
|
|
6
|
+
"*",
|
|
7
|
+
"collections"
|
|
8
|
+
], [
|
|
9
|
+
"storage",
|
|
10
|
+
"namespaces",
|
|
11
|
+
"*",
|
|
12
|
+
"collections",
|
|
13
|
+
"*"
|
|
14
|
+
]]);
|
|
15
|
+
const shouldPreserveEmpty = (path) => path[path.length - 1] === "additionalProperties" || matchesPreserveEmptyPattern(path);
|
|
16
|
+
const mongoContractCanonicalizationHooks = { shouldPreserveEmpty };
|
|
17
|
+
//#endregion
|
|
18
|
+
export { mongoContractCanonicalizationHooks };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=canonicalization-hooks.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonicalization-hooks.mjs","names":[],"sources":["../src/canonicalization-hooks.ts"],"sourcesContent":["import type { PreserveEmptyPredicate } from '@prisma-next/contract/hashing';\nimport {\n createPreserveEmptyPredicate,\n type PathPattern,\n} from '@prisma-next/contract/hashing-utils';\n\nconst preserveEmptyPatterns = [\n ['storage', 'namespaces', '*', 'collections'],\n ['storage', 'namespaces', '*', 'collections', '*'],\n] as const satisfies readonly PathPattern[];\n\nconst matchesPreserveEmptyPattern = createPreserveEmptyPredicate(preserveEmptyPatterns);\n\n// `additionalProperties: false` is the closed-schema marker on a Mongo\n// `$jsonSchema` validator. It is injected at every object level — top-level\n// collections, nested embedded value objects, and each polymorphic `oneOf`\n// branch — so it appears at an unbounded set of paths that fixed-length path\n// patterns cannot enumerate. It is a meaningful constraint rather than an\n// omittable default, so preserve it wherever it occurs in a Mongo contract.\nconst shouldPreserveEmpty: PreserveEmptyPredicate = (path) =>\n path[path.length - 1] === 'additionalProperties' || matchesPreserveEmptyPattern(path);\n\nexport const mongoContractCanonicalizationHooks: {\n readonly shouldPreserveEmpty: PreserveEmptyPredicate;\n} = {\n shouldPreserveEmpty,\n};\n"],"mappings":";;AAWA,MAAM,8BAA8B,6BAA6B,CAJ/D;CAAC;CAAW;CAAc;CAAK;AAAa,GAC5C;CAAC;CAAW;CAAc;CAAK;CAAe;AAAG,CAGkC,CAAC;AAQtF,MAAM,uBAA+C,SACnD,KAAK,KAAK,SAAS,OAAO,0BAA0B,4BAA4B,IAAI;AAEtF,MAAa,qCAET,EACF,oBACF"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import * as _$_prisma_next_contract_types0 from "@prisma-next/contract/types";
|
|
2
|
+
import { Contract, ContractField, ContractModel, ContractModelsMap, ContractValueObject, ContractValueObjectsMap, StorageBase, StorageHashBase } from "@prisma-next/contract/types";
|
|
1
3
|
import * as _$arktype from "arktype";
|
|
2
4
|
import { Type } from "arktype";
|
|
3
5
|
import { IRNodeBase, Namespace, NamespaceBase, Storage } from "@prisma-next/framework-components/ir";
|
|
4
|
-
import { Contract, ContractField, ContractModel, ContractValueObject, StorageBase, StorageHashBase } from "@prisma-next/contract/types";
|
|
5
|
-
|
|
6
6
|
//#region src/contract-schema.d.ts
|
|
7
7
|
/**
|
|
8
8
|
* Builds the per-namespace envelope schema for Mongo storage. Pack
|
|
@@ -11,8 +11,8 @@ import { Contract, ContractField, ContractModel, ContractValueObject, StorageBas
|
|
|
11
11
|
* has no pack contributions; the composition surface exists for symmetry
|
|
12
12
|
* with SQL and as the substrate for future entity kinds.
|
|
13
13
|
*
|
|
14
|
-
* `'kind?': 'string'` because `kind` is non-enumerable on
|
|
15
|
-
*
|
|
14
|
+
* `'kind?': 'string'` because `kind` is non-enumerable on built
|
|
15
|
+
* Mongo namespace IR classes and therefore absent from the wire shape; the
|
|
16
16
|
* type-side narrowing is enforced by the IR class, not by this validator.
|
|
17
17
|
*/
|
|
18
18
|
declare function createMongoNamespaceEnvelopeSchema(fragments?: ReadonlyMap<string, Type<unknown>>): Type<unknown>;
|
|
@@ -482,6 +482,11 @@ type MongoStorageShape<THash extends string = string> = StorageBase<THash> & {
|
|
|
482
482
|
}>;
|
|
483
483
|
};
|
|
484
484
|
type MongoContract<S extends MongoStorageShape = MongoStorageShape, M extends Record<string, MongoModelDefinition> = Record<string, MongoModelDefinition>> = Contract<S, M>;
|
|
485
|
+
/** Model map inferred from a {@link MongoContract} (domain.namespaces union). */
|
|
486
|
+
type MongoModelsMap<TContract extends MongoContract> = ContractModelsMap<TContract>;
|
|
487
|
+
type RootModelName<TContract extends MongoContract, RootName extends keyof TContract['roots'] & string> = TContract['roots'][RootName] extends {
|
|
488
|
+
readonly model: infer M extends string;
|
|
489
|
+
} ? M & keyof _$_prisma_next_contract_types0.ContractModelsMap<TContract> : never;
|
|
485
490
|
type MongoTypeMaps<TCodecTypes extends Record<string, {
|
|
486
491
|
output: unknown;
|
|
487
492
|
}> = Record<string, {
|
|
@@ -505,9 +510,7 @@ type ExtractMongoFieldOutputTypes<T> = ExtractMongoTypeMaps<T> extends {
|
|
|
505
510
|
type ExtractMongoFieldInputTypes<T> = ExtractMongoTypeMaps<T> extends {
|
|
506
511
|
fieldInputTypes: infer F;
|
|
507
512
|
} ? F extends Record<string, Record<string, unknown>> ? F : Record<string, never> : Record<string, never>;
|
|
508
|
-
type ExtractValueObjects<TContract> = TContract
|
|
509
|
-
valueObjects: infer VO extends Record<string, ContractValueObject>;
|
|
510
|
-
} ? VO : Record<never, never>;
|
|
513
|
+
type ExtractValueObjects<TContract extends Contract> = ContractValueObjectsMap<TContract>;
|
|
511
514
|
type NormalizeContractFields<TFields> = { [K in keyof TFields]: TFields[K] extends ContractField ? TFields[K] : never };
|
|
512
515
|
type ExtractValueObjectFields<TValueObjects extends Record<string, ContractValueObject>, VOName extends keyof TValueObjects> = NormalizeContractFields<TValueObjects[VOName]['fields']>;
|
|
513
516
|
type InferFieldBaseType<TFieldType, TValueObjects extends Record<string, ContractValueObject>, TCodecTypes extends Record<string, {
|
|
@@ -527,7 +530,7 @@ type InferFieldType<TField, TValueObjects extends Record<string, ContractValueOb
|
|
|
527
530
|
}>> = TField extends ContractField ? TField extends {
|
|
528
531
|
many: true;
|
|
529
532
|
} ? TField['nullable'] extends true ? InferFieldBaseType<TField['type'], TValueObjects, TCodecTypes>[] | null : InferFieldBaseType<TField['type'], TValueObjects, TCodecTypes>[] : TField['nullable'] extends true ? InferFieldBaseType<TField['type'], TValueObjects, TCodecTypes> | null : InferFieldBaseType<TField['type'], TValueObjects, TCodecTypes> : never;
|
|
530
|
-
type InferModelRow<TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>, ModelName extends string & keyof TContract
|
|
533
|
+
type InferModelRow<TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>, ModelName extends string & keyof ContractModelsMap<TContract>, TFields extends Record<string, ContractField> = ContractModelsMap<TContract>[ModelName]['fields'], TCodecTypes extends Record<string, {
|
|
531
534
|
output: unknown;
|
|
532
535
|
}> = ExtractMongoCodecTypes<TContract>, TValueObjects extends Record<string, ContractValueObject> = ExtractValueObjects<TContract>> = { -readonly [FieldName in keyof TFields]: InferFieldType<TFields[FieldName], TValueObjects, TCodecTypes> };
|
|
533
536
|
//#endregion
|
|
@@ -536,13 +539,13 @@ interface MongoNamespaceCollectionsInput {
|
|
|
536
539
|
readonly id: string;
|
|
537
540
|
readonly collections?: Record<string, MongoCollection | MongoCollectionInput>;
|
|
538
541
|
}
|
|
539
|
-
interface MongoStorageInput<THash extends string = string> {
|
|
540
|
-
readonly storageHash: StorageHashBase<THash>;
|
|
541
|
-
readonly namespaces?: Readonly<Record<string, Namespace | MongoNamespaceCollectionsInput>>;
|
|
542
|
-
}
|
|
543
542
|
type MongoNamespace = Namespace & {
|
|
544
543
|
readonly collections: Readonly<Record<string, MongoCollection>>;
|
|
545
544
|
};
|
|
545
|
+
interface MongoStorageInput<THash extends string = string> {
|
|
546
|
+
readonly storageHash: StorageHashBase<THash>;
|
|
547
|
+
readonly namespaces: Readonly<Record<string, MongoNamespace>>;
|
|
548
|
+
}
|
|
546
549
|
declare class MongoStorage<THash extends string = string> extends IRNodeBase implements Storage {
|
|
547
550
|
readonly kind: 'mongo-storage';
|
|
548
551
|
readonly storageHash: StorageHashBase<THash>;
|
|
@@ -550,6 +553,10 @@ declare class MongoStorage<THash extends string = string> extends IRNodeBase imp
|
|
|
550
553
|
constructor(input: MongoStorageInput<THash>);
|
|
551
554
|
}
|
|
552
555
|
//#endregion
|
|
556
|
+
//#region src/ir/build-mongo-namespace.d.ts
|
|
557
|
+
declare function buildMongoNamespace(input: MongoNamespaceCollectionsInput): MongoNamespace;
|
|
558
|
+
declare function buildMongoNamespaceMap(namespaces: Readonly<Record<string, Namespace | MongoNamespaceCollectionsInput>>): Readonly<Record<string, MongoNamespace>>;
|
|
559
|
+
//#endregion
|
|
553
560
|
//#region src/ir/mongo-unbound-namespace.d.ts
|
|
554
561
|
declare class MongoUnboundNamespace extends NamespaceBase {
|
|
555
562
|
static readonly instance: MongoUnboundNamespace;
|
|
@@ -576,5 +583,5 @@ declare function applyPolymorphicScopeToMongoIndex(index: MongoIndex, scope: Pol
|
|
|
576
583
|
//#region src/validate-storage.d.ts
|
|
577
584
|
declare function validateMongoStorage(contract: MongoContract): void;
|
|
578
585
|
//#endregion
|
|
579
|
-
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, MongoUnboundNamespace, MongoValidator, type MongoValidatorInput, type MongoValidatorValidationAction, type MongoValidatorValidationLevel, type MongoWildcardProjection, type PolymorphicIndexScope, applyPolymorphicScopeToMongoIndex, createMongoContractSchema, createMongoNamespaceEnvelopeSchema, validateMongoStorage };
|
|
586
|
+
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, type MongoModelsMap, MongoStorage, type MongoStorageCappedShape, type MongoStorageClusteredIndexShape, type MongoStorageInput, type MongoStorageShape, MongoTimeSeriesCollectionOptions, type MongoTimeSeriesCollectionOptionsInput, type MongoTimeSeriesGranularity, type MongoTypeMaps, type MongoTypeMapsPhantomKey, MongoUnboundNamespace, MongoValidator, type MongoValidatorInput, type MongoValidatorValidationAction, type MongoValidatorValidationLevel, type MongoWildcardProjection, type PolymorphicIndexScope, type RootModelName, applyPolymorphicScopeToMongoIndex, buildMongoNamespace, buildMongoNamespaceMap, createMongoContractSchema, createMongoNamespaceEnvelopeSchema, validateMongoStorage };
|
|
580
587
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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/ir/mongo-unbound-namespace.ts","../src/polymorphic-index-scope.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/ir/build-mongo-namespace.ts","../src/ir/mongo-unbound-namespace.ts","../src/polymorphic-index-scope.ts","../src/validate-storage.ts"],"mappings":";;;;;;;;;;;;;AGoDiD;;;;iBHkTjC,kCAAA,CACd,SAAA,GAAY,WAAA,SAAoB,IAAA,aA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,aAAa"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { CrossReferenceSchema } from "@prisma-next/contract/types";
|
|
1
2
|
import { type } from "arktype";
|
|
2
3
|
import { IRNodeBase, NamespaceBase, UNBOUND_NAMESPACE_ID, freezeNode } from "@prisma-next/framework-components/ir";
|
|
4
|
+
import { blindCast, castAs } from "@prisma-next/utils/casts";
|
|
3
5
|
//#region src/contract-schema.ts
|
|
4
6
|
const ScalarFieldTypeSchema = type({
|
|
5
7
|
"+": "reject",
|
|
@@ -29,7 +31,7 @@ const FieldSchema = type({
|
|
|
29
31
|
}));
|
|
30
32
|
const RelationSchema = type({
|
|
31
33
|
"+": "reject",
|
|
32
|
-
to:
|
|
34
|
+
to: CrossReferenceSchema,
|
|
33
35
|
cardinality: "'1:1' | '1:N' | 'N:1'",
|
|
34
36
|
"on?": type({
|
|
35
37
|
"+": "reject",
|
|
@@ -144,7 +146,7 @@ const ModelDefinitionSchema = type({
|
|
|
144
146
|
"relations?": type({ "[string]": RelationSchema }),
|
|
145
147
|
"discriminator?": DiscriminatorSchema,
|
|
146
148
|
"variants?": type({ "[string]": VariantEntrySchema }),
|
|
147
|
-
"base?":
|
|
149
|
+
"base?": CrossReferenceSchema,
|
|
148
150
|
"owner?": "string"
|
|
149
151
|
});
|
|
150
152
|
type({
|
|
@@ -259,8 +261,8 @@ function collectionEntrySchema(fragments) {
|
|
|
259
261
|
* has no pack contributions; the composition surface exists for symmetry
|
|
260
262
|
* with SQL and as the substrate for future entity kinds.
|
|
261
263
|
*
|
|
262
|
-
* `'kind?': 'string'` because `kind` is non-enumerable on
|
|
263
|
-
*
|
|
264
|
+
* `'kind?': 'string'` because `kind` is non-enumerable on built
|
|
265
|
+
* Mongo namespace IR classes and therefore absent from the wire shape; the
|
|
264
266
|
* type-side narrowing is enforced by the IR class, not by this validator.
|
|
265
267
|
*/
|
|
266
268
|
function createMongoNamespaceEnvelopeSchema(fragments) {
|
|
@@ -277,6 +279,7 @@ function createMongoNamespaceEnvelopeSchema(fragments) {
|
|
|
277
279
|
* the rest of the envelope is family-shared.
|
|
278
280
|
*/
|
|
279
281
|
function createMongoContractSchema(fragments) {
|
|
282
|
+
const namespaceEnvelope = createMongoNamespaceEnvelopeSchema(fragments);
|
|
280
283
|
return type({
|
|
281
284
|
"+": "reject",
|
|
282
285
|
targetFamily: "'mongo'",
|
|
@@ -284,23 +287,24 @@ function createMongoContractSchema(fragments) {
|
|
|
284
287
|
"target?": "string",
|
|
285
288
|
"storageHash?": "string",
|
|
286
289
|
"profileHash?": "string",
|
|
287
|
-
roots: "
|
|
290
|
+
roots: type({ "[string]": CrossReferenceSchema }),
|
|
288
291
|
"capabilities?": "Record<string, unknown>",
|
|
289
292
|
"extensionPacks?": "Record<string, unknown>",
|
|
290
293
|
"meta?": "Record<string, unknown>",
|
|
291
294
|
"sources?": "Record<string, unknown>",
|
|
292
295
|
"_generated?": "Record<string, unknown>",
|
|
293
|
-
|
|
296
|
+
domain: type({ namespaces: type({ "[string]": type({
|
|
297
|
+
models: type({ "[string]": ModelDefinitionSchema }),
|
|
298
|
+
"valueObjects?": type({ "[string]": type({
|
|
299
|
+
"+": "reject",
|
|
300
|
+
fields: type({ "[string]": FieldSchema })
|
|
301
|
+
}) })
|
|
302
|
+
}) }) }),
|
|
294
303
|
storage: type({
|
|
295
304
|
"+": "reject",
|
|
296
|
-
namespaces: type({ "[string]":
|
|
305
|
+
namespaces: type({ "[string]": namespaceEnvelope }),
|
|
297
306
|
"storageHash?": "string"
|
|
298
|
-
})
|
|
299
|
-
models: type({ "[string]": ModelDefinitionSchema }),
|
|
300
|
-
"valueObjects?": type({ "[string]": type({
|
|
301
|
-
"+": "reject",
|
|
302
|
-
fields: type({ "[string]": FieldSchema })
|
|
303
|
-
}) })
|
|
307
|
+
})
|
|
304
308
|
});
|
|
305
309
|
}
|
|
306
310
|
const MongoContractSchema = createMongoContractSchema();
|
|
@@ -323,28 +327,6 @@ var MongoChangeStreamPreAndPostImagesOptions = class extends IRNodeBase {
|
|
|
323
327
|
}
|
|
324
328
|
};
|
|
325
329
|
//#endregion
|
|
326
|
-
//#region src/ir/mongo-clustered-collection-options.ts
|
|
327
|
-
/**
|
|
328
|
-
* Clustered-collection options (the `clusteredIndex` collection-creation
|
|
329
|
-
* field). Lifted from a `type =` data shape to an AST class extending
|
|
330
|
-
* `IRNodeBase` per FR18.
|
|
331
|
-
*
|
|
332
|
-
* MongoDB requires `key` and `unique` for any clustered collection; the
|
|
333
|
-
* constructor enforces presence by type signature.
|
|
334
|
-
*/
|
|
335
|
-
var MongoClusteredCollectionOptions = class extends IRNodeBase {
|
|
336
|
-
kind = "mongo-clustered-collection-options";
|
|
337
|
-
key;
|
|
338
|
-
unique;
|
|
339
|
-
constructor(options) {
|
|
340
|
-
super();
|
|
341
|
-
if (options.name !== void 0) this.name = options.name;
|
|
342
|
-
this.key = options.key;
|
|
343
|
-
this.unique = options.unique;
|
|
344
|
-
freezeNode(this);
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
//#endregion
|
|
348
330
|
//#region src/ir/mongo-collation-options.ts
|
|
349
331
|
/**
|
|
350
332
|
* Mongo Contract IR leaf for collection / index collation options.
|
|
@@ -556,6 +538,81 @@ var MongoCollection = class extends IRNodeBase {
|
|
|
556
538
|
}
|
|
557
539
|
};
|
|
558
540
|
//#endregion
|
|
541
|
+
//#region src/ir/mongo-unbound-namespace.ts
|
|
542
|
+
var MongoUnboundNamespace = class MongoUnboundNamespace extends NamespaceBase {
|
|
543
|
+
static instance = new MongoUnboundNamespace();
|
|
544
|
+
id = UNBOUND_NAMESPACE_ID;
|
|
545
|
+
collections = Object.freeze({});
|
|
546
|
+
constructor() {
|
|
547
|
+
super();
|
|
548
|
+
Object.defineProperty(this, "kind", {
|
|
549
|
+
value: "mongo-namespace",
|
|
550
|
+
writable: false,
|
|
551
|
+
enumerable: false,
|
|
552
|
+
configurable: true
|
|
553
|
+
});
|
|
554
|
+
freezeNode(this);
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
//#endregion
|
|
558
|
+
//#region src/ir/build-mongo-namespace.ts
|
|
559
|
+
const MONGO_NAMESPACE_KIND = "mongo-namespace";
|
|
560
|
+
function isMaterializedMongoNamespace(ns) {
|
|
561
|
+
if (typeof ns !== "object" || ns === null) return false;
|
|
562
|
+
const proto = Object.getPrototypeOf(ns);
|
|
563
|
+
if (proto === Object.prototype || proto === null) return false;
|
|
564
|
+
return ns.kind === MONGO_NAMESPACE_KIND;
|
|
565
|
+
}
|
|
566
|
+
var MongoBoundNamespace = class MongoBoundNamespace extends NamespaceBase {
|
|
567
|
+
id;
|
|
568
|
+
collections;
|
|
569
|
+
static fromCollectionsInput(input) {
|
|
570
|
+
const collectionCount = Object.keys(input.collections ?? {}).length;
|
|
571
|
+
if (input.id === UNBOUND_NAMESPACE_ID && collectionCount === 0) return castAs(MongoUnboundNamespace.instance);
|
|
572
|
+
return castAs(new MongoBoundNamespace(input));
|
|
573
|
+
}
|
|
574
|
+
constructor(input) {
|
|
575
|
+
super();
|
|
576
|
+
this.id = input.id;
|
|
577
|
+
this.collections = Object.freeze(Object.fromEntries(Object.entries(input.collections ?? {}).map(([name, c]) => [name, c instanceof MongoCollection ? c : new MongoCollection(c)])));
|
|
578
|
+
Object.defineProperty(this, "kind", {
|
|
579
|
+
value: MONGO_NAMESPACE_KIND,
|
|
580
|
+
writable: false,
|
|
581
|
+
enumerable: false,
|
|
582
|
+
configurable: true
|
|
583
|
+
});
|
|
584
|
+
freezeNode(this);
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
function buildMongoNamespace(input) {
|
|
588
|
+
return MongoBoundNamespace.fromCollectionsInput(input);
|
|
589
|
+
}
|
|
590
|
+
function buildMongoNamespaceMap(namespaces) {
|
|
591
|
+
return Object.fromEntries(Object.entries(namespaces).map(([nsKey, ns]) => [nsKey, isMaterializedMongoNamespace(ns) ? blindCast(ns) : MongoBoundNamespace.fromCollectionsInput(ns)]));
|
|
592
|
+
}
|
|
593
|
+
//#endregion
|
|
594
|
+
//#region src/ir/mongo-clustered-collection-options.ts
|
|
595
|
+
/**
|
|
596
|
+
* Clustered-collection options (the `clusteredIndex` collection-creation
|
|
597
|
+
* field). Lifted from a `type =` data shape to an AST class extending
|
|
598
|
+
* `IRNodeBase` per FR18.
|
|
599
|
+
*
|
|
600
|
+
* MongoDB requires `key` and `unique` for any clustered collection; the
|
|
601
|
+
* constructor enforces presence by type signature.
|
|
602
|
+
*/
|
|
603
|
+
var MongoClusteredCollectionOptions = class extends IRNodeBase {
|
|
604
|
+
kind = "mongo-clustered-collection-options";
|
|
605
|
+
key;
|
|
606
|
+
unique;
|
|
607
|
+
constructor(options) {
|
|
608
|
+
super();
|
|
609
|
+
if (options.name !== void 0) this.name = options.name;
|
|
610
|
+
this.key = options.key;
|
|
611
|
+
this.unique = options.unique;
|
|
612
|
+
freezeNode(this);
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
//#endregion
|
|
559
616
|
//#region src/ir/mongo-index-options.ts
|
|
560
617
|
/**
|
|
561
618
|
* Mongo Contract IR node for the per-index option vocabulary (the second
|
|
@@ -592,48 +649,7 @@ var MongoIndexOptions = class extends IRNodeBase {
|
|
|
592
649
|
}
|
|
593
650
|
};
|
|
594
651
|
//#endregion
|
|
595
|
-
//#region src/ir/mongo-unbound-namespace.ts
|
|
596
|
-
var MongoUnboundNamespace = class MongoUnboundNamespace extends NamespaceBase {
|
|
597
|
-
static instance = new MongoUnboundNamespace();
|
|
598
|
-
id = UNBOUND_NAMESPACE_ID;
|
|
599
|
-
collections = Object.freeze({});
|
|
600
|
-
constructor() {
|
|
601
|
-
super();
|
|
602
|
-
Object.defineProperty(this, "kind", {
|
|
603
|
-
value: "mongo-namespace",
|
|
604
|
-
writable: false,
|
|
605
|
-
enumerable: false,
|
|
606
|
-
configurable: true
|
|
607
|
-
});
|
|
608
|
-
freezeNode(this);
|
|
609
|
-
}
|
|
610
|
-
};
|
|
611
|
-
//#endregion
|
|
612
652
|
//#region src/ir/mongo-storage.ts
|
|
613
|
-
const DEFAULT_NAMESPACES = Object.freeze({ [UNBOUND_NAMESPACE_ID]: MongoUnboundNamespace.instance });
|
|
614
|
-
var MongoNamespacePayload = class extends NamespaceBase {
|
|
615
|
-
id;
|
|
616
|
-
collections;
|
|
617
|
-
constructor(input) {
|
|
618
|
-
super();
|
|
619
|
-
this.id = input.id;
|
|
620
|
-
this.collections = Object.freeze(Object.fromEntries(Object.entries(input.collections ?? {}).map(([name, c]) => [name, c instanceof MongoCollection ? c : new MongoCollection(c)])));
|
|
621
|
-
Object.defineProperty(this, "kind", {
|
|
622
|
-
value: "mongo-namespace",
|
|
623
|
-
writable: false,
|
|
624
|
-
enumerable: false,
|
|
625
|
-
configurable: true
|
|
626
|
-
});
|
|
627
|
-
freezeNode(this);
|
|
628
|
-
}
|
|
629
|
-
};
|
|
630
|
-
function normaliseNamespaceEntry(nsKey, ns) {
|
|
631
|
-
if (ns instanceof NamespaceBase) return ns;
|
|
632
|
-
const input = ns;
|
|
633
|
-
const collectionCount = Object.keys(input.collections ?? {}).length;
|
|
634
|
-
if (nsKey === UNBOUND_NAMESPACE_ID && collectionCount === 0) return MongoUnboundNamespace.instance;
|
|
635
|
-
return new MongoNamespacePayload(input);
|
|
636
|
-
}
|
|
637
653
|
var MongoStorage = class extends IRNodeBase {
|
|
638
654
|
storageHash;
|
|
639
655
|
namespaces;
|
|
@@ -646,7 +662,7 @@ var MongoStorage = class extends IRNodeBase {
|
|
|
646
662
|
configurable: true
|
|
647
663
|
});
|
|
648
664
|
this.storageHash = input.storageHash;
|
|
649
|
-
this.namespaces = Object.freeze(
|
|
665
|
+
this.namespaces = Object.freeze(input.namespaces);
|
|
650
666
|
freezeNode(this);
|
|
651
667
|
}
|
|
652
668
|
};
|
|
@@ -702,31 +718,39 @@ function applyPolymorphicScopeToMongoIndex(index, scope) {
|
|
|
702
718
|
}
|
|
703
719
|
//#endregion
|
|
704
720
|
//#region src/validate-storage.ts
|
|
721
|
+
function formatCrossRef(crossRef) {
|
|
722
|
+
return `${crossRef.namespace}.${crossRef.model}`;
|
|
723
|
+
}
|
|
705
724
|
function storageDeclaresCollection(storage, collectionName) {
|
|
706
725
|
for (const ns of Object.values(storage.namespaces)) if (Object.hasOwn(ns.collections, collectionName)) return true;
|
|
707
726
|
return false;
|
|
708
727
|
}
|
|
709
728
|
function validateMongoStorage(contract) {
|
|
710
729
|
const errors = [];
|
|
711
|
-
for (const [
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
const
|
|
715
|
-
if (
|
|
716
|
-
|
|
717
|
-
const
|
|
718
|
-
if (
|
|
730
|
+
for (const [namespaceId, namespace] of Object.entries(contract.domain.namespaces)) {
|
|
731
|
+
const models = namespace.models;
|
|
732
|
+
for (const [modelName, model] of Object.entries(models)) {
|
|
733
|
+
const qualifiedName = `${namespaceId}:${modelName}`;
|
|
734
|
+
if (model.storage.collection && !storageDeclaresCollection(contract.storage, model.storage.collection)) errors.push(`Model "${qualifiedName}" references collection "${model.storage.collection}" which is not declared under any namespace's collections map`);
|
|
735
|
+
if (model.base) {
|
|
736
|
+
const baseModel = models[model.base.model];
|
|
737
|
+
if (baseModel) {
|
|
738
|
+
const variantCollection = model.storage.collection;
|
|
739
|
+
const baseCollection = baseModel.storage.collection;
|
|
740
|
+
if (variantCollection !== baseCollection) errors.push(`Mongo does not support multi-table inheritance; variant "${qualifiedName}" must share its base's collection ("${baseCollection ?? "(none)"}"), but has "${variantCollection ?? "(none)"}"`);
|
|
741
|
+
}
|
|
719
742
|
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
743
|
+
for (const [relName, relation] of Object.entries(model.relations ?? {})) {
|
|
744
|
+
const targetModel = models[relation.to.model];
|
|
745
|
+
const targetLabel = formatCrossRef(relation.to);
|
|
746
|
+
if (targetModel?.owner) {
|
|
747
|
+
if (targetModel.owner !== modelName) errors.push(`Embed relation "${relName}" targets "${targetLabel}" which is owned by "${targetModel.owner}", not "${qualifiedName}"`);
|
|
748
|
+
if (targetModel.storage.collection) errors.push(`Embed relation "${relName}" targets "${targetLabel}" which must not have a collection`);
|
|
749
|
+
} else if ("on" in relation && relation.on) {
|
|
750
|
+
for (const localField of relation.on.localFields) if (!(localField in model.fields)) errors.push(`Reference relation "${relName}": localField "${localField}" is not a field on model "${qualifiedName}"`);
|
|
751
|
+
if (targetModel) {
|
|
752
|
+
for (const targetField of relation.on.targetFields) if (!(targetField in targetModel.fields)) errors.push(`Reference relation "${relName}": targetField "${targetField}" is not a field on model "${targetLabel}"`);
|
|
753
|
+
}
|
|
730
754
|
}
|
|
731
755
|
}
|
|
732
756
|
}
|
|
@@ -734,6 +758,6 @@ function validateMongoStorage(contract) {
|
|
|
734
758
|
if (errors.length > 0) throw new Error(`Contract storage validation failed:\n- ${errors.join("\n- ")}`);
|
|
735
759
|
}
|
|
736
760
|
//#endregion
|
|
737
|
-
export { MongoChangeStreamPreAndPostImagesOptions, MongoClusteredCollectionOptions, MongoCollationOptions, MongoCollection, MongoCollectionOptions, MongoContractSchema, MongoIndex, MongoIndexOptionDefaults, MongoIndexOptions, MongoStorage, MongoTimeSeriesCollectionOptions, MongoUnboundNamespace, MongoValidator, applyPolymorphicScopeToMongoIndex, createMongoContractSchema, createMongoNamespaceEnvelopeSchema, validateMongoStorage };
|
|
761
|
+
export { MongoChangeStreamPreAndPostImagesOptions, MongoClusteredCollectionOptions, MongoCollationOptions, MongoCollection, MongoCollectionOptions, MongoContractSchema, MongoIndex, MongoIndexOptionDefaults, MongoIndexOptions, MongoStorage, MongoTimeSeriesCollectionOptions, MongoUnboundNamespace, MongoValidator, applyPolymorphicScopeToMongoIndex, buildMongoNamespace, buildMongoNamespaceMap, createMongoContractSchema, createMongoNamespaceEnvelopeSchema, validateMongoStorage };
|
|
738
762
|
|
|
739
763
|
//# sourceMappingURL=index.mjs.map
|