@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,97 @@
1
+ import { v7 } from "uuid";
2
+ //#region src/root/lib/upload.client.ts
3
+ function createLocalDriveUploadClient(props) {
4
+ /**
5
+ * Create input schema for the upload method
6
+ * @param {PrepareLocalDriveUploadInput} input
7
+ * @returns {LocalDriveUploadFileRequest}
8
+ */
9
+ function prepareUpload(input) {
10
+ return {
11
+ ...input,
12
+ uploadId: input.uploadId ?? v7(),
13
+ name: input.file.name,
14
+ size: input.file.size,
15
+ contentType: input.file.type
16
+ };
17
+ }
18
+ /**
19
+ * Upload file to the server
20
+ * @param {LocalDriveUploadFileRequest} input
21
+ * @returns {Promise<LocalDriveFileNode>}
22
+ */
23
+ async function upload(input, hooks) {
24
+ let presignResult = null;
25
+ try {
26
+ /**
27
+ * Presign
28
+ */
29
+ await hooks?.beforePresign?.(input);
30
+ const { file, ...presignInput } = input;
31
+ presignResult = await props.endpoints.presignUpload(presignInput);
32
+ await hooks?.afterPresign?.(presignResult);
33
+ /**
34
+ * Upload the file
35
+ */
36
+ const uploadResponse = await fetch(presignResult.presignedUrl, {
37
+ method: "PUT",
38
+ headers: { "Content-Type": input.file.type },
39
+ body: input.file
40
+ });
41
+ if (!uploadResponse.ok) {
42
+ const message = await uploadResponse.text();
43
+ throw new Error(`Upload failed: ${message}`);
44
+ }
45
+ /**
46
+ * Confirm
47
+ */
48
+ await hooks?.beforeConfirm?.(presignResult);
49
+ const node = await props.endpoints.confirmUpload({ uploadId: presignResult.uploadId });
50
+ await hooks?.afterConfirm?.(node);
51
+ /**
52
+ * Return
53
+ */
54
+ return node;
55
+ } catch (err) {
56
+ console.error("Upload error: ", err);
57
+ /**
58
+ * Delete if upload failed
59
+ * */
60
+ try {
61
+ if (presignResult?.node.id) await deleteFiles([presignResult.node.id]);
62
+ } catch (cleanupErr) {
63
+ console.error("Cleanup delete failed:", cleanupErr);
64
+ }
65
+ throw err;
66
+ }
67
+ }
68
+ /**
69
+ * Delete files
70
+ * @param {string[]} ids
71
+ */
72
+ async function deleteFiles(ids) {
73
+ await props.endpoints.deleteNodes({ ids });
74
+ }
75
+ /**
76
+ * Update node
77
+ * @param {string} id
78
+ * @param {UpdateLocalDriveNodeInput} data
79
+ */
80
+ async function updateNode(id, data) {
81
+ return props.endpoints.updateNode({
82
+ id,
83
+ data
84
+ });
85
+ }
86
+ /**
87
+ * Upload client
88
+ */
89
+ return {
90
+ prepareUpload,
91
+ upload,
92
+ deleteFiles,
93
+ updateNode
94
+ };
95
+ }
96
+ //#endregion
97
+ export { createLocalDriveUploadClient };