@prisma-next/family-sql 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/control-adapter.d.mts +28 -3
- package/dist/control-adapter.d.mts.map +1 -1
- package/dist/control.d.mts +3 -2
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +1025 -11
- package/dist/control.mjs.map +1 -1
- package/dist/migration.d.mts +14 -2
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +16 -1
- package/dist/migration.mjs.map +1 -1
- package/dist/schema-verify.d.mts +2 -2
- package/dist/{types-C6K4mxDM.d.mts → types-gLyIyd2X.d.mts} +36 -11
- package/dist/types-gLyIyd2X.d.mts.map +1 -0
- package/dist/verify-BdES8wgQ.mjs +82 -0
- package/dist/verify-BdES8wgQ.mjs.map +1 -0
- package/dist/verify-sql-schema-Ovz7RXR5.mjs.map +1 -1
- package/dist/{verify-sql-schema-BBhkqEDo.d.mts → verify-sql-schema-_EoNcGIq.d.mts} +2 -2
- package/dist/{verify-sql-schema-BBhkqEDo.d.mts.map → verify-sql-schema-_EoNcGIq.d.mts.map} +1 -1
- package/dist/verify.d.mts +16 -20
- package/dist/verify.d.mts.map +1 -1
- package/dist/verify.mjs +2 -2
- package/package.json +20 -20
- package/src/core/control-adapter.ts +33 -1
- package/src/core/control-instance.ts +43 -15
- package/src/core/migrations/plan-helpers.ts +1 -0
- package/src/core/migrations/types.ts +29 -6
- package/src/core/operation-preview.ts +62 -0
- package/src/core/psl-contract-infer/default-mapping.ts +56 -0
- package/src/core/psl-contract-infer/name-transforms.ts +178 -0
- package/src/core/psl-contract-infer/postgres-default-mapping.ts +16 -0
- package/src/core/psl-contract-infer/postgres-type-map.ts +165 -0
- package/src/core/psl-contract-infer/printer-config.ts +55 -0
- package/src/core/psl-contract-infer/raw-default-parser.ts +91 -0
- package/src/core/psl-contract-infer/relation-inference.ts +196 -0
- package/src/core/psl-contract-infer/sql-schema-ir-to-psl-ast.ts +832 -0
- package/src/core/sql-migration.ts +19 -3
- package/src/core/verify.ts +46 -108
- package/src/exports/verify.ts +1 -1
- package/dist/types-C6K4mxDM.d.mts.map +0 -1
- package/dist/verify-4GshvY4p.mjs +0 -122
- package/dist/verify-4GshvY4p.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -111,7 +111,7 @@ The descriptor is "pure data + factory" - it only provides the hook and factory
|
|
|
111
111
|
- **`src/core/control-descriptor.ts`**: `SqlFamilyDescriptor` class implementing `ControlFamilyDescriptor` interface (pure data + factory)
|
|
112
112
|
- **`src/core/control-instance.ts`**: `createSqlFamilyInstance` function that creates `SqlFamilyInstance` with domain action methods (`validateContract`, `verify`, `schemaVerify`, `introspect`, `toSchemaView`, `emitContract`). Contains `convertOperationManifest` function used internally by instance creation and test utilities in the same package.
|
|
113
113
|
- **`src/core/assembly.ts`**: Assembly helpers for extracting type imports, collecting codec-owned storage type control hooks, and composing mutation-default registries with duplicate detection.
|
|
114
|
-
- **`src/core/verify.ts`**: Verification helpers (`
|
|
114
|
+
- **`src/core/verify.ts`**: Verification helpers (`parseContractMarkerRow`, `collectSupportedCodecTypeIds`)
|
|
115
115
|
- **`src/core/control-adapter.ts`**: SQL control adapter interface (`SqlControlAdapter`) for control-plane operations
|
|
116
116
|
- **`src/core/migrations/`**: Migration IR helpers plus planner and runner SPI types (`MigrationPlanner`, `MigrationRunner`, `SqlControlTargetDescriptor`). Runners return `MigrationRunnerResult` which is a union of success/failure.
|
|
117
117
|
- **`src/core/migrations/contract-to-schema-ir.ts`**: `contractToSchemaIR(contract, { annotationNamespace, ... })` converts a contract to `SqlSchemaIR` for offline migration planning (used by `migration plan` to synthesize the "from" schema without a database connection). Also exports `detectDestructiveChanges(from, to)` which compares two `SqlStorage` values and returns a list of destructive changes (dropped tables, dropped columns) for migration policy enforcement.
|
|
@@ -135,7 +135,7 @@ The runner returns structured errors with the following codes:
|
|
|
135
135
|
- **`./control`**: Control plane entry point for CLI/config usage (exports `SqlFamilyDescriptor`)
|
|
136
136
|
- **`./control-adapter`**: SQL control adapter interface (`SqlControlAdapter`, `SqlControlAdapterDescriptor`) for target-specific adapters
|
|
137
137
|
- **`./runtime`**: Runtime plane identity exports only (family ID, types, descriptor identity). Does **not** export runtime creation helpers—use `instantiateExecutionStack` from `@prisma-next/framework-components/execution` and `createExecutionContext`, `createRuntime`, `createSqlExecutionStack` from `@prisma-next/sql-runtime`. See [ADR 152](../../../docs/architecture%20docs/adrs/ADR%20152%20-%20Execution%20Plane%20Descriptors%20and%20Instances.md).
|
|
138
|
-
- **`./verify`**:
|
|
138
|
+
- **`./verify`**: Marker row parsing helper (`parseContractMarkerRow`). Marker reads are owned by each `SqlControlAdapter` (e.g. `PostgresControlAdapter.readMarker`) so dialect-specific SQL stays target-local.
|
|
139
139
|
|
|
140
140
|
## Dependencies
|
|
141
141
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { n as NativeTypeNormalizer, t as DefaultNormalizer } from "./verify-sql-schema-
|
|
2
|
-
import { ControlAdapterInstance, ControlDriverInstance } from "@prisma-next/framework-components/control";
|
|
1
|
+
import { n as NativeTypeNormalizer, t as DefaultNormalizer } from "./verify-sql-schema-_EoNcGIq.mjs";
|
|
2
|
+
import { ControlAdapterInstance, ControlDriverInstance, ControlStack } from "@prisma-next/framework-components/control";
|
|
3
|
+
import { ContractMarkerRecord } from "@prisma-next/contract/types";
|
|
4
|
+
import { AnyQueryAst, LoweredStatement, LowererContext } from "@prisma-next/sql-relational-core/ast";
|
|
3
5
|
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
4
6
|
|
|
5
7
|
//#region src/core/control-adapter.d.ts
|
|
@@ -11,6 +13,16 @@ import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
|
11
13
|
* @template TTarget - The target ID (e.g., 'postgres', 'mysql')
|
|
12
14
|
*/
|
|
13
15
|
interface SqlControlAdapter<TTarget extends string = string> extends ControlAdapterInstance<'sql', TTarget> {
|
|
16
|
+
/**
|
|
17
|
+
* Reads the contract marker from the database, returning `null` if the marker
|
|
18
|
+
* table or its row is missing. Implementations are responsible for the
|
|
19
|
+
* dialect-specific existence probe (e.g. Postgres `information_schema.tables`
|
|
20
|
+
* vs SQLite `sqlite_master`) and parameter placeholders.
|
|
21
|
+
*
|
|
22
|
+
* @param driver - ControlDriverInstance for executing queries (target-specific)
|
|
23
|
+
* @returns Resolved marker record, or `null` if not yet stamped.
|
|
24
|
+
*/
|
|
25
|
+
readMarker(driver: ControlDriverInstance<'sql', TTarget>): Promise<ContractMarkerRecord | null>;
|
|
14
26
|
/**
|
|
15
27
|
* Introspects a database schema and returns a raw SqlSchemaIR.
|
|
16
28
|
*
|
|
@@ -36,6 +48,16 @@ interface SqlControlAdapter<TTarget extends string = string> extends ControlAdap
|
|
|
36
48
|
* before comparison with contract native types during schema verification.
|
|
37
49
|
*/
|
|
38
50
|
readonly normalizeNativeType?: NativeTypeNormalizer;
|
|
51
|
+
/**
|
|
52
|
+
* Lower a SQL query AST into a target-flavored `{ sql, params }` payload.
|
|
53
|
+
*
|
|
54
|
+
* Migration tooling (e.g. the `dataTransform` operation) needs to materialize
|
|
55
|
+
* SQL at emit/plan time without instantiating the runtime adapter. The control
|
|
56
|
+
* adapter's `lower` is byte-equivalent to the runtime adapter's `lower` for the
|
|
57
|
+
* same AST and contract, ensuring planned SQL matches what the runtime would
|
|
58
|
+
* emit.
|
|
59
|
+
*/
|
|
60
|
+
lower(ast: AnyQueryAst, context: LowererContext<unknown>): LoweredStatement;
|
|
39
61
|
}
|
|
40
62
|
/**
|
|
41
63
|
* SQL control adapter descriptor interface.
|
|
@@ -46,8 +68,11 @@ interface SqlControlAdapter<TTarget extends string = string> extends ControlAdap
|
|
|
46
68
|
interface SqlControlAdapterDescriptor<TTarget extends string = string> {
|
|
47
69
|
/**
|
|
48
70
|
* Creates a SQL control adapter instance for control-plane operations.
|
|
71
|
+
*
|
|
72
|
+
* Receives the assembled `ControlStack` so adapters can read aggregated
|
|
73
|
+
* metadata (codec lookup, extension contributions) when materializing.
|
|
49
74
|
*/
|
|
50
|
-
create(): SqlControlAdapter<TTarget>;
|
|
75
|
+
create(stack: ControlStack<'sql', TTarget>): SqlControlAdapter<TTarget>;
|
|
51
76
|
}
|
|
52
77
|
//#endregion
|
|
53
78
|
export { type SqlControlAdapter, type SqlControlAdapterDescriptor };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-adapter.d.mts","names":[],"sources":["../src/core/control-adapter.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"control-adapter.d.mts","names":[],"sources":["../src/core/control-adapter.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAoBA;;;;AAWqE,UAXpD,iBAWoD,CAAA,gBAAA,MAAA,GAAA,MAAA,CAAA,SAV3D,sBAU2D,CAAA,KAAA,EAV7B,OAU6B,CAAA,CAAA;EAAR;;;;;;;;;EA2CA,UAAA,CAAA,MAAA,EA3CxC,qBA2CwC,CAAA,KAAA,EA3CX,OA2CW,CAAA,CAAA,EA3CA,OA2CA,CA3CQ,oBA2CR,GAAA,IAAA,CAAA;EArDnD;;AA8DV;;;;;;;;;;qBArCY,6BAA6B,gDAGpC,QAAQ;;;;;;8BAOiB;;;;;;iCAOG;;;;;;;;;;aAWpB,sBAAsB,0BAA0B;;;;;;;;UAS5C;;;;;;;gBAOD,oBAAoB,WAAW,kBAAkB"}
|
package/dist/control.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { A as SqlPlannerFailureResult, C as SqlMigrationRunnerFailure, D as SqlPlannerConflict, E as SqlPlanTargetDetails, F as isDatabaseDependencyProvider, I as SchemaVerifyOptions, L as SqlControlFamilyInstance, M as SqlPlannerSuccessResult, N as StorageTypePlanResult, O as SqlPlannerConflictKind, P as collectInitDependencies, S as SqlMigrationRunnerExecuteOptions, T as SqlMigrationRunnerSuccessValue, _ as SqlMigrationPlanner, a as ComponentDatabaseDependency, b as SqlMigrationRunnerErrorCode, c as ResolveIdentityValueInput, d as SqlControlTargetDescriptor, f as SqlMigrationPlan, g as SqlMigrationPlanOperationTarget, h as SqlMigrationPlanOperationStep, i as ComponentDatabaseDependencies, j as SqlPlannerResult, k as SqlPlannerConflictLocation, l as SqlControlAdapterDescriptor, m as SqlMigrationPlanOperation, n as AnySqlMigrationOperation, o as CreateSqlMigrationPlanOptions, p as SqlMigrationPlanContractInfo, r as CodecControlHooks, s as ExpandNativeTypeInput, t as AnyRecord, u as SqlControlExtensionDescriptor, v as SqlMigrationPlannerPlanOptions, w as SqlMigrationRunnerResult, x as SqlMigrationRunnerExecuteCallbacks, y as SqlMigrationRunner } from "./types-
|
|
1
|
+
import { A as SqlPlannerFailureResult, C as SqlMigrationRunnerFailure, D as SqlPlannerConflict, E as SqlPlanTargetDetails, F as isDatabaseDependencyProvider, I as SchemaVerifyOptions, L as SqlControlFamilyInstance, M as SqlPlannerSuccessResult, N as StorageTypePlanResult, O as SqlPlannerConflictKind, P as collectInitDependencies, S as SqlMigrationRunnerExecuteOptions, T as SqlMigrationRunnerSuccessValue, _ as SqlMigrationPlanner, a as ComponentDatabaseDependency, b as SqlMigrationRunnerErrorCode, c as ResolveIdentityValueInput, d as SqlControlTargetDescriptor, f as SqlMigrationPlan, g as SqlMigrationPlanOperationTarget, h as SqlMigrationPlanOperationStep, i as ComponentDatabaseDependencies, j as SqlPlannerResult, k as SqlPlannerConflictLocation, l as SqlControlAdapterDescriptor, m as SqlMigrationPlanOperation, n as AnySqlMigrationOperation, o as CreateSqlMigrationPlanOptions, p as SqlMigrationPlanContractInfo, r as CodecControlHooks, s as ExpandNativeTypeInput, t as AnyRecord, u as SqlControlExtensionDescriptor, v as SqlMigrationPlannerPlanOptions, w as SqlMigrationRunnerResult, x as SqlMigrationRunnerExecuteCallbacks, y as SqlMigrationRunner } from "./types-gLyIyd2X.mjs";
|
|
2
2
|
import { ControlFamilyDescriptor, ControlStack, MigrationOperationClass, MigrationOperationPolicy, MigrationOperationPolicy as MigrationOperationPolicy$1, MigrationPlan, MigrationPlanOperation, MigrationPlanner, MigrationPlannerConflict, MigrationPlannerConflict as MigrationPlannerConflict$1, MigrationPlannerResult, TargetMigrationsCapability, assembleAuthoringContributions } from "@prisma-next/framework-components/control";
|
|
3
3
|
import { NotOk, Ok } from "@prisma-next/utils/result";
|
|
4
|
-
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
5
4
|
import * as _prisma_next_contract_types0 from "@prisma-next/contract/types";
|
|
6
5
|
import { ColumnDefault, Contract } from "@prisma-next/contract/types";
|
|
6
|
+
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
7
7
|
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
8
8
|
import { SqlStorage, StorageColumn } from "@prisma-next/sql-contract/types";
|
|
9
9
|
import * as _prisma_next_framework_components_emission0 from "@prisma-next/framework-components/emission";
|
|
@@ -20,6 +20,7 @@ declare class SqlFamilyDescriptor implements ControlFamilyDescriptor<'sql', SqlC
|
|
|
20
20
|
readonly validateStructure: (contract: _prisma_next_contract_types0.Contract) => void;
|
|
21
21
|
readonly generateStorageType: (contract: _prisma_next_contract_types0.Contract, storageHashTypeName: string) => string;
|
|
22
22
|
readonly generateModelStorageType: (_modelName: string, model: _prisma_next_contract_types0.ContractModel) => string;
|
|
23
|
+
readonly resolveFieldTypeParams: (_modelName: string, fieldName: string, model: _prisma_next_contract_types0.ContractModel, contract: _prisma_next_contract_types0.Contract) => Record<string, unknown> | undefined;
|
|
23
24
|
readonly getFamilyImports: () => string[];
|
|
24
25
|
readonly getFamilyTypeAliases: (options?: _prisma_next_framework_components_emission0.GenerateContractTypesOptions) => string;
|
|
25
26
|
readonly getTypeMapsExpression: () => string;
|
package/dist/control.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-descriptor.ts","../src/core/assembly.ts","../src/core/migrations/contract-to-schema-ir.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/exports/control.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;cASa,mBAAA,YACA,+BAA+B;;;;;;;uCAAwB,4BAAA,CAAA;;IADvD,SAAA,mBACX,EAAA,CAAA,QAAA,uCAAA,EAAA,mBAAA,EAAA,MAAA,EAAA,GAAA,MAAA;IAA0C,SAAA,wBAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,KAAA,4CAAA,EAAA,GAAA,MAAA;IAAwB,SAAA,
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-descriptor.ts","../src/core/assembly.ts","../src/core/migrations/contract-to-schema-ir.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/exports/control.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;cASa,mBAAA,YACA,+BAA+B;;;;;;;uCAAwB,4BAAA,CAAA;;IADvD,SAAA,mBACX,EAAA,CAAA,QAAA,uCAAA,EAAA,mBAAA,EAAA,MAAA,EAAA,GAAA,MAAA;IAA0C,SAAA,wBAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,KAAA,4CAAA,EAAA,GAAA,MAAA;IAAwB,SAAA,sBAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,SAAA,EAAA,MAAA,EAAA,KAAA,4CAAA,EAAA,QAAA,uCAAA,EAAA,SAAA,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,SAAA;;0FAY5C;;;;;;;QACO,SAAA,IAAA,EAAA,aAAA;QAApB,SAAA,MAAA,EAAA;UACN,SAAA,OAAA,EAAA,YAAA;UAdQ,SAAA,UAAA,EAAA,WAAA;UAAuB,SAAA,UAAA,EAAA;;;;MCYpB,CAAA;MACa,SAAA,IAAA,EAAA;QAAd,SAAA,IAAA,EAAA,aAAA;QACA,SAAA,MAAA,EAAA;UAAZ,SAAA,OAAA,EAAA,YAA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