@northern/yaml-loader 1.0.3 → 1.0.5
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/README.md +2 -4
- package/lib/{index.d.ts → cjs/index.d.ts} +1 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/{index.js → cjs/index.js} +7 -1
- package/lib/{yaml-loader.d.ts → esm/index.d.ts} +1 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/{yaml-loader.js → esm/index.js} +25 -28
- package/package.json +24 -4
package/README.md
CHANGED
|
@@ -40,14 +40,12 @@ The YAML loader module provides:
|
|
|
40
40
|
- **Debugging**: Comprehensive debug information and error reporting
|
|
41
41
|
- **Extensibility**: Custom resolver plugin system
|
|
42
42
|
|
|
43
|
-
##
|
|
43
|
+
## Basic Usage
|
|
44
44
|
|
|
45
45
|
```typescript
|
|
46
|
-
import
|
|
46
|
+
import loadYaml from '@northern/yaml-loader';
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
## Basic Usage
|
|
50
|
-
|
|
51
49
|
### Simple YAML Loading
|
|
52
50
|
|
|
53
51
|
```typescript
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,EAAE,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;CACrF;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,GAAG,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC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AO,CAAyB;IAExC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK7B,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAKtC,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAK1C,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,GAAG,IAAI;IAQxE,KAAK,IAAI,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG;IAIlC,YAAY,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,QAAQ,EAAE,MAAM,KAAK,CAAC;CAGjD;AAMD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB;;;eAUpE,MAAM;;EAGpB;AAGD,eAAe,QAAQ,CAAC"}
|
|
@@ -168,7 +168,13 @@ const createResolutionContext = (options = {}) => {
|
|
|
168
168
|
pathChain: [],
|
|
169
169
|
pathSet: new Set(),
|
|
170
170
|
fileCache: new LRUFileCache(options.maxCacheSize || 100),
|
|
171
|
-
options:
|
|
171
|
+
options: {
|
|
172
|
+
maxCacheSize: 100,
|
|
173
|
+
allowExternalAccess: false,
|
|
174
|
+
strictMode: false,
|
|
175
|
+
customResolvers: new Map(),
|
|
176
|
+
...options,
|
|
177
|
+
},
|
|
172
178
|
startTime: Date.now(),
|
|
173
179
|
};
|
|
174
180
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,EAAE,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;CACrF;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ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AC,KAAK,EAAE,SAAS,CAAA;CAAE,CA2BzH;AAQD,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,gBAAgB,CA4BtG;AAKD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAyB;IAExC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK7B,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAKtC,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAK1C,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,GAAG,IAAI;IAQxE,KAAK,IAAI,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG;IAIlC,YAAY,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,QAAQ,EAAE,MAAM,KAAK,CAAC;CAGjD;AAMD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB;;;eAUpE,MAAM;;EAGpB;AAGD,eAAe,QAAQ,CAAC"}
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.loadYamlWithDebug = loadYamlWithDebug;
|
|
6
|
-
exports.validateYamlReferences = validateYamlReferences;
|
|
7
|
-
exports.getTestCacheInterface = getTestCacheInterface;
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const path_1 = require("path");
|
|
10
|
-
const yaml_1 = require("yaml");
|
|
11
|
-
class YamlLoaderError extends Error {
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { resolve, dirname, extname } from 'path';
|
|
3
|
+
import { parse } from 'yaml';
|
|
4
|
+
export class YamlLoaderError extends Error {
|
|
12
5
|
constructor(message, type, path, refChain) {
|
|
13
6
|
super(message);
|
|
14
7
|
this.type = type;
|
|
@@ -17,7 +10,6 @@ class YamlLoaderError extends Error {
|
|
|
17
10
|
this.name = 'YamlLoaderError';
|
|
18
11
|
}
|
|
19
12
|
}
|
|
20
|
-
exports.YamlLoaderError = YamlLoaderError;
|
|
21
13
|
class LRUFileCache {
|
|
22
14
|
constructor(maxSize = 100) {
|
|
23
15
|
this.cache = new Map();
|
|
@@ -54,12 +46,12 @@ class LRUFileCache {
|
|
|
54
46
|
}
|
|
55
47
|
}
|
|
56
48
|
const loadFile = (filename) => {
|
|
57
|
-
const content =
|
|
58
|
-
const ext =
|
|
49
|
+
const content = readFileSync(filename, 'utf-8');
|
|
50
|
+
const ext = extname(filename).toLowerCase();
|
|
59
51
|
if (ext === '.json') {
|
|
60
52
|
return JSON.parse(content);
|
|
61
53
|
}
|
|
62
|
-
return
|
|
54
|
+
return parse(content);
|
|
63
55
|
};
|
|
64
56
|
const resolvePointer = (obj, pointer) => {
|
|
65
57
|
if (!pointer || pointer === '' || pointer === '/') {
|
|
@@ -77,7 +69,7 @@ const resolvePointer = (obj, pointer) => {
|
|
|
77
69
|
return current;
|
|
78
70
|
};
|
|
79
71
|
const resolvePath = (baseDir, filePath, options) => {
|
|
80
|
-
const resolved =
|
|
72
|
+
const resolved = resolve(baseDir, filePath);
|
|
81
73
|
if (!options.allowExternalAccess && !resolved.startsWith(baseDir)) {
|
|
82
74
|
throw new YamlLoaderError(`Attempted to access file outside base directory: ${filePath}`, 'invalid_pointer', resolved);
|
|
83
75
|
}
|
|
@@ -128,7 +120,7 @@ const resolveRefs = (obj, baseDir, context, rootDoc) => {
|
|
|
128
120
|
throw new YamlLoaderError(`Failed to load file: ${resolvedPath}`, 'file_not_found', resolvedPath, context.pathChain);
|
|
129
121
|
}
|
|
130
122
|
}
|
|
131
|
-
const refBaseDir =
|
|
123
|
+
const refBaseDir = dirname(resolvedPath);
|
|
132
124
|
const resolved = resolvePointer(refContent, pointer);
|
|
133
125
|
return resolveRefs(resolved, refBaseDir, context, refContent);
|
|
134
126
|
}
|
|
@@ -168,15 +160,21 @@ const createResolutionContext = (options = {}) => {
|
|
|
168
160
|
pathChain: [],
|
|
169
161
|
pathSet: new Set(),
|
|
170
162
|
fileCache: new LRUFileCache(options.maxCacheSize || 100),
|
|
171
|
-
options:
|
|
163
|
+
options: {
|
|
164
|
+
maxCacheSize: 100,
|
|
165
|
+
allowExternalAccess: false,
|
|
166
|
+
strictMode: false,
|
|
167
|
+
customResolvers: new Map(),
|
|
168
|
+
...options,
|
|
169
|
+
},
|
|
172
170
|
startTime: Date.now(),
|
|
173
171
|
};
|
|
174
172
|
};
|
|
175
|
-
function loadYaml(filename, options) {
|
|
173
|
+
export function loadYaml(filename, options) {
|
|
176
174
|
const context = createResolutionContext(options);
|
|
177
175
|
try {
|
|
178
176
|
const content = loadFile(filename);
|
|
179
|
-
const baseDir =
|
|
177
|
+
const baseDir = dirname(filename);
|
|
180
178
|
return resolveRefs(content, baseDir, context, content);
|
|
181
179
|
}
|
|
182
180
|
catch (error) {
|
|
@@ -186,11 +184,11 @@ function loadYaml(filename, options) {
|
|
|
186
184
|
throw new YamlLoaderError(`Failed to parse YAML file: ${error instanceof Error ? error.message : String(error)}`, 'parse_error', filename);
|
|
187
185
|
}
|
|
188
186
|
}
|
|
189
|
-
function loadYamlWithDebug(filename, options) {
|
|
187
|
+
export function loadYamlWithDebug(filename, options) {
|
|
190
188
|
const context = createResolutionContext(options);
|
|
191
189
|
try {
|
|
192
190
|
const content = loadFile(filename);
|
|
193
|
-
const baseDir =
|
|
191
|
+
const baseDir = dirname(filename);
|
|
194
192
|
const result = resolveRefs(content, baseDir, context, content);
|
|
195
193
|
return {
|
|
196
194
|
result,
|
|
@@ -208,13 +206,13 @@ function loadYamlWithDebug(filename, options) {
|
|
|
208
206
|
throw new YamlLoaderError(`Failed to parse YAML file: ${error instanceof Error ? error.message : String(error)}`, 'parse_error', filename);
|
|
209
207
|
}
|
|
210
208
|
}
|
|
211
|
-
function validateYamlReferences(filename, options) {
|
|
209
|
+
export function validateYamlReferences(filename, options) {
|
|
212
210
|
const errors = [];
|
|
213
211
|
const warnings = [];
|
|
214
212
|
try {
|
|
215
213
|
const context = createResolutionContext(options);
|
|
216
214
|
const content = loadFile(filename);
|
|
217
|
-
const baseDir =
|
|
215
|
+
const baseDir = dirname(filename);
|
|
218
216
|
resolveRefs(content, baseDir, context, content);
|
|
219
217
|
return { isValid: true, errors, warnings };
|
|
220
218
|
}
|
|
@@ -228,7 +226,7 @@ function validateYamlReferences(filename, options) {
|
|
|
228
226
|
return { isValid: false, errors, warnings };
|
|
229
227
|
}
|
|
230
228
|
}
|
|
231
|
-
class YamlLoaderBuilder {
|
|
229
|
+
export class YamlLoaderBuilder {
|
|
232
230
|
constructor() {
|
|
233
231
|
this.options = {};
|
|
234
232
|
}
|
|
@@ -258,8 +256,7 @@ class YamlLoaderBuilder {
|
|
|
258
256
|
return (filename) => loadYaml(filename, this.options);
|
|
259
257
|
}
|
|
260
258
|
}
|
|
261
|
-
|
|
262
|
-
function getTestCacheInterface(filename, options) {
|
|
259
|
+
export function getTestCacheInterface(filename, options) {
|
|
263
260
|
const context = createResolutionContext(options);
|
|
264
261
|
loadFile(filename);
|
|
265
262
|
return {
|
|
@@ -269,4 +266,4 @@ function getTestCacheInterface(filename, options) {
|
|
|
269
266
|
getCache: () => context.fileCache.getCache(),
|
|
270
267
|
};
|
|
271
268
|
}
|
|
272
|
-
|
|
269
|
+
export default loadYaml;
|
package/package.json
CHANGED
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@northern/yaml-loader",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Load YAML files from
|
|
5
|
-
"main": "lib/index.js",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "Load YAML files from fragmented sources",
|
|
5
|
+
"main": "lib/cjs/index.js",
|
|
6
|
+
"module": "lib/esm/index.js",
|
|
7
|
+
"types": "lib/cjs/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./lib/esm/index.d.ts",
|
|
12
|
+
"default": "./lib/esm/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./lib/cjs/index.d.ts",
|
|
16
|
+
"default": "./lib/cjs/index.js"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=16.0.0"
|
|
23
|
+
},
|
|
6
24
|
"files": [
|
|
7
25
|
"lib/**/*"
|
|
8
26
|
],
|
|
9
27
|
"scripts": {
|
|
10
|
-
"build": "
|
|
28
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
29
|
+
"build:cjs": "tsc -p tsconfig.cjs.json --removeComments",
|
|
30
|
+
"build:esm": "tsc -p tsconfig.esm.json --removeComments",
|
|
11
31
|
"test": "jest",
|
|
12
32
|
"test:watch": "jest --watch --no-coverage",
|
|
13
33
|
"test:coverage": "jest --coverage",
|