@dimah-s3/db 1.7.1 → 2.0.0-beta.1
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/README.md +62 -17
- package/dist/adapters/drizzle.d.ts +8 -0
- package/dist/adapters/drizzle.d.ts.map +1 -0
- package/dist/adapters/drizzle.js +3 -0
- package/dist/adapters/drizzle.js.map +1 -0
- package/dist/adapters/kysely.d.ts +7 -0
- package/dist/adapters/kysely.d.ts.map +1 -0
- package/dist/adapters/kysely.js +3 -0
- package/dist/adapters/kysely.js.map +1 -0
- package/dist/adapters/prisma.d.ts +7 -0
- package/dist/adapters/prisma.d.ts.map +1 -0
- package/dist/adapters/prisma.js +3 -0
- package/dist/adapters/prisma.js.map +1 -0
- package/dist/cli.d.ts +32 -4
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +135 -4
- package/dist/cli.js.map +1 -1
- package/dist/client/db-client.d.ts +9 -85
- package/dist/client/db-client.d.ts.map +1 -1
- package/dist/client/db-object-source.d.ts +25 -0
- package/dist/client/db-object-source.d.ts.map +1 -0
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +96 -42
- package/dist/client/index.js.map +1 -1
- package/dist/drizzle/mysql.d.ts +1025 -0
- package/dist/drizzle/mysql.d.ts.map +1 -0
- package/dist/drizzle/mysql.js +117 -0
- package/dist/drizzle/mysql.js.map +1 -0
- package/dist/drizzle/pg.d.ts +964 -0
- package/dist/drizzle/pg.d.ts.map +1 -0
- package/dist/drizzle/pg.js +98 -0
- package/dist/drizzle/pg.js.map +1 -0
- package/dist/drizzle/shared.d.ts +7 -0
- package/dist/drizzle/shared.d.ts.map +1 -0
- package/dist/drizzle/sqlite.d.ts +1024 -0
- package/dist/drizzle/sqlite.d.ts.map +1 -0
- package/dist/drizzle/sqlite.js +101 -0
- package/dist/drizzle/sqlite.js.map +1 -0
- package/dist/folder-path.d.ts +32 -0
- package/dist/folder-path.d.ts.map +1 -0
- package/dist/fuma-db.d.ts +30 -9
- package/dist/fuma-db.d.ts.map +1 -1
- package/dist/index.d.ts +9 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1419 -623
- package/dist/index.js.map +1 -1
- package/dist/plugin/create-database-endpoints.d.ts +105 -21
- package/dist/plugin/create-database-endpoints.d.ts.map +1 -1
- package/dist/plugin/create-database-lifecycle-hooks.d.ts +37 -19
- package/dist/plugin/create-database-lifecycle-hooks.d.ts.map +1 -1
- package/dist/plugin/db.d.ts +29 -118
- package/dist/plugin/db.d.ts.map +1 -1
- package/dist/plugin/object-access.d.ts +46 -0
- package/dist/plugin/object-access.d.ts.map +1 -0
- package/dist/plugin/public-stores.d.ts +33 -0
- package/dist/plugin/public-stores.d.ts.map +1 -0
- package/dist/plugin/purge.d.ts +49 -0
- package/dist/plugin/purge.d.ts.map +1 -0
- package/dist/plugin/quota.d.ts +25 -0
- package/dist/plugin/quota.d.ts.map +1 -0
- package/dist/plugin/schemas.d.ts +69 -0
- package/dist/plugin/schemas.d.ts.map +1 -0
- package/dist/plugin/scope.d.ts +31 -0
- package/dist/plugin/scope.d.ts.map +1 -0
- package/dist/plugin/to-db-client-object.d.ts +8 -4
- package/dist/plugin/to-db-client-object.d.ts.map +1 -1
- package/dist/schema/schema.d.ts +73 -0
- package/dist/schema/schema.d.ts.map +1 -0
- package/dist/standard-schema.d.ts +42 -0
- package/dist/standard-schema.d.ts.map +1 -0
- package/dist/store/create-db-store.d.ts +17 -0
- package/dist/store/create-db-store.d.ts.map +1 -0
- package/dist/store/folder-store.d.ts +36 -0
- package/dist/store/folder-store.d.ts.map +1 -0
- package/dist/store/list-cursor.d.ts +26 -4
- package/dist/store/list-cursor.d.ts.map +1 -1
- package/dist/store/map-row.d.ts +17 -8
- package/dist/store/map-row.d.ts.map +1 -1
- package/dist/store/object-store.d.ts +208 -0
- package/dist/store/object-store.d.ts.map +1 -0
- package/dist/store/schema-version.d.ts +7 -0
- package/dist/store/schema-version.d.ts.map +1 -0
- package/dist/types/client.d.ts +209 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/plugin.d.ts +112 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/storage-object.d.ts +40 -85
- package/dist/types/storage-object.d.ts.map +1 -1
- package/package.json +53 -11
- package/prisma/dimah-s3.prisma +80 -0
- package/sql/mysql.sql +59 -0
- package/sql/pg.sql +53 -0
- package/sql/sqlite.sql +54 -0
- package/src/drizzle/mysql.ts +172 -0
- package/src/drizzle/pg.ts +140 -0
- package/src/drizzle/sqlite.ts +144 -0
- package/dist/client/db-object-list-accessors.d.ts +0 -36
- package/dist/client/db-object-list-accessors.d.ts.map +0 -1
- package/dist/client/db-object-query.d.ts +0 -40
- package/dist/client/db-object-query.d.ts.map +0 -1
- package/dist/errors.d.ts +0 -6
- package/dist/errors.d.ts.map +0 -1
- package/dist/hooks/create-object-access-guard.d.ts +0 -51
- package/dist/hooks/create-object-access-guard.d.ts.map +0 -1
- package/dist/hooks/create-quota-guard.d.ts +0 -28
- package/dist/hooks/create-quota-guard.d.ts.map +0 -1
- package/dist/jobs/purge-stale-pending.d.ts +0 -31
- package/dist/jobs/purge-stale-pending.d.ts.map +0 -1
- package/dist/plugin/list-query-schema.d.ts +0 -21
- package/dist/plugin/list-query-schema.d.ts.map +0 -1
- package/dist/plugin/memoize-scope-resolver.d.ts +0 -8
- package/dist/plugin/memoize-scope-resolver.d.ts.map +0 -1
- package/dist/schema/v1.d.ts +0 -31
- package/dist/schema/v1.d.ts.map +0 -1
- package/dist/store/storage-object-store.d.ts +0 -137
- package/dist/store/storage-object-store.d.ts.map +0 -1
- package/src/schema/examples/README.md +0 -10
- package/src/schema/examples/drizzle.ts +0 -92
- package/src/schema/examples/schema.prisma +0 -55
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
/** Most rows one page of `GET /db/objects` returns. */
|
|
3
|
+
export declare const DB_LIST_MAX_LIMIT = 100;
|
|
4
|
+
/**
|
|
5
|
+
* Query of `GET /db/objects`. `folder` is a wire folder (`""` is the root)
|
|
6
|
+
* that the endpoint validates, so a bad path is `FOLDER_INVALID`. Blank
|
|
7
|
+
* `search`, `contentType`, and `cursor` values are omitted.
|
|
8
|
+
*/
|
|
9
|
+
export declare const dbListQuerySchema: z.ZodObject<{
|
|
10
|
+
folder: z.ZodOptional<z.ZodString>;
|
|
11
|
+
route: z.ZodOptional<z.ZodString>;
|
|
12
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
13
|
+
active: "active";
|
|
14
|
+
deleted: "deleted";
|
|
15
|
+
pending: "pending";
|
|
16
|
+
}>>;
|
|
17
|
+
contentType: z.ZodPipe<z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>, z.ZodOptional<z.ZodString>>;
|
|
18
|
+
search: z.ZodPipe<z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>, z.ZodOptional<z.ZodString>>;
|
|
19
|
+
sort: z.ZodOptional<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
20
|
+
field: z.ZodEnum<{
|
|
21
|
+
createdAt: "createdAt";
|
|
22
|
+
filename: "filename";
|
|
23
|
+
size: "size";
|
|
24
|
+
updatedAt: "updatedAt";
|
|
25
|
+
}>;
|
|
26
|
+
direction: z.ZodEnum<{
|
|
27
|
+
asc: "asc";
|
|
28
|
+
desc: "desc";
|
|
29
|
+
}>;
|
|
30
|
+
}, z.core.$strip>]>, z.ZodObject<{
|
|
31
|
+
field: z.ZodEnum<{
|
|
32
|
+
createdAt: "createdAt";
|
|
33
|
+
filename: "filename";
|
|
34
|
+
size: "size";
|
|
35
|
+
updatedAt: "updatedAt";
|
|
36
|
+
}>;
|
|
37
|
+
direction: z.ZodEnum<{
|
|
38
|
+
asc: "asc";
|
|
39
|
+
desc: "desc";
|
|
40
|
+
}>;
|
|
41
|
+
}, z.core.$strip>>>;
|
|
42
|
+
limit: z.ZodDefault<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>, z.ZodInt>>;
|
|
43
|
+
cursor: z.ZodPipe<z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>, z.ZodOptional<z.ZodString>>;
|
|
44
|
+
}, z.core.$strict>;
|
|
45
|
+
/** Query of `GET /db/object`. */
|
|
46
|
+
export declare const dbObjectQuerySchema: z.ZodObject<{
|
|
47
|
+
key: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
48
|
+
bucket: z.ZodOptional<z.ZodString>;
|
|
49
|
+
}, z.core.$strict>;
|
|
50
|
+
/**
|
|
51
|
+
* Body of `PATCH /db/object`. `folder` is validated by the endpoint; `null`
|
|
52
|
+
* and `""` are the root. `attributes` are checked by the plugin's
|
|
53
|
+
* `attributes.schema`.
|
|
54
|
+
*/
|
|
55
|
+
export declare const dbUpdateObjectBodySchema: z.ZodObject<{
|
|
56
|
+
key: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
57
|
+
bucket: z.ZodOptional<z.ZodString>;
|
|
58
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
59
|
+
folder: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
60
|
+
attributes: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
61
|
+
}, z.core.$strict>;
|
|
62
|
+
/**
|
|
63
|
+
* Body of `POST /db/folder` and query of `DELETE /db/folder`. The endpoint
|
|
64
|
+
* validates `path`, so a bad path is `FOLDER_INVALID`.
|
|
65
|
+
*/
|
|
66
|
+
export declare const dbFolderInputSchema: z.ZodObject<{
|
|
67
|
+
path: z.ZodString;
|
|
68
|
+
}, z.core.$strict>;
|
|
69
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/plugin/schemas.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAGzB,uDAAuD;AACvD,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAuDrC;;;;GAIG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAiB5B,CAAC;AAEH,iCAAiC;AACjC,eAAO,MAAM,mBAAmB;;;kBAG9B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,wBAAwB;;;;;;kBAOnC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;kBAE9B,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DimahS3Locals } from "@dimah-s3/server";
|
|
2
|
+
import type { DbPluginOptions, ScopeContext } from "../types/plugin.js";
|
|
3
|
+
/** The call a scope is resolved for: its request and the guards' `locals`. */
|
|
4
|
+
export type ScopeCall = {
|
|
5
|
+
request: Request;
|
|
6
|
+
locals: DimahS3Locals;
|
|
7
|
+
};
|
|
8
|
+
/** What a scope is resolved for: the operation and, when known, the route. */
|
|
9
|
+
export type ScopeTarget = Pick<ScopeContext, "operation" | "route">;
|
|
10
|
+
/** A {@link ScopeContext} whose scope is resolved. */
|
|
11
|
+
export type ResolvedScope<TSession = undefined> = ScopeContext<TSession> & {
|
|
12
|
+
scope: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Resolves the scope of a call.
|
|
16
|
+
* @throws `UNAUTHORIZED` when `resolveScope` returns `null`.
|
|
17
|
+
*/
|
|
18
|
+
export type ScopeResolver<TSession = undefined> = (call: ScopeCall, target: ScopeTarget) => Promise<ResolvedScope<TSession>>;
|
|
19
|
+
export type CreateScopeResolverOptions<TSession> = Pick<DbPluginOptions<TSession>, "getSession" | "resolveScope">;
|
|
20
|
+
/**
|
|
21
|
+
* Wraps the plugin's `getSession` and `resolveScope`. `getSession` runs at
|
|
22
|
+
* most once per `Request`. `resolveScope` runs once per call, operation,
|
|
23
|
+
* and route. A call is its `locals` object: the server creates one per
|
|
24
|
+
* operation and hands it to every hook of that operation. So the guard and
|
|
25
|
+
* the lifecycle hooks of one call share a scope, and it sees the `locals`
|
|
26
|
+
* of the first hook that asked. Two `s3.api` calls never share one, even
|
|
27
|
+
* when they pass the same `Request`. Each key of a `deleteMany` gets its
|
|
28
|
+
* own `locals`, so its guard's `locals` reach the scope too.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createScopeResolver<TSession>(options: CreateScopeResolverOptions<TSession>): ScopeResolver<TSession>;
|
|
31
|
+
//# sourceMappingURL=scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/plugin/scope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEpE,8EAA8E;AAC9E,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC;AAEpE,sDAAsD;AACtD,MAAM,MAAM,aAAa,CAAC,QAAQ,GAAG,SAAS,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG;IACzE,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,QAAQ,GAAG,SAAS,IAAI,CAChD,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,WAAW,KAChB,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;AAEtC,MAAM,MAAM,0BAA0B,CAAC,QAAQ,IAAI,IAAI,CACrD,eAAe,CAAC,QAAQ,CAAC,EACzB,YAAY,GAAG,cAAc,CAC9B,CAAC;AAgBF;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAC1C,OAAO,EAAE,0BAA0B,CAAC,QAAQ,CAAC,GAC5C,aAAa,CAAC,QAAQ,CAAC,CAmCzB"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DbClientFolder, DbClientObject } from "../types/client.js";
|
|
2
|
+
import type { StorageFolder, StorageObject } from "../types/storage-object.js";
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
4
|
+
* Maps a store row to the browser wire shape. Drops server-only fields
|
|
5
|
+
* (`scope`, `eTag`, `s3Metadata`, `acl`, upload state). `toClient` maps the
|
|
6
|
+
* stored attributes; without it the browser sees them as stored.
|
|
5
7
|
*/
|
|
6
|
-
export declare function toDbClientObject(object: StorageObject): DbClientObject
|
|
8
|
+
export declare function toDbClientObject<TAttributes, TClientAttributes = TAttributes>(object: StorageObject<TAttributes>, toClient?: (attributes: TAttributes) => TClientAttributes): DbClientObject<TClientAttributes>;
|
|
9
|
+
/** Maps a `storage_folder` row to the browser wire shape. */
|
|
10
|
+
export declare function toDbClientFolder(folder: StorageFolder): DbClientFolder;
|
|
7
11
|
//# sourceMappingURL=to-db-client-object.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-db-client-object.d.ts","sourceRoot":"","sources":["../../src/plugin/to-db-client-object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"to-db-client-object.d.ts","sourceRoot":"","sources":["../../src/plugin/to-db-client-object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EAEf,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE3E;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,iBAAiB,GAAG,WAAW,EAC3E,MAAM,EAAE,aAAa,CAAC,WAAW,CAAC,EAClC,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,WAAW,KAAK,iBAAiB,GACxD,cAAc,CAAC,iBAAiB,CAAC,CAyBnC;AAED,6DAA6D;AAC7D,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,cAAc,CAOtE"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type Column } from "fumadb/schema";
|
|
2
|
+
/** A secondary index, by SQL table and column names. */
|
|
3
|
+
export type SchemaIndex = {
|
|
4
|
+
name: string;
|
|
5
|
+
table: "storage_object" | "storage_folder";
|
|
6
|
+
columns: readonly string[];
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Secondary indexes. FumaDB cannot declare them, so {@link dbSchema}'s
|
|
10
|
+
* migration, the SQL files, the Drizzle tables, and the Prisma schema carry
|
|
11
|
+
* them.
|
|
12
|
+
*/
|
|
13
|
+
export declare const schemaIndexes: readonly SchemaIndex[];
|
|
14
|
+
/**
|
|
15
|
+
* FumaDB runs `up` only when migrating from the previous entry, and skips
|
|
16
|
+
* `up` on the first one. This empty entry exists so {@link dbSchema} can
|
|
17
|
+
* create the indexes on a new database. A finished database is at
|
|
18
|
+
* {@link dbSchema}.
|
|
19
|
+
*/
|
|
20
|
+
export declare const PREDECESSOR_VERSION = "0.0.1";
|
|
21
|
+
export declare const predecessor: import("fumadb/schema").Schema<"0.0.1", {}>;
|
|
22
|
+
/**
|
|
23
|
+
* The @dimah-s3/db schema, version `2.0.0`. The migration creates the
|
|
24
|
+
* secondary indexes after the tables, because FumaDB cannot declare them.
|
|
25
|
+
*/
|
|
26
|
+
export declare const dbSchema: import("fumadb/schema").Schema<"2.0.0", {
|
|
27
|
+
storageObject: import("fumadb/schema").Table<{
|
|
28
|
+
id: import("fumadb/schema").IdColumn<"varchar(255)", string | null, string>;
|
|
29
|
+
/** Owner, for example `user:123` or `org:acme`. */
|
|
30
|
+
scope: Column<"string", string, string>;
|
|
31
|
+
bucket: Column<"string", string, string>;
|
|
32
|
+
key: Column<"string", string, string>;
|
|
33
|
+
/** Named dimah-s3 route that created the object. */
|
|
34
|
+
route: Column<"string", string, string>;
|
|
35
|
+
/** Logical folder path. `null` is the root. */
|
|
36
|
+
folder: Column<"string", string | null, string | null>;
|
|
37
|
+
filename: Column<"string", string, string>;
|
|
38
|
+
contentType: Column<"string", string | null, string | null>;
|
|
39
|
+
/** Verified size from HeadObject, set on confirm. */
|
|
40
|
+
size: Column<"bigint", number | null, string | number | bigint | null>;
|
|
41
|
+
/** Size the client declared before confirm. Quota counts it while pending. */
|
|
42
|
+
declaredSize: Column<"bigint", number | null, string | number | bigint | null>;
|
|
43
|
+
eTag: Column<"string", string | null, string | null>;
|
|
44
|
+
status: Column<"string", string, string>;
|
|
45
|
+
/** S3 user metadata of the verified object. */
|
|
46
|
+
s3Metadata: Column<"json", unknown, unknown>;
|
|
47
|
+
/** App attributes, validated by the plugin's `attributes.schema`. */
|
|
48
|
+
attributes: Column<"json", unknown, unknown>;
|
|
49
|
+
acl: Column<"string", string | null, string | null>;
|
|
50
|
+
/** Multipart upload ID while the row is pending. */
|
|
51
|
+
uploadId: Column<"string", string | null, string | null>;
|
|
52
|
+
/** Token of the upload ticket that wrote the row. Confirm and purge match it. */
|
|
53
|
+
uploadToken: Column<"string", string | null, string | null>;
|
|
54
|
+
/** Confirm deadline of a pending row (the upload ticket's expiry). */
|
|
55
|
+
expiresAt: Column<"timestamp", Date | null, Date | null>;
|
|
56
|
+
confirmedAt: Column<"timestamp", Date | null, Date | null>;
|
|
57
|
+
createdAt: Column<"timestamp", Date | null, Date>;
|
|
58
|
+
updatedAt: Column<"timestamp", Date | null, Date>;
|
|
59
|
+
deletedAt: Column<"timestamp", Date | null, Date | null>;
|
|
60
|
+
}, {}>;
|
|
61
|
+
storageFolder: import("fumadb/schema").Table<{
|
|
62
|
+
id: import("fumadb/schema").IdColumn<"varchar(255)", string | null, string>;
|
|
63
|
+
scope: Column<"string", string, string>;
|
|
64
|
+
/** Full folder path. */
|
|
65
|
+
path: Column<"string", string, string>;
|
|
66
|
+
/** Path of the containing folder. `null` is the root. */
|
|
67
|
+
parent: Column<"string", string | null, string | null>;
|
|
68
|
+
/** Last segment of `path`. */
|
|
69
|
+
name: Column<"string", string, string>;
|
|
70
|
+
createdAt: Column<"timestamp", Date | null, Date>;
|
|
71
|
+
}, {}>;
|
|
72
|
+
}>;
|
|
73
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAsE7E,wDAAwD;AACxD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,CAAC;IAC3C,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,WAAW,EA+B/C,CAAC;AAIF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAE3C,eAAO,MAAM,WAAW,6CAGtB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,QAAQ;;;QA9GnB,mDAAmD;;;;QAInD,oDAAoD;;QAEpD,+CAA+C;;;;QAI/C,qDAAqD;;QAErD,8EAA8E;;;;QAI9E,+CAA+C;;QAE/C,qEAAqE;;;QAGrE,oDAAoD;;QAEpD,iFAAiF;;QAEjF,sEAAsE;;;;;;;;;;QAYtE,wBAAwB;;QAExB,yDAAyD;;QAEzD,8BAA8B;;;;EAoF9B,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Standard Schema v1 interface (https://standardschema.dev). Zod,
|
|
3
|
+
* Valibot, ArkType, and other validators implement it, so `attributes.schema`
|
|
4
|
+
* accepts any of them without a dependency on one.
|
|
5
|
+
*/
|
|
6
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
7
|
+
readonly "~standard": StandardSchemaProps<Input, Output>;
|
|
8
|
+
}
|
|
9
|
+
/** The `~standard` property of a {@link StandardSchemaV1}. */
|
|
10
|
+
export interface StandardSchemaProps<Input = unknown, Output = Input> {
|
|
11
|
+
readonly version: 1;
|
|
12
|
+
readonly vendor: string;
|
|
13
|
+
readonly validate: (value: unknown) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>>;
|
|
14
|
+
readonly types?: StandardSchemaTypes<Input, Output> | undefined;
|
|
15
|
+
}
|
|
16
|
+
export type StandardSchemaResult<Output> = StandardSchemaSuccess<Output> | StandardSchemaFailure;
|
|
17
|
+
export interface StandardSchemaSuccess<Output> {
|
|
18
|
+
readonly value: Output;
|
|
19
|
+
readonly issues?: undefined;
|
|
20
|
+
}
|
|
21
|
+
export interface StandardSchemaFailure {
|
|
22
|
+
readonly issues: readonly StandardSchemaIssue[];
|
|
23
|
+
}
|
|
24
|
+
export interface StandardSchemaIssue {
|
|
25
|
+
readonly message: string;
|
|
26
|
+
readonly path?: readonly (PropertyKey | StandardSchemaPathSegment)[] | undefined;
|
|
27
|
+
}
|
|
28
|
+
export interface StandardSchemaPathSegment {
|
|
29
|
+
readonly key: PropertyKey;
|
|
30
|
+
}
|
|
31
|
+
export interface StandardSchemaTypes<Input = unknown, Output = Input> {
|
|
32
|
+
readonly input: Input;
|
|
33
|
+
readonly output: Output;
|
|
34
|
+
}
|
|
35
|
+
/** Runs `schema` on `value`, whether the validator is sync or async. */
|
|
36
|
+
export declare function validateStandardSchema<Output>(schema: StandardSchemaV1<unknown, Output>, value: unknown): Promise<StandardSchemaResult<Output>>;
|
|
37
|
+
/**
|
|
38
|
+
* One line for the first issue, prefixed with its dotted path when it has
|
|
39
|
+
* one (`title: Required`). Fits the `VALIDATION_ERROR` `issue` param.
|
|
40
|
+
*/
|
|
41
|
+
export declare function formatStandardIssue(issues: readonly StandardSchemaIssue[]): string;
|
|
42
|
+
//# sourceMappingURL=standard-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard-schema.d.ts","sourceRoot":"","sources":["../src/standard-schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;IAC/D,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;CAC1D;AAED,8DAA8D;AAC9D,MAAM,WAAW,mBAAmB,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;IAClE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,CACjB,KAAK,EAAE,OAAO,KACX,oBAAoB,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1E,QAAQ,CAAC,KAAK,CAAC,EAAE,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;CACjE;AAED,MAAM,MAAM,oBAAoB,CAAC,MAAM,IACrC,qBAAqB,CAAC,MAAM,CAAC,GAAG,qBAAqB,CAAC;AAExD,MAAM,WAAW,qBAAqB,CAAC,MAAM;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;CAC7B;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,MAAM,EAAE,SAAS,mBAAmB,EAAE,CAAC;CACjD;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EACZ,SAAS,CAAC,WAAW,GAAG,yBAAyB,CAAC,EAAE,GAAG,SAAS,CAAC;CACpE;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;CAC3B;AAED,MAAM,WAAW,mBAAmB,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;IAClE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,wEAAwE;AACxE,wBAAsB,sBAAsB,CAAC,MAAM,EACjD,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,EACzC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAEvC;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,mBAAmB,EAAE,GACrC,MAAM,CASR"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type DimahS3DbClient } from "../fuma-db.js";
|
|
2
|
+
import { type StorageFolderStore } from "./folder-store";
|
|
3
|
+
import { type StorageObjectStore } from "./object-store";
|
|
4
|
+
/** The stores over one FumaDB client. */
|
|
5
|
+
export type DbStore<TAttributes = never> = {
|
|
6
|
+
objects: StorageObjectStore<TAttributes>;
|
|
7
|
+
folders: StorageFolderStore;
|
|
8
|
+
/** Throws unless the database is at the schema the stores use. */
|
|
9
|
+
checkSchema: () => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Creates the object and folder stores. The first query checks the schema
|
|
13
|
+
* version, so a database at another version throws instead of being read
|
|
14
|
+
* with the wrong columns. A failed check runs again on the next query.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createDbStore<TAttributes = never>(client: DimahS3DbClient): DbStore<TAttributes>;
|
|
17
|
+
//# sourceMappingURL=create-db-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-db-store.d.ts","sourceRoot":"","sources":["../../src/store/create-db-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAqB,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAqB,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAG5E,yCAAyC;AACzC,MAAM,MAAM,OAAO,CAAC,WAAW,GAAG,KAAK,IAAI;IACzC,OAAO,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAC;IACzC,OAAO,EAAE,kBAAkB,CAAC;IAC5B,kEAAkE;IAClE,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,WAAW,GAAG,KAAK,EAC/C,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,WAAW,CAAC,CAkBtB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { StorageFolder } from "../types/storage-object.js";
|
|
2
|
+
import { type GetDbOrm } from "./object-store";
|
|
3
|
+
/** Most child folders `children` returns when `limit` is not given. */
|
|
4
|
+
export declare const DEFAULT_FOLDER_CHILDREN_LIMIT = 1000;
|
|
5
|
+
/**
|
|
6
|
+
* Data access for the `storage_folder` table. Paths are normalized folder
|
|
7
|
+
* paths (see `parseFolder`); the root (`null`) is never stored.
|
|
8
|
+
*/
|
|
9
|
+
export type StorageFolderStore = {
|
|
10
|
+
/** Loads one folder. */
|
|
11
|
+
find: (scope: string, path: string) => Promise<StorageFolder | null>;
|
|
12
|
+
/** Direct child folders of `parent` (`null` is the root), by name. */
|
|
13
|
+
children: (scope: string, parent: string | null, options?: {
|
|
14
|
+
limit?: number;
|
|
15
|
+
}) => Promise<StorageFolder[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Creates `path` and every missing ancestor, so it also restores an
|
|
18
|
+
* ancestor that a concurrent delete removed. Safe to call concurrently.
|
|
19
|
+
* The root (`null`) needs nothing.
|
|
20
|
+
*/
|
|
21
|
+
ensure: (scope: string, path: string | null) => Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Creates `path` and every missing ancestor.
|
|
24
|
+
* @throws `FOLDER_EXISTS` when the folder already exists.
|
|
25
|
+
*/
|
|
26
|
+
create: (scope: string, path: string) => Promise<StorageFolder>;
|
|
27
|
+
/**
|
|
28
|
+
* Removes an empty folder. Removing a missing folder does nothing.
|
|
29
|
+
* @throws `FOLDER_NOT_EMPTY` when it has child folders, or active or
|
|
30
|
+
* pending objects.
|
|
31
|
+
*/
|
|
32
|
+
delete: (scope: string, path: string) => Promise<void>;
|
|
33
|
+
};
|
|
34
|
+
/** Creates the `storage_folder` store over `getOrm`. */
|
|
35
|
+
export declare function createFolderStore(getOrm: GetDbOrm): StorageFolderStore;
|
|
36
|
+
//# sourceMappingURL=folder-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"folder-store.d.ts","sourceRoot":"","sources":["../../src/store/folder-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAA0B,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEvE,uEAAuE;AACvE,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAElD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,wBAAwB;IACxB,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;IACrE,sEAAsE;IACtE,QAAQ,EAAE,CACR,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,KACzB,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAC9B;;;;OAIG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D;;;OAGG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IAChE;;;;OAIG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD,CAAC;AAYF,wDAAwD;AACxD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,QAAQ,GAAG,kBAAkB,CAoHtE"}
|
|
@@ -1,6 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { DbListSort } from "../types/client.js";
|
|
2
|
+
import type { StorageObject, StorageObjectStatus } from "../types/storage-object.js";
|
|
3
|
+
/** Listing order when none is given: newest first. */
|
|
4
|
+
export declare const DEFAULT_LIST_SORT: DbListSort;
|
|
5
|
+
/** What a listing is filtered and ordered by. A cursor is only valid for these. */
|
|
6
|
+
export type ListCursorFilters = {
|
|
7
|
+
/** `undefined` lists every folder; `null` is the root. */
|
|
8
|
+
folder: string | null | undefined;
|
|
9
|
+
search: string | undefined;
|
|
10
|
+
status: StorageObjectStatus;
|
|
11
|
+
route: string | undefined;
|
|
12
|
+
contentType: string | undefined;
|
|
13
|
+
sort: DbListSort;
|
|
14
|
+
};
|
|
15
|
+
/** Position after one row: its sort value (`null` when it has none) and `id`. */
|
|
16
|
+
export type ListCursor = {
|
|
17
|
+
value: Date | number | string | null;
|
|
4
18
|
id: string;
|
|
5
|
-
}
|
|
19
|
+
};
|
|
20
|
+
/** Encodes the position after `object` in a listing under `filters`. */
|
|
21
|
+
export declare function encodeListCursor(filters: ListCursorFilters, object: StorageObject<unknown>): string;
|
|
22
|
+
/**
|
|
23
|
+
* Decodes a cursor for a listing under `filters`. Returns `null` when the
|
|
24
|
+
* cursor is malformed or was made under other filters, so the listing
|
|
25
|
+
* starts again at the first row.
|
|
26
|
+
*/
|
|
27
|
+
export declare function decodeListCursor(cursor: string, filters: ListCursorFilters): ListCursor | null;
|
|
6
28
|
//# sourceMappingURL=list-cursor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-cursor.d.ts","sourceRoot":"","sources":["../../src/store/list-cursor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"list-cursor.d.ts","sourceRoot":"","sources":["../../src/store/list-cursor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAmB,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAEhC,sDAAsD;AACtD,eAAO,MAAM,iBAAiB,EAAE,UAG/B,CAAC;AAEF,mFAAmF;AACnF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,0DAA0D;IAC1D,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAClC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,MAAM,EAAE,mBAAmB,CAAC;IAC5B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,IAAI,EAAE,UAAU,CAAC;CAClB,CAAC;AAEF,iFAAiF;AACjF,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACrC,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAqCF,wEAAwE;AACxE,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,GAC7B,MAAM,CAQR;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,iBAAiB,GACzB,UAAU,GAAG,IAAI,CAYnB"}
|
package/dist/store/map-row.d.ts
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
import type { StorageObject } from "../types/storage-object.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* A byte count as a driver returns it: a number, a bigint, or a string
|
|
4
|
+
* (PostgreSQL int8).
|
|
5
|
+
*/
|
|
6
|
+
type ByteCount = number | bigint | string | null;
|
|
7
|
+
/** Raw `storage_object` row as the FumaDB ORM returns it. */
|
|
3
8
|
export type StorageObjectRow = {
|
|
4
9
|
id: string;
|
|
5
10
|
scope: string;
|
|
6
11
|
bucket: string;
|
|
7
12
|
key: string;
|
|
8
13
|
route: string;
|
|
14
|
+
folder: string | null;
|
|
15
|
+
filename: string;
|
|
9
16
|
contentType: string | null;
|
|
10
|
-
size:
|
|
17
|
+
size: ByteCount;
|
|
18
|
+
declaredSize: ByteCount;
|
|
11
19
|
eTag: string | null;
|
|
12
|
-
filename: string | null;
|
|
13
20
|
status: string;
|
|
14
|
-
|
|
21
|
+
s3Metadata: unknown;
|
|
22
|
+
attributes: unknown;
|
|
15
23
|
acl: string | null;
|
|
16
24
|
uploadId: string | null;
|
|
17
|
-
|
|
18
|
-
confirmedAt: Date | null;
|
|
25
|
+
uploadToken: string | null;
|
|
19
26
|
expiresAt: Date | null;
|
|
27
|
+
confirmedAt: Date | null;
|
|
20
28
|
createdAt: Date;
|
|
21
29
|
updatedAt: Date;
|
|
22
30
|
deletedAt: Date | null;
|
|
23
31
|
};
|
|
24
|
-
/**
|
|
25
|
-
export declare function mapStorageObjectRow(row: StorageObjectRow): StorageObject
|
|
32
|
+
/** Normalizes a raw row: sizes become numbers, JSON columns are cast. */
|
|
33
|
+
export declare function mapStorageObjectRow<TAttributes = never>(row: StorageObjectRow): StorageObject<TAttributes>;
|
|
34
|
+
export {};
|
|
26
35
|
//# sourceMappingURL=map-row.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-row.d.ts","sourceRoot":"","sources":["../../src/store/map-row.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAEd,MAAM,wBAAwB,CAAC;AAEhC,
|
|
1
|
+
{"version":3,"file":"map-row.d.ts","sourceRoot":"","sources":["../../src/store/map-row.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAEd,MAAM,wBAAwB,CAAC;AAEhC;;;GAGG;AACH,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAEjD,6DAA6D;AAC7D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,IAAI,EAAE,SAAS,CAAC;IAChB,YAAY,EAAE,SAAS,CAAC;IACxB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;CACxB,CAAC;AAMF,yEAAyE;AACzE,wBAAgB,mBAAmB,CAAC,WAAW,GAAG,KAAK,EACrD,GAAG,EAAE,gBAAgB,GACpB,aAAa,CAAC,WAAW,CAAC,CAyB5B"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import type { AbstractQuery, FindManyOptions } from "fumadb/query";
|
|
2
|
+
import type { dbSchema } from "../schema/schema.js";
|
|
3
|
+
import type { DbListSort, DbUsage } from "../types/client.js";
|
|
4
|
+
import type { StorageObject, StorageObjectStatus } from "../types/storage-object.js";
|
|
5
|
+
/** The FumaDB ORM for the schema the stores read. */
|
|
6
|
+
export type DbOrm = AbstractQuery<typeof dbSchema>;
|
|
7
|
+
/** Resolves the ORM once the schema version is checked. */
|
|
8
|
+
export type GetDbOrm = () => Promise<DbOrm>;
|
|
9
|
+
/** Condition builder of a `storage_object` query. */
|
|
10
|
+
export type ObjectConditions = Parameters<NonNullable<FindManyOptions<(typeof dbSchema.tables)["storageObject"]>["where"]>>[0];
|
|
11
|
+
type Condition = ReturnType<ObjectConditions> | boolean;
|
|
12
|
+
/** Rows per page when `limit` is not given. */
|
|
13
|
+
export declare const DEFAULT_LIST_LIMIT = 50;
|
|
14
|
+
/** Rows `findStale` returns when `limit` is not given. */
|
|
15
|
+
export declare const DEFAULT_STALE_LIMIT = 100;
|
|
16
|
+
/**
|
|
17
|
+
* How long a purge claim holds a stale row. A row whose purge failed is
|
|
18
|
+
* stale again once its claim lapses.
|
|
19
|
+
*/
|
|
20
|
+
export declare const PURGE_CLAIM_MS: number;
|
|
21
|
+
/** Identifies one object row. `(bucket, key)` is unique. */
|
|
22
|
+
export type ObjectRef = {
|
|
23
|
+
bucket: string;
|
|
24
|
+
key: string;
|
|
25
|
+
};
|
|
26
|
+
/** The upload `uploadToken` started on the row at `(bucket, key)`. */
|
|
27
|
+
export type UploadRef = ObjectRef & {
|
|
28
|
+
uploadToken: string;
|
|
29
|
+
};
|
|
30
|
+
export type UpsertPendingInput = ObjectRef & {
|
|
31
|
+
scope: string;
|
|
32
|
+
route: string;
|
|
33
|
+
/** Logical folder. `null` is the root. */
|
|
34
|
+
folder: string | null;
|
|
35
|
+
filename: string;
|
|
36
|
+
contentType?: string | null;
|
|
37
|
+
/** Size the client declared. Quota counts it until the row expires. */
|
|
38
|
+
declaredSize?: number | null;
|
|
39
|
+
acl?: string | null;
|
|
40
|
+
/** Multipart upload ID. */
|
|
41
|
+
uploadId?: string | null;
|
|
42
|
+
/** Token of the upload ticket. Confirm must present the same one. */
|
|
43
|
+
uploadToken: string;
|
|
44
|
+
/** Confirm deadline: the upload ticket's expiry. */
|
|
45
|
+
expiresAt: Date;
|
|
46
|
+
/**
|
|
47
|
+
* Lets the upload replace an active object at the key. The active row
|
|
48
|
+
* keeps its object fields, folder, and attributes until the upload is
|
|
49
|
+
* confirmed, so the object stays listed and downloadable meanwhile.
|
|
50
|
+
*/
|
|
51
|
+
overwrite?: boolean;
|
|
52
|
+
};
|
|
53
|
+
export type MarkActiveInput = UploadRef & {
|
|
54
|
+
/** Verified size from HeadObject. */
|
|
55
|
+
size: number;
|
|
56
|
+
eTag?: string | null;
|
|
57
|
+
contentType?: string | null;
|
|
58
|
+
filename?: string;
|
|
59
|
+
s3Metadata?: Record<string, string> | null;
|
|
60
|
+
acl?: string | null;
|
|
61
|
+
};
|
|
62
|
+
/** Which rows of a scope a listing or count covers. */
|
|
63
|
+
export type ObjectFilter = {
|
|
64
|
+
scope: string;
|
|
65
|
+
/** Folder to cover. `null` is the root. Omit for every folder. */
|
|
66
|
+
folder?: string | null;
|
|
67
|
+
/**
|
|
68
|
+
* @default "active". `pending` covers only rows that have not expired.
|
|
69
|
+
*/
|
|
70
|
+
status?: StorageObjectStatus;
|
|
71
|
+
route?: string;
|
|
72
|
+
/** Exact type, or `type/*` for every subtype (`image/*`). */
|
|
73
|
+
contentType?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Text the `filename` contains (`LIKE` on SQL), where `%` and `_` act as
|
|
76
|
+
* wildcards. The database decides case: PostgreSQL matches it exactly,
|
|
77
|
+
* SQLite ignores ASCII case, and MySQL follows the column collation.
|
|
78
|
+
*/
|
|
79
|
+
search?: string;
|
|
80
|
+
};
|
|
81
|
+
export type ListObjectsInput = ObjectFilter & {
|
|
82
|
+
/** @default { field: "createdAt", direction: "desc" } */
|
|
83
|
+
sort?: DbListSort;
|
|
84
|
+
/** @default 50 */
|
|
85
|
+
limit?: number;
|
|
86
|
+
/**
|
|
87
|
+
* `nextCursor` of the previous page. A cursor made under other filters is
|
|
88
|
+
* ignored, and the listing starts at the first page.
|
|
89
|
+
*/
|
|
90
|
+
cursor?: string | null;
|
|
91
|
+
};
|
|
92
|
+
export type ListObjectsPage<TAttributes = never> = {
|
|
93
|
+
objects: StorageObject<TAttributes>[];
|
|
94
|
+
/** `null` on the last page. */
|
|
95
|
+
nextCursor: string | null;
|
|
96
|
+
/** True when the page starts the listing, including after an ignored cursor. */
|
|
97
|
+
firstPage: boolean;
|
|
98
|
+
};
|
|
99
|
+
/** Fields `update` changes. Omitted fields stay as they are. */
|
|
100
|
+
export type UpdateObjectInput<TAttributes = never> = {
|
|
101
|
+
filename?: string;
|
|
102
|
+
/** Folder path. `null` is the root. */
|
|
103
|
+
folder?: string | null;
|
|
104
|
+
attributes?: TAttributes | null;
|
|
105
|
+
};
|
|
106
|
+
/** Data access for the `storage_object` table. It never calls S3. */
|
|
107
|
+
export type StorageObjectStore<TAttributes = never> = {
|
|
108
|
+
/** Loads the row at `(bucket, key)`, whatever its status. */
|
|
109
|
+
find: (ref: ObjectRef) => Promise<StorageObject<TAttributes> | null>;
|
|
110
|
+
/**
|
|
111
|
+
* One page of a scope's rows. Pages follow a cursor, ordered by `sort`
|
|
112
|
+
* with ties broken on `id`. Rows with no `size` come last.
|
|
113
|
+
*/
|
|
114
|
+
list: (input: ListObjectsInput) => Promise<ListObjectsPage<TAttributes>>;
|
|
115
|
+
/** Counts the rows a filter covers. */
|
|
116
|
+
count: (filter: ObjectFilter) => Promise<number>;
|
|
117
|
+
/**
|
|
118
|
+
* Bytes and files of a scope: the size of each active row plus the
|
|
119
|
+
* declared size of each pending row that has not expired. An active row
|
|
120
|
+
* with an overwrite in flight counts the larger of the two. `excluding`
|
|
121
|
+
* leaves one row out, such as the row an upload replaces.
|
|
122
|
+
*/
|
|
123
|
+
getUsage: (scope: string, options?: {
|
|
124
|
+
excluding?: ObjectRef;
|
|
125
|
+
}) => Promise<DbUsage>;
|
|
126
|
+
/**
|
|
127
|
+
* Starts an upload at `(bucket, key)`: writes a fresh pending row over a
|
|
128
|
+
* missing, pending, or deleted one (a deleted row is replaced by a new row
|
|
129
|
+
* with a new id). With `overwrite`, an active row stays active and only
|
|
130
|
+
* takes the upload's token, upload ID, declared size, and deadline. Each
|
|
131
|
+
* write is a compare-and-set on the row as it was read.
|
|
132
|
+
* @throws `OBJECT_EXISTS` when an active row is there and `overwrite` is
|
|
133
|
+
* not set; `CONFLICT` when purge has claimed the row or a concurrent write
|
|
134
|
+
* wins.
|
|
135
|
+
*/
|
|
136
|
+
upsertPending: (input: UpsertPendingInput) => Promise<StorageObject<TAttributes>>;
|
|
137
|
+
/**
|
|
138
|
+
* Compare-and-set confirm: promotes the row only while `uploadToken`'s
|
|
139
|
+
* upload is in flight on it (see {@link isUploading}). A row this upload
|
|
140
|
+
* already confirmed is a replay and is returned as stored.
|
|
141
|
+
* @throws `OBJECT_NOT_FOUND` when no row matches (missing, deleted,
|
|
142
|
+
* purging, or taken by another upload).
|
|
143
|
+
*/
|
|
144
|
+
markActive: (input: MarkActiveInput) => Promise<StorageObject<TAttributes>>;
|
|
145
|
+
/**
|
|
146
|
+
* Changes an active row. With `id` or `scope`, only that row, so a check
|
|
147
|
+
* made on it still holds. Returns `null` when no row matches.
|
|
148
|
+
*/
|
|
149
|
+
update: (ref: ObjectRef & {
|
|
150
|
+
id?: string;
|
|
151
|
+
scope?: string;
|
|
152
|
+
}, input: UpdateObjectInput<TAttributes>) => Promise<StorageObject<TAttributes> | null>;
|
|
153
|
+
/** Marks the row `deleted` and keeps it. */
|
|
154
|
+
softDelete: (ref: ObjectRef) => Promise<void>;
|
|
155
|
+
/** Removes the row. */
|
|
156
|
+
hardDelete: (ref: ObjectRef) => Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Ends an upload that left no object, such as a multipart abort: removes
|
|
159
|
+
* its pending row, or clears it from the active row it was overwriting,
|
|
160
|
+
* which keeps the previous object. Rows of other uploads are left alone.
|
|
161
|
+
*/
|
|
162
|
+
cancelUpload: (ref: UploadRef) => Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Removes the row while `uploadToken`'s upload is in flight on it, for
|
|
165
|
+
* when that upload's object is gone. An overwrite's object already
|
|
166
|
+
* replaced the previous one, so its active row goes too.
|
|
167
|
+
*/
|
|
168
|
+
discardUpload: (ref: UploadRef) => Promise<void>;
|
|
169
|
+
/**
|
|
170
|
+
* Rows past their deadline, oldest first: pending rows, active rows whose
|
|
171
|
+
* overwrite was never confirmed, and rows a failed purge left `purging`,
|
|
172
|
+
* once the claim lapses.
|
|
173
|
+
*/
|
|
174
|
+
findStale: (options?: {
|
|
175
|
+
limit?: number;
|
|
176
|
+
}) => Promise<StorageObject<TAttributes>[]>;
|
|
177
|
+
/**
|
|
178
|
+
* Exclusive compare-and-set claim for purge, while the row is still stale.
|
|
179
|
+
* A pending row becomes `purging`. An active row stays active, and its
|
|
180
|
+
* `uploadToken` takes the claim prefix (see {@link uploadTokenOf}).
|
|
181
|
+
* Either way the upload can no longer confirm the row. The claim moves the
|
|
182
|
+
* deadline {@link PURGE_CLAIM_MS} ahead, so no other run can claim the row
|
|
183
|
+
* meanwhile. Returns the claimed row, or `null` when it was confirmed,
|
|
184
|
+
* deleted, written again by a new upload, or claimed by another run.
|
|
185
|
+
*/
|
|
186
|
+
claimStale: (id: string) => Promise<StorageObject<TAttributes> | null>;
|
|
187
|
+
/** Removes a claimed row, only while it is still `purging`. */
|
|
188
|
+
deletePurged: (id: string) => Promise<void>;
|
|
189
|
+
/** Removes `deleted` rows deleted before `olderThan`. Returns how many. */
|
|
190
|
+
pruneDeleted: (olderThan: Date) => Promise<number>;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* The token of the upload that wrote the row, also once purge has claimed
|
|
194
|
+
* it. It is the value of the object's upload marker in S3.
|
|
195
|
+
*/
|
|
196
|
+
export declare function uploadTokenOf(object: StorageObject<unknown>): string | null;
|
|
197
|
+
/**
|
|
198
|
+
* True while an upload is in flight on the row: it is pending, or it is
|
|
199
|
+
* active with the deadline of an overwrite that is not confirmed yet. The
|
|
200
|
+
* row's `uploadToken` is that upload's, or purge's claim of it.
|
|
201
|
+
*/
|
|
202
|
+
export declare function isUploading(object: StorageObject<unknown>): boolean;
|
|
203
|
+
/** Active rows, and pending rows whose confirm deadline has not passed. */
|
|
204
|
+
export declare function liveObject(b: ObjectConditions, now: Date): Condition;
|
|
205
|
+
/** Creates the `storage_object` store over `getOrm`. */
|
|
206
|
+
export declare function createObjectStore<TAttributes = never>(getOrm: GetDbOrm): StorageObjectStore<TAttributes>;
|
|
207
|
+
export {};
|
|
208
|
+
//# sourceMappingURL=object-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-store.d.ts","sourceRoot":"","sources":["../../src/store/object-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAUhC,qDAAqD;AACrD,MAAM,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEnD,2DAA2D;AAC3D,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC;AAE5C,qD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