@prisma-next/family-sql 0.14.0-dev.49 → 0.14.0-dev.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{control-adapter-DHYFuOBy.d.mts → control-adapter-BVOj4gXI.d.mts} +34 -5
- package/dist/control-adapter-BVOj4gXI.d.mts.map +1 -0
- package/dist/control-adapter.d.mts +1 -1
- package/dist/control.d.mts +65 -50
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +308 -56
- package/dist/control.mjs.map +1 -1
- package/dist/diff.d.mts +141 -30
- package/dist/diff.d.mts.map +1 -1
- package/dist/diff.mjs +155 -1384
- package/dist/diff.mjs.map +1 -1
- package/dist/ir.d.mts +5 -5
- 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 +1 -1
- 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-DwUSJ4PO.mjs → sql-contract-serializer-C75cfMSS.mjs} +2 -2
- package/dist/{sql-contract-serializer-DwUSJ4PO.mjs.map → sql-contract-serializer-C75cfMSS.mjs.map} +1 -1
- package/dist/{types-DBxrwN1d.d.mts → types-BW7pzb2j.d.mts} +24 -15
- package/dist/types-BW7pzb2j.d.mts.map +1 -0
- package/package.json +21 -21
- package/src/core/control-instance.ts +99 -80
- package/src/core/control-target-descriptor.ts +29 -14
- package/src/core/diff/diff-tree-normalization.ts +211 -0
- package/src/core/diff/schema-verify.ts +324 -0
- package/src/core/diff/sql-schema-diff.ts +40 -1466
- package/src/core/diff/verifier-disposition.ts +14 -42
- package/src/core/ir/sql-schema-verifier-base.ts +5 -5
- package/src/core/migrations/contract-to-schema-ir.ts +63 -20
- package/src/core/migrations/native-type-expander.ts +28 -0
- package/src/core/migrations/schema-differ.ts +30 -29
- package/src/core/migrations/types.ts +23 -14
- package/src/exports/control.ts +6 -0
- package/src/exports/diff.ts +28 -8
- package/dist/contract-to-schema-ir-S-evq8E6.mjs +0 -264
- package/dist/contract-to-schema-ir-S-evq8E6.mjs.map +0 -1
- package/dist/control-adapter-DHYFuOBy.d.mts.map +0 -1
- package/dist/sql-schema-diff-6z36dZt6.d.mts +0 -105
- package/dist/sql-schema-diff-6z36dZt6.d.mts.map +0 -1
- package/dist/types-DBxrwN1d.d.mts.map +0 -1
- package/src/core/diff/control-verify-emit.ts +0 -46
- package/src/core/diff/verify-helpers.ts +0 -832
package/dist/diff.d.mts
CHANGED
|
@@ -1,39 +1,150 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { a as NativeTypeNormalizer, c as isUniqueConstraintSatisfied, o as arraysEqual, s as isIndexSatisfied } from "./control-adapter-BVOj4gXI.mjs";
|
|
2
|
+
import { n as CodecControlHooks } from "./types-BW7pzb2j.mjs";
|
|
3
|
+
import { t as SqlSchemaDiffFn } from "./schema-differ-DnoopSXm.mjs";
|
|
4
|
+
import { DiffSubjectGranularity, SchemaDiffIssue, VerifierIssueCategory, VerifyDatabaseSchemaResult } from "@prisma-next/framework-components/control";
|
|
5
|
+
import { Contract, ControlPolicy } from "@prisma-next/contract/types";
|
|
6
|
+
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
|
7
|
+
import { SqlIndexIR, SqlSchemaIR, SqlSchemaIRNode, SqlUniqueIR } from "@prisma-next/sql-schema-ir/types";
|
|
8
|
+
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
5
9
|
|
|
6
|
-
//#region src/core/diff/
|
|
10
|
+
//#region src/core/diff/diff-tree-normalization.d.ts
|
|
11
|
+
interface SemanticSatisfactionInput {
|
|
12
|
+
readonly expectedUniques: readonly SqlUniqueIR[];
|
|
13
|
+
readonly expectedIndexes: readonly SqlIndexIR[];
|
|
14
|
+
readonly actualUniques: readonly SqlUniqueIR[];
|
|
15
|
+
readonly actualIndexes: readonly SqlIndexIR[];
|
|
16
|
+
}
|
|
17
|
+
interface SemanticSatisfactionResult {
|
|
18
|
+
readonly actualUniques: readonly SqlUniqueIR[];
|
|
19
|
+
readonly actualIndexes: readonly SqlIndexIR[];
|
|
20
|
+
}
|
|
7
21
|
/**
|
|
8
|
-
*
|
|
22
|
+
* Adjusts a table pair's ACTUAL unique/index child lists so the legacy
|
|
23
|
+
* walk's cross-kind semantic satisfaction materializes as same-kind node
|
|
24
|
+
* pairs for the differ (the differ pairs strictly by id, so a `unique:`
|
|
25
|
+
* node can never pair with an `index:` node). Three legacy rules, ported
|
|
26
|
+
* from `isUniqueConstraintSatisfied` / `isIndexSatisfied` and the
|
|
27
|
+
* strict-extras loops of the retired relational walk:
|
|
28
|
+
*
|
|
29
|
+
* 1. A contract unique satisfied by a live unique INDEX: the actual index
|
|
30
|
+
* node is reclassified as a unique node (it pairs with the expected
|
|
31
|
+
* unique and stops being a candidate extra).
|
|
32
|
+
* 2. A contract index (with no type/options demands) satisfied by a live
|
|
33
|
+
* unique CONSTRAINT: a same-kind actual index node is synthesized so
|
|
34
|
+
* the expected index pairs — the unique constraint itself stays (the
|
|
35
|
+
* legacy strict-extras loop still reports it as an undeclared unique).
|
|
36
|
+
* 3. Live unique indexes are never extras in the legacy walk (its
|
|
37
|
+
* strict-extras loop skips `unique: true` rows), so any remaining
|
|
38
|
+
* actual unique-index node with no expected index counterpart is
|
|
39
|
+
* dropped rather than surfacing as `not-expected`.
|
|
9
40
|
*/
|
|
10
|
-
declare function
|
|
41
|
+
declare function resolveSemanticSatisfaction(input: SemanticSatisfactionInput): SemanticSatisfactionResult;
|
|
11
42
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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
|
|
43
|
+
* Applies {@link resolveSemanticSatisfaction} across a flat table pair set:
|
|
44
|
+
* every actual table with an expected counterpart gets its unique/index
|
|
45
|
+
* child lists adjusted; unpaired tables pass through untouched.
|
|
22
46
|
*/
|
|
23
|
-
declare function
|
|
47
|
+
declare function normalizeFlatActualForDiff(expected: SqlSchemaIR, actual: SqlSchemaIR): SqlSchemaIR;
|
|
24
48
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* -
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
* Neutralizes the FK schema segment on a flat expected tree so its FK diff
|
|
50
|
+
* nodes pair with introspected FKs on single-schema targets: the family
|
|
51
|
+
* converter stamps `referencedSchema` with the contract namespace id
|
|
52
|
+
* verbatim (the unbound sentinel on non-namespaced targets), while a
|
|
53
|
+
* single-schema introspection stamps none — resolving both sides to the
|
|
54
|
+
* empty segment makes the ids meet.
|
|
55
|
+
*/
|
|
56
|
+
declare function neutralizeFlatExpectedFkSchemas(expected: SqlSchemaIR): SqlSchemaIR;
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/core/diff/schema-verify.d.ts
|
|
59
|
+
/**
|
|
60
|
+
* Resolves an issue's framework-neutral {@link DiffSubjectGranularity} on
|
|
61
|
+
* demand, from the issue's node's `nodeKind` via the target-provided
|
|
62
|
+
* `granularityOf` map. The node carries only its `nodeKind` identity, never a
|
|
63
|
+
* classification, and nothing is stamped onto the issue — every consumer
|
|
64
|
+
* (the family verdict below, the framework aggregate's unclaimed-elements
|
|
65
|
+
* sweep via {@link import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable})
|
|
66
|
+
* calls this the same way, resolved by the family/target that owns the node
|
|
67
|
+
* vocabulary. `undefined` for an issue with no node.
|
|
68
|
+
*/
|
|
69
|
+
declare function classifyDiffSubjectGranularity(issue: SchemaDiffIssue, granularityOf: (nodeKind: string) => DiffSubjectGranularity): DiffSubjectGranularity | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Re-keys the legacy `classifySqlVerifierIssueKind` category mapping on the
|
|
72
|
+
* issue's {@link DiffSubjectGranularity} (resolved via `granularityOf`) + the
|
|
73
|
+
* issue reason. The vocabulary maps one-to-one: an undeclared live entity or
|
|
74
|
+
* namespace is `extraTopLevelObject`, an undeclared live field
|
|
75
|
+
* `extraNestedElement`, undeclared auxiliaries (constraints, indexes,
|
|
76
|
+
* defaults) and structural leaves (policies) `extraAuxiliary`; a value-set
|
|
77
|
+
* drift on a check node is `valueDrift`; every other paired divergence is
|
|
78
|
+
* `declaredIncompatible`; anything the database lacks is `declaredMissing`.
|
|
79
|
+
* `granularityOf` is the target's classifier, so target and extension node
|
|
80
|
+
* kinds classify without the family importing them.
|
|
81
|
+
*/
|
|
82
|
+
declare function classifySqlDiffIssue(issue: SchemaDiffIssue, granularityOf: (nodeKind: string) => DiffSubjectGranularity): VerifierIssueCategory;
|
|
83
|
+
interface SqlDiffVerdictInput {
|
|
84
|
+
/** The full, ownership-scoped diff issue list from the target's differ. */
|
|
85
|
+
readonly issues: readonly SchemaDiffIssue[];
|
|
86
|
+
/** Resolves a diff issue's subject table's declared control policy directly from the contract. */
|
|
87
|
+
readonly resolveControlPolicy: (issue: SchemaDiffIssue) => ControlPolicy | undefined;
|
|
88
|
+
readonly strict: boolean;
|
|
89
|
+
readonly defaultControlPolicy: ControlPolicy | undefined;
|
|
90
|
+
/** The target's classifier: a diff issue node's `nodeKind` → its subject granularity. */
|
|
91
|
+
readonly granularityOf: (nodeKind: string) => DiffSubjectGranularity;
|
|
92
|
+
}
|
|
93
|
+
interface SqlDiffVerdict {
|
|
94
|
+
readonly failures: readonly SchemaDiffIssue[];
|
|
95
|
+
readonly warnings: readonly SchemaDiffIssue[];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Applies the two consumer filters to a diff issue list: strict gating
|
|
99
|
+
* (relational `not-expected` findings drop in lenient mode) and
|
|
100
|
+
* control-policy disposition (each surviving issue grades against its
|
|
101
|
+
* subject table's effective policy; suppressed issues drop, `observed`
|
|
102
|
+
* subjects warn). The verify verdict is `failures.length === 0`.
|
|
103
|
+
*/
|
|
104
|
+
declare function computeSqlDiffVerdict(input: SqlDiffVerdictInput): SqlDiffVerdict;
|
|
105
|
+
interface StorageTypeVerdictInput {
|
|
106
|
+
readonly contract: Contract<SqlStorage>;
|
|
107
|
+
/**
|
|
108
|
+
* Expected/actual namespace-node pairs the target's differ input produced:
|
|
109
|
+
* for a namespaced tree, one entry per expected namespace with a
|
|
110
|
+
* non-empty table set, paired by DDL schema name (absent actual side for
|
|
111
|
+
* a schema the database lacks); a flat tree is the sole pair.
|
|
112
|
+
*/
|
|
113
|
+
readonly namespacePairs: ReadonlyArray<{
|
|
114
|
+
readonly actual: SqlSchemaIRNode | undefined;
|
|
115
|
+
}>;
|
|
116
|
+
readonly codecHooks: ReadonlyMap<string, CodecControlHooks>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Runs the codec `verifyType` hooks the way the legacy walk did: once per
|
|
120
|
+
* contract namespace with tables, against that namespace's paired actual
|
|
121
|
+
* node (the hook reads namespace-scoped state such as
|
|
122
|
+
* `nativeEnumTypeNames` off it). Issue dispositions grade against the
|
|
123
|
+
* contract default policy, matching the legacy `pushTypeNode` semantics.
|
|
124
|
+
*/
|
|
125
|
+
interface StorageTypeVerdict {
|
|
126
|
+
readonly failures: readonly SchemaDiffIssue[];
|
|
127
|
+
readonly warnings: readonly SchemaDiffIssue[];
|
|
128
|
+
}
|
|
129
|
+
declare function computeStorageTypeVerdict(input: StorageTypeVerdictInput): StorageTypeVerdict;
|
|
130
|
+
interface VerifySqlSchemaByDiffInput {
|
|
131
|
+
readonly contract: Contract<SqlStorage>;
|
|
132
|
+
readonly schema: SqlSchemaIRNode;
|
|
133
|
+
readonly strict: boolean;
|
|
134
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
135
|
+
/** The target's full-tree node diff (`diffSchema` descriptor hook). */
|
|
136
|
+
readonly diffSchema: SqlSchemaDiffFn;
|
|
137
|
+
/** The target's classifier: a diff issue node's `nodeKind` → its subject granularity. */
|
|
138
|
+
readonly granularityOf: (nodeKind: string) => DiffSubjectGranularity;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* THE SQL schema verify: runs the target's full-tree node diff, grades it
|
|
142
|
+
* through the family's post-diff filters (strict gating + control-policy
|
|
143
|
+
* disposition) plus the codec `verifyType` hook findings, and wraps the
|
|
144
|
+
* verdict in the issue-based result envelope. `ok` holds exactly when both
|
|
145
|
+
* issue lists are empty — the lists carry the verdict's failures.
|
|
35
146
|
*/
|
|
36
|
-
declare function
|
|
147
|
+
declare function verifySqlSchemaByDiff(input: VerifySqlSchemaByDiffInput): VerifyDatabaseSchemaResult;
|
|
37
148
|
//#endregion
|
|
38
|
-
export { type NativeTypeNormalizer, type
|
|
149
|
+
export { type NativeTypeNormalizer, type SemanticSatisfactionInput, type SemanticSatisfactionResult, type SqlDiffVerdict, type SqlDiffVerdictInput, type StorageTypeVerdict, type StorageTypeVerdictInput, type VerifySqlSchemaByDiffInput, arraysEqual, classifyDiffSubjectGranularity, classifySqlDiffIssue, computeSqlDiffVerdict, computeStorageTypeVerdict, isIndexSatisfied, isUniqueConstraintSatisfied, neutralizeFlatExpectedFkSchemas, normalizeFlatActualForDiff, resolveSemanticSatisfaction, verifySqlSchemaByDiff };
|
|
39
150
|
//# sourceMappingURL=diff.d.mts.map
|
package/dist/diff.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.d.mts","names":[],"sources":["../src/core/diff/
|
|
1
|
+
{"version":3,"file":"diff.d.mts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