@valbuild/core 0.43.0 → 0.44.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 +2 -2
- package/dist/declarations/src/initSchema.d.ts +3 -3
- package/dist/declarations/src/module.d.ts +3 -3
- package/dist/declarations/src/schema/array.d.ts +6 -6
- package/dist/declarations/src/schema/index.d.ts +1 -1
- package/dist/declarations/src/schema/object.d.ts +3 -3
- package/dist/declarations/src/schema/record.d.ts +6 -6
- package/dist/declarations/src/schema/validation/ValidationError.d.ts +1 -0
- package/dist/{ops-e02ab215.cjs.dev.js → ops-422169e5.cjs.dev.js} +201 -2
- package/dist/{ops-d88e99cd.cjs.prod.js → ops-5bd1bd7a.cjs.prod.js} +201 -2
- package/dist/{ops-266faf09.esm.js → ops-899d8bef.esm.js} +201 -3
- package/dist/valbuild-core.cjs.dev.js +2 -63
- package/dist/valbuild-core.cjs.prod.js +2 -63
- package/dist/valbuild-core.esm.js +1 -62
- package/package.json +1 -1
- package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
- package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
- package/patch/dist/valbuild-core-patch.esm.js +2 -2
@@ -1,9 +1,9 @@
|
|
1
1
|
export { initVal } from "./initVal.js";
|
2
2
|
export type { InitVal, ValConfig, ValConstructor } from "./initVal.js";
|
3
|
-
export { Schema, type SerializedSchema } from "./schema/index.js";
|
3
|
+
export { Schema, type SerializedSchema, type SelectorOfSchema } from "./schema/index.js";
|
4
4
|
export type { ImageMetadata } from "./schema/image.js";
|
5
5
|
export type { LinkSource } from "./source/link.js";
|
6
|
-
export type { ValModule, SerializedModule } from "./module.js";
|
6
|
+
export type { ValModule, SerializedModule, InferValModuleType } from "./module.js";
|
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";
|
@@ -28,10 +28,10 @@ export declare function initSchema(): {
|
|
28
28
|
minLength?: number | undefined;
|
29
29
|
} | undefined) => import("./schema/string.js").StringSchema<T>;
|
30
30
|
boolean: () => import("./schema/index.js").Schema<boolean>;
|
31
|
-
array: <S extends import("./schema/index.js").Schema<import("./selector/index.js").SelectorSource>>(schema: S) => import("./schema/index.js").Schema<import("./schema/index.js").
|
31
|
+
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>[]>;
|
32
32
|
object: <Props extends {
|
33
33
|
[key: string]: import("./schema/index.js").Schema<import("./selector/index.js").SelectorSource>;
|
34
|
-
}>(schema: Props) => import("./schema/index.js").Schema<{ [key in keyof Props]: import("./schema/index.js").
|
34
|
+
}>(schema: Props) => import("./schema/index.js").Schema<{ [key in keyof Props]: import("./schema/index.js").SelectorOfSchema<Props[key]>; }>;
|
35
35
|
number: (options?: {
|
36
36
|
max?: number | undefined;
|
37
37
|
min?: number | undefined;
|
@@ -51,5 +51,5 @@ export declare function initSchema(): {
|
|
51
51
|
image: (options?: import("./schema/image.js").ImageOptions | undefined) => import("./schema/index.js").Schema<import("./index.js").FileSource<import("./schema/image.js").ImageMetadata>>;
|
52
52
|
literal: <T_2 extends string>(value: T_2) => import("./schema/index.js").Schema<T_2>;
|
53
53
|
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
|
-
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").
|
54
|
+
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>>>;
|
55
55
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Schema,
|
1
|
+
import { Schema, SelectorOfSchema, SerializedSchema } from "./schema/index.js";
|
2
2
|
import { GenericSelector, SelectorOf, SelectorSource } from "./selector/index.js";
|
3
3
|
import { Source } from "./source/index.js";
|
4
4
|
import { ModuleId, ModulePath, SourcePath } from "./val/index.js";
|
@@ -9,13 +9,13 @@ export type ValModule<T extends SelectorSource> = SelectorOf<T> & ValModuleBrand
|
|
9
9
|
export type ValModuleBrand = {
|
10
10
|
[brand]: "ValModule";
|
11
11
|
};
|
12
|
-
export type
|
12
|
+
export type InferValModuleType<T extends ValModule<SelectorSource>> = T extends GenericSelector<infer S> ? S : never;
|
13
13
|
type ReplaceRawStringWithString<T extends SelectorSource> = SelectorSource extends T ? T : T extends RawString ? string : T extends {
|
14
14
|
[key in string]: SelectorSource;
|
15
15
|
} ? {
|
16
16
|
[key in keyof T]: ReplaceRawStringWithString<T[key]>;
|
17
17
|
} : T extends SelectorSource[] ? ReplaceRawStringWithString<T[number]>[] : T;
|
18
|
-
export declare function content<T extends Schema<SelectorSource>>(id: string, schema: T, source: ReplaceRawStringWithString<
|
18
|
+
export declare function content<T extends Schema<SelectorSource>>(id: string, schema: T, source: ReplaceRawStringWithString<SelectorOfSchema<T>>): ValModule<SelectorOfSchema<T>>;
|
19
19
|
export declare function getSource(valModule: ValModule<SelectorSource>): Source;
|
20
20
|
export declare function splitModuleIdAndModulePath(path: SourcePath): [moduleId: ModuleId, path: ModulePath];
|
21
21
|
export declare function getSourceAtPath(modulePath: ModulePath, valModule: ValModule<SelectorSource> | Source): any;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Schema,
|
1
|
+
import { Schema, SelectorOfSchema, SerializedSchema } from "./index.js";
|
2
2
|
import { SelectorSource } from "../selector/index.js";
|
3
3
|
import { SourcePath } from "../val/index.js";
|
4
4
|
import { ValidationErrors } from "./validation/ValidationError.js";
|
@@ -7,13 +7,13 @@ export type SerializedArraySchema = {
|
|
7
7
|
item: SerializedSchema;
|
8
8
|
opt: boolean;
|
9
9
|
};
|
10
|
-
export declare class ArraySchema<T extends Schema<SelectorSource>> extends Schema<
|
10
|
+
export declare class ArraySchema<T extends Schema<SelectorSource>> extends Schema<SelectorOfSchema<T>[]> {
|
11
11
|
readonly item: T;
|
12
12
|
readonly opt: boolean;
|
13
13
|
constructor(item: T, opt?: boolean);
|
14
|
-
validate(path: SourcePath, src:
|
15
|
-
assert(src:
|
16
|
-
optional(): Schema<
|
14
|
+
validate(path: SourcePath, src: SelectorOfSchema<T>[]): ValidationErrors;
|
15
|
+
assert(src: SelectorOfSchema<T>[]): boolean;
|
16
|
+
optional(): Schema<SelectorOfSchema<T>[] | null>;
|
17
17
|
serialize(): SerializedArraySchema;
|
18
18
|
}
|
19
|
-
export declare const array: <S extends Schema<SelectorSource>>(schema: S) => Schema<
|
19
|
+
export declare const array: <S extends Schema<SelectorSource>>(schema: S) => Schema<SelectorOfSchema<S>[]>;
|
@@ -21,4 +21,4 @@ export declare abstract class Schema<Src extends SelectorSource> {
|
|
21
21
|
/** MUTATES! since internal and perf sensitive */
|
22
22
|
protected appendValidationError(current: ValidationErrors, path: SourcePath, message: string, value?: unknown): ValidationErrors;
|
23
23
|
}
|
24
|
-
export type
|
24
|
+
export type SelectorOfSchema<T extends Schema<SelectorSource>> = T extends Schema<infer Src> ? Src : never;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Schema,
|
1
|
+
import { Schema, SelectorOfSchema, SerializedSchema } from "./index.js";
|
2
2
|
import { SelectorSource } from "../selector/index.js";
|
3
3
|
import { SourcePath } from "../val/index.js";
|
4
4
|
import { ValidationErrors } from "./validation/ValidationError.js";
|
@@ -11,7 +11,7 @@ type ObjectSchemaProps = {
|
|
11
11
|
[key: string]: Schema<SelectorSource>;
|
12
12
|
};
|
13
13
|
type ObjectSchemaSrcOf<Props extends ObjectSchemaProps> = {
|
14
|
-
[key in keyof Props]:
|
14
|
+
[key in keyof Props]: SelectorOfSchema<Props[key]>;
|
15
15
|
};
|
16
16
|
export declare class ObjectSchema<Props extends ObjectSchemaProps> extends Schema<ObjectSchemaSrcOf<Props>> {
|
17
17
|
readonly items: Props;
|
@@ -22,5 +22,5 @@ export declare class ObjectSchema<Props extends ObjectSchemaProps> extends Schem
|
|
22
22
|
optional(): Schema<ObjectSchemaSrcOf<Props> | null>;
|
23
23
|
serialize(): SerializedSchema;
|
24
24
|
}
|
25
|
-
export declare const object: <Props extends ObjectSchemaProps>(schema: Props) => Schema<{ [key in keyof Props]:
|
25
|
+
export declare const object: <Props extends ObjectSchemaProps>(schema: Props) => Schema<{ [key in keyof Props]: SelectorOfSchema<Props[key]>; }>;
|
26
26
|
export {};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Schema,
|
1
|
+
import { Schema, SelectorOfSchema, SerializedSchema } from "./index.js";
|
2
2
|
import { SelectorSource } from "../selector/index.js";
|
3
3
|
import { SourcePath } from "../val/index.js";
|
4
4
|
import { ValidationErrors } from "./validation/ValidationError.js";
|
@@ -7,13 +7,13 @@ export type SerializedRecordSchema = {
|
|
7
7
|
item: SerializedSchema;
|
8
8
|
opt: boolean;
|
9
9
|
};
|
10
|
-
export declare class RecordSchema<T extends Schema<SelectorSource>> extends Schema<Record<string,
|
10
|
+
export declare class RecordSchema<T extends Schema<SelectorSource>> extends Schema<Record<string, SelectorOfSchema<T>>> {
|
11
11
|
readonly item: T;
|
12
12
|
readonly opt: boolean;
|
13
13
|
constructor(item: T, opt?: boolean);
|
14
|
-
validate(path: SourcePath, src: Record<string,
|
15
|
-
assert(src: Record<string,
|
16
|
-
optional(): Schema<Record<string,
|
14
|
+
validate(path: SourcePath, src: Record<string, SelectorOfSchema<T>>): ValidationErrors;
|
15
|
+
assert(src: Record<string, SelectorOfSchema<T>>): boolean;
|
16
|
+
optional(): Schema<Record<string, SelectorOfSchema<T>> | null>;
|
17
17
|
serialize(): SerializedRecordSchema;
|
18
18
|
}
|
19
|
-
export declare const record: <S extends Schema<SelectorSource>>(schema: S) => Schema<Record<string,
|
19
|
+
export declare const record: <S extends Schema<SelectorSource>>(schema: S) => Schema<Record<string, SelectorOfSchema<S>>>;
|
@@ -163,6 +163,8 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
163
163
|
value: function validate(path, src) {
|
164
164
|
var _this2 = this;
|
165
165
|
var error = false;
|
166
|
+
|
167
|
+
// TODO: src should never be undefined
|
166
168
|
if (this.opt && (src === null || src === undefined)) {
|
167
169
|
return false;
|
168
170
|
}
|
@@ -328,6 +330,67 @@ var array = function array(schema) {
|
|
328
330
|
return new ArraySchema(schema);
|
329
331
|
};
|
330
332
|
|
333
|
+
var LiteralSchema = /*#__PURE__*/function (_Schema) {
|
334
|
+
index._inherits(LiteralSchema, _Schema);
|
335
|
+
var _super = index._createSuper(LiteralSchema);
|
336
|
+
function LiteralSchema(value) {
|
337
|
+
var _this;
|
338
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
339
|
+
index._classCallCheck(this, LiteralSchema);
|
340
|
+
_this = _super.call(this);
|
341
|
+
_this.value = value;
|
342
|
+
_this.opt = opt;
|
343
|
+
return _this;
|
344
|
+
}
|
345
|
+
index._createClass(LiteralSchema, [{
|
346
|
+
key: "validate",
|
347
|
+
value: function validate(path, src) {
|
348
|
+
if (this.opt && (src === null || src === undefined)) {
|
349
|
+
return false;
|
350
|
+
}
|
351
|
+
if (typeof src !== "string") {
|
352
|
+
return index._defineProperty({}, path, [{
|
353
|
+
message: "Expected 'string', got '".concat(index._typeof(src), "'"),
|
354
|
+
value: src
|
355
|
+
}]);
|
356
|
+
}
|
357
|
+
if (src !== this.value) {
|
358
|
+
return index._defineProperty({}, path, [{
|
359
|
+
message: "Expected literal '".concat(this.value, "', got '").concat(src, "'"),
|
360
|
+
value: src
|
361
|
+
}]);
|
362
|
+
}
|
363
|
+
return false;
|
364
|
+
}
|
365
|
+
}, {
|
366
|
+
key: "assert",
|
367
|
+
value: function assert(src) {
|
368
|
+
if (this.opt && (src === null || src === undefined)) {
|
369
|
+
return true;
|
370
|
+
}
|
371
|
+
return typeof src === "string";
|
372
|
+
}
|
373
|
+
}, {
|
374
|
+
key: "optional",
|
375
|
+
value: function optional() {
|
376
|
+
return new LiteralSchema(this.value, true);
|
377
|
+
}
|
378
|
+
}, {
|
379
|
+
key: "serialize",
|
380
|
+
value: function serialize() {
|
381
|
+
return {
|
382
|
+
type: "literal",
|
383
|
+
value: this.value,
|
384
|
+
opt: this.opt
|
385
|
+
};
|
386
|
+
}
|
387
|
+
}]);
|
388
|
+
return LiteralSchema;
|
389
|
+
}(index.Schema);
|
390
|
+
var literal = function literal(value) {
|
391
|
+
return new LiteralSchema(value);
|
392
|
+
};
|
393
|
+
|
331
394
|
var UnionSchema = /*#__PURE__*/function (_Schema) {
|
332
395
|
index._inherits(UnionSchema, _Schema);
|
333
396
|
var _super = index._createSuper(UnionSchema);
|
@@ -344,8 +407,143 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
|
|
344
407
|
index._createClass(UnionSchema, [{
|
345
408
|
key: "validate",
|
346
409
|
value: function validate(path, src) {
|
347
|
-
|
348
|
-
|
410
|
+
var unknownSrc = src;
|
411
|
+
var errors = false;
|
412
|
+
if (this.opt && (unknownSrc === null || unknownSrc === undefined)) {
|
413
|
+
// TODO: src should never be undefined
|
414
|
+
return false;
|
415
|
+
}
|
416
|
+
if (!this.key) {
|
417
|
+
return index._defineProperty({}, path, [{
|
418
|
+
message: "Missing required first argument in union"
|
419
|
+
}]);
|
420
|
+
}
|
421
|
+
var key = this.key;
|
422
|
+
if (!Array.isArray(this.items)) {
|
423
|
+
return index._defineProperty({}, path, [{
|
424
|
+
message: "A union schema must take more than 1 schema arguments",
|
425
|
+
fatal: true
|
426
|
+
}]);
|
427
|
+
}
|
428
|
+
if (typeof key === "string") {
|
429
|
+
// tagged union
|
430
|
+
if (this.items.some(function (item) {
|
431
|
+
return !(item instanceof ObjectSchema);
|
432
|
+
})) {
|
433
|
+
return index._defineProperty({}, path, [{
|
434
|
+
message: "Key is a string, so all schema items must be objects",
|
435
|
+
fatal: true
|
436
|
+
}]);
|
437
|
+
}
|
438
|
+
var objectSchemas = this.items;
|
439
|
+
var serializedSchemas = objectSchemas.map(function (schema) {
|
440
|
+
return schema.serialize();
|
441
|
+
});
|
442
|
+
var illegalSchemas = serializedSchemas.filter(function (schema) {
|
443
|
+
return !(schema.type === "object") || !(schema.items[key].type === "literal");
|
444
|
+
});
|
445
|
+
if (illegalSchemas.length > 0) {
|
446
|
+
return index._defineProperty({}, path, [{
|
447
|
+
message: "All schema items must be objects with a key: ".concat(key, " that is a literal schema. Found: ").concat(JSON.stringify(illegalSchemas, null, 2)),
|
448
|
+
fatal: true
|
449
|
+
}]);
|
450
|
+
}
|
451
|
+
var serializedObjectSchemas = serializedSchemas;
|
452
|
+
var optionalLiterals = serializedObjectSchemas.filter(function (schema) {
|
453
|
+
return schema.items[key].opt;
|
454
|
+
});
|
455
|
+
if (optionalLiterals.length > 1) {
|
456
|
+
return index._defineProperty({}, path, [{
|
457
|
+
message: "Schema cannot have an optional keys: ".concat(key),
|
458
|
+
fatal: true
|
459
|
+
}]);
|
460
|
+
}
|
461
|
+
if (index._typeof(unknownSrc) !== "object") {
|
462
|
+
return index._defineProperty({}, path, [{
|
463
|
+
message: "Expected an object"
|
464
|
+
}]);
|
465
|
+
}
|
466
|
+
var objectSrc = unknownSrc;
|
467
|
+
if (objectSrc[key] === undefined) {
|
468
|
+
return index._defineProperty({}, path, [{
|
469
|
+
message: "Missing required key: ".concat(key)
|
470
|
+
}]);
|
471
|
+
}
|
472
|
+
var foundSchemaLiterals = [];
|
473
|
+
var _iterator = result._createForOfIteratorHelper(serializedObjectSchemas),
|
474
|
+
_step;
|
475
|
+
try {
|
476
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
477
|
+
var schema = _step.value;
|
478
|
+
var schemaKey = schema.items[key];
|
479
|
+
if (schemaKey.type === "literal") {
|
480
|
+
if (!foundSchemaLiterals.includes(schemaKey.value)) {
|
481
|
+
foundSchemaLiterals.push(schemaKey.value);
|
482
|
+
} else {
|
483
|
+
return index._defineProperty({}, path, [{
|
484
|
+
message: "Found duplicate key in schema: ".concat(schemaKey.value),
|
485
|
+
fatal: true
|
486
|
+
}]);
|
487
|
+
}
|
488
|
+
}
|
489
|
+
}
|
490
|
+
} catch (err) {
|
491
|
+
_iterator.e(err);
|
492
|
+
} finally {
|
493
|
+
_iterator.f();
|
494
|
+
}
|
495
|
+
var objectSchemaAtKey = objectSchemas.find(function (schema) {
|
496
|
+
return !schema.items[key].validate(path, objectSrc[key]);
|
497
|
+
});
|
498
|
+
if (!objectSchemaAtKey) {
|
499
|
+
var keyPath = createValPathOfItem(path, key);
|
500
|
+
if (!keyPath) {
|
501
|
+
throw new Error("Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(key));
|
502
|
+
}
|
503
|
+
return index._defineProperty({}, keyPath, [{
|
504
|
+
message: "Invalid key: \"".concat(key, "\". Value was: \"").concat(objectSrc[key], "\". Valid values: ").concat(serializedObjectSchemas.map(function (schema) {
|
505
|
+
var keySchema = schema.items[key];
|
506
|
+
if (keySchema.type === "literal" && keySchema.value) {
|
507
|
+
return "\"".concat(keySchema.value, "\"");
|
508
|
+
} else {
|
509
|
+
// should not happen here, we already checked this
|
510
|
+
throw new Error("Expected literal schema, got ".concat(JSON.stringify(keySchema, null, 2)));
|
511
|
+
}
|
512
|
+
}).join(", "))
|
513
|
+
}]);
|
514
|
+
}
|
515
|
+
var error = objectSchemaAtKey.validate(path, objectSrc);
|
516
|
+
if (error) {
|
517
|
+
return error;
|
518
|
+
}
|
519
|
+
} else if (key instanceof LiteralSchema) {
|
520
|
+
if (this.items.some(function (item) {
|
521
|
+
return !(item instanceof LiteralSchema);
|
522
|
+
})) {
|
523
|
+
return index._defineProperty({}, path, [{
|
524
|
+
message: "Key is a literal schema, so all schema items must be literals",
|
525
|
+
fatal: true
|
526
|
+
}]);
|
527
|
+
}
|
528
|
+
var literalItems = [key].concat(index._toConsumableArray(this.items));
|
529
|
+
if (typeof unknownSrc === "string") {
|
530
|
+
var isMatch = literalItems.some(function (item) {
|
531
|
+
return !item.validate(path, unknownSrc);
|
532
|
+
});
|
533
|
+
if (!isMatch) {
|
534
|
+
return index._defineProperty({}, path, [{
|
535
|
+
message: "Union must match one of the following: ".concat(literalItems.map(function (item) {
|
536
|
+
return "\"".concat(item.value, "\"");
|
537
|
+
}).join(", "))
|
538
|
+
}]);
|
539
|
+
}
|
540
|
+
}
|
541
|
+
} else {
|
542
|
+
return index._defineProperty({}, path, [{
|
543
|
+
message: "Expected a string or literal"
|
544
|
+
}]);
|
545
|
+
}
|
546
|
+
return errors;
|
349
547
|
}
|
350
548
|
}, {
|
351
549
|
key: "assert",
|
@@ -776,6 +974,7 @@ exports.content = content;
|
|
776
974
|
exports.createValPathOfItem = createValPathOfItem;
|
777
975
|
exports.getSource = getSource;
|
778
976
|
exports.isSelector = isSelector;
|
977
|
+
exports.literal = literal;
|
779
978
|
exports.newSelectorProxy = newSelectorProxy;
|
780
979
|
exports.object = object;
|
781
980
|
exports.record = record;
|
@@ -163,6 +163,8 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
163
163
|
value: function validate(path, src) {
|
164
164
|
var _this2 = this;
|
165
165
|
var error = false;
|
166
|
+
|
167
|
+
// TODO: src should never be undefined
|
166
168
|
if (this.opt && (src === null || src === undefined)) {
|
167
169
|
return false;
|
168
170
|
}
|
@@ -328,6 +330,67 @@ var array = function array(schema) {
|
|
328
330
|
return new ArraySchema(schema);
|
329
331
|
};
|
330
332
|
|
333
|
+
var LiteralSchema = /*#__PURE__*/function (_Schema) {
|
334
|
+
index._inherits(LiteralSchema, _Schema);
|
335
|
+
var _super = index._createSuper(LiteralSchema);
|
336
|
+
function LiteralSchema(value) {
|
337
|
+
var _this;
|
338
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
339
|
+
index._classCallCheck(this, LiteralSchema);
|
340
|
+
_this = _super.call(this);
|
341
|
+
_this.value = value;
|
342
|
+
_this.opt = opt;
|
343
|
+
return _this;
|
344
|
+
}
|
345
|
+
index._createClass(LiteralSchema, [{
|
346
|
+
key: "validate",
|
347
|
+
value: function validate(path, src) {
|
348
|
+
if (this.opt && (src === null || src === undefined)) {
|
349
|
+
return false;
|
350
|
+
}
|
351
|
+
if (typeof src !== "string") {
|
352
|
+
return index._defineProperty({}, path, [{
|
353
|
+
message: "Expected 'string', got '".concat(index._typeof(src), "'"),
|
354
|
+
value: src
|
355
|
+
}]);
|
356
|
+
}
|
357
|
+
if (src !== this.value) {
|
358
|
+
return index._defineProperty({}, path, [{
|
359
|
+
message: "Expected literal '".concat(this.value, "', got '").concat(src, "'"),
|
360
|
+
value: src
|
361
|
+
}]);
|
362
|
+
}
|
363
|
+
return false;
|
364
|
+
}
|
365
|
+
}, {
|
366
|
+
key: "assert",
|
367
|
+
value: function assert(src) {
|
368
|
+
if (this.opt && (src === null || src === undefined)) {
|
369
|
+
return true;
|
370
|
+
}
|
371
|
+
return typeof src === "string";
|
372
|
+
}
|
373
|
+
}, {
|
374
|
+
key: "optional",
|
375
|
+
value: function optional() {
|
376
|
+
return new LiteralSchema(this.value, true);
|
377
|
+
}
|
378
|
+
}, {
|
379
|
+
key: "serialize",
|
380
|
+
value: function serialize() {
|
381
|
+
return {
|
382
|
+
type: "literal",
|
383
|
+
value: this.value,
|
384
|
+
opt: this.opt
|
385
|
+
};
|
386
|
+
}
|
387
|
+
}]);
|
388
|
+
return LiteralSchema;
|
389
|
+
}(index.Schema);
|
390
|
+
var literal = function literal(value) {
|
391
|
+
return new LiteralSchema(value);
|
392
|
+
};
|
393
|
+
|
331
394
|
var UnionSchema = /*#__PURE__*/function (_Schema) {
|
332
395
|
index._inherits(UnionSchema, _Schema);
|
333
396
|
var _super = index._createSuper(UnionSchema);
|
@@ -344,8 +407,143 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
|
|
344
407
|
index._createClass(UnionSchema, [{
|
345
408
|
key: "validate",
|
346
409
|
value: function validate(path, src) {
|
347
|
-
|
348
|
-
|
410
|
+
var unknownSrc = src;
|
411
|
+
var errors = false;
|
412
|
+
if (this.opt && (unknownSrc === null || unknownSrc === undefined)) {
|
413
|
+
// TODO: src should never be undefined
|
414
|
+
return false;
|
415
|
+
}
|
416
|
+
if (!this.key) {
|
417
|
+
return index._defineProperty({}, path, [{
|
418
|
+
message: "Missing required first argument in union"
|
419
|
+
}]);
|
420
|
+
}
|
421
|
+
var key = this.key;
|
422
|
+
if (!Array.isArray(this.items)) {
|
423
|
+
return index._defineProperty({}, path, [{
|
424
|
+
message: "A union schema must take more than 1 schema arguments",
|
425
|
+
fatal: true
|
426
|
+
}]);
|
427
|
+
}
|
428
|
+
if (typeof key === "string") {
|
429
|
+
// tagged union
|
430
|
+
if (this.items.some(function (item) {
|
431
|
+
return !(item instanceof ObjectSchema);
|
432
|
+
})) {
|
433
|
+
return index._defineProperty({}, path, [{
|
434
|
+
message: "Key is a string, so all schema items must be objects",
|
435
|
+
fatal: true
|
436
|
+
}]);
|
437
|
+
}
|
438
|
+
var objectSchemas = this.items;
|
439
|
+
var serializedSchemas = objectSchemas.map(function (schema) {
|
440
|
+
return schema.serialize();
|
441
|
+
});
|
442
|
+
var illegalSchemas = serializedSchemas.filter(function (schema) {
|
443
|
+
return !(schema.type === "object") || !(schema.items[key].type === "literal");
|
444
|
+
});
|
445
|
+
if (illegalSchemas.length > 0) {
|
446
|
+
return index._defineProperty({}, path, [{
|
447
|
+
message: "All schema items must be objects with a key: ".concat(key, " that is a literal schema. Found: ").concat(JSON.stringify(illegalSchemas, null, 2)),
|
448
|
+
fatal: true
|
449
|
+
}]);
|
450
|
+
}
|
451
|
+
var serializedObjectSchemas = serializedSchemas;
|
452
|
+
var optionalLiterals = serializedObjectSchemas.filter(function (schema) {
|
453
|
+
return schema.items[key].opt;
|
454
|
+
});
|
455
|
+
if (optionalLiterals.length > 1) {
|
456
|
+
return index._defineProperty({}, path, [{
|
457
|
+
message: "Schema cannot have an optional keys: ".concat(key),
|
458
|
+
fatal: true
|
459
|
+
}]);
|
460
|
+
}
|
461
|
+
if (index._typeof(unknownSrc) !== "object") {
|
462
|
+
return index._defineProperty({}, path, [{
|
463
|
+
message: "Expected an object"
|
464
|
+
}]);
|
465
|
+
}
|
466
|
+
var objectSrc = unknownSrc;
|
467
|
+
if (objectSrc[key] === undefined) {
|
468
|
+
return index._defineProperty({}, path, [{
|
469
|
+
message: "Missing required key: ".concat(key)
|
470
|
+
}]);
|
471
|
+
}
|
472
|
+
var foundSchemaLiterals = [];
|
473
|
+
var _iterator = result._createForOfIteratorHelper(serializedObjectSchemas),
|
474
|
+
_step;
|
475
|
+
try {
|
476
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
477
|
+
var schema = _step.value;
|
478
|
+
var schemaKey = schema.items[key];
|
479
|
+
if (schemaKey.type === "literal") {
|
480
|
+
if (!foundSchemaLiterals.includes(schemaKey.value)) {
|
481
|
+
foundSchemaLiterals.push(schemaKey.value);
|
482
|
+
} else {
|
483
|
+
return index._defineProperty({}, path, [{
|
484
|
+
message: "Found duplicate key in schema: ".concat(schemaKey.value),
|
485
|
+
fatal: true
|
486
|
+
}]);
|
487
|
+
}
|
488
|
+
}
|
489
|
+
}
|
490
|
+
} catch (err) {
|
491
|
+
_iterator.e(err);
|
492
|
+
} finally {
|
493
|
+
_iterator.f();
|
494
|
+
}
|
495
|
+
var objectSchemaAtKey = objectSchemas.find(function (schema) {
|
496
|
+
return !schema.items[key].validate(path, objectSrc[key]);
|
497
|
+
});
|
498
|
+
if (!objectSchemaAtKey) {
|
499
|
+
var keyPath = createValPathOfItem(path, key);
|
500
|
+
if (!keyPath) {
|
501
|
+
throw new Error("Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(key));
|
502
|
+
}
|
503
|
+
return index._defineProperty({}, keyPath, [{
|
504
|
+
message: "Invalid key: \"".concat(key, "\". Value was: \"").concat(objectSrc[key], "\". Valid values: ").concat(serializedObjectSchemas.map(function (schema) {
|
505
|
+
var keySchema = schema.items[key];
|
506
|
+
if (keySchema.type === "literal" && keySchema.value) {
|
507
|
+
return "\"".concat(keySchema.value, "\"");
|
508
|
+
} else {
|
509
|
+
// should not happen here, we already checked this
|
510
|
+
throw new Error("Expected literal schema, got ".concat(JSON.stringify(keySchema, null, 2)));
|
511
|
+
}
|
512
|
+
}).join(", "))
|
513
|
+
}]);
|
514
|
+
}
|
515
|
+
var error = objectSchemaAtKey.validate(path, objectSrc);
|
516
|
+
if (error) {
|
517
|
+
return error;
|
518
|
+
}
|
519
|
+
} else if (key instanceof LiteralSchema) {
|
520
|
+
if (this.items.some(function (item) {
|
521
|
+
return !(item instanceof LiteralSchema);
|
522
|
+
})) {
|
523
|
+
return index._defineProperty({}, path, [{
|
524
|
+
message: "Key is a literal schema, so all schema items must be literals",
|
525
|
+
fatal: true
|
526
|
+
}]);
|
527
|
+
}
|
528
|
+
var literalItems = [key].concat(index._toConsumableArray(this.items));
|
529
|
+
if (typeof unknownSrc === "string") {
|
530
|
+
var isMatch = literalItems.some(function (item) {
|
531
|
+
return !item.validate(path, unknownSrc);
|
532
|
+
});
|
533
|
+
if (!isMatch) {
|
534
|
+
return index._defineProperty({}, path, [{
|
535
|
+
message: "Union must match one of the following: ".concat(literalItems.map(function (item) {
|
536
|
+
return "\"".concat(item.value, "\"");
|
537
|
+
}).join(", "))
|
538
|
+
}]);
|
539
|
+
}
|
540
|
+
}
|
541
|
+
} else {
|
542
|
+
return index._defineProperty({}, path, [{
|
543
|
+
message: "Expected a string or literal"
|
544
|
+
}]);
|
545
|
+
}
|
546
|
+
return errors;
|
349
547
|
}
|
350
548
|
}, {
|
351
549
|
key: "assert",
|
@@ -776,6 +974,7 @@ exports.content = content;
|
|
776
974
|
exports.createValPathOfItem = createValPathOfItem;
|
777
975
|
exports.getSource = getSource;
|
778
976
|
exports.isSelector = isSelector;
|
977
|
+
exports.literal = literal;
|
779
978
|
exports.newSelectorProxy = newSelectorProxy;
|
780
979
|
exports.object = object;
|
781
980
|
exports.record = record;
|
@@ -161,6 +161,8 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
161
161
|
value: function validate(path, src) {
|
162
162
|
var _this2 = this;
|
163
163
|
var error = false;
|
164
|
+
|
165
|
+
// TODO: src should never be undefined
|
164
166
|
if (this.opt && (src === null || src === undefined)) {
|
165
167
|
return false;
|
166
168
|
}
|
@@ -326,6 +328,67 @@ var array = function array(schema) {
|
|
326
328
|
return new ArraySchema(schema);
|
327
329
|
};
|
328
330
|
|
331
|
+
var LiteralSchema = /*#__PURE__*/function (_Schema) {
|
332
|
+
_inherits(LiteralSchema, _Schema);
|
333
|
+
var _super = _createSuper(LiteralSchema);
|
334
|
+
function LiteralSchema(value) {
|
335
|
+
var _this;
|
336
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
337
|
+
_classCallCheck(this, LiteralSchema);
|
338
|
+
_this = _super.call(this);
|
339
|
+
_this.value = value;
|
340
|
+
_this.opt = opt;
|
341
|
+
return _this;
|
342
|
+
}
|
343
|
+
_createClass(LiteralSchema, [{
|
344
|
+
key: "validate",
|
345
|
+
value: function validate(path, src) {
|
346
|
+
if (this.opt && (src === null || src === undefined)) {
|
347
|
+
return false;
|
348
|
+
}
|
349
|
+
if (typeof src !== "string") {
|
350
|
+
return _defineProperty({}, path, [{
|
351
|
+
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
352
|
+
value: src
|
353
|
+
}]);
|
354
|
+
}
|
355
|
+
if (src !== this.value) {
|
356
|
+
return _defineProperty({}, path, [{
|
357
|
+
message: "Expected literal '".concat(this.value, "', got '").concat(src, "'"),
|
358
|
+
value: src
|
359
|
+
}]);
|
360
|
+
}
|
361
|
+
return false;
|
362
|
+
}
|
363
|
+
}, {
|
364
|
+
key: "assert",
|
365
|
+
value: function assert(src) {
|
366
|
+
if (this.opt && (src === null || src === undefined)) {
|
367
|
+
return true;
|
368
|
+
}
|
369
|
+
return typeof src === "string";
|
370
|
+
}
|
371
|
+
}, {
|
372
|
+
key: "optional",
|
373
|
+
value: function optional() {
|
374
|
+
return new LiteralSchema(this.value, true);
|
375
|
+
}
|
376
|
+
}, {
|
377
|
+
key: "serialize",
|
378
|
+
value: function serialize() {
|
379
|
+
return {
|
380
|
+
type: "literal",
|
381
|
+
value: this.value,
|
382
|
+
opt: this.opt
|
383
|
+
};
|
384
|
+
}
|
385
|
+
}]);
|
386
|
+
return LiteralSchema;
|
387
|
+
}(Schema);
|
388
|
+
var literal = function literal(value) {
|
389
|
+
return new LiteralSchema(value);
|
390
|
+
};
|
391
|
+
|
329
392
|
var UnionSchema = /*#__PURE__*/function (_Schema) {
|
330
393
|
_inherits(UnionSchema, _Schema);
|
331
394
|
var _super = _createSuper(UnionSchema);
|
@@ -342,8 +405,143 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
|
|
342
405
|
_createClass(UnionSchema, [{
|
343
406
|
key: "validate",
|
344
407
|
value: function validate(path, src) {
|
345
|
-
|
346
|
-
|
408
|
+
var unknownSrc = src;
|
409
|
+
var errors = false;
|
410
|
+
if (this.opt && (unknownSrc === null || unknownSrc === undefined)) {
|
411
|
+
// TODO: src should never be undefined
|
412
|
+
return false;
|
413
|
+
}
|
414
|
+
if (!this.key) {
|
415
|
+
return _defineProperty({}, path, [{
|
416
|
+
message: "Missing required first argument in union"
|
417
|
+
}]);
|
418
|
+
}
|
419
|
+
var key = this.key;
|
420
|
+
if (!Array.isArray(this.items)) {
|
421
|
+
return _defineProperty({}, path, [{
|
422
|
+
message: "A union schema must take more than 1 schema arguments",
|
423
|
+
fatal: true
|
424
|
+
}]);
|
425
|
+
}
|
426
|
+
if (typeof key === "string") {
|
427
|
+
// tagged union
|
428
|
+
if (this.items.some(function (item) {
|
429
|
+
return !(item instanceof ObjectSchema);
|
430
|
+
})) {
|
431
|
+
return _defineProperty({}, path, [{
|
432
|
+
message: "Key is a string, so all schema items must be objects",
|
433
|
+
fatal: true
|
434
|
+
}]);
|
435
|
+
}
|
436
|
+
var objectSchemas = this.items;
|
437
|
+
var serializedSchemas = objectSchemas.map(function (schema) {
|
438
|
+
return schema.serialize();
|
439
|
+
});
|
440
|
+
var illegalSchemas = serializedSchemas.filter(function (schema) {
|
441
|
+
return !(schema.type === "object") || !(schema.items[key].type === "literal");
|
442
|
+
});
|
443
|
+
if (illegalSchemas.length > 0) {
|
444
|
+
return _defineProperty({}, path, [{
|
445
|
+
message: "All schema items must be objects with a key: ".concat(key, " that is a literal schema. Found: ").concat(JSON.stringify(illegalSchemas, null, 2)),
|
446
|
+
fatal: true
|
447
|
+
}]);
|
448
|
+
}
|
449
|
+
var serializedObjectSchemas = serializedSchemas;
|
450
|
+
var optionalLiterals = serializedObjectSchemas.filter(function (schema) {
|
451
|
+
return schema.items[key].opt;
|
452
|
+
});
|
453
|
+
if (optionalLiterals.length > 1) {
|
454
|
+
return _defineProperty({}, path, [{
|
455
|
+
message: "Schema cannot have an optional keys: ".concat(key),
|
456
|
+
fatal: true
|
457
|
+
}]);
|
458
|
+
}
|
459
|
+
if (_typeof(unknownSrc) !== "object") {
|
460
|
+
return _defineProperty({}, path, [{
|
461
|
+
message: "Expected an object"
|
462
|
+
}]);
|
463
|
+
}
|
464
|
+
var objectSrc = unknownSrc;
|
465
|
+
if (objectSrc[key] === undefined) {
|
466
|
+
return _defineProperty({}, path, [{
|
467
|
+
message: "Missing required key: ".concat(key)
|
468
|
+
}]);
|
469
|
+
}
|
470
|
+
var foundSchemaLiterals = [];
|
471
|
+
var _iterator = _createForOfIteratorHelper(serializedObjectSchemas),
|
472
|
+
_step;
|
473
|
+
try {
|
474
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
475
|
+
var schema = _step.value;
|
476
|
+
var schemaKey = schema.items[key];
|
477
|
+
if (schemaKey.type === "literal") {
|
478
|
+
if (!foundSchemaLiterals.includes(schemaKey.value)) {
|
479
|
+
foundSchemaLiterals.push(schemaKey.value);
|
480
|
+
} else {
|
481
|
+
return _defineProperty({}, path, [{
|
482
|
+
message: "Found duplicate key in schema: ".concat(schemaKey.value),
|
483
|
+
fatal: true
|
484
|
+
}]);
|
485
|
+
}
|
486
|
+
}
|
487
|
+
}
|
488
|
+
} catch (err) {
|
489
|
+
_iterator.e(err);
|
490
|
+
} finally {
|
491
|
+
_iterator.f();
|
492
|
+
}
|
493
|
+
var objectSchemaAtKey = objectSchemas.find(function (schema) {
|
494
|
+
return !schema.items[key].validate(path, objectSrc[key]);
|
495
|
+
});
|
496
|
+
if (!objectSchemaAtKey) {
|
497
|
+
var keyPath = createValPathOfItem(path, key);
|
498
|
+
if (!keyPath) {
|
499
|
+
throw new Error("Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(key));
|
500
|
+
}
|
501
|
+
return _defineProperty({}, keyPath, [{
|
502
|
+
message: "Invalid key: \"".concat(key, "\". Value was: \"").concat(objectSrc[key], "\". Valid values: ").concat(serializedObjectSchemas.map(function (schema) {
|
503
|
+
var keySchema = schema.items[key];
|
504
|
+
if (keySchema.type === "literal" && keySchema.value) {
|
505
|
+
return "\"".concat(keySchema.value, "\"");
|
506
|
+
} else {
|
507
|
+
// should not happen here, we already checked this
|
508
|
+
throw new Error("Expected literal schema, got ".concat(JSON.stringify(keySchema, null, 2)));
|
509
|
+
}
|
510
|
+
}).join(", "))
|
511
|
+
}]);
|
512
|
+
}
|
513
|
+
var error = objectSchemaAtKey.validate(path, objectSrc);
|
514
|
+
if (error) {
|
515
|
+
return error;
|
516
|
+
}
|
517
|
+
} else if (key instanceof LiteralSchema) {
|
518
|
+
if (this.items.some(function (item) {
|
519
|
+
return !(item instanceof LiteralSchema);
|
520
|
+
})) {
|
521
|
+
return _defineProperty({}, path, [{
|
522
|
+
message: "Key is a literal schema, so all schema items must be literals",
|
523
|
+
fatal: true
|
524
|
+
}]);
|
525
|
+
}
|
526
|
+
var literalItems = [key].concat(_toConsumableArray(this.items));
|
527
|
+
if (typeof unknownSrc === "string") {
|
528
|
+
var isMatch = literalItems.some(function (item) {
|
529
|
+
return !item.validate(path, unknownSrc);
|
530
|
+
});
|
531
|
+
if (!isMatch) {
|
532
|
+
return _defineProperty({}, path, [{
|
533
|
+
message: "Union must match one of the following: ".concat(literalItems.map(function (item) {
|
534
|
+
return "\"".concat(item.value, "\"");
|
535
|
+
}).join(", "))
|
536
|
+
}]);
|
537
|
+
}
|
538
|
+
}
|
539
|
+
} else {
|
540
|
+
return _defineProperty({}, path, [{
|
541
|
+
message: "Expected a string or literal"
|
542
|
+
}]);
|
543
|
+
}
|
544
|
+
return errors;
|
347
545
|
}
|
348
546
|
}, {
|
349
547
|
key: "assert",
|
@@ -768,4 +966,4 @@ var PatchError = /*#__PURE__*/_createClass(function PatchError(message) {
|
|
768
966
|
* NOTE: MAY mutate the input document.
|
769
967
|
*/
|
770
968
|
|
771
|
-
export { PatchError as P, array as a, record as b, content as c, createValPathOfItem as d, resolvePath as e, getSource as g, isSelector as i, newSelectorProxy as n, object as o, richtext as r, splitModuleIdAndModulePath as s, union as u };
|
969
|
+
export { PatchError as P, array as a, record as b, content as c, createValPathOfItem as d, resolvePath as e, getSource as g, isSelector as i, literal as l, newSelectorProxy as n, object as o, richtext as r, splitModuleIdAndModulePath as s, union as u };
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var ops = require('./ops-
|
5
|
+
var ops = require('./ops-422169e5.cjs.dev.js');
|
6
6
|
var index = require('./index-a5295001.cjs.dev.js');
|
7
7
|
var expr_dist_valbuildCoreExpr = require('./index-6deb169d.cjs.dev.js');
|
8
8
|
var result = require('./result-48320acd.cjs.dev.js');
|
@@ -195,67 +195,6 @@ var _boolean = function _boolean() {
|
|
195
195
|
return new BooleanSchema();
|
196
196
|
};
|
197
197
|
|
198
|
-
var LiteralSchema = /*#__PURE__*/function (_Schema) {
|
199
|
-
index._inherits(LiteralSchema, _Schema);
|
200
|
-
var _super = index._createSuper(LiteralSchema);
|
201
|
-
function LiteralSchema(value) {
|
202
|
-
var _this;
|
203
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
204
|
-
index._classCallCheck(this, LiteralSchema);
|
205
|
-
_this = _super.call(this);
|
206
|
-
_this.value = value;
|
207
|
-
_this.opt = opt;
|
208
|
-
return _this;
|
209
|
-
}
|
210
|
-
index._createClass(LiteralSchema, [{
|
211
|
-
key: "validate",
|
212
|
-
value: function validate(path, src) {
|
213
|
-
if (this.opt && (src === null || src === undefined)) {
|
214
|
-
return false;
|
215
|
-
}
|
216
|
-
if (typeof src !== "string") {
|
217
|
-
return index._defineProperty({}, path, [{
|
218
|
-
message: "Expected 'string', got '".concat(index._typeof(src), "'"),
|
219
|
-
value: src
|
220
|
-
}]);
|
221
|
-
}
|
222
|
-
if (src !== this.value) {
|
223
|
-
return index._defineProperty({}, path, [{
|
224
|
-
message: "Expected literal '".concat(this.value, "', got '").concat(src, "'"),
|
225
|
-
value: src
|
226
|
-
}]);
|
227
|
-
}
|
228
|
-
return false;
|
229
|
-
}
|
230
|
-
}, {
|
231
|
-
key: "assert",
|
232
|
-
value: function assert(src) {
|
233
|
-
if (this.opt && (src === null || src === undefined)) {
|
234
|
-
return true;
|
235
|
-
}
|
236
|
-
return typeof src === "string";
|
237
|
-
}
|
238
|
-
}, {
|
239
|
-
key: "optional",
|
240
|
-
value: function optional() {
|
241
|
-
return new LiteralSchema(this.value, true);
|
242
|
-
}
|
243
|
-
}, {
|
244
|
-
key: "serialize",
|
245
|
-
value: function serialize() {
|
246
|
-
return {
|
247
|
-
type: "literal",
|
248
|
-
value: this.value,
|
249
|
-
opt: this.opt
|
250
|
-
};
|
251
|
-
}
|
252
|
-
}]);
|
253
|
-
return LiteralSchema;
|
254
|
-
}(index.Schema);
|
255
|
-
var literal = function literal(value) {
|
256
|
-
return new LiteralSchema(value);
|
257
|
-
};
|
258
|
-
|
259
198
|
var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
260
199
|
index._inherits(KeyOfSchema, _Schema);
|
261
200
|
var _super = index._createSuper(KeyOfSchema);
|
@@ -403,7 +342,7 @@ function initSchema() {
|
|
403
342
|
// oneOf,
|
404
343
|
richtext: ops.richtext,
|
405
344
|
image: index.image,
|
406
|
-
literal: literal,
|
345
|
+
literal: ops.literal,
|
407
346
|
keyOf: keyOf,
|
408
347
|
record: ops.record
|
409
348
|
// i18n: i18n(locales),
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var ops = require('./ops-
|
5
|
+
var ops = require('./ops-5bd1bd7a.cjs.prod.js');
|
6
6
|
var index = require('./index-5bdaa229.cjs.prod.js');
|
7
7
|
var expr_dist_valbuildCoreExpr = require('./index-216627d7.cjs.prod.js');
|
8
8
|
var result = require('./result-26f67b40.cjs.prod.js');
|
@@ -195,67 +195,6 @@ var _boolean = function _boolean() {
|
|
195
195
|
return new BooleanSchema();
|
196
196
|
};
|
197
197
|
|
198
|
-
var LiteralSchema = /*#__PURE__*/function (_Schema) {
|
199
|
-
index._inherits(LiteralSchema, _Schema);
|
200
|
-
var _super = index._createSuper(LiteralSchema);
|
201
|
-
function LiteralSchema(value) {
|
202
|
-
var _this;
|
203
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
204
|
-
index._classCallCheck(this, LiteralSchema);
|
205
|
-
_this = _super.call(this);
|
206
|
-
_this.value = value;
|
207
|
-
_this.opt = opt;
|
208
|
-
return _this;
|
209
|
-
}
|
210
|
-
index._createClass(LiteralSchema, [{
|
211
|
-
key: "validate",
|
212
|
-
value: function validate(path, src) {
|
213
|
-
if (this.opt && (src === null || src === undefined)) {
|
214
|
-
return false;
|
215
|
-
}
|
216
|
-
if (typeof src !== "string") {
|
217
|
-
return index._defineProperty({}, path, [{
|
218
|
-
message: "Expected 'string', got '".concat(index._typeof(src), "'"),
|
219
|
-
value: src
|
220
|
-
}]);
|
221
|
-
}
|
222
|
-
if (src !== this.value) {
|
223
|
-
return index._defineProperty({}, path, [{
|
224
|
-
message: "Expected literal '".concat(this.value, "', got '").concat(src, "'"),
|
225
|
-
value: src
|
226
|
-
}]);
|
227
|
-
}
|
228
|
-
return false;
|
229
|
-
}
|
230
|
-
}, {
|
231
|
-
key: "assert",
|
232
|
-
value: function assert(src) {
|
233
|
-
if (this.opt && (src === null || src === undefined)) {
|
234
|
-
return true;
|
235
|
-
}
|
236
|
-
return typeof src === "string";
|
237
|
-
}
|
238
|
-
}, {
|
239
|
-
key: "optional",
|
240
|
-
value: function optional() {
|
241
|
-
return new LiteralSchema(this.value, true);
|
242
|
-
}
|
243
|
-
}, {
|
244
|
-
key: "serialize",
|
245
|
-
value: function serialize() {
|
246
|
-
return {
|
247
|
-
type: "literal",
|
248
|
-
value: this.value,
|
249
|
-
opt: this.opt
|
250
|
-
};
|
251
|
-
}
|
252
|
-
}]);
|
253
|
-
return LiteralSchema;
|
254
|
-
}(index.Schema);
|
255
|
-
var literal = function literal(value) {
|
256
|
-
return new LiteralSchema(value);
|
257
|
-
};
|
258
|
-
|
259
198
|
var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
260
199
|
index._inherits(KeyOfSchema, _Schema);
|
261
200
|
var _super = index._createSuper(KeyOfSchema);
|
@@ -403,7 +342,7 @@ function initSchema() {
|
|
403
342
|
// oneOf,
|
404
343
|
richtext: ops.richtext,
|
405
344
|
image: index.image,
|
406
|
-
literal: literal,
|
345
|
+
literal: ops.literal,
|
407
346
|
keyOf: keyOf,
|
408
347
|
record: ops.record
|
409
348
|
// i18n: i18n(locales),
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { a as array, o as object, u as union, r as richtext$1, b as record, c as content, P as PatchError, n as newSelectorProxy, d as createValPathOfItem, i as isSelector, g as getSource, e as resolvePath, s as splitModuleIdAndModulePath } from './ops-
|
1
|
+
import { a as array, o as object, u as union, r as richtext$1, l as literal, b as record, c as content, P as PatchError, n as newSelectorProxy, d as createValPathOfItem, i as isSelector, g as getSource, e as resolvePath, s as splitModuleIdAndModulePath } from './ops-899d8bef.esm.js';
|
2
2
|
import { _ as _inherits, a as _createSuper, b as _classCallCheck, c as _createClass, d as _defineProperty, e as _typeof, S as Schema, G as GetSchema, g as getValPath, i as image, V as VAL_EXTENSION, f as file, h as _slicedToArray, j as isFile, F as FILE_REF_PROP, P as Path, k as GetSource, l as isSerializedVal, m as convertFileSource, n as getSchema, o as isVal } from './index-c83918b8.esm.js';
|
3
3
|
export { F as FILE_REF_PROP, p as GenericSelector, S as Schema, V as VAL_EXTENSION } from './index-c83918b8.esm.js';
|
4
4
|
export { i as expr } from './index-4f821892.esm.js';
|
@@ -192,67 +192,6 @@ var _boolean = function _boolean() {
|
|
192
192
|
return new BooleanSchema();
|
193
193
|
};
|
194
194
|
|
195
|
-
var LiteralSchema = /*#__PURE__*/function (_Schema) {
|
196
|
-
_inherits(LiteralSchema, _Schema);
|
197
|
-
var _super = _createSuper(LiteralSchema);
|
198
|
-
function LiteralSchema(value) {
|
199
|
-
var _this;
|
200
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
201
|
-
_classCallCheck(this, LiteralSchema);
|
202
|
-
_this = _super.call(this);
|
203
|
-
_this.value = value;
|
204
|
-
_this.opt = opt;
|
205
|
-
return _this;
|
206
|
-
}
|
207
|
-
_createClass(LiteralSchema, [{
|
208
|
-
key: "validate",
|
209
|
-
value: function validate(path, src) {
|
210
|
-
if (this.opt && (src === null || src === undefined)) {
|
211
|
-
return false;
|
212
|
-
}
|
213
|
-
if (typeof src !== "string") {
|
214
|
-
return _defineProperty({}, path, [{
|
215
|
-
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
216
|
-
value: src
|
217
|
-
}]);
|
218
|
-
}
|
219
|
-
if (src !== this.value) {
|
220
|
-
return _defineProperty({}, path, [{
|
221
|
-
message: "Expected literal '".concat(this.value, "', got '").concat(src, "'"),
|
222
|
-
value: src
|
223
|
-
}]);
|
224
|
-
}
|
225
|
-
return false;
|
226
|
-
}
|
227
|
-
}, {
|
228
|
-
key: "assert",
|
229
|
-
value: function assert(src) {
|
230
|
-
if (this.opt && (src === null || src === undefined)) {
|
231
|
-
return true;
|
232
|
-
}
|
233
|
-
return typeof src === "string";
|
234
|
-
}
|
235
|
-
}, {
|
236
|
-
key: "optional",
|
237
|
-
value: function optional() {
|
238
|
-
return new LiteralSchema(this.value, true);
|
239
|
-
}
|
240
|
-
}, {
|
241
|
-
key: "serialize",
|
242
|
-
value: function serialize() {
|
243
|
-
return {
|
244
|
-
type: "literal",
|
245
|
-
value: this.value,
|
246
|
-
opt: this.opt
|
247
|
-
};
|
248
|
-
}
|
249
|
-
}]);
|
250
|
-
return LiteralSchema;
|
251
|
-
}(Schema);
|
252
|
-
var literal = function literal(value) {
|
253
|
-
return new LiteralSchema(value);
|
254
|
-
};
|
255
|
-
|
256
195
|
var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
257
196
|
_inherits(KeyOfSchema, _Schema);
|
258
197
|
var _super = _createSuper(KeyOfSchema);
|
package/package.json
CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
var index = require('../../dist/index-a5295001.cjs.dev.js');
|
6
6
|
var result = require('../../dist/result-48320acd.cjs.dev.js');
|
7
7
|
var util = require('../../dist/util-b213092b.cjs.dev.js');
|
8
|
-
var ops = require('../../dist/ops-
|
8
|
+
var ops = require('../../dist/ops-422169e5.cjs.dev.js');
|
9
9
|
|
10
10
|
function isNotRoot(path) {
|
11
11
|
return result.isNonEmpty(path);
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
var index = require('../../dist/index-5bdaa229.cjs.prod.js');
|
6
6
|
var result = require('../../dist/result-26f67b40.cjs.prod.js');
|
7
7
|
var util = require('../../dist/util-030d8a1f.cjs.prod.js');
|
8
|
-
var ops = require('../../dist/ops-
|
8
|
+
var ops = require('../../dist/ops-5bd1bd7a.cjs.prod.js');
|
9
9
|
|
10
10
|
function isNotRoot(path) {
|
11
11
|
return result.isNonEmpty(path);
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { e as _typeof, h as _slicedToArray, c as _createClass, b as _classCallCheck, u as _toConsumableArray } from '../../dist/index-c83918b8.esm.js';
|
2
2
|
import { f as isNonEmpty, e as err, o as ok, m as map, g as flatMap, i as isErr, h as flatMapReduce, j as filterOrElse, k as mapErr, l as map$1, n as all, p as flatten, q as allT } from '../../dist/result-b96df128.esm.js';
|
3
3
|
import { p as pipe } from '../../dist/util-18613e99.esm.js';
|
4
|
-
import { P as PatchError, s as splitModuleIdAndModulePath } from '../../dist/ops-
|
5
|
-
export { P as PatchError } from '../../dist/ops-
|
4
|
+
import { P as PatchError, s as splitModuleIdAndModulePath } from '../../dist/ops-899d8bef.esm.js';
|
5
|
+
export { P as PatchError } from '../../dist/ops-899d8bef.esm.js';
|
6
6
|
|
7
7
|
function isNotRoot(path) {
|
8
8
|
return isNonEmpty(path);
|