@prisma-next/target-postgres 0.12.0-dev.1 → 0.12.0-dev.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/control.mjs +34 -18
- package/dist/control.mjs.map +1 -1
- package/dist/{descriptor-meta-Dvr_77Z3.mjs → descriptor-meta-Uu8QaClr.mjs} +2 -2
- package/dist/{descriptor-meta-Dvr_77Z3.mjs.map → descriptor-meta-Uu8QaClr.mjs.map} +1 -1
- package/dist/{descriptor-meta-runtime-ByjztWgs.mjs → descriptor-meta-runtime-DMRX39kp.mjs} +2 -2
- package/dist/{descriptor-meta-runtime-ByjztWgs.mjs.map → descriptor-meta-runtime-DMRX39kp.mjs.map} +1 -1
- package/dist/{enum-planning-DrNWCtCp.mjs → enum-planning-DRA9LaMU.mjs} +0 -0
- package/dist/{enum-planning-DrNWCtCp.mjs.map → enum-planning-DRA9LaMU.mjs.map} +1 -1
- package/dist/enum-planning.d.mts +1 -1
- package/dist/enum-planning.mjs +1 -1
- package/dist/{issue-planner-2RgYsjUJ.mjs → issue-planner-BtaL6OfW.mjs} +7 -7
- package/dist/{issue-planner-2RgYsjUJ.mjs.map → issue-planner-BtaL6OfW.mjs.map} +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.mjs +1 -1
- package/dist/{op-factory-call-C_K5ibAY.mjs → op-factory-call-ewOd5q6L.mjs} +2 -2
- package/dist/{op-factory-call-C_K5ibAY.mjs.map → op-factory-call-ewOd5q6L.mjs.map} +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/pack.d.mts +2 -1
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-CC3r_uNJ.mjs → planner-Bjz5pnLa.mjs} +4 -4
- package/dist/{planner-CC3r_uNJ.mjs.map → planner-Bjz5pnLa.mjs.map} +1 -1
- package/dist/{planner-ddl-builders-DgyqpFji.mjs → planner-ddl-builders-BNMfSE9r.mjs} +2 -2
- package/dist/{planner-ddl-builders-DgyqpFji.mjs.map → planner-ddl-builders-BNMfSE9r.mjs.map} +1 -1
- package/dist/planner-ddl-builders.mjs +1 -1
- package/dist/{planner-sql-checks-BMu3fiMc.mjs → planner-sql-checks-CfEiTXoQ.mjs} +2 -2
- package/dist/{planner-sql-checks-BMu3fiMc.mjs.map → planner-sql-checks-CfEiTXoQ.mjs.map} +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-contract-serializer-C0UtIDB8.mjs → postgres-contract-serializer-BnOboPWs.mjs} +3 -3
- package/dist/{postgres-contract-serializer-C0UtIDB8.mjs.map → postgres-contract-serializer-BnOboPWs.mjs.map} +1 -1
- package/dist/{postgres-enum-type-DS-KLVRH.mjs → postgres-enum-type-BMgyxNyy.mjs} +2 -1
- package/dist/postgres-enum-type-BMgyxNyy.mjs.map +1 -0
- package/dist/{postgres-enum-type-5MBoKsIj.d.mts → postgres-enum-type-CSzsvXrO.d.mts} +4 -1
- package/dist/postgres-enum-type-CSzsvXrO.d.mts.map +1 -0
- package/dist/{postgres-schema-vp5rvbYg.mjs → postgres-schema-BxAuNFX0.mjs} +2 -2
- package/dist/{postgres-schema-vp5rvbYg.mjs.map → postgres-schema-BxAuNFX0.mjs.map} +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/{statement-builders-DVI5IVAa.mjs → statement-builders-DgYQooDR.mjs} +16 -4
- package/dist/statement-builders-DgYQooDR.mjs.map +1 -0
- package/dist/statement-builders.d.mts.map +1 -1
- package/dist/statement-builders.mjs +1 -1
- package/dist/{tables-C8RrPLUq.mjs → tables-DoA39Yqo.mjs} +2 -2
- package/dist/{tables-C8RrPLUq.mjs.map → tables-DoA39Yqo.mjs.map} +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.mjs +2 -2
- package/package.json +17 -17
- package/src/core/migrations/runner.ts +50 -15
- package/src/core/migrations/statement-builders.ts +18 -3
- package/src/core/postgres-enum-type.ts +4 -0
- package/dist/postgres-enum-type-5MBoKsIj.d.mts.map +0 -1
- package/dist/postgres-enum-type-DS-KLVRH.mjs.map +0 -1
- package/dist/statement-builders-DVI5IVAa.mjs.map +0 -1
|
@@ -40,6 +40,9 @@ export const ensureLedgerTableStatement: SqlStatement = {
|
|
|
40
40
|
sql: `create table if not exists prisma_contract.ledger (
|
|
41
41
|
id bigserial primary key,
|
|
42
42
|
created_at timestamptz not null default now(),
|
|
43
|
+
space text not null,
|
|
44
|
+
migration_name text not null,
|
|
45
|
+
migration_hash text not null,
|
|
43
46
|
origin_core_hash text,
|
|
44
47
|
origin_profile_hash text,
|
|
45
48
|
destination_core_hash text not null,
|
|
@@ -138,6 +141,9 @@ export function buildMergeMarkerStatements(input: MergeMarkerInput): {
|
|
|
138
141
|
}
|
|
139
142
|
|
|
140
143
|
export interface LedgerInsertInput {
|
|
144
|
+
readonly space: string;
|
|
145
|
+
readonly migrationName: string;
|
|
146
|
+
readonly migrationHash: string;
|
|
141
147
|
readonly originStorageHash?: string | null;
|
|
142
148
|
readonly originProfileHash?: string | null;
|
|
143
149
|
readonly destinationStorageHash: string;
|
|
@@ -150,6 +156,9 @@ export interface LedgerInsertInput {
|
|
|
150
156
|
export function buildLedgerInsertStatement(input: LedgerInsertInput): SqlStatement {
|
|
151
157
|
return {
|
|
152
158
|
sql: `insert into prisma_contract.ledger (
|
|
159
|
+
space,
|
|
160
|
+
migration_name,
|
|
161
|
+
migration_hash,
|
|
153
162
|
origin_core_hash,
|
|
154
163
|
origin_profile_hash,
|
|
155
164
|
destination_core_hash,
|
|
@@ -162,11 +171,17 @@ export function buildLedgerInsertStatement(input: LedgerInsertInput): SqlStateme
|
|
|
162
171
|
$2,
|
|
163
172
|
$3,
|
|
164
173
|
$4,
|
|
165
|
-
$5
|
|
166
|
-
$6
|
|
167
|
-
$7
|
|
174
|
+
$5,
|
|
175
|
+
$6,
|
|
176
|
+
$7,
|
|
177
|
+
$8::jsonb,
|
|
178
|
+
$9::jsonb,
|
|
179
|
+
$10::jsonb
|
|
168
180
|
)`,
|
|
169
181
|
params: [
|
|
182
|
+
input.space,
|
|
183
|
+
input.migrationName,
|
|
184
|
+
input.migrationHash,
|
|
170
185
|
input.originStorageHash ?? null,
|
|
171
186
|
input.originProfileHash ?? null,
|
|
172
187
|
input.destinationStorageHash,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ControlPolicy } from '@prisma-next/contract/types';
|
|
1
2
|
import { freezeNode } from '@prisma-next/framework-components/ir';
|
|
2
3
|
import { SqlNode } from '@prisma-next/sql-contract/types';
|
|
3
4
|
|
|
@@ -18,6 +19,7 @@ export interface PostgresEnumTypeInput<
|
|
|
18
19
|
*/
|
|
19
20
|
readonly nativeType?: string;
|
|
20
21
|
readonly values: TValues;
|
|
22
|
+
readonly control?: ControlPolicy;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
/** Codec id used by Postgres enum-typed columns (text wire format). */
|
|
@@ -64,6 +66,7 @@ export class PostgresEnumType<
|
|
|
64
66
|
* dispatching through the prototype-only `codecBinding` accessor.
|
|
65
67
|
*/
|
|
66
68
|
readonly codecId: typeof PG_ENUM_CODEC_ID = PG_ENUM_CODEC_ID;
|
|
69
|
+
declare readonly control?: ControlPolicy;
|
|
67
70
|
|
|
68
71
|
constructor(input: PostgresEnumTypeInput<TName, TValues>) {
|
|
69
72
|
super();
|
|
@@ -73,6 +76,7 @@ export class PostgresEnumType<
|
|
|
73
76
|
// `TValues` literal tuple. Cast preserves the caller-supplied
|
|
74
77
|
// tuple shape so inferred contract types retain literal narrowing.
|
|
75
78
|
this.values = Object.freeze([...input.values] as unknown as TValues);
|
|
79
|
+
if (input.control !== undefined) this.control = input.control;
|
|
76
80
|
freezeNode(this);
|
|
77
81
|
}
|
|
78
82
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-enum-type-5MBoKsIj.d.mts","names":[],"sources":["../src/core/postgres-enum-type.ts"],"mappings":";;;UAGiB,qBAAA;;AAAjB;;;;WASW,IAAA,EAAM,KAAA;EAPf;;;;;EAAA,SAaS,UAAA;EAAA,SACA,MAAA,EAAQ,OAAO;AAAA;AACzB;AAAA,cAGK,gBAAA;;;AAAgB;AAyBtB;;;;;;;;;;;;;;;;;;;;cAAa,gBAAA,+FAGH,OAAA;EAAA,SACU,IAAA;EAAA,SACT,IAAA,EAAM,KAAA;EAAA,SACN,UAAA;EAAA,SACA,MAAA,EAAQ,OAAA;;;;;;;;;;WAUR,OAAA,SAAgB,gBAAA;cAEb,KAAA,EAAO,qBAAA,CAAsB,KAAA,EAAO,OAAA;EAAA,IAW5C,YAAA,CAAA;IAAA,SACO,OAAA,SAAgB,gBAAA;IAAA,SAChB,UAAA;MAAA,SAAuB,MAAA,EAAQ,OAAA;IAAA;EAAA;AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-enum-type-DS-KLVRH.mjs","names":[],"sources":["../src/core/postgres-enum-type.ts"],"sourcesContent":["import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from '@prisma-next/sql-contract/types';\n\nexport interface PostgresEnumTypeInput<\n TName extends string = string,\n TValues extends readonly string[] = readonly string[],\n> {\n /**\n * Contract-level enum name (e.g. `'Role'`). Used as the key in\n * `SqlStorage.types` and as the contract-facing identifier in\n * planner / verifier diagnostics.\n */\n readonly name: TName;\n /**\n * Postgres-side native type name created by `CREATE TYPE … AS ENUM`.\n * Defaults to `name` when not overridden via PSL `@map(...)` or the\n * TS authoring surface.\n */\n readonly nativeType?: string;\n readonly values: TValues;\n}\n\n/** Codec id used by Postgres enum-typed columns (text wire format). */\nconst PG_ENUM_CODEC_ID = 'pg/enum@1';\n\n/**\n * Postgres IR class for the `CREATE TYPE … AS ENUM` concept.\n *\n * Per Decision 18, enum is a target-only concept (Postgres alone today;\n * SQLite emulates via CHECK constraints). There is no family-layer\n * enum abstract — the abstract-earns-existence rule keeps the IR class\n * hierarchy minimal: this class extends `SqlNode` directly and is the\n * single concrete representation of the polymorphic `'postgres-enum'`\n * slot variant.\n *\n * Carries Postgres-specific resolution (`nativeType` defaults to\n * `name`; `values` is frozen at construction time). Constructor calls\n * `freezeNode(this)` per Decision 8 — the instance is fully immutable,\n * JSON-clean, and dispatchable on its enumerable `kind: 'postgres-enum'`\n * literal.\n *\n * The family-layer slot dispatch (verifier, planner, lowering, etc.)\n * narrows polymorphic `StorageType` entries via the `kind` literal\n * (e.g. `isPostgresEnumStorageEntry`) — SQL-domain code must not import\n * `target-postgres` directly (cross-domain layering rule). The\n * structural interface lives at the family layer for that purpose;\n * this class is the runtime concrete that satisfies it.\n */\nexport class PostgresEnumType<\n TName extends string = string,\n TValues extends readonly string[] = readonly string[],\n> extends SqlNode {\n override readonly kind = 'postgres-enum' as const;\n readonly name: TName;\n readonly nativeType: string;\n readonly values: TValues;\n /**\n * Enumerable own property so the persisted JSON envelope carries\n * `codecId: 'pg/enum@1'` alongside `kind: 'postgres-enum'`. The\n * runtime path (`codecRefForStorageColumn`, `assertColumnCodecIntegrity`)\n * receives JSON-shaped contracts (e.g. inside a user-written\n * `migration.ts` that loads `endContract` from `end-contract.json`)\n * and reads `codecId` directly from the envelope rather than\n * dispatching through the prototype-only `codecBinding` accessor.\n */\n readonly codecId: typeof PG_ENUM_CODEC_ID = PG_ENUM_CODEC_ID;\n\n constructor(input: PostgresEnumTypeInput<TName, TValues>) {\n super();\n this.name = input.name;\n this.nativeType = input.nativeType ?? input.name;\n // `Object.freeze` returns `Readonly<string[]>`, widening past the\n // `TValues` literal tuple. Cast preserves the caller-supplied\n // tuple shape so inferred contract types retain literal narrowing.\n this.values = Object.freeze([...input.values] as unknown as TValues);\n freezeNode(this);\n }\n\n get codecBinding(): {\n readonly codecId: typeof PG_ENUM_CODEC_ID;\n readonly typeParams: { readonly values: TValues };\n } {\n return { codecId: PG_ENUM_CODEC_ID, typeParams: { values: this.values } };\n }\n}\n"],"mappings":";;;;AAuBA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;AAyBzB,IAAa,mBAAb,cAGU,QAAQ;CAChB,OAAyB;CACzB;CACA;CACA;;;;;;;;;;CAUA,UAA4C;CAE5C,YAAY,OAA8C;EACxD,MAAM;EACN,KAAK,OAAO,MAAM;EAClB,KAAK,aAAa,MAAM,cAAc,MAAM;EAI5C,KAAK,SAAS,OAAO,OAAO,CAAC,GAAG,MAAM,MAAM,CAAuB;EACnE,WAAW,IAAI;CACjB;CAEA,IAAI,eAGF;EACA,OAAO;GAAE,SAAS;GAAkB,YAAY,EAAE,QAAQ,KAAK,OAAO;EAAE;CAC1E;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"statement-builders-DVI5IVAa.mjs","names":["APP_SPACE_ID"],"sources":["../src/core/migrations/statement-builders.ts"],"sourcesContent":["import { APP_SPACE_ID } from '@prisma-next/framework-components/control';\n\nexport { APP_SPACE_ID };\n\nexport interface SqlStatement {\n readonly sql: string;\n readonly params: readonly unknown[];\n}\n\nexport const ensurePrismaContractSchemaStatement: SqlStatement = {\n sql: 'create schema if not exists prisma_contract',\n params: [],\n};\n\n/**\n * Schema for `prisma_contract.marker`. The `space text` primary key\n * supports one row per loaded contract space (`'app'`,\n * `'<extension-id>'`, …); on a brand-new database `CREATE TABLE IF NOT\n * EXISTS` produces this shape directly. The migration runner detects\n * pre-1.0 single-row markers (no `space` column) at boot and fails with\n * a structured `LEGACY_MARKER_SHAPE` error rather than auto-migrating —\n * see `specs/framework-mechanism.spec.md § 2`.\n */\nexport const ensureMarkerTableStatement: SqlStatement = {\n sql: `create table if not exists prisma_contract.marker (\n space text not null primary key default '${APP_SPACE_ID}',\n core_hash text not null,\n profile_hash text not null,\n contract_json jsonb,\n canonical_version int,\n updated_at timestamptz not null default now(),\n app_tag text,\n meta jsonb not null default '{}',\n invariants text[] not null default '{}'\n )`,\n params: [],\n};\n\nexport const ensureLedgerTableStatement: SqlStatement = {\n sql: `create table if not exists prisma_contract.ledger (\n id bigserial primary key,\n created_at timestamptz not null default now(),\n origin_core_hash text,\n origin_profile_hash text,\n destination_core_hash text not null,\n destination_profile_hash text,\n contract_json_before jsonb,\n contract_json_after jsonb,\n operations jsonb not null\n )`,\n params: [],\n};\n\nexport interface MergeMarkerInput {\n /**\n * Logical space identifier for this marker row. Required at every\n * call site so the type system surfaces every place that needs to\n * thread the value (rather than letting an `?? APP_SPACE_ID`\n * fall-through silently collapse per-space markers onto the\n * `'app'` row). App-plan callers pass {@link APP_SPACE_ID}\n * (`'app'`); per-extension callers (planner / runner / verifier\n * extensions over contract spaces) pass the extension's space id.\n */\n readonly space: string;\n readonly storageHash: string;\n readonly profileHash: string;\n readonly contractJson?: unknown;\n readonly canonicalVersion?: number | null;\n readonly appTag?: string | null;\n readonly meta?: Record<string, unknown>;\n /**\n * Invariants to merge into `marker.invariants`. INSERT writes them as\n * the initial value (callers are expected to pass a sorted, deduped\n * array). UPDATE merges them with the existing column server-side via\n * a single atomic SQL expression.\n */\n readonly invariants: readonly string[];\n}\n\nexport function buildMergeMarkerStatements(input: MergeMarkerInput): {\n readonly insert: SqlStatement;\n readonly update: SqlStatement;\n} {\n const params: readonly unknown[] = [\n input.space,\n input.storageHash,\n input.profileHash,\n jsonParam(input.contractJson),\n input.canonicalVersion ?? null,\n input.appTag ?? null,\n jsonParam(input.meta ?? {}),\n input.invariants,\n ];\n\n return {\n insert: {\n sql: `insert into prisma_contract.marker (\n space,\n core_hash,\n profile_hash,\n contract_json,\n canonical_version,\n updated_at,\n app_tag,\n meta,\n invariants\n ) values (\n $1,\n $2,\n $3,\n $4::jsonb,\n $5,\n now(),\n $6,\n $7::jsonb,\n $8::text[]\n )`,\n params,\n },\n update: {\n // `invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)`\n // reads the current column value under the UPDATE's row lock, unions\n // with the incoming array, dedupes, and sorts ascending — single\n // statement, atomic, no read-then-write window.\n sql: `update prisma_contract.marker set\n core_hash = $2,\n profile_hash = $3,\n contract_json = $4::jsonb,\n canonical_version = $5,\n updated_at = now(),\n app_tag = $6,\n meta = $7::jsonb,\n invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)\n where space = $1`,\n params,\n },\n };\n}\n\nexport interface LedgerInsertInput {\n readonly originStorageHash?: string | null;\n readonly originProfileHash?: string | null;\n readonly destinationStorageHash: string;\n readonly destinationProfileHash?: string | null;\n readonly contractJsonBefore?: unknown;\n readonly contractJsonAfter?: unknown;\n readonly operations: unknown;\n}\n\nexport function buildLedgerInsertStatement(input: LedgerInsertInput): SqlStatement {\n return {\n sql: `insert into prisma_contract.ledger (\n origin_core_hash,\n origin_profile_hash,\n destination_core_hash,\n destination_profile_hash,\n contract_json_before,\n contract_json_after,\n operations\n ) values (\n $1,\n $2,\n $3,\n $4,\n $5::jsonb,\n $6::jsonb,\n $7::jsonb\n )`,\n params: [\n input.originStorageHash ?? null,\n input.originProfileHash ?? null,\n input.destinationStorageHash,\n input.destinationProfileHash ?? null,\n jsonParam(input.contractJsonBefore),\n jsonParam(input.contractJsonAfter),\n jsonParam(input.operations),\n ],\n };\n}\n\nfunction jsonParam(value: unknown): string {\n return JSON.stringify(value ?? null);\n}\n"],"mappings":";;AASA,MAAa,sCAAoD;CAC/D,KAAK;CACL,QAAQ,CAAC;AACX;;;;;;;;;;AAWA,MAAa,6BAA2C;CACtD,KAAK;+CACwCA,eAAa;;;;;;;;;;CAU1D,QAAQ,CAAC;AACX;AAEA,MAAa,6BAA2C;CACtD,KAAK;;;;;;;;;;;CAWL,QAAQ,CAAC;AACX;AA4BA,SAAgB,2BAA2B,OAGzC;CACA,MAAM,SAA6B;EACjC,MAAM;EACN,MAAM;EACN,MAAM;EACN,UAAU,MAAM,YAAY;EAC5B,MAAM,oBAAoB;EAC1B,MAAM,UAAU;EAChB,UAAU,MAAM,QAAQ,CAAC,CAAC;EAC1B,MAAM;CACR;CAEA,OAAO;EACL,QAAQ;GACN,KAAK;;;;;;;;;;;;;;;;;;;;;GAqBL;EACF;EACA,QAAQ;GAKN,KAAK;;;;;;;;;;GAUL;EACF;CACF;AACF;AAYA,SAAgB,2BAA2B,OAAwC;CACjF,OAAO;EACL,KAAK;;;;;;;;;;;;;;;;;EAiBL,QAAQ;GACN,MAAM,qBAAqB;GAC3B,MAAM,qBAAqB;GAC3B,MAAM;GACN,MAAM,0BAA0B;GAChC,UAAU,MAAM,kBAAkB;GAClC,UAAU,MAAM,iBAAiB;GACjC,UAAU,MAAM,UAAU;EAC5B;CACF;AACF;AAEA,SAAS,UAAU,OAAwB;CACzC,OAAO,KAAK,UAAU,SAAS,IAAI;AACrC"}
|