@dreamkit/app 0.0.44 → 0.0.45
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/lib/EJSON.d.ts +10 -2
- package/lib/EJSON.d.ts.map +1 -1
- package/lib/EJSON.js +8 -6
- package/lib/LazyFile.d.ts +15 -0
- package/lib/LazyFile.d.ts.map +1 -0
- package/lib/LazyFile.js +34 -0
- package/lib/builders/SerializerBuilder.d.ts +3 -2
- package/lib/builders/SerializerBuilder.d.ts.map +1 -1
- package/lib/handlers/StorageHandler.d.ts +9 -0
- package/lib/handlers/StorageHandler.d.ts.map +1 -0
- package/lib/handlers/StorageHandler.js +7 -0
- package/lib/index.base.d.ts +3 -1
- package/lib/index.base.d.ts.map +1 -1
- package/lib/index.base.js +3 -1
- package/lib/presets/serializers.d.ts +6 -0
- package/lib/presets/serializers.d.ts.map +1 -1
- package/lib/presets/serializers.js +23 -0
- package/package.json +1 -1
package/lib/EJSON.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ export type EJSONEncodedObject = {
|
|
|
3
3
|
$ejson: string;
|
|
4
4
|
$value: any;
|
|
5
5
|
};
|
|
6
|
+
export type BlobRef = {
|
|
7
|
+
path: string;
|
|
8
|
+
size: number;
|
|
9
|
+
};
|
|
10
|
+
export type BlobRefs = Record<number, BlobRef>;
|
|
6
11
|
export declare class EJSON {
|
|
7
12
|
#private;
|
|
8
13
|
get serializers(): readonly Serializer[];
|
|
@@ -10,8 +15,11 @@ export declare class EJSON {
|
|
|
10
15
|
add(serializer: Serializer): void;
|
|
11
16
|
remove(name: string): void;
|
|
12
17
|
clear(): void;
|
|
13
|
-
encode(input: any): any;
|
|
14
|
-
decode(input: any
|
|
18
|
+
encode(input: any, blobs?: Blob[]): any;
|
|
19
|
+
decode(input: any, options?: {
|
|
20
|
+
blobRefs?: BlobRefs;
|
|
21
|
+
onDecoded?: (input: any) => void;
|
|
22
|
+
}): any;
|
|
15
23
|
parse(input: string): any;
|
|
16
24
|
stringify(value: any): string;
|
|
17
25
|
}
|
package/lib/EJSON.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EJSON.d.ts","sourceRoot":"","sources":["../src/EJSON.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAG7D,MAAM,MAAM,kBAAkB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"EJSON.d.ts","sourceRoot":"","sources":["../src/EJSON.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAG7D,MAAM,MAAM,kBAAkB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,CAAC;AACjE,MAAM,MAAM,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AACrD,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAQ/C,qBAAa,KAAK;;IAGhB,IAAI,WAAW,IAAI,SAAS,UAAU,EAAE,CAMvC;gBACW,WAAW,EAAE,UAAU,EAAE;IAGrC,GAAG,CAAC,UAAU,EAAE,UAAU;IAK1B,MAAM,CAAC,IAAI,EAAE,MAAM;IAInB,KAAK;IAIL,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,GAAE,IAAI,EAAO,GAAG,GAAG;IAqB3C,MAAM,CACJ,KAAK,EAAE,GAAG,EACV,OAAO,GAAE;QACP,QAAQ,CAAC,EAAE,QAAQ,CAAC;QACpB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;KAC7B,GACL,GAAG;IAwBN,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG;IAIzB,SAAS,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM;CAI9B"}
|
package/lib/EJSON.js
CHANGED
|
@@ -26,7 +26,7 @@ export class EJSON {
|
|
|
26
26
|
this.#serializers = [];
|
|
27
27
|
this.#serializersValue = undefined;
|
|
28
28
|
}
|
|
29
|
-
encode(input) {
|
|
29
|
+
encode(input, blobs = []) {
|
|
30
30
|
if (isPlainObject(input)) {
|
|
31
31
|
const object = {};
|
|
32
32
|
for (const key in input) {
|
|
@@ -42,30 +42,32 @@ export class EJSON {
|
|
|
42
42
|
if (serializer.config.is(input)) {
|
|
43
43
|
return {
|
|
44
44
|
$ejson: serializer.config.key,
|
|
45
|
-
$value: serializer.config.to(input),
|
|
45
|
+
$value: serializer.config.to(input, blobs),
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
return input;
|
|
51
51
|
}
|
|
52
|
-
decode(input) {
|
|
52
|
+
decode(input, options = {}) {
|
|
53
53
|
if (isPlainObject(input)) {
|
|
54
54
|
if (isEJSONObject(input)) {
|
|
55
55
|
const serializer = this.serializers.find((s) => s.config.key === input.$ejson);
|
|
56
56
|
if (!serializer)
|
|
57
57
|
throw new Error(`Unknown EJSON type: ${input.$ejson}`);
|
|
58
|
-
|
|
58
|
+
const decoded = serializer.config.from(input.$value, options.blobRefs ?? {});
|
|
59
|
+
options.onDecoded?.(decoded);
|
|
60
|
+
return decoded;
|
|
59
61
|
}
|
|
60
62
|
else {
|
|
61
63
|
const object = {};
|
|
62
64
|
for (const key in input)
|
|
63
|
-
object[key] = this.decode(input[key]);
|
|
65
|
+
object[key] = this.decode(input[key], options);
|
|
64
66
|
return object;
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
else if (Array.isArray(input)) {
|
|
68
|
-
return input.map((item) => this.decode(item));
|
|
70
|
+
return input.map((item) => this.decode(item, options));
|
|
69
71
|
}
|
|
70
72
|
else {
|
|
71
73
|
return input;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BlobRef } from "./EJSON.js";
|
|
2
|
+
import { StorageHandler } from "./handlers/StorageHandler.js";
|
|
3
|
+
export declare class LazyFile extends File {
|
|
4
|
+
readonly ref: BlobRef;
|
|
5
|
+
protected options: FilePropertyBag;
|
|
6
|
+
protected handler?: StorageHandler | undefined;
|
|
7
|
+
constructor(ref: BlobRef, name: string, options: FilePropertyBag, handler?: StorageHandler | undefined);
|
|
8
|
+
get size(): number;
|
|
9
|
+
text(): Promise<string>;
|
|
10
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
11
|
+
stream(): ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
12
|
+
slice(): Blob;
|
|
13
|
+
get [Symbol.toStringTag](): string;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=LazyFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LazyFile.d.ts","sourceRoot":"","sources":["../src/LazyFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,qBAAa,QAAS,SAAQ,IAAI;IAK9B,QAAQ,CAAC,GAAG,EAAE,OAAO;IAErB,SAAS,CAAC,OAAO,EAAE,eAAe;IAClC,SAAS,CAAC,OAAO,CAAC,EAAE,cAAc;gBAHzB,GAAG,EAAE,OAAO,EACrB,IAAI,EAAE,MAAM,EACF,OAAO,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,cAAc,YAAA;IAKpC,IAAa,IAAI,IAAI,MAAM,CAE1B;IAEc,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAKvB,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAIzC,MAAM,IAAI,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAIjD,KAAK,IAAI,IAAI;IAItB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAEjC;CACF"}
|
package/lib/LazyFile.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { kindApp } from "./utils/kind.js";
|
|
2
|
+
export class LazyFile extends File {
|
|
3
|
+
ref;
|
|
4
|
+
options;
|
|
5
|
+
handler;
|
|
6
|
+
static {
|
|
7
|
+
kindApp(this, "LazyFile");
|
|
8
|
+
}
|
|
9
|
+
constructor(ref, name, options, handler) {
|
|
10
|
+
super([], name, options);
|
|
11
|
+
this.ref = ref;
|
|
12
|
+
this.options = options;
|
|
13
|
+
this.handler = handler;
|
|
14
|
+
}
|
|
15
|
+
get size() {
|
|
16
|
+
return this.ref.size;
|
|
17
|
+
}
|
|
18
|
+
async text() {
|
|
19
|
+
const buffer = await this.arrayBuffer();
|
|
20
|
+
return new TextDecoder().decode(buffer);
|
|
21
|
+
}
|
|
22
|
+
async arrayBuffer() {
|
|
23
|
+
return await this.handler.read(this.ref.path);
|
|
24
|
+
}
|
|
25
|
+
stream() {
|
|
26
|
+
return this.handler.stream(this.ref.path);
|
|
27
|
+
}
|
|
28
|
+
slice() {
|
|
29
|
+
throw new Error("LazyFile: slice() is not supported.");
|
|
30
|
+
}
|
|
31
|
+
get [Symbol.toStringTag]() {
|
|
32
|
+
return "File";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { BlobRefs } from "../EJSON.js";
|
|
1
2
|
export declare const kindSerializer: (input: object, name?: string) => void, isSerializer: (input: unknown) => input is unknown;
|
|
2
3
|
export type SerializerData<I = any, O = any> = {
|
|
3
4
|
key: string;
|
|
4
5
|
is(input: any): input is I;
|
|
5
|
-
to(input: I): O;
|
|
6
|
-
from(output: O): I;
|
|
6
|
+
to(input: I, blobs: Blob[]): O;
|
|
7
|
+
from(output: O, blobRefs: BlobRefs): I;
|
|
7
8
|
priority?: number;
|
|
8
9
|
};
|
|
9
10
|
export declare class Serializer<I = any, O = any> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SerializerBuilder.d.ts","sourceRoot":"","sources":["../../src/builders/SerializerBuilder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SerializerBuilder.d.ts","sourceRoot":"","sources":["../../src/builders/SerializerBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,eAAO,MAAO,cAAc,0CAAE,YAAY,sCAEzC,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI;IAC7C,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,CAAC,CAAC;IAC3B,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IAC/B,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,GAAG,CAAC,CAAC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,qBAAa,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG;IAI1B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC;gBAA5B,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC;CAClD;AAED,qBAAa,iBAAiB;IAC5B,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;CAG3D"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Constructor } from "@dreamkit/utils/ts.js";
|
|
2
|
+
export type StorageHandlerConstructor = Constructor<StorageHandler>;
|
|
3
|
+
export declare const kindStorageHandler: (input: object, name?: string) => void, isStorageHandler: (input: unknown) => input is StorageHandlerConstructor;
|
|
4
|
+
export declare abstract class StorageHandler {
|
|
5
|
+
abstract read(path: string): Promise<ArrayBuffer>;
|
|
6
|
+
abstract stream(path: string): ReadableStream<Uint8Array>;
|
|
7
|
+
abstract moveTo(path: string): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=StorageHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageHandler.d.ts","sourceRoot":"","sources":["../../src/handlers/StorageHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,MAAM,MAAM,yBAAyB,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC;AAEpE,eAAO,MAAO,kBAAkB,0CAAE,gBAAgB,wDACqB,CAAC;AAExE,8BAAsB,cAAc;IAIlC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IACjD,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC;IACzD,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAC7C"}
|
package/lib/index.base.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ export { isApi, isApiBuilder } from "./builders/ApiBuilder.js";
|
|
|
4
4
|
export { App } from "./App.js";
|
|
5
5
|
export { AppError } from "./AppError.js";
|
|
6
6
|
export { defineRoutePath, type RoutePathFunc } from "./routePath.js";
|
|
7
|
-
export { EJSON, type EJSONEncodedObject } from "./EJSON.js";
|
|
7
|
+
export { EJSON, type EJSONEncodedObject, type BlobRef, type BlobRefs, } from "./EJSON.js";
|
|
8
|
+
export { LazyFile } from "./LazyFile.js";
|
|
8
9
|
export { AppContext } from "./contexts/AppContext.js";
|
|
9
10
|
export { RequestContext } from "./contexts/RequestContext.js";
|
|
10
11
|
export { $api } from "./objects/$api.js";
|
|
@@ -23,4 +24,5 @@ export { Service, type ServiceConstructor, type ServiceOptions, type ServiceData
|
|
|
23
24
|
export { Session, type SessionConstructor, type SessionOptions, type SessionData, isSession, } from "./builders/SessionBuilder.js";
|
|
24
25
|
export { SettingsHandler, SettingsHandlerClass, type SettingsHandlerConstructor, type SettingsHandlerSaveResult, } from "./handlers/SettingsHandler.js";
|
|
25
26
|
export { SessionHandler, SessionHandlerClass, type SessionHandlerConstructor, } from "./handlers/SessionHandler.js";
|
|
27
|
+
export { StorageHandler, type StorageHandlerConstructor, } from "./handlers/StorageHandler.js";
|
|
26
28
|
//# sourceMappingURL=index.base.d.ts.map
|
package/lib/index.base.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.base.d.ts","sourceRoot":"","sources":["../src/index.base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.base.d.ts","sourceRoot":"","sources":["../src/index.base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EACL,KAAK,EACL,KAAK,kBAAkB,EACvB,KAAK,OAAO,EACZ,KAAK,QAAQ,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EACL,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,UAAU,GAChB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EACL,QAAQ,EACR,eAAe,EACf,UAAU,EACV,KAAK,mBAAmB,EACxB,KAAK,YAAY,GAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,UAAU,EACV,YAAY,EACZ,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,cAAc,GACpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,UAAU,EACV,KAAK,cAAc,EACnB,YAAY,GACb,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,OAAO,EACP,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,SAAS,GACV,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,OAAO,EACP,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,SAAS,GACV,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,KAAK,yBAAyB,GAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,cAAc,EACd,KAAK,yBAAyB,GAC/B,MAAM,8BAA8B,CAAC"}
|
package/lib/index.base.js
CHANGED
|
@@ -4,7 +4,8 @@ export { isApi, isApiBuilder } from "./builders/ApiBuilder.js";
|
|
|
4
4
|
export { App } from "./App.js";
|
|
5
5
|
export { AppError } from "./AppError.js";
|
|
6
6
|
export { defineRoutePath } from "./routePath.js";
|
|
7
|
-
export { EJSON } from "./EJSON.js";
|
|
7
|
+
export { EJSON, } from "./EJSON.js";
|
|
8
|
+
export { LazyFile } from "./LazyFile.js";
|
|
8
9
|
// contexts
|
|
9
10
|
export { AppContext } from "./contexts/AppContext.js";
|
|
10
11
|
export { RequestContext } from "./contexts/RequestContext.js";
|
|
@@ -26,3 +27,4 @@ export { Session, isSession, } from "./builders/SessionBuilder.js";
|
|
|
26
27
|
// handlers
|
|
27
28
|
export { SettingsHandler, SettingsHandlerClass, } from "./handlers/SettingsHandler.js";
|
|
28
29
|
export { SessionHandler, SessionHandlerClass, } from "./handlers/SessionHandler.js";
|
|
30
|
+
export { StorageHandler, } from "./handlers/StorageHandler.js";
|
|
@@ -10,4 +10,10 @@ export declare const appErrorSerializer: import("../index.base.js").Serializer<A
|
|
|
10
10
|
message: string;
|
|
11
11
|
cause: unknown;
|
|
12
12
|
}>;
|
|
13
|
+
export declare const fileSerializer: import("../index.base.js").Serializer<File, {
|
|
14
|
+
blobIndex: number;
|
|
15
|
+
name: string;
|
|
16
|
+
type: string;
|
|
17
|
+
lastModified: number;
|
|
18
|
+
}>;
|
|
13
19
|
//# sourceMappingURL=serializers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializers.d.ts","sourceRoot":"","sources":["../../src/presets/serializers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"serializers.d.ts","sourceRoot":"","sources":["../../src/presets/serializers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,eAAO,MAAM,eAAe;;;EAU1B,CAAC;AAEH,eAAO,MAAM,cAAc,qDAMzB,CAAC;AAEH,eAAO,MAAM,yBAAyB,+GAKpC,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;EAK7B,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;EAoBzB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AppError } from "../AppError.js";
|
|
2
|
+
import { LazyFile } from "../LazyFile.js";
|
|
2
3
|
import { $serializer } from "../objects/$serializer.js";
|
|
3
4
|
import { TypeAssertError } from "@dreamkit/schema";
|
|
4
5
|
export const errorSerializer = $serializer.create({
|
|
@@ -31,3 +32,25 @@ export const appErrorSerializer = $serializer.create({
|
|
|
31
32
|
to: (input) => ({ message: input.message, cause: input.cause }),
|
|
32
33
|
from: (input) => new AppError(input.message, { cause: input.cause }),
|
|
33
34
|
});
|
|
35
|
+
export const fileSerializer = $serializer.create({
|
|
36
|
+
key: "File",
|
|
37
|
+
is: (input) => input instanceof File,
|
|
38
|
+
to: (input, blobs) => {
|
|
39
|
+
const blobIndex = blobs.push(input) - 1;
|
|
40
|
+
return {
|
|
41
|
+
blobIndex,
|
|
42
|
+
name: input.name,
|
|
43
|
+
type: input.type,
|
|
44
|
+
lastModified: input.lastModified,
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
from: (input, blobRefs) => {
|
|
48
|
+
const ref = blobRefs[input.blobIndex];
|
|
49
|
+
if (!ref)
|
|
50
|
+
throw new Error(`Blob ref not found: ${input.blobIndex}`);
|
|
51
|
+
return new LazyFile(ref, input.name, {
|
|
52
|
+
type: input.type,
|
|
53
|
+
lastModified: input.lastModified,
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
});
|