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