@digicatapult/dtdl-parser 0.0.88 → 0.1.0

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.
Files changed (182) hide show
  1. package/build/index.d.ts +1 -0
  2. package/build/index.js +4 -3
  3. package/build/index.js.map +1 -1
  4. package/build/interop/DTDLParserJSInterop.runtimeconfig.json +1 -1
  5. package/build/interop/_framework/DTDLParserJSInterop.pdb +0 -0
  6. package/build/interop/_framework/DTDLParserJSInterop.wasm +0 -0
  7. package/build/interop/_framework/Microsoft.CSharp.wasm +0 -0
  8. package/build/interop/_framework/Microsoft.VisualBasic.Core.wasm +0 -0
  9. package/build/interop/_framework/Microsoft.VisualBasic.wasm +0 -0
  10. package/build/interop/_framework/Microsoft.Win32.Primitives.wasm +0 -0
  11. package/build/interop/_framework/Microsoft.Win32.Registry.wasm +0 -0
  12. package/build/interop/_framework/System.AppContext.wasm +0 -0
  13. package/build/interop/_framework/System.Buffers.wasm +0 -0
  14. package/build/interop/_framework/System.Collections.Concurrent.wasm +0 -0
  15. package/build/interop/_framework/System.Collections.Immutable.wasm +0 -0
  16. package/build/interop/_framework/System.Collections.NonGeneric.wasm +0 -0
  17. package/build/interop/_framework/System.Collections.Specialized.wasm +0 -0
  18. package/build/interop/_framework/System.Collections.wasm +0 -0
  19. package/build/interop/_framework/System.ComponentModel.Annotations.wasm +0 -0
  20. package/build/interop/_framework/System.ComponentModel.DataAnnotations.wasm +0 -0
  21. package/build/interop/_framework/System.ComponentModel.EventBasedAsync.wasm +0 -0
  22. package/build/interop/_framework/System.ComponentModel.Primitives.wasm +0 -0
  23. package/build/interop/_framework/System.ComponentModel.TypeConverter.wasm +0 -0
  24. package/build/interop/_framework/System.ComponentModel.wasm +0 -0
  25. package/build/interop/_framework/System.Configuration.wasm +0 -0
  26. package/build/interop/_framework/System.Console.wasm +0 -0
  27. package/build/interop/_framework/System.Core.wasm +0 -0
  28. package/build/interop/_framework/System.Data.Common.wasm +0 -0
  29. package/build/interop/_framework/System.Data.DataSetExtensions.wasm +0 -0
  30. package/build/interop/_framework/System.Data.wasm +0 -0
  31. package/build/interop/_framework/System.Diagnostics.Contracts.wasm +0 -0
  32. package/build/interop/_framework/System.Diagnostics.Debug.wasm +0 -0
  33. package/build/interop/_framework/System.Diagnostics.DiagnosticSource.wasm +0 -0
  34. package/build/interop/_framework/System.Diagnostics.FileVersionInfo.wasm +0 -0
  35. package/build/interop/_framework/System.Diagnostics.Process.wasm +0 -0
  36. package/build/interop/_framework/System.Diagnostics.StackTrace.wasm +0 -0
  37. package/build/interop/_framework/System.Diagnostics.TextWriterTraceListener.wasm +0 -0
  38. package/build/interop/_framework/System.Diagnostics.Tools.wasm +0 -0
  39. package/build/interop/_framework/System.Diagnostics.TraceSource.wasm +0 -0
  40. package/build/interop/_framework/System.Diagnostics.Tracing.wasm +0 -0
  41. package/build/interop/_framework/System.Drawing.Primitives.wasm +0 -0
  42. package/build/interop/_framework/System.Drawing.wasm +0 -0
  43. package/build/interop/_framework/System.Dynamic.Runtime.wasm +0 -0
  44. package/build/interop/_framework/System.Formats.Asn1.wasm +0 -0
  45. package/build/interop/_framework/System.Formats.Tar.wasm +0 -0
  46. package/build/interop/_framework/System.Globalization.Calendars.wasm +0 -0
  47. package/build/interop/_framework/System.Globalization.Extensions.wasm +0 -0
  48. package/build/interop/_framework/System.Globalization.wasm +0 -0
  49. package/build/interop/_framework/System.IO.Compression.Brotli.wasm +0 -0
  50. package/build/interop/_framework/System.IO.Compression.FileSystem.wasm +0 -0
  51. package/build/interop/_framework/System.IO.Compression.ZipFile.wasm +0 -0
  52. package/build/interop/_framework/System.IO.Compression.wasm +0 -0
  53. package/build/interop/_framework/System.IO.FileSystem.AccessControl.wasm +0 -0
  54. package/build/interop/_framework/System.IO.FileSystem.DriveInfo.wasm +0 -0
  55. package/build/interop/_framework/System.IO.FileSystem.Primitives.wasm +0 -0
  56. package/build/interop/_framework/System.IO.FileSystem.Watcher.wasm +0 -0
  57. package/build/interop/_framework/System.IO.FileSystem.wasm +0 -0
  58. package/build/interop/_framework/System.IO.IsolatedStorage.wasm +0 -0
  59. package/build/interop/_framework/System.IO.MemoryMappedFiles.wasm +0 -0
  60. package/build/interop/_framework/System.IO.Pipes.AccessControl.wasm +0 -0
  61. package/build/interop/_framework/System.IO.Pipes.wasm +0 -0
  62. package/build/interop/_framework/System.IO.UnmanagedMemoryStream.wasm +0 -0
  63. package/build/interop/_framework/System.IO.wasm +0 -0
  64. package/build/interop/_framework/System.Linq.Expressions.wasm +0 -0
  65. package/build/interop/_framework/System.Linq.Parallel.wasm +0 -0
  66. package/build/interop/_framework/System.Linq.Queryable.wasm +0 -0
  67. package/build/interop/_framework/System.Linq.wasm +0 -0
  68. package/build/interop/_framework/System.Memory.wasm +0 -0
  69. package/build/interop/_framework/System.Net.Http.Json.wasm +0 -0
  70. package/build/interop/_framework/System.Net.Http.wasm +0 -0
  71. package/build/interop/_framework/System.Net.HttpListener.wasm +0 -0
  72. package/build/interop/_framework/System.Net.Mail.wasm +0 -0
  73. package/build/interop/_framework/System.Net.NameResolution.wasm +0 -0
  74. package/build/interop/_framework/System.Net.NetworkInformation.wasm +0 -0
  75. package/build/interop/_framework/System.Net.Ping.wasm +0 -0
  76. package/build/interop/_framework/System.Net.Primitives.wasm +0 -0
  77. package/build/interop/_framework/System.Net.Quic.wasm +0 -0
  78. package/build/interop/_framework/System.Net.Requests.wasm +0 -0
  79. package/build/interop/_framework/System.Net.Security.wasm +0 -0
  80. package/build/interop/_framework/System.Net.ServicePoint.wasm +0 -0
  81. package/build/interop/_framework/System.Net.Sockets.wasm +0 -0
  82. package/build/interop/_framework/System.Net.WebClient.wasm +0 -0
  83. package/build/interop/_framework/System.Net.WebHeaderCollection.wasm +0 -0
  84. package/build/interop/_framework/System.Net.WebProxy.wasm +0 -0
  85. package/build/interop/_framework/System.Net.WebSockets.Client.wasm +0 -0
  86. package/build/interop/_framework/System.Net.WebSockets.wasm +0 -0
  87. package/build/interop/_framework/System.Net.wasm +0 -0
  88. package/build/interop/_framework/System.Numerics.Vectors.wasm +0 -0
  89. package/build/interop/_framework/System.Numerics.wasm +0 -0
  90. package/build/interop/_framework/System.ObjectModel.wasm +0 -0
  91. package/build/interop/_framework/System.Private.CoreLib.wasm +0 -0
  92. package/build/interop/_framework/System.Private.DataContractSerialization.wasm +0 -0
  93. package/build/interop/_framework/System.Private.Uri.wasm +0 -0
  94. package/build/interop/_framework/System.Private.Xml.Linq.wasm +0 -0
  95. package/build/interop/_framework/System.Private.Xml.wasm +0 -0
  96. package/build/interop/_framework/System.Reflection.DispatchProxy.wasm +0 -0
  97. package/build/interop/_framework/System.Reflection.Emit.ILGeneration.wasm +0 -0
  98. package/build/interop/_framework/System.Reflection.Emit.Lightweight.wasm +0 -0
  99. package/build/interop/_framework/System.Reflection.Emit.wasm +0 -0
  100. package/build/interop/_framework/System.Reflection.Extensions.wasm +0 -0
  101. package/build/interop/_framework/System.Reflection.Metadata.wasm +0 -0
  102. package/build/interop/_framework/System.Reflection.Primitives.wasm +0 -0
  103. package/build/interop/_framework/System.Reflection.TypeExtensions.wasm +0 -0
  104. package/build/interop/_framework/System.Reflection.wasm +0 -0
  105. package/build/interop/_framework/System.Resources.Reader.wasm +0 -0
  106. package/build/interop/_framework/System.Resources.ResourceManager.wasm +0 -0
  107. package/build/interop/_framework/System.Resources.Writer.wasm +0 -0
  108. package/build/interop/_framework/System.Runtime.CompilerServices.Unsafe.wasm +0 -0
  109. package/build/interop/_framework/System.Runtime.CompilerServices.VisualC.wasm +0 -0
  110. package/build/interop/_framework/System.Runtime.Extensions.wasm +0 -0
  111. package/build/interop/_framework/System.Runtime.Handles.wasm +0 -0
  112. package/build/interop/_framework/System.Runtime.InteropServices.JavaScript.wasm +0 -0
  113. package/build/interop/_framework/System.Runtime.InteropServices.RuntimeInformation.wasm +0 -0
  114. package/build/interop/_framework/System.Runtime.InteropServices.wasm +0 -0
  115. package/build/interop/_framework/System.Runtime.Intrinsics.wasm +0 -0
  116. package/build/interop/_framework/System.Runtime.Loader.wasm +0 -0
  117. package/build/interop/_framework/System.Runtime.Numerics.wasm +0 -0
  118. package/build/interop/_framework/System.Runtime.Serialization.Formatters.wasm +0 -0
  119. package/build/interop/_framework/System.Runtime.Serialization.Json.wasm +0 -0
  120. package/build/interop/_framework/System.Runtime.Serialization.Primitives.wasm +0 -0
  121. package/build/interop/_framework/System.Runtime.Serialization.Xml.wasm +0 -0
  122. package/build/interop/_framework/System.Runtime.Serialization.wasm +0 -0
  123. package/build/interop/_framework/System.Runtime.wasm +0 -0
  124. package/build/interop/_framework/System.Security.AccessControl.wasm +0 -0
  125. package/build/interop/_framework/System.Security.Claims.wasm +0 -0
  126. package/build/interop/_framework/System.Security.Cryptography.Algorithms.wasm +0 -0
  127. package/build/interop/_framework/System.Security.Cryptography.Cng.wasm +0 -0
  128. package/build/interop/_framework/System.Security.Cryptography.Csp.wasm +0 -0
  129. package/build/interop/_framework/System.Security.Cryptography.Encoding.wasm +0 -0
  130. package/build/interop/_framework/System.Security.Cryptography.OpenSsl.wasm +0 -0
  131. package/build/interop/_framework/System.Security.Cryptography.Primitives.wasm +0 -0
  132. package/build/interop/_framework/System.Security.Cryptography.X509Certificates.wasm +0 -0
  133. package/build/interop/_framework/System.Security.Cryptography.wasm +0 -0
  134. package/build/interop/_framework/System.Security.Principal.Windows.wasm +0 -0
  135. package/build/interop/_framework/System.Security.Principal.wasm +0 -0
  136. package/build/interop/_framework/System.Security.SecureString.wasm +0 -0
  137. package/build/interop/_framework/System.Security.wasm +0 -0
  138. package/build/interop/_framework/System.ServiceModel.Web.wasm +0 -0
  139. package/build/interop/_framework/System.ServiceProcess.wasm +0 -0
  140. package/build/interop/_framework/System.Text.Encoding.CodePages.wasm +0 -0
  141. package/build/interop/_framework/System.Text.Encoding.Extensions.wasm +0 -0
  142. package/build/interop/_framework/System.Text.Encoding.wasm +0 -0
  143. package/build/interop/_framework/System.Text.Encodings.Web.wasm +0 -0
  144. package/build/interop/_framework/System.Text.Json.wasm +0 -0
  145. package/build/interop/_framework/System.Text.RegularExpressions.wasm +0 -0
  146. package/build/interop/_framework/System.Threading.Channels.wasm +0 -0
  147. package/build/interop/_framework/System.Threading.Overlapped.wasm +0 -0
  148. package/build/interop/_framework/System.Threading.Tasks.Dataflow.wasm +0 -0
  149. package/build/interop/_framework/System.Threading.Tasks.Extensions.wasm +0 -0
  150. package/build/interop/_framework/System.Threading.Tasks.Parallel.wasm +0 -0
  151. package/build/interop/_framework/System.Threading.Tasks.wasm +0 -0
  152. package/build/interop/_framework/System.Threading.Thread.wasm +0 -0
  153. package/build/interop/_framework/System.Threading.ThreadPool.wasm +0 -0
  154. package/build/interop/_framework/System.Threading.Timer.wasm +0 -0
  155. package/build/interop/_framework/System.Threading.wasm +0 -0
  156. package/build/interop/_framework/System.Transactions.Local.wasm +0 -0
  157. package/build/interop/_framework/System.Transactions.wasm +0 -0
  158. package/build/interop/_framework/System.ValueTuple.wasm +0 -0
  159. package/build/interop/_framework/System.Web.HttpUtility.wasm +0 -0
  160. package/build/interop/_framework/System.Web.wasm +0 -0
  161. package/build/interop/_framework/System.Windows.wasm +0 -0
  162. package/build/interop/_framework/System.Xml.Linq.wasm +0 -0
  163. package/build/interop/_framework/System.Xml.ReaderWriter.wasm +0 -0
  164. package/build/interop/_framework/System.Xml.Serialization.wasm +0 -0
  165. package/build/interop/_framework/System.Xml.XDocument.wasm +0 -0
  166. package/build/interop/_framework/System.Xml.XPath.XDocument.wasm +0 -0
  167. package/build/interop/_framework/System.Xml.XPath.wasm +0 -0
  168. package/build/interop/_framework/System.Xml.XmlDocument.wasm +0 -0
  169. package/build/interop/_framework/System.Xml.XmlSerializer.wasm +0 -0
  170. package/build/interop/_framework/System.Xml.wasm +0 -0
  171. package/build/interop/_framework/System.wasm +0 -0
  172. package/build/interop/_framework/WindowsBase.wasm +0 -0
  173. package/build/interop/_framework/blazor.boot.json +174 -174
  174. package/build/interop/_framework/dotnet.js +1 -1
  175. package/build/interop/_framework/dotnet.js.map +1 -1
  176. package/build/interop/_framework/dotnet.native.js +1 -1
  177. package/build/interop/_framework/dotnet.native.wasm +0 -0
  178. package/build/interop/_framework/dotnet.runtime.js +1 -1
  179. package/build/interop/_framework/dotnet.runtime.js.map +1 -1
  180. package/build/interop/_framework/mscorlib.wasm +0 -0
  181. package/build/interop/_framework/netstandard.wasm +0 -0
  182. package/package.json +5 -5
package/build/index.d.ts CHANGED
@@ -4,5 +4,6 @@ export type * from '../types/DtdlErr.d.ts';
4
4
  export type * from '../types/DtdlOm.d.ts';
5
5
  export { getInterop } from './interop.js';
6
6
  export declare const searchForJsonFiles: (directory: string) => string[];
7
+ export declare const parseDtdl: (json: string, parserModule: Parser) => DtdlObjectModel | null;
7
8
  export declare const validateDirectories: (directory: string, parser: Parser, incResolutionException: boolean) => boolean;
8
9
  export declare const parseDirectories: (directory: string, parser: Parser) => DtdlObjectModel | null;
package/build/index.js CHANGED
@@ -27,9 +27,10 @@ let i = (r)=>{
27
27
  if (!a && l(e)) return n(`Successfully validated '${r}'`), !0;
28
28
  return s(`Error parsing '${r}'`), t(e), !1;
29
29
  }
30
- }, u = (e, r)=>{
30
+ };
31
+ export const parseDtdl = (e, r)=>{
31
32
  try {
32
- let t = JSON.parse(r.parse(JSON.stringify(e)));
33
+ let t = JSON.parse(r.parse(e));
33
34
  return n("Successfully parsed"), t;
34
35
  } catch (e) {
35
36
  return s("Error parsing"), t(e), null;
@@ -49,7 +50,7 @@ export const parseDirectories = (e, r)=>{
49
50
  n(`Found ${t.length} files:`), n(t);
50
51
  let l = a(t);
51
52
  if (null === l) return null;
52
- let s = u(l, r);
53
+ let s = parseDtdl(JSON.stringify(l), r);
53
54
  if (null === s) return null;
54
55
  n(`All files parsed!\n`), n("Entities:"), n(Object.keys(s));
55
56
  let i = Object.values(s).filter((e)=>'Interface' === e.EntityKind);
@@ -1 +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,QAA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IAE/BzC,EAAI,CAAC,mBAAmB,CAAC,GACzBA,EAAI,cACJA,EAAI0C,OAAOC,IAAI,CAACF;IAGhB,IAAMG,IAA8BF,OAAOG,MAAM,CAACJ,GAAWK,MAAM,CACjE,CAACC,IAAkCA,AAAqB,gBAArBA,EAAMC,UAAU;IAIrD,OAFAhD,EAAI,CAAC,sBAAsB,EAAE4C,EAAWN,MAAM,EAAE,GAEzCG;AACT,EAAC"}
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\nexport const parseDtdl = (json: string, parserModule: Parser): DtdlObjectModel | null => {\n try {\n const model = JSON.parse(parserModule.parse(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(JSON.stringify(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","validateDirectories","parser","parserVersion","length","parseDirectories","fullJson","fullModel","stringify","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,CAAC,GACpC,EAAE,EAcZ;AAED,IAAMa,IAAe,CAACC;IACpB,IAAI;QACF,IAAMV,IAAOb,EAAGwB,YAAY,CAACD,GAAU;QAEvC,OADaE,KAAKC,KAAK,CAACb;IAE1B,EAAE,OAAOc,GAAK;QAGZ,OAFAtB,EAAM,CAAC,iBAAiB,EAAEkB,EAAS,CAAC,CAAC,GACrClB,EAAMsB,IACC;IACT;AACF,GAEMC,IAAc,CAACC;IACnB,IAAMC,IAA0B,EAAE;IAElC,KAAK,IAAMP,KAAYM,EAAW;QAChC,IAAME,IAAOT,EAAaC;QAC1B,IAAIQ,AAAS,SAATA,GACF,OAAO;QAETD,EAAaE,IAAI,CAACD;IACpB;IAEA,OAAOD;AACT,GAEMG,IAAe,CAACV,G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