@valbuild/core 0.44.0 → 0.46.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/declarations/src/index.d.ts +13 -14
- package/dist/declarations/src/initSchema.d.ts +2 -1
- package/dist/declarations/src/initVal.d.ts +1 -0
- package/dist/declarations/src/module.d.ts +3 -1
- package/dist/declarations/src/schema/file.d.ts +10 -0
- package/dist/declarations/src/schema/image.d.ts +11 -7
- package/dist/declarations/src/schema/string.d.ts +9 -1
- package/dist/declarations/src/selector/file.d.ts +6 -2
- package/dist/declarations/src/selector/image.d.ts +3 -0
- package/dist/declarations/src/selector/index.d.ts +3 -1
- package/dist/declarations/src/source/file.d.ts +8 -9
- package/dist/declarations/src/source/image.d.ts +7 -0
- package/dist/declarations/src/source/richtext.d.ts +4 -4
- package/dist/{index-6deb169d.cjs.dev.js → index-00276955.cjs.dev.js} +1 -1
- package/dist/{index-c83918b8.esm.js → index-5750c299.esm.js} +3 -81
- package/dist/{index-4f821892.esm.js → index-799bcf49.esm.js} +1 -1
- package/dist/{index-5bdaa229.cjs.prod.js → index-7b467ee6.cjs.prod.js} +2 -82
- package/dist/{index-a5295001.cjs.dev.js → index-d23e237a.cjs.dev.js} +2 -82
- package/dist/{index-216627d7.cjs.prod.js → index-db60fc1d.cjs.prod.js} +1 -1
- package/dist/{ops-422169e5.cjs.dev.js → ops-74e62ffe.cjs.dev.js} +89 -2
- package/dist/{ops-5bd1bd7a.cjs.prod.js → ops-c0e7e3a8.cjs.prod.js} +89 -2
- package/dist/{ops-899d8bef.esm.js → ops-ffed3406.esm.js} +81 -2
- package/dist/valbuild-core.cjs.dev.js +30 -6
- package/dist/valbuild-core.cjs.prod.js +30 -6
- package/dist/valbuild-core.esm.js +22 -7
- package/expr/dist/valbuild-core-expr.cjs.dev.js +2 -2
- package/expr/dist/valbuild-core-expr.cjs.prod.js +2 -2
- package/expr/dist/valbuild-core-expr.esm.js +2 -2
- package/package.json +1 -1
- package/patch/dist/valbuild-core-patch.cjs.dev.js +2 -2
- package/patch/dist/valbuild-core-patch.cjs.prod.js +2 -2
- package/patch/dist/valbuild-core-patch.esm.js +3 -3
@@ -7,6 +7,7 @@ export type { ValModule, SerializedModule, InferValModuleType } from "./module.j
|
|
7
7
|
export type { SourceObject, SourcePrimitive, Source } from "./source/index.js";
|
8
8
|
export type { FileSource } from "./source/file.js";
|
9
9
|
export type { RawString } from "./schema/string.js";
|
10
|
+
export type { ImageSource } from "./source/image.js";
|
10
11
|
export type { AnyRichTextOptions, Bold, Classes, HeadingNode, ImageNode, Italic, LineThrough, ListItemNode, LinkNode, OrderedListNode, ParagraphNode, BrNode, RichText, RichTextNode, RichTextOptions, RichTextSource, RootNode, SpanNode, UnorderedListNode, } from "./source/richtext.js";
|
11
12
|
export { type Val, type SerializedVal, type ModuleId, type ModulePath, type SourcePath, type JsonOfSource, } from "./val/index.js";
|
12
13
|
export type { Json, JsonPrimitive, JsonArray, JsonObject } from "./Json.js";
|
@@ -21,22 +22,23 @@ export { type SelectorSource, type SelectorOf, GenericSelector, } from "./select
|
|
21
22
|
import { getSource, resolvePath, splitModuleIdAndModulePath } from "./module.js";
|
22
23
|
import { getSchema } from "./selector/index.js";
|
23
24
|
import { ModuleId, ModulePath, getValPath, isVal } from "./val/index.js";
|
25
|
+
import { convertFileSource } from "./schema/file.js";
|
24
26
|
import { createValPathOfItem } from "./selector/SelectorProxy.js";
|
25
27
|
import { getVal } from "./future/fetchVal.js";
|
26
28
|
import type { Json } from "./Json.js";
|
27
29
|
import { SerializedSchema } from "./schema/index.js";
|
28
30
|
import { PatchJSON } from "./patch/index.js";
|
29
31
|
export { ValApi } from "./ValApi.js";
|
30
|
-
export type
|
31
|
-
export type
|
32
|
-
export type
|
33
|
-
export type
|
34
|
-
export type
|
35
|
-
export type
|
36
|
-
export type
|
37
|
-
export type
|
38
|
-
export type
|
39
|
-
export type
|
32
|
+
export { type SerializedArraySchema, ArraySchema } from "./schema/array.js";
|
33
|
+
export { type SerializedObjectSchema, ObjectSchema } from "./schema/object.js";
|
34
|
+
export { type SerializedRecordSchema, RecordSchema } from "./schema/record.js";
|
35
|
+
export { type SerializedStringSchema, StringSchema } from "./schema/string.js";
|
36
|
+
export { type SerializedNumberSchema, NumberSchema } from "./schema/number.js";
|
37
|
+
export { type SerializedBooleanSchema, BooleanSchema } from "./schema/boolean.js";
|
38
|
+
export { type SerializedImageSchema, ImageSchema } from "./schema/image.js";
|
39
|
+
export { type SerializedRichTextSchema, RichTextSchema, } from "./schema/richtext.js";
|
40
|
+
export { type SerializedUnionSchema, UnionSchema } from "./schema/union.js";
|
41
|
+
export { type SerializedLiteralSchema, LiteralSchema } from "./schema/literal.js";
|
40
42
|
export type ApiCommitResponse = {
|
41
43
|
modules: Record<ModuleId, {
|
42
44
|
patches: {
|
@@ -80,10 +82,7 @@ export type ApiGetPatchResponse = Record<ModuleId, {
|
|
80
82
|
}[]>;
|
81
83
|
export type ApiPostPatchResponse = Record<ModuleId, string[]>;
|
82
84
|
declare const Internal: {
|
83
|
-
convertFileSource:
|
84
|
-
url: string;
|
85
|
-
metadata?: import("./schema/image.js").ImageMetadata;
|
86
|
-
};
|
85
|
+
convertFileSource: typeof convertFileSource;
|
87
86
|
getSchema: typeof getSchema;
|
88
87
|
getValPath: typeof getValPath;
|
89
88
|
getVal: typeof getVal;
|
@@ -26,6 +26,7 @@ export declare function initSchema(): {
|
|
26
26
|
string: <T extends string>(options?: {
|
27
27
|
maxLength?: number | undefined;
|
28
28
|
minLength?: number | undefined;
|
29
|
+
regexp?: RegExp | undefined;
|
29
30
|
} | undefined) => import("./schema/string.js").StringSchema<T>;
|
30
31
|
boolean: () => import("./schema/index.js").Schema<boolean>;
|
31
32
|
array: <S extends import("./schema/index.js").Schema<import("./selector/index.js").SelectorSource>>(schema: S) => import("./schema/index.js").Schema<import("./schema/index.js").SelectorOfSchema<S>[]>;
|
@@ -48,7 +49,7 @@ export declare function initSchema(): {
|
|
48
49
|
valPath?: undefined;
|
49
50
|
} & { [k in Key]: string; } : Key extends import("./schema/index.js").Schema<string> ? string : unknown>[]>(key: Key, ...objects: T_1) => import("./schema/index.js").Schema<T_1 extends import("./schema/index.js").Schema<infer S_1 extends import("./selector/index.js").SelectorSource>[] ? S_1 extends import("./selector/index.js").SelectorSource ? S_1 | (Key extends import("./schema/index.js").Schema<infer K extends import("./selector/index.js").SelectorSource> ? K : never) : never : never>;
|
50
51
|
richtext: <O extends import("./index.js").RichTextOptions>(options?: O | undefined) => import("./schema/index.js").Schema<import("./index.js").RichTextSource<O>>;
|
51
|
-
image: (options?: import("./schema/image.js").ImageOptions | undefined) => import("./schema/index.js").Schema<import("./index.js").
|
52
|
+
image: (options?: import("./schema/image.js").ImageOptions | undefined) => import("./schema/index.js").Schema<import("./index.js").ImageSource>;
|
52
53
|
literal: <T_2 extends string>(value: T_2) => import("./schema/index.js").Schema<T_2>;
|
53
54
|
keyOf: <Src extends import("./selector/index.js").GenericSelector<import("./source/index.js").SourceObject | import("./source/index.js").SourceArray, undefined> & import("./module.js").ValModuleBrand>(valModule: Src) => import("./schema/index.js").Schema<Src extends import("./selector/index.js").GenericSelector<infer S_2 extends import("./source/index.js").Source, undefined> ? S_2 extends readonly any[] ? number : S_2 extends import("./source/index.js").SourceObject ? keyof S_2 : S_2 extends Record<string, any> ? string : never : never>;
|
54
55
|
record: <S_3 extends import("./schema/index.js").Schema<import("./selector/index.js").SelectorSource>>(schema: S_3) => import("./schema/index.js").Schema<Record<string, import("./schema/index.js").SelectorOfSchema<S_3>>>;
|
@@ -4,13 +4,15 @@ import { Source } from "./source/index.js";
|
|
4
4
|
import { ModuleId, ModulePath, SourcePath } from "./val/index.js";
|
5
5
|
import { Json } from "./Json.js";
|
6
6
|
import { RawString } from "./schema/string.js";
|
7
|
+
import { ImageSelector } from "./selector/image.js";
|
8
|
+
import { ImageSource } from "./source/image.js";
|
7
9
|
declare const brand: unique symbol;
|
8
10
|
export type ValModule<T extends SelectorSource> = SelectorOf<T> & ValModuleBrand;
|
9
11
|
export type ValModuleBrand = {
|
10
12
|
[brand]: "ValModule";
|
11
13
|
};
|
12
14
|
export type InferValModuleType<T extends ValModule<SelectorSource>> = T extends GenericSelector<infer S> ? S : never;
|
13
|
-
type ReplaceRawStringWithString<T extends SelectorSource> = SelectorSource extends T ? T : T extends RawString ? string : T extends {
|
15
|
+
type ReplaceRawStringWithString<T extends SelectorSource> = SelectorSource extends T ? T : T extends RawString ? string : T extends ImageSelector ? ImageSource : T extends {
|
14
16
|
[key in string]: SelectorSource;
|
15
17
|
} ? {
|
16
18
|
[key in keyof T]: ReplaceRawStringWithString<T[key]>;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Json } from "../Json.js";
|
2
|
+
import { FileSource } from "../source/file.js";
|
3
|
+
export declare function convertFileSource<Metadata extends {
|
4
|
+
readonly [key: string]: Json;
|
5
|
+
} | undefined = {
|
6
|
+
readonly [key: string]: Json;
|
7
|
+
} | undefined>(src: FileSource<Metadata>): {
|
8
|
+
url: string;
|
9
|
+
metadata?: Metadata;
|
10
|
+
};
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { Schema, SerializedSchema } from "./index.js";
|
2
2
|
import { FileSource } from "../source/file.js";
|
3
|
+
import { ImageSource } from "../source/image.js";
|
3
4
|
import { SourcePath } from "../val/index.js";
|
4
5
|
import { ValidationErrors } from "./validation/ValidationError.js";
|
5
6
|
export type ImageOptions = {
|
@@ -16,8 +17,15 @@ export type ImageMetadata = {
|
|
16
17
|
width: number;
|
17
18
|
height: number;
|
18
19
|
sha256: string;
|
19
|
-
|
20
|
-
|
20
|
+
mimeType: string;
|
21
|
+
hotspot?: {
|
22
|
+
x: number;
|
23
|
+
y: number;
|
24
|
+
height: number;
|
25
|
+
width: number;
|
26
|
+
};
|
27
|
+
};
|
28
|
+
export declare class ImageSchema<Src extends FileSource<ImageMetadata | undefined> | null> extends Schema<Src> {
|
21
29
|
readonly options?: ImageOptions | undefined;
|
22
30
|
readonly opt: boolean;
|
23
31
|
constructor(options?: ImageOptions | undefined, opt?: boolean);
|
@@ -26,8 +34,4 @@ export declare class ImageSchema<Src extends FileSource<ImageMetadata> | null> e
|
|
26
34
|
optional(): Schema<Src | null>;
|
27
35
|
serialize(): SerializedSchema;
|
28
36
|
}
|
29
|
-
export declare const image: (options?: ImageOptions) => Schema<
|
30
|
-
export declare const convertFileSource: (src: FileSource<ImageMetadata>) => {
|
31
|
-
url: string;
|
32
|
-
metadata?: ImageMetadata;
|
33
|
-
};
|
37
|
+
export declare const image: (options?: ImageOptions) => Schema<ImageSource>;
|
@@ -4,10 +4,18 @@ import { ValidationErrors } from "./validation/ValidationError.js";
|
|
4
4
|
type StringOptions = {
|
5
5
|
maxLength?: number;
|
6
6
|
minLength?: number;
|
7
|
+
regexp?: RegExp;
|
7
8
|
};
|
8
9
|
export type SerializedStringSchema = {
|
9
10
|
type: "string";
|
10
|
-
options?:
|
11
|
+
options?: {
|
12
|
+
maxLength?: number;
|
13
|
+
minLength?: number;
|
14
|
+
regexp?: {
|
15
|
+
source: string;
|
16
|
+
flags: string;
|
17
|
+
};
|
18
|
+
};
|
11
19
|
opt: boolean;
|
12
20
|
raw: boolean;
|
13
21
|
};
|
@@ -1,6 +1,10 @@
|
|
1
|
+
import { Source } from "../source/index.js";
|
2
|
+
import { FileMetadata } from "../source/file.js";
|
1
3
|
import { Selector as UnknownSelector, GenericSelector } from "./index.js";
|
2
|
-
export type FileSelector = GenericSelector<{
|
4
|
+
export type FileSelector<Metadata extends FileMetadata | undefined> = GenericSelector<{
|
3
5
|
url: string;
|
4
6
|
}> & {
|
5
7
|
readonly url: UnknownSelector<string>;
|
6
|
-
}
|
8
|
+
} & Metadata extends undefined ? {} : Metadata extends Source ? {
|
9
|
+
readonly metadata: UnknownSelector<Metadata>;
|
10
|
+
} : {};
|
@@ -11,7 +11,9 @@ import { Schema } from "../schema/index.js";
|
|
11
11
|
import type { A } from "ts-toolbelt";
|
12
12
|
import { FileSource } from "../source/file.js";
|
13
13
|
import { RichText, RichTextOptions, RichTextSource } from "../source/richtext.js";
|
14
|
-
|
14
|
+
import { ImageMetadata } from "../schema/image.js";
|
15
|
+
import { ImageSelector } from "./image.js";
|
16
|
+
export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends FileSource<infer M> ? M extends ImageMetadata ? ImageSelector : FileSelector<M> : T extends RichTextSource<infer O> ? RichText<O> : T extends SourceObject ? ObjectSelector<T> : T extends SourceArray ? ArraySelector<T> : T extends string ? StringSelector<T> : T extends number ? NumberSelector<T> : T extends boolean ? BooleanSelector<T> : T extends null ? PrimitiveSelector<null> : never;
|
15
17
|
export type SelectorSource = SourcePrimitive | undefined | readonly SelectorSource[] | {
|
16
18
|
[key: string]: SelectorSource;
|
17
19
|
} | FileSource | RichTextSource<RichTextOptions> | GenericSelector<Source>;
|
@@ -1,23 +1,22 @@
|
|
1
1
|
import { VAL_EXTENSION } from "./index.js";
|
2
|
-
import {
|
2
|
+
import { Json } from "../Json.js";
|
3
3
|
export declare const FILE_REF_PROP: "_ref";
|
4
|
+
export type FileMetadata = {
|
5
|
+
readonly [key: string]: Json;
|
6
|
+
};
|
4
7
|
/**
|
5
8
|
* A file source represents the path to a (local) file.
|
6
9
|
*
|
7
10
|
* It will be resolved into a Asset object.
|
8
11
|
*
|
9
12
|
*/
|
10
|
-
export type FileSource<Metadata extends {
|
11
|
-
readonly [key: string]: JsonPrimitive;
|
12
|
-
} | undefined = {
|
13
|
-
readonly [key: string]: JsonPrimitive;
|
14
|
-
} | undefined> = {
|
13
|
+
export type FileSource<Metadata extends FileMetadata | undefined = FileMetadata | undefined> = {
|
15
14
|
readonly [FILE_REF_PROP]: string;
|
16
15
|
readonly [VAL_EXTENSION]: "file";
|
17
16
|
readonly metadata?: Metadata;
|
18
17
|
};
|
19
18
|
export declare function file<Metadata extends {
|
20
|
-
readonly [key: string]:
|
21
|
-
}>(ref: string
|
22
|
-
export declare function file(ref: string
|
19
|
+
readonly [key: string]: Json;
|
20
|
+
}>(ref: `/public/${string}`, metadata: Metadata): FileSource<Metadata>;
|
21
|
+
export declare function file(ref: `/public/${string}`, metadata?: undefined): FileSource<undefined>;
|
23
22
|
export declare function isFile(obj: unknown): obj is FileSource;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { ImageMetadata } from "../schema/image.js";
|
2
|
+
import { FileSource } from "./file.js";
|
3
|
+
/**
|
4
|
+
* A image source represents the path to a (local) image.
|
5
|
+
*
|
6
|
+
*/
|
7
|
+
export type ImageSource<Metadata extends ImageMetadata | undefined = ImageMetadata> = FileSource<Metadata>;
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import { FileSource } from "./file.js";
|
2
1
|
import { VAL_EXTENSION } from "./index.js";
|
3
2
|
import { LinkSource } from "./link.js";
|
4
|
-
import {
|
3
|
+
import { ImageSource } from "./image.js";
|
5
4
|
export type RichTextOptions = {
|
6
5
|
headings?: ("h1" | "h2" | "h3" | "h4" | "h5" | "h6")[];
|
7
6
|
img?: boolean;
|
@@ -44,6 +43,7 @@ type ImageTagNode = {
|
|
44
43
|
src: string;
|
45
44
|
height?: number;
|
46
45
|
width?: number;
|
46
|
+
mimeType?: string;
|
47
47
|
children: [];
|
48
48
|
};
|
49
49
|
export type ImageNode<O extends RichTextOptions> = O["img"] extends true ? ImageTagNode : never;
|
@@ -79,7 +79,7 @@ export type RootNode<O extends RichTextOptions> = HeadingNode<O> | ParagraphNode
|
|
79
79
|
export type RichTextSource<O extends RichTextOptions> = {
|
80
80
|
[VAL_EXTENSION]: "richtext";
|
81
81
|
templateStrings: string[];
|
82
|
-
exprs: ((O["img"] extends true ?
|
82
|
+
exprs: ((O["img"] extends true ? ImageSource : never) | (O["a"] extends true ? LinkSource : never))[];
|
83
83
|
};
|
84
84
|
/**
|
85
85
|
* RichText is accessible by users (after conversion via useVal / fetchVal)
|
@@ -89,5 +89,5 @@ export type RichText<O extends RichTextOptions> = {
|
|
89
89
|
[VAL_EXTENSION]: "richtext";
|
90
90
|
children: RootNode<O>[];
|
91
91
|
};
|
92
|
-
export declare function richtext<O extends RichTextOptions>(templateStrings: TemplateStringsArray, ...nodes: (
|
92
|
+
export declare function richtext<O extends RichTextOptions>(templateStrings: TemplateStringsArray, ...nodes: (ImageSource | LinkSource)[]): RichTextSource<O>;
|
93
93
|
export {};
|
@@ -427,85 +427,7 @@ function isFile(obj) {
|
|
427
427
|
return _typeof(obj) === "object" && obj !== null && VAL_EXTENSION in obj && obj[VAL_EXTENSION] === "file" && FILE_REF_PROP in obj && typeof obj[FILE_REF_PROP] === "string";
|
428
428
|
}
|
429
429
|
|
430
|
-
|
431
|
-
_inherits(ImageSchema, _Schema);
|
432
|
-
var _super = _createSuper(ImageSchema);
|
433
|
-
function ImageSchema(options) {
|
434
|
-
var _this;
|
435
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
436
|
-
_classCallCheck(this, ImageSchema);
|
437
|
-
_this = _super.call(this);
|
438
|
-
_this.options = options;
|
439
|
-
_this.opt = opt;
|
440
|
-
return _this;
|
441
|
-
}
|
442
|
-
_createClass(ImageSchema, [{
|
443
|
-
key: "validate",
|
444
|
-
value: function validate(path, src) {
|
445
|
-
if (this.opt && (src === null || src === undefined)) {
|
446
|
-
return false;
|
447
|
-
}
|
448
|
-
if (src === null || src === undefined) {
|
449
|
-
return _defineProperty({}, path, [{
|
450
|
-
message: "Non-optional image was null or undefined.",
|
451
|
-
value: src
|
452
|
-
}]);
|
453
|
-
}
|
454
|
-
if (typeof src[FILE_REF_PROP] !== "string") {
|
455
|
-
return _defineProperty({}, path, [{
|
456
|
-
message: "Image did not have a file reference string. Got: ".concat(_typeof(src[FILE_REF_PROP])),
|
457
|
-
value: src
|
458
|
-
}]);
|
459
|
-
}
|
460
|
-
if (src[VAL_EXTENSION] !== "file") {
|
461
|
-
return _defineProperty({}, path, [{
|
462
|
-
message: "Image did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
|
463
|
-
value: src
|
464
|
-
}]);
|
465
|
-
}
|
466
|
-
if (src.metadata) {
|
467
|
-
return _defineProperty({}, path, [{
|
468
|
-
message: "Found metadata, but it could not be validated. Image metadata must be an object with the required props: width (positive number), height (positive number) and sha256 (string of length 64 of the base16 hash).",
|
469
|
-
// These validation errors will have to be picked up by logic outside of this package and revalidated. Reasons: 1) we have to read files to verify the metadata, which is handled differently in different runtimes (Browser, QuickJS, Node.js); 2) we want to keep this package dependency free.
|
470
|
-
value: src,
|
471
|
-
fixes: ["image:replace-metadata"]
|
472
|
-
}]);
|
473
|
-
}
|
474
|
-
return _defineProperty({}, path, [{
|
475
|
-
message: "Could not validate Image metadata.",
|
476
|
-
value: src,
|
477
|
-
fixes: ["image:add-metadata"]
|
478
|
-
}]);
|
479
|
-
}
|
480
|
-
}, {
|
481
|
-
key: "assert",
|
482
|
-
value: function assert(src) {
|
483
|
-
if (this.opt && (src === null || src === undefined)) {
|
484
|
-
return true;
|
485
|
-
}
|
486
|
-
return (src === null || src === void 0 ? void 0 : src[FILE_REF_PROP]) === "image" && (src === null || src === void 0 ? void 0 : src[VAL_EXTENSION]) === "file";
|
487
|
-
}
|
488
|
-
}, {
|
489
|
-
key: "optional",
|
490
|
-
value: function optional() {
|
491
|
-
return new ImageSchema(this.options, true);
|
492
|
-
}
|
493
|
-
}, {
|
494
|
-
key: "serialize",
|
495
|
-
value: function serialize() {
|
496
|
-
return {
|
497
|
-
type: "image",
|
498
|
-
options: this.options,
|
499
|
-
opt: this.opt
|
500
|
-
};
|
501
|
-
}
|
502
|
-
}]);
|
503
|
-
return ImageSchema;
|
504
|
-
}(Schema);
|
505
|
-
var image = function image(options) {
|
506
|
-
return new ImageSchema(options);
|
507
|
-
};
|
508
|
-
var convertFileSource = function convertFileSource(src) {
|
430
|
+
function convertFileSource(src) {
|
509
431
|
var _src$metadata2;
|
510
432
|
// TODO: /public should be configurable
|
511
433
|
if (!src[FILE_REF_PROP].startsWith("/public")) {
|
@@ -519,7 +441,7 @@ var convertFileSource = function convertFileSource(src) {
|
|
519
441
|
url: src[FILE_REF_PROP].slice("/public".length) + "?sha256=".concat((_src$metadata2 = src.metadata) === null || _src$metadata2 === void 0 ? void 0 : _src$metadata2.sha256),
|
520
442
|
metadata: src.metadata
|
521
443
|
};
|
522
|
-
}
|
444
|
+
}
|
523
445
|
|
524
446
|
function isSerializedVal(val) {
|
525
447
|
return _typeof(val) === "object" && val !== null && val !== undefined && ("val" in val || "valPath" in val);
|
@@ -553,4 +475,4 @@ function getValPath(valOrSelector) {
|
|
553
475
|
return valOrSelector[Path];
|
554
476
|
}
|
555
477
|
|
556
|
-
export { Call as C, Expr as E, FILE_REF_PROP as F, GetSchema as G,
|
478
|
+
export { Call as C, Expr as E, FILE_REF_PROP as F, GetSchema as G, NilSym as N, Path as P, Schema as S, VAL_EXTENSION as V, _inherits as _, _createSuper as a, _classCallCheck as b, _createClass as c, _defineProperty as d, _typeof as e, file as f, getValPath as g, _slicedToArray as h, isFile as i, GetSource as j, isSerializedVal as k, convertFileSource as l, getSchema as m, isVal as n, GenericSelector as o, _objectSpread2 as p, Sym as q, StringLiteral as r, StringTemplate as s, _toConsumableArray as t };
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { p as _objectSpread2, h as _slicedToArray, c as _createClass, b as _classCallCheck, q as Sym, C as Call, r as StringLiteral, s as StringTemplate, e as _typeof, k as isSerializedVal, F as FILE_REF_PROP, V as VAL_EXTENSION, l as convertFileSource, d as _defineProperty, E as Expr, S as Schema, t as _toConsumableArray, N as NilSym } from './index-5750c299.esm.js';
|
2
2
|
import { i as isErr, e as err, o as ok, a as isOk } from './result-b96df128.esm.js';
|
3
3
|
|
4
4
|
var WHITE_SPACE = ["\n", "\r", "\t", " "];
|
@@ -429,85 +429,7 @@ function isFile(obj) {
|
|
429
429
|
return _typeof(obj) === "object" && obj !== null && VAL_EXTENSION in obj && obj[VAL_EXTENSION] === "file" && FILE_REF_PROP in obj && typeof obj[FILE_REF_PROP] === "string";
|
430
430
|
}
|
431
431
|
|
432
|
-
|
433
|
-
_inherits(ImageSchema, _Schema);
|
434
|
-
var _super = _createSuper(ImageSchema);
|
435
|
-
function ImageSchema(options) {
|
436
|
-
var _this;
|
437
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
438
|
-
_classCallCheck(this, ImageSchema);
|
439
|
-
_this = _super.call(this);
|
440
|
-
_this.options = options;
|
441
|
-
_this.opt = opt;
|
442
|
-
return _this;
|
443
|
-
}
|
444
|
-
_createClass(ImageSchema, [{
|
445
|
-
key: "validate",
|
446
|
-
value: function validate(path, src) {
|
447
|
-
if (this.opt && (src === null || src === undefined)) {
|
448
|
-
return false;
|
449
|
-
}
|
450
|
-
if (src === null || src === undefined) {
|
451
|
-
return _defineProperty({}, path, [{
|
452
|
-
message: "Non-optional image was null or undefined.",
|
453
|
-
value: src
|
454
|
-
}]);
|
455
|
-
}
|
456
|
-
if (typeof src[FILE_REF_PROP] !== "string") {
|
457
|
-
return _defineProperty({}, path, [{
|
458
|
-
message: "Image did not have a file reference string. Got: ".concat(_typeof(src[FILE_REF_PROP])),
|
459
|
-
value: src
|
460
|
-
}]);
|
461
|
-
}
|
462
|
-
if (src[VAL_EXTENSION] !== "file") {
|
463
|
-
return _defineProperty({}, path, [{
|
464
|
-
message: "Image did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
|
465
|
-
value: src
|
466
|
-
}]);
|
467
|
-
}
|
468
|
-
if (src.metadata) {
|
469
|
-
return _defineProperty({}, path, [{
|
470
|
-
message: "Found metadata, but it could not be validated. Image metadata must be an object with the required props: width (positive number), height (positive number) and sha256 (string of length 64 of the base16 hash).",
|
471
|
-
// These validation errors will have to be picked up by logic outside of this package and revalidated. Reasons: 1) we have to read files to verify the metadata, which is handled differently in different runtimes (Browser, QuickJS, Node.js); 2) we want to keep this package dependency free.
|
472
|
-
value: src,
|
473
|
-
fixes: ["image:replace-metadata"]
|
474
|
-
}]);
|
475
|
-
}
|
476
|
-
return _defineProperty({}, path, [{
|
477
|
-
message: "Could not validate Image metadata.",
|
478
|
-
value: src,
|
479
|
-
fixes: ["image:add-metadata"]
|
480
|
-
}]);
|
481
|
-
}
|
482
|
-
}, {
|
483
|
-
key: "assert",
|
484
|
-
value: function assert(src) {
|
485
|
-
if (this.opt && (src === null || src === undefined)) {
|
486
|
-
return true;
|
487
|
-
}
|
488
|
-
return (src === null || src === void 0 ? void 0 : src[FILE_REF_PROP]) === "image" && (src === null || src === void 0 ? void 0 : src[VAL_EXTENSION]) === "file";
|
489
|
-
}
|
490
|
-
}, {
|
491
|
-
key: "optional",
|
492
|
-
value: function optional() {
|
493
|
-
return new ImageSchema(this.options, true);
|
494
|
-
}
|
495
|
-
}, {
|
496
|
-
key: "serialize",
|
497
|
-
value: function serialize() {
|
498
|
-
return {
|
499
|
-
type: "image",
|
500
|
-
options: this.options,
|
501
|
-
opt: this.opt
|
502
|
-
};
|
503
|
-
}
|
504
|
-
}]);
|
505
|
-
return ImageSchema;
|
506
|
-
}(Schema);
|
507
|
-
var image = function image(options) {
|
508
|
-
return new ImageSchema(options);
|
509
|
-
};
|
510
|
-
var convertFileSource = function convertFileSource(src) {
|
432
|
+
function convertFileSource(src) {
|
511
433
|
var _src$metadata2;
|
512
434
|
// TODO: /public should be configurable
|
513
435
|
if (!src[FILE_REF_PROP].startsWith("/public")) {
|
@@ -521,7 +443,7 @@ var convertFileSource = function convertFileSource(src) {
|
|
521
443
|
url: src[FILE_REF_PROP].slice("/public".length) + "?sha256=".concat((_src$metadata2 = src.metadata) === null || _src$metadata2 === void 0 ? void 0 : _src$metadata2.sha256),
|
522
444
|
metadata: src.metadata
|
523
445
|
};
|
524
|
-
}
|
446
|
+
}
|
525
447
|
|
526
448
|
function isSerializedVal(val) {
|
527
449
|
return _typeof(val) === "object" && val !== null && val !== undefined && ("val" in val || "valPath" in val);
|
@@ -561,7 +483,6 @@ exports.FILE_REF_PROP = FILE_REF_PROP;
|
|
561
483
|
exports.GenericSelector = GenericSelector;
|
562
484
|
exports.GetSchema = GetSchema;
|
563
485
|
exports.GetSource = GetSource;
|
564
|
-
exports.ImageSchema = ImageSchema;
|
565
486
|
exports.NilSym = NilSym;
|
566
487
|
exports.Path = Path;
|
567
488
|
exports.Schema = Schema;
|
@@ -582,7 +503,6 @@ exports.convertFileSource = convertFileSource;
|
|
582
503
|
exports.file = file;
|
583
504
|
exports.getSchema = getSchema;
|
584
505
|
exports.getValPath = getValPath;
|
585
|
-
exports.image = image;
|
586
506
|
exports.isFile = isFile;
|
587
507
|
exports.isSerializedVal = isSerializedVal;
|
588
508
|
exports.isVal = isVal;
|
@@ -429,85 +429,7 @@ function isFile(obj) {
|
|
429
429
|
return _typeof(obj) === "object" && obj !== null && VAL_EXTENSION in obj && obj[VAL_EXTENSION] === "file" && FILE_REF_PROP in obj && typeof obj[FILE_REF_PROP] === "string";
|
430
430
|
}
|
431
431
|
|
432
|
-
|
433
|
-
_inherits(ImageSchema, _Schema);
|
434
|
-
var _super = _createSuper(ImageSchema);
|
435
|
-
function ImageSchema(options) {
|
436
|
-
var _this;
|
437
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
438
|
-
_classCallCheck(this, ImageSchema);
|
439
|
-
_this = _super.call(this);
|
440
|
-
_this.options = options;
|
441
|
-
_this.opt = opt;
|
442
|
-
return _this;
|
443
|
-
}
|
444
|
-
_createClass(ImageSchema, [{
|
445
|
-
key: "validate",
|
446
|
-
value: function validate(path, src) {
|
447
|
-
if (this.opt && (src === null || src === undefined)) {
|
448
|
-
return false;
|
449
|
-
}
|
450
|
-
if (src === null || src === undefined) {
|
451
|
-
return _defineProperty({}, path, [{
|
452
|
-
message: "Non-optional image was null or undefined.",
|
453
|
-
value: src
|
454
|
-
}]);
|
455
|
-
}
|
456
|
-
if (typeof src[FILE_REF_PROP] !== "string") {
|
457
|
-
return _defineProperty({}, path, [{
|
458
|
-
message: "Image did not have a file reference string. Got: ".concat(_typeof(src[FILE_REF_PROP])),
|
459
|
-
value: src
|
460
|
-
}]);
|
461
|
-
}
|
462
|
-
if (src[VAL_EXTENSION] !== "file") {
|
463
|
-
return _defineProperty({}, path, [{
|
464
|
-
message: "Image did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
|
465
|
-
value: src
|
466
|
-
}]);
|
467
|
-
}
|
468
|
-
if (src.metadata) {
|
469
|
-
return _defineProperty({}, path, [{
|
470
|
-
message: "Found metadata, but it could not be validated. Image metadata must be an object with the required props: width (positive number), height (positive number) and sha256 (string of length 64 of the base16 hash).",
|
471
|
-
// These validation errors will have to be picked up by logic outside of this package and revalidated. Reasons: 1) we have to read files to verify the metadata, which is handled differently in different runtimes (Browser, QuickJS, Node.js); 2) we want to keep this package dependency free.
|
472
|
-
value: src,
|
473
|
-
fixes: ["image:replace-metadata"]
|
474
|
-
}]);
|
475
|
-
}
|
476
|
-
return _defineProperty({}, path, [{
|
477
|
-
message: "Could not validate Image metadata.",
|
478
|
-
value: src,
|
479
|
-
fixes: ["image:add-metadata"]
|
480
|
-
}]);
|
481
|
-
}
|
482
|
-
}, {
|
483
|
-
key: "assert",
|
484
|
-
value: function assert(src) {
|
485
|
-
if (this.opt && (src === null || src === undefined)) {
|
486
|
-
return true;
|
487
|
-
}
|
488
|
-
return (src === null || src === void 0 ? void 0 : src[FILE_REF_PROP]) === "image" && (src === null || src === void 0 ? void 0 : src[VAL_EXTENSION]) === "file";
|
489
|
-
}
|
490
|
-
}, {
|
491
|
-
key: "optional",
|
492
|
-
value: function optional() {
|
493
|
-
return new ImageSchema(this.options, true);
|
494
|
-
}
|
495
|
-
}, {
|
496
|
-
key: "serialize",
|
497
|
-
value: function serialize() {
|
498
|
-
return {
|
499
|
-
type: "image",
|
500
|
-
options: this.options,
|
501
|
-
opt: this.opt
|
502
|
-
};
|
503
|
-
}
|
504
|
-
}]);
|
505
|
-
return ImageSchema;
|
506
|
-
}(Schema);
|
507
|
-
var image = function image(options) {
|
508
|
-
return new ImageSchema(options);
|
509
|
-
};
|
510
|
-
var convertFileSource = function convertFileSource(src) {
|
432
|
+
function convertFileSource(src) {
|
511
433
|
var _src$metadata2;
|
512
434
|
// TODO: /public should be configurable
|
513
435
|
if (!src[FILE_REF_PROP].startsWith("/public")) {
|
@@ -521,7 +443,7 @@ var convertFileSource = function convertFileSource(src) {
|
|
521
443
|
url: src[FILE_REF_PROP].slice("/public".length) + "?sha256=".concat((_src$metadata2 = src.metadata) === null || _src$metadata2 === void 0 ? void 0 : _src$metadata2.sha256),
|
522
444
|
metadata: src.metadata
|
523
445
|
};
|
524
|
-
}
|
446
|
+
}
|
525
447
|
|
526
448
|
function isSerializedVal(val) {
|
527
449
|
return _typeof(val) === "object" && val !== null && val !== undefined && ("val" in val || "valPath" in val);
|
@@ -561,7 +483,6 @@ exports.FILE_REF_PROP = FILE_REF_PROP;
|
|
561
483
|
exports.GenericSelector = GenericSelector;
|
562
484
|
exports.GetSchema = GetSchema;
|
563
485
|
exports.GetSource = GetSource;
|
564
|
-
exports.ImageSchema = ImageSchema;
|
565
486
|
exports.NilSym = NilSym;
|
566
487
|
exports.Path = Path;
|
567
488
|
exports.Schema = Schema;
|
@@ -582,7 +503,6 @@ exports.convertFileSource = convertFileSource;
|
|
582
503
|
exports.file = file;
|
583
504
|
exports.getSchema = getSchema;
|
584
505
|
exports.getValPath = getValPath;
|
585
|
-
exports.image = image;
|
586
506
|
exports.isFile = isFile;
|
587
507
|
exports.isSerializedVal = isSerializedVal;
|
588
508
|
exports.isVal = isVal;
|