@effect/platform-node 0.29.4 → 0.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Http/FormData.js +8 -2
- package/dist/cjs/Http/FormData.js.map +1 -1
- package/dist/cjs/internal/http/formData.js +65 -96
- package/dist/cjs/internal/http/formData.js.map +1 -1
- package/dist/dts/Http/FormData.d.ts +6 -1
- package/dist/dts/Http/FormData.d.ts.map +1 -1
- package/dist/dts/Worker.d.ts +1 -1
- package/dist/dts/Worker.d.ts.map +1 -1
- package/dist/dts/WorkerRunner.d.ts +1 -1
- package/dist/dts/WorkerRunner.d.ts.map +1 -1
- package/dist/dts/internal/http/formData.d.ts +1 -5
- package/dist/dts/internal/http/formData.d.ts.map +1 -1
- package/dist/esm/Http/FormData.js +5 -0
- package/dist/esm/Http/FormData.js.map +1 -1
- package/dist/esm/internal/http/formData.js +62 -89
- package/dist/esm/internal/http/formData.js.map +1 -1
- package/package.json +3 -3
- package/src/Http/FormData.ts +11 -2
- package/src/Worker.ts +1 -1
- package/src/WorkerRunner.ts +1 -1
- package/src/internal/http/formData.ts +74 -135
- package/src/internal/http/server.ts +2 -2
|
@@ -5,9 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
7
|
stream: true,
|
|
8
|
-
formData: true
|
|
8
|
+
formData: true,
|
|
9
|
+
fileToReadable: true
|
|
9
10
|
};
|
|
10
|
-
exports.stream = exports.formData = void 0;
|
|
11
|
+
exports.stream = exports.formData = exports.fileToReadable = void 0;
|
|
11
12
|
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../internal/http/formData.js"));
|
|
12
13
|
var _FormData = /*#__PURE__*/require("@effect/platform/Http/FormData");
|
|
13
14
|
Object.keys(_FormData).forEach(function (key) {
|
|
@@ -60,4 +61,9 @@ const stream = exports.stream = internal.stream;
|
|
|
60
61
|
* @category constructors
|
|
61
62
|
*/
|
|
62
63
|
const formData = exports.formData = internal.formData;
|
|
64
|
+
/**
|
|
65
|
+
* @since 1.0.0
|
|
66
|
+
* @category conversions
|
|
67
|
+
*/
|
|
68
|
+
const fileToReadable = exports.fileToReadable = internal.fileToReadable;
|
|
63
69
|
//# sourceMappingURL=FormData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormData.js","names":["internal","_interopRequireWildcard","require","_FormData","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","n","__proto__","a","getOwnPropertyDescriptor","u","i","set","stream","formData"],"sources":["../../../src/Http/FormData.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"file":"FormData.js","names":["internal","_interopRequireWildcard","require","_FormData","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","n","__proto__","a","getOwnPropertyDescriptor","u","i","set","stream","formData","fileToReadable"],"sources":["../../../src/Http/FormData.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;AAaA,IAAAA,QAAA,gBAAAC,uBAAA,eAAAC,OAAA;AAKA,IAAAC,SAAA,gBAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,SAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,SAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,SAAA,CAAAI,GAAA;IAAA;EAAA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;;;AAIO,MAAMO,MAAM,GAAAnB,OAAA,CAAAmB,MAAA,GAGgD/B,QAAQ,CAAC+B,MAAM;AAElF;;;;AAIO,MAAMC,QAAQ,GAAApB,OAAA,CAAAoB,QAAA,GAOjBhC,QAAQ,CAACgC,QAAQ;AAErB;;;;AAIO,MAAMC,cAAc,GAAArB,OAAA,CAAAqB,cAAA,GAAsCjC,QAAQ,CAACiC,cAAc"}
|
|
@@ -3,25 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.stream = exports.formData = void 0;
|
|
7
|
-
var FileSystem = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/FileSystem"));
|
|
6
|
+
exports.stream = exports.formData = exports.fileToReadable = void 0;
|
|
8
7
|
var FormData = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/Http/FormData"));
|
|
9
|
-
var Path = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/Path"));
|
|
10
|
-
var _busboy = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("busboy"));
|
|
11
|
-
var Chunk = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Chunk"));
|
|
12
8
|
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
|
|
13
|
-
var FiberRef = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/FiberRef"));
|
|
14
9
|
var _Function = /*#__PURE__*/require("effect/Function");
|
|
15
|
-
var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Option"));
|
|
16
10
|
var Stream = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Stream"));
|
|
17
|
-
var
|
|
11
|
+
var _multipasta = /*#__PURE__*/require("multipasta");
|
|
12
|
+
var MP = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("multipasta/node"));
|
|
13
|
+
var NFS = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("node:fs"));
|
|
18
14
|
var NodeStreamP = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("node:stream/promises"));
|
|
19
|
-
var NodeStream = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("
|
|
20
|
-
function _interopRequireDefault(obj) {
|
|
21
|
-
return obj && obj.__esModule ? obj : {
|
|
22
|
-
default: obj
|
|
23
|
-
};
|
|
24
|
-
}
|
|
15
|
+
var NodeStream = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../stream.js"));
|
|
25
16
|
function _getRequireWildcardCache(e) {
|
|
26
17
|
if ("function" != typeof WeakMap) return null;
|
|
27
18
|
var r = new WeakMap(),
|
|
@@ -47,104 +38,82 @@ function _interopRequireWildcard(e, r) {
|
|
|
47
38
|
}
|
|
48
39
|
return n.default = e, t && t.set(e, n), n;
|
|
49
40
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
headers,
|
|
58
|
-
limits: {
|
|
59
|
-
parts: Option.getOrUndefined(Option.map(maxParts, Number)),
|
|
60
|
-
files: Option.getOrUndefined(Option.map(maxFiles, Number)),
|
|
61
|
-
fields: Option.getOrUndefined(Option.map(maxFields, Number)),
|
|
62
|
-
fieldSize: Number(maxFieldSize),
|
|
63
|
-
fileSize: Option.getOrUndefined(Option.map(maxFileSize, Number))
|
|
64
|
-
}
|
|
65
|
-
})), busboy => Effect.sync(() => {
|
|
66
|
-
busboy.removeAllListeners();
|
|
67
|
-
if (!busboy.closed) {
|
|
68
|
-
busboy.destroy();
|
|
69
|
-
}
|
|
70
|
-
}))), Effect.map(({
|
|
71
|
-
busboy,
|
|
72
|
-
fieldMimeTypes
|
|
73
|
-
}) => Stream.mapEffect(Stream.async(emit => {
|
|
74
|
-
busboy.on("field", (name, value, info) => {
|
|
75
|
-
if (info.valueTruncated) {
|
|
76
|
-
emit.fail(FormData.FormDataError("FieldTooLarge", new Error("maxFieldSize exceeded")));
|
|
77
|
-
} else {
|
|
78
|
-
emit.single(new FieldImpl(name, info.mimeType, value));
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
busboy.on("file", (name, stream, info) => {
|
|
82
|
-
stream.once("limit", () => {
|
|
83
|
-
emit.fail(FormData.FormDataError("FileTooLarge", new Error("maxFileSize exceeded")));
|
|
84
|
-
});
|
|
85
|
-
emit.single(new FileImpl(name, info.filename, info.mimeType, NodeStream.fromReadable(() => stream, error => FormData.FormDataError("InternalError", error)), stream));
|
|
86
|
-
});
|
|
87
|
-
busboy.on("error", _ => {
|
|
88
|
-
emit.fail(FormData.FormDataError("InternalError", _));
|
|
89
|
-
});
|
|
90
|
-
busboy.on("finish", () => {
|
|
91
|
-
emit.end();
|
|
92
|
-
});
|
|
93
|
-
source.pipe(busboy);
|
|
94
|
-
}), part => part._tag === "File" && Chunk.some(fieldMimeTypes, _ => part.contentType.includes(_)) ? Effect.map(NodeStream.toString(() => part.source, {
|
|
95
|
-
onFailure: error => FormData.FormDataError("InternalError", error)
|
|
96
|
-
}), content => new FieldImpl(part.key, part.contentType, content)) : Effect.succeed(part))), Stream.unwrapScoped);
|
|
41
|
+
/** @internal */
|
|
42
|
+
const stream = (source, headers) => (0, _Function.pipe)(FormData.makeConfig(headers), Effect.map(config => NodeStream.fromReadable(() => {
|
|
43
|
+
const parser = MP.make(config);
|
|
44
|
+
source.pipe(parser);
|
|
45
|
+
return parser;
|
|
46
|
+
}, error => convertError(error))), Stream.unwrap, Stream.map(convertPart));
|
|
47
|
+
/** @internal */
|
|
97
48
|
exports.stream = stream;
|
|
49
|
+
const formData = (source, headers) => FormData.formData(stream(source, headers), (path, file) => Effect.tryPromise({
|
|
50
|
+
try: signal => NodeStreamP.pipeline(file.file, NFS.createWriteStream(path), {
|
|
51
|
+
signal
|
|
52
|
+
}),
|
|
53
|
+
catch: error => FormData.FormDataError("InternalError", error)
|
|
54
|
+
}));
|
|
55
|
+
exports.formData = formData;
|
|
56
|
+
const convertPart = part => part._tag === "Field" ? new FieldImpl(part.info, part.value) : new FileImpl(part);
|
|
98
57
|
class FieldImpl {
|
|
58
|
+
[FormData.TypeId];
|
|
59
|
+
_tag = "Field";
|
|
99
60
|
key;
|
|
100
61
|
contentType;
|
|
101
62
|
value;
|
|
102
|
-
|
|
103
|
-
_tag = "Field";
|
|
104
|
-
constructor(key, contentType, value) {
|
|
105
|
-
this.key = key;
|
|
106
|
-
this.contentType = contentType;
|
|
107
|
-
this.value = value;
|
|
63
|
+
constructor(info, value) {
|
|
108
64
|
this[FormData.TypeId] = FormData.TypeId;
|
|
65
|
+
this.key = info.name;
|
|
66
|
+
this.contentType = info.contentType;
|
|
67
|
+
this.value = (0, _multipasta.decodeField)(info, value);
|
|
109
68
|
}
|
|
110
69
|
}
|
|
111
70
|
class FileImpl {
|
|
71
|
+
file;
|
|
72
|
+
_tag = "File";
|
|
73
|
+
[FormData.TypeId];
|
|
112
74
|
key;
|
|
113
75
|
name;
|
|
114
76
|
contentType;
|
|
115
77
|
content;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
_tag = "File";
|
|
119
|
-
constructor(key, name, contentType, content, source) {
|
|
120
|
-
this.key = key;
|
|
121
|
-
this.name = name;
|
|
122
|
-
this.contentType = contentType;
|
|
123
|
-
this.content = content;
|
|
124
|
-
this.source = source;
|
|
78
|
+
constructor(file) {
|
|
79
|
+
this.file = file;
|
|
125
80
|
this[FormData.TypeId] = FormData.TypeId;
|
|
81
|
+
this.key = file.info.name;
|
|
82
|
+
this.name = file.filename ?? file.info.name;
|
|
83
|
+
this.contentType = file.info.contentType;
|
|
84
|
+
this.content = NodeStream.fromReadable(() => file, error => FormData.FormDataError("InternalError", error));
|
|
126
85
|
}
|
|
127
86
|
}
|
|
128
87
|
/** @internal */
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
88
|
+
const fileToReadable = file => file.file;
|
|
89
|
+
exports.fileToReadable = fileToReadable;
|
|
90
|
+
function convertError(error) {
|
|
91
|
+
switch (error._tag) {
|
|
92
|
+
case "ReachedLimit":
|
|
93
|
+
{
|
|
94
|
+
switch (error.limit) {
|
|
95
|
+
case "MaxParts":
|
|
96
|
+
{
|
|
97
|
+
return FormData.FormDataError("TooManyParts", error);
|
|
98
|
+
}
|
|
99
|
+
case "MaxFieldSize":
|
|
100
|
+
{
|
|
101
|
+
return FormData.FormDataError("FieldTooLarge", error);
|
|
102
|
+
}
|
|
103
|
+
case "MaxPartSize":
|
|
104
|
+
{
|
|
105
|
+
return FormData.FormDataError("FileTooLarge", error);
|
|
106
|
+
}
|
|
107
|
+
case "MaxTotalSize":
|
|
108
|
+
{
|
|
109
|
+
return FormData.FormDataError("BodyTooLarge", error);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
default:
|
|
114
|
+
{
|
|
115
|
+
return FormData.FormDataError("Parse", error);
|
|
116
|
+
}
|
|
133
117
|
}
|
|
134
|
-
|
|
135
|
-
const path = path_.join(dir, file.name);
|
|
136
|
-
const blob = "Bun" in globalThis ? globalThis.Bun.file(path, {
|
|
137
|
-
type: file.contentType
|
|
138
|
-
}) : new Blob([], {
|
|
139
|
-
type: file.contentType
|
|
140
|
-
});
|
|
141
|
-
formData.append(part.key, blob, path);
|
|
142
|
-
return Effect.as(Effect.tryPromise({
|
|
143
|
-
try: signal => NodeStreamP.pipeline(file.source, NodeFs.createWriteStream(path), {
|
|
144
|
-
signal
|
|
145
|
-
}),
|
|
146
|
-
catch: error => FormData.FormDataError("InternalError", error)
|
|
147
|
-
}), formData);
|
|
148
|
-
}));
|
|
149
|
-
exports.formData = formData;
|
|
118
|
+
}
|
|
150
119
|
//# sourceMappingURL=formData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formData.js","names":["
|
|
1
|
+
{"version":3,"file":"formData.js","names":["FormData","_interopRequireWildcard","require","Effect","_Function","Stream","_multipasta","MP","NFS","NodeStreamP","NodeStream","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","stream","source","headers","pipe","makeConfig","map","config","fromReadable","parser","make","error","convertError","unwrap","convertPart","exports","formData","path","file","tryPromise","try","signal","pipeline","createWriteStream","catch","FormDataError","part","_tag","FieldImpl","info","value","FileImpl","TypeId","key","contentType","constructor","name","decodeField","content","filename","fileToReadable","limit"],"sources":["../../../../src/internal/http/formData.ts"],"sourcesContent":[null],"mappings":";;;;;;AAAA,IAAAA,QAAA,gBAAAC,uBAAA,eAAAC,OAAA;AACA,IAAAC,MAAA,gBAAAF,uBAAA,eAAAC,OAAA;AACA,IAAAE,SAAA,gBAAAF,OAAA;AACA,IAAAG,MAAA,gBAAAJ,uBAAA,eAAAC,OAAA;AAEA,IAAAI,WAAA,gBAAAJ,OAAA;AACA,IAAAK,EAAA,gBAAAN,uBAAA,eAAAC,OAAA;AACA,IAAAM,GAAA,gBAAAP,uBAAA,eAAAC,OAAA;AAGA,IAAAO,WAAA,gBAAAR,uBAAA,eAAAC,OAAA;AACA,IAAAQ,UAAA,gBAAAT,uBAAA,eAAAC,OAAA;AAA0C,SAAAS,yBAAAC,CAAA;EAAA,yBAAAC,OAAA;EAAA,IAAAC,CAAA,OAAAD,OAAA;IAAAE,CAAA,OAAAF,OAAA;EAAA,QAAAF,wBAAA,YAAAA,CAAAC,CAAA;IAAA,OAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA;EAAA,GAAAF,CAAA;AAAA;AAAA,SAAAX,wBAAAW,CAAA,EAAAE,CAAA;EAAA,KAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA;EAAA,aAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA;IAAAK,OAAA,EAAAL;EAAA;EAAA,IAAAG,CAAA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IAI1D;MAAS;QACP,OAAO1C,QAAQ,CAACwD,aAAa,CAAC,OAAO,EAAEd,KAAK,CAAC;;;AAGnD"}
|
|
@@ -26,5 +26,10 @@ export declare const stream: (source: Readable, headers: IncomingHttpHeaders) =>
|
|
|
26
26
|
* @since 1.0.0
|
|
27
27
|
* @category constructors
|
|
28
28
|
*/
|
|
29
|
-
export declare const formData: (source: Readable, headers: IncomingHttpHeaders) => Effect.Effect<
|
|
29
|
+
export declare const formData: (source: Readable, headers: IncomingHttpHeaders) => Effect.Effect<FileSystem.FileSystem | Path.Path | Scope.Scope, FormData.FormDataError, FormData.PersistedFormData>;
|
|
30
|
+
/**
|
|
31
|
+
* @since 1.0.0
|
|
32
|
+
* @category conversions
|
|
33
|
+
*/
|
|
34
|
+
export declare const fileToReadable: (file: FormData.File) => Readable;
|
|
30
35
|
//# sourceMappingURL=FormData.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormData.d.ts","sourceRoot":"","sources":["../../../src/Http/FormData.ts"],"names":[],"mappings":";;AAAA;;;;GAIG;AACH,OAAO,KAAK,KAAK,UAAU,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,KAAK,QAAQ,MAAM,gCAAgC,CAAA;AAC/D,OAAO,KAAK,KAAK,IAAI,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAG3C;;GAEG;AACH,cAAc,gCAAgC,CAAA;AAE9C;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,CACnB,MAAM,EAAE,QAAQ,EAChB,OAAO,EAAE,mBAAmB,KACzB,MAAM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AACH,eAAO,MAAM,cAAc,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,KAAK,QAAkC,CAAA"}
|
package/dist/dts/Worker.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* Also includes exports from [`@effect/platform/Worker`](https://effect-ts.github.io/platform/platform/Worker.ts.html).
|
|
6
6
|
*/
|
|
7
7
|
import type * as Worker from "@effect/platform/Worker";
|
|
8
|
-
import type { Effect } from "effect";
|
|
9
8
|
import type * as Context from "effect/Context";
|
|
9
|
+
import type * as Effect from "effect/Effect";
|
|
10
10
|
import type * as Layer from "effect/Layer";
|
|
11
11
|
import type * as Scope from "effect/Scope";
|
|
12
12
|
import type * as WorkerThreads from "node:worker_threads";
|
package/dist/dts/Worker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Worker.d.ts","sourceRoot":"","sources":["../../src/Worker.ts"],"names":[],"mappings":";AAAA;;;;GAIG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,yBAAyB,CAAA;AACtD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Worker.d.ts","sourceRoot":"","sources":["../../src/Worker.ts"],"names":[],"mappings":";AAAA;;;;GAIG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,yBAAyB,CAAA;AACtD,OAAO,KAAK,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,KAAK,aAAa,MAAM,qBAAqB,CAAA;AAGzD;;GAEG;AACH,cAAc,yBAAyB,CAAA;AAEvC;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC7B,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,KACxD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,GAAG,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAqB,CAAA;AAE7G;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EACvC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EACjD,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,KACxD,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAA0B,CAAA;AAE5D;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,aAAa,CAAyB,CAAA;AAElG;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,cAAc,CAAwB,CAAA"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { WorkerError } from "@effect/platform/WorkerError";
|
|
7
7
|
import type * as Runner from "@effect/platform/WorkerRunner";
|
|
8
|
-
import type
|
|
8
|
+
import type * as Effect from "effect/Effect";
|
|
9
9
|
import type * as Layer from "effect/Layer";
|
|
10
10
|
import type * as Scope from "effect/Scope";
|
|
11
11
|
import type * as Stream from "effect/Stream";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkerRunner.d.ts","sourceRoot":"","sources":["../../src/WorkerRunner.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,KAAK,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAC5D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"WorkerRunner.d.ts","sourceRoot":"","sources":["../../src/WorkerRunner.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,KAAK,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAC5D,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAG5C;;GAEG;AACH,cAAc,+BAA+B,CAAA;AAE7C;;;GAGG;AACH,eAAO,MAAM,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAC5B,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC/C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,KAC3C,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAiB,CAAA;AAEtE;;;GAGG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,cAAc,CAAkB,CAAA"}
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import * as Stream from "effect/Stream";
|
|
3
|
-
import type { IncomingHttpHeaders } from "node:http";
|
|
4
|
-
import type { Readable } from "node:stream";
|
|
5
|
-
export declare const stream: (source: Readable, headers: IncomingHttpHeaders) => Stream.Stream<never, FormData.FormDataError, FormData.Part>;
|
|
1
|
+
export {};
|
|
6
2
|
//# sourceMappingURL=formData.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formData.d.ts","sourceRoot":"","sources":["../../../../src/internal/http/formData.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formData.d.ts","sourceRoot":"","sources":["../../../../src/internal/http/formData.ts"],"names":[],"mappings":""}
|
|
@@ -13,4 +13,9 @@ export const stream = internal.stream;
|
|
|
13
13
|
* @category constructors
|
|
14
14
|
*/
|
|
15
15
|
export const formData = internal.formData;
|
|
16
|
+
/**
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
* @category conversions
|
|
19
|
+
*/
|
|
20
|
+
export const fileToReadable = internal.fileToReadable;
|
|
16
21
|
//# sourceMappingURL=FormData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormData.js","names":["internal","stream","formData"],"sources":["../../../src/Http/FormData.ts"],"sourcesContent":[null],"mappings":"AAaA,OAAO,KAAKA,QAAQ,MAAM,8BAA8B;AAExD;;;AAGA,cAAc,gCAAgC;AAE9C;;;;AAIA,OAAO,MAAMC,MAAM,GAGgDD,QAAQ,CAACC,MAAM;AAElF;;;;AAIA,OAAO,MAAMC,QAAQ,
|
|
1
|
+
{"version":3,"file":"FormData.js","names":["internal","stream","formData","fileToReadable"],"sources":["../../../src/Http/FormData.ts"],"sourcesContent":[null],"mappings":"AAaA,OAAO,KAAKA,QAAQ,MAAM,8BAA8B;AAExD;;;AAGA,cAAc,gCAAgC;AAE9C;;;;AAIA,OAAO,MAAMC,MAAM,GAGgDD,QAAQ,CAACC,MAAM;AAElF;;;;AAIA,OAAO,MAAMC,QAAQ,GAOjBF,QAAQ,CAACE,QAAQ;AAErB;;;;AAIA,OAAO,MAAMC,cAAc,GAAsCH,QAAQ,CAACG,cAAc"}
|
|
@@ -1,112 +1,85 @@
|
|
|
1
|
-
import * as FileSystem from "@effect/platform/FileSystem";
|
|
2
1
|
import * as FormData from "@effect/platform/Http/FormData";
|
|
3
|
-
import * as Path from "@effect/platform/Path";
|
|
4
|
-
import Busboy from "busboy";
|
|
5
|
-
import * as Chunk from "effect/Chunk";
|
|
6
2
|
import * as Effect from "effect/Effect";
|
|
7
|
-
import * as FiberRef from "effect/FiberRef";
|
|
8
3
|
import { pipe } from "effect/Function";
|
|
9
|
-
import * as Option from "effect/Option";
|
|
10
4
|
import * as Stream from "effect/Stream";
|
|
11
|
-
import
|
|
5
|
+
import { decodeField } from "multipasta";
|
|
6
|
+
import * as MP from "multipasta/node";
|
|
7
|
+
import * as NFS from "node:fs";
|
|
12
8
|
import * as NodeStreamP from "node:stream/promises";
|
|
13
|
-
import * as NodeStream from "
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
})), busboy => Effect.sync(() => {
|
|
30
|
-
busboy.removeAllListeners();
|
|
31
|
-
if (!busboy.closed) {
|
|
32
|
-
busboy.destroy();
|
|
33
|
-
}
|
|
34
|
-
}))), Effect.map(({
|
|
35
|
-
busboy,
|
|
36
|
-
fieldMimeTypes
|
|
37
|
-
}) => Stream.mapEffect(Stream.async(emit => {
|
|
38
|
-
busboy.on("field", (name, value, info) => {
|
|
39
|
-
if (info.valueTruncated) {
|
|
40
|
-
emit.fail(FormData.FormDataError("FieldTooLarge", new Error("maxFieldSize exceeded")));
|
|
41
|
-
} else {
|
|
42
|
-
emit.single(new FieldImpl(name, info.mimeType, value));
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
busboy.on("file", (name, stream, info) => {
|
|
46
|
-
stream.once("limit", () => {
|
|
47
|
-
emit.fail(FormData.FormDataError("FileTooLarge", new Error("maxFileSize exceeded")));
|
|
48
|
-
});
|
|
49
|
-
emit.single(new FileImpl(name, info.filename, info.mimeType, NodeStream.fromReadable(() => stream, error => FormData.FormDataError("InternalError", error)), stream));
|
|
50
|
-
});
|
|
51
|
-
busboy.on("error", _ => {
|
|
52
|
-
emit.fail(FormData.FormDataError("InternalError", _));
|
|
53
|
-
});
|
|
54
|
-
busboy.on("finish", () => {
|
|
55
|
-
emit.end();
|
|
56
|
-
});
|
|
57
|
-
source.pipe(busboy);
|
|
58
|
-
}), part => part._tag === "File" && Chunk.some(fieldMimeTypes, _ => part.contentType.includes(_)) ? Effect.map(NodeStream.toString(() => part.source, {
|
|
59
|
-
onFailure: error => FormData.FormDataError("InternalError", error)
|
|
60
|
-
}), content => new FieldImpl(part.key, part.contentType, content)) : Effect.succeed(part))), Stream.unwrapScoped);
|
|
9
|
+
import * as NodeStream from "../stream.js";
|
|
10
|
+
/** @internal */
|
|
11
|
+
export const stream = (source, headers) => pipe(FormData.makeConfig(headers), Effect.map(config => NodeStream.fromReadable(() => {
|
|
12
|
+
const parser = MP.make(config);
|
|
13
|
+
source.pipe(parser);
|
|
14
|
+
return parser;
|
|
15
|
+
}, error => convertError(error))), Stream.unwrap, Stream.map(convertPart));
|
|
16
|
+
/** @internal */
|
|
17
|
+
export const formData = (source, headers) => FormData.formData(stream(source, headers), (path, file) => Effect.tryPromise({
|
|
18
|
+
try: signal => NodeStreamP.pipeline(file.file, NFS.createWriteStream(path), {
|
|
19
|
+
signal
|
|
20
|
+
}),
|
|
21
|
+
catch: error => FormData.FormDataError("InternalError", error)
|
|
22
|
+
}));
|
|
23
|
+
const convertPart = part => part._tag === "Field" ? new FieldImpl(part.info, part.value) : new FileImpl(part);
|
|
61
24
|
class FieldImpl {
|
|
25
|
+
[FormData.TypeId];
|
|
26
|
+
_tag = "Field";
|
|
62
27
|
key;
|
|
63
28
|
contentType;
|
|
64
29
|
value;
|
|
65
|
-
|
|
66
|
-
_tag = "Field";
|
|
67
|
-
constructor(key, contentType, value) {
|
|
68
|
-
this.key = key;
|
|
69
|
-
this.contentType = contentType;
|
|
70
|
-
this.value = value;
|
|
30
|
+
constructor(info, value) {
|
|
71
31
|
this[FormData.TypeId] = FormData.TypeId;
|
|
32
|
+
this.key = info.name;
|
|
33
|
+
this.contentType = info.contentType;
|
|
34
|
+
this.value = decodeField(info, value);
|
|
72
35
|
}
|
|
73
36
|
}
|
|
74
37
|
class FileImpl {
|
|
38
|
+
file;
|
|
39
|
+
_tag = "File";
|
|
40
|
+
[FormData.TypeId];
|
|
75
41
|
key;
|
|
76
42
|
name;
|
|
77
43
|
contentType;
|
|
78
44
|
content;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
_tag = "File";
|
|
82
|
-
constructor(key, name, contentType, content, source) {
|
|
83
|
-
this.key = key;
|
|
84
|
-
this.name = name;
|
|
85
|
-
this.contentType = contentType;
|
|
86
|
-
this.content = content;
|
|
87
|
-
this.source = source;
|
|
45
|
+
constructor(file) {
|
|
46
|
+
this.file = file;
|
|
88
47
|
this[FormData.TypeId] = FormData.TypeId;
|
|
48
|
+
this.key = file.info.name;
|
|
49
|
+
this.name = file.filename ?? file.info.name;
|
|
50
|
+
this.contentType = file.info.contentType;
|
|
51
|
+
this.content = NodeStream.fromReadable(() => file, error => FormData.FormDataError("InternalError", error));
|
|
89
52
|
}
|
|
90
53
|
}
|
|
91
54
|
/** @internal */
|
|
92
|
-
export const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
55
|
+
export const fileToReadable = file => file.file;
|
|
56
|
+
function convertError(error) {
|
|
57
|
+
switch (error._tag) {
|
|
58
|
+
case "ReachedLimit":
|
|
59
|
+
{
|
|
60
|
+
switch (error.limit) {
|
|
61
|
+
case "MaxParts":
|
|
62
|
+
{
|
|
63
|
+
return FormData.FormDataError("TooManyParts", error);
|
|
64
|
+
}
|
|
65
|
+
case "MaxFieldSize":
|
|
66
|
+
{
|
|
67
|
+
return FormData.FormDataError("FieldTooLarge", error);
|
|
68
|
+
}
|
|
69
|
+
case "MaxPartSize":
|
|
70
|
+
{
|
|
71
|
+
return FormData.FormDataError("FileTooLarge", error);
|
|
72
|
+
}
|
|
73
|
+
case "MaxTotalSize":
|
|
74
|
+
{
|
|
75
|
+
return FormData.FormDataError("BodyTooLarge", error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
default:
|
|
80
|
+
{
|
|
81
|
+
return FormData.FormDataError("Parse", error);
|
|
82
|
+
}
|
|
96
83
|
}
|
|
97
|
-
|
|
98
|
-
const path = path_.join(dir, file.name);
|
|
99
|
-
const blob = "Bun" in globalThis ? globalThis.Bun.file(path, {
|
|
100
|
-
type: file.contentType
|
|
101
|
-
}) : new Blob([], {
|
|
102
|
-
type: file.contentType
|
|
103
|
-
});
|
|
104
|
-
formData.append(part.key, blob, path);
|
|
105
|
-
return Effect.as(Effect.tryPromise({
|
|
106
|
-
try: signal => NodeStreamP.pipeline(file.source, NodeFs.createWriteStream(path), {
|
|
107
|
-
signal
|
|
108
|
-
}),
|
|
109
|
-
catch: error => FormData.FormDataError("InternalError", error)
|
|
110
|
-
}), formData);
|
|
111
|
-
}));
|
|
84
|
+
}
|
|
112
85
|
//# sourceMappingURL=formData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formData.js","names":["
|
|
1
|
+
{"version":3,"file":"formData.js","names":["FormData","Effect","pipe","Stream","decodeField","MP","NFS","NodeStreamP","NodeStream","stream","source","headers","makeConfig","map","config","fromReadable","parser","make","error","convertError","unwrap","convertPart","formData","path","file","tryPromise","try","signal","pipeline","createWriteStream","catch","FormDataError","part","_tag","FieldImpl","info","value","FileImpl","TypeId","key","contentType","constructor","name","content","filename","fileToReadable","limit"],"sources":["../../../../src/internal/http/formData.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,QAAQ,MAAM,gCAAgC;AAC1D,OAAO,KAAKC,MAAM,MAAM,eAAe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cAAc,GAAIrB,IAAmB,IAAgBA,IAAiB,CAACA,IAAI;AAExF,SAASL,YAAYA,CAACD,KAAqB;EACzC,QAAQA,KAAK,CAACe,IAAI;IAChB,KAAK,cAAc;MAAE;QACnB,QAAQf,KAAK,CAAC4B,KAAK;UACjB,KAAK,UAAU;YAAE;cACf,OAAO9C,QAAQ,CAAC+B,aAAa,CAAC,cAAc,EAAEb,KAAK,CAAC;;UAEtD,KAAK,cAAc;YAAE;cACnB,OAAOlB,QAAQ,CAAC+B,aAAa,CAAC,eAAe,EAAEb,KAAK,CAAC;;UAEvD,KAAK,aAAa;YAAE;cAClB,OAAOlB,QAAQ,CAAC+B,aAAa,CAAC,cAAc,EAAEb,KAAK,CAAC;;UAEtD,KAAK,cAAc;YAAE;cACnB,OAAOlB,QAAQ,CAAC+B,aAAa,CAAC,cAAc,EAAEb,KAAK,CAAC;;;;IAI1D;MAAS;QACP,OAAOlB,QAAQ,CAAC+B,aAAa,CAAC,OAAO,EAAEb,KAAK,CAAC;;;AAGnD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/platform-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.1",
|
|
4
4
|
"description": "Unified interfaces for common platform-specific services",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"sideEffects": false,
|
|
11
11
|
"author": "Effect contributors",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"busboy": "^1.6.0",
|
|
14
13
|
"mime": "^3.0.0",
|
|
15
|
-
"
|
|
14
|
+
"multipasta": "^0.1.11",
|
|
15
|
+
"@effect/platform": "0.29.1"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"effect": "2.0.0-next.54"
|
package/src/Http/FormData.ts
CHANGED
|
@@ -34,5 +34,14 @@ export const stream: (
|
|
|
34
34
|
export const formData: (
|
|
35
35
|
source: Readable,
|
|
36
36
|
headers: IncomingHttpHeaders
|
|
37
|
-
) => Effect.Effect<
|
|
38
|
-
|
|
37
|
+
) => Effect.Effect<
|
|
38
|
+
FileSystem.FileSystem | Path.Path | Scope.Scope,
|
|
39
|
+
FormData.FormDataError,
|
|
40
|
+
FormData.PersistedFormData
|
|
41
|
+
> = internal.formData
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @since 1.0.0
|
|
45
|
+
* @category conversions
|
|
46
|
+
*/
|
|
47
|
+
export const fileToReadable: (file: FormData.File) => Readable = internal.fileToReadable
|
package/src/Worker.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Also includes exports from [`@effect/platform/Worker`](https://effect-ts.github.io/platform/platform/Worker.ts.html).
|
|
5
5
|
*/
|
|
6
6
|
import type * as Worker from "@effect/platform/Worker"
|
|
7
|
-
import type { Effect } from "effect"
|
|
8
7
|
import type * as Context from "effect/Context"
|
|
8
|
+
import type * as Effect from "effect/Effect"
|
|
9
9
|
import type * as Layer from "effect/Layer"
|
|
10
10
|
import type * as Scope from "effect/Scope"
|
|
11
11
|
import type * as WorkerThreads from "node:worker_threads"
|
package/src/WorkerRunner.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { WorkerError } from "@effect/platform/WorkerError"
|
|
7
7
|
import type * as Runner from "@effect/platform/WorkerRunner"
|
|
8
|
-
import type
|
|
8
|
+
import type * as Effect from "effect/Effect"
|
|
9
9
|
import type * as Layer from "effect/Layer"
|
|
10
10
|
import type * as Scope from "effect/Scope"
|
|
11
11
|
import type * as Stream from "effect/Stream"
|
|
@@ -1,168 +1,107 @@
|
|
|
1
|
-
import * as FileSystem from "@effect/platform/FileSystem"
|
|
2
1
|
import * as FormData from "@effect/platform/Http/FormData"
|
|
3
|
-
import * as Path from "@effect/platform/Path"
|
|
4
|
-
import Busboy from "busboy"
|
|
5
|
-
import * as Chunk from "effect/Chunk"
|
|
6
2
|
import * as Effect from "effect/Effect"
|
|
7
|
-
import * as FiberRef from "effect/FiberRef"
|
|
8
3
|
import { pipe } from "effect/Function"
|
|
9
|
-
import * as Option from "effect/Option"
|
|
10
4
|
import * as Stream from "effect/Stream"
|
|
11
|
-
import
|
|
5
|
+
import type { MultipartError, PartInfo } from "multipasta"
|
|
6
|
+
import { decodeField } from "multipasta"
|
|
7
|
+
import * as MP from "multipasta/node"
|
|
8
|
+
import * as NFS from "node:fs"
|
|
12
9
|
import type { IncomingHttpHeaders } from "node:http"
|
|
13
10
|
import type { Readable } from "node:stream"
|
|
14
11
|
import * as NodeStreamP from "node:stream/promises"
|
|
15
|
-
import * as NodeStream from "
|
|
12
|
+
import * as NodeStream from "../stream.js"
|
|
16
13
|
|
|
14
|
+
/** @internal */
|
|
17
15
|
export const stream = (
|
|
18
16
|
source: Readable,
|
|
19
17
|
headers: IncomingHttpHeaders
|
|
20
18
|
): Stream.Stream<never, FormData.FormDataError, FormData.Part> =>
|
|
21
19
|
pipe(
|
|
22
|
-
|
|
23
|
-
Effect.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Effect.acquireRelease(
|
|
31
|
-
Effect.sync(
|
|
32
|
-
() =>
|
|
33
|
-
Busboy({
|
|
34
|
-
headers,
|
|
35
|
-
limits: {
|
|
36
|
-
parts: Option.getOrUndefined(Option.map(maxParts, Number)),
|
|
37
|
-
files: Option.getOrUndefined(Option.map(maxFiles, Number)),
|
|
38
|
-
fields: Option.getOrUndefined(Option.map(maxFields, Number)),
|
|
39
|
-
fieldSize: Number(maxFieldSize),
|
|
40
|
-
fileSize: Option.getOrUndefined(Option.map(maxFileSize, Number))
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
),
|
|
44
|
-
(busboy) =>
|
|
45
|
-
Effect.sync(() => {
|
|
46
|
-
busboy.removeAllListeners()
|
|
47
|
-
if (!busboy.closed) {
|
|
48
|
-
busboy.destroy()
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
)),
|
|
52
|
-
Effect.map(({ busboy, fieldMimeTypes }) =>
|
|
53
|
-
Stream.mapEffect(
|
|
54
|
-
Stream.async<never, FormData.FormDataError, FieldImpl | FileImpl>((emit) => {
|
|
55
|
-
busboy.on("field", (name, value, info) => {
|
|
56
|
-
if (info.valueTruncated) {
|
|
57
|
-
emit.fail(FormData.FormDataError("FieldTooLarge", new Error("maxFieldSize exceeded")))
|
|
58
|
-
} else {
|
|
59
|
-
emit.single(new FieldImpl(name, info.mimeType, value))
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
busboy.on("file", (name, stream, info) => {
|
|
64
|
-
stream.once("limit", () => {
|
|
65
|
-
emit.fail(FormData.FormDataError("FileTooLarge", new Error("maxFileSize exceeded")))
|
|
66
|
-
})
|
|
67
|
-
emit.single(
|
|
68
|
-
new FileImpl(
|
|
69
|
-
name,
|
|
70
|
-
info.filename,
|
|
71
|
-
info.mimeType,
|
|
72
|
-
NodeStream.fromReadable(() => stream, (error) => FormData.FormDataError("InternalError", error)),
|
|
73
|
-
stream
|
|
74
|
-
)
|
|
75
|
-
)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
busboy.on("error", (_) => {
|
|
79
|
-
emit.fail(FormData.FormDataError("InternalError", _))
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
busboy.on("finish", () => {
|
|
83
|
-
emit.end()
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
source.pipe(busboy)
|
|
87
|
-
}),
|
|
88
|
-
(part) =>
|
|
89
|
-
part._tag === "File" && Chunk.some(fieldMimeTypes, (_) => part.contentType.includes(_)) ?
|
|
90
|
-
Effect.map(
|
|
91
|
-
NodeStream.toString(() => part.source, {
|
|
92
|
-
onFailure: (error) => FormData.FormDataError("InternalError", error)
|
|
93
|
-
}),
|
|
94
|
-
(content) => new FieldImpl(part.key, part.contentType, content)
|
|
95
|
-
)
|
|
96
|
-
: Effect.succeed(part)
|
|
97
|
-
)
|
|
20
|
+
FormData.makeConfig(headers as any),
|
|
21
|
+
Effect.map(
|
|
22
|
+
(config) =>
|
|
23
|
+
NodeStream.fromReadable<FormData.FormDataError, MP.Part>(() => {
|
|
24
|
+
const parser = MP.make(config)
|
|
25
|
+
source.pipe(parser)
|
|
26
|
+
return parser
|
|
27
|
+
}, (error) => convertError(error as any))
|
|
98
28
|
),
|
|
99
|
-
Stream.
|
|
29
|
+
Stream.unwrap,
|
|
30
|
+
Stream.map(convertPart)
|
|
100
31
|
)
|
|
101
32
|
|
|
33
|
+
/** @internal */
|
|
34
|
+
export const formData = (
|
|
35
|
+
source: Readable,
|
|
36
|
+
headers: IncomingHttpHeaders
|
|
37
|
+
) =>
|
|
38
|
+
FormData.formData(stream(source, headers), (path, file) =>
|
|
39
|
+
Effect.tryPromise({
|
|
40
|
+
try: (signal) => NodeStreamP.pipeline((file as FileImpl).file, NFS.createWriteStream(path), { signal }),
|
|
41
|
+
catch: (error) => FormData.FormDataError("InternalError", error)
|
|
42
|
+
}))
|
|
43
|
+
|
|
44
|
+
const convertPart = (part: MP.Part): FormData.Part =>
|
|
45
|
+
part._tag === "Field" ? new FieldImpl(part.info, part.value) : new FileImpl(part)
|
|
46
|
+
|
|
102
47
|
class FieldImpl implements FormData.Field {
|
|
103
48
|
readonly [FormData.TypeId]: FormData.TypeId
|
|
104
49
|
readonly _tag = "Field"
|
|
50
|
+
readonly key: string
|
|
51
|
+
readonly contentType: string
|
|
52
|
+
readonly value: string
|
|
53
|
+
|
|
105
54
|
constructor(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
readonly value: string
|
|
55
|
+
info: PartInfo,
|
|
56
|
+
value: Uint8Array
|
|
109
57
|
) {
|
|
110
58
|
this[FormData.TypeId] = FormData.TypeId
|
|
59
|
+
this.key = info.name
|
|
60
|
+
this.contentType = info.contentType
|
|
61
|
+
this.value = decodeField(info, value)
|
|
111
62
|
}
|
|
112
63
|
}
|
|
113
64
|
|
|
114
65
|
class FileImpl implements FormData.File {
|
|
115
|
-
readonly [FormData.TypeId]: FormData.TypeId
|
|
116
66
|
readonly _tag = "File"
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
) {
|
|
67
|
+
readonly [FormData.TypeId]: FormData.TypeId
|
|
68
|
+
readonly key: string
|
|
69
|
+
readonly name: string
|
|
70
|
+
readonly contentType: string
|
|
71
|
+
readonly content: Stream.Stream<never, FormData.FormDataError, Uint8Array>
|
|
72
|
+
|
|
73
|
+
constructor(readonly file: MP.FileStream) {
|
|
124
74
|
this[FormData.TypeId] = FormData.TypeId
|
|
75
|
+
this.key = file.info.name
|
|
76
|
+
this.name = file.filename ?? file.info.name
|
|
77
|
+
this.contentType = file.info.contentType
|
|
78
|
+
this.content = NodeStream.fromReadable(() => file, (error) => FormData.FormDataError("InternalError", error))
|
|
125
79
|
}
|
|
126
80
|
}
|
|
127
81
|
|
|
128
82
|
/** @internal */
|
|
129
|
-
export const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
(error) => FormData.FormDataError("InternalError", error)
|
|
138
|
-
),
|
|
139
|
-
Path.Path
|
|
140
|
-
]),
|
|
141
|
-
([dir, path_]) =>
|
|
142
|
-
Stream.runFoldEffect(
|
|
143
|
-
stream(source, headers),
|
|
144
|
-
new globalThis.FormData(),
|
|
145
|
-
(formData, part) => {
|
|
146
|
-
if (part._tag === "Field") {
|
|
147
|
-
formData.append(part.key, part.value)
|
|
148
|
-
return Effect.succeed(formData)
|
|
149
|
-
}
|
|
150
|
-
const file = part as FileImpl
|
|
151
|
-
const path = path_.join(dir, file.name)
|
|
152
|
-
const blob = "Bun" in globalThis ?
|
|
153
|
-
(globalThis as any).Bun.file(path, { type: file.contentType })
|
|
154
|
-
: new Blob([], { type: file.contentType })
|
|
155
|
-
formData.append(part.key, blob, path)
|
|
156
|
-
return Effect.as(
|
|
157
|
-
Effect.tryPromise({
|
|
158
|
-
try: (signal) =>
|
|
159
|
-
NodeStreamP.pipeline(file.source, NodeFs.createWriteStream(path), {
|
|
160
|
-
signal
|
|
161
|
-
}),
|
|
162
|
-
catch: (error) => FormData.FormDataError("InternalError", error)
|
|
163
|
-
}),
|
|
164
|
-
formData
|
|
165
|
-
)
|
|
83
|
+
export const fileToReadable = (file: FormData.File): Readable => (file as FileImpl).file
|
|
84
|
+
|
|
85
|
+
function convertError(error: MultipartError): FormData.FormDataError {
|
|
86
|
+
switch (error._tag) {
|
|
87
|
+
case "ReachedLimit": {
|
|
88
|
+
switch (error.limit) {
|
|
89
|
+
case "MaxParts": {
|
|
90
|
+
return FormData.FormDataError("TooManyParts", error)
|
|
166
91
|
}
|
|
167
|
-
|
|
168
|
-
|
|
92
|
+
case "MaxFieldSize": {
|
|
93
|
+
return FormData.FormDataError("FieldTooLarge", error)
|
|
94
|
+
}
|
|
95
|
+
case "MaxPartSize": {
|
|
96
|
+
return FormData.FormDataError("FileTooLarge", error)
|
|
97
|
+
}
|
|
98
|
+
case "MaxTotalSize": {
|
|
99
|
+
return FormData.FormDataError("BodyTooLarge", error)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
default: {
|
|
104
|
+
return FormData.FormDataError("Parse", error)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -211,13 +211,13 @@ class ServerRequestImpl extends IncomingMessageImpl<Error.RequestError> implemen
|
|
|
211
211
|
| Effect.Effect<
|
|
212
212
|
Scope.Scope | FileSystem.FileSystem | Path.Path,
|
|
213
213
|
FormData.FormDataError,
|
|
214
|
-
|
|
214
|
+
FormData.PersistedFormData
|
|
215
215
|
>
|
|
216
216
|
| undefined
|
|
217
217
|
get formData(): Effect.Effect<
|
|
218
218
|
Scope.Scope | FileSystem.FileSystem | Path.Path,
|
|
219
219
|
FormData.FormDataError,
|
|
220
|
-
|
|
220
|
+
FormData.PersistedFormData
|
|
221
221
|
> {
|
|
222
222
|
if (this.formDataEffect) {
|
|
223
223
|
return this.formDataEffect
|