apps 0.0.1-beta.144 → 0.0.1-beta.148

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 (48) hide show
  1. package/README.md +14 -0
  2. package/framework-reference.json +1 -1
  3. package/js/{chunk-IWLFLMIL.js → chunk-4XXHO5UG.js} +3966 -1760
  4. package/js/{chunk-6OWHQINS.js → chunk-63BS5GBH.js} +2 -2
  5. package/js/{chunk-6NRWFVK2.js → chunk-ALZDZ3ZT.js} +3 -3
  6. package/js/{chunk-T4MICYGT.js → chunk-CQCY3OZS.js} +2 -2
  7. package/js/{chunk-QDF7PQAD.js → chunk-CWAPV2TN.js} +2 -2
  8. package/js/{chunk-5MEOL2SG.js → chunk-DX5DD6Z2.js} +6 -6
  9. package/js/{chunk-455CCO6Q.js → chunk-E2PVLAGK.js} +1 -1
  10. package/js/{chunk-AFEMXP3F.js → chunk-FWK2WTJB.js} +2 -2
  11. package/js/{chunk-2OGVSUNI.js → chunk-GWFQCQB5.js} +2 -2
  12. package/js/chunk-HEFJFDU4.js +87 -0
  13. package/js/{chunk-B2PSDMZP.js → chunk-I7MYW7IK.js} +2 -2
  14. package/js/{chunk-B4JN2A6F.js → chunk-MXFPSMNM.js} +1 -1
  15. package/js/{chunk-INQON4A2.js → chunk-OA4UYCJ4.js} +2 -2
  16. package/js/{chunk-OFSXKKD6.js → chunk-PUMGAWHB.js} +7 -7
  17. package/js/{chunk-W6V5OIHB.js → chunk-SEJXUMGT.js} +267 -1
  18. package/js/{chunk-BU3UOD2T.js → chunk-SXYFFXHM.js} +1 -1
  19. package/js/{chunk-BHSWVS3Q.js → chunk-UT2CBMW3.js} +4 -1
  20. package/js/{chunk-TMYRAFMC.js → chunk-ZWFMEH2Y.js} +18 -1
  21. package/js/client.js +30 -8
  22. package/js/contracts.js +1 -2
  23. package/js/effect.js +10 -11
  24. package/js/graphql.js +12 -13
  25. package/js/host.js +10 -11
  26. package/js/index.js +6 -7
  27. package/js/mcp/effect.js +11 -12
  28. package/js/mcp.js +13 -14
  29. package/js/openapi.js +8 -9
  30. package/js/react.js +122 -3
  31. package/js/skills/effect.js +1 -2
  32. package/js/skills.js +7 -8
  33. package/js/ui/auth/contracts.js +5 -1
  34. package/js/ui/auth.js +7 -4
  35. package/js/ui/contracts.js +52 -5
  36. package/js/ui/serving.js +55 -17
  37. package/package.json +1 -1
  38. package/runtime.json +1 -1
  39. package/types/apps/src/client.d.ts +3 -0
  40. package/types/apps/src/contracts/desktop-errors.d.ts +46 -0
  41. package/types/apps/src/contracts/desktop.d.ts +228 -0
  42. package/types/apps/src/contracts/ui-auth.d.ts +4 -1
  43. package/types/apps/src/contracts/ui.d.ts +43 -1
  44. package/types/apps/src/implementation/desktop.d.ts +85 -0
  45. package/types/apps/src/implementation/ui-serving.d.ts +13 -1
  46. package/types/apps/src/react.d.ts +29 -0
  47. package/types/apps/src/ui-serving.d.ts +1 -1
  48. package/js/chunk-QLUWYCOT.js +0 -2325
@@ -1,2325 +0,0 @@
1
- import {
2
- DecodeError,
3
- HttpClient,
4
- HttpClientError,
5
- StatusCodeError,
6
- appendUrlParams,
7
- blankType,
8
- bodyFormData,
9
- contentType,
10
- fixedMember,
11
- fromLiteral,
12
- get,
13
- getClosingParenthensePosition,
14
- hasBody,
15
- isHttpBody,
16
- isSocket,
17
- make as make2,
18
- mapRequest,
19
- prefixPath,
20
- prependUrl,
21
- setBody,
22
- setHeaders,
23
- setUrl,
24
- stream,
25
- text,
26
- uint8Array,
27
- upgrade,
28
- urlParams
29
- } from "./chunk-IWLFLMIL.js";
30
- import {
31
- Cause,
32
- CurrentRedactedNames,
33
- CurrentRedactedNames2,
34
- Defect,
35
- Forbidden,
36
- InvalidValue,
37
- Literal,
38
- Never,
39
- Never2,
40
- NonEmptyArray,
41
- Objects,
42
- PropertySignature,
43
- RecordFromUrlParams,
44
- SchemaError,
45
- Service,
46
- String as String2,
47
- Struct,
48
- TaggedClass,
49
- TaggedError,
50
- Transformation,
51
- Uint8Array as Uint8Array2,
52
- Undefined,
53
- UndefinedOr,
54
- Union,
55
- Union2,
56
- Unknown,
57
- UnknownFromJsonString,
58
- Void,
59
- add,
60
- all,
61
- applyToSelfOrLastLinkEncodingIdempotent,
62
- as,
63
- assignProperty,
64
- brand,
65
- catchCause,
66
- catchIf,
67
- combine2 as combine,
68
- constVoid,
69
- context,
70
- declare,
71
- decode2 as decode,
72
- decodeText,
73
- decodeTo,
74
- decodeTo2,
75
- decodeUnknownEffect2 as decodeUnknownEffect,
76
- die,
77
- done,
78
- empty,
79
- empty6 as empty2,
80
- encodeSync,
81
- encodeUnknownEffect2 as encodeUnknownEffect,
82
- ensure,
83
- escape,
84
- fail,
85
- fail2,
86
- fail4 as fail3,
87
- failCause2 as failCause,
88
- filter,
89
- flatMap2 as flatMap,
90
- fnUntraced,
91
- fromInput3 as fromInput,
92
- fromInputUnsafe,
93
- fromInputUnsafe2,
94
- fromJsonString,
95
- fromTransform,
96
- gen,
97
- getLastEncoding,
98
- getOrUndefined2 as getOrUndefined,
99
- hasProperty,
100
- identity,
101
- ignore,
102
- instanceOf,
103
- isArrayNonEmpty,
104
- isCause,
105
- isLiteral,
106
- isNotUndefined,
107
- isNull,
108
- isObject,
109
- isObjects,
110
- isOptional,
111
- isReadonlyArrayNonEmpty,
112
- isSchema,
113
- isStream,
114
- isSuspend,
115
- isUnion,
116
- isVoid,
117
- make3 as make,
118
- map2 as map,
119
- map3 as map2,
120
- map4 as map3,
121
- map5 as map4,
122
- map6 as map5,
123
- map8 as map6,
124
- mapArrayEffect,
125
- mapEffect,
126
- mapError,
127
- mapError3 as mapError2,
128
- mapOrSame,
129
- matchEffect,
130
- mebibytes,
131
- memoize,
132
- merge,
133
- millis,
134
- of,
135
- onError,
136
- optional,
137
- passthrough2 as passthrough,
138
- pipeArguments,
139
- pipeThroughChannel,
140
- pipeTo,
141
- provideContext,
142
- replaceContext,
143
- resolveAt,
144
- scoped,
145
- succeed,
146
- succeed4 as succeed2,
147
- suspend,
148
- sync2 as sync,
149
- tag,
150
- toCodecJson,
151
- toCodecStringTree,
152
- toEncoded,
153
- toNumberUnsafe,
154
- toString,
155
- toType,
156
- transform,
157
- transformEffect,
158
- transformOptional,
159
- transformPull,
160
- uninterruptibleMask,
161
- unwrap2 as unwrap,
162
- updateService,
163
- void_2 as void_
164
- } from "./chunk-NXEGROI6.js";
165
- import {
166
- __export
167
- } from "./chunk-CZ7CSFO4.js";
168
-
169
- // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http-api/HttpApiSchema.js
170
- var HttpApiSchema_exports = {};
171
- __export(HttpApiSchema_exports, {
172
- Accepted: () => Accepted,
173
- Created: () => Created,
174
- Empty: () => Empty,
175
- MultipartStreamTypeId: () => MultipartStreamTypeId,
176
- MultipartTypeId: () => MultipartTypeId,
177
- NoContent: () => NoContent,
178
- StreamNdjson: () => StreamNdjson,
179
- StreamSse: () => StreamSse,
180
- StreamUint8Array: () => StreamUint8Array,
181
- Upgrade: () => Upgrade,
182
- WithHeaders: () => WithHeaders,
183
- WithHeadersTypeId: () => WithHeadersTypeId,
184
- WithHeadersValueTypeId: () => WithHeadersValueTypeId,
185
- asFormUrlEncoded: () => asFormUrlEncoded,
186
- asJson: () => asJson,
187
- asMultipart: () => asMultipart,
188
- asMultipartStream: () => asMultipartStream,
189
- asNoContent: () => asNoContent,
190
- asProblem: () => asProblem,
191
- asText: () => asText,
192
- asUint8Array: () => asUint8Array,
193
- encodeToWithHeaders: () => encodeToWithHeaders,
194
- getEncodeToWithHeadersParts: () => getEncodeToWithHeadersParts,
195
- getPayloadEncoding: () => getPayloadEncoding,
196
- getResponseEncoding: () => getResponseEncoding,
197
- getResponseEncodingSchema: () => getResponseEncodingSchema,
198
- getStatusError: () => getStatusError,
199
- getStatusErrorSchema: () => getStatusErrorSchema,
200
- getStatusSuccess: () => getStatusSuccess,
201
- getStatusSuccessSchema: () => getStatusSuccessSchema,
202
- getWithHeadersAnnotation: () => getWithHeadersAnnotation,
203
- isNoContent: () => isNoContent,
204
- isStreamNdjson: () => isStreamNdjson,
205
- isStreamSchema: () => isStreamSchema,
206
- isStreamSse: () => isStreamSse,
207
- isStreamUint8Array: () => isStreamUint8Array,
208
- isUpgrade: () => isUpgrade,
209
- isWithHeaders: () => isWithHeaders,
210
- isWithHeadersValue: () => isWithHeadersValue,
211
- rebuildUpgrade: () => rebuildUpgrade,
212
- rebuildWithHeaders: () => rebuildWithHeaders,
213
- status: () => status,
214
- withHeaders: () => withHeaders
215
- });
216
-
217
- // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/encoding/Sse.js
218
- var SseErrorTypeId = "~effect/encoding/Sse/SseError";
219
- var EventTooLarge = class extends (/* @__PURE__ */ TaggedError("EventTooLarge")) {
220
- get message() {
221
- return `Pending SSE event exceeded the maximum size of ${this.maxEventSize}`;
222
- }
223
- };
224
- var SseError = class extends (/* @__PURE__ */ TaggedError("SseError")) {
225
- /**
226
- * Marks this value as an SSE decoding error.
227
- *
228
- * @stability unstable
229
- * @since 4.0.0
230
- */
231
- [SseErrorTypeId] = SseErrorTypeId;
232
- /**
233
- * Delegates the public message to the underlying SSE error reason.
234
- *
235
- * @stability unstable
236
- * @since 4.0.0
237
- */
238
- get message() {
239
- return this.reason.message;
240
- }
241
- };
242
- var defaultMaxEventSize = 10 * 1024 * 1024;
243
- var decode2 = (options2) => fromTransform((upstream, _scope) => sync(() => {
244
- let buffer = [];
245
- let retry;
246
- const parser = makeParser((event) => {
247
- if (event._tag === "Retry") {
248
- retry = event;
249
- } else {
250
- buffer.push(event);
251
- }
252
- }, options2);
253
- const pump = flatMap(upstream, (arr) => {
254
- for (let i = 0; i < arr.length; i++) {
255
- const error = parser.feed(arr[i]);
256
- if (error !== void 0) {
257
- return fail3(error);
258
- }
259
- }
260
- return void_;
261
- });
262
- return suspend(function loop() {
263
- if (isArrayNonEmpty(buffer)) {
264
- const out = buffer;
265
- buffer = [];
266
- return succeed2(out);
267
- } else if (retry) {
268
- return fail3(retry);
269
- }
270
- return flatMap(pump, loop);
271
- });
272
- }));
273
- var decodeSchema = (schema, options2, parseOptions) => pipeTo(decode2(options2), decode(Event.pipe(decodeTo2(schema, transformEvent)), parseOptions)());
274
- function makeParser(onParse, options2) {
275
- const maxEventSize = options2?.maxEventSize ?? defaultMaxEventSize;
276
- const dispatchEmptyNamedEvents = options2?.dispatchEmptyNamedEvents === true;
277
- let isFirstChunk;
278
- let pending;
279
- let pendingLength;
280
- let discardTrailingNewline;
281
- let generation = 0;
282
- let lastEventId;
283
- let eventName;
284
- let data;
285
- reset();
286
- return {
287
- feed,
288
- reset
289
- };
290
- function reset() {
291
- generation++;
292
- isFirstChunk = true;
293
- pending = [];
294
- pendingLength = 0;
295
- discardTrailingNewline = false;
296
- lastEventId = void 0;
297
- eventName = void 0;
298
- data = "";
299
- }
300
- function feed(chunk) {
301
- if (chunk.length === 0) return;
302
- if (isFirstChunk && chunk.startsWith(BOM)) {
303
- chunk = chunk.slice(BOM.length);
304
- }
305
- isFirstChunk = false;
306
- const length = chunk.length;
307
- const currentGeneration = generation;
308
- let position = 0;
309
- while (position < length) {
310
- if (discardTrailingNewline) {
311
- discardTrailingNewline = false;
312
- if (chunk.charCodeAt(position) === LF) {
313
- ++position;
314
- continue;
315
- }
316
- }
317
- let lineEnd = position;
318
- while (lineEnd < length) {
319
- const code = chunk.charCodeAt(lineEnd);
320
- if (code === CR || code === LF) break;
321
- ++lineEnd;
322
- }
323
- if (lineEnd === length) {
324
- pending.push(chunk.slice(position));
325
- pendingLength += length - position;
326
- break;
327
- }
328
- discardTrailingNewline = chunk.charCodeAt(lineEnd) === CR;
329
- let line = chunk.slice(position, lineEnd);
330
- if (pending.length > 0) {
331
- pending.push(line);
332
- line = pending.join("");
333
- pending = [];
334
- pendingLength = 0;
335
- }
336
- parseLine2(line);
337
- if (generation !== currentGeneration) {
338
- return;
339
- }
340
- position = lineEnd + 1;
341
- }
342
- if (pendingLength + data.length > maxEventSize) {
343
- const error = new SseError({
344
- reason: new EventTooLarge({
345
- maxEventSize
346
- })
347
- });
348
- reset();
349
- return error;
350
- }
351
- }
352
- function parseLine2(line) {
353
- if (line.length === 0) {
354
- const named = eventName !== void 0 && eventName !== "";
355
- const event = eventName || "message";
356
- const eventData = data;
357
- eventName = void 0;
358
- data = "";
359
- if (eventData.length > 0 || dispatchEmptyNamedEvents && named) {
360
- onParse({
361
- _tag: "Event",
362
- id: lastEventId,
363
- event,
364
- data: eventData.slice(0, -1)
365
- // remove trailing newline
366
- });
367
- }
368
- return;
369
- }
370
- const colon = line.indexOf(":");
371
- let field = line;
372
- let value = "";
373
- if (colon >= 0) {
374
- field = line.slice(0, colon);
375
- value = line.slice(line.charCodeAt(colon + 1) === SPACE ? colon + 2 : colon + 1);
376
- }
377
- if (field === "data") {
378
- data += value + "\n";
379
- } else if (field === "event") {
380
- eventName = value;
381
- } else if (field === "id" && !value.includes("\0")) {
382
- lastEventId = value;
383
- } else if (field === "retry" && /^\d+$/.test(value)) {
384
- const retry = parseInt(value, 10);
385
- onParse(new Retry({
386
- duration: millis(retry),
387
- lastEventId
388
- }));
389
- }
390
- }
391
- }
392
- var BOM = "\uFEFF";
393
- var LF = 10;
394
- var CR = 13;
395
- var SPACE = 32;
396
- var EventEncoded = /* @__PURE__ */ Struct({
397
- id: /* @__PURE__ */ optional(String2),
398
- event: String2,
399
- data: String2
400
- });
401
- var Event = /* @__PURE__ */ Struct({
402
- _tag: /* @__PURE__ */ tag("Event"),
403
- id: /* @__PURE__ */ UndefinedOr(String2),
404
- event: String2,
405
- data: String2
406
- });
407
- var transformEvent = /* @__PURE__ */ transform({
408
- decode: (event) => event.id === void 0 ? {
409
- event: event.event,
410
- data: event.data
411
- } : {
412
- id: event.id,
413
- event: event.event,
414
- data: event.data
415
- },
416
- encode: (event) => ({
417
- _tag: "Event",
418
- id: event.id,
419
- event: event.event ?? "message",
420
- data: event.data
421
- })
422
- });
423
- var RetryTypeId = "~effect/encoding/Sse/Retry";
424
- var Retry = class _Retry extends (/* @__PURE__ */ TaggedClass("Retry")) {
425
- /**
426
- * Marks this value as an SSE retry directive for runtime guards.
427
- *
428
- * @stability unstable
429
- * @since 4.0.0
430
- */
431
- [RetryTypeId] = RetryTypeId;
432
- /**
433
- * Returns `true` when the value is an SSE retry directive.
434
- *
435
- * @stability unstable
436
- * @since 4.0.0
437
- */
438
- static is(u) {
439
- return hasProperty(u, RetryTypeId);
440
- }
441
- /**
442
- * Separates SSE retry directives from regular event values.
443
- *
444
- * @stability unstable
445
- * @since 4.0.0
446
- */
447
- static filter(u) {
448
- return _Retry.is(u) ? succeed(u) : fail(u);
449
- }
450
- };
451
-
452
- // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http-api/internal/mediaType.js
453
- function normalize(contentType2) {
454
- const normalized = contentType2.toLowerCase().trim();
455
- const index = normalized.indexOf(";");
456
- return index === -1 ? normalized : normalized.slice(0, index).trim();
457
- }
458
-
459
- // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http-api/HttpApiSchema.js
460
- var StreamSchemaTypeId = "~effect/http-api/HttpApiSchema/Stream";
461
- function status(code) {
462
- const statusCode = typeof code === "string" ? fromLiteral(code) : code;
463
- return (self) => findHttpApiStatusAnnotation(self.ast) === void 0 ? self.annotateKey({
464
- httpApiStatus: statusCode
465
- }) : self.annotate({
466
- httpApiStatus: statusCode
467
- });
468
- }
469
- var Empty = (code) => Void.pipe(status(code));
470
- var NoContent = /* @__PURE__ */ Empty(204);
471
- var Created = /* @__PURE__ */ Empty(201);
472
- var Accepted = /* @__PURE__ */ Empty(202);
473
- function asNoContent(options2) {
474
- return (self) => {
475
- return Void.pipe(decodeTo2(toType(self), transform({
476
- decode: options2.decode,
477
- encode: constVoid
478
- })));
479
- };
480
- }
481
- function asProblem(options2) {
482
- return (self) => {
483
- const status2 = getStatusError(self.ast);
484
- const type = options2.type ?? blankType;
485
- const body = {
486
- type,
487
- status: status2,
488
- title: options2.title
489
- };
490
- const decode4 = options2.decode ?? (() => new self());
491
- const problem = Struct({
492
- type: tag(type),
493
- status: fixedMember(status2),
494
- title: fixedMember(options2.title)
495
- });
496
- return problem.pipe(decodeTo2(toType(self), transform({
497
- decode: decode4,
498
- encode: () => body
499
- })), asJson({
500
- contentType
501
- }));
502
- };
503
- }
504
- var streamSchema = /* @__PURE__ */ declare(isStream);
505
- var defaultMaxElementBytes = /* @__PURE__ */ mebibytes(1);
506
- var StreamSse = (options2) => {
507
- const events = options2.events ?? (options2.data === void 0 ? void 0 : Struct({
508
- ...EventEncoded.fields,
509
- data: fromJsonString(toCodecJson(options2.data))
510
- }));
511
- if (events === void 0) {
512
- throw new Error("StreamSse requires either an events schema or a data schema");
513
- }
514
- return make(streamSchema.ast, {
515
- [StreamSchemaTypeId]: StreamSchemaTypeId,
516
- _tag: "StreamSse",
517
- mode: "sse",
518
- sseMode: options2.events === void 0 ? "data" : "events",
519
- ...streamContentTypes(options2.contentType, "sse"),
520
- events,
521
- error: options2.error ?? Never2,
522
- keepAlive: options2.keepAlive === void 0 ? void 0 : fromInputUnsafe(options2.keepAlive)
523
- });
524
- };
525
- var StreamUint8Array = (options2) => make(streamSchema.ast, {
526
- [StreamSchemaTypeId]: StreamSchemaTypeId,
527
- _tag: "StreamUint8Array",
528
- mode: "uint8array",
529
- ...streamContentTypes(options2?.contentType, "uint8array"),
530
- maxBytes: options2?.maxBytes === void 0 ? void 0 : fromInputUnsafe2(options2.maxBytes)
531
- });
532
- var StreamNdjson = (options2) => make(streamSchema.ast, {
533
- [StreamSchemaTypeId]: StreamSchemaTypeId,
534
- _tag: "StreamNdjson",
535
- mode: "ndjson",
536
- ...streamContentTypes(options2.contentType, "ndjson"),
537
- schema: options2.schema,
538
- maxBytes: options2.maxBytes === void 0 ? void 0 : fromInputUnsafe2(options2.maxBytes),
539
- maxElementBytes: options2.maxElementBytes === void 0 ? defaultMaxElementBytes : fromInputUnsafe2(options2.maxElementBytes)
540
- });
541
- var isStreamSchema = (u) => isSchema(u) && hasProperty(u, StreamSchemaTypeId);
542
- var isStreamSse = (u) => isStreamSchema(u) && u._tag === "StreamSse";
543
- var isStreamUint8Array = (u) => isStreamSchema(u) && u._tag === "StreamUint8Array";
544
- var isStreamNdjson = (u) => isStreamSchema(u) && u._tag === "StreamNdjson";
545
- var UpgradeTypeId = "~effect/http-api/HttpApiSchema/Upgrade";
546
- var upgradeSchema = /* @__PURE__ */ declare(isSocket).pipe(/* @__PURE__ */ status(101));
547
- function Upgrade(options2) {
548
- if (options2.protocol.toLowerCase() === "websocket") {
549
- throw new Error("Upgrade does not support WebSocket");
550
- }
551
- const headers = options2.headers === void 0 || isSchema(options2.headers) ? options2.headers : Struct(options2.headers);
552
- return rebuildUpgrade(options2.protocol, headers);
553
- }
554
- var rebuildUpgrade = (protocol, headers) => make(upgradeSchema.ast, {
555
- [UpgradeTypeId]: UpgradeTypeId,
556
- protocol,
557
- headers
558
- });
559
- var isUpgrade = (u) => isSchema(u) && hasProperty(u, UpgradeTypeId);
560
- function streamContentTypes(contentType2, mode) {
561
- if (contentType2 === void 0) contentType2 = defaultStreamContentType(mode);
562
- if (typeof contentType2 === "string") return {
563
- contentType: contentType2,
564
- contentTypes: [contentType2]
565
- };
566
- if (!isReadonlyArrayNonEmpty(contentType2)) {
567
- throw new Error("Stream schemas require at least one content type");
568
- }
569
- const seen = /* @__PURE__ */ new Set();
570
- for (const entry of contentType2) {
571
- const normalized = normalize(entry);
572
- if (seen.has(normalized)) {
573
- throw new Error(`Duplicate stream content type: ${entry}`);
574
- }
575
- seen.add(normalized);
576
- }
577
- return {
578
- contentType: contentType2[0],
579
- contentTypes: contentType2
580
- };
581
- }
582
- function defaultStreamContentType(mode) {
583
- switch (mode) {
584
- case "sse":
585
- return "text/event-stream";
586
- case "uint8array":
587
- return "application/octet-stream";
588
- case "ndjson":
589
- return "application/x-ndjson";
590
- }
591
- }
592
- var WithHeadersTypeId = "~effect/http-api/HttpApiSchema/WithHeaders";
593
- var WithHeadersValueTypeId = "~effect/http-api/HttpApiSchema/WithHeadersValue";
594
- var isWithHeadersValue = (u) => hasProperty(u, WithHeadersValueTypeId);
595
- var withHeadersValueSchema = /* @__PURE__ */ declare(isWithHeadersValue);
596
- function WithHeaders(schema, headers) {
597
- if (isWithHeaders(schema)) {
598
- throw new Error("WithHeaders schemas cannot be nested");
599
- }
600
- if (isUpgrade(schema)) {
601
- throw new Error("WithHeaders cannot wrap an upgrade");
602
- }
603
- return make(withHeadersValueSchema.ast, {
604
- [WithHeadersTypeId]: WithHeadersTypeId,
605
- schema,
606
- headers: isSchema(headers) ? headers : Struct(headers)
607
- });
608
- }
609
- var withHeaders = (options2) => ({
610
- [WithHeadersValueTypeId]: WithHeadersValueTypeId,
611
- body: options2.body,
612
- headers: options2.headers
613
- });
614
- var isWithHeaders = (u) => isSchema(u) && hasProperty(u, WithHeadersTypeId);
615
- function rebuildWithHeaders(self, schema, headers) {
616
- return make(self.ast, {
617
- [WithHeadersTypeId]: WithHeadersTypeId,
618
- schema,
619
- headers
620
- });
621
- }
622
- function encodeToWithHeaders(options2, transformation) {
623
- return (self) => {
624
- const body = options2.body;
625
- if (isUpgrade(body)) {
626
- throw new Error("encodeToWithHeaders cannot wrap an upgrade");
627
- }
628
- const headers = Struct(options2.headers);
629
- const status2 = resolveHttpApiStatus(body.ast);
630
- const encoding = resolveHttpApiEncoding(body.ast);
631
- return Struct({
632
- body,
633
- headers
634
- }).pipe(decodeTo2(toType(self), transform(transformation))).annotate({
635
- "~httpApiWithHeaders": {
636
- body,
637
- headers,
638
- bodyCodec: body,
639
- headersCodec: headers,
640
- transformation
641
- },
642
- httpApiStatus: status2,
643
- "~httpApiEncoding": encoding
644
- });
645
- };
646
- }
647
- var MultipartTypeId = "~effect/http-api/HttpApiSchema/Multipart";
648
- function asMultipart(options2) {
649
- return (self) => self.pipe(brand(MultipartTypeId)).annotate({
650
- "~httpApiEncoding": {
651
- _tag: "Multipart",
652
- mode: "buffered",
653
- contentType: defaultContentType("Multipart"),
654
- limits: options2
655
- }
656
- });
657
- }
658
- var MultipartStreamTypeId = "~effect/http-api/HttpApiSchema/MultipartStream";
659
- function asMultipartStream(options2) {
660
- return (self) => self.pipe(brand(MultipartStreamTypeId)).annotate({
661
- "~httpApiEncoding": {
662
- _tag: "Multipart",
663
- mode: "stream",
664
- contentType: defaultContentType("Multipart"),
665
- limits: options2
666
- }
667
- });
668
- }
669
- function asNonMultipartEncoding(self, options2) {
670
- return self.annotate({
671
- "~httpApiEncoding": {
672
- _tag: options2._tag,
673
- contentType: options2.contentType ?? defaultContentType(options2._tag)
674
- }
675
- });
676
- }
677
- function defaultContentType(_tag) {
678
- switch (_tag) {
679
- case "Multipart":
680
- return "multipart/form-data";
681
- case "Json":
682
- return "application/json";
683
- case "FormUrlEncoded":
684
- return "application/x-www-form-urlencoded";
685
- case "Uint8Array":
686
- return "application/octet-stream";
687
- case "Text":
688
- return "text/plain";
689
- }
690
- }
691
- function asJson(options2) {
692
- return (self) => asNonMultipartEncoding(self, {
693
- _tag: "Json",
694
- ...options2
695
- });
696
- }
697
- function asFormUrlEncoded(options2) {
698
- return (self) => asNonMultipartEncoding(self, {
699
- _tag: "FormUrlEncoded",
700
- ...options2
701
- });
702
- }
703
- function asText(options2) {
704
- return (self) => asNonMultipartEncoding(self, {
705
- _tag: "Text",
706
- ...options2
707
- });
708
- }
709
- function asUint8Array(options2) {
710
- return (self) => asNonMultipartEncoding(self, {
711
- _tag: "Uint8Array",
712
- ...options2
713
- });
714
- }
715
- var isNoContent = (ast) => {
716
- if (isVoid(ast)) return true;
717
- const encoded = toEncoded(ast);
718
- if (isVoid(encoded)) return true;
719
- const target = ast.encoding?.[0].to;
720
- if (target === void 0) return false;
721
- return isVoid(target);
722
- };
723
- var resolveHttpApiEncoding = /* @__PURE__ */ resolveAt("~httpApiEncoding");
724
- var getWithHeadersAnnotation = /* @__PURE__ */ resolveAt("~httpApiWithHeaders");
725
- function getEncodeToWithHeadersParts(schema) {
726
- const annotation = getWithHeadersAnnotation(schema.ast);
727
- return annotation === void 0 ? void 0 : {
728
- body: annotation.body,
729
- headers: annotation.headers
730
- };
731
- }
732
- function findHttpApiStatusAnnotation(ast) {
733
- if (ast.checks) {
734
- for (let i = ast.checks.length - 1; i >= 0; i--) {
735
- const check = ast.checks[i];
736
- if (check.annotations && "httpApiStatus" in check.annotations) return check.annotations;
737
- if (check._tag === "FilterGroup") {
738
- const annotations2 = findHttpApiStatusAnnotation(check);
739
- if (annotations2 !== void 0) return annotations2;
740
- }
741
- }
742
- }
743
- const annotations = ast.annotations;
744
- return annotations && "httpApiStatus" in annotations ? annotations : void 0;
745
- }
746
- function resolveHttpApiStatus(ast) {
747
- const annotations = findHttpApiStatusAnnotation(ast);
748
- if (annotations !== void 0) return annotations.httpApiStatus;
749
- return ast.context?.annotations?.httpApiStatus;
750
- }
751
- var defaultJsonEncoding = {
752
- _tag: "Json",
753
- contentType: "application/json"
754
- };
755
- var defaultUrlEncodedEncoding = {
756
- _tag: "FormUrlEncoded",
757
- contentType: "application/x-www-form-urlencoded"
758
- };
759
- function getEncoding(ast) {
760
- return resolveHttpApiEncoding(ast) ?? defaultJsonEncoding;
761
- }
762
- function getPayloadEncoding(ast, method) {
763
- const encoding = resolveHttpApiEncoding(ast);
764
- if (encoding) return encoding;
765
- return hasBody(method) ? defaultJsonEncoding : defaultUrlEncodedEncoding;
766
- }
767
- function getResponseEncoding(ast) {
768
- const out = getEncoding(ast);
769
- if (out._tag === "Multipart") {
770
- throw new Error("Multipart is not supported in response");
771
- }
772
- return out;
773
- }
774
- function getStatusSuccess(self) {
775
- return resolveHttpApiStatus(self) ?? 200;
776
- }
777
- function getStatusSuccessSchema(schema) {
778
- if (isWithHeaders(schema)) {
779
- return resolveHttpApiStatus(schema.ast) ?? getStatusSuccess(schema.schema.ast);
780
- }
781
- return getStatusSuccess(schema.ast);
782
- }
783
- function getResponseEncodingSchema(schema) {
784
- if (isWithHeaders(schema) && resolveHttpApiEncoding(schema.ast) === void 0) {
785
- return getResponseEncoding(schema.schema.ast);
786
- }
787
- return getResponseEncoding(schema.ast);
788
- }
789
- function getStatusError(self) {
790
- return resolveHttpApiStatus(self) ?? 500;
791
- }
792
- function getStatusErrorSchema(schema) {
793
- if (isWithHeaders(schema)) {
794
- return resolveHttpApiStatus(schema.ast) ?? getStatusError(schema.schema.ast);
795
- }
796
- return getStatusError(schema.ast);
797
- }
798
-
799
- // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http-api/HttpApiEndpoint.js
800
- var HttpApiEndpoint_exports = {};
801
- __export(HttpApiEndpoint_exports, {
802
- delete: () => del,
803
- get: () => get2,
804
- getErrorSchemas: () => getErrorSchemas,
805
- getPayloadSchemas: () => getPayloadSchemas,
806
- getSuccessSchemas: () => getSuccessSchemas,
807
- head: () => head,
808
- isHttpApiEndpoint: () => isHttpApiEndpoint,
809
- make: () => make3,
810
- options: () => options,
811
- patch: () => patch,
812
- post: () => post,
813
- put: () => put,
814
- query: () => query
815
- });
816
-
817
- // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http-api/internal/toCodecHttpProperties.js
818
- function toCodecHttpProperties(schema) {
819
- const codec = toCodecStringTree(schema);
820
- return codec.rebuild(normalizeProperties(codec.ast));
821
- }
822
- var omitUndefined = /* @__PURE__ */ new Transformation(/* @__PURE__ */ passthrough(), /* @__PURE__ */ transformOptional(/* @__PURE__ */ filter(isNotUndefined)));
823
- var present = /* @__PURE__ */ memoize((ast) => {
824
- if (ast._tag === "Undefined") return new Never(ast.annotations, void 0, void 0, ast.context);
825
- if (ast._tag === "Suspend") return ast.recur(present);
826
- if (ast._tag !== "Union") return ast;
827
- const members = mapOrSame(ast.types, present);
828
- if (members === ast.types) return ast;
829
- const types = members.filter((member) => member._tag !== "Never");
830
- if (types.length === 1 && ast.checks === void 0 && ast.annotations === void 0) {
831
- return replaceContext(types[0], ast.context);
832
- }
833
- return new Union(types, ast.options, ast.annotations, ast.checks, void 0, ast.context);
834
- });
835
- var normalizeProperties = /* @__PURE__ */ applyToSelfOrLastLinkEncodingIdempotent((ast) => {
836
- if (ast._tag === "Union" || ast._tag === "Suspend") return ast.recur(normalizeProperties);
837
- if (ast._tag !== "Objects") return ast;
838
- const properties = mapOrSame(ast.propertySignatures, (ps) => {
839
- const encoded = toEncoded(ps.type);
840
- if (!isOptional(encoded)) return ps;
841
- const wire = present(encoded);
842
- return wire === encoded ? ps : new PropertySignature(ps.name, decodeTo(wire, ps.type, omitUndefined));
843
- });
844
- return properties === ast.propertySignatures ? ast : new Objects(properties, ast.indexSignatures, ast.annotations, ast.checks, void 0, ast.context, ast.encodingChecks);
845
- });
846
-
847
- // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http-api/HttpApiEndpoint.js
848
- var TypeId = "~effect/http-api/HttpApiEndpoint";
849
- var isHttpApiEndpoint = (u) => hasProperty(u, TypeId);
850
- function getPayloadSchemas(endpoint2) {
851
- const result = [];
852
- for (const {
853
- schemas
854
- } of endpoint2.payload.values()) {
855
- result.push(...schemas);
856
- }
857
- return result;
858
- }
859
- function getSuccessSchemas(endpoint2) {
860
- const schemas = Array.from(endpoint2.success);
861
- return isArrayNonEmpty(schemas) ? schemas : [NoContent];
862
- }
863
- function getErrorSchemas(endpoint2) {
864
- const schemas = new Set(endpoint2.error);
865
- const transform2 = endpoint2.disableCodecs ? identity : transformResponseSchema;
866
- for (const middleware of endpoint2.middlewares) {
867
- const key = middleware;
868
- for (const schema of key.error) {
869
- schemas.add(transform2(schema));
870
- }
871
- }
872
- return Array.from(schemas);
873
- }
874
- var Proto = {
875
- [TypeId]: TypeId,
876
- pipe() {
877
- return pipeArguments(this, arguments);
878
- },
879
- prefix(prefix) {
880
- return makeProto({
881
- ...optionsFromEndpoint(this),
882
- path: prefixPath(this.path, prefix)
883
- });
884
- },
885
- middleware(middleware) {
886
- return makeProto({
887
- ...optionsFromEndpoint(this),
888
- middlewares: /* @__PURE__ */ new Set([...this.middlewares, middleware])
889
- });
890
- },
891
- annotate(key, value) {
892
- return makeProto({
893
- ...optionsFromEndpoint(this),
894
- annotations: add(this.annotations, key, value)
895
- });
896
- },
897
- annotateMerge(annotations) {
898
- return makeProto({
899
- ...optionsFromEndpoint(this),
900
- annotations: merge(this.annotations, annotations)
901
- });
902
- }
903
- };
904
- var optionsFromEndpoint = (endpoint2) => ({
905
- identifier: endpoint2.identifier,
906
- path: endpoint2.path,
907
- method: endpoint2.method,
908
- params: endpoint2.params,
909
- query: endpoint2.query,
910
- headers: endpoint2.headers,
911
- payload: endpoint2.payload,
912
- success: endpoint2.success,
913
- error: endpoint2.error,
914
- annotations: endpoint2.annotations,
915
- middlewares: endpoint2.middlewares,
916
- disableCodecs: endpoint2.disableCodecs
917
- });
918
- function makeProto(options2) {
919
- function HttpApiEndpoint() {
920
- }
921
- Object.setPrototypeOf(HttpApiEndpoint, Proto);
922
- return Object.assign(HttpApiEndpoint, options2);
923
- }
924
- var make3 = (method) => (identifier, path, options2) => {
925
- const disableCodecs = options2?.disableCodecs ?? false;
926
- const transformProperties = disableCodecs ? identity : toCodecHttpProperties;
927
- const payload = getPayload(options2?.payload, method, disableCodecs);
928
- return makeProto({
929
- identifier,
930
- path,
931
- method,
932
- params: ensureStruct(options2?.params, transformProperties),
933
- query: ensureStruct(options2?.query, transformProperties),
934
- headers: ensureStruct(options2?.headers, transformProperties),
935
- payload,
936
- success: getSuccessResponse(options2?.success, method, payload, disableCodecs),
937
- error: getErrorResponse(options2?.error, disableCodecs),
938
- annotations: empty(),
939
- middlewares: /* @__PURE__ */ new Set(),
940
- disableCodecs
941
- });
942
- };
943
- function ensureStruct(params, transform2) {
944
- if (params === void 0) return void 0;
945
- if (isSchema(params)) return transform2(params);
946
- return transform2(Struct(params));
947
- }
948
- function getPayload(payload, method, disableCodecs) {
949
- const result = /* @__PURE__ */ new Map();
950
- if (payload === void 0) return result;
951
- const schemas = Array.isArray(payload) ? payload : isSchema(payload) ? [payload] : [Struct(payload).pipe(asFormUrlEncoded())];
952
- const transform2 = disableCodecs ? identity : transformPayload;
953
- let hasStream = false;
954
- for (const schema of schemas) {
955
- if (isStreamSchema(schema)) {
956
- if (isStreamSse(schema)) {
957
- throw new Error("StreamSse is response-only and cannot be used as a payload");
958
- }
959
- if (!hasBody(method)) {
960
- throw new Error(`${method} endpoints cannot declare a streaming payload`);
961
- }
962
- if (hasStream) {
963
- throw new Error("Multiple streaming payloads are not supported");
964
- }
965
- hasStream = true;
966
- for (const declared of schema.contentTypes) {
967
- const contentType3 = normalize(declared);
968
- if (result.has(contentType3)) {
969
- throw new Error(`Cannot combine buffered and streaming payloads for content-type: ${declared}`);
970
- }
971
- result.set(contentType3, {
972
- encoding: {
973
- _tag: "Stream",
974
- contentType: declared
975
- },
976
- schemas: [schema]
977
- });
978
- }
979
- continue;
980
- }
981
- const encoding = getPayloadEncoding(schema.ast, method);
982
- const contentType2 = normalize(encoding.contentType);
983
- const existing = result.get(contentType2);
984
- if (existing) {
985
- if (existing.encoding._tag === "Stream") {
986
- throw new Error(`Cannot combine buffered and streaming payloads for content-type: ${encoding.contentType}`);
987
- }
988
- if (existing.encoding._tag !== encoding._tag) {
989
- throw new Error(`Multiple payload encodings for content-type: ${encoding.contentType}`);
990
- }
991
- if (existing.encoding._tag === "Multipart") {
992
- throw new Error(`Multiple multipart payloads for content-type: ${encoding.contentType}`);
993
- }
994
- existing.schemas.push(transform2(schema, method));
995
- } else {
996
- result.set(contentType2, {
997
- encoding,
998
- schemas: [transform2(schema, method)]
999
- });
1000
- }
1001
- }
1002
- return result;
1003
- }
1004
- var reservedStreamFailureEvent = "effect/http-api/stream/failure";
1005
- function getSuccessResponse(success, method, payload, disableCodecs) {
1006
- if (success === void 0) return /* @__PURE__ */ new Set();
1007
- const schemas = ensure(success);
1008
- validateSuccessResponse(schemas, method, payload);
1009
- return new Set(disableCodecs ? schemas : schemas.map(transformResponseSchema));
1010
- }
1011
- var transformResponseSchema = /* @__PURE__ */ memoize((schema) => {
1012
- if (isStreamSchema(schema)) return schema;
1013
- if (isUpgrade(schema)) {
1014
- return schema.headers === void 0 ? schema : rebuildUpgrade(schema.protocol, toCodecHttpProperties(schema.headers));
1015
- }
1016
- if (isWithHeaders(schema)) {
1017
- const inner = isStreamSchema(schema.schema) ? schema.schema : applyResponseEncoding(schema.schema, getResponseEncodingSchema(schema));
1018
- return rebuildWithHeaders(schema, inner, toCodecHttpProperties(schema.headers));
1019
- }
1020
- return transformResponse(schema);
1021
- });
1022
- function getErrorResponse(error, disableCodecs) {
1023
- if (error === void 0) return /* @__PURE__ */ new Set();
1024
- const schemas = ensure(error);
1025
- for (const schema of schemas) {
1026
- const body = isWithHeaders(schema) ? schema.schema : schema;
1027
- if (isStreamSchema(body)) {
1028
- throw new Error("Streaming schemas are not supported in error responses");
1029
- }
1030
- if (isUpgrade(body)) {
1031
- throw new Error("Upgrade schemas are not supported in error responses");
1032
- }
1033
- }
1034
- validateResponseExclusivity(schemas, getStatusErrorSchema);
1035
- return new Set(disableCodecs ? schemas : schemas.map(transformResponseSchema));
1036
- }
1037
- function validateSuccessResponse(schemas, method, payload) {
1038
- const upgrades = schemas.filter(isUpgrade);
1039
- if (upgrades.length > 1) {
1040
- throw new Error("Cannot declare more than one upgrade");
1041
- }
1042
- const hasUpgrade = upgrades.length === 1;
1043
- if (hasUpgrade) {
1044
- if (method === "HEAD") {
1045
- throw new Error("HEAD endpoints cannot declare an upgrade");
1046
- }
1047
- for (const {
1048
- encoding
1049
- } of payload.values()) {
1050
- if (encoding._tag === "Stream" || encoding._tag === "Multipart" && encoding.mode === "stream") {
1051
- throw new Error("Upgrade endpoints cannot declare a streaming payload");
1052
- }
1053
- }
1054
- }
1055
- let hasStream = false;
1056
- const statuses = /* @__PURE__ */ new Map();
1057
- for (const schema of schemas) {
1058
- if (isUpgrade(schema)) continue;
1059
- const inner = isWithHeaders(schema) ? schema.schema : schema;
1060
- const status2 = getStatusSuccessSchema(schema);
1061
- if (hasUpgrade && status2 === 101) {
1062
- throw new Error("Cannot combine an upgrade with another success response for status: 101");
1063
- }
1064
- if (isStreamSchema(inner)) {
1065
- if (hasUpgrade) {
1066
- throw new Error("Cannot combine an upgrade with a streaming success response");
1067
- }
1068
- validateStreamSuccess(inner, method);
1069
- if (hasStream) {
1070
- throw new Error("Multiple streaming success responses are not supported");
1071
- }
1072
- hasStream = true;
1073
- const entry = getStatusEntry(statuses, status2);
1074
- if (entry.noContent) {
1075
- throw new Error(`Cannot combine no-content and streaming success responses for status: ${status2}`);
1076
- }
1077
- for (const declared of inner.contentTypes) {
1078
- if (entry.bufferedContentTypes.has(normalize(declared))) {
1079
- throw new Error(`Cannot combine buffered and streaming success responses for status ${status2} and content-type: ${declared}`);
1080
- }
1081
- }
1082
- statuses.set(status2, {
1083
- ...entry,
1084
- stream: inner
1085
- });
1086
- } else {
1087
- const entry = getStatusEntry(statuses, status2);
1088
- const noContent = isNoContent(inner.ast);
1089
- if (entry.stream !== void 0) {
1090
- if (noContent) {
1091
- throw new Error(`Cannot combine no-content and streaming success responses for status: ${status2}`);
1092
- }
1093
- const encoding = getResponseEncodingSchema(schema);
1094
- const contentType2 = normalize(encoding.contentType);
1095
- if (entry.stream.contentTypes.some((declared) => normalize(declared) === contentType2)) {
1096
- throw new Error(`Cannot combine buffered and streaming success responses for status ${status2} and content-type: ${encoding.contentType}`);
1097
- }
1098
- }
1099
- if (!noContent) {
1100
- entry.bufferedContentTypes.add(normalize(getResponseEncodingSchema(schema).contentType));
1101
- }
1102
- entry.noContent = entry.noContent || noContent;
1103
- }
1104
- }
1105
- validateResponseExclusivity(schemas, getStatusSuccessSchema);
1106
- }
1107
- function getStatusEntry(statuses, status2) {
1108
- let entry = statuses.get(status2);
1109
- if (entry === void 0) {
1110
- entry = {
1111
- bufferedContentTypes: /* @__PURE__ */ new Set(),
1112
- noContent: false
1113
- };
1114
- statuses.set(status2, entry);
1115
- }
1116
- return entry;
1117
- }
1118
- function validateResponseExclusivity(schemas, getStatus) {
1119
- const statuses = /* @__PURE__ */ new Map();
1120
- for (const schema of schemas) {
1121
- const status2 = getStatus(schema);
1122
- const withHeadersAnnotation = getWithHeadersAnnotation(schema.ast);
1123
- const body = isWithHeaders(schema) ? schema.schema : withHeadersAnnotation?.body ?? schema;
1124
- const contentType2 = isNoContent(body.ast) ? "" : normalize(isStreamSchema(body) ? body.contentType : getResponseEncodingSchema(schema).contentType);
1125
- let entry = statuses.get(status2);
1126
- if (entry === void 0) {
1127
- entry = {
1128
- headerContentType: void 0,
1129
- plainContentTypes: /* @__PURE__ */ new Set()
1130
- };
1131
- statuses.set(status2, entry);
1132
- }
1133
- const combineError = () => new Error(`Cannot combine a response with headers with another response for status ${status2} and content-type: ${contentType2 || "<no content>"}`);
1134
- if (isWithHeaders(schema) || withHeadersAnnotation !== void 0) {
1135
- if (entry.headerContentType !== void 0) {
1136
- throw new Error(`Cannot declare multiple responses with headers for status ${status2}`);
1137
- }
1138
- if (entry.plainContentTypes.has(contentType2)) throw combineError();
1139
- entry.headerContentType = contentType2;
1140
- } else {
1141
- if (entry.headerContentType === contentType2) throw combineError();
1142
- entry.plainContentTypes.add(contentType2);
1143
- }
1144
- }
1145
- }
1146
- function validateStreamSuccess(schema, method) {
1147
- if (method === "HEAD") {
1148
- throw new Error("HEAD endpoints cannot declare streaming success responses");
1149
- }
1150
- if (isStreamSse(schema) && hasReservedSseEventName(schema.events.ast)) {
1151
- throw new Error(`SSE event name is reserved: ${reservedStreamFailureEvent}`);
1152
- }
1153
- }
1154
- function hasReservedSseEventName(ast) {
1155
- return hasReservedEventName(toEncoded(ast), /* @__PURE__ */ new Set());
1156
- }
1157
- function hasReservedEventName(ast, seen) {
1158
- if (seen.has(ast)) return false;
1159
- seen.add(ast);
1160
- if (isUnion(ast)) {
1161
- return ast.types.some((type) => hasReservedEventName(type, seen));
1162
- }
1163
- if (isSuspend(ast)) {
1164
- return hasReservedEventName(ast.thunk(), seen);
1165
- }
1166
- if (!isObjects(ast)) return false;
1167
- const event = ast.propertySignatures.find((ps) => ps.name === "event");
1168
- return event !== void 0 && hasReservedEventLiteral(event.type, seen);
1169
- }
1170
- function hasReservedEventLiteral(ast, seen) {
1171
- if (seen.has(ast)) return false;
1172
- seen.add(ast);
1173
- const encoded = toEncoded(ast);
1174
- if (encoded !== ast) {
1175
- return hasReservedEventLiteral(encoded, seen);
1176
- }
1177
- if (isLiteral(ast)) {
1178
- return ast.literal === reservedStreamFailureEvent;
1179
- }
1180
- if (isUnion(ast)) {
1181
- return ast.types.some((type) => hasReservedEventLiteral(type, seen));
1182
- }
1183
- if (isSuspend(ast)) {
1184
- return hasReservedEventLiteral(ast.thunk(), seen);
1185
- }
1186
- return false;
1187
- }
1188
- function transformResponse(schema) {
1189
- const encoding = getResponseEncoding(schema.ast);
1190
- const withHeaders2 = getWithHeadersAnnotation(schema.ast);
1191
- if (withHeaders2 === void 0) {
1192
- return applyResponseEncoding(schema, encoding);
1193
- }
1194
- return schema.annotate({
1195
- "~httpApiWithHeaders": {
1196
- ...withHeaders2,
1197
- bodyCodec: applyResponseEncoding(withHeaders2.body, encoding),
1198
- headersCodec: toCodecHttpProperties(withHeaders2.headers)
1199
- }
1200
- });
1201
- }
1202
- function applyResponseEncoding(schema, encoding) {
1203
- switch (encoding._tag) {
1204
- case "Json":
1205
- return toCodecJson(schema);
1206
- case "FormUrlEncoded":
1207
- return toCodecStringTree(schema);
1208
- case "Text":
1209
- case "Uint8Array":
1210
- return schema;
1211
- }
1212
- }
1213
- function transformPayload(schema, method) {
1214
- if (!hasBody(method)) return toCodecHttpProperties(schema);
1215
- const encoding = getPayloadEncoding(schema.ast, method);
1216
- switch (encoding._tag) {
1217
- case "Json":
1218
- return toCodecJson(schema);
1219
- case "FormUrlEncoded":
1220
- return toCodecStringTree(schema);
1221
- case "Text":
1222
- case "Uint8Array":
1223
- case "Multipart":
1224
- return schema;
1225
- }
1226
- }
1227
- var get2 = /* @__PURE__ */ make3("GET");
1228
- var query = /* @__PURE__ */ make3("QUERY");
1229
- var post = /* @__PURE__ */ make3("POST");
1230
- var put = /* @__PURE__ */ make3("PUT");
1231
- var patch = /* @__PURE__ */ make3("PATCH");
1232
- var del = /* @__PURE__ */ make3("DELETE");
1233
- var head = /* @__PURE__ */ make3("HEAD");
1234
- var options = /* @__PURE__ */ make3("OPTIONS");
1235
-
1236
- // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http-api/HttpApi.js
1237
- var HttpApi_exports = {};
1238
- __export(HttpApi_exports, {
1239
- AdditionalSchemas: () => AdditionalSchemas,
1240
- ErrorParseOptions: () => ErrorParseOptions,
1241
- HeadersParseOptions: () => HeadersParseOptions,
1242
- ParamsParseOptions: () => ParamsParseOptions,
1243
- ParseOptions: () => ParseOptions,
1244
- PayloadParseOptions: () => PayloadParseOptions,
1245
- QueryParseOptions: () => QueryParseOptions,
1246
- RedactedNames: () => RedactedNames,
1247
- SuccessParseOptions: () => SuccessParseOptions,
1248
- getEndpointRedactedNames: () => getEndpointRedactedNames,
1249
- getSlotParseOptions: () => getSlotParseOptions,
1250
- isHttpApi: () => isHttpApi,
1251
- make: () => make4,
1252
- reflect: () => reflect
1253
- });
1254
- var TypeId2 = "~effect/http-api/HttpApi";
1255
- var isHttpApi = (u) => hasProperty(u, TypeId2);
1256
- var Proto2 = {
1257
- [TypeId2]: TypeId2,
1258
- pipe() {
1259
- return pipeArguments(this, arguments);
1260
- },
1261
- add(...toAdd) {
1262
- const groups = {
1263
- ...this.groups
1264
- };
1265
- for (const group2 of toAdd) {
1266
- assignProperty(groups, group2.identifier, group2);
1267
- }
1268
- return makeProto2({
1269
- ...optionsFromApi(this),
1270
- groups
1271
- });
1272
- },
1273
- addHttpApi(api) {
1274
- const newGroups = {
1275
- ...this.groups
1276
- };
1277
- for (const key of Object.keys(api.groups)) {
1278
- const group2 = api.groups[key];
1279
- assignProperty(newGroups, key, group2.annotateMerge(merge(api.annotations, group2.annotations)));
1280
- }
1281
- return makeProto2({
1282
- ...optionsFromApi(this),
1283
- groups: newGroups
1284
- });
1285
- },
1286
- prefix(prefix) {
1287
- return makeProto2({
1288
- ...optionsFromApi(this),
1289
- groups: map(this.groups, (group2) => group2.prefix(prefix))
1290
- });
1291
- },
1292
- middleware(tag2) {
1293
- return makeProto2({
1294
- ...optionsFromApi(this),
1295
- groups: map(this.groups, (group2) => group2.middleware(tag2))
1296
- });
1297
- },
1298
- annotate(key, value) {
1299
- return makeProto2({
1300
- ...optionsFromApi(this),
1301
- annotations: add(this.annotations, key, value)
1302
- });
1303
- },
1304
- annotateMerge(annotations) {
1305
- return makeProto2({
1306
- ...optionsFromApi(this),
1307
- annotations: merge(this.annotations, annotations)
1308
- });
1309
- }
1310
- };
1311
- var optionsFromApi = (api) => ({
1312
- identifier: api.identifier,
1313
- groups: api.groups,
1314
- annotations: api.annotations
1315
- });
1316
- var makeProto2 = (options2) => {
1317
- function HttpApi() {
1318
- }
1319
- Object.setPrototypeOf(HttpApi, Proto2);
1320
- return Object.assign(HttpApi, options2);
1321
- };
1322
- var make4 = (identifier) => makeProto2({
1323
- identifier,
1324
- groups: {},
1325
- annotations: empty()
1326
- });
1327
- var reflect = (self, options2) => {
1328
- const groups = Object.values(self.groups);
1329
- for (const group2 of groups) {
1330
- const groupAnnotations = merge(self.annotations, group2.annotations);
1331
- options2.onGroup({
1332
- group: group2,
1333
- mergedAnnotations: groupAnnotations
1334
- });
1335
- const endpoints = Object.values(group2.endpoints);
1336
- for (const endpoint2 of endpoints) {
1337
- if (options2.predicate && !options2.predicate({
1338
- endpoint: endpoint2,
1339
- group: group2
1340
- })) continue;
1341
- options2.onEndpoint({
1342
- group: group2,
1343
- endpoint: endpoint2,
1344
- middleware: endpoint2.middlewares,
1345
- mergedAnnotations: merge(groupAnnotations, endpoint2.annotations),
1346
- successes: extractResponseContent(getSuccessSchemas(endpoint2), getStatusSuccessSchema),
1347
- errors: extractResponseContent(getErrorSchemas(endpoint2), getStatusErrorSchema)
1348
- });
1349
- }
1350
- }
1351
- };
1352
- var extractResponseContent = (schemas, getStatus) => {
1353
- const map7 = /* @__PURE__ */ new Map();
1354
- schemas.forEach(add2);
1355
- return map7;
1356
- function add2(schema) {
1357
- const body = isWithHeaders(schema) ? schema.schema : schema;
1358
- if (isStreamSchema(body) || isUpgrade(body)) return;
1359
- const status2 = getStatus(schema);
1360
- const schemas2 = map7.get(status2);
1361
- if (schemas2 === void 0) {
1362
- map7.set(status2, [schema]);
1363
- } else {
1364
- schemas2.push(schema);
1365
- }
1366
- }
1367
- };
1368
- var AdditionalSchemas = class extends (/* @__PURE__ */ Service()("effect/http-api/HttpApi/AdditionalSchemas")) {
1369
- };
1370
- var ParseOptions = class extends (/* @__PURE__ */ Service()("effect/http-api/HttpApi/ParseOptions")) {
1371
- };
1372
- var ParamsParseOptions = class extends (/* @__PURE__ */ Service()("effect/http-api/HttpApi/ParamsParseOptions")) {
1373
- };
1374
- var QueryParseOptions = class extends (/* @__PURE__ */ Service()("effect/http-api/HttpApi/QueryParseOptions")) {
1375
- };
1376
- var HeadersParseOptions = class extends (/* @__PURE__ */ Service()("effect/http-api/HttpApi/HeadersParseOptions")) {
1377
- };
1378
- var PayloadParseOptions = class extends (/* @__PURE__ */ Service()("effect/http-api/HttpApi/PayloadParseOptions")) {
1379
- };
1380
- var SuccessParseOptions = class extends (/* @__PURE__ */ Service()("effect/http-api/HttpApi/SuccessParseOptions")) {
1381
- };
1382
- var ErrorParseOptions = class extends (/* @__PURE__ */ Service()("effect/http-api/HttpApi/ErrorParseOptions")) {
1383
- };
1384
- var RedactedNames = class extends (/* @__PURE__ */ Service()("effect/http-api/HttpApi/RedactedNames")) {
1385
- };
1386
- var getSlotParseOptions = (annotations) => {
1387
- const fallback = getOrUndefined(annotations, ParseOptions);
1388
- return {
1389
- params: getOrUndefined(annotations, ParamsParseOptions) ?? fallback,
1390
- query: getOrUndefined(annotations, QueryParseOptions) ?? fallback,
1391
- headers: getOrUndefined(annotations, HeadersParseOptions) ?? fallback,
1392
- payload: getOrUndefined(annotations, PayloadParseOptions) ?? fallback,
1393
- success: getOrUndefined(annotations, SuccessParseOptions) ?? fallback,
1394
- error: getOrUndefined(annotations, ErrorParseOptions) ?? fallback
1395
- };
1396
- };
1397
- var getEndpointRedactedNames = (api, group2, endpoint2) => {
1398
- const query2 = [];
1399
- const headers = [];
1400
- for (const annotations of [api.annotations, group2.annotations, endpoint2.annotations]) {
1401
- const options2 = getOrUndefined(annotations, RedactedNames);
1402
- if (options2 === void 0) continue;
1403
- for (const name of options2.query ?? []) {
1404
- query2.push(name);
1405
- if (typeof name === "string") query2.push(new RegExp(`^${escape(name)}\\[`, "i"));
1406
- }
1407
- if (options2.headers !== void 0) headers.push(...options2.headers);
1408
- }
1409
- return query2.length === 0 && headers.length === 0 ? void 0 : {
1410
- query: query2,
1411
- headers
1412
- };
1413
- };
1414
-
1415
- // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http-api/HttpApiGroup.js
1416
- var HttpApiGroup_exports = {};
1417
- __export(HttpApiGroup_exports, {
1418
- isHttpApiGroup: () => isHttpApiGroup,
1419
- make: () => make5
1420
- });
1421
- var TypeId3 = "~effect/http-api/HttpApiGroup";
1422
- var isHttpApiGroup = (u) => hasProperty(u, TypeId3);
1423
- var Proto3 = {
1424
- [TypeId3]: TypeId3,
1425
- add(...toAdd) {
1426
- const endpoints = {
1427
- ...this.endpoints
1428
- };
1429
- for (const endpoint2 of toAdd) {
1430
- assignProperty(endpoints, endpoint2.identifier, endpoint2);
1431
- }
1432
- return makeProto3({
1433
- ...optionsFromGroup(this),
1434
- endpoints
1435
- });
1436
- },
1437
- prefix(prefix) {
1438
- return makeProto3({
1439
- ...optionsFromGroup(this),
1440
- endpoints: map(this.endpoints, (endpoint2) => endpoint2.prefix(prefix))
1441
- });
1442
- },
1443
- middleware(middleware) {
1444
- return makeProto3({
1445
- ...optionsFromGroup(this),
1446
- endpoints: map(this.endpoints, (endpoint2) => endpoint2.middleware(middleware))
1447
- });
1448
- },
1449
- annotateMerge(annotations) {
1450
- return makeProto3({
1451
- ...optionsFromGroup(this),
1452
- annotations: merge(this.annotations, annotations)
1453
- });
1454
- },
1455
- annotate(annotation, value) {
1456
- return makeProto3({
1457
- ...optionsFromGroup(this),
1458
- annotations: add(this.annotations, annotation, value)
1459
- });
1460
- },
1461
- annotateEndpointsMerge(annotations) {
1462
- return makeProto3({
1463
- ...optionsFromGroup(this),
1464
- endpoints: map(this.endpoints, (endpoint2) => endpoint2.annotateMerge(annotations))
1465
- });
1466
- },
1467
- annotateEndpoints(annotation, value) {
1468
- return makeProto3({
1469
- ...optionsFromGroup(this),
1470
- endpoints: map(this.endpoints, (endpoint2) => endpoint2.annotate(annotation, value))
1471
- });
1472
- },
1473
- pipe() {
1474
- return pipeArguments(this, arguments);
1475
- }
1476
- };
1477
- var optionsFromGroup = (group2) => ({
1478
- identifier: group2.identifier,
1479
- topLevel: group2.topLevel,
1480
- endpoints: group2.endpoints,
1481
- annotations: group2.annotations
1482
- });
1483
- var makeProto3 = (options2) => {
1484
- function HttpApiGroup() {
1485
- }
1486
- Object.setPrototypeOf(HttpApiGroup, Proto3);
1487
- HttpApiGroup.key = `effect/http-api/HttpApiGroup/${options2.identifier}`;
1488
- return Object.assign(HttpApiGroup, options2);
1489
- };
1490
- var make5 = (identifier, options2) => makeProto3({
1491
- identifier,
1492
- topLevel: options2?.topLevel ?? false,
1493
- endpoints: {},
1494
- annotations: empty()
1495
- });
1496
-
1497
- // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/encoding/Ndjson.js
1498
- var NdjsonErrorTypeId = "~effect/encoding/Ndjson/NdjsonError";
1499
- var encoder = /* @__PURE__ */ new TextEncoder();
1500
- var utf8Decoder = /* @__PURE__ */ new TextDecoder("utf-8", {
1501
- fatal: true,
1502
- ignoreBOM: true
1503
- });
1504
- var NdjsonError = class extends (/* @__PURE__ */ TaggedError("NdjsonError")) {
1505
- /**
1506
- * Marks this value as an NDJSON encoding or decoding error for runtime guards.
1507
- *
1508
- * @stability unstable
1509
- * @since 4.0.0
1510
- */
1511
- [NdjsonErrorTypeId] = NdjsonErrorTypeId;
1512
- /**
1513
- * Uses the failed NDJSON operation as the public message.
1514
- *
1515
- * @stability unstable
1516
- * @since 4.0.0
1517
- */
1518
- get message() {
1519
- return this.kind;
1520
- }
1521
- };
1522
- var isNdjsonError = (u) => hasProperty(u, NdjsonErrorTypeId);
1523
- var encodeString = () => fromTransform((upstream, _scope) => succeed2(flatMap(upstream, (input) => {
1524
- try {
1525
- return succeed2(of(input.map((item) => {
1526
- const output = JSON.stringify(item);
1527
- if (output === void 0) {
1528
- throw new TypeError("Value cannot be represented as JSON");
1529
- }
1530
- return output;
1531
- }).join("\n") + "\n"));
1532
- } catch (cause) {
1533
- return fail3(new NdjsonError({
1534
- kind: "Pack",
1535
- cause
1536
- }));
1537
- }
1538
- })));
1539
- var encode2 = () => map4(encodeString(), map2((_) => encoder.encode(_)));
1540
- var makeDecodePull = (upstream, step, flush) => {
1541
- let failure;
1542
- let done2;
1543
- const emit = (out, error) => {
1544
- failure = error;
1545
- if (isArrayNonEmpty(out)) return succeed2(out);
1546
- return error !== void 0 ? fail3(error) : void 0;
1547
- };
1548
- const pull = suspend(() => {
1549
- if (failure !== void 0) return fail3(failure);
1550
- if (done2 !== void 0) return done(done2.leftover);
1551
- return matchEffect(upstream, {
1552
- onSuccess: (input) => {
1553
- const out = [];
1554
- return emit(out, step(input, out)) ?? pull;
1555
- },
1556
- onFailure: failCause,
1557
- onDone: (leftover) => {
1558
- done2 = {
1559
- leftover
1560
- };
1561
- const out = [];
1562
- return emit(out, flush(out)) ?? done(leftover);
1563
- }
1564
- });
1565
- });
1566
- return pull;
1567
- };
1568
- var parseLine = (line, out, ignoreEmptyLines, unterminated) => {
1569
- if (ignoreEmptyLines && /^[ \t]*$/.test(line)) return;
1570
- try {
1571
- out.push(JSON.parse(line));
1572
- } catch (cause) {
1573
- return new NdjsonError({
1574
- kind: "Unpack",
1575
- reason: "InvalidJson",
1576
- unterminated,
1577
- cause
1578
- });
1579
- }
1580
- };
1581
- var LF2 = 10;
1582
- var CR2 = 13;
1583
- var emptyBytes = /* @__PURE__ */ new Uint8Array(0);
1584
- var decode3 = (options2) => fromTransform((upstream, _scope) => sync(() => {
1585
- const ignoreEmptyLines = options2?.ignoreEmptyLines === true;
1586
- const maxLineBytes = options2?.maxLineBytes ?? Number.POSITIVE_INFINITY;
1587
- let decoder = new TextDecoder("utf-8", {
1588
- fatal: true
1589
- });
1590
- let pending = [];
1591
- let pendingBytes = 0;
1592
- let afterCR = false;
1593
- const takeLine = (chunk, start, end) => {
1594
- if (pendingBytes === 0) return chunk.subarray(start, end);
1595
- const line = new Uint8Array(pendingBytes + end - start);
1596
- let offset = 0;
1597
- for (const bytes of pending) {
1598
- line.set(bytes, offset);
1599
- offset += bytes.length;
1600
- }
1601
- line.set(chunk.subarray(start, end), offset);
1602
- pending = [];
1603
- pendingBytes = 0;
1604
- return line;
1605
- };
1606
- const decodeLine = (bytes, out, unterminated) => {
1607
- let line;
1608
- try {
1609
- line = decoder.decode(bytes);
1610
- } catch (cause) {
1611
- return new NdjsonError({
1612
- kind: "Unpack",
1613
- reason: "InvalidUtf8",
1614
- unterminated,
1615
- cause
1616
- });
1617
- }
1618
- const firstLine = decoder !== utf8Decoder;
1619
- decoder = utf8Decoder;
1620
- if (firstLine && unterminated && line.length === 0) return;
1621
- return parseLine(line, out, ignoreEmptyLines, unterminated);
1622
- };
1623
- const step = (chunks, out) => {
1624
- for (const chunk of chunks) {
1625
- let start = 0;
1626
- for (let i = 0; i < chunk.length; i++) {
1627
- const byte = chunk[i];
1628
- if (byte === LF2 || byte === CR2) {
1629
- if (byte === LF2 && afterCR) {
1630
- start = i + 1;
1631
- } else {
1632
- const error = decodeLine(takeLine(chunk, start, i), out, false);
1633
- if (error !== void 0) return error;
1634
- start = i + 1;
1635
- }
1636
- afterCR = byte === CR2;
1637
- } else {
1638
- afterCR = false;
1639
- if (pendingBytes + i + 1 - start > maxLineBytes) {
1640
- return new NdjsonError({
1641
- kind: "Unpack",
1642
- reason: "LineTooLarge",
1643
- unterminated: false,
1644
- cause: new RangeError(`NDJSON line exceeds maxLineBytes of ${maxLineBytes}`)
1645
- });
1646
- }
1647
- }
1648
- }
1649
- if (start < chunk.length) {
1650
- pending.push(chunk.slice(start));
1651
- pendingBytes += chunk.length - start;
1652
- }
1653
- }
1654
- };
1655
- const flush = (out) => pendingBytes === 0 ? void 0 : decodeLine(takeLine(emptyBytes, 0, 0), out, true);
1656
- return makeDecodePull(upstream, step, flush);
1657
- }));
1658
-
1659
- // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http-api/internal/path.js
1660
- var emptyParamNames = /* @__PURE__ */ new Set();
1661
- function getParamNames(schema) {
1662
- if (schema === void 0) return emptyParamNames;
1663
- const ast = getLastEncoding(schema.ast);
1664
- return isObjects(ast) && ast.indexSignatures.length === 0 ? new Set(ast.propertySignatures.map((ps) => String(ps.name))) : void 0;
1665
- }
1666
- function replaceParams(path, paramNames, replace) {
1667
- const params = /::|:(\w+)/g;
1668
- let out = "";
1669
- let last = 0;
1670
- for (let param = params.exec(path); param !== null; param = params.exec(path)) {
1671
- const name = param[1];
1672
- if (name === void 0 || paramNames !== void 0 && !paramNames.has(name)) continue;
1673
- let end = params.lastIndex;
1674
- if (path[end] === "(") end = getClosingParenthensePosition(path, end) + 1;
1675
- const optional2 = path[end] === "?";
1676
- if (optional2) end++;
1677
- const value = replace(name, optional2);
1678
- let start = param.index;
1679
- if (value === void 0 && path[start - 1] === "/") start--;
1680
- out += path.slice(last, start) + (value ?? "");
1681
- params.lastIndex = end;
1682
- last = end;
1683
- }
1684
- return out + path.slice(last);
1685
- }
1686
-
1687
- // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http-api/HttpApiClient.js
1688
- var HttpApiClient_exports = {};
1689
- __export(HttpApiClient_exports, {
1690
- UpgradedTypeId: () => UpgradedTypeId,
1691
- decodeResponse: () => decodeResponse,
1692
- endpoint: () => endpoint,
1693
- group: () => group,
1694
- isUpgraded: () => isUpgraded,
1695
- make: () => make6,
1696
- makeClient: () => makeClient,
1697
- makeWith: () => makeWith,
1698
- urlBuilder: () => urlBuilder
1699
- });
1700
- var UpgradedTypeId = "~effect/http-api/HttpApiClient/Upgraded";
1701
- var isUpgraded = (u) => hasProperty(u, UpgradedTypeId);
1702
- var makeClient = (api, options2) => gen(function* () {
1703
- const services = yield* context();
1704
- const httpClient = options2.httpClient.pipe(options2?.baseUrl === void 0 ? identity : mapRequest(prependUrl(options2.baseUrl.toString())));
1705
- function executeMiddleware(group2, endpoint2, request, middlewareKeys, index) {
1706
- if (index === -1) {
1707
- return httpClient.execute(request);
1708
- }
1709
- const middleware = services.mapUnsafe.get(middlewareKeys[index]);
1710
- if (middleware === void 0) {
1711
- return executeMiddleware(group2, endpoint2, request, middlewareKeys, index - 1);
1712
- }
1713
- return middleware({
1714
- endpoint: endpoint2,
1715
- group: group2,
1716
- request,
1717
- next(request2) {
1718
- return executeMiddleware(group2, endpoint2, request2, middlewareKeys, index - 1);
1719
- }
1720
- });
1721
- }
1722
- reflect(api, {
1723
- predicate: options2?.predicate,
1724
- onGroup(onGroupOptions) {
1725
- options2.onGroup?.(onGroupOptions);
1726
- },
1727
- onEndpoint(onEndpointOptions) {
1728
- const {
1729
- group: group2,
1730
- endpoint: endpoint2,
1731
- mergedAnnotations
1732
- } = onEndpointOptions;
1733
- const parseOptions = getSlotParseOptions(mergedAnnotations);
1734
- const makeUrl = compilePath(endpoint2.path, endpoint2.params);
1735
- const upgrade2 = getUpgradeSuccessSchema(endpoint2);
1736
- const decodeEndpointResponse = makeEndpointDecoder(onEndpointOptions);
1737
- const encodeParams = map6(endpoint2.params, (schema) => encodeUnknownEffect(schema, parseOptions.params));
1738
- const payloadSchemas = [];
1739
- let streamPayload;
1740
- for (const schema of getPayloadSchemas(endpoint2)) {
1741
- if (isStreamUint8Array(schema) || isStreamNdjson(schema)) {
1742
- streamPayload = schema;
1743
- } else {
1744
- payloadSchemas.push(schema);
1745
- }
1746
- }
1747
- const streamPayloadEncoder = map6(streamPayload, (schema) => ({
1748
- contentType: schema.contentType,
1749
- encode: makeStreamPayloadEncoder(schema, parseOptions.payload)
1750
- }));
1751
- const encodePayload = isArrayNonEmpty(payloadSchemas) ? encodeUnknownEffect(hasBody(endpoint2.method) ? getEncodePayloadSchema(payloadSchemas, endpoint2.method) : Union2(payloadSchemas), parseOptions.payload) : void 0;
1752
- const encodeHeaders = map6(endpoint2.headers, (schema) => encodeUnknownEffect(schema, parseOptions.headers));
1753
- const encodeQuery = map6(endpoint2.query, (schema) => encodeUnknownEffect(schema, parseOptions.query));
1754
- const middlewareKeys = Array.from(onEndpointOptions.middleware, (tag2) => `${tag2.key}/Client`);
1755
- const redactedNames = getEndpointRedactedNames(api, group2, endpoint2);
1756
- const endpointFn = fnUntraced(function* (request) {
1757
- let httpRequest = make2(endpoint2.method)(endpoint2.path);
1758
- if (request !== void 0) {
1759
- if (encodeParams !== void 0) {
1760
- const params = yield* encodeParams(request.params);
1761
- httpRequest = setUrl(httpRequest, makeUrl(params));
1762
- }
1763
- if (streamPayloadEncoder !== void 0 && isStream(request.payload)) {
1764
- const context2 = yield* context();
1765
- httpRequest = setBody(httpRequest, stream(provideContext(streamPayloadEncoder.encode(request.payload), context2), streamPayloadEncoder.contentType));
1766
- } else if (encodePayload !== void 0) {
1767
- if (hasBody(endpoint2.method)) {
1768
- if (request.payload instanceof FormData) {
1769
- httpRequest = bodyFormData(httpRequest, request.payload);
1770
- } else {
1771
- const body = yield* encodePayload(request.payload);
1772
- httpRequest = setBody(httpRequest, body);
1773
- }
1774
- } else {
1775
- const urlParams2 = yield* encodePayload(request.payload);
1776
- httpRequest = appendUrlParams(httpRequest, urlParams2);
1777
- }
1778
- } else if (streamPayloadEncoder !== void 0) {
1779
- return yield* new SchemaError(new InvalidValue({
1780
- message: "Expected a Stream payload"
1781
- }, request.payload));
1782
- }
1783
- if (encodeHeaders !== void 0) {
1784
- const headers = yield* encodeHeaders(request.headers);
1785
- httpRequest = setHeaders(httpRequest, headers);
1786
- }
1787
- if (encodeQuery !== void 0) {
1788
- const query2 = yield* encodeQuery(request.query);
1789
- httpRequest = appendUrlParams(httpRequest, query2);
1790
- }
1791
- }
1792
- if (upgrade2 !== void 0) {
1793
- httpRequest = upgrade(httpRequest, upgrade2.protocol);
1794
- }
1795
- const execute = executeMiddleware(group2, endpoint2, httpRequest, middlewareKeys, middlewareKeys.length - 1);
1796
- const response = yield* redactedNames === void 0 ? execute : withRedactedNames(execute, redactedNames);
1797
- if (request?.responseMode === "response-only") {
1798
- return response;
1799
- }
1800
- const decoded = decodeEndpointResponse(response, request?.sseOptions);
1801
- const value = yield* options2.transformResponse === void 0 ? decoded : options2.transformResponse(decoded);
1802
- return request?.responseMode === "decoded-and-response" ? [value, response] : value;
1803
- });
1804
- options2.onEndpoint({
1805
- ...onEndpointOptions,
1806
- endpointFn
1807
- });
1808
- }
1809
- });
1810
- });
1811
- var withRedactedNames = (effect, redactedNames) => effect.pipe(updateService(CurrentRedactedNames2, (names) => [...names, ...redactedNames.query]), updateService(CurrentRedactedNames, (names) => [...names, ...redactedNames.headers]));
1812
- var make6 = (api, options2) => flatMap(HttpClient, (httpClient) => makeWith(api, {
1813
- ...options2,
1814
- httpClient: options2?.transformClient ? options2.transformClient(httpClient) : httpClient
1815
- }));
1816
- var makeWith = (api, options2) => {
1817
- const client = {};
1818
- return makeClient(api, {
1819
- ...options2,
1820
- onGroup({
1821
- group: group2
1822
- }) {
1823
- if (group2.topLevel) return;
1824
- assignProperty(client, group2.identifier, {});
1825
- },
1826
- onEndpoint({
1827
- endpoint: endpoint2,
1828
- endpointFn,
1829
- group: group2
1830
- }) {
1831
- assignProperty(group2.topLevel ? client : client[group2.identifier], endpoint2.identifier, endpointFn);
1832
- }
1833
- }).pipe(as(client));
1834
- };
1835
- var group = (api, options2) => {
1836
- const client = {};
1837
- return makeClient(api, {
1838
- ...options2,
1839
- predicate: ({
1840
- group: group2
1841
- }) => group2.identifier === options2.group,
1842
- onEndpoint({
1843
- endpoint: endpoint2,
1844
- endpointFn
1845
- }) {
1846
- assignProperty(client, endpoint2.identifier, endpointFn);
1847
- }
1848
- }).pipe(map3(() => client));
1849
- };
1850
- var endpoint = (api, options2) => {
1851
- let client = void 0;
1852
- return makeClient(api, {
1853
- ...options2,
1854
- httpClient: options2.transformClient ? options2.transformClient(options2.httpClient) : options2.httpClient,
1855
- predicate: ({
1856
- endpoint: endpoint2,
1857
- group: group2
1858
- }) => group2.identifier === options2.group && endpoint2.identifier === options2.endpoint,
1859
- onEndpoint({
1860
- endpointFn
1861
- }) {
1862
- client = endpointFn;
1863
- }
1864
- }).pipe(map3(() => client));
1865
- };
1866
- var decodeResponse = (api, options2) => {
1867
- let decode4;
1868
- reflect(api, {
1869
- predicate: ({
1870
- endpoint: endpoint2,
1871
- group: group2
1872
- }) => group2.identifier === options2.group && endpoint2.identifier === options2.endpoint,
1873
- onGroup() {
1874
- },
1875
- onEndpoint(endpointOptions) {
1876
- decode4 = makeEndpointDecoder(endpointOptions);
1877
- }
1878
- });
1879
- return (response, decodeOptions) => decode4(response, decodeOptions?.sseOptions);
1880
- };
1881
- var urlBuilder = (api, options2) => {
1882
- const builder = {};
1883
- reflect(api, {
1884
- onGroup({
1885
- group: group2
1886
- }) {
1887
- if (group2.topLevel) return;
1888
- assignProperty(builder, group2.identifier, {});
1889
- },
1890
- onEndpoint({
1891
- group: group2,
1892
- endpoint: endpoint2,
1893
- mergedAnnotations
1894
- }) {
1895
- const parseOptions = getSlotParseOptions(mergedAnnotations);
1896
- const makeUrl = compilePath(endpoint2.path, endpoint2.params);
1897
- const encodeParams = endpoint2.params === void 0 ? void 0 : encodeSync(endpoint2.params, parseOptions.params);
1898
- const encodeQuery = endpoint2.query === void 0 ? void 0 : encodeSync(endpoint2.query, parseOptions.query);
1899
- const endpointBuilder = (request) => {
1900
- const params = request?.params;
1901
- const path = params === void 0 ? endpoint2.path : makeUrl(encodeParams === void 0 ? params : encodeParams(params));
1902
- const queryInput = request?.query === void 0 ? void 0 : encodeQuery === void 0 ? request.query : encodeQuery(request.query);
1903
- const urlParams2 = queryInput === void 0 ? empty2 : fromInput(queryInput);
1904
- if (options2?.baseUrl === void 0) {
1905
- const query2 = toString(urlParams2);
1906
- return query2 === "" ? path : `${path}?${query2}`;
1907
- }
1908
- const url = new URL(prependUrl(get(path), options2.baseUrl.toString()).url);
1909
- for (const [key, value] of urlParams2.params) {
1910
- if (value !== void 0) {
1911
- url.searchParams.append(key, unwrap(value));
1912
- }
1913
- }
1914
- return url.toString();
1915
- };
1916
- assignProperty(group2.topLevel ? builder : builder[group2.identifier], endpoint2.identifier, endpointBuilder);
1917
- }
1918
- });
1919
- return builder;
1920
- };
1921
- var compilePath = (path, schema) => {
1922
- if (schema === void 0 || !path.includes(":")) {
1923
- return (_) => path;
1924
- }
1925
- const paramNames = getParamNames(schema);
1926
- return (params) => replaceParams(path, paramNames, (key, optional2) => {
1927
- const value = params[key];
1928
- if (value === "." || value === "..") {
1929
- throw new Error(`Invalid path parameter: ${key}`);
1930
- }
1931
- if (value !== void 0) return encodeURIComponent(value);
1932
- if (optional2) return void 0;
1933
- throw new Error(`Missing path parameter: ${key}`);
1934
- });
1935
- };
1936
- function schemasToResponse(schemas, options2, headersOptions) {
1937
- const hasWithHeaders = schemas.some((schema) => isWithHeaders(schema) || getWithHeadersAnnotation(schema.ast) !== void 0);
1938
- const codec = hasWithHeaders ? Union2(schemas.map((schema) => toCodecArrayBufferWithHeaders(schema, options2, headersOptions))) : toCodecArrayBuffer(schemas);
1939
- const decode4 = decodeUnknownEffect(codec, options2);
1940
- return (response) => flatMap(response.arrayBuffer, hasWithHeaders ? (body) => decode4({
1941
- body,
1942
- headers: response.headers
1943
- }) : decode4);
1944
- }
1945
- var ResponsePair = /* @__PURE__ */ Struct({
1946
- body: Unknown,
1947
- headers: Unknown
1948
- });
1949
- function toCodecArrayBufferWithHeaders(schema, options2, headersOptions) {
1950
- const annotation = getWithHeadersAnnotation(schema.ast);
1951
- const parts = annotation !== void 0 ? {
1952
- body: annotation.bodyCodec,
1953
- headers: annotation.headersCodec,
1954
- toValue: annotation.transformation.decode
1955
- } : isWithHeaders(schema) ? {
1956
- body: schema.schema,
1957
- headers: schema.headers,
1958
- toValue: withHeaders
1959
- } : {
1960
- body: schema,
1961
- headers: Unknown,
1962
- toValue: (pair) => pair.body
1963
- };
1964
- const decodeBody = decodeUnknownEffect(fromArrayBuffer(parts.body).pipe(decodeTo2(parts.body)), options2);
1965
- const decodeHeaders = decodeUnknownEffect(parts.headers, headersOptions);
1966
- return ResponsePair.pipe(decodeTo2(isWithHeaders(schema) ? schema : toType(schema), transformEffect({
1967
- decode: (pair) => all({
1968
- body: decodeBody(pair.body),
1969
- headers: decodeHeaders(pair.headers)
1970
- }).pipe(map3(parts.toValue), mapError((error) => error.issue)),
1971
- encode: (input, options3) => fail3(new Forbidden({
1972
- message: "Decode only schema"
1973
- }, input, options3))
1974
- })));
1975
- }
1976
- var makeEndpointDecoder = (options2) => {
1977
- const {
1978
- endpoint: endpoint2,
1979
- errors,
1980
- successes,
1981
- mergedAnnotations
1982
- } = options2;
1983
- const parseOptions = getSlotParseOptions(mergedAnnotations);
1984
- const decodeMap = {
1985
- orElse: statusOrElse
1986
- };
1987
- const errorAlternatives = /* @__PURE__ */ new Map();
1988
- for (const [status2, schemas] of errors.entries()) {
1989
- const grouped = groupSchemasByContentType(schemas);
1990
- for (const [contentType2, schemas2] of grouped.entries()) {
1991
- addResponseAlternative(errorAlternatives, status2, contentType2, schemasToResponse(schemas2, parseOptions.error, parseOptions.headers));
1992
- }
1993
- }
1994
- for (const [status2, alternatives] of errorAlternatives.entries()) {
1995
- const decode4 = makeResponseDecoder(alternatives);
1996
- decodeMap[status2] = (response) => flatMap(catchCause(decode4(response), (cause) => failCause(combine(fail2(new HttpClientError({
1997
- reason: new StatusCodeError({
1998
- request: response.request,
1999
- response
2000
- })
2001
- })), cause))), fail3);
2002
- }
2003
- const successAlternatives = /* @__PURE__ */ new Map();
2004
- for (const [status2, schemas] of successes.entries()) {
2005
- const grouped = groupSchemasByContentType(schemas);
2006
- for (const [contentType2, schemas2] of grouped.entries()) {
2007
- addResponseAlternative(successAlternatives, status2, contentType2, schemasToResponse(schemas2, parseOptions.success, parseOptions.headers));
2008
- }
2009
- }
2010
- for (const streamSuccess of getStreamSuccessSchemas(endpoint2)) {
2011
- const streamSchema2 = isWithHeadersStreamSuccess(streamSuccess) ? streamSuccess.schema : streamSuccess;
2012
- const status2 = getStatusSuccessSchema(streamSuccess);
2013
- const decode4 = streamToResponse(streamSuccess, parseOptions.success, parseOptions.headers);
2014
- for (const contentType2 of streamSchema2.contentTypes) {
2015
- addResponseAlternative(successAlternatives, status2, contentType2, decode4);
2016
- }
2017
- }
2018
- for (const [status2, alternatives] of successAlternatives.entries()) {
2019
- decodeMap[status2] = makeResponseDecoder(alternatives);
2020
- }
2021
- const upgrade2 = getUpgradeSuccessSchema(endpoint2);
2022
- if (upgrade2 !== void 0) {
2023
- const decodeHeaders = upgrade2.headers === void 0 ? succeed2 : decodeUnknownEffect(upgrade2.headers, parseOptions.headers);
2024
- decodeMap[101] = (response) => (
2025
- // the cleanup must be in place before an interruption can be observed
2026
- uninterruptibleMask((restore) => flatMap(response.upgrade, (socket) => restore(decodeHeaders(response.headers)).pipe(
2027
- map3((headers) => ({
2028
- [UpgradedTypeId]: UpgradedTypeId,
2029
- headers,
2030
- socket
2031
- })),
2032
- // nothing takes the connection on failure, so close it: releasing
2033
- // the reader's scope closes the connection
2034
- onError(() => ignore(scoped(socket.reader)))
2035
- )))
2036
- );
2037
- }
2038
- return (response, sseOptions) => (decodeMap[response.status] ?? decodeMap.orElse)(response, sseOptions);
2039
- };
2040
- function addResponseAlternative(map7, status2, contentType2, decode4) {
2041
- const normalizedContentType = normalize(contentType2);
2042
- const alternatives = map7.get(status2);
2043
- if (alternatives === void 0) {
2044
- map7.set(status2, [{
2045
- contentType: normalizedContentType,
2046
- decode: decode4
2047
- }]);
2048
- } else {
2049
- alternatives.push({
2050
- contentType: normalizedContentType,
2051
- decode: decode4
2052
- });
2053
- }
2054
- }
2055
- function makeResponseDecoder(alternatives) {
2056
- const first = alternatives[0];
2057
- if (first !== void 0 && alternatives.every((alternative) => alternative.decode === first.decode)) {
2058
- return first.decode;
2059
- }
2060
- return (response, sseOptions) => {
2061
- const contentType2 = normalize(response.headers["content-type"] ?? "");
2062
- const alternative = alternatives.find((alternative2) => alternative2.contentType === contentType2);
2063
- return alternative === void 0 ? failUnsupportedContentType(response, contentType2, alternatives) : alternative.decode(response, sseOptions);
2064
- };
2065
- }
2066
- function groupSchemasByContentType(schemas) {
2067
- const grouped = /* @__PURE__ */ new Map();
2068
- for (const schema of schemas) {
2069
- const body = isWithHeaders(schema) ? schema.schema : schema;
2070
- const contentType2 = isNoContent(body.ast) ? "" : normalize(getResponseEncodingSchema(schema).contentType);
2071
- const existing = grouped.get(contentType2);
2072
- if (existing === void 0) {
2073
- grouped.set(contentType2, [schema]);
2074
- } else {
2075
- existing.push(schema);
2076
- }
2077
- }
2078
- return grouped;
2079
- }
2080
- function failUnsupportedContentType(response, contentType2, alternatives) {
2081
- const expected = Array.from(new Set(alternatives.map((alternative) => alternative.contentType))).join(", ");
2082
- return fail3(new HttpClientError({
2083
- reason: new DecodeError({
2084
- request: response.request,
2085
- response,
2086
- description: `Unsupported response content-type for status ${response.status}: ${contentType2 || "<missing>"}. Expected one of: ${expected}`
2087
- })
2088
- }));
2089
- }
2090
- var reservedStreamFailureEvent2 = "effect/http-api/stream/failure";
2091
- var isWithHeadersStreamSuccess = (schema) => isWithHeaders(schema);
2092
- function getUpgradeSuccessSchema(endpoint2) {
2093
- for (const schema of endpoint2.success) {
2094
- if (isUpgrade(schema)) return schema;
2095
- }
2096
- }
2097
- function getStreamSuccessSchemas(endpoint2) {
2098
- const schemas = [];
2099
- for (const schema of endpoint2.success) {
2100
- const body = isWithHeaders(schema) ? schema.schema : schema;
2101
- if (isStreamSchema(body)) {
2102
- schemas.push(schema);
2103
- }
2104
- }
2105
- return schemas;
2106
- }
2107
- function streamToResponse(successSchema, options2, headersOptions) {
2108
- const isWithHeaders2 = isWithHeadersStreamSuccess(successSchema);
2109
- const streamSchema2 = isWithHeaders2 ? successSchema.schema : successSchema;
2110
- const decodeBody = makeStreamBodyDecoder(streamSchema2, options2);
2111
- const toStream = (response, sseOptions) => map3(context(), (context2) => provideContext(decodeBody(response, sseOptions), context2));
2112
- if (!isWithHeaders2) return toStream;
2113
- const decodeHeaders = decodeUnknownEffect(successSchema.headers, headersOptions);
2114
- return (response, sseOptions) => flatMap(decodeHeaders(response.headers), (headers) => map3(toStream(response, sseOptions), (body) => withHeaders({
2115
- body,
2116
- headers
2117
- })));
2118
- }
2119
- function makeStreamBodyDecoder(streamSchema2, options2) {
2120
- if (isStreamUint8Array(streamSchema2)) {
2121
- return (response) => response.stream;
2122
- }
2123
- if (isStreamNdjson(streamSchema2)) {
2124
- const decodeElement = decodeUnknownEffect(toCodecJson(streamSchema2.schema), options2);
2125
- const maxElementBytes = toNumberUnsafe(streamSchema2.maxElementBytes);
2126
- return (response) => response.stream.pipe(pipeThroughChannel(decode3({
2127
- ignoreEmptyLines: true,
2128
- maxLineBytes: maxElementBytes
2129
- })), mapError2((error) => {
2130
- if (!isNdjsonError(error)) return error;
2131
- if (error.reason !== "LineTooLarge") return ndjsonSchemaError(error);
2132
- return new HttpClientError({
2133
- reason: new DecodeError({
2134
- request: response.request,
2135
- response,
2136
- description: `NDJSON line exceeds maxElementBytes of ${maxElementBytes} bytes`
2137
- })
2138
- });
2139
- }), mapEffect((json) => decodeElement(json)));
2140
- }
2141
- const decoder = makeSseDecoder(streamSchema2, options2);
2142
- return (response, sseOptions) => decodeSseStream(response.stream, streamSchema2, decoder(sseOptions));
2143
- }
2144
- var isNdjsonPackError = (error) => isNdjsonError(error) && error.kind === "Pack";
2145
- var ndjsonSchemaError = (error) => new SchemaError(new InvalidValue({
2146
- message: error.reason === "InvalidUtf8" ? "Expected valid UTF-8" : error.unterminated ? "Expected a valid JSON line, got an unterminated final line" : "Expected a valid JSON line"
2147
- }));
2148
- function makeSseDecoder(declaration, parseOptions) {
2149
- const Event2 = Union2([Struct({
2150
- id: optional(String2),
2151
- event: Literal(reservedStreamFailureEvent2),
2152
- data: fromJsonString(toCodecJson(Cause(declaration.error, Defect())))
2153
- }), declaration.events]);
2154
- const defaultDecoder = decodeSchema(Event2, void 0, parseOptions);
2155
- return (options2) => options2 === void 0 ? defaultDecoder : decodeSchema(Event2, options2, parseOptions);
2156
- }
2157
- function decodeSseStream(stream2, declaration, decoder) {
2158
- const events = transformPull(stream2.pipe(decodeText, pipeThroughChannel(decoder)), (pull) => sync(() => {
2159
- let pendingFailureCause = void 0;
2160
- return suspend(() => {
2161
- if (pendingFailureCause !== void 0) {
2162
- return failCause(pendingFailureCause);
2163
- }
2164
- return flatMap(pull, (events2) => {
2165
- for (let i = 0; i < events2.length; i++) {
2166
- const event = events2[i];
2167
- if (event.event === reservedStreamFailureEvent2 && isCause(event.data)) {
2168
- if (i === 0) {
2169
- return failCause(event.data);
2170
- }
2171
- pendingFailureCause = event.data;
2172
- events2 = events2.slice(0, i);
2173
- break;
2174
- }
2175
- }
2176
- return succeed2(events2);
2177
- });
2178
- });
2179
- }));
2180
- if (declaration.sseMode === "data") {
2181
- return map5(events, (event) => event.data);
2182
- }
2183
- return events;
2184
- }
2185
- var ArrayBuffer = /* @__PURE__ */ instanceOf(globalThis.ArrayBuffer, {
2186
- expected: "ArrayBuffer"
2187
- });
2188
- var Uint8ArrayFromArrayBuffer = /* @__PURE__ */ ArrayBuffer.pipe(/* @__PURE__ */ decodeTo2(Uint8Array2, /* @__PURE__ */ transform({
2189
- decode(fromA) {
2190
- return new Uint8Array(fromA);
2191
- },
2192
- encode(arr) {
2193
- return arr.byteLength === arr.buffer.byteLength ? arr.buffer : arr.buffer.slice(arr.byteOffset, arr.byteOffset + arr.byteLength);
2194
- }
2195
- })));
2196
- var StringFromArrayBuffer = /* @__PURE__ */ ArrayBuffer.pipe(/* @__PURE__ */ decodeTo2(String2, /* @__PURE__ */ transform({
2197
- decode(fromA) {
2198
- return new TextDecoder().decode(fromA);
2199
- },
2200
- encode(toI) {
2201
- const arr = new TextEncoder().encode(toI);
2202
- return arr.byteLength === arr.buffer.byteLength ? arr.buffer : arr.buffer.slice(arr.byteOffset, arr.byteOffset + arr.byteLength);
2203
- }
2204
- })));
2205
- var UnknownFromArrayBuffer = /* @__PURE__ */ StringFromArrayBuffer.pipe(/* @__PURE__ */ decodeTo2(/* @__PURE__ */ Union2([
2206
- // Handle No Content
2207
- /* @__PURE__ */ Literal("").pipe(/* @__PURE__ */ decodeTo2(Undefined, /* @__PURE__ */ transform({
2208
- decode: () => void 0,
2209
- encode: () => ""
2210
- }))),
2211
- UnknownFromJsonString
2212
- ])));
2213
- function toCodecArrayBuffer(schemas) {
2214
- return Union2(schemas.map(onSchema));
2215
- function onSchema(schema) {
2216
- return fromArrayBuffer(schema).pipe(decodeTo2(schema));
2217
- }
2218
- }
2219
- function fromArrayBuffer(schema) {
2220
- const encoding = getResponseEncoding(schema.ast);
2221
- switch (encoding._tag) {
2222
- case "Json": {
2223
- const encodedIsNull = isNull(toEncoded(schema.ast));
2224
- return encodedIsNull ? UnknownFromArrayBuffer.pipe(decodeTo2(Unknown, transform({
2225
- decode: (a) => a === void 0 ? null : a,
2226
- encode: (a) => a === null ? void 0 : a
2227
- }))) : UnknownFromArrayBuffer;
2228
- }
2229
- case "FormUrlEncoded":
2230
- return StringFromArrayBuffer.pipe(decodeTo2(RecordFromUrlParams, transform({
2231
- decode: (text2) => fromInput(new URLSearchParams(text2)),
2232
- encode: toString
2233
- })));
2234
- case "Uint8Array":
2235
- return Uint8ArrayFromArrayBuffer;
2236
- case "Text":
2237
- return StringFromArrayBuffer;
2238
- }
2239
- }
2240
- var statusOrElse = (response) => fail3(new HttpClientError({
2241
- reason: new DecodeError({
2242
- request: response.request,
2243
- response,
2244
- description: "undeclared status code"
2245
- })
2246
- }));
2247
- var $HttpBody = /* @__PURE__ */ declare(isHttpBody);
2248
- function makeStreamPayloadEncoder(schema, options2) {
2249
- if (isStreamUint8Array(schema)) {
2250
- return (stream2) => stream2;
2251
- }
2252
- const encodeElements = encodeUnknownEffect(NonEmptyArray(toCodecJson(schema.schema)), options2);
2253
- return (stream2) => stream2.pipe(mapArrayEffect((elements) => encodeElements(elements)), pipeThroughChannel(encode2()), catchIf(isNdjsonPackError, die));
2254
- }
2255
- function getEncodePayloadSchema(schemas, method) {
2256
- return Union2(schemas.map((s) => getEncodePayloadSchemaFromBody(s, method)));
2257
- }
2258
- var bodyFromPayloadCache = /* @__PURE__ */ new WeakMap();
2259
- function getEncodePayloadSchemaFromBody(schema, method) {
2260
- const ast = schema.ast;
2261
- const cached = bodyFromPayloadCache.get(ast);
2262
- if (cached !== void 0) {
2263
- return cached;
2264
- }
2265
- const encoding = getPayloadEncoding(ast, method);
2266
- const out = $HttpBody.pipe(decodeTo2(schema, transformEffect({
2267
- decode(input, options2) {
2268
- return fail3(new Forbidden({
2269
- message: "Encode only schema"
2270
- }, input, options2));
2271
- },
2272
- encode(t, options2) {
2273
- switch (encoding._tag) {
2274
- case "Multipart":
2275
- return fail3(new Forbidden({
2276
- message: "Payload must be a FormData"
2277
- }, t, options2));
2278
- case "Json": {
2279
- try {
2280
- const body = JSON.stringify(t);
2281
- return succeed2(text(body, encoding.contentType));
2282
- } catch {
2283
- return fail3(new InvalidValue({
2284
- expected: "a JSON-serializable request body"
2285
- }, t, options2));
2286
- }
2287
- }
2288
- case "Text": {
2289
- if (typeof t !== "string") {
2290
- return fail3(new InvalidValue({
2291
- message: "Expected a string"
2292
- }, t, options2));
2293
- }
2294
- return succeed2(text(t, encoding.contentType));
2295
- }
2296
- case "FormUrlEncoded": {
2297
- if (!isObject(t)) {
2298
- return fail3(new InvalidValue({
2299
- message: "Expected a record"
2300
- }, t, options2));
2301
- }
2302
- return succeed2(urlParams(fromInput(t), encoding.contentType));
2303
- }
2304
- case "Uint8Array": {
2305
- if (!(t instanceof Uint8Array)) {
2306
- return fail3(new InvalidValue({
2307
- message: "Expected a Uint8Array"
2308
- }, t, options2));
2309
- }
2310
- return succeed2(uint8Array(t, encoding.contentType));
2311
- }
2312
- }
2313
- }
2314
- })));
2315
- bodyFromPayloadCache.set(ast, out);
2316
- return out;
2317
- }
2318
-
2319
- export {
2320
- HttpApiSchema_exports,
2321
- HttpApiEndpoint_exports,
2322
- HttpApi_exports,
2323
- HttpApiClient_exports,
2324
- HttpApiGroup_exports
2325
- };