@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
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import { S as SchemaDocument, M as ModelNode } from './index-D0xIdtCl.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Database driver abstraction. The query engine depends only on these
|
|
5
|
+
* interfaces (DIP), never on `node-firebird` directly, so a different
|
|
6
|
+
* backend could be plugged in without touching the engine.
|
|
7
|
+
*/
|
|
8
|
+
interface ConnectionConfig {
|
|
9
|
+
host: string;
|
|
10
|
+
port: number;
|
|
11
|
+
database: string;
|
|
12
|
+
user: string;
|
|
13
|
+
password: string;
|
|
14
|
+
role?: string;
|
|
15
|
+
encoding?: string;
|
|
16
|
+
pageSize?: number;
|
|
17
|
+
/** Max pooled connections. */
|
|
18
|
+
poolMax?: number;
|
|
19
|
+
blobAsText?: boolean;
|
|
20
|
+
lowercaseKeys?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Authentication plugin. Firebird 3+ defaults to "Srp" (secure remote
|
|
23
|
+
* password) and is negotiated automatically; use "Legacy_Auth" for legacy
|
|
24
|
+
* Firebird 2.1/2.5 servers.
|
|
25
|
+
*/
|
|
26
|
+
authPlugin?: "Srp" | "Legacy_Auth";
|
|
27
|
+
/** Enable wire compression (Firebird 3+). */
|
|
28
|
+
wireCompression?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Target server major version, used to pick version-specific SQL/DDL
|
|
31
|
+
* (e.g. BOOLEAN vs SMALLINT, IDENTITY vs generator+trigger). Defaults to 3.
|
|
32
|
+
*/
|
|
33
|
+
version?: FirebirdVersion;
|
|
34
|
+
}
|
|
35
|
+
type FirebirdVersion = "2.1" | "2.5" | "3" | "4" | "5";
|
|
36
|
+
type SqlValue = string | number | boolean | bigint | Date | Buffer | null;
|
|
37
|
+
/** A connection scoped to an open transaction. */
|
|
38
|
+
interface TransactionContext {
|
|
39
|
+
/** Run a parameterized query and return all rows. */
|
|
40
|
+
query<T = Record<string, unknown>>(sql: string, params?: readonly SqlValue[]): Promise<T[]>;
|
|
41
|
+
}
|
|
42
|
+
type IsolationLevel = "READ_COMMITTED" | "READ_COMMITTED_READ_ONLY" | "REPEATABLE_READ" | "SERIALIZABLE";
|
|
43
|
+
/** Emitted once per executed statement when a logger is configured. */
|
|
44
|
+
interface QueryEvent {
|
|
45
|
+
sql: string;
|
|
46
|
+
params: readonly SqlValue[];
|
|
47
|
+
durationMs: number;
|
|
48
|
+
/** Number of rows returned (selects) or affected-ish (best-effort). */
|
|
49
|
+
rowCount: number;
|
|
50
|
+
}
|
|
51
|
+
type QueryLogger = (event: QueryEvent) => void;
|
|
52
|
+
interface DriverOptions {
|
|
53
|
+
/** Called after each statement completes (used by the client `log` option). */
|
|
54
|
+
onQuery?: QueryLogger;
|
|
55
|
+
}
|
|
56
|
+
interface TransactionOptions {
|
|
57
|
+
isolation?: IsolationLevel;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The driver contract used by the runtime. Every read and write goes through
|
|
61
|
+
* `transaction()` so the project rule "every operation runs in a transaction"
|
|
62
|
+
* holds by construction.
|
|
63
|
+
*/
|
|
64
|
+
interface SqlDriver {
|
|
65
|
+
connect(): Promise<void>;
|
|
66
|
+
disconnect(): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Run `fn` inside a transaction, committing on success and rolling back on
|
|
69
|
+
* any thrown error. Nested calls reuse the active transaction.
|
|
70
|
+
*/
|
|
71
|
+
transaction<T>(fn: (tx: TransactionContext) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Strategy interface for SQL generation. Encapsulates every dialect-specific
|
|
76
|
+
* decision so the query compiler stays backend-agnostic. Only FirebirdDialect
|
|
77
|
+
* is implemented today, but the engine never assumes Firebird directly.
|
|
78
|
+
*/
|
|
79
|
+
interface SqlDialect {
|
|
80
|
+
/** Quote an identifier (table/column/alias). */
|
|
81
|
+
quoteId(name: string): string;
|
|
82
|
+
/** Quote a `table.column` reference. */
|
|
83
|
+
quoteRef(table: string, column: string): string;
|
|
84
|
+
/** Pagination clause placed right after SELECT (e.g. `FIRST 10 SKIP 5`). */
|
|
85
|
+
paginationClause(take?: number, skip?: number): string;
|
|
86
|
+
/** Wrap a value for LIKE with case-insensitive mode. */
|
|
87
|
+
caseInsensitive(expr: string): string;
|
|
88
|
+
/** Map a default function name (now/uuid/...) to a SQL expression, if any. */
|
|
89
|
+
defaultFunctionSql(name: string): string | null;
|
|
90
|
+
/** Coerce a JS value into a driver-bindable SqlValue. */
|
|
91
|
+
coerceValue(value: unknown): SqlValue;
|
|
92
|
+
/** True if the dialect can paginate (controls FIRST/SKIP usage). */
|
|
93
|
+
readonly supportsReturning: boolean;
|
|
94
|
+
/** Native BOOLEAN type (Firebird 3+) vs SMALLINT fallback (2.1/2.5). */
|
|
95
|
+
readonly supportsBooleanType: boolean;
|
|
96
|
+
/** IDENTITY columns (Firebird 3+) vs generator+trigger (2.1/2.5). */
|
|
97
|
+
readonly supportsIdentity: boolean;
|
|
98
|
+
/** Window functions like ROW_NUMBER() OVER (...) (Firebird 3+). */
|
|
99
|
+
readonly supportsWindowFunctions: boolean;
|
|
100
|
+
/** DDL type used for boolean columns. */
|
|
101
|
+
booleanColumnType(): string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Firebird 3+/4+ dialect.
|
|
105
|
+
* - Identifiers are double-quoted to preserve case (introspection yields
|
|
106
|
+
* UPPER-CASE names and quoting avoids accidental folding).
|
|
107
|
+
* - Pagination uses `FIRST n SKIP m` after the SELECT keyword.
|
|
108
|
+
* - Case-insensitive matching uses UPPER() on both sides.
|
|
109
|
+
*/
|
|
110
|
+
interface FirebirdDialectOptions {
|
|
111
|
+
version?: FirebirdVersion;
|
|
112
|
+
}
|
|
113
|
+
declare class FirebirdDialect implements SqlDialect {
|
|
114
|
+
readonly supportsReturning = true;
|
|
115
|
+
readonly version: FirebirdVersion;
|
|
116
|
+
readonly supportsBooleanType: boolean;
|
|
117
|
+
readonly supportsIdentity: boolean;
|
|
118
|
+
readonly supportsWindowFunctions: boolean;
|
|
119
|
+
constructor(options?: FirebirdDialectOptions);
|
|
120
|
+
booleanColumnType(): string;
|
|
121
|
+
quoteId(name: string): string;
|
|
122
|
+
quoteRef(table: string, column: string): string;
|
|
123
|
+
paginationClause(take?: number, skip?: number): string;
|
|
124
|
+
caseInsensitive(expr: string): string;
|
|
125
|
+
defaultFunctionSql(name: string): string | null;
|
|
126
|
+
coerceValue(value: unknown): SqlValue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Runtime-facing query argument shapes. The generated client produces strict,
|
|
131
|
+
* per-model versions of these; at runtime the engine works with these generic
|
|
132
|
+
* forms. Mirrors Prisma's query API surface.
|
|
133
|
+
*/
|
|
134
|
+
type SortOrder = "asc" | "desc";
|
|
135
|
+
type QueryMode = "default" | "insensitive";
|
|
136
|
+
/** Scalar field filter, e.g. `{ equals, in, lt, contains, ... }`. */
|
|
137
|
+
interface ScalarFilter {
|
|
138
|
+
equals?: unknown;
|
|
139
|
+
not?: unknown | ScalarFilter;
|
|
140
|
+
in?: unknown[];
|
|
141
|
+
notIn?: unknown[];
|
|
142
|
+
lt?: unknown;
|
|
143
|
+
lte?: unknown;
|
|
144
|
+
gt?: unknown;
|
|
145
|
+
gte?: unknown;
|
|
146
|
+
contains?: string;
|
|
147
|
+
startsWith?: string;
|
|
148
|
+
endsWith?: string;
|
|
149
|
+
mode?: QueryMode;
|
|
150
|
+
}
|
|
151
|
+
/** Relation filter for to-one (`is`/`isNot`) and to-many (`some`/`every`/`none`). */
|
|
152
|
+
interface RelationFilter {
|
|
153
|
+
is?: WhereInput | null;
|
|
154
|
+
isNot?: WhereInput | null;
|
|
155
|
+
some?: WhereInput;
|
|
156
|
+
every?: WhereInput;
|
|
157
|
+
none?: WhereInput;
|
|
158
|
+
}
|
|
159
|
+
interface WhereInput {
|
|
160
|
+
AND?: WhereInput | WhereInput[];
|
|
161
|
+
OR?: WhereInput[];
|
|
162
|
+
NOT?: WhereInput | WhereInput[];
|
|
163
|
+
[field: string]: unknown | ScalarFilter | RelationFilter | WhereInput | WhereInput[] | undefined;
|
|
164
|
+
}
|
|
165
|
+
type OrderByInput = Record<string, SortOrder> | Record<string, SortOrder>[];
|
|
166
|
+
type SelectInput = Record<string, boolean | NestedReadArgs>;
|
|
167
|
+
type IncludeInput = Record<string, boolean | NestedReadArgs>;
|
|
168
|
+
/** Fields to exclude from the result (inverse of select). */
|
|
169
|
+
type OmitInput = Record<string, boolean>;
|
|
170
|
+
interface NestedReadArgs {
|
|
171
|
+
select?: SelectInput;
|
|
172
|
+
include?: IncludeInput;
|
|
173
|
+
where?: WhereInput;
|
|
174
|
+
orderBy?: OrderByInput;
|
|
175
|
+
take?: number;
|
|
176
|
+
skip?: number;
|
|
177
|
+
distinct?: string[];
|
|
178
|
+
}
|
|
179
|
+
interface FindManyArgs {
|
|
180
|
+
where?: WhereInput;
|
|
181
|
+
orderBy?: OrderByInput;
|
|
182
|
+
select?: SelectInput;
|
|
183
|
+
include?: IncludeInput;
|
|
184
|
+
omit?: OmitInput;
|
|
185
|
+
take?: number;
|
|
186
|
+
skip?: number;
|
|
187
|
+
cursor?: Record<string, unknown>;
|
|
188
|
+
distinct?: string[];
|
|
189
|
+
}
|
|
190
|
+
interface FindUniqueArgs {
|
|
191
|
+
where: WhereInput;
|
|
192
|
+
select?: SelectInput;
|
|
193
|
+
include?: IncludeInput;
|
|
194
|
+
omit?: OmitInput;
|
|
195
|
+
}
|
|
196
|
+
interface FindFirstArgs extends FindManyArgs {
|
|
197
|
+
}
|
|
198
|
+
interface CreateArgs {
|
|
199
|
+
data: Record<string, unknown>;
|
|
200
|
+
select?: SelectInput;
|
|
201
|
+
include?: IncludeInput;
|
|
202
|
+
omit?: OmitInput;
|
|
203
|
+
}
|
|
204
|
+
interface CreateManyArgs {
|
|
205
|
+
data: Record<string, unknown>[];
|
|
206
|
+
skipDuplicates?: boolean;
|
|
207
|
+
}
|
|
208
|
+
interface CreateManyAndReturnArgs {
|
|
209
|
+
data: Record<string, unknown>[];
|
|
210
|
+
select?: SelectInput;
|
|
211
|
+
omit?: OmitInput;
|
|
212
|
+
skipDuplicates?: boolean;
|
|
213
|
+
}
|
|
214
|
+
interface UpdateArgs {
|
|
215
|
+
where: WhereInput;
|
|
216
|
+
data: Record<string, unknown>;
|
|
217
|
+
select?: SelectInput;
|
|
218
|
+
include?: IncludeInput;
|
|
219
|
+
omit?: OmitInput;
|
|
220
|
+
}
|
|
221
|
+
interface UpdateManyArgs {
|
|
222
|
+
where?: WhereInput;
|
|
223
|
+
data: Record<string, unknown>;
|
|
224
|
+
}
|
|
225
|
+
interface UpsertArgs {
|
|
226
|
+
where: WhereInput;
|
|
227
|
+
create: Record<string, unknown>;
|
|
228
|
+
update: Record<string, unknown>;
|
|
229
|
+
select?: SelectInput;
|
|
230
|
+
include?: IncludeInput;
|
|
231
|
+
omit?: OmitInput;
|
|
232
|
+
}
|
|
233
|
+
interface DeleteArgs {
|
|
234
|
+
where: WhereInput;
|
|
235
|
+
select?: SelectInput;
|
|
236
|
+
include?: IncludeInput;
|
|
237
|
+
omit?: OmitInput;
|
|
238
|
+
}
|
|
239
|
+
interface DeleteManyArgs {
|
|
240
|
+
where?: WhereInput;
|
|
241
|
+
}
|
|
242
|
+
interface CountArgs {
|
|
243
|
+
where?: WhereInput;
|
|
244
|
+
take?: number;
|
|
245
|
+
skip?: number;
|
|
246
|
+
select?: Record<string, boolean> | true;
|
|
247
|
+
}
|
|
248
|
+
interface AggregateArgs {
|
|
249
|
+
where?: WhereInput;
|
|
250
|
+
orderBy?: OrderByInput;
|
|
251
|
+
take?: number;
|
|
252
|
+
skip?: number;
|
|
253
|
+
_count?: Record<string, boolean> | true;
|
|
254
|
+
_avg?: Record<string, boolean>;
|
|
255
|
+
_sum?: Record<string, boolean>;
|
|
256
|
+
_min?: Record<string, boolean>;
|
|
257
|
+
_max?: Record<string, boolean>;
|
|
258
|
+
}
|
|
259
|
+
interface GroupByArgs extends AggregateArgs {
|
|
260
|
+
by: string[];
|
|
261
|
+
having?: WhereInput;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The query engine executes high-level operations against a driver. Reads use
|
|
266
|
+
* a projection + relation-stitching pipeline (relations are loaded with
|
|
267
|
+
* separate batched queries, Prisma-style). Writes are delegated to
|
|
268
|
+
* WriteProcessor. Every operation runs inside a driver transaction.
|
|
269
|
+
*/
|
|
270
|
+
declare class QueryEngine {
|
|
271
|
+
private readonly schema;
|
|
272
|
+
private readonly dialect;
|
|
273
|
+
private readonly driver;
|
|
274
|
+
constructor(schema: SchemaDocument, dialect: SqlDialect, driver: SqlDriver);
|
|
275
|
+
model(name: string): ModelNode;
|
|
276
|
+
private run;
|
|
277
|
+
private execOn;
|
|
278
|
+
findMany(name: string, args?: FindManyArgs): Promise<Record<string, unknown>[]>;
|
|
279
|
+
findFirst(name: string, args?: FindFirstArgs): Promise<Record<string, unknown> | null>;
|
|
280
|
+
findFirstOrThrow(name: string, args?: FindFirstArgs): Promise<Record<string, unknown>>;
|
|
281
|
+
findUnique(name: string, args: FindUniqueArgs): Promise<Record<string, unknown> | null>;
|
|
282
|
+
findUniqueOrThrow(name: string, args: FindUniqueArgs): Promise<Record<string, unknown>>;
|
|
283
|
+
count(name: string, args?: CountArgs): Promise<number>;
|
|
284
|
+
aggregate(name: string, args?: AggregateArgs): Promise<Record<string, unknown>>;
|
|
285
|
+
groupBy(name: string, args: GroupByArgs): Promise<Record<string, unknown>[]>;
|
|
286
|
+
create(name: string, args: CreateArgs): Promise<Record<string, unknown>>;
|
|
287
|
+
createMany(name: string, args: CreateManyArgs): Promise<{
|
|
288
|
+
count: number;
|
|
289
|
+
}>;
|
|
290
|
+
/** Like createMany, but returns the created records (no nested relations). */
|
|
291
|
+
createManyAndReturn(name: string, args: CreateManyAndReturnArgs): Promise<Record<string, unknown>[]>;
|
|
292
|
+
update(name: string, args: UpdateArgs): Promise<Record<string, unknown>>;
|
|
293
|
+
updateMany(name: string, args: UpdateManyArgs): Promise<{
|
|
294
|
+
count: number;
|
|
295
|
+
}>;
|
|
296
|
+
upsert(name: string, args: UpsertArgs): Promise<Record<string, unknown>>;
|
|
297
|
+
delete(name: string, args: DeleteArgs): Promise<Record<string, unknown>>;
|
|
298
|
+
deleteMany(name: string, args?: DeleteManyArgs): Promise<{
|
|
299
|
+
count: number;
|
|
300
|
+
}>;
|
|
301
|
+
private readMany;
|
|
302
|
+
private loadRelation;
|
|
303
|
+
private readRelations;
|
|
304
|
+
/**
|
|
305
|
+
* Resolve which to-many relations to count for `_count` in select/include.
|
|
306
|
+
* `_count: true` counts every list relation; `_count: { select: { rel } }`
|
|
307
|
+
* counts the named ones.
|
|
308
|
+
*/
|
|
309
|
+
private readCountRelations;
|
|
310
|
+
/** Attach a `_count` object to each row with per-relation child counts. */
|
|
311
|
+
private loadCounts;
|
|
312
|
+
private readBack;
|
|
313
|
+
private readBackOne;
|
|
314
|
+
private requireOne;
|
|
315
|
+
private findOneRaw;
|
|
316
|
+
private countMatching;
|
|
317
|
+
private pickKeys;
|
|
318
|
+
private assertUniqueWhere;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* The full set of operations exposed on `client.<model>`. The generated client
|
|
323
|
+
* narrows every argument and return type per model; this is the untyped runtime
|
|
324
|
+
* surface they share.
|
|
325
|
+
*/
|
|
326
|
+
interface ModelDelegate {
|
|
327
|
+
findMany(args?: FindManyArgs): Promise<Record<string, unknown>[]>;
|
|
328
|
+
findFirst(args?: FindFirstArgs): Promise<Record<string, unknown> | null>;
|
|
329
|
+
findFirstOrThrow(args?: FindFirstArgs): Promise<Record<string, unknown>>;
|
|
330
|
+
findUnique(args: FindUniqueArgs): Promise<Record<string, unknown> | null>;
|
|
331
|
+
findUniqueOrThrow(args: FindUniqueArgs): Promise<Record<string, unknown>>;
|
|
332
|
+
create(args: CreateArgs): Promise<Record<string, unknown>>;
|
|
333
|
+
createMany(args: CreateManyArgs): Promise<{
|
|
334
|
+
count: number;
|
|
335
|
+
}>;
|
|
336
|
+
createManyAndReturn(args: CreateManyAndReturnArgs): Promise<Record<string, unknown>[]>;
|
|
337
|
+
update(args: UpdateArgs): Promise<Record<string, unknown>>;
|
|
338
|
+
updateMany(args: UpdateManyArgs): Promise<{
|
|
339
|
+
count: number;
|
|
340
|
+
}>;
|
|
341
|
+
upsert(args: UpsertArgs): Promise<Record<string, unknown>>;
|
|
342
|
+
delete(args: DeleteArgs): Promise<Record<string, unknown>>;
|
|
343
|
+
deleteMany(args?: DeleteManyArgs): Promise<{
|
|
344
|
+
count: number;
|
|
345
|
+
}>;
|
|
346
|
+
count(args?: CountArgs): Promise<number>;
|
|
347
|
+
aggregate(args?: AggregateArgs): Promise<Record<string, unknown>>;
|
|
348
|
+
groupBy(args: GroupByArgs): Promise<Record<string, unknown>[]>;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Client Extensions ($extends), middleware ($use) and the fluent API live here.
|
|
353
|
+
* The delegate factory composes per-operation query hooks, computes `result`
|
|
354
|
+
* fields, and returns fluent thenables for single-record reads.
|
|
355
|
+
*/
|
|
356
|
+
interface ResultFieldExtension {
|
|
357
|
+
needs?: Record<string, boolean>;
|
|
358
|
+
compute: (record: Record<string, unknown>) => unknown;
|
|
359
|
+
}
|
|
360
|
+
interface QueryHookParams {
|
|
361
|
+
model: string;
|
|
362
|
+
operation: string;
|
|
363
|
+
args: Record<string, unknown>;
|
|
364
|
+
query: (args: Record<string, unknown>) => Promise<unknown>;
|
|
365
|
+
}
|
|
366
|
+
type QueryHook = (params: QueryHookParams) => Promise<unknown>;
|
|
367
|
+
type HookMap = Record<string, QueryHook>;
|
|
368
|
+
interface EmberExtensionArgs {
|
|
369
|
+
name?: string;
|
|
370
|
+
result?: Record<string, Record<string, ResultFieldExtension>>;
|
|
371
|
+
model?: Record<string, Record<string, (...args: unknown[]) => unknown>>;
|
|
372
|
+
query?: Record<string, HookMap>;
|
|
373
|
+
client?: Record<string, unknown>;
|
|
374
|
+
}
|
|
375
|
+
/** Prisma-style middleware: `(params, next) => next(params)`. */
|
|
376
|
+
type Middleware = (params: {
|
|
377
|
+
model?: string;
|
|
378
|
+
action: string;
|
|
379
|
+
args: unknown;
|
|
380
|
+
}, next: (params: {
|
|
381
|
+
model?: string;
|
|
382
|
+
action: string;
|
|
383
|
+
args: unknown;
|
|
384
|
+
}) => Promise<unknown>) => Promise<unknown>;
|
|
385
|
+
|
|
386
|
+
interface ClientOptions {
|
|
387
|
+
/** Connection URL or explicit config. Overrides the schema datasource. */
|
|
388
|
+
datasourceUrl?: string;
|
|
389
|
+
datasource?: ConnectionConfig;
|
|
390
|
+
/** A pre-parsed schema document (the generated client passes its own). */
|
|
391
|
+
schema: SchemaDocument;
|
|
392
|
+
/**
|
|
393
|
+
* Query logging: `true` logs each statement to the console; pass a function
|
|
394
|
+
* to receive structured `QueryEvent`s (sql, params, durationMs, rowCount).
|
|
395
|
+
*/
|
|
396
|
+
log?: boolean | QueryLogger;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Runtime client. Builds one delegate per model from the schema and exposes
|
|
400
|
+
* Prisma-style lifecycle and transaction helpers. The generated client extends
|
|
401
|
+
* this and adds strongly-typed delegate properties.
|
|
402
|
+
*/
|
|
403
|
+
declare class EmberClientBase {
|
|
404
|
+
protected readonly driver: SqlDriver;
|
|
405
|
+
protected readonly engine: QueryEngine;
|
|
406
|
+
protected readonly dialect: SqlDialect;
|
|
407
|
+
protected readonly schema: SchemaDocument;
|
|
408
|
+
private connected;
|
|
409
|
+
/** Mutated by $extends (per instance) and $use (shared). */
|
|
410
|
+
protected extensions: EmberExtensionArgs[];
|
|
411
|
+
protected middlewares: Middleware[];
|
|
412
|
+
private readonly queryListeners;
|
|
413
|
+
private readonly baseLog?;
|
|
414
|
+
/** Dynamic model delegates, keyed by camelCased model name. */
|
|
415
|
+
[delegate: string]: unknown;
|
|
416
|
+
constructor(options: ClientOptions);
|
|
417
|
+
private dispatchQuery;
|
|
418
|
+
private delegateContext;
|
|
419
|
+
/** (Re)define one delegate property per model using the current extensions. */
|
|
420
|
+
private installDelegates;
|
|
421
|
+
/**
|
|
422
|
+
* Prisma-style Client Extensions. Returns a new client (the original is
|
|
423
|
+
* unchanged) that shares the connection/engine but applies the extension's
|
|
424
|
+
* `result` / `model` / `query` / `client` definitions.
|
|
425
|
+
*/
|
|
426
|
+
$extends(extension: EmberExtensionArgs): this;
|
|
427
|
+
/** Prisma-style middleware: runs around every operation. */
|
|
428
|
+
$use(middleware: Middleware): void;
|
|
429
|
+
/** Subscribe to query events (mirrors the `log` callback). */
|
|
430
|
+
$on(event: "query", listener: QueryLogger): void;
|
|
431
|
+
/** Type-safe access to a delegate by model name. */
|
|
432
|
+
model(name: string): ModelDelegate;
|
|
433
|
+
$connect(): Promise<void>;
|
|
434
|
+
$disconnect(): Promise<void>;
|
|
435
|
+
/**
|
|
436
|
+
* Run work inside a single transaction.
|
|
437
|
+
* - Interactive form: `$transaction(async (tx) => { ... })`.
|
|
438
|
+
* - Sequential form: `$transaction([(tx) => tx.user.create(...), ...])`.
|
|
439
|
+
*
|
|
440
|
+
* Because the driver tracks the active transaction via AsyncLocalStorage,
|
|
441
|
+
* every delegate call made on the passed client runs in the same transaction.
|
|
442
|
+
*/
|
|
443
|
+
$transaction<T>(fn: (tx: this) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
444
|
+
$transaction<T>(thunks: ((tx: this) => Promise<T>)[], options?: TransactionOptions): Promise<T[]>;
|
|
445
|
+
/** Execute a raw read query (returns rows) inside a transaction. */
|
|
446
|
+
$queryRawUnsafe<T = Record<string, unknown>>(sql: string, ...params: unknown[]): Promise<T[]>;
|
|
447
|
+
/** Execute a raw write statement inside a transaction; returns affected rows when available. */
|
|
448
|
+
$executeRawUnsafe(sql: string, ...params: unknown[]): Promise<number>;
|
|
449
|
+
/** Tagged-template raw query: `client.$queryRaw\`SELECT * FROM T WHERE id = ${id}\``. */
|
|
450
|
+
$queryRaw<T = Record<string, unknown>>(strings: TemplateStringsArray, ...values: unknown[]): Promise<T[]>;
|
|
451
|
+
$executeRaw(strings: TemplateStringsArray, ...values: unknown[]): Promise<number>;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Factory for an untyped client when you don't use the generated client.
|
|
455
|
+
* Prefer the generated `EmberClient` for full type-safety.
|
|
456
|
+
*/
|
|
457
|
+
declare function createClient(options: ClientOptions): EmberClientBase;
|
|
458
|
+
|
|
459
|
+
export { type AggregateArgs as A, type ConnectionConfig as C, type DriverOptions as D, EmberClientBase as E, type FindManyArgs as F, type GroupByArgs as G, type IncludeInput as I, type ModelDelegate as M, type OrderByInput as O, QueryEngine as Q, type ResultFieldExtension as R, type SqlDriver as S, type TransactionContext as T, type UpdateArgs as U, type WhereInput as W, type TransactionOptions as a, type SqlValue as b, type SqlDialect as c, type ClientOptions as d, type CreateArgs as e, type DeleteArgs as f, type FindUniqueArgs as g, FirebirdDialect as h, type IsolationLevel as i, type SelectInput as j, type UpsertArgs as k, createClient as l, type EmberExtensionArgs as m, type Middleware as n, type QueryEvent as o, type QueryHook as p, type QueryHookParams as q, type QueryLogger as r };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { S as SchemaDocument } from './index-D0xIdtCl.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Structural validation of a parsed schema. Throws SchemaValidationError with
|
|
5
|
+
* all detected problems at once so the user can fix them in a single pass.
|
|
6
|
+
*/
|
|
7
|
+
declare function validateSchema(doc: SchemaDocument): void;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Serializes a SchemaDocument back into `.ember` source text.
|
|
11
|
+
* Used by `ember db pull` (introspection output) and `ember format`.
|
|
12
|
+
* Field columns are aligned for readability, mirroring Prisma's formatter.
|
|
13
|
+
*/
|
|
14
|
+
declare function printSchema(doc: SchemaDocument): string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Canonical formatter: parse, auto-complete missing relation sides (like
|
|
18
|
+
* Prisma's formatter), validate, and re-print with aligned formatting.
|
|
19
|
+
*/
|
|
20
|
+
declare function formatSchema(source: string, file?: string): string;
|
|
21
|
+
/** Parse schema source text into an AST (no validation). */
|
|
22
|
+
declare function parseSchema(source: string, file?: string): SchemaDocument;
|
|
23
|
+
/** Parse and validate schema source text. */
|
|
24
|
+
declare function parseAndValidate(source: string, file?: string): SchemaDocument;
|
|
25
|
+
interface LoadedSchema {
|
|
26
|
+
document: SchemaDocument;
|
|
27
|
+
path: string;
|
|
28
|
+
/** Resolved connection URL (env() expanded). */
|
|
29
|
+
databaseUrl?: string;
|
|
30
|
+
}
|
|
31
|
+
/** Locate the schema file relative to a base directory. */
|
|
32
|
+
declare function findSchemaPath(base?: string, explicit?: string): string | undefined;
|
|
33
|
+
/** Load, parse, validate a schema file and resolve its datasource URL. */
|
|
34
|
+
declare function loadSchema(path: string): LoadedSchema;
|
|
35
|
+
declare function resolveDatasourceUrl(doc: SchemaDocument, _base: string): string | undefined;
|
|
36
|
+
|
|
37
|
+
/** Base class for every error thrown by EmberORM. */
|
|
38
|
+
declare class EmberError extends Error {
|
|
39
|
+
constructor(message: string);
|
|
40
|
+
}
|
|
41
|
+
/** Raised while lexing/parsing a `.ember` schema file. */
|
|
42
|
+
declare class SchemaParseError extends EmberError {
|
|
43
|
+
readonly line: number;
|
|
44
|
+
readonly column: number;
|
|
45
|
+
readonly file?: string | undefined;
|
|
46
|
+
constructor(message: string, line: number, column: number, file?: string | undefined);
|
|
47
|
+
}
|
|
48
|
+
/** Raised when a parsed schema is structurally invalid. */
|
|
49
|
+
declare class SchemaValidationError extends EmberError {
|
|
50
|
+
readonly details: string[];
|
|
51
|
+
constructor(message: string, details?: string[]);
|
|
52
|
+
}
|
|
53
|
+
/** Raised when a query is malformed before it reaches the database. */
|
|
54
|
+
declare class QueryValidationError extends EmberError {
|
|
55
|
+
}
|
|
56
|
+
/** Wraps a low-level driver/database failure with EmberORM context. */
|
|
57
|
+
declare class DatabaseError extends EmberError {
|
|
58
|
+
readonly cause?: unknown | undefined;
|
|
59
|
+
readonly sql?: string | undefined;
|
|
60
|
+
constructor(message: string, cause?: unknown | undefined, sql?: string | undefined);
|
|
61
|
+
}
|
|
62
|
+
/** Thrown by `*OrThrow` operations when no record matches. */
|
|
63
|
+
declare class RecordNotFoundError extends EmberError {
|
|
64
|
+
constructor(model: string);
|
|
65
|
+
}
|
|
66
|
+
/** Thrown on unique constraint violations (mapped from Firebird errors). */
|
|
67
|
+
declare class UniqueConstraintError extends EmberError {
|
|
68
|
+
readonly target: string;
|
|
69
|
+
constructor(target: string, cause?: unknown);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { DatabaseError as D, EmberError as E, type LoadedSchema as L, QueryValidationError as Q, RecordNotFoundError as R, SchemaParseError as S, UniqueConstraintError as U, SchemaValidationError as a, parseSchema as b, printSchema as c, findSchemaPath as d, formatSchema as f, loadSchema as l, parseAndValidate as p, resolveDatasourceUrl as r, validateSchema as v };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EmberORM schema AST (DMMF-like).
|
|
3
|
+
*
|
|
4
|
+
* This is the single in-memory source of truth that every other layer
|
|
5
|
+
* (parser, validator, query engine, generator, introspection) depends on.
|
|
6
|
+
* It is intentionally decoupled from Firebird specifics so it can be reused
|
|
7
|
+
* for other dialects in the future.
|
|
8
|
+
*/
|
|
9
|
+
type ScalarType = "String" | "Boolean" | "Int" | "BigInt" | "Float" | "Decimal" | "DateTime" | "Bytes" | "Json";
|
|
10
|
+
declare const SCALAR_TYPES: readonly ScalarType[];
|
|
11
|
+
type FieldKind = "scalar" | "enum" | "object";
|
|
12
|
+
/** Value of an attribute argument, e.g. `@default(now())` or `@map("USER_ID")`. */
|
|
13
|
+
type AttributeArgValue = {
|
|
14
|
+
kind: "string";
|
|
15
|
+
value: string;
|
|
16
|
+
} | {
|
|
17
|
+
kind: "number";
|
|
18
|
+
value: number;
|
|
19
|
+
} | {
|
|
20
|
+
kind: "boolean";
|
|
21
|
+
value: boolean;
|
|
22
|
+
} | {
|
|
23
|
+
kind: "ref";
|
|
24
|
+
value: string;
|
|
25
|
+
} | {
|
|
26
|
+
kind: "function";
|
|
27
|
+
name: string;
|
|
28
|
+
args: AttributeArgValue[];
|
|
29
|
+
} | {
|
|
30
|
+
kind: "array";
|
|
31
|
+
items: AttributeArgValue[];
|
|
32
|
+
};
|
|
33
|
+
interface DefaultValue {
|
|
34
|
+
/** A scalar literal default. */
|
|
35
|
+
literal?: string | number | boolean;
|
|
36
|
+
/** A function default such as now(), uuid(), cuid(), autoincrement(). */
|
|
37
|
+
function?: {
|
|
38
|
+
name: string;
|
|
39
|
+
args: AttributeArgValue[];
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
interface RelationInfo {
|
|
43
|
+
/** Relation name (@relation("name")). */
|
|
44
|
+
name?: string;
|
|
45
|
+
/** Local fields participating in the FK (`fields: [...]`). */
|
|
46
|
+
fields?: string[];
|
|
47
|
+
/** Referenced fields on the other model (`references: [...]`). */
|
|
48
|
+
references?: string[];
|
|
49
|
+
onDelete?: ReferentialAction;
|
|
50
|
+
onUpdate?: ReferentialAction;
|
|
51
|
+
}
|
|
52
|
+
type ReferentialAction = "Cascade" | "Restrict" | "NoAction" | "SetNull" | "SetDefault";
|
|
53
|
+
interface NativeType {
|
|
54
|
+
/** e.g. "VarChar", "Decimal". */
|
|
55
|
+
name: string;
|
|
56
|
+
/** e.g. [255] or [18, 4]. */
|
|
57
|
+
args: number[];
|
|
58
|
+
}
|
|
59
|
+
interface FieldNode {
|
|
60
|
+
name: string;
|
|
61
|
+
/** Resolved type name: a ScalarType, an enum name, or a model name. */
|
|
62
|
+
type: string;
|
|
63
|
+
kind: FieldKind;
|
|
64
|
+
isList: boolean;
|
|
65
|
+
isRequired: boolean;
|
|
66
|
+
isId: boolean;
|
|
67
|
+
isUnique: boolean;
|
|
68
|
+
isUpdatedAt: boolean;
|
|
69
|
+
/** Column name in the database (@map). Defaults to `name`. */
|
|
70
|
+
dbName?: string;
|
|
71
|
+
default?: DefaultValue;
|
|
72
|
+
relation?: RelationInfo;
|
|
73
|
+
nativeType?: NativeType;
|
|
74
|
+
/** documentation/comment attached above the field (///). */
|
|
75
|
+
documentation?: string;
|
|
76
|
+
}
|
|
77
|
+
interface UniqueIndex {
|
|
78
|
+
name?: string;
|
|
79
|
+
fields: string[];
|
|
80
|
+
}
|
|
81
|
+
interface IndexNode {
|
|
82
|
+
name?: string;
|
|
83
|
+
fields: string[];
|
|
84
|
+
unique: boolean;
|
|
85
|
+
}
|
|
86
|
+
interface ModelNode {
|
|
87
|
+
name: string;
|
|
88
|
+
/** Table name in the database (@@map). Defaults to `name`. */
|
|
89
|
+
dbName?: string;
|
|
90
|
+
fields: FieldNode[];
|
|
91
|
+
/** Names of fields forming the primary key (composite supported via @@id). */
|
|
92
|
+
primaryKey: string[];
|
|
93
|
+
uniqueIndexes: UniqueIndex[];
|
|
94
|
+
indexes: IndexNode[];
|
|
95
|
+
documentation?: string;
|
|
96
|
+
}
|
|
97
|
+
interface EnumNode {
|
|
98
|
+
name: string;
|
|
99
|
+
dbName?: string;
|
|
100
|
+
values: {
|
|
101
|
+
name: string;
|
|
102
|
+
dbName?: string;
|
|
103
|
+
}[];
|
|
104
|
+
documentation?: string;
|
|
105
|
+
}
|
|
106
|
+
interface DatasourceNode {
|
|
107
|
+
name: string;
|
|
108
|
+
provider: string;
|
|
109
|
+
/** Raw url expression; env("X") resolved at runtime. */
|
|
110
|
+
url: {
|
|
111
|
+
kind: "literal" | "env";
|
|
112
|
+
value: string;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
interface GeneratorNode {
|
|
116
|
+
name: string;
|
|
117
|
+
provider: string;
|
|
118
|
+
output?: string;
|
|
119
|
+
config: Record<string, string>;
|
|
120
|
+
}
|
|
121
|
+
interface SchemaDocument {
|
|
122
|
+
datasource?: DatasourceNode;
|
|
123
|
+
generators: GeneratorNode[];
|
|
124
|
+
models: ModelNode[];
|
|
125
|
+
enums: EnumNode[];
|
|
126
|
+
}
|
|
127
|
+
declare function emptySchema(): SchemaDocument;
|
|
128
|
+
declare function findModel(schema: SchemaDocument, name: string): ModelNode | undefined;
|
|
129
|
+
declare function findEnum(schema: SchemaDocument, name: string): EnumNode | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* Physical column name. Firebird folds unquoted identifiers to UPPER CASE, and
|
|
132
|
+
* EmberORM always quotes identifiers, so a field without an explicit `@map`
|
|
133
|
+
* resolves to its UPPER-CASED name to match the stored column. Use `@map` to
|
|
134
|
+
* target a column created with case-sensitive (quoted) lower/mixed case.
|
|
135
|
+
*/
|
|
136
|
+
declare function fieldColumn(field: FieldNode): string;
|
|
137
|
+
/** Physical table name; same UPPER-CASE folding rule as {@link fieldColumn}. */
|
|
138
|
+
declare function modelTable(model: ModelNode): string;
|
|
139
|
+
/** Returns scalar fields only (excludes relation/object fields). */
|
|
140
|
+
declare function scalarFields(model: ModelNode): FieldNode[];
|
|
141
|
+
/** Returns relation (object) fields only. */
|
|
142
|
+
declare function relationFields(model: ModelNode): FieldNode[];
|
|
143
|
+
declare function idFields(model: ModelNode): FieldNode[];
|
|
144
|
+
|
|
145
|
+
export { type AttributeArgValue as A, type DatasourceNode as D, type EnumNode as E, type FieldNode as F, type GeneratorNode as G, type IndexNode as I, type ModelNode as M, type NativeType as N, type ReferentialAction as R, type SchemaDocument as S, type UniqueIndex as U, SCALAR_TYPES as a, type ScalarType as b, type DefaultValue as c, type FieldKind as d, type RelationInfo as e, emptySchema as f, fieldColumn as g, findEnum as h, findModel as i, idFields as j, modelTable as m, relationFields as r, scalarFields as s };
|