uql-orm 0.110.0 → 0.111.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/README.md +3 -3
- package/dist/browser/uql-browser.min.js.map +1 -1
- package/dist/bunSql/bunSqlQuerier.d.ts +2 -5
- package/dist/d1/d1Querier.d.ts +1 -2
- package/dist/d1/d1Querier.js +0 -2
- package/dist/dialect/abstractSqlDialect.js +2 -2
- package/dist/dialect/aliases.d.ts +2 -0
- package/dist/dialect/aliases.js +2 -0
- package/dist/entity/columnOptionsBuilder.d.ts +1 -1
- package/dist/entity/columnOptionsBuilder.js +2 -2
- package/dist/entity/decorator/members.d.ts +15 -6
- package/dist/entity/metadata/definedFixture/animal.d.ts +4 -0
- package/dist/entity/metadata/definedFixture/animal.js +1 -1
- package/dist/entity/metadata/definedFixture/author.d.ts +4 -0
- package/dist/entity/metadata/definedFixture/author.js +1 -1
- package/dist/entity/metadata/definedFixture/book.d.ts +5 -0
- package/dist/entity/metadata/definedFixture/book.js +1 -1
- package/dist/entity/metadata/definition.d.ts +0 -2
- package/dist/entity/metadata/definition.js +3 -8
- package/dist/mariadb/mariadbQuerier.d.ts +2 -4
- package/dist/migrate/builder/columnBuilder.js +2 -2
- package/dist/migrate/codegen/entityCodeGenerator.js +1 -1
- package/dist/migrate/codegen/fieldOptionsSource.js +2 -13
- package/dist/migrate/schemaGenerator.d.ts +2 -2
- package/dist/migrate/schemaGenerator.js +9 -5
- package/dist/mongodb/mongodbQuerier.d.ts +1 -2
- package/dist/mongodb/mongodbQuerier.js +0 -2
- package/dist/mssql/mssqlQuerier.d.ts +2 -4
- package/dist/mysql/mysql2Querier.d.ts +2 -10
- package/dist/pglite/pgliteQuerier.d.ts +4 -7
- package/dist/pglite/pgliteQuerier.js +0 -2
- package/dist/postgres/pgQuerier.d.ts +2 -1
- package/dist/querier/abstractPoolQuerier.d.ts +1 -2
- package/dist/querier/abstractPoolQuerier.js +0 -2
- package/dist/querier/abstractQuerier.d.ts +5 -8
- package/dist/querier/abstractQuerier.js +8 -11
- package/dist/querier/abstractSqlQuerier.d.ts +9 -2
- package/dist/querier/abstractSqlQuerier.js +36 -4
- package/dist/schema/canonicalType.d.ts +3 -3
- package/dist/schema/canonicalType.js +9 -4
- package/dist/schema/declaredColumn.d.ts +2 -4
- package/dist/schema/declaredColumn.js +4 -5
- package/dist/schema/schemaASTBuilder.js +1 -2
- package/dist/sqlite/hranaQuerier.d.ts +1 -2
- package/dist/sqlite/hranaQuerier.js +0 -2
- package/dist/sqlite/sqliteQuerier.d.ts +3 -9
- package/dist/sqlite/sqliteQuerier.js +0 -2
- package/dist/turso/tursoSessionQuerier.d.ts +1 -2
- package/dist/turso/tursoSessionQuerier.js +0 -2
- package/dist/type/column.d.ts +4 -6
- package/dist/type/definedEntity.d.ts +1 -1
- package/dist/type/entity.d.ts +4 -5
- package/dist/type/querier.d.ts +2 -2
- package/dist/type/querierPool.d.ts +1 -1
- package/dist/type/query.d.ts +3 -1
- package/dist/type/universalQuerier.d.ts +2 -2
- package/dist/util/field.util.d.ts +1 -7
- package/dist/util/field.util.js +2 -12
- package/package.json +1 -1
- package/skills/uql-orm/SKILL.md +5 -5
package/dist/type/querier.d.ts
CHANGED
|
@@ -84,10 +84,10 @@ export interface Querier extends UniversalQuerier {
|
|
|
84
84
|
}, opts?: QueryOptions & WriteOptions<E, S, V, W>) => Promise<WriteResults<E, S, V, W>['affectedMany']>) & UniversalQuerier['deleteMany'];
|
|
85
85
|
upsertOne: (<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true, const W extends boolean = false>(q: QueryUpsert<E> & {
|
|
86
86
|
$entity: Type<E>;
|
|
87
|
-
}, payload: EntityWrite<E>, opts?: WriteOptions<E, S, V, W>) => Promise<WriteResults<E, S, V, W>['
|
|
87
|
+
}, payload: EntityWrite<E>, opts?: WriteOptions<E, S, V, W>) => Promise<WriteResults<E, S, V, W>['upserted']>) & UniversalQuerier['upsertOne'];
|
|
88
88
|
upsertMany: (<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true, const W extends boolean = false>(q: QueryUpsert<E> & {
|
|
89
89
|
$entity: Type<E>;
|
|
90
|
-
}, payload: readonly EntityWrite<E>[], opts?: WriteOptions<E, S, V, W>) => Promise<WriteResults<E, S, V, W>['
|
|
90
|
+
}, payload: readonly EntityWrite<E>[], opts?: WriteOptions<E, S, V, W>) => Promise<WriteResults<E, S, V, W>['upserted'][]>) & UniversalQuerier['upsertMany'];
|
|
91
91
|
/**
|
|
92
92
|
* whether this querier is in a transaction or not.
|
|
93
93
|
*/
|
|
@@ -25,7 +25,7 @@ export interface QuerierPool<Q extends Querier = Querier, D extends AbstractDial
|
|
|
25
25
|
/**
|
|
26
26
|
* extra options
|
|
27
27
|
*/
|
|
28
|
-
readonly extra?: ExtraOptions;
|
|
28
|
+
readonly extra?: ExtraOptions | undefined;
|
|
29
29
|
/**
|
|
30
30
|
* Default connection for application queries, transactions, and anything that should use the pool's primary URL.
|
|
31
31
|
*/
|
package/dist/type/query.d.ts
CHANGED
|
@@ -505,12 +505,14 @@ export type WriteOptions<E, S extends FieldKey<E> = FieldKey<E>, V = BooleanLike
|
|
|
505
505
|
/** What each kind of write resolves to: its ids or its count where it reads nothing back, else the rows it reads. */
|
|
506
506
|
export type WriteResults<E, S, V, W = false> = [W] extends [true] ? ReturnedRows<Pick<E, FieldKey<E>>> : [W] extends [false] ? WrittenIds<E> : [S] extends [never] ? WrittenIds<E> : ReturnedRows<ReturnedRow<E, S, V>>;
|
|
507
507
|
type WrittenIds<E> = {
|
|
508
|
-
readonly inserted: WrittenId<E
|
|
508
|
+
readonly inserted: NonNullable<WrittenId<E>>;
|
|
509
|
+
readonly upserted: WrittenId<E> | undefined;
|
|
509
510
|
readonly affected: number;
|
|
510
511
|
readonly affectedMany: number;
|
|
511
512
|
};
|
|
512
513
|
type ReturnedRows<R> = {
|
|
513
514
|
readonly inserted: R;
|
|
515
|
+
readonly upserted: R;
|
|
514
516
|
readonly affected: R | undefined;
|
|
515
517
|
readonly affectedMany: R[];
|
|
516
518
|
};
|
|
@@ -104,9 +104,9 @@ export interface UniversalQuerier extends SharedQuerier<'server', QueryOptions>
|
|
|
104
104
|
* conflicting row matching `q.$where` takes the payload less those keys, or `q.$update` as `updateMany` takes an
|
|
105
105
|
* update: `{ uses: { $inc: 1 } }` counts, and `{}` leaves the row as it is. Either branch writes the cascaded relations it is given.
|
|
106
106
|
*/
|
|
107
|
-
upsertOne<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true, const W extends boolean = false>(entity: Type<E>, q: QueryUpsert<E>, payload: EntityWrite<E>, opts?: WriteOptions<E, S, V, W>): Promise<WriteResults<E, S, V, W>['
|
|
107
|
+
upsertOne<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true, const W extends boolean = false>(entity: Type<E>, q: QueryUpsert<E>, payload: EntityWrite<E>, opts?: WriteOptions<E, S, V, W>): Promise<WriteResults<E, S, V, W>['upserted']>;
|
|
108
108
|
/** Insert or update records by `q.$conflict`'s keys, as `upsertOne` does; resolves to their ids in payload order, or the rows. */
|
|
109
|
-
upsertMany<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true, const W extends boolean = false>(entity: Type<E>, q: QueryUpsert<E>, payload: readonly EntityWrite<E>[], opts?: WriteOptions<E, S, V, W>): Promise<WriteResults<E, S, V, W>['
|
|
109
|
+
upsertMany<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true, const W extends boolean = false>(entity: Type<E>, q: QueryUpsert<E>, payload: readonly EntityWrite<E>[], opts?: WriteOptions<E, S, V, W>): Promise<WriteResults<E, S, V, W>['upserted'][]>;
|
|
110
110
|
/** Insert a record, or upsert one naming its key; resolves to its id, or the row `returning` reads back. */
|
|
111
111
|
saveOne<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true, const W extends boolean = false>(entity: Type<E>, payload: EntityWrite<E>, opts?: WriteOptions<E, S, V, W>): Promise<WriteResults<E, S, V, W>['inserted']>;
|
|
112
112
|
/** Insert records, or upsert those naming their key; resolves to their ids in payload order, or the rows. */
|
|
@@ -38,12 +38,6 @@ export declare function aggregateField(aggregate: RelationAggregate): FieldOptio
|
|
|
38
38
|
* computed column *is* a real column, read like one, but writing to it is an error on every engine.
|
|
39
39
|
*/
|
|
40
40
|
export declare function isDatabaseWritten(field: FieldOptions): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Whether the database generates this column's value: its table's whole and own key (see `ownsSoleKey`), numeric,
|
|
43
|
-
* that the application does not fill `onInsert`; a `columnType` only states its width. The one answer the create
|
|
44
|
-
* statement and the diff both read.
|
|
45
|
-
*/
|
|
46
|
-
export declare function isAutoIncrement(field: FieldOptions, soleKey: boolean): boolean;
|
|
47
41
|
/** The column family of a field, from its `columnType` if set, else from its `type`. */
|
|
48
42
|
export declare function fieldFamily(field: FieldOptions): ColumnFamily | undefined;
|
|
49
43
|
/** Whether the column is NOT NULL: every column is, a key included, unless it declares `nullable()`. */
|
|
@@ -59,7 +53,7 @@ export declare function lacksValue(column: {
|
|
|
59
53
|
* {@link lacksValue} for an insert leaving the field out, where a computed column, a stamp its trigger fills included,
|
|
60
54
|
* holds a value too, unlike on the rows a migration finds.
|
|
61
55
|
*/
|
|
62
|
-
export declare function lacksValueOnInsert(field: FieldOptions
|
|
56
|
+
export declare function lacksValueOnInsert(field: FieldOptions): boolean;
|
|
63
57
|
/** Whether `key` is a field of `meta`, as opposed to a relation, a JSON path or an unknown key. */
|
|
64
58
|
export declare function isFieldKey<E>(meta: EntityMeta<E>, key: string): key is FieldKey<E>;
|
|
65
59
|
/** The fields `meta` declares whose options `pick` accepts, in declaration order, each as the entity's own key. */
|
package/dist/util/field.util.js
CHANGED
|
@@ -83,16 +83,6 @@ export function aggregateField(aggregate) {
|
|
|
83
83
|
export function isDatabaseWritten(field) {
|
|
84
84
|
return field.computed !== undefined;
|
|
85
85
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Whether the database generates this column's value: its table's whole and own key (see `ownsSoleKey`), numeric,
|
|
88
|
-
* that the application does not fill `onInsert`; a `columnType` only states its width. The one answer the create
|
|
89
|
-
* statement and the diff both read.
|
|
90
|
-
*/
|
|
91
|
-
export function isAutoIncrement(field, soleKey) {
|
|
92
|
-
if (field.autoIncrement !== undefined)
|
|
93
|
-
return field.autoIncrement;
|
|
94
|
-
return soleKey && columnFamily(field.type) === 'numeric' && !field.onInsert;
|
|
95
|
-
}
|
|
96
86
|
/** The column family of a field, from its `columnType` if set, else from its `type`. */
|
|
97
87
|
export function fieldFamily(field) {
|
|
98
88
|
return columnFamily(field.columnType ?? field.type);
|
|
@@ -109,12 +99,12 @@ export function lacksValue(column) {
|
|
|
109
99
|
* {@link lacksValue} for an insert leaving the field out, where a computed column, a stamp its trigger fills included,
|
|
110
100
|
* holds a value too, unlike on the rows a migration finds.
|
|
111
101
|
*/
|
|
112
|
-
export function lacksValueOnInsert(field
|
|
102
|
+
export function lacksValueOnInsert(field) {
|
|
113
103
|
return (!isDatabaseWritten(field) &&
|
|
114
104
|
lacksValue({
|
|
115
105
|
nullable: !declaresNotNull(field),
|
|
116
106
|
defaultValue: field.defaultValue,
|
|
117
|
-
isAutoIncrement:
|
|
107
|
+
isAutoIncrement: field.autoIncrement === true,
|
|
118
108
|
}));
|
|
119
109
|
}
|
|
120
110
|
/** Whether `key` is a field of `meta`, as opposed to a relation, a JSON path or an unknown key. */
|
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.
|
|
6
|
+
"version": "0.111.1",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=22.18"
|
package/skills/uql-orm/SKILL.md
CHANGED
|
@@ -73,7 +73,7 @@ export class User {
|
|
|
73
73
|
|
|
74
74
|
@Entity()
|
|
75
75
|
export class Post {
|
|
76
|
-
@Field(f.number().
|
|
76
|
+
@Field(f.number().autoIncrement())
|
|
77
77
|
id?: number;
|
|
78
78
|
|
|
79
79
|
@Field(f.string().nullable())
|
|
@@ -88,7 +88,7 @@ export class Post {
|
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
- A column is a builder: `f.string()`, `f.text()`, `f.uuid()`, `f.number()`, `f.bigint()`, `f.decimal(precision?, scale?)`, `f.boolean()`, `f.date()`, `f.json(schema?)`, `f.jsonb(schema?)`, `f.vector(dimensions)`, `f.enum(values)`, `f.version()`, `f.column(type)` for any other SQL type uql names (`f.column('smallint')`, `f.column('date')` for a day with no time, `f.column('timestamptz')`), typed by its family, and `f.references(() => Target)` for a foreign key typed as the target's key. A type uql does not name is ``.columnType(sql`citext`)``. Only the methods a column's type takes exist: `.length()` is a string's, `.precision()` a number's or a date's. A builder is immutable, so `const money = f.decimal(12, 2)` is shared across fields, each chaining its own `.nullable()`.
|
|
91
|
-
- A column is NOT NULL unless `.nullable()`. Declare a NOT NULL property `!` (`email!: string`), and `?` what an insert may omit: nullable columns (`title?: string | null`), `.eager(false)` and computed fields, relations, and the
|
|
91
|
+
- A column is NOT NULL unless `.nullable()`. Declare a NOT NULL property `!` (`email!: string`), and `?` what an insert may omit: nullable columns (`title?: string | null`), `.eager(false)` and computed fields, relations, and the version uql fills. A key the database generates is `@Field(f.number().autoIncrement()) id?: number` (`f.bigint().autoIncrement()` past 2^53); `.id()` alone generates nothing, so `f.number().id()` is a key the caller supplies and `@Field` refuses `?` on it, as on a `.references()` key. A NOT NULL field something fills (`.default()`, `.onInsert()`, a generated key) stays `!` when listed in the class's `[filledKey]?: 'id' | 'createdAt'`: inserts may omit it, reads always have it. MongoDB fills a text key declared `?` and `_id`. `insertOne`, `insertMany`, `saveOne` and `saveMany` resolve to a defined key, so no `!`; an upsert's may be `undefined`. On SQL engines an insert leaving out a key nothing declared fills throws before writing. `defineEntity` works all of this out.
|
|
92
92
|
- `.default()` takes a value of the field's type, or SQL the database evaluates per row: `currentTimestamp`, `currentDate`, `currentTime`, `uuid` (not SQLite), `uuidv7` (Postgres 18+, MariaDB 11.7+), or ``sql`...` ``. A plain string is always text, `'CURRENT_TIMESTAMP'` included. A JSON column defaults to a value, `.default({})` or `.default(0)`, never its JSON text (`'{}'`, `'0'` are refused); any other string there is a JSON string.
|
|
93
93
|
- `Date` is an instant, stored in UTC to the millisecond. `f.decimal()` is exact text (`price?: string | null`); `f.number().precision(10).scale(2)` opts into a rounding JS number.
|
|
94
94
|
- A JSON column's property is `Json<T>`: `settings?: Json<{ theme?: string }> | null`. A plain object type reads as a relation, which `$where`, `$sort` and the update operators refuse.
|
|
@@ -112,7 +112,7 @@ const Settings = z.object({ theme: z.string(), bio: z.string().optional() });
|
|
|
112
112
|
export const Author = defineEntity({
|
|
113
113
|
name: 'Author',
|
|
114
114
|
fields: {
|
|
115
|
-
id: f.number().
|
|
115
|
+
id: f.number().autoIncrement(),
|
|
116
116
|
name: f.string(),
|
|
117
117
|
settings: f.json(Settings).nullable(),
|
|
118
118
|
},
|
|
@@ -125,7 +125,7 @@ export type Author = InstanceType<typeof Author>;
|
|
|
125
125
|
export const Book = defineEntity({
|
|
126
126
|
name: 'Book',
|
|
127
127
|
fields: {
|
|
128
|
-
id: f.number().
|
|
128
|
+
id: f.number().autoIncrement(),
|
|
129
129
|
title: f.string(),
|
|
130
130
|
stock: f.number().default(0),
|
|
131
131
|
authorId: f.number(),
|
|
@@ -164,7 +164,7 @@ declare module 'uql-orm' {
|
|
|
164
164
|
},
|
|
165
165
|
})
|
|
166
166
|
export class Invoice {
|
|
167
|
-
@Field(f.number().
|
|
167
|
+
@Field(f.number().autoIncrement()) id?: number;
|
|
168
168
|
@Field(f.number()) companyId!: number;
|
|
169
169
|
@Field(f.string().nullable()) status?: string | null;
|
|
170
170
|
@Field(f.date().nullable().softDelete()) deletedAt?: Date | null;
|