@smthrs/artifacts 0.0.0-stage → 1.0.0-rc.12

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 (171) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/LICENSE +21 -0
  3. package/README.md +175 -2
  4. package/dist/cjs/ArtifactBackupLease.d.ts +34 -0
  5. package/dist/cjs/ArtifactBackupLease.d.ts.map +1 -0
  6. package/dist/cjs/ArtifactBackupLease.js +183 -0
  7. package/dist/cjs/ArtifactBackupLease.js.map +7 -0
  8. package/dist/cjs/ArtifactStore.d.ts +129 -0
  9. package/dist/cjs/ArtifactStore.d.ts.map +1 -0
  10. package/dist/cjs/ArtifactStore.js +73 -0
  11. package/dist/cjs/ArtifactStore.js.map +7 -0
  12. package/dist/cjs/ArtifactStoreError.d.ts +82 -0
  13. package/dist/cjs/ArtifactStoreError.d.ts.map +1 -0
  14. package/dist/cjs/ArtifactStoreError.js +72 -0
  15. package/dist/cjs/ArtifactStoreError.js.map +7 -0
  16. package/dist/cjs/ArtifactStoreMetrics.d.ts +70 -0
  17. package/dist/cjs/ArtifactStoreMetrics.d.ts.map +1 -0
  18. package/dist/cjs/ArtifactStoreMetrics.js +51 -0
  19. package/dist/cjs/ArtifactStoreMetrics.js.map +7 -0
  20. package/dist/cjs/ArtifactSweep.d.ts +185 -0
  21. package/dist/cjs/ArtifactSweep.d.ts.map +1 -0
  22. package/dist/cjs/ArtifactSweep.js +171 -0
  23. package/dist/cjs/ArtifactSweep.js.map +7 -0
  24. package/dist/cjs/CombinedArtifacts.d.ts +103 -0
  25. package/dist/cjs/CombinedArtifacts.d.ts.map +1 -0
  26. package/dist/cjs/CombinedArtifacts.js +189 -0
  27. package/dist/cjs/CombinedArtifacts.js.map +7 -0
  28. package/dist/cjs/FileLease.d.ts +117 -0
  29. package/dist/cjs/FileLease.d.ts.map +1 -0
  30. package/dist/cjs/FileLease.js +208 -0
  31. package/dist/cjs/FileLease.js.map +7 -0
  32. package/dist/cjs/FileSystemArtifactStore.d.ts +93 -0
  33. package/dist/cjs/FileSystemArtifactStore.d.ts.map +1 -0
  34. package/dist/cjs/FileSystemArtifactStore.js +276 -0
  35. package/dist/cjs/FileSystemArtifactStore.js.map +7 -0
  36. package/dist/cjs/MemoryArtifactStore.d.ts +25 -0
  37. package/dist/cjs/MemoryArtifactStore.d.ts.map +1 -0
  38. package/dist/cjs/MemoryArtifactStore.js +84 -0
  39. package/dist/cjs/MemoryArtifactStore.js.map +7 -0
  40. package/dist/cjs/NoopArtifactStore.d.ts +17 -0
  41. package/dist/cjs/NoopArtifactStore.d.ts.map +1 -0
  42. package/dist/cjs/NoopArtifactStore.js +46 -0
  43. package/dist/cjs/NoopArtifactStore.js.map +7 -0
  44. package/dist/cjs/RemoteArtifacts.d.ts +237 -0
  45. package/dist/cjs/RemoteArtifacts.d.ts.map +1 -0
  46. package/dist/cjs/RemoteArtifacts.js +405 -0
  47. package/dist/cjs/RemoteArtifacts.js.map +7 -0
  48. package/dist/cjs/index.d.ts +65 -0
  49. package/dist/cjs/index.d.ts.map +1 -0
  50. package/dist/cjs/index.js +47 -0
  51. package/dist/cjs/index.js.map +7 -0
  52. package/dist/cjs/internal/ArtifactLocks.d.ts +30 -0
  53. package/dist/cjs/internal/ArtifactLocks.d.ts.map +1 -0
  54. package/dist/cjs/internal/ArtifactLocks.js +93 -0
  55. package/dist/cjs/internal/ArtifactLocks.js.map +7 -0
  56. package/dist/cjs/internal/ArtifactPath.d.ts +19 -0
  57. package/dist/cjs/internal/ArtifactPath.d.ts.map +1 -0
  58. package/dist/cjs/internal/ArtifactPath.js +74 -0
  59. package/dist/cjs/internal/ArtifactPath.js.map +7 -0
  60. package/dist/cjs/measureBytes.d.ts +18 -0
  61. package/dist/cjs/measureBytes.d.ts.map +1 -0
  62. package/dist/cjs/measureBytes.js +43 -0
  63. package/dist/cjs/measureBytes.js.map +7 -0
  64. package/dist/cjs/package.json +1 -0
  65. package/dist/cjs/snapshotBytes.d.ts +19 -0
  66. package/dist/cjs/snapshotBytes.d.ts.map +1 -0
  67. package/dist/cjs/snapshotBytes.js +41 -0
  68. package/dist/cjs/snapshotBytes.js.map +7 -0
  69. package/dist/cjs/validateDigest.d.ts +22 -0
  70. package/dist/cjs/validateDigest.d.ts.map +1 -0
  71. package/dist/cjs/validateDigest.js +42 -0
  72. package/dist/cjs/validateDigest.js.map +7 -0
  73. package/dist/esm/ArtifactBackupLease.d.ts +34 -0
  74. package/dist/esm/ArtifactBackupLease.d.ts.map +1 -0
  75. package/dist/esm/ArtifactBackupLease.js +126 -0
  76. package/dist/esm/ArtifactBackupLease.js.map +1 -0
  77. package/dist/esm/ArtifactStore.d.ts +129 -0
  78. package/dist/esm/ArtifactStore.d.ts.map +1 -0
  79. package/dist/esm/ArtifactStore.js +83 -0
  80. package/dist/esm/ArtifactStore.js.map +1 -0
  81. package/dist/esm/ArtifactStoreError.d.ts +82 -0
  82. package/dist/esm/ArtifactStoreError.d.ts.map +1 -0
  83. package/dist/esm/ArtifactStoreError.js +77 -0
  84. package/dist/esm/ArtifactStoreError.js.map +1 -0
  85. package/dist/esm/ArtifactStoreMetrics.d.ts +70 -0
  86. package/dist/esm/ArtifactStoreMetrics.d.ts.map +1 -0
  87. package/dist/esm/ArtifactStoreMetrics.js +77 -0
  88. package/dist/esm/ArtifactStoreMetrics.js.map +1 -0
  89. package/dist/esm/ArtifactSweep.d.ts +185 -0
  90. package/dist/esm/ArtifactSweep.d.ts.map +1 -0
  91. package/dist/esm/ArtifactSweep.js +210 -0
  92. package/dist/esm/ArtifactSweep.js.map +1 -0
  93. package/dist/esm/CombinedArtifacts.d.ts +103 -0
  94. package/dist/esm/CombinedArtifacts.d.ts.map +1 -0
  95. package/dist/esm/CombinedArtifacts.js +214 -0
  96. package/dist/esm/CombinedArtifacts.js.map +1 -0
  97. package/dist/esm/FileLease.d.ts +117 -0
  98. package/dist/esm/FileLease.d.ts.map +1 -0
  99. package/dist/esm/FileLease.js +249 -0
  100. package/dist/esm/FileLease.js.map +1 -0
  101. package/dist/esm/FileSystemArtifactStore.d.ts +93 -0
  102. package/dist/esm/FileSystemArtifactStore.d.ts.map +1 -0
  103. package/dist/esm/FileSystemArtifactStore.js +336 -0
  104. package/dist/esm/FileSystemArtifactStore.js.map +1 -0
  105. package/dist/esm/MemoryArtifactStore.d.ts +25 -0
  106. package/dist/esm/MemoryArtifactStore.d.ts.map +1 -0
  107. package/dist/esm/MemoryArtifactStore.js +67 -0
  108. package/dist/esm/MemoryArtifactStore.js.map +1 -0
  109. package/dist/esm/NoopArtifactStore.d.ts +17 -0
  110. package/dist/esm/NoopArtifactStore.d.ts.map +1 -0
  111. package/dist/esm/NoopArtifactStore.js +27 -0
  112. package/dist/esm/NoopArtifactStore.js.map +1 -0
  113. package/dist/esm/RemoteArtifacts.d.ts +237 -0
  114. package/dist/esm/RemoteArtifacts.d.ts.map +1 -0
  115. package/dist/esm/RemoteArtifacts.js +557 -0
  116. package/dist/esm/RemoteArtifacts.js.map +1 -0
  117. package/dist/esm/index.d.ts +65 -0
  118. package/dist/esm/index.d.ts.map +1 -0
  119. package/dist/esm/index.js +65 -0
  120. package/dist/esm/index.js.map +1 -0
  121. package/dist/esm/internal/ArtifactLocks.d.ts +30 -0
  122. package/dist/esm/internal/ArtifactLocks.d.ts.map +1 -0
  123. package/dist/esm/internal/ArtifactLocks.js +86 -0
  124. package/dist/esm/internal/ArtifactLocks.js.map +1 -0
  125. package/dist/esm/internal/ArtifactPath.d.ts +19 -0
  126. package/dist/esm/internal/ArtifactPath.d.ts.map +1 -0
  127. package/dist/esm/internal/ArtifactPath.js +59 -0
  128. package/dist/esm/internal/ArtifactPath.js.map +1 -0
  129. package/dist/esm/measureBytes.d.ts +18 -0
  130. package/dist/esm/measureBytes.d.ts.map +1 -0
  131. package/dist/esm/measureBytes.js +22 -0
  132. package/dist/esm/measureBytes.js.map +1 -0
  133. package/dist/esm/snapshotBytes.d.ts +19 -0
  134. package/dist/esm/snapshotBytes.d.ts.map +1 -0
  135. package/dist/esm/snapshotBytes.js +30 -0
  136. package/dist/esm/snapshotBytes.js.map +1 -0
  137. package/dist/esm/validateDigest.d.ts +22 -0
  138. package/dist/esm/validateDigest.d.ts.map +1 -0
  139. package/dist/esm/validateDigest.js +26 -0
  140. package/dist/esm/validateDigest.js.map +1 -0
  141. package/docs/README.md +202 -0
  142. package/docs/api.md +484 -0
  143. package/docs/concepts/content-addressing.md +174 -0
  144. package/docs/concepts/coordination.md +141 -0
  145. package/docs/concepts/tiers.md +147 -0
  146. package/docs/guides/fence-a-backup.md +123 -0
  147. package/docs/guides/reclaim-disk-space.md +143 -0
  148. package/docs/guides/serve-the-artifact-protocol.md +140 -0
  149. package/docs/guides/share-artifacts-across-machines.md +180 -0
  150. package/docs/guides/test-against-an-artifact-store.md +158 -0
  151. package/docs/installation.md +102 -0
  152. package/docs/quickstart.md +183 -0
  153. package/docs/troubleshooting.md +232 -0
  154. package/package.json +179 -3
  155. package/src/ArtifactBackupLease.ts +223 -0
  156. package/src/ArtifactStore.ts +152 -0
  157. package/src/ArtifactStoreError.ts +96 -0
  158. package/src/ArtifactStoreMetrics.ts +83 -0
  159. package/src/ArtifactSweep.ts +346 -0
  160. package/src/CombinedArtifacts.ts +369 -0
  161. package/src/FileLease.ts +397 -0
  162. package/src/FileSystemArtifactStore.ts +459 -0
  163. package/src/MemoryArtifactStore.ts +83 -0
  164. package/src/NoopArtifactStore.ts +30 -0
  165. package/src/RemoteArtifacts.ts +814 -0
  166. package/src/index.ts +71 -0
  167. package/src/internal/ArtifactLocks.ts +110 -0
  168. package/src/internal/ArtifactPath.ts +72 -0
  169. package/src/measureBytes.ts +28 -0
  170. package/src/snapshotBytes.ts +34 -0
  171. package/src/validateDigest.ts +31 -0
@@ -0,0 +1,185 @@
1
+ /**
2
+ * The sweep half of artifact garbage collection: enumerate this host's blobs
3
+ * and delete one, fenced by its age.
4
+ *
5
+ * This surface is deliberately NOT part of `ArtifactStore.Service`. The store
6
+ * contract is shared by memory, filesystem, and network tiers, and a remote
7
+ * tier can neither enumerate its address space nor accept a delete — Bazel
8
+ * draws the same line: its disk-cache collector
9
+ * (class `DiskCacheGarbageCollector` in
10
+ * `com.google.devtools.build.lib.remote.disk`) walks the local directory, while
11
+ * the remote tier owns its own retention. Only the
12
+ * host-local filesystem store implements this.
13
+ *
14
+ * The *policy* — which digests are live, how old a dead blob must be before it
15
+ * goes — belongs to the engine composition, which is the only place the
16
+ * durable roots (attempt rows, cache entries) are visible. This module ships
17
+ * mechanics alone; `@smthrs/engine-store` owns the mark policy and grace
18
+ * period.
19
+ *
20
+ * @since 1.0.0-rc.0
21
+ */
22
+ import * as Context from "effect/Context";
23
+ import * as Effect from "effect/Effect";
24
+ import * as FileSystem from "effect/FileSystem";
25
+ import * as Layer from "effect/Layer";
26
+ import * as ArtifactStore from "./ArtifactStore.ts";
27
+ /**
28
+ * One enumerated blob: its content address, when it was last written or
29
+ * freshened, and its size.
30
+ *
31
+ * `modifiedAtMs` is the age evidence a sweep fences on — the same signal git
32
+ * (`git prune --expire`) and Bazel's disk-cache collector read, because it is
33
+ * the one timestamp a filesystem maintains without any bookkeeping of ours.
34
+ *
35
+ * @category models
36
+ * @since 1.0.0-rc.0
37
+ * @slop
38
+ */
39
+ export interface BlobStat {
40
+ readonly digest: string;
41
+ readonly modifiedAtMs: number;
42
+ readonly sizeBytes: number;
43
+ }
44
+ /**
45
+ * Fencing predicate for a sweep deletion.
46
+ *
47
+ * @category models
48
+ * @since 1.0.0-rc.0
49
+ * @slop
50
+ */
51
+ export interface RemoveOptions {
52
+ /**
53
+ * Deletes the blob only while its mtime is still at or before this bound.
54
+ * A blob freshened after the caller computed its live set — a concurrent
55
+ * `put` re-referencing the same bytes — fails the fence and survives, the
56
+ * same shape as `CacheStore.evict`'s `ifRecordedBy`: the guard rides in the
57
+ * delete, never in a prior read alone.
58
+ */
59
+ readonly ifUnmodifiedSinceMs?: number | undefined;
60
+ }
61
+ /**
62
+ * Host-local blob enumeration and fenced deletion.
63
+ *
64
+ * @category models
65
+ * @since 1.0.0-rc.0
66
+ * @slop
67
+ */
68
+ export interface Service {
69
+ /**
70
+ * Every content-addressed blob this host's store currently holds. In-flight
71
+ * `.tmp-*` scratch files, foreign files, and blobs whose age cannot be
72
+ * measured are excluded — what the sweep cannot judge it must not touch.
73
+ */
74
+ readonly inventory: Effect.Effect<Array<BlobStat>, ArtifactStore.ArtifactStoreError>;
75
+ /**
76
+ * Deletes the blob at `digest`, returning whether bytes were removed. A
77
+ * missing blob reports `false` rather than failing, so a crashed and
78
+ * re-run sweep converges instead of erroring on its own progress.
79
+ *
80
+ * `false` covers three outcomes a caller cannot tell apart, all of which mean
81
+ * "nothing was reclaimed, and retrying later is safe": the blob was already
82
+ * gone, it failed the `ifUnmodifiedSinceMs` fence, or a live backup lease
83
+ * fenced the deletion (see `ArtifactBackupLease`). The last one is not
84
+ * progress — the blob is still there — so a collector that counts reclaimed
85
+ * bytes must not count it, and the next pass after the backup finishes
86
+ * removes it.
87
+ */
88
+ readonly remove: (digest: string, options?: RemoveOptions) => Effect.Effect<boolean, ArtifactStore.ArtifactStoreError>;
89
+ }
90
+ declare const ArtifactSweep_base: Context.ServiceClass<ArtifactSweep, "@smthrs/artifacts/ArtifactSweep", Service>;
91
+ /**
92
+ * Service tag for host-local artifact sweeping.
93
+ *
94
+ * The identity string equals this module's package path, per the house rule
95
+ * that a new identity is the defining module path.
96
+ *
97
+ * @category services
98
+ * @since 1.0.0-rc.0
99
+ * @slop
100
+ */
101
+ export declare class ArtifactSweep extends ArtifactSweep_base {
102
+ }
103
+ /**
104
+ * How the sweep reaches the objects directory.
105
+ *
106
+ * Deliberately not `ArtifactStore.FileSystemOptions`: the sweep never writes a
107
+ * blob, so `durability` would be an accepted argument it ignores. Both fields
108
+ * must match the store built over the same directory — see `coordination`.
109
+ *
110
+ * @category models
111
+ * @since 1.0.0-rc.0
112
+ */
113
+ export interface SweepOptions {
114
+ /**
115
+ * The objects directory to enumerate, the one the paired
116
+ * `ArtifactStore.makeFileSystem` publishes into. Defaults to
117
+ * `ArtifactStore.defaultDirectory`.
118
+ */
119
+ readonly directory?: string | undefined;
120
+ /**
121
+ * `required` takes the same per-digest lock file a publishing writer takes,
122
+ * and consults the backup lease, before deleting. It fences nothing unless
123
+ * the paired store was built with `required` too: a store on `process` never
124
+ * takes the lock this sweep waits on, so the fence would read as armed while
125
+ * protecting nothing. `process` is the explicit weaker browser/test mode.
126
+ */
127
+ readonly coordination?: "required" | "process" | undefined;
128
+ }
129
+ /**
130
+ * Builds the filesystem-backed sweep surface over the same objects directory
131
+ * an `ArtifactStore.makeFileSystem` publishes into.
132
+ *
133
+ * Enumeration is conservative by construction. Only paths in the store's
134
+ * canonical fanout shape — `xx/<digest>` with `xx` equal to the digest's
135
+ * two-hex prefix — are blobs; anything else in the directory (a temp file, a
136
+ * lock file, a foreign file, a fanout directory itself) is skipped, never
137
+ * deleted. A blob that vanishes between listing and stat was removed by someone
138
+ * else and is likewise skipped.
139
+ *
140
+ * Pair it with the store over the SAME `directory` and the SAME `coordination`.
141
+ * Nothing checks the pairing, and a mismatch is silent: a sweep on `required`
142
+ * beside a store on `process` deletes blobs no writer is fenced against.
143
+ *
144
+ * Under `required`, one deletion costs two lock acquisitions — the per-digest
145
+ * lock, then the workspace-global backup-lease gate — which is roughly ten
146
+ * filesystem operations and two forked heartbeat fibers per blob. The gate is
147
+ * one file for the whole workspace, so concurrent deletions serialize through
148
+ * it. That is the price of never deleting a blob a running backup already
149
+ * recorded; size a collection window with it in mind.
150
+ *
151
+ * @category constructors
152
+ * @since 1.0.0-rc.0
153
+ * @slop
154
+ */
155
+ export declare const makeFileSystem: (fs: FileSystem.FileSystem, options?: SweepOptions) => Service;
156
+ /**
157
+ * Provides the filesystem-backed sweep surface.
158
+ *
159
+ * Give it the same `directory` and `coordination` as the `ArtifactStore` layer
160
+ * it sweeps behind; see {@link makeFileSystem}.
161
+ *
162
+ * @category layers
163
+ * @since 1.0.0-rc.0
164
+ * @slop
165
+ */
166
+ export declare const layerFileSystem: (options?: SweepOptions) => Layer.Layer<ArtifactSweep, never, FileSystem.FileSystem>;
167
+ /**
168
+ * Builds a sweep surface whose every operation fails as unavailable, with
169
+ * per-method overrides.
170
+ *
171
+ * @category constructors
172
+ * @since 1.0.0-rc.0
173
+ * @slop
174
+ */
175
+ export declare const makeNoop: (overrides?: Partial<Service>) => Service;
176
+ /**
177
+ * Provides a no-op sweep surface.
178
+ *
179
+ * @category layers
180
+ * @since 1.0.0-rc.0
181
+ * @slop
182
+ */
183
+ export declare const layerNoop: (overrides?: Partial<Service>) => Layer.Layer<ArtifactSweep>;
184
+ export {};
185
+ //# sourceMappingURL=ArtifactSweep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArtifactSweep.d.ts","sourceRoot":"","sources":["../../src/ArtifactSweep.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAIrC,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAInD;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC3B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;OAMG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAClD;AAED;;;;;;GAMG;AACH,MAAM,WAAW,OAAO;IACtB;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAA;IACpF;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,MAAM,EAAE,CACf,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,aAAa,KACpB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAA;CAC9D;;AAED;;;;;;;;;GASG;AACH,qBAAa,aAAc,SAAQ,kBAA4E;CAAG;AAelH;;;;;;;;;GASG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACvC;;;;;;OAMG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,SAAS,CAAA;CAC3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,cAAc,GACzB,IAAI,UAAU,CAAC,UAAU,EACzB,UAAS,YAAiB,KACzB,OA2HF,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAC1B,UAAS,YAAiB,KACzB,KAAK,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,EAAE,UAAU,CAAC,UAAU,CAC2C,CAAA;AAErG;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GAAI,YAAW,OAAO,CAAC,OAAO,CAAM,KAAG,OAI1D,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,YAAW,OAAO,CAAC,OAAO,CAAM,KAAG,KAAK,CAAC,KAAK,CAAC,aAAa,CACnC,CAAA"}
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var ArtifactSweep_exports = {};
30
+ __export(ArtifactSweep_exports, {
31
+ ArtifactSweep: () => ArtifactSweep,
32
+ layerFileSystem: () => layerFileSystem,
33
+ layerNoop: () => layerNoop,
34
+ makeFileSystem: () => makeFileSystem,
35
+ makeNoop: () => makeNoop
36
+ });
37
+ module.exports = __toCommonJS(ArtifactSweep_exports);
38
+ var Context = __toESM(require("effect/Context"), 1);
39
+ var Effect = __toESM(require("effect/Effect"), 1);
40
+ var FileSystem = __toESM(require("effect/FileSystem"), 1);
41
+ var Layer = __toESM(require("effect/Layer"), 1);
42
+ var Option = __toESM(require("effect/Option"), 1);
43
+ var PlatformError = __toESM(require("effect/PlatformError"), 1);
44
+ var ArtifactBackupLease = __toESM(require("./ArtifactBackupLease.js"), 1);
45
+ var ArtifactStore = __toESM(require("./ArtifactStore.js"), 1);
46
+ var ArtifactLocks = __toESM(require("./internal/ArtifactLocks.js"), 1);
47
+ var ArtifactPath = __toESM(require("./internal/ArtifactPath.js"), 1);
48
+ class ArtifactSweep extends Context.Service()("@smthrs/artifacts/ArtifactSweep") {
49
+ }
50
+ const error = (message, cause) => new ArtifactStore.ArtifactStoreError({
51
+ code: "unavailable",
52
+ message,
53
+ ...cause === void 0 ? {} : { cause }
54
+ });
55
+ const hostFailure = (cause) => error(`the host filesystem refused a sweep operation: ${String(cause)}`, cause);
56
+ const isNotFound = (cause) => cause instanceof PlatformError.PlatformError && cause.reason._tag === "NotFound";
57
+ const makeFileSystem = (fs, options = {}) => {
58
+ const directory = (options.directory ?? ArtifactStore.defaultDirectory).replace(/([^/])\/+$/, "$1");
59
+ const coordination = options.coordination ?? "required";
60
+ const blobPath = (digest) => `${directory}/${digest.slice(0, 2)}/${digest}`;
61
+ const inventory = Effect.gen(function* () {
62
+ const checkRoot = yield* ArtifactPath.guard(fs, directory).pipe(Effect.mapError(hostFailure));
63
+ const parents = yield* fs.readDirectory(directory).pipe(
64
+ Effect.catch((cause) => isNotFound(cause) ? Effect.succeed([]) : Effect.fail(hostFailure(cause)))
65
+ );
66
+ const entries = [];
67
+ for (const parent of parents) {
68
+ if (!/^[0-9a-f]{2}$/.test(parent)) continue;
69
+ yield* checkRoot.pipe(Effect.mapError(hostFailure));
70
+ const safe = yield* ArtifactPath.guard(fs, `${directory}/${parent}`).pipe(Effect.option);
71
+ if (Option.isNone(safe)) continue;
72
+ const children = yield* fs.readDirectory(`${directory}/${parent}`).pipe(
73
+ Effect.orElseSucceed(() => [])
74
+ );
75
+ for (const child of children) entries.push(`${parent}/${child}`);
76
+ }
77
+ const candidates = entries.filter((entry) => {
78
+ if (entry.includes(".tmp-")) return false;
79
+ const separator = entry.indexOf("/");
80
+ const fan = entry.slice(0, separator);
81
+ const digest = entry.slice(separator + 1);
82
+ return /^[0-9a-f]{64}$/.test(digest) && fan === digest.slice(0, 2);
83
+ });
84
+ const blobs = yield* Effect.forEach(candidates, (entry) => Effect.gen(function* () {
85
+ const separator = entry.indexOf("/");
86
+ const fan = entry.slice(0, separator);
87
+ const digest = entry.slice(separator + 1);
88
+ const info = yield* Effect.gen(function* () {
89
+ yield* checkRoot;
90
+ yield* ArtifactPath.guard(fs, `${directory}/${fan}`);
91
+ yield* ArtifactPath.guard(fs, `${directory}/${entry}`, "File");
92
+ return yield* fs.stat(`${directory}/${entry}`);
93
+ }).pipe(Effect.option);
94
+ if (Option.isNone(info) || info.value.type !== "File") return void 0;
95
+ const mtime = Option.getOrUndefined(info.value.mtime);
96
+ if (mtime === void 0) return void 0;
97
+ return {
98
+ digest,
99
+ modifiedAtMs: mtime.getTime(),
100
+ sizeBytes: Number(info.value.size)
101
+ };
102
+ }), { concurrency: 16 });
103
+ return blobs.filter((blob) => blob !== void 0);
104
+ });
105
+ const remove = Effect.fn("ArtifactSweep.remove")(
106
+ (digest, removeOptions) => Effect.gen(function* () {
107
+ const validated = yield* ArtifactStore.validateDigest(digest);
108
+ const bound = removeOptions?.ifUnmodifiedSinceMs;
109
+ if (bound !== void 0 && (typeof bound !== "number" || Number.isNaN(bound))) {
110
+ return yield* Effect.fail(
111
+ new ArtifactStore.ArtifactStoreError({
112
+ code: "invalid_configuration",
113
+ message: "invalid sweep option: ifUnmodifiedSinceMs"
114
+ })
115
+ );
116
+ }
117
+ yield* Effect.annotateCurrentSpan({ digest: validated });
118
+ const checkRoot = yield* ArtifactPath.guard(fs, directory).pipe(Effect.mapError(hostFailure));
119
+ const checkParent = yield* ArtifactPath.guard(fs, `${directory}/${validated.slice(0, 2)}`).pipe(
120
+ Effect.mapError(hostFailure)
121
+ );
122
+ return yield* ArtifactLocks.withDigest(
123
+ fs,
124
+ directory,
125
+ validated,
126
+ coordination === "process" ? removeBlob() : ArtifactBackupLease.unlessActive(fs, directory, removeBlob(), hostFailure).pipe(
127
+ Effect.map(Option.getOrElse(() => false))
128
+ ),
129
+ hostFailure,
130
+ coordination
131
+ );
132
+ function removeBlob() {
133
+ return Effect.gen(function* () {
134
+ const path = blobPath(validated);
135
+ yield* checkRoot.pipe(Effect.mapError(hostFailure));
136
+ yield* checkParent.pipe(Effect.mapError(hostFailure));
137
+ const checkBlob = yield* ArtifactPath.guard(fs, path, "File").pipe(Effect.mapError(hostFailure));
138
+ if (bound !== void 0) {
139
+ const info = yield* fs.stat(path).pipe(Effect.option);
140
+ if (Option.isNone(info)) return false;
141
+ const mtime = Option.getOrUndefined(info.value.mtime);
142
+ if (mtime === void 0 || mtime.getTime() > bound) return false;
143
+ }
144
+ yield* checkRoot.pipe(Effect.mapError(hostFailure));
145
+ yield* checkParent.pipe(Effect.mapError(hostFailure));
146
+ yield* checkBlob.pipe(Effect.mapError(hostFailure));
147
+ return yield* fs.remove(path).pipe(
148
+ Effect.as(true),
149
+ // The blob may have been removed between the fence and here; only a
150
+ // refusal over bytes that still exist is a host failure.
151
+ Effect.catch(
152
+ (cause) => fs.exists(path).pipe(
153
+ Effect.mapError((probeCause) => hostFailure({ remove: cause, existenceProbe: probeCause })),
154
+ Effect.flatMap((present) => present ? Effect.fail(hostFailure(cause)) : Effect.succeed(false))
155
+ )
156
+ )
157
+ );
158
+ });
159
+ }
160
+ })
161
+ );
162
+ return { inventory, remove };
163
+ };
164
+ const layerFileSystem = (options = {}) => Layer.effect(ArtifactSweep)(Effect.map(FileSystem.FileSystem, (fs) => makeFileSystem(fs, options)));
165
+ const makeNoop = (overrides = {}) => ({
166
+ inventory: Effect.fail(error("inventory is unavailable")),
167
+ remove: Effect.fn("ArtifactSweep.remove")(() => Effect.fail(error("remove is unavailable"))),
168
+ ...overrides
169
+ });
170
+ const layerNoop = (overrides = {}) => Layer.succeed(ArtifactSweep)(makeNoop(overrides));
171
+ //# sourceMappingURL=ArtifactSweep.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/ArtifactSweep.ts"],
4
+ "sourcesContent": ["/**\n * The sweep half of artifact garbage collection: enumerate this host's blobs\n * and delete one, fenced by its age.\n *\n * This surface is deliberately NOT part of `ArtifactStore.Service`. The store\n * contract is shared by memory, filesystem, and network tiers, and a remote\n * tier can neither enumerate its address space nor accept a delete \u2014 Bazel\n * draws the same line: its disk-cache collector\n * (class `DiskCacheGarbageCollector` in\n * `com.google.devtools.build.lib.remote.disk`) walks the local directory, while\n * the remote tier owns its own retention. Only the\n * host-local filesystem store implements this.\n *\n * The *policy* \u2014 which digests are live, how old a dead blob must be before it\n * goes \u2014 belongs to the engine composition, which is the only place the\n * durable roots (attempt rows, cache entries) are visible. This module ships\n * mechanics alone; `@smthrs/engine-store` owns the mark policy and grace\n * period.\n *\n * @since 1.0.0-rc.0\n */\n\nimport * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport * as FileSystem from \"effect/FileSystem\"\nimport * as Layer from \"effect/Layer\"\nimport * as Option from \"effect/Option\"\nimport * as PlatformError from \"effect/PlatformError\"\nimport * as ArtifactBackupLease from \"./ArtifactBackupLease.ts\"\nimport * as ArtifactStore from \"./ArtifactStore.ts\"\nimport * as ArtifactLocks from \"./internal/ArtifactLocks.ts\"\nimport * as ArtifactPath from \"./internal/ArtifactPath.ts\"\n\n/**\n * One enumerated blob: its content address, when it was last written or\n * freshened, and its size.\n *\n * `modifiedAtMs` is the age evidence a sweep fences on \u2014 the same signal git\n * (`git prune --expire`) and Bazel's disk-cache collector read, because it is\n * the one timestamp a filesystem maintains without any bookkeeping of ours.\n *\n * @category models\n * @since 1.0.0-rc.0\n * @slop\n */\nexport interface BlobStat {\n readonly digest: string\n readonly modifiedAtMs: number\n readonly sizeBytes: number\n}\n\n/**\n * Fencing predicate for a sweep deletion.\n *\n * @category models\n * @since 1.0.0-rc.0\n * @slop\n */\nexport interface RemoveOptions {\n /**\n * Deletes the blob only while its mtime is still at or before this bound.\n * A blob freshened after the caller computed its live set \u2014 a concurrent\n * `put` re-referencing the same bytes \u2014 fails the fence and survives, the\n * same shape as `CacheStore.evict`'s `ifRecordedBy`: the guard rides in the\n * delete, never in a prior read alone.\n */\n readonly ifUnmodifiedSinceMs?: number | undefined\n}\n\n/**\n * Host-local blob enumeration and fenced deletion.\n *\n * @category models\n * @since 1.0.0-rc.0\n * @slop\n */\nexport interface Service {\n /**\n * Every content-addressed blob this host's store currently holds. In-flight\n * `.tmp-*` scratch files, foreign files, and blobs whose age cannot be\n * measured are excluded \u2014 what the sweep cannot judge it must not touch.\n */\n readonly inventory: Effect.Effect<Array<BlobStat>, ArtifactStore.ArtifactStoreError>\n /**\n * Deletes the blob at `digest`, returning whether bytes were removed. A\n * missing blob reports `false` rather than failing, so a crashed and\n * re-run sweep converges instead of erroring on its own progress.\n *\n * `false` covers three outcomes a caller cannot tell apart, all of which mean\n * \"nothing was reclaimed, and retrying later is safe\": the blob was already\n * gone, it failed the `ifUnmodifiedSinceMs` fence, or a live backup lease\n * fenced the deletion (see `ArtifactBackupLease`). The last one is not\n * progress \u2014 the blob is still there \u2014 so a collector that counts reclaimed\n * bytes must not count it, and the next pass after the backup finishes\n * removes it.\n */\n readonly remove: (\n digest: string,\n options?: RemoveOptions\n ) => Effect.Effect<boolean, ArtifactStore.ArtifactStoreError>\n}\n\n/**\n * Service tag for host-local artifact sweeping.\n *\n * The identity string equals this module's package path, per the house rule\n * that a new identity is the defining module path.\n *\n * @category services\n * @since 1.0.0-rc.0\n * @slop\n */\nexport class ArtifactSweep extends Context.Service<ArtifactSweep, Service>()(\"@smthrs/artifacts/ArtifactSweep\") {}\n\nconst error = (message: string, cause?: unknown): ArtifactStore.ArtifactStoreError =>\n new ArtifactStore.ArtifactStoreError({\n code: \"unavailable\",\n message,\n ...(cause === undefined ? {} : { cause })\n })\n\nconst hostFailure = (cause: unknown): ArtifactStore.ArtifactStoreError =>\n error(`the host filesystem refused a sweep operation: ${String(cause)}`, cause)\n\nconst isNotFound = (cause: unknown): boolean =>\n cause instanceof PlatformError.PlatformError && cause.reason._tag === \"NotFound\"\n\n/**\n * How the sweep reaches the objects directory.\n *\n * Deliberately not `ArtifactStore.FileSystemOptions`: the sweep never writes a\n * blob, so `durability` would be an accepted argument it ignores. Both fields\n * must match the store built over the same directory \u2014 see `coordination`.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport interface SweepOptions {\n /**\n * The objects directory to enumerate, the one the paired\n * `ArtifactStore.makeFileSystem` publishes into. Defaults to\n * `ArtifactStore.defaultDirectory`.\n */\n readonly directory?: string | undefined\n /**\n * `required` takes the same per-digest lock file a publishing writer takes,\n * and consults the backup lease, before deleting. It fences nothing unless\n * the paired store was built with `required` too: a store on `process` never\n * takes the lock this sweep waits on, so the fence would read as armed while\n * protecting nothing. `process` is the explicit weaker browser/test mode.\n */\n readonly coordination?: \"required\" | \"process\" | undefined\n}\n\n/**\n * Builds the filesystem-backed sweep surface over the same objects directory\n * an `ArtifactStore.makeFileSystem` publishes into.\n *\n * Enumeration is conservative by construction. Only paths in the store's\n * canonical fanout shape \u2014 `xx/<digest>` with `xx` equal to the digest's\n * two-hex prefix \u2014 are blobs; anything else in the directory (a temp file, a\n * lock file, a foreign file, a fanout directory itself) is skipped, never\n * deleted. A blob that vanishes between listing and stat was removed by someone\n * else and is likewise skipped.\n *\n * Pair it with the store over the SAME `directory` and the SAME `coordination`.\n * Nothing checks the pairing, and a mismatch is silent: a sweep on `required`\n * beside a store on `process` deletes blobs no writer is fenced against.\n *\n * Under `required`, one deletion costs two lock acquisitions \u2014 the per-digest\n * lock, then the workspace-global backup-lease gate \u2014 which is roughly ten\n * filesystem operations and two forked heartbeat fibers per blob. The gate is\n * one file for the whole workspace, so concurrent deletions serialize through\n * it. That is the price of never deleting a blob a running backup already\n * recorded; size a collection window with it in mind.\n *\n * @category constructors\n * @since 1.0.0-rc.0\n * @slop\n */\nexport const makeFileSystem = (\n fs: FileSystem.FileSystem,\n options: SweepOptions = {}\n): Service => {\n const directory = (options.directory ?? ArtifactStore.defaultDirectory).replace(/([^/])\\/+$/, \"$1\")\n const coordination = options.coordination ?? \"required\"\n const blobPath = (digest: string): string => `${directory}/${digest.slice(0, 2)}/${digest}`\n\n const inventory: Service[\"inventory\"] = Effect.gen(function*() {\n // A store that never published anything has no directory; that is an\n // empty inventory, not a failure.\n const checkRoot = yield* ArtifactPath.guard(fs, directory).pipe(Effect.mapError(hostFailure))\n const parents = yield* fs.readDirectory(directory).pipe(\n Effect.catch((cause) => isNotFound(cause) ? Effect.succeed([] as Array<string>) : Effect.fail(hostFailure(cause)))\n )\n const entries: Array<string> = []\n for (const parent of parents) {\n if (!/^[0-9a-f]{2}$/.test(parent)) continue\n yield* checkRoot.pipe(Effect.mapError(hostFailure))\n const safe = yield* ArtifactPath.guard(fs, `${directory}/${parent}`).pipe(Effect.option)\n if (Option.isNone(safe)) continue\n const children = yield* fs.readDirectory(`${directory}/${parent}`).pipe(\n Effect.orElseSucceed(() => [] as Array<string>)\n )\n for (const child of children) entries.push(`${parent}/${child}`)\n }\n const candidates = entries.filter((entry) => {\n if (entry.includes(\".tmp-\")) return false\n const separator = entry.indexOf(\"/\")\n const fan = entry.slice(0, separator)\n const digest = entry.slice(separator + 1)\n return /^[0-9a-f]{64}$/.test(digest) && fan === digest.slice(0, 2)\n })\n const blobs = yield* Effect.forEach(candidates, (entry) =>\n Effect.gen(function*() {\n const separator = entry.indexOf(\"/\")\n const fan = entry.slice(0, separator)\n const digest = entry.slice(separator + 1)\n // The stat is per-candidate and tolerant: a blob another process\n // removed between the listing and here simply is not in the\n // inventory, and one whose mtime the host cannot report offers no\n // age evidence, so the sweep must never judge it.\n const info = yield* Effect.gen(function*() {\n yield* checkRoot\n yield* ArtifactPath.guard(fs, `${directory}/${fan}`)\n yield* ArtifactPath.guard(fs, `${directory}/${entry}`, \"File\")\n return yield* fs.stat(`${directory}/${entry}`)\n }).pipe(Effect.option)\n if (Option.isNone(info) || info.value.type !== \"File\") return undefined\n const mtime = Option.getOrUndefined(info.value.mtime)\n if (mtime === undefined) return undefined\n return {\n digest,\n modifiedAtMs: mtime.getTime(),\n sizeBytes: Number(info.value.size)\n }\n }), { concurrency: 16 })\n return blobs.filter((blob) => blob !== undefined)\n })\n\n const remove: Service[\"remove\"] = Effect.fn(\"ArtifactSweep.remove\")((digest, removeOptions) =>\n Effect.gen(function*() {\n const validated = yield* ArtifactStore.validateDigest(digest)\n const bound = removeOptions?.ifUnmodifiedSinceMs\n // NaN fails every comparison, so the fence below would read it as \"not\n // modified since\" and delete a blob a concurrent put just freshened.\n if (bound !== undefined && (typeof bound !== \"number\" || Number.isNaN(bound))) {\n return yield* Effect.fail(\n new ArtifactStore.ArtifactStoreError({\n code: \"invalid_configuration\",\n message: \"invalid sweep option: ifUnmodifiedSinceMs\"\n })\n )\n }\n yield* Effect.annotateCurrentSpan({ digest: validated })\n const checkRoot = yield* ArtifactPath.guard(fs, directory).pipe(Effect.mapError(hostFailure))\n const checkParent = yield* ArtifactPath.guard(fs, `${directory}/${validated.slice(0, 2)}`).pipe(\n Effect.mapError(hostFailure)\n )\n return yield* ArtifactLocks.withDigest(\n fs,\n directory,\n validated,\n coordination === \"process\"\n ? removeBlob()\n : ArtifactBackupLease.unlessActive(fs, directory, removeBlob(), hostFailure).pipe(\n Effect.map(Option.getOrElse(() => false))\n ),\n hostFailure,\n coordination\n )\n\n function removeBlob(): Effect.Effect<boolean, ArtifactStore.ArtifactStoreError> {\n return Effect.gen(function*() {\n const path = blobPath(validated)\n yield* checkRoot.pipe(Effect.mapError(hostFailure))\n yield* checkParent.pipe(Effect.mapError(hostFailure))\n const checkBlob = yield* ArtifactPath.guard(fs, path, \"File\").pipe(Effect.mapError(hostFailure))\n if (bound !== undefined) {\n const info = yield* fs.stat(path).pipe(Effect.option)\n // Already gone is a completed deletion, and an unmeasurable mtime is\n // no proof of age: both refuse rather than delete.\n if (Option.isNone(info)) return false\n const mtime = Option.getOrUndefined(info.value.mtime)\n if (mtime === undefined || mtime.getTime() > bound) return false\n }\n yield* checkRoot.pipe(Effect.mapError(hostFailure))\n yield* checkParent.pipe(Effect.mapError(hostFailure))\n yield* checkBlob.pipe(Effect.mapError(hostFailure))\n return yield* fs.remove(path).pipe(\n Effect.as(true),\n // The blob may have been removed between the fence and here; only a\n // refusal over bytes that still exist is a host failure.\n Effect.catch((cause) =>\n fs.exists(path).pipe(\n Effect.mapError((probeCause) => hostFailure({ remove: cause, existenceProbe: probeCause })),\n Effect.flatMap((present) => present ? Effect.fail(hostFailure(cause)) : Effect.succeed(false))\n )\n )\n )\n })\n }\n })\n )\n\n return { inventory, remove }\n}\n\n/**\n * Provides the filesystem-backed sweep surface.\n *\n * Give it the same `directory` and `coordination` as the `ArtifactStore` layer\n * it sweeps behind; see {@link makeFileSystem}.\n *\n * @category layers\n * @since 1.0.0-rc.0\n * @slop\n */\nexport const layerFileSystem = (\n options: SweepOptions = {}\n): Layer.Layer<ArtifactSweep, never, FileSystem.FileSystem> =>\n Layer.effect(ArtifactSweep)(Effect.map(FileSystem.FileSystem, (fs) => makeFileSystem(fs, options)))\n\n/**\n * Builds a sweep surface whose every operation fails as unavailable, with\n * per-method overrides.\n *\n * @category constructors\n * @since 1.0.0-rc.0\n * @slop\n */\nexport const makeNoop = (overrides: Partial<Service> = {}): Service => ({\n inventory: Effect.fail(error(\"inventory is unavailable\")),\n remove: Effect.fn(\"ArtifactSweep.remove\")(() => Effect.fail(error(\"remove is unavailable\"))),\n ...overrides\n})\n\n/**\n * Provides a no-op sweep surface.\n *\n * @category layers\n * @since 1.0.0-rc.0\n * @slop\n */\nexport const layerNoop = (overrides: Partial<Service> = {}): Layer.Layer<ArtifactSweep> =>\n Layer.succeed(ArtifactSweep)(makeNoop(overrides))\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,cAAyB;AACzB,aAAwB;AACxB,iBAA4B;AAC5B,YAAuB;AACvB,aAAwB;AACxB,oBAA+B;AAC/B,0BAAqC;AACrC,oBAA+B;AAC/B,oBAA+B;AAC/B,mBAA8B;AAiFvB,MAAM,sBAAsB,QAAQ,QAAgC,EAAE,iCAAiC,EAA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,aAAa,EAAE,SAAS,SAAS,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Two artifact tiers composed into one: local first, remote second, with
3
+ * write-back into the local tier.
4
+ *
5
+ * This is the shape of Bazel's `CombinedCache`
6
+ * (`com.google.devtools.build.lib.remote.CombinedCache`): a read consults the
7
+ * disk cache, falls back to the remote cache only on a miss, and *uploads what it
8
+ * found back into the disk cache* so the next read is local
9
+ * (`downloadActionResultFromRemote`, lines 230-303). A write goes to both.
10
+ *
11
+ * Deviation from Bazel: policy is declared once by the remote tier rather than
12
+ * threaded through every call. `downloadPolicy` controls prefetch and local
13
+ * materialization; composing only the local tier opts out of shared storage.
14
+ *
15
+ * @since 1.0.0-rc.0
16
+ */
17
+ import * as Duration from "effect/Duration";
18
+ import * as Effect from "effect/Effect";
19
+ import * as Layer from "effect/Layer";
20
+ import * as ArtifactStore from "./ArtifactStore.ts";
21
+ import * as RemoteArtifacts from "./RemoteArtifacts.ts";
22
+ /**
23
+ * The two tiers to compose.
24
+ *
25
+ * @category models
26
+ * @since 1.0.0-rc.0
27
+ * @slop
28
+ */
29
+ export interface Options {
30
+ /** The fast, machine-local tier. Every read tries this one first. */
31
+ readonly local: ArtifactStore.Service;
32
+ /** The shared tier. Consulted only on a local miss; written through on put. */
33
+ readonly remote: ArtifactStore.Service;
34
+ /**
35
+ * How long a `put` waits for its opportunistic upload to the shared tier
36
+ * before abandoning it. The local digest is already in hand when the upload
37
+ * starts, so the deadline bounds only how long a stalled remote can delay
38
+ * the answer — an abandoned upload is dropped exactly like a refused one.
39
+ * Defaults to 60 seconds, Bazel's `--remote_timeout` default
40
+ * (its `RemoteOptions`).
41
+ */
42
+ readonly uploadTimeout?: Duration.Input | undefined;
43
+ /**
44
+ * How long a `get` waits for opportunistic local write-back before
45
+ * interrupting it and returning the verified remote bytes. Defaults to
46
+ * 60 seconds, matching the default upload deadline.
47
+ */
48
+ readonly writeBackTimeout?: Duration.Input | undefined;
49
+ /**
50
+ * How eagerly a read materializes a blob into the local tier. Defaults to
51
+ * the policy the remote tier declares (`RemoteArtifacts.Options.downloadPolicy`),
52
+ * and to `all` for a remote tier that declares none.
53
+ *
54
+ * `all` and `toplevel` both write a fetched blob back into the local tier, so
55
+ * the second read is local; they differ only in whether
56
+ * `@smthrs/engine-store`'s `ArtifactSync.hydrate` prefetches. `minimal`
57
+ * serves the bytes without writing them back, so a host that must not
58
+ * accumulate other machines' artifacts never does. `minimal` still repairs a
59
+ * *corrupt* local address, because a rewrite of an address the local tier
60
+ * already claims is repair rather than growth.
61
+ *
62
+ * No policy makes the write-back load-bearing: a local tier that refuses it
63
+ * costs the next read a network round trip, never this read's answer.
64
+ */
65
+ readonly downloadPolicy?: RemoteArtifacts.DownloadPolicy | undefined;
66
+ }
67
+ /**
68
+ * Composes a local and a remote artifact store.
69
+ *
70
+ * @category constructors
71
+ * @since 1.0.0-rc.0
72
+ * @slop
73
+ */
74
+ export declare const make: (options: Options) => Effect.Effect<RemoteArtifacts.Service, ArtifactStore.ArtifactStoreError>;
75
+ /**
76
+ * The two tiers as effects, plus the options {@link make} takes.
77
+ *
78
+ * Both tiers are supplied as *effects* rather than layers because they inhabit
79
+ * the same tag: composing two `Layer<ArtifactStore>` would just shadow one
80
+ * with the other. Pair `ArtifactStore.makeFileSystem` (wrapped in
81
+ * `Effect.sync`) or `Effect.map(FileSystem.FileSystem, ...)` with
82
+ * `RemoteArtifacts.make`.
83
+ *
84
+ * @category models
85
+ * @since 1.0.0-rc.0
86
+ * @slop
87
+ */
88
+ export interface LayerOptions<EL, RL, ER, RR> {
89
+ readonly local: Effect.Effect<ArtifactStore.Service, EL, RL>;
90
+ readonly remote: Effect.Effect<ArtifactStore.Service, ER, RR>;
91
+ readonly uploadTimeout?: Duration.Input | undefined;
92
+ readonly writeBackTimeout?: Duration.Input | undefined;
93
+ readonly downloadPolicy?: RemoteArtifacts.DownloadPolicy | undefined;
94
+ }
95
+ /**
96
+ * Provides a local-first artifact store, backed by local and remote effects, as
97
+ * the `ArtifactStore` tag.
98
+ *
99
+ * @category layers
100
+ * @since 1.0.0-rc.0
101
+ */
102
+ export declare const layer: <EL, RL, ER, RR>(options: LayerOptions<EL, RL, ER, RR>) => Layer.Layer<ArtifactStore.ArtifactStore, EL | ER | ArtifactStore.ArtifactStoreError, RL | RR>;
103
+ //# sourceMappingURL=CombinedArtifacts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CombinedArtifacts.d.ts","sourceRoot":"","sources":["../../src/CombinedArtifacts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAIrC,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AAEvD;;;;;;GAMG;AACH,MAAM,WAAW,OAAO;IACtB,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAA;IACrC,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAA;IACtC;;;;;;;OAOG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAA;IACnD;;;;OAIG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAA;IACtD;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,eAAe,CAAC,cAAc,GAAG,SAAS,CAAA;CACrE;AAyBD;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,GACf,SAAS,OAAO,KACf,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,aAAa,CAAC,kBAAkB,CAsNtE,CAAA;AAEJ;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