@distilled.cloud/core 1.0.0-rc.13 → 1.0.0-rc.14
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/lib/api.d.ts +4 -4
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +3 -5
- package/lib/api.js.map +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +3 -5
- package/lib/category.js.map +1 -1
- package/lib/codegen/boolean-string-enums.d.ts.map +1 -1
- package/lib/codegen/boolean-string-enums.js +2 -6
- package/lib/codegen/boolean-string-enums.js.map +1 -1
- package/lib/codegen/boolean-string-enums.test.js +3 -5
- package/lib/codegen/boolean-string-enums.test.js.map +1 -1
- package/lib/codegen/cli.d.ts +5 -4
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +12 -9
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/defer-naming.test.d.ts +2 -0
- package/lib/codegen/defer-naming.test.d.ts.map +1 -0
- package/lib/codegen/defer-naming.test.js +105 -0
- package/lib/codegen/defer-naming.test.js.map +1 -0
- package/lib/codegen/emit.d.ts.map +1 -1
- package/lib/codegen/emit.js +1 -3
- package/lib/codegen/emit.js.map +1 -1
- package/lib/codegen/format.d.ts +0 -12
- package/lib/codegen/format.d.ts.map +1 -1
- package/lib/codegen/format.js +10 -6
- package/lib/codegen/format.js.map +1 -1
- package/lib/codegen/generated-at.d.ts +29 -0
- package/lib/codegen/generated-at.d.ts.map +1 -0
- package/lib/codegen/generated-at.js +78 -0
- package/lib/codegen/generated-at.js.map +1 -0
- package/lib/codegen/generated-at.test.d.ts +2 -0
- package/lib/codegen/generated-at.test.d.ts.map +1 -0
- package/lib/codegen/generated-at.test.js +81 -0
- package/lib/codegen/generated-at.test.js.map +1 -0
- package/lib/codegen/generator.d.ts +4 -2
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +37 -75
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/generator.test.js +4 -9
- package/lib/codegen/generator.test.js.map +1 -1
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +12 -33
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql-client.test.js +4 -12
- package/lib/codegen/graphql-client.test.js.map +1 -1
- package/lib/codegen/graphql.d.ts.map +1 -1
- package/lib/codegen/graphql.js +7 -20
- package/lib/codegen/graphql.js.map +1 -1
- package/lib/codegen/model-diff.d.ts +10 -0
- package/lib/codegen/model-diff.d.ts.map +1 -0
- package/lib/codegen/model-diff.js +67 -0
- package/lib/codegen/model-diff.js.map +1 -0
- package/lib/codegen/naming.d.ts.map +1 -1
- package/lib/codegen/naming.js.map +1 -1
- package/lib/codegen/openapi-binary.test.js +1 -1
- package/lib/codegen/openapi-binary.test.js.map +1 -1
- package/lib/codegen/openapi-cli.d.ts +11 -11
- package/lib/codegen/openapi-cli.d.ts.map +1 -1
- package/lib/codegen/openapi-cli.js +26 -51
- package/lib/codegen/openapi-cli.js.map +1 -1
- package/lib/codegen/openapi.d.ts +9 -1
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +48 -42
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/operations.d.ts.map +1 -1
- package/lib/codegen/operations.js.map +1 -1
- package/lib/codegen/pagination.d.ts.map +1 -1
- package/lib/codegen/pagination.js +2 -4
- package/lib/codegen/pagination.js.map +1 -1
- package/lib/codegen/patch-audit.d.ts +84 -0
- package/lib/codegen/patch-audit.d.ts.map +1 -0
- package/lib/codegen/patch-audit.js +366 -0
- package/lib/codegen/patch-audit.js.map +1 -0
- package/lib/codegen/patch-audit.test.d.ts +2 -0
- package/lib/codegen/patch-audit.test.d.ts.map +1 -0
- package/lib/codegen/patch-audit.test.js +141 -0
- package/lib/codegen/patch-audit.test.js.map +1 -0
- package/lib/codegen/patches.d.ts +59 -10
- package/lib/codegen/patches.d.ts.map +1 -1
- package/lib/codegen/patches.js +233 -63
- package/lib/codegen/patches.js.map +1 -1
- package/lib/codegen/patches.test.js +8 -4
- package/lib/codegen/patches.test.js.map +1 -1
- package/lib/codegen/prelude.js +1 -1
- package/lib/codegen/prelude.js.map +1 -1
- package/lib/codegen/proto.d.ts.map +1 -1
- package/lib/codegen/proto.js +2 -4
- package/lib/codegen/proto.js.map +1 -1
- package/lib/codegen/protocol-imports.test.d.ts +2 -0
- package/lib/codegen/protocol-imports.test.d.ts.map +1 -0
- package/lib/codegen/protocol-imports.test.js +36 -0
- package/lib/codegen/protocol-imports.test.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.d.ts +23 -0
- package/lib/codegen/rewrite-operation-ids.d.ts.map +1 -1
- package/lib/codegen/rewrite-operation-ids.js +97 -59
- package/lib/codegen/rewrite-operation-ids.js.map +1 -1
- package/lib/codegen/rewrite-operation-ids.test.js +19 -101
- package/lib/codegen/rewrite-operation-ids.test.js.map +1 -1
- package/lib/codegen/spec-path.d.ts +1 -1
- package/lib/codegen/spec-path.d.ts.map +1 -1
- package/lib/codegen/spec-path.js +1 -1
- package/lib/codegen/spec-path.js.map +1 -1
- package/lib/codegen/untagged-unions.test.js +1 -1
- package/lib/codegen/untagged-unions.test.js.map +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js.map +1 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +7 -5
- package/lib/errors.js.map +1 -1
- package/lib/graphql.d.ts +4 -8
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +20 -48
- package/lib/graphql.js.map +1 -1
- package/lib/graphql.test.js +6 -6
- package/lib/graphql.test.js.map +1 -1
- package/lib/graphql.types.d.ts.map +1 -1
- package/lib/graphql.types.js.map +1 -1
- package/lib/json-patch.d.ts +13 -6
- package/lib/json-patch.d.ts.map +1 -1
- package/lib/json-patch.js +34 -19
- package/lib/json-patch.js.map +1 -1
- package/lib/json-patch.test.d.ts +2 -0
- package/lib/json-patch.test.d.ts.map +1 -0
- package/lib/json-patch.test.js +65 -0
- package/lib/json-patch.test.js.map +1 -0
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +6 -16
- package/lib/pagination.js.map +1 -1
- package/lib/pagination.test.js +3 -6
- package/lib/pagination.test.js.map +1 -1
- package/lib/protocol-http.d.ts +20 -1
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +41 -47
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-http.test.js +20 -10
- package/lib/protocol-http.test.js.map +1 -1
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +9 -18
- package/lib/protocol-rest.js.map +1 -1
- package/lib/protocol-rest.test.d.ts +2 -0
- package/lib/protocol-rest.test.d.ts.map +1 -0
- package/lib/protocol-rest.test.js +498 -0
- package/lib/protocol-rest.test.js.map +1 -0
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js.map +1 -1
- package/lib/response-validation.test.js +10 -5
- package/lib/response-validation.test.js.map +1 -1
- package/lib/retry-after.d.ts.map +1 -1
- package/lib/retry-after.js +1 -1
- package/lib/retry-after.js.map +1 -1
- package/lib/retry-after.test.d.ts +2 -0
- package/lib/retry-after.test.d.ts.map +1 -0
- package/lib/retry-after.test.js +204 -0
- package/lib/retry-after.test.js.map +1 -0
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -2
- package/lib/retry.js.map +1 -1
- package/lib/retry.test.d.ts +2 -0
- package/lib/retry.test.d.ts.map +1 -0
- package/lib/retry.test.js +407 -0
- package/lib/retry.test.js.map +1 -0
- package/lib/sdks.test.d.ts +2 -0
- package/lib/sdks.test.d.ts.map +1 -0
- package/lib/sdks.test.js +76 -0
- package/lib/sdks.test.js.map +1 -0
- package/lib/testing.d.ts +2 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +1 -1
- package/lib/testing.js.map +1 -1
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js.map +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +3 -7
- package/lib/xml.js.map +1 -1
- package/lib/xml.test.js +11 -12
- package/lib/xml.test.js.map +1 -1
- package/package.json +7 -10
- package/src/api.ts +38 -55
- package/src/category.ts +21 -50
- package/src/codegen/boolean-string-enums.test.ts +12 -28
- package/src/codegen/boolean-string-enums.ts +2 -10
- package/src/codegen/cli.ts +29 -47
- package/src/codegen/defer-naming.test.ts +113 -0
- package/src/codegen/emit.ts +2 -5
- package/src/codegen/format.ts +12 -10
- package/src/codegen/generated-at.test.ts +89 -0
- package/src/codegen/generated-at.ts +88 -0
- package/src/codegen/generator.test.ts +8 -22
- package/src/codegen/generator.ts +72 -191
- package/src/codegen/graphql-client.test.ts +12 -42
- package/src/codegen/graphql-client.ts +30 -95
- package/src/codegen/graphql.ts +22 -94
- package/src/codegen/model-diff.ts +67 -0
- package/src/codegen/naming.ts +1 -2
- package/src/codegen/openapi-binary.test.ts +5 -12
- package/src/codegen/openapi-cli.ts +38 -79
- package/src/codegen/openapi.ts +79 -136
- package/src/codegen/operations.ts +2 -5
- package/src/codegen/pagination.ts +4 -11
- package/src/codegen/patch-audit.test.ts +160 -0
- package/src/codegen/patch-audit.ts +480 -0
- package/src/codegen/patches.test.ts +14 -21
- package/src/codegen/patches.ts +313 -103
- package/src/codegen/prelude.ts +1 -1
- package/src/codegen/proto.ts +18 -54
- package/src/codegen/protocol-imports.test.ts +39 -0
- package/src/codegen/rewrite-operation-ids.test.ts +23 -114
- package/src/codegen/rewrite-operation-ids.ts +111 -98
- package/src/codegen/spec-path.ts +3 -6
- package/src/codegen/untagged-unions.test.ts +3 -7
- package/src/error-category.ts +5 -17
- package/src/errors.ts +16 -31
- package/src/graphql.test.ts +6 -8
- package/src/graphql.ts +76 -219
- package/src/graphql.types.ts +10 -25
- package/src/json-patch.test.ts +77 -0
- package/src/json-patch.ts +54 -60
- package/src/pagination.test.ts +13 -35
- package/src/pagination.ts +44 -111
- package/src/protocol-http.test.ts +36 -30
- package/src/protocol-http.ts +73 -138
- package/src/protocol-rest.test.ts +703 -0
- package/src/protocol-rest.ts +24 -62
- package/src/response-validation.test.ts +12 -18
- package/src/response-validation.ts +3 -12
- package/src/retry-after.test.ts +267 -0
- package/src/retry-after.ts +4 -10
- package/src/retry.test.ts +566 -0
- package/src/retry.ts +6 -21
- package/src/sdks.test.ts +87 -0
- package/src/testing.ts +4 -10
- package/src/trait.ts +21 -67
- package/src/xml.test.ts +15 -33
- package/src/xml.ts +9 -25
package/src/pagination.ts
CHANGED
|
@@ -89,12 +89,7 @@ export interface PaginatedTrait {
|
|
|
89
89
|
readonly hasNextPage?: string;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
export type PaginationStrategy = <
|
|
93
|
-
Input extends Record<string, unknown>,
|
|
94
|
-
Output,
|
|
95
|
-
E,
|
|
96
|
-
R,
|
|
97
|
-
>(
|
|
92
|
+
export type PaginationStrategy = <Input extends Record<string, unknown>, Output, E, R>(
|
|
98
93
|
operation: (input: Input) => Effect.Effect<Output, E, R>,
|
|
99
94
|
input: Input,
|
|
100
95
|
pagination: PaginatedTrait,
|
|
@@ -120,9 +115,7 @@ export const isTerminalToken = (token: unknown): boolean =>
|
|
|
120
115
|
* surface — emits exactly one page.
|
|
121
116
|
*/
|
|
122
117
|
export const paginateSingle: PaginationStrategy = (operation, input) =>
|
|
123
|
-
Stream.make(input).pipe(
|
|
124
|
-
Stream.mapEffect((requestPayload) => operation(requestPayload)),
|
|
125
|
-
);
|
|
118
|
+
Stream.make(input).pipe(Stream.mapEffect((requestPayload) => operation(requestPayload)));
|
|
126
119
|
|
|
127
120
|
// ============================================================================
|
|
128
121
|
// Page-based Pagination
|
|
@@ -133,12 +126,7 @@ export const paginateSingle: PaginationStrategy = (operation, input) =>
|
|
|
133
126
|
* `outputToken` when it advances; otherwise the page number is incremented,
|
|
134
127
|
* terminating when a page comes back with no items (or no token).
|
|
135
128
|
*/
|
|
136
|
-
export const paginatePageNumber = <
|
|
137
|
-
Input extends Record<string, unknown>,
|
|
138
|
-
Output,
|
|
139
|
-
E,
|
|
140
|
-
R,
|
|
141
|
-
>(
|
|
129
|
+
export const paginatePageNumber = <Input extends Record<string, unknown>, Output, E, R>(
|
|
142
130
|
operation: (input: Input) => Effect.Effect<Output, E, R>,
|
|
143
131
|
input: Input,
|
|
144
132
|
pagination: PaginatedTrait,
|
|
@@ -146,13 +134,10 @@ export const paginatePageNumber = <
|
|
|
146
134
|
const inputToken = pagination.inputToken;
|
|
147
135
|
const outputToken = pagination.outputToken;
|
|
148
136
|
if (!inputToken || !outputToken) {
|
|
149
|
-
return missingPaginationConfig(
|
|
150
|
-
"Page-number pagination requires inputToken and outputToken",
|
|
151
|
-
);
|
|
137
|
+
return missingPaginationConfig("Page-number pagination requires inputToken and outputToken");
|
|
152
138
|
}
|
|
153
139
|
type State = { page: number; done: boolean };
|
|
154
|
-
const startPage =
|
|
155
|
-
typeof input[inputToken] === "number" ? (input[inputToken] as number) : 1;
|
|
140
|
+
const startPage = typeof input[inputToken] === "number" ? (input[inputToken] as number) : 1;
|
|
156
141
|
|
|
157
142
|
return Stream.unfold({ page: startPage, done: false } as State, (state) =>
|
|
158
143
|
Effect.gen(function* () {
|
|
@@ -161,10 +146,7 @@ export const paginatePageNumber = <
|
|
|
161
146
|
const requestPayload = { ...input, [inputToken]: state.page } as Input;
|
|
162
147
|
const response = yield* operation(requestPayload);
|
|
163
148
|
|
|
164
|
-
const nextPage = getPath(response, outputToken) as
|
|
165
|
-
| number
|
|
166
|
-
| null
|
|
167
|
-
| undefined;
|
|
149
|
+
const nextPage = getPath(response, outputToken) as number | null | undefined;
|
|
168
150
|
|
|
169
151
|
// Some APIs report the CURRENT page at `outputToken` rather than the
|
|
170
152
|
// next one (e.g. Cloudflare's `result_info.page`). Taking that value as
|
|
@@ -172,16 +154,11 @@ export const paginatePageNumber = <
|
|
|
172
154
|
// *advancing* page number; otherwise advance by one and terminate when
|
|
173
155
|
// a page comes back with no items (or the token is absent).
|
|
174
156
|
const items = pagination.items
|
|
175
|
-
? (getPath(response, pagination.items) as
|
|
176
|
-
| readonly unknown[]
|
|
177
|
-
| undefined)
|
|
157
|
+
? (getPath(response, pagination.items) as readonly unknown[] | undefined)
|
|
178
158
|
: undefined;
|
|
179
159
|
|
|
180
160
|
const nextState: State = {
|
|
181
|
-
page:
|
|
182
|
-
typeof nextPage === "number" && nextPage > state.page
|
|
183
|
-
? nextPage
|
|
184
|
-
: state.page + 1,
|
|
161
|
+
page: typeof nextPage === "number" && nextPage > state.page ? nextPage : state.page + 1,
|
|
185
162
|
done:
|
|
186
163
|
nextPage === null ||
|
|
187
164
|
nextPage === undefined ||
|
|
@@ -202,12 +179,7 @@ export const paginatePageNumber = <
|
|
|
202
179
|
* cursors until one comes back absent or repeats a previously requested cursor.
|
|
203
180
|
* Empty pages still advance when they return a new cursor.
|
|
204
181
|
*/
|
|
205
|
-
export const paginateCursor = <
|
|
206
|
-
Input extends Record<string, unknown>,
|
|
207
|
-
Output,
|
|
208
|
-
E,
|
|
209
|
-
R,
|
|
210
|
-
>(
|
|
182
|
+
export const paginateCursor = <Input extends Record<string, unknown>, Output, E, R>(
|
|
211
183
|
operation: (input: Input) => Effect.Effect<Output, E, R>,
|
|
212
184
|
input: Input,
|
|
213
185
|
pagination: PaginatedTrait,
|
|
@@ -215,47 +187,37 @@ export const paginateCursor = <
|
|
|
215
187
|
const inputToken = pagination.inputToken;
|
|
216
188
|
const outputToken = pagination.outputToken;
|
|
217
189
|
if (!inputToken || !outputToken) {
|
|
218
|
-
return missingPaginationConfig(
|
|
219
|
-
"Cursor pagination requires inputToken and outputToken",
|
|
220
|
-
);
|
|
190
|
+
return missingPaginationConfig("Cursor pagination requires inputToken and outputToken");
|
|
221
191
|
}
|
|
222
192
|
type State = { cursor: string | undefined; done: boolean };
|
|
223
193
|
const startCursor =
|
|
224
|
-
typeof input[inputToken] === "string"
|
|
225
|
-
? (input[inputToken] as string)
|
|
226
|
-
: undefined;
|
|
194
|
+
typeof input[inputToken] === "string" ? (input[inputToken] as string) : undefined;
|
|
227
195
|
|
|
228
196
|
return Stream.suspend(() => {
|
|
229
197
|
// Cursor history belongs to this traversal, not to the reusable stream.
|
|
230
198
|
const requestedCursors = new Set<string>();
|
|
231
|
-
return Stream.unfold(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
isTerminalToken(nextCursor) ||
|
|
254
|
-
(nextCursor != null && requestedCursors.has(nextCursor)),
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
return [response, nextState] as const;
|
|
258
|
-
}),
|
|
199
|
+
return Stream.unfold({ cursor: startCursor, done: false } as State, (state) =>
|
|
200
|
+
Effect.gen(function* () {
|
|
201
|
+
if (state.done) return undefined;
|
|
202
|
+
if (state.cursor !== undefined) requestedCursors.add(state.cursor);
|
|
203
|
+
|
|
204
|
+
const requestPayload = {
|
|
205
|
+
...input,
|
|
206
|
+
...(state.cursor ? { [inputToken]: state.cursor } : {}),
|
|
207
|
+
} as Input;
|
|
208
|
+
|
|
209
|
+
const response = yield* operation(requestPayload);
|
|
210
|
+
|
|
211
|
+
const nextCursor = getPath(response, outputToken) as string | null | undefined;
|
|
212
|
+
|
|
213
|
+
const nextState: State = {
|
|
214
|
+
cursor: nextCursor ?? undefined,
|
|
215
|
+
done:
|
|
216
|
+
isTerminalToken(nextCursor) || (nextCursor != null && requestedCursors.has(nextCursor)),
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
return [response, nextState] as const;
|
|
220
|
+
}),
|
|
259
221
|
);
|
|
260
222
|
});
|
|
261
223
|
};
|
|
@@ -268,12 +230,7 @@ export const paginateCursor = <
|
|
|
268
230
|
* Stream of pages using token-based pagination — pass `outputToken` back as
|
|
269
231
|
* `inputToken` until it comes back absent.
|
|
270
232
|
*/
|
|
271
|
-
export const paginateToken = <
|
|
272
|
-
Input extends Record<string, unknown>,
|
|
273
|
-
Output,
|
|
274
|
-
E,
|
|
275
|
-
R,
|
|
276
|
-
>(
|
|
233
|
+
export const paginateToken = <Input extends Record<string, unknown>, Output, E, R>(
|
|
277
234
|
operation: (input: Input) => Effect.Effect<Output, E, R>,
|
|
278
235
|
input: Input,
|
|
279
236
|
pagination: PaginatedTrait,
|
|
@@ -281,9 +238,7 @@ export const paginateToken = <
|
|
|
281
238
|
const inputToken = pagination.inputToken;
|
|
282
239
|
const outputToken = pagination.outputToken;
|
|
283
240
|
if (!inputToken || !outputToken) {
|
|
284
|
-
return missingPaginationConfig(
|
|
285
|
-
"Token pagination requires inputToken and outputToken",
|
|
286
|
-
);
|
|
241
|
+
return missingPaginationConfig("Token pagination requires inputToken and outputToken");
|
|
287
242
|
}
|
|
288
243
|
type State = { token: unknown; done: boolean };
|
|
289
244
|
const startToken = input[inputToken];
|
|
@@ -293,9 +248,7 @@ export const paginateToken = <
|
|
|
293
248
|
if (state.done) return undefined;
|
|
294
249
|
|
|
295
250
|
const requestPayload =
|
|
296
|
-
state.token !== undefined
|
|
297
|
-
? ({ ...input, [inputToken]: state.token } as Input)
|
|
298
|
-
: input;
|
|
251
|
+
state.token !== undefined ? ({ ...input, [inputToken]: state.token } as Input) : input;
|
|
299
252
|
|
|
300
253
|
const response = yield* operation(requestPayload);
|
|
301
254
|
|
|
@@ -327,12 +280,7 @@ export const paginateToken = <
|
|
|
327
280
|
* connection that omits `pageInfo` entirely (or returns an empty page) also
|
|
328
281
|
* terminates, so a malformed response can't spin forever.
|
|
329
282
|
*/
|
|
330
|
-
export const paginateRelay = <
|
|
331
|
-
Input extends Record<string, unknown>,
|
|
332
|
-
Output,
|
|
333
|
-
E,
|
|
334
|
-
R,
|
|
335
|
-
>(
|
|
283
|
+
export const paginateRelay = <Input extends Record<string, unknown>, Output, E, R>(
|
|
336
284
|
operation: (input: Input) => Effect.Effect<Output, E, R>,
|
|
337
285
|
input: Input,
|
|
338
286
|
pagination: PaginatedTrait,
|
|
@@ -340,9 +288,7 @@ export const paginateRelay = <
|
|
|
340
288
|
const inputToken = pagination.inputToken;
|
|
341
289
|
const outputToken = pagination.outputToken;
|
|
342
290
|
if (!inputToken || !outputToken) {
|
|
343
|
-
return missingPaginationConfig(
|
|
344
|
-
"Relay pagination requires inputToken and outputToken",
|
|
345
|
-
);
|
|
291
|
+
return missingPaginationConfig("Relay pagination requires inputToken and outputToken");
|
|
346
292
|
}
|
|
347
293
|
// `pageInfo.endCursor` → `pageInfo.hasNextPage` when the trait doesn't say.
|
|
348
294
|
const hasNextPath =
|
|
@@ -351,9 +297,7 @@ export const paginateRelay = <
|
|
|
351
297
|
|
|
352
298
|
type State = { cursor: string | undefined; done: boolean };
|
|
353
299
|
const startCursor =
|
|
354
|
-
typeof input[inputToken] === "string"
|
|
355
|
-
? (input[inputToken] as string)
|
|
356
|
-
: undefined;
|
|
300
|
+
typeof input[inputToken] === "string" ? (input[inputToken] as string) : undefined;
|
|
357
301
|
|
|
358
302
|
return Stream.unfold({ cursor: startCursor, done: false } as State, (state) =>
|
|
359
303
|
Effect.gen(function* () {
|
|
@@ -366,16 +310,12 @@ export const paginateRelay = <
|
|
|
366
310
|
|
|
367
311
|
const response = yield* operation(requestPayload);
|
|
368
312
|
|
|
369
|
-
const nextCursor = getPath(response, outputToken) as
|
|
370
|
-
| string
|
|
371
|
-
| null
|
|
372
|
-
| undefined;
|
|
313
|
+
const nextCursor = getPath(response, outputToken) as string | null | undefined;
|
|
373
314
|
const hasNext = getPath(response, hasNextPath) === true;
|
|
374
315
|
// An empty page means the connection is exhausted regardless of what
|
|
375
316
|
// `hasNextPage` claims — re-requesting the same cursor would loop.
|
|
376
317
|
const emptyPage =
|
|
377
|
-
pagination.items !== undefined &&
|
|
378
|
-
getItems(response, pagination.items).length === 0;
|
|
318
|
+
pagination.items !== undefined && getItems(response, pagination.items).length === 0;
|
|
379
319
|
// A connection that keeps returning the same `endCursor` with
|
|
380
320
|
// `hasNextPage: true` (Railway `projects` has done this) would
|
|
381
321
|
// otherwise paginate forever.
|
|
@@ -387,8 +327,7 @@ export const paginateRelay = <
|
|
|
387
327
|
|
|
388
328
|
const nextState: State = {
|
|
389
329
|
cursor: nextCursor ?? undefined,
|
|
390
|
-
done:
|
|
391
|
-
!hasNext || isTerminalToken(nextCursor) || emptyPage || stuckCursor,
|
|
330
|
+
done: !hasNext || isTerminalToken(nextCursor) || emptyPage || stuckCursor,
|
|
392
331
|
};
|
|
393
332
|
|
|
394
333
|
return [response, nextState] as const;
|
|
@@ -400,11 +339,7 @@ export const paginateRelay = <
|
|
|
400
339
|
* Shared default pagination dispatcher for SDKs that use generic
|
|
401
340
|
* token/cursor/page traversal.
|
|
402
341
|
*/
|
|
403
|
-
export const paginateWithDefaults: PaginationStrategy = (
|
|
404
|
-
operation,
|
|
405
|
-
input,
|
|
406
|
-
pagination,
|
|
407
|
-
) => {
|
|
342
|
+
export const paginateWithDefaults: PaginationStrategy = (operation, input, pagination) => {
|
|
408
343
|
const mode = pagination.mode ?? "token";
|
|
409
344
|
|
|
410
345
|
switch (mode) {
|
|
@@ -439,7 +374,5 @@ export const extractItems = <Output, Item, E, R>(
|
|
|
439
374
|
itemsPath: string,
|
|
440
375
|
): Stream.Stream<Item, E, R> =>
|
|
441
376
|
pages.pipe(
|
|
442
|
-
Stream.flatMap((page) =>
|
|
443
|
-
Stream.fromIterable(getItems(page, itemsPath) as readonly Item[]),
|
|
444
|
-
),
|
|
377
|
+
Stream.flatMap((page) => Stream.fromIterable(getItems(page, itemsPath) as readonly Item[])),
|
|
445
378
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
1
|
import * as Redacted from "effect/Redacted";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
3
|
import { buildRequest, mapKeys } from "./protocol-http.ts";
|
|
4
4
|
import { SensitiveValue, wrapSensitive } from "./protocol-rest.ts";
|
|
5
5
|
import * as S from "./schema.ts";
|
|
@@ -13,17 +13,11 @@ import * as T from "./trait.ts";
|
|
|
13
13
|
const JsonInput = S.Struct({
|
|
14
14
|
flag: S.optional(S.Boolean.pipe(T.Body("flag"), T.StringEncoded())),
|
|
15
15
|
plain: S.optional(S.Boolean.pipe(T.Body("plain"))),
|
|
16
|
-
nullable: S.optional(
|
|
17
|
-
|
|
18
|
-
),
|
|
19
|
-
flags: S.optional(
|
|
20
|
-
S.Array(S.Boolean).pipe(T.Body("flags"), T.StringEncoded()),
|
|
21
|
-
),
|
|
16
|
+
nullable: S.optional(S.NullOr(S.Boolean).pipe(T.Body("nullable"), T.StringEncoded())),
|
|
17
|
+
flags: S.optional(S.Array(S.Boolean).pipe(T.Body("flags"), T.StringEncoded())),
|
|
22
18
|
profile: S.optional(
|
|
23
19
|
S.Struct({
|
|
24
|
-
nested: S.optional(
|
|
25
|
-
S.Boolean.pipe(T.Body("nested_flag"), T.StringEncoded()),
|
|
26
|
-
),
|
|
20
|
+
nested: S.optional(S.Boolean.pipe(T.Body("nested_flag"), T.StringEncoded())),
|
|
27
21
|
plain: S.optional(S.Boolean.pipe(T.Body("plain_flag"))),
|
|
28
22
|
}).pipe(T.Body("profile")),
|
|
29
23
|
),
|
|
@@ -103,6 +97,32 @@ describe("URI label encoding", () => {
|
|
|
103
97
|
});
|
|
104
98
|
});
|
|
105
99
|
|
|
100
|
+
describe("greedy labels", () => {
|
|
101
|
+
const ScopedInput = S.Struct({
|
|
102
|
+
scope: S.String.pipe(T.Label()),
|
|
103
|
+
name: S.String.pipe(T.Label()),
|
|
104
|
+
}).pipe(T.Http({ method: "GET", uri: "/{scope+}/providers/Things/{name}" }));
|
|
105
|
+
|
|
106
|
+
const urlOf = (input: unknown) =>
|
|
107
|
+
buildRequest({
|
|
108
|
+
input,
|
|
109
|
+
inputAst: ScopedInput.ast,
|
|
110
|
+
baseUrl: "https://example.test",
|
|
111
|
+
}).url;
|
|
112
|
+
|
|
113
|
+
test("keeps slashes and drops the leading slash of the value", () => {
|
|
114
|
+
expect(urlOf({ scope: "/subscriptions/abc/resourceGroups/my rg", name: "a/b" })).toBe(
|
|
115
|
+
"https://example.test/subscriptions/abc/resourceGroups/my%20rg/providers/Things/a%2Fb",
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("accepts a value without a leading slash", () => {
|
|
120
|
+
expect(urlOf({ scope: "subscriptions/abc", name: "x" })).toBe(
|
|
121
|
+
"https://example.test/subscriptions/abc/providers/Things/x",
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
106
126
|
describe("multipart binary parts", () => {
|
|
107
127
|
const schema = S.Struct({ zip: S.Unknown, environment: S.String }).pipe(
|
|
108
128
|
T.Http({ method: "POST", uri: "/deployments", contentType: "multipart" }),
|
|
@@ -125,9 +145,7 @@ describe("multipart binary parts", () => {
|
|
|
125
145
|
method: "POST",
|
|
126
146
|
body: request.body.formData,
|
|
127
147
|
});
|
|
128
|
-
expect(wire.headers.get("content-type")).toContain(
|
|
129
|
-
"multipart/form-data; boundary=",
|
|
130
|
-
);
|
|
148
|
+
expect(wire.headers.get("content-type")).toContain("multipart/form-data; boundary=");
|
|
131
149
|
});
|
|
132
150
|
|
|
133
151
|
test("preserves File names and ArrayBuffer bytes", async () => {
|
|
@@ -140,13 +158,10 @@ describe("multipart binary parts", () => {
|
|
|
140
158
|
inputAst: schema.ast,
|
|
141
159
|
baseUrl: "https://example.test",
|
|
142
160
|
});
|
|
143
|
-
if (request.body._tag !== "FormData")
|
|
144
|
-
throw new Error("Expected multipart");
|
|
161
|
+
if (request.body._tag !== "FormData") throw new Error("Expected multipart");
|
|
145
162
|
const part = request.body.formData.get("zip") as File;
|
|
146
163
|
expect(part.name).toBe(zip instanceof File ? "bundle.zip" : "zip");
|
|
147
|
-
expect(new Uint8Array(await part.arrayBuffer())).toEqual(
|
|
148
|
-
new Uint8Array([80, 75, 255]),
|
|
149
|
-
);
|
|
164
|
+
expect(new Uint8Array(await part.arrayBuffer())).toEqual(new Uint8Array([80, 75, 255]));
|
|
150
165
|
}
|
|
151
166
|
});
|
|
152
167
|
});
|
|
@@ -192,18 +207,11 @@ describe("sensitive union responses", () => {
|
|
|
192
207
|
provider: S.optional(S.NullOr(schema)),
|
|
193
208
|
providers: S.Array(schema),
|
|
194
209
|
});
|
|
195
|
-
for (const value of [
|
|
196
|
-
{},
|
|
197
|
-
{ provider: null },
|
|
198
|
-
{ provider: { type: "shared" } },
|
|
199
|
-
]) {
|
|
210
|
+
for (const value of [{}, { provider: null }, { provider: { type: "shared" } }]) {
|
|
200
211
|
expect(
|
|
201
212
|
wrapSensitive(nested.ast, {
|
|
202
213
|
...value,
|
|
203
|
-
providers: [
|
|
204
|
-
{ type: "standard", password: "fixture-password" },
|
|
205
|
-
{ type: "shared" },
|
|
206
|
-
],
|
|
214
|
+
providers: [{ type: "standard", password: "fixture-password" }, { type: "shared" }],
|
|
207
215
|
}),
|
|
208
216
|
).toEqual({
|
|
209
217
|
...value,
|
|
@@ -250,9 +258,7 @@ describe("UnionCases decoding", () => {
|
|
|
250
258
|
const schema = S.Unknown.pipe(
|
|
251
259
|
T.UnionCases(cases, { key: "type", values: ["zone", "account"] }),
|
|
252
260
|
);
|
|
253
|
-
expect(
|
|
254
|
-
decode(schema, { ...merged, type: "other", accountName: null }),
|
|
255
|
-
).toEqual({
|
|
261
|
+
expect(decode(schema, { ...merged, type: "other", accountName: null })).toEqual({
|
|
256
262
|
id: "1",
|
|
257
263
|
type: "other",
|
|
258
264
|
zoneName: "zone-a",
|