@prisma-next/mongo-contract 0.11.0 → 0.12.0-dev.10
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 +22 -13
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +125 -97
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -8
- package/src/canonicalization-hooks.ts +27 -0
- package/src/contract-schema.ts +20 -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-collection.ts +4 -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, ControlPolicy, 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>;
|
|
@@ -349,6 +349,7 @@ interface MongoCollectionInput {
|
|
|
349
349
|
readonly indexes?: ReadonlyArray<MongoIndex | MongoIndexInput>;
|
|
350
350
|
readonly validator?: MongoValidator | MongoValidatorInput;
|
|
351
351
|
readonly options?: MongoCollectionOptions | MongoCollectionOptionsInput;
|
|
352
|
+
readonly control?: ControlPolicy;
|
|
352
353
|
}
|
|
353
354
|
/**
|
|
354
355
|
* Mongo Contract IR node for a single collection entry in a namespace's
|
|
@@ -375,6 +376,7 @@ declare class MongoCollection extends IRNodeBase {
|
|
|
375
376
|
readonly indexes?: ReadonlyArray<MongoIndex>;
|
|
376
377
|
readonly validator?: MongoValidator;
|
|
377
378
|
readonly options?: MongoCollectionOptions;
|
|
379
|
+
readonly control?: ControlPolicy;
|
|
378
380
|
constructor(input?: MongoCollectionInput);
|
|
379
381
|
}
|
|
380
382
|
//#endregion
|
|
@@ -482,6 +484,11 @@ type MongoStorageShape<THash extends string = string> = StorageBase<THash> & {
|
|
|
482
484
|
}>;
|
|
483
485
|
};
|
|
484
486
|
type MongoContract<S extends MongoStorageShape = MongoStorageShape, M extends Record<string, MongoModelDefinition> = Record<string, MongoModelDefinition>> = Contract<S, M>;
|
|
487
|
+
/** Model map inferred from a {@link MongoContract} (domain.namespaces union). */
|
|
488
|
+
type MongoModelsMap<TContract extends MongoContract> = ContractModelsMap<TContract>;
|
|
489
|
+
type RootModelName<TContract extends MongoContract, RootName extends keyof TContract['roots'] & string> = TContract['roots'][RootName] extends {
|
|
490
|
+
readonly model: infer M extends string;
|
|
491
|
+
} ? M & keyof _$_prisma_next_contract_types0.ContractModelsMap<TContract> : never;
|
|
485
492
|
type MongoTypeMaps<TCodecTypes extends Record<string, {
|
|
486
493
|
output: unknown;
|
|
487
494
|
}> = Record<string, {
|
|
@@ -505,9 +512,7 @@ type ExtractMongoFieldOutputTypes<T> = ExtractMongoTypeMaps<T> extends {
|
|
|
505
512
|
type ExtractMongoFieldInputTypes<T> = ExtractMongoTypeMaps<T> extends {
|
|
506
513
|
fieldInputTypes: infer F;
|
|
507
514
|
} ? 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>;
|
|
515
|
+
type ExtractValueObjects<TContract extends Contract> = ContractValueObjectsMap<TContract>;
|
|
511
516
|
type NormalizeContractFields<TFields> = { [K in keyof TFields]: TFields[K] extends ContractField ? TFields[K] : never };
|
|
512
517
|
type ExtractValueObjectFields<TValueObjects extends Record<string, ContractValueObject>, VOName extends keyof TValueObjects> = NormalizeContractFields<TValueObjects[VOName]['fields']>;
|
|
513
518
|
type InferFieldBaseType<TFieldType, TValueObjects extends Record<string, ContractValueObject>, TCodecTypes extends Record<string, {
|
|
@@ -527,7 +532,7 @@ type InferFieldType<TField, TValueObjects extends Record<string, ContractValueOb
|
|
|
527
532
|
}>> = TField extends ContractField ? TField extends {
|
|
528
533
|
many: true;
|
|
529
534
|
} ? 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
|
|
535
|
+
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
536
|
output: unknown;
|
|
532
537
|
}> = ExtractMongoCodecTypes<TContract>, TValueObjects extends Record<string, ContractValueObject> = ExtractValueObjects<TContract>> = { -readonly [FieldName in keyof TFields]: InferFieldType<TFields[FieldName], TValueObjects, TCodecTypes> };
|
|
533
538
|
//#endregion
|
|
@@ -536,13 +541,13 @@ interface MongoNamespaceCollectionsInput {
|
|
|
536
541
|
readonly id: string;
|
|
537
542
|
readonly collections?: Record<string, MongoCollection | MongoCollectionInput>;
|
|
538
543
|
}
|
|
539
|
-
interface MongoStorageInput<THash extends string = string> {
|
|
540
|
-
readonly storageHash: StorageHashBase<THash>;
|
|
541
|
-
readonly namespaces?: Readonly<Record<string, Namespace | MongoNamespaceCollectionsInput>>;
|
|
542
|
-
}
|
|
543
544
|
type MongoNamespace = Namespace & {
|
|
544
545
|
readonly collections: Readonly<Record<string, MongoCollection>>;
|
|
545
546
|
};
|
|
547
|
+
interface MongoStorageInput<THash extends string = string> {
|
|
548
|
+
readonly storageHash: StorageHashBase<THash>;
|
|
549
|
+
readonly namespaces: Readonly<Record<string, MongoNamespace>>;
|
|
550
|
+
}
|
|
546
551
|
declare class MongoStorage<THash extends string = string> extends IRNodeBase implements Storage {
|
|
547
552
|
readonly kind: 'mongo-storage';
|
|
548
553
|
readonly storageHash: StorageHashBase<THash>;
|
|
@@ -550,6 +555,10 @@ declare class MongoStorage<THash extends string = string> extends IRNodeBase imp
|
|
|
550
555
|
constructor(input: MongoStorageInput<THash>);
|
|
551
556
|
}
|
|
552
557
|
//#endregion
|
|
558
|
+
//#region src/ir/build-mongo-namespace.d.ts
|
|
559
|
+
declare function buildMongoNamespace(input: MongoNamespaceCollectionsInput): MongoNamespace;
|
|
560
|
+
declare function buildMongoNamespaceMap(namespaces: Readonly<Record<string, Namespace | MongoNamespaceCollectionsInput>>): Readonly<Record<string, MongoNamespace>>;
|
|
561
|
+
//#endregion
|
|
553
562
|
//#region src/ir/mongo-unbound-namespace.d.ts
|
|
554
563
|
declare class MongoUnboundNamespace extends NamespaceBase {
|
|
555
564
|
static readonly instance: MongoUnboundNamespace;
|
|
@@ -576,5 +585,5 @@ declare function applyPolymorphicScopeToMongoIndex(index: MongoIndex, scope: Pol
|
|
|
576
585
|
//#region src/validate-storage.d.ts
|
|
577
586
|
declare function validateMongoStorage(contract: MongoContract): void;
|
|
578
587
|
//#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 };
|
|
588
|
+
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
589
|
//# 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;;;;iBHqTjC,kCAAA,CACd,SAAA,GAAY,WAAA,SAAoB,IAAA,aAC/B,IAAA;;;;AIvWuC;AAa1C;iBJwWgB,yBAAA,CACd,SAAA,GAAY,WAAA,SAAoB,IAAA,aAC/B,IAAA;AAAA,cAkCU,mBAAA,EAAiD,SAAA,CAA9B,QAAA;;;UC3Zf,6CAAA;EAAA,SACN,OAAO;AAAA;;;;;ADsWlB;;;cC5Va,wCAAA,SAAiD,UAAU;EAAA,SAC7D,IAAA;EAAA,SACA,OAAA;cAEG,OAAA,EAAS,6CAAA;AAAA;;;KCfX,2BAAA,GAA8B,QAAQ,CAAC,MAAA;AAAA,UAElC,oCAAA;EAAA,SACN,IAAA;EAAA,SACA,GAAA,EAAK,2BAA2B;EAAA,SAChC,MAAA;AAAA;;AFkWX;;;;;;;cEvVa,+BAAA,SAAwC,UAAA;EAAA,SAC1C,IAAA;EAAA,SACQ,IAAA;EAAA,SACR,GAAA,EAAK,2BAAA;EAAA,SACL,MAAA;cAEG,OAAA,EAAS,oCAAA;AAAA;;;KCtBX,uBAAA;AAAA,KACA,sBAAA;AAAA,KACA,uBAAA;AA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B,mBAAA,CAAoB,KAAA,EAAO,8BAAA,GAAiC,cAAc;AAAA,iBAI1E,sBAAA,CACd,UAAA,EAAY,QAAA,CAAS,MAAA,SAAe,SAAA,GAAY,8BAAA,KAC/C,QAAA,CAAS,MAAA,SAAe,cAAA;;;cC5Dd,qBAAA,SAA8B,aAAA;EAAA,gBACzB,QAAA,EAAU,qBAAA;EAAA,SAEjB,EAAA;EAAA,SACA,WAAA,EAAa,QAAA,CAAS,MAAA,SAAe,eAAA;EAAA,SAC7B,IAAA;EAAA,QAEV,WAAA,CAAA;AAAA;;;KCZG,qBAAA;EAAA,SACD,kBAAA;EAAA,SACA,kBAAkB;AAAA;AAAA,KAGjB,gBAAA;EAAA,SACG,IAAA;EAAA,SAAqB,KAAA,EAAO,UAAU;AAAA;EAAA,SACtC,IAAA;EAAA,SAA2B,MAAA;AAAA;AAAA,iBAe1B,iCAAA,CACd,KAAA,EAAO,UAAA,EACP,KAAA,EAAO,qBAAA,GACN,gBAAA;;;iBCTa,oBAAA,CAAqB,QAAuB,EAAb,aAAa"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
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
|
|
6
|
+
const ControlPolicySchema = type("'managed' | 'tolerated' | 'external' | 'observed'");
|
|
4
7
|
const ScalarFieldTypeSchema = type({
|
|
5
8
|
"+": "reject",
|
|
6
9
|
kind: "'scalar'",
|
|
@@ -29,7 +32,7 @@ const FieldSchema = type({
|
|
|
29
32
|
}));
|
|
30
33
|
const RelationSchema = type({
|
|
31
34
|
"+": "reject",
|
|
32
|
-
to:
|
|
35
|
+
to: CrossReferenceSchema,
|
|
33
36
|
cardinality: "'1:1' | '1:N' | 'N:1'",
|
|
34
37
|
"on?": type({
|
|
35
38
|
"+": "reject",
|
|
@@ -144,7 +147,7 @@ const ModelDefinitionSchema = type({
|
|
|
144
147
|
"relations?": type({ "[string]": RelationSchema }),
|
|
145
148
|
"discriminator?": DiscriminatorSchema,
|
|
146
149
|
"variants?": type({ "[string]": VariantEntrySchema }),
|
|
147
|
-
"base?":
|
|
150
|
+
"base?": CrossReferenceSchema,
|
|
148
151
|
"owner?": "string"
|
|
149
152
|
});
|
|
150
153
|
type({
|
|
@@ -232,7 +235,8 @@ const StorageCollectionSchema = type({
|
|
|
232
235
|
"kind?": "'mongo-collection'",
|
|
233
236
|
"indexes?": MongoStorageIndexSchema.array(),
|
|
234
237
|
"validator?": MongoStorageValidatorSchema,
|
|
235
|
-
"options?": MongoCollectionOptionsSchema
|
|
238
|
+
"options?": MongoCollectionOptionsSchema,
|
|
239
|
+
"control?": ControlPolicySchema
|
|
236
240
|
});
|
|
237
241
|
function collectionEntrySchema(fragments) {
|
|
238
242
|
if (fragments === void 0 || fragments.size === 0) return StorageCollectionSchema;
|
|
@@ -259,8 +263,8 @@ function collectionEntrySchema(fragments) {
|
|
|
259
263
|
* has no pack contributions; the composition surface exists for symmetry
|
|
260
264
|
* with SQL and as the substrate for future entity kinds.
|
|
261
265
|
*
|
|
262
|
-
* `'kind?': 'string'` because `kind` is non-enumerable on
|
|
263
|
-
*
|
|
266
|
+
* `'kind?': 'string'` because `kind` is non-enumerable on built
|
|
267
|
+
* Mongo namespace IR classes and therefore absent from the wire shape; the
|
|
264
268
|
* type-side narrowing is enforced by the IR class, not by this validator.
|
|
265
269
|
*/
|
|
266
270
|
function createMongoNamespaceEnvelopeSchema(fragments) {
|
|
@@ -277,6 +281,7 @@ function createMongoNamespaceEnvelopeSchema(fragments) {
|
|
|
277
281
|
* the rest of the envelope is family-shared.
|
|
278
282
|
*/
|
|
279
283
|
function createMongoContractSchema(fragments) {
|
|
284
|
+
const namespaceEnvelope = createMongoNamespaceEnvelopeSchema(fragments);
|
|
280
285
|
return type({
|
|
281
286
|
"+": "reject",
|
|
282
287
|
targetFamily: "'mongo'",
|
|
@@ -284,23 +289,25 @@ function createMongoContractSchema(fragments) {
|
|
|
284
289
|
"target?": "string",
|
|
285
290
|
"storageHash?": "string",
|
|
286
291
|
"profileHash?": "string",
|
|
287
|
-
roots: "
|
|
292
|
+
roots: type({ "[string]": CrossReferenceSchema }),
|
|
288
293
|
"capabilities?": "Record<string, unknown>",
|
|
289
294
|
"extensionPacks?": "Record<string, unknown>",
|
|
290
295
|
"meta?": "Record<string, unknown>",
|
|
296
|
+
"defaultControl?": ControlPolicySchema,
|
|
291
297
|
"sources?": "Record<string, unknown>",
|
|
292
298
|
"_generated?": "Record<string, unknown>",
|
|
293
|
-
|
|
299
|
+
domain: type({ namespaces: type({ "[string]": type({
|
|
300
|
+
models: type({ "[string]": ModelDefinitionSchema }),
|
|
301
|
+
"valueObjects?": type({ "[string]": type({
|
|
302
|
+
"+": "reject",
|
|
303
|
+
fields: type({ "[string]": FieldSchema })
|
|
304
|
+
}) })
|
|
305
|
+
}) }) }),
|
|
294
306
|
storage: type({
|
|
295
307
|
"+": "reject",
|
|
296
|
-
namespaces: type({ "[string]":
|
|
308
|
+
namespaces: type({ "[string]": namespaceEnvelope }),
|
|
297
309
|
"storageHash?": "string"
|
|
298
|
-
})
|
|
299
|
-
models: type({ "[string]": ModelDefinitionSchema }),
|
|
300
|
-
"valueObjects?": type({ "[string]": type({
|
|
301
|
-
"+": "reject",
|
|
302
|
-
fields: type({ "[string]": FieldSchema })
|
|
303
|
-
}) })
|
|
310
|
+
})
|
|
304
311
|
});
|
|
305
312
|
}
|
|
306
313
|
const MongoContractSchema = createMongoContractSchema();
|
|
@@ -323,28 +330,6 @@ var MongoChangeStreamPreAndPostImagesOptions = class extends IRNodeBase {
|
|
|
323
330
|
}
|
|
324
331
|
};
|
|
325
332
|
//#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
333
|
//#region src/ir/mongo-collation-options.ts
|
|
349
334
|
/**
|
|
350
335
|
* Mongo Contract IR leaf for collection / index collation options.
|
|
@@ -552,6 +537,82 @@ var MongoCollection = class extends IRNodeBase {
|
|
|
552
537
|
if (input.indexes !== void 0) this.indexes = input.indexes.map((idx) => idx instanceof MongoIndex ? idx : new MongoIndex(idx));
|
|
553
538
|
if (input.validator !== void 0) this.validator = input.validator instanceof MongoValidator ? input.validator : new MongoValidator(input.validator);
|
|
554
539
|
if (input.options !== void 0) this.options = input.options instanceof MongoCollectionOptions ? input.options : new MongoCollectionOptions(input.options);
|
|
540
|
+
if (input.control !== void 0) this.control = input.control;
|
|
541
|
+
freezeNode(this);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
//#endregion
|
|
545
|
+
//#region src/ir/mongo-unbound-namespace.ts
|
|
546
|
+
var MongoUnboundNamespace = class MongoUnboundNamespace extends NamespaceBase {
|
|
547
|
+
static instance = new MongoUnboundNamespace();
|
|
548
|
+
id = UNBOUND_NAMESPACE_ID;
|
|
549
|
+
collections = Object.freeze({});
|
|
550
|
+
constructor() {
|
|
551
|
+
super();
|
|
552
|
+
Object.defineProperty(this, "kind", {
|
|
553
|
+
value: "mongo-namespace",
|
|
554
|
+
writable: false,
|
|
555
|
+
enumerable: false,
|
|
556
|
+
configurable: true
|
|
557
|
+
});
|
|
558
|
+
freezeNode(this);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region src/ir/build-mongo-namespace.ts
|
|
563
|
+
const MONGO_NAMESPACE_KIND = "mongo-namespace";
|
|
564
|
+
function isMaterializedMongoNamespace(ns) {
|
|
565
|
+
if (typeof ns !== "object" || ns === null) return false;
|
|
566
|
+
const proto = Object.getPrototypeOf(ns);
|
|
567
|
+
if (proto === Object.prototype || proto === null) return false;
|
|
568
|
+
return ns.kind === MONGO_NAMESPACE_KIND;
|
|
569
|
+
}
|
|
570
|
+
var MongoBoundNamespace = class MongoBoundNamespace extends NamespaceBase {
|
|
571
|
+
id;
|
|
572
|
+
collections;
|
|
573
|
+
static fromCollectionsInput(input) {
|
|
574
|
+
const collectionCount = Object.keys(input.collections ?? {}).length;
|
|
575
|
+
if (input.id === UNBOUND_NAMESPACE_ID && collectionCount === 0) return castAs(MongoUnboundNamespace.instance);
|
|
576
|
+
return castAs(new MongoBoundNamespace(input));
|
|
577
|
+
}
|
|
578
|
+
constructor(input) {
|
|
579
|
+
super();
|
|
580
|
+
this.id = input.id;
|
|
581
|
+
this.collections = Object.freeze(Object.fromEntries(Object.entries(input.collections ?? {}).map(([name, c]) => [name, c instanceof MongoCollection ? c : new MongoCollection(c)])));
|
|
582
|
+
Object.defineProperty(this, "kind", {
|
|
583
|
+
value: MONGO_NAMESPACE_KIND,
|
|
584
|
+
writable: false,
|
|
585
|
+
enumerable: false,
|
|
586
|
+
configurable: true
|
|
587
|
+
});
|
|
588
|
+
freezeNode(this);
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
function buildMongoNamespace(input) {
|
|
592
|
+
return MongoBoundNamespace.fromCollectionsInput(input);
|
|
593
|
+
}
|
|
594
|
+
function buildMongoNamespaceMap(namespaces) {
|
|
595
|
+
return Object.fromEntries(Object.entries(namespaces).map(([nsKey, ns]) => [nsKey, isMaterializedMongoNamespace(ns) ? blindCast(ns) : MongoBoundNamespace.fromCollectionsInput(ns)]));
|
|
596
|
+
}
|
|
597
|
+
//#endregion
|
|
598
|
+
//#region src/ir/mongo-clustered-collection-options.ts
|
|
599
|
+
/**
|
|
600
|
+
* Clustered-collection options (the `clusteredIndex` collection-creation
|
|
601
|
+
* field). Lifted from a `type =` data shape to an AST class extending
|
|
602
|
+
* `IRNodeBase` per FR18.
|
|
603
|
+
*
|
|
604
|
+
* MongoDB requires `key` and `unique` for any clustered collection; the
|
|
605
|
+
* constructor enforces presence by type signature.
|
|
606
|
+
*/
|
|
607
|
+
var MongoClusteredCollectionOptions = class extends IRNodeBase {
|
|
608
|
+
kind = "mongo-clustered-collection-options";
|
|
609
|
+
key;
|
|
610
|
+
unique;
|
|
611
|
+
constructor(options) {
|
|
612
|
+
super();
|
|
613
|
+
if (options.name !== void 0) this.name = options.name;
|
|
614
|
+
this.key = options.key;
|
|
615
|
+
this.unique = options.unique;
|
|
555
616
|
freezeNode(this);
|
|
556
617
|
}
|
|
557
618
|
};
|
|
@@ -592,48 +653,7 @@ var MongoIndexOptions = class extends IRNodeBase {
|
|
|
592
653
|
}
|
|
593
654
|
};
|
|
594
655
|
//#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
656
|
//#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
657
|
var MongoStorage = class extends IRNodeBase {
|
|
638
658
|
storageHash;
|
|
639
659
|
namespaces;
|
|
@@ -646,7 +666,7 @@ var MongoStorage = class extends IRNodeBase {
|
|
|
646
666
|
configurable: true
|
|
647
667
|
});
|
|
648
668
|
this.storageHash = input.storageHash;
|
|
649
|
-
this.namespaces = Object.freeze(
|
|
669
|
+
this.namespaces = Object.freeze(input.namespaces);
|
|
650
670
|
freezeNode(this);
|
|
651
671
|
}
|
|
652
672
|
};
|
|
@@ -702,31 +722,39 @@ function applyPolymorphicScopeToMongoIndex(index, scope) {
|
|
|
702
722
|
}
|
|
703
723
|
//#endregion
|
|
704
724
|
//#region src/validate-storage.ts
|
|
725
|
+
function formatCrossRef(crossRef) {
|
|
726
|
+
return `${crossRef.namespace}.${crossRef.model}`;
|
|
727
|
+
}
|
|
705
728
|
function storageDeclaresCollection(storage, collectionName) {
|
|
706
729
|
for (const ns of Object.values(storage.namespaces)) if (Object.hasOwn(ns.collections, collectionName)) return true;
|
|
707
730
|
return false;
|
|
708
731
|
}
|
|
709
732
|
function validateMongoStorage(contract) {
|
|
710
733
|
const errors = [];
|
|
711
|
-
for (const [
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
const
|
|
715
|
-
if (
|
|
716
|
-
|
|
717
|
-
const
|
|
718
|
-
if (
|
|
734
|
+
for (const [namespaceId, namespace] of Object.entries(contract.domain.namespaces)) {
|
|
735
|
+
const models = namespace.models;
|
|
736
|
+
for (const [modelName, model] of Object.entries(models)) {
|
|
737
|
+
const qualifiedName = `${namespaceId}:${modelName}`;
|
|
738
|
+
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`);
|
|
739
|
+
if (model.base) {
|
|
740
|
+
const baseModel = models[model.base.model];
|
|
741
|
+
if (baseModel) {
|
|
742
|
+
const variantCollection = model.storage.collection;
|
|
743
|
+
const baseCollection = baseModel.storage.collection;
|
|
744
|
+
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)"}"`);
|
|
745
|
+
}
|
|
719
746
|
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
747
|
+
for (const [relName, relation] of Object.entries(model.relations ?? {})) {
|
|
748
|
+
const targetModel = models[relation.to.model];
|
|
749
|
+
const targetLabel = formatCrossRef(relation.to);
|
|
750
|
+
if (targetModel?.owner) {
|
|
751
|
+
if (targetModel.owner !== modelName) errors.push(`Embed relation "${relName}" targets "${targetLabel}" which is owned by "${targetModel.owner}", not "${qualifiedName}"`);
|
|
752
|
+
if (targetModel.storage.collection) errors.push(`Embed relation "${relName}" targets "${targetLabel}" which must not have a collection`);
|
|
753
|
+
} else if ("on" in relation && relation.on) {
|
|
754
|
+
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}"`);
|
|
755
|
+
if (targetModel) {
|
|
756
|
+
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}"`);
|
|
757
|
+
}
|
|
730
758
|
}
|
|
731
759
|
}
|
|
732
760
|
}
|
|
@@ -734,6 +762,6 @@ function validateMongoStorage(contract) {
|
|
|
734
762
|
if (errors.length > 0) throw new Error(`Contract storage validation failed:\n- ${errors.join("\n- ")}`);
|
|
735
763
|
}
|
|
736
764
|
//#endregion
|
|
737
|
-
export { MongoChangeStreamPreAndPostImagesOptions, MongoClusteredCollectionOptions, MongoCollationOptions, MongoCollection, MongoCollectionOptions, MongoContractSchema, MongoIndex, MongoIndexOptionDefaults, MongoIndexOptions, MongoStorage, MongoTimeSeriesCollectionOptions, MongoUnboundNamespace, MongoValidator, applyPolymorphicScopeToMongoIndex, createMongoContractSchema, createMongoNamespaceEnvelopeSchema, validateMongoStorage };
|
|
765
|
+
export { MongoChangeStreamPreAndPostImagesOptions, MongoClusteredCollectionOptions, MongoCollationOptions, MongoCollection, MongoCollectionOptions, MongoContractSchema, MongoIndex, MongoIndexOptionDefaults, MongoIndexOptions, MongoStorage, MongoTimeSeriesCollectionOptions, MongoUnboundNamespace, MongoValidator, applyPolymorphicScopeToMongoIndex, buildMongoNamespace, buildMongoNamespaceMap, createMongoContractSchema, createMongoNamespaceEnvelopeSchema, validateMongoStorage };
|
|
738
766
|
|
|
739
767
|
//# sourceMappingURL=index.mjs.map
|