seroval-plugins 1.3.2 → 1.4.0
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/development/web.cjs +47 -39
- package/dist/cjs/development/web.cjs.map +2 -2
- package/dist/cjs/production/web.cjs +1 -1
- package/dist/esm/development/web.mjs +47 -39
- package/dist/esm/development/web.mjs.map +2 -2
- package/dist/esm/production/web.mjs +1 -1
- package/dist/types/web/abort-signal.d.ts +1 -16
- package/dist/types/web/abort-signal.d.ts.map +1 -1
- package/dist/types/web/blob.d.ts +1 -6
- package/dist/types/web/blob.d.ts.map +1 -1
- package/dist/types/web/custom-event.d.ts +1 -6
- package/dist/types/web/custom-event.d.ts.map +1 -1
- package/dist/types/web/dom-exception.d.ts +1 -6
- package/dist/types/web/dom-exception.d.ts.map +1 -1
- package/dist/types/web/event.d.ts +1 -6
- package/dist/types/web/event.d.ts.map +1 -1
- package/dist/types/web/file.d.ts +1 -7
- package/dist/types/web/file.d.ts.map +1 -1
- package/dist/types/web/form-data.d.ts +1 -6
- package/dist/types/web/form-data.d.ts.map +1 -1
- package/dist/types/web/headers.d.ts +1 -2
- package/dist/types/web/headers.d.ts.map +1 -1
- package/dist/types/web/image-data.d.ts +1 -8
- package/dist/types/web/image-data.d.ts.map +1 -1
- package/dist/types/web/readable-stream.d.ts +1 -6
- package/dist/types/web/readable-stream.d.ts.map +1 -1
- package/dist/types/web/request.d.ts +1 -6
- package/dist/types/web/request.d.ts.map +1 -1
- package/dist/types/web/response.d.ts +1 -6
- package/dist/types/web/response.d.ts.map +1 -1
- package/dist/types/web/url-search-params.d.ts +1 -2
- package/dist/types/web/url-search-params.d.ts.map +1 -1
- package/dist/types/web/url.d.ts +1 -2
- package/dist/types/web/url.d.ts.map +1 -1
- package/package.json +17 -19
- package/web/form-data.ts +19 -13
- package/web/image-data.ts +1 -1
- package/web/readable-stream.ts +27 -31
- package/web/request.ts +9 -2
- package/web/response.ts +6 -2
package/web/form-data.ts
CHANGED
|
@@ -6,7 +6,6 @@ type FormDataInit = [key: string, value: FormDataEntryValue][];
|
|
|
6
6
|
|
|
7
7
|
function convertFormData(instance: FormData): FormDataInit {
|
|
8
8
|
const items: FormDataInit = [];
|
|
9
|
-
// biome-ignore lint/complexity/noForEach: <explanation>
|
|
10
9
|
instance.forEach((value, key) => {
|
|
11
10
|
items.push([key, value]);
|
|
12
11
|
});
|
|
@@ -15,6 +14,20 @@ function convertFormData(instance: FormData): FormDataInit {
|
|
|
15
14
|
|
|
16
15
|
const FORM_DATA_FACTORY = {};
|
|
17
16
|
|
|
17
|
+
const FORM_DATA_FACTORY_CONSTRUCTOR = (
|
|
18
|
+
e: [key: string, value: FormDataEntryValue][],
|
|
19
|
+
f = new FormData(),
|
|
20
|
+
i = 0,
|
|
21
|
+
s = e.length,
|
|
22
|
+
t?: [key: string, value: FormDataEntryValue],
|
|
23
|
+
) => {
|
|
24
|
+
for (; i < s; i++) {
|
|
25
|
+
t = e[i];
|
|
26
|
+
f.append(t[0], t[1]);
|
|
27
|
+
}
|
|
28
|
+
return f;
|
|
29
|
+
};
|
|
30
|
+
|
|
18
31
|
const FormDataFactoryPlugin = /* @__PURE__ */ createPlugin<object, undefined>({
|
|
19
32
|
tag: 'seroval-plugins/web/FormDataFactory',
|
|
20
33
|
test(value) {
|
|
@@ -31,11 +44,8 @@ const FormDataFactoryPlugin = /* @__PURE__ */ createPlugin<object, undefined>({
|
|
|
31
44
|
return undefined;
|
|
32
45
|
},
|
|
33
46
|
},
|
|
34
|
-
serialize(
|
|
35
|
-
return
|
|
36
|
-
['e', 'f', 'i', 's', 't'],
|
|
37
|
-
'f=new FormData;for(i=0,s=e.length;i<s;i++)f.append((t=e[i])[0],t[1]);return f',
|
|
38
|
-
);
|
|
47
|
+
serialize() {
|
|
48
|
+
return FORM_DATA_FACTORY_CONSTRUCTOR.toString();
|
|
39
49
|
},
|
|
40
50
|
deserialize() {
|
|
41
51
|
return FORM_DATA_FACTORY;
|
|
@@ -86,13 +96,9 @@ const FormDataPlugin = /* @__PURE__ */ createPlugin<FormData, FormDataNode>({
|
|
|
86
96
|
);
|
|
87
97
|
},
|
|
88
98
|
deserialize(node, ctx) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const entry = entries[i];
|
|
93
|
-
instance.append(entry[0], entry[1]);
|
|
94
|
-
}
|
|
95
|
-
return instance;
|
|
99
|
+
return FORM_DATA_FACTORY_CONSTRUCTOR(
|
|
100
|
+
ctx.deserialize(node.entries) as FormDataInit,
|
|
101
|
+
);
|
|
96
102
|
},
|
|
97
103
|
});
|
|
98
104
|
|
package/web/image-data.ts
CHANGED
|
@@ -63,7 +63,7 @@ const ImageDataPlugin = /* @__PURE__ */ createPlugin<ImageData, ImageDataNode>({
|
|
|
63
63
|
},
|
|
64
64
|
deserialize(node, ctx) {
|
|
65
65
|
return new ImageData(
|
|
66
|
-
ctx.deserialize(node.data) as Uint8ClampedArray
|
|
66
|
+
ctx.deserialize(node.data) as Uint8ClampedArray<ArrayBuffer>,
|
|
67
67
|
ctx.deserialize(node.width) as number,
|
|
68
68
|
ctx.deserialize(node.height) as number,
|
|
69
69
|
ctx.deserialize(node.options) as ImageDataSettings,
|
package/web/readable-stream.ts
CHANGED
|
@@ -3,6 +3,30 @@ import { createPlugin, createStream } from 'seroval';
|
|
|
3
3
|
|
|
4
4
|
const READABLE_STREAM_FACTORY = {};
|
|
5
5
|
|
|
6
|
+
const READABLE_STREAM_FACTORY_CONSTRUCTOR = (stream: Stream<unknown>) => new ReadableStream({
|
|
7
|
+
start: (controller) => {
|
|
8
|
+
stream.on({
|
|
9
|
+
next: (value) => {
|
|
10
|
+
try {
|
|
11
|
+
controller.enqueue(value)
|
|
12
|
+
} catch (_error) {
|
|
13
|
+
// no-op
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
throw: (value) => {
|
|
17
|
+
controller.error(value);
|
|
18
|
+
},
|
|
19
|
+
return: () => {
|
|
20
|
+
try {
|
|
21
|
+
controller.close();
|
|
22
|
+
} catch (_error) {
|
|
23
|
+
// no-op
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
6
30
|
const ReadableStreamFactoryPlugin = /* @__PURE__ */ createPlugin<
|
|
7
31
|
object,
|
|
8
32
|
undefined
|
|
@@ -22,22 +46,8 @@ const ReadableStreamFactoryPlugin = /* @__PURE__ */ createPlugin<
|
|
|
22
46
|
return undefined;
|
|
23
47
|
},
|
|
24
48
|
},
|
|
25
|
-
serialize(
|
|
26
|
-
return
|
|
27
|
-
['d'],
|
|
28
|
-
'new ReadableStream({start:' +
|
|
29
|
-
ctx.createEffectfulFunction(
|
|
30
|
-
['c'],
|
|
31
|
-
'd.on({next:' +
|
|
32
|
-
ctx.createEffectfulFunction(['v'], 'c.enqueue(v)') +
|
|
33
|
-
',throw:' +
|
|
34
|
-
ctx.createEffectfulFunction(['v'], 'c.error(v)') +
|
|
35
|
-
',return:' +
|
|
36
|
-
ctx.createEffectfulFunction([], 'c.close()') +
|
|
37
|
-
'})',
|
|
38
|
-
) +
|
|
39
|
-
'})',
|
|
40
|
-
);
|
|
49
|
+
serialize() {
|
|
50
|
+
return READABLE_STREAM_FACTORY_CONSTRUCTOR.toString();
|
|
41
51
|
},
|
|
42
52
|
deserialize() {
|
|
43
53
|
return READABLE_STREAM_FACTORY;
|
|
@@ -118,21 +128,7 @@ const ReadableStreamPlugin = /* @__PURE__ */ createPlugin<
|
|
|
118
128
|
},
|
|
119
129
|
deserialize(node, ctx) {
|
|
120
130
|
const stream = ctx.deserialize(node.stream) as Stream<any>;
|
|
121
|
-
return
|
|
122
|
-
start(controller): void {
|
|
123
|
-
stream.on({
|
|
124
|
-
next(value) {
|
|
125
|
-
controller.enqueue(value);
|
|
126
|
-
},
|
|
127
|
-
throw(value) {
|
|
128
|
-
controller.error(value);
|
|
129
|
-
},
|
|
130
|
-
return() {
|
|
131
|
-
controller.close();
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
},
|
|
135
|
-
});
|
|
131
|
+
return READABLE_STREAM_FACTORY_CONSTRUCTOR(stream);
|
|
136
132
|
},
|
|
137
133
|
});
|
|
138
134
|
|
package/web/request.ts
CHANGED
|
@@ -43,7 +43,9 @@ const RequestPlugin = /* @__PURE__ */ createPlugin<Request, RequestNode>({
|
|
|
43
43
|
options: await ctx.parse(
|
|
44
44
|
createRequestOptions(
|
|
45
45
|
value,
|
|
46
|
-
value.body
|
|
46
|
+
value.body && !value.bodyUsed
|
|
47
|
+
? await value.clone().arrayBuffer()
|
|
48
|
+
: null,
|
|
47
49
|
),
|
|
48
50
|
),
|
|
49
51
|
};
|
|
@@ -51,7 +53,12 @@ const RequestPlugin = /* @__PURE__ */ createPlugin<Request, RequestNode>({
|
|
|
51
53
|
stream(value, ctx) {
|
|
52
54
|
return {
|
|
53
55
|
url: ctx.parse(value.url),
|
|
54
|
-
options: ctx.parse(
|
|
56
|
+
options: ctx.parse(
|
|
57
|
+
createRequestOptions(
|
|
58
|
+
value,
|
|
59
|
+
value.body && !value.bodyUsed ? value.clone().body : null,
|
|
60
|
+
),
|
|
61
|
+
),
|
|
55
62
|
};
|
|
56
63
|
},
|
|
57
64
|
},
|
package/web/response.ts
CHANGED
|
@@ -29,14 +29,18 @@ const ResponsePlugin = /* @__PURE__ */ createPlugin<Response, ResponseNode>({
|
|
|
29
29
|
async async(value, ctx) {
|
|
30
30
|
return {
|
|
31
31
|
body: await ctx.parse(
|
|
32
|
-
value.body
|
|
32
|
+
value.body && !value.bodyUsed
|
|
33
|
+
? await value.clone().arrayBuffer()
|
|
34
|
+
: null,
|
|
33
35
|
),
|
|
34
36
|
options: await ctx.parse(createResponseOptions(value)),
|
|
35
37
|
};
|
|
36
38
|
},
|
|
37
39
|
stream(value, ctx) {
|
|
38
40
|
return {
|
|
39
|
-
body: ctx.parse(
|
|
41
|
+
body: ctx.parse(
|
|
42
|
+
value.body && !value.bodyUsed ? value.clone().body : null,
|
|
43
|
+
),
|
|
40
44
|
options: ctx.parse(createResponseOptions(value)),
|
|
41
45
|
};
|
|
42
46
|
},
|