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.
@@ -1,4 +1,4 @@
1
- export * from './contract.js';
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 * from './query.js';
4
+ export type { WireCursors, WireFlags } from './query.js';
@@ -1,4 +1,3 @@
1
- export * from './contract.js';
1
+ export { CRUD_ROUTES, entityPath, toErrorResponse, } from './contract.js';
2
2
  export * from './fetchHandler.js';
3
3
  export * from './handler.js';
4
- export * from './query.js';
@@ -1,2 +1,2 @@
1
- export * from './libsqlDialect.js';
1
+ export { LibsqlDialect } from './libsqlDialect.js';
2
2
  export * from './libsqlQuerierPool.js';
@@ -1,2 +1,2 @@
1
- export * from './libsqlDialect.js';
1
+ export { LibsqlDialect } from './libsqlDialect.js';
2
2
  export * from './libsqlQuerierPool.js';
@@ -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 { loadConfig } from './cli-config.js';
7
- export * from './codegen/index.js';
8
- export * from './ddl/index.js';
9
- export * from './drift/index.js';
10
- export * from './introspection/index.js';
11
- export { migrationBuilderFor } from './migrationTarget.js';
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';
@@ -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 { loadConfig } from './cli-config.js';
7
- // Entity code generation
8
- export * from './codegen/index.js';
9
- // Index and table DDL, per dialect family
10
- export * from './ddl/index.js';
11
- // Drift detection
12
- export * from './drift/index.js';
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';
@@ -1,4 +1,4 @@
1
- export * from './mongoDialect.js';
1
+ export { MongoDialect } from './mongoDialect.js';
2
2
  export * from './mongodbQuerier.js';
3
3
  export * from './mongodbQuerierPool.js';
4
4
  export * from './mongoIntrospector.js';
@@ -1,4 +1,4 @@
1
- export * from './mongoDialect.js';
1
+ export { MongoDialect } from './mongoDialect.js';
2
2
  export * from './mongodbQuerier.js';
3
3
  export * from './mongodbQuerierPool.js';
4
4
  export * from './mongoIntrospector.js';
@@ -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, PrimaryKey, Query, QueryAggMap, QueryAggregate, QueryAggregateResult, QueryConflictPaths, QueryPage, QueryGroupMap, QueryOptions, QuerySearch, TransactionOptions, Type, UpdatePayload } from '../type/index.js';
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<(PrimaryKey | undefined)[]>;
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. */
@@ -1,3 +1,3 @@
1
1
  export * from './pgQuerier.js';
2
2
  export * from './pgQuerierPool.js';
3
- export * from './postgresDialect.js';
3
+ export { PostgresDialect } from './postgresDialect.js';
@@ -1,3 +1,3 @@
1
1
  export * from './pgQuerier.js';
2
2
  export * from './pgQuerierPool.js';
3
- export * from './postgresDialect.js';
3
+ export { PostgresDialect } from './postgresDialect.js';
@@ -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, PrimaryKey, RelationKey, SavepointCommand, TransactionOptions, Type, UpdatePayload, UpdateWrite, ReturningResult, WriteOptions, WrittenId } from '../type/index.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, 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<(PrimaryKey | undefined)[] | undefined>;
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<(PrimaryKey | undefined)[]>;
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 (meta.ids.length !== 1 || reported?.length !== rows.length) {
103
+ if (reported?.length !== rows.length) {
109
104
  return;
110
105
  }
111
106
  const [idKey] = meta.ids;
112
- for (let index = 0; index < rows.length; index++) {
113
- rows[index][idKey] ??= reported[index];
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([idKey, ...keys]), $where: whereKeysIn(keys, batch) };
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[idKey]);
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, PrimaryKey, QueryOptions, QuerySearch, QueryUpdateResult, RawRow, SavepointCommand, SqlQuerier, SqlStatement, TransactionOptions, Type, UpdatePayload } from '../type/index.js';
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<(PrimaryKey | undefined)[] | undefined>;
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 = meta.ids.length === 1 && payload.some((row) => !namesKey(meta, row));
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
@@ -1,6 +1,6 @@
1
1
  export * from './abstractSqliteQuerier.js';
2
2
  export * from './hranaQuerier.js';
3
3
  export * from './nodeSqliteQuerierPool.js';
4
- export * from './sqliteDialect.js';
4
+ export { SqliteDialect } from './sqliteDialect.js';
5
5
  export * from './sqliteQuerier.js';
6
6
  export * from './sqliteQuerierPool.js';
@@ -1,6 +1,6 @@
1
1
  export * from './abstractSqliteQuerier.js';
2
2
  export * from './hranaQuerier.js';
3
3
  export * from './nodeSqliteQuerierPool.js';
4
- export * from './sqliteDialect.js';
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.0",
6
+ "version": "0.101.1",
7
7
  "type": "module",
8
8
  "engines": {
9
9
  "node": ">=22.18"