@dimah-s3/db 1.7.0 → 2.0.0-beta.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.
Files changed (120) hide show
  1. package/README.md +62 -17
  2. package/dist/adapters/drizzle.d.ts +7 -0
  3. package/dist/adapters/drizzle.d.ts.map +1 -0
  4. package/dist/adapters/drizzle.js +3 -0
  5. package/dist/adapters/drizzle.js.map +1 -0
  6. package/dist/adapters/kysely.d.ts +7 -0
  7. package/dist/adapters/kysely.d.ts.map +1 -0
  8. package/dist/adapters/kysely.js +3 -0
  9. package/dist/adapters/kysely.js.map +1 -0
  10. package/dist/adapters/prisma.d.ts +7 -0
  11. package/dist/adapters/prisma.d.ts.map +1 -0
  12. package/dist/adapters/prisma.js +3 -0
  13. package/dist/adapters/prisma.js.map +1 -0
  14. package/dist/cli.d.ts +33 -4
  15. package/dist/cli.d.ts.map +1 -1
  16. package/dist/cli.js +192 -4
  17. package/dist/cli.js.map +1 -1
  18. package/dist/client/db-client.d.ts +9 -85
  19. package/dist/client/db-client.d.ts.map +1 -1
  20. package/dist/client/db-object-source.d.ts +25 -0
  21. package/dist/client/db-object-source.d.ts.map +1 -0
  22. package/dist/client/index.d.ts +3 -3
  23. package/dist/client/index.d.ts.map +1 -1
  24. package/dist/client/index.js +96 -42
  25. package/dist/client/index.js.map +1 -1
  26. package/dist/drizzle/mysql.d.ts +1024 -0
  27. package/dist/drizzle/mysql.d.ts.map +1 -0
  28. package/dist/drizzle/mysql.js +123 -0
  29. package/dist/drizzle/mysql.js.map +1 -0
  30. package/dist/drizzle/pg.d.ts +963 -0
  31. package/dist/drizzle/pg.d.ts.map +1 -0
  32. package/dist/drizzle/pg.js +104 -0
  33. package/dist/drizzle/pg.js.map +1 -0
  34. package/dist/drizzle/shared.d.ts +16 -0
  35. package/dist/drizzle/shared.d.ts.map +1 -0
  36. package/dist/drizzle/sqlite.d.ts +1023 -0
  37. package/dist/drizzle/sqlite.d.ts.map +1 -0
  38. package/dist/drizzle/sqlite.js +107 -0
  39. package/dist/drizzle/sqlite.js.map +1 -0
  40. package/dist/folder-path.d.ts +32 -0
  41. package/dist/folder-path.d.ts.map +1 -0
  42. package/dist/fuma-db.d.ts +47 -5
  43. package/dist/fuma-db.d.ts.map +1 -1
  44. package/dist/index.d.ts +9 -13
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +1452 -620
  47. package/dist/index.js.map +1 -1
  48. package/dist/plugin/create-database-endpoints.d.ts +105 -21
  49. package/dist/plugin/create-database-endpoints.d.ts.map +1 -1
  50. package/dist/plugin/create-database-lifecycle-hooks.d.ts +37 -19
  51. package/dist/plugin/create-database-lifecycle-hooks.d.ts.map +1 -1
  52. package/dist/plugin/db.d.ts +29 -118
  53. package/dist/plugin/db.d.ts.map +1 -1
  54. package/dist/plugin/object-access.d.ts +46 -0
  55. package/dist/plugin/object-access.d.ts.map +1 -0
  56. package/dist/plugin/public-stores.d.ts +33 -0
  57. package/dist/plugin/public-stores.d.ts.map +1 -0
  58. package/dist/plugin/purge.d.ts +49 -0
  59. package/dist/plugin/purge.d.ts.map +1 -0
  60. package/dist/plugin/quota.d.ts +25 -0
  61. package/dist/plugin/quota.d.ts.map +1 -0
  62. package/dist/plugin/schemas.d.ts +69 -0
  63. package/dist/plugin/schemas.d.ts.map +1 -0
  64. package/dist/plugin/scope.d.ts +31 -0
  65. package/dist/plugin/scope.d.ts.map +1 -0
  66. package/dist/plugin/to-db-client-object.d.ts +8 -4
  67. package/dist/plugin/to-db-client-object.d.ts.map +1 -1
  68. package/dist/schema/v1.d.ts +1 -8
  69. package/dist/schema/v1.d.ts.map +1 -1
  70. package/dist/schema/v2.d.ts +64 -0
  71. package/dist/schema/v2.d.ts.map +1 -0
  72. package/dist/standard-schema.d.ts +42 -0
  73. package/dist/standard-schema.d.ts.map +1 -0
  74. package/dist/store/create-db-store.d.ts +17 -0
  75. package/dist/store/create-db-store.d.ts.map +1 -0
  76. package/dist/store/folder-store.d.ts +36 -0
  77. package/dist/store/folder-store.d.ts.map +1 -0
  78. package/dist/store/list-cursor.d.ts +26 -4
  79. package/dist/store/list-cursor.d.ts.map +1 -1
  80. package/dist/store/map-row.d.ts +17 -8
  81. package/dist/store/map-row.d.ts.map +1 -1
  82. package/dist/store/object-store.d.ts +208 -0
  83. package/dist/store/object-store.d.ts.map +1 -0
  84. package/dist/store/schema-version.d.ts +7 -0
  85. package/dist/store/schema-version.d.ts.map +1 -0
  86. package/dist/types/client.d.ts +209 -0
  87. package/dist/types/client.d.ts.map +1 -0
  88. package/dist/types/plugin.d.ts +112 -0
  89. package/dist/types/plugin.d.ts.map +1 -0
  90. package/dist/types/storage-object.d.ts +40 -85
  91. package/dist/types/storage-object.d.ts.map +1 -1
  92. package/package.json +51 -12
  93. package/prisma/dimah-s3.prisma +80 -0
  94. package/sql/mysql.sql +59 -0
  95. package/sql/pg.sql +53 -0
  96. package/sql/sqlite.sql +54 -0
  97. package/sql/upgrade/1.0.0-2.0.0/mysql.sql +71 -0
  98. package/sql/upgrade/1.0.0-2.0.0/pg.sql +47 -0
  99. package/sql/upgrade/1.0.0-2.0.0/sqlite.sql +119 -0
  100. package/dist/client/db-object-list-accessors.d.ts +0 -36
  101. package/dist/client/db-object-list-accessors.d.ts.map +0 -1
  102. package/dist/client/db-object-query.d.ts +0 -40
  103. package/dist/client/db-object-query.d.ts.map +0 -1
  104. package/dist/errors.d.ts +0 -6
  105. package/dist/errors.d.ts.map +0 -1
  106. package/dist/hooks/create-object-access-guard.d.ts +0 -51
  107. package/dist/hooks/create-object-access-guard.d.ts.map +0 -1
  108. package/dist/hooks/create-quota-guard.d.ts +0 -28
  109. package/dist/hooks/create-quota-guard.d.ts.map +0 -1
  110. package/dist/jobs/purge-stale-pending.d.ts +0 -31
  111. package/dist/jobs/purge-stale-pending.d.ts.map +0 -1
  112. package/dist/plugin/list-query-schema.d.ts +0 -21
  113. package/dist/plugin/list-query-schema.d.ts.map +0 -1
  114. package/dist/plugin/memoize-scope-resolver.d.ts +0 -8
  115. package/dist/plugin/memoize-scope-resolver.d.ts.map +0 -1
  116. package/dist/store/storage-object-store.d.ts +0 -137
  117. package/dist/store/storage-object-store.d.ts.map +0 -1
  118. package/src/schema/examples/README.md +0 -10
  119. package/src/schema/examples/drizzle.ts +0 -92
  120. package/src/schema/examples/schema.prisma +0 -55
@@ -0,0 +1,119 @@
1
+ -- @dimah-s3/db schema 1.0.0 → 2.0.0 for SQLite.
2
+ -- Back up the database first. SQLite cannot change a column in place, so
3
+ -- this rebuilds `storage_object`:
4
+ -- - `metadata` moves to `s3_metadata`; `attributes`, `folder`, and
5
+ -- `upload_token` start empty (`folder` NULL is the root).
6
+ -- - A missing `filename` becomes the last segment of the key.
7
+ -- - Sizes become INTEGER. 1.x stored them as blobs: an 8-byte big-endian
8
+ -- integer (Kysely adapter) or the decimal digits (Drizzle).
9
+ -- - Timestamps become epoch milliseconds. 1.x Drizzle tables stored seconds.
10
+
11
+ BEGIN;
12
+
13
+ UPDATE "storage_object" SET "size" = CASE
14
+ WHEN length("size") = 8 AND substr(hex("size"), 1, 2) = '00' THEN (
15
+ WITH RECURSIVE "digit" ("i", "n") AS (
16
+ SELECT 1, 0
17
+ UNION ALL
18
+ SELECT "i" + 1, "n" * 16 + instr('0123456789ABCDEF', substr(hex("storage_object"."size"), "i", 1)) - 1
19
+ FROM "digit" WHERE "i" <= 16
20
+ )
21
+ SELECT "n" FROM "digit" WHERE "i" = 17
22
+ )
23
+ ELSE CAST(CAST("size" AS TEXT) AS INTEGER)
24
+ END
25
+ WHERE typeof("size") = 'blob';
26
+
27
+ UPDATE "storage_object" SET "declared_size" = CASE
28
+ WHEN length("declared_size") = 8 AND substr(hex("declared_size"), 1, 2) = '00' THEN (
29
+ WITH RECURSIVE "digit" ("i", "n") AS (
30
+ SELECT 1, 0
31
+ UNION ALL
32
+ SELECT "i" + 1, "n" * 16 + instr('0123456789ABCDEF', substr(hex("storage_object"."declared_size"), "i", 1)) - 1
33
+ FROM "digit" WHERE "i" <= 16
34
+ )
35
+ SELECT "n" FROM "digit" WHERE "i" = 17
36
+ )
37
+ ELSE CAST(CAST("declared_size" AS TEXT) AS INTEGER)
38
+ END
39
+ WHERE typeof("declared_size") = 'blob';
40
+
41
+ -- Seconds (anything before 1973 as milliseconds) and text dates become milliseconds.
42
+ UPDATE "storage_object" SET
43
+ "expires_at" = CASE WHEN typeof("expires_at") = 'text' THEN CAST(strftime('%s', "expires_at") AS INTEGER) * 1000 WHEN "expires_at" < 100000000000 THEN "expires_at" * 1000 ELSE "expires_at" END,
44
+ "confirmed_at" = CASE WHEN typeof("confirmed_at") = 'text' THEN CAST(strftime('%s', "confirmed_at") AS INTEGER) * 1000 WHEN "confirmed_at" < 100000000000 THEN "confirmed_at" * 1000 ELSE "confirmed_at" END,
45
+ "created_at" = CASE WHEN typeof("created_at") = 'text' THEN CAST(strftime('%s', "created_at") AS INTEGER) * 1000 WHEN "created_at" < 100000000000 THEN "created_at" * 1000 ELSE "created_at" END,
46
+ "updated_at" = CASE WHEN typeof("updated_at") = 'text' THEN CAST(strftime('%s', "updated_at") AS INTEGER) * 1000 WHEN "updated_at" < 100000000000 THEN "updated_at" * 1000 ELSE "updated_at" END,
47
+ "deleted_at" = CASE WHEN typeof("deleted_at") = 'text' THEN CAST(strftime('%s', "deleted_at") AS INTEGER) * 1000 WHEN "deleted_at" < 100000000000 THEN "deleted_at" * 1000 ELSE "deleted_at" END;
48
+
49
+ CREATE TABLE "storage_object_v2" (
50
+ "id" text PRIMARY KEY NOT NULL,
51
+ "scope" text NOT NULL,
52
+ "bucket" text NOT NULL,
53
+ "key" text NOT NULL,
54
+ "route" text NOT NULL,
55
+ "folder" text,
56
+ "filename" text NOT NULL,
57
+ "content_type" text,
58
+ "size" integer,
59
+ "declared_size" integer,
60
+ "e_tag" text,
61
+ "status" text NOT NULL,
62
+ "s3_metadata" text,
63
+ "attributes" text,
64
+ "acl" text,
65
+ "upload_id" text,
66
+ "upload_token" text,
67
+ "expires_at" integer,
68
+ "confirmed_at" integer,
69
+ "created_at" integer NOT NULL DEFAULT (strftime('%s', 'now') * 1000),
70
+ "updated_at" integer NOT NULL DEFAULT (strftime('%s', 'now') * 1000),
71
+ "deleted_at" integer
72
+ );
73
+
74
+ INSERT INTO "storage_object_v2" (
75
+ "id", "scope", "bucket", "key", "route", "folder", "filename",
76
+ "content_type", "size", "declared_size", "e_tag", "status", "s3_metadata",
77
+ "attributes", "acl", "upload_id", "upload_token", "expires_at",
78
+ "confirmed_at", "created_at", "updated_at", "deleted_at"
79
+ )
80
+ SELECT
81
+ "id", "scope", "bucket", "key", "route", NULL,
82
+ COALESCE(
83
+ "filename",
84
+ NULLIF(substr("key", length(rtrim("key", replace("key", '/', ''))) + 1), ''),
85
+ "key"
86
+ ),
87
+ "content_type", "size", "declared_size", "e_tag", "status",
88
+ CASE WHEN typeof("metadata") = 'blob' THEN CAST("metadata" AS TEXT) ELSE "metadata" END,
89
+ NULL, "acl", "upload_id", NULL, "expires_at",
90
+ "confirmed_at", "created_at", "updated_at", "deleted_at"
91
+ FROM "storage_object";
92
+
93
+ DROP TABLE "storage_object";
94
+ ALTER TABLE "storage_object_v2" RENAME TO "storage_object";
95
+
96
+ CREATE UNIQUE INDEX "storage_object_bucket_key_uk" ON "storage_object" ("bucket", "key");
97
+ CREATE INDEX "storage_object_scope_folder_idx" ON "storage_object" ("scope", "status", "folder", "created_at");
98
+ CREATE INDEX "storage_object_scope_updated_idx" ON "storage_object" ("scope", "status", "updated_at");
99
+ CREATE INDEX "storage_object_scope_filename_idx" ON "storage_object" ("scope", "status", "filename");
100
+ CREATE INDEX "storage_object_scope_size_idx" ON "storage_object" ("scope", "status", "size");
101
+ CREATE INDEX "storage_object_status_expires_idx" ON "storage_object" ("status", "expires_at");
102
+
103
+ CREATE TABLE "storage_folder" (
104
+ "id" text PRIMARY KEY NOT NULL,
105
+ "scope" text NOT NULL,
106
+ "path" text NOT NULL,
107
+ "parent" text,
108
+ "name" text NOT NULL,
109
+ "created_at" integer NOT NULL DEFAULT (strftime('%s', 'now') * 1000)
110
+ );
111
+
112
+ CREATE UNIQUE INDEX "storage_folder_scope_path_uk" ON "storage_folder" ("scope", "path");
113
+ CREATE INDEX "storage_folder_scope_parent_idx" ON "storage_folder" ("scope", "parent");
114
+
115
+ COMMIT;
116
+
117
+ -- Kysely and Prisma read the version from this table. A Drizzle setup reads
118
+ -- it from the table definition instead: skip this statement there.
119
+ UPDATE "private_dimah_s3_settings" SET "value" = '2.0.0' WHERE "key" = 'version';
@@ -1,36 +0,0 @@
1
- import type { DbClientObject } from "../types/storage-object.js";
2
- /** Accessors that map a `listObjects` row onto `ObjectList`. */
3
- export type DbObjectListAccessors = {
4
- /** Row id. */
5
- getKey: (object: DbClientObject) => string;
6
- /** Stored object key. Bulk delete uses this. */
7
- getObjectKey: (object: DbClientObject) => string;
8
- /** Filename, or the last segment of the key. */
9
- getLabel: (object: DbClientObject) => string;
10
- /** Same name the type glyph uses. */
11
- getFileName: (object: DbClientObject) => string;
12
- getFileType: (object: DbClientObject) => string | null;
13
- /** Verified size. `null` while the object is still pending. */
14
- getDescription: (object: DbClientObject) => string | null;
15
- };
16
- /** Options for {@link dbObjectListAccessors}. */
17
- export type DbObjectListAccessorsOptions = {
18
- /**
19
- * Size label for `getDescription`. In React, pass `useFormatFileSize()`
20
- * from `@dimah-s3/react` to follow the `S3Provider` `locale`.
21
- */
22
- formatSize?: (bytes: number) => string;
23
- };
24
- /**
25
- * Map `api.db.listObjects` rows onto `ObjectList` accessors.
26
- *
27
- * This does not invent folders. Pass the result of `dbObjectQuery` as `list`.
28
- *
29
- * ```tsx
30
- * const files = dbObjectListAccessors();
31
- *
32
- * <ObjectList list={list} {...files} />
33
- * ```
34
- */
35
- export declare function dbObjectListAccessors(options?: DbObjectListAccessorsOptions): DbObjectListAccessors;
36
- //# sourceMappingURL=db-object-list-accessors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"db-object-list-accessors.d.ts","sourceRoot":"","sources":["../../src/client/db-object-list-accessors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,gEAAgE;AAChE,MAAM,MAAM,qBAAqB,GAAG;IAClC,cAAc;IACd,MAAM,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,MAAM,CAAC;IAC3C,gDAAgD;IAChD,YAAY,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,MAAM,CAAC;IACjD,gDAAgD;IAChD,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,MAAM,CAAC;IAC7C,qCAAqC;IACrC,WAAW,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,MAAM,CAAC;IAChD,WAAW,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,MAAM,GAAG,IAAI,CAAC;IACvD,+DAA+D;IAC/D,cAAc,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,MAAM,GAAG,IAAI,CAAC;CAC3D,CAAC;AAEF,iDAAiD;AACjD,MAAM,MAAM,4BAA4B,GAAG;IACzC;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CACxC,CAAC;AAMF;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,4BAAiC,GACzC,qBAAqB,CAYvB"}
@@ -1,40 +0,0 @@
1
- import type { DbClientListInput, DbClientListResponse, DbClientObject, StorageObjectStatus } from "../types/storage-object.js";
2
- /** `listObjects` plus an optional abort signal. Matches `dbClient()`. */
3
- export type DbObjectListSource = (input?: DbClientListInput, init?: {
4
- signal?: AbortSignal;
5
- }) => Promise<DbClientListResponse>;
6
- export type DbObjectQueryOptions = {
7
- route?: string;
8
- status?: StorageObjectStatus;
9
- contentType?: string;
10
- limit?: number;
11
- };
12
- export type DbObjectQueryInput = {
13
- parent: string | null;
14
- cursor: string | null;
15
- signal: AbortSignal;
16
- };
17
- export type DbObjectQueryPage = {
18
- items: DbClientObject[];
19
- nextCursor: string | null;
20
- /** Scope totals from `listObjects`. Not limited to the open folder. */
21
- usage: DbClientListResponse["usage"];
22
- };
23
- /**
24
- * Adapt `api.db.listObjects` to a `useObjectList` query.
25
- *
26
- * `parent` is sent as the key `prefix`. This does not invent folder rows:
27
- * default object keys contain a uuid segment, so a delimiter over the key
28
- * is not a folder tree. Return `folders` from your own query when the
29
- * catalog has them. `usage` is the scope total from `listObjects`, not the
30
- * open folder.
31
- *
32
- * ```ts
33
- * const list = useObjectList({
34
- * query: dbObjectQuery(api.db.listObjects, { route: "docs" }),
35
- * queryKey: ["docs"],
36
- * });
37
- * ```
38
- */
39
- export declare function dbObjectQuery(listObjects: DbObjectListSource, options?: DbObjectQueryOptions): (input: DbObjectQueryInput) => Promise<DbObjectQueryPage>;
40
- //# sourceMappingURL=db-object-query.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"db-object-query.d.ts","sourceRoot":"","sources":["../../src/client/db-object-query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAEhC,yEAAyE;AACzE,MAAM,MAAM,kBAAkB,GAAG,CAC/B,KAAK,CAAC,EAAE,iBAAiB,EACzB,IAAI,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,KAC5B,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEnC,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,uEAAuE;IACvE,KAAK,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;CACtC,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAC3B,WAAW,EAAE,kBAAkB,EAC/B,OAAO,CAAC,EAAE,oBAAoB,WAGrB,kBAAkB,KACxB,OAAO,CAAC,iBAAiB,CAAC,CAgB9B"}
package/dist/errors.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { APIError } from "@dimah-s3/core";
2
- export declare function unauthorized(message?: string): APIError;
3
- export declare function forbidden(message?: string): APIError;
4
- export declare function notFound(message?: string): APIError;
5
- export declare function conflict(message?: string): APIError;
6
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,gBAAgB,CAAC;AAE1D,wBAAgB,YAAY,CAC1B,OAAO,GAAE,MAA4C,GACpD,QAAQ,CAKV;AAED,wBAAgB,SAAS,CACvB,OAAO,GAAE,MAAyC,GACjD,QAAQ,CAKV;AAED,wBAAgB,QAAQ,CACtB,OAAO,GAAE,MAAgD,GACxD,QAAQ,CAKV;AAED,wBAAgB,QAAQ,CACtB,OAAO,GAAE,MAAwC,GAChD,QAAQ,CAKV"}
@@ -1,51 +0,0 @@
1
- import { type DimahS3DbClient, type StorageObjectStore } from "../store/storage-object-store.js";
2
- import type { ScopeOperation, ScopeResolver, StorageObject, StorageObjectStatus } from "../types/storage-object.js";
3
- /** Minimal context the guard needs — matches every key-bearing server hook context. */
4
- export type ObjectAccessGuardContext = {
5
- request: Request;
6
- key: string;
7
- bucket: string;
8
- /** Named route. Passed on to `resolveScope`. */
9
- route?: string;
10
- /** Multipart session id — required when {@link CreateObjectAccessGuardOptions.requireUploadId} is set. */
11
- uploadId?: string;
12
- };
13
- export type CreateObjectAccessGuardOptions = {
14
- /** FumaDB client (`DimahS3DB.client(adapter)`) or a prebuilt objects store. */
15
- client: DimahS3DbClient | StorageObjectStore;
16
- resolveScope: ScopeResolver;
17
- /**
18
- * The operation this guard protects, passed to `resolveScope`. Create one
19
- * guard per hook, such as `"download"` for `download.guard` and
20
- * `"delete"` for `delete.guard`.
21
- */
22
- operation: ScopeOperation;
23
- /**
24
- * Which rows count as accessible.
25
- * `"any"` means pending or active (not deleted).
26
- * @default "active"
27
- */
28
- requireStatus?: StorageObjectStatus | "any";
29
- /**
30
- * Require `context.uploadId` to match the pending row's `uploadId`.
31
- * Use for `upload.multipart.guard`.
32
- */
33
- requireUploadId?: boolean;
34
- /**
35
- * Replace the default `object.scope === scope` ownership check —
36
- * e.g. also allow objects whose metadata marks them public.
37
- */
38
- authorize?: (object: StorageObject, context: ObjectAccessGuardContext & {
39
- scope: string;
40
- }) => boolean | Promise<boolean>;
41
- };
42
- export declare function resolveStore(client: DimahS3DbClient | StorageObjectStore): StorageObjectStore;
43
- /**
44
- * Guard that checks the requested object exists in the DB and belongs to the
45
- * caller's scope. Throws `APIError` (401 / 404 / 403) to reject.
46
- *
47
- * Usable as `download.guard`, `delete.guard`,
48
- * `upload.confirmGuard`, `upload.multipart.guard`, or in your own routes.
49
- */
50
- export declare function createObjectAccessGuard(options: CreateObjectAccessGuardOptions): (context: ObjectAccessGuardContext) => Promise<void>;
51
- //# sourceMappingURL=create-object-access-guard.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-object-access-guard.d.ts","sourceRoot":"","sources":["../../src/hooks/create-object-access-guard.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,aAAa,EACb,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAEhC,uFAAuF;AACvF,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0GAA0G;IAC1G,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,+EAA+E;IAC/E,MAAM,EAAE,eAAe,GAAG,kBAAkB,CAAC;IAC7C,YAAY,EAAE,aAAa,CAAC;IAC5B;;;;OAIG;IACH,SAAS,EAAE,cAAc,CAAC;IAC1B;;;;OAIG;IACH,aAAa,CAAC,EAAE,mBAAmB,GAAG,KAAK,CAAC;IAC5C;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,SAAS,CAAC,EAAE,CACV,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,wBAAwB,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,KAClD,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACjC,CAAC;AAEF,wBAAgB,YAAY,CAC1B,MAAM,EAAE,eAAe,GAAG,kBAAkB,GAC3C,kBAAkB,CAEpB;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,GACtC,CAAC,OAAO,EAAE,wBAAwB,KAAK,OAAO,CAAC,IAAI,CAAC,CAiCtD"}
@@ -1,28 +0,0 @@
1
- import type { DimahS3DbClient, StorageObjectStore } from "../store/storage-object-store.js";
2
- import type { ScopeResolver } from "../types/storage-object.js";
3
- export type CreateQuotaGuardOptions = {
4
- client: DimahS3DbClient | StorageObjectStore;
5
- resolveScope: ScopeResolver;
6
- maxBytes?: number;
7
- maxFiles?: number;
8
- };
9
- export type QuotaGuardContext = {
10
- request: Request;
11
- /** Named route. Passed on to `resolveScope`. */
12
- route?: string;
13
- /** Client extras from the presign body. Passed on to `resolveScope`. */
14
- clientMetadata?: Record<string, string>;
15
- file?: {
16
- size?: number;
17
- };
18
- replace?: "overwrite";
19
- key?: string;
20
- bucket?: string;
21
- };
22
- /**
23
- * Reject uploads that would exceed scope usage.
24
- * Wire as `upload.guard` (after `db()` so ownership still runs), or pass
25
- * `quota` on {@link db}.
26
- */
27
- export declare function createQuotaGuard(options: CreateQuotaGuardOptions): (context: QuotaGuardContext) => Promise<void>;
28
- //# sourceMappingURL=create-quota-guard.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-quota-guard.d.ts","sourceRoot":"","sources":["../../src/hooks/create-quota-guard.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,eAAe,GAAG,kBAAkB,CAAC;IAC7C,YAAY,EAAE,aAAa,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AASF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,uBAAuB,GAC/B,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAwC/C"}
@@ -1,31 +0,0 @@
1
- import { type S3Client } from "@aws-sdk/client-s3";
2
- import type { DimahS3DbClient, StorageObjectStore } from "../store/storage-object-store.js";
3
- import type { StorageObject } from "../types/storage-object.js";
4
- export type PurgeStalePendingOptions = {
5
- /** FumaDB client (`DimahS3DB.client(adapter)`) or a prebuilt store. */
6
- client: DimahS3DbClient | StorageObjectStore;
7
- /**
8
- * Fallback age for pending rows that have no `expiresAt`.
9
- * @default 86_400_000 (24h)
10
- */
11
- olderThanMs?: number;
12
- /**
13
- * When set, abort in-progress multipart uploads and `DeleteObject` for
14
- * each stale pending key before rows are removed.
15
- */
16
- s3?: S3Client;
17
- /**
18
- * Runs before rows are deleted. Throwing keeps all rows for the next run.
19
- * Prefer `s3` unless you need a custom cleanup.
20
- */
21
- onBeforePurge?: (objects: StorageObject[]) => Promise<void> | void;
22
- };
23
- export type PurgeStalePendingResult = {
24
- purged: StorageObject[];
25
- };
26
- /**
27
- * Delete stale `pending` rows — uploads that were presigned but never
28
- * confirmed. Run it on a schedule (cron, queue worker, route handler).
29
- */
30
- export declare function purgeStalePendingObjects(options: PurgeStalePendingOptions): Promise<PurgeStalePendingResult>;
31
- //# sourceMappingURL=purge-stale-pending.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"purge-stale-pending.d.ts","sourceRoot":"","sources":["../../src/jobs/purge-stale-pending.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAI5D,MAAM,MAAM,wBAAwB,GAAG;IACrC,uEAAuE;IACvE,MAAM,EAAE,eAAe,GAAG,kBAAkB,CAAC;IAC7C;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,EAAE,CAAC,EAAE,QAAQ,CAAC;IACd;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACpE,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB,CAAC;AAiCF;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,uBAAuB,CAAC,CAclC"}
@@ -1,21 +0,0 @@
1
- import * as z from "zod";
2
- export declare const DB_LIST_DEFAULT_LIMIT = 50;
3
- export declare const DB_LIST_MAX_LIMIT = 100;
4
- export declare const dbListQuerySchema: z.ZodObject<{
5
- status: z.ZodOptional<z.ZodEnum<{
6
- active: "active";
7
- deleted: "deleted";
8
- pending: "pending";
9
- }>>;
10
- limit: z.ZodDefault<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>, z.ZodInt>>;
11
- offset: z.ZodOptional<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>, z.ZodInt>>;
12
- cursor: z.ZodOptional<z.ZodString>;
13
- route: z.ZodOptional<z.ZodString>;
14
- contentType: z.ZodOptional<z.ZodString>;
15
- prefix: z.ZodOptional<z.ZodString>;
16
- }, z.core.$strip>;
17
- export declare const dbGetQuerySchema: z.ZodObject<{
18
- key: z.ZodString;
19
- bucket: z.ZodOptional<z.ZodString>;
20
- }, z.core.$strip>;
21
- //# sourceMappingURL=list-query-schema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"list-query-schema.d.ts","sourceRoot":"","sources":["../../src/plugin/list-query-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAGzB,eAAO,MAAM,qBAAqB,KAAK,CAAC;AACxC,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAkBrC,eAAO,MAAM,iBAAiB;;;;;;;;;;;;iBAU5B,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;iBAG3B,CAAC"}
@@ -1,8 +0,0 @@
1
- import type { ScopeResolver } from "../types/storage-object.js";
2
- /**
3
- * Resolve each (request, operation, route, key) once. Presign runs the
4
- * ownership guard, the quota guard, and `onPresigned` on one request; they
5
- * share a single `resolveScope` call. A batch delete still resolves per key.
6
- */
7
- export declare function memoizeScopeResolver(resolve: ScopeResolver): ScopeResolver;
8
- //# sourceMappingURL=memoize-scope-resolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"memoize-scope-resolver.d.ts","sourceRoot":"","sources":["../../src/plugin/memoize-scope-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE1E;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAoB1E"}
@@ -1,137 +0,0 @@
1
- import type { InferFumaDB } from "fumadb";
2
- import type { DimahS3DB } from "../fuma-db.js";
3
- import type { StorageObject, StorageObjectStatus } from "../types/storage-object.js";
4
- /** FumaDB client for the @dimah-s3/db schema. */
5
- export type DimahS3DbClient = InferFumaDB<typeof DimahS3DB>;
6
- /** Identifies one object row — `(bucket, key)` is unique. */
7
- export type ObjectRef = {
8
- bucket: string;
9
- key: string;
10
- };
11
- export type UpsertPendingInput = ObjectRef & {
12
- scope: string;
13
- route: string;
14
- contentType?: string | null;
15
- /** Client-declared size in bytes (quota reservation — not verified). */
16
- declaredSize?: number | null;
17
- metadata?: Record<string, unknown> | null;
18
- acl?: string | null;
19
- filename?: string | null;
20
- /** Multipart upload ID, when the pending upload is multipart. */
21
- uploadId?: string | null;
22
- /** Pending TTL — stale rows past this are eligible for purge. */
23
- expiresAt?: Date | null;
24
- };
25
- export type MarkActiveInput = ObjectRef & {
26
- /** Verified size in bytes (from HeadObject). */
27
- size: number;
28
- eTag?: string | null;
29
- contentType?: string | null;
30
- acl?: string | null;
31
- filename?: string | null;
32
- metadata?: Record<string, unknown> | null;
33
- };
34
- export type ListByScopeInput = {
35
- scope: string;
36
- /**
37
- * Filter by exact status. When omitted, only `active` rows are returned.
38
- */
39
- status?: StorageObjectStatus;
40
- route?: string;
41
- contentType?: string;
42
- /** Key prefix. Applied in the query (`starts with`), so pages stay full. */
43
- prefix?: string;
44
- limit?: number;
45
- offset?: number;
46
- cursor?: string;
47
- };
48
- export type ScopeUsage = {
49
- /** Sum of verified size (fallback: declared size) of non-deleted rows. */
50
- totalBytes: number;
51
- /** Non-deleted row count. */
52
- objectCount: number;
53
- };
54
- /**
55
- * Minimal multipart resume payload — structurally matches
56
- * `@dimah-s3/react` `StoredUpload` so a custom client `UploadStore` can
57
- * return it from `get()` without importing react types.
58
- */
59
- export type PendingMultipartResume = {
60
- uploadId: string;
61
- key: string;
62
- /** Declared file size in bytes (must match the File being resumed). */
63
- fileSize: number;
64
- bucket: string;
65
- };
66
- export type FindPendingMultipartInput = ObjectRef & {
67
- /** Must equal the pending row's `declaredSize`. */
68
- fileSize: number;
69
- };
70
- /**
71
- * Map a `storage_object` row to a client resume payload.
72
- * Returns `null` unless the row is `pending` with `uploadId` and `declaredSize`.
73
- */
74
- export declare function toPendingMultipartResume(object: StorageObject): PendingMultipartResume | null;
75
- /** Data-access layer for the `storage_object` table. */
76
- export type StorageObjectStore = {
77
- /**
78
- * Insert or reset a row to `pending` (presign / multipart init).
79
- * Returns the written row.
80
- */
81
- upsertPending: (input: UpsertPendingInput) => Promise<StorageObject>;
82
- /**
83
- * Promote a pending row to `active` with verified fields (confirm / complete).
84
- * Also refreshes an already-active row (overwrite). Returns the active row.
85
- */
86
- markActive: (input: MarkActiveInput) => Promise<StorageObject>;
87
- /** Load one row by `bucket` + `key` (any status). */
88
- find: (ref: ObjectRef) => Promise<StorageObject | null>;
89
- /** Load one row by scope + key (any status). */
90
- findByScopeKey: (input: {
91
- scope: string;
92
- key: string;
93
- bucket?: string;
94
- }) => Promise<StorageObject | null>;
95
- /** Load one row — only when `status` is `active`. */
96
- findActive: (ref: ObjectRef) => Promise<StorageObject | null>;
97
- /**
98
- * Pending multipart row for resume: `pending` + `uploadId` + matching
99
- * `declaredSize`. Returns the full row so callers can enforce scope.
100
- */
101
- findPendingMultipart: (input: FindPendingMultipartInput) => Promise<StorageObject | null>;
102
- /**
103
- * List rows for a scope (pass `scope` explicitly — admin routes, jobs, etc.).
104
- * Defaults to `active`. Server-side listing; browser apps use
105
- * `api.db.listObjects` instead (scope from `resolveScope`, no HTTP from server code).
106
- */
107
- listByScope: (input: ListByScopeInput) => Promise<StorageObject[]>;
108
- /** Total bytes and row count for a scope — quota checks (`pending` uses `declaredSize`). */
109
- getScopeUsage: (scope: string) => Promise<ScopeUsage>;
110
- /** Row count for a scope; optional `status` filter (same defaults as `listByScope`). */
111
- countByScope: (scope: string, status?: StorageObjectStatus) => Promise<number>;
112
- /**
113
- * Mark a row `deleted` (keeps the record). DB-only — does not delete from S3.
114
- * Not a substitute for `api.delete`; the plugin calls this from `onDeleted`
115
- * when `deleteMode` is `"soft"`.
116
- */
117
- softDelete: (ref: ObjectRef) => Promise<void>;
118
- /**
119
- * Remove the row entirely. DB-only — does not delete from S3.
120
- * Not a substitute for `api.delete`; used by the plugin when `deleteMode` is
121
- * `"hard"`, or by admin jobs to prune soft-deleted audit rows.
122
- */
123
- hardDelete: (ref: ObjectRef) => Promise<void>;
124
- /** Remove a `pending` row (multipart abort path). Optional `uploadId` must match. */
125
- deletePending: (ref: ObjectRef & {
126
- uploadId?: string;
127
- }) => Promise<void>;
128
- /** Pending rows past `expiresAt`, or with no TTL and `createdAt` before `olderThan`. */
129
- findStalePending: (input: {
130
- olderThan: Date;
131
- }) => Promise<StorageObject[]>;
132
- /** Delete rows by ID (used by the purge job after `findStalePending`). */
133
- deleteByIds: (ids: string[]) => Promise<void>;
134
- };
135
- /** Create a store bound to schema v1 (`db.orm("1.0.0")`). */
136
- export declare function createStorageObjectStore(db: DimahS3DbClient): StorageObjectStore;
137
- //# sourceMappingURL=storage-object-store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage-object-store.d.ts","sourceRoot":"","sources":["../../src/store/storage-object-store.ts"],"names":[],"mappings":"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"}
@@ -1,10 +0,0 @@
1
- # Schema examples
2
-
3
- Copy-paste `storage_object` + recommended indexes. Not imported at runtime.
4
-
5
- | File | ORM |
6
- | ---------------------------------- | -------------------- |
7
- | [`drizzle.ts`](./drizzle.ts) | Drizzle 1.x (SQLite) |
8
- | [`schema.prisma`](./schema.prisma) | Prisma |
9
-
10
- Docs: [Database Setup](https://s3.dimah.dev/docs/db/setup). Drizzle needs `fumadb/cuid` → `@paralleldrive/cuid2` in tsconfig paths.
@@ -1,92 +0,0 @@
1
- /**
2
- * Reference Drizzle schema — same shape as FumaDB `generate` (SQLite) on
3
- * drizzle-orm 1.x, plus the recommended secondary indexes. Not imported by
4
- * `@dimah-s3/db` at runtime.
5
- *
6
- * 1.x discovers tables through `relations`. Pass that object to
7
- * `drizzle({ client, relations })`. Column names stay explicit so they match
8
- * `generate` (re-add the indexes below after regenerating).
9
- *
10
- * `.defaultNow()` is deprecated in 1.x and writes milliseconds, while
11
- * `mode: "timestamp"` reads seconds. `generate` still emits `.defaultNow()` —
12
- * replace it with `default(sql`(unixepoch())`)` after regenerating.
13
- *
14
- * `fumadb/cuid` is not a real fumadb export; map it to `@paralleldrive/cuid2`
15
- * in tsconfig (this package and `examples/with-db` already do).
16
- *
17
- * @see ../v1.ts
18
- * @see ./schema.prisma
19
- */
20
- import { defineRelations, sql } from "drizzle-orm";
21
- import {
22
- sqliteTable,
23
- text,
24
- blob,
25
- integer,
26
- uniqueIndex,
27
- index,
28
- } from "drizzle-orm/sqlite-core";
29
- import { createId } from "fumadb/cuid";
30
-
31
- export const storageObject = sqliteTable(
32
- "storage_object",
33
- {
34
- id: text("id", { length: 255 })
35
- .primaryKey()
36
- .notNull()
37
- .$defaultFn(() => createId()),
38
- scope: text("scope").notNull(),
39
- bucket: text("bucket").notNull(),
40
- key: text("key").notNull(),
41
- route: text("route").notNull(),
42
- contentType: text("content_type"),
43
- size: blob("size", { mode: "bigint" }),
44
- eTag: text("e_tag"),
45
- filename: text("filename"),
46
- status: text("status").notNull(),
47
- metadata: blob("metadata", { mode: "json" }),
48
- acl: text("acl"),
49
- uploadId: text("upload_id"),
50
- declaredSize: blob("declared_size", { mode: "bigint" }),
51
- confirmedAt: integer("confirmed_at", { mode: "timestamp" }),
52
- expiresAt: integer("expires_at", { mode: "timestamp" }),
53
- createdAt: integer("created_at", { mode: "timestamp" })
54
- .notNull()
55
- .default(sql`(unixepoch())`),
56
- updatedAt: integer("updated_at", { mode: "timestamp" })
57
- .notNull()
58
- .default(sql`(unixepoch())`),
59
- deletedAt: integer("deleted_at", { mode: "timestamp" }),
60
- },
61
- (table) => [
62
- uniqueIndex("storage_object_bucket_key_uk").on(table.bucket, table.key),
63
- // Consumer-added — FumaDB generate does not emit these (yet).
64
- index("storage_object_scope_status_created_idx").on(
65
- table.scope,
66
- table.status,
67
- table.createdAt,
68
- ),
69
- index("storage_object_scope_route_idx").on(table.scope, table.route),
70
- index("storage_object_status_expires_idx").on(
71
- table.status,
72
- table.expiresAt,
73
- ),
74
- index("storage_object_status_created_idx").on(
75
- table.status,
76
- table.createdAt,
77
- ),
78
- ],
79
- );
80
-
81
- export const private_dimah_s3_settings = sqliteTable(
82
- "private_dimah_s3_settings",
83
- {
84
- id: text("id", { length: 255 }).primaryKey().notNull(),
85
- version: text("version", { length: 255 }).notNull().default("1.0.0"),
86
- },
87
- );
88
-
89
- export const relations = defineRelations({
90
- storageObject,
91
- private_dimah_s3_settings,
92
- });