cloudrop 0.2.0 → 0.3.0

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/dist/react.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as CloudropError } from "./errors-CUxMmFAe.js";
2
- import { n as isList, t as createCloudropClient } from "./client-ePVHwvMv.js";
2
+ import { n as isList, t as createCloudropClient } from "./client-DxP3uv8V.js";
3
3
  import { useCallback, useEffect, useInsertionEffect, useRef, useState, useSyncExternalStore } from "react";
4
4
  // src/react/job-tracker.ts
5
5
  const endedOf = (job) => {
@@ -0,0 +1,81 @@
1
+ import { ClientOptions, CloudropClient } from "./client.js";
2
+ import { Cloudrop, CloudropStore, FetchLike, InferableCloudrop, StorageDriver, TransactionalStore } from "./index.js";
3
+ export interface TestBucketOptions {
4
+ /** Where the bucket is served publicly, such as "https://cdn.example.com", as in `r2({ publicUrl })`. Default none. */
5
+ publicUrl?: string;
6
+ /**
7
+ * The bucket's CORS configuration as S3 XML, for tests of `api.checkBucket`. Once `cors` or `lifecycle` is given, the
8
+ * other one reads as not configured; with neither, both read as refused, as with an R2 object token (M9-T6).
9
+ */
10
+ cors?: string;
11
+ /** The bucket's lifecycle configuration as S3 XML, for tests of `api.checkBucket`. */
12
+ lifecycle?: string;
13
+ }
14
+ /** An object as the test bucket stores it. */
15
+ export interface TestObject {
16
+ key: string;
17
+ size: number;
18
+ /** The stored Content-Type, or null. */
19
+ type: string | null;
20
+ /** The stored Content-Disposition, or null. */
21
+ disposition: string | null;
22
+ /** The `x-amz-meta-*` headers, without the prefix: `cloudrop-id` is the file's id. */
23
+ metadata: Record<string, string>;
24
+ /** How many parts a multipart upload stored it in; null for a single PUT. */
25
+ parts: number | null;
26
+ /** A copy of the stored bytes. */
27
+ body: Uint8Array;
28
+ uploadedAt: Date;
29
+ }
30
+ /** An in-process bucket that keeps R2's measured rules and checks every request's signature. */
31
+ export interface TestBucket {
32
+ /** The driver to pass to `createCloudrop({ storage })`: `r2()` pointed at this bucket. */
33
+ readonly storage: StorageDriver;
34
+ /**
35
+ * Reaches the bucket with a signed request, such as a URL from `api.getUrl`. A `publicUrl` is not served: read a
36
+ * public file with `object(key)`.
37
+ */
38
+ readonly fetch: FetchLike;
39
+ /** The object stored under `key`, or null. */
40
+ object(key: string): TestObject | null;
41
+ /** Every stored key, sorted. */
42
+ keys(): string[];
43
+ /** Multipart uploads started and neither completed nor aborted. */
44
+ pendingUploads(): number;
45
+ }
46
+ export interface TestClientOptions {
47
+ /** The test bucket the server stores in: the client's presigned PUTs go there. */
48
+ bucket: TestBucket;
49
+ /**
50
+ * Headers for every request to the server, never to the bucket: the session a browser's cookies would carry, such as
51
+ * `{ cookie: "session=alice" }`, or a function that returns them before each request. `origin` is always the page's
52
+ * own, `http://localhost`, as a browser sends it.
53
+ */
54
+ headers?: ClientOptions["headers"];
55
+ /** The server's `basePath`, a path without a trailing slash. Default "/api/cloudrop". */
56
+ basePath?: string;
57
+ }
58
+ /** A bucket for tests, with no network: pass `bucket.storage` to `createCloudrop`, then read what landed. */
59
+ export declare function testBucket(options?: TestBucketOptions | null): TestBucket;
60
+ /**
61
+ * The real `cloudrop/client` client, wired to `cloudrop.handler` and the test bucket in-process. Requests to the server
62
+ * arrive as a same-origin page sends them; bucket PUTs go through fetch, never XMLHttpRequest, and nothing is kept
63
+ * for resuming after a reload (M9-T4, M9-T5). Throws INVALID_CONFIG without a bucket or with a basePath that is not
64
+ * a path.
65
+ */
66
+ export declare function testClient<TCloudrop extends InferableCloudrop>(cloudrop: TCloudrop & Pick<Cloudrop, "handler">, options: TestClientOptions): CloudropClient<TCloudrop>;
67
+ /**
68
+ * An in-memory database store with the guarantees of the shipped adapters, for tests of an app that uses `store`:
69
+ * owners, `quota`, `afterComplete`, `replace` and the store's file API. With `{ transaction: true }` it has
70
+ * `transaction` and `store.route`, like `sqlStore(executor, { transaction: true })`; its `tx` is undefined, since
71
+ * there is no database to write through (M9-T7).
72
+ */
73
+ export declare function memoryStore(options: {
74
+ transaction: true;
75
+ }): TransactionalStore<undefined>;
76
+ export declare function memoryStore(options?: {
77
+ transaction?: false;
78
+ } | null): CloudropStore;
79
+ export declare function memoryStore(options?: {
80
+ transaction?: boolean;
81
+ } | null): CloudropStore<undefined>;