@extrahorizon/exh-cli 1.5.0 → 1.5.1-dev-27-7bdff2e
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/CHANGELOG.md +56 -53
- package/README.md +0 -12
- package/build/commands/completion.d.ts +5 -5
- package/build/commands/completion.js +38 -38
- package/build/commands/data/schemas/delete.d.ts +10 -10
- package/build/commands/data/schemas/delete.js +29 -29
- package/build/commands/data/schemas/list.d.ts +8 -8
- package/build/commands/data/schemas/list.js +20 -20
- package/build/commands/data/schemas/sync/statusHelpers.d.ts +3 -3
- package/build/commands/data/schemas/sync/statusHelpers.js +49 -49
- package/build/commands/data/schemas/sync.d.ts +35 -35
- package/build/commands/data/schemas/sync.js +72 -72
- package/build/commands/data/schemas/util/listFilesInDir.d.ts +1 -1
- package/build/commands/data/schemas/util/listFilesInDir.js +25 -25
- package/build/commands/data/schemas/util/metaschema.json +455 -455
- package/build/commands/data/schemas/util/readJson.d.ts +1 -1
- package/build/commands/data/schemas/util/readJson.js +11 -11
- package/build/commands/data/schemas/util/schemaverify.d.ts +28 -28
- package/build/commands/data/schemas/util/schemaverify.js +202 -202
- package/build/commands/data/schemas/util/syncSchema.d.ts +20 -20
- package/build/commands/data/schemas/util/syncSchema.js +276 -276
- package/build/commands/data/schemas/util/tests/listFilesInDir.test.d.ts +1 -1
- package/build/commands/data/schemas/util/tests/listFilesInDir.test.js +40 -40
- package/build/commands/data/schemas/verify.d.ts +18 -18
- package/build/commands/data/schemas/verify.js +82 -82
- package/build/commands/data/schemas.d.ts +5 -5
- package/build/commands/data/schemas.js +10 -10
- package/build/commands/data.d.ts +5 -5
- package/build/commands/data.js +10 -10
- package/build/commands/dispatchers/sync.d.ts +21 -21
- package/build/commands/dispatchers/sync.js +24 -24
- package/build/commands/dispatchers.d.ts +5 -5
- package/build/commands/dispatchers.js +10 -10
- package/build/commands/login.d.ts +37 -37
- package/build/commands/login.js +59 -59
- package/build/commands/sync.d.ts +55 -55
- package/build/commands/sync.js +107 -107
- package/build/commands/tasks/createrepo.d.ts +22 -22
- package/build/commands/tasks/createrepo.js +70 -70
- package/build/commands/tasks/delete.d.ts +10 -10
- package/build/commands/tasks/delete.js +29 -29
- package/build/commands/tasks/list.d.ts +8 -8
- package/build/commands/tasks/list.js +27 -27
- package/build/commands/tasks/sync.d.ts +56 -56
- package/build/commands/tasks/sync.js +122 -122
- package/build/commands/tasks/taskConfig.d.ts +24 -24
- package/build/commands/tasks/taskConfig.js +169 -169
- package/build/commands/tasks/util.d.ts +1 -1
- package/build/commands/tasks/util.js +27 -27
- package/build/commands/tasks.d.ts +5 -5
- package/build/commands/tasks.js +10 -10
- package/build/commands/templates/delete.d.ts +19 -19
- package/build/commands/templates/delete.js +48 -48
- package/build/commands/templates/get.d.ts +19 -19
- package/build/commands/templates/get.js +37 -37
- package/build/commands/templates/list.d.ts +9 -9
- package/build/commands/templates/list.js +25 -25
- package/build/commands/templates/sync.d.ts +22 -22
- package/build/commands/templates/sync.js +65 -65
- package/build/commands/templates/util/buildTemplates.d.ts +2 -2
- package/build/commands/templates/util/buildTemplates.js +50 -50
- package/build/commands/templates/util/readTemplateFiles.d.ts +3 -3
- package/build/commands/templates/util/readTemplateFiles.js +52 -52
- package/build/commands/templates/util/templateService.d.ts +8 -8
- package/build/commands/templates/util/templateService.js +18 -18
- package/build/commands/templates/util/uploadTemplate.d.ts +2 -2
- package/build/commands/templates/util/uploadTemplate.js +20 -20
- package/build/commands/templates/util/utils.d.ts +4 -4
- package/build/commands/templates/util/utils.js +22 -22
- package/build/commands/templates.d.ts +5 -5
- package/build/commands/templates.js +10 -10
- package/build/constants.d.ts +13 -13
- package/build/constants.js +37 -37
- package/build/exh.d.ts +3 -3
- package/build/exh.js +65 -65
- package/build/helpers/error.d.ts +2 -2
- package/build/helpers/error.js +6 -6
- package/build/helpers/repoConfig.d.ts +2 -2
- package/build/helpers/repoConfig.js +60 -60
- package/build/helpers/util.d.ts +3 -3
- package/build/helpers/util.js +36 -36
- package/build/index.d.ts +2 -2
- package/build/index.js +33 -33
- package/build/repositories/dispatchers.d.ts +8 -8
- package/build/repositories/dispatchers.js +31 -31
- package/build/repositories/functions.d.ts +24 -24
- package/build/repositories/functions.js +28 -28
- package/build/repositories/schemas.d.ts +44 -44
- package/build/repositories/schemas.js +86 -86
- package/build/services/dispatchers.d.ts +3 -3
- package/build/services/dispatchers.js +132 -132
- package/package.json +53 -53
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function readJsonFile(filePath: string): Promise<any>;
|
|
1
|
+
export declare function readJsonFile(filePath: string): Promise<any>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readJsonFile = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const util_1 = require("util");
|
|
6
|
-
const readFile = (0, util_1.promisify)(fs.readFile);
|
|
7
|
-
async function readJsonFile(filePath) {
|
|
8
|
-
const file = await readFile(filePath);
|
|
9
|
-
return JSON.parse(file.toString());
|
|
10
|
-
}
|
|
11
|
-
exports.readJsonFile = readJsonFile;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readJsonFile = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const util_1 = require("util");
|
|
6
|
+
const readFile = (0, util_1.promisify)(fs.readFile);
|
|
7
|
+
async function readJsonFile(filePath) {
|
|
8
|
+
const file = await readFile(filePath);
|
|
9
|
+
return JSON.parse(file.toString());
|
|
10
|
+
}
|
|
11
|
+
exports.readJsonFile = readJsonFile;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import Ajv from 'ajv';
|
|
2
|
-
export declare enum TestId {
|
|
3
|
-
META_SCHEMA = 1,
|
|
4
|
-
PROPERTY_VERIFY = 2,
|
|
5
|
-
INPUT_CONDITIONS = 3,
|
|
6
|
-
STATUS_CHECK = 4,
|
|
7
|
-
CONDITION_TYPES = 5,
|
|
8
|
-
TRANSITION_NAMES = 6
|
|
9
|
-
}
|
|
10
|
-
interface InternalTestResult {
|
|
11
|
-
ok: boolean;
|
|
12
|
-
errors: any[];
|
|
13
|
-
}
|
|
14
|
-
export interface TestResult extends InternalTestResult {
|
|
15
|
-
id: TestId;
|
|
16
|
-
test: string;
|
|
17
|
-
}
|
|
18
|
-
export declare class SchemaVerify {
|
|
19
|
-
#private;
|
|
20
|
-
private ajv;
|
|
21
|
-
private schema;
|
|
22
|
-
private metaSchema;
|
|
23
|
-
constructor(ajv: Ajv, schema: any, metaSchema: any);
|
|
24
|
-
RunChecks(): Generator<TestResult>;
|
|
25
|
-
validateTransition(transition: any, name: string): any[];
|
|
26
|
-
validateConditionPropertiesAgainstSchemaProperties(conditionProperties: any, schemaProperties: any, path: string): Set<any>;
|
|
27
|
-
}
|
|
28
|
-
export {};
|
|
1
|
+
import Ajv from 'ajv';
|
|
2
|
+
export declare enum TestId {
|
|
3
|
+
META_SCHEMA = 1,
|
|
4
|
+
PROPERTY_VERIFY = 2,
|
|
5
|
+
INPUT_CONDITIONS = 3,
|
|
6
|
+
STATUS_CHECK = 4,
|
|
7
|
+
CONDITION_TYPES = 5,
|
|
8
|
+
TRANSITION_NAMES = 6
|
|
9
|
+
}
|
|
10
|
+
interface InternalTestResult {
|
|
11
|
+
ok: boolean;
|
|
12
|
+
errors: any[];
|
|
13
|
+
}
|
|
14
|
+
export interface TestResult extends InternalTestResult {
|
|
15
|
+
id: TestId;
|
|
16
|
+
test: string;
|
|
17
|
+
}
|
|
18
|
+
export declare class SchemaVerify {
|
|
19
|
+
#private;
|
|
20
|
+
private ajv;
|
|
21
|
+
private schema;
|
|
22
|
+
private metaSchema;
|
|
23
|
+
constructor(ajv: Ajv, schema: any, metaSchema: any);
|
|
24
|
+
RunChecks(): Generator<TestResult>;
|
|
25
|
+
validateTransition(transition: any, name: string): any[];
|
|
26
|
+
validateConditionPropertiesAgainstSchemaProperties(conditionProperties: any, schemaProperties: any, path: string): Set<any>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -1,202 +1,202 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var _SchemaVerify_instances, _SchemaVerify_verifyMetaSchema, _SchemaVerify_verifyTransitionNames, _SchemaVerify_verifyProperties, _SchemaVerify_verifyStatuses, _SchemaVerify_verifyInputConditions, _SchemaVerify_verifyConditionTypes;
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.SchemaVerify = exports.TestId = void 0;
|
|
10
|
-
var TestId;
|
|
11
|
-
(function (TestId) {
|
|
12
|
-
TestId[TestId["META_SCHEMA"] = 1] = "META_SCHEMA";
|
|
13
|
-
TestId[TestId["PROPERTY_VERIFY"] = 2] = "PROPERTY_VERIFY";
|
|
14
|
-
TestId[TestId["INPUT_CONDITIONS"] = 3] = "INPUT_CONDITIONS";
|
|
15
|
-
TestId[TestId["STATUS_CHECK"] = 4] = "STATUS_CHECK";
|
|
16
|
-
TestId[TestId["CONDITION_TYPES"] = 5] = "CONDITION_TYPES";
|
|
17
|
-
TestId[TestId["TRANSITION_NAMES"] = 6] = "TRANSITION_NAMES";
|
|
18
|
-
})(TestId = exports.TestId || (exports.TestId = {}));
|
|
19
|
-
function transformAjvErrors(offsetPath, errors) {
|
|
20
|
-
const result = {};
|
|
21
|
-
for (const error of errors) {
|
|
22
|
-
const path = offsetPath + error.instancePath;
|
|
23
|
-
if (!result[path]) {
|
|
24
|
-
result[path] = [];
|
|
25
|
-
}
|
|
26
|
-
result[path].push(`${error.message} ${error.params ? JSON.stringify(error.params) : ''}`);
|
|
27
|
-
}
|
|
28
|
-
return Object.keys(result).map(r => [r, ...result[r].map((m) => `\t-${m}`)]).flat();
|
|
29
|
-
}
|
|
30
|
-
class SchemaVerify {
|
|
31
|
-
constructor(ajv, schema, metaSchema) {
|
|
32
|
-
_SchemaVerify_instances.add(this);
|
|
33
|
-
this.ajv = ajv;
|
|
34
|
-
this.schema = schema;
|
|
35
|
-
this.metaSchema = metaSchema;
|
|
36
|
-
}
|
|
37
|
-
*RunChecks() {
|
|
38
|
-
yield { id: TestId.META_SCHEMA, test: 'Check if the schema is in the correct form', ...__classPrivateFieldGet(this, _SchemaVerify_instances, "m", _SchemaVerify_verifyMetaSchema).call(this) };
|
|
39
|
-
yield { id: TestId.PROPERTY_VERIFY, test: 'Check if the properties object is valid JSON schema', ...__classPrivateFieldGet(this, _SchemaVerify_instances, "m", _SchemaVerify_verifyProperties).call(this) };
|
|
40
|
-
yield { id: TestId.INPUT_CONDITIONS, test: 'Check if all input conditions of transitions are valid JSON schema', ...__classPrivateFieldGet(this, _SchemaVerify_instances, "m", _SchemaVerify_verifyInputConditions).call(this) };
|
|
41
|
-
yield { id: TestId.STATUS_CHECK, test: 'Check if all statuses are accounted for', ...__classPrivateFieldGet(this, _SchemaVerify_instances, "m", _SchemaVerify_verifyStatuses).call(this) };
|
|
42
|
-
yield { id: TestId.CONDITION_TYPES, test: 'Check if all condition types are used in the correct transitions', ...__classPrivateFieldGet(this, _SchemaVerify_instances, "m", _SchemaVerify_verifyConditionTypes).call(this) };
|
|
43
|
-
yield { id: TestId.TRANSITION_NAMES, test: 'Check if all transition names are unique', ...__classPrivateFieldGet(this, _SchemaVerify_instances, "m", _SchemaVerify_verifyTransitionNames).call(this) };
|
|
44
|
-
}
|
|
45
|
-
validateTransition(transition, name) {
|
|
46
|
-
const errors = [];
|
|
47
|
-
const conditions = transition.conditions || [];
|
|
48
|
-
for (const [index, condition] of Object.entries(conditions)) {
|
|
49
|
-
if (condition.type === 'input') {
|
|
50
|
-
condition.configuration.$schema = 'http://json-schema.org/draft-07/schema#';
|
|
51
|
-
const isValidConfiguration = this.ajv.validateSchema(condition.configuration);
|
|
52
|
-
if (!isValidConfiguration) {
|
|
53
|
-
errors.push(...transformAjvErrors(`/creationTransition/conditions[${index}]/configuration`, this.ajv.errors));
|
|
54
|
-
}
|
|
55
|
-
const result = this.validateConditionPropertiesAgainstSchemaProperties(condition.configuration.properties, this.schema.properties, '');
|
|
56
|
-
result.forEach((error) => errors.push(`Transition - ${name} : property ${error}`));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return errors;
|
|
60
|
-
}
|
|
61
|
-
validateConditionPropertiesAgainstSchemaProperties(conditionProperties, schemaProperties, path) {
|
|
62
|
-
const invalidPaths = new Set([]);
|
|
63
|
-
if (typeof conditionProperties !== 'object') {
|
|
64
|
-
return invalidPaths;
|
|
65
|
-
}
|
|
66
|
-
for (const key of Object.keys(conditionProperties)) {
|
|
67
|
-
const conditionProperty = conditionProperties[key];
|
|
68
|
-
const schemaProperty = schemaProperties?.[key];
|
|
69
|
-
if (key === 'type' && typeof conditionProperty === 'string') {
|
|
70
|
-
if (schemaProperty && conditionProperty !== schemaProperty) {
|
|
71
|
-
invalidPaths.add(`'${path}.type' does not match the value found in the schema properties`);
|
|
72
|
-
}
|
|
73
|
-
if (!schemaProperty) {
|
|
74
|
-
invalidPaths.add(`'${path}' is defined in the condition properties, but not defined in the schema properties`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const currentPath = path ? `${path}.${key}` : key;
|
|
78
|
-
const result = this.validateConditionPropertiesAgainstSchemaProperties(conditionProperty, schemaProperty, currentPath);
|
|
79
|
-
result.forEach(error => invalidPaths.add(error));
|
|
80
|
-
}
|
|
81
|
-
return invalidPaths;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.SchemaVerify = SchemaVerify;
|
|
85
|
-
_SchemaVerify_instances = new WeakSet(), _SchemaVerify_verifyMetaSchema = function _SchemaVerify_verifyMetaSchema() {
|
|
86
|
-
const validate = this.ajv.compile(this.metaSchema);
|
|
87
|
-
if (!validate(this.schema)) {
|
|
88
|
-
return { ok: false, errors: transformAjvErrors('', validate.errors) };
|
|
89
|
-
}
|
|
90
|
-
return { ok: true, errors: [] };
|
|
91
|
-
}, _SchemaVerify_verifyTransitionNames = function _SchemaVerify_verifyTransitionNames() {
|
|
92
|
-
const transitionNames = new Set();
|
|
93
|
-
const nonUniqueNames = new Set();
|
|
94
|
-
for (const transition of (this.schema.transitions || [])) {
|
|
95
|
-
const { name } = transition;
|
|
96
|
-
if (transitionNames.has(name)) {
|
|
97
|
-
nonUniqueNames.add(name);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
transitionNames.add(name);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return { ok: nonUniqueNames.size === 0, errors: [...nonUniqueNames].map(name => `Transition name '${name}' is not unique`) };
|
|
104
|
-
}, _SchemaVerify_verifyProperties = function _SchemaVerify_verifyProperties() {
|
|
105
|
-
if (this.schema.properties) {
|
|
106
|
-
const tmpSchema = {
|
|
107
|
-
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
108
|
-
type: 'object',
|
|
109
|
-
properties: this.schema.properties,
|
|
110
|
-
};
|
|
111
|
-
if (!this.ajv.validateSchema(tmpSchema)) {
|
|
112
|
-
return { ok: false, errors: transformAjvErrors('', this.ajv.errors) };
|
|
113
|
-
}
|
|
114
|
-
const errors = getIdInObjectArrayErrors(this.schema.properties);
|
|
115
|
-
if (errors.length > 0) {
|
|
116
|
-
return { ok: false, errors: errors.map(path => `The following id property is not allowed: ${path}`) };
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return { ok: true, errors: [] };
|
|
120
|
-
}, _SchemaVerify_verifyStatuses = function _SchemaVerify_verifyStatuses() {
|
|
121
|
-
let ok = true;
|
|
122
|
-
const errors = [];
|
|
123
|
-
let statusList = new Set();
|
|
124
|
-
if (this.schema.transitions) {
|
|
125
|
-
statusList = new Set([
|
|
126
|
-
...statusList.entries(),
|
|
127
|
-
...this.schema.transitions.map((t) => t.fromStatuses).flat(),
|
|
128
|
-
...this.schema.transitions.map((t) => t.toStatus),
|
|
129
|
-
]);
|
|
130
|
-
}
|
|
131
|
-
if (this.schema.creationTransition) {
|
|
132
|
-
statusList = new Set([...statusList.values(), this.schema.creationTransition.toStatus]);
|
|
133
|
-
}
|
|
134
|
-
Object.keys(this.schema.statuses || []).forEach(status => {
|
|
135
|
-
if (!statusList.has(status)) {
|
|
136
|
-
errors.push(`Status '${status}' is defined in the schema statuses but not used in any transition`);
|
|
137
|
-
ok = false;
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
for (const status of statusList) {
|
|
141
|
-
if (this.schema.statuses[status] === undefined) {
|
|
142
|
-
errors.push(`Status '${status}' is not defined in the status list`);
|
|
143
|
-
ok = false;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return { ok, errors };
|
|
147
|
-
}, _SchemaVerify_verifyInputConditions = function _SchemaVerify_verifyInputConditions() {
|
|
148
|
-
let ok = true;
|
|
149
|
-
const errors = [];
|
|
150
|
-
if (this.schema.creationTransition?.conditions?.length) {
|
|
151
|
-
const result = this.validateTransition(this.schema.creationTransition, 'creationTransition');
|
|
152
|
-
errors.push(...result);
|
|
153
|
-
}
|
|
154
|
-
if (this.schema.transitions?.length) {
|
|
155
|
-
for (const transition of this.schema.transitions) {
|
|
156
|
-
const result = this.validateTransition(transition, `${transition.name}`);
|
|
157
|
-
errors.push(...result);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
if (errors.length) {
|
|
161
|
-
ok = false;
|
|
162
|
-
}
|
|
163
|
-
return { ok, errors };
|
|
164
|
-
}, _SchemaVerify_verifyConditionTypes = function _SchemaVerify_verifyConditionTypes() {
|
|
165
|
-
let ok = true;
|
|
166
|
-
const errors = [];
|
|
167
|
-
if (this.schema.transitions) {
|
|
168
|
-
for (const [tIndex, transition] of this.schema.transitions.entries()) {
|
|
169
|
-
if (transition.type === 'manual' || !transition.conditions) {
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
for (const [cIndex, condition] of transition.conditions.entries()) {
|
|
173
|
-
if (['input', 'initiator'].includes(condition.type)) {
|
|
174
|
-
ok = false;
|
|
175
|
-
errors.push(`/transitions[${tIndex}]/conditions[${cIndex}] type cannot be ${condition.type} in a non-manual transition`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return { ok, errors };
|
|
181
|
-
};
|
|
182
|
-
function getIdInObjectArrayErrors(properties, path = []) {
|
|
183
|
-
const pathsWithIdInArray = [];
|
|
184
|
-
let name;
|
|
185
|
-
let value;
|
|
186
|
-
for ([name, value] of Object.entries(properties)) {
|
|
187
|
-
while (value.type === 'array' && value.items.type === 'array') {
|
|
188
|
-
value = value.items;
|
|
189
|
-
name = `${name}.items`;
|
|
190
|
-
}
|
|
191
|
-
if (value.type === 'array' && value.items.type === 'object') {
|
|
192
|
-
if ('id' in value.items.properties) {
|
|
193
|
-
pathsWithIdInArray.push([...path, `${name}.items.properties`, 'id'].join('.'));
|
|
194
|
-
}
|
|
195
|
-
pathsWithIdInArray.push(...getIdInObjectArrayErrors(value.items.properties, [...path, `${name}.items.properties`]));
|
|
196
|
-
}
|
|
197
|
-
if (value.type === 'object') {
|
|
198
|
-
pathsWithIdInArray.push(...getIdInObjectArrayErrors(value.properties, [...path, `${name}.properties`]));
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return pathsWithIdInArray;
|
|
202
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _SchemaVerify_instances, _SchemaVerify_verifyMetaSchema, _SchemaVerify_verifyTransitionNames, _SchemaVerify_verifyProperties, _SchemaVerify_verifyStatuses, _SchemaVerify_verifyInputConditions, _SchemaVerify_verifyConditionTypes;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SchemaVerify = exports.TestId = void 0;
|
|
10
|
+
var TestId;
|
|
11
|
+
(function (TestId) {
|
|
12
|
+
TestId[TestId["META_SCHEMA"] = 1] = "META_SCHEMA";
|
|
13
|
+
TestId[TestId["PROPERTY_VERIFY"] = 2] = "PROPERTY_VERIFY";
|
|
14
|
+
TestId[TestId["INPUT_CONDITIONS"] = 3] = "INPUT_CONDITIONS";
|
|
15
|
+
TestId[TestId["STATUS_CHECK"] = 4] = "STATUS_CHECK";
|
|
16
|
+
TestId[TestId["CONDITION_TYPES"] = 5] = "CONDITION_TYPES";
|
|
17
|
+
TestId[TestId["TRANSITION_NAMES"] = 6] = "TRANSITION_NAMES";
|
|
18
|
+
})(TestId = exports.TestId || (exports.TestId = {}));
|
|
19
|
+
function transformAjvErrors(offsetPath, errors) {
|
|
20
|
+
const result = {};
|
|
21
|
+
for (const error of errors) {
|
|
22
|
+
const path = offsetPath + error.instancePath;
|
|
23
|
+
if (!result[path]) {
|
|
24
|
+
result[path] = [];
|
|
25
|
+
}
|
|
26
|
+
result[path].push(`${error.message} ${error.params ? JSON.stringify(error.params) : ''}`);
|
|
27
|
+
}
|
|
28
|
+
return Object.keys(result).map(r => [r, ...result[r].map((m) => `\t-${m}`)]).flat();
|
|
29
|
+
}
|
|
30
|
+
class SchemaVerify {
|
|
31
|
+
constructor(ajv, schema, metaSchema) {
|
|
32
|
+
_SchemaVerify_instances.add(this);
|
|
33
|
+
this.ajv = ajv;
|
|
34
|
+
this.schema = schema;
|
|
35
|
+
this.metaSchema = metaSchema;
|
|
36
|
+
}
|
|
37
|
+
*RunChecks() {
|
|
38
|
+
yield { id: TestId.META_SCHEMA, test: 'Check if the schema is in the correct form', ...__classPrivateFieldGet(this, _SchemaVerify_instances, "m", _SchemaVerify_verifyMetaSchema).call(this) };
|
|
39
|
+
yield { id: TestId.PROPERTY_VERIFY, test: 'Check if the properties object is valid JSON schema', ...__classPrivateFieldGet(this, _SchemaVerify_instances, "m", _SchemaVerify_verifyProperties).call(this) };
|
|
40
|
+
yield { id: TestId.INPUT_CONDITIONS, test: 'Check if all input conditions of transitions are valid JSON schema', ...__classPrivateFieldGet(this, _SchemaVerify_instances, "m", _SchemaVerify_verifyInputConditions).call(this) };
|
|
41
|
+
yield { id: TestId.STATUS_CHECK, test: 'Check if all statuses are accounted for', ...__classPrivateFieldGet(this, _SchemaVerify_instances, "m", _SchemaVerify_verifyStatuses).call(this) };
|
|
42
|
+
yield { id: TestId.CONDITION_TYPES, test: 'Check if all condition types are used in the correct transitions', ...__classPrivateFieldGet(this, _SchemaVerify_instances, "m", _SchemaVerify_verifyConditionTypes).call(this) };
|
|
43
|
+
yield { id: TestId.TRANSITION_NAMES, test: 'Check if all transition names are unique', ...__classPrivateFieldGet(this, _SchemaVerify_instances, "m", _SchemaVerify_verifyTransitionNames).call(this) };
|
|
44
|
+
}
|
|
45
|
+
validateTransition(transition, name) {
|
|
46
|
+
const errors = [];
|
|
47
|
+
const conditions = transition.conditions || [];
|
|
48
|
+
for (const [index, condition] of Object.entries(conditions)) {
|
|
49
|
+
if (condition.type === 'input') {
|
|
50
|
+
condition.configuration.$schema = 'http://json-schema.org/draft-07/schema#';
|
|
51
|
+
const isValidConfiguration = this.ajv.validateSchema(condition.configuration);
|
|
52
|
+
if (!isValidConfiguration) {
|
|
53
|
+
errors.push(...transformAjvErrors(`/creationTransition/conditions[${index}]/configuration`, this.ajv.errors));
|
|
54
|
+
}
|
|
55
|
+
const result = this.validateConditionPropertiesAgainstSchemaProperties(condition.configuration.properties, this.schema.properties, '');
|
|
56
|
+
result.forEach((error) => errors.push(`Transition - ${name} : property ${error}`));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return errors;
|
|
60
|
+
}
|
|
61
|
+
validateConditionPropertiesAgainstSchemaProperties(conditionProperties, schemaProperties, path) {
|
|
62
|
+
const invalidPaths = new Set([]);
|
|
63
|
+
if (typeof conditionProperties !== 'object') {
|
|
64
|
+
return invalidPaths;
|
|
65
|
+
}
|
|
66
|
+
for (const key of Object.keys(conditionProperties)) {
|
|
67
|
+
const conditionProperty = conditionProperties[key];
|
|
68
|
+
const schemaProperty = schemaProperties?.[key];
|
|
69
|
+
if (key === 'type' && typeof conditionProperty === 'string') {
|
|
70
|
+
if (schemaProperty && conditionProperty !== schemaProperty) {
|
|
71
|
+
invalidPaths.add(`'${path}.type' does not match the value found in the schema properties`);
|
|
72
|
+
}
|
|
73
|
+
if (!schemaProperty) {
|
|
74
|
+
invalidPaths.add(`'${path}' is defined in the condition properties, but not defined in the schema properties`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const currentPath = path ? `${path}.${key}` : key;
|
|
78
|
+
const result = this.validateConditionPropertiesAgainstSchemaProperties(conditionProperty, schemaProperty, currentPath);
|
|
79
|
+
result.forEach(error => invalidPaths.add(error));
|
|
80
|
+
}
|
|
81
|
+
return invalidPaths;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.SchemaVerify = SchemaVerify;
|
|
85
|
+
_SchemaVerify_instances = new WeakSet(), _SchemaVerify_verifyMetaSchema = function _SchemaVerify_verifyMetaSchema() {
|
|
86
|
+
const validate = this.ajv.compile(this.metaSchema);
|
|
87
|
+
if (!validate(this.schema)) {
|
|
88
|
+
return { ok: false, errors: transformAjvErrors('', validate.errors) };
|
|
89
|
+
}
|
|
90
|
+
return { ok: true, errors: [] };
|
|
91
|
+
}, _SchemaVerify_verifyTransitionNames = function _SchemaVerify_verifyTransitionNames() {
|
|
92
|
+
const transitionNames = new Set();
|
|
93
|
+
const nonUniqueNames = new Set();
|
|
94
|
+
for (const transition of (this.schema.transitions || [])) {
|
|
95
|
+
const { name } = transition;
|
|
96
|
+
if (transitionNames.has(name)) {
|
|
97
|
+
nonUniqueNames.add(name);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
transitionNames.add(name);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { ok: nonUniqueNames.size === 0, errors: [...nonUniqueNames].map(name => `Transition name '${name}' is not unique`) };
|
|
104
|
+
}, _SchemaVerify_verifyProperties = function _SchemaVerify_verifyProperties() {
|
|
105
|
+
if (this.schema.properties) {
|
|
106
|
+
const tmpSchema = {
|
|
107
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
108
|
+
type: 'object',
|
|
109
|
+
properties: this.schema.properties,
|
|
110
|
+
};
|
|
111
|
+
if (!this.ajv.validateSchema(tmpSchema)) {
|
|
112
|
+
return { ok: false, errors: transformAjvErrors('', this.ajv.errors) };
|
|
113
|
+
}
|
|
114
|
+
const errors = getIdInObjectArrayErrors(this.schema.properties);
|
|
115
|
+
if (errors.length > 0) {
|
|
116
|
+
return { ok: false, errors: errors.map(path => `The following id property is not allowed: ${path}`) };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return { ok: true, errors: [] };
|
|
120
|
+
}, _SchemaVerify_verifyStatuses = function _SchemaVerify_verifyStatuses() {
|
|
121
|
+
let ok = true;
|
|
122
|
+
const errors = [];
|
|
123
|
+
let statusList = new Set();
|
|
124
|
+
if (this.schema.transitions) {
|
|
125
|
+
statusList = new Set([
|
|
126
|
+
...statusList.entries(),
|
|
127
|
+
...this.schema.transitions.map((t) => t.fromStatuses).flat(),
|
|
128
|
+
...this.schema.transitions.map((t) => t.toStatus),
|
|
129
|
+
]);
|
|
130
|
+
}
|
|
131
|
+
if (this.schema.creationTransition) {
|
|
132
|
+
statusList = new Set([...statusList.values(), this.schema.creationTransition.toStatus]);
|
|
133
|
+
}
|
|
134
|
+
Object.keys(this.schema.statuses || []).forEach(status => {
|
|
135
|
+
if (!statusList.has(status)) {
|
|
136
|
+
errors.push(`Status '${status}' is defined in the schema statuses but not used in any transition`);
|
|
137
|
+
ok = false;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
for (const status of statusList) {
|
|
141
|
+
if (this.schema.statuses[status] === undefined) {
|
|
142
|
+
errors.push(`Status '${status}' is not defined in the status list`);
|
|
143
|
+
ok = false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return { ok, errors };
|
|
147
|
+
}, _SchemaVerify_verifyInputConditions = function _SchemaVerify_verifyInputConditions() {
|
|
148
|
+
let ok = true;
|
|
149
|
+
const errors = [];
|
|
150
|
+
if (this.schema.creationTransition?.conditions?.length) {
|
|
151
|
+
const result = this.validateTransition(this.schema.creationTransition, 'creationTransition');
|
|
152
|
+
errors.push(...result);
|
|
153
|
+
}
|
|
154
|
+
if (this.schema.transitions?.length) {
|
|
155
|
+
for (const transition of this.schema.transitions) {
|
|
156
|
+
const result = this.validateTransition(transition, `${transition.name}`);
|
|
157
|
+
errors.push(...result);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (errors.length) {
|
|
161
|
+
ok = false;
|
|
162
|
+
}
|
|
163
|
+
return { ok, errors };
|
|
164
|
+
}, _SchemaVerify_verifyConditionTypes = function _SchemaVerify_verifyConditionTypes() {
|
|
165
|
+
let ok = true;
|
|
166
|
+
const errors = [];
|
|
167
|
+
if (this.schema.transitions) {
|
|
168
|
+
for (const [tIndex, transition] of this.schema.transitions.entries()) {
|
|
169
|
+
if (transition.type === 'manual' || !transition.conditions) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
for (const [cIndex, condition] of transition.conditions.entries()) {
|
|
173
|
+
if (['input', 'initiator'].includes(condition.type)) {
|
|
174
|
+
ok = false;
|
|
175
|
+
errors.push(`/transitions[${tIndex}]/conditions[${cIndex}] type cannot be ${condition.type} in a non-manual transition`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return { ok, errors };
|
|
181
|
+
};
|
|
182
|
+
function getIdInObjectArrayErrors(properties, path = []) {
|
|
183
|
+
const pathsWithIdInArray = [];
|
|
184
|
+
let name;
|
|
185
|
+
let value;
|
|
186
|
+
for ([name, value] of Object.entries(properties)) {
|
|
187
|
+
while (value.type === 'array' && value.items.type === 'array') {
|
|
188
|
+
value = value.items;
|
|
189
|
+
name = `${name}.items`;
|
|
190
|
+
}
|
|
191
|
+
if (value.type === 'array' && value.items.type === 'object') {
|
|
192
|
+
if ('id' in value.items.properties) {
|
|
193
|
+
pathsWithIdInArray.push([...path, `${name}.items.properties`, 'id'].join('.'));
|
|
194
|
+
}
|
|
195
|
+
pathsWithIdInArray.push(...getIdInObjectArrayErrors(value.items.properties, [...path, `${name}.items.properties`]));
|
|
196
|
+
}
|
|
197
|
+
if (value.type === 'object') {
|
|
198
|
+
pathsWithIdInArray.push(...getIdInObjectArrayErrors(value.properties, [...path, `${name}.properties`]));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return pathsWithIdInArray;
|
|
202
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export declare class SyncSchema {
|
|
2
|
-
#private;
|
|
3
|
-
private sdk;
|
|
4
|
-
private dry;
|
|
5
|
-
private cloudSchema;
|
|
6
|
-
private localSchema;
|
|
7
|
-
static createSchemaSync(sdk: any, dry?: boolean): SyncSchema;
|
|
8
|
-
constructor(sdk: any, dry?: boolean);
|
|
9
|
-
sync(target: any): Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
export declare type Changes = {
|
|
12
|
-
toAdd: string[];
|
|
13
|
-
toRemove: string[];
|
|
14
|
-
toUpdate: string[];
|
|
15
|
-
};
|
|
16
|
-
export declare function compareSchemaKey(localSchema: any, cloudSchema: any, key: string): {
|
|
17
|
-
toAdd: any[];
|
|
18
|
-
toRemove: any[];
|
|
19
|
-
toUpdate: any[];
|
|
20
|
-
};
|
|
1
|
+
export declare class SyncSchema {
|
|
2
|
+
#private;
|
|
3
|
+
private sdk;
|
|
4
|
+
private dry;
|
|
5
|
+
private cloudSchema;
|
|
6
|
+
private localSchema;
|
|
7
|
+
static createSchemaSync(sdk: any, dry?: boolean): SyncSchema;
|
|
8
|
+
constructor(sdk: any, dry?: boolean);
|
|
9
|
+
sync(target: any): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare type Changes = {
|
|
12
|
+
toAdd: string[];
|
|
13
|
+
toRemove: string[];
|
|
14
|
+
toUpdate: string[];
|
|
15
|
+
};
|
|
16
|
+
export declare function compareSchemaKey(localSchema: any, cloudSchema: any, key: string): {
|
|
17
|
+
toAdd: any[];
|
|
18
|
+
toRemove: any[];
|
|
19
|
+
toUpdate: any[];
|
|
20
|
+
};
|