wysiwyv 0.1.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/LICENSE +21 -0
- package/README.md +150 -0
- package/dist/core.d.ts +7 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +147 -0
- package/dist/hooks/and.d.ts +10 -0
- package/dist/hooks/and.d.ts.map +1 -0
- package/dist/hooks/and.js +29 -0
- package/dist/hooks/any.d.ts +8 -0
- package/dist/hooks/any.d.ts.map +1 -0
- package/dist/hooks/any.js +11 -0
- package/dist/hooks/array.d.ts +18 -0
- package/dist/hooks/array.d.ts.map +1 -0
- package/dist/hooks/array.js +56 -0
- package/dist/hooks/bool.d.ts +8 -0
- package/dist/hooks/bool.d.ts.map +1 -0
- package/dist/hooks/bool.js +16 -0
- package/dist/hooks/datetime.d.ts +11 -0
- package/dist/hooks/datetime.d.ts.map +1 -0
- package/dist/hooks/datetime.js +88 -0
- package/dist/hooks/email.d.ts +8 -0
- package/dist/hooks/email.d.ts.map +1 -0
- package/dist/hooks/email.js +26 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +28 -0
- package/dist/hooks/int.d.ts +13 -0
- package/dist/hooks/int.d.ts.map +1 -0
- package/dist/hooks/int.js +24 -0
- package/dist/hooks/number.d.ts +15 -0
- package/dist/hooks/number.d.ts.map +1 -0
- package/dist/hooks/number.js +30 -0
- package/dist/hooks/object.d.ts +14 -0
- package/dist/hooks/object.d.ts.map +1 -0
- package/dist/hooks/object.js +80 -0
- package/dist/hooks/or.d.ts +10 -0
- package/dist/hooks/or.d.ts.map +1 -0
- package/dist/hooks/or.js +26 -0
- package/dist/hooks/string.d.ts +8 -0
- package/dist/hooks/string.d.ts.map +1 -0
- package/dist/hooks/string.js +16 -0
- package/dist/hooks/uuid.d.ts +9 -0
- package/dist/hooks/uuid.d.ts.map +1 -0
- package/dist/hooks/uuid.js +78 -0
- package/dist/hooks/val.d.ts +10 -0
- package/dist/hooks/val.d.ts.map +1 -0
- package/dist/hooks/val.js +24 -0
- package/dist/type/engine.d.ts +14 -0
- package/dist/type/engine.d.ts.map +1 -0
- package/dist/type/engine.js +1 -0
- package/dist/type/plugin.d.ts +26 -0
- package/dist/type/plugin.d.ts.map +1 -0
- package/dist/type/plugin.js +1 -0
- package/dist/type/template.d.ts +6 -0
- package/dist/type/template.d.ts.map +1 -0
- package/dist/type/template.js +1 -0
- package/dist/util/HookAssessment.d.ts +13 -0
- package/dist/util/HookAssessment.d.ts.map +1 -0
- package/dist/util/HookAssessment.js +42 -0
- package/dist/util/HookError.d.ts +14 -0
- package/dist/util/HookError.d.ts.map +1 -0
- package/dist/util/HookError.js +13 -0
- package/dist/util/parseHook.d.ts +5 -0
- package/dist/util/parseHook.d.ts.map +1 -0
- package/dist/util/parseHook.js +21 -0
- package/dist/util/stringify.d.ts +2 -0
- package/dist/util/stringify.d.ts.map +1 -0
- package/dist/util/stringify.js +34 -0
- package/dist/util/types.d.ts +15 -0
- package/dist/util/types.d.ts.map +1 -0
- package/dist/util/types.js +24 -0
- package/dist/wysiwyv-core.d.ts +3 -0
- package/dist/wysiwyv-core.d.ts.map +1 -0
- package/dist/wysiwyv-core.js +11 -0
- package/dist/wysiwyv.d.ts +3 -0
- package/dist/wysiwyv.d.ts.map +1 -0
- package/dist/wysiwyv.js +7 -0
- package/dist/wysiwyv.min.js +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import andWyvern from "./and";
|
|
2
|
+
import anyWyvern from "./any";
|
|
3
|
+
import arrayWyvern from "./array";
|
|
4
|
+
import boolWyvern from "./bool";
|
|
5
|
+
import datetimeWyvern from "./datetime";
|
|
6
|
+
import emailWyvern from "./email";
|
|
7
|
+
import intWyvern from "./int";
|
|
8
|
+
import numberWyvern from "./number";
|
|
9
|
+
import objectWyvern from "./object";
|
|
10
|
+
import orWyvern from "./or";
|
|
11
|
+
import stringWyvern from "./string";
|
|
12
|
+
import uuidWyvern from "./uuid";
|
|
13
|
+
import valWyvern from "./val";
|
|
14
|
+
export const defaultHooks = [
|
|
15
|
+
andWyvern,
|
|
16
|
+
anyWyvern,
|
|
17
|
+
arrayWyvern,
|
|
18
|
+
boolWyvern,
|
|
19
|
+
datetimeWyvern,
|
|
20
|
+
emailWyvern,
|
|
21
|
+
intWyvern,
|
|
22
|
+
numberWyvern,
|
|
23
|
+
objectWyvern,
|
|
24
|
+
orWyvern,
|
|
25
|
+
stringWyvern,
|
|
26
|
+
uuidWyvern,
|
|
27
|
+
valWyvern,
|
|
28
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ContextObject } from "../type/plugin";
|
|
2
|
+
import type { HookKey } from "../type/plugin";
|
|
3
|
+
import type { WyvPlugin } from "../type/plugin";
|
|
4
|
+
export declare const WYV_KEY_INT: HookKey;
|
|
5
|
+
type WyvParams = {
|
|
6
|
+
$min?: number;
|
|
7
|
+
$max?: number;
|
|
8
|
+
};
|
|
9
|
+
type WyvSetup = unknown;
|
|
10
|
+
type WyvContext = ContextObject;
|
|
11
|
+
declare const intWyvern: WyvPlugin<WyvParams, WyvSetup, WyvContext>;
|
|
12
|
+
export default intWyvern;
|
|
13
|
+
//# sourceMappingURL=int.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"int.d.ts","sourceRoot":"","sources":["../../src/hooks/int.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKhD,eAAO,MAAM,WAAW,EAAE,OAAgB,CAAC;AAE3C,KAAK,SAAS,GAAG;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AACF,KAAK,QAAQ,GAAG,OAAO,CAAC;AACxB,KAAK,UAAU,GAAG,aAAa,CAAC;AAEhC,QAAA,MAAM,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,UAAU,CA2BzD,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HookAssessor } from "../util/HookAssessment";
|
|
2
|
+
import { errType, errAttr } from "../util/HookError";
|
|
3
|
+
import { isDefined, isNumber, isObject } from "../util/types";
|
|
4
|
+
export const WYV_KEY_INT = "$int";
|
|
5
|
+
const intWyvern = {
|
|
6
|
+
handles: (value) => [WYV_KEY_INT].includes(value),
|
|
7
|
+
handlers: {
|
|
8
|
+
[WYV_KEY_INT]: (value, _expected, { path, params }) => {
|
|
9
|
+
if (!isNumber(value) || !Number.isInteger(value)) {
|
|
10
|
+
return HookAssessor.fault(errType("integer", value, path));
|
|
11
|
+
}
|
|
12
|
+
const errors = HookAssessor.start();
|
|
13
|
+
const { $min, $max } = isObject(params) ? params : {};
|
|
14
|
+
if (isDefined($min) && isNumber($min) && value < $min) {
|
|
15
|
+
errors.fault(errAttr(WYV_KEY_INT + "." + "$min", "≥" + $min, value, path));
|
|
16
|
+
}
|
|
17
|
+
if (isDefined($max) && isNumber($max) && value > $max) {
|
|
18
|
+
errors.fault(errAttr(WYV_KEY_INT + "." + "$max", "≤" + $max, value, path));
|
|
19
|
+
}
|
|
20
|
+
return errors;
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export default intWyvern;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ContextObject } from "../type/plugin";
|
|
2
|
+
import type { HookKey } from "../type/plugin";
|
|
3
|
+
import type { WyvPlugin } from "../type/plugin";
|
|
4
|
+
export declare const WYV_KEY_NUMBER: HookKey;
|
|
5
|
+
type WyvParams = {
|
|
6
|
+
$min?: number;
|
|
7
|
+
$max?: number;
|
|
8
|
+
$gt?: number;
|
|
9
|
+
$lt?: number;
|
|
10
|
+
};
|
|
11
|
+
type WyvSetup = unknown;
|
|
12
|
+
type WyvContext = ContextObject;
|
|
13
|
+
declare const numberWyvern: WyvPlugin<WyvParams, WyvSetup, WyvContext>;
|
|
14
|
+
export default numberWyvern;
|
|
15
|
+
//# sourceMappingURL=number.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/hooks/number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKhD,eAAO,MAAM,cAAc,EAAE,OAAmB,CAAC;AAEjD,KAAK,SAAS,GAAG;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AACF,KAAK,QAAQ,GAAG,OAAO,CAAC;AACxB,KAAK,UAAU,GAAG,aAAa,CAAC;AAEhC,QAAA,MAAM,YAAY,EAAE,SAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,UAAU,CAgC5D,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HookAssessor } from "../util/HookAssessment";
|
|
2
|
+
import { errType, errAttr } from "../util/HookError";
|
|
3
|
+
import { isDefined, isNumber, isObject } from "../util/types";
|
|
4
|
+
export const WYV_KEY_NUMBER = "$number";
|
|
5
|
+
const numberWyvern = {
|
|
6
|
+
handles: (value) => [WYV_KEY_NUMBER].includes(value),
|
|
7
|
+
handlers: {
|
|
8
|
+
[WYV_KEY_NUMBER]: (value, _expected, { path, params }) => {
|
|
9
|
+
if (!isNumber(value)) {
|
|
10
|
+
return HookAssessor.fault(errType("number", value, path));
|
|
11
|
+
}
|
|
12
|
+
const errors = HookAssessor.start();
|
|
13
|
+
const { $min, $max, $gt, $lt } = isObject(params) ? params : {};
|
|
14
|
+
if (isDefined($min) && value < $min) {
|
|
15
|
+
errors.fault(errAttr(WYV_KEY_NUMBER + "." + "$min", "≥" + $min, value, path));
|
|
16
|
+
}
|
|
17
|
+
if (isDefined($max) && value > $max) {
|
|
18
|
+
errors.fault(errAttr(WYV_KEY_NUMBER + "." + "$max", "≤" + $max, value, path));
|
|
19
|
+
}
|
|
20
|
+
if (isDefined($gt) && value <= $gt) {
|
|
21
|
+
errors.fault(errAttr(WYV_KEY_NUMBER + "." + "$gt", ">" + $gt, value, path));
|
|
22
|
+
}
|
|
23
|
+
if (isDefined($lt) && value >= $lt) {
|
|
24
|
+
errors.fault(errAttr(WYV_KEY_NUMBER + "." + "$lt", "<" + $lt, value, path));
|
|
25
|
+
}
|
|
26
|
+
return errors;
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
export default numberWyvern;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HookValue } from "../type/template";
|
|
2
|
+
import type { ContextObject } from "../type/plugin";
|
|
3
|
+
import type { WyvPlugin } from "../type/plugin";
|
|
4
|
+
export declare const WYV_KEY_OBJECT = "$object";
|
|
5
|
+
export declare const WYV_KEY_PLAINOBJECT = "$plainobject";
|
|
6
|
+
type WyvParams = {
|
|
7
|
+
$partial?: HookValue;
|
|
8
|
+
$eachElement?: HookValue;
|
|
9
|
+
};
|
|
10
|
+
type WyvSetup = unknown;
|
|
11
|
+
type WyvContext = ContextObject;
|
|
12
|
+
declare const objectWyvern: WyvPlugin<WyvParams, WyvSetup, WyvContext>;
|
|
13
|
+
export default objectWyvern;
|
|
14
|
+
//# sourceMappingURL=object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/hooks/object.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,gBAAgB,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKhD,eAAO,MAAM,cAAc,YAAY,CAAC;AACxC,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAElD,KAAK,SAAS,GAAG;IACf,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,YAAY,CAAC,EAAE,SAAS,CAAC;CAC1B,CAAC;AACF,KAAK,QAAQ,GAAG,OAAO,CAAC;AACxB,KAAK,UAAU,GAAG,aAAa,CAAC;AA6HhC,QAAA,MAAM,YAAY,EAAE,SAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,UAAU,CAM5D,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { HookAssessor } from "../util/HookAssessment";
|
|
2
|
+
import { errConfig, errMissing, errType } from "../util/HookError";
|
|
3
|
+
import { isDefined, isObject, isPlainObject } from "../util/types";
|
|
4
|
+
export const WYV_KEY_OBJECT = "$object";
|
|
5
|
+
export const WYV_KEY_PLAINOBJECT = "$plainobject";
|
|
6
|
+
const validatePartial = ($partial, value, path, evaluate) => {
|
|
7
|
+
const errors = HookAssessor.start();
|
|
8
|
+
if (!isPlainObject($partial)) {
|
|
9
|
+
errors.fault(errConfig("$object.$partial option should be an object", path));
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
for (const expectedKey in $partial) {
|
|
13
|
+
if (!(expectedKey in value)) {
|
|
14
|
+
errors.fault(errMissing(expectedKey, $partial[expectedKey], `${path}.${expectedKey}`));
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const expectedSub = $partial[expectedKey]; // because it came from a hook object
|
|
18
|
+
const candidateSub = value[expectedKey];
|
|
19
|
+
const valueErrors = evaluate(expectedSub, candidateSub, `${path}.${expectedKey}`);
|
|
20
|
+
errors.include(valueErrors);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return errors;
|
|
24
|
+
};
|
|
25
|
+
const validateEachElement = ($eachElement, value, path, evaluate) => {
|
|
26
|
+
const errors = HookAssessor.start();
|
|
27
|
+
for (const valueKey in value) {
|
|
28
|
+
const eachErrors = evaluate($eachElement, value[valueKey], `${path}.${valueKey}`);
|
|
29
|
+
errors.include(eachErrors);
|
|
30
|
+
}
|
|
31
|
+
return errors;
|
|
32
|
+
};
|
|
33
|
+
const validateObject = (plainOnly) => (value, _expected, { path, params, evaluate }) => {
|
|
34
|
+
if (plainOnly) {
|
|
35
|
+
if (!isPlainObject(value)) {
|
|
36
|
+
return HookAssessor.fault(errType("plainobject", value, path));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
if (!isObject(value)) {
|
|
41
|
+
return HookAssessor.fault(errType("object", value, path));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const errors = HookAssessor.start();
|
|
45
|
+
const { $partial = undefined, $eachElement = undefined, ...rest } = isObject(params) ? params : {};
|
|
46
|
+
if (Object.keys(rest).length > 0) {
|
|
47
|
+
errors.fault(errConfig(`Unexpected $object parameters: ${Object.keys(rest)}`, path));
|
|
48
|
+
}
|
|
49
|
+
if (isDefined($partial) && isDefined($eachElement)) {
|
|
50
|
+
errors.fault(errConfig("$object options can specify $partial or $eachElement but not both", path));
|
|
51
|
+
return errors;
|
|
52
|
+
}
|
|
53
|
+
if (isDefined($partial)) {
|
|
54
|
+
if (!isPlainObject(value)) {
|
|
55
|
+
errors.fault(errType("plainobject for $partial", value, path));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const entireErrors = validatePartial($partial, value, path, evaluate);
|
|
59
|
+
errors.include(entireErrors);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (isDefined($eachElement)) {
|
|
63
|
+
if (!isPlainObject(value)) {
|
|
64
|
+
errors.fault(errType("plainobject for $eachElement", value, path));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const eachErrors = validateEachElement($eachElement, value, path, evaluate);
|
|
68
|
+
errors.include(eachErrors);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return errors;
|
|
72
|
+
};
|
|
73
|
+
const objectWyvern = {
|
|
74
|
+
handles: (value) => [WYV_KEY_OBJECT, WYV_KEY_PLAINOBJECT].includes(value),
|
|
75
|
+
handlers: {
|
|
76
|
+
[WYV_KEY_OBJECT]: validateObject(false),
|
|
77
|
+
[WYV_KEY_PLAINOBJECT]: validateObject(true),
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
export default objectWyvern;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HookValue } from "../type/template";
|
|
2
|
+
import type { ContextObject } from "../type/plugin";
|
|
3
|
+
import type { WyvPlugin } from "../type/plugin";
|
|
4
|
+
export declare const WYV_KEY_OR = "$or";
|
|
5
|
+
type WyvParams = HookValue[];
|
|
6
|
+
type WyvSetup = unknown;
|
|
7
|
+
type WyvContext = ContextObject;
|
|
8
|
+
declare const orWyvern: WyvPlugin<WyvParams, WyvSetup, WyvContext>;
|
|
9
|
+
export default orWyvern;
|
|
10
|
+
//# sourceMappingURL=or.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"or.d.ts","sourceRoot":"","sources":["../../src/hooks/or.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIhD,eAAO,MAAM,UAAU,QAAQ,CAAC;AAEhC,KAAK,SAAS,GAAG,SAAS,EAAE,CAAC;AAC7B,KAAK,QAAQ,GAAG,OAAO,CAAC;AACxB,KAAK,UAAU,GAAG,aAAa,CAAC;AAEhC,QAAA,MAAM,QAAQ,EAAE,SAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,UAAU,CA+BxD,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
package/dist/hooks/or.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { HookAssessor } from "../util/HookAssessment";
|
|
2
|
+
import { errColl, errConfig } from "../util/HookError";
|
|
3
|
+
export const WYV_KEY_OR = "$or";
|
|
4
|
+
const orWyvern = {
|
|
5
|
+
handles: (value) => [WYV_KEY_OR].includes(value),
|
|
6
|
+
handlers: {
|
|
7
|
+
[WYV_KEY_OR]: (value, _expected, { path, params, evaluate }) => {
|
|
8
|
+
if (!Array.isArray(params)) {
|
|
9
|
+
return HookAssessor.fault(errConfig("$or value should be an array of templates", path));
|
|
10
|
+
}
|
|
11
|
+
if (params.length === 0) {
|
|
12
|
+
// OR(<no arguments>) is defined as FALSE for boolean algebra
|
|
13
|
+
return HookAssessor.fault(errConfig(`$or must take one or more predicates`, path));
|
|
14
|
+
}
|
|
15
|
+
const errors = HookAssessor.start();
|
|
16
|
+
for (const template of params) {
|
|
17
|
+
const templateErrors = evaluate(template, value, path);
|
|
18
|
+
if (templateErrors.success)
|
|
19
|
+
return HookAssessor.SUCCESS;
|
|
20
|
+
errors.include(templateErrors);
|
|
21
|
+
}
|
|
22
|
+
return HookAssessor.fault(errColl("$or", path)).include(errors);
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
export default orWyvern;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ContextObject, WyvPlugin } from "../type/plugin";
|
|
2
|
+
export declare const WYV_KEY_STRING = "$string";
|
|
3
|
+
type WyvParams = unknown;
|
|
4
|
+
type WyvSetup = unknown;
|
|
5
|
+
type WyvContext = ContextObject;
|
|
6
|
+
declare const stringWyvern: WyvPlugin<WyvParams, WyvSetup, WyvContext>;
|
|
7
|
+
export default stringWyvern;
|
|
8
|
+
//# sourceMappingURL=string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/hooks/string.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAK/D,eAAO,MAAM,cAAc,YAAY,CAAC;AAExC,KAAK,SAAS,GAAG,OAAO,CAAC;AACzB,KAAK,QAAQ,GAAG,OAAO,CAAC;AACxB,KAAK,UAAU,GAAG,aAAa,CAAC;AAEhC,QAAA,MAAM,YAAY,EAAE,SAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,UAAU,CAU5D,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HookAssessor } from "../util/HookAssessment";
|
|
2
|
+
import { isString } from "../util/types";
|
|
3
|
+
import { errType } from "../util/HookError";
|
|
4
|
+
export const WYV_KEY_STRING = "$string";
|
|
5
|
+
const stringWyvern = {
|
|
6
|
+
handles: (value) => [WYV_KEY_STRING].includes(value),
|
|
7
|
+
handlers: {
|
|
8
|
+
[WYV_KEY_STRING]: (value, _expected, { path }) => {
|
|
9
|
+
if (!isString(value)) {
|
|
10
|
+
return HookAssessor.fault(errType("string", value, path));
|
|
11
|
+
}
|
|
12
|
+
return HookAssessor.SUCCESS;
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
export default stringWyvern;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ContextObject, HookKey } from "../type/plugin";
|
|
2
|
+
import type { WyvPlugin } from "../type/plugin";
|
|
3
|
+
export declare const WYV_KEY_UUID: HookKey;
|
|
4
|
+
type WyvParams = unknown;
|
|
5
|
+
type WyvSetup = unknown;
|
|
6
|
+
type WyvContext = ContextObject;
|
|
7
|
+
declare const uuidWyvern: WyvPlugin<WyvParams, WyvSetup, WyvContext>;
|
|
8
|
+
export default uuidWyvern;
|
|
9
|
+
//# sourceMappingURL=uuid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src/hooks/uuid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA4ChD,eAAO,MAAM,YAAY,EAAE,OAAiB,CAAC;AA6B7C,KAAK,SAAS,GAAG,OAAO,CAAC;AACzB,KAAK,QAAQ,GAAG,OAAO,CAAC;AACxB,KAAK,UAAU,GAAG,aAAa,CAAC;AAEhC,QAAA,MAAM,UAAU,EAAE,SAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,UAAU,CA0B1D,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { HookAssessor } from "../util/HookAssessment";
|
|
2
|
+
import { errConfig, errType } from "../util/HookError";
|
|
3
|
+
import { isEmptyObject, isNumber, isString } from "../util/types";
|
|
4
|
+
const hex = "[0-9a-f]";
|
|
5
|
+
const seg8 = `${hex}{8}`;
|
|
6
|
+
const seg4 = `${hex}{4}`;
|
|
7
|
+
const seg3 = `${hex}{3}`;
|
|
8
|
+
const seg12 = `${hex}{12}`;
|
|
9
|
+
const variant = "[89ab]";
|
|
10
|
+
const RE_UUID_NIL_STR = `0{8}-0{4}-0{4}-0{4}-0{12}`;
|
|
11
|
+
const RE_UUID_FFF_STR = `f{8}-f{4}-f{4}-f{4}-f{12}`;
|
|
12
|
+
const makeFullRe = (pattern) => new RegExp(`^${pattern}$`, "i");
|
|
13
|
+
const UUID_VERSIONS = [0, 1, 2, 3, 4, 5, 6, 7, 8, "F", null];
|
|
14
|
+
const isVersion = (val) => UUID_VERSIONS.includes(val);
|
|
15
|
+
const buildVersion = (version) => `${seg8}-${seg4}-${version}${seg3}-${variant}${seg3}-${seg12}`;
|
|
16
|
+
const RE_UUID_V1 = makeFullRe(buildVersion(1));
|
|
17
|
+
const RE_UUID_V2 = makeFullRe(buildVersion(2));
|
|
18
|
+
const RE_UUID_V3 = makeFullRe(buildVersion(3));
|
|
19
|
+
const RE_UUID_V4 = makeFullRe(buildVersion(4));
|
|
20
|
+
const RE_UUID_V5 = makeFullRe(buildVersion(5));
|
|
21
|
+
const RE_UUID_V6 = makeFullRe(buildVersion(6));
|
|
22
|
+
const RE_UUID_V7 = makeFullRe(buildVersion(7));
|
|
23
|
+
const RE_UUID_V8 = makeFullRe(buildVersion(8));
|
|
24
|
+
const RE_UUID_NIL = makeFullRe(RE_UUID_NIL_STR);
|
|
25
|
+
const RE_UUID_FFF = makeFullRe(RE_UUID_FFF_STR);
|
|
26
|
+
const RE_UUID_ANY_VERSIONED = buildVersion("[1-8]");
|
|
27
|
+
const RE_UUID_ANY = makeFullRe([RE_UUID_ANY_VERSIONED, RE_UUID_NIL_STR, RE_UUID_FFF_STR]
|
|
28
|
+
.map((s) => `(${s})`)
|
|
29
|
+
.join("|"));
|
|
30
|
+
export const WYV_KEY_UUID = "$uuid";
|
|
31
|
+
const testByVersion = (version, value) => {
|
|
32
|
+
switch (version) {
|
|
33
|
+
case 0:
|
|
34
|
+
return RE_UUID_NIL.test(value);
|
|
35
|
+
case 1:
|
|
36
|
+
return RE_UUID_V1.test(value);
|
|
37
|
+
case 2:
|
|
38
|
+
return RE_UUID_V2.test(value);
|
|
39
|
+
case 3:
|
|
40
|
+
return RE_UUID_V3.test(value);
|
|
41
|
+
case 4:
|
|
42
|
+
return RE_UUID_V4.test(value);
|
|
43
|
+
case 5:
|
|
44
|
+
return RE_UUID_V5.test(value);
|
|
45
|
+
case 6:
|
|
46
|
+
return RE_UUID_V6.test(value);
|
|
47
|
+
case 7:
|
|
48
|
+
return RE_UUID_V7.test(value);
|
|
49
|
+
case 8:
|
|
50
|
+
return RE_UUID_V8.test(value);
|
|
51
|
+
case "F":
|
|
52
|
+
return RE_UUID_FFF.test(value);
|
|
53
|
+
default:
|
|
54
|
+
return RE_UUID_ANY.test(value);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const uuidWyvern = {
|
|
58
|
+
handles: (value) => [WYV_KEY_UUID].includes(value),
|
|
59
|
+
handlers: {
|
|
60
|
+
$uuid: (value, _expected, { path, params }) => {
|
|
61
|
+
const version = isEmptyObject(params) ? null : params;
|
|
62
|
+
if (!isVersion(version)) {
|
|
63
|
+
return HookAssessor.fault(errConfig(`Unknown UUID version: '${version}'`, path));
|
|
64
|
+
}
|
|
65
|
+
if (!isString(value)) {
|
|
66
|
+
return HookAssessor.fault(errType("string", value, path));
|
|
67
|
+
}
|
|
68
|
+
if (!testByVersion(version, value)) {
|
|
69
|
+
const subMessage = isNumber(version) || isString(version)
|
|
70
|
+
? ` of version '${version}'`
|
|
71
|
+
: "";
|
|
72
|
+
return HookAssessor.fault(errType(`UUID${subMessage}`, value, path));
|
|
73
|
+
}
|
|
74
|
+
return HookAssessor.SUCCESS;
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
export default uuidWyvern;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WyvPlugin } from "../type/plugin";
|
|
2
|
+
type MatchDictionary = Record<string, unknown>;
|
|
3
|
+
type WyvParams = string;
|
|
4
|
+
type WyvSetup = MatchDictionary;
|
|
5
|
+
type WyvContext = {
|
|
6
|
+
matches: MatchDictionary;
|
|
7
|
+
};
|
|
8
|
+
declare const valWyvern: WyvPlugin<WyvParams, WyvSetup, WyvContext>;
|
|
9
|
+
export default valWyvern;
|
|
10
|
+
//# sourceMappingURL=val.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"val.d.ts","sourceRoot":"","sources":["../../src/hooks/val.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAMhD,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/C,KAAK,SAAS,GAAG,MAAM,CAAC;AACxB,KAAK,QAAQ,GAAG,eAAe,CAAC;AAChC,KAAK,UAAU,GAAG;IAAE,OAAO,EAAE,eAAe,CAAA;CAAE,CAAC;AAE/C,QAAA,MAAM,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,UAAU,CA4BzD,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HookAssessor } from "../util/HookAssessment";
|
|
2
|
+
import { errMatch } from "../util/HookError";
|
|
3
|
+
const WYV_KEY_VAL = "$val";
|
|
4
|
+
const valWyvern = {
|
|
5
|
+
handles: (value) => [WYV_KEY_VAL].includes(value),
|
|
6
|
+
handlers: {
|
|
7
|
+
[WYV_KEY_VAL]: (value, _expected, { path, params: match, setup, context }) => {
|
|
8
|
+
if (context.matches === undefined) {
|
|
9
|
+
// initialize matches on first call
|
|
10
|
+
context.matches = setup ?? {};
|
|
11
|
+
}
|
|
12
|
+
if (!(match in context.matches)) {
|
|
13
|
+
// intentionally mutating passed-in object
|
|
14
|
+
context.matches[match] = value;
|
|
15
|
+
return HookAssessor.SUCCESS;
|
|
16
|
+
}
|
|
17
|
+
if (value !== context.matches[match]) {
|
|
18
|
+
return HookAssessor.fault(errMatch(context.matches[match], value, match, path));
|
|
19
|
+
}
|
|
20
|
+
return HookAssessor.SUCCESS;
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export default valWyvern;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HookValue } from "./template";
|
|
2
|
+
import type { ContextObject, PluginList } from "./plugin";
|
|
3
|
+
import type { HookAssessment } from "../util/HookAssessment";
|
|
4
|
+
export type MultiContext = Record<string, ContextObject>;
|
|
5
|
+
export type WysiwyvConfig = {
|
|
6
|
+
plugins?: PluginList;
|
|
7
|
+
pluginSetups?: MultiContext;
|
|
8
|
+
};
|
|
9
|
+
export type WysiwyvInstance = {
|
|
10
|
+
validate: (expected: HookValue, candidate: unknown) => HookAssessment;
|
|
11
|
+
};
|
|
12
|
+
export type WysiwyvFactory = (config?: WysiwyvConfig) => WysiwyvInstance;
|
|
13
|
+
export type WysiwyvEvaluatorFunction = (expected: HookValue, candidate: unknown, path: string) => HookAssessment;
|
|
14
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/type/engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAEzD,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AACF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,KAAK,cAAc,CAAC;CACvE,CAAC;AACF,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,CAAC,EAAE,aAAa,KAAK,eAAe,CAAC;AAGzE,MAAM,MAAM,wBAAwB,GAAG,CACrC,QAAQ,EAAE,SAAS,EACnB,SAAS,EAAE,OAAO,EAClB,IAAI,EAAE,MAAM,KACT,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { WysiwyvEvaluatorFunction } from "./engine";
|
|
2
|
+
import type { HookValue } from "./template";
|
|
3
|
+
import type { HookAssessment } from "../util/HookAssessment";
|
|
4
|
+
export type ContextObject = Record<string, unknown>;
|
|
5
|
+
export type HookEnviron<ParamsType = unknown, SetupType = unknown, ContextType extends ContextObject = ContextObject> = {
|
|
6
|
+
path: string;
|
|
7
|
+
params: ParamsType;
|
|
8
|
+
setup: SetupType;
|
|
9
|
+
context: ContextType;
|
|
10
|
+
shared: Record<string, unknown>;
|
|
11
|
+
evaluate: WysiwyvEvaluatorFunction;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @example options: HookEnviron<string>
|
|
15
|
+
* @example options: HookEnviron<{...}>
|
|
16
|
+
*/
|
|
17
|
+
export type HookHandler<ParamsType = unknown, SetupType = unknown, ContextType extends ContextObject = ContextObject> = (candidate: unknown, expected: HookValue, options: HookEnviron<ParamsType, SetupType, ContextType>) => HookAssessment;
|
|
18
|
+
export type HookKey = `$${string}${string}`;
|
|
19
|
+
export type WyvPlugin<ParamsType = unknown, SetupType = unknown, ContextType extends ContextObject = ContextObject> = {
|
|
20
|
+
handles: (value: HookKey) => boolean;
|
|
21
|
+
handlers: {
|
|
22
|
+
[key: HookKey]: HookHandler<ParamsType, SetupType, ContextType>;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type PluginList = WyvPlugin<any, any, any>[];
|
|
26
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/type/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpD,MAAM,MAAM,WAAW,CACrB,UAAU,GAAG,OAAO,EACpB,SAAS,GAAG,OAAO,EACnB,WAAW,SAAS,aAAa,GAAG,aAAa,IAC/C;IACF,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,EAAE,SAAS,CAAC;IACjB,OAAO,EAAE,WAAW,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,QAAQ,EAAE,wBAAwB,CAAC;CACpC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,WAAW,CACrB,UAAU,GAAG,OAAO,EACpB,SAAS,GAAG,OAAO,EACnB,WAAW,SAAS,aAAa,GAAG,aAAa,IAC/C,CACF,SAAS,EAAE,OAAO,EAClB,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE,WAAW,CAAC,UAAU,EAAE,SAAS,EAAE,WAAW,CAAC,KACrD,cAAc,CAAC;AAIpB,MAAM,MAAM,OAAO,GAAG,IAAI,MAAM,GAAG,MAAM,EAAE,CAAC;AAE5C,MAAM,MAAM,SAAS,CACnB,UAAU,GAAG,OAAO,EACpB,SAAS,GAAG,OAAO,EACnB,WAAW,SAAS,aAAa,GAAG,aAAa,IAC/C;IACF,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IACrC,QAAQ,EAAE;QAAE,CAAC,GAAG,EAAE,OAAO,GAAG,WAAW,CAAC,UAAU,EAAE,SAAS,EAAE,WAAW,CAAC,CAAA;KAAE,CAAC;CAC/E,CAAC;AAGF,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/type/template.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAE3D,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,EAAE,CAAC;AAE/D,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HookError } from "./HookError";
|
|
2
|
+
export interface HookAssessment {
|
|
3
|
+
readonly fault: (error: HookError) => HookAssessment;
|
|
4
|
+
readonly include: (assessment: HookAssessment) => HookAssessment;
|
|
5
|
+
readonly errors: readonly HookError[];
|
|
6
|
+
readonly success: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const HookAssessor: {
|
|
9
|
+
start: (errors?: readonly HookError[]) => HookAssessment;
|
|
10
|
+
SUCCESS: HookAssessment;
|
|
11
|
+
fault: (error: HookError) => HookAssessment;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=HookAssessment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HookAssessment.d.ts","sourceRoot":"","sources":["../../src/util/HookAssessment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,cAAc,CAAC;IACrD,QAAQ,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE,cAAc,KAAK,cAAc,CAAC;IACjE,QAAQ,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAkDD,eAAO,MAAM,YAAY;qBA5BF,SAAS,SAAS,EAAE,KAAQ,cAAc;;mBA0B3C,SAAS;CAM9B,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const EMPTY_ERRORS = Object.freeze([]);
|
|
2
|
+
const SUCCESS = {
|
|
3
|
+
get success() {
|
|
4
|
+
return true;
|
|
5
|
+
},
|
|
6
|
+
get errors() {
|
|
7
|
+
return EMPTY_ERRORS;
|
|
8
|
+
},
|
|
9
|
+
fault(error) {
|
|
10
|
+
return start().fault(error);
|
|
11
|
+
},
|
|
12
|
+
include(newAssessment) {
|
|
13
|
+
return newAssessment;
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
const start = (errors = []) => {
|
|
17
|
+
const _errors = errors.length === 0 ? [] : [...errors];
|
|
18
|
+
const assessment = {
|
|
19
|
+
get success() {
|
|
20
|
+
return _errors.length === 0;
|
|
21
|
+
},
|
|
22
|
+
get errors() {
|
|
23
|
+
return [..._errors];
|
|
24
|
+
},
|
|
25
|
+
fault(error) {
|
|
26
|
+
_errors.push(error);
|
|
27
|
+
return assessment;
|
|
28
|
+
},
|
|
29
|
+
include(newAssessment) {
|
|
30
|
+
if (!newAssessment.success)
|
|
31
|
+
_errors.push(...newAssessment.errors);
|
|
32
|
+
return assessment;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
return assessment;
|
|
36
|
+
};
|
|
37
|
+
const fault = (error) => start().fault(error);
|
|
38
|
+
export const HookAssessor = {
|
|
39
|
+
start,
|
|
40
|
+
SUCCESS,
|
|
41
|
+
fault,
|
|
42
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HookValue } from "../type/template";
|
|
2
|
+
export interface HookError {
|
|
3
|
+
message: string;
|
|
4
|
+
path: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const errUnexpected: (key: string, candidate: unknown, path: string) => HookError;
|
|
7
|
+
export declare const errMissing: (key: string, expected: HookValue | unknown, path: string) => HookError;
|
|
8
|
+
export declare const errValue: (expected: HookValue, candidate: unknown, path: string) => HookError;
|
|
9
|
+
export declare const errMatch: (expected: unknown, candidate: unknown, matcher: string, path: string) => HookError;
|
|
10
|
+
export declare const errType: (expectedType: string, candidate: unknown, path: string) => HookError;
|
|
11
|
+
export declare const errAttr: (attribute: string, expectedAttribute: unknown, candidateAttribute: unknown, path: string) => HookError;
|
|
12
|
+
export declare const errConfig: (messageDetail: string, path: string) => HookError;
|
|
13
|
+
export declare const errColl: (booleanFunction: string, path: string) => HookError;
|
|
14
|
+
//# sourceMappingURL=HookError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HookError.d.ts","sourceRoot":"","sources":["../../src/util/HookError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGlD,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAOD,eAAO,MAAM,aAAa,GACxB,KAAK,MAAM,EACX,WAAW,OAAO,EAClB,MAAM,MAAM,KACX,SACqE,CAAC;AAEzE,eAAO,MAAM,UAAU,GACrB,KAAK,MAAM,EACX,UAAU,SAAS,GAAG,OAAO,EAC7B,MAAM,MAAM,KACX,SAKA,CAAC;AAEJ,eAAO,MAAM,QAAQ,GACnB,UAAU,SAAS,EACnB,WAAW,OAAO,EAClB,MAAM,MAAM,KACX,SACoE,CAAC;AAExE,eAAO,MAAM,QAAQ,GACnB,UAAU,OAAO,EACjB,WAAW,OAAO,EAClB,SAAS,MAAM,EACf,MAAM,MAAM,KACX,SAKA,CAAC;AAEJ,eAAO,MAAM,OAAO,GAClB,cAAc,MAAM,EACpB,WAAW,OAAO,EAClB,MAAM,MAAM,KACX,SAKA,CAAC;AAEJ,eAAO,MAAM,OAAO,GAClB,WAAW,MAAM,EACjB,mBAAmB,OAAO,EAC1B,oBAAoB,OAAO,EAC3B,MAAM,MAAM,KACX,SAKA,CAAC;AAEJ,eAAO,MAAM,SAAS,GAAI,eAAe,MAAM,EAAE,MAAM,MAAM,KAAG,SACK,CAAC;AAEtE,eAAO,MAAM,OAAO,GAAI,iBAAiB,MAAM,EAAE,MAAM,MAAM,KAAG,SACG,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { repr } from "./stringify";
|
|
2
|
+
const makeError = (messageTemplate, value, path) => ({
|
|
3
|
+
message: messageTemplate.replace("%s", repr(value)),
|
|
4
|
+
path,
|
|
5
|
+
});
|
|
6
|
+
export const errUnexpected = (key, candidate, path) => makeError(`Unexpected element at '${key}': got '%s'`, candidate, path);
|
|
7
|
+
export const errMissing = (key, expected, path) => makeError(`Missing element at '${key}': expected '${expected}'`, undefined, path);
|
|
8
|
+
export const errValue = (expected, candidate, path) => makeError(`Value: Expected '${expected}', got '%s'`, candidate, path);
|
|
9
|
+
export const errMatch = (expected, candidate, matcher, path) => makeError(`Expected value '${expected}' for key '${matcher}', got '%s'`, candidate, path);
|
|
10
|
+
export const errType = (expectedType, candidate, path) => makeError(`Type: Expected '${expectedType}', got value '%s'`, candidate, path);
|
|
11
|
+
export const errAttr = (attribute, expectedAttribute, candidateAttribute, path) => makeError(`${attribute}: Expected '${expectedAttribute}', got '%s'`, candidateAttribute, path);
|
|
12
|
+
export const errConfig = (messageDetail, path) => makeError(`Configuration Error: ${messageDetail}`, undefined, path);
|
|
13
|
+
export const errColl = (booleanFunction, path) => makeError(`Aggregate Error: ${booleanFunction}`, undefined, path);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { HookValue } from "../type/template";
|
|
2
|
+
import type { HookKey } from "../type/plugin";
|
|
3
|
+
export declare const getHookKey: (val: HookValue) => HookKey | null;
|
|
4
|
+
export declare const getHookParams: (hook: unknown, key: string) => unknown;
|
|
5
|
+
//# sourceMappingURL=parseHook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseHook.d.ts","sourceRoot":"","sources":["../../src/util/parseHook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAG9C,eAAO,MAAM,UAAU,GAAI,KAAK,SAAS,KAAG,OAAO,GAAG,IAgBrD,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,MAAM,OAAO,EAAE,KAAK,MAAM,KAAG,OAK1D,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isPlainObject, isString } from "./types";
|
|
2
|
+
export const getHookKey = (val) => {
|
|
3
|
+
if (isString(val)) {
|
|
4
|
+
if (val.startsWith("$") && !val.startsWith("$$")) {
|
|
5
|
+
return val;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
if (isPlainObject(val) && Object.keys(val).length === 1) {
|
|
9
|
+
const key = Object.keys(val)[0];
|
|
10
|
+
if (key.startsWith("$") && !key.startsWith("$$")) {
|
|
11
|
+
return key;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
};
|
|
16
|
+
export const getHookParams = (hook, key) => {
|
|
17
|
+
if (isPlainObject(hook)) {
|
|
18
|
+
return hook[key];
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
};
|