ff-effect 0.0.10 → 0.0.11

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.
@@ -0,0 +1,3021 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all2) => {
9
+ for (var name in all2)
10
+ __defProp(target, name, { get: all2[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/for/inngest/index.ts
31
+ var inngest_exports = {};
32
+ __export(inngest_exports, {
33
+ InngestError: () => InngestError,
34
+ NodeInspectSymbol: () => NodeInspectSymbol4,
35
+ TagTypeId: () => TagTypeId2,
36
+ createInngest: () => createInngest
37
+ });
38
+ module.exports = __toCommonJS(inngest_exports);
39
+
40
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/Cookies.js
41
+ var Duration = __toESM(require("effect/Duration"), 1);
42
+ var Either = __toESM(require("effect/Either"), 1);
43
+ var import_Function = require("effect/Function");
44
+ var Inspectable = __toESM(require("effect/Inspectable"), 1);
45
+ var Option = __toESM(require("effect/Option"), 1);
46
+ var import_Pipeable = require("effect/Pipeable");
47
+ var Predicate2 = __toESM(require("effect/Predicate"), 1);
48
+ var Record = __toESM(require("effect/Record"), 1);
49
+
50
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/Error.js
51
+ var Data = __toESM(require("effect/Data"), 1);
52
+ var Predicate = __toESM(require("effect/Predicate"), 1);
53
+ var Schema = __toESM(require("effect/Schema"), 1);
54
+ var TypeId = /* @__PURE__ */ Symbol.for("@effect/platform/Error");
55
+ var TypeIdError = (typeId, tag2) => {
56
+ class Base extends Data.Error {
57
+ _tag = tag2;
58
+ }
59
+ ;
60
+ Base.prototype[typeId] = typeId;
61
+ Base.prototype.name = tag2;
62
+ return Base;
63
+ };
64
+ var Module = /* @__PURE__ */ Schema.Literal("Clipboard", "Command", "FileSystem", "KeyValueStore", "Path", "Stream", "Terminal");
65
+ var BadArgument = class extends (/* @__PURE__ */ Schema.TaggedError("@effect/platform/Error/BadArgument")("BadArgument", {
66
+ module: Module,
67
+ method: Schema.String,
68
+ description: /* @__PURE__ */ Schema.optional(Schema.String),
69
+ cause: /* @__PURE__ */ Schema.optional(Schema.Defect)
70
+ })) {
71
+ /**
72
+ * @since 1.0.0
73
+ */
74
+ [TypeId] = TypeId;
75
+ /**
76
+ * @since 1.0.0
77
+ */
78
+ get message() {
79
+ return `${this.module}.${this.method}${this.description ? `: ${this.description}` : ""}`;
80
+ }
81
+ };
82
+ var SystemErrorReason = /* @__PURE__ */ Schema.Literal("AlreadyExists", "BadResource", "Busy", "InvalidData", "NotFound", "PermissionDenied", "TimedOut", "UnexpectedEof", "Unknown", "WouldBlock", "WriteZero");
83
+ var SystemError = class extends (/* @__PURE__ */ Schema.TaggedError("@effect/platform/Error/SystemError")("SystemError", {
84
+ reason: SystemErrorReason,
85
+ module: Module,
86
+ method: Schema.String,
87
+ description: /* @__PURE__ */ Schema.optional(Schema.String),
88
+ syscall: /* @__PURE__ */ Schema.optional(Schema.String),
89
+ pathOrDescriptor: /* @__PURE__ */ Schema.optional(/* @__PURE__ */ Schema.Union(Schema.String, Schema.Number)),
90
+ cause: /* @__PURE__ */ Schema.optional(Schema.Defect)
91
+ })) {
92
+ /**
93
+ * @since 1.0.0
94
+ */
95
+ [TypeId] = TypeId;
96
+ /**
97
+ * @since 1.0.0
98
+ */
99
+ get message() {
100
+ return `${this.reason}: ${this.module}.${this.method}${this.pathOrDescriptor !== void 0 ? ` (${this.pathOrDescriptor})` : ""}${this.description ? `: ${this.description}` : ""}`;
101
+ }
102
+ };
103
+
104
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/Cookies.js
105
+ var TypeId2 = /* @__PURE__ */ Symbol.for("@effect/platform/Cookies");
106
+ var CookieTypeId = /* @__PURE__ */ Symbol.for("@effect/platform/Cookies/Cookie");
107
+ var Proto = {
108
+ [TypeId2]: TypeId2,
109
+ ...Inspectable.BaseProto,
110
+ toJSON() {
111
+ return {
112
+ _id: "@effect/platform/Cookies",
113
+ cookies: Record.map(this.cookies, (cookie) => cookie.toJSON())
114
+ };
115
+ },
116
+ pipe() {
117
+ return (0, import_Pipeable.pipeArguments)(this, arguments);
118
+ }
119
+ };
120
+ var fromReadonlyRecord = (cookies) => {
121
+ const self = Object.create(Proto);
122
+ self.cookies = cookies;
123
+ return self;
124
+ };
125
+ var fromIterable = (cookies) => {
126
+ const record = {};
127
+ for (const cookie of cookies) {
128
+ record[cookie.name] = cookie;
129
+ }
130
+ return fromReadonlyRecord(record);
131
+ };
132
+ var fromSetCookie = (headers) => {
133
+ const arrayHeaders = typeof headers === "string" ? [headers] : headers;
134
+ const cookies = [];
135
+ for (const header of arrayHeaders) {
136
+ const cookie = parseSetCookie(header.trim());
137
+ if (Option.isSome(cookie)) {
138
+ cookies.push(cookie.value);
139
+ }
140
+ }
141
+ return fromIterable(cookies);
142
+ };
143
+ function parseSetCookie(header) {
144
+ const parts = header.split(";").map((_) => _.trim()).filter((_) => _ !== "");
145
+ if (parts.length === 0) {
146
+ return Option.none();
147
+ }
148
+ const firstEqual = parts[0].indexOf("=");
149
+ if (firstEqual === -1) {
150
+ return Option.none();
151
+ }
152
+ const name = parts[0].slice(0, firstEqual);
153
+ if (!fieldContentRegExp.test(name)) {
154
+ return Option.none();
155
+ }
156
+ const valueEncoded = parts[0].slice(firstEqual + 1);
157
+ const value = tryDecodeURIComponent(valueEncoded);
158
+ if (parts.length === 1) {
159
+ return Option.some(Object.assign(Object.create(CookieProto), {
160
+ name,
161
+ value,
162
+ valueEncoded
163
+ }));
164
+ }
165
+ const options = {};
166
+ for (let i = 1; i < parts.length; i++) {
167
+ const part = parts[i];
168
+ const equalIndex = part.indexOf("=");
169
+ const key = equalIndex === -1 ? part : part.slice(0, equalIndex).trim();
170
+ const value2 = equalIndex === -1 ? void 0 : part.slice(equalIndex + 1).trim();
171
+ switch (key.toLowerCase()) {
172
+ case "domain": {
173
+ if (value2 === void 0) {
174
+ break;
175
+ }
176
+ const domain = value2.trim().replace(/^\./, "");
177
+ if (domain) {
178
+ options.domain = domain;
179
+ }
180
+ break;
181
+ }
182
+ case "expires": {
183
+ if (value2 === void 0) {
184
+ break;
185
+ }
186
+ const date = new Date(value2);
187
+ if (!isNaN(date.getTime())) {
188
+ options.expires = date;
189
+ }
190
+ break;
191
+ }
192
+ case "max-age": {
193
+ if (value2 === void 0) {
194
+ break;
195
+ }
196
+ const maxAge = parseInt(value2, 10);
197
+ if (!isNaN(maxAge)) {
198
+ options.maxAge = Duration.seconds(maxAge);
199
+ }
200
+ break;
201
+ }
202
+ case "path": {
203
+ if (value2 === void 0) {
204
+ break;
205
+ }
206
+ if (value2[0] === "/") {
207
+ options.path = value2;
208
+ }
209
+ break;
210
+ }
211
+ case "priority": {
212
+ if (value2 === void 0) {
213
+ break;
214
+ }
215
+ switch (value2.toLowerCase()) {
216
+ case "low":
217
+ options.priority = "low";
218
+ break;
219
+ case "medium":
220
+ options.priority = "medium";
221
+ break;
222
+ case "high":
223
+ options.priority = "high";
224
+ break;
225
+ }
226
+ break;
227
+ }
228
+ case "httponly": {
229
+ options.httpOnly = true;
230
+ break;
231
+ }
232
+ case "secure": {
233
+ options.secure = true;
234
+ break;
235
+ }
236
+ case "partitioned": {
237
+ options.partitioned = true;
238
+ break;
239
+ }
240
+ case "samesite": {
241
+ if (value2 === void 0) {
242
+ break;
243
+ }
244
+ switch (value2.toLowerCase()) {
245
+ case "lax":
246
+ options.sameSite = "lax";
247
+ break;
248
+ case "strict":
249
+ options.sameSite = "strict";
250
+ break;
251
+ case "none":
252
+ options.sameSite = "none";
253
+ break;
254
+ }
255
+ break;
256
+ }
257
+ }
258
+ }
259
+ return Option.some(Object.assign(Object.create(CookieProto), {
260
+ name,
261
+ value,
262
+ valueEncoded,
263
+ options: Object.keys(options).length > 0 ? options : void 0
264
+ }));
265
+ }
266
+ var empty = /* @__PURE__ */ fromIterable([]);
267
+ var isEmpty = (self) => Record.isEmptyRecord(self.cookies);
268
+ var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
269
+ var CookieProto = {
270
+ [CookieTypeId]: CookieTypeId,
271
+ ...Inspectable.BaseProto,
272
+ toJSON() {
273
+ return {
274
+ _id: "@effect/platform/Cookies/Cookie",
275
+ name: this.name,
276
+ value: this.value,
277
+ options: this.options
278
+ };
279
+ }
280
+ };
281
+ function serializeCookie(self) {
282
+ let str = self.name + "=" + self.valueEncoded;
283
+ if (self.options === void 0) {
284
+ return str;
285
+ }
286
+ const options = self.options;
287
+ if (options.maxAge !== void 0) {
288
+ const maxAge = Duration.toSeconds(options.maxAge);
289
+ str += "; Max-Age=" + Math.trunc(maxAge);
290
+ }
291
+ if (options.domain !== void 0) {
292
+ str += "; Domain=" + options.domain;
293
+ }
294
+ if (options.path !== void 0) {
295
+ str += "; Path=" + options.path;
296
+ }
297
+ if (options.priority !== void 0) {
298
+ switch (options.priority) {
299
+ case "low":
300
+ str += "; Priority=Low";
301
+ break;
302
+ case "medium":
303
+ str += "; Priority=Medium";
304
+ break;
305
+ case "high":
306
+ str += "; Priority=High";
307
+ break;
308
+ }
309
+ }
310
+ if (options.expires !== void 0) {
311
+ str += "; Expires=" + options.expires.toUTCString();
312
+ }
313
+ if (options.httpOnly) {
314
+ str += "; HttpOnly";
315
+ }
316
+ if (options.secure) {
317
+ str += "; Secure";
318
+ }
319
+ if (options.partitioned) {
320
+ str += "; Partitioned";
321
+ }
322
+ if (options.sameSite !== void 0) {
323
+ switch (options.sameSite) {
324
+ case "lax":
325
+ str += "; SameSite=Lax";
326
+ break;
327
+ case "strict":
328
+ str += "; SameSite=Strict";
329
+ break;
330
+ case "none":
331
+ str += "; SameSite=None";
332
+ break;
333
+ }
334
+ }
335
+ return str;
336
+ }
337
+ var toSetCookieHeaders = (self) => Object.values(self.cookies).map(serializeCookie);
338
+ function parseHeader(header) {
339
+ const result = {};
340
+ const strLen = header.length;
341
+ let pos = 0;
342
+ let terminatorPos = 0;
343
+ while (true) {
344
+ if (terminatorPos === strLen) break;
345
+ terminatorPos = header.indexOf(";", pos);
346
+ if (terminatorPos === -1) terminatorPos = strLen;
347
+ let eqIdx = header.indexOf("=", pos);
348
+ if (eqIdx === -1) break;
349
+ if (eqIdx > terminatorPos) {
350
+ pos = terminatorPos + 1;
351
+ continue;
352
+ }
353
+ const key = header.substring(pos, eqIdx++).trim();
354
+ if (result[key] === void 0) {
355
+ const val = header.charCodeAt(eqIdx) === 34 ? header.substring(eqIdx + 1, terminatorPos - 1).trim() : header.substring(eqIdx, terminatorPos).trim();
356
+ result[key] = !(val.indexOf("%") === -1) ? tryDecodeURIComponent(val) : val;
357
+ }
358
+ pos = terminatorPos + 1;
359
+ }
360
+ return result;
361
+ }
362
+ var tryDecodeURIComponent = (str) => {
363
+ try {
364
+ return decodeURIComponent(str);
365
+ } catch {
366
+ return str;
367
+ }
368
+ };
369
+
370
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/Headers.js
371
+ var FiberRef = __toESM(require("effect/FiberRef"), 1);
372
+ var FiberRefs = __toESM(require("effect/FiberRefs"), 1);
373
+ var import_Function2 = require("effect/Function");
374
+ var import_GlobalValue = require("effect/GlobalValue");
375
+ var import_Inspectable = require("effect/Inspectable");
376
+ var Predicate3 = __toESM(require("effect/Predicate"), 1);
377
+ var Record2 = __toESM(require("effect/Record"), 1);
378
+ var Redacted = __toESM(require("effect/Redacted"), 1);
379
+ var Schema2 = __toESM(require("effect/Schema"), 1);
380
+ var String4 = __toESM(require("effect/String"), 1);
381
+ var HeadersTypeId = /* @__PURE__ */ Symbol.for("@effect/platform/Headers");
382
+ var Proto2 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(null), {
383
+ [HeadersTypeId]: HeadersTypeId,
384
+ [import_Inspectable.symbolRedactable](fiberRefs) {
385
+ return redact(this, FiberRefs.getOrDefault(fiberRefs, currentRedactedNames));
386
+ }
387
+ });
388
+ var make2 = (input) => Object.assign(Object.create(Proto2), input);
389
+ var empty2 = /* @__PURE__ */ Object.create(Proto2);
390
+ var fromInput = (input) => {
391
+ if (input === void 0) {
392
+ return empty2;
393
+ } else if (Symbol.iterator in input) {
394
+ const out2 = Object.create(Proto2);
395
+ for (const [k, v] of input) {
396
+ out2[k.toLowerCase()] = v;
397
+ }
398
+ return out2;
399
+ }
400
+ const out = Object.create(Proto2);
401
+ for (const [k, v] of Object.entries(input)) {
402
+ if (Array.isArray(v)) {
403
+ out[k.toLowerCase()] = v.join(", ");
404
+ } else if (v !== void 0) {
405
+ out[k.toLowerCase()] = v;
406
+ }
407
+ }
408
+ return out;
409
+ };
410
+ var remove2 = /* @__PURE__ */ (0, import_Function2.dual)(2, (self, key) => {
411
+ const out = make2(self);
412
+ const modify = (key2) => {
413
+ if (typeof key2 === "string") {
414
+ const k = key2.toLowerCase();
415
+ if (k in self) {
416
+ delete out[k];
417
+ }
418
+ } else {
419
+ for (const name in self) {
420
+ if (key2.test(name)) {
421
+ delete out[name];
422
+ }
423
+ }
424
+ }
425
+ };
426
+ if (Array.isArray(key)) {
427
+ for (let i = 0; i < key.length; i++) {
428
+ modify(key[i]);
429
+ }
430
+ } else {
431
+ modify(key);
432
+ }
433
+ return out;
434
+ });
435
+ var redact = /* @__PURE__ */ (0, import_Function2.dual)(2, (self, key) => {
436
+ const out = {
437
+ ...self
438
+ };
439
+ const modify = (key2) => {
440
+ if (typeof key2 === "string") {
441
+ const k = key2.toLowerCase();
442
+ if (k in self) {
443
+ out[k] = Redacted.make(self[k]);
444
+ }
445
+ } else {
446
+ for (const name in self) {
447
+ if (key2.test(name)) {
448
+ out[name] = Redacted.make(self[name]);
449
+ }
450
+ }
451
+ }
452
+ };
453
+ if (Array.isArray(key)) {
454
+ for (let i = 0; i < key.length; i++) {
455
+ modify(key[i]);
456
+ }
457
+ } else {
458
+ modify(key);
459
+ }
460
+ return out;
461
+ });
462
+ var currentRedactedNames = /* @__PURE__ */ (0, import_GlobalValue.globalValue)("@effect/platform/Headers/currentRedactedNames", () => FiberRef.unsafeMake(["authorization", "cookie", "set-cookie", "x-api-key"]));
463
+
464
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/HttpIncomingMessage.js
465
+ var Context2 = __toESM(require("effect/Context"), 1);
466
+ var Effect2 = __toESM(require("effect/Effect"), 1);
467
+ var import_Function5 = require("effect/Function");
468
+ var Inspectable2 = __toESM(require("effect/Inspectable"), 1);
469
+ var Option4 = __toESM(require("effect/Option"), 1);
470
+ var Schema4 = __toESM(require("effect/Schema"), 1);
471
+
472
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/FileSystem.js
473
+ var Brand = __toESM(require("effect/Brand"), 1);
474
+ var Context = __toESM(require("effect/Context"), 1);
475
+ var Data2 = __toESM(require("effect/Data"), 1);
476
+
477
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/internal/fileSystem.js
478
+ var Channel = __toESM(require("effect/Channel"), 1);
479
+ var Chunk = __toESM(require("effect/Chunk"), 1);
480
+ var import_Context = require("effect/Context");
481
+ var Effect = __toESM(require("effect/Effect"), 1);
482
+ var import_Function3 = require("effect/Function");
483
+ var Layer = __toESM(require("effect/Layer"), 1);
484
+ var Option2 = __toESM(require("effect/Option"), 1);
485
+ var Sink = __toESM(require("effect/Sink"), 1);
486
+ var Stream = __toESM(require("effect/Stream"), 1);
487
+ var tag = /* @__PURE__ */ (0, import_Context.GenericTag)("@effect/platform/FileSystem");
488
+ var Size = (bytes) => typeof bytes === "bigint" ? bytes : BigInt(bytes);
489
+ var bigint1024 = /* @__PURE__ */ BigInt(1024);
490
+ var bigintPiB = bigint1024 * bigint1024 * bigint1024 * bigint1024 * bigint1024;
491
+
492
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/FileSystem.js
493
+ var Size2 = Size;
494
+ var FileSystem = tag;
495
+
496
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/UrlParams.js
497
+ var Arr = __toESM(require("effect/Array"), 1);
498
+ var Either2 = __toESM(require("effect/Either"), 1);
499
+ var import_Function4 = require("effect/Function");
500
+ var Option3 = __toESM(require("effect/Option"), 1);
501
+ var Schema3 = __toESM(require("effect/Schema"), 1);
502
+ var fromInput2 = (input) => {
503
+ const parsed = fromInputNested(input);
504
+ const out = [];
505
+ for (let i = 0; i < parsed.length; i++) {
506
+ if (Array.isArray(parsed[i][0])) {
507
+ const [keys, value] = parsed[i];
508
+ out.push([`${keys[0]}[${keys.slice(1).join("][")}]`, value]);
509
+ } else {
510
+ out.push(parsed[i]);
511
+ }
512
+ }
513
+ return out;
514
+ };
515
+ var fromInputNested = (input) => {
516
+ const entries = Symbol.iterator in input ? Arr.fromIterable(input) : Object.entries(input);
517
+ const out = [];
518
+ for (const [key, value] of entries) {
519
+ if (Array.isArray(value)) {
520
+ for (let i = 0; i < value.length; i++) {
521
+ if (value[i] !== void 0) {
522
+ out.push([key, String(value[i])]);
523
+ }
524
+ }
525
+ } else if (typeof value === "object") {
526
+ const nested = fromInputNested(value);
527
+ for (const [k, v] of nested) {
528
+ out.push([[key, ...typeof k === "string" ? [k] : k], v]);
529
+ }
530
+ } else if (value !== void 0) {
531
+ out.push([key, String(value)]);
532
+ }
533
+ }
534
+ return out;
535
+ };
536
+
537
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/HttpIncomingMessage.js
538
+ var TypeId3 = /* @__PURE__ */ Symbol.for("@effect/platform/HttpIncomingMessage");
539
+ var MaxBodySize = class extends (/* @__PURE__ */ Context2.Reference()("@effect/platform/HttpIncomingMessage/MaxBodySize", {
540
+ defaultValue: Option4.none
541
+ })) {
542
+ };
543
+ var inspect = (self, that) => {
544
+ const contentType = self.headers["content-type"] ?? "";
545
+ let body;
546
+ if (contentType.includes("application/json")) {
547
+ try {
548
+ body = Effect2.runSync(self.json);
549
+ } catch {
550
+ }
551
+ } else if (contentType.includes("text/") || contentType.includes("urlencoded")) {
552
+ try {
553
+ body = Effect2.runSync(self.text);
554
+ } catch {
555
+ }
556
+ }
557
+ const obj = {
558
+ ...that,
559
+ headers: Inspectable2.redact(self.headers),
560
+ remoteAddress: self.remoteAddress.toJSON()
561
+ };
562
+ if (body !== void 0) {
563
+ obj.body = body;
564
+ }
565
+ return obj;
566
+ };
567
+
568
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/HttpTraceContext.js
569
+ var Option5 = __toESM(require("effect/Option"), 1);
570
+ var Tracer = __toESM(require("effect/Tracer"), 1);
571
+ var fromHeaders = (headers) => {
572
+ let span = w3c(headers);
573
+ if (span._tag === "Some") {
574
+ return span;
575
+ }
576
+ span = b3(headers);
577
+ if (span._tag === "Some") {
578
+ return span;
579
+ }
580
+ return xb3(headers);
581
+ };
582
+ var b3 = (headers) => {
583
+ if (!("b3" in headers)) {
584
+ return Option5.none();
585
+ }
586
+ const parts = headers["b3"].split("-");
587
+ if (parts.length < 2) {
588
+ return Option5.none();
589
+ }
590
+ return Option5.some(Tracer.externalSpan({
591
+ traceId: parts[0],
592
+ spanId: parts[1],
593
+ sampled: parts[2] ? parts[2] === "1" : true
594
+ }));
595
+ };
596
+ var xb3 = (headers) => {
597
+ if (!headers["x-b3-traceid"] || !headers["x-b3-spanid"]) {
598
+ return Option5.none();
599
+ }
600
+ return Option5.some(Tracer.externalSpan({
601
+ traceId: headers["x-b3-traceid"],
602
+ spanId: headers["x-b3-spanid"],
603
+ sampled: headers["x-b3-sampled"] ? headers["x-b3-sampled"] === "1" : true
604
+ }));
605
+ };
606
+ var w3cTraceId = /^[0-9a-f]{32}$/i;
607
+ var w3cSpanId = /^[0-9a-f]{16}$/i;
608
+ var w3c = (headers) => {
609
+ if (!headers["traceparent"]) {
610
+ return Option5.none();
611
+ }
612
+ const parts = headers["traceparent"].split("-");
613
+ if (parts.length !== 4) {
614
+ return Option5.none();
615
+ }
616
+ const [version, traceId, spanId, flags] = parts;
617
+ switch (version) {
618
+ case "00": {
619
+ if (w3cTraceId.test(traceId) === false || w3cSpanId.test(spanId) === false) {
620
+ return Option5.none();
621
+ }
622
+ return Option5.some(Tracer.externalSpan({
623
+ traceId,
624
+ spanId,
625
+ sampled: (parseInt(flags, 16) & 1) === 1
626
+ }));
627
+ }
628
+ default: {
629
+ return Option5.none();
630
+ }
631
+ }
632
+ };
633
+
634
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/internal/httpBody.js
635
+ var Data3 = __toESM(require("effect/Data"), 1);
636
+ var Effect3 = __toESM(require("effect/Effect"), 1);
637
+ var import_Function6 = require("effect/Function");
638
+ var Inspectable3 = __toESM(require("effect/Inspectable"), 1);
639
+ var Schema5 = __toESM(require("effect/Schema"), 1);
640
+ var Stream_ = __toESM(require("effect/Stream"), 1);
641
+ var TypeId4 = /* @__PURE__ */ Symbol.for("@effect/platform/HttpBody");
642
+ var BodyBase = class {
643
+ [TypeId4];
644
+ constructor() {
645
+ this[TypeId4] = TypeId4;
646
+ }
647
+ [Inspectable3.NodeInspectSymbol]() {
648
+ return this.toJSON();
649
+ }
650
+ toString() {
651
+ return Inspectable3.format(this);
652
+ }
653
+ };
654
+ var EmptyImpl = class extends BodyBase {
655
+ _tag = "Empty";
656
+ toJSON() {
657
+ return {
658
+ _id: "@effect/platform/HttpBody",
659
+ _tag: "Empty"
660
+ };
661
+ }
662
+ };
663
+ var empty3 = /* @__PURE__ */ new EmptyImpl();
664
+ var StreamImpl = class extends BodyBase {
665
+ stream;
666
+ contentType;
667
+ contentLength;
668
+ _tag = "Stream";
669
+ constructor(stream4, contentType, contentLength) {
670
+ super();
671
+ this.stream = stream4;
672
+ this.contentType = contentType;
673
+ this.contentLength = contentLength;
674
+ }
675
+ toJSON() {
676
+ return {
677
+ _id: "@effect/platform/HttpBody",
678
+ _tag: "Stream",
679
+ contentType: this.contentType,
680
+ contentLength: this.contentLength
681
+ };
682
+ }
683
+ };
684
+ var stream = (body, contentType, contentLength) => new StreamImpl(body, contentType ?? "application/octet-stream", contentLength);
685
+
686
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/HttpApp.js
687
+ var HttpApp_exports = {};
688
+ __export(HttpApp_exports, {
689
+ appendPreResponseHandler: () => appendPreResponseHandler2,
690
+ currentPreResponseHandlers: () => currentPreResponseHandlers2,
691
+ ejectDefaultScopeClose: () => ejectDefaultScopeClose,
692
+ fromWebHandler: () => fromWebHandler,
693
+ toHandled: () => toHandled,
694
+ toWebHandler: () => toWebHandler,
695
+ toWebHandlerLayer: () => toWebHandlerLayer,
696
+ toWebHandlerLayerWith: () => toWebHandlerLayerWith,
697
+ toWebHandlerRuntime: () => toWebHandlerRuntime,
698
+ unsafeEjectStreamScope: () => unsafeEjectStreamScope,
699
+ withPreResponseHandler: () => withPreResponseHandler2
700
+ });
701
+ var Cause3 = __toESM(require("effect/Cause"), 1);
702
+ var Context7 = __toESM(require("effect/Context"), 1);
703
+ var Effect13 = __toESM(require("effect/Effect"), 1);
704
+ var Exit2 = __toESM(require("effect/Exit"), 1);
705
+ var Fiber = __toESM(require("effect/Fiber"), 1);
706
+ var GlobalValue = __toESM(require("effect/GlobalValue"), 1);
707
+ var Layer4 = __toESM(require("effect/Layer"), 1);
708
+ var Option12 = __toESM(require("effect/Option"), 1);
709
+ var Runtime3 = __toESM(require("effect/Runtime"), 1);
710
+ var Scope = __toESM(require("effect/Scope"), 1);
711
+ var Stream7 = __toESM(require("effect/Stream"), 1);
712
+ var import_Unify = require("effect/Unify");
713
+
714
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/HttpBody.js
715
+ var Predicate4 = __toESM(require("effect/Predicate"), 1);
716
+ var stream2 = stream;
717
+
718
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/HttpServerRespondable.js
719
+ var Cause = __toESM(require("effect/Cause"), 1);
720
+ var Effect5 = __toESM(require("effect/Effect"), 1);
721
+ var ParseResult = __toESM(require("effect/ParseResult"), 1);
722
+ var import_Predicate = require("effect/Predicate");
723
+
724
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/HttpServerResponse.js
725
+ var Stream3 = __toESM(require("effect/Stream"), 1);
726
+
727
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/internal/httpServerResponse.js
728
+ var Context3 = __toESM(require("effect/Context"), 1);
729
+ var Effect4 = __toESM(require("effect/Effect"), 1);
730
+ var Effectable = __toESM(require("effect/Effectable"), 1);
731
+ var import_Function7 = require("effect/Function");
732
+ var Inspectable4 = __toESM(require("effect/Inspectable"), 1);
733
+ var Runtime = __toESM(require("effect/Runtime"), 1);
734
+ var Stream2 = __toESM(require("effect/Stream"), 1);
735
+ var TypeId5 = /* @__PURE__ */ Symbol.for("@effect/platform/HttpServerResponse");
736
+ var respondableSymbol = /* @__PURE__ */ Symbol.for("@effect/platform/HttpServerRespondable");
737
+ var ServerResponseImpl = class extends Effectable.StructuralClass {
738
+ status;
739
+ statusText;
740
+ cookies;
741
+ body;
742
+ [TypeId5];
743
+ headers;
744
+ constructor(status, statusText, headers, cookies, body) {
745
+ super();
746
+ this.status = status;
747
+ this.statusText = statusText;
748
+ this.cookies = cookies;
749
+ this.body = body;
750
+ this[TypeId5] = TypeId5;
751
+ if (body.contentType || body.contentLength) {
752
+ const newHeaders = {
753
+ ...headers
754
+ };
755
+ if (body.contentType) {
756
+ newHeaders["content-type"] = body.contentType;
757
+ }
758
+ if (body.contentLength) {
759
+ newHeaders["content-length"] = body.contentLength.toString();
760
+ }
761
+ this.headers = newHeaders;
762
+ } else {
763
+ this.headers = headers;
764
+ }
765
+ }
766
+ commit() {
767
+ return Effect4.succeed(this);
768
+ }
769
+ [respondableSymbol]() {
770
+ return Effect4.succeed(this);
771
+ }
772
+ [Inspectable4.NodeInspectSymbol]() {
773
+ return this.toJSON();
774
+ }
775
+ toString() {
776
+ return Inspectable4.format(this);
777
+ }
778
+ toJSON() {
779
+ return {
780
+ _id: "@effect/platform/HttpServerResponse",
781
+ status: this.status,
782
+ statusText: this.statusText,
783
+ headers: Inspectable4.redact(this.headers),
784
+ cookies: this.cookies.toJSON(),
785
+ body: this.body.toJSON()
786
+ };
787
+ }
788
+ };
789
+ var isServerResponse = (u) => typeof u === "object" && u !== null && TypeId5 in u;
790
+ var empty4 = (options) => new ServerResponseImpl(options?.status ?? 204, options?.statusText, options?.headers ? fromInput(options.headers) : empty2, options?.cookies ?? empty, empty3);
791
+ var setBody = /* @__PURE__ */ (0, import_Function7.dual)(2, (self, body) => {
792
+ let headers = self.headers;
793
+ if (body._tag === "Empty") {
794
+ headers = remove2(remove2(headers, "Content-Type"), "Content-length");
795
+ }
796
+ return new ServerResponseImpl(self.status, self.statusText, headers, self.cookies, body);
797
+ });
798
+ var toWeb = (response, options) => {
799
+ const headers = new globalThis.Headers(response.headers);
800
+ if (!isEmpty(response.cookies)) {
801
+ const toAdd = toSetCookieHeaders(response.cookies);
802
+ for (const header of toAdd) {
803
+ headers.append("set-cookie", header);
804
+ }
805
+ }
806
+ if (options?.withoutBody) {
807
+ return new Response(void 0, {
808
+ status: response.status,
809
+ statusText: response.statusText,
810
+ headers
811
+ });
812
+ }
813
+ const body = response.body;
814
+ switch (body._tag) {
815
+ case "Empty": {
816
+ return new Response(void 0, {
817
+ status: response.status,
818
+ statusText: response.statusText,
819
+ headers
820
+ });
821
+ }
822
+ case "Uint8Array":
823
+ case "Raw": {
824
+ if (body.body instanceof Response) {
825
+ for (const [key, value] of headers) {
826
+ body.body.headers.set(key, value);
827
+ }
828
+ return body.body;
829
+ }
830
+ return new Response(body.body, {
831
+ status: response.status,
832
+ statusText: response.statusText,
833
+ headers
834
+ });
835
+ }
836
+ case "FormData": {
837
+ return new Response(body.formData, {
838
+ status: response.status,
839
+ statusText: response.statusText,
840
+ headers
841
+ });
842
+ }
843
+ case "Stream": {
844
+ return new Response(Stream2.toReadableStreamRuntime(body.stream, options?.runtime ?? Runtime.defaultRuntime), {
845
+ status: response.status,
846
+ statusText: response.statusText,
847
+ headers
848
+ });
849
+ }
850
+ }
851
+ };
852
+
853
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/HttpServerResponse.js
854
+ var isServerResponse2 = isServerResponse;
855
+ var empty5 = empty4;
856
+ var setBody2 = setBody;
857
+ var toWeb2 = toWeb;
858
+ var fromWeb = (response) => {
859
+ const headers = new globalThis.Headers(response.headers);
860
+ const setCookieHeaders = headers.getSetCookie();
861
+ headers.delete("set-cookie");
862
+ let self = empty5({
863
+ status: response.status,
864
+ statusText: response.statusText,
865
+ headers,
866
+ cookies: fromSetCookie(setCookieHeaders)
867
+ });
868
+ if (response.body) {
869
+ const contentType = headers.get("content-type");
870
+ self = setBody2(self, stream2(Stream3.fromReadableStream({
871
+ evaluate: () => response.body,
872
+ onError: (e) => e
873
+ }), contentType ?? void 0));
874
+ }
875
+ return self;
876
+ };
877
+
878
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/HttpServerRespondable.js
879
+ var symbol = /* @__PURE__ */ Symbol.for("@effect/platform/HttpServerRespondable");
880
+ var isRespondable = (u) => (0, import_Predicate.hasProperty)(u, symbol);
881
+ var badRequest = /* @__PURE__ */ empty5({
882
+ status: 400
883
+ });
884
+ var notFound = /* @__PURE__ */ empty5({
885
+ status: 404
886
+ });
887
+ var toResponseOrElse = (u, orElse) => {
888
+ if (isServerResponse2(u)) {
889
+ return Effect5.succeed(u);
890
+ } else if (isRespondable(u)) {
891
+ return Effect5.catchAllCause(u[symbol](), () => Effect5.succeed(orElse));
892
+ } else if (ParseResult.isParseError(u)) {
893
+ return Effect5.succeed(badRequest);
894
+ } else if (Cause.isNoSuchElementException(u)) {
895
+ return Effect5.succeed(notFound);
896
+ }
897
+ return Effect5.succeed(orElse);
898
+ };
899
+ var toResponseOrElseDefect = (u, orElse) => {
900
+ if (isServerResponse2(u)) {
901
+ return Effect5.succeed(u);
902
+ } else if (isRespondable(u)) {
903
+ return Effect5.catchAllCause(u[symbol](), () => Effect5.succeed(orElse));
904
+ }
905
+ return Effect5.succeed(orElse);
906
+ };
907
+
908
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/internal/httpServerError.js
909
+ var Cause2 = __toESM(require("effect/Cause"), 1);
910
+ var Effect6 = __toESM(require("effect/Effect"), 1);
911
+ var FiberId = __toESM(require("effect/FiberId"), 1);
912
+ var import_GlobalValue2 = require("effect/GlobalValue");
913
+ var Option6 = __toESM(require("effect/Option"), 1);
914
+ var Predicate5 = __toESM(require("effect/Predicate"), 1);
915
+ var TypeId6 = /* @__PURE__ */ Symbol.for("@effect/platform/HttpServerError");
916
+ var clientAbortFiberId = /* @__PURE__ */ (0, import_GlobalValue2.globalValue)("@effect/platform/HttpServerError/clientAbortFiberId", () => FiberId.runtime(-499, 0));
917
+ var causeResponse = (cause) => {
918
+ const [effect, stripped] = Cause2.reduce(cause, [Effect6.succeed(internalServerError), Cause2.empty], (acc, cause2) => {
919
+ const withoutInterrupt = Cause2.isInterruptType(acc[1]) ? Cause2.empty : acc[1];
920
+ switch (cause2._tag) {
921
+ case "Fail": {
922
+ return Option6.some([toResponseOrElse(cause2.error, internalServerError), combineCauses(withoutInterrupt, cause2)]);
923
+ }
924
+ case "Die": {
925
+ const isResponse = isServerResponse(cause2.defect);
926
+ return Option6.some([toResponseOrElseDefect(cause2.defect, internalServerError), isResponse ? withoutInterrupt : combineCauses(withoutInterrupt, cause2)]);
927
+ }
928
+ case "Interrupt": {
929
+ if (acc[1]._tag !== "Empty") {
930
+ return Option6.none();
931
+ }
932
+ const response = cause2.fiberId === clientAbortFiberId ? clientAbortError : serverAbortError;
933
+ return Option6.some([Effect6.succeed(response), cause2]);
934
+ }
935
+ default: {
936
+ return Option6.none();
937
+ }
938
+ }
939
+ });
940
+ return Effect6.map(effect, (response) => {
941
+ if (Cause2.isEmptyType(stripped)) {
942
+ return [response, Cause2.empty];
943
+ }
944
+ return [response, Cause2.sequential(stripped, Cause2.die(response))];
945
+ });
946
+ };
947
+ var combineCauses = (left4, right4) => {
948
+ if (Cause2.isEmptyType(left4)) {
949
+ return right4;
950
+ } else if (Cause2.isEmptyType(right4)) {
951
+ return left4;
952
+ }
953
+ return Cause2.sequential(left4, right4);
954
+ };
955
+ var causeResponseStripped = (cause) => {
956
+ let response;
957
+ const stripped = Cause2.stripSomeDefects(cause, (defect) => {
958
+ if (isServerResponse(defect)) {
959
+ response = defect;
960
+ return Option6.some(Cause2.empty);
961
+ }
962
+ return Option6.none();
963
+ });
964
+ return [response ?? internalServerError, stripped];
965
+ };
966
+ var internalServerError = /* @__PURE__ */ empty4({
967
+ status: 500
968
+ });
969
+ var clientAbortError = /* @__PURE__ */ empty4({
970
+ status: 499
971
+ });
972
+ var serverAbortError = /* @__PURE__ */ empty4({
973
+ status: 503
974
+ });
975
+ var exitResponse = (exit2) => {
976
+ if (exit2._tag === "Success") {
977
+ return exit2.value;
978
+ }
979
+ return causeResponseStripped(exit2.cause)[0];
980
+ };
981
+
982
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/HttpServerError.js
983
+ var TypeId7 = TypeId6;
984
+ var RequestError = class extends (/* @__PURE__ */ TypeIdError(TypeId7, "RequestError")) {
985
+ /**
986
+ * @since 1.0.0
987
+ */
988
+ [symbol]() {
989
+ return empty5({
990
+ status: 400
991
+ });
992
+ }
993
+ get methodAndUrl() {
994
+ return `${this.request.method} ${this.request.url}`;
995
+ }
996
+ get message() {
997
+ return this.description ? `${this.reason}: ${this.description} (${this.methodAndUrl})` : `${this.reason} error (${this.methodAndUrl})`;
998
+ }
999
+ };
1000
+ var RouteNotFound = class extends (/* @__PURE__ */ TypeIdError(TypeId7, "RouteNotFound")) {
1001
+ constructor(options) {
1002
+ super(options);
1003
+ this.stack = `${this.name}: ${this.message}`;
1004
+ }
1005
+ /**
1006
+ * @since 1.0.0
1007
+ */
1008
+ [symbol]() {
1009
+ return empty5({
1010
+ status: 404
1011
+ });
1012
+ }
1013
+ get message() {
1014
+ return `${this.request.method} ${this.request.url} not found`;
1015
+ }
1016
+ };
1017
+ var ResponseError = class extends (/* @__PURE__ */ TypeIdError(TypeId7, "ResponseError")) {
1018
+ /**
1019
+ * @since 1.0.0
1020
+ */
1021
+ [symbol]() {
1022
+ return empty5({
1023
+ status: 500
1024
+ });
1025
+ }
1026
+ get methodAndUrl() {
1027
+ return `${this.request.method} ${this.request.url}`;
1028
+ }
1029
+ get message() {
1030
+ const info = `${this.response.status} ${this.methodAndUrl}`;
1031
+ return this.description ? `${this.description} (${info})` : `${this.reason} error (${info})`;
1032
+ }
1033
+ };
1034
+ var clientAbortFiberId2 = clientAbortFiberId;
1035
+ var causeResponse2 = causeResponse;
1036
+ var exitResponse2 = exitResponse;
1037
+
1038
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/HttpServerRequest.js
1039
+ var Effect10 = __toESM(require("effect/Effect"), 1);
1040
+ var Either3 = __toESM(require("effect/Either"), 1);
1041
+ var Option9 = __toESM(require("effect/Option"), 1);
1042
+ var Runtime2 = __toESM(require("effect/Runtime"), 1);
1043
+ var Stream6 = __toESM(require("effect/Stream"), 1);
1044
+
1045
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/HttpMethod.js
1046
+ var hasBody = (method) => method !== "GET" && method !== "HEAD" && method !== "OPTIONS";
1047
+
1048
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/internal/httpServerRequest.js
1049
+ var Channel3 = __toESM(require("effect/Channel"), 1);
1050
+ var Context5 = __toESM(require("effect/Context"), 1);
1051
+ var Effect9 = __toESM(require("effect/Effect"), 1);
1052
+ var Inspectable6 = __toESM(require("effect/Inspectable"), 1);
1053
+ var Option8 = __toESM(require("effect/Option"), 1);
1054
+ var Schema7 = __toESM(require("effect/Schema"), 1);
1055
+ var Stream5 = __toESM(require("effect/Stream"), 1);
1056
+
1057
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/Multipart.js
1058
+ var Channel2 = __toESM(require("effect/Channel"), 1);
1059
+ var Chunk2 = __toESM(require("effect/Chunk"), 1);
1060
+ var Context4 = __toESM(require("effect/Context"), 1);
1061
+ var Effect8 = __toESM(require("effect/Effect"), 1);
1062
+ var Exit = __toESM(require("effect/Exit"), 1);
1063
+ var import_Function9 = require("effect/Function");
1064
+ var Inspectable5 = __toESM(require("effect/Inspectable"), 1);
1065
+ var Mailbox = __toESM(require("effect/Mailbox"), 1);
1066
+ var Option7 = __toESM(require("effect/Option"), 1);
1067
+ var Predicate6 = __toESM(require("effect/Predicate"), 1);
1068
+ var Schema6 = __toESM(require("effect/Schema"), 1);
1069
+ var Stream4 = __toESM(require("effect/Stream"), 1);
1070
+
1071
+ // ../../node_modules/.bun/multipasta@0.2.7/node_modules/multipasta/dist/esm/internal/contentType.js
1072
+ var paramRE = /; *([!#$%&'*+.^\w`|~-]+)=("(?:[\v\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\v\u0020-\u00ff])*"|[!#$%&'*+.^\w`|~-]+) */gu;
1073
+ var quotedPairRE = /\\([\v\u0020-\u00ff])/gu;
1074
+ var mediaTypeRE = /^[!#$%&'*+.^\w|~-]+\/[!#$%&'*+.^\w|~-]+$/u;
1075
+ var mediaTypeRENoSlash = /^[!#$%&'*+.^\w|~-]+$/u;
1076
+ var defaultContentType = {
1077
+ value: "",
1078
+ parameters: /* @__PURE__ */ Object.create(null)
1079
+ };
1080
+ function parse(header, withoutSlash = false) {
1081
+ if (typeof header !== "string") {
1082
+ return defaultContentType;
1083
+ }
1084
+ let index = header.indexOf(";");
1085
+ const type = index !== -1 ? header.slice(0, index).trim() : header.trim();
1086
+ const mediaRE = withoutSlash ? mediaTypeRENoSlash : mediaTypeRE;
1087
+ if (mediaRE.test(type) === false) {
1088
+ return defaultContentType;
1089
+ }
1090
+ const result = {
1091
+ value: type.toLowerCase(),
1092
+ parameters: /* @__PURE__ */ Object.create(null)
1093
+ };
1094
+ if (index === -1) {
1095
+ return result;
1096
+ }
1097
+ let key;
1098
+ let match3;
1099
+ let value;
1100
+ paramRE.lastIndex = index;
1101
+ while (match3 = paramRE.exec(header)) {
1102
+ if (match3.index !== index) {
1103
+ return defaultContentType;
1104
+ }
1105
+ index += match3[0].length;
1106
+ key = match3[1].toLowerCase();
1107
+ value = match3[2];
1108
+ if (value[0] === '"') {
1109
+ value = value.slice(1, value.length - 1);
1110
+ !withoutSlash && quotedPairRE.test(value) && (value = value.replace(quotedPairRE, "$1"));
1111
+ }
1112
+ result.parameters[key] = value;
1113
+ }
1114
+ if (index !== header.length) {
1115
+ return defaultContentType;
1116
+ }
1117
+ return result;
1118
+ }
1119
+
1120
+ // ../../node_modules/.bun/multipasta@0.2.7/node_modules/multipasta/dist/esm/internal/headers.js
1121
+ var constMaxPairs = 100;
1122
+ var constMaxSize = 16 * 1024;
1123
+ var State;
1124
+ (function(State3) {
1125
+ State3[State3["key"] = 0] = "key";
1126
+ State3[State3["whitespace"] = 1] = "whitespace";
1127
+ State3[State3["value"] = 2] = "value";
1128
+ })(State || (State = {}));
1129
+ var constContinue = {
1130
+ _tag: "Continue"
1131
+ };
1132
+ var constNameChars = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1];
1133
+ var constValueChars = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
1134
+ function make4() {
1135
+ const decoder = new TextDecoder();
1136
+ const state = {
1137
+ state: State.key,
1138
+ headers: /* @__PURE__ */ Object.create(null),
1139
+ key: "",
1140
+ value: void 0,
1141
+ crlf: 0,
1142
+ previousChunk: void 0,
1143
+ pairs: 0,
1144
+ size: 0
1145
+ };
1146
+ function reset(value) {
1147
+ state.state = State.key;
1148
+ state.headers = /* @__PURE__ */ Object.create(null);
1149
+ state.key = "";
1150
+ state.value = void 0;
1151
+ state.crlf = 0;
1152
+ state.previousChunk = void 0;
1153
+ state.pairs = 0;
1154
+ state.size = 0;
1155
+ return value;
1156
+ }
1157
+ function concatUint8Array(a, b) {
1158
+ const newUint8Array = new Uint8Array(a.length + b.length);
1159
+ newUint8Array.set(a);
1160
+ newUint8Array.set(b, a.length);
1161
+ return newUint8Array;
1162
+ }
1163
+ function error(reason) {
1164
+ return reset({
1165
+ _tag: "Failure",
1166
+ reason,
1167
+ headers: state.headers
1168
+ });
1169
+ }
1170
+ return function write3(chunk, start) {
1171
+ let endOffset = 0;
1172
+ let previousCursor;
1173
+ if (state.previousChunk !== void 0) {
1174
+ endOffset = state.previousChunk.length;
1175
+ previousCursor = endOffset;
1176
+ const newChunk = new Uint8Array(chunk.length + endOffset);
1177
+ newChunk.set(state.previousChunk);
1178
+ newChunk.set(chunk, endOffset);
1179
+ state.previousChunk = void 0;
1180
+ chunk = newChunk;
1181
+ }
1182
+ const end = chunk.length;
1183
+ outer: while (start < end) {
1184
+ if (state.state === State.key) {
1185
+ let i = start;
1186
+ for (; i < end; i++) {
1187
+ if (state.size++ > constMaxSize) {
1188
+ return error("HeaderTooLarge");
1189
+ }
1190
+ if (chunk[i] === 58) {
1191
+ state.key += decoder.decode(chunk.subarray(start, i)).toLowerCase();
1192
+ if (state.key.length === 0) {
1193
+ return error("InvalidHeaderName");
1194
+ }
1195
+ if (chunk[i + 1] === 32 && chunk[i + 2] !== 32 && chunk[i + 2] !== 9) {
1196
+ start = i + 2;
1197
+ state.state = State.value;
1198
+ state.size++;
1199
+ } else if (chunk[i + 1] !== 32 && chunk[i + 1] !== 9) {
1200
+ start = i + 1;
1201
+ state.state = State.value;
1202
+ } else {
1203
+ start = i + 1;
1204
+ state.state = State.whitespace;
1205
+ }
1206
+ break;
1207
+ } else if (constNameChars[chunk[i]] !== 1) {
1208
+ return error("InvalidHeaderName");
1209
+ }
1210
+ }
1211
+ if (i === end) {
1212
+ state.key += decoder.decode(chunk.subarray(start, end)).toLowerCase();
1213
+ return constContinue;
1214
+ }
1215
+ }
1216
+ if (state.state === State.whitespace) {
1217
+ for (; start < end; start++) {
1218
+ if (state.size++ > constMaxSize) {
1219
+ return error("HeaderTooLarge");
1220
+ }
1221
+ if (chunk[start] !== 32 && chunk[start] !== 9) {
1222
+ state.state = State.value;
1223
+ break;
1224
+ }
1225
+ }
1226
+ if (start === end) {
1227
+ return constContinue;
1228
+ }
1229
+ }
1230
+ if (state.state === State.value) {
1231
+ let i = start;
1232
+ if (previousCursor !== void 0) {
1233
+ i = previousCursor;
1234
+ previousCursor = void 0;
1235
+ }
1236
+ for (; i < end; i++) {
1237
+ if (state.size++ > constMaxSize) {
1238
+ return error("HeaderTooLarge");
1239
+ }
1240
+ if (chunk[i] === 13 || state.crlf > 0) {
1241
+ let byte = chunk[i];
1242
+ if (byte === 13 && state.crlf === 0) {
1243
+ state.crlf = 1;
1244
+ i++;
1245
+ state.size++;
1246
+ byte = chunk[i];
1247
+ }
1248
+ if (byte === 10 && state.crlf === 1) {
1249
+ state.crlf = 2;
1250
+ i++;
1251
+ state.size++;
1252
+ byte = chunk[i];
1253
+ }
1254
+ if (byte === 13 && state.crlf === 2) {
1255
+ state.crlf = 3;
1256
+ i++;
1257
+ state.size++;
1258
+ byte = chunk[i];
1259
+ }
1260
+ if (byte === 10 && state.crlf === 3) {
1261
+ state.crlf = 4;
1262
+ i++;
1263
+ state.size++;
1264
+ }
1265
+ if (state.crlf < 4 && i >= end) {
1266
+ state.previousChunk = chunk.subarray(start);
1267
+ return constContinue;
1268
+ } else if (state.crlf >= 2) {
1269
+ state.value = state.value === void 0 ? chunk.subarray(start, i - state.crlf) : concatUint8Array(state.value, chunk.subarray(start, i - state.crlf));
1270
+ const value = decoder.decode(state.value);
1271
+ if (state.headers[state.key] === void 0) {
1272
+ state.headers[state.key] = value;
1273
+ } else if (typeof state.headers[state.key] === "string") {
1274
+ state.headers[state.key] = [state.headers[state.key], value];
1275
+ } else {
1276
+ ;
1277
+ state.headers[state.key].push(value);
1278
+ }
1279
+ start = i;
1280
+ state.size--;
1281
+ if (state.crlf !== 4 && state.pairs === constMaxPairs) {
1282
+ return error("TooManyHeaders");
1283
+ } else if (state.crlf === 3) {
1284
+ return error("InvalidHeaderValue");
1285
+ } else if (state.crlf === 4) {
1286
+ return reset({
1287
+ _tag: "Headers",
1288
+ headers: state.headers,
1289
+ endPosition: start - endOffset
1290
+ });
1291
+ }
1292
+ state.pairs++;
1293
+ state.key = "";
1294
+ state.value = void 0;
1295
+ state.crlf = 0;
1296
+ state.state = State.key;
1297
+ continue outer;
1298
+ }
1299
+ } else if (constValueChars[chunk[i]] !== 1) {
1300
+ return error("InvalidHeaderValue");
1301
+ }
1302
+ }
1303
+ if (i === end) {
1304
+ state.value = state.value === void 0 ? chunk.subarray(start, end) : concatUint8Array(state.value, chunk.subarray(start, end));
1305
+ return constContinue;
1306
+ }
1307
+ }
1308
+ }
1309
+ if (start > end) {
1310
+ state.size += end - start;
1311
+ }
1312
+ return constContinue;
1313
+ };
1314
+ }
1315
+
1316
+ // ../../node_modules/.bun/multipasta@0.2.7/node_modules/multipasta/dist/esm/internal/search.js
1317
+ function makeState(needle_) {
1318
+ const needle = new TextEncoder().encode(needle_);
1319
+ const needleLength = needle.length;
1320
+ const indexes = {};
1321
+ for (let i = 0; i < needleLength; i++) {
1322
+ const b = needle[i];
1323
+ if (indexes[b] === void 0) indexes[b] = [];
1324
+ indexes[b].push(i);
1325
+ }
1326
+ return {
1327
+ needle,
1328
+ needleLength,
1329
+ indexes,
1330
+ firstByte: needle[0],
1331
+ previousChunk: void 0,
1332
+ previousChunkLength: 0,
1333
+ matchIndex: 0
1334
+ };
1335
+ }
1336
+ function make5(needle, callback, seed) {
1337
+ const state = makeState(needle);
1338
+ if (seed !== void 0) {
1339
+ state.previousChunk = seed;
1340
+ state.previousChunkLength = seed.length;
1341
+ }
1342
+ function makeIndexOf() {
1343
+ if ("Buffer" in globalThis && !("Bun" in globalThis || "Deno" in globalThis)) {
1344
+ return function(chunk, needle2, fromIndex) {
1345
+ return Buffer.prototype.indexOf.call(chunk, needle2, fromIndex);
1346
+ };
1347
+ }
1348
+ const skipTable = new Uint8Array(256).fill(state.needle.length);
1349
+ for (let i = 0, lastIndex = state.needle.length - 1; i < lastIndex; ++i) {
1350
+ skipTable[state.needle[i]] = lastIndex - i;
1351
+ }
1352
+ return function(chunk, needle2, fromIndex) {
1353
+ const lengthTotal = chunk.length;
1354
+ let i = fromIndex + state.needleLength - 1;
1355
+ while (i < lengthTotal) {
1356
+ for (let j = state.needleLength - 1, k = i; j >= 0 && chunk[k] === needle2[j]; j--, k--) {
1357
+ if (j === 0) return k;
1358
+ }
1359
+ i += skipTable[chunk[i]];
1360
+ }
1361
+ return -1;
1362
+ };
1363
+ }
1364
+ const indexOf = makeIndexOf();
1365
+ function write3(chunk) {
1366
+ let chunkLength = chunk.length;
1367
+ if (state.previousChunk !== void 0) {
1368
+ const newChunk = new Uint8Array(state.previousChunkLength + chunkLength);
1369
+ newChunk.set(state.previousChunk);
1370
+ newChunk.set(chunk, state.previousChunkLength);
1371
+ chunk = newChunk;
1372
+ chunkLength = state.previousChunkLength + chunkLength;
1373
+ state.previousChunk = void 0;
1374
+ }
1375
+ if (chunkLength < state.needleLength) {
1376
+ state.previousChunk = chunk;
1377
+ state.previousChunkLength = chunkLength;
1378
+ return;
1379
+ }
1380
+ let pos = 0;
1381
+ while (pos < chunkLength) {
1382
+ const match3 = indexOf(chunk, state.needle, pos);
1383
+ if (match3 > -1) {
1384
+ if (match3 > pos) {
1385
+ callback(state.matchIndex, chunk.subarray(pos, match3));
1386
+ }
1387
+ state.matchIndex += 1;
1388
+ pos = match3 + state.needleLength;
1389
+ continue;
1390
+ } else if (chunk[chunkLength - 1] in state.indexes) {
1391
+ const indexes = state.indexes[chunk[chunkLength - 1]];
1392
+ let earliestIndex = -1;
1393
+ for (let i = 0, len = indexes.length; i < len; i++) {
1394
+ const index = indexes[i];
1395
+ if (chunk[chunkLength - 1 - index] === state.firstByte && i > earliestIndex) {
1396
+ earliestIndex = index;
1397
+ }
1398
+ }
1399
+ if (earliestIndex === -1) {
1400
+ if (pos === 0) {
1401
+ callback(state.matchIndex, chunk);
1402
+ } else {
1403
+ callback(state.matchIndex, chunk.subarray(pos));
1404
+ }
1405
+ } else {
1406
+ if (chunkLength - 1 - earliestIndex > pos) {
1407
+ callback(state.matchIndex, chunk.subarray(pos, chunkLength - 1 - earliestIndex));
1408
+ }
1409
+ state.previousChunk = chunk.subarray(chunkLength - 1 - earliestIndex);
1410
+ state.previousChunkLength = earliestIndex + 1;
1411
+ }
1412
+ } else if (pos === 0) {
1413
+ callback(state.matchIndex, chunk);
1414
+ } else {
1415
+ callback(state.matchIndex, chunk.subarray(pos));
1416
+ }
1417
+ break;
1418
+ }
1419
+ }
1420
+ function end() {
1421
+ if (state.previousChunk !== void 0 && state.previousChunk !== seed) {
1422
+ callback(state.matchIndex, state.previousChunk);
1423
+ }
1424
+ state.previousChunk = seed;
1425
+ state.previousChunkLength = seed?.length ?? 0;
1426
+ state.matchIndex = 0;
1427
+ }
1428
+ return {
1429
+ write: write3,
1430
+ end
1431
+ };
1432
+ }
1433
+
1434
+ // ../../node_modules/.bun/multipasta@0.2.7/node_modules/multipasta/dist/esm/internal/multipart.js
1435
+ var State2;
1436
+ (function(State3) {
1437
+ State3[State3["headers"] = 0] = "headers";
1438
+ State3[State3["body"] = 1] = "body";
1439
+ })(State2 || (State2 = {}));
1440
+ var errInvalidDisposition = {
1441
+ _tag: "InvalidDisposition"
1442
+ };
1443
+ var errEndNotReached = {
1444
+ _tag: "EndNotReached"
1445
+ };
1446
+ var errMaxParts = {
1447
+ _tag: "ReachedLimit",
1448
+ limit: "MaxParts"
1449
+ };
1450
+ var errMaxTotalSize = {
1451
+ _tag: "ReachedLimit",
1452
+ limit: "MaxTotalSize"
1453
+ };
1454
+ var errMaxPartSize = {
1455
+ _tag: "ReachedLimit",
1456
+ limit: "MaxPartSize"
1457
+ };
1458
+ var errMaxFieldSize = {
1459
+ _tag: "ReachedLimit",
1460
+ limit: "MaxFieldSize"
1461
+ };
1462
+ var constCR = /* @__PURE__ */ new TextEncoder().encode("\r\n");
1463
+ function defaultIsFile(info) {
1464
+ return info.filename !== void 0 || info.contentType === "application/octet-stream";
1465
+ }
1466
+ function parseBoundary(headers) {
1467
+ const contentType = parse(headers["content-type"]);
1468
+ return contentType.parameters.boundary;
1469
+ }
1470
+ function noopOnChunk(_chunk) {
1471
+ }
1472
+ function make6({
1473
+ headers,
1474
+ onFile: onPart,
1475
+ onField,
1476
+ onError,
1477
+ onDone,
1478
+ isFile = defaultIsFile,
1479
+ maxParts = Infinity,
1480
+ maxTotalSize = Infinity,
1481
+ maxPartSize = Infinity,
1482
+ maxFieldSize = 1024 * 1024
1483
+ }) {
1484
+ const boundary = parseBoundary(headers);
1485
+ if (boundary === void 0) {
1486
+ onError({
1487
+ _tag: "InvalidBoundary"
1488
+ });
1489
+ return {
1490
+ write: noopOnChunk,
1491
+ end() {
1492
+ }
1493
+ };
1494
+ }
1495
+ const state = {
1496
+ state: State2.headers,
1497
+ index: 0,
1498
+ parts: 0,
1499
+ onChunk: noopOnChunk,
1500
+ info: void 0,
1501
+ headerSkip: 0,
1502
+ partSize: 0,
1503
+ totalSize: 0,
1504
+ isFile: false,
1505
+ fieldChunks: [],
1506
+ fieldSize: 0
1507
+ };
1508
+ function skipBody() {
1509
+ state.state = State2.body;
1510
+ state.isFile = true;
1511
+ state.onChunk = noopOnChunk;
1512
+ }
1513
+ const headerParser = make4();
1514
+ const split = make5(`\r
1515
+ --${boundary}`, function(index, chunk) {
1516
+ if (index === 0) {
1517
+ skipBody();
1518
+ return;
1519
+ } else if (index !== state.index) {
1520
+ if (state.index > 0) {
1521
+ if (state.isFile) {
1522
+ state.onChunk(null);
1523
+ state.partSize = 0;
1524
+ } else {
1525
+ if (state.fieldChunks.length === 1) {
1526
+ onField(state.info, state.fieldChunks[0]);
1527
+ } else {
1528
+ const buf = new Uint8Array(state.fieldSize);
1529
+ let offset = 0;
1530
+ for (let i = 0; i < state.fieldChunks.length; i++) {
1531
+ const chunk2 = state.fieldChunks[i];
1532
+ buf.set(chunk2, offset);
1533
+ offset += chunk2.length;
1534
+ }
1535
+ onField(state.info, buf);
1536
+ }
1537
+ state.fieldSize = 0;
1538
+ state.fieldChunks = [];
1539
+ }
1540
+ }
1541
+ state.state = State2.headers;
1542
+ state.index = index;
1543
+ state.headerSkip = 2;
1544
+ if (chunk[0] === 45 && chunk[1] === 45) {
1545
+ return onDone();
1546
+ }
1547
+ state.parts++;
1548
+ if (state.parts > maxParts) {
1549
+ onError(errMaxParts);
1550
+ }
1551
+ }
1552
+ if ((state.partSize += chunk.length) > maxPartSize) {
1553
+ onError(errMaxPartSize);
1554
+ }
1555
+ if (state.state === State2.headers) {
1556
+ const result = headerParser(chunk, state.headerSkip);
1557
+ state.headerSkip = 0;
1558
+ if (result._tag === "Continue") {
1559
+ return;
1560
+ } else if (result._tag === "Failure") {
1561
+ skipBody();
1562
+ return onError({
1563
+ _tag: "BadHeaders",
1564
+ error: result
1565
+ });
1566
+ }
1567
+ const contentType = parse(result.headers["content-type"]);
1568
+ const contentDisposition = parse(result.headers["content-disposition"], true);
1569
+ if ("form-data" === contentDisposition.value && !("name" in contentDisposition.parameters)) {
1570
+ skipBody();
1571
+ return onError(errInvalidDisposition);
1572
+ }
1573
+ let encodedFilename;
1574
+ if ("filename*" in contentDisposition.parameters) {
1575
+ const parts = contentDisposition.parameters["filename*"].split("''");
1576
+ if (parts.length === 2) {
1577
+ encodedFilename = decodeURIComponent(parts[1]);
1578
+ }
1579
+ }
1580
+ state.info = {
1581
+ name: contentDisposition.parameters.name ?? "",
1582
+ filename: encodedFilename ?? contentDisposition.parameters.filename,
1583
+ contentType: contentType.value === "" ? contentDisposition.parameters.filename !== void 0 ? "application/octet-stream" : "text/plain" : contentType.value,
1584
+ contentTypeParameters: contentType.parameters,
1585
+ contentDisposition: contentDisposition.value,
1586
+ contentDispositionParameters: contentDisposition.parameters,
1587
+ headers: result.headers
1588
+ };
1589
+ state.state = State2.body;
1590
+ state.isFile = isFile(state.info);
1591
+ if (state.isFile) {
1592
+ state.onChunk = onPart(state.info);
1593
+ }
1594
+ if (result.endPosition < chunk.length) {
1595
+ if (state.isFile) {
1596
+ state.onChunk(chunk.subarray(result.endPosition));
1597
+ } else {
1598
+ const buf = chunk.subarray(result.endPosition);
1599
+ if ((state.fieldSize += buf.length) > maxFieldSize) {
1600
+ onError(errMaxFieldSize);
1601
+ }
1602
+ state.fieldChunks.push(buf);
1603
+ }
1604
+ }
1605
+ } else if (state.isFile) {
1606
+ state.onChunk(chunk);
1607
+ } else {
1608
+ if ((state.fieldSize += chunk.length) > maxFieldSize) {
1609
+ onError(errMaxFieldSize);
1610
+ }
1611
+ state.fieldChunks.push(chunk);
1612
+ }
1613
+ }, constCR);
1614
+ return {
1615
+ write(chunk) {
1616
+ if ((state.totalSize += chunk.length) > maxTotalSize) {
1617
+ return onError(errMaxTotalSize);
1618
+ }
1619
+ return split.write(chunk);
1620
+ },
1621
+ end() {
1622
+ split.end();
1623
+ if (state.state === State2.body) {
1624
+ onError(errEndNotReached);
1625
+ }
1626
+ state.state = State2.headers;
1627
+ state.index = 0;
1628
+ state.parts = 0;
1629
+ state.onChunk = noopOnChunk;
1630
+ state.info = void 0;
1631
+ state.totalSize = 0;
1632
+ state.partSize = 0;
1633
+ state.fieldChunks = [];
1634
+ state.fieldSize = 0;
1635
+ }
1636
+ };
1637
+ }
1638
+ var utf8Decoder = /* @__PURE__ */ new TextDecoder("utf-8");
1639
+ function getDecoder(charset) {
1640
+ if (charset === "utf-8" || charset === "utf8" || charset === "") {
1641
+ return utf8Decoder;
1642
+ }
1643
+ try {
1644
+ return new TextDecoder(charset);
1645
+ } catch (error) {
1646
+ return utf8Decoder;
1647
+ }
1648
+ }
1649
+ function decodeField(info, value) {
1650
+ return getDecoder(info.contentTypeParameters.charset ?? "utf-8").decode(value);
1651
+ }
1652
+
1653
+ // ../../node_modules/.bun/multipasta@0.2.7/node_modules/multipasta/dist/esm/index.js
1654
+ var make7 = make6;
1655
+ var defaultIsFile2 = defaultIsFile;
1656
+ var decodeField2 = decodeField;
1657
+
1658
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/internal/path.js
1659
+ var import_Context2 = require("effect/Context");
1660
+ var Effect7 = __toESM(require("effect/Effect"), 1);
1661
+ var import_Function8 = require("effect/Function");
1662
+ var Layer2 = __toESM(require("effect/Layer"), 1);
1663
+ var TypeId8 = /* @__PURE__ */ Symbol.for("@effect/platform/Path");
1664
+ var Path = /* @__PURE__ */ (0, import_Context2.GenericTag)("@effect/platform/Path");
1665
+ function normalizeStringPosix(path, allowAboveRoot) {
1666
+ let res = "";
1667
+ let lastSegmentLength = 0;
1668
+ let lastSlash = -1;
1669
+ let dots = 0;
1670
+ let code;
1671
+ for (let i = 0; i <= path.length; ++i) {
1672
+ if (i < path.length) {
1673
+ code = path.charCodeAt(i);
1674
+ } else if (code === 47) {
1675
+ break;
1676
+ } else {
1677
+ code = 47;
1678
+ }
1679
+ if (code === 47) {
1680
+ if (lastSlash === i - 1 || dots === 1) {
1681
+ } else if (lastSlash !== i - 1 && dots === 2) {
1682
+ if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
1683
+ if (res.length > 2) {
1684
+ const lastSlashIndex = res.lastIndexOf("/");
1685
+ if (lastSlashIndex !== res.length - 1) {
1686
+ if (lastSlashIndex === -1) {
1687
+ res = "";
1688
+ lastSegmentLength = 0;
1689
+ } else {
1690
+ res = res.slice(0, lastSlashIndex);
1691
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
1692
+ }
1693
+ lastSlash = i;
1694
+ dots = 0;
1695
+ continue;
1696
+ }
1697
+ } else if (res.length === 2 || res.length === 1) {
1698
+ res = "";
1699
+ lastSegmentLength = 0;
1700
+ lastSlash = i;
1701
+ dots = 0;
1702
+ continue;
1703
+ }
1704
+ }
1705
+ if (allowAboveRoot) {
1706
+ if (res.length > 0) {
1707
+ res += "/..";
1708
+ } else {
1709
+ res = "..";
1710
+ }
1711
+ lastSegmentLength = 2;
1712
+ }
1713
+ } else {
1714
+ if (res.length > 0) {
1715
+ res += "/" + path.slice(lastSlash + 1, i);
1716
+ } else {
1717
+ res = path.slice(lastSlash + 1, i);
1718
+ }
1719
+ lastSegmentLength = i - lastSlash - 1;
1720
+ }
1721
+ lastSlash = i;
1722
+ dots = 0;
1723
+ } else if (code === 46 && dots !== -1) {
1724
+ ++dots;
1725
+ } else {
1726
+ dots = -1;
1727
+ }
1728
+ }
1729
+ return res;
1730
+ }
1731
+ function _format(sep, pathObject) {
1732
+ const dir = pathObject.dir || pathObject.root;
1733
+ const base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
1734
+ if (!dir) {
1735
+ return base;
1736
+ }
1737
+ if (dir === pathObject.root) {
1738
+ return dir + base;
1739
+ }
1740
+ return dir + sep + base;
1741
+ }
1742
+ function fromFileUrl(url) {
1743
+ if (url.protocol !== "file:") {
1744
+ return Effect7.fail(new BadArgument({
1745
+ module: "Path",
1746
+ method: "fromFileUrl",
1747
+ description: "URL must be of scheme file"
1748
+ }));
1749
+ } else if (url.hostname !== "") {
1750
+ return Effect7.fail(new BadArgument({
1751
+ module: "Path",
1752
+ method: "fromFileUrl",
1753
+ description: "Invalid file URL host"
1754
+ }));
1755
+ }
1756
+ const pathname = url.pathname;
1757
+ for (let n = 0; n < pathname.length; n++) {
1758
+ if (pathname[n] === "%") {
1759
+ const third = pathname.codePointAt(n + 2) | 32;
1760
+ if (pathname[n + 1] === "2" && third === 102) {
1761
+ return Effect7.fail(new BadArgument({
1762
+ module: "Path",
1763
+ method: "fromFileUrl",
1764
+ description: "must not include encoded / characters"
1765
+ }));
1766
+ }
1767
+ }
1768
+ }
1769
+ return Effect7.succeed(decodeURIComponent(pathname));
1770
+ }
1771
+ var resolve = function resolve2() {
1772
+ let resolvedPath = "";
1773
+ let resolvedAbsolute = false;
1774
+ let cwd = void 0;
1775
+ for (let i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
1776
+ let path;
1777
+ if (i >= 0) {
1778
+ path = arguments[i];
1779
+ } else {
1780
+ const process = globalThis.process;
1781
+ if (cwd === void 0 && "process" in globalThis && typeof process === "object" && process !== null && typeof process.cwd === "function") {
1782
+ cwd = process.cwd();
1783
+ }
1784
+ path = cwd;
1785
+ }
1786
+ if (path.length === 0) {
1787
+ continue;
1788
+ }
1789
+ resolvedPath = path + "/" + resolvedPath;
1790
+ resolvedAbsolute = path.charCodeAt(0) === 47;
1791
+ }
1792
+ resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
1793
+ if (resolvedAbsolute) {
1794
+ if (resolvedPath.length > 0) {
1795
+ return "/" + resolvedPath;
1796
+ } else {
1797
+ return "/";
1798
+ }
1799
+ } else if (resolvedPath.length > 0) {
1800
+ return resolvedPath;
1801
+ } else {
1802
+ return ".";
1803
+ }
1804
+ };
1805
+ var CHAR_FORWARD_SLASH = 47;
1806
+ function toFileUrl(filepath) {
1807
+ const outURL = new URL("file://");
1808
+ let resolved = resolve(filepath);
1809
+ const filePathLast = filepath.charCodeAt(filepath.length - 1);
1810
+ if (filePathLast === CHAR_FORWARD_SLASH && resolved[resolved.length - 1] !== "/") {
1811
+ resolved += "/";
1812
+ }
1813
+ outURL.pathname = encodePathChars(resolved);
1814
+ return Effect7.succeed(outURL);
1815
+ }
1816
+ var percentRegEx = /%/g;
1817
+ var backslashRegEx = /\\/g;
1818
+ var newlineRegEx = /\n/g;
1819
+ var carriageReturnRegEx = /\r/g;
1820
+ var tabRegEx = /\t/g;
1821
+ function encodePathChars(filepath) {
1822
+ if (filepath.includes("%")) {
1823
+ filepath = filepath.replace(percentRegEx, "%25");
1824
+ }
1825
+ if (filepath.includes("\\")) {
1826
+ filepath = filepath.replace(backslashRegEx, "%5C");
1827
+ }
1828
+ if (filepath.includes("\n")) {
1829
+ filepath = filepath.replace(newlineRegEx, "%0A");
1830
+ }
1831
+ if (filepath.includes("\r")) {
1832
+ filepath = filepath.replace(carriageReturnRegEx, "%0D");
1833
+ }
1834
+ if (filepath.includes(" ")) {
1835
+ filepath = filepath.replace(tabRegEx, "%09");
1836
+ }
1837
+ return filepath;
1838
+ }
1839
+ var posixImpl = /* @__PURE__ */ Path.of({
1840
+ [TypeId8]: TypeId8,
1841
+ resolve,
1842
+ normalize(path) {
1843
+ if (path.length === 0) return ".";
1844
+ const isAbsolute = path.charCodeAt(0) === 47;
1845
+ const trailingSeparator = path.charCodeAt(path.length - 1) === 47;
1846
+ path = normalizeStringPosix(path, !isAbsolute);
1847
+ if (path.length === 0 && !isAbsolute) path = ".";
1848
+ if (path.length > 0 && trailingSeparator) path += "/";
1849
+ if (isAbsolute) return "/" + path;
1850
+ return path;
1851
+ },
1852
+ isAbsolute(path) {
1853
+ return path.length > 0 && path.charCodeAt(0) === 47;
1854
+ },
1855
+ join() {
1856
+ if (arguments.length === 0) {
1857
+ return ".";
1858
+ }
1859
+ let joined;
1860
+ for (let i = 0; i < arguments.length; ++i) {
1861
+ const arg = arguments[i];
1862
+ if (arg.length > 0) {
1863
+ if (joined === void 0) {
1864
+ joined = arg;
1865
+ } else {
1866
+ joined += "/" + arg;
1867
+ }
1868
+ }
1869
+ }
1870
+ if (joined === void 0) {
1871
+ return ".";
1872
+ }
1873
+ return posixImpl.normalize(joined);
1874
+ },
1875
+ relative(from, to) {
1876
+ if (from === to) return "";
1877
+ from = posixImpl.resolve(from);
1878
+ to = posixImpl.resolve(to);
1879
+ if (from === to) return "";
1880
+ let fromStart = 1;
1881
+ for (; fromStart < from.length; ++fromStart) {
1882
+ if (from.charCodeAt(fromStart) !== 47) {
1883
+ break;
1884
+ }
1885
+ }
1886
+ const fromEnd = from.length;
1887
+ const fromLen = fromEnd - fromStart;
1888
+ let toStart = 1;
1889
+ for (; toStart < to.length; ++toStart) {
1890
+ if (to.charCodeAt(toStart) !== 47) {
1891
+ break;
1892
+ }
1893
+ }
1894
+ const toEnd = to.length;
1895
+ const toLen = toEnd - toStart;
1896
+ const length = fromLen < toLen ? fromLen : toLen;
1897
+ let lastCommonSep = -1;
1898
+ let i = 0;
1899
+ for (; i <= length; ++i) {
1900
+ if (i === length) {
1901
+ if (toLen > length) {
1902
+ if (to.charCodeAt(toStart + i) === 47) {
1903
+ return to.slice(toStart + i + 1);
1904
+ } else if (i === 0) {
1905
+ return to.slice(toStart + i);
1906
+ }
1907
+ } else if (fromLen > length) {
1908
+ if (from.charCodeAt(fromStart + i) === 47) {
1909
+ lastCommonSep = i;
1910
+ } else if (i === 0) {
1911
+ lastCommonSep = 0;
1912
+ }
1913
+ }
1914
+ break;
1915
+ }
1916
+ const fromCode = from.charCodeAt(fromStart + i);
1917
+ const toCode = to.charCodeAt(toStart + i);
1918
+ if (fromCode !== toCode) {
1919
+ break;
1920
+ } else if (fromCode === 47) {
1921
+ lastCommonSep = i;
1922
+ }
1923
+ }
1924
+ let out = "";
1925
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
1926
+ if (i === fromEnd || from.charCodeAt(i) === 47) {
1927
+ if (out.length === 0) {
1928
+ out += "..";
1929
+ } else {
1930
+ out += "/..";
1931
+ }
1932
+ }
1933
+ }
1934
+ if (out.length > 0) {
1935
+ return out + to.slice(toStart + lastCommonSep);
1936
+ } else {
1937
+ toStart += lastCommonSep;
1938
+ if (to.charCodeAt(toStart) === 47) {
1939
+ ++toStart;
1940
+ }
1941
+ return to.slice(toStart);
1942
+ }
1943
+ },
1944
+ dirname(path) {
1945
+ if (path.length === 0) return ".";
1946
+ let code = path.charCodeAt(0);
1947
+ const hasRoot = code === 47;
1948
+ let end = -1;
1949
+ let matchedSlash = true;
1950
+ for (let i = path.length - 1; i >= 1; --i) {
1951
+ code = path.charCodeAt(i);
1952
+ if (code === 47) {
1953
+ if (!matchedSlash) {
1954
+ end = i;
1955
+ break;
1956
+ }
1957
+ } else {
1958
+ matchedSlash = false;
1959
+ }
1960
+ }
1961
+ if (end === -1) return hasRoot ? "/" : ".";
1962
+ if (hasRoot && end === 1) return "//";
1963
+ return path.slice(0, end);
1964
+ },
1965
+ basename(path, ext) {
1966
+ let start = 0;
1967
+ let end = -1;
1968
+ let matchedSlash = true;
1969
+ let i;
1970
+ if (ext !== void 0 && ext.length > 0 && ext.length <= path.length) {
1971
+ if (ext.length === path.length && ext === path) return "";
1972
+ let extIdx = ext.length - 1;
1973
+ let firstNonSlashEnd = -1;
1974
+ for (i = path.length - 1; i >= 0; --i) {
1975
+ const code = path.charCodeAt(i);
1976
+ if (code === 47) {
1977
+ if (!matchedSlash) {
1978
+ start = i + 1;
1979
+ break;
1980
+ }
1981
+ } else {
1982
+ if (firstNonSlashEnd === -1) {
1983
+ matchedSlash = false;
1984
+ firstNonSlashEnd = i + 1;
1985
+ }
1986
+ if (extIdx >= 0) {
1987
+ if (code === ext.charCodeAt(extIdx)) {
1988
+ if (--extIdx === -1) {
1989
+ end = i;
1990
+ }
1991
+ } else {
1992
+ extIdx = -1;
1993
+ end = firstNonSlashEnd;
1994
+ }
1995
+ }
1996
+ }
1997
+ }
1998
+ if (start === end) end = firstNonSlashEnd;
1999
+ else if (end === -1) end = path.length;
2000
+ return path.slice(start, end);
2001
+ } else {
2002
+ for (i = path.length - 1; i >= 0; --i) {
2003
+ if (path.charCodeAt(i) === 47) {
2004
+ if (!matchedSlash) {
2005
+ start = i + 1;
2006
+ break;
2007
+ }
2008
+ } else if (end === -1) {
2009
+ matchedSlash = false;
2010
+ end = i + 1;
2011
+ }
2012
+ }
2013
+ if (end === -1) return "";
2014
+ return path.slice(start, end);
2015
+ }
2016
+ },
2017
+ extname(path) {
2018
+ let startDot = -1;
2019
+ let startPart = 0;
2020
+ let end = -1;
2021
+ let matchedSlash = true;
2022
+ let preDotState = 0;
2023
+ for (let i = path.length - 1; i >= 0; --i) {
2024
+ const code = path.charCodeAt(i);
2025
+ if (code === 47) {
2026
+ if (!matchedSlash) {
2027
+ startPart = i + 1;
2028
+ break;
2029
+ }
2030
+ continue;
2031
+ }
2032
+ if (end === -1) {
2033
+ matchedSlash = false;
2034
+ end = i + 1;
2035
+ }
2036
+ if (code === 46) {
2037
+ if (startDot === -1) {
2038
+ startDot = i;
2039
+ } else if (preDotState !== 1) {
2040
+ preDotState = 1;
2041
+ }
2042
+ } else if (startDot !== -1) {
2043
+ preDotState = -1;
2044
+ }
2045
+ }
2046
+ if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
2047
+ preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
2048
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
2049
+ return "";
2050
+ }
2051
+ return path.slice(startDot, end);
2052
+ },
2053
+ format: function format3(pathObject) {
2054
+ if (pathObject === null || typeof pathObject !== "object") {
2055
+ throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
2056
+ }
2057
+ return _format("/", pathObject);
2058
+ },
2059
+ parse(path) {
2060
+ const ret = {
2061
+ root: "",
2062
+ dir: "",
2063
+ base: "",
2064
+ ext: "",
2065
+ name: ""
2066
+ };
2067
+ if (path.length === 0) return ret;
2068
+ let code = path.charCodeAt(0);
2069
+ const isAbsolute = code === 47;
2070
+ let start;
2071
+ if (isAbsolute) {
2072
+ ret.root = "/";
2073
+ start = 1;
2074
+ } else {
2075
+ start = 0;
2076
+ }
2077
+ let startDot = -1;
2078
+ let startPart = 0;
2079
+ let end = -1;
2080
+ let matchedSlash = true;
2081
+ let i = path.length - 1;
2082
+ let preDotState = 0;
2083
+ for (; i >= start; --i) {
2084
+ code = path.charCodeAt(i);
2085
+ if (code === 47) {
2086
+ if (!matchedSlash) {
2087
+ startPart = i + 1;
2088
+ break;
2089
+ }
2090
+ continue;
2091
+ }
2092
+ if (end === -1) {
2093
+ matchedSlash = false;
2094
+ end = i + 1;
2095
+ }
2096
+ if (code === 46) {
2097
+ if (startDot === -1) startDot = i;
2098
+ else if (preDotState !== 1) preDotState = 1;
2099
+ } else if (startDot !== -1) {
2100
+ preDotState = -1;
2101
+ }
2102
+ }
2103
+ if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
2104
+ preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
2105
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
2106
+ if (end !== -1) {
2107
+ if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);
2108
+ else ret.base = ret.name = path.slice(startPart, end);
2109
+ }
2110
+ } else {
2111
+ if (startPart === 0 && isAbsolute) {
2112
+ ret.name = path.slice(1, startDot);
2113
+ ret.base = path.slice(1, end);
2114
+ } else {
2115
+ ret.name = path.slice(startPart, startDot);
2116
+ ret.base = path.slice(startPart, end);
2117
+ }
2118
+ ret.ext = path.slice(startDot, end);
2119
+ }
2120
+ if (startPart > 0) ret.dir = path.slice(0, startPart - 1);
2121
+ else if (isAbsolute) ret.dir = "/";
2122
+ return ret;
2123
+ },
2124
+ sep: "/",
2125
+ fromFileUrl,
2126
+ toFileUrl,
2127
+ toNamespacedPath: import_Function8.identity
2128
+ });
2129
+
2130
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/Path.js
2131
+ var Path2 = Path;
2132
+
2133
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/Multipart.js
2134
+ var TypeId9 = /* @__PURE__ */ Symbol.for("@effect/platform/Multipart");
2135
+ var ErrorTypeId2 = /* @__PURE__ */ Symbol.for("@effect/platform/Multipart/MultipartError");
2136
+ var MultipartError = class extends (/* @__PURE__ */ Schema6.TaggedError()("MultipartError", {
2137
+ reason: /* @__PURE__ */ Schema6.Literal("FileTooLarge", "FieldTooLarge", "BodyTooLarge", "TooManyParts", "InternalError", "Parse"),
2138
+ cause: Schema6.Defect
2139
+ })) {
2140
+ /**
2141
+ * @since 1.0.0
2142
+ */
2143
+ [ErrorTypeId2] = ErrorTypeId2;
2144
+ /**
2145
+ * @since 1.0.0
2146
+ */
2147
+ get message() {
2148
+ return this.reason;
2149
+ }
2150
+ };
2151
+ var makeConfig = (headers) => Effect8.withFiberRuntime((fiber) => {
2152
+ const mimeTypes = Context4.get(fiber.currentContext, FieldMimeTypes);
2153
+ return Effect8.succeed({
2154
+ headers,
2155
+ maxParts: Option7.getOrUndefined(Context4.get(fiber.currentContext, MaxParts)),
2156
+ maxFieldSize: Number(Context4.get(fiber.currentContext, MaxFieldSize)),
2157
+ maxPartSize: Context4.get(fiber.currentContext, MaxFileSize).pipe(Option7.map(Number), Option7.getOrUndefined),
2158
+ maxTotalSize: Context4.get(fiber.currentContext, MaxBodySize).pipe(Option7.map(Number), Option7.getOrUndefined),
2159
+ isFile: mimeTypes.length === 0 ? void 0 : (info) => !Chunk2.some(mimeTypes, (_) => info.contentType.includes(_)) && defaultIsFile2(info)
2160
+ });
2161
+ });
2162
+ var makeChannel = (headers, bufferSize = 16) => Channel2.acquireUseRelease(Effect8.all([makeConfig(headers), Mailbox.make(bufferSize)]), ([config, mailbox]) => {
2163
+ let partsBuffer = [];
2164
+ let exit2 = Option7.none();
2165
+ const input = {
2166
+ awaitRead: () => Effect8.void,
2167
+ emit(element) {
2168
+ return mailbox.offer(element);
2169
+ },
2170
+ error(cause) {
2171
+ exit2 = Option7.some(Exit.failCause(cause));
2172
+ return mailbox.end;
2173
+ },
2174
+ done(_value) {
2175
+ return mailbox.end;
2176
+ }
2177
+ };
2178
+ const parser = make7({
2179
+ ...config,
2180
+ onField(info, value) {
2181
+ partsBuffer.push(new FieldImpl(info.name, info.contentType, decodeField2(info, value)));
2182
+ },
2183
+ onFile(info) {
2184
+ let chunks = [];
2185
+ let finished = false;
2186
+ const take = Channel2.suspend(() => {
2187
+ if (chunks.length === 0) {
2188
+ return finished ? Channel2.void : Channel2.zipRight(pump, take);
2189
+ }
2190
+ const chunk = Chunk2.unsafeFromArray(chunks);
2191
+ chunks = [];
2192
+ return finished ? Channel2.write(chunk) : Channel2.zipRight(Channel2.write(chunk), Channel2.zipRight(pump, take));
2193
+ });
2194
+ partsBuffer.push(new FileImpl(info, take));
2195
+ return function(chunk) {
2196
+ if (chunk === null) {
2197
+ finished = true;
2198
+ } else {
2199
+ chunks.push(chunk);
2200
+ }
2201
+ };
2202
+ },
2203
+ onError(error_) {
2204
+ exit2 = Option7.some(Exit.fail(convertError(error_)));
2205
+ },
2206
+ onDone() {
2207
+ exit2 = Option7.some(Exit.void);
2208
+ }
2209
+ });
2210
+ const pump = Channel2.flatMap(mailbox.takeAll, ([chunks, done]) => Channel2.sync(() => {
2211
+ Chunk2.forEach(chunks, Chunk2.forEach(parser.write));
2212
+ if (done) {
2213
+ parser.end();
2214
+ }
2215
+ }));
2216
+ const partsChannel = Channel2.flatMap(pump, () => {
2217
+ if (partsBuffer.length === 0) {
2218
+ return exit2._tag === "None" ? partsChannel : writeExit(exit2.value);
2219
+ }
2220
+ const chunk = Chunk2.unsafeFromArray(partsBuffer);
2221
+ partsBuffer = [];
2222
+ return Channel2.zipRight(Channel2.write(chunk), exit2._tag === "None" ? partsChannel : writeExit(exit2.value));
2223
+ });
2224
+ return Channel2.embedInput(partsChannel, input);
2225
+ }, ([, mailbox]) => mailbox.shutdown);
2226
+ var writeExit = (self) => self._tag === "Success" ? Channel2.void : Channel2.failCause(self.cause);
2227
+ function convertError(cause) {
2228
+ switch (cause._tag) {
2229
+ case "ReachedLimit": {
2230
+ switch (cause.limit) {
2231
+ case "MaxParts": {
2232
+ return new MultipartError({
2233
+ reason: "TooManyParts",
2234
+ cause
2235
+ });
2236
+ }
2237
+ case "MaxFieldSize": {
2238
+ return new MultipartError({
2239
+ reason: "FieldTooLarge",
2240
+ cause
2241
+ });
2242
+ }
2243
+ case "MaxPartSize": {
2244
+ return new MultipartError({
2245
+ reason: "FileTooLarge",
2246
+ cause
2247
+ });
2248
+ }
2249
+ case "MaxTotalSize": {
2250
+ return new MultipartError({
2251
+ reason: "BodyTooLarge",
2252
+ cause
2253
+ });
2254
+ }
2255
+ }
2256
+ }
2257
+ default: {
2258
+ return new MultipartError({
2259
+ reason: "Parse",
2260
+ cause
2261
+ });
2262
+ }
2263
+ }
2264
+ }
2265
+ var PartBase = class extends Inspectable5.Class {
2266
+ [TypeId9];
2267
+ constructor() {
2268
+ super();
2269
+ this[TypeId9] = TypeId9;
2270
+ }
2271
+ };
2272
+ var FieldImpl = class extends PartBase {
2273
+ key;
2274
+ contentType;
2275
+ value;
2276
+ _tag = "Field";
2277
+ constructor(key, contentType, value) {
2278
+ super();
2279
+ this.key = key;
2280
+ this.contentType = contentType;
2281
+ this.value = value;
2282
+ }
2283
+ toJSON() {
2284
+ return {
2285
+ _id: "@effect/platform/Multipart/Part",
2286
+ _tag: "Field",
2287
+ key: this.key,
2288
+ contentType: this.contentType,
2289
+ value: this.value
2290
+ };
2291
+ }
2292
+ };
2293
+ var FileImpl = class extends PartBase {
2294
+ _tag = "File";
2295
+ key;
2296
+ name;
2297
+ contentType;
2298
+ content;
2299
+ contentEffect;
2300
+ constructor(info, channel) {
2301
+ super();
2302
+ this.key = info.name;
2303
+ this.name = info.filename ?? info.name;
2304
+ this.contentType = info.contentType;
2305
+ this.content = Stream4.fromChannel(channel);
2306
+ this.contentEffect = channel.pipe(Channel2.pipeTo(collectUint8Array), Channel2.run, Effect8.mapError((cause) => new MultipartError({
2307
+ reason: "InternalError",
2308
+ cause
2309
+ })));
2310
+ }
2311
+ toJSON() {
2312
+ return {
2313
+ _id: "@effect/platform/Multipart/Part",
2314
+ _tag: "File",
2315
+ key: this.key,
2316
+ name: this.name,
2317
+ contentType: this.contentType
2318
+ };
2319
+ }
2320
+ };
2321
+ var defaultWriteFile = (path, file3) => Effect8.flatMap(FileSystem, (fs) => Effect8.mapError(Stream4.run(file3.content, fs.sink(path)), (cause) => new MultipartError({
2322
+ reason: "InternalError",
2323
+ cause
2324
+ })));
2325
+ var collectUint8Array = /* @__PURE__ */ Channel2.suspend(() => {
2326
+ let accumulator = new Uint8Array(0);
2327
+ const loop = Channel2.readWithCause({
2328
+ onInput(chunk) {
2329
+ for (const element of chunk) {
2330
+ const newAccumulator = new Uint8Array(accumulator.length + element.length);
2331
+ newAccumulator.set(accumulator, 0);
2332
+ newAccumulator.set(element, accumulator.length);
2333
+ accumulator = newAccumulator;
2334
+ }
2335
+ return loop;
2336
+ },
2337
+ onFailure: (cause) => Channel2.failCause(cause),
2338
+ onDone: () => Channel2.succeed(accumulator)
2339
+ });
2340
+ return loop;
2341
+ });
2342
+ var toPersisted = (stream4, writeFile = defaultWriteFile) => Effect8.gen(function* () {
2343
+ const fs = yield* FileSystem;
2344
+ const path_ = yield* Path2;
2345
+ const dir = yield* fs.makeTempDirectoryScoped();
2346
+ const persisted = /* @__PURE__ */ Object.create(null);
2347
+ yield* Stream4.runForEach(stream4, (part) => {
2348
+ if (part._tag === "Field") {
2349
+ if (!(part.key in persisted)) {
2350
+ persisted[part.key] = part.value;
2351
+ } else if (typeof persisted[part.key] === "string") {
2352
+ persisted[part.key] = [persisted[part.key], part.value];
2353
+ } else {
2354
+ ;
2355
+ persisted[part.key].push(part.value);
2356
+ }
2357
+ return Effect8.void;
2358
+ } else if (part.name === "") {
2359
+ return Effect8.void;
2360
+ }
2361
+ const file3 = part;
2362
+ const path = path_.join(dir, path_.basename(file3.name).slice(-128));
2363
+ const filePart = new PersistedFileImpl(file3.key, file3.name, file3.contentType, path);
2364
+ if (Array.isArray(persisted[part.key])) {
2365
+ ;
2366
+ persisted[part.key].push(filePart);
2367
+ } else {
2368
+ persisted[part.key] = [filePart];
2369
+ }
2370
+ return writeFile(path, file3);
2371
+ });
2372
+ return persisted;
2373
+ }).pipe(Effect8.catchTags({
2374
+ SystemError: (cause) => Effect8.fail(new MultipartError({
2375
+ reason: "InternalError",
2376
+ cause
2377
+ })),
2378
+ BadArgument: (cause) => Effect8.fail(new MultipartError({
2379
+ reason: "InternalError",
2380
+ cause
2381
+ }))
2382
+ }));
2383
+ var PersistedFileImpl = class extends PartBase {
2384
+ key;
2385
+ name;
2386
+ contentType;
2387
+ path;
2388
+ _tag = "PersistedFile";
2389
+ constructor(key, name, contentType, path) {
2390
+ super();
2391
+ this.key = key;
2392
+ this.name = name;
2393
+ this.contentType = contentType;
2394
+ this.path = path;
2395
+ }
2396
+ toJSON() {
2397
+ return {
2398
+ _id: "@effect/platform/Multipart/Part",
2399
+ _tag: "PersistedFile",
2400
+ key: this.key,
2401
+ name: this.name,
2402
+ contentType: this.contentType,
2403
+ path: this.path
2404
+ };
2405
+ }
2406
+ };
2407
+ var MaxParts = class extends (/* @__PURE__ */ Context4.Reference()("@effect/platform/Multipart/MaxParts", {
2408
+ defaultValue: Option7.none
2409
+ })) {
2410
+ };
2411
+ var MaxFieldSize = class extends (/* @__PURE__ */ Context4.Reference()("@effect/platform/Multipart/MaxFieldSize", {
2412
+ defaultValue: /* @__PURE__ */ (0, import_Function9.constant)(/* @__PURE__ */ Size2(10 * 1024 * 1024))
2413
+ })) {
2414
+ };
2415
+ var MaxFileSize = class extends (/* @__PURE__ */ Context4.Reference()("@effect/platform/Multipart/MaxFileSize", {
2416
+ defaultValue: Option7.none
2417
+ })) {
2418
+ };
2419
+ var FieldMimeTypes = class extends (/* @__PURE__ */ Context4.Reference()("@effect/platform/Multipart/FieldMimeTypes", {
2420
+ defaultValue: /* @__PURE__ */ (0, import_Function9.constant)(/* @__PURE__ */ Chunk2.make("application/json"))
2421
+ })) {
2422
+ };
2423
+
2424
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/internal/httpServerRequest.js
2425
+ var TypeId10 = /* @__PURE__ */ Symbol.for("@effect/platform/HttpServerRequest");
2426
+ var serverRequestTag = /* @__PURE__ */ Context5.GenericTag("@effect/platform/HttpServerRequest");
2427
+ var fromWeb2 = (request) => new ServerRequestImpl(request, removeHost(request.url));
2428
+ var removeHost = (url) => {
2429
+ if (url[0] === "/") {
2430
+ return url;
2431
+ }
2432
+ const index = url.indexOf("/", url.indexOf("//") + 2);
2433
+ return index === -1 ? "/" : url.slice(index);
2434
+ };
2435
+ var ServerRequestImpl = class _ServerRequestImpl extends Inspectable6.Class {
2436
+ source;
2437
+ url;
2438
+ headersOverride;
2439
+ remoteAddressOverride;
2440
+ [TypeId10];
2441
+ [TypeId3];
2442
+ constructor(source, url, headersOverride, remoteAddressOverride) {
2443
+ super();
2444
+ this.source = source;
2445
+ this.url = url;
2446
+ this.headersOverride = headersOverride;
2447
+ this.remoteAddressOverride = remoteAddressOverride;
2448
+ this[TypeId10] = TypeId10;
2449
+ this[TypeId3] = TypeId3;
2450
+ }
2451
+ toJSON() {
2452
+ return inspect(this, {
2453
+ _id: "@effect/platform/HttpServerRequest",
2454
+ method: this.method,
2455
+ url: this.originalUrl
2456
+ });
2457
+ }
2458
+ modify(options) {
2459
+ return new _ServerRequestImpl(this.source, options.url ?? this.url, options.headers ?? this.headersOverride, options.remoteAddress ?? this.remoteAddressOverride);
2460
+ }
2461
+ get method() {
2462
+ return this.source.method.toUpperCase();
2463
+ }
2464
+ get originalUrl() {
2465
+ return this.source.url;
2466
+ }
2467
+ get remoteAddress() {
2468
+ return this.remoteAddressOverride ? Option8.some(this.remoteAddressOverride) : Option8.none();
2469
+ }
2470
+ get headers() {
2471
+ this.headersOverride ??= fromInput(this.source.headers);
2472
+ return this.headersOverride;
2473
+ }
2474
+ cachedCookies;
2475
+ get cookies() {
2476
+ if (this.cachedCookies) {
2477
+ return this.cachedCookies;
2478
+ }
2479
+ return this.cachedCookies = parseHeader(this.headers.cookie ?? "");
2480
+ }
2481
+ get stream() {
2482
+ return this.source.body ? Stream5.fromReadableStream(() => this.source.body, (cause) => new RequestError({
2483
+ request: this,
2484
+ reason: "Decode",
2485
+ cause
2486
+ })) : Stream5.fail(new RequestError({
2487
+ request: this,
2488
+ reason: "Decode",
2489
+ description: "can not create stream from empty body"
2490
+ }));
2491
+ }
2492
+ textEffect;
2493
+ get text() {
2494
+ if (this.textEffect) {
2495
+ return this.textEffect;
2496
+ }
2497
+ this.textEffect = Effect9.runSync(Effect9.cached(Effect9.tryPromise({
2498
+ try: () => this.source.text(),
2499
+ catch: (cause) => new RequestError({
2500
+ request: this,
2501
+ reason: "Decode",
2502
+ cause
2503
+ })
2504
+ })));
2505
+ return this.textEffect;
2506
+ }
2507
+ get json() {
2508
+ return Effect9.tryMap(this.text, {
2509
+ try: (_) => JSON.parse(_),
2510
+ catch: (cause) => new RequestError({
2511
+ request: this,
2512
+ reason: "Decode",
2513
+ cause
2514
+ })
2515
+ });
2516
+ }
2517
+ get urlParamsBody() {
2518
+ return Effect9.flatMap(this.text, (_) => Effect9.try({
2519
+ try: () => fromInput2(new URLSearchParams(_)),
2520
+ catch: (cause) => new RequestError({
2521
+ request: this,
2522
+ reason: "Decode",
2523
+ cause
2524
+ })
2525
+ }));
2526
+ }
2527
+ multipartEffect;
2528
+ get multipart() {
2529
+ if (this.multipartEffect) {
2530
+ return this.multipartEffect;
2531
+ }
2532
+ this.multipartEffect = Effect9.runSync(Effect9.cached(toPersisted(this.multipartStream)));
2533
+ return this.multipartEffect;
2534
+ }
2535
+ get multipartStream() {
2536
+ return Stream5.pipeThroughChannel(Stream5.mapError(this.stream, (cause) => new MultipartError({
2537
+ reason: "InternalError",
2538
+ cause
2539
+ })), makeChannel(this.headers));
2540
+ }
2541
+ arrayBufferEffect;
2542
+ get arrayBuffer() {
2543
+ if (this.arrayBufferEffect) {
2544
+ return this.arrayBufferEffect;
2545
+ }
2546
+ this.arrayBufferEffect = Effect9.runSync(Effect9.cached(Effect9.tryPromise({
2547
+ try: () => this.source.arrayBuffer(),
2548
+ catch: (cause) => new RequestError({
2549
+ request: this,
2550
+ reason: "Decode",
2551
+ cause
2552
+ })
2553
+ })));
2554
+ return this.arrayBufferEffect;
2555
+ }
2556
+ get upgrade() {
2557
+ return Effect9.fail(new RequestError({
2558
+ request: this,
2559
+ reason: "Decode",
2560
+ description: "Not an upgradeable ServerRequest"
2561
+ }));
2562
+ }
2563
+ };
2564
+ var toURL = (self) => {
2565
+ const host = self.headers.host ?? "localhost";
2566
+ const protocol = self.headers["x-forwarded-proto"] === "https" ? "https" : "http";
2567
+ try {
2568
+ return Option8.some(new URL(self.url, `${protocol}://${host}`));
2569
+ } catch {
2570
+ return Option8.none();
2571
+ }
2572
+ };
2573
+
2574
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/HttpServerRequest.js
2575
+ var HttpServerRequest = serverRequestTag;
2576
+ var fromWeb3 = fromWeb2;
2577
+ var toWebEither = (self, options) => {
2578
+ if (self.source instanceof Request) {
2579
+ return Either3.right(self.source);
2580
+ }
2581
+ const ourl = toURL2(self);
2582
+ if (Option9.isNone(ourl)) {
2583
+ return Either3.left(new RequestError({
2584
+ request: self,
2585
+ reason: "Decode",
2586
+ description: "Invalid URL"
2587
+ }));
2588
+ }
2589
+ const requestInit = {
2590
+ method: self.method,
2591
+ headers: self.headers,
2592
+ signal: options?.signal
2593
+ };
2594
+ if (hasBody(self.method)) {
2595
+ requestInit.body = Stream6.toReadableStreamRuntime(self.stream, options?.runtime ?? Runtime2.defaultRuntime);
2596
+ requestInit.duplex = "half";
2597
+ }
2598
+ return Either3.right(new Request(ourl.value, requestInit));
2599
+ };
2600
+ var toURL2 = toURL;
2601
+
2602
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/internal/httpApp.js
2603
+ var Effect11 = __toESM(require("effect/Effect"), 1);
2604
+ var FiberRef2 = __toESM(require("effect/FiberRef"), 1);
2605
+ var import_Function10 = require("effect/Function");
2606
+ var import_GlobalValue3 = require("effect/GlobalValue");
2607
+ var Option10 = __toESM(require("effect/Option"), 1);
2608
+ var currentPreResponseHandlers = /* @__PURE__ */ (0, import_GlobalValue3.globalValue)(/* @__PURE__ */ Symbol.for("@effect/platform/HttpApp/preResponseHandlers"), () => FiberRef2.unsafeMake(Option10.none()));
2609
+ var appendPreResponseHandler = (handler) => FiberRef2.update(currentPreResponseHandlers, Option10.match({
2610
+ onNone: () => Option10.some(handler),
2611
+ onSome: (prev) => Option10.some((request, response) => Effect11.flatMap(prev(request, response), (response2) => handler(request, response2)))
2612
+ }));
2613
+ var withPreResponseHandler = /* @__PURE__ */ (0, import_Function10.dual)(2, (self, handler) => Effect11.locallyWith(self, currentPreResponseHandlers, Option10.match({
2614
+ onNone: () => Option10.some(handler),
2615
+ onSome: (prev) => Option10.some((request, response) => Effect11.flatMap(prev(request, response), (response2) => handler(request, response2)))
2616
+ })));
2617
+
2618
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/internal/httpMiddleware.js
2619
+ var Context6 = __toESM(require("effect/Context"), 1);
2620
+ var Effect12 = __toESM(require("effect/Effect"), 1);
2621
+ var FiberRef3 = __toESM(require("effect/FiberRef"), 1);
2622
+ var import_Function11 = require("effect/Function");
2623
+ var Function = __toESM(require("effect/Function"), 1);
2624
+ var import_GlobalValue4 = require("effect/GlobalValue");
2625
+ var Layer3 = __toESM(require("effect/Layer"), 1);
2626
+ var Option11 = __toESM(require("effect/Option"), 1);
2627
+ var make10 = (middleware) => middleware;
2628
+ var currentTracerDisabledWhen = /* @__PURE__ */ (0, import_GlobalValue4.globalValue)(/* @__PURE__ */ Symbol.for("@effect/platform/HttpMiddleware/tracerDisabledWhen"), () => FiberRef3.unsafeMake(import_Function11.constFalse));
2629
+ var SpanNameGenerator = /* @__PURE__ */ Context6.Reference()("@effect/platform/HttpMiddleware/SpanNameGenerator", {
2630
+ defaultValue: () => (request) => `http.server ${request.method}`
2631
+ });
2632
+ var tracer = /* @__PURE__ */ make10((httpApp) => Effect12.withFiberRuntime((fiber) => {
2633
+ const request = Context6.unsafeGet(fiber.currentContext, HttpServerRequest);
2634
+ const disabled = fiber.getFiberRef(currentTracerDisabledWhen)(request);
2635
+ if (disabled) {
2636
+ return httpApp;
2637
+ }
2638
+ const url = Option11.getOrUndefined(toURL2(request));
2639
+ if (url !== void 0 && (url.username !== "" || url.password !== "")) {
2640
+ url.username = "REDACTED";
2641
+ url.password = "REDACTED";
2642
+ }
2643
+ const redactedHeaderNames = fiber.getFiberRef(currentRedactedNames);
2644
+ const redactedHeaders = redact(request.headers, redactedHeaderNames);
2645
+ const nameGenerator = Context6.get(fiber.currentContext, SpanNameGenerator);
2646
+ return Effect12.useSpan(nameGenerator(request), {
2647
+ parent: Option11.getOrUndefined(fromHeaders(request.headers)),
2648
+ kind: "server",
2649
+ captureStackTrace: false
2650
+ }, (span) => {
2651
+ span.attribute("http.request.method", request.method);
2652
+ if (url !== void 0) {
2653
+ span.attribute("url.full", url.toString());
2654
+ span.attribute("url.path", url.pathname);
2655
+ const query = url.search.slice(1);
2656
+ if (query !== "") {
2657
+ span.attribute("url.query", url.search.slice(1));
2658
+ }
2659
+ span.attribute("url.scheme", url.protocol.slice(0, -1));
2660
+ }
2661
+ if (request.headers["user-agent"] !== void 0) {
2662
+ span.attribute("user_agent.original", request.headers["user-agent"]);
2663
+ }
2664
+ for (const name in redactedHeaders) {
2665
+ span.attribute(`http.request.header.${name}`, String(redactedHeaders[name]));
2666
+ }
2667
+ if (request.remoteAddress._tag === "Some") {
2668
+ span.attribute("client.address", request.remoteAddress.value);
2669
+ }
2670
+ return Effect12.flatMap(Effect12.exit(Effect12.withParentSpan(httpApp, span)), (exit2) => {
2671
+ const response = exitResponse2(exit2);
2672
+ span.attribute("http.response.status_code", response.status);
2673
+ const redactedHeaders2 = redact(response.headers, redactedHeaderNames);
2674
+ for (const name in redactedHeaders2) {
2675
+ span.attribute(`http.response.header.${name}`, String(redactedHeaders2[name]));
2676
+ }
2677
+ return exit2;
2678
+ });
2679
+ });
2680
+ }));
2681
+
2682
+ // ../../node_modules/.bun/@effect+platform@0.94.2+8cc8b89dc7ad56db/node_modules/@effect/platform/dist/esm/HttpApp.js
2683
+ var handledSymbol = /* @__PURE__ */ Symbol.for("@effect/platform/HttpApp/handled");
2684
+ var toHandled = (self, handleResponse, middleware) => {
2685
+ const responded = Effect13.withFiberRuntime((fiber) => Effect13.flatMap(self, (response) => {
2686
+ const request = Context7.unsafeGet(fiber.currentContext, HttpServerRequest);
2687
+ const handler = fiber.getFiberRef(currentPreResponseHandlers2);
2688
+ if (handler._tag === "None") {
2689
+ ;
2690
+ request[handledSymbol] = true;
2691
+ return Effect13.as(handleResponse(request, response), response);
2692
+ }
2693
+ return Effect13.tap(handler.value(request, response), (response2) => {
2694
+ ;
2695
+ request[handledSymbol] = true;
2696
+ return handleResponse(request, response2);
2697
+ });
2698
+ }));
2699
+ const withErrorHandling = Effect13.catchAllCause(responded, (cause) => Effect13.withFiberRuntime((fiber) => Effect13.flatMap(causeResponse2(cause), ([response, cause2]) => {
2700
+ const request = Context7.unsafeGet(fiber.currentContext, HttpServerRequest);
2701
+ const handler = fiber.getFiberRef(currentPreResponseHandlers2);
2702
+ if (handler._tag === "None") {
2703
+ ;
2704
+ request[handledSymbol] = true;
2705
+ return Effect13.zipRight(handleResponse(request, response), Cause3.isEmptyType(cause2) ? Effect13.succeed(response) : Effect13.failCause(cause2));
2706
+ }
2707
+ return Effect13.zipRight(Effect13.tap(handler.value(request, response), (response2) => {
2708
+ ;
2709
+ request[handledSymbol] = true;
2710
+ return handleResponse(request, response2);
2711
+ }), Cause3.isEmptyType(cause2) ? Effect13.succeed(response) : Effect13.failCause(cause2));
2712
+ })));
2713
+ const withMiddleware = (0, import_Unify.unify)(middleware === void 0 ? tracer(withErrorHandling) : Effect13.matchCauseEffect(tracer(middleware(withErrorHandling)), {
2714
+ onFailure: (cause) => Effect13.withFiberRuntime((fiber) => {
2715
+ const request = Context7.unsafeGet(fiber.currentContext, HttpServerRequest);
2716
+ if (handledSymbol in request) {
2717
+ return Effect13.void;
2718
+ }
2719
+ return Effect13.matchCauseEffect(causeResponse2(cause), {
2720
+ onFailure: (_cause) => handleResponse(request, empty5({
2721
+ status: 500
2722
+ })),
2723
+ onSuccess: ([response]) => handleResponse(request, response)
2724
+ });
2725
+ }),
2726
+ onSuccess: (response) => Effect13.withFiberRuntime((fiber) => {
2727
+ const request = Context7.unsafeGet(fiber.currentContext, HttpServerRequest);
2728
+ return handledSymbol in request ? Effect13.void : handleResponse(request, response);
2729
+ })
2730
+ }));
2731
+ return Effect13.uninterruptible(scoped(withMiddleware));
2732
+ };
2733
+ var ejectDefaultScopeClose = (scope) => {
2734
+ ejectedScopes.add(scope);
2735
+ };
2736
+ var unsafeEjectStreamScope = (response) => {
2737
+ if (response.body._tag !== "Stream") {
2738
+ return response;
2739
+ }
2740
+ const fiber = Option12.getOrThrow(Fiber.getCurrentFiber());
2741
+ const scope = Context7.unsafeGet(fiber.currentContext, Scope.Scope);
2742
+ ejectDefaultScopeClose(scope);
2743
+ return setBody2(response, stream2(Stream7.ensuring(response.body.stream, Scope.close(scope, Exit2.void)), response.body.contentType, response.body.contentLength));
2744
+ };
2745
+ var ejectedScopes = /* @__PURE__ */ GlobalValue.globalValue("@effect/platform/HttpApp/ejectedScopes", () => /* @__PURE__ */ new WeakSet());
2746
+ var scoped = (effect) => Effect13.flatMap(Scope.make(), (scope) => Effect13.onExit(Scope.extend(effect, scope), (exit2) => {
2747
+ if (ejectedScopes.has(scope)) {
2748
+ return Effect13.void;
2749
+ }
2750
+ return Scope.close(scope, exit2);
2751
+ }));
2752
+ var currentPreResponseHandlers2 = currentPreResponseHandlers;
2753
+ var appendPreResponseHandler2 = appendPreResponseHandler;
2754
+ var withPreResponseHandler2 = withPreResponseHandler;
2755
+ var toWebHandlerRuntime = (runtime3) => {
2756
+ const httpRuntime = Runtime3.make(runtime3);
2757
+ const run3 = Runtime3.runFork(httpRuntime);
2758
+ return (self, middleware) => {
2759
+ const resolveSymbol = /* @__PURE__ */ Symbol.for("@effect/platform/HttpApp/resolve");
2760
+ const httpApp = toHandled(self, (request, response) => {
2761
+ response = unsafeEjectStreamScope(response);
2762
+ request[resolveSymbol](toWeb2(response, {
2763
+ withoutBody: request.method === "HEAD",
2764
+ runtime: runtime3
2765
+ }));
2766
+ return Effect13.void;
2767
+ }, middleware);
2768
+ return (request, context2) => new Promise((resolve3) => {
2769
+ const contextMap = new Map(runtime3.context.unsafeMap);
2770
+ if (Context7.isContext(context2)) {
2771
+ for (const [key, value] of context2.unsafeMap) {
2772
+ contextMap.set(key, value);
2773
+ }
2774
+ }
2775
+ const httpServerRequest = fromWeb3(request);
2776
+ contextMap.set(HttpServerRequest.key, httpServerRequest);
2777
+ httpServerRequest[resolveSymbol] = resolve3;
2778
+ httpRuntime.context = Context7.unsafeMake(contextMap);
2779
+ const fiber = run3(httpApp);
2780
+ request.signal?.addEventListener("abort", () => {
2781
+ fiber.unsafeInterruptAsFork(clientAbortFiberId2);
2782
+ }, {
2783
+ once: true
2784
+ });
2785
+ });
2786
+ };
2787
+ };
2788
+ var toWebHandler = /* @__PURE__ */ toWebHandlerRuntime(Runtime3.defaultRuntime);
2789
+ var toWebHandlerLayerWith = (layer2, options) => {
2790
+ const scope = Effect13.runSync(Scope.make());
2791
+ const dispose = () => Effect13.runPromise(Scope.close(scope, Exit2.void));
2792
+ let handlerCache;
2793
+ let handlerPromise;
2794
+ function handler(request, context2) {
2795
+ if (handlerCache) {
2796
+ return handlerCache(request, context2);
2797
+ }
2798
+ handlerPromise ??= Effect13.gen(function* () {
2799
+ const runtime3 = yield* options.memoMap ? Layer4.toRuntimeWithMemoMap(layer2, options.memoMap) : Layer4.toRuntime(layer2);
2800
+ return handlerCache = toWebHandlerRuntime(runtime3)(yield* options.toHandler(runtime3), options.middleware);
2801
+ }).pipe(Scope.extend(scope), Effect13.runPromise);
2802
+ return handlerPromise.then((f) => f(request, context2));
2803
+ }
2804
+ return {
2805
+ dispose,
2806
+ handler
2807
+ };
2808
+ };
2809
+ var toWebHandlerLayer = (self, layer2, options) => toWebHandlerLayerWith(layer2, {
2810
+ ...options,
2811
+ toHandler: () => Effect13.succeed(self)
2812
+ });
2813
+ var fromWebHandler = (handler) => Effect13.async((resume, signal) => {
2814
+ const fiber = Option12.getOrThrow(Fiber.getCurrentFiber());
2815
+ const request = Context7.unsafeGet(fiber.currentContext, HttpServerRequest);
2816
+ const requestResult = toWebEither(request, {
2817
+ signal,
2818
+ runtime: Runtime3.make({
2819
+ context: fiber.currentContext,
2820
+ fiberRefs: fiber.getFiberRefs(),
2821
+ runtimeFlags: Runtime3.defaultRuntimeFlags
2822
+ })
2823
+ });
2824
+ if (requestResult._tag === "Left") {
2825
+ return resume(Effect13.fail(requestResult.left));
2826
+ }
2827
+ handler(requestResult.right).then((response) => resume(Effect13.succeed(fromWeb(response))), (cause) => resume(Effect13.fail(new RequestError({
2828
+ cause,
2829
+ request,
2830
+ reason: "Transport",
2831
+ description: "HttpApp.fromWebHandler: Error in handler"
2832
+ }))));
2833
+ });
2834
+
2835
+ // src/for/inngest/index.ts
2836
+ var import_effect5 = require("effect");
2837
+ var Context9 = __toESM(require("effect/Context"), 1);
2838
+ var Inspectable7 = __toESM(require("effect/Inspectable"), 1);
2839
+ var import_bun = require("inngest/bun");
2840
+
2841
+ // src/extract.ts
2842
+ var import_effect = require("effect");
2843
+ function extract(effect, options) {
2844
+ return import_effect.Effect.gen(function* () {
2845
+ const runtime3 = yield* import_effect.Effect.runtime();
2846
+ const context2 = runtime3.context.pipe(
2847
+ options?.exclude ? import_effect.Context.omit(...options.exclude) : (e) => e
2848
+ );
2849
+ return (...params) => (0, import_effect.pipe)(effect(...params), import_effect.Effect.provide(context2));
2850
+ });
2851
+ }
2852
+
2853
+ // src/for/inngest/cron.ts
2854
+ var import_effect2 = require("effect");
2855
+ function fieldToString(field, max) {
2856
+ if (field.size === 0 || field.size === max) return "*";
2857
+ return Array.from(field).sort((a, b) => a - b).join(",");
2858
+ }
2859
+ function cronToString(cron) {
2860
+ const minutes = fieldToString(cron.minutes, 60);
2861
+ const hours = fieldToString(cron.hours, 24);
2862
+ const days = fieldToString(cron.days, 31);
2863
+ const months = fieldToString(cron.months, 12);
2864
+ const weekdays = fieldToString(cron.weekdays, 7);
2865
+ const expr = `${minutes} ${hours} ${days} ${months} ${weekdays}`;
2866
+ if (import_effect2.Option.isSome(cron.tz)) return `TZ=${cron.tz.value} ${expr}`;
2867
+ return expr;
2868
+ }
2869
+
2870
+ // src/for/inngest/step.ts
2871
+ var import_effect4 = require("effect");
2872
+
2873
+ // src/run-promise-unwrapped.ts
2874
+ var import_effect3 = require("effect");
2875
+ async function runPromiseUnwrapped(effect) {
2876
+ const exit2 = await import_effect3.Effect.runPromiseExit(effect);
2877
+ return import_effect3.Exit.match(exit2, {
2878
+ onSuccess: (value) => value,
2879
+ onFailure: (cause) => {
2880
+ throw import_effect3.Cause.isFailType(cause) ? cause.error : cause;
2881
+ }
2882
+ });
2883
+ }
2884
+
2885
+ // src/for/inngest/step.ts
2886
+ function wrapStep(step) {
2887
+ const s = step;
2888
+ return {
2889
+ run: (id, fn) => import_effect4.Effect.tryPromise({
2890
+ try: () => s.run(id, () => runPromiseUnwrapped(fn())),
2891
+ catch: (cause) => new InngestError({ message: `Step "${id}" failed`, cause })
2892
+ }),
2893
+ sleep: (id, duration) => import_effect4.Effect.tryPromise({
2894
+ try: () => s.sleep(id, import_effect4.Duration.toMillis(import_effect4.Duration.decode(duration))),
2895
+ catch: (cause) => new InngestError({
2896
+ message: `Step sleep "${id}" failed`,
2897
+ cause
2898
+ })
2899
+ }),
2900
+ sleepUntil: (id, time) => import_effect4.Effect.tryPromise({
2901
+ try: () => s.sleepUntil(id, time),
2902
+ catch: (cause) => new InngestError({
2903
+ message: `Step sleepUntil "${id}" failed`,
2904
+ cause
2905
+ })
2906
+ }),
2907
+ invoke: (id, opts) => import_effect4.Effect.tryPromise({
2908
+ try: () => s.invoke(id, opts),
2909
+ catch: (cause) => new InngestError({
2910
+ message: `Step invoke "${id}" failed`,
2911
+ cause
2912
+ })
2913
+ }),
2914
+ waitForEvent: (id, opts) => import_effect4.Effect.tryPromise({
2915
+ try: () => s.waitForEvent(id, opts),
2916
+ catch: (cause) => new InngestError({
2917
+ message: `Step waitForEvent "${id}" failed`,
2918
+ cause
2919
+ })
2920
+ }),
2921
+ sendEvent: (id, payload) => import_effect4.Effect.tryPromise({
2922
+ try: () => s.sendEvent(id, payload),
2923
+ catch: (cause) => new InngestError({
2924
+ message: `Step sendEvent "${id}" failed`,
2925
+ cause
2926
+ })
2927
+ })
2928
+ };
2929
+ }
2930
+
2931
+ // src/for/inngest/index.ts
2932
+ var TagTypeId2 = Context9.TagTypeId;
2933
+ var NodeInspectSymbol4 = Inspectable7.NodeInspectSymbol;
2934
+ var InngestError = class extends import_effect5.Data.TaggedError("ff-effect/InngestError") {
2935
+ };
2936
+ function isCronTrigger(trigger) {
2937
+ return typeof trigger === "object" && trigger !== null && "cron" in trigger && typeof trigger.cron === "object" && trigger.cron !== null && "minutes" in trigger.cron;
2938
+ }
2939
+ function resolveTrigger(trigger) {
2940
+ if (Array.isArray(trigger)) {
2941
+ return trigger.map(
2942
+ (t) => resolveTrigger(t)
2943
+ );
2944
+ }
2945
+ if (isCronTrigger(trigger)) {
2946
+ return { cron: cronToString(trigger.cron) };
2947
+ }
2948
+ return trigger;
2949
+ }
2950
+ var defaultPrefix = "@ff-effect/Inngest";
2951
+ function createInngest(createClient, opts) {
2952
+ const tagId = opts?.tagId ?? defaultPrefix;
2953
+ const Tag3 = Context9.Tag(tagId)();
2954
+ const send = (payload) => import_effect5.Effect.gen(function* () {
2955
+ const c = yield* Tag3;
2956
+ return yield* import_effect5.Effect.tryPromise({
2957
+ // @ts-expect-error inngest generic variance issue between constrained and inferred client types
2958
+ try: () => c.send(payload),
2959
+ catch: (cause) => new InngestError({ message: "Failed to send event", cause })
2960
+ });
2961
+ });
2962
+ const createFunction = (config, trigger, handler) => import_effect5.Effect.gen(function* () {
2963
+ const c = yield* Tag3;
2964
+ const ext_handler = yield* extract(handler);
2965
+ const resolvedTrigger = resolveTrigger(trigger);
2966
+ const runPromise2 = yield* import_effect5.FiberSet.makeRuntimePromise();
2967
+ return c.createFunction(
2968
+ config,
2969
+ resolvedTrigger,
2970
+ // biome-ignore lint/suspicious/noExplicitAny: inngest middleware produces unresolvable context type
2971
+ async (ctx) => {
2972
+ const effectStep = wrapStep(ctx.step);
2973
+ return runPromise2(
2974
+ ext_handler({
2975
+ ...ctx,
2976
+ step: effectStep
2977
+ })
2978
+ );
2979
+ }
2980
+ );
2981
+ });
2982
+ function buildServe(client, httpOpts) {
2983
+ return (0, import_bun.serve)({
2984
+ client,
2985
+ functions: httpOpts.functions,
2986
+ ...httpOpts.servePath != null && { servePath: httpOpts.servePath },
2987
+ ...httpOpts.signingKey != null && {
2988
+ signingKey: httpOpts.signingKey
2989
+ },
2990
+ ...httpOpts.signingKeyFallback != null && {
2991
+ signingKeyFallback: httpOpts.signingKeyFallback
2992
+ },
2993
+ ...httpOpts.logLevel != null && { logLevel: httpOpts.logLevel },
2994
+ ...httpOpts.streaming != null && { streaming: httpOpts.streaming }
2995
+ });
2996
+ }
2997
+ const fetchHandler = (httpOpts) => import_effect5.Effect.gen(function* () {
2998
+ const c = yield* Tag3;
2999
+ return buildServe(c, httpOpts);
3000
+ });
3001
+ const httpHandler = (httpOpts) => import_effect5.Effect.gen(function* () {
3002
+ const c = yield* Tag3;
3003
+ return HttpApp_exports.fromWebHandler(buildServe(c, httpOpts));
3004
+ });
3005
+ return {
3006
+ Tag: Tag3,
3007
+ layer: import_effect5.Layer.effect(Tag3, createClient),
3008
+ createFunction,
3009
+ send,
3010
+ fetchHandler,
3011
+ httpHandler
3012
+ };
3013
+ }
3014
+ // Annotate the CommonJS export names for ESM import in node:
3015
+ 0 && (module.exports = {
3016
+ InngestError,
3017
+ NodeInspectSymbol,
3018
+ TagTypeId,
3019
+ createInngest
3020
+ });
3021
+ //# sourceMappingURL=index.cjs.map