@atscript/db-client 0.1.144 → 0.1.145

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/index.cjs CHANGED
@@ -248,13 +248,7 @@ var Client = class {
248
248
  */
249
249
  async one(id, query) {
250
250
  const controlStr = query?.controls ? (0, _uniqu_url_builder.buildUrl)({ controls: query.controls }) : "";
251
- if (id !== null && typeof id === "object") {
252
- const params = this._idToParams(id);
253
- if (controlStr) for (const [k, v] of new URLSearchParams(controlStr)) params.set(k, v);
254
- const qs = params.toString();
255
- return this._getOrNull(`one${qs ? `?${qs}` : ""}`);
256
- }
257
- return this._getOrNull(`one/${encodeURIComponent(String(id))}${controlStr ? `?${controlStr}` : ""}`);
251
+ return this._getOrNull(this._idUrl("one", id, controlStr));
258
252
  }
259
253
  async insert(data) {
260
254
  return this._request("POST", "", await this._prepareWrite(data, "insert"));
@@ -282,8 +276,7 @@ var Client = class {
282
276
  * `DELETE /:id` or `DELETE /?k1=v1&k2=v2` — remove a record by primary key.
283
277
  */
284
278
  async remove(id) {
285
- if (id !== null && typeof id === "object") return this._request("DELETE", `?${this._idToParams(id).toString()}`);
286
- return this._request("DELETE", encodeURIComponent(String(id)));
279
+ return this._request("DELETE", this._idUrl("", id));
287
280
  }
288
281
  /**
289
282
  * `GET /meta` — table/view metadata (cached after first call).
@@ -348,6 +341,18 @@ var Client = class {
348
341
  return this._postAction(action, body);
349
342
  }
350
343
  /**
344
+ * `GET /meta/actions/:id` or `GET /meta/actions?k1=v1&k2=v2` — the
345
+ * row-level actions the caller may run on one row right now, and the
346
+ * reasons of those disabled with one: `{ actions, disabledReasons? }`.
347
+ * Works for rows the caller cannot read; an unknown or out-of-scope id
348
+ * resolves to `{ actions: [] }`. Id forms as {@link one}.
349
+ *
350
+ * @since 0.1.145
351
+ */
352
+ async availableActions(id) {
353
+ return this._request("GET", this._idUrl("meta/actions", id));
354
+ }
355
+ /**
351
356
  * Fetches and caches the deserialized form schema for an action's
352
357
  * `@InputForm()` parameter. Returns `null` when the action has no form
353
358
  * declared, or doesn't exist on `/meta`. Callers typically pass the
@@ -442,6 +447,21 @@ var Client = class {
442
447
  for (const [k, v] of Object.entries(id)) params.set(k, String(v));
443
448
  return params;
444
449
  }
450
+ /**
451
+ * The endpoint addressing one row under `base`: `base/<id>` for a scalar
452
+ * id, `base?k1=v1&k2=v2` for an object id; `query` (a query string) is
453
+ * appended.
454
+ */
455
+ _idUrl(base, id, query = "") {
456
+ if (id !== null && typeof id === "object") {
457
+ const params = this._idToParams(id);
458
+ for (const [k, v] of new URLSearchParams(query)) params.set(k, v);
459
+ const qs = params.toString();
460
+ return qs ? `${base}?${qs}` : base;
461
+ }
462
+ const path = `${base ? `${base}/` : ""}${encodeURIComponent(String(id))}`;
463
+ return query ? `${path}?${query}` : path;
464
+ }
445
465
  async _getOrNull(endpoint) {
446
466
  try {
447
467
  return await this._request("GET", endpoint);
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { A as TDbDeleteResult, C as OwnOf, D as RowOf, E as RelationInfo, F as Uniquery, I as UniqueryControls, L as ValidGroupBy, M as TDbInsertResult, N as TDbUpdateResult, O as SearchIndexInfo, P as TypedWithRelation, R as WeekStart, S as NavOf, T as PatchOf, _ as DbRow, a as ValidatorMode, b as IdOf, c as AggregateResult, d as BucketUnit, f as CalendarBucketLabel, g as DbPatch, h as DataOf, j as TDbInsertManyResult, k as ServerError, l as AtscriptClientShape, m as ClientResponse, n as ClientValidator, p as ClientOptions, r as ClientValidatorOptions, s as AggregateQuery, t as ClientValidationError, u as BucketExpr, v as FieldMeta, w as PageResult, x as MetaResponse, y as FilterExpr } from "./validator-810-rhnQ.cjs";
2
2
  import { AggregateExpr, AggregateQuery as AggregateQuery$1, AggregateResult as AggregateResult$1, BucketExpr as BucketExpr$1, Uniquery as Uniquery$1, UniqueryControls as UniqueryControls$1, ValidGroupBy as ValidGroupBy$1, bucketStartInstant, nextBucketLabel } from "@uniqu/core";
3
3
  import { TAtscriptAnnotatedType, TSerializedAnnotatedType } from "@atscript/typescript/utils";
4
- import { TCrudOp, TCrudPermissions, TDbActionInfo, TDbActionIntent, TDbActionLevel, TDbActionProcessor, TDbDeleteResult as TDbDeleteResult$1, TDbInsertManyResult as TDbInsertManyResult$1, TDbInsertResult as TDbInsertResult$1, TDbUpdateResult as TDbUpdateResult$1 } from "@atscript/db";
4
+ import { TCrudOp, TCrudPermissions, TDbActionInfo, TDbActionIntent, TDbActionLevel, TDbActionProcessor, TDbAvailableActions, TDbAvailableActions as TDbAvailableActions$1, TDbDeleteResult as TDbDeleteResult$1, TDbInsertManyResult as TDbInsertManyResult$1, TDbInsertResult as TDbInsertResult$1, TDbUpdateResult as TDbUpdateResult$1 } from "@atscript/db";
5
5
 
6
6
  //#region src/client.d.ts
7
7
  type Own<T> = OwnOf<T>;
@@ -171,6 +171,16 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape> {
171
171
  * `{ message?: string, ... }`); the client cannot validate.
172
172
  */
173
173
  action<R = unknown>(name: string, id?: Partial<Own<T>> | Partial<Own<T>>[], input?: unknown): Promise<R>;
174
+ /**
175
+ * `GET /meta/actions/:id` or `GET /meta/actions?k1=v1&k2=v2` — the
176
+ * row-level actions the caller may run on one row right now, and the
177
+ * reasons of those disabled with one: `{ actions, disabledReasons? }`.
178
+ * Works for rows the caller cannot read; an unknown or out-of-scope id
179
+ * resolves to `{ actions: [] }`. Id forms as {@link one}.
180
+ *
181
+ * @since 0.1.145
182
+ */
183
+ availableActions(id: Id<T>): Promise<TDbAvailableActions$1>;
174
184
  /**
175
185
  * Fetches and caches the deserialized form schema for an action's
176
186
  * `@InputForm()` parameter. Returns `null` when the action has no form
@@ -198,6 +208,12 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape> {
198
208
  private _dispatchNavigate;
199
209
  private _postAction;
200
210
  private _idToParams;
211
+ /**
212
+ * The endpoint addressing one row under `base`: `base/<id>` for a scalar
213
+ * id, `base?k1=v1&k2=v2` for an object id; `query` (a query string) is
214
+ * appended.
215
+ */
216
+ private _idUrl;
201
217
  private _getOrNull;
202
218
  private _get;
203
219
  private _resolveHeaders;
@@ -366,4 +382,4 @@ declare class ActionUnsupportedError extends Error {
366
382
  constructor(action: string, processor: string, message: string);
367
383
  }
368
384
  //#endregion
369
- export { ActionDisabledError, type ActionDisabledErrorBody, ActionNotFoundError, ActionUnsupportedError, type AggregateQuery, type AggregateResult, type AtscriptClientShape, type BucketExpr, type BucketUnit, type CalendarBucketLabel, Client, ClientError, type ClientOptions, type ClientResponse, type ClientValidationError, type ClientValidator, type ClientValidatorOptions, type DataOf, type DbPatch, type DbRow, type FieldMeta, type FilterExpr, type IdOf, type MetaResponse, type NavOf, type OwnOf, type PageResult, type PatchOf, type RelationInfo, type RowOf, type SearchIndexInfo, type ServerError, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TDbDeleteResult, type TDbInsertManyResult, type TDbInsertResult, type TDbUpdateResult, type TSerializedAnnotatedType, TransportError, type TypedWithRelation, type Uniquery, type UniqueryControls, type ValidGroupBy, type ValidatorMode, VersionMismatchError, type VersionMismatchErrorBody, type WeekStart, bucketStartInstant, encodeNavigateId, formatIdentifier, formatIdentifierField, nextBucketLabel };
385
+ export { ActionDisabledError, type ActionDisabledErrorBody, ActionNotFoundError, ActionUnsupportedError, type AggregateQuery, type AggregateResult, type AtscriptClientShape, type BucketExpr, type BucketUnit, type CalendarBucketLabel, Client, ClientError, type ClientOptions, type ClientResponse, type ClientValidationError, type ClientValidator, type ClientValidatorOptions, type DataOf, type DbPatch, type DbRow, type FieldMeta, type FilterExpr, type IdOf, type MetaResponse, type NavOf, type OwnOf, type PageResult, type PatchOf, type RelationInfo, type RowOf, type SearchIndexInfo, type ServerError, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TDbAvailableActions, type TDbDeleteResult, type TDbInsertManyResult, type TDbInsertResult, type TDbUpdateResult, type TSerializedAnnotatedType, TransportError, type TypedWithRelation, type Uniquery, type UniqueryControls, type ValidGroupBy, type ValidatorMode, VersionMismatchError, type VersionMismatchErrorBody, type WeekStart, bucketStartInstant, encodeNavigateId, formatIdentifier, formatIdentifierField, nextBucketLabel };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { A as TDbDeleteResult, C as OwnOf, D as RowOf, E as RelationInfo, F as Uniquery, I as UniqueryControls, L as ValidGroupBy, M as TDbInsertResult, N as TDbUpdateResult, O as SearchIndexInfo, P as TypedWithRelation, R as WeekStart, S as NavOf, T as PatchOf, _ as DbRow, a as ValidatorMode, b as IdOf, c as AggregateResult, d as BucketUnit, f as CalendarBucketLabel, g as DbPatch, h as DataOf, j as TDbInsertManyResult, k as ServerError, l as AtscriptClientShape, m as ClientResponse, n as ClientValidator, p as ClientOptions, r as ClientValidatorOptions, s as AggregateQuery, t as ClientValidationError, u as BucketExpr, v as FieldMeta, w as PageResult, x as MetaResponse, y as FilterExpr } from "./validator-CIm1ZCS5.mjs";
2
2
  import { TAtscriptAnnotatedType, TSerializedAnnotatedType } from "@atscript/typescript/utils";
3
3
  import { AggregateExpr, AggregateQuery as AggregateQuery$1, AggregateResult as AggregateResult$1, BucketExpr as BucketExpr$1, Uniquery as Uniquery$1, UniqueryControls as UniqueryControls$1, ValidGroupBy as ValidGroupBy$1, bucketStartInstant, nextBucketLabel } from "@uniqu/core";
4
- import { TCrudOp, TCrudPermissions, TDbActionInfo, TDbActionIntent, TDbActionLevel, TDbActionProcessor, TDbDeleteResult as TDbDeleteResult$1, TDbInsertManyResult as TDbInsertManyResult$1, TDbInsertResult as TDbInsertResult$1, TDbUpdateResult as TDbUpdateResult$1 } from "@atscript/db";
4
+ import { TCrudOp, TCrudPermissions, TDbActionInfo, TDbActionIntent, TDbActionLevel, TDbActionProcessor, TDbAvailableActions, TDbAvailableActions as TDbAvailableActions$1, TDbDeleteResult as TDbDeleteResult$1, TDbInsertManyResult as TDbInsertManyResult$1, TDbInsertResult as TDbInsertResult$1, TDbUpdateResult as TDbUpdateResult$1 } from "@atscript/db";
5
5
 
6
6
  //#region src/client.d.ts
7
7
  type Own<T> = OwnOf<T>;
@@ -171,6 +171,16 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape> {
171
171
  * `{ message?: string, ... }`); the client cannot validate.
172
172
  */
173
173
  action<R = unknown>(name: string, id?: Partial<Own<T>> | Partial<Own<T>>[], input?: unknown): Promise<R>;
174
+ /**
175
+ * `GET /meta/actions/:id` or `GET /meta/actions?k1=v1&k2=v2` — the
176
+ * row-level actions the caller may run on one row right now, and the
177
+ * reasons of those disabled with one: `{ actions, disabledReasons? }`.
178
+ * Works for rows the caller cannot read; an unknown or out-of-scope id
179
+ * resolves to `{ actions: [] }`. Id forms as {@link one}.
180
+ *
181
+ * @since 0.1.145
182
+ */
183
+ availableActions(id: Id<T>): Promise<TDbAvailableActions$1>;
174
184
  /**
175
185
  * Fetches and caches the deserialized form schema for an action's
176
186
  * `@InputForm()` parameter. Returns `null` when the action has no form
@@ -198,6 +208,12 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape> {
198
208
  private _dispatchNavigate;
199
209
  private _postAction;
200
210
  private _idToParams;
211
+ /**
212
+ * The endpoint addressing one row under `base`: `base/<id>` for a scalar
213
+ * id, `base?k1=v1&k2=v2` for an object id; `query` (a query string) is
214
+ * appended.
215
+ */
216
+ private _idUrl;
201
217
  private _getOrNull;
202
218
  private _get;
203
219
  private _resolveHeaders;
@@ -366,4 +382,4 @@ declare class ActionUnsupportedError extends Error {
366
382
  constructor(action: string, processor: string, message: string);
367
383
  }
368
384
  //#endregion
369
- export { ActionDisabledError, type ActionDisabledErrorBody, ActionNotFoundError, ActionUnsupportedError, type AggregateQuery, type AggregateResult, type AtscriptClientShape, type BucketExpr, type BucketUnit, type CalendarBucketLabel, Client, ClientError, type ClientOptions, type ClientResponse, type ClientValidationError, type ClientValidator, type ClientValidatorOptions, type DataOf, type DbPatch, type DbRow, type FieldMeta, type FilterExpr, type IdOf, type MetaResponse, type NavOf, type OwnOf, type PageResult, type PatchOf, type RelationInfo, type RowOf, type SearchIndexInfo, type ServerError, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TDbDeleteResult, type TDbInsertManyResult, type TDbInsertResult, type TDbUpdateResult, type TSerializedAnnotatedType, TransportError, type TypedWithRelation, type Uniquery, type UniqueryControls, type ValidGroupBy, type ValidatorMode, VersionMismatchError, type VersionMismatchErrorBody, type WeekStart, bucketStartInstant, encodeNavigateId, formatIdentifier, formatIdentifierField, nextBucketLabel };
385
+ export { ActionDisabledError, type ActionDisabledErrorBody, ActionNotFoundError, ActionUnsupportedError, type AggregateQuery, type AggregateResult, type AtscriptClientShape, type BucketExpr, type BucketUnit, type CalendarBucketLabel, Client, ClientError, type ClientOptions, type ClientResponse, type ClientValidationError, type ClientValidator, type ClientValidatorOptions, type DataOf, type DbPatch, type DbRow, type FieldMeta, type FilterExpr, type IdOf, type MetaResponse, type NavOf, type OwnOf, type PageResult, type PatchOf, type RelationInfo, type RowOf, type SearchIndexInfo, type ServerError, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TDbAvailableActions, type TDbDeleteResult, type TDbInsertManyResult, type TDbInsertResult, type TDbUpdateResult, type TSerializedAnnotatedType, TransportError, type TypedWithRelation, type Uniquery, type UniqueryControls, type ValidGroupBy, type ValidatorMode, VersionMismatchError, type VersionMismatchErrorBody, type WeekStart, bucketStartInstant, encodeNavigateId, formatIdentifier, formatIdentifierField, nextBucketLabel };
package/dist/index.mjs CHANGED
@@ -247,13 +247,7 @@ var Client = class {
247
247
  */
248
248
  async one(id, query) {
249
249
  const controlStr = query?.controls ? buildUrl({ controls: query.controls }) : "";
250
- if (id !== null && typeof id === "object") {
251
- const params = this._idToParams(id);
252
- if (controlStr) for (const [k, v] of new URLSearchParams(controlStr)) params.set(k, v);
253
- const qs = params.toString();
254
- return this._getOrNull(`one${qs ? `?${qs}` : ""}`);
255
- }
256
- return this._getOrNull(`one/${encodeURIComponent(String(id))}${controlStr ? `?${controlStr}` : ""}`);
250
+ return this._getOrNull(this._idUrl("one", id, controlStr));
257
251
  }
258
252
  async insert(data) {
259
253
  return this._request("POST", "", await this._prepareWrite(data, "insert"));
@@ -281,8 +275,7 @@ var Client = class {
281
275
  * `DELETE /:id` or `DELETE /?k1=v1&k2=v2` — remove a record by primary key.
282
276
  */
283
277
  async remove(id) {
284
- if (id !== null && typeof id === "object") return this._request("DELETE", `?${this._idToParams(id).toString()}`);
285
- return this._request("DELETE", encodeURIComponent(String(id)));
278
+ return this._request("DELETE", this._idUrl("", id));
286
279
  }
287
280
  /**
288
281
  * `GET /meta` — table/view metadata (cached after first call).
@@ -347,6 +340,18 @@ var Client = class {
347
340
  return this._postAction(action, body);
348
341
  }
349
342
  /**
343
+ * `GET /meta/actions/:id` or `GET /meta/actions?k1=v1&k2=v2` — the
344
+ * row-level actions the caller may run on one row right now, and the
345
+ * reasons of those disabled with one: `{ actions, disabledReasons? }`.
346
+ * Works for rows the caller cannot read; an unknown or out-of-scope id
347
+ * resolves to `{ actions: [] }`. Id forms as {@link one}.
348
+ *
349
+ * @since 0.1.145
350
+ */
351
+ async availableActions(id) {
352
+ return this._request("GET", this._idUrl("meta/actions", id));
353
+ }
354
+ /**
350
355
  * Fetches and caches the deserialized form schema for an action's
351
356
  * `@InputForm()` parameter. Returns `null` when the action has no form
352
357
  * declared, or doesn't exist on `/meta`. Callers typically pass the
@@ -441,6 +446,21 @@ var Client = class {
441
446
  for (const [k, v] of Object.entries(id)) params.set(k, String(v));
442
447
  return params;
443
448
  }
449
+ /**
450
+ * The endpoint addressing one row under `base`: `base/<id>` for a scalar
451
+ * id, `base?k1=v1&k2=v2` for an object id; `query` (a query string) is
452
+ * appended.
453
+ */
454
+ _idUrl(base, id, query = "") {
455
+ if (id !== null && typeof id === "object") {
456
+ const params = this._idToParams(id);
457
+ for (const [k, v] of new URLSearchParams(query)) params.set(k, v);
458
+ const qs = params.toString();
459
+ return qs ? `${base}?${qs}` : base;
460
+ }
461
+ const path = `${base ? `${base}/` : ""}${encodeURIComponent(String(id))}`;
462
+ return query ? `${path}?${query}` : path;
463
+ }
444
464
  async _getOrNull(endpoint) {
445
465
  try {
446
466
  return await this._request("GET", endpoint);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/db-client",
3
- "version": "0.1.144",
3
+ "version": "0.1.145",
4
4
  "description": "Browser-compatible HTTP client for @atscript/moost-db REST endpoints.",
5
5
  "keywords": [
6
6
  "atscript",
@@ -47,14 +47,14 @@
47
47
  "@uniqu/url": "^0.1.11"
48
48
  },
49
49
  "devDependencies": {
50
- "@atscript/core": "^0.1.96",
51
- "@atscript/typescript": "^0.1.96",
52
- "unplugin-atscript": "^0.1.96",
53
- "@atscript/db": "0.1.144"
50
+ "@atscript/core": "^0.1.97",
51
+ "@atscript/typescript": "^0.1.97",
52
+ "unplugin-atscript": "^0.1.97",
53
+ "@atscript/db": "0.1.145"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@atscript/db": "^0.1.44",
57
- "@atscript/typescript": "^0.1.96"
57
+ "@atscript/typescript": "^0.1.97"
58
58
  },
59
59
  "scripts": {
60
60
  "postinstall": "asc -f dts",