@prisma/orm-family-sql 8.0.0-rc.11-dev.32 → 8.0.0-rc.11-dev.34
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/{authoring-type-constructors-C1ogrr_x-BziNu7gs.mjs → authoring-type-constructors-C1ogrr_x-V3OpvQTx.mjs} +2 -2
- package/dist/{authoring-type-constructors-C1ogrr_x-BziNu7gs.mjs.map → authoring-type-constructors-C1ogrr_x-V3OpvQTx.mjs.map} +1 -1
- package/dist/{contract-builder-C8uKThYB.d.mts → contract-builder-BnirYYsD.d.mts} +5 -5
- package/dist/{contract-builder-C8uKThYB.d.mts.map → contract-builder-BnirYYsD.d.mts.map} +1 -1
- package/dist/{contract-builder-CkT67-Wq.mjs → contract-builder-W6jqU1qo.mjs} +7 -7
- package/dist/contract-builder-W6jqU1qo.mjs.map +1 -0
- package/dist/contract-prisma7__provider.mjs +58 -44
- package/dist/contract-prisma7__provider.mjs.map +1 -1
- package/dist/contract-psl.d.mts +6 -6
- package/dist/contract-psl.d.mts.map +1 -1
- package/dist/contract-psl.mjs +1 -1
- package/dist/contract-psl__attribute-specs.d.mts +2 -2
- package/dist/contract-psl__attribute-specs.d.mts.map +1 -1
- package/dist/contract-psl__attribute-specs.mjs +1 -1
- package/dist/contract-psl__provider.mjs +11 -20
- package/dist/contract-psl__provider.mjs.map +1 -1
- package/dist/contract-ts.d.mts +1 -1
- package/dist/contract-ts.mjs +1 -1
- package/dist/contract-ts__contract-builder.d.mts +1 -1
- package/dist/contract-ts__contract-builder.mjs +1 -1
- package/dist/{control-dqbsNN69.mjs → control-liGaqQ0q.mjs} +27 -28
- package/dist/control-liGaqQ0q.mjs.map +1 -0
- package/dist/diff-B16bL_IR.mjs.map +1 -1
- package/dist/family.mjs +5 -5
- package/dist/family__control.mjs +2 -2
- package/dist/family__diff.mjs +1 -1
- package/dist/family__ir.mjs +1 -1
- package/dist/family__pack.mjs +2 -2
- package/dist/family__psl-infer.mjs +1 -1
- package/dist/family__verify.mjs +1 -1
- package/dist/{interpreter-9Ru2E-MH-CQdWmnh8.mjs → interpreter-C8N5eRW1-LGv-WI9y.mjs} +280 -336
- package/dist/interpreter-C8N5eRW1-LGv-WI9y.mjs.map +1 -0
- package/dist/ir-I-xciGUH.mjs.map +1 -1
- package/dist/{psl-infer-DyRJ8dw6.mjs → psl-infer-CsCbcmXS.mjs} +4 -2
- package/dist/psl-infer-CsCbcmXS.mjs.map +1 -0
- package/dist/{schema-verify-C_PEdlAr-CmXrFuW1.mjs → schema-verify-CrvQZ5V8-BfrNHJbX.mjs} +3 -3
- package/dist/schema-verify-CrvQZ5V8-BfrNHJbX.mjs.map +1 -0
- package/dist/{sql-attribute-specs-CHSP1wKs-D5T2TZQ8.mjs → sql-attribute-specs-DAEpjrWl-C0kmaUJt.mjs} +11 -16
- package/dist/sql-attribute-specs-DAEpjrWl-C0kmaUJt.mjs.map +1 -0
- package/dist/{sql-contract-serializer-Bxu4a5oQ-CNy5ONMn.mjs → sql-contract-serializer-C4HbCKFe-BD1Fx4JX.mjs} +6 -6
- package/dist/sql-contract-serializer-C4HbCKFe-BD1Fx4JX.mjs.map +1 -0
- package/dist/{verify-ChiDeTk8-HEewdjrM.mjs → verify-BVk5bjdH-BXgGLM2U.mjs} +6 -5
- package/dist/verify-BVk5bjdH-BXgGLM2U.mjs.map +1 -0
- package/package.json +18 -18
- package/dist/contract-builder-CkT67-Wq.mjs.map +0 -1
- package/dist/control-dqbsNN69.mjs.map +0 -1
- package/dist/interpreter-9Ru2E-MH-CQdWmnh8.mjs.map +0 -1
- package/dist/psl-infer-DyRJ8dw6.mjs.map +0 -1
- package/dist/schema-verify-C_PEdlAr-CmXrFuW1.mjs.map +0 -1
- package/dist/sql-attribute-specs-CHSP1wKs-D5T2TZQ8.mjs.map +0 -1
- package/dist/sql-contract-serializer-Bxu4a5oQ-CNy5ONMn.mjs.map +0 -1
- package/dist/verify-ChiDeTk8-HEewdjrM.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"psl-infer-CsCbcmXS.mjs","names":[],"sources":["../../../../2-sql/9-family/dist/psl-infer.mjs"],"sourcesContent":["import { InternalError } from \"@internal/utils/internal-error\";\nimport { defaultTableName } from \"@internal/sql-contract-psl/default-table-name\";\nimport pluralizeLib from \"pluralize\";\nimport { backingIndexColumnKeys, isBackedByColumnKeys } from \"@internal/sql-contract/foreign-key-materialization\";\n//#region src/core/psl-contract-infer/default-mapping.ts\nconst DEFAULT_FUNCTION_ATTRIBUTES = {\n\t\"autoincrement()\": \"@default(autoincrement())\",\n\t\"now()\": \"@default(now())\"\n};\nfunction mapDefault(columnDefault, options) {\n\tswitch (columnDefault.kind) {\n\t\tcase \"literal\": return { attribute: `@default(${formatLiteralValue(columnDefault.value)})` };\n\t\tcase \"function\": {\n\t\t\tconst attribute = options?.functionAttributes?.[columnDefault.expression] ?? DEFAULT_FUNCTION_ATTRIBUTES[columnDefault.expression] ?? options?.fallbackFunctionAttribute?.(columnDefault.expression);\n\t\t\treturn attribute ? { attribute } : { comment: `// Raw default: ${columnDefault.expression.replace(/[\\r\\n]+/g, \" \")}` };\n\t\t}\n\t}\n}\nfunction formatLiteralValue(value) {\n\tif (value === null) return \"null\";\n\tswitch (typeof value) {\n\t\tcase \"boolean\":\n\t\tcase \"number\": return String(value);\n\t\tcase \"string\": return quoteString(value);\n\t\tdefault: return quoteString(JSON.stringify(value));\n\t}\n}\nfunction quoteString(str) {\n\treturn `\"${escapeString(str)}\"`;\n}\nfunction escapeString(str) {\n\treturn JSON.stringify(str).slice(1, -1);\n}\n//#endregion\n//#region src/core/psl-contract-infer/name-transforms.ts\nconst PSL_RESERVED_WORDS = /* @__PURE__ */ new Set([\n\t\"model\",\n\t\"enum\",\n\t\"types\",\n\t\"type\",\n\t\"generator\",\n\t\"datasource\"\n]);\nconst IDENTIFIER_PART_PATTERN = /[A-Za-z0-9]+/g;\nfunction hasSeparators(input) {\n\treturn /[^A-Za-z0-9]/.test(input);\n}\nfunction extractIdentifierParts(input) {\n\treturn input.match(IDENTIFIER_PART_PATTERN) ?? [];\n}\nfunction createSyntheticIdentifier(input) {\n\tlet hash = 2166136261;\n\tfor (const char of input) {\n\t\thash ^= char.codePointAt(0) ?? 0;\n\t\thash = Math.imul(hash, 16777619);\n\t}\n\treturn `x${(hash >>> 0).toString(16)}`;\n}\nfunction sanitizeIdentifierCharacters(input) {\n\tconst sanitized = input.replace(/[^\\w]/g, \"\");\n\treturn sanitized.length > 0 ? sanitized : createSyntheticIdentifier(input);\n}\nfunction capitalize(word) {\n\treturn word.charAt(0).toUpperCase() + word.slice(1);\n}\nfunction snakeToPascalCase(input) {\n\tconst parts = extractIdentifierParts(input);\n\tif (parts.length === 0) return capitalize(sanitizeIdentifierCharacters(input));\n\treturn parts.map(capitalize).join(\"\");\n}\nfunction snakeToCamelCase(input) {\n\tconst parts = extractIdentifierParts(input);\n\tif (parts.length === 0) return sanitizeIdentifierCharacters(input);\n\tconst [firstPart = input, ...rest] = parts;\n\treturn firstPart.charAt(0).toLowerCase() + firstPart.slice(1) + rest.map(capitalize).join(\"\");\n}\nfunction needsEscaping(name) {\n\treturn PSL_RESERVED_WORDS.has(name.toLowerCase()) || /^\\d/.test(name);\n}\nfunction escapeName(name) {\n\treturn `_${name}`;\n}\nfunction escapeIfNeeded(name) {\n\treturn needsEscaping(name) ? escapeName(name) : name;\n}\nfunction toModelName(tableName) {\n\tlet name;\n\tif (hasSeparators(tableName)) name = snakeToPascalCase(tableName);\n\telse name = tableName.charAt(0).toUpperCase() + tableName.slice(1);\n\tif (needsEscaping(name)) return {\n\t\tname: escapeName(name),\n\t\tmap: tableName\n\t};\n\tif (defaultTableName(name) !== tableName) return {\n\t\tname,\n\t\tmap: tableName\n\t};\n\treturn { name };\n}\nfunction toFieldName(columnName) {\n\tlet name;\n\tif (hasSeparators(columnName)) name = snakeToCamelCase(columnName);\n\telse name = columnName.charAt(0).toLowerCase() + columnName.slice(1);\n\tif (needsEscaping(name)) return {\n\t\tname: escapeName(name),\n\t\tmap: columnName\n\t};\n\tif (name !== columnName) return {\n\t\tname,\n\t\tmap: columnName\n\t};\n\treturn { name };\n}\nfunction toEnumName(pgTypeName) {\n\tlet name;\n\tif (hasSeparators(pgTypeName)) name = snakeToPascalCase(pgTypeName);\n\telse name = pgTypeName.charAt(0).toUpperCase() + pgTypeName.slice(1);\n\tif (needsEscaping(name)) return {\n\t\tname: escapeName(name),\n\t\tmap: pgTypeName\n\t};\n\tif (name !== pgTypeName) return {\n\t\tname,\n\t\tmap: pgTypeName\n\t};\n\treturn { name };\n}\nconst VALID_IDENTIFIER_PATTERN = /^[A-Za-z_]\\w*$/;\n/**\n* PSL member name for a native-enum value. The value itself always prints\n* explicitly (`member = \"value\"`), so the returned name never needs a map:\n* a value that already is a valid, non-reserved identifier is kept verbatim\n* (case included); anything else is camelCased/escaped like a field name.\n*/\nfunction toEnumMemberName(value) {\n\tif (VALID_IDENTIFIER_PATTERN.test(value) && !needsEscaping(value)) return value;\n\treturn escapeIfNeeded(snakeToCamelCase(value));\n}\nfunction pluralize(word) {\n\treturn pluralizeLib.plural(word);\n}\nfunction deriveRelationFieldName(fkColumns, referencedTableName) {\n\tif (fkColumns.length === 1) {\n\t\tconst [col = referencedTableName] = fkColumns;\n\t\tconst stripped = col.replace(/_id$/i, \"\").replace(/Id$/, \"\");\n\t\tif (stripped.length > 0 && stripped !== col) return escapeIfNeeded(snakeToCamelCase(stripped));\n\t\treturn escapeIfNeeded(snakeToCamelCase(referencedTableName));\n\t}\n\treturn escapeIfNeeded(snakeToCamelCase(referencedTableName));\n}\nfunction deriveBackRelationFieldName(childModelName, isOneToOne) {\n\tconst base = childModelName.charAt(0).toLowerCase() + childModelName.slice(1);\n\treturn isOneToOne ? base : pluralize(base);\n}\n//#endregion\n//#region src/core/psl-contract-infer/relation-inference.ts\nconst DEFAULT_ON_DELETE = \"noAction\";\nconst DEFAULT_ON_UPDATE = \"noAction\";\nconst REFERENTIAL_ACTION_PSL = {\n\tnoAction: \"NoAction\",\n\trestrict: \"Restrict\",\n\tcascade: \"Cascade\",\n\tsetNull: \"SetNull\",\n\tsetDefault: \"SetDefault\"\n};\nfunction inferRelations(tables, modelNameMap) {\n\tconst relationsByTable = /* @__PURE__ */ new Map();\n\tconst fkCountByPair = /* @__PURE__ */ new Map();\n\tfor (const table of Object.values(tables)) for (const fk of table.foreignKeys) {\n\t\tconst pairKey = `${table.name}→${fk.referencedTable}`;\n\t\tfkCountByPair.set(pairKey, (fkCountByPair.get(pairKey) ?? 0) + 1);\n\t}\n\tconst usedFieldNames = /* @__PURE__ */ new Map();\n\tfor (const table of Object.values(tables)) {\n\t\tconst names = /* @__PURE__ */ new Set();\n\t\tfor (const col of Object.values(table.columns)) names.add(col.name);\n\t\tusedFieldNames.set(table.name, names);\n\t}\n\tfor (const table of Object.values(tables)) for (const fk of table.foreignKeys) {\n\t\tconst childTableName = table.name;\n\t\tconst parentTableName = fk.referencedTable;\n\t\tconst childUsed = usedFieldNames.get(childTableName);\n\t\tif (childUsed === void 0) throw new InternalError(`Missing inferred field-name set for table \"${childTableName}\"`);\n\t\tconst childModelName = modelNameMap.get(childTableName) ?? childTableName;\n\t\tconst parentModelName = modelNameMap.get(parentTableName) ?? parentTableName;\n\t\tconst pairKey = `${childTableName}→${parentTableName}`;\n\t\tconst isSelfRelation = childTableName === parentTableName;\n\t\tconst needsRelationName = (fkCountByPair.get(pairKey) ?? 0) > 1 || isSelfRelation;\n\t\tconst isOneToOne = detectOneToOne(fk, table);\n\t\tconst childRelFieldName = resolveUniqueFieldName(deriveRelationFieldName(fk.columns, parentTableName), childUsed, parentModelName);\n\t\tconst relationName = needsRelationName ? deriveRelationName(fk, childRelFieldName, parentModelName, isSelfRelation) : void 0;\n\t\taddRelationField(relationsByTable, childTableName, buildChildRelationField(childRelFieldName, parentModelName, fk, fk.columns.some((columnName) => table.columns[columnName]?.nullable ?? false), relationName, table));\n\t\tchildUsed.add(childRelFieldName);\n\t\tconst parentUsed = usedFieldNames.get(parentTableName) ?? /* @__PURE__ */ new Set();\n\t\tusedFieldNames.set(parentTableName, parentUsed);\n\t\tconst backRelFieldName = resolveUniqueFieldName(deriveBackRelationFieldName(childModelName, isOneToOne), parentUsed, childModelName);\n\t\taddRelationField(relationsByTable, parentTableName, {\n\t\t\tfieldName: backRelFieldName,\n\t\t\ttypeName: childModelName,\n\t\t\toptional: isOneToOne,\n\t\t\tlist: !isOneToOne,\n\t\t\trelationName\n\t\t});\n\t\tparentUsed.add(backRelFieldName);\n\t}\n\treturn { relationsByTable };\n}\nfunction detectOneToOne(fk, table) {\n\tconst fkCols = [...fk.columns].sort();\n\tif (table.primaryKey) {\n\t\tconst pkCols = [...table.primaryKey.columns].sort();\n\t\tif (pkCols.length === fkCols.length && pkCols.every((c, i) => c === fkCols[i])) return true;\n\t}\n\tfor (const unique of table.uniques) {\n\t\tconst uniqueCols = [...unique.columns].sort();\n\t\tif (uniqueCols.length === fkCols.length && uniqueCols.every((c, i) => c === fkCols[i])) return true;\n\t}\n\tfor (const index of table.indexes) {\n\t\tif (!index.unique || index.partial || index.columns === void 0) continue;\n\t\tconst indexCols = [...index.columns].sort();\n\t\tif (indexCols.length === fkCols.length && indexCols.every((c, i) => c === fkCols[i])) return true;\n\t}\n\treturn false;\n}\nfunction deriveRelationName(fk, childRelationFieldName, parentModelName, isSelfRelation) {\n\tif (fk.name) return fk.name;\n\tif (isSelfRelation) return `${childRelationFieldName.charAt(0).toUpperCase() + childRelationFieldName.slice(1)}${pluralize(parentModelName)}`;\n\treturn fk.columns.join(\"_\");\n}\n/**\n* Builds the child-side {@link RelationField} for a single foreign key:\n* `typeName` is the parent model name, `fields`/`references` are the FK's raw\n* columns, and `onDelete`/`onUpdate` are normalized to their PSL spelling.\n* Exported so a caller resolving a foreign key against a model outside\n* `tables` (e.g. a cross-space reference into another contract) can reuse the\n* same normalization instead of duplicating it.\n*\n* `hostTable` is the table the FK is declared on (i.e. `table`, not the\n* referenced parent) — its own indexes/uniques/primary key are what a\n* backing index for this FK would be. When none of them exactly match the\n* FK's source columns (in order), `index: false` is stamped so the emitted\n* `@relation` opts out of the framework's default derived backing-index\n* expectation, matching what `db verify` will find live. Passing the table\n* is optional so existing single-FK callers (e.g. cross-space resolution\n* before a host table reference is threaded through) can omit it and keep\n* the framework default.\n*/\nfunction buildChildRelationField(fieldName, parentModelName, fk, optional, relationName, hostTable) {\n\tconst onDelete = fk.onDelete && fk.onDelete !== DEFAULT_ON_DELETE ? fk.onDelete : void 0;\n\tconst onUpdate = fk.onUpdate && fk.onUpdate !== DEFAULT_ON_UPDATE ? fk.onUpdate : void 0;\n\tconst index = hostTable && !isBackedByColumnKeys(fk.columns, backingIndexColumnKeys({\n\t\tindexes: hostTable.indexes.filter((i) => i.where === void 0),\n\t\tuniques: hostTable.uniques,\n\t\tprimaryKey: hostTable.primaryKey\n\t})) ? false : void 0;\n\treturn {\n\t\tfieldName,\n\t\ttypeName: parentModelName,\n\t\treferencedTableName: fk.referencedTable,\n\t\toptional,\n\t\tlist: false,\n\t\trelationName,\n\t\tfkName: fk.name,\n\t\tfields: fk.columns,\n\t\treferences: fk.referencedColumns,\n\t\tonDelete: onDelete ? REFERENTIAL_ACTION_PSL[onDelete] : void 0,\n\t\tonUpdate: onUpdate ? REFERENTIAL_ACTION_PSL[onUpdate] : void 0,\n\t\tindex\n\t};\n}\nfunction resolveUniqueFieldName(desired, usedNames, fallbackSuffix) {\n\tif (!usedNames.has(desired)) return desired;\n\tconst withSuffix = `${desired}${fallbackSuffix}`;\n\tif (!usedNames.has(withSuffix)) return withSuffix;\n\tlet counter = 2;\n\twhile (usedNames.has(`${desired}${counter}`)) counter++;\n\treturn `${desired}${counter}`;\n}\nfunction addRelationField(map, tableName, field) {\n\tconst existing = map.get(tableName);\n\tif (existing) existing.push(field);\n\telse map.set(tableName, [field]);\n}\n//#endregion\nexport { buildChildRelationField, deriveBackRelationFieldName, deriveRelationFieldName, inferRelations, mapDefault, p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AAI,OAAO,GAAG,OAAO;CACpC,MAAM,aAAa,GAAG,UAAU;CAChC,IAAI,CAAC,UAAU,IAAI,UAAU,GAAG,OAAO;CACvC,IAAI,UAAU;CACd,OAAO,UAAU,IAAI,GAAG,UAAU,SAAS,GAAG;CAC9C,OAAO,GAAG,UAAU;AACrB;AACA,SAAS,iBAAiB,KAAK,WAAW,OAAO;CAChD,MAAM,WAAW,IAAI,IAAI,SAAS;CAClC,IAAI,UAAU,SAAS,KAAK,KAAK;MAC5B,IAAI,IAAI,WAAW,CAAC,KAAK,CAAC;AAChC"}
|
|
@@ -3,10 +3,10 @@ import { effectiveControlPolicy } from "@prisma/orm-framework/contract/types";
|
|
|
3
3
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
4
4
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
5
5
|
import { assertUniqueCodecOwner, dispositionForCategory, issueOutcome } from "@prisma/orm-framework/components/control";
|
|
6
|
-
//#region ../../../2-sql/9-family/dist/schema-verify-
|
|
6
|
+
//#region ../../../2-sql/9-family/dist/schema-verify-CrvQZ5V8.mjs
|
|
7
7
|
function hasCodecControlHooks(descriptor) {
|
|
8
8
|
if (typeof descriptor !== "object" || descriptor === null) return false;
|
|
9
|
-
const hooks = descriptor.types?.codecTypes?.controlPlaneHooks;
|
|
9
|
+
const hooks = blindCast(descriptor).types?.codecTypes?.controlPlaneHooks;
|
|
10
10
|
return hooks !== null && hooks !== void 0 && typeof hooks === "object";
|
|
11
11
|
}
|
|
12
12
|
function extractCodecControlHooks(descriptors) {
|
|
@@ -217,4 +217,4 @@ function verifySqlSchemaByDiff(input) {
|
|
|
217
217
|
//#endregion
|
|
218
218
|
export { computeStorageTypeVerdict as a, computeSqlDiffVerdict as i, classifyDiffSubjectGranularity as n, extractCodecControlHooks as o, classifySqlDiffIssue as r, verifySqlSchemaByDiff as s, classifyDiffEntityKind as t };
|
|
219
219
|
|
|
220
|
-
//# sourceMappingURL=schema-verify-
|
|
220
|
+
//# sourceMappingURL=schema-verify-CrvQZ5V8-BfrNHJbX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-verify-CrvQZ5V8-BfrNHJbX.mjs","names":[],"sources":["../../../../2-sql/9-family/dist/schema-verify-CrvQZ5V8.mjs"],"sourcesContent":["import { blindCast } from \"@internal/utils/casts\";\nimport { assertUniqueCodecOwner, dispositionForCategory, issueOutcome } from \"@internal/framework-components/control\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { effectiveControlPolicy } from \"@internal/contract/types\";\nimport { isStorageTypeInstance } from \"@internal/sql-contract/types\";\n//#region src/core/assembly.ts\nfunction hasCodecControlHooks(descriptor) {\n\tif (typeof descriptor !== \"object\" || descriptor === null) return false;\n\tconst hooks = blindCast(descriptor).types?.codecTypes?.controlPlaneHooks;\n\treturn hooks !== null && hooks !== void 0 && typeof hooks === \"object\";\n}\nfunction extractCodecControlHooks(descriptors) {\n\tconst hooks = /* @__PURE__ */ new Map();\n\tconst owners = /* @__PURE__ */ new Map();\n\tfor (const descriptor of descriptors) {\n\t\tif (typeof descriptor !== \"object\" || descriptor === null) continue;\n\t\tif (!hasCodecControlHooks(descriptor)) continue;\n\t\tconst controlPlaneHooks = descriptor.types.codecTypes.controlPlaneHooks;\n\t\tfor (const [codecId, hook] of Object.entries(controlPlaneHooks)) {\n\t\t\tassertUniqueCodecOwner({\n\t\t\t\tcodecId,\n\t\t\t\towners,\n\t\t\t\tdescriptorId: descriptor.id,\n\t\t\t\tentityLabel: \"control hooks\",\n\t\t\t\tentityOwnershipLabel: \"owner\"\n\t\t\t});\n\t\t\thooks.set(codecId, hook);\n\t\t\towners.set(codecId, descriptor.id);\n\t\t}\n\t}\n\treturn hooks;\n}\n//#endregion\n//#region src/core/diff/verifier-disposition.ts\n/**\n* Classifies a codec `verifyType` hook finding into the target-neutral\n* categories the framework grades. A storage type is a named type instance\n* (e.g. a native enum); the only shape divergence it can carry is a change\n* to its value set, so a paired mismatch always classifies as `valueDrift`.\n*/\nfunction classifyStorageTypeDiffIssue(issue) {\n\tif (issueOutcome(issue) === \"not-found\") return \"declaredMissing\";\n\tif (issueOutcome(issue) === \"not-expected\") return \"extraAuxiliary\";\n\treturn \"valueDrift\";\n}\nfunction verifierDisposition(controlPolicy, issue) {\n\treturn dispositionForCategory(controlPolicy, classifyStorageTypeDiffIssue(issue));\n}\n//#endregion\n//#region src/core/diff/schema-verify.ts\nfunction issueNode(issue) {\n\tconst node = issue.expected ?? issue.actual;\n\tif (node === void 0) return void 0;\n\treturn blindCast(node);\n}\n/**\n* Resolves an issue's framework-neutral {@link DiffSubjectGranularity} on\n* demand, from the issue's node's `nodeKind` via the target-provided\n* `granularityOf` map. The node carries only its `nodeKind` identity, never a\n* classification, and nothing is stamped onto the issue — every consumer\n* (the family verdict below, the framework aggregate's unclaimed-elements\n* sweep via {@link import('@internal/framework-components/control').SchemaSubjectClassifierCapable})\n* calls this the same way, resolved by the family/target that owns the node\n* vocabulary. `undefined` for an issue with no node.\n*/\nfunction classifyDiffSubjectGranularity(issue, granularityOf) {\n\tconst node = issueNode(issue);\n\treturn node === void 0 ? void 0 : granularityOf(node.nodeKind);\n}\n/**\n* Resolves an issue's storage `entityKind` on demand, from the issue's\n* node's `nodeKind` via the target-provided `entityKindOf` map — the sibling\n* of {@link classifyDiffSubjectGranularity}, called the same way by the same\n* consumers (via\n* {@link import('@internal/framework-components/control').SchemaSubjectClassifierCapable}).\n* `undefined` for an issue with no node, or for a node kind with no storage\n* entity of its own.\n*/\nfunction classifyDiffEntityKind(issue, entityKindOf) {\n\tconst node = issueNode(issue);\n\treturn node === void 0 ? void 0 : entityKindOf(node.nodeKind);\n}\n/**\n* Re-keys the legacy `classifySqlVerifierIssueKind` category mapping on the\n* issue's {@link DiffSubjectGranularity} (resolved via `granularityOf`) + the\n* issue reason. The vocabulary maps one-to-one: an undeclared live entity or\n* namespace is `extraTopLevelObject`, an undeclared live field\n* `extraNestedElement`, undeclared auxiliaries (constraints, indexes,\n* defaults) and structural leaves (policies) `extraAuxiliary`; every paired\n* divergence is `declaredIncompatible`; anything the database lacks is\n* `declaredMissing`.\n* `granularityOf` is the target's classifier, so target and extension node\n* kinds classify without the family importing them.\n*/\nfunction classifySqlDiffIssue(issue, granularityOf) {\n\tif (issueOutcome(issue) === \"not-found\") return \"declaredMissing\";\n\tif (issueOutcome(issue) === \"not-expected\") {\n\t\tconst granularity = classifyDiffSubjectGranularity(issue, granularityOf);\n\t\tif (granularity === \"entity\" || granularity === \"namespace\") return \"extraTopLevelObject\";\n\t\tif (granularity === \"field\") return \"extraNestedElement\";\n\t\treturn \"extraAuxiliary\";\n\t}\n\treturn \"declaredIncompatible\";\n}\n/**\n* Whether a `not-expected` issue is a strict-mode-only finding. The legacy\n* walk detected every relational extra (namespaces, entities, fields, and\n* their auxiliaries) only under `--strict`; the structural diff (roots, RLS\n* policies, roles) was never strict-gated — its extras fail in both modes.\n* Keyed on the issue's granularity, resolved via `granularityOf`.\n*/\nfunction isStrictOnlyExtra(issue, granularityOf) {\n\tconst granularity = classifyDiffSubjectGranularity(issue, granularityOf);\n\treturn granularity === \"namespace\" || granularity === \"entity\" || granularity === \"field\" || granularity === \"auxiliary\";\n}\n/**\n* Applies the two consumer filters to a diff issue list: strict gating\n* (relational `not-expected` findings drop in lenient mode) and\n* control-policy disposition (each surviving issue grades against its\n* subject table's effective policy; suppressed issues drop, `observed`\n* subjects warn). The verify verdict is `failures.length === 0`.\n*/\nfunction computeSqlDiffVerdict(input) {\n\tconst failures = [];\n\tconst warnings = [];\n\tfor (const issue of input.issues) {\n\t\tif (!input.strict && issueOutcome(issue) === \"not-expected\" && isStrictOnlyExtra(issue, input.granularityOf)) continue;\n\t\tconst disposition = dispositionForCategory(effectiveControlPolicy(input.resolveControlPolicy(issue), input.defaultControlPolicy), classifySqlDiffIssue(issue, input.granularityOf));\n\t\tif (disposition === \"suppress\") continue;\n\t\tif (disposition === \"warn\") {\n\t\t\twarnings.push(issue);\n\t\t\tcontinue;\n\t\t}\n\t\tfailures.push(issue);\n\t}\n\treturn {\n\t\tfailures,\n\t\twarnings\n\t};\n}\nfunction computeStorageTypeVerdict(input) {\n\tconst failures = [];\n\tconst warnings = [];\n\tconst policy = effectiveControlPolicy(void 0, input.contract.defaultControlPolicy);\n\tfor (const pair of input.namespacePairs) {\n\t\tif (pair.actual === void 0) continue;\n\t\tfor (const [typeName, typeInstance] of Object.entries(input.contract.storage.types ?? {})) {\n\t\t\tif (!isStorageTypeInstance(typeInstance)) continue;\n\t\t\tconst hook = input.codecHooks.get(typeInstance.codecId);\n\t\t\tif (!hook?.verifyType) continue;\n\t\t\tconst typeIssues = hook.verifyType({\n\t\t\t\ttypeName,\n\t\t\t\ttypeInstance,\n\t\t\t\tschema: pair.actual\n\t\t\t});\n\t\t\tfor (const issue of typeIssues) {\n\t\t\t\tconst disposition = verifierDisposition(policy, issue);\n\t\t\t\tif (disposition === \"suppress\") continue;\n\t\t\t\tif (disposition === \"warn\") {\n\t\t\t\t\twarnings.push(issue);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfailures.push(issue);\n\t\t\t}\n\t\t}\n\t}\n\treturn {\n\t\tfailures,\n\t\twarnings\n\t};\n}\n/**\n* THE SQL schema verify: runs the target's full-tree node diff, grades it\n* through the family's post-diff filters (strict gating + control-policy\n* disposition) plus the codec `verifyType` hook findings, and wraps the\n* verdict in the issue-based result envelope. `ok` holds exactly when both\n* issue lists are empty — the lists carry the verdict's failures.\n*/\nfunction verifySqlSchemaByDiff(input) {\n\tconst startTime = Date.now();\n\tconst verdictDiff = input.diffSchema({\n\t\tcontract: input.contract,\n\t\tschema: input.schema,\n\t\tframeworkComponents: input.frameworkComponents\n\t});\n\tconst diffVerdict = computeSqlDiffVerdict({\n\t\tissues: verdictDiff.issues,\n\t\tresolveControlPolicy: verdictDiff.resolveControlPolicy,\n\t\tstrict: input.strict,\n\t\tdefaultControlPolicy: input.contract.defaultControlPolicy,\n\t\tgranularityOf: input.granularityOf\n\t});\n\tconst storageTypeVerdict = computeStorageTypeVerdict({\n\t\tcontract: input.contract,\n\t\tnamespacePairs: verdictDiff.namespacePairs,\n\t\tcodecHooks: extractCodecControlHooks(input.frameworkComponents)\n\t});\n\tconst failCount = diffVerdict.failures.length + storageTypeVerdict.failures.length;\n\tconst ok = failCount === 0;\n\tconst profileHash = \"profileHash\" in input.contract && typeof input.contract.profileHash === \"string\" ? input.contract.profileHash : void 0;\n\treturn {\n\t\tok,\n\t\t...ok ? {} : { code: \"CONTRACT.SCHEMA_VERIFICATION_FAILED\" },\n\t\tsummary: ok ? \"Database schema satisfies contract\" : `Database schema does not satisfy contract (${failCount} failure${failCount === 1 ? \"\" : \"s\"})`,\n\t\tcontract: {\n\t\t\tstorageHash: input.contract.storage.storageHash,\n\t\t\t...ifDefined(\"profileHash\", profileHash)\n\t\t},\n\t\ttarget: {\n\t\t\texpected: input.contract.target,\n\t\t\tactual: input.contract.target\n\t\t},\n\t\tschema: {\n\t\t\tissues: [...diffVerdict.failures, ...storageTypeVerdict.failures],\n\t\t\twarnings: { issues: [...diffVerdict.warnings, ...storageTypeVerdict.warnings] }\n\t\t},\n\t\tmeta: { strict: input.strict },\n\t\ttimings: { total: Date.now() - startTime }\n\t};\n}\n//#endregion\nexport { computeStorageTypeVerdict as a, computeSqlDiffVerdict as i, classifyDiffSubjectGranularity as n, verifySqlSchemaByDiff as o, classifySqlDiffIssue as r, extractCodecControlHooks as s, classifyDiffEntityKind as t };\n\n//# sourceMappingURL=schema-verify-CrvQZ5V8.mjs.map"],"mappings":";;;;;;AAMA,SAAS,qBAAqB,YAAY;CACzC,IAAI,OAAO,eAAe,YAAY,eAAe,MAAM,OAAO;CAClE,MAAM,QAAQ,UAAU,UAAU,CAAC,CAAC,OAAO,YAAY;CACvD,OAAO,UAAU,QAAQ,UAAU,KAAK,KAAK,OAAO,UAAU;AAC/D;AACA,SAAS,yBAAyB,aAAa;CAC9C,MAAM,wBAAwB,IAAI,IAAI;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AAQ,EAAE;EAC/E;EACA,MAAM,EAAE,QAAQ,MAAM,OAAO;EAC7B,SAAS,EAAE,OAAO,KAAK,IAAI,IAAI,UAAU;CAC1C;AACD"}
|
package/dist/{sql-attribute-specs-CHSP1wKs-D5T2TZQ8.mjs → sql-attribute-specs-DAEpjrWl-C0kmaUJt.mjs}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
2
|
-
import { bool, entityRef, fieldAttribute, fieldRef, funcCall, identifier, interpretAttribute, leafDiagnostic, list, modelAttribute, nodePslSpan, numLiteral, oneOf, optional, record, referencedFieldRef, str, taggedLiteral } from "@prisma/orm-framework/psl-parser";
|
|
3
2
|
import { notOk } from "@prisma/orm-framework/utils/result";
|
|
4
|
-
|
|
3
|
+
import { bool, diagnosticSource, entityRef, fieldAttribute, fieldRef, funcCall, identifier, interpretAttribute, leafDiagnostic, list, modelAttribute, nodePslSpan, numLiteral, oneOf, optional, record, referencedFieldRef, str, taggedLiteral } from "@prisma/orm-framework/psl-parser";
|
|
4
|
+
//#region ../../../2-sql/2-authoring/contract-psl/dist/sql-attribute-specs-DAEpjrWl.mjs
|
|
5
5
|
function findModelAttributeNode(model, name) {
|
|
6
6
|
for (const attribute of model.node.attributes()) if (attribute.name()?.isSimpleName(name) === true) return attribute;
|
|
7
7
|
}
|
|
@@ -10,15 +10,13 @@ function findFieldAttributeNode(field, name) {
|
|
|
10
10
|
}
|
|
11
11
|
function buildModelAttributeCtx(input) {
|
|
12
12
|
return {
|
|
13
|
-
|
|
14
|
-
sourceFile: input.sourceFile,
|
|
13
|
+
sources: input.sources,
|
|
15
14
|
selfModel: input.selfModel
|
|
16
15
|
};
|
|
17
16
|
}
|
|
18
17
|
function buildFieldAttributeCtx(input) {
|
|
19
18
|
return {
|
|
20
|
-
|
|
21
|
-
sourceFile: input.sourceFile,
|
|
19
|
+
sources: input.sources,
|
|
22
20
|
selfModel: input.selfModel,
|
|
23
21
|
resolveReferencedModel: input.resolveReferencedModel ?? (() => void 0),
|
|
24
22
|
field: input.field
|
|
@@ -27,11 +25,10 @@ function buildFieldAttributeCtx(input) {
|
|
|
27
25
|
function interpretModelAttribute(input) {
|
|
28
26
|
const result = interpretAttribute(input.node, input.spec, buildModelAttributeCtx({
|
|
29
27
|
selfModel: input.model,
|
|
30
|
-
|
|
31
|
-
sourceId: input.sourceId
|
|
28
|
+
sources: input.sources
|
|
32
29
|
}));
|
|
33
30
|
if (!result.ok) {
|
|
34
|
-
|
|
31
|
+
input.diagnostics.push(...result.failure);
|
|
35
32
|
return;
|
|
36
33
|
}
|
|
37
34
|
return result.value;
|
|
@@ -40,12 +37,11 @@ function interpretFieldAttribute(input) {
|
|
|
40
37
|
const result = interpretAttribute(input.node, input.spec, buildFieldAttributeCtx({
|
|
41
38
|
selfModel: input.model,
|
|
42
39
|
field: input.field,
|
|
43
|
-
|
|
44
|
-
sourceId: input.sourceId,
|
|
40
|
+
sources: input.sources,
|
|
45
41
|
resolveReferencedModel: input.resolveReferencedModel
|
|
46
42
|
}));
|
|
47
43
|
if (!result.ok) {
|
|
48
|
-
|
|
44
|
+
input.diagnostics.push(...result.failure);
|
|
49
45
|
return;
|
|
50
46
|
}
|
|
51
47
|
return result.value;
|
|
@@ -302,15 +298,14 @@ const baseModelSpec = modelAttribute("base", {
|
|
|
302
298
|
});
|
|
303
299
|
function relationAttributeSpan(ctx) {
|
|
304
300
|
const node = findFieldAttributeNode(ctx.field, "relation");
|
|
305
|
-
if (node !== void 0) return nodePslSpan(node.syntax, ctx.
|
|
301
|
+
if (node !== void 0) return nodePslSpan(node.syntax, ctx.sources);
|
|
306
302
|
return ctx.field.span;
|
|
307
303
|
}
|
|
308
304
|
function relationInvariants(parsed, ctx) {
|
|
309
305
|
if (parsed.fields !== void 0 !== (parsed.references !== void 0)) return [{
|
|
310
306
|
code: "PSL_INVALID_ATTRIBUTE_SYNTAX",
|
|
311
307
|
message: `Relation field "${ctx.selfModel.name}.${ctx.field.name}" requires fields and references arguments`,
|
|
312
|
-
|
|
313
|
-
span: relationAttributeSpan(ctx)
|
|
308
|
+
...diagnosticSource(ctx.sources, ctx.field.node.syntax).at(relationAttributeSpan(ctx))
|
|
314
309
|
}];
|
|
315
310
|
return [];
|
|
316
311
|
}
|
|
@@ -391,4 +386,4 @@ const sqlAttributeSpecs = {
|
|
|
391
386
|
//#endregion
|
|
392
387
|
export { interpretFieldAttribute as a, findModelAttributeNode as i, fieldSpecContext as n, interpretModelAttribute as o, findFieldAttributeNode as r, sqlAttributeSpecs as s, PSL_CHECK_ON_STI_VARIANT as t };
|
|
393
388
|
|
|
394
|
-
//# sourceMappingURL=sql-attribute-specs-
|
|
389
|
+
//# sourceMappingURL=sql-attribute-specs-DAEpjrWl-C0kmaUJt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-attribute-specs-DAEpjrWl-C0kmaUJt.mjs","names":[],"sources":["../../../../2-sql/2-authoring/contract-psl/dist/sql-attribute-specs-DAEpjrWl.mjs"],"sourcesContent":["import { bool, diagnosticSource, entityRef, fieldAttribute, fieldRef, funcCall, identifier, interpretAttribute, leafDiagnostic, list, modelAttribute, nodePslSpan, numLiteral, oneOf, optional, record, referencedFieldRef, str, taggedLiteral } from \"@internal/psl-parser\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { notOk } from \"@internal/utils/result\";\n//#region src/sql-attribute-specs.ts\nfunction findModelAttributeNode(model, name) {\n\tfor (const attribute of model.node.attributes()) if (attribute.name()?.isSimpleName(name) === true) return attribute;\n}\nfunction findFieldAttributeNode(field, name) {\n\tfor (const attribute of field.node.attributes()) if (attribute.name()?.isSimpleName(name) === true) return attribute;\n}\nfunction buildModelAttributeCtx(input) {\n\treturn {\n\t\tsources: input.sources,\n\t\tselfModel: input.selfModel\n\t};\n}\nfunction buildFieldAttributeCtx(input) {\n\treturn {\n\t\tsources: input.sources,\n\t\tselfModel: input.selfModel,\n\t\tresolveReferencedModel: input.resolveReferencedModel ?? (() => void 0),\n\t\tfield: input.field\n\t};\n}\nfunction interpretModelAttribute(input) {\n\tconst result = interpretAttribute(input.node, input.spec, buildModelAttributeCtx({\n\t\tselfModel: input.model,\n\t\tsources: input.sources\n\t}));\n\tif (!result.ok) {\n\t\tinput.diagnostics.push(...result.failure);\n\t\treturn;\n\t}\n\treturn result.value;\n}\nfunction interpretFieldAttribute(input) {\n\tconst result = interpretAttribute(input.node, input.spec, buildFieldAttributeCtx({\n\t\tselfModel: input.model,\n\t\tfield: input.field,\n\t\tsources: input.sources,\n\t\tresolveReferencedModel: input.resolveReferencedModel\n\t}));\n\tif (!result.ok) {\n\t\tinput.diagnostics.push(...result.failure);\n\t\treturn;\n\t}\n\treturn result.value;\n}\nfunction validateMappedName(value, ctx, attributeNode) {\n\treturn value.name === \"\" ? [leafDiagnostic(ctx, attributeNode, \"Mapped name must not be empty\")] : [];\n}\nconst mapModelSpec = modelAttribute(\"map\", {\n\tdocumentation: \"Maps this model to a database table name.\",\n\tpositional: [{\n\t\tkey: \"name\",\n\t\ttype: str(),\n\t\tdocumentation: \"The nonempty database table name.\"\n\t}],\n\trefine: validateMappedName\n});\nconst mapFieldSpec = fieldAttribute(\"map\", {\n\tdocumentation: \"Maps this field to a database column name.\",\n\tpositional: [{\n\t\tkey: \"name\",\n\t\ttype: str(),\n\t\tdocumentation: \"The nonempty database column name.\"\n\t}],\n\trefine: validateMappedName\n});\nfunction scalarDefaultArms(isList, registries) {\n\tconst literal = () => oneOf(str(), numLiteral(), bool());\n\tconst tagEntries = [...registries.defaultLiteralTagRegistry];\n\tconst tagArms = tagEntries.length > 0 ? [taggedLiteral(tagEntries.map(([tag]) => tag), { documentation: [...new Set(tagEntries.map(([, entry]) => entry.documentation))].join(\" \") })] : [];\n\tconst funcArms = [...registries.defaultFunctionRegistry.entries()].map(([name, entry]) => funcCall(name, blindCast(entry.signature)));\n\treturn isList ? [\n\t\tlist(literal()),\n\t\t...funcArms,\n\t\t...tagArms\n\t] : [\n\t\tstr(),\n\t\tnumLiteral(),\n\t\tbool(),\n\t\t...funcArms,\n\t\t...tagArms\n\t];\n}\nfunction noEnumMember() {\n\treturn {\n\t\tkind: \"rejecting\",\n\t\tlabel: \"enum member\",\n\t\tmessage: \"Enum declares no members\",\n\t\tparse: (arg, ctx) => notOk([leafDiagnostic(ctx, arg, \"Enum declares no members\")])\n\t};\n}\nfunction enumMemberNames(ctx) {\n\tconst block = (ctx.field.typeNamespaceId === void 0 ? ctx.symbols.topLevel : ctx.symbols.topLevel.namespaces[ctx.field.typeNamespaceId])?.blocks[ctx.field.typeName];\n\tif (block === void 0 || block.keyword !== \"enum\") return void 0;\n\treturn Object.keys(block.block.parameters);\n}\nfunction enumDefaultArms(members, enumName) {\n\tconst [first, ...rest] = members;\n\tif (first === void 0) return [noEnumMember()];\n\tconst member = (name) => identifier(name, { documentation: `The \\`${name}\\` member of enum \\`${enumName}\\`.` });\n\treturn [member(first), ...rest.map(member)];\n}\nfunction defaultFieldSpec(ctx) {\n\tconst members = enumMemberNames(ctx);\n\treturn fieldAttribute(\"default\", {\n\t\tdocumentation: \"Supplies a default value when this field is omitted from a mutation.\",\n\t\tpositional: [{\n\t\t\tkey: \"value\",\n\t\t\ttype: oneOf(...members === void 0 ? scalarDefaultArms(ctx.field.list, ctx.controlMutationDefaults) : enumDefaultArms(members, ctx.field.typeName)),\n\t\t\tdocumentation: \"A literal, enum member, or registered default function compatible with this field.\"\n\t\t}]\n\t});\n}\nconst idFieldSpec = fieldAttribute(\"id\", {\n\tdocumentation: \"Makes this field the primary key of the table.\",\n\tnamed: { map: {\n\t\ttype: optional(str()),\n\t\tdocumentation: \"The database primary-key constraint name.\"\n\t} }\n});\nconst uniqueFieldSpec = fieldAttribute(\"unique\", {\n\tdocumentation: \"Requires values in this field to be unique.\",\n\tnamed: { map: {\n\t\ttype: optional(str()),\n\t\tdocumentation: \"The database unique-constraint name.\"\n\t} }\n});\nconst noCheckKindArgument = () => oneOf(identifier(\"membership\", { documentation: \"Waives the generated check that values belong to the declared domain enum.\" }), identifier(\"elementNotNull\", { documentation: \"Waives the generated check that scalar-list elements are non-null.\" }));\n/**\n* `@noCheck` waives generated CHECK constraints on one column: bare for every\n* kind the column's shape derives, or naming concrete kinds. Two optional\n* positional slots cover the whole kind vocabulary; a third argument is\n* necessarily a duplicate and fails as excess arity.\n*/\nconst noCheckFieldSpec = fieldAttribute(\"noCheck\", {\n\tdocumentation: \"Waives generated CHECK constraints for this column. With no arguments, waives every generated kind.\",\n\tpositional: [{\n\t\tkey: \"first\",\n\t\ttype: optional(noCheckKindArgument()),\n\t\tdocumentation: \"The first generated check kind to waive: `membership` or `elementNotNull`.\"\n\t}, {\n\t\tkey: \"second\",\n\t\ttype: optional(noCheckKindArgument()),\n\t\tdocumentation: \"A second, distinct generated check kind to waive.\"\n\t}],\n\trefine: (value, ctx, attributeNode) => {\n\t\tif (value.first !== void 0 && value.first === value.second) return [leafDiagnostic(ctx, attributeNode, \"`@noCheck` names the same kind twice\")];\n\t\treturn [];\n\t}\n});\nconst idModelSpec = modelAttribute(\"id\", {\n\tdocumentation: \"Declares a compound primary key for this table.\",\n\tpositional: [{\n\t\tkey: \"fields\",\n\t\ttype: list(fieldRef(), {\n\t\t\tallowEmpty: false,\n\t\t\tunique: true\n\t\t}),\n\t\tdocumentation: \"The ordered, nonempty list of distinct primary-key fields.\"\n\t}],\n\tnamed: { map: {\n\t\ttype: optional(str()),\n\t\tdocumentation: \"The database primary-key constraint name.\"\n\t} }\n});\nconst uniqueModelSpec = modelAttribute(\"unique\", {\n\tdocumentation: \"Requires the combination of these fields to be unique.\",\n\tpositional: [{\n\t\tkey: \"fields\",\n\t\ttype: list(fieldRef(), {\n\t\t\tallowEmpty: false,\n\t\t\tunique: true\n\t\t}),\n\t\tdocumentation: \"The ordered, nonempty list of distinct fields in the unique constraint.\"\n\t}],\n\tnamed: { map: {\n\t\ttype: optional(str()),\n\t\tdocumentation: \"The database unique-constraint name.\"\n\t} }\n});\nconst PSL_INDEX_FIELDS_XOR_EXPRESSION = \"PSL_INDEX_FIELDS_XOR_EXPRESSION\";\nconst PSL_INDEX_EXPRESSION_REQUIRES_NAME = \"PSL_INDEX_EXPRESSION_REQUIRES_NAME\";\nconst PSL_INDEX_NAME_XOR_MAP = \"PSL_INDEX_NAME_XOR_MAP\";\nconst indexModelSpec = modelAttribute(\"index\", {\n\tdocumentation: \"Declares a database index over fields or a SQL expression, optionally restricted by a predicate.\",\n\tpositional: [{\n\t\tkey: \"fields\",\n\t\ttype: optional(list(fieldRef(), {\n\t\t\tallowEmpty: false,\n\t\t\tunique: true\n\t\t})),\n\t\tdocumentation: \"The ordered list of distinct indexed fields. Mutually exclusive with `expression`.\"\n\t}],\n\tnamed: {\n\t\texpression: {\n\t\t\ttype: optional(str()),\n\t\t\tdocumentation: \"The SQL index expression. Requires `name` or `map` and cannot be combined with a fields list.\"\n\t\t},\n\t\twhere: {\n\t\t\ttype: optional(str()),\n\t\t\tdocumentation: \"The SQL predicate restricting rows included in a partial index.\"\n\t\t},\n\t\tunique: {\n\t\t\ttype: optional(bool()),\n\t\t\tdocumentation: \"Whether the index enforces uniqueness.\"\n\t\t},\n\t\tname: {\n\t\t\ttype: optional(str()),\n\t\t\tdocumentation: \"The index name. Mutually exclusive with `map`.\"\n\t\t},\n\t\tmap: {\n\t\t\ttype: optional(str()),\n\t\t\tdocumentation: \"The database index name. Mutually exclusive with `name`.\"\n\t\t},\n\t\ttype: {\n\t\t\ttype: optional(str()),\n\t\t\tdocumentation: \"The target-specific index access method.\"\n\t\t},\n\t\toptions: {\n\t\t\ttype: optional(record(str())),\n\t\t\tdocumentation: \"Target-specific index options. Requires an explicit `type`.\"\n\t\t}\n\t},\n\trefine: (value, ctx, attributeNode) => {\n\t\tconst diagnostics = [];\n\t\tif (value.fields === void 0 === (value.expression === void 0)) diagnostics.push(leafDiagnostic(ctx, attributeNode, \"`@@index` requires exactly one of a fields list or an `expression` argument\", PSL_INDEX_FIELDS_XOR_EXPRESSION));\n\t\tif (value.expression !== void 0 && value.name === void 0 && value.map === void 0) diagnostics.push(leafDiagnostic(ctx, attributeNode, \"`@@index` with an `expression` argument requires a `name` or `map` argument (a default name cannot be derived from an expression)\", PSL_INDEX_EXPRESSION_REQUIRES_NAME));\n\t\tif (value.name !== void 0 && value.map !== void 0) diagnostics.push(leafDiagnostic(ctx, attributeNode, \"`@@index` takes at most one of `name` and `map`\", PSL_INDEX_NAME_XOR_MAP));\n\t\tif (value.options !== void 0 && value.type === void 0) diagnostics.push(leafDiagnostic(ctx, attributeNode, \"`@@index` options argument requires a type argument\"));\n\t\treturn diagnostics;\n\t}\n});\nconst PSL_CHECK_REQUIRES_NAME_OR_MAP = \"PSL_CHECK_REQUIRES_NAME_OR_MAP\";\nconst PSL_CHECK_NAME_XOR_MAP = \"PSL_CHECK_NAME_XOR_MAP\";\nconst PSL_CHECK_EXPRESSION_EMPTY = \"PSL_CHECK_EXPRESSION_EMPTY\";\n/**\n* A single-table-inheritance variant (`@@base` with no own `@@map`) shares\n* its base model's storage table and has no table of its own to declare a\n* check on — raised from {@link interpretPslDocumentToSqlContract}, not from\n* this spec's own `refine`, because the rule needs the model's `@@base`\n* declaration, which a single attribute's `refine` cannot see.\n*/\nconst PSL_CHECK_ON_STI_VARIANT = \"PSL_CHECK_ON_STI_VARIANT\";\nconst checkModelSpec = modelAttribute(\"check\", {\n\tdocumentation: \"Declares a named database CHECK constraint on this table.\",\n\tnamed: {\n\t\texpression: {\n\t\t\ttype: str(),\n\t\t\tdocumentation: \"The nonempty SQL predicate checked for each row.\"\n\t\t},\n\t\tname: {\n\t\t\ttype: optional(str()),\n\t\t\tdocumentation: \"The constraint name. Exactly one of `name` and `map` is required.\"\n\t\t},\n\t\tmap: {\n\t\t\ttype: optional(str()),\n\t\t\tdocumentation: \"The database constraint name. Exactly one of `name` and `map` is required.\"\n\t\t}\n\t},\n\trefine: (value, ctx, attributeNode) => {\n\t\tconst diagnostics = [];\n\t\tif (value.expression.trim().length === 0) diagnostics.push(leafDiagnostic(ctx, attributeNode, \"`@@check` expression must not be empty — an empty predicate is not a constraint\", PSL_CHECK_EXPRESSION_EMPTY));\n\t\tif (value.name === void 0 && value.map === void 0) diagnostics.push(leafDiagnostic(ctx, attributeNode, \"`@@check` requires a `name` or `map` argument (a default name cannot be derived — a check has no column tuple to name itself after)\", PSL_CHECK_REQUIRES_NAME_OR_MAP));\n\t\tif (value.name !== void 0 && value.map !== void 0) diagnostics.push(leafDiagnostic(ctx, attributeNode, \"`@@check` takes at most one of `name` and `map`\", PSL_CHECK_NAME_XOR_MAP));\n\t\treturn diagnostics;\n\t}\n});\nconst controlModelSpec = modelAttribute(\"control\", {\n\tdocumentation: \"Sets how schema management treats this model’s storage.\",\n\tpositional: [{\n\t\tkey: \"policy\",\n\t\tdocumentation: \"The storage control policy: `managed`, `tolerated`, `external`, or `observed`.\",\n\t\ttype: oneOf(identifier(\"managed\", { documentation: \"Verifies the declared shape strictly and allows migrations to create, alter, or drop the storage object.\" }), identifier(\"tolerated\", { documentation: \"Verifies declared columns while allowing extra columns. Migrations may create missing storage, but never alter or drop existing storage.\" }), identifier(\"external\", { documentation: \"Verifies declared storage without creating, altering, or dropping it.\" }), identifier(\"observed\", { documentation: \"Reports storage differences as warnings rather than verification failures and never emits migration operations.\" }))\n\t}]\n});\nconst discriminatorModelSpec = modelAttribute(\"discriminator\", {\n\tdocumentation: \"Selects the field that identifies inheritance variants of this model.\",\n\tpositional: [{\n\t\tkey: \"field\",\n\t\ttype: fieldRef(),\n\t\tdocumentation: \"The discriminator field on this model.\"\n\t}]\n});\nconst baseModelSpec = modelAttribute(\"base\", {\n\tdocumentation: \"Declares this model as a variant of a base model.\",\n\tpositional: [{\n\t\tkey: \"base\",\n\t\ttype: entityRef(),\n\t\tdocumentation: \"The base model to inherit from.\"\n\t}, {\n\t\tkey: \"value\",\n\t\ttype: str(),\n\t\tdocumentation: \"The discriminator value identifying this variant.\"\n\t}]\n});\nfunction relationAttributeSpan(ctx) {\n\tconst node = findFieldAttributeNode(ctx.field, \"relation\");\n\tif (node !== void 0) return nodePslSpan(node.syntax, ctx.sources);\n\treturn ctx.field.span;\n}\nfunction relationInvariants(parsed, ctx) {\n\tif (parsed.fields !== void 0 !== (parsed.references !== void 0)) return [{\n\t\tcode: \"PSL_INVALID_ATTRIBUTE_SYNTAX\",\n\t\tmessage: `Relation field \"${ctx.selfModel.name}.${ctx.field.name}\" requires fields and references arguments`,\n\t\t...diagnosticSource(ctx.sources, ctx.field.node.syntax).at(relationAttributeSpan(ctx))\n\t}];\n\treturn [];\n}\nconst referentialActionArgument = () => oneOf(identifier(\"NoAction\", { documentation: \"Rejects a change that would violate the foreign key when the constraint is checked; checking may be deferred when supported and configured.\" }), identifier(\"Restrict\", { documentation: \"Rejects deleting or updating a referenced row while referencing rows remain, without deferring the check.\" }), identifier(\"Cascade\", { documentation: \"Propagates deletion or key updates of a referenced row to its referencing rows.\" }), identifier(\"SetNull\", { documentation: \"Sets referencing foreign-key fields to null when the referenced row is deleted or its key changes. The fields must allow null.\" }), identifier(\"SetDefault\", { documentation: \"Sets referencing foreign-key fields to their defaults when the referenced row is deleted or its key changes. The resulting values must satisfy the foreign key.\" }));\nconst relationFieldSpec = fieldAttribute(\"relation\", {\n\tdocumentation: \"Defines the relation name, foreign-key fields, and referential actions for this relation.\",\n\tpositional: [{\n\t\tkey: \"name\",\n\t\ttype: optional(str()),\n\t\tdocumentation: \"The relation name used to pair both sides. May also be supplied by name.\"\n\t}],\n\tnamed: {\n\t\tname: {\n\t\t\ttype: optional(str()),\n\t\t\tdocumentation: \"The relation name used to pair both sides. Cannot also be supplied positionally.\"\n\t\t},\n\t\tfields: {\n\t\t\ttype: optional(list(fieldRef(), {\n\t\t\t\tallowEmpty: false,\n\t\t\t\tunique: true\n\t\t\t})),\n\t\t\tdocumentation: \"The ordered local foreign-key fields. Must be supplied together with `references`.\"\n\t\t},\n\t\treferences: {\n\t\t\ttype: optional(list(referencedFieldRef(), {\n\t\t\t\tallowEmpty: false,\n\t\t\t\tunique: true\n\t\t\t})),\n\t\t\tdocumentation: \"The corresponding fields on the referenced model. Must be supplied together with `fields`.\"\n\t\t},\n\t\tmap: {\n\t\t\ttype: optional(str()),\n\t\t\tdocumentation: \"The database foreign-key constraint name.\"\n\t\t},\n\t\tonDelete: {\n\t\t\ttype: optional(referentialActionArgument()),\n\t\t\tdocumentation: \"The referential action when a referenced row is deleted.\"\n\t\t},\n\t\tonUpdate: {\n\t\t\ttype: optional(referentialActionArgument()),\n\t\t\tdocumentation: \"The referential action when a referenced key is updated.\"\n\t\t},\n\t\tindex: {\n\t\t\ttype: optional(bool()),\n\t\t\tdocumentation: \"Whether to create an index for the relation’s foreign-key fields.\"\n\t\t}\n\t},\n\trefine: relationInvariants\n});\nfunction fieldSpecContext(input) {\n\treturn {\n\t\tsymbols: input.symbols,\n\t\tmodel: input.model,\n\t\tfield: input.field,\n\t\tcontrolMutationDefaults: input.controlMutationDefaults\n\t};\n}\nconst sqlAttributeSpecs = {\n\tmodel: {\n\t\tmap: () => mapModelSpec,\n\t\tid: () => idModelSpec,\n\t\tunique: () => uniqueModelSpec,\n\t\tindex: () => indexModelSpec,\n\t\tcheck: () => checkModelSpec,\n\t\tcontrol: () => controlModelSpec,\n\t\tdiscriminator: () => discriminatorModelSpec,\n\t\tbase: () => baseModelSpec\n\t},\n\tfield: {\n\t\tmap: () => mapFieldSpec,\n\t\tid: () => idFieldSpec,\n\t\tunique: () => uniqueFieldSpec,\n\t\tnoCheck: () => noCheckFieldSpec,\n\t\trelation: () => relationFieldSpec,\n\t\tdefault: defaultFieldSpec\n\t}\n};\n//#endregion\nexport { interpretFieldAttribute as a, findModelAttributeNode as i, fieldSpecContext as n, interpretModelAttribute as o, findFieldAttributeNode as r, sqlAttributeSpecs as s, PSL_CHECK_ON_STI_VARIANT as t };\n\n//# sourceMappingURL=sql-attribute-specs-DAEpjrWl.mjs.map"],"mappings":";;;;AAIA,SAAS,uBAAuB,OAAO,M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ype";
|
|
|
10
10
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
11
11
|
import { withDerivedToOneRelationNullability } from "@prisma/orm-framework/contract-authoring";
|
|
12
12
|
import { isPlainRecord as isPlainRecord$1 } from "@prisma/orm-framework/contract/is-plain-record";
|
|
13
|
-
//#region ../../../2-sql/9-family/dist/sql-contract-serializer-
|
|
13
|
+
//#region ../../../2-sql/9-family/dist/sql-contract-serializer-C4HbCKFe.mjs
|
|
14
14
|
const NamespaceRawSchema = type({
|
|
15
15
|
id: "string",
|
|
16
16
|
"kind?": "string",
|
|
@@ -70,10 +70,10 @@ var SqlContractSerializerBase = class {
|
|
|
70
70
|
deserializeContract(json) {
|
|
71
71
|
const validated = withSqlToOneRelationNullability(this.parseSqlContractStructure(json));
|
|
72
72
|
const hydrated = this.hydrateSqlStorage(validated);
|
|
73
|
-
return this.constructTargetContract(hydrated);
|
|
73
|
+
return blindCast(this.constructTargetContract(hydrated));
|
|
74
74
|
}
|
|
75
75
|
serializeContract(contract) {
|
|
76
|
-
return contract;
|
|
76
|
+
return blindCast(contract);
|
|
77
77
|
}
|
|
78
78
|
shouldPreserveEmpty = sqlContractCanonicalizationHooks.shouldPreserveEmpty;
|
|
79
79
|
sortStorage = sqlContractCanonicalizationHooks.sortStorage;
|
|
@@ -126,14 +126,14 @@ var SqlContractSerializerBase = class {
|
|
|
126
126
|
}
|
|
127
127
|
hydrateStorageTypeEntry(entry) {
|
|
128
128
|
if (typeof entry !== "object" || entry === null) return entry;
|
|
129
|
-
const kind = entry
|
|
129
|
+
const kind = isPlainRecord$1(entry) ? entry["kind"] : void 0;
|
|
130
130
|
if (typeof kind !== "string") return entry;
|
|
131
131
|
const factory = this.entityHydrationRegistry.get(kind);
|
|
132
132
|
if (factory === void 0) return entry;
|
|
133
133
|
return blindCast(factory(entry));
|
|
134
134
|
}
|
|
135
135
|
constructTargetContract(hydrated) {
|
|
136
|
-
return hydrated;
|
|
136
|
+
return blindCast(hydrated);
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* Serializes a namespace's `entries` dict by walking every enumerable
|
|
@@ -187,4 +187,4 @@ var SqlContractSerializer = class extends SqlContractSerializerBase {
|
|
|
187
187
|
//#endregion
|
|
188
188
|
export { SqlContractSerializerBase as n, SqlContractSerializer as t };
|
|
189
189
|
|
|
190
|
-
//# sourceMappingURL=sql-contract-serializer-
|
|
190
|
+
//# sourceMappingURL=sql-contract-serializer-C4HbCKFe-BD1Fx4JX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-contract-serializer-C4HbCKFe-BD1Fx4JX.mjs","names":[],"sources":["../../../../2-sql/9-family/dist/sql-contract-serializer-C4HbCKFe.mjs"],"sourcesContent":["import { t as sqlFamilyError } from \"./errors-B5g0xWro.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { hydrateNamespaceEntities } from \"@internal/framework-components/ir\";\nimport { sqlContractCanonicalizationHooks } from \"@internal/sql-contract/canonicalization-hooks\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { SqlStorage, isMaterializedSqlNamespace } from \"@internal/sql-contract/types\";\nimport { ContractValidationError } from \"@internal/contract/contract-validation-error\";\nimport { isPlainRecord as isPlainRecord$1 } from \"@internal/contract/is-plain-record\";\nimport { withDerivedToOneRelationNullability } from \"@internal/contract-authoring\";\nimport { composeSqlEntityKinds } from \"@internal/sql-contract/entity-kinds\";\nimport { createSqlContractSchema, resolveSqlToOneRelationStorage, validateSqlContractFully } from \"@internal/sql-contract/validators\";\nimport { type } from \"arktype\";\n//#region src/core/ir/sql-contract-serializer-base.ts\nconst NamespaceRawSchema = type({\n\tid: \"string\",\n\t\"kind?\": \"string\",\n\tentries: type({ \"+\": \"ignore\" })\n});\n/**\n* A `contract.json` written before to-one relations recorded `nullable` (rc.9 and earlier)\n* loads with the flag derived from storage: nullable when any local FK column is nullable or\n* cannot be resolved.\n*/\nfunction withSqlToOneRelationNullability(contract) {\n\tconst domain = withDerivedToOneRelationNullability(contract.domain, ({ model, relation }) => {\n\t\tconst { ownsForeignKey, columns } = resolveSqlToOneRelationStorage(contract, blindCast(model.storage), relation);\n\t\treturn {\n\t\t\townsReference: ownsForeignKey,\n\t\t\tlocalFieldNullability: columns.map((column) => column.nullable)\n\t\t};\n\t});\n\treturn {\n\t\t...contract,\n\t\tdomain\n\t};\n}\n/**\n* SQL family `ContractSerializer` abstract base. Carries the SQL-shared\n* deserialization pipeline:\n*\n* 1. `parseSqlContractStructure` validates the on-disk JSON envelope\n* against the SQL contract arktype schema (`validateSqlContractFully`)\n* and returns the validated flat-data shape.\n* 2. `hydrateSqlStorage` walks the validated `storage` subtree and\n* constructs the family-shared SQL Contract IR class hierarchy\n* (`SqlStorage` -> `StorageTable` -> `StorageColumn` / `PrimaryKey`\n* / …). The rest of the contract envelope is JSON-clean primitive\n* data and passes through unchanged.\n* 3. `constructTargetContract` is the target-specific extension hook;\n* defaults to identity. Targets that need to attach target-only\n* fields (e.g. target-specific derived storage fields) override it.\n*\n* Default `serializeContract` is identity over the contract — concrete\n* SQL targets ship JSON-clean class instances, so the contract value\n* can be stringified directly. The non-enumerable family-level `kind`\n* discriminator on `SqlNode` instances stays out of the persisted\n* envelope automatically. Targets that need to canonicalize on the way\n* out (key ordering, dropping computed-only fields) override\n* `serializeContract` directly.\n*/\nvar SqlContractSerializerBase = class {\n\tentityHydrationRegistry;\n\tcontractSchema;\n\tentryKinds;\n\tconstructor(entityHydrationRegistry = /* @__PURE__ */ new Map(), packEntityKinds = []) {\n\t\tthis.entityHydrationRegistry = entityHydrationRegistry;\n\t\tthis.entryKinds = composeSqlEntityKinds(packEntityKinds);\n\t\tthis.contractSchema = packEntityKinds.length > 0 ? createSqlContractSchema(this.entryKinds) : void 0;\n\t}\n\tdeserializeContract(json) {\n\t\tconst validated = withSqlToOneRelationNullability(this.parseSqlContractStructure(json));\n\t\tconst hydrated = this.hydrateSqlStorage(validated);\n\t\treturn blindCast(this.constructTargetContract(hydrated));\n\t}\n\tserializeContract(contract) {\n\t\treturn blindCast(contract);\n\t}\n\tshouldPreserveEmpty = sqlContractCanonicalizationHooks.shouldPreserveEmpty;\n\tsortStorage = sqlContractCanonicalizationHooks.sortStorage;\n\tparseSqlContractStructure(json) {\n\t\treturn validateSqlContractFully(json, this.contractSchema !== void 0 ? { contractSchema: this.contractSchema } : void 0);\n\t}\n\thydrateSqlStorage(validated) {\n\t\tconst types = validated.storage.types;\n\t\tconst hydratedTypes = types !== void 0 ? Object.fromEntries(Object.entries(types).map(([name, entry]) => [name, this.hydrateStorageTypeEntry(entry)])) : void 0;\n\t\tconst rawNamespaces = validated.storage.namespaces;\n\t\tif (rawNamespaces === void 0) throw new ContractValidationError(\"Contract storage.namespaces is required after structural validation\", \"structural\");\n\t\tconst hydratedNamespaces = this.hydrateSqlNamespaceMap(blindCast(rawNamespaces));\n\t\treturn {\n\t\t\t...validated,\n\t\t\tstorage: new SqlStorage({\n\t\t\t\tstorageHash: validated.storage.storageHash,\n\t\t\t\t...ifDefined(\"types\", hydratedTypes),\n\t\t\t\tnamespaces: blindCast(hydratedNamespaces)\n\t\t\t})\n\t\t};\n\t}\n\thydrateSqlNamespaceMap(namespaces) {\n\t\treturn Object.fromEntries(Object.entries(namespaces).map(([nsId, namespaceEntryRaw]) => {\n\t\t\tconst namespaceHydrated = this.hydrateSqlNamespaceEntry(nsId, namespaceEntryRaw);\n\t\t\tif (!isMaterializedSqlNamespace(namespaceHydrated)) throw sqlFamilyError(\"CONTRACT.PACK_CONTRIBUTION_INVALID\", `Target serializer bug: hydrateSqlNamespaceEntry for namespace \"${nsId}\" returned a non-NamespaceBase value. Override hydrateSqlNamespaceEntry to produce a target namespace concretion.`, {\n\t\t\t\twhy: \"The target contract serializer hydrated a namespace into a value that is not a materialized namespace concretion.\",\n\t\t\t\tfix: \"Fix the target package: its hydrateSqlNamespaceEntry override must return a target namespace concretion.\",\n\t\t\t\tmeta: { namespaceId: nsId }\n\t\t\t});\n\t\t\treturn [nsId, namespaceHydrated];\n\t\t}));\n\t}\n\thydrateSqlNamespaceEntry(nsId, raw) {\n\t\tconst id = typeof raw[\"id\"] === \"string\" ? raw[\"id\"] : nsId;\n\t\tconst parsed = NamespaceRawSchema({\n\t\t\t...raw,\n\t\t\tid\n\t\t});\n\t\tif (parsed instanceof type.errors) throw new ContractValidationError(`Namespace hydration failed: ${parsed.map((p) => p.message).join(\"; \")}`, \"structural\");\n\t\tconst entriesRaw = parsed.entries;\n\t\tconst rawEntriesMap = isPlainRecord$1(entriesRaw) ? entriesRaw : {};\n\t\tconst entriesInput = {};\n\t\tfor (const [key, innerMap] of Object.entries(rawEntriesMap)) entriesInput[key] = isPlainRecord$1(innerMap) ? innerMap : Object.freeze({});\n\t\tconst entriesOutput = hydrateNamespaceEntities(entriesInput, this.entryKinds, \"fail\", id);\n\t\tif (!Object.hasOwn(entriesOutput, \"table\")) entriesOutput[\"table\"] = {};\n\t\treturn blindCast({\n\t\t\tid,\n\t\t\tentries: entriesOutput\n\t\t});\n\t}\n\thydrateStorageTypeEntry(entry) {\n\t\tif (typeof entry !== \"object\" || entry === null) return entry;\n\t\tconst kind = isPlainRecord$1(entry) ? entry[\"kind\"] : void 0;\n\t\tif (typeof kind !== \"string\") return entry;\n\t\tconst factory = this.entityHydrationRegistry.get(kind);\n\t\tif (factory === void 0) return entry;\n\t\treturn blindCast(factory(entry));\n\t}\n\tconstructTargetContract(hydrated) {\n\t\treturn blindCast(hydrated);\n\t}\n\t/**\n\t* Serializes a namespace's `entries` dict by walking every enumerable\n\t* kind — no kind is named here, mirroring the generic hydrate walk in\n\t* `hydrateSqlNamespaceEntry` above. `table` is the SQL family's one\n\t* universal base kind (every namespace carries it), so it is always\n\t* emitted, even when empty; every other kind — target- or\n\t* pack-contributed — is emitted only when it holds at least one entry.\n\t* A kind carried non-enumerable on `entries` is excluded here for free,\n\t* since `Object.entries` honors enumerability.\n\t*/\n\tserializeNamespaceEntries(entries) {\n\t\tconst out = { table: this.serializeEntries(entries[\"table\"] ?? {}) };\n\t\tfor (const [kind, record] of Object.entries(entries)) {\n\t\t\tif (kind === \"table\" || record == null || Object.keys(record).length === 0) continue;\n\t\t\tout[kind] = this.serializeEntries(record);\n\t\t}\n\t\treturn out;\n\t}\n\tserializeEntries(entries) {\n\t\tconst out = {};\n\t\tfor (const [name, entry] of Object.entries(entries)) out[name] = this.serializeJsonObject(entry);\n\t\treturn out;\n\t}\n\tserializeJsonObject(value) {\n\t\treturn blindCast(this.serializeJsonValue(value));\n\t}\n\tserializeJsonValue(value) {\n\t\treturn blindCast(JSON.parse(JSON.stringify(value)));\n\t}\n};\n//#endregion\n//#region src/core/ir/sql-contract-serializer.ts\n/**\n* Default SQL family `ContractSerializer` concretion. Inherits the\n* full SQL-shared deserialization pipeline (structural validation +\n* IR-class hydration) without pack-registered `storage.types`\n* hydration factories — targets that emit polymorphic JSON outside the\n* codec-typed envelope wire a target-specific subclass with a populated\n* registry (see Postgres). Family-level call sites instantiate this\n* default directly when no target serializer is supplied.\n*\n* Because this serializer has no target concretion, deserialization of\n* contracts that include namespace entries from JSON will throw unless\n* the caller provides pre-hydrated `NamespaceBase` instances. Production\n* paths always supply a target-specific serializer.\n*/\nvar SqlContractSerializer = class extends SqlContractSerializerBase {\n\tconstructor() {\n\t\tsuper(/* @__PURE__ */ new Map());\n\t}\n};\n//#endregion\nexport { SqlContractSerializerBase as n, SqlContractSerializer as t };\n\n//# sourceMappingURL=sql-contract-serializer-C4HbCKFe.mjs.map"],"mappings":";;;;;;;;;;;;;AAaA,MAAM,qBAAqB,KAAK;CAC/B,IAAI;CACJ,SAAS;CACT,SAAS,KAAK,EAAE,KAAK,SAAS,CAAC;AAChC,CAAC;;;;;;AAMD,SAAS,gCAAgC,UAAU;CAClD,MAAM,SAAS,oCAAoC,SAAS,SAAS,EAAE,OAAO,eAAe;EAC5F,MAAM,EAAE,gBAAgB,YAAY,+BAA+B,UAAU,UAAU,MAAM,OAAO,GAAG,QAAQ;EAC/G,OAAO;GACN,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AO;EACrC,MAAM,UAAU,KAAK,wBAAwB,IAAI,IAAI;EACrD,IAAI,YAAY,KAAK,GAAG,OAAO;EAC/B,OAAO,UAAU,QAAQ,KAAK,CAAC;CAChC;CACA,wBAAwB,UAAU;EACjC,OAAO,UAAU,QAAQ;CAC1B;;;;;;;;;;;CAWA,0BAA0B,SAAS;EAClC,MAAM,MAAM,EAAE,OAAO,KAAK,iBAAiB,QAAQ,YAAY,CAAC,CAAC,EAAE;EACnE,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,OAAO,GAAG;GACrD,IAAI,SAAS,WAAW,UAAU,QAAQ,OAAO,KAAK,MAAM,CAAC,CAAC,WAAW,GAAG;GAC5E,IAAI,QAAQ,KAAK,iBAAiB,MAAM;EACzC;EACA,OAAO;CACR;CACA,iBAAiB,SAAS;EACzB,MAAM,MAAM,CAAC;EACb,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,OAAO,GAAG,IAAI,QAAQ,KAAK,oBAAoB,KAAK;EAC/F,OAAO;CACR;CACA,oBAAoB,OAAO;EAC1B,OAAO,UAAU,KAAK,mBAAmB,KAAK,CAAC;CAChD;CACA,mBAAmB,OAAO;EACzB,OAAO,UAAU,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC,CAAC;CACnD;AACD;;;;;;;;;;;;;;;AAiBA,IAAI,wBAAwB,cAAc,0BAA0B;CACnE,cAAc;EACb,sBAAsB,IAAI,IAAI,CAAC;CAChC;AACD"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { t as sqlFamilyError } from "./errors-B5g0xWro-mWH2C07F.mjs";
|
|
2
2
|
import { type } from "arktype";
|
|
3
|
-
|
|
3
|
+
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
4
|
+
//#region ../../../2-sql/9-family/dist/verify-BVk5bjdH.mjs
|
|
4
5
|
const MetaSchema = type({ "[string]": "unknown" });
|
|
5
6
|
function parseMeta(meta) {
|
|
6
7
|
if (meta === null || meta === void 0) return {};
|
|
@@ -13,7 +14,7 @@ function parseMeta(meta) {
|
|
|
13
14
|
else parsed = meta;
|
|
14
15
|
const result = MetaSchema(parsed);
|
|
15
16
|
if (result instanceof type.errors) return {};
|
|
16
|
-
return result;
|
|
17
|
+
return blindCast(result);
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* SQLite stores `contract_json` as TEXT, so the wire shape is a JSON string;
|
|
@@ -22,9 +23,9 @@ function parseMeta(meta) {
|
|
|
22
23
|
*/
|
|
23
24
|
function parseContractJson(value) {
|
|
24
25
|
if (value === null || value === void 0) return null;
|
|
25
|
-
if (typeof value !== "string") return value;
|
|
26
|
+
if (typeof value !== "string") return blindCast(value);
|
|
26
27
|
try {
|
|
27
|
-
return JSON.parse(value);
|
|
28
|
+
return blindCast(JSON.parse(value));
|
|
28
29
|
} catch {
|
|
29
30
|
return null;
|
|
30
31
|
}
|
|
@@ -92,4 +93,4 @@ function collectSupportedCodecTypeIds(descriptors) {
|
|
|
92
93
|
//#endregion
|
|
93
94
|
export { parseContractMarkerRow as n, collectSupportedCodecTypeIds as t };
|
|
94
95
|
|
|
95
|
-
//# sourceMappingURL=verify-
|
|
96
|
+
//# sourceMappingURL=verify-BVk5bjdH-BXgGLM2U.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-BVk5bjdH-BXgGLM2U.mjs","names":[],"sources":["../../../../2-sql/9-family/dist/verify-BVk5bjdH.mjs"],"sourcesContent":["import { t as sqlFamilyError } from \"./errors-B5g0xWro.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { type } from \"arktype\";\n//#region src/core/verify.ts\nconst MetaSchema = type({ \"[string]\": \"unknown\" });\nfunction parseMeta(meta) {\n\tif (meta === null || meta === void 0) return {};\n\tlet parsed;\n\tif (typeof meta === \"string\") try {\n\t\tparsed = JSON.parse(meta);\n\t} catch {\n\t\treturn {};\n\t}\n\telse parsed = meta;\n\tconst result = MetaSchema(parsed);\n\tif (result instanceof type.errors) return {};\n\treturn blindCast(result);\n}\n/**\n* SQLite stores `contract_json` as TEXT, so the wire shape is a JSON string;\n* Postgres uses `jsonb` and returns an already-parsed value. Normalize both\n* here so `ContractMarkerRecord.contractJson` is always the structured form.\n*/\nfunction parseContractJson(value) {\n\tif (value === null || value === void 0) return null;\n\tif (typeof value !== \"string\") return blindCast(value);\n\ttry {\n\t\treturn blindCast(JSON.parse(value));\n\t} catch {\n\t\treturn null;\n\t}\n}\nconst ContractMarkerRowSchema = type({\n\tcore_hash: \"string\",\n\tprofile_hash: \"string\",\n\t\"contract_json?\": \"unknown | null\",\n\t\"canonical_version?\": \"number | null\",\n\t\"updated_at?\": \"Date | string\",\n\t\"app_tag?\": \"string | null\",\n\t\"meta?\": \"unknown | null\",\n\tinvariants: type(\"string\").array()\n});\n/**\n* Parses a contract marker row from database query result.\n* This is SQL-specific parsing logic (handles SQL row structure with snake_case columns).\n*/\nfunction parseContractMarkerRow(row) {\n\tconst result = ContractMarkerRowSchema(row);\n\tif (result instanceof type.errors) {\n\t\tconst messages = result.map((p) => p.message).join(\"; \");\n\t\tthrow sqlFamilyError(\"CONTRACT.MARKER_ROW_CORRUPT\", `Invalid contract marker row: ${messages}`, {\n\t\t\twhy: \"The contract marker row read from the database does not match the expected marker shape.\",\n\t\t\tfix: \"Re-sign the database with `prisma db sign`, or repair the marker table.\",\n\t\t\tnextActions: [{\n\t\t\t\tkind: \"run-command\",\n\t\t\t\tlabel: \"Re-sign the database\",\n\t\t\t\tcommand: \"{bin} db sign\"\n\t\t\t}, {\n\t\t\t\tkind: \"user-choice\",\n\t\t\t\tlabel: \"Repair the marker table by hand\",\n\t\t\t\treason: messages\n\t\t\t}],\n\t\t\tmeta: { issues: messages }\n\t\t});\n\t}\n\tconst updatedAt = result.updated_at ? result.updated_at instanceof Date ? result.updated_at : new Date(result.updated_at) : /* @__PURE__ */ new Date();\n\treturn {\n\t\tstorageHash: result.core_hash,\n\t\tprofileHash: result.profile_hash,\n\t\tcontractJson: parseContractJson(result.contract_json),\n\t\tcanonicalVersion: result.canonical_version ?? null,\n\t\tupdatedAt,\n\t\tappTag: result.app_tag ?? null,\n\t\tmeta: parseMeta(result.meta),\n\t\tinvariants: result.invariants\n\t};\n}\n/**\n* Collects supported codec type IDs from adapter and extension manifests.\n* Returns a sorted, unique array of type IDs that are declared in the manifests.\n* This enables coverage checks by comparing contract column types against supported types.\n*\n* Note: This extracts type IDs from manifest type imports, not from runtime codec registries.\n* The manifests declare which codec types are available, but the actual type IDs\n* are defined in the codec-types TypeScript modules that are imported.\n*\n* For MVP, we return an empty array since extracting type IDs from TypeScript modules\n* would require runtime evaluation or static analysis. This can be enhanced later.\n*/\nfunction collectSupportedCodecTypeIds(descriptors) {\n\treturn [];\n}\n//#endregion\nexport { parseContractMarkerRow as n, collectSupportedCodecTypeIds as t };\n\n//# sourceMappingURL=verify-BVk5bjdH.mjs.map"],"mappings":";;;;AAIA,MAAM,aAAa,KAAK,EAAE,YAAY,UAAU,CAAC;AACjD,SAAS,UAAU,MAAM;CACxB,IAAI,SAAS,QAAQ,SAAS,KAAK,GAAG,OAAO,CAAC;CAC9C,IAAI;CACJ,IAAI,OAAO,SAAS,UAAU,IAAI;EACjC,SAAS,KAAK,MAAM,IAAI;CACzB,QAAQ;EACP,OAAO,CAAC;CACT;MACK,SAAS;CACd,MAAM,SAAS,WAAW,MAAM;CAChC,IAAI,kBAAkB,KAAK,QAAQ,OAAO,CAAC;CAC3C,OAAO,UAAU,MAAM;AACxB;;;;;;AAMA,SAAS,kBAAkB,OAAO;CACjC,IAAI,UAAU,QAAQ,UAAU,KAAK,GAAG,OAAO;CAC/C,IAAI,OAAO,UAAU,UAAU,OAAO,UAAU,KAAK;CACrD,IAAI;EACH,OAAO,UAAU,KAAK,MAAM,KAAK,CAAC;CACnC,QAAQ;EACP,OAAO;CACR;AACD;AACA,MAAM,0BAA0B,KAAK;CACpC,WAAW;CACX,cAAc;CACd,kBAAkB;CAClB,sBAAsB;CACtB,eAAe;CACf,YAAY;CACZ,SAAS;CACT,YAAY,KAAK,QAAQ,CAAC,CAAC,MAAM;AAClC,CAAC;;;;;AAKD,SAAS,uBAAuB,KAAK;CACpC,MAAM,SAAS,wBAAwB,GAAG;CAC1C,IAAI,kBAAkB,KAAK,QAAQ;EAClC,MAAM,WAAW,OAAO,KAAK,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,IAAI;EACvD,MAAM,eAAe,+BAA+B,gCAAgC,YAAY;GAC/F,KAAK;GACL,KAAK;GACL,aAAa,CAAC;IACb,MAAM;IACN,OAAO;IACP,SAAS;GACV,GAAG;IACF,MAAM;IACN,OAAO;IACP,QAAQ;GACT,CAAC;GACD,MAAM,EAAE,QAAQ,SAAS;EAC1B,CAAC;CACF;CACA,MAAM,YAAY,OAAO,aAAa,OAAO,sBAAsB,OAAO,OAAO,aAAa,IAAI,KAAK,OAAO,UAAU,oBAAoB,IAAI,KAAK;CACrJ,OAAO;EACN,aAAa,OAAO;EACpB,aAAa,OAAO;EACpB,cAAc,kBAAkB,OAAO,aAAa;EACpD,kBAAkB,OAAO,qBAAqB;EAC9C;EACA,QAAQ,OAAO,WAAW;EAC1B,MAAM,UAAU,OAAO,IAAI;EAC3B,YAAY,OAAO;CACpB;AACD;;;;;;;;;;;;;AAaA,SAAS,6BAA6B,aAAa;CAClD,OAAO,CAAC;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/orm-family-sql",
|
|
3
|
-
"version": "8.0.0-rc.11-dev.
|
|
3
|
+
"version": "8.0.0-rc.11-dev.34",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@prisma/orm-framework": "8.0.0-rc.11-dev.
|
|
13
|
-
"@prisma/orm-toolchain": "8.0.0-rc.11-dev.
|
|
12
|
+
"@prisma/orm-framework": "8.0.0-rc.11-dev.34",
|
|
13
|
+
"@prisma/orm-toolchain": "8.0.0-rc.11-dev.34",
|
|
14
14
|
"@standard-schema/spec": "^1.1.0",
|
|
15
15
|
"arktype": "^2.2.2",
|
|
16
16
|
"pathe": "^2.0.3",
|
|
@@ -18,21 +18,21 @@
|
|
|
18
18
|
"ts-toolbelt": "^9.6.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@internal/family-sql": "8.0.0-rc.11-dev.
|
|
22
|
-
"@internal/sql-builder": "8.0.0-rc.11-dev.
|
|
23
|
-
"@internal/sql-contract": "8.0.0-rc.11-dev.
|
|
24
|
-
"@internal/sql-contract-emitter": "8.0.0-rc.11-dev.
|
|
25
|
-
"@internal/sql-contract-prisma7": "8.0.0-rc.11-dev.
|
|
26
|
-
"@internal/sql-contract-psl": "8.0.0-rc.11-dev.
|
|
27
|
-
"@internal/sql-contract-ts": "8.0.0-rc.11-dev.
|
|
28
|
-
"@internal/sql-errors": "8.0.0-rc.11-dev.
|
|
29
|
-
"@internal/sql-operations": "8.0.0-rc.11-dev.
|
|
30
|
-
"@internal/sql-orm-client": "8.0.0-rc.11-dev.
|
|
31
|
-
"@internal/sql-relational-core": "8.0.0-rc.11-dev.
|
|
32
|
-
"@internal/sql-runtime": "8.0.0-rc.11-dev.
|
|
33
|
-
"@internal/sql-schema-ir": "8.0.0-rc.11-dev.
|
|
34
|
-
"@repo/tsconfig": "8.0.0-rc.11-dev.
|
|
35
|
-
"@repo/tsdown": "8.0.0-rc.11-dev.
|
|
21
|
+
"@internal/family-sql": "8.0.0-rc.11-dev.34",
|
|
22
|
+
"@internal/sql-builder": "8.0.0-rc.11-dev.34",
|
|
23
|
+
"@internal/sql-contract": "8.0.0-rc.11-dev.34",
|
|
24
|
+
"@internal/sql-contract-emitter": "8.0.0-rc.11-dev.34",
|
|
25
|
+
"@internal/sql-contract-prisma7": "8.0.0-rc.11-dev.34",
|
|
26
|
+
"@internal/sql-contract-psl": "8.0.0-rc.11-dev.34",
|
|
27
|
+
"@internal/sql-contract-ts": "8.0.0-rc.11-dev.34",
|
|
28
|
+
"@internal/sql-errors": "8.0.0-rc.11-dev.34",
|
|
29
|
+
"@internal/sql-operations": "8.0.0-rc.11-dev.34",
|
|
30
|
+
"@internal/sql-orm-client": "8.0.0-rc.11-dev.34",
|
|
31
|
+
"@internal/sql-relational-core": "8.0.0-rc.11-dev.34",
|
|
32
|
+
"@internal/sql-runtime": "8.0.0-rc.11-dev.34",
|
|
33
|
+
"@internal/sql-schema-ir": "8.0.0-rc.11-dev.34",
|
|
34
|
+
"@repo/tsconfig": "8.0.0-rc.11-dev.34",
|
|
35
|
+
"@repo/tsdown": "8.0.0-rc.11-dev.34",
|
|
36
36
|
"tsdown": "0.22.14",
|
|
37
37
|
"typescript": "5.9.3"
|
|
38
38
|
},
|