@chrtco/sdk 0.4.1 → 0.6.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.
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/node/index.ts
21
+ var node_exports = {};
22
+ __export(node_exports, {
23
+ nodeFileSystemAdapter: () => nodeFileSystemAdapter
24
+ });
25
+ module.exports = __toCommonJS(node_exports);
26
+
27
+ // src/node/fs-adapter.ts
28
+ var import_node_fs = require("fs");
29
+ var import_promises = require("fs/promises");
30
+ var import_node_stream = require("stream");
31
+ var import_node_crypto = require("crypto");
32
+ function nodeFileSystemAdapter() {
33
+ return {
34
+ async exists(path) {
35
+ try {
36
+ await (0, import_promises.stat)(path);
37
+ return true;
38
+ } catch (err) {
39
+ if (isNotFound(err)) return false;
40
+ throw err;
41
+ }
42
+ },
43
+ async stat(path) {
44
+ const s = await (0, import_promises.stat)(path);
45
+ return { size: s.size };
46
+ },
47
+ async writeStream(path, opts) {
48
+ const node = (0, import_node_fs.createWriteStream)(path, { flags: opts?.append ? "a" : "w" });
49
+ return import_node_stream.Writable.toWeb(node);
50
+ },
51
+ async rename(from, to) {
52
+ await (0, import_promises.rename)(from, to);
53
+ },
54
+ async unlink(path) {
55
+ try {
56
+ await (0, import_promises.unlink)(path);
57
+ } catch (err) {
58
+ if (isNotFound(err)) return;
59
+ throw err;
60
+ }
61
+ },
62
+ async mkdir(path, opts) {
63
+ await (0, import_promises.mkdir)(path, { recursive: opts?.recursive ?? false });
64
+ },
65
+ async readFile(path) {
66
+ const buf = await (0, import_promises.readFile)(path);
67
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
68
+ },
69
+ async writeFile(path, data) {
70
+ await (0, import_promises.writeFile)(path, data);
71
+ },
72
+ async sha256(path) {
73
+ return new Promise((resolve, reject) => {
74
+ const hash = (0, import_node_crypto.createHash)("sha256");
75
+ const stream = (0, import_node_fs.createReadStream)(path);
76
+ stream.on("data", (chunk) => hash.update(chunk));
77
+ stream.on("end", () => resolve(hash.digest("hex")));
78
+ stream.on("error", reject);
79
+ });
80
+ }
81
+ };
82
+ }
83
+ function isNotFound(err) {
84
+ return !!(err && typeof err === "object" && "code" in err && err.code === "ENOENT");
85
+ }
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ nodeFileSystemAdapter
89
+ });
90
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/node/index.ts","../../src/node/fs-adapter.ts"],"sourcesContent":["/**\n * Node 18+ sub-export: `import { nodeFileSystemAdapter } from '@chrtco/sdk/node'`.\n *\n * This module imports `node:*` — do not re-export it from the root `index.ts`\n * or you'll pull `node:fs` into browser/Deno builds.\n */\nexport { nodeFileSystemAdapter } from \"./fs-adapter.js\";\n","/**\n * Node 18+ implementation of `FileSystemAdapter`.\n *\n * Imports are `node:*` prefixed so bundlers mark them as external cleanly and\n * core bundle consumers that never import `@chrtco/sdk/node` don't pull them\n * in. Every method uses streaming primitives so multi-GB MBTiles files don't\n * blow the heap.\n */\nimport {\n createReadStream,\n createWriteStream,\n} from \"node:fs\";\nimport { mkdir, rename, stat, unlink, readFile, writeFile } from \"node:fs/promises\";\nimport { Writable } from \"node:stream\";\nimport { createHash } from \"node:crypto\";\nimport type { FileSystemAdapter } from \"../fs-adapter.js\";\n\nexport function nodeFileSystemAdapter(): FileSystemAdapter {\n return {\n async exists(path: string): Promise<boolean> {\n try {\n await stat(path);\n return true;\n } catch (err) {\n if (isNotFound(err)) return false;\n throw err;\n }\n },\n\n async stat(path: string): Promise<{ size: number }> {\n const s = await stat(path);\n return { size: s.size };\n },\n\n async writeStream(\n path: string,\n opts?: { append?: boolean },\n ): Promise<WritableStream<Uint8Array>> {\n const node = createWriteStream(path, { flags: opts?.append ? \"a\" : \"w\" });\n return Writable.toWeb(node) as WritableStream<Uint8Array>;\n },\n\n async rename(from: string, to: string): Promise<void> {\n await rename(from, to);\n },\n\n async unlink(path: string): Promise<void> {\n try {\n await unlink(path);\n } catch (err) {\n if (isNotFound(err)) return;\n throw err;\n }\n },\n\n async mkdir(path: string, opts?: { recursive?: boolean }): Promise<void> {\n await mkdir(path, { recursive: opts?.recursive ?? false });\n },\n\n async readFile(path: string): Promise<Uint8Array> {\n const buf = await readFile(path);\n return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);\n },\n\n async writeFile(path: string, data: Uint8Array): Promise<void> {\n await writeFile(path, data);\n },\n\n async sha256(path: string): Promise<string> {\n return new Promise<string>((resolve, reject) => {\n const hash = createHash(\"sha256\");\n const stream = createReadStream(path);\n stream.on(\"data\", (chunk) => hash.update(chunk));\n stream.on(\"end\", () => resolve(hash.digest(\"hex\")));\n stream.on(\"error\", reject);\n });\n },\n };\n}\n\nfunction isNotFound(err: unknown): boolean {\n return !!(err && typeof err === \"object\" && \"code\" in err && (err as { code?: unknown }).code === \"ENOENT\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQA,qBAGO;AACP,sBAAiE;AACjE,yBAAyB;AACzB,yBAA2B;AAGpB,SAAS,wBAA2C;AACzD,SAAO;A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eAAO,GAAG,OAAO,MAAM,QAAQ,KAAK,OAAO,KAAK,CAAC,CAAC;AAClD,eAAO,GAAG,SAAS,MAAM;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,SAAS,WAAW,KAAuB;AACzC,SAAO,CAAC,EAAE,OAAO,OAAO,QAAQ,YAAY,UAAU,OAAQ,IAA2B,SAAS;AACpG;","names":[]}
@@ -0,0 +1,5 @@
1
+ import { F as FileSystemAdapter } from '../fs-adapter-D5iwdb1Q.cjs';
2
+
3
+ declare function nodeFileSystemAdapter(): FileSystemAdapter;
4
+
5
+ export { nodeFileSystemAdapter };
@@ -0,0 +1,5 @@
1
+ import { F as FileSystemAdapter } from '../fs-adapter-D5iwdb1Q.js';
2
+
3
+ declare function nodeFileSystemAdapter(): FileSystemAdapter;
4
+
5
+ export { nodeFileSystemAdapter };
@@ -0,0 +1,66 @@
1
+ // src/node/fs-adapter.ts
2
+ import {
3
+ createReadStream,
4
+ createWriteStream
5
+ } from "fs";
6
+ import { mkdir, rename, stat, unlink, readFile, writeFile } from "fs/promises";
7
+ import { Writable } from "stream";
8
+ import { createHash } from "crypto";
9
+ function nodeFileSystemAdapter() {
10
+ return {
11
+ async exists(path) {
12
+ try {
13
+ await stat(path);
14
+ return true;
15
+ } catch (err) {
16
+ if (isNotFound(err)) return false;
17
+ throw err;
18
+ }
19
+ },
20
+ async stat(path) {
21
+ const s = await stat(path);
22
+ return { size: s.size };
23
+ },
24
+ async writeStream(path, opts) {
25
+ const node = createWriteStream(path, { flags: opts?.append ? "a" : "w" });
26
+ return Writable.toWeb(node);
27
+ },
28
+ async rename(from, to) {
29
+ await rename(from, to);
30
+ },
31
+ async unlink(path) {
32
+ try {
33
+ await unlink(path);
34
+ } catch (err) {
35
+ if (isNotFound(err)) return;
36
+ throw err;
37
+ }
38
+ },
39
+ async mkdir(path, opts) {
40
+ await mkdir(path, { recursive: opts?.recursive ?? false });
41
+ },
42
+ async readFile(path) {
43
+ const buf = await readFile(path);
44
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
45
+ },
46
+ async writeFile(path, data) {
47
+ await writeFile(path, data);
48
+ },
49
+ async sha256(path) {
50
+ return new Promise((resolve, reject) => {
51
+ const hash = createHash("sha256");
52
+ const stream = createReadStream(path);
53
+ stream.on("data", (chunk) => hash.update(chunk));
54
+ stream.on("end", () => resolve(hash.digest("hex")));
55
+ stream.on("error", reject);
56
+ });
57
+ }
58
+ };
59
+ }
60
+ function isNotFound(err) {
61
+ return !!(err && typeof err === "object" && "code" in err && err.code === "ENOENT");
62
+ }
63
+ export {
64
+ nodeFileSystemAdapter
65
+ };
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/node/fs-adapter.ts"],"sourcesContent":["/**\n * Node 18+ implementation of `FileSystemAdapter`.\n *\n * Imports are `node:*` prefixed so bundlers mark them as external cleanly and\n * core bundle consumers that never import `@chrtco/sdk/node` don't pull them\n * in. Every method uses streaming primitives so multi-GB MBTiles files don't\n * blow the heap.\n */\nimport {\n createReadStream,\n createWriteStream,\n} from \"node:fs\";\nimport { mkdir, rename, stat, unlink, readFile, writeFile } from \"node:fs/promises\";\nimport { Writable } from \"node:stream\";\nimport { createHash } from \"node:crypto\";\nimport type { FileSystemAdapter } from \"../fs-adapter.js\";\n\nexport function nodeFileSystemAdapter(): FileSystemAdapter {\n return {\n async exists(path: string): Promise<boolean> {\n try {\n await stat(path);\n return true;\n } catch (err) {\n if (isNotFound(err)) return false;\n throw err;\n }\n },\n\n async stat(path: string): Promise<{ size: number }> {\n const s = await stat(path);\n return { size: s.size };\n },\n\n async writeStream(\n path: string,\n opts?: { append?: boolean },\n ): Promise<WritableStream<Uint8Array>> {\n const node = createWriteStream(path, { flags: opts?.append ? \"a\" : \"w\" });\n return Writable.toWeb(node) as WritableStream<Uint8Array>;\n },\n\n async rename(from: string, to: string): Promise<void> {\n await rename(from, to);\n },\n\n async unlink(path: string): Promise<void> {\n try {\n await unlink(path);\n } catch (err) {\n if (isNotFound(err)) return;\n throw err;\n }\n },\n\n async mkdir(path: string, opts?: { recursive?: boolean }): Promise<void> {\n await mkdir(path, { recursive: opts?.recursive ?? false });\n },\n\n async readFile(path: string): Promise<Uint8Array> {\n const buf = await readFile(path);\n return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);\n },\n\n async writeFile(path: string, data: Uint8Array): Promise<void> {\n await writeFile(path, data);\n },\n\n async sha256(path: string): Promise<string> {\n return new Promise<string>((resolve, reject) => {\n const hash = createHash(\"sha256\");\n const stream = createReadStream(path);\n stream.on(\"data\", (chunk) => hash.update(chunk));\n stream.on(\"end\", () => resolve(hash.digest(\"hex\")));\n stream.on(\"error\", reject);\n });\n },\n };\n}\n\nfunction isNotFound(err: unknown): boolean {\n return !!(err && typeof err === \"object\" && \"code\" in err && (err as { code?: unknown }).code === \"ENOENT\");\n}\n"],"mappings":";AAQA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,OAAO,QAAQ,MAAM,QAAQ,UAAU,iBAAiB;AACjE,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAGpB,SAAS,wBAA2C;AACzD,SAAO;AAAA,IACL,MAAM,OAAO,MAAgC;AAC3C,UAAI;AACF,cAAM,KAAK,IAAI;AACf,eAAO;AAAA,MACT,SAAS,KAAK;AACZ,YAAI,WAAW,GAAG,EAAG,QAAO;AAC5B,cAAM;AAAA,MACR;AAAA,IACF;AAAA,IAEA,MAAM,KAAK,MAAyC;AAClD,YAAM,IAAI,MAAM,KAAK,IAAI;AACzB,aAAO,EAAE,MAAM,EAAE,KAAK;AAAA,IACxB;AAAA,IAEA,MAAM,YACJ,MACA,MACqC;AACrC,YAAM,OAAO,kBAAkB,MAAM,EAAE,OAAO,MAAM,SAAS,MAAM,IAAI,CAAC;AACxE,aAAO,SAAS,MAAM,IAAI;AAAA,IAC5B;AAAA,IAEA,MAAM,OAAO,MAAc,IAA2B;AACpD,YAAM,OAAO,MAAM,EAAE;AAAA,IACvB;AAAA,IAEA,MAAM,OAAO,MAA6B;AACxC,UAAI;AACF,cAAM,OAAO,IAAI;AAAA,MACnB,SAAS,KAAK;AACZ,YAAI,WAAW,GAAG,EAAG;AACrB,cAAM;AAAA,MACR;AAAA,IACF;AAAA,IAEA,MAAM,MAAM,MAAc,MAA+C;AACvE,YAAM,MAAM,MAAM,EAAE,WAAW,MAAM,aAAa,MAAM,CAAC;AAAA,IAC3D;AAAA,IAEA,MAAM,SAAS,MAAmC;AAChD,YAAM,MAAM,MAAM,SAAS,IAAI;AAC/B,aAAO,IAAI,WAAW,IAAI,QAAQ,IAAI,YAAY,IAAI,UAAU;AAAA,IAClE;AAAA,IAEA,MAAM,UAAU,MAAc,MAAiC;AAC7D,YAAM,UAAU,MAAM,IAAI;AAAA,IAC5B;AAAA,IAEA,MAAM,OAAO,MAA+B;AAC1C,aAAO,IAAI,QAAgB,CAAC,SAAS,WAAW;AAC9C,cAAM,OAAO,WAAW,QAAQ;AAChC,cAAM,SAAS,iBAAiB,IAAI;AACpC,eAAO,GAAG,QAAQ,CAAC,UAAU,KAAK,OAAO,KAAK,CAAC;AAC/C,eAAO,GAAG,OAAO,MAAM,QAAQ,KAAK,OAAO,KAAK,CAAC,CAAC;AAClD,eAAO,GAAG,SAAS,MAAM;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,SAAS,WAAW,KAAuB;AACzC,SAAO,CAAC,EAAE,OAAO,OAAO,QAAQ,YAAY,UAAU,OAAQ,IAA2B,SAAS;AACpG;","names":[]}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * IHO S-52 Colour Tables: DAY_BRIGHT, DUSK, and NIGHT.
3
+ * Each token maps to a hex colour string.
4
+ * Source: IHO S-52 Presentation Library, Edition 4.0 – Annex A
5
+ */
6
+ type ColorTableName = "DAY" | "DUSK" | "NIGHT";
7
+ declare const S52_DAY: Record<string, string>;
8
+ declare const S52_DUSK: Record<string, string>;
9
+ declare const S52_NIGHT: Record<string, string>;
10
+ /** Backward-compatible alias – the DAY_BRIGHT table */
11
+ declare const S52_COLORS: Record<string, string>;
12
+ /** Get a full colour table by name */
13
+ declare function getColorTable(name: ColorTableName): Record<string, string>;
14
+ /** Resolve an S-52 colour token to a hex string. Falls back to black/amber. */
15
+ declare function resolveColor(token: string, table?: ColorTableName): string;
16
+
17
+ export { type ColorTableName as C, S52_COLORS as S, S52_DAY as a, S52_DUSK as b, S52_NIGHT as c, getColorTable as g, resolveColor as r };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * IHO S-52 Colour Tables: DAY_BRIGHT, DUSK, and NIGHT.
3
+ * Each token maps to a hex colour string.
4
+ * Source: IHO S-52 Presentation Library, Edition 4.0 – Annex A
5
+ */
6
+ type ColorTableName = "DAY" | "DUSK" | "NIGHT";
7
+ declare const S52_DAY: Record<string, string>;
8
+ declare const S52_DUSK: Record<string, string>;
9
+ declare const S52_NIGHT: Record<string, string>;
10
+ /** Backward-compatible alias – the DAY_BRIGHT table */
11
+ declare const S52_COLORS: Record<string, string>;
12
+ /** Get a full colour table by name */
13
+ declare function getColorTable(name: ColorTableName): Record<string, string>;
14
+ /** Resolve an S-52 colour token to a hex string. Falls back to black/amber. */
15
+ declare function resolveColor(token: string, table?: ColorTableName): string;
16
+
17
+ export { type ColorTableName as C, S52_COLORS as S, S52_DAY as a, S52_DUSK as b, S52_NIGHT as c, getColorTable as g, resolveColor as r };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrtco/sdk",
3
- "version": "0.4.1",
3
+ "version": "0.6.0",
4
4
  "description": "Official TypeScript SDK for the CHRT nautical chart API",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -11,25 +11,50 @@
11
11
  "types": "./dist/index.d.ts",
12
12
  "import": "./dist/index.js",
13
13
  "require": "./dist/index.cjs"
14
+ },
15
+ "./node": {
16
+ "types": "./dist/node/index.d.ts",
17
+ "import": "./dist/node/index.js",
18
+ "require": "./dist/node/index.cjs"
19
+ },
20
+ "./atlas/browser": {
21
+ "types": "./dist/atlas/browser.d.ts",
22
+ "import": "./dist/atlas/browser.js",
23
+ "require": "./dist/atlas/browser.cjs"
14
24
  }
15
25
  },
16
- "files": ["dist", "README.md"],
26
+ "files": ["dist", "README.md", "CHANGELOG.md"],
17
27
  "scripts": {
28
+ "gen:svgs": "bun run scripts/gen-s52-svgs.ts",
29
+ "prebuild": "bun run gen:svgs",
18
30
  "build": "tsup",
19
31
  "dev": "tsup --watch",
20
- "typecheck": "tsc --noEmit"
32
+ "typecheck": "tsc --noEmit",
33
+ "test": "vitest run"
21
34
  },
22
- "keywords": ["chrt", "nautical", "charts", "maritime", "enc", "s57", "mapbox", "maplibre", "gis", "api"],
35
+ "keywords": ["chrt", "nautical", "charts", "maritime", "enc", "s57", "mapbox", "maplibre", "gis", "api", "offline", "mbtiles"],
23
36
  "license": "MIT",
24
37
  "repository": {
25
38
  "type": "git",
26
- "url": "git+https://github.com/chrt-co/enc-hub.git",
39
+ "url": "git+https://github.com/chrt-co/chrt-prod.git",
27
40
  "directory": "packages/sdk"
28
41
  },
29
42
  "homepage": "https://chrt.co/docs/sdks",
43
+ "peerDependencies": {
44
+ "maplibre-gl": "^4.0.0 || ^5.0.0"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "maplibre-gl": {
48
+ "optional": true
49
+ }
50
+ },
30
51
  "devDependencies": {
52
+ "@maplibre/maplibre-gl-style-spec": "^20.4.0",
53
+ "@types/node": "^20.0.0",
54
+ "maplibre-gl": "^4.7.1",
31
55
  "tsup": "^8.0.0",
32
- "typescript": "^5.4.0"
56
+ "typescript": "^5.4.0",
57
+ "vitest": "^2.1.0"
33
58
  },
34
59
  "engines": {
35
60
  "node": ">=18.0.0"