uql-orm 0.91.0 → 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 +7 -13
- package/dist/migrate/codegen/entityTypes.js +6 -20
- 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 +7 -20
- 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 +22 -11
- 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
package/dist/browser/http/bus.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
const subscriptors =
|
|
1
|
+
const subscriptors = new Set();
|
|
2
2
|
export function notify(notification) {
|
|
3
3
|
for (const subscriptor of subscriptors) {
|
|
4
4
|
subscriptor(notification);
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
export function on(cb) {
|
|
8
|
-
subscriptors.
|
|
9
|
-
const index = subscriptors.length - 1;
|
|
8
|
+
subscriptors.add(cb);
|
|
10
9
|
return () => {
|
|
11
|
-
subscriptors.
|
|
10
|
+
subscriptors.delete(cb);
|
|
12
11
|
};
|
|
13
12
|
}
|
|
@@ -15,7 +15,6 @@ export declare function put<T>(url: string, payload: unknown, opts?: RequestOpti
|
|
|
15
15
|
export declare function remove<T>(url: string, opts?: RequestOptions): Promise<RequestSuccessResponse<T>>;
|
|
16
16
|
/**
|
|
17
17
|
* HTTP QUERY (RFC 10008): a safe, idempotent read whose JSON query travels in the
|
|
18
|
-
* request body, avoiding URL-length limits.
|
|
19
|
-
* (fetch only normalizes the classic verbs).
|
|
18
|
+
* request body, avoiding URL-length limits.
|
|
20
19
|
*/
|
|
21
20
|
export declare function query<T>(url: string, payload: unknown, opts?: RequestOptions): Promise<RequestSuccessResponse<T>>;
|
|
@@ -12,25 +12,26 @@ export class RequestError extends Error {
|
|
|
12
12
|
this.name = 'RequestError';
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
// Methods are upper-case because `fetch` normalizes only the classic verbs: a lowercase `patch` or `query`
|
|
16
|
+
// is sent as written, and servers refuse it.
|
|
15
17
|
export function get(url, opts) {
|
|
16
|
-
return request(url, { method: '
|
|
18
|
+
return request(url, { method: 'GET' }, opts);
|
|
17
19
|
}
|
|
18
20
|
export function post(url, payload, opts) {
|
|
19
|
-
return request(url, { method: '
|
|
21
|
+
return request(url, { method: 'POST', body: wireJson(payload) }, opts);
|
|
20
22
|
}
|
|
21
23
|
export function patch(url, payload, opts) {
|
|
22
|
-
return request(url, { method: '
|
|
24
|
+
return request(url, { method: 'PATCH', body: wireJson(payload) }, opts);
|
|
23
25
|
}
|
|
24
26
|
export function put(url, payload, opts) {
|
|
25
|
-
return request(url, { method: '
|
|
27
|
+
return request(url, { method: 'PUT', body: wireJson(payload) }, opts);
|
|
26
28
|
}
|
|
27
29
|
export function remove(url, opts) {
|
|
28
|
-
return request(url, { method: '
|
|
30
|
+
return request(url, { method: 'DELETE' }, opts);
|
|
29
31
|
}
|
|
30
32
|
/**
|
|
31
33
|
* HTTP QUERY (RFC 10008): a safe, idempotent read whose JSON query travels in the
|
|
32
|
-
* request body, avoiding URL-length limits.
|
|
33
|
-
* (fetch only normalizes the classic verbs).
|
|
34
|
+
* request body, avoiding URL-length limits.
|
|
34
35
|
*/
|
|
35
36
|
export function query(url, payload, opts) {
|
|
36
37
|
return request(url, { method: 'QUERY', body: wireJson(payload) }, opts);
|
package/dist/browser/index.d.ts
CHANGED
package/dist/browser/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type HttpMethod } from '../../http/contract.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { SharedQuerier, Type } from '../../type/index.js';
|
|
3
3
|
import type { ClientQuerier, RequestFindOptions, RequestOptions } from '../type/index.js';
|
|
4
4
|
export type HttpQuerierDefaults = {
|
|
5
5
|
/**
|
|
@@ -8,7 +8,7 @@ export type HttpQuerierDefaults = {
|
|
|
8
8
|
*/
|
|
9
9
|
readonly headers?: Record<string, string>;
|
|
10
10
|
/**
|
|
11
|
-
* transport for read queries (findOne, findMany, count). 'QUERY' (RFC 10008) sends the
|
|
11
|
+
* transport for read queries (findOne, findMany, findManyPage, count). 'QUERY' (RFC 10008) sends the
|
|
12
12
|
* JSON query in the request body, avoiding URL-length limits for large queries; requires
|
|
13
13
|
* infrastructure (proxies, CDNs) that forwards the QUERY method. Defaults to 'GET'.
|
|
14
14
|
*/
|
|
@@ -24,25 +24,23 @@ export declare class HttpQuerier implements ClientQuerier {
|
|
|
24
24
|
readonly basePath: string;
|
|
25
25
|
readonly defaults: HttpQuerierDefaults;
|
|
26
26
|
constructor(basePath: string, defaults?: HttpQuerierDefaults);
|
|
27
|
-
findOneById
|
|
28
|
-
findOne
|
|
29
|
-
findMany
|
|
30
|
-
findManyAndCount
|
|
31
|
-
|
|
27
|
+
readonly findOneById: ClientQuerier['findOneById'];
|
|
28
|
+
readonly findOne: ClientQuerier['findOne'];
|
|
29
|
+
readonly findMany: SharedQuerier<'client', RequestFindOptions>['findMany'];
|
|
30
|
+
readonly findManyAndCount: SharedQuerier<'client', RequestFindOptions>['findManyAndCount'];
|
|
31
|
+
readonly findManyPage: ClientQuerier['findManyPage'];
|
|
32
|
+
readonly count: ClientQuerier['count'];
|
|
32
33
|
/** The `count` route capped at one row, so existence needs no endpoint of its own. */
|
|
33
|
-
exists
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
saveMany<E extends object>(entity: Type<E>, payload: readonly EntityWrite<E>[], opts?: RequestOptions): Promise<RequestSuccessResponse<(WrittenId<E> | undefined)[]>>;
|
|
43
|
-
deleteOneById<E extends object>(entity: Type<E>, id: EntityId<E>, opts?: QueryOptions & RequestOptions): Promise<RequestSuccessResponse<number>>;
|
|
44
|
-
deleteMany<E extends object>(entity: Type<E>, q: QuerySearch<E, never>, opts?: QueryOptions & RequestOptions): Promise<RequestSuccessResponse<number>>;
|
|
34
|
+
readonly exists: ClientQuerier['exists'];
|
|
35
|
+
readonly insertOne: ClientQuerier['insertOne'];
|
|
36
|
+
readonly insertMany: ClientQuerier['insertMany'];
|
|
37
|
+
readonly updateOneById: ClientQuerier['updateOneById'];
|
|
38
|
+
readonly updateMany: ClientQuerier['updateMany'];
|
|
39
|
+
readonly saveOne: ClientQuerier['saveOne'];
|
|
40
|
+
readonly saveMany: ClientQuerier['saveMany'];
|
|
41
|
+
readonly deleteOneById: ClientQuerier['deleteOneById'];
|
|
42
|
+
readonly deleteMany: ClientQuerier['deleteMany'];
|
|
45
43
|
getBasePath<E>(entity: Type<E>): string;
|
|
46
|
-
protected read<T>(path: string, q: Record<string, unknown> | undefined, opts?: RequestOptions): Promise<RequestSuccessResponse<T>>;
|
|
44
|
+
protected read<T>(path: string, q: Record<string, unknown> | undefined, opts?: RequestOptions): Promise<import("../../type/wire.js").RequestSuccessResponse<T>>;
|
|
47
45
|
protected buildOptions(opts?: RequestOptions): RequestOptions | undefined;
|
|
48
46
|
}
|
|
@@ -17,71 +17,35 @@ export class HttpQuerier {
|
|
|
17
17
|
this.basePath = basePath;
|
|
18
18
|
this.defaults = defaults;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
findOne(entity, q, opts) {
|
|
26
|
-
return this.read(`${this.getBasePath(entity)}${CRUD_ROUTES.findOne.path}`, q, opts);
|
|
27
|
-
}
|
|
28
|
-
findMany(entity, q, opts) {
|
|
29
|
-
const data = { ...q };
|
|
30
|
-
if (opts?.count) {
|
|
31
|
-
data.count = true;
|
|
32
|
-
}
|
|
33
|
-
return this.read(this.getBasePath(entity), data, opts);
|
|
34
|
-
}
|
|
35
|
-
async findManyAndCount(entity, q, opts) {
|
|
20
|
+
// Typed properties instead of methods, so each takes its signature from `ClientQuerier` rather than repeating it.
|
|
21
|
+
findOneById = async (entity, id, q, opts) => get(`${this.getBasePath(entity)}/${idSegment(entity, id)}${stringifyQuery(q)}`, this.buildOptions(opts));
|
|
22
|
+
findOne = (entity, q, opts) => this.read(`${this.getBasePath(entity)}${CRUD_ROUTES.findOne.path}`, q, opts);
|
|
23
|
+
findMany = (entity, q, opts) => this.read(this.getBasePath(entity), opts?.count ? { ...q, count: true } : q, opts);
|
|
24
|
+
findManyAndCount = async (entity, q, opts) => {
|
|
36
25
|
const response = await this.findMany(entity, q, { ...opts, count: true });
|
|
37
26
|
if (typeof response.count !== 'number') {
|
|
38
27
|
throw new TypeError('findManyAndCount response has an invalid count');
|
|
39
28
|
}
|
|
40
29
|
return { ...response, count: response.count };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
30
|
+
};
|
|
31
|
+
findManyPage = (entity, q, opts) => this.read(`${this.getBasePath(entity)}${CRUD_ROUTES.findManyPage.path}`, q, opts);
|
|
32
|
+
count = (entity, q, opts) => this.read(`${this.getBasePath(entity)}${CRUD_ROUTES.count.path}`, q, opts);
|
|
45
33
|
/** The `count` route capped at one row, so existence needs no endpoint of its own. */
|
|
46
|
-
async
|
|
34
|
+
exists = async (entity, q, opts) => {
|
|
47
35
|
const res = await this.count(entity, { ...q, $limit: 1 }, opts);
|
|
48
36
|
return { ...res, data: res.data > 0 };
|
|
49
|
-
}
|
|
50
|
-
insertOne(entity, payload, opts)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
async updateOneById(entity, id, payload, opts) {
|
|
59
|
-
const basePath = this.getBasePath(entity);
|
|
60
|
-
return patch(`${basePath}/${idSegment(entity, id)}`, payload, this.buildOptions(opts));
|
|
61
|
-
}
|
|
62
|
-
updateMany(entity, q, payload, opts) {
|
|
63
|
-
const basePath = this.getBasePath(entity);
|
|
64
|
-
const qs = stringifyQuery(q);
|
|
65
|
-
return patch(`${basePath}${qs}`, payload, this.buildOptions(opts));
|
|
66
|
-
}
|
|
67
|
-
saveOne(entity, payload, opts) {
|
|
68
|
-
const basePath = this.getBasePath(entity);
|
|
69
|
-
return put(basePath, payload, this.buildOptions(opts));
|
|
70
|
-
}
|
|
71
|
-
saveMany(entity, payload, opts) {
|
|
72
|
-
const basePath = this.getBasePath(entity);
|
|
73
|
-
return put(`${basePath}${CRUD_ROUTES.saveMany.path}`, payload, this.buildOptions(opts));
|
|
74
|
-
}
|
|
75
|
-
async deleteOneById(entity, id, opts = {}) {
|
|
76
|
-
const basePath = this.getBasePath(entity);
|
|
37
|
+
};
|
|
38
|
+
insertOne = (entity, payload, opts) => post(this.getBasePath(entity), payload, this.buildOptions(opts));
|
|
39
|
+
insertMany = (entity, payload, opts) => post(`${this.getBasePath(entity)}${CRUD_ROUTES.insertMany.path}`, payload, this.buildOptions(opts));
|
|
40
|
+
updateOneById = async (entity, id, payload, opts) => patch(`${this.getBasePath(entity)}/${idSegment(entity, id)}`, payload, this.buildOptions(opts));
|
|
41
|
+
updateMany = (entity, q, payload, opts) => patch(`${this.getBasePath(entity)}${stringifyQuery(q)}`, payload, this.buildOptions(opts));
|
|
42
|
+
saveOne = (entity, payload, opts) => put(this.getBasePath(entity), payload, this.buildOptions(opts));
|
|
43
|
+
saveMany = (entity, payload, opts) => put(`${this.getBasePath(entity)}${CRUD_ROUTES.saveMany.path}`, payload, this.buildOptions(opts));
|
|
44
|
+
deleteOneById = async (entity, id, opts = {}) => {
|
|
77
45
|
const qs = opts.hardDelete ? stringifyQuery({ hardDelete: opts.hardDelete }) : '';
|
|
78
|
-
return remove(`${
|
|
79
|
-
}
|
|
80
|
-
deleteMany(entity, q, opts = {}) {
|
|
81
|
-
const basePath = this.getBasePath(entity);
|
|
82
|
-
const qs = stringifyQuery(opts.hardDelete ? { ...q, hardDelete: opts.hardDelete } : q);
|
|
83
|
-
return remove(`${basePath}${qs}`, this.buildOptions(opts));
|
|
84
|
-
}
|
|
46
|
+
return remove(`${this.getBasePath(entity)}/${idSegment(entity, id)}${qs}`, this.buildOptions(opts));
|
|
47
|
+
};
|
|
48
|
+
deleteMany = (entity, q, opts = {}) => remove(`${this.getBasePath(entity)}${stringifyQuery(opts.hardDelete ? { ...q, hardDelete: opts.hardDelete } : q)}`, this.buildOptions(opts));
|
|
85
49
|
getBasePath(entity) {
|
|
86
50
|
return `${this.basePath}/${(this.defaults.entityPath ?? entityPath)(entity)}`;
|
|
87
51
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var c=
|
|
1
|
+
var c=new Set;function d(e){for(let r of c)r(e)}function M(e){return c.add(e),()=>{c.delete(e)}}var f={$select:{value:"object",scope:"relation"},$populate:{value:"object",scope:"relation"},$exclude:{value:"object",scope:"relation"},$where:{value:"object",scope:"relation"},$sort:{value:"object",scope:"relation"},$skip:{value:"number",scope:"relation"},$limit:{value:"number",scope:"relation"},$distinct:{value:"boolean",scope:"relation"},$count:{value:"object",scope:"statement"},$candidates:{value:"number",scope:"statement"},$lock:{value:"object",scope:"statement"},$after:{value:"string",scope:"statement"},$before:{value:"string",scope:"statement"}};var w=Symbol("rawValue"),A=Symbol("rawAlias"),F=Symbol("rawText"),W=Symbol("rawValueType");function p(e){return e?Object.keys(e):[]}function b(e){if(typeof e!=="object"||e===null)return!0;if(Array.isArray(e))return!1;let r=Object.getPrototypeOf(e);return r!==Object.prototype&&r!==null}class P extends Error{}class i extends P{name="UqlUsageError";kind="usage";status=400}var k=["hardDelete","count"];var H=new Map([...p(f).map((e)=>[e,f[e].value]),...k.map((e)=>[e,"boolean"])]);function a(e){if(!e)return"";let r=new URLSearchParams;for(let n of p(e)){let s=e[n];if(s===void 0)continue;r.append(n,typeof s==="object"&&s!==null?u(s):String(s))}let t=r.toString();return t?`?${t}`:""}function u(e){return JSON.stringify(e,(r,t)=>{if(typeof t!=="object"||t===null)return t;if(w in t)throw new i("raw SQL cannot travel over HTTP: what leaves the browser is JSON");if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))throw new i("binary cannot travel over HTTP: what leaves the browser is JSON");return t})}class S extends Error{status;constructor(e,r){super(e);this.status=r;this.name="RequestError"}}function E(e,r){return y(e,{method:"GET"},r)}function h(e,r,t){return y(e,{method:"POST",body:u(r)},t)}function R(e,r,t){return y(e,{method:"PATCH",body:u(r)},t)}function x(e,r,t){return y(e,{method:"PUT",body:u(r)},t)}function g(e,r){return y(e,{method:"DELETE"},r)}function T(e,r,t){return y(e,{method:"QUERY",body:u(r)},t)}function y(e,r,t){if(d({phase:"start",opts:t}),r.headers={accept:"application/json","content-type":"application/json",...t?.headers},t?.signal)r.signal=t.signal;return fetch(e,r).then((n)=>n.json().then((s)=>{if(n.status>=200&&n.status<300)return d({phase:"success",opts:t}),s;let m=s,l={message:m?.error?.message??n.statusText,code:m?.error?.code??n.status};throw d({phase:"error",error:l,opts:t}),new S(l.message,l.code)})).finally(()=>{d({phase:"complete",opts:t})})}function C(e){let r=e.charAt(0).toLowerCase();for(let t=1;t<e.length;++t)r+=e[t]===e[t].toUpperCase()?"-"+e[t].toLowerCase():e[t];return r}var o={findMany:{method:"GET",path:""},findManyPage:{method:"GET",path:"/page"},findOne:{method:"GET",path:"/one"},count:{method:"GET",path:"/count"},findOneById:{method:"GET",path:"/:id"},insertOne:{method:"POST",path:""},insertMany:{method:"POST",path:"/many"},saveOne:{method:"PUT",path:""},saveMany:{method:"PUT",path:"/many"},updateMany:{method:"PATCH",path:""},updateOneById:{method:"PATCH",path:"/:id"},deleteOneById:{method:"DELETE",path:"/:id"},deleteMany:{method:"DELETE",path:""}},K=p(o),ne=new Map(K.filter((e)=>o[e].method==="GET"&&o[e].path!=="/:id").map((e)=>[o[e].path,e]));function O(e){return C(e.name)}function Q(e,r){if(!b(r))throw new i(`'${e.name}' was addressed by an id object, which the HTTP route cannot carry.`);return String(r)}class U{basePath;defaults;constructor(e,r={}){this.basePath=e;this.defaults=r}findOneById=async(e,r,t,n)=>E(`${this.getBasePath(e)}/${Q(e,r)}${a(t)}`,this.buildOptions(n));findOne=(e,r,t)=>this.read(`${this.getBasePath(e)}${o.findOne.path}`,r,t);findMany=(e,r,t)=>this.read(this.getBasePath(e),t?.count?{...r,count:!0}:r,t);findManyAndCount=async(e,r,t)=>{let n=await this.findMany(e,r,{...t,count:!0});if(typeof n.count!=="number")throw TypeError("findManyAndCount response has an invalid count");return{...n,count:n.count}};findManyPage=(e,r,t)=>this.read(`${this.getBasePath(e)}${o.findManyPage.path}`,r,t);count=(e,r,t)=>this.read(`${this.getBasePath(e)}${o.count.path}`,r,t);exists=async(e,r,t)=>{let n=await this.count(e,{...r,$limit:1},t);return{...n,data:n.data>0}};insertOne=(e,r,t)=>h(this.getBasePath(e),r,this.buildOptions(t));insertMany=(e,r,t)=>h(`${this.getBasePath(e)}${o.insertMany.path}`,r,this.buildOptions(t));updateOneById=async(e,r,t,n)=>R(`${this.getBasePath(e)}/${Q(e,r)}`,t,this.buildOptions(n));updateMany=(e,r,t,n)=>R(`${this.getBasePath(e)}${a(r)}`,t,this.buildOptions(n));saveOne=(e,r,t)=>x(this.getBasePath(e),r,this.buildOptions(t));saveMany=(e,r,t)=>x(`${this.getBasePath(e)}${o.saveMany.path}`,r,this.buildOptions(t));deleteOneById=async(e,r,t={})=>{let n=t.hardDelete?a({hardDelete:t.hardDelete}):"";return g(`${this.getBasePath(e)}/${Q(e,r)}${n}`,this.buildOptions(t))};deleteMany=(e,r,t={})=>g(`${this.getBasePath(e)}${a(t.hardDelete?{...r,hardDelete:t.hardDelete}:r)}`,this.buildOptions(t));getBasePath(e){return`${this.basePath}/${(this.defaults.entityPath??O)(e)}`}read(e,r,t){if(this.defaults.readMethod==="QUERY")return T(e,r??{},this.buildOptions(t));return E(`${e}${a(r)}`,this.buildOptions(t))}buildOptions(e){if(!this.defaults.headers&&!e?.headers)return e;return{...e,headers:{...this.defaults.headers,...e?.headers}}}}export{U as HttpQuerier,S as RequestError,E as get,d as notify,M as on,R as patch,h as post,x as put,T as query,g as remove};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=378777E0D54B28F864756E2164756E21
|
|
4
4
|
//# sourceMappingURL=uql-browser.min.js.map
|