@statewalker/webrun-files-rpc 0.0.0-stage → 0.1.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.
@@ -0,0 +1,45 @@
1
+ import type { FileInfo, FileStats, FilesApi, ListOptions, ReadOptions } from "@statewalker/webrun-files";
2
+ import type { FilesRpc } from "./types.js";
3
+ export interface FilesRpcClientOptions {
4
+ /** The server's methods, through any transport (a stub, a proxy, the server itself). */
5
+ rpc: FilesRpc;
6
+ /** Bytes per chunk written. Default 256 KiB (keep it at most the server's `maxChunkSize`). */
7
+ chunkSize?: number;
8
+ /** Chunk requests kept in flight while reading. Default 4 (below the server's `window`). */
9
+ readAhead?: number;
10
+ /** Chunks sent and not yet acknowledged while writing. Default 4. */
11
+ writeAhead?: number;
12
+ /** Listing page size. Default 256. */
13
+ pageSize?: number;
14
+ }
15
+ /** A FilesApi whose every call goes through a FilesRpc; content moves in keyed chunks. */
16
+ export declare class FilesRpcClient implements FilesApi {
17
+ #private;
18
+ constructor(options: FilesRpcClientOptions);
19
+ /**
20
+ * Asks for chunks 0, 1, 2, … keeping `readAhead` requests in flight, and yields them in key
21
+ * order whatever order the answers come in.
22
+ */
23
+ read(path: string, options?: ReadOptions): AsyncIterable<Uint8Array>;
24
+ /**
25
+ * Sends chunks of `chunkSize` bytes keyed 0, 1, 2, … with up to `writeAhead` unacknowledged,
26
+ * then `closeWrite` with their count; any failure aborts the write.
27
+ */
28
+ write(path: string, content: Iterable<Uint8Array> | AsyncIterable<Uint8Array>): Promise<void>;
29
+ /**
30
+ * Adds `content` to the end of `path` (creating it if it does not exist), streamed as `write`
31
+ * streams. The server appends through the served FilesApi's own `append`, or emulates it.
32
+ */
33
+ append(path: string, content: Iterable<Uint8Array> | AsyncIterable<Uint8Array>): Promise<void>;
34
+ mkdir(path: string): Promise<void>;
35
+ /** Pages of `pageSize`, each asked after the last path of the one before. */
36
+ list(path: string, options?: ListOptions): AsyncIterable<FileInfo>;
37
+ stats(path: string): Promise<FileStats | undefined>;
38
+ exists(path: string): Promise<boolean>;
39
+ remove(path: string): Promise<boolean>;
40
+ move(source: string, target: string): Promise<boolean>;
41
+ copy(source: string, target: string): Promise<boolean>;
42
+ }
43
+ /** A FilesApi over a FilesRpc. */
44
+ export declare function newFilesRpcClient(options: FilesRpcClientOptions): FilesRpcClient;
45
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,WAAW,EACX,WAAW,EACZ,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,YAAY,CAAC;AAEvD,MAAM,WAAW,qBAAqB;IACpC,wFAAwF;IACxF,GAAG,EAAE,QAAQ,CAAC;IACd,8FAA8F;IAC9F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4FAA4F;IAC5F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAyCD,0FAA0F;AAC1F,qBAAa,cAAe,YAAW,QAAQ;;IAO7C,YAAY,OAAO,EAAE,qBAAqB,EAMzC;IAED;;;OAGG;IACI,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,aAAa,CAAC,UAAU,CAAC,CA4C9E;IAED;;;OAGG;IACG,KAAK,CACT,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,GACxD,OAAO,CAAC,IAAI,CAAC,CAEf;IAED;;;OAGG;IACG,MAAM,CACV,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,GACxD,OAAO,CAAC,IAAI,CAAC,CAEf;IAsCK,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvC;IAED,6EAA6E;IACtE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,aAAa,CAAC,QAAQ,CAAC,CAY5E;IAED,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAElD;IACD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAErC;IACD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAErC;IACD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAErD;IACD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAErD;CACF;AAED,kCAAkC;AAClC,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAEhF"}
@@ -0,0 +1,13 @@
1
+ import type { FilesRpcErrorCode } from "./types.js";
2
+ /**
3
+ * An error of the protocol itself. The code also leads the message (`UNKNOWN_STREAM: …`), since
4
+ * a structured clone keeps an error's name and message but not its other properties:
5
+ * `errorCode(e)` reads it back on the other side of a transport.
6
+ */
7
+ export declare class FilesRpcError extends Error {
8
+ readonly code: FilesRpcErrorCode;
9
+ constructor(code: FilesRpcErrorCode, message: string);
10
+ }
11
+ /** The FilesRpcError code of an error, also after it crossed a transport; undefined otherwise. */
12
+ export declare function errorCode(e: unknown): FilesRpcErrorCode | undefined;
13
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,YAAY,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,EAInD;CACF;AAED,kGAAkG;AAClG,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,iBAAiB,GAAG,SAAS,CAMnE"}