@valbuild/core 0.48.1 → 0.50.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 +4 -0
- package/dist/declarations/src/initSchema.d.ts +3 -0
- package/dist/declarations/src/schema/file.d.ts +23 -0
- package/dist/declarations/src/schema/index.d.ts +2 -1
- package/dist/declarations/src/schema/richtext.d.ts +2 -1
- package/dist/declarations/src/schema/validation/ValidationFix.d.ts +1 -1
- package/dist/declarations/src/selector/SelectorProxy.d.ts +2 -2
- package/dist/declarations/src/source/richtext.d.ts +1 -1
- package/dist/{index-7b467ee6.cjs.prod.js → index-0391a11a.cjs.prod.js} +133 -71
- package/dist/{index-799bcf49.esm.js → index-14edbcc8.esm.js} +1 -1
- package/dist/{index-5750c299.esm.js → index-a038a0f3.esm.js} +131 -71
- package/dist/{index-d23e237a.cjs.dev.js → index-b14b0d9c.cjs.dev.js} +133 -71
- package/dist/{index-db60fc1d.cjs.prod.js → index-df01e42d.cjs.prod.js} +1 -1
- package/dist/{index-00276955.cjs.dev.js → index-f66c449e.cjs.dev.js} +1 -1
- package/dist/{ops-ffed3406.esm.js → ops-2029f7c3.esm.js} +11 -17
- package/dist/{ops-74e62ffe.cjs.dev.js → ops-2b3f01fb.cjs.dev.js} +11 -17
- package/dist/{ops-c0e7e3a8.cjs.prod.js → ops-cff2b7c2.cjs.prod.js} +11 -17
- package/dist/valbuild-core.cjs.dev.js +18 -13
- package/dist/valbuild-core.cjs.prod.js +18 -13
- package/dist/valbuild-core.esm.js +19 -15
- 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
@@ -2,6 +2,7 @@ export { initVal } from "./initVal.js";
|
|
2
2
|
export type { InitVal, ValConfig, ValConstructor } from "./initVal.js";
|
3
3
|
export { Schema, type SerializedSchema, type SelectorOfSchema } from "./schema/index.js";
|
4
4
|
export type { ImageMetadata } from "./schema/image.js";
|
5
|
+
export type { FileMetadata } from "./schema/file.js";
|
5
6
|
export type { LinkSource } from "./source/link.js";
|
6
7
|
export type { ValModule, SerializedModule, InferValModuleType } from "./module.js";
|
7
8
|
export type { SourceObject, SourcePrimitive, Source } from "./source/index.js";
|
@@ -28,6 +29,7 @@ import { getVal } from "./future/fetchVal.js";
|
|
28
29
|
import type { Json } from "./Json.js";
|
29
30
|
import { SerializedSchema } from "./schema/index.js";
|
30
31
|
import { PatchJSON } from "./patch/index.js";
|
32
|
+
import { initSchema } from "./initSchema.js";
|
31
33
|
export { ValApi } from "./ValApi.js";
|
32
34
|
export { type SerializedArraySchema, ArraySchema } from "./schema/array.js";
|
33
35
|
export { type SerializedObjectSchema, ObjectSchema } from "./schema/object.js";
|
@@ -36,6 +38,7 @@ export { type SerializedStringSchema, StringSchema } from "./schema/string.js";
|
|
36
38
|
export { type SerializedNumberSchema, NumberSchema } from "./schema/number.js";
|
37
39
|
export { type SerializedBooleanSchema, BooleanSchema } from "./schema/boolean.js";
|
38
40
|
export { type SerializedImageSchema, ImageSchema } from "./schema/image.js";
|
41
|
+
export { type SerializedFileSchema, FileSchema } from "./schema/file.js";
|
39
42
|
export { type SerializedRichTextSchema, RichTextSchema, } from "./schema/richtext.js";
|
40
43
|
export { type SerializedUnionSchema, UnionSchema } from "./schema/union.js";
|
41
44
|
export { type SerializedLiteralSchema, LiteralSchema } from "./schema/literal.js";
|
@@ -92,6 +95,7 @@ declare const Internal: {
|
|
92
95
|
isVal: typeof isVal;
|
93
96
|
createValPathOfItem: typeof createValPathOfItem;
|
94
97
|
getSHA256Hash: (bits: Uint8Array) => string;
|
98
|
+
initSchema: typeof initSchema;
|
95
99
|
createPatchJSONPath: (modulePath: ModulePath) => string;
|
96
100
|
VAL_ENABLE_COOKIE_NAME: "val_enable";
|
97
101
|
VAL_STATE_COOKIE: "val_state";
|
@@ -9,6 +9,7 @@ import { image } from "./schema/image.js";
|
|
9
9
|
import { literal } from "./schema/literal.js";
|
10
10
|
import { keyOf } from "./schema/keyOf.js";
|
11
11
|
import { record } from "./schema/record.js";
|
12
|
+
import { file } from "./schema/file.js";
|
12
13
|
export type InitSchema = {
|
13
14
|
readonly string: typeof string;
|
14
15
|
readonly boolean: typeof boolean;
|
@@ -21,6 +22,7 @@ export type InitSchema = {
|
|
21
22
|
readonly literal: typeof literal;
|
22
23
|
readonly keyOf: typeof keyOf;
|
23
24
|
readonly record: typeof record;
|
25
|
+
readonly file: typeof file;
|
24
26
|
};
|
25
27
|
export declare function initSchema(): {
|
26
28
|
string: <T extends string>(options?: {
|
@@ -53,4 +55,5 @@ export declare function initSchema(): {
|
|
53
55
|
literal: <T_2 extends string>(value: T_2) => import("./schema/index.js").Schema<T_2>;
|
54
56
|
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>;
|
55
57
|
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>>>;
|
58
|
+
file: (options?: import("./schema/file.js").FileOptions | undefined) => import("./schema/index.js").Schema<import("./index.js").FileSource<import("./schema/file.js").FileMetadata>>;
|
56
59
|
};
|
@@ -1,5 +1,28 @@
|
|
1
1
|
import { Json } from "../Json.js";
|
2
2
|
import { FileSource } from "../source/file.js";
|
3
|
+
import { Schema, SerializedSchema } from "./index.js";
|
4
|
+
import { SourcePath } from "../val/index.js";
|
5
|
+
import { ValidationErrors } from "./validation/ValidationError.js";
|
6
|
+
export type FileOptions = Record<string, never>;
|
7
|
+
export type SerializedFileSchema = {
|
8
|
+
type: "file";
|
9
|
+
options?: FileOptions;
|
10
|
+
opt: boolean;
|
11
|
+
};
|
12
|
+
export type FileMetadata = {
|
13
|
+
sha256: string;
|
14
|
+
mimeType?: string;
|
15
|
+
};
|
16
|
+
export declare class FileSchema<Src extends FileSource<FileMetadata | undefined> | null> extends Schema<Src> {
|
17
|
+
readonly options?: FileOptions | undefined;
|
18
|
+
readonly opt: boolean;
|
19
|
+
constructor(options?: FileOptions | undefined, opt?: boolean);
|
20
|
+
validate(path: SourcePath, src: Src): ValidationErrors;
|
21
|
+
assert(src: Src): boolean;
|
22
|
+
optional(): Schema<Src | null>;
|
23
|
+
serialize(): SerializedSchema;
|
24
|
+
}
|
25
|
+
export declare const file: (options?: FileOptions) => Schema<FileSource<FileMetadata>>;
|
3
26
|
export declare function convertFileSource<Metadata extends {
|
4
27
|
readonly [key: string]: Json;
|
5
28
|
} | undefined = {
|
@@ -2,6 +2,7 @@ import { SelectorSource } from "../selector/index.js";
|
|
2
2
|
import { SourcePath } from "../val/index.js";
|
3
3
|
import { SerializedArraySchema } from "./array.js";
|
4
4
|
import { SerializedBooleanSchema } from "./boolean.js";
|
5
|
+
import { SerializedFileSchema } from "./file.js";
|
5
6
|
import { SerializedImageSchema } from "./image.js";
|
6
7
|
import { SerializedKeyOfSchema } from "./keyOf.js";
|
7
8
|
import { SerializedLiteralSchema } from "./literal.js";
|
@@ -12,7 +13,7 @@ import { SerializedRichTextSchema } from "./richtext.js";
|
|
12
13
|
import { SerializedStringSchema } from "./string.js";
|
13
14
|
import { SerializedUnionSchema } from "./union.js";
|
14
15
|
import { ValidationErrors } from "./validation/ValidationError.js";
|
15
|
-
export type SerializedSchema = SerializedStringSchema | SerializedLiteralSchema | SerializedBooleanSchema | SerializedNumberSchema | SerializedObjectSchema | SerializedArraySchema | SerializedUnionSchema | SerializedRichTextSchema | SerializedRecordSchema | SerializedKeyOfSchema | SerializedImageSchema;
|
16
|
+
export type SerializedSchema = SerializedStringSchema | SerializedLiteralSchema | SerializedBooleanSchema | SerializedNumberSchema | SerializedObjectSchema | SerializedArraySchema | SerializedUnionSchema | SerializedRichTextSchema | SerializedRecordSchema | SerializedKeyOfSchema | SerializedFileSchema | SerializedImageSchema;
|
16
17
|
export declare abstract class Schema<Src extends SelectorSource> {
|
17
18
|
abstract validate(path: SourcePath, src: Src): ValidationErrors;
|
18
19
|
abstract assert(src: Src): boolean;
|
@@ -2,9 +2,10 @@ import { Schema, SerializedSchema } from "./index.js";
|
|
2
2
|
import { RichTextSource, RichTextOptions } from "../source/richtext.js";
|
3
3
|
import { SourcePath } from "../val/index.js";
|
4
4
|
import { ValidationErrors } from "./validation/ValidationError.js";
|
5
|
-
export type SerializedRichTextSchema =
|
5
|
+
export type SerializedRichTextSchema = {
|
6
6
|
type: "richtext";
|
7
7
|
opt: boolean;
|
8
|
+
options: RichTextOptions;
|
8
9
|
};
|
9
10
|
export declare class RichTextSchema<O extends RichTextOptions, Src extends RichTextSource<O> | null> extends Schema<Src> {
|
10
11
|
readonly options: O;
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const ValidationFix: readonly ["image:add-metadata", "image:replace-metadata"];
|
1
|
+
export declare const ValidationFix: readonly ["image:add-metadata", "image:replace-metadata", "file:add-metadata", "file:check-metadata"];
|
2
2
|
export type ValidationFix = (typeof ValidationFix)[number];
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { GenericSelector } from "./index.js";
|
2
2
|
import { Source } from "../source/index.js";
|
3
|
-
import { SourcePath } from "../val/index.js";
|
3
|
+
import { ModulePath, SourcePath } from "../val/index.js";
|
4
4
|
export declare function isSelector(source: any): source is GenericSelector<Source>;
|
5
5
|
export declare function newSelectorProxy(source: any, path?: SourcePath, moduleSchema?: any): any;
|
6
|
-
export declare function createValPathOfItem(arrayPath: SourcePath | undefined, prop: string | number | symbol): SourcePath | undefined;
|
6
|
+
export declare function createValPathOfItem(arrayPath: SourcePath | ModulePath | undefined, prop: string | number | symbol): SourcePath | undefined;
|
7
7
|
export declare function selectorToVal(s: any): any;
|
@@ -28,24 +28,24 @@ function _typeof(o) {
|
|
28
28
|
}, _typeof(o);
|
29
29
|
}
|
30
30
|
|
31
|
-
function
|
32
|
-
if (
|
33
|
-
var
|
34
|
-
if (
|
35
|
-
var
|
36
|
-
if (
|
31
|
+
function toPrimitive(t, r) {
|
32
|
+
if ("object" != typeof t || !t) return t;
|
33
|
+
var e = t[Symbol.toPrimitive];
|
34
|
+
if (void 0 !== e) {
|
35
|
+
var i = e.call(t, r || "default");
|
36
|
+
if ("object" != typeof i) return i;
|
37
37
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
38
38
|
}
|
39
|
-
return (
|
39
|
+
return ("string" === r ? String : Number)(t);
|
40
40
|
}
|
41
41
|
|
42
|
-
function
|
43
|
-
var
|
44
|
-
return
|
42
|
+
function toPropertyKey(t) {
|
43
|
+
var i = toPrimitive(t, "string");
|
44
|
+
return "symbol" == typeof i ? i : String(i);
|
45
45
|
}
|
46
46
|
|
47
47
|
function _defineProperty(obj, key, value) {
|
48
|
-
key =
|
48
|
+
key = toPropertyKey(key);
|
49
49
|
if (key in obj) {
|
50
50
|
Object.defineProperty(obj, key, {
|
51
51
|
value: value,
|
@@ -133,7 +133,7 @@ function _defineProperties(target, props) {
|
|
133
133
|
descriptor.enumerable = descriptor.enumerable || false;
|
134
134
|
descriptor.configurable = true;
|
135
135
|
if ("value" in descriptor) descriptor.writable = true;
|
136
|
-
Object.defineProperty(target,
|
136
|
+
Object.defineProperty(target, toPropertyKey(descriptor.key), descriptor);
|
137
137
|
}
|
138
138
|
}
|
139
139
|
function _createClass(Constructor, protoProps, staticProps) {
|
@@ -145,31 +145,6 @@ function _createClass(Constructor, protoProps, staticProps) {
|
|
145
145
|
return Constructor;
|
146
146
|
}
|
147
147
|
|
148
|
-
function _setPrototypeOf(o, p) {
|
149
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
150
|
-
o.__proto__ = p;
|
151
|
-
return o;
|
152
|
-
};
|
153
|
-
return _setPrototypeOf(o, p);
|
154
|
-
}
|
155
|
-
|
156
|
-
function _inherits(subClass, superClass) {
|
157
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
158
|
-
throw new TypeError("Super expression must either be null or a function");
|
159
|
-
}
|
160
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
161
|
-
constructor: {
|
162
|
-
value: subClass,
|
163
|
-
writable: true,
|
164
|
-
configurable: true
|
165
|
-
}
|
166
|
-
});
|
167
|
-
Object.defineProperty(subClass, "prototype", {
|
168
|
-
writable: false
|
169
|
-
});
|
170
|
-
if (superClass) _setPrototypeOf(subClass, superClass);
|
171
|
-
}
|
172
|
-
|
173
148
|
function _getPrototypeOf(o) {
|
174
149
|
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
175
150
|
return o.__proto__ || Object.getPrototypeOf(o);
|
@@ -178,15 +153,12 @@ function _getPrototypeOf(o) {
|
|
178
153
|
}
|
179
154
|
|
180
155
|
function _isNativeReflectConstruct() {
|
181
|
-
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
182
|
-
if (Reflect.construct.sham) return false;
|
183
|
-
if (typeof Proxy === "function") return true;
|
184
156
|
try {
|
185
|
-
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
186
|
-
|
187
|
-
|
188
|
-
return
|
189
|
-
}
|
157
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
158
|
+
} catch (t) {}
|
159
|
+
return (_isNativeReflectConstruct = function () {
|
160
|
+
return !!t;
|
161
|
+
})();
|
190
162
|
}
|
191
163
|
|
192
164
|
function _assertThisInitialized(self) {
|
@@ -205,25 +177,40 @@ function _possibleConstructorReturn(self, call) {
|
|
205
177
|
return _assertThisInitialized(self);
|
206
178
|
}
|
207
179
|
|
208
|
-
function
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
} else {
|
217
|
-
result = Super.apply(this, arguments);
|
218
|
-
}
|
219
|
-
return _possibleConstructorReturn(this, result);
|
180
|
+
function _callSuper(t, o, e) {
|
181
|
+
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
|
182
|
+
}
|
183
|
+
|
184
|
+
function _setPrototypeOf(o, p) {
|
185
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
186
|
+
o.__proto__ = p;
|
187
|
+
return o;
|
220
188
|
};
|
189
|
+
return _setPrototypeOf(o, p);
|
190
|
+
}
|
191
|
+
|
192
|
+
function _inherits(subClass, superClass) {
|
193
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
194
|
+
throw new TypeError("Super expression must either be null or a function");
|
195
|
+
}
|
196
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
197
|
+
constructor: {
|
198
|
+
value: subClass,
|
199
|
+
writable: true,
|
200
|
+
configurable: true
|
201
|
+
}
|
202
|
+
});
|
203
|
+
Object.defineProperty(subClass, "prototype", {
|
204
|
+
writable: false
|
205
|
+
});
|
206
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
221
207
|
}
|
222
208
|
|
223
209
|
// import { RemoteCompatibleSource, RemoteSource } from "../source/remote";
|
224
210
|
|
225
211
|
// import { SerializedI18nSchema } from "./future/i18n";
|
226
212
|
// import { SerializedOneOfSchema } from "./future/oneOf";
|
213
|
+
|
227
214
|
var Schema = /*#__PURE__*/function () {
|
228
215
|
function Schema() {
|
229
216
|
_classCallCheck(this, Schema);
|
@@ -309,11 +296,10 @@ var Expr = /*#__PURE__*/_createClass(function Expr(span) {
|
|
309
296
|
});
|
310
297
|
var StringLiteral = /*#__PURE__*/function (_Expr) {
|
311
298
|
_inherits(StringLiteral, _Expr);
|
312
|
-
var _super = _createSuper(StringLiteral);
|
313
299
|
function StringLiteral(value, span) {
|
314
300
|
var _this;
|
315
301
|
_classCallCheck(this, StringLiteral);
|
316
|
-
_this =
|
302
|
+
_this = _callSuper(this, StringLiteral, [span]);
|
317
303
|
_defineProperty(_assertThisInitialized(_this), "type", "StringLiteral");
|
318
304
|
_this.value = value;
|
319
305
|
return _this;
|
@@ -328,11 +314,10 @@ var StringLiteral = /*#__PURE__*/function (_Expr) {
|
|
328
314
|
}(Expr);
|
329
315
|
var Sym = /*#__PURE__*/function (_Expr2) {
|
330
316
|
_inherits(Sym, _Expr2);
|
331
|
-
var _super2 = _createSuper(Sym);
|
332
317
|
function Sym(value, span) {
|
333
318
|
var _this2;
|
334
319
|
_classCallCheck(this, Sym);
|
335
|
-
_this2 =
|
320
|
+
_this2 = _callSuper(this, Sym, [span]);
|
336
321
|
_defineProperty(_assertThisInitialized(_this2), "type", "Sym");
|
337
322
|
_this2.value = value;
|
338
323
|
return _this2;
|
@@ -348,11 +333,10 @@ var Sym = /*#__PURE__*/function (_Expr2) {
|
|
348
333
|
var NilSym = new Sym("()");
|
349
334
|
var StringTemplate = /*#__PURE__*/function (_Expr3) {
|
350
335
|
_inherits(StringTemplate, _Expr3);
|
351
|
-
var _super3 = _createSuper(StringTemplate);
|
352
336
|
function StringTemplate(children, span) {
|
353
337
|
var _this3;
|
354
338
|
_classCallCheck(this, StringTemplate);
|
355
|
-
_this3 =
|
339
|
+
_this3 = _callSuper(this, StringTemplate, [span]);
|
356
340
|
_defineProperty(_assertThisInitialized(_this3), "type", "StringTemplate");
|
357
341
|
_this3.children = children;
|
358
342
|
return _this3;
|
@@ -373,11 +357,10 @@ var StringTemplate = /*#__PURE__*/function (_Expr3) {
|
|
373
357
|
}(Expr);
|
374
358
|
var Call = /*#__PURE__*/function (_Expr4) {
|
375
359
|
_inherits(Call, _Expr4);
|
376
|
-
var _super4 = _createSuper(Call);
|
377
360
|
function Call(children, isAnon, span) {
|
378
361
|
var _this4;
|
379
362
|
_classCallCheck(this, Call);
|
380
|
-
_this4 =
|
363
|
+
_this4 = _callSuper(this, Call, [span]);
|
381
364
|
_defineProperty(_assertThisInitialized(_this4), "type", "Call");
|
382
365
|
_this4.children = children;
|
383
366
|
_this4.isAnon = isAnon;
|
@@ -422,25 +405,102 @@ var FILE_REF_PROP = "_ref";
|
|
422
405
|
*
|
423
406
|
*/
|
424
407
|
|
425
|
-
function file(ref, metadata) {
|
408
|
+
function file$1(ref, metadata) {
|
426
409
|
return _defineProperty(_defineProperty(_defineProperty({}, FILE_REF_PROP, ref), VAL_EXTENSION, "file"), "metadata", metadata);
|
427
410
|
}
|
428
411
|
function isFile(obj) {
|
429
412
|
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
413
|
}
|
431
414
|
|
415
|
+
var FileSchema = /*#__PURE__*/function (_Schema) {
|
416
|
+
_inherits(FileSchema, _Schema);
|
417
|
+
function FileSchema(options) {
|
418
|
+
var _this;
|
419
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
420
|
+
_classCallCheck(this, FileSchema);
|
421
|
+
_this = _callSuper(this, FileSchema);
|
422
|
+
_this.options = options;
|
423
|
+
_this.opt = opt;
|
424
|
+
return _this;
|
425
|
+
}
|
426
|
+
_createClass(FileSchema, [{
|
427
|
+
key: "validate",
|
428
|
+
value: function validate(path, src) {
|
429
|
+
if (this.opt && (src === null || src === undefined)) {
|
430
|
+
return false;
|
431
|
+
}
|
432
|
+
if (src === null || src === undefined) {
|
433
|
+
return _defineProperty({}, path, [{
|
434
|
+
message: "Non-optional file was null or undefined.",
|
435
|
+
value: src
|
436
|
+
}]);
|
437
|
+
}
|
438
|
+
if (typeof src[FILE_REF_PROP] !== "string") {
|
439
|
+
return _defineProperty({}, path, [{
|
440
|
+
message: "File did not have a file reference string. Got: ".concat(_typeof(src[FILE_REF_PROP])),
|
441
|
+
value: src
|
442
|
+
}]);
|
443
|
+
}
|
444
|
+
if (src[VAL_EXTENSION] !== "file") {
|
445
|
+
return _defineProperty({}, path, [{
|
446
|
+
message: "File did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
|
447
|
+
value: src
|
448
|
+
}]);
|
449
|
+
}
|
450
|
+
if (src.metadata) {
|
451
|
+
return _defineProperty({}, path, [{
|
452
|
+
message: "Found metadata, but it could not be validated. File 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).",
|
453
|
+
// 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.
|
454
|
+
value: src,
|
455
|
+
fixes: ["file:check-metadata"]
|
456
|
+
}]);
|
457
|
+
}
|
458
|
+
return _defineProperty({}, path, [{
|
459
|
+
message: "Missing File metadata.",
|
460
|
+
value: src,
|
461
|
+
fixes: ["file:add-metadata"]
|
462
|
+
}]);
|
463
|
+
}
|
464
|
+
}, {
|
465
|
+
key: "assert",
|
466
|
+
value: function assert(src) {
|
467
|
+
if (this.opt && (src === null || src === undefined)) {
|
468
|
+
return true;
|
469
|
+
}
|
470
|
+
return (src === null || src === void 0 ? void 0 : src[FILE_REF_PROP]) === "file" && (src === null || src === void 0 ? void 0 : src[VAL_EXTENSION]) === "file";
|
471
|
+
}
|
472
|
+
}, {
|
473
|
+
key: "optional",
|
474
|
+
value: function optional() {
|
475
|
+
return new FileSchema(this.options, true);
|
476
|
+
}
|
477
|
+
}, {
|
478
|
+
key: "serialize",
|
479
|
+
value: function serialize() {
|
480
|
+
return {
|
481
|
+
type: "file",
|
482
|
+
options: this.options,
|
483
|
+
opt: this.opt
|
484
|
+
};
|
485
|
+
}
|
486
|
+
}]);
|
487
|
+
return FileSchema;
|
488
|
+
}(Schema);
|
489
|
+
var file = function file(options) {
|
490
|
+
return new FileSchema(options);
|
491
|
+
};
|
432
492
|
function convertFileSource(src) {
|
433
|
-
var _src$
|
493
|
+
var _src$metadata3, _src$metadata4;
|
434
494
|
// TODO: /public should be configurable
|
435
495
|
if (!src[FILE_REF_PROP].startsWith("/public")) {
|
436
|
-
var _src$metadata;
|
496
|
+
var _src$metadata, _src$metadata2;
|
437
497
|
return {
|
438
|
-
url: src[FILE_REF_PROP] + "?sha256=".concat((_src$
|
498
|
+
url: src[FILE_REF_PROP] + ((_src$metadata = src.metadata) !== null && _src$metadata !== void 0 && _src$metadata.sha256 ? "?sha256=".concat((_src$metadata2 = src.metadata) === null || _src$metadata2 === void 0 ? void 0 : _src$metadata2.sha256) : ""),
|
439
499
|
metadata: src.metadata
|
440
500
|
};
|
441
501
|
}
|
442
502
|
return {
|
443
|
-
url: src[FILE_REF_PROP].slice("/public".length) + "?sha256=".concat((_src$
|
503
|
+
url: src[FILE_REF_PROP].slice("/public".length) + ((_src$metadata3 = src.metadata) !== null && _src$metadata3 !== void 0 && _src$metadata3.sha256 ? "?sha256=".concat((_src$metadata4 = src.metadata) === null || _src$metadata4 === void 0 ? void 0 : _src$metadata4.sha256) : ""),
|
444
504
|
metadata: src.metadata
|
445
505
|
};
|
446
506
|
}
|
@@ -480,6 +540,7 @@ function getValPath(valOrSelector) {
|
|
480
540
|
exports.Call = Call;
|
481
541
|
exports.Expr = Expr;
|
482
542
|
exports.FILE_REF_PROP = FILE_REF_PROP;
|
543
|
+
exports.FileSchema = FileSchema;
|
483
544
|
exports.GenericSelector = GenericSelector;
|
484
545
|
exports.GetSchema = GetSchema;
|
485
546
|
exports.GetSource = GetSource;
|
@@ -490,9 +551,9 @@ exports.StringLiteral = StringLiteral;
|
|
490
551
|
exports.StringTemplate = StringTemplate;
|
491
552
|
exports.Sym = Sym;
|
492
553
|
exports.VAL_EXTENSION = VAL_EXTENSION;
|
554
|
+
exports._callSuper = _callSuper;
|
493
555
|
exports._classCallCheck = _classCallCheck;
|
494
556
|
exports._createClass = _createClass;
|
495
|
-
exports._createSuper = _createSuper;
|
496
557
|
exports._defineProperty = _defineProperty;
|
497
558
|
exports._inherits = _inherits;
|
498
559
|
exports._objectSpread2 = _objectSpread2;
|
@@ -501,6 +562,7 @@ exports._toConsumableArray = _toConsumableArray;
|
|
501
562
|
exports._typeof = _typeof;
|
502
563
|
exports.convertFileSource = convertFileSource;
|
503
564
|
exports.file = file;
|
565
|
+
exports.file$1 = file$1;
|
504
566
|
exports.getSchema = getSchema;
|
505
567
|
exports.getValPath = getValPath;
|
506
568
|
exports.isFile = isFile;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { r as _objectSpread2, i as _slicedToArray, c as _createClass, a as _classCallCheck, s as Sym, C as Call, t as StringLiteral, u as StringTemplate, e as _typeof, l as isSerializedVal, F as FILE_REF_PROP, V as VAL_EXTENSION, m as convertFileSource, d as _defineProperty, E as Expr, S as Schema, v as _toConsumableArray, N as NilSym } from './index-a038a0f3.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", " "];
|