@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
|
@@ -1,37 +1,68 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { DbClientListResponse, DbClientObject
|
|
3
|
-
|
|
1
|
+
import type { DbStore } from "../store/create-db-store.js";
|
|
2
|
+
import type { DbClientFolder, DbClientListResponse, DbClientObject } from "../types/client.js";
|
|
3
|
+
import type { DbAttributesOptions } from "../types/plugin.js";
|
|
4
|
+
import type { StorageObject } from "../types/storage-object.js";
|
|
5
|
+
import type { ObjectAccess } from "./object-access";
|
|
6
|
+
import type { DbObjects } from "./public-stores";
|
|
7
|
+
import type { Quota } from "./quota";
|
|
8
|
+
/** Largest JSON size of stored attributes when `maxBytes` is not set. */
|
|
9
|
+
export declare const DEFAULT_ATTRIBUTES_MAX_BYTES = 16384;
|
|
10
|
+
export type CreateDatabaseEndpointsOptions<TSession, TAttributes, TClientAttributes> = {
|
|
11
|
+
store: Pick<DbStore<TAttributes>, "objects" | "folders">;
|
|
12
|
+
/** The public object store, whose `update` also creates the folder. */
|
|
13
|
+
objects: Pick<DbObjects<TAttributes>, "update">;
|
|
14
|
+
access: ObjectAccess<TSession, TAttributes>;
|
|
15
|
+
quota: Pick<Quota<TSession>, "limits">;
|
|
16
|
+
/** The plugin's `attributes` option. Without it, PATCH refuses `attributes`. */
|
|
17
|
+
attributes?: DbAttributesOptions<TAttributes, TClientAttributes>;
|
|
18
|
+
toClientObject: (object: StorageObject<TAttributes>) => DbClientObject<TClientAttributes>;
|
|
19
|
+
};
|
|
4
20
|
/**
|
|
5
|
-
*
|
|
21
|
+
* The `db` plugin's HTTP endpoints. Each one resolves the caller's scope and
|
|
22
|
+
* runs `authorize` before it reads or writes a row:
|
|
23
|
+
*
|
|
24
|
+
* - `GET /db/objects` (op `list`): one page of the scope's objects. The
|
|
25
|
+
* first page also carries usage, the quota, and the child folders (those
|
|
26
|
+
* whose name contains `search`, when it is set).
|
|
27
|
+
* - `GET /db/object` (op `read`): one object.
|
|
28
|
+
* - `PATCH /db/object` (op `update`): renames, moves, or sets attributes.
|
|
29
|
+
* - `POST /db/folder` and `DELETE /db/folder` (op `update`): creates or
|
|
30
|
+
* removes an empty folder.
|
|
6
31
|
*/
|
|
7
|
-
export declare function createDatabaseEndpoints(options: {
|
|
8
|
-
objects
|
|
9
|
-
resolveScope: ScopeResolver;
|
|
10
|
-
}): {
|
|
11
|
-
/** List objects + usage for the request scope (`resolveScope`). */
|
|
32
|
+
export declare function createDatabaseEndpoints<TSession, TAttributes, TClientAttributes>(options: CreateDatabaseEndpointsOptions<TSession, TAttributes, TClientAttributes>): {
|
|
33
|
+
/** One page of the caller's objects. `folder` omitted lists every folder. */
|
|
12
34
|
objects: import("better-call").StrictEndpoint<string, {
|
|
13
35
|
use: import("better-call").MiddlewareHandler[];
|
|
14
36
|
} & {
|
|
15
37
|
method: "GET";
|
|
16
38
|
} & {
|
|
17
39
|
query: import("better-call").StandardSchemaV1<{
|
|
40
|
+
folder?: string | undefined;
|
|
41
|
+
route?: string | undefined;
|
|
18
42
|
status?: "active" | "deleted" | "pending" | undefined;
|
|
43
|
+
contentType?: unknown;
|
|
44
|
+
search?: unknown;
|
|
45
|
+
sort?: string | {
|
|
46
|
+
field: "createdAt" | "filename" | "size" | "updatedAt";
|
|
47
|
+
direction: "asc" | "desc";
|
|
48
|
+
} | undefined;
|
|
19
49
|
limit?: string | number | undefined;
|
|
20
|
-
|
|
21
|
-
cursor?: string | undefined;
|
|
22
|
-
route?: string | undefined;
|
|
23
|
-
contentType?: string | undefined;
|
|
24
|
-
prefix?: string | undefined;
|
|
50
|
+
cursor?: unknown;
|
|
25
51
|
}, {
|
|
52
|
+
folder?: string | undefined;
|
|
53
|
+
route?: string | undefined;
|
|
26
54
|
status?: "active" | "deleted" | "pending" | undefined;
|
|
55
|
+
contentType?: unknown;
|
|
56
|
+
search?: unknown;
|
|
57
|
+
sort?: string | {
|
|
58
|
+
field: "createdAt" | "filename" | "size" | "updatedAt";
|
|
59
|
+
direction: "asc" | "desc";
|
|
60
|
+
} | undefined;
|
|
27
61
|
limit?: string | number | undefined;
|
|
28
|
-
|
|
29
|
-
cursor?: string | undefined;
|
|
30
|
-
route?: string | undefined;
|
|
31
|
-
contentType?: string | undefined;
|
|
32
|
-
prefix?: string | undefined;
|
|
62
|
+
cursor?: unknown;
|
|
33
63
|
}>;
|
|
34
|
-
}, DbClientListResponse
|
|
64
|
+
}, DbClientListResponse<TClientAttributes>>;
|
|
65
|
+
/** One object of the caller's scope. */
|
|
35
66
|
object: import("better-call").StrictEndpoint<string, {
|
|
36
67
|
use: import("better-call").MiddlewareHandler[];
|
|
37
68
|
} & {
|
|
@@ -45,7 +76,60 @@ export declare function createDatabaseEndpoints(options: {
|
|
|
45
76
|
bucket?: string | undefined;
|
|
46
77
|
}>;
|
|
47
78
|
}, {
|
|
48
|
-
object: DbClientObject
|
|
79
|
+
object: DbClientObject<TClientAttributes>;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Renames, moves, or sets the attributes of an active object. A move
|
|
83
|
+
* checks the target folder like an upload: validated, authorized, and
|
|
84
|
+
* created when missing.
|
|
85
|
+
*/
|
|
86
|
+
updateObject: import("better-call").StrictEndpoint<string, {
|
|
87
|
+
use: import("better-call").MiddlewareHandler[];
|
|
88
|
+
} & {
|
|
89
|
+
method: "PATCH";
|
|
90
|
+
body: import("better-call").StandardSchemaV1<{
|
|
91
|
+
key: string;
|
|
92
|
+
bucket?: string | undefined;
|
|
93
|
+
filename?: string | undefined;
|
|
94
|
+
folder?: string | null | undefined;
|
|
95
|
+
attributes?: Record<string, unknown> | null | undefined;
|
|
96
|
+
}, {
|
|
97
|
+
key: string;
|
|
98
|
+
bucket?: string | undefined;
|
|
99
|
+
filename?: string | undefined;
|
|
100
|
+
folder?: string | null | undefined;
|
|
101
|
+
attributes?: Record<string, unknown> | null | undefined;
|
|
102
|
+
}>;
|
|
103
|
+
}, {
|
|
104
|
+
object: DbClientObject<TClientAttributes>;
|
|
105
|
+
}>;
|
|
106
|
+
/** Creates a folder and its missing ancestors. */
|
|
107
|
+
createFolder: import("better-call").StrictEndpoint<string, {
|
|
108
|
+
use: import("better-call").MiddlewareHandler[];
|
|
109
|
+
} & {
|
|
110
|
+
method: "POST";
|
|
111
|
+
body: import("better-call").StandardSchemaV1<{
|
|
112
|
+
path: string;
|
|
113
|
+
}, {
|
|
114
|
+
path: string;
|
|
115
|
+
}>;
|
|
116
|
+
}, {
|
|
117
|
+
folder: DbClientFolder;
|
|
118
|
+
}>;
|
|
119
|
+
/** Removes an empty folder. A missing folder is not an error. */
|
|
120
|
+
deleteFolder: import("better-call").StrictEndpoint<string, {
|
|
121
|
+
use: import("better-call").MiddlewareHandler[];
|
|
122
|
+
} & {
|
|
123
|
+
method: "DELETE";
|
|
124
|
+
body: import("better-call").StandardSchemaV1<unknown, unknown>;
|
|
125
|
+
} & {
|
|
126
|
+
query: import("better-call").StandardSchemaV1<{
|
|
127
|
+
path: string;
|
|
128
|
+
}, {
|
|
129
|
+
path: string;
|
|
130
|
+
}>;
|
|
131
|
+
}, {
|
|
132
|
+
path: string;
|
|
49
133
|
}>;
|
|
50
134
|
};
|
|
51
135
|
//# sourceMappingURL=create-database-endpoints.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-database-endpoints.d.ts","sourceRoot":"","sources":["../../src/plugin/create-database-endpoints.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-database-endpoints.d.ts","sourceRoot":"","sources":["../../src/plugin/create-database-endpoints.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,cAAc,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AASrC,yEAAyE;AACzE,eAAO,MAAM,4BAA4B,QAAS,CAAC;AAEnD,MAAM,MAAM,8BAA8B,CACxC,QAAQ,EACR,WAAW,EACX,iBAAiB,IACf;IACF,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;IACzD,uEAAuE;IACvE,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,CAAC;IAChD,MAAM,EAAE,YAAY,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IAC5C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;IACvC,gFAAgF;IAChF,UAAU,CAAC,EAAE,mBAAmB,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;IACjE,cAAc,EAAE,CACd,MAAM,EAAE,aAAa,CAAC,WAAW,CAAC,KAC/B,cAAc,CAAC,iBAAiB,CAAC,CAAC;CACxC,CAAC;AAuDF;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EACR,WAAW,EACX,iBAAiB,EAEjB,OAAO,EAAE,8BAA8B,CACrC,QAAQ,EACR,WAAW,EACX,iBAAiB,CAClB;IAoCC,6EAA6E;IAC7E,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2CP,wCAAwC;IACxC,MAAM;;;;;;;;;;;;;gBAG2B,cAAc,CAAC,iBAAiB,CAAC;;IAiBlE;;;;OAIG;IACH,YAAY;;;;;;;;;;;;;;;;;;gBAGqB,cAAc,CAAC,iBAAiB,CAAC;;IA+ClE,kDAAkD;IAClD,YAAY;;;;;;;;;;gBAGqB,cAAc;;IAW/C,iEAAiE;IACjE,YAAY;;;;;;;;;;;;cAGmB,MAAM;;EAWxC"}
|
|
@@ -1,25 +1,43 @@
|
|
|
1
1
|
import { type S3Client } from "@aws-sdk/client-s3";
|
|
2
|
-
import type { DimahS3PluginHooks } from "@dimah-s3/server";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import type { DimahS3PluginHooks } from "@dimah-s3/server/plugins";
|
|
3
|
+
import type { DbStore } from "../store/create-db-store.js";
|
|
4
|
+
import type { ObjectAccess } from "./object-access";
|
|
5
|
+
import type { Quota } from "./quota";
|
|
6
|
+
import type { ScopeResolver } from "./scope";
|
|
7
|
+
/** What the hooks read from the dimah-s3 config, once `init` has run. */
|
|
8
|
+
export type DbRoutes = {
|
|
9
|
+
/** False when the route sets `plugins: { db: false }`. */
|
|
10
|
+
tracked: (route: string) => boolean;
|
|
11
|
+
/** The route's `plugins.db.replace`. */
|
|
12
|
+
replace: (route: string) => "overwrite" | undefined;
|
|
13
|
+
/** S3 client of the route. */
|
|
14
|
+
client: (route: string) => S3Client | undefined;
|
|
15
|
+
};
|
|
16
|
+
export type CreateDatabaseLifecycleHooksOptions<TSession, TAttributes> = {
|
|
17
|
+
store: Pick<DbStore<TAttributes>, "objects" | "folders">;
|
|
18
|
+
resolveScope: ScopeResolver<TSession>;
|
|
19
|
+
access: ObjectAccess<TSession, TAttributes>;
|
|
20
|
+
quota: Quota<TSession>;
|
|
21
|
+
/** @default "soft" */
|
|
9
22
|
deleteMode?: "soft" | "hard";
|
|
10
|
-
|
|
11
|
-
* S3 client for a route. Deleting a pending multipart row aborts its
|
|
12
|
-
* upload through this client.
|
|
13
|
-
*/
|
|
14
|
-
s3Client?: (route: string) => S3Client | undefined;
|
|
23
|
+
routes: DbRoutes;
|
|
15
24
|
};
|
|
16
25
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
26
|
+
* The `db` plugin's server hooks. They keep `storage_object` in step with
|
|
27
|
+
* S3 and check that every call acts on rows of its own scope:
|
|
28
|
+
*
|
|
29
|
+
* - `ticketSubject` binds upload tickets to the scope.
|
|
30
|
+
* - `upload.guard` checks the folder, ownership of the key, `authorize`
|
|
31
|
+
* (with the object an overwrite replaces), and the quota; `onStart` writes
|
|
32
|
+
* the pending row, then its folders. An overwrite leaves the active row in
|
|
33
|
+
* place until it is confirmed.
|
|
34
|
+
* - `confirmGuard` and `multipart.guard` accept only the row of the ticket's
|
|
35
|
+
* upload, or a confirm it already finished; `onConfirmed` checks the quota
|
|
36
|
+
* against the verified size, marks the row active, and retires the row of
|
|
37
|
+
* the `previousKey` the server deletes next.
|
|
38
|
+
* - `download.guard` and `delete.guard` check ownership; `onDeleted` aborts a
|
|
39
|
+
* multipart upload in flight and deletes the row. Deleting a deleted row
|
|
40
|
+
* again succeeds, like a plain delete.
|
|
19
41
|
*/
|
|
20
|
-
export declare function createDatabaseLifecycleHooks(options: CreateDatabaseLifecycleHooksOptions):
|
|
21
|
-
objects: StorageObjectStore;
|
|
22
|
-
hooks: DimahS3PluginHooks;
|
|
23
|
-
resolveScope: ScopeResolver;
|
|
24
|
-
};
|
|
42
|
+
export declare function createDatabaseLifecycleHooks<TSession, TAttributes>(options: CreateDatabaseLifecycleHooksOptions<TSession, TAttributes>): DimahS3PluginHooks;
|
|
25
43
|
//# sourceMappingURL=create-database-lifecycle-hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-database-lifecycle-hooks.d.ts","sourceRoot":"","sources":["../../src/plugin/create-database-lifecycle-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-database-lifecycle-hooks.d.ts","sourceRoot":"","sources":["../../src/plugin/create-database-lifecycle-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAQhF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAIvD,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,yEAAyE;AACzE,MAAM,MAAM,QAAQ,GAAG;IACrB,0DAA0D;IAC1D,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IACpC,wCAAwC;IACxC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,WAAW,GAAG,SAAS,CAAC;IACpD,8BAA8B;IAC9B,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,QAAQ,GAAG,SAAS,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,mCAAmC,CAAC,QAAQ,EAAE,WAAW,IAAI;IACvE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;IACzD,YAAY,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IACtC,MAAM,EAAE,YAAY,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IAC5C,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACvB,sBAAsB;IACtB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,MAAM,EAAE,QAAQ,CAAC;CAClB,CAAC;AA8DF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,WAAW,EAChE,OAAO,EAAE,mCAAmC,CAAC,QAAQ,EAAE,WAAW,CAAC,GAClE,kBAAkB,CA+OpB"}
|
package/dist/plugin/db.d.ts
CHANGED
|
@@ -1,134 +1,45 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { type DimahS3Plugin } from "@dimah-s3/server/plugins";
|
|
2
|
+
import type { DbPluginOptions } from "../types/plugin.js";
|
|
3
|
+
import { type DbFolders, type DbObjects } from "./public-stores";
|
|
4
|
+
import { type Purge } from "./purge";
|
|
5
|
+
/** What `db()` exposes on `s3.db` and `s3.context.db`. */
|
|
6
|
+
export type DbPluginContext<TAttributes = never> = {
|
|
7
|
+
/** The `storage_object` rows: listings, usage, and your own changes. */
|
|
8
|
+
objects: DbObjects<TAttributes>;
|
|
9
|
+
/** The `storage_folder` rows. */
|
|
10
|
+
folders: DbFolders;
|
|
6
11
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* already validated.
|
|
12
|
+
* Throws unless the database is at the schema this version needs. Call it
|
|
13
|
+
* at startup to fail fast; the first query runs the same check.
|
|
10
14
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* How long a `pending` row stays valid before the purge job may remove it.
|
|
14
|
-
* @default 86_400_000 (24h)
|
|
15
|
-
*/
|
|
16
|
-
pendingTtlMs?: number;
|
|
17
|
-
/**
|
|
18
|
-
* After a normal server delete (`api.delete` → S3 `DeleteObject`), how the
|
|
19
|
-
* plugin updates the DB row in `onDeleted`: `soft` keeps it with
|
|
20
|
-
* `status = "deleted"`; `hard` removes it. Does not change the S3 delete
|
|
21
|
-
* path — callers still use `api.delete`, not store helpers. Delete also
|
|
22
|
-
* clears a row whose object never landed, and aborts a pending multipart
|
|
23
|
-
* upload by its `uploadId`.
|
|
24
|
-
* @default "soft"
|
|
25
|
-
*/
|
|
26
|
-
deleteMode?: "soft" | "hard";
|
|
27
|
-
/**
|
|
28
|
-
* Optional scope usage caps. Numbers come from you — the plugin only
|
|
29
|
-
* checks. Wired as `upload.guard` after ownership.
|
|
30
|
-
*/
|
|
31
|
-
quota?: {
|
|
32
|
-
maxBytes?: number;
|
|
33
|
-
maxFiles?: number;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
export type DbPluginContext = {
|
|
37
|
-
/** `storage_object` data-access layer — listings, quota, resume, custom routes. */
|
|
38
|
-
objects: StorageObjectStore;
|
|
39
|
-
/** Underlying FumaDB client (or the store when one was passed as `client`). */
|
|
40
|
-
client: DimahS3DbClient | StorageObjectStore;
|
|
41
|
-
};
|
|
15
|
+
checkSchema: () => Promise<void>;
|
|
16
|
+
} & Purge;
|
|
42
17
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
18
|
+
* Database plugin for `dimahS3()`. It tracks each upload in `storage_object`
|
|
19
|
+
* from start to delete, binds upload tickets to the caller's scope, and
|
|
20
|
+
* rejects calls on objects of another scope. It mounts `GET /db/objects`,
|
|
21
|
+
* `GET /db/object`, `PATCH /db/object`, and the folder endpoints for
|
|
22
|
+
* `dbClient()`.
|
|
47
23
|
*
|
|
48
|
-
*
|
|
49
|
-
* {@link dbClient}.
|
|
24
|
+
* Every route is tracked unless it sets `plugins: { db: false }`.
|
|
50
25
|
*
|
|
51
26
|
* ```ts
|
|
52
27
|
* const s3 = dimahS3({
|
|
53
28
|
* client: awsS3,
|
|
54
29
|
* bucket,
|
|
55
30
|
* plugins: [
|
|
56
|
-
* db({
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
31
|
+
* db({
|
|
32
|
+
* client: DimahS3DB.client(adapter),
|
|
33
|
+
* getSession: (request) => auth.getSession(request),
|
|
34
|
+
* resolveScope: ({ session }) => (session ? `user:${session.userId}` : null),
|
|
35
|
+
* quota: { maxBytes: 1024 ** 3 },
|
|
61
36
|
* }),
|
|
62
|
-
*
|
|
37
|
+
* ],
|
|
38
|
+
* routes: { uploads: route({ upload: true, download: true, delete: true }) },
|
|
63
39
|
* });
|
|
64
40
|
*
|
|
65
|
-
* s3.db.
|
|
66
|
-
* s3.context.db === s3.db;
|
|
41
|
+
* await s3.db.purgeStale();
|
|
67
42
|
* ```
|
|
68
43
|
*/
|
|
69
|
-
export declare function db(options: DbPluginOptions):
|
|
70
|
-
objects: StorageObjectStore;
|
|
71
|
-
client: import("fumadb").FumaDB<import("fumadb/schema").Schema<"1.0.0", {
|
|
72
|
-
storageObject: import("fumadb/schema").Table<{
|
|
73
|
-
id: import("fumadb/schema").IdColumn<"varchar(255)", string | null, string>;
|
|
74
|
-
scope: import("fumadb/schema").Column<"string", string, string>;
|
|
75
|
-
bucket: import("fumadb/schema").Column<"string", string, string>;
|
|
76
|
-
key: import("fumadb/schema").Column<"string", string, string>;
|
|
77
|
-
route: import("fumadb/schema").Column<"string", string, string>;
|
|
78
|
-
contentType: import("fumadb/schema").Column<"string", string | null, string | null>;
|
|
79
|
-
size: import("fumadb/schema").Column<"bigint", bigint | null, bigint | null>;
|
|
80
|
-
eTag: import("fumadb/schema").Column<"string", string | null, string | null>;
|
|
81
|
-
filename: import("fumadb/schema").Column<"string", string | null, string | null>;
|
|
82
|
-
status: import("fumadb/schema").Column<"string", string, string>;
|
|
83
|
-
metadata: import("fumadb/schema").Column<"json", unknown, unknown>;
|
|
84
|
-
acl: import("fumadb/schema").Column<"string", string | null, string | null>;
|
|
85
|
-
uploadId: import("fumadb/schema").Column<"string", string | null, string | null>;
|
|
86
|
-
declaredSize: import("fumadb/schema").Column<"bigint", bigint | null, bigint | null>;
|
|
87
|
-
confirmedAt: import("fumadb/schema").Column<"timestamp", Date | null, Date | null>;
|
|
88
|
-
expiresAt: import("fumadb/schema").Column<"timestamp", Date | null, Date | null>;
|
|
89
|
-
createdAt: import("fumadb/schema").Column<"timestamp", Date | null, Date>;
|
|
90
|
-
updatedAt: import("fumadb/schema").Column<"timestamp", Date | null, Date>;
|
|
91
|
-
deletedAt: import("fumadb/schema").Column<"timestamp", Date | null, Date | null>;
|
|
92
|
-
}, {}>;
|
|
93
|
-
}>[]> | StorageObjectStore;
|
|
94
|
-
}, {
|
|
95
|
-
objects: import("better-call").StrictEndpoint<string, {
|
|
96
|
-
use: import("better-call").MiddlewareHandler[];
|
|
97
|
-
} & {
|
|
98
|
-
method: "GET";
|
|
99
|
-
} & {
|
|
100
|
-
query: import("better-call").StandardSchemaV1<{
|
|
101
|
-
status?: "active" | "deleted" | "pending" | undefined;
|
|
102
|
-
limit?: string | number | undefined;
|
|
103
|
-
offset?: string | number | undefined;
|
|
104
|
-
cursor?: string | undefined;
|
|
105
|
-
route?: string | undefined;
|
|
106
|
-
contentType?: string | undefined;
|
|
107
|
-
prefix?: string | undefined;
|
|
108
|
-
}, {
|
|
109
|
-
status?: "active" | "deleted" | "pending" | undefined;
|
|
110
|
-
limit?: string | number | undefined;
|
|
111
|
-
offset?: string | number | undefined;
|
|
112
|
-
cursor?: string | undefined;
|
|
113
|
-
route?: string | undefined;
|
|
114
|
-
contentType?: string | undefined;
|
|
115
|
-
prefix?: string | undefined;
|
|
116
|
-
}>;
|
|
117
|
-
}, import("../types/storage-object.js").DbClientListResponse>;
|
|
118
|
-
object: import("better-call").StrictEndpoint<string, {
|
|
119
|
-
use: import("better-call").MiddlewareHandler[];
|
|
120
|
-
} & {
|
|
121
|
-
method: "GET";
|
|
122
|
-
} & {
|
|
123
|
-
query: import("better-call").StandardSchemaV1<{
|
|
124
|
-
key: string;
|
|
125
|
-
bucket?: string | undefined;
|
|
126
|
-
}, {
|
|
127
|
-
key: string;
|
|
128
|
-
bucket?: string | undefined;
|
|
129
|
-
}>;
|
|
130
|
-
}, {
|
|
131
|
-
object: import("../types/storage-object.js").DbClientObject;
|
|
132
|
-
}>;
|
|
133
|
-
}>;
|
|
44
|
+
export declare function db<TSession = undefined, TAttributes = never, TClientAttributes = TAttributes>(options: DbPluginOptions<TSession, TAttributes, TClientAttributes>): DimahS3Plugin<"db", DbPluginContext<TAttributes>>;
|
|
134
45
|
//# sourceMappingURL=db.d.ts.map
|
package/dist/plugin/db.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/plugin/db.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/plugin/db.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,aAAa,EAEnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AAQtE,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,KAAK,KAAK,EAAE,MAAM,SAAS,CAAC;AAKlD,0DAA0D;AAC1D,MAAM,MAAM,eAAe,CAAC,WAAW,GAAG,KAAK,IAAI;IACjD,wEAAwE;IACxE,OAAO,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;IAChC,iCAAiC;IACjC,OAAO,EAAE,SAAS,CAAC;IACnB;;;OAGG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC,GAAG,KAAK,CAAC;AAEV;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,EAAE,CAChB,QAAQ,GAAG,SAAS,EACpB,WAAW,GAAG,KAAK,EACnB,iBAAiB,GAAG,WAAW,EAE/B,OAAO,EAAE,eAAe,CAAC,QAAQ,EAAE,WAAW,EAAE,iBAAiB,CAAC,GACjE,aAAa,CAAC,IAAI,EAAE,eAAe,CAAC,WAAW,CAAC,CAAC,CA0DnD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ObjectRef, StorageObjectStore } from "../store/object-store.js";
|
|
2
|
+
import type { AuthorizeContext, DbPluginOptions } from "../types/plugin.js";
|
|
3
|
+
import type { StorageObject } from "../types/storage-object.js";
|
|
4
|
+
import type { ResolvedScope, ScopeCall, ScopeResolver, ScopeTarget } from "./scope";
|
|
5
|
+
/** What a call targets: its scope target, plus what `authorize` checks. */
|
|
6
|
+
export type AccessTarget = ScopeTarget & Pick<AuthorizeContext, "key" | "folder" | "clientMetadata">;
|
|
7
|
+
export type CreateObjectAccessOptions<TSession, TAttributes> = Pick<DbPluginOptions<TSession, TAttributes>, "authorize"> & {
|
|
8
|
+
objects: Pick<StorageObjectStore<TAttributes>, "find">;
|
|
9
|
+
resolveScope: ScopeResolver<TSession>;
|
|
10
|
+
};
|
|
11
|
+
/** A row the call may act on, with the scope it was checked against. */
|
|
12
|
+
export type AccessibleObject<TSession, TAttributes> = {
|
|
13
|
+
scope: ResolvedScope<TSession>;
|
|
14
|
+
object: StorageObject<TAttributes>;
|
|
15
|
+
};
|
|
16
|
+
/** Scope and ownership checks shared by the db hooks and endpoints. */
|
|
17
|
+
export type ObjectAccess<TSession, TAttributes> = {
|
|
18
|
+
/**
|
|
19
|
+
* Resolves the scope and runs `authorize` with no object: uploads,
|
|
20
|
+
* listings, and folder changes.
|
|
21
|
+
* @throws `UNAUTHORIZED` or `FORBIDDEN`.
|
|
22
|
+
*/
|
|
23
|
+
scope: (call: ScopeCall, target: AccessTarget) => Promise<ResolvedScope<TSession>>;
|
|
24
|
+
/**
|
|
25
|
+
* Resolves the scope and loads the row at `ref`, which must belong to it.
|
|
26
|
+
* A row of another scope is `OBJECT_NOT_FOUND`, the same as no row, so a
|
|
27
|
+
* caller cannot learn which keys other scopes hold. A `deleted` row is
|
|
28
|
+
* `OBJECT_NOT_FOUND` too, unless `allowDeleted` is set.
|
|
29
|
+
* @throws `UNAUTHORIZED`, `OBJECT_NOT_FOUND`, or `FORBIDDEN` from
|
|
30
|
+
* `authorize`.
|
|
31
|
+
*/
|
|
32
|
+
object: (call: ScopeCall, target: AccessTarget, ref: ObjectRef, options?: {
|
|
33
|
+
allowDeleted?: boolean;
|
|
34
|
+
}) => Promise<AccessibleObject<TSession, TAttributes>>;
|
|
35
|
+
/**
|
|
36
|
+
* Checks that `object` belongs to the scope (`OBJECT_NOT_FOUND`
|
|
37
|
+
* otherwise), then runs `authorize` with it.
|
|
38
|
+
*/
|
|
39
|
+
assertOwner: (scope: ResolvedScope<TSession>, object: StorageObject<TAttributes>, target?: AccessTarget) => Promise<void>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Creates the access checks. A row belongs to the scope that wrote it, and
|
|
43
|
+
* `authorize` can only narrow that: it runs after the ownership check.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createObjectAccess<TSession, TAttributes>(options: CreateObjectAccessOptions<TSession, TAttributes>): ObjectAccess<TSession, TAttributes>;
|
|
46
|
+
//# sourceMappingURL=object-access.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-access.d.ts","sourceRoot":"","sources":["../../src/plugin/object-access.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EACT,aAAa,EACb,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB,2EAA2E;AAC3E,MAAM,MAAM,YAAY,GAAG,WAAW,GACpC,IAAI,CAAC,gBAAgB,EAAE,KAAK,GAAG,QAAQ,GAAG,gBAAgB,CAAC,CAAC;AAE9D,MAAM,MAAM,yBAAyB,CAAC,QAAQ,EAAE,WAAW,IAAI,IAAI,CACjE,eAAe,CAAC,QAAQ,EAAE,WAAW,CAAC,EACtC,WAAW,CACZ,GAAG;IACF,OAAO,EAAE,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC;IACvD,YAAY,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;CACvC,CAAC;AAEF,wEAAwE;AACxE,MAAM,MAAM,gBAAgB,CAAC,QAAQ,EAAE,WAAW,IAAI;IACpD,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC/B,MAAM,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;CACpC,CAAC;AAEF,uEAAuE;AACvE,MAAM,MAAM,YAAY,CAAC,QAAQ,EAAE,WAAW,IAAI;IAChD;;;;OAIG;IACH,KAAK,EAAE,CACL,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,YAAY,KACjB,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;IACtC;;;;;;;OAOG;IACH,MAAM,EAAE,CACN,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,SAAS,EACd,OAAO,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,KACjC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;IACtD;;;OAGG;IACH,WAAW,EAAE,CACX,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC,EAC9B,MAAM,EAAE,aAAa,CAAC,WAAW,CAAC,EAClC,MAAM,CAAC,EAAE,YAAY,KAClB,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,WAAW,EACtD,OAAO,EAAE,yBAAyB,CAAC,QAAQ,EAAE,WAAW,CAAC,GACxD,YAAY,CAAC,QAAQ,EAAE,WAAW,CAAC,CA+CrC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DbStore } from "../store/create-db-store.js";
|
|
2
|
+
import type { StorageFolderStore } from "../store/folder-store.js";
|
|
3
|
+
import type { ObjectRef, StorageObjectStore, UpdateObjectInput } from "../store/object-store.js";
|
|
4
|
+
import type { StorageObject } from "../types/storage-object.js";
|
|
5
|
+
/**
|
|
6
|
+
* `s3.db.objects`: the `storage_object` rows, for your routes, jobs, and
|
|
7
|
+
* scripts. It takes the scope as an argument, so it reads any scope. It
|
|
8
|
+
* never calls S3, and the upload lifecycle stays with the plugin: delete
|
|
9
|
+
* files through `s3.api.delete`.
|
|
10
|
+
*/
|
|
11
|
+
export type DbObjects<TAttributes = never> = Pick<StorageObjectStore<TAttributes>, "find" | "list" | "count" | "getUsage"> & {
|
|
12
|
+
/**
|
|
13
|
+
* Renames, moves, or sets the attributes of an active row, like
|
|
14
|
+
* `PATCH /db/object` without its access check. A folder is validated
|
|
15
|
+
* (`FOLDER_INVALID`) and created when missing. With `id` or `scope`, only
|
|
16
|
+
* that row changes. Returns `null` when no active row matches.
|
|
17
|
+
*/
|
|
18
|
+
update: (ref: ObjectRef & {
|
|
19
|
+
id?: string;
|
|
20
|
+
scope?: string;
|
|
21
|
+
}, input: UpdateObjectInput<TAttributes>) => Promise<StorageObject<TAttributes> | null>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* `s3.db.folders`: the `storage_folder` rows. Paths are validated as on the
|
|
25
|
+
* HTTP endpoints (`FOLDER_INVALID`); the root (`null`) is never stored.
|
|
26
|
+
*/
|
|
27
|
+
export type DbFolders = StorageFolderStore;
|
|
28
|
+
/** The public stores over the plugin's stores. */
|
|
29
|
+
export declare function createPublicStores<TAttributes>(store: Pick<DbStore<TAttributes>, "objects" | "folders">): {
|
|
30
|
+
objects: DbObjects<TAttributes>;
|
|
31
|
+
folders: DbFolders;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=public-stores.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-stores.d.ts","sourceRoot":"","sources":["../../src/plugin/public-stores.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EACV,SAAS,EACT,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,MAAM,SAAS,CAAC,WAAW,GAAG,KAAK,IAAI,IAAI,CAC/C,kBAAkB,CAAC,WAAW,CAAC,EAC/B,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CACvC,GAAG;IACF;;;;;OAKG;IACH,MAAM,EAAE,CACN,GAAG,EAAE,SAAS,GAAG;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAChD,KAAK,EAAE,iBAAiB,CAAC,WAAW,CAAC,KAClC,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;CACjD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,kBAAkB,CAAC;AAS3C,kDAAkD;AAClD,wBAAgB,kBAAkB,CAAC,WAAW,EAC5C,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC,GACvD;IAAE,OAAO,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;IAAC,OAAO,EAAE,SAAS,CAAA;CAAE,CAoCzD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type S3Client } from "@aws-sdk/client-s3";
|
|
2
|
+
import type { DimahS3Logger } from "@dimah-s3/server";
|
|
3
|
+
import { type StorageObjectStore } from "../store/object-store.js";
|
|
4
|
+
export type CreatePurgeOptions = {
|
|
5
|
+
objects: Pick<StorageObjectStore<unknown>, "findStale" | "claimStale" | "deletePurged" | "cancelUpload" | "discardUpload" | "pruneDeleted">;
|
|
6
|
+
/** S3 client of a route. `undefined` fails the row, which stays claimed. */
|
|
7
|
+
client: (route: string) => S3Client | undefined;
|
|
8
|
+
/** Where a row that fails to purge is reported. */
|
|
9
|
+
logger: () => DimahS3Logger | undefined;
|
|
10
|
+
};
|
|
11
|
+
export type PurgeStaleOptions = {
|
|
12
|
+
/** Most rows one run handles. @default 100 */
|
|
13
|
+
limit?: number;
|
|
14
|
+
};
|
|
15
|
+
export type PruneDeletedOptions = {
|
|
16
|
+
/** Soft-deleted rows deleted before this time are removed (a `Date` or epoch milliseconds). */
|
|
17
|
+
olderThan: Date | number;
|
|
18
|
+
};
|
|
19
|
+
/** What one `purgeStale` run did. */
|
|
20
|
+
export type PurgeStaleResult = {
|
|
21
|
+
/** Uploads cleaned up. */
|
|
22
|
+
purged: number;
|
|
23
|
+
/** Rows that failed. They stay claimed and are retried after the claim lapses. */
|
|
24
|
+
failed: number;
|
|
25
|
+
/** Rows that another run claimed, or that were confirmed or written again meanwhile. */
|
|
26
|
+
skipped: number;
|
|
27
|
+
/** True when the run hit `limit`, so more stale rows may be waiting. */
|
|
28
|
+
more: boolean;
|
|
29
|
+
};
|
|
30
|
+
/** The cleanup jobs on `s3.db`. */
|
|
31
|
+
export type Purge = {
|
|
32
|
+
/**
|
|
33
|
+
* Cleans up uploads past their confirm deadline. It aborts the multipart
|
|
34
|
+
* upload, and deletes the object only while it still carries the upload's
|
|
35
|
+
* marker. A pending row is removed. An unconfirmed overwrite keeps the
|
|
36
|
+
* active row and its object, unless the overwrite's object already
|
|
37
|
+
* replaced it. A row confirmed meanwhile is kept. A row that fails stays
|
|
38
|
+
* claimed, is logged, and is retried once the claim lapses, 15 minutes
|
|
39
|
+
* later.
|
|
40
|
+
*/
|
|
41
|
+
purgeStale: (options?: PurgeStaleOptions) => Promise<PurgeStaleResult>;
|
|
42
|
+
/** Removes soft-deleted rows older than `olderThan`. */
|
|
43
|
+
pruneDeleted: (options: PruneDeletedOptions) => Promise<{
|
|
44
|
+
pruned: number;
|
|
45
|
+
}>;
|
|
46
|
+
};
|
|
47
|
+
/** Creates the purge jobs. */
|
|
48
|
+
export declare function createPurge(options: CreatePurgeOptions): Purge;
|
|
49
|
+
//# sourceMappingURL=purge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"purge.d.ts","sourceRoot":"","sources":["../../src/plugin/purge.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAMtD,OAAO,EAEL,KAAK,kBAAkB,EAExB,MAAM,sBAAsB,CAAC;AAG9B,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,IAAI,CACX,kBAAkB,CAAC,OAAO,CAAC,EACzB,WAAW,GACX,YAAY,GACZ,cAAc,GACd,cAAc,GACd,eAAe,GACf,cAAc,CACjB,CAAC;IACF,4EAA4E;IAC5E,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,QAAQ,GAAG,SAAS,CAAC;IAChD,mDAAmD;IACnD,MAAM,EAAE,MAAM,aAAa,GAAG,SAAS,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,8CAA8C;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,+FAA+F;IAC/F,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;CAC1B,CAAC;AAEF,qCAAqC;AACrC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,0BAA0B;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,kFAAkF;IAClF,MAAM,EAAE,MAAM,CAAC;IACf,wFAAwF;IACxF,OAAO,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,mCAAmC;AACnC,MAAM,MAAM,KAAK,GAAG;IAClB;;;;;;;;OAQG;IACH,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,iBAAiB,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACvE,wDAAwD;IACxD,YAAY,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC7E,CAAC;AA6DF,8BAA8B;AAC9B,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,KAAK,CAiE9D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ObjectRef, StorageObjectStore } from "../store/object-store.js";
|
|
2
|
+
import type { DbQuota } from "../types/client.js";
|
|
3
|
+
import type { DbQuotaOption } from "../types/plugin.js";
|
|
4
|
+
import type { ResolvedScope } from "./scope";
|
|
5
|
+
/** An upload checked against the caps of its scope. */
|
|
6
|
+
export type QuotaInput = {
|
|
7
|
+
/** Bytes the upload adds: the declared size, or the verified size at confirm. */
|
|
8
|
+
size: number;
|
|
9
|
+
/** The row the upload writes, left out of the usage. */
|
|
10
|
+
excluding: ObjectRef;
|
|
11
|
+
};
|
|
12
|
+
/** The plugin's `quota` option, resolved per scope. */
|
|
13
|
+
export type Quota<TSession> = {
|
|
14
|
+
/** Caps for the scope, or `null` when there are none. */
|
|
15
|
+
limits: (scope: ResolvedScope<TSession>) => Promise<DbQuota | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Checks that one more file of `size` bytes fits the caps. Usage counts
|
|
18
|
+
* active rows and pending rows that have not expired.
|
|
19
|
+
* @throws `QUOTA_EXCEEDED` with `limit: "files"` or `limit: "bytes"`.
|
|
20
|
+
*/
|
|
21
|
+
assert: (scope: ResolvedScope<TSession>, input: QuotaInput) => Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
/** Creates the quota checks over `objects`. Without `option`, nothing is capped. */
|
|
24
|
+
export declare function createQuota<TSession>(objects: Pick<StorageObjectStore, "getUsage">, option: DbQuotaOption<TSession> | undefined): Quota<TSession>;
|
|
25
|
+
//# sourceMappingURL=quota.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota.d.ts","sourceRoot":"","sources":["../../src/plugin/quota.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,uDAAuD;AACvD,MAAM,MAAM,UAAU,GAAG;IACvB,iFAAiF;IACjF,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF,uDAAuD;AACvD,MAAM,MAAM,KAAK,CAAC,QAAQ,IAAI;IAC5B,yDAAyD;IACzD,MAAM,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IACpE;;;;OAIG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9E,CAAC;AAEF,oFAAoF;AACpF,wBAAgB,WAAW,CAAC,QAAQ,EAClC,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAAE,UAAU,CAAC,EAC7C,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,SAAS,GAC1C,KAAK,CAAC,QAAQ,CAAC,CA6BjB"}
|