@opencraw/driver 0.0.0-stage → 0.1.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 +59 -2
- package/dist/index.esm.js +373 -0
- package/dist/main.esm.js +334 -0
- package/dist/src/callout-bridge/client-hooks.client.d.ts +19 -0
- package/dist/src/callout-bridge/index.d.ts +3 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/main.d.ts +3 -0
- package/dist/src/protocol/driver-json-schema.mapper.d.ts +9 -0
- package/dist/src/protocol/driver-message.contract.d.ts +251 -0
- package/dist/src/protocol/index.d.ts +4 -0
- package/dist/src/server/index.d.ts +3 -0
- package/dist/src/server/serve-driver.use-case.d.ts +17 -0
- package/dist/src/session/index.d.ts +5 -0
- package/dist/src/session/recipe-loading.use-case.d.ts +23 -0
- package/dist/src/session/run-session.use-case.d.ts +24 -0
- package/dist/src/session/streaming-sink.repository.d.ts +8 -0
- package/dist/src/transport/index.d.ts +5 -0
- package/dist/src/transport/json-rpc.contract.d.ts +31 -0
- package/dist/src/transport/line-channel.client.d.ts +27 -0
- package/package.json +45 -4
- package/schemas/driver-protocol.schema.json +539 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RecipeSet, RecipeSource } from '@opencraw/core';
|
|
2
|
+
import type { ValidateParams, ValidateResult } from '../protocol/index.js';
|
|
3
|
+
/** The recipes a method names: files and folders, or the recipes themselves. Exactly one of the two. */
|
|
4
|
+
export declare function sourceOf(params: {
|
|
5
|
+
paths?: string[];
|
|
6
|
+
recipes?: Record<string, unknown>[];
|
|
7
|
+
}): RecipeSource;
|
|
8
|
+
/** Loads and binds a method's recipes, keeping the input ids in `only`. */
|
|
9
|
+
export declare function loadRecipes(params: {
|
|
10
|
+
paths?: string[];
|
|
11
|
+
recipes?: Record<string, unknown>[];
|
|
12
|
+
only?: string[];
|
|
13
|
+
}): Promise<RecipeSet>;
|
|
14
|
+
/** Every hook the set's input recipes call, once each, sorted. */
|
|
15
|
+
export declare function hooksOf(set: RecipeSet): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Checks recipes the way `run` would load them, without running them.
|
|
18
|
+
*
|
|
19
|
+
* @param params - The recipes and the input ids to keep.
|
|
20
|
+
* @returns Whether they load, the inputs and hooks a run would have, and every problem with its path.
|
|
21
|
+
*/
|
|
22
|
+
export declare function validateRecipes(params: ValidateParams): Promise<ValidateResult>;
|
|
23
|
+
//# sourceMappingURL=recipe-loading.use-case.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AskClient } from '../callout-bridge/index.js';
|
|
2
|
+
import type { RunParams } from '../protocol/index.js';
|
|
3
|
+
/** Sends a notification to the client. */
|
|
4
|
+
export type NotifyClient = (method: string, params: unknown) => void;
|
|
5
|
+
/** The runs a driver has going, by id, so `cancel` can reach them and `shutdown` close them all. */
|
|
6
|
+
export interface RunSessions {
|
|
7
|
+
start: (params: RunParams) => Promise<string>;
|
|
8
|
+
cancel: (runId: string) => Promise<boolean>;
|
|
9
|
+
closeAll: () => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Starts and tracks runs. `start` loads and binds the recipes (a bad recipe fails the `run` request
|
|
13
|
+
* itself, with its problems), answers with a run id at once, and crawls in the background: every crawl
|
|
14
|
+
* event goes to the client as an `event` notification, every record as a `record` one unless `out`
|
|
15
|
+
* names a file, and the end as `finished` with the report. A hook the client serves is asked back with
|
|
16
|
+
* a `callout` request. `cancel` closes the run's crawler, which stops its recipes; the run still ends
|
|
17
|
+
* with `finished`.
|
|
18
|
+
*
|
|
19
|
+
* @param notify - The channel's notify.
|
|
20
|
+
* @param ask - The channel's request, for callouts.
|
|
21
|
+
* @returns The sessions.
|
|
22
|
+
*/
|
|
23
|
+
export declare function runSessions(notify: NotifyClient, ask: AskClient): RunSessions;
|
|
24
|
+
//# sourceMappingURL=run-session.use-case.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RecordSink } from '@opencraw/core';
|
|
2
|
+
/**
|
|
3
|
+
* The sink of a run with no `out` file: it keeps nothing, since each record already reached the client
|
|
4
|
+
* as a `record` notification from its `record:emit` event, and only counts them for the report. A long
|
|
5
|
+
* crawl therefore streams in constant memory.
|
|
6
|
+
*/
|
|
7
|
+
export declare function streamingSink(): RecordSink;
|
|
8
|
+
//# sourceMappingURL=streaming-sink.repository.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { openLineChannel } from './line-channel.client.js';
|
|
2
|
+
export type { LineChannel, RequestHandler } from './line-channel.client.js';
|
|
3
|
+
export { RPC_ERRORS, RpcFailure } from './json-rpc.contract.js';
|
|
4
|
+
export type { RpcError, RpcMessage } from './json-rpc.contract.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** JSON-RPC 2.0 error codes the driver answers with. */
|
|
2
|
+
export declare const RPC_ERRORS: {
|
|
3
|
+
readonly parse: -32700;
|
|
4
|
+
readonly invalidRequest: -32600;
|
|
5
|
+
readonly methodNotFound: -32601;
|
|
6
|
+
readonly invalidParams: -32602;
|
|
7
|
+
readonly internal: -32603;
|
|
8
|
+
/** A failure the caller must act on: the message says what to do. */
|
|
9
|
+
readonly server: -32000;
|
|
10
|
+
};
|
|
11
|
+
export interface RpcError {
|
|
12
|
+
code: number;
|
|
13
|
+
message: string;
|
|
14
|
+
data?: unknown;
|
|
15
|
+
}
|
|
16
|
+
/** A request (it has an id and wants a response) or a notification (no id). */
|
|
17
|
+
export interface RpcMessage {
|
|
18
|
+
jsonrpc: '2.0';
|
|
19
|
+
id?: number | string | null;
|
|
20
|
+
method?: string;
|
|
21
|
+
params?: unknown;
|
|
22
|
+
result?: unknown;
|
|
23
|
+
error?: RpcError;
|
|
24
|
+
}
|
|
25
|
+
/** An error a method handler throws to answer with a code other than `server`. */
|
|
26
|
+
export declare class RpcFailure extends Error {
|
|
27
|
+
readonly code: number;
|
|
28
|
+
readonly data: unknown;
|
|
29
|
+
constructor(code: number, message: string, data?: unknown);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=json-rpc.contract.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Readable, Writable } from 'node:stream';
|
|
2
|
+
/** Answers a request: its result, or a thrown error (an `RpcFailure` for a specific code). */
|
|
3
|
+
export type RequestHandler = (method: string, params: unknown) => Promise<unknown>;
|
|
4
|
+
/** JSON-RPC 2.0 both ways over a stream pair, one message per line. */
|
|
5
|
+
export interface LineChannel {
|
|
6
|
+
/** Sends a request to the other side and waits for its result; rejects with its error. */
|
|
7
|
+
request: (method: string, params: unknown) => Promise<unknown>;
|
|
8
|
+
/** Sends a notification: no answer is expected. */
|
|
9
|
+
notify: (method: string, params: unknown) => void;
|
|
10
|
+
/** Settles when the input ends (the other side closed it, or went away). */
|
|
11
|
+
closed: Promise<void>;
|
|
12
|
+
/** Settles once every request read so far has been answered: what to wait for before stopping. */
|
|
13
|
+
drained: () => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Opens a channel: every line read from `input` is a JSON-RPC message. A request goes to `handle` and its
|
|
17
|
+
* answer is written back; a response settles the matching `request`. A line that is not JSON gets a parse
|
|
18
|
+
* error, a message without `jsonrpc: "2.0"` an invalid-request error, and nothing it does stops the channel.
|
|
19
|
+
* Writes are one line each, never interleaved.
|
|
20
|
+
*
|
|
21
|
+
* @param input - Where messages arrive (the driver's stdin).
|
|
22
|
+
* @param output - Where they go (the driver's stdout).
|
|
23
|
+
* @param handle - What answers the other side's requests and notifications.
|
|
24
|
+
* @returns The channel.
|
|
25
|
+
*/
|
|
26
|
+
export declare function openLineChannel(input: Readable, output: Writable, handle: RequestHandler): LineChannel;
|
|
27
|
+
//# sourceMappingURL=line-channel.client.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencraw/driver",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OpenCraw's driver: the engine over JSON-RPC on stdio, for clients in other languages",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"smith": {
|
|
8
|
+
"kind": "package",
|
|
9
|
+
"stack": "node-vitest"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.esm.js",
|
|
12
|
+
"module": "./dist/index.esm.js",
|
|
13
|
+
"types": "./dist/src/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": "./package.json",
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/src/index.d.ts",
|
|
18
|
+
"import": "./dist/index.esm.js",
|
|
19
|
+
"default": "./dist/index.esm.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"bin": {
|
|
23
|
+
"opencraw-driver": "./dist/main.esm.js"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"schemas",
|
|
28
|
+
"!**/*.tsbuildinfo",
|
|
29
|
+
"!**/*.d.ts.map",
|
|
30
|
+
"!**/*.js.map"
|
|
31
|
+
],
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "esbuild src/index.ts src/main.ts --bundle --packages=external --platform=node --format=esm --outdir=dist --out-extension:.js=.esm.js --sourcemap && tsc -p tsconfig.build.json && node ../../declaration-specifiers.mjs dist/src",
|
|
37
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
38
|
+
"lint": "eslint .",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"schemas": "node tools/emit-protocol-schema.mjs"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@opencraw/cli": "^0.1.55",
|
|
44
|
+
"@opencraw/core": "^0.2.0",
|
|
45
|
+
"zod": "^4.6.5"
|
|
46
|
+
}
|
|
47
|
+
}
|