@arcblock/validator 1.27.15 → 1.28.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.
@@ -1,96 +1,100 @@
1
- import { Root, AnySchema } from 'joi';
2
- import BN from 'bn.js';
3
- export interface BNSchema extends AnySchema {
4
- min(threshold: any): this;
5
- gte(threshold: any): this;
6
- max(threshold: any): this;
7
- lte(threshold: any): this;
8
- greater(threshold: any): this;
9
- gt(threshold: any): this;
10
- less(threshold: any): this;
11
- lt(threshold: any): this;
12
- positive(): this;
13
- negative(): this;
1
+ import { AnySchema, Root } from "joi";
2
+ import BN from "bn.js";
3
+
4
+ //#region src/extension/bn.d.ts
5
+ interface BNSchema extends AnySchema {
6
+ min(threshold: any): this;
7
+ gte(threshold: any): this;
8
+ max(threshold: any): this;
9
+ lte(threshold: any): this;
10
+ greater(threshold: any): this;
11
+ gt(threshold: any): this;
12
+ less(threshold: any): this;
13
+ lt(threshold: any): this;
14
+ positive(): this;
15
+ negative(): this;
14
16
  }
15
- export declare function BNExtension(root: Root): {
16
- type: string;
17
- base: AnySchema<any>;
18
- messages: {
19
- 'bn.nan': string;
20
- 'bn.max': string;
21
- 'bn.min': string;
22
- 'bn.less': string;
23
- 'bn.greater': string;
24
- 'bn.positive': string;
25
- 'bn.negative': string;
17
+ declare function BNExtension(root: Root): {
18
+ type: string;
19
+ base: AnySchema<any>;
20
+ messages: {
21
+ 'bn.nan': string;
22
+ 'bn.max': string;
23
+ 'bn.min': string;
24
+ 'bn.less': string;
25
+ 'bn.greater': string;
26
+ 'bn.positive': string;
27
+ 'bn.negative': string;
28
+ };
29
+ prepare(value: any, helpers: any): {
30
+ value: BN;
31
+ errors?: undefined;
32
+ } | {
33
+ errors: any;
34
+ value?: undefined;
35
+ };
36
+ coerce(value: BN): {
37
+ value: string;
38
+ };
39
+ validate(value: any): {
40
+ value: any;
41
+ };
42
+ rules: {
43
+ gt: {
44
+ args: ({
45
+ name: string;
46
+ ref: boolean;
47
+ assert: (v: any) => v is BN;
48
+ message: string;
49
+ normalize: (v: any) => BN;
50
+ } | {
51
+ name: string;
52
+ assert: (v: any) => v is boolean;
53
+ message: string;
54
+ ref?: undefined;
55
+ normalize?: undefined;
56
+ })[];
57
+ validate(value: any, helpers: any, args: any): any;
26
58
  };
27
- prepare(value: any, helpers: any): {
28
- value: BN;
29
- errors?: undefined;
30
- } | {
31
- errors: any;
32
- value?: undefined;
59
+ lt: {
60
+ args: ({
61
+ name: string;
62
+ ref: boolean;
63
+ assert: (v: any) => v is BN;
64
+ message: string;
65
+ normalize: (v: any) => BN;
66
+ } | {
67
+ name: string;
68
+ assert: (v: any) => v is boolean;
69
+ message: string;
70
+ ref?: undefined;
71
+ normalize?: undefined;
72
+ })[];
73
+ validate(value: any, helpers: any, args: any): any;
33
74
  };
34
- coerce(value: BN): {
35
- value: string;
75
+ min: {
76
+ alias: string;
77
+ method(threshold: any): BNSchema;
36
78
  };
37
- validate(value: any): {
38
- value: any;
79
+ max: {
80
+ alias: string;
81
+ method(threshold: any): BNSchema;
39
82
  };
40
- rules: {
41
- gt: {
42
- args: ({
43
- name: string;
44
- ref: boolean;
45
- assert: (v: any) => v is BN;
46
- message: string;
47
- normalize: (v: any) => BN;
48
- } | {
49
- name: string;
50
- assert: (v: any) => v is boolean;
51
- message: string;
52
- ref?: undefined;
53
- normalize?: undefined;
54
- })[];
55
- validate(value: any, helpers: any, args: any): any;
56
- };
57
- lt: {
58
- args: ({
59
- name: string;
60
- ref: boolean;
61
- assert: (v: any) => v is BN;
62
- message: string;
63
- normalize: (v: any) => BN;
64
- } | {
65
- name: string;
66
- assert: (v: any) => v is boolean;
67
- message: string;
68
- ref?: undefined;
69
- normalize?: undefined;
70
- })[];
71
- validate(value: any, helpers: any, args: any): any;
72
- };
73
- min: {
74
- alias: string;
75
- method(threshold: any): BNSchema;
76
- };
77
- max: {
78
- alias: string;
79
- method(threshold: any): BNSchema;
80
- };
81
- greater: {
82
- alias: string;
83
- method(threshold: any): BNSchema;
84
- };
85
- less: {
86
- alias: string;
87
- method(threshold: any): BNSchema;
88
- };
89
- positive: {
90
- method(): BNSchema;
91
- };
92
- negative: {
93
- method(): BNSchema;
94
- };
83
+ greater: {
84
+ alias: string;
85
+ method(threshold: any): BNSchema;
95
86
  };
87
+ less: {
88
+ alias: string;
89
+ method(threshold: any): BNSchema;
90
+ };
91
+ positive: {
92
+ method(): BNSchema;
93
+ };
94
+ negative: {
95
+ method(): BNSchema;
96
+ };
97
+ };
96
98
  };
99
+ //#endregion
100
+ export { BNExtension, BNSchema };
@@ -1,130 +1,140 @@
1
- import BN from 'bn.js';
2
- export function BNExtension(root) {
3
- return {
4
- type: 'BN',
5
- base: root.any(),
6
- messages: {
7
- 'bn.nan': '{{#label}} is not a big number',
8
- 'bn.max': '{{#label}} needs to be less than or equal to "{{#threshold}}"',
9
- 'bn.min': '{{#label}} needs to be greater than or equal to "{{#threshold}}"',
10
- 'bn.less': '{{#label}} needs to be less than "{{#threshold}}"',
11
- 'bn.greater': '{{#label}} needs to be greater than "{{#threshold}}"',
12
- 'bn.positive': '{{#label}} needs to be positive',
13
- 'bn.negative': '{{#label}} needs to be negative',
14
- },
15
- prepare(value, helpers) {
16
- try {
17
- return { value: new BN(value) };
18
- }
19
- catch (err) {
20
- return { errors: helpers.error('bn.nan') };
21
- }
22
- },
23
- coerce(value) {
24
- return { value: value.toString(10) };
25
- },
26
- validate(value) {
27
- return { value };
28
- },
29
- rules: {
30
- gt: {
31
- args: [
32
- {
33
- name: 'threshold',
34
- ref: true,
35
- assert: (v) => BN.isBN(v),
36
- message: 'must be a big number',
37
- normalize: (v) => new BN(v),
38
- },
39
- {
40
- name: 'equal',
41
- assert: (v) => typeof v === 'boolean',
42
- message: 'must be a boolean',
43
- },
44
- ],
45
- // The rule return structure is different from the root
46
- // eslint-disable-next-line consistent-return
47
- validate(value, helpers, args) {
48
- const v = new BN(value);
49
- if (args.equal && v.lt(args.threshold)) {
50
- return helpers.error('bn.min', args);
51
- }
52
- if (!args.equal && v.lte(args.threshold)) {
53
- return helpers.error('bn.greater', args);
54
- }
55
- // must return value when valid
56
- return value;
57
- },
58
- },
59
- lt: {
60
- args: [
61
- {
62
- name: 'threshold',
63
- ref: true,
64
- assert: (v) => BN.isBN(v),
65
- message: 'must be a big number',
66
- normalize: (v) => new BN(v),
67
- },
68
- {
69
- name: 'equal',
70
- assert: (v) => typeof v === 'boolean',
71
- message: 'must be a boolean',
72
- },
73
- ],
74
- // The rule return structure is different from the root
75
- // eslint-disable-next-line consistent-return
76
- validate(value, helpers, args) {
77
- const v = new BN(value);
78
- if (args.equal && v.gt(args.threshold)) {
79
- return helpers.error('bn.max', args);
80
- }
81
- if (!args.equal && v.gte(args.threshold)) {
82
- return helpers.error('bn.less', args);
83
- }
84
- // must return value when valid
85
- return value;
86
- },
87
- },
88
- min: {
89
- alias: 'gte',
90
- method(threshold) {
91
- // @ts-ignore
92
- return this.$_addRule({ name: 'gt', args: { threshold, equal: true } });
93
- },
94
- },
95
- max: {
96
- alias: 'lte',
97
- method(threshold) {
98
- // @ts-ignore
99
- return this.$_addRule({ name: 'lt', args: { threshold, equal: true } });
100
- },
101
- },
102
- greater: {
103
- alias: 'gt',
104
- method(threshold) {
105
- // @ts-ignore
106
- return this.$_addRule({ name: 'gt', args: { threshold, equal: false } });
107
- },
108
- },
109
- less: {
110
- alias: 'lt',
111
- method(threshold) {
112
- // @ts-ignore
113
- return this.$_addRule({ name: 'lt', args: { threshold, equal: false } });
114
- },
115
- },
116
- positive: {
117
- method() {
118
- // @ts-ignore
119
- return this.$_addRule({ name: 'gt', args: { threshold: 0, equal: false } });
120
- },
121
- },
122
- negative: {
123
- method() {
124
- // @ts-ignore
125
- return this.$_addRule({ name: 'lt', args: { threshold: 0, equal: false } });
126
- },
127
- },
128
- },
129
- };
1
+ import BN from "bn.js";
2
+
3
+ //#region src/extension/bn.ts
4
+ function BNExtension(root) {
5
+ return {
6
+ type: "BN",
7
+ base: root.any(),
8
+ messages: {
9
+ "bn.nan": "{{#label}} is not a big number",
10
+ "bn.max": "{{#label}} needs to be less than or equal to \"{{#threshold}}\"",
11
+ "bn.min": "{{#label}} needs to be greater than or equal to \"{{#threshold}}\"",
12
+ "bn.less": "{{#label}} needs to be less than \"{{#threshold}}\"",
13
+ "bn.greater": "{{#label}} needs to be greater than \"{{#threshold}}\"",
14
+ "bn.positive": "{{#label}} needs to be positive",
15
+ "bn.negative": "{{#label}} needs to be negative"
16
+ },
17
+ prepare(value, helpers) {
18
+ try {
19
+ return { value: new BN(value) };
20
+ } catch (err) {
21
+ return { errors: helpers.error("bn.nan") };
22
+ }
23
+ },
24
+ coerce(value) {
25
+ return { value: value.toString(10) };
26
+ },
27
+ validate(value) {
28
+ return { value };
29
+ },
30
+ rules: {
31
+ gt: {
32
+ args: [{
33
+ name: "threshold",
34
+ ref: true,
35
+ assert: (v) => BN.isBN(v),
36
+ message: "must be a big number",
37
+ normalize: (v) => new BN(v)
38
+ }, {
39
+ name: "equal",
40
+ assert: (v) => typeof v === "boolean",
41
+ message: "must be a boolean"
42
+ }],
43
+ validate(value, helpers, args) {
44
+ const v = new BN(value);
45
+ if (args.equal && v.lt(args.threshold)) return helpers.error("bn.min", args);
46
+ if (!args.equal && v.lte(args.threshold)) return helpers.error("bn.greater", args);
47
+ return value;
48
+ }
49
+ },
50
+ lt: {
51
+ args: [{
52
+ name: "threshold",
53
+ ref: true,
54
+ assert: (v) => BN.isBN(v),
55
+ message: "must be a big number",
56
+ normalize: (v) => new BN(v)
57
+ }, {
58
+ name: "equal",
59
+ assert: (v) => typeof v === "boolean",
60
+ message: "must be a boolean"
61
+ }],
62
+ validate(value, helpers, args) {
63
+ const v = new BN(value);
64
+ if (args.equal && v.gt(args.threshold)) return helpers.error("bn.max", args);
65
+ if (!args.equal && v.gte(args.threshold)) return helpers.error("bn.less", args);
66
+ return value;
67
+ }
68
+ },
69
+ min: {
70
+ alias: "gte",
71
+ method(threshold) {
72
+ return this.$_addRule({
73
+ name: "gt",
74
+ args: {
75
+ threshold,
76
+ equal: true
77
+ }
78
+ });
79
+ }
80
+ },
81
+ max: {
82
+ alias: "lte",
83
+ method(threshold) {
84
+ return this.$_addRule({
85
+ name: "lt",
86
+ args: {
87
+ threshold,
88
+ equal: true
89
+ }
90
+ });
91
+ }
92
+ },
93
+ greater: {
94
+ alias: "gt",
95
+ method(threshold) {
96
+ return this.$_addRule({
97
+ name: "gt",
98
+ args: {
99
+ threshold,
100
+ equal: false
101
+ }
102
+ });
103
+ }
104
+ },
105
+ less: {
106
+ alias: "lt",
107
+ method(threshold) {
108
+ return this.$_addRule({
109
+ name: "lt",
110
+ args: {
111
+ threshold,
112
+ equal: false
113
+ }
114
+ });
115
+ }
116
+ },
117
+ positive: { method() {
118
+ return this.$_addRule({
119
+ name: "gt",
120
+ args: {
121
+ threshold: 0,
122
+ equal: false
123
+ }
124
+ });
125
+ } },
126
+ negative: { method() {
127
+ return this.$_addRule({
128
+ name: "lt",
129
+ args: {
130
+ threshold: 0,
131
+ equal: false
132
+ }
133
+ });
134
+ } }
135
+ }
136
+ };
130
137
  }
138
+
139
+ //#endregion
140
+ export { BNExtension };
@@ -1,77 +1,81 @@
1
- import { Root, StringSchema } from 'joi';
2
- import { KeyType, HashType, RoleType } from '@ocap/mcrypto';
3
- import { DIDTypeShortcut } from '@arcblock/did';
4
- export interface DIDSchema extends StringSchema {
5
- wallet(type: DIDTypeShortcut): this;
6
- pk(type: KeyType): this;
7
- hash(type: HashType): this;
8
- role(type: RoleType): this;
9
- prefix(str?: string): this;
1
+ import { Root, StringSchema } from "joi";
2
+ import { HashType, KeyType, RoleType } from "@ocap/mcrypto";
3
+ import { DIDTypeShortcut } from "@arcblock/did";
4
+
5
+ //#region src/extension/did.d.ts
6
+ interface DIDSchema extends StringSchema {
7
+ wallet(type: DIDTypeShortcut): this;
8
+ pk(type: KeyType): this;
9
+ hash(type: HashType): this;
10
+ role(type: RoleType): this;
11
+ prefix(str?: string): this;
10
12
  }
11
- export declare function DIDExtension(root: Root): {
12
- type: string;
13
- base: StringSchema<string>;
14
- messages: {
15
- 'did.empty': string;
16
- 'did.invalid': string;
17
- 'did.wallet': string;
18
- 'did.pk': string;
19
- 'did.hash': string;
20
- 'did.role': string;
21
- 'did.prefix': string;
13
+ declare function DIDExtension(root: Root): {
14
+ type: string;
15
+ base: StringSchema<string>;
16
+ messages: {
17
+ 'did.empty': string;
18
+ 'did.invalid': string;
19
+ 'did.wallet': string;
20
+ 'did.pk': string;
21
+ 'did.hash': string;
22
+ 'did.role': string;
23
+ 'did.prefix': string;
24
+ };
25
+ validate(value: any, helpers: any): {
26
+ errors: any;
27
+ value?: undefined;
28
+ } | {
29
+ value: string;
30
+ errors?: undefined;
31
+ };
32
+ rules: {
33
+ type: {
34
+ args: ({
35
+ name: string;
36
+ ref: boolean;
37
+ assert: (v: string) => boolean;
38
+ message: string;
39
+ } | {
40
+ name: string;
41
+ assert: (v: string) => boolean;
42
+ message: string;
43
+ ref?: undefined;
44
+ })[];
45
+ validate(value: string, helpers: any, args: any): any;
22
46
  };
23
- validate(value: any, helpers: any): {
24
- errors: any;
25
- value?: undefined;
26
- } | {
27
- value: string;
28
- errors?: undefined;
47
+ pk: {
48
+ method(type: KeyType): DIDSchema;
29
49
  };
30
- rules: {
31
- type: {
32
- args: ({
33
- name: string;
34
- ref: boolean;
35
- assert: (v: string) => boolean;
36
- message: string;
37
- } | {
38
- name: string;
39
- assert: (v: string) => boolean;
40
- message: string;
41
- ref?: undefined;
42
- })[];
43
- validate(value: string, helpers: any, args: any): any;
44
- };
45
- pk: {
46
- method(type: KeyType): DIDSchema;
47
- };
48
- hash: {
49
- method(type: HashType): DIDSchema;
50
- };
51
- role: {
52
- method(type: RoleType): DIDSchema;
53
- };
54
- wallet: {
55
- method(type: DIDTypeShortcut): DIDSchema;
56
- args: {
57
- name: string;
58
- ref: boolean;
59
- assert: (v: any) => boolean;
60
- message: string;
61
- normalize: (v: any) => any;
62
- }[];
63
- validate(value: any, helpers: any, args?: any): any;
64
- };
65
- prefix: {
66
- method(str?: string): DIDSchema;
67
- args: {
68
- name: string;
69
- ref: boolean;
70
- assert: (v: any) => boolean;
71
- message: string;
72
- normalize: (v: any) => any;
73
- }[];
74
- validate(value: any, helpers: any, args?: any): any;
75
- };
50
+ hash: {
51
+ method(type: HashType): DIDSchema;
76
52
  };
53
+ role: {
54
+ method(type: RoleType): DIDSchema;
55
+ };
56
+ wallet: {
57
+ method(type: DIDTypeShortcut): DIDSchema;
58
+ args: {
59
+ name: string;
60
+ ref: boolean;
61
+ assert: (v: any) => boolean;
62
+ message: string;
63
+ normalize: (v: any) => any;
64
+ }[];
65
+ validate(value: any, helpers: any, args?: any): any;
66
+ };
67
+ prefix: {
68
+ method(str?: string): DIDSchema;
69
+ args: {
70
+ name: string;
71
+ ref: boolean;
72
+ assert: (v: any) => boolean;
73
+ message: string;
74
+ normalize: (v: any) => any;
75
+ }[];
76
+ validate(value: any, helpers: any, args?: any): any;
77
+ };
78
+ };
77
79
  };
80
+ //#endregion
81
+ export { DIDExtension, DIDSchema };