@prisma-next/sql-schema-ir 0.8.0 → 0.9.0-dev.2

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.
@@ -1,2 +1,2 @@
1
- import { a as SqlIndexIR, c as SqlTableIR, d as SqlUniqueIR, i as SqlForeignKeyIR, l as SqlTypeMetadata, n as SqlAnnotations, o as SqlReferentialAction, r as SqlColumnIR, s as SqlSchemaIR, t as PrimaryKey, u as SqlTypeMetadataRegistry } from "../types-BNW257Ug.mjs";
2
- export { PrimaryKey, SqlAnnotations, SqlColumnIR, SqlForeignKeyIR, SqlIndexIR, SqlReferentialAction, SqlSchemaIR, SqlTableIR, SqlTypeMetadata, SqlTypeMetadataRegistry, SqlUniqueIR };
1
+ import { _ as PrimaryKey, a as SqlTableIR, c as SqlUniqueIRInput, d as SqlForeignKeyIR, f as SqlForeignKeyIRInput, g as SqlColumnIRInput, h as SqlColumnIR, i as SqlSchemaIRInput, l as SqlIndexIR, m as SqlAnnotations, n as SqlTypeMetadataRegistry, o as SqlTableIRInput, p as SqlReferentialAction, r as SqlSchemaIR, s as SqlUniqueIR, t as SqlTypeMetadata, u as SqlIndexIRInput, v as PrimaryKeyInput, y as SqlSchemaIRNode } from "../types-CpDFLYCH.mjs";
2
+ export { PrimaryKey, PrimaryKeyInput, SqlAnnotations, SqlColumnIR, SqlColumnIRInput, SqlForeignKeyIR, SqlForeignKeyIRInput, SqlIndexIR, SqlIndexIRInput, SqlReferentialAction, SqlSchemaIR, SqlSchemaIRInput, SqlSchemaIRNode, SqlTableIR, SqlTableIRInput, SqlTypeMetadata, SqlTypeMetadataRegistry, SqlUniqueIR, SqlUniqueIRInput };
@@ -1 +1,2 @@
1
- export {};
1
+ import { a as SqlForeignKeyIR, c as SqlSchemaIRNode, i as SqlIndexIR, n as SqlTableIR, o as SqlColumnIR, r as SqlUniqueIR, s as PrimaryKey, t as SqlSchemaIR } from "../types-DKwM7vwx.mjs";
2
+ export { PrimaryKey, SqlColumnIR, SqlForeignKeyIR, SqlIndexIR, SqlSchemaIR, SqlSchemaIRNode, SqlTableIR, SqlUniqueIR };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as SqlIndexIR, c as SqlTableIR, d as SqlUniqueIR, i as SqlForeignKeyIR, l as SqlTypeMetadata, n as SqlAnnotations, o as SqlReferentialAction, r as SqlColumnIR, s as SqlSchemaIR, t as PrimaryKey, u as SqlTypeMetadataRegistry } from "./types-BNW257Ug.mjs";
2
- export { PrimaryKey, SqlAnnotations, SqlColumnIR, SqlForeignKeyIR, SqlIndexIR, SqlReferentialAction, SqlSchemaIR, SqlTableIR, SqlTypeMetadata, SqlTypeMetadataRegistry, SqlUniqueIR };
1
+ import { _ as PrimaryKey, a as SqlTableIR, c as SqlUniqueIRInput, d as SqlForeignKeyIR, f as SqlForeignKeyIRInput, g as SqlColumnIRInput, h as SqlColumnIR, i as SqlSchemaIRInput, l as SqlIndexIR, m as SqlAnnotations, n as SqlTypeMetadataRegistry, o as SqlTableIRInput, p as SqlReferentialAction, r as SqlSchemaIR, s as SqlUniqueIR, t as SqlTypeMetadata, u as SqlIndexIRInput, v as PrimaryKeyInput, y as SqlSchemaIRNode } from "./types-CpDFLYCH.mjs";
2
+ export { PrimaryKey, PrimaryKeyInput, SqlAnnotations, SqlColumnIR, SqlColumnIRInput, SqlForeignKeyIR, SqlForeignKeyIRInput, SqlIndexIR, SqlIndexIRInput, SqlReferentialAction, SqlSchemaIR, SqlSchemaIRInput, SqlSchemaIRNode, SqlTableIR, SqlTableIRInput, SqlTypeMetadata, SqlTypeMetadataRegistry, SqlUniqueIR, SqlUniqueIRInput };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import "./exports/types.mjs";
2
- export {};
1
+ import { a as SqlForeignKeyIR, c as SqlSchemaIRNode, i as SqlIndexIR, n as SqlTableIR, o as SqlColumnIR, r as SqlUniqueIR, s as PrimaryKey, t as SqlSchemaIR } from "./types-DKwM7vwx.mjs";
2
+ export { PrimaryKey, SqlColumnIR, SqlForeignKeyIR, SqlIndexIR, SqlSchemaIR, SqlSchemaIRNode, SqlTableIR, SqlUniqueIR };
@@ -0,0 +1,232 @@
1
+ import { IRNodeBase } from "@prisma-next/framework-components/ir";
2
+
3
+ //#region src/ir/sql-schema-ir-node.d.ts
4
+ /**
5
+ * SQL Schema IR node base. Carries the family-level
6
+ * `kind = 'sql-schema-ir'` discriminator and inherits the framework's
7
+ * `freezeNode` affordance.
8
+ *
9
+ * SQL Schema IR represents the actual database state as discovered by
10
+ * introspection (the parallel to SQL Contract IR, which represents the
11
+ * desired state). Like the Contract side, today's Schema IR has no
12
+ * polymorphic dispatch — verifiers and planners walk by structural
13
+ * position, not by inspecting `kind` — so a single family-level
14
+ * discriminator is sufficient. Future per-leaf overrides land cleanly
15
+ * the same way as on the Contract side.
16
+ *
17
+ * The discriminator is installed as a non-enumerable own property,
18
+ * matching the SqlNode pattern. This keeps `JSON.stringify(node)`
19
+ * canonical (no `kind` field), keeps `toEqual({...})` test assertions
20
+ * against pre-lift flat shapes passing, and keeps `node.kind` readable
21
+ * for future polymorphic dispatch.
22
+ */
23
+ declare abstract class SqlSchemaIRNode extends IRNodeBase {
24
+ readonly kind?: string;
25
+ constructor();
26
+ }
27
+ //#endregion
28
+ //#region src/ir/primary-key.d.ts
29
+ interface PrimaryKeyInput {
30
+ readonly columns: readonly string[];
31
+ readonly name?: string;
32
+ }
33
+ /**
34
+ * Primary-key Schema IR node. Mirrors the Contract IR `PrimaryKey`
35
+ * shape (same `columns` + optional `name`) so verification can compare
36
+ * intent and actual structurally. Defined here independently to avoid
37
+ * a sql-schema-ir -> sql-contract dependency.
38
+ */
39
+ declare class PrimaryKey extends SqlSchemaIRNode {
40
+ readonly columns: readonly string[];
41
+ readonly name?: string;
42
+ constructor(input: PrimaryKeyInput);
43
+ }
44
+ //#endregion
45
+ //#region src/ir/sql-column-ir.d.ts
46
+ /**
47
+ * Namespaced annotations for extensibility. Each namespace
48
+ * (e.g. `pg`, `pgvector`) owns its annotations subtree.
49
+ */
50
+ type SqlAnnotations = {
51
+ readonly [namespace: string]: unknown;
52
+ };
53
+ interface SqlColumnIRInput {
54
+ readonly name: string;
55
+ readonly nativeType: string;
56
+ readonly nullable: boolean;
57
+ /** Raw database default expression (e.g. `'hello'::text`, `nextval('seq')`). */
58
+ readonly default?: string;
59
+ readonly annotations?: SqlAnnotations;
60
+ }
61
+ /**
62
+ * Schema IR node for a single column on a table, as observed by
63
+ * introspection. Unlike the Contract IR `StorageColumn`, this carries
64
+ * the column's `name` (Schema IR columns are returned as arrays from
65
+ * introspection queries; the parent table re-keys them into a record
66
+ * for downstream consumers).
67
+ */
68
+ declare class SqlColumnIR extends SqlSchemaIRNode {
69
+ readonly name: string;
70
+ readonly nativeType: string;
71
+ readonly nullable: boolean;
72
+ readonly default?: string;
73
+ readonly annotations?: SqlAnnotations;
74
+ constructor(input: SqlColumnIRInput);
75
+ }
76
+ //#endregion
77
+ //#region src/ir/sql-foreign-key-ir.d.ts
78
+ type SqlReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
79
+ interface SqlForeignKeyIRInput {
80
+ readonly columns: readonly string[];
81
+ readonly referencedTable: string;
82
+ readonly referencedColumns: readonly string[];
83
+ readonly name?: string;
84
+ readonly onDelete?: SqlReferentialAction;
85
+ readonly onUpdate?: SqlReferentialAction;
86
+ readonly annotations?: SqlAnnotations;
87
+ }
88
+ /**
89
+ * Schema IR node for a foreign-key constraint as observed by
90
+ * introspection. The `referencedTable` / `referencedColumns` field
91
+ * names match the introspection vocabulary (`pg_constraint.confkey`,
92
+ * etc.) and intentionally differ from the Contract IR's nested
93
+ * `references: { table, columns }` shape so that the verifier's
94
+ * structural comparison stays explicit about which side it's reading.
95
+ */
96
+ declare class SqlForeignKeyIR extends SqlSchemaIRNode {
97
+ readonly columns: readonly string[];
98
+ readonly referencedTable: string;
99
+ readonly referencedColumns: readonly string[];
100
+ readonly name?: string;
101
+ readonly onDelete?: SqlReferentialAction;
102
+ readonly onUpdate?: SqlReferentialAction;
103
+ readonly annotations?: SqlAnnotations;
104
+ constructor(input: SqlForeignKeyIRInput);
105
+ }
106
+ //#endregion
107
+ //#region src/ir/sql-index-ir.d.ts
108
+ interface SqlIndexIRInput {
109
+ readonly columns: readonly string[];
110
+ readonly unique: boolean;
111
+ readonly name?: string;
112
+ readonly type?: string;
113
+ readonly options?: Record<string, unknown>;
114
+ readonly annotations?: SqlAnnotations;
115
+ }
116
+ /**
117
+ * Schema IR node for a secondary index as observed by introspection.
118
+ * Unlike the Contract IR `Index`, the Schema IR carries an explicit
119
+ * `unique` field — introspection sees the underlying index regardless
120
+ * of whether the user expressed it as `@@index` or `@@unique`, and the
121
+ * verifier needs to distinguish them when comparing to the Contract.
122
+ */
123
+ declare class SqlIndexIR extends SqlSchemaIRNode {
124
+ readonly columns: readonly string[];
125
+ readonly unique: boolean;
126
+ readonly name?: string;
127
+ readonly type?: string;
128
+ readonly options?: Record<string, unknown>;
129
+ readonly annotations?: SqlAnnotations;
130
+ constructor(input: SqlIndexIRInput);
131
+ }
132
+ //#endregion
133
+ //#region src/ir/sql-unique-ir.d.ts
134
+ interface SqlUniqueIRInput {
135
+ readonly columns: readonly string[];
136
+ readonly name?: string;
137
+ readonly annotations?: SqlAnnotations;
138
+ }
139
+ /**
140
+ * Schema IR node for a table-level unique constraint as observed by
141
+ * introspection.
142
+ */
143
+ declare class SqlUniqueIR extends SqlSchemaIRNode {
144
+ readonly columns: readonly string[];
145
+ readonly name?: string;
146
+ readonly annotations?: SqlAnnotations;
147
+ constructor(input: SqlUniqueIRInput);
148
+ }
149
+ //#endregion
150
+ //#region src/ir/sql-table-ir.d.ts
151
+ interface SqlTableIRInput {
152
+ readonly name: string;
153
+ readonly columns: Record<string, SqlColumnIR | SqlColumnIRInput>;
154
+ readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR | SqlForeignKeyIRInput>;
155
+ readonly uniques: ReadonlyArray<SqlUniqueIR | SqlUniqueIRInput>;
156
+ readonly indexes: ReadonlyArray<SqlIndexIR | SqlIndexIRInput>;
157
+ readonly primaryKey?: PrimaryKey | PrimaryKeyInput;
158
+ readonly annotations?: SqlAnnotations;
159
+ }
160
+ /**
161
+ * Schema IR node for a single table as observed by introspection.
162
+ *
163
+ * Unlike the Contract IR `StorageTable`, this carries the table's
164
+ * `name` — introspection queries return tables as arrays and the
165
+ * verifier keys them into `SqlSchemaIR.tables` afterwards, so the name
166
+ * stays on the table object for downstream call sites that walk
167
+ * `Object.values(schema.tables)`.
168
+ *
169
+ * The constructor normalises nested IR-class fields so downstream
170
+ * walks see a uniform AST regardless of whether the input was a
171
+ * plain-data literal (from introspection) or already-constructed
172
+ * class instances.
173
+ */
174
+ declare class SqlTableIR extends SqlSchemaIRNode {
175
+ readonly name: string;
176
+ readonly columns: Readonly<Record<string, SqlColumnIR>>;
177
+ readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR>;
178
+ readonly uniques: ReadonlyArray<SqlUniqueIR>;
179
+ readonly indexes: ReadonlyArray<SqlIndexIR>;
180
+ readonly primaryKey?: PrimaryKey;
181
+ readonly annotations?: SqlAnnotations;
182
+ constructor(input: SqlTableIRInput);
183
+ }
184
+ //#endregion
185
+ //#region src/ir/sql-schema-ir.d.ts
186
+ interface SqlSchemaIRInput {
187
+ readonly tables: Record<string, SqlTableIR | SqlTableIRInput>;
188
+ readonly annotations?: SqlAnnotations;
189
+ }
190
+ /**
191
+ * Root Schema IR node representing the complete database schema as
192
+ * observed by introspection. Target-agnostic; used by both verifiers
193
+ * (compare against intended Contract storage) and migration planners
194
+ * (derive operations needed to reconcile).
195
+ *
196
+ * The constructor normalises nested `SqlTableIR` instances so
197
+ * downstream walks see a uniform AST regardless of whether the input
198
+ * was a plain-data literal or already-constructed class instances.
199
+ */
200
+ declare class SqlSchemaIR extends SqlSchemaIRNode {
201
+ readonly tables: Readonly<Record<string, SqlTableIR>>;
202
+ readonly annotations?: SqlAnnotations;
203
+ constructor(input: SqlSchemaIRInput);
204
+ }
205
+ //#endregion
206
+ //#region src/types.d.ts
207
+ /**
208
+ * SQL type metadata for control-plane and execution-plane type
209
+ * availability and mapping. Read-only view of type information
210
+ * without encode/decode behavior.
211
+ */
212
+ interface SqlTypeMetadata {
213
+ /** Namespaced type identifier, e.g. `pg/int4@1`, `pg/text@1`. */
214
+ readonly typeId: string;
215
+ /** Contract scalar type IDs this type can handle. */
216
+ readonly targetTypes: readonly string[];
217
+ /**
218
+ * Native database type name (target-specific). Optional because
219
+ * not all types have a native database representation.
220
+ */
221
+ readonly nativeType?: string;
222
+ }
223
+ /**
224
+ * Registry interface for SQL type metadata. Provides read-only
225
+ * iteration over type metadata entries.
226
+ */
227
+ interface SqlTypeMetadataRegistry {
228
+ values(): IterableIterator<SqlTypeMetadata>;
229
+ }
230
+ //#endregion
231
+ export { PrimaryKey as _, SqlTableIR as a, SqlUniqueIRInput as c, SqlForeignKeyIR as d, SqlForeignKeyIRInput as f, SqlColumnIRInput as g, SqlColumnIR as h, SqlSchemaIRInput as i, SqlIndexIR as l, SqlAnnotations as m, SqlTypeMetadataRegistry as n, SqlTableIRInput as o, SqlReferentialAction as p, SqlSchemaIR as r, SqlUniqueIR as s, SqlTypeMetadata as t, SqlIndexIRInput as u, PrimaryKeyInput as v, SqlSchemaIRNode as y };
232
+ //# sourceMappingURL=types-CpDFLYCH.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-CpDFLYCH.d.mts","names":[],"sources":["../src/ir/sql-schema-ir-node.ts","../src/ir/primary-key.ts","../src/ir/sql-column-ir.ts","../src/ir/sql-foreign-key-ir.ts","../src/ir/sql-index-ir.ts","../src/ir/sql-unique-ir.ts","../src/ir/sql-table-ir.ts","../src/ir/sql-schema-ir.ts","../src/types.ts"],"mappings":";;;;;AAqBA;;;;;;;;;;;;AClBA;;;;;uBDkBsB,eAAA,SAAwB,UAAA;EAAA,SACnC,IAAA;;;;;UCnBM,eAAA;EAAA,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qBrB,MAAA;EPnBQ;EAAA,SOsBR,WAAA;EPpBU;;;;EAAA,SO0BV,UAAA;AAAA;;ANrCX;;;UM4CiB,uBAAA;EACf,MAAA,IAAU,gBAAA,CAAiB,eAAA;AAAA"}
@@ -0,0 +1,197 @@
1
+ import { IRNodeBase, freezeNode } from "@prisma-next/framework-components/ir";
2
+ //#region src/ir/sql-schema-ir-node.ts
3
+ /**
4
+ * SQL Schema IR node base. Carries the family-level
5
+ * `kind = 'sql-schema-ir'` discriminator and inherits the framework's
6
+ * `freezeNode` affordance.
7
+ *
8
+ * SQL Schema IR represents the actual database state as discovered by
9
+ * introspection (the parallel to SQL Contract IR, which represents the
10
+ * desired state). Like the Contract side, today's Schema IR has no
11
+ * polymorphic dispatch — verifiers and planners walk by structural
12
+ * position, not by inspecting `kind` — so a single family-level
13
+ * discriminator is sufficient. Future per-leaf overrides land cleanly
14
+ * the same way as on the Contract side.
15
+ *
16
+ * The discriminator is installed as a non-enumerable own property,
17
+ * matching the SqlNode pattern. This keeps `JSON.stringify(node)`
18
+ * canonical (no `kind` field), keeps `toEqual({...})` test assertions
19
+ * against pre-lift flat shapes passing, and keeps `node.kind` readable
20
+ * for future polymorphic dispatch.
21
+ */
22
+ var SqlSchemaIRNode = class extends IRNodeBase {
23
+ kind;
24
+ constructor() {
25
+ super();
26
+ Object.defineProperty(this, "kind", {
27
+ value: "sql-schema-ir",
28
+ writable: false,
29
+ enumerable: false,
30
+ configurable: false
31
+ });
32
+ }
33
+ };
34
+ //#endregion
35
+ //#region src/ir/primary-key.ts
36
+ /**
37
+ * Primary-key Schema IR node. Mirrors the Contract IR `PrimaryKey`
38
+ * shape (same `columns` + optional `name`) so verification can compare
39
+ * intent and actual structurally. Defined here independently to avoid
40
+ * a sql-schema-ir -> sql-contract dependency.
41
+ */
42
+ var PrimaryKey = class extends SqlSchemaIRNode {
43
+ columns;
44
+ constructor(input) {
45
+ super();
46
+ this.columns = input.columns;
47
+ if (input.name !== void 0) this.name = input.name;
48
+ freezeNode(this);
49
+ }
50
+ };
51
+ //#endregion
52
+ //#region src/ir/sql-column-ir.ts
53
+ /**
54
+ * Schema IR node for a single column on a table, as observed by
55
+ * introspection. Unlike the Contract IR `StorageColumn`, this carries
56
+ * the column's `name` (Schema IR columns are returned as arrays from
57
+ * introspection queries; the parent table re-keys them into a record
58
+ * for downstream consumers).
59
+ */
60
+ var SqlColumnIR = class extends SqlSchemaIRNode {
61
+ name;
62
+ nativeType;
63
+ nullable;
64
+ constructor(input) {
65
+ super();
66
+ this.name = input.name;
67
+ this.nativeType = input.nativeType;
68
+ this.nullable = input.nullable;
69
+ if (input.default !== void 0) this.default = input.default;
70
+ if (input.annotations !== void 0) this.annotations = input.annotations;
71
+ freezeNode(this);
72
+ }
73
+ };
74
+ //#endregion
75
+ //#region src/ir/sql-foreign-key-ir.ts
76
+ /**
77
+ * Schema IR node for a foreign-key constraint as observed by
78
+ * introspection. The `referencedTable` / `referencedColumns` field
79
+ * names match the introspection vocabulary (`pg_constraint.confkey`,
80
+ * etc.) and intentionally differ from the Contract IR's nested
81
+ * `references: { table, columns }` shape so that the verifier's
82
+ * structural comparison stays explicit about which side it's reading.
83
+ */
84
+ var SqlForeignKeyIR = class extends SqlSchemaIRNode {
85
+ columns;
86
+ referencedTable;
87
+ referencedColumns;
88
+ constructor(input) {
89
+ super();
90
+ this.columns = input.columns;
91
+ this.referencedTable = input.referencedTable;
92
+ this.referencedColumns = input.referencedColumns;
93
+ if (input.name !== void 0) this.name = input.name;
94
+ if (input.onDelete !== void 0) this.onDelete = input.onDelete;
95
+ if (input.onUpdate !== void 0) this.onUpdate = input.onUpdate;
96
+ if (input.annotations !== void 0) this.annotations = input.annotations;
97
+ freezeNode(this);
98
+ }
99
+ };
100
+ //#endregion
101
+ //#region src/ir/sql-index-ir.ts
102
+ /**
103
+ * Schema IR node for a secondary index as observed by introspection.
104
+ * Unlike the Contract IR `Index`, the Schema IR carries an explicit
105
+ * `unique` field — introspection sees the underlying index regardless
106
+ * of whether the user expressed it as `@@index` or `@@unique`, and the
107
+ * verifier needs to distinguish them when comparing to the Contract.
108
+ */
109
+ var SqlIndexIR = class extends SqlSchemaIRNode {
110
+ columns;
111
+ unique;
112
+ constructor(input) {
113
+ super();
114
+ this.columns = input.columns;
115
+ this.unique = input.unique;
116
+ if (input.name !== void 0) this.name = input.name;
117
+ if (input.type !== void 0) this.type = input.type;
118
+ if (input.options !== void 0) this.options = input.options;
119
+ if (input.annotations !== void 0) this.annotations = input.annotations;
120
+ freezeNode(this);
121
+ }
122
+ };
123
+ //#endregion
124
+ //#region src/ir/sql-unique-ir.ts
125
+ /**
126
+ * Schema IR node for a table-level unique constraint as observed by
127
+ * introspection.
128
+ */
129
+ var SqlUniqueIR = class extends SqlSchemaIRNode {
130
+ columns;
131
+ constructor(input) {
132
+ super();
133
+ this.columns = [...input.columns];
134
+ if (input.name !== void 0) this.name = input.name;
135
+ if (input.annotations !== void 0) this.annotations = input.annotations;
136
+ freezeNode(this);
137
+ }
138
+ };
139
+ //#endregion
140
+ //#region src/ir/sql-table-ir.ts
141
+ /**
142
+ * Schema IR node for a single table as observed by introspection.
143
+ *
144
+ * Unlike the Contract IR `StorageTable`, this carries the table's
145
+ * `name` — introspection queries return tables as arrays and the
146
+ * verifier keys them into `SqlSchemaIR.tables` afterwards, so the name
147
+ * stays on the table object for downstream call sites that walk
148
+ * `Object.values(schema.tables)`.
149
+ *
150
+ * The constructor normalises nested IR-class fields so downstream
151
+ * walks see a uniform AST regardless of whether the input was a
152
+ * plain-data literal (from introspection) or already-constructed
153
+ * class instances.
154
+ */
155
+ var SqlTableIR = class extends SqlSchemaIRNode {
156
+ name;
157
+ columns;
158
+ foreignKeys;
159
+ uniques;
160
+ indexes;
161
+ constructor(input) {
162
+ super();
163
+ this.name = input.name;
164
+ this.columns = Object.freeze(Object.fromEntries(Object.entries(input.columns).map(([key, col]) => [key, col instanceof SqlColumnIR ? col : new SqlColumnIR(col)])));
165
+ this.foreignKeys = Object.freeze(input.foreignKeys.map((fk) => fk instanceof SqlForeignKeyIR ? fk : new SqlForeignKeyIR(fk)));
166
+ this.uniques = Object.freeze(input.uniques.map((u) => u instanceof SqlUniqueIR ? u : new SqlUniqueIR(u)));
167
+ this.indexes = Object.freeze(input.indexes.map((i) => i instanceof SqlIndexIR ? i : new SqlIndexIR(i)));
168
+ if (input.primaryKey !== void 0) this.primaryKey = input.primaryKey instanceof PrimaryKey ? input.primaryKey : new PrimaryKey(input.primaryKey);
169
+ if (input.annotations !== void 0) this.annotations = input.annotations;
170
+ freezeNode(this);
171
+ }
172
+ };
173
+ //#endregion
174
+ //#region src/ir/sql-schema-ir.ts
175
+ /**
176
+ * Root Schema IR node representing the complete database schema as
177
+ * observed by introspection. Target-agnostic; used by both verifiers
178
+ * (compare against intended Contract storage) and migration planners
179
+ * (derive operations needed to reconcile).
180
+ *
181
+ * The constructor normalises nested `SqlTableIR` instances so
182
+ * downstream walks see a uniform AST regardless of whether the input
183
+ * was a plain-data literal or already-constructed class instances.
184
+ */
185
+ var SqlSchemaIR = class extends SqlSchemaIRNode {
186
+ tables;
187
+ constructor(input) {
188
+ super();
189
+ this.tables = Object.freeze(Object.fromEntries(Object.entries(input.tables).map(([key, t]) => [key, t instanceof SqlTableIR ? t : new SqlTableIR(t)])));
190
+ if (input.annotations !== void 0) this.annotations = input.annotations;
191
+ freezeNode(this);
192
+ }
193
+ };
194
+ //#endregion
195
+ export { SqlForeignKeyIR as a, SqlSchemaIRNode as c, SqlIndexIR as i, SqlTableIR as n, SqlColumnIR as o, SqlUniqueIR as r, PrimaryKey as s, SqlSchemaIR as t };
196
+
197
+ //# sourceMappingURL=types-DKwM7vwx.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DKwM7vwx.mjs","names":[],"sources":["../src/ir/sql-schema-ir-node.ts","../src/ir/primary-key.ts","../src/ir/sql-column-ir.ts","../src/ir/sql-foreign-key-ir.ts","../src/ir/sql-index-ir.ts","../src/ir/sql-unique-ir.ts","../src/ir/sql-table-ir.ts","../src/ir/sql-schema-ir.ts"],"sourcesContent":["import { IRNodeBase } from '@prisma-next/framework-components/ir';\n\n/**\n * SQL Schema IR node base. Carries the family-level\n * `kind = 'sql-schema-ir'` discriminator and inherits the framework's\n * `freezeNode` affordance.\n *\n * SQL Schema IR represents the actual database state as discovered by\n * introspection (the parallel to SQL Contract IR, which represents the\n * desired state). Like the Contract side, today's Schema IR has no\n * polymorphic dispatch — verifiers and planners walk by structural\n * position, not by inspecting `kind` — so a single family-level\n * discriminator is sufficient. Future per-leaf overrides land cleanly\n * the same way as on the Contract side.\n *\n * The discriminator is installed as a non-enumerable own property,\n * matching the SqlNode pattern. This keeps `JSON.stringify(node)`\n * canonical (no `kind` field), keeps `toEqual({...})` test assertions\n * against pre-lift flat shapes passing, and keeps `node.kind` readable\n * for future polymorphic dispatch.\n */\nexport abstract class SqlSchemaIRNode extends IRNodeBase {\n readonly kind?: string;\n\n constructor() {\n super();\n Object.defineProperty(this, 'kind', {\n value: 'sql-schema-ir',\n writable: false,\n enumerable: false,\n configurable: false,\n });\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlSchemaIRNode } from './sql-schema-ir-node';\n\nexport interface PrimaryKeyInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * Primary-key Schema IR node. Mirrors the Contract IR `PrimaryKey`\n * shape (same `columns` + optional `name`) so verification can compare\n * intent and actual structurally. Defined here independently to avoid\n * a sql-schema-ir -> sql-contract dependency.\n */\nexport class PrimaryKey extends SqlSchemaIRNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: PrimaryKeyInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlSchemaIRNode } from './sql-schema-ir-node';\n\n/**\n * Namespaced annotations for extensibility. Each namespace\n * (e.g. `pg`, `pgvector`) owns its annotations subtree.\n */\nexport type SqlAnnotations = {\n readonly [namespace: string]: unknown;\n};\n\nexport interface SqlColumnIRInput {\n readonly name: string;\n readonly nativeType: string;\n readonly nullable: boolean;\n /** Raw database default expression (e.g. `'hello'::text`, `nextval('seq')`). */\n readonly default?: string;\n readonly annotations?: SqlAnnotations;\n}\n\n/**\n * Schema IR node for a single column on a table, as observed by\n * introspection. Unlike the Contract IR `StorageColumn`, this carries\n * the column's `name` (Schema IR columns are returned as arrays from\n * introspection queries; the parent table re-keys them into a record\n * for downstream consumers).\n */\nexport class SqlColumnIR extends SqlSchemaIRNode {\n readonly name: string;\n readonly nativeType: string;\n readonly nullable: boolean;\n declare readonly default?: string;\n declare readonly annotations?: SqlAnnotations;\n\n constructor(input: SqlColumnIRInput) {\n super();\n this.name = input.name;\n this.nativeType = input.nativeType;\n this.nullable = input.nullable;\n if (input.default !== undefined) this.default = input.default;\n if (input.annotations !== undefined) this.annotations = input.annotations;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport type { SqlAnnotations } from './sql-column-ir';\nimport { SqlSchemaIRNode } from './sql-schema-ir-node';\n\nexport type SqlReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';\n\nexport interface SqlForeignKeyIRInput {\n readonly columns: readonly string[];\n readonly referencedTable: string;\n readonly referencedColumns: readonly string[];\n readonly name?: string;\n readonly onDelete?: SqlReferentialAction;\n readonly onUpdate?: SqlReferentialAction;\n readonly annotations?: SqlAnnotations;\n}\n\n/**\n * Schema IR node for a foreign-key constraint as observed by\n * introspection. The `referencedTable` / `referencedColumns` field\n * names match the introspection vocabulary (`pg_constraint.confkey`,\n * etc.) and intentionally differ from the Contract IR's nested\n * `references: { table, columns }` shape so that the verifier's\n * structural comparison stays explicit about which side it's reading.\n */\nexport class SqlForeignKeyIR extends SqlSchemaIRNode {\n readonly columns: readonly string[];\n readonly referencedTable: string;\n readonly referencedColumns: readonly string[];\n declare readonly name?: string;\n declare readonly onDelete?: SqlReferentialAction;\n declare readonly onUpdate?: SqlReferentialAction;\n declare readonly annotations?: SqlAnnotations;\n\n constructor(input: SqlForeignKeyIRInput) {\n super();\n this.columns = input.columns;\n this.referencedTable = input.referencedTable;\n this.referencedColumns = input.referencedColumns;\n if (input.name !== undefined) this.name = input.name;\n if (input.onDelete !== undefined) this.onDelete = input.onDelete;\n if (input.onUpdate !== undefined) this.onUpdate = input.onUpdate;\n if (input.annotations !== undefined) this.annotations = input.annotations;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport type { SqlAnnotations } from './sql-column-ir';\nimport { SqlSchemaIRNode } from './sql-schema-ir-node';\n\nexport interface SqlIndexIRInput {\n readonly columns: readonly string[];\n readonly unique: boolean;\n readonly name?: string;\n readonly type?: string;\n readonly options?: Record<string, unknown>;\n readonly annotations?: SqlAnnotations;\n}\n\n/**\n * Schema IR node for a secondary index as observed by introspection.\n * Unlike the Contract IR `Index`, the Schema IR carries an explicit\n * `unique` field — introspection sees the underlying index regardless\n * of whether the user expressed it as `@@index` or `@@unique`, and the\n * verifier needs to distinguish them when comparing to the Contract.\n */\nexport class SqlIndexIR extends SqlSchemaIRNode {\n readonly columns: readonly string[];\n readonly unique: boolean;\n declare readonly name?: string;\n declare readonly type?: string;\n declare readonly options?: Record<string, unknown>;\n declare readonly annotations?: SqlAnnotations;\n\n constructor(input: SqlIndexIRInput) {\n super();\n this.columns = input.columns;\n this.unique = input.unique;\n if (input.name !== undefined) this.name = input.name;\n if (input.type !== undefined) this.type = input.type;\n if (input.options !== undefined) this.options = input.options;\n if (input.annotations !== undefined) this.annotations = input.annotations;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport type { SqlAnnotations } from './sql-column-ir';\nimport { SqlSchemaIRNode } from './sql-schema-ir-node';\n\nexport interface SqlUniqueIRInput {\n readonly columns: readonly string[];\n readonly name?: string;\n readonly annotations?: SqlAnnotations;\n}\n\n/**\n * Schema IR node for a table-level unique constraint as observed by\n * introspection.\n */\nexport class SqlUniqueIR extends SqlSchemaIRNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n declare readonly annotations?: SqlAnnotations;\n\n constructor(input: SqlUniqueIRInput) {\n super();\n this.columns = [...input.columns];\n if (input.name !== undefined) this.name = input.name;\n if (input.annotations !== undefined) this.annotations = input.annotations;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { PrimaryKey, type PrimaryKeyInput } from './primary-key';\nimport { type SqlAnnotations, SqlColumnIR, type SqlColumnIRInput } from './sql-column-ir';\nimport { SqlForeignKeyIR, type SqlForeignKeyIRInput } from './sql-foreign-key-ir';\nimport { SqlIndexIR, type SqlIndexIRInput } from './sql-index-ir';\nimport { SqlSchemaIRNode } from './sql-schema-ir-node';\nimport { SqlUniqueIR, type SqlUniqueIRInput } from './sql-unique-ir';\n\nexport interface SqlTableIRInput {\n readonly name: string;\n readonly columns: Record<string, SqlColumnIR | SqlColumnIRInput>;\n readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR | SqlForeignKeyIRInput>;\n readonly uniques: ReadonlyArray<SqlUniqueIR | SqlUniqueIRInput>;\n readonly indexes: ReadonlyArray<SqlIndexIR | SqlIndexIRInput>;\n readonly primaryKey?: PrimaryKey | PrimaryKeyInput;\n readonly annotations?: SqlAnnotations;\n}\n\n/**\n * Schema IR node for a single table as observed by introspection.\n *\n * Unlike the Contract IR `StorageTable`, this carries the table's\n * `name` — introspection queries return tables as arrays and the\n * verifier keys them into `SqlSchemaIR.tables` afterwards, so the name\n * stays on the table object for downstream call sites that walk\n * `Object.values(schema.tables)`.\n *\n * The constructor normalises nested IR-class fields so downstream\n * walks see a uniform AST regardless of whether the input was a\n * plain-data literal (from introspection) or already-constructed\n * class instances.\n */\nexport class SqlTableIR extends SqlSchemaIRNode {\n readonly name: string;\n readonly columns: Readonly<Record<string, SqlColumnIR>>;\n readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR>;\n readonly uniques: ReadonlyArray<SqlUniqueIR>;\n readonly indexes: ReadonlyArray<SqlIndexIR>;\n declare readonly primaryKey?: PrimaryKey;\n declare readonly annotations?: SqlAnnotations;\n\n constructor(input: SqlTableIRInput) {\n super();\n this.name = input.name;\n this.columns = Object.freeze(\n Object.fromEntries(\n Object.entries(input.columns).map(([key, col]) => [\n key,\n col instanceof SqlColumnIR ? col : new SqlColumnIR(col),\n ]),\n ),\n );\n this.foreignKeys = Object.freeze(\n input.foreignKeys.map((fk) => (fk instanceof SqlForeignKeyIR ? fk : new SqlForeignKeyIR(fk))),\n );\n this.uniques = Object.freeze(\n input.uniques.map((u) => (u instanceof SqlUniqueIR ? u : new SqlUniqueIR(u))),\n );\n this.indexes = Object.freeze(\n input.indexes.map((i) => (i instanceof SqlIndexIR ? i : new SqlIndexIR(i))),\n );\n if (input.primaryKey !== undefined) {\n this.primaryKey =\n input.primaryKey instanceof PrimaryKey\n ? input.primaryKey\n : new PrimaryKey(input.primaryKey);\n }\n if (input.annotations !== undefined) this.annotations = input.annotations;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport type { SqlAnnotations } from './sql-column-ir';\nimport { SqlSchemaIRNode } from './sql-schema-ir-node';\nimport { SqlTableIR, type SqlTableIRInput } from './sql-table-ir';\n\nexport interface SqlSchemaIRInput {\n readonly tables: Record<string, SqlTableIR | SqlTableIRInput>;\n readonly annotations?: SqlAnnotations;\n}\n\n/**\n * Root Schema IR node representing the complete database schema as\n * observed by introspection. Target-agnostic; used by both verifiers\n * (compare against intended Contract storage) and migration planners\n * (derive operations needed to reconcile).\n *\n * The constructor normalises nested `SqlTableIR` instances so\n * downstream walks see a uniform AST regardless of whether the input\n * was a plain-data literal or already-constructed class instances.\n */\nexport class SqlSchemaIR extends SqlSchemaIRNode {\n readonly tables: Readonly<Record<string, SqlTableIR>>;\n declare readonly annotations?: SqlAnnotations;\n\n constructor(input: SqlSchemaIRInput) {\n super();\n this.tables = Object.freeze(\n Object.fromEntries(\n Object.entries(input.tables).map(([key, t]) => [\n key,\n t instanceof SqlTableIR ? t : new SqlTableIR(t),\n ]),\n ),\n );\n if (input.annotations !== undefined) this.annotations = input.annotations;\n freezeNode(this);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,IAAsB,kBAAtB,cAA8C,WAAW;CACvD;CAEA,cAAc;EACZ,OAAO;EACP,OAAO,eAAe,MAAM,QAAQ;GAClC,OAAO;GACP,UAAU;GACV,YAAY;GACZ,cAAc;GACf,CAAC;;;;;;;;;;;ACjBN,IAAa,aAAb,cAAgC,gBAAgB;CAC9C;CAGA,YAAY,OAAwB;EAClC,OAAO;EACP,KAAK,UAAU,MAAM;EACrB,IAAI,MAAM,SAAS,KAAA,GAAW,KAAK,OAAO,MAAM;EAChD,WAAW,KAAK;;;;;;;;;;;;ACKpB,IAAa,cAAb,cAAiC,gBAAgB;CAC/C;CACA;CACA;CAIA,YAAY,OAAyB;EACnC,OAAO;EACP,KAAK,OAAO,MAAM;EAClB,KAAK,aAAa,MAAM;EACxB,KAAK,WAAW,MAAM;EACtB,IAAI,MAAM,YAAY,KAAA,GAAW,KAAK,UAAU,MAAM;EACtD,IAAI,MAAM,gBAAgB,KAAA,GAAW,KAAK,cAAc,MAAM;EAC9D,WAAW,KAAK;;;;;;;;;;;;;ACjBpB,IAAa,kBAAb,cAAqC,gBAAgB;CACnD;CACA;CACA;CAMA,YAAY,OAA6B;EACvC,OAAO;EACP,KAAK,UAAU,MAAM;EACrB,KAAK,kBAAkB,MAAM;EAC7B,KAAK,oBAAoB,MAAM;EAC/B,IAAI,MAAM,SAAS,KAAA,GAAW,KAAK,OAAO,MAAM;EAChD,IAAI,MAAM,aAAa,KAAA,GAAW,KAAK,WAAW,MAAM;EACxD,IAAI,MAAM,aAAa,KAAA,GAAW,KAAK,WAAW,MAAM;EACxD,IAAI,MAAM,gBAAgB,KAAA,GAAW,KAAK,cAAc,MAAM;EAC9D,WAAW,KAAK;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,EAAE,CAAE,CAC5E;EACD,IAAI,MAAM,eAAe,KAAA,GACvB,KAAK,aACH,MAAM,sBAAsB,aACxB,MAAM,aACN,IAAI,WAAW,MAAM,WAAW;EAExC,IAAI,MAAM,gBAAgB,KAAA,GAAW,KAAK,cAAc,MAAM;EAC9D,WAAW,KAAK;;;;;;;;;;;;;;;AChDpB,IAAa,cAAb,cAAiC,gBAAgB;CAC/C;CAGA,YAAY,OAAyB;EACnC,OAAO;EACP,KAAK,SAAS,OAAO,OACnB,OAAO,YACL,OAAO,QAAQ,MAAM,OAAO,CAAC,KAAK,CAAC,KAAK,OAAO,CAC7C,KACA,aAAa,aAAa,IAAI,IAAI,WAAW,EAAE,CAChD,CAAC,CACH,CACF;EACD,IAAI,MAAM,gBAAgB,KAAA,GAAW,KAAK,cAAc,MAAM;EAC9D,WAAW,KAAK"}
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@prisma-next/sql-schema-ir",
3
- "version": "0.8.0",
3
+ "version": "0.9.0-dev.2",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "description": "SQL Schema IR types for schema introspection and verification",
8
8
  "dependencies": {
9
- "@prisma-next/contract": "0.8.0"
9
+ "@prisma-next/contract": "0.9.0-dev.2",
10
+ "@prisma-next/framework-components": "0.9.0-dev.2"
10
11
  },
11
12
  "devDependencies": {
12
- "@prisma-next/test-utils": "0.8.0",
13
- "@prisma-next/tsconfig": "0.8.0",
14
- "@prisma-next/tsdown": "0.8.0",
13
+ "@prisma-next/test-utils": "0.9.0-dev.2",
14
+ "@prisma-next/tsconfig": "0.9.0-dev.2",
15
+ "@prisma-next/tsdown": "0.9.0-dev.2",
15
16
  "tsdown": "0.22.0",
16
17
  "typescript": "5.9.3",
17
18
  "vitest": "4.1.5"
@@ -29,8 +30,6 @@
29
30
  "./types": "./dist/exports/types.mjs",
30
31
  "./package.json": "./package.json"
31
32
  },
32
- "main": "./dist/index.mjs",
33
- "module": "./dist/index.mjs",
34
33
  "types": "./dist/index.d.mts",
35
34
  "repository": {
36
35
  "type": "git",
@@ -1,13 +1,24 @@
1
1
  export type {
2
- PrimaryKey,
2
+ PrimaryKeyInput,
3
3
  SqlAnnotations,
4
+ SqlColumnIRInput,
5
+ SqlForeignKeyIRInput,
6
+ SqlIndexIRInput,
7
+ SqlReferentialAction,
8
+ SqlSchemaIRInput,
9
+ SqlTableIRInput,
10
+ SqlTypeMetadata,
11
+ SqlTypeMetadataRegistry,
12
+ SqlUniqueIRInput,
13
+ } from '../types';
14
+
15
+ export {
16
+ PrimaryKey,
4
17
  SqlColumnIR,
5
18
  SqlForeignKeyIR,
6
19
  SqlIndexIR,
7
- SqlReferentialAction,
8
20
  SqlSchemaIR,
21
+ SqlSchemaIRNode,
9
22
  SqlTableIR,
10
- SqlTypeMetadata,
11
- SqlTypeMetadataRegistry,
12
23
  SqlUniqueIR,
13
24
  } from '../types';
@@ -0,0 +1,25 @@
1
+ import { freezeNode } from '@prisma-next/framework-components/ir';
2
+ import { SqlSchemaIRNode } from './sql-schema-ir-node';
3
+
4
+ export interface PrimaryKeyInput {
5
+ readonly columns: readonly string[];
6
+ readonly name?: string;
7
+ }
8
+
9
+ /**
10
+ * Primary-key Schema IR node. Mirrors the Contract IR `PrimaryKey`
11
+ * shape (same `columns` + optional `name`) so verification can compare
12
+ * intent and actual structurally. Defined here independently to avoid
13
+ * a sql-schema-ir -> sql-contract dependency.
14
+ */
15
+ export class PrimaryKey extends SqlSchemaIRNode {
16
+ readonly columns: readonly string[];
17
+ declare readonly name?: string;
18
+
19
+ constructor(input: PrimaryKeyInput) {
20
+ super();
21
+ this.columns = input.columns;
22
+ if (input.name !== undefined) this.name = input.name;
23
+ freezeNode(this);
24
+ }
25
+ }
@@ -0,0 +1,44 @@
1
+ import { freezeNode } from '@prisma-next/framework-components/ir';
2
+ import { SqlSchemaIRNode } from './sql-schema-ir-node';
3
+
4
+ /**
5
+ * Namespaced annotations for extensibility. Each namespace
6
+ * (e.g. `pg`, `pgvector`) owns its annotations subtree.
7
+ */
8
+ export type SqlAnnotations = {
9
+ readonly [namespace: string]: unknown;
10
+ };
11
+
12
+ export interface SqlColumnIRInput {
13
+ readonly name: string;
14
+ readonly nativeType: string;
15
+ readonly nullable: boolean;
16
+ /** Raw database default expression (e.g. `'hello'::text`, `nextval('seq')`). */
17
+ readonly default?: string;
18
+ readonly annotations?: SqlAnnotations;
19
+ }
20
+
21
+ /**
22
+ * Schema IR node for a single column on a table, as observed by
23
+ * introspection. Unlike the Contract IR `StorageColumn`, this carries
24
+ * the column's `name` (Schema IR columns are returned as arrays from
25
+ * introspection queries; the parent table re-keys them into a record
26
+ * for downstream consumers).
27
+ */
28
+ export class SqlColumnIR extends SqlSchemaIRNode {
29
+ readonly name: string;
30
+ readonly nativeType: string;
31
+ readonly nullable: boolean;
32
+ declare readonly default?: string;
33
+ declare readonly annotations?: SqlAnnotations;
34
+
35
+ constructor(input: SqlColumnIRInput) {
36
+ super();
37
+ this.name = input.name;
38
+ this.nativeType = input.nativeType;
39
+ this.nullable = input.nullable;
40
+ if (input.default !== undefined) this.default = input.default;
41
+ if (input.annotations !== undefined) this.annotations = input.annotations;
42
+ freezeNode(this);
43
+ }
44
+ }
@@ -0,0 +1,45 @@
1
+ import { freezeNode } from '@prisma-next/framework-components/ir';
2
+ import type { SqlAnnotations } from './sql-column-ir';
3
+ import { SqlSchemaIRNode } from './sql-schema-ir-node';
4
+
5
+ export type SqlReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
6
+
7
+ export interface SqlForeignKeyIRInput {
8
+ readonly columns: readonly string[];
9
+ readonly referencedTable: string;
10
+ readonly referencedColumns: readonly string[];
11
+ readonly name?: string;
12
+ readonly onDelete?: SqlReferentialAction;
13
+ readonly onUpdate?: SqlReferentialAction;
14
+ readonly annotations?: SqlAnnotations;
15
+ }
16
+
17
+ /**
18
+ * Schema IR node for a foreign-key constraint as observed by
19
+ * introspection. The `referencedTable` / `referencedColumns` field
20
+ * names match the introspection vocabulary (`pg_constraint.confkey`,
21
+ * etc.) and intentionally differ from the Contract IR's nested
22
+ * `references: { table, columns }` shape so that the verifier's
23
+ * structural comparison stays explicit about which side it's reading.
24
+ */
25
+ export class SqlForeignKeyIR extends SqlSchemaIRNode {
26
+ readonly columns: readonly string[];
27
+ readonly referencedTable: string;
28
+ readonly referencedColumns: readonly string[];
29
+ declare readonly name?: string;
30
+ declare readonly onDelete?: SqlReferentialAction;
31
+ declare readonly onUpdate?: SqlReferentialAction;
32
+ declare readonly annotations?: SqlAnnotations;
33
+
34
+ constructor(input: SqlForeignKeyIRInput) {
35
+ super();
36
+ this.columns = input.columns;
37
+ this.referencedTable = input.referencedTable;
38
+ this.referencedColumns = input.referencedColumns;
39
+ if (input.name !== undefined) this.name = input.name;
40
+ if (input.onDelete !== undefined) this.onDelete = input.onDelete;
41
+ if (input.onUpdate !== undefined) this.onUpdate = input.onUpdate;
42
+ if (input.annotations !== undefined) this.annotations = input.annotations;
43
+ freezeNode(this);
44
+ }
45
+ }
@@ -0,0 +1,39 @@
1
+ import { freezeNode } from '@prisma-next/framework-components/ir';
2
+ import type { SqlAnnotations } from './sql-column-ir';
3
+ import { SqlSchemaIRNode } from './sql-schema-ir-node';
4
+
5
+ export interface SqlIndexIRInput {
6
+ readonly columns: readonly string[];
7
+ readonly unique: boolean;
8
+ readonly name?: string;
9
+ readonly type?: string;
10
+ readonly options?: Record<string, unknown>;
11
+ readonly annotations?: SqlAnnotations;
12
+ }
13
+
14
+ /**
15
+ * Schema IR node for a secondary index as observed by introspection.
16
+ * Unlike the Contract IR `Index`, the Schema IR carries an explicit
17
+ * `unique` field — introspection sees the underlying index regardless
18
+ * of whether the user expressed it as `@@index` or `@@unique`, and the
19
+ * verifier needs to distinguish them when comparing to the Contract.
20
+ */
21
+ export class SqlIndexIR extends SqlSchemaIRNode {
22
+ readonly columns: readonly string[];
23
+ readonly unique: boolean;
24
+ declare readonly name?: string;
25
+ declare readonly type?: string;
26
+ declare readonly options?: Record<string, unknown>;
27
+ declare readonly annotations?: SqlAnnotations;
28
+
29
+ constructor(input: SqlIndexIRInput) {
30
+ super();
31
+ this.columns = input.columns;
32
+ this.unique = input.unique;
33
+ if (input.name !== undefined) this.name = input.name;
34
+ if (input.type !== undefined) this.type = input.type;
35
+ if (input.options !== undefined) this.options = input.options;
36
+ if (input.annotations !== undefined) this.annotations = input.annotations;
37
+ freezeNode(this);
38
+ }
39
+ }
@@ -0,0 +1,34 @@
1
+ import { IRNodeBase } from '@prisma-next/framework-components/ir';
2
+
3
+ /**
4
+ * SQL Schema IR node base. Carries the family-level
5
+ * `kind = 'sql-schema-ir'` discriminator and inherits the framework's
6
+ * `freezeNode` affordance.
7
+ *
8
+ * SQL Schema IR represents the actual database state as discovered by
9
+ * introspection (the parallel to SQL Contract IR, which represents the
10
+ * desired state). Like the Contract side, today's Schema IR has no
11
+ * polymorphic dispatch — verifiers and planners walk by structural
12
+ * position, not by inspecting `kind` — so a single family-level
13
+ * discriminator is sufficient. Future per-leaf overrides land cleanly
14
+ * the same way as on the Contract side.
15
+ *
16
+ * The discriminator is installed as a non-enumerable own property,
17
+ * matching the SqlNode pattern. This keeps `JSON.stringify(node)`
18
+ * canonical (no `kind` field), keeps `toEqual({...})` test assertions
19
+ * against pre-lift flat shapes passing, and keeps `node.kind` readable
20
+ * for future polymorphic dispatch.
21
+ */
22
+ export abstract class SqlSchemaIRNode extends IRNodeBase {
23
+ readonly kind?: string;
24
+
25
+ constructor() {
26
+ super();
27
+ Object.defineProperty(this, 'kind', {
28
+ value: 'sql-schema-ir',
29
+ writable: false,
30
+ enumerable: false,
31
+ configurable: false,
32
+ });
33
+ }
34
+ }
@@ -0,0 +1,38 @@
1
+ import { freezeNode } from '@prisma-next/framework-components/ir';
2
+ import type { SqlAnnotations } from './sql-column-ir';
3
+ import { SqlSchemaIRNode } from './sql-schema-ir-node';
4
+ import { SqlTableIR, type SqlTableIRInput } from './sql-table-ir';
5
+
6
+ export interface SqlSchemaIRInput {
7
+ readonly tables: Record<string, SqlTableIR | SqlTableIRInput>;
8
+ readonly annotations?: SqlAnnotations;
9
+ }
10
+
11
+ /**
12
+ * Root Schema IR node representing the complete database schema as
13
+ * observed by introspection. Target-agnostic; used by both verifiers
14
+ * (compare against intended Contract storage) and migration planners
15
+ * (derive operations needed to reconcile).
16
+ *
17
+ * The constructor normalises nested `SqlTableIR` instances so
18
+ * downstream walks see a uniform AST regardless of whether the input
19
+ * was a plain-data literal or already-constructed class instances.
20
+ */
21
+ export class SqlSchemaIR extends SqlSchemaIRNode {
22
+ readonly tables: Readonly<Record<string, SqlTableIR>>;
23
+ declare readonly annotations?: SqlAnnotations;
24
+
25
+ constructor(input: SqlSchemaIRInput) {
26
+ super();
27
+ this.tables = Object.freeze(
28
+ Object.fromEntries(
29
+ Object.entries(input.tables).map(([key, t]) => [
30
+ key,
31
+ t instanceof SqlTableIR ? t : new SqlTableIR(t),
32
+ ]),
33
+ ),
34
+ );
35
+ if (input.annotations !== undefined) this.annotations = input.annotations;
36
+ freezeNode(this);
37
+ }
38
+ }
@@ -0,0 +1,71 @@
1
+ import { freezeNode } from '@prisma-next/framework-components/ir';
2
+ import { PrimaryKey, type PrimaryKeyInput } from './primary-key';
3
+ import { type SqlAnnotations, SqlColumnIR, type SqlColumnIRInput } from './sql-column-ir';
4
+ import { SqlForeignKeyIR, type SqlForeignKeyIRInput } from './sql-foreign-key-ir';
5
+ import { SqlIndexIR, type SqlIndexIRInput } from './sql-index-ir';
6
+ import { SqlSchemaIRNode } from './sql-schema-ir-node';
7
+ import { SqlUniqueIR, type SqlUniqueIRInput } from './sql-unique-ir';
8
+
9
+ export interface SqlTableIRInput {
10
+ readonly name: string;
11
+ readonly columns: Record<string, SqlColumnIR | SqlColumnIRInput>;
12
+ readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR | SqlForeignKeyIRInput>;
13
+ readonly uniques: ReadonlyArray<SqlUniqueIR | SqlUniqueIRInput>;
14
+ readonly indexes: ReadonlyArray<SqlIndexIR | SqlIndexIRInput>;
15
+ readonly primaryKey?: PrimaryKey | PrimaryKeyInput;
16
+ readonly annotations?: SqlAnnotations;
17
+ }
18
+
19
+ /**
20
+ * Schema IR node for a single table as observed by introspection.
21
+ *
22
+ * Unlike the Contract IR `StorageTable`, this carries the table's
23
+ * `name` — introspection queries return tables as arrays and the
24
+ * verifier keys them into `SqlSchemaIR.tables` afterwards, so the name
25
+ * stays on the table object for downstream call sites that walk
26
+ * `Object.values(schema.tables)`.
27
+ *
28
+ * The constructor normalises nested IR-class fields so downstream
29
+ * walks see a uniform AST regardless of whether the input was a
30
+ * plain-data literal (from introspection) or already-constructed
31
+ * class instances.
32
+ */
33
+ export class SqlTableIR extends SqlSchemaIRNode {
34
+ readonly name: string;
35
+ readonly columns: Readonly<Record<string, SqlColumnIR>>;
36
+ readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR>;
37
+ readonly uniques: ReadonlyArray<SqlUniqueIR>;
38
+ readonly indexes: ReadonlyArray<SqlIndexIR>;
39
+ declare readonly primaryKey?: PrimaryKey;
40
+ declare readonly annotations?: SqlAnnotations;
41
+
42
+ constructor(input: SqlTableIRInput) {
43
+ super();
44
+ this.name = input.name;
45
+ this.columns = Object.freeze(
46
+ Object.fromEntries(
47
+ Object.entries(input.columns).map(([key, col]) => [
48
+ key,
49
+ col instanceof SqlColumnIR ? col : new SqlColumnIR(col),
50
+ ]),
51
+ ),
52
+ );
53
+ this.foreignKeys = Object.freeze(
54
+ input.foreignKeys.map((fk) => (fk instanceof SqlForeignKeyIR ? fk : new SqlForeignKeyIR(fk))),
55
+ );
56
+ this.uniques = Object.freeze(
57
+ input.uniques.map((u) => (u instanceof SqlUniqueIR ? u : new SqlUniqueIR(u))),
58
+ );
59
+ this.indexes = Object.freeze(
60
+ input.indexes.map((i) => (i instanceof SqlIndexIR ? i : new SqlIndexIR(i))),
61
+ );
62
+ if (input.primaryKey !== undefined) {
63
+ this.primaryKey =
64
+ input.primaryKey instanceof PrimaryKey
65
+ ? input.primaryKey
66
+ : new PrimaryKey(input.primaryKey);
67
+ }
68
+ if (input.annotations !== undefined) this.annotations = input.annotations;
69
+ freezeNode(this);
70
+ }
71
+ }
@@ -0,0 +1,27 @@
1
+ import { freezeNode } from '@prisma-next/framework-components/ir';
2
+ import type { SqlAnnotations } from './sql-column-ir';
3
+ import { SqlSchemaIRNode } from './sql-schema-ir-node';
4
+
5
+ export interface SqlUniqueIRInput {
6
+ readonly columns: readonly string[];
7
+ readonly name?: string;
8
+ readonly annotations?: SqlAnnotations;
9
+ }
10
+
11
+ /**
12
+ * Schema IR node for a table-level unique constraint as observed by
13
+ * introspection.
14
+ */
15
+ export class SqlUniqueIR extends SqlSchemaIRNode {
16
+ readonly columns: readonly string[];
17
+ declare readonly name?: string;
18
+ declare readonly annotations?: SqlAnnotations;
19
+
20
+ constructor(input: SqlUniqueIRInput) {
21
+ super();
22
+ this.columns = [...input.columns];
23
+ if (input.name !== undefined) this.name = input.name;
24
+ if (input.annotations !== undefined) this.annotations = input.annotations;
25
+ freezeNode(this);
26
+ }
27
+ }
package/src/types.ts CHANGED
@@ -1,133 +1,54 @@
1
1
  /**
2
2
  * SQL Schema IR types for target-agnostic schema representation.
3
3
  *
4
- * These types represent the canonical in-memory representation of SQL schemas
5
- * for the SQL family, used for verification and future migration planning.
6
- */
7
-
8
- /**
9
- * Primary key definition matching Contract format.
10
- * Defined here to avoid circular dependency with sql-contract.
11
- */
12
- export type PrimaryKey = {
13
- readonly columns: readonly string[];
14
- readonly name?: string;
15
- };
16
-
17
- /**
18
- * Namespaced annotations for extensibility.
19
- * Each namespace (e.g., 'pg', 'pgvector') owns its annotations.
20
- */
21
- export type SqlAnnotations = {
22
- readonly [namespace: string]: unknown;
23
- };
24
-
25
- /**
26
- * SQL column IR representing a column in a table.
27
- */
28
- export type SqlColumnIR = {
29
- readonly name: string;
30
- readonly nativeType: string; // explicit DB type, e.g. 'integer', 'vector'
31
- readonly nullable: boolean;
32
- readonly default?: string; // Raw database default expression (e.g., "'hello'::text", "nextval('seq')")
33
- readonly annotations?: SqlAnnotations; // column-level metadata
34
- };
35
-
36
- /**
37
- * Referential action for foreign keys in the schema IR.
38
- * Defined here independently from the contract package to avoid coupling.
39
- */
40
- export type SqlReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
41
-
42
- /**
43
- * SQL foreign key IR.
44
- */
45
- export type SqlForeignKeyIR = {
46
- readonly columns: readonly string[];
47
- readonly referencedTable: string;
48
- readonly referencedColumns: readonly string[];
49
- readonly name?: string;
50
- readonly onDelete?: SqlReferentialAction;
51
- readonly onUpdate?: SqlReferentialAction;
52
- readonly annotations?: SqlAnnotations;
53
- };
54
-
55
- /**
56
- * SQL unique constraint IR.
57
- */
58
- export type SqlUniqueIR = {
59
- readonly columns: readonly string[];
60
- readonly name?: string;
61
- readonly annotations?: SqlAnnotations;
62
- };
63
-
64
- /**
65
- * SQL index IR.
66
- */
67
- export type SqlIndexIR = {
68
- readonly columns: readonly string[];
69
- readonly name?: string;
70
- readonly unique: boolean;
71
- readonly type?: string;
72
- readonly options?: Record<string, unknown>;
73
- readonly annotations?: SqlAnnotations;
74
- };
75
-
76
- /**
77
- * SQL table IR representing a table in the schema.
78
- * Primary key format matches Contract for consistency.
79
- */
80
- export type SqlTableIR = {
81
- readonly name: string;
82
- readonly columns: Record<string, SqlColumnIR>;
83
- readonly primaryKey?: PrimaryKey; // Matches Contract format: { columns: string[]; name?: string }
84
- readonly foreignKeys: readonly SqlForeignKeyIR[];
85
- readonly uniques: readonly SqlUniqueIR[];
86
- readonly indexes: readonly SqlIndexIR[];
87
- readonly annotations?: SqlAnnotations; // table-level metadata
88
- };
89
-
90
- /**
91
- * SQL Schema IR representing the complete database schema.
92
- * This is the target-agnostic representation used for verification and migration planning.
93
- */
94
- export type SqlSchemaIR = {
95
- readonly tables: Record<string, SqlTableIR>;
96
- readonly annotations?: SqlAnnotations; // extensible global metadata
97
- };
98
-
99
- /**
100
- * SQL type metadata for control-plane and execution-plane type availability and mapping.
101
- * This abstraction provides a read-only view of type information without encode/decode behavior.
4
+ * These classes represent the canonical in-memory representation of
5
+ * SQL schemas for the SQL family, used for verification and migration
6
+ * planning. Each class extends `SqlSchemaIRNode` (the family base
7
+ * declared in `ir/sql-schema-ir-node.ts`) and carries `freezeNode`
8
+ * sealing in its constructor. `Input` interfaces describe the
9
+ * plain-data shape that introspection adapters produce.
10
+ */
11
+
12
+ export { PrimaryKey, type PrimaryKeyInput } from './ir/primary-key';
13
+ export {
14
+ type SqlAnnotations,
15
+ SqlColumnIR,
16
+ type SqlColumnIRInput,
17
+ } from './ir/sql-column-ir';
18
+ export {
19
+ SqlForeignKeyIR,
20
+ type SqlForeignKeyIRInput,
21
+ type SqlReferentialAction,
22
+ } from './ir/sql-foreign-key-ir';
23
+ export { SqlIndexIR, type SqlIndexIRInput } from './ir/sql-index-ir';
24
+ export { SqlSchemaIR, type SqlSchemaIRInput } from './ir/sql-schema-ir';
25
+ export { SqlSchemaIRNode } from './ir/sql-schema-ir-node';
26
+ export { SqlTableIR, type SqlTableIRInput } from './ir/sql-table-ir';
27
+ export { SqlUniqueIR, type SqlUniqueIRInput } from './ir/sql-unique-ir';
28
+
29
+ /**
30
+ * SQL type metadata for control-plane and execution-plane type
31
+ * availability and mapping. Read-only view of type information
32
+ * without encode/decode behavior.
102
33
  */
103
34
  export interface SqlTypeMetadata {
104
- /**
105
- * Namespaced type identifier in format 'namespace/name@version'
106
- * Examples: 'pg/int4@1', 'pg/text@1', 'pg/timestamptz@1'
107
- */
35
+ /** Namespaced type identifier, e.g. `pg/int4@1`, `pg/text@1`. */
108
36
  readonly typeId: string;
109
37
 
110
- /**
111
- * Contract scalar type IDs that this type can handle.
112
- * Examples: ['text'], ['int4', 'float8'], ['timestamp', 'timestamptz']
113
- */
38
+ /** Contract scalar type IDs this type can handle. */
114
39
  readonly targetTypes: readonly string[];
115
40
 
116
41
  /**
117
- * Native database type name (target-specific).
118
- * Examples: 'integer', 'text', 'character varying', 'timestamp with time zone'
119
- * This is optional because not all types have a native database representation.
42
+ * Native database type name (target-specific). Optional because
43
+ * not all types have a native database representation.
120
44
  */
121
45
  readonly nativeType?: string;
122
46
  }
123
47
 
124
48
  /**
125
- * Registry interface for SQL type metadata.
126
- * Provides read-only iteration over type metadata entries.
49
+ * Registry interface for SQL type metadata. Provides read-only
50
+ * iteration over type metadata entries.
127
51
  */
128
52
  export interface SqlTypeMetadataRegistry {
129
- /**
130
- * Returns an iterator over all type metadata entries.
131
- */
132
53
  values(): IterableIterator<SqlTypeMetadata>;
133
54
  }
@@ -1,124 +0,0 @@
1
- //#region src/types.d.ts
2
- /**
3
- * SQL Schema IR types for target-agnostic schema representation.
4
- *
5
- * These types represent the canonical in-memory representation of SQL schemas
6
- * for the SQL family, used for verification and future migration planning.
7
- */
8
- /**
9
- * Primary key definition matching Contract format.
10
- * Defined here to avoid circular dependency with sql-contract.
11
- */
12
- type PrimaryKey = {
13
- readonly columns: readonly string[];
14
- readonly name?: string;
15
- };
16
- /**
17
- * Namespaced annotations for extensibility.
18
- * Each namespace (e.g., 'pg', 'pgvector') owns its annotations.
19
- */
20
- type SqlAnnotations = {
21
- readonly [namespace: string]: unknown;
22
- };
23
- /**
24
- * SQL column IR representing a column in a table.
25
- */
26
- type SqlColumnIR = {
27
- readonly name: string;
28
- readonly nativeType: string;
29
- readonly nullable: boolean;
30
- readonly default?: string;
31
- readonly annotations?: SqlAnnotations;
32
- };
33
- /**
34
- * Referential action for foreign keys in the schema IR.
35
- * Defined here independently from the contract package to avoid coupling.
36
- */
37
- type SqlReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
38
- /**
39
- * SQL foreign key IR.
40
- */
41
- type SqlForeignKeyIR = {
42
- readonly columns: readonly string[];
43
- readonly referencedTable: string;
44
- readonly referencedColumns: readonly string[];
45
- readonly name?: string;
46
- readonly onDelete?: SqlReferentialAction;
47
- readonly onUpdate?: SqlReferentialAction;
48
- readonly annotations?: SqlAnnotations;
49
- };
50
- /**
51
- * SQL unique constraint IR.
52
- */
53
- type SqlUniqueIR = {
54
- readonly columns: readonly string[];
55
- readonly name?: string;
56
- readonly annotations?: SqlAnnotations;
57
- };
58
- /**
59
- * SQL index IR.
60
- */
61
- type SqlIndexIR = {
62
- readonly columns: readonly string[];
63
- readonly name?: string;
64
- readonly unique: boolean;
65
- readonly type?: string;
66
- readonly options?: Record<string, unknown>;
67
- readonly annotations?: SqlAnnotations;
68
- };
69
- /**
70
- * SQL table IR representing a table in the schema.
71
- * Primary key format matches Contract for consistency.
72
- */
73
- type SqlTableIR = {
74
- readonly name: string;
75
- readonly columns: Record<string, SqlColumnIR>;
76
- readonly primaryKey?: PrimaryKey;
77
- readonly foreignKeys: readonly SqlForeignKeyIR[];
78
- readonly uniques: readonly SqlUniqueIR[];
79
- readonly indexes: readonly SqlIndexIR[];
80
- readonly annotations?: SqlAnnotations;
81
- };
82
- /**
83
- * SQL Schema IR representing the complete database schema.
84
- * This is the target-agnostic representation used for verification and migration planning.
85
- */
86
- type SqlSchemaIR = {
87
- readonly tables: Record<string, SqlTableIR>;
88
- readonly annotations?: SqlAnnotations;
89
- };
90
- /**
91
- * SQL type metadata for control-plane and execution-plane type availability and mapping.
92
- * This abstraction provides a read-only view of type information without encode/decode behavior.
93
- */
94
- interface SqlTypeMetadata {
95
- /**
96
- * Namespaced type identifier in format 'namespace/name@version'
97
- * Examples: 'pg/int4@1', 'pg/text@1', 'pg/timestamptz@1'
98
- */
99
- readonly typeId: string;
100
- /**
101
- * Contract scalar type IDs that this type can handle.
102
- * Examples: ['text'], ['int4', 'float8'], ['timestamp', 'timestamptz']
103
- */
104
- readonly targetTypes: readonly string[];
105
- /**
106
- * Native database type name (target-specific).
107
- * Examples: 'integer', 'text', 'character varying', 'timestamp with time zone'
108
- * This is optional because not all types have a native database representation.
109
- */
110
- readonly nativeType?: string;
111
- }
112
- /**
113
- * Registry interface for SQL type metadata.
114
- * Provides read-only iteration over type metadata entries.
115
- */
116
- interface SqlTypeMetadataRegistry {
117
- /**
118
- * Returns an iterator over all type metadata entries.
119
- */
120
- values(): IterableIterator<SqlTypeMetadata>;
121
- }
122
- //#endregion
123
- export { SqlIndexIR as a, SqlTableIR as c, SqlUniqueIR as d, SqlForeignKeyIR as i, SqlTypeMetadata as l, SqlAnnotations as n, SqlReferentialAction as o, SqlColumnIR as r, SqlSchemaIR as s, PrimaryKey as t, SqlTypeMetadataRegistry as u };
124
- //# sourceMappingURL=types-BNW257Ug.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-BNW257Ug.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;AAWA;;;;;AASA;;;;AAAA,KATY,UAAA;EAAA,SACD,OAAA;EAAA,SACA,IAAA;AAAA;;;;;KAOC,cAAA;EAAA,UACA,SAAA;AAAA;;;AAkBZ;KAZY,WAAA;EAAA,SACD,IAAA;EAAA,SACA,UAAA;EAAA,SACA,QAAA;EAAA,SACA,OAAA;EAAA,SACA,WAAA,GAAc,cAAA;AAAA;;;;;KAOb,oBAAA;;;;KAKA,eAAA;EAAA,SACD,OAAA;EAAA,SACA,eAAA;EAAA,SACA,iBAAA;EAAA,SACA,IAAA;EAAA,SACA,QAAA,GAAW,oBAAA;EAAA,SACX,QAAA,GAAW,oBAAA;EAAA,SACX,WAAA,GAAc,cAAA;AAAA;AAMzB;;;AAAA,KAAY,WAAA;EAAA,SACD,OAAA;EAAA,SACA,IAAA;EAAA,SACA,WAAA,GAAc,cAAA;AAAA;;;AAMzB;KAAY,UAAA;EAAA,SACD,OAAA;EAAA,SACA,IAAA;EAAA,SACA,MAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA,GAAU,MAAA;EAAA,SACV,WAAA,GAAc,cAAA;AAAA;;;;;KAOb,UAAA;EAAA,SACD,IAAA;EAAA,SACA,OAAA,EAAS,MAAA,SAAe,WAAA;EAAA,SACxB,UAAA,GAAa,UAAA;EAAA,SACb,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