@c9up/eon 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -0
- package/dist/EonProvider.d.ts +51 -0
- package/dist/EonProvider.d.ts.map +1 -0
- package/dist/EonProvider.js +154 -0
- package/dist/EonProvider.js.map +1 -0
- package/dist/connection/EonConnection.d.ts +116 -0
- package/dist/connection/EonConnection.d.ts.map +1 -0
- package/dist/connection/EonConnection.js +15 -0
- package/dist/connection/EonConnection.js.map +1 -0
- package/dist/connection/config.d.ts +56 -0
- package/dist/connection/config.d.ts.map +1 -0
- package/dist/connection/config.js +14 -0
- package/dist/connection/config.js.map +1 -0
- package/dist/connection/websocket.d.ts +16 -0
- package/dist/connection/websocket.d.ts.map +1 -0
- package/dist/connection/websocket.js +383 -0
- package/dist/connection/websocket.js.map +1 -0
- package/dist/decorators/superTable.d.ts +73 -0
- package/dist/decorators/superTable.d.ts.map +1 -0
- package/dist/decorators/superTable.js +98 -0
- package/dist/decorators/superTable.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/ingest/schemaless.d.ts +22 -0
- package/dist/ingest/schemaless.d.ts.map +1 -0
- package/dist/ingest/schemaless.js +161 -0
- package/dist/ingest/schemaless.js.map +1 -0
- package/dist/ingest/sql.d.ts +23 -0
- package/dist/ingest/sql.d.ts.map +1 -0
- package/dist/ingest/sql.js +59 -0
- package/dist/ingest/sql.js.map +1 -0
- package/dist/ingest/stmt.d.ts +82 -0
- package/dist/ingest/stmt.d.ts.map +1 -0
- package/dist/ingest/stmt.js +246 -0
- package/dist/ingest/stmt.js.map +1 -0
- package/dist/metadata-keys.d.ts +17 -0
- package/dist/metadata-keys.d.ts.map +1 -0
- package/dist/metadata-keys.js +17 -0
- package/dist/metadata-keys.js.map +1 -0
- package/dist/query/TimeSeriesQuery.d.ts +121 -0
- package/dist/query/TimeSeriesQuery.d.ts.map +1 -0
- package/dist/query/TimeSeriesQuery.js +291 -0
- package/dist/query/TimeSeriesQuery.js.map +1 -0
- package/dist/query/native.d.ts +22 -0
- package/dist/query/native.d.ts.map +1 -0
- package/dist/query/native.js +135 -0
- package/dist/query/native.js.map +1 -0
- package/dist/repository/SuperTableRepository.d.ts +80 -0
- package/dist/repository/SuperTableRepository.d.ts.map +1 -0
- package/dist/repository/SuperTableRepository.js +232 -0
- package/dist/repository/SuperTableRepository.js.map +1 -0
- package/dist/schema/CreateStableSpec.d.ts +140 -0
- package/dist/schema/CreateStableSpec.d.ts.map +1 -0
- package/dist/schema/CreateStableSpec.js +41 -0
- package/dist/schema/CreateStableSpec.js.map +1 -0
- package/dist/schema/EonMigrationRunner.d.ts +71 -0
- package/dist/schema/EonMigrationRunner.d.ts.map +1 -0
- package/dist/schema/EonMigrationRunner.js +295 -0
- package/dist/schema/EonMigrationRunner.js.map +1 -0
- package/dist/schema/EonSchema.d.ts +128 -0
- package/dist/schema/EonSchema.d.ts.map +1 -0
- package/dist/schema/EonSchema.js +309 -0
- package/dist/schema/EonSchema.js.map +1 -0
- package/dist/schema/Migration.d.ts +47 -0
- package/dist/schema/Migration.d.ts.map +1 -0
- package/dist/schema/Migration.js +55 -0
- package/dist/schema/Migration.js.map +1 -0
- package/dist/schema/compile.d.ts +33 -0
- package/dist/schema/compile.d.ts.map +1 -0
- package/dist/schema/compile.js +70 -0
- package/dist/schema/compile.js.map +1 -0
- package/dist/schema/sync.d.ts +45 -0
- package/dist/schema/sync.d.ts.map +1 -0
- package/dist/schema/sync.js +102 -0
- package/dist/schema/sync.js.map +1 -0
- package/dist/services/connection.d.ts +33 -0
- package/dist/services/connection.d.ts.map +1 -0
- package/dist/services/connection.js +71 -0
- package/dist/services/connection.js.map +1 -0
- package/dist/testing/Factory.d.ts +43 -0
- package/dist/testing/Factory.d.ts.map +1 -0
- package/dist/testing/Factory.js +134 -0
- package/dist/testing/Factory.js.map +1 -0
- package/dist/testing/FakeEonConnection.d.ts +43 -0
- package/dist/testing/FakeEonConnection.d.ts.map +1 -0
- package/dist/testing/FakeEonConnection.js +315 -0
- package/dist/testing/FakeEonConnection.js.map +1 -0
- package/dist/testing/index.d.ts +34 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +67 -0
- package/dist/testing/index.js.map +1 -0
- package/index.darwin-arm64.node +0 -0
- package/index.darwin-x64.node +0 -0
- package/index.linux-arm64-gnu.node +0 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +65 -0
- package/scripts/copy-napi.mjs +72 -0
- package/src/EonProvider.ts +222 -0
- package/src/connection/EonConnection.ts +146 -0
- package/src/connection/config.ts +60 -0
- package/src/connection/websocket.ts +436 -0
- package/src/decorators/superTable.ts +169 -0
- package/src/index.ts +118 -0
- package/src/ingest/schemaless.ts +211 -0
- package/src/ingest/sql.ts +73 -0
- package/src/ingest/stmt.ts +335 -0
- package/src/metadata-keys.ts +20 -0
- package/src/query/TimeSeriesQuery.ts +480 -0
- package/src/query/native.ts +180 -0
- package/src/repository/SuperTableRepository.ts +347 -0
- package/src/schema/CreateStableSpec.ts +184 -0
- package/src/schema/EonMigrationRunner.ts +378 -0
- package/src/schema/EonSchema.ts +396 -0
- package/src/schema/Migration.ts +66 -0
- package/src/schema/compile.ts +109 -0
- package/src/schema/sync.ts +142 -0
- package/src/services/connection.ts +89 -0
- package/src/testing/Factory.ts +186 -0
- package/src/testing/FakeEonConnection.ts +351 -0
- package/src/testing/index.ts +81 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `EonSchema` — the fluent DDL surface a migration's `up()`/`down()` drives.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors atlas `Schema` (`schema/Schema.ts`) in shape: each method compiles its
|
|
5
|
+
* spec through the Rust `compileStatementNative` seam and appends the resulting
|
|
6
|
+
* SQL to an internal buffer the runner flushes. The TS side NEVER string-builds
|
|
7
|
+
* SQL — every identifier, literal, and option value is quoted/validated in Rust
|
|
8
|
+
* (the injection seam stays in one place, memory `feedback_security_first`).
|
|
9
|
+
*
|
|
10
|
+
* The `StableBuilder` is intentionally THINNER than atlas `TableBuilder`:
|
|
11
|
+
* TDengine columns have no `DEFAULT`, no per-column `PRIMARY KEY` choice (the
|
|
12
|
+
* first `TIMESTAMP` is always the key), no `UNIQUE`, no foreign keys, no SQL
|
|
13
|
+
* secondary indexes — so `defaultTo`/`primary`/`unique`/`references`/`increments`
|
|
14
|
+
* have NO analogue and are deliberately absent (D — the reconciliation note).
|
|
15
|
+
*/
|
|
16
|
+
import { compileStatementNative } from "../query/native.js";
|
|
17
|
+
/** Build one column/tag spec — the ONE place logical type args become an `EonColumnSpec`. */
|
|
18
|
+
function columnSpec(name, kind, length = null, precision = null, scale = null) {
|
|
19
|
+
return { name, kind, length, precision, scale };
|
|
20
|
+
}
|
|
21
|
+
/** Build the type portion — the ONE place logical type args become an `EonType`. */
|
|
22
|
+
function makeType(kind, length = null, precision = null, scale = null) {
|
|
23
|
+
return { kind, length, precision, scale };
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The thin column/tag surface shared by every builder: only column-type methods
|
|
27
|
+
* (+ length/precision/scale). No `defaultTo`/`primary`/`unique` — TDengine has
|
|
28
|
+
* no analogue. Each method appends a column via `#add` and returns whatever that
|
|
29
|
+
* hook returns (a tag-handle for stables, `void` for basic tables).
|
|
30
|
+
*/
|
|
31
|
+
class ColumnMethods {
|
|
32
|
+
timestamp(name) {
|
|
33
|
+
return this.add(columnSpec(name, "timestamp"));
|
|
34
|
+
}
|
|
35
|
+
int(name) {
|
|
36
|
+
return this.add(columnSpec(name, "int"));
|
|
37
|
+
}
|
|
38
|
+
bigInteger(name) {
|
|
39
|
+
return this.add(columnSpec(name, "bigInt"));
|
|
40
|
+
}
|
|
41
|
+
float(name) {
|
|
42
|
+
return this.add(columnSpec(name, "float"));
|
|
43
|
+
}
|
|
44
|
+
double(name) {
|
|
45
|
+
return this.add(columnSpec(name, "double"));
|
|
46
|
+
}
|
|
47
|
+
bool(name) {
|
|
48
|
+
return this.add(columnSpec(name, "bool"));
|
|
49
|
+
}
|
|
50
|
+
varchar(name, length) {
|
|
51
|
+
return this.add(columnSpec(name, "varchar", length));
|
|
52
|
+
}
|
|
53
|
+
nchar(name, length) {
|
|
54
|
+
return this.add(columnSpec(name, "nchar", length));
|
|
55
|
+
}
|
|
56
|
+
binary(name, length) {
|
|
57
|
+
return this.add(columnSpec(name, "varbinary", length));
|
|
58
|
+
}
|
|
59
|
+
decimal(name, precision, scale) {
|
|
60
|
+
return this.add(columnSpec(name, "decimal", null, precision, scale ?? null));
|
|
61
|
+
}
|
|
62
|
+
json(name) {
|
|
63
|
+
return this.add(columnSpec(name, "json"));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The no-name type surface for an `ALTER STABLE` add/modify change: the column
|
|
68
|
+
* name is already fixed (by `addColumn(name)` etc.), so these methods take ONLY
|
|
69
|
+
* the type arguments and finalize the change.
|
|
70
|
+
*/
|
|
71
|
+
class TypeMethods {
|
|
72
|
+
timestamp() {
|
|
73
|
+
return this.emit(makeType("timestamp"));
|
|
74
|
+
}
|
|
75
|
+
int() {
|
|
76
|
+
return this.emit(makeType("int"));
|
|
77
|
+
}
|
|
78
|
+
bigInteger() {
|
|
79
|
+
return this.emit(makeType("bigInt"));
|
|
80
|
+
}
|
|
81
|
+
float() {
|
|
82
|
+
return this.emit(makeType("float"));
|
|
83
|
+
}
|
|
84
|
+
double() {
|
|
85
|
+
return this.emit(makeType("double"));
|
|
86
|
+
}
|
|
87
|
+
bool() {
|
|
88
|
+
return this.emit(makeType("bool"));
|
|
89
|
+
}
|
|
90
|
+
varchar(length) {
|
|
91
|
+
return this.emit(makeType("varchar", length));
|
|
92
|
+
}
|
|
93
|
+
nchar(length) {
|
|
94
|
+
return this.emit(makeType("nchar", length));
|
|
95
|
+
}
|
|
96
|
+
binary(length) {
|
|
97
|
+
return this.emit(makeType("varbinary", length));
|
|
98
|
+
}
|
|
99
|
+
decimal(precision, scale) {
|
|
100
|
+
return this.emit(makeType("decimal", null, precision, scale ?? null));
|
|
101
|
+
}
|
|
102
|
+
json() {
|
|
103
|
+
return this.emit(makeType("json"));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** Fluent builder for `CREATE STABLE` columns + tags (ts-first is enforced in Rust). */
|
|
107
|
+
export class StableBuilder extends ColumnMethods {
|
|
108
|
+
#columns = [];
|
|
109
|
+
#tags = [];
|
|
110
|
+
add(spec) {
|
|
111
|
+
this.#columns.push(spec);
|
|
112
|
+
return {
|
|
113
|
+
tag: () => {
|
|
114
|
+
// Idempotent: a second `.tag()` on the same handle finds the spec
|
|
115
|
+
// already re-homed (i < 0) and must NOT push a duplicate tag.
|
|
116
|
+
const i = this.#columns.indexOf(spec);
|
|
117
|
+
if (i >= 0) {
|
|
118
|
+
this.#columns.splice(i, 1);
|
|
119
|
+
this.#tags.push(spec);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** @internal */
|
|
125
|
+
columns() {
|
|
126
|
+
return this.#columns;
|
|
127
|
+
}
|
|
128
|
+
/** @internal */
|
|
129
|
+
tags() {
|
|
130
|
+
return this.#tags;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** Fluent builder for a basic (non-super) table — same columns, no tags. */
|
|
134
|
+
export class BasicTableBuilder extends ColumnMethods {
|
|
135
|
+
#columns = [];
|
|
136
|
+
add(spec) {
|
|
137
|
+
this.#columns.push(spec);
|
|
138
|
+
}
|
|
139
|
+
/** @internal */
|
|
140
|
+
columns() {
|
|
141
|
+
return this.#columns;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
class AlterTypeSetterImpl extends TypeMethods {
|
|
145
|
+
#record;
|
|
146
|
+
constructor(record) {
|
|
147
|
+
super();
|
|
148
|
+
this.#record = record;
|
|
149
|
+
}
|
|
150
|
+
emit(type) {
|
|
151
|
+
this.#record(type);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** Fluent builder for `ALTER STABLE` — one method per TDengine change op. */
|
|
155
|
+
export class AlterStableBuilder {
|
|
156
|
+
#changes = [];
|
|
157
|
+
addColumn(name) {
|
|
158
|
+
return new AlterTypeSetterImpl((type) => this.#changes.push({ op: "addColumn", name, type }));
|
|
159
|
+
}
|
|
160
|
+
modifyColumn(name) {
|
|
161
|
+
return new AlterTypeSetterImpl((type) => this.#changes.push({ op: "modifyColumn", name, type }));
|
|
162
|
+
}
|
|
163
|
+
dropColumn(name) {
|
|
164
|
+
this.#changes.push({ op: "dropColumn", name });
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
addTag(name) {
|
|
168
|
+
return new AlterTypeSetterImpl((type) => this.#changes.push({ op: "addTag", name, type }));
|
|
169
|
+
}
|
|
170
|
+
modifyTag(name) {
|
|
171
|
+
return new AlterTypeSetterImpl((type) => this.#changes.push({ op: "modifyTag", name, type }));
|
|
172
|
+
}
|
|
173
|
+
dropTag(name) {
|
|
174
|
+
this.#changes.push({ op: "dropTag", name });
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
renameTag(from, to) {
|
|
178
|
+
this.#changes.push({ op: "renameTag", from, to });
|
|
179
|
+
return this;
|
|
180
|
+
}
|
|
181
|
+
/** @internal */
|
|
182
|
+
changes() {
|
|
183
|
+
return this.#changes;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/** Map an `alterDatabase` option key to its Rust-side option name. */
|
|
187
|
+
const ALTER_DB_OPTION_NAMES = {
|
|
188
|
+
keep: "keep",
|
|
189
|
+
buffer: "buffer",
|
|
190
|
+
walLevel: "wal_level",
|
|
191
|
+
cachemodel: "cachemodel",
|
|
192
|
+
replica: "replica",
|
|
193
|
+
minrows: "minrows",
|
|
194
|
+
};
|
|
195
|
+
export class EonSchema {
|
|
196
|
+
#statements = [];
|
|
197
|
+
#push(spec) {
|
|
198
|
+
const { statements } = compileStatementNative(spec, "tdengine");
|
|
199
|
+
this.#statements.push(...statements);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* `CREATE STABLE`. Defaults to `IF NOT EXISTS` (idempotent DDL — the mitigation
|
|
203
|
+
* for TDengine's non-transactional migrations, AC6). Pass `keep` for retention.
|
|
204
|
+
*/
|
|
205
|
+
createStable(name, callback, options = {}) {
|
|
206
|
+
const builder = new StableBuilder();
|
|
207
|
+
callback(builder);
|
|
208
|
+
const spec = {
|
|
209
|
+
kind: "createStable",
|
|
210
|
+
name,
|
|
211
|
+
columns: builder.columns(),
|
|
212
|
+
tags: builder.tags(),
|
|
213
|
+
ifNotExists: options.ifNotExists ?? true,
|
|
214
|
+
...(options.keep !== undefined ? { keep: options.keep } : {}),
|
|
215
|
+
};
|
|
216
|
+
this.#push(spec);
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
/** `ALTER STABLE` → one statement per change. */
|
|
220
|
+
alterStable(name, callback) {
|
|
221
|
+
const builder = new AlterStableBuilder();
|
|
222
|
+
callback(builder);
|
|
223
|
+
const spec = {
|
|
224
|
+
kind: "alterStable",
|
|
225
|
+
name,
|
|
226
|
+
changes: builder.changes(),
|
|
227
|
+
};
|
|
228
|
+
this.#push(spec);
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
/** `DROP STABLE IF EXISTS`. */
|
|
232
|
+
dropStable(name) {
|
|
233
|
+
this.#push({ kind: "dropStable", name, ifExists: true });
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
/** `CREATE DATABASE IF NOT EXISTS` with optional retention/storage options. */
|
|
237
|
+
createDatabase(name, options = {}) {
|
|
238
|
+
this.#push({
|
|
239
|
+
kind: "createDatabase",
|
|
240
|
+
name,
|
|
241
|
+
ifNotExists: true,
|
|
242
|
+
...options,
|
|
243
|
+
});
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* `ALTER DATABASE` — exactly ONE option per call (TDengine restriction).
|
|
248
|
+
* Throws if zero or more than one option key is provided.
|
|
249
|
+
*/
|
|
250
|
+
alterDatabase(name, options) {
|
|
251
|
+
const keys = [
|
|
252
|
+
"keep",
|
|
253
|
+
"buffer",
|
|
254
|
+
"walLevel",
|
|
255
|
+
"cachemodel",
|
|
256
|
+
"replica",
|
|
257
|
+
"minrows",
|
|
258
|
+
];
|
|
259
|
+
const set = keys.filter((k) => options[k] !== undefined);
|
|
260
|
+
const key = set[0];
|
|
261
|
+
if (set.length !== 1 || key === undefined) {
|
|
262
|
+
throw new Error(`[E_EON_ALTER_DB_ONE_OPTION] alterDatabase('${name}', …) requires exactly one option, got ${set.length}`);
|
|
263
|
+
}
|
|
264
|
+
const value = options[key];
|
|
265
|
+
if (value === undefined) {
|
|
266
|
+
throw new Error(`[E_EON_ALTER_DB_ONE_OPTION] alterDatabase('${name}', …) option '${key}' has no value`);
|
|
267
|
+
}
|
|
268
|
+
const spec = {
|
|
269
|
+
kind: "alterDatabase",
|
|
270
|
+
name,
|
|
271
|
+
option: ALTER_DB_OPTION_NAMES[key],
|
|
272
|
+
value,
|
|
273
|
+
};
|
|
274
|
+
this.#push(spec);
|
|
275
|
+
return this;
|
|
276
|
+
}
|
|
277
|
+
/** `CREATE TABLE IF NOT EXISTS` — a basic (non-super) table, no tags. */
|
|
278
|
+
createTable(name, callback) {
|
|
279
|
+
const builder = new BasicTableBuilder();
|
|
280
|
+
callback(builder);
|
|
281
|
+
const spec = {
|
|
282
|
+
kind: "createTable",
|
|
283
|
+
name,
|
|
284
|
+
columns: builder.columns(),
|
|
285
|
+
ifNotExists: true,
|
|
286
|
+
};
|
|
287
|
+
this.#push(spec);
|
|
288
|
+
return this;
|
|
289
|
+
}
|
|
290
|
+
/** `DROP TABLE IF EXISTS`. */
|
|
291
|
+
dropTable(name) {
|
|
292
|
+
this.#push({ kind: "dropTable", name, ifExists: true });
|
|
293
|
+
return this;
|
|
294
|
+
}
|
|
295
|
+
/** Queue a raw SQL statement verbatim (an escape hatch for options not modelled above). */
|
|
296
|
+
raw(sql) {
|
|
297
|
+
this.#statements.push(sql);
|
|
298
|
+
return this;
|
|
299
|
+
}
|
|
300
|
+
/** Clear the buffer (called before each `up()`/`down()` run). */
|
|
301
|
+
reset() {
|
|
302
|
+
this.#statements = [];
|
|
303
|
+
}
|
|
304
|
+
/** The compiled SQL statements queued so far. */
|
|
305
|
+
toSQL() {
|
|
306
|
+
return [...this.#statements];
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
//# sourceMappingURL=EonSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EonSchema.js","sourceRoot":"","sources":["../../src/schema/EonSchema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAY5D,6FAA6F;AAC7F,SAAS,UAAU,CAClB,IAAY,EACZ,IAAY,EACZ,SAAwB,IAAI,EAC5B,YAA2B,IAAI,EAC/B,QAAuB,IAAI;IAE3B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACjD,CAAC;AAKD,oFAAoF;AACpF,SAAS,QAAQ,CAChB,IAAY,EACZ,SAAwB,IAAI,EAC5B,YAA2B,IAAI,EAC/B,QAAuB,IAAI;IAE3B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAC3C,CAAC;AAED;;;;;GAKG;AACH,MAAe,aAAa;IAG3B,SAAS,CAAC,IAAY;QACrB,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;IAChD,CAAC;IACD,GAAG,CAAC,IAAY;QACf,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EA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,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,iDAAiD;IACjD,KAAK;QACJ,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IAC9B,CAAC;CACD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Migration` — extend this to author a versioned eon (TDengine) migration.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors atlas `Migration` (`schema/Migration.ts`): `up()`/`down()` drive a
|
|
5
|
+
* fluent `EonSchema`, and `getUpSQL()`/`getDownSQL()` replay the callback to
|
|
6
|
+
* collect the compiled SQL. Single-dialect (TDengine) so — unlike atlas — the
|
|
7
|
+
* constructor takes NO dialect argument, and there is no `now()`/`defaultTo`
|
|
8
|
+
* helper (TDengine columns have no `DEFAULT`).
|
|
9
|
+
*
|
|
10
|
+
* TDengine caveat (AC6): DDL is non-transactional and some operations are
|
|
11
|
+
* irreversible (a `MODIFY` length-extension cannot be un-extended, a dropped
|
|
12
|
+
* column's data is gone) — `down()` is best-effort. Prefer idempotent DDL
|
|
13
|
+
* (`IF (NOT) EXISTS`, the `EonSchema` default) so a partially-applied migration
|
|
14
|
+
* re-runs cleanly.
|
|
15
|
+
*
|
|
16
|
+
* import { Migration } from "@c9up/eon";
|
|
17
|
+
*
|
|
18
|
+
* export default class CreateMeters extends Migration {
|
|
19
|
+
* up() {
|
|
20
|
+
* this.schema.createDatabase("metrics", { keep: "90d", duration: "10d" });
|
|
21
|
+
* this.schema.createStable("meters", (t) => {
|
|
22
|
+
* t.timestamp("ts");
|
|
23
|
+
* t.float("current");
|
|
24
|
+
* t.int("groupid").tag();
|
|
25
|
+
* });
|
|
26
|
+
* }
|
|
27
|
+
* down() {
|
|
28
|
+
* this.schema.dropStable("meters");
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
*/
|
|
32
|
+
import { EonSchema } from "./EonSchema.js";
|
|
33
|
+
export declare abstract class Migration {
|
|
34
|
+
readonly schema: EonSchema;
|
|
35
|
+
constructor();
|
|
36
|
+
/** Apply the migration. */
|
|
37
|
+
abstract up(): Promise<void> | void;
|
|
38
|
+
/** Reverse the migration (best-effort on TDengine — see class docs). */
|
|
39
|
+
abstract down(): Promise<void> | void;
|
|
40
|
+
/** Queue a raw SQL statement verbatim (escape hatch for un-modelled DDL). */
|
|
41
|
+
raw(sql: string): void;
|
|
42
|
+
/** Compile the SQL statements this migration's `up()` produces. */
|
|
43
|
+
getUpSQL(): Promise<string[]>;
|
|
44
|
+
/** Compile the SQL statements this migration's `down()` produces. */
|
|
45
|
+
getDownSQL(): Promise<string[]>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=Migration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration.d.ts","sourceRoot":"","sources":["../../src/schema/Migration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,8BAAsB,SAAS;IAC9B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;;IAM3B,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAEnC,wEAAwE;IACxE,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAErC,6EAA6E;IAC7E,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAItB,mEAAmE;IAC7D,QAAQ,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAMnC,qEAAqE;IAC/D,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAKrC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Migration` — extend this to author a versioned eon (TDengine) migration.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors atlas `Migration` (`schema/Migration.ts`): `up()`/`down()` drive a
|
|
5
|
+
* fluent `EonSchema`, and `getUpSQL()`/`getDownSQL()` replay the callback to
|
|
6
|
+
* collect the compiled SQL. Single-dialect (TDengine) so — unlike atlas — the
|
|
7
|
+
* constructor takes NO dialect argument, and there is no `now()`/`defaultTo`
|
|
8
|
+
* helper (TDengine columns have no `DEFAULT`).
|
|
9
|
+
*
|
|
10
|
+
* TDengine caveat (AC6): DDL is non-transactional and some operations are
|
|
11
|
+
* irreversible (a `MODIFY` length-extension cannot be un-extended, a dropped
|
|
12
|
+
* column's data is gone) — `down()` is best-effort. Prefer idempotent DDL
|
|
13
|
+
* (`IF (NOT) EXISTS`, the `EonSchema` default) so a partially-applied migration
|
|
14
|
+
* re-runs cleanly.
|
|
15
|
+
*
|
|
16
|
+
* import { Migration } from "@c9up/eon";
|
|
17
|
+
*
|
|
18
|
+
* export default class CreateMeters extends Migration {
|
|
19
|
+
* up() {
|
|
20
|
+
* this.schema.createDatabase("metrics", { keep: "90d", duration: "10d" });
|
|
21
|
+
* this.schema.createStable("meters", (t) => {
|
|
22
|
+
* t.timestamp("ts");
|
|
23
|
+
* t.float("current");
|
|
24
|
+
* t.int("groupid").tag();
|
|
25
|
+
* });
|
|
26
|
+
* }
|
|
27
|
+
* down() {
|
|
28
|
+
* this.schema.dropStable("meters");
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
*/
|
|
32
|
+
import { EonSchema } from "./EonSchema.js";
|
|
33
|
+
export class Migration {
|
|
34
|
+
schema;
|
|
35
|
+
constructor() {
|
|
36
|
+
this.schema = new EonSchema();
|
|
37
|
+
}
|
|
38
|
+
/** Queue a raw SQL statement verbatim (escape hatch for un-modelled DDL). */
|
|
39
|
+
raw(sql) {
|
|
40
|
+
this.schema.raw(sql);
|
|
41
|
+
}
|
|
42
|
+
/** Compile the SQL statements this migration's `up()` produces. */
|
|
43
|
+
async getUpSQL() {
|
|
44
|
+
this.schema.reset();
|
|
45
|
+
await this.up();
|
|
46
|
+
return this.schema.toSQL();
|
|
47
|
+
}
|
|
48
|
+
/** Compile the SQL statements this migration's `down()` produces. */
|
|
49
|
+
async getDownSQL() {
|
|
50
|
+
this.schema.reset();
|
|
51
|
+
await this.down();
|
|
52
|
+
return this.schema.toSQL();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=Migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration.js","sourceRoot":"","sources":["../../src/schema/Migration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,OAAgB,SAAS;IACrB,MAAM,CAAY;IAE3B;QACC,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;IAC/B,CAAC;IAQD,6EAA6E;IAC7E,GAAG,CAAC,GAAW;QACd,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACtB,CAAC;IAED,mEAAmE;IACnE,KAAK,CAAC,QAAQ;QACb,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,MAAM,IAAI,CAAC,EAAE,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,qEAAqE;IACrE,KAAK,CAAC,UAAU;QACf,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assemble a `CreateStableSpec` from a decorated super-table class.
|
|
3
|
+
*
|
|
4
|
+
* Reads schema through the metadata getters ONLY (never `key in instance` — the
|
|
5
|
+
* `declare` pitfall, memory `project_atlas_declare_hydration`), places the
|
|
6
|
+
* timestamp column first (TDengine's PK rule), and normalises each logical type
|
|
7
|
+
* string to the compiler kind via `TYPE_KIND_MAP`. Mirror of atlas
|
|
8
|
+
* `TableBuilder.toStatements` spec-build.
|
|
9
|
+
*/
|
|
10
|
+
import { type CreateStableSpec } from "./CreateStableSpec.js";
|
|
11
|
+
/** A decorated super-table class. Every constructor carries `.name` (`Function.name`). */
|
|
12
|
+
export type SuperTableClass = (abstract new (...args: never[]) => object) & {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
};
|
|
15
|
+
/** Resolve the super-table name for a class, or throw if it is undecorated. */
|
|
16
|
+
export declare function requireSuperTableName(EntityClass: SuperTableClass): string;
|
|
17
|
+
/**
|
|
18
|
+
* The stable's physical column order: timestamp first (TDengine's PK rule), then
|
|
19
|
+
* declaration order. The STMT columnar bind is POSITIONAL (the connector's
|
|
20
|
+
* prepare template omits the value-column list), so its bind order MUST match the
|
|
21
|
+
* order the STABLE was created with. Both `compileCreateStableSpec` (the DDL) and
|
|
22
|
+
* `SuperTableRepository`'s ingest plan derive their order from THIS one function
|
|
23
|
+
* so the two can never silently drift apart and write values into wrong columns.
|
|
24
|
+
*/
|
|
25
|
+
export declare function orderTimestampFirst<T extends {
|
|
26
|
+
propertyKey: string;
|
|
27
|
+
}>(columns: readonly T[], tsColumn: T, tsProperty: string): T[];
|
|
28
|
+
/**
|
|
29
|
+
* Build the `createStable` spec (ts column first). `ifNotExists` defaults to
|
|
30
|
+
* `false`; `syncSuperTable` overrides it to `true`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function compileCreateStableSpec(EntityClass: SuperTableClass): CreateStableSpec;
|
|
33
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/schema/compile.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAUH,OAAO,EACN,KAAK,gBAAgB,EAGrB,MAAM,uBAAuB,CAAC;AAE/B,0FAA0F;AAC1F,MAAM,MAAM,eAAe,GAAG,CAAC,QAAQ,MACtC,GAAG,IAAI,EAAE,KAAK,EAAE,KACZ,MAAM,CAAC,GAAG;IACd,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,+EAA+E;AAC/E,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,eAAe,GAAG,MAAM,CAU1E;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,EACpE,OAAO,EAAE,SAAS,CAAC,EAAE,EACrB,QAAQ,EAAE,CAAC,EACX,UAAU,EAAE,MAAM,GAChB,CAAC,EAAE,CAEL;AAmBD;;;GAGG;AACH,wBAAgB,uBAAuB,CACtC,WAAW,EAAE,eAAe,GAC1B,gBAAgB,CAyBlB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assemble a `CreateStableSpec` from a decorated super-table class.
|
|
3
|
+
*
|
|
4
|
+
* Reads schema through the metadata getters ONLY (never `key in instance` — the
|
|
5
|
+
* `declare` pitfall, memory `project_atlas_declare_hydration`), places the
|
|
6
|
+
* timestamp column first (TDengine's PK rule), and normalises each logical type
|
|
7
|
+
* string to the compiler kind via `TYPE_KIND_MAP`. Mirror of atlas
|
|
8
|
+
* `TableBuilder.toStatements` spec-build.
|
|
9
|
+
*/
|
|
10
|
+
import { getColumnMetadata, getSuperTableMetadata, getTagMetadata, getTimestampColumn, } from "../decorators/superTable.js";
|
|
11
|
+
import { TYPE_KIND_MAP, } from "./CreateStableSpec.js";
|
|
12
|
+
/** Resolve the super-table name for a class, or throw if it is undecorated. */
|
|
13
|
+
export function requireSuperTableName(EntityClass) {
|
|
14
|
+
const meta = getSuperTableMetadata(EntityClass);
|
|
15
|
+
if (!meta) {
|
|
16
|
+
const label = EntityClass.name.length > 0 ? EntityClass.name : "the given class";
|
|
17
|
+
throw new Error(`[E_EON_NOT_A_SUPERTABLE] ${label} is not decorated with @SuperTable`);
|
|
18
|
+
}
|
|
19
|
+
return meta.name;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The stable's physical column order: timestamp first (TDengine's PK rule), then
|
|
23
|
+
* declaration order. The STMT columnar bind is POSITIONAL (the connector's
|
|
24
|
+
* prepare template omits the value-column list), so its bind order MUST match the
|
|
25
|
+
* order the STABLE was created with. Both `compileCreateStableSpec` (the DDL) and
|
|
26
|
+
* `SuperTableRepository`'s ingest plan derive their order from THIS one function
|
|
27
|
+
* so the two can never silently drift apart and write values into wrong columns.
|
|
28
|
+
*/
|
|
29
|
+
export function orderTimestampFirst(columns, tsColumn, tsProperty) {
|
|
30
|
+
return [tsColumn, ...columns.filter((c) => c.propertyKey !== tsProperty)];
|
|
31
|
+
}
|
|
32
|
+
function toColumnSpec(meta) {
|
|
33
|
+
const logical = (meta.type ?? "").toLowerCase();
|
|
34
|
+
const kind = TYPE_KIND_MAP[logical];
|
|
35
|
+
if (!kind) {
|
|
36
|
+
throw new Error(`[E_EON_TYPE] column/tag '${meta.propertyKey}' has an unknown or missing type '${meta.type ?? ""}'`);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
name: meta.propertyKey,
|
|
40
|
+
kind,
|
|
41
|
+
length: meta.length ?? null,
|
|
42
|
+
precision: meta.precision ?? null,
|
|
43
|
+
scale: meta.scale ?? null,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Build the `createStable` spec (ts column first). `ifNotExists` defaults to
|
|
48
|
+
* `false`; `syncSuperTable` overrides it to `true`.
|
|
49
|
+
*/
|
|
50
|
+
export function compileCreateStableSpec(EntityClass) {
|
|
51
|
+
const name = requireSuperTableName(EntityClass);
|
|
52
|
+
const tsProperty = getTimestampColumn(EntityClass);
|
|
53
|
+
if (!tsProperty) {
|
|
54
|
+
throw new Error(`[E_EON_NO_TIMESTAMP] super-table '${name}' has no @Timestamp column`);
|
|
55
|
+
}
|
|
56
|
+
const columns = getColumnMetadata(EntityClass);
|
|
57
|
+
const tsColumn = columns.find((c) => c.propertyKey === tsProperty);
|
|
58
|
+
if (!tsColumn) {
|
|
59
|
+
throw new Error(`[E_EON_NO_TIMESTAMP] super-table '${name}' @Timestamp column '${tsProperty}' is not registered`);
|
|
60
|
+
}
|
|
61
|
+
const orderedColumns = orderTimestampFirst(columns, tsColumn, tsProperty);
|
|
62
|
+
return {
|
|
63
|
+
kind: "createStable",
|
|
64
|
+
name,
|
|
65
|
+
columns: orderedColumns.map(toColumnSpec),
|
|
66
|
+
tags: getTagMetadata(EntityClass).map(toColumnSpec),
|
|
67
|
+
ifNotExists: false,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/schema/compile.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAGN,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,kBAAkB,GAClB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAGN,aAAa,GACb,MAAM,uBAAuB,CAAC;AAS/B,+EAA+E;AAC/E,MAAM,UAAU,qBAAqB,CAAC,WAA4B;IACjE,MAAM,IAAI,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAC;IAChD,IAAI,CAAC,IAAI,EAAE,CAAC;QACX,MAAM,KAAK,GACV,WAAW,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC;QACpE,MAAM,IAAI,KAAK,CACd,4BAA4B,KAAK,oCAAoC,CACrE,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC;AAClB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAClC,OAAqB,EACrB,QAAW,EACX,U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,CACd,qCAAqC,IAAI,wBAAwB,UAAU,qBAAqB,CAChG,CAAC;IACH,CAAC;IACD,MAAM,cAAc,GAAG,mBAAmB,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IAE1E,OAAO;QACN,IAAI,EAAE,cAAc;QACpB,IAAI;QACJ,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC;QACzC,IAAI,EAAE,cAAc,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC;QACnD,WAAW,EAAE,KAAK;KAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema facade — drive TDengine DDL from decorator metadata through a live
|
|
3
|
+
* `EonConnection`. Agnostic leaf: takes the connection structurally, never
|
|
4
|
+
* imports `@c9up/ream`.
|
|
5
|
+
*
|
|
6
|
+
* Every statement is compiled in Rust (`compileStatementNative`) and run through
|
|
7
|
+
* the literal-only `EonConnection.exec` (58.2 D3). Child-table creation renders
|
|
8
|
+
* its tag values as inlined SQL literals (`literal: true`, D4) so `exec` can run
|
|
9
|
+
* it directly; the `?`-bound STMT form lands with ingest in 58.4.
|
|
10
|
+
*/
|
|
11
|
+
import type { EonConnection } from "../connection/EonConnection.js";
|
|
12
|
+
import { type SuperTableClass } from "./compile.js";
|
|
13
|
+
/** Create the super-table for a decorated class (`CREATE STABLE IF NOT EXISTS`). */
|
|
14
|
+
export declare function syncSuperTable(conn: EonConnection, EntityClass: SuperTableClass): Promise<void>;
|
|
15
|
+
/** Options for {@link createChildTable}: identify the stable by name or class. */
|
|
16
|
+
export interface CreateChildTableOptions {
|
|
17
|
+
stable?: string;
|
|
18
|
+
EntityClass?: SuperTableClass;
|
|
19
|
+
name: string;
|
|
20
|
+
tags: unknown[];
|
|
21
|
+
ifNotExists?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create an explicit child table bound to its super-table's tag values
|
|
25
|
+
* (`CREATE TABLE name USING stable TAGS (...)`). Tag values are inlined as typed
|
|
26
|
+
* SQL literals (D4).
|
|
27
|
+
*/
|
|
28
|
+
export declare function createChildTable(conn: EonConnection, options: CreateChildTableOptions): Promise<void>;
|
|
29
|
+
/** Drop the super-table for a decorated class (`DROP STABLE IF EXISTS`). */
|
|
30
|
+
export declare function dropSuperTable(conn: EonConnection, EntityClass: SuperTableClass): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* A deterministic child-table name for a stable + tag-set, so the same tags
|
|
33
|
+
* always map to the same child (idempotent create, stable routing for 58.4
|
|
34
|
+
* ingest). Dependency-free FNV-1a — no `crypto`, no npm dep (D6). Pass an
|
|
35
|
+
* explicit `name` to {@link createChildTable} to override.
|
|
36
|
+
*/
|
|
37
|
+
export declare function childTableName(stableOrEntity: string | SuperTableClass, tagValues: unknown[]): string;
|
|
38
|
+
/**
|
|
39
|
+
* A tag value's stable string form for the child-name key. `JSON.stringify`
|
|
40
|
+
* throws on a `bigint` (`TypeError: Do not know how to serialize a BigInt`),
|
|
41
|
+
* which would surface as an opaque crash for any BIGINT `@Tag`; render bigints
|
|
42
|
+
* explicitly so every tag type maps to a deterministic, typed-out string.
|
|
43
|
+
*/
|
|
44
|
+
export declare function stringifyTagValue(value: unknown): string;
|
|
45
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/schema/sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAMpE,OAAO,EAGN,KAAK,eAAe,EACpB,MAAM,cAAc,CAAC;AAUtB,oFAAoF;AACpF,wBAAgB,cAAc,CAC7B,IAAI,EAAE,aAAa,EACnB,WAAW,EAAE,eAAe,GAC1B,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,kFAAkF;AAClF,MAAM,WAAW,uBAAuB;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC/B,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,uBAAuB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAWf;AAED,4EAA4E;AAC5E,wBAAgB,cAAc,CAC7B,IAAI,EAAE,aAAa,EACnB,WAAW,EAAE,eAAe,GAC1B,OAAO,CAAC,IAAI,CAAC,CAOf;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC7B,cAAc,EAAE,MAAM,GAAG,eAAe,EACxC,SAAS,EAAE,OAAO,EAAE,GAClB,MAAM,CAOR;AAcD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAGxD"}
|