@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.
Files changed (172) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +946 -2
  3. package/_dist/accepts.d.ts +38 -0
  4. package/_dist/accepts.d.ts.map +1 -0
  5. package/_dist/artifact.d.ts +29 -0
  6. package/_dist/artifact.d.ts.map +1 -0
  7. package/_dist/attachment.d.ts +53 -0
  8. package/_dist/attachment.d.ts.map +1 -0
  9. package/_dist/backend.d.ts +20 -0
  10. package/_dist/backend.d.ts.map +1 -0
  11. package/_dist/broken.d.ts +24 -0
  12. package/_dist/broken.d.ts.map +1 -0
  13. package/_dist/browser.d.ts +27 -0
  14. package/_dist/browser.d.ts.map +1 -0
  15. package/_dist/compare.d.ts +4 -0
  16. package/_dist/compare.d.ts.map +1 -0
  17. package/_dist/content_type.d.ts +20 -0
  18. package/_dist/content_type.d.ts.map +1 -0
  19. package/_dist/graph.d.ts +13 -0
  20. package/_dist/graph.d.ts.map +1 -0
  21. package/_dist/hydrate.d.ts +36 -0
  22. package/_dist/hydrate.d.ts.map +1 -0
  23. package/_dist/identify.d.ts +7 -0
  24. package/_dist/identify.d.ts.map +1 -0
  25. package/_dist/image.d.ts +37 -0
  26. package/_dist/image.d.ts.map +1 -0
  27. package/_dist/keywords.d.ts +10 -0
  28. package/_dist/keywords.d.ts.map +1 -0
  29. package/_dist/mime.d.ts +2 -0
  30. package/_dist/mime.d.ts.map +1 -0
  31. package/_dist/mod.d.ts +97 -0
  32. package/_dist/mod.d.ts.map +1 -0
  33. package/_dist/object-put.d.ts +2 -0
  34. package/_dist/object-put.d.ts.map +1 -0
  35. package/_dist/object.d.ts +175 -0
  36. package/_dist/object.d.ts.map +1 -0
  37. package/_dist/parts.d.ts +91 -0
  38. package/_dist/parts.d.ts.map +1 -0
  39. package/_dist/plugin.d.ts +38 -0
  40. package/_dist/plugin.d.ts.map +1 -0
  41. package/_dist/png.d.ts +14 -0
  42. package/_dist/png.d.ts.map +1 -0
  43. package/_dist/props.d.ts +20 -0
  44. package/_dist/props.d.ts.map +1 -0
  45. package/_dist/representation.d.ts +17 -0
  46. package/_dist/representation.d.ts.map +1 -0
  47. package/_dist/representation_rules.d.ts +3 -0
  48. package/_dist/representation_rules.d.ts.map +1 -0
  49. package/_dist/routes.d.ts +65 -0
  50. package/_dist/routes.d.ts.map +1 -0
  51. package/_dist/serve.d.ts +29 -0
  52. package/_dist/serve.d.ts.map +1 -0
  53. package/_dist/sha256.d.ts +26 -0
  54. package/_dist/sha256.d.ts.map +1 -0
  55. package/_dist/sqlite.d.ts +57 -0
  56. package/_dist/sqlite.d.ts.map +1 -0
  57. package/_dist/store.d.ts +41 -0
  58. package/_dist/store.d.ts.map +1 -0
  59. package/_dist/stream.d.ts +91 -0
  60. package/_dist/stream.d.ts.map +1 -0
  61. package/_dist/upload.d.ts +114 -0
  62. package/_dist/upload.d.ts.map +1 -0
  63. package/_dist/value.d.ts +62 -0
  64. package/_dist/value.d.ts.map +1 -0
  65. package/_dist/vocab.d.ts +13 -0
  66. package/_dist/vocab.d.ts.map +1 -0
  67. package/accepts.js +76 -0
  68. package/accepts.js.map +1 -0
  69. package/accepts.ts +95 -0
  70. package/artifact.js +50 -0
  71. package/artifact.js.map +1 -0
  72. package/artifact.ts +93 -0
  73. package/attachment.js +190 -0
  74. package/attachment.js.map +1 -0
  75. package/attachment.ts +201 -0
  76. package/backend.js +37 -0
  77. package/backend.js.map +1 -0
  78. package/backend.ts +44 -0
  79. package/broken.js +278 -0
  80. package/broken.js.map +1 -0
  81. package/broken.ts +217 -0
  82. package/browser.js +124 -0
  83. package/browser.js.map +1 -0
  84. package/browser.ts +179 -0
  85. package/compare.js +82 -0
  86. package/compare.js.map +1 -0
  87. package/compare.ts +90 -0
  88. package/content_type.js +43 -0
  89. package/content_type.js.map +1 -0
  90. package/content_type.ts +58 -0
  91. package/deno.json +1 -0
  92. package/fixed.js +53 -0
  93. package/fixed.js.map +1 -0
  94. package/fixed.ts +61 -0
  95. package/graph.js +15 -0
  96. package/graph.js.map +1 -0
  97. package/graph.ts +22 -0
  98. package/hydrate.js +69 -0
  99. package/hydrate.js.map +1 -0
  100. package/hydrate.ts +72 -0
  101. package/identify.js +38 -0
  102. package/identify.js.map +1 -0
  103. package/identify.ts +50 -0
  104. package/image.js +111 -0
  105. package/image.js.map +1 -0
  106. package/image.ts +120 -0
  107. package/keywords.js +28 -0
  108. package/keywords.js.map +1 -0
  109. package/keywords.ts +28 -0
  110. package/meta/blob.vocab.json +17 -0
  111. package/mime.js +72 -0
  112. package/mime.js.map +1 -0
  113. package/mime.ts +73 -0
  114. package/mod.js +97 -0
  115. package/mod.js.map +1 -0
  116. package/mod.ts +115 -0
  117. package/object-put.js +90 -0
  118. package/object-put.js.map +1 -0
  119. package/object-put.ts +114 -0
  120. package/object.js +369 -0
  121. package/object.js.map +1 -0
  122. package/object.ts +592 -0
  123. package/package.json +84 -4
  124. package/parts.js +354 -0
  125. package/parts.js.map +1 -0
  126. package/parts.ts +423 -0
  127. package/plugin.js +158 -0
  128. package/plugin.js.map +1 -0
  129. package/plugin.ts +184 -0
  130. package/png.js +74 -0
  131. package/png.js.map +1 -0
  132. package/png.ts +58 -0
  133. package/props.js +32 -0
  134. package/props.js.map +1 -0
  135. package/props.ts +47 -0
  136. package/purge.js +65 -0
  137. package/purge.js.map +1 -0
  138. package/purge.ts +72 -0
  139. package/representation.js +34 -0
  140. package/representation.js.map +1 -0
  141. package/representation.ts +44 -0
  142. package/representation_rules.js +44 -0
  143. package/representation_rules.js.map +1 -0
  144. package/representation_rules.ts +57 -0
  145. package/routes.js +454 -0
  146. package/routes.js.map +1 -0
  147. package/routes.ts +575 -0
  148. package/serve.js +196 -0
  149. package/serve.js.map +1 -0
  150. package/serve.ts +242 -0
  151. package/sha256.js +185 -0
  152. package/sha256.js.map +1 -0
  153. package/sha256.ts +210 -0
  154. package/sqlite.js +201 -0
  155. package/sqlite.js.map +1 -0
  156. package/sqlite.ts +250 -0
  157. package/store.js +40 -0
  158. package/store.js.map +1 -0
  159. package/store.ts +93 -0
  160. package/stream.js +203 -0
  161. package/stream.js.map +1 -0
  162. package/stream.ts +256 -0
  163. package/upload.js +256 -0
  164. package/upload.js.map +1 -0
  165. package/upload.ts +404 -0
  166. package/value.js +234 -0
  167. package/value.js.map +1 -0
  168. package/value.ts +281 -0
  169. package/vocab.js +27 -0
  170. package/vocab.js.map +1 -0
  171. package/vocab.json +123 -0
  172. package/vocab.ts +32 -0
@@ -0,0 +1,38 @@
1
+ /** What an application takes as a blob. */ export type Accepts = {
2
+ maxLength?: number;
3
+ contentMediaType?: string | string[];
4
+ };
5
+ /**
6
+ * What is wrong with a declaration, a sentence each; none when it is one.
7
+ *
8
+ * ```ts
9
+ * import { assertEquals } from '@std/assert'
10
+ * import { acceptsErrors } from '@yaks/blob'
11
+ *
12
+ * assertEquals(acceptsErrors({ maxLength: 1048576, contentMediaType: 'image/*' }), [])
13
+ * assertEquals(acceptsErrors({ maxLength: -1 }), [
14
+ * 'maxLength is a whole number of bytes, more than none',
15
+ * ])
16
+ * assertEquals(acceptsErrors({ contentMediaType: ['image'] }), [
17
+ * 'contentMediaType "image" is a media type like image/png, or a range like image/*',
18
+ * ])
19
+ * ```
20
+ */ export declare let acceptsErrors: (said: unknown) => string[];
21
+ /** Whether a blob of `bytes` bytes is not too big. */ export declare let fits: (a: Accepts | undefined, bytes: number) => boolean;
22
+ /**
23
+ * Whether a blob of media type `type` is one of the types taken.
24
+ *
25
+ * ```ts
26
+ * import { assertEquals } from '@std/assert'
27
+ * import { takes } from '@yaks/blob'
28
+ *
29
+ * let photos = { contentMediaType: ['image/*', 'application/pdf'] }
30
+ * assertEquals(takes(photos, 'image/png'), true)
31
+ * assertEquals(takes(photos, 'application/pdf'), true)
32
+ * assertEquals(takes(photos, 'video/mp4'), false)
33
+ * assertEquals(takes({ contentMediaType: '*' + '/*' }, 'video/mp4'), true)
34
+ * assertEquals(takes({}, 'video/mp4'), true)
35
+ * ```
36
+ */ export declare let takes: (a: Accepts | undefined, type: string) => boolean;
37
+ /** The types taken, as a sentence names them: `image/* or application/pdf`. */ export declare let taken: (a: Accepts | undefined) => string;
38
+ //# sourceMappingURL=accepts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accepts.d.ts","sources":["../accepts.ts"],"names":[],"mappings":"AAUA,yCAAyC,GACzC,YAAY;EACV,YAAY,MAAM;EAClB,mBAAmB,MAAM,GAAG,MAAM;;AAWpC;;;;;;;;;;;;;;;CAeC,GACD,OAAO,YAAI,gBAAiB,MAAM,OAAO,KAAG,MAAM,GAwBjD;AAED,oDAAoD,GACpD,OAAO,YAAI,OAAQ,GAAG,UAAU,SAAS,EAAE,OAAO,MAAM,KAAG,OAAO,CACpB;AAE9C;;;;;;;;;;;;;;CAcC,GACD,OAAO,YAAI,QAAS,GAAG,UAAU,SAAS,EAAE,MAAM,MAAM,KAAG,OAAO,CAKjE;AAED,6EAA6E,GAC7E,OAAO,YAAI,QAAS,GAAG,UAAU,SAAS,KAAG,MAAM,CAClB"}
@@ -0,0 +1,29 @@
1
+ import type { Blobs } from "./store.js";
2
+ import type { VocabDoc } from "@yaks/vocab";
3
+ export type Artifact = {
4
+ address: string;
5
+ media_type: string;
6
+ size: number;
7
+ };
8
+ export type ArtifactStore = ((bytes: Uint8Array, mediaType: string) => Promise<Artifact>) & {
9
+ /** Refuses when the store has no room for more, so a model that makes
10
+ * bytes is asked before anything is paid for them. A store that is never
11
+ * full has none. */ room?: () => Promise<void>;
12
+ };
13
+ /** What these bytes are called: their SHA-256, lowercase hex. It is both the
14
+ * key in the store and the eid of the row, so there is no second name for the
15
+ * two sides to agree on. */ export declare let addressOf: (bytes: Uint8Array) => Promise<string>;
16
+ /** Put bytes under their address, once, and verify the store kept them. Writing
17
+ * the same pair twice is a no-op — the second copy is the first one — and a
18
+ * store that hands back anything else has not kept this object, which throws
19
+ * here rather than returning corrupt bytes later. A store that keeps any bytes
20
+ * as given (`exact`) is put to once: the same pair again writes what is
21
+ * already there, and a bucket's look first would be a second round trip. */ export declare let keep: (blobs: Blobs, address: string, bytes: Uint8Array) => Promise<void>;
22
+ /** The bytes an {@link Artifact} names, read back from where they are kept:
23
+ * `undefined` when the store holds nothing under its address, and an error
24
+ * when what it holds is not those bytes — another size, or another SHA-256.
25
+ * A row is a promise about the bytes, and this is where the promise is
26
+ * checked, so a reader never hands on bytes the row did not name. Bytes known
27
+ * by their address alone are checked against it alone. */ export declare let artifactBytes: (blobs: Blobs, artifact: Pick<Artifact, 'address'> & Partial<Artifact>) => Promise<Uint8Array | undefined>;
28
+ export declare let artifactDoc: VocabDoc;
29
+ //# sourceMappingURL=artifact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifact.d.ts","sources":["../artifact.ts"],"names":[],"mappings":"AAcA,cAAc,KAAK,qBAAoB;AACvC,cAAc,QAAQ,2BAAgC;AAGtD,YAAY;EACV,SAAS,MAAM;EACf,YAAY,MAAM;EAClB,MAAM,MAAM;;AAEd,YAAY,kBAER,OAAO,YACP,WAAW,MAAM,KACd,QAAQ;EAEX;;sBAEkB,GAClB,aAAa,QAAQ,IAAI;;AAG7B;;0BAE0B,GAC1B,OAAO,YAAI,YAAmB,OAAO,eAAa,QAAQ,MAAM,EAS/D;AAED;;;;;0EAK0E,GAC1E,OAAO,YAAI,OACT,OAAO,OACP,SAAS,MAAM,EACf,OAAO,eACN,QAAQ,IAAI,EAQd;AAED;;;;;wDAKwD,GACxD,OAAO,YAAI,gBACT,OAAO,OACP,UAAU,KAAK,UAAU,aAAa,QAAQ,cAC7C,QAAQ,aAAa,SAAS,EAYhC;AAED,OAAO,YAAI,aAAa,SAAc"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * An attachment is one use of immutable bytes, beside the message they came
3
+ * with: the bytes' `artifact` row, named by their address, and an
4
+ * `attachment` row for each message that carried them, named by that message
5
+ * and its place there. Sending the same bytes again with another message
6
+ * keeps both names; writing one message's files again patches the same rows.
7
+ *
8
+ * ```ts
9
+ * import { equal } from '@yaks/testing'
10
+ * import { attachmentOf, attachmentRows } from '@yaks/blob/attachment'
11
+ *
12
+ * let [bytes, use] = attachmentRows('m1', [
13
+ * { name: 'notes.pdf', media_type: 'application/pdf', address: 'c0ffee' },
14
+ * ])
15
+ * equal(bytes, {
16
+ * entity: { eid: 'c0ffee' },
17
+ * artifact: { address: 'c0ffee', media_type: 'application/pdf' },
18
+ * })
19
+ * equal(use.entity.eid, attachmentOf('m1', 0))
20
+ * ```
21
+ *
22
+ * What a reader is shown of them is {@link attachmentsSeen}: the attachment
23
+ * rows a clause admits and the artifacts they name, and nothing else in the
24
+ * graph, even where a query walks a reference.
25
+ *
26
+ * @module
27
+ */ import { type Bundle, type Graph } from "@yaks/graph";
28
+ import { type Clause } from "@yaks/query/core";
29
+ /** A file as a message carries it: its name, media type and the address its
30
+ * bytes are kept by, with their size where it is known, and the words read
31
+ * from it for a model that cannot read it as it is, once something has. */ export type Attached = {
32
+ name: string;
33
+ media_type: string;
34
+ address: string;
35
+ size?: number;
36
+ text?: string;
37
+ };
38
+ /** The attachment's stable identity within the message that carried it. The
39
+ * words it is derived from are the ones its first rows were named by. */ export declare let attachmentOf: (message: string, index: number) => string;
40
+ /** The bytes of each file, and each one's use beside `message`. */ export declare let attachmentRows: (message: string, files: Attached[]) => Bundle[];
41
+ /** The files each of these messages came with, in the order they came: each
42
+ * attachment beside it (`attachmentRows`) and the size its bytes are kept at.
43
+ * A message with none is left out. */ export declare let attachedTo: (g: Pick<Graph, 'read' | 'get'>, messages: string[]) => Promise<Map<string, Attached[]>>;
44
+ /** The artifact row of each address `head` finds kept, its media type read
45
+ * from the first bytes `head` gives back. An address with nothing kept is
46
+ * left out, for the graph to hold as it is. */ export declare let artifactsOf: (addresses: string[], head: (address: string) => Promise<Uint8Array | null>) => Promise<Bundle[]>;
47
+ /**
48
+ * `q` asked as graph_query asks it, of only the attachment rows `admits` lets
49
+ * a reader see and the artifact rows they name: their names, media types and
50
+ * sizes, never the messages they came with or anything else, even where `q`
51
+ * walks a reference. `call` is the query's call, which the answer names.
52
+ */ export declare let attachmentsSeen: (g: Pick<Graph, 'read' | 'get' | 'vocab'>, admits: Clause, q: string, call?: string) => Promise<Bundle[]>;
53
+ //# sourceMappingURL=attachment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment.d.ts","sources":["../attachment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,SAAS,KAAK,MAAM,EAAE,KAAK,KAAK,2BAAuC;AAIvE,SAEE,KAAK,MAAM,gCAQuB;AAGpC;;yEAEyE,GACzE,YAAY;EACV,MAAM,MAAM;EACZ,YAAY,MAAM;EAClB,SAAS,MAAM;EACf,OAAO,MAAM;EACb,OAAO,MAAM;;AAGf;uEACuE,GACvE,OAAO,YAAI,eAAgB,SAAS,MAAM,EAAE,OAAO,MAAM,KAAG,MAAM,CACX;AAEvD,iEAAiE,GACjE,OAAO,YAAI,iBAAkB,SAAS,MAAM,EAAE,OAAO,eAAa,SAiB7D;AAEL;;oCAEoC,GACpC,OAAO,YAAI,aACT,GAAG,KAAK,OAAO,SAAS,QACxB,UAAU,MAAM,OACf,QAAQ,IAAI,MAAM,EAAE,aAqCtB;AAUD;;6CAE6C,GAC7C,OAAO,YAAI,cACT,WAAW,MAAM,IACjB,OAAO,SAAS,MAAM,KAAK,QAAQ,aAAa,IAAI,MACnD,QAAQ,UAWV;AAgBD;;;;;CAKC,GACD,OAAO,YAAI,kBACT,GAAG,KAAK,OAAO,SAAS,QAAQ,UAChC,QAAQ,QACR,GAAG,MAAM,EACT,OAAM,MAAM,KACX,QAAQ,UAuBV"}
@@ -0,0 +1,20 @@
1
+ import { type Bucket } from "./object.js";
2
+ import type { Blobs } from "./store.js";
3
+ /** A byte store, as a graph's configuration names one. */ export type Backend = {
4
+ via: 'sqlite';
5
+ } | {
6
+ via: 'file';
7
+ dir: string;
8
+ } | {
9
+ via: 'object';
10
+ bucket: Pick<Bucket, 'head' | 'get' | 'put' | 'delete'>;
11
+ prefix?: string;
12
+ };
13
+ /** Build the backend named by a config, or explain why it cannot serve. */ export declare let backend: (said: Backend, host: {
14
+ blobs?: Blobs;
15
+ files?: (dir: string) => Blobs;
16
+ }) => {
17
+ store?: Blobs;
18
+ waiting?: string;
19
+ };
20
+ //# sourceMappingURL=backend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend.d.ts","sources":["../backend.ts"],"names":[],"mappings":"AAMA,SAAS,KAAK,MAAM,sBAAkC;AACtD,cAAc,KAAK,qBAAoB;AAEvC,wDAAwD,GACxD,YAAY;EACN,KAAK;;EACL,KAAK;EAAQ,KAAK,MAAM;;EAE1B,KAAK;EACL,QAAQ,KAAK,QAAQ,SAAS,QAAQ,QAAQ;EAC9C,SAAS,MAAM;;AAGnB,yEAAyE,GACzE,OAAO,YAAI,UACT,MAAM,SACN;EAAQ,QAAQ;EAAO,SAAS,KAAK,MAAM,KAAK;;EAC7C,QAAQ;EAAO,UAAU,MAAM;EAoBnC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * What is wrong with bytes that claim to be a picture of `type`, or
3
+ * `undefined` when they decode as one (or `type` is one nothing here reads).
4
+ * The answer is a clause, to follow "icon.png does not decode: ".
5
+ *
6
+ * ```ts
7
+ * import { assertEquals } from '@std/assert'
8
+ * import { broken } from '@yaks/blob'
9
+ *
10
+ * let png = Uint8Array.from(atob(
11
+ * 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==',
12
+ * ), (c) => c.charCodeAt(0))
13
+ * assertEquals(await broken(png, 'image/png'), undefined)
14
+ * assertEquals(
15
+ * await broken(png.slice(0, 50), 'image/png'),
16
+ * 'it ends inside its IDAT chunk',
17
+ * )
18
+ * assertEquals(
19
+ * await broken(png, 'image/jpeg'),
20
+ * 'its bytes are a PNG, not a JPEG',
21
+ * )
22
+ * ```
23
+ */ export declare let broken: (b: Uint8Array, type: string) => Promise<string | undefined>;
24
+ //# sourceMappingURL=broken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broken.d.ts","sources":["../broken.ts"],"names":[],"mappings":"AAoLA;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,OAAO,YAAI,SACT,GAAG,YACH,MAAM,MAAM,KACX,QAAQ,MAAM,GAAG,SAAS,EAU5B"}
@@ -0,0 +1,27 @@
1
+ /** The digest and the hash state at each whole MiB, for resuming parts. */ export type FileHash = {
2
+ sha: string;
3
+ states: string[];
4
+ };
5
+ /** The SHA-256 address of a file, read in bounded pieces. */ export declare let digest: (blob: Blob) => Promise<string>;
6
+ /** The blob door's upload receipt. */ export type Uploaded = {
7
+ eid: string;
8
+ attachment: string;
9
+ url: string;
10
+ mime: string;
11
+ bytes: number;
12
+ w?: number;
13
+ h?: number;
14
+ };
15
+ /** Call an upload route relative to the app's API and decode its answer. */ export type Ask = (path: string, init: RequestInit) => Promise<unknown>;
16
+ export type Again = <T>(call: () => Promise<T>) => Promise<T>;
17
+ /** Options for one file sent through the blob door. */ export type Sending = {
18
+ name?: string;
19
+ signal?: AbortSignal;
20
+ /** Each checkpoint lists the parts the door has received. */ progress?: (part: number, sent: number[]) => void | Promise<void>;
21
+ /** Reuse a checkpoint for the same bytes after reopening the queue. */ hash?: FileHash;
22
+ prepared?: (hash: FileHash) => void | Promise<void>;
23
+ /** Number of requests sending parts of this file concurrently. */ lanes?: number;
24
+ };
25
+ /** Send a file whole or through the blob door's resumable multipart protocol.
26
+ * Each multipart attempt asks the door which parts still need to arrive. */ export declare let uploading: (ask: Ask, again?: Again) => (file: Blob, opts?: Sending) => Promise<Uploaded>;
27
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sources":["../browser.ts"],"names":[],"mappings":"AAOA,yEAAyE,GACzE,YAAY;EAAa,KAAK,MAAM;EAAE,QAAQ,MAAM;;AAcpD,2DAA2D,GAC3D,OAAO,YAAI,SAAgB,MAAM,SAAO,QAAQ,MAAM,EAC5B;AAE1B,oCAAoC,GACpC,YAAY;EACV,KAAK,MAAM;EACX,YAAY,MAAM;EAClB,KAAK,MAAM;EACX,MAAM,MAAM;EACZ,OAAO,MAAM;EACb,IAAI,MAAM;EACV,IAAI,MAAM;;AAGZ,0EAA0E,GAC1E,YAAY,OAAO,MAAM,MAAM,EAAE,MAAM,gBAAgB,QAAQ,OAAO;AACtE,YAAY,SAAS,GAAG,YAAY,QAAQ,OAAO,QAAQ;AAE3D,qDAAqD,GACrD,YAAY;EACV,OAAO,MAAM;EACb,SAAS;EACT,2DAA2D,GAC3D,YAAY,MAAM,MAAM,EAAE,MAAM,MAAM,OAAO,IAAI,GAAG,QAAQ,IAAI;EAChE,qEAAqE,GACrE,OAAO;EACP,YAAY,MAAM,aAAa,IAAI,GAAG,QAAQ,IAAI;EAClD,gEAAgE,GAChE,QAAQ,MAAM;;AAsChB;0EAC0E,GAC1E,OAAO,YAAI,YACT,KAAK,KACL,QAAO,WACL,MAAM,MAAM,OAAO,YAAY,QAAQ,UAoF1C"}
@@ -0,0 +1,4 @@
1
+ import type { Opened } from "./object.js";
2
+ /** Null when `sent` is the stored object's exact bytes. Otherwise return
3
+ * the original response stream, including the bytes read to compare it. */ export declare let differing: (sent: ReadableStream<Uint8Array>, original: Opened) => Promise<ReadableStream<Uint8Array> | null>;
4
+ //# sourceMappingURL=compare.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare.d.ts","sources":["../compare.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,sBAAqB;AAuCzC;yEACyE,GACzE,OAAO,YAAI,YACT,MAAM,eAAe,aACrB,UAAU,WACT,QAAQ,eAAe,cAAc,IAAI,EA6C3C"}
@@ -0,0 +1,20 @@
1
+ /** A declared media type with no parameters or header control characters. */ export declare let mediaType: (declared?: string) => string;
2
+ /**
3
+ * Whether bytes are text: UTF-8 with no control character but tab, line feed
4
+ * and carriage return. For the first bytes of a file (`whole` false), a
5
+ * character the cut split in two is not held against them.
6
+ *
7
+ * ```ts
8
+ * import { assertEquals } from '@std/assert'
9
+ * import { utf8 } from '@yaks/blob'
10
+ *
11
+ * let bytes = (s: string) => new TextEncoder().encode(s)
12
+ * assertEquals(utf8(bytes('<h1>Café</h1>\n')), true)
13
+ * assertEquals(utf8(new Uint8Array([0x89, 0x50, 0x4e, 0x47])), false)
14
+ * assertEquals(utf8(bytes('a\x00b')), false)
15
+ * assertEquals(utf8(bytes('Café').subarray(0, 4)), false)
16
+ * assertEquals(utf8(bytes('Café').subarray(0, 4), false), true)
17
+ * ```
18
+ */ export declare let utf8: (bytes: Uint8Array, whole?: boolean) => boolean;
19
+ /** Formats whose declaration can be checked without a file-type guess. */ export declare let matchesMediaType: (bytes: Uint8Array, mime: string) => boolean;
20
+ //# sourceMappingURL=content_type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content_type.d.ts","sources":["../content_type.ts"],"names":[],"mappings":"AAQA,2EAA2E,GAC3E,OAAO,YAAI,YAAa,sBAAgB,MAAM,CAG7C;AAED;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,YAAI,OAAQ,OAAO,YAAY,oBAAe,OAAO,CAS3D;AAMD,wEAAwE,GACxE,OAAO,YAAI,mBAAoB,OAAO,YAAY,MAAM,MAAM,KAAG,OAAO,CAUJ"}
@@ -0,0 +1,13 @@
1
+ import type { Plugin } from "@yaks/graph";
2
+ import type { Vocab } from "@yaks/vocab";
3
+ import type { Blobs } from "./store.js";
4
+ /** The plugin for every body property this vocabulary marks `store: blob`,
5
+ * storing each distinct value once in the host's blob store however many rows
6
+ * hold the same text. */ export declare let plugins: (host: {
7
+ vocab: Vocab;
8
+ blobs: Blobs;
9
+ }) => Plugin[];
10
+ /** A store this plugin wrote keeps an address where each body's text was,
11
+ * which only this plugin reads back as text and writes in its place: from
12
+ * then on the store requires it (@yaks/host `GraphFacet.required`). */ export declare let required: () => boolean;
13
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sources":["../graph.ts"],"names":[],"mappings":"AAIA,cAAc,MAAM,2BAAgC;AACpD,cAAc,KAAK,2BAAgC;AAGnD,cAAc,KAAK,qBAAoB;AAEvC;;uBAEuB,GACvB,OAAO,YAAI,UAAW;EAAQ,OAAO;EAAO,OAAO;MAAU,SAG5D;AAED;;qEAEqE,GACrE,OAAO,YAAI,gBAAe,OAAO,CAAQ"}
@@ -0,0 +1,36 @@
1
+ import type { Bundle } from "@yaks/graph";
2
+ import type { Vocab } from "@yaks/vocab";
3
+ import { type Blobs } from "./store.js";
4
+ /**
5
+ * Resolve every content-addressed property in these bundles: each address is
6
+ * looked up in the store and replaced by the text it names. An address the
7
+ * store does not hold is left in place — dropping the value would be a worse
8
+ * result than an address nobody can resolve.
9
+ *
10
+ * ```ts
11
+ * import { assertEquals } from '@std/assert'
12
+ * import { loadVocab } from '@yaks/vocab'
13
+ * import {
14
+ * address,
15
+ * blobKeywords,
16
+ * encode,
17
+ * hydrate,
18
+ * memoryBlobs,
19
+ * } from '@yaks/blob'
20
+ *
21
+ * let body = { type: 'string', store: 'blob' }
22
+ * let post = { component: true, type: 'object', properties: { body } }
23
+ * let vocab = loadVocab([{ $defs: { post } }], [blobKeywords])
24
+ * let store = memoryBlobs()
25
+ * store.put(address('A long essay.'), encode('A long essay.'))
26
+ *
27
+ * let essay = address('A long essay.')
28
+ * let read = { entity: { eid: 'p1' }, post: { body: essay } }
29
+ * let [p1] = await hydrate(vocab, store, [read])
30
+ * assertEquals(p1.post, { body: 'A long essay.' })
31
+ * ```
32
+ *
33
+ * Asynchronous only when the store is: over a synchronous backend this returns
34
+ * the bundles directly.
35
+ */ export declare let hydrate: (vocab: Vocab, store: Blobs, bundles: Bundle[]) => Bundle[] | Promise<Bundle[]>;
36
+ //# sourceMappingURL=hydrate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hydrate.d.ts","sources":["../hydrate.ts"],"names":[],"mappings":"AAUA,cAAc,MAAM,2BAAsC;AAE1D,cAAc,KAAK,2BAAgC;AAEnD,SAAS,KAAK,KAAK,qBAA4B;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BC,GACD,OAAO,YAAI,UACT,OAAO,OACP,OAAO,OACP,SAAS,aACR,WAAW,QAAQ,UAmBrB"}
@@ -0,0 +1,7 @@
1
+ import { type ArtifactStore } from "./artifact.js";
2
+ import type { Blobs } from "./store.js";
3
+ /** A stable media type chosen from bytes and, for text, a valid declaration.
4
+ * `whole` false says the bytes are only a file's first ones. */ export declare let contentType: (bytes: Uint8Array, declared?: string, whole?: boolean) => Promise<string>;
5
+ /** Store bytes and their media type, and return the {@link Artifact} a row
6
+ * records. */ export declare let artifactStore: (blobs: Blobs) => ArtifactStore;
7
+ //# sourceMappingURL=identify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identify.d.ts","sources":["../identify.ts"],"names":[],"mappings":"AAIA,SAAoB,KAAK,aAAa,wBAA6B;AACnE,cAAc,KAAK,qBAAoB;AAavC;8DAC8D,GAC9D,OAAO,YAAI,cACT,OAAO,YACP,mBACA,oBACC,QAAQ,MAAM,EAYhB;AAED;YACY,GACZ,OAAO,YAAI,gBACR,OAAO,UAAQ,cAQf"}
@@ -0,0 +1,37 @@
1
+ export type Size = {
2
+ w: number;
3
+ h: number;
4
+ };
5
+ /**
6
+ * What kind of picture the bytes are, read from their own signature — the one
7
+ * thing a caller can trust over the label it was handed — or `undefined` for
8
+ * anything that is not one of the four formats.
9
+ *
10
+ * ```ts
11
+ * import { assertEquals } from '@std/assert'
12
+ * import { mediaTypeOf } from '@yaks/blob'
13
+ *
14
+ * let png = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])
15
+ * assertEquals(mediaTypeOf(png), 'image/png')
16
+ * assertEquals(mediaTypeOf(new TextEncoder().encode('<svg/>')), undefined)
17
+ * ```
18
+ */ export declare let mediaTypeOf: (b: Uint8Array) => string | undefined;
19
+ /**
20
+ * The size a file states about itself, or `undefined` — including for a header
21
+ * that states a zero, which is a broken file and not a picture of no width.
22
+ *
23
+ * ```ts
24
+ * import { assertEquals } from '@std/assert'
25
+ * import { sizeOf } from '@yaks/blob'
26
+ *
27
+ * // A PNG's signature and the head of its IHDR chunk: 1600 by 900.
28
+ * let png = new Uint8Array([
29
+ * 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
30
+ * 0, 0, 0, 13, 0x49, 0x48, 0x44, 0x52,
31
+ * 0, 0, 0x06, 0x40, 0, 0, 0x03, 0x84,
32
+ * ])
33
+ * assertEquals(sizeOf(png), { w: 1600, h: 900 })
34
+ * assertEquals(sizeOf(new TextEncoder().encode('%PDF-1.7')), undefined)
35
+ * ```
36
+ */ export declare let sizeOf: (b: Uint8Array) => Size | undefined;
37
+ //# sourceMappingURL=image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.d.ts","sources":["../image.ts"],"names":[],"mappings":"AAWA,YAAY;EAAS,GAAG,MAAM;EAAE,GAAG,MAAM;;AA8DzC;;;;;;;;;;;;;CAaC,GACD,OAAO,YAAI,cAAe,GAAG,eAAa,MAAM,GAAG,SAAS,CAS7C;AAEf;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,YAAI,SAAU,GAAG,eAAa,OAAO,SAAS,CAGpD"}
@@ -0,0 +1,10 @@
1
+ import type { Keywords } from "@yaks/vocab";
2
+ /** The URI a vocabulary file lists under `$vocabulary` to use `store` and
3
+ * `address`. */ export declare let BLOB_URI: string;
4
+ /**
5
+ * The `store` and `address` keyword vocabulary, ready to register:
6
+ * `loadVocab(docs, [blobKeywords])` carries each property's declaration onto
7
+ * `v.prop(comp, prop).keywords.store`, which is where {@link bodies} reads
8
+ * it.
9
+ */ export declare let blobKeywords: Keywords;
10
+ //# sourceMappingURL=keywords.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keywords.d.ts","sources":["../keywords.ts"],"names":[],"mappings":"AAUA,cAAc,QAAQ,2BAAgC;AAGtD;cACc,GACd,OAAO,YAAI,iBAAsC;AAEjD;;;;;CAKC,GACD,OAAO,YAAI,cAAc,SAIxB"}
@@ -0,0 +1,2 @@
1
+ export declare let mimeOf: (name: string) => string;
2
+ //# sourceMappingURL=mime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mime.d.ts","sources":["../mime.ts"],"names":[],"mappings":"AAmEA,OAAO,YAAI,SAAU,MAAM,MAAM,KAAG,MAAM,CAKzC"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @yaks/blob — content-addressed storage for a text property, applied without
3
+ * any caller having to know.
4
+ *
5
+ * A blog post's body, a product description, a page of notes: values that are
6
+ * long, often repeated, and awkward in a row. Mark the property and they move:
7
+ *
8
+ * ```ts
9
+ * import { assertObjectMatch } from '@std/assert'
10
+ * import { loadVocab } from '@yaks/vocab'
11
+ * import { graph } from '@yaks/graph'
12
+ * import { storage } from '@yaks/sqlite'
13
+ * import { open } from '@yaks/sqlite/db'
14
+ * import {
15
+ * blobKeywords,
16
+ * blobRead,
17
+ * blobs,
18
+ * blobSchema,
19
+ * sqliteBlobs,
20
+ * } from '@yaks/blob'
21
+ *
22
+ * let blog = {
23
+ * $defs: {
24
+ * post: {
25
+ * component: true,
26
+ * type: 'object',
27
+ * properties: {
28
+ * title: { type: 'string' },
29
+ * // the one declaration this package reads
30
+ * body: { type: 'string', store: 'blob' },
31
+ * },
32
+ * },
33
+ * },
34
+ * }
35
+ * let vocab = loadVocab([blog], [blobKeywords])
36
+ * let driver = open(':memory:')
37
+ * let db = storage(driver, vocab, { derived: blobRead(vocab) })
38
+ * for (let s of [...db.ddl(), ...blobSchema()]) driver.query(s)
39
+ * let store = sqliteBlobs(db.statements)
40
+ * let g = graph({ storage: db, vocab, plugins: [blobs(vocab, store)] })
41
+ *
42
+ * g.apply([{ entity: { eid: 'p1' }, post: { body: 'a long essay…' } }])
43
+ * assertObjectMatch(db.read('.post')[0], { post: { body: 'a long essay…' } })
44
+ * ```
45
+ *
46
+ * Nothing between those two lines mentions blobs. The write went in as text and
47
+ * came back as text; in between, the row kept the SHA-256 of the essay and the
48
+ * essay itself went to the store — once, however many posts quote it.
49
+ *
50
+ * ## What it is made of
51
+ *
52
+ * - **One keyword.** {@link blobKeywords} registers `store` with @yaks/vocab,
53
+ * so a schema can carry the word and this package supplies its meaning. To
54
+ * the schema a body property is a plain string property, and it stays one for
55
+ * validation, routing and queries.
56
+ * - **One plugin.** {@link blobs} replaces the text with its address on the way
57
+ * in and puts it back before `apply()` returns. It runs inside the
58
+ * transaction, so the bytes and the row that addresses them commit together.
59
+ * - **One byte-store interface.** {@link Blobs} is `has`, `get` and `put` over
60
+ * `Uint8Array`, keyed by {@link address}. Three implementations ship with the
61
+ * package: {@link sqliteBlobs} (a table beside your rows — synchronous, and
62
+ * the only one SQL can read through), `fileBlobs` (a directory, from `@yaks/file/blobs`), and
63
+ * {@link objectBlobs} (an S3-shaped bucket, R2 included).
64
+ * - **Two read paths.** Over SQL, {@link blobRead} resolves the address in the
65
+ * statement itself; over any other store, {@link hydrate} resolves the
66
+ * bundles a read returned.
67
+ *
68
+ * Removing the plugin does not strand your data: a body property is a text
69
+ * property holding a hash, and the store is a table of hashes and text.
70
+ *
71
+ * The core — the keyword, the plugin, the interface, and the SQLite store —
72
+ * imports no platform API, so the same code runs on a server, in a worker, and
73
+ * in a browser tab. `fileBlobs` is the one store that needs a filesystem, so it
74
+ * lives in @yaks/file (`@yaks/file/blobs`), which those runtimes never load.
75
+ *
76
+ * @module
77
+ */ export * from "./keywords.js";
78
+ export * from "./props.js";
79
+ export * from "./store.js";
80
+ export * from "./plugin.js";
81
+ export * from "./sqlite.js";
82
+ export * from "./hydrate.js";
83
+ export * from "./object.js";
84
+ export * from "./accepts.js";
85
+ export * from "./parts.js";
86
+ export * from "./sha256.js";
87
+ export * from "./stream.js";
88
+ export * from "./image.js";
89
+ export { broken } from "./broken.js";
90
+ export * from "./serve.js";
91
+ export * from "./mime.js";
92
+ export * from "./content_type.js";
93
+ export * from "./representation.js";
94
+ export * from "./representation_rules.js";
95
+ export { VALUE_LIMIT, type ValueRange, valueRange, type ValueReader, type ValueSearch, valueSearch, type ValueTool, valueTools } from "./value.js";
96
+ export { addressOf, type Artifact, artifactBytes, artifactDoc, type ArtifactStore, keep } from "./artifact.js";
97
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4EC,GAED,8BAA6B;AAC7B,2BAA0B;AAC1B,2BAA0B;AAC1B,4BAA2B;AAC3B,4BAA2B;AAC3B,6BAA4B;AAC5B,4BAA2B;AAC3B,6BAA4B;AAC5B,2BAA0B;AAC1B,4BAA2B;AAC3B,4BAA2B;AAC3B,2BAA0B;AAC1B,SAAS,MAAM,sBAAqB;AACpC,2BAA0B;AAC1B,0BAAyB;AACzB,kCAAiC;AACjC,oCAAmC;AACnC,0CAAyC;AAEzC,SACE,WAAW,EACX,KAAK,UAAU,EACf,UAAU,EACV,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,WAAW,EACX,KAAK,SAAS,EACd,UAAU,qBACO;AACnB,SACE,SAAS,EACT,KAAK,QAAQ,EACb,aAAa,EACb,WAAW,EACX,KAAK,aAAa,EAClB,IAAI,wBACgB"}
@@ -0,0 +1,2 @@
1
+ export type Discard = (remove: () => Promise<void>) => Promise<void>;
2
+ //# sourceMappingURL=object-put.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-put.d.ts","sources":["../object-put.ts"],"names":[],"mappings":"AAOA,YAAY,WAAW,cAAc,QAAQ,IAAI,MAAM,QAAQ,IAAI"}