@prisma-next/contract 0.3.0-dev.140 → 0.3.0-dev.141
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 +38 -285
- package/dist/contract-types-x89nqTli.d.mts +49 -0
- package/dist/contract-types-x89nqTli.d.mts.map +1 -0
- package/dist/{hashing-CVS9sXxd.mjs → hashing-D1EPxYRl.mjs} +2 -2
- package/dist/{hashing-CVS9sXxd.mjs.map → hashing-D1EPxYRl.mjs.map} +1 -1
- package/dist/hashing.d.mts +1 -1
- package/dist/hashing.mjs +1 -1
- package/dist/testing.d.mts +3 -2
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +2 -2
- package/dist/testing.mjs.map +1 -1
- package/dist/{types-DokLaU9G.mjs → types-DYikGC04.mjs} +5 -2
- package/dist/types-DYikGC04.mjs.map +1 -0
- package/dist/{types-D-iOS0Ks.d.mts → types-DmKtoEd-.d.mts} +5 -213
- package/dist/types-DmKtoEd-.d.mts.map +1 -0
- package/dist/types.d.mts +3 -2
- package/dist/types.mjs +2 -2
- package/dist/validate-contract.d.mts +1 -1
- package/package.json +4 -5
- package/src/exports/types.ts +1 -9
- package/src/testing-factories.ts +1 -1
- package/src/types.ts +6 -201
- package/dist/types-D-iOS0Ks.d.mts.map +0 -1
- package/dist/types-DokLaU9G.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,148 +1,39 @@
|
|
|
1
1
|
# @prisma-next/contract
|
|
2
2
|
|
|
3
|
-
Core contract types
|
|
3
|
+
Core contract data types and JSON schemas for Prisma Next.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
This package provides the foundational type definitions for Prisma Next
|
|
8
|
-
- **Data contracts**: The canonical description of an application's data model and storage layout
|
|
9
|
-
- **Framework component descriptors**: Base interfaces for the modular component system (families, targets, adapters, drivers, extensions)
|
|
10
|
-
- **JSON Schemas**: Validation schemas for contract files
|
|
11
|
-
|
|
12
|
-
## Responsibilities
|
|
13
|
-
|
|
14
|
-
- **Core Contract Types**: Defines framework-level contract types (`ContractBase`, `Source`, `FamilyInstance`) that are shared across all target families
|
|
15
|
-
- **Framework Component Model**: Provides base descriptor interfaces (`FamilyDescriptor`, `TargetDescriptor`, `AdapterDescriptor`, `DriverDescriptor`, `ExtensionDescriptor`) and identity instance bases (`FamilyInstance`, `TargetInstance`, `AdapterInstance`, `DriverInstance`, `ExtensionInstance`) that plane-specific types extend
|
|
16
|
-
- **Document Family Types**: Provides TypeScript types for document target family contracts (`DocumentContract`)
|
|
17
|
-
- **Shared Column Defaults**: Defines `ColumnDefault` for db-agnostic defaults (literal and function) reused across family contracts and authoring builders
|
|
18
|
-
- **JSON Schema Validation**: Provides JSON Schemas for validating contract structure in IDEs and tooling
|
|
19
|
-
- **Type Guards**: Provides runtime type guards for narrowing contract types (`isDocumentContract`)
|
|
20
|
-
- **Emitter Types**: Defines emitter SPI types (`TargetFamilyHook`, `ValidationContext`, `TypesImportSpec`) that are shared between emitter and control plane
|
|
7
|
+
This package provides the foundational type definitions for Prisma Next data contracts:
|
|
21
8
|
|
|
22
|
-
The
|
|
23
|
-
- **
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
- **Contract data types**: The canonical description of an application's data model and storage layout (`ContractBase`, `DocumentContract`, `Source`, `FieldType`)
|
|
10
|
+
- **Plan types**: Target-family-agnostic execution plan types (`ExecutionPlan`, `PlanMeta`, `ParamDescriptor`)
|
|
11
|
+
- **Hash types**: Branded hash types for storage, execution, and profile hashing (`StorageHashBase`, `ExecutionHashBase`, `ProfileHashBase`)
|
|
12
|
+
- **JSON Schemas**: Validation schemas for contract files
|
|
13
|
+
- **Type guards**: Runtime type guards for narrowing contract types (`isDocumentContract`)
|
|
26
14
|
|
|
27
|
-
- **
|
|
28
|
-
- **Emitter Types**: SPI types for emitter hooks (`TargetFamilyHook`, `ValidationContext`, `TypesImportSpec`)
|
|
29
|
-
- **JSON Schemas**: Schema definitions for validating `contract.json` files in IDEs and tooling
|
|
30
|
-
- `data-contract-document-v1.json` (Document family)
|
|
15
|
+
This package is a **foundation-layer leaf** — it has no framework-domain dependencies and is consumed by all layers above it.
|
|
31
16
|
|
|
32
17
|
## Usage
|
|
33
18
|
|
|
34
|
-
### TypeScript Types
|
|
35
|
-
|
|
36
|
-
Import contract types in your TypeScript code:
|
|
37
|
-
|
|
38
19
|
```typescript
|
|
39
20
|
import type {
|
|
21
|
+
Contract,
|
|
40
22
|
ContractMarkerRecord,
|
|
41
23
|
DocumentContract,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
ValidationContext,
|
|
24
|
+
ExecutionPlan,
|
|
25
|
+
PlanMeta,
|
|
45
26
|
} from '@prisma-next/contract/types';
|
|
46
|
-
import { isDocumentContract } from '@prisma-next/contract/types';
|
|
47
|
-
|
|
48
|
-
// Use type guards to narrow the contract type
|
|
49
|
-
function processContract(contract: DocumentContract) {
|
|
50
|
-
if (isDocumentContract(contract)) {
|
|
51
|
-
// contract is DocumentContract
|
|
52
|
-
console.log(contract.storage.document.collections);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Use ContractMarkerRecord for database marker operations
|
|
57
|
-
function processMarker(marker: ContractMarkerRecord) {
|
|
58
|
-
console.log(marker.storageHash, marker.profileHash);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Use emitter types for implementing family hooks
|
|
62
|
-
const myFamilyHook: TargetFamilyHook = {
|
|
63
|
-
id: 'my-family',
|
|
64
|
-
validateTypes: (ir, ctx: ValidationContext) => {
|
|
65
|
-
// Validation logic
|
|
66
|
-
},
|
|
67
|
-
validateStructure: (ir) => {
|
|
68
|
-
// Structure validation
|
|
69
|
-
},
|
|
70
|
-
generateContractTypes: (ir, codecTypeImports: TypesImportSpec[], operationTypeImports: TypesImportSpec[]) => {
|
|
71
|
-
// Type generation
|
|
72
|
-
return '// Generated types...';
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### Framework Component Model
|
|
78
|
-
|
|
79
|
-
Import base descriptor and instance interfaces to define or type-check framework components:
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
import type {
|
|
83
|
-
// Descriptors
|
|
84
|
-
ComponentDescriptor,
|
|
85
|
-
FamilyDescriptor,
|
|
86
|
-
TargetDescriptor,
|
|
87
|
-
AdapterDescriptor,
|
|
88
|
-
DriverDescriptor,
|
|
89
|
-
ExtensionDescriptor,
|
|
90
|
-
// Instances
|
|
91
|
-
FamilyInstance,
|
|
92
|
-
TargetInstance,
|
|
93
|
-
AdapterInstance,
|
|
94
|
-
DriverInstance,
|
|
95
|
-
ExtensionInstance,
|
|
96
|
-
} from '@prisma-next/contract/framework-components';
|
|
97
|
-
|
|
98
|
-
// Component descriptors share common properties
|
|
99
|
-
interface MyDescriptor extends ComponentDescriptor<'custom'> {
|
|
100
|
-
readonly customField: string;
|
|
101
|
-
}
|
|
27
|
+
import { isDocumentContract, coreHash, profileHash } from '@prisma-next/contract/types';
|
|
102
28
|
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
kind: 'family',
|
|
106
|
-
id: 'sql',
|
|
107
|
-
familyId: 'sql',
|
|
108
|
-
version: '0.0.1',
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// Use TargetDescriptor for target components
|
|
112
|
-
const postgresTarget: TargetDescriptor<'sql', 'postgres'> = {
|
|
113
|
-
kind: 'target',
|
|
114
|
-
id: 'postgres',
|
|
115
|
-
familyId: 'sql',
|
|
116
|
-
targetId: 'postgres',
|
|
117
|
-
version: '0.0.1',
|
|
118
|
-
capabilities: { postgres: { returning: true } },
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
// Identity instance bases are extended by plane-specific instances
|
|
122
|
-
interface MySqlInstance extends FamilyInstance<'sql'> {
|
|
123
|
-
// Plane-specific methods...
|
|
29
|
+
if (isDocumentContract(contract)) {
|
|
30
|
+
const collections = contract.storage.document.collections;
|
|
124
31
|
}
|
|
125
32
|
```
|
|
126
33
|
|
|
127
|
-
The component hierarchy is:
|
|
128
|
-
|
|
129
|
-
```
|
|
130
|
-
Family (e.g., 'sql', 'document')
|
|
131
|
-
└── Target (e.g., 'postgres', 'mysql', 'mongodb')
|
|
132
|
-
├── Adapter (protocol/dialect implementation)
|
|
133
|
-
├── Driver (connection/execution layer)
|
|
134
|
-
└── Extension (optional capabilities like pgvector)
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
Plane-specific descriptors (`ControlFamilyDescriptor`, `RuntimeTargetDescriptor`, etc.) extend these bases with plane-specific factory methods and capabilities.
|
|
138
|
-
|
|
139
34
|
### JSON Schema Validation
|
|
140
35
|
|
|
141
|
-
Reference the appropriate JSON schema in your `contract.json` files to enable IDE validation
|
|
142
|
-
|
|
143
|
-
#### Document Family
|
|
144
|
-
|
|
145
|
-
For document targets (MongoDB, Firestore, etc.):
|
|
36
|
+
Reference the appropriate JSON schema in your `contract.json` files to enable IDE validation:
|
|
146
37
|
|
|
147
38
|
```json
|
|
148
39
|
{
|
|
@@ -150,189 +41,51 @@ For document targets (MongoDB, Firestore, etc.):
|
|
|
150
41
|
"schemaVersion": "1",
|
|
151
42
|
"target": "mongodb",
|
|
152
43
|
"targetFamily": "document",
|
|
153
|
-
"storageHash": "sha256:..."
|
|
154
|
-
"storage": {
|
|
155
|
-
"document": {
|
|
156
|
-
"collections": {
|
|
157
|
-
"users": {
|
|
158
|
-
"name": "users",
|
|
159
|
-
"fields": {
|
|
160
|
-
"id": { "type": "objectId", "nullable": false },
|
|
161
|
-
"email": { "type": "string", "nullable": false }
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
44
|
+
"storageHash": "sha256:..."
|
|
167
45
|
}
|
|
168
46
|
```
|
|
169
47
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
```json
|
|
173
|
-
{
|
|
174
|
-
"$schema": "node_modules/@prisma-next/sql-query/schemas/data-contract-sql-v1.json",
|
|
175
|
-
"schemaVersion": "1",
|
|
176
|
-
"target": "postgres",
|
|
177
|
-
"targetFamily": "sql",
|
|
178
|
-
"storageHash": "sha256:...",
|
|
179
|
-
"storage": {
|
|
180
|
-
"tables": {
|
|
181
|
-
"user": {
|
|
182
|
-
"columns": {
|
|
183
|
-
"id": { "type": "int4", "nullable": false },
|
|
184
|
-
"email": { "type": "text", "nullable": false }
|
|
185
|
-
},
|
|
186
|
-
"primaryKey": {
|
|
187
|
-
"columns": ["id"],
|
|
188
|
-
"name": "user_pkey"
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
After installing this package, IDEs like VS Code will automatically:
|
|
197
|
-
- Validate your contract structure
|
|
198
|
-
- Provide autocomplete for properties
|
|
199
|
-
- Show descriptions and constraints in tooltips
|
|
200
|
-
- Highlight errors for invalid configurations
|
|
201
|
-
|
|
202
|
-
## Schema Reference
|
|
48
|
+
For SQL contracts, use `@prisma-next/sql-contract-ts/schemas/data-contract-sql-v1.json` instead.
|
|
203
49
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
All contracts share these common fields:
|
|
207
|
-
|
|
208
|
-
- **`schemaVersion`** (required): Contract schema version (currently `"1"`)
|
|
209
|
-
- **`target`** (required): Database target identifier (e.g., `"postgres"`, `"mongo"`, `"firestore"`)
|
|
210
|
-
- **`targetFamily`** (required): Target family classification (`"document"` for document contracts)
|
|
211
|
-
- **`storageHash`** (required): SHA-256 hash of the storage schema structure
|
|
212
|
-
- **`executionHash`** (optional): SHA-256 hash of execution-time mutation defaults
|
|
213
|
-
- **`profileHash`** (optional): SHA-256 hash of the capability profile
|
|
214
|
-
- **`capabilities`** (optional): Capability flags declared by the contract
|
|
215
|
-
- **`extensionPacks`** (optional): Extension packs and their configuration
|
|
216
|
-
- **`meta`** (optional): Non-semantic metadata (excluded from hashing)
|
|
217
|
-
- **`sources`** (optional): Read-only sources (views, etc.) available for querying
|
|
218
|
-
|
|
219
|
-
### Document Family Structure
|
|
220
|
-
|
|
221
|
-
- **`storage.document.collections`**: Object mapping collection names to collection definitions
|
|
222
|
-
- Each collection includes:
|
|
223
|
-
- **`name`**: Logical collection name
|
|
224
|
-
- **`id`** (optional): ID generation strategy (`auto`, `client`, `uuid`, `objectId`)
|
|
225
|
-
- **`fields`**: Field definitions using `FieldType` (supports nested objects and arrays)
|
|
226
|
-
- **`indexes`** (optional): Array of index definitions with keys and optional predicates
|
|
227
|
-
- **`readOnly`** (optional): Whether mutations are disallowed
|
|
228
|
-
|
|
229
|
-
## Column Defaults
|
|
230
|
-
|
|
231
|
-
### Key Points
|
|
232
|
-
|
|
233
|
-
- When adding column defaults, re-emit the contract and verify the emitted JSON includes the full default payload.
|
|
234
|
-
- Keep `nullable: false` explicit for columns with defaults in emitted contracts.
|
|
235
|
-
- Literal defaults must include a `value` in the emitted contract; avoid falsey literals unless the emitter preserves them.
|
|
236
|
-
- Add the corresponding `defaults.*` capability when using function defaults like `autoincrement()` or `now()`.
|
|
237
|
-
|
|
238
|
-
### CLI Output: Tree vs JSON
|
|
239
|
-
|
|
240
|
-
Column defaults are handled differently depending on output format:
|
|
241
|
-
|
|
242
|
-
- **Tree output** (`db introspect`): Labels show only type and nullability, e.g. `id: int4 (not nullable)`. Defaults are omitted from labels to keep tree output concise.
|
|
243
|
-
- **JSON output** (`db introspect --json`): Full default information is preserved in the schema IR.
|
|
244
|
-
- **Programmatic access**: Defaults are always available in `SchemaTreeNode.meta.default` for tooling that needs them.
|
|
50
|
+
## Exports
|
|
245
51
|
|
|
246
|
-
|
|
52
|
+
- `./types`: Contract data types, hash types, plan types, type guards
|
|
53
|
+
- `./hashing`: Contract hashing utilities
|
|
54
|
+
- `./testing`: Test helpers for creating contract fixtures
|
|
55
|
+
- `./validate-contract`: Contract structure validation
|
|
56
|
+
- `./validate-domain`: Domain model validation
|
|
247
57
|
|
|
248
58
|
## Type System
|
|
249
59
|
|
|
250
60
|
### Plan Types
|
|
251
61
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
`ParamDescriptor` describes a single parameter in an execution plan. Used in `PlanMeta.paramDescriptors` for param encoding and plugin inspection.
|
|
62
|
+
`ParamDescriptor` describes a single parameter in an execution plan:
|
|
255
63
|
|
|
256
|
-
- **`source`**: Origin of the parameter
|
|
257
|
-
- **`'dsl'`**: From the Prisma Next DSL/ORM query builder
|
|
258
|
-
- **`'raw'`**: From raw SQL (e.g. `sql\`...\`` with placeholders)
|
|
259
|
-
- **`'lane'`**: From a lane integration (e.g. Kysely) that transforms an external AST into PN plan form; the lane id is in `meta.lane`
|
|
64
|
+
- **`source`**: Origin of the parameter (`'dsl'`, `'raw'`, or `'lane'`)
|
|
260
65
|
- **`index`** (optional): 1-based position into `plan.params`
|
|
261
66
|
- **`name`** (optional): Parameter name for codec resolution
|
|
262
67
|
- **`codecId`**, **`nativeType`**, **`nullable`** (optional): Type metadata from contract
|
|
263
68
|
- **`refs`** (optional): `{ table, column }` when the param is used against a known column
|
|
264
69
|
|
|
265
|
-
###
|
|
266
|
-
|
|
267
|
-
Use type guards to narrow the contract type:
|
|
268
|
-
|
|
269
|
-
```typescript
|
|
270
|
-
import { isDocumentContract } from '@prisma-next/contract/types';
|
|
271
|
-
|
|
272
|
-
if (isDocumentContract(contract)) {
|
|
273
|
-
// TypeScript knows contract is DocumentContract
|
|
274
|
-
const collections = contract.storage.document.collections;
|
|
275
|
-
}
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
## Exports
|
|
279
|
-
|
|
280
|
-
- `./types`: Core contract type definitions, type guards, and emitter SPI types
|
|
281
|
-
- `./framework-components`: Framework component model (descriptors + identity instance bases)
|
|
282
|
-
- `./pack-manifest-types`: Extension pack manifest types
|
|
283
|
-
- `./ir`: Contract IR types
|
|
284
|
-
- `./schema-document`: Document family JSON Schema (`schemas/data-contract-document-v1.json`)
|
|
285
|
-
|
|
286
|
-
## Architecture
|
|
70
|
+
### Column Defaults
|
|
287
71
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
TYPES[Type Definitions]
|
|
292
|
-
SCHEMA[JSON Schemas]
|
|
293
|
-
GUARDS[Type Guards]
|
|
294
|
-
end
|
|
72
|
+
- When adding column defaults, re-emit the contract and verify the emitted JSON includes the full default payload.
|
|
73
|
+
- Keep `nullable: false` explicit for columns with defaults in emitted contracts.
|
|
74
|
+
- Add the corresponding `defaults.*` capability when using function defaults like `autoincrement()` or `now()`.
|
|
295
75
|
|
|
296
|
-
|
|
297
|
-
EMITTER[Emitter]
|
|
298
|
-
RUNTIME[Runtime]
|
|
299
|
-
QUERY[Query Builder]
|
|
300
|
-
end
|
|
76
|
+
## Dependencies
|
|
301
77
|
|
|
302
|
-
|
|
303
|
-
TYPES --> RUNTIME
|
|
304
|
-
TYPES --> QUERY
|
|
305
|
-
SCHEMA --> EMITTER
|
|
306
|
-
GUARDS --> RUNTIME
|
|
307
|
-
GUARDS --> QUERY
|
|
308
|
-
```
|
|
78
|
+
- **`@prisma-next/utils`**: Shared utility functions
|
|
309
79
|
|
|
310
80
|
## Related Subsystems
|
|
311
81
|
|
|
312
|
-
-
|
|
313
|
-
-
|
|
82
|
+
- [Data Contract](../../../../../docs/architecture%20docs/subsystems/1.%20Data%20Contract.md)
|
|
83
|
+
- [Contract Emitter & Types](../../../../../docs/architecture%20docs/subsystems/2.%20Contract%20Emitter%20&%20Types.md)
|
|
314
84
|
|
|
315
85
|
## Related ADRs
|
|
316
86
|
|
|
317
|
-
- [ADR 001 - Migrations as Edges](
|
|
318
|
-
- [ADR 004 - Storage Hash vs Profile Hash](
|
|
319
|
-
- [ADR
|
|
320
|
-
- [ADR
|
|
321
|
-
- [ADR
|
|
322
|
-
|
|
323
|
-
## Dependencies
|
|
324
|
-
|
|
325
|
-
- **`@prisma-next/operations`**: For `OperationRegistry` type used in `ValidationContext` and `TargetFamilyHook`
|
|
326
|
-
- **Note**: This package depends on `@prisma-next/operations`, but `@prisma-next/operations` does not depend on this package (no cycle). The `OperationRegistry` type is used in emitter SPI types that are shared between migration-plane and shared-plane packages.
|
|
327
|
-
|
|
328
|
-
**Dependents:**
|
|
329
|
-
- **`@prisma-next/contract-authoring`**: Uses core contract types for authoring
|
|
330
|
-
- **`@prisma-next/sql-contract`**: Extends core contract types for SQL family
|
|
331
|
-
- **`@prisma-next/emitter`**: Uses contract types for emission
|
|
332
|
-
- **`@prisma-next/runtime`**: Uses contract types for runtime execution
|
|
333
|
-
- **`@prisma-next/sql-query`**: Uses contract types for query building
|
|
334
|
-
|
|
335
|
-
## Related Packages
|
|
336
|
-
|
|
337
|
-
- `@prisma-next/sql-query`: SQL query builder and plan types
|
|
338
|
-
- `@prisma-next/runtime`: Runtime execution engine that consumes contracts
|
|
87
|
+
- [ADR 001 - Migrations as Edges](../../../../../docs/architecture%20docs/adrs/ADR%20001%20-%20Migrations%20as%20Edges.md)
|
|
88
|
+
- [ADR 004 - Storage Hash vs Profile Hash](../../../../../docs/architecture%20docs/adrs/ADR%20004%20-%20Storage%20Hash%20vs%20Profile%20Hash.md)
|
|
89
|
+
- [ADR 010 - Canonicalization Rules](../../../../../docs/architecture%20docs/adrs/ADR%20010%20-%20Canonicalization%20Rules.md)
|
|
90
|
+
- [ADR 021 - Contract Marker Storage](../../../../../docs/architecture%20docs/adrs/ADR%20021%20-%20Contract%20Marker%20Storage.md)
|
|
91
|
+
- [ADR 183 - SPI types live at the lowest consuming layer](../../../../../docs/architecture%20docs/adrs/ADR%20183%20-%20SPI%20types%20live%20at%20the%20lowest%20consuming%20layer.md)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { O as StorageBase, T as ProfileHashBase, U as ContractModel, f as ExecutionHashBase, p as ExecutionMutationDefault } from "./types-DmKtoEd-.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/contract-types.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Execution section for the unified contract (ADR 182).
|
|
7
|
+
*
|
|
8
|
+
* Unlike the legacy {@link import('./types').ExecutionSection}, this type
|
|
9
|
+
* requires `executionHash` — when an execution section is present, its
|
|
10
|
+
* hash must be too (consistent with `StorageBase.storageHash`).
|
|
11
|
+
*
|
|
12
|
+
* @template THash Literal hash string type for type-safe hash tracking.
|
|
13
|
+
*/
|
|
14
|
+
type ContractExecutionSection<THash extends string = string> = {
|
|
15
|
+
readonly executionHash: ExecutionHashBase<THash>;
|
|
16
|
+
readonly mutations: {
|
|
17
|
+
readonly defaults: ReadonlyArray<ExecutionMutationDefault>;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Unified contract representation (ADR 182).
|
|
22
|
+
*
|
|
23
|
+
* A `Contract` is the canonical in-memory representation of a data contract.
|
|
24
|
+
* It is model-first (domain models carry their own storage bridge) and
|
|
25
|
+
* family-parameterized (SQL, Mongo, etc. specialize via `TStorage` and model
|
|
26
|
+
* storage generics on `ContractModel`).
|
|
27
|
+
*
|
|
28
|
+
* JSON persistence fields (`schemaVersion`, `sources`) are not represented
|
|
29
|
+
* here — they are handled at the serialization boundary.
|
|
30
|
+
*
|
|
31
|
+
* @template TStorage Family-specific storage block (extends {@link StorageBase}).
|
|
32
|
+
* @template TModels Record of model name → {@link ContractModel} with
|
|
33
|
+
* family-specific model storage.
|
|
34
|
+
*/
|
|
35
|
+
interface Contract<TStorage extends StorageBase = StorageBase, TModels extends Record<string, ContractModel> = Record<string, ContractModel>> {
|
|
36
|
+
readonly target: string;
|
|
37
|
+
readonly targetFamily: string;
|
|
38
|
+
readonly roots: Record<string, string>;
|
|
39
|
+
readonly models: TModels;
|
|
40
|
+
readonly storage: TStorage;
|
|
41
|
+
readonly capabilities: Record<string, Record<string, boolean>>;
|
|
42
|
+
readonly extensionPacks: Record<string, unknown>;
|
|
43
|
+
readonly execution?: ContractExecutionSection;
|
|
44
|
+
readonly profileHash: ProfileHashBase<string>;
|
|
45
|
+
readonly meta: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { ContractExecutionSection as n, Contract as t };
|
|
49
|
+
//# sourceMappingURL=contract-types-x89nqTli.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-types-x89nqTli.d.mts","names":[],"sources":["../src/contract-types.ts"],"sourcesContent":[],"mappings":";;;;;AAiBA;;;;;;AAsBA;;AACiC,KAvBrB,wBAuBqB,CAAA,cAAA,MAAA,GAAA,MAAA,CAAA,GAAA;EACA,SAAA,aAAA,EAvBP,iBAuBO,CAvBW,KAuBX,CAAA;EAAf,SAAA,SAAA,EAAA;IAA+C,SAAA,QAAA,EArB1C,aAqB0C,CArB5B,wBAqB4B,CAAA;EAAf,CAAA;CAIhC;;;;;;;;;;;;;;;;UAND,0BACE,cAAc,6BACf,eAAe,iBAAiB,eAAe;;;kBAI/C;mBACC;oBACC;yBACK,eAAe;2BACb;uBACJ;wBACC;iBACP"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as bigintJsonReplacer } from "./types-
|
|
1
|
+
import { t as bigintJsonReplacer } from "./types-DYikGC04.mjs";
|
|
2
2
|
import { isArrayEqual } from "@prisma-next/utils/array-equal";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
|
|
@@ -212,4 +212,4 @@ function computeProfileHash(args) {
|
|
|
212
212
|
|
|
213
213
|
//#endregion
|
|
214
214
|
export { canonicalizeContractToObject as a, canonicalizeContract as i, computeProfileHash as n, computeStorageHash as r, computeExecutionHash as t };
|
|
215
|
-
//# sourceMappingURL=hashing-
|
|
215
|
+
//# sourceMappingURL=hashing-D1EPxYRl.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hashing-CVS9sXxd.mjs","names":["result: Record<string, unknown>","sorted: Record<string, unknown>","result: StorageObject","sortedTable: TableObject","ordered: Record<string, unknown>"],"sources":["../src/canonicalization.ts","../src/hashing.ts"],"sourcesContent":["import { isArrayEqual } from '@prisma-next/utils/array-equal';\n\nimport type { StorageBase } from './types';\nimport { bigintJsonReplacer } from './types';\n\nconst TOP_LEVEL_ORDER = [\n 'schemaVersion',\n 'canonicalVersion',\n 'targetFamily',\n 'target',\n 'profileHash',\n 'roots',\n 'models',\n 'storage',\n 'execution',\n 'capabilities',\n 'extensionPacks',\n 'meta',\n] as const;\n\nfunction isDefaultValue(value: unknown): boolean {\n if (value === false) return true;\n if (value === null) return false;\n if (value instanceof Date) return false;\n if (Array.isArray(value) && value.length === 0) return true;\n if (typeof value === 'object' && value !== null) {\n const keys = Object.keys(value);\n return keys.length === 0;\n }\n return false;\n}\n\nfunction omitDefaults(obj: unknown, path: readonly string[]): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (obj instanceof Date) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => omitDefaults(item, path));\n }\n\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n const currentPath = [...path, key];\n\n if (key === '_generated') {\n continue;\n }\n\n if (key === 'nullable' && value === false) {\n continue;\n }\n\n if (key === 'generated' && value === false) {\n continue;\n }\n\n if ((key === 'onDelete' || key === 'onUpdate') && value === 'noAction') {\n continue;\n }\n\n if (isDefaultValue(value)) {\n const isRequiredModels = isArrayEqual(currentPath, ['models']);\n const isRequiredTables = isArrayEqual(currentPath, ['storage', 'tables']);\n const isRequiredCollections = isArrayEqual(currentPath, ['storage', 'collections']);\n const isCollectionEntry =\n currentPath.length === 3 &&\n isArrayEqual([currentPath[0], currentPath[1]], ['storage', 'collections']);\n const isRequiredRoots = isArrayEqual(currentPath, ['roots']);\n const isRequiredExtensionPacks = isArrayEqual(currentPath, ['extensionPacks']);\n const isRequiredCapabilities = isArrayEqual(currentPath, ['capabilities']);\n const isRequiredMeta = isArrayEqual(currentPath, ['meta']);\n const isRequiredExecutionDefaults = isArrayEqual(currentPath, [\n 'execution',\n 'mutations',\n 'defaults',\n ]);\n const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === 'extensionPacks';\n const isModelRelations =\n currentPath.length === 3 &&\n isArrayEqual([currentPath[0], currentPath[2]], ['models', 'relations']);\n const isModelStorage =\n currentPath.length === 3 &&\n isArrayEqual([currentPath[0], currentPath[2]], ['models', 'storage']);\n const isTableUniques =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'uniques'],\n );\n const isTableIndexes =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'indexes'],\n );\n const isTableForeignKeys =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'foreignKeys'],\n );\n\n const isFkBooleanField =\n currentPath.length === 5 &&\n currentPath[0] === 'storage' &&\n currentPath[1] === 'tables' &&\n currentPath[3] === 'foreignKeys' &&\n (key === 'constraint' || key === 'index');\n\n if (\n !isRequiredModels &&\n !isRequiredTables &&\n !isRequiredCollections &&\n !isCollectionEntry &&\n !isRequiredRoots &&\n !isRequiredExtensionPacks &&\n !isRequiredCapabilities &&\n !isRequiredMeta &&\n !isRequiredExecutionDefaults &&\n !isExtensionNamespace &&\n !isModelRelations &&\n !isModelStorage &&\n !isTableUniques &&\n !isTableIndexes &&\n !isTableForeignKeys &&\n !isFkBooleanField\n ) {\n continue;\n }\n }\n\n result[key] = omitDefaults(value, currentPath);\n }\n\n return result;\n}\n\nfunction sortObjectKeys(obj: unknown): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (obj instanceof Date) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => sortObjectKeys(item));\n }\n\n const sorted: Record<string, unknown> = {};\n const keys = Object.keys(obj).sort();\n for (const key of keys) {\n sorted[key] = sortObjectKeys((obj as Record<string, unknown>)[key]);\n }\n\n return sorted;\n}\n\ntype StorageObject = {\n tables?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\ntype TableObject = {\n indexes?: unknown[];\n uniques?: unknown[];\n [key: string]: unknown;\n};\n\nfunction sortIndexesAndUniques(storage: unknown): unknown {\n if (!storage || typeof storage !== 'object') {\n return storage;\n }\n\n const storageObj = storage as StorageObject;\n if (!storageObj.tables || typeof storageObj.tables !== 'object') {\n return storage;\n }\n\n const tables = storageObj.tables;\n const result: StorageObject = { ...storageObj };\n\n result.tables = {};\n const sortedTableNames = Object.keys(tables).sort();\n for (const tableName of sortedTableNames) {\n const table = tables[tableName];\n if (!table || typeof table !== 'object') {\n result.tables[tableName] = table;\n continue;\n }\n\n const tableObj = table as TableObject;\n const sortedTable: TableObject = { ...tableObj };\n\n if (Array.isArray(tableObj.indexes)) {\n sortedTable.indexes = [...tableObj.indexes].sort((a, b) => {\n const nameA = (a as { name?: string })?.name || '';\n const nameB = (b as { name?: string })?.name || '';\n return nameA.localeCompare(nameB);\n });\n }\n\n if (Array.isArray(tableObj.uniques)) {\n sortedTable.uniques = [...tableObj.uniques].sort((a, b) => {\n const nameA = (a as { name?: string })?.name || '';\n const nameB = (b as { name?: string })?.name || '';\n return nameA.localeCompare(nameB);\n });\n }\n\n result.tables[tableName] = sortedTable;\n }\n\n return result;\n}\n\nfunction orderTopLevel(obj: Record<string, unknown>): Record<string, unknown> {\n const ordered: Record<string, unknown> = {};\n const remaining = new Set(Object.keys(obj));\n\n for (const key of TOP_LEVEL_ORDER) {\n if (remaining.has(key)) {\n ordered[key] = obj[key];\n remaining.delete(key);\n }\n }\n\n for (const key of Array.from(remaining).sort()) {\n ordered[key] = obj[key];\n }\n\n return ordered;\n}\n\nexport type CanonicalContractInput = {\n readonly schemaVersion?: string | undefined;\n readonly targetFamily: string;\n readonly target: string;\n readonly profileHash?: string | undefined;\n readonly roots: Record<string, string>;\n readonly models: Record<string, unknown>;\n // StorageBase is an interface without an index signature, so it is not\n // assignable to Record<string, unknown>. The union allows callers to pass\n // either the typed StorageBase or a plain record.\n readonly storage: StorageBase | Record<string, unknown>;\n readonly execution?: Record<string, unknown> | undefined;\n readonly extensionPacks: Record<string, unknown>;\n readonly capabilities: Record<string, Record<string, boolean>>;\n readonly meta: Record<string, unknown>;\n};\n\nexport function canonicalizeContractToObject(\n input: CanonicalContractInput,\n): Record<string, unknown> {\n const i = input as Record<string, unknown>;\n const normalized: Record<string, unknown> = {\n ...(i['schemaVersion'] !== undefined ? { schemaVersion: i['schemaVersion'] } : {}),\n targetFamily: i['targetFamily'],\n target: i['target'],\n ...(i['profileHash'] !== undefined ? { profileHash: i['profileHash'] } : {}),\n roots: i['roots'],\n models: i['models'],\n storage: i['storage'],\n ...(i['execution'] !== undefined ? { execution: i['execution'] } : {}),\n extensionPacks: i['extensionPacks'],\n capabilities: i['capabilities'],\n meta: i['meta'],\n };\n\n const withDefaultsOmitted = omitDefaults(normalized, []) as Record<string, unknown>;\n const withSortedIndexes = sortIndexesAndUniques(withDefaultsOmitted['storage']);\n const withSortedStorage = { ...withDefaultsOmitted, storage: withSortedIndexes };\n const withSortedKeys = sortObjectKeys(withSortedStorage) as Record<string, unknown>;\n return orderTopLevel(withSortedKeys);\n}\n\nexport function canonicalizeContract(input: CanonicalContractInput): string {\n return JSON.stringify(canonicalizeContractToObject(input), bigintJsonReplacer, 2);\n}\n","import { createHash } from 'node:crypto';\nimport { canonicalizeContract } from './canonicalization';\nimport type { ExecutionHashBase, ProfileHashBase, StorageHashBase } from './types';\n\nconst SCHEMA_VERSION = '1';\n\nfunction sha256(content: string): string {\n const hash = createHash('sha256');\n hash.update(content);\n return `sha256:${hash.digest('hex')}`;\n}\n\nexport function computeStorageHash(args: {\n target: string;\n targetFamily: string;\n storage: Record<string, unknown>;\n}): StorageHashBase<string> {\n const canonical = canonicalizeContract({\n schemaVersion: SCHEMA_VERSION,\n targetFamily: args.targetFamily,\n target: args.target,\n storage: args.storage,\n roots: {},\n models: {},\n extensionPacks: {},\n capabilities: {},\n meta: {},\n });\n return sha256(canonical) as StorageHashBase<string>;\n}\n\nexport function computeExecutionHash(args: {\n target: string;\n targetFamily: string;\n execution: Record<string, unknown>;\n}): ExecutionHashBase<string> {\n const canonical = canonicalizeContract({\n schemaVersion: SCHEMA_VERSION,\n targetFamily: args.targetFamily,\n target: args.target,\n execution: args.execution,\n roots: {},\n models: {},\n storage: {},\n extensionPacks: {},\n capabilities: {},\n meta: {},\n });\n return sha256(canonical) as ExecutionHashBase<string>;\n}\n\nexport function computeProfileHash(args: {\n target: string;\n targetFamily: string;\n capabilities: Record<string, Record<string, boolean>>;\n}): ProfileHashBase<string> {\n const canonical = canonicalizeContract({\n schemaVersion: SCHEMA_VERSION,\n targetFamily: args.targetFamily,\n target: args.target,\n capabilities: args.capabilities,\n roots: {},\n models: {},\n storage: {},\n extensionPacks: {},\n meta: {},\n });\n return sha256(canonical) as ProfileHashBase<string>;\n}\n"],"mappings":";;;;;AAKA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAS,eAAe,OAAyB;AAC/C,KAAI,UAAU,MAAO,QAAO;AAC5B,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,iBAAiB,KAAM,QAAO;AAClC,KAAI,MAAM,QAAQ,MAAM,IAAI,MAAM,WAAW,EAAG,QAAO;AACvD,KAAI,OAAO,UAAU,YAAY,UAAU,KAEzC,QADa,OAAO,KAAK,MAAM,CACnB,WAAW;AAEzB,QAAO;;AAGT,SAAS,aAAa,KAAc,MAAkC;AACpE,KAAI,QAAQ,QAAQ,OAAO,QAAQ,SACjC,QAAO;AAGT,KAAI,eAAe,KACjB,QAAO;AAGT,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,KAAK,SAAS,aAAa,MAAM,KAAK,CAAC;CAGpD,MAAMA,SAAkC,EAAE;AAE1C,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,IAAI,EAAE;EAC9C,MAAM,cAAc,CAAC,GAAG,MA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E,gBAAgB,EAAE;EAClB,cAAc,EAAE;EAChB,MAAM,EAAE;EACT,EAEoD,EAAE,CAAC;CACxD,MAAM,oBAAoB,sBAAsB,oBAAoB,WAAW;AAG/E,QAAO,cADgB,eADG;EAAE,GAAG;EAAqB,SAAS;EAAmB,CACxB,CACpB;;AAGtC,SAAgB,qBAAqB,OAAuC;AAC1E,QAAO,KAAK,UAAU,6BAA6B,MAAM,EAAE,oBAAoB,EAAE;;;;;ACxRnF,MAAM,iBAAiB;AAEvB,SAAS,OAAO,SAAyB;CACvC,MAAM,OAAO,WAAW,SAAS;AACjC,MAAK,OAAO,QAAQ;AACpB,QAAO,UAAU,KAAK,OAAO,MAAM;;AAGrC,SAAgB,mBAAmB,MAIP;AAY1B,QAAO,OAXW,qBAAqB;EACrC,eAAe;EACf,cAAc,KAAK;EACnB,QAAQ,KAAK;EACb,SAAS,KAAK;EACd,OAAO,EAAE;EACT,QAAQ,EAAE;EACV,gBAAgB,EAAE;EAClB,cAAc,EAAE;EAChB,MAAM,EAAE;EACT,CAAC,CACsB;;AAG1B,SAAgB,qBAAqB,MAIP;AAa5B,QAAO,OAZW,qBAAqB;EACrC,eAAe;EACf,cAAc,KAAK;EACnB,QAAQ,KAAK;EACb,WAAW,KAAK;EAChB,OAAO,EAAE;EACT,QAAQ,EAAE;EACV,SAAS,EAAE;EACX,gBAAgB,EAAE;EAClB,cAAc,EAAE;EAChB,MAAM,EAAE;EACT,CAAC,CACsB;;AAG1B,SAAgB,mBAAmB,MAIP;AAY1B,QAAO,OAXW,qBAAqB;EACrC,eAAe;EACf,cAAc,KAAK;EACnB,QAAQ,KAAK;EACb,cAAc,KAAK;EACnB,OAAO,EAAE;EACT,QAAQ,EAAE;EACV,SAAS,EAAE;EACX,gBAAgB,EAAE;EAClB,MAAM,EAAE;EACT,CAAC,CACsB"}
|
|
1
|
+
{"version":3,"file":"hashing-D1EPxYRl.mjs","names":["result: Record<string, unknown>","sorted: Record<string, unknown>","result: StorageObject","sortedTable: TableObject","ordered: Record<string, unknown>"],"sources":["../src/canonicalization.ts","../src/hashing.ts"],"sourcesContent":["import { isArrayEqual } from '@prisma-next/utils/array-equal';\n\nimport type { StorageBase } from './types';\nimport { bigintJsonReplacer } from './types';\n\nconst TOP_LEVEL_ORDER = [\n 'schemaVersion',\n 'canonicalVersion',\n 'targetFamily',\n 'target',\n 'profileHash',\n 'roots',\n 'models',\n 'storage',\n 'execution',\n 'capabilities',\n 'extensionPacks',\n 'meta',\n] as const;\n\nfunction isDefaultValue(value: unknown): boolean {\n if (value === false) return true;\n if (value === null) return false;\n if (value instanceof Date) return false;\n if (Array.isArray(value) && value.length === 0) return true;\n if (typeof value === 'object' && value !== null) {\n const keys = Object.keys(value);\n return keys.length === 0;\n }\n return false;\n}\n\nfunction omitDefaults(obj: unknown, path: readonly string[]): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (obj instanceof Date) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => omitDefaults(item, path));\n }\n\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n const currentPath = [...path, key];\n\n if (key === '_generated') {\n continue;\n }\n\n if (key === 'nullable' && value === false) {\n continue;\n }\n\n if (key === 'generated' && value === false) {\n continue;\n }\n\n if ((key === 'onDelete' || key === 'onUpdate') && value === 'noAction') {\n continue;\n }\n\n if (isDefaultValue(value)) {\n const isRequiredModels = isArrayEqual(currentPath, ['models']);\n const isRequiredTables = isArrayEqual(currentPath, ['storage', 'tables']);\n const isRequiredCollections = isArrayEqual(currentPath, ['storage', 'collections']);\n const isCollectionEntry =\n currentPath.length === 3 &&\n isArrayEqual([currentPath[0], currentPath[1]], ['storage', 'collections']);\n const isRequiredRoots = isArrayEqual(currentPath, ['roots']);\n const isRequiredExtensionPacks = isArrayEqual(currentPath, ['extensionPacks']);\n const isRequiredCapabilities = isArrayEqual(currentPath, ['capabilities']);\n const isRequiredMeta = isArrayEqual(currentPath, ['meta']);\n const isRequiredExecutionDefaults = isArrayEqual(currentPath, [\n 'execution',\n 'mutations',\n 'defaults',\n ]);\n const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === 'extensionPacks';\n const isModelRelations =\n currentPath.length === 3 &&\n isArrayEqual([currentPath[0], currentPath[2]], ['models', 'relations']);\n const isModelStorage =\n currentPath.length === 3 &&\n isArrayEqual([currentPath[0], currentPath[2]], ['models', 'storage']);\n const isTableUniques =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'uniques'],\n );\n const isTableIndexes =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'indexes'],\n );\n const isTableForeignKeys =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'foreignKeys'],\n );\n\n const isFkBooleanField =\n currentPath.length === 5 &&\n currentPath[0] === 'storage' &&\n currentPath[1] === 'tables' &&\n currentPath[3] === 'foreignKeys' &&\n (key === 'constraint' || key === 'index');\n\n if (\n !isRequiredModels &&\n !isRequiredTables &&\n !isRequiredCollections &&\n !isCollectionEntry &&\n !isRequiredRoots &&\n !isRequiredExtensionPacks &&\n !isRequiredCapabilities &&\n !isRequiredMeta &&\n !isRequiredExecutionDefaults &&\n !isExtensionNamespace &&\n !isModelRelations &&\n !isModelStorage &&\n !isTableUniques &&\n !isTableIndexes &&\n !isTableForeignKeys &&\n !isFkBooleanField\n ) {\n continue;\n }\n }\n\n result[key] = omitDefaults(value, currentPath);\n }\n\n return result;\n}\n\nfunction sortObjectKeys(obj: unknown): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (obj instanceof Date) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => sortObjectKeys(item));\n }\n\n const sorted: Record<string, unknown> = {};\n const keys = Object.keys(obj).sort();\n for (const key of keys) {\n sorted[key] = sortObjectKeys((obj as Record<string, unknown>)[key]);\n }\n\n return sorted;\n}\n\ntype StorageObject = {\n tables?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\ntype TableObject = {\n indexes?: unknown[];\n uniques?: unknown[];\n [key: string]: unknown;\n};\n\nfunction sortIndexesAndUniques(storage: unknown): unknown {\n if (!storage || typeof storage !== 'object') {\n return storage;\n }\n\n const storageObj = storage as StorageObject;\n if (!storageObj.tables || typeof storageObj.tables !== 'object') {\n return storage;\n }\n\n const tables = storageObj.tables;\n const result: StorageObject = { ...storageObj };\n\n result.tables = {};\n const sortedTableNames = Object.keys(tables).sort();\n for (const tableName of sortedTableNames) {\n const table = tables[tableName];\n if (!table || typeof table !== 'object') {\n result.tables[tableName] = table;\n continue;\n }\n\n const tableObj = table as TableObject;\n const sortedTable: TableObject = { ...tableObj };\n\n if (Array.isArray(tableObj.indexes)) {\n sortedTable.indexes = [...tableObj.indexes].sort((a, b) => {\n const nameA = (a as { name?: string })?.name || '';\n const nameB = (b as { name?: string })?.name || '';\n return nameA.localeCompare(nameB);\n });\n }\n\n if (Array.isArray(tableObj.uniques)) {\n sortedTable.uniques = [...tableObj.uniques].sort((a, b) => {\n const nameA = (a as { name?: string })?.name || '';\n const nameB = (b as { name?: string })?.name || '';\n return nameA.localeCompare(nameB);\n });\n }\n\n result.tables[tableName] = sortedTable;\n }\n\n return result;\n}\n\nfunction orderTopLevel(obj: Record<string, unknown>): Record<string, unknown> {\n const ordered: Record<string, unknown> = {};\n const remaining = new Set(Object.keys(obj));\n\n for (const key of TOP_LEVEL_ORDER) {\n if (remaining.has(key)) {\n ordered[key] = obj[key];\n remaining.delete(key);\n }\n }\n\n for (const key of Array.from(remaining).sort()) {\n ordered[key] = obj[key];\n }\n\n return ordered;\n}\n\nexport type CanonicalContractInput = {\n readonly schemaVersion?: string | undefined;\n readonly targetFamily: string;\n readonly target: string;\n readonly profileHash?: string | undefined;\n readonly roots: Record<string, string>;\n readonly models: Record<string, unknown>;\n // StorageBase is an interface without an index signature, so it is not\n // assignable to Record<string, unknown>. The union allows callers to pass\n // either the typed StorageBase or a plain record.\n readonly storage: StorageBase | Record<string, unknown>;\n readonly execution?: Record<string, unknown> | undefined;\n readonly extensionPacks: Record<string, unknown>;\n readonly capabilities: Record<string, Record<string, boolean>>;\n readonly meta: Record<string, unknown>;\n};\n\nexport function canonicalizeContractToObject(\n input: CanonicalContractInput,\n): Record<string, unknown> {\n const i = input as Record<string, unknown>;\n const normalized: Record<string, unknown> = {\n ...(i['schemaVersion'] !== undefined ? { schemaVersion: i['schemaVersion'] } : {}),\n targetFamily: i['targetFamily'],\n target: i['target'],\n ...(i['profileHash'] !== undefined ? { profileHash: i['profileHash'] } : {}),\n roots: i['roots'],\n models: i['models'],\n storage: i['storage'],\n ...(i['execution'] !== undefined ? { execution: i['execution'] } : {}),\n extensionPacks: i['extensionPacks'],\n capabilities: i['capabilities'],\n meta: i['meta'],\n };\n\n const withDefaultsOmitted = omitDefaults(normalized, []) as Record<string, unknown>;\n const withSortedIndexes = sortIndexesAndUniques(withDefaultsOmitted['storage']);\n const withSortedStorage = { ...withDefaultsOmitted, storage: withSortedIndexes };\n const withSortedKeys = sortObjectKeys(withSortedStorage) as Record<string, unknown>;\n return orderTopLevel(withSortedKeys);\n}\n\nexport function canonicalizeContract(input: CanonicalContractInput): string {\n return JSON.stringify(canonicalizeContractToObject(input), bigintJsonReplacer, 2);\n}\n","import { createHash } from 'node:crypto';\nimport { canonicalizeContract } from './canonicalization';\nimport type { ExecutionHashBase, ProfileHashBase, StorageHashBase } from './types';\n\nconst SCHEMA_VERSION = '1';\n\nfunction sha256(content: string): string {\n const hash = createHash('sha256');\n hash.update(content);\n return `sha256:${hash.digest('hex')}`;\n}\n\nexport function computeStorageHash(args: {\n target: string;\n targetFamily: string;\n storage: Record<string, unknown>;\n}): StorageHashBase<string> {\n const canonical = canonicalizeContract({\n schemaVersion: SCHEMA_VERSION,\n targetFamily: args.targetFamily,\n target: args.target,\n storage: args.storage,\n roots: {},\n models: {},\n extensionPacks: {},\n capabilities: {},\n meta: {},\n });\n return sha256(canonical) as StorageHashBase<string>;\n}\n\nexport function computeExecutionHash(args: {\n target: string;\n targetFamily: string;\n execution: Record<string, unknown>;\n}): ExecutionHashBase<string> {\n const canonical = canonicalizeContract({\n schemaVersion: SCHEMA_VERSION,\n targetFamily: args.targetFamily,\n target: args.target,\n execution: args.execution,\n roots: {},\n models: {},\n storage: {},\n extensionPacks: {},\n capabilities: {},\n meta: {},\n });\n return sha256(canonical) as ExecutionHashBase<string>;\n}\n\nexport function computeProfileHash(args: {\n target: string;\n targetFamily: string;\n capabilities: Record<string, Record<string, boolean>>;\n}): ProfileHashBase<string> {\n const canonical = canonicalizeContract({\n schemaVersion: SCHEMA_VERSION,\n targetFamily: args.targetFamily,\n target: args.target,\n capabilities: args.capabilities,\n roots: {},\n models: {},\n storage: {},\n extensionPacks: {},\n meta: {},\n });\n return sha256(canonical) as ProfileHashBase<string>;\n}\n"],"mappings":";;;;;AAKA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAS,eAAe,OAAyB;AAC/C,KAAI,UAAU,MAAO,QAAO;AAC5B,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,iBAAiB,KAAM,QAAO;AAClC,KAAI,MAAM,QAAQ,MAAM,IAAI,MAAM,WAAW,EAAG,QAAO;AACvD,KAAI,OAAO,UAAU,YAAY,UAAU,KAEzC,QADa,OAAO,KAAK,MAAM,CACnB,WAAW;AAEzB,QAAO;;AAGT,SAAS,aAAa,KAAc,MAAkC;AACpE,KAAI,QAAQ,QAAQ,OAAO,QAAQ,SACjC,QAAO;AAGT,KAAI,eAAe,KACjB,QAAO;AAGT,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,KAAK,SAAS,aAAa,MAAM,KAAK,CAAC;CAGpD,MAAMA,SAAkC,EAAE;AAE1C,MAAK,MAAM,CAAC,KAAK,UA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1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { O as StorageBase, T as ProfileHashBase, f as ExecutionHashBase, k as StorageHashBase } from "./types-DmKtoEd-.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/canonicalization.d.ts
|
|
4
4
|
type CanonicalContractInput = {
|
package/dist/hashing.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as canonicalizeContractToObject, i as canonicalizeContract, n as computeProfileHash, r as computeStorageHash, t as computeExecutionHash } from "./hashing-
|
|
1
|
+
import { a as canonicalizeContractToObject, i as canonicalizeContract, n as computeProfileHash, r as computeStorageHash, t as computeExecutionHash } from "./hashing-D1EPxYRl.mjs";
|
|
2
2
|
|
|
3
3
|
export { canonicalizeContract, canonicalizeContractToObject, computeExecutionHash, computeProfileHash, computeStorageHash };
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { O as StorageBase, T as ProfileHashBase, U as ContractModel, g as ExecutionSection, k as StorageHashBase, rt as ModelStorageBase } from "./types-DmKtoEd-.mjs";
|
|
2
|
+
import { t as Contract } from "./contract-types-x89nqTli.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/testing-factories.d.ts
|
|
4
5
|
type ContractOverrides<TStorage extends StorageBase = StorageBase, TModels extends Record<string, ContractModel> = Record<string, ContractModel>> = {
|
|
@@ -9,7 +10,7 @@ type ContractOverrides<TStorage extends StorageBase = StorageBase, TModels exten
|
|
|
9
10
|
storage?: Omit<TStorage, 'storageHash'>;
|
|
10
11
|
capabilities?: Record<string, Record<string, boolean>>;
|
|
11
12
|
extensionPacks?: Record<string, unknown>;
|
|
12
|
-
execution?: ExecutionSection
|
|
13
|
+
execution?: Omit<ExecutionSection, 'executionHash'>;
|
|
13
14
|
profileHash?: ProfileHashBase<string>;
|
|
14
15
|
meta?: Record<string, unknown>;
|
|
15
16
|
};
|
package/dist/testing.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.mts","names":[],"sources":["../src/testing-factories.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"testing.d.mts","names":[],"sources":["../src/testing-factories.ts"],"sourcesContent":[],"mappings":";;;;KAMK,mCACc,cAAc,6BACf,eAAe,iBAAiB,eAAe;EAF5D,MAAA,CAAA,EAAA,MAAA;EACc,YAAA,CAAA,EAAA,MAAA;EAAc,KAAA,CAAA,EAKvB,MALuB,CAAA,MAAA,EAAA,MAAA,CAAA;EACA,MAAA,CAAA,EAKtB,OALsB;EAAf,OAAA,CAAA,EAMN,IANM,CAMD,QANC,EAAA,aAAA,CAAA;EAA+C,YAAA,CAAA,EAOhD,MAPgD,CAAA,MAAA,EAOjC,MAPiC,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;EAAf,cAAA,CAAA,EAQ/B,MAR+B,CAAA,MAAA,EAAA,OAAA,CAAA;EAIxC,SAAA,CAAA,EAKI,IALJ,CAKS,gBALT,EAAA,eAAA,CAAA;EACC,WAAA,CAAA,EAKK,eALL,CAAA,MAAA,CAAA;EACM,IAAA,CAAA,EAKR,MALQ,CAAA,MAAA,EAAA,OAAA,CAAA;CAAL;cAQN,UAP0B,EAOU,eAPV,CAAA,aAAA,CAAA;AAAf,iBASD,cATC,CAAA,iBAUE,WAVF,GAUgB,WAVhB,EAAA,gBAWC,MAXD,CAAA,MAAA,EAWgB,aAXhB,CAAA,GAWiC,MAXjC,CAAA,MAAA,EAWgD,aAXhD,CAAA,CAAA,CAAA,SAAA,CAAA,EAYJ,iBAZI,CAYc,QAZd,EAYwB,OAZxB,CAAA,CAAA,EAYwC,QAZxC,CAYiD,QAZjD,EAY2D,OAZ3D,CAAA;KA2DZ,cAAA,GAAiB,WA1DH,GAAA;EACA,SAAA,MAAA,EA0DA,MA1DA,CAAA,MAAA,EAAA,OAAA,CAAA;EAAL,SAAA,KAAA,CAAA,EA2DK,MA3DL,CAAA,MAAA,EAAA,OAAA,CAAA;CACE;KA6DX,YAAA,GAAe,aA5DX,CA4DyB,gBA5DzB,GAAA;EAAM,KAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAKC,iBAyDA,iBAAA,CAzDc,SAAA,CAAA,EA0DjB,iBA1DiB,CA0DC,cA1DD,EA0DiB,MA1DjB,CAAA,MAAA,EA0DgC,YA1DhC,CAAA,CAAA,CAAA,EA2D3B,QA3D2B,CA2DlB,cA3DkB,EA2DF,MA3DE,CAAA,MAAA,EA2Da,YA3Db,CAAA,CAAA"}
|
package/dist/testing.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as coreHash } from "./types-
|
|
2
|
-
import { n as computeProfileHash, r as computeStorageHash, t as computeExecutionHash } from "./hashing-
|
|
1
|
+
import { n as coreHash } from "./types-DYikGC04.mjs";
|
|
2
|
+
import { n as computeProfileHash, r as computeStorageHash, t as computeExecutionHash } from "./hashing-D1EPxYRl.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/testing-factories.ts
|
|
5
5
|
const DUMMY_HASH = coreHash("sha256:test");
|
package/dist/testing.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.mjs","names":[],"sources":["../src/testing-factories.ts"],"sourcesContent":["import type { Contract } from './contract-types';\nimport type { ContractModel, ModelStorageBase } from './domain-types';\nimport { computeExecutionHash, computeProfileHash, computeStorageHash } from './hashing';\nimport type { ExecutionSection, ProfileHashBase, StorageBase } from './types';\nimport { coreHash } from './types';\n\ntype ContractOverrides<\n TStorage extends StorageBase = StorageBase,\n TModels extends Record<string, ContractModel> = Record<string, ContractModel>,\n> = {\n target?: string;\n targetFamily?: string;\n roots?: Record<string, string>;\n models?: TModels;\n storage?: Omit<TStorage, 'storageHash'>;\n capabilities?: Record<string, Record<string, boolean>>;\n extensionPacks?: Record<string, unknown>;\n execution?: ExecutionSection
|
|
1
|
+
{"version":3,"file":"testing.mjs","names":[],"sources":["../src/testing-factories.ts"],"sourcesContent":["import type { Contract } from './contract-types';\nimport type { ContractModel, ModelStorageBase } from './domain-types';\nimport { computeExecutionHash, computeProfileHash, computeStorageHash } from './hashing';\nimport type { ExecutionSection, ProfileHashBase, StorageBase } from './types';\nimport { coreHash } from './types';\n\ntype ContractOverrides<\n TStorage extends StorageBase = StorageBase,\n TModels extends Record<string, ContractModel> = Record<string, ContractModel>,\n> = {\n target?: string;\n targetFamily?: string;\n roots?: Record<string, string>;\n models?: TModels;\n storage?: Omit<TStorage, 'storageHash'>;\n capabilities?: Record<string, Record<string, boolean>>;\n extensionPacks?: Record<string, unknown>;\n execution?: Omit<ExecutionSection, 'executionHash'>;\n profileHash?: ProfileHashBase<string>;\n meta?: Record<string, unknown>;\n};\n\nconst DUMMY_HASH = coreHash('sha256:test');\n\nexport function createContract<\n TStorage extends StorageBase = StorageBase,\n TModels extends Record<string, ContractModel> = Record<string, ContractModel>,\n>(overrides: ContractOverrides<TStorage, TModels> = {}): Contract<TStorage, TModels> {\n const target = overrides.target ?? 'postgres';\n const targetFamily = overrides.targetFamily ?? 'sql';\n const capabilities = overrides.capabilities ?? {};\n\n const rawStorage =\n overrides.storage ?? ({ tables: {} } as unknown as Omit<TStorage, 'storageHash'>);\n\n const storageHash = computeStorageHash({\n target,\n targetFamily,\n storage: rawStorage as Record<string, unknown>,\n });\n\n const storage = {\n ...rawStorage,\n storageHash,\n } as TStorage;\n\n const computedProfileHash =\n overrides.profileHash ?? computeProfileHash({ target, targetFamily, capabilities });\n\n return {\n target,\n targetFamily,\n roots: overrides.roots ?? {},\n models: (overrides.models ?? {}) as TModels,\n storage,\n capabilities,\n extensionPacks: overrides.extensionPacks ?? {},\n ...(overrides.execution !== undefined\n ? {\n execution: {\n ...overrides.execution,\n executionHash: computeExecutionHash({\n target,\n targetFamily,\n execution: overrides.execution,\n }),\n },\n }\n : {}),\n profileHash: computedProfileHash,\n meta: overrides.meta ?? {},\n };\n}\n\ntype SqlStorageLike = StorageBase & {\n readonly tables: Record<string, unknown>;\n readonly types?: Record<string, unknown>;\n};\n\ntype SqlModelLike = ContractModel<ModelStorageBase & { table: string }>;\n\nexport function createSqlContract(\n overrides: ContractOverrides<SqlStorageLike, Record<string, SqlModelLike>> = {},\n): Contract<SqlStorageLike, Record<string, SqlModelLike>> {\n return createContract<SqlStorageLike, Record<string, SqlModelLike>>({\n target: 'postgres',\n targetFamily: 'sql',\n storage: overrides.storage ?? { tables: {} },\n ...overrides,\n });\n}\n\nexport { DUMMY_HASH };\n"],"mappings":";;;;AAsBA,MAAM,aAAa,SAAS,cAAc;AAE1C,SAAgB,eAGd,YAAkD,EAAE,EAA+B;CACnF,MAAM,SAAS,UAAU,UAAU;CACnC,MAAM,eAAe,UAAU,gBAAgB;CAC/C,MAAM,eAAe,UAAU,gBAAgB,EAAE;CAEjD,MAAM,aACJ,UAAU,WAAY,EAAE,QAAQ,EAAE,EAAE;CAEtC,MAAM,cAAc,mBAAmB;EACrC;EACA;EACA,SAAS;EACV,CAAC;CAEF,MAAM,UAAU;EACd,GAAG;EACH;EACD;CAED,MAAM,sBACJ,UAAU,eAAe,mBAAmB;EAAE;EAAQ;EAAc;EAAc,CAAC;AAErF,QAAO;EACL;EACA;EACA,OAAO,UAAU,SAAS,EAAE;EAC5B,QAAS,UAAU,UAAU,EAAE;EAC/B;EACA;EACA,gBAAgB,UAAU,kBAAkB,EAAE;EAC9C,GAAI,UAAU,cAAc,SACxB,EACE,WAAW;GACT,GAAG,UAAU;GACb,eAAe,qBAAqB;IAClC;IACA;IACA,WAAW,UAAU;IACtB,CAAC;GACH,EACF,GACD,EAAE;EACN,aAAa;EACb,MAAM,UAAU,QAAQ,EAAE;EAC3B;;AAUH,SAAgB,kBACd,YAA6E,EAAE,EACvB;AACxD,QAAO,eAA6D;EAClE,QAAQ;EACR,cAAc;EACd,SAAS,UAAU,WAAW,EAAE,QAAQ,EAAE,EAAE;EAC5C,GAAG;EACJ,CAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
//#region src/types.ts
|
|
2
|
+
function executionHash(value) {
|
|
3
|
+
return value;
|
|
4
|
+
}
|
|
2
5
|
function coreHash(value) {
|
|
3
6
|
return value;
|
|
4
7
|
}
|
|
@@ -26,5 +29,5 @@ function isDocumentContract(contract) {
|
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
//#endregion
|
|
29
|
-
export {
|
|
30
|
-
//# sourceMappingURL=types-
|
|
32
|
+
export { isTaggedBigInt as a, isDocumentContract as i, coreHash as n, isTaggedRaw as o, executionHash as r, profileHash as s, bigintJsonReplacer as t };
|
|
33
|
+
//# sourceMappingURL=types-DYikGC04.mjs.map
|