@xyo-network/payload-validator 2.42.13
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 +165 -0
- package/README.md +81 -0
- package/dist/cjs/SchemaNameValidator.d.ts +68 -0
- package/dist/cjs/SchemaNameValidator.d.ts.map +1 -0
- package/dist/cjs/SchemaNameValidator.js +127 -0
- package/dist/cjs/SchemaNameValidator.js.map +1 -0
- package/dist/cjs/Validator/Validator.d.ts +11 -0
- package/dist/cjs/Validator/Validator.d.ts.map +1 -0
- package/dist/cjs/Validator/Validator.js +32 -0
- package/dist/cjs/Validator/Validator.js.map +1 -0
- package/dist/cjs/Validator/index.d.ts +2 -0
- package/dist/cjs/Validator/index.d.ts.map +1 -0
- package/dist/cjs/Validator/index.js +5 -0
- package/dist/cjs/Validator/index.js.map +1 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/SchemaNameValidator.d.ts +68 -0
- package/dist/esm/SchemaNameValidator.d.ts.map +1 -0
- package/dist/esm/SchemaNameValidator.js +114 -0
- package/dist/esm/SchemaNameValidator.js.map +1 -0
- package/dist/esm/Validator/Validator.d.ts +11 -0
- package/dist/esm/Validator/Validator.d.ts.map +1 -0
- package/dist/esm/Validator/Validator.js +28 -0
- package/dist/esm/Validator/Validator.js.map +1 -0
- package/dist/esm/Validator/index.d.ts +2 -0
- package/dist/esm/Validator/index.d.ts.map +1 -0
- package/dist/esm/Validator/index.js +2 -0
- package/dist/esm/Validator/index.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +54 -0
- package/src/SchemaNameValidator.ts +120 -0
- package/src/Validator/Validator.spec.ts +52 -0
- package/src/Validator/Validator.ts +33 -0
- package/src/Validator/index.ts +1 -0
- package/src/index.ts +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
[![logo][]](https://xyo.network)
|
|
2
|
+
|
|
3
|
+
# sdk-xyo-client-js
|
|
4
|
+
|
|
5
|
+
[![main-build][]][main-build-link]
|
|
6
|
+
[![beta-build][]][beta-build-link]
|
|
7
|
+
[![npm-badge][]][npm-link]
|
|
8
|
+
[![bch-badge][]][bch-link]
|
|
9
|
+
[![codacy-badge][]][codacy-link]
|
|
10
|
+
[![codeclimate-badge][]][codeclimate-link]
|
|
11
|
+
[![snyk-badge][]][snyk-link]
|
|
12
|
+
|
|
13
|
+
> The XYO Foundation provides this source code available in our efforts to
|
|
14
|
+
> advance the understanding of the XYO Protocol and its possible uses.
|
|
15
|
+
> We continue to maintain this software in the interest of developer education.
|
|
16
|
+
> Usage of this source code is not intended for production.
|
|
17
|
+
|
|
18
|
+
## Table of Contents
|
|
19
|
+
- [Title](#sdk-xyo-client-js)
|
|
20
|
+
- [Table of Contents](#table-of-contents)
|
|
21
|
+
- [Description](#description)
|
|
22
|
+
- [Install](#install)
|
|
23
|
+
- [Maintainers](#maintainers)
|
|
24
|
+
- [License](#license)
|
|
25
|
+
- [Credits](#credits)
|
|
26
|
+
|
|
27
|
+
## Description
|
|
28
|
+
|
|
29
|
+
> Primary SDK for using the XYO Protocol 2.0 from TypeScript/JavaScript.
|
|
30
|
+
> Designed to work in both browser based and Node JS based solutions.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
Using npm:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
npm i --save @xyo-network/sdk-xyo-client-js
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Using yarn:
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
yarn add @xyo-network/sdk-xyo-client-js
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Maintainers
|
|
47
|
+
|
|
48
|
+
- [Arie Trouw](https://github.com/arietrouw) [(arietrouw.com)](https://arietrouw.com)
|
|
49
|
+
- [Matt Jones](https://github.com/jonesmac)
|
|
50
|
+
- [Joel Carter](https://github.com/JoelBCarter)
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
> See the [LICENSE](LICENSE) file for license details
|
|
55
|
+
|
|
56
|
+
## Credits
|
|
57
|
+
|
|
58
|
+
[Made with 🔥 and ❄️ by XYO](https://xyo.network)
|
|
59
|
+
|
|
60
|
+
[logo]: https://cdn.xy.company/img/brand/XYO_full_colored.png
|
|
61
|
+
|
|
62
|
+
[main-build]: https://github.com/XYOracleNetwork/sdk-xyo-client-js/actions/workflows/build-main.yml/badge.svg
|
|
63
|
+
[main-build-link]: https://github.com/XYOracleNetwork/sdk-xyo-client-js/actions/workflows/build-main.yml
|
|
64
|
+
|
|
65
|
+
[beta-build]: https://github.com/XYOracleNetwork/sdk-xyo-client-js/actions/workflows/build-beta.yml/badge.svg
|
|
66
|
+
[beta-build-link]: https://github.com/XYOracleNetwork/sdk-xyo-client-js/actions/workflows/build-beta.yml
|
|
67
|
+
|
|
68
|
+
[npm-badge]: https://img.shields.io/npm/v/@xyo-network/sdk-xyo-client-js.svg
|
|
69
|
+
[npm-link]: https://www.npmjs.com/package/@xyo-network/sdk-xyo-client-js
|
|
70
|
+
|
|
71
|
+
[bch-badge]: https://bettercodehub.com/edge/badge/XYOracleNetwork/sdk-xyo-client-js?branch=main
|
|
72
|
+
[bch-link]: https://bettercodehub.com/results/XYOracleNetwork/sdk-xyo-client-js
|
|
73
|
+
|
|
74
|
+
[codacy-badge]: https://app.codacy.com/project/badge/Grade/ba1f344ae34e4bfe999331cf4e27b9f5
|
|
75
|
+
[codacy-link]: https://www.codacy.com/gh/XYOracleNetwork/sdk-xyo-client-js/dashboard?utm_source=github.com&utm_medium=referral&utm_content=XYOracleNetwork/sdk-xyo-client-js&utm_campaign=Badge_Grade
|
|
76
|
+
|
|
77
|
+
[codeclimate-badge]: https://api.codeclimate.com/v1/badges/0e76349c9541f3866948/maintainability
|
|
78
|
+
[codeclimate-link]: https://codeclimate.com/github/XYOracleNetwork/sdk-xyo-client-js/maintainability
|
|
79
|
+
|
|
80
|
+
[snyk-badge]: https://snyk.io/test/github/XYOracleNetwork/sdk-xyo-client-js/badge.svg?targetFile=package.json
|
|
81
|
+
[snyk-link]: https://snyk.io/test/github/XYOracleNetwork/sdk-xyo-client-js?targetFile=package.json
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates a XYO schema structure and existence
|
|
3
|
+
*/
|
|
4
|
+
export declare class XyoSchemaNameValidator {
|
|
5
|
+
schema?: string;
|
|
6
|
+
private _parts?;
|
|
7
|
+
private _rootDomain?;
|
|
8
|
+
constructor(schema?: string);
|
|
9
|
+
/**
|
|
10
|
+
* Checks whether the schema is all lowercase
|
|
11
|
+
*
|
|
12
|
+
* @returns boolean
|
|
13
|
+
*/
|
|
14
|
+
get isLowercase(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Levels in the schema
|
|
17
|
+
*
|
|
18
|
+
* @returns number
|
|
19
|
+
*/
|
|
20
|
+
get levels(): number | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* The schema converted into a string array split on '.'
|
|
23
|
+
*
|
|
24
|
+
* @returns string[]
|
|
25
|
+
*/
|
|
26
|
+
get parts(): string[] | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* The rootDomain is the first two levels of the schema, in reverse order
|
|
29
|
+
* This can be used to determine who 'owns' that schema, based on domain
|
|
30
|
+
* registration
|
|
31
|
+
*
|
|
32
|
+
* @returns string
|
|
33
|
+
*/
|
|
34
|
+
get rootDomain(): string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Run all static validations
|
|
37
|
+
* @returns Error[]
|
|
38
|
+
*/
|
|
39
|
+
all(): Error[];
|
|
40
|
+
/**
|
|
41
|
+
* Run all the validations
|
|
42
|
+
* @param checkExistance - boolean
|
|
43
|
+
* @returns Error[]
|
|
44
|
+
*/
|
|
45
|
+
allDynamic(): Promise<Error[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Determines how many levels of the schema's reverse domain
|
|
48
|
+
* pass DNS resolution
|
|
49
|
+
*
|
|
50
|
+
* @returns number (0 if none exist)
|
|
51
|
+
*/
|
|
52
|
+
domainExistenceDepth(): Promise<number>;
|
|
53
|
+
/**
|
|
54
|
+
* Checks if the root domain validates via DNS resolution
|
|
55
|
+
*
|
|
56
|
+
* @returns boolean
|
|
57
|
+
*/
|
|
58
|
+
rootDomainExists(): Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* Get a domain for the schema at a certain level
|
|
62
|
+
*
|
|
63
|
+
* @param level - Zero based level to check
|
|
64
|
+
* @returns string
|
|
65
|
+
*/
|
|
66
|
+
private domainLevel;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=SchemaNameValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaNameValidator.d.ts","sourceRoot":"","sources":["../../src/SchemaNameValidator.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,sBAAsB;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAA;IACtB,OAAO,CAAC,MAAM,CAAC,CAAU;IACzB,OAAO,CAAC,WAAW,CAAC,CAAQ;gBAChB,MAAM,CAAC,EAAE,MAAM;IAI3B;;;;OAIG;IACH,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED;;;;OAIG;IACH,IAAI,MAAM,IAAI,MAAM,GAAG,SAAS,CAE/B;IAED;;;;OAIG;IACH,IAAI,KAAK,yBAGR;IAED;;;;;;OAMG;IACH,IAAI,UAAU,IAAI,MAAM,GAAG,SAAS,CAGnC;IAED;;;OAGG;IAEI,GAAG;IAQV;;;;OAIG;IAEU,UAAU;IAOvB;;;;;OAKG;IACU,oBAAoB;IAYjC;;;;OAIG;IACU,gBAAgB;IAI7B;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;CAMpB"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XyoSchemaNameValidator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const dns_1 = require("@xyo-network/dns");
|
|
6
|
+
/**
|
|
7
|
+
* Validates a XYO schema structure and existence
|
|
8
|
+
*/
|
|
9
|
+
class XyoSchemaNameValidator {
|
|
10
|
+
constructor(schema) {
|
|
11
|
+
this.schema = schema;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Checks whether the schema is all lowercase
|
|
15
|
+
*
|
|
16
|
+
* @returns boolean
|
|
17
|
+
*/
|
|
18
|
+
get isLowercase() {
|
|
19
|
+
var _a;
|
|
20
|
+
return this.schema === ((_a = this.schema) === null || _a === void 0 ? void 0 : _a.toLowerCase());
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Levels in the schema
|
|
24
|
+
*
|
|
25
|
+
* @returns number
|
|
26
|
+
*/
|
|
27
|
+
get levels() {
|
|
28
|
+
var _a;
|
|
29
|
+
return (_a = this.parts) === null || _a === void 0 ? void 0 : _a.length;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The schema converted into a string array split on '.'
|
|
33
|
+
*
|
|
34
|
+
* @returns string[]
|
|
35
|
+
*/
|
|
36
|
+
get parts() {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
this._parts = (_a = this._parts) !== null && _a !== void 0 ? _a : (_b = this.schema) === null || _b === void 0 ? void 0 : _b.split('.');
|
|
39
|
+
return this._parts;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The rootDomain is the first two levels of the schema, in reverse order
|
|
43
|
+
* This can be used to determine who 'owns' that schema, based on domain
|
|
44
|
+
* registration
|
|
45
|
+
*
|
|
46
|
+
* @returns string
|
|
47
|
+
*/
|
|
48
|
+
get rootDomain() {
|
|
49
|
+
var _a;
|
|
50
|
+
this._rootDomain = (_a = this._rootDomain) !== null && _a !== void 0 ? _a : this.domainLevel(1);
|
|
51
|
+
return this._rootDomain;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Run all static validations
|
|
55
|
+
* @returns Error[]
|
|
56
|
+
*/
|
|
57
|
+
all() {
|
|
58
|
+
var _a, _b, _c;
|
|
59
|
+
const errors = [];
|
|
60
|
+
if (((_b = (_a = this.schema) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) === 0)
|
|
61
|
+
errors.push(Error('schema missing'));
|
|
62
|
+
else if (((_c = this.levels) !== null && _c !== void 0 ? _c : 0) < 3)
|
|
63
|
+
errors.push(Error(`schema levels < 3 [${this.levels}, ${this.schema}]`));
|
|
64
|
+
else if (!this.isLowercase)
|
|
65
|
+
errors.push(Error(`schema not lowercase [${this.schema}]`));
|
|
66
|
+
return errors;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Run all the validations
|
|
70
|
+
* @param checkExistance - boolean
|
|
71
|
+
* @returns Error[]
|
|
72
|
+
*/
|
|
73
|
+
allDynamic() {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const errors = [];
|
|
77
|
+
if (((_b = (_a = this.schema) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) === 0)
|
|
78
|
+
errors.push(Error('schema missing'));
|
|
79
|
+
else if (!(yield this.rootDomainExists()))
|
|
80
|
+
errors.push(Error(`schema root domain must exist [${this.rootDomain}]`));
|
|
81
|
+
return errors;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Determines how many levels of the schema's reverse domain
|
|
86
|
+
* pass DNS resolution
|
|
87
|
+
*
|
|
88
|
+
* @returns number (0 if none exist)
|
|
89
|
+
*/
|
|
90
|
+
domainExistenceDepth() {
|
|
91
|
+
var _a;
|
|
92
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const levels = (_a = this.levels) !== null && _a !== void 0 ? _a : 0;
|
|
94
|
+
let level = 0;
|
|
95
|
+
while (level < levels) {
|
|
96
|
+
if (!(yield (0, dns_1.domainExists)(this.domainLevel(level)))) {
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
level += 1;
|
|
100
|
+
}
|
|
101
|
+
return level;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Checks if the root domain validates via DNS resolution
|
|
106
|
+
*
|
|
107
|
+
* @returns boolean
|
|
108
|
+
*/
|
|
109
|
+
rootDomainExists() {
|
|
110
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
return yield (0, dns_1.domainExists)(this.rootDomain);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
*
|
|
116
|
+
* Get a domain for the schema at a certain level
|
|
117
|
+
*
|
|
118
|
+
* @param level - Zero based level to check
|
|
119
|
+
* @returns string
|
|
120
|
+
*/
|
|
121
|
+
domainLevel(level) {
|
|
122
|
+
var _a;
|
|
123
|
+
return (_a = this.parts) === null || _a === void 0 ? void 0 : _a.slice(0, level + 1).reverse().join('.');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.XyoSchemaNameValidator = XyoSchemaNameValidator;
|
|
127
|
+
//# sourceMappingURL=SchemaNameValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaNameValidator.js","sourceRoot":"","sources":["../../src/SchemaNameValidator.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Validator, XyoValidatorBase } from '@xyo-network/core';
|
|
2
|
+
import { XyoPayload } from '@xyo-network/payload-model';
|
|
3
|
+
import { XyoSchemaNameValidator } from '../SchemaNameValidator';
|
|
4
|
+
export declare class PayloadValidator<T extends XyoPayload = XyoPayload> extends XyoValidatorBase<T> implements Validator<T> {
|
|
5
|
+
private _schemaValidator?;
|
|
6
|
+
constructor(payload: T);
|
|
7
|
+
get schemaValidator(): XyoSchemaNameValidator;
|
|
8
|
+
schemaName(): Error[];
|
|
9
|
+
validate(): Error[];
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=Validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../../src/Validator/Validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAEvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,qBAAa,gBAAgB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAE,YAAW,SAAS,CAAC,CAAC,CAAC;IAClH,OAAO,CAAC,gBAAgB,CAAC,CAAwB;gBAErC,OAAO,EAAE,CAAC;IAItB,IAAI,eAAe,2BAGlB;IAEM,UAAU;IAUV,QAAQ;CAKhB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PayloadValidator = void 0;
|
|
4
|
+
const core_1 = require("@xyo-network/core");
|
|
5
|
+
const SchemaNameValidator_1 = require("../SchemaNameValidator");
|
|
6
|
+
class PayloadValidator extends core_1.XyoValidatorBase {
|
|
7
|
+
constructor(payload) {
|
|
8
|
+
super(payload);
|
|
9
|
+
}
|
|
10
|
+
get schemaValidator() {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
this._schemaValidator = (_a = this._schemaValidator) !== null && _a !== void 0 ? _a : new SchemaNameValidator_1.XyoSchemaNameValidator((_b = this.obj.schema) !== null && _b !== void 0 ? _b : '');
|
|
13
|
+
return this._schemaValidator;
|
|
14
|
+
}
|
|
15
|
+
schemaName() {
|
|
16
|
+
const errors = [];
|
|
17
|
+
if (this.obj.schema === undefined) {
|
|
18
|
+
errors.push(Error('schema missing'));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
errors.push(...this.schemaValidator.all());
|
|
22
|
+
}
|
|
23
|
+
return errors;
|
|
24
|
+
}
|
|
25
|
+
validate() {
|
|
26
|
+
const errors = [];
|
|
27
|
+
errors.push(...this.schemaName());
|
|
28
|
+
return errors;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.PayloadValidator = PayloadValidator;
|
|
32
|
+
//# sourceMappingURL=Validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Validator.js","sourceRoot":"","sources":["../../../src/Validator/Validator.ts"],"names":[],"mappings":";;;AAAA,4CAA+D;AAG/D,gEAA+D;AAE/D,MAAa,gBAAoD,SAAQ,uBAAmB;IAG1F,YAAY,OAAU;QACpB,KAAK,CAAC,OAAO,CAAC,CAAA;IAChB,CAAC;IAED,IAAI,eAAe;;QACjB,IAAI,CAAC,gBAAgB,GAAG,MAAA,IAAI,CAAC,gBAAgB,mCAAI,IAAI,4CAAsB,CAAC,MAAA,IAAI,CAAC,GAAG,CAAC,MAAM,mCAAI,EAAE,CAAC,CAAA;QAClG,OAAO,IAAI,CAAC,gBAAgB,CAAA;IAC9B,CAAC;IAEM,UAAU;QACf,MAAM,MAAM,GAAY,EAAE,CAAA;QAC1B,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE;YACjC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAA;SACrC;aAAM;YACL,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC,CAAA;SAC3C;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAEM,QAAQ;QACb,MAAM,MAAM,GAAY,EAAE,CAAA;QAC1B,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,CAAA;QACjC,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AA3BD,4CA2BC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validator/index.ts"],"names":[],"mappings":";;;AAAA,sDAA2B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./SchemaNameValidator"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./Validator"), exports);
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,gEAAqC;AACrC,sDAA2B"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates a XYO schema structure and existence
|
|
3
|
+
*/
|
|
4
|
+
export declare class XyoSchemaNameValidator {
|
|
5
|
+
schema?: string;
|
|
6
|
+
private _parts?;
|
|
7
|
+
private _rootDomain?;
|
|
8
|
+
constructor(schema?: string);
|
|
9
|
+
/**
|
|
10
|
+
* Checks whether the schema is all lowercase
|
|
11
|
+
*
|
|
12
|
+
* @returns boolean
|
|
13
|
+
*/
|
|
14
|
+
get isLowercase(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Levels in the schema
|
|
17
|
+
*
|
|
18
|
+
* @returns number
|
|
19
|
+
*/
|
|
20
|
+
get levels(): number | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* The schema converted into a string array split on '.'
|
|
23
|
+
*
|
|
24
|
+
* @returns string[]
|
|
25
|
+
*/
|
|
26
|
+
get parts(): string[] | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* The rootDomain is the first two levels of the schema, in reverse order
|
|
29
|
+
* This can be used to determine who 'owns' that schema, based on domain
|
|
30
|
+
* registration
|
|
31
|
+
*
|
|
32
|
+
* @returns string
|
|
33
|
+
*/
|
|
34
|
+
get rootDomain(): string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Run all static validations
|
|
37
|
+
* @returns Error[]
|
|
38
|
+
*/
|
|
39
|
+
all(): Error[];
|
|
40
|
+
/**
|
|
41
|
+
* Run all the validations
|
|
42
|
+
* @param checkExistance - boolean
|
|
43
|
+
* @returns Error[]
|
|
44
|
+
*/
|
|
45
|
+
allDynamic(): Promise<Error[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Determines how many levels of the schema's reverse domain
|
|
48
|
+
* pass DNS resolution
|
|
49
|
+
*
|
|
50
|
+
* @returns number (0 if none exist)
|
|
51
|
+
*/
|
|
52
|
+
domainExistenceDepth(): Promise<number>;
|
|
53
|
+
/**
|
|
54
|
+
* Checks if the root domain validates via DNS resolution
|
|
55
|
+
*
|
|
56
|
+
* @returns boolean
|
|
57
|
+
*/
|
|
58
|
+
rootDomainExists(): Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* Get a domain for the schema at a certain level
|
|
62
|
+
*
|
|
63
|
+
* @param level - Zero based level to check
|
|
64
|
+
* @returns string
|
|
65
|
+
*/
|
|
66
|
+
private domainLevel;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=SchemaNameValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaNameValidator.d.ts","sourceRoot":"","sources":["../../src/SchemaNameValidator.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,sBAAsB;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAA;IACtB,OAAO,CAAC,MAAM,CAAC,CAAU;IACzB,OAAO,CAAC,WAAW,CAAC,CAAQ;gBAChB,MAAM,CAAC,EAAE,MAAM;IAI3B;;;;OAIG;IACH,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED;;;;OAIG;IACH,IAAI,MAAM,IAAI,MAAM,GAAG,SAAS,CAE/B;IAED;;;;OAIG;IACH,IAAI,KAAK,yBAGR;IAED;;;;;;OAMG;IACH,IAAI,UAAU,IAAI,MAAM,GAAG,SAAS,CAGnC;IAED;;;OAGG;IAEI,GAAG;IAQV;;;;OAIG;IAEU,UAAU;IAOvB;;;;;OAKG;IACU,oBAAoB;IAYjC;;;;OAIG;IACU,gBAAgB;IAI7B;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;CAMpB"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { domainExists } from '@xyo-network/dns';
|
|
2
|
+
/**
|
|
3
|
+
* Validates a XYO schema structure and existence
|
|
4
|
+
*/
|
|
5
|
+
export class XyoSchemaNameValidator {
|
|
6
|
+
schema;
|
|
7
|
+
_parts;
|
|
8
|
+
_rootDomain;
|
|
9
|
+
constructor(schema) {
|
|
10
|
+
this.schema = schema;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Checks whether the schema is all lowercase
|
|
14
|
+
*
|
|
15
|
+
* @returns boolean
|
|
16
|
+
*/
|
|
17
|
+
get isLowercase() {
|
|
18
|
+
return this.schema === this.schema?.toLowerCase();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Levels in the schema
|
|
22
|
+
*
|
|
23
|
+
* @returns number
|
|
24
|
+
*/
|
|
25
|
+
get levels() {
|
|
26
|
+
return this.parts?.length;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The schema converted into a string array split on '.'
|
|
30
|
+
*
|
|
31
|
+
* @returns string[]
|
|
32
|
+
*/
|
|
33
|
+
get parts() {
|
|
34
|
+
this._parts = this._parts ?? this.schema?.split('.');
|
|
35
|
+
return this._parts;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The rootDomain is the first two levels of the schema, in reverse order
|
|
39
|
+
* This can be used to determine who 'owns' that schema, based on domain
|
|
40
|
+
* registration
|
|
41
|
+
*
|
|
42
|
+
* @returns string
|
|
43
|
+
*/
|
|
44
|
+
get rootDomain() {
|
|
45
|
+
this._rootDomain = this._rootDomain ?? this.domainLevel(1);
|
|
46
|
+
return this._rootDomain;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Run all static validations
|
|
50
|
+
* @returns Error[]
|
|
51
|
+
*/
|
|
52
|
+
all() {
|
|
53
|
+
const errors = [];
|
|
54
|
+
if ((this.schema?.length ?? 0) === 0)
|
|
55
|
+
errors.push(Error('schema missing'));
|
|
56
|
+
else if ((this.levels ?? 0) < 3)
|
|
57
|
+
errors.push(Error(`schema levels < 3 [${this.levels}, ${this.schema}]`));
|
|
58
|
+
else if (!this.isLowercase)
|
|
59
|
+
errors.push(Error(`schema not lowercase [${this.schema}]`));
|
|
60
|
+
return errors;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Run all the validations
|
|
64
|
+
* @param checkExistance - boolean
|
|
65
|
+
* @returns Error[]
|
|
66
|
+
*/
|
|
67
|
+
async allDynamic() {
|
|
68
|
+
const errors = [];
|
|
69
|
+
if ((this.schema?.length ?? 0) === 0)
|
|
70
|
+
errors.push(Error('schema missing'));
|
|
71
|
+
else if (!(await this.rootDomainExists()))
|
|
72
|
+
errors.push(Error(`schema root domain must exist [${this.rootDomain}]`));
|
|
73
|
+
return errors;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Determines how many levels of the schema's reverse domain
|
|
77
|
+
* pass DNS resolution
|
|
78
|
+
*
|
|
79
|
+
* @returns number (0 if none exist)
|
|
80
|
+
*/
|
|
81
|
+
async domainExistenceDepth() {
|
|
82
|
+
const levels = this.levels ?? 0;
|
|
83
|
+
let level = 0;
|
|
84
|
+
while (level < levels) {
|
|
85
|
+
if (!(await domainExists(this.domainLevel(level)))) {
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
level += 1;
|
|
89
|
+
}
|
|
90
|
+
return level;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Checks if the root domain validates via DNS resolution
|
|
94
|
+
*
|
|
95
|
+
* @returns boolean
|
|
96
|
+
*/
|
|
97
|
+
async rootDomainExists() {
|
|
98
|
+
return await domainExists(this.rootDomain);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* Get a domain for the schema at a certain level
|
|
103
|
+
*
|
|
104
|
+
* @param level - Zero based level to check
|
|
105
|
+
* @returns string
|
|
106
|
+
*/
|
|
107
|
+
domainLevel(level) {
|
|
108
|
+
return this.parts
|
|
109
|
+
?.slice(0, level + 1)
|
|
110
|
+
.reverse()
|
|
111
|
+
.join('.');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=SchemaNameValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaNameValidator.js","sourceRoot":"","sources":["../../src/SchemaNameValidator.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Validator, XyoValidatorBase } from '@xyo-network/core';
|
|
2
|
+
import { XyoPayload } from '@xyo-network/payload-model';
|
|
3
|
+
import { XyoSchemaNameValidator } from '../SchemaNameValidator';
|
|
4
|
+
export declare class PayloadValidator<T extends XyoPayload = XyoPayload> extends XyoValidatorBase<T> implements Validator<T> {
|
|
5
|
+
private _schemaValidator?;
|
|
6
|
+
constructor(payload: T);
|
|
7
|
+
get schemaValidator(): XyoSchemaNameValidator;
|
|
8
|
+
schemaName(): Error[];
|
|
9
|
+
validate(): Error[];
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=Validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../../src/Validator/Validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAEvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,qBAAa,gBAAgB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAE,YAAW,SAAS,CAAC,CAAC,CAAC;IAClH,OAAO,CAAC,gBAAgB,CAAC,CAAwB;gBAErC,OAAO,EAAE,CAAC;IAItB,IAAI,eAAe,2BAGlB;IAEM,UAAU;IAUV,QAAQ;CAKhB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { XyoValidatorBase } from '@xyo-network/core';
|
|
2
|
+
import { XyoSchemaNameValidator } from '../SchemaNameValidator';
|
|
3
|
+
export class PayloadValidator extends XyoValidatorBase {
|
|
4
|
+
_schemaValidator;
|
|
5
|
+
constructor(payload) {
|
|
6
|
+
super(payload);
|
|
7
|
+
}
|
|
8
|
+
get schemaValidator() {
|
|
9
|
+
this._schemaValidator = this._schemaValidator ?? new XyoSchemaNameValidator(this.obj.schema ?? '');
|
|
10
|
+
return this._schemaValidator;
|
|
11
|
+
}
|
|
12
|
+
schemaName() {
|
|
13
|
+
const errors = [];
|
|
14
|
+
if (this.obj.schema === undefined) {
|
|
15
|
+
errors.push(Error('schema missing'));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
errors.push(...this.schemaValidator.all());
|
|
19
|
+
}
|
|
20
|
+
return errors;
|
|
21
|
+
}
|
|
22
|
+
validate() {
|
|
23
|
+
const errors = [];
|
|
24
|
+
errors.push(...this.schemaName());
|
|
25
|
+
return errors;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=Validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Validator.js","sourceRoot":"","sources":["../../../src/Validator/Validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAG/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,MAAM,OAAO,gBAAoD,SAAQ,gBAAmB;IAClF,gBAAgB,CAAyB;IAEjD,YAAY,OAAU;QACpB,KAAK,CAAC,OAAO,CAAC,CAAA;IAChB,CAAC;IAED,IAAI,eAAe;QACjB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,IAAI,IAAI,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,CAAA;QAClG,OAAO,IAAI,CAAC,gBAAgB,CAAA;IAC9B,CAAC;IAEM,UAAU;QACf,MAAM,MAAM,GAAY,EAAE,CAAA;QAC1B,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE;YACjC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAA;SACrC;aAAM;YACL,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC,CAAA;SAC3C;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAEM,QAAQ;QACb,MAAM,MAAM,GAAY,EAAE,CAAA;QAC1B,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,CAAA;QACjC,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,aAAa,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xyo-network/payload-validator",
|
|
3
|
+
"author": {
|
|
4
|
+
"email": "support@xyo.network",
|
|
5
|
+
"name": "XYO Development Team",
|
|
6
|
+
"url": "https://xyo.network"
|
|
7
|
+
},
|
|
8
|
+
"bugs": {
|
|
9
|
+
"email": "support@xyo.network",
|
|
10
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@xyo-network/core": "^2.42.14",
|
|
14
|
+
"@xyo-network/dns": "^2.42.13",
|
|
15
|
+
"@xyo-network/payload-model": "^2.42.13"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@xylabs/ts-scripts-yarn3": "^2.10.19"
|
|
19
|
+
},
|
|
20
|
+
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
21
|
+
"browser": "dist/esm/index.js",
|
|
22
|
+
"docs": "dist/docs.json",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"node": {
|
|
26
|
+
"import": "./dist/esm/index.js",
|
|
27
|
+
"require": "./dist/cjs/index.js"
|
|
28
|
+
},
|
|
29
|
+
"browser": {
|
|
30
|
+
"import": "./dist/esm/index.js",
|
|
31
|
+
"require": "./dist/cjs/index.js"
|
|
32
|
+
},
|
|
33
|
+
"default": "./dist/esm/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./dist/docs.json": {
|
|
36
|
+
"default": "./dist/docs.json"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"main": "dist/cjs/index.js",
|
|
41
|
+
"module": "dist/esm/index.js",
|
|
42
|
+
"homepage": "https://xyo.network",
|
|
43
|
+
"license": "LGPL-3.0-only",
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
50
|
+
},
|
|
51
|
+
"sideEffects": false,
|
|
52
|
+
"types": "dist/esm/index.d.ts",
|
|
53
|
+
"version": "2.42.13"
|
|
54
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { domainExists } from '@xyo-network/dns'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Validates a XYO schema structure and existence
|
|
5
|
+
*/
|
|
6
|
+
export class XyoSchemaNameValidator {
|
|
7
|
+
public schema?: string
|
|
8
|
+
private _parts?: string[]
|
|
9
|
+
private _rootDomain?: string
|
|
10
|
+
constructor(schema?: string) {
|
|
11
|
+
this.schema = schema
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Checks whether the schema is all lowercase
|
|
16
|
+
*
|
|
17
|
+
* @returns boolean
|
|
18
|
+
*/
|
|
19
|
+
get isLowercase(): boolean {
|
|
20
|
+
return this.schema === this.schema?.toLowerCase()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Levels in the schema
|
|
25
|
+
*
|
|
26
|
+
* @returns number
|
|
27
|
+
*/
|
|
28
|
+
get levels(): number | undefined {
|
|
29
|
+
return this.parts?.length
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The schema converted into a string array split on '.'
|
|
34
|
+
*
|
|
35
|
+
* @returns string[]
|
|
36
|
+
*/
|
|
37
|
+
get parts() {
|
|
38
|
+
this._parts = this._parts ?? this.schema?.split('.')
|
|
39
|
+
return this._parts
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The rootDomain is the first two levels of the schema, in reverse order
|
|
44
|
+
* This can be used to determine who 'owns' that schema, based on domain
|
|
45
|
+
* registration
|
|
46
|
+
*
|
|
47
|
+
* @returns string
|
|
48
|
+
*/
|
|
49
|
+
get rootDomain(): string | undefined {
|
|
50
|
+
this._rootDomain = this._rootDomain ?? this.domainLevel(1)
|
|
51
|
+
return this._rootDomain
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Run all static validations
|
|
56
|
+
* @returns Error[]
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
public all() {
|
|
60
|
+
const errors: Error[] = []
|
|
61
|
+
if ((this.schema?.length ?? 0) === 0) errors.push(Error('schema missing'))
|
|
62
|
+
else if ((this.levels ?? 0) < 3) errors.push(Error(`schema levels < 3 [${this.levels}, ${this.schema}]`))
|
|
63
|
+
else if (!this.isLowercase) errors.push(Error(`schema not lowercase [${this.schema}]`))
|
|
64
|
+
return errors
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Run all the validations
|
|
69
|
+
* @param checkExistance - boolean
|
|
70
|
+
* @returns Error[]
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
public async allDynamic() {
|
|
74
|
+
const errors: Error[] = []
|
|
75
|
+
if ((this.schema?.length ?? 0) === 0) errors.push(Error('schema missing'))
|
|
76
|
+
else if (!(await this.rootDomainExists())) errors.push(Error(`schema root domain must exist [${this.rootDomain}]`))
|
|
77
|
+
return errors
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Determines how many levels of the schema's reverse domain
|
|
82
|
+
* pass DNS resolution
|
|
83
|
+
*
|
|
84
|
+
* @returns number (0 if none exist)
|
|
85
|
+
*/
|
|
86
|
+
public async domainExistenceDepth() {
|
|
87
|
+
const levels = this.levels ?? 0
|
|
88
|
+
let level = 0
|
|
89
|
+
while (level < levels) {
|
|
90
|
+
if (!(await domainExists(this.domainLevel(level)))) {
|
|
91
|
+
break
|
|
92
|
+
}
|
|
93
|
+
level += 1
|
|
94
|
+
}
|
|
95
|
+
return level
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Checks if the root domain validates via DNS resolution
|
|
100
|
+
*
|
|
101
|
+
* @returns boolean
|
|
102
|
+
*/
|
|
103
|
+
public async rootDomainExists() {
|
|
104
|
+
return await domainExists(this.rootDomain)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
*
|
|
109
|
+
* Get a domain for the schema at a certain level
|
|
110
|
+
*
|
|
111
|
+
* @param level - Zero based level to check
|
|
112
|
+
* @returns string
|
|
113
|
+
*/
|
|
114
|
+
private domainLevel(level: number): string | undefined {
|
|
115
|
+
return this.parts
|
|
116
|
+
?.slice(0, level + 1)
|
|
117
|
+
.reverse()
|
|
118
|
+
.join('.')
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { dumpErrors } from '@xyo-network/core'
|
|
2
|
+
import { XyoPayload } from '@xyo-network/payload-model'
|
|
3
|
+
|
|
4
|
+
import { PayloadValidator } from './Validator'
|
|
5
|
+
|
|
6
|
+
const testPayloadNoSchema: XyoPayload = {} as XyoPayload
|
|
7
|
+
const testPayloadMixedCase: XyoPayload = {
|
|
8
|
+
schema: 'network.xyo.testMixedCaseSchema',
|
|
9
|
+
} as XyoPayload
|
|
10
|
+
const testPayloadTooFewLevels: XyoPayload = {
|
|
11
|
+
schema: 'network.xyo',
|
|
12
|
+
} as XyoPayload
|
|
13
|
+
const testPayloadDoesNotExist: XyoPayload = {
|
|
14
|
+
schema: 'network.dfd-sf-sf-s.blahblah',
|
|
15
|
+
} as XyoPayload
|
|
16
|
+
const testPayloadValid: XyoPayload = {
|
|
17
|
+
schema: 'network.xyo.test',
|
|
18
|
+
} as XyoPayload
|
|
19
|
+
|
|
20
|
+
test('all [missing schema]', () => {
|
|
21
|
+
const validator = new PayloadValidator(testPayloadNoSchema)
|
|
22
|
+
const errors = validator.validate()
|
|
23
|
+
expect(errors.length).toBe(1)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('all [mixed case]', () => {
|
|
27
|
+
const validator = new PayloadValidator(testPayloadMixedCase)
|
|
28
|
+
const errors = validator.validate()
|
|
29
|
+
expect(errors.length).toBe(1)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('all [too few levels]', () => {
|
|
33
|
+
const validator = new PayloadValidator(testPayloadTooFewLevels)
|
|
34
|
+
const errors = validator.validate()
|
|
35
|
+
expect(errors.length).toBe(1)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('all [does not exist]', () => {
|
|
39
|
+
const validator = new PayloadValidator(testPayloadDoesNotExist)
|
|
40
|
+
const errors = validator.validate()
|
|
41
|
+
dumpErrors(errors)
|
|
42
|
+
expect(errors.length).toBe(0)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('all [valid]', () => {
|
|
46
|
+
const validator = new PayloadValidator(testPayloadValid)
|
|
47
|
+
|
|
48
|
+
let errors: Error[] = []
|
|
49
|
+
errors = validator.validate()
|
|
50
|
+
dumpErrors(errors)
|
|
51
|
+
expect(errors.length).toBe(0)
|
|
52
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Validator, XyoValidatorBase } from '@xyo-network/core'
|
|
2
|
+
import { XyoPayload } from '@xyo-network/payload-model'
|
|
3
|
+
|
|
4
|
+
import { XyoSchemaNameValidator } from '../SchemaNameValidator'
|
|
5
|
+
|
|
6
|
+
export class PayloadValidator<T extends XyoPayload = XyoPayload> extends XyoValidatorBase<T> implements Validator<T> {
|
|
7
|
+
private _schemaValidator?: XyoSchemaNameValidator
|
|
8
|
+
|
|
9
|
+
constructor(payload: T) {
|
|
10
|
+
super(payload)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get schemaValidator() {
|
|
14
|
+
this._schemaValidator = this._schemaValidator ?? new XyoSchemaNameValidator(this.obj.schema ?? '')
|
|
15
|
+
return this._schemaValidator
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public schemaName() {
|
|
19
|
+
const errors: Error[] = []
|
|
20
|
+
if (this.obj.schema === undefined) {
|
|
21
|
+
errors.push(Error('schema missing'))
|
|
22
|
+
} else {
|
|
23
|
+
errors.push(...this.schemaValidator.all())
|
|
24
|
+
}
|
|
25
|
+
return errors
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public validate() {
|
|
29
|
+
const errors: Error[] = []
|
|
30
|
+
errors.push(...this.schemaName())
|
|
31
|
+
return errors
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Validator'
|
package/src/index.ts
ADDED