@scenario-labs/sdk 0.3.0 → 1.1.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 +30 -0
- package/README.md +40 -8
- package/client.d.mts +36 -16
- package/client.d.mts.map +1 -1
- package/client.d.ts +36 -16
- package/client.d.ts.map +1 -1
- package/client.js +10 -0
- package/client.js.map +1 -1
- package/client.mjs +10 -0
- package/client.mjs.map +1 -1
- package/core/pagination.d.mts +153 -0
- package/core/pagination.d.mts.map +1 -0
- package/core/pagination.d.ts +153 -0
- package/core/pagination.d.ts.map +1 -0
- package/core/pagination.js +276 -0
- package/core/pagination.js.map +1 -0
- package/core/pagination.mjs +263 -0
- package/core/pagination.mjs.map +1 -0
- package/index.d.mts +5 -1
- package/index.d.mts.map +1 -1
- package/index.d.ts +5 -1
- package/index.d.ts.map +1 -1
- package/index.js +14 -1
- package/index.js.map +1 -1
- package/index.mjs +5 -1
- package/index.mjs.map +1 -1
- package/lib/asset.d.mts +55 -0
- package/lib/asset.d.mts.map +1 -0
- package/lib/asset.d.ts +55 -0
- package/lib/asset.d.ts.map +1 -0
- package/lib/asset.js +60 -0
- package/lib/asset.js.map +1 -0
- package/lib/asset.mjs +54 -0
- package/lib/asset.mjs.map +1 -0
- package/lib/job.d.mts +13 -1
- package/lib/job.d.mts.map +1 -1
- package/lib/job.d.ts +13 -1
- package/lib/job.d.ts.map +1 -1
- package/lib/job.js +18 -1
- package/lib/job.js.map +1 -1
- package/lib/job.mjs +16 -0
- package/lib/job.mjs.map +1 -1
- package/lib/models.d.mts +34 -2
- package/lib/models.d.mts.map +1 -1
- package/lib/models.d.ts +34 -2
- package/lib/models.d.ts.map +1 -1
- package/lib/models.js +39 -2
- package/lib/models.js.map +1 -1
- package/lib/models.mjs +37 -1
- package/lib/models.mjs.map +1 -1
- package/lib/scenario.d.mts +14 -0
- package/lib/scenario.d.mts.map +1 -1
- package/lib/scenario.d.ts +14 -0
- package/lib/scenario.d.ts.map +1 -1
- package/lib/scenario.js +14 -0
- package/lib/scenario.js.map +1 -1
- package/lib/scenario.mjs +14 -0
- package/lib/scenario.mjs.map +1 -1
- package/lib/upload.d.mts +143 -0
- package/lib/upload.d.mts.map +1 -0
- package/lib/upload.d.ts +143 -0
- package/lib/upload.d.ts.map +1 -0
- package/lib/upload.js +242 -0
- package/lib/upload.js.map +1 -0
- package/lib/upload.mjs +203 -0
- package/lib/upload.mjs.map +1 -0
- package/lib/workflow.d.mts +13 -2
- package/lib/workflow.d.mts.map +1 -1
- package/lib/workflow.d.ts +13 -2
- package/lib/workflow.d.ts.map +1 -1
- package/lib/workflow.js +17 -4
- package/lib/workflow.js.map +1 -1
- package/lib/workflow.mjs +17 -4
- package/lib/workflow.mjs.map +1 -1
- package/lib/workflow_import_validator.d.mts +40 -0
- package/lib/workflow_import_validator.d.mts.map +1 -0
- package/lib/workflow_import_validator.d.ts +40 -0
- package/lib/workflow_import_validator.d.ts.map +1 -0
- package/lib/workflow_import_validator.js +69 -0
- package/lib/workflow_import_validator.js.map +1 -0
- package/lib/workflow_import_validator.mjs +64 -0
- package/lib/workflow_import_validator.mjs.map +1 -0
- package/package.json +11 -1
- package/pagination.d.mts +2 -0
- package/pagination.d.mts.map +1 -0
- package/pagination.d.ts +2 -0
- package/pagination.d.ts.map +1 -0
- package/pagination.js +6 -0
- package/pagination.js.map +1 -0
- package/pagination.mjs +2 -0
- package/pagination.mjs.map +1 -0
- package/resources/assets/assets.d.mts +646 -669
- package/resources/assets/assets.d.mts.map +1 -1
- package/resources/assets/assets.d.ts +646 -669
- package/resources/assets/assets.d.ts.map +1 -1
- package/resources/assets/assets.js +3 -2
- package/resources/assets/assets.js.map +1 -1
- package/resources/assets/assets.mjs +3 -2
- package/resources/assets/assets.mjs.map +1 -1
- package/resources/assets/index.d.mts +1 -1
- package/resources/assets/index.d.mts.map +1 -1
- package/resources/assets/index.d.ts +1 -1
- package/resources/assets/index.d.ts.map +1 -1
- package/resources/assets/index.js.map +1 -1
- package/resources/assets/index.mjs.map +1 -1
- package/resources/assets/public.d.mts +12 -12
- package/resources/assets/public.d.mts.map +1 -1
- package/resources/assets/public.d.ts +12 -12
- package/resources/assets/public.d.ts.map +1 -1
- package/resources/collections/collections.d.mts +38 -49
- package/resources/collections/collections.d.mts.map +1 -1
- package/resources/collections/collections.d.ts +38 -49
- package/resources/collections/collections.d.ts.map +1 -1
- package/resources/collections/collections.js +5 -1
- package/resources/collections/collections.js.map +1 -1
- package/resources/collections/collections.mjs +5 -1
- package/resources/collections/collections.mjs.map +1 -1
- package/resources/collections/index.d.mts +1 -1
- package/resources/collections/index.d.mts.map +1 -1
- package/resources/collections/index.d.ts +1 -1
- package/resources/collections/index.d.ts.map +1 -1
- package/resources/collections/index.js.map +1 -1
- package/resources/collections/index.mjs.map +1 -1
- package/resources/generate.d.mts +1027 -242
- package/resources/generate.d.mts.map +1 -1
- package/resources/generate.d.ts +1027 -242
- package/resources/generate.d.ts.map +1 -1
- package/resources/generate.js +7 -0
- package/resources/generate.js.map +1 -1
- package/resources/generate.mjs +7 -0
- package/resources/generate.mjs.map +1 -1
- package/resources/index.d.mts +8 -8
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +8 -8
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/jobs.d.mts +369 -380
- package/resources/jobs.d.mts.map +1 -1
- package/resources/jobs.d.ts +369 -380
- package/resources/jobs.d.ts.map +1 -1
- package/resources/jobs.js +2 -1
- package/resources/jobs.js.map +1 -1
- package/resources/jobs.mjs +2 -1
- package/resources/jobs.mjs.map +1 -1
- package/resources/models/description.d.mts +2 -2
- package/resources/models/description.d.mts.map +1 -1
- package/resources/models/description.d.ts +2 -2
- package/resources/models/description.d.ts.map +1 -1
- package/resources/models/examples.d.mts +4 -4
- package/resources/models/examples.d.mts.map +1 -1
- package/resources/models/examples.d.ts +4 -4
- package/resources/models/examples.d.ts.map +1 -1
- package/resources/models/index.d.mts +1 -1
- package/resources/models/index.d.mts.map +1 -1
- package/resources/models/index.d.ts +1 -1
- package/resources/models/index.d.ts.map +1 -1
- package/resources/models/index.js.map +1 -1
- package/resources/models/index.mjs.map +1 -1
- package/resources/models/models.d.mts +845 -856
- package/resources/models/models.d.mts.map +1 -1
- package/resources/models/models.d.ts +845 -856
- package/resources/models/models.d.ts.map +1 -1
- package/resources/models/models.js +2 -1
- package/resources/models/models.js.map +1 -1
- package/resources/models/models.mjs +2 -1
- package/resources/models/models.mjs.map +1 -1
- package/resources/models/train.d.mts +2 -2
- package/resources/models/train.d.mts.map +1 -1
- package/resources/models/train.d.ts +2 -2
- package/resources/models/train.d.ts.map +1 -1
- package/resources/search.d.mts +215 -295
- package/resources/search.d.mts.map +1 -1
- package/resources/search.d.ts +215 -295
- package/resources/search.d.ts.map +1 -1
- package/resources/search.js +9 -2
- package/resources/search.js.map +1 -1
- package/resources/search.mjs +9 -2
- package/resources/search.mjs.map +1 -1
- package/resources/tags.d.mts +23 -35
- package/resources/tags.d.mts.map +1 -1
- package/resources/tags.d.ts +23 -35
- package/resources/tags.d.ts.map +1 -1
- package/resources/tags.js +2 -1
- package/resources/tags.js.map +1 -1
- package/resources/tags.mjs +2 -1
- package/resources/tags.mjs.map +1 -1
- package/resources/usages.d.mts +3 -3
- package/resources/usages.d.mts.map +1 -1
- package/resources/usages.d.ts +3 -3
- package/resources/usages.d.ts.map +1 -1
- package/resources/workflows.d.mts +688 -704
- package/resources/workflows.d.mts.map +1 -1
- package/resources/workflows.d.ts +688 -704
- package/resources/workflows.d.ts.map +1 -1
- package/resources/workflows.js +5 -1
- package/resources/workflows.js.map +1 -1
- package/resources/workflows.mjs +5 -1
- package/resources/workflows.mjs.map +1 -1
- package/src/client.ts +107 -2
- package/src/core/pagination.ts +497 -0
- package/src/index.ts +11 -1
- package/src/lib/asset.ts +85 -0
- package/src/lib/job.ts +28 -1
- package/src/lib/models.ts +62 -2
- package/src/lib/scenario.ts +14 -0
- package/src/lib/upload.ts +344 -0
- package/src/lib/workflow.ts +29 -4
- package/src/lib/workflow_import_validator.ts +104 -0
- package/src/pagination.ts +2 -0
- package/src/resources/assets/assets.ts +930 -909
- package/src/resources/assets/index.ts +2 -0
- package/src/resources/assets/public.ts +17 -7
- package/src/resources/collections/collections.ts +45 -54
- package/src/resources/collections/index.ts +1 -0
- package/src/resources/generate.ts +1227 -136
- package/src/resources/index.ts +11 -1
- package/src/resources/jobs.ts +613 -622
- package/src/resources/models/description.ts +4 -0
- package/src/resources/models/examples.ts +8 -0
- package/src/resources/models/index.ts +1 -0
- package/src/resources/models/models.ts +1066 -1064
- package/src/resources/models/train.ts +4 -0
- package/src/resources/search.ts +239 -327
- package/src/resources/tags.ts +32 -39
- package/src/resources/usages.ts +5 -0
- package/src/resources/workflows.ts +850 -864
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { ScenarioError } from './error';
|
|
4
|
+
import { FinalRequestOptions } from '../internal/request-options';
|
|
5
|
+
import { defaultParseResponse } from '../internal/parse';
|
|
6
|
+
import { type Scenario } from '../client';
|
|
7
|
+
import { APIPromise } from './api-promise';
|
|
8
|
+
import { type APIResponseProps } from '../internal/parse';
|
|
9
|
+
import { maybeObj } from '../internal/utils/values';
|
|
10
|
+
|
|
11
|
+
export type PageRequestOptions = Pick<FinalRequestOptions, 'query' | 'headers' | 'body' | 'path' | 'method'>;
|
|
12
|
+
|
|
13
|
+
export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
|
|
14
|
+
#client: Scenario;
|
|
15
|
+
protected options: FinalRequestOptions;
|
|
16
|
+
|
|
17
|
+
protected response: Response;
|
|
18
|
+
protected body: unknown;
|
|
19
|
+
|
|
20
|
+
constructor(client: Scenario, response: Response, body: unknown, options: FinalRequestOptions) {
|
|
21
|
+
this.#client = client;
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.response = response;
|
|
24
|
+
this.body = body;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
abstract nextPageRequestOptions(): PageRequestOptions | null;
|
|
28
|
+
|
|
29
|
+
abstract getPaginatedItems(): Item[];
|
|
30
|
+
|
|
31
|
+
hasNextPage(): boolean {
|
|
32
|
+
const items = this.getPaginatedItems();
|
|
33
|
+
if (!items.length) return false;
|
|
34
|
+
return this.nextPageRequestOptions() != null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async getNextPage(): Promise<this> {
|
|
38
|
+
const nextOptions = this.nextPageRequestOptions();
|
|
39
|
+
if (!nextOptions) {
|
|
40
|
+
throw new ScenarioError(
|
|
41
|
+
'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.',
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return await this.#client.requestAPIList(this.constructor as any, nextOptions);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async *iterPages(): AsyncGenerator<this> {
|
|
49
|
+
let page: this = this;
|
|
50
|
+
yield page;
|
|
51
|
+
while (page.hasNextPage()) {
|
|
52
|
+
page = await page.getNextPage();
|
|
53
|
+
yield page;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
|
|
58
|
+
for await (const page of this.iterPages()) {
|
|
59
|
+
for (const item of page.getPaginatedItems()) {
|
|
60
|
+
yield item;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* This subclass of Promise will resolve to an instantiated Page once the request completes.
|
|
68
|
+
*
|
|
69
|
+
* It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg:
|
|
70
|
+
*
|
|
71
|
+
* for await (const item of client.items.list()) {
|
|
72
|
+
* console.log(item)
|
|
73
|
+
* }
|
|
74
|
+
*/
|
|
75
|
+
export class PagePromise<
|
|
76
|
+
PageClass extends AbstractPage<Item>,
|
|
77
|
+
Item = ReturnType<PageClass['getPaginatedItems']>[number],
|
|
78
|
+
>
|
|
79
|
+
extends APIPromise<PageClass>
|
|
80
|
+
implements AsyncIterable<Item>
|
|
81
|
+
{
|
|
82
|
+
constructor(
|
|
83
|
+
client: Scenario,
|
|
84
|
+
request: Promise<APIResponseProps>,
|
|
85
|
+
Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass,
|
|
86
|
+
) {
|
|
87
|
+
super(
|
|
88
|
+
client,
|
|
89
|
+
request,
|
|
90
|
+
async (client, props) =>
|
|
91
|
+
new Page(client, props.response, await defaultParseResponse(client, props), props.options),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Allow auto-paginating iteration on an unawaited list call, eg:
|
|
97
|
+
*
|
|
98
|
+
* for await (const item of client.items.list()) {
|
|
99
|
+
* console.log(item)
|
|
100
|
+
* }
|
|
101
|
+
*/
|
|
102
|
+
async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
|
|
103
|
+
const page = await this;
|
|
104
|
+
for await (const item of page) {
|
|
105
|
+
yield item;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface AssetsCursorResponse<Item> {
|
|
111
|
+
assets: Array<Item>;
|
|
112
|
+
|
|
113
|
+
nextPaginationToken: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface AssetsCursorParams {
|
|
117
|
+
paginationToken?: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export class AssetsCursor<Item> extends AbstractPage<Item> implements AssetsCursorResponse<Item> {
|
|
121
|
+
assets: Array<Item>;
|
|
122
|
+
|
|
123
|
+
nextPaginationToken: string;
|
|
124
|
+
|
|
125
|
+
constructor(
|
|
126
|
+
client: Scenario,
|
|
127
|
+
response: Response,
|
|
128
|
+
body: AssetsCursorResponse<Item>,
|
|
129
|
+
options: FinalRequestOptions,
|
|
130
|
+
) {
|
|
131
|
+
super(client, response, body, options);
|
|
132
|
+
|
|
133
|
+
this.assets = body.assets || [];
|
|
134
|
+
this.nextPaginationToken = body.nextPaginationToken || '';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
getPaginatedItems(): Item[] {
|
|
138
|
+
return this.assets ?? [];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
142
|
+
const cursor = this.nextPaginationToken;
|
|
143
|
+
if (!cursor) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
...this.options,
|
|
149
|
+
query: {
|
|
150
|
+
...maybeObj(this.options.query),
|
|
151
|
+
paginationToken: cursor,
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface SnapshotsCursorResponse<Item> {
|
|
158
|
+
snapshots: Array<Item>;
|
|
159
|
+
|
|
160
|
+
nextPaginationToken: string;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export interface SnapshotsCursorParams {
|
|
164
|
+
paginationToken?: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export class SnapshotsCursor<Item> extends AbstractPage<Item> implements SnapshotsCursorResponse<Item> {
|
|
168
|
+
snapshots: Array<Item>;
|
|
169
|
+
|
|
170
|
+
nextPaginationToken: string;
|
|
171
|
+
|
|
172
|
+
constructor(
|
|
173
|
+
client: Scenario,
|
|
174
|
+
response: Response,
|
|
175
|
+
body: SnapshotsCursorResponse<Item>,
|
|
176
|
+
options: FinalRequestOptions,
|
|
177
|
+
) {
|
|
178
|
+
super(client, response, body, options);
|
|
179
|
+
|
|
180
|
+
this.snapshots = body.snapshots || [];
|
|
181
|
+
this.nextPaginationToken = body.nextPaginationToken || '';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
getPaginatedItems(): Item[] {
|
|
185
|
+
return this.snapshots ?? [];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
189
|
+
const cursor = this.nextPaginationToken;
|
|
190
|
+
if (!cursor) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
...this.options,
|
|
196
|
+
query: {
|
|
197
|
+
...maybeObj(this.options.query),
|
|
198
|
+
paginationToken: cursor,
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface CollectionsCursorResponse<Item> {
|
|
205
|
+
collections: Array<Item>;
|
|
206
|
+
|
|
207
|
+
nextPaginationToken: string;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export interface CollectionsCursorParams {
|
|
211
|
+
paginationToken?: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export class CollectionsCursor<Item> extends AbstractPage<Item> implements CollectionsCursorResponse<Item> {
|
|
215
|
+
collections: Array<Item>;
|
|
216
|
+
|
|
217
|
+
nextPaginationToken: string;
|
|
218
|
+
|
|
219
|
+
constructor(
|
|
220
|
+
client: Scenario,
|
|
221
|
+
response: Response,
|
|
222
|
+
body: CollectionsCursorResponse<Item>,
|
|
223
|
+
options: FinalRequestOptions,
|
|
224
|
+
) {
|
|
225
|
+
super(client, response, body, options);
|
|
226
|
+
|
|
227
|
+
this.collections = body.collections || [];
|
|
228
|
+
this.nextPaginationToken = body.nextPaginationToken || '';
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
getPaginatedItems(): Item[] {
|
|
232
|
+
return this.collections ?? [];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
236
|
+
const cursor = this.nextPaginationToken;
|
|
237
|
+
if (!cursor) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return {
|
|
242
|
+
...this.options,
|
|
243
|
+
query: {
|
|
244
|
+
...maybeObj(this.options.query),
|
|
245
|
+
paginationToken: cursor,
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export interface JobsCursorResponse<Item> {
|
|
252
|
+
jobs: Array<Item>;
|
|
253
|
+
|
|
254
|
+
nextPaginationToken: string;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface JobsCursorParams {
|
|
258
|
+
paginationToken?: string;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export class JobsCursor<Item> extends AbstractPage<Item> implements JobsCursorResponse<Item> {
|
|
262
|
+
jobs: Array<Item>;
|
|
263
|
+
|
|
264
|
+
nextPaginationToken: string;
|
|
265
|
+
|
|
266
|
+
constructor(
|
|
267
|
+
client: Scenario,
|
|
268
|
+
response: Response,
|
|
269
|
+
body: JobsCursorResponse<Item>,
|
|
270
|
+
options: FinalRequestOptions,
|
|
271
|
+
) {
|
|
272
|
+
super(client, response, body, options);
|
|
273
|
+
|
|
274
|
+
this.jobs = body.jobs || [];
|
|
275
|
+
this.nextPaginationToken = body.nextPaginationToken || '';
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
getPaginatedItems(): Item[] {
|
|
279
|
+
return this.jobs ?? [];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
283
|
+
const cursor = this.nextPaginationToken;
|
|
284
|
+
if (!cursor) {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return {
|
|
289
|
+
...this.options,
|
|
290
|
+
query: {
|
|
291
|
+
...maybeObj(this.options.query),
|
|
292
|
+
paginationToken: cursor,
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export interface ModelsCursorResponse<Item> {
|
|
299
|
+
models: Array<Item>;
|
|
300
|
+
|
|
301
|
+
nextPaginationToken: string;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface ModelsCursorParams {
|
|
305
|
+
paginationToken?: string;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export class ModelsCursor<Item> extends AbstractPage<Item> implements ModelsCursorResponse<Item> {
|
|
309
|
+
models: Array<Item>;
|
|
310
|
+
|
|
311
|
+
nextPaginationToken: string;
|
|
312
|
+
|
|
313
|
+
constructor(
|
|
314
|
+
client: Scenario,
|
|
315
|
+
response: Response,
|
|
316
|
+
body: ModelsCursorResponse<Item>,
|
|
317
|
+
options: FinalRequestOptions,
|
|
318
|
+
) {
|
|
319
|
+
super(client, response, body, options);
|
|
320
|
+
|
|
321
|
+
this.models = body.models || [];
|
|
322
|
+
this.nextPaginationToken = body.nextPaginationToken || '';
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
getPaginatedItems(): Item[] {
|
|
326
|
+
return this.models ?? [];
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
330
|
+
const cursor = this.nextPaginationToken;
|
|
331
|
+
if (!cursor) {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return {
|
|
336
|
+
...this.options,
|
|
337
|
+
query: {
|
|
338
|
+
...maybeObj(this.options.query),
|
|
339
|
+
paginationToken: cursor,
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export interface TagsCursorResponse<Item> {
|
|
346
|
+
tags: Array<Item>;
|
|
347
|
+
|
|
348
|
+
nextPaginationToken: string;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export interface TagsCursorParams {
|
|
352
|
+
paginationToken?: string;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export class TagsCursor<Item> extends AbstractPage<Item> implements TagsCursorResponse<Item> {
|
|
356
|
+
tags: Array<Item>;
|
|
357
|
+
|
|
358
|
+
nextPaginationToken: string;
|
|
359
|
+
|
|
360
|
+
constructor(
|
|
361
|
+
client: Scenario,
|
|
362
|
+
response: Response,
|
|
363
|
+
body: TagsCursorResponse<Item>,
|
|
364
|
+
options: FinalRequestOptions,
|
|
365
|
+
) {
|
|
366
|
+
super(client, response, body, options);
|
|
367
|
+
|
|
368
|
+
this.tags = body.tags || [];
|
|
369
|
+
this.nextPaginationToken = body.nextPaginationToken || '';
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
getPaginatedItems(): Item[] {
|
|
373
|
+
return this.tags ?? [];
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
377
|
+
const cursor = this.nextPaginationToken;
|
|
378
|
+
if (!cursor) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return {
|
|
383
|
+
...this.options,
|
|
384
|
+
query: {
|
|
385
|
+
...maybeObj(this.options.query),
|
|
386
|
+
paginationToken: cursor,
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export interface WorkflowsCursorResponse<Item> {
|
|
393
|
+
workflows: Array<Item>;
|
|
394
|
+
|
|
395
|
+
nextPaginationToken: string;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export interface WorkflowsCursorParams {
|
|
399
|
+
paginationToken?: string;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export class WorkflowsCursor<Item> extends AbstractPage<Item> implements WorkflowsCursorResponse<Item> {
|
|
403
|
+
workflows: Array<Item>;
|
|
404
|
+
|
|
405
|
+
nextPaginationToken: string;
|
|
406
|
+
|
|
407
|
+
constructor(
|
|
408
|
+
client: Scenario,
|
|
409
|
+
response: Response,
|
|
410
|
+
body: WorkflowsCursorResponse<Item>,
|
|
411
|
+
options: FinalRequestOptions,
|
|
412
|
+
) {
|
|
413
|
+
super(client, response, body, options);
|
|
414
|
+
|
|
415
|
+
this.workflows = body.workflows || [];
|
|
416
|
+
this.nextPaginationToken = body.nextPaginationToken || '';
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
getPaginatedItems(): Item[] {
|
|
420
|
+
return this.workflows ?? [];
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
424
|
+
const cursor = this.nextPaginationToken;
|
|
425
|
+
if (!cursor) {
|
|
426
|
+
return null;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return {
|
|
430
|
+
...this.options,
|
|
431
|
+
query: {
|
|
432
|
+
...maybeObj(this.options.query),
|
|
433
|
+
paginationToken: cursor,
|
|
434
|
+
},
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export interface SearchHitsOffsetResponse<Item> {
|
|
440
|
+
hits: Array<Item>;
|
|
441
|
+
|
|
442
|
+
estimatedTotalHits: number;
|
|
443
|
+
|
|
444
|
+
offset: number;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export interface SearchHitsOffsetParams {
|
|
448
|
+
offset?: number;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export class SearchHitsOffset<Item> extends AbstractPage<Item> implements SearchHitsOffsetResponse<Item> {
|
|
452
|
+
hits: Array<Item>;
|
|
453
|
+
|
|
454
|
+
estimatedTotalHits: number;
|
|
455
|
+
|
|
456
|
+
offset: number;
|
|
457
|
+
|
|
458
|
+
constructor(
|
|
459
|
+
client: Scenario,
|
|
460
|
+
response: Response,
|
|
461
|
+
body: SearchHitsOffsetResponse<Item>,
|
|
462
|
+
options: FinalRequestOptions,
|
|
463
|
+
) {
|
|
464
|
+
super(client, response, body, options);
|
|
465
|
+
|
|
466
|
+
this.hits = body.hits || [];
|
|
467
|
+
this.estimatedTotalHits = body.estimatedTotalHits || 0;
|
|
468
|
+
this.offset = body.offset || 0;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
getPaginatedItems(): Item[] {
|
|
472
|
+
return this.hits ?? [];
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
476
|
+
const offset = this.offset ?? 0;
|
|
477
|
+
const length = this.getPaginatedItems().length;
|
|
478
|
+
const currentCount = offset + length;
|
|
479
|
+
|
|
480
|
+
const totalCount = this.estimatedTotalHits;
|
|
481
|
+
if (!totalCount) {
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if (currentCount < totalCount) {
|
|
486
|
+
return {
|
|
487
|
+
...this.options,
|
|
488
|
+
body: {
|
|
489
|
+
...maybeObj(this.options.body),
|
|
490
|
+
offset: currentCount,
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return null;
|
|
496
|
+
}
|
|
497
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { type Uploadable, toFile } from './core/uploads';
|
|
|
6
6
|
export { APIPromise } from './core/api-promise';
|
|
7
7
|
export { Scenario } from './lib/scenario';
|
|
8
8
|
export { type ClientOptions } from './client';
|
|
9
|
+
export { PagePromise } from './core/pagination';
|
|
9
10
|
export {
|
|
10
11
|
ScenarioError,
|
|
11
12
|
APIError,
|
|
@@ -21,8 +22,17 @@ export {
|
|
|
21
22
|
PermissionDeniedError,
|
|
22
23
|
UnprocessableEntityError,
|
|
23
24
|
} from './core/error';
|
|
24
|
-
export { Job, type WaitOptions, type WithJob } from './lib/job';
|
|
25
|
+
export { EnhancedJobs, Job, type WaitOptions, type WithJob } from './lib/job';
|
|
25
26
|
export { EnhancedWorkflows, WorkflowEntity } from './lib/workflow';
|
|
26
27
|
export { validateWorkflowFlow } from './lib/workflow_validator';
|
|
28
|
+
export {
|
|
29
|
+
validateEditorInfo,
|
|
30
|
+
WorkflowImportError,
|
|
31
|
+
VALID_EDITOR_NODE_TYPES,
|
|
32
|
+
type WorkflowExportData,
|
|
33
|
+
type WorkflowEditorNodeType,
|
|
34
|
+
} from './lib/workflow_import_validator';
|
|
27
35
|
export { EnhancedGenerate } from './lib/generate';
|
|
28
36
|
export { EnhancedModels, EnhancedTrain } from './lib/models';
|
|
37
|
+
export { EnhancedUploads, Upload, type UploadWaitOptions, type WithUpload } from './lib/upload';
|
|
38
|
+
export { EnhancedAssets, Asset, type WithAsset } from './lib/asset';
|
package/src/lib/asset.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { APIPromise } from '../core/api-promise';
|
|
2
|
+
import type { RequestOptions } from '../internal/request-options';
|
|
3
|
+
import {
|
|
4
|
+
Assets,
|
|
5
|
+
type AssetRetrieveParams,
|
|
6
|
+
type AssetRetrieveResponse,
|
|
7
|
+
type AssetUpdateParams,
|
|
8
|
+
type AssetUpdateResponse,
|
|
9
|
+
} from '../resources/assets/assets';
|
|
10
|
+
|
|
11
|
+
/** Asset methods added on top of the original asset fields. */
|
|
12
|
+
export class AssetMethods {
|
|
13
|
+
/**
|
|
14
|
+
* Fetch the asset's content as bytes, using the signed `url` field on the
|
|
15
|
+
* asset. Works in Node ≥18 and in browsers with no extra setup.
|
|
16
|
+
*
|
|
17
|
+
* This is a thin wrapper around `fetch(asset.url)` — use `asset.url`
|
|
18
|
+
* directly if you need streaming or a Response object.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const res = await client.assets.retrieve(assetId);
|
|
23
|
+
* const bytes = await res.asset.download();
|
|
24
|
+
* await fs.writeFile('out.png', bytes);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
async download(this: Asset): Promise<Uint8Array> {
|
|
28
|
+
const res = await fetch(this.url);
|
|
29
|
+
if (!res.ok) {
|
|
30
|
+
throw new Error(`Failed to download asset ${this.id}: ${res.status} ${res.statusText}`);
|
|
31
|
+
}
|
|
32
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** @internal Create an Asset from raw asset data. */
|
|
36
|
+
static from(data: AssetRetrieveResponse['asset']): Asset {
|
|
37
|
+
return Object.assign(Object.create(AssetMethods.prototype), data) as Asset;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** An asset with all original fields plus `.download()`. */
|
|
42
|
+
export type Asset = AssetRetrieveResponse.Asset & AssetMethods;
|
|
43
|
+
export const Asset = AssetMethods;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @internal Helper type: adds `.download()` to the `asset` field of a response.
|
|
47
|
+
* Uses intersection so the original response type is preserved — a `WithAsset<T>` is still assignable to `T`.
|
|
48
|
+
*/
|
|
49
|
+
export type WithAsset<T extends { asset: unknown }> = T & { asset: AssetMethods };
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @internal Wrap `_thenUnwrap` to replace `response.asset` with an enhanced Asset.
|
|
53
|
+
*/
|
|
54
|
+
export function enhanceAsset<T extends { asset: { id: string; url: string } }>(
|
|
55
|
+
promise: APIPromise<T>,
|
|
56
|
+
): APIPromise<WithAsset<T>> {
|
|
57
|
+
return promise._thenUnwrap((data) => ({
|
|
58
|
+
...data,
|
|
59
|
+
asset: Asset.from(data.asset as AssetRetrieveResponse['asset']),
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Enhanced Assets resource.
|
|
65
|
+
* All original methods (and subresources like `download`, `public`) are
|
|
66
|
+
* inherited. `retrieve` and `update` responses' `asset` field gains a
|
|
67
|
+
* `.download()` helper for fetching the asset's bytes.
|
|
68
|
+
*/
|
|
69
|
+
export class EnhancedAssets extends Assets {
|
|
70
|
+
override retrieve(
|
|
71
|
+
assetID: string,
|
|
72
|
+
query: AssetRetrieveParams | null | undefined = {},
|
|
73
|
+
options?: RequestOptions,
|
|
74
|
+
): APIPromise<WithAsset<AssetRetrieveResponse>> {
|
|
75
|
+
return enhanceAsset(super.retrieve(assetID, query, options));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
override update(
|
|
79
|
+
assetID: string,
|
|
80
|
+
params: AssetUpdateParams,
|
|
81
|
+
options?: RequestOptions,
|
|
82
|
+
): APIPromise<WithAsset<AssetUpdateResponse>> {
|
|
83
|
+
return enhanceAsset(super.update(assetID, params, options));
|
|
84
|
+
}
|
|
85
|
+
}
|
package/src/lib/job.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { Scenario } from '../client';
|
|
2
2
|
import type { APIPromise } from '../core/api-promise';
|
|
3
|
-
import type {
|
|
3
|
+
import type { RequestOptions } from '../internal/request-options';
|
|
4
|
+
import {
|
|
5
|
+
Jobs,
|
|
6
|
+
type JobRetrieveResponse,
|
|
7
|
+
type JobTriggerActionParams,
|
|
8
|
+
type JobTriggerActionResponse,
|
|
9
|
+
} from '../resources/jobs';
|
|
4
10
|
|
|
5
11
|
export interface WaitOptions {
|
|
6
12
|
/** Polling interval in milliseconds. Default: 3000 */
|
|
@@ -76,3 +82,24 @@ export function enhanceJob<T extends { job: { jobId: string; status: string } }>
|
|
|
76
82
|
job: Job.from(client, data.job as JobRetrieveResponse['job']),
|
|
77
83
|
}));
|
|
78
84
|
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Enhanced Jobs resource. `retrieve` and `triggerAction` responses' `job`
|
|
88
|
+
* field gains a `.wait()` helper — previously only job-creating endpoints
|
|
89
|
+
* (workflow.run, models.trigger, generate.*) had it. `list` is not enhanced:
|
|
90
|
+
* its items use a different (but structurally similar) type, and users
|
|
91
|
+
* typically fetch individual jobs via `retrieve` before acting on them.
|
|
92
|
+
*/
|
|
93
|
+
export class EnhancedJobs extends Jobs {
|
|
94
|
+
override retrieve(jobID: string, options?: RequestOptions): APIPromise<WithJob<JobRetrieveResponse>> {
|
|
95
|
+
return enhanceJob(this._client, super.retrieve(jobID, options));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
override triggerAction(
|
|
99
|
+
jobID: string,
|
|
100
|
+
params: JobTriggerActionParams,
|
|
101
|
+
options?: RequestOptions,
|
|
102
|
+
): APIPromise<WithJob<JobTriggerActionResponse>> {
|
|
103
|
+
return enhanceJob(this._client, super.triggerAction(jobID, params, options));
|
|
104
|
+
}
|
|
105
|
+
}
|