@atscript/db-client 0.1.134 → 0.1.136
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 +23 -17
- package/dist/index.d.cts +9 -2
- package/dist/index.d.mts +9 -2
- package/dist/index.mjs +23 -17
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -132,7 +132,7 @@ var Client = class {
|
|
|
132
132
|
_lenientWrites;
|
|
133
133
|
_metaPromise;
|
|
134
134
|
_validatorPromise;
|
|
135
|
-
/** Cached deserialized form schemas keyed by
|
|
135
|
+
/** Cached deserialized form schemas keyed by resolved URL. */
|
|
136
136
|
_formCache = /* @__PURE__ */ new Map();
|
|
137
137
|
constructor(path, opts) {
|
|
138
138
|
this._path = path.endsWith("/") ? path.slice(0, -1) : path;
|
|
@@ -333,20 +333,25 @@ var Client = class {
|
|
|
333
333
|
* returned annotated type to a form-renderer (e.g. `@atscript/ui` form
|
|
334
334
|
* components) and then submit the collected payload through
|
|
335
335
|
* {@link action}'s `input` argument.
|
|
336
|
+
*
|
|
337
|
+
* The schema comes from this controller's `meta/form/:name`, or — when the
|
|
338
|
+
* action carries `formUrl` — from `baseUrl + formUrl`.
|
|
339
|
+
* Cached per resolved URL.
|
|
336
340
|
*/
|
|
337
341
|
async getActionForm(actionName) {
|
|
338
342
|
const action = (await this.meta()).actions.find((a) => a.name === actionName);
|
|
339
343
|
if (!action?.inputForm) return null;
|
|
340
|
-
|
|
344
|
+
const url = action.formUrl ? `${this._baseUrl}${action.formUrl}` : this._endpointUrl(`meta/form/${encodeURIComponent(action.inputForm)}`);
|
|
345
|
+
return this._loadActionForm(url);
|
|
341
346
|
}
|
|
342
|
-
_loadActionForm(
|
|
343
|
-
let p = this._formCache.get(
|
|
347
|
+
_loadActionForm(url) {
|
|
348
|
+
let p = this._formCache.get(url);
|
|
344
349
|
if (!p) {
|
|
345
|
-
p = this.
|
|
346
|
-
this._formCache.delete(
|
|
350
|
+
p = this._requestUrl("GET", url).then((schema) => (0, _atscript_typescript_utils.deserializeAnnotatedType)(schema)).catch((err) => {
|
|
351
|
+
this._formCache.delete(url);
|
|
347
352
|
throw err;
|
|
348
353
|
});
|
|
349
|
-
this._formCache.set(
|
|
354
|
+
this._formCache.set(url, p);
|
|
350
355
|
}
|
|
351
356
|
return p;
|
|
352
357
|
}
|
|
@@ -408,10 +413,8 @@ var Client = class {
|
|
|
408
413
|
}
|
|
409
414
|
throw new ActionUnsupportedError(action.name, "navigate", `Action "${action.name}" is processor: 'navigate' but no browser is available and no \`navigate\` option was provided to Client.`);
|
|
410
415
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
const init = await this._buildInit("POST", body);
|
|
414
|
-
return this._send(url, init, true);
|
|
416
|
+
_postAction(action, body) {
|
|
417
|
+
return this._requestUrl("POST", `${this._baseUrl}${action.value}`, body, true);
|
|
415
418
|
}
|
|
416
419
|
_idToParams(id) {
|
|
417
420
|
const params = new URLSearchParams();
|
|
@@ -435,13 +438,16 @@ var Client = class {
|
|
|
435
438
|
if (typeof this._headers === "function") return await this._headers();
|
|
436
439
|
return this._headers;
|
|
437
440
|
}
|
|
438
|
-
|
|
441
|
+
_request(method, endpoint, body) {
|
|
442
|
+
return this._requestUrl(method, this._endpointUrl(endpoint), body);
|
|
443
|
+
}
|
|
444
|
+
/** `baseUrl + path` joined with an endpoint relative to this controller (`""`, `meta`, `?q`…). */
|
|
445
|
+
_endpointUrl(endpoint) {
|
|
439
446
|
const sep = endpoint && !endpoint.startsWith("?") ? "/" : "";
|
|
440
|
-
|
|
441
|
-
const init = await this._buildInit(method, body);
|
|
442
|
-
return this._send(url, init, false);
|
|
447
|
+
return `${this._baseUrl}${this._path}${sep}${endpoint}`;
|
|
443
448
|
}
|
|
444
|
-
|
|
449
|
+
/** Sends one request to an absolute URL with the client's headers and a JSON body. */
|
|
450
|
+
async _requestUrl(method, url, body, allowEmpty = false) {
|
|
445
451
|
const headers = { ...await this._resolveHeaders() };
|
|
446
452
|
const init = {
|
|
447
453
|
method,
|
|
@@ -451,7 +457,7 @@ var Client = class {
|
|
|
451
457
|
headers["Content-Type"] = "application/json";
|
|
452
458
|
init.body = JSON.stringify(body);
|
|
453
459
|
}
|
|
454
|
-
return init;
|
|
460
|
+
return this._send(url, init, allowEmpty);
|
|
455
461
|
}
|
|
456
462
|
async _send(url, init, allowEmpty) {
|
|
457
463
|
const method = init.method ?? "GET";
|
package/dist/index.d.cts
CHANGED
|
@@ -38,7 +38,7 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape> {
|
|
|
38
38
|
private readonly _lenientWrites?;
|
|
39
39
|
private _metaPromise?;
|
|
40
40
|
private _validatorPromise?;
|
|
41
|
-
/** Cached deserialized form schemas keyed by
|
|
41
|
+
/** Cached deserialized form schemas keyed by resolved URL. */
|
|
42
42
|
private _formCache;
|
|
43
43
|
constructor(path: string, opts?: ClientOptions);
|
|
44
44
|
/**
|
|
@@ -178,6 +178,10 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape> {
|
|
|
178
178
|
* returned annotated type to a form-renderer (e.g. `@atscript/ui` form
|
|
179
179
|
* components) and then submit the collected payload through
|
|
180
180
|
* {@link action}'s `input` argument.
|
|
181
|
+
*
|
|
182
|
+
* The schema comes from this controller's `meta/form/:name`, or — when the
|
|
183
|
+
* action carries `formUrl` — from `baseUrl + formUrl`.
|
|
184
|
+
* Cached per resolved URL.
|
|
181
185
|
*/
|
|
182
186
|
getActionForm(actionName: string): Promise<TAtscriptAnnotatedType | null>;
|
|
183
187
|
private _loadActionForm;
|
|
@@ -198,7 +202,10 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape> {
|
|
|
198
202
|
private _get;
|
|
199
203
|
private _resolveHeaders;
|
|
200
204
|
private _request;
|
|
201
|
-
|
|
205
|
+
/** `baseUrl + path` joined with an endpoint relative to this controller (`""`, `meta`, `?q`…). */
|
|
206
|
+
private _endpointUrl;
|
|
207
|
+
/** Sends one request to an absolute URL with the client's headers and a JSON body. */
|
|
208
|
+
private _requestUrl;
|
|
202
209
|
private _send;
|
|
203
210
|
}
|
|
204
211
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -38,7 +38,7 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape> {
|
|
|
38
38
|
private readonly _lenientWrites?;
|
|
39
39
|
private _metaPromise?;
|
|
40
40
|
private _validatorPromise?;
|
|
41
|
-
/** Cached deserialized form schemas keyed by
|
|
41
|
+
/** Cached deserialized form schemas keyed by resolved URL. */
|
|
42
42
|
private _formCache;
|
|
43
43
|
constructor(path: string, opts?: ClientOptions);
|
|
44
44
|
/**
|
|
@@ -178,6 +178,10 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape> {
|
|
|
178
178
|
* returned annotated type to a form-renderer (e.g. `@atscript/ui` form
|
|
179
179
|
* components) and then submit the collected payload through
|
|
180
180
|
* {@link action}'s `input` argument.
|
|
181
|
+
*
|
|
182
|
+
* The schema comes from this controller's `meta/form/:name`, or — when the
|
|
183
|
+
* action carries `formUrl` — from `baseUrl + formUrl`.
|
|
184
|
+
* Cached per resolved URL.
|
|
181
185
|
*/
|
|
182
186
|
getActionForm(actionName: string): Promise<TAtscriptAnnotatedType | null>;
|
|
183
187
|
private _loadActionForm;
|
|
@@ -198,7 +202,10 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape> {
|
|
|
198
202
|
private _get;
|
|
199
203
|
private _resolveHeaders;
|
|
200
204
|
private _request;
|
|
201
|
-
|
|
205
|
+
/** `baseUrl + path` joined with an endpoint relative to this controller (`""`, `meta`, `?q`…). */
|
|
206
|
+
private _endpointUrl;
|
|
207
|
+
/** Sends one request to an absolute URL with the client's headers and a JSON body. */
|
|
208
|
+
private _requestUrl;
|
|
202
209
|
private _send;
|
|
203
210
|
}
|
|
204
211
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -131,7 +131,7 @@ var Client = class {
|
|
|
131
131
|
_lenientWrites;
|
|
132
132
|
_metaPromise;
|
|
133
133
|
_validatorPromise;
|
|
134
|
-
/** Cached deserialized form schemas keyed by
|
|
134
|
+
/** Cached deserialized form schemas keyed by resolved URL. */
|
|
135
135
|
_formCache = /* @__PURE__ */ new Map();
|
|
136
136
|
constructor(path, opts) {
|
|
137
137
|
this._path = path.endsWith("/") ? path.slice(0, -1) : path;
|
|
@@ -332,20 +332,25 @@ var Client = class {
|
|
|
332
332
|
* returned annotated type to a form-renderer (e.g. `@atscript/ui` form
|
|
333
333
|
* components) and then submit the collected payload through
|
|
334
334
|
* {@link action}'s `input` argument.
|
|
335
|
+
*
|
|
336
|
+
* The schema comes from this controller's `meta/form/:name`, or — when the
|
|
337
|
+
* action carries `formUrl` — from `baseUrl + formUrl`.
|
|
338
|
+
* Cached per resolved URL.
|
|
335
339
|
*/
|
|
336
340
|
async getActionForm(actionName) {
|
|
337
341
|
const action = (await this.meta()).actions.find((a) => a.name === actionName);
|
|
338
342
|
if (!action?.inputForm) return null;
|
|
339
|
-
|
|
343
|
+
const url = action.formUrl ? `${this._baseUrl}${action.formUrl}` : this._endpointUrl(`meta/form/${encodeURIComponent(action.inputForm)}`);
|
|
344
|
+
return this._loadActionForm(url);
|
|
340
345
|
}
|
|
341
|
-
_loadActionForm(
|
|
342
|
-
let p = this._formCache.get(
|
|
346
|
+
_loadActionForm(url) {
|
|
347
|
+
let p = this._formCache.get(url);
|
|
343
348
|
if (!p) {
|
|
344
|
-
p = this.
|
|
345
|
-
this._formCache.delete(
|
|
349
|
+
p = this._requestUrl("GET", url).then((schema) => deserializeAnnotatedType(schema)).catch((err) => {
|
|
350
|
+
this._formCache.delete(url);
|
|
346
351
|
throw err;
|
|
347
352
|
});
|
|
348
|
-
this._formCache.set(
|
|
353
|
+
this._formCache.set(url, p);
|
|
349
354
|
}
|
|
350
355
|
return p;
|
|
351
356
|
}
|
|
@@ -407,10 +412,8 @@ var Client = class {
|
|
|
407
412
|
}
|
|
408
413
|
throw new ActionUnsupportedError(action.name, "navigate", `Action "${action.name}" is processor: 'navigate' but no browser is available and no \`navigate\` option was provided to Client.`);
|
|
409
414
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
const init = await this._buildInit("POST", body);
|
|
413
|
-
return this._send(url, init, true);
|
|
415
|
+
_postAction(action, body) {
|
|
416
|
+
return this._requestUrl("POST", `${this._baseUrl}${action.value}`, body, true);
|
|
414
417
|
}
|
|
415
418
|
_idToParams(id) {
|
|
416
419
|
const params = new URLSearchParams();
|
|
@@ -434,13 +437,16 @@ var Client = class {
|
|
|
434
437
|
if (typeof this._headers === "function") return await this._headers();
|
|
435
438
|
return this._headers;
|
|
436
439
|
}
|
|
437
|
-
|
|
440
|
+
_request(method, endpoint, body) {
|
|
441
|
+
return this._requestUrl(method, this._endpointUrl(endpoint), body);
|
|
442
|
+
}
|
|
443
|
+
/** `baseUrl + path` joined with an endpoint relative to this controller (`""`, `meta`, `?q`…). */
|
|
444
|
+
_endpointUrl(endpoint) {
|
|
438
445
|
const sep = endpoint && !endpoint.startsWith("?") ? "/" : "";
|
|
439
|
-
|
|
440
|
-
const init = await this._buildInit(method, body);
|
|
441
|
-
return this._send(url, init, false);
|
|
446
|
+
return `${this._baseUrl}${this._path}${sep}${endpoint}`;
|
|
442
447
|
}
|
|
443
|
-
|
|
448
|
+
/** Sends one request to an absolute URL with the client's headers and a JSON body. */
|
|
449
|
+
async _requestUrl(method, url, body, allowEmpty = false) {
|
|
444
450
|
const headers = { ...await this._resolveHeaders() };
|
|
445
451
|
const init = {
|
|
446
452
|
method,
|
|
@@ -450,7 +456,7 @@ var Client = class {
|
|
|
450
456
|
headers["Content-Type"] = "application/json";
|
|
451
457
|
init.body = JSON.stringify(body);
|
|
452
458
|
}
|
|
453
|
-
return init;
|
|
459
|
+
return this._send(url, init, allowEmpty);
|
|
454
460
|
}
|
|
455
461
|
async _send(url, init, allowEmpty) {
|
|
456
462
|
const method = init.method ?? "GET";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.136",
|
|
4
4
|
"description": "Browser-compatible HTTP client for @atscript/moost-db REST endpoints.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@uniqu/core": "^0.1.
|
|
47
|
-
"@uniqu/url": "^0.1.
|
|
46
|
+
"@uniqu/core": "^0.1.11",
|
|
47
|
+
"@uniqu/url": "^0.1.11"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@atscript/core": "^0.1.92",
|
|
51
51
|
"@atscript/typescript": "^0.1.92",
|
|
52
52
|
"unplugin-atscript": "^0.1.92",
|
|
53
|
-
"@atscript/db": "0.1.
|
|
53
|
+
"@atscript/db": "0.1.136"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@atscript/db": "^0.1.44",
|