@kravc/schema 2.8.1 → 2.8.2
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/.claude/settings.local.json +7 -0
- package/dist/helpers/createSchemasMap.d.ts.map +1 -1
- package/dist/helpers/createSchemasMap.js +2 -0
- package/dist/helpers/createSchemasMap.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/__tests__/createSchemasMap.test.ts +7 -0
- package/src/helpers/createSchemasMap.ts +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSchemasMap.d.ts","sourceRoot":"","sources":["../../src/helpers/createSchemasMap.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,WAAW,CAAC;AAK/B,wEAAwE;AACxE,eAAO,MAAM,QAAQ,GAAI,UAAU,MAAM,WAUxC,CAAC;AAoBF,qGAAqG;AACrG,QAAA,MAAM,gBAAgB,GAAI,aAAa,MAAM,EAAE,SAAS,OAAO,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"createSchemasMap.d.ts","sourceRoot":"","sources":["../../src/helpers/createSchemasMap.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,WAAW,CAAC;AAK/B,wEAAwE;AACxE,eAAO,MAAM,QAAQ,GAAI,UAAU,MAAM,WAUxC,CAAC;AAoBF,qGAAqG;AACrG,QAAA,MAAM,gBAAgB,GAAI,aAAa,MAAM,EAAE,SAAS,OAAO,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAcxF,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -31,6 +31,8 @@ const readSchemasSync = (servicePath) => listFilesSync(servicePath)
|
|
|
31
31
|
.map((schemaPath) => (0, exports.loadSync)(schemaPath));
|
|
32
32
|
/** Creates a map of schemas by ID, loading from YAML files and merging with programmatic schemas. */
|
|
33
33
|
const createSchemasMap = (servicePath, modules) => {
|
|
34
|
+
if (!(0, fs_1.existsSync)(servicePath))
|
|
35
|
+
return {};
|
|
34
36
|
const yamlSchemas = readSchemasSync(servicePath);
|
|
35
37
|
const schemasMap = (0, lodash_1.keyBy)(yamlSchemas, 'id');
|
|
36
38
|
const schemas = modules
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSchemasMap.js","sourceRoot":"","sources":["../../src/helpers/createSchemasMap.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,uDAA+B;AAC/B,qCAA+B;AAC/B,mCAA+B;AAC/B,
|
|
1
|
+
{"version":3,"file":"createSchemasMap.js","sourceRoot":"","sources":["../../src/helpers/createSchemasMap.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,uDAA+B;AAC/B,qCAA+B;AAC/B,mCAA+B;AAC/B,2BAAqE;AAErE,wEAAwE;AACjE,MAAM,QAAQ,GAAG,CAAC,QAAgB,EAAE,EAAE;IAC3C,MAAM,QAAQ,GAAG,QAAQ;SACtB,KAAK,CAAC,GAAG,CAAC;SACV,OAAO,EAAE,CAAC,CAAC,CAAC;SACZ,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAErB,MAAM,IAAI,GAAG,IAAA,iBAAY,EAAC,QAAQ,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,IAAA,cAAI,EAAC,IAAI,CAAC,QAAQ,EAAE,CAAkC,CAAC;IAEtE,OAAO,IAAI,gBAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC,CAAC;AAVW,QAAA,QAAQ,YAUnB;AAEF,yEAAyE;AACzE,MAAM,aAAa,GAAG,CAAC,WAAmB,EAAY,EAAE,CACtD,IAAA,gBAAW,EAAC,WAAW,CAAC;KACrB,MAAM,CACL,CAAC,SAAmB,EAAE,QAAgB,EAAE,EAAE,CACxC,IAAA,aAAQ,EACN,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,WAAW,E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return empty map if servicePath does not exist', () => {
|
|
154
|
+
const nonExistentPath = path.join(__dirname, '../../../non-existent-src');
|
|
155
|
+
const schemasMap = createSchemasMap(nonExistentPath, []);
|
|
156
|
+
|
|
157
|
+
expect(schemasMap).toEqual({});
|
|
158
|
+
});
|
|
159
|
+
|
|
153
160
|
it('should handle empty directory gracefully', () => {
|
|
154
161
|
const emptyDir = path.join(__dirname, '../../../examples');
|
|
155
162
|
// This directory might have subdirectories but no YAML files directly
|
|
@@ -2,7 +2,7 @@ import path from 'path';
|
|
|
2
2
|
import Schema from '../Schema';
|
|
3
3
|
import { load } from 'js-yaml';
|
|
4
4
|
import { keyBy } from 'lodash';
|
|
5
|
-
import { readFileSync, readdirSync, statSync } from 'fs';
|
|
5
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'fs';
|
|
6
6
|
|
|
7
7
|
/** Reads schema source from YAML file and returns a Schema instance. */
|
|
8
8
|
export const loadSync = (yamlPath: string) => {
|
|
@@ -37,6 +37,8 @@ const readSchemasSync = (servicePath: string) =>
|
|
|
37
37
|
|
|
38
38
|
/** Creates a map of schemas by ID, loading from YAML files and merging with programmatic schemas. */
|
|
39
39
|
const createSchemasMap = (servicePath: string, modules: unknown[]): Record<string, Schema> => {
|
|
40
|
+
if (!existsSync(servicePath)) return {};
|
|
41
|
+
|
|
40
42
|
const yamlSchemas = readSchemasSync(servicePath);
|
|
41
43
|
const schemasMap = keyBy(yamlSchemas, 'id');
|
|
42
44
|
|