uql-orm 0.91.1 → 0.92.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/http/bus.js +3 -4
- package/dist/browser/http/http.d.ts +1 -2
- package/dist/browser/http/http.js +8 -7
- package/dist/browser/index.d.ts +0 -1
- package/dist/browser/index.js +0 -1
- package/dist/browser/querier/httpQuerier.d.ts +18 -20
- package/dist/browser/querier/httpQuerier.js +20 -56
- package/dist/browser/type/index.d.ts +0 -1
- package/dist/browser/type/index.js +0 -1
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +11 -12
- package/dist/cockroachdb/cockroachDialect.d.ts +4 -1
- package/dist/cockroachdb/cockroachDialect.js +5 -1
- package/dist/dialect/abstractDialect.d.ts +1 -1
- package/dist/dialect/abstractDialect.js +4 -1
- package/dist/dialect/abstractSqlDialect.d.ts +24 -28
- package/dist/dialect/abstractSqlDialect.js +47 -45
- package/dist/dialect/aliases.d.ts +4 -1
- package/dist/dialect/aliases.js +5 -2
- package/dist/dialect/hydrateColumn.js +3 -10
- package/dist/dialect/jsonSql.d.ts +4 -1
- package/dist/dialect/jsonSql.js +4 -1
- package/dist/dialect/mergeSqlDialect.d.ts +4 -3
- package/dist/dialect/mergeSqlDialect.js +5 -4
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +7 -21
- package/dist/dialect/mysqlLikeSqlDialect.js +9 -36
- package/dist/dialect/pgLikeSqlDialect.d.ts +3 -7
- package/dist/dialect/pgLikeSqlDialect.js +11 -21
- package/dist/http/contract.d.ts +4 -0
- package/dist/http/contract.js +1 -0
- package/dist/http/handler.d.ts +2 -2
- package/dist/http/handler.js +17 -19
- package/dist/http/query.d.ts +5 -3
- package/dist/http/query.js +42 -42
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/maria/mariaDialect.d.ts +2 -3
- package/dist/maria/mariaDialect.js +1 -5
- package/dist/migrate/builder/columnBuilder.d.ts +5 -15
- package/dist/migrate/builder/columnBuilder.js +50 -86
- package/dist/migrate/builder/expressions.d.ts +12 -18
- package/dist/migrate/builder/expressions.js +39 -42
- package/dist/migrate/builder/migrationBuilder.d.ts +3 -11
- package/dist/migrate/builder/migrationBuilder.js +41 -81
- package/dist/migrate/builder/tableBuilder.d.ts +0 -7
- package/dist/migrate/builder/tableBuilder.js +17 -28
- package/dist/migrate/builder/types.d.ts +2 -2
- package/dist/migrate/codegen/entityCodeGenerator.js +3 -3
- package/dist/migrate/codegen/entityTypes.js +2 -2
- package/dist/migrate/codegen/fieldOptionsSource.d.ts +2 -2
- package/dist/migrate/codegen/fieldOptionsSource.js +27 -12
- package/dist/migrate/codegen/indexDecoratorSource.js +64 -41
- package/dist/migrate/ddl/index.d.ts +2 -4
- package/dist/migrate/ddl/index.js +14 -5
- package/dist/migrate/ddl/mssqlTableDdl.d.ts +1 -0
- package/dist/migrate/ddl/mssqlTableDdl.js +4 -1
- package/dist/migrate/ddl/mysqlTableDdl.d.ts +17 -0
- package/dist/migrate/ddl/mysqlTableDdl.js +33 -0
- package/dist/migrate/ddl/pgTableDdl.d.ts +7 -0
- package/dist/migrate/ddl/pgTableDdl.js +17 -0
- package/dist/migrate/ddl/tableDdl.d.ts +15 -10
- package/dist/migrate/ddl/tableDdl.js +31 -32
- package/dist/migrate/drift/driftDetector.js +46 -59
- package/dist/migrate/generator/definitionToNode.d.ts +11 -7
- package/dist/migrate/generator/definitionToNode.js +27 -34
- package/dist/migrate/generator/indexNodeToSchema.d.ts +3 -3
- package/dist/migrate/generator/indexNodeToSchema.js +5 -4
- package/dist/migrate/index.js +1 -1
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +10 -5
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +10 -0
- package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -1
- package/dist/migrate/introspection/baseSqlIntrospector.js +6 -8
- package/dist/migrate/introspection/mssqlIntrospector.js +3 -8
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +11 -4
- package/dist/migrate/introspection/mysqlIntrospector.js +25 -11
- package/dist/migrate/introspection/postgresIntrospector.d.ts +2 -2
- package/dist/migrate/introspection/postgresIntrospector.js +3 -3
- package/dist/migrate/introspection/sqliteIntrospector.d.ts +1 -1
- package/dist/migrate/introspection/sqliteIntrospector.js +7 -10
- package/dist/migrate/migrationTarget.js +3 -3
- package/dist/migrate/schemaGenerator.d.ts +8 -12
- package/dist/migrate/schemaGenerator.js +35 -61
- package/dist/migrate/triggerSql.d.ts +1 -1
- package/dist/migrate/triggerSql.js +8 -6
- package/dist/mongo/mongoDialect.d.ts +4 -3
- package/dist/mongo/mongoDialect.js +52 -38
- package/dist/mongo/mongoIntrospector.js +1 -1
- package/dist/mongo/mongoSchemaGenerator.d.ts +7 -4
- package/dist/mongo/mongoSchemaGenerator.js +18 -21
- package/dist/mongo/mongodbQuerier.d.ts +2 -3
- package/dist/mongo/mongodbQuerier.js +9 -28
- package/dist/mssql/mssqlDialect.d.ts +4 -5
- package/dist/mssql/mssqlDialect.js +9 -7
- package/dist/postgres/postgresDialect.js +2 -2
- package/dist/querier/abstractQuerier.d.ts +16 -11
- package/dist/querier/abstractQuerier.js +74 -26
- package/dist/querier/abstractQuerierPool.d.ts +26 -24
- package/dist/querier/abstractQuerierPool.js +26 -64
- package/dist/querier/abstractSqlQuerier.d.ts +2 -3
- package/dist/querier/abstractSqlQuerier.js +8 -26
- package/dist/querier/cursor.d.ts +10 -0
- package/dist/querier/cursor.js +81 -0
- package/dist/querier/keyset.d.ts +19 -0
- package/dist/querier/keyset.js +198 -0
- package/dist/schema/canonicalType.d.ts +3 -3
- package/dist/schema/canonicalType.js +13 -12
- package/dist/schema/indexDifferences.d.ts +14 -7
- package/dist/schema/indexDifferences.js +7 -5
- package/dist/schema/schemaAST.d.ts +0 -1
- package/dist/schema/schemaAST.js +0 -2
- package/dist/schema/schemaASTBuilder.js +28 -20
- package/dist/schema/schemaASTDiffer.d.ts +7 -9
- package/dist/schema/schemaASTDiffer.js +54 -107
- package/dist/schema/sqlExpression.d.ts +22 -0
- package/dist/schema/sqlExpression.js +28 -0
- package/dist/schema/types.d.ts +48 -105
- package/dist/sqlite/sqliteDialect.d.ts +9 -13
- package/dist/sqlite/sqliteDialect.js +10 -29
- package/dist/type/dialect.d.ts +20 -3
- package/dist/type/entity.d.ts +3 -3
- package/dist/type/migration.d.ts +7 -7
- package/dist/type/querier.d.ts +19 -26
- package/dist/type/query.d.ts +104 -24
- package/dist/type/query.js +21 -28
- package/dist/type/universalQuerier.d.ts +31 -5
- package/dist/type/utility.d.ts +10 -0
- package/dist/util/bytes.d.ts +7 -0
- package/dist/util/bytes.js +22 -0
- package/dist/util/date.d.ts +5 -0
- package/dist/util/date.js +5 -0
- package/dist/util/dialect.util.d.ts +1 -25
- package/dist/util/dialect.util.js +4 -50
- package/dist/util/field.util.d.ts +9 -0
- package/dist/util/field.util.js +15 -0
- package/dist/util/fieldOption.util.js +2 -2
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +1 -0
- package/dist/util/object.util.d.ts +0 -2
- package/dist/util/object.util.js +0 -7
- package/dist/util/query.util.d.ts +40 -0
- package/dist/util/query.util.js +76 -0
- package/dist/util/raw.d.ts +5 -0
- package/dist/util/raw.js +5 -0
- package/dist/util/relationQuery.util.js +18 -16
- package/dist/util/rowKey.util.js +2 -3
- package/dist/util/sql.util.d.ts +8 -2
- package/dist/util/sql.util.js +16 -17
- package/dist/util/sqlLiteral.js +2 -12
- package/dist/util/string.util.d.ts +5 -0
- package/dist/util/string.util.js +12 -0
- package/package.json +1 -1
- package/skills/uql-orm/SKILL.md +21 -10
- package/dist/browser/options.d.ts +0 -4
- package/dist/browser/options.js +0 -13
- package/dist/browser/type/clientQuerierPool.d.ts +0 -4
- package/dist/browser/type/clientQuerierPool.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IndexType } from '../schema/types.js';
|
|
2
|
-
import { type AggregateCall, type CascadeType, type EntityData, type
|
|
2
|
+
import { type AggregateCall, type CascadeType, type EntityData, type EntityIndexMeta, type EntityMeta, type FieldKey, type FieldOptions, type FieldUpdateOp, type JsonUpdateOp, type OnFieldCallback, type QueryAggMap, type QueryExclude, type QueryGroupMap, type QueryOptions, QueryRaw, type QuerySearch, type QuerySelect, type QuerySelectValue, type QuerySortDirection, type QuerySizeComparisonOps, type QuerySortMap, type QueryTextSearchOptions, type QueryVectorQuery, type QueryVectorSearch, type QueryWhere, type RelationKey, type UpdatePayload, type VectorDistance } from '../type/index.js';
|
|
3
3
|
export type CallbackKey = keyof Pick<FieldOptions, 'onInsert' | 'onUpdate'>;
|
|
4
4
|
/** The keys of `payload` a write persists as columns. */
|
|
5
5
|
export declare function filterFieldKeys<E>(meta: EntityMeta<E>, payload: EntityData<E> | UpdatePayload<E>, callbackKey: CallbackKey): FieldKey<E>[];
|
|
@@ -41,20 +41,6 @@ export declare function isCascadable(action: CascadeType, configuration?: boolea
|
|
|
41
41
|
* neither clause on a write at all.
|
|
42
42
|
*/
|
|
43
43
|
export declare function isPagedQuery<E>(q: QuerySearch<E>): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Each of `keys` switched on, as a `$select` or conflict paths name them. This and the `where*` builders
|
|
46
|
-
* below hold the casts a statement built in generic code needs: a key read at run time is no key of
|
|
47
|
-
* these maps to the compiler, whose values it works out per entity.
|
|
48
|
-
*/
|
|
49
|
-
export declare function keySet<E>(keys: readonly FieldKey<E>[]): QueryConflictPaths<E>;
|
|
50
|
-
/** `where`, or no `$where`, with `key` held to `value` as well: spread, so the two `AND`. */
|
|
51
|
-
export declare function whereWith<E>(key: FieldKey<E>, value: unknown, where?: QueryWhere<E>): QueryWhere<E>;
|
|
52
|
-
/** The `$where` holding each of `keys` to what `valueOf` reads for it. */
|
|
53
|
-
export declare function whereEach<E>(keys: readonly FieldKey<E>[], valueOf: (key: FieldKey<E>) => unknown): QueryWhere<E>;
|
|
54
|
-
/** The `$where` any one of `clauses` satisfies. */
|
|
55
|
-
export declare function whereAnyOf<E>(clauses: QueryWhereArray<E>): QueryWhere<E>;
|
|
56
|
-
/** `q` selecting nothing but the id: what a write hands its backend's own read builder to settle the rows it will name. */
|
|
57
|
-
export declare function idOnlyQuery<E>(meta: EntityMeta<E>, q: QuerySearch<E>): Query<E>;
|
|
58
44
|
/** Whether `select` is the list form `raw()` fills, narrowing both ways, which `Array.isArray` does not for a `readonly` array. */
|
|
59
45
|
export declare function isSelectList<E>(select: QuerySelectValue<E> | undefined): select is readonly QueryRaw[];
|
|
60
46
|
export declare function normalizeScalarFieldSelection<E>(meta: EntityMeta<E>, select?: QuerySelect<E>, exclude?: QueryExclude<E>): FieldKey<E>[];
|
|
@@ -97,16 +83,6 @@ export declare function isFieldUpdateOp(value: unknown): value is FieldUpdateOp;
|
|
|
97
83
|
* reading one: their order would change the result, and an untyped payload is how both arrive.
|
|
98
84
|
*/
|
|
99
85
|
export declare function fieldUpdateOf(key: string, value: FieldUpdateOp): [keyof FieldUpdateOp, number | bigint];
|
|
100
|
-
/**
|
|
101
|
-
* The `$where` naming rows by key: a bare value names the one key column (refused on a composite), a
|
|
102
|
-
* composite's key map is a `$where` already, and a list is an `IN` of bare values or an OR of maps.
|
|
103
|
-
*/
|
|
104
|
-
export declare function whereIds<E>(meta: EntityMeta<E>, ids: EntityId<E> | EntityId<E>[]): QueryWhere<E>;
|
|
105
|
-
/**
|
|
106
|
-
* Refuses a `$where` that is not a map. Untyped JS and parsed JSON can still pass an id or a list of
|
|
107
|
-
* them, and a scalar read as a map has no keys: the statement would address every row.
|
|
108
|
-
*/
|
|
109
|
-
export declare function assertWhere<E>(meta: EntityMeta<E>, where: unknown): void;
|
|
110
86
|
/** Returns a `QueryOptions.filters` value with the built-in soft-delete filter disabled (used by hard delete). */
|
|
111
87
|
export declare function withoutSoftDeleteFilter(filters: QueryOptions['filters']): QueryOptions['filters'];
|
|
112
88
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getContext } from '../context/context.js';
|
|
2
|
-
import { soleIdOf } from '../entity/metadata/definition.js';
|
|
3
2
|
import { QueryRaw, resolveAggregateOp, SOFT_DELETE_FILTER, } from '../type/index.js';
|
|
4
3
|
import { DEFAULT_VECTOR_DISTANCE, VECTOR_INDEX_TYPES } from '../type/vector.js';
|
|
5
4
|
import { defaultReadKeys, fieldKeys, isDatabaseWritten } from './field.util.js';
|
|
6
|
-
import { entityName, getKeys, hasKeys, isOperatorObject,
|
|
5
|
+
import { entityName, getKeys, hasKeys, isOperatorObject, isRecord, someKey } from './object.util.js';
|
|
6
|
+
import { whereAnd } from './query.util.js';
|
|
7
7
|
import { UqlSecurityError, UqlUsageError } from './uqlError.js';
|
|
8
8
|
/** The keys of `payload` a write persists as columns. */
|
|
9
9
|
export function filterFieldKeys(meta, payload, callbackKey) {
|
|
@@ -114,30 +114,6 @@ export function isCascadable(action, configuration) {
|
|
|
114
114
|
export function isPagedQuery(q) {
|
|
115
115
|
return q.$sort !== undefined || q.$limit !== undefined || q.$skip !== undefined;
|
|
116
116
|
}
|
|
117
|
-
/**
|
|
118
|
-
* Each of `keys` switched on, as a `$select` or conflict paths name them. This and the `where*` builders
|
|
119
|
-
* below hold the casts a statement built in generic code needs: a key read at run time is no key of
|
|
120
|
-
* these maps to the compiler, whose values it works out per entity.
|
|
121
|
-
*/
|
|
122
|
-
export function keySet(keys) {
|
|
123
|
-
return Object.fromEntries(keys.map((key) => [key, true]));
|
|
124
|
-
}
|
|
125
|
-
/** `where`, or no `$where`, with `key` held to `value` as well: spread, so the two `AND`. */
|
|
126
|
-
export function whereWith(key, value, where) {
|
|
127
|
-
return { ...where, [key]: value };
|
|
128
|
-
}
|
|
129
|
-
/** The `$where` holding each of `keys` to what `valueOf` reads for it. */
|
|
130
|
-
export function whereEach(keys, valueOf) {
|
|
131
|
-
return Object.fromEntries(keys.map((key) => [key, valueOf(key)]));
|
|
132
|
-
}
|
|
133
|
-
/** The `$where` any one of `clauses` satisfies. */
|
|
134
|
-
export function whereAnyOf(clauses) {
|
|
135
|
-
return { $or: clauses };
|
|
136
|
-
}
|
|
137
|
-
/** `q` selecting nothing but the id: what a write hands its backend's own read builder to settle the rows it will name. */
|
|
138
|
-
export function idOnlyQuery(meta, q) {
|
|
139
|
-
return { ...q, $select: keySet(meta.ids) };
|
|
140
|
-
}
|
|
141
117
|
/** Whether `select` is the list form `raw()` fills, narrowing both ways, which `Array.isArray` does not for a `readonly` array. */
|
|
142
118
|
export function isSelectList(select) {
|
|
143
119
|
return Array.isArray(select);
|
|
@@ -270,25 +246,6 @@ export function fieldUpdateOf(key, value) {
|
|
|
270
246
|
}
|
|
271
247
|
return value.$inc === undefined ? ['$mul', value.$mul] : ['$inc', value.$inc];
|
|
272
248
|
}
|
|
273
|
-
/**
|
|
274
|
-
* The `$where` naming rows by key: a bare value names the one key column (refused on a composite), a
|
|
275
|
-
* composite's key map is a `$where` already, and a list is an `IN` of bare values or an OR of maps.
|
|
276
|
-
*/
|
|
277
|
-
export function whereIds(meta, ids) {
|
|
278
|
-
if (Array.isArray(ids) ? ids.every(isScalarId) : isScalarId(ids)) {
|
|
279
|
-
return whereWith(soleIdOf(meta, 'addressing by a bare id value'), ids);
|
|
280
|
-
}
|
|
281
|
-
return (Array.isArray(ids) ? { $or: ids } : ids);
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Refuses a `$where` that is not a map. Untyped JS and parsed JSON can still pass an id or a list of
|
|
285
|
-
* them, and a scalar read as a map has no keys: the statement would address every row.
|
|
286
|
-
*/
|
|
287
|
-
export function assertWhere(meta, where) {
|
|
288
|
-
if (!isWhereMap(where)) {
|
|
289
|
-
throw new UqlUsageError(`$where on '${entityName(meta)}' must be a map of conditions, such as { id: 1 }`);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
249
|
/** Returns a `QueryOptions.filters` value with the built-in soft-delete filter disabled (used by hard delete). */
|
|
293
250
|
export function withoutSoftDeleteFilter(filters) {
|
|
294
251
|
return filters === false ? false : { ...filters, [SOFT_DELETE_FILTER]: false };
|
|
@@ -314,12 +271,9 @@ export function applyFilters(meta, whereMap, opts) {
|
|
|
314
271
|
}
|
|
315
272
|
}
|
|
316
273
|
}
|
|
274
|
+
const merged = result;
|
|
317
275
|
const security = securityConditions(meta).map(([, condition]) => condition);
|
|
318
|
-
|
|
319
|
-
const existing = result['$and'];
|
|
320
|
-
result['$and'] = existing ? [...existing, ...security] : security;
|
|
321
|
-
}
|
|
322
|
-
return result;
|
|
276
|
+
return security.length ? whereAnd(merged, security) : merged;
|
|
323
277
|
}
|
|
324
278
|
/**
|
|
325
279
|
* Each `security` filter's condition, by name, resolved against the ambient context. One resolving to
|
|
@@ -39,6 +39,15 @@ export declare function isSoleIdField<E>(meta: EntityMeta<E>, field: FieldOption
|
|
|
39
39
|
* states its width. The one answer the create statement and the diff both read.
|
|
40
40
|
*/
|
|
41
41
|
export declare function isAutoIncrement(field: FieldOptions, isPrimaryKey: boolean): boolean;
|
|
42
|
+
/** The column family of a field, from its `columnType` if set, else from its `type`. */
|
|
43
|
+
export declare function fieldFamily(field: FieldOptions): ColumnFamily | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Whether the column is NOT NULL: the field declares `nullable: false` or is a key. A key counts whatever its
|
|
46
|
+
* property says: `id?: number` is optional because the database assigns it, not because it can be null.
|
|
47
|
+
*/
|
|
48
|
+
export declare function declaresNotNull(field: FieldOptions): boolean;
|
|
49
|
+
/** Whether `key` is a field of `meta`, as opposed to a relation, a JSON path or an unknown key. */
|
|
50
|
+
export declare function isFieldKey<E>(meta: EntityMeta<E>, key: string): key is FieldKey<E>;
|
|
42
51
|
/** The fields `meta` declares whose options `pick` accepts, in declaration order, each as the entity's own key. */
|
|
43
52
|
export declare function fieldKeys<E>(meta: EntityMeta<E>, pick: (field: FieldMeta) => unknown): FieldKey<E>[];
|
|
44
53
|
/**
|
package/dist/util/field.util.js
CHANGED
|
@@ -83,6 +83,21 @@ export function isAutoIncrement(field, isPrimaryKey) {
|
|
|
83
83
|
return field.autoIncrement;
|
|
84
84
|
return isPrimaryKey && columnFamily(field.type) === 'numeric' && !field.onInsert && !field.references;
|
|
85
85
|
}
|
|
86
|
+
/** The column family of a field, from its `columnType` if set, else from its `type`. */
|
|
87
|
+
export function fieldFamily(field) {
|
|
88
|
+
return columnFamily(field.columnType ?? field.type);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Whether the column is NOT NULL: the field declares `nullable: false` or is a key. A key counts whatever its
|
|
92
|
+
* property says: `id?: number` is optional because the database assigns it, not because it can be null.
|
|
93
|
+
*/
|
|
94
|
+
export function declaresNotNull(field) {
|
|
95
|
+
return field.isId === true || field.nullable === false;
|
|
96
|
+
}
|
|
97
|
+
/** Whether `key` is a field of `meta`, as opposed to a relation, a JSON path or an unknown key. */
|
|
98
|
+
export function isFieldKey(meta, key) {
|
|
99
|
+
return meta.fields[key] !== undefined;
|
|
100
|
+
}
|
|
86
101
|
/** The fields `meta` declares whose options `pick` accepts, in declaration order, each as the entity's own key. */
|
|
87
102
|
export function fieldKeys(meta, pick) {
|
|
88
103
|
const fields = meta.fields;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryRaw } from '../type/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { fieldFamily, isInlinedExpression } from './field.util.js';
|
|
3
3
|
import { getKeys } from './object.util.js';
|
|
4
4
|
import { constantSql } from './raw.js';
|
|
5
5
|
/**
|
|
@@ -112,7 +112,7 @@ export function fieldOptionConflict(opts) {
|
|
|
112
112
|
if (opts.columnType instanceof QueryRaw && constantSql(opts.columnType) === undefined) {
|
|
113
113
|
return "cannot use 'columnType': a `raw` one names a constant type, so it can bind no value and read no column";
|
|
114
114
|
}
|
|
115
|
-
const family =
|
|
115
|
+
const family = fieldFamily(opts);
|
|
116
116
|
// Walked in table order, not in the order the field happened to be written, so a field with two
|
|
117
117
|
// conflicts always reports the same one. An option no rule knows is a typo, which `@Field`'s own check
|
|
118
118
|
// reports where it can still be spelled right.
|
package/dist/util/index.d.ts
CHANGED
package/dist/util/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { EntityMeta } from '../type/index.js';
|
|
2
|
-
export declare function throwPendingTransaction(): never;
|
|
3
|
-
export declare function throwNoPendingTransaction(): never;
|
|
4
2
|
export declare function clone<T>(value: T): T;
|
|
5
3
|
/** Whether `obj` has at least one enumerable key. Narrows away `undefined`/`null` for callers. */
|
|
6
4
|
export declare function hasKeys<T>(obj: T): obj is NonNullable<T>;
|
package/dist/util/object.util.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import { UqlUsageError } from './uqlError.js';
|
|
2
|
-
export function throwPendingTransaction() {
|
|
3
|
-
throw new UqlUsageError('pending transaction');
|
|
4
|
-
}
|
|
5
|
-
export function throwNoPendingTransaction() {
|
|
6
|
-
throw new UqlUsageError('not a pending transaction');
|
|
7
|
-
}
|
|
8
1
|
export function clone(value) {
|
|
9
2
|
if (typeof value !== 'object' || value === null) {
|
|
10
3
|
return value;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { EntityId, EntityMeta, FieldKey, Query, QueryConflictPaths, QuerySearch, QuerySortDirection, QuerySortMap, QueryWhere, QueryWhereArray } from '../type/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Maps each of `keys` to `true`, the shape of a `$select` or conflict paths. This and the builders below hold
|
|
4
|
+
* the casts generic code needs to build a statement: the compiler types these maps per entity, so it does not
|
|
5
|
+
* accept a key read at run time as one of their keys.
|
|
6
|
+
*/
|
|
7
|
+
export declare function keySet<E>(keys: readonly FieldKey<E>[]): QueryConflictPaths<E>;
|
|
8
|
+
/** `where` (or an empty `$where`) with `key` also set to `value`. Keys in one map combine with `AND`. */
|
|
9
|
+
export declare function whereWith<E>(key: FieldKey<E>, value: unknown, where?: QueryWhere<E>): QueryWhere<E>;
|
|
10
|
+
export declare function whereEach<E>(keys: readonly FieldKey<E>[], valueOf: (key: FieldKey<E>) => unknown): QueryWhere<E>;
|
|
11
|
+
export declare function whereAnyOf<E>(clauses: QueryWhereArray<E>): QueryWhere<E>;
|
|
12
|
+
/** A `$sort` from `[key, direction]` pairs, sorting by the keys in the order given. */
|
|
13
|
+
export declare function sortOf<E>(entries: readonly (readonly [FieldKey<E>, QuerySortDirection])[]): QuerySortMap<E>;
|
|
14
|
+
/**
|
|
15
|
+
* Appends `clauses` to the `$and` of `where`. Merging them into its keys instead could lose one to a key of
|
|
16
|
+
* the same name, such as a second `$or`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function whereAnd<E>(where: QueryWhere<E> | undefined, clauses: QueryWhereArray<E>): QueryWhere<E>;
|
|
19
|
+
/** `q` selecting only the id. A write passes it to its backend's read builder to find the rows it will act on. */
|
|
20
|
+
export declare function idOnlyQuery<E>(meta: EntityMeta<E>, q: QuerySearch<E>): Query<E>;
|
|
21
|
+
/**
|
|
22
|
+
* A `$where` selecting rows by key. A bare value matches the single key column (refused on a composite key),
|
|
23
|
+
* a composite key's map is already a `$where`, and a list becomes an `IN` of bare values or an `$or` of maps.
|
|
24
|
+
*/
|
|
25
|
+
export declare function whereIds<E>(meta: EntityMeta<E>, ids: EntityId<E> | EntityId<E>[]): QueryWhere<E>;
|
|
26
|
+
/**
|
|
27
|
+
* Throws on a `$where` that is not a map. Untyped JS and parsed JSON can still pass an id or a list of ids,
|
|
28
|
+
* and a scalar read as a map has no keys, so the statement would match every row.
|
|
29
|
+
*/
|
|
30
|
+
export declare function assertWhere<E>(meta: EntityMeta<E>, where: unknown): void;
|
|
31
|
+
/** A parsed `$sort` direction: whether it is descending, and where it puts nulls if it says. */
|
|
32
|
+
export type SortDirection = {
|
|
33
|
+
readonly desc: boolean;
|
|
34
|
+
readonly nulls?: 'first' | 'last';
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Parses a `$sort` direction. Every backend and the page cursor share this one parser, so a sort order and
|
|
38
|
+
* the cursor condition that pages through it cannot disagree.
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseSortDirection(value: unknown): SortDirection;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { soleIdOf } from '../entity/metadata/definition.js';
|
|
2
|
+
import { entityName, isScalarId, isWhereMap } from './object.util.js';
|
|
3
|
+
import { UqlUsageError } from './uqlError.js';
|
|
4
|
+
/**
|
|
5
|
+
* Maps each of `keys` to `true`, the shape of a `$select` or conflict paths. This and the builders below hold
|
|
6
|
+
* the casts generic code needs to build a statement: the compiler types these maps per entity, so it does not
|
|
7
|
+
* accept a key read at run time as one of their keys.
|
|
8
|
+
*/
|
|
9
|
+
export function keySet(keys) {
|
|
10
|
+
return Object.fromEntries(keys.map((key) => [key, true]));
|
|
11
|
+
}
|
|
12
|
+
/** `where` (or an empty `$where`) with `key` also set to `value`. Keys in one map combine with `AND`. */
|
|
13
|
+
export function whereWith(key, value, where) {
|
|
14
|
+
return { ...where, [key]: value };
|
|
15
|
+
}
|
|
16
|
+
export function whereEach(keys, valueOf) {
|
|
17
|
+
return Object.fromEntries(keys.map((key) => [key, valueOf(key)]));
|
|
18
|
+
}
|
|
19
|
+
export function whereAnyOf(clauses) {
|
|
20
|
+
return { $or: clauses };
|
|
21
|
+
}
|
|
22
|
+
/** A `$sort` from `[key, direction]` pairs, sorting by the keys in the order given. */
|
|
23
|
+
export function sortOf(entries) {
|
|
24
|
+
return Object.fromEntries(entries);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Appends `clauses` to the `$and` of `where`. Merging them into its keys instead could lose one to a key of
|
|
28
|
+
* the same name, such as a second `$or`.
|
|
29
|
+
*/
|
|
30
|
+
export function whereAnd(where, clauses) {
|
|
31
|
+
return { ...where, $and: [...(where?.$and ?? []), ...clauses] };
|
|
32
|
+
}
|
|
33
|
+
/** `q` selecting only the id. A write passes it to its backend's read builder to find the rows it will act on. */
|
|
34
|
+
export function idOnlyQuery(meta, q) {
|
|
35
|
+
return { ...q, $select: keySet(meta.ids) };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A `$where` selecting rows by key. A bare value matches the single key column (refused on a composite key),
|
|
39
|
+
* a composite key's map is already a `$where`, and a list becomes an `IN` of bare values or an `$or` of maps.
|
|
40
|
+
*/
|
|
41
|
+
export function whereIds(meta, ids) {
|
|
42
|
+
if (Array.isArray(ids) ? ids.every(isScalarId) : isScalarId(ids)) {
|
|
43
|
+
return whereWith(soleIdOf(meta, 'addressing by a bare id value'), ids);
|
|
44
|
+
}
|
|
45
|
+
return (Array.isArray(ids) ? { $or: ids } : ids);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Throws on a `$where` that is not a map. Untyped JS and parsed JSON can still pass an id or a list of ids,
|
|
49
|
+
* and a scalar read as a map has no keys, so the statement would match every row.
|
|
50
|
+
*/
|
|
51
|
+
export function assertWhere(meta, where) {
|
|
52
|
+
if (!isWhereMap(where)) {
|
|
53
|
+
throw new UqlUsageError(`$where on '${entityName(meta)}' must be a map of conditions, such as { id: 1 }`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const SORT_DIRECTIONS = new Map([
|
|
57
|
+
[1, { desc: false }],
|
|
58
|
+
['asc', { desc: false }],
|
|
59
|
+
[-1, { desc: true }],
|
|
60
|
+
['desc', { desc: true }],
|
|
61
|
+
['ascNullsFirst', { desc: false, nulls: 'first' }],
|
|
62
|
+
['ascNullsLast', { desc: false, nulls: 'last' }],
|
|
63
|
+
['descNullsFirst', { desc: true, nulls: 'first' }],
|
|
64
|
+
['descNullsLast', { desc: true, nulls: 'last' }],
|
|
65
|
+
]);
|
|
66
|
+
/**
|
|
67
|
+
* Parses a `$sort` direction. Every backend and the page cursor share this one parser, so a sort order and
|
|
68
|
+
* the cursor condition that pages through it cannot disagree.
|
|
69
|
+
*/
|
|
70
|
+
export function parseSortDirection(value) {
|
|
71
|
+
const direction = SORT_DIRECTIONS.get(value);
|
|
72
|
+
if (!direction) {
|
|
73
|
+
throw new UqlUsageError(`unknown sort direction: ${String(value)}`);
|
|
74
|
+
}
|
|
75
|
+
return direction;
|
|
76
|
+
}
|
package/dist/util/raw.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ export declare function raw(value: QueryRawFn): QueryRaw;
|
|
|
11
11
|
* nowhere to bind a value; `undefined` where it interpolates and so needs one.
|
|
12
12
|
*/
|
|
13
13
|
export declare function constantSql(value: QueryRaw): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The database's current time in UTC to the millisecond, in each engine's SQL, so uql reads the timestamp
|
|
16
|
+
* back exactly. Use it for a stamp, an `onUpdate`, a `$where` or a `defaultValue`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const currentTimestamp: QueryRaw;
|
|
14
19
|
/**
|
|
15
20
|
* The fields of `entity` as {@link ColumnRef}s, each rendering inside `raw` as its column: named the way
|
|
16
21
|
* the dialect names it, so the naming strategy and `@Field({ name })` apply, and qualified by the alias
|
package/dist/util/raw.js
CHANGED
|
@@ -30,6 +30,11 @@ export function raw(value, ...rest) {
|
|
|
30
30
|
export function constantSql(value) {
|
|
31
31
|
return value[RAW_TEXT];
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* The database's current time in UTC to the millisecond, in each engine's SQL, so uql reads the timestamp
|
|
35
|
+
* back exactly. Use it for a stamp, an `onUpdate`, a `$where` or a `defaultValue`.
|
|
36
|
+
*/
|
|
37
|
+
export const currentTimestamp = raw(({ dialect }) => dialect.currentTimestamp);
|
|
33
38
|
/**
|
|
34
39
|
* The fields of `entity` as {@link ColumnRef}s, each rendering inside `raw` as its column: named the way
|
|
35
40
|
* the dialect names it, so the naming strategy and `@Field({ name })` apply, and qualified by the alias
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { QUERY_CLAUSES } from '../type/query.js';
|
|
2
2
|
import { getKeys, isRecord, someKey } from './object.util.js';
|
|
3
3
|
import { UqlUsageError } from './uqlError.js';
|
|
4
4
|
/** What a query populating nothing requests, shared: most reads populate nothing, and ask on every one. */
|
|
@@ -119,17 +119,18 @@ export function countedRelations(meta, counts) {
|
|
|
119
119
|
return [{ relKey, relation, where: where ?? {} }];
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
...RELATION_QUERY_NUMBER_KEYS,
|
|
122
|
+
/**
|
|
123
|
+
* The value type each key of a relation query takes: the clauses scoped to a relation, plus `$required`,
|
|
124
|
+
* which is not a clause. It says how the relation joins, not what it selects.
|
|
125
|
+
*/
|
|
126
|
+
const RELATION_QUERY_VALUES = new Map([
|
|
127
|
+
...getKeys(QUERY_CLAUSES)
|
|
128
|
+
.filter((key) => QUERY_CLAUSES[key].scope === 'relation')
|
|
129
|
+
.map((key) => [key, QUERY_CLAUSES[key].value]),
|
|
130
|
+
['$required', 'boolean'],
|
|
132
131
|
]);
|
|
132
|
+
/** Clauses only a top-level statement takes. A populated relation's query rejects them, naming the clause. */
|
|
133
|
+
const STATEMENT_CLAUSES = getKeys(QUERY_CLAUSES).filter((key) => QUERY_CLAUSES[key].scope === 'statement');
|
|
133
134
|
function isRelationQueryObject(value) {
|
|
134
135
|
return isRecord(value) && isValidRelationQueryShape(value);
|
|
135
136
|
}
|
|
@@ -137,7 +138,7 @@ export function parseRelationQueryValue(value) {
|
|
|
137
138
|
// Caught before the shape check so the message names the key, rather than reporting the whole
|
|
138
139
|
// object as an unrecognized relation query value.
|
|
139
140
|
if (isRecord(value)) {
|
|
140
|
-
const statementOnly =
|
|
141
|
+
const statementOnly = STATEMENT_CLAUSES.find((clause) => clause in value);
|
|
141
142
|
if (statementOnly) {
|
|
142
143
|
throw new UqlUsageError(`'${statementOnly}' applies to the whole statement, not to a populated relation. Move it to the top level of the query.`);
|
|
143
144
|
}
|
|
@@ -172,17 +173,18 @@ function isBooleanLikeValue(value) {
|
|
|
172
173
|
function isValidRelationQueryShape(query) {
|
|
173
174
|
let hasKnownKey = false;
|
|
174
175
|
for (const [key, value] of Object.entries(query)) {
|
|
175
|
-
|
|
176
|
+
const shape = RELATION_QUERY_VALUES.get(key);
|
|
177
|
+
if (shape === undefined) {
|
|
176
178
|
return false;
|
|
177
179
|
}
|
|
178
180
|
hasKnownKey = true;
|
|
179
|
-
if (
|
|
181
|
+
if (shape === 'boolean' && !isBooleanLikeValue(value)) {
|
|
180
182
|
return false;
|
|
181
183
|
}
|
|
182
|
-
if (
|
|
184
|
+
if (shape === 'object' && !isRecord(value) && !(key === '$select' && Array.isArray(value))) {
|
|
183
185
|
return false;
|
|
184
186
|
}
|
|
185
|
-
if (
|
|
187
|
+
if (shape === 'number' && (typeof value !== 'number' || !Number.isFinite(value))) {
|
|
186
188
|
return false;
|
|
187
189
|
}
|
|
188
190
|
}
|
package/dist/util/rowKey.util.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { bytesToHex } from './bytes.js';
|
|
1
2
|
/** Separates the parts of a composite key: a unit separator, which no column value carries. */
|
|
2
3
|
const KEY_SEPARATOR = '\u001f';
|
|
3
4
|
/**
|
|
@@ -19,10 +20,8 @@ function keyPart(value) {
|
|
|
19
20
|
if (value instanceof Date) {
|
|
20
21
|
return value.toISOString();
|
|
21
22
|
}
|
|
22
|
-
// Hex by hand rather than through `Buffer`, which is undefined on the browser and edge runtimes
|
|
23
|
-
// this module reaches through `AbstractQuerier`.
|
|
24
23
|
if (value instanceof Uint8Array) {
|
|
25
|
-
return
|
|
24
|
+
return bytesToHex(value);
|
|
26
25
|
}
|
|
27
26
|
return String(value);
|
|
28
27
|
}
|
package/dist/util/sql.util.d.ts
CHANGED
|
@@ -16,9 +16,15 @@ export declare function obtainAttrsPaths<T extends object>(row: T): {
|
|
|
16
16
|
* `sales.Order_total_idx` is a syntax error.
|
|
17
17
|
*/
|
|
18
18
|
export declare function qualifyName(name: string, schema?: string): string;
|
|
19
|
+
/** Reverses {@link qualifyName}: splits at the last dot into the schema, if any, and the name. */
|
|
20
|
+
export declare function splitQualifiedName(qualified: string): {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly schema?: string;
|
|
23
|
+
};
|
|
19
24
|
/**
|
|
20
|
-
* The name a derived index or constraint
|
|
21
|
-
*
|
|
25
|
+
* The name of a derived index or constraint, such as `Order__total_idx`, with the kind last as Postgres names
|
|
26
|
+
* its own. It leaves out the table's schema, since it is a single identifier. The AST, the DDL and a `DROP`
|
|
27
|
+
* all use this one rule.
|
|
22
28
|
*/
|
|
23
29
|
export declare function derivedConstraintName(table: string, parts: readonly (string | number)[], kind: ConstraintKind): string;
|
|
24
30
|
/** The kinds of derived name, which is also what `indexNameStem` strips to compare them. */
|
package/dist/util/sql.util.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { OWNED_PREFIX } from '../dialect/aliases.js';
|
|
1
|
+
import { OWNED_PREFIX, UPSERT_CREATED_ALIAS } from '../dialect/aliases.js';
|
|
2
2
|
import { hasKeys } from './object.util.js';
|
|
3
|
+
import { fnv1a } from './string.util.js';
|
|
3
4
|
/** Pre-computed regex for each SQL identifier escape character to avoid per-call allocation. */
|
|
4
5
|
const escapeIdRegexCache = { '`': /`/g, '"': /"/g };
|
|
5
6
|
export function unflatObjects(objects) {
|
|
@@ -58,6 +59,11 @@ export function obtainAttrsPaths(row) {
|
|
|
58
59
|
export function qualifyName(name, schema) {
|
|
59
60
|
return schema ? `${schema}.${name}` : name;
|
|
60
61
|
}
|
|
62
|
+
/** Reverses {@link qualifyName}: splits at the last dot into the schema, if any, and the name. */
|
|
63
|
+
export function splitQualifiedName(qualified) {
|
|
64
|
+
const dot = qualified.lastIndexOf('.');
|
|
65
|
+
return dot < 0 ? { name: qualified } : { name: qualified.slice(dot + 1), schema: qualified.slice(0, dot) };
|
|
66
|
+
}
|
|
61
67
|
/**
|
|
62
68
|
* The longest identifier every engine here accepts. Postgres truncates silently at 63 bytes and
|
|
63
69
|
* MySQL errors at 64, so one conservative limit needs no per-dialect plumbing to be safe on both -
|
|
@@ -67,11 +73,13 @@ const MAX_IDENTIFIER_LENGTH = 63;
|
|
|
67
73
|
/** Hex chars of hash kept when a name has to be shortened. 24 bits over one table's constraints. */
|
|
68
74
|
const NAME_HASH_LENGTH = 6;
|
|
69
75
|
/**
|
|
70
|
-
* The name a derived index or constraint
|
|
71
|
-
*
|
|
76
|
+
* The name of a derived index or constraint, such as `Order__total_idx`, with the kind last as Postgres names
|
|
77
|
+
* its own. It leaves out the table's schema, since it is a single identifier. The AST, the DDL and a `DROP`
|
|
78
|
+
* all use this one rule.
|
|
72
79
|
*/
|
|
73
80
|
export function derivedConstraintName(table, parts, kind) {
|
|
74
|
-
const
|
|
81
|
+
const { name } = splitQualifiedName(table);
|
|
82
|
+
const body = parts.length ? `${name}${TABLE_SEPARATOR}${parts.join('_')}` : name;
|
|
75
83
|
return clampIdentifier(`${body}_${kind}`);
|
|
76
84
|
}
|
|
77
85
|
/** Between table and columns, doubled: index names share one namespace per database, where `a` + `b_c` and `a_b` + `c` would collide. */
|
|
@@ -104,18 +112,9 @@ function clampIdentifier(name, reserved = 0) {
|
|
|
104
112
|
const suffix = `_${hashIdentifier(name)}`;
|
|
105
113
|
return name.slice(0, max - suffix.length) + suffix;
|
|
106
114
|
}
|
|
107
|
-
/**
|
|
108
|
-
* FNV-1a, by hand: the package ships zero runtime dependencies, and `node:crypto` is not reachable
|
|
109
|
-
* from the browser and edge entries this module is bundled into. Not a security hash - it only has
|
|
110
|
-
* to spread the names of one table's constraints.
|
|
111
|
-
*/
|
|
115
|
+
/** A short hash that keeps one table's constraint names apart; it needs to do nothing more. */
|
|
112
116
|
function hashIdentifier(value) {
|
|
113
|
-
|
|
114
|
-
for (let i = 0; i < value.length; i++) {
|
|
115
|
-
hash ^= value.charCodeAt(i);
|
|
116
|
-
hash = Math.imul(hash, 0x01000193) >>> 0;
|
|
117
|
-
}
|
|
118
|
-
return hash.toString(16).padStart(NAME_HASH_LENGTH, '0').slice(-NAME_HASH_LENGTH);
|
|
117
|
+
return fnv1a(value).toString(16).padStart(NAME_HASH_LENGTH, '0').slice(-NAME_HASH_LENGTH);
|
|
119
118
|
}
|
|
120
119
|
/**
|
|
121
120
|
* The name a derived index gets when nothing named it: `Order__total_idx`, or `Order__total_uk` for a
|
|
@@ -181,9 +180,9 @@ export function buildUpdateResult(payload) {
|
|
|
181
180
|
ids = sequentialIds(id, changes, stride);
|
|
182
181
|
}
|
|
183
182
|
}
|
|
184
|
-
// Whether the row was created: Postgres's
|
|
183
|
+
// Whether the row was created: Postgres's created flag, or MySQL's 1/2/0 `affectedRows`,
|
|
185
184
|
// which is unreliable under `RETURNING`, so those dialects report nothing.
|
|
186
|
-
const created = (rows?.length === 1 ? rows[0]?.[
|
|
185
|
+
const created = (rows?.length === 1 ? rows[0]?.[UPSERT_CREATED_ALIAS] : undefined) ??
|
|
187
186
|
(insertIdSource !== 'returning' && typeof upsertStatus === 'number' && upsertStatus >= 0 && upsertStatus <= 2
|
|
188
187
|
? upsertStatus === 1
|
|
189
188
|
: undefined);
|
package/dist/util/sqlLiteral.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SQL literal escaping for `Dialect.escape`: ANSI quote doubling, or MySQL's backslashes. UQL binds
|
|
2
2
|
// values instead, so this is the hand-written-SQL hatch, and inline MySQL literals break under
|
|
3
3
|
// `NO_BACKSLASH_ESCAPES` or a GBK-like charset: prefer bound parameters. Postgres arrays are separate.
|
|
4
|
+
import { bytesToHex } from './bytes.js';
|
|
4
5
|
import { utcTimestamp } from './date.js';
|
|
5
6
|
import { UqlUsageError } from './uqlError.js';
|
|
6
7
|
const SINGLE_QUOTE = /'/g;
|
|
@@ -29,17 +30,6 @@ export function unescapeMysqlString(body) {
|
|
|
29
30
|
return body.replace(/\\(.)|''/gs, (_, char) => char === undefined ? "'" : (MYSQL_UNESCAPES[char] ?? char));
|
|
30
31
|
}
|
|
31
32
|
const mysqlStringLiteral = (val) => `'${val.replace(MYSQL_SPECIALS, (char) => MYSQL_ESCAPES[char])}'`;
|
|
32
|
-
const HEX_BYTES = Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, '0'));
|
|
33
|
-
/** Native hex encoder where available (~130x faster on 4 KB); lookup table for browsers. */
|
|
34
|
-
function bytesToHexLiteral(bytes) {
|
|
35
|
-
if (typeof Buffer !== 'undefined') {
|
|
36
|
-
return `X'${Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('hex')}'`;
|
|
37
|
-
}
|
|
38
|
-
let hex = '';
|
|
39
|
-
for (let i = 0; i < bytes.length; i++)
|
|
40
|
-
hex += HEX_BYTES[bytes[i]];
|
|
41
|
-
return `X'${hex}'`;
|
|
42
|
-
}
|
|
43
33
|
/**
|
|
44
34
|
* A factory, not a function taking `escapeString` as an argument: threading it through every call
|
|
45
35
|
* measured 1.1-1.5x slower. Rejects unsupported types rather than stringifying them into SQL.
|
|
@@ -66,7 +56,7 @@ function createEscaper(escapeString, zone = '') {
|
|
|
66
56
|
}
|
|
67
57
|
// A Node `Buffer` is a `Uint8Array` too.
|
|
68
58
|
if (value instanceof Uint8Array) {
|
|
69
|
-
return
|
|
59
|
+
return `X'${bytesToHex(value)}'`;
|
|
70
60
|
}
|
|
71
61
|
if ('toSqlString' in value && typeof value.toSqlString === 'function') {
|
|
72
62
|
return String(value.toSqlString());
|
|
@@ -26,3 +26,8 @@ export declare function singularize(name: string): string;
|
|
|
26
26
|
* @example 'category' -> 'categories'
|
|
27
27
|
*/
|
|
28
28
|
export declare function pluralize(name: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* The FNV-1a hash of `value`, written by hand because the package has zero runtime dependencies and the
|
|
31
|
+
* browser and edge entries cannot reach `node:crypto`. It is not a security hash; it only tells inputs apart.
|
|
32
|
+
*/
|
|
33
|
+
export declare function fnv1a(value: string): number;
|
package/dist/util/string.util.js
CHANGED
|
@@ -89,3 +89,15 @@ export function pluralize(name) {
|
|
|
89
89
|
}
|
|
90
90
|
return name + 's';
|
|
91
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* The FNV-1a hash of `value`, written by hand because the package has zero runtime dependencies and the
|
|
94
|
+
* browser and edge entries cannot reach `node:crypto`. It is not a security hash; it only tells inputs apart.
|
|
95
|
+
*/
|
|
96
|
+
export function fnv1a(value) {
|
|
97
|
+
let hash = 0x811c9dc5;
|
|
98
|
+
for (let i = 0; i < value.length; i++) {
|
|
99
|
+
hash ^= value.charCodeAt(i);
|
|
100
|
+
hash = Math.imul(hash, 0x01000193) >>> 0;
|
|
101
|
+
}
|
|
102
|
+
return hash;
|
|
103
|
+
}
|
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, Deno, 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.92.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=24"
|