@noy-db/to-cloudflare-r2 0.1.0-pre.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 vLannaAi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @noy-db/to-cloudflare-r2
2
+
3
+ [![npm](https://img.shields.io/npm/v/%40noy-db/to-cloudflare-r2.svg)](https://www.npmjs.com/package/@noy-db/to-cloudflare-r2)
4
+
5
+ > Cloudflare R2 adapter for noy-db
6
+
7
+ Part of [**`@noy-db/hub`**](https://www.npmjs.com/package/@noy-db/hub) — the zero-knowledge, offline-first, encrypted document store.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add @noy-db/hub @noy-db/to-cloudflare-r2
13
+ ```
14
+
15
+ ## What it is
16
+
17
+ Cloudflare R2 adapter for noy-db — S3-compatible object storage with zero egress fees. Thin wrapper around @noy-db/to-aws-s3 configured for the R2 endpoint. casAtomic: false (same caveat as S3).
18
+
19
+ ## Status
20
+
21
+ **Pre-release** (`0.1.0-pre.1`). API may change before `1.0`.
22
+
23
+ ## Documentation
24
+
25
+ See the [main repository](https://github.com/vLannaAi/noy-db#readme) for setup, examples, and the full subsystem catalog.
26
+
27
+ - Source — [`packages/to-cloudflare-r2`](https://github.com/vLannaAi/noy-db/tree/main/packages/to-cloudflare-r2)
28
+ - Issues — [github.com/vLannaAi/noy-db/issues](https://github.com/vLannaAi/noy-db/issues)
29
+ - Spec — [`SPEC.md`](https://github.com/vLannaAi/noy-db/blob/main/SPEC.md)
30
+
31
+ ## License
32
+
33
+ [MIT](./LICENSE) © vLannaAi
package/dist/index.cjs ADDED
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ r2: () => r2,
24
+ r2EndpointFor: () => r2EndpointFor
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_client_s3 = require("@aws-sdk/client-s3");
28
+ var import_to_aws_s3 = require("@noy-db/to-aws-s3");
29
+ var R2_REGION = "auto";
30
+ function r2EndpointFor(accountId) {
31
+ return `https://${accountId}.r2.cloudflarestorage.com`;
32
+ }
33
+ function r2(options) {
34
+ if (options.client) {
35
+ const opts2 = {
36
+ bucket: options.bucket,
37
+ ...options.prefix !== void 0 && { prefix: options.prefix },
38
+ client: options.client
39
+ };
40
+ return (0, import_to_aws_s3.s3)(opts2);
41
+ }
42
+ if (!options.accountId) {
43
+ throw new Error("@noy-db/to-cloudflare-r2: provide either `client` or `accountId`.");
44
+ }
45
+ if (!options.accessKeyId || !options.secretAccessKey) {
46
+ throw new Error("@noy-db/to-cloudflare-r2: `accessKeyId` and `secretAccessKey` are required (unless `client` is supplied).");
47
+ }
48
+ const endpoint = options.endpoint ?? r2EndpointFor(options.accountId);
49
+ const config = {
50
+ region: R2_REGION,
51
+ endpoint,
52
+ credentials: {
53
+ accessKeyId: options.accessKeyId,
54
+ secretAccessKey: options.secretAccessKey
55
+ },
56
+ forcePathStyle: true
57
+ };
58
+ const built = new import_client_s3.S3Client(config);
59
+ const opts = {
60
+ bucket: options.bucket,
61
+ ...options.prefix !== void 0 && { prefix: options.prefix },
62
+ client: built
63
+ };
64
+ return { ...(0, import_to_aws_s3.s3)(opts), name: "cloudflare-r2" };
65
+ }
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ r2,
69
+ r2EndpointFor
70
+ });
71
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * **@noy-db/to-cloudflare-r2** — Cloudflare R2 adapter for noy-db.\n *\n * R2 is S3-API-compatible, so this package is a thin factory that\n * configures `@noy-db/to-aws-s3` to point at the R2 endpoint and\n * pass the R2-specific access key signature. Every capability,\n * behavior, and pagination detail of `s3()` applies verbatim.\n *\n * ## Why R2 for noy-db?\n *\n * - **Zero egress fees** — backup/archive workflows that stream the\n * whole vault on a schedule cost nothing to read back.\n * - **S3-compatible** — no new API surface; same SDK, same commands.\n * - **Workers edge** — pair with `@noy-db/to-cloudflare-d1` for a\n * pure-edge noy-db deployment.\n *\n * ## Account-id vs endpoint\n *\n * The simplest configuration passes your Cloudflare account id and\n * the bucket name:\n *\n * ```ts\n * import { r2 } from '@noy-db/to-cloudflare-r2'\n *\n * const store = r2({\n * accountId: 'abc123…', // Cloudflare dashboard → R2 → account id\n * bucket: 'my-noydb-bucket',\n * accessKeyId: process.env.R2_ACCESS_KEY_ID!,\n * secretAccessKey: process.env.R2_SECRET!,\n * })\n * ```\n *\n * Consumers who already have a configured `S3Client` (common in Workers\n * / multi-region setups) can pass it via `client`; the rest of the\n * options are ignored.\n *\n * @packageDocumentation\n */\n\nimport type { NoydbStore } from '@noy-db/hub'\nimport type { S3Client, S3ClientConfig } from '@aws-sdk/client-s3'\nimport { S3Client as RealS3Client } from '@aws-sdk/client-s3'\nimport { s3 } from '@noy-db/to-aws-s3'\n\nexport interface R2Options {\n /** Cloudflare account id (from the R2 dashboard). Required unless `client` is supplied. */\n readonly accountId?: string\n /** R2 bucket name. */\n readonly bucket: string\n /** Key prefix within the bucket. Default `''`. */\n readonly prefix?: string\n /**\n * R2 access key id. Required unless `client` is supplied. Prefer\n * short-lived credentials via the account's API token flow.\n */\n readonly accessKeyId?: string\n /** R2 secret access key. Required unless `client` is supplied. */\n readonly secretAccessKey?: string\n /**\n * Pre-built S3Client — overrides every other authentication option.\n * Use this when you already share an R2-pointed client across adapters\n * or run in Cloudflare Workers with an injected binding.\n */\n readonly client?: S3Client\n /** Override the endpoint. Default derived from `accountId`. */\n readonly endpoint?: string\n}\n\nconst R2_REGION = 'auto'\n\n/**\n * Build the default R2 endpoint URL for a Cloudflare account.\n * The public form is documented as:\n * `https://<accountId>.r2.cloudflarestorage.com`\n */\nexport function r2EndpointFor(accountId: string): string {\n return `https://${accountId}.r2.cloudflarestorage.com`\n}\n\n/**\n * Create a noy-db store backed by Cloudflare R2. Delegates to\n * `@noy-db/to-aws-s3`'s `s3()` with R2-specific endpoint + region\n * configured.\n */\nexport function r2(options: R2Options): NoydbStore {\n if (options.client) {\n const opts: Parameters<typeof s3>[0] = {\n bucket: options.bucket,\n ...(options.prefix !== undefined && { prefix: options.prefix }),\n client: options.client,\n }\n return s3(opts)\n }\n\n if (!options.accountId) {\n throw new Error('@noy-db/to-cloudflare-r2: provide either `client` or `accountId`.')\n }\n if (!options.accessKeyId || !options.secretAccessKey) {\n throw new Error('@noy-db/to-cloudflare-r2: `accessKeyId` and `secretAccessKey` are required (unless `client` is supplied).')\n }\n\n const endpoint = options.endpoint ?? r2EndpointFor(options.accountId)\n const config: S3ClientConfig = {\n region: R2_REGION,\n endpoint,\n credentials: {\n accessKeyId: options.accessKeyId,\n secretAccessKey: options.secretAccessKey,\n },\n forcePathStyle: true,\n }\n const built = new RealS3Client(config)\n const opts: Parameters<typeof s3>[0] = {\n bucket: options.bucket,\n ...(options.prefix !== undefined && { prefix: options.prefix }),\n client: built,\n }\n return { ...s3(opts), name: 'cloudflare-r2' }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCA,uBAAyC;AACzC,uBAAmB;AA0BnB,IAAM,YAAY;AAOX,SAAS,cAAc,WAA2B;AACvD,SAAO,WAAW,SAAS;AAC7B;AAOO,SAAS,GAAG,SAAgC;AACjD,MAAI,QAAQ,QAAQ;AAClB,UAAMA,QAAiC;AAAA,MACrC,QAAQ,QAAQ;AAAA,MAChB,GAAI,QAAQ,WAAW,UAAa,EAAE,QAAQ,QAAQ,OAAO;AAAA,MAC7D,QAAQ,QAAQ;AAAA,IAClB;AACA,eAAO,qBAAGA,KAAI;AAAA,EAChB;AAEA,MAAI,CAAC,QAAQ,WAAW;AACtB,UAAM,IAAI,MAAM,mEAAmE;AAAA,EACrF;AACA,MAAI,CAAC,QAAQ,eAAe,CAAC,QAAQ,iBAAiB;AACpD,UAAM,IAAI,MAAM,2GAA2G;AAAA,EAC7H;AAEA,QAAM,WAAW,QAAQ,YAAY,cAAc,QAAQ,SAAS;AACpE,QAAM,SAAyB;AAAA,IAC7B,QAAQ;AAAA,IACR;AAAA,IACA,aAAa;AAAA,MACX,aAAa,QAAQ;AAAA,MACrB,iBAAiB,QAAQ;AAAA,IAC3B;AAAA,IACA,gBAAgB;AAAA,EAClB;AACA,QAAM,QAAQ,IAAI,iBAAAC,SAAa,MAAM;AACrC,QAAM,OAAiC;AAAA,IACrC,QAAQ,QAAQ;AAAA,IAChB,GAAI,QAAQ,WAAW,UAAa,EAAE,QAAQ,QAAQ,OAAO;AAAA,IAC7D,QAAQ;AAAA,EACV;AACA,SAAO,EAAE,OAAG,qBAAG,IAAI,GAAG,MAAM,gBAAgB;AAC9C;","names":["opts","RealS3Client"]}
@@ -0,0 +1,79 @@
1
+ import { NoydbStore } from '@noy-db/hub';
2
+ import { S3Client } from '@aws-sdk/client-s3';
3
+
4
+ /**
5
+ * **@noy-db/to-cloudflare-r2** — Cloudflare R2 adapter for noy-db.
6
+ *
7
+ * R2 is S3-API-compatible, so this package is a thin factory that
8
+ * configures `@noy-db/to-aws-s3` to point at the R2 endpoint and
9
+ * pass the R2-specific access key signature. Every capability,
10
+ * behavior, and pagination detail of `s3()` applies verbatim.
11
+ *
12
+ * ## Why R2 for noy-db?
13
+ *
14
+ * - **Zero egress fees** — backup/archive workflows that stream the
15
+ * whole vault on a schedule cost nothing to read back.
16
+ * - **S3-compatible** — no new API surface; same SDK, same commands.
17
+ * - **Workers edge** — pair with `@noy-db/to-cloudflare-d1` for a
18
+ * pure-edge noy-db deployment.
19
+ *
20
+ * ## Account-id vs endpoint
21
+ *
22
+ * The simplest configuration passes your Cloudflare account id and
23
+ * the bucket name:
24
+ *
25
+ * ```ts
26
+ * import { r2 } from '@noy-db/to-cloudflare-r2'
27
+ *
28
+ * const store = r2({
29
+ * accountId: 'abc123…', // Cloudflare dashboard → R2 → account id
30
+ * bucket: 'my-noydb-bucket',
31
+ * accessKeyId: process.env.R2_ACCESS_KEY_ID!,
32
+ * secretAccessKey: process.env.R2_SECRET!,
33
+ * })
34
+ * ```
35
+ *
36
+ * Consumers who already have a configured `S3Client` (common in Workers
37
+ * / multi-region setups) can pass it via `client`; the rest of the
38
+ * options are ignored.
39
+ *
40
+ * @packageDocumentation
41
+ */
42
+
43
+ interface R2Options {
44
+ /** Cloudflare account id (from the R2 dashboard). Required unless `client` is supplied. */
45
+ readonly accountId?: string;
46
+ /** R2 bucket name. */
47
+ readonly bucket: string;
48
+ /** Key prefix within the bucket. Default `''`. */
49
+ readonly prefix?: string;
50
+ /**
51
+ * R2 access key id. Required unless `client` is supplied. Prefer
52
+ * short-lived credentials via the account's API token flow.
53
+ */
54
+ readonly accessKeyId?: string;
55
+ /** R2 secret access key. Required unless `client` is supplied. */
56
+ readonly secretAccessKey?: string;
57
+ /**
58
+ * Pre-built S3Client — overrides every other authentication option.
59
+ * Use this when you already share an R2-pointed client across adapters
60
+ * or run in Cloudflare Workers with an injected binding.
61
+ */
62
+ readonly client?: S3Client;
63
+ /** Override the endpoint. Default derived from `accountId`. */
64
+ readonly endpoint?: string;
65
+ }
66
+ /**
67
+ * Build the default R2 endpoint URL for a Cloudflare account.
68
+ * The public form is documented as:
69
+ * `https://<accountId>.r2.cloudflarestorage.com`
70
+ */
71
+ declare function r2EndpointFor(accountId: string): string;
72
+ /**
73
+ * Create a noy-db store backed by Cloudflare R2. Delegates to
74
+ * `@noy-db/to-aws-s3`'s `s3()` with R2-specific endpoint + region
75
+ * configured.
76
+ */
77
+ declare function r2(options: R2Options): NoydbStore;
78
+
79
+ export { type R2Options, r2, r2EndpointFor };
@@ -0,0 +1,79 @@
1
+ import { NoydbStore } from '@noy-db/hub';
2
+ import { S3Client } from '@aws-sdk/client-s3';
3
+
4
+ /**
5
+ * **@noy-db/to-cloudflare-r2** — Cloudflare R2 adapter for noy-db.
6
+ *
7
+ * R2 is S3-API-compatible, so this package is a thin factory that
8
+ * configures `@noy-db/to-aws-s3` to point at the R2 endpoint and
9
+ * pass the R2-specific access key signature. Every capability,
10
+ * behavior, and pagination detail of `s3()` applies verbatim.
11
+ *
12
+ * ## Why R2 for noy-db?
13
+ *
14
+ * - **Zero egress fees** — backup/archive workflows that stream the
15
+ * whole vault on a schedule cost nothing to read back.
16
+ * - **S3-compatible** — no new API surface; same SDK, same commands.
17
+ * - **Workers edge** — pair with `@noy-db/to-cloudflare-d1` for a
18
+ * pure-edge noy-db deployment.
19
+ *
20
+ * ## Account-id vs endpoint
21
+ *
22
+ * The simplest configuration passes your Cloudflare account id and
23
+ * the bucket name:
24
+ *
25
+ * ```ts
26
+ * import { r2 } from '@noy-db/to-cloudflare-r2'
27
+ *
28
+ * const store = r2({
29
+ * accountId: 'abc123…', // Cloudflare dashboard → R2 → account id
30
+ * bucket: 'my-noydb-bucket',
31
+ * accessKeyId: process.env.R2_ACCESS_KEY_ID!,
32
+ * secretAccessKey: process.env.R2_SECRET!,
33
+ * })
34
+ * ```
35
+ *
36
+ * Consumers who already have a configured `S3Client` (common in Workers
37
+ * / multi-region setups) can pass it via `client`; the rest of the
38
+ * options are ignored.
39
+ *
40
+ * @packageDocumentation
41
+ */
42
+
43
+ interface R2Options {
44
+ /** Cloudflare account id (from the R2 dashboard). Required unless `client` is supplied. */
45
+ readonly accountId?: string;
46
+ /** R2 bucket name. */
47
+ readonly bucket: string;
48
+ /** Key prefix within the bucket. Default `''`. */
49
+ readonly prefix?: string;
50
+ /**
51
+ * R2 access key id. Required unless `client` is supplied. Prefer
52
+ * short-lived credentials via the account's API token flow.
53
+ */
54
+ readonly accessKeyId?: string;
55
+ /** R2 secret access key. Required unless `client` is supplied. */
56
+ readonly secretAccessKey?: string;
57
+ /**
58
+ * Pre-built S3Client — overrides every other authentication option.
59
+ * Use this when you already share an R2-pointed client across adapters
60
+ * or run in Cloudflare Workers with an injected binding.
61
+ */
62
+ readonly client?: S3Client;
63
+ /** Override the endpoint. Default derived from `accountId`. */
64
+ readonly endpoint?: string;
65
+ }
66
+ /**
67
+ * Build the default R2 endpoint URL for a Cloudflare account.
68
+ * The public form is documented as:
69
+ * `https://<accountId>.r2.cloudflarestorage.com`
70
+ */
71
+ declare function r2EndpointFor(accountId: string): string;
72
+ /**
73
+ * Create a noy-db store backed by Cloudflare R2. Delegates to
74
+ * `@noy-db/to-aws-s3`'s `s3()` with R2-specific endpoint + region
75
+ * configured.
76
+ */
77
+ declare function r2(options: R2Options): NoydbStore;
78
+
79
+ export { type R2Options, r2, r2EndpointFor };
package/dist/index.js ADDED
@@ -0,0 +1,45 @@
1
+ // src/index.ts
2
+ import { S3Client as RealS3Client } from "@aws-sdk/client-s3";
3
+ import { s3 } from "@noy-db/to-aws-s3";
4
+ var R2_REGION = "auto";
5
+ function r2EndpointFor(accountId) {
6
+ return `https://${accountId}.r2.cloudflarestorage.com`;
7
+ }
8
+ function r2(options) {
9
+ if (options.client) {
10
+ const opts2 = {
11
+ bucket: options.bucket,
12
+ ...options.prefix !== void 0 && { prefix: options.prefix },
13
+ client: options.client
14
+ };
15
+ return s3(opts2);
16
+ }
17
+ if (!options.accountId) {
18
+ throw new Error("@noy-db/to-cloudflare-r2: provide either `client` or `accountId`.");
19
+ }
20
+ if (!options.accessKeyId || !options.secretAccessKey) {
21
+ throw new Error("@noy-db/to-cloudflare-r2: `accessKeyId` and `secretAccessKey` are required (unless `client` is supplied).");
22
+ }
23
+ const endpoint = options.endpoint ?? r2EndpointFor(options.accountId);
24
+ const config = {
25
+ region: R2_REGION,
26
+ endpoint,
27
+ credentials: {
28
+ accessKeyId: options.accessKeyId,
29
+ secretAccessKey: options.secretAccessKey
30
+ },
31
+ forcePathStyle: true
32
+ };
33
+ const built = new RealS3Client(config);
34
+ const opts = {
35
+ bucket: options.bucket,
36
+ ...options.prefix !== void 0 && { prefix: options.prefix },
37
+ client: built
38
+ };
39
+ return { ...s3(opts), name: "cloudflare-r2" };
40
+ }
41
+ export {
42
+ r2,
43
+ r2EndpointFor
44
+ };
45
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * **@noy-db/to-cloudflare-r2** — Cloudflare R2 adapter for noy-db.\n *\n * R2 is S3-API-compatible, so this package is a thin factory that\n * configures `@noy-db/to-aws-s3` to point at the R2 endpoint and\n * pass the R2-specific access key signature. Every capability,\n * behavior, and pagination detail of `s3()` applies verbatim.\n *\n * ## Why R2 for noy-db?\n *\n * - **Zero egress fees** — backup/archive workflows that stream the\n * whole vault on a schedule cost nothing to read back.\n * - **S3-compatible** — no new API surface; same SDK, same commands.\n * - **Workers edge** — pair with `@noy-db/to-cloudflare-d1` for a\n * pure-edge noy-db deployment.\n *\n * ## Account-id vs endpoint\n *\n * The simplest configuration passes your Cloudflare account id and\n * the bucket name:\n *\n * ```ts\n * import { r2 } from '@noy-db/to-cloudflare-r2'\n *\n * const store = r2({\n * accountId: 'abc123…', // Cloudflare dashboard → R2 → account id\n * bucket: 'my-noydb-bucket',\n * accessKeyId: process.env.R2_ACCESS_KEY_ID!,\n * secretAccessKey: process.env.R2_SECRET!,\n * })\n * ```\n *\n * Consumers who already have a configured `S3Client` (common in Workers\n * / multi-region setups) can pass it via `client`; the rest of the\n * options are ignored.\n *\n * @packageDocumentation\n */\n\nimport type { NoydbStore } from '@noy-db/hub'\nimport type { S3Client, S3ClientConfig } from '@aws-sdk/client-s3'\nimport { S3Client as RealS3Client } from '@aws-sdk/client-s3'\nimport { s3 } from '@noy-db/to-aws-s3'\n\nexport interface R2Options {\n /** Cloudflare account id (from the R2 dashboard). Required unless `client` is supplied. */\n readonly accountId?: string\n /** R2 bucket name. */\n readonly bucket: string\n /** Key prefix within the bucket. Default `''`. */\n readonly prefix?: string\n /**\n * R2 access key id. Required unless `client` is supplied. Prefer\n * short-lived credentials via the account's API token flow.\n */\n readonly accessKeyId?: string\n /** R2 secret access key. Required unless `client` is supplied. */\n readonly secretAccessKey?: string\n /**\n * Pre-built S3Client — overrides every other authentication option.\n * Use this when you already share an R2-pointed client across adapters\n * or run in Cloudflare Workers with an injected binding.\n */\n readonly client?: S3Client\n /** Override the endpoint. Default derived from `accountId`. */\n readonly endpoint?: string\n}\n\nconst R2_REGION = 'auto'\n\n/**\n * Build the default R2 endpoint URL for a Cloudflare account.\n * The public form is documented as:\n * `https://<accountId>.r2.cloudflarestorage.com`\n */\nexport function r2EndpointFor(accountId: string): string {\n return `https://${accountId}.r2.cloudflarestorage.com`\n}\n\n/**\n * Create a noy-db store backed by Cloudflare R2. Delegates to\n * `@noy-db/to-aws-s3`'s `s3()` with R2-specific endpoint + region\n * configured.\n */\nexport function r2(options: R2Options): NoydbStore {\n if (options.client) {\n const opts: Parameters<typeof s3>[0] = {\n bucket: options.bucket,\n ...(options.prefix !== undefined && { prefix: options.prefix }),\n client: options.client,\n }\n return s3(opts)\n }\n\n if (!options.accountId) {\n throw new Error('@noy-db/to-cloudflare-r2: provide either `client` or `accountId`.')\n }\n if (!options.accessKeyId || !options.secretAccessKey) {\n throw new Error('@noy-db/to-cloudflare-r2: `accessKeyId` and `secretAccessKey` are required (unless `client` is supplied).')\n }\n\n const endpoint = options.endpoint ?? r2EndpointFor(options.accountId)\n const config: S3ClientConfig = {\n region: R2_REGION,\n endpoint,\n credentials: {\n accessKeyId: options.accessKeyId,\n secretAccessKey: options.secretAccessKey,\n },\n forcePathStyle: true,\n }\n const built = new RealS3Client(config)\n const opts: Parameters<typeof s3>[0] = {\n bucket: options.bucket,\n ...(options.prefix !== undefined && { prefix: options.prefix }),\n client: built,\n }\n return { ...s3(opts), name: 'cloudflare-r2' }\n}\n"],"mappings":";AAyCA,SAAS,YAAY,oBAAoB;AACzC,SAAS,UAAU;AA0BnB,IAAM,YAAY;AAOX,SAAS,cAAc,WAA2B;AACvD,SAAO,WAAW,SAAS;AAC7B;AAOO,SAAS,GAAG,SAAgC;AACjD,MAAI,QAAQ,QAAQ;AAClB,UAAMA,QAAiC;AAAA,MACrC,QAAQ,QAAQ;AAAA,MAChB,GAAI,QAAQ,WAAW,UAAa,EAAE,QAAQ,QAAQ,OAAO;AAAA,MAC7D,QAAQ,QAAQ;AAAA,IAClB;AACA,WAAO,GAAGA,KAAI;AAAA,EAChB;AAEA,MAAI,CAAC,QAAQ,WAAW;AACtB,UAAM,IAAI,MAAM,mEAAmE;AAAA,EACrF;AACA,MAAI,CAAC,QAAQ,eAAe,CAAC,QAAQ,iBAAiB;AACpD,UAAM,IAAI,MAAM,2GAA2G;AAAA,EAC7H;AAEA,QAAM,WAAW,QAAQ,YAAY,cAAc,QAAQ,SAAS;AACpE,QAAM,SAAyB;AAAA,IAC7B,QAAQ;AAAA,IACR;AAAA,IACA,aAAa;AAAA,MACX,aAAa,QAAQ;AAAA,MACrB,iBAAiB,QAAQ;AAAA,IAC3B;AAAA,IACA,gBAAgB;AAAA,EAClB;AACA,QAAM,QAAQ,IAAI,aAAa,MAAM;AACrC,QAAM,OAAiC;AAAA,IACrC,QAAQ,QAAQ;AAAA,IAChB,GAAI,QAAQ,WAAW,UAAa,EAAE,QAAQ,QAAQ,OAAO;AAAA,IAC7D,QAAQ;AAAA,EACV;AACA,SAAO,EAAE,GAAG,GAAG,IAAI,GAAG,MAAM,gBAAgB;AAC9C;","names":["opts"]}
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@noy-db/to-cloudflare-r2",
3
+ "version": "0.1.0-pre.3",
4
+ "description": "Cloudflare R2 adapter for noy-db — S3-compatible object storage with zero egress fees. Thin wrapper around @noy-db/to-aws-s3 configured for the R2 endpoint. casAtomic: false (same caveat as S3).",
5
+ "license": "MIT",
6
+ "author": "vLannaAi <vicio@lanna.ai>",
7
+ "homepage": "https://github.com/vLannaAi/noy-db/tree/main/packages/to-cloudflare-r2#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/vLannaAi/noy-db.git",
11
+ "directory": "packages/to-cloudflare-r2"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/vLannaAi/noy-db/issues"
15
+ },
16
+ "type": "module",
17
+ "sideEffects": false,
18
+ "exports": {
19
+ ".": {
20
+ "import": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "require": {
25
+ "types": "./dist/index.d.cts",
26
+ "default": "./dist/index.cjs"
27
+ }
28
+ }
29
+ },
30
+ "main": "./dist/index.cjs",
31
+ "module": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "files": [
34
+ "dist",
35
+ "README.md",
36
+ "LICENSE"
37
+ ],
38
+ "engines": {
39
+ "node": ">=18.0.0"
40
+ },
41
+ "peerDependencies": {
42
+ "@aws-sdk/client-s3": "^3.0.0",
43
+ "@noy-db/to-aws-s3": "0.1.0-pre.3",
44
+ "@noy-db/hub": "0.1.0-pre.3"
45
+ },
46
+ "devDependencies": {
47
+ "@aws-sdk/client-s3": "^3.0.0",
48
+ "@types/node": "^22.0.0",
49
+ "@noy-db/hub": "0.1.0-pre.3",
50
+ "@noy-db/to-aws-s3": "0.1.0-pre.3"
51
+ },
52
+ "keywords": [
53
+ "noy-db",
54
+ "to-cloudflare-r2",
55
+ "cloudflare",
56
+ "r2",
57
+ "s3",
58
+ "storage"
59
+ ],
60
+ "publishConfig": {
61
+ "access": "public",
62
+ "tag": "latest"
63
+ },
64
+ "scripts": {
65
+ "build": "tsup",
66
+ "test": "vitest run",
67
+ "lint": "eslint src/",
68
+ "typecheck": "tsc --noEmit"
69
+ }
70
+ }