@distilled.cloud/core 0.30.2 → 1.0.0-rc.1

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 (132) hide show
  1. package/lib/api.d.ts +165 -0
  2. package/lib/api.d.ts.map +1 -0
  3. package/lib/api.js +178 -0
  4. package/lib/api.js.map +1 -0
  5. package/lib/codegen/cli.d.ts +29 -0
  6. package/lib/codegen/cli.d.ts.map +1 -0
  7. package/lib/codegen/cli.js +165 -0
  8. package/lib/codegen/cli.js.map +1 -0
  9. package/lib/codegen/emit.d.ts +129 -0
  10. package/lib/codegen/emit.d.ts.map +1 -0
  11. package/lib/codegen/emit.js +105 -0
  12. package/lib/codegen/emit.js.map +1 -0
  13. package/lib/codegen/format.d.ts +23 -0
  14. package/lib/codegen/format.d.ts.map +1 -0
  15. package/lib/codegen/format.js +28 -0
  16. package/lib/codegen/format.js.map +1 -0
  17. package/lib/codegen/generator.d.ts +334 -0
  18. package/lib/codegen/generator.d.ts.map +1 -0
  19. package/lib/codegen/generator.js +691 -0
  20. package/lib/codegen/generator.js.map +1 -0
  21. package/lib/codegen/graph.d.ts +36 -0
  22. package/lib/codegen/graph.d.ts.map +1 -0
  23. package/lib/codegen/graph.js +136 -0
  24. package/lib/codegen/graph.js.map +1 -0
  25. package/lib/codegen/members.d.ts +25 -0
  26. package/lib/codegen/members.d.ts.map +1 -0
  27. package/lib/codegen/members.js +55 -0
  28. package/lib/codegen/members.js.map +1 -0
  29. package/lib/codegen/naming.d.ts +29 -0
  30. package/lib/codegen/naming.d.ts.map +1 -0
  31. package/lib/codegen/naming.js +74 -0
  32. package/lib/codegen/naming.js.map +1 -0
  33. package/lib/codegen/openapi-cli.d.ts +38 -0
  34. package/lib/codegen/openapi-cli.d.ts.map +1 -0
  35. package/lib/codegen/openapi-cli.js +107 -0
  36. package/lib/codegen/openapi-cli.js.map +1 -0
  37. package/lib/codegen/openapi.d.ts +115 -0
  38. package/lib/codegen/openapi.d.ts.map +1 -0
  39. package/lib/codegen/openapi.js +1220 -0
  40. package/lib/codegen/openapi.js.map +1 -0
  41. package/lib/codegen/operations.d.ts +24 -0
  42. package/lib/codegen/operations.d.ts.map +1 -0
  43. package/lib/codegen/operations.js +56 -0
  44. package/lib/codegen/operations.js.map +1 -0
  45. package/lib/codegen/pagination.d.ts +39 -0
  46. package/lib/codegen/pagination.d.ts.map +1 -0
  47. package/lib/codegen/pagination.js +33 -0
  48. package/lib/codegen/pagination.js.map +1 -0
  49. package/lib/codegen/prelude.d.ts +15 -0
  50. package/lib/codegen/prelude.d.ts.map +1 -0
  51. package/lib/codegen/prelude.js +60 -0
  52. package/lib/codegen/prelude.js.map +1 -0
  53. package/lib/error-category.d.ts +28 -0
  54. package/lib/error-category.d.ts.map +1 -0
  55. package/lib/error-category.js +46 -0
  56. package/lib/error-category.js.map +1 -0
  57. package/lib/errors.d.ts +1 -0
  58. package/lib/errors.d.ts.map +1 -1
  59. package/lib/errors.js +1 -0
  60. package/lib/errors.js.map +1 -1
  61. package/lib/json-patch.d.ts +25 -32
  62. package/lib/json-patch.d.ts.map +1 -1
  63. package/lib/json-patch.js +23 -95
  64. package/lib/json-patch.js.map +1 -1
  65. package/lib/pagination.d.ts +37 -51
  66. package/lib/pagination.d.ts.map +1 -1
  67. package/lib/pagination.js +72 -90
  68. package/lib/pagination.js.map +1 -1
  69. package/lib/protocol-http.d.ts +74 -0
  70. package/lib/protocol-http.d.ts.map +1 -0
  71. package/lib/protocol-http.js +554 -0
  72. package/lib/protocol-http.js.map +1 -0
  73. package/lib/protocol-rest.d.ts +124 -0
  74. package/lib/protocol-rest.d.ts.map +1 -0
  75. package/lib/protocol-rest.js +242 -0
  76. package/lib/protocol-rest.js.map +1 -0
  77. package/lib/retry.d.ts +8 -2
  78. package/lib/retry.d.ts.map +1 -1
  79. package/lib/retry.js +21 -15
  80. package/lib/retry.js.map +1 -1
  81. package/lib/schema.d.ts +7 -8
  82. package/lib/schema.d.ts.map +1 -1
  83. package/lib/schema.js +7 -8
  84. package/lib/schema.js.map +1 -1
  85. package/lib/trait.d.ts +150 -0
  86. package/lib/trait.d.ts.map +1 -0
  87. package/lib/trait.js +107 -0
  88. package/lib/trait.js.map +1 -0
  89. package/package.json +18 -75
  90. package/src/api.ts +446 -0
  91. package/src/codegen/cli.ts +268 -0
  92. package/src/codegen/emit.ts +207 -0
  93. package/src/codegen/format.ts +47 -0
  94. package/src/codegen/generator.ts +1153 -0
  95. package/src/codegen/graph.ts +151 -0
  96. package/src/codegen/members.ts +71 -0
  97. package/src/codegen/naming.ts +86 -0
  98. package/src/codegen/openapi-cli.ts +166 -0
  99. package/src/codegen/openapi.ts +1450 -0
  100. package/src/codegen/operations.ts +76 -0
  101. package/src/codegen/pagination.ts +71 -0
  102. package/src/codegen/prelude.ts +70 -0
  103. package/src/error-category.ts +84 -0
  104. package/src/errors.ts +2 -0
  105. package/src/json-patch.ts +26 -110
  106. package/src/pagination.ts +86 -142
  107. package/src/protocol-http.ts +699 -0
  108. package/src/protocol-rest.ts +367 -0
  109. package/src/retry.ts +20 -21
  110. package/src/schema.ts +7 -8
  111. package/src/trait.ts +238 -0
  112. package/README.md +0 -30
  113. package/lib/client.d.ts +0 -167
  114. package/lib/client.d.ts.map +0 -1
  115. package/lib/client.js +0 -659
  116. package/lib/client.js.map +0 -1
  117. package/lib/schemas.d.ts +0 -60
  118. package/lib/schemas.d.ts.map +0 -1
  119. package/lib/schemas.js +0 -79
  120. package/lib/schemas.js.map +0 -1
  121. package/lib/sensitive.d.ts +0 -71
  122. package/lib/sensitive.d.ts.map +0 -1
  123. package/lib/sensitive.js +0 -96
  124. package/lib/sensitive.js.map +0 -1
  125. package/lib/traits.d.ts +0 -421
  126. package/lib/traits.d.ts.map +0 -1
  127. package/lib/traits.js +0 -737
  128. package/lib/traits.js.map +0 -1
  129. package/src/client.ts +0 -1177
  130. package/src/schemas.ts +0 -128
  131. package/src/sensitive.ts +0 -119
  132. package/src/traits.ts +0 -996
package/src/api.ts ADDED
@@ -0,0 +1,446 @@
1
+ import * as Context from "effect/Context";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import * as Option from "effect/Option";
5
+ import * as S from "effect/Schema";
6
+ import type * as AST from "effect/SchemaAST";
7
+ import { pipeArguments } from "effect/Pipeable";
8
+ import * as Ref from "effect/Ref";
9
+ import * as Scope from "effect/Scope";
10
+ import type * as Stream from "effect/Stream";
11
+ import { SingleShotGen } from "effect/Utils";
12
+ import * as Pagination from "./pagination.ts";
13
+ import { makeDefault, type Policy as RetryPolicy } from "./retry.ts";
14
+ import * as HttpClient from "effect/unstable/http/HttpClient";
15
+ import type * as HttpClientError from "effect/unstable/http/HttpClientError";
16
+ import type * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
17
+ import type * as HttpClientResponse from "effect/unstable/http/HttpClientResponse";
18
+
19
+ //#region Protocol
20
+
21
+ /**
22
+ * The view of an operation's config that protocols receive on every
23
+ * encode/decode call. The object is the same memoized config instance for
24
+ * every call to a given operation, so protocols can key per-operation
25
+ * preprocessing (handler construction, error maps) off its identity in a
26
+ * WeakMap.
27
+ */
28
+ export interface ProtocolOperationConfig {
29
+ readonly input?: S.Top;
30
+ readonly output?: S.Top;
31
+ readonly errors?: ReadonlyArray<ApiErrorClass>;
32
+ /**
33
+ * The wire operation name (e.g. the Smithy operation shape name). RPC-style
34
+ * protocols address operations by name (AWS JSON's `X-Amz-Target`, AWS
35
+ * Query's `Action=`) and unwrap responses by it; REST protocols ignore it.
36
+ */
37
+ readonly operationName?: string;
38
+ /**
39
+ * The smithy `smithy.api#endpoint` hostPrefix (e.g. `sync-` for Step
40
+ * Functions' StartSyncExecution). Protocols prepend it to the resolved
41
+ * endpoint host, substituting `{memberName}` labels from the input.
42
+ */
43
+ readonly endpointHostPrefix?: string;
44
+ readonly pagination?: Pagination.PaginatedTrait;
45
+ }
46
+
47
+ /**
48
+ * The Protocol service knows how to turn a value into an HTTP request using
49
+ * only the input schema's trait annotations, and how to turn a response back
50
+ * into an output value using the output schema's trait annotations.
51
+ *
52
+ * Swap implementations by providing a different `Layer<Protocol>`.
53
+ */
54
+ export class Protocol extends Context.Service<
55
+ Protocol,
56
+ {
57
+ readonly encode: (args: {
58
+ readonly input: unknown;
59
+ readonly inputAst: AST.AST;
60
+ /** The operation's config (memoized per operation — see {@link ProtocolOperationConfig}). */
61
+ readonly config: ProtocolOperationConfig;
62
+ }) => Effect.Effect<HttpClientRequest.HttpClientRequest>;
63
+ readonly decode: (args: {
64
+ readonly response: HttpClientResponse.HttpClientResponse;
65
+ readonly outputAst: AST.AST;
66
+ /**
67
+ * The operation's declared error classes (from `OperationConfig.errors`).
68
+ * Protocols use these to surface wire failures as the operation's typed
69
+ * errors — e.g. by consulting matcher metadata stamped on the class.
70
+ */
71
+ readonly errors: ReadonlyArray<ApiErrorClass>;
72
+ /** The operation's config (memoized per operation — see {@link ProtocolOperationConfig}). */
73
+ readonly config: ProtocolOperationConfig;
74
+ }) => Effect.Effect<unknown>;
75
+ }
76
+ >()("Protocol") {}
77
+
78
+ //#endregion
79
+
80
+ //#region Make
81
+
82
+ export type ApiErrorClass = {
83
+ new (...args: any[]): {
84
+ readonly _tag: string;
85
+ readonly message: string;
86
+ };
87
+ };
88
+
89
+ /**
90
+ * The shape of a generated SDK operation — usable two ways (mirrors the
91
+ * distilled repo's OperationMethod):
92
+ *
93
+ * 1. Direct call: `yield* operation(input)` — an Effect with requirements.
94
+ * 2. Yield first: `const fn = yield* operation` — captures the current
95
+ * context and returns a requirement-free call function.
96
+ *
97
+ * Generated service files annotate every exported operation with this type
98
+ * explicitly (against their hand-emitted interfaces), so the compiler never
99
+ * has to infer it back out of the schema generics.
100
+ */
101
+ export type OperationMethod<I, O, E, R> = Effect.Effect<
102
+ (input: I) => Effect.Effect<O, E, never>,
103
+ never,
104
+ R
105
+ > &
106
+ ((input: I) => Effect.Effect<O, E, R>);
107
+
108
+ // NOTE: request/response ASTs are handed to the protocol RAW (Suspend nodes
109
+ // included). Pre-resolving Suspends here would drop annotations that sit on
110
+ // intermediate nodes — e.g. a bare-payload response whose payload type is
111
+ // itself a suspended schema carries its EnvelopePayloadRoot marker on the
112
+ // inner Suspend, and unwrapping it silently degrades decode to the struct
113
+ // path. The protocol helpers (core/protocol-http getAnn/getProps) descend
114
+ // Suspends themselves, and `Suspend.thunk` memoizes, so raw ASTs cost
115
+ // nothing extra.
116
+
117
+ /**
118
+ * Protocol layers are built once per process and shared by every operation
119
+ * call (keyed by layer value identity — generated operations all reference the
120
+ * same module-level layer const). The build runs against a process-lifetime
121
+ * scope, and concurrent first calls are deduplicated through a private
122
+ * MemoMap.
123
+ *
124
+ * Contract for protocol implementations: the layer build must not capture
125
+ * per-call context. Anything call-dependent — credentials, per-request
126
+ * options — must be resolved inside `encode`/`decode`, which execute on the
127
+ * calling fiber and therefore see the caller's services on every request.
128
+ */
129
+ const protocolMemoMap = Layer.makeMemoMapUnsafe();
130
+ const protocolScope = Scope.makeUnsafe();
131
+ const protocolContexts = new WeakMap<
132
+ Layer.Layer<Protocol, any, any>,
133
+ Context.Context<Protocol>
134
+ >();
135
+
136
+ const protocolContext = <PE, PR>(
137
+ layer: Layer.Layer<Protocol, PE, PR>,
138
+ ): Effect.Effect<Context.Context<Protocol>, PE, PR> => {
139
+ const cached = protocolContexts.get(layer);
140
+ if (cached) return Effect.succeed(cached);
141
+ return Effect.map(
142
+ Layer.buildWithMemoMap(layer, protocolMemoMap, protocolScope),
143
+ (ctx) => {
144
+ protocolContexts.set(layer, ctx);
145
+ return ctx;
146
+ },
147
+ );
148
+ };
149
+
150
+ export interface OperationConfig<
151
+ I extends S.Top,
152
+ O extends S.Top,
153
+ PE,
154
+ PR,
155
+ E extends readonly ApiErrorClass[] = readonly ApiErrorClass[],
156
+ > {
157
+ input?: I;
158
+ output?: O;
159
+ errors?: E;
160
+ /**
161
+ * The protocol layer that knows how to encode/decode this operation's wire
162
+ * format. Built once per process and shared across all operations that
163
+ * reference the same layer value — it must resolve call-dependent services
164
+ * (credentials etc.) inside encode/decode, not at build time.
165
+ */
166
+ protocol: Layer.Layer<Protocol, PE, PR>;
167
+ /**
168
+ * SDK-specific retry service tag (see `core/retry`). When provided and the
169
+ * caller's context carries a policy under this tag, every call is retried
170
+ * per that policy (e.g. `Layer.succeed(Cloudflare.Retry.Retry, factory)`).
171
+ */
172
+ retry?: Context.Key<any, RetryPolicy>;
173
+ /**
174
+ * The wire operation name for RPC-style protocols (see
175
+ * {@link ProtocolOperationConfig.operationName}).
176
+ */
177
+ operationName?: string;
178
+ /**
179
+ * Host prefix from the smithy endpoint trait (see
180
+ * {@link ProtocolOperationConfig.endpointHostPrefix}).
181
+ */
182
+ endpointHostPrefix?: string;
183
+ }
184
+
185
+ /**
186
+ * Wrap one operation call with the caller-provided retry policy, if the
187
+ * operation declares a retry tag and the context carries a policy for it.
188
+ */
189
+ const applyRetry = (
190
+ base: Effect.Effect<any, any, any>,
191
+ retryKey: Context.Key<any, RetryPolicy> | undefined,
192
+ ): Effect.Effect<any, any, any> =>
193
+ retryKey === undefined
194
+ ? base
195
+ : Effect.flatMap(Effect.serviceOption(retryKey), (opt) =>
196
+ Effect.gen(function* () {
197
+ const lastError = yield* Ref.make<unknown>(undefined);
198
+ // No policy in context → makeDefault (transient/throttling/server
199
+ // errors, capped exponential backoff + jitter, honors server
200
+ // retryAfter hints). Mirrors the distilled client.
201
+ const policy = Option.isSome(opt) ? opt.value : makeDefault;
202
+ const opts =
203
+ typeof policy === "function" ? policy(lastError) : policy;
204
+ if (!opts.while) return yield* base;
205
+ return yield* base.pipe(
206
+ Effect.tapError((e) => Ref.set(lastError, e)),
207
+ Effect.retry({
208
+ while: (e: unknown) => opts.while!(e),
209
+ ...(opts.schedule ? { schedule: opts.schedule as any } : {}),
210
+ }),
211
+ );
212
+ }),
213
+ );
214
+
215
+ export function make<
216
+ I extends S.Top,
217
+ O extends S.Top,
218
+ PE,
219
+ PR,
220
+ const E extends readonly ApiErrorClass[] = readonly [],
221
+ >(
222
+ configFn: () => OperationConfig<I, O, PE, PR, E>,
223
+ ): OperationMethod<
224
+ S.Schema.Type<I>,
225
+ S.Schema.Type<O>,
226
+ InstanceType<E[number]> | PE | HttpClientError.HttpClientError,
227
+ PR | HttpClient.HttpClient
228
+ > {
229
+ // Lazily resolve the operation config + schema ASTs on first call, not at
230
+ // module-load time. Generated SDKs wrap each request/response schema in
231
+ // `Schema.suspend(() => ...)`; forcing them here (rather than when the
232
+ // `export const` is evaluated) keeps importing a service module cheap and
233
+ // only pays the schema-construction cost for operations that are actually
234
+ // called. Memoized so subsequent calls are free.
235
+ interface Prepared {
236
+ readonly cfg: OperationConfig<I, O, PE, PR, E>;
237
+ readonly inputAst: AST.AST;
238
+ readonly outputAst: AST.AST;
239
+ }
240
+ let prepared: Prepared | undefined;
241
+ const prepare = (): Prepared => {
242
+ if (prepared) return prepared;
243
+ const cfg = configFn();
244
+ prepared = {
245
+ cfg,
246
+ inputAst: cfg.input!.ast,
247
+ outputAst: cfg.output!.ast,
248
+ };
249
+ return prepared;
250
+ };
251
+ const fn = (input: unknown) =>
252
+ Effect.suspend(() => {
253
+ const { cfg, inputAst, outputAst } = prepare();
254
+ const call = Effect.flatMap(
255
+ protocolContext(cfg.protocol),
256
+ (protocolCtx) =>
257
+ Effect.gen(function* () {
258
+ const protocol = yield* Protocol;
259
+ const client = yield* HttpClient.HttpClient;
260
+ const request = yield* protocol.encode({
261
+ input,
262
+ inputAst,
263
+ config: cfg,
264
+ });
265
+ const response = yield* client.execute(request);
266
+ return yield* protocol.decode({
267
+ response,
268
+ outputAst,
269
+ errors: cfg.errors ?? [],
270
+ config: cfg,
271
+ });
272
+ }).pipe(Effect.provideContext(protocolCtx)),
273
+ );
274
+ return applyRetry(call, cfg.retry);
275
+ });
276
+
277
+ // Make the operation itself yieldable: `yield* operation` captures the
278
+ // current context and returns a requirement-free call function (mirrors
279
+ // the distilled repo's OperationMethod).
280
+ const Proto = {
281
+ [Symbol.iterator](this: any) {
282
+ return new SingleShotGen(this.asEffect());
283
+ },
284
+ pipe(this: any) {
285
+ return pipeArguments(this.asEffect(), arguments);
286
+ },
287
+ asEffect() {
288
+ return Effect.map(
289
+ Effect.context(),
290
+ (context) => (input: unknown) =>
291
+ Effect.provideContext(fn(input), context),
292
+ );
293
+ },
294
+ };
295
+ Object.assign(fn, Proto);
296
+
297
+ // Debug/introspection surface carried over from the distilled client:
298
+ // the operation's metadata is readable off the exported callable
299
+ // (e.g. `iam.listRoles.input` / `.output` / `.errors` / `.operationName`
300
+ // / `.pagination`). Lazy getters, so importing a service module doesn't
301
+ // force its suspended schemas.
302
+ Object.defineProperties(fn, {
303
+ input: { get: () => prepare().cfg.input, configurable: true },
304
+ output: { get: () => prepare().cfg.output, configurable: true },
305
+ errors: { get: () => prepare().cfg.errors ?? [], configurable: true },
306
+ operationName: {
307
+ get: () => prepare().cfg.operationName,
308
+ configurable: true,
309
+ },
310
+ pagination: {
311
+ get: () =>
312
+ (prepare().cfg as PaginatedOperationConfig<I, O, PE, PR, E>).pagination,
313
+ configurable: true,
314
+ },
315
+ });
316
+
317
+ return fn as any;
318
+ }
319
+
320
+ //#endregion
321
+
322
+ //#region MakePaginated
323
+
324
+ /**
325
+ * STRUCTURAL fallback for the element type `.items()` yields: the array
326
+ * element of the page response itself, or of its `result` member.
327
+ *
328
+ * It can only see shapes it was taught, so any other envelope
329
+ * (`{ branches: […] }`, `{ data: […] }`, …) lands on `unknown` — which is
330
+ * why generators pass the item type EXPLICITLY as
331
+ * {@link PaginatedOperationMethod}'s `Item` argument, resolved from the
332
+ * pagination trait's `items` path against the response shape. This default
333
+ * only applies to hand-written operations.
334
+ */
335
+ export type PaginatedItem<A> =
336
+ A extends ReadonlyArray<infer Item>
337
+ ? Item
338
+ : A extends { result: ReadonlyArray<infer Item> }
339
+ ? Item
340
+ : A extends { result?: ReadonlyArray<infer Item> | null | undefined }
341
+ ? Item
342
+ : unknown;
343
+
344
+ /**
345
+ * The callable half of a paginated operation: the operation call itself, plus
346
+ * `.pages(input)` streaming every page response and `.items(input)` streaming
347
+ * the individual items across pages.
348
+ *
349
+ * Used twice in {@link PaginatedOperationMethod} — once with the operation's
350
+ * requirements (`R`) for the direct-call style, once with `R = never` for the
351
+ * value `yield* operation` hands back, which has the caller's context baked in.
352
+ */
353
+ export interface PaginatedCall<I, O, E, R, Item> {
354
+ (input: I): Effect.Effect<O, E, R>;
355
+ readonly pages: (input: I) => Stream.Stream<O, E, R>;
356
+ readonly items: (input: I) => Stream.Stream<Item, E, R>;
357
+ }
358
+
359
+ /**
360
+ * A paginated operation: usable both ways an {@link OperationMethod} is, with
361
+ * `.pages` / `.items` on BOTH — the operation object for
362
+ * `yield* op.items(input)`, and the requirement-free call function for
363
+ * `const op = yield* operation; yield* op.items(input)` (distilled #145).
364
+ */
365
+ export type PaginatedOperationMethod<
366
+ I,
367
+ O,
368
+ E,
369
+ R,
370
+ Item = PaginatedItem<O>,
371
+ > = Effect.Effect<PaginatedCall<I, O, E, never, Item>, never, R> &
372
+ PaginatedCall<I, O, E, R, Item>;
373
+
374
+ export interface PaginatedOperationConfig<
375
+ I extends S.Top,
376
+ O extends S.Top,
377
+ PE,
378
+ PR,
379
+ E extends readonly ApiErrorClass[] = readonly ApiErrorClass[],
380
+ > extends OperationConfig<I, O, PE, PR, E> {
381
+ /** How to advance between pages (mirrors the `smithy.api#paginated` trait). */
382
+ pagination: Pagination.PaginatedTrait;
383
+ }
384
+
385
+ /**
386
+ * Like {@link make}, plus `.pages()` / `.items()` streaming built on the
387
+ * operation's pagination trait. The SDK can pass a provider-specific
388
+ * {@link Pagination.PaginationStrategy} (e.g. Cloudflare stops page-mode
389
+ * traversal on the first empty page); the default dispatches on
390
+ * `pagination.mode`.
391
+ */
392
+ export function makePaginated<
393
+ I extends S.Top,
394
+ O extends S.Top,
395
+ PE,
396
+ PR,
397
+ const E extends readonly ApiErrorClass[] = readonly [],
398
+ >(
399
+ configFn: () => PaginatedOperationConfig<I, O, PE, PR, E>,
400
+ strategy?: Pagination.PaginationStrategy,
401
+ ): PaginatedOperationMethod<
402
+ S.Schema.Type<I>,
403
+ S.Schema.Type<O>,
404
+ InstanceType<E[number]> | PE | HttpClientError.HttpClientError,
405
+ PR | HttpClient.HttpClient
406
+ > {
407
+ const fn: any = make(configFn);
408
+ // configFn is a cheap object literal over already-constructed consts —
409
+ // re-invoking it here just reads the pagination trait (memoized).
410
+ let pagination: Pagination.PaginatedTrait | undefined;
411
+ const pag = () => (pagination ??= configFn().pagination);
412
+ const paginate = strategy ?? Pagination.paginateWithDefaults;
413
+
414
+ // The streams are built over a CALL FUNCTION, so the same code serves both
415
+ // call styles: the operation itself (requirements intact), and the
416
+ // context-bound function `yield* operation` hands back — whose streams
417
+ // inherit that captured context and so need nothing after the yield.
418
+ const withStreams = (
419
+ call: (input: any) => Effect.Effect<any, any, any>,
420
+ ): any => {
421
+ const pages = (input: Record<string, unknown>) =>
422
+ paginate(call, input, pag());
423
+ const items = (input: Record<string, unknown>) => {
424
+ const p = pag();
425
+ return p.items
426
+ ? Pagination.extractItems(pages(input), p.items)
427
+ : pages(input);
428
+ };
429
+ return Object.assign(call, { pages, items });
430
+ };
431
+
432
+ // `yield* operation` runs through `make`'s Proto.asEffect, which builds a
433
+ // fresh arrow and would drop `.pages` / `.items` (distilled #145). Override
434
+ // it here — Proto's `[Symbol.iterator]`/`pipe` dispatch on `this`, so both
435
+ // pick this up. Only paginated operations pay for it.
436
+ fn.asEffect = () =>
437
+ Effect.map(Effect.context(), (context) =>
438
+ withStreams((input: unknown) =>
439
+ Effect.provideContext(fn(input), context),
440
+ ),
441
+ );
442
+
443
+ return withStreams(fn);
444
+ }
445
+
446
+ //#endregion