@prisma/orm-family-mongo 0.16.0-dev.36
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/LICENSE +201 -0
- package/README.md +27 -0
- package/dist/authoring-entity-types-BGtkMyoN-D32kzx28.mjs +176 -0
- package/dist/authoring-entity-types-BGtkMyoN-D32kzx28.mjs.map +1 -0
- package/dist/canonicalization-hooks-DF3Z6sjO.mjs +22 -0
- package/dist/canonicalization-hooks-DF3Z6sjO.mjs.map +1 -0
- package/dist/codec.d.mts +2 -0
- package/dist/codec.mjs +2 -0
- package/dist/config-types-CFDf9ivE.mjs +37 -0
- package/dist/config-types-CFDf9ivE.mjs.map +1 -0
- package/dist/config-types-CQOf5N7R.d.mts +12 -0
- package/dist/config-types-CQOf5N7R.d.mts.map +1 -0
- package/dist/contract-builder-BFq0gOMV.mjs +634 -0
- package/dist/contract-builder-BFq0gOMV.mjs.map +1 -0
- package/dist/contract-builder-DB8nguDE.d.mts +445 -0
- package/dist/contract-builder-DB8nguDE.d.mts.map +1 -0
- package/dist/contract-errors-BCN6RVI5-kMurtAbI.mjs +9 -0
- package/dist/contract-errors-BCN6RVI5-kMurtAbI.mjs.map +1 -0
- package/dist/contract-psl.d.mts +45 -0
- package/dist/contract-psl.d.mts.map +1 -0
- package/dist/contract-psl.mjs +2 -0
- package/dist/contract-psl__provider.d.mts +15 -0
- package/dist/contract-psl__provider.d.mts.map +1 -0
- package/dist/contract-psl__provider.mjs +82 -0
- package/dist/contract-psl__provider.mjs.map +1 -0
- package/dist/contract-ts.d.mts +3 -0
- package/dist/contract-ts.mjs +3 -0
- package/dist/contract-ts__config-types.d.mts +2 -0
- package/dist/contract-ts__config-types.mjs +2 -0
- package/dist/contract-ts__contract-builder.d.mts +2 -0
- package/dist/contract-ts__contract-builder.mjs +2 -0
- package/dist/contract.d.mts +3 -0
- package/dist/contract.mjs +3 -0
- package/dist/contract__canonicalization-hooks.d.mts +9 -0
- package/dist/contract__canonicalization-hooks.d.mts.map +1 -0
- package/dist/contract__canonicalization-hooks.mjs +2 -0
- package/dist/contract__entity-kinds.d.mts +17 -0
- package/dist/contract__entity-kinds.d.mts.map +1 -0
- package/dist/contract__entity-kinds.mjs +2 -0
- package/dist/control-C7-kthr1.d.mts +193 -0
- package/dist/control-C7-kthr1.d.mts.map +1 -0
- package/dist/control-CClR5JMr.mjs +127 -0
- package/dist/control-CClR5JMr.mjs.map +1 -0
- package/dist/control-CFr3tYsg.mjs +398 -0
- package/dist/control-CFr3tYsg.mjs.map +1 -0
- package/dist/control-Cj81sPbj.d.mts +101 -0
- package/dist/control-Cj81sPbj.d.mts.map +1 -0
- package/dist/control-adapter-Db5pT77b.d.mts +83 -0
- package/dist/control-adapter-Db5pT77b.d.mts.map +1 -0
- package/dist/dist-C7Ykq48Q.mjs +19 -0
- package/dist/dist-C7Ykq48Q.mjs.map +1 -0
- package/dist/dist-Czwqx_i3.mjs +58 -0
- package/dist/dist-Czwqx_i3.mjs.map +1 -0
- package/dist/dist-DHrEJnhK.mjs +236 -0
- package/dist/dist-DHrEJnhK.mjs.map +1 -0
- package/dist/dist-Dyp05u64.mjs +1546 -0
- package/dist/dist-Dyp05u64.mjs.map +1 -0
- package/dist/emitter.d.mts +22 -0
- package/dist/emitter.d.mts.map +1 -0
- package/dist/emitter.mjs +2 -0
- package/dist/entity-kinds-B4KNTF8z-DPIuUuuB.mjs +603 -0
- package/dist/entity-kinds-B4KNTF8z-DPIuUuuB.mjs.map +1 -0
- package/dist/execution-CKnUiOfm.d.mts +48 -0
- package/dist/execution-CKnUiOfm.d.mts.map +1 -0
- package/dist/execution-D5XyZ5XS.mjs +1269 -0
- package/dist/execution-D5XyZ5XS.mjs.map +1 -0
- package/dist/exports-Bx-hlnZ3.mjs +209 -0
- package/dist/exports-Bx-hlnZ3.mjs.map +1 -0
- package/dist/exports-CJMh0VTU.mjs +156 -0
- package/dist/exports-CJMh0VTU.mjs.map +1 -0
- package/dist/family.d.mts +10 -0
- package/dist/family.mjs +9 -0
- package/dist/family__control-adapter.d.mts +2 -0
- package/dist/family__control-adapter.mjs +1 -0
- package/dist/family__control.d.mts +2 -0
- package/dist/family__control.mjs +3 -0
- package/dist/family__ir.d.mts +3 -0
- package/dist/family__ir.mjs +4 -0
- package/dist/family__migration.d.mts +2 -0
- package/dist/family__migration.mjs +2 -0
- package/dist/family__pack.d.mts +2 -0
- package/dist/family__pack.mjs +16 -0
- package/dist/family__pack.mjs.map +1 -0
- package/dist/family__runtime.d.mts +3 -0
- package/dist/family__runtime.mjs +2 -0
- package/dist/family__schema-verify.d.mts +2 -0
- package/dist/family__schema-verify.mjs +2 -0
- package/dist/field-accessor-0oUt6RZC-B_Z30uAA.mjs +234 -0
- package/dist/field-accessor-0oUt6RZC-B_Z30uAA.mjs.map +1 -0
- package/dist/field-accessor-DHsAPiW3-BdYCspQC.d.mts +588 -0
- package/dist/field-accessor-DHsAPiW3-BdYCspQC.d.mts.map +1 -0
- package/dist/filter-expressions-Uo8ZdzwB-53qnqceS.mjs +181 -0
- package/dist/filter-expressions-Uo8ZdzwB-53qnqceS.mjs.map +1 -0
- package/dist/index-BR0ue13b.d.mts +136 -0
- package/dist/index-BR0ue13b.d.mts.map +1 -0
- package/dist/index-Cd2zLiU6.d.mts +128 -0
- package/dist/index-Cd2zLiU6.d.mts.map +1 -0
- package/dist/index-DAOkcTCK.d.mts +151 -0
- package/dist/index-DAOkcTCK.d.mts.map +1 -0
- package/dist/index-Dv2PNMiG.d.mts +53 -0
- package/dist/index-Dv2PNMiG.d.mts.map +1 -0
- package/dist/index-DxoO-ywI.d.mts +178 -0
- package/dist/index-DxoO-ywI.d.mts.map +1 -0
- package/dist/index-wKMm41HC.d.mts +30 -0
- package/dist/index-wKMm41HC.d.mts.map +1 -0
- package/dist/interpreter-BxbUTQ3k-ClR98Ned.mjs +1091 -0
- package/dist/interpreter-BxbUTQ3k-ClR98Ned.mjs.map +1 -0
- package/dist/ir-CQrenTYt.d.mts +147 -0
- package/dist/ir-CQrenTYt.d.mts.map +1 -0
- package/dist/ir-Ch2aPr7a.mjs +62 -0
- package/dist/ir-Ch2aPr7a.mjs.map +1 -0
- package/dist/lowering.d.mts +2 -0
- package/dist/lowering.mjs +1 -0
- package/dist/migration-CNDQv5yB.d.mts +50 -0
- package/dist/migration-CNDQv5yB.d.mts.map +1 -0
- package/dist/migration-dcM7u4HG.mjs +52 -0
- package/dist/migration-dcM7u4HG.mjs.map +1 -0
- package/dist/mongo-contract-serializer-Cx7Fae8e-C8ZYPXpc.mjs +119 -0
- package/dist/mongo-contract-serializer-Cx7Fae8e-C8ZYPXpc.mjs.map +1 -0
- package/dist/mongo-contract-view-AnejqfrQ-BaCFT0xm.d.mts +27 -0
- package/dist/mongo-contract-view-AnejqfrQ-BaCFT0xm.d.mts.map +1 -0
- package/dist/mongo-contract-view-rcWzby6f-wRBCUnBt.mjs +17 -0
- package/dist/mongo-contract-view-rcWzby6f-wRBCUnBt.mjs.map +1 -0
- package/dist/mongo-value-set-tNn9-pun-dJYx_rVD.d.mts +536 -0
- package/dist/mongo-value-set-tNn9-pun-dJYx_rVD.d.mts.map +1 -0
- package/dist/mongodb-types-B4HmhF1S.d.mts +2 -0
- package/dist/orm.d.mts +311 -0
- package/dist/orm.d.mts.map +1 -0
- package/dist/orm.mjs +664 -0
- package/dist/orm.mjs.map +1 -0
- package/dist/pack-D9aLY50F.d.mts +44 -0
- package/dist/pack-D9aLY50F.d.mts.map +1 -0
- package/dist/query-ast.d.mts +5 -0
- package/dist/query-ast.mjs +4 -0
- package/dist/query-ast__control.d.mts +4 -0
- package/dist/query-ast__control.mjs +3 -0
- package/dist/query-ast__execution.d.mts +3 -0
- package/dist/query-ast__execution.mjs +3 -0
- package/dist/query-builder.d.mts +836 -0
- package/dist/query-builder.d.mts.map +1 -0
- package/dist/query-builder.mjs +3 -0
- package/dist/query-builder__contract-free.d.mts +83 -0
- package/dist/query-builder__contract-free.d.mts.map +1 -0
- package/dist/query-builder__contract-free.mjs +107 -0
- package/dist/query-builder__contract-free.mjs.map +1 -0
- package/dist/query-plan-C0-Yu8hf-DdilEdW6.d.mts +822 -0
- package/dist/query-plan-C0-Yu8hf-DdilEdW6.d.mts.map +1 -0
- package/dist/runtime-DPkRW4iu.d.mts +1 -0
- package/dist/runtime.d.mts +286 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +532 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/schema-ir.d.mts +2 -0
- package/dist/schema-ir.mjs +2 -0
- package/dist/schema-verify-DJGr28XW.d.mts +23 -0
- package/dist/schema-verify-DJGr28XW.d.mts.map +1 -0
- package/dist/value.d.mts +2 -0
- package/dist/value.mjs +2 -0
- package/dist/value__mongodb-types.d.mts +2 -0
- package/dist/value__mongodb-types.mjs +1 -0
- package/dist/verify-mongo-schema-De0FG2Rm-CCzwnNPY.mjs +447 -0
- package/dist/verify-mongo-schema-De0FG2Rm-CCzwnNPY.mjs.map +1 -0
- package/dist/wire.d.mts +3 -0
- package/dist/wire.mjs +190 -0
- package/dist/wire.mjs.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import { i as MongoCollectionOptions, o as MongoIndex } from "./entity-kinds-B4KNTF8z-DPIuUuuB.mjs";
|
|
2
|
+
import { a as applyPolymorphicScopeToMongoIndex, r as MongoStorage, s as buildMongoNamespace } from "./dist-DHrEJnhK.mjs";
|
|
3
|
+
import { t as mongoContractCanonicalizationHooks } from "./canonicalization-hooks-DF3Z6sjO.mjs";
|
|
4
|
+
import { t as contractError } from "./contract-errors-BCN6RVI5-kMurtAbI.mjs";
|
|
5
|
+
import { crossRef } from "@prisma/orm-framework/contract/types";
|
|
6
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
|
|
7
|
+
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
8
|
+
import { computeProfileHash, computeStorageHash } from "@prisma/orm-framework/contract/hashing";
|
|
9
|
+
import { errorEnumCodecNotInPackStack } from "@prisma/orm-framework/errors/control";
|
|
10
|
+
import { assertNoCrossRegistryCollisions, mergeAuthoringNamespaces } from "@prisma/orm-framework/components/authoring";
|
|
11
|
+
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
12
|
+
import { bindEnumType, createEntityHelpersFromNamespace, enumType, isEnumTypeHandle, member } from "@prisma/orm-framework/contract-authoring";
|
|
13
|
+
import { extractCodecLookup } from "@prisma/orm-framework/components/control";
|
|
14
|
+
import { canonicalStringify } from "@prisma/orm-framework/utils/canonical-stringify";
|
|
15
|
+
//#region ../../../2-mongo-family/2-authoring/contract-ts/dist/contract-builder.mjs
|
|
16
|
+
/**
|
|
17
|
+
* Encode an authored enum value to its codec-encoded JSON form, mirroring SQL's `build-contract`.
|
|
18
|
+
*
|
|
19
|
+
* The codec is resolved by id from the lookup built from the contract's target pack, so a
|
|
20
|
+
* non-identity `encodeJson` (permitted by the `mongoCodec` factory) is respected. A codecId the
|
|
21
|
+
* lookup cannot resolve is a hard error: the enum uses a codec that is not part of the contract's
|
|
22
|
+
* pack stack.
|
|
23
|
+
*/
|
|
24
|
+
function encodeEnumValue(value, codecId, codecLookup) {
|
|
25
|
+
const codec = codecLookup.get(codecId);
|
|
26
|
+
if (!codec) throw errorEnumCodecNotInPackStack({ codecId });
|
|
27
|
+
return codec.encodeJson(value);
|
|
28
|
+
}
|
|
29
|
+
function stableStringify(value) {
|
|
30
|
+
if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
|
|
31
|
+
if (value && typeof value === "object") return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, entry]) => `${JSON.stringify(key)}:${stableStringify(entry)}`).join(",")}}`;
|
|
32
|
+
return JSON.stringify(value);
|
|
33
|
+
}
|
|
34
|
+
function extractEntitiesNamespace(component) {
|
|
35
|
+
return component.authoring?.entityTypes ?? {};
|
|
36
|
+
}
|
|
37
|
+
const MONGO_RESERVED_HELPER_KEYS = [
|
|
38
|
+
"field",
|
|
39
|
+
"index",
|
|
40
|
+
"model",
|
|
41
|
+
"rel",
|
|
42
|
+
"valueObject"
|
|
43
|
+
];
|
|
44
|
+
function composeMongoEntityHelpers(family, target, extensions) {
|
|
45
|
+
const components = [
|
|
46
|
+
family,
|
|
47
|
+
target,
|
|
48
|
+
...Object.values(extensions ?? {})
|
|
49
|
+
];
|
|
50
|
+
const merged = {};
|
|
51
|
+
for (const component of components) {
|
|
52
|
+
const ns = extractEntitiesNamespace(component);
|
|
53
|
+
if (Object.keys(ns).length > 0) mergeAuthoringNamespaces(merged, ns, [], "entity", "entity");
|
|
54
|
+
}
|
|
55
|
+
assertNoCrossRegistryCollisions({}, {}, merged);
|
|
56
|
+
const collisions = Object.keys(merged).filter((name) => MONGO_RESERVED_HELPER_KEYS.includes(name));
|
|
57
|
+
if (collisions.length > 0) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `Pack-contributed entity type(s) ${collisions.map((c) => `"${c}"`).join(", ")} collide with the reserved built-in helper key(s) on the Mongo composed helpers surface. Reserved keys: ${MONGO_RESERVED_HELPER_KEYS.map((k) => `"${k}"`).join(", ")}.`, { meta: {
|
|
58
|
+
reason: "reserved-helper-key-collision",
|
|
59
|
+
contribution: collisions
|
|
60
|
+
} });
|
|
61
|
+
return createEntityHelpersFromNamespace(merged, { ctx: {
|
|
62
|
+
family: family.familyId,
|
|
63
|
+
target: target.targetId
|
|
64
|
+
} });
|
|
65
|
+
}
|
|
66
|
+
function createFieldBuilder(spec, enumHandle) {
|
|
67
|
+
return {
|
|
68
|
+
__kind: "field",
|
|
69
|
+
__type: spec.type,
|
|
70
|
+
__nullable: spec.nullable,
|
|
71
|
+
__many: spec.many,
|
|
72
|
+
__enumHandle: blindCast(enumHandle),
|
|
73
|
+
optional() {
|
|
74
|
+
return createFieldBuilder({
|
|
75
|
+
type: spec.type,
|
|
76
|
+
nullable: true,
|
|
77
|
+
many: spec.many
|
|
78
|
+
}, enumHandle);
|
|
79
|
+
},
|
|
80
|
+
many() {
|
|
81
|
+
return createFieldBuilder({
|
|
82
|
+
type: spec.type,
|
|
83
|
+
nullable: spec.nullable,
|
|
84
|
+
many: true
|
|
85
|
+
}, enumHandle);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function normalizeOptionalTypeParams(typeParams) {
|
|
90
|
+
if (!typeParams) return {};
|
|
91
|
+
return { typeParams };
|
|
92
|
+
}
|
|
93
|
+
function createScalarFieldBuilder(codecId, options) {
|
|
94
|
+
return createFieldBuilder({
|
|
95
|
+
type: {
|
|
96
|
+
kind: "scalar",
|
|
97
|
+
codecId,
|
|
98
|
+
...normalizeOptionalTypeParams(options?.typeParams)
|
|
99
|
+
},
|
|
100
|
+
nullable: false,
|
|
101
|
+
many: false
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
const field = {
|
|
105
|
+
scalar: createScalarFieldBuilder,
|
|
106
|
+
objectId() {
|
|
107
|
+
return createScalarFieldBuilder("mongo/objectId@1");
|
|
108
|
+
},
|
|
109
|
+
string() {
|
|
110
|
+
return createScalarFieldBuilder("mongo/string@1");
|
|
111
|
+
},
|
|
112
|
+
double() {
|
|
113
|
+
return createScalarFieldBuilder("mongo/double@1");
|
|
114
|
+
},
|
|
115
|
+
int32() {
|
|
116
|
+
return createScalarFieldBuilder("mongo/int32@1");
|
|
117
|
+
},
|
|
118
|
+
bool() {
|
|
119
|
+
return createScalarFieldBuilder("mongo/bool@1");
|
|
120
|
+
},
|
|
121
|
+
date() {
|
|
122
|
+
return createScalarFieldBuilder("mongo/date@1");
|
|
123
|
+
},
|
|
124
|
+
vector(options) {
|
|
125
|
+
return createScalarFieldBuilder("mongo/vector@1", options);
|
|
126
|
+
},
|
|
127
|
+
valueObject(valueObjectName) {
|
|
128
|
+
return createFieldBuilder({
|
|
129
|
+
type: {
|
|
130
|
+
kind: "valueObject",
|
|
131
|
+
name: resolveValueObjectName(valueObjectName)
|
|
132
|
+
},
|
|
133
|
+
nullable: false,
|
|
134
|
+
many: false
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
namedType(handle) {
|
|
138
|
+
return createFieldBuilder({
|
|
139
|
+
type: blindCast({
|
|
140
|
+
kind: "scalar",
|
|
141
|
+
codecId: handle.codecId
|
|
142
|
+
}),
|
|
143
|
+
nullable: false,
|
|
144
|
+
many: false
|
|
145
|
+
}, handle);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
function index(fields, options) {
|
|
149
|
+
return {
|
|
150
|
+
fields,
|
|
151
|
+
...options ? { options } : {}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function createFieldReference(modelName, fieldName) {
|
|
155
|
+
return {
|
|
156
|
+
__kind: "fieldRef",
|
|
157
|
+
modelName,
|
|
158
|
+
fieldName
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function isFieldReference(value) {
|
|
162
|
+
return typeof value === "object" && value !== null && "__kind" in value && value.__kind === "fieldRef";
|
|
163
|
+
}
|
|
164
|
+
function resolveModelName(value) {
|
|
165
|
+
return typeof value === "string" ? value : value.__name;
|
|
166
|
+
}
|
|
167
|
+
function resolveValueObjectName(value) {
|
|
168
|
+
return typeof value === "string" ? value : value.__name;
|
|
169
|
+
}
|
|
170
|
+
function normalizeStringList(value) {
|
|
171
|
+
return typeof value === "string" ? [value] : [...value];
|
|
172
|
+
}
|
|
173
|
+
function normalizeTargetField(targetModelName, value) {
|
|
174
|
+
if (!isFieldReference(value)) return value;
|
|
175
|
+
if (value.modelName !== targetModelName) throw contractError("CONTRACT.RELATION_INVALID", `Relation target "${targetModelName}" cannot reference field "${value.modelName}.${value.fieldName}".`, { meta: {
|
|
176
|
+
modelName: targetModelName,
|
|
177
|
+
reason: "cross-model-field-reference",
|
|
178
|
+
referencedModel: value.modelName,
|
|
179
|
+
referencedField: value.fieldName
|
|
180
|
+
} });
|
|
181
|
+
return value.fieldName;
|
|
182
|
+
}
|
|
183
|
+
function normalizeTargetFields(targetModelName, value) {
|
|
184
|
+
if (typeof value === "string") return [value];
|
|
185
|
+
if (isFieldReference(value)) return [normalizeTargetField(targetModelName, value)];
|
|
186
|
+
return value.map((entry) => normalizeTargetField(targetModelName, entry));
|
|
187
|
+
}
|
|
188
|
+
function createRelationBuilder(spec) {
|
|
189
|
+
return {
|
|
190
|
+
__kind: "relation",
|
|
191
|
+
__to: spec.to,
|
|
192
|
+
__cardinality: spec.cardinality,
|
|
193
|
+
__on: spec.on
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function createReferenceRelationBuilder(target, cardinality, options) {
|
|
197
|
+
const targetModelName = resolveModelName(target);
|
|
198
|
+
return createRelationBuilder({
|
|
199
|
+
to: targetModelName,
|
|
200
|
+
cardinality,
|
|
201
|
+
on: {
|
|
202
|
+
localFields: normalizeStringList(options.from),
|
|
203
|
+
targetFields: normalizeTargetFields(targetModelName, options.to)
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
function createEmbedRelationBuilder(target, cardinality) {
|
|
208
|
+
return createRelationBuilder({
|
|
209
|
+
to: resolveModelName(target),
|
|
210
|
+
cardinality,
|
|
211
|
+
on: void 0
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function hasOne(target, options) {
|
|
215
|
+
if (!options) return createEmbedRelationBuilder(target, "1:1");
|
|
216
|
+
return createReferenceRelationBuilder(target, "1:1", options);
|
|
217
|
+
}
|
|
218
|
+
function hasMany(target, options) {
|
|
219
|
+
if (!options) return createEmbedRelationBuilder(target, "1:N");
|
|
220
|
+
return createReferenceRelationBuilder(target, "1:N", options);
|
|
221
|
+
}
|
|
222
|
+
function belongsTo(target, options) {
|
|
223
|
+
return createReferenceRelationBuilder(target, "N:1", options);
|
|
224
|
+
}
|
|
225
|
+
const rel = {
|
|
226
|
+
belongsTo,
|
|
227
|
+
hasMany,
|
|
228
|
+
hasOne
|
|
229
|
+
};
|
|
230
|
+
function valueObject(name, input) {
|
|
231
|
+
return {
|
|
232
|
+
__kind: "valueObject",
|
|
233
|
+
__name: name,
|
|
234
|
+
__fields: input.fields
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function model(name, input) {
|
|
238
|
+
return {
|
|
239
|
+
__kind: "model",
|
|
240
|
+
__name: name,
|
|
241
|
+
__fields: input.fields,
|
|
242
|
+
__relations: input.relations ?? {},
|
|
243
|
+
__indexes: input.indexes,
|
|
244
|
+
__collectionOptions: input.collectionOptions,
|
|
245
|
+
__controlPolicy: input.controlPolicy,
|
|
246
|
+
__collection: input.collection,
|
|
247
|
+
__owner: input.owner ? resolveModelName(input.owner) : void 0,
|
|
248
|
+
__base: input.base ? resolveModelName(input.base) : void 0,
|
|
249
|
+
__storageRelations: input.storageRelations,
|
|
250
|
+
__discriminator: input.discriminator ? { field: input.discriminator.field } : void 0,
|
|
251
|
+
__variants: input.discriminator?.variants,
|
|
252
|
+
ref(fieldName) {
|
|
253
|
+
return createFieldReference(name, fieldName);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
function validateTargetPackRef(family, target) {
|
|
258
|
+
if (family.familyId !== "mongo") throw contractError("CONTRACT.PACK_FAMILY_MISMATCH", `defineContract only accepts Mongo family packs. Received family "${family.familyId}".`, { meta: {
|
|
259
|
+
packId: family.id,
|
|
260
|
+
packFamilyId: family.familyId,
|
|
261
|
+
contractFamilyId: "mongo"
|
|
262
|
+
} });
|
|
263
|
+
if (target.familyId !== family.familyId) throw contractError("CONTRACT.PACK_FAMILY_MISMATCH", `target pack "${target.id}" targets family "${target.familyId}" but contract family is "${family.familyId}".`, { meta: {
|
|
264
|
+
packId: target.id,
|
|
265
|
+
packFamilyId: target.familyId,
|
|
266
|
+
contractFamilyId: family.familyId
|
|
267
|
+
} });
|
|
268
|
+
}
|
|
269
|
+
function validateExtensionPackRefs(target, extensions) {
|
|
270
|
+
if (!extensions) return;
|
|
271
|
+
for (const packRef of Object.values(extensions)) {
|
|
272
|
+
if (packRef.kind !== "extension") throw contractError("CONTRACT.PACK_REF_INVALID", `defineContract only accepts extension pack refs in extensions. Received kind "${packRef.kind}".`, { meta: {
|
|
273
|
+
packId: packRef.id,
|
|
274
|
+
kind: packRef.kind
|
|
275
|
+
} });
|
|
276
|
+
if (packRef.familyId !== target.familyId) throw contractError("CONTRACT.PACK_FAMILY_MISMATCH", `extension pack "${packRef.id}" targets family "${packRef.familyId}" but contract target family is "${target.familyId}".`, { meta: {
|
|
277
|
+
packId: packRef.id,
|
|
278
|
+
packFamilyId: packRef.familyId,
|
|
279
|
+
contractFamilyId: target.familyId
|
|
280
|
+
} });
|
|
281
|
+
if (packRef.targetId && packRef.targetId !== target.targetId) throw contractError("CONTRACT.PACK_TARGET_MISMATCH", `extension pack "${packRef.id}" targets "${packRef.targetId}" but contract target is "${target.targetId}".`, { meta: {
|
|
282
|
+
packId: packRef.id,
|
|
283
|
+
packTargetId: packRef.targetId,
|
|
284
|
+
contractTargetId: target.targetId
|
|
285
|
+
} });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function isContractScaffold(value) {
|
|
289
|
+
if (typeof value !== "object" || value === null) return false;
|
|
290
|
+
return "family" in value && "target" in value;
|
|
291
|
+
}
|
|
292
|
+
function buildContractField(builder) {
|
|
293
|
+
const valueSet = builder.__enumHandle ? {
|
|
294
|
+
plane: "domain",
|
|
295
|
+
entityKind: "enum",
|
|
296
|
+
namespaceId: UNBOUND_NAMESPACE_ID,
|
|
297
|
+
entityName: builder.__enumHandle.enumName
|
|
298
|
+
} : void 0;
|
|
299
|
+
return builder.__many ? {
|
|
300
|
+
type: builder.__type,
|
|
301
|
+
nullable: builder.__nullable,
|
|
302
|
+
many: true,
|
|
303
|
+
...ifDefined("valueSet", valueSet)
|
|
304
|
+
} : {
|
|
305
|
+
type: builder.__type,
|
|
306
|
+
nullable: builder.__nullable,
|
|
307
|
+
...ifDefined("valueSet", valueSet)
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function buildFields(fields) {
|
|
311
|
+
const builtFields = {};
|
|
312
|
+
for (const [fieldName, fieldBuilder] of Object.entries(fields)) builtFields[fieldName] = buildContractField(fieldBuilder);
|
|
313
|
+
return builtFields;
|
|
314
|
+
}
|
|
315
|
+
function buildRelation(relationBuilder) {
|
|
316
|
+
const to = crossRef(relationBuilder.__to, UNBOUND_NAMESPACE_ID);
|
|
317
|
+
return relationBuilder.__on ? {
|
|
318
|
+
to,
|
|
319
|
+
cardinality: relationBuilder.__cardinality,
|
|
320
|
+
on: relationBuilder.__on
|
|
321
|
+
} : {
|
|
322
|
+
to,
|
|
323
|
+
cardinality: relationBuilder.__cardinality
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
function buildRelations(relations) {
|
|
327
|
+
const builtRelations = {};
|
|
328
|
+
for (const [relationName, relationBuilder] of Object.entries(relations)) builtRelations[relationName] = buildRelation(relationBuilder);
|
|
329
|
+
return builtRelations;
|
|
330
|
+
}
|
|
331
|
+
function buildValueObjects(valueObjects) {
|
|
332
|
+
const builtValueObjects = {};
|
|
333
|
+
for (const valueObjectBuilder of Object.values(valueObjects ?? {})) {
|
|
334
|
+
if (valueObjectBuilder.__name in builtValueObjects) throw contractError("CONTRACT.NAME_DUPLICATE", `Duplicate value object name "${valueObjectBuilder.__name}" in defineContract().`, { meta: {
|
|
335
|
+
kind: "valueObject",
|
|
336
|
+
name: valueObjectBuilder.__name
|
|
337
|
+
} });
|
|
338
|
+
builtValueObjects[valueObjectBuilder.__name] = { fields: buildFields(valueObjectBuilder.__fields) };
|
|
339
|
+
}
|
|
340
|
+
return builtValueObjects;
|
|
341
|
+
}
|
|
342
|
+
function buildModels(models) {
|
|
343
|
+
const builtModels = {};
|
|
344
|
+
for (const modelBuilder of Object.values(models ?? {})) {
|
|
345
|
+
if (modelBuilder.__name in builtModels) throw contractError("CONTRACT.NAME_DUPLICATE", `Duplicate model name "${modelBuilder.__name}" in defineContract().`, { meta: {
|
|
346
|
+
kind: "model",
|
|
347
|
+
name: modelBuilder.__name
|
|
348
|
+
} });
|
|
349
|
+
const storage = {
|
|
350
|
+
...modelBuilder.__collection ? { collection: modelBuilder.__collection } : {},
|
|
351
|
+
...modelBuilder.__storageRelations ? { relations: modelBuilder.__storageRelations } : {}
|
|
352
|
+
};
|
|
353
|
+
builtModels[modelBuilder.__name] = {
|
|
354
|
+
fields: buildFields(modelBuilder.__fields),
|
|
355
|
+
relations: buildRelations(modelBuilder.__relations),
|
|
356
|
+
storage,
|
|
357
|
+
...modelBuilder.__owner ? { owner: modelBuilder.__owner } : {},
|
|
358
|
+
...modelBuilder.__base ? { base: crossRef(modelBuilder.__base, UNBOUND_NAMESPACE_ID) } : {},
|
|
359
|
+
...modelBuilder.__discriminator ? { discriminator: modelBuilder.__discriminator } : {},
|
|
360
|
+
...modelBuilder.__variants ? { variants: modelBuilder.__variants } : {}
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
return builtModels;
|
|
364
|
+
}
|
|
365
|
+
function deriveRoots(models) {
|
|
366
|
+
const roots = {};
|
|
367
|
+
for (const modelBuilder of Object.values(models ?? {})) {
|
|
368
|
+
if (!modelBuilder.__collection || modelBuilder.__owner || modelBuilder.__base) continue;
|
|
369
|
+
roots[modelBuilder.__collection] = crossRef(modelBuilder.__name, UNBOUND_NAMESPACE_ID);
|
|
370
|
+
}
|
|
371
|
+
return roots;
|
|
372
|
+
}
|
|
373
|
+
function normalizeRoots(roots) {
|
|
374
|
+
const normalizedRoots = {};
|
|
375
|
+
for (const [rootName, rootValue] of Object.entries(roots ?? {})) normalizedRoots[rootName] = crossRef(resolveModelName(rootValue), UNBOUND_NAMESPACE_ID);
|
|
376
|
+
return normalizedRoots;
|
|
377
|
+
}
|
|
378
|
+
function toStorageIndex(index) {
|
|
379
|
+
const input = { keys: Object.entries(index.fields).map(([field, direction]) => ({
|
|
380
|
+
field,
|
|
381
|
+
direction
|
|
382
|
+
})) };
|
|
383
|
+
if (index.options) {
|
|
384
|
+
for (const [key, value] of Object.entries(index.options)) if (value !== void 0) input[key] = value;
|
|
385
|
+
}
|
|
386
|
+
return new MongoIndex(input);
|
|
387
|
+
}
|
|
388
|
+
function toStorageCollectionOptions(opts) {
|
|
389
|
+
return new MongoCollectionOptions({
|
|
390
|
+
...opts.capped ? { capped: {
|
|
391
|
+
size: opts.size ?? 0,
|
|
392
|
+
...opts.max != null && { max: opts.max }
|
|
393
|
+
} } : {},
|
|
394
|
+
...ifDefined("storageEngine", opts.storageEngine),
|
|
395
|
+
...ifDefined("indexOptionDefaults", opts.indexOptionDefaults),
|
|
396
|
+
...ifDefined("collation", opts.collation),
|
|
397
|
+
...ifDefined("timeseries", opts.timeseries),
|
|
398
|
+
...opts.clusteredIndex !== void 0 && { clusteredIndex: opts.clusteredIndex.name !== void 0 ? { name: opts.clusteredIndex.name } : {} },
|
|
399
|
+
...ifDefined("expireAfterSeconds", opts.expireAfterSeconds),
|
|
400
|
+
...ifDefined("changeStreamPreAndPostImages", opts.changeStreamPreAndPostImages)
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
function findMissingIndexField(index, modelFields) {
|
|
404
|
+
for (const fieldName of Object.keys(index.fields)) {
|
|
405
|
+
const wildcardMatch = fieldName.match(/^(.+)\.\$\*\*$/);
|
|
406
|
+
const lookupName = wildcardMatch ? wildcardMatch[1] : fieldName;
|
|
407
|
+
if (lookupName === void 0 || lookupName.length === 0) continue;
|
|
408
|
+
if (lookupName === "$**") continue;
|
|
409
|
+
if (!Object.hasOwn(modelFields, lookupName)) return lookupName;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
function resolveVariantScope(modelBuilder, modelsByName) {
|
|
413
|
+
if (!modelBuilder.__base) return void 0;
|
|
414
|
+
const baseBuilder = modelsByName[modelBuilder.__base];
|
|
415
|
+
if (!baseBuilder) return void 0;
|
|
416
|
+
const discriminatorField = baseBuilder.__discriminator?.field;
|
|
417
|
+
const variantValue = baseBuilder.__variants?.[modelBuilder.__name]?.value;
|
|
418
|
+
if (!discriminatorField || variantValue === void 0) return void 0;
|
|
419
|
+
return {
|
|
420
|
+
discriminatorField,
|
|
421
|
+
discriminatorValue: variantValue
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
function scopeVariantIndex(storageIndex, scope, variantName, authoredIndex) {
|
|
425
|
+
const result = applyPolymorphicScopeToMongoIndex(storageIndex, scope);
|
|
426
|
+
if (result.kind === "conflict") {
|
|
427
|
+
const indexLabel = authoredIndex ? canonicalStringify(authoredIndex) : "<unknown>";
|
|
428
|
+
throw contractError("CONTRACT.INDEX_INVALID", `Variant model "${variantName}" index ${indexLabel} conflicts with discriminator scope: ${result.reason}`, { meta: {
|
|
429
|
+
variantName,
|
|
430
|
+
indexLabel,
|
|
431
|
+
reason: result.reason
|
|
432
|
+
} });
|
|
433
|
+
}
|
|
434
|
+
return result.index;
|
|
435
|
+
}
|
|
436
|
+
function buildCollections(models) {
|
|
437
|
+
const intermediate = {};
|
|
438
|
+
const declaredIndexOwners = /* @__PURE__ */ new Map();
|
|
439
|
+
const modelMap = models ?? {};
|
|
440
|
+
const modelsByName = {};
|
|
441
|
+
for (const builder of Object.values(modelMap)) modelsByName[builder.__name] = builder;
|
|
442
|
+
for (const modelBuilder of Object.values(modelMap)) {
|
|
443
|
+
if (!modelBuilder.__collection) {
|
|
444
|
+
if (modelBuilder.__indexes && modelBuilder.__indexes.length > 0) throw contractError("CONTRACT.COLLECTION_INVALID", `Model "${modelBuilder.__name}" defines indexes but has no collection to attach them to.`, { meta: {
|
|
445
|
+
modelName: modelBuilder.__name,
|
|
446
|
+
reason: "indexes-without-collection"
|
|
447
|
+
} });
|
|
448
|
+
if (modelBuilder.__collectionOptions) throw contractError("CONTRACT.COLLECTION_INVALID", `Model "${modelBuilder.__name}" defines collectionOptions but has no collection to attach them to.`, { meta: {
|
|
449
|
+
modelName: modelBuilder.__name,
|
|
450
|
+
reason: "collectionOptions-without-collection"
|
|
451
|
+
} });
|
|
452
|
+
if (modelBuilder.__controlPolicy) throw contractError("CONTRACT.COLLECTION_INVALID", `Model "${modelBuilder.__name}" defines controlPolicy but has no collection to attach it to.`, { meta: {
|
|
453
|
+
modelName: modelBuilder.__name,
|
|
454
|
+
reason: "controlPolicy-without-collection"
|
|
455
|
+
} });
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
const existingCollection = intermediate[modelBuilder.__collection] ?? {};
|
|
459
|
+
const existingIndexes = existingCollection.indexes ?? [];
|
|
460
|
+
if (existingCollection.options && modelBuilder.__collectionOptions) throw contractError("CONTRACT.COLLECTION_INVALID", `Collection "${modelBuilder.__collection}" has collectionOptions declared by multiple models. Author collectionOptions on a single model per collection.`, { meta: {
|
|
461
|
+
modelName: modelBuilder.__name,
|
|
462
|
+
collection: modelBuilder.__collection,
|
|
463
|
+
reason: "collectionOptions-declared-by-multiple-models"
|
|
464
|
+
} });
|
|
465
|
+
if (existingCollection.control !== void 0 && modelBuilder.__controlPolicy) throw contractError("CONTRACT.COLLECTION_INVALID", `Collection "${modelBuilder.__collection}" has controlPolicy declared by multiple models. Author controlPolicy on a single model per collection.`, { meta: {
|
|
466
|
+
modelName: modelBuilder.__name,
|
|
467
|
+
collection: modelBuilder.__collection,
|
|
468
|
+
reason: "controlPolicy-declared-by-multiple-models"
|
|
469
|
+
} });
|
|
470
|
+
for (const collectionIndex of modelBuilder.__indexes ?? []) {
|
|
471
|
+
const missingField = findMissingIndexField(collectionIndex, modelBuilder.__fields);
|
|
472
|
+
if (missingField !== void 0) {
|
|
473
|
+
const indexSignature = canonicalStringify(collectionIndex);
|
|
474
|
+
throw contractError("CONTRACT.FIELD_UNKNOWN", `Model "${modelBuilder.__name}" index ${indexSignature} references unknown field "${missingField}".`, { meta: {
|
|
475
|
+
modelName: modelBuilder.__name,
|
|
476
|
+
fieldName: missingField,
|
|
477
|
+
indexSignature
|
|
478
|
+
} });
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
const polymorphicScope = resolveVariantScope(modelBuilder, modelsByName);
|
|
482
|
+
const rawStorageIndexes = (modelBuilder.__indexes ?? []).map(toStorageIndex);
|
|
483
|
+
const storageIndexes = polymorphicScope ? rawStorageIndexes.map((idx, i) => scopeVariantIndex(idx, polymorphicScope, modelBuilder.__name, modelBuilder.__indexes?.[i])) : rawStorageIndexes;
|
|
484
|
+
for (let i = 0; i < storageIndexes.length; i++) {
|
|
485
|
+
const storageIndex = storageIndexes[i];
|
|
486
|
+
if (storageIndex === void 0) continue;
|
|
487
|
+
const indexSignature = stableStringify(storageIndex);
|
|
488
|
+
const collectionIndexKey = `${modelBuilder.__collection}:${indexSignature}`;
|
|
489
|
+
const firstOwner = declaredIndexOwners.get(collectionIndexKey);
|
|
490
|
+
if (firstOwner) {
|
|
491
|
+
const authoredIndex = modelBuilder.__indexes?.[i];
|
|
492
|
+
const reportedSignature = authoredIndex ? canonicalStringify(authoredIndex) : indexSignature;
|
|
493
|
+
throw contractError("CONTRACT.NAME_DUPLICATE", `Collection "${modelBuilder.__collection}" defines duplicate index ${reportedSignature}. First declared on model "${firstOwner}" and duplicated on model "${modelBuilder.__name}".`, { meta: {
|
|
494
|
+
kind: "index",
|
|
495
|
+
name: reportedSignature,
|
|
496
|
+
collection: modelBuilder.__collection,
|
|
497
|
+
first: firstOwner,
|
|
498
|
+
second: modelBuilder.__name
|
|
499
|
+
} });
|
|
500
|
+
}
|
|
501
|
+
declaredIndexOwners.set(collectionIndexKey, modelBuilder.__name);
|
|
502
|
+
}
|
|
503
|
+
const storageOptions = modelBuilder.__collectionOptions ? toStorageCollectionOptions(modelBuilder.__collectionOptions) : void 0;
|
|
504
|
+
const controlPatch = modelBuilder.__controlPolicy !== void 0 ? { control: modelBuilder.__controlPolicy } : {};
|
|
505
|
+
intermediate[modelBuilder.__collection] = storageIndexes.length > 0 ? {
|
|
506
|
+
...existingCollection,
|
|
507
|
+
indexes: [...existingIndexes, ...storageIndexes],
|
|
508
|
+
...storageOptions ? { options: storageOptions } : {},
|
|
509
|
+
...controlPatch
|
|
510
|
+
} : storageOptions ? {
|
|
511
|
+
...existingCollection,
|
|
512
|
+
options: storageOptions,
|
|
513
|
+
...controlPatch
|
|
514
|
+
} : Object.keys(controlPatch).length > 0 ? {
|
|
515
|
+
...existingCollection,
|
|
516
|
+
...controlPatch
|
|
517
|
+
} : existingCollection;
|
|
518
|
+
}
|
|
519
|
+
return intermediate;
|
|
520
|
+
}
|
|
521
|
+
function buildContractFromDefinition(definition) {
|
|
522
|
+
validateTargetPackRef(definition.family, definition.target);
|
|
523
|
+
validateExtensionPackRefs(definition.target, definition.extensions);
|
|
524
|
+
const builtModels = buildModels(definition.models);
|
|
525
|
+
const builtValueObjects = buildValueObjects(definition.valueObjects);
|
|
526
|
+
const roots = definition.roots ? normalizeRoots(definition.roots) : deriveRoots(definition.models);
|
|
527
|
+
const capabilities = {};
|
|
528
|
+
const collections = buildCollections(definition.models);
|
|
529
|
+
const codecLookup = extractCodecLookup([definition.target]);
|
|
530
|
+
const storageValueSets = {};
|
|
531
|
+
for (const [enumName, handle] of Object.entries(definition.enums ?? {})) storageValueSets[enumName] = {
|
|
532
|
+
kind: "valueSet",
|
|
533
|
+
values: handle.values.map((v) => encodeEnumValue(v, handle.codecId, codecLookup))
|
|
534
|
+
};
|
|
535
|
+
const unboundNamespace = buildMongoNamespace({
|
|
536
|
+
id: UNBOUND_NAMESPACE_ID,
|
|
537
|
+
entries: {
|
|
538
|
+
collection: collections,
|
|
539
|
+
...ifDefined("valueSet", Object.keys(storageValueSets).length > 0 ? storageValueSets : void 0)
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
const storageBody = { namespaces: { [UNBOUND_NAMESPACE_ID]: {
|
|
543
|
+
id: UNBOUND_NAMESPACE_ID,
|
|
544
|
+
collections: unboundNamespace.entries.collection,
|
|
545
|
+
...ifDefined("valueSet", unboundNamespace.entries.valueSet)
|
|
546
|
+
} } };
|
|
547
|
+
const storage = new MongoStorage({
|
|
548
|
+
storageHash: computeStorageHash({
|
|
549
|
+
target: definition.target.targetId,
|
|
550
|
+
targetFamily: definition.family.familyId,
|
|
551
|
+
storage: storageBody,
|
|
552
|
+
...mongoContractCanonicalizationHooks
|
|
553
|
+
}),
|
|
554
|
+
namespaces: { [UNBOUND_NAMESPACE_ID]: unboundNamespace }
|
|
555
|
+
});
|
|
556
|
+
const builtEnums = {};
|
|
557
|
+
for (const [enumName, handle] of Object.entries(definition.enums ?? {})) {
|
|
558
|
+
if (enumName !== handle.enumName) throw contractError("CONTRACT.ENUM_INVALID", `enum declaration key "${enumName}" must match enumType name "${handle.enumName}". Aliases are not supported.`, { meta: {
|
|
559
|
+
enumName: handle.enumName,
|
|
560
|
+
declaredKey: enumName,
|
|
561
|
+
reason: "declaration-key-mismatch"
|
|
562
|
+
} });
|
|
563
|
+
builtEnums[enumName] = {
|
|
564
|
+
codecId: handle.codecId,
|
|
565
|
+
members: handle.enumMembers.map((m) => ({
|
|
566
|
+
name: m.name,
|
|
567
|
+
value: encodeEnumValue(m.value, handle.codecId, codecLookup)
|
|
568
|
+
}))
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
const hasEnums = Object.keys(builtEnums).length > 0;
|
|
572
|
+
for (const [modelName, modelBuilder] of Object.entries(definition.models ?? {})) for (const [fieldName, fieldBuilder] of Object.entries(modelBuilder.__fields)) {
|
|
573
|
+
const handle = fieldBuilder.__enumHandle;
|
|
574
|
+
if (handle && !(handle.enumName in builtEnums)) throw contractError("CONTRACT.ENUM_UNKNOWN", `Model "${modelName}" field "${fieldName}" references enum "${handle.enumName}" which is not declared in defineContract({ enums: { ... } }).`, { meta: {
|
|
575
|
+
modelName,
|
|
576
|
+
fieldName,
|
|
577
|
+
enumName: handle.enumName
|
|
578
|
+
} });
|
|
579
|
+
}
|
|
580
|
+
return blindCast({
|
|
581
|
+
target: definition.target.targetId,
|
|
582
|
+
targetFamily: definition.family.familyId,
|
|
583
|
+
...ifDefined("defaultControlPolicy", definition.defaultControlPolicy),
|
|
584
|
+
roots,
|
|
585
|
+
domain: { namespaces: { [UNBOUND_NAMESPACE_ID]: {
|
|
586
|
+
models: builtModels,
|
|
587
|
+
...Object.keys(builtValueObjects).length > 0 ? { valueObjects: builtValueObjects } : {},
|
|
588
|
+
...hasEnums ? { enum: builtEnums } : {}
|
|
589
|
+
} } },
|
|
590
|
+
storage,
|
|
591
|
+
capabilities,
|
|
592
|
+
extensions: definition.extensions ?? {},
|
|
593
|
+
profileHash: computeProfileHash({
|
|
594
|
+
target: definition.target.targetId,
|
|
595
|
+
targetFamily: definition.family.familyId,
|
|
596
|
+
capabilities
|
|
597
|
+
}),
|
|
598
|
+
meta: {}
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
/** Implementation. */
|
|
602
|
+
function buildBoundContract(family, target, definition, factory) {
|
|
603
|
+
const full = {
|
|
604
|
+
...definition,
|
|
605
|
+
family,
|
|
606
|
+
target
|
|
607
|
+
};
|
|
608
|
+
if (factory !== void 0) {
|
|
609
|
+
const built = factory({
|
|
610
|
+
...composeMongoEntityHelpers(family, target, definition.extensions),
|
|
611
|
+
field,
|
|
612
|
+
index,
|
|
613
|
+
model,
|
|
614
|
+
rel,
|
|
615
|
+
valueObject
|
|
616
|
+
});
|
|
617
|
+
return buildContractFromDefinition({
|
|
618
|
+
...full,
|
|
619
|
+
...ifDefined("models", built.models),
|
|
620
|
+
...ifDefined("valueObjects", built.valueObjects),
|
|
621
|
+
...ifDefined("roots", built.roots)
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
return buildContractFromDefinition(full);
|
|
625
|
+
}
|
|
626
|
+
function defineContract(definition, factory) {
|
|
627
|
+
if (!isContractScaffold(definition)) throw contractError("CONTRACT.ARGUMENT_INVALID", "defineContract expects a contract definition object. Define your contract with defineContract({ family, target, models, ... }).");
|
|
628
|
+
if (factory !== void 0) return buildBoundContract(definition.family, definition.target, definition, factory);
|
|
629
|
+
return buildBoundContract(definition.family, definition.target, definition);
|
|
630
|
+
}
|
|
631
|
+
//#endregion
|
|
632
|
+
export { field as a, member as c, valueObject as d, enumType as i, model as l, buildBoundContract as n, index as o, defineContract as r, isEnumTypeHandle as s, bindEnumType as t, rel as u };
|
|
633
|
+
|
|
634
|
+
//# sourceMappingURL=contract-builder-BFq0gOMV.mjs.map
|