@dimah-s3/db 1.7.1 → 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.
- package/README.md +62 -17
- package/dist/adapters/drizzle.d.ts +7 -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 +33 -4
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +192 -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 +1024 -0
- package/dist/drizzle/mysql.d.ts.map +1 -0
- package/dist/drizzle/mysql.js +123 -0
- package/dist/drizzle/mysql.js.map +1 -0
- package/dist/drizzle/pg.d.ts +963 -0
- package/dist/drizzle/pg.d.ts.map +1 -0
- package/dist/drizzle/pg.js +104 -0
- package/dist/drizzle/pg.js.map +1 -0
- package/dist/drizzle/shared.d.ts +16 -0
- package/dist/drizzle/shared.d.ts.map +1 -0
- package/dist/drizzle/sqlite.d.ts +1023 -0
- package/dist/drizzle/sqlite.d.ts.map +1 -0
- package/dist/drizzle/sqlite.js +107 -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 +47 -5
- 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 +1452 -620
- 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/v1.d.ts +1 -8
- package/dist/schema/v1.d.ts.map +1 -1
- package/dist/schema/v2.d.ts +64 -0
- package/dist/schema/v2.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 +50 -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/sql/upgrade/1.0.0-2.0.0/mysql.sql +71 -0
- package/sql/upgrade/1.0.0-2.0.0/pg.sql +47 -0
- package/sql/upgrade/1.0.0-2.0.0/sqlite.sql +119 -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/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,208 @@
|
|
|
1
|
+
import type { AbstractQuery, FindManyOptions } from "fumadb/query";
|
|
2
|
+
import type { v2 } from "../schema/v2.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 schema 2.0.0. */
|
|
6
|
+
export type DbOrm = AbstractQuery<typeof v2>;
|
|
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 v2.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,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAUhC,uCAAuC;AACvC,MAAM,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC;AAE7C,2DAA2D;AAC3D,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC;AAE5C,qDAAqD;AACrD,MAAM,MAAM,gBAAgB,GAAG,UAAU,CACvC,WAAW,CAAC,eAAe,CAAC,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAC3E,CAAC,CAAC,CAAC,CAAC;AAEL,KAAK,SA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;;;OAIG;IACH,aAAa,EAAE,CAAC,GAAG,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD;;;;OAIG;IACH,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE;QACpB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,KAAK,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAC5C;;;;;;;;OAQG;IACH,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;IACvE,+DAA+D;IAC/D,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,2EAA2E;IAC3E,YAAY,EAAE,CAAC,SAAS,EAAE,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACpD,CAAC;AAiBF;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,iBAK3D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,OAAO,CAMnE;AAED,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,CAAC,EAAE,gBAAgB,EAAE,GAAG,EAAE,IAAI,GAAG,SAAS,CAKpE;AAwFD,wDAAwD;AACxD,wBAAgB,iBAAiB,CAAC,WAAW,GAAG,KAAK,EACnD,MAAM,EAAE,QAAQ,GACf,kBAAkB,CAAC,WAAW,CAAC,CAqZjC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type DimahS3DbClient } from "../fuma-db.js";
|
|
2
|
+
/**
|
|
3
|
+
* Throws unless the database is at the schema the stores use
|
|
4
|
+
* ({@link DB_SCHEMA_VERSION}). A 1.x database must be upgraded first.
|
|
5
|
+
*/
|
|
6
|
+
export declare function checkSchemaVersion(client: DimahS3DbClient): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=schema-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-version.d.ts","sourceRoot":"","sources":["../../src/store/schema-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAEpE;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,IAAI,CAAC,CAoBf"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { S3RequestOptions, S3RouteName } from "@dimah-s3/core";
|
|
2
|
+
import type { StorageObjectStatus } from "./storage-object";
|
|
3
|
+
/** A row status the browser can see. Rows that purge has claimed stay internal. */
|
|
4
|
+
export type DbClientObjectStatus = Exclude<StorageObjectStatus, "purging">;
|
|
5
|
+
/**
|
|
6
|
+
* Browser-facing object row. Narrower than `StorageObject`: no scope,
|
|
7
|
+
* S3 metadata, or upload state. `attributes` are the plugin's
|
|
8
|
+
* `attributes.toClient` output.
|
|
9
|
+
*/
|
|
10
|
+
export type DbClientObject<TClientAttributes = never> = {
|
|
11
|
+
id: string;
|
|
12
|
+
bucket: string;
|
|
13
|
+
key: string;
|
|
14
|
+
route: string;
|
|
15
|
+
/** Logical folder path. `null` is the root. */
|
|
16
|
+
folder: string | null;
|
|
17
|
+
filename: string;
|
|
18
|
+
contentType: string | null;
|
|
19
|
+
/** Verified size. `null` while the object is pending. */
|
|
20
|
+
size: number | null;
|
|
21
|
+
declaredSize: number | null;
|
|
22
|
+
status: DbClientObjectStatus;
|
|
23
|
+
attributes: TClientAttributes | null;
|
|
24
|
+
/** ISO 8601 timestamp. */
|
|
25
|
+
createdAt: string;
|
|
26
|
+
/** ISO 8601 timestamp. */
|
|
27
|
+
updatedAt: string;
|
|
28
|
+
};
|
|
29
|
+
/** Browser-facing folder row. */
|
|
30
|
+
export type DbClientFolder = {
|
|
31
|
+
path: string;
|
|
32
|
+
name: string;
|
|
33
|
+
/** Path of the containing folder. `null` is the root. */
|
|
34
|
+
parent: string | null;
|
|
35
|
+
/** ISO 8601 timestamp. */
|
|
36
|
+
createdAt: string;
|
|
37
|
+
};
|
|
38
|
+
/** Column a listing can be ordered by. */
|
|
39
|
+
export type DbListSortField = "createdAt" | "updatedAt" | "size" | "filename";
|
|
40
|
+
/**
|
|
41
|
+
* Listing order. Ties break on row `id` in the same direction. Rows with no
|
|
42
|
+
* value for the field (a pending row's `size`) come last in both directions.
|
|
43
|
+
*/
|
|
44
|
+
export type DbListSort = {
|
|
45
|
+
field: DbListSortField;
|
|
46
|
+
direction: "asc" | "desc";
|
|
47
|
+
};
|
|
48
|
+
/** Bytes and file count of a scope. Expired pending rows are not counted. */
|
|
49
|
+
export type DbUsage = {
|
|
50
|
+
totalBytes: number;
|
|
51
|
+
objectCount: number;
|
|
52
|
+
};
|
|
53
|
+
/** Caps for one scope. Omit a field for no cap. */
|
|
54
|
+
export type DbQuota = {
|
|
55
|
+
maxBytes?: number;
|
|
56
|
+
maxFiles?: number;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Query for `GET /db/objects`. The scope is not an input: the server
|
|
60
|
+
* resolves it from the request.
|
|
61
|
+
*/
|
|
62
|
+
export type DbClientListInput = {
|
|
63
|
+
/**
|
|
64
|
+
* Folder to list. `null` (or `""`) is the root. Omit for a flat list of
|
|
65
|
+
* every folder.
|
|
66
|
+
*/
|
|
67
|
+
folder?: string | null;
|
|
68
|
+
route?: S3RouteName;
|
|
69
|
+
/** @default "active" */
|
|
70
|
+
status?: DbClientObjectStatus;
|
|
71
|
+
/** Exact type, or `type/*` for every subtype (`image/*`). */
|
|
72
|
+
contentType?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Text the `filename` contains. The database decides case: PostgreSQL
|
|
75
|
+
* matches it exactly, SQLite ignores ASCII case, and MySQL follows the
|
|
76
|
+
* column collation.
|
|
77
|
+
*/
|
|
78
|
+
search?: string;
|
|
79
|
+
/** @default { field: "createdAt", direction: "desc" } */
|
|
80
|
+
sort?: DbListSort;
|
|
81
|
+
/** Rows per page, 1 to 100. @default 50 */
|
|
82
|
+
limit?: number;
|
|
83
|
+
/**
|
|
84
|
+
* `nextCursor` from the previous page. A cursor from other filters is
|
|
85
|
+
* ignored, and the list starts again at the first page.
|
|
86
|
+
*/
|
|
87
|
+
cursor?: string;
|
|
88
|
+
};
|
|
89
|
+
/** One page of `GET /db/objects`. */
|
|
90
|
+
export type DbClientListResponse<TClientAttributes = never> = {
|
|
91
|
+
objects: DbClientObject<TClientAttributes>[];
|
|
92
|
+
/** `null` on the last page. */
|
|
93
|
+
nextCursor: string | null;
|
|
94
|
+
/**
|
|
95
|
+
* Direct child folders of `folder`, at most 1000, and only those whose
|
|
96
|
+
* name contains `search` when it is set. First page only.
|
|
97
|
+
*/
|
|
98
|
+
folders?: DbClientFolder[];
|
|
99
|
+
/** First page only. */
|
|
100
|
+
usage?: DbUsage;
|
|
101
|
+
/** Caps for the scope, `null` when there are none. First page only. */
|
|
102
|
+
limits?: DbQuota | null;
|
|
103
|
+
};
|
|
104
|
+
/** Identifies one object. `bucket` defaults to the only configured bucket. */
|
|
105
|
+
export type DbClientGetInput = {
|
|
106
|
+
key: string;
|
|
107
|
+
bucket?: string;
|
|
108
|
+
};
|
|
109
|
+
/** Body of `PATCH /db/object`. Omitted fields stay as they are. */
|
|
110
|
+
export type DbClientUpdateInput = DbClientGetInput & {
|
|
111
|
+
filename?: string;
|
|
112
|
+
/** Folder path. `null` moves the object to the root. */
|
|
113
|
+
folder?: string | null;
|
|
114
|
+
/**
|
|
115
|
+
* Replaces the attributes, checked by the plugin's `attributes.schema`.
|
|
116
|
+
* `null` clears them.
|
|
117
|
+
*/
|
|
118
|
+
attributes?: Record<string, unknown> | null;
|
|
119
|
+
};
|
|
120
|
+
/** Body of `POST /db/folder` and query of `DELETE /db/folder`. */
|
|
121
|
+
export type DbClientFolderInput = {
|
|
122
|
+
path: string;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* The db endpoints as client actions (`api.db`). Each takes the same
|
|
126
|
+
* per-call `{ signal, headers }` as the core methods.
|
|
127
|
+
*/
|
|
128
|
+
export type DbClientActions<TClientAttributes = never> = {
|
|
129
|
+
listObjects(input?: DbClientListInput, options?: S3RequestOptions): Promise<DbClientListResponse<TClientAttributes>>;
|
|
130
|
+
getObject(input: DbClientGetInput, options?: S3RequestOptions): Promise<{
|
|
131
|
+
object: DbClientObject<TClientAttributes>;
|
|
132
|
+
}>;
|
|
133
|
+
updateObject(input: DbClientUpdateInput, options?: S3RequestOptions): Promise<{
|
|
134
|
+
object: DbClientObject<TClientAttributes>;
|
|
135
|
+
}>;
|
|
136
|
+
createFolder(input: DbClientFolderInput, options?: S3RequestOptions): Promise<{
|
|
137
|
+
folder: DbClientFolder;
|
|
138
|
+
}>;
|
|
139
|
+
deleteFolder(input: DbClientFolderInput, options?: S3RequestOptions): Promise<{
|
|
140
|
+
path: string;
|
|
141
|
+
}>;
|
|
142
|
+
};
|
|
143
|
+
/** Filters `dbObjectSource` sends with every page. */
|
|
144
|
+
export type DbObjectSourceOptions = {
|
|
145
|
+
route?: S3RouteName;
|
|
146
|
+
/** @default "active" */
|
|
147
|
+
status?: DbClientObjectStatus;
|
|
148
|
+
/** Exact type, or `type/*` for every subtype (`image/*`). */
|
|
149
|
+
contentType?: string;
|
|
150
|
+
/** Rows per page. The server caps it at 100. */
|
|
151
|
+
limit?: number;
|
|
152
|
+
/** List one folder at a time, with folder rows. @default true */
|
|
153
|
+
folders?: boolean;
|
|
154
|
+
};
|
|
155
|
+
/** A folder row of {@link DbObjectSource}. `id` is the folder path. */
|
|
156
|
+
export type DbObjectSourceFolder = {
|
|
157
|
+
id: string;
|
|
158
|
+
name: string;
|
|
159
|
+
};
|
|
160
|
+
/** The `useObjectList` query input. Mirrors react's `ObjectListQueryInput`. */
|
|
161
|
+
export type DbObjectSourceQueryInput = {
|
|
162
|
+
/** Folder path. `null` is the root. */
|
|
163
|
+
parent: string | null;
|
|
164
|
+
cursor: string | null;
|
|
165
|
+
/** `name`, `size`, or `updatedAt`. Other fields keep the default order. */
|
|
166
|
+
sort: {
|
|
167
|
+
field: string;
|
|
168
|
+
direction: "asc" | "desc";
|
|
169
|
+
} | null;
|
|
170
|
+
search: string;
|
|
171
|
+
signal: AbortSignal;
|
|
172
|
+
};
|
|
173
|
+
/** One page of {@link DbObjectSource}. Mirrors react's `ObjectListPage`. */
|
|
174
|
+
export type DbObjectSourcePage<TClientAttributes = never> = {
|
|
175
|
+
items: DbClientObject<TClientAttributes>[];
|
|
176
|
+
/** First page only. */
|
|
177
|
+
folders?: DbObjectSourceFolder[];
|
|
178
|
+
nextCursor: string | null;
|
|
179
|
+
/** Scope usage with its caps. First page only. */
|
|
180
|
+
usage?: DbUsage & DbQuota;
|
|
181
|
+
};
|
|
182
|
+
/** How the list reads one row. Mirrors react's `ObjectListFile`. */
|
|
183
|
+
export type DbObjectSourceFile = {
|
|
184
|
+
name: string;
|
|
185
|
+
objectKey: string;
|
|
186
|
+
size: number | null;
|
|
187
|
+
contentType: string | null;
|
|
188
|
+
/** The row's `updatedAt`. */
|
|
189
|
+
updatedAt: string;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* A `useObjectList` source over `GET /db/objects`. Typed structurally so db
|
|
193
|
+
* does not depend on react; a type test checks it against `ObjectListSource`.
|
|
194
|
+
*/
|
|
195
|
+
export type DbObjectSource<TClientAttributes = never> = {
|
|
196
|
+
query: (input: DbObjectSourceQueryInput) => Promise<DbObjectSourcePage<TClientAttributes>>;
|
|
197
|
+
getKey: (item: DbClientObject<TClientAttributes>) => string;
|
|
198
|
+
getFile: (item: DbClientObject<TClientAttributes>) => DbObjectSourceFile;
|
|
199
|
+
/** Upload options for files dropped into `parent`. Root is `""`. */
|
|
200
|
+
uploadOptions?: (parent: string | null) => {
|
|
201
|
+
metadata: Record<string, string>;
|
|
202
|
+
};
|
|
203
|
+
/** Creates `name` inside `parent`. */
|
|
204
|
+
createFolder?: (input: {
|
|
205
|
+
parent: string | null;
|
|
206
|
+
name: string;
|
|
207
|
+
}) => Promise<DbObjectSourceFolder>;
|
|
208
|
+
};
|
|
209
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/types/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,mFAAmF;AACnF,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC;AAE3E;;;;GAIG;AACH,MAAM,MAAM,cAAc,CAAC,iBAAiB,GAAG,KAAK,IAAI;IACtD,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,yDAAyD;IACzD,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,oBAAoB,CAAC;IAC7B,UAAU,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACrC,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,iCAAiC;AACjC,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,MAAM,EAAE,MAAM,GAAG,IAAI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C,EAAE,OAAO,GAAG,OAAO,CAAC;CAC3B,CAAC;AAEF,oEAAoE;AACpE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,cAAc,CAAC,iBAAiB,GAAG,KAAK,IAAI;IACtD,KAAK,EAAE,CACL,KAAK,EAAE,wBAAwB,KAC5B,OAAO,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACpD,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,iBAAiB,CAAC,KAAK,MAAM,CAAC;IAC5D,OAAO,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,iBAAiB,CAAC,KAAK,kBAAkB,CAAC;IACzE,oEAAoE;IACpE,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,KAAK;QACzC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAClC,CAAC;IACF,sCAAsC;IACtC,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE;QACrB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QACtB,IAAI,EAAE,MAAM,CAAC;KACd,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAC;CACrC,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { DimahS3Locals } from "@dimah-s3/server";
|
|
2
|
+
import type { DimahS3DbClient } from "../fuma-db.js";
|
|
3
|
+
import type { StandardSchemaV1 } from "../standard-schema.js";
|
|
4
|
+
import type { DbQuota } from "./client";
|
|
5
|
+
import type { StorageObject } from "./storage-object";
|
|
6
|
+
/**
|
|
7
|
+
* What a scope is resolved for.
|
|
8
|
+
* - `upload`: presign, multipart init, and `s3.put`
|
|
9
|
+
* - `confirm`: confirm, and the confirm step of multipart complete
|
|
10
|
+
* - `multipart`: part, list, abort, and complete
|
|
11
|
+
* - `download`: presigned download and `GET /file`
|
|
12
|
+
* - `delete`: delete, and each key of `deleteMany`
|
|
13
|
+
* - `list`: `GET /db/objects`
|
|
14
|
+
* - `read`: `GET /db/object`
|
|
15
|
+
* - `update`: `PATCH /db/object` and the folder endpoints
|
|
16
|
+
*/
|
|
17
|
+
export type ScopeOperation = "upload" | "confirm" | "multipart" | "download" | "delete" | "list" | "read" | "update";
|
|
18
|
+
/**
|
|
19
|
+
* Who is calling: what `resolveScope` and a `quota` function see. The
|
|
20
|
+
* scope comes from the caller alone, never from the target, so the same
|
|
21
|
+
* caller gets the same scope when a ticket is bound, used, and confirmed.
|
|
22
|
+
*/
|
|
23
|
+
export type ScopeContext<TSession = undefined> = {
|
|
24
|
+
request: Request;
|
|
25
|
+
/** Locals the guards have set so far. */
|
|
26
|
+
locals: DimahS3Locals;
|
|
27
|
+
/** `getSession(request)`, resolved once per request. */
|
|
28
|
+
session: TSession;
|
|
29
|
+
operation: ScopeOperation;
|
|
30
|
+
/**
|
|
31
|
+
* Named route of the call. `list` has one only when the client filters
|
|
32
|
+
* by route; `read`, `update`, and the folder endpoints have none.
|
|
33
|
+
*/
|
|
34
|
+
route?: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* What `authorize` checks: the caller's resolved scope, and what the call
|
|
38
|
+
* targets.
|
|
39
|
+
*/
|
|
40
|
+
export type AuthorizeContext<TSession = undefined, TAttributes = never> = ScopeContext<TSession> & {
|
|
41
|
+
scope: string;
|
|
42
|
+
/** Object key. Absent on `list` and the folder endpoints. */
|
|
43
|
+
key?: string;
|
|
44
|
+
/** Target folder of an upload, move, or folder endpoint. `null` is the root. */
|
|
45
|
+
folder?: string | null;
|
|
46
|
+
/** Client extras of the upload. Set on `upload` only. */
|
|
47
|
+
clientMetadata?: Record<string, string>;
|
|
48
|
+
/**
|
|
49
|
+
* The stored row, when the call targets one, including the active object
|
|
50
|
+
* an overwrite replaces. It is the server view: `scope`, `s3Metadata`, and
|
|
51
|
+
* the attributes as stored.
|
|
52
|
+
*/
|
|
53
|
+
object?: StorageObject<TAttributes>;
|
|
54
|
+
};
|
|
55
|
+
/** Per-route options under `plugins: { db: … }`. */
|
|
56
|
+
export type DbRouteOptions = {
|
|
57
|
+
/**
|
|
58
|
+
* `"overwrite"` lets an upload replace an active object at the same key.
|
|
59
|
+
* Without it, that upload fails with `OBJECT_EXISTS`.
|
|
60
|
+
*/
|
|
61
|
+
replace?: "overwrite";
|
|
62
|
+
};
|
|
63
|
+
declare module "@dimah-s3/server" {
|
|
64
|
+
interface DimahS3RoutePluginOptions {
|
|
65
|
+
/** `false` turns db tracking and every db hook off for the route. */
|
|
66
|
+
db?: false | DbRouteOptions;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Typed app attributes for `PATCH /db/object`. */
|
|
70
|
+
export type DbAttributesOptions<TAttributes, TClientAttributes = TAttributes> = {
|
|
71
|
+
/** Validates the `attributes` of a PATCH body. */
|
|
72
|
+
schema: StandardSchemaV1<unknown, TAttributes>;
|
|
73
|
+
/** Maps stored attributes to what the browser sees. Defaults to all of them. */
|
|
74
|
+
toClient?: (attributes: TAttributes) => TClientAttributes;
|
|
75
|
+
/** Largest JSON size of the attributes, in bytes. @default 16_384 */
|
|
76
|
+
maxBytes?: number;
|
|
77
|
+
};
|
|
78
|
+
/** Caps for a scope, or a function that returns them per request. */
|
|
79
|
+
export type DbQuotaOption<TSession = undefined> = DbQuota | ((context: ScopeContext<TSession> & {
|
|
80
|
+
scope: string;
|
|
81
|
+
}) => DbQuota | null | Promise<DbQuota | null>);
|
|
82
|
+
/**
|
|
83
|
+
* Options of the `db()` plugin. Without `attributes.toClient`, the browser
|
|
84
|
+
* sees the stored attributes, so `TClientAttributes` defaults to them.
|
|
85
|
+
*/
|
|
86
|
+
export type DbPluginOptions<TSession = undefined, TAttributes = never, TClientAttributes = TAttributes> = {
|
|
87
|
+
/** `DimahS3DB.client(adapter)`. */
|
|
88
|
+
client: DimahS3DbClient;
|
|
89
|
+
/** Loads the session for a request. Called at most once per `Request`. */
|
|
90
|
+
getSession?: (request: Request) => TSession | Promise<TSession>;
|
|
91
|
+
/**
|
|
92
|
+
* Owning scope of the caller, such as `user:123`. `null` rejects the
|
|
93
|
+
* call with `UNAUTHORIZED`. It runs once per call and route, so the guard
|
|
94
|
+
* and the lifecycle hooks of one call share the result.
|
|
95
|
+
*/
|
|
96
|
+
resolveScope: (context: ScopeContext<TSession>) => string | null | Promise<string | null>;
|
|
97
|
+
/**
|
|
98
|
+
* Runs after the scope is resolved and, for a stored object, after the
|
|
99
|
+
* ownership check, so it can only narrow access. `object` is set when the
|
|
100
|
+
* call targets a stored row, including the active object an overwrite
|
|
101
|
+
* replaces; that upload's `folder` is the folder of the object it
|
|
102
|
+
* replaces. `false` rejects the call with `FORBIDDEN`.
|
|
103
|
+
*/
|
|
104
|
+
authorize?: (context: AuthorizeContext<TSession, TAttributes>) => boolean | Promise<boolean>;
|
|
105
|
+
/** Byte and file caps, checked at upload and again at confirm. */
|
|
106
|
+
quota?: DbQuotaOption<TSession>;
|
|
107
|
+
/** `"soft"` keeps a `deleted` row; `"hard"` removes it. @default "soft" */
|
|
108
|
+
deleteMode?: "soft" | "hard";
|
|
109
|
+
/** Enables `attributes` on `PATCH /db/object`. */
|
|
110
|
+
attributes?: DbAttributesOptions<TAttributes, TClientAttributes>;
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/types/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,C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