@kravc/schema 2.8.0-alpha.1 → 2.8.0-alpha.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/dist/helpers/createSchemasMap.d.ts +31 -0
- package/dist/helpers/createSchemasMap.d.ts.map +1 -1
- package/dist/helpers/createSchemasMap.js +3 -1
- package/dist/helpers/createSchemasMap.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +37 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/createSchemasMap.ts +1 -1
- package/src/index.ts +2 -1
|
@@ -1,4 +1,35 @@
|
|
|
1
1
|
import Schema from '../Schema';
|
|
2
|
+
/**
|
|
3
|
+
* Reads schema source from YAML file and returns a Schema instance.
|
|
4
|
+
*
|
|
5
|
+
* **Intent:** Load and parse a single YAML schema file, extracting the schema ID
|
|
6
|
+
* from the filename and creating a Schema instance for use in validation or
|
|
7
|
+
* schema composition.
|
|
8
|
+
*
|
|
9
|
+
* **Use Cases:**
|
|
10
|
+
* - Load individual schema files during application startup
|
|
11
|
+
* - Parse YAML schema definitions into Schema instances
|
|
12
|
+
* - Extract schema identifiers from file paths automatically
|
|
13
|
+
* - Support both enum and properties-based schemas from YAML files
|
|
14
|
+
*
|
|
15
|
+
* @param yamlPath - Absolute or relative path to the YAML schema file
|
|
16
|
+
* @returns A Schema instance with ID extracted from the filename (without .yaml extension)
|
|
17
|
+
*
|
|
18
|
+
* **Example:**
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const schema = loadSync('/path/to/schemas/User.yaml');
|
|
21
|
+
* // schema.id === 'User'
|
|
22
|
+
* // schema.source contains the parsed YAML content
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* **Example - Enum Schema:**
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const statusSchema = loadSync('/path/to/schemas/Status.yaml');
|
|
28
|
+
* // If Status.yaml contains: { enum: ['PENDING', 'ACTIVE'] }
|
|
29
|
+
* // statusSchema.isEnum === true
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const loadSync: (yamlPath: string) => Schema;
|
|
2
33
|
/**
|
|
3
34
|
* Creates a map of schemas by ID, loading from YAML files and merging with programmatic schemas.
|
|
4
35
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSchemasMap.d.ts","sourceRoot":"","sources":["../../src/helpers/createSchemasMap.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"createSchemasMap.d.ts","sourceRoot":"","sources":["../../src/helpers/createSchemasMap.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,WAAW,CAAC;AAM/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,QAAQ,GAAI,UAAU,MAAM,WAUxC,CAAC;AAuFF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,QAAA,MAAM,gBAAgB,GAAI,aAAa,MAAM,EAAE,SAAS,OAAO,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAYxF,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadSync = void 0;
|
|
6
7
|
const path_1 = __importDefault(require("path"));
|
|
7
8
|
const Schema_1 = __importDefault(require("../Schema"));
|
|
8
9
|
const js_yaml_1 = require("js-yaml");
|
|
@@ -47,6 +48,7 @@ const loadSync = (yamlPath) => {
|
|
|
47
48
|
const source = (0, js_yaml_1.load)(file.toString());
|
|
48
49
|
return new Schema_1.default(source, schemaId);
|
|
49
50
|
};
|
|
51
|
+
exports.loadSync = loadSync;
|
|
50
52
|
/**
|
|
51
53
|
* Recursively lists all files in a directory and its subdirectories.
|
|
52
54
|
*
|
|
@@ -122,7 +124,7 @@ const listFilesSync = (servicePath) => (0, fs_1.readdirSync)(servicePath)
|
|
|
122
124
|
*/
|
|
123
125
|
const readSchemasSync = (servicePath) => listFilesSync(servicePath)
|
|
124
126
|
.filter((fileName) => fileName.endsWith('.yaml'))
|
|
125
|
-
.map((schemaPath) => loadSync(schemaPath));
|
|
127
|
+
.map((schemaPath) => (0, exports.loadSync)(schemaPath));
|
|
126
128
|
/**
|
|
127
129
|
* Creates a map of schemas by ID, loading from YAML files and merging with programmatic schemas.
|
|
128
130
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSchemasMap.js","sourceRoot":"","sources":["../../src/helpers/createSchemasMap.ts"],"names":[],"mappings":"
|
|
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;AAE/B,2BAAyD;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACI,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,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,CAAC;IAE9C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;IACjC,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,kBAAe,gBAAgB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import Schema from './Schema';
|
|
|
3
3
|
import Validator from './Validator';
|
|
4
4
|
import documentLoader from './ld/documentLoader';
|
|
5
5
|
import ValidationError from './ValidationError';
|
|
6
|
-
import createSchemasMap from './helpers/createSchemasMap';
|
|
7
6
|
import CredentialFactory from './CredentialFactory';
|
|
8
|
-
|
|
7
|
+
import createSchemasMap, { loadSync } from './helpers/createSchemasMap';
|
|
8
|
+
export { got, Schema, loadSync, Validator, documentLoader, ValidationError, createSchemasMap, CredentialFactory };
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,eAAe,CAAC;AAChC,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,eAAe,CAAC;AAChC,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,gBAAgB,EAAE,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,EACL,GAAG,EACH,MAAM,EACN,QAAQ,EACR,SAAS,EACT,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EAClB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CredentialFactory = exports.createSchemasMap = exports.ValidationError = exports.documentLoader = exports.Validator = exports.Schema = exports.got = void 0;
|
|
39
|
+
exports.CredentialFactory = exports.createSchemasMap = exports.ValidationError = exports.documentLoader = exports.Validator = exports.loadSync = exports.Schema = exports.got = void 0;
|
|
7
40
|
const got_1 = __importDefault(require("./helpers/got"));
|
|
8
41
|
exports.got = got_1.default;
|
|
9
42
|
const Schema_1 = __importDefault(require("./Schema"));
|
|
@@ -14,8 +47,9 @@ const documentLoader_1 = __importDefault(require("./ld/documentLoader"));
|
|
|
14
47
|
exports.documentLoader = documentLoader_1.default;
|
|
15
48
|
const ValidationError_1 = __importDefault(require("./ValidationError"));
|
|
16
49
|
exports.ValidationError = ValidationError_1.default;
|
|
17
|
-
const createSchemasMap_1 = __importDefault(require("./helpers/createSchemasMap"));
|
|
18
|
-
exports.createSchemasMap = createSchemasMap_1.default;
|
|
19
50
|
const CredentialFactory_1 = __importDefault(require("./CredentialFactory"));
|
|
20
51
|
exports.CredentialFactory = CredentialFactory_1.default;
|
|
52
|
+
const createSchemasMap_1 = __importStar(require("./helpers/createSchemasMap"));
|
|
53
|
+
exports.createSchemasMap = createSchemasMap_1.default;
|
|
54
|
+
Object.defineProperty(exports, "loadSync", { enumerable: true, get: function () { return createSchemasMap_1.loadSync; } });
|
|
21
55
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAgC;AAS9B,cATK,aAAG,CASL;AARL,sDAA8B;AAS5B,iBATK,gBAAM,CASL;AARR,4DAAoC;AAUlC,oBAVK,mBAAS,CAUL;AATX,yEAAiD;AAU/C,yBAVK,wBAAc,CAUL;AAThB,wEAAgD;AAU9C,0BAVK,yBAAe,CAUL;AATjB,4EAAoD;AAWlD,4BAXK,2BAAiB,CAWL;AAVnB,+EAAwE;AAStE,2BATK,0BAAgB,CASL;AAJhB,yFALyB,2BAAQ,OAKzB"}
|
package/package.json
CHANGED
|
@@ -35,7 +35,7 @@ import { readFileSync, readdirSync, statSync } from 'fs';
|
|
|
35
35
|
* // statusSchema.isEnum === true
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
const loadSync = (yamlPath: string) => {
|
|
38
|
+
export const loadSync = (yamlPath: string) => {
|
|
39
39
|
const schemaId = yamlPath
|
|
40
40
|
.split('/')
|
|
41
41
|
.reverse()[0]
|
package/src/index.ts
CHANGED
|
@@ -3,12 +3,13 @@ import Schema from './Schema';
|
|
|
3
3
|
import Validator from './Validator';
|
|
4
4
|
import documentLoader from './ld/documentLoader';
|
|
5
5
|
import ValidationError from './ValidationError';
|
|
6
|
-
import createSchemasMap from './helpers/createSchemasMap';
|
|
7
6
|
import CredentialFactory from './CredentialFactory';
|
|
7
|
+
import createSchemasMap, { loadSync } from './helpers/createSchemasMap';
|
|
8
8
|
|
|
9
9
|
export {
|
|
10
10
|
got,
|
|
11
11
|
Schema,
|
|
12
|
+
loadSync,
|
|
12
13
|
Validator,
|
|
13
14
|
documentLoader,
|
|
14
15
|
ValidationError,
|