@typemf/node 0.6.0 → 0.8.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.
package/dist/index.cjs CHANGED
@@ -27,6 +27,7 @@ module.exports = __toCommonJS(index_exports);
27
27
  // src/node-file-uri-converter.ts
28
28
  var import_promises = require("fs/promises");
29
29
  var import_node_path = require("path");
30
+ var import_node_url = require("url");
30
31
  var NodeFileUriConverter = class {
31
32
  canHandle(uri) {
32
33
  return uri.getScheme() === "file";
@@ -49,11 +50,21 @@ var NodeFileUriConverter = class {
49
50
  return false;
50
51
  }
51
52
  }
53
+ /**
54
+ * A URI's own `getPath()` is unusable directly as a filesystem path on every
55
+ * platform/caller combination - a URI built from a Windows `fsPath` ("c:\Users\...") has a
56
+ * `path` of "/c:\Users\..." (createFileURI only ever prepends "/"; it doesn't know about drive
57
+ * letters or backslashes), and a URI parsed from real "file:" text keeps its percent-encoding
58
+ * ("a%20b") rather than decoding it. `fileURLToPath` is Node's own, already-correct, per-platform
59
+ * answer to exactly this problem - it treats backslashes as path separators (the WHATWG URL
60
+ * parser does this for every "special" scheme, "file" included) and decodes percent-escapes -
61
+ * so this converts through it instead of reading `getPath()` by hand.
62
+ */
52
63
  pathFor(uri) {
53
64
  if (uri.getScheme() !== "file") {
54
65
  throw new Error(`NodeFileUriConverter cannot handle scheme '${uri.getScheme()}' (only 'file').`);
55
66
  }
56
- return uri.trimFragment().getPath();
67
+ return (0, import_node_url.fileURLToPath)(uri.trimFragment().toString());
57
68
  }
58
69
  };
59
70
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/node-file-uri-converter.ts"],"sourcesContent":["export * from './node-file-uri-converter.js';\n","import { URI, UriConverter } from '@typemf/core';\nimport { access, mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname } from 'node:path';\n\n/**\n * The Node-only, fs-backed UriConverter discussed back when @typemf/core's\n * resource/ layer was designed: it exists as its own package specifically\n * so that nothing shipping to a browser bundle ever pulls in Node's `fs`\n * module, and so a consumer wanting only the in-memory or a fetch()-based\n * converter never needs this one at all.\n *\n * Handles the \"file\" URI scheme only. Register it into a ResourceSet's\n * UriConverterRegistry alongside any other converter for other schemes -\n * see the \"browser could load an https:// XMI file without fs access\"\n * discussion for why this is a registry rather than a single slot.\n */\nexport class NodeFileUriConverter implements UriConverter {\n canHandle(uri: URI): boolean {\n return uri.getScheme() === 'file';\n }\n\n async readBinary(uri: URI): Promise<Uint8Array> {\n const path = this.pathFor(uri);\n const buffer = await readFile(path);\n return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n }\n\n async writeBinary(uri: URI, content: Uint8Array): Promise<void> {\n const path = this.pathFor(uri);\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, content);\n }\n\n async exists(uri: URI): Promise<boolean> {\n try {\n await access(this.pathFor(uri));\n return true;\n } catch {\n return false;\n }\n }\n\n private pathFor(uri: URI): string {\n if (uri.getScheme() !== 'file') {\n throw new Error(`NodeFileUriConverter cannot handle scheme '${uri.getScheme()}' (only 'file').`);\n }\n return uri.trimFragment().getPath();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,sBAAmD;AACnD,uBAAwB;AAcjB,IAAM,uBAAN,MAAmD;AAAA,EACxD,UAAU,KAAmB;AAC3B,WAAO,IAAI,UAAU,MAAM;AAAA,EAC7B;AAAA,EAEA,MAAM,WAAW,KAA+B;AAC9C,UAAM,OAAO,KAAK,QAAQ,GAAG;AAC7B,UAAM,SAAS,UAAM,0BAAS,IAAI;AAClC,WAAO,IAAI,WAAW,OAAO,QAAQ,OAAO,YAAY,OAAO,UAAU;AAAA,EAC3E;AAAA,EAEA,MAAM,YAAY,KAAU,SAAoC;AAC9D,UAAM,OAAO,KAAK,QAAQ,GAAG;AAC7B,cAAM,2BAAM,0BAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC9C,cAAM,2BAAU,MAAM,OAAO;AAAA,EAC/B;AAAA,EAEA,MAAM,OAAO,KAA4B;AACvC,QAAI;AACF,gBAAM,wBAAO,KAAK,QAAQ,GAAG,CAAC;AAC9B,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEQ,QAAQ,KAAkB;AAChC,QAAI,IAAI,UAAU,MAAM,QAAQ;AAC9B,YAAM,IAAI,MAAM,8CAA8C,IAAI,UAAU,CAAC,kBAAkB;AAAA,IACjG;AACA,WAAO,IAAI,aAAa,EAAE,QAAQ;AAAA,EACpC;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/node-file-uri-converter.ts"],"sourcesContent":["export * from './node-file-uri-converter.js';\n","import { URI, UriConverter } from '@typemf/core';\nimport { access, mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\n/**\n * The Node-only, fs-backed UriConverter discussed back when @typemf/core's\n * resource/ layer was designed: it exists as its own package specifically\n * so that nothing shipping to a browser bundle ever pulls in Node's `fs`\n * module, and so a consumer wanting only the in-memory or a fetch()-based\n * converter never needs this one at all.\n *\n * Handles the \"file\" URI scheme only. Register it into a ResourceSet's\n * UriConverterRegistry alongside any other converter for other schemes -\n * see the \"browser could load an https:// XMI file without fs access\"\n * discussion for why this is a registry rather than a single slot.\n */\nexport class NodeFileUriConverter implements UriConverter {\n canHandle(uri: URI): boolean {\n return uri.getScheme() === 'file';\n }\n\n async readBinary(uri: URI): Promise<Uint8Array> {\n const path = this.pathFor(uri);\n const buffer = await readFile(path);\n return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n }\n\n async writeBinary(uri: URI, content: Uint8Array): Promise<void> {\n const path = this.pathFor(uri);\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, content);\n }\n\n async exists(uri: URI): Promise<boolean> {\n try {\n await access(this.pathFor(uri));\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * A URI's own `getPath()` is unusable directly as a filesystem path on every\n * platform/caller combination - a URI built from a Windows `fsPath` (\"c:\\Users\\...\") has a\n * `path` of \"/c:\\Users\\...\" (createFileURI only ever prepends \"/\"; it doesn't know about drive\n * letters or backslashes), and a URI parsed from real \"file:\" text keeps its percent-encoding\n * (\"a%20b\") rather than decoding it. `fileURLToPath` is Node's own, already-correct, per-platform\n * answer to exactly this problem - it treats backslashes as path separators (the WHATWG URL\n * parser does this for every \"special\" scheme, \"file\" included) and decodes percent-escapes -\n * so this converts through it instead of reading `getPath()` by hand.\n */\n private pathFor(uri: URI): string {\n if (uri.getScheme() !== 'file') {\n throw new Error(`NodeFileUriConverter cannot handle scheme '${uri.getScheme()}' (only 'file').`);\n }\n return fileURLToPath(uri.trimFragment().toString());\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,sBAAmD;AACnD,uBAAwB;AACxB,sBAA8B;AAcvB,IAAM,uBAAN,MAAmD;AAAA,EACxD,UAAU,KAAmB;AAC3B,WAAO,IAAI,UAAU,MAAM;AAAA,EAC7B;AAAA,EAEA,MAAM,WAAW,KAA+B;AAC9C,UAAM,OAAO,KAAK,QAAQ,GAAG;AAC7B,UAAM,SAAS,UAAM,0BAAS,IAAI;AAClC,WAAO,IAAI,WAAW,OAAO,QAAQ,OAAO,YAAY,OAAO,UAAU;AAAA,EAC3E;AAAA,EAEA,MAAM,YAAY,KAAU,SAAoC;AAC9D,UAAM,OAAO,KAAK,QAAQ,GAAG;AAC7B,cAAM,2BAAM,0BAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC9C,cAAM,2BAAU,MAAM,OAAO;AAAA,EAC/B;AAAA,EAEA,MAAM,OAAO,KAA4B;AACvC,QAAI;AACF,gBAAM,wBAAO,KAAK,QAAQ,GAAG,CAAC;AAC9B,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYQ,QAAQ,KAAkB;AAChC,QAAI,IAAI,UAAU,MAAM,QAAQ;AAC9B,YAAM,IAAI,MAAM,8CAA8C,IAAI,UAAU,CAAC,kBAAkB;AAAA,IACjG;AACA,eAAO,+BAAc,IAAI,aAAa,EAAE,SAAS,CAAC;AAAA,EACpD;AACF;","names":[]}
package/dist/index.d.cts CHANGED
@@ -17,6 +17,16 @@ declare class NodeFileUriConverter implements UriConverter {
17
17
  readBinary(uri: URI): Promise<Uint8Array>;
18
18
  writeBinary(uri: URI, content: Uint8Array): Promise<void>;
19
19
  exists(uri: URI): Promise<boolean>;
20
+ /**
21
+ * A URI's own `getPath()` is unusable directly as a filesystem path on every
22
+ * platform/caller combination - a URI built from a Windows `fsPath` ("c:\Users\...") has a
23
+ * `path` of "/c:\Users\..." (createFileURI only ever prepends "/"; it doesn't know about drive
24
+ * letters or backslashes), and a URI parsed from real "file:" text keeps its percent-encoding
25
+ * ("a%20b") rather than decoding it. `fileURLToPath` is Node's own, already-correct, per-platform
26
+ * answer to exactly this problem - it treats backslashes as path separators (the WHATWG URL
27
+ * parser does this for every "special" scheme, "file" included) and decodes percent-escapes -
28
+ * so this converts through it instead of reading `getPath()` by hand.
29
+ */
20
30
  private pathFor;
21
31
  }
22
32
 
package/dist/index.d.ts CHANGED
@@ -17,6 +17,16 @@ declare class NodeFileUriConverter implements UriConverter {
17
17
  readBinary(uri: URI): Promise<Uint8Array>;
18
18
  writeBinary(uri: URI, content: Uint8Array): Promise<void>;
19
19
  exists(uri: URI): Promise<boolean>;
20
+ /**
21
+ * A URI's own `getPath()` is unusable directly as a filesystem path on every
22
+ * platform/caller combination - a URI built from a Windows `fsPath` ("c:\Users\...") has a
23
+ * `path` of "/c:\Users\..." (createFileURI only ever prepends "/"; it doesn't know about drive
24
+ * letters or backslashes), and a URI parsed from real "file:" text keeps its percent-encoding
25
+ * ("a%20b") rather than decoding it. `fileURLToPath` is Node's own, already-correct, per-platform
26
+ * answer to exactly this problem - it treats backslashes as path separators (the WHATWG URL
27
+ * parser does this for every "special" scheme, "file" included) and decodes percent-escapes -
28
+ * so this converts through it instead of reading `getPath()` by hand.
29
+ */
20
30
  private pathFor;
21
31
  }
22
32
 
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/node-file-uri-converter.ts
2
2
  import { access, mkdir, readFile, writeFile } from "fs/promises";
3
3
  import { dirname } from "path";
4
+ import { fileURLToPath } from "url";
4
5
  var NodeFileUriConverter = class {
5
6
  canHandle(uri) {
6
7
  return uri.getScheme() === "file";
@@ -23,11 +24,21 @@ var NodeFileUriConverter = class {
23
24
  return false;
24
25
  }
25
26
  }
27
+ /**
28
+ * A URI's own `getPath()` is unusable directly as a filesystem path on every
29
+ * platform/caller combination - a URI built from a Windows `fsPath` ("c:\Users\...") has a
30
+ * `path` of "/c:\Users\..." (createFileURI only ever prepends "/"; it doesn't know about drive
31
+ * letters or backslashes), and a URI parsed from real "file:" text keeps its percent-encoding
32
+ * ("a%20b") rather than decoding it. `fileURLToPath` is Node's own, already-correct, per-platform
33
+ * answer to exactly this problem - it treats backslashes as path separators (the WHATWG URL
34
+ * parser does this for every "special" scheme, "file" included) and decodes percent-escapes -
35
+ * so this converts through it instead of reading `getPath()` by hand.
36
+ */
26
37
  pathFor(uri) {
27
38
  if (uri.getScheme() !== "file") {
28
39
  throw new Error(`NodeFileUriConverter cannot handle scheme '${uri.getScheme()}' (only 'file').`);
29
40
  }
30
- return uri.trimFragment().getPath();
41
+ return fileURLToPath(uri.trimFragment().toString());
31
42
  }
32
43
  };
33
44
  export {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/node-file-uri-converter.ts"],"sourcesContent":["import { URI, UriConverter } from '@typemf/core';\nimport { access, mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname } from 'node:path';\n\n/**\n * The Node-only, fs-backed UriConverter discussed back when @typemf/core's\n * resource/ layer was designed: it exists as its own package specifically\n * so that nothing shipping to a browser bundle ever pulls in Node's `fs`\n * module, and so a consumer wanting only the in-memory or a fetch()-based\n * converter never needs this one at all.\n *\n * Handles the \"file\" URI scheme only. Register it into a ResourceSet's\n * UriConverterRegistry alongside any other converter for other schemes -\n * see the \"browser could load an https:// XMI file without fs access\"\n * discussion for why this is a registry rather than a single slot.\n */\nexport class NodeFileUriConverter implements UriConverter {\n canHandle(uri: URI): boolean {\n return uri.getScheme() === 'file';\n }\n\n async readBinary(uri: URI): Promise<Uint8Array> {\n const path = this.pathFor(uri);\n const buffer = await readFile(path);\n return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n }\n\n async writeBinary(uri: URI, content: Uint8Array): Promise<void> {\n const path = this.pathFor(uri);\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, content);\n }\n\n async exists(uri: URI): Promise<boolean> {\n try {\n await access(this.pathFor(uri));\n return true;\n } catch {\n return false;\n }\n }\n\n private pathFor(uri: URI): string {\n if (uri.getScheme() !== 'file') {\n throw new Error(`NodeFileUriConverter cannot handle scheme '${uri.getScheme()}' (only 'file').`);\n }\n return uri.trimFragment().getPath();\n }\n}\n"],"mappings":";AACA,SAAS,QAAQ,OAAO,UAAU,iBAAiB;AACnD,SAAS,eAAe;AAcjB,IAAM,uBAAN,MAAmD;AAAA,EACxD,UAAU,KAAmB;AAC3B,WAAO,IAAI,UAAU,MAAM;AAAA,EAC7B;AAAA,EAEA,MAAM,WAAW,KAA+B;AAC9C,UAAM,OAAO,KAAK,QAAQ,GAAG;AAC7B,UAAM,SAAS,MAAM,SAAS,IAAI;AAClC,WAAO,IAAI,WAAW,OAAO,QAAQ,OAAO,YAAY,OAAO,UAAU;AAAA,EAC3E;AAAA,EAEA,MAAM,YAAY,KAAU,SAAoC;AAC9D,UAAM,OAAO,KAAK,QAAQ,GAAG;AAC7B,UAAM,MAAM,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC9C,UAAM,UAAU,MAAM,OAAO;AAAA,EAC/B;AAAA,EAEA,MAAM,OAAO,KAA4B;AACvC,QAAI;AACF,YAAM,OAAO,KAAK,QAAQ,GAAG,CAAC;AAC9B,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEQ,QAAQ,KAAkB;AAChC,QAAI,IAAI,UAAU,MAAM,QAAQ;AAC9B,YAAM,IAAI,MAAM,8CAA8C,IAAI,UAAU,CAAC,kBAAkB;AAAA,IACjG;AACA,WAAO,IAAI,aAAa,EAAE,QAAQ;AAAA,EACpC;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/node-file-uri-converter.ts"],"sourcesContent":["import { URI, UriConverter } from '@typemf/core';\nimport { access, mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\n/**\n * The Node-only, fs-backed UriConverter discussed back when @typemf/core's\n * resource/ layer was designed: it exists as its own package specifically\n * so that nothing shipping to a browser bundle ever pulls in Node's `fs`\n * module, and so a consumer wanting only the in-memory or a fetch()-based\n * converter never needs this one at all.\n *\n * Handles the \"file\" URI scheme only. Register it into a ResourceSet's\n * UriConverterRegistry alongside any other converter for other schemes -\n * see the \"browser could load an https:// XMI file without fs access\"\n * discussion for why this is a registry rather than a single slot.\n */\nexport class NodeFileUriConverter implements UriConverter {\n canHandle(uri: URI): boolean {\n return uri.getScheme() === 'file';\n }\n\n async readBinary(uri: URI): Promise<Uint8Array> {\n const path = this.pathFor(uri);\n const buffer = await readFile(path);\n return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n }\n\n async writeBinary(uri: URI, content: Uint8Array): Promise<void> {\n const path = this.pathFor(uri);\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, content);\n }\n\n async exists(uri: URI): Promise<boolean> {\n try {\n await access(this.pathFor(uri));\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * A URI's own `getPath()` is unusable directly as a filesystem path on every\n * platform/caller combination - a URI built from a Windows `fsPath` (\"c:\\Users\\...\") has a\n * `path` of \"/c:\\Users\\...\" (createFileURI only ever prepends \"/\"; it doesn't know about drive\n * letters or backslashes), and a URI parsed from real \"file:\" text keeps its percent-encoding\n * (\"a%20b\") rather than decoding it. `fileURLToPath` is Node's own, already-correct, per-platform\n * answer to exactly this problem - it treats backslashes as path separators (the WHATWG URL\n * parser does this for every \"special\" scheme, \"file\" included) and decodes percent-escapes -\n * so this converts through it instead of reading `getPath()` by hand.\n */\n private pathFor(uri: URI): string {\n if (uri.getScheme() !== 'file') {\n throw new Error(`NodeFileUriConverter cannot handle scheme '${uri.getScheme()}' (only 'file').`);\n }\n return fileURLToPath(uri.trimFragment().toString());\n }\n}\n"],"mappings":";AACA,SAAS,QAAQ,OAAO,UAAU,iBAAiB;AACnD,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAcvB,IAAM,uBAAN,MAAmD;AAAA,EACxD,UAAU,KAAmB;AAC3B,WAAO,IAAI,UAAU,MAAM;AAAA,EAC7B;AAAA,EAEA,MAAM,WAAW,KAA+B;AAC9C,UAAM,OAAO,KAAK,QAAQ,GAAG;AAC7B,UAAM,SAAS,MAAM,SAAS,IAAI;AAClC,WAAO,IAAI,WAAW,OAAO,QAAQ,OAAO,YAAY,OAAO,UAAU;AAAA,EAC3E;AAAA,EAEA,MAAM,YAAY,KAAU,SAAoC;AAC9D,UAAM,OAAO,KAAK,QAAQ,GAAG;AAC7B,UAAM,MAAM,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC9C,UAAM,UAAU,MAAM,OAAO;AAAA,EAC/B;AAAA,EAEA,MAAM,OAAO,KAA4B;AACvC,QAAI;AACF,YAAM,OAAO,KAAK,QAAQ,GAAG,CAAC;AAC9B,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYQ,QAAQ,KAAkB;AAChC,QAAI,IAAI,UAAU,MAAM,QAAQ;AAC9B,YAAM,IAAI,MAAM,8CAA8C,IAAI,UAAU,CAAC,kBAAkB;AAAA,IACjG;AACA,WAAO,cAAc,IAAI,aAAa,EAAE,SAAS,CAAC;AAAA,EACpD;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typemf/node",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -27,12 +27,12 @@
27
27
  "provenance": true
28
28
  },
29
29
  "devDependencies": {
30
- "@typemf/core": "0.6.0",
31
- "@typemf/json": "0.6.0",
32
- "@typemf/xmi": "0.6.0"
30
+ "@typemf/core": "0.8.0",
31
+ "@typemf/json": "0.8.0",
32
+ "@typemf/xmi": "0.8.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "@typemf/core": "^0.6.0"
35
+ "@typemf/core": "^0.8.0"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "tsc -p tsconfig.json --noEmit && tsup",