@yaks/blob 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +946 -2
- package/_dist/accepts.d.ts +38 -0
- package/_dist/accepts.d.ts.map +1 -0
- package/_dist/artifact.d.ts +29 -0
- package/_dist/artifact.d.ts.map +1 -0
- package/_dist/attachment.d.ts +53 -0
- package/_dist/attachment.d.ts.map +1 -0
- package/_dist/backend.d.ts +20 -0
- package/_dist/backend.d.ts.map +1 -0
- package/_dist/broken.d.ts +24 -0
- package/_dist/broken.d.ts.map +1 -0
- package/_dist/browser.d.ts +27 -0
- package/_dist/browser.d.ts.map +1 -0
- package/_dist/compare.d.ts +4 -0
- package/_dist/compare.d.ts.map +1 -0
- package/_dist/content_type.d.ts +20 -0
- package/_dist/content_type.d.ts.map +1 -0
- package/_dist/graph.d.ts +13 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/hydrate.d.ts +36 -0
- package/_dist/hydrate.d.ts.map +1 -0
- package/_dist/identify.d.ts +7 -0
- package/_dist/identify.d.ts.map +1 -0
- package/_dist/image.d.ts +37 -0
- package/_dist/image.d.ts.map +1 -0
- package/_dist/keywords.d.ts +10 -0
- package/_dist/keywords.d.ts.map +1 -0
- package/_dist/mime.d.ts +2 -0
- package/_dist/mime.d.ts.map +1 -0
- package/_dist/mod.d.ts +97 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/object-put.d.ts +2 -0
- package/_dist/object-put.d.ts.map +1 -0
- package/_dist/object.d.ts +175 -0
- package/_dist/object.d.ts.map +1 -0
- package/_dist/parts.d.ts +91 -0
- package/_dist/parts.d.ts.map +1 -0
- package/_dist/plugin.d.ts +38 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/png.d.ts +14 -0
- package/_dist/png.d.ts.map +1 -0
- package/_dist/props.d.ts +20 -0
- package/_dist/props.d.ts.map +1 -0
- package/_dist/representation.d.ts +17 -0
- package/_dist/representation.d.ts.map +1 -0
- package/_dist/representation_rules.d.ts +3 -0
- package/_dist/representation_rules.d.ts.map +1 -0
- package/_dist/routes.d.ts +65 -0
- package/_dist/routes.d.ts.map +1 -0
- package/_dist/serve.d.ts +29 -0
- package/_dist/serve.d.ts.map +1 -0
- package/_dist/sha256.d.ts +26 -0
- package/_dist/sha256.d.ts.map +1 -0
- package/_dist/sqlite.d.ts +57 -0
- package/_dist/sqlite.d.ts.map +1 -0
- package/_dist/store.d.ts +41 -0
- package/_dist/store.d.ts.map +1 -0
- package/_dist/stream.d.ts +91 -0
- package/_dist/stream.d.ts.map +1 -0
- package/_dist/upload.d.ts +114 -0
- package/_dist/upload.d.ts.map +1 -0
- package/_dist/value.d.ts +62 -0
- package/_dist/value.d.ts.map +1 -0
- package/_dist/vocab.d.ts +13 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/accepts.js +76 -0
- package/accepts.js.map +1 -0
- package/accepts.ts +95 -0
- package/artifact.js +50 -0
- package/artifact.js.map +1 -0
- package/artifact.ts +93 -0
- package/attachment.js +190 -0
- package/attachment.js.map +1 -0
- package/attachment.ts +201 -0
- package/backend.js +37 -0
- package/backend.js.map +1 -0
- package/backend.ts +44 -0
- package/broken.js +278 -0
- package/broken.js.map +1 -0
- package/broken.ts +217 -0
- package/browser.js +124 -0
- package/browser.js.map +1 -0
- package/browser.ts +179 -0
- package/compare.js +82 -0
- package/compare.js.map +1 -0
- package/compare.ts +90 -0
- package/content_type.js +43 -0
- package/content_type.js.map +1 -0
- package/content_type.ts +58 -0
- package/deno.json +1 -0
- package/fixed.js +53 -0
- package/fixed.js.map +1 -0
- package/fixed.ts +61 -0
- package/graph.js +15 -0
- package/graph.js.map +1 -0
- package/graph.ts +22 -0
- package/hydrate.js +69 -0
- package/hydrate.js.map +1 -0
- package/hydrate.ts +72 -0
- package/identify.js +38 -0
- package/identify.js.map +1 -0
- package/identify.ts +50 -0
- package/image.js +111 -0
- package/image.js.map +1 -0
- package/image.ts +120 -0
- package/keywords.js +28 -0
- package/keywords.js.map +1 -0
- package/keywords.ts +28 -0
- package/meta/blob.vocab.json +17 -0
- package/mime.js +72 -0
- package/mime.js.map +1 -0
- package/mime.ts +73 -0
- package/mod.js +97 -0
- package/mod.js.map +1 -0
- package/mod.ts +115 -0
- package/object-put.js +90 -0
- package/object-put.js.map +1 -0
- package/object-put.ts +114 -0
- package/object.js +369 -0
- package/object.js.map +1 -0
- package/object.ts +592 -0
- package/package.json +84 -4
- package/parts.js +354 -0
- package/parts.js.map +1 -0
- package/parts.ts +423 -0
- package/plugin.js +158 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +184 -0
- package/png.js +74 -0
- package/png.js.map +1 -0
- package/png.ts +58 -0
- package/props.js +32 -0
- package/props.js.map +1 -0
- package/props.ts +47 -0
- package/purge.js +65 -0
- package/purge.js.map +1 -0
- package/purge.ts +72 -0
- package/representation.js +34 -0
- package/representation.js.map +1 -0
- package/representation.ts +44 -0
- package/representation_rules.js +44 -0
- package/representation_rules.js.map +1 -0
- package/representation_rules.ts +57 -0
- package/routes.js +454 -0
- package/routes.js.map +1 -0
- package/routes.ts +575 -0
- package/serve.js +196 -0
- package/serve.js.map +1 -0
- package/serve.ts +242 -0
- package/sha256.js +185 -0
- package/sha256.js.map +1 -0
- package/sha256.ts +210 -0
- package/sqlite.js +201 -0
- package/sqlite.js.map +1 -0
- package/sqlite.ts +250 -0
- package/store.js +40 -0
- package/store.js.map +1 -0
- package/store.ts +93 -0
- package/stream.js +203 -0
- package/stream.js.map +1 -0
- package/stream.ts +256 -0
- package/upload.js +256 -0
- package/upload.js.map +1 -0
- package/upload.ts +404 -0
- package/value.js +234 -0
- package/value.js.map +1 -0
- package/value.ts +281 -0
- package/vocab.js +27 -0
- package/vocab.js.map +1 -0
- package/vocab.json +123 -0
- package/vocab.ts +32 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { type Clock } from "@yaks/fp";
|
|
2
|
+
import { type Discard } from "./object-put.js";
|
|
3
|
+
import type { Multipart } from "./parts.js";
|
|
4
|
+
import type { Blobs } from "./store.js";
|
|
5
|
+
import { type Put, type Staged, type Streamed } from "./stream.js";
|
|
6
|
+
/**
|
|
7
|
+
* The bucket these stores call, keyed by string. Cloudflare R2's `R2Bucket` is
|
|
8
|
+
* one of these; so is any object store wrapped to match.
|
|
9
|
+
*/ export type Bucket = {
|
|
10
|
+
/** whether an object exists under this key (its metadata, or null) */ head: (key: string) => Promise<{
|
|
11
|
+
size: number;
|
|
12
|
+
etag: string;
|
|
13
|
+
} | null>;
|
|
14
|
+
/** the object under this key, or null */ get: (key: string, options?: {
|
|
15
|
+
range: {
|
|
16
|
+
offset: number;
|
|
17
|
+
length: number;
|
|
18
|
+
};
|
|
19
|
+
}) => Promise<{
|
|
20
|
+
size: number;
|
|
21
|
+
etag: string;
|
|
22
|
+
body: ReadableStream<Uint8Array>;
|
|
23
|
+
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
24
|
+
} | null>;
|
|
25
|
+
/** write an object under this key; a stream must be of a known length,
|
|
26
|
+
* which {@link bucketObjects} gives it */ put: (key: string, value: ArrayBuffer | ArrayBufferView | string | ReadableStream<Uint8Array>) => Promise<unknown>;
|
|
27
|
+
/** remove the object under this key, or under each of these keys: at most
|
|
28
|
+
* {@link DELETES} of them in one call */ delete: (keys: string | string[]) => Promise<unknown>;
|
|
29
|
+
/** one page of the objects whose keys start with `prefix`, each with the
|
|
30
|
+
* moment it landed and its size in bytes; `cursor` continues a truncated
|
|
31
|
+
* page */ list: (opts: {
|
|
32
|
+
prefix: string;
|
|
33
|
+
cursor?: string;
|
|
34
|
+
limit?: number;
|
|
35
|
+
startAfter?: string;
|
|
36
|
+
}) => Promise<{
|
|
37
|
+
objects: {
|
|
38
|
+
key: string;
|
|
39
|
+
uploaded: Date;
|
|
40
|
+
size: number;
|
|
41
|
+
}[];
|
|
42
|
+
truncated: boolean;
|
|
43
|
+
cursor?: string;
|
|
44
|
+
}>;
|
|
45
|
+
};
|
|
46
|
+
/** The most keys one bucket delete takes: R2's own limit. */ export declare let DELETES: number;
|
|
47
|
+
/** R2's code, whether carried as a property or in the Workers binding's message. */ export declare let bucketCode: (e: unknown) => number | undefined;
|
|
48
|
+
/** Whether the bucket failed on its own side, including the Workers binding
|
|
49
|
+
* which carries R2's code in its message rather than on the Error. */ export declare let busy: (e: unknown) => boolean;
|
|
50
|
+
/** A bucket that kept failing on its own side through every attempt. */ export declare class BucketUnavailable extends Error {
|
|
51
|
+
name: string;
|
|
52
|
+
constructor(cause: unknown);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A bucket call, sent again while the bucket answers that it is busy: a burst
|
|
56
|
+
* of uploads to one space is enough for R2 to refuse some of them, and R2's
|
|
57
|
+
* internal error (10001) can last a few seconds. Each wait
|
|
58
|
+
* doubles from `wait` milliseconds, jittered so calls that collided once do not
|
|
59
|
+
* collide again, and after `tries` throws {@link BucketUnavailable} with the
|
|
60
|
+
* last answer as its cause: by default about six seconds of waiting, since a
|
|
61
|
+
* file that opens late is better than one that fails. Other failures are
|
|
62
|
+
* thrown at once. `pause` spends each wait, a timer unless the caller brings
|
|
63
|
+
* its own. Every call the stores below make to a bucket goes through it; a
|
|
64
|
+
* stream is read once, so a put of one is sent again only by a caller that
|
|
65
|
+
* can open its source again (`staging`).
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { patient } from '@yaks/blob'
|
|
69
|
+
* import { equal } from '@yaks/testing'
|
|
70
|
+
*
|
|
71
|
+
* let calls = 0, waits: number[] = []
|
|
72
|
+
* let list = () =>
|
|
73
|
+
* ++calls < 3 ? Promise.reject({ code: 10058 }) : Promise.resolve(['a/x'])
|
|
74
|
+
* let pause = (ms: number) => Promise.resolve(void waits.push(ms))
|
|
75
|
+
* equal(await patient(list, pause), ['a/x'])
|
|
76
|
+
* equal(waits.length, 2)
|
|
77
|
+
* ```
|
|
78
|
+
*/ export declare let patient: <T>(call: () => Promise<T>, pause?: (ms: number) => Promise<void>, tries?: number, wait?: number) => Promise<T>;
|
|
79
|
+
/** An object replaced by another writer between opening it and reading its
|
|
80
|
+
* bytes. Its reader holds a stale version: open the key again. */ export declare class ObjectChanged extends Error {
|
|
81
|
+
name: string;
|
|
82
|
+
constructor(key: string);
|
|
83
|
+
}
|
|
84
|
+
/** A stored object's length and validator, with its body read on demand. */ export type Opened = {
|
|
85
|
+
size: number;
|
|
86
|
+
version: string;
|
|
87
|
+
read: (range?: {
|
|
88
|
+
from: number;
|
|
89
|
+
to: number;
|
|
90
|
+
}) => Promise<ReadableStream<Uint8Array>>;
|
|
91
|
+
};
|
|
92
|
+
/** Bytes in hand, opened the way a stored object is. */ export declare let openedOf: (bytes: Uint8Array, version?: string) => Opened;
|
|
93
|
+
/** View a bounded span of an opened object as a file in its own right. */ export declare let sliceOf: (object: Opened | null | undefined, offset: number, size: number, version: string) => Opened | null;
|
|
94
|
+
export type Loaded = {
|
|
95
|
+
bytes: Uint8Array<ArrayBuffer>;
|
|
96
|
+
version: string;
|
|
97
|
+
};
|
|
98
|
+
type Pause = (ms: number) => Promise<void>;
|
|
99
|
+
/** Open a whole object with a single GET. A first-chunk failure can still
|
|
100
|
+
* fail the response, and an interrupted body resumes at its last byte. */ export declare let wholeObject: (bucket: Pick<Bucket, 'get'>, key: string, pause?: Pause) => Promise<{
|
|
101
|
+
size: number;
|
|
102
|
+
body: ReadableStream<Uint8Array>;
|
|
103
|
+
} | null>;
|
|
104
|
+
/** Read an object up to the caller's byte limit. Missing objects return null;
|
|
105
|
+
* objects above the limit return undefined. */ export declare let smallObject: (bucket: Pick<Bucket, 'get'>, key: string, most: number, pause?: Pause) => Promise<Uint8Array<ArrayBuffer> | null | undefined>;
|
|
106
|
+
/**
|
|
107
|
+
* A {@link Blobs} over an object store. `prefix` namespaces the keys, for a
|
|
108
|
+
* bucket that holds more than these objects.
|
|
109
|
+
*
|
|
110
|
+
* ```ts
|
|
111
|
+
* import { objectBlobs } from '@yaks/blob'
|
|
112
|
+
*
|
|
113
|
+
* // in a Worker, where `env.BLOBS` is an R2 binding
|
|
114
|
+
* // let store = objectBlobs(env.BLOBS, 'bodies/')
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* Asynchronous, so a graph writing through it applies asynchronously.
|
|
118
|
+
*/ export declare let objectBlobs: (bucket: Pick<Bucket, 'head' | 'get' | 'put' | 'delete'> & Partial<Multipart>, prefix?: string, pause?: Pause) => Blobs;
|
|
119
|
+
/** Where a stream waits, under a key of its own, until its address is known
|
|
120
|
+
* (`staging`). Whatever is left here was dropped by a process that ended
|
|
121
|
+
* before it could let it go. */ export declare let STAGING: string;
|
|
122
|
+
/**
|
|
123
|
+
* A content-addressed store's `stage` over a store keyed by name: the stream
|
|
124
|
+
* lands at a key under {@link STAGING}, hashed as it passes, and `keep` moves
|
|
125
|
+
* it to `prefix` and its address. A bucket has no copy, so the move streams
|
|
126
|
+
* the staged object into the put, and is sent again, from a fresh read, while
|
|
127
|
+
* the bucket answers that it is busy.
|
|
128
|
+
*/ export declare let staging: (objects: Pick<Objects, 'open' | 'has' | 'delete'> & {
|
|
129
|
+
put: (key: string, sent: Streamed) => Promise<void>;
|
|
130
|
+
}, prefix: string, pause?: Pause, discard?: Discard) => any;
|
|
131
|
+
/**
|
|
132
|
+
* The {@link Blobs} kept in `objects` under `prefix`, each by its address
|
|
133
|
+
* after it: a host's bucket as the host reaches it, counted or cached,
|
|
134
|
+
* holding one app's files beside every other's.
|
|
135
|
+
*
|
|
136
|
+
* ```ts
|
|
137
|
+
* import { bucketObjects, prefixed } from '@yaks/blob'
|
|
138
|
+
*
|
|
139
|
+
* // in a Worker, where `env.BLOBS` is an R2 binding
|
|
140
|
+
* // let photos = prefixed(bucketObjects(env.BLOBS), 'ada/photos/blobs/')
|
|
141
|
+
* ```
|
|
142
|
+
*/ export declare let prefixed: (objects: Objects, prefix: string, discard?: Discard) => Blobs;
|
|
143
|
+
/**
|
|
144
|
+
* A byte store keyed by name: the caller chooses each key, where {@link Blobs}
|
|
145
|
+
* derives it from the bytes. It is how a host keeps files that are replaced
|
|
146
|
+
* and swept, an app's pages among them.
|
|
147
|
+
*/ export type Objects = {
|
|
148
|
+
/** whether an object is stored under this key */ has(key: string): Promise<boolean>;
|
|
149
|
+
/** store these bytes under this key, replacing what was there: held
|
|
150
|
+
* whole, or streamed ({@link Streamed}) */ put(key: string, bytes: Put): Promise<void>;
|
|
151
|
+
/** Stream bytes to this key, making them visible only after `check` passes. */ publish?<T>(key: string, sent: Streamed, check: () => Promise<T>): Promise<T>;
|
|
152
|
+
/** the bytes under this key, or null; a miss is one round trip, like a hit,
|
|
153
|
+
* where `has` then `get` is two */ read(key: string): Promise<Uint8Array<ArrayBuffer> | null>;
|
|
154
|
+
/** bytes and their validator in the same object-store read */ load(key: string): Promise<Loaded | null>;
|
|
155
|
+
/** the bytes under a key the caller knows is there; a miss throws */ get(key: string): Promise<Uint8Array<ArrayBuffer>>;
|
|
156
|
+
/** length and validator first, then stream only the bytes the caller needs */ open(key: string): Promise<Opened | null>;
|
|
157
|
+
/** remove the object under this key, or under each of these keys in as few
|
|
158
|
+
* round trips as the bucket allows: a sweep of a thousand objects is one
|
|
159
|
+
* call, not a thousand */ delete(keys: string | string[]): Promise<void>;
|
|
160
|
+
/** every key under a prefix, sorted */ list(prefix: string): Promise<string[]>;
|
|
161
|
+
/** the same keys, each with the moment it landed in epoch milliseconds: a
|
|
162
|
+
* sweep must not delete bytes written a minute ago for a row that has not
|
|
163
|
+
* landed yet */ uploaded(prefix: string): Promise<Record<string, number>>;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* An {@link Objects} over a bucket, key for key.
|
|
167
|
+
*
|
|
168
|
+
* ```ts
|
|
169
|
+
* import { bucketObjects } from '@yaks/blob'
|
|
170
|
+
*
|
|
171
|
+
* // in a Worker, where `env.BLOBS` is an R2 binding
|
|
172
|
+
* // let files = bucketObjects(env.BLOBS)
|
|
173
|
+
* ```
|
|
174
|
+
*/ export declare let bucketObjects: (bucket: Bucket & Partial<Multipart>, pause?: Pause, discard?: Discard, time?: Clock) => Objects;
|
|
175
|
+
//# sourceMappingURL=object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.d.ts","sources":["../object.ts"],"names":[],"mappings":"AAmBA,SAAS,KAAK,KAAK,wBAAmD;AACtE,SACE,KAAK,OAAO,0BAIU;AACxB,cAAc,SAAS,qBAAoB;AAC3C,cAAc,KAAK,qBAAoB;AACvC,SAAkB,KAAK,GAAG,EAAE,KAAK,MAAM,EAAE,KAAK,QAAQ,sBAAqB;AAE3E;;;CAGC,GACD,YAAY;EACV,oEAAoE,GACpE,OAAO,KAAK,MAAM,KAAK;IAAU,MAAM,MAAM;IAAE,MAAM,MAAM;MAAK,IAAI;EACpE,uCAAuC,GACvC,MACE,KAAK,MAAM,EACX;IAAY;MAAS,QAAQ,MAAM;MAAE,QAAQ,MAAM;;QAChD;IAED,MAAM,MAAM;IACZ,MAAM,MAAM;IACZ,MAAM,eAAe;IACrB,mBAAmB,QAAQ;MACzB,IAAI;EAEV;0CACwC,GACxC,MACE,KAAK,MAAM,EACX,OAAO,cAAc,kBAAkB,MAAM,GAAG,eAAe,gBAC5D,QAAQ,OAAO;EACpB;yCACuC,GACvC,SAAS,MAAM,MAAM,GAAG,MAAM,OAAO,QAAQ,OAAO;EACpD;;UAEQ,GACR,OACE;IACE,QAAQ,MAAM;IACd,SAAS,MAAM;IACf,QAAQ,MAAM;IACd,aAAa,MAAM;QAElB;IACH;MAAW,KAAK,MAAM;MAAE,UAAU;MAAM,MAAM,MAAM;;IACpD,WAAW,OAAO;IAClB,SAAS,MAAM;;;AAInB,2DAA2D,GAC3D,OAAO,YAAI,gBAAc;AAOzB,kFAAkF,GAClF,OAAO,YAAI,aAAc,GAAG,OAAO,KAAG,MAAM,GAAG,SAAS,CAKvD;AAED;oEACoE,GACpE,OAAO,YAAI,OAAQ,GAAG,OAAO,KAAG,OAAO,C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 export type Multipart = {
|
|
3
|
+
createMultipartUpload: (key: string) => Promise<{
|
|
4
|
+
uploadId: string;
|
|
5
|
+
}>;
|
|
6
|
+
resumeMultipartUpload: (key: string, uploadId: string) => Assembly;
|
|
7
|
+
};
|
|
8
|
+
/** One multipart upload under way: its parts, then the whole, or nothing. */ export type Assembly = {
|
|
9
|
+
uploadPart: (n: number, value: ReadableStream<Uint8Array> | Uint8Array<ArrayBuffer>) => Promise<{
|
|
10
|
+
partNumber: number;
|
|
11
|
+
etag: string;
|
|
12
|
+
}>;
|
|
13
|
+
complete: (parts: {
|
|
14
|
+
partNumber: number;
|
|
15
|
+
etag: string;
|
|
16
|
+
}[]) => Promise<{
|
|
17
|
+
size: number;
|
|
18
|
+
}>;
|
|
19
|
+
abort: () => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
/** The most parts one upload has. */ export declare let MOST: number;
|
|
22
|
+
/** Every part size is a whole number of these, so a sender records its hash
|
|
23
|
+
* state once per MiB and holds the state at every part's start. */ export declare let MiB: any;
|
|
24
|
+
/** An upload that is not under way, never begun or aborted: begin again. */ export declare class Gone extends Error {
|
|
25
|
+
}
|
|
26
|
+
/** A part, or a whole, that is not what it was said to be. */ export declare class Wrong extends Error {
|
|
27
|
+
}
|
|
28
|
+
/** What a finished upload holds: its length and its first bytes, and `made`
|
|
29
|
+
* when this `post` assembled it rather than finding it kept already. */ export type Whole = {
|
|
30
|
+
bytes: number;
|
|
31
|
+
head: Uint8Array<ArrayBuffer>;
|
|
32
|
+
made?: boolean;
|
|
33
|
+
};
|
|
34
|
+
/** Where an upload stands: the size of every part but the last, the parts
|
|
35
|
+
* still to send, and the whole once none are. */ export type Standing = {
|
|
36
|
+
part: number;
|
|
37
|
+
need: number[];
|
|
38
|
+
whole?: Whole;
|
|
39
|
+
};
|
|
40
|
+
/** One upload in parts, as {@link parts} answers it. */ export type Parts = {
|
|
41
|
+
post: (bytes: number) => Promise<Standing>;
|
|
42
|
+
put: (n: number, body: ReadableStream<Uint8Array>, length: number, from?: string) => Promise<void>;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* The part size for `bytes`: `part`, unless that would take more than
|
|
46
|
+
* {@link MOST} parts, in whole {@link MiB}. Every part but the last is this
|
|
47
|
+
* size, which R2 requires.
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { equal } from '@yaks/testing'
|
|
51
|
+
* import { MiB, sized } from '@yaks/blob'
|
|
52
|
+
*
|
|
53
|
+
* equal(sized(20 * MiB, 8 * MiB), 8 * MiB)
|
|
54
|
+
* equal(sized(100_000 * MiB, 8 * MiB), 10 * MiB)
|
|
55
|
+
* ```
|
|
56
|
+
*/ export declare let sized: (bytes: number, part: number) => number;
|
|
57
|
+
/**
|
|
58
|
+
* The upload of the bytes named `sha` into `key`, in parts of `part` bytes
|
|
59
|
+
* (more, for a file that would need over {@link MOST}), its ledger kept under
|
|
60
|
+
* `ledger`. `objects` is the bucket keyed by name and `bucket` the same
|
|
61
|
+
* bucket's multipart upload.
|
|
62
|
+
*
|
|
63
|
+
* - `post(bytes)` says where the upload stands, beginning it if nothing is
|
|
64
|
+
* under way, and once nothing is missing makes it whole: `whole` is set,
|
|
65
|
+
* and `need` is empty.
|
|
66
|
+
* - `put(n, body, length, from)` keeps part `n`, hashed on from `from`, the
|
|
67
|
+
* state the bytes before it leave ({@link START} for the first). A length
|
|
68
|
+
* that is not the part's is refused before anything is read, and a part
|
|
69
|
+
* sent twice is kept once.
|
|
70
|
+
*
|
|
71
|
+
* {@link Gone} says the upload is not under way, so it is begun again;
|
|
72
|
+
* {@link Wrong} says what was sent is not what was said.
|
|
73
|
+
*/ export declare let parts: (objects: Objects, bucket: Multipart, at: {
|
|
74
|
+
key: string;
|
|
75
|
+
sha: string;
|
|
76
|
+
ledger: string;
|
|
77
|
+
part: number;
|
|
78
|
+
}, pause?: (ms: number) => Promise<void>) => Parts;
|
|
79
|
+
/** Abort ticketed native uploads only for a person's confirmed permanent purge.
|
|
80
|
+
* Keep recovery objects and receipts until the caller removes that private
|
|
81
|
+
* ledger prefix after every abort succeeds. A retry tolerates uploads already
|
|
82
|
+
* completed or purged; ordinary upload cleanup never calls this. */ export declare let purgeParts: (objects: Objects, bucket: Multipart, at: {
|
|
83
|
+
prefix: string;
|
|
84
|
+
ledger: string;
|
|
85
|
+
}, pause?: (ms: number) => Promise<void>) => Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Multipart for a bucket that has none, its parts held in this process's
|
|
88
|
+
* memory and the whole written through `put`: a host's memory bucket, or a
|
|
89
|
+
* test's.
|
|
90
|
+
*/ export declare let memoryMultipart: (put: (key: string, bytes: Uint8Array) => Promise<unknown>) => Multipart;
|
|
91
|
+
//# sourceMappingURL=parts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parts.d.ts","sources":["../parts.ts"],"names":[],"mappings":"AAsBA,SAA2B,KAAK,OAAO,sBAA8B;AAMrE,oEAAoE,GACpE,YAAY;EACV,wBAAwB,KAAK,MAAM,KAAK;IAAU,UAAU,MAAM;;EAClE,wBAAwB,KAAK,MAAM,EAAE,UAAU,MAAM,KAAK;;AAG5D,2EAA2E,GAC3E,YAAY;EACV,aACE,GAAG,MAAM,EACT,OAAO,eAAe,cAAc,WAAW,iBAC5C;IAAU,YAAY,MAAM;IAAE,MAAM,MAAM;;EAC/C,WACE;IAAS,YAAY,MAAM;IAAE,MAAM,MAAM;UACtC;IAAU,MAAM,MAAM;;EAC3B,aAAa,QAAQ,IAAI;;AAG3B,mCAAmC,GACnC,OAAO,YAAI,aAAa;AAExB;iEACiE,GACjE,OAAO,YAAI,SAAiB;AAE5B,0EAA0E,GAC1E,OAAO,cAAM,aAAa;AAAO;AAEjC,4DAA4D,GAC5D,OAAO,cAAM,cAAc;AAAO;AAElC;sEACsE,GACtE,YAAY;EACV,OAAO,MAAM;EACb,MAAM,WAAW;EACjB,OAAO,OAAO;;AAGhB;+CAC+C,GAC/C,YAAY;EAAa,MAAM,MAAM;EAAE,MAAM,MAAM;EAAI,QAAQ;;AAE/D,sDAAsD,GACtD,YAAY;EACV,OAAO,OAAO,MAAM,KAAK,QAAQ;EACjC,MACE,GAAG,MAAM,EACT,MAAM,eAAe,aACrB,QAAQ,MAAM,EACd,OAAO,MAAM,KACV,QAAQ,IAAI;;AAGnB;;;;;;;;;;;;CAYC,GACD,OAAO,YAAI,QAAS,OAAO,MAAM,EAAE,MAAM,MAAM,KAAG,MAAM,CACW;AAenE;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,YAAI,QACT,SAAS,SACT,QAAQ,WACR;EAAM,KAAK,MAAM;EAAE,KAAK,MAAM;EAAE,QAAQ,MAAM;EAAE,MAAM,MAAM;GAC5D,SAAQ,IAAI,MAAM,KAAK,QAAQ,IAAI,MAClC,MAoMF;AAED;;;kEAGkE,GAClE,OAAO,YAAI,aACT,SAAS,SACT,QAAQ,WACR;EAAM,QAAQ,MAAM;EAAE,QAAQ,MAAM;GACpC,SAAQ,IAAI,MAAM,KAAK,QAAQ,IAAI,MAClC,QAAQ,IAAI,EAmBd;AAED;;;;CAIC,GACD,OAAO,YAAI,kBACT,MAAM,KAAK,MAAM,EAAE,OAAO,eAAe,QAAQ,OAAO,MACvD,UAsDF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Plugin } from "@yaks/graph/plugin";
|
|
2
|
+
import type { Vocab } from "@yaks/vocab";
|
|
3
|
+
import { type Body } from "./props.js";
|
|
4
|
+
import { type Blobs } from "./store.js";
|
|
5
|
+
/** How a store addresses an object from a component row. Usually the hash
|
|
6
|
+
* itself; an existing SQL layout may instead keep an integer foreign key.
|
|
7
|
+
* Called after `put`, in the store's preparation phase. */ export type Reference = (sha: string) => string | number | Promise<string | number>;
|
|
8
|
+
export type BlobOpts = {
|
|
9
|
+
/** Narrow the vocabulary's blob properties for a partially migrated store. */ props?: Body[];
|
|
10
|
+
/** Translate the content hash into the reference the row should hold. */ reference?: Reference;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The blob plugin: content-addressed storage for every property the vocabulary
|
|
14
|
+
* marks `store: "blob"`.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
18
|
+
* import { graph } from '@yaks/graph'
|
|
19
|
+
* import { ram } from '@yaks/ram'
|
|
20
|
+
* import { blobKeywords, blobs, memoryBlobs } from '@yaks/blob'
|
|
21
|
+
*
|
|
22
|
+
* let body = { type: 'string', store: 'blob' }
|
|
23
|
+
* let post = { component: true, type: 'object', properties: { body } }
|
|
24
|
+
* let vocab = loadVocab([{ $defs: { post } }], [blobKeywords])
|
|
25
|
+
* let store = memoryBlobs()
|
|
26
|
+
* let g = graph({ storage: ram(vocab), vocab, plugins: [blobs(vocab, store)] })
|
|
27
|
+
* g.apply([{ entity: { eid: 'p1' }, post: { body: 'a long essay…' } }])
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* The write side is here. The read side belongs to the storage adapter, which
|
|
31
|
+
* is the half that knows its own layout: over SQL, register {@link blobRead}'s
|
|
32
|
+
* property overrides and a row resolves in the statement itself; over any other
|
|
33
|
+
* store, {@link hydrate} resolves the bundles a read returned.
|
|
34
|
+
*
|
|
35
|
+
* A vocabulary loaded without {@link blobKeywords} declares no body properties,
|
|
36
|
+
* so this plugin is a no-op on it rather than a surprise.
|
|
37
|
+
*/ export declare let blobs: (vocab: Vocab, store: Blobs, opts?: BlobOpts) => Plugin;
|
|
38
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sources":["../plugin.ts"],"names":[],"mappings":"AAaA,SAAe,KAAK,MAAM,kCAAuC;AAEjE,cAAc,KAAK,2BAAgC;AACnD,SAAiB,KAAK,IAAI,qBAA6B;AACvD,SAAkB,KAAK,KAAK,qBAA4B;AAsExD;;yDAEyD,GACzD,YAAY,aACV,KAAK,MAAM,KACR,MAAM,GAAG,MAAM,GAAG,QAAQ,MAAM,GAAG,MAAM;AAE9C,YAAY;EACV,4EAA4E,GAC5E,QAAQ;EACR,uEAAuE,GACvE,YAAY;;AAGd;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GACD,OAAO,YAAI,QACT,OAAO,OACP,OAAO,OACP,OAAM,aACL,OAoDF"}
|
package/_dist/png.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An RGBA image `w` by `h` pixels as PNG bytes: `rgba` holds four bytes a
|
|
3
|
+
* pixel, row by row from the top left.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { png } from '@yaks/blob/png'
|
|
7
|
+
* import { sizeOf } from '@yaks/blob'
|
|
8
|
+
* import { equal } from '@yaks/testing'
|
|
9
|
+
*
|
|
10
|
+
* let red = new Uint8Array(3 * 2 * 4).map((_, i) => i % 4 == 1 || i % 4 == 2 ? 0 : 255)
|
|
11
|
+
* equal(sizeOf(await png(3, 2, red)), { w: 3, h: 2 })
|
|
12
|
+
* ```
|
|
13
|
+
*/ export declare let png: (w: number, h: number, rgba: Uint8Array) => Promise<Uint8Array>;
|
|
14
|
+
//# sourceMappingURL=png.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"png.d.ts","sources":["../png.ts"],"names":[],"mappings":"AA6BA;;;;;;;;;;;;CAYC,GACD,OAAO,YAAI,MACT,GAAG,MAAM,EACT,GAAG,MAAM,EACT,MAAM,eACL,QAAQ,YAWV"}
|
package/_dist/props.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Prop, Vocab } from "@yaks/vocab";
|
|
2
|
+
/** One content-addressed property, named the way a vocabulary names it. */ export type Body = {
|
|
3
|
+
comp: string;
|
|
4
|
+
prop: string;
|
|
5
|
+
};
|
|
6
|
+
/** Whether a property keeps its value in a content-addressed store. */ export declare let isBody: (prop: Prop | undefined) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Every content-addressed property in a vocabulary, by component then
|
|
9
|
+
* declaration order. Requires the vocabulary to have been loaded with
|
|
10
|
+
* {@link blobKeywords} — without that registration the loader does not carry
|
|
11
|
+
* the `store` keyword at all, and this returns an empty list, which is the
|
|
12
|
+
* correct reading of a vocabulary that never declared one.
|
|
13
|
+
*/ export declare let bodies: (vocab: Vocab) => Body[];
|
|
14
|
+
/**
|
|
15
|
+
* Every stored property whose value names bytes in the store: the bodies, and
|
|
16
|
+
* the properties declaring `address: true`, whose package wrote the bytes and
|
|
17
|
+
* keeps their address itself. While a row of one names an address, its bytes
|
|
18
|
+
* are kept.
|
|
19
|
+
*/ export declare let holders: (vocab: Vocab) => Body[];
|
|
20
|
+
//# sourceMappingURL=props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.d.ts","sources":["../props.ts"],"names":[],"mappings":"AASA,cAAc,IAAI,EAAE,KAAK,2BAAgC;AAEzD,yEAAyE,GACzE,YAAY;EAAS,MAAM,MAAM;EAAE,MAAM,MAAM;;AAE/C,qEAAqE,GACrE,OAAO,YAAI,SAAU,MAAM,OAAO,SAAS,KAAG,OAAO,CACpB;AAEjC;;;;;;CAMC,GACD,OAAO,YAAI,SAAU,OAAO,UAAQ,OAKjC;AAEH;;;;;CAKC,GACD,OAAO,YAAI,UAAW,OAAO,UAAQ,OAQlC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type Representation = {
|
|
2
|
+
scope: string;
|
|
3
|
+
address: string;
|
|
4
|
+
media_type: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare let representation: (scope: string, address: string, mime: string, name?: string) => {
|
|
8
|
+
eid: string;
|
|
9
|
+
row: Representation;
|
|
10
|
+
path: string;
|
|
11
|
+
};
|
|
12
|
+
export declare let represents: (eid: string, row: Representation) => boolean;
|
|
13
|
+
export declare let addressed: (path: string) => {
|
|
14
|
+
sha: string;
|
|
15
|
+
eid: string | null;
|
|
16
|
+
} | null;
|
|
17
|
+
//# sourceMappingURL=representation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"representation.d.ts","sources":["../representation.ts"],"names":[],"mappings":"AAOA,YAAY;EACV,OAAO,MAAM;EACb,SAAS,MAAM;EACf,YAAY,MAAM;EAClB,OAAO,MAAM;;AAGf,OAAO,YAAI,iBACT,OAAO,MAAM,EACb,SAAS,MAAM,EACf,MAAM,MAAM,EACZ;EACG,KAAK,MAAM;EAAE,KAAK;EAAgB,MAAM,MAAM;EASlD;AAED,OAAO,YAAI,aACT,KAAK,MAAM,EACX,KAAK,mBACJ,OAAO,CAGmE;AAE7E,OAAO,YAAI,YACT,MAAM,MAAM;EACT,KAAK,MAAM;EAAE,KAAK,MAAM,GAAG,IAAI;IAAK,IAAI,CAG5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"representation_rules.d.ts","sources":["../representation_rules.ts"],"names":[],"mappings":"AAKA,SAAe,KAAK,MAAM,kCAAuC;AAKjE,OAAO,YAAI,uBAAsB,OA8C/B"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type Authenticate, type Route } from "@yaks/api";
|
|
2
|
+
import type { Bundle } from "@yaks/graph";
|
|
3
|
+
import { type Objects } from "./object.js";
|
|
4
|
+
import { type Multipart } from "./parts.js";
|
|
5
|
+
import { type Representation } from "./representation.js";
|
|
6
|
+
import { type Served } from "./serve.js";
|
|
7
|
+
import type { Blobs } from "./store.js";
|
|
8
|
+
import { type File, type Read, type Upload } from "./upload.js";
|
|
9
|
+
/** The path the doors answer under where a configuration names none. */ export declare let PREFIX: string;
|
|
10
|
+
/** The largest upload accepted when the configuration sets no `limit`. */ export declare let LIMIT: any;
|
|
11
|
+
/** The size of each part an upload in parts goes up in but the last,
|
|
12
|
+
* measured from a box and from a Worker (T-124790). At least 5 MiB, the least
|
|
13
|
+
* R2 takes. */ export declare let PART: any;
|
|
14
|
+
/** A graph as this door reads and writes it. */ export type Rows = {
|
|
15
|
+
read: Read;
|
|
16
|
+
apply: (bundles: Bundle[], opts: {
|
|
17
|
+
check?: boolean;
|
|
18
|
+
trusted?: boolean;
|
|
19
|
+
}) => Bundle[] | Promise<Bundle[]>;
|
|
20
|
+
};
|
|
21
|
+
/** Where uploads in parts go (./parts.ts): the bucket by name and its
|
|
22
|
+
* multipart uploads, the prefix its objects are kept under (the store's), and
|
|
23
|
+
* the prefix of the ledger of uploads under way. */ export type InParts = {
|
|
24
|
+
objects: Objects;
|
|
25
|
+
bucket: Multipart;
|
|
26
|
+
prefix: string;
|
|
27
|
+
ledger: string;
|
|
28
|
+
/** the size of every part but the last (default {@link PART}) */ part?: number;
|
|
29
|
+
};
|
|
30
|
+
/** The options a configuration passes to this plugin. */ export type Options = Omit<Upload, 'store'> & {
|
|
31
|
+
/** the path the doors answer under (default {@link PREFIX}) */ at?: string;
|
|
32
|
+
/** uploads in parts, where the store's bucket takes them */ parts?: InParts;
|
|
33
|
+
/** Let a host incorporate its pending record into the upload transaction. */ finish?: (request: Request, file: File) => Promise<File>;
|
|
34
|
+
/** Whether the representation `eid` of the bytes at `sha` is served, where
|
|
35
|
+
* a host keeps that answer nearer than its graph (default {@link servable}
|
|
36
|
+
* of the graph). */ served?: (sha: string, eid: string) => Promise<Representation | null>;
|
|
37
|
+
/** The bytes at `sha` answering `seek`, a GET or HEAD and its range, where
|
|
38
|
+
* a host reads them through a cache (default: from the store). */ bytes?: (seek: Request, sha: string) => Promise<Response>;
|
|
39
|
+
/** A named byte range in an object shared by several immutable files. */ slice?: (read: Read, sha: string) => Promise<Slice | null>;
|
|
40
|
+
/** A host's alternate representation, served after the original is authorized. */ variant?: (request: Request, sha: string, source: Served, read: (request: Request) => Promise<Response | null>) => Promise<Response | null>;
|
|
41
|
+
/** Let a host report and render a file whose rows exist but whose bytes do not. */ missing?: (request: Request, error: MissingBlob, answer: Response) => Response;
|
|
42
|
+
/** Let a host render an unavailable read for its client. */ unavailable?: (request: Request, error: unknown, answer: Response) => Response;
|
|
43
|
+
/** what the host adds to the failures this door reports */ tags?: Record<string, string>;
|
|
44
|
+
};
|
|
45
|
+
export type Slice = {
|
|
46
|
+
object: string;
|
|
47
|
+
offset: number;
|
|
48
|
+
size: number;
|
|
49
|
+
mime: string;
|
|
50
|
+
};
|
|
51
|
+
export declare class MissingBlob extends Error {
|
|
52
|
+
sha: string;
|
|
53
|
+
mime: string | null | undefined;
|
|
54
|
+
constructor(sha: string, mime: string | null | undefined);
|
|
55
|
+
}
|
|
56
|
+
/** The doors, answering under `options.at` (default {@link PREFIX}), over
|
|
57
|
+
* the host's artifact store, else its blob store. Building a store a
|
|
58
|
+
* configuration names is the host's (./backend.ts), so a host without files,
|
|
59
|
+
* a Worker, never loads the filesystem (./file.ts). */ export declare let routes: (host: {
|
|
60
|
+
blobs?: Blobs;
|
|
61
|
+
graph: Rows;
|
|
62
|
+
who?: Authenticate;
|
|
63
|
+
artifacts?: Blobs;
|
|
64
|
+
}, options?: Options) => Route[];
|
|
65
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sources":["../routes.ts"],"names":[],"mappings":"AAsCA,SACE,KAAK,YAAY,EAIjB,KAAK,KAAK,yBAEiB;AAE7B,cAAc,MAAM,2BAAuC;AAK3D,SAAS,KAAK,OAAO,sBAA8B;AACnD,SAAe,KAAK,SAAS,qBAA6C;AAC1E,SAEE,KAAK,cAAc,8BAGO;AAC5B,SAAS,KAAK,MAAM,qBAAmD;AACvE,cAAc,KAAK,qBAAoB;AAEvC,SAKE,KAAK,IAAI,EACT,KAAK,IAAI,EAMT,KAAK,MAAM,sBAEO;AAEpB,sEAAsE,GACtE,OAAO,YAAI,eAAiB;AAE5B,wEAAwE,GACxE,OAAO,YAAI,WAAwB;AAEnC;;aAEa,GACb,OAAO,YAAI,UAAsB;AAEjC,8CAA8C,GAC9C,YAAY;EACV,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AAO;EAAM,MAAM;EAAc,YAAY;GACpE,UAAS,YACR,QAyXF"}
|
package/_dist/serve.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Opened } from "./object.js";
|
|
2
|
+
/** What the response needs to know about the object besides its bytes. */ export type Served = {
|
|
3
|
+
mime?: string | null;
|
|
4
|
+
name?: string | null;
|
|
5
|
+
etag?: string | null;
|
|
6
|
+
cache?: 'immutable' | 'browser';
|
|
7
|
+
download?: boolean;
|
|
8
|
+
};
|
|
9
|
+
/** Whether an `If-None-Match` header names `etag`, weakly compared. An
|
|
10
|
+
* answer with no etag matches nothing, not even `*`.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { matches } from '@yaks/blob/serve'
|
|
14
|
+
* import { assert } from '@std/assert'
|
|
15
|
+
* assert(matches('"a", W/"b"', '"b"') && matches('*', '"c"'))
|
|
16
|
+
* assert(!matches(null, '"a"') && !matches('*', ''))
|
|
17
|
+
* ```
|
|
18
|
+
*/ export declare let matches: (asked: string | null, etag: string | null) => boolean;
|
|
19
|
+
/** Answer one byte range with the same headers as the whole byte response. */ export declare let ranged: (bytes: Uint8Array, request: Request, headers?: HeadersInit) => Response;
|
|
20
|
+
/** Serve a stored object without reading bytes before range selection. */ export declare let rangedOpen: (object: Opened, request: Request, headers?: HeadersInit) => Promise<Response>;
|
|
21
|
+
export declare let validator: (sha: string, meta: Served) => Promise<string>;
|
|
22
|
+
export declare let served: (bytes: Uint8Array, meta?: Served, request?: Request) => Response;
|
|
23
|
+
export declare let servedOpen: (object: Opened, meta?: Served, request?: Request) => Promise<Response>;
|
|
24
|
+
/** An answer's own `headers` and, of a read through a cache or another
|
|
25
|
+
* object store, only what describes the bytes. The rest of the read's
|
|
26
|
+
* headers are the store's or its cache's (`cf-cache-status`, `age`,
|
|
27
|
+
* `cache-tag`, a `public` policy), never this answer's. */ export declare let carried: (read: Response, headers: HeadersInit) => Headers;
|
|
28
|
+
/** Fence a byte response fetched through a cache or another object store. */ export declare let servedVia: (read: (request: Request) => Promise<Response>, meta: Served, request: Request) => Promise<Response>;
|
|
29
|
+
//# sourceMappingURL=serve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sources":["../serve.ts"],"names":[],"mappings":"AAWA,cAAc,MAAM,sBAAqB;AAGzC,wEAAwE,GACxE,YAAY;EACV,OAAO,MAAM,GAAG,IAAI;EACpB,OAAO,MAAM,GAAG,IAAI;EACpB,OAAO,MAAM,GAAG,IAAI;EACpB,QAAQ,cAAc;EACtB,WAAW,OAAO;;AAuBpB;;;;;;;;;CASC,GACD,OAAO,YAAI,UAAW,OAAO,MAAM,GAAG,IAAI,EAAE,MAAM,MAAM,GAAG,IAAI,KAAG,OAAO,CAItE;AA6BH,4EAA4E,GAC5E,OAAO,YAAI,SACT,OAAO,YACP,SAAS,SACT,UAAS,gBACR,SAYF;AAED,wEAAwE,GACxE,OAAO,YAAI,aACT,QAAQ,QACR,SAAS,SACT,UAAS,gBACR,QAAQ,UAiBV;AAKD,OAAO,YAAI,YACT,KAAK,MAAM,EACX,MAAM,WACL,QAAQ,MAAM,EAMhB;AAyCD,OAAO,YAAI,SACT,OAAO,YACP,OAAM,QACN,UAAS,YACR,SAAmD;AAEtD,OAAO,YAAI,aACT,QAAQ,QACR,OAAM,QACN,UAAS,YACR,QAAQ,UAAyD;AAEpE;;;yDAGyD,GACzD,OAAO,YAAI,UAAW,MAAM,UAAU,SAAS,gBAAc,QAO5D;AAED,2EAA2E,GAC3E,OAAO,YAAI,YACT,OAAO,SAAS,YAAY,QAAQ,WACpC,MAAM,QACN,SAAS,YACR,QAAQ,UA6BV"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** The state before any bytes, SHA-256's initial hash value, as hex. */ export declare let START: string;
|
|
2
|
+
/** Bytes hashed a piece at a time: `add` each, then `end` once. */ export type Hasher = {
|
|
3
|
+
add: (bytes: Uint8Array) => void;
|
|
4
|
+
end: (total?: number) => string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Bytes hashed on from `from`, a piece at a time with `add`. `end()` answers
|
|
8
|
+
* the state after them, which only whole 64-byte blocks leave; given `total`,
|
|
9
|
+
* the length of everything hashed since {@link START}, it answers the
|
|
10
|
+
* finished digest instead.
|
|
11
|
+
*/ export declare let hasher: () => Hasher;
|
|
12
|
+
/**
|
|
13
|
+
* `bytes` hashed on from `from`: the state after them, or with `total`, the
|
|
14
|
+
* digest of everything hashed since {@link START}.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { equal } from '@yaks/testing'
|
|
18
|
+
* import { address, encode, fold, START } from '@yaks/blob'
|
|
19
|
+
*
|
|
20
|
+
* let text = 'a'.repeat(64) + 'and the rest'
|
|
21
|
+
* let half = fold(START, encode('a'.repeat(64)))
|
|
22
|
+
* equal(fold(half, encode('and the rest'), 76), address(text))
|
|
23
|
+
* equal(fold(START, encode(text), 76), address(text))
|
|
24
|
+
* ```
|
|
25
|
+
*/ export declare let fold: (from: string, bytes: Uint8Array, total?: number) => string;
|
|
26
|
+
//# sourceMappingURL=sha256.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sha256.d.ts","sources":["../sha256.ts"],"names":[],"mappings":"AA6EA,sEAAsE,GACtE,OAAO,YAAI,cACyD;AA6DpE,iEAAiE,GACjE,YAAY;EACV,MAAM,OAAO,eAAe,IAAI;EAChC,MAAM,QAAQ,MAAM,KAAK,MAAM;;AAGjC;;;;;CAKC,GACD,OAAO,YAAI,cAAyB,OAqCnC;AAED;;;;;;;;;;;;;CAaC,GACD,OAAO,YAAI,OAAQ,MAAM,MAAM,EAAE,OAAO,YAAY,QAAQ,MAAM,KAAG,MAAM,CAI1E"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Vocab } from "@yaks/vocab";
|
|
2
|
+
import type { Statements } from "@yaks/sql";
|
|
3
|
+
import { type Derived, type Row, type Stmt } from "@yaks/sql/core";
|
|
4
|
+
import { type Body } from "./props.js";
|
|
5
|
+
import { type Blobs } from "./store.js";
|
|
6
|
+
/**
|
|
7
|
+
* Where the blob table is and what its two columns are called. The defaults
|
|
8
|
+
* describe the table {@link blobSchema} creates; an application pointing this
|
|
9
|
+
* at a table it already has names that table's columns instead.
|
|
10
|
+
*/ export type Layout = {
|
|
11
|
+
/** the table holding the objects (default `blob_text`) */ table?: string;
|
|
12
|
+
/** the column holding an object's address (default `sha`) */ key?: string;
|
|
13
|
+
/** the column holding its text (default `value`) */ value?: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The statement creating the blob table: an address, and the text stored under
|
|
17
|
+
* it. Run it beside a storage adapter's own schema.
|
|
18
|
+
*/ export declare let blobSchema: (layout?: Layout) => Stmt[];
|
|
19
|
+
/**
|
|
20
|
+
* The statement letting go of the objects `shas` names, except each a column
|
|
21
|
+
* of `held` still names: one scan of each holding table, whatever the count.
|
|
22
|
+
*/ export declare let dropSql: (shas: string[], held: Body[], layout?: Layout) => Stmt;
|
|
23
|
+
/**
|
|
24
|
+
* A {@link Blobs} over a SQLite table. Writes use the store's atomic boundary:
|
|
25
|
+
* nested writes share the graph's transaction; independent writes await a
|
|
26
|
+
* competing writer without holding their thread. Writing one address twice
|
|
27
|
+
* keeps one copy of its bytes. An optional reader answers committed reads;
|
|
28
|
+
* reads inside the owning transaction stay on its connection.
|
|
29
|
+
*/ export declare let sqliteBlobs: (db: Statements, layout?: Layout, read?: {
|
|
30
|
+
query: (statement: Stmt) => Row[] | Promise<Row[]>;
|
|
31
|
+
}) => Blobs;
|
|
32
|
+
/**
|
|
33
|
+
* The read side, as @yaks/sql read overrides: one entry per content-addressed
|
|
34
|
+
* property, each resolving the stored address to its text in the statement
|
|
35
|
+
* itself (`expr`), and resolving an address already in hand (`text`: an FTS5
|
|
36
|
+
* trigger's `new."body"`, a view column). Pass them to a compile (or to
|
|
37
|
+
* `@yaks/sqlite`'s `storage()`, which passes them on to the query, the
|
|
38
|
+
* whole-entity read and the `doc_value` view; and to @yaks/fts `schema()`, so
|
|
39
|
+
* a search index holds words rather than addresses) and a body property reads
|
|
40
|
+
* as text everywhere:
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
44
|
+
* import { storage } from '@yaks/sqlite'
|
|
45
|
+
* import { open } from '@yaks/sqlite/db'
|
|
46
|
+
* import { blobKeywords, blobRead } from '@yaks/blob'
|
|
47
|
+
*
|
|
48
|
+
* let body = { type: 'string', store: 'blob' }
|
|
49
|
+
* let post = { component: true, type: 'object', properties: { body } }
|
|
50
|
+
* let vocab = loadVocab([{ $defs: { post } }], [blobKeywords])
|
|
51
|
+
* let store = storage(open(':memory:'), vocab, { derived: blobRead(vocab) })
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* Merge them with any overrides of your own — the registry is a plain object
|
|
55
|
+
* keyed `comp.prop`.
|
|
56
|
+
*/ export declare let blobRead: (vocab: Vocab, layout?: Layout) => Derived;
|
|
57
|
+
//# sourceMappingURL=sqlite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sources":["../sqlite.ts"],"names":[],"mappings":"AAsBA,cAAc,KAAK,2BAAgC;AACnD,cAAc,UAAU,yBAA8B;AAEtD,SAKE,KAAK,OAAO,EAKZ,KAAK,GAAG,EAER,KAAK,IAAI,8BAIuB;AAClC,SAAiB,KAAK,IAAI,qBAAoB;AAC9C,SAAS,KAAK,KAAK,qBAA4B;AAE/C;;;;CAIC,GACD,YAAY;EACV,wDAAwD,GACxD,QAAQ,MAAM;EACd,2DAA2D,GAC3D,MAAM,MAAM;EACZ,kDAAkD,GAClD,QAAQ,MAAM;;AA4BhB;;;CAGC,GACD,OAAO,YAAI,aAAc,SAAQ,WAAc,OAW9C;AAED;;;CAGC,GACD,OAAO,YAAI,UACT,MAAM,MAAM,IACZ,MAAM,QACN,SAAQ,WACP,KAoBF;AAED;;;;;;CAMC,GACD,OAAO,YAAI,cACT,IAAI,YACJ,SAAQ,QACR;EAAS,QAAQ,WAAW,SAAS,QAAQ,QAAQ;MACpD,MA+CF;AAsBD;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GACD,OAAO,YAAI,WAAY,OAAO,OAAO,SAAQ,WAAc,QAa1D"}
|
package/_dist/store.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Opened } from "./object.js";
|
|
2
|
+
import type { Body } from "./props.js";
|
|
3
|
+
import type { Staged, Streamed } from "./stream.js";
|
|
4
|
+
/**
|
|
5
|
+
* A content-addressed byte store. `sha` is always the lowercase-hex SHA-256 of
|
|
6
|
+
* the bytes — {@link address} computes it, and an implementation may take it on
|
|
7
|
+
* trust rather than re-hashing.
|
|
8
|
+
*/ export type Blobs = {
|
|
9
|
+
/** Writes share the graph's transaction and must roll back with its rows.
|
|
10
|
+
* Other stores prepare their content before the graph takes its write lock. */ transactional?: boolean;
|
|
11
|
+
/** The store holds any bytes exactly as it was given them, so keeping an
|
|
12
|
+
* object is one `put`, neither asked about first nor read back
|
|
13
|
+
* (./artifact.ts `keep`): a bucket, where each look is a round trip. A text
|
|
14
|
+
* table is not: handed a PNG, it keeps something else. */ exact?: boolean;
|
|
15
|
+
/** whether the store already holds an object under this hash */ has: (sha: string) => boolean | Promise<boolean>;
|
|
16
|
+
/** the bytes stored under this hash, or `undefined` if there are none */ get: (sha: string) => Uint8Array | undefined | Promise<Uint8Array | undefined>;
|
|
17
|
+
/** Stores that can stream a requested span expose it here. */ open?: (sha: string) => Promise<Opened | null>;
|
|
18
|
+
/** store these bytes under this hash; storing the same pair twice is a
|
|
19
|
+
* no-op, because the second copy is the first one */ put: (sha: string, bytes: Uint8Array) => void | Promise<void>;
|
|
20
|
+
/** Stores that take a stream without holding it land it here, hashed as it
|
|
21
|
+
* passes and refused past `most`, for the caller to keep at its address or
|
|
22
|
+
* drop (./stream.ts `stage`). */ stage?: (sent: Streamed, most?: number) => Promise<Staged>;
|
|
23
|
+
/** Stream to a known address, making it visible only after `check` passes. */ publish?: <T>(sha: string, sent: Streamed, check: () => Promise<T>) => Promise<T>;
|
|
24
|
+
/** Let go of these objects, keeping each one a row of `held` still names:
|
|
25
|
+
* what an expired value leaves behind. A store that cannot tell which rows
|
|
26
|
+
* name an object leaves this out and keeps everything. */ drop?: (shas: string[], held: Body[]) => void | Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The address of a string: the SHA-256 of its UTF-8 bytes, lowercase hex. This
|
|
30
|
+
* is the value a content-addressed property holds in place of its text, and the
|
|
31
|
+
* key the bytes are stored under.
|
|
32
|
+
*
|
|
33
|
+
* It reuses @yaks/graph's synchronous digest rather than `crypto.subtle`, whose
|
|
34
|
+
* promise would make every write to a body property asynchronous — including
|
|
35
|
+
* one over an embedded database that is otherwise synchronous end to end.
|
|
36
|
+
*/ export declare let address: (value: string) => string;
|
|
37
|
+
/** A string as the bytes a store holds: its UTF-8 encoding. */ export declare let encode: (value: string) => Uint8Array;
|
|
38
|
+
/** Stored bytes read back as the string they encode. */ export declare let decode: (bytes: Uint8Array) => string;
|
|
39
|
+
/** A {@link Blobs} held in this process's memory, for exactly as long as it
|
|
40
|
+
* runs: where a graph in memory keeps its bytes. */ export declare let memoryBlobs: () => Blobs;
|
|
41
|
+
//# sourceMappingURL=store.d.ts.map
|