@prisma-next/sql-relational-core 0.3.0-dev.3 → 0.3.0-dev.31

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 (117) hide show
  1. package/README.md +1 -1
  2. package/dist/ast/adapter-types.d.ts +28 -0
  3. package/dist/ast/adapter-types.d.ts.map +1 -0
  4. package/dist/{query-lane-context-BhOMmb_K.d.ts → ast/codec-types.d.ts} +14 -31
  5. package/dist/ast/codec-types.d.ts.map +1 -0
  6. package/dist/ast/common.d.ts +7 -0
  7. package/dist/ast/common.d.ts.map +1 -0
  8. package/dist/ast/delete.d.ts +8 -0
  9. package/dist/ast/delete.d.ts.map +1 -0
  10. package/dist/ast/driver-types.d.ts +20 -0
  11. package/dist/ast/driver-types.d.ts.map +1 -0
  12. package/dist/ast/insert.d.ts +8 -0
  13. package/dist/ast/insert.d.ts.map +1 -0
  14. package/dist/ast/join.d.ts +6 -0
  15. package/dist/ast/join.d.ts.map +1 -0
  16. package/dist/ast/order.d.ts +6 -0
  17. package/dist/ast/order.d.ts.map +1 -0
  18. package/dist/ast/predicate.d.ts +4 -0
  19. package/dist/ast/predicate.d.ts.map +1 -0
  20. package/dist/ast/select.d.ts +18 -0
  21. package/dist/ast/select.d.ts.map +1 -0
  22. package/dist/ast/types.d.ts +130 -0
  23. package/dist/ast/types.d.ts.map +1 -0
  24. package/dist/ast/update.d.ts +9 -0
  25. package/dist/ast/update.d.ts.map +1 -0
  26. package/dist/ast/util.d.ts +2 -0
  27. package/dist/ast/util.d.ts.map +1 -0
  28. package/dist/{chunk-MM74SVJ4.js → chunk-2BWK6XEY.js} +1 -1
  29. package/dist/chunk-2BWK6XEY.js.map +1 -0
  30. package/dist/{chunk-5N34PNVZ.js → chunk-2MAKNVCP.js} +25 -1
  31. package/dist/chunk-2MAKNVCP.js.map +1 -0
  32. package/dist/{chunk-M23L3JHG.js → chunk-3F4RFQIB.js} +45 -35
  33. package/dist/chunk-3F4RFQIB.js.map +1 -0
  34. package/dist/{chunk-WZBPVEZI.js → chunk-HV334QHG.js} +2 -2
  35. package/dist/chunk-HV334QHG.js.map +1 -0
  36. package/dist/{chunk-CBTYMOX2.js → chunk-YXD25S5I.js} +31 -12
  37. package/dist/chunk-YXD25S5I.js.map +1 -0
  38. package/dist/errors.d.ts +2 -0
  39. package/dist/errors.d.ts.map +1 -0
  40. package/dist/exports/ast.d.ts +14 -119
  41. package/dist/exports/ast.d.ts.map +1 -0
  42. package/dist/exports/ast.js +2 -2
  43. package/dist/exports/errors.d.ts +2 -1
  44. package/dist/exports/errors.d.ts.map +1 -0
  45. package/dist/exports/guards.d.ts +2 -63
  46. package/dist/exports/guards.d.ts.map +1 -0
  47. package/dist/exports/guards.js +13 -3
  48. package/dist/exports/operations-registry.d.ts +2 -13
  49. package/dist/exports/operations-registry.d.ts.map +1 -0
  50. package/dist/exports/operations-registry.js +2 -2
  51. package/dist/exports/param.d.ts +3 -14
  52. package/dist/exports/param.d.ts.map +1 -0
  53. package/dist/exports/plan.d.ts +2 -5
  54. package/dist/exports/plan.d.ts.map +1 -0
  55. package/dist/exports/query-lane-context.d.ts +2 -4
  56. package/dist/exports/query-lane-context.d.ts.map +1 -0
  57. package/dist/exports/schema.d.ts +3 -69
  58. package/dist/exports/schema.d.ts.map +1 -0
  59. package/dist/exports/schema.js +3 -4
  60. package/dist/exports/types.d.ts +2 -335
  61. package/dist/exports/types.d.ts.map +1 -0
  62. package/dist/exports/types.js +1 -1
  63. package/dist/index.d.ts +9 -13
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +5 -5
  66. package/dist/operations-registry.d.ts +5 -0
  67. package/dist/operations-registry.d.ts.map +1 -0
  68. package/dist/param.d.ts +4 -0
  69. package/dist/param.d.ts.map +1 -0
  70. package/dist/plan.d.ts +23 -0
  71. package/dist/plan.d.ts.map +1 -0
  72. package/dist/query-lane-context.d.ts +27 -0
  73. package/dist/query-lane-context.d.ts.map +1 -0
  74. package/dist/schema.d.ts +83 -0
  75. package/dist/schema.d.ts.map +1 -0
  76. package/dist/types.d.ts +371 -0
  77. package/dist/types.d.ts.map +1 -0
  78. package/dist/utils/guards.d.ts +82 -0
  79. package/dist/utils/guards.d.ts.map +1 -0
  80. package/package.json +19 -19
  81. package/src/ast/adapter-types.ts +36 -0
  82. package/src/ast/codec-types.ts +376 -0
  83. package/src/ast/common.ts +36 -0
  84. package/src/ast/delete.ts +17 -0
  85. package/src/ast/driver-types.ts +25 -0
  86. package/src/ast/insert.ts +17 -0
  87. package/src/ast/join.ts +54 -0
  88. package/src/ast/order.ts +11 -0
  89. package/src/ast/predicate.ts +22 -0
  90. package/src/ast/select.ts +39 -0
  91. package/src/ast/types.ts +147 -0
  92. package/src/ast/update.ts +19 -0
  93. package/src/ast/util.ts +9 -0
  94. package/src/errors.ts +1 -0
  95. package/src/exports/ast.ts +13 -0
  96. package/src/exports/errors.ts +1 -0
  97. package/src/exports/guards.ts +15 -0
  98. package/src/exports/operations-registry.ts +1 -0
  99. package/src/exports/param.ts +2 -0
  100. package/src/exports/plan.ts +1 -0
  101. package/src/exports/query-lane-context.ts +1 -0
  102. package/src/exports/schema.ts +6 -0
  103. package/src/exports/types.ts +1 -0
  104. package/src/index.ts +8 -0
  105. package/src/operations-registry.ts +276 -0
  106. package/src/param.ts +15 -0
  107. package/src/plan.ts +39 -0
  108. package/src/query-lane-context.ts +30 -0
  109. package/src/schema.ts +406 -0
  110. package/src/types.ts +598 -0
  111. package/src/utils/guards.ts +193 -0
  112. package/dist/chunk-5N34PNVZ.js.map +0 -1
  113. package/dist/chunk-CBTYMOX2.js.map +0 -1
  114. package/dist/chunk-M23L3JHG.js.map +0 -1
  115. package/dist/chunk-MM74SVJ4.js.map +0 -1
  116. package/dist/chunk-WZBPVEZI.js.map +0 -1
  117. package/dist/plan-D0OG5qzy.d.ts +0 -142
package/README.md CHANGED
@@ -97,7 +97,7 @@ flowchart TD
97
97
  - **`@prisma-next/contract`**: Core contract types
98
98
  - **`@prisma-next/plan`**: Plan error helpers (`planInvalid`, `planUnsupported`) and `RuntimeError` type
99
99
  - **`@prisma-next/runtime`**: Runtime context types (TODO: Slice 6 will clean this up)
100
- - **`@prisma-next/sql-target`**: SQL contract types, adapter interfaces
100
+ - **`@prisma-next/sql-contract`**: SQL contract types (via `@prisma-next/sql-contract/types`)
101
101
 
102
102
  **Note**: This package does not depend on specific adapters (e.g., `@prisma-next/adapter-postgres`). Test fixtures define `CodecTypes` inline to remain adapter-agnostic and avoid cyclic dependencies.
103
103
 
@@ -0,0 +1,28 @@
1
+ import type { CodecRegistry } from './codec-types';
2
+ export type AdapterTarget = string;
3
+ export interface AdapterProfile<TTarget extends AdapterTarget = AdapterTarget> {
4
+ readonly id: string;
5
+ readonly target: TTarget;
6
+ readonly capabilities: Record<string, unknown>;
7
+ /**
8
+ * Returns the adapter's default codec registry.
9
+ * The registry contains codecs provided by the adapter for converting
10
+ * between wire types and JavaScript types.
11
+ */
12
+ codecs(): CodecRegistry;
13
+ }
14
+ export interface LoweredPayload<TBody = unknown> {
15
+ readonly profileId?: string;
16
+ readonly body: TBody;
17
+ readonly annotations?: Record<string, unknown>;
18
+ }
19
+ export interface LowererContext<TContract = unknown> {
20
+ readonly contract: TContract;
21
+ readonly params?: readonly unknown[];
22
+ }
23
+ export type Lowerer<Ast = unknown, TContract = unknown, TBody = unknown> = (ast: Ast, context: LowererContext<TContract>) => LoweredPayload<TBody>;
24
+ export interface Adapter<Ast = unknown, TContract = unknown, TBody = unknown> {
25
+ readonly profile: AdapterProfile;
26
+ lower(ast: Ast, context: LowererContext<TContract>): LoweredPayload<TBody>;
27
+ }
28
+ //# sourceMappingURL=adapter-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter-types.d.ts","sourceRoot":"","sources":["../../src/ast/adapter-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,MAAM,aAAa,GAAG,MAAM,CAA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{ O } from 'ts-toolbelt';
4
-
1
+ import type { O } from 'ts-toolbelt';
5
2
  /**
6
3
  * Codec metadata for database-specific type information.
7
4
  * Used for schema introspection and verification.
8
5
  */
9
- interface CodecMeta {
6
+ export interface CodecMeta {
10
7
  readonly db?: {
11
8
  readonly sql?: {
12
9
  readonly postgres?: {
@@ -21,7 +18,7 @@ interface CodecMeta {
21
18
  * Codecs are pure, synchronous functions with no side effects or IO.
22
19
  * They provide deterministic conversion between database wire types and JS values.
23
20
  */
24
- interface Codec<Id extends string = string, TWire = unknown, TJs = unknown> {
21
+ export interface Codec<Id extends string = string, TWire = unknown, TJs = unknown> {
25
22
  /**
26
23
  * Namespaced codec identifier in format 'namespace/name@version'
27
24
  * Examples: 'pg/text@1', 'pg/uuid@1', 'pg/timestamptz@1'
@@ -57,7 +54,7 @@ interface Codec<Id extends string = string, TWire = unknown, TJs = unknown> {
57
54
  * scalar type; ordering in byScalar reflects preference (adapter first,
58
55
  * then packs, then app overrides).
59
56
  */
60
- interface CodecRegistry {
57
+ export interface CodecRegistry {
61
58
  get(id: string): Codec<string> | undefined;
62
59
  has(id: string): boolean;
63
60
  getByScalar(scalar: string): readonly Codec<string>[];
@@ -69,7 +66,7 @@ interface CodecRegistry {
69
66
  /**
70
67
  * Codec factory - creates a codec with typeId and encode/decode functions.
71
68
  */
72
- declare function codec<Id extends string, TWire, TJs>(config: {
69
+ export declare function codec<Id extends string, TWire, TJs>(config: {
73
70
  typeId: Id;
74
71
  targetTypes: readonly string[];
75
72
  encode: (value: TJs) => TWire;
@@ -79,15 +76,15 @@ declare function codec<Id extends string, TWire, TJs>(config: {
79
76
  /**
80
77
  * Type helpers to extract codec types.
81
78
  */
82
- type CodecId<T> = T extends Codec<infer Id, unknown, unknown> ? Id : T extends {
79
+ export type CodecId<T> = T extends Codec<infer Id, unknown, unknown> ? Id : T extends {
83
80
  readonly id: infer Id;
84
81
  } ? Id : never;
85
- type CodecInput<T> = T extends Codec<string, unknown, infer JsT> ? JsT : never;
86
- type CodecOutput<T> = T extends Codec<string, unknown, infer JsT> ? JsT : never;
82
+ export type CodecInput<T> = T extends Codec<string, unknown, infer JsT> ? JsT : never;
83
+ export type CodecOutput<T> = T extends Codec<string, unknown, infer JsT> ? JsT : never;
87
84
  /**
88
85
  * Type helper to extract codec types from builder instance.
89
86
  */
90
- type ExtractCodecTypes<ScalarNames extends {
87
+ export type ExtractCodecTypes<ScalarNames extends {
91
88
  readonly [K in keyof ScalarNames]: Codec<string>;
92
89
  } = Record<never, never>> = {
93
90
  readonly [K in keyof ScalarNames as ScalarNames[K] extends Codec<infer Id, unknown, unknown> ? Id : never]: {
@@ -102,7 +99,7 @@ type ExtractCodecTypes<ScalarNames extends {
102
99
  * we extract it by creating a mapped type that uses the Id as both key and value,
103
100
  * then extract the value type. This preserves literal types.
104
101
  */
105
- type ExtractDataTypes<ScalarNames extends {
102
+ export type ExtractDataTypes<ScalarNames extends {
106
103
  readonly [K in keyof ScalarNames]: Codec<string>;
107
104
  }> = {
108
105
  readonly [K in keyof ScalarNames]: {
@@ -112,7 +109,7 @@ type ExtractDataTypes<ScalarNames extends {
112
109
  /**
113
110
  * Builder interface for declaring codecs.
114
111
  */
115
- interface CodecDefBuilder<ScalarNames extends {
112
+ export interface CodecDefBuilder<ScalarNames extends {
116
113
  readonly [K in keyof ScalarNames]: Codec<string>;
117
114
  } = Record<never, never>> {
118
115
  readonly CodecTypes: ExtractCodecTypes<ScalarNames>;
@@ -136,23 +133,9 @@ interface CodecDefBuilder<ScalarNames extends {
136
133
  /**
137
134
  * Create a new codec registry.
138
135
  */
139
- declare function createCodecRegistry(): CodecRegistry;
136
+ export declare function createCodecRegistry(): CodecRegistry;
140
137
  /**
141
138
  * Create a new codec definition builder.
142
139
  */
143
- declare function defineCodecs(): CodecDefBuilder<Record<never, never>>;
144
-
145
- /**
146
- * Minimal context interface for SQL query lanes.
147
- *
148
- * Lanes only need contract, operations, and codecs to build typed ASTs and attach
149
- * operation builders. This interface explicitly excludes runtime concerns like
150
- * adapters, connection management, and transaction state.
151
- */
152
- interface QueryLaneContext<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>> {
153
- readonly contract: TContract;
154
- readonly operations: OperationRegistry;
155
- readonly codecs: CodecRegistry;
156
- }
157
-
158
- export { type CodecMeta as C, type ExtractCodecTypes as E, type QueryLaneContext as Q, type Codec as a, type CodecRegistry as b, codec as c, type CodecId as d, type CodecInput as e, type CodecOutput as f, type ExtractDataTypes as g, type CodecDefBuilder as h, createCodecRegistry as i, defineCodecs as j };
140
+ export declare function defineCodecs(): CodecDefBuilder<Record<never, never>>;
141
+ //# sourceMappingURL=codec-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec-types.d.ts","sourceRoot":"","sources":["../../src/ast/codec-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAErC;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,CAAC,EAAE;QACZ,QAAQ,CAAC,GAAG,CAAC,EAAE;YACb,QAAQ,CAAC,QAAQ,CAAC,EAAE;gBAClB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;aAC7B,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED;;;;;GAKG;AACH,MAAM,WAAW,KAAK,CAAC,EAAE,SAAS,MAAM,GAAG,MAAM,EAAE,KAAK,GAAG,OAAO,EAAE,GAAG,GAAG,OAAO;IAC/E;;;OAGG;IACH,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAExC;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;IAE1B;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,KAAK,GAAG,GAAG,CAAC;IAEzB;;;;OAIG;IACH,MAAM,CAAC,CAAC,KAAK,EAAE,GAAG,GA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,EAAE,EAAE,IAAI,MAAM,iBAAiB,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE;SACxE,CAAC,MAAM,iBAAiB,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KACtD,CAAC;CACH;AAkHD;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAEnD;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,eAAe,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAEpE"}
@@ -0,0 +1,7 @@
1
+ import type { ColumnRef, LiteralExpr, OperationExpr, ParamRef, TableRef } from './types';
2
+ export declare function createTableRef(name: string): TableRef;
3
+ export declare function createColumnRef(table: string, column: string): ColumnRef;
4
+ export declare function createParamRef(index: number, name?: string): ParamRef;
5
+ export declare function createOperationExpr(operation: OperationExpr): OperationExpr;
6
+ export declare function createLiteralExpr(value: unknown): LiteralExpr;
7
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/ast/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGzF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAKrD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAMxE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,CAMrE;AAED,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,aAAa,GAAG,aAAa,CAE3E;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAK7D"}
@@ -0,0 +1,8 @@
1
+ import type { BinaryExpr, ColumnRef, DeleteAst, TableRef } from './types';
2
+ export interface CreateDeleteAstOptions {
3
+ readonly table: TableRef;
4
+ readonly where: BinaryExpr;
5
+ readonly returning?: ReadonlyArray<ColumnRef>;
6
+ }
7
+ export declare function createDeleteAst(options: CreateDeleteAstOptions): DeleteAst;
8
+ //# sourceMappingURL=delete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../src/ast/delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG1E,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CAC/C;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,SAAS,CAO1E"}
@@ -0,0 +1,20 @@
1
+ export interface SqlExecuteRequest {
2
+ readonly sql: string;
3
+ readonly params?: readonly unknown[];
4
+ }
5
+ export interface SqlQueryResult<Row = Record<string, unknown>> {
6
+ readonly rows: ReadonlyArray<Row>;
7
+ readonly rowCount?: number | null;
8
+ readonly [key: string]: unknown;
9
+ }
10
+ export interface SqlExplainResult<Row = Record<string, unknown>> {
11
+ readonly rows: ReadonlyArray<Row>;
12
+ }
13
+ export interface SqlDriver {
14
+ connect(): Promise<void>;
15
+ execute<Row = Record<string, unknown>>(request: SqlExecuteRequest): AsyncIterable<Row>;
16
+ explain?(request: SqlExecuteRequest): Promise<SqlExplainResult>;
17
+ query<Row = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<SqlQueryResult<Row>>;
18
+ close(): Promise<void>;
19
+ }
20
+ //# sourceMappingURL=driver-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver-types.d.ts","sourceRoot":"","sources":["../../src/ast/driver-types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;CACtC;AAED,MAAM,WAAW,cAAc,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC3D,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAClC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACjC;AAED,MAAM,WAAW,gBAAgB,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC7D,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IACvF,OAAO,CAAC,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAChE,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAC1B,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;IAChC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
@@ -0,0 +1,8 @@
1
+ import type { ColumnRef, InsertAst, ParamRef, TableRef } from './types';
2
+ export interface CreateInsertAstOptions {
3
+ readonly table: TableRef;
4
+ readonly values: Record<string, ColumnRef | ParamRef>;
5
+ readonly returning?: ReadonlyArray<ColumnRef>;
6
+ }
7
+ export declare function createInsertAst(options: CreateInsertAstOptions): InsertAst;
8
+ //# sourceMappingURL=insert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insert.d.ts","sourceRoot":"","sources":["../../src/ast/insert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxE,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC,CAAC;IACtD,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CAC/C;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,SAAS,CAO1E"}
@@ -0,0 +1,6 @@
1
+ import type { JoinOnBuilder } from '../types';
2
+ import type { ColumnRef, JoinAst, JoinOnExpr, TableRef } from './types';
3
+ export declare function createJoin(joinType: 'inner' | 'left' | 'right' | 'full', table: TableRef, on: JoinOnExpr): JoinAst;
4
+ export declare function createJoinOnExpr(left: ColumnRef, right: ColumnRef): JoinOnExpr;
5
+ export declare function createJoinOnBuilder(): JoinOnBuilder;
6
+ //# sourceMappingURL=join.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join.d.ts","sourceRoot":"","sources":["../../src/ast/join.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,aAAa,EAAmB,MAAM,UAAU,CAAC;AAEjF,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExE,wBAAgB,UAAU,CACxB,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAC7C,KAAK,EAAE,QAAQ,EACf,EAAE,EAAE,UAAU,GACb,OAAO,CAOT;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,UAAU,CAM9E;AA2BD,wBAAgB,mBAAmB,IAAI,aAAa,CAEnD"}
@@ -0,0 +1,6 @@
1
+ import type { ColumnRef, Direction, OperationExpr } from './types';
2
+ export declare function createOrderByItem(expr: ColumnRef | OperationExpr, dir: 'asc' | 'desc'): {
3
+ expr: ColumnRef | OperationExpr;
4
+ dir: Direction;
5
+ };
6
+ //# sourceMappingURL=order.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order.d.ts","sourceRoot":"","sources":["../../src/ast/order.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEnE,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,SAAS,GAAG,aAAa,EAC/B,GAAG,EAAE,KAAK,GAAG,MAAM,GAClB;IAAE,IAAI,EAAE,SAAS,GAAG,aAAa,CAAC;IAAC,GAAG,EAAE,SAAS,CAAA;CAAE,CAKrD"}
@@ -0,0 +1,4 @@
1
+ import type { BinaryExpr, BinaryOp, ExistsExpr, Expression, ParamRef, SelectAst } from './types';
2
+ export declare function createBinaryExpr(op: BinaryOp, left: Expression, right: Expression | ParamRef): BinaryExpr;
3
+ export declare function createExistsExpr(not: boolean, subquery: SelectAst): ExistsExpr;
4
+ //# sourceMappingURL=predicate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predicate.d.ts","sourceRoot":"","sources":["../../src/ast/predicate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEjG,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,QAAQ,EACZ,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,UAAU,GAAG,QAAQ,GAC3B,UAAU,CAOZ;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,GAAG,UAAU,CAM9E"}
@@ -0,0 +1,18 @@
1
+ import type { BinaryExpr, ColumnRef, Direction, ExistsExpr, IncludeAst, IncludeRef, JoinAst, OperationExpr, SelectAst, TableRef } from './types';
2
+ export interface CreateSelectAstOptions {
3
+ readonly from: TableRef;
4
+ readonly joins?: ReadonlyArray<JoinAst>;
5
+ readonly includes?: ReadonlyArray<IncludeAst>;
6
+ readonly project: ReadonlyArray<{
7
+ alias: string;
8
+ expr: ColumnRef | IncludeRef | OperationExpr;
9
+ }>;
10
+ readonly where?: BinaryExpr | ExistsExpr;
11
+ readonly orderBy?: ReadonlyArray<{
12
+ expr: ColumnRef | OperationExpr;
13
+ dir: Direction;
14
+ }>;
15
+ readonly limit?: number;
16
+ }
17
+ export declare function createSelectAst(options: CreateSelectAstOptions): SelectAst;
18
+ //# sourceMappingURL=select.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/ast/select.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,UAAU,EACV,UAAU,EACV,UAAU,EACV,OAAO,EACP,aAAa,EACb,SAAS,EACT,QAAQ,EACT,MAAM,SAAS,CAAC;AAGjB,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IACxC,QAAQ,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IAC9C,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;QAC9B,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,SAAS,GAAG,UAAU,GAAG,aAAa,CAAC;KAC9C,CAAC,CAAC;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;IACzC,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;QAAE,IAAI,EAAE,SAAS,GAAG,aAAa,CAAC;QAAC,GAAG,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;IACtF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,SAAS,CAW1E"}
@@ -0,0 +1,130 @@
1
+ import type { ReturnSpec } from '@prisma-next/operations';
2
+ import type { SqlLoweringSpec } from '@prisma-next/sql-operations';
3
+ export type Direction = 'asc' | 'desc';
4
+ export interface TableRef {
5
+ readonly kind: 'table';
6
+ readonly name: string;
7
+ }
8
+ export interface ColumnRef {
9
+ readonly kind: 'col';
10
+ readonly table: string;
11
+ readonly column: string;
12
+ }
13
+ export interface ParamRef {
14
+ readonly kind: 'param';
15
+ readonly index: number;
16
+ readonly name?: string;
17
+ }
18
+ export interface LiteralExpr {
19
+ readonly kind: 'literal';
20
+ readonly value: unknown;
21
+ }
22
+ export interface OperationExpr {
23
+ readonly kind: 'operation';
24
+ readonly method: string;
25
+ readonly forTypeId: string;
26
+ readonly self: Expression;
27
+ readonly args: ReadonlyArray<Expression | ParamRef | LiteralExpr>;
28
+ readonly returns: ReturnSpec;
29
+ readonly lowering: SqlLoweringSpec;
30
+ }
31
+ /**
32
+ * Unified expression type - the canonical AST representation for column references
33
+ * and operation expressions. This is what all builders convert to via toExpr().
34
+ */
35
+ export type Expression = ColumnRef | OperationExpr;
36
+ /**
37
+ * Interface for any builder that can produce an Expression.
38
+ * Implemented by ColumnBuilder and ExpressionBuilder.
39
+ */
40
+ export interface ExpressionSource {
41
+ toExpr(): Expression;
42
+ }
43
+ export declare function isOperationExpr(expr: Expression): expr is OperationExpr;
44
+ export type BinaryOp = 'eq' | 'neq' | 'gt' | 'lt' | 'gte' | 'lte';
45
+ export interface BinaryExpr {
46
+ readonly kind: 'bin';
47
+ readonly op: BinaryOp;
48
+ readonly left: Expression;
49
+ readonly right: Expression | ParamRef;
50
+ }
51
+ export interface ExistsExpr {
52
+ readonly kind: 'exists';
53
+ readonly not: boolean;
54
+ readonly subquery: SelectAst;
55
+ }
56
+ export type JoinOnExpr = {
57
+ readonly kind: 'eqCol';
58
+ readonly left: ColumnRef;
59
+ readonly right: ColumnRef;
60
+ };
61
+ export interface JoinAst {
62
+ readonly kind: 'join';
63
+ readonly joinType: 'inner' | 'left' | 'right' | 'full';
64
+ readonly table: TableRef;
65
+ readonly on: JoinOnExpr;
66
+ }
67
+ export interface IncludeRef {
68
+ readonly kind: 'includeRef';
69
+ readonly alias: string;
70
+ }
71
+ export interface IncludeAst {
72
+ readonly kind: 'includeMany';
73
+ readonly alias: string;
74
+ readonly child: {
75
+ readonly table: TableRef;
76
+ readonly on: JoinOnExpr;
77
+ readonly where?: BinaryExpr | ExistsExpr;
78
+ readonly orderBy?: ReadonlyArray<{
79
+ expr: Expression;
80
+ dir: Direction;
81
+ }>;
82
+ readonly limit?: number;
83
+ readonly project: ReadonlyArray<{
84
+ alias: string;
85
+ expr: Expression;
86
+ }>;
87
+ };
88
+ }
89
+ export interface SelectAst {
90
+ readonly kind: 'select';
91
+ readonly from: TableRef;
92
+ readonly joins?: ReadonlyArray<JoinAst>;
93
+ readonly includes?: ReadonlyArray<IncludeAst>;
94
+ readonly project: ReadonlyArray<{
95
+ alias: string;
96
+ expr: Expression | IncludeRef | LiteralExpr;
97
+ }>;
98
+ readonly where?: BinaryExpr | ExistsExpr;
99
+ readonly orderBy?: ReadonlyArray<{
100
+ expr: Expression;
101
+ dir: Direction;
102
+ }>;
103
+ readonly limit?: number;
104
+ }
105
+ export interface InsertAst {
106
+ readonly kind: 'insert';
107
+ readonly table: TableRef;
108
+ readonly values: Record<string, ColumnRef | ParamRef>;
109
+ readonly returning?: ReadonlyArray<ColumnRef>;
110
+ }
111
+ export interface UpdateAst {
112
+ readonly kind: 'update';
113
+ readonly table: TableRef;
114
+ readonly set: Record<string, ColumnRef | ParamRef>;
115
+ readonly where: BinaryExpr;
116
+ readonly returning?: ReadonlyArray<ColumnRef>;
117
+ }
118
+ export interface DeleteAst {
119
+ readonly kind: 'delete';
120
+ readonly table: TableRef;
121
+ readonly where: BinaryExpr;
122
+ readonly returning?: ReadonlyArray<ColumnRef>;
123
+ }
124
+ export type QueryAst = SelectAst | InsertAst | UpdateAst | DeleteAst;
125
+ export interface LoweredStatement {
126
+ readonly sql: string;
127
+ readonly params: readonly unknown[];
128
+ readonly annotations?: Record<string, unknown>;
129
+ }
130
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ast/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAKnE,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC;AAEvC,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,M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K,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CAC/C;AAED,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAErE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC;IACpC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChD"}
@@ -0,0 +1,9 @@
1
+ import type { BinaryExpr, ColumnRef, ParamRef, TableRef, UpdateAst } from './types';
2
+ export interface CreateUpdateAstOptions {
3
+ readonly table: TableRef;
4
+ readonly set: Record<string, ColumnRef | ParamRef>;
5
+ readonly where: BinaryExpr;
6
+ readonly returning?: ReadonlyArray<ColumnRef>;
7
+ }
8
+ export declare function createUpdateAst(options: CreateUpdateAstOptions): UpdateAst;
9
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../src/ast/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC,CAAC;IACnD,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CAC/C;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,SAAS,CAQ1E"}
@@ -0,0 +1,2 @@
1
+ export declare function compact<T extends Record<string, unknown>>(o: T): T;
2
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/ast/util.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAQlE"}
@@ -10,4 +10,4 @@ export {
10
10
  createOrderBuilder,
11
11
  isColumnBuilder
12
12
  };
13
- //# sourceMappingURL=chunk-MM74SVJ4.js.map
13
+ //# sourceMappingURL=chunk-2BWK6XEY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n ResultType as CoreResultType,\n ExecutionPlan,\n PlanRefs,\n} from '@prisma-next/contract/types';\nimport type { ArgSpec, ReturnSpec } from '@prisma-next/operations';\nimport type { SqlContract, SqlStorage, StorageColumn } from '@prisma-next/sql-contract/types';\nimport type { SqlLoweringSpec } from '@prisma-next/sql-operations';\nimport type {\n BinaryOp,\n ColumnRef,\n Direction,\n Expression,\n ExpressionSource,\n OperationExpr,\n ParamRef,\n QueryAst,\n} from './ast/types';\nimport type { SqlQueryPlan } from './plan';\nimport type { QueryLaneContext } from './query-lane-context';\n\nexport interface ParamPlaceholder {\n readonly kind: 'param-placeholder';\n readonly name: string;\n}\n\n/**\n * ValueSource represents any value that can appear in a comparison or as an argument.\n * This includes:\n * - ParamPlaceholder: A parameter placeholder (e.g., `param('userId')`)\n * - ExpressionSource: Something that can be converted to an Expression (ColumnBuilder, ExpressionBuilder)\n */\nexport type ValueSource = ParamPlaceholder | ExpressionSource;\n\nexport interface OrderBuilder<\n _ColumnName extends string = string,\n _ColumnMeta extends StorageColumn = StorageColumn,\n _JsType = unknown,\n> {\n readonly kind: 'order';\n readonly expr: Expression;\n readonly dir: Direction;\n}\n\n/**\n * Creates an OrderBuilder for use in orderBy clauses.\n */\nexport function createOrderBuilder(\n expr: AnyColumnBuilder | OperationExpr,\n dir: Direction,\n): AnyOrderBuilder {\n return { kind: 'order', expr, dir } as AnyOrderBuilder;\n}\n\n/**\n * ColumnBuilder with optional operation methods based on the column's typeId.\n * When Operations is provided and the column's typeId matches, operation methods are included.\n * Implements ExpressionSource to provide type-safe conversion to ColumnRef.\n */\nexport type ColumnBuilder<\n ColumnName extends string = string,\n ColumnMeta extends StorageColumn = StorageColumn,\n JsType = unknown,\n Operations extends OperationTypes = Record<string, never>,\n> = {\n readonly kind: 'column';\n readonly table: string;\n readonly column: ColumnName;\n readonly columnMeta: ColumnMeta;\n // Methods accept ValueSource (ParamPlaceholder or ExpressionSource)\n eq(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;\n neq(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;\n gt(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;\n lt(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;\n gte(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;\n lte(value: ValueSource): BinaryBuilder<ColumnName, ColumnMeta, JsType>;\n asc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;\n desc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;\n /** Converts this column builder to a ColumnRef expression */\n toExpr(): ColumnRef;\n // Helper property for type extraction (not used at runtime)\n readonly __jsType: JsType;\n} & (ColumnMeta['codecId'] extends string\n ? ColumnMeta['codecId'] extends keyof Operations\n ? OperationMethods<\n OperationsForTypeId<ColumnMeta['codecId'] & string, Operations>,\n ColumnName,\n StorageColumn,\n JsType\n >\n : Record<string, never>\n : Record<string, never>);\n\nexport interface BinaryBuilder<\n _ColumnName extends string = string,\n _ColumnMeta extends StorageColumn = StorageColumn,\n _JsType = unknown,\n> {\n readonly kind: 'binary';\n readonly op: BinaryOp;\n readonly left: Expression;\n readonly right: ValueSource;\n}\n\n// Forward declare AnyBinaryBuilder and AnyOrderBuilder for use in ExpressionBuilder\nexport type AnyBinaryBuilder = BinaryBuilder;\nexport type AnyOrderBuilder = OrderBuilder;\n\n/**\n * ExpressionBuilder represents the result of an operation (e.g., col.distance(...)).\n * Unlike ColumnBuilder (which represents a column), ExpressionBuilder represents\n * an operation expression and provides the same DSL methods for chaining.\n *\n * Implements ExpressionSource to provide type-safe conversion to OperationExpr.\n */\nexport interface ExpressionBuilder<JsType = unknown> extends ExpressionSource {\n readonly kind: 'expression';\n readonly expr: OperationExpr;\n readonly columnMeta: StorageColumn;\n\n // Methods accept ValueSource (ParamPlaceholder or ExpressionSource)\n eq(value: ValueSource): AnyBinaryBuilder;\n neq(value: ValueSource): AnyBinaryBuilder;\n gt(value: ValueSource): AnyBinaryBuilder;\n lt(value: ValueSource): AnyBinaryBuilder;\n gte(value: ValueSource): AnyBinaryBuilder;\n lte(value: ValueSource): AnyBinaryBuilder;\n asc(): AnyOrderBuilder;\n desc(): AnyOrderBuilder;\n\n /** Converts this expression builder to the underlying OperationExpr */\n toExpr(): OperationExpr;\n\n // Helper property for type extraction (not used at runtime)\n readonly __jsType: JsType;\n}\n\n// Helper aliases for usage sites where the specific column parameters are irrelevant\n// Accepts any ColumnBuilder regardless of its Operations parameter\n// Note: We use `any` here because TypeScript's variance rules don't allow us to express\n// \"any type that extends OperationTypes\" in a way that works for assignment.\n// Contract-specific OperationTypes (e.g., PgVectorOperationTypes) are not assignable\n// to the base OperationTypes in generic parameter position, even though they extend it structurally.\n// Helper type that accepts any ColumnBuilder regardless of its generic parameters\n// This is needed because conditional types in ColumnBuilder create incompatible intersection types\n// when Operations differs, even though structurally they're compatible\nexport type AnyColumnBuilderBase = {\n readonly kind: 'column';\n readonly table: string;\n readonly column: string;\n readonly columnMeta: StorageColumn;\n // Methods accept ValueSource (ParamPlaceholder or ExpressionSource)\n eq(value: ValueSource): AnyBinaryBuilder;\n neq(value: ValueSource): AnyBinaryBuilder;\n gt(value: ValueSource): AnyBinaryBuilder;\n lt(value: ValueSource): AnyBinaryBuilder;\n gte(value: ValueSource): AnyBinaryBuilder;\n lte(value: ValueSource): AnyBinaryBuilder;\n asc(): AnyOrderBuilder;\n desc(): AnyOrderBuilder;\n toExpr(): ColumnRef;\n readonly __jsType: unknown;\n // Allow any operation methods (from conditional type)\n readonly [key: string]: unknown;\n};\n\nexport type AnyColumnBuilder =\n | ColumnBuilder<\n string,\n StorageColumn,\n unknown,\n // biome-ignore lint/suspicious/noExplicitAny: AnyColumnBuilder must accept column builders with any operation types\n any\n >\n | AnyColumnBuilderBase;\n\n/**\n * Union type for any builder that can produce an Expression.\n * Used in DSL method signatures where either a column or operation result can be passed.\n */\nexport type AnyExpressionSource = AnyColumnBuilder | ExpressionBuilder;\n\nexport function isColumnBuilder(value: unknown): value is AnyColumnBuilder {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'kind' in value &&\n (value as { kind: unknown }).kind === 'column'\n );\n}\n\nexport interface JoinOnBuilder {\n eqCol(left: AnyColumnBuilder, right: AnyColumnBuilder): JoinOnPredicate;\n}\n\nexport interface JoinOnPredicate {\n readonly kind: 'join-on';\n readonly left: AnyColumnBuilder;\n readonly right: AnyColumnBuilder;\n}\n\nexport type Expr = ColumnRef | ParamRef;\n\n/**\n * Helper type to extract codec output type from CodecTypes.\n * Returns never if the codecId is not found in CodecTypes.\n */\ntype ExtractCodecOutputType<\n CodecId extends string,\n CodecTypes extends Record<string, { readonly output: unknown }>,\n> = CodecId extends keyof CodecTypes\n ? CodecTypes[CodecId] extends { readonly output: infer Output }\n ? Output\n : never\n : never;\n\n/**\n * Type-level operation signature.\n * Represents an operation at the type level, similar to OperationSignature at runtime.\n */\nexport type OperationTypeSignature = {\n readonly args: ReadonlyArray<ArgSpec>;\n readonly returns: ReturnSpec;\n readonly lowering: SqlLoweringSpec;\n readonly capabilities?: ReadonlyArray<string>;\n};\n\n/**\n * Type-level operation registry.\n * Maps typeId → operations, where operations is a record of method name → operation signature.\n *\n * Example:\n * ```typescript\n * type MyOperations: OperationTypes = {\n * 'pg/vector@1': {\n * cosineDistance: {\n * args: [{ kind: 'typeId'; type: 'pg/vector@1' }];\n * returns: { kind: 'builtin'; type: 'number' };\n * lowering: { targetFamily: 'sql'; strategy: 'function'; template: '...' };\n * };\n * };\n * };\n * ```\n */\nexport type OperationTypes = Record<string, Record<string, OperationTypeSignature>>;\n\n/**\n * CodecTypes represents a map of typeId to codec definitions.\n * Each codec definition must have an `output` property indicating the JavaScript type.\n *\n * Example:\n * ```typescript\n * type MyCodecTypes: CodecTypes = {\n * 'pg/int4@1': { output: number };\n * 'pg/text@1': { output: string };\n * };\n * ```\n */\nexport type CodecTypes = Record<string, { readonly output: unknown }>;\n\n/**\n * Extracts operations for a given typeId from the operation registry.\n * Returns an empty record if the typeId is not found.\n *\n * @example\n * ```typescript\n * type Ops = OperationsForTypeId<'pg/vector@1', MyOperations>;\n * // Ops = { cosineDistance: { ... }, l2Distance: { ... } }\n * ```\n */\nexport type OperationsForTypeId<\n TypeId extends string,\n Operations extends OperationTypes,\n> = Operations extends Record<string, never>\n ? Record<string, never>\n : TypeId extends keyof Operations\n ? Operations[TypeId]\n : Record<string, never>;\n\n/**\n * Maps operation signatures to method signatures on ColumnBuilder.\n * Each operation becomes a method that returns a ColumnBuilder or BinaryBuilder\n * based on the return type.\n */\ntype OperationMethods<\n Ops extends Record<string, OperationTypeSignature>,\n ColumnName extends string,\n ColumnMeta extends StorageColumn,\n JsType,\n> = {\n [K in keyof Ops]: Ops[K] extends OperationTypeSignature\n ? (\n ...args: OperationArgs<Ops[K]['args']>\n ) => OperationReturn<Ops[K]['returns'], ColumnName, ColumnMeta, JsType>\n : never;\n};\n\n/**\n * Maps operation argument specs to TypeScript argument types.\n * - typeId args: ColumnBuilder (accepts base columns or operation results)\n * - param args: ParamPlaceholder\n * - literal args: unknown (could be more specific in future)\n */\ntype OperationArgs<Args extends ReadonlyArray<ArgSpec>> = Args extends readonly [\n infer First,\n ...infer Rest,\n]\n ? First extends ArgSpec\n ? [ArgToType<First>, ...(Rest extends ReadonlyArray<ArgSpec> ? OperationArgs<Rest> : [])]\n : []\n : [];\n\ntype ArgToType<Arg extends ArgSpec> = Arg extends { kind: 'typeId' }\n ? AnyExpressionSource\n : Arg extends { kind: 'param' }\n ? ParamPlaceholder\n : Arg extends { kind: 'literal' }\n ? unknown\n : never;\n\n/**\n * Maps operation return spec to return type.\n * Operations return ExpressionBuilder, not ColumnBuilder, because the result\n * represents an expression (OperationExpr) rather than a column reference.\n */\ntype OperationReturn<\n Returns extends ReturnSpec,\n _ColumnName extends string,\n _ColumnMeta extends StorageColumn,\n _JsType,\n> = Returns extends { kind: 'builtin'; type: infer T }\n ? T extends 'number'\n ? ExpressionBuilder<number>\n : T extends 'boolean'\n ? ExpressionBuilder<boolean>\n : T extends 'string'\n ? ExpressionBuilder<string>\n : ExpressionBuilder<unknown>\n : Returns extends { kind: 'typeId' }\n ? ExpressionBuilder<unknown>\n : ExpressionBuilder<unknown>;\n\n/**\n * Computes JavaScript type for a column at column creation time.\n *\n * Type inference:\n * - Read columnMeta.codecId as typeId string literal\n * - Look up CodecTypes[typeId].output\n * - Apply nullability: nullable ? Output | null : Output\n */\ntype ColumnMetaTypeId<ColumnMeta> = ColumnMeta extends { codecId: infer CodecId extends string }\n ? CodecId\n : ColumnMeta extends { type: infer TypeId extends string }\n ? TypeId\n : never;\n\nexport type ComputeColumnJsType<\n _Contract extends SqlContract<SqlStorage>,\n _TableName extends string,\n _ColumnName extends string,\n ColumnMeta extends StorageColumn,\n CodecTypes extends Record<string, { readonly output: unknown }>,\n> = ColumnMeta extends { nullable: infer Nullable }\n ? ColumnMetaTypeId<ColumnMeta> extends infer TypeId\n ? TypeId extends string\n ? ExtractCodecOutputType<TypeId, CodecTypes> extends infer CodecOutput\n ? [CodecOutput] extends [never]\n ? unknown // Codec not found in CodecTypes\n : Nullable extends true\n ? CodecOutput | null\n : CodecOutput\n : unknown\n : unknown\n : unknown\n : unknown;\n\n/**\n * Infers Row type from a projection object.\n * Maps Record<string, ColumnBuilder> to Record<string, JSType>\n *\n * Extracts the pre-computed JsType from each ColumnBuilder in the projection.\n */\n/**\n * Extracts the inferred JsType carried by a ColumnBuilder.\n */\ntype ExtractJsTypeFromColumnBuilder<CB extends AnyColumnBuilder> =\n CB extends ColumnBuilder<\n infer _ColumnName extends string,\n infer _ColumnMeta extends StorageColumn,\n infer JsType,\n infer _Ops\n >\n ? JsType\n : never;\n\nexport type InferProjectionRow<P extends Record<string, AnyColumnBuilder>> = {\n [K in keyof P]: ExtractJsTypeFromColumnBuilder<P[K]>;\n};\n\n/**\n * Nested projection type - allows recursive nesting of ColumnBuilder, ExpressionBuilder, or nested objects.\n */\nexport type NestedProjection = Record<\n string,\n | AnyExpressionSource\n | Record<\n string,\n | AnyExpressionSource\n | Record<\n string,\n | AnyExpressionSource\n | Record<string, AnyExpressionSource | Record<string, AnyExpressionSource>>\n >\n >\n>;\n\n/**\n * Helper type to extract include type from Includes map.\n * Returns the value type if K is a key of Includes, otherwise returns unknown.\n */\ntype ExtractIncludeType<\n K extends string,\n Includes extends Record<string, unknown>,\n> = K extends keyof Includes ? Includes[K] : unknown;\n\n/**\n * Infers Row type from a nested projection object.\n * Recursively maps Record<string, ColumnBuilder | boolean | NestedProjection> to nested object types.\n *\n * Extracts the pre-computed JsType from each ColumnBuilder at leaves.\n * When a value is `true`, it represents an include reference and infers `Array<ChildShape>`\n * by looking up the include alias in the Includes type map.\n */\nexport type InferNestedProjectionRow<\n P extends Record<string, AnyExpressionSource | boolean | NestedProjection>,\n CodecTypes extends Record<string, { readonly output: unknown }> = Record<string, never>,\n Includes extends Record<string, unknown> = Record<string, never>,\n> = {\n [K in keyof P]: P[K] extends ExpressionBuilder<infer JsType>\n ? JsType\n : P[K] extends AnyColumnBuilder\n ? ExtractJsTypeFromColumnBuilder<P[K]>\n : P[K] extends true\n ? Array<ExtractIncludeType<K & string, Includes>> // Include reference - infers Array<ChildShape> from Includes map\n : P[K] extends NestedProjection\n ? InferNestedProjectionRow<P[K], CodecTypes, Includes>\n : never;\n};\n\n/**\n * Infers Row type from a tuple of ColumnBuilders used in returning() clause.\n * Extracts column name and JsType from each ColumnBuilder and creates a Record.\n */\nexport type InferReturningRow<Columns extends readonly AnyColumnBuilder[]> =\n Columns extends readonly [infer First, ...infer Rest]\n ? First extends ColumnBuilder<\n infer Name,\n infer _Meta,\n infer JsType,\n infer _Ops extends OperationTypes\n >\n ? Name extends string\n ? Rest extends readonly AnyColumnBuilder[]\n ? { [K in Name]: JsType } & InferReturningRow<Rest>\n : { [K in Name]: JsType }\n : never\n : never\n : Record<string, never>;\n\n/**\n * Utility type to check if a contract has the required capabilities for includeMany.\n * Requires both `lateral` and `jsonAgg` to be `true` in the contract's capabilities for the target.\n * Capabilities are nested by target: `{ [target]: { lateral: true, jsonAgg: true } }`\n */\nexport type HasIncludeManyCapabilities<TContract extends SqlContract<SqlStorage>> =\n TContract extends { capabilities: infer C; target: infer T }\n ? T extends string\n ? C extends Record<string, Record<string, boolean>>\n ? C extends { [K in T]: infer TargetCaps }\n ? TargetCaps extends { lateral: true; jsonAgg: true }\n ? true\n : false\n : false\n : false\n : false\n : false;\n\n/**\n * SQL-specific Plan type that refines the ast field to use QueryAst.\n * This is the type used by SQL query builders.\n */\nexport type SqlPlan<Row = unknown> = ExecutionPlan<Row, QueryAst>;\n\n/**\n * Helper types for extracting contract structure.\n */\nexport type TablesOf<TContract> = TContract extends {\n storage: { tables: infer U };\n}\n ? U\n : never;\n\nexport type TableKey<TContract> = Extract<keyof TablesOf<TContract>, string>;\n\n// Common types for contract.d.ts generation (SQL-specific)\n// These types are used by emitted contract.d.ts files to provide type-safe DSL/ORM types\n\n/**\n * Unique symbol for metadata property to avoid collisions with user-defined properties\n */\nexport declare const META: unique symbol;\n\n/**\n * Extracts metadata from a type that has a META property\n */\nexport type Meta<T extends { [META]: unknown }> = T[typeof META];\n\n/**\n * Metadata interface for table definitions\n */\nexport interface TableMetadata<Name extends string> {\n name: Name;\n}\n\n/**\n * Metadata interface for model definitions\n */\nexport interface ModelMetadata<Name extends string> {\n name: Name;\n}\n\n/**\n * Base interface for table definitions with metadata\n * Used in contract.d.ts to define storage-level table types\n */\nexport interface TableDef<Name extends string> {\n readonly [META]: TableMetadata<Name>;\n}\n\n/**\n * Base interface for model definitions with metadata\n * Used in contract.d.ts to define application-level model types\n */\nexport interface ModelDef<Name extends string> {\n readonly [META]: ModelMetadata<Name>;\n}\n\nexport type ColumnsOf<\n TContract,\n K extends TableKey<TContract>,\n> = K extends keyof TablesOf<TContract>\n ? TablesOf<TContract>[K] extends { columns: infer C }\n ? C\n : never\n : never;\n\nexport interface RawTemplateOptions {\n readonly refs?: PlanRefs;\n readonly annotations?: Record<string, unknown>;\n readonly projection?: ReadonlyArray<string>;\n}\n\nexport interface RawFunctionOptions extends RawTemplateOptions {\n readonly params: ReadonlyArray<unknown>;\n}\n\nexport type RawTemplateFactory = (\n strings: TemplateStringsArray,\n ...values: readonly unknown[]\n) => ExecutionPlan;\n\nexport interface RawFactory extends RawTemplateFactory {\n (text: string, options: RawFunctionOptions): ExecutionPlan;\n with(options: RawTemplateOptions): RawTemplateFactory;\n}\n\nexport type { RuntimeError } from '@prisma-next/plan';\n\nexport interface BuildParamsMap {\n readonly [name: string]: unknown;\n}\n\nexport interface BuildOptions {\n readonly params?: BuildParamsMap;\n}\n\nexport interface SqlBuilderOptions<\n TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>,\n> {\n readonly context: QueryLaneContext<TContract>;\n}\n\n/**\n * SQL-specific ResultType that works with both Plan and SqlQueryPlan.\n * This extends the core ResultType to also handle SqlQueryPlan.\n * Example: `type Row = ResultType<typeof plan>`\n */\nexport type ResultType<P> = P extends SqlQueryPlan<infer R> ? R : CoreResultType<P>;\n"],"mappings":";AA+CO,SAAS,mBACd,MACA,KACiB;AACjB,SAAO,EAAE,MAAM,SAAS,MAAM,IAAI;AACpC;AAkIO,SAAS,gBAAgB,OAA2C;AACzE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACT,MAA4B,SAAS;AAE1C;","names":[]}
@@ -35,12 +35,31 @@ function getColumnInfo(expr) {
35
35
  const baseCol = extractBaseColumnRef(expr);
36
36
  return { table: baseCol.table, column: baseCol.column };
37
37
  }
38
+ if (isExpressionBuilder(expr)) {
39
+ const baseCol = extractBaseColumnRef(expr.expr);
40
+ return { table: baseCol.table, column: baseCol.column };
41
+ }
38
42
  const colBuilder = expr;
39
43
  return { table: colBuilder.table, column: colBuilder.column };
40
44
  }
41
45
  function isColumnBuilder(value) {
42
46
  return typeof value === "object" && value !== null && "kind" in value && value.kind === "column";
43
47
  }
48
+ function isExpressionBuilder(value) {
49
+ return typeof value === "object" && value !== null && "kind" in value && value.kind === "expression";
50
+ }
51
+ function isExpressionSource(value) {
52
+ return typeof value === "object" && value !== null && "toExpr" in value && typeof value.toExpr === "function";
53
+ }
54
+ function toExpression(source) {
55
+ return source.toExpr();
56
+ }
57
+ function expressionFromSource(source) {
58
+ return source.toExpr();
59
+ }
60
+ function isValueSource(value) {
61
+ return isParamPlaceholder(value) || isExpressionSource(value);
62
+ }
44
63
  function getOperationExpr(builder) {
45
64
  if (isOperationExpr(builder)) {
46
65
  return builder;
@@ -57,6 +76,11 @@ export {
57
76
  isOperationExpr,
58
77
  getColumnInfo,
59
78
  isColumnBuilder,
79
+ isExpressionBuilder,
80
+ isExpressionSource,
81
+ toExpression,
82
+ expressionFromSource,
83
+ isValueSource,
60
84
  getOperationExpr
61
85
  };
62
- //# sourceMappingURL=chunk-5N34PNVZ.js.map
86
+ //# sourceMappingURL=chunk-2MAKNVCP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/guards.ts"],"sourcesContent":["import type { StorageColumn } from '@prisma-next/sql-contract/types';\nimport type {\n ColumnRef,\n Expression,\n ExpressionSource,\n LiteralExpr,\n OperationExpr,\n ParamRef,\n} from '../ast/types';\nimport type {\n AnyColumnBuilder,\n AnyExpressionSource,\n ExpressionBuilder,\n ParamPlaceholder,\n ValueSource,\n} from '../types';\n\n/**\n * Helper to extract columnMeta from a ColumnBuilder or ExpressionBuilder.\n * Returns StorageColumn if present, undefined otherwise.\n * Both ColumnBuilder and ExpressionBuilder have columnMeta property.\n */\nexport function getColumnMeta(expr: AnyExpressionSource): StorageColumn | undefined {\n // Both ColumnBuilder and ExpressionBuilder have columnMeta: StorageColumn\n // TypeScript should narrow the type after the 'in' check\n if ('columnMeta' in expr) {\n return expr.columnMeta;\n }\n return undefined;\n}\n\n/**\n * Type predicate to check if a value is a ParamPlaceholder.\n */\nexport function isParamPlaceholder(value: unknown): value is ParamPlaceholder {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'kind' in value &&\n (value as { kind: unknown }).kind === 'param-placeholder' &&\n 'name' in value &&\n typeof (value as { name: unknown }).name === 'string'\n );\n}\n\n/**\n * Recursively extracts the base ColumnRef from an OperationExpr.\n * If the expression is already a ColumnRef, it is returned directly.\n */\nexport function extractBaseColumnRef(expr: ColumnRef | OperationExpr): ColumnRef {\n if (expr.kind === 'col') {\n return expr;\n }\n return extractBaseColumnRef(expr.self);\n}\n\n/**\n * Recursively collects all ColumnRef nodes from an expression tree.\n * Handles nested OperationExpr structures by traversing both self and args.\n */\nexport function collectColumnRefs(\n expr: ColumnRef | ParamRef | LiteralExpr | OperationExpr,\n): ColumnRef[] {\n if (expr.kind === 'col') {\n return [expr];\n }\n if (expr.kind === 'operation') {\n const refs: ColumnRef[] = collectColumnRefs(expr.self);\n for (const arg of expr.args) {\n refs.push(...collectColumnRefs(arg));\n }\n return refs;\n }\n return [];\n}\n\n/**\n * Type predicate to check if an expression is an OperationExpr.\n */\nexport function isOperationExpr(\n expr: AnyExpressionSource | OperationExpr | Expression,\n): expr is OperationExpr {\n return typeof expr === 'object' && expr !== null && 'kind' in expr && expr.kind === 'operation';\n}\n\n/**\n * Helper to extract table and column from a ColumnBuilder, ExpressionBuilder, or OperationExpr.\n * For ExpressionBuilder or OperationExpr, recursively unwraps to find the base ColumnRef.\n */\nexport function getColumnInfo(expr: AnyExpressionSource | OperationExpr): {\n table: string;\n column: string;\n} {\n if (isOperationExpr(expr)) {\n const baseCol = extractBaseColumnRef(expr);\n return { table: baseCol.table, column: baseCol.column };\n }\n if (isExpressionBuilder(expr)) {\n const baseCol = extractBaseColumnRef(expr.expr);\n return { table: baseCol.table, column: baseCol.column };\n }\n // expr is ColumnBuilder - TypeScript can't narrow properly\n const colBuilder = expr as unknown as { table: string; column: string };\n return { table: colBuilder.table, column: colBuilder.column };\n}\n\n/**\n * Type predicate to check if a value is a ColumnBuilder.\n */\nexport function isColumnBuilder(value: unknown): value is AnyColumnBuilder {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'kind' in value &&\n (value as { kind: unknown }).kind === 'column'\n );\n}\n\n/**\n * Type predicate to check if a value is an ExpressionBuilder.\n */\nexport function isExpressionBuilder(value: unknown): value is ExpressionBuilder {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'kind' in value &&\n (value as { kind: unknown }).kind === 'expression'\n );\n}\n\n/**\n * Type predicate to check if a value is an ExpressionSource (has toExpr method).\n */\nexport function isExpressionSource(value: unknown): value is ExpressionSource {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'toExpr' in value &&\n typeof (value as ExpressionSource).toExpr === 'function'\n );\n}\n\n/**\n * Converts any ExpressionSource to an Expression.\n * This is the canonical way to get an AST Expression from a builder.\n *\n * @param source - A ColumnBuilder or ExpressionBuilder\n * @returns The corresponding Expression (ColumnRef or OperationExpr)\n */\nexport function toExpression(source: ExpressionSource): Expression {\n return source.toExpr();\n}\n\n/**\n * Converts an AnyExpressionSource to an Expression.\n * Handles both ColumnBuilder and ExpressionBuilder.\n *\n * @param source - A ColumnBuilder or ExpressionBuilder\n * @returns The corresponding Expression (ColumnRef or OperationExpr)\n */\nexport function expressionFromSource(source: AnyExpressionSource): Expression {\n return source.toExpr();\n}\n\n/**\n * Type predicate to check if a value is a ValueSource.\n * ValueSource is either a ParamPlaceholder or an ExpressionSource.\n */\nexport function isValueSource(value: unknown): value is ValueSource {\n return isParamPlaceholder(value) || isExpressionSource(value);\n}\n\n/**\n * Extracts and returns an OperationExpr from a builder.\n * Returns the OperationExpr if the builder is an OperationExpr or has an _operationExpr property,\n * otherwise returns undefined.\n *\n * @deprecated Use isExpressionBuilder() instead. This function exists for backward compatibility\n * with code that uses the hidden _operationExpr property pattern.\n *\n * @design-note: This function accesses the hidden `_operationExpr` property, which is a code smell.\n * The ExpressionBuilder type (introduced in the operation-expr-refactoring) provides a cleaner\n * approach by explicitly representing operation results as a distinct type.\n */\nexport function getOperationExpr(\n builder: AnyColumnBuilder | OperationExpr,\n): OperationExpr | undefined {\n if (isOperationExpr(builder)) {\n return builder;\n }\n const builderWithExpr = builder as unknown as { _operationExpr?: OperationExpr };\n return builderWithExpr._operationExpr;\n}\n"],"mappings":";AAsBO,SAAS,cAAc,MAAsD;AAGlF,MAAI,gBAAgB,MAAM;AACxB,WAAO,KAAK;AAAA,EACd;AACA,SAAO;AACT;AAKO,SAAS,mBAAmB,OAA2C;AAC5E,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACT,MAA4B,SAAS,uBACtC,UAAU,SACV,OAAQ,MAA4B,SAAS;AAEjD;AAMO,SAAS,qBAAqB,MAA4C;AAC/E,MAAI,KAAK,SAAS,OAAO;AACvB,WAAO;AAAA,EACT;AACA,SAAO,qBAAqB,KAAK,IAAI;AACvC;AAMO,SAAS,kBACd,MACa;AACb,MAAI,KAAK,SAAS,OAAO;AACvB,WAAO,CAAC,IAAI;AAAA,EACd;AACA,MAAI,KAAK,SAAS,aAAa;AAC7B,UAAM,OAAoB,kBAAkB,KAAK,IAAI;AACrD,eAAW,OAAO,KAAK,MAAM;AAC3B,WAAK,KAAK,GAAG,kBAAkB,GAAG,CAAC;AAAA,IACrC;AACA,WAAO;AAAA,EACT;AACA,SAAO,CAAC;AACV;AAKO,SAAS,gBACd,MACuB;AACvB,SAAO,OAAO,SAAS,YAA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