@converge.ai/a13n 0.5.0 → 0.8.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/README.md +27 -144
- package/dist/client.d.ts +32 -14
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +92 -16
- package/dist/client.js.map +1 -1
- package/dist/conversations.d.ts +134 -0
- package/dist/conversations.d.ts.map +1 -0
- package/dist/conversations.js +421 -0
- package/dist/conversations.js.map +1 -0
- package/dist/errors.d.ts +57 -44
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +97 -63
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +25 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +42 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +72 -0
- package/dist/models.js.map +1 -0
- package/dist/public-models.d.ts +673 -0
- package/dist/public-models.d.ts.map +1 -0
- package/dist/public-models.js +2 -0
- package/dist/public-models.js.map +1 -0
- package/dist/realtime/browser.d.ts +16 -0
- package/dist/realtime/browser.d.ts.map +1 -0
- package/dist/realtime/browser.js +97 -0
- package/dist/realtime/browser.js.map +1 -0
- package/dist/realtime/core.d.ts +103 -0
- package/dist/realtime/core.d.ts.map +1 -0
- package/dist/realtime/core.js +240 -0
- package/dist/realtime/core.js.map +1 -0
- package/dist/resources/base.d.ts +43 -36
- package/dist/resources/base.d.ts.map +1 -1
- package/dist/resources/base.js +222 -200
- package/dist/resources/base.js.map +1 -1
- package/dist/resources/generated.d.ts +3909 -7345
- package/dist/resources/generated.d.ts.map +1 -1
- package/dist/resources/generated.js +6478 -5842
- package/dist/resources/generated.js.map +1 -1
- package/dist/resources/interaction.js +2 -2
- package/dist/resources/interaction.js.map +1 -1
- package/dist/schema.d.ts +4180 -2696
- package/dist/schema.d.ts.map +1 -1
- package/dist/session-stream-schema.d.ts +214 -3
- package/dist/session-stream-schema.d.ts.map +1 -1
- package/dist/session-stream-schema.js +10 -1
- package/dist/session-stream-schema.js.map +1 -1
- package/dist/streams/ag-ui.d.ts +114 -0
- package/dist/streams/ag-ui.d.ts.map +1 -0
- package/dist/streams/ag-ui.js +115 -0
- package/dist/streams/ag-ui.js.map +1 -0
- package/dist/streams/session-stream.d.ts +18 -7
- package/dist/streams/session-stream.d.ts.map +1 -1
- package/dist/streams/session-stream.js +95 -19
- package/dist/streams/session-stream.js.map +1 -1
- package/dist/streams/sse.d.ts +2 -2
- package/dist/streams/sse.d.ts.map +1 -1
- package/dist/streams/sse.js +5 -5
- package/dist/streams/sse.js.map +1 -1
- package/dist/streams/thread-stream.d.ts +3 -2
- package/dist/streams/thread-stream.d.ts.map +1 -1
- package/dist/streams/thread-stream.js +12 -12
- package/dist/streams/thread-stream.js.map +1 -1
- package/dist/transport.d.ts +34 -25
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +176 -128
- package/dist/transport.js.map +1 -1
- package/dist/webhooks.d.ts +59 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +79 -0
- package/dist/webhooks.js.map +1 -0
- package/dist/workflow.d.ts +35 -35
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +5 -1
- package/dist/workflow.js.map +1 -1
- package/openapi.json +9461 -2019
- package/package.json +9 -8
- package/THIRD_PARTY_NOTICES.txt +0 -83
- package/dist/dispatch.d.ts +0 -6
- package/dist/dispatch.d.ts.map +0 -1
- package/dist/dispatch.js +0 -19
- package/dist/dispatch.js.map +0 -1
- package/dist/semantic.d.ts +0 -262
- package/dist/semantic.d.ts.map +0 -1
- package/dist/semantic.js +0 -624
- package/dist/semantic.js.map +0 -1
- package/dist/session-stream-validation.d.ts +0 -129
- package/dist/session-stream-validation.d.ts.map +0 -1
- package/dist/session-stream-validation.js +0 -36240
- package/dist/session-stream-validation.js.map +0 -1
- package/dist/workspace-scope.d.ts +0 -2
- package/dist/workspace-scope.d.ts.map +0 -1
- package/dist/workspace-scope.js +0 -354
- package/dist/workspace-scope.js.map +0 -1
package/dist/resources/base.d.ts
CHANGED
|
@@ -1,47 +1,54 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
1
|
+
import { type Projection } from "../models.js";
|
|
2
|
+
import { type Transport } from "../transport.js";
|
|
3
|
+
import { type ServiceResources } from "./generated.js";
|
|
4
|
+
export interface RawResponse<T> {
|
|
3
5
|
readonly data: T;
|
|
6
|
+
readonly status: number;
|
|
7
|
+
readonly headers: Headers;
|
|
8
|
+
readonly requestId: string | null;
|
|
4
9
|
readonly response: Response;
|
|
5
10
|
}
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
export type Decoded<A extends boolean, T> = Promise<A extends true ? RawResponse<T> : T>;
|
|
12
|
+
export interface RequestOptions {
|
|
13
|
+
headers: Headers;
|
|
8
14
|
signal?: AbortSignal | undefined;
|
|
15
|
+
body?: BodyInit | undefined;
|
|
9
16
|
}
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
readonly
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export declare function binaryRequest(transport: Transport, path: string, options?: JsonRequestOptions & {
|
|
22
|
-
headers?: HeadersInit | undefined;
|
|
17
|
+
export interface OperationSpec {
|
|
18
|
+
id: string;
|
|
19
|
+
path: string;
|
|
20
|
+
method: string;
|
|
21
|
+
statuses: readonly number[];
|
|
22
|
+
workspace: boolean;
|
|
23
|
+
retry: "safe_read" | "safe_repeat_post" | "idempotent_keyed_post" | "none";
|
|
24
|
+
query?: readonly string[];
|
|
25
|
+
headers?: readonly string[];
|
|
26
|
+
media?: "application/json" | "multipart/form-data" | "application/x-www-form-urlencoded" | "binary";
|
|
27
|
+
binary?: boolean;
|
|
23
28
|
accept?: string;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
readonly next_cursor?: string | null;
|
|
29
|
+
model?: Projection;
|
|
30
|
+
page?: "cursor" | "hybrid";
|
|
31
|
+
submitted?: boolean;
|
|
28
32
|
}
|
|
29
|
-
|
|
33
|
+
/** One eagerly requested page; iterate items and follow continuation until the cursor is absent. */
|
|
34
|
+
export declare class PagePromise<P extends {
|
|
35
|
+
items: readonly unknown[];
|
|
36
|
+
next_cursor?: string | null | undefined;
|
|
37
|
+
}> implements PromiseLike<P>, AsyncIterable<P["items"][number]> {
|
|
38
|
+
private readonly initial;
|
|
30
39
|
private readonly fetchPage;
|
|
31
|
-
private readonly
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
private readonly first;
|
|
41
|
+
constructor(initial: string | null | undefined, fetchPage: (cursor: string | null | undefined) => Promise<P>);
|
|
42
|
+
then<TResult1 = P, TResult2 = never>(onfulfilled?: ((value: P) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
43
|
+
[Symbol.asyncIterator](): AsyncGenerator<P["items"][number]>;
|
|
44
|
+
}
|
|
45
|
+
/** A response body with explicit ownership, available for binary reads and raw protocol streams. */
|
|
46
|
+
export interface BinaryBody {
|
|
47
|
+
readonly body: ReadableStream<Uint8Array>;
|
|
48
|
+
readonly response: Response;
|
|
49
|
+
close(): Promise<void>;
|
|
40
50
|
}
|
|
41
|
-
|
|
42
|
-
export declare function
|
|
43
|
-
export declare function withCursor<T extends Record<string, unknown>>(filters: T, cursor: string | null | undefined): T & {
|
|
44
|
-
cursor?: string | null;
|
|
45
|
-
};
|
|
51
|
+
type Extras = (path: string, selectors: Readonly<Record<string, string>>) => Record<string, unknown> | undefined;
|
|
52
|
+
export declare function createResources<A extends boolean>(transport: Transport, workspace: string | undefined, raw: A, extras?: Extras, entry?: (receipt: unknown, key: string | null) => unknown): ServiceResources<A>;
|
|
46
53
|
export {};
|
|
47
54
|
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/resources/base.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/resources/base.ts"],"names":[],"mappings":"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"}
|
package/dist/resources/base.js
CHANGED
|
@@ -1,223 +1,245 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { UnexpectedResponseError, UnknownOutcomeError } from "../errors.js";
|
|
2
|
+
import { projectModels } from "../models.js";
|
|
3
|
+
import { abortable, abortError } from "../transport.js";
|
|
4
|
+
import { operations, projections } from "./generated.js";
|
|
5
|
+
/** One eagerly requested page; iterate items and follow continuation until the cursor is absent. */
|
|
6
|
+
export class PagePromise {
|
|
7
|
+
initial;
|
|
8
|
+
fetchPage;
|
|
9
|
+
first;
|
|
10
|
+
constructor(initial, fetchPage) {
|
|
11
|
+
this.initial = initial;
|
|
12
|
+
this.fetchPage = fetchPage;
|
|
13
|
+
this.first = fetchPage(initial);
|
|
14
|
+
// Allows callers to save a PagePromise before awaiting or iterating it.
|
|
15
|
+
void this.first.catch(() => { });
|
|
16
|
+
}
|
|
17
|
+
then(onfulfilled, onrejected) {
|
|
18
|
+
return this.first.then(onfulfilled, onrejected);
|
|
19
|
+
}
|
|
20
|
+
async *[Symbol.asyncIterator]() {
|
|
21
|
+
const seen = new Set(this.initial == null ? [] : [this.initial]);
|
|
22
|
+
let page = await this.first;
|
|
23
|
+
for (;;) {
|
|
24
|
+
for (const item of page.items)
|
|
25
|
+
yield item;
|
|
26
|
+
const next = page.next_cursor;
|
|
27
|
+
if (next == null)
|
|
28
|
+
return;
|
|
29
|
+
if (seen.has(next))
|
|
30
|
+
throw new UnexpectedResponseError("Service returned a repeated pagination cursor.");
|
|
31
|
+
seen.add(next);
|
|
32
|
+
page = await this.fetchPage(next);
|
|
23
33
|
}
|
|
24
34
|
}
|
|
25
|
-
const encoded = parameters.toString();
|
|
26
|
-
return encoded ? `${path}?${encoded}` : path;
|
|
27
|
-
}
|
|
28
|
-
export async function jsonRequest(transport, method, path, body, headers, options = {}) {
|
|
29
|
-
const requestHeaders = new Headers(headers);
|
|
30
|
-
requestHeaders.set("Accept", "application/json");
|
|
31
|
-
const hasBody = body !== undefined;
|
|
32
|
-
if (hasBody)
|
|
33
|
-
requestHeaders.set("Content-Type", "application/json");
|
|
34
|
-
const init = {
|
|
35
|
-
method,
|
|
36
|
-
headers: requestHeaders,
|
|
37
|
-
signal: requestSignal(options.signal),
|
|
38
|
-
};
|
|
39
|
-
if (hasBody)
|
|
40
|
-
init.body = JSON.stringify(body);
|
|
41
|
-
const response = await transport.fetch(inheritDispatch(new Request(`${transport.baseUrl}${withQuery(path, options.query)}`, init), options.signal));
|
|
42
|
-
if (response.status === 204 || response.status === 205)
|
|
43
|
-
return { data: undefined, response };
|
|
44
|
-
const text = await response.text();
|
|
45
|
-
if (!text)
|
|
46
|
-
return { data: undefined, response };
|
|
47
|
-
try {
|
|
48
|
-
return { data: JSON.parse(text), response };
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
throw new ProtocolError("The Service returned invalid JSON.");
|
|
52
|
-
}
|
|
53
35
|
}
|
|
54
|
-
|
|
55
|
-
response
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.sourceReader = source.getReader();
|
|
64
|
-
this.body = new ReadableStream({
|
|
65
|
-
pull: async (controller) => {
|
|
66
|
-
try {
|
|
67
|
-
const result = await this.sourceReader.read();
|
|
68
|
-
if (result.done) {
|
|
69
|
-
this.isClosed = true;
|
|
70
|
-
this.releaseSource();
|
|
71
|
-
controller.close();
|
|
72
|
-
}
|
|
73
|
-
else
|
|
74
|
-
controller.enqueue(result.value);
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
this.isClosed = true;
|
|
78
|
-
this.releaseSource();
|
|
79
|
-
controller.error(error);
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
cancel: (reason) => this.cancelSource(reason),
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
get closed() {
|
|
86
|
-
return this.isClosed;
|
|
87
|
-
}
|
|
88
|
-
close() {
|
|
89
|
-
return this.cancelSource(new DOMException("Binary download closed.", "AbortError"));
|
|
90
|
-
}
|
|
91
|
-
cancelSource(reason) {
|
|
92
|
-
if (this.isClosed)
|
|
93
|
-
return Promise.resolve();
|
|
94
|
-
if (!this.closePromise) {
|
|
95
|
-
this.closePromise = this.sourceReader.cancel(reason).then(() => {
|
|
96
|
-
this.isClosed = true;
|
|
97
|
-
this.releaseSource();
|
|
98
|
-
});
|
|
36
|
+
function binaryBody(response) {
|
|
37
|
+
if (!response.body)
|
|
38
|
+
throw new UnexpectedResponseError("Service returned no binary response body.");
|
|
39
|
+
const reader = response.body.getReader();
|
|
40
|
+
let closed = false;
|
|
41
|
+
function release() {
|
|
42
|
+
if (!closed) {
|
|
43
|
+
closed = true;
|
|
44
|
+
reader.releaseLock();
|
|
99
45
|
}
|
|
100
|
-
return this.closePromise;
|
|
101
|
-
}
|
|
102
|
-
releaseSource() {
|
|
103
|
-
if (this.released)
|
|
104
|
-
return;
|
|
105
|
-
this.released = true;
|
|
106
|
-
this.sourceReader.releaseLock();
|
|
107
46
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
headers: requestHeaders,
|
|
117
|
-
body,
|
|
118
|
-
signal: requestSignal(options.signal),
|
|
47
|
+
const close = async () => {
|
|
48
|
+
if (!closed)
|
|
49
|
+
try {
|
|
50
|
+
await reader.cancel();
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
release();
|
|
54
|
+
}
|
|
119
55
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
56
|
+
const body = new ReadableStream({
|
|
57
|
+
async pull(controller) {
|
|
58
|
+
if (closed) {
|
|
59
|
+
controller.close();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const next = await reader.read();
|
|
64
|
+
if (next.done) {
|
|
65
|
+
release();
|
|
66
|
+
controller.close();
|
|
67
|
+
}
|
|
68
|
+
else
|
|
69
|
+
controller.enqueue(next.value);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
release();
|
|
73
|
+
controller.error(error);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
cancel: close,
|
|
77
|
+
}, { highWaterMark: 0 });
|
|
78
|
+
return { response, body, close };
|
|
79
|
+
}
|
|
80
|
+
const camel = (name) => name.replace(/[-_]([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
81
|
+
function encodeQuery(options, keys) {
|
|
82
|
+
const query = new URLSearchParams();
|
|
83
|
+
for (const key of keys) {
|
|
84
|
+
const value = options[camel(key)];
|
|
85
|
+
if (value === undefined || (value === null && key === "app_id"))
|
|
86
|
+
continue;
|
|
87
|
+
for (const item of Array.isArray(value) ? value : [value])
|
|
88
|
+
if (item !== undefined)
|
|
89
|
+
query.append(key, item === null ? "" : String(item));
|
|
131
90
|
}
|
|
91
|
+
return query.size ? "?" + query.toString() : "";
|
|
132
92
|
}
|
|
133
|
-
|
|
93
|
+
function formBody(value) {
|
|
134
94
|
const form = new FormData();
|
|
135
|
-
for (const [name,
|
|
136
|
-
|
|
137
|
-
continue;
|
|
138
|
-
for (const item of Array.isArray(value) ? value : [value]) {
|
|
95
|
+
for (const [name, value_] of Object.entries(value ?? {})) {
|
|
96
|
+
for (const item of Array.isArray(value_) ? value_ : [value_]) {
|
|
139
97
|
if (item instanceof Blob)
|
|
140
98
|
form.append(name, item);
|
|
141
|
-
else
|
|
99
|
+
else if (item !== undefined)
|
|
142
100
|
form.append(name, item === null ? "" : String(item));
|
|
143
101
|
}
|
|
144
102
|
}
|
|
145
103
|
return form;
|
|
146
104
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (!response.body)
|
|
156
|
-
throw new ProtocolError("The Service returned no binary response body.");
|
|
157
|
-
return new ScopedBinaryResult(response, response.body);
|
|
158
|
-
}
|
|
159
|
-
export class PageIterator {
|
|
160
|
-
fetchPage;
|
|
161
|
-
pageInfo;
|
|
162
|
-
cursor;
|
|
163
|
-
seen = new Set();
|
|
164
|
-
reading = false;
|
|
165
|
-
isClosed = false;
|
|
166
|
-
constructor(cursor, fetchPage, pageInfo) {
|
|
167
|
-
this.fetchPage = fetchPage;
|
|
168
|
-
this.pageInfo = pageInfo;
|
|
169
|
-
this.cursor = cursor;
|
|
170
|
-
if (typeof cursor === "string")
|
|
171
|
-
this.seen.add(cursor);
|
|
172
|
-
}
|
|
173
|
-
[Symbol.asyncIterator]() {
|
|
174
|
-
return this;
|
|
175
|
-
}
|
|
176
|
-
async next() {
|
|
177
|
-
if (this.isClosed)
|
|
178
|
-
return { done: true, value: undefined };
|
|
179
|
-
if (this.reading)
|
|
180
|
-
throw new TypeError("The page iterator supports one active reader.");
|
|
181
|
-
this.reading = true;
|
|
182
|
-
try {
|
|
183
|
-
const page = await this.fetchPage(this.cursor);
|
|
184
|
-
const following = this.pageInfo(page.data).next_cursor;
|
|
185
|
-
if (following === null || following === undefined)
|
|
186
|
-
this.isClosed = true;
|
|
187
|
-
else {
|
|
188
|
-
if (this.seen.has(following))
|
|
189
|
-
throw new ProtocolError("The Service returned a repeated pagination cursor.");
|
|
190
|
-
this.seen.add(following);
|
|
191
|
-
this.cursor = following;
|
|
192
|
-
}
|
|
193
|
-
return { done: false, value: page };
|
|
105
|
+
const makeNode = () => ({ methods: new Map(), children: new Map() });
|
|
106
|
+
const root = makeNode();
|
|
107
|
+
for (const [parts, method, spec] of operations) {
|
|
108
|
+
let node = root;
|
|
109
|
+
for (const part of parts) {
|
|
110
|
+
if (part.startsWith("{")) {
|
|
111
|
+
node.select ??= [part, makeNode()];
|
|
112
|
+
node = node.select[1];
|
|
194
113
|
}
|
|
195
|
-
|
|
196
|
-
|
|
114
|
+
else {
|
|
115
|
+
if (!node.children.has(part))
|
|
116
|
+
node.children.set(part, makeNode());
|
|
117
|
+
node = node.children.get(part);
|
|
197
118
|
}
|
|
198
119
|
}
|
|
199
|
-
|
|
200
|
-
this.isClosed = true;
|
|
201
|
-
return { done: true, value: undefined };
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
export async function* flattenPages(pages, pageInfo) {
|
|
205
|
-
for await (const page of pages) {
|
|
206
|
-
for (const item of pageInfo(page.data).items)
|
|
207
|
-
yield item;
|
|
208
|
-
}
|
|
120
|
+
node.methods.set(method, spec);
|
|
209
121
|
}
|
|
210
|
-
|
|
211
|
-
|
|
122
|
+
function selector(value) {
|
|
123
|
+
if (typeof value !== "string" && typeof value !== "number")
|
|
124
|
+
throw new TypeError("Resource selector must be a string or number.");
|
|
125
|
+
const raw = String(value);
|
|
126
|
+
// WHATWG URL normalizes even percent-encoded dot segments.
|
|
127
|
+
if (!raw || raw === "." || raw === "..")
|
|
128
|
+
throw new TypeError("Resource selector is empty or a dot segment.");
|
|
129
|
+
return encodeURIComponent(raw);
|
|
212
130
|
}
|
|
213
|
-
export function
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
131
|
+
export function createResources(transport, workspace, raw, extras, entry) {
|
|
132
|
+
function bind(node, path, selectors, wire) {
|
|
133
|
+
const value = node.select
|
|
134
|
+
? (id) => {
|
|
135
|
+
const [parameter, child] = node.select;
|
|
136
|
+
const encoded = selector(id);
|
|
137
|
+
return bind(child, [...path, parameter], { ...selectors, [parameter.slice(1, -1)]: String(id) }, { ...wire, [parameter]: encoded });
|
|
138
|
+
}
|
|
139
|
+
: Object.create(null);
|
|
140
|
+
for (const [name, child] of node.children) {
|
|
141
|
+
Object.defineProperty(value, name, {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get() {
|
|
144
|
+
return bind(child, [...path, name], selectors, wire);
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
for (const [name, spec] of node.methods) {
|
|
149
|
+
const route = spec.path.replace(/\{[^}]+\}/g, (parameter) => wire[parameter]);
|
|
150
|
+
Object.assign(value, {
|
|
151
|
+
[name](...args) {
|
|
152
|
+
const body = spec.media ? args[0] : undefined;
|
|
153
|
+
const options = {
|
|
154
|
+
...args[spec.media ? 1 : 0],
|
|
155
|
+
};
|
|
156
|
+
const headers = new Headers();
|
|
157
|
+
headers.set("Accept", spec.accept ?? "application/json");
|
|
158
|
+
for (const header of spec.headers ?? []) {
|
|
159
|
+
const provided = options[camel(header.toLowerCase())];
|
|
160
|
+
if (provided != null)
|
|
161
|
+
headers.set(header, String(provided));
|
|
162
|
+
}
|
|
163
|
+
const request = {
|
|
164
|
+
headers,
|
|
165
|
+
signal: options.signal,
|
|
166
|
+
};
|
|
167
|
+
if (body !== undefined) {
|
|
168
|
+
if (spec.media === "application/json") {
|
|
169
|
+
headers.set("Content-Type", "application/json");
|
|
170
|
+
request.body = JSON.stringify(body);
|
|
171
|
+
}
|
|
172
|
+
else if (spec.media === "multipart/form-data")
|
|
173
|
+
request.body = formBody(body);
|
|
174
|
+
else if (spec.media === "application/x-www-form-urlencoded")
|
|
175
|
+
request.body = new URLSearchParams(Object.entries(body)
|
|
176
|
+
.filter(([, part]) => part !== undefined)
|
|
177
|
+
.map(([field, part]) => [
|
|
178
|
+
field,
|
|
179
|
+
part === null ? "" : String(part),
|
|
180
|
+
]));
|
|
181
|
+
else {
|
|
182
|
+
headers.set("Content-Type", String(options.contentType));
|
|
183
|
+
request.body = body;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const send = async (params) => {
|
|
187
|
+
const signal = transport.requestSignal(request.signal);
|
|
188
|
+
const response = await transport.fetch(spec, route + encodeQuery(params, spec.query ?? []), request, workspace, signal);
|
|
189
|
+
let data;
|
|
190
|
+
if (spec.binary)
|
|
191
|
+
data = binaryBody(response);
|
|
192
|
+
else if (response.status !== 204 &&
|
|
193
|
+
response.status !== 205 &&
|
|
194
|
+
spec.accept?.includes("application/json")) {
|
|
195
|
+
try {
|
|
196
|
+
data = await abortable(response.json(), signal);
|
|
197
|
+
}
|
|
198
|
+
catch (cause) {
|
|
199
|
+
const error = signal.aborted
|
|
200
|
+
? abortError(signal)
|
|
201
|
+
: new UnexpectedResponseError(`Service returned invalid JSON for ${spec.id}.`, { cause });
|
|
202
|
+
if (spec.method !== "GET" && spec.method !== "HEAD")
|
|
203
|
+
throw new UnknownOutcomeError(headers.get("Idempotency-Key"), error, response);
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (spec.model)
|
|
208
|
+
projectModels(data, spec.model, projections);
|
|
209
|
+
if (raw)
|
|
210
|
+
return {
|
|
211
|
+
data,
|
|
212
|
+
response,
|
|
213
|
+
status: response.status,
|
|
214
|
+
headers: response.headers,
|
|
215
|
+
requestId: response.headers.get("X-Request-ID"),
|
|
216
|
+
};
|
|
217
|
+
if (spec.submitted)
|
|
218
|
+
return entry(data, headers.get("Idempotency-Key"));
|
|
219
|
+
return data;
|
|
220
|
+
};
|
|
221
|
+
if (!raw &&
|
|
222
|
+
(spec.page === "cursor" ||
|
|
223
|
+
(spec.page === "hybrid" &&
|
|
224
|
+
options.section == null &&
|
|
225
|
+
(options.limit != null ||
|
|
226
|
+
options.cursor != null ||
|
|
227
|
+
options.view === "compact" ||
|
|
228
|
+
options.query != null ||
|
|
229
|
+
options.capability != null)))) {
|
|
230
|
+
return new PagePromise(options.cursor, (cursor) => {
|
|
231
|
+
const next = { ...options, cursor };
|
|
232
|
+
if (cursor != null)
|
|
233
|
+
delete next.anchor;
|
|
234
|
+
return send(next);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return send(options);
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return Object.assign(value, extras?.(path.join("."), selectors));
|
|
242
|
+
}
|
|
243
|
+
return bind(root, [], {}, {});
|
|
222
244
|
}
|
|
223
245
|
//# sourceMappingURL=base.js.map
|