@w6w/sdk 0.9.24 → 0.9.28
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/mod.d.ts +6 -0
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +4 -0
- package/dist/mod.js.map +1 -1
- package/dist/src/app-management.d.ts +41 -0
- package/dist/src/app-management.d.ts.map +1 -0
- package/dist/src/app-management.js +107 -0
- package/dist/src/app-management.js.map +1 -0
- package/dist/src/client.d.ts +9 -0
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +11 -0
- package/dist/src/client.js.map +1 -1
- package/dist/src/console/apps.d.ts +2 -0
- package/dist/src/console/apps.d.ts.map +1 -1
- package/dist/src/console/apps.js +1 -0
- package/dist/src/console/apps.js.map +1 -1
- package/dist/src/console/subscriptions.d.ts +14 -2
- package/dist/src/console/subscriptions.d.ts.map +1 -1
- package/dist/src/console/subscriptions.js +14 -0
- package/dist/src/console/subscriptions.js.map +1 -1
- package/dist/src/data-stores.d.ts +128 -0
- package/dist/src/data-stores.d.ts.map +1 -0
- package/dist/src/data-stores.js +212 -0
- package/dist/src/data-stores.js.map +1 -0
- package/dist/src/http.d.ts +18 -3
- package/dist/src/http.d.ts.map +1 -1
- package/dist/src/http.js +15 -2
- package/dist/src/http.js.map +1 -1
- package/dist/src/types.d.ts +321 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `client.dataStores.*` — the account's persistent key-value, document and
|
|
3
|
+
* table storage (contract `0.15.0`, 14 operations, one HTTP call each).
|
|
4
|
+
*
|
|
5
|
+
* Stores are **project-scoped**: every route accepts an optional `?project=`,
|
|
6
|
+
* resolved per call, then from the client's default, and otherwise left to the
|
|
7
|
+
* server (the account's default project).
|
|
8
|
+
*
|
|
9
|
+
* Two operations use the explicit text transport (`docs/implementation.md` §3):
|
|
10
|
+
* `importCsv` sends the CSV string verbatim as `text/csv`, and `exportCsv`
|
|
11
|
+
* returns the body verbatim as a string. Errors keep the ordinary
|
|
12
|
+
* {@linkcode ApiError} shape; the server's `field`/`row`/`column` extras are on
|
|
13
|
+
* `error.raw.error`.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import type { ResolvedConfig } from "./config.ts";
|
|
18
|
+
import { type CallOptions, type HttpResponse, type RequestOptions } from "./http.ts";
|
|
19
|
+
import type { DataStore, DataStoreEntry, DataStoreEntryPage, DataStoreKind, DataStorePage, DataStoreRowSet, DataStoreSchema } from "./types.ts";
|
|
20
|
+
/** The slice of `W6WClient` these namespaces need: the transport plus the default project. */
|
|
21
|
+
export interface DataStoresHost {
|
|
22
|
+
/** The resolved configuration; only `project` is read. */
|
|
23
|
+
readonly config: ResolvedConfig;
|
|
24
|
+
/** Perform one request. */
|
|
25
|
+
request<T>(options: RequestOptions): Promise<HttpResponse<T>>;
|
|
26
|
+
}
|
|
27
|
+
/** Per-call options shared by every data-store operation. */
|
|
28
|
+
export interface DataStoreOptions extends CallOptions {
|
|
29
|
+
/** Project id to scope this call to; overrides the client's default. */
|
|
30
|
+
project?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Options of `dataStores.list`. */
|
|
33
|
+
export interface DataStoreListOptions extends DataStoreOptions {
|
|
34
|
+
kind?: DataStoreKind;
|
|
35
|
+
cursor?: string;
|
|
36
|
+
limit?: number;
|
|
37
|
+
}
|
|
38
|
+
/** The body of `dataStores.create`. */
|
|
39
|
+
export interface DataStoreCreateInput {
|
|
40
|
+
kind: DataStoreKind;
|
|
41
|
+
name: string;
|
|
42
|
+
description?: string;
|
|
43
|
+
/** Table stores only. */
|
|
44
|
+
schema?: DataStoreSchema;
|
|
45
|
+
}
|
|
46
|
+
/** The body of `dataStores.update`; an omitted field is left alone. */
|
|
47
|
+
export interface DataStorePatch {
|
|
48
|
+
name?: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
schema?: DataStoreSchema;
|
|
51
|
+
}
|
|
52
|
+
/** Options of `dataStores.entries.list`. */
|
|
53
|
+
export interface DataStoreEntryListOptions extends DataStoreOptions {
|
|
54
|
+
prefix?: string;
|
|
55
|
+
cursor?: string;
|
|
56
|
+
limit?: number;
|
|
57
|
+
}
|
|
58
|
+
/** The body of `dataStores.entries.set`. */
|
|
59
|
+
export interface DataStoreEntrySetInput {
|
|
60
|
+
value: unknown;
|
|
61
|
+
/** Conditional write: only if the entry is at this version (`409 version_conflict`). */
|
|
62
|
+
ifVersion?: number;
|
|
63
|
+
ttlSeconds?: number;
|
|
64
|
+
}
|
|
65
|
+
/** Options of `dataStores.entries.insert`. */
|
|
66
|
+
export interface DataStoreInsertOptions extends DataStoreOptions {
|
|
67
|
+
ttlSeconds?: number;
|
|
68
|
+
}
|
|
69
|
+
/** The filter of `dataStores.entries.query`. */
|
|
70
|
+
export interface DataStoreQuery {
|
|
71
|
+
/** One `where[<col>]=<value>` query key per column. */
|
|
72
|
+
where?: Record<string, string | number | boolean>;
|
|
73
|
+
order?: string;
|
|
74
|
+
limit?: number;
|
|
75
|
+
}
|
|
76
|
+
/** The `dataStores.entries` namespace. */
|
|
77
|
+
export declare class DataStoreEntriesApi {
|
|
78
|
+
#private;
|
|
79
|
+
/** @param host - The client this namespace issues requests through. */
|
|
80
|
+
constructor(host: DataStoresHost);
|
|
81
|
+
/** List a store's entries, paged by key. */
|
|
82
|
+
list(id: string, options?: DataStoreEntryListOptions): Promise<DataStoreEntryPage>;
|
|
83
|
+
/** Fetch one entry by key. `404 entry_not_found` when absent. */
|
|
84
|
+
get(id: string, key: string, options?: DataStoreOptions): Promise<DataStoreEntry>;
|
|
85
|
+
/** Create or replace one entry by key. */
|
|
86
|
+
set(id: string, key: string, input: DataStoreEntrySetInput, options?: DataStoreOptions): Promise<DataStoreEntry>;
|
|
87
|
+
/** Insert one row into a table store; the server generates the key. */
|
|
88
|
+
insert(id: string, row: Record<string, unknown>, options?: DataStoreInsertOptions): Promise<DataStoreEntry>;
|
|
89
|
+
/** Atomically add `by` (default 1, sent as no body) to a numeric entry. */
|
|
90
|
+
increment(id: string, key: string, by?: number, options?: DataStoreOptions): Promise<DataStoreEntry>;
|
|
91
|
+
/** Delete one entry by key. `404 entry_not_found` when absent. */
|
|
92
|
+
delete(id: string, key: string, options?: DataStoreOptions): Promise<void>;
|
|
93
|
+
/** Filter and order a table store's rows (query mode: `{items}` only). */
|
|
94
|
+
query(id: string, query?: DataStoreQuery, options?: DataStoreOptions): Promise<DataStoreRowSet>;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The `dataStores` namespace on a `W6WClient`.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* const store = await client.dataStores.create({ kind: "kv", name: "counters" });
|
|
102
|
+
* await client.dataStores.entries.increment(store.id, "visits");
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare class DataStoresApi {
|
|
106
|
+
#private;
|
|
107
|
+
/** Entry operations. */
|
|
108
|
+
readonly entries: DataStoreEntriesApi;
|
|
109
|
+
/** @param host - The client this namespace issues requests through. */
|
|
110
|
+
constructor(host: DataStoresHost);
|
|
111
|
+
/** List the project's stores. */
|
|
112
|
+
list(options?: DataStoreListOptions): Promise<DataStorePage>;
|
|
113
|
+
/** Fetch one store. `404 data_store_not_found` when absent. */
|
|
114
|
+
get(id: string, options?: DataStoreOptions): Promise<DataStore>;
|
|
115
|
+
/** Create a store (the server answers `201`). */
|
|
116
|
+
create(input: DataStoreCreateInput, options?: DataStoreOptions): Promise<DataStore>;
|
|
117
|
+
/** Patch a store's name, description or schema. */
|
|
118
|
+
update(id: string, patch: DataStorePatch, options?: DataStoreOptions): Promise<DataStore>;
|
|
119
|
+
/** Archive a store (soft delete; `204`). */
|
|
120
|
+
archive(id: string, options?: DataStoreOptions): Promise<void>;
|
|
121
|
+
/** Import CSV text (header row = column names) into a table store. */
|
|
122
|
+
importCsv(id: string, csv: string, options?: DataStoreOptions): Promise<{
|
|
123
|
+
imported: number;
|
|
124
|
+
}>;
|
|
125
|
+
/** Export a table store as CSV text, returned verbatim. */
|
|
126
|
+
exportCsv(id: string, options?: DataStoreOptions): Promise<string>;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=data-stores.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-stores.d.ts","sourceRoot":"","sources":["../../src/data-stores.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAQ,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3F,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,eAAe,EACf,eAAe,EAChB,MAAM,YAAY,CAAC;AAEpB,8FAA8F;AAC9F,MAAM,WAAW,cAAc;IAC7B,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,2BAA2B;IAC3B,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/D;AAED,6DAA6D;AAC7D,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,oCAAoC;AACpC,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC5D,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,uCAAuC;AACvC,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,CAAC;IACpB,I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gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC;IAezF,mDAAmD;IAC7C,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC;IAU/F,4CAA4C;IACtC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQpE,sEAAsE;IAChE,SAAS,CACb,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAWhC,2DAA2D;IACrD,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;CAUzE"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `client.dataStores.*` — the account's persistent key-value, document and
|
|
3
|
+
* table storage (contract `0.15.0`, 14 operations, one HTTP call each).
|
|
4
|
+
*
|
|
5
|
+
* Stores are **project-scoped**: every route accepts an optional `?project=`,
|
|
6
|
+
* resolved per call, then from the client's default, and otherwise left to the
|
|
7
|
+
* server (the account's default project).
|
|
8
|
+
*
|
|
9
|
+
* Two operations use the explicit text transport (`docs/implementation.md` §3):
|
|
10
|
+
* `importCsv` sends the CSV string verbatim as `text/csv`, and `exportCsv`
|
|
11
|
+
* returns the body verbatim as a string. Errors keep the ordinary
|
|
12
|
+
* {@linkcode ApiError} shape; the server's `field`/`row`/`column` extras are on
|
|
13
|
+
* `error.raw.error`.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import { path } from "./http.js";
|
|
18
|
+
/** The `dataStores.entries` namespace. */
|
|
19
|
+
export class DataStoreEntriesApi {
|
|
20
|
+
#host;
|
|
21
|
+
/** @param host - The client this namespace issues requests through. */
|
|
22
|
+
constructor(host) {
|
|
23
|
+
this.#host = host;
|
|
24
|
+
}
|
|
25
|
+
#project(options) {
|
|
26
|
+
return options?.project ?? this.#host.config.project ?? undefined;
|
|
27
|
+
}
|
|
28
|
+
/** List a store's entries, paged by key. */
|
|
29
|
+
async list(id, options) {
|
|
30
|
+
const res = await this.#host.request({
|
|
31
|
+
method: "GET",
|
|
32
|
+
path: path `/data-stores/${id}/entries`,
|
|
33
|
+
query: {
|
|
34
|
+
prefix: options?.prefix,
|
|
35
|
+
cursor: options?.cursor,
|
|
36
|
+
limit: options?.limit,
|
|
37
|
+
project: this.#project(options),
|
|
38
|
+
},
|
|
39
|
+
signal: options?.signal,
|
|
40
|
+
});
|
|
41
|
+
return res.body;
|
|
42
|
+
}
|
|
43
|
+
/** Fetch one entry by key. `404 entry_not_found` when absent. */
|
|
44
|
+
async get(id, key, options) {
|
|
45
|
+
const res = await this.#host.request({
|
|
46
|
+
method: "GET",
|
|
47
|
+
path: path `/data-stores/${id}/entries/${key}`,
|
|
48
|
+
query: { project: this.#project(options) },
|
|
49
|
+
signal: options?.signal,
|
|
50
|
+
});
|
|
51
|
+
return res.body;
|
|
52
|
+
}
|
|
53
|
+
/** Create or replace one entry by key. */
|
|
54
|
+
async set(id, key, input, options) {
|
|
55
|
+
const res = await this.#host.request({
|
|
56
|
+
method: "PUT",
|
|
57
|
+
path: path `/data-stores/${id}/entries/${key}`,
|
|
58
|
+
query: { project: this.#project(options) },
|
|
59
|
+
body: { value: input.value, ifVersion: input.ifVersion, ttlSeconds: input.ttlSeconds },
|
|
60
|
+
});
|
|
61
|
+
return res.body;
|
|
62
|
+
}
|
|
63
|
+
/** Insert one row into a table store; the server generates the key. */
|
|
64
|
+
async insert(id, row, options) {
|
|
65
|
+
const res = await this.#host.request({
|
|
66
|
+
method: "POST",
|
|
67
|
+
path: path `/data-stores/${id}/entries`,
|
|
68
|
+
query: { project: this.#project(options) },
|
|
69
|
+
body: { value: row, ttlSeconds: options?.ttlSeconds },
|
|
70
|
+
});
|
|
71
|
+
return res.body;
|
|
72
|
+
}
|
|
73
|
+
/** Atomically add `by` (default 1, sent as no body) to a numeric entry. */
|
|
74
|
+
async increment(id, key, by, options) {
|
|
75
|
+
const res = await this.#host.request({
|
|
76
|
+
method: "POST",
|
|
77
|
+
path: path `/data-stores/${id}/entries/${key}/increment`,
|
|
78
|
+
query: { project: this.#project(options) },
|
|
79
|
+
...(by === undefined ? {} : { body: { by } }),
|
|
80
|
+
});
|
|
81
|
+
return res.body;
|
|
82
|
+
}
|
|
83
|
+
/** Delete one entry by key. `404 entry_not_found` when absent. */
|
|
84
|
+
async delete(id, key, options) {
|
|
85
|
+
await this.#host.request({
|
|
86
|
+
method: "DELETE",
|
|
87
|
+
path: path `/data-stores/${id}/entries/${key}`,
|
|
88
|
+
query: { project: this.#project(options) },
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** Filter and order a table store's rows (query mode: `{items}` only). */
|
|
92
|
+
async query(id, query, options) {
|
|
93
|
+
const where = {};
|
|
94
|
+
for (const [col, v] of Object.entries(query?.where ?? {}))
|
|
95
|
+
where[`where[${col}]`] = v;
|
|
96
|
+
const res = await this.#host.request({
|
|
97
|
+
method: "GET",
|
|
98
|
+
path: path `/data-stores/${id}/entries`,
|
|
99
|
+
query: {
|
|
100
|
+
...where,
|
|
101
|
+
order: query?.order,
|
|
102
|
+
limit: query?.limit,
|
|
103
|
+
project: this.#project(options),
|
|
104
|
+
},
|
|
105
|
+
signal: options?.signal,
|
|
106
|
+
});
|
|
107
|
+
return res.body;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The `dataStores` namespace on a `W6WClient`.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const store = await client.dataStores.create({ kind: "kv", name: "counters" });
|
|
116
|
+
* await client.dataStores.entries.increment(store.id, "visits");
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export class DataStoresApi {
|
|
120
|
+
#host;
|
|
121
|
+
/** Entry operations. */
|
|
122
|
+
entries;
|
|
123
|
+
/** @param host - The client this namespace issues requests through. */
|
|
124
|
+
constructor(host) {
|
|
125
|
+
this.#host = host;
|
|
126
|
+
this.entries = new DataStoreEntriesApi(host);
|
|
127
|
+
}
|
|
128
|
+
#project(options) {
|
|
129
|
+
return options?.project ?? this.#host.config.project ?? undefined;
|
|
130
|
+
}
|
|
131
|
+
/** List the project's stores. */
|
|
132
|
+
async list(options) {
|
|
133
|
+
const res = await this.#host.request({
|
|
134
|
+
method: "GET",
|
|
135
|
+
path: "/data-stores",
|
|
136
|
+
query: {
|
|
137
|
+
kind: options?.kind,
|
|
138
|
+
cursor: options?.cursor,
|
|
139
|
+
limit: options?.limit,
|
|
140
|
+
project: this.#project(options),
|
|
141
|
+
},
|
|
142
|
+
signal: options?.signal,
|
|
143
|
+
});
|
|
144
|
+
return res.body;
|
|
145
|
+
}
|
|
146
|
+
/** Fetch one store. `404 data_store_not_found` when absent. */
|
|
147
|
+
async get(id, options) {
|
|
148
|
+
const res = await this.#host.request({
|
|
149
|
+
method: "GET",
|
|
150
|
+
path: path `/data-stores/${id}`,
|
|
151
|
+
query: { project: this.#project(options) },
|
|
152
|
+
signal: options?.signal,
|
|
153
|
+
});
|
|
154
|
+
return res.body;
|
|
155
|
+
}
|
|
156
|
+
/** Create a store (the server answers `201`). */
|
|
157
|
+
async create(input, options) {
|
|
158
|
+
const res = await this.#host.request({
|
|
159
|
+
method: "POST",
|
|
160
|
+
path: "/data-stores",
|
|
161
|
+
query: { project: this.#project(options) },
|
|
162
|
+
body: {
|
|
163
|
+
kind: input.kind,
|
|
164
|
+
name: input.name,
|
|
165
|
+
description: input.description,
|
|
166
|
+
schema: input.schema,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
return res.body;
|
|
170
|
+
}
|
|
171
|
+
/** Patch a store's name, description or schema. */
|
|
172
|
+
async update(id, patch, options) {
|
|
173
|
+
const res = await this.#host.request({
|
|
174
|
+
method: "PATCH",
|
|
175
|
+
path: path `/data-stores/${id}`,
|
|
176
|
+
query: { project: this.#project(options) },
|
|
177
|
+
body: { name: patch.name, description: patch.description, schema: patch.schema },
|
|
178
|
+
});
|
|
179
|
+
return res.body;
|
|
180
|
+
}
|
|
181
|
+
/** Archive a store (soft delete; `204`). */
|
|
182
|
+
async archive(id, options) {
|
|
183
|
+
await this.#host.request({
|
|
184
|
+
method: "DELETE",
|
|
185
|
+
path: path `/data-stores/${id}`,
|
|
186
|
+
query: { project: this.#project(options) },
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/** Import CSV text (header row = column names) into a table store. */
|
|
190
|
+
async importCsv(id, csv, options) {
|
|
191
|
+
const res = await this.#host.request({
|
|
192
|
+
method: "POST",
|
|
193
|
+
path: path `/data-stores/${id}/import`,
|
|
194
|
+
query: { project: this.#project(options) },
|
|
195
|
+
body: csv,
|
|
196
|
+
bodyEncoding: "csv",
|
|
197
|
+
});
|
|
198
|
+
return res.body;
|
|
199
|
+
}
|
|
200
|
+
/** Export a table store as CSV text, returned verbatim. */
|
|
201
|
+
async exportCsv(id, options) {
|
|
202
|
+
const res = await this.#host.request({
|
|
203
|
+
method: "GET",
|
|
204
|
+
path: path `/data-stores/${id}/export`,
|
|
205
|
+
query: { project: this.#project(options) },
|
|
206
|
+
responseType: "text",
|
|
207
|
+
signal: options?.signal,
|
|
208
|
+
});
|
|
209
|
+
return res.body;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=data-stores.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-stores.js","sourceRoot":"","sources":["../../src/data-stores.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAuC,IAAI,EAAuB,MAAM,WAAW,CAAC;AA4E3F,0CAA0C;AAC1C,MAAM,OAAO,mB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,CAAC,CAAC;IACL,CAAC;IAED,sEAAsE;IACtE,KAAK,CAAC,SAAS,CACb,EAAU,EACV,GAAW,EACX,OAA0B;QAE1B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAuB;YACzD,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAA,gBAAgB,EAAE,SAAS;YACrC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC1C,IAAI,EAAE,GAAG;YACT,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;QACH,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,SAAS,CAAC,EAAU,EAAE,OAA0B;QACpD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAS;YAC3C,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,IAAI,CAAA,gBAAgB,EAAE,SAAS;YACrC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC1C,YAAY,EAAE,MAAM;YACpB,MAAM,EAAE,OAAO,EAAE,MAAM;SACxB,CAAC,CAAC;QACH,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;CACF"}
|
package/dist/src/http.d.ts
CHANGED
|
@@ -58,17 +58,28 @@ export interface RequestOptions {
|
|
|
58
58
|
* Request body; omit it for a bodiless request. A `Uint8Array` is **bytes
|
|
59
59
|
* mode**: sent untouched with `content-type: application/octet-stream` — no
|
|
60
60
|
* JSON encoding, quoting or base64 (an `endpoints.json` operation declaring
|
|
61
|
-
* `bodyEncoding: "octet-stream"`). Anything else is serialised as JSON
|
|
61
|
+
* `bodyEncoding: "octet-stream"`). Anything else is serialised as JSON —
|
|
62
|
+
* including a `string`, unless {@linkcode RequestOptions.bodyEncoding} says
|
|
63
|
+
* otherwise.
|
|
62
64
|
*/
|
|
63
65
|
body?: unknown;
|
|
66
|
+
/**
|
|
67
|
+
* **Text mode** (contract `0.15.0`, an operation declaring `bodyEncoding:
|
|
68
|
+
* "csv"`): `"csv"` sends `body` — which must then be a string — verbatim with
|
|
69
|
+
* `content-type: text/csv`, never JSON-encoded or quoted. The mode is chosen
|
|
70
|
+
* ONLY by this option, never by `typeof body`: a string without it stays JSON.
|
|
71
|
+
*/
|
|
72
|
+
bodyEncoding?: "csv";
|
|
64
73
|
/**
|
|
65
74
|
* How to read a **successful** response. `"bytes"` returns the body as a
|
|
66
75
|
* `Uint8Array`, read once via `arrayBuffer()` and never decoded or
|
|
67
76
|
* JSON-parsed (an operation declaring `responseEncoding: "octet-stream"`).
|
|
68
|
-
*
|
|
77
|
+
* `"text"` returns the body as a `string`, read once via `text()` and never
|
|
78
|
+
* JSON-parsed even when it would parse (an operation declaring
|
|
79
|
+
* `responseEncoding: "text"`, contract `0.15.0`). Omitted, the body is parsed as JSON as always. A non-2xx response is the
|
|
69
80
|
* JSON error envelope in **both** modes and raises exactly as before.
|
|
70
81
|
*/
|
|
71
|
-
responseType?: "json" | "bytes";
|
|
82
|
+
responseType?: "json" | "bytes" | "text";
|
|
72
83
|
/**
|
|
73
84
|
* Extra headers to send with this request. Precedence, low to high: the
|
|
74
85
|
* client's own `headers` default < this option < the bearer
|
|
@@ -210,6 +221,10 @@ export declare function buildUrl(config: ResolvedConfig, options: RequestOptions
|
|
|
210
221
|
* check is false by construction. `config.onUnauthorized` is invoked with
|
|
211
222
|
* whichever `401`/`unauthorized` error turns out to be terminal.
|
|
212
223
|
*
|
|
224
|
+
* **Text mode** (contract `0.15.0`): `options.bodyEncoding: "csv"` and/or
|
|
225
|
+
* `options.responseType: "text"` swap the success-path encoding the same way,
|
|
226
|
+
* for a string body / string result. Chosen by those options alone.
|
|
227
|
+
*
|
|
213
228
|
* **Byte mode** (contract `0.11.0`): a `Uint8Array` `options.body` and/or
|
|
214
229
|
* `options.responseType: "bytes"` swap only the success-path encoding — see
|
|
215
230
|
* {@linkcode RequestOptions.body} and {@linkcode RequestOptions.responseType}.
|
package/dist/src/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAgB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAGhF;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC;AAErE;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;AAEhF,oCAAoC;AACpC,MAAM,WAAW,cAAc;IAC7B,mBAAmB;IACnB,MAAM,EAAE,UAAU,CAAC;IACnB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAgB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAGhF;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC;AAErE;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;AAEhF,oCAAoC;AACpC,MAAM,WAAW,cAAc;IAC7B,mBAAmB;IACnB,MAAM,EAAE,UA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
@@ -120,6 +120,10 @@ export function buildUrl(config, options) {
|
|
|
120
120
|
* check is false by construction. `config.onUnauthorized` is invoked with
|
|
121
121
|
* whichever `401`/`unauthorized` error turns out to be terminal.
|
|
122
122
|
*
|
|
123
|
+
* **Text mode** (contract `0.15.0`): `options.bodyEncoding: "csv"` and/or
|
|
124
|
+
* `options.responseType: "text"` swap the success-path encoding the same way,
|
|
125
|
+
* for a string body / string result. Chosen by those options alone.
|
|
126
|
+
*
|
|
123
127
|
* **Byte mode** (contract `0.11.0`): a `Uint8Array` `options.body` and/or
|
|
124
128
|
* `options.responseType: "bytes"` swap only the success-path encoding — see
|
|
125
129
|
* {@linkcode RequestOptions.body} and {@linkcode RequestOptions.responseType}.
|
|
@@ -152,8 +156,9 @@ export async function request(config, fetchImpl, options) {
|
|
|
152
156
|
}
|
|
153
157
|
const hasBody = options.body !== undefined;
|
|
154
158
|
const bytesBody = options.body instanceof Uint8Array;
|
|
159
|
+
const csvBody = hasBody && !bytesBody && options.bodyEncoding === "csv";
|
|
155
160
|
if (hasBody) {
|
|
156
|
-
headers.set("content-type", bytesBody ? "application/octet-stream" : "application/json");
|
|
161
|
+
headers.set("content-type", bytesBody ? "application/octet-stream" : csvBody ? "text/csv" : "application/json");
|
|
157
162
|
}
|
|
158
163
|
let res;
|
|
159
164
|
try {
|
|
@@ -164,7 +169,9 @@ export async function request(config, fetchImpl, options) {
|
|
|
164
169
|
? undefined
|
|
165
170
|
: bytesBody
|
|
166
171
|
? options.body
|
|
167
|
-
:
|
|
172
|
+
: csvBody
|
|
173
|
+
? String(options.body)
|
|
174
|
+
: JSON.stringify(options.body),
|
|
168
175
|
signal: options.signal,
|
|
169
176
|
});
|
|
170
177
|
}
|
|
@@ -191,6 +198,12 @@ export async function request(config, fetchImpl, options) {
|
|
|
191
198
|
if (res.ok && options.responseType === "bytes") {
|
|
192
199
|
return { status: res.status, body: new Uint8Array(await res.arrayBuffer()) };
|
|
193
200
|
}
|
|
201
|
+
// Text mode, success path only: the payload is the body, verbatim. Read once
|
|
202
|
+
// via `text()` and never JSON-parsed (a CSV body that happens to parse as
|
|
203
|
+
// JSON stays a string). A non-2xx falls through to the envelope handling.
|
|
204
|
+
if (res.ok && options.responseType === "text") {
|
|
205
|
+
return { status: res.status, body: (await res.text()) };
|
|
206
|
+
}
|
|
194
207
|
// Read the body exactly once, as text, then parse it guardedly — a response
|
|
195
208
|
// body is a single-use stream, and `res.json()` on an HTML error page throws
|
|
196
209
|
// an opaque SyntaxError that loses the page.
|
package/dist/src/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAkB,YAAY,EAAuB,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAkB,YAAY,EAAuB,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAuHvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,IAAI,CAAC,OAA6B,EAAE,GAAG,MAAgB;IACrE,OAAO,OAAO,CAAC,MAAM,CACnB,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,CACnB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,EAAE,EAC9E,EAAE,CACH,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,QAAQ,CAAC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