@prisma/orm-family-sql 8.0.0-rc.21-dev.13 → 8.0.0-rc.21-dev.15

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.
Files changed (51) hide show
  1. package/dist/{attribute-specs-DDpSUaG9.d.mts → attribute-specs-BhWwV_Uu.d.mts} +3 -3
  2. package/dist/{attribute-specs-DDpSUaG9.d.mts.map → attribute-specs-BhWwV_Uu.d.mts.map} +1 -1
  3. package/dist/{authoring-entity-types-CgKIgWq5-BqRjoPFF.d.mts → authoring-entity-types-CgKIgWq5-DrdNt_VL.d.mts} +2 -2
  4. package/dist/{authoring-entity-types-CgKIgWq5-BqRjoPFF.d.mts.map → authoring-entity-types-CgKIgWq5-DrdNt_VL.d.mts.map} +1 -1
  5. package/dist/{contract-builder-D6JuOGA6.d.mts → contract-builder-1Ml9yJ0j.d.mts} +9 -3
  6. package/dist/{contract-builder-D6JuOGA6.d.mts.map → contract-builder-1Ml9yJ0j.d.mts.map} +1 -1
  7. package/dist/{contract-builder-D50r41BU.mjs → contract-builder-Y2rB4xMf.mjs} +18 -3
  8. package/dist/contract-builder-Y2rB4xMf.mjs.map +1 -0
  9. package/dist/contract-prisma7__provider.d.mts +16 -0
  10. package/dist/contract-prisma7__provider.d.mts.map +1 -1
  11. package/dist/contract-prisma7__provider.mjs +195 -11
  12. package/dist/contract-prisma7__provider.mjs.map +1 -1
  13. package/dist/contract-psl.d.mts +1 -1
  14. package/dist/contract-psl.mjs +1 -1
  15. package/dist/contract-psl__attribute-specs.d.mts +1 -1
  16. package/dist/contract-psl__provider.mjs +1 -1
  17. package/dist/contract-psl__provider.mjs.map +1 -1
  18. package/dist/contract-ts.d.mts +2 -2
  19. package/dist/contract-ts.mjs +2 -2
  20. package/dist/contract-ts__contract-builder.d.mts +2 -2
  21. package/dist/contract-ts__contract-builder.mjs +2 -2
  22. package/dist/contract.d.mts +2 -2
  23. package/dist/contract.mjs +2 -2
  24. package/dist/contract__entity-handle-lowering-hook.d.mts +2 -2
  25. package/dist/contract__entity-handle-lowering-hook.mjs +2 -2
  26. package/dist/{control-BE7gXqZF.d.mts → control-BuY5mjLl.d.mts} +3 -3
  27. package/dist/{control-BE7gXqZF.d.mts.map → control-BuY5mjLl.d.mts.map} +1 -1
  28. package/dist/{control-DPCrkpMS.mjs → control-w9vYxuDF.mjs} +2 -2
  29. package/dist/{control-DPCrkpMS.mjs.map → control-w9vYxuDF.mjs.map} +1 -1
  30. package/dist/{entity-handle-lowering-hook-BJZSlVVF.mjs → entity-handle-lowering-hook-3KYrW-BT.mjs} +5 -2
  31. package/dist/entity-handle-lowering-hook-3KYrW-BT.mjs.map +1 -0
  32. package/dist/{entity-handle-lowering-hook-BuvLtgFi.d.mts → entity-handle-lowering-hook-Bmgnj7Dk.d.mts} +9 -2
  33. package/dist/{entity-handle-lowering-hook-BuvLtgFi.d.mts.map → entity-handle-lowering-hook-Bmgnj7Dk.d.mts.map} +1 -1
  34. package/dist/family.d.mts +2 -2
  35. package/dist/family.mjs +2 -2
  36. package/dist/family__control.d.mts +1 -1
  37. package/dist/family__control.mjs +1 -1
  38. package/dist/family__pack.d.mts +1 -1
  39. package/dist/family__pack.mjs +1 -1
  40. package/dist/{generator-functions-Hy4pDDr9-CMfJOBtv.mjs → generator-functions-Hy4pDDr9-HEQuSSaK.mjs} +2 -2
  41. package/dist/{generator-functions-Hy4pDDr9-CMfJOBtv.mjs.map → generator-functions-Hy4pDDr9-HEQuSSaK.mjs.map} +1 -1
  42. package/dist/{interpreter-ChvVEijY-FeJngsog.mjs → interpreter-6czZvMo_-C2_2jQGn.mjs} +21 -15
  43. package/dist/interpreter-6czZvMo_-C2_2jQGn.mjs.map +1 -0
  44. package/dist/{pack-DKM1hv1E.d.mts → pack-DXK_yIeS.d.mts} +3 -3
  45. package/dist/{pack-DKM1hv1E.d.mts.map → pack-DXK_yIeS.d.mts.map} +1 -1
  46. package/dist/{psl-column-resolution-djGEITmJ-C0LSpwl4.d.mts → psl-column-resolution-djGEITmJ-BEln16CX.d.mts} +2 -2
  47. package/dist/{psl-column-resolution-djGEITmJ-C0LSpwl4.d.mts.map → psl-column-resolution-djGEITmJ-BEln16CX.d.mts.map} +1 -1
  48. package/package.json +18 -18
  49. package/dist/contract-builder-D50r41BU.mjs.map +0 -1
  50. package/dist/entity-handle-lowering-hook-BJZSlVVF.mjs.map +0 -1
  51. package/dist/interpreter-ChvVEijY-FeJngsog.mjs.map +0 -1
@@ -5,8 +5,9 @@ import { h as storedSqlText } from "./sql-expression-CKgKznXS.mjs";
5
5
  import { p as validateSqlStorageConsistency, u as validateModelStorageReferences } from "./validators-qcQteqs2.mjs";
6
6
  import { t as deriveValueSetFromEntity } from "./value-set-derivation-hook-HVaxhALD.mjs";
7
7
  import { n as buildSqlContractFromDefinition, t as applySqlSpecifierControlPolicy } from "./derived-checks-D__agoFB-Boa1MHcA.mjs";
8
+ import { o as composedExtensionPackRefs } from "./contract-builder-Y2rB4xMf.mjs";
8
9
  import { c as instantiateFieldTypeConstructor, i as defaultFunctionCall, v as readDataTypeDefault } from "./psl-field-resolution-BW2_FOb9-DxqR43fo.mjs";
9
- import { a as normalizeReferentialAction, n as buildEntityTypesByDiscriminator, r as indexFkRelations, t as applyBackrelationCandidates } from "./interpreter-ChvVEijY-FeJngsog.mjs";
10
+ import { a as normalizeReferentialAction, n as buildEntityTypesByDiscriminator, r as indexFkRelations, t as applyBackrelationCandidates } from "./interpreter-6czZvMo_-C2_2jQGn.mjs";
10
11
  import { isStructuredError } from "@prisma/orm-framework/utils/structured-error";
11
12
  import { ifDefined } from "@prisma/orm-framework/utils/defined";
12
13
  import { entryForTag, getAuthoringTypeChoice, getAuthoringTypeConstructor, instantiateAuthoringEntityType, instantiateAuthoringTypeConstructorFromValues, resolveAuthoringTypeChoice } from "@prisma/orm-framework/components/authoring";
@@ -501,6 +502,135 @@ function dbgeneratedDefault(callArgs, unknown, span) {
501
502
  onCreate: void 0
502
503
  };
503
504
  }
505
+ const PRISMA7_EXTENSION_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
506
+ function entryValue(source, key) {
507
+ return source.block.entries.find((entry) => entry.key()?.name() === key);
508
+ }
509
+ function stringOf(expression) {
510
+ return expression === void 0 ? void 0 : StringLiteralExprAst.cast(expression.syntax)?.value();
511
+ }
512
+ function previewFeatures(generators) {
513
+ const features = /* @__PURE__ */ new Set();
514
+ for (const generator of generators) {
515
+ const value = entryValue(generator, "previewFeatures")?.value();
516
+ const list = value === void 0 ? void 0 : ArrayLiteralAst.cast(value.syntax);
517
+ for (const element of list?.elements() ?? []) {
518
+ const feature = stringOf(element);
519
+ if (feature !== void 0) features.add(feature);
520
+ }
521
+ }
522
+ return features;
523
+ }
524
+ function text(node) {
525
+ return printSyntax(node.syntax).trim();
526
+ }
527
+ /**
528
+ * The datasource `extensions` list: each listed extension no composed pack's contract declares, in the namespace of its `schema:` argument or the default one. An extension a composed pack's contract declares is left to that pack; one the binding names a pack for that is not composed, and arguments the contract cannot describe, are reported.
529
+ */
530
+ function readDatasourceExtensions(input) {
531
+ const { datasource, binding, diagnostics } = input;
532
+ const { sourceId, sources } = datasource;
533
+ const entry = entryValue(datasource, "extensions");
534
+ const value = entry?.value();
535
+ if (entry === void 0 || value === void 0) return [];
536
+ if (!previewFeatures(input.generators).has(binding.previewFeature)) {
537
+ diagnostics.push(prisma7Diagnostic("PSL.PRISMA7_EXTENSIONS_PREVIEW_FEATURE_MISSING", `The datasource lists extensions, which Prisma 7 reads only with the "${binding.previewFeature}" preview feature, so Prisma 7 refuses this schema too. Add "${binding.previewFeature}" to previewFeatures in the generator block.`, sourceId, nodePslSpan(entry.syntax, sources)));
538
+ return [];
539
+ }
540
+ const invalid = (what, span) => {
541
+ diagnostics.push({
542
+ code: "PSL_INVALID_EXTENSION_BLOCK_MEMBER",
543
+ message: `datasource "${datasource.block.name}": ${what}, and Prisma 7 refuses it too. List each extension by name, such as extensions = [pg_trgm].`,
544
+ sourceId,
545
+ span
546
+ });
547
+ };
548
+ const list = ArrayLiteralAst.cast(value.syntax);
549
+ if (list === void 0) {
550
+ invalid(`extensions is ${text(value)}, which is not a list`, nodePslSpan(value.syntax, sources));
551
+ return [];
552
+ }
553
+ const extensions = /* @__PURE__ */ new Map();
554
+ for (const element of list.elements()) {
555
+ const span = nodePslSpan(element.syntax, sources);
556
+ const call = FunctionCallAst.cast(element.syntax);
557
+ if (dottedPathsIn(element).length > 0) continue;
558
+ const name = call === void 0 ? IdentifierAst.cast(element.syntax)?.name() : call.path()[0];
559
+ if (name === void 0) {
560
+ invalid(`extensions lists ${text(element)}, which is not an extension name`, span);
561
+ continue;
562
+ }
563
+ const schema = readArguments(name, call, input);
564
+ const namespaceId = schema ?? input.defaultNamespaceId;
565
+ const declaring = input.declaringPack(name);
566
+ if (declaring !== void 0) {
567
+ if (declaring.namespaceId !== namespaceId) {
568
+ const packNamespace = declaring.namespaceId;
569
+ const edit = schema === void 0 ? `write ${name}(schema: "${packNamespace}")` : packNamespace === input.defaultNamespaceId ? `remove schema: "${schema}"` : `write schema: "${packNamespace}"`;
570
+ diagnostics.push(prisma7Diagnostic("PSL.PRISMA7_EXTENSION_SCHEMA_MISMATCH", `Extension "${name}": the "${declaring.packId}" extension pack declares it in schema "${packNamespace}", so Prisma 8 expects it there, but this entry puts it in schema "${namespaceId}". Moving it is a database change the pack does not make: move it with ALTER EXTENSION "${name}" SET SCHEMA "${packNamespace}", then ${edit}.`, sourceId, span));
571
+ }
572
+ continue;
573
+ }
574
+ const pack = Object.hasOwn(binding.packs, name) ? binding.packs[name] : void 0;
575
+ if (pack !== void 0 && !input.composedExtensions.has(pack.id)) {
576
+ diagnostics.push(prisma7Diagnostic("PSL.PRISMA7_EXTENSION_PACK_MISSING", `Extension "${name}" is declared by the "${pack.id}" extension pack, which is not available. Add the pack to extensions in prisma.config.ts: import ${pack.importName} from '${pack.importPath}', then extensions: [${pack.importName}].`, sourceId, span));
577
+ continue;
578
+ }
579
+ if (!extensions.has(name)) extensions.set(name, {
580
+ name,
581
+ namespaceId,
582
+ span,
583
+ sourceId
584
+ });
585
+ }
586
+ return [...extensions.values()];
587
+ }
588
+ /** Reports each argument the contract cannot describe; returns the `schema:` argument's value. */
589
+ function readArguments(name, call, input) {
590
+ if (call === void 0) return void 0;
591
+ const { sourceId, sources } = input.datasource;
592
+ const args = [...call.args()];
593
+ const refuse = (arg, message) => {
594
+ input.diagnostics.push(prisma7Diagnostic("PSL.PRISMA7_EXTENSION_ARGUMENT_UNSUPPORTED", `Extension "${name}": ${message}`, sourceId, nodePslSpan(arg.syntax, sources)));
595
+ };
596
+ let schema;
597
+ for (const arg of args) {
598
+ const argName = arg.name()?.name();
599
+ const argValue = stringOf(arg.value());
600
+ if (argName === void 0) {
601
+ refuse(arg, `the argument ${text(arg)} has no name, and Prisma 7 refuses it too. Remove it.`);
602
+ continue;
603
+ }
604
+ if (argValue === void 0 && [
605
+ "schema",
606
+ "version",
607
+ "map"
608
+ ].includes(argName)) {
609
+ refuse(arg, `${argName} must be a string, and Prisma 7 refuses ${text(arg)} too.`);
610
+ continue;
611
+ }
612
+ switch (argName) {
613
+ case "schema":
614
+ schema = argValue;
615
+ break;
616
+ case "version":
617
+ refuse(arg, `the version argument is not supported, because the contract does not record an extension's version. Remove ${text(arg)}; Prisma 7's next migration is then empty.`);
618
+ break;
619
+ case "map": {
620
+ if (argValue === void 0 || !PRISMA7_EXTENSION_NAME.test(argValue)) {
621
+ refuse(arg, `the map argument is not supported, and Prisma 7 can write the name "${argValue}" only with map, so Prisma 8 cannot read this schema until it reads map.`);
622
+ break;
623
+ }
624
+ const others = args.filter((other) => other !== arg).map(text);
625
+ const replacement = others.length === 0 ? argValue : `${argValue}(${others.join(", ")})`;
626
+ refuse(arg, `the map argument is not supported. Replace ${text(call)} with ${replacement}, the extension's name in the database; Prisma 7's next migration is then empty.`);
627
+ break;
628
+ }
629
+ default: refuse(arg, `argument "${argName}" is not known, and Prisma 7 refuses it too. Remove it.`);
630
+ }
631
+ }
632
+ return schema;
633
+ }
504
634
  function prisma7ScalarMapping(typeMap, scalar) {
505
635
  return Object.hasOwn(typeMap.scalars, scalar) ? typeMap.scalars[scalar] : void 0;
506
636
  }
@@ -1145,6 +1275,7 @@ function interpretPrisma7Documents(input) {
1145
1275
  const diagnostics = [...input.seedDiagnostics];
1146
1276
  const { defaultNamespaceId } = input;
1147
1277
  const datasources = [];
1278
+ const generators = [];
1148
1279
  const enumBlocks = [];
1149
1280
  const models = [];
1150
1281
  const declaredNames = /* @__PURE__ */ new Map();
@@ -1201,6 +1332,12 @@ function interpretPrisma7Documents(input) {
1201
1332
  reportDottedBlockValues(block, sourceId, sources, diagnostics);
1202
1333
  break;
1203
1334
  case "generator":
1335
+ generators.push({
1336
+ block,
1337
+ sourceId,
1338
+ sources,
1339
+ sourceFile
1340
+ });
1204
1341
  reportDottedBlockValues(block, sourceId, sources, diagnostics);
1205
1342
  break;
1206
1343
  case "enum":
@@ -1248,6 +1385,16 @@ function interpretPrisma7Documents(input) {
1248
1385
  if (declaration !== void 0) enums.set(declaration.name, declaration);
1249
1386
  }
1250
1387
  const namespaceEntities = lowerNativeEnums(enums, input, diagnostics);
1388
+ const [datasource] = datasources;
1389
+ if (datasource !== void 0) lowerDatasourceExtensions(readDatasourceExtensions({
1390
+ datasource,
1391
+ generators,
1392
+ binding: binding.extensions,
1393
+ composedExtensions: new Set(input.composedExtensions),
1394
+ declaringPack: (extensionName) => packDeclaring(input.composedExtensionContracts, binding.extensions.entityKind, extensionName),
1395
+ defaultNamespaceId,
1396
+ diagnostics
1397
+ }), namespaceEntities, input, diagnostics);
1251
1398
  const modelNames = new Set(models.map((model) => model.symbol.name));
1252
1399
  const ignoredModels = new Set(models.filter((model) => model.ignored).map((model) => model.symbol.name));
1253
1400
  const composedExtensions = new Set(input.composedExtensions);
@@ -1397,6 +1544,7 @@ function interpretPrisma7Documents(input) {
1397
1544
  target: binding.target,
1398
1545
  warnings: void 0,
1399
1546
  createNamespace,
1547
+ ...ifDefined("extensions", composedExtensionPackRefs(binding.target, input.composedExtensions)),
1400
1548
  ...namespaceEntities.size > 0 ? { namespaces: [...namespaceEntities.keys()] } : {},
1401
1549
  models: modelNodes,
1402
1550
  ...tables.length > 0 ? { tables } : {}
@@ -1593,6 +1741,50 @@ function readEnumDeclaration(source, defaultNamespaceId, diagnostics) {
1593
1741
  sourceId
1594
1742
  };
1595
1743
  }
1744
+ function packDeclaring(packContracts, entityKind, name) {
1745
+ for (const [packId, contract] of packContracts) for (const [namespaceId, namespace] of Object.entries(contract.storage.namespaces)) if (Object.hasOwn(namespace.entries[entityKind] ?? {}, name)) return {
1746
+ packId,
1747
+ namespaceId
1748
+ };
1749
+ }
1750
+ function entityContext(input, sourceId, diagnostics) {
1751
+ return {
1752
+ family: input.binding.target.familyId,
1753
+ target: input.binding.target.targetId,
1754
+ codecLookup: input.codecLookup,
1755
+ dataTypes: input.dataTypes,
1756
+ sourceId,
1757
+ diagnostics: { push: (diagnostic) => {
1758
+ diagnostics.push(blindCast(diagnostic));
1759
+ } }
1760
+ };
1761
+ }
1762
+ /** Files each extension the application's contract declares under its namespace, as the target's extension entity. */
1763
+ function lowerDatasourceExtensions(extensions, namespaceEntities, input, diagnostics) {
1764
+ if (extensions.length === 0) return;
1765
+ const { entityKind } = input.binding.extensions;
1766
+ const descriptor = buildEntityTypesByDiscriminator(input.authoringContributions).get(entityKind);
1767
+ if (descriptor === void 0) throw new InternalError(`The Prisma 7 binding names the extension entity kind "${entityKind}", which target "${input.binding.target.targetId}" does not register.`);
1768
+ for (const extension of extensions) {
1769
+ const entity = instantiateAuthoringEntityType(entityKind, descriptor, [{
1770
+ kind: entityKind,
1771
+ keyword: entityKind,
1772
+ name: extension.name,
1773
+ values: {},
1774
+ writtenValues: {},
1775
+ parameterSpans: {},
1776
+ attributes: {},
1777
+ span: extension.span,
1778
+ namespaceId: extension.namespaceId
1779
+ }], entityContext(input, extension.sourceId, diagnostics));
1780
+ const entities = namespaceEntities.get(extension.namespaceId) ?? {};
1781
+ namespaceEntities.set(extension.namespaceId, entities);
1782
+ entities[entityKind] = {
1783
+ ...entities[entityKind],
1784
+ [extension.name]: entity
1785
+ };
1786
+ }
1787
+ }
1596
1788
  function lowerNativeEnums(enums, input, diagnostics) {
1597
1789
  const result = /* @__PURE__ */ new Map();
1598
1790
  if (enums.size === 0) return result;
@@ -1603,16 +1795,7 @@ function lowerNativeEnums(enums, input, diagnostics) {
1603
1795
  diagnostics.push(prisma7Diagnostic("PSL.PRISMA7_UNSUPPORTED_TYPE", `Enum "${declaration.name}" cannot be lowered: target "${input.binding.target.targetId}" registers no "${entityKind}" entity kind.`, declaration.sourceId, declaration.span));
1604
1796
  continue;
1605
1797
  }
1606
- const context = {
1607
- family: input.binding.target.familyId,
1608
- target: input.binding.target.targetId,
1609
- codecLookup: input.codecLookup,
1610
- dataTypes: input.dataTypes,
1611
- sourceId: declaration.sourceId,
1612
- diagnostics: { push: (diagnostic) => {
1613
- diagnostics.push(blindCast(diagnostic));
1614
- } }
1615
- };
1798
+ const context = entityContext(input, declaration.sourceId, diagnostics);
1616
1799
  const values = Object.create(null);
1617
1800
  const writtenValues = Object.create(null);
1618
1801
  const parameterSpans = Object.create(null);
@@ -2048,6 +2231,7 @@ function prisma7Contract(schemaPath, options) {
2048
2231
  codecLookup: context.codecLookup,
2049
2232
  dataTypes: context.dataTypes,
2050
2233
  composedExtensions: context.composedExtensions,
2234
+ composedExtensionContracts: context.composedExtensionContracts,
2051
2235
  defaultNamespaceId: context.defaultNamespaceId
2052
2236
  });
2053
2237
  if (!interpreted.ok) return interpreted;