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

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 +173 -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 +175 -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 +163 -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 +113 -0
  29. package/dist/cjs/FileLease.d.ts.map +1 -0
  30. package/dist/cjs/FileLease.js +201 -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 +117 -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 +202 -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 +113 -0
  98. package/dist/esm/FileLease.d.ts.map +1 -0
  99. package/dist/esm/FileLease.js +239 -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 +554 -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 +200 -0
  142. package/docs/api.md +474 -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 +98 -0
  152. package/docs/quickstart.md +182 -0
  153. package/docs/troubleshooting.md +232 -0
  154. package/package.json +179 -3
  155. package/src/ArtifactBackupLease.ts +213 -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 +336 -0
  160. package/src/CombinedArtifacts.ts +369 -0
  161. package/src/FileLease.ts +380 -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 +809 -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,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/RemoteArtifacts.ts"],
4
+ "sourcesContent": ["/**\n * The shared artifact tier: an {@link ArtifactStore.Service} spoken over HTTP.\n *\n * The wire protocol mirrors Bazel's dumb-HTTP remote cache, class\n * `HttpCacheClient` in `com.google.devtools.build.lib.remote.http`, which\n * documents it as: \"CAS (Content Addressable Storage) blobs are stored under\n * the path `/cas/base16-key`\", uploaded with `PUT`, downloaded with `GET`. We add\n * `HEAD /cas/{digest}` for a single existence probe and\n * `POST /cas/findMissing` for the batched one, because Bazel's HTTP client has\n * no `findMissingDigests` at all \u2014 it answers \"everything is missing\" and\n * re-uploads \u2014 and a batched probe is the whole reason\n * `MissingDigestsFinder` exists in the gRPC client.\n *\n * Transport is Effect's own `HttpClient` tag. There is no lower transport in\n * this repository, and there does not need to be one: the kernel already\n * decorates that tag with `net:get`/`net:post` capability checks, so a remote\n * artifact fetch is permission-checked like every other egress.\n *\n * ## Chunked uploads\n *\n * With `chunkBytes` set, a blob past that size travels as a sequence of\n * `PUT /cas/{digest}` requests carrying `Content-Range: bytes {a}-{b}/{total}`,\n * preceded by a `HEAD /cas/{digest}` existence probe and a\n * `Content-Range: bytes *\\/{total}` probe with an empty body. This is the\n * resumable-upload shape HTTP already has: the range probe asks what prefix\n * the tier holds and `308` means \"keep going\", with a `Range: bytes=0-{last}`\n * header on the probe or on a chunk answer moving the offset.\n *\n * Only a `308` continues the sequence, and the completing chunk's `2xx` is\n * confirmed with `HEAD` before `put` reports the digest as published. A `2xx`\n * anywhere else, to the empty probe or to a chunk the tier is still owed bytes\n * after, reads as a tier that ignored `Content-Range` and stored the body it\n * was handed, which is what plain WebDAV `PUT` does. That tier, the one that\n * answers `400`, `411`, or `416`, and the one whose `HEAD` will not confirm\n * the stored length all get the same treatment: one whole-blob `PUT`, which\n * overwrites the partial body the sequence left behind. So the blob always\n * lands whole, and the cost of turning the dial on against a server that\n * never learned about it is round trips, never a digest published over bytes\n * the server does not hold.\n *\n * This repository's own hosted and self-hosted cache services are such\n * servers: neither implements the resumable sequence, and both refuse a\n * ranged `PUT` with `400`, RFC 9110 section 14.5's answer from a resource\n * that does not support partial `PUT`. Against them `chunkBytes` costs the\n * probe round trip and the blob travels whole, and both cap one request body\n * at 16 MiB, so a blob past that cap is refused with `413` in either mode.\n *\n * The endpoint and its credentials arrive as **layer construction options**.\n * They are capabilities, never step inputs: they are not hashed into a step\n * key, journaled, or returned in a recorded result. Invalid endpoint errors are\n * sanitized before they cross the boundary.\n *\n * @since 1.0.0-rc.0\n */\n\nimport * as Duration from \"effect/Duration\"\nimport * as Effect from \"effect/Effect\"\nimport * as Layer from \"effect/Layer\"\nimport * as Option from \"effect/Option\"\nimport * as Schema from \"effect/Schema\"\nimport * as Stream from \"effect/Stream\"\nimport * as FetchHttpClient from \"effect/unstable/http/FetchHttpClient\"\nimport * as Headers from \"effect/unstable/http/Headers\"\nimport * as HttpClient from \"effect/unstable/http/HttpClient\"\nimport * as HttpClientRequest from \"effect/unstable/http/HttpClientRequest\"\nimport type * as HttpClientResponse from \"effect/unstable/http/HttpClientResponse\"\nimport * as ArtifactStore from \"./ArtifactStore.ts\"\n\n/**\n * How eagerly a composition materializes shared blobs into its local store.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport const DownloadPolicy = Schema.Literals([\"all\", \"toplevel\", \"minimal\"] as const)\n\n/**\n * How eagerly a composition materializes remote blobs.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport type DownloadPolicy = typeof DownloadPolicy.Type\n\n/**\n * Every download policy, in materialization order.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport const downloadPolicies: ReadonlyArray<DownloadPolicy> = Object.freeze([\"all\", \"toplevel\", \"minimal\"])\n\n/**\n * A remote artifact tier, which is an ordinary store that also states how\n * eagerly a composition reading through it should materialize blobs locally.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport interface Service extends ArtifactStore.Service {\n readonly downloadPolicy: DownloadPolicy\n}\n\n/**\n * Reads the download policy a store declares, or `undefined` for a store that\n * declares none \u2014 every local store, and any foreign implementation.\n *\n * @category getters\n * @since 1.0.0-rc.0\n */\nexport const downloadPolicyOf = (store: ArtifactStore.Service): DownloadPolicy | undefined => {\n const declared = (store as { readonly downloadPolicy?: unknown }).downloadPolicy\n return Schema.is(DownloadPolicy)(declared) ? declared : undefined\n}\n\n/**\n * How to reach the shared artifact tier.\n *\n * @category models\n * @since 1.0.0-rc.0\n * @slop\n */\nexport interface Options {\n /**\n * The cache root, e.g. `https://cache.example.com`. `/cas/{digest}` and\n * `/cas/findMissing` are resolved beneath it. A trailing slash is ignored.\n *\n * Four shapes are refused at construction as `invalid_configuration`, before\n * any request leaves and therefore before `headers` can reach a wire: a value\n * that is not a string, one no `URL` parser accepts, a scheme other than\n * `https:` (plain `http:` is accepted only for the literal loopback hosts\n * `localhost`, `127.0.0.1`, and `[::1]`), and an endpoint carrying\n * userinfo, a query, or a fragment. The\n * last rule keeps a credential out of a place nothing here would redact: an\n * endpoint is interpolated into every request path and into span attributes.\n *\n * The refusal message names only the violated rule and never echoes the\n * endpoint, so a rejected `https://user:secret@host` cannot leak its\n * credential into a log line or a durable error.\n */\n readonly endpoint: string\n /**\n * Headers sent with every request \u2014 an `Authorization` bearer token, a\n * tenant header, whatever the deployment's gateway wants. This is the\n * credential seam, and it is deliberately construction-time: a credential\n * that arrived as a step input would be hashed into a step key and persisted\n * everywhere the journal goes.\n *\n * The protocol wins every collision. These headers are applied to a request\n * first. Configured `content-type`, `content-length`, and `content-range`\n * are removed, then computed only where the protocol needs them. Whole-blob\n * uploads, including fallbacks, never carry `content-range`.\n * All configured header names are redacted in HTTP spans, in addition to\n * the host's existing redaction rules.\n *\n * A name that is not an HTTP token, or a value longer than 16 KiB or\n * carrying a control character (CR and LF included), is refused at\n * construction as `invalid_configuration`.\n */\n readonly headers?: Record<string, string> | undefined\n /**\n * The deadline on a single download, from the request leaving to the last\n * body byte arriving. A shared tier that stops answering must fail the read\n * rather than park it forever. `CombinedArtifacts.get` propagates a remote\n * `ArtifactStoreError`, including a download timeout. Only opportunistic\n * uploads from `CombinedArtifacts.put` ignore remote failures;\n * `ArtifactSync.hydrate` separately turns a failure into replay rejection.\n * Defaults to 60 seconds, Bazel's `--remote_timeout`\n * default for the same REST protocol (its `RemoteOptions`: \"For the REST\n * cache, this is both the connect and the read timeout\").\n */\n readonly downloadTimeout?: Duration.Input | undefined\n /**\n * Deadline for an upload, including every resume probe and chunk. Defaults\n * to 60 seconds.\n */\n readonly uploadTimeout?: Duration.Input | undefined\n /**\n * Deadline for an existence probe or one `findMissing` batch, including its\n * response body. Defaults to 60 seconds.\n */\n readonly requestTimeout?: Duration.Input | undefined\n /**\n * The largest download this client will buffer, in bytes. The body is read\n * incrementally and abandoned the moment it exceeds the bound \u2014 and refused\n * outright when `Content-Length` already declares the excess \u2014 so a\n * mis-serving or hostile cache cannot make this process buffer and hash an\n * arbitrarily large body before the digest check refuses it. Defaults to\n * 256 MiB.\n */\n readonly maxDownloadBytes?: number | undefined\n /**\n * Largest `findMissing` response body accepted. Defaults to the protocol's\n * 256 KiB request/response bound and may only lower that bound.\n */\n readonly maxFindMissingResponseBytes?: number | undefined\n /**\n * Above this many bytes an upload travels as a sequence of `Content-Range`\n * `PUT`s instead of one whole-blob body, and a transfer that died partway\n * resumes from the prefix the tier kept rather than starting over. See\n * {@link module:RemoteArtifacts | the chunked upload protocol} below.\n *\n * Absent by default: every upload is one whole-blob `PUT`, which is what\n * Bazel's dumb-HTTP client does and what every deployment already serving\n * this protocol expects. Set it when a proxy caps request bodies, or when\n * artifacts are large enough that losing a transfer is expensive.\n *\n * The repository's own hosted and self-hosted cache services answer the\n * ranged probe with `400`, so against them this dial degrades to one\n * whole-blob `PUT`, and their 16 MiB body cap refuses a larger blob with\n * `413` in either mode.\n */\n readonly chunkBytes?: number | undefined\n /**\n * How eagerly a composition reading through this tier materializes blobs\n * into its local store. This is Bazel's `--remote_download_{all,toplevel,\n * minimal}` dial (`RemoteOutputChecker`), and it lives here because the\n * shared tier is the thing being conserved.\n *\n * - `all` (the default) prefetches every referenced blob when a replay is\n * admitted, so the replay reads local bytes.\n * - `toplevel` prefetches nothing and materializes a blob into the local\n * store on the first read that actually needs it.\n * - `minimal` prefetches nothing and materializes nothing: a read is served\n * straight from the shared tier and the local store never grows.\n *\n * `CombinedArtifacts.get` honors the last two; `@smthrs/engine-store`'s\n * `ArtifactSync.hydrate` honors the first.\n */\n readonly downloadPolicy?: DownloadPolicy | undefined\n}\n\n/**\n * The default download deadline. 60 seconds is Bazel's `--remote_timeout`\n * default, governing the same dumb-HTTP cache protocol.\n */\nconst defaultDownloadTimeout = Duration.seconds(60)\nconst defaultUploadTimeout = Duration.seconds(60)\nconst defaultRequestTimeout = Duration.seconds(60)\n\n/**\n * The default bound on a downloaded blob: 256 MiB. Artifacts are spilled step\n * values, not media libraries; a body past this size is far more likely a\n * mis-serving cache than a legitimate blob, and the dial is per-store for a\n * deployment that knows better.\n */\nconst defaultMaxDownloadBytes = 256 * 1024 * 1024\nconst maxFindMissingBatchDigests = 1_000\nconst maxFindMissingBodyBytes = 256 * 1024\nconst encoder = new TextEncoder()\nconst decoder = new TextDecoder(\"utf-8\", { fatal: true })\n\n/**\n * The credential-free part of a transport failure: the HTTP client's reason\n * tag and the first operating-system error code (`ECONNREFUSED`, `ENOTFOUND`,\n * `CERT_HAS_EXPIRED`) in its cause chain. Never the request, the URL, the\n * headers, or free-form text, any of which may carry a credential.\n */\nconst transportReason = (cause: unknown): string | undefined => {\n const reason = (cause as { readonly reason?: { readonly _tag?: unknown } } | null)?.reason\n const tag = typeof reason?._tag === \"string\" ? reason._tag : undefined\n let code: string | undefined\n let current: unknown = reason ?? cause\n for (let depth = 0; depth < 8 && typeof current === \"object\" && current !== null; depth++) {\n const candidate = (current as { readonly code?: unknown }).code\n if (typeof candidate === \"string\" && /^[A-Z][A-Z0-9_]{1,63}$/.test(candidate)) {\n code = candidate\n break\n }\n current = (current as { readonly cause?: unknown }).cause\n }\n const parts = [tag, code].filter((part): part is string => part !== undefined)\n return parts.length === 0 ? undefined : parts.join(\" \")\n}\n\nconst transportFailure = (operation: string, cause?: unknown): ArtifactStore.ArtifactStoreError => {\n const reason = transportReason(cause)\n return new ArtifactStore.ArtifactStoreError({\n code: \"transport_failed\",\n message: `the remote artifact tier refused ${operation}${reason === undefined ? \"\" : ` (${reason})`}`\n })\n}\n\nconst unexpectedStatus = (operation: string, status: number): ArtifactStore.ArtifactStoreError =>\n new ArtifactStore.ArtifactStoreError({\n code: \"transport_failed\",\n message: `the remote artifact tier answered ${operation} with HTTP ${status}`\n })\n\nconst invalidOption = (name: string): ArtifactStore.ArtifactStoreError =>\n new ArtifactStore.ArtifactStoreError({\n code: \"invalid_configuration\",\n message: `invalid remote artifact option: ${name}`\n })\n\n/** The batched-probe response body. */\nconst FindMissingResponse = Schema.Struct({ missing: Schema.Array(Schema.String) })\n\n/** An RFC 9110 field-name token. */\nconst headerName = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/\n\n/** Whether a header value carries a C0 control character or DEL, CR and LF included. */\nconst hasControlText = (value: string): boolean => {\n for (let index = 0; index < value.length; index++) {\n const unit = value.charCodeAt(index)\n if (unit <= 0x1f || unit === 0x7f) return true\n }\n return false\n}\n\nconst configurationFailure = (message: string): ArtifactStore.ArtifactStoreError =>\n new ArtifactStore.ArtifactStoreError({ code: \"invalid_configuration\", message })\n\n/**\n * A 2xx is success, a 404 is a miss, and everything else is a transport\n * failure. Bazel's HTTP client takes the same three-way split; it is the only\n * classification a dumb-HTTP cache can support, because there is no richer\n * error envelope on the wire.\n */\nconst isOk = (response: HttpClientResponse.HttpClientResponse): boolean =>\n response.status >= 200 && response.status < 300\n\n/**\n * Builds a remote artifact store over Effect's `HttpClient`.\n *\n * @category constructors\n * @since 1.0.0-rc.0\n * @slop\n */\nexport const make = (\n options: Options\n): Effect.Effect<Service, ArtifactStore.ArtifactStoreError, HttpClient.HttpClient> =>\n Effect.gen(function*() {\n const configured = yield* Effect.try({\n try: () => {\n const headers = options.headers === undefined\n ? undefined\n : Object.freeze(Object.fromEntries(\n Object.entries(options.headers).map(([name, value]) => {\n // Refused here, once, rather than on every request as an opaque\n // transport failure: a CRLF in a value or a space in a name can\n // never become a valid header.\n if (typeof value !== \"string\" || value.length > 16 * 1024 || hasControlText(value)) {\n throw new TypeError(\"header value\")\n }\n if (!headerName.test(name)) throw new TypeError(\"header name\")\n return [name, value]\n })\n ))\n return {\n endpoint: options.endpoint,\n headers,\n downloadTimeout: options.downloadTimeout,\n uploadTimeout: options.uploadTimeout,\n requestTimeout: options.requestTimeout,\n maxDownloadBytes: options.maxDownloadBytes,\n maxFindMissingResponseBytes: options.maxFindMissingResponseBytes,\n chunkBytes: options.chunkBytes,\n downloadPolicy: options.downloadPolicy\n }\n },\n catch: () => invalidOption(\"options\")\n })\n if (typeof configured.endpoint !== \"string\") return yield* Effect.fail(invalidOption(\"endpoint\"))\n const endpoint = yield* Effect.try({\n try: () => new URL(configured.endpoint),\n catch: () => configurationFailure(\"invalid remote artifact endpoint\")\n })\n // A self-hosted cache on this machine is reachable over plain HTTP, and\n // loopback traffic never leaves the host. Only literal loopback names are\n // exempt: a `*.localhost` name reaches loopback only on a resolver that\n // follows RFC 6761, and one that forwards it to DNS would carry the\n // credential headers over plaintext to whatever host answers.\n const loopback = endpoint.hostname === \"localhost\" || endpoint.hostname === \"127.0.0.1\" ||\n endpoint.hostname === \"[::1]\"\n if (endpoint.protocol !== \"https:\" && !(endpoint.protocol === \"http:\" && loopback)) {\n return yield* Effect.fail(configurationFailure(\"remote artifact endpoint must use HTTPS\"))\n }\n if (endpoint.username !== \"\" || endpoint.password !== \"\" || endpoint.search !== \"\" || endpoint.hash !== \"\") {\n return yield* Effect.fail(\n configurationFailure(\"remote artifact endpoint must not contain credentials, a query, or a fragment\")\n )\n }\n endpoint.pathname = endpoint.pathname.replace(/\\/+$/, \"\")\n const base = endpoint.toString().replace(/\\/+$/, \"\")\n const headers = configured.headers\n const client = yield* HttpClient.HttpClient\n const credentialNames = Object.keys(headers ?? {}).map((name) => name.toLowerCase())\n /**\n * Protocol-owned headers are computed from each request's body and range,\n * never inherited from credentials, including on a whole-blob fallback.\n */\n const authorized = (request: HttpClientRequest.HttpClientRequest): HttpClientRequest.HttpClientRequest =>\n (headers === undefined ? request : HttpClientRequest.setHeaders(request, headers)).pipe(\n HttpClientRequest.removeHeader(\"content-type\"),\n HttpClientRequest.removeHeader(\"content-length\"),\n HttpClientRequest.removeHeader(\"content-range\")\n )\n // The address is a URL path segment, so it is refused before it is\n // interpolated and percent-encoded when it is: an address carrying a\n // separator or a `..` would otherwise point this client at a different\n // resource on the configured endpoint. `ArtifactStore.validateDigest` is\n // the same guard the filesystem tier applies to the same untrusted input \u2014\n // a digest read back out of a durable row.\n const casUrl = (digest: ArtifactStore.Digest) => `${base}/cas/${digest}`\n const scopedClient = HttpClient.withScope(client)\n /**\n * Keep body processing inside the exchange; abort unused responses on every exit.\n *\n * Redirects are never followed. A fetch-based client follows them by\n * default and strips only `Authorization` on a cross-origin hop, so a\n * tier answering `3xx` would otherwise receive the credential headers at\n * another origin or over plain HTTP. Manual mode hands the `3xx` back,\n * where it is an unexpected status (or, for `308`, the resumable-upload\n * answer this protocol already speaks).\n */\n const send = <A, E, R>(\n operation: string,\n request: HttpClientRequest.HttpClientRequest,\n use: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, E, R>\n ): Effect.Effect<A, E | ArtifactStore.ArtifactStoreError, R> =>\n Effect.gen(function*() {\n const redactedNames = yield* Headers.CurrentRedactedNames\n const requestInit = yield* Effect.serviceOption(FetchHttpClient.RequestInit)\n return yield* scopedClient.execute(request).pipe(\n Effect.provideService(FetchHttpClient.RequestInit, {\n ...Option.getOrUndefined(requestInit),\n redirect: \"manual\"\n }),\n Effect.mapError((cause) => transportFailure(operation, cause)),\n Effect.flatMap(use),\n Effect.provideService(Headers.CurrentRedactedNames, [...redactedNames, ...credentialNames]),\n Effect.scoped\n )\n })\n const parseDeadline = (name: string, input: Duration.Input | undefined, fallback: Duration.Duration) =>\n Effect.gen(function*() {\n const parsed = Duration.fromInput(input ?? fallback)\n if (\n Option.isNone(parsed) ||\n !Number.isFinite(Duration.toMillis(parsed.value)) ||\n Duration.toMillis(parsed.value) <= 0\n ) {\n return yield* Effect.fail(invalidOption(name))\n }\n return parsed.value\n })\n const downloadDeadline = yield* parseDeadline(\n \"downloadTimeout\",\n configured.downloadTimeout,\n defaultDownloadTimeout\n )\n const uploadDeadline = yield* parseDeadline(\"uploadTimeout\", configured.uploadTimeout, defaultUploadTimeout)\n const requestDeadline = yield* parseDeadline(\"requestTimeout\", configured.requestTimeout, defaultRequestTimeout)\n const maxDownloadBytes = configured.maxDownloadBytes ?? defaultMaxDownloadBytes\n if (!Number.isSafeInteger(maxDownloadBytes) || maxDownloadBytes <= 0) {\n return yield* Effect.fail(invalidOption(\"maxDownloadBytes\"))\n }\n const maxFindMissingResponseBytes = configured.maxFindMissingResponseBytes ?? maxFindMissingBodyBytes\n if (\n !Number.isSafeInteger(maxFindMissingResponseBytes) ||\n maxFindMissingResponseBytes <= 0 ||\n maxFindMissingResponseBytes > maxFindMissingBodyBytes\n ) {\n return yield* Effect.fail(invalidOption(\"maxFindMissingResponseBytes\"))\n }\n const chunkBytes = configured.chunkBytes\n if (chunkBytes !== undefined && (!Number.isSafeInteger(chunkBytes) || chunkBytes <= 0)) {\n return yield* Effect.fail(invalidOption(\"chunkBytes\"))\n }\n const downloadPolicy = configured.downloadPolicy ?? \"all\"\n if (!Schema.is(DownloadPolicy)(downloadPolicy)) {\n return yield* Effect.fail(invalidOption(\"downloadPolicy\"))\n }\n const bodyTooLarge = (operation: string, received: number, bound: number): ArtifactStore.ArtifactStoreError =>\n new ArtifactStore.ArtifactStoreError({\n code: \"transport_failed\",\n message: `the remote artifact tier answered ${operation} with ${received} bytes, past the ${bound}-byte bound`\n })\n const timedOut = (operation: string): ArtifactStore.ArtifactStoreError =>\n new ArtifactStore.ArtifactStoreError({\n code: \"transport_failed\",\n message: `the remote artifact tier did not finish ${operation} within its configured deadline`\n })\n const within = <A, E, R>(\n operation: string,\n deadline: Duration.Duration,\n effect: Effect.Effect<A, E, R>\n ): Effect.Effect<A, E | ArtifactStore.ArtifactStoreError, R> =>\n effect.pipe(\n Effect.timeout(deadline),\n Effect.catchTag(\"TimeoutError\", () => Effect.fail(timedOut(operation)))\n )\n /**\n * Reads a download body incrementally, refusing it the moment it exceeds\n * the size bound; a `Content-Length` that already declares the excess is\n * refused before a single body byte is read. Streaming instead of\n * buffering the whole body means the guard fires at most one chunk past\n * the bound, never after an arbitrarily large response is in memory.\n */\n const readBounded = (\n response: HttpClientResponse.HttpClientResponse,\n operation: string,\n bound: number\n ) =>\n Effect.gen(function*() {\n const declared = response.headers[\"content-length\"]\n if (declared !== undefined) {\n const declaredBytes = Number(declared)\n if (!/^\\d+$/.test(declared) || !Number.isSafeInteger(declaredBytes)) {\n return yield* Effect.fail(transportFailure(`${operation} body`))\n }\n if (declaredBytes > bound) return yield* Effect.fail(bodyTooLarge(operation, declaredBytes, bound))\n }\n const chunks: Array<Uint8Array> = []\n let received = 0\n yield* Stream.runForEach(response.stream, (chunk: Uint8Array) =>\n Effect.suspend(() => {\n received += chunk.byteLength\n if (received > bound) return Effect.fail(bodyTooLarge(operation, received, bound))\n chunks.push(new Uint8Array(chunk))\n return Effect.void\n })).pipe(\n Effect.catchTag(\"HttpClientError\", (cause) =>\n // An absent body is zero bytes, not a transport refusal: the\n // digest check in `get` is the arbiter of whether empty content\n // is the requested artifact.\n cause.reason._tag === \"EmptyBodyError\"\n ? Effect.void\n : Effect.fail(transportFailure(`${operation} body`)))\n )\n const bytes = new Uint8Array(received)\n let offset = 0\n for (const chunk of chunks) {\n bytes.set(chunk, offset)\n offset += chunk.byteLength\n }\n return bytes\n })\n /** The network half of `get`: request, status split, bounded body read. */\n const download = (digest: ArtifactStore.Digest) =>\n send(\"a download\", authorized(HttpClientRequest.get(casUrl(digest))), (response) =>\n Effect.gen(function*() {\n if (response.status === 404) {\n return yield* Effect.fail(new ArtifactStore.ArtifactMissing({ code: \"artifact_missing\", digest }))\n }\n if (!isOk(response)) return yield* Effect.fail(unexpectedStatus(\"a download\", response.status))\n return yield* readBounded(response, \"a download\", maxDownloadBytes)\n }))\n\n /** One whole-blob `PUT`: the protocol every dumb-HTTP CAS already speaks. */\n const uploadWhole = (digest: ArtifactStore.Digest, bytes: Uint8Array) =>\n send(\n \"an upload\",\n authorized(HttpClientRequest.put(casUrl(digest))).pipe(\n HttpClientRequest.bodyUint8Array(bytes, \"application/octet-stream\")\n ),\n (response) => isOk(response) ? Effect.void : Effect.fail(unexpectedStatus(\"an upload\", response.status))\n )\n\n /**\n * The byte after the prefix a `Range: bytes=0-{last}` header reports, or\n * `undefined` when the answer names no prefix. Only a prefix starting at\n * zero is usable: a tier holding a middle span has nothing this client can\n * continue from, so it is treated as holding nothing.\n */\n const resumeOffset = (response: HttpClientResponse.HttpClientResponse): number | undefined => {\n const header = response.headers[\"range\"]\n if (header === undefined) return undefined\n const match = /^bytes=0-(\\d+)$/.exec(header.trim())\n if (match === null) return undefined\n const last = Number(match[1])\n // A prefix past the safe integer range does not survive `Number`: the\n // decimal digits are rounded, so the offset it names is a number this\n // client made up. It proves nothing about what the tier holds, which is\n // the same as naming no prefix at all.\n if (!Number.isSafeInteger(last)) return undefined\n return last + 1\n }\n\n /**\n * A tier that refuses ranged bodies, in the three ways HTTP has to say\n * so. `411` and `416` refuse the body's framing; `400` is RFC 9110\n * section 14.5's answer from a resource that \"does not support partial\n * PUT requests\", and it is what both of this repository's cache services\n * send. Falling back on it can mask no genuine `400`: the whole-blob\n * `PUT` that follows presents the same URL, digest, and credential, so a\n * real refusal comes straight back on that request.\n */\n const rejectsRanges = (status: number): boolean => status === 400 || status === 411 || status === 416\n\n /**\n * Whether the tier holds exactly `total` bytes under `digest`, read from\n * the `Content-Length` of a `HEAD` answer.\n *\n * This is the only claim about a chunked transfer this client will make on\n * its own behalf. A tier that answers `HEAD` without a length is not\n * refused \u2014 it simply proves nothing, so the caller sends the blob whole.\n */\n const holdsWhole = (digest: ArtifactStore.Digest, total: number) =>\n send(\"an existence probe\", authorized(HttpClientRequest.head(casUrl(digest))), (response) =>\n Effect.sync(() => {\n if (!isOk(response)) return false\n const declared = response.headers[\"content-length\"]\n return declared !== undefined && Number(declared) === total\n }))\n\n /**\n * Sends `bytes` as `Content-Range` chunks, resuming from whatever prefix\n * the tier reports. Answers `false` when the tier has not proved it stored\n * the whole blob, which is the caller's signal to send it whole.\n *\n * A `2xx` answer is never by itself proof of that. A tier that ignores\n * `Content-Range`, such as plain WebDAV `PUT`, which Bazel documents as a\n * supported dumb-HTTP cache, answers every request in this sequence `201`\n * while storing only the last body it was handed, which for the probe is\n * zero bytes. So only a `308` continues the sequence, and the completing\n * chunk's `2xx` is confirmed with `HEAD` before the caller is told the\n * digest is published. Everything else falls back, and the whole-blob\n * `PUT` overwrites whatever partial body the sequence left behind.\n */\n const uploadChunked = (digest: ArtifactStore.Digest, bytes: Uint8Array, chunk: number) =>\n Effect.gen(function*() {\n const total = bytes.byteLength\n const ranged = (range: string, body: Uint8Array) =>\n send(\n \"an upload\",\n authorized(HttpClientRequest.put(casUrl(digest))).pipe(\n HttpClientRequest.bodyUint8Array(body, \"application/octet-stream\"),\n HttpClientRequest.setHeader(\"content-range\", range)\n ),\n // Only status and headers are used after the response is released.\n Effect.succeed\n )\n // A blob the tier already holds whole costs one `HEAD` and no body.\n // Asking first is also what makes the probe's answer readable: a `2xx`\n // to it can no longer mean \"already there\", so the one reading left is\n // a tier that ignored the header and stored the empty body.\n if (yield* holdsWhole(digest, total)) return true\n // The probe carries no bytes: it exists to learn where to start, so\n // that an interrupted transfer costs one round trip rather than the\n // whole blob again.\n const probe = yield* ranged(`bytes */${total}`, new Uint8Array(0))\n if (isOk(probe) || rejectsRanges(probe.status)) return false\n if (probe.status !== 308 && probe.status !== 404) {\n return yield* Effect.fail(unexpectedStatus(\"an upload probe\", probe.status))\n }\n let offset = probe.status === 308 ? resumeOffset(probe) ?? 0 : 0\n while (offset < total) {\n const end = Math.min(offset + chunk, total)\n const answer = yield* ranged(`bytes ${offset}-${end - 1}/${total}`, bytes.subarray(offset, end))\n if (answer.status !== 308) {\n // The completing chunk may answer `2xx`; anything before it may\n // not, because a tier that is still owed bytes and reports success\n // is a tier that is not reading the header. Both are checked\n // against what the tier actually holds below.\n if (end === total && isOk(answer)) break\n if (isOk(answer) || rejectsRanges(answer.status)) return false\n return yield* Effect.fail(unexpectedStatus(\"an upload\", answer.status))\n }\n // A tier that reports a longer prefix than this chunk delivered has\n // more than we just sent, so the next chunk starts there. Never\n // backwards: an answer naming a shorter prefix would loop forever.\n offset = Math.max(end, resumeOffset(answer) ?? 0)\n }\n return yield* holdsWhole(digest, total)\n })\n\n const put: ArtifactStore.Service[\"put\"] = Effect.fn(\"RemoteArtifacts.put\")((bytes: Uint8Array) =>\n Effect.flatMap(ArtifactStore.snapshotBytes(bytes), (snapshot) =>\n Effect.gen(function*() {\n const digest = yield* ArtifactStore.measureBytes(snapshot)\n yield* Effect.annotateCurrentSpan({ digest })\n yield* within(\n \"an upload\",\n uploadDeadline,\n Effect.gen(function*() {\n if (chunkBytes === undefined || snapshot.byteLength <= chunkBytes) {\n yield* uploadWhole(digest, snapshot)\n return\n }\n const transferred = yield* uploadChunked(digest, snapshot, chunkBytes)\n if (!transferred) yield* uploadWhole(digest, snapshot)\n })\n )\n return digest\n }))\n )\n\n const get: ArtifactStore.Service[\"get\"] = Effect.fn(\"RemoteArtifacts.get\")((digest: string) =>\n Effect.gen(function*() {\n const validated = yield* ArtifactStore.validateDigest(digest)\n yield* Effect.annotateCurrentSpan({ digest: validated })\n // The deadline covers the whole exchange \u2014 request, headers, body \u2014\n // because a tier that stalls mid-body is exactly as unanswering as\n // one that never accepts the connection.\n const bytes = yield* within(\"a download\", downloadDeadline, download(validated))\n // The shared tier is the least trusted store there is: it is written\n // by machines this one has never met. Verifying the address here means\n // a mis-serving or compromised cache can waste a round trip but can\n // never substitute content.\n const measured = yield* ArtifactStore.measureBytes(bytes)\n if (measured !== validated) {\n return yield* Effect.fail(\n new ArtifactStore.ArtifactCorruption({\n code: \"artifact_corruption\",\n recordedDigest: validated,\n measuredDigest: measured\n })\n )\n }\n return bytes\n })\n )\n\n const has: ArtifactStore.Service[\"has\"] = Effect.fn(\"RemoteArtifacts.has\")((digest: string) =>\n Effect.gen(function*() {\n const validated = yield* ArtifactStore.validateDigest(digest)\n yield* Effect.annotateCurrentSpan({ digest: validated })\n const response = yield* within(\n \"an existence probe\",\n requestDeadline,\n send(\"an existence probe\", authorized(HttpClientRequest.head(casUrl(validated))), Effect.succeed)\n )\n if (response.status === 404) return false\n if (!isOk(response)) return yield* Effect.fail(unexpectedStatus(\"an existence probe\", response.status))\n return true\n })\n )\n\n const findMissing: ArtifactStore.Service[\"findMissing\"] = Effect.fn(\"RemoteArtifacts.findMissing\")(\n (digests: Iterable<string>) =>\n Effect.gen(function*() {\n const requested = [...new Set(digests)]\n if (requested.length === 0) return []\n // The batch travels in a JSON body rather than a path, but an\n // unusable address is still an unusable address, and the local tier\n // refuses the same batch wholesale rather than probing part of it.\n const validated: Array<ArtifactStore.Digest> = []\n for (const digest of requested) validated.push(yield* ArtifactStore.validateDigest(digest))\n yield* Effect.annotateCurrentSpan({ count: validated.length })\n const missing = new Set<string>()\n for (let offset = 0; offset < validated.length; offset += maxFindMissingBatchDigests) {\n const batch = validated.slice(offset, offset + maxFindMissingBatchDigests)\n const requestBody = encoder.encode(JSON.stringify({ digests: batch }))\n /* v8 ignore next 3 -- strict 64-byte digests plus the 1,000-entry batch cap make this\n * at most 67,013 bytes; keep the protocol assertion beside serialization in case either invariant changes. */\n if (requestBody.byteLength > maxFindMissingBodyBytes) {\n return yield* Effect.fail(configurationFailure(\"remote artifact findMissing request exceeds 256 KiB\"))\n }\n const decoded = yield* within(\n \"a batched existence probe\",\n requestDeadline,\n send(\n \"a batched existence probe\",\n authorized(HttpClientRequest.post(`${base}/cas/findMissing`)).pipe(\n HttpClientRequest.bodyUint8Array(requestBody, \"application/json\")\n ),\n (response) =>\n Effect.gen(function*() {\n if (!isOk(response)) {\n return yield* Effect.fail(unexpectedStatus(\"a batched existence probe\", response.status))\n }\n const bodyBytes = yield* readBounded(\n response,\n \"a batched existence probe\",\n maxFindMissingResponseBytes\n )\n const body = yield* Effect.try({\n try: () => JSON.parse(decoder.decode(bodyBytes)) as unknown,\n catch: () => transportFailure(\"a batched existence probe body\")\n })\n return yield* Schema.decodeUnknownEffect(FindMissingResponse)(body).pipe(\n Effect.mapError(() => transportFailure(\"a batched existence probe body\"))\n )\n })\n )\n )\n const asked = new Set<string>(batch)\n for (const digest of decoded.missing) if (asked.has(digest)) missing.add(digest)\n }\n // \"The returned set is guaranteed to be a subset of `digests`\"\n // (`MissingDigestsFinder`). Bazel gets that from the server; we\n // enforce it on this side too, because a server that answered with\n // an unrequested digest would otherwise make the caller upload bytes\n // it never asked about.\n return validated.filter((digest) => missing.has(digest))\n })\n )\n\n return { put, get, has, findMissing, downloadPolicy }\n })\n\n/**\n * Provides a remote artifact store as the `ArtifactStore` tag.\n *\n * Composing this *alone* makes every artifact read and write a network round\n * trip. The intended production shape is\n * {@link CombinedArtifacts.layer | CombinedArtifacts}, with this as its remote\n * tier.\n *\n * @category layers\n * @since 1.0.0-rc.0\n * @slop\n */\nexport const layer = (\n options: Options\n): Layer.Layer<ArtifactStore.ArtifactStore, ArtifactStore.ArtifactStoreError, HttpClient.HttpClient> =>\n Layer.effect(ArtifactStore.ArtifactStore)(make(options))\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuDA,eAA0B;AAC1B,aAAwB;AACxB,YAAuB;AACvB,aAAwB;AACxB,aAAwB;AACxB,aAAwB;AACxB,sBAAiC;AACjC,cAAyB;AACzB,iBAA4B;AAC5B,wBAAmC;AAEnC,oBAA+B;AAQxB,MAAM,iBAAiB,OAAO,SAAS,CAAC,OAAO,YAAY,SAAS,CAAU;AAgB9E,MAAM,mBAAkD,OAAO,OAAO,CAAC,O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EAAE,IAAI,EAAE;AAAA,gBAClE,OAAO,SAAS,MAAM,iBAAiB,gCAAgC,CAAC;AAAA,cAC1E;AAAA,YACF,CAAC;AAAA,UACL;AAAA,QACF;AACA,cAAM,QAAQ,IAAI,IAAY,KAAK;AACnC,mBAAW,UAAU,QAAQ,QAAS,KAAI,MAAM,IAAI,MAAM,EAAG,SAAQ,IAAI,MAAM;AAAA,MACjF;AAMA,aAAO,UAAU,OAAO,CAAC,WAAW,QAAQ,IAAI,MAAM,CAAC;AAAA,IACzD,CAAC;AAAA,EACL;AAEA,SAAO,EAAE,KAAK,KAAK,KAAK,aAAa,eAAe;AACtD,CAAC;AAcI,MAAM,QAAQ,CACnB,YAEA,MAAM,OAAO,cAAc,aAAa,EAAE,KAAK,OAAO,CAAC;",
6
+ "names": ["headers"]
7
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The content-addressed artifact store: bytes addressed by their own digest.
3
+ *
4
+ * `ArtifactStore` is the byte half of the cache. `@smthrs/step-cache` maps a
5
+ * step key to a recorded result, while large result bytes live here under their
6
+ * digest. The package depends on `effect` and `@smthrs/crypto`, owns no SQL,
7
+ * and bundles for the browser: host access is Effect's `FileSystem` and
8
+ * `HttpClient` tags, both of which the capability kernel decorates in place.
9
+ *
10
+ * ```ts
11
+ * import { ArtifactStore, CombinedArtifacts, RemoteArtifacts } from "@smthrs/artifacts"
12
+ * import * as Effect from "effect/Effect"
13
+ * import * as FileSystem from "effect/FileSystem"
14
+ * import * as Path from "effect/Path"
15
+ *
16
+ * const layer = CombinedArtifacts.layer({
17
+ * local: Effect.map(Effect.all([FileSystem.FileSystem, Path.Path]), ([fs, path]) =>
18
+ * ArtifactStore.makeFileSystem(fs, path)),
19
+ * remote: RemoteArtifacts.make({ endpoint: "https://cache.example.com" })
20
+ * })
21
+ * ```
22
+ *
23
+ * @since 1.0.0-rc.0
24
+ */
25
+ /**
26
+ * @category services
27
+ * @since 1.0.0-rc.0
28
+ * @slop
29
+ */
30
+ export * as ArtifactStore from "./ArtifactStore.ts";
31
+ /**
32
+ * @category metrics
33
+ * @since 1.0.0-rc.0
34
+ * @slop
35
+ */
36
+ export * as ArtifactStoreMetrics from "./ArtifactStoreMetrics.ts";
37
+ /**
38
+ * @category services
39
+ * @since 1.0.0-rc.0
40
+ */
41
+ export * as ArtifactBackupLease from "./ArtifactBackupLease.ts";
42
+ /**
43
+ * @category services
44
+ * @since 1.0.0-rc.0
45
+ * @slop
46
+ */
47
+ export * as ArtifactSweep from "./ArtifactSweep.ts";
48
+ /**
49
+ * @category services
50
+ * @since 1.0.0-rc.0
51
+ * @slop
52
+ */
53
+ export * as CombinedArtifacts from "./CombinedArtifacts.ts";
54
+ /**
55
+ * @category coordination
56
+ * @since 1.0.0-rc.1
57
+ */
58
+ export * as FileLease from "./FileLease.ts";
59
+ /**
60
+ * @category services
61
+ * @since 1.0.0-rc.0
62
+ * @slop
63
+ */
64
+ export * as RemoteArtifacts from "./RemoteArtifacts.ts";
65
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;;;;GAIG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;;;GAIG;AACH,OAAO,KAAK,oBAAoB,MAAM,2BAA2B,CAAA;AAEjE;;;GAGG;AACH,OAAO,KAAK,mBAAmB,MAAM,0BAA0B,CAAA;AAE/D;;;;GAIG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;;;GAIG;AACH,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAE3D;;;GAGG;AACH,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAE3C;;;;GAIG;AACH,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA"}
@@ -0,0 +1,47 @@
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 index_exports = {};
30
+ __export(index_exports, {
31
+ ArtifactBackupLease: () => ArtifactBackupLease,
32
+ ArtifactStore: () => ArtifactStore,
33
+ ArtifactStoreMetrics: () => ArtifactStoreMetrics,
34
+ ArtifactSweep: () => ArtifactSweep,
35
+ CombinedArtifacts: () => CombinedArtifacts,
36
+ FileLease: () => FileLease,
37
+ RemoteArtifacts: () => RemoteArtifacts
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+ var ArtifactStore = __toESM(require("./ArtifactStore.js"), 1);
41
+ var ArtifactStoreMetrics = __toESM(require("./ArtifactStoreMetrics.js"), 1);
42
+ var ArtifactBackupLease = __toESM(require("./ArtifactBackupLease.js"), 1);
43
+ var ArtifactSweep = __toESM(require("./ArtifactSweep.js"), 1);
44
+ var CombinedArtifacts = __toESM(require("./CombinedArtifacts.js"), 1);
45
+ var FileLease = __toESM(require("./FileLease.js"), 1);
46
+ var RemoteArtifacts = __toESM(require("./RemoteArtifacts.js"), 1);
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["/**\n * The content-addressed artifact store: bytes addressed by their own digest.\n *\n * `ArtifactStore` is the byte half of the cache. `@smthrs/step-cache` maps a\n * step key to a recorded result, while large result bytes live here under their\n * digest. The package depends on `effect` and `@smthrs/crypto`, owns no SQL,\n * and bundles for the browser: host access is Effect's `FileSystem` and\n * `HttpClient` tags, both of which the capability kernel decorates in place.\n *\n * ```ts\n * import { ArtifactStore, CombinedArtifacts, RemoteArtifacts } from \"@smthrs/artifacts\"\n * import * as Effect from \"effect/Effect\"\n * import * as FileSystem from \"effect/FileSystem\"\n * import * as Path from \"effect/Path\"\n *\n * const layer = CombinedArtifacts.layer({\n * local: Effect.map(Effect.all([FileSystem.FileSystem, Path.Path]), ([fs, path]) =>\n * ArtifactStore.makeFileSystem(fs, path)),\n * remote: RemoteArtifacts.make({ endpoint: \"https://cache.example.com\" })\n * })\n * ```\n *\n * @since 1.0.0-rc.0\n */\n\n/**\n * @category services\n * @since 1.0.0-rc.0\n * @slop\n */\nexport * as ArtifactStore from \"./ArtifactStore.ts\"\n\n/**\n * @category metrics\n * @since 1.0.0-rc.0\n * @slop\n */\nexport * as ArtifactStoreMetrics from \"./ArtifactStoreMetrics.ts\"\n\n/**\n * @category services\n * @since 1.0.0-rc.0\n */\nexport * as ArtifactBackupLease from \"./ArtifactBackupLease.ts\"\n\n/**\n * @category services\n * @since 1.0.0-rc.0\n * @slop\n */\nexport * as ArtifactSweep from \"./ArtifactSweep.ts\"\n\n/**\n * @category services\n * @since 1.0.0-rc.0\n * @slop\n */\nexport * as CombinedArtifacts from \"./CombinedArtifacts.ts\"\n\n/**\n * @category coordination\n * @since 1.0.0-rc.1\n */\nexport * as FileLease from \"./FileLease.ts\"\n\n/**\n * @category services\n * @since 1.0.0-rc.0\n * @slop\n */\nexport * as RemoteArtifacts from \"./RemoteArtifacts.ts\"\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BA,oBAA+B;AAO/B,2BAAsC;AAMtC,0BAAqC;AAOrC,oBAA+B;AAO/B,wBAAmC;AAMnC,gBAA2B;AAO3B,sBAAiC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Per-digest coordination for filesystem publication and removal.
3
+ *
4
+ * The semaphore is the cheap in-process path. A `FileLease` lock file is the
5
+ * actual workspace-wide fence: every process that can mutate the object
6
+ * directory observes it, and a crashed owner is recovered after its heartbeat
7
+ * expires.
8
+ *
9
+ * @since 1.0.0-rc.0
10
+ */
11
+ import * as Effect from "effect/Effect";
12
+ import type * as FileSystem from "effect/FileSystem";
13
+ /**
14
+ * The subdirectory of the objects directory that holds lock files and their
15
+ * stale-owner tombstones. Named here rather than spelled in each caller so the
16
+ * store's crash-orphan sweep reclaims exactly what this module creates.
17
+ *
18
+ * @category constants
19
+ * @since 1.0.0-rc.0
20
+ */
21
+ export declare const directoryName = ".locks";
22
+ /**
23
+ * Coordinates publication, freshening, and sweep deletion for one digest.
24
+ * `process` is the explicit weaker mode for hosts without atomic create.
25
+ *
26
+ * @category combinators
27
+ * @since 1.0.0-rc.0
28
+ */
29
+ export declare const withDigest: <A, E, R, E2>(fs: FileSystem.FileSystem, directory: string, digest: string, effect: Effect.Effect<A, E, R>, failure: (cause: unknown) => E2, coordination?: "required" | "process") => Effect.Effect<A, E | E2, R>;
30
+ //# sourceMappingURL=ArtifactLocks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArtifactLocks.d.ts","sourceRoot":"","sources":["../../../src/internal/ArtifactLocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAYpD;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,WAAW,CAAA;AAErC;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EACpC,IAAI,UAAU,CAAC,UAAU,EACzB,WAAW,MAAM,EACjB,QAAQ,MAAM,EACd,QAAQ,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC9B,SAAS,CAAC,KAAK,EAAE,OAAO,KAAK,EAAE,EAC/B,eAAc,UAAU,GAAG,SAAsB,KAChD,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CA4DzB,CAAA"}
@@ -0,0 +1,93 @@
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 ArtifactLocks_exports = {};
30
+ __export(ArtifactLocks_exports, {
31
+ directoryName: () => directoryName,
32
+ withDigest: () => withDigest
33
+ });
34
+ module.exports = __toCommonJS(ArtifactLocks_exports);
35
+ var Deferred = __toESM(require("effect/Deferred"), 1);
36
+ var Effect = __toESM(require("effect/Effect"), 1);
37
+ var Semaphore = __toESM(require("effect/Semaphore"), 1);
38
+ var FileLease = __toESM(require("../FileLease.js"), 1);
39
+ var ArtifactPath = __toESM(require("./ArtifactPath.js"), 1);
40
+ const locks = /* @__PURE__ */ new WeakMap();
41
+ const directoryName = ".locks";
42
+ const withDigest = (fs, directory, digest, effect, failure, coordination = "required") => (
43
+ // Every execution of the returned effect claims its own share of the entry,
44
+ // which is why the whole body is suspended rather than run when `withDigest`
45
+ // is called. A count taken at construction is wrong in both directions: an
46
+ // effect built and discarded pins an entry nothing will ever release, and one
47
+ // built once and run repeatedly — `ArtifactBackupLease` builds its gate once
48
+ // and runs it on every heartbeat — retires the entry underneath a live holder,
49
+ // so the next caller mints a second semaphore for the same digest and the two
50
+ // serialize against nothing.
51
+ Effect.suspend(() => {
52
+ let byKey = locks.get(fs);
53
+ if (byKey === void 0) {
54
+ byKey = /* @__PURE__ */ new Map();
55
+ locks.set(fs, byKey);
56
+ }
57
+ const key = JSON.stringify([directory, digest]);
58
+ let entry = byKey.get(key);
59
+ if (entry === void 0) {
60
+ entry = { semaphore: Semaphore.makeUnsafe(1), users: 0 };
61
+ byKey.set(key, entry);
62
+ }
63
+ entry.users += 1;
64
+ const held = entry;
65
+ const table = byKey;
66
+ const ready = Deferred.makeUnsafe();
67
+ const deadline = Deferred.await(ready).pipe(
68
+ Effect.timeout(FileLease.defaultAcquireWithin),
69
+ Effect.catchTag("TimeoutError", (cause) => Effect.fail(failure(cause))),
70
+ Effect.andThen(Effect.never)
71
+ );
72
+ const coordinated = coordination === "process" ? Deferred.succeed(ready, void 0).pipe(Effect.andThen(effect)) : Effect.gen(function* () {
73
+ const lockDirectory = `${directory}/${directoryName}`;
74
+ yield* ArtifactPath.guard(fs, lockDirectory).pipe(Effect.mapError(failure));
75
+ yield* fs.makeDirectory(lockDirectory, { recursive: true, mode: 448 }).pipe(Effect.mapError(failure));
76
+ const checkLockDirectory = yield* ArtifactPath.guard(fs, lockDirectory).pipe(Effect.mapError(failure));
77
+ return yield* FileLease.hold(fs, `${lockDirectory}/${digest}.lock`, effect, failure, {
78
+ label: "Artifact lock",
79
+ annotations: { digest },
80
+ onAcquired: Deferred.succeed(ready, void 0).pipe(Effect.asVoid),
81
+ guard: checkLockDirectory
82
+ });
83
+ });
84
+ return held.semaphore.withPermit(coordinated).pipe(
85
+ Effect.raceFirst(deadline),
86
+ Effect.ensuring(Effect.sync(() => {
87
+ held.users -= 1;
88
+ if (held.users === 0 && table.get(key) === held) table.delete(key);
89
+ }))
90
+ );
91
+ })
92
+ );
93
+ //# sourceMappingURL=ArtifactLocks.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/internal/ArtifactLocks.ts"],
4
+ "sourcesContent": ["/**\n * Per-digest coordination for filesystem publication and removal.\n *\n * The semaphore is the cheap in-process path. A `FileLease` lock file is the\n * actual workspace-wide fence: every process that can mutate the object\n * directory observes it, and a crashed owner is recovered after its heartbeat\n * expires.\n *\n * @since 1.0.0-rc.0\n */\n\nimport * as Deferred from \"effect/Deferred\"\nimport * as Effect from \"effect/Effect\"\nimport type * as FileSystem from \"effect/FileSystem\"\nimport * as Semaphore from \"effect/Semaphore\"\nimport * as FileLease from \"../FileLease.ts\"\nimport * as ArtifactPath from \"./ArtifactPath.ts\"\n\ninterface Entry {\n readonly semaphore: Semaphore.Semaphore\n users: number\n}\n\nconst locks = new WeakMap<FileSystem.FileSystem, Map<string, Entry>>()\n\n/**\n * The subdirectory of the objects directory that holds lock files and their\n * stale-owner tombstones. Named here rather than spelled in each caller so the\n * store's crash-orphan sweep reclaims exactly what this module creates.\n *\n * @category constants\n * @since 1.0.0-rc.0\n */\nexport const directoryName = \".locks\"\n\n/**\n * Coordinates publication, freshening, and sweep deletion for one digest.\n * `process` is the explicit weaker mode for hosts without atomic create.\n *\n * @category combinators\n * @since 1.0.0-rc.0\n */\nexport const withDigest = <A, E, R, E2>(\n fs: FileSystem.FileSystem,\n directory: string,\n digest: string,\n effect: Effect.Effect<A, E, R>,\n failure: (cause: unknown) => E2,\n coordination: \"required\" | \"process\" = \"required\"\n): Effect.Effect<A, E | E2, R> =>\n // Every execution of the returned effect claims its own share of the entry,\n // which is why the whole body is suspended rather than run when `withDigest`\n // is called. A count taken at construction is wrong in both directions: an\n // effect built and discarded pins an entry nothing will ever release, and one\n // built once and run repeatedly \u2014 `ArtifactBackupLease` builds its gate once\n // and runs it on every heartbeat \u2014 retires the entry underneath a live holder,\n // so the next caller mints a second semaphore for the same digest and the two\n // serialize against nothing.\n Effect.suspend(() => {\n let byKey = locks.get(fs)\n if (byKey === undefined) {\n byKey = new Map()\n locks.set(fs, byKey)\n }\n const key = JSON.stringify([directory, digest])\n let entry = byKey.get(key)\n if (entry === undefined) {\n entry = { semaphore: Semaphore.makeUnsafe(1), users: 0 }\n byKey.set(key, entry)\n }\n entry.users += 1\n const held = entry\n const table = byKey\n\n // The deadline starts before the semaphore wait and ends once both locks\n // are held. The protected operation and its release are never timed out.\n const ready = Deferred.makeUnsafe<void>()\n const deadline = Deferred.await(ready).pipe(\n Effect.timeout(FileLease.defaultAcquireWithin),\n Effect.catchTag(\"TimeoutError\", (cause) => Effect.fail(failure(cause))),\n Effect.andThen(Effect.never)\n )\n const coordinated = coordination === \"process\"\n ? Deferred.succeed(ready, undefined).pipe(Effect.andThen(effect))\n : Effect.gen(function*() {\n // The lock directory is refused as a symlink before and after it is\n // created, and its identity is re-checked before every lock-file\n // mutation, so a swap of `.locks` for a link cannot redirect lock,\n // claim, or tombstone writes and removals elsewhere. The portable\n // filesystem cannot make a check atomic with the mutation after it.\n const lockDirectory = `${directory}/${directoryName}`\n yield* ArtifactPath.guard(fs, lockDirectory).pipe(Effect.mapError(failure))\n yield* fs.makeDirectory(lockDirectory, { recursive: true, mode: 0o700 }).pipe(Effect.mapError(failure))\n const checkLockDirectory = yield* ArtifactPath.guard(fs, lockDirectory).pipe(Effect.mapError(failure))\n return yield* FileLease.hold(fs, `${lockDirectory}/${digest}.lock`, effect, failure, {\n label: \"Artifact lock\",\n annotations: { digest },\n onAcquired: Deferred.succeed(ready, undefined).pipe(Effect.asVoid),\n guard: checkLockDirectory\n })\n })\n\n return held.semaphore.withPermit(coordinated).pipe(\n Effect.raceFirst(deadline),\n Effect.ensuring(Effect.sync(() => {\n held.users -= 1\n if (held.users === 0 && table.get(key) === held) table.delete(key)\n }))\n )\n })\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,eAA0B;AAC1B,aAAwB;AAExB,gBAA2B;AAC3B,gBAA2B;AAC3B,mBAA8B;AAO9B,MAAM,QAAQ,oBAAI,QAAmD;AAU9D,MAAM,gBAAgB;AAStB,MAAM,aAAa,CACxB,IACA,WACA,QACA,QACA,SACA,eAAuC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUvC,OAAO,QAAQ,MAAM;AACnB,QAAI,QAAQ,MAAM,IAAI,EAAE;AACxB,QAAI,UAAU,QAAW;AACvB,cAAQ,oBAAI,IAAI;AAChB,YAAM,IAAI,IAAI,KAAK;AAAA,IACrB;AACA,UAAM,MAAM,KAAK,UAAU,CAAC,WAAW,MAAM,CAAC;AAC9C,QA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KAAK,MAAM;AAChC,aAAK,SAAS;AACd,YAAI,KAAK,UAAU,KAAK,MAAM,IAAI,GAAG,MAAM,KAAM,OAAM,OAAO,GAAG;AAAA,MACnE,CAAC,CAAC;AAAA,IACJ;AAAA,EACF,CAAC;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Path checks for the portable filesystem adapter. These detect symlinks and
3
+ * observed replacements, but cannot make pathname mutations atomic with the
4
+ * check. Effect's FileSystem has no descriptor-relative rename or unlink.
5
+ *
6
+ * @since 1.0.0-rc.0
7
+ */
8
+ import * as Effect from "effect/Effect";
9
+ import type * as FileSystem from "effect/FileSystem";
10
+ import * as PlatformError from "effect/PlatformError";
11
+ /**
12
+ * Checks one entry without accepting a symbolic link and returns a check that
13
+ * also refuses a changed identity. Missing entries are allowed for creation.
14
+ *
15
+ * @category utilities
16
+ * @since 1.0.0-rc.0
17
+ */
18
+ export declare const guard: (fs: FileSystem.FileSystem, path: string, type?: "Directory" | "File", expected?: FileSystem.File.Info) => Effect.Effect<Effect.Effect<void, PlatformError.PlatformError>, PlatformError.PlatformError>;
19
+ //# sourceMappingURL=ArtifactPath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArtifactPath.d.ts","sourceRoot":"","sources":["../../../src/internal/ArtifactPath.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAEpD,OAAO,KAAK,aAAa,MAAM,sBAAsB,CAAA;AAErD;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,GAChB,IAAI,UAAU,CAAC,UAAU,EACzB,MAAM,MAAM,EACZ,OAAM,WAAW,GAAG,MAAoB,EACxC,WAAW,UAAU,CAAC,IAAI,CAAC,IAAI,KAC9B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC,aAAa,CA8C7F,CAAA"}
@@ -0,0 +1,74 @@
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 ArtifactPath_exports = {};
30
+ __export(ArtifactPath_exports, {
31
+ guard: () => guard
32
+ });
33
+ module.exports = __toCommonJS(ArtifactPath_exports);
34
+ var Effect = __toESM(require("effect/Effect"), 1);
35
+ var Option = __toESM(require("effect/Option"), 1);
36
+ var PlatformError = __toESM(require("effect/PlatformError"), 1);
37
+ const guard = (fs, path, type = "Directory", expected) => {
38
+ const refused = () => PlatformError.systemError({
39
+ _tag: "PermissionDenied",
40
+ module: "ArtifactPath",
41
+ method: "guard",
42
+ pathOrDescriptor: path,
43
+ description: "artifact path is a symlink, has the wrong type, or was replaced"
44
+ });
45
+ const inspect = Effect.gen(function* () {
46
+ const linked = yield* fs.readLink(path).pipe(
47
+ Effect.as(true),
48
+ Effect.catch((cause) => {
49
+ const underlying = cause.cause;
50
+ return cause.reason._tag === "NotFound" || typeof underlying === "object" && underlying !== null && "code" in underlying && underlying.code === "EINVAL" ? Effect.succeed(false) : Effect.fail(cause);
51
+ })
52
+ );
53
+ if (linked) return yield* Effect.fail(refused());
54
+ const info = yield* fs.stat(path).pipe(
55
+ Effect.map(Option.some),
56
+ Effect.catch((cause) => cause.reason._tag === "NotFound" ? Effect.succeed(Option.none()) : Effect.fail(cause))
57
+ );
58
+ if (Option.isSome(info) && info.value.type !== type) return yield* Effect.fail(refused());
59
+ return info;
60
+ });
61
+ const unchanged = (before, after) => {
62
+ if (Option.isNone(before)) return Effect.void;
63
+ if (Option.isNone(after) || before.value.dev !== after.value.dev || Option.getOrUndefined(before.value.ino) !== Option.getOrUndefined(after.value.ino)) {
64
+ return Effect.fail(refused());
65
+ }
66
+ return Effect.void;
67
+ };
68
+ return Effect.gen(function* () {
69
+ const before = yield* inspect;
70
+ yield* unchanged(Option.fromUndefinedOr(expected), before);
71
+ return Effect.flatMap(inspect, (after) => unchanged(before, after));
72
+ });
73
+ };
74
+ //# sourceMappingURL=ArtifactPath.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/internal/ArtifactPath.ts"],
4
+ "sourcesContent": ["/**\n * Path checks for the portable filesystem adapter. These detect symlinks and\n * observed replacements, but cannot make pathname mutations atomic with the\n * check. Effect's FileSystem has no descriptor-relative rename or unlink.\n *\n * @since 1.0.0-rc.0\n */\n\nimport * as Effect from \"effect/Effect\"\nimport type * as FileSystem from \"effect/FileSystem\"\nimport * as Option from \"effect/Option\"\nimport * as PlatformError from \"effect/PlatformError\"\n\n/**\n * Checks one entry without accepting a symbolic link and returns a check that\n * also refuses a changed identity. Missing entries are allowed for creation.\n *\n * @category utilities\n * @since 1.0.0-rc.0\n */\nexport const guard = (\n fs: FileSystem.FileSystem,\n path: string,\n type: \"Directory\" | \"File\" = \"Directory\",\n expected?: FileSystem.File.Info\n): Effect.Effect<Effect.Effect<void, PlatformError.PlatformError>, PlatformError.PlatformError> => {\n const refused = () =>\n PlatformError.systemError({\n _tag: \"PermissionDenied\",\n module: \"ArtifactPath\",\n method: \"guard\",\n pathOrDescriptor: path,\n description: \"artifact path is a symlink, has the wrong type, or was replaced\"\n })\n const inspect = Effect.gen(function*() {\n const linked = yield* fs.readLink(path).pipe(\n Effect.as(true),\n Effect.catch((cause) => {\n // Node readlink uses EINVAL for an existing entry that is not a link.\n // Other failures, including an unsupported host capability, fail closed.\n const underlying = cause.cause\n return cause.reason._tag === \"NotFound\" ||\n (typeof underlying === \"object\" && underlying !== null && \"code\" in underlying &&\n underlying.code === \"EINVAL\")\n ? Effect.succeed(false)\n : Effect.fail(cause)\n })\n )\n if (linked) return yield* Effect.fail(refused())\n const info = yield* fs.stat(path).pipe(\n Effect.map(Option.some),\n Effect.catch((cause) => cause.reason._tag === \"NotFound\" ? Effect.succeed(Option.none()) : Effect.fail(cause))\n )\n if (Option.isSome(info) && info.value.type !== type) return yield* Effect.fail(refused())\n return info\n })\n const unchanged = (before: Option.Option<FileSystem.File.Info>, after: Option.Option<FileSystem.File.Info>) => {\n if (Option.isNone(before)) return Effect.void\n if (\n Option.isNone(after) || before.value.dev !== after.value.dev ||\n Option.getOrUndefined(before.value.ino) !== Option.getOrUndefined(after.value.ino)\n ) {\n return Effect.fail(refused())\n }\n return Effect.void\n }\n return Effect.gen(function*() {\n const before = yield* inspect\n yield* unchanged(Option.fromUndefinedOr(expected), before)\n return Effect.flatMap(inspect, (after) => unchanged(before, after))\n })\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,aAAwB;AAExB,aAAwB;AACxB,oBAA+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AO,OAAO;AAAA,EAChB;AACA,SAAO,OAAO,IAAI,aAAY;AAC5B,UAAM,SAAS,OAAO;AACtB,WAAO,UAAU,OAAO,gBAAgB,QAAQ,GAAG,MAAM;AACzD,WAAO,OAAO,QAAQ,SAAS,CAAC,UAAU,UAAU,QAAQ,KAAK,CAAC;AAAA,EACpE,CAAC;AACH;",
6
+ "names": []
7
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Measuring artifact bytes: the SHA-256 content address of one immutable
3
+ * snapshot, computed through the injected `Crypto` service.
4
+ *
5
+ * @since 1.0.0-rc.0
6
+ */
7
+ import type * as Crypto from "effect/Crypto";
8
+ import * as Effect from "effect/Effect";
9
+ import type { Digest } from "./ArtifactStore.ts";
10
+ import { ArtifactStoreError } from "./ArtifactStoreError.ts";
11
+ /**
12
+ * Measures one immutable byte snapshot without ever retaining it in an error.
13
+ *
14
+ * @category utilities
15
+ * @since 1.0.0-rc.0
16
+ */
17
+ export declare const measureBytes: (bytes: Uint8Array) => Effect.Effect<Digest, ArtifactStoreError, Crypto.Crypto>;
18
+ //# sourceMappingURL=measureBytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measureBytes.d.ts","sourceRoot":"","sources":["../../src/measureBytes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAS5D;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,UAAU,KAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,EAAE,MAAM,CAAC,MAAM,CAC7C,CAAA"}
@@ -0,0 +1,43 @@
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 measureBytes_exports = {};
30
+ __export(measureBytes_exports, {
31
+ measureBytes: () => measureBytes
32
+ });
33
+ module.exports = __toCommonJS(measureBytes_exports);
34
+ var import_crypto = require("@smthrs/crypto");
35
+ var Effect = __toESM(require("effect/Effect"), 1);
36
+ var import_ArtifactStoreError = require("./ArtifactStoreError.js");
37
+ const digestFailure = (cause) => new import_ArtifactStoreError.ArtifactStoreError({
38
+ code: "digest_failed",
39
+ message: "the Crypto service failed to compute an artifact digest",
40
+ cause
41
+ });
42
+ const measureBytes = (bytes) => import_crypto.Sha256.digest(bytes).pipe(Effect.mapError(digestFailure));
43
+ //# sourceMappingURL=measureBytes.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/measureBytes.ts"],
4
+ "sourcesContent": ["/**\n * Measuring artifact bytes: the SHA-256 content address of one immutable\n * snapshot, computed through the injected `Crypto` service.\n *\n * @since 1.0.0-rc.0\n */\n\nimport { Sha256 } from \"@smthrs/crypto\"\nimport type * as Crypto from \"effect/Crypto\"\nimport * as Effect from \"effect/Effect\"\nimport type { Digest } from \"./ArtifactStore.ts\"\nimport { ArtifactStoreError } from \"./ArtifactStoreError.ts\"\n\nconst digestFailure = (cause: unknown): ArtifactStoreError =>\n new ArtifactStoreError({\n code: \"digest_failed\",\n message: \"the Crypto service failed to compute an artifact digest\",\n cause\n })\n\n/**\n * Measures one immutable byte snapshot without ever retaining it in an error.\n *\n * @category utilities\n * @since 1.0.0-rc.0\n */\nexport const measureBytes = (bytes: Uint8Array): Effect.Effect<Digest, ArtifactStoreError, Crypto.Crypto> =>\n Sha256.digest(bytes).pipe(Effect.mapError(digestFailure))\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,oBAAuB;AAEvB,aAAwB;AAExB,gCAAmC;AAEnC,MAAM,gBAAgB,CAAC,UACrB,IAAI,6CAAmB;AAAA,EACrB,MAAM;AAAA,EACN,SAAS;AAAA,EACT;AACF,CAAC;AAQI,MAAM,eAAe,CAAC,UAC3B,qBAAO,OAAO,KAAK,EAAE,KAAK,OAAO,SAAS,aAAa,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Snapshotting caller-owned artifact bytes, so a caller that reuses its buffer
3
+ * cannot change what is measured or stored.
4
+ *
5
+ * @since 1.0.0-rc.0
6
+ */
7
+ import * as Effect from "effect/Effect";
8
+ import { ArtifactStoreError } from "./ArtifactStoreError.ts";
9
+ /**
10
+ * Copies a caller-owned buffer when the returned Effect begins.
11
+ *
12
+ * A host that refuses the copy — a detached buffer, an allocation past what the
13
+ * runtime will give — fails as `unavailable`, the code for a host refusal.
14
+ *
15
+ * @category utilities
16
+ * @since 1.0.0-rc.0
17
+ */
18
+ export declare const snapshotBytes: (bytes: Uint8Array) => Effect.Effect<Uint8Array, ArtifactStoreError>;
19
+ //# sourceMappingURL=snapshotBytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshotBytes.d.ts","sourceRoot":"","sources":["../../src/snapshotBytes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAY5D;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,UAAU,KAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAI1F,CAAA"}