@extrahorizon/exh-cli 1.12.0-dev-143-312ba3f → 1.12.0-dev-144-b9d0b5a
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/build/commands/data/schemas/delete.js +2 -14
- package/build/commands/data/schemas/init.js +2 -30
- package/build/commands/data/schemas/list.js +2 -15
- package/build/commands/data/schemas/sync.d.ts +3 -5
- package/build/commands/data/schemas/sync.js +4 -40
- package/build/commands/data/schemas/verify.js +6 -51
- package/build/commands/sync.js +12 -11
- package/build/services/schemas/index.d.ts +5 -0
- package/build/services/schemas/index.js +43 -0
- package/build/services/schemas/init.d.ts +1 -0
- package/build/services/schemas/init.js +37 -0
- package/build/services/schemas/sync.d.ts +3 -0
- package/build/services/schemas/sync.js +44 -0
- package/build/{commands/data → services}/schemas/util/syncSchema.js +1 -1
- package/build/services/schemas/verify.d.ts +1 -0
- package/build/services/schemas/verify.js +56 -0
- package/package.json +1 -1
- /package/build/{commands/data → services}/schemas/sync/statusHelpers.d.ts +0 -0
- /package/build/{commands/data → services}/schemas/sync/statusHelpers.js +0 -0
- /package/build/{commands/data → services}/schemas/util/listFilesInDir.d.ts +0 -0
- /package/build/{commands/data → services}/schemas/util/listFilesInDir.js +0 -0
- /package/build/{commands/data → services}/schemas/util/readJson.d.ts +0 -0
- /package/build/{commands/data → services}/schemas/util/readJson.js +0 -0
- /package/build/{commands/data → services}/schemas/util/schemaverify.d.ts +0 -0
- /package/build/{commands/data → services}/schemas/util/schemaverify.js +0 -0
- /package/build/{commands/data → services}/schemas/util/stripUnsupportedDescriptionFields.d.ts +0 -0
- /package/build/{commands/data → services}/schemas/util/stripUnsupportedDescriptionFields.js +0 -0
- /package/build/{commands/data → services}/schemas/util/syncSchema.d.ts +0 -0
- /package/build/{commands/data → services}/schemas/util/tests/listFilesInDir.test.d.ts +0 -0
- /package/build/{commands/data → services}/schemas/util/tests/listFilesInDir.test.js +0 -0
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const chalk = require("chalk");
|
|
5
4
|
const util_1 = require("../../../helpers/util");
|
|
6
|
-
const
|
|
5
|
+
const schemaService = require("../../../services/schemas");
|
|
7
6
|
exports.command = 'delete';
|
|
8
7
|
exports.desc = 'Delete a schema';
|
|
9
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs).option('id', {
|
|
@@ -13,17 +12,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).option('id', {
|
|
|
13
12
|
});
|
|
14
13
|
exports.builder = builder;
|
|
15
14
|
const handler = async ({ id }) => {
|
|
16
|
-
|
|
17
|
-
if (disableResponse.affectedRecords !== 1) {
|
|
18
|
-
console.log(chalk.red('Failed to delete schema', id));
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const deleteResponse = await schemaRepository.remove(id);
|
|
22
|
-
if (deleteResponse.affectedRecords) {
|
|
23
|
-
console.log(chalk.green('Successfully deleted schema', id));
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
console.log(chalk.red('Failed to delete schema', id));
|
|
27
|
-
}
|
|
15
|
+
await schemaService.remove(id);
|
|
28
16
|
};
|
|
29
17
|
exports.handler = handler;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const promises_1 = require("fs/promises");
|
|
5
|
-
const osPath = require("path");
|
|
6
4
|
const util_1 = require("../../../helpers/util");
|
|
5
|
+
const schemaService = require("../../../services/schemas");
|
|
7
6
|
exports.command = 'init <name>';
|
|
8
7
|
exports.desc = 'Create a basic schema configuration file';
|
|
9
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
@@ -21,33 +20,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
|
21
20
|
});
|
|
22
21
|
exports.builder = builder;
|
|
23
22
|
const handler = async function init({ name, path }) {
|
|
24
|
-
await (
|
|
25
|
-
const filePath = osPath.join(path, `${name}.json`);
|
|
26
|
-
await (0, promises_1.writeFile)(filePath, JSON.stringify(createSchema(name), null, 2));
|
|
27
|
-
console.log(`✅ Successfully created ${filePath}`);
|
|
23
|
+
await schemaService.init(name, path);
|
|
28
24
|
};
|
|
29
25
|
exports.handler = handler;
|
|
30
|
-
function createSchema(name) {
|
|
31
|
-
return {
|
|
32
|
-
name,
|
|
33
|
-
description: `The ${name} schema`,
|
|
34
|
-
createMode: 'allUsers',
|
|
35
|
-
readMode: ['creator'],
|
|
36
|
-
updateMode: ['creator'],
|
|
37
|
-
deleteMode: ['creator'],
|
|
38
|
-
statuses: {
|
|
39
|
-
new: {},
|
|
40
|
-
},
|
|
41
|
-
creationTransition: {
|
|
42
|
-
type: 'manual',
|
|
43
|
-
toStatus: 'new',
|
|
44
|
-
},
|
|
45
|
-
transitions: [],
|
|
46
|
-
properties: {
|
|
47
|
-
firstProperty: {
|
|
48
|
-
type: 'string',
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
$schema: (0, util_1.getSwaggerDocumentationUrl)('config-json-schemas/Schema.json'),
|
|
52
|
-
};
|
|
53
|
-
}
|
|
@@ -2,25 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
4
|
const util_1 = require("../../../helpers/util");
|
|
5
|
-
const
|
|
5
|
+
const schemaService = require("../../../services/schemas");
|
|
6
6
|
exports.command = 'list';
|
|
7
7
|
exports.desc = 'List all schemas';
|
|
8
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs);
|
|
9
9
|
exports.builder = builder;
|
|
10
10
|
const handler = async function list({ isTTY }) {
|
|
11
|
-
|
|
12
|
-
if (schemas.length < 1) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (isTTY) {
|
|
16
|
-
console.table(schemas.map(schema => ({
|
|
17
|
-
Id: schema.id,
|
|
18
|
-
Name: schema.name,
|
|
19
|
-
Description: schema.description || '<none>',
|
|
20
|
-
})));
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
schemas.forEach(schema => console.log([schema.id, schema.name].join(',')));
|
|
24
|
-
}
|
|
11
|
+
await schemaService.list(isTTY);
|
|
25
12
|
};
|
|
26
13
|
exports.handler = handler;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="yargs" />
|
|
2
2
|
export declare const command = "sync";
|
|
3
3
|
export declare const desc = "Sync all schemas in a directory with the ExH cloud";
|
|
4
|
-
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "file" | "dir" | "
|
|
4
|
+
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "file" | "dir" | "dry" | "ignoreVerificationErrors"> & import("yargs").InferredOptionTypes<{
|
|
5
5
|
dir: {
|
|
6
6
|
demandOption: false;
|
|
7
7
|
describe: string;
|
|
@@ -24,11 +24,9 @@ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs
|
|
|
24
24
|
default: boolean;
|
|
25
25
|
};
|
|
26
26
|
}>>;
|
|
27
|
-
export declare const handler: ({
|
|
28
|
-
dir: any;
|
|
27
|
+
export declare const handler: ({ file, dir, dry, ignoreVerificationErrors }: {
|
|
29
28
|
file: any;
|
|
29
|
+
dir: any;
|
|
30
30
|
dry: any;
|
|
31
31
|
ignoreVerificationErrors: any;
|
|
32
32
|
}) => Promise<void>;
|
|
33
|
-
export declare function syncTargetFile(targetFile: string, dry?: boolean, ignoreVerificationErrors?: boolean): Promise<void>;
|
|
34
|
-
export declare function syncTargetDir(targetDir: string, dry?: boolean, ignoreVerificationErrors?: boolean): Promise<void>;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const chalk = require("chalk");
|
|
3
|
+
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
6
4
|
const util_1 = require("../../../helpers/util");
|
|
7
|
-
const
|
|
8
|
-
const readJson_1 = require("./util/readJson");
|
|
9
|
-
const syncSchema_1 = require("./util/syncSchema");
|
|
10
|
-
const verify_1 = require("./verify");
|
|
5
|
+
const schemaService = require("../../../services/schemas");
|
|
11
6
|
exports.command = 'sync';
|
|
12
7
|
exports.desc = 'Sync all schemas in a directory with the ExH cloud';
|
|
13
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
@@ -34,38 +29,7 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
34
29
|
},
|
|
35
30
|
});
|
|
36
31
|
exports.builder = builder;
|
|
37
|
-
const handler = async ({
|
|
38
|
-
|
|
39
|
-
console.log(chalk.red('No target is chosen to be synced. Please use flags "--file" or "--dir" when syncing'));
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
if (dir) {
|
|
43
|
-
await syncTargetDir(path.resolve(dir || '.'), dry, ignoreVerificationErrors);
|
|
44
|
-
}
|
|
45
|
-
if (file) {
|
|
46
|
-
await syncTargetFile(path.resolve(file), dry, ignoreVerificationErrors);
|
|
47
|
-
}
|
|
32
|
+
const handler = async ({ file, dir, dry, ignoreVerificationErrors }) => {
|
|
33
|
+
await schemaService.sync(file, dir, dry, ignoreVerificationErrors);
|
|
48
34
|
};
|
|
49
35
|
exports.handler = handler;
|
|
50
|
-
async function syncTargetFile(targetFile, dry, ignoreVerificationErrors) {
|
|
51
|
-
await (0, verify_1.handler)({ dir: null, file: targetFile, ignoreVerificationErrors });
|
|
52
|
-
const filePath = path.resolve(targetFile);
|
|
53
|
-
if (!filePath.endsWith('.json')) {
|
|
54
|
-
console.log(`Ignored ${path.basename(filePath)}, not a JSON file (needs .json extension)`);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
console.log(chalk.bold(`Synchronizing ${path.basename(filePath)}`));
|
|
58
|
-
const targetSchema = await (0, readJson_1.readJsonFile)(filePath);
|
|
59
|
-
const syncSchema = syncSchema_1.SyncSchema.createSchemaSync(dry);
|
|
60
|
-
await syncSchema.sync(targetSchema);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.syncTargetFile = syncTargetFile;
|
|
64
|
-
async function syncTargetDir(targetDir, dry, ignoreVerificationErrors) {
|
|
65
|
-
const targetFiles = (0, listFilesInDir_1.flatListFiles)(targetDir, '.json');
|
|
66
|
-
for (const filePath of targetFiles) {
|
|
67
|
-
await syncTargetFile(filePath, dry, ignoreVerificationErrors);
|
|
68
|
-
process.stdout.write('\n');
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.syncTargetDir = syncTargetDir;
|
|
@@ -3,16 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
|
-
const ajv_1 = require("ajv");
|
|
7
|
-
const chalk = require("chalk");
|
|
8
|
-
const metaschema = require("../../../config-json-schemas/Schema.json");
|
|
9
|
-
const error_1 = require("../../../helpers/error");
|
|
10
6
|
const util_1 = require("../../../helpers/util");
|
|
11
|
-
const
|
|
12
|
-
const schemaverify_1 = require("./util/schemaverify");
|
|
7
|
+
const schemaService = require("../../../services/schemas");
|
|
13
8
|
exports.command = 'verify';
|
|
14
9
|
exports.desc = 'Syntactically verify a local schema';
|
|
15
|
-
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
10
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
11
|
+
.options({
|
|
16
12
|
file: {
|
|
17
13
|
describe: 'schema json file which needs to be verified',
|
|
18
14
|
type: 'string',
|
|
@@ -21,7 +17,8 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
21
17
|
describe: 'directory containing schemas to be verified',
|
|
22
18
|
type: 'string',
|
|
23
19
|
},
|
|
24
|
-
})
|
|
20
|
+
})
|
|
21
|
+
.check(({ file, dir }) => {
|
|
25
22
|
if (file && (!fs.existsSync(path.resolve(file)) || !fs.lstatSync(path.resolve(file)).isFile())) {
|
|
26
23
|
throw new Error('Schema file does not exist, please make sure you provided the correct file path');
|
|
27
24
|
}
|
|
@@ -35,48 +32,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
35
32
|
});
|
|
36
33
|
exports.builder = builder;
|
|
37
34
|
const handler = async ({ file, dir, ignoreVerificationErrors }) => {
|
|
38
|
-
|
|
39
|
-
if (dir) {
|
|
40
|
-
files = await (0, listFilesInDir_1.flatListFiles)(dir, '.json');
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
files = [file];
|
|
44
|
-
}
|
|
45
|
-
const checkFile = (schemaPath) => {
|
|
46
|
-
let schema = {};
|
|
47
|
-
console.log(chalk.bold('Checking', schemaPath));
|
|
48
|
-
try {
|
|
49
|
-
schema = require(path.resolve(schemaPath));
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
console.log(chalk.red(`Failed to load schema file ${file}. Possibly not a valid JSON file`));
|
|
53
|
-
console.log(err);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const ajv = new ajv_1.default();
|
|
57
|
-
for (const result of (new schemaverify_1.SchemaVerify(ajv, schema, metaschema)).RunChecks()) {
|
|
58
|
-
if (result.ok) {
|
|
59
|
-
console.log(chalk.green(`${result.test}... ✓`));
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
console.log(chalk.red(`${result.test}... x`));
|
|
63
|
-
for (const error of result.errors) {
|
|
64
|
-
if (typeof error === 'object') {
|
|
65
|
-
console.log('\t', chalk.red(JSON.stringify(error, null, 4)));
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
console.log('\t', chalk.red(error));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (!ignoreVerificationErrors) {
|
|
72
|
-
throw new error_1.CommandError(`Schema ${schemaPath} contains error, please fix`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
console.log();
|
|
77
|
-
};
|
|
78
|
-
for (const f of files) {
|
|
79
|
-
checkFile(f);
|
|
80
|
-
}
|
|
35
|
+
await schemaService.verify(file, dir, ignoreVerificationErrors);
|
|
81
36
|
};
|
|
82
37
|
exports.handler = handler;
|
package/build/commands/sync.js
CHANGED
|
@@ -7,11 +7,11 @@ const ospath = require("path");
|
|
|
7
7
|
const chalk = require("chalk");
|
|
8
8
|
const repoConfig_1 = require("../helpers/repoConfig");
|
|
9
9
|
const util_1 = require("../helpers/util");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
10
|
+
const dispatcherService = require("../services/dispatchers");
|
|
11
|
+
const localizationService = require("../services/localizations");
|
|
12
|
+
const schemaService = require("../services/schemas");
|
|
13
|
+
const taskService = require("../services/tasks");
|
|
14
|
+
const templateService = require("../services/templates");
|
|
15
15
|
exports.command = 'sync';
|
|
16
16
|
exports.desc = 'Sync your ExH configuration to the cloud environment';
|
|
17
17
|
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
@@ -63,7 +63,8 @@ If not, the local directory is assumed with a default configuration which assume
|
|
|
63
63
|
type: 'boolean',
|
|
64
64
|
default: false,
|
|
65
65
|
},
|
|
66
|
-
})
|
|
66
|
+
})
|
|
67
|
+
.check(async ({ path }) => {
|
|
67
68
|
if (path !== undefined) {
|
|
68
69
|
try {
|
|
69
70
|
await fs.access(ospath.join(process.cwd(), path, repoConfig_1.REPO_CONFIG_FILE));
|
|
@@ -85,25 +86,25 @@ const handler = async ({ path, schemas, tasks, templates, dispatchers, cleanDisp
|
|
|
85
86
|
if ((syncAll || schemas) && cfg.schemas) {
|
|
86
87
|
console.log(chalk.green('\n ⚙️ Syncing schemas ...'));
|
|
87
88
|
for (const schema of cfg.schemas) {
|
|
88
|
-
await
|
|
89
|
+
await schemaService.sync(ospath.join(targetPath, schema), undefined, false, ignoreSchemaVerificationErrors);
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
if ((syncAll || templates) && cfg.templates) {
|
|
92
93
|
console.log(chalk.green('\n ⚙️ Syncing templates...'));
|
|
93
94
|
for (const template of cfg.templates) {
|
|
94
|
-
await
|
|
95
|
+
await templateService.sync(ospath.join(targetPath, template));
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
if ((syncAll || tasks) && cfg.tasks) {
|
|
98
99
|
console.log(chalk.green('\n ⚙️ Syncing tasks...'));
|
|
99
100
|
for (const task of cfg.tasks) {
|
|
100
|
-
await
|
|
101
|
+
await taskService.sync({ path: ospath.join(targetPath, task) });
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
if ((syncAll || localizations) && cfg.localizations) {
|
|
104
105
|
console.log(chalk.green('\n ⚙️ Syncing localizations...'));
|
|
105
106
|
for (const localization of cfg.localizations) {
|
|
106
|
-
await
|
|
107
|
+
await localizationService.sync(ospath.join(targetPath, localization));
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
if ((syncAll || dispatchers)) {
|
|
@@ -111,7 +112,7 @@ const handler = async ({ path, schemas, tasks, templates, dispatchers, cleanDisp
|
|
|
111
112
|
const isValidPath = (0, fs_1.existsSync)(dispatchersPath);
|
|
112
113
|
if (isValidPath) {
|
|
113
114
|
console.log(chalk.green('\n ⚙️ Syncing dispatchers...'));
|
|
114
|
-
await
|
|
115
|
+
await dispatcherService.sync(dispatchersPath, cleanDispatchers);
|
|
115
116
|
}
|
|
116
117
|
else if (dispatchers) {
|
|
117
118
|
console.log(chalk.yellow('Warning: dispatchers.json not found'));
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.remove = exports.list = exports.sync = exports.verify = exports.init = void 0;
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const schemaRepository = require("../../repositories/schemas");
|
|
6
|
+
var init_1 = require("./init");
|
|
7
|
+
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return init_1.init; } });
|
|
8
|
+
var verify_1 = require("./verify");
|
|
9
|
+
Object.defineProperty(exports, "verify", { enumerable: true, get: function () { return verify_1.verify; } });
|
|
10
|
+
var sync_1 = require("./sync");
|
|
11
|
+
Object.defineProperty(exports, "sync", { enumerable: true, get: function () { return sync_1.sync; } });
|
|
12
|
+
async function list(isTTY) {
|
|
13
|
+
const schemas = await schemaRepository.fetchAll();
|
|
14
|
+
if (schemas.length < 1) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (isTTY) {
|
|
18
|
+
console.table(schemas.map(schema => ({
|
|
19
|
+
Id: schema.id,
|
|
20
|
+
Name: schema.name,
|
|
21
|
+
Description: schema.description || '<none>',
|
|
22
|
+
})));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
schemas.forEach(schema => console.log([schema.id, schema.name].join(',')));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.list = list;
|
|
29
|
+
async function remove(id) {
|
|
30
|
+
const disableResponse = await schemaRepository.disable(id);
|
|
31
|
+
if (disableResponse.affectedRecords !== 1) {
|
|
32
|
+
console.log(chalk.red('Failed to delete schema', id));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const deleteResponse = await schemaRepository.remove(id);
|
|
36
|
+
if (deleteResponse.affectedRecords) {
|
|
37
|
+
console.log(chalk.green('Successfully deleted schema', id));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.log(chalk.red('Failed to delete schema', id));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.remove = remove;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(name: string, path: string): Promise<void>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const osPath = require("path");
|
|
6
|
+
const util_1 = require("../../helpers/util");
|
|
7
|
+
async function init(name, path) {
|
|
8
|
+
await (0, promises_1.mkdir)(path, { recursive: true });
|
|
9
|
+
const filePath = osPath.join(path, `${name}.json`);
|
|
10
|
+
await (0, promises_1.writeFile)(filePath, JSON.stringify(createSchema(name), null, 2));
|
|
11
|
+
console.log(`✅ Successfully created ${filePath}`);
|
|
12
|
+
}
|
|
13
|
+
exports.init = init;
|
|
14
|
+
function createSchema(name) {
|
|
15
|
+
return {
|
|
16
|
+
name,
|
|
17
|
+
description: `The ${name} schema`,
|
|
18
|
+
createMode: 'allUsers',
|
|
19
|
+
readMode: ['creator'],
|
|
20
|
+
updateMode: ['creator'],
|
|
21
|
+
deleteMode: ['creator'],
|
|
22
|
+
statuses: {
|
|
23
|
+
new: {},
|
|
24
|
+
},
|
|
25
|
+
creationTransition: {
|
|
26
|
+
type: 'manual',
|
|
27
|
+
toStatus: 'new',
|
|
28
|
+
},
|
|
29
|
+
transitions: [],
|
|
30
|
+
properties: {
|
|
31
|
+
firstProperty: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
$schema: (0, util_1.getSwaggerDocumentationUrl)('config-json-schemas/Schema.json'),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function sync(file?: string, dir?: string, dry?: boolean, ignoreVerificationErrors?: boolean): Promise<void>;
|
|
2
|
+
export declare function syncTargetFile(targetFile: string, dry?: boolean, ignoreVerificationErrors?: boolean): Promise<void>;
|
|
3
|
+
export declare function syncTargetDir(targetDir: string, dry?: boolean, ignoreVerificationErrors?: boolean): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.syncTargetDir = exports.syncTargetFile = exports.sync = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const listFilesInDir_1 = require("./util/listFilesInDir");
|
|
7
|
+
const readJson_1 = require("./util/readJson");
|
|
8
|
+
const syncSchema_1 = require("./util/syncSchema");
|
|
9
|
+
const verify_1 = require("./verify");
|
|
10
|
+
async function sync(file, dir, dry, ignoreVerificationErrors) {
|
|
11
|
+
if (!file && !dir) {
|
|
12
|
+
console.log(chalk.red('No target is chosen to be synced. Please use flags "--file" or "--dir" when syncing'));
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
if (dir) {
|
|
16
|
+
await syncTargetDir(path.resolve(dir || '.'), dry, ignoreVerificationErrors);
|
|
17
|
+
}
|
|
18
|
+
if (file) {
|
|
19
|
+
await syncTargetFile(path.resolve(file), dry, ignoreVerificationErrors);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.sync = sync;
|
|
23
|
+
async function syncTargetFile(targetFile, dry, ignoreVerificationErrors) {
|
|
24
|
+
await (0, verify_1.verify)(targetFile, null, ignoreVerificationErrors);
|
|
25
|
+
const filePath = path.resolve(targetFile);
|
|
26
|
+
if (!filePath.endsWith('.json')) {
|
|
27
|
+
console.log(`Ignored ${path.basename(filePath)}, not a JSON file (needs .json extension)`);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
console.log(chalk.bold(`Synchronizing ${path.basename(filePath)}`));
|
|
31
|
+
const targetSchema = await (0, readJson_1.readJsonFile)(filePath);
|
|
32
|
+
const syncSchema = syncSchema_1.SyncSchema.createSchemaSync(dry);
|
|
33
|
+
await syncSchema.sync(targetSchema);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.syncTargetFile = syncTargetFile;
|
|
37
|
+
async function syncTargetDir(targetDir, dry, ignoreVerificationErrors) {
|
|
38
|
+
const targetFiles = (0, listFilesInDir_1.flatListFiles)(targetDir, '.json');
|
|
39
|
+
for (const filePath of targetFiles) {
|
|
40
|
+
await syncTargetFile(filePath, dry, ignoreVerificationErrors);
|
|
41
|
+
process.stdout.write('\n');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.syncTargetDir = syncTargetDir;
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.compareSchemaKey = exports.SyncSchema = void 0;
|
|
10
10
|
const chalk = require("chalk");
|
|
11
11
|
const _ = require("lodash");
|
|
12
|
-
const schemaRepository = require("
|
|
12
|
+
const schemaRepository = require("../../../repositories/schemas");
|
|
13
13
|
const statusHelpers_1 = require("../sync/statusHelpers");
|
|
14
14
|
const stripUnsupportedDescriptionFields_1 = require("./stripUnsupportedDescriptionFields");
|
|
15
15
|
class SyncSchema {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function verify(file?: string, dir?: string, ignoreVerificationErrors?: boolean): Promise<void>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verify = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const ajv_1 = require("ajv");
|
|
6
|
+
const chalk = require("chalk");
|
|
7
|
+
const metaschema = require("../../config-json-schemas/Schema.json");
|
|
8
|
+
const error_1 = require("../../helpers/error");
|
|
9
|
+
const listFilesInDir_1 = require("./util/listFilesInDir");
|
|
10
|
+
const schemaverify_1 = require("./util/schemaverify");
|
|
11
|
+
async function verify(file, dir, ignoreVerificationErrors) {
|
|
12
|
+
let files = [];
|
|
13
|
+
if (dir) {
|
|
14
|
+
files = await (0, listFilesInDir_1.flatListFiles)(dir, '.json');
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
files = [file];
|
|
18
|
+
}
|
|
19
|
+
const checkFile = (schemaPath) => {
|
|
20
|
+
let schema = {};
|
|
21
|
+
console.log(chalk.bold('Checking', schemaPath));
|
|
22
|
+
try {
|
|
23
|
+
schema = require(path.resolve(schemaPath));
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
console.log(chalk.red(`Failed to load schema file ${file}. Possibly not a valid JSON file`));
|
|
27
|
+
console.log(err);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const ajv = new ajv_1.default();
|
|
31
|
+
for (const result of (new schemaverify_1.SchemaVerify(ajv, schema, metaschema)).RunChecks()) {
|
|
32
|
+
if (result.ok) {
|
|
33
|
+
console.log(chalk.green(`${result.test}... ✓`));
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
console.log(chalk.red(`${result.test}... x`));
|
|
37
|
+
for (const error of result.errors) {
|
|
38
|
+
if (typeof error === 'object') {
|
|
39
|
+
console.log('\t', chalk.red(JSON.stringify(error, null, 4)));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.log('\t', chalk.red(error));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!ignoreVerificationErrors) {
|
|
46
|
+
throw new error_1.CommandError(`Schema ${schemaPath} contains error, please fix`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
console.log();
|
|
51
|
+
};
|
|
52
|
+
for (const f of files) {
|
|
53
|
+
checkFile(f);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.verify = verify;
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/build/{commands/data → services}/schemas/util/stripUnsupportedDescriptionFields.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|