uql-orm 0.22.0 → 0.23.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/dist/browser/uql-browser.min.js.map +3 -3
- package/dist/dialect/abstractSqlDialect.d.ts +14 -1
- package/dist/dialect/abstractSqlDialect.js +21 -14
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +11 -1
- package/dist/dialect/mysqlLikeSqlDialect.js +25 -0
- package/dist/dialect/pgLikeSqlDialect.d.ts +4 -7
- package/dist/dialect/pgLikeSqlDialect.js +7 -12
- package/dist/entity/decorator/bag.d.ts +35 -0
- package/dist/entity/decorator/bag.js +54 -0
- package/dist/entity/decorator/entity.d.ts +28 -2
- package/dist/entity/decorator/entity.js +40 -2
- package/dist/entity/decorator/members.d.ts +51 -0
- package/dist/entity/decorator/members.js +51 -0
- package/dist/entity/index.d.ts +3 -1
- package/dist/entity/index.js +3 -1
- package/dist/entity/metadata/definition.d.ts +23 -9
- package/dist/entity/metadata/definition.js +55 -100
- package/dist/http/contract.js +1 -2
- package/dist/http/handler.js +5 -26
- package/dist/http/query.js +1 -1
- package/dist/migrate/acquireQuerierForMigrations.d.ts +13 -1
- package/dist/migrate/acquireQuerierForMigrations.js +28 -0
- package/dist/migrate/cli-config.js +24 -8
- package/dist/migrate/cli.js +5 -1
- package/dist/migrate/codegen/entityCodeGenerator.js +3 -4
- package/dist/migrate/codegen/index.d.ts +0 -1
- package/dist/migrate/codegen/index.js +0 -2
- package/dist/migrate/drift/driftDetector.d.ts +10 -1
- package/dist/migrate/drift/driftDetector.js +22 -5
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +5 -1
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +17 -27
- package/dist/migrate/introspection/mongoIntrospector.js +7 -13
- package/dist/migrate/migrator.js +44 -81
- package/dist/migrate/storage/databaseStorage.d.ts +2 -0
- package/dist/migrate/storage/databaseStorage.js +8 -23
- package/dist/mongo/mongodbQuerier.js +171 -229
- package/dist/nestjs/uqlContextInterceptor.js +58 -22
- package/dist/nestjs/uqlModule.d.ts +2 -11
- package/dist/nestjs/uqlModule.js +93 -44
- package/dist/postgres/postgresDialect.js +2 -2
- package/dist/querier/abstractQuerier.d.ts +28 -0
- package/dist/querier/abstractQuerier.js +47 -22
- package/dist/querier/abstractQuerierPool.d.ts +3 -0
- package/dist/querier/abstractQuerierPool.js +5 -3
- package/dist/querier/abstractSqlQuerier.d.ts +1 -3
- package/dist/querier/abstractSqlQuerier.js +48 -96
- package/dist/querier/index.d.ts +3 -1
- package/dist/querier/index.js +3 -1
- package/dist/querier/querierContext.browser.d.ts +12 -0
- package/dist/querier/querierContext.browser.js +18 -0
- package/dist/querier/querierContext.d.ts +22 -0
- package/dist/querier/querierContext.js +42 -0
- package/dist/querier/queryError.d.ts +22 -0
- package/dist/querier/queryError.js +20 -0
- package/dist/querier/transactional.d.ts +26 -0
- package/dist/querier/transactional.js +43 -0
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/schemaASTBuilder.d.ts +1 -1
- package/dist/schema/schemaASTBuilder.js +2 -2
- package/dist/schema/types.d.ts +0 -21
- package/dist/sqlite/abstractSqliteQuerier.d.ts +9 -2
- package/dist/sqlite/hranaQuerier.js +20 -42
- package/dist/sqlite/index.d.ts +1 -0
- package/dist/sqlite/index.js +1 -0
- package/dist/sqlite/localSqliteQuerierPool.d.ts +31 -0
- package/dist/sqlite/localSqliteQuerierPool.js +34 -0
- package/dist/sqlite/nodeSqliteAdapter.d.ts +35 -0
- package/dist/sqlite/nodeSqliteAdapter.js +28 -0
- package/dist/sqlite/nodeSqliteQuerierPool.d.ts +28 -0
- package/dist/sqlite/nodeSqliteQuerierPool.js +29 -0
- package/dist/sqlite/sqliteDialect.d.ts +1 -2
- package/dist/sqlite/sqliteDialect.js +0 -13
- package/dist/sqlite/sqliteQuerierPool.d.ts +10 -23
- package/dist/sqlite/sqliteQuerierPool.js +9 -28
- package/dist/type/entity.d.ts +95 -28
- package/dist/type/querier.d.ts +6 -0
- package/dist/util/hook.util.js +1 -1
- package/package.json +8 -16
- package/dist/entity/decorator/field.d.ts +0 -2
- package/dist/entity/decorator/field.js +0 -7
- package/dist/entity/decorator/filter.d.ts +0 -7
- package/dist/entity/decorator/filter.js +0 -11
- package/dist/entity/decorator/hook.d.ts +0 -7
- package/dist/entity/decorator/hook.js +0 -14
- package/dist/entity/decorator/id.d.ts +0 -2
- package/dist/entity/decorator/id.js +0 -7
- package/dist/entity/decorator/index-decorator.d.ts +0 -22
- package/dist/entity/decorator/index-decorator.js +0 -26
- package/dist/entity/decorator/index.d.ts +0 -8
- package/dist/entity/decorator/index.js +0 -8
- package/dist/entity/decorator/relation.d.ts +0 -8
- package/dist/entity/decorator/relation.js +0 -19
- package/dist/migrate/codegen/smartRelationDetector.d.ts +0 -47
- package/dist/migrate/codegen/smartRelationDetector.js +0 -134
- package/dist/querier/decorator/index.d.ts +0 -4
- package/dist/querier/decorator/index.js +0 -4
- package/dist/querier/decorator/injectQuerier.d.ts +0 -3
- package/dist/querier/decorator/injectQuerier.js +0 -33
- package/dist/querier/decorator/log.d.ts +0 -32
- package/dist/querier/decorator/log.js +0 -52
- package/dist/querier/decorator/serialized.d.ts +0 -6
- package/dist/querier/decorator/serialized.js +0 -13
- package/dist/querier/decorator/transactional.d.ts +0 -6
- package/dist/querier/decorator/transactional.js +0 -48
|
@@ -1,34 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { AbstractLocalSqliteQuerierPool } from './localSqliteQuerierPool.js';
|
|
2
|
+
/**
|
|
3
|
+
* Pool for `better-sqlite3`, or `bun:sqlite` when running under Bun - the same file, through whichever
|
|
4
|
+
* driver the runtime provides.
|
|
5
|
+
*/
|
|
6
|
+
export class Sqlite3QuerierPool extends AbstractLocalSqliteQuerierPool {
|
|
5
7
|
filename;
|
|
6
|
-
opts;
|
|
7
|
-
db;
|
|
8
8
|
constructor(filename = ':memory:', opts, extra) {
|
|
9
|
-
super(
|
|
9
|
+
super(opts, extra);
|
|
10
10
|
this.filename = filename;
|
|
11
|
-
this.opts = opts;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
* The database handle is shared (single connection), but each acquisition gets its own querier
|
|
15
|
-
* so transaction state stays per unit of work.
|
|
16
|
-
*/
|
|
17
|
-
async getQuerier() {
|
|
18
|
-
this.db ??= await this.openDb();
|
|
19
|
-
return new SqliteQuerier(this.db, this.dialect, this.extra);
|
|
20
|
-
}
|
|
21
|
-
async openDb() {
|
|
12
|
+
async createDb() {
|
|
22
13
|
// `bun:sqlite` rejects option keys it does not know, and rejects an options object carrying no
|
|
23
14
|
// open flags, so `extensions` is stripped out and what remains of it collapses back to nothing.
|
|
24
15
|
const { extensions, ...driverOpts } = this.opts ?? {};
|
|
25
|
-
const
|
|
26
|
-
for (const extension of extensions ?? []) {
|
|
27
|
-
db.loadExtension(extension);
|
|
28
|
-
}
|
|
29
|
-
return db;
|
|
30
|
-
}
|
|
31
|
-
async openDriverDb(opts) {
|
|
16
|
+
const opts = Object.keys(driverOpts).length > 0 ? driverOpts : undefined;
|
|
32
17
|
if (typeof Bun !== 'undefined') {
|
|
33
18
|
const { Database: BunDatabase } = await import('bun:sqlite');
|
|
34
19
|
const { adaptBunSqlite } = await import('./bunSqliteAdapter.bun.js');
|
|
@@ -41,8 +26,4 @@ export class Sqlite3QuerierPool extends AbstractSqlQuerierPool {
|
|
|
41
26
|
db.pragma('journal_mode = WAL');
|
|
42
27
|
return db;
|
|
43
28
|
}
|
|
44
|
-
async end() {
|
|
45
|
-
await this.db?.close();
|
|
46
|
-
this.db = undefined;
|
|
47
|
-
}
|
|
48
29
|
}
|
package/dist/type/entity.d.ts
CHANGED
|
@@ -175,14 +175,36 @@ export type JsonColumnType = 'json' | 'jsonb';
|
|
|
175
175
|
* SQL binary/blob column types
|
|
176
176
|
*/
|
|
177
177
|
export type BlobColumnType = 'blob' | 'bytea';
|
|
178
|
+
/**
|
|
179
|
+
* SQL boolean column types
|
|
180
|
+
*/
|
|
181
|
+
export type BooleanColumnType = 'bool' | 'boolean';
|
|
182
|
+
/**
|
|
183
|
+
* SQL vector column types
|
|
184
|
+
*/
|
|
185
|
+
export type VectorColumnType = 'vector' | 'halfvec' | 'sparsevec';
|
|
178
186
|
/**
|
|
179
187
|
* SQL column types supported by uql migrations
|
|
180
188
|
*/
|
|
181
|
-
export type ColumnType = NumericColumnType | StringColumnType | DateColumnType | JsonColumnType | BlobColumnType |
|
|
189
|
+
export type ColumnType = NumericColumnType | StringColumnType | DateColumnType | JsonColumnType | BlobColumnType | BooleanColumnType | VectorColumnType;
|
|
182
190
|
/**
|
|
183
191
|
* Logical types for a field
|
|
184
192
|
*/
|
|
185
193
|
export type FieldType = StringConstructor | NumberConstructor | BooleanConstructor | DateConstructor | BigIntConstructor | ColumnType;
|
|
194
|
+
/**
|
|
195
|
+
* The {@link FieldType} values legal for a field declared as `V`.
|
|
196
|
+
*
|
|
197
|
+
* This is what makes an explicit `type` an improvement over the reflected one it replaces: the
|
|
198
|
+
* annotation is checked against the property's real TypeScript type, so `@Field({ type: String })` on
|
|
199
|
+
* a `number` no longer compiles into a silent TEXT column. `unknown` shapes fall through to the full
|
|
200
|
+
* {@link FieldType}, keeping genuinely untyped fields usable.
|
|
201
|
+
*
|
|
202
|
+
* JSON is matched on the `__json` brand rather than structurally, because {@link Json} intersects its
|
|
203
|
+
* payload (`Json<string>` really does extend `string`) and would otherwise land on the string arm.
|
|
204
|
+
* Both `Json<T>` and `Json<T>[]` have to be recognised, and the array check has to precede the scalar
|
|
205
|
+
* arms so a `number[]` vector is not read as a `number`.
|
|
206
|
+
*/
|
|
207
|
+
export type TypeFor<V, T = NonNullable<V>> = IsJson<T> extends true ? JsonColumnType : IsJson<NonNullable<Unpacked<T>>> extends true ? JsonColumnType : T extends readonly number[] ? VectorColumnType : T extends string ? StringConstructor | StringColumnType : T extends number ? NumberConstructor | NumericColumnType : T extends bigint ? BigIntConstructor | NumericColumnType : T extends boolean ? BooleanConstructor | BooleanColumnType : T extends Date ? DateConstructor | DateColumnType : T extends Uint8Array ? BlobColumnType : FieldType;
|
|
186
208
|
/**
|
|
187
209
|
* Configurable options for a field
|
|
188
210
|
*/
|
|
@@ -191,11 +213,13 @@ export type FieldOptions = {
|
|
|
191
213
|
readonly isId?: true;
|
|
192
214
|
readonly type?: FieldType;
|
|
193
215
|
/**
|
|
194
|
-
* Set by `defineField` when `
|
|
195
|
-
*
|
|
216
|
+
* Set by `defineField` when the field gave `references` but no `type`, so schema generation resolves
|
|
217
|
+
* the column from the referenced primary key rather than from whatever ended up in `type`. That is
|
|
218
|
+
* what keeps a `uuid` primary key from becoming TEXT on every foreign key pointing at it.
|
|
219
|
+
* Internal bookkeeping - do not set this from a decorator.
|
|
196
220
|
* @internal
|
|
197
221
|
*/
|
|
198
|
-
readonly
|
|
222
|
+
readonly typeFromReference?: boolean;
|
|
199
223
|
/**
|
|
200
224
|
* Dimensions for vector fields. Used in schema generation.
|
|
201
225
|
* @example `@Field({ type: 'vector', dimensions: 1536 })`
|
|
@@ -270,6 +294,55 @@ export type FieldOptions = {
|
|
|
270
294
|
readonly comment?: string;
|
|
271
295
|
};
|
|
272
296
|
export type OnFieldCallback = Scalar | QueryRaw | (() => Scalar | QueryRaw);
|
|
297
|
+
/**
|
|
298
|
+
* The TypeScript types a field may be declared as, given the `type` it registers: the inverse of
|
|
299
|
+
* {@link TypeFor}.
|
|
300
|
+
*
|
|
301
|
+
* Both directions are needed because they are consumed at opposite ends. `defineEntity` keys its bulk
|
|
302
|
+
* `fields` by property name, so the property's type is already known and {@link TypeFor} narrows the
|
|
303
|
+
* `type` allowed. A decorator has it the other way round: `@Field({ type: String })` is checked before
|
|
304
|
+
* the class exists, so the only way to reach the property is to state what `type: String` implies and
|
|
305
|
+
* let the decorator's context position compare it against the real field. Neither can be derived from
|
|
306
|
+
* the other by inference, so `entityOptions.type-test.ts` asserts they agree instead.
|
|
307
|
+
*/
|
|
308
|
+
export type TsTypeOf<T> = T extends StringConstructor ? string : T extends NumberConstructor ? number : T extends BigIntConstructor ? bigint : T extends BooleanConstructor ? boolean : T extends DateConstructor ? Date : T extends StringColumnType ? string : T extends NumericColumnType ? number | bigint : T extends BooleanColumnType ? boolean : T extends DateColumnType ? Date : T extends JsonColumnType ? Json<unknown> | readonly Json<unknown>[] : T extends BlobColumnType ? Uint8Array : T extends VectorColumnType ? readonly number[] : unknown;
|
|
309
|
+
/**
|
|
310
|
+
* {@link FieldOptions} for a field declared as `V`, with `type` required and checked by
|
|
311
|
+
* {@link TypeFor}.
|
|
312
|
+
*
|
|
313
|
+
* The second arm is load-bearing rather than a convenience: a foreign-key column may omit `type` so
|
|
314
|
+
* that schema generation resolves it from the referenced primary key instead, picking up that key's
|
|
315
|
+
* `columnType`, length and chained references. Forcing `type: Number` onto
|
|
316
|
+
* `@Field({ references: () => Company })` would silently downgrade a `uuid` key to TEXT on every
|
|
317
|
+
* column pointing at it.
|
|
318
|
+
*/
|
|
319
|
+
export type FieldOptionsFor<V> = (FieldOptions & {
|
|
320
|
+
readonly type: TypeFor<V>;
|
|
321
|
+
}) | (FieldOptions & {
|
|
322
|
+
readonly references: EntityGetter;
|
|
323
|
+
readonly type?: TypeFor<V>;
|
|
324
|
+
});
|
|
325
|
+
/**
|
|
326
|
+
* The entity a relation field points at: `Company` for both `company?: Company` and
|
|
327
|
+
* `companies?: Company[]`.
|
|
328
|
+
*/
|
|
329
|
+
export type RelationTarget<V> = NonNullable<Unpacked<NonNullable<V>>>;
|
|
330
|
+
/**
|
|
331
|
+
* {@link RelationOptions} for a relation field declared as `V`, with `entity` required and pinned to
|
|
332
|
+
* `V`'s own type, and the cardinality restricted to the ones that field shape can hold. Together those
|
|
333
|
+
* reject `@ManyToOne({ entity: () => Other })` on a `Company` field, and any to-many cardinality on a
|
|
334
|
+
* field that is not an array.
|
|
335
|
+
*/
|
|
336
|
+
export type RelationOptionsFor<V> = Omit<RelationOptions<RelationTarget<V>>, 'entity' | 'cardinality'> & {
|
|
337
|
+
readonly entity: EntityGetter<RelationTarget<V>>;
|
|
338
|
+
readonly cardinality: NonNullable<V> extends readonly unknown[] ? '1m' | 'mm' : '11' | 'm1';
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* The method names of an entity, so hook registrations name a method that exists.
|
|
342
|
+
*/
|
|
343
|
+
export type MethodKey<E> = {
|
|
344
|
+
readonly [K in keyof E]-?: NonNullable<E[K]> extends (...args: never[]) => unknown ? K : never;
|
|
345
|
+
}[Key<E>];
|
|
273
346
|
export type EntityGetter<E = any> = () => Type<E>;
|
|
274
347
|
export type CascadeType = 'persist' | 'delete';
|
|
275
348
|
export type RelationOptions<E = any> = {
|
|
@@ -299,20 +372,6 @@ export type RelationOneToOneOptions<E> = RelationOptionsOwner<E> | RelationOptio
|
|
|
299
372
|
export type RelationOneToManyOptions<E> = RelationOptionsInverseSide<E> | RelationOptionsThroughOwner<E>;
|
|
300
373
|
export type RelationManyToOneOptions<E> = RelationOptionsOwner<E>;
|
|
301
374
|
export type RelationManyToManyOptions<E> = RelationOptionsThroughOwner<E> | RelationOptionsInverseSide<E>;
|
|
302
|
-
/**
|
|
303
|
-
* Wrapper type for relation type definitions in entities.
|
|
304
|
-
* Used to circumvent ESM modules circular dependency issue caused by reflection metadata saving the type of the property.
|
|
305
|
-
*
|
|
306
|
-
* Usage example:
|
|
307
|
-
* @Entity()
|
|
308
|
-
* export default class User {
|
|
309
|
-
*
|
|
310
|
-
* @OneToOne(() => Profile, profile => profile.user)
|
|
311
|
-
* profile: Relation<Profile>;
|
|
312
|
-
*
|
|
313
|
-
* }
|
|
314
|
-
*/
|
|
315
|
-
export type Relation<T> = T;
|
|
316
375
|
/**
|
|
317
376
|
* Lifecycle hook event names.
|
|
318
377
|
*/
|
|
@@ -354,8 +413,12 @@ export type IndexTypeOptions = {
|
|
|
354
413
|
* @Index([{ column: 'body', length: 64 }]) // MySQL needs a prefix on TEXT
|
|
355
414
|
* @Index(['data'], { type: 'gin' }) // JSONB containment
|
|
356
415
|
* ```
|
|
416
|
+
*
|
|
417
|
+
* `C` is the entity's `FieldKey` on the `@Index`/`defineEntity` paths, where the decorated class says
|
|
418
|
+
* which columns exist. It defaults to `string` for the migration builder's `table.index(...)`, which
|
|
419
|
+
* names raw table columns with no entity in scope.
|
|
357
420
|
*/
|
|
358
|
-
export type IndexColumnInput = string | QueryRaw | IndexColumnOptions
|
|
421
|
+
export type IndexColumnInput<C extends string = string> = C | QueryRaw | IndexColumnOptions<C>;
|
|
359
422
|
/**
|
|
360
423
|
* What an index entry can carry besides the thing being indexed. Shared with the normalized
|
|
361
424
|
* `IndexColumnSchema`, so the authored and internal shapes cannot drift apart.
|
|
@@ -373,9 +436,9 @@ export type IndexColumnModifiers = {
|
|
|
373
436
|
/** Operator class, e.g. `jsonb_path_ops` for a smaller GIN index. Postgres only. */
|
|
374
437
|
readonly opsClass?: string;
|
|
375
438
|
};
|
|
376
|
-
export type IndexColumnOptions = IndexColumnModifiers & {
|
|
439
|
+
export type IndexColumnOptions<C extends string = string> = IndexColumnModifiers & {
|
|
377
440
|
/** The column to index, or `raw(...)` for an expression. */
|
|
378
|
-
readonly column:
|
|
441
|
+
readonly column: C | QueryRaw;
|
|
379
442
|
};
|
|
380
443
|
/**
|
|
381
444
|
* One index entry, normalized: {@link IndexColumnInput}'s three authored shapes all reduce to this
|
|
@@ -439,11 +502,15 @@ export type EntityOptions<E = unknown> = {
|
|
|
439
502
|
/** Named, default-on `$where` filters (soft-delete is auto-registered from `@Field({ softDelete })`). */
|
|
440
503
|
readonly filters?: Record<string, FilterOptions<E>>;
|
|
441
504
|
/** Scalar fields; use `isId: true` on exactly one field for the primary key. */
|
|
442
|
-
readonly fields?:
|
|
443
|
-
|
|
444
|
-
|
|
505
|
+
readonly fields?: {
|
|
506
|
+
readonly [K in FieldKey<E>]?: FieldOptionsFor<E[K]>;
|
|
507
|
+
};
|
|
508
|
+
readonly relations?: {
|
|
509
|
+
readonly [K in RelationKey<E>]?: RelationOptionsFor<E[K]>;
|
|
510
|
+
};
|
|
511
|
+
readonly indexes?: readonly EntityIndexInput<FieldKey<E>>[];
|
|
445
512
|
/** Map hook events to method names on the entity class. */
|
|
446
|
-
readonly hooks?: Partial<Record<HookEvent, readonly
|
|
513
|
+
readonly hooks?: Partial<Record<HookEvent, readonly MethodKey<E>[]>>;
|
|
447
514
|
};
|
|
448
515
|
/**
|
|
449
516
|
* Everything an index carries beyond its columns, shared by `@Index`, `defineEntity` and the
|
|
@@ -452,9 +519,9 @@ export type EntityOptions<E = unknown> = {
|
|
|
452
519
|
*/
|
|
453
520
|
export type IndexOptions = DistributiveOmit<EntityIndexMeta, 'columns'>;
|
|
454
521
|
/**
|
|
455
|
-
* An index as authored, before
|
|
522
|
+
* An index as authored, before `defineIndex` normalizes its columns.
|
|
456
523
|
*/
|
|
457
|
-
export type EntityIndexInput = IndexOptions & {
|
|
458
|
-
readonly columns: readonly IndexColumnInput[];
|
|
524
|
+
export type EntityIndexInput<C extends string = string> = IndexOptions & {
|
|
525
|
+
readonly columns: readonly IndexColumnInput<C>[];
|
|
459
526
|
};
|
|
460
527
|
export {};
|
package/dist/type/querier.d.ts
CHANGED
|
@@ -120,6 +120,12 @@ export interface Querier extends UniversalQuerier {
|
|
|
120
120
|
* release the querier to the pool.
|
|
121
121
|
*/
|
|
122
122
|
release(): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Releases the querier when an `await using` binding goes out of scope, so a unit of work cannot
|
|
125
|
+
* leak a connection on an early return or a throw.
|
|
126
|
+
* @example `await using querier = await pool.getQuerier();`
|
|
127
|
+
*/
|
|
128
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
123
129
|
}
|
|
124
130
|
export interface SqlQuerier extends Querier {
|
|
125
131
|
/**
|
package/dist/util/hook.util.js
CHANGED
package/package.json
CHANGED
|
@@ -3,16 +3,17 @@
|
|
|
3
3
|
"homepage": "https://uql-orm.dev",
|
|
4
4
|
"description": "Extremely fast, type-safe TypeScript ORM - one API for every database",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.23.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"engines": {
|
|
9
|
-
"node": ">=
|
|
9
|
+
"node": ">=24"
|
|
10
10
|
},
|
|
11
11
|
"sideEffects": false,
|
|
12
12
|
"main": "./dist/index.js",
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
14
|
"browser": {
|
|
15
|
-
"./dist/context/context.js": "./dist/context/context.browser.js"
|
|
15
|
+
"./dist/context/context.js": "./dist/context/context.browser.js",
|
|
16
|
+
"./dist/querier/querierContext.js": "./dist/querier/querierContext.browser.js"
|
|
16
17
|
},
|
|
17
18
|
"bin": {
|
|
18
19
|
"uql-migrate": "./dist/migrate/bin.js"
|
|
@@ -72,13 +73,11 @@
|
|
|
72
73
|
"@tursodatabase/serverless": ">=1.0.0",
|
|
73
74
|
"better-sqlite3": ">=9.0.0",
|
|
74
75
|
"express": ">=5.0.0",
|
|
75
|
-
"jiti": ">=2.0.0",
|
|
76
76
|
"mariadb": ">=3.0.0",
|
|
77
77
|
"mongodb": ">=6.0.0",
|
|
78
78
|
"mysql2": ">=3.0.0",
|
|
79
79
|
"pg": ">=8.0.0",
|
|
80
80
|
"pg-query-stream": ">=4.0.0",
|
|
81
|
-
"reflect-metadata": ">=0.2.0",
|
|
82
81
|
"rxjs": ">=7.0.0"
|
|
83
82
|
},
|
|
84
83
|
"peerDependenciesMeta": {
|
|
@@ -106,9 +105,6 @@
|
|
|
106
105
|
"express": {
|
|
107
106
|
"optional": true
|
|
108
107
|
},
|
|
109
|
-
"jiti": {
|
|
110
|
-
"optional": true
|
|
111
|
-
},
|
|
112
108
|
"mariadb": {
|
|
113
109
|
"optional": true
|
|
114
110
|
},
|
|
@@ -124,9 +120,6 @@
|
|
|
124
120
|
"pg-query-stream": {
|
|
125
121
|
"optional": true
|
|
126
122
|
},
|
|
127
|
-
"reflect-metadata": {
|
|
128
|
-
"optional": true
|
|
129
|
-
},
|
|
130
123
|
"rxjs": {
|
|
131
124
|
"optional": true
|
|
132
125
|
}
|
|
@@ -139,21 +132,20 @@
|
|
|
139
132
|
"@nestjs/testing": "^11.1.28",
|
|
140
133
|
"@tursodatabase/database": "^0.7.2",
|
|
141
134
|
"@tursodatabase/serverless": "^1.4.0",
|
|
142
|
-
"@types/better-sqlite3": "^
|
|
135
|
+
"@types/better-sqlite3": "^9.6.0",
|
|
143
136
|
"@types/express": "^5.0.6",
|
|
144
|
-
"@types/pg": "^8.20.
|
|
137
|
+
"@types/pg": "^8.20.3",
|
|
145
138
|
"@types/ws": "^8.18.1",
|
|
146
139
|
"better-sqlite3": "^13.0.2",
|
|
147
140
|
"express": "^5.2.1",
|
|
148
|
-
"jiti": "^2.7.0",
|
|
149
141
|
"mariadb": "^3.5.3",
|
|
150
142
|
"mongodb": "^7.5.0",
|
|
151
143
|
"mysql2": "^3.23.2",
|
|
152
144
|
"pg": "^8.22.0",
|
|
153
145
|
"pg-query-stream": "^4.16.0",
|
|
154
|
-
"reflect-metadata": "^0.2.2",
|
|
155
146
|
"rxjs": "^7.8.2",
|
|
156
147
|
"sqlite-vec": "^0.1.9",
|
|
148
|
+
"tsx": "^4.23.1",
|
|
157
149
|
"ws": "^8.21.1"
|
|
158
150
|
},
|
|
159
151
|
"author": "Roger Padilla",
|
|
@@ -207,5 +199,5 @@
|
|
|
207
199
|
"publishConfig": {
|
|
208
200
|
"access": "public"
|
|
209
201
|
},
|
|
210
|
-
"gitHead": "
|
|
202
|
+
"gitHead": "3bfca5950ac564b8503fb2140726501b01825b9d"
|
|
211
203
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { FilterOptions, Type } from '../../type/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Registers a named, default-on `$where` filter on the entity, applied to every query
|
|
4
|
-
* unless bypassed via `QueryOptions.filters`.
|
|
5
|
-
* @example `@Filter('active', { condition: { status: 'active' }, default: false })`
|
|
6
|
-
*/
|
|
7
|
-
export declare function Filter<E>(name: string, opts: FilterOptions<E>): (entity: Type<E>) => void;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { defineFilter } from '../metadata/definition.js';
|
|
2
|
-
/**
|
|
3
|
-
* Registers a named, default-on `$where` filter on the entity, applied to every query
|
|
4
|
-
* unless bypassed via `QueryOptions.filters`.
|
|
5
|
-
* @example `@Filter('active', { condition: { status: 'active' }, default: false })`
|
|
6
|
-
*/
|
|
7
|
-
export function Filter(name, opts) {
|
|
8
|
-
return (entity) => {
|
|
9
|
-
defineFilter(entity, name, opts);
|
|
10
|
-
};
|
|
11
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const BeforeInsert: () => MethodDecorator;
|
|
2
|
-
export declare const AfterInsert: () => MethodDecorator;
|
|
3
|
-
export declare const BeforeUpdate: () => MethodDecorator;
|
|
4
|
-
export declare const AfterUpdate: () => MethodDecorator;
|
|
5
|
-
export declare const BeforeDelete: () => MethodDecorator;
|
|
6
|
-
export declare const AfterDelete: () => MethodDecorator;
|
|
7
|
-
export declare const AfterLoad: () => MethodDecorator;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { defineHook } from '../metadata/definition.js';
|
|
2
|
-
function createHookDecorator(event) {
|
|
3
|
-
return () => (target, key) => {
|
|
4
|
-
const entity = target.constructor;
|
|
5
|
-
defineHook(entity, String(key), event);
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
export const BeforeInsert = createHookDecorator('beforeInsert');
|
|
9
|
-
export const AfterInsert = createHookDecorator('afterInsert');
|
|
10
|
-
export const BeforeUpdate = createHookDecorator('beforeUpdate');
|
|
11
|
-
export const AfterUpdate = createHookDecorator('afterUpdate');
|
|
12
|
-
export const BeforeDelete = createHookDecorator('beforeDelete');
|
|
13
|
-
export const AfterDelete = createHookDecorator('afterDelete');
|
|
14
|
-
export const AfterLoad = createHookDecorator('afterLoad');
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { IndexColumnInput, IndexOptions, Type } from '../../type/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Define a composite index on an entity class.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* @Index(['lastName', 'firstName'], { name: 'idx_users_fullname' })
|
|
8
|
-
* @Entity()
|
|
9
|
-
* export class User {
|
|
10
|
-
* @Id() id?: number;
|
|
11
|
-
* @Field() firstName?: string;
|
|
12
|
-
* @Field() lastName?: string;
|
|
13
|
-
* }
|
|
14
|
-
*
|
|
15
|
-
* // With unique and partial index
|
|
16
|
-
* @Index(['email'], { unique: true })
|
|
17
|
-
* @Index(['status'], { where: "status = 'active'" })
|
|
18
|
-
* @Entity()
|
|
19
|
-
* export class User { ... }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare function Index<E>(columns: readonly IndexColumnInput[], options?: IndexOptions): (target: Type<E>) => void;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { defineIndex } from '../metadata/definition.js';
|
|
2
|
-
/**
|
|
3
|
-
* Define a composite index on an entity class.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* @Index(['lastName', 'firstName'], { name: 'idx_users_fullname' })
|
|
8
|
-
* @Entity()
|
|
9
|
-
* export class User {
|
|
10
|
-
* @Id() id?: number;
|
|
11
|
-
* @Field() firstName?: string;
|
|
12
|
-
* @Field() lastName?: string;
|
|
13
|
-
* }
|
|
14
|
-
*
|
|
15
|
-
* // With unique and partial index
|
|
16
|
-
* @Index(['email'], { unique: true })
|
|
17
|
-
* @Index(['status'], { where: "status = 'active'" })
|
|
18
|
-
* @Entity()
|
|
19
|
-
* export class User { ... }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export function Index(columns, options = {}) {
|
|
23
|
-
return (target) => {
|
|
24
|
-
defineIndex(target, { ...options, columns });
|
|
25
|
-
};
|
|
26
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { defineEntity, defineField, defineFilter, defineHook, defineId, defineIndex, defineRelation, getEntities, getMeta, } from '../metadata/definition.js';
|
|
2
|
-
export * from './entity.js';
|
|
3
|
-
export * from './field.js';
|
|
4
|
-
export * from './filter.js';
|
|
5
|
-
export * from './hook.js';
|
|
6
|
-
export * from './id.js';
|
|
7
|
-
export * from './index-decorator.js';
|
|
8
|
-
export * from './relation.js';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { defineEntity, defineField, defineFilter, defineHook, defineId, defineIndex, defineRelation, getEntities, getMeta, } from '../metadata/definition.js';
|
|
2
|
-
export * from './entity.js';
|
|
3
|
-
export * from './field.js';
|
|
4
|
-
export * from './filter.js';
|
|
5
|
-
export * from './hook.js';
|
|
6
|
-
export * from './id.js';
|
|
7
|
-
export * from './index-decorator.js';
|
|
8
|
-
export * from './relation.js';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { RelationManyToManyOptions, RelationManyToOneOptions, RelationOneToManyOptions, RelationOneToOneOptions, RelationOptions } from '../../type/index.js';
|
|
2
|
-
declare function Relation<E>(opts: RelationOptions<E>): (target: object, key: string) => void;
|
|
3
|
-
type RelationReturn = ReturnType<typeof Relation>;
|
|
4
|
-
export declare function OneToOne<E>(opts?: RelationOneToOneOptions<E>): RelationReturn;
|
|
5
|
-
export declare function ManyToOne<E>(opts?: RelationManyToOneOptions<E>): RelationReturn;
|
|
6
|
-
export declare function OneToMany<E>(opts: RelationOneToManyOptions<E>): RelationReturn;
|
|
7
|
-
export declare function ManyToMany<E>(opts: RelationManyToManyOptions<E>): RelationReturn;
|
|
8
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { defineRelation } from '../metadata/definition.js';
|
|
2
|
-
function Relation(opts) {
|
|
3
|
-
return (target, key) => {
|
|
4
|
-
const entity = target.constructor;
|
|
5
|
-
defineRelation(entity, key, opts);
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
export function OneToOne(opts) {
|
|
9
|
-
return Relation({ cardinality: '11', ...opts });
|
|
10
|
-
}
|
|
11
|
-
export function ManyToOne(opts) {
|
|
12
|
-
return Relation({ cardinality: 'm1', ...opts });
|
|
13
|
-
}
|
|
14
|
-
export function OneToMany(opts) {
|
|
15
|
-
return Relation({ cardinality: '1m', ...opts });
|
|
16
|
-
}
|
|
17
|
-
export function ManyToMany(opts) {
|
|
18
|
-
return Relation({ cardinality: 'mm', ...opts });
|
|
19
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Smart Relation Detector
|
|
3
|
-
*
|
|
4
|
-
* Uses heuristics and schema analysis to detect relationships between tables:
|
|
5
|
-
* - Explicit foreign keys (highest confidence)
|
|
6
|
-
* - Junction tables for ManyToMany
|
|
7
|
-
* - Unique FK columns for OneToOne
|
|
8
|
-
*/
|
|
9
|
-
import type { SchemaAST } from '../../schema/schemaAST.js';
|
|
10
|
-
import type { DetectedRelation } from '../../schema/types.js';
|
|
11
|
-
/**
|
|
12
|
-
* Configuration for relation detection.
|
|
13
|
-
*/
|
|
14
|
-
export interface RelationDetectorOptions {
|
|
15
|
-
/** Minimum confidence threshold (0-1) to include in results */
|
|
16
|
-
minConfidence?: number;
|
|
17
|
-
/** Custom singularize function */
|
|
18
|
-
singularize?: (name: string) => string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Detects relationships in a SchemaAST using multiple heuristics.
|
|
22
|
-
*/
|
|
23
|
-
export declare class SmartRelationDetector {
|
|
24
|
-
private readonly ast;
|
|
25
|
-
private readonly options;
|
|
26
|
-
constructor(ast: SchemaAST, options?: RelationDetectorOptions);
|
|
27
|
-
/**
|
|
28
|
-
* Detect all relationships in the schema.
|
|
29
|
-
*/
|
|
30
|
-
detectAll(): DetectedRelation[];
|
|
31
|
-
/**
|
|
32
|
-
* Detect junction tables that represent ManyToMany relationships.
|
|
33
|
-
*/
|
|
34
|
-
private detectJunctionTables;
|
|
35
|
-
/**
|
|
36
|
-
* Detect relations where unique FK should upgrade to OneToOne.
|
|
37
|
-
*/
|
|
38
|
-
private detectOneToOneRelations;
|
|
39
|
-
/**
|
|
40
|
-
* Default singularize function (delegates to shared utility).
|
|
41
|
-
*/
|
|
42
|
-
private defaultSingularize;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Create a SmartRelationDetector for the given AST.
|
|
46
|
-
*/
|
|
47
|
-
export declare function createRelationDetector(ast: SchemaAST, options?: RelationDetectorOptions): SmartRelationDetector;
|