@alexwohlbruck/portolan 0.3.1

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 (46) hide show
  1. package/README.md +262 -0
  2. package/bin/darwin-arm64/portolan +0 -0
  3. package/bin/darwin-x64/portolan +0 -0
  4. package/bin/linux-arm64/portolan +0 -0
  5. package/bin/linux-x64/portolan +0 -0
  6. package/bin/win32-arm64/portolan.exe +0 -0
  7. package/bin/win32-x64/portolan.exe +0 -0
  8. package/dist/binary.d.ts +16 -0
  9. package/dist/binary.d.ts.map +1 -0
  10. package/dist/binary.js +117 -0
  11. package/dist/binary.js.map +1 -0
  12. package/dist/client.d.ts +61 -0
  13. package/dist/client.d.ts.map +1 -0
  14. package/dist/client.js +201 -0
  15. package/dist/client.js.map +1 -0
  16. package/dist/index.d.ts +47 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +41 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/plnb.d.ts +89 -0
  21. package/dist/plnb.d.ts.map +1 -0
  22. package/dist/plnb.js +268 -0
  23. package/dist/plnb.js.map +1 -0
  24. package/dist/server.d.ts +68 -0
  25. package/dist/server.d.ts.map +1 -0
  26. package/dist/server.js +208 -0
  27. package/dist/server.js.map +1 -0
  28. package/dist/types.d.ts +177 -0
  29. package/dist/types.d.ts.map +1 -0
  30. package/dist/types.js +10 -0
  31. package/dist/types.js.map +1 -0
  32. package/package.json +49 -0
  33. package/style/_default.json +5 -0
  34. package/style/amsterdam.json +19 -0
  35. package/style/amtrak.json +5 -0
  36. package/style/barcelona-tmb.json +7 -0
  37. package/style/berlin.json +7 -0
  38. package/style/charlotte.json +12 -0
  39. package/style/chicago-cta.json +28 -0
  40. package/style/chicago.json +7 -0
  41. package/style/mexico.json +13 -0
  42. package/style/mta-subway.json +5 -0
  43. package/style/nj-transit-rail.json +5 -0
  44. package/style/paris.json +10 -0
  45. package/style/santiago.json +7 -0
  46. package/style/vienna.json +19 -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G,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,CAAgB,CAAC,CAAC;IACpG,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC"}
@@ -0,0 +1,68 @@
1
+ import type { VersionInfo } from "./types.js";
2
+ export interface StartOptions {
3
+ /** Path to the executable. Defaults to the bundled per-platform binary. */
4
+ binary?: string;
5
+ /** Listen host. Loopback by default, and you should keep it that way. */
6
+ host?: string;
7
+ /** Port. 0 (the default) lets the OS pick and the engine reports it back. */
8
+ port?: number;
9
+ /**
10
+ * Bearer token. A random one is generated per launch by default.
11
+ *
12
+ * Do not turn this off casually. A chart request names files for the
13
+ * engine to read, so an unauthenticated port is a file-read oracle for
14
+ * every other process on the machine — loopback is not a boundary
15
+ * between processes on one host. Pass `null` only if something else is
16
+ * already isolating the port.
17
+ */
18
+ token?: string | null;
19
+ /** Curation directory the engine reads when a request names a city. */
20
+ styleDir?: string;
21
+ /** Working directory. The engine reads `./style` relative to this. */
22
+ cwd?: string;
23
+ /** How long to wait for the port line before giving up. Default 10s. */
24
+ startupTimeoutMs?: number;
25
+ /**
26
+ * Refuse to start when the engine's PLNB layout version is not the one
27
+ * this package decodes. Default true — drawing against a layout you do
28
+ * not understand produces plausible-but-wrong geometry rather than an
29
+ * error, which is the failure this check exists to prevent.
30
+ */
31
+ requireCompatible?: boolean;
32
+ /** Called with each stderr line — the engine's build log. */
33
+ onLog?: (line: string) => void;
34
+ }
35
+ export declare class PortolanStartupError extends Error {
36
+ constructor(message: string);
37
+ }
38
+ export declare class IncompatibleEngineError extends Error {
39
+ readonly info: VersionInfo;
40
+ constructor(message: string, info: VersionInfo);
41
+ }
42
+ /**
43
+ * A running `portolan serve` process.
44
+ *
45
+ * The engine prints its bound port on stdout as the first line, which is
46
+ * how a `port: 0` launch is usable: the OS picks a free port and there is
47
+ * no race between choosing one and binding it.
48
+ */
49
+ export declare class PortolanServer {
50
+ private readonly proc;
51
+ readonly port: number;
52
+ readonly host: string;
53
+ readonly token: string | null;
54
+ readonly version: VersionInfo;
55
+ private constructor();
56
+ get origin(): string;
57
+ /** Headers every request needs. */
58
+ get headers(): Record<string, string>;
59
+ static start(opts?: StartOptions): Promise<PortolanServer>;
60
+ private fetchVersion;
61
+ /** Whether the process is still alive. */
62
+ get running(): boolean;
63
+ /** Stop the engine. Safe to call twice. */
64
+ stop(): Promise<void>;
65
+ /** `await using` support, so a server cannot outlive its scope. */
66
+ [Symbol.asyncDispose](): Promise<void>;
67
+ }
68
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,YAAY;IAC3B,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,uEAAuE;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,6DAA6D;IAC7D,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAED,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IAG9C,QAAQ,CAAC,IAAI,EAAE,WAAW;gBAD1B,OAAO,EAAE,MAAM,EACN,IAAI,EAAE,WAAW;CAK7B;AAED;;;;;;GAMG;AACH,qBAAa,cAAc;IAEvB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAC7B,QAAQ,CAAC,OAAO,EAAE,WAAW;IAL/B,OAAO;IAQP,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,mCAAmC;IACnC,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEpC;WAEY,KAAK,CAAC,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,cAAc,CAAC;YAkDtD,YAAY;IAQ1B,0CAA0C;IAC1C,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,2CAA2C;IACrC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAc3B,mEAAmE;IAC7D,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7C"}
package/dist/server.js ADDED
@@ -0,0 +1,208 @@
1
+ import { spawn } from "node:child_process";
2
+ import { randomBytes } from "node:crypto";
3
+ import { resolveBinary } from "./binary.js";
4
+ import { SUPPORTED_PLNB } from "./plnb.js";
5
+ export class PortolanStartupError extends Error {
6
+ constructor(message) {
7
+ super(message);
8
+ this.name = "PortolanStartupError";
9
+ }
10
+ }
11
+ export class IncompatibleEngineError extends Error {
12
+ info;
13
+ constructor(message, info) {
14
+ super(message);
15
+ this.info = info;
16
+ this.name = "IncompatibleEngineError";
17
+ }
18
+ }
19
+ /**
20
+ * A running `portolan serve` process.
21
+ *
22
+ * The engine prints its bound port on stdout as the first line, which is
23
+ * how a `port: 0` launch is usable: the OS picks a free port and there is
24
+ * no race between choosing one and binding it.
25
+ */
26
+ export class PortolanServer {
27
+ proc;
28
+ port;
29
+ host;
30
+ token;
31
+ version;
32
+ constructor(proc, port, host, token, version) {
33
+ this.proc = proc;
34
+ this.port = port;
35
+ this.host = host;
36
+ this.token = token;
37
+ this.version = version;
38
+ }
39
+ get origin() {
40
+ return `http://${this.host}:${this.port}`;
41
+ }
42
+ /** Headers every request needs. */
43
+ get headers() {
44
+ return this.token ? { Authorization: `Bearer ${this.token}` } : {};
45
+ }
46
+ static async start(opts = {}) {
47
+ const bin = resolveBinary(opts.binary);
48
+ const host = opts.host ?? "127.0.0.1";
49
+ const token = opts.token === null ? null : (opts.token ?? randomBytes(24).toString("hex"));
50
+ const args = ["serve", "--addr", `${host}:${opts.port ?? 0}`];
51
+ if (token)
52
+ args.push("--token", token);
53
+ if (opts.styleDir)
54
+ args.push("--style-dir", opts.styleDir);
55
+ const proc = spawn(bin, args, {
56
+ cwd: opts.cwd,
57
+ stdio: ["ignore", "pipe", "pipe"],
58
+ // do not let the engine outlive an abrupt parent exit
59
+ detached: false,
60
+ });
61
+ // The engine is NOT detached, but on POSIX that only means it shares
62
+ // a process group — a parent that exits leaves it reparented to init,
63
+ // still holding its port. `await using` covers scope exit and nothing
64
+ // else: not process.exit(), not an uncaught throw, not a crash. So
65
+ // every live engine is also killed on the way out.
66
+ //
67
+ // This is reaping, not supervision. Restart policy is deliberately
68
+ // the caller's: whether to retry, how many times, and when to give up
69
+ // and degrade are product decisions, and a contract mismatch in
70
+ // particular must NOT be retried — it fails identically every time.
71
+ const port = await firstLinePort(proc, opts.startupTimeoutMs ?? 10_000, opts.onLog);
72
+ reapOnExit(proc);
73
+ const server = new PortolanServer(proc, port, host, token, {
74
+ version: "unknown",
75
+ plnb: -1,
76
+ formats: [],
77
+ bands: [],
78
+ auth: false,
79
+ });
80
+ const info = await server.fetchVersion();
81
+ const withInfo = new PortolanServer(proc, port, host, token, info);
82
+ if ((opts.requireCompatible ?? true) && info.plnb !== SUPPORTED_PLNB) {
83
+ await withInfo.stop();
84
+ throw new IncompatibleEngineError(`engine ${info.version} emits PLNB layout ${info.plnb}, this client decodes ` +
85
+ `${SUPPORTED_PLNB}. Match the versions, or pass requireCompatible: false and ` +
86
+ `use format "geojson".`, info);
87
+ }
88
+ return withInfo;
89
+ }
90
+ async fetchVersion() {
91
+ // /version is open even when a token is set, so a caller can tell
92
+ // "not up yet" from "wrong token"
93
+ const r = await fetch(`${this.origin}/version`);
94
+ if (!r.ok)
95
+ throw new PortolanStartupError(`GET /version returned ${r.status}`);
96
+ return (await r.json());
97
+ }
98
+ /** Whether the process is still alive. */
99
+ get running() {
100
+ return this.proc.exitCode === null && !this.proc.killed;
101
+ }
102
+ /** Stop the engine. Safe to call twice. */
103
+ async stop() {
104
+ if (!this.running)
105
+ return;
106
+ await new Promise((resolve) => {
107
+ const done = () => resolve();
108
+ this.proc.once("exit", done);
109
+ this.proc.kill("SIGTERM");
110
+ // it has no shutdown work to do; if it has not gone in a second
111
+ // something is wedged and SIGKILL is the honest answer
112
+ setTimeout(() => {
113
+ if (this.running)
114
+ this.proc.kill("SIGKILL");
115
+ }, 1000).unref?.();
116
+ });
117
+ }
118
+ /** `await using` support, so a server cannot outlive its scope. */
119
+ async [Symbol.asyncDispose]() {
120
+ await this.stop();
121
+ }
122
+ }
123
+ /**
124
+ * Kill any still-running engine when this process ends.
125
+ *
126
+ * Entries are removed on the child's own exit, so a long-lived process
127
+ * that starts and stops many engines does not accumulate them.
128
+ */
129
+ const live = new Set();
130
+ let reaperInstalled = false;
131
+ function reapOnExit(proc) {
132
+ live.add(proc);
133
+ proc.once("exit", () => live.delete(proc));
134
+ if (reaperInstalled)
135
+ return;
136
+ reaperInstalled = true;
137
+ // 'exit' can only do synchronous work, and kill() is synchronous
138
+ process.on("exit", () => {
139
+ for (const p of live)
140
+ p.kill("SIGKILL");
141
+ });
142
+ // a signal does not fire 'exit' by itself; clean up, then re-raise so
143
+ // the caller's own exit code and handlers are unaffected
144
+ for (const sig of ["SIGINT", "SIGTERM"]) {
145
+ process.on(sig, () => {
146
+ for (const p of live)
147
+ p.kill("SIGKILL");
148
+ if (process.listenerCount(sig) <= 1)
149
+ process.kill(process.pid, sig);
150
+ });
151
+ }
152
+ }
153
+ /**
154
+ * Read the bound port off stdout's first line.
155
+ *
156
+ * Rejects on early exit rather than hanging until the timeout — a
157
+ * mis-specified binary or a port already in use should say so at once,
158
+ * and the engine's stderr is the only place that says why.
159
+ */
160
+ function firstLinePort(proc, timeoutMs, onLog) {
161
+ return new Promise((resolve, reject) => {
162
+ let stdout = "";
163
+ let stderr = "";
164
+ let settled = false;
165
+ const finish = (fn) => {
166
+ if (settled)
167
+ return;
168
+ settled = true;
169
+ clearTimeout(timer);
170
+ fn();
171
+ };
172
+ const timer = setTimeout(() => {
173
+ finish(() => {
174
+ proc.kill("SIGKILL");
175
+ reject(new PortolanStartupError(`portolan serve printed no port within ${timeoutMs}ms` +
176
+ (stderr ? `\n${stderr.trim()}` : "")));
177
+ });
178
+ }, timeoutMs);
179
+ timer.unref?.();
180
+ proc.stdout?.on("data", (chunk) => {
181
+ stdout += chunk.toString();
182
+ const nl = stdout.indexOf("\n");
183
+ if (nl < 0)
184
+ return;
185
+ const port = Number.parseInt(stdout.slice(0, nl).trim(), 10);
186
+ finish(() => {
187
+ if (!Number.isInteger(port) || port <= 0) {
188
+ proc.kill("SIGKILL");
189
+ reject(new PortolanStartupError(`expected a port on the first stdout line, got ${JSON.stringify(stdout.slice(0, nl))}`));
190
+ return;
191
+ }
192
+ resolve(port);
193
+ });
194
+ });
195
+ proc.stderr?.on("data", (chunk) => {
196
+ const text = chunk.toString();
197
+ stderr += text;
198
+ if (onLog)
199
+ for (const line of text.split("\n"))
200
+ if (line)
201
+ onLog(line);
202
+ });
203
+ proc.once("error", (err) => finish(() => reject(new PortolanStartupError(`could not spawn portolan: ${err.message}`))));
204
+ proc.once("exit", (code) => finish(() => reject(new PortolanStartupError(`portolan serve exited with code ${code} before printing a port` +
205
+ (stderr ? `\n${stderr.trim()}` : "")))));
206
+ });
207
+ }
208
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","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AAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAC3F,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CACzB,MAAM,CAAC,GAAG,EAAE,CACV,MAAM,CACJ,IAAI,oBAAoB,CACtB,mCAAmC,IAAI,yBAAyB;YAC9D,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACvC,CACF,CACF,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,177 @@
1
+ /**
2
+ * The wire types, mirroring `internal/serve`.Request and the emitters.
3
+ *
4
+ * These exist so a consumer never hand-writes the request shape or
5
+ * re-derives a property name. Every field here is checked against the Go
6
+ * struct by `test/contract.test.js`, which reads the Go source — the two
7
+ * have drifted before and it was expensive both times.
8
+ */
9
+ /** A GTFS feed held in memory: table name to its CSV text, header row included. */
10
+ export type GtfsTables = Record<string, string>;
11
+ /**
12
+ * A curation document: colours, names, bullet shapes and fonts.
13
+ *
14
+ * SUBJECT-KEYED — name a route or agency once and hang everything known
15
+ * about it off that name. The flat `route:<id>` tables that appear in
16
+ * the engine's own source are its INTERNAL form and are rejected here,
17
+ * loudly, because a curation document that parses and applies nothing is
18
+ * the worst failure this format can have.
19
+ */
20
+ export interface StyleDoc {
21
+ routes?: Record<string, StyleEntity>;
22
+ agencies?: Record<string, StyleEntity>;
23
+ stops?: Record<string, StyleEntity>;
24
+ modes?: Record<string, StyleClass>;
25
+ options?: {
26
+ bullet_order?: "color" | "feed" | "natural";
27
+ caterpillars?: boolean;
28
+ osm_stop_names?: boolean;
29
+ };
30
+ }
31
+ export interface StyleEntity {
32
+ /** Display name — the bullet text and the trunk label. */
33
+ name?: string;
34
+ /** Drawn colour, hex without `#`. */
35
+ color?: string;
36
+ /** Bullet outline. */
37
+ shape?: "circle" | "square" | "rounded" | "notch" | "diamond" | "hexagon" | "octagon" | "triangle";
38
+ font?: "default" | "mono" | "bolder" | "lighter" | "italic";
39
+ /** A contrasting ring — what a white or near-white bullet needs to have an edge. */
40
+ bordered?: boolean;
41
+ /**
42
+ * Merge policy for this subject alone, in practice `"route"` to keep
43
+ * it out of a colour trunk. Trunking is colour-based, which is right
44
+ * where colour carries meaning and wrong where it is assigned freely.
45
+ */
46
+ trunk?: "color" | "agency" | "route" | "none";
47
+ /** Agencies only: these route colours are line identities, not branch decoration. */
48
+ line_colors?: boolean;
49
+ }
50
+ export interface StyleClass {
51
+ color?: string;
52
+ width?: number;
53
+ opacity?: number;
54
+ band_floor?: number;
55
+ trunk?: "color" | "agency" | "route" | "none";
56
+ hidden?: boolean;
57
+ }
58
+ /** A place. Prefer this over the tuple — `[lat, lon]` is easy to swap. */
59
+ export interface LatLon {
60
+ lat: number;
61
+ lon: number;
62
+ }
63
+ /** A window. Prefer this over the tuple — the tuple is longitude-first. */
64
+ export interface BBox {
65
+ w: number;
66
+ s: number;
67
+ e: number;
68
+ n: number;
69
+ }
70
+ /** A zoom band. `null` means every band, which is the default. */
71
+ export type Band = 15 | 14 | 13 | 0 | null;
72
+ export type Format = "geojson" | "bin";
73
+ export interface ChartRequest {
74
+ /** GTFS zip or a directory of .txt tables. Required unless `gtfsInline`. */
75
+ gtfs?: string;
76
+ /** The feed itself, instead of a path — for a caller whose tables are live state. */
77
+ gtfsInline?: GtfsTables;
78
+ /** OSM rail extract. Portolan infers the corridors from it. */
79
+ rail?: string;
80
+ /** A corridor graph you already have, as a path. Alternative to `rail`. */
81
+ corridors?: string;
82
+ /** The corridor graph itself, as GeoJSON. Alternative to `corridors`. */
83
+ corridorsInline?: unknown;
84
+ /** The nodes half, when the graph arrives as two files. */
85
+ corridorNodes?: string;
86
+ stops?: string;
87
+ streets?: string;
88
+ /**
89
+ * Clip window. The object form is unambiguous; the tuple is
90
+ * `[w, s, e, n]` — LONGITUDE first, GeoJSON's order — and sits next to
91
+ * an `anchor` that is latitude-first, so prefer the object.
92
+ */
93
+ bbox?: BBox | [number, number, number, number];
94
+ /**
95
+ * Pin the projection origin. Object form preferred; the tuple is
96
+ * `[lat, lon]`, LATITUDE first, which is what a map UI hands you when
97
+ * you copy a location — and the opposite order to `bbox`.
98
+ *
99
+ * PIN IT TO SOMETHING THAT DOES NOT MOVE. Every measurement happens in
100
+ * a local metric frame, so moving the origin re-rounds every float in
101
+ * the build. Deriving it from the current extent of what has been
102
+ * drawn means it shifts the moment the network grows past that extent,
103
+ * which costs exactly the locality guarantee the engine otherwise
104
+ * gives you. A city centre is right; the bounding-box centre of the
105
+ * user's current stations is not.
106
+ */
107
+ anchor?: LatLon | [number, number];
108
+ city?: string;
109
+ styleDir?: string;
110
+ /**
111
+ * The curation document itself, instead of a directory.
112
+ *
113
+ * Symmetrical with `gtfsInline` and `corridorsInline`, and for the
114
+ * same reason: colours and bullet shapes are live state for an editor,
115
+ * so a path forces a file write per rebuild — and somewhere writable
116
+ * to put it. Replaces `styleDir`/`city` when set; the class defaults
117
+ * are compiled into the engine, so a document alone is complete.
118
+ */
119
+ styleInline?: StyleDoc;
120
+ lineAgencies?: string[];
121
+ scenario?: string;
122
+ cover?: number;
123
+ format?: Format;
124
+ band?: Band;
125
+ }
126
+ /** What the engine says it is. Check this before drawing anything. */
127
+ export interface VersionInfo {
128
+ /** Bare semver, no leading `v`. `"devel"` for an unstamped build. */
129
+ version: string;
130
+ /**
131
+ * The PLNB binary layout version. THIS is the number to gate on — it
132
+ * changes when a column moves, which is what a decoder depends on.
133
+ * `version` tells you what you got; `plnb` tells you if you can read it.
134
+ */
135
+ plnb: number;
136
+ formats: Format[];
137
+ bands: number[];
138
+ /** Whether the server requires a bearer token. */
139
+ auth: boolean;
140
+ }
141
+ export interface ProgressEvent {
142
+ /** Stage name: queued, load, gtfs, topology, traversal, order, fair, stations, caterpillars, emit, done. */
143
+ stage?: string;
144
+ /** Monotonic 0-100. */
145
+ pct?: number;
146
+ /** A line from the build log. */
147
+ log?: string;
148
+ /** Set on the single terminal frame. */
149
+ done?: boolean;
150
+ /** Present on the terminal frame when the build failed. */
151
+ error?: string;
152
+ }
153
+ export type Artifact = "segments" | "stations" | "style" | "trackcenter" | "nodes";
154
+ /** One decoded ribbon. Property arrays are parallel to feature index. */
155
+ export interface PlnbFeature {
156
+ index: number;
157
+ kind: "steady" | "transition" | "bridge" | "unknown";
158
+ /** 0xRRGGBB. */
159
+ color: number;
160
+ offsetPx: number;
161
+ offFromPx: number;
162
+ offToPx: number;
163
+ slot: number;
164
+ nslots: number;
165
+ bandMin: number;
166
+ bandMax: number;
167
+ routeType: number;
168
+ label: string;
169
+ mode: string;
170
+ /** Route ids, split from the emitted CSV. Verbatim — never normalised. */
171
+ routes: string[];
172
+ /** Hex weekly masks, aligned with `routes`. Empty when there is no calendar. */
173
+ acts: string[];
174
+ /** `[lon, lat]` pairs in degrees. */
175
+ coordinates: Array<[number, number]>;
176
+ }
177
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,mFAAmF;AACnF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEhD;;;;;;;;GAQG;AACH,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACnC,OAAO,CAAC,EAAE;QACR,YAAY,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;QAC5C,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,cA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AAO,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,4GAA4G;IAC5G,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,QAAQ,GAChB,UAAU,GACV,UAAU,GACV,OAAO,GACP,aAAa,GACb,OAAO,CAAC;AAEZ,yEAAyE;AACzE,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,QAAQ,GAAG,YAAY,GAAG,QAAQ,GAAG,SAAS,CAAC;IACrD,gBAAgB;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,gFAAgF;IAChF,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,qCAAqC;IACrC,WAAW,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACtC"}
package/dist/types.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The wire types, mirroring `internal/serve`.Request and the emitters.
3
+ *
4
+ * These exist so a consumer never hand-writes the request shape or
5
+ * re-derives a property name. Every field here is checked against the Go
6
+ * struct by `test/contract.test.js`, which reads the Go source — the two
7
+ * have drifted before and it was expensive both times.
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@alexwohlbruck/portolan",
3
+ "version": "0.3.1",
4
+ "description": "Automatic transit line maps. Spawns the portolan engine and speaks its build API, with a typed PLNB decoder.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/alexwohlbruck/portolan.git",
9
+ "directory": "clients/npm"
10
+ },
11
+ "homepage": "https://github.com/alexwohlbruck/portolan#readme",
12
+ "type": "module",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "./client": {
19
+ "types": "./dist/client.d.ts",
20
+ "default": "./dist/client.js"
21
+ },
22
+ "./plnb": {
23
+ "types": "./dist/plnb.d.ts",
24
+ "default": "./dist/plnb.js"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "types": "./dist/index.d.ts",
29
+ "files": [
30
+ "dist",
31
+ "bin",
32
+ "style",
33
+ "README.md"
34
+ ],
35
+ "preferUnplugged": true,
36
+ "engines": {
37
+ "node": ">=18"
38
+ },
39
+ "scripts": {
40
+ "build": "tsc -p tsconfig.json",
41
+ "test": "npm run build && node --test test/*.test.js",
42
+ "check-publish": "node scripts/check-publish.mjs",
43
+ "prepublishOnly": "npm run build && npm run check-publish"
44
+ },
45
+ "devDependencies": {
46
+ "typescript": "^5.6.0",
47
+ "@types/node": "^22.0.0"
48
+ }
49
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "agencies": {
3
+ "intercity": { "color": "2A7AB8" }
4
+ }
5
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "routes": {
3
+ "50": {
4
+ "shape": "rounded"
5
+ },
6
+ "51": {
7
+ "shape": "rounded"
8
+ },
9
+ "52": {
10
+ "shape": "rounded"
11
+ },
12
+ "53": {
13
+ "shape": "rounded"
14
+ },
15
+ "54": {
16
+ "shape": "rounded"
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "agencies": {
3
+ "Amtrak": { "trunk": "intercity" }
4
+ }
5
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "agencies": {
3
+ "TMB": {
4
+ "shape": "rounded"
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "agencies": {
3
+ "Berliner Verkehrsbetriebe": {
4
+ "shape": "rounded"
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "routes": {
3
+ "501": {
4
+ "name": "Blue",
5
+ "color": "0067B1"
6
+ },
7
+ "510": {
8
+ "name": "Gold",
9
+ "color": "CBA052"
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "routes": {
3
+ "Red Line": {
4
+ "name": "Red"
5
+ },
6
+ "Blue Line": {
7
+ "name": "Blue"
8
+ },
9
+ "Brown Line": {
10
+ "name": "Brown"
11
+ },
12
+ "Green Line": {
13
+ "name": "Green"
14
+ },
15
+ "Orange Line": {
16
+ "name": "Orange"
17
+ },
18
+ "Pink Line": {
19
+ "name": "Pink"
20
+ },
21
+ "Purple Line": {
22
+ "name": "Purple"
23
+ },
24
+ "Yellow Line": {
25
+ "name": "Yellow"
26
+ }
27
+ }
28
+ }