uql-orm 0.101.0 → 0.101.1
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/http/index.d.ts +2 -2
- package/dist/http/index.js +1 -2
- package/dist/libsql/index.d.ts +1 -1
- package/dist/libsql/index.js +1 -1
- package/dist/migrate/index.d.ts +8 -11
- package/dist/migrate/index.js +7 -17
- package/dist/mongodb/index.d.ts +1 -1
- package/dist/mongodb/index.js +1 -1
- package/dist/mongodb/mongodbQuerier.d.ts +3 -2
- package/dist/postgres/index.d.ts +1 -1
- package/dist/postgres/index.js +1 -1
- package/dist/querier/abstractQuerier.d.ts +10 -3
- package/dist/querier/abstractQuerier.js +12 -12
- package/dist/querier/abstractSqlQuerier.d.ts +3 -3
- package/dist/querier/abstractSqlQuerier.js +2 -2
- package/dist/sqlite/index.d.ts +1 -1
- package/dist/sqlite/index.js +1 -1
- package/package.json +1 -1
package/dist/http/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { CRUD_ROUTES, type CrudOperation, type CrudRoute, entityPath, type HttpMethod, type RequestErrorResponse, toErrorResponse, } from './contract.js';
|
|
2
2
|
export * from './fetchHandler.js';
|
|
3
3
|
export * from './handler.js';
|
|
4
|
-
export
|
|
4
|
+
export type { WireCursors, WireFlags } from './query.js';
|
package/dist/http/index.js
CHANGED
package/dist/libsql/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { LibsqlDialect } from './libsqlDialect.js';
|
|
2
2
|
export * from './libsqlQuerierPool.js';
|
package/dist/libsql/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { LibsqlDialect } from './libsqlDialect.js';
|
|
2
2
|
export * from './libsqlQuerierPool.js';
|
package/dist/migrate/index.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
export type { Change, ColumnSchema, DialectName, ForeignKeySchema, IndexSchema, Migration, MigrationDefinition, MigrationResult, MigratorOptions, PrimaryKeySchema, SchemaDiff, SchemaGenerator, SchemaIntrospector, SqlDialectName, SqlQuerier, SqlQueryDialect, SyncOptions, TableSchema, } from '../type/index.js';
|
|
2
|
-
export { type Config, isSqlQuerier } from '../type/index.js';
|
|
3
|
-
export { acquireQuerierForMigrations } from './acquireQuerierForMigrations.js';
|
|
4
|
-
export { assertCliConfig } from './assertCliConfig.js';
|
|
1
|
+
export type { Change, ColumnSchema, Config, DialectName, ForeignKeySchema, IndexSchema, Migration, MigrationDefinition, MigrationResult, MigratorOptions, PrimaryKeySchema, SchemaDiff, SchemaGenerator, SchemaIntrospector, SqlDialectName, SqlQuerier, SqlQueryDialect, SyncOptions, TableSchema, } from '../type/index.js';
|
|
5
2
|
export * from './builder/index.js';
|
|
6
|
-
export {
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export {
|
|
3
|
+
export { EntityCodeGenerator, type EntityCodeGeneratorOptions, type GeneratedEntity, } from './codegen/entityCodeGenerator.js';
|
|
4
|
+
export { buildMigrationModule, type MigrationModuleOptions, type MigrationQuerierType, } from './codegen/migrationFile.js';
|
|
5
|
+
export { AbstractSqlSchemaIntrospector } from './introspection/abstractSqlSchemaIntrospector.js';
|
|
6
|
+
export { MsSqlSchemaIntrospector } from './introspection/mssqlIntrospector.js';
|
|
7
|
+
export { MariadbSchemaIntrospector, MysqlSchemaIntrospector } from './introspection/mysqlIntrospector.js';
|
|
8
|
+
export { CockroachSchemaIntrospector, PostgresSchemaIntrospector } from './introspection/postgresIntrospector.js';
|
|
9
|
+
export { SqliteSchemaIntrospector } from './introspection/sqliteIntrospector.js';
|
|
12
10
|
export { type BuilderMigrationDefinition, defineBuilderMigration, defineMigration, Migrator } from './migrator.js';
|
|
13
|
-
export { reverseDiff } from './schemaChange.js';
|
|
14
11
|
export { SqlSchemaGenerator } from './schemaGenerator.js';
|
package/dist/migrate/index.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
export { isSqlQuerier } from '../type/index.js';
|
|
2
|
-
export { acquireQuerierForMigrations } from './acquireQuerierForMigrations.js';
|
|
3
|
-
export { assertCliConfig } from './assertCliConfig.js';
|
|
4
|
-
// Type-safe migration builder
|
|
5
1
|
export * from './builder/index.js';
|
|
6
|
-
export {
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
// Schema introspection
|
|
14
|
-
export * from './introspection/index.js';
|
|
15
|
-
// Main migrator
|
|
16
|
-
export { migrationBuilderFor } from './migrationTarget.js';
|
|
2
|
+
export { EntityCodeGenerator, } from './codegen/entityCodeGenerator.js';
|
|
3
|
+
export { buildMigrationModule, } from './codegen/migrationFile.js';
|
|
4
|
+
export { AbstractSqlSchemaIntrospector } from './introspection/abstractSqlSchemaIntrospector.js';
|
|
5
|
+
export { MsSqlSchemaIntrospector } from './introspection/mssqlIntrospector.js';
|
|
6
|
+
export { MariadbSchemaIntrospector, MysqlSchemaIntrospector } from './introspection/mysqlIntrospector.js';
|
|
7
|
+
export { CockroachSchemaIntrospector, PostgresSchemaIntrospector } from './introspection/postgresIntrospector.js';
|
|
8
|
+
export { SqliteSchemaIntrospector } from './introspection/sqliteIntrospector.js';
|
|
17
9
|
export { defineBuilderMigration, defineMigration, Migrator } from './migrator.js';
|
|
18
|
-
// Schema generators
|
|
19
|
-
export { reverseDiff } from './schemaChange.js';
|
|
20
10
|
export { SqlSchemaGenerator } from './schemaGenerator.js';
|
package/dist/mongodb/index.d.ts
CHANGED
package/dist/mongodb/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ClientSession, Document, MongoClient } from 'mongodb';
|
|
2
|
+
import type { UpsertedId } from '../querier/abstractQuerier.js';
|
|
2
3
|
import { AbstractQuerier } from '../querier/index.js';
|
|
3
|
-
import type { EntityData, ExtraOptions,
|
|
4
|
+
import type { EntityData, ExtraOptions, Query, QueryAggMap, QueryAggregate, QueryAggregateResult, QueryConflictPaths, QueryPage, QueryGroupMap, QueryOptions, QuerySearch, TransactionOptions, Type, UpdatePayload } from '../type/index.js';
|
|
4
5
|
import type { MongoDialect } from './mongoDialect.js';
|
|
5
6
|
import type { MongoQuerier } from './mongoQuerier.js';
|
|
6
7
|
export declare class MongodbQuerier extends AbstractQuerier implements MongoQuerier {
|
|
@@ -61,7 +62,7 @@ export declare class MongodbQuerier extends AbstractQuerier implements MongoQuer
|
|
|
61
62
|
* a concurrent one included, then takes `update`.
|
|
62
63
|
*/
|
|
63
64
|
private upsertWithUpdate;
|
|
64
|
-
protected internalUpsertMany<E extends Document>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E[], update?: UpdatePayload<E>): Promise<(
|
|
65
|
+
protected internalUpsertMany<E extends Document>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E[], update?: UpdatePayload<E>): Promise<(UpsertedId<E> | undefined)[]>;
|
|
65
66
|
protected internalDeleteMany<E extends Document>(entity: Type<E>, qm: QuerySearch<E>, opts?: QueryOptions): Promise<number>;
|
|
66
67
|
get hasOpenTransaction(): boolean;
|
|
67
68
|
/** Every read and write goes through here, which makes it where a released querier is caught. */
|
package/dist/postgres/index.d.ts
CHANGED
package/dist/postgres/index.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { AbstractDialect } from '../dialect/abstractDialect.js';
|
|
2
|
-
import type { BooleanLike, CursorPage, EntityData, EntityId, EntityWrite, ExtraOptions, FieldKey, Querier, Query, QueryAggMap, QueryAggregate, QueryAggregateResult, QueryConflictPaths, QueryFilter, QueryFindResult, QueryGroupMap, QueryKeysetProjected, QueryOneProjected, QueryOptions, QueryPage, QueryProjected, QuerySearch,
|
|
2
|
+
import type { BooleanLike, CursorPage, EntityData, EntityId, EntityWrite, ExtraOptions, FieldKey, Querier, Query, QueryAggMap, QueryAggregate, QueryAggregateResult, QueryConflictPaths, QueryFilter, QueryFindResult, QueryGroupMap, QueryKeysetProjected, QueryOneProjected, QueryOptions, QueryPage, QueryProjected, QuerySearch, RelationKey, SavepointCommand, TransactionOptions, Type, UpdatePayload, UpdateWrite, ReturningResult, WriteOptions, PrimaryKey, WrittenId } from '../type/index.js';
|
|
3
3
|
import { LoggerWrapper } from '../util/index.js';
|
|
4
4
|
import { type TransactionScope } from './transaction.js';
|
|
5
|
+
/**
|
|
6
|
+
* Writes the key an upsert reported onto each row that named none - only the key, since an `onInsert`
|
|
7
|
+
* value was never written to a row the upsert updated. A report aligns with the rows only when it
|
|
8
|
+
* speaks for every one: a `firstId` dialect reports nothing for a batch.
|
|
9
|
+
*/
|
|
10
|
+
/** What an upsert reports of a row: the value a driver answers for a lone key, or the key the read back names. */
|
|
11
|
+
export type UpsertedId<E> = PrimaryKey | WrittenId<E>;
|
|
5
12
|
/** Base class for all database queriers. */
|
|
6
13
|
export declare abstract class AbstractQuerier implements Querier {
|
|
7
14
|
#private;
|
|
@@ -174,7 +181,7 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
174
181
|
*/
|
|
175
182
|
private readThenUpsert;
|
|
176
183
|
/** Upserts `payload`, answering each row's key in payload order where the engine reports every one. */
|
|
177
|
-
protected abstract internalUpsertMany<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E[], update?: UpdatePayload<E>): Promise<(
|
|
184
|
+
protected abstract internalUpsertMany<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E[], update?: UpdatePayload<E>): Promise<(UpsertedId<E> | undefined)[] | undefined>;
|
|
178
185
|
deleteOneById<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true>(entity: Type<E>, id: EntityId<E>, opts?: QueryOptions & WriteOptions<E, S, V>): Promise<ReturningResult<S, number, QueryFindResult<E, S, V> | undefined>>;
|
|
179
186
|
/** Delete records matching the query, the entity passed first or as `$entity`; soft-deletes unless `opts.hardDelete`. */
|
|
180
187
|
deleteMany<E extends object>(q: QuerySearch<E> & {
|
|
@@ -278,7 +285,7 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
278
285
|
* statement that could not report them in payload order, or before a guarded upsert. A row that no
|
|
279
286
|
* read row matches, or that two do, keeps `undefined`: a missing id is honest where a guessed one is not.
|
|
280
287
|
*/
|
|
281
|
-
protected idsByConflict<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, rows: EntityData<E>[]): Promise<(
|
|
288
|
+
protected idsByConflict<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, rows: EntityData<E>[]): Promise<(WrittenId<E> | undefined)[]>;
|
|
282
289
|
/**
|
|
283
290
|
* Runs `write` between the event's `before`/`after` pair. The before hooks get the caller's rows, so
|
|
284
291
|
* what they assign is written; `write` and the after hooks get a copy, which by then carries what
|
|
@@ -99,19 +99,20 @@ function conflictAssignments(row, conflictPaths) {
|
|
|
99
99
|
}
|
|
100
100
|
return assigned;
|
|
101
101
|
}
|
|
102
|
-
/**
|
|
103
|
-
* Writes the key an upsert reported onto each row that named none - only the key, since an `onInsert`
|
|
104
|
-
* value was never written to a row the upsert updated. A report aligns with the rows only when it
|
|
105
|
-
* speaks for every one: a `firstId` dialect reports nothing for a batch.
|
|
106
|
-
*/
|
|
107
102
|
function adoptReportedIds(meta, rows, reported) {
|
|
108
|
-
if (
|
|
103
|
+
if (reported?.length !== rows.length) {
|
|
109
104
|
return;
|
|
110
105
|
}
|
|
111
106
|
const [idKey] = meta.ids;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
107
|
+
rows.forEach((row, index) => {
|
|
108
|
+
const id = reported[index];
|
|
109
|
+
if (meta.ids.length > 1) {
|
|
110
|
+
Object.assign(row, id);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
row[idKey] ??= id;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
115
116
|
}
|
|
116
117
|
/** Normalizes either call form to `[entity, query, opts]`, throwing when a query object has no `$entity`. */
|
|
117
118
|
function entityArgs(args) {
|
|
@@ -1016,20 +1017,19 @@ export class AbstractQuerier {
|
|
|
1016
1017
|
*/
|
|
1017
1018
|
async idsByConflict(entity, conflictPaths, rows) {
|
|
1018
1019
|
const meta = getMeta(entity);
|
|
1019
|
-
const [idKey] = meta.ids;
|
|
1020
1020
|
const keys = getKeys(conflictPaths);
|
|
1021
1021
|
// A null key never conflicts, so no row is read back for it, whether one key names the row or several.
|
|
1022
1022
|
const named = rows.filter((row) => keys.every((key) => row[key] != null));
|
|
1023
1023
|
const distinct = [...new Map(named.map((row) => [rowKey(row, keys), row])).values()];
|
|
1024
1024
|
const found = [];
|
|
1025
1025
|
for (const batch of chunk(distinct, this.dialect.keyListCapacity(keys.length))) {
|
|
1026
|
-
const q = { $select: keySet([
|
|
1026
|
+
const q = { $select: keySet([...meta.ids, ...keys]), $where: whereKeysIn(keys, batch) };
|
|
1027
1027
|
found.push(await this.internalFindMany(entity, q, { filters: withoutSoftDeleteFilter(undefined) }));
|
|
1028
1028
|
}
|
|
1029
1029
|
const byConflict = new Map();
|
|
1030
1030
|
for (const row of found.flat()) {
|
|
1031
1031
|
const key = rowKey(row, keys);
|
|
1032
|
-
byConflict.set(key, byConflict.has(key) ? undefined : row
|
|
1032
|
+
byConflict.set(key, byConflict.has(key) ? undefined : idOf(meta, row));
|
|
1033
1033
|
}
|
|
1034
1034
|
return rows.map((row) => byConflict.get(rowKey(row, keys)));
|
|
1035
1035
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AbstractSqlDialect } from '../dialect/index.js';
|
|
2
|
-
import type { EntityData, ExtraOptions, Query, QueryAggMap, QueryAggregate, QueryAggregateResult, QueryConflictPaths, QueryPage, QueryGroupMap,
|
|
2
|
+
import type { EntityData, ExtraOptions, Query, QueryAggMap, QueryAggregate, QueryAggregateResult, QueryConflictPaths, QueryPage, QueryGroupMap, QueryOptions, QuerySearch, QueryUpdateResult, RawRow, SavepointCommand, SqlQuerier, SqlStatement, TransactionOptions, Type, UpdatePayload } from '../type/index.js';
|
|
3
3
|
import type { BuildUpdateResultPayload } from '../util/sql.util.js';
|
|
4
|
-
import { AbstractQuerier } from './abstractQuerier.js';
|
|
4
|
+
import { AbstractQuerier, type UpsertedId } from './abstractQuerier.js';
|
|
5
5
|
export declare abstract class AbstractSqlQuerier extends AbstractQuerier implements SqlQuerier {
|
|
6
6
|
#private;
|
|
7
7
|
readonly dialect: AbstractSqlDialect;
|
|
@@ -83,7 +83,7 @@ export declare abstract class AbstractSqlQuerier extends AbstractQuerier impleme
|
|
|
83
83
|
protected internalAggregate<E extends object, G extends QueryGroupMap<E>, A extends QueryAggMap<E>>(entity: Type<E>, q: QueryAggregate<E, G, A>, opts?: QueryOptions): Promise<QueryAggregateResult<E, G, A>[]>;
|
|
84
84
|
internalInsertMany<E extends object>(entity: Type<E>, rows: EntityData<E>[]): Promise<void>;
|
|
85
85
|
internalUpdateMany<E extends object>(entity: Type<E>, q: QuerySearch<E>, payload: UpdatePayload<E>, opts?: QueryOptions): Promise<number>;
|
|
86
|
-
protected internalUpsertMany<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E[], update?: UpdatePayload<E>): Promise<(
|
|
86
|
+
protected internalUpsertMany<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E[], update?: UpdatePayload<E>): Promise<(UpsertedId<E> | undefined)[] | undefined>;
|
|
87
87
|
private runUpsert;
|
|
88
88
|
protected internalDeleteMany<E extends object>(entity: Type<E>, q: QuerySearch<E>, opts?: QueryOptions): Promise<number>;
|
|
89
89
|
protected openTransaction(opts?: TransactionOptions): Promise<void>;
|
|
@@ -313,11 +313,11 @@ export class AbstractSqlQuerier extends AbstractQuerier {
|
|
|
313
313
|
async runUpsert(entity, conflictPaths, payload, update) {
|
|
314
314
|
const meta = getMeta(entity);
|
|
315
315
|
// Asked first: the statement fills an `onInsert` key into these rows whether it inserts them or not.
|
|
316
|
-
const unnamed =
|
|
316
|
+
const unnamed = payload.some((row) => !namesKey(meta, row));
|
|
317
317
|
const { ids } = await this.exec((ctx) => this.dialect.upsert(ctx, entity, conflictPaths, payload, update));
|
|
318
318
|
const ordered = payload.length === 1 ||
|
|
319
319
|
(this.dialect.insertIdSource === 'returning' && this.dialect.features.orderedUpsertReturning);
|
|
320
|
-
if (ordered && ids?.length === payload.length) {
|
|
320
|
+
if (meta.ids.length === 1 && ordered && ids?.length === payload.length) {
|
|
321
321
|
return ids;
|
|
322
322
|
}
|
|
323
323
|
// The statement's ids name its rows only in order and for every one. A MySQL batch reports a
|
package/dist/sqlite/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './abstractSqliteQuerier.js';
|
|
2
2
|
export * from './hranaQuerier.js';
|
|
3
3
|
export * from './nodeSqliteQuerierPool.js';
|
|
4
|
-
export
|
|
4
|
+
export { SqliteDialect } from './sqliteDialect.js';
|
|
5
5
|
export * from './sqliteQuerier.js';
|
|
6
6
|
export * from './sqliteQuerierPool.js';
|
package/dist/sqlite/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './abstractSqliteQuerier.js';
|
|
2
2
|
export * from './hranaQuerier.js';
|
|
3
3
|
export * from './nodeSqliteQuerierPool.js';
|
|
4
|
-
export
|
|
4
|
+
export { SqliteDialect } from './sqliteDialect.js';
|
|
5
5
|
export * from './sqliteQuerier.js';
|
|
6
6
|
export * from './sqliteQuerierPool.js';
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"homepage": "https://uql-orm.dev",
|
|
4
4
|
"description": "JSON-native TypeScript ORM for Bun, Browsers, Edge, Node, Workers. Supports PostgreSQL, PGlite, MySQL, MariaDB, SQLite, CockroachDB, SQL Server, Turso, Neon, Cloudflare D1 and MongoDB. Queries are plain JSON, typed to the leaf.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.101.
|
|
6
|
+
"version": "0.101.1",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=22.18"
|