@prisma-next/sql-relational-core 0.3.0-pr.99.6 → 0.3.0

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.
Files changed (163) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +20 -6
  3. package/dist/codec-types-DcEITed4.d.mts +144 -0
  4. package/dist/codec-types-DcEITed4.d.mts.map +1 -0
  5. package/dist/errors-Cs52upp3.d.mts +8 -0
  6. package/dist/errors-Cs52upp3.d.mts.map +1 -0
  7. package/dist/errors-D3xmG4h-.mjs +35 -0
  8. package/dist/errors-D3xmG4h-.mjs.map +1 -0
  9. package/dist/exports/ast.d.mts +158 -0
  10. package/dist/exports/ast.d.mts.map +1 -0
  11. package/dist/exports/ast.mjs +1358 -0
  12. package/dist/exports/ast.mjs.map +1 -0
  13. package/dist/exports/errors.d.mts +5 -0
  14. package/dist/exports/errors.mjs +3 -0
  15. package/dist/exports/plan.d.mts +2 -0
  16. package/dist/exports/plan.mjs +17 -0
  17. package/dist/exports/plan.mjs.map +1 -0
  18. package/dist/exports/query-lane-context.d.mts +3 -0
  19. package/dist/exports/query-lane-context.mjs +1 -0
  20. package/dist/exports/types.d.mts +4 -0
  21. package/dist/exports/types.mjs +1 -0
  22. package/dist/index.d.mts +11 -0
  23. package/dist/index.mjs +7 -0
  24. package/dist/plan-5qUWdlJM.d.mts +28 -0
  25. package/dist/plan-5qUWdlJM.d.mts.map +1 -0
  26. package/dist/query-lane-context-UlR8vOkd.d.mts +89 -0
  27. package/dist/query-lane-context-UlR8vOkd.d.mts.map +1 -0
  28. package/dist/types-CLCtwVWx.d.mts +485 -0
  29. package/dist/types-CLCtwVWx.d.mts.map +1 -0
  30. package/dist/types-V1qiC5DO.d.mts +200 -0
  31. package/dist/types-V1qiC5DO.d.mts.map +1 -0
  32. package/package.json +29 -51
  33. package/src/ast/adapter-types.ts +11 -0
  34. package/src/ast/codec-types.ts +101 -53
  35. package/src/ast/driver-types.ts +20 -3
  36. package/src/ast/sql-codecs.ts +142 -0
  37. package/src/ast/types.ts +1678 -88
  38. package/src/errors.ts +47 -1
  39. package/src/exports/ast.ts +1 -8
  40. package/src/index.ts +0 -3
  41. package/src/plan.ts +4 -4
  42. package/src/query-lane-context.ts +74 -11
  43. package/src/types.ts +102 -404
  44. package/dist/ast/adapter-types.d.ts +0 -28
  45. package/dist/ast/adapter-types.d.ts.map +0 -1
  46. package/dist/ast/codec-types.d.ts +0 -141
  47. package/dist/ast/codec-types.d.ts.map +0 -1
  48. package/dist/ast/common.d.ts +0 -7
  49. package/dist/ast/common.d.ts.map +0 -1
  50. package/dist/ast/delete.d.ts +0 -8
  51. package/dist/ast/delete.d.ts.map +0 -1
  52. package/dist/ast/driver-types.d.ts +0 -20
  53. package/dist/ast/driver-types.d.ts.map +0 -1
  54. package/dist/ast/insert.d.ts +0 -8
  55. package/dist/ast/insert.d.ts.map +0 -1
  56. package/dist/ast/join.d.ts +0 -6
  57. package/dist/ast/join.d.ts.map +0 -1
  58. package/dist/ast/order.d.ts +0 -6
  59. package/dist/ast/order.d.ts.map +0 -1
  60. package/dist/ast/predicate.d.ts +0 -4
  61. package/dist/ast/predicate.d.ts.map +0 -1
  62. package/dist/ast/select.d.ts +0 -18
  63. package/dist/ast/select.d.ts.map +0 -1
  64. package/dist/ast/types.d.ts +0 -130
  65. package/dist/ast/types.d.ts.map +0 -1
  66. package/dist/ast/update.d.ts +0 -9
  67. package/dist/ast/update.d.ts.map +0 -1
  68. package/dist/ast/util.d.ts +0 -2
  69. package/dist/ast/util.d.ts.map +0 -1
  70. package/dist/chunk-2BWK6XEY.js +0 -13
  71. package/dist/chunk-2BWK6XEY.js.map +0 -1
  72. package/dist/chunk-2F7DSEOU.js +0 -8
  73. package/dist/chunk-2F7DSEOU.js.map +0 -1
  74. package/dist/chunk-2MAKNVCP.js +0 -86
  75. package/dist/chunk-2MAKNVCP.js.map +0 -1
  76. package/dist/chunk-36WJWNHT.js +0 -1
  77. package/dist/chunk-36WJWNHT.js.map +0 -1
  78. package/dist/chunk-3F4RFQIB.js +0 -169
  79. package/dist/chunk-3F4RFQIB.js.map +0 -1
  80. package/dist/chunk-7I3EMQID.js +0 -16
  81. package/dist/chunk-7I3EMQID.js.map +0 -1
  82. package/dist/chunk-G52ENULI.js +0 -1
  83. package/dist/chunk-G52ENULI.js.map +0 -1
  84. package/dist/chunk-HV334QHG.js +0 -320
  85. package/dist/chunk-HV334QHG.js.map +0 -1
  86. package/dist/chunk-KYSP7L5C.js +0 -16
  87. package/dist/chunk-KYSP7L5C.js.map +0 -1
  88. package/dist/chunk-U7AXAUJA.js +0 -1
  89. package/dist/chunk-U7AXAUJA.js.map +0 -1
  90. package/dist/chunk-YXD25S5I.js +0 -171
  91. package/dist/chunk-YXD25S5I.js.map +0 -1
  92. package/dist/errors.d.ts +0 -2
  93. package/dist/errors.d.ts.map +0 -1
  94. package/dist/exports/ast.d.ts +0 -14
  95. package/dist/exports/ast.d.ts.map +0 -1
  96. package/dist/exports/ast.js +0 -46
  97. package/dist/exports/ast.js.map +0 -1
  98. package/dist/exports/errors.d.ts +0 -2
  99. package/dist/exports/errors.d.ts.map +0 -1
  100. package/dist/exports/errors.js +0 -9
  101. package/dist/exports/errors.js.map +0 -1
  102. package/dist/exports/guards.d.ts +0 -2
  103. package/dist/exports/guards.d.ts.map +0 -1
  104. package/dist/exports/guards.js +0 -31
  105. package/dist/exports/guards.js.map +0 -1
  106. package/dist/exports/operations-registry.d.ts +0 -2
  107. package/dist/exports/operations-registry.d.ts.map +0 -1
  108. package/dist/exports/operations-registry.js +0 -9
  109. package/dist/exports/operations-registry.js.map +0 -1
  110. package/dist/exports/param.d.ts +0 -3
  111. package/dist/exports/param.d.ts.map +0 -1
  112. package/dist/exports/param.js +0 -7
  113. package/dist/exports/param.js.map +0 -1
  114. package/dist/exports/plan.d.ts +0 -2
  115. package/dist/exports/plan.d.ts.map +0 -1
  116. package/dist/exports/plan.js +0 -7
  117. package/dist/exports/plan.js.map +0 -1
  118. package/dist/exports/query-lane-context.d.ts +0 -2
  119. package/dist/exports/query-lane-context.d.ts.map +0 -1
  120. package/dist/exports/query-lane-context.js +0 -2
  121. package/dist/exports/query-lane-context.js.map +0 -1
  122. package/dist/exports/schema.d.ts +0 -3
  123. package/dist/exports/schema.d.ts.map +0 -1
  124. package/dist/exports/schema.js +0 -13
  125. package/dist/exports/schema.js.map +0 -1
  126. package/dist/exports/types.d.ts +0 -2
  127. package/dist/exports/types.d.ts.map +0 -1
  128. package/dist/exports/types.js +0 -10
  129. package/dist/exports/types.js.map +0 -1
  130. package/dist/index.d.ts +0 -9
  131. package/dist/index.d.ts.map +0 -1
  132. package/dist/index.js +0 -81
  133. package/dist/index.js.map +0 -1
  134. package/dist/operations-registry.d.ts +0 -5
  135. package/dist/operations-registry.d.ts.map +0 -1
  136. package/dist/param.d.ts +0 -4
  137. package/dist/param.d.ts.map +0 -1
  138. package/dist/plan.d.ts +0 -23
  139. package/dist/plan.d.ts.map +0 -1
  140. package/dist/query-lane-context.d.ts +0 -27
  141. package/dist/query-lane-context.d.ts.map +0 -1
  142. package/dist/schema.d.ts +0 -83
  143. package/dist/schema.d.ts.map +0 -1
  144. package/dist/types.d.ts +0 -371
  145. package/dist/types.d.ts.map +0 -1
  146. package/dist/utils/guards.d.ts +0 -82
  147. package/dist/utils/guards.d.ts.map +0 -1
  148. package/src/ast/common.ts +0 -36
  149. package/src/ast/delete.ts +0 -17
  150. package/src/ast/insert.ts +0 -17
  151. package/src/ast/join.ts +0 -54
  152. package/src/ast/order.ts +0 -11
  153. package/src/ast/predicate.ts +0 -22
  154. package/src/ast/select.ts +0 -39
  155. package/src/ast/update.ts +0 -19
  156. package/src/exports/guards.ts +0 -15
  157. package/src/exports/operations-registry.ts +0 -1
  158. package/src/exports/param.ts +0 -2
  159. package/src/exports/schema.ts +0 -6
  160. package/src/operations-registry.ts +0 -276
  161. package/src/param.ts +0 -15
  162. package/src/schema.ts +0 -406
  163. package/src/utils/guards.ts +0 -193
package/src/errors.ts CHANGED
@@ -1 +1,47 @@
1
- export { planInvalid, planUnsupported } from '@prisma-next/plan';
1
+ import type { RuntimeError } from './types';
2
+
3
+ export function planInvalid(
4
+ message: string,
5
+ details?: Record<string, unknown>,
6
+ hints?: readonly string[],
7
+ docs?: readonly string[],
8
+ ): RuntimeError {
9
+ const error = new Error(message) as RuntimeError;
10
+
11
+ Object.defineProperty(error, 'name', {
12
+ value: 'RuntimeError',
13
+ configurable: true,
14
+ });
15
+
16
+ return Object.assign(error, {
17
+ code: 'PLAN.INVALID',
18
+ category: 'PLAN' as const,
19
+ severity: 'error' as const,
20
+ details,
21
+ hints,
22
+ docs,
23
+ });
24
+ }
25
+
26
+ export function planUnsupported(
27
+ message: string,
28
+ details?: Record<string, unknown>,
29
+ hints?: readonly string[],
30
+ docs?: readonly string[],
31
+ ): RuntimeError {
32
+ const error = new Error(message) as RuntimeError;
33
+
34
+ Object.defineProperty(error, 'name', {
35
+ value: 'RuntimeError',
36
+ configurable: true,
37
+ });
38
+
39
+ return Object.assign(error, {
40
+ code: 'PLAN.UNSUPPORTED',
41
+ category: 'PLAN' as const,
42
+ severity: 'error' as const,
43
+ details,
44
+ hints,
45
+ docs,
46
+ });
47
+ }
@@ -1,13 +1,6 @@
1
1
  export * from '../ast/adapter-types';
2
2
  export * from '../ast/codec-types';
3
- export * from '../ast/common';
4
- export * from '../ast/delete';
5
3
  export * from '../ast/driver-types';
6
- export * from '../ast/insert';
7
- export * from '../ast/join';
8
- export * from '../ast/order';
9
- export * from '../ast/predicate';
10
- export * from '../ast/select';
4
+ export * from '../ast/sql-codecs';
11
5
  export * from '../ast/types';
12
- export * from '../ast/update';
13
6
  export * from '../ast/util';
package/src/index.ts CHANGED
@@ -1,8 +1,5 @@
1
1
  export * from './exports/ast';
2
2
  export * from './exports/errors';
3
- export * from './exports/operations-registry';
4
- export * from './exports/param';
5
3
  export * from './exports/plan';
6
4
  export * from './exports/query-lane-context';
7
- export * from './exports/schema';
8
5
  export * from './exports/types';
package/src/plan.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ExecutionPlan, ParamDescriptor } from '@prisma-next/contract/types';
2
2
  import type { StorageColumn } from '@prisma-next/sql-contract/types';
3
- import type { QueryAst } from './ast/types';
3
+ import type { AnyQueryAst } from './ast/types';
4
4
 
5
5
  /**
6
6
  * SQL query plan produced by lanes before lowering.
@@ -8,13 +8,13 @@ import type { QueryAst } from './ast/types';
8
8
  * Lanes build ASTs and metadata but do not perform SQL lowering.
9
9
  * The `sql` field is absent - lowering happens in the runtime executor.
10
10
  *
11
- * Structurally aligns with ExecutionPlan<Row, QueryAst> (without sql field) to maintain
11
+ * Structurally aligns with ExecutionPlan<Row, AnyQueryAst> (without sql field) to maintain
12
12
  * compatibility with ExecutionPlan/Plan-based utilities.
13
13
  * The generic parameter `_Row` is preserved for type extraction via ResultType.
14
14
  */
15
15
  export interface SqlQueryPlan<_Row = unknown>
16
- extends Pick<ExecutionPlan<_Row, QueryAst>, 'params' | 'meta'> {
17
- readonly ast: QueryAst;
16
+ extends Pick<ExecutionPlan<_Row, AnyQueryAst>, 'params' | 'meta'> {
17
+ readonly ast: AnyQueryAst;
18
18
  // Phantom property to preserve generic parameter for type extraction
19
19
  // This allows ResultType to extract _Row for SqlQueryPlan values.
20
20
  readonly _Row?: _Row;
@@ -1,14 +1,69 @@
1
- import type { OperationRegistry } from '@prisma-next/operations';
2
- import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
1
+ import type { Contract } from '@prisma-next/contract/types';
2
+ import type { SqlStorage } from '@prisma-next/sql-contract/types';
3
+ import type { SqlOperationRegistry } from '@prisma-next/sql-operations';
3
4
  import type { CodecRegistry } from './ast/codec-types';
4
5
 
5
6
  /**
6
7
  * Registry of initialized type helpers from storage.types.
7
- * Each key is a type name from storage.types, and the value is the initialized helper
8
- * (or validated typeParams if no init hook was provided).
8
+ * Each key is a type name from storage.types, and the value is:
9
+ * - The result of the codec's init hook (if provided), or
10
+ * - The full StorageTypeInstance metadata (codecId, nativeType, typeParams) if no init hook
9
11
  */
10
12
  export type TypeHelperRegistry = Record<string, unknown>;
11
13
 
14
+ // =============================================================================
15
+ // JSON Schema Validation Types
16
+ // =============================================================================
17
+
18
+ /**
19
+ * A single validation error from JSON Schema validation.
20
+ */
21
+ export interface JsonSchemaValidationError {
22
+ readonly path: string;
23
+ readonly message: string;
24
+ readonly keyword: string;
25
+ }
26
+
27
+ /**
28
+ * Result of a JSON Schema validation.
29
+ */
30
+ export type JsonSchemaValidationResult =
31
+ | { readonly valid: true }
32
+ | { readonly valid: false; readonly errors: ReadonlyArray<JsonSchemaValidationError> };
33
+
34
+ /**
35
+ * A compiled JSON Schema validate function.
36
+ * Returns a structured result indicating whether the value conforms to the schema.
37
+ */
38
+ export type JsonSchemaValidateFn = (value: unknown) => JsonSchemaValidationResult;
39
+
40
+ /**
41
+ * Registry of compiled JSON Schema validators for columns with typed JSON/JSONB.
42
+ *
43
+ * Built during context creation by scanning the contract for columns whose codec
44
+ * descriptor provides an `init` hook that returns a `{ validate }` helper.
45
+ * Keys are `"table.column"` (e.g., `"user.metadata"`).
46
+ */
47
+ export interface JsonSchemaValidatorRegistry {
48
+ /** Get the compiled validator for a column. Key format: "table.column". */
49
+ get(key: string): JsonSchemaValidateFn | undefined;
50
+ /** Number of registered validators. */
51
+ readonly size: number;
52
+ }
53
+
54
+ export type MutationDefaultsOp = 'create' | 'update';
55
+
56
+ export type AppliedMutationDefault = {
57
+ readonly column: string;
58
+ readonly value: unknown;
59
+ };
60
+
61
+ export type MutationDefaultsOptions = {
62
+ readonly op: MutationDefaultsOp;
63
+ readonly table: string;
64
+ readonly values: Record<string, unknown>;
65
+ };
66
+
12
67
  /**
13
68
  * Minimal context interface for SQL query lanes.
14
69
  *
@@ -16,15 +71,23 @@ export type TypeHelperRegistry = Record<string, unknown>;
16
71
  * operation builders. This interface explicitly excludes runtime concerns like
17
72
  * adapters, connection management, and transaction state.
18
73
  */
19
- export interface QueryLaneContext<
20
- TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>,
21
- > {
74
+ export interface ExecutionContext<TContract extends Contract<SqlStorage> = Contract<SqlStorage>> {
22
75
  readonly contract: TContract;
23
- readonly operations: OperationRegistry;
24
76
  readonly codecs: CodecRegistry;
77
+ readonly queryOperations: SqlOperationRegistry;
78
+ /**
79
+ * Type helper registry for parameterized types.
80
+ * Schema builders expose these helpers via schema.types.
81
+ */
82
+ readonly types: TypeHelperRegistry;
83
+ /**
84
+ * Compiled JSON Schema validators for typed JSON/JSONB columns.
85
+ * Present only when the contract declares columns with JSON Schema typeParams.
86
+ */
87
+ readonly jsonSchemaValidators?: JsonSchemaValidatorRegistry;
25
88
  /**
26
- * Optional type helper registry for parameterized types.
27
- * When present, schema() will expose these helpers via schema.types.
89
+ * Applies execution-time mutation defaults for the given table.
90
+ * Returns the applied defaults (caller-provided values always win).
28
91
  */
29
- readonly types?: TypeHelperRegistry;
92
+ applyMutationDefaults(options: MutationDefaultsOptions): ReadonlyArray<AppliedMutationDefault>;
30
93
  }