@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.
- package/README.md +262 -0
- package/bin/darwin-arm64/portolan +0 -0
- package/bin/darwin-x64/portolan +0 -0
- package/bin/linux-arm64/portolan +0 -0
- package/bin/linux-x64/portolan +0 -0
- package/bin/win32-arm64/portolan.exe +0 -0
- package/bin/win32-x64/portolan.exe +0 -0
- package/dist/binary.d.ts +16 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +117 -0
- package/dist/binary.js.map +1 -0
- package/dist/client.d.ts +61 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +201 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/plnb.d.ts +89 -0
- package/dist/plnb.d.ts.map +1 -0
- package/dist/plnb.js +268 -0
- package/dist/plnb.js.map +1 -0
- package/dist/server.d.ts +68 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +208 -0
- package/dist/server.js.map +1 -0
- package/dist/types.d.ts +177 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +49 -0
- package/style/_default.json +5 -0
- package/style/amsterdam.json +19 -0
- package/style/amtrak.json +5 -0
- package/style/barcelona-tmb.json +7 -0
- package/style/berlin.json +7 -0
- package/style/charlotte.json +12 -0
- package/style/chicago-cta.json +28 -0
- package/style/chicago.json +7 -0
- package/style/mexico.json +13 -0
- package/style/mta-subway.json +5 -0
- package/style/nj-transit-rail.json +5 -0
- package/style/paris.json +10 -0
- package/style/santiago.json +7 -0
- package/style/vienna.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# @alexwohlbruck/portolan
|
|
2
|
+
|
|
3
|
+
Automatic transit line maps, as a Node package. Spawns the
|
|
4
|
+
[portolan](https://github.com/alexwohlbruck/portolan) engine, speaks its
|
|
5
|
+
build API, and decodes its binary output.
|
|
6
|
+
|
|
7
|
+
**The engine ships inside the package.** One binary per platform, pulled
|
|
8
|
+
in as an `optionalDependency`, so npm installs only the one matching your
|
|
9
|
+
machine and a version bump here ships a new engine. No download step, no
|
|
10
|
+
`postinstall`, nothing to keep in sync.
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @alexwohlbruck/portolan
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Use
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { portolan } from "@alexwohlbruck/portolan";
|
|
20
|
+
|
|
21
|
+
await using p = await portolan();
|
|
22
|
+
|
|
23
|
+
const job = await p.chart(
|
|
24
|
+
{
|
|
25
|
+
gtfsInline: {
|
|
26
|
+
"routes.txt": "route_id,route_short_name,route_type,route_color\nR1,1,1,EE352E\n",
|
|
27
|
+
"stops.txt": "stop_id,stop_name,stop_lat,stop_lon\ns1,Alpha,37.77,-122.42\n",
|
|
28
|
+
},
|
|
29
|
+
corridorsInline: graph, // a GeoJSON corridor graph
|
|
30
|
+
format: "bin",
|
|
31
|
+
band: 15,
|
|
32
|
+
},
|
|
33
|
+
{ onProgress: (e) => console.log(e.stage, e.pct) },
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const plnb = await job.plnb();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`await using` stops the engine when the scope ends. It needs TypeScript
|
|
40
|
+
5.2+ and `Symbol.asyncDispose` at runtime (Node 20+); on an older target
|
|
41
|
+
just call **`p.stop()`**, which is always available and is the same
|
|
42
|
+
thing. The syntax is sugar, not the interface.
|
|
43
|
+
|
|
44
|
+
Either way the package installs a `process.on("exit")` reaper, so an
|
|
45
|
+
engine cannot outlive its parent even on `process.exit()` or an uncaught
|
|
46
|
+
throw — see *Lifecycle* below for what that does and does not cover.
|
|
47
|
+
|
|
48
|
+
Nothing above touches the filesystem. `gtfsInline` and `corridorsInline`
|
|
49
|
+
put the feed tables and the corridor graph in the request body, which is
|
|
50
|
+
what an editor wants: a colour change touches `routes.txt` and every
|
|
51
|
+
route edit touches `stop_times.txt`, so writing a zip per keystroke is a
|
|
52
|
+
round trip bought for nothing.
|
|
53
|
+
|
|
54
|
+
## Two processes, one engine
|
|
55
|
+
|
|
56
|
+
In Electron, **main owns the process and the renderer owns the
|
|
57
|
+
traffic.** Routing artifacts through IPC structured-clones them, which
|
|
58
|
+
is exactly the main-thread cost this format exists to remove.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
// main: own the lifecycle, hand out the address
|
|
62
|
+
const p = await portolan();
|
|
63
|
+
ipcMain.handle("portolan:addr", () => ({
|
|
64
|
+
origin: p.server.origin,
|
|
65
|
+
token: p.server.token,
|
|
66
|
+
}));
|
|
67
|
+
app.on("before-quit", () => p.stop());
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
// renderer (or a worker): own the traffic
|
|
72
|
+
import { PortolanClient } from "@alexwohlbruck/portolan/client";
|
|
73
|
+
|
|
74
|
+
const { origin, token } = await ipcRenderer.invoke("portolan:addr");
|
|
75
|
+
const client = PortolanClient.at(origin, token);
|
|
76
|
+
const job = await client.chart({ ... });
|
|
77
|
+
const plnb = await job.plnb(); // bytes never cross IPC
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Import from `/client` in the renderer, not from the package root.**
|
|
81
|
+
The root exports `PortolanServer`, so it pulls `node:child_process`, and
|
|
82
|
+
an Electron renderer with context isolation has no Node — the bundler
|
|
83
|
+
fails the build. `/client` and `/plnb` are Node-free by construction and
|
|
84
|
+
there is a test that keeps them that way.
|
|
85
|
+
|
|
86
|
+
| subpath | holds | needs Node |
|
|
87
|
+
| --- | --- | --- |
|
|
88
|
+
| `@alexwohlbruck/portolan` | everything, incl. `portolan()` and `PortolanServer` | yes |
|
|
89
|
+
| `@alexwohlbruck/portolan/client` | `PortolanClient`, `Job`, `PortolanError` | no |
|
|
90
|
+
| `@alexwohlbruck/portolan/plnb` | `decodePlnb`, `Plnb`, `SUPPORTED_PLNB` | no |
|
|
91
|
+
|
|
92
|
+
`PortolanClient.at()` is the piece that makes this split possible. The
|
|
93
|
+
one-liner at the top is the right shape for a CLI or a server; for a UI
|
|
94
|
+
process, use this one.
|
|
95
|
+
|
|
96
|
+
## Reading the output
|
|
97
|
+
|
|
98
|
+
`job.plnb()` returns a decoded build whose property arrays are **views
|
|
99
|
+
over the response buffer**, so per-feature values are read by index with
|
|
100
|
+
no allocation.
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
const plnb = await job.plnb();
|
|
104
|
+
|
|
105
|
+
plnb.degrees(); // Float64Array, flat [lon, lat, lon, lat, …] — for the GPU
|
|
106
|
+
plnb.starts; // Uint32Array, featureCount + 1 vertex offsets
|
|
107
|
+
plnb.positions; // Int32Array at 1e-7 degrees — the wire form, rarely what you want
|
|
108
|
+
|
|
109
|
+
for (let i = 0; i < plnb.featureCount; i++) {
|
|
110
|
+
const [a, b] = plnb.vertexRange(i); // positions[a*2 .. b*2)
|
|
111
|
+
plnb.colorHex(i); // "#ee352e"
|
|
112
|
+
plnb.offsetPx(i); // lateral slot offset in px
|
|
113
|
+
plnb.routes(i); // ["R1"] — verbatim, never normalised
|
|
114
|
+
plnb.bandMin(i), plnb.bandMax(i); // HALF-OPEN: [min, max)
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`plnb.feature(i)` gives a plain object, and `plnb.toGeoJSON()` the whole
|
|
119
|
+
thing — both allocate, so neither is the fast path.
|
|
120
|
+
|
|
121
|
+
### Getting it onto the GPU
|
|
122
|
+
|
|
123
|
+
Use **`degrees()`**, not `positions`. Every WebGL path — deck.gl,
|
|
124
|
+
MapLibre, raw GL — wants degrees in the vertex buffer, because
|
|
125
|
+
projection happens in the shader from lng/lat, and nothing off the shelf
|
|
126
|
+
divides by 1e7.
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
new PathLayer({
|
|
130
|
+
data: { length: plnb.featureCount, startIndices: plnb.starts,
|
|
131
|
+
attributes: { getPath: { value: plnb.degrees(), size: 2 } } },
|
|
132
|
+
_pathType: "open",
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
It is `Float64Array` and that is not a preference: a float32 holds about
|
|
137
|
+
seven significant digits where a longitude needs nine, so an f32 buffer
|
|
138
|
+
quantises vertices to roughly two metres and visibly kinks a ribbon —
|
|
139
|
+
the same reason the wire format is `i32` and not `f32`. deck.gl takes
|
|
140
|
+
f64 and splits it into hi/lo f32 pairs for exactly this.
|
|
141
|
+
|
|
142
|
+
`degrees()` is one pass over the buffer, cached, so calling it per frame
|
|
143
|
+
costs nothing after the first.
|
|
144
|
+
|
|
145
|
+
## Lifecycle
|
|
146
|
+
|
|
147
|
+
The package **reaps**; it does not **supervise**.
|
|
148
|
+
|
|
149
|
+
Reaped for you: scope exit via `await using`, an explicit `stop()`, and
|
|
150
|
+
a `process.on("exit")` / SIGINT / SIGTERM hook that kills any live engine
|
|
151
|
+
on the way out. An engine cannot outlive its parent and sit on a port.
|
|
152
|
+
|
|
153
|
+
**Yours:** restart policy. Whether to retry a crashed engine, how many
|
|
154
|
+
times, with what backoff, and when to give up and degrade are product
|
|
155
|
+
decisions, and a library guessing them is worse than a caller choosing
|
|
156
|
+
them. One rule worth stating: an `IncompatibleEngineError` must **not**
|
|
157
|
+
be retried — it will fail identically every time.
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
p.server.running; // false once it has died
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Version handshake
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
p.version; // { version: "0.3.1", plnb: 1, formats, bands, auth }
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Gate on `plnb`, not `version`.** It is the binary layout number, and it
|
|
170
|
+
changes when a column moves — which is the thing a decoder depends on.
|
|
171
|
+
`version` tells you what you got; `plnb` tells you whether you can read
|
|
172
|
+
it. `portolan()` refuses to start on a mismatch by default; pass
|
|
173
|
+
`requireCompatible: false` and use `format: "geojson"` if you would
|
|
174
|
+
rather degrade than fail.
|
|
175
|
+
|
|
176
|
+
## Security
|
|
177
|
+
|
|
178
|
+
The engine is started with a **random bearer token per launch**, and you
|
|
179
|
+
should leave it that way. A chart request names files for the engine to
|
|
180
|
+
read (`gtfs`, `styleDir`, `corridors`), so an unauthenticated port is a
|
|
181
|
+
file-read oracle for every other process on the machine — binding to
|
|
182
|
+
loopback is not a boundary between processes on one host.
|
|
183
|
+
|
|
184
|
+
`/version` and `/healthz` stay open so a supervisor can tell "not up yet"
|
|
185
|
+
from "wrong token".
|
|
186
|
+
|
|
187
|
+
## Choosing a binary
|
|
188
|
+
|
|
189
|
+
Resolution order, first hit wins:
|
|
190
|
+
|
|
191
|
+
1. `portolan({ binary: "/path/to/portolan" })`
|
|
192
|
+
2. `$PORTOLAN_BIN` — a dev override, or a copy you bundled yourself
|
|
193
|
+
3. the per-platform optional dependency (the default)
|
|
194
|
+
|
|
195
|
+
If you are packaging this inside a signed application and would rather
|
|
196
|
+
place the binary yourself, use `PORTOLAN_BIN` and install with
|
|
197
|
+
`--no-optional` to skip the ~3 MB download.
|
|
198
|
+
|
|
199
|
+
Supported: `darwin-arm64`, `darwin-x64`, `linux-arm64`, `linux-x64`,
|
|
200
|
+
`win32-arm64`, `win32-x64`.
|
|
201
|
+
|
|
202
|
+
The engine package is pinned to this package's exact version and
|
|
203
|
+
`resolveBinary()` checks it, because npm **skips an unresolvable
|
|
204
|
+
optional dependency without failing the install** — so a mismatch would
|
|
205
|
+
otherwise surface as a missing binary at the first chart call rather
|
|
206
|
+
than as the version problem it is. Both errors extend
|
|
207
|
+
`BinaryNotFoundError`; neither is worth retrying.
|
|
208
|
+
|
|
209
|
+
> Node says `x64` where Go says `amd64`, for the same architecture. The
|
|
210
|
+
> package names use Node's spelling because npm resolves them against
|
|
211
|
+
> `process.arch`; the release archives use Go's because `GOOS`/`GOARCH`
|
|
212
|
+
> built them. The mapping lives in one script and nowhere else.
|
|
213
|
+
|
|
214
|
+
## Curation
|
|
215
|
+
|
|
216
|
+
Colours, names, bullet shapes and fonts are curation, not feed data —
|
|
217
|
+
and for an editor they are live state, changing whenever the user
|
|
218
|
+
recolours a line. So send the document, not a path:
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
await p.chart({
|
|
222
|
+
...,
|
|
223
|
+
styleInline: {
|
|
224
|
+
routes: { L: { color: "EE352E", shape: "diamond", font: "italic" } },
|
|
225
|
+
agencies: { CR: { name: "Commuter Rail", color: "80276C" } },
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
`styleInline` replaces `styleDir`/`city` when set, and needs nowhere
|
|
231
|
+
writable — which matters more than it sounds: a packaged app that must
|
|
232
|
+
write a file first needs a writable location AND a way to reach it, and
|
|
233
|
+
that path is a surface rather than a detail.
|
|
234
|
+
|
|
235
|
+
`styleDir` still works when your curation genuinely lives on disk:
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
await p.chart({ ..., city: "sf", styleDir: "/writable/path/style" });
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
The class defaults are compiled into the engine, so a directory holding
|
|
242
|
+
only your own document is complete — there is nothing to copy out of the
|
|
243
|
+
package first. Either way the document is **subject-keyed**:
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
{ "routes": { "L": { "color": "EE352E", "shape": "diamond", "font": "italic" } } }
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
A document using the wrong shape is a hard error naming the right one,
|
|
250
|
+
rather than parsing cleanly and applying nothing.
|
|
251
|
+
|
|
252
|
+
## Versioning
|
|
253
|
+
|
|
254
|
+
This package's version tracks the engine it carries, and the two are
|
|
255
|
+
published together. Pin an exact version if your renderer depends on the
|
|
256
|
+
geometry: portolan is pre-1.0, so the map is still allowed to move
|
|
257
|
+
between minor versions.
|
|
258
|
+
|
|
259
|
+
See [docs/CORRIDORS.md](https://github.com/alexwohlbruck/portolan/blob/main/docs/CORRIDORS.md)
|
|
260
|
+
for the corridor graph contract and
|
|
261
|
+
[docs/CLI.md](https://github.com/alexwohlbruck/portolan/blob/main/docs/CLI.md)
|
|
262
|
+
for the full API.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/binary.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class BinaryNotFoundError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
/** `darwin-arm64` etc. Node's names, not Go's — see the note on SUPPORTED. */
|
|
5
|
+
export declare function platformKey(): string;
|
|
6
|
+
/**
|
|
7
|
+
* The curation documents that ship with the engine.
|
|
8
|
+
*
|
|
9
|
+
* The engine reads `./style` relative to its WORKING DIRECTORY, not to the
|
|
10
|
+
* binary, so it does not find this on its own — pass it as `styleDir` (or
|
|
11
|
+
* `cwd`) if you want the shipped curation rather than raw feed colours.
|
|
12
|
+
*/
|
|
13
|
+
export declare function styleDir(): string;
|
|
14
|
+
/** Locate the portolan executable for this host. */
|
|
15
|
+
export declare function resolveBinary(explicit?: string): string;
|
|
16
|
+
//# sourceMappingURL=binary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary.d.ts","sourceRoot":"","sources":["../src/binary.ts"],"names":[],"mappings":"AAoDA,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAgBD,8EAA8E;AAC9E,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,IAAI,MAAM,CAEjC;AAED,oDAAoD;AACpD,wBAAgB,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAsCvD"}
|
package/dist/binary.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join, dirname } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
/**
|
|
5
|
+
* Finding the engine.
|
|
6
|
+
*
|
|
7
|
+
* All six binaries ship INSIDE this package, under `bin/<platform>-<arch>/`.
|
|
8
|
+
* One package, one publish, one thing to install — and the engine can never
|
|
9
|
+
* disagree with the wrapper about its version, because they are the same
|
|
10
|
+
* artifact.
|
|
11
|
+
*
|
|
12
|
+
* WHY NOT THE optionalDependency SPLIT (which this replaced): six sibling
|
|
13
|
+
* packages with `os`/`cpu` gates is the esbuild shape, and it is genuinely
|
|
14
|
+
* leaner per install — npm resolves the one matching the host and skips the
|
|
15
|
+
* rest. It costs a chain of failure modes that all look like success. npm
|
|
16
|
+
* SKIPS an optional dependency it cannot resolve and still calls the install
|
|
17
|
+
* clean, so a half-finished publish, an `--omit=optional`, or an install on a
|
|
18
|
+
* different platform than the one that runs all produce a working install
|
|
19
|
+
* that dies at the first chart call. Publishing needs the six to go out
|
|
20
|
+
* before the wrapper, and each is a separate registry write. For an engine
|
|
21
|
+
* this size, paying ~22MB per install to make every one of those failures
|
|
22
|
+
* impossible is the better trade.
|
|
23
|
+
*
|
|
24
|
+
* Deliberately NOT a postinstall download: that breaks offline installs,
|
|
25
|
+
* air-gapped CI, `--ignore-scripts`, and — the case that matters here —
|
|
26
|
+
* signed and notarized application bundles, where a binary that appeared
|
|
27
|
+
* after signing is exactly what the OS refuses to run.
|
|
28
|
+
*
|
|
29
|
+
* Resolution order, first hit wins:
|
|
30
|
+
* 1. an explicit path passed by the caller
|
|
31
|
+
* 2. $PORTOLAN_BIN — dev override, or a bundled copy
|
|
32
|
+
* 3. bin/<platform>-<arch>/ inside this package
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* Node's spelling of every target that has a build. Note the naming seam:
|
|
36
|
+
* Node says `x64` where Go says `amd64`, for the same architecture. These
|
|
37
|
+
* keys are NODE's, because `process.platform`/`process.arch` are what
|
|
38
|
+
* choose between them; the release archives use Go's, because GOOS/GOARCH
|
|
39
|
+
* are what built them. The mapping lives in scripts/build-universal.mjs
|
|
40
|
+
* and nowhere else, which is the point.
|
|
41
|
+
*/
|
|
42
|
+
const SUPPORTED = [
|
|
43
|
+
"darwin-arm64",
|
|
44
|
+
"darwin-x64",
|
|
45
|
+
"linux-arm64",
|
|
46
|
+
"linux-x64",
|
|
47
|
+
"win32-arm64",
|
|
48
|
+
"win32-x64",
|
|
49
|
+
];
|
|
50
|
+
export class BinaryNotFoundError extends Error {
|
|
51
|
+
constructor(message) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.name = "BinaryNotFoundError";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** This package's own root — `bin/` and `style/` sit beside `dist/`. */
|
|
57
|
+
function packageRoot() {
|
|
58
|
+
return join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
59
|
+
}
|
|
60
|
+
/** This package's own version, or "" if the manifest cannot be read. */
|
|
61
|
+
function selfVersion() {
|
|
62
|
+
try {
|
|
63
|
+
return JSON.parse(readFileSync(join(packageRoot(), "package.json"), "utf8")).version ?? "";
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** `darwin-arm64` etc. Node's names, not Go's — see the note on SUPPORTED. */
|
|
70
|
+
export function platformKey() {
|
|
71
|
+
return `${process.platform}-${process.arch}`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The curation documents that ship with the engine.
|
|
75
|
+
*
|
|
76
|
+
* The engine reads `./style` relative to its WORKING DIRECTORY, not to the
|
|
77
|
+
* binary, so it does not find this on its own — pass it as `styleDir` (or
|
|
78
|
+
* `cwd`) if you want the shipped curation rather than raw feed colours.
|
|
79
|
+
*/
|
|
80
|
+
export function styleDir() {
|
|
81
|
+
return join(packageRoot(), "style");
|
|
82
|
+
}
|
|
83
|
+
/** Locate the portolan executable for this host. */
|
|
84
|
+
export function resolveBinary(explicit) {
|
|
85
|
+
if (explicit) {
|
|
86
|
+
if (!existsSync(explicit)) {
|
|
87
|
+
throw new BinaryNotFoundError(`no portolan executable at ${explicit}`);
|
|
88
|
+
}
|
|
89
|
+
return explicit;
|
|
90
|
+
}
|
|
91
|
+
const env = process.env.PORTOLAN_BIN;
|
|
92
|
+
if (env) {
|
|
93
|
+
if (!existsSync(env)) {
|
|
94
|
+
throw new BinaryNotFoundError(`PORTOLAN_BIN is set to ${env}, which does not exist`);
|
|
95
|
+
}
|
|
96
|
+
return env;
|
|
97
|
+
}
|
|
98
|
+
const key = platformKey();
|
|
99
|
+
if (!SUPPORTED.includes(key)) {
|
|
100
|
+
throw new BinaryNotFoundError(`portolan has no build for ${key}. Supported: ${SUPPORTED.join(", ")}. ` +
|
|
101
|
+
`Point PORTOLAN_BIN at a binary you built yourself if you have one.`);
|
|
102
|
+
}
|
|
103
|
+
const exe = process.platform === "win32" ? "portolan.exe" : "portolan";
|
|
104
|
+
const path = join(packageRoot(), "bin", key, exe);
|
|
105
|
+
if (!existsSync(path)) {
|
|
106
|
+
// The binaries are committed to the PUBLISHED package, not to the repo,
|
|
107
|
+
// so the ordinary way to see this is running from a source checkout that
|
|
108
|
+
// has not staged them yet. A published package missing one is a broken
|
|
109
|
+
// publish — the `files` field or the staging step, not the consumer.
|
|
110
|
+
throw new BinaryNotFoundError(`@alexwohlbruck/portolan ${selfVersion()} has no bin/${key}/${exe}. ` +
|
|
111
|
+
`In a source checkout, stage the binaries first: ` +
|
|
112
|
+
`make dist && node clients/npm/scripts/build-universal.mjs. ` +
|
|
113
|
+
`In an installed package this is a broken publish — reinstall, or set PORTOLAN_BIN.`);
|
|
114
|
+
}
|
|
115
|
+
return path;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=binary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary.js","s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package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type Plnb } from "./plnb.js";
|
|
2
|
+
import type { PortolanServer } from "./server.js";
|
|
3
|
+
import type { Artifact, ChartRequest, ProgressEvent, VersionInfo } from "./types.js";
|
|
4
|
+
export declare class PortolanError extends Error {
|
|
5
|
+
readonly status?: number | undefined;
|
|
6
|
+
constructor(message: string, status?: number | undefined);
|
|
7
|
+
}
|
|
8
|
+
export interface ChartOptions {
|
|
9
|
+
/** Called for each progress event, including log lines. */
|
|
10
|
+
onProgress?: (e: ProgressEvent) => void;
|
|
11
|
+
/** Abort the build. Cancels server-side, not just locally. */
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}
|
|
14
|
+
/** A build in flight, or finished. */
|
|
15
|
+
export declare class Job {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
private readonly client;
|
|
18
|
+
constructor(id: string, client: PortolanClient);
|
|
19
|
+
/** Stream progress until the terminal frame. */
|
|
20
|
+
watch(onProgress?: (e: ProgressEvent) => void, signal?: AbortSignal): Promise<void>;
|
|
21
|
+
/** Abandon the build. The engine stops between stages. */
|
|
22
|
+
cancel(): Promise<void>;
|
|
23
|
+
/** Fetch an artifact as bytes. */
|
|
24
|
+
bytes(artifact?: Artifact): Promise<Uint8Array>;
|
|
25
|
+
/** Fetch and decode the binary segments. */
|
|
26
|
+
plnb(): Promise<Plnb>;
|
|
27
|
+
/** Fetch an artifact as parsed JSON. */
|
|
28
|
+
json<T = unknown>(artifact?: Artifact): Promise<T>;
|
|
29
|
+
}
|
|
30
|
+
export declare class PortolanClient {
|
|
31
|
+
private readonly origin;
|
|
32
|
+
private readonly headers;
|
|
33
|
+
constructor(origin: string, headers?: Record<string, string>);
|
|
34
|
+
/** Point a client at an already-running server. */
|
|
35
|
+
static at(origin: string, token?: string): PortolanClient;
|
|
36
|
+
/** Wrap a server this process started. */
|
|
37
|
+
static from(server: PortolanServer): PortolanClient;
|
|
38
|
+
version(): Promise<VersionInfo>;
|
|
39
|
+
/** Start a build. Returns as soon as the engine accepts it. */
|
|
40
|
+
start(req: ChartRequest): Promise<Job>;
|
|
41
|
+
/**
|
|
42
|
+
* Build and wait. The common case.
|
|
43
|
+
*
|
|
44
|
+
* Aborting cancels SERVER-side as well as locally: an interactive
|
|
45
|
+
* caller supersedes builds constantly, and one that keeps running
|
|
46
|
+
* after nobody wants it piles up behind the one they do.
|
|
47
|
+
*/
|
|
48
|
+
chart(req: ChartRequest, opts?: ChartOptions): Promise<Job>;
|
|
49
|
+
/** Follow a job's SSE stream until it ends. */
|
|
50
|
+
watch(id: string, onProgress?: (e: ProgressEvent) => void, signal?: AbortSignal): Promise<void>;
|
|
51
|
+
cancel(id: string): Promise<void>;
|
|
52
|
+
status(id: string): Promise<{
|
|
53
|
+
id: string;
|
|
54
|
+
done: boolean;
|
|
55
|
+
error?: string;
|
|
56
|
+
}>;
|
|
57
|
+
artifactBytes(id: string, artifact?: Artifact): Promise<Uint8Array>;
|
|
58
|
+
artifactJson<T = unknown>(id: string, artifact?: Artifact): Promise<T>;
|
|
59
|
+
plnb(id: string): Promise<Plnb>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAErF,qBAAa,aAAc,SAAQ,KAAK;IAGpC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;gBADxB,OAAO,EAAE,MAAM,EACN,MAAM,CAAC,EAAE,MAAM,YAAA;CAK3B;AAsCD,MAAM,WAAW,YAAY;IAC3B,2DAA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