@prisma-next/sql-contract-ts 0.14.0-dev.51 → 0.14.0-dev.52

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.
@@ -1,10 +1,10 @@
1
- import { t as buildSqlContractFromDefinition } from "./build-contract-Bi8UaU_S.mjs";
1
+ import { t as buildSqlContractFromDefinition } from "./build-contract-CSyrbCoJ.mjs";
2
2
  import { blindCast } from "@prisma-next/utils/casts";
3
3
  import { ifDefined } from "@prisma-next/utils/defined";
4
4
  import { isColumnDefault } from "@prisma-next/contract/types";
5
5
  import { bindEnumType, createEntityHelpersFromNamespace, enumType, isEnumTypeHandle, member } from "@prisma-next/contract-authoring";
6
- import { toStorageTypeInstance } from "@prisma-next/sql-contract/types";
7
6
  import { assertNoCrossRegistryCollisions, instantiateAuthoringFieldPreset, instantiateAuthoringTypeConstructor, isAuthoringFieldPresetDescriptor, isAuthoringTypeConstructorDescriptor, mergeAuthoringNamespaces, validateAuthoringHelperArguments } from "@prisma-next/framework-components/authoring";
7
+ import { toStorageTypeInstance } from "@prisma-next/sql-contract/types";
8
8
  //#region src/authoring-helper-runtime.ts
9
9
  function isNamedConstraintOptionsLike(value) {
10
10
  if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
@@ -1203,6 +1203,7 @@ function buildContractDefinition(definition) {
1203
1203
  ...definition.namespaces ? { namespaces: definition.namespaces } : {},
1204
1204
  createNamespace: definition.createNamespace,
1205
1205
  ...definition.enums && Object.keys(definition.enums).length > 0 ? { enums: definition.enums } : {},
1206
+ ...definition.packEntities && Object.keys(definition.packEntities).length > 0 ? { packEntities: definition.packEntities } : {},
1206
1207
  models
1207
1208
  };
1208
1209
  }
@@ -1290,6 +1291,29 @@ function buildContractFromDsl(definition) {
1290
1291
  validatePerModelNamespaces(definition.target, definition.namespaces, definition.models ?? {});
1291
1292
  return blindCast(buildSqlContractFromDefinition(buildContractDefinition(definition), definition.codecLookup));
1292
1293
  }
1294
+ function mergePackEntityNames(namespaceId, kind, a, b) {
1295
+ if (a !== void 0 && b !== void 0) for (const [name, entity] of Object.entries(b)) {
1296
+ const existing = a[name];
1297
+ if (existing !== void 0 && existing !== entity) throw new Error(`defineContract: two different "${kind}" entities named "${name}" in namespace "${namespaceId}" — a factory-returned pack entity conflicts with a scaffold-declared one; pack-entity names must be unique per namespace.`);
1298
+ }
1299
+ return {
1300
+ ...a ?? {},
1301
+ ...b ?? {}
1302
+ };
1303
+ }
1304
+ function mergePackEntityKinds(namespaceId, a, b) {
1305
+ const kinds = new Set([...Object.keys(a ?? {}), ...Object.keys(b ?? {})]);
1306
+ const result = {};
1307
+ for (const kind of kinds) result[kind] = mergePackEntityNames(namespaceId, kind, a?.[kind], b?.[kind]);
1308
+ return result;
1309
+ }
1310
+ function mergePackEntities(a, b) {
1311
+ if (a === void 0 && b === void 0) return void 0;
1312
+ const namespaces = new Set([...Object.keys(a ?? {}), ...Object.keys(b ?? {})]);
1313
+ const result = {};
1314
+ for (const namespaceId of namespaces) result[namespaceId] = mergePackEntityKinds(namespaceId, a?.[namespaceId], b?.[namespaceId]);
1315
+ return result;
1316
+ }
1293
1317
  /** Implementation. */
1294
1318
  function buildBoundContract(family, target, definition, factory) {
1295
1319
  const full = {
@@ -1307,11 +1331,13 @@ function buildBoundContract(family, target, definition, factory) {
1307
1331
  ...definition.enums ?? {},
1308
1332
  ...built.enums
1309
1333
  };
1334
+ const mergedPackEntities = mergePackEntities(definition.packEntities, built.packEntities);
1310
1335
  return buildContractFromDsl({
1311
1336
  ...full,
1312
1337
  ...ifDefined("types", built.types),
1313
1338
  ...ifDefined("models", built.models),
1314
- ...ifDefined("enums", Object.keys(mergedEnums).length > 0 ? mergedEnums : void 0)
1339
+ ...ifDefined("enums", Object.keys(mergedEnums).length > 0 ? mergedEnums : void 0),
1340
+ ...ifDefined("packEntities", mergedPackEntities)
1315
1341
  });
1316
1342
  }
1317
1343
  return buildContractFromDsl(full);