@cosmicdrift/kumiko-types 0.159.0 → 0.160.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.
@@ -0,0 +1,19 @@
1
+ export type FileHandle = {
2
+ readonly key: string;
3
+ read(): Promise<Uint8Array>;
4
+ write(data: Uint8Array, mimeType?: string): Promise<void>;
5
+ delete(): Promise<void>;
6
+ exists(): Promise<boolean>;
7
+ // Produce a handle for a derived key (e.g. a thumbnail). Does not touch
8
+ // storage; only computes the key. Writing to the derived handle is the
9
+ // caller's job.
10
+ derive(suffix: string): FileHandle;
11
+ };
12
+
13
+ // The `ctx.files` service — a factory that materialises a FileHandle for a
14
+ // storage key. One per request/event, bound to a single tenant: the provider
15
+ // is resolved per-tenant through file-foundation, so uploads, ctx.files and the
16
+ // GDPR jobs all hit the same store by construction.
17
+ export type FileContext = {
18
+ ref(key: string): FileHandle;
19
+ };
@@ -0,0 +1,7 @@
1
+ import type { FileStorageProvider } from "./file-storage-provider-types";
2
+ import type { TenantId } from "./identifiers";
3
+
4
+ // A bound, per-tenant provider resolver. One instance serves all tenants
5
+ // (tenantId is the call argument) — the single spine shared by upload routes,
6
+ // ctx.files and the GDPR jobs.
7
+ export type FileProviderResolver = (tenantId: TenantId) => Promise<FileStorageProvider>;
@@ -0,0 +1,39 @@
1
+ // Options for `getSignedUrl`. `contentDisposition` lets the caller hint the
2
+ // browser to download-with-name vs inline-display (maps to ResponseContent-
3
+ // Disposition on S3). Keep the option-bag small and additive; provider impls
4
+ // that don't support a given hint should ignore it rather than error.
5
+ export type SignedUrlOptions = {
6
+ readonly contentDisposition?: string;
7
+ };
8
+
9
+ // Options for `writeStream`. `mimeType` is a Content-Type hint analogous to
10
+ // `write`. `contentLength` is optional for providers that need a Length
11
+ // header (S3 multipart has a TransferManager and can work without it);
12
+ // local providers ignore both.
13
+ export type WriteStreamOptions = {
14
+ readonly mimeType?: string;
15
+ readonly contentLength?: number;
16
+ };
17
+
18
+ // Primitive storage contract: key+bytes in, bytes out. Metadata (fileName,
19
+ // mimeType, size) lives on the FileRef row — the provider only needs to
20
+ // shuttle bytes. `mimeType` on write() is a hint for providers that need a
21
+ // Content-Type header (S3/R2/…); local filesystems can ignore it.
22
+ //
23
+ // getSignedUrl is optional — providers without native presigned-URL support
24
+ // (filesystem) leave it undefined; the route then returns 501 and the
25
+ // client falls back to streaming via GET /files/:id. Callers must
26
+ // feature-detect via `typeof provider.getSignedUrl === "function"`.
27
+ export type FileStorageProvider = {
28
+ write(key: string, data: Uint8Array, mimeType?: string): Promise<void>;
29
+ writeStream(
30
+ key: string,
31
+ source: AsyncIterable<Uint8Array>,
32
+ options?: WriteStreamOptions,
33
+ ): Promise<void>;
34
+ read(key: string): Promise<Uint8Array>;
35
+ readStream(key: string): AsyncIterable<Uint8Array>;
36
+ delete(key: string): Promise<void>;
37
+ exists(key: string): Promise<boolean>;
38
+ getSignedUrl?(key: string, expiresInSeconds: number, options?: SignedUrlOptions): Promise<string>;
39
+ };