uql-orm 0.91.1 → 0.93.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.
Files changed (165) hide show
  1. package/dist/browser/http/bus.js +3 -4
  2. package/dist/browser/http/http.d.ts +1 -2
  3. package/dist/browser/http/http.js +8 -7
  4. package/dist/browser/index.d.ts +0 -1
  5. package/dist/browser/index.js +0 -1
  6. package/dist/browser/querier/httpQuerier.d.ts +18 -20
  7. package/dist/browser/querier/httpQuerier.js +20 -56
  8. package/dist/browser/type/index.d.ts +0 -1
  9. package/dist/browser/type/index.js +0 -1
  10. package/dist/browser/uql-browser.min.js +2 -2
  11. package/dist/browser/uql-browser.min.js.map +11 -12
  12. package/dist/cockroachdb/cockroachDialect.d.ts +4 -1
  13. package/dist/cockroachdb/cockroachDialect.js +6 -2
  14. package/dist/dialect/abstractDialect.d.ts +1 -1
  15. package/dist/dialect/abstractDialect.js +4 -1
  16. package/dist/dialect/abstractSqlDialect.d.ts +68 -37
  17. package/dist/dialect/abstractSqlDialect.js +185 -107
  18. package/dist/dialect/aliases.d.ts +4 -1
  19. package/dist/dialect/aliases.js +5 -2
  20. package/dist/dialect/hydrateColumn.js +3 -10
  21. package/dist/dialect/jsonSql.d.ts +4 -1
  22. package/dist/dialect/jsonSql.js +4 -1
  23. package/dist/dialect/mergeSqlDialect.d.ts +14 -4
  24. package/dist/dialect/mergeSqlDialect.js +32 -15
  25. package/dist/dialect/mysqlLikeSqlDialect.d.ts +16 -24
  26. package/dist/dialect/mysqlLikeSqlDialect.js +38 -52
  27. package/dist/dialect/pgLikeSqlDialect.d.ts +8 -8
  28. package/dist/dialect/pgLikeSqlDialect.js +19 -22
  29. package/dist/http/contract.d.ts +4 -0
  30. package/dist/http/contract.js +1 -0
  31. package/dist/http/handler.d.ts +2 -2
  32. package/dist/http/handler.js +17 -19
  33. package/dist/http/query.d.ts +5 -3
  34. package/dist/http/query.js +42 -42
  35. package/dist/index.d.ts +2 -2
  36. package/dist/index.js +2 -2
  37. package/dist/maria/mariaDialect.d.ts +4 -3
  38. package/dist/maria/mariaDialect.js +4 -6
  39. package/dist/migrate/builder/columnBuilder.d.ts +5 -15
  40. package/dist/migrate/builder/columnBuilder.js +50 -86
  41. package/dist/migrate/builder/index.d.ts +0 -1
  42. package/dist/migrate/builder/index.js +0 -1
  43. package/dist/migrate/builder/migrationBuilder.d.ts +3 -11
  44. package/dist/migrate/builder/migrationBuilder.js +41 -81
  45. package/dist/migrate/builder/tableBuilder.d.ts +0 -7
  46. package/dist/migrate/builder/tableBuilder.js +19 -30
  47. package/dist/migrate/builder/types.d.ts +2 -2
  48. package/dist/migrate/codegen/entityCodeGenerator.js +3 -3
  49. package/dist/migrate/codegen/entityTypes.js +2 -2
  50. package/dist/migrate/codegen/fieldOptionsSource.d.ts +2 -2
  51. package/dist/migrate/codegen/fieldOptionsSource.js +22 -14
  52. package/dist/migrate/codegen/indexDecoratorSource.js +64 -41
  53. package/dist/migrate/ddl/defaultSql.d.ts +31 -0
  54. package/dist/migrate/ddl/defaultSql.js +109 -0
  55. package/dist/migrate/ddl/index.d.ts +2 -4
  56. package/dist/migrate/ddl/index.js +14 -5
  57. package/dist/migrate/ddl/mssqlTableDdl.d.ts +1 -0
  58. package/dist/migrate/ddl/mssqlTableDdl.js +4 -1
  59. package/dist/migrate/ddl/mysqlTableDdl.d.ts +17 -0
  60. package/dist/migrate/ddl/mysqlTableDdl.js +33 -0
  61. package/dist/migrate/ddl/pgTableDdl.d.ts +7 -0
  62. package/dist/migrate/ddl/pgTableDdl.js +17 -0
  63. package/dist/migrate/ddl/tableDdl.d.ts +15 -10
  64. package/dist/migrate/ddl/tableDdl.js +31 -32
  65. package/dist/migrate/drift/driftDetector.js +46 -59
  66. package/dist/migrate/generator/definitionToNode.d.ts +11 -7
  67. package/dist/migrate/generator/definitionToNode.js +27 -34
  68. package/dist/migrate/generator/indexNodeToSchema.d.ts +3 -3
  69. package/dist/migrate/generator/indexNodeToSchema.js +5 -4
  70. package/dist/migrate/index.js +1 -1
  71. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +10 -5
  72. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +9 -0
  73. package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -1
  74. package/dist/migrate/introspection/baseSqlIntrospector.js +6 -8
  75. package/dist/migrate/introspection/mssqlIntrospector.js +3 -8
  76. package/dist/migrate/introspection/mysqlIntrospector.d.ts +11 -4
  77. package/dist/migrate/introspection/mysqlIntrospector.js +27 -11
  78. package/dist/migrate/introspection/postgresIntrospector.d.ts +2 -2
  79. package/dist/migrate/introspection/postgresIntrospector.js +3 -3
  80. package/dist/migrate/introspection/sqliteIntrospector.d.ts +1 -1
  81. package/dist/migrate/introspection/sqliteIntrospector.js +7 -10
  82. package/dist/migrate/migrationTarget.js +3 -3
  83. package/dist/migrate/schemaGenerator.d.ts +8 -12
  84. package/dist/migrate/schemaGenerator.js +36 -62
  85. package/dist/migrate/storage/databaseStorage.js +2 -2
  86. package/dist/migrate/triggerSql.d.ts +1 -1
  87. package/dist/migrate/triggerSql.js +17 -8
  88. package/dist/mongo/mongoDialect.d.ts +4 -3
  89. package/dist/mongo/mongoDialect.js +52 -38
  90. package/dist/mongo/mongoIntrospector.js +1 -1
  91. package/dist/mongo/mongoSchemaGenerator.d.ts +7 -4
  92. package/dist/mongo/mongoSchemaGenerator.js +18 -21
  93. package/dist/mongo/mongodbQuerier.d.ts +15 -8
  94. package/dist/mongo/mongodbQuerier.js +48 -33
  95. package/dist/mssql/mssqlDialect.d.ts +9 -5
  96. package/dist/mssql/mssqlDialect.js +23 -8
  97. package/dist/postgres/postgresDialect.d.ts +5 -2
  98. package/dist/postgres/postgresDialect.js +6 -6
  99. package/dist/querier/abstractQuerier.d.ts +20 -15
  100. package/dist/querier/abstractQuerier.js +93 -41
  101. package/dist/querier/abstractQuerierPool.d.ts +26 -24
  102. package/dist/querier/abstractQuerierPool.js +26 -64
  103. package/dist/querier/abstractSqlQuerier.d.ts +5 -6
  104. package/dist/querier/abstractSqlQuerier.js +15 -33
  105. package/dist/querier/cursor.d.ts +10 -0
  106. package/dist/querier/cursor.js +81 -0
  107. package/dist/querier/keyset.d.ts +19 -0
  108. package/dist/querier/keyset.js +198 -0
  109. package/dist/schema/canonicalType.d.ts +3 -3
  110. package/dist/schema/canonicalType.js +13 -12
  111. package/dist/schema/indexDifferences.d.ts +14 -7
  112. package/dist/schema/indexDifferences.js +7 -5
  113. package/dist/schema/schemaAST.d.ts +0 -1
  114. package/dist/schema/schemaAST.js +0 -2
  115. package/dist/schema/schemaASTBuilder.js +14 -20
  116. package/dist/schema/schemaASTDiffer.d.ts +7 -9
  117. package/dist/schema/schemaASTDiffer.js +54 -107
  118. package/dist/schema/sqlExpression.d.ts +28 -0
  119. package/dist/schema/sqlExpression.js +42 -0
  120. package/dist/schema/types.d.ts +48 -105
  121. package/dist/sqlite/sqliteDialect.d.ts +10 -13
  122. package/dist/sqlite/sqliteDialect.js +19 -30
  123. package/dist/type/dialect.d.ts +46 -11
  124. package/dist/type/dialect.js +2 -0
  125. package/dist/type/entity.d.ts +18 -3
  126. package/dist/type/migration.d.ts +7 -7
  127. package/dist/type/querier.d.ts +19 -26
  128. package/dist/type/query.d.ts +116 -25
  129. package/dist/type/query.js +21 -28
  130. package/dist/type/universalQuerier.d.ts +33 -7
  131. package/dist/type/utility.d.ts +10 -0
  132. package/dist/util/bytes.d.ts +7 -0
  133. package/dist/util/bytes.js +22 -0
  134. package/dist/util/date.d.ts +5 -0
  135. package/dist/util/date.js +5 -0
  136. package/dist/util/dialect.util.d.ts +1 -25
  137. package/dist/util/dialect.util.js +4 -50
  138. package/dist/util/field.util.d.ts +9 -0
  139. package/dist/util/field.util.js +15 -0
  140. package/dist/util/fieldOption.util.js +2 -2
  141. package/dist/util/index.d.ts +2 -1
  142. package/dist/util/index.js +2 -1
  143. package/dist/util/object.util.d.ts +0 -2
  144. package/dist/util/object.util.js +0 -7
  145. package/dist/util/query.util.d.ts +40 -0
  146. package/dist/util/query.util.js +76 -0
  147. package/dist/util/raw.d.ts +16 -1
  148. package/dist/util/raw.js +31 -0
  149. package/dist/util/relationQuery.util.js +18 -16
  150. package/dist/util/rowKey.util.js +2 -3
  151. package/dist/util/sql.util.d.ts +8 -2
  152. package/dist/util/sql.util.js +16 -17
  153. package/dist/util/sqlLiteral.js +2 -12
  154. package/dist/util/string.util.d.ts +5 -0
  155. package/dist/util/string.util.js +12 -0
  156. package/dist/util/triggerWrite.d.ts +11 -1
  157. package/dist/util/triggerWrite.js +14 -0
  158. package/package.json +1 -1
  159. package/skills/uql-orm/SKILL.md +22 -10
  160. package/dist/browser/options.d.ts +0 -4
  161. package/dist/browser/options.js +0 -13
  162. package/dist/browser/type/clientQuerierPool.d.ts +0 -4
  163. package/dist/browser/type/clientQuerierPool.js +0 -1
  164. package/dist/migrate/builder/expressions.d.ts +0 -69
  165. package/dist/migrate/builder/expressions.js +0 -145
@@ -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.push(cb);
9
- const index = subscriptors.length - 1;
8
+ subscriptors.add(cb);
10
9
  return () => {
11
- subscriptors.splice(index, 1);
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. Method name must stay uppercase
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: 'get' }, opts);
18
+ return request(url, { method: 'GET' }, opts);
17
19
  }
18
20
  export function post(url, payload, opts) {
19
- return request(url, { method: 'post', body: wireJson(payload) }, opts);
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: 'patch', body: wireJson(payload) }, opts);
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: 'put', body: wireJson(payload) }, opts);
27
+ return request(url, { method: 'PUT', body: wireJson(payload) }, opts);
26
28
  }
27
29
  export function remove(url, opts) {
28
- return request(url, { method: 'delete' }, opts);
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. Method name must stay uppercase
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);
@@ -1,4 +1,3 @@
1
1
  export * from './http/index.js';
2
- export * from './options.js';
3
2
  export * from './querier/index.js';
4
3
  export * from './type/index.js';
@@ -1,4 +1,3 @@
1
1
  export * from './http/index.js';
2
- export * from './options.js';
3
2
  export * from './querier/index.js';
4
3
  export * from './type/index.js';
@@ -1,5 +1,5 @@
1
1
  import { type HttpMethod } from '../../http/contract.js';
2
- import type { EntityWrite, EntityId, FieldKey, QueryFilter, QueryFindResult, QueryOneProjected, QueryOptions, QueryPage, QueryProjected, QuerySearch, RelationKey, RequestCountedSuccessResponse, RequestSuccessResponse, Type, UpdateWrite, WrittenId } from '../../type/index.js';
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<E extends object, const S extends FieldKey<E> = never, const V = true, const X extends FieldKey<E> = never, const P extends RelationKey<E> = never, const C extends RelationKey<E> = never>(entity: Type<E>, id: EntityId<E>, q?: QueryOneProjected<E, S, V, X, P, C, never>, opts?: RequestOptions): Promise<RequestSuccessResponse<QueryFindResult<E, S, V, X, P, C> | undefined>>;
28
- findOne<E extends object, const S extends FieldKey<E> = never, const V = true, const X extends FieldKey<E> = never, const P extends RelationKey<E> = never, const C extends RelationKey<E> = never>(entity: Type<E>, q: QueryOneProjected<E, S, V, X, P, C, never>, opts?: RequestOptions): Promise<RequestSuccessResponse<QueryFindResult<E, S, V, X, P, C> | undefined>>;
29
- findMany<E extends object, const S extends FieldKey<E> = never, const V = true, const X extends FieldKey<E> = never, const P extends RelationKey<E> = never, const C extends RelationKey<E> = never>(entity: Type<E>, q: QueryProjected<E, S, V, X, P, C, never>, opts?: RequestFindOptions): Promise<RequestSuccessResponse<QueryFindResult<E, S, V, X, P, C>[]>>;
30
- findManyAndCount<E extends object, const S extends FieldKey<E> = never, const V = true, const X extends FieldKey<E> = never, const P extends RelationKey<E> = never, const C extends RelationKey<E> = never>(entity: Type<E>, q: QueryProjected<E, S, V, X, P, C, never>, opts?: RequestFindOptions): Promise<RequestCountedSuccessResponse<QueryFindResult<E, S, V, X, P, C>[]>>;
31
- count<E extends object>(entity: Type<E>, q?: QueryPage<E, never>, opts?: RequestOptions): Promise<RequestSuccessResponse<number>>;
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<E extends object>(entity: Type<E>, q?: QueryFilter<E, never>, opts?: RequestOptions): Promise<{
34
- count?: number;
35
- data: boolean;
36
- }>;
37
- insertOne<E extends object>(entity: Type<E>, payload: EntityWrite<E>, opts?: RequestOptions): Promise<RequestSuccessResponse<WrittenId<E> | undefined>>;
38
- insertMany<E extends object>(entity: Type<E>, payload: readonly EntityWrite<E>[], opts?: RequestOptions): Promise<RequestSuccessResponse<(WrittenId<E> | undefined)[]>>;
39
- updateOneById<E extends object>(entity: Type<E>, id: EntityId<E>, payload: UpdateWrite<E, never>, opts?: RequestOptions): Promise<RequestSuccessResponse<number>>;
40
- updateMany<E extends object>(entity: Type<E>, q: QuerySearch<E, never>, payload: UpdateWrite<E, never>, opts?: RequestOptions): Promise<RequestSuccessResponse<number>>;
41
- saveOne<E extends object>(entity: Type<E>, payload: EntityWrite<E>, opts?: RequestOptions): Promise<RequestSuccessResponse<WrittenId<E> | undefined>>;
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
- async findOneById(entity, id, q, opts) {
21
- const basePath = this.getBasePath(entity);
22
- const qs = stringifyQuery(q);
23
- return get(`${basePath}/${idSegment(entity, id)}${qs}`, this.buildOptions(opts));
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
- count(entity, q, opts) {
43
- return this.read(`${this.getBasePath(entity)}${CRUD_ROUTES.count.path}`, q, opts);
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 exists(entity, q, opts) {
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
- const basePath = this.getBasePath(entity);
52
- return post(basePath, payload, this.buildOptions(opts));
53
- }
54
- insertMany(entity, payload, opts) {
55
- const basePath = this.getBasePath(entity);
56
- return post(`${basePath}${CRUD_ROUTES.insertMany.path}`, payload, this.buildOptions(opts));
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(`${basePath}/${idSegment(entity, id)}${qs}`, this.buildOptions(opts));
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,3 +1,2 @@
1
1
  export * from './clientQuerier.js';
2
- export * from './clientQuerierPool.js';
3
2
  export * from './request.js';
@@ -1,3 +1,2 @@
1
1
  export * from './clientQuerier.js';
2
- export * from './clientQuerierPool.js';
3
2
  export * from './request.js';
@@ -1,4 +1,4 @@
1
- var c=[];function d(e){for(let r of c)r(e)}function L(e){c.push(e);let r=c.length-1;return()=>{c.splice(r,1)}}var b=["$select","$populate","$exclude","$where","$sort"],f=["$count"],O=["$skip","$limit"],R=["$candidates"],T=["$distinct"],v=["$lock",...f,...R];var C=Symbol("rawValue"),N=Symbol("rawAlias"),D=Symbol("rawText"),I=Symbol("rawValueType");class k extends Error{}class i extends k{name="UqlUsageError";kind="usage";status=400}function l(e){return e?Object.keys(e):[]}function U(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}var _=["hardDelete","count"],re=new Set([...b,...f,...O,...R,...T,..._]);function u(e){if(!e)return"";let r=new URLSearchParams;for(let n of l(e)){let o=e[n];if(o===void 0)continue;r.append(n,typeof o==="object"&&o!==null?a(o):String(o))}let t=r.toString();return t?`?${t}`:""}function a(e){return JSON.stringify(e,(r,t)=>{if(typeof t!=="object"||t===null)return t;if(C 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 K extends Error{status;constructor(e,r){super(e);this.status=r;this.name="RequestError"}}function x(e,r){return y(e,{method:"get"},r)}function h(e,r,t){return y(e,{method:"post",body:a(r)},t)}function Q(e,r,t){return y(e,{method:"patch",body:a(r)},t)}function g(e,r,t){return y(e,{method:"put",body:a(r)},t)}function m(e,r){return y(e,{method:"delete"},r)}function q(e,r,t){return y(e,{method:"QUERY",body:a(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((o)=>{if(n.status>=200&&n.status<300)return d({phase:"success",opts:t}),o;let P=o,E={message:P?.error?.message??n.statusText,code:P?.error?.code??n.status};throw d({phase:"error",error:E,opts:t}),new K(E.message,E.code)})).finally(()=>{d({phase:"complete",opts:t})})}function V(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 s={findMany:{method:"GET",path:""},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:""}},A=l(s),de=new Map(A.filter((e)=>s[e].method==="GET"&&s[e].path!=="/:id").map((e)=>[s[e].path,e]));function F(e){return V(e.name)}function w(e,r){if(!U(r))throw new i(`'${e.name}' was addressed by an id object, which the HTTP route cannot carry.`);return String(r)}class S{basePath;defaults;constructor(e,r={}){this.basePath=e;this.defaults=r}async findOneById(e,r,t,n){let o=this.getBasePath(e),p=u(t);return x(`${o}/${w(e,r)}${p}`,this.buildOptions(n))}findOne(e,r,t){return this.read(`${this.getBasePath(e)}${s.findOne.path}`,r,t)}findMany(e,r,t){let n={...r};if(t?.count)n.count=!0;return this.read(this.getBasePath(e),n,t)}async findManyAndCount(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}}count(e,r,t){return this.read(`${this.getBasePath(e)}${s.count.path}`,r,t)}async exists(e,r,t){let n=await this.count(e,{...r,$limit:1},t);return{...n,data:n.data>0}}insertOne(e,r,t){let n=this.getBasePath(e);return h(n,r,this.buildOptions(t))}insertMany(e,r,t){let n=this.getBasePath(e);return h(`${n}${s.insertMany.path}`,r,this.buildOptions(t))}async updateOneById(e,r,t,n){let o=this.getBasePath(e);return Q(`${o}/${w(e,r)}`,t,this.buildOptions(n))}updateMany(e,r,t,n){let o=this.getBasePath(e),p=u(r);return Q(`${o}${p}`,t,this.buildOptions(n))}saveOne(e,r,t){let n=this.getBasePath(e);return g(n,r,this.buildOptions(t))}saveMany(e,r,t){let n=this.getBasePath(e);return g(`${n}${s.saveMany.path}`,r,this.buildOptions(t))}async deleteOneById(e,r,t={}){let n=this.getBasePath(e),o=t.hardDelete?u({hardDelete:t.hardDelete}):"";return m(`${n}/${w(e,r)}${o}`,this.buildOptions(t))}deleteMany(e,r,t={}){let n=this.getBasePath(e),o=u(t.hardDelete?{...r,hardDelete:t.hardDelete}:r);return m(`${n}${o}`,this.buildOptions(t))}getBasePath(e){return`${this.basePath}/${(this.defaults.entityPath??F)(e)}`}read(e,r,t){if(this.defaults.readMethod==="QUERY")return q(e,r??{},this.buildOptions(t));return x(`${e}${u(r)}`,this.buildOptions(t))}buildOptions(e){if(!this.defaults.headers&&!e?.headers)return e;return{...e,headers:{...this.defaults.headers,...e?.headers}}}}var j={getQuerier:()=>new S("/api")};function Qe(e){j=e}function W(){return j}function ge(){return W().getQuerier()}export{S as HttpQuerier,K as RequestError,x as get,ge as getQuerier,W as getQuerierPool,d as notify,L as on,Q as patch,h as post,g as put,q as query,m as remove,Qe as setQuerierPool};
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=E62137AC3E6D9C8264756E2164756E21
3
+ //# debugId=378777E0D54B28F864756E2164756E21
4
4
  //# sourceMappingURL=uql-browser.min.js.map