@prisma-next/target-postgres 0.7.0 → 0.8.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/{codec-ids-CplrEfmx.d.mts → codec-ids-RvYfmUmi.d.mts} +1 -1
- package/dist/{codec-ids-CplrEfmx.d.mts.map → codec-ids-RvYfmUmi.d.mts.map} +1 -1
- package/dist/codec-ids.d.mts +1 -1
- package/dist/{codec-types-lrsb3N07.d.mts → codec-types-667FxIW8.d.mts} +2 -2
- package/dist/{codec-types-lrsb3N07.d.mts.map → codec-types-667FxIW8.d.mts.map} +1 -1
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs-Cue97Xqf.d.mts → codecs-DXeDABSO.d.mts} +2 -2
- package/dist/{codecs-Cue97Xqf.d.mts.map → codecs-DXeDABSO.d.mts.map} +1 -1
- package/dist/codecs.d.mts +1 -1
- package/dist/control.d.mts +2 -2
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +38 -7
- package/dist/control.mjs.map +1 -1
- package/dist/{data-transform-bIeAcZIJ.d.mts → data-transform-B6p02mFJ.d.mts} +3 -3
- package/dist/{data-transform-bIeAcZIJ.d.mts.map → data-transform-B6p02mFJ.d.mts.map} +1 -1
- package/dist/{data-transform-DKWXdHuZ.mjs → data-transform-aF9az88u.mjs} +1 -1
- package/dist/{data-transform-DKWXdHuZ.mjs.map → data-transform-aF9az88u.mjs.map} +1 -1
- package/dist/data-transform.d.mts +1 -1
- package/dist/data-transform.mjs +1 -1
- package/dist/{default-normalizer-C8XyZj85.mjs → default-normalizer-DHCsbfjc.mjs} +1 -1
- package/dist/{default-normalizer-C8XyZj85.mjs.map → default-normalizer-DHCsbfjc.mjs.map} +1 -1
- package/dist/default-normalizer.mjs +1 -1
- package/dist/descriptor-meta-DFUCClk_.mjs +124 -0
- package/dist/descriptor-meta-DFUCClk_.mjs.map +1 -0
- package/dist/enum-planning-Bqp96iIw.mjs +63 -0
- package/dist/enum-planning-Bqp96iIw.mjs.map +1 -0
- package/dist/enum-planning.d.mts +48 -0
- package/dist/enum-planning.d.mts.map +1 -0
- package/dist/enum-planning.mjs +2 -0
- package/dist/{errors-Chm2bKcS.mjs → errors-BiOloWUh.mjs} +1 -1
- package/dist/{errors-Chm2bKcS.mjs.map → errors-BiOloWUh.mjs.map} +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/{issue-planner-DQ6WJkad.mjs → issue-planner-BhWVYyE1.mjs} +114 -49
- package/dist/issue-planner-BhWVYyE1.mjs.map +1 -0
- package/dist/issue-planner.d.mts +11 -9
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +4 -4
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +3 -3
- package/dist/{native-type-normalizer-Cry4QoLf.mjs → native-type-normalizer-DMikJJ1V.mjs} +1 -1
- package/dist/{native-type-normalizer-Cry4QoLf.mjs.map → native-type-normalizer-DMikJJ1V.mjs.map} +1 -1
- package/dist/native-type-normalizer.mjs +1 -1
- package/dist/{op-factory-call-DeaFxa8_.mjs → op-factory-call-DerP9BoT.mjs} +8 -5
- package/dist/{op-factory-call-DeaFxa8_.mjs.map → op-factory-call-DerP9BoT.mjs.map} +1 -1
- package/dist/{op-factory-call-UFpUPJL6.d.mts → op-factory-call-c1zELk3U.d.mts} +5 -4
- package/dist/{op-factory-call-UFpUPJL6.d.mts.map → op-factory-call-c1zELk3U.d.mts.map} +1 -1
- package/dist/op-factory-call.d.mts +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/pack.d.mts +13 -24
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-CYtKhLYa.mjs → planner-DSDXUbQ4.mjs} +8 -6
- package/dist/planner-DSDXUbQ4.mjs.map +1 -0
- package/dist/{planner-ddl-builders-CLB7Umhh.mjs → planner-ddl-builders-5QIyhBUF.mjs} +3 -3
- package/dist/planner-ddl-builders-5QIyhBUF.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts +5 -5
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +1 -1
- package/dist/{planner-identity-values-DTx0gePL.mjs → planner-identity-values-BUYNOCwb.mjs} +9 -3
- package/dist/planner-identity-values-BUYNOCwb.mjs.map +1 -0
- package/dist/planner-identity-values.d.mts +1 -1
- package/dist/planner-identity-values.d.mts.map +1 -1
- package/dist/planner-identity-values.mjs +1 -1
- package/dist/{planner-produced-postgres-migration-CjxWIVgh.d.mts → planner-produced-postgres-migration-D34ftfEK.d.mts} +3 -3
- package/dist/{planner-produced-postgres-migration-CjxWIVgh.d.mts.map → planner-produced-postgres-migration-D34ftfEK.d.mts.map} +1 -1
- package/dist/{planner-produced-postgres-migration-DphktB2N.mjs → planner-produced-postgres-migration-D8OCSSLM.mjs} +4 -4
- package/dist/{planner-produced-postgres-migration-DphktB2N.mjs.map → planner-produced-postgres-migration-D8OCSSLM.mjs.map} +1 -1
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-schema-lookup-B1ags8ys.mjs → planner-schema-lookup--u9whY_Y.mjs} +1 -1
- package/dist/{planner-schema-lookup-B1ags8ys.mjs.map → planner-schema-lookup--u9whY_Y.mjs.map} +1 -1
- package/dist/planner-schema-lookup.mjs +1 -1
- package/dist/{planner-sql-checks-DwZvGlV4.mjs → planner-sql-checks-Cd016Ycs.mjs} +7 -2
- package/dist/planner-sql-checks-Cd016Ycs.mjs.map +1 -0
- package/dist/planner-sql-checks.d.mts +2 -2
- package/dist/planner-sql-checks.d.mts.map +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/{planner-target-details-bVVcanWh.d.mts → planner-target-details-iYJwzFHP.d.mts} +1 -1
- package/dist/{planner-target-details-bVVcanWh.d.mts.map → planner-target-details-iYJwzFHP.d.mts.map} +1 -1
- package/dist/planner-target-details.d.mts +1 -1
- package/dist/planner.d.mts +1 -1
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/postgres-contract-serializer-D5VJk6lo.mjs +61 -0
- package/dist/postgres-contract-serializer-D5VJk6lo.mjs.map +1 -0
- package/dist/postgres-enum-type-CrKq8au9.d.mts +69 -0
- package/dist/postgres-enum-type-CrKq8au9.d.mts.map +1 -0
- package/dist/postgres-enum-type-DS-KLVRH.mjs +61 -0
- package/dist/postgres-enum-type-DS-KLVRH.mjs.map +1 -0
- package/dist/{postgres-migration-UkcHfZAA.d.mts → postgres-migration-CiQzhcMe.d.mts} +4 -4
- package/dist/{postgres-migration-UkcHfZAA.d.mts.map → postgres-migration-CiQzhcMe.d.mts.map} +1 -1
- package/dist/{postgres-migration-Bkv140RW.mjs → postgres-migration-Fdxzo6l2.mjs} +3 -3
- package/dist/{postgres-migration-Bkv140RW.mjs.map → postgres-migration-Fdxzo6l2.mjs.map} +1 -1
- package/dist/{render-ops--1nnfNus.mjs → render-ops-CkiuHSNj.mjs} +1 -1
- package/dist/{render-ops--1nnfNus.mjs.map → render-ops-CkiuHSNj.mjs.map} +1 -1
- package/dist/render-ops.d.mts +1 -1
- package/dist/render-ops.mjs +1 -1
- package/dist/{render-typescript-D3doH-vX.mjs → render-typescript-C9XWI8Ld.mjs} +1 -1
- package/dist/{render-typescript-D3doH-vX.mjs.map → render-typescript-C9XWI8Ld.mjs.map} +1 -1
- package/dist/render-typescript.mjs +1 -1
- package/dist/runtime.d.mts +25 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +3 -2
- package/dist/runtime.mjs.map +1 -1
- package/dist/{shared-MpwjwAjM.d.mts → shared-DLYdmYo-.d.mts} +2 -2
- package/dist/{shared-MpwjwAjM.d.mts.map → shared-DLYdmYo-.d.mts.map} +1 -1
- package/dist/{sql-utils-CggjWNij.mjs → sql-utils-BewXAnsG.mjs} +1 -1
- package/dist/{sql-utils-CggjWNij.mjs.map → sql-utils-BewXAnsG.mjs.map} +1 -1
- package/dist/sql-utils.mjs +1 -1
- package/dist/{statement-builders-BT889jV0.mjs → statement-builders-BSIQMClE.mjs} +1 -1
- package/dist/{statement-builders-BT889jV0.mjs.map → statement-builders-BSIQMClE.mjs.map} +1 -1
- package/dist/statement-builders.mjs +1 -1
- package/dist/{tables-DgYIXjUt.mjs → tables-Ce_Q0I8B.mjs} +7 -7
- package/dist/{tables-DgYIXjUt.mjs.map → tables-Ce_Q0I8B.mjs.map} +1 -1
- package/dist/{types-CTqpysRY.d.mts → types-Dq74Z3eu.d.mts} +1 -1
- package/dist/types-Dq74Z3eu.d.mts.map +1 -0
- package/dist/types.d.mts +3 -2
- package/dist/types.mjs +2 -1
- package/package.json +20 -19
- package/src/core/authoring.ts +41 -9
- package/src/core/descriptor-meta.ts +6 -1
- package/src/core/migrations/enum-planning.ts +93 -0
- package/src/core/migrations/issue-planner.ts +25 -13
- package/src/core/migrations/op-factory-call.ts +12 -3
- package/src/core/migrations/operations/enums.ts +5 -4
- package/src/core/migrations/planner-ddl-builders.ts +4 -3
- package/src/core/migrations/planner-identity-values.ts +28 -4
- package/src/core/migrations/planner-recipes.ts +6 -2
- package/src/core/migrations/planner-sql-checks.ts +6 -2
- package/src/core/migrations/planner-strategies.ts +187 -74
- package/src/core/migrations/planner-type-resolution.ts +20 -2
- package/src/core/migrations/planner.ts +3 -0
- package/src/core/migrations/runner.ts +3 -0
- package/src/core/postgres-contract-serializer.ts +70 -0
- package/src/core/postgres-enum-type.ts +85 -0
- package/src/core/postgres-schema-verifier.ts +37 -0
- package/src/exports/control.ts +4 -0
- package/src/exports/enum-planning.ts +6 -0
- package/src/exports/runtime.ts +2 -0
- package/src/exports/types.ts +1 -0
- package/dist/descriptor-meta-Dde_BS3K.mjs +0 -99
- package/dist/descriptor-meta-Dde_BS3K.mjs.map +0 -1
- package/dist/issue-planner-DQ6WJkad.mjs.map +0 -1
- package/dist/planner-CYtKhLYa.mjs.map +0 -1
- package/dist/planner-ddl-builders-CLB7Umhh.mjs.map +0 -1
- package/dist/planner-identity-values-DTx0gePL.mjs.map +0 -1
- package/dist/planner-sql-checks-DwZvGlV4.mjs.map +0 -1
- package/dist/types-CTqpysRY.d.mts.map +0 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { t as PostgresEnumType } from "./postgres-enum-type-DS-KLVRH.mjs";
|
|
2
|
+
import { n as postgresAuthoringEntityTypes } from "./descriptor-meta-DFUCClk_.mjs";
|
|
3
|
+
import { SqlContractSerializerBase } from "@prisma-next/family-sql/ir";
|
|
4
|
+
//#region src/core/postgres-contract-serializer.ts
|
|
5
|
+
/**
|
|
6
|
+
* Build the hydration registry from this target pack's literal
|
|
7
|
+
* `postgresAuthoringEntityTypes`. Extension-pack-contributed entity
|
|
8
|
+
* types do not reach this registry today; the surface is honest for
|
|
9
|
+
* in-tree consumers (Postgres pack only) and the slot stays
|
|
10
|
+
* deserializable because the family-layer validator's
|
|
11
|
+
* `StorageTypeEntrySchema` only admits kinds whose factory the
|
|
12
|
+
* Postgres pack already ships.
|
|
13
|
+
*
|
|
14
|
+
* Future open (F14): lift the registry build to descriptor-composition
|
|
15
|
+
* time, threading the composed `AuthoringContributions.entityTypes`
|
|
16
|
+
* from extension packs, so a real extension pack shipping a
|
|
17
|
+
* round-trip-needing entity type can be deserialized end-to-end.
|
|
18
|
+
* Earned by the first such extension pack in tree.
|
|
19
|
+
*/
|
|
20
|
+
function buildPostgresEntityTypeRegistry() {
|
|
21
|
+
const ctx = {
|
|
22
|
+
family: "sql",
|
|
23
|
+
target: "postgres"
|
|
24
|
+
};
|
|
25
|
+
const registry = /* @__PURE__ */ new Map();
|
|
26
|
+
for (const descriptor of Object.values(postgresAuthoringEntityTypes)) {
|
|
27
|
+
if (descriptor.kind !== "entity") continue;
|
|
28
|
+
if (!("factory" in descriptor.output)) continue;
|
|
29
|
+
const factory = descriptor.output.factory;
|
|
30
|
+
registry.set(descriptor.discriminator, (entry) => {
|
|
31
|
+
if (entry instanceof PostgresEnumType) return entry;
|
|
32
|
+
return factory(entry, ctx);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return registry;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Postgres target `ContractSerializer` concretion. Inherits the full
|
|
39
|
+
* SQL-family deserialization pipeline (structural validation +
|
|
40
|
+
* hydration walker that materialises the SQL Contract IR class
|
|
41
|
+
* hierarchy from the validated JSON envelope). Polymorphic
|
|
42
|
+
* `storage.types` entries hydrate through the pack contribution registry
|
|
43
|
+
* keyed by each entity type's declared `discriminator` (matching the
|
|
44
|
+
* enumerable `kind` on the persisted JSON envelope).
|
|
45
|
+
*
|
|
46
|
+
* `serializeContract` falls through to the family-base default —
|
|
47
|
+
* Postgres' contract is JSON-clean today (`PostgresEnumType`
|
|
48
|
+
* instances are frozen with enumerable own properties, so
|
|
49
|
+
* `JSON.stringify` produces the canonical envelope shape). Once
|
|
50
|
+
* target-only fields land (e.g. per-target derived storage fields)
|
|
51
|
+
* this is the home for stripping them from the persisted envelope.
|
|
52
|
+
*/
|
|
53
|
+
var PostgresContractSerializer = class extends SqlContractSerializerBase {
|
|
54
|
+
constructor() {
|
|
55
|
+
super(buildPostgresEntityTypeRegistry());
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
//#endregion
|
|
59
|
+
export { PostgresContractSerializer as t };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=postgres-contract-serializer-D5VJk6lo.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-contract-serializer-D5VJk6lo.mjs","names":[],"sources":["../src/core/postgres-contract-serializer.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport {\n SqlContractSerializerBase,\n type SqlEntityHydrationFactory,\n} from '@prisma-next/family-sql/ir';\nimport type { AuthoringEntityContext } from '@prisma-next/framework-components/authoring';\nimport type { SqlStorage, SqlStorageTypeEntry } from '@prisma-next/sql-contract/types';\nimport { postgresAuthoringEntityTypes } from './authoring';\nimport { PostgresEnumType } from './postgres-enum-type';\n\n/**\n * Build the hydration registry from this target pack's literal\n * `postgresAuthoringEntityTypes`. Extension-pack-contributed entity\n * types do not reach this registry today; the surface is honest for\n * in-tree consumers (Postgres pack only) and the slot stays\n * deserializable because the family-layer validator's\n * `StorageTypeEntrySchema` only admits kinds whose factory the\n * Postgres pack already ships.\n *\n * Future open (F14): lift the registry build to descriptor-composition\n * time, threading the composed `AuthoringContributions.entityTypes`\n * from extension packs, so a real extension pack shipping a\n * round-trip-needing entity type can be deserialized end-to-end.\n * Earned by the first such extension pack in tree.\n */\nfunction buildPostgresEntityTypeRegistry(): ReadonlyMap<string, SqlEntityHydrationFactory> {\n const ctx: AuthoringEntityContext = { family: 'sql', target: 'postgres' };\n const registry = new Map<string, SqlEntityHydrationFactory>();\n for (const descriptor of Object.values(postgresAuthoringEntityTypes)) {\n if (descriptor.kind !== 'entity') {\n continue;\n }\n if (!('factory' in descriptor.output)) {\n continue;\n }\n const factory = descriptor.output.factory as (\n input: never,\n ctx: AuthoringEntityContext,\n ) => SqlStorageTypeEntry;\n registry.set(descriptor.discriminator, (entry) => {\n if (entry instanceof PostgresEnumType) {\n return entry;\n }\n return factory(entry as never, ctx);\n });\n }\n return registry;\n}\n\n/**\n * Postgres target `ContractSerializer` concretion. Inherits the full\n * SQL-family deserialization pipeline (structural validation +\n * hydration walker that materialises the SQL Contract IR class\n * hierarchy from the validated JSON envelope). Polymorphic\n * `storage.types` entries hydrate through the pack contribution registry\n * keyed by each entity type's declared `discriminator` (matching the\n * enumerable `kind` on the persisted JSON envelope).\n *\n * `serializeContract` falls through to the family-base default —\n * Postgres' contract is JSON-clean today (`PostgresEnumType`\n * instances are frozen with enumerable own properties, so\n * `JSON.stringify` produces the canonical envelope shape). Once\n * target-only fields land (e.g. per-target derived storage fields)\n * this is the home for stripping them from the persisted envelope.\n */\nexport class PostgresContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {\n constructor() {\n super(buildPostgresEntityTypeRegistry());\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyBA,SAAS,kCAAkF;CACzF,MAAM,MAA8B;EAAE,QAAQ;EAAO,QAAQ;EAAY;CACzE,MAAM,2BAAW,IAAI,KAAwC;CAC7D,KAAK,MAAM,cAAc,OAAO,OAAO,6BAA6B,EAAE;EACpE,IAAI,WAAW,SAAS,UACtB;EAEF,IAAI,EAAE,aAAa,WAAW,SAC5B;EAEF,MAAM,UAAU,WAAW,OAAO;EAIlC,SAAS,IAAI,WAAW,gBAAgB,UAAU;GAChD,IAAI,iBAAiB,kBACnB,OAAO;GAET,OAAO,QAAQ,OAAgB,IAAI;IACnC;;CAEJ,OAAO;;;;;;;;;;;;;;;;;;AAmBT,IAAa,6BAAb,cAAgD,0BAAgD;CAC9F,cAAc;EACZ,MAAM,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { SqlNode } from "@prisma-next/sql-contract/types";
|
|
2
|
+
|
|
3
|
+
//#region src/core/postgres-enum-type.d.ts
|
|
4
|
+
interface PostgresEnumTypeInput<TName extends string = string, TValues extends readonly string[] = readonly string[]> {
|
|
5
|
+
/**
|
|
6
|
+
* Contract-level enum name (e.g. `'Role'`). Used as the key in
|
|
7
|
+
* `SqlStorage.types` and as the contract-facing identifier in
|
|
8
|
+
* planner / verifier diagnostics.
|
|
9
|
+
*/
|
|
10
|
+
readonly name: TName;
|
|
11
|
+
/**
|
|
12
|
+
* Postgres-side native type name created by `CREATE TYPE … AS ENUM`.
|
|
13
|
+
* Defaults to `name` when not overridden via PSL `@map(...)` or the
|
|
14
|
+
* TS authoring surface.
|
|
15
|
+
*/
|
|
16
|
+
readonly nativeType?: string;
|
|
17
|
+
readonly values: TValues;
|
|
18
|
+
}
|
|
19
|
+
/** Codec id used by Postgres enum-typed columns (text wire format). */
|
|
20
|
+
declare const PG_ENUM_CODEC_ID = "pg/enum@1";
|
|
21
|
+
/**
|
|
22
|
+
* Postgres IR class for the `CREATE TYPE … AS ENUM` concept.
|
|
23
|
+
*
|
|
24
|
+
* Per Decision 18, enum is a target-only concept (Postgres alone today;
|
|
25
|
+
* SQLite emulates via CHECK constraints). There is no family-layer
|
|
26
|
+
* enum abstract — the abstract-earns-existence rule keeps the IR class
|
|
27
|
+
* hierarchy minimal: this class extends `SqlNode` directly and is the
|
|
28
|
+
* single concrete representation of the polymorphic `'postgres-enum'`
|
|
29
|
+
* slot variant.
|
|
30
|
+
*
|
|
31
|
+
* Carries Postgres-specific resolution (`nativeType` defaults to
|
|
32
|
+
* `name`; `values` is frozen at construction time). Constructor calls
|
|
33
|
+
* `freezeNode(this)` per Decision 8 — the instance is fully immutable,
|
|
34
|
+
* JSON-clean, and dispatchable on its enumerable `kind: 'postgres-enum'`
|
|
35
|
+
* literal.
|
|
36
|
+
*
|
|
37
|
+
* The family-layer slot dispatch (verifier, planner, lowering, etc.)
|
|
38
|
+
* narrows polymorphic `StorageType` entries via the `kind` literal
|
|
39
|
+
* (e.g. `isPostgresEnumStorageEntry`) — SQL-domain code must not import
|
|
40
|
+
* `target-postgres` directly (cross-domain layering rule). The
|
|
41
|
+
* structural interface lives at the family layer for that purpose;
|
|
42
|
+
* this class is the runtime concrete that satisfies it.
|
|
43
|
+
*/
|
|
44
|
+
declare class PostgresEnumType<TName extends string = string, TValues extends readonly string[] = readonly string[]> extends SqlNode {
|
|
45
|
+
readonly kind: "postgres-enum";
|
|
46
|
+
readonly name: TName;
|
|
47
|
+
readonly nativeType: string;
|
|
48
|
+
readonly values: TValues;
|
|
49
|
+
/**
|
|
50
|
+
* Enumerable own property so the persisted JSON envelope carries
|
|
51
|
+
* `codecId: 'pg/enum@1'` alongside `kind: 'postgres-enum'`. The
|
|
52
|
+
* runtime path (`codecRefForStorageColumn`, `assertColumnCodecIntegrity`)
|
|
53
|
+
* receives JSON-shaped contracts (e.g. inside a user-written
|
|
54
|
+
* `migration.ts` that loads `endContract` from `end-contract.json`)
|
|
55
|
+
* and reads `codecId` directly from the envelope rather than
|
|
56
|
+
* dispatching through the prototype-only `codecBinding` accessor.
|
|
57
|
+
*/
|
|
58
|
+
readonly codecId: typeof PG_ENUM_CODEC_ID;
|
|
59
|
+
constructor(input: PostgresEnumTypeInput<TName, TValues>);
|
|
60
|
+
get codecBinding(): {
|
|
61
|
+
readonly codecId: typeof PG_ENUM_CODEC_ID;
|
|
62
|
+
readonly typeParams: {
|
|
63
|
+
readonly values: TValues;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { PostgresEnumTypeInput as n, PostgresEnumType as t };
|
|
69
|
+
//# sourceMappingURL=postgres-enum-type-CrKq8au9.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-enum-type-CrKq8au9.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,OAAA;AAAA;AAClB;AAAA,cAGK,gBAAA;;;;AAyBN;;;;;;;;;;;;;;;;;;;;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"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { freezeNode } from "@prisma-next/framework-components/ir";
|
|
2
|
+
import { SqlNode } from "@prisma-next/sql-contract/types";
|
|
3
|
+
//#region src/core/postgres-enum-type.ts
|
|
4
|
+
/** Codec id used by Postgres enum-typed columns (text wire format). */
|
|
5
|
+
const PG_ENUM_CODEC_ID = "pg/enum@1";
|
|
6
|
+
/**
|
|
7
|
+
* Postgres IR class for the `CREATE TYPE … AS ENUM` concept.
|
|
8
|
+
*
|
|
9
|
+
* Per Decision 18, enum is a target-only concept (Postgres alone today;
|
|
10
|
+
* SQLite emulates via CHECK constraints). There is no family-layer
|
|
11
|
+
* enum abstract — the abstract-earns-existence rule keeps the IR class
|
|
12
|
+
* hierarchy minimal: this class extends `SqlNode` directly and is the
|
|
13
|
+
* single concrete representation of the polymorphic `'postgres-enum'`
|
|
14
|
+
* slot variant.
|
|
15
|
+
*
|
|
16
|
+
* Carries Postgres-specific resolution (`nativeType` defaults to
|
|
17
|
+
* `name`; `values` is frozen at construction time). Constructor calls
|
|
18
|
+
* `freezeNode(this)` per Decision 8 — the instance is fully immutable,
|
|
19
|
+
* JSON-clean, and dispatchable on its enumerable `kind: 'postgres-enum'`
|
|
20
|
+
* literal.
|
|
21
|
+
*
|
|
22
|
+
* The family-layer slot dispatch (verifier, planner, lowering, etc.)
|
|
23
|
+
* narrows polymorphic `StorageType` entries via the `kind` literal
|
|
24
|
+
* (e.g. `isPostgresEnumStorageEntry`) — SQL-domain code must not import
|
|
25
|
+
* `target-postgres` directly (cross-domain layering rule). The
|
|
26
|
+
* structural interface lives at the family layer for that purpose;
|
|
27
|
+
* this class is the runtime concrete that satisfies it.
|
|
28
|
+
*/
|
|
29
|
+
var PostgresEnumType = class extends SqlNode {
|
|
30
|
+
kind = "postgres-enum";
|
|
31
|
+
name;
|
|
32
|
+
nativeType;
|
|
33
|
+
values;
|
|
34
|
+
/**
|
|
35
|
+
* Enumerable own property so the persisted JSON envelope carries
|
|
36
|
+
* `codecId: 'pg/enum@1'` alongside `kind: 'postgres-enum'`. The
|
|
37
|
+
* runtime path (`codecRefForStorageColumn`, `assertColumnCodecIntegrity`)
|
|
38
|
+
* receives JSON-shaped contracts (e.g. inside a user-written
|
|
39
|
+
* `migration.ts` that loads `endContract` from `end-contract.json`)
|
|
40
|
+
* and reads `codecId` directly from the envelope rather than
|
|
41
|
+
* dispatching through the prototype-only `codecBinding` accessor.
|
|
42
|
+
*/
|
|
43
|
+
codecId = PG_ENUM_CODEC_ID;
|
|
44
|
+
constructor(input) {
|
|
45
|
+
super();
|
|
46
|
+
this.name = input.name;
|
|
47
|
+
this.nativeType = input.nativeType ?? input.name;
|
|
48
|
+
this.values = Object.freeze([...input.values]);
|
|
49
|
+
freezeNode(this);
|
|
50
|
+
}
|
|
51
|
+
get codecBinding() {
|
|
52
|
+
return {
|
|
53
|
+
codecId: PG_ENUM_CODEC_ID,
|
|
54
|
+
typeParams: { values: this.values }
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
//#endregion
|
|
59
|
+
export { PostgresEnumType as t };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=postgres-enum-type-DS-KLVRH.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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,OAAO;EACP,KAAK,OAAO,MAAM;EAClB,KAAK,aAAa,MAAM,cAAc,MAAM;EAI5C,KAAK,SAAS,OAAO,OAAO,CAAC,GAAG,MAAM,OAAO,CAAuB;EACpE,WAAW,KAAK;;CAGlB,IAAI,eAGF;EACA,OAAO;GAAE,SAAS;GAAkB,YAAY,EAAE,QAAQ,KAAK,QAAQ;GAAE"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as PostgresPlanTargetDetails } from "./planner-target-details-
|
|
2
|
-
import { n as DataTransformOptions } from "./data-transform-
|
|
1
|
+
import { t as PostgresPlanTargetDetails } from "./planner-target-details-iYJwzFHP.mjs";
|
|
2
|
+
import { n as DataTransformOptions } from "./data-transform-B6p02mFJ.mjs";
|
|
3
3
|
import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
|
|
4
|
+
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
|
4
5
|
import { Migration } from "@prisma-next/family-sql/migration";
|
|
5
6
|
import { ControlStack } from "@prisma-next/framework-components/control";
|
|
6
7
|
import { Contract } from "@prisma-next/contract/types";
|
|
7
|
-
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
|
8
8
|
import { SqlControlAdapter } from "@prisma-next/family-sql/control-adapter";
|
|
9
9
|
|
|
10
10
|
//#region src/core/migrations/postgres-migration.d.ts
|
|
@@ -47,4 +47,4 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
|
|
|
47
47
|
}
|
|
48
48
|
//#endregion
|
|
49
49
|
export { PostgresMigration as t };
|
|
50
|
-
//# sourceMappingURL=postgres-migration-
|
|
50
|
+
//# sourceMappingURL=postgres-migration-CiQzhcMe.d.mts.map
|
package/dist/{postgres-migration-UkcHfZAA.d.mts.map → postgres-migration-CiQzhcMe.d.mts.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-migration-
|
|
1
|
+
{"version":3,"file":"postgres-migration-CiQzhcMe.d.mts","names":[],"sources":["../src/core/migrations/postgres-migration.ts"],"mappings":";;;;;;;;;;;;AA8BA;;;;;;;;;;;;;;;;;;uBAAsB,iBAAA,SAA0B,SAAA,CAC9C,yBAAA;EAAA,SAGS,QAAA;;;;;;;qBAQU,cAAA,EAAgB,iBAAA;cAEvB,KAAA,GAAQ,YAAA;EAgBlB;;;;;EAAA,UADQ,aAAA,mBAAgC,QAAA,CAAS,UAAA,EAAA,CACjD,QAAA,EAAU,SAAA,EACV,IAAA,UACA,OAAA,EAAS,oBAAA,GACR,yBAAA,CAA0B,yBAAA;AAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as errorPostgresMigrationStackMissing } from "./errors-
|
|
2
|
-
import { t as dataTransform } from "./data-transform-
|
|
1
|
+
import { t as errorPostgresMigrationStackMissing } from "./errors-BiOloWUh.mjs";
|
|
2
|
+
import { t as dataTransform } from "./data-transform-aF9az88u.mjs";
|
|
3
3
|
import { Migration } from "@prisma-next/family-sql/migration";
|
|
4
4
|
//#region src/core/migrations/postgres-migration.ts
|
|
5
5
|
/**
|
|
@@ -48,4 +48,4 @@ var PostgresMigration = class extends Migration {
|
|
|
48
48
|
//#endregion
|
|
49
49
|
export { PostgresMigration as t };
|
|
50
50
|
|
|
51
|
-
//# sourceMappingURL=postgres-migration-
|
|
51
|
+
//# sourceMappingURL=postgres-migration-Fdxzo6l2.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-migration-
|
|
1
|
+
{"version":3,"file":"postgres-migration-Fdxzo6l2.mjs","names":["SqlMigration"],"sources":["../src/core/migrations/postgres-migration.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport { Migration as SqlMigration } from '@prisma-next/family-sql/migration';\nimport type { ControlStack } from '@prisma-next/framework-components/control';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport { errorPostgresMigrationStackMissing } from '../errors';\nimport { type DataTransformOptions, dataTransform } from './operations/data-transform';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\n/**\n * Target-owned base class for Postgres migrations.\n *\n * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the\n * abstract `targetId` to the Postgres target-id string literal, so both\n * user-authored migrations and renderer-generated scaffolds (the output of\n * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without\n * redeclaring target-local identity.\n *\n * Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer\n * emits `extends Migration` against a target-specific re-export of this\n * class from `@prisma-next/target-postgres/migration`, keeping the\n * authoring surface target-scoped rather than family-scoped.\n *\n * The constructor materializes a single Postgres `SqlControlAdapter` from\n * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`\n * instance method forwards to the free `dataTransform` factory with that\n * stored adapter, so user migrations can write `this.dataTransform(...)`\n * without threading the adapter through every call.\n */\nexport abstract class PostgresMigration extends SqlMigration<\n PostgresPlanTargetDetails,\n 'postgres'\n> {\n readonly targetId = 'postgres' as const;\n\n /**\n * Materialized Postgres control adapter, created once per migration\n * instance from the injected stack. `undefined` only when the migration\n * was instantiated without a stack (test fixtures); `dataTransform`\n * throws in that case to surface the misuse.\n */\n protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;\n\n constructor(stack?: ControlStack<'sql', 'postgres'>) {\n super(stack);\n // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;\n // the Postgres descriptor concretely returns a `SqlControlAdapter<'postgres'>`,\n // so the cast holds for any Postgres-target stack assembled at runtime.\n this.controlAdapter = stack?.adapter\n ? (stack.adapter.create(stack) as SqlControlAdapter<'postgres'>)\n : undefined;\n }\n\n /**\n * Instance-method wrapper around the free `dataTransform` factory that\n * supplies the stored control adapter. Authors call this from inside\n * `get operations()`; the adapter argument is hidden from the call site.\n */\n protected dataTransform<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n name: string,\n options: DataTransformOptions,\n ): SqlMigrationPlanOperation<PostgresPlanTargetDetails> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return dataTransform(contract, name, options, this.controlAdapter);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAsB,oBAAtB,cAAgDA,UAG9C;CACA,WAAoB;;;;;;;CAQpB;CAEA,YAAY,OAAyC;EACnD,MAAM,MAAM;EAIZ,KAAK,iBAAiB,OAAO,UACxB,MAAM,QAAQ,OAAO,MAAM,GAC5B,KAAA;;;;;;;CAQN,cACE,UACA,MACA,SACsD;EACtD,IAAI,CAAC,KAAK,gBACR,MAAM,oCAAoC;EAE5C,OAAO,cAAc,UAAU,MAAM,SAAS,KAAK,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-ops
|
|
1
|
+
{"version":3,"file":"render-ops-CkiuHSNj.mjs","names":[],"sources":["../src/core/migrations/render-ops.ts"],"sourcesContent":["import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { OpFactoryCall } from '@prisma-next/framework-components/control';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\ntype Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\n/**\n * Asserts an op materialised by an `OpFactoryCall` targets postgres. The\n * extension surface lets any contributor emit calls, so this is the\n * integration boundary where a stray non-postgres op would otherwise\n * silently flow through to postgres-shaped renderers — exactly the\n * place to fail loudly with op metadata (`id` + `target.id`).\n */\nfunction assertPostgresOp(\n op: ReturnType<OpFactoryCall['toOp']>,\n callFactoryName: string,\n): asserts op is Op {\n const targetId = (op as Partial<Op>).target?.id;\n if (targetId !== 'postgres') {\n throw new Error(\n `renderOps: expected postgres op but got target.id=\"${String(targetId)}\" for op.id=\"${op.id}\" (factoryName=\"${callFactoryName}\"). An OpFactoryCall produced an op for a different target on the postgres planner path; check the call's target binding.`,\n );\n }\n}\n\nexport function renderOps(calls: readonly OpFactoryCall[]): Op[] {\n return calls.map((c) => {\n const op = c.toOp();\n assertPostgresOp(op, c.factoryName);\n return op;\n });\n}\n"],"mappings":";;;;;;;;AAaA,SAAS,iBACP,IACA,iBACkB;CAClB,MAAM,WAAY,GAAmB,QAAQ;CAC7C,IAAI,aAAa,YACf,MAAM,IAAI,MACR,sDAAsD,OAAO,SAAS,CAAC,eAAe,GAAG,GAAG,kBAAkB,gBAAgB,2HAC/H;;AAIL,SAAgB,UAAU,OAAuC;CAC/D,OAAO,MAAM,KAAK,MAAM;EACtB,MAAM,KAAK,EAAE,MAAM;EACnB,iBAAiB,IAAI,EAAE,YAAY;EACnC,OAAO;GACP"}
|
package/dist/render-ops.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as PostgresPlanTargetDetails } from "./planner-target-details-
|
|
1
|
+
import { t as PostgresPlanTargetDetails } from "./planner-target-details-iYJwzFHP.mjs";
|
|
2
2
|
import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
|
|
3
3
|
import { OpFactoryCall } from "@prisma-next/framework-components/control";
|
|
4
4
|
|
package/dist/render-ops.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as renderOps } from "./render-ops
|
|
1
|
+
import { t as renderOps } from "./render-ops-CkiuHSNj.mjs";
|
|
2
2
|
export { renderOps };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-typescript-
|
|
1
|
+
{"version":3,"file":"render-typescript-C9XWI8Ld.mjs","names":[],"sources":["../src/core/migrations/render-typescript.ts"],"sourcesContent":["/**\n * Polymorphic TypeScript emitter for the Postgres migration IR.\n *\n * Each `OpFactoryCall` renders itself via `renderTypeScript()` and\n * declares its own `importRequirements()`; this file just composes the module\n * source around those contributions. The design mirrors the Mongo target's\n * `render-typescript.ts` deliberately — byte-for-byte alignment isn't required\n * (different factory module specifiers, different base-class name) but the\n * shape is, so future consolidation to a framework-level helper is mechanical.\n */\n\nimport type { OpFactoryCall } from '@prisma-next/framework-components/control';\nimport { detectScaffoldRuntime, shebangLineFor } from '@prisma-next/migration-tools/migration-ts';\nimport { type ImportRequirement, jsonToTsSource, renderImports } from '@prisma-next/ts-render';\n\nexport interface RenderMigrationMeta {\n readonly from: string | null;\n readonly to: string;\n readonly labels?: readonly string[];\n}\n\n/**\n * Always-present base imports for the rendered scaffold. Both come from\n * `@prisma-next/target-postgres/migration` so an authored Postgres\n * `migration.ts` only needs a single dependency for its base class and\n * its CLI entrypoint:\n *\n * - `Migration` — the target-owned re-export fixes the `SqlMigration`\n * generic to `PostgresPlanTargetDetails` and the abstract `targetId`\n * to `'postgres'`, so user-authored migrations don't need to thread\n * target-details or redeclare `targetId`.\n * - `MigrationCLI` — the migration-file CLI entrypoint, re-exported from\n * `@prisma-next/cli/migration-cli`. Loads `prisma-next.config.ts`,\n * assembles a `ControlStack`, and instantiates the migration class.\n * The migration file owns this dependency directly: pulling CLI\n * machinery in at script run time is acceptable because the script's\n * whole purpose is to be invoked from the project that owns the\n * config.\n */\nconst BASE_IMPORTS: readonly ImportRequirement[] = [\n { moduleSpecifier: '@prisma-next/target-postgres/migration', symbol: 'Migration' },\n { moduleSpecifier: '@prisma-next/target-postgres/migration', symbol: 'MigrationCLI' },\n];\n\nexport function renderCallsToTypeScript(\n calls: ReadonlyArray<OpFactoryCall>,\n meta: RenderMigrationMeta,\n): string {\n const imports = buildImports(calls);\n const operationsBody = calls.map((c) => c.renderTypeScript()).join(',\\n');\n\n return [\n shebangLineFor(detectScaffoldRuntime()),\n imports,\n '',\n 'export default class M extends Migration {',\n buildDescribeMethod(meta),\n ' override get operations() {',\n ' return [',\n indent(operationsBody, 6),\n ' ];',\n ' }',\n '}',\n '',\n 'MigrationCLI.run(import.meta.url, M);',\n '',\n ].join('\\n');\n}\n\nfunction buildImports(calls: ReadonlyArray<OpFactoryCall>): string {\n const requirements: ImportRequirement[] = [...BASE_IMPORTS];\n for (const call of calls) {\n for (const req of call.importRequirements()) {\n requirements.push(req);\n }\n }\n return renderImports(requirements);\n}\n\nfunction buildDescribeMethod(meta: RenderMigrationMeta): string {\n const lines: string[] = [];\n lines.push(' override describe() {');\n lines.push(' return {');\n lines.push(` from: ${JSON.stringify(meta.from)},`);\n lines.push(` to: ${JSON.stringify(meta.to)},`);\n if (meta.labels && meta.labels.length > 0) {\n lines.push(` labels: ${jsonToTsSource(meta.labels)},`);\n }\n lines.push(' };');\n lines.push(' }');\n lines.push('');\n return lines.join('\\n');\n}\n\nfunction indent(text: string, spaces: number): string {\n const pad = ' '.repeat(spaces);\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${pad}${line}` : line))\n .join('\\n');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuCA,MAAM,eAA6C,CACjD;CAAE,iBAAiB;CAA0C,QAAQ;CAAa,EAClF;CAAE,iBAAiB;CAA0C,QAAQ;CAAgB,CACtF;AAED,SAAgB,wBACd,OACA,MACQ;CACR,MAAM,UAAU,aAAa,MAAM;CACnC,MAAM,iBAAiB,MAAM,KAAK,MAAM,EAAE,kBAAkB,CAAC,CAAC,KAAK,MAAM;CAEzE,OAAO;EACL,eAAe,uBAAuB,CAAC;EACvC;EACA;EACA;EACA,oBAAoB,KAAK;EACzB;EACA;EACA,OAAO,gBAAgB,EAAE;EACzB;EACA;EACA;EACA;EACA;EACA;EACD,CAAC,KAAK,KAAK;;AAGd,SAAS,aAAa,OAA6C;CACjE,MAAM,eAAoC,CAAC,GAAG,aAAa;CAC3D,KAAK,MAAM,QAAQ,OACjB,KAAK,MAAM,OAAO,KAAK,oBAAoB,EACzC,aAAa,KAAK,IAAI;CAG1B,OAAO,cAAc,aAAa;;AAGpC,SAAS,oBAAoB,MAAmC;CAC9D,MAAM,QAAkB,EAAE;CAC1B,MAAM,KAAK,0BAA0B;CACrC,MAAM,KAAK,eAAe;CAC1B,MAAM,KAAK,eAAe,KAAK,UAAU,KAAK,KAAK,CAAC,GAAG;CACvD,MAAM,KAAK,aAAa,KAAK,UAAU,KAAK,GAAG,CAAC,GAAG;CACnD,IAAI,KAAK,UAAU,KAAK,OAAO,SAAS,GACtC,MAAM,KAAK,iBAAiB,eAAe,KAAK,OAAO,CAAC,GAAG;CAE7D,MAAM,KAAK,SAAS;CACpB,MAAM,KAAK,MAAM;CACjB,MAAM,KAAK,GAAG;CACd,OAAO,MAAM,KAAK,KAAK;;AAGzB,SAAS,OAAO,MAAc,QAAwB;CACpD,MAAM,MAAM,IAAI,OAAO,OAAO;CAC9B,OAAO,KACJ,MAAM,KAAK,CACX,KAAK,SAAU,KAAK,MAAM,GAAG,GAAG,MAAM,SAAS,KAAM,CACrD,KAAK,KAAK"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as renderCallsToTypeScript } from "./render-typescript-
|
|
1
|
+
import { t as renderCallsToTypeScript } from "./render-typescript-C9XWI8Ld.mjs";
|
|
2
2
|
export { renderCallsToTypeScript };
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
import { AnyCodecDescriptor } from "@prisma-next/framework-components/codec";
|
|
2
|
+
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
|
3
|
+
import { SqlContractSerializerBase } from "@prisma-next/family-sql/ir";
|
|
4
|
+
import { Contract } from "@prisma-next/contract/types";
|
|
2
5
|
import { RuntimeTargetDescriptor, RuntimeTargetInstance } from "@prisma-next/framework-components/execution";
|
|
3
6
|
|
|
7
|
+
//#region src/core/postgres-contract-serializer.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Postgres target `ContractSerializer` concretion. Inherits the full
|
|
10
|
+
* SQL-family deserialization pipeline (structural validation +
|
|
11
|
+
* hydration walker that materialises the SQL Contract IR class
|
|
12
|
+
* hierarchy from the validated JSON envelope). Polymorphic
|
|
13
|
+
* `storage.types` entries hydrate through the pack contribution registry
|
|
14
|
+
* keyed by each entity type's declared `discriminator` (matching the
|
|
15
|
+
* enumerable `kind` on the persisted JSON envelope).
|
|
16
|
+
*
|
|
17
|
+
* `serializeContract` falls through to the family-base default —
|
|
18
|
+
* Postgres' contract is JSON-clean today (`PostgresEnumType`
|
|
19
|
+
* instances are frozen with enumerable own properties, so
|
|
20
|
+
* `JSON.stringify` produces the canonical envelope shape). Once
|
|
21
|
+
* target-only fields land (e.g. per-target derived storage fields)
|
|
22
|
+
* this is the home for stripping them from the persisted envelope.
|
|
23
|
+
*/
|
|
24
|
+
declare class PostgresContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {
|
|
25
|
+
constructor();
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
4
28
|
//#region src/exports/runtime.d.ts
|
|
5
29
|
interface PostgresRuntimeTargetInstance extends RuntimeTargetInstance<'sql', 'postgres'> {}
|
|
6
30
|
/**
|
|
@@ -13,5 +37,5 @@ declare const postgresRuntimeTargetDescriptor: RuntimeTargetDescriptor<'sql', 'p
|
|
|
13
37
|
readonly codecs: () => readonly AnyCodecDescriptor[];
|
|
14
38
|
};
|
|
15
39
|
//#endregion
|
|
16
|
-
export { PostgresRuntimeTargetInstance, postgresRuntimeTargetDescriptor as default };
|
|
40
|
+
export { PostgresContractSerializer, PostgresRuntimeTargetInstance, postgresRuntimeTargetDescriptor as default };
|
|
17
41
|
//# sourceMappingURL=runtime.d.mts.map
|
package/dist/runtime.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/core/postgres-contract-serializer.ts","../src/exports/runtime.ts"],"mappings":";;;;;;;;;;;AAiEA;;;;;;;;;;;;cAAa,0BAAA,SAAmC,yBAAA,CAA0B,QAAA,CAAS,UAAA;;;;;UCxDlE,6BAAA,SAAsC,qBAAA;;;ADwDvD;;;;cChDM,+BAAA,EAAiC,uBAAA,oBAGrC,6BAAA;EAAA,SAES,MAAA,iBAAuB,kBAAA;AAAA"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-
|
|
1
|
+
import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-DFUCClk_.mjs";
|
|
2
|
+
import { t as PostgresContractSerializer } from "./postgres-contract-serializer-D5VJk6lo.mjs";
|
|
2
3
|
//#region src/exports/runtime.ts
|
|
3
4
|
/**
|
|
4
5
|
* Target-postgres deliberately does NOT import `SqlRuntimeTargetDescriptor` from `@prisma-next/sql-runtime`. The target package is a control-plane residence and must not pull the SQL execution-plane package into its dependency closure. The runtime descriptor here is shaped to satisfy the framework's `RuntimeTargetDescriptor` plus the structural `SqlStaticContributions` (`codecs:` returning a descriptor list) that
|
|
@@ -17,6 +18,6 @@ const postgresRuntimeTargetDescriptor = {
|
|
|
17
18
|
}
|
|
18
19
|
};
|
|
19
20
|
//#endregion
|
|
20
|
-
export { postgresRuntimeTargetDescriptor as default };
|
|
21
|
+
export { PostgresContractSerializer, postgresRuntimeTargetDescriptor as default };
|
|
21
22
|
|
|
22
23
|
//# sourceMappingURL=runtime.mjs.map
|
package/dist/runtime.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":["import type { AnyCodecDescriptor } from '@prisma-next/framework-components/codec';\nimport type {\n RuntimeTargetDescriptor,\n RuntimeTargetInstance,\n} from '@prisma-next/framework-components/execution';\nimport { postgresTargetDescriptorMeta } from '../core/descriptor-meta';\n\nexport interface PostgresRuntimeTargetInstance extends RuntimeTargetInstance<'sql', 'postgres'> {}\n\n/**\n * Target-postgres deliberately does NOT import `SqlRuntimeTargetDescriptor` from `@prisma-next/sql-runtime`. The target package is a control-plane residence and must not pull the SQL execution-plane package into its dependency closure. The runtime descriptor here is shaped to satisfy the framework's `RuntimeTargetDescriptor` plus the structural `SqlStaticContributions` (`codecs:` returning a descriptor list) that\n * `@prisma-next/sql-runtime` consumers narrow to at composition time.\n *\n * The target itself contributes no codecs — postgres-specific codecs ship from the postgres adapter and from extension packs (pgvector, arktype-json, etc.).\n */\nconst postgresRuntimeTargetDescriptor: RuntimeTargetDescriptor<\n 'sql',\n 'postgres',\n PostgresRuntimeTargetInstance\n> & {\n readonly codecs: () => readonly AnyCodecDescriptor[];\n} = {\n ...postgresTargetDescriptorMeta,\n codecs: () => [],\n create(): PostgresRuntimeTargetInstance {\n return {\n familyId: 'sql',\n targetId: 'postgres',\n };\n },\n};\n\nexport default postgresRuntimeTargetDescriptor;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":["import type { AnyCodecDescriptor } from '@prisma-next/framework-components/codec';\nimport type {\n RuntimeTargetDescriptor,\n RuntimeTargetInstance,\n} from '@prisma-next/framework-components/execution';\nimport { postgresTargetDescriptorMeta } from '../core/descriptor-meta';\n\nexport { PostgresContractSerializer } from '../core/postgres-contract-serializer';\n\nexport interface PostgresRuntimeTargetInstance extends RuntimeTargetInstance<'sql', 'postgres'> {}\n\n/**\n * Target-postgres deliberately does NOT import `SqlRuntimeTargetDescriptor` from `@prisma-next/sql-runtime`. The target package is a control-plane residence and must not pull the SQL execution-plane package into its dependency closure. The runtime descriptor here is shaped to satisfy the framework's `RuntimeTargetDescriptor` plus the structural `SqlStaticContributions` (`codecs:` returning a descriptor list) that\n * `@prisma-next/sql-runtime` consumers narrow to at composition time.\n *\n * The target itself contributes no codecs — postgres-specific codecs ship from the postgres adapter and from extension packs (pgvector, arktype-json, etc.).\n */\nconst postgresRuntimeTargetDescriptor: RuntimeTargetDescriptor<\n 'sql',\n 'postgres',\n PostgresRuntimeTargetInstance\n> & {\n readonly codecs: () => readonly AnyCodecDescriptor[];\n} = {\n ...postgresTargetDescriptorMeta,\n codecs: () => [],\n create(): PostgresRuntimeTargetInstance {\n return {\n familyId: 'sql',\n targetId: 'postgres',\n };\n },\n};\n\nexport default postgresRuntimeTargetDescriptor;\n"],"mappings":";;;;;;;;;AAiBA,MAAM,kCAMF;CACF,GAAG;CACH,cAAc,EAAE;CAChB,SAAwC;EACtC,OAAO;GACL,UAAU;GACV,UAAU;GACX;;CAEJ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as PostgresPlanTargetDetails } from "./planner-target-details-
|
|
1
|
+
import { t as PostgresPlanTargetDetails } from "./planner-target-details-iYJwzFHP.mjs";
|
|
2
2
|
import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
|
|
3
3
|
import { ReferentialAction } from "@prisma-next/sql-contract/types";
|
|
4
4
|
|
|
@@ -38,4 +38,4 @@ interface ForeignKeySpec {
|
|
|
38
38
|
}
|
|
39
39
|
//#endregion
|
|
40
40
|
export { ForeignKeySpec as n, Op as r, ColumnSpec as t };
|
|
41
|
-
//# sourceMappingURL=shared-
|
|
41
|
+
//# sourceMappingURL=shared-DLYdmYo-.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-
|
|
1
|
+
{"version":3,"file":"shared-DLYdmYo-.d.mts","names":[],"sources":["../src/core/migrations/operations/shared.ts"],"mappings":";;;;;KAMY,EAAA,GAAK,yBAAA,CAA0B,yBAAA;;AAA3C;;;;;AAcA;;;;;;UAAiB,UAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA;EAAA,SACA,QAAA;AAAA;;;;;UAOM,cAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA;IAAA,SACE,KAAA;IAAA,SACA,OAAA;EAAA;EAAA,SAEF,QAAA,GAAW,iBAAA;EAAA,SACX,QAAA,GAAW,iBAAA;AAAA"}
|
|
@@ -75,4 +75,4 @@ function validateEnumValueLength(value, enumTypeName) {
|
|
|
75
75
|
//#endregion
|
|
76
76
|
export { validateEnumValueLength as a, quoteIdentifier as i, escapeLiteral as n, qualifyName as r, SqlEscapeError as t };
|
|
77
77
|
|
|
78
|
-
//# sourceMappingURL=sql-utils-
|
|
78
|
+
//# sourceMappingURL=sql-utils-BewXAnsG.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-utils-
|
|
1
|
+
{"version":3,"file":"sql-utils-BewXAnsG.mjs","names":[],"sources":["../src/core/sql-utils.ts"],"sourcesContent":["/**\n * Shared SQL utility functions for the Postgres target.\n *\n * These functions handle safe SQL identifier and literal escaping\n * with security validations to prevent injection and encoding issues.\n *\n * They live in `target-postgres` because both the control adapter (used at\n * emit time) and the runtime adapter (used at execute time) need the same\n * escaping/validation behavior, and the target package is the natural shared\n * home that both adapters can depend on without crossing planes.\n */\n\nexport class SqlEscapeError extends Error {\n constructor(\n message: string,\n public readonly value: string,\n public readonly kind: 'identifier' | 'literal',\n ) {\n super(message);\n this.name = 'SqlEscapeError';\n }\n}\n\nconst MAX_IDENTIFIER_LENGTH = 63;\n\n/**\n * Validates and quotes a PostgreSQL identifier (table, column, type, schema names).\n *\n * Security validations:\n * - Rejects null bytes which could cause truncation or unexpected behavior\n * - Rejects empty identifiers\n * - Warns on identifiers exceeding PostgreSQL's 63-character limit\n *\n * @throws {SqlEscapeError} If the identifier contains null bytes or is empty\n */\nexport function quoteIdentifier(identifier: string): string {\n if (identifier.length === 0) {\n throw new SqlEscapeError('Identifier cannot be empty', identifier, 'identifier');\n }\n if (identifier.includes('\\0')) {\n throw new SqlEscapeError(\n 'Identifier cannot contain null bytes',\n identifier.replace(/\\0/g, '\\\\0'),\n 'identifier',\n );\n }\n if (identifier.length > MAX_IDENTIFIER_LENGTH) {\n console.warn(\n `Identifier \"${identifier.slice(0, 20)}...\" exceeds PostgreSQL's ${MAX_IDENTIFIER_LENGTH}-character limit and will be truncated`,\n );\n }\n return `\"${identifier.replace(/\"/g, '\"\"')}\"`;\n}\n\n/**\n * Escapes a string literal for safe use in SQL statements.\n *\n * Security validations:\n * - Rejects null bytes which could cause truncation or unexpected behavior\n *\n * Note: This assumes PostgreSQL's `standard_conforming_strings` is ON (default since PG 9.1).\n * Backslashes are treated as literal characters, not escape sequences.\n *\n * @throws {SqlEscapeError} If the value contains null bytes\n */\nexport function escapeLiteral(value: string): string {\n if (value.includes('\\0')) {\n throw new SqlEscapeError(\n 'Literal value cannot contain null bytes',\n value.replace(/\\0/g, '\\\\0'),\n 'literal',\n );\n }\n return value.replace(/'/g, \"''\");\n}\n\n/**\n * Builds a qualified name (schema.object) with proper quoting.\n */\nexport function qualifyName(schemaName: string, objectName: string): string {\n return `${quoteIdentifier(schemaName)}.${quoteIdentifier(objectName)}`;\n}\n\n/**\n * Validates that an enum value doesn't exceed PostgreSQL's label length limit.\n *\n * PostgreSQL enum labels have a maximum length of NAMEDATALEN-1 (63 bytes by default).\n * Unlike identifiers, enum labels that exceed this limit cause an error rather than\n * silent truncation.\n *\n * @param value - The enum value to validate\n * @param enumTypeName - Name of the enum type (for error messages)\n * @throws {SqlEscapeError} If the value exceeds the maximum length\n */\nexport function validateEnumValueLength(value: string, enumTypeName: string): void {\n if (value.length > MAX_IDENTIFIER_LENGTH) {\n throw new SqlEscapeError(\n `Enum value \"${value.slice(0, 20)}...\" for type \"${enumTypeName}\" exceeds PostgreSQL's ` +\n `${MAX_IDENTIFIER_LENGTH}-character label limit`,\n value,\n 'literal',\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,iBAAb,cAAoC,MAAM;CAGtB;CACA;CAHlB,YACE,SACA,OACA,MACA;EACA,MAAM,QAAQ;EAHE,KAAA,QAAA;EACA,KAAA,OAAA;EAGhB,KAAK,OAAO;;;AAIhB,MAAM,wBAAwB;;;;;;;;;;;AAY9B,SAAgB,gBAAgB,YAA4B;CAC1D,IAAI,WAAW,WAAW,GACxB,MAAM,IAAI,eAAe,8BAA8B,YAAY,aAAa;CAElF,IAAI,WAAW,SAAS,KAAK,EAC3B,MAAM,IAAI,eACR,wCACA,WAAW,QAAQ,OAAO,MAAM,EAChC,aACD;CAEH,IAAI,WAAW,SAAS,uBACtB,QAAQ,KACN,eAAe,WAAW,MAAM,GAAG,GAAG,CAAC,4BAA4B,sBAAsB,wCAC1F;CAEH,OAAO,IAAI,WAAW,QAAQ,MAAM,OAAK,CAAC;;;;;;;;;;;;;AAc5C,SAAgB,cAAc,OAAuB;CACnD,IAAI,MAAM,SAAS,KAAK,EACtB,MAAM,IAAI,eACR,2CACA,MAAM,QAAQ,OAAO,MAAM,EAC3B,UACD;CAEH,OAAO,MAAM,QAAQ,MAAM,KAAK;;;;;AAMlC,SAAgB,YAAY,YAAoB,YAA4B;CAC1E,OAAO,GAAG,gBAAgB,WAAW,CAAC,GAAG,gBAAgB,WAAW;;;;;;;;;;;;;AActE,SAAgB,wBAAwB,OAAe,cAA4B;CACjF,IAAI,MAAM,SAAS,uBACjB,MAAM,IAAI,eACR,eAAe,MAAM,MAAM,GAAG,GAAG,CAAC,iBAAiB,aAAa,yBAC3D,sBAAsB,yBAC3B,OACA,UACD"}
|
package/dist/sql-utils.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as validateEnumValueLength, i as quoteIdentifier, n as escapeLiteral, r as qualifyName, t as SqlEscapeError } from "./sql-utils-
|
|
1
|
+
import { a as validateEnumValueLength, i as quoteIdentifier, n as escapeLiteral, r as qualifyName, t as SqlEscapeError } from "./sql-utils-BewXAnsG.mjs";
|
|
2
2
|
export { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier, validateEnumValueLength };
|
|
@@ -128,4 +128,4 @@ function jsonParam(value) {
|
|
|
128
128
|
//#endregion
|
|
129
129
|
export { ensureMarkerTableStatement as a, ensureLedgerTableStatement as i, buildLedgerInsertStatement as n, ensurePrismaContractSchemaStatement as o, buildMergeMarkerStatements as r, APP_SPACE_ID$1 as t };
|
|
130
130
|
|
|
131
|
-
//# sourceMappingURL=statement-builders-
|
|
131
|
+
//# sourceMappingURL=statement-builders-BSIQMClE.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statement-builders-
|
|
1
|
+
{"version":3,"file":"statement-builders-BSIQMClE.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 multi-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,EAAE;CACX;;;;;;;;;;AAWD,MAAa,6BAA2C;CACtD,KAAK;+CACwCA,eAAa;;;;;;;;;;CAU1D,QAAQ,EAAE;CACX;AAED,MAAa,6BAA2C;CACtD,KAAK;;;;;;;;;;;CAWL,QAAQ,EAAE;CACX;AA4BD,SAAgB,2BAA2B,OAGzC;CACA,MAAM,SAA6B;EACjC,MAAM;EACN,MAAM;EACN,MAAM;EACN,UAAU,MAAM,aAAa;EAC7B,MAAM,oBAAoB;EAC1B,MAAM,UAAU;EAChB,UAAU,MAAM,QAAQ,EAAE,CAAC;EAC3B,MAAM;EACP;CAED,OAAO;EACL,QAAQ;GACN,KAAK;;;;;;;;;;;;;;;;;;;;;GAqBL;GACD;EACD,QAAQ;GAKN,KAAK;;;;;;;;;;GAUL;GACD;EACF;;AAaH,SAAgB,2BAA2B,OAAwC;CACjF,OAAO;EACL,KAAK;;;;;;;;;;;;;;;;;EAiBL,QAAQ;GACN,MAAM,qBAAqB;GAC3B,MAAM,qBAAqB;GAC3B,MAAM;GACN,MAAM,0BAA0B;GAChC,UAAU,MAAM,mBAAmB;GACnC,UAAU,MAAM,kBAAkB;GAClC,UAAU,MAAM,WAAW;GAC5B;EACF;;AAGH,SAAS,UAAU,OAAwB;CACzC,OAAO,KAAK,UAAU,SAAS,KAAK"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as ensureMarkerTableStatement, i as ensureLedgerTableStatement, o as ensurePrismaContractSchemaStatement, r as buildMergeMarkerStatements, t as APP_SPACE_ID } from "./statement-builders-
|
|
1
|
+
import { a as ensureMarkerTableStatement, i as ensureLedgerTableStatement, o as ensurePrismaContractSchemaStatement, r as buildMergeMarkerStatements, t as APP_SPACE_ID } from "./statement-builders-BSIQMClE.mjs";
|
|
2
2
|
export { APP_SPACE_ID, buildMergeMarkerStatements, ensureLedgerTableStatement, ensureMarkerTableStatement, ensurePrismaContractSchemaStatement };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as quoteIdentifier, n as escapeLiteral, r as qualifyName } from "./sql-utils-
|
|
2
|
-
import { a as columnNullabilityCheck, c as qualifyTableName, d as toRegclassLiteral, n as columnDefaultExistsCheck, o as columnTypeCheck, r as columnExistsCheck, s as constraintExistsCheck } from "./planner-sql-checks-
|
|
1
|
+
import { i as quoteIdentifier, n as escapeLiteral, r as qualifyName } from "./sql-utils-BewXAnsG.mjs";
|
|
2
|
+
import { a as columnNullabilityCheck, c as qualifyTableName, d as toRegclassLiteral, n as columnDefaultExistsCheck, o as columnTypeCheck, r as columnExistsCheck, s as constraintExistsCheck } from "./planner-sql-checks-Cd016Ycs.mjs";
|
|
3
3
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
4
4
|
//#region src/core/migrations/operations/shared.ts
|
|
5
5
|
function step(description, sql) {
|
|
@@ -388,17 +388,17 @@ function enumTypeExistsCheck(schemaName, nativeType, exists = true) {
|
|
|
388
388
|
AND t.typname = '${escapeLiteral(nativeType)}'
|
|
389
389
|
)`;
|
|
390
390
|
}
|
|
391
|
-
function createEnumType(schemaName, typeName, values) {
|
|
392
|
-
const qualifiedType = qualifyName(schemaName,
|
|
391
|
+
function createEnumType(schemaName, typeName, values, nativeType = typeName) {
|
|
392
|
+
const qualifiedType = qualifyName(schemaName, nativeType);
|
|
393
393
|
const literalValues = values.map((v) => `'${escapeLiteral(v)}'`).join(", ");
|
|
394
394
|
return {
|
|
395
395
|
id: `type.${typeName}`,
|
|
396
396
|
label: `Create enum type "${typeName}"`,
|
|
397
397
|
operationClass: "additive",
|
|
398
398
|
target: targetDetails("type", typeName, schemaName),
|
|
399
|
-
precheck: [step(`ensure type "${
|
|
399
|
+
precheck: [step(`ensure type "${nativeType}" does not exist`, enumTypeExistsCheck(schemaName, nativeType, false))],
|
|
400
400
|
execute: [step(`create enum type "${typeName}"`, `CREATE TYPE ${qualifiedType} AS ENUM (${literalValues})`)],
|
|
401
|
-
postcheck: [step(`verify type "${
|
|
401
|
+
postcheck: [step(`verify type "${nativeType}" exists`, enumTypeExistsCheck(schemaName, nativeType))]
|
|
402
402
|
};
|
|
403
403
|
}
|
|
404
404
|
/**
|
|
@@ -513,4 +513,4 @@ function dropTable(schemaName, tableName) {
|
|
|
513
513
|
//#endregion
|
|
514
514
|
export { setNotNull as S, alterColumnType as _, addEnumValues as a, dropNotNull as b, renameType as c, installExtension as d, addForeignKey as f, addColumn as g, dropConstraint as h, dropIndex as i, createExtension as l, addUnique as m, dropTable as n, createEnumType as o, addPrimaryKey as p, createIndex as r, dropEnumType as s, createTable as t, createSchema as u, dropColumn as v, setDefault as x, dropDefault as y };
|
|
515
515
|
|
|
516
|
-
//# sourceMappingURL=tables-
|
|
516
|
+
//# sourceMappingURL=tables-Ce_Q0I8B.mjs.map
|