@opencraw/driver 0.5.0 → 0.7.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/README.md +13 -0
- package/dist/index.esm.js +33 -0
- package/dist/main.esm.js +6 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/runtime-manifest/index.d.ts +4 -0
- package/dist/src/runtime-manifest/runtime-manifest-json-schema.mapper.d.ts +8 -0
- package/dist/src/runtime-manifest/runtime-manifest.contract.d.ts +28 -0
- package/package.json +1 -1
- package/schemas/driver-runtime.fixture.json +9 -0
- package/schemas/driver-runtime.schema.json +63 -0
package/README.md
CHANGED
|
@@ -60,6 +60,19 @@ stdin at once. Answers may arrive out of order; match them by `id`.
|
|
|
60
60
|
`-32602` (bad params, the problems listed), `-32000` (a failure to act on: its message says what to do).
|
|
61
61
|
- stdout carries protocol messages only. The driver's own logs go to stderr.
|
|
62
62
|
|
|
63
|
+
## The runtime: no Node needed
|
|
64
|
+
|
|
65
|
+
Each driver release carries, as assets of its GitHub release `driver@<version>`, an archive per platform
|
|
66
|
+
(`win32-x64`, `darwin-arm64`, `darwin-x64`, `linux-x64`, `linux-arm64`): a Node binary, the driver and its
|
|
67
|
+
dependencies, and `runtime.json`, whose `command` starts it (both paths relative to the unpacked folder).
|
|
68
|
+
`driver-runtime.json` lists them with their SHA-256 and size; its schema is `schemas/driver-runtime.schema.json`
|
|
69
|
+
and `schemas/driver-runtime.fixture.json` is an example. A client downloads its platform's archive once, refuses
|
|
70
|
+
one whose hash does not match, unpacks it into a per-user cache and starts the driver from there.
|
|
71
|
+
|
|
72
|
+
`node packages/driver/packaging/stage-runtime.mjs` builds this platform's archive into `dist/drop/driver-runtime`
|
|
73
|
+
(after `smith build -p driver`), and starts the staged driver once with `PATH` emptied, to prove it needs nothing
|
|
74
|
+
else. Browsers are not in it: they are installed through the driver, the Playwright way.
|
|
75
|
+
|
|
63
76
|
## Development
|
|
64
77
|
|
|
65
78
|
`smith run lint typecheck test build -p driver`. After changing a contract in `src/protocol/`, run
|
package/dist/index.esm.js
CHANGED
|
@@ -512,8 +512,10 @@ function openLineChannel(input, output, handle) {
|
|
|
512
512
|
if (typeof message.method === "string") track(answer(message));
|
|
513
513
|
else settle(message);
|
|
514
514
|
});
|
|
515
|
+
let ended = false;
|
|
515
516
|
const closed = new Promise((resolve) => {
|
|
516
517
|
lines.on("close", () => {
|
|
518
|
+
ended = true;
|
|
517
519
|
for (const waiting of pending.values()) waiting.reject(new Error("the client closed the channel"));
|
|
518
520
|
pending.clear();
|
|
519
521
|
resolve();
|
|
@@ -521,6 +523,10 @@ function openLineChannel(input, output, handle) {
|
|
|
521
523
|
});
|
|
522
524
|
return {
|
|
523
525
|
request: async (method, params) => await new Promise((resolve, reject) => {
|
|
526
|
+
if (ended) {
|
|
527
|
+
reject(new Error("the channel is closed"));
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
524
530
|
const id = nextId++;
|
|
525
531
|
pending.set(id, { resolve, reject });
|
|
526
532
|
write({ jsonrpc: "2.0", id, method, params });
|
|
@@ -575,10 +581,35 @@ async function serveDriver(input, output, identity) {
|
|
|
575
581
|
await channel.drained();
|
|
576
582
|
await sessions.closeAll();
|
|
577
583
|
}
|
|
584
|
+
|
|
585
|
+
// src/runtime-manifest/runtime-manifest.contract.ts
|
|
586
|
+
import { z as z3 } from "zod";
|
|
587
|
+
var RUNTIME_PLATFORMS = ["win32-x64", "darwin-arm64", "darwin-x64", "linux-x64", "linux-arm64"];
|
|
588
|
+
var archiveSchema = z3.strictObject({
|
|
589
|
+
/** The archive's file name, an asset of the same GitHub release as the manifest. */
|
|
590
|
+
file: z3.string().regex(/^opencraw-driver-[\w.-]+\.tar\.gz$/),
|
|
591
|
+
/** Its SHA-256, lowercase hex: a client refuses an archive that does not match. */
|
|
592
|
+
sha256: z3.string().regex(/^[0-9a-f]{64}$/),
|
|
593
|
+
size: z3.number().int().positive()
|
|
594
|
+
});
|
|
595
|
+
var runtimeManifestSchema = z3.strictObject({
|
|
596
|
+
driverVersion: z3.string().min(1),
|
|
597
|
+
protocolVersion: z3.string().regex(/^\d+\.\d+\.\d+$/),
|
|
598
|
+
/** The Node version every archive carries. */
|
|
599
|
+
node: z3.string().regex(/^v\d+\.\d+\.\d+$/),
|
|
600
|
+
archives: z3.partialRecord(z3.enum(RUNTIME_PLATFORMS), archiveSchema)
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
// src/runtime-manifest/runtime-manifest-json-schema.mapper.ts
|
|
604
|
+
import { z as z4 } from "zod";
|
|
605
|
+
function runtimeManifestJsonSchema() {
|
|
606
|
+
return { $id: "https://opencraw.dev/schemas/driver-runtime.schema.json", ...z4.toJSONSchema(runtimeManifestSchema, { target: "draft-2020-12" }) };
|
|
607
|
+
}
|
|
578
608
|
export {
|
|
579
609
|
MESSAGES,
|
|
580
610
|
PROTOCOL_VERSION,
|
|
581
611
|
RPC_ERRORS,
|
|
612
|
+
RUNTIME_PLATFORMS,
|
|
582
613
|
RpcFailure,
|
|
583
614
|
calloutParamsSchema,
|
|
584
615
|
calloutResultSchema,
|
|
@@ -607,6 +638,8 @@ export {
|
|
|
607
638
|
runParamsSchema,
|
|
608
639
|
runResultSchema,
|
|
609
640
|
runSessions,
|
|
641
|
+
runtimeManifestJsonSchema,
|
|
642
|
+
runtimeManifestSchema,
|
|
610
643
|
serveDriver,
|
|
611
644
|
streamingSink,
|
|
612
645
|
validateParamsSchema,
|
package/dist/main.esm.js
CHANGED
|
@@ -473,8 +473,10 @@ function openLineChannel(input, output, handle) {
|
|
|
473
473
|
if (typeof message.method === "string") track(answer(message));
|
|
474
474
|
else settle(message);
|
|
475
475
|
});
|
|
476
|
+
let ended = false;
|
|
476
477
|
const closed = new Promise((resolve) => {
|
|
477
478
|
lines.on("close", () => {
|
|
479
|
+
ended = true;
|
|
478
480
|
for (const waiting of pending.values()) waiting.reject(new Error("the client closed the channel"));
|
|
479
481
|
pending.clear();
|
|
480
482
|
resolve();
|
|
@@ -482,6 +484,10 @@ function openLineChannel(input, output, handle) {
|
|
|
482
484
|
});
|
|
483
485
|
return {
|
|
484
486
|
request: async (method, params) => await new Promise((resolve, reject) => {
|
|
487
|
+
if (ended) {
|
|
488
|
+
reject(new Error("the channel is closed"));
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
485
491
|
const id = nextId++;
|
|
486
492
|
pending.set(id, { resolve, reject });
|
|
487
493
|
write({ jsonrpc: "2.0", id, method, params });
|
package/dist/src/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { serveDriver } from './server/index.js';
|
|
|
2
2
|
export type { DriverIdentity } from './server/index.js';
|
|
3
3
|
export { PROTOCOL_VERSION, MESSAGES, driverProtocolJsonSchema, initializeParamsSchema, initializeResultSchema, validateParamsSchema, validateResultSchema, runParamsSchema, runResultSchema, cancelParamsSchema, cancelResultSchema, eventParamsSchema, recordParamsSchema, finishedParamsSchema, calloutParamsSchema, calloutResultSchema, probeParamsSchema, probeResultSchema, diffParamsSchema, diffResultSchema, exportParamsSchema, exportResultSchema, workParamsSchema, workItemSchema, workNextParamsSchema, workNextResultSchema, workDoneParamsSchema, workFailedParamsSchema, } from './protocol/index.js';
|
|
4
4
|
export type { InitializeParams, InitializeResult, ValidateParams, ValidateResult, RunParams, RunResult, CancelParams, CancelResult, EventParams, RecordParams, FinishedParams, CalloutParams, ProbeParams, DiffParams, DiffResult, ExportParams, ExportResult, WorkParams, WorkItemMessage, WorkNextResult, WorkDoneParams, WorkFailedParams, } from './protocol/index.js';
|
|
5
|
+
export { RUNTIME_PLATFORMS, runtimeManifestSchema, runtimeManifestJsonSchema } from './runtime-manifest/index.js';
|
|
6
|
+
export type { RuntimeManifest, RuntimePlatform } from './runtime-manifest/index.js';
|
|
5
7
|
export { openLineChannel, RPC_ERRORS, RpcFailure } from './transport/index.js';
|
|
6
8
|
export type { LineChannel, RequestHandler, RpcError, RpcMessage } from './transport/index.js';
|
|
7
9
|
export { runSessions, validateRecipes, streamingSink } from './session/index.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { RUNTIME_PLATFORMS, runtimeManifestSchema } from './runtime-manifest.contract.js';
|
|
2
|
+
export type { RuntimeManifest, RuntimePlatform } from './runtime-manifest.contract.js';
|
|
3
|
+
export { runtimeManifestJsonSchema } from './runtime-manifest-json-schema.mapper.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `driver-runtime.json`'s JSON Schema, written to `schemas/driver-runtime.schema.json`: what clients in
|
|
3
|
+
* other languages generate their manifest model from.
|
|
4
|
+
*
|
|
5
|
+
* @returns The schema.
|
|
6
|
+
*/
|
|
7
|
+
export declare function runtimeManifestJsonSchema(): Record<string, unknown>;
|
|
8
|
+
//# sourceMappingURL=runtime-manifest-json-schema.mapper.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The platforms the driver's runtime is built for: `<process.platform>-<process.arch>`. */
|
|
3
|
+
export declare const RUNTIME_PLATFORMS: readonly ['win32-x64', 'darwin-arm64', 'darwin-x64', 'linux-x64', 'linux-arm64'];
|
|
4
|
+
export type RuntimePlatform = typeof RUNTIME_PLATFORMS[number];
|
|
5
|
+
/**
|
|
6
|
+
* `driver-runtime.json`, an asset of each driver release beside the archives: what a client in any
|
|
7
|
+
* language reads to download the runtime for its platform, check it and start it. The archive holds a
|
|
8
|
+
* Node binary, the driver and its dependencies, and `runtime.json` (`command`: the Node binary and the
|
|
9
|
+
* driver's entry, both relative to the folder the archive is unpacked into).
|
|
10
|
+
*/
|
|
11
|
+
export declare const runtimeManifestSchema: z.ZodObject<{
|
|
12
|
+
driverVersion: z.ZodString;
|
|
13
|
+
protocolVersion: z.ZodString;
|
|
14
|
+
node: z.ZodString;
|
|
15
|
+
archives: z.ZodRecord<z.ZodEnum<{
|
|
16
|
+
"darwin-arm64": "darwin-arm64";
|
|
17
|
+
"darwin-x64": "darwin-x64";
|
|
18
|
+
"linux-arm64": "linux-arm64";
|
|
19
|
+
"linux-x64": "linux-x64";
|
|
20
|
+
"win32-x64": "win32-x64";
|
|
21
|
+
}> & z.core.$partial, z.ZodObject<{
|
|
22
|
+
file: z.ZodString;
|
|
23
|
+
sha256: z.ZodString;
|
|
24
|
+
size: z.ZodNumber;
|
|
25
|
+
}, z.core.$strict>>;
|
|
26
|
+
}, z.core.$strict>;
|
|
27
|
+
export type RuntimeManifest = z.infer<typeof runtimeManifestSchema>;
|
|
28
|
+
//# sourceMappingURL=runtime-manifest.contract.d.ts.map
|
package/package.json
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"driverVersion": "0.6.0",
|
|
3
|
+
"protocolVersion": "1.2.0",
|
|
4
|
+
"node": "v24.12.0",
|
|
5
|
+
"archives": {
|
|
6
|
+
"linux-x64": { "file": "opencraw-driver-0.6.0-linux-x64.tar.gz", "sha256": "697d28005ed87b2887cf79edca25f06da89ab19bcb48f49c0a67dbdbcb004ad7", "size": 65410362 },
|
|
7
|
+
"win32-x64": { "file": "opencraw-driver-0.6.0-win32-x64.tar.gz", "sha256": "0f1e2d3c4b5a69788796a5b4c3d2e1f00f1e2d3c4b5a69788796a5b4c3d2e1f0", "size": 66120448 }
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$id": "https://opencraw.dev/schemas/driver-runtime.schema.json",
|
|
3
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"properties": {
|
|
6
|
+
"driverVersion": {
|
|
7
|
+
"type": "string",
|
|
8
|
+
"minLength": 1
|
|
9
|
+
},
|
|
10
|
+
"protocolVersion": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"pattern": "^\\d+\\.\\d+\\.\\d+$"
|
|
13
|
+
},
|
|
14
|
+
"node": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"pattern": "^v\\d+\\.\\d+\\.\\d+$"
|
|
17
|
+
},
|
|
18
|
+
"archives": {
|
|
19
|
+
"type": "object",
|
|
20
|
+
"propertyNames": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"enum": [
|
|
23
|
+
"win32-x64",
|
|
24
|
+
"darwin-arm64",
|
|
25
|
+
"darwin-x64",
|
|
26
|
+
"linux-x64",
|
|
27
|
+
"linux-arm64"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"additionalProperties": {
|
|
31
|
+
"type": "object",
|
|
32
|
+
"properties": {
|
|
33
|
+
"file": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"pattern": "^opencraw-driver-[\\w.-]+\\.tar\\.gz$"
|
|
36
|
+
},
|
|
37
|
+
"sha256": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"pattern": "^[0-9a-f]{64}$"
|
|
40
|
+
},
|
|
41
|
+
"size": {
|
|
42
|
+
"type": "integer",
|
|
43
|
+
"exclusiveMinimum": 0,
|
|
44
|
+
"maximum": 9007199254740991
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"required": [
|
|
48
|
+
"file",
|
|
49
|
+
"sha256",
|
|
50
|
+
"size"
|
|
51
|
+
],
|
|
52
|
+
"additionalProperties": false
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"required": [
|
|
57
|
+
"driverVersion",
|
|
58
|
+
"protocolVersion",
|
|
59
|
+
"node",
|
|
60
|
+
"archives"
|
|
61
|
+
],
|
|
62
|
+
"additionalProperties": false
|
|
63
|
+
}
|