@prisma-next/target-postgres 0.16.0-dev.33 → 0.16.0-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/README.md +4 -0
- package/dist/{authoring-DnO1B0N9.mjs → authoring-DL-Y8A7_.mjs} +5 -5
- package/dist/{authoring-DnO1B0N9.mjs.map → authoring-DL-Y8A7_.mjs.map} +1 -1
- package/dist/codec-descriptor-C4SaWX0P.d.mts +36 -0
- package/dist/codec-descriptor-C4SaWX0P.d.mts.map +1 -0
- package/dist/codec-descriptor-cuAuPE0Y.mjs +142 -0
- package/dist/codec-descriptor-cuAuPE0Y.mjs.map +1 -0
- package/dist/codec-descriptor.d.mts +2 -0
- package/dist/codec-descriptor.mjs +2 -0
- package/dist/{codec-types-DdoPc2dy.d.mts → codec-types-Bstec0HR.d.mts} +9 -8
- package/dist/codec-types-Bstec0HR.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs-Deand7sy.mjs → codecs-C-VA-quH.mjs} +228 -40
- package/dist/codecs-C-VA-quH.mjs.map +1 -0
- package/dist/{codecs-CGE5dh94.d.mts → codecs-Cd4TftwI.d.mts} +82 -29
- package/dist/codecs-Cd4TftwI.d.mts.map +1 -0
- package/dist/codecs.d.mts +4 -2
- package/dist/codecs.d.mts.map +1 -1
- package/dist/codecs.mjs +4 -2
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.mjs +2 -2
- package/dist/{control-policy-DEwdS3oK.mjs → control-policy-DMZVl4x7.mjs} +8 -8
- package/dist/{control-policy-DEwdS3oK.mjs.map → control-policy-DMZVl4x7.mjs.map} +1 -1
- package/dist/control.mjs +9 -9
- package/dist/{ddl-BQC6u-L9.mjs → ddl-Db1JOIMn.mjs} +2 -2
- package/dist/{ddl-BQC6u-L9.mjs.map → ddl-Db1JOIMn.mjs.map} +1 -1
- package/dist/{descriptor-meta-DGlJurgA.mjs → descriptor-meta-AnueS0OA.mjs} +4 -4
- package/dist/{descriptor-meta-DGlJurgA.mjs.map → descriptor-meta-AnueS0OA.mjs.map} +1 -1
- package/dist/{diff-database-schema-qRPwuYBH.mjs → diff-database-schema-CluGQkmh.mjs} +8 -8
- package/dist/{diff-database-schema-qRPwuYBH.mjs.map → diff-database-schema-CluGQkmh.mjs.map} +1 -1
- package/dist/diff-database-schema.mjs +1 -1
- package/dist/{errors-DBSNx7EJ.mjs → errors-l1usFTuz.mjs} +2 -2
- package/dist/{errors-DBSNx7EJ.mjs.map → errors-l1usFTuz.mjs.map} +1 -1
- package/dist/errors.d.mts +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.mjs +2 -2
- package/dist/{op-factory-call-CIaPDDUc.mjs → op-factory-call-Cm13qr4w.mjs} +7 -7
- package/dist/{op-factory-call-CIaPDDUc.mjs.map → op-factory-call-Cm13qr4w.mjs.map} +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/pack.d.mts +2 -2
- package/dist/pack.mjs +1 -1
- package/dist/{planner-BhnkIJX-.mjs → planner-CB0e-x6l.mjs} +9 -9
- package/dist/{planner-BhnkIJX-.mjs.map → planner-CB0e-x6l.mjs.map} +1 -1
- package/dist/{planner-ddl-builders-CVo3L7Nd.mjs → planner-ddl-builders-DX8DHY8D.mjs} +4 -4
- package/dist/{planner-ddl-builders-CVo3L7Nd.mjs.map → planner-ddl-builders-DX8DHY8D.mjs.map} +1 -1
- package/dist/planner-ddl-builders.mjs +1 -1
- package/dist/{planner-produced-postgres-migration-BE3EJIRK.mjs → planner-produced-postgres-migration-B0i-PVar.mjs} +3 -3
- package/dist/{planner-produced-postgres-migration-BE3EJIRK.mjs.map → planner-produced-postgres-migration-B0i-PVar.mjs.map} +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-sql-checks-CmiQ6Nei.mjs → planner-sql-checks-D3Xsln1p.mjs} +3 -3
- package/dist/{planner-sql-checks-CmiQ6Nei.mjs.map → planner-sql-checks-D3Xsln1p.mjs.map} +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/planner.mjs +2 -2
- package/dist/{postgres-contract-view-BeIEyZfD.mjs → postgres-contract-view-v-zxqBtj.mjs} +4 -4
- package/dist/{postgres-contract-view-BeIEyZfD.mjs.map → postgres-contract-view-v-zxqBtj.mjs.map} +1 -1
- package/dist/{postgres-migration--BzvpA92.mjs → postgres-migration-D_6w1hJj.mjs} +5 -5
- package/dist/{postgres-migration--BzvpA92.mjs.map → postgres-migration-D_6w1hJj.mjs.map} +1 -1
- package/dist/{postgres-native-enum-BwVNf0Ku.mjs → postgres-native-enum-DqjHPN11.mjs} +2 -2
- package/dist/{postgres-native-enum-BwVNf0Ku.mjs.map → postgres-native-enum-DqjHPN11.mjs.map} +1 -1
- package/dist/{postgres-role-schema-node-bg32e7I-.mjs → postgres-role-schema-node-DOkim7QI.mjs} +3 -3
- package/dist/{postgres-role-schema-node-bg32e7I-.mjs.map → postgres-role-schema-node-DOkim7QI.mjs.map} +1 -1
- package/dist/{postgres-schema-CTplQZDK.mjs → postgres-schema-DAhXnFac.mjs} +4 -4
- package/dist/{postgres-schema-CTplQZDK.mjs.map → postgres-schema-DAhXnFac.mjs.map} +1 -1
- package/dist/{postgres-table-schema-node-D6LvInCe.mjs → postgres-table-schema-node-DXzwiu16.mjs} +2 -2
- package/dist/{postgres-table-schema-node-D6LvInCe.mjs.map → postgres-table-schema-node-DXzwiu16.mjs.map} +1 -1
- package/dist/{render-ops-TcY9XEkz.mjs → render-ops-DIjVRr1-.mjs} +2 -2
- package/dist/{render-ops-TcY9XEkz.mjs.map → render-ops-DIjVRr1-.mjs.map} +1 -1
- package/dist/render-ops.mjs +1 -1
- package/dist/{resolve-ddl-schema-BAsJEKW8.mjs → resolve-ddl-schema-nTvL_9Nq.mjs} +2 -2
- package/dist/{resolve-ddl-schema-BAsJEKW8.mjs.map → resolve-ddl-schema-nTvL_9Nq.mjs.map} +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/schema-ir-annotations.mjs +1 -1
- package/dist/{sql-utils-B2lzkKfP.mjs → sql-utils-CuKSscKn.mjs} +2 -2
- package/dist/{sql-utils-B2lzkKfP.mjs.map → sql-utils-CuKSscKn.mjs.map} +1 -1
- package/dist/sql-utils.mjs +1 -1
- package/dist/types.mjs +4 -4
- package/package.json +21 -20
- package/src/core/codec-descriptor.ts +318 -0
- package/src/core/codec-type-map.ts +12 -14
- package/src/core/codecs.ts +232 -39
- package/src/core/registry.ts +4 -0
- package/src/exports/codec-descriptor.ts +11 -0
- package/src/exports/codecs.ts +4 -1
- package/dist/codec-types-DdoPc2dy.d.mts.map +0 -1
- package/dist/codecs-CGE5dh94.d.mts.map +0 -1
- package/dist/codecs-Deand7sy.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -113,6 +113,10 @@ export const contract = defineContract({
|
|
|
113
113
|
|
|
114
114
|
Pack refs are pure JSON-friendly objects that make TypeScript contract authoring work in both emit and no-emit workflows without requiring separate manifest files.
|
|
115
115
|
|
|
116
|
+
## Codec descriptor authoring
|
|
117
|
+
|
|
118
|
+
PostgreSQL-bound codecs use the public `PostgresCodecDescriptor` protocol, `postgresCodec(...)` adapter, and `definePostgresCodecs(...)` tuple helper exported from `@prisma-next/target-postgres/codec-descriptor`. See the [codec authoring guide](../../../../docs/reference/codec-authoring-guide.md#target-owned-sql-codec-descriptors) for subclassing, generic adaptation, stack contribution, validation, array projection, and the current renderer transition.
|
|
119
|
+
|
|
116
120
|
## Architecture
|
|
117
121
|
|
|
118
122
|
This package provides both control and runtime entry points for the Postgres target. All declarative fields (version, capabilities, types, operations) are defined directly on the descriptor, so the published entry points never touch the filesystem. The `./pack` entry point provides a pure pack ref for contract authoring. The runtime entry point will provide target-specific runtime functionality in the future.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { o as PG_ENUM_CODEC_ID } from "./codec-ids-D3G8K0YM.mjs";
|
|
2
|
-
import { n as postgresError } from "./errors-
|
|
3
|
-
import { t as PostgresNativeEnum } from "./postgres-native-enum-
|
|
4
|
-
import { _ as PostgresRlsEnablement, d as PostgresRlsEnablementSchema, f as PostgresRlsPolicySchema, g as PostgresRlsPolicy, m as PostgresRole, p as PostgresRoleSchema, u as PostgresNativeEnumSchema } from "./postgres-schema-
|
|
2
|
+
import { n as postgresError } from "./errors-l1usFTuz.mjs";
|
|
3
|
+
import { t as PostgresNativeEnum } from "./postgres-native-enum-DqjHPN11.mjs";
|
|
4
|
+
import { _ as PostgresRlsEnablement, d as PostgresRlsEnablementSchema, f as PostgresRlsPolicySchema, g as PostgresRlsPolicy, m as PostgresRole, p as PostgresRoleSchema, u as PostgresNativeEnumSchema } from "./postgres-schema-DAhXnFac.mjs";
|
|
5
5
|
import { n as computeContentHash, t as POLICY_OPERATION_PREDICATES } from "./canonicalize-C7zKHw8m.mjs";
|
|
6
|
-
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
7
6
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
7
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
8
8
|
import { temporalAuthoringPresets, temporalCodecPresetWithPrecision } from "@prisma-next/family-sql/control";
|
|
9
9
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
10
10
|
import { modelAttribute } from "@prisma-next/psl-parser";
|
|
@@ -692,4 +692,4 @@ function postgresLowerEntityHandles(input) {
|
|
|
692
692
|
//#endregion
|
|
693
693
|
export { postgresAuthoringTypes as a, postgresAuthoringPslBlockDescriptors as i, postgresAuthoringFieldPresets as n, postgresLowerEntityHandles as o, postgresAuthoringModelAttributes as r, postgresAuthoringEntityTypes as t };
|
|
694
694
|
|
|
695
|
-
//# sourceMappingURL=authoring-
|
|
695
|
+
//# sourceMappingURL=authoring-DL-Y8A7_.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authoring-DnO1B0N9.mjs","names":[],"sources":["../src/core/authoring.ts"],"sourcesContent":["import {\n temporalAuthoringPresets,\n temporalCodecPresetWithPrecision,\n} from '@prisma-next/family-sql/control';\nimport type {\n AuthoringEntityContext,\n AuthoringEntityTypeFactoryOutput,\n AuthoringEntityTypeNamespace,\n AuthoringFieldNamespace,\n AuthoringModelAttributeContext,\n AuthoringModelAttributeDescriptorNamespace,\n AuthoringPslBlockDescriptorNamespace,\n AuthoringTypeNamespace,\n PslExtensionBlock,\n} from '@prisma-next/framework-components/authoring';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport { modelAttribute } from '@prisma-next/psl-parser';\nimport type {\n EntityHandleLoweringInput,\n LoweredPackEntity,\n ResolvedEntityHandleRef,\n ResolvedPslModelRefs,\n} from '@prisma-next/sql-contract/entity-handle-lowering-hook';\nimport type { SqlValueSetDerivingEntityTypeOutput } from '@prisma-next/sql-contract/value-set-derivation-hook';\nimport {\n assertWireNamePrefixLength,\n formatWireName,\n normalizeSqlBody,\n} from '@prisma-next/sql-schema-ir/naming';\nimport { assertDefined } from '@prisma-next/utils/assertions';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { PG_ENUM_CODEC_ID } from './codec-ids';\nimport { postgresError } from './errors';\nimport { PostgresNativeEnum } from './postgres-native-enum';\nimport { PostgresRlsEnablement, type PostgresRlsEnablementInput } from './postgres-rls-enablement';\nimport { PostgresRlsPolicy, type RlsPolicyOperation } from './postgres-rls-policy';\nimport { PostgresRole } from './postgres-role';\nimport {\n PostgresNativeEnumSchema,\n PostgresRlsEnablementSchema,\n PostgresRlsPolicySchema,\n PostgresRoleSchema,\n} from './postgres-validators';\nimport { computeContentHash, POLICY_OPERATION_PREDICATES } from './rls/canonicalize';\n\n/**\n * `pg.enum(<ref>)` registers as an ordinary type constructor whose sole\n * positional argument names a `native_enum` entity instead of carrying a\n * literal value. The interpreter resolves the ref to the `native_enum`\n * entity generically (driven by `entityRefArg`); the `pg/enum@1` codec\n * descriptor's `columnFromEntity` hook (see `codecs.ts`) converts that\n * entity into the column's `typeParams` and native type.\n */\nexport const postgresAuthoringTypes = {\n pg: {\n enum: {\n kind: 'typeConstructor',\n entityRefArg: { index: 0, entityKind: 'native_enum' },\n output: {\n codecId: PG_ENUM_CODEC_ID,\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n\nexport interface RlsPolicyExtensionBlock extends PslExtensionBlock {\n readonly namespaceId: string;\n /**\n * Model refs the family interpreter resolved from the block's descriptor-\n * declared `refKind: 'model'` parameters before invoking this factory\n * (keyed by parameter name). An unresolved required ref is the\n * interpreter's diagnostic; the factory is never called with one missing.\n */\n readonly resolvedModelRefs?: ResolvedPslModelRefs;\n}\n\n/** A parsed `role` block annotated with its lexical namespace id by the interpreter. */\nexport interface RoleExtensionBlock extends PslExtensionBlock {\n readonly namespaceId: string;\n}\n\n/**\n * Maps a `policy_<op>` keyword to the RLS operation it authors. The keyword\n * IS the operation (per the project's rejection of a `policy { operation = … }`\n * conditional block).\n */\nconst POLICY_KEYWORD_OPERATION: Readonly<Record<string, RlsPolicyOperation>> = {\n policy_select: 'select',\n policy_insert: 'insert',\n policy_update: 'update',\n policy_delete: 'delete',\n policy_all: 'all',\n};\n\nfunction readValueParam(block: PslExtensionBlock, key: string): string | undefined {\n const param = block.parameters[key];\n return param?.kind === 'value' ? param.raw : undefined;\n}\n\nfunction readListRefParams(block: PslExtensionBlock, key: string): string[] {\n const param = block.parameters[key];\n if (param?.kind !== 'list') return [];\n return param.items.flatMap((item) => (item.kind === 'ref' ? [item.identifier] : []));\n}\n\n/**\n * Unwraps a quoted PSL string argument, inverting the printer's\n * `escapePslString` escapes (`\\\\`, `\\\"`, `\\n`, `\\r`). An unknown escape\n * sequence is kept verbatim, matching the printer-side `unescapePslString`\n * convention.\n */\nfunction unwrapQuotedString(raw: string): string {\n if (!(raw.startsWith('\"') && raw.endsWith('\"') && raw.length >= 2)) {\n return raw;\n }\n const inner = raw.slice(1, -1);\n let result = '';\n for (let i = 0; i < inner.length; i++) {\n if (inner[i] !== '\\\\' || i + 1 >= inner.length) {\n result += inner[i];\n continue;\n }\n const next = inner[i + 1];\n if (next === '\\\\' || next === '\"') {\n result += next;\n } else if (next === 'n') {\n result += '\\n';\n } else if (next === 'r') {\n result += '\\r';\n } else {\n result += '\\\\';\n result += next;\n }\n i++;\n }\n return result;\n}\n\n/**\n * Assembles a {@link PostgresRlsPolicy} from lowered inputs: normalizes the\n * predicates, computes the content-hash wire name, and constructs the frozen\n * entity. The single hash-assembly body shared by the PSL block lowering\n * ({@link lowerRlsPolicyFromBlock}) and the TS entity-handle lowering\n * ({@link postgresLowerEntityHandles}) so the two surfaces cannot drift.\n */\nfunction buildRlsPolicyEntity(input: {\n readonly prefix: string;\n readonly tableName: string;\n readonly namespaceId: string;\n readonly operation: RlsPolicyOperation;\n readonly roles: readonly string[];\n readonly using?: string;\n readonly withCheck?: string;\n}): PostgresRlsPolicy {\n const wireHash = computeContentHash({\n ...ifDefined('using', input.using !== undefined ? normalizeSqlBody(input.using) : undefined),\n ...ifDefined(\n 'withCheck',\n input.withCheck !== undefined ? normalizeSqlBody(input.withCheck) : undefined,\n ),\n roles: input.roles,\n operation: input.operation,\n permissive: true,\n });\n\n return new PostgresRlsPolicy({\n name: formatWireName(input.prefix, wireHash),\n prefix: input.prefix,\n tableName: input.tableName,\n namespaceId: input.namespaceId,\n operation: input.operation,\n roles: input.roles,\n ...ifDefined('using', input.using),\n ...ifDefined('withCheck', input.withCheck),\n permissive: true,\n });\n}\n\nfunction lowerRlsPolicyFromBlock(\n block: RlsPolicyExtensionBlock,\n ctx: AuthoringEntityContext,\n): PostgresRlsPolicy | undefined {\n const prefix = block.name;\n const operation = POLICY_KEYWORD_OPERATION[block.keyword] ?? 'select';\n // The interpreter resolves the descriptor-declared `target` model ref to\n // its storage table name before invoking this factory (an unresolved or\n // missing required ref is the interpreter's diagnostic), so a lookup miss\n // here is structurally impossible.\n const tableName = block.resolvedModelRefs?.['target']?.tableName;\n assertDefined(\n tableName,\n `lowerRlsPolicyFromBlock: policy \"${block.name}\" reached the factory without a resolved \\`target\\` ref; the interpreter resolves same-namespace model refs before invoking entity factories.`,\n );\n const roles = [...readListRefParams(block, 'roles')].sort();\n\n const usingRaw = readValueParam(block, 'using');\n const withCheckRaw = readValueParam(block, 'withCheck');\n\n // Reject a predicate the operation does not take (e.g. `using` on INSERT, or\n // `withCheck` on SELECT/DELETE). The descriptor's param set already omits it,\n // but the generic descriptor validator is not wired into the SQL-family\n // interpreter, so the lowering enforces the per-operation predicate matrix\n // directly — a wrong predicate is a load-time diagnostic, not a silent drop.\n const support = POLICY_OPERATION_PREDICATES[operation];\n const rejectPredicate = (predicate: 'using' | 'withCheck'): undefined => {\n ctx.diagnostics?.push({\n code: 'PSL_RLS_PREDICATE_NOT_FOR_OPERATION',\n message: `\\`${block.keyword}\\` policy \"${block.name}\" does not take a \\`${predicate}\\` predicate; the ${operation.toUpperCase()} operation uses ${support.using ? '`using`' : '`withCheck`'}${support.using && support.withCheck ? ' and `withCheck`' : ' only'}.`,\n sourceId: ctx.sourceId ?? 'unknown',\n span: block.parameters[predicate]?.span ?? block.span,\n });\n return undefined;\n };\n if (usingRaw !== undefined && !support.using) return rejectPredicate('using');\n if (withCheckRaw !== undefined && !support.withCheck) return rejectPredicate('withCheck');\n\n const using = usingRaw !== undefined ? unwrapQuotedString(usingRaw) : undefined;\n const withCheck = withCheckRaw !== undefined ? unwrapQuotedString(withCheckRaw) : undefined;\n\n return buildRlsPolicyEntity({\n prefix,\n tableName,\n namespaceId: block.namespaceId,\n operation,\n roles,\n ...ifDefined('using', using),\n ...ifDefined('withCheck', withCheck),\n });\n}\n\n/**\n * Lowers a `native_enum { memberName = \"value\" … @@map(\"type_name\") }` block\n * into a {@link PostgresNativeEnum}. Members must be authored as explicit\n * `key = \"value\"` pairs — a bare (value-less) member is a diagnostic, not\n * accepted (authoring-design.md §2.1). The parsed `memberName` is only used\n * to duplicate-check and report diagnostics; the lowered entity carries just\n * the member values (a native enum is value-only — the member \"name\" isn't\n * a separate authoring concept from the value). `typeName` comes from\n * `@@map` or defaults to the block name verbatim.\n */\nfunction lowerNativeEnumFromBlock(\n block: PslExtensionBlock,\n ctx: AuthoringEntityContext,\n): PostgresNativeEnum | undefined {\n const sourceId = ctx.sourceId ?? 'unknown';\n const diagnostics = ctx.diagnostics;\n\n const mapAttr = block.blockAttributes.find((a) => a.name === 'map');\n let typeName = block.name;\n if (mapAttr) {\n const rawArg = mapAttr.args[0]?.value;\n const mapped = rawArg !== undefined ? unwrapQuotedString(rawArg) : undefined;\n if (mapped === undefined) {\n diagnostics?.push({\n code: 'PSL_NATIVE_ENUM_INVALID_MAP',\n message: `native_enum \"${block.name}\" @@map attribute must have a quoted type-name argument`,\n sourceId,\n span: mapAttr.span,\n });\n return undefined;\n }\n typeName = mapped;\n }\n\n let memberError = false;\n const seenValues = new Set<string>();\n const members: string[] = [];\n for (const [memberName, paramValue] of Object.entries(block.parameters)) {\n if (paramValue.kind === 'bare') {\n diagnostics?.push({\n code: 'PSL_NATIVE_ENUM_BARE_MEMBER',\n message: `native_enum \"${block.name}\" member \"${memberName}\" has no value; members must be authored as \"${memberName} = \\\\\"value\\\\\"\"`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n if (paramValue.kind !== 'value') continue;\n\n let jsonValue: unknown;\n try {\n jsonValue = JSON.parse(paramValue.raw);\n } catch {\n diagnostics?.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `native_enum \"${block.name}\" member \"${memberName}\" value \"${paramValue.raw}\" is not valid JSON`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n if (typeof jsonValue !== 'string') {\n diagnostics?.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `native_enum \"${block.name}\" member \"${memberName}\" value must be a string`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n if (seenValues.has(jsonValue)) {\n diagnostics?.push({\n code: 'PSL_NATIVE_ENUM_DUPLICATE_MEMBER_VALUE',\n message: `native_enum \"${block.name}\": duplicate member value \"${jsonValue}\"`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n seenValues.add(jsonValue);\n members.push(jsonValue);\n }\n\n if (memberError) return undefined;\n\n if (members.length === 0) {\n diagnostics?.push({\n code: 'PSL_NATIVE_ENUM_MISSING_MEMBERS',\n message: `native_enum \"${block.name}\" must have at least one member`,\n sourceId,\n span: block.span,\n });\n return undefined;\n }\n\n // `control` stays unset — the effective grade is resolved at read time via `effectiveControlPolicy`, like `StorageTable`/`StorageColumn`.\n return new PostgresNativeEnum({ typeName, members });\n}\n\n/**\n * `native_enum`'s entity-type factory output, checked separately from the assembled\n * `postgresAuthoringEntityTypes` map below: `deriveValueSet` is SQL-family surface\n * ({@link SqlValueSetDerivingEntityTypeOutput}), not part of the framework\n * `AuthoringEntityTypeFactoryOutput` shape, so folding it directly into the map's single\n * `satisfies AuthoringEntityTypeNamespace` check would trip an excess-property error. Checking it\n * here against the intersection of both shapes keeps it structurally valid against each without\n * widening the map's own check.\n */\nconst nativeEnumEntityTypeOutput = {\n factory: lowerNativeEnumFromBlock,\n deriveValueSet: (entity: PostgresNativeEnum) => ({\n kind: 'valueSet' as const,\n values: [...entity.members],\n }),\n} satisfies AuthoringEntityTypeFactoryOutput<PslExtensionBlock, PostgresNativeEnum | undefined> &\n SqlValueSetDerivingEntityTypeOutput;\n\n/**\n * Lowers a `role <name> {}` block into a {@link PostgresRole}. Roles are\n * cluster-scoped in Postgres, so the block must be declared inside\n * `namespace unbound { … }` — any other lexical namespace (a named schema,\n * or the default bucket top-level declarations resolve to) is a load-time\n * diagnostic. The lowered entity carries the unbound coordinate.\n */\nfunction lowerRoleFromBlock(\n block: RoleExtensionBlock,\n ctx: AuthoringEntityContext,\n): PostgresRole | undefined {\n if (block.namespaceId !== UNBOUND_NAMESPACE_ID) {\n ctx.diagnostics?.push({\n code: 'PSL_ROLE_BLOCK_OUTSIDE_UNBOUND_NAMESPACE',\n message: `\\`role\\` block \"${block.name}\" must be declared inside \\`namespace unbound { }\\`, not in namespace \"${block.namespaceId}\"`,\n sourceId: ctx.sourceId ?? 'unknown',\n span: block.span,\n });\n return undefined;\n }\n return new PostgresRole({ name: block.name, namespaceId: UNBOUND_NAMESPACE_ID });\n}\n\nexport const postgresAuthoringEntityTypes = {\n role: {\n kind: 'entity',\n discriminator: 'role',\n validatorSchema: PostgresRoleSchema,\n output: {\n factory: lowerRoleFromBlock,\n },\n },\n rls: {\n kind: 'entity',\n discriminator: 'rls',\n validatorSchema: PostgresRlsEnablementSchema,\n output: {\n factory: (input: PostgresRlsEnablementInput): PostgresRlsEnablement =>\n new PostgresRlsEnablement(input),\n },\n },\n policy: {\n kind: 'entity',\n discriminator: 'policy',\n validatorSchema: PostgresRlsPolicySchema,\n output: {\n factory: lowerRlsPolicyFromBlock,\n },\n },\n native_enum: {\n kind: 'entity',\n discriminator: 'native_enum',\n validatorSchema: PostgresNativeEnumSchema,\n output: nativeEnumEntityTypeOutput,\n },\n} as const satisfies AuthoringEntityTypeNamespace;\n\n/**\n * Field presets contributed by the Postgres target pack.\n *\n * These mirror the PSL scalar-to-codec mapping used by the Postgres adapter\n * (see `createPostgresPslScalarTypeDescriptors`), so that authoring a field\n * via the TS callback surface (e.g. `field.int()`) and via the PSL scalar\n * surface (e.g. `Int`) lowers to byte-identical contracts.\n *\n * The `uuidNative` / `id.uuidv4Native` / `id.uuidv7Native` presets use the\n * native Postgres `uuid` type (codecId `pg/uuid@1`). For cross-target\n * portability use `uuidString` / `id.uuidv4String` / `id.uuidv7String` from\n * the family pack instead.\n */\n/**\n * Shared parameter descriptors for the five `policy_<op>` PSL block\n * keywords. All five share the `policy` discriminator — the parser\n * dispatches by keyword (see the framework's PSL-block SPI), and every\n * keyword's factory lowers to `PostgresRlsPolicy` via `lowerRlsPolicyFromBlock`.\n *\n * The `roles` list uses `scope:'cross-space'` because same-namespace\n * role ref resolution requires PSL namespace entries keyed by `refKind`\n * (i.e. `'role'`), which in turn requires the role block discriminator to\n * equal `'role'`. Aligning discriminator with refKind is tracked for\n * slice 4 (cross-space roles). Until then cross-space passes validation\n * unconditionally and the authored role names flow through unchanged.\n */\nconst policyTargetParam = {\n kind: 'ref',\n refKind: 'model',\n scope: 'same-namespace',\n required: true,\n} as const;\nconst policyRolesParam = {\n kind: 'list',\n of: { kind: 'ref', refKind: 'role', scope: 'cross-space' },\n} as const;\nconst policyPredicateParam = { kind: 'value', codecId: 'pg/text@1', required: true } as const;\n// A policy may only target an RLS-controlled model: the model named by\n// `target` must declare `@@rls`, or the load fails with a diagnostic naming\n// the model and the policy prefix.\nconst policyRequiresRls = { parameter: 'target', attribute: 'rls' } as const;\n\nexport const postgresAuthoringPslBlockDescriptors = {\n // The predicate param set per keyword mirrors Postgres: SELECT/DELETE take\n // USING only; INSERT takes WITH CHECK only; UPDATE/ALL take both. The\n // per-operation predicate matrix is enforced in `lowerRlsPolicyFromBlock`\n // (a wrong predicate for the operation is a load-time diagnostic there),\n // since the generic descriptor validator is not wired into the SQL-family\n // interpreter.\n policy_select: {\n kind: 'pslBlock',\n keyword: 'policy_select',\n discriminator: 'policy',\n name: { required: true },\n parameters: { target: policyTargetParam, roles: policyRolesParam, using: policyPredicateParam },\n requiresModelAttribute: policyRequiresRls,\n },\n policy_delete: {\n kind: 'pslBlock',\n keyword: 'policy_delete',\n discriminator: 'policy',\n name: { required: true },\n parameters: { target: policyTargetParam, roles: policyRolesParam, using: policyPredicateParam },\n requiresModelAttribute: policyRequiresRls,\n },\n policy_insert: {\n kind: 'pslBlock',\n keyword: 'policy_insert',\n discriminator: 'policy',\n name: { required: true },\n parameters: {\n target: policyTargetParam,\n roles: policyRolesParam,\n withCheck: policyPredicateParam,\n },\n requiresModelAttribute: policyRequiresRls,\n },\n policy_update: {\n kind: 'pslBlock',\n keyword: 'policy_update',\n discriminator: 'policy',\n name: { required: true },\n parameters: {\n target: policyTargetParam,\n roles: policyRolesParam,\n using: policyPredicateParam,\n withCheck: policyPredicateParam,\n },\n requiresModelAttribute: policyRequiresRls,\n },\n policy_all: {\n kind: 'pslBlock',\n keyword: 'policy_all',\n discriminator: 'policy',\n name: { required: true },\n parameters: {\n target: policyTargetParam,\n roles: policyRolesParam,\n using: policyPredicateParam,\n withCheck: policyPredicateParam,\n },\n requiresModelAttribute: policyRequiresRls,\n },\n /**\n * PSL block descriptor for `native_enum`.\n *\n * Reuses the existing variadic-block mechanism (the same shape the SQL\n * family's `enum` block ships): the body is an open `memberName = \"value\"`\n * list. `variadicParameters: true` opens the block to arbitrary keys\n * beyond the declared (empty) `parameters` set — the lowering factory\n * (`lowerNativeEnumFromBlock`) turns the variadic entries into ordered\n * members and rejects a bare (value-less) member.\n */\n native_enum: {\n kind: 'pslBlock',\n keyword: 'native_enum',\n discriminator: 'native_enum',\n name: { required: true },\n parameters: {},\n variadicParameters: true,\n },\n /**\n * PSL block descriptor for `role` (e.g. `role anon {}`). Name-only, no\n * parameters and no body content. Declared inside `namespace unbound { }`\n * — see {@link lowerRoleFromBlock} for the placement check and the\n * coordinate the lowered entity carries.\n */\n role: {\n kind: 'pslBlock',\n keyword: 'role',\n discriminator: 'role',\n name: { required: true },\n parameters: {},\n },\n} as const satisfies AuthoringPslBlockDescriptorNamespace;\n\n/**\n * `@@` model attributes contributed by the Postgres target pack.\n *\n * `@@rls` is argument-less: presence marks the model's table\n * RLS-controlled. It lowers to a {@link PostgresRlsEnablement} marker in\n * the namespace's `entries.rls`, keyed by the model's table name — the\n * marker (never the policy set) is what drives\n * `ENABLE`/`DISABLE ROW LEVEL SECURITY` planning.\n */\nexport const postgresAuthoringModelAttributes = {\n rls: {\n kind: 'modelAttribute',\n attribute: 'rls',\n spec: modelAttribute('rls', {}),\n lower: (_parsed: Record<never, never>, ctx: AuthoringModelAttributeContext) => ({\n key: ctx.storageName,\n entity: new PostgresRlsEnablement({\n tableName: ctx.storageName,\n namespaceId: ctx.namespaceId,\n }),\n }),\n },\n} as const satisfies AuthoringModelAttributeDescriptorNamespace;\n\nexport const postgresAuthoringFieldPresets = {\n text: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/text@1',\n nativeType: 'text',\n },\n },\n int: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/int4@1',\n nativeType: 'int4',\n },\n },\n bigint: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/int8@1',\n nativeType: 'int8',\n },\n },\n float: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/float8@1',\n nativeType: 'float8',\n },\n },\n decimal: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/numeric@1',\n nativeType: 'numeric',\n },\n },\n boolean: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/bool@1',\n nativeType: 'bool',\n },\n },\n json: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/jsonb@1',\n nativeType: 'jsonb',\n },\n },\n bytes: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/bytea@1',\n nativeType: 'bytea',\n },\n },\n dateTime: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n },\n },\n temporal: {\n .../* @__PURE__ */ temporalAuthoringPresets({\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n }),\n timestamp: /* @__PURE__ */ temporalCodecPresetWithPrecision({\n codecId: 'pg/timestamp@1',\n nativeType: 'timestamp',\n }),\n timestamptz: /* @__PURE__ */ temporalCodecPresetWithPrecision({\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n }),\n },\n uuidNative: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/uuid@1',\n nativeType: 'uuid',\n },\n },\n id: {\n uuidv4Native: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/uuid@1',\n nativeType: 'uuid',\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv4',\n },\n },\n id: true,\n },\n },\n uuidv7Native: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/uuid@1',\n nativeType: 'uuid',\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv7',\n },\n },\n id: true,\n },\n },\n },\n} as const satisfies AuthoringFieldNamespace;\n\ninterface RlsRoleHandleShape {\n readonly entityKind: 'role';\n readonly name: string;\n}\n\ninterface RlsPolicyHandleShape {\n readonly entityKind: 'policy';\n readonly operation: RlsPolicyOperation;\n readonly name: string;\n readonly roles: readonly { readonly name: string }[];\n readonly using?: string;\n readonly withCheck?: string;\n}\n\ninterface RlsTargetCoordinate {\n readonly namespaceId: string;\n readonly tableName: string;\n}\n\n/**\n * Resolves an entity handle's `target` ref to a table coordinate of this\n * contract, or throws the load-time diagnostic naming the handle: a\n * cross-space target is rejected (you cannot CREATE POLICY on a table\n * another space owns) and an unresolved target names the model.\n */\nfunction requireLocalTarget(\n refs: Readonly<Record<string, ResolvedEntityHandleRef>>,\n subject: string,\n): RlsTargetCoordinate {\n const target = refs['target'];\n if (target !== undefined && target.kind === 'resolved') {\n return { namespaceId: target.namespaceId, tableName: target.tableName };\n }\n if (target !== undefined && target.kind === 'cross-space') {\n throw postgresError(\n 'CONTRACT.POLICY_INVALID',\n `defineContract: ${subject} targets model \"${target.modelName ?? target.tableName}\", which lives in another contract space. Policies and rlsEnabled entries must target a model declared in this contract.`,\n { meta: { model: target.modelName ?? target.tableName, reason: 'cross-space-target' } },\n );\n }\n throw postgresError(\n 'CONTRACT.MODEL_UNKNOWN',\n `defineContract: ${subject} targets model \"${target?.modelName ?? '<anonymous>'}\", which is not in the contract's models. Add the model to \\`models\\`.`,\n { meta: { model: target?.modelName ?? '<anonymous>' } },\n );\n}\n\n/**\n * The SQL-family entity-handle batch lowering hook for the Postgres pack\n * (`SqlEntityHandleLoweringContribution`). Receives every `entities` handle\n * whose kind this pack registered — batch, so the cross-entity diagnostics\n * (duplicate prefix, policy without rlsEnabled, duplicate role) can see\n * sibling handles — and lowers them with the same keying and hash assembly\n * as the PSL path: `policy` keyed by prefix (wire name via\n * {@link buildRlsPolicyEntity}), `rls` keyed by table name, `role` keyed by\n * name and filed under the default namespace (roles are declared\n * contract-wide; PSL has no role block to set a precedent).\n */\nexport function postgresLowerEntityHandles(\n input: EntityHandleLoweringInput,\n): readonly LoweredPackEntity[] {\n const enablements = new Map<\n string,\n { coordinate: RlsTargetCoordinate; entity: PostgresRlsEnablement }\n >();\n const roles = new Map<string, PostgresRole>();\n const policies: {\n readonly handle: RlsPolicyHandleShape;\n readonly refs: Readonly<Record<string, ResolvedEntityHandleRef>>;\n }[] = [];\n const coordinateKey = (coordinate: RlsTargetCoordinate): string =>\n `${coordinate.namespaceId} ${coordinate.tableName}`;\n\n for (const { handle, refs } of input.handles) {\n switch (handle.entityKind) {\n case 'rls': {\n const coordinate = requireLocalTarget(refs, 'an rlsEnabled entry');\n const key = coordinateKey(coordinate);\n if (!enablements.has(key)) {\n enablements.set(key, {\n coordinate,\n entity: new PostgresRlsEnablement({\n tableName: coordinate.tableName,\n namespaceId: coordinate.namespaceId,\n }),\n });\n }\n break;\n }\n case 'role': {\n const roleHandle = blindCast<\n RlsRoleHandleShape,\n 'role handles are constructed only by the postgres contract-builder role() constructor, which enforces this shape'\n >(handle);\n if (roles.has(roleHandle.name)) {\n throw postgresError(\n 'CONTRACT.ROLE_INVALID',\n `defineContract: role \"${roleHandle.name}\" is declared more than once in the entities list.`,\n { meta: { role: roleHandle.name, reason: 'duplicate' } },\n );\n }\n // Roles are cluster-scoped in Postgres, so they always land in the\n // `__unbound__` namespace — identical to a PSL `role` block\n // (`lowerRoleFromBlock`) and matching the `PostgresRole` class's own\n // contract. The declaring surface (TS entities vs PSL) does not move\n // the slot.\n roles.set(\n roleHandle.name,\n new PostgresRole({ name: roleHandle.name, namespaceId: UNBOUND_NAMESPACE_ID }),\n );\n break;\n }\n case 'policy': {\n const policyHandle = blindCast<\n RlsPolicyHandleShape,\n 'policy handles are constructed only by the postgres contract-builder policy*() constructors, which enforce this shape'\n >(handle);\n policies.push({ handle: policyHandle, refs });\n break;\n }\n default:\n throw postgresError(\n 'CONTRACT.ENTITY_KIND_INVALID',\n `defineContract: the postgres pack does not lower \"${handle.entityKind}\" handles from the entities list.`,\n { meta: { entityKind: handle.entityKind } },\n );\n }\n }\n\n const rows: LoweredPackEntity[] = [];\n const seenPrefixes = new Set<string>();\n\n for (const { handle: policy, refs } of policies) {\n const prefix = policy.name;\n assertWireNamePrefixLength(prefix, 'defineContract: policy prefix');\n const coordinate = requireLocalTarget(refs, `policy \"${prefix}\"`);\n if (!enablements.has(coordinateKey(coordinate))) {\n const target = refs['target'];\n throw postgresError(\n 'CONTRACT.POLICY_INVALID',\n `defineContract: policy \"${prefix}\" targets model \"${target?.modelName ?? coordinate.tableName}\", whose table is not RLS-enabled. Add rlsEnabled(<model>) to the entities list.`,\n {\n meta: {\n prefix,\n model: target?.modelName ?? coordinate.tableName,\n reason: 'target-not-rls-enabled',\n },\n },\n );\n }\n const prefixKey = `${coordinate.namespaceId} ${prefix}`;\n if (seenPrefixes.has(prefixKey)) {\n throw postgresError(\n 'CONTRACT.POLICY_INVALID',\n `defineContract: policy prefix \"${prefix}\" is declared more than once in namespace \"${coordinate.namespaceId}\". Policy prefixes must be unique per namespace.`,\n { meta: { prefix, namespaceId: coordinate.namespaceId, reason: 'duplicate-prefix' } },\n );\n }\n seenPrefixes.add(prefixKey);\n\n const roleNames = [...new Set(policy.roles.map((roleHandle) => roleHandle.name))].sort();\n rows.push({\n namespaceId: coordinate.namespaceId,\n entityKind: 'policy',\n key: prefix,\n entity: buildRlsPolicyEntity({\n prefix,\n tableName: coordinate.tableName,\n namespaceId: coordinate.namespaceId,\n operation: policy.operation,\n roles: roleNames,\n ...ifDefined('using', policy.using),\n ...ifDefined('withCheck', policy.withCheck),\n }),\n });\n }\n\n for (const { coordinate, entity } of enablements.values()) {\n rows.push({\n namespaceId: coordinate.namespaceId,\n entityKind: 'rls',\n key: coordinate.tableName,\n entity,\n });\n }\n for (const [name, entity] of roles) {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,OAAO,QAAQ,aAAa,WAAW;IACvC,QAAQ;GACV,EACF,CACF;EACF;EACA,MAAM,YAAY,GAAG,WAAW,YAAY,GAAG;EAC/C,IAAI,aAAa,IAAI,SAAS,GAC5B,MAAM,cACJ,2BACA,kCAAkC,OAAO,6CAA6C,WAAW,YAAY,mDAC7G,EAAE,MAAM;GAAE;GAAQ,aAAa,WAAW;GAAa,QAAQ;EAAmB,EAAE,CACtF;EAEF,aAAa,IAAI,SAAS;EAE1B,MAAM,YAAY,CAAC,GAAG,IAAI,IAAI,OAAO,MAAM,KAAK,eAAe,WAAW,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK;EACvF,KAAK,KAAK;GACR,aAAa,WAAW;GACxB,YAAY;GACZ,KAAK;GACL,QAAQ,qBAAqB;IAC3B;IACA,WAAW,WAAW;IACtB,aAAa,WAAW;IACxB,WAAW,OAAO;IAClB,OAAO;IACP,GAAG,UAAU,SAAS,OAAO,KAAK;IAClC,GAAG,UAAU,aAAa,OAAO,SAAS;GAC5C,CAAC;EACH,CAAC;CACH;CAEA,KAAK,MAAM,EAAE,YAAY,YAAY,YAAY,OAAO,GACtD,KAAK,KAAK;EACR,aAAa,WAAW;EACxB,YAAY;EACZ,KAAK,WAAW;EAChB;CACF,CAAC;CAEH,KAAK,MAAM,CAAC,MAAM,WAAW,OAC3B,KAAK,KAAK;EAAE,aAAa;EAAsB,YAAY;EAAQ,KAAK;EAAM;CAAO,CAAC;CAExF,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"authoring-DL-Y8A7_.mjs","names":[],"sources":["../src/core/authoring.ts"],"sourcesContent":["import {\n temporalAuthoringPresets,\n temporalCodecPresetWithPrecision,\n} from '@prisma-next/family-sql/control';\nimport type {\n AuthoringEntityContext,\n AuthoringEntityTypeFactoryOutput,\n AuthoringEntityTypeNamespace,\n AuthoringFieldNamespace,\n AuthoringModelAttributeContext,\n AuthoringModelAttributeDescriptorNamespace,\n AuthoringPslBlockDescriptorNamespace,\n AuthoringTypeNamespace,\n PslExtensionBlock,\n} from '@prisma-next/framework-components/authoring';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport { modelAttribute } from '@prisma-next/psl-parser';\nimport type {\n EntityHandleLoweringInput,\n LoweredPackEntity,\n ResolvedEntityHandleRef,\n ResolvedPslModelRefs,\n} from '@prisma-next/sql-contract/entity-handle-lowering-hook';\nimport type { SqlValueSetDerivingEntityTypeOutput } from '@prisma-next/sql-contract/value-set-derivation-hook';\nimport {\n assertWireNamePrefixLength,\n formatWireName,\n normalizeSqlBody,\n} from '@prisma-next/sql-schema-ir/naming';\nimport { assertDefined } from '@prisma-next/utils/assertions';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { PG_ENUM_CODEC_ID } from './codec-ids';\nimport { postgresError } from './errors';\nimport { PostgresNativeEnum } from './postgres-native-enum';\nimport { PostgresRlsEnablement, type PostgresRlsEnablementInput } from './postgres-rls-enablement';\nimport { PostgresRlsPolicy, type RlsPolicyOperation } from './postgres-rls-policy';\nimport { PostgresRole } from './postgres-role';\nimport {\n PostgresNativeEnumSchema,\n PostgresRlsEnablementSchema,\n PostgresRlsPolicySchema,\n PostgresRoleSchema,\n} from './postgres-validators';\nimport { computeContentHash, POLICY_OPERATION_PREDICATES } from './rls/canonicalize';\n\n/**\n * `pg.enum(<ref>)` registers as an ordinary type constructor whose sole\n * positional argument names a `native_enum` entity instead of carrying a\n * literal value. The interpreter resolves the ref to the `native_enum`\n * entity generically (driven by `entityRefArg`); the `pg/enum@1` codec\n * descriptor's `columnFromEntity` hook (see `codecs.ts`) converts that\n * entity into the column's `typeParams` and native type.\n */\nexport const postgresAuthoringTypes = {\n pg: {\n enum: {\n kind: 'typeConstructor',\n entityRefArg: { index: 0, entityKind: 'native_enum' },\n output: {\n codecId: PG_ENUM_CODEC_ID,\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n\nexport interface RlsPolicyExtensionBlock extends PslExtensionBlock {\n readonly namespaceId: string;\n /**\n * Model refs the family interpreter resolved from the block's descriptor-\n * declared `refKind: 'model'` parameters before invoking this factory\n * (keyed by parameter name). An unresolved required ref is the\n * interpreter's diagnostic; the factory is never called with one missing.\n */\n readonly resolvedModelRefs?: ResolvedPslModelRefs;\n}\n\n/** A parsed `role` block annotated with its lexical namespace id by the interpreter. */\nexport interface RoleExtensionBlock extends PslExtensionBlock {\n readonly namespaceId: string;\n}\n\n/**\n * Maps a `policy_<op>` keyword to the RLS operation it authors. The keyword\n * IS the operation (per the project's rejection of a `policy { operation = … }`\n * conditional block).\n */\nconst POLICY_KEYWORD_OPERATION: Readonly<Record<string, RlsPolicyOperation>> = {\n policy_select: 'select',\n policy_insert: 'insert',\n policy_update: 'update',\n policy_delete: 'delete',\n policy_all: 'all',\n};\n\nfunction readValueParam(block: PslExtensionBlock, key: string): string | undefined {\n const param = block.parameters[key];\n return param?.kind === 'value' ? param.raw : undefined;\n}\n\nfunction readListRefParams(block: PslExtensionBlock, key: string): string[] {\n const param = block.parameters[key];\n if (param?.kind !== 'list') return [];\n return param.items.flatMap((item) => (item.kind === 'ref' ? [item.identifier] : []));\n}\n\n/**\n * Unwraps a quoted PSL string argument, inverting the printer's\n * `escapePslString` escapes (`\\\\`, `\\\"`, `\\n`, `\\r`). An unknown escape\n * sequence is kept verbatim, matching the printer-side `unescapePslString`\n * convention.\n */\nfunction unwrapQuotedString(raw: string): string {\n if (!(raw.startsWith('\"') && raw.endsWith('\"') && raw.length >= 2)) {\n return raw;\n }\n const inner = raw.slice(1, -1);\n let result = '';\n for (let i = 0; i < inner.length; i++) {\n if (inner[i] !== '\\\\' || i + 1 >= inner.length) {\n result += inner[i];\n continue;\n }\n const next = inner[i + 1];\n if (next === '\\\\' || next === '\"') {\n result += next;\n } else if (next === 'n') {\n result += '\\n';\n } else if (next === 'r') {\n result += '\\r';\n } else {\n result += '\\\\';\n result += next;\n }\n i++;\n }\n return result;\n}\n\n/**\n * Assembles a {@link PostgresRlsPolicy} from lowered inputs: normalizes the\n * predicates, computes the content-hash wire name, and constructs the frozen\n * entity. The single hash-assembly body shared by the PSL block lowering\n * ({@link lowerRlsPolicyFromBlock}) and the TS entity-handle lowering\n * ({@link postgresLowerEntityHandles}) so the two surfaces cannot drift.\n */\nfunction buildRlsPolicyEntity(input: {\n readonly prefix: string;\n readonly tableName: string;\n readonly namespaceId: string;\n readonly operation: RlsPolicyOperation;\n readonly roles: readonly string[];\n readonly using?: string;\n readonly withCheck?: string;\n}): PostgresRlsPolicy {\n const wireHash = computeContentHash({\n ...ifDefined('using', input.using !== undefined ? normalizeSqlBody(input.using) : undefined),\n ...ifDefined(\n 'withCheck',\n input.withCheck !== undefined ? normalizeSqlBody(input.withCheck) : undefined,\n ),\n roles: input.roles,\n operation: input.operation,\n permissive: true,\n });\n\n return new PostgresRlsPolicy({\n name: formatWireName(input.prefix, wireHash),\n prefix: input.prefix,\n tableName: input.tableName,\n namespaceId: input.namespaceId,\n operation: input.operation,\n roles: input.roles,\n ...ifDefined('using', input.using),\n ...ifDefined('withCheck', input.withCheck),\n permissive: true,\n });\n}\n\nfunction lowerRlsPolicyFromBlock(\n block: RlsPolicyExtensionBlock,\n ctx: AuthoringEntityContext,\n): PostgresRlsPolicy | undefined {\n const prefix = block.name;\n const operation = POLICY_KEYWORD_OPERATION[block.keyword] ?? 'select';\n // The interpreter resolves the descriptor-declared `target` model ref to\n // its storage table name before invoking this factory (an unresolved or\n // missing required ref is the interpreter's diagnostic), so a lookup miss\n // here is structurally impossible.\n const tableName = block.resolvedModelRefs?.['target']?.tableName;\n assertDefined(\n tableName,\n `lowerRlsPolicyFromBlock: policy \"${block.name}\" reached the factory without a resolved \\`target\\` ref; the interpreter resolves same-namespace model refs before invoking entity factories.`,\n );\n const roles = [...readListRefParams(block, 'roles')].sort();\n\n const usingRaw = readValueParam(block, 'using');\n const withCheckRaw = readValueParam(block, 'withCheck');\n\n // Reject a predicate the operation does not take (e.g. `using` on INSERT, or\n // `withCheck` on SELECT/DELETE). The descriptor's param set already omits it,\n // but the generic descriptor validator is not wired into the SQL-family\n // interpreter, so the lowering enforces the per-operation predicate matrix\n // directly — a wrong predicate is a load-time diagnostic, not a silent drop.\n const support = POLICY_OPERATION_PREDICATES[operation];\n const rejectPredicate = (predicate: 'using' | 'withCheck'): undefined => {\n ctx.diagnostics?.push({\n code: 'PSL_RLS_PREDICATE_NOT_FOR_OPERATION',\n message: `\\`${block.keyword}\\` policy \"${block.name}\" does not take a \\`${predicate}\\` predicate; the ${operation.toUpperCase()} operation uses ${support.using ? '`using`' : '`withCheck`'}${support.using && support.withCheck ? ' and `withCheck`' : ' only'}.`,\n sourceId: ctx.sourceId ?? 'unknown',\n span: block.parameters[predicate]?.span ?? block.span,\n });\n return undefined;\n };\n if (usingRaw !== undefined && !support.using) return rejectPredicate('using');\n if (withCheckRaw !== undefined && !support.withCheck) return rejectPredicate('withCheck');\n\n const using = usingRaw !== undefined ? unwrapQuotedString(usingRaw) : undefined;\n const withCheck = withCheckRaw !== undefined ? unwrapQuotedString(withCheckRaw) : undefined;\n\n return buildRlsPolicyEntity({\n prefix,\n tableName,\n namespaceId: block.namespaceId,\n operation,\n roles,\n ...ifDefined('using', using),\n ...ifDefined('withCheck', withCheck),\n });\n}\n\n/**\n * Lowers a `native_enum { memberName = \"value\" … @@map(\"type_name\") }` block\n * into a {@link PostgresNativeEnum}. Members must be authored as explicit\n * `key = \"value\"` pairs — a bare (value-less) member is a diagnostic, not\n * accepted (authoring-design.md §2.1). The parsed `memberName` is only used\n * to duplicate-check and report diagnostics; the lowered entity carries just\n * the member values (a native enum is value-only — the member \"name\" isn't\n * a separate authoring concept from the value). `typeName` comes from\n * `@@map` or defaults to the block name verbatim.\n */\nfunction lowerNativeEnumFromBlock(\n block: PslExtensionBlock,\n ctx: AuthoringEntityContext,\n): PostgresNativeEnum | undefined {\n const sourceId = ctx.sourceId ?? 'unknown';\n const diagnostics = ctx.diagnostics;\n\n const mapAttr = block.blockAttributes.find((a) => a.name === 'map');\n let typeName = block.name;\n if (mapAttr) {\n const rawArg = mapAttr.args[0]?.value;\n const mapped = rawArg !== undefined ? unwrapQuotedString(rawArg) : undefined;\n if (mapped === undefined) {\n diagnostics?.push({\n code: 'PSL_NATIVE_ENUM_INVALID_MAP',\n message: `native_enum \"${block.name}\" @@map attribute must have a quoted type-name argument`,\n sourceId,\n span: mapAttr.span,\n });\n return undefined;\n }\n typeName = mapped;\n }\n\n let memberError = false;\n const seenValues = new Set<string>();\n const members: string[] = [];\n for (const [memberName, paramValue] of Object.entries(block.parameters)) {\n if (paramValue.kind === 'bare') {\n diagnostics?.push({\n code: 'PSL_NATIVE_ENUM_BARE_MEMBER',\n message: `native_enum \"${block.name}\" member \"${memberName}\" has no value; members must be authored as \"${memberName} = \\\\\"value\\\\\"\"`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n if (paramValue.kind !== 'value') continue;\n\n let jsonValue: unknown;\n try {\n jsonValue = JSON.parse(paramValue.raw);\n } catch {\n diagnostics?.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `native_enum \"${block.name}\" member \"${memberName}\" value \"${paramValue.raw}\" is not valid JSON`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n if (typeof jsonValue !== 'string') {\n diagnostics?.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `native_enum \"${block.name}\" member \"${memberName}\" value must be a string`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n if (seenValues.has(jsonValue)) {\n diagnostics?.push({\n code: 'PSL_NATIVE_ENUM_DUPLICATE_MEMBER_VALUE',\n message: `native_enum \"${block.name}\": duplicate member value \"${jsonValue}\"`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n seenValues.add(jsonValue);\n members.push(jsonValue);\n }\n\n if (memberError) return undefined;\n\n if (members.length === 0) {\n diagnostics?.push({\n code: 'PSL_NATIVE_ENUM_MISSING_MEMBERS',\n message: `native_enum \"${block.name}\" must have at least one member`,\n sourceId,\n span: block.span,\n });\n return undefined;\n }\n\n // `control` stays unset — the effective grade is resolved at read time via `effectiveControlPolicy`, like `StorageTable`/`StorageColumn`.\n return new PostgresNativeEnum({ typeName, members });\n}\n\n/**\n * `native_enum`'s entity-type factory output, checked separately from the assembled\n * `postgresAuthoringEntityTypes` map below: `deriveValueSet` is SQL-family surface\n * ({@link SqlValueSetDerivingEntityTypeOutput}), not part of the framework\n * `AuthoringEntityTypeFactoryOutput` shape, so folding it directly into the map's single\n * `satisfies AuthoringEntityTypeNamespace` check would trip an excess-property error. Checking it\n * here against the intersection of both shapes keeps it structurally valid against each without\n * widening the map's own check.\n */\nconst nativeEnumEntityTypeOutput = {\n factory: lowerNativeEnumFromBlock,\n deriveValueSet: (entity: PostgresNativeEnum) => ({\n kind: 'valueSet' as const,\n values: [...entity.members],\n }),\n} satisfies AuthoringEntityTypeFactoryOutput<PslExtensionBlock, PostgresNativeEnum | undefined> &\n SqlValueSetDerivingEntityTypeOutput;\n\n/**\n * Lowers a `role <name> {}` block into a {@link PostgresRole}. Roles are\n * cluster-scoped in Postgres, so the block must be declared inside\n * `namespace unbound { … }` — any other lexical namespace (a named schema,\n * or the default bucket top-level declarations resolve to) is a load-time\n * diagnostic. The lowered entity carries the unbound coordinate.\n */\nfunction lowerRoleFromBlock(\n block: RoleExtensionBlock,\n ctx: AuthoringEntityContext,\n): PostgresRole | undefined {\n if (block.namespaceId !== UNBOUND_NAMESPACE_ID) {\n ctx.diagnostics?.push({\n code: 'PSL_ROLE_BLOCK_OUTSIDE_UNBOUND_NAMESPACE',\n message: `\\`role\\` block \"${block.name}\" must be declared inside \\`namespace unbound { }\\`, not in namespace \"${block.namespaceId}\"`,\n sourceId: ctx.sourceId ?? 'unknown',\n span: block.span,\n });\n return undefined;\n }\n return new PostgresRole({ name: block.name, namespaceId: UNBOUND_NAMESPACE_ID });\n}\n\nexport const postgresAuthoringEntityTypes = {\n role: {\n kind: 'entity',\n discriminator: 'role',\n validatorSchema: PostgresRoleSchema,\n output: {\n factory: lowerRoleFromBlock,\n },\n },\n rls: {\n kind: 'entity',\n discriminator: 'rls',\n validatorSchema: PostgresRlsEnablementSchema,\n output: {\n factory: (input: PostgresRlsEnablementInput): PostgresRlsEnablement =>\n new PostgresRlsEnablement(input),\n },\n },\n policy: {\n kind: 'entity',\n discriminator: 'policy',\n validatorSchema: PostgresRlsPolicySchema,\n output: {\n factory: lowerRlsPolicyFromBlock,\n },\n },\n native_enum: {\n kind: 'entity',\n discriminator: 'native_enum',\n validatorSchema: PostgresNativeEnumSchema,\n output: nativeEnumEntityTypeOutput,\n },\n} as const satisfies AuthoringEntityTypeNamespace;\n\n/**\n * Field presets contributed by the Postgres target pack.\n *\n * These mirror the PSL scalar-to-codec mapping used by the Postgres adapter\n * (see `createPostgresPslScalarTypeDescriptors`), so that authoring a field\n * via the TS callback surface (e.g. `field.int()`) and via the PSL scalar\n * surface (e.g. `Int`) lowers to byte-identical contracts.\n *\n * The `uuidNative` / `id.uuidv4Native` / `id.uuidv7Native` presets use the\n * native Postgres `uuid` type (codecId `pg/uuid@1`). For cross-target\n * portability use `uuidString` / `id.uuidv4String` / `id.uuidv7String` from\n * the family pack instead.\n */\n/**\n * Shared parameter descriptors for the five `policy_<op>` PSL block\n * keywords. All five share the `policy` discriminator — the parser\n * dispatches by keyword (see the framework's PSL-block SPI), and every\n * keyword's factory lowers to `PostgresRlsPolicy` via `lowerRlsPolicyFromBlock`.\n *\n * The `roles` list uses `scope:'cross-space'` because same-namespace\n * role ref resolution requires PSL namespace entries keyed by `refKind`\n * (i.e. `'role'`), which in turn requires the role block discriminator to\n * equal `'role'`. Aligning discriminator with refKind is tracked for\n * slice 4 (cross-space roles). Until then cross-space passes validation\n * unconditionally and the authored role names flow through unchanged.\n */\nconst policyTargetParam = {\n kind: 'ref',\n refKind: 'model',\n scope: 'same-namespace',\n required: true,\n} as const;\nconst policyRolesParam = {\n kind: 'list',\n of: { kind: 'ref', refKind: 'role', scope: 'cross-space' },\n} as const;\nconst policyPredicateParam = { kind: 'value', codecId: 'pg/text@1', required: true } as const;\n// A policy may only target an RLS-controlled model: the model named by\n// `target` must declare `@@rls`, or the load fails with a diagnostic naming\n// the model and the policy prefix.\nconst policyRequiresRls = { parameter: 'target', attribute: 'rls' } as const;\n\nexport const postgresAuthoringPslBlockDescriptors = {\n // The predicate param set per keyword mirrors Postgres: SELECT/DELETE take\n // USING only; INSERT takes WITH CHECK only; UPDATE/ALL take both. The\n // per-operation predicate matrix is enforced in `lowerRlsPolicyFromBlock`\n // (a wrong predicate for the operation is a load-time diagnostic there),\n // since the generic descriptor validator is not wired into the SQL-family\n // interpreter.\n policy_select: {\n kind: 'pslBlock',\n keyword: 'policy_select',\n discriminator: 'policy',\n name: { required: true },\n parameters: { target: policyTargetParam, roles: policyRolesParam, using: policyPredicateParam },\n requiresModelAttribute: policyRequiresRls,\n },\n policy_delete: {\n kind: 'pslBlock',\n keyword: 'policy_delete',\n discriminator: 'policy',\n name: { required: true },\n parameters: { target: policyTargetParam, roles: policyRolesParam, using: policyPredicateParam },\n requiresModelAttribute: policyRequiresRls,\n },\n policy_insert: {\n kind: 'pslBlock',\n keyword: 'policy_insert',\n discriminator: 'policy',\n name: { required: true },\n parameters: {\n target: policyTargetParam,\n roles: policyRolesParam,\n withCheck: policyPredicateParam,\n },\n requiresModelAttribute: policyRequiresRls,\n },\n policy_update: {\n kind: 'pslBlock',\n keyword: 'policy_update',\n discriminator: 'policy',\n name: { required: true },\n parameters: {\n target: policyTargetParam,\n roles: policyRolesParam,\n using: policyPredicateParam,\n withCheck: policyPredicateParam,\n },\n requiresModelAttribute: policyRequiresRls,\n },\n policy_all: {\n kind: 'pslBlock',\n keyword: 'policy_all',\n discriminator: 'policy',\n name: { required: true },\n parameters: {\n target: policyTargetParam,\n roles: policyRolesParam,\n using: policyPredicateParam,\n withCheck: policyPredicateParam,\n },\n requiresModelAttribute: policyRequiresRls,\n },\n /**\n * PSL block descriptor for `native_enum`.\n *\n * Reuses the existing variadic-block mechanism (the same shape the SQL\n * family's `enum` block ships): the body is an open `memberName = \"value\"`\n * list. `variadicParameters: true` opens the block to arbitrary keys\n * beyond the declared (empty) `parameters` set — the lowering factory\n * (`lowerNativeEnumFromBlock`) turns the variadic entries into ordered\n * members and rejects a bare (value-less) member.\n */\n native_enum: {\n kind: 'pslBlock',\n keyword: 'native_enum',\n discriminator: 'native_enum',\n name: { required: true },\n parameters: {},\n variadicParameters: true,\n },\n /**\n * PSL block descriptor for `role` (e.g. `role anon {}`). Name-only, no\n * parameters and no body content. Declared inside `namespace unbound { }`\n * — see {@link lowerRoleFromBlock} for the placement check and the\n * coordinate the lowered entity carries.\n */\n role: {\n kind: 'pslBlock',\n keyword: 'role',\n discriminator: 'role',\n name: { required: true },\n parameters: {},\n },\n} as const satisfies AuthoringPslBlockDescriptorNamespace;\n\n/**\n * `@@` model attributes contributed by the Postgres target pack.\n *\n * `@@rls` is argument-less: presence marks the model's table\n * RLS-controlled. It lowers to a {@link PostgresRlsEnablement} marker in\n * the namespace's `entries.rls`, keyed by the model's table name — the\n * marker (never the policy set) is what drives\n * `ENABLE`/`DISABLE ROW LEVEL SECURITY` planning.\n */\nexport const postgresAuthoringModelAttributes = {\n rls: {\n kind: 'modelAttribute',\n attribute: 'rls',\n spec: modelAttribute('rls', {}),\n lower: (_parsed: Record<never, never>, ctx: AuthoringModelAttributeContext) => ({\n key: ctx.storageName,\n entity: new PostgresRlsEnablement({\n tableName: ctx.storageName,\n namespaceId: ctx.namespaceId,\n }),\n }),\n },\n} as const satisfies AuthoringModelAttributeDescriptorNamespace;\n\nexport const postgresAuthoringFieldPresets = {\n text: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/text@1',\n nativeType: 'text',\n },\n },\n int: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/int4@1',\n nativeType: 'int4',\n },\n },\n bigint: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/int8@1',\n nativeType: 'int8',\n },\n },\n float: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/float8@1',\n nativeType: 'float8',\n },\n },\n decimal: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/numeric@1',\n nativeType: 'numeric',\n },\n },\n boolean: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/bool@1',\n nativeType: 'bool',\n },\n },\n json: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/jsonb@1',\n nativeType: 'jsonb',\n },\n },\n bytes: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/bytea@1',\n nativeType: 'bytea',\n },\n },\n dateTime: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n },\n },\n temporal: {\n .../* @__PURE__ */ temporalAuthoringPresets({\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n }),\n timestamp: /* @__PURE__ */ temporalCodecPresetWithPrecision({\n codecId: 'pg/timestamp@1',\n nativeType: 'timestamp',\n }),\n timestamptz: /* @__PURE__ */ temporalCodecPresetWithPrecision({\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n }),\n },\n uuidNative: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/uuid@1',\n nativeType: 'uuid',\n },\n },\n id: {\n uuidv4Native: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/uuid@1',\n nativeType: 'uuid',\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv4',\n },\n },\n id: true,\n },\n },\n uuidv7Native: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/uuid@1',\n nativeType: 'uuid',\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv7',\n },\n },\n id: true,\n },\n },\n },\n} as const satisfies AuthoringFieldNamespace;\n\ninterface RlsRoleHandleShape {\n readonly entityKind: 'role';\n readonly name: string;\n}\n\ninterface RlsPolicyHandleShape {\n readonly entityKind: 'policy';\n readonly operation: RlsPolicyOperation;\n readonly name: string;\n readonly roles: readonly { readonly name: string }[];\n readonly using?: string;\n readonly withCheck?: string;\n}\n\ninterface RlsTargetCoordinate {\n readonly namespaceId: string;\n readonly tableName: string;\n}\n\n/**\n * Resolves an entity handle's `target` ref to a table coordinate of this\n * contract, or throws the load-time diagnostic naming the handle: a\n * cross-space target is rejected (you cannot CREATE POLICY on a table\n * another space owns) and an unresolved target names the model.\n */\nfunction requireLocalTarget(\n refs: Readonly<Record<string, ResolvedEntityHandleRef>>,\n subject: string,\n): RlsTargetCoordinate {\n const target = refs['target'];\n if (target !== undefined && target.kind === 'resolved') {\n return { namespaceId: target.namespaceId, tableName: target.tableName };\n }\n if (target !== undefined && target.kind === 'cross-space') {\n throw postgresError(\n 'CONTRACT.POLICY_INVALID',\n `defineContract: ${subject} targets model \"${target.modelName ?? target.tableName}\", which lives in another contract space. Policies and rlsEnabled entries must target a model declared in this contract.`,\n { meta: { model: target.modelName ?? target.tableName, reason: 'cross-space-target' } },\n );\n }\n throw postgresError(\n 'CONTRACT.MODEL_UNKNOWN',\n `defineContract: ${subject} targets model \"${target?.modelName ?? '<anonymous>'}\", which is not in the contract's models. Add the model to \\`models\\`.`,\n { meta: { model: target?.modelName ?? '<anonymous>' } },\n );\n}\n\n/**\n * The SQL-family entity-handle batch lowering hook for the Postgres pack\n * (`SqlEntityHandleLoweringContribution`). Receives every `entities` handle\n * whose kind this pack registered — batch, so the cross-entity diagnostics\n * (duplicate prefix, policy without rlsEnabled, duplicate role) can see\n * sibling handles — and lowers them with the same keying and hash assembly\n * as the PSL path: `policy` keyed by prefix (wire name via\n * {@link buildRlsPolicyEntity}), `rls` keyed by table name, `role` keyed by\n * name and filed under the default namespace (roles are declared\n * contract-wide; PSL has no role block to set a precedent).\n */\nexport function postgresLowerEntityHandles(\n input: EntityHandleLoweringInput,\n): readonly LoweredPackEntity[] {\n const enablements = new Map<\n string,\n { coordinate: RlsTargetCoordinate; entity: PostgresRlsEnablement }\n >();\n const roles = new Map<string, PostgresRole>();\n const policies: {\n readonly handle: RlsPolicyHandleShape;\n readonly refs: Readonly<Record<string, ResolvedEntityHandleRef>>;\n }[] = [];\n const coordinateKey = (coordinate: RlsTargetCoordinate): string =>\n `${coordinate.namespaceId} ${coordinate.tableName}`;\n\n for (const { handle, refs } of input.handles) {\n switch (handle.entityKind) {\n case 'rls': {\n const coordinate = requireLocalTarget(refs, 'an rlsEnabled entry');\n const key = coordinateKey(coordinate);\n if (!enablements.has(key)) {\n enablements.set(key, {\n coordinate,\n entity: new PostgresRlsEnablement({\n tableName: coordinate.tableName,\n namespaceId: coordinate.namespaceId,\n }),\n });\n }\n break;\n }\n case 'role': {\n const roleHandle = blindCast<\n RlsRoleHandleShape,\n 'role handles are constructed only by the postgres contract-builder role() constructor, which enforces this shape'\n >(handle);\n if (roles.has(roleHandle.name)) {\n throw postgresError(\n 'CONTRACT.ROLE_INVALID',\n `defineContract: role \"${roleHandle.name}\" is declared more than once in the entities list.`,\n { meta: { role: roleHandle.name, reason: 'duplicate' } },\n );\n }\n // Roles are cluster-scoped in Postgres, so they always land in the\n // `__unbound__` namespace — identical to a PSL `role` block\n // (`lowerRoleFromBlock`) and matching the `PostgresRole` class's own\n // contract. The declaring surface (TS entities vs PSL) does not move\n // the slot.\n roles.set(\n roleHandle.name,\n new PostgresRole({ name: roleHandle.name, namespaceId: UNBOUND_NAMESPACE_ID }),\n );\n break;\n }\n case 'policy': {\n const policyHandle = blindCast<\n RlsPolicyHandleShape,\n 'policy handles are constructed only by the postgres contract-builder policy*() constructors, which enforce this shape'\n >(handle);\n policies.push({ handle: policyHandle, refs });\n break;\n }\n default:\n throw postgresError(\n 'CONTRACT.ENTITY_KIND_INVALID',\n `defineContract: the postgres pack does not lower \"${handle.entityKind}\" handles from the entities list.`,\n { meta: { entityKind: handle.entityKind } },\n );\n }\n }\n\n const rows: LoweredPackEntity[] = [];\n const seenPrefixes = new Set<string>();\n\n for (const { handle: policy, refs } of policies) {\n const prefix = policy.name;\n assertWireNamePrefixLength(prefix, 'defineContract: policy prefix');\n const coordinate = requireLocalTarget(refs, `policy \"${prefix}\"`);\n if (!enablements.has(coordinateKey(coordinate))) {\n const target = refs['target'];\n throw postgresError(\n 'CONTRACT.POLICY_INVALID',\n `defineContract: policy \"${prefix}\" targets model \"${target?.modelName ?? coordinate.tableName}\", whose table is not RLS-enabled. Add rlsEnabled(<model>) to the entities list.`,\n {\n meta: {\n prefix,\n model: target?.modelName ?? coordinate.tableName,\n reason: 'target-not-rls-enabled',\n },\n },\n );\n }\n const prefixKey = `${coordinate.namespaceId} ${prefix}`;\n if (seenPrefixes.has(prefixKey)) {\n throw postgresError(\n 'CONTRACT.POLICY_INVALID',\n `defineContract: policy prefix \"${prefix}\" is declared more than once in namespace \"${coordinate.namespaceId}\". Policy prefixes must be unique per namespace.`,\n { meta: { prefix, namespaceId: coordinate.namespaceId, reason: 'duplicate-prefix' } },\n );\n }\n seenPrefixes.add(prefixKey);\n\n const roleNames = [...new Set(policy.roles.map((roleHandle) => roleHandle.name))].sort();\n rows.push({\n namespaceId: coordinate.namespaceId,\n entityKind: 'policy',\n key: prefix,\n entity: buildRlsPolicyEntity({\n prefix,\n tableName: coordinate.tableName,\n namespaceId: coordinate.namespaceId,\n operation: policy.operation,\n roles: roleNames,\n ...ifDefined('using', policy.using),\n ...ifDefined('withCheck', policy.withCheck),\n }),\n });\n }\n\n for (const { coordinate, entity } of enablements.values()) {\n rows.push({\n namespaceId: coordinate.namespaceId,\n entityKind: 'rls',\n key: coordinate.tableName,\n entity,\n });\n }\n for (const [name, entity] of roles) {\n rows.push({ namespaceId: UNBOUND_NAMESPACE_ID, entityKind: 'role', key: name, entity });\n }\n return rows;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsDA,MAAa,yBAAyB,EACpC,IAAI,EACF,MAAM;CACJ,MAAM;CACN,cAAc;EAAE,OAAO;EAAG,YAAY;CAAc;CACpD,QAAQ,EACN,SAAS,iBACX;AACF,EAC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QAAQ;EAAmB,EAAE,CACtF;EAEF,aAAa,IAAI,SAAS;EAE1B,MAAM,YAAY,CAAC,GAAG,IAAI,IAAI,OAAO,MAAM,KAAK,eAAe,WAAW,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK;EACvF,KAAK,KAAK;GACR,aAAa,WAAW;GACxB,YAAY;GACZ,KAAK;GACL,QAAQ,qBAAqB;IAC3B;IACA,WAAW,WAAW;IACtB,aAAa,WAAW;IACxB,WAAW,OAAO;IAClB,OAAO;IACP,GAAG,UAAU,SAAS,OAAO,KAAK;IAClC,GAAG,UAAU,aAAa,OAAO,SAAS;GAC5C,CAAC;EACH,CAAC;CACH;CAEA,KAAK,MAAM,EAAE,YAAY,YAAY,YAAY,OAAO,GACtD,KAAK,KAAK;EACR,aAAa,WAAW;EACxB,YAAY;EACZ,KAAK,WAAW;EAChB;CACF,CAAC;CAEH,KAAK,MAAM,CAAC,MAAM,WAAW,OAC3B,KAAK,KAAK;EAAE,aAAa;EAAsB,YAAY;EAAQ,KAAK;EAAM;CAAO,CAAC;CAExF,OAAO;AACT"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ProjectionExpr } from "@prisma-next/sql-relational-core/ast";
|
|
2
|
+
import { AnyCodecDescriptor, CodecDescriptor, CodecDescriptorImpl, CodecRef } from "@prisma-next/framework-components/codec";
|
|
3
|
+
//#region src/core/codec-descriptor.d.ts
|
|
4
|
+
declare const POSTGRES_CODEC_DESCRIPTOR_KIND: "postgres-codec";
|
|
5
|
+
interface AnyPostgresCodecDescriptor extends AnyCodecDescriptor {
|
|
6
|
+
readonly descriptorKind: typeof POSTGRES_CODEC_DESCRIPTOR_KIND;
|
|
7
|
+
nativeTypeFor(ref: CodecRef): string;
|
|
8
|
+
projectJson(expression: ProjectionExpr, ref: CodecRef): ProjectionExpr;
|
|
9
|
+
}
|
|
10
|
+
declare abstract class PostgresCodecDescriptor<P = void> extends CodecDescriptorImpl<P> implements AnyPostgresCodecDescriptor {
|
|
11
|
+
readonly descriptorKind: "postgres-codec";
|
|
12
|
+
protected abstract nativeType(params: P): string;
|
|
13
|
+
protected abstract jsonProjection(expression: ProjectionExpr, params: P): ProjectionExpr;
|
|
14
|
+
protected jsonArrayProjection(expression: ProjectionExpr, params: P): ProjectionExpr;
|
|
15
|
+
nativeTypeFor(ref: CodecRef): string;
|
|
16
|
+
projectJson(expression: ProjectionExpr, ref: CodecRef): ProjectionExpr;
|
|
17
|
+
private validateParams;
|
|
18
|
+
}
|
|
19
|
+
type DescriptorParams<D extends AnyCodecDescriptor> = D extends CodecDescriptor<infer P> ? P : never;
|
|
20
|
+
interface PostgresCodecOptions<P> {
|
|
21
|
+
readonly nativeType: (params: P) => string;
|
|
22
|
+
readonly jsonProjection: (expression: ProjectionExpr, params: P) => ProjectionExpr;
|
|
23
|
+
readonly jsonArrayProjection?: (expression: ProjectionExpr, params: P) => ProjectionExpr;
|
|
24
|
+
}
|
|
25
|
+
type AdaptedPostgresCodecDescriptor<D extends AnyCodecDescriptor> = Pick<D, keyof CodecDescriptor<DescriptorParams<D>>> & Pick<AnyPostgresCodecDescriptor, 'descriptorKind' | 'nativeTypeFor' | 'projectJson'>;
|
|
26
|
+
declare function postgresCodec<D extends AnyCodecDescriptor>(descriptor: D, options: PostgresCodecOptions<DescriptorParams<D>>): AdaptedPostgresCodecDescriptor<D>;
|
|
27
|
+
declare function definePostgresCodecs<const Descriptors extends readonly AnyPostgresCodecDescriptor[]>(descriptors: Descriptors): Descriptors;
|
|
28
|
+
declare function isPostgresCodecDescriptor(value: unknown): value is AnyPostgresCodecDescriptor;
|
|
29
|
+
interface PostgresCodecDescriptorRegistry {
|
|
30
|
+
descriptorFor(codecId: string): AnyPostgresCodecDescriptor | undefined;
|
|
31
|
+
values(): IterableIterator<AnyPostgresCodecDescriptor>;
|
|
32
|
+
}
|
|
33
|
+
declare function buildPostgresCodecDescriptorRegistry(descriptors: ReadonlyArray<unknown>): PostgresCodecDescriptorRegistry;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { PostgresCodecOptions as a, isPostgresCodecDescriptor as c, PostgresCodecDescriptorRegistry as i, postgresCodec as l, AnyPostgresCodecDescriptor as n, buildPostgresCodecDescriptorRegistry as o, PostgresCodecDescriptor as r, definePostgresCodecs as s, AdaptedPostgresCodecDescriptor as t };
|
|
36
|
+
//# sourceMappingURL=codec-descriptor-C4SaWX0P.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec-descriptor-C4SaWX0P.d.mts","names":[],"sources":["../src/core/codec-descriptor.ts"],"mappings":";;;cA8BM;UAMW,mCAAmC;WACzC,uBAAuB;EAChC,cAAc,KAAK;EACnB,YAAY,YAAY,gBAAgB,KAAK,WAAW;;uBAGpC,wBAAwB,kBACpC,oBAAoB,cACjB;WAEF;qBAEU,WAAW,QAAQ;qBACnB,eAAe,YAAY,gBAAgB,QAAQ,IAAI;YAEhE,oBAAoB,YAAY,gBAAgB,QAAQ,IAAI;EAkCtE,cAAc,KAAK;EAInB,YAAY,YAAY,gBAAgB,KAAK,WAAW;UAOhD;;KAQL,iBAAiB,UAAU,sBAC9B,UAAU,sBAAsB,KAAK;UAEtB,qBAAqB;WAC3B,aAAa,QAAQ;WACrB,iBAAiB,YAAY,gBAAgB,QAAQ,MAAM;WAC3D,uBAAuB,YAAY,gBAAgB,QAAQ,MAAM;;KAGhE,+BAA+B,UAAU,sBAAsB,KACzE,SACM,gBAAgB,iBAAiB,OAEvC,KAAK;iBAoFS,cAAc,UAAU,oBACtC,YAAY,GACZ,SAAS,qBAAqB,iBAAiB,MAC9C,+BAA+B;iBAOlB,2BACR,6BAA6B,8BACnC,aAAa,cAAc;iBAIb,0BAA0B,iBAAiB,SAAS;UAkCnD;EACf,cAAc,kBAAkB;EAChC,UAAU,iBAAiB;;iBAoBb,qCACd,aAAa,yBACZ"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { CaseExpr, ColumnRef, DerivedTableSource, FunctionSource, JsonArrayAggExpr, LiteralExpr, NativeJsonValueProjection, NullCheckExpr, OrderByItem, ProjectionItem, SelectAst, SubqueryExpr } from "@prisma-next/sql-relational-core/ast";
|
|
2
|
+
import { CodecDescriptorImpl, validateCodecTypeParams } from "@prisma-next/framework-components/codec";
|
|
3
|
+
import { blindCast } from "@prisma-next/utils/casts";
|
|
4
|
+
import { structuredError } from "@prisma-next/utils/structured-error";
|
|
5
|
+
//#region src/core/codec-descriptor.ts
|
|
6
|
+
const POSTGRES_CODEC_DESCRIPTOR_KIND = "postgres-codec";
|
|
7
|
+
const ARRAY_INPUT_ALIAS = "array_input";
|
|
8
|
+
const ARRAY_ELEMENT_ALIAS = "array_element";
|
|
9
|
+
const ARRAY_VALUE_COLUMN = "value";
|
|
10
|
+
const ARRAY_ORDINALITY_COLUMN = "ordinality";
|
|
11
|
+
var PostgresCodecDescriptor = class extends CodecDescriptorImpl {
|
|
12
|
+
descriptorKind = POSTGRES_CODEC_DESCRIPTOR_KIND;
|
|
13
|
+
jsonArrayProjection(expression, params) {
|
|
14
|
+
const boundArray = ColumnRef.of(ARRAY_INPUT_ALIAS, ARRAY_VALUE_COLUMN);
|
|
15
|
+
const element = ColumnRef.of(ARRAY_ELEMENT_ALIAS, ARRAY_VALUE_COLUMN);
|
|
16
|
+
const ordinality = ColumnRef.of(ARRAY_ELEMENT_ALIAS, ARRAY_ORDINALITY_COLUMN);
|
|
17
|
+
const projectedElement = CaseExpr.of([{
|
|
18
|
+
condition: NullCheckExpr.isNull(element),
|
|
19
|
+
value: LiteralExpr.of(null)
|
|
20
|
+
}], this.jsonProjection(element, params));
|
|
21
|
+
const aggregate = JsonArrayAggExpr.of(new NativeJsonValueProjection(projectedElement), "emptyArray", [OrderByItem.asc(ordinality)]);
|
|
22
|
+
const aggregateQuery = SelectAst.from(FunctionSource.of("unnest", [boundArray], {
|
|
23
|
+
alias: ARRAY_ELEMENT_ALIAS,
|
|
24
|
+
columnAliases: [ARRAY_VALUE_COLUMN, ARRAY_ORDINALITY_COLUMN]
|
|
25
|
+
}).withOrdinality()).withProjection([ProjectionItem.of(ARRAY_VALUE_COLUMN, aggregate)]);
|
|
26
|
+
const arrayResult = CaseExpr.of([{
|
|
27
|
+
condition: NullCheckExpr.isNull(boundArray),
|
|
28
|
+
value: LiteralExpr.of(null)
|
|
29
|
+
}], SubqueryExpr.of(aggregateQuery));
|
|
30
|
+
const inputBinding = SelectAst.noFrom().withProjection([ProjectionItem.of(ARRAY_VALUE_COLUMN, expression)]);
|
|
31
|
+
return SubqueryExpr.of(SelectAst.from(DerivedTableSource.as(ARRAY_INPUT_ALIAS, inputBinding)).withProjection([ProjectionItem.of(ARRAY_VALUE_COLUMN, arrayResult)]));
|
|
32
|
+
}
|
|
33
|
+
nativeTypeFor(ref) {
|
|
34
|
+
return this.nativeType(this.validateParams(ref));
|
|
35
|
+
}
|
|
36
|
+
projectJson(expression, ref) {
|
|
37
|
+
const params = this.validateParams(ref);
|
|
38
|
+
return ref.many === true ? this.jsonArrayProjection(expression, params) : this.jsonProjection(expression, params);
|
|
39
|
+
}
|
|
40
|
+
validateParams(ref) {
|
|
41
|
+
return blindCast(validateCodecTypeParams(this, ref));
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var PostgresCodecDescriptorAdapter = class extends PostgresCodecDescriptor {
|
|
45
|
+
descriptor;
|
|
46
|
+
options;
|
|
47
|
+
codecId;
|
|
48
|
+
traits;
|
|
49
|
+
targetTypes;
|
|
50
|
+
paramsSchema;
|
|
51
|
+
metaFor;
|
|
52
|
+
renderOutputType;
|
|
53
|
+
renderInputType;
|
|
54
|
+
renderValueLiteral;
|
|
55
|
+
factory;
|
|
56
|
+
constructor(descriptor, options) {
|
|
57
|
+
super();
|
|
58
|
+
this.descriptor = descriptor;
|
|
59
|
+
this.options = options;
|
|
60
|
+
this.codecId = descriptor.codecId;
|
|
61
|
+
this.traits = descriptor.traits;
|
|
62
|
+
this.targetTypes = descriptor.targetTypes;
|
|
63
|
+
this.paramsSchema = descriptor.paramsSchema;
|
|
64
|
+
this.factory = (params) => descriptor.factory(params);
|
|
65
|
+
if (descriptor.meta !== void 0) Object.defineProperty(this, "meta", {
|
|
66
|
+
value: descriptor.meta,
|
|
67
|
+
enumerable: true
|
|
68
|
+
});
|
|
69
|
+
const metaFor = descriptor.metaFor;
|
|
70
|
+
if (metaFor !== void 0) this.metaFor = (params) => metaFor.call(descriptor, params);
|
|
71
|
+
const renderOutputType = descriptor.renderOutputType;
|
|
72
|
+
if (renderOutputType !== void 0) this.renderOutputType = (params) => renderOutputType.call(descriptor, params);
|
|
73
|
+
const renderInputType = descriptor.renderInputType;
|
|
74
|
+
if (renderInputType !== void 0) this.renderInputType = (params) => renderInputType.call(descriptor, params);
|
|
75
|
+
const renderValueLiteral = descriptor.renderValueLiteral;
|
|
76
|
+
if (renderValueLiteral !== void 0) this.renderValueLiteral = (value, side) => renderValueLiteral.call(descriptor, value, side);
|
|
77
|
+
}
|
|
78
|
+
get isParameterized() {
|
|
79
|
+
return this.descriptor.isParameterized;
|
|
80
|
+
}
|
|
81
|
+
nativeType(params) {
|
|
82
|
+
return this.options.nativeType(params);
|
|
83
|
+
}
|
|
84
|
+
jsonProjection(expression, params) {
|
|
85
|
+
return this.options.jsonProjection(expression, params);
|
|
86
|
+
}
|
|
87
|
+
jsonArrayProjection(expression, params) {
|
|
88
|
+
return this.options.jsonArrayProjection === void 0 ? super.jsonArrayProjection(expression, params) : this.options.jsonArrayProjection(expression, params);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
function postgresCodec(descriptor, options) {
|
|
92
|
+
return blindCast(new PostgresCodecDescriptorAdapter(descriptor, options));
|
|
93
|
+
}
|
|
94
|
+
function definePostgresCodecs(descriptors) {
|
|
95
|
+
return descriptors;
|
|
96
|
+
}
|
|
97
|
+
function isPostgresCodecDescriptor(value) {
|
|
98
|
+
return typeof value === "object" && value !== null && "descriptorKind" in value && value.descriptorKind === POSTGRES_CODEC_DESCRIPTOR_KIND && "codecId" in value && typeof value.codecId === "string" && "traits" in value && Array.isArray(value.traits) && "targetTypes" in value && Array.isArray(value.targetTypes) && value.targetTypes.every((targetType) => typeof targetType === "string") && "paramsSchema" in value && isObjectLike(value.paramsSchema) && "~standard" in value.paramsSchema && isObjectLike(value.paramsSchema["~standard"]) && "validate" in value.paramsSchema["~standard"] && typeof value.paramsSchema["~standard"].validate === "function" && "isParameterized" in value && typeof value.isParameterized === "boolean" && "factory" in value && typeof value.factory === "function" && "nativeTypeFor" in value && typeof value.nativeTypeFor === "function" && "projectJson" in value && typeof value.projectJson === "function";
|
|
99
|
+
}
|
|
100
|
+
function isObjectLike(value) {
|
|
101
|
+
return typeof value === "object" && value !== null || typeof value === "function";
|
|
102
|
+
}
|
|
103
|
+
var PostgresCodecDescriptorRegistryImpl = class {
|
|
104
|
+
#descriptors;
|
|
105
|
+
constructor(descriptors) {
|
|
106
|
+
this.#descriptors = descriptors;
|
|
107
|
+
Object.freeze(this);
|
|
108
|
+
}
|
|
109
|
+
descriptorFor(codecId) {
|
|
110
|
+
return this.#descriptors.get(codecId);
|
|
111
|
+
}
|
|
112
|
+
*values() {
|
|
113
|
+
yield* this.#descriptors.values();
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
function buildPostgresCodecDescriptorRegistry(descriptors) {
|
|
117
|
+
const byId = /* @__PURE__ */ new Map();
|
|
118
|
+
for (const descriptor of descriptors) {
|
|
119
|
+
if (!isPostgresCodecDescriptor(descriptor)) {
|
|
120
|
+
const codecId = candidateCodecId(descriptor);
|
|
121
|
+
throw structuredError("POSTGRES.CODEC_DESCRIPTOR_INVALID", `Codec descriptor '${codecId}' is not a valid PostgreSQL codec descriptor.`, {
|
|
122
|
+
why: "PostgreSQL codec registries require the postgres-codec discriminant and complete target descriptor methods.",
|
|
123
|
+
fix: "Extend PostgresCodecDescriptor or adapt a generic descriptor with postgresCodec().",
|
|
124
|
+
meta: { codecId }
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (byId.has(descriptor.codecId)) throw structuredError("POSTGRES.CODEC_DESCRIPTOR_DUPLICATE", `Duplicate PostgreSQL codec descriptor id '${descriptor.codecId}'.`, {
|
|
128
|
+
why: "Each codecId must resolve to exactly one PostgreSQL descriptor during registry composition.",
|
|
129
|
+
fix: "Remove the duplicate target, adapter, or extension contribution.",
|
|
130
|
+
meta: { codecId: descriptor.codecId }
|
|
131
|
+
});
|
|
132
|
+
byId.set(descriptor.codecId, descriptor);
|
|
133
|
+
}
|
|
134
|
+
return new PostgresCodecDescriptorRegistryImpl(byId);
|
|
135
|
+
}
|
|
136
|
+
function candidateCodecId(value) {
|
|
137
|
+
return typeof value === "object" && value !== null && "codecId" in value && typeof value.codecId === "string" ? value.codecId : "<unknown>";
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
export { postgresCodec as a, isPostgresCodecDescriptor as i, buildPostgresCodecDescriptorRegistry as n, definePostgresCodecs as r, PostgresCodecDescriptor as t };
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=codec-descriptor-cuAuPE0Y.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec-descriptor-cuAuPE0Y.mjs","names":["#descriptors"],"sources":["../src/core/codec-descriptor.ts"],"sourcesContent":["import type { JsonValue } from '@prisma-next/contract/types';\nimport {\n type AnyCodecDescriptor,\n type Codec,\n type CodecDescriptor,\n CodecDescriptorImpl,\n type CodecInstanceContext,\n type CodecMeta,\n type CodecRef,\n type CodecTrait,\n validateCodecTypeParams,\n} from '@prisma-next/framework-components/codec';\nimport {\n CaseExpr,\n ColumnRef,\n DerivedTableSource,\n FunctionSource,\n JsonArrayAggExpr,\n LiteralExpr,\n NativeJsonValueProjection,\n NullCheckExpr,\n OrderByItem,\n type ProjectionExpr,\n ProjectionItem,\n SelectAst,\n SubqueryExpr,\n} from '@prisma-next/sql-relational-core/ast';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { structuredError } from '@prisma-next/utils/structured-error';\n\nconst POSTGRES_CODEC_DESCRIPTOR_KIND = 'postgres-codec' as const;\nconst ARRAY_INPUT_ALIAS = 'array_input';\nconst ARRAY_ELEMENT_ALIAS = 'array_element';\nconst ARRAY_VALUE_COLUMN = 'value';\nconst ARRAY_ORDINALITY_COLUMN = 'ordinality';\n\nexport interface AnyPostgresCodecDescriptor extends AnyCodecDescriptor {\n readonly descriptorKind: typeof POSTGRES_CODEC_DESCRIPTOR_KIND;\n nativeTypeFor(ref: CodecRef): string;\n projectJson(expression: ProjectionExpr, ref: CodecRef): ProjectionExpr;\n}\n\nexport abstract class PostgresCodecDescriptor<P = void>\n extends CodecDescriptorImpl<P>\n implements AnyPostgresCodecDescriptor\n{\n readonly descriptorKind = POSTGRES_CODEC_DESCRIPTOR_KIND;\n\n protected abstract nativeType(params: P): string;\n protected abstract jsonProjection(expression: ProjectionExpr, params: P): ProjectionExpr;\n\n protected jsonArrayProjection(expression: ProjectionExpr, params: P): ProjectionExpr {\n const boundArray = ColumnRef.of(ARRAY_INPUT_ALIAS, ARRAY_VALUE_COLUMN);\n const element = ColumnRef.of(ARRAY_ELEMENT_ALIAS, ARRAY_VALUE_COLUMN);\n const ordinality = ColumnRef.of(ARRAY_ELEMENT_ALIAS, ARRAY_ORDINALITY_COLUMN);\n const projectedElement = CaseExpr.of(\n [{ condition: NullCheckExpr.isNull(element), value: LiteralExpr.of(null) }],\n this.jsonProjection(element, params),\n );\n const aggregate = JsonArrayAggExpr.of(\n new NativeJsonValueProjection(projectedElement),\n 'emptyArray',\n [OrderByItem.asc(ordinality)],\n );\n const aggregateQuery = SelectAst.from(\n FunctionSource.of('unnest', [boundArray], {\n alias: ARRAY_ELEMENT_ALIAS,\n columnAliases: [ARRAY_VALUE_COLUMN, ARRAY_ORDINALITY_COLUMN],\n }).withOrdinality(),\n ).withProjection([ProjectionItem.of(ARRAY_VALUE_COLUMN, aggregate)]);\n const arrayResult = CaseExpr.of(\n [{ condition: NullCheckExpr.isNull(boundArray), value: LiteralExpr.of(null) }],\n SubqueryExpr.of(aggregateQuery),\n );\n const inputBinding = SelectAst.noFrom().withProjection([\n ProjectionItem.of(ARRAY_VALUE_COLUMN, expression),\n ]);\n\n return SubqueryExpr.of(\n SelectAst.from(DerivedTableSource.as(ARRAY_INPUT_ALIAS, inputBinding)).withProjection([\n ProjectionItem.of(ARRAY_VALUE_COLUMN, arrayResult),\n ]),\n );\n }\n\n nativeTypeFor(ref: CodecRef): string {\n return this.nativeType(this.validateParams(ref));\n }\n\n projectJson(expression: ProjectionExpr, ref: CodecRef): ProjectionExpr {\n const params = this.validateParams(ref);\n return ref.many === true\n ? this.jsonArrayProjection(expression, params)\n : this.jsonProjection(expression, params);\n }\n\n private validateParams(ref: CodecRef): P {\n return blindCast<\n P,\n 'validateCodecTypeParams synchronously validates this descriptor schema before the typed hook'\n >(validateCodecTypeParams(this, ref));\n }\n}\n\ntype DescriptorParams<D extends AnyCodecDescriptor> =\n D extends CodecDescriptor<infer P> ? P : never;\n\nexport interface PostgresCodecOptions<P> {\n readonly nativeType: (params: P) => string;\n readonly jsonProjection: (expression: ProjectionExpr, params: P) => ProjectionExpr;\n readonly jsonArrayProjection?: (expression: ProjectionExpr, params: P) => ProjectionExpr;\n}\n\nexport type AdaptedPostgresCodecDescriptor<D extends AnyCodecDescriptor> = Pick<\n D,\n keyof CodecDescriptor<DescriptorParams<D>>\n> &\n Pick<AnyPostgresCodecDescriptor, 'descriptorKind' | 'nativeTypeFor' | 'projectJson'>;\n\nclass PostgresCodecDescriptorAdapter<D extends AnyCodecDescriptor> extends PostgresCodecDescriptor<\n DescriptorParams<D>\n> {\n override readonly codecId: string;\n override readonly traits: readonly CodecTrait[];\n override readonly targetTypes: readonly string[];\n override readonly paramsSchema: D['paramsSchema'];\n override readonly metaFor?: (params: DescriptorParams<D>) => CodecMeta | undefined;\n override readonly renderOutputType?: (params: DescriptorParams<D>) => string | undefined;\n override readonly renderInputType?: (params: DescriptorParams<D>) => string | undefined;\n override readonly renderValueLiteral?: (\n value: JsonValue,\n side: 'output' | 'input',\n ) => string | undefined;\n override readonly factory: (\n params: DescriptorParams<D>,\n ) => (ctx: CodecInstanceContext) => Codec<string, readonly CodecTrait[], unknown, unknown>;\n\n constructor(\n private readonly descriptor: D,\n private readonly options: PostgresCodecOptions<DescriptorParams<D>>,\n ) {\n super();\n this.codecId = descriptor.codecId;\n this.traits = descriptor.traits;\n this.targetTypes = descriptor.targetTypes;\n this.paramsSchema = descriptor.paramsSchema;\n this.factory = (params) => descriptor.factory(params);\n\n if (descriptor.meta !== undefined) {\n Object.defineProperty(this, 'meta', {\n value: descriptor.meta,\n enumerable: true,\n });\n }\n\n const metaFor = descriptor.metaFor;\n if (metaFor !== undefined) {\n this.metaFor = (params) => metaFor.call(descriptor, params);\n }\n\n const renderOutputType = descriptor.renderOutputType;\n if (renderOutputType !== undefined) {\n this.renderOutputType = (params) => renderOutputType.call(descriptor, params);\n }\n\n const renderInputType = descriptor.renderInputType;\n if (renderInputType !== undefined) {\n this.renderInputType = (params) => renderInputType.call(descriptor, params);\n }\n\n const renderValueLiteral = descriptor.renderValueLiteral;\n if (renderValueLiteral !== undefined) {\n this.renderValueLiteral = (value, side) => renderValueLiteral.call(descriptor, value, side);\n }\n }\n\n override get isParameterized(): boolean {\n return this.descriptor.isParameterized;\n }\n\n protected override nativeType(params: DescriptorParams<D>): string {\n return this.options.nativeType(params);\n }\n\n protected override jsonProjection(\n expression: ProjectionExpr,\n params: DescriptorParams<D>,\n ): ProjectionExpr {\n return this.options.jsonProjection(expression, params);\n }\n\n protected override jsonArrayProjection(\n expression: ProjectionExpr,\n params: DescriptorParams<D>,\n ): ProjectionExpr {\n return this.options.jsonArrayProjection === undefined\n ? super.jsonArrayProjection(expression, params)\n : this.options.jsonArrayProjection(expression, params);\n }\n}\n\nexport function postgresCodec<D extends AnyCodecDescriptor>(\n descriptor: D,\n options: PostgresCodecOptions<DescriptorParams<D>>,\n): AdaptedPostgresCodecDescriptor<D> {\n return blindCast<\n AdaptedPostgresCodecDescriptor<D>,\n 'the adapter delegates every ordinary descriptor member while adding the validated PostgreSQL protocol'\n >(new PostgresCodecDescriptorAdapter(descriptor, options));\n}\n\nexport function definePostgresCodecs<\n const Descriptors extends readonly AnyPostgresCodecDescriptor[],\n>(descriptors: Descriptors): Descriptors {\n return descriptors;\n}\n\nexport function isPostgresCodecDescriptor(value: unknown): value is AnyPostgresCodecDescriptor {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'descriptorKind' in value &&\n value.descriptorKind === POSTGRES_CODEC_DESCRIPTOR_KIND &&\n 'codecId' in value &&\n typeof value.codecId === 'string' &&\n 'traits' in value &&\n Array.isArray(value.traits) &&\n 'targetTypes' in value &&\n Array.isArray(value.targetTypes) &&\n value.targetTypes.every((targetType) => typeof targetType === 'string') &&\n 'paramsSchema' in value &&\n isObjectLike(value.paramsSchema) &&\n '~standard' in value.paramsSchema &&\n isObjectLike(value.paramsSchema['~standard']) &&\n 'validate' in value.paramsSchema['~standard'] &&\n typeof value.paramsSchema['~standard'].validate === 'function' &&\n 'isParameterized' in value &&\n typeof value.isParameterized === 'boolean' &&\n 'factory' in value &&\n typeof value.factory === 'function' &&\n 'nativeTypeFor' in value &&\n typeof value.nativeTypeFor === 'function' &&\n 'projectJson' in value &&\n typeof value.projectJson === 'function'\n );\n}\n\nfunction isObjectLike(value: unknown): value is object {\n return (typeof value === 'object' && value !== null) || typeof value === 'function';\n}\n\nexport interface PostgresCodecDescriptorRegistry {\n descriptorFor(codecId: string): AnyPostgresCodecDescriptor | undefined;\n values(): IterableIterator<AnyPostgresCodecDescriptor>;\n}\n\nclass PostgresCodecDescriptorRegistryImpl implements PostgresCodecDescriptorRegistry {\n readonly #descriptors: ReadonlyMap<string, AnyPostgresCodecDescriptor>;\n\n constructor(descriptors: ReadonlyMap<string, AnyPostgresCodecDescriptor>) {\n this.#descriptors = descriptors;\n Object.freeze(this);\n }\n\n descriptorFor(codecId: string): AnyPostgresCodecDescriptor | undefined {\n return this.#descriptors.get(codecId);\n }\n\n *values(): IterableIterator<AnyPostgresCodecDescriptor> {\n yield* this.#descriptors.values();\n }\n}\n\nexport function buildPostgresCodecDescriptorRegistry(\n descriptors: ReadonlyArray<unknown>,\n): PostgresCodecDescriptorRegistry {\n const byId = new Map<string, AnyPostgresCodecDescriptor>();\n\n for (const descriptor of descriptors) {\n if (!isPostgresCodecDescriptor(descriptor)) {\n const codecId = candidateCodecId(descriptor);\n throw structuredError(\n 'POSTGRES.CODEC_DESCRIPTOR_INVALID',\n `Codec descriptor '${codecId}' is not a valid PostgreSQL codec descriptor.`,\n {\n why: 'PostgreSQL codec registries require the postgres-codec discriminant and complete target descriptor methods.',\n fix: 'Extend PostgresCodecDescriptor or adapt a generic descriptor with postgresCodec().',\n meta: { codecId },\n },\n );\n }\n\n if (byId.has(descriptor.codecId)) {\n throw structuredError(\n 'POSTGRES.CODEC_DESCRIPTOR_DUPLICATE',\n `Duplicate PostgreSQL codec descriptor id '${descriptor.codecId}'.`,\n {\n why: 'Each codecId must resolve to exactly one PostgreSQL descriptor during registry composition.',\n fix: 'Remove the duplicate target, adapter, or extension contribution.',\n meta: { codecId: descriptor.codecId },\n },\n );\n }\n\n byId.set(descriptor.codecId, descriptor);\n }\n\n return new PostgresCodecDescriptorRegistryImpl(byId);\n}\n\nfunction candidateCodecId(value: unknown): string {\n return typeof value === 'object' &&\n value !== null &&\n 'codecId' in value &&\n typeof value.codecId === 'string'\n ? value.codecId\n : '<unknown>';\n}\n"],"mappings":";;;;;AA8BA,MAAM,iCAAiC;AACvC,MAAM,oBAAoB;AAC1B,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;AAC3B,MAAM,0BAA0B;AAQhC,IAAsB,0BAAtB,cACU,oBAEV;CACE,iBAA0B;CAK1B,oBAA8B,YAA4B,QAA2B;EACnF,MAAM,aAAa,UAAU,GAAG,mBAAmB,kBAAkB;EACrE,MAAM,UAAU,UAAU,GAAG,qBAAqB,kBAAkB;EACpE,MAAM,aAAa,UAAU,GAAG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AO,GAC7B,MAAM,gBACJ,uCACA,6CAA6C,WAAW,QAAQ,KAChE;GACE,KAAK;GACL,KAAK;GACL,MAAM,EAAE,SAAS,WAAW,QAAQ;EACtC,CACF;EAGF,KAAK,IAAI,WAAW,SAAS,UAAU;CACzC;CAEA,OAAO,IAAI,oCAAoC,IAAI;AACrD;AAEA,SAAS,iBAAiB,OAAwB;CAChD,OAAO,OAAO,UAAU,YACtB,UAAU,QACV,aAAa,SACb,OAAO,MAAM,YAAY,WACvB,MAAM,UACN;AACN"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as PostgresCodecOptions, c as isPostgresCodecDescriptor, i as PostgresCodecDescriptorRegistry, l as postgresCodec, n as AnyPostgresCodecDescriptor, o as buildPostgresCodecDescriptorRegistry, r as PostgresCodecDescriptor, s as definePostgresCodecs, t as AdaptedPostgresCodecDescriptor } from "./codec-descriptor-C4SaWX0P.mjs";
|
|
2
|
+
export { type AdaptedPostgresCodecDescriptor, type AnyPostgresCodecDescriptor, PostgresCodecDescriptor, type PostgresCodecDescriptorRegistry, type PostgresCodecOptions, buildPostgresCodecDescriptorRegistry, definePostgresCodecs, isPostgresCodecDescriptor, postgresCodec };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as postgresCodec, i as isPostgresCodecDescriptor, n as buildPostgresCodecDescriptorRegistry, r as definePostgresCodecs, t as PostgresCodecDescriptor } from "./codec-descriptor-cuAuPE0Y.mjs";
|
|
2
|
+
export { PostgresCodecDescriptor, buildPostgresCodecDescriptorRegistry, definePostgresCodecs, isPostgresCodecDescriptor, postgresCodec };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as AdaptedPostgresCodecDescriptor } from "./codec-descriptor-C4SaWX0P.mjs";
|
|
2
|
+
import { C as PgTimestampDescriptor, D as PgVarbitDescriptor, E as PgUuidDescriptor, O as PgVarcharDescriptor, S as PgTimeDescriptor, T as PgTimetzDescriptor, _ as PgIntervalDescriptor, a as PgDateDescriptor, b as PgNumericDescriptor, d as PgFloatDescriptor, f as PgInetDescriptor, g as PgIntDescriptor, h as PgInt8Descriptor, i as PgCharDescriptor, l as PgFloat4Descriptor, m as PgInt4Descriptor, n as PgBoolDescriptor, p as PgInt2Descriptor, r as PgByteaDescriptor, s as PgEnumDescriptor, t as PgBitDescriptor, u as PgFloat8Descriptor, v as PgJsonDescriptor, w as PgTimestamptzDescriptor, x as PgTextDescriptor, y as PgJsonbDescriptor } from "./codecs-Cd4TftwI.mjs";
|
|
2
3
|
import { ExtractCodecTypes } from "@prisma-next/sql-relational-core/ast";
|
|
3
4
|
import { JsonValue as JsonValue$1 } from "@prisma-next/contract/types";
|
|
4
5
|
//#region src/core/codec-type-map.d.ts
|
|
5
6
|
declare const codecDescriptorMap: {
|
|
6
|
-
readonly char: import("@prisma-next/sql-relational-core/ast").SqlCharDescriptor
|
|
7
|
-
readonly varchar: import("@prisma-next/sql-relational-core/ast").SqlVarcharDescriptor
|
|
8
|
-
readonly int: import("@prisma-next/sql-relational-core/ast").SqlIntDescriptor
|
|
9
|
-
readonly float: import("@prisma-next/sql-relational-core/ast").SqlFloatDescriptor
|
|
10
|
-
readonly 'sql-text': import("@prisma-next/sql-relational-core/ast").SqlTextDescriptor
|
|
11
|
-
readonly 'sql-timestamp': import("@prisma-next/sql-relational-core/ast").SqlTimestampDescriptor
|
|
7
|
+
readonly char: AdaptedPostgresCodecDescriptor<import("@prisma-next/sql-relational-core/ast").SqlCharDescriptor>;
|
|
8
|
+
readonly varchar: AdaptedPostgresCodecDescriptor<import("@prisma-next/sql-relational-core/ast").SqlVarcharDescriptor>;
|
|
9
|
+
readonly int: AdaptedPostgresCodecDescriptor<import("@prisma-next/sql-relational-core/ast").SqlIntDescriptor>;
|
|
10
|
+
readonly float: AdaptedPostgresCodecDescriptor<import("@prisma-next/sql-relational-core/ast").SqlFloatDescriptor>;
|
|
11
|
+
readonly 'sql-text': AdaptedPostgresCodecDescriptor<import("@prisma-next/sql-relational-core/ast").SqlTextDescriptor>;
|
|
12
|
+
readonly 'sql-timestamp': AdaptedPostgresCodecDescriptor<import("@prisma-next/sql-relational-core/ast").SqlTimestampDescriptor>;
|
|
12
13
|
readonly text: PgTextDescriptor;
|
|
13
14
|
readonly enum: PgEnumDescriptor;
|
|
14
15
|
readonly character: PgCharDescriptor;
|
|
@@ -77,4 +78,4 @@ type Interval<P extends number | undefined = undefined> = BrandedString<{
|
|
|
77
78
|
}>;
|
|
78
79
|
//#endregion
|
|
79
80
|
export { JsonValue$1 as a, Timestamp as c, VarBit as d, Varchar as f, Interval as i, Timestamptz as l, Char as n, Numeric as o, CodecTypes as r, Time as s, Bit as t, Timetz as u };
|
|
80
|
-
//# sourceMappingURL=codec-types-
|
|
81
|
+
//# sourceMappingURL=codec-types-Bstec0HR.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec-types-Bstec0HR.d.mts","names":[],"sources":["../src/core/codec-type-map.ts","../src/exports/codec-types.ts"],"mappings":";;;;;cA6Ca;iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmCD,QAAQ,iBAAiB,WAAW,gBAAgB,WAAW,EAAE,KAAK,EAAE,GAAG;KAE3E,4BAA4B;KAE5B,sBAAsB,kBAAkB;;;KCzExC,aAAa,QAAQ;KAI5B,QAAQ,GAAG,cAAc,2BAA2B,gBAC7C,WAAW,QAAQ,MAAM;KAGhC,cAAc,cAAc,2BAA2B,gBAAgB;KAEhE,KAAK,oBAAoB;EAAgB,cAAc;;KACvD,QAAQ,oBAAoB;EAAgB,iBAAiB;;KAC7D,QAAQ,kBAAkB,4CAA4C;EAChF,oBAAoB;EACpB,gBAAgB;;KAEN,IAAI,oBAAoB;EAAgB,aAAa;;KACrD,OAAO,oBAAoB;EAAgB,gBAAgB;;KAC3D,UAAU,4CAA4C;EAChE,sBAAsB;;KAEZ,YAAY,4CAA4C;EAClE,wBAAwB;;KAEd,KAAK,4CAA4C;EAAgB,iBAAiB;;KAClF,OAAO,4CAA4C;EAC7D,mBAAmB;;KAET,SAAS,4CAA4C;EAC/D,qBAAqB"}
|
package/dist/codec-types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as JsonValue, c as Timestamp, d as VarBit, f as Varchar, i as Interval, l as Timestamptz, n as Char, o as Numeric, r as CodecTypes, s as Time, t as Bit, u as Timetz } from "./codec-types-
|
|
1
|
+
import { a as JsonValue, c as Timestamp, d as VarBit, f as Varchar, i as Interval, l as Timestamptz, n as Char, o as Numeric, r as CodecTypes, s as Time, t as Bit, u as Timetz } from "./codec-types-Bstec0HR.mjs";
|
|
2
2
|
export { Bit, Char, CodecTypes, Interval, type JsonValue, Numeric, Time, Timestamp, Timestamptz, Timetz, VarBit, Varchar };
|