@metapages/metapage 1.9.2 → 1.9.3

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.
@@ -18,8 +18,8 @@ export type DataRefSerializedFile = DataRefSerializedBlob & {
18
18
  name: string;
19
19
  lastModified?: number;
20
20
  };
21
+ export declare const possiblySerializeValueToDataref: <T>(value: T) => Promise<string | T>;
22
+ export declare const possiblyDeserializeDatarefToValue: (value: any) => Promise<any>;
23
+ export declare const possiblyDeserializeDatarefToFile: (value: any) => Promise<File | undefined>;
21
24
  export declare const valueToFile: (value: any, fileName: string, options?: FilePropertyBag) => Promise<File>;
22
- export declare const possiblySerializeValueToDataref: <T>(value: T) => Promise<DataRefSerialized | T>;
23
- export declare const possiblyDeserializeDatarefToValue: (value: any) => any;
24
- export declare const possiblyDeserializeDatarefToFile: (value: any) => File | undefined;
25
25
  //# sourceMappingURL=data.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/metapage/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAS3C,eAAO,MAAM,eAAe,WAClB,iBAAiB,KACxB,QAAQ,iBAAiB,CAS3B,CAAC;AAOF,eAAO,MAAM,iBAAiB,WACpB,iBAAiB,KACxB,QAAQ,iBAAiB,CAW3B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAE9B,EAAE,EAAE,IAAI,CAAC;IAET,EAAE,EAAE,MAAM,CAAC;IAEX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,iBAAiB,GAAG;IAE5D,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,GAAG;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,qBAAqB,GAAG;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,WAAW,UACf,GAAG,YACA,MAAM,YACN,eAAe,KACxB,QAAQ,IAAI,CAgDd,CAAC;AAEF,eAAO,MAAM,+BAA+B,iDA2D3C,CAAC;AAEF,eAAO,MAAM,iCAAiC,UAAW,GAAG,KAAG,GAiD9D,CAAC;AAEF,eAAO,MAAM,gCAAgC,UACpC,GAAG,KACT,IAAI,GAAG,SAoDT,CAAC"}
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/metapage/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAkC3C,eAAO,MAAM,eAAe,WAClB,iBAAiB,KACxB,QAAQ,iBAAiB,CAa3B,CAAC;AAOF,eAAO,MAAM,iBAAiB,WACpB,iBAAiB,KACxB,QAAQ,iBAAiB,CAa3B,CAAC;AAGF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,IAAI,CAAC;IACT,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,iBAAiB,GAAG;IAC5D,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,GAAG;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,qBAAqB,GAAG;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAoBF,eAAO,MAAM,+BAA+B,sCAgC3C,CAAC;AASF,eAAO,MAAM,iCAAiC,UACrC,GAAG,KACT,QAAQ,GAAG,CAsBb,CAAC;AAMF,eAAO,MAAM,gCAAgC,UACpC,GAAG,KACT,QAAQ,IAAI,GAAG,SAAS,CAmB1B,CAAC;AAEF,eAAO,MAAM,WAAW,UACf,GAAG,YACA,MAAM,YACN,eAAe,KACxB,QAAQ,IAAI,CAoCd,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@metapages/metapage",
3
3
  "public": true,
4
- "version": "1.9.2",
4
+ "version": "1.9.3",
5
5
  "description": "Connect web pages together",
6
6
  "repository": "https://github.com/metapages/metapage",
7
7
  "homepage": "https://metapage.io/",
@@ -23,6 +23,7 @@
23
23
  ],
24
24
  "source": "src/index.ts",
25
25
  "dependencies": {
26
+ "@metapages/dataref": "^2.0.1",
26
27
  "@metapages/hash-query": "^0.9.8",
27
28
  "base64-arraybuffer": "^1.0.2",
28
29
  "compare-versions": "^6.1.1",
@@ -1,57 +1,85 @@
1
1
  import { MetaframeInputMap } from "./v0_4";
2
- import { encode, decode } from "base64-arraybuffer";
3
- import { create } from "mutative";
2
+ import { decode } from "base64-arraybuffer";
3
+ import {
4
+ typedArrayToDataUrl,
5
+ bufferToDataUrl,
6
+ dataUrlToBuffer,
7
+ dataUrlToTypedArray,
8
+ isDataUrl,
9
+ getParameters,
10
+ getMimeType,
11
+ type TypedArrayType,
12
+ } from "@metapages/dataref";
13
+
14
+ /** Cheap sync check: does this value need serialization? */
15
+ const needsSerialization = (value: any): boolean =>
16
+ value instanceof ArrayBuffer ||
17
+ value instanceof Blob || // File extends Blob, so this catches both
18
+ ArrayBuffer.isView(value);
19
+
20
+ /** Cheap sync check: does this value need deserialization? */
21
+ const needsDeserialization = (value: any): boolean => {
22
+ if (typeof value === "string") return value.startsWith("data:");
23
+ if (value && typeof value === "object") {
24
+ if (value._s === true && value._c) return true;
25
+ if (value.ref === "base64" && value.c) return true;
26
+ }
27
+ return false;
28
+ };
4
29
 
5
30
  /**
6
- * Modifies in place!!!
7
- * @param inputs
8
- * @returns
31
+ * Serialize all values in inputs (one level deep).
32
+ * Binary types (TypedArray, ArrayBuffer, Blob, File) become data URL strings.
33
+ * Returns the original object if nothing needs serialization.
9
34
  */
10
35
  export const serializeInputs = async (
11
36
  inputs: MetaframeInputMap,
12
37
  ): Promise<MetaframeInputMap> => {
13
- // only serialize one level deep
14
- return create<MetaframeInputMap>(inputs, async (draft: MetaframeInputMap) => {
15
- for (const key of Object.keys(inputs)) {
16
- const maybeNewObject = await possiblySerializeValueToDataref(inputs[key]);
17
- draft[key] = maybeNewObject;
18
- return draft;
19
- }
20
- });
38
+ const keys = Object.keys(inputs);
39
+ const keysToSerialize: string[] = [];
40
+ for (const key of keys) {
41
+ if (needsSerialization(inputs[key])) keysToSerialize.push(key);
42
+ }
43
+ if (keysToSerialize.length === 0) return inputs;
44
+
45
+ const result: MetaframeInputMap = { ...inputs };
46
+ for (const key of keysToSerialize) {
47
+ result[key] = await possiblySerializeValueToDataref(inputs[key]);
48
+ }
49
+ return result;
21
50
  };
22
51
 
23
52
  /**
24
- * Modifies in place!!!
25
- * @param inputs
26
- * @returns
53
+ * Deserialize all values in inputs (one level deep).
54
+ * Handles v2 data URLs, legacy metapage _s/_c format, and dataref v1 ref/c format.
55
+ * Returns the original object if nothing needs deserialization.
27
56
  */
28
57
  export const deserializeInputs = async (
29
58
  inputs: MetaframeInputMap,
30
59
  ): Promise<MetaframeInputMap> => {
31
- // only deserialize one level deep
32
- return create<MetaframeInputMap>(inputs, async (draft: MetaframeInputMap) => {
33
- for (const key of Object.keys(inputs)) {
34
- const maybeNewObject = await possiblyDeserializeDatarefToValue(
35
- inputs[key],
36
- );
37
- draft[key] = maybeNewObject;
38
- return draft;
39
- }
40
- });
60
+ const keys = Object.keys(inputs);
61
+ const keysToDeserialize: string[] = [];
62
+ for (const key of keys) {
63
+ if (needsDeserialization(inputs[key])) keysToDeserialize.push(key);
64
+ }
65
+ if (keysToDeserialize.length === 0) return inputs;
66
+
67
+ const result: MetaframeInputMap = { ...inputs };
68
+ for (const key of keysToDeserialize) {
69
+ result[key] = await possiblyDeserializeDatarefToValue(inputs[key]);
70
+ }
71
+ return result;
41
72
  };
42
73
 
74
+ // Legacy types kept for backwards-compatible deserialization
43
75
  export type DataRefSerialized = {
44
- // This means it's a serialized DataRef
45
76
  _s: true;
46
- // constructor
47
77
  _c: string;
48
- // value is base64 encoded
49
78
  value: string;
50
79
  size: number;
51
80
  };
52
81
 
53
82
  export type DataRefSerializedTypedArray = DataRefSerialized & {
54
- // Typed arrays are from ArrayBufferView
55
83
  byteLength: number;
56
84
  byteOffset: number;
57
85
  };
@@ -65,12 +93,124 @@ export type DataRefSerializedFile = DataRefSerializedBlob & {
65
93
  lastModified?: number;
66
94
  };
67
95
 
96
+ const TYPED_ARRAY_NAMES: Set<string> = new Set([
97
+ "Int8Array",
98
+ "Uint8Array",
99
+ "Uint8ClampedArray",
100
+ "Int16Array",
101
+ "Uint16Array",
102
+ "Int32Array",
103
+ "Uint32Array",
104
+ "Float32Array",
105
+ "Float64Array",
106
+ "BigInt64Array",
107
+ "BigUint64Array",
108
+ ]);
109
+
110
+ /**
111
+ * Serialize a value to a data URL string if it's a binary type.
112
+ * Non-binary values pass through unchanged.
113
+ */
114
+ export const possiblySerializeValueToDataref = async <T>(
115
+ value: T,
116
+ ): Promise<T | string> => {
117
+ if (
118
+ value instanceof Int8Array ||
119
+ value instanceof Uint8Array ||
120
+ value instanceof Uint8ClampedArray ||
121
+ value instanceof Int16Array ||
122
+ value instanceof Uint16Array ||
123
+ value instanceof Int32Array ||
124
+ value instanceof Uint32Array ||
125
+ value instanceof Float32Array ||
126
+ value instanceof Float64Array
127
+ ) {
128
+ return typedArrayToDataUrl(value, value.constructor.name as TypedArrayType);
129
+ } else if (value instanceof File) {
130
+ const arrayBuffer = await value.arrayBuffer();
131
+ const bytes = new Uint8Array(arrayBuffer);
132
+ const base64 = btoa(String.fromCharCode(...bytes));
133
+ const mimeType = value.type || "application/octet-stream";
134
+ const name = encodeURIComponent(value.name);
135
+ return `data:${mimeType};file=true;name=${name};lastModified=${value.lastModified};base64,${base64}`;
136
+ } else if (value instanceof Blob) {
137
+ const arrayBuffer = await value.arrayBuffer();
138
+ const bytes = new Uint8Array(arrayBuffer);
139
+ const base64 = btoa(String.fromCharCode(...bytes));
140
+ const mimeType = value.type || "application/octet-stream";
141
+ return `data:${mimeType};blob=true;base64,${base64}`;
142
+ } else if (value instanceof ArrayBuffer) {
143
+ return bufferToDataUrl(value);
144
+ }
145
+ return value;
146
+ };
147
+
148
+ /**
149
+ * Deserialize a value from any supported format:
150
+ * 1. v2 data URL strings (new format)
151
+ * 2. Legacy metapage format ({ _s: true, _c: "..." })
152
+ * 3. dataref v1 format ({ ref: "base64", c: "..." })
153
+ * 4. Anything else passes through unchanged
154
+ */
155
+ export const possiblyDeserializeDatarefToValue = async (
156
+ value: any,
157
+ ): Promise<any> => {
158
+ // 1. v2 data URL string
159
+ if (isDataUrl(value)) {
160
+ return deserializeDataUrl(value);
161
+ }
162
+
163
+ if (!value || typeof value !== "object") {
164
+ return value;
165
+ }
166
+
167
+ // 2. Legacy metapage format: { _s: true, _c: "ConstructorName", value: "base64..." }
168
+ if (value._s === true && value._c) {
169
+ return deserializeLegacyMetapage(value);
170
+ }
171
+
172
+ // 3. dataref v1 format: { ref: "base64", c: "ConstructorName", value: "base64..." }
173
+ if (value.ref === "base64" && value.c) {
174
+ return deserializeDatarefV1(value);
175
+ }
176
+
177
+ // 4. Pass through
178
+ return value;
179
+ };
180
+
181
+ /**
182
+ * Attempt to deserialize a value to a File. Returns undefined if the value
183
+ * is not a recognized serialized format.
184
+ */
185
+ export const possiblyDeserializeDatarefToFile = async (
186
+ value: any,
187
+ ): Promise<File | undefined> => {
188
+ const deserialized = await possiblyDeserializeDatarefToValue(value);
189
+ if (deserialized instanceof File) {
190
+ return deserialized;
191
+ }
192
+ if (deserialized instanceof Blob) {
193
+ return new File([deserialized], "file", { type: deserialized.type });
194
+ }
195
+ if (deserialized instanceof ArrayBuffer) {
196
+ return new File([deserialized], "file", {
197
+ type: "application/octet-stream",
198
+ });
199
+ }
200
+ if (ArrayBuffer.isView(deserialized)) {
201
+ return new File([deserialized], "file", {
202
+ type: "application/octet-stream",
203
+ });
204
+ }
205
+ return undefined;
206
+ };
207
+
68
208
  export const valueToFile = async (
69
209
  value: any,
70
210
  fileName: string,
71
211
  options?: FilePropertyBag,
72
212
  ): Promise<File> => {
73
- value = possiblyDeserializeDatarefToValue(value);
213
+ value = await possiblyDeserializeDatarefToValue(value);
74
214
  options = options || {};
75
215
  if (!options.type) {
76
216
  options.type = "application/octet-stream";
@@ -82,26 +222,15 @@ export const valueToFile = async (
82
222
  if (value instanceof File || value instanceof Blob) {
83
223
  const buffer = await value.arrayBuffer();
84
224
  if (value instanceof File) {
85
- options.type = (value as File).type;
225
+ options.type = value.type;
86
226
  }
87
227
  return new File([buffer], fileName, options);
88
228
  }
89
- if (
90
- value instanceof Int8Array ||
91
- value instanceof Uint8Array ||
92
- value instanceof Uint8ClampedArray ||
93
- value instanceof Int16Array ||
94
- value instanceof Uint16Array ||
95
- value instanceof Int32Array ||
96
- value instanceof Uint32Array ||
97
- value instanceof Float32Array ||
98
- value instanceof Float64Array
99
- ) {
100
- const typedValue = value as ArrayBufferView;
101
- return new File([typedValue.buffer], fileName, options);
229
+ if (ArrayBuffer.isView(value)) {
230
+ return new File([value.buffer], fileName, options);
102
231
  }
103
232
  if (typeof value === "string") {
104
- var blob = new Blob([value], { type: "text/plain" });
233
+ const blob = new Blob([value], { type: "text/plain" });
105
234
  options.type = "text/plain";
106
235
  return new File([blob], fileName, options);
107
236
  }
@@ -113,176 +242,94 @@ export const valueToFile = async (
113
242
  return new File([blob], fileName, options);
114
243
  }
115
244
 
116
- // assume it's a string
117
- var blob = new Blob([value as string], { type: "text/plain" });
245
+ const blob = new Blob([value as string], { type: "text/plain" });
118
246
  options.type = "text/plain";
119
247
  return new File([blob], fileName, options);
120
248
  };
121
249
 
122
- export const possiblySerializeValueToDataref = async <T>(
123
- value: T,
124
- ): Promise<T | DataRefSerialized> => {
125
- if (
126
- value instanceof Int8Array ||
127
- value instanceof Uint8Array ||
128
- value instanceof Uint8ClampedArray ||
129
- value instanceof Int16Array ||
130
- value instanceof Uint16Array ||
131
- value instanceof Int32Array ||
132
- value instanceof Uint32Array ||
133
- value instanceof Float32Array ||
134
- value instanceof Float64Array
135
- ) {
136
- const typedValue = value as ArrayBufferView;
137
- const replacement: DataRefSerializedTypedArray = {
138
- _s: true,
139
- _c: value.constructor.name,
140
- value: encode(typedValue.buffer),
141
- byteLength: typedValue.byteLength,
142
- byteOffset: typedValue.byteOffset,
143
- size: typedValue.byteLength,
144
- };
145
- return Promise.resolve(replacement);
146
- } else if (value instanceof File) {
147
- const typedValue = value as File;
148
- const arrayBuffer = await typedValue.arrayBuffer();
149
- const replacement: DataRefSerializedFile = {
150
- _s: true,
151
- _c: File.name,
152
- value: encode(arrayBuffer),
153
- name: typedValue.name,
154
- fileType: typedValue.type,
155
- lastModified: typedValue.lastModified,
156
- size: arrayBuffer.byteLength,
157
- };
158
- return replacement;
159
- } else if (value instanceof Blob) {
160
- const typedValue = value as Blob;
161
- const arrayBuffer = await typedValue.arrayBuffer();
162
- const replacement: DataRefSerializedBlob = {
163
- _s: true,
164
- _c: Blob.name,
165
- value: encode(arrayBuffer),
166
- fileType: typedValue.type,
167
- size: arrayBuffer.byteLength,
168
- };
169
- return replacement;
170
- } else if (value instanceof ArrayBuffer) {
171
- const typedValue = value as ArrayBuffer;
172
- const replacement: DataRefSerialized = {
173
- _s: true,
174
- _c: ArrayBuffer.name,
175
- value: encode(typedValue),
176
- size: typedValue.byteLength,
177
- };
178
- return Promise.resolve(replacement);
250
+ // --- Internal helpers ---
251
+
252
+ async function deserializeDataUrl(dataUrl: string): Promise<any> {
253
+ const params = getParameters(dataUrl);
254
+
255
+ // TypedArray: has "type" parameter (e.g. type=Float32Array)
256
+ if (params.type && TYPED_ARRAY_NAMES.has(params.type)) {
257
+ return dataUrlToTypedArray(dataUrl);
179
258
  }
180
- return Promise.resolve(value);
181
- };
182
259
 
183
- export const possiblyDeserializeDatarefToValue = (value: any): any => {
184
- if (
185
- !(
186
- value &&
187
- typeof value === "object" &&
188
- (value as DataRefSerialized)._s === true
189
- )
190
- ) {
191
- return value;
260
+ // File: has "file=true" parameter
261
+ if (params.file === "true") {
262
+ const name = params.name ? decodeURIComponent(params.name) : "file";
263
+ const lastModified = params.lastModified
264
+ ? parseInt(params.lastModified, 10)
265
+ : undefined;
266
+ const mimeType = getMimeType(dataUrl);
267
+ const buffer = await dataUrlToBuffer(dataUrl);
268
+ return new File([buffer], name, { type: mimeType, lastModified });
192
269
  }
193
- const serializedRef = value as DataRefSerialized;
194
- const _c: string = serializedRef._c;
195
- if (_c === Blob.name) {
196
- const serializedRefBlob = value as DataRefSerializedBlob;
197
- const blob = new Blob([decode(serializedRef.value)], {
198
- type: serializedRefBlob.fileType,
199
- });
200
- return blob;
201
- } else if (_c === File.name) {
202
- const serializedRefFile = value as DataRefSerializedFile;
203
- const file = new File(
204
- [decode(serializedRef.value)],
205
- serializedRefFile.name,
206
- {
207
- type: serializedRefFile.fileType,
208
- lastModified: serializedRefFile.lastModified,
209
- },
210
- );
211
- return file;
212
- } else if (_c === ArrayBuffer.name) {
213
- const arrayBuffer: ArrayBuffer = decode(serializedRef.value);
214
- return arrayBuffer;
270
+
271
+ // Blob: has "blob=true" parameter
272
+ if (params.blob === "true") {
273
+ const mimeType = getMimeType(dataUrl);
274
+ const buffer = await dataUrlToBuffer(dataUrl);
275
+ return new Blob([buffer], { type: mimeType });
215
276
  }
216
- // Assume typed array
217
- const serializedRefTypedArray = value as DataRefSerializedTypedArray;
218
277
 
219
- const arrayBuffer: ArrayBuffer = decode(serializedRefTypedArray.value);
220
- const constructorName: string = serializedRefTypedArray._c;
278
+ // Plain ArrayBuffer
279
+ return dataUrlToBuffer(dataUrl);
280
+ }
221
281
 
222
- try {
223
- // @ts-ignore
224
- const typedArray: ArrayBufferView = new globalThis[constructorName](
225
- arrayBuffer,
226
- // serializedRefTypedArray.byteOffset,
227
- // serializedRefTypedArray.byteLength
228
- );
229
- return typedArray;
230
- } catch (e) {}
282
+ function deserializeLegacyMetapage(value: DataRefSerialized): any {
283
+ const _c = value._c;
284
+ if (_c === "Blob") {
285
+ const v = value as DataRefSerializedBlob;
286
+ return new Blob([decode(value.value)], { type: v.fileType });
287
+ } else if (_c === "File") {
288
+ const v = value as DataRefSerializedFile;
289
+ return new File([decode(value.value)], v.name, {
290
+ type: v.fileType,
291
+ lastModified: v.lastModified,
292
+ });
293
+ } else if (_c === "ArrayBuffer") {
294
+ return decode(value.value);
295
+ }
296
+ // Typed array
297
+ const arrayBuffer = decode(value.value);
298
+ if (TYPED_ARRAY_NAMES.has(_c)) {
299
+ try {
300
+ // @ts-ignore
301
+ return new globalThis[_c](arrayBuffer);
302
+ } catch (_) {}
303
+ }
231
304
  return value;
232
- };
305
+ }
233
306
 
234
- export const possiblyDeserializeDatarefToFile = (
235
- value: any,
236
- ): File | undefined => {
237
- if (
238
- !(
239
- value &&
240
- typeof value === "object" &&
241
- (value as DataRefSerialized)._s === true
242
- )
243
- ) {
244
- return undefined;
245
- }
246
- const serializedRef = value as DataRefSerialized;
247
- const _c: string = serializedRef._c;
248
- if (_c === Blob.name) {
249
- const serializedRefBlob = value as DataRefSerializedBlob;
250
- const blob = new Blob([decode(serializedRef.value)], {
251
- type: serializedRefBlob.fileType,
252
- });
253
- return new File([blob], "file", {
254
- type: blob.type,
307
+ function deserializeDatarefV1(value: {
308
+ ref: string;
309
+ c: string;
310
+ value: string;
311
+ [key: string]: any;
312
+ }): any {
313
+ const _c = value.c;
314
+ if (_c === "Blob") {
315
+ return new Blob([decode(value.value)], {
316
+ type: value.fileType || undefined,
255
317
  });
256
- } else if (_c === File.name) {
257
- const serializedRefFile = value as DataRefSerializedFile;
258
- const file = new File(
259
- [decode(serializedRef.value)],
260
- serializedRefFile.name,
261
- {
262
- type: serializedRefFile.fileType,
263
- lastModified: serializedRefFile.lastModified,
264
- },
265
- );
266
- return file;
267
- } else if (_c === ArrayBuffer.name) {
268
- const arrayBuffer: ArrayBuffer = decode(serializedRef.value);
269
- return new File([arrayBuffer], "file", {
270
- type: "application/octet-stream",
318
+ } else if (_c === "File") {
319
+ return new File([decode(value.value)], value.name || "file", {
320
+ type: value.fileType || undefined,
321
+ lastModified: value.lastModified || undefined,
271
322
  });
323
+ } else if (_c === "ArrayBuffer") {
324
+ return decode(value.value);
272
325
  }
273
- // Assume typed array
274
- const serializedRefTypedArray = value as DataRefSerializedTypedArray;
275
- const arrayBuffer: ArrayBuffer = decode(serializedRefTypedArray.value);
276
- const constructorName: string = serializedRefTypedArray._c;
277
-
278
- try {
279
- // @ts-ignore
280
- const typedArray: ArrayBufferView = new globalThis[constructorName](
281
- arrayBuffer,
282
- );
283
- return new File([typedArray], "file", {
284
- type: "application/octet-stream",
285
- });
286
- } catch (e) {}
287
- return undefined;
288
- };
326
+ // Typed array
327
+ const arrayBuffer = decode(value.value);
328
+ if (TYPED_ARRAY_NAMES.has(_c)) {
329
+ try {
330
+ // @ts-ignore
331
+ return new globalThis[_c](arrayBuffer);
332
+ } catch (_) {}
333
+ }
334
+ return value;
335
+ }