@volcanicminds/backend 1.0.2 → 1.0.3
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/dist/lib/loader/schemas.js +43 -12
- package/dist/lib/loader/schemas.js.map +1 -1
- package/dist/package.json +1 -1
- package/lib/loader/schemas.ts +48 -11
- package/package.json +1 -1
|
@@ -5,28 +5,59 @@ const path_1 = require("../util/path");
|
|
|
5
5
|
const glob = require('glob');
|
|
6
6
|
const path = require('path');
|
|
7
7
|
function apply(server) {
|
|
8
|
-
const
|
|
8
|
+
const [baseSchemaPath, customSchemaPath] = (0, path_1.normalizePatterns)(['..', 'schemas', '*.{ts,js}'], ['src', 'schemas', '*.{ts,js}']);
|
|
9
|
+
const customSchemas = [];
|
|
10
|
+
const customSchemaIds = new Set();
|
|
9
11
|
let schemaCount = 0;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
log.t && log.trace('Looking for custom schemas in ' + customSchemaPath);
|
|
13
|
+
glob.sync(customSchemaPath).forEach((f) => {
|
|
14
|
+
try {
|
|
15
|
+
const schemaClass = require(f);
|
|
16
|
+
const schemaNames = Object.keys(schemaClass);
|
|
17
|
+
schemaNames.forEach((name) => {
|
|
18
|
+
const schema = schemaClass[name];
|
|
19
|
+
if (schema === null || schema === void 0 ? void 0 : schema.$id) {
|
|
20
|
+
customSchemas.push(schema);
|
|
21
|
+
customSchemaIds.add(schema.$id);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
log.w && log.warn(`Could not load custom schema file: ${f}`, e);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
customSchemas.forEach((schema) => {
|
|
30
|
+
log.trace(`* Registering custom schema [${schema.$id}]`);
|
|
31
|
+
server.addSchema(schema);
|
|
32
|
+
schemaCount++;
|
|
33
|
+
});
|
|
34
|
+
log.t && log.trace('Looking for base schemas in ' + baseSchemaPath);
|
|
35
|
+
glob.sync(baseSchemaPath).forEach((f) => {
|
|
36
|
+
try {
|
|
13
37
|
const schemaFileName = path.basename(f);
|
|
14
38
|
const schemaClass = require(f);
|
|
15
39
|
const schemaNames = Object.keys(schemaClass);
|
|
16
|
-
schemaNames.
|
|
40
|
+
schemaNames.forEach((name) => {
|
|
17
41
|
const schema = schemaClass[name];
|
|
18
|
-
if (schema
|
|
19
|
-
if (schema
|
|
20
|
-
log.
|
|
21
|
-
|
|
22
|
-
schemaCount++;
|
|
42
|
+
if (schema === null || schema === void 0 ? void 0 : schema.$id) {
|
|
43
|
+
if (customSchemaIds.has(schema.$id)) {
|
|
44
|
+
log.w &&
|
|
45
|
+
log.warn(`* Base schema [${schema.$id}] from ${schemaFileName} is overridden by a custom schema and will be ignored.`);
|
|
23
46
|
}
|
|
24
47
|
else {
|
|
25
|
-
log.
|
|
48
|
+
log.trace(`* Registering base schema [${schema.$id}] from ${schemaFileName}`);
|
|
49
|
+
server.addSchema(schema);
|
|
50
|
+
schemaCount++;
|
|
26
51
|
}
|
|
27
52
|
}
|
|
53
|
+
else {
|
|
54
|
+
log.w && log.warn(`* Schema with no $id found in ${schemaFileName}, cannot be registered.`);
|
|
55
|
+
}
|
|
28
56
|
});
|
|
29
|
-
}
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
log.w && log.warn(`Could not load base schema file: ${f}`, e);
|
|
60
|
+
}
|
|
30
61
|
});
|
|
31
62
|
log.d && log.debug(`Schemas loaded: ${schemaCount} referenceable by $ref`);
|
|
32
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../lib/loader/schemas.ts"],"names":[],"mappings":";;AAKA,
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../lib/loader/schemas.ts"],"names":[],"mappings":";;AAKA,sBAgEC;AArED,uCAAgD;AAEhD,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CA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,cAAc,yBAAyB,CAAC,CAAA;gBAC7F,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,oCAAoC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;QAC/D,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,mBAAmB,WAAW,wBAAwB,CAAC,CAAA;AAC5E,CAAC"}
|
package/dist/package.json
CHANGED
package/lib/loader/schemas.ts
CHANGED
|
@@ -4,29 +4,66 @@ const glob = require('glob')
|
|
|
4
4
|
const path = require('path')
|
|
5
5
|
|
|
6
6
|
export function apply(server: any): void {
|
|
7
|
-
const
|
|
7
|
+
const [baseSchemaPath, customSchemaPath] = normalizePatterns(
|
|
8
|
+
['..', 'schemas', '*.{ts,js}'],
|
|
9
|
+
['src', 'schemas', '*.{ts,js}']
|
|
10
|
+
)
|
|
8
11
|
|
|
12
|
+
const customSchemas: any[] = []
|
|
13
|
+
const customSchemaIds = new Set()
|
|
9
14
|
let schemaCount = 0
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
|
|
16
|
+
log.t && log.trace('Looking for custom schemas in ' + customSchemaPath)
|
|
17
|
+
glob.sync(customSchemaPath).forEach((f: string) => {
|
|
18
|
+
try {
|
|
19
|
+
const schemaClass = require(f)
|
|
20
|
+
const schemaNames = Object.keys(schemaClass)
|
|
21
|
+
|
|
22
|
+
schemaNames.forEach((name) => {
|
|
23
|
+
const schema = schemaClass[name]
|
|
24
|
+
if (schema?.$id) {
|
|
25
|
+
customSchemas.push(schema)
|
|
26
|
+
customSchemaIds.add(schema.$id)
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
} catch (e) {
|
|
30
|
+
log.w && log.warn(`Could not load custom schema file: ${f}`, e)
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
customSchemas.forEach((schema) => {
|
|
35
|
+
log.trace(`* Registering custom schema [${schema.$id}]`)
|
|
36
|
+
server.addSchema(schema)
|
|
37
|
+
schemaCount++
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
log.t && log.trace('Looking for base schemas in ' + baseSchemaPath)
|
|
41
|
+
glob.sync(baseSchemaPath).forEach((f: string) => {
|
|
42
|
+
try {
|
|
13
43
|
const schemaFileName = path.basename(f)
|
|
14
44
|
const schemaClass = require(f)
|
|
15
45
|
const schemaNames = Object.keys(schemaClass)
|
|
16
46
|
|
|
17
|
-
schemaNames.
|
|
47
|
+
schemaNames.forEach((name) => {
|
|
18
48
|
const schema = schemaClass[name]
|
|
19
|
-
if (schema
|
|
20
|
-
if (schema
|
|
21
|
-
log.
|
|
49
|
+
if (schema?.$id) {
|
|
50
|
+
if (customSchemaIds.has(schema.$id)) {
|
|
51
|
+
log.w &&
|
|
52
|
+
log.warn(
|
|
53
|
+
`* Base schema [${schema.$id}] from ${schemaFileName} is overridden by a custom schema and will be ignored.`
|
|
54
|
+
)
|
|
55
|
+
} else {
|
|
56
|
+
log.trace(`* Registering base schema [${schema.$id}] from ${schemaFileName}`)
|
|
22
57
|
server.addSchema(schema)
|
|
23
58
|
schemaCount++
|
|
24
|
-
} else {
|
|
25
|
-
log.warn(`* Schema [${schema.$id}] not loaded from ${schemaFileName}`)
|
|
26
59
|
}
|
|
60
|
+
} else {
|
|
61
|
+
log.w && log.warn(`* Schema with no $id found in ${schemaFileName}, cannot be registered.`)
|
|
27
62
|
}
|
|
28
63
|
})
|
|
29
|
-
})
|
|
64
|
+
} catch (e) {
|
|
65
|
+
log.w && log.warn(`Could not load base schema file: ${f}`, e)
|
|
66
|
+
}
|
|
30
67
|
})
|
|
31
68
|
|
|
32
69
|
log.d && log.debug(`Schemas loaded: ${schemaCount} referenceable by $ref`)
|