@prisma-next/family-sql 0.14.0-dev.9 → 0.14.0-dev.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{authoring-type-constructors-CjFfO6LM.mjs → authoring-type-constructors-CXd-8ydc.mjs} +7 -30
- package/dist/authoring-type-constructors-CXd-8ydc.mjs.map +1 -0
- package/dist/{control-adapter-Cmw9LvEP.d.mts → control-adapter-BQgad8Zc.d.mts} +30 -8
- package/dist/control-adapter-BQgad8Zc.d.mts.map +1 -0
- package/dist/control-adapter.d.mts +1 -1
- package/dist/control.d.mts +279 -34
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +378 -1005
- package/dist/control.mjs.map +1 -1
- package/dist/diff.d.mts +102 -0
- package/dist/diff.d.mts.map +1 -0
- package/dist/diff.mjs +14 -0
- package/dist/diff.mjs.map +1 -0
- package/dist/foreign-key-index-backing-BP71iI-Q.mjs +32 -0
- package/dist/foreign-key-index-backing-BP71iI-Q.mjs.map +1 -0
- package/dist/ir.d.mts +26 -9
- package/dist/ir.d.mts.map +1 -1
- package/dist/ir.mjs +2 -2
- package/dist/ir.mjs.map +1 -1
- package/dist/migration.d.mts +11 -2
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +7 -0
- package/dist/migration.mjs.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/psl-infer.d.mts +119 -0
- package/dist/psl-infer.d.mts.map +1 -0
- package/dist/psl-infer.mjs +366 -0
- package/dist/psl-infer.mjs.map +1 -0
- package/dist/schema-differ-DnoopSXm.d.mts +45 -0
- package/dist/schema-differ-DnoopSXm.d.mts.map +1 -0
- package/dist/schema-verify-W3r631Jh.mjs +226 -0
- package/dist/schema-verify-W3r631Jh.mjs.map +1 -0
- package/dist/{sql-contract-serializer-BR2vC7Z-.mjs → sql-contract-serializer-C75cfMSS.mjs} +46 -20
- package/dist/sql-contract-serializer-C75cfMSS.mjs.map +1 -0
- package/dist/{types-kgstZ_Zd.d.mts → types-BPv_y7iS.d.mts} +36 -142
- package/dist/types-BPv_y7iS.d.mts.map +1 -0
- package/package.json +26 -26
- package/src/core/authoring-entity-types.ts +12 -37
- package/src/core/control-adapter.ts +11 -5
- package/src/core/control-instance.ts +212 -42
- package/src/core/control-target-descriptor.ts +98 -0
- package/src/core/diff/schema-verify.ts +324 -0
- package/src/core/diff/sql-schema-diff.ts +41 -0
- package/src/core/diff/verifier-disposition.ts +30 -0
- package/src/core/foreign-key-index-backing.ts +37 -0
- package/src/core/ir/sql-contract-serializer-base.ts +70 -56
- package/src/core/ir/sql-contract-serializer.ts +5 -7
- package/src/core/ir/sql-schema-verifier-base.ts +5 -5
- package/src/core/migrations/contract-to-schema-ir.ts +141 -37
- package/src/core/migrations/control-policy.ts +66 -115
- package/src/core/migrations/field-event-planner.ts +2 -2
- package/src/core/migrations/native-type-expander.ts +28 -0
- package/src/core/migrations/schema-differ.ts +41 -0
- package/src/core/migrations/types.ts +33 -37
- package/src/core/psl-contract-infer/name-transforms.ts +15 -0
- package/src/core/psl-contract-infer/printer-config.ts +14 -6
- package/src/core/psl-contract-infer/relation-inference.ts +27 -1
- package/src/core/sql-migration.ts +12 -1
- package/src/exports/control.ts +12 -2
- package/src/exports/diff.ts +25 -0
- package/src/exports/psl-infer.ts +40 -0
- package/dist/authoring-type-constructors-CjFfO6LM.mjs.map +0 -1
- package/dist/control-adapter-Cmw9LvEP.d.mts.map +0 -1
- package/dist/schema-verify.d.mts +0 -39
- package/dist/schema-verify.d.mts.map +0 -1
- package/dist/schema-verify.mjs +0 -2
- package/dist/sql-contract-serializer-BR2vC7Z-.mjs.map +0 -1
- package/dist/test-utils.d.mts +0 -2
- package/dist/test-utils.mjs +0 -2
- package/dist/types-kgstZ_Zd.d.mts.map +0 -1
- package/dist/verify-sql-schema-thU-jKpf.d.mts +0 -66
- package/dist/verify-sql-schema-thU-jKpf.d.mts.map +0 -1
- package/dist/verify-sql-schema-xT4udQLQ.mjs +0 -1501
- package/dist/verify-sql-schema-xT4udQLQ.mjs.map +0 -1
- package/src/core/psl-contract-infer/postgres-default-mapping.ts +0 -16
- package/src/core/psl-contract-infer/postgres-type-map.ts +0 -157
- package/src/core/psl-contract-infer/sql-schema-ir-to-psl-ast.ts +0 -795
- package/src/core/schema-verify/control-verify-emit.ts +0 -46
- package/src/core/schema-verify/verifier-disposition.ts +0 -58
- package/src/core/schema-verify/verify-helpers.ts +0 -820
- package/src/core/schema-verify/verify-sql-schema.ts +0 -1311
- package/src/exports/schema-verify.ts +0 -18
- package/src/exports/test-utils.ts +0 -9
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';
|
|
2
|
+
import { extractCodecControlHooks } from '../assembly';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Builds the codec-hook-composed `expandNativeType` callback the contract→IR
|
|
6
|
+
* derivation uses to expand parameterized native types (e.g. `character` +
|
|
7
|
+
* `{ length: 36 }` → `character(36)`). Returns `undefined` when no framework
|
|
8
|
+
* components are supplied, so callers can omit the option entirely.
|
|
9
|
+
*/
|
|
10
|
+
export function buildNativeTypeExpander(
|
|
11
|
+
frameworkComponents?: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>,
|
|
12
|
+
) {
|
|
13
|
+
if (!frameworkComponents) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const codecHooks = extractCodecControlHooks(frameworkComponents);
|
|
17
|
+
return (input: {
|
|
18
|
+
readonly nativeType: string;
|
|
19
|
+
readonly codecId?: string;
|
|
20
|
+
readonly typeParams?: Record<string, unknown>;
|
|
21
|
+
}) => {
|
|
22
|
+
if (!input.typeParams) return input.nativeType;
|
|
23
|
+
if (!input.codecId) return input.nativeType;
|
|
24
|
+
const hooks = codecHooks.get(input.codecId);
|
|
25
|
+
if (!hooks?.expandNativeType) return input.nativeType;
|
|
26
|
+
return hooks.expandNativeType(input);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Contract, ControlPolicy } from '@prisma-next/contract/types';
|
|
2
|
+
import type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';
|
|
3
|
+
import type { SchemaDiffIssue } from '@prisma-next/framework-components/control';
|
|
4
|
+
import type { SqlStorage } from '@prisma-next/sql-contract/types';
|
|
5
|
+
import type { SqlSchemaIRNode } from '@prisma-next/sql-schema-ir/types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The full-tree node diff a SQL target produces for the family verify
|
|
9
|
+
* verdict: the target derives the expected tree from the contract, applies
|
|
10
|
+
* the pre-diff normalizations (semantic satisfaction, FK schema-segment
|
|
11
|
+
* resolution), runs the generic differ, and ownership-scopes the result.
|
|
12
|
+
* Strict gating, control-policy disposition, and the verdict itself are the
|
|
13
|
+
* family's post-diff filters over this output.
|
|
14
|
+
*/
|
|
15
|
+
export interface SqlSchemaDiffResult {
|
|
16
|
+
/** The full, ownership-scoped diff issue list. */
|
|
17
|
+
readonly issues: readonly SchemaDiffIssue[];
|
|
18
|
+
/**
|
|
19
|
+
* Resolves a diff issue's subject table's declared control policy directly
|
|
20
|
+
* from the contract (Decision 5's own-layer-per-concern discipline extends
|
|
21
|
+
* here too: control policy is a contract concern, resolved by the target
|
|
22
|
+
* at disposition time — never stamped on the diff node). `undefined`
|
|
23
|
+
* when the issue's path resolves to no contract table (a genuine orphan,
|
|
24
|
+
* or a non-table subject).
|
|
25
|
+
*/
|
|
26
|
+
readonly resolveControlPolicy: (issue: SchemaDiffIssue) => ControlPolicy | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* The expected/actual namespace-node pairs the codec `verifyType` hooks
|
|
29
|
+
* run over — one per contract namespace with tables, paired by DDL
|
|
30
|
+
* schema; a flat target repeats its sole actual root per such namespace.
|
|
31
|
+
*/
|
|
32
|
+
readonly namespacePairs: ReadonlyArray<{ readonly actual: SqlSchemaIRNode | undefined }>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SqlSchemaDiffInput {
|
|
36
|
+
readonly contract: Contract<SqlStorage>;
|
|
37
|
+
readonly schema: SqlSchemaIRNode;
|
|
38
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type SqlSchemaDiffFn = (input: SqlSchemaDiffInput) => SqlSchemaDiffResult;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { Contract } from '@prisma-next/contract/types';
|
|
2
2
|
import type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';
|
|
3
3
|
import type {
|
|
4
|
-
ContractSerializer,
|
|
5
4
|
ContractSpace,
|
|
6
5
|
ControlAdapterDescriptor,
|
|
7
6
|
ControlExtensionDescriptor,
|
|
8
|
-
MigratableTargetDescriptor,
|
|
9
7
|
MigrationOperationPolicy,
|
|
10
8
|
MigrationPlan,
|
|
11
9
|
MigrationPlannerConflict,
|
|
@@ -18,8 +16,8 @@ import type {
|
|
|
18
16
|
MigrationRunnerResult,
|
|
19
17
|
OperationContext,
|
|
20
18
|
OpFactoryCall,
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
SchemaDiffIssue,
|
|
20
|
+
SchemaOwnership,
|
|
23
21
|
} from '@prisma-next/framework-components/control';
|
|
24
22
|
import type { AggregateMigrationEdgeRef } from '@prisma-next/migration-tools/aggregate';
|
|
25
23
|
import type {
|
|
@@ -30,10 +28,9 @@ import type {
|
|
|
30
28
|
StorageTypeInstance,
|
|
31
29
|
} from '@prisma-next/sql-contract/types';
|
|
32
30
|
import type { SqlOperationDescriptors } from '@prisma-next/sql-operations';
|
|
33
|
-
import type {
|
|
31
|
+
import type { SqlSchemaIRNode } from '@prisma-next/sql-schema-ir/types';
|
|
34
32
|
import type { Result } from '@prisma-next/utils/result';
|
|
35
33
|
import type { SqlControlAdapter } from '../control-adapter';
|
|
36
|
-
import type { SqlControlFamilyInstance } from '../control-instance';
|
|
37
34
|
|
|
38
35
|
export type AnyRecord = Readonly<Record<string, unknown>>;
|
|
39
36
|
|
|
@@ -102,20 +99,28 @@ export interface FieldEventContext {
|
|
|
102
99
|
}
|
|
103
100
|
|
|
104
101
|
export interface CodecControlHooks<TTargetDetails = unknown> {
|
|
102
|
+
/**
|
|
103
|
+
* `schema` is typed as the family-level `SqlSchemaIRNode` (not the concrete
|
|
104
|
+
* `SqlSchemaIR` class) because the actual value handed in is whatever
|
|
105
|
+
* per-namespace node the calling target's tree shape produces — a flat
|
|
106
|
+
* `SqlSchemaIR` for SQLite, a `PostgresNamespaceSchemaNode` for Postgres —
|
|
107
|
+
* read structurally for its `tables`/`nativeEnums` fields. Hooks that need
|
|
108
|
+
* the concrete Postgres shape narrow via `PostgresNamespaceSchemaNode.is(schema)`.
|
|
109
|
+
*/
|
|
105
110
|
planTypeOperations?: (options: {
|
|
106
111
|
readonly typeName: string;
|
|
107
112
|
readonly typeInstance: StorageTypeInstance;
|
|
108
113
|
readonly contract: Contract<SqlStorage>;
|
|
109
|
-
readonly schema:
|
|
114
|
+
readonly schema: SqlSchemaIRNode;
|
|
110
115
|
readonly schemaName?: string;
|
|
111
116
|
readonly policy: MigrationOperationPolicy;
|
|
112
117
|
}) => StorageTypePlanResult<TTargetDetails>;
|
|
113
118
|
verifyType?: (options: {
|
|
114
119
|
readonly typeName: string;
|
|
115
120
|
readonly typeInstance: StorageTypeInstance;
|
|
116
|
-
readonly schema:
|
|
121
|
+
readonly schema: SqlSchemaIRNode;
|
|
117
122
|
readonly schemaName?: string;
|
|
118
|
-
}) => readonly
|
|
123
|
+
}) => readonly SchemaDiffIssue[];
|
|
119
124
|
introspectTypes?: (options: {
|
|
120
125
|
readonly driver: SqlControlDriverInstance<string>;
|
|
121
126
|
readonly schemaName?: string;
|
|
@@ -277,12 +282,12 @@ export type SqlPlannerConflictKind =
|
|
|
277
282
|
| 'controlPolicySuppressedCall';
|
|
278
283
|
|
|
279
284
|
export interface SqlPlannerConflictLocation {
|
|
280
|
-
readonly
|
|
281
|
-
readonly
|
|
285
|
+
readonly namespaceId?: string;
|
|
286
|
+
readonly entityKind?: string;
|
|
287
|
+
readonly entityName?: string;
|
|
282
288
|
readonly column?: string;
|
|
283
289
|
readonly index?: string;
|
|
284
290
|
readonly constraint?: string;
|
|
285
|
-
readonly type?: string;
|
|
286
291
|
}
|
|
287
292
|
|
|
288
293
|
export interface SqlPlannerConflict extends MigrationPlannerConflict {
|
|
@@ -308,7 +313,12 @@ export type SqlPlannerResult<TTargetDetails> =
|
|
|
308
313
|
|
|
309
314
|
export interface SqlMigrationPlannerPlanOptions {
|
|
310
315
|
readonly contract: Contract<SqlStorage>;
|
|
311
|
-
|
|
316
|
+
/**
|
|
317
|
+
* The "from"/live schema as the target's introspected node (SQLite a flat
|
|
318
|
+
* `SqlSchemaIR`, Postgres a `PostgresDatabaseSchemaNode` root). Structure-aware
|
|
319
|
+
* consumers narrow the concrete shape before walking it.
|
|
320
|
+
*/
|
|
321
|
+
readonly schema: SqlSchemaIRNode;
|
|
312
322
|
readonly policy: MigrationOperationPolicy;
|
|
313
323
|
readonly schemaName?: string;
|
|
314
324
|
/**
|
|
@@ -343,6 +353,16 @@ export interface SqlMigrationPlannerPlanOptions {
|
|
|
343
353
|
* All components must have matching familyId ('sql') and targetId.
|
|
344
354
|
*/
|
|
345
355
|
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
356
|
+
/**
|
|
357
|
+
* Ownership oracle over the whole contract-space composition (the passive
|
|
358
|
+
* aggregate). The planner asks it, per live extra node, whether any space
|
|
359
|
+
* declares that entity: a sibling-owned node is left untouched, an unowned
|
|
360
|
+
* node is a genuine extra it may drop under a destructive policy. The
|
|
361
|
+
* planner holds no list of other spaces' names — ownership lives in the
|
|
362
|
+
* aggregate; it only asks. Absent for a single-space plan handed no
|
|
363
|
+
* aggregate. See {@link SchemaOwnership}.
|
|
364
|
+
*/
|
|
365
|
+
readonly ownership?: SchemaOwnership;
|
|
346
366
|
}
|
|
347
367
|
|
|
348
368
|
export interface SqlMigrationPlanner<TTargetDetails> {
|
|
@@ -456,30 +476,6 @@ export interface SqlMigrationRunner<TTargetDetails> {
|
|
|
456
476
|
): Promise<SqlMigrationRunnerResult>;
|
|
457
477
|
}
|
|
458
478
|
|
|
459
|
-
export interface SqlControlTargetDescriptor<
|
|
460
|
-
TTargetId extends string,
|
|
461
|
-
TTargetDetails,
|
|
462
|
-
TContract extends Contract<SqlStorage> = Contract<SqlStorage>,
|
|
463
|
-
> extends MigratableTargetDescriptor<'sql', TTargetId, SqlControlFamilyInstance> {
|
|
464
|
-
readonly queryOperations?: () => SqlOperationDescriptors;
|
|
465
|
-
/**
|
|
466
|
-
* JSON ⇄ class boundary for the SQL target's contract. The descriptor
|
|
467
|
-
* composes a concrete `SqlContractSerializerBase` subclass; the rest
|
|
468
|
-
* of the control stack reaches `descriptor.contractSerializer` rather
|
|
469
|
-
* than importing a per-target deserialization function.
|
|
470
|
-
*/
|
|
471
|
-
readonly contractSerializer: ContractSerializer<TContract>;
|
|
472
|
-
/**
|
|
473
|
-
* Per-target schema verifier walking the contract against
|
|
474
|
-
* `SqlSchemaIR`. The descriptor composes a concrete
|
|
475
|
-
* `SqlSchemaVerifierBase` subclass; the family-shared walk lives on
|
|
476
|
-
* the base, the target-specific dispatch on the subclass.
|
|
477
|
-
*/
|
|
478
|
-
readonly schemaVerifier: SchemaVerifier<TContract, SqlSchemaIR>;
|
|
479
|
-
createPlanner(adapter: SqlControlAdapter<TTargetId>): SqlMigrationPlanner<TTargetDetails>;
|
|
480
|
-
createRunner(family: SqlControlFamilyInstance): SqlMigrationRunner<TTargetDetails>;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
479
|
export interface CreateSqlMigrationPlanOptions<TTargetDetails> {
|
|
484
480
|
readonly targetId: string;
|
|
485
481
|
/**
|
|
@@ -127,6 +127,21 @@ export function toEnumName(pgTypeName: string): NameResult {
|
|
|
127
127
|
return { name };
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
const VALID_IDENTIFIER_PATTERN = /^[A-Za-z_]\w*$/;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* PSL member name for a native-enum value. The value itself always prints
|
|
134
|
+
* explicitly (`member = "value"`), so the returned name never needs a map:
|
|
135
|
+
* a value that already is a valid, non-reserved identifier is kept verbatim
|
|
136
|
+
* (case included); anything else is camelCased/escaped like a field name.
|
|
137
|
+
*/
|
|
138
|
+
export function toEnumMemberName(value: string): string {
|
|
139
|
+
if (VALID_IDENTIFIER_PATTERN.test(value) && !needsEscaping(value)) {
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
return escapeIfNeeded(snakeToCamelCase(value));
|
|
143
|
+
}
|
|
144
|
+
|
|
130
145
|
export function pluralize(word: string): string {
|
|
131
146
|
if (
|
|
132
147
|
word.endsWith('s') ||
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import type { ColumnDefault } from '@prisma-next/contract/types';
|
|
2
2
|
import type { DefaultMappingOptions } from './default-mapping';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Internal printer-shaped configuration, used by the SQL family's
|
|
6
|
-
* `sqlSchemaIrToPslAst` helper (M2). The framework-level psl-printer no longer
|
|
7
|
-
* exposes these — they're consumed only inside the SQL family.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
4
|
export type PslNativeTypeAttribute = {
|
|
11
5
|
readonly name: string;
|
|
12
6
|
readonly args?: readonly string[];
|
|
@@ -43,6 +37,18 @@ export interface PslPrinterOptions {
|
|
|
43
37
|
export type RelationField = {
|
|
44
38
|
readonly fieldName: string;
|
|
45
39
|
readonly typeName: string;
|
|
40
|
+
/**
|
|
41
|
+
* Namespace qualifier for a cross-space relation (e.g. `"auth"` for a
|
|
42
|
+
* relation into `supabase:auth.AuthUser`). Absent for a same-namespace
|
|
43
|
+
* relation.
|
|
44
|
+
*/
|
|
45
|
+
readonly typeNamespaceId?: string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Contract-space qualifier for a relation into another stack extension
|
|
48
|
+
* pack's contract space (e.g. `"supabase"`). Absent for a same-space
|
|
49
|
+
* relation.
|
|
50
|
+
*/
|
|
51
|
+
readonly typeContractSpaceId?: string | undefined;
|
|
46
52
|
readonly referencedTableName?: string | undefined;
|
|
47
53
|
readonly optional: boolean;
|
|
48
54
|
readonly list: boolean;
|
|
@@ -52,4 +58,6 @@ export type RelationField = {
|
|
|
52
58
|
readonly references?: readonly string[] | undefined;
|
|
53
59
|
readonly onDelete?: string | undefined;
|
|
54
60
|
readonly onUpdate?: string | undefined;
|
|
61
|
+
/** `false` when the FK's source columns have no live backing index; omitted (the default) otherwise. */
|
|
62
|
+
readonly index?: boolean | undefined;
|
|
55
63
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SqlForeignKeyIR, SqlTableIR } from '@prisma-next/sql-schema-ir/types';
|
|
2
|
+
import { backingIndexColumnKeys, isBackedByColumnKeys } from '../foreign-key-index-backing';
|
|
2
3
|
import { deriveBackRelationFieldName, deriveRelationFieldName, pluralize } from './name-transforms';
|
|
3
4
|
import type { RelationField } from './printer-config';
|
|
4
5
|
|
|
@@ -71,6 +72,7 @@ export function inferRelations(
|
|
|
71
72
|
fk,
|
|
72
73
|
childOptional,
|
|
73
74
|
relationName,
|
|
75
|
+
table,
|
|
74
76
|
);
|
|
75
77
|
|
|
76
78
|
addRelationField(relationsByTable, childTableName, childRelField);
|
|
@@ -136,15 +138,38 @@ function deriveRelationName(
|
|
|
136
138
|
return fk.columns.join('_');
|
|
137
139
|
}
|
|
138
140
|
|
|
139
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Builds the child-side {@link RelationField} for a single foreign key:
|
|
143
|
+
* `typeName` is the parent model name, `fields`/`references` are the FK's raw
|
|
144
|
+
* columns, and `onDelete`/`onUpdate` are normalized to their PSL spelling.
|
|
145
|
+
* Exported so a caller resolving a foreign key against a model outside
|
|
146
|
+
* `tables` (e.g. a cross-space reference into another contract) can reuse the
|
|
147
|
+
* same normalization instead of duplicating it.
|
|
148
|
+
*
|
|
149
|
+
* `hostTable` is the table the FK is declared on (i.e. `table`, not the
|
|
150
|
+
* referenced parent) — its own indexes/uniques/primary key are what a
|
|
151
|
+
* backing index for this FK would be. When none of them exactly match the
|
|
152
|
+
* FK's source columns (in order), `index: false` is stamped so the emitted
|
|
153
|
+
* `@relation` opts out of the framework's default derived backing-index
|
|
154
|
+
* expectation, matching what `db verify` will find live. Passing the table
|
|
155
|
+
* is optional so existing single-FK callers (e.g. cross-space resolution
|
|
156
|
+
* before a host table reference is threaded through) can omit it and keep
|
|
157
|
+
* the framework default.
|
|
158
|
+
*/
|
|
159
|
+
export function buildChildRelationField(
|
|
140
160
|
fieldName: string,
|
|
141
161
|
parentModelName: string,
|
|
142
162
|
fk: SqlForeignKeyIR,
|
|
143
163
|
optional: boolean,
|
|
144
164
|
relationName?: string,
|
|
165
|
+
hostTable?: SqlTableIR,
|
|
145
166
|
): RelationField {
|
|
146
167
|
const onDelete = fk.onDelete && fk.onDelete !== DEFAULT_ON_DELETE ? fk.onDelete : undefined;
|
|
147
168
|
const onUpdate = fk.onUpdate && fk.onUpdate !== DEFAULT_ON_UPDATE ? fk.onUpdate : undefined;
|
|
169
|
+
const index =
|
|
170
|
+
hostTable && !isBackedByColumnKeys(fk.columns, backingIndexColumnKeys(hostTable))
|
|
171
|
+
? false
|
|
172
|
+
: undefined;
|
|
148
173
|
|
|
149
174
|
return {
|
|
150
175
|
fieldName,
|
|
@@ -158,6 +183,7 @@ function buildChildRelationField(
|
|
|
158
183
|
references: fk.referencedColumns,
|
|
159
184
|
onDelete: onDelete ? REFERENTIAL_ACTION_PSL[onDelete] : undefined,
|
|
160
185
|
onUpdate: onUpdate ? REFERENTIAL_ACTION_PSL[onUpdate] : undefined,
|
|
186
|
+
index,
|
|
161
187
|
};
|
|
162
188
|
}
|
|
163
189
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { Contract } from '@prisma-next/contract/types';
|
|
1
2
|
import { deriveProvidedInvariants } from '@prisma-next/migration-tools/invariants';
|
|
2
3
|
import { Migration } from '@prisma-next/migration-tools/migration';
|
|
4
|
+
import type { SqlStorage } from '@prisma-next/sql-contract/types';
|
|
3
5
|
import { isThenable } from '@prisma-next/utils/promise';
|
|
4
6
|
import type { SqlMigrationPlanOperation, SqlPlanTargetDetails } from './migrations/types';
|
|
5
7
|
|
|
@@ -14,13 +16,22 @@ import type { SqlMigrationPlanOperation, SqlPlanTargetDetails } from './migratio
|
|
|
14
16
|
* fully concrete operation shape. Target-free code in SQL family / tooling
|
|
15
17
|
* parameterises over `TDetails` (and usually `TTargetId = string`).
|
|
16
18
|
*
|
|
19
|
+
* The `Start` / `End` contract generics are forwarded to the framework
|
|
20
|
+
* `Migration` base so the derived `describe()` and the per-target view getters
|
|
21
|
+
* (`PostgresMigration` / `SqliteMigration`) carry each migration's precise
|
|
22
|
+
* contract types. The view getters themselves live on the per-target bases
|
|
23
|
+
* because the SQL ContractView shapes differ per target (SQLite unwraps its
|
|
24
|
+
* sole namespace to the root; Postgres is schema-qualified).
|
|
25
|
+
*
|
|
17
26
|
* Keeps target-free contract/runtime features in the family layer while
|
|
18
27
|
* letting adapters own target shape.
|
|
19
28
|
*/
|
|
20
29
|
export abstract class SqlMigration<
|
|
21
30
|
TDetails extends SqlPlanTargetDetails,
|
|
22
31
|
TTargetId extends string = string,
|
|
23
|
-
|
|
32
|
+
Start extends Contract<SqlStorage> = Contract<SqlStorage>,
|
|
33
|
+
End extends Contract<SqlStorage> = Contract<SqlStorage>,
|
|
34
|
+
> extends Migration<SqlMigrationPlanOperation<TDetails>, 'sql', TTargetId, Start, End> {
|
|
24
35
|
/**
|
|
25
36
|
* Sorted, deduplicated invariant ids declared by this migration's
|
|
26
37
|
* data-transform ops. Derived from `this.operations` so the field remains
|
package/src/exports/control.ts
CHANGED
|
@@ -14,6 +14,10 @@ export type {
|
|
|
14
14
|
export { assembleAuthoringContributions } from '@prisma-next/framework-components/control';
|
|
15
15
|
export { extractCodecControlHooks } from '../core/assembly';
|
|
16
16
|
export type { SqlControlFamilyInstance } from '../core/control-instance';
|
|
17
|
+
export type {
|
|
18
|
+
SqlControlTargetDescriptor,
|
|
19
|
+
SqlDescribedContractSpace,
|
|
20
|
+
} from '../core/control-target-descriptor';
|
|
17
21
|
export type {
|
|
18
22
|
ContractToSchemaIROptions,
|
|
19
23
|
DefaultRenderer,
|
|
@@ -22,11 +26,12 @@ export type {
|
|
|
22
26
|
} from '../core/migrations/contract-to-schema-ir';
|
|
23
27
|
// Contract → SchemaIR conversion for offline migration planning
|
|
24
28
|
export {
|
|
29
|
+
contractNamespaceToSchemaIR,
|
|
25
30
|
contractToSchemaIR,
|
|
26
31
|
detectDestructiveChanges,
|
|
27
32
|
resolveValueSetValues,
|
|
28
33
|
} from '../core/migrations/contract-to-schema-ir';
|
|
29
|
-
export type { ControlPolicySubject } from '../core/migrations/control-policy';
|
|
34
|
+
export type { ControlPolicySubject, SuppressionRecord } from '../core/migrations/control-policy';
|
|
30
35
|
export {
|
|
31
36
|
controlPolicyForCall,
|
|
32
37
|
partitionCallsByControlPolicy,
|
|
@@ -34,6 +39,7 @@ export {
|
|
|
34
39
|
} from '../core/migrations/control-policy';
|
|
35
40
|
export type { PlanFieldEventOperationsOptions } from '../core/migrations/field-event-planner';
|
|
36
41
|
export { planFieldEventOperations } from '../core/migrations/field-event-planner';
|
|
42
|
+
export { buildNativeTypeExpander } from '../core/migrations/native-type-expander';
|
|
37
43
|
export {
|
|
38
44
|
createMigrationPlan,
|
|
39
45
|
plannerFailure,
|
|
@@ -42,6 +48,11 @@ export {
|
|
|
42
48
|
runnerSuccess,
|
|
43
49
|
} from '../core/migrations/plan-helpers';
|
|
44
50
|
export { INIT_ADDITIVE_POLICY } from '../core/migrations/policies';
|
|
51
|
+
export type {
|
|
52
|
+
SqlSchemaDiffFn,
|
|
53
|
+
SqlSchemaDiffInput,
|
|
54
|
+
SqlSchemaDiffResult,
|
|
55
|
+
} from '../core/migrations/schema-differ';
|
|
45
56
|
export type {
|
|
46
57
|
CodecControlHooks,
|
|
47
58
|
CreateSqlMigrationPlanOptions,
|
|
@@ -51,7 +62,6 @@ export type {
|
|
|
51
62
|
ResolveIdentityValueInput,
|
|
52
63
|
SqlControlAdapterDescriptor,
|
|
53
64
|
SqlControlExtensionDescriptor,
|
|
54
|
-
SqlControlTargetDescriptor,
|
|
55
65
|
SqlMigrationPlan,
|
|
56
66
|
SqlMigrationPlanContractInfo,
|
|
57
67
|
SqlMigrationPlanner,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQL relational schema-diff exports.
|
|
3
|
+
*
|
|
4
|
+
* The generic node differ (`buildPostgresPlanDiff` / `buildSqlitePlanDiff`)
|
|
5
|
+
* drives both plan and verify over the trees as derived — no pre-diff
|
|
6
|
+
* transformation. This module surfaces the verify-verdict machinery. Pure —
|
|
7
|
+
* no database connection required.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type {
|
|
11
|
+
SqlDiffVerdict,
|
|
12
|
+
SqlDiffVerdictInput,
|
|
13
|
+
StorageTypeVerdict,
|
|
14
|
+
StorageTypeVerdictInput,
|
|
15
|
+
VerifySqlSchemaByDiffInput,
|
|
16
|
+
} from '../core/diff/schema-verify';
|
|
17
|
+
export {
|
|
18
|
+
classifyDiffSubjectGranularity,
|
|
19
|
+
classifySqlDiffIssue,
|
|
20
|
+
computeSqlDiffVerdict,
|
|
21
|
+
computeStorageTypeVerdict,
|
|
22
|
+
verifySqlSchemaByDiff,
|
|
23
|
+
} from '../core/diff/schema-verify';
|
|
24
|
+
export type { NativeTypeNormalizer } from '../core/diff/sql-schema-diff';
|
|
25
|
+
export { arraysEqual } from '../core/diff/sql-schema-diff';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shape-neutral database→PSL inference utilities.
|
|
3
|
+
*
|
|
4
|
+
* These leaf transforms (name normalization, relation inference, generic
|
|
5
|
+
* default mapping, the printer-config types, raw-default parsing) carry no
|
|
6
|
+
* dialect knowledge, so they live in the SQL family and are imported by the
|
|
7
|
+
* target that owns the dialect maps and walks its own schema tree (Postgres).
|
|
8
|
+
* The framework owns `PslDocumentAst` + `printPsl`; the target owns the
|
|
9
|
+
* Postgres type/default maps.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export type {
|
|
13
|
+
DefaultMappingOptions,
|
|
14
|
+
DefaultMappingResult,
|
|
15
|
+
} from '../core/psl-contract-infer/default-mapping';
|
|
16
|
+
export { mapDefault } from '../core/psl-contract-infer/default-mapping';
|
|
17
|
+
export {
|
|
18
|
+
deriveBackRelationFieldName,
|
|
19
|
+
deriveRelationFieldName,
|
|
20
|
+
pluralize,
|
|
21
|
+
toEnumMemberName,
|
|
22
|
+
toEnumName,
|
|
23
|
+
toFieldName,
|
|
24
|
+
toModelName,
|
|
25
|
+
toNamedTypeName,
|
|
26
|
+
} from '../core/psl-contract-infer/name-transforms';
|
|
27
|
+
export type {
|
|
28
|
+
EnumInfo,
|
|
29
|
+
PslNativeTypeAttribute,
|
|
30
|
+
PslPrinterOptions,
|
|
31
|
+
PslTypeMap,
|
|
32
|
+
PslTypeResolution,
|
|
33
|
+
RelationField,
|
|
34
|
+
} from '../core/psl-contract-infer/printer-config';
|
|
35
|
+
export { parseRawDefault } from '../core/psl-contract-infer/raw-default-parser';
|
|
36
|
+
export type { InferredRelations } from '../core/psl-contract-infer/relation-inference';
|
|
37
|
+
export {
|
|
38
|
+
buildChildRelationField,
|
|
39
|
+
inferRelations,
|
|
40
|
+
} from '../core/psl-contract-infer/relation-inference';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authoring-type-constructors-CjFfO6LM.mjs","names":[],"sources":["../src/core/authoring-entity-types.ts","../src/core/authoring-field-presets.ts","../src/core/authoring-type-constructors.ts"],"sourcesContent":["import type { JsonValue } from '@prisma-next/contract/types';\nimport type {\n AuthoringEntityContext,\n AuthoringEntityTypeDescriptor,\n AuthoringEntityTypeNamespace,\n AuthoringPslBlockDescriptorNamespace,\n PslExtensionBlock,\n} from '@prisma-next/framework-components/authoring';\nimport { type EnumTypeHandle, enumType } from '@prisma-next/sql-contract-ts/contract-builder';\nimport { blindCast } from '@prisma-next/utils/casts';\n\nfunction parseQuotedString(raw: string): string | undefined {\n if (raw.startsWith('\"') && raw.endsWith('\"') && raw.length >= 2) {\n return raw.slice(1, -1);\n }\n return undefined;\n}\n\nexport const sqlFamilyEnumEntityDescriptor = {\n kind: 'entity' as const,\n discriminator: 'enum',\n output: {\n factory: (\n block: PslExtensionBlock,\n ctx: AuthoringEntityContext,\n ): EnumTypeHandle | undefined => {\n const sourceId = ctx.sourceId ?? 'unknown';\n const diagnostics = ctx.diagnostics;\n\n const typeAttr = block.blockAttributes.find((a) => a.name === 'type');\n if (!typeAttr) {\n diagnostics?.push({\n code: 'PSL_ENUM_MISSING_TYPE',\n message: `enum \"${block.name}\" is missing a @@type(\"codecId\") attribute`,\n sourceId,\n span: block.span,\n });\n return undefined;\n }\n\n const rawCodecArg = typeAttr.args[0]?.value;\n const codecId = rawCodecArg !== undefined ? parseQuotedString(rawCodecArg) : undefined;\n if (!codecId) {\n diagnostics?.push({\n code: 'PSL_ENUM_MISSING_TYPE',\n message: `enum \"${block.name}\" @@type attribute must have a quoted codec id argument`,\n sourceId,\n span: typeAttr.span,\n });\n return undefined;\n }\n\n const nativeType = ctx.codecLookup?.targetTypesFor(codecId)?.[0];\n if (nativeType === undefined) {\n const typeArgSpan = typeAttr.args[0]?.span ?? typeAttr.span;\n diagnostics?.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `enum \"${block.name}\" @@type references unknown codec \"${codecId}\"`,\n sourceId,\n span: typeArgSpan,\n });\n return undefined;\n }\n\n const codec = ctx.codecLookup?.get(codecId);\n if (codec === undefined) {\n const typeArgSpan = typeAttr.args[0]?.span ?? typeAttr.span;\n diagnostics?.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `enum \"${block.name}\" @@type codec \"${codecId}\" resolves in targetTypesFor but is absent from codecLookup.get`,\n sourceId,\n span: typeArgSpan,\n });\n return undefined;\n }\n\n const seenValues = new Set<string>();\n const members: { name: string; value: unknown }[] = [];\n let memberError = false;\n\n for (const [memberName, paramValue] of Object.entries(block.parameters)) {\n let value: unknown;\n if (paramValue.kind === 'bare') {\n try {\n value = codec.decodeJson(memberName);\n } catch {\n diagnostics?.push({\n code: 'PSL_ENUM_BARE_MEMBER_NON_STRING_CODEC',\n message: `enum \"${block.name}\" member \"${memberName}\" has no value and codec \"${codecId}\" does not accept a bare name as input`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n } else if (paramValue.kind === 'value') {\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: `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 try {\n value = codec.decodeJson(\n blindCast<JsonValue, 'JSON.parse returns a JsonValue-compatible value'>(jsonValue),\n );\n } catch (err) {\n const reason = err instanceof Error ? err.message : String(err);\n diagnostics?.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `enum \"${block.name}\" member \"${memberName}\" was rejected by codec \"${codecId}\": ${reason}`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n } else {\n continue;\n }\n\n const valueKey = String(value);\n if (seenValues.has(valueKey)) {\n diagnostics?.push({\n code: 'PSL_ENUM_DUPLICATE_MEMBER_VALUE',\n message: `enum \"${block.name}\": duplicate member value \"${valueKey}\"`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n seenValues.add(valueKey);\n members.push({ name: memberName, value });\n }\n\n if (memberError) return undefined;\n\n if (members.length === 0) {\n diagnostics?.push({\n code: 'PSL_ENUM_MISSING_TYPE',\n message: `enum \"${block.name}\" must have at least one member`,\n sourceId,\n span: block.span,\n });\n return undefined;\n }\n\n return enumType(\n block.name,\n { codecId, nativeType },\n ...members.map((m) => ({ name: m.name, value: m.value })),\n );\n },\n },\n} satisfies AuthoringEntityTypeDescriptor;\n\nexport const sqlFamilyEntityTypes: AuthoringEntityTypeNamespace = {\n enum: sqlFamilyEnumEntityDescriptor,\n};\n\nexport const sqlFamilyPslBlockDescriptors = {\n enum: {\n kind: 'pslBlock',\n keyword: 'enum',\n discriminator: 'enum',\n name: { required: true },\n parameters: {},\n variadicParameters: true,\n },\n} as const satisfies AuthoringPslBlockDescriptorNamespace;\n","import type { AuthoringFieldNamespace } from '@prisma-next/framework-components/authoring';\n\n/**\n * Family-level SQL authoring field presets.\n *\n * Only presets whose codec IDs align with the ID generator metadata live here\n * (see `@prisma-next/ids`). These presets are target-agnostic because the\n * generator metadata fixes their codec/native-type to `sql/char@1`\n * (`character`) regardless of target, and the PSL interpreter lets the\n * generator override the scalar descriptor.\n *\n * The `uuidString` / `id.uuidv4String` / `id.uuidv7String` presets store UUID\n * values as `character(36)` — portable across all SQL targets. For a native\n * Postgres `uuid` column use `uuidNative` / `id.uuidv4Native` /\n * `id.uuidv7Native` from `@prisma-next/target-postgres`.\n *\n * Scalar presets that map to target-specific codecs (e.g. `text`, `int`,\n * `boolean`, `dateTime`) are contributed by the target pack (see\n * `postgresAuthoringFieldPresets` in `@prisma-next/target-postgres`) so the\n * TS callback surface and the PSL scalar surface lower to byte-identical\n * contracts for the active target.\n */\n\nconst CHARACTER_CODEC_ID = 'sql/char@1';\nconst CHARACTER_NATIVE_TYPE = 'character';\n\nconst nanoidOptionsArgument = {\n kind: 'object',\n optional: true,\n properties: {\n size: {\n kind: 'number',\n optional: true,\n integer: true,\n minimum: 2,\n maximum: 255,\n },\n },\n} as const;\n\nexport const sqlFamilyAuthoringFieldPresets = {\n uuidString: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 36,\n },\n },\n },\n ulid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 26,\n },\n },\n },\n nanoid: {\n kind: 'fieldPreset',\n args: [nanoidOptionsArgument],\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: {\n kind: 'arg',\n index: 0,\n path: ['size'],\n default: 21,\n },\n },\n },\n },\n cuid2: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 24,\n },\n },\n },\n ksuid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 27,\n },\n },\n },\n id: {\n uuidv4String: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 36,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv4',\n },\n },\n id: true,\n },\n },\n uuidv7String: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 36,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv7',\n },\n },\n id: true,\n },\n },\n ulid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 26,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'ulid',\n },\n },\n id: true,\n },\n },\n nanoid: {\n kind: 'fieldPreset',\n args: [nanoidOptionsArgument],\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: {\n kind: 'arg',\n index: 0,\n path: ['size'],\n default: 21,\n },\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'nanoid',\n params: {\n size: {\n kind: 'arg',\n index: 0,\n path: ['size'],\n },\n },\n },\n },\n id: true,\n },\n },\n cuid2: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 24,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'cuid2',\n },\n },\n id: true,\n },\n },\n ksuid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 27,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'ksuid',\n },\n },\n id: true,\n },\n },\n },\n} as const satisfies AuthoringFieldNamespace;\n","import type { AuthoringTypeNamespace } from '@prisma-next/framework-components/authoring';\n\nexport const sqlFamilyAuthoringTypes = {\n sql: {\n String: {\n kind: 'typeConstructor',\n args: [{ kind: 'number', name: 'length', integer: true, minimum: 1, maximum: 10485760 }],\n output: {\n codecId: 'sql/varchar@1',\n nativeType: 'character varying',\n typeParams: {\n length: { kind: 'arg', index: 0 },\n },\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n"],"mappings":";;;AAWA,SAAS,kBAAkB,KAAiC;CAC1D,IAAI,IAAI,WAAW,IAAG,KAAK,IAAI,SAAS,IAAG,KAAK,IAAI,UAAU,GAC5D,OAAO,IAAI,MAAM,GAAG,EAAE;AAG1B;AAoJA,MAAa,uBAAqD,EAChE,MAAM;CAlJN,MAAM;CACN,eAAe;CACf,QAAQ,EACN,UACE,OACA,QAC+B;EAC/B,MAAM,WAAW,IAAI,YAAY;EACjC,MAAM,cAAc,IAAI;EAExB,MAAM,WAAW,MAAM,gBAAgB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,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ,GACV;IACA,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;IACN,EACF;IACA,IAAI;GACN;EACF;EACA,QAAQ;GACN,MAAM;GACN,MAAM,CAAC,qBAAqB;GAC5B,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ;KACN,MAAM;KACN,OAAO;KACP,MAAM,CAAC,MAAM;KACb,SAAS;IACX,EACF;IACA,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;KACJ,QAAQ,EACN,MAAM;MACJ,MAAM;MACN,OAAO;MACP,MAAM,CAAC,MAAM;KACf,EACF;IACF,EACF;IACA,IAAI;GACN;EACF;EACA,OAAO;GACL,MAAM;GACN,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ,GACV;IACA,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;IACN,EACF;IACA,IAAI;GACN;EACF;EACA,OAAO;GACL,MAAM;GACN,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ,GACV;IACA,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;IACN,EACF;IACA,IAAI;GACN;EACF;CACF;AACF;;;ACpNA,MAAa,0BAA0B,EACrC,KAAK,EACH,QAAQ;CACN,MAAM;CACN,MAAM,CAAC;EAAE,MAAM;EAAU,MAAM;EAAU,SAAS;EAAM,SAAS;EAAG,SAAS;CAAS,CAAC;CACvF,QAAQ;EACN,SAAS;EACT,YAAY;EACZ,YAAY,EACV,QAAQ;GAAE,MAAM;GAAO,OAAO;EAAE,EAClC;CACF;AACF,EACF,EACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"control-adapter-Cmw9LvEP.d.mts","names":[],"sources":["../src/core/control-adapter.ts"],"mappings":";;;;;;;;;;AAuBA;;;;;UAAiB,OAAA;EACf,KAAA,CAAM,GAAA,EAAK,WAAA,G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AA,SACA,aAAA;IAAA,SACA,UAAA;EAAA,IAEV,OAAA;EAvEgC;;;;;;;;;;;;EAqFnC,UAAA,CACE,MAAA,EAAQ,wBAAA,CAAyB,OAAA,GACjC,QAAA,YACA,MAAA,YACC,OAAA,CAAQ,WAAA;EA5ET;;;;;EAAA,SAmFO,gBAAA,GAAmB,iBAAA;EApE1B;;;;;EAAA,SA2EO,mBAAA,GAAsB,oBAAA;EA5D/B;;;;EAkEA,4BAAA,aAAyC,OAAA;EA/DvC;;;;EAqEF,0BAAA,aAAuC,OAAA;AAAA;;;;;;;UASxB,2BAAA;EA1DF;;;;;;EAiEb,MAAA,CAAO,KAAA,EAAO,YAAA,QAAoB,OAAA,IAAW,iBAAA,CAAkB,OAAA;AAAA"}
|
package/dist/schema-verify.d.mts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { i as verifySqlSchema, n as NativeTypeNormalizer, r as VerifySqlSchemaOptions } from "./verify-sql-schema-thU-jKpf.mjs";
|
|
2
|
-
import { SchemaIssue } from "@prisma-next/framework-components/control";
|
|
3
|
-
import { ControlPolicy } from "@prisma-next/contract/types";
|
|
4
|
-
import { SqlIndexIR, SqlUniqueIR } from "@prisma-next/sql-schema-ir/types";
|
|
5
|
-
|
|
6
|
-
//#region src/core/schema-verify/verify-helpers.d.ts
|
|
7
|
-
/**
|
|
8
|
-
* Compares two arrays of strings for equality (order-sensitive).
|
|
9
|
-
*/
|
|
10
|
-
declare function arraysEqual(a: readonly string[], b: readonly string[]): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Checks if a unique constraint requirement is satisfied by the given columns.
|
|
13
|
-
*
|
|
14
|
-
* Semantic satisfaction: a unique constraint requirement can be satisfied by:
|
|
15
|
-
* - A unique constraint with the same columns, OR
|
|
16
|
-
* - A unique index with the same columns
|
|
17
|
-
*
|
|
18
|
-
* @param uniques - The unique constraints in the schema table
|
|
19
|
-
* @param indexes - The indexes in the schema table
|
|
20
|
-
* @param columns - The columns required by the unique constraint
|
|
21
|
-
* @returns true if the requirement is satisfied
|
|
22
|
-
*/
|
|
23
|
-
declare function isUniqueConstraintSatisfied(uniques: readonly SqlUniqueIR[], indexes: readonly SqlIndexIR[], columns: readonly string[]): boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Checks if an index requirement is satisfied by the given columns.
|
|
26
|
-
*
|
|
27
|
-
* Semantic satisfaction: a non-unique index requirement can be satisfied by:
|
|
28
|
-
* - Any index (unique or non-unique) with the same columns, OR
|
|
29
|
-
* - A unique constraint with the same columns (stronger satisfies weaker)
|
|
30
|
-
*
|
|
31
|
-
* @param indexes - The indexes in the schema table
|
|
32
|
-
* @param uniques - The unique constraints in the schema table
|
|
33
|
-
* @param columns - The columns required by the index
|
|
34
|
-
* @returns true if the requirement is satisfied
|
|
35
|
-
*/
|
|
36
|
-
declare function isIndexSatisfied(indexes: readonly SqlIndexIR[], uniques: readonly SqlUniqueIR[], columns: readonly string[]): boolean;
|
|
37
|
-
//#endregion
|
|
38
|
-
export { type NativeTypeNormalizer, type VerifySqlSchemaOptions, arraysEqual, isIndexSatisfied, isUniqueConstraintSatisfied, verifySqlSchema };
|
|
39
|
-
//# sourceMappingURL=schema-verify.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-verify.d.mts","names":[],"sources":["../src/core/schema-verify/verify-helpers.ts"],"mappings":";;;;;;;;;iBAgEgB,WAAA,CAAY,CAAA,qBAAsB,CAAoB;AA+BtE;;;;;;;;;;AAG4B;AAuB5B;AA1BA,iBAAgB,2BAAA,CACd,OAAA,WAAkB,WAAA,IAClB,OAAA,WAAkB,UAAU,IAC5B,OAAA;;;;;;;;;AA0B0B;;;;iBAHZ,gBAAA,CACd,OAAA,WAAkB,UAAA,IAClB,OAAA,WAAkB,WAAW,IAC7B,OAAA"}
|
package/dist/schema-verify.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sql-contract-serializer-BR2vC7Z-.mjs","names":[],"sources":["../src/core/ir/sql-contract-serializer-base.ts","../src/core/ir/sql-contract-serializer.ts"],"sourcesContent":["import { ContractValidationError } from '@prisma-next/contract/contract-validation-error';\nimport { isPlainRecord } from '@prisma-next/contract/is-plain-record';\nimport type { Contract } from '@prisma-next/contract/types';\nimport type { ContractSerializer } from '@prisma-next/framework-components/control';\nimport {\n type AnyEntityKindDescriptor,\n hydrateNamespaceEntities,\n type Namespace,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport { sqlContractCanonicalizationHooks } from '@prisma-next/sql-contract/canonicalization-hooks';\nimport { composeSqlEntityKinds } from '@prisma-next/sql-contract/entity-kinds';\nimport {\n buildSqlNamespace,\n type SqlNamespaceTablesInput,\n SqlStorage,\n type SqlStorageInput,\n type SqlStorageTypeEntry,\n SqlUnboundNamespace,\n} from '@prisma-next/sql-contract/types';\nimport {\n createSqlContractSchema,\n validateSqlContractFully,\n} from '@prisma-next/sql-contract/validators';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { JsonObject } from '@prisma-next/utils/json';\nimport { type Type, type } from 'arktype';\n\nconst NamespaceRawSchema = type({\n id: 'string',\n 'kind?': 'string',\n entries: type({\n '+': 'ignore',\n }),\n});\n\nexport type SqlEntityHydrationFactory = (entry: unknown) => unknown;\n\n/**\n * SQL family `ContractSerializer` abstract base. Carries the SQL-shared\n * deserialization pipeline:\n *\n * 1. `parseSqlContractStructure` validates the on-disk JSON envelope\n * against the SQL contract arktype schema (`validateSqlContractFully`)\n * and returns the validated flat-data shape.\n * 2. `hydrateSqlStorage` walks the validated `storage` subtree and\n * constructs the family-shared SQL Contract IR class hierarchy\n * (`SqlStorage` -> `StorageTable` -> `StorageColumn` / `PrimaryKey`\n * / …). The rest of the contract envelope is JSON-clean primitive\n * data and passes through unchanged.\n * 3. `constructTargetContract` is the target-specific extension hook;\n * defaults to identity. Targets that need to attach target-only\n * fields (e.g. target-specific derived storage fields) override it.\n *\n * Default `serializeContract` is identity over the contract — concrete\n * SQL targets ship JSON-clean class instances, so the contract value\n * can be stringified directly. The non-enumerable family-level `kind`\n * discriminator on `SqlNode` instances stays out of the persisted\n * envelope automatically. Targets that need to canonicalize on the way\n * out (key ordering, dropping computed-only fields) override\n * `serializeContract` directly.\n */\nexport abstract class SqlContractSerializerBase<TContract extends Contract<SqlStorage>>\n implements ContractSerializer<TContract>\n{\n private readonly contractSchema: Type<unknown> | undefined;\n private readonly entryKinds: ReadonlyMap<string, AnyEntityKindDescriptor>;\n\n constructor(\n protected readonly entityHydrationRegistry: ReadonlyMap<\n string,\n SqlEntityHydrationFactory\n > = new Map(),\n packEntityKinds: readonly AnyEntityKindDescriptor[] = [],\n ) {\n this.entryKinds = composeSqlEntityKinds(packEntityKinds);\n this.contractSchema =\n packEntityKinds.length > 0 ? createSqlContractSchema(this.entryKinds) : undefined;\n }\n\n deserializeContract<T extends TContract = TContract>(json: unknown): T {\n const validated = this.parseSqlContractStructure(json);\n const hydrated = this.hydrateSqlStorage(validated);\n return this.constructTargetContract(hydrated) as T;\n }\n\n serializeContract(contract: TContract): JsonObject {\n return contract as unknown as JsonObject;\n }\n\n shouldPreserveEmpty = sqlContractCanonicalizationHooks.shouldPreserveEmpty;\n\n sortStorage = sqlContractCanonicalizationHooks.sortStorage;\n\n protected parseSqlContractStructure(json: unknown): Contract<SqlStorage> {\n return validateSqlContractFully<Contract<SqlStorage>>(\n json,\n this.contractSchema !== undefined ? { contractSchema: this.contractSchema } : undefined,\n );\n }\n\n protected hydrateSqlStorage(validated: Contract<SqlStorage>): Contract<SqlStorage> {\n const types = validated.storage.types;\n const hydratedTypes =\n types !== undefined\n ? Object.fromEntries(\n Object.entries(types).map(([name, entry]) => [\n name,\n this.hydrateStorageTypeEntry(entry),\n ]),\n )\n : undefined;\n\n const rawNamespaces = validated.storage.namespaces;\n if (rawNamespaces === undefined) {\n throw new ContractValidationError(\n 'Contract storage.namespaces is required after structural validation',\n 'structural',\n );\n }\n const hydratedNamespaces = this.hydrateSqlNamespaceMap(rawNamespaces);\n // Compatibility shim: production code that addresses `__unbound__` for table\n // metadata lookups (collection-contract, query-plan-mutations, model-accessor,\n // query-plan-meta, where-binding) uses optional chaining and tolerates absence,\n // but runtime-qualification (TML-2605) has not yet landed cross-namespace table\n // routing. Injecting the empty singleton here keeps helpers that augment the\n // deserialized JSON (e.g. buildMixedPolyContract) working by providing a slot to\n // write into. Once runtime-qualification routes table lookups by namespace, this\n // shim should be removed.\n //\n // TML-2916: the shim only fires when the target's default namespace IS unbound\n // (SQLite, Mongo). On Postgres (`defaultNamespaceId === 'public'`) injecting an\n // empty `__unbound__` slot violates ADR 223 — un-namespaced PG models belong in\n // `public`, not `__unbound__`.\n const withInjectedUnbound =\n this.defaultNamespaceId === UNBOUND_NAMESPACE_ID\n ? {\n ...hydratedNamespaces,\n [UNBOUND_NAMESPACE_ID]:\n hydratedNamespaces[UNBOUND_NAMESPACE_ID] ?? SqlUnboundNamespace.instance,\n }\n : hydratedNamespaces;\n\n return {\n ...validated,\n storage: new SqlStorage({\n storageHash: validated.storage.storageHash,\n ...ifDefined('types', hydratedTypes),\n // Cast narrows the result of hydrateSqlNamespaceMap from the wider\n // framework `Namespace` to the SQL-family `SqlNamespace`.\n namespaces: blindCast<\n SqlStorageInput['namespaces'],\n 'hydrateSqlNamespaceMap builds each namespace through the SQL family concretions (SqlBoundNamespace / target schema), so every value is a SqlNamespace; the framework return type only promises the base Namespace.'\n >(withInjectedUnbound),\n }),\n };\n }\n\n protected abstract get defaultNamespaceId(): string;\n\n protected hydrateSqlNamespaceMap(\n namespaces: Readonly<Record<string, Namespace | Record<string, unknown>>>,\n ): Readonly<Record<string, Namespace>> {\n return Object.fromEntries(\n Object.entries(namespaces).map(([nsId, namespaceEntryRaw]) => {\n // Raw entries passed structural validation; hydrate materialises family IR class instances.\n const namespaceHydrated = this.hydrateSqlNamespaceEntry(nsId, namespaceEntryRaw);\n const namespaceMaterialised =\n namespaceHydrated instanceof NamespaceBase\n ? namespaceHydrated\n : buildSqlNamespace(\n blindCast<\n SqlNamespaceTablesInput,\n 'hydrateSqlNamespaceEntry returns SqlNamespaceTablesInput when raw is not a NamespaceBase'\n >(namespaceHydrated),\n );\n return [nsId, namespaceMaterialised];\n }),\n );\n }\n\n protected hydrateSqlNamespaceEntry(\n nsId: string,\n raw: Namespace | Record<string, unknown>,\n ): Namespace | SqlNamespaceTablesInput {\n if (raw instanceof NamespaceBase) {\n return raw;\n }\n const rawRecord = isPlainRecord(raw) ? raw : {};\n const id = typeof rawRecord['id'] === 'string' ? rawRecord['id'] : nsId;\n const parsed = NamespaceRawSchema({ ...rawRecord, id });\n if (parsed instanceof type.errors) {\n const messages = parsed.map((p: { message: string }) => p.message).join('; ');\n throw new ContractValidationError(`Namespace hydration failed: ${messages}`, 'structural');\n }\n const entriesRaw = parsed.entries;\n const rawEntriesMap = isPlainRecord(entriesRaw) ? entriesRaw : {};\n\n const entriesInput: Record<string, Readonly<Record<string, unknown>>> = {};\n for (const [key, innerMap] of Object.entries(rawEntriesMap)) {\n entriesInput[key] = isPlainRecord(innerMap) ? innerMap : Object.freeze({});\n }\n\n const entriesOutput = hydrateNamespaceEntities(entriesInput, this.entryKinds, 'fail', id);\n\n // Always ensure a 'table' key is present (may be empty).\n if (!Object.hasOwn(entriesOutput, 'table')) {\n entriesOutput['table'] = {};\n }\n\n return blindCast<\n SqlNamespaceTablesInput,\n 'entriesOutput holds the hydrated SQL entity-kind maps (table always present); this wraps them as the SqlNamespaceTablesInput the family createNamespace consumes.'\n >({\n id,\n entries: entriesOutput,\n });\n }\n\n protected hydrateStorageTypeEntry(entry: SqlStorageTypeEntry): SqlStorageTypeEntry {\n if (typeof entry !== 'object' || entry === null) {\n return entry;\n }\n const kind = (entry as { kind?: unknown }).kind;\n if (typeof kind !== 'string') {\n return entry;\n }\n const factory = this.entityHydrationRegistry.get(kind);\n if (factory === undefined) {\n return entry;\n }\n return blindCast<\n SqlStorageTypeEntry,\n 'entity registry factory returns SqlStorageTypeEntry for storage.types entries'\n >(factory(entry));\n }\n\n protected constructTargetContract(hydrated: Contract<SqlStorage>): TContract {\n return hydrated as TContract;\n }\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport { SqlContractSerializerBase } from './sql-contract-serializer-base';\n\n/**\n * Default SQL family `ContractSerializer` concretion. Inherits the\n * full SQL-shared deserialization pipeline (structural validation +\n * IR-class hydration) without pack-registered `storage.types`\n * hydration factories — targets that emit polymorphic JSON outside the\n * codec-typed envelope wire a target-specific subclass with a populated\n * registry (see Postgres). Family-level call sites instantiate this\n * default directly when no target serializer is supplied.\n */\nexport class SqlContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {\n constructor() {\n super(new Map());\n }\n\n // Family-level fallback when no target descriptor is wired in. Preserves the\n // pre-TML-2916 compatibility-shim behaviour for the unbound slot.\n protected override get defaultNamespaceId(): string {\n return UNBOUND_NAMESPACE_ID;\n }\n}\n"],"mappings":";;;;;;;;;;;AA8BA,MAAM,qBAAqB,KAAK;CAC9B,IAAI;CACJ,SAAS;CACT,SAAS,KAAK,EACZ,KAAK,SACP,CAAC;AACH,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AA4BD,IAAsB,4BAAtB,MAEA;CAKuB;CAJrB;CACA;CAEA,YACE,0CAGI,IAAI,IAAI,GACZ,kBAAsD,CAAC,GACvD;EALmB,KAAA,0BAAA;EAMnB,KAAK,aAAa,sBAAsB,eAAe;EACvD,KAAK,iBACH,gBAAgB,SAAS,IAAI,wBAAwB,KAAK,UAAU,IAAI,KAAA;CAC5E;CAEA,oBAAqD,MAAkB;EACrE,MAAM,YAAY,KAAK,0BAA0B,IAAI;EACrD,MAAM,WAAW,KAAK,kBAAkB,SAAS;EACjD,OAAO,KAAK,wBAAwB,QAAQ;CAC9C;CAEA,kBA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;GAAE,GAAG;GAAW;EAAG,CAAC;EACtD,IAAI,kBAAkB,KAAK,QAEzB,MAAM,IAAI,wBAAwB,+BADjB,OAAO,KAAK,MAA2B,EAAE,OAAO,CAAC,CAAC,KAAK,IACA,KAAK,YAAY;EAE3F,MAAM,aAAa,OAAO;EAC1B,MAAM,gBAAgB,cAAc,UAAU,IAAI,aAAa,CAAC;EAEhE,MAAM,eAAkE,CAAC;EACzE,KAAK,MAAM,CAAC,KAAK,aAAa,OAAO,QAAQ,aAAa,GACxD,aAAa,OAAO,cAAc,QAAQ,IAAI,WAAW,OAAO,OAAO,CAAC,CAAC;EAG3E,MAAM,gBAAgB,yBAAyB,cAAc,KAAK,YAAY,QAAQ,EAAE;EAGxF,IAAI,CAAC,OAAO,OAAO,eAAe,OAAO,GACvC,cAAc,WAAW,CAAC;EAG5B,OAAO,UAGL;GACA;GACA,SAAS;EACX,CAAC;CACH;CAEA,wBAAkC,OAAiD;EACjF,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,OAAO;EAET,MAAM,OAAQ,MAA6B;EAC3C,IAAI,OAAO,SAAS,UAClB,OAAO;EAET,MAAM,UAAU,KAAK,wBAAwB,IAAI,IAAI;EACrD,IAAI,YAAY,KAAA,GACd,OAAO;EAET,OAAO,UAGL,QAAQ,KAAK,CAAC;CAClB;CAEA,wBAAkC,UAA2C;EAC3E,OAAO;CACT;AACF;;;;;;;;;;;;ACpOA,IAAa,wBAAb,cAA2C,0BAAgD;CACzF,cAAc;EACZ,sBAAM,IAAI,IAAI,CAAC;CACjB;CAIA,IAAuB,qBAA6B;EAClD,OAAO;CACT;AACF"}
|
package/dist/test-utils.d.mts
DELETED
package/dist/test-utils.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-kgstZ_Zd.d.mts","names":[],"sources":["../src/core/control-instance.ts","../src/core/migrations/types.ts"],"mappings":";;;;;;;;;;;;;;UA4KU,eAAA;EAAA,SACC,MAAA;EAAA,SACA,QA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