@mateusseiboth/ember-orm 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/LICENSE +21 -0
- package/README.md +125 -0
- package/dist/cli/bin.cjs +3265 -0
- package/dist/cli/bin.cjs.map +1 -0
- package/dist/cli/bin.d.cts +1 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +3241 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/client/index.cjs +2434 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +2 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +2396 -0
- package/dist/client/index.js.map +1 -0
- package/dist/editor.cjs +1113 -0
- package/dist/editor.cjs.map +1 -0
- package/dist/editor.d.cts +22 -0
- package/dist/editor.d.ts +22 -0
- package/dist/editor.js +1077 -0
- package/dist/editor.js.map +1 -0
- package/dist/index-0lWi8TMM.d.ts +72 -0
- package/dist/index-BSXZjDUd.d.ts +459 -0
- package/dist/index-CKqkQhZx.d.cts +459 -0
- package/dist/index-CMeqhmVc.d.cts +72 -0
- package/dist/index-D0xIdtCl.d.cts +145 -0
- package/dist/index-D0xIdtCl.d.ts +145 -0
- package/dist/index.cjs +5013 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +288 -0
- package/dist/index.d.ts +288 -0
- package/dist/index.js +4935 -0
- package/dist/index.js.map +1 -0
- package/package.json +75 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { S as SchemaDocument, M as ModelNode, F as FieldNode } from './index-D0xIdtCl.cjs';
|
|
2
|
+
export { A as AttributeArgValue, D as DatasourceNode, c as DefaultValue, E as EnumNode, d as FieldKind, G as GeneratorNode, I as IndexNode, N as NativeType, R as ReferentialAction, e as RelationInfo, a as SCALAR_TYPES, b as ScalarType, U as UniqueIndex, f as emptySchema, g as fieldColumn, h as findEnum, i as findModel, j as idFields, m as modelTable, r as relationFields, s as scalarFields } from './index-D0xIdtCl.cjs';
|
|
3
|
+
export { D as DatabaseError, E as EmberError, L as LoadedSchema, Q as QueryValidationError, R as RecordNotFoundError, S as SchemaParseError, a as SchemaValidationError, U as UniqueConstraintError, d as findSchemaPath, l as loadSchema, p as parseAndValidate, b as parseSchema, c as printSchema, r as resolveDatasourceUrl, v as validateSchema } from './index-CMeqhmVc.cjs';
|
|
4
|
+
import { S as SqlDriver, C as ConnectionConfig, D as DriverOptions, T as TransactionContext, a as TransactionOptions, b as SqlValue, c as SqlDialect } from './index-CKqkQhZx.cjs';
|
|
5
|
+
export { A as AggregateArgs, d as ClientOptions, e as CreateArgs, f as DeleteArgs, E as EmberClientBase, F as FindManyArgs, g as FindUniqueArgs, h as FirebirdDialect, G as GroupByArgs, I as IncludeInput, i as IsolationLevel, M as ModelDelegate, O as OrderByInput, Q as QueryEngine, j as SelectInput, U as UpdateArgs, k as UpsertArgs, W as WhereInput, l as createClient } from './index-CKqkQhZx.cjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Firebird implementation of SqlDriver. Wraps node-firebird's callback API in
|
|
9
|
+
* promises, manages a connection pool, and guarantees every query executes
|
|
10
|
+
* inside a transaction. Nested `transaction()` calls reuse the active one via
|
|
11
|
+
* AsyncLocalStorage so `client.$transaction(...)` composes naturally.
|
|
12
|
+
*/
|
|
13
|
+
declare class FirebirdDriver implements SqlDriver {
|
|
14
|
+
private pool;
|
|
15
|
+
private readonly options;
|
|
16
|
+
private readonly poolMax;
|
|
17
|
+
private readonly onQuery?;
|
|
18
|
+
private readonly activeTx;
|
|
19
|
+
constructor(config: ConnectionConfig, driverOptions?: DriverOptions);
|
|
20
|
+
connect(): Promise<void>;
|
|
21
|
+
disconnect(): Promise<void>;
|
|
22
|
+
transaction<T>(fn: (tx: TransactionContext) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
23
|
+
private acquire;
|
|
24
|
+
private begin;
|
|
25
|
+
private runOnTransaction;
|
|
26
|
+
private commit;
|
|
27
|
+
private safeRollback;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Parse a Firebird connection URL into a ConnectionConfig.
|
|
32
|
+
*
|
|
33
|
+
* Supported forms:
|
|
34
|
+
* firebird://user:password@host:port/path/to/database.fdb?role=RDB$ADMIN
|
|
35
|
+
* firebird://SYSDBA:masterkey@localhost:3050//var/lib/firebird/data/app.fdb
|
|
36
|
+
*
|
|
37
|
+
* The path after the host is treated as the absolute database path. A leading
|
|
38
|
+
* double slash (`//var/...`) yields an absolute POSIX path; a single slash with
|
|
39
|
+
* a Windows drive (`/C:/...`) is normalized too.
|
|
40
|
+
*/
|
|
41
|
+
declare function parseConnectionUrl(url: string): ConnectionConfig;
|
|
42
|
+
declare function buildConnectionUrl(config: ConnectionConfig): string;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Factory that builds a driver from either a connection URL or an explicit
|
|
46
|
+
* config object. Centralizing creation here keeps the client decoupled from a
|
|
47
|
+
* concrete driver class (Factory pattern / DIP).
|
|
48
|
+
*/
|
|
49
|
+
declare function createDriver(source: string | ConnectionConfig, options?: DriverOptions): SqlDriver;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* An accumulating SQL fragment that keeps text and bound parameters together,
|
|
53
|
+
* so values are always parameterized (`?`) and never string-interpolated.
|
|
54
|
+
* This is the core defense against SQL injection in the query layer.
|
|
55
|
+
*/
|
|
56
|
+
declare class Sql {
|
|
57
|
+
private parts;
|
|
58
|
+
readonly params: SqlValue[];
|
|
59
|
+
static raw(text: string): Sql;
|
|
60
|
+
static value(value: SqlValue): Sql;
|
|
61
|
+
static join(fragments: Sql[], separator: string): Sql;
|
|
62
|
+
/** Append raw, trusted SQL text (keywords, already-escaped identifiers). */
|
|
63
|
+
push(text: string): this;
|
|
64
|
+
/** Append a `?` placeholder bound to `value`. */
|
|
65
|
+
bind(value: SqlValue): this;
|
|
66
|
+
/** Append a comma-separated list of placeholders bound to `values`. */
|
|
67
|
+
bindList(values: readonly SqlValue[]): this;
|
|
68
|
+
/** Merge another fragment (text + params) into this one. */
|
|
69
|
+
append(other: Sql): this;
|
|
70
|
+
get text(): string;
|
|
71
|
+
isEmpty(): boolean;
|
|
72
|
+
toQuery(): {
|
|
73
|
+
sql: string;
|
|
74
|
+
params: SqlValue[];
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface IntrospectOptions {
|
|
79
|
+
datasource?: {
|
|
80
|
+
name: string;
|
|
81
|
+
provider: string;
|
|
82
|
+
envVar?: string;
|
|
83
|
+
url?: string;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Reverse-engineer a SchemaDocument from a live Firebird database.
|
|
88
|
+
* Table/column names are kept as-is via `@@map`/`@map` when the idiomatic
|
|
89
|
+
* Ember name differs, and foreign keys become relation fields on both sides.
|
|
90
|
+
*/
|
|
91
|
+
declare class Introspector {
|
|
92
|
+
private readonly driver;
|
|
93
|
+
constructor(driver: SqlDriver);
|
|
94
|
+
introspect(options?: IntrospectOptions): Promise<SchemaDocument>;
|
|
95
|
+
private buildModel;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Generates a fully-typed TypeScript client from a schema. Produces per-model
|
|
100
|
+
* scalar types, relation payloads, filter/where/select/include/create/update
|
|
101
|
+
* input types, typed delegates, and the `EmberClient` class (which embeds the
|
|
102
|
+
* schema so it can run with no extra wiring).
|
|
103
|
+
*/
|
|
104
|
+
declare class ClientGenerator {
|
|
105
|
+
private readonly schema;
|
|
106
|
+
constructor(schema: SchemaDocument);
|
|
107
|
+
generate(): string;
|
|
108
|
+
private header;
|
|
109
|
+
private enums;
|
|
110
|
+
private enumType;
|
|
111
|
+
private modelTypes;
|
|
112
|
+
private modelType;
|
|
113
|
+
/**
|
|
114
|
+
* Fluent-API return type for single-record reads: a Promise of the payload
|
|
115
|
+
* that also exposes a method per relation (to-many -> array; to-one ->
|
|
116
|
+
* chainable fluent).
|
|
117
|
+
*/
|
|
118
|
+
private fluentType;
|
|
119
|
+
/**
|
|
120
|
+
* Type-level registry powering recursive payload resolution: a model-name
|
|
121
|
+
* union, a scalar-payload map, and a relation map carrying each relation's
|
|
122
|
+
* target model, list-ness and nullability.
|
|
123
|
+
*/
|
|
124
|
+
private registry;
|
|
125
|
+
private scalarType;
|
|
126
|
+
private namespace;
|
|
127
|
+
private whereInput;
|
|
128
|
+
private whereUnique;
|
|
129
|
+
private fieldFilter;
|
|
130
|
+
private relationFilter;
|
|
131
|
+
private orderByInput;
|
|
132
|
+
private selectInclude;
|
|
133
|
+
private dataInputs;
|
|
134
|
+
private inputScalarType;
|
|
135
|
+
/**
|
|
136
|
+
* Update value for a scalar field: a bare value, `{ set }`, and — for numeric
|
|
137
|
+
* fields — the atomic operators increment/decrement/multiply/divide.
|
|
138
|
+
*/
|
|
139
|
+
private updateScalarType;
|
|
140
|
+
private nestedCreate;
|
|
141
|
+
private nestedUpdate;
|
|
142
|
+
private argsTypes;
|
|
143
|
+
private delegateInterface;
|
|
144
|
+
private clientClass;
|
|
145
|
+
}
|
|
146
|
+
declare function generateClientSource(schema: SchemaDocument): string;
|
|
147
|
+
/** Generate and write the client to `<outDir>/index.ts`. Returns the path. */
|
|
148
|
+
declare function writeClient(schema: SchemaDocument, outDir: string): string;
|
|
149
|
+
|
|
150
|
+
interface ColumnChange {
|
|
151
|
+
field: FieldNode;
|
|
152
|
+
table: string;
|
|
153
|
+
typeChanged: boolean;
|
|
154
|
+
nullabilityChanged: boolean;
|
|
155
|
+
}
|
|
156
|
+
interface UniqueSpec {
|
|
157
|
+
name: string;
|
|
158
|
+
columns: string[];
|
|
159
|
+
}
|
|
160
|
+
interface ForeignKeySpec {
|
|
161
|
+
name: string;
|
|
162
|
+
columns: string[];
|
|
163
|
+
refTable: string;
|
|
164
|
+
refColumns: string[];
|
|
165
|
+
onDelete?: string;
|
|
166
|
+
onUpdate?: string;
|
|
167
|
+
}
|
|
168
|
+
interface ModelChange {
|
|
169
|
+
model: ModelNode;
|
|
170
|
+
table: string;
|
|
171
|
+
addedColumns: FieldNode[];
|
|
172
|
+
droppedColumns: string[];
|
|
173
|
+
changedColumns: ColumnChange[];
|
|
174
|
+
addedUniques: UniqueSpec[];
|
|
175
|
+
addedForeignKeys: ForeignKeySpec[];
|
|
176
|
+
}
|
|
177
|
+
interface SchemaDiff {
|
|
178
|
+
createdModels: ModelNode[];
|
|
179
|
+
droppedTables: string[];
|
|
180
|
+
modelChanges: ModelChange[];
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Structural diff turning `current` (usually introspected from the live DB)
|
|
184
|
+
* into `desired` (the `.ember` schema). Pure and dialect-independent; the
|
|
185
|
+
* planner converts it to DDL.
|
|
186
|
+
*
|
|
187
|
+
* Scope (safe subset): create/drop tables, add/drop/alter columns, and add
|
|
188
|
+
* unique/foreign-key constraints that don't already exist. Dropping
|
|
189
|
+
* constraints and plain (non-constraint) indexes on existing tables is left to
|
|
190
|
+
* explicit user action — see doc/migrations.md.
|
|
191
|
+
*/
|
|
192
|
+
declare function diffSchemas(desired: SchemaDocument, current: SchemaDocument): SchemaDiff;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Convert a SchemaDiff into an ordered list of DDL statements. Order matters in
|
|
196
|
+
* Firebird: tables and columns must exist before constraints reference them, so
|
|
197
|
+
* foreign keys are always emitted last.
|
|
198
|
+
*/
|
|
199
|
+
declare function planMigration(diff: SchemaDiff, desired: SchemaDocument, dialect: SqlDialect): string[];
|
|
200
|
+
/** Render DDL statements as a `.sql` migration file body. */
|
|
201
|
+
declare function renderMigrationSql(statements: string[]): string;
|
|
202
|
+
/** Split a migration `.sql` body back into executable statements. */
|
|
203
|
+
declare function splitStatements(sql: string): string[];
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Generates Firebird DDL from schema nodes. Pure string generation (no I/O),
|
|
207
|
+
* so it is fully unit-testable. Identifier quoting is delegated to the dialect
|
|
208
|
+
* (Strategy) to stay backend-agnostic at the call sites.
|
|
209
|
+
*/
|
|
210
|
+
declare class FirebirdDdl {
|
|
211
|
+
private readonly d;
|
|
212
|
+
constructor(d: SqlDialect);
|
|
213
|
+
/** Firebird column type for a field, honoring its `@db.*` native type. */
|
|
214
|
+
columnType(field: FieldNode): string;
|
|
215
|
+
/** `"COL" <type> [GENERATED ...] [DEFAULT ...] [NOT NULL]`. */
|
|
216
|
+
columnDefinition(field: FieldNode): string;
|
|
217
|
+
/**
|
|
218
|
+
* On Firebird 2.1/2.5 (no IDENTITY), emulate autoincrement with a SEQUENCE
|
|
219
|
+
* and a BEFORE INSERT trigger. Returns the extra DDL objects to create after
|
|
220
|
+
* the table; an empty array when IDENTITY is supported.
|
|
221
|
+
*/
|
|
222
|
+
autoIncrementObjects(model: ModelNode): string[];
|
|
223
|
+
autoIncrementForColumn(table: string, column: string): string[];
|
|
224
|
+
createTable(model: ModelNode): string;
|
|
225
|
+
dropTable(table: string): string;
|
|
226
|
+
addColumn(table: string, field: FieldNode): string;
|
|
227
|
+
dropColumn(table: string, column: string): string;
|
|
228
|
+
/** Change a column's data type (Firebird: ALTER COLUMN ... TYPE ...). */
|
|
229
|
+
alterColumnType(table: string, field: FieldNode): string;
|
|
230
|
+
setNotNull(table: string, column: string, notNull: boolean): string;
|
|
231
|
+
addUnique(table: string, name: string, columns: string[]): string;
|
|
232
|
+
dropConstraint(table: string, name: string): string;
|
|
233
|
+
addForeignKey(table: string, name: string, columns: string[], refTable: string, refColumns: string[], onDelete?: string, onUpdate?: string): string;
|
|
234
|
+
createIndex(table: string, name: string, columns: string[], unique: boolean): string;
|
|
235
|
+
dropIndex(name: string): string;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
interface DevResult {
|
|
239
|
+
empty: boolean;
|
|
240
|
+
id?: string;
|
|
241
|
+
dir?: string;
|
|
242
|
+
statements: string[];
|
|
243
|
+
}
|
|
244
|
+
interface DeployResult {
|
|
245
|
+
applied: {
|
|
246
|
+
id: string;
|
|
247
|
+
steps: number;
|
|
248
|
+
}[];
|
|
249
|
+
}
|
|
250
|
+
interface StatusResult {
|
|
251
|
+
applied: string[];
|
|
252
|
+
pending: string[];
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Drives schema migrations against a live Firebird database. Diffs the desired
|
|
256
|
+
* `.ember` schema against the introspected current state and emits/applies DDL.
|
|
257
|
+
* The history table `_EMBER_MIGRATIONS` is always excluded from the diff.
|
|
258
|
+
*/
|
|
259
|
+
declare class Migrator {
|
|
260
|
+
private readonly driver;
|
|
261
|
+
private readonly desired;
|
|
262
|
+
private readonly migrationsDir;
|
|
263
|
+
private readonly dialect;
|
|
264
|
+
constructor(driver: SqlDriver, desired: SchemaDocument, migrationsDir: string, dialect?: SqlDialect);
|
|
265
|
+
/** Compute the diff between the desired schema and the live database. */
|
|
266
|
+
diff(): Promise<SchemaDiff>;
|
|
267
|
+
/** Plan (but do not apply) the DDL needed to reach the desired schema. */
|
|
268
|
+
plan(): Promise<string[]>;
|
|
269
|
+
/**
|
|
270
|
+
* `migrate dev`: create a timestamped migration from the current diff, apply
|
|
271
|
+
* it, and record it in history.
|
|
272
|
+
*/
|
|
273
|
+
dev(name?: string): Promise<DevResult>;
|
|
274
|
+
/**
|
|
275
|
+
* `db push`: apply the diff directly to the database without writing a
|
|
276
|
+
* migration file (prototyping flow).
|
|
277
|
+
*/
|
|
278
|
+
push(): Promise<{
|
|
279
|
+
statements: string[];
|
|
280
|
+
}>;
|
|
281
|
+
/** `migrate deploy`: apply every on-disk migration not yet recorded. */
|
|
282
|
+
deploy(): Promise<DeployResult>;
|
|
283
|
+
/** `migrate status`: list applied vs pending migrations. */
|
|
284
|
+
status(): Promise<StatusResult>;
|
|
285
|
+
private currentSchema;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export { ClientGenerator, ConnectionConfig, FieldNode, FirebirdDdl, FirebirdDriver, Introspector, Migrator, ModelNode, SchemaDocument, Sql, SqlDialect, SqlDriver, SqlValue, TransactionContext, TransactionOptions, buildConnectionUrl, createDriver, diffSchemas, generateClientSource, parseConnectionUrl, planMigration, renderMigrationSql, splitStatements, writeClient };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { S as SchemaDocument, M as ModelNode, F as FieldNode } from './index-D0xIdtCl.js';
|
|
2
|
+
export { A as AttributeArgValue, D as DatasourceNode, c as DefaultValue, E as EnumNode, d as FieldKind, G as GeneratorNode, I as IndexNode, N as NativeType, R as ReferentialAction, e as RelationInfo, a as SCALAR_TYPES, b as ScalarType, U as UniqueIndex, f as emptySchema, g as fieldColumn, h as findEnum, i as findModel, j as idFields, m as modelTable, r as relationFields, s as scalarFields } from './index-D0xIdtCl.js';
|
|
3
|
+
export { D as DatabaseError, E as EmberError, L as LoadedSchema, Q as QueryValidationError, R as RecordNotFoundError, S as SchemaParseError, a as SchemaValidationError, U as UniqueConstraintError, d as findSchemaPath, l as loadSchema, p as parseAndValidate, b as parseSchema, c as printSchema, r as resolveDatasourceUrl, v as validateSchema } from './index-0lWi8TMM.js';
|
|
4
|
+
import { S as SqlDriver, C as ConnectionConfig, D as DriverOptions, T as TransactionContext, a as TransactionOptions, b as SqlValue, c as SqlDialect } from './index-BSXZjDUd.js';
|
|
5
|
+
export { A as AggregateArgs, d as ClientOptions, e as CreateArgs, f as DeleteArgs, E as EmberClientBase, F as FindManyArgs, g as FindUniqueArgs, h as FirebirdDialect, G as GroupByArgs, I as IncludeInput, i as IsolationLevel, M as ModelDelegate, O as OrderByInput, Q as QueryEngine, j as SelectInput, U as UpdateArgs, k as UpsertArgs, W as WhereInput, l as createClient } from './index-BSXZjDUd.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Firebird implementation of SqlDriver. Wraps node-firebird's callback API in
|
|
9
|
+
* promises, manages a connection pool, and guarantees every query executes
|
|
10
|
+
* inside a transaction. Nested `transaction()` calls reuse the active one via
|
|
11
|
+
* AsyncLocalStorage so `client.$transaction(...)` composes naturally.
|
|
12
|
+
*/
|
|
13
|
+
declare class FirebirdDriver implements SqlDriver {
|
|
14
|
+
private pool;
|
|
15
|
+
private readonly options;
|
|
16
|
+
private readonly poolMax;
|
|
17
|
+
private readonly onQuery?;
|
|
18
|
+
private readonly activeTx;
|
|
19
|
+
constructor(config: ConnectionConfig, driverOptions?: DriverOptions);
|
|
20
|
+
connect(): Promise<void>;
|
|
21
|
+
disconnect(): Promise<void>;
|
|
22
|
+
transaction<T>(fn: (tx: TransactionContext) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
23
|
+
private acquire;
|
|
24
|
+
private begin;
|
|
25
|
+
private runOnTransaction;
|
|
26
|
+
private commit;
|
|
27
|
+
private safeRollback;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Parse a Firebird connection URL into a ConnectionConfig.
|
|
32
|
+
*
|
|
33
|
+
* Supported forms:
|
|
34
|
+
* firebird://user:password@host:port/path/to/database.fdb?role=RDB$ADMIN
|
|
35
|
+
* firebird://SYSDBA:masterkey@localhost:3050//var/lib/firebird/data/app.fdb
|
|
36
|
+
*
|
|
37
|
+
* The path after the host is treated as the absolute database path. A leading
|
|
38
|
+
* double slash (`//var/...`) yields an absolute POSIX path; a single slash with
|
|
39
|
+
* a Windows drive (`/C:/...`) is normalized too.
|
|
40
|
+
*/
|
|
41
|
+
declare function parseConnectionUrl(url: string): ConnectionConfig;
|
|
42
|
+
declare function buildConnectionUrl(config: ConnectionConfig): string;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Factory that builds a driver from either a connection URL or an explicit
|
|
46
|
+
* config object. Centralizing creation here keeps the client decoupled from a
|
|
47
|
+
* concrete driver class (Factory pattern / DIP).
|
|
48
|
+
*/
|
|
49
|
+
declare function createDriver(source: string | ConnectionConfig, options?: DriverOptions): SqlDriver;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* An accumulating SQL fragment that keeps text and bound parameters together,
|
|
53
|
+
* so values are always parameterized (`?`) and never string-interpolated.
|
|
54
|
+
* This is the core defense against SQL injection in the query layer.
|
|
55
|
+
*/
|
|
56
|
+
declare class Sql {
|
|
57
|
+
private parts;
|
|
58
|
+
readonly params: SqlValue[];
|
|
59
|
+
static raw(text: string): Sql;
|
|
60
|
+
static value(value: SqlValue): Sql;
|
|
61
|
+
static join(fragments: Sql[], separator: string): Sql;
|
|
62
|
+
/** Append raw, trusted SQL text (keywords, already-escaped identifiers). */
|
|
63
|
+
push(text: string): this;
|
|
64
|
+
/** Append a `?` placeholder bound to `value`. */
|
|
65
|
+
bind(value: SqlValue): this;
|
|
66
|
+
/** Append a comma-separated list of placeholders bound to `values`. */
|
|
67
|
+
bindList(values: readonly SqlValue[]): this;
|
|
68
|
+
/** Merge another fragment (text + params) into this one. */
|
|
69
|
+
append(other: Sql): this;
|
|
70
|
+
get text(): string;
|
|
71
|
+
isEmpty(): boolean;
|
|
72
|
+
toQuery(): {
|
|
73
|
+
sql: string;
|
|
74
|
+
params: SqlValue[];
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface IntrospectOptions {
|
|
79
|
+
datasource?: {
|
|
80
|
+
name: string;
|
|
81
|
+
provider: string;
|
|
82
|
+
envVar?: string;
|
|
83
|
+
url?: string;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Reverse-engineer a SchemaDocument from a live Firebird database.
|
|
88
|
+
* Table/column names are kept as-is via `@@map`/`@map` when the idiomatic
|
|
89
|
+
* Ember name differs, and foreign keys become relation fields on both sides.
|
|
90
|
+
*/
|
|
91
|
+
declare class Introspector {
|
|
92
|
+
private readonly driver;
|
|
93
|
+
constructor(driver: SqlDriver);
|
|
94
|
+
introspect(options?: IntrospectOptions): Promise<SchemaDocument>;
|
|
95
|
+
private buildModel;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Generates a fully-typed TypeScript client from a schema. Produces per-model
|
|
100
|
+
* scalar types, relation payloads, filter/where/select/include/create/update
|
|
101
|
+
* input types, typed delegates, and the `EmberClient` class (which embeds the
|
|
102
|
+
* schema so it can run with no extra wiring).
|
|
103
|
+
*/
|
|
104
|
+
declare class ClientGenerator {
|
|
105
|
+
private readonly schema;
|
|
106
|
+
constructor(schema: SchemaDocument);
|
|
107
|
+
generate(): string;
|
|
108
|
+
private header;
|
|
109
|
+
private enums;
|
|
110
|
+
private enumType;
|
|
111
|
+
private modelTypes;
|
|
112
|
+
private modelType;
|
|
113
|
+
/**
|
|
114
|
+
* Fluent-API return type for single-record reads: a Promise of the payload
|
|
115
|
+
* that also exposes a method per relation (to-many -> array; to-one ->
|
|
116
|
+
* chainable fluent).
|
|
117
|
+
*/
|
|
118
|
+
private fluentType;
|
|
119
|
+
/**
|
|
120
|
+
* Type-level registry powering recursive payload resolution: a model-name
|
|
121
|
+
* union, a scalar-payload map, and a relation map carrying each relation's
|
|
122
|
+
* target model, list-ness and nullability.
|
|
123
|
+
*/
|
|
124
|
+
private registry;
|
|
125
|
+
private scalarType;
|
|
126
|
+
private namespace;
|
|
127
|
+
private whereInput;
|
|
128
|
+
private whereUnique;
|
|
129
|
+
private fieldFilter;
|
|
130
|
+
private relationFilter;
|
|
131
|
+
private orderByInput;
|
|
132
|
+
private selectInclude;
|
|
133
|
+
private dataInputs;
|
|
134
|
+
private inputScalarType;
|
|
135
|
+
/**
|
|
136
|
+
* Update value for a scalar field: a bare value, `{ set }`, and — for numeric
|
|
137
|
+
* fields — the atomic operators increment/decrement/multiply/divide.
|
|
138
|
+
*/
|
|
139
|
+
private updateScalarType;
|
|
140
|
+
private nestedCreate;
|
|
141
|
+
private nestedUpdate;
|
|
142
|
+
private argsTypes;
|
|
143
|
+
private delegateInterface;
|
|
144
|
+
private clientClass;
|
|
145
|
+
}
|
|
146
|
+
declare function generateClientSource(schema: SchemaDocument): string;
|
|
147
|
+
/** Generate and write the client to `<outDir>/index.ts`. Returns the path. */
|
|
148
|
+
declare function writeClient(schema: SchemaDocument, outDir: string): string;
|
|
149
|
+
|
|
150
|
+
interface ColumnChange {
|
|
151
|
+
field: FieldNode;
|
|
152
|
+
table: string;
|
|
153
|
+
typeChanged: boolean;
|
|
154
|
+
nullabilityChanged: boolean;
|
|
155
|
+
}
|
|
156
|
+
interface UniqueSpec {
|
|
157
|
+
name: string;
|
|
158
|
+
columns: string[];
|
|
159
|
+
}
|
|
160
|
+
interface ForeignKeySpec {
|
|
161
|
+
name: string;
|
|
162
|
+
columns: string[];
|
|
163
|
+
refTable: string;
|
|
164
|
+
refColumns: string[];
|
|
165
|
+
onDelete?: string;
|
|
166
|
+
onUpdate?: string;
|
|
167
|
+
}
|
|
168
|
+
interface ModelChange {
|
|
169
|
+
model: ModelNode;
|
|
170
|
+
table: string;
|
|
171
|
+
addedColumns: FieldNode[];
|
|
172
|
+
droppedColumns: string[];
|
|
173
|
+
changedColumns: ColumnChange[];
|
|
174
|
+
addedUniques: UniqueSpec[];
|
|
175
|
+
addedForeignKeys: ForeignKeySpec[];
|
|
176
|
+
}
|
|
177
|
+
interface SchemaDiff {
|
|
178
|
+
createdModels: ModelNode[];
|
|
179
|
+
droppedTables: string[];
|
|
180
|
+
modelChanges: ModelChange[];
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Structural diff turning `current` (usually introspected from the live DB)
|
|
184
|
+
* into `desired` (the `.ember` schema). Pure and dialect-independent; the
|
|
185
|
+
* planner converts it to DDL.
|
|
186
|
+
*
|
|
187
|
+
* Scope (safe subset): create/drop tables, add/drop/alter columns, and add
|
|
188
|
+
* unique/foreign-key constraints that don't already exist. Dropping
|
|
189
|
+
* constraints and plain (non-constraint) indexes on existing tables is left to
|
|
190
|
+
* explicit user action — see doc/migrations.md.
|
|
191
|
+
*/
|
|
192
|
+
declare function diffSchemas(desired: SchemaDocument, current: SchemaDocument): SchemaDiff;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Convert a SchemaDiff into an ordered list of DDL statements. Order matters in
|
|
196
|
+
* Firebird: tables and columns must exist before constraints reference them, so
|
|
197
|
+
* foreign keys are always emitted last.
|
|
198
|
+
*/
|
|
199
|
+
declare function planMigration(diff: SchemaDiff, desired: SchemaDocument, dialect: SqlDialect): string[];
|
|
200
|
+
/** Render DDL statements as a `.sql` migration file body. */
|
|
201
|
+
declare function renderMigrationSql(statements: string[]): string;
|
|
202
|
+
/** Split a migration `.sql` body back into executable statements. */
|
|
203
|
+
declare function splitStatements(sql: string): string[];
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Generates Firebird DDL from schema nodes. Pure string generation (no I/O),
|
|
207
|
+
* so it is fully unit-testable. Identifier quoting is delegated to the dialect
|
|
208
|
+
* (Strategy) to stay backend-agnostic at the call sites.
|
|
209
|
+
*/
|
|
210
|
+
declare class FirebirdDdl {
|
|
211
|
+
private readonly d;
|
|
212
|
+
constructor(d: SqlDialect);
|
|
213
|
+
/** Firebird column type for a field, honoring its `@db.*` native type. */
|
|
214
|
+
columnType(field: FieldNode): string;
|
|
215
|
+
/** `"COL" <type> [GENERATED ...] [DEFAULT ...] [NOT NULL]`. */
|
|
216
|
+
columnDefinition(field: FieldNode): string;
|
|
217
|
+
/**
|
|
218
|
+
* On Firebird 2.1/2.5 (no IDENTITY), emulate autoincrement with a SEQUENCE
|
|
219
|
+
* and a BEFORE INSERT trigger. Returns the extra DDL objects to create after
|
|
220
|
+
* the table; an empty array when IDENTITY is supported.
|
|
221
|
+
*/
|
|
222
|
+
autoIncrementObjects(model: ModelNode): string[];
|
|
223
|
+
autoIncrementForColumn(table: string, column: string): string[];
|
|
224
|
+
createTable(model: ModelNode): string;
|
|
225
|
+
dropTable(table: string): string;
|
|
226
|
+
addColumn(table: string, field: FieldNode): string;
|
|
227
|
+
dropColumn(table: string, column: string): string;
|
|
228
|
+
/** Change a column's data type (Firebird: ALTER COLUMN ... TYPE ...). */
|
|
229
|
+
alterColumnType(table: string, field: FieldNode): string;
|
|
230
|
+
setNotNull(table: string, column: string, notNull: boolean): string;
|
|
231
|
+
addUnique(table: string, name: string, columns: string[]): string;
|
|
232
|
+
dropConstraint(table: string, name: string): string;
|
|
233
|
+
addForeignKey(table: string, name: string, columns: string[], refTable: string, refColumns: string[], onDelete?: string, onUpdate?: string): string;
|
|
234
|
+
createIndex(table: string, name: string, columns: string[], unique: boolean): string;
|
|
235
|
+
dropIndex(name: string): string;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
interface DevResult {
|
|
239
|
+
empty: boolean;
|
|
240
|
+
id?: string;
|
|
241
|
+
dir?: string;
|
|
242
|
+
statements: string[];
|
|
243
|
+
}
|
|
244
|
+
interface DeployResult {
|
|
245
|
+
applied: {
|
|
246
|
+
id: string;
|
|
247
|
+
steps: number;
|
|
248
|
+
}[];
|
|
249
|
+
}
|
|
250
|
+
interface StatusResult {
|
|
251
|
+
applied: string[];
|
|
252
|
+
pending: string[];
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Drives schema migrations against a live Firebird database. Diffs the desired
|
|
256
|
+
* `.ember` schema against the introspected current state and emits/applies DDL.
|
|
257
|
+
* The history table `_EMBER_MIGRATIONS` is always excluded from the diff.
|
|
258
|
+
*/
|
|
259
|
+
declare class Migrator {
|
|
260
|
+
private readonly driver;
|
|
261
|
+
private readonly desired;
|
|
262
|
+
private readonly migrationsDir;
|
|
263
|
+
private readonly dialect;
|
|
264
|
+
constructor(driver: SqlDriver, desired: SchemaDocument, migrationsDir: string, dialect?: SqlDialect);
|
|
265
|
+
/** Compute the diff between the desired schema and the live database. */
|
|
266
|
+
diff(): Promise<SchemaDiff>;
|
|
267
|
+
/** Plan (but do not apply) the DDL needed to reach the desired schema. */
|
|
268
|
+
plan(): Promise<string[]>;
|
|
269
|
+
/**
|
|
270
|
+
* `migrate dev`: create a timestamped migration from the current diff, apply
|
|
271
|
+
* it, and record it in history.
|
|
272
|
+
*/
|
|
273
|
+
dev(name?: string): Promise<DevResult>;
|
|
274
|
+
/**
|
|
275
|
+
* `db push`: apply the diff directly to the database without writing a
|
|
276
|
+
* migration file (prototyping flow).
|
|
277
|
+
*/
|
|
278
|
+
push(): Promise<{
|
|
279
|
+
statements: string[];
|
|
280
|
+
}>;
|
|
281
|
+
/** `migrate deploy`: apply every on-disk migration not yet recorded. */
|
|
282
|
+
deploy(): Promise<DeployResult>;
|
|
283
|
+
/** `migrate status`: list applied vs pending migrations. */
|
|
284
|
+
status(): Promise<StatusResult>;
|
|
285
|
+
private currentSchema;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export { ClientGenerator, ConnectionConfig, FieldNode, FirebirdDdl, FirebirdDriver, Introspector, Migrator, ModelNode, SchemaDocument, Sql, SqlDialect, SqlDriver, SqlValue, TransactionContext, TransactionOptions, buildConnectionUrl, createDriver, diffSchemas, generateClientSource, parseConnectionUrl, planMigration, renderMigrationSql, splitStatements, writeClient };
|