@tulip-systems/drive-local 0.11.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.
Files changed (61) hide show
  1. package/LICENSE +662 -0
  2. package/dist/client.d.mts +12 -0
  3. package/dist/client.mjs +12 -0
  4. package/dist/database/drizzle/lib/adapter.d.mts +310 -0
  5. package/dist/database/drizzle/lib/adapter.mjs +520 -0
  6. package/dist/database/drizzle/lib/compilers.d.mts +395 -0
  7. package/dist/database/drizzle/lib/compilers.mjs +21 -0
  8. package/dist/database/drizzle/lib/schema.d.mts +61 -0
  9. package/dist/drizzle.d.mts +4 -0
  10. package/dist/drizzle.mjs +3 -0
  11. package/dist/index.d.mts +8 -0
  12. package/dist/index.mjs +8 -0
  13. package/dist/root/components/command-file-update.d.mts +11 -0
  14. package/dist/root/components/command-file-update.mjs +44 -0
  15. package/dist/root/components/command-file-upload.d.mts +5 -0
  16. package/dist/root/components/command-file-upload.mjs +31 -0
  17. package/dist/root/components/command-folder-create.d.mts +11 -0
  18. package/dist/root/components/command-folder-create.mjs +50 -0
  19. package/dist/root/components/command-folder-update.d.mts +11 -0
  20. package/dist/root/components/command-folder-update.mjs +44 -0
  21. package/dist/root/components/content.client.d.mts +5 -0
  22. package/dist/root/components/content.client.mjs +5 -0
  23. package/dist/root/components/navigation.client.d.mts +11 -0
  24. package/dist/root/components/navigation.client.mjs +12 -0
  25. package/dist/root/components/provider.client.d.mts +16 -0
  26. package/dist/root/components/provider.client.mjs +65 -0
  27. package/dist/root/components/upload-zone-context.client.d.mts +36 -0
  28. package/dist/root/components/upload-zone-context.client.mjs +19 -0
  29. package/dist/root/components/upload-zone.client.d.mts +16 -0
  30. package/dist/root/components/upload-zone.client.mjs +147 -0
  31. package/dist/root/components/view.client.d.mts +20 -0
  32. package/dist/root/components/view.client.mjs +86 -0
  33. package/dist/root/config/columns-data.d.mts +6 -0
  34. package/dist/root/config/columns-data.mjs +62 -0
  35. package/dist/root/config/filters.d.mts +404 -0
  36. package/dist/root/config/filters.mjs +122 -0
  37. package/dist/root/config/sorting.d.mts +38 -0
  38. package/dist/root/config/sorting.mjs +26 -0
  39. package/dist/root/lib/constants.d.mts +12 -0
  40. package/dist/root/lib/constants.mjs +27 -0
  41. package/dist/root/lib/database/contracts.d.mts +112 -0
  42. package/dist/root/lib/database/filters.d.mts +28 -0
  43. package/dist/root/lib/database/filters.mjs +73 -0
  44. package/dist/root/lib/helpers.d.mts +33 -0
  45. package/dist/root/lib/helpers.mjs +78 -0
  46. package/dist/root/lib/route-handler.server.d.mts +36 -0
  47. package/dist/root/lib/route-handler.server.mjs +111 -0
  48. package/dist/root/lib/router.server.d.mts +819 -0
  49. package/dist/root/lib/router.server.mjs +87 -0
  50. package/dist/root/lib/search-params.d.mts +15 -0
  51. package/dist/root/lib/search-params.mjs +6 -0
  52. package/dist/root/lib/service.server.d.mts +522 -0
  53. package/dist/root/lib/service.server.mjs +613 -0
  54. package/dist/root/lib/upload.client.d.mts +60 -0
  55. package/dist/root/lib/upload.client.mjs +97 -0
  56. package/dist/root/lib/validators.d.mts +710 -0
  57. package/dist/root/lib/validators.mjs +116 -0
  58. package/dist/server.d.mts +5 -0
  59. package/dist/server.mjs +4 -0
  60. package/package.json +83 -0
  61. package/styles.css +1 -0
@@ -0,0 +1,12 @@
1
+ import { LocalDriveFileUpdateCommand } from "./root/components/command-file-update.mjs";
2
+ import { DriveUploadZoneContext, LocalDriveUploadZoneContext, useDriveUploadZone, useLocalDriveUploadZone } from "./root/components/upload-zone-context.client.mjs";
3
+ import { LocalDriveFilesUploadCommand } from "./root/components/command-file-upload.mjs";
4
+ import { LocalDriveFoldersCreateCommand } from "./root/components/command-folder-create.mjs";
5
+ import { LocalDriveFoldersUpdateCommand } from "./root/components/command-folder-update.mjs";
6
+ import { LocalDriveContent } from "./root/components/content.client.mjs";
7
+ import { LocalDriveHeader, LocalDriveHeaderBreadcrumbs, LocalDriveHeaderTools, LocalDriveToolbar, LocalDriveToolbarBreadcrumbs, LocalDriveToolbarTools, LocalDriveViewSwitcher } from "./root/components/navigation.client.mjs";
8
+ import { DriveUploadZone, LocalDriveUploadZone } from "./root/components/upload-zone.client.mjs";
9
+ import { LocalDriveContext, LocalDriveProvider, useLocalDriveContext } from "./root/components/provider.client.mjs";
10
+ import { LocalDriveView, LocalDriveViewLoading, LocalDriveViewProvider } from "./root/components/view.client.mjs";
11
+ import { createLocalDriveUploadClient } from "./root/lib/upload.client.mjs";
12
+ export { DriveUploadZone, DriveUploadZoneContext, LocalDriveContent, LocalDriveContext, LocalDriveFileUpdateCommand, LocalDriveFilesUploadCommand, LocalDriveFoldersCreateCommand, LocalDriveFoldersUpdateCommand, LocalDriveHeader, LocalDriveHeaderBreadcrumbs, LocalDriveHeaderTools, LocalDriveProvider, LocalDriveToolbar, LocalDriveToolbarBreadcrumbs, LocalDriveToolbarTools, LocalDriveUploadZone, LocalDriveUploadZoneContext, LocalDriveView, LocalDriveViewLoading, LocalDriveViewProvider, LocalDriveViewSwitcher, createLocalDriveUploadClient, useDriveUploadZone, useLocalDriveContext, useLocalDriveUploadZone };
@@ -0,0 +1,310 @@
1
+ import { LocalNode } from "../../../root/lib/validators.mjs";
2
+ import { LocalDriveDatabaseCreateNodeInput, LocalDriveDatabaseCreateVariantInput, LocalDriveDatabaseDeleteNodesInput, LocalDriveDatabaseFindFirstNodeInput, LocalDriveDatabaseFindFirstPresignedUrlInput, LocalDriveDatabaseFindNodesInput, LocalDriveDatabaseFindVariantsInput, LocalDriveDatabaseListNodesWithAssetInput, LocalDriveDatabaseNodeChild, LocalDriveDatabaseUpdateNodesInput, UpsertLocalDrivePresignedUrlInput } from "../../../root/lib/database/contracts.mjs";
3
+ import "../../../server.mjs";
4
+ import { LocalDriveDrizzleSchema } from "./schema.mjs";
5
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
6
+ //#region src/database/drizzle/lib/adapter.d.ts
7
+ type LocalDriveDrizzleAdapterConfig<TSchema extends Record<string, unknown>, TDriveSchema extends LocalDriveDrizzleSchema> = {
8
+ db: NodePgDatabase<TSchema>;
9
+ schema: TDriveSchema;
10
+ };
11
+ /**
12
+ * Creates the Drizzle database adapter for the local drive package.
13
+ *
14
+ * The local drive package owns the drive behavior, but the consumer app owns the
15
+ * Drizzle schema and migrations. Pass the app's `db` instance and a schema map
16
+ * with the local drive tables under the expected contract keys.
17
+ *
18
+ * @example
19
+ * import { localDriveDrizzleAdapter } from "@tulip-systems/drive-local/drizzle";
20
+ * import { LocalDrive } from "@tulip-systems/drive-local/server";
21
+ * import * as driveSchema from "@/server/drive-local/schema";
22
+ * import * as storageSchema from "@/server/storage/schema";
23
+ *
24
+ * export const drive = new LocalDrive({
25
+ * database: localDriveDrizzleAdapter({
26
+ * db,
27
+ * schema: { ...driveSchema, storageAssets: storageSchema.storageAssets },
28
+ * }),
29
+ * storage,
30
+ * });
31
+ *
32
+ * @example
33
+ * // You can also remap app-owned table names to the local drive contract keys.
34
+ * localDriveDrizzleAdapter({
35
+ * db,
36
+ * schema: {
37
+ * nodes: driveNodes,
38
+ * nodeVariants: driveNodeVariants,
39
+ * nodePresignedUrls: driveNodePresignedUrls,
40
+ * storageAssets: assets,
41
+ * },
42
+ * });
43
+ */
44
+ declare function localDriveDrizzleAdapter<TSchema extends Record<string, unknown>, TDriveSchema extends LocalDriveDrizzleSchema>({ db, schema }: LocalDriveDrizzleAdapterConfig<TSchema, TDriveSchema>): {
45
+ db: NodePgDatabase<TSchema>;
46
+ schema: TDriveSchema;
47
+ /**
48
+ * Finds a local drive node by its primary id.
49
+ *
50
+ * @example
51
+ * const node = await database.findNodeById("019d...");
52
+ */
53
+ findNodeById: (id: string) => Promise<{
54
+ id: string;
55
+ createdAt: Date;
56
+ updatedAt: Date;
57
+ name: string;
58
+ namespace: string;
59
+ type: ("folder" | "file") | null;
60
+ subtype: "image" | "document" | "spreadsheet" | "video" | "audio" | "archive" | "other";
61
+ size: number | null;
62
+ contentType: string | null;
63
+ readonly: boolean | null;
64
+ hidden: boolean | null;
65
+ archivedAt: Date | null;
66
+ parentId: string | null;
67
+ assetId: string | null;
68
+ } | null>;
69
+ /**
70
+ * Finds the first local drive node matching the provided database filters.
71
+ *
72
+ * @example
73
+ * const node = await database.findFirstNode({ filters: { assetIds: [asset.id] } });
74
+ */
75
+ findFirstNode: (input: LocalDriveDatabaseFindFirstNodeInput | undefined) => Promise<{
76
+ id: string;
77
+ createdAt: Date;
78
+ updatedAt: Date;
79
+ name: string;
80
+ namespace: string;
81
+ type: ("folder" | "file") | null;
82
+ subtype: "image" | "document" | "spreadsheet" | "video" | "audio" | "archive" | "other";
83
+ size: number | null;
84
+ contentType: string | null;
85
+ readonly: boolean | null;
86
+ hidden: boolean | null;
87
+ archivedAt: Date | null;
88
+ parentId: string | null;
89
+ assetId: string | null;
90
+ } | null>;
91
+ /**
92
+ * Finds local drive nodes matching the provided filters, sorts, and pagination limits.
93
+ *
94
+ * @example
95
+ * const nodes = await database.findNodes({
96
+ * filters: { namespace: "products", parentId: null },
97
+ * sorts: [{ key: "name", direction: "asc" }],
98
+ * });
99
+ */
100
+ findNodes: (input?: LocalDriveDatabaseFindNodesInput | undefined) => Promise<{
101
+ id: string;
102
+ createdAt: Date;
103
+ updatedAt: Date;
104
+ name: string;
105
+ namespace: string;
106
+ type: ("folder" | "file") | null;
107
+ subtype: "image" | "document" | "spreadsheet" | "video" | "audio" | "archive" | "other";
108
+ size: number | null;
109
+ contentType: string | null;
110
+ readonly: boolean | null;
111
+ hidden: boolean | null;
112
+ archivedAt: Date | null;
113
+ parentId: string | null;
114
+ assetId: string | null;
115
+ }[]>;
116
+ /**
117
+ * Lists paginated nodes with their linked storage asset.
118
+ *
119
+ * @example
120
+ * const result = await database.listNodesWithAsset({
121
+ * limit: 20,
122
+ * offset: 0,
123
+ * filters: { namespace: "products", parentId: null },
124
+ * sorts: [],
125
+ * });
126
+ */
127
+ listNodesWithAsset: ({ filters, limit, offset, sorts }: LocalDriveDatabaseListNodesWithAssetInput) => Promise<{
128
+ data: {
129
+ id: never;
130
+ createdAt: never;
131
+ updatedAt: never;
132
+ name: never;
133
+ namespace: never;
134
+ type: never;
135
+ subtype: never;
136
+ size: never;
137
+ contentType: never;
138
+ readonly: never;
139
+ hidden: never;
140
+ archivedAt: never;
141
+ parentId: never;
142
+ assetId: never;
143
+ asset: never;
144
+ }[];
145
+ total: number;
146
+ }>;
147
+ /**
148
+ * Resolves the ancestor chain for a folder or file within a namespace.
149
+ *
150
+ * @example
151
+ * const parents = await database.getNodeParents({ id: node.id, namespace: "products" });
152
+ */
153
+ getNodeParents: (input: {
154
+ id: string | null;
155
+ namespace: string;
156
+ }) => Promise<(Pick<LocalNode, "name" | "id" | "parentId"> & {
157
+ depth: number;
158
+ })[]>;
159
+ /**
160
+ * Resolves all recursive descendants for one or more nodes.
161
+ *
162
+ * @example
163
+ * const descendants = await database.getNodeChildren([folder.id]);
164
+ */
165
+ getNodeChildren: (ids: string[]) => Promise<LocalDriveDatabaseNodeChild[]>;
166
+ /**
167
+ * Creates a node row.
168
+ *
169
+ * @example
170
+ * const node = await database.createNode({
171
+ * type: "file",
172
+ * name: "manual.pdf",
173
+ * namespace: "products",
174
+ * subtype: "document",
175
+ * assetId: asset.id,
176
+ * });
177
+ */
178
+ createNode: (input: LocalDriveDatabaseCreateNodeInput) => Promise<{
179
+ id: string;
180
+ createdAt: Date;
181
+ updatedAt: Date;
182
+ name: string;
183
+ namespace: string;
184
+ type: ("folder" | "file") | null;
185
+ subtype: "image" | "document" | "spreadsheet" | "video" | "audio" | "archive" | "other";
186
+ size: number | null;
187
+ contentType: string | null;
188
+ readonly: boolean | null;
189
+ hidden: boolean | null;
190
+ archivedAt: Date | null;
191
+ parentId: string | null;
192
+ assetId: string | null;
193
+ } | null>;
194
+ /**
195
+ * Updates a node row by primary id.
196
+ *
197
+ * @example
198
+ * const updated = await database.updateNodeById(node.id, { name: "Updated name" });
199
+ */
200
+ updateNodeById: (id: string, data: Partial<Pick<LocalNode, "name" | "size" | "contentType" | "readonly" | "hidden" | "archivedAt" | "parentId">>) => Promise<{
201
+ id: string;
202
+ createdAt: Date;
203
+ updatedAt: Date;
204
+ name: string;
205
+ namespace: string;
206
+ type: ("folder" | "file") | null;
207
+ subtype: "image" | "document" | "spreadsheet" | "video" | "audio" | "archive" | "other";
208
+ size: number | null;
209
+ contentType: string | null;
210
+ readonly: boolean | null;
211
+ hidden: boolean | null;
212
+ archivedAt: Date | null;
213
+ parentId: string | null;
214
+ assetId: string | null;
215
+ } | null>;
216
+ /**
217
+ * Updates nodes matching the provided filters.
218
+ *
219
+ * @example
220
+ * const [updated] = await database.updateNodes({
221
+ * filters: { nodeIds: [node.id] },
222
+ * data: { name: "Updated name" },
223
+ * });
224
+ */
225
+ updateNodes: ({ data, filters }: LocalDriveDatabaseUpdateNodesInput) => Promise<{
226
+ id: string;
227
+ createdAt: Date;
228
+ updatedAt: Date;
229
+ name: string;
230
+ namespace: string;
231
+ type: ("folder" | "file") | null;
232
+ subtype: "image" | "document" | "spreadsheet" | "video" | "audio" | "archive" | "other";
233
+ size: number | null;
234
+ contentType: string | null;
235
+ readonly: boolean | null;
236
+ hidden: boolean | null;
237
+ archivedAt: Date | null;
238
+ parentId: string | null;
239
+ assetId: string | null;
240
+ }[]>;
241
+ /**
242
+ * Deletes a node by primary id and relies on database cascades for dependent rows.
243
+ *
244
+ * @example
245
+ * await database.deleteNodeById(node.id);
246
+ */
247
+ deleteNodeById: (id: string) => Promise<void>;
248
+ /**
249
+ * Deletes nodes matching the provided filters.
250
+ *
251
+ * @example
252
+ * await database.deleteNodes({ filters: { nodeIds: [node.id] } });
253
+ */
254
+ deleteNodes: ({ filters }: LocalDriveDatabaseDeleteNodesInput) => Promise<void>;
255
+ /**
256
+ * Finds generated variants matching the provided filters.
257
+ *
258
+ * @example
259
+ * const variants = await database.findVariants({ filters: { nodeIds: [node.id] } });
260
+ */
261
+ findVariants: (input?: LocalDriveDatabaseFindVariantsInput | undefined) => Promise<{
262
+ id: string;
263
+ createdAt: Date;
264
+ updatedAt: Date;
265
+ nodeId: string;
266
+ assetId: string;
267
+ variant: "main" | `preview-${number}`;
268
+ width: number;
269
+ }[]>;
270
+ /**
271
+ * Records a generated image variant and its storage asset.
272
+ *
273
+ * @example
274
+ * await database.createVariant({
275
+ * nodeId: node.id,
276
+ * assetId: previewAsset.id,
277
+ * variant: "preview-640",
278
+ * width: 640,
279
+ * });
280
+ */
281
+ createVariant: (input: LocalDriveDatabaseCreateVariantInput) => Promise<void>;
282
+ /**
283
+ * Finds the first cached presigned URL matching the provided filters.
284
+ *
285
+ * @example
286
+ * const cached = await database.findFirstPresignedUrl({
287
+ * filters: { nodeId: node.id, variant: "main", disposition: "inline" },
288
+ * });
289
+ */
290
+ findFirstPresignedUrl: (input: LocalDriveDatabaseFindFirstPresignedUrlInput | undefined) => Promise<{
291
+ url: string;
292
+ expiresAt: Date;
293
+ } | null>;
294
+ /**
295
+ * Creates or refreshes the cached presigned URL for a node variant.
296
+ *
297
+ * @example
298
+ * await database.upsertPresignedUrl({
299
+ * nodeId: node.id,
300
+ * variant: "main",
301
+ * disposition: "attachment",
302
+ * url,
303
+ * expiresAt,
304
+ * });
305
+ */
306
+ upsertPresignedUrl: (input: UpsertLocalDrivePresignedUrlInput) => Promise<void>;
307
+ };
308
+ type LocalDriveDrizzleProvider<TSchema extends Record<string, unknown>, TDriveSchema extends LocalDriveDrizzleSchema = LocalDriveDrizzleSchema> = ReturnType<typeof localDriveDrizzleAdapter<TSchema, TDriveSchema>>;
309
+ //#endregion
310
+ export { LocalDriveDrizzleAdapterConfig, LocalDriveDrizzleProvider, localDriveDrizzleAdapter };