@voltro/api-client 0.86.0 → 0.87.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/CHANGELOG.md +5321 -0
- package/dist/apiRoleEndpoints.js +108 -0
- package/dist/client.js +32 -18
- package/dist/index.d.ts +37 -1
- package/dist/index.js +4 -3
- package/package.json +1 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
//#region src/apiRoleEndpoints.ts
|
|
2
|
+
var e = (e, t) => {
|
|
3
|
+
if (!e || typeof e != "object" || Array.isArray(e) || ![Object.prototype, null].includes(Object.getPrototypeOf(e))) throw Error("Invalid role endpoint object");
|
|
4
|
+
let n = Object.create(null);
|
|
5
|
+
for (let r of Reflect.ownKeys(e)) {
|
|
6
|
+
let i = Object.getOwnPropertyDescriptor(e, r);
|
|
7
|
+
if (typeof r != "string" || !t.includes(r) || !i.enumerable || !("value" in i)) throw Error("Invalid role endpoint field");
|
|
8
|
+
n[r] = i.value;
|
|
9
|
+
}
|
|
10
|
+
return n;
|
|
11
|
+
}, t = (e, t, n = !1) => {
|
|
12
|
+
if (!Array.isArray(e) || e.length < +!n || e.length > t || Reflect.ownKeys(e).length !== e.length + 1) throw Error("Invalid role endpoint list");
|
|
13
|
+
let r = [];
|
|
14
|
+
for (let t = 0; t < e.length; t++) {
|
|
15
|
+
let n = Object.getOwnPropertyDescriptor(e, String(t));
|
|
16
|
+
if (!n?.enumerable || !("value" in n)) throw Error("Invalid role endpoint list item");
|
|
17
|
+
r.push(n.value);
|
|
18
|
+
}
|
|
19
|
+
return r;
|
|
20
|
+
}, n = /^(?:[A-Za-z][A-Za-z0-9_-]*\.)*[A-Za-z][A-Za-z0-9_-]*$/, r = /^(?:[A-Za-z_][A-Za-z0-9_-]*\.)*[A-Za-z_][A-Za-z0-9_-]*$/, i = [
|
|
21
|
+
"rpc",
|
|
22
|
+
"subscriptions",
|
|
23
|
+
"events",
|
|
24
|
+
"presence",
|
|
25
|
+
"workflows",
|
|
26
|
+
"schedules",
|
|
27
|
+
"directors",
|
|
28
|
+
"drainers",
|
|
29
|
+
"reapers",
|
|
30
|
+
"retention",
|
|
31
|
+
"rest",
|
|
32
|
+
"webhooks",
|
|
33
|
+
"inspect",
|
|
34
|
+
"cdc"
|
|
35
|
+
], a = (r) => {
|
|
36
|
+
let a = e(r, [
|
|
37
|
+
"version",
|
|
38
|
+
"transport",
|
|
39
|
+
"roles"
|
|
40
|
+
]);
|
|
41
|
+
if (a.version !== 1 || a.transport !== "compose-nginx" && a.transport !== "kubernetes-nginx") throw Error("Unknown role endpoint protocol");
|
|
42
|
+
let o = /* @__PURE__ */ new Set(), s = t(a.roles, 32, !0).map((r) => {
|
|
43
|
+
let a = e(r, [
|
|
44
|
+
"role",
|
|
45
|
+
"routes",
|
|
46
|
+
"workloads",
|
|
47
|
+
"httpPath",
|
|
48
|
+
"webSocketPath"
|
|
49
|
+
]), s = a.role;
|
|
50
|
+
if (typeof s != "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(s) || o.has(s)) throw Error("Invalid or duplicate endpoint role");
|
|
51
|
+
o.add(s);
|
|
52
|
+
let c = t(a.workloads, 14).map((e) => {
|
|
53
|
+
if (typeof e != "string" || !i.includes(e)) throw Error("Unknown endpoint workload");
|
|
54
|
+
return e;
|
|
55
|
+
});
|
|
56
|
+
if (new Set(c).size !== c.length) throw Error("Duplicate endpoint workload");
|
|
57
|
+
let l = a.routes === null ? null : t(a.routes, 128).map((e) => {
|
|
58
|
+
if (typeof e != "string" || e.length > 191 || !n.test(e.endsWith(".*") ? e.slice(0, -2) : e)) throw Error("Invalid endpoint tag filter");
|
|
59
|
+
return e;
|
|
60
|
+
});
|
|
61
|
+
if (l && new Set(l).size !== l.length) throw Error("Duplicate endpoint tag filter");
|
|
62
|
+
let u = "/_voltro/roles/" + s;
|
|
63
|
+
if (a.webSocketPath !== u + "/ws" || a.httpPath !== (c.includes("rpc") ? u + "/rpc" : null)) throw Error("Role endpoints must use canonical same-origin paths");
|
|
64
|
+
return Object.freeze({
|
|
65
|
+
role: s,
|
|
66
|
+
routes: l && Object.freeze(l),
|
|
67
|
+
workloads: Object.freeze(c),
|
|
68
|
+
httpPath: a.httpPath,
|
|
69
|
+
webSocketPath: a.webSocketPath
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
return Object.freeze({
|
|
73
|
+
version: 1,
|
|
74
|
+
transport: a.transport,
|
|
75
|
+
roles: Object.freeze(s)
|
|
76
|
+
});
|
|
77
|
+
}, o = (e, t, n) => {
|
|
78
|
+
if (t.length > 191 || !r.test(t) || ![
|
|
79
|
+
"rpc",
|
|
80
|
+
"subscriptions",
|
|
81
|
+
"events"
|
|
82
|
+
].includes(n)) throw Error("Invalid role endpoint request");
|
|
83
|
+
let i, a = -1, o = !1;
|
|
84
|
+
for (let r of e.roles) {
|
|
85
|
+
if (!r.workloads.includes(n)) continue;
|
|
86
|
+
let e = r.routes === null ? 0 : Math.max(-1, ...r.routes.map((e) => e.endsWith(".*") ? t.startsWith(e.slice(0, -1)) ? e.length : -1 : e === t ? 1024 + e.length : -1));
|
|
87
|
+
e > a ? (i = r, a = e, o = !1) : e >= 0 && e === a && (o = !0);
|
|
88
|
+
}
|
|
89
|
+
if (!i || o) throw Error(o ? "Ambiguous role endpoint" : "No role endpoint owns this tag and workload");
|
|
90
|
+
return i;
|
|
91
|
+
}, s = (e) => {
|
|
92
|
+
if (!/^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/.test(e)) throw Error("Invalid role proxy API name");
|
|
93
|
+
return `/_voltro/role-api/api-${e}/ws`;
|
|
94
|
+
}, c = (e, t, n) => {
|
|
95
|
+
if (!/^[a-z][a-z0-9-]{0,63}$/.test(t.role) || !["http", "websocket"].includes(n)) throw Error("Invalid role transport");
|
|
96
|
+
let r = new URL(e);
|
|
97
|
+
if (![
|
|
98
|
+
"http:",
|
|
99
|
+
"https:",
|
|
100
|
+
"ws:",
|
|
101
|
+
"wss:"
|
|
102
|
+
].includes(r.protocol) || r.username || r.password) throw Error("Invalid role endpoint origin");
|
|
103
|
+
let i = n === "http" ? t.httpPath : t.webSocketPath;
|
|
104
|
+
if (!i || i !== "/_voltro/roles/" + t.role + (n === "http" ? "/rpc" : "/ws")) throw Error("Missing or noncanonical role transport");
|
|
105
|
+
return r.protocol = n === "http" ? r.protocol === "https:" || r.protocol === "wss:" ? "https:" : "http:" : r.protocol === "https:" || r.protocol === "wss:" ? "wss:" : "ws:", r.pathname = (/^\/_voltro\/role-api\/api-[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}\/ws$/.test(r.pathname) ? r.pathname.slice(0, -3) : "") + i, r.search = "", r.hash = "", r.toString();
|
|
106
|
+
};
|
|
107
|
+
//#endregion
|
|
108
|
+
export { c as apiRoleEndpointUrl, s as apiRoleProxyBasePath, a as captureApiRoleEndpoints, o as selectApiRoleEndpoint };
|
package/dist/client.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { splitTag as e } from "./manifest.js";
|
|
2
2
|
import { makeRestCore as t } from "./rest.js";
|
|
3
3
|
import { openLiveQueries as n } from "./live.js";
|
|
4
|
+
import { apiRoleEndpointUrl as r, captureApiRoleEndpoints as i, selectApiRoleEndpoint as a } from "./apiRoleEndpoints.js";
|
|
4
5
|
//#region src/client.ts
|
|
5
|
-
var
|
|
6
|
+
var o = (t) => {
|
|
6
7
|
let n = {};
|
|
7
8
|
for (let r of t.manifest.projections) {
|
|
8
9
|
let i = Object.assign((e, n) => t.call(r.tag, e, n), {
|
|
@@ -18,7 +19,7 @@ var r = (t) => {
|
|
|
18
19
|
s[o] = i, n[a] = s;
|
|
19
20
|
}
|
|
20
21
|
return n;
|
|
21
|
-
},
|
|
22
|
+
}, s = (e, t, n, r) => ({ async *[Symbol.asyncIterator]() {
|
|
22
23
|
let i;
|
|
23
24
|
for (;;) {
|
|
24
25
|
let a = await e(i === void 0 ? n : {
|
|
@@ -28,27 +29,40 @@ var r = (t) => {
|
|
|
28
29
|
if (yield a.value, a.nextCursor === void 0) return;
|
|
29
30
|
i = a.nextCursor;
|
|
30
31
|
}
|
|
31
|
-
} }),
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
} }), c = (e, o = {}) => {
|
|
33
|
+
let c = t(e.manifest, e.errors, o), l = e.manifest.profile.cursorParam, u = o.roleEndpoints === void 0 ? void 0 : i(o.roleEndpoints);
|
|
34
|
+
if (u && o.subscriptions?.wsUrl !== void 0) throw Error("Role endpoints and a fixed subscription URL are mutually exclusive");
|
|
35
|
+
let d = /* @__PURE__ */ new Map(), f = !1, p = (t) => {
|
|
36
|
+
if (f) throw Error("API client is closed");
|
|
37
|
+
let i = u && a(u, t, "subscriptions"), s = i?.role ?? "default", l = d.get(s);
|
|
38
|
+
return l || (l = n(e.manifest, e.errors, c.baseUrl, {
|
|
39
|
+
token: o.token,
|
|
40
|
+
tenant: o.tenant,
|
|
41
|
+
headers: o.headers,
|
|
42
|
+
...o.subscriptions ?? {},
|
|
43
|
+
...i ? { wsUrl: r(c.baseUrl, i, "websocket") } : {}
|
|
44
|
+
}), d.set(s, l)), l;
|
|
45
|
+
};
|
|
38
46
|
return {
|
|
39
47
|
manifest: e.manifest,
|
|
40
48
|
errors: e.errors,
|
|
41
|
-
call: async (e, t = {}, n) => (await
|
|
42
|
-
callRaw: (e, t = {}, n) =>
|
|
43
|
-
pages: (e, t = {}, n) =>
|
|
44
|
-
subscribe: (e, t = {}) =>
|
|
49
|
+
call: async (e, t = {}, n) => (await c.call(e, t, n)).value,
|
|
50
|
+
callRaw: (e, t = {}, n) => c.call(e, t, n),
|
|
51
|
+
pages: (e, t = {}, n) => s((t, n) => c.call(e, t, n), l, t, n),
|
|
52
|
+
subscribe: (e, t = {}) => {
|
|
53
|
+
let n = p(e);
|
|
54
|
+
return { [Symbol.asyncIterator]: () => {
|
|
55
|
+
if (f) throw Error("API client is closed");
|
|
56
|
+
return n.subscribe(e, t)[Symbol.asyncIterator]();
|
|
57
|
+
} };
|
|
58
|
+
},
|
|
45
59
|
close: async () => {
|
|
46
|
-
await
|
|
60
|
+
f = !0, await Promise.all([...d.values()].map((e) => e.close())), d.clear();
|
|
47
61
|
}
|
|
48
62
|
};
|
|
49
|
-
},
|
|
50
|
-
let n =
|
|
51
|
-
return Object.assign(
|
|
63
|
+
}, l = (e, t = {}) => {
|
|
64
|
+
let n = c(e, t);
|
|
65
|
+
return Object.assign(o(n), n);
|
|
52
66
|
};
|
|
53
67
|
//#endregion
|
|
54
|
-
export {
|
|
68
|
+
export { o as buildNamespaces, l as createClient, c as createPromiseClient, s as pagesOf };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export declare interface ApiClientConfig extends RestClientConfig {
|
|
|
8
8
|
/** The socket the live queries ride — derived from `baseUrl` by default,
|
|
9
9
|
* opened on the first `subscribe`. */
|
|
10
10
|
readonly subscriptions?: LiveQueriesConfig | undefined;
|
|
11
|
+
/** Captured role-endpoints.json; live subscriptions use a separate socket per role. */
|
|
12
|
+
readonly roleEndpoints?: unknown;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
/** The base of every error the client raises: a `_tag`, the HTTP `status`
|
|
@@ -44,6 +46,27 @@ export declare class ApiHttpError extends ApiClientError {
|
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
export declare interface ApiRoleEndpoint {
|
|
50
|
+
readonly role: string;
|
|
51
|
+
readonly routes: ReadonlyArray<string> | null;
|
|
52
|
+
readonly workloads: ReadonlyArray<string>;
|
|
53
|
+
readonly httpPath: string | null;
|
|
54
|
+
readonly webSocketPath: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export declare interface ApiRoleEndpoints {
|
|
58
|
+
readonly version: 1;
|
|
59
|
+
readonly transport: 'compose-nginx' | 'kubernetes-nginx';
|
|
60
|
+
readonly roles: ReadonlyArray<ApiRoleEndpoint>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export declare const apiRoleEndpointUrl: (baseUrl: string, endpoint: ApiRoleEndpoint, transport: "http" | "websocket") => string;
|
|
64
|
+
|
|
65
|
+
/** Reserved web proxy base; the API name isolates identical role names. */
|
|
66
|
+
export declare const apiRoleProxyBasePath: (apiName: string) => string;
|
|
67
|
+
|
|
68
|
+
export declare type ApiRoleRpcWorkload = 'rpc' | 'subscriptions' | 'events';
|
|
69
|
+
|
|
47
70
|
/**
|
|
48
71
|
* Apply a patch to `prev`: `add`/`replace` set the id's row, `mergeCells`
|
|
49
72
|
* folds columns into it, and null order preserves the previous ID sequence.
|
|
@@ -79,6 +102,8 @@ export declare interface CallResult<A = unknown> {
|
|
|
79
102
|
readonly fromCache: boolean;
|
|
80
103
|
}
|
|
81
104
|
|
|
105
|
+
export declare const captureApiRoleEndpoints: (value: unknown) => ApiRoleEndpoints;
|
|
106
|
+
|
|
82
107
|
export declare interface ClientManifest {
|
|
83
108
|
/** The generated package's name and version — the `User-Agent` line. */
|
|
84
109
|
readonly name?: string;
|
|
@@ -135,6 +160,9 @@ export declare interface ClientProjection {
|
|
|
135
160
|
/** The typed errors the projection answers with, by tag, and the status
|
|
136
161
|
* each is answered with. */
|
|
137
162
|
readonly errorStatus?: Readonly<Record<string, number>>;
|
|
163
|
+
/** Other documented statuses for the same typed error; the primary mapping
|
|
164
|
+
* above remains stable. Response decoding uses the actual HTTP response. */
|
|
165
|
+
readonly additionalErrorStatuses?: Readonly<Record<string, ReadonlyArray<number>>>;
|
|
138
166
|
/** Whether the output carries the profile's cursor field — the route can
|
|
139
167
|
* answer with a next page. */
|
|
140
168
|
readonly paginates: boolean;
|
|
@@ -436,6 +464,10 @@ export declare type RowPatchOp = {
|
|
|
436
464
|
/** The codec options of the rpc socket: the schema's own date forms, no renaming. */
|
|
437
465
|
export declare const rpcCodec: (models: Readonly<Record<string, WireType>>) => WireCodecOptions;
|
|
438
466
|
|
|
467
|
+
/** Exact tags outrank namespace filters; deeper namespaces outrank broader ones.
|
|
468
|
+
* Equal specificity is an ambiguity, never an implicit failover/credential hop. */
|
|
469
|
+
export declare const selectApiRoleEndpoint: (endpoints: ApiRoleEndpoints, tag: string, workload: ApiRoleRpcWorkload) => ApiRoleEndpoint;
|
|
470
|
+
|
|
439
471
|
/** `teams.getById` → `{ namespace: 'teams', method: 'getById' }`; a tag
|
|
440
472
|
* without a dot lives at the root. The tag prefix is the namespace, like the
|
|
441
473
|
* OpenAPI tag group. */
|
|
@@ -514,8 +546,12 @@ export declare interface WireProcedure {
|
|
|
514
546
|
readonly errors?: Readonly<Record<string, WireType>> | undefined;
|
|
515
547
|
}
|
|
516
548
|
|
|
517
|
-
export declare type WireType =
|
|
549
|
+
export declare type WireType =
|
|
550
|
+
/** Native source may retain the actual byte transformation's encoded form.
|
|
551
|
+
* Ordinary TypeScript wire generation and string values are unchanged. */
|
|
552
|
+
{
|
|
518
553
|
readonly kind: 'string';
|
|
554
|
+
readonly byteEncoding?: 'base64';
|
|
519
555
|
} | {
|
|
520
556
|
readonly kind: 'number';
|
|
521
557
|
} | {
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { ApiClientError as s, ApiHttpError as c, DeclaredError as l, InputEncode
|
|
|
4
4
|
import { cursorFromLink as h, declaredErrorOf as g, makeRestCore as _, uuidV7 as v } from "./rest.js";
|
|
5
5
|
import { applyRowPatch as y, pathToId as b } from "./rowPatch.js";
|
|
6
6
|
import { openLiveQueries as x, wsUrlFromBase as S } from "./live.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
7
|
+
import { apiRoleEndpointUrl as C, apiRoleProxyBasePath as w, captureApiRoleEndpoints as T, selectApiRoleEndpoint as E } from "./apiRoleEndpoints.js";
|
|
8
|
+
import { buildNamespaces as D, createClient as O, createPromiseClient as k, pagesOf as A } from "./client.js";
|
|
9
|
+
import { createMockClient as j } from "./mock.js";
|
|
10
|
+
export { s as ApiClientError, c as ApiHttpError, l as DeclaredError, u as InputEncodeError, d as ProfileMismatchError, f as RateLimitedError, p as TransportError, C as apiRoleEndpointUrl, w as apiRoleProxyBasePath, y as applyRowPatch, D as buildNamespaces, T as captureApiRoleEndpoints, O as createClient, j as createMockClient, k as createPromiseClient, h as cursorFromLink, g as declaredErrorOf, n as decodeWire, m as defineError, r as encodeWire, i as hasRequiredField, _ as makeRestCore, x as openLiveQueries, A as pagesOf, b as pathToId, e as projectionOf, a as rpcCodec, E as selectApiRoleEndpoint, t as splitTag, o as toSnakeCase, v as uuidV7, S as wsUrlFromBase };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/api-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.87.0",
|
|
4
4
|
"description": "The runtime of a generated TypeScript client for a Voltro public API (`voltro build api --target typescript`): the REST surface spoken profile-aware — typed errors as plain classes, dates, envelopes, pagination, a 429 as a wait, idempotency keys — with no dependencies, not on a schema library and not on Effect. Runs in Node, Bun, Deno and the browser. The Effect flavor is `@voltro/api-client-effect`.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|