@atscript/db-client 0.1.150 → 0.1.152

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
@@ -324,13 +324,31 @@ var Client = class {
324
324
  * `GET /meta` — table/view metadata (cached after first call).
325
325
  */
326
326
  async meta() {
327
- if (!this._metaPromise) this._metaPromise = this._request("GET", "meta").catch((err) => {
328
- this._metaPromise = void 0;
329
- throw err;
330
- });
327
+ if (!this._metaPromise) {
328
+ const p = this._request("GET", "meta").catch((err) => {
329
+ if (this._metaPromise === p) this._metaPromise = void 0;
330
+ throw err;
331
+ });
332
+ this._metaPromise = p;
333
+ }
331
334
  return this._metaPromise;
332
335
  }
333
336
  /**
337
+ * Drops everything this client cached from the server's metadata — the
338
+ * `/meta` response, the validator built from it and the loaded action
339
+ * forms — so the next call fetches them again. Call it when the viewer's
340
+ * identity changes (login, logout, role change): `/meta` is projected per
341
+ * user, and a client reused across identities would otherwise keep serving
342
+ * the previous user's columns, actions and write rules.
343
+ *
344
+ * @since 0.1.151
345
+ */
346
+ invalidateMeta() {
347
+ this._metaPromise = void 0;
348
+ this._validatorPromise = void 0;
349
+ this._formCache.clear();
350
+ }
351
+ /**
334
352
  * Invoke a declared action by name. Resolves the action descriptor from the
335
353
  * cached `/meta` response, then dispatches based on `processor`:
336
354
  *
@@ -472,10 +490,11 @@ var Client = class {
472
490
  _loadActionForm(url) {
473
491
  let p = this._formCache.get(url);
474
492
  if (!p) {
475
- p = this._requestUrl("GET", url).then((schema) => (0, _atscript_typescript_utils.deserializeAnnotatedType)(schema)).catch((err) => {
476
- this._formCache.delete(url);
493
+ const loading = this._requestUrl("GET", url).then((schema) => (0, _atscript_typescript_utils.deserializeAnnotatedType)(schema)).catch((err) => {
494
+ if (this._formCache.get(url) === loading) this._formCache.delete(url);
477
495
  throw err;
478
496
  });
497
+ p = loading;
479
498
  this._formCache.set(url, p);
480
499
  }
481
500
  return p;
@@ -495,10 +514,13 @@ var Client = class {
495
514
  return normalized;
496
515
  }
497
516
  _getValidator() {
498
- if (!this._validatorPromise) this._validatorPromise = Promise.all([this.meta(), Promise.resolve().then(() => require("./validator.cjs"))]).then(([m, { createClientValidator }]) => createClientValidator(m, { lenientWrites: this._lenientWrites })).catch((err) => {
499
- this._validatorPromise = void 0;
500
- throw err;
501
- });
517
+ if (!this._validatorPromise) {
518
+ const p = Promise.all([this.meta(), Promise.resolve().then(() => require("./validator.cjs"))]).then(([m, { createClientValidator }]) => createClientValidator(m, { lenientWrites: this._lenientWrites })).catch((err) => {
519
+ if (this._validatorPromise === p) this._validatorPromise = void 0;
520
+ throw err;
521
+ });
522
+ this._validatorPromise = p;
523
+ }
502
524
  return this._validatorPromise;
503
525
  }
504
526
  _buildActionBody(action, id, input) {
package/dist/index.d.cts CHANGED
@@ -165,6 +165,17 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D exte
165
165
  * `GET /meta` — table/view metadata (cached after first call).
166
166
  */
167
167
  meta(): Promise<MetaResponse>;
168
+ /**
169
+ * Drops everything this client cached from the server's metadata — the
170
+ * `/meta` response, the validator built from it and the loaded action
171
+ * forms — so the next call fetches them again. Call it when the viewer's
172
+ * identity changes (login, logout, role change): `/meta` is projected per
173
+ * user, and a client reused across identities would otherwise keep serving
174
+ * the previous user's columns, actions and write rules.
175
+ *
176
+ * @since 0.1.151
177
+ */
178
+ invalidateMeta(): void;
168
179
  /**
169
180
  * Invoke a declared action by name. Resolves the action descriptor from the
170
181
  * cached `/meta` response, then dispatches based on `processor`:
package/dist/index.d.mts CHANGED
@@ -165,6 +165,17 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D exte
165
165
  * `GET /meta` — table/view metadata (cached after first call).
166
166
  */
167
167
  meta(): Promise<MetaResponse>;
168
+ /**
169
+ * Drops everything this client cached from the server's metadata — the
170
+ * `/meta` response, the validator built from it and the loaded action
171
+ * forms — so the next call fetches them again. Call it when the viewer's
172
+ * identity changes (login, logout, role change): `/meta` is projected per
173
+ * user, and a client reused across identities would otherwise keep serving
174
+ * the previous user's columns, actions and write rules.
175
+ *
176
+ * @since 0.1.151
177
+ */
178
+ invalidateMeta(): void;
168
179
  /**
169
180
  * Invoke a declared action by name. Resolves the action descriptor from the
170
181
  * cached `/meta` response, then dispatches based on `processor`:
package/dist/index.mjs CHANGED
@@ -323,13 +323,31 @@ var Client = class {
323
323
  * `GET /meta` — table/view metadata (cached after first call).
324
324
  */
325
325
  async meta() {
326
- if (!this._metaPromise) this._metaPromise = this._request("GET", "meta").catch((err) => {
327
- this._metaPromise = void 0;
328
- throw err;
329
- });
326
+ if (!this._metaPromise) {
327
+ const p = this._request("GET", "meta").catch((err) => {
328
+ if (this._metaPromise === p) this._metaPromise = void 0;
329
+ throw err;
330
+ });
331
+ this._metaPromise = p;
332
+ }
330
333
  return this._metaPromise;
331
334
  }
332
335
  /**
336
+ * Drops everything this client cached from the server's metadata — the
337
+ * `/meta` response, the validator built from it and the loaded action
338
+ * forms — so the next call fetches them again. Call it when the viewer's
339
+ * identity changes (login, logout, role change): `/meta` is projected per
340
+ * user, and a client reused across identities would otherwise keep serving
341
+ * the previous user's columns, actions and write rules.
342
+ *
343
+ * @since 0.1.151
344
+ */
345
+ invalidateMeta() {
346
+ this._metaPromise = void 0;
347
+ this._validatorPromise = void 0;
348
+ this._formCache.clear();
349
+ }
350
+ /**
333
351
  * Invoke a declared action by name. Resolves the action descriptor from the
334
352
  * cached `/meta` response, then dispatches based on `processor`:
335
353
  *
@@ -471,10 +489,11 @@ var Client = class {
471
489
  _loadActionForm(url) {
472
490
  let p = this._formCache.get(url);
473
491
  if (!p) {
474
- p = this._requestUrl("GET", url).then((schema) => deserializeAnnotatedType(schema)).catch((err) => {
475
- this._formCache.delete(url);
492
+ const loading = this._requestUrl("GET", url).then((schema) => deserializeAnnotatedType(schema)).catch((err) => {
493
+ if (this._formCache.get(url) === loading) this._formCache.delete(url);
476
494
  throw err;
477
495
  });
496
+ p = loading;
478
497
  this._formCache.set(url, p);
479
498
  }
480
499
  return p;
@@ -494,10 +513,13 @@ var Client = class {
494
513
  return normalized;
495
514
  }
496
515
  _getValidator() {
497
- if (!this._validatorPromise) this._validatorPromise = Promise.all([this.meta(), import("./validator.mjs")]).then(([m, { createClientValidator }]) => createClientValidator(m, { lenientWrites: this._lenientWrites })).catch((err) => {
498
- this._validatorPromise = void 0;
499
- throw err;
500
- });
516
+ if (!this._validatorPromise) {
517
+ const p = Promise.all([this.meta(), import("./validator.mjs")]).then(([m, { createClientValidator }]) => createClientValidator(m, { lenientWrites: this._lenientWrites })).catch((err) => {
518
+ if (this._validatorPromise === p) this._validatorPromise = void 0;
519
+ throw err;
520
+ });
521
+ this._validatorPromise = p;
522
+ }
501
523
  return this._validatorPromise;
502
524
  }
503
525
  _buildActionBody(action, id, input) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/db-client",
3
- "version": "0.1.150",
3
+ "version": "0.1.152",
4
4
  "description": "Browser-compatible HTTP client for @atscript/moost-db REST endpoints.",
5
5
  "keywords": [
6
6
  "atscript",
@@ -43,18 +43,18 @@
43
43
  "access": "public"
44
44
  },
45
45
  "dependencies": {
46
- "@uniqu/core": "^0.1.13",
47
- "@uniqu/url": "^0.1.13"
46
+ "@uniqu/core": "^0.1.14",
47
+ "@uniqu/url": "^0.1.14"
48
48
  },
49
49
  "devDependencies": {
50
- "@atscript/core": "^0.1.101",
51
- "@atscript/typescript": "^0.1.101",
52
- "unplugin-atscript": "^0.1.101",
53
- "@atscript/db": "0.1.150"
50
+ "@atscript/core": "^0.1.102",
51
+ "@atscript/typescript": "^0.1.102",
52
+ "unplugin-atscript": "^0.1.102",
53
+ "@atscript/db": "0.1.152"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@atscript/db": "^0.1.44",
57
- "@atscript/typescript": "^0.1.101"
57
+ "@atscript/typescript": "^0.1.102"
58
58
  },
59
59
  "scripts": {
60
60
  "postinstall": "asc -f dts",