@scenario-labs/sdk 0.3.0 → 1.0.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.
Files changed (180) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +40 -6
  3. package/client.d.mts +34 -14
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +34 -14
  6. package/client.d.ts.map +1 -1
  7. package/client.js +10 -0
  8. package/client.js.map +1 -1
  9. package/client.mjs +10 -0
  10. package/client.mjs.map +1 -1
  11. package/core/pagination.d.mts +153 -0
  12. package/core/pagination.d.mts.map +1 -0
  13. package/core/pagination.d.ts +153 -0
  14. package/core/pagination.d.ts.map +1 -0
  15. package/core/pagination.js +276 -0
  16. package/core/pagination.js.map +1 -0
  17. package/core/pagination.mjs +263 -0
  18. package/core/pagination.mjs.map +1 -0
  19. package/index.d.mts +2 -0
  20. package/index.d.mts.map +1 -1
  21. package/index.d.ts +2 -0
  22. package/index.d.ts.map +1 -1
  23. package/index.js +7 -1
  24. package/index.js.map +1 -1
  25. package/index.mjs +2 -0
  26. package/index.mjs.map +1 -1
  27. package/lib/models.d.mts +34 -2
  28. package/lib/models.d.mts.map +1 -1
  29. package/lib/models.d.ts +34 -2
  30. package/lib/models.d.ts.map +1 -1
  31. package/lib/models.js +39 -2
  32. package/lib/models.js.map +1 -1
  33. package/lib/models.mjs +37 -1
  34. package/lib/models.mjs.map +1 -1
  35. package/lib/scenario.d.mts +2 -0
  36. package/lib/scenario.d.mts.map +1 -1
  37. package/lib/scenario.d.ts +2 -0
  38. package/lib/scenario.d.ts.map +1 -1
  39. package/lib/scenario.js +2 -0
  40. package/lib/scenario.js.map +1 -1
  41. package/lib/scenario.mjs +2 -0
  42. package/lib/scenario.mjs.map +1 -1
  43. package/lib/upload.d.mts +89 -0
  44. package/lib/upload.d.mts.map +1 -0
  45. package/lib/upload.d.ts +89 -0
  46. package/lib/upload.d.ts.map +1 -0
  47. package/lib/upload.js +193 -0
  48. package/lib/upload.js.map +1 -0
  49. package/lib/upload.mjs +156 -0
  50. package/lib/upload.mjs.map +1 -0
  51. package/lib/workflow.d.mts +13 -2
  52. package/lib/workflow.d.mts.map +1 -1
  53. package/lib/workflow.d.ts +13 -2
  54. package/lib/workflow.d.ts.map +1 -1
  55. package/lib/workflow.js +17 -4
  56. package/lib/workflow.js.map +1 -1
  57. package/lib/workflow.mjs +17 -4
  58. package/lib/workflow.mjs.map +1 -1
  59. package/lib/workflow_import_validator.d.mts +40 -0
  60. package/lib/workflow_import_validator.d.mts.map +1 -0
  61. package/lib/workflow_import_validator.d.ts +40 -0
  62. package/lib/workflow_import_validator.d.ts.map +1 -0
  63. package/lib/workflow_import_validator.js +69 -0
  64. package/lib/workflow_import_validator.js.map +1 -0
  65. package/lib/workflow_import_validator.mjs +64 -0
  66. package/lib/workflow_import_validator.mjs.map +1 -0
  67. package/package.json +11 -1
  68. package/pagination.d.mts +2 -0
  69. package/pagination.d.mts.map +1 -0
  70. package/pagination.d.ts +2 -0
  71. package/pagination.d.ts.map +1 -0
  72. package/pagination.js +6 -0
  73. package/pagination.js.map +1 -0
  74. package/pagination.mjs +2 -0
  75. package/pagination.mjs.map +1 -0
  76. package/resources/assets/assets.d.mts +623 -646
  77. package/resources/assets/assets.d.mts.map +1 -1
  78. package/resources/assets/assets.d.ts +623 -646
  79. package/resources/assets/assets.d.ts.map +1 -1
  80. package/resources/assets/assets.js +3 -2
  81. package/resources/assets/assets.js.map +1 -1
  82. package/resources/assets/assets.mjs +3 -2
  83. package/resources/assets/assets.mjs.map +1 -1
  84. package/resources/assets/index.d.mts +1 -1
  85. package/resources/assets/index.d.mts.map +1 -1
  86. package/resources/assets/index.d.ts +1 -1
  87. package/resources/assets/index.d.ts.map +1 -1
  88. package/resources/assets/index.js.map +1 -1
  89. package/resources/assets/index.mjs.map +1 -1
  90. package/resources/collections/collections.d.mts +38 -49
  91. package/resources/collections/collections.d.mts.map +1 -1
  92. package/resources/collections/collections.d.ts +38 -49
  93. package/resources/collections/collections.d.ts.map +1 -1
  94. package/resources/collections/collections.js +5 -1
  95. package/resources/collections/collections.js.map +1 -1
  96. package/resources/collections/collections.mjs +5 -1
  97. package/resources/collections/collections.mjs.map +1 -1
  98. package/resources/collections/index.d.mts +1 -1
  99. package/resources/collections/index.d.mts.map +1 -1
  100. package/resources/collections/index.d.ts +1 -1
  101. package/resources/collections/index.d.ts.map +1 -1
  102. package/resources/collections/index.js.map +1 -1
  103. package/resources/collections/index.mjs.map +1 -1
  104. package/resources/index.d.mts +7 -7
  105. package/resources/index.d.mts.map +1 -1
  106. package/resources/index.d.ts +7 -7
  107. package/resources/index.d.ts.map +1 -1
  108. package/resources/index.js.map +1 -1
  109. package/resources/index.mjs.map +1 -1
  110. package/resources/jobs.d.mts +369 -380
  111. package/resources/jobs.d.mts.map +1 -1
  112. package/resources/jobs.d.ts +369 -380
  113. package/resources/jobs.d.ts.map +1 -1
  114. package/resources/jobs.js +2 -1
  115. package/resources/jobs.js.map +1 -1
  116. package/resources/jobs.mjs +2 -1
  117. package/resources/jobs.mjs.map +1 -1
  118. package/resources/models/index.d.mts +1 -1
  119. package/resources/models/index.d.mts.map +1 -1
  120. package/resources/models/index.d.ts +1 -1
  121. package/resources/models/index.d.ts.map +1 -1
  122. package/resources/models/index.js.map +1 -1
  123. package/resources/models/index.mjs.map +1 -1
  124. package/resources/models/models.d.mts +839 -850
  125. package/resources/models/models.d.mts.map +1 -1
  126. package/resources/models/models.d.ts +839 -850
  127. package/resources/models/models.d.ts.map +1 -1
  128. package/resources/models/models.js +2 -1
  129. package/resources/models/models.js.map +1 -1
  130. package/resources/models/models.mjs +2 -1
  131. package/resources/models/models.mjs.map +1 -1
  132. package/resources/search.d.mts +215 -295
  133. package/resources/search.d.mts.map +1 -1
  134. package/resources/search.d.ts +215 -295
  135. package/resources/search.d.ts.map +1 -1
  136. package/resources/search.js +9 -2
  137. package/resources/search.js.map +1 -1
  138. package/resources/search.mjs +9 -2
  139. package/resources/search.mjs.map +1 -1
  140. package/resources/tags.d.mts +23 -35
  141. package/resources/tags.d.mts.map +1 -1
  142. package/resources/tags.d.ts +23 -35
  143. package/resources/tags.d.ts.map +1 -1
  144. package/resources/tags.js +2 -1
  145. package/resources/tags.js.map +1 -1
  146. package/resources/tags.mjs +2 -1
  147. package/resources/tags.mjs.map +1 -1
  148. package/resources/workflows.d.mts +688 -704
  149. package/resources/workflows.d.mts.map +1 -1
  150. package/resources/workflows.d.ts +688 -704
  151. package/resources/workflows.d.ts.map +1 -1
  152. package/resources/workflows.js +5 -1
  153. package/resources/workflows.js.map +1 -1
  154. package/resources/workflows.mjs +5 -1
  155. package/resources/workflows.mjs.map +1 -1
  156. package/src/client.ts +103 -2
  157. package/src/core/pagination.ts +497 -0
  158. package/src/index.ts +8 -0
  159. package/src/lib/models.ts +62 -2
  160. package/src/lib/scenario.ts +2 -0
  161. package/src/lib/upload.ts +250 -0
  162. package/src/lib/workflow.ts +29 -4
  163. package/src/lib/workflow_import_validator.ts +104 -0
  164. package/src/pagination.ts +2 -0
  165. package/src/resources/assets/assets.ts +887 -902
  166. package/src/resources/assets/index.ts +2 -0
  167. package/src/resources/collections/collections.ts +45 -54
  168. package/src/resources/collections/index.ts +1 -0
  169. package/src/resources/index.ts +9 -1
  170. package/src/resources/jobs.ts +613 -622
  171. package/src/resources/models/index.ts +1 -0
  172. package/src/resources/models/models.ts +1052 -1064
  173. package/src/resources/search.ts +239 -327
  174. package/src/resources/tags.ts +32 -39
  175. package/src/resources/workflows.ts +850 -864
  176. package/src/version.ts +1 -1
  177. package/version.d.mts +1 -1
  178. package/version.d.ts +1 -1
  179. package/version.js +1 -1
  180. package/version.mjs +1 -1
package/src/client.ts CHANGED
@@ -14,6 +14,26 @@ import * as Opts from './internal/request-options';
14
14
  import { stringifyQuery } from './internal/utils/query';
15
15
  import { VERSION } from './version';
16
16
  import * as Errors from './core/error';
17
+ import * as Pagination from './core/pagination';
18
+ import {
19
+ AbstractPage,
20
+ type AssetsCursorParams,
21
+ AssetsCursorResponse,
22
+ type CollectionsCursorParams,
23
+ CollectionsCursorResponse,
24
+ type JobsCursorParams,
25
+ JobsCursorResponse,
26
+ type ModelsCursorParams,
27
+ ModelsCursorResponse,
28
+ type SearchHitsOffsetParams,
29
+ SearchHitsOffsetResponse,
30
+ type SnapshotsCursorParams,
31
+ SnapshotsCursorResponse,
32
+ type TagsCursorParams,
33
+ TagsCursorResponse,
34
+ type WorkflowsCursorParams,
35
+ WorkflowsCursorResponse,
36
+ } from './core/pagination';
17
37
  import * as Uploads from './core/uploads';
18
38
  import * as API from './resources/index';
19
39
  import { APIPromise } from './core/api-promise';
@@ -37,6 +57,7 @@ import {
37
57
  import {
38
58
  JobListParams,
39
59
  JobListResponse,
60
+ JobListResponsesJobsCursor,
40
61
  JobRetrieveResponse,
41
62
  JobTriggerActionParams,
42
63
  JobTriggerActionResponse,
@@ -47,10 +68,12 @@ import {
47
68
  Search,
48
69
  SearchAssetSearchParams,
49
70
  SearchAssetSearchResponse,
71
+ SearchAssetSearchResponsesSearchHitsOffset,
50
72
  SearchModelSearchParams,
51
73
  SearchModelSearchResponse,
74
+ SearchModelSearchResponsesSearchHitsOffset,
52
75
  } from './resources/search';
53
- import { TagListParams, TagListResponse, Tags } from './resources/tags';
76
+ import { TagListParams, TagListResponse, TagListResponsesTagsCursor, Tags } from './resources/tags';
54
77
  import {
55
78
  UploadCreateParams,
56
79
  UploadCreateResponse,
@@ -70,6 +93,7 @@ import {
70
93
  WorkflowGetTagsResponse,
71
94
  WorkflowListParams,
72
95
  WorkflowListResponse,
96
+ WorkflowListResponsesWorkflowsCursor,
73
97
  WorkflowRetrieveResponse,
74
98
  WorkflowRunParams,
75
99
  WorkflowRunResponse,
@@ -86,8 +110,10 @@ import {
86
110
  AssetGetBulkResponse,
87
111
  AssetListParams,
88
112
  AssetListResponse,
113
+ AssetListResponsesAssetsCursor,
89
114
  AssetListSnapshotsParams,
90
115
  AssetListSnapshotsResponse,
116
+ AssetListSnapshotsResponsesSnapshotsCursor,
91
117
  AssetLockParams,
92
118
  AssetLockResponse,
93
119
  AssetRetrieveParams,
@@ -108,6 +134,7 @@ import {
108
134
  CollectionDeleteResponse,
109
135
  CollectionListParams,
110
136
  CollectionListResponse,
137
+ CollectionListResponsesCollectionsCursor,
111
138
  CollectionRetrieveResponse,
112
139
  CollectionUpdateParams,
113
140
  CollectionUpdateResponse,
@@ -127,6 +154,7 @@ import {
127
154
  ModelGetBulkResponse,
128
155
  ModelListParams,
129
156
  ModelListResponse,
157
+ ModelListResponsesModelsCursor,
130
158
  ModelRetrieveParams,
131
159
  ModelRetrieveResponse,
132
160
  ModelTransferParams,
@@ -647,6 +675,30 @@ export class Scenario {
647
675
  return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
648
676
  }
649
677
 
678
+ getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(
679
+ path: string,
680
+ Page: new (...args: any[]) => PageClass,
681
+ opts?: PromiseOrValue<RequestOptions>,
682
+ ): Pagination.PagePromise<PageClass, Item> {
683
+ return this.requestAPIList(
684
+ Page,
685
+ opts && 'then' in opts ?
686
+ opts.then((opts) => ({ method: 'get', path, ...opts }))
687
+ : { method: 'get', path, ...opts },
688
+ );
689
+ }
690
+
691
+ requestAPIList<
692
+ Item = unknown,
693
+ PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,
694
+ >(
695
+ Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,
696
+ options: PromiseOrValue<FinalRequestOptions>,
697
+ ): Pagination.PagePromise<PageClass, Item> {
698
+ const request = this.makeRequest(options, null, undefined);
699
+ return new Pagination.PagePromise<PageClass, Item>(this as any as Scenario, request, Page);
700
+ }
701
+
650
702
  async fetchWithTimeout(
651
703
  url: RequestInfo,
652
704
  init: RequestInit | undefined,
@@ -922,6 +974,42 @@ Scenario.Workflows = Workflows;
922
974
  export declare namespace Scenario {
923
975
  export type RequestOptions = Opts.RequestOptions;
924
976
 
977
+ export import AssetsCursor = Pagination.AssetsCursor;
978
+ export { type AssetsCursorParams as AssetsCursorParams, type AssetsCursorResponse as AssetsCursorResponse };
979
+
980
+ export import SnapshotsCursor = Pagination.SnapshotsCursor;
981
+ export {
982
+ type SnapshotsCursorParams as SnapshotsCursorParams,
983
+ type SnapshotsCursorResponse as SnapshotsCursorResponse,
984
+ };
985
+
986
+ export import CollectionsCursor = Pagination.CollectionsCursor;
987
+ export {
988
+ type CollectionsCursorParams as CollectionsCursorParams,
989
+ type CollectionsCursorResponse as CollectionsCursorResponse,
990
+ };
991
+
992
+ export import JobsCursor = Pagination.JobsCursor;
993
+ export { type JobsCursorParams as JobsCursorParams, type JobsCursorResponse as JobsCursorResponse };
994
+
995
+ export import ModelsCursor = Pagination.ModelsCursor;
996
+ export { type ModelsCursorParams as ModelsCursorParams, type ModelsCursorResponse as ModelsCursorResponse };
997
+
998
+ export import TagsCursor = Pagination.TagsCursor;
999
+ export { type TagsCursorParams as TagsCursorParams, type TagsCursorResponse as TagsCursorResponse };
1000
+
1001
+ export import WorkflowsCursor = Pagination.WorkflowsCursor;
1002
+ export {
1003
+ type WorkflowsCursorParams as WorkflowsCursorParams,
1004
+ type WorkflowsCursorResponse as WorkflowsCursorResponse,
1005
+ };
1006
+
1007
+ export import SearchHitsOffset = Pagination.SearchHitsOffset;
1008
+ export {
1009
+ type SearchHitsOffsetParams as SearchHitsOffsetParams,
1010
+ type SearchHitsOffsetResponse as SearchHitsOffsetResponse,
1011
+ };
1012
+
925
1013
  export {
926
1014
  Assets as Assets,
927
1015
  type AssetRetrieveResponse as AssetRetrieveResponse,
@@ -935,6 +1023,8 @@ export declare namespace Scenario {
935
1023
  type AssetUnlockResponse as AssetUnlockResponse,
936
1024
  type AssetUpdateTagsResponse as AssetUpdateTagsResponse,
937
1025
  type AssetUploadResponse as AssetUploadResponse,
1026
+ type AssetListResponsesAssetsCursor as AssetListResponsesAssetsCursor,
1027
+ type AssetListSnapshotsResponsesSnapshotsCursor as AssetListSnapshotsResponsesSnapshotsCursor,
938
1028
  type AssetRetrieveParams as AssetRetrieveParams,
939
1029
  type AssetUpdateParams as AssetUpdateParams,
940
1030
  type AssetListParams as AssetListParams,
@@ -955,6 +1045,7 @@ export declare namespace Scenario {
955
1045
  type CollectionUpdateResponse as CollectionUpdateResponse,
956
1046
  type CollectionListResponse as CollectionListResponse,
957
1047
  type CollectionDeleteResponse as CollectionDeleteResponse,
1048
+ type CollectionListResponsesCollectionsCursor as CollectionListResponsesCollectionsCursor,
958
1049
  type CollectionCreateParams as CollectionCreateParams,
959
1050
  type CollectionUpdateParams as CollectionUpdateParams,
960
1051
  type CollectionListParams as CollectionListParams,
@@ -983,6 +1074,7 @@ export declare namespace Scenario {
983
1074
  type JobRetrieveResponse as JobRetrieveResponse,
984
1075
  type JobListResponse as JobListResponse,
985
1076
  type JobTriggerActionResponse as JobTriggerActionResponse,
1077
+ type JobListResponsesJobsCursor as JobListResponsesJobsCursor,
986
1078
  type JobListParams as JobListParams,
987
1079
  type JobTriggerActionParams as JobTriggerActionParams,
988
1080
  };
@@ -1000,6 +1092,7 @@ export declare namespace Scenario {
1000
1092
  type ModelGetBulkResponse as ModelGetBulkResponse,
1001
1093
  type ModelTransferResponse as ModelTransferResponse,
1002
1094
  type ModelUpdateTagsResponse as ModelUpdateTagsResponse,
1095
+ type ModelListResponsesModelsCursor as ModelListResponsesModelsCursor,
1003
1096
  type ModelCreateParams as ModelCreateParams,
1004
1097
  type ModelRetrieveParams as ModelRetrieveParams,
1005
1098
  type ModelUpdateParams as ModelUpdateParams,
@@ -1018,11 +1111,18 @@ export declare namespace Scenario {
1018
1111
  Search as Search,
1019
1112
  type SearchAssetSearchResponse as SearchAssetSearchResponse,
1020
1113
  type SearchModelSearchResponse as SearchModelSearchResponse,
1114
+ type SearchAssetSearchResponsesSearchHitsOffset as SearchAssetSearchResponsesSearchHitsOffset,
1115
+ type SearchModelSearchResponsesSearchHitsOffset as SearchModelSearchResponsesSearchHitsOffset,
1021
1116
  type SearchAssetSearchParams as SearchAssetSearchParams,
1022
1117
  type SearchModelSearchParams as SearchModelSearchParams,
1023
1118
  };
1024
1119
 
1025
- export { Tags as Tags, type TagListResponse as TagListResponse, type TagListParams as TagListParams };
1120
+ export {
1121
+ Tags as Tags,
1122
+ type TagListResponse as TagListResponse,
1123
+ type TagListResponsesTagsCursor as TagListResponsesTagsCursor,
1124
+ type TagListParams as TagListParams,
1125
+ };
1026
1126
 
1027
1127
  export {
1028
1128
  UploadsAPIUploads as Uploads,
@@ -1049,6 +1149,7 @@ export declare namespace Scenario {
1049
1149
  type WorkflowApproveUserResponse as WorkflowApproveUserResponse,
1050
1150
  type WorkflowGetTagsResponse as WorkflowGetTagsResponse,
1051
1151
  type WorkflowRunResponse as WorkflowRunResponse,
1152
+ type WorkflowListResponsesWorkflowsCursor as WorkflowListResponsesWorkflowsCursor,
1052
1153
  type WorkflowCreateParams as WorkflowCreateParams,
1053
1154
  type WorkflowUpdateParams as WorkflowUpdateParams,
1054
1155
  type WorkflowListParams as WorkflowListParams,
@@ -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
+ }