@prisma-next/family-sql 0.0.1
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 +90 -0
- package/dist/exports/control-adapter.d.ts +44 -0
- package/dist/exports/control-adapter.js +1 -0
- package/dist/exports/control-adapter.js.map +1 -0
- package/dist/exports/control.d.ts +148 -0
- package/dist/exports/control.js +1439 -0
- package/dist/exports/control.js.map +1 -0
- package/dist/exports/index-Bi3Sr19r.d.ts +28 -0
- package/dist/exports/runtime.d.ts +296 -0
- package/dist/exports/runtime.js +71 -0
- package/dist/exports/runtime.js.map +1 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# @prisma-next/family-sql
|
|
2
|
+
|
|
3
|
+
SQL family descriptor for Prisma Next.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides the SQL family descriptor (`ControlFamilyDescriptor`) that includes:
|
|
8
|
+
- The SQL target family hook (`sqlTargetFamilyHook`)
|
|
9
|
+
- Factory method (`create()`) to create family instances
|
|
10
|
+
|
|
11
|
+
## Responsibilities
|
|
12
|
+
|
|
13
|
+
- **Family Descriptor Export**: Exports the SQL `ControlFamilyDescriptor` for use in CLI configuration files
|
|
14
|
+
- **Family Instance Creation**: Creates `SqlFamilyInstance` objects that implement control-plane domain actions (`verify`, `schemaVerify`, `introspect`, `emitContract`, `validateContractIR`)
|
|
15
|
+
- **Family Hook Integration**: Integrates the SQL target family hook (`sqlTargetFamilyHook`) from `@prisma-next/sql-contract-emitter`
|
|
16
|
+
- **Control Plane Entry Point**: Serves as the control plane entry point for the SQL family, enabling the CLI to select the family hook and create family instances
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import sql from '@prisma-next/family-sql/control';
|
|
22
|
+
|
|
23
|
+
// sql is a ControlFamilyDescriptor with:
|
|
24
|
+
// - kind: 'family'
|
|
25
|
+
// - id: 'sql'
|
|
26
|
+
// - familyId: 'sql'
|
|
27
|
+
// - hook: TargetFamilyHook
|
|
28
|
+
// - create: (options) => SqlFamilyInstance
|
|
29
|
+
|
|
30
|
+
// Create a family instance for control-plane operations
|
|
31
|
+
const familyInstance = sql.create({
|
|
32
|
+
target: postgresTargetDescriptor,
|
|
33
|
+
adapter: postgresAdapterDescriptor,
|
|
34
|
+
driver: postgresDriverDescriptor, // Required
|
|
35
|
+
extensions: [pgVectorExtensionDescriptor],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Use instance methods for domain actions
|
|
39
|
+
const contractIR = familyInstance.validateContractIR(contractJson);
|
|
40
|
+
const verifyResult = await familyInstance.verify({ driver, contractIR, ... });
|
|
41
|
+
const emitResult = await familyInstance.emitContract({ contractIR: rawContract }); // Handles stripping mappings and validation internally
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Architecture
|
|
45
|
+
|
|
46
|
+
This package is the control plane entry point for the SQL family. It composes:
|
|
47
|
+
- `@prisma-next/sql-contract-emitter` - Provides the SQL family hook
|
|
48
|
+
- `@prisma-next/sql-operations` - SQL operation signature types
|
|
49
|
+
- `@prisma-next/sql-contract-ts` - Contract validation
|
|
50
|
+
|
|
51
|
+
The framework CLI uses this descriptor to:
|
|
52
|
+
1. Create family instances for control-plane operations (via `create()`)
|
|
53
|
+
|
|
54
|
+
Family instances implement domain actions:
|
|
55
|
+
- **`validateContractIR(contractJson)`**: Validates and normalizes contract, returns ContractIR without mappings
|
|
56
|
+
- **`verify()`**: Verifies database marker against contract (compares target, coreHash, profileHash)
|
|
57
|
+
- **`schemaVerify()`**: Verifies database schema against contract (compares contract requirements vs live schema)
|
|
58
|
+
- **`introspect()`**: Introspects database schema and returns `SqlSchemaIR`
|
|
59
|
+
- **`toSchemaView(schema)`**: Projects `SqlSchemaIR` into `CoreSchemaView` for human-readable display. Always displays native database types (e.g., `int4`, `text`) rather than mapped codec IDs (e.g., `pg/int4@1`) to reflect actual database state.
|
|
60
|
+
- **`emitContract({ contractIR })`**: Emits contract JSON and DTS as strings. Handles stripping mappings and validation internally. Uses preassembled state (operation registry, type imports, extension IDs).
|
|
61
|
+
|
|
62
|
+
The descriptor is "pure data + factory" - it only provides the hook and factory method. All family-specific logic lives on the instance.
|
|
63
|
+
|
|
64
|
+
## Package Structure
|
|
65
|
+
|
|
66
|
+
- **`src/core/descriptor.ts`**: `SqlFamilyDescriptor` class implementing `ControlFamilyDescriptor` interface (pure data + factory)
|
|
67
|
+
- **`src/core/instance.ts`**: `createSqlFamilyInstance` function that creates `SqlFamilyInstance` with domain action methods (`validateContractIR`, `verify`, `schemaVerify`, `introspect`, `toSchemaView`, `emitContract`). Contains `convertOperationManifest` function used internally by instance creation and test utilities in the same package.
|
|
68
|
+
- **`src/core/assembly.ts`**: Assembly helpers for building operation registries and extracting type imports from descriptors. Test utilities import `convertOperationManifest` from the same package via relative path.
|
|
69
|
+
- **`src/core/verify.ts`**: Verification helpers (`readMarker`, `collectSupportedCodecTypeIds`)
|
|
70
|
+
- **`src/core/control-adapter.ts`**: SQL control adapter interface (`SqlControlAdapter`) for control-plane operations
|
|
71
|
+
- **`src/exports/control.ts`**: Control plane entry point (exports `SqlFamilyDescriptor` instance)
|
|
72
|
+
- **`src/exports/runtime.ts`**: Runtime entry point (placeholder for future functionality)
|
|
73
|
+
|
|
74
|
+
## Entrypoints
|
|
75
|
+
|
|
76
|
+
- **`./control`**: Control plane entry point for CLI/config usage (exports `SqlFamilyDescriptor`)
|
|
77
|
+
- **`./control-adapter`**: SQL control adapter interface (`SqlControlAdapter`, `SqlControlAdapterDescriptor`) for target-specific adapters
|
|
78
|
+
- **`./runtime`**: Runtime entry point (placeholder for future functionality)
|
|
79
|
+
|
|
80
|
+
## Dependencies
|
|
81
|
+
|
|
82
|
+
- **`@prisma-next/core-control-plane`**: Control plane types (`ControlFamilyDescriptor`, `ControlTargetDescriptor`, `ControlAdapterDescriptor`, `ControlDriverDescriptor`, `ControlExtensionDescriptor`, `ControlDriverInstance`, etc.)
|
|
83
|
+
- **`@prisma-next/sql-contract-emitter`**: SQL target family hook (`sqlTargetFamilyHook`)
|
|
84
|
+
- **`@prisma-next/sql-contract-ts`**: Contract validation (`validateContract`)
|
|
85
|
+
- **`@prisma-next/sql-contract`**: SQL contract types (`SqlContract`, `SqlStorage`)
|
|
86
|
+
- **`@prisma-next/sql-operations`**: SQL operation signature types (`SqlOperationSignature`)
|
|
87
|
+
|
|
88
|
+
**Dependents:**
|
|
89
|
+
- CLI configuration files import this package to register the SQL family
|
|
90
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ControlAdapterInstance, ControlDriverInstance } from '@prisma-next/core-control-plane/types';
|
|
2
|
+
import { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SQL control adapter interface for control-plane operations.
|
|
6
|
+
* Implemented by target-specific adapters (e.g., Postgres, MySQL).
|
|
7
|
+
*
|
|
8
|
+
* @template TTarget - The target ID (e.g., 'postgres', 'mysql')
|
|
9
|
+
*/
|
|
10
|
+
interface SqlControlAdapter<TTarget extends string = string> extends ControlAdapterInstance<'sql', TTarget> {
|
|
11
|
+
/**
|
|
12
|
+
* The target ID this adapter implements.
|
|
13
|
+
* Used for type tracking and runtime validation.
|
|
14
|
+
* @deprecated Use targetId from ControlAdapterInstance instead
|
|
15
|
+
*/
|
|
16
|
+
readonly target: TTarget;
|
|
17
|
+
/**
|
|
18
|
+
* Introspects a database schema and returns a raw SqlSchemaIR.
|
|
19
|
+
*
|
|
20
|
+
* This is a pure schema discovery operation that queries the database catalog
|
|
21
|
+
* and returns the schema structure without type mapping or contract enrichment.
|
|
22
|
+
* Type mapping and enrichment are handled separately by enrichment helpers.
|
|
23
|
+
*
|
|
24
|
+
* @param driver - ControlDriverInstance instance for executing queries (target-specific)
|
|
25
|
+
* @param contractIR - Optional contract IR for contract-guided introspection (filtering, optimization)
|
|
26
|
+
* @param schema - Schema name to introspect (defaults to 'public')
|
|
27
|
+
* @returns Promise resolving to SqlSchemaIR representing the live database schema
|
|
28
|
+
*/
|
|
29
|
+
introspect(driver: ControlDriverInstance<TTarget>, contractIR?: unknown, schema?: string): Promise<SqlSchemaIR>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* SQL control adapter descriptor interface.
|
|
33
|
+
* Provides a factory method to create control adapter instances.
|
|
34
|
+
*
|
|
35
|
+
* @template TTarget - The target ID (e.g., 'postgres', 'mysql')
|
|
36
|
+
*/
|
|
37
|
+
interface SqlControlAdapterDescriptor<TTarget extends string = string> {
|
|
38
|
+
/**
|
|
39
|
+
* Creates a SQL control adapter instance for control-plane operations.
|
|
40
|
+
*/
|
|
41
|
+
create(): SqlControlAdapter<TTarget>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type { SqlControlAdapter, SqlControlAdapterDescriptor };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=control-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import * as _prisma_next_sql_contract_types from '@prisma-next/sql-contract/types';
|
|
2
|
+
import * as _prisma_next_contract from '@prisma-next/contract';
|
|
3
|
+
import * as _prisma_next_contract_ir from '@prisma-next/contract/ir';
|
|
4
|
+
import { ContractIR } from '@prisma-next/contract/ir';
|
|
5
|
+
import { ExtensionPackManifest } from '@prisma-next/contract/pack-manifest-types';
|
|
6
|
+
import { ControlFamilyInstance, ControlDriverInstance, VerifyDatabaseResult, VerifyDatabaseSchemaResult, SignDatabaseResult, EmitContractResult, ControlFamilyDescriptor, ControlTargetDescriptor, ControlAdapterDescriptor, ControlDriverDescriptor, ControlExtensionDescriptor } from '@prisma-next/core-control-plane/types';
|
|
7
|
+
import { TypesImportSpec } from '@prisma-next/contract/types';
|
|
8
|
+
import { CoreSchemaView } from '@prisma-next/core-control-plane/schema-view';
|
|
9
|
+
import { O as OperationRegistry } from './index-Bi3Sr19r.js';
|
|
10
|
+
import { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Type metadata for SQL storage types.
|
|
14
|
+
* Maps contract storage type IDs to native database types.
|
|
15
|
+
*/
|
|
16
|
+
interface SqlTypeMetadata {
|
|
17
|
+
readonly typeId: string;
|
|
18
|
+
readonly familyId: 'sql';
|
|
19
|
+
readonly targetId: string;
|
|
20
|
+
readonly nativeType?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Registry mapping type IDs to their metadata.
|
|
24
|
+
* Keyed by contract storage type ID (e.g., 'pg/int4@1').
|
|
25
|
+
*/
|
|
26
|
+
type SqlTypeMetadataRegistry = Map<string, SqlTypeMetadata>;
|
|
27
|
+
/**
|
|
28
|
+
* State fields for SQL family instance that hold assembly data.
|
|
29
|
+
*/
|
|
30
|
+
interface SqlFamilyInstanceState {
|
|
31
|
+
readonly operationRegistry: OperationRegistry;
|
|
32
|
+
readonly codecTypeImports: ReadonlyArray<TypesImportSpec>;
|
|
33
|
+
readonly operationTypeImports: ReadonlyArray<TypesImportSpec>;
|
|
34
|
+
readonly extensionIds: ReadonlyArray<string>;
|
|
35
|
+
readonly typeMetadataRegistry: SqlTypeMetadataRegistry;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* SQL control family instance interface.
|
|
39
|
+
* Extends ControlFamilyInstance with SQL-specific domain actions.
|
|
40
|
+
*/
|
|
41
|
+
interface SqlControlFamilyInstance extends ControlFamilyInstance<'sql'>, SqlFamilyInstanceState {
|
|
42
|
+
/**
|
|
43
|
+
* Validates a contract JSON and returns a validated ContractIR (without mappings).
|
|
44
|
+
* Mappings are runtime-only and should not be part of ContractIR.
|
|
45
|
+
*/
|
|
46
|
+
validateContractIR(contractJson: unknown): unknown;
|
|
47
|
+
/**
|
|
48
|
+
* Verifies the database marker against the contract.
|
|
49
|
+
* Compares target, coreHash, and profileHash.
|
|
50
|
+
*/
|
|
51
|
+
verify(options: {
|
|
52
|
+
readonly driver: ControlDriverInstance;
|
|
53
|
+
readonly contractIR: unknown;
|
|
54
|
+
readonly expectedTargetId: string;
|
|
55
|
+
readonly contractPath: string;
|
|
56
|
+
readonly configPath?: string;
|
|
57
|
+
}): Promise<VerifyDatabaseResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Verifies the database schema against the contract.
|
|
60
|
+
* Compares contract requirements against live database schema.
|
|
61
|
+
*/
|
|
62
|
+
schemaVerify(options: {
|
|
63
|
+
readonly driver: ControlDriverInstance;
|
|
64
|
+
readonly contractIR: unknown;
|
|
65
|
+
readonly strict: boolean;
|
|
66
|
+
readonly contractPath: string;
|
|
67
|
+
readonly configPath?: string;
|
|
68
|
+
}): Promise<VerifyDatabaseSchemaResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Signs the database with the contract marker.
|
|
71
|
+
* Writes or updates the contract marker if schema verification passes.
|
|
72
|
+
* This operation is idempotent - if the marker already matches, no changes are made.
|
|
73
|
+
*/
|
|
74
|
+
sign(options: {
|
|
75
|
+
readonly driver: ControlDriverInstance;
|
|
76
|
+
readonly contractIR: unknown;
|
|
77
|
+
readonly contractPath: string;
|
|
78
|
+
readonly configPath?: string;
|
|
79
|
+
}): Promise<SignDatabaseResult>;
|
|
80
|
+
/**
|
|
81
|
+
* Introspects the database schema and returns a family-specific schema IR.
|
|
82
|
+
*
|
|
83
|
+
* This is a read-only operation that returns a snapshot of the live database schema.
|
|
84
|
+
* The method is family-owned and delegates to target/adapter-specific introspectors
|
|
85
|
+
* to perform the actual schema introspection.
|
|
86
|
+
*
|
|
87
|
+
* @param options - Introspection options
|
|
88
|
+
* @param options.driver - Control plane driver for database connection
|
|
89
|
+
* @param options.contractIR - Optional contract IR for contract-guided introspection.
|
|
90
|
+
* When provided, families may use it for filtering, optimization, or validation
|
|
91
|
+
* during introspection. The contract IR does not change the meaning of "what exists"
|
|
92
|
+
* in the database - it only guides how introspection is performed.
|
|
93
|
+
* @returns Promise resolving to the family-specific Schema IR (e.g., `SqlSchemaIR` for SQL).
|
|
94
|
+
* The IR represents the complete schema snapshot at the time of introspection.
|
|
95
|
+
*/
|
|
96
|
+
introspect(options: {
|
|
97
|
+
readonly driver: ControlDriverInstance;
|
|
98
|
+
readonly contractIR?: unknown;
|
|
99
|
+
}): Promise<SqlSchemaIR>;
|
|
100
|
+
/**
|
|
101
|
+
* Projects a SQL Schema IR into a core schema view for CLI visualization.
|
|
102
|
+
* Converts SqlSchemaIR (tables, columns, indexes, extensions) into a tree structure.
|
|
103
|
+
*/
|
|
104
|
+
toSchemaView(schema: SqlSchemaIR): CoreSchemaView;
|
|
105
|
+
/**
|
|
106
|
+
* Emits contract JSON and DTS as strings.
|
|
107
|
+
* Uses the instance's preassembled state (operation registry, type imports, extension IDs).
|
|
108
|
+
* Handles stripping mappings and validation internally.
|
|
109
|
+
*/
|
|
110
|
+
emitContract(options: {
|
|
111
|
+
readonly contractIR: ContractIR | unknown;
|
|
112
|
+
}): Promise<EmitContractResult>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* SQL family descriptor implementation.
|
|
117
|
+
* Provides the SQL family hook and factory method.
|
|
118
|
+
*/
|
|
119
|
+
declare class SqlFamilyDescriptor implements ControlFamilyDescriptor<'sql', SqlControlFamilyInstance> {
|
|
120
|
+
readonly kind: "family";
|
|
121
|
+
readonly id = "sql";
|
|
122
|
+
readonly familyId: "sql";
|
|
123
|
+
readonly manifest: ExtensionPackManifest;
|
|
124
|
+
readonly hook: {
|
|
125
|
+
readonly id: "sql";
|
|
126
|
+
readonly validateTypes: (ir: _prisma_next_contract_ir.ContractIR, ctx: _prisma_next_contract.ValidationContext) => void;
|
|
127
|
+
readonly validateStructure: (ir: _prisma_next_contract_ir.ContractIR) => void;
|
|
128
|
+
readonly generateContractTypes: (ir: _prisma_next_contract_ir.ContractIR, codecTypeImports: ReadonlyArray<_prisma_next_contract.TypesImportSpec>, operationTypeImports: ReadonlyArray<_prisma_next_contract.TypesImportSpec>) => string;
|
|
129
|
+
readonly generateStorageType: (storage: _prisma_next_sql_contract_types.SqlStorage) => string;
|
|
130
|
+
readonly generateModelsType: (models: Record<string, _prisma_next_sql_contract_types.ModelDefinition> | undefined, storage: _prisma_next_sql_contract_types.SqlStorage) => string;
|
|
131
|
+
readonly generateRelationsType: (relations: Record<string, unknown> | undefined) => string;
|
|
132
|
+
readonly generateMappingsType: (models: Record<string, _prisma_next_sql_contract_types.ModelDefinition> | undefined, storage: _prisma_next_sql_contract_types.SqlStorage, codecTypes: string, operationTypes: string) => string;
|
|
133
|
+
};
|
|
134
|
+
create<TTargetId extends string>(options: {
|
|
135
|
+
readonly target: ControlTargetDescriptor<'sql', TTargetId>;
|
|
136
|
+
readonly adapter: ControlAdapterDescriptor<'sql', TTargetId>;
|
|
137
|
+
readonly driver: ControlDriverDescriptor<'sql', TTargetId>;
|
|
138
|
+
readonly extensions: readonly ControlExtensionDescriptor<'sql', TTargetId>[];
|
|
139
|
+
}): SqlControlFamilyInstance;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* SQL family descriptor for control plane (CLI/config).
|
|
144
|
+
* Provides the SQL family hook and conversion helpers.
|
|
145
|
+
*/
|
|
146
|
+
declare const _default: SqlFamilyDescriptor;
|
|
147
|
+
|
|
148
|
+
export { _default as default };
|