@digicatapult/dtdl-parser 0.0.13 → 0.0.15
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/error.d.ts +2 -0
- package/build/error.js +9 -0
- package/build/error.js.map +1 -0
- package/build/index.d.ts +8 -0
- package/build/index.js +59 -0
- package/build/index.js.map +1 -0
- package/build/interop/_framework/DTDLParserJSInterop.pdb +0 -0
- package/build/interop/_framework/DTDLParserJSInterop.wasm +0 -0
- package/build/interop/_framework/blazor.boot.json +3 -3
- package/build/interop.d.ts +5 -0
- package/package.json +15 -8
- package/build/package.json +0 -62
- package/build/src/__tests__/fixtures/empty.json +0 -1
- package/build/src/__tests__/fixtures/nested/nested.json +0 -1
- package/build/src/error.js +0 -2
- package/build/src/error.js.map +0 -1
- package/build/src/index.js +0 -6
- package/build/src/index.js.map +0 -1
- package/build/src/interop.js +0 -2
- package/build/src/interop.js.map +0 -1
package/build/error.d.ts
ADDED
package/build/error.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
let { error: e } = console, n = (e)=>'Parsing' === e.ExceptionKind, o = (e)=>'Resolution' === e.ExceptionKind;
|
|
2
|
+
export const isResolutionException = (e)=>e instanceof Error && o(JSON.parse(e.message));
|
|
3
|
+
export const errorHandler = (r)=>{
|
|
4
|
+
if (!(r instanceof Error)) return e(`Unexpected error: ${r}`);
|
|
5
|
+
let t = JSON.parse(r.message);
|
|
6
|
+
n(t) || o(t) || e('Unknown exception type'), e(t);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/error.ts"],"sourcesContent":["import type { ModelingException, ParsingException, ResolutionException } from '../types/DtdlErr.d.ts'\n\nconst { error } = console\n\nconst isParsingEx = (exception: ModelingException): exception is ParsingException => {\n return exception.ExceptionKind === 'Parsing'\n}\n\nconst isResolutionEx = (exception: ModelingException): exception is ResolutionException => {\n return exception.ExceptionKind === 'Resolution'\n}\n\nexport const isResolutionException = (err: unknown) => {\n if (!(err instanceof Error)) return false\n return isResolutionEx(JSON.parse(err.message))\n}\n\nexport const errorHandler = (err: unknown) => {\n if (!(err instanceof Error)) return error(`Unexpected error: ${err}`)\n\n const exception = JSON.parse(err.message) as ModelingException\n\n if (!(isParsingEx(exception) || isResolutionEx(exception))) error('Unknown exception type')\n error(exception)\n}\n"],"names":["error","console","isParsingEx","exception","ExceptionKind","isResolutionEx","isResolutionException","err","Error","JSON","parse","message","errorHandler"],"mappings":"AAEA,IAAM,EAAEA,OAAAA,CAAK,EAAE,GAAGC,SAEZC,IAAc,CAACC,IACZA,AAA4B,cAA5BA,EAAUC,aAAa,EAG1BC,IAAiB,CAACF,IACfA,AAA4B,iBAA5BA,EAAUC,aAAa;AAGhC,OAAO,MAAME,wBAAwB,CAACC,IACpC,AAAMA,aAAeC,SACdH,EAAeI,KAAKC,KAAK,CAACH,EAAII,OAAO,GAC7C;AAED,OAAO,MAAMC,eAAe,CAACL;IAC3B,IAAI,CAAEA,CAAAA,aAAeC,KAAI,GAAI,OAAOR,EAAM,CAAC,kBAAkB,EAAEO,GAAK;IAEpE,IAAMJ,IAAYM,KAAKC,KAAK,CAACH,EAAII,OAAO;IAElCT,EAAYC,MAAcE,EAAeF,MAAaH,EAAM,2BAClEA,EAAMG;AACR,EAAC"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DtdlObjectModel } from '../types/DtdlOm.d.ts';
|
|
2
|
+
import type { Parser } from './interop.js';
|
|
3
|
+
export type * from '../types/DtdlErr.d.ts';
|
|
4
|
+
export type * from '../types/DtdlOm.d.ts';
|
|
5
|
+
export { getInterop } from './interop.js';
|
|
6
|
+
export declare const searchForJsonFiles: (directory: string) => string[];
|
|
7
|
+
export declare const validateDirectories: (directory: string, parser: Parser, incResolutionException: boolean) => boolean;
|
|
8
|
+
export declare const parseDirectories: (directory: string, parser: Parser) => DtdlObjectModel | null;
|
package/build/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import e from 'fs';
|
|
2
|
+
import r from 'path';
|
|
3
|
+
import { errorHandler as t, isResolutionException as l } from './error.js';
|
|
4
|
+
let { log: n, error: s } = console;
|
|
5
|
+
export { getInterop } from './interop.js';
|
|
6
|
+
export const searchForJsonFiles = (t)=>e.existsSync(t) ? e.readdirSync(t).map((e)=>r.join(t, e)).reduce((t, l)=>e.statSync(l).isDirectory() ? t.concat(searchForJsonFiles(l)) : '.json' === r.extname(l) ? t.concat(l) : t, []) : (s(`'${t}' not a valid filepath`), []);
|
|
7
|
+
let i = (r)=>{
|
|
8
|
+
try {
|
|
9
|
+
let t = e.readFileSync(r, 'utf-8');
|
|
10
|
+
return JSON.parse(t);
|
|
11
|
+
} catch (e) {
|
|
12
|
+
return s(`Invalid JSON at '${r}'`), s(e), null;
|
|
13
|
+
}
|
|
14
|
+
}, a = (e)=>{
|
|
15
|
+
let r = [];
|
|
16
|
+
for (let t of e){
|
|
17
|
+
let e = i(t);
|
|
18
|
+
if (null === e) return null;
|
|
19
|
+
r.push(e);
|
|
20
|
+
}
|
|
21
|
+
return r;
|
|
22
|
+
}, o = (r, i, a)=>{
|
|
23
|
+
try {
|
|
24
|
+
let t = e.readFileSync(r, 'utf-8');
|
|
25
|
+
return i.parse(t), n(`Successfully validated '${r}'`), !0;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
if (!a && l(e)) return n(`Successfully validated '${r}'`), !0;
|
|
28
|
+
return s(`Error parsing '${r}'`), t(e), !1;
|
|
29
|
+
}
|
|
30
|
+
}, u = (e, r)=>{
|
|
31
|
+
try {
|
|
32
|
+
let t = JSON.parse(r.parse(JSON.stringify(e)));
|
|
33
|
+
return n("Successfully parsed"), t;
|
|
34
|
+
} catch (e) {
|
|
35
|
+
return s("Error parsing"), t(e), null;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export const validateDirectories = (e, r, t)=>{
|
|
39
|
+
n(`${r.parserVersion()}\n`), n(`Validating DTDL at: '${e}'`);
|
|
40
|
+
let l = searchForJsonFiles(e);
|
|
41
|
+
if (l.length < 1) return !1;
|
|
42
|
+
for (let e of (n(`Found ${l.length} files:`), n(l), l))if (!o(e, r, t)) return !1;
|
|
43
|
+
return n(`All files validated!\n`), !0;
|
|
44
|
+
};
|
|
45
|
+
export const parseDirectories = (e, r)=>{
|
|
46
|
+
n(`${r.parserVersion()}\n`), n(`Parsing DTDL at: '${e}'`);
|
|
47
|
+
let t = searchForJsonFiles(e);
|
|
48
|
+
if (t.length < 1) return null;
|
|
49
|
+
n(`Found ${t.length} files:`), n(t);
|
|
50
|
+
let l = a(t);
|
|
51
|
+
if (null === l) return null;
|
|
52
|
+
let s = u(l, r);
|
|
53
|
+
if (null === s) return null;
|
|
54
|
+
n(`All files parsed!\n`), n("Entities:"), n(Object.keys(s));
|
|
55
|
+
let i = Object.values(s).filter((e)=>'Interface' === e.EntityKind);
|
|
56
|
+
return n(`Number of interfaces: ${i.length}`), s;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport type { DtdlObjectModel, InterfaceInfo } from '../types/DtdlOm.d.ts'\nimport { errorHandler, isResolutionException } from './error.js'\nimport type { Parser } from './interop.js'\n\nconst { log, error } = console\n\nexport type * from '../types/DtdlErr.d.ts'\nexport type * from '../types/DtdlOm.d.ts'\nexport { getInterop } from './interop.js'\n\nexport const searchForJsonFiles = (directory: string): string[] => {\n if (!fs.existsSync(directory)) {\n error(`'${directory}' not a valid filepath`)\n return []\n }\n\n return fs\n .readdirSync(directory)\n .map((file) => path.join(directory, file))\n .reduce((jsonFiles, fullPath) => {\n if (fs.statSync(fullPath).isDirectory()) {\n return jsonFiles.concat(searchForJsonFiles(fullPath)) //recursive\n } else if (path.extname(fullPath) === '.json') {\n return jsonFiles.concat(fullPath)\n }\n return jsonFiles\n }, [] as string[])\n}\n\nconst readJsonFile = (filepath: string): unknown | null => {\n try {\n const file = fs.readFileSync(filepath, 'utf-8')\n const json = JSON.parse(file)\n return json\n } catch (err) {\n error(`Invalid JSON at '${filepath}'`)\n error(err)\n return null\n }\n}\n\nconst combineJson = (filepaths: string[]) => {\n const combinedJson: unknown[] = []\n\n for (const filepath of filepaths) {\n const json = readJsonFile(filepath)\n if (json === null) {\n return null // exit on any error\n }\n combinedJson.push(json)\n }\n\n return combinedJson\n}\n\nconst validateFile = (filepath: string, parserModule: Parser, incResolutionException: boolean): boolean => {\n try {\n const file = fs.readFileSync(filepath, 'utf-8')\n parserModule.parse(file)\n log(`Successfully validated '${filepath}'`)\n return true\n } catch (err) {\n if (!incResolutionException && isResolutionException(err)) {\n // ignore resolution exception\n log(`Successfully validated '${filepath}'`)\n return true\n }\n error(`Error parsing '${filepath}'`)\n errorHandler(err)\n return false\n }\n}\n\nconst parseDtdl = (json: unknown[], parserModule: Parser): DtdlObjectModel | null => {\n try {\n const model = JSON.parse(parserModule.parse(JSON.stringify(json))) as DtdlObjectModel\n log(`Successfully parsed`)\n return model\n } catch (err) {\n error(`Error parsing`)\n errorHandler(err)\n return null\n }\n}\n\nexport const validateDirectories = (directory: string, parser: Parser, incResolutionException: boolean): boolean => {\n log(`${parser.parserVersion()}\\n`)\n log(`Validating DTDL at: '${directory}'`)\n\n const filepaths = searchForJsonFiles(directory)\n if (filepaths.length < 1) return false\n\n log(`Found ${filepaths.length} files:`)\n log(filepaths)\n\n for (const filepath of filepaths) {\n const isValid = validateFile(filepath, parser, incResolutionException)\n if (!isValid) return false // stop validating if error\n }\n\n log(`All files validated!\\n`)\n return true\n}\n\nexport const parseDirectories = (directory: string, parser: Parser): DtdlObjectModel | null => {\n log(`${parser.parserVersion()}\\n`)\n log(`Parsing DTDL at: '${directory}'`)\n\n const filepaths = searchForJsonFiles(directory)\n if (filepaths.length < 1) return null\n\n log(`Found ${filepaths.length} files:`)\n log(filepaths)\n\n const fullJson = combineJson(filepaths)\n if (fullJson === null) return null\n\n const fullModel = parseDtdl(fullJson, parser)\n if (fullModel === null) return null\n\n log(`All files parsed!\\n`)\n log(`Entities:`)\n log(Object.keys(fullModel))\n\n // Example type guard\n const interfaces: InterfaceInfo[] = Object.values(fullModel).filter(\n (value): value is InterfaceInfo => value.EntityKind === 'Interface'\n )\n log(`Number of interfaces: ${interfaces.length}`)\n\n return fullModel\n}\n"],"names":["fs","path","errorHandler","isResolutionException","log","error","console","getInterop","searchForJsonFiles","directory","existsSync","readdirSync","map","file","join","reduce","jsonFiles","fullPath","statSync","isDirectory","concat","extname","readJsonFile","filepath","readFileSync","JSON","parse","err","combineJson","filepaths","combinedJson","json","push","validateFile","parserModule","incResolutionException","parseDtdl","model","stringify","validateDirectories","parser","parserVersion","length","parseDirectories","fullJson","fullModel","Object","keys","interfaces","values","filter","value","EntityKind"],"mappings":"AAAA,OAAOA,OAAQ,KAAI;AACnB,OAAOC,OAAU,OAAM;AAEvB,SAASC,gBAAAA,CAAY,EAAEC,yBAAAA,CAAqB,QAAQ,aAAY;AAGhE,IAAM,EAAEC,KAAAA,CAAG,EAAEC,OAAAA,CAAK,EAAE,GAAGC;AAIvB,SAASC,UAAU,QAAQ,eAAc;AAEzC,OAAO,MAAMC,qBAAqB,CAACC,IACjC,AAAKT,EAAGU,UAAU,CAACD,KAKZT,EACJW,WAAW,CAACF,GACZG,GAAG,CAAC,CAACC,IAASZ,EAAKa,IAAI,CAACL,GAAWI,IACnCE,MAAM,CAAC,CAACC,GAAWC,IAClB,AAAIjB,EAAGkB,QAAQ,CAACD,GAAUE,WAAW,KAC5BH,EAAUI,MAAM,CAACZ,mBAAmBS,MAClChB,AAA2B,YAA3BA,EAAKoB,OAAO,CAACJ,KACfD,EAAUI,MAAM,CAACH,KAEnBD,GACN,EAAE,KAdLX,EAAM,CAAC,CAAC,EAAEI,EAAU,sBAAsB,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": "sha256-
|
|
4
|
+
"hash": "sha256-gz7SFK75PKjPCvG+55ZwMLiIGkxrTqRy/2Wjzk68AFU=",
|
|
5
5
|
"jsModuleNative": {
|
|
6
6
|
"dotnet.native.js": "sha256-79LdZogK41buIci0KtOWmQvQc2swMI3jvDQCoN23NBM="
|
|
7
7
|
},
|
|
@@ -181,10 +181,10 @@
|
|
|
181
181
|
"mscorlib.wasm": "sha256-KvqZaNpjwhrOuzE4b4aMFsI+VUTyiWfoDI4zn4l9BM8=",
|
|
182
182
|
"netstandard.wasm": "sha256-v+s7sWxtOM6bnOvC0jFrtnm6uMfbDymwl2nHNgbS2LM=",
|
|
183
183
|
"System.Private.CoreLib.wasm": "sha256-pklll63uFQoY6vaD3vbluS9osYiJWLLLmob1yHFgepI=",
|
|
184
|
-
"DTDLParserJSInterop.wasm": "sha256-
|
|
184
|
+
"DTDLParserJSInterop.wasm": "sha256-In0ykSqWvOHUMaydHOB4gMR1guIwhvIPHqqA+wJDy2w="
|
|
185
185
|
},
|
|
186
186
|
"pdb": {
|
|
187
|
-
"DTDLParserJSInterop.pdb": "sha256-
|
|
187
|
+
"DTDLParserJSInterop.pdb": "sha256-GY59ni7t9PtmnPBjm+F+HwpjTCgF9LoFjDMjode/fak="
|
|
188
188
|
},
|
|
189
189
|
"vfs": {
|
|
190
190
|
"runtimeconfig.bin": {
|
package/package.json
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digicatapult/dtdl-parser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "JS tool to parse DTDL defined Ontologies",
|
|
5
|
-
"main": "build/
|
|
5
|
+
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
"import": "./build/index.js"
|
|
9
|
+
},
|
|
10
|
+
"types": "./build/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"build/"
|
|
13
|
+
],
|
|
7
14
|
"scripts": {
|
|
8
15
|
"test": "NODE_ENV=test ./node_modules/.bin/mocha --config ./test/mocharc.json ./src/**/*.test.ts",
|
|
9
|
-
"build": "
|
|
16
|
+
"build": "npm run build:ts && npm run interop:build && npm run build:declarations",
|
|
17
|
+
"build:declarations": "tsc --emitDeclarationOnly",
|
|
10
18
|
"interop:debug": "dotnet build interop",
|
|
11
|
-
"interop:build": "dotnet build interop --configuration Release",
|
|
19
|
+
"interop:build": "dotnet build src/interop --configuration Release",
|
|
20
|
+
"build:ts": "swc ./src -d ./build --strip-leading-paths",
|
|
21
|
+
"check": "tsc --noEmit",
|
|
12
22
|
"clean": "rimraf -rf ./build",
|
|
13
23
|
"lint": "eslint .",
|
|
14
24
|
"depcheck": "depcheck"
|
|
@@ -17,9 +27,6 @@
|
|
|
17
27
|
"type": "git",
|
|
18
28
|
"url": "git+https://github.com/digicatapult/dtdl-parser.git"
|
|
19
29
|
},
|
|
20
|
-
"files": [
|
|
21
|
-
"build"
|
|
22
|
-
],
|
|
23
30
|
"keywords": [
|
|
24
31
|
"dtdl",
|
|
25
32
|
"digital",
|
|
@@ -59,4 +66,4 @@
|
|
|
59
66
|
"engines": {
|
|
60
67
|
"node": ">= 20"
|
|
61
68
|
}
|
|
62
|
-
}
|
|
69
|
+
}
|
package/build/package.json
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@digicatapult/dtdl-parser",
|
|
3
|
-
"version": "0.0.13",
|
|
4
|
-
"description": "JS tool to parse DTDL defined Ontologies",
|
|
5
|
-
"main": "build/src/index.js",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "NODE_ENV=test ./node_modules/.bin/mocha --config ./test/mocharc.json ./src/**/*.test.ts",
|
|
9
|
-
"build": "swc ./src ./package.json -d ./build --copy-files && npm run interop:build",
|
|
10
|
-
"interop:debug": "dotnet build interop",
|
|
11
|
-
"interop:build": "dotnet build interop --configuration Release",
|
|
12
|
-
"clean": "rimraf -rf ./build",
|
|
13
|
-
"lint": "eslint .",
|
|
14
|
-
"depcheck": "depcheck"
|
|
15
|
-
},
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/digicatapult/dtdl-parser.git"
|
|
19
|
-
},
|
|
20
|
-
"files": [
|
|
21
|
-
"build"
|
|
22
|
-
],
|
|
23
|
-
"keywords": [
|
|
24
|
-
"dtdl",
|
|
25
|
-
"digital",
|
|
26
|
-
"twins",
|
|
27
|
-
"parsing",
|
|
28
|
-
"tool"
|
|
29
|
-
],
|
|
30
|
-
"author": "Digital Catapult",
|
|
31
|
-
"license": "Apache-2.0",
|
|
32
|
-
"bugs": {
|
|
33
|
-
"url": "https://github.com/digicatapult/dtdl-parser/issues"
|
|
34
|
-
},
|
|
35
|
-
"homepage": "https://github.com/digicatapult/dtdl-parser#readme",
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@eslint/eslintrc": "^3.1.0",
|
|
38
|
-
"@eslint/js": "^9.12.0",
|
|
39
|
-
"@swc-node/register": "^1.10.9",
|
|
40
|
-
"@swc/cli": "^0.4.1-nightly.20240914",
|
|
41
|
-
"@swc/core": "^1.7.35",
|
|
42
|
-
"@types/chai": "^5.0.0",
|
|
43
|
-
"@types/mocha": "^10.0.9",
|
|
44
|
-
"@types/node": "^22.7.5",
|
|
45
|
-
"@typescript-eslint/eslint-plugin": "^8.8.1",
|
|
46
|
-
"@typescript-eslint/parser": "^8.8.1",
|
|
47
|
-
"chai": "^5.1.1",
|
|
48
|
-
"depcheck": "^1.4.7",
|
|
49
|
-
"eslint": "^9.12.0",
|
|
50
|
-
"eslint-config-prettier": "^9.1.0",
|
|
51
|
-
"eslint-plugin-prettier": "^5.2.1",
|
|
52
|
-
"globals": "^15.11.0",
|
|
53
|
-
"mocha": "^10.7.3",
|
|
54
|
-
"prettier": "^3.3.3",
|
|
55
|
-
"prettier-plugin-organize-imports": "^4.1.0",
|
|
56
|
-
"rimraf": "^6.0.1",
|
|
57
|
-
"typescript": "^5.6.3"
|
|
58
|
-
},
|
|
59
|
-
"engines": {
|
|
60
|
-
"node": ">= 20"
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
package/build/src/error.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
let{error:e}=console,n=e=>"Parsing"===e.ExceptionKind,o=e=>"Resolution"===e.ExceptionKind;export const isResolutionException=e=>e instanceof Error&&o(JSON.parse(e.message));export const errorHandler=r=>{if(!(r instanceof Error))return e(`Unexpected error: ${r}`);let t=JSON.parse(r.message);n(t)||o(t)||e("Unknown exception type"),e(t)};
|
|
2
|
-
//# sourceMappingURL=error.js.map
|
package/build/src/error.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/error.ts"],"sourcesContent":["import { ModelingException, ParsingException, ResolutionException } from '../interop/DtdlErr.js'\n\nconst { error } = console\n\nconst isParsingEx = (exception: ModelingException): exception is ParsingException => {\n return exception.ExceptionKind === 'Parsing'\n}\n\nconst isResolutionEx = (exception: ModelingException): exception is ResolutionException => {\n return exception.ExceptionKind === 'Resolution'\n}\n\nexport const isResolutionException = (err: unknown) => {\n if (!(err instanceof Error)) return false\n return isResolutionEx(JSON.parse(err.message))\n}\n\nexport const errorHandler = (err: unknown) => {\n if (!(err instanceof Error)) return error(`Unexpected error: ${err}`)\n\n const exception = JSON.parse(err.message) as ModelingException\n\n if (!(isParsingEx(exception) || isResolutionEx(exception))) error('Unknown exception type')\n error(exception)\n}\n"],"names":["error","console","isParsingEx","exception","ExceptionKind","isResolutionEx","isResolutionException","err","Error","JSON","parse","message","errorHandler"],"mappings":"AAEA,GAAM,CAAEA,MAAAA,CAAK,CAAE,CAAGC,QAEZC,EAAc,AAACC,GACZA,AAA4B,YAA5BA,EAAUC,aAAa,CAG1BC,EAAiB,AAACF,GACfA,AAA4B,eAA5BA,EAAUC,aAAa,AAGhC,QAAO,MAAME,sBAAwB,AAACC,GACpC,AAAMA,aAAeC,OACdH,EAAeI,KAAKC,KAAK,CAACH,EAAII,OAAO,EAC7C,AAED,QAAO,MAAMC,aAAe,AAACL,IAC3B,GAAI,CAAEA,CAAAA,aAAeC,KAAI,EAAI,OAAOR,EAAM,CAAC,kBAAkB,EAAEO,EAAI,CAAC,EAEpE,IAAMJ,EAAYM,KAAKC,KAAK,CAACH,EAAII,OAAO,EAElCT,EAAYC,IAAcE,EAAeF,IAAaH,EAAM,0BAClEA,EAAMG,EACR,CAAC"}
|
package/build/src/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import e from"fs";import r from"path";import{errorHandler as t,isResolutionException as l}from"./error.js";import{getInterop as n}from"./interop.js";let{log:s,error:i}=console;export const searchForJsonFiles=t=>e.existsSync(t)?e.readdirSync(t).map(e=>r.join(t,e)).reduce((t,l)=>e.statSync(l).isDirectory()?t.concat(searchForJsonFiles(l)):".json"===r.extname(l)?t.concat(l):t,[]):(i(`'${t}' not a valid filepath`),[]);let o=r=>{try{let t=e.readFileSync(r,"utf-8");return JSON.parse(t)}catch(e){return i(`Invalid JSON at '${r}'`),i(e),null}},a=e=>{let r=[];for(let t of e){let e=o(t);if(null===e)return null;r.push(e)}return r},u=(r,n,o)=>{try{let t=e.readFileSync(r,"utf-8");return n.parse(t),s(`Successfully validated '${r}'`),!0}catch(e){if(!o&&l(e))return s(`Successfully validated '${r}'`),!0;return i(`Error parsing '${r}'`),t(e),!1}},c=(e,r)=>{try{let t=JSON.parse(r.parse(JSON.stringify(e)));return s("Successfully parsed"),t}catch(e){return i("Error parsing"),t(e),null}};export const validateDirectories=(e,r,t)=>{s(`${r.parserVersion()}
|
|
2
|
-
`),s(`Validating DTDL at: '${e}'`);let l=searchForJsonFiles(e);if(l.length<1)return!1;for(let e of(s(`Found ${l.length} files:`),s(l),l))if(!u(e,r,t))return!1;return s(`All files validated!
|
|
3
|
-
`),!0};export const parseDirectories=(e,r)=>{s(`${r.parserVersion()}
|
|
4
|
-
`),s(`Parsing DTDL at: '${e}'`);let t=searchForJsonFiles(e);if(t.length<1)return null;s(`Found ${t.length} files:`),s(t);let l=a(t);if(null===l)return null;let n=c(l,r);if(null===n)return null;s(`All files parsed!
|
|
5
|
-
`),s("Entities:"),s(Object.keys(n));let i=Object.values(n).filter(e=>"Interface"===e.EntityKind);return s(`Number of interfaces: ${i.length}`),n};export{t as errorHandler,n as getInterop,l as isResolutionException};
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
package/build/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport { DtdlObjectModel, InterfaceInfo } from '../interop/DtdlOm.js'\nimport { errorHandler, isResolutionException } from './error.js'\nimport { Parser, getInterop } from './interop.js'\n\nconst { log, error } = console\n\nexport const searchForJsonFiles = (directory: string): string[] => {\n if (!fs.existsSync(directory)) {\n error(`'${directory}' not a valid filepath`)\n return []\n }\n\n return fs\n .readdirSync(directory)\n .map((file) => path.join(directory, file))\n .reduce((jsonFiles, fullPath) => {\n if (fs.statSync(fullPath).isDirectory()) {\n return jsonFiles.concat(searchForJsonFiles(fullPath)) //recursive\n } else if (path.extname(fullPath) === '.json') {\n return jsonFiles.concat(fullPath)\n }\n return jsonFiles\n }, [] as string[])\n}\n\nconst readJsonFile = (filepath: string): unknown | null => {\n try {\n const file = fs.readFileSync(filepath, 'utf-8')\n const json = JSON.parse(file)\n return json\n } catch (err) {\n error(`Invalid JSON at '${filepath}'`)\n error(err)\n return null\n }\n}\n\nconst combineJson = (filepaths: string[]) => {\n const combinedJson: unknown[] = []\n\n for (const filepath of filepaths) {\n const json = readJsonFile(filepath)\n if (json === null) {\n return null // exit on any error\n }\n combinedJson.push(json)\n }\n\n return combinedJson\n}\n\nconst validateFile = (filepath: string, parserModule: Parser, incResolutionException: boolean): boolean => {\n try {\n const file = fs.readFileSync(filepath, 'utf-8')\n parserModule.parse(file)\n log(`Successfully validated '${filepath}'`)\n return true\n } catch (err) {\n if (!incResolutionException && isResolutionException(err)) {\n // ignore resolution exception\n log(`Successfully validated '${filepath}'`)\n return true\n }\n error(`Error parsing '${filepath}'`)\n errorHandler(err)\n return false\n }\n}\n\nconst parseDtdl = (json: unknown[], parserModule: Parser): DtdlObjectModel | null => {\n try {\n const model = JSON.parse(parserModule.parse(JSON.stringify(json))) as DtdlObjectModel\n log(`Successfully parsed`)\n return model\n } catch (err) {\n error(`Error parsing`)\n errorHandler(err)\n return null\n }\n}\n\nexport const validateDirectories = (directory: string, parser: Parser, incResolutionException: boolean): boolean => {\n log(`${parser.parserVersion()}\\n`)\n log(`Validating DTDL at: '${directory}'`)\n\n const filepaths = searchForJsonFiles(directory)\n if (filepaths.length < 1) return false\n\n log(`Found ${filepaths.length} files:`)\n log(filepaths)\n\n for (const filepath of filepaths) {\n const isValid = validateFile(filepath, parser, incResolutionException)\n if (!isValid) return false // stop validating if error\n }\n\n log(`All files validated!\\n`)\n return true\n}\n\nexport const parseDirectories = (directory: string, parser: Parser): DtdlObjectModel | null => {\n log(`${parser.parserVersion()}\\n`)\n log(`Parsing DTDL at: '${directory}'`)\n\n const filepaths = searchForJsonFiles(directory)\n if (filepaths.length < 1) return null\n\n log(`Found ${filepaths.length} files:`)\n log(filepaths)\n\n const fullJson = combineJson(filepaths)\n if (fullJson === null) return null\n\n const fullModel = parseDtdl(fullJson, parser)\n if (fullModel === null) return null\n\n log(`All files parsed!\\n`)\n log(`Entities:`)\n log(Object.keys(fullModel))\n\n // Example type guard\n const interfaces: InterfaceInfo[] = Object.values(fullModel).filter(\n (value): value is InterfaceInfo => value.EntityKind === 'Interface'\n )\n log(`Number of interfaces: ${interfaces.length}`)\n\n return fullModel\n}\nexport { errorHandler, getInterop, isResolutionException }\n"],"names":["fs","path","errorHandler","isResolutionException","getInterop","log","error","console","searchForJsonFiles","directory","existsSync","readdirSync","map","file","join","reduce","jsonFiles","fullPath","statSync","isDirectory","concat","extname","readJsonFile","filepath","readFileSync","JSON","parse","err","combineJson","filepaths","combinedJson","json","push","validateFile","parserModule","incResolutionException","parseDtdl","model","stringify","validateDirectories","parser","parserVersion","length","parseDirectories","fullJson","fullModel","Object","keys","interfaces","values","filter","value","EntityKind"],"mappings":"AAAA,OAAOA,MAAQ,IAAI,AACnB,QAAOC,MAAU,MAAM,AAEvB,QAASC,gBAAAA,CAAY,CAAEC,yBAAAA,CAAqB,KAAQ,YAAY,AAChE,QAAiBC,cAAAA,CAAU,KAAQ,cAAc,CAEjD,GAAM,CAAEC,IAAAA,CAAG,CAAEC,MAAAA,CAAK,CAAE,CAAGC,OAEvB,QAAO,MAAMC,mBAAqB,AAACC,GACjC,AAAKT,EAAGU,UAAU,CAACD,GAKZT,EACJW,WAAW,CAACF,GACZG,GAAG,CAAC,AAACC,GAASZ,EAAKa,IAAI,CAACL,EAAWI,IACnCE,MAAM,CAAC,CAACC,EAAWC,IAClB,AAAIjB,EAAGkB,QAAQ,CAACD,GAAUE,WAAW,GAC5BH,EAAUI,MAAM,CAACZ,mBAAmBS,IAClChB,AAA2B,UAA3BA,EAAKoB,OAAO,CAACJ,GACfD,EAAUI,MAAM,CAACH,GAEnBD,EACN,EAAE,GAdLV,EAAM,CAAC,CAAC,EAAEG,EAAU,sBAAsB,CAAC,EACpC,EAAE,CAcZ,CAED,IAAMa,EAAe,AAACC,IACpB,GAAI,CACF,IAAMV,EAAOb,EAAGwB,YAAY,CAACD,EAAU,SAEvC,OADaE,KAAKC,KAAK,CAACb,EAE1B,CAAE,MAAOc,EAAK,CAGZ,OAFArB,EAAM,CAAC,iBAAiB,EAAEiB,EAAS,CAAC,CAAC,EACrCjB,EAAMqB,GACC,IACT,CACF,EAEMC,EAAc,AAACC,IACnB,IAAMC,EAA0B,EAAE,CAElC,IAAK,IAAMP,KAAYM,EAAW,CAChC,IAAME,EAAOT,EA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O,MAAMsC,iBAAmB,CAAClC,EAAmB+B,KAClDnC,EAAI,CAAC,EAAEmC,EAAOC,aAAa;AAAK,CAAC,EACjCpC,EAAI,CAAC,kBAAkB,EAAEI,EAAU,CAAC,CAAC,EAErC,IAAMoB,EAAYrB,mBAAmBC,GACrC,GAAIoB,EAAUa,MAAM,CAAG,EAAG,OAAO,KAEjCrC,EAAI,CAAC,MAAM,EAAEwB,EAAUa,MAAM,CAAC,OAAO,CAAC,EACtCrC,EAAIwB,GAEJ,IAAMe,EAAWhB,EAAYC,GAC7B,GAAIe,AAAa,OAAbA,EAAmB,OAAO,KAE9B,IAAMC,EAAYT,EAAUQ,EAAUJ,GACtC,GAAIK,AAAc,OAAdA,EAAoB,OAAO,KAE/BxC,EAAI,CAAC;AAAmB,CAAC,EACzBA,EAAI,aACJA,EAAIyC,OAAOC,IAAI,CAACF,IAGhB,IAAMG,EAA8BF,OAAOG,MAAM,CAACJ,GAAWK,MAAM,CACjE,AAACC,GAAkCA,AAAqB,cAArBA,EAAMC,UAAU,EAIrD,OAFA/C,EAAI,CAAC,sBAAsB,EAAE2C,EAAWN,MAAM,CAAC,CAAC,EAEzCG,CACT,CAAC,QACQ3C,KAAAA,YAAY,CAAEE,KAAAA,UAAU,CAAED,KAAAA,qBAAqB"}
|
package/build/src/interop.js
DELETED
package/build/src/interop.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/interop.ts"],"sourcesContent":["export const getInterop = async (): Promise<Parser> => {\n const module = await import('../interop/modelParser.js')\n return module as Parser\n}\n\nexport interface Parser {\n parse: (file: string) => string\n parserVersion: () => string\n}\n"],"names":["getInterop"],"mappings":"AAAA,OAAO,MAAMA,WAAa,SACT,MAAM,MAAM,CAAC,4BAE7B"}
|