@pipelex/sdk 0.46.1 → 0.47.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/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,6FAA6F;AAC7F,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,oFAAoF;AACpF,kFAAkF;AAClF,mFAAmF;AACnF,wBAAwB;AACxB,cAAc,gBAAgB,CAAC;AAE/B,wEAAwE;AACxE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACtF,sFAAsF;AACtF,yFAAyF;AACzF,2EAA2E;AAC3E,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAgBzF,+FAA+F;AAC/F,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,+FAA+F;AAC/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,+FAA+F;AAC/F,6FAA6F;AAC7F,iGAAiG;AACjG,8FAA8F;AAC9F,iEAAiE;AACjE,OAAO,EAAE,yBAAyB,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAEhG,iGAAiG;AACjG,kFAAkF;AAClF,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAK/E,yFAAyF;AACzF,sEAAsE;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AASpD,+FAA+F;AAC/F,0EAA0E;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,uEAAuE;AACvE,wFAAwF;AACxF,0FAA0F;AAC1F,iFAAiF;AACjF,OAAO,EACL,eAAe,EACf,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AmB,EACnB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,WAAW,CAAC;AAwBnB,oFAAoF;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAS5C,+EAA+E;AAC/E,gGAAgG;AAChG,8FAA8F;AAC9F,8EAA8E;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EACzB,2BAA2B,EAC3B,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,4BAA4B,EAC5B,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,gCAAgC,EAChC,yBAAyB,EACzB,oBAAoB,EACpB,sBAAsB,EACtB,2BAA2B,EAC3B,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,209 @@
1
+ /**
2
+ * A saved method's tree on the client side (see `docs/method-trees.md`): the source a save reads a
3
+ * tree from, how that tree becomes the `files` map a save sends, inline or by hash, the blob routes
4
+ * that let a large tree travel by hash (mthds/docs/spec/protocol.md, "Sending files by hash"), the
5
+ * upload of a blob the platform lacks, and the writing of a saved tree to disk.
6
+ *
7
+ * The tree-sending part mirrors the `mthds` npm package's own helpers, which its published
8
+ * `mthds/protocol` subpath does not export yet. This SDK imports `mthds` through that subpath alone,
9
+ * so it carries this copy, held to the same rule: the same inline threshold, the same text-or-Base64
10
+ * choice per file, and each file added as an own property. It needs no Node built-in: SHA-256 is Web
11
+ * Crypto's, and Base64 is written here. Only `writeMethodTreeTo` needs Node, which it loads when
12
+ * called.
13
+ */
14
+ import type { FileEntry, MethodFiles } from "mthds/protocol";
15
+ import { type MethodFileTransferCode } from "./errors.js";
16
+ import type { SavedMethodFile } from "./product-models.js";
17
+ /** A file of a {@link MethodTreeSource}. */
18
+ export interface MethodTreeSourceFile {
19
+ /** Its tree path. */
20
+ readonly path: string;
21
+ /** Its length in bytes. */
22
+ readonly size: number;
23
+ /** The SHA-256 of its bytes, in lowercase hexadecimal. */
24
+ readonly sha256: string;
25
+ }
26
+ /**
27
+ * A method tree a save reads from: its files, its digest, and a way to read each file's bytes. The
28
+ * `MethodTree` the `mthds` package's `listMethodTree` returns is one, so a tree listed from a
29
+ * directory, under the limits `methodTreeLimits` reports, is passed as it is.
30
+ */
31
+ export interface MethodTreeSource {
32
+ /** Every file of the tree, each tree path once. */
33
+ readonly files: readonly MethodTreeSourceFile[];
34
+ /** The tree digest, `sha256:` and 64 lowercase hexadecimal digits. */
35
+ readonly digest: string;
36
+ /** The bytes of the file at `treePath`, which must hash to the SHA-256 the listing gives it. */
37
+ readFile(treePath: string): Promise<Uint8Array>;
38
+ }
39
+ /**
40
+ * The limits a deployment holds a tree to, in the shape the `mthds` package's `listMethodTree`
41
+ * takes as its `limits` option, so a lister stops at the first breach before hashing anything. A
42
+ * limit the deployment does not announce is absent.
43
+ */
44
+ export interface MethodTreeLimits {
45
+ /** The most files a tree may hold. */
46
+ readonly maxFileCount?: number;
47
+ /** The largest one file may be, in bytes. */
48
+ readonly maxFileSize?: number;
49
+ /** The largest all the files together may be, in bytes. */
50
+ readonly maxTotalSize?: number;
51
+ }
52
+ /** A blob a sender is about to send by hash, named by its SHA-256 and its size. */
53
+ export interface BlobRef {
54
+ sha256: string;
55
+ size: number;
56
+ }
57
+ /**
58
+ * Body of `POST /v1/blobs/missing`: the blobs a sender is about to send by hash, each hash listed
59
+ * once, and the digest of the tree they make up, which lets a platform that holds that tree whole
60
+ * answer at once.
61
+ */
62
+ export interface MissingBlobsRequest {
63
+ blobs: BlobRef[];
64
+ digest?: string;
65
+ }
66
+ /**
67
+ * Where to upload one blob: its bytes as the whole body of a request with this method to this URL,
68
+ * carrying exactly these headers. The URL is signed by storage and is a bearer credential.
69
+ */
70
+ export interface UploadTarget {
71
+ method: string;
72
+ url: string;
73
+ headers: Record<string, string>;
74
+ [extension: string]: unknown;
75
+ }
76
+ /** A blob the platform lacks, with where to upload it. */
77
+ export interface MissingBlob {
78
+ sha256: string;
79
+ size: number;
80
+ upload: UploadTarget;
81
+ [extension: string]: unknown;
82
+ }
83
+ /** The `200` answer of `POST /v1/blobs/missing`; an empty `missing` means nothing to upload. */
84
+ export interface MissingBlobsResult {
85
+ missing: MissingBlob[];
86
+ [extension: string]: unknown;
87
+ }
88
+ /**
89
+ * The heaviest inline map, in bytes of its JSON serialization in UTF-8, that a save sends inline
90
+ * to a deployment keeping a blob store. Below it a tree is cheaper to send whole than to check and
91
+ * upload; above it every file travels by hash. `mthds`'s clients use the same threshold.
92
+ */
93
+ export declare const INLINE_TREE_MAX_BYTES: number;
94
+ /** How many blobs a save uploads at once, and how many files `writeMethodTree` downloads at once. */
95
+ export declare const MAX_CONCURRENT_TRANSFERS = 8;
96
+ /** Whether a version handshake declares a blob store (`blob_store: true`). */
97
+ export declare function declaresBlobStore(version: object): boolean;
98
+ /**
99
+ * The tree limits a version handshake announces under `limits.method_tree`. A value that is not a
100
+ * positive safe integer is left out rather than trusted, and a limit not announced is absent, so a
101
+ * bare runner, which announces none, yields no limit.
102
+ */
103
+ export declare function announcedTreeLimits(version: object): MethodTreeLimits;
104
+ /** What an inline map spends in a request: its JSON serialization with no whitespace, in UTF-8. */
105
+ export declare function inlineMapBytes(files: MethodFiles): number;
106
+ /** The total of a tree's file sizes, in bytes. */
107
+ export declare function treeTotalSize(tree: MethodTreeSource): number;
108
+ /** Every file's bytes, by tree path, each read and checked by the tree, one file at a time. */
109
+ export declare function readTreeBytes(tree: MethodTreeSource): Promise<Map<string, Uint8Array>>;
110
+ /** The whole tree as inline entries, from bytes already read by `readTreeBytes`. */
111
+ export declare function inlineFilesOf(tree: MethodTreeSource, bytesByPath: ReadonlyMap<string, Uint8Array>): MethodFiles;
112
+ /** The whole tree as hash entries, which the platform resolves in the organization's blobs. */
113
+ export declare function hashMethodFiles(tree: MethodTreeSource): MethodFiles;
114
+ /** Each blob of the tree once, in the tree's order: files with the same bytes share one blob. */
115
+ export declare function uniqueBlobs(tree: MethodTreeSource): BlobRef[];
116
+ /** A file of the tree holding each blob, so a missing blob's bytes can be read and uploaded. */
117
+ export declare function fileByBlob(tree: MethodTreeSource): Map<string, MethodTreeSourceFile>;
118
+ /**
119
+ * Run `task` over `items`, at most `limit` at a time. The first task to fail stops the run: no
120
+ * queued item is handed out after it, `signal` is aborted so the tasks still in flight can stop
121
+ * early, and once they have settled the first failure is thrown.
122
+ */
123
+ export declare function forEachConcurrently<T>(items: readonly T[], limit: number, task: (item: T, signal: AbortSignal) => Promise<void>): Promise<void>;
124
+ /**
125
+ * The tree whose files are `contents`, each file's bytes or its text by tree path, a text encoded
126
+ * in UTF-8. The keys are sent as they are, and the platform refuses one that is not a tree path,
127
+ * with the `422` `invalid_method_files` naming it. `call` names the caller's method in a refusal.
128
+ *
129
+ * Throws `RequestArgumentError` for `contents` holding no file, for a value that is neither a
130
+ * string nor bytes, and for a text holding a lone surrogate, which no file can hold.
131
+ */
132
+ export declare function contentsTreeSource(contents: Readonly<Record<string, Uint8Array | string>>, call: string): Promise<MethodTreeSource>;
133
+ /**
134
+ * The tree digest of a tree's files: `sha256:` and the SHA-256 of its listing, one line
135
+ * `<sha256> <path>` per file, in tree path order.
136
+ */
137
+ export declare function treeDigestOf(files: readonly MethodTreeSourceFile[]): Promise<string>;
138
+ /** The SHA-256 of `bytes`, in lowercase hexadecimal, by Web Crypto. */
139
+ export declare function sha256Hex(bytes: Uint8Array): Promise<string>;
140
+ /**
141
+ * Compare two strings byte for byte on their UTF-8 encoding, the order tree paths are sorted in.
142
+ * JavaScript's own string order compares UTF-16 code units, which puts a character above U+FFFF
143
+ * before one between U+E000 and U+FFFF, where UTF-8 puts it after.
144
+ */
145
+ export declare function compareUtf8(left: string, right: string): number;
146
+ /** The entry a file travels as inline: its text when its bytes are UTF-8, its Base64 otherwise. */
147
+ export declare function inlineFileEntry(bytes: Uint8Array): FileEntry;
148
+ /**
149
+ * Add a file to a map of file entries as an own property, since assigning to a key such as
150
+ * `__proto__`, a tree path like any other, would set the object's prototype instead of adding the
151
+ * file.
152
+ */
153
+ export declare function defineFileEntry(files: MethodFiles, treePath: string, entry: FileEntry): void;
154
+ /** Canonical padded standard Base64 (RFC 4648), with no line break and its pad bits zero. */
155
+ export declare function encodeBase64(bytes: Uint8Array): string;
156
+ /**
157
+ * Upload one blob's bytes to the target `POST /v1/blobs/missing` named: the bytes as the whole body
158
+ * of a request with the target's method to its URL, carrying exactly the target's headers and no
159
+ * credential of the client, since the signed URL authorizes the upload itself. A `412` from a
160
+ * target asking for a create-only write (`If-None-Match`) means the bytes are already stored, and
161
+ * counts as uploaded.
162
+ *
163
+ * Throws `MethodFileTransferError` (`operation` `upload`) when storage gives no answer within
164
+ * `timeoutMs` or answers any other non-2xx; neither its message nor any member carries the URL,
165
+ * nor storage's error body, which can echo the signed request.
166
+ */
167
+ export declare function uploadBlob(blob: MissingBlob, bytes: Uint8Array, options: {
168
+ timeoutMs: number;
169
+ signal?: AbortSignal;
170
+ }): Promise<void>;
171
+ /**
172
+ * The code of a transfer storage answered with a non-2xx `status`: `storage_error` for one the
173
+ * fallback table calls retryable (`408`, `429`, a `5xx` other than `501`), `refused` otherwise.
174
+ */
175
+ export declare function methodFileTransferCodeOfStatus(status: number): MethodFileTransferCode;
176
+ /**
177
+ * Write a saved tree to disk, each file of `files` at its tree path under `destination`; see
178
+ * `PipelexApiClient.writeMethodTree`. Node only: the file system modules are loaded when it runs.
179
+ */
180
+ export declare function writeMethodTreeTo(files: readonly SavedMethodFile[], destination: string, options: {
181
+ timeoutMs: number;
182
+ }): Promise<void>;
183
+ /**
184
+ * Refuse a listing whose paths could not be written as a tree, before anything is downloaded. A
185
+ * platform's listing holds tree paths that never collide; the check guards the disk against any
186
+ * other listing a caller hands over, such as one built by hand, since a path such as `../x` would
187
+ * be written outside the destination. Throws `RequestArgumentError`.
188
+ */
189
+ export declare function refuseUnwritableListing(files: readonly SavedMethodFile[]): void;
190
+ /**
191
+ * Why `candidate` is not a tree path, or `null` when it is one (mthds/docs/spec/method-tree.md,
192
+ * "Tree Paths"), the rule the `mthds` package's `treePathViolation` holds.
193
+ */
194
+ export declare function treePathViolation(candidate: string): string | null;
195
+ /**
196
+ * The paths that collide: those equal to another once case-folded, and those naming, once
197
+ * case-folded, a directory of another, with the paths under it, sorted byte for byte. The fold is
198
+ * `toUpperCase().toLowerCase()`, which agrees with Unicode full case folding on the scripts a file
199
+ * name uses; a pair it misses still fails the write, which never writes over a file.
200
+ */
201
+ export declare function pathCollisions(treePaths: readonly string[]): string[];
202
+ /**
203
+ * `text`, an answer that carries signed links, with every link hidden, for an error to hold: in a
204
+ * JSON body every `url` member, at any depth, is replaced whole, and in any text, JSON or not, a
205
+ * truncated body included, the query of every `http(s)` link is replaced, since a signed link's
206
+ * signature rides its query. A link is a bearer credential, so no error, message or member may
207
+ * carry one.
208
+ */
209
+ export declare function redactSignedLinks(text: string): string;