@lobb-js/lobb-ext-storage 0.5.8 → 0.8.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 (64) hide show
  1. package/.github/workflows/create_tag_on_version_change.yaml +45 -0
  2. package/.github/workflows/publish_npm_package.yaml +28 -0
  3. package/.vscode/settings.json +5 -0
  4. package/CHANGELOG.md +150 -29
  5. package/README.md +1 -35
  6. package/extensions/storage/adapters/index.ts +18 -0
  7. package/extensions/storage/adapters/localAdapter.ts +60 -0
  8. package/extensions/storage/adapters/storageAdapter.ts +13 -0
  9. package/extensions/storage/collections/fileSystem.ts +58 -0
  10. package/extensions/storage/collections/index.ts +12 -0
  11. package/extensions/storage/config/extensionConfigSchema.ts +15 -0
  12. package/extensions/storage/index.ts +26 -0
  13. package/extensions/storage/init.ts +6 -0
  14. package/extensions/storage/meta.ts +5 -0
  15. package/extensions/storage/migrations.ts +3 -0
  16. package/extensions/storage/openapi.ts +84 -0
  17. package/extensions/storage/studio/tests/fileManager.spec.ts +23 -0
  18. package/extensions/storage/studio/tests/package.json +1 -0
  19. package/extensions/storage/studio/tests/playwright.config.cjs +27 -0
  20. package/extensions/storage/studioExtension.json +1 -0
  21. package/extensions/storage/tests/configs/simple.ts +95 -0
  22. package/extensions/storage/tests/directories.test.ts +156 -0
  23. package/extensions/storage/tests/extraFormData.test.ts +47 -0
  24. package/extensions/storage/tests/files/rose.jpeg +0 -0
  25. package/extensions/storage/tests/files.test.ts +292 -0
  26. package/extensions/storage/tests/forceUpload.test.ts +72 -0
  27. package/extensions/storage/tests/massRemove.test.ts +189 -0
  28. package/extensions/storage/tests/meta.test.ts +26 -0
  29. package/extensions/storage/tests/recursiveDeleteMany.test.ts +208 -0
  30. package/extensions/storage/tests/recursiveDeleteOne.test.ts +206 -0
  31. package/extensions/storage/tests/storage/127 +0 -0
  32. package/extensions/storage/types.ts +11 -0
  33. package/extensions/storage/utils.ts +87 -0
  34. package/extensions/storage/workflows/controllers.ts +103 -0
  35. package/extensions/storage/workflows/index.ts +10 -0
  36. package/extensions/storage/workflows/services.ts +182 -0
  37. package/lobb.ts +54 -0
  38. package/package.json +32 -9
  39. package/scripts/postpublish.sh +12 -0
  40. package/scripts/prepublish.sh +17 -0
  41. package/studio/app.html +12 -0
  42. package/studio/routes/+layout.svelte +7 -0
  43. package/studio/routes/+layout.ts +1 -0
  44. package/studio/routes/[...path]/+page.svelte +6 -0
  45. package/svelte.config.js +23 -7
  46. package/todo.md +36 -0
  47. package/tsconfig.app.json +3 -3
  48. package/tsconfig.json +11 -5
  49. package/vite.config.ts +4 -10
  50. package/components.json +0 -16
  51. package/index.html +0 -13
  52. package/src/app.css +0 -124
  53. package/src/main.ts +0 -14
  54. /package/{src → extensions/storage/studio}/extension.types.ts +0 -0
  55. /package/{src → extensions/storage/studio}/index.ts +0 -0
  56. /package/{src → extensions/storage/studio}/lib/components/childrenFileExplorer.svelte +0 -0
  57. /package/{src → extensions/storage/studio}/lib/components/explorerNotSupported.svelte +0 -0
  58. /package/{src → extensions/storage/studio}/lib/components/fileExplorer.svelte +0 -0
  59. /package/{src → extensions/storage/studio}/lib/components/fileIcon.svelte +0 -0
  60. /package/{src → extensions/storage/studio}/lib/components/fileManagerBreadCrumbs.svelte +0 -0
  61. /package/{src → extensions/storage/studio}/lib/components/foreignKeyComponent.svelte +0 -0
  62. /package/{src → extensions/storage/studio}/lib/components/pages/fileExplorerPage.svelte +0 -0
  63. /package/{src → extensions/storage/studio}/lib/index.ts +0 -0
  64. /package/{src → extensions/storage/studio}/lib/utils.ts +0 -0
@@ -0,0 +1,45 @@
1
+ name: Create Tag on Version Change
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ check-version-and-tag:
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: write
13
+ outputs:
14
+ current_version: ${{ steps.current_version.outputs.current_version }}
15
+ previous_version: ${{ steps.previous_version.outputs.previous_version }}
16
+ steps:
17
+ - name: Checkout repository
18
+ uses: actions/checkout@v4
19
+ with:
20
+ fetch-depth: 0
21
+
22
+ - name: Get previous version
23
+ id: previous_version
24
+ run: |
25
+ PREV_VERSION=$(git show HEAD^:package.json | jq -r .version || echo "none")
26
+ echo "previous_version=$PREV_VERSION" >> "$GITHUB_OUTPUT"
27
+
28
+ - name: Get current version
29
+ id: current_version
30
+ run: |
31
+ CURR_VERSION=$(jq -r .version package.json)
32
+ echo "current_version=$CURR_VERSION" >> "$GITHUB_OUTPUT"
33
+
34
+ - name: Create tag
35
+ if: steps.previous_version.outputs.previous_version != steps.current_version.outputs.current_version
36
+ uses: rickstaa/action-create-tag@v1
37
+ with:
38
+ tag: "${{ steps.current_version.outputs.current_version }}"
39
+
40
+ publish-to-npm:
41
+ name: Publish to npm
42
+ needs: check-version-and-tag
43
+ if: needs.check-version-and-tag.outputs.previous_version != needs.check-version-and-tag.outputs.current_version
44
+ uses: maliknajjar/lobb_storage_ext/.github/workflows/publish_npm_package.yaml@main
45
+ secrets: inherit
@@ -0,0 +1,28 @@
1
+ name: publish package to npm
2
+
3
+ on:
4
+ workflow_call:
5
+
6
+ jobs:
7
+ publish:
8
+ runs-on: ubuntu-latest
9
+ permissions:
10
+ contents: read
11
+ id-token: write
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - name: Setup Node.js
15
+ uses: actions/setup-node@v4
16
+ with:
17
+ node-version: '24'
18
+ registry-url: 'https://registry.npmjs.org'
19
+ - name: Setup Bun
20
+ uses: oven-sh/setup-bun@v2
21
+ - name: Install jq
22
+ run: sudo apt-get update && sudo apt-get install -y jq
23
+ - name: Install dependencies
24
+ run: bun install
25
+ - name: Publish to npm
26
+ run: npm publish --access public
27
+ env:
28
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,5 @@
1
+ {
2
+ "deno.disablePaths": [
3
+ "studio"
4
+ ]
5
+ }
package/CHANGELOG.md CHANGED
@@ -2,78 +2,199 @@
2
2
  All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
3
3
 
4
4
  - - -
5
- ## storage-ext-studio@0.5.8 - 2026-03-03
5
+ ## storage-ext@0.8.1 - 2026-03-28
6
6
  #### Bug Fixes
7
+ - adding readme to all packages - (3a9264a) - malik ben
8
+ #### Miscellaneous Chores
9
+ - add publishConfig and fix ext packages for npm publishing - (49747e9) - malik ben
10
+
11
+ - - -
12
+
13
+ ## storage-ext@0.8.0 - 2026-03-28
14
+ #### Features
15
+ - (**reports-ext,storage-ext**) convert studio from Svelte SPA to SvelteKit - (3cd7f63) - malik ben
16
+ - (**storage-ext**) migrate packages/storage-ext from Deno to Bun - (a4e6bc6) - malik ben
17
+ - replace hasDashboardExtension with virtual:lobb-studio-extensions module - (437cb2e) - malik ben
18
+ #### Bug Fixes
19
+ - add /studio subpath exports to ext packages, update studio pages to use them - (c0b9a82) - malik ben
20
+ - untrack .svelte-kit from mindhar, fix process leak and $lib imports, update ai sdk versions - (017f784) - malik ben
21
+ - chaning $lib to relative path - (c6d9e8f) - malik ben
22
+ #### Miscellaneous Chores
23
+ - (**storage-ext**) move extension logic and tests to extensions/storage, flatten studio, add Playwright tests - (a27a46d) - malik ben
24
+ - (**version**) 0.25.2 - (a62acb9) - Cocogitto Bot
25
+ - (**version**) 0.25.1 - (afe7e69) - Cocogitto Bot
26
+ - (**version**) 0.25.0 - (77a383c) - Cocogitto Bot
27
+ - (**version**) 0.24.0 - (a8cb605) - Cocogitto Bot
28
+ - (**version**) 0.23.0 - (60f357e) - Cocogitto Bot
29
+ - add dev:studio/build:studio scripts, fix Dockerfiles, remove --build flag - (1595975) - malik ben
30
+ - migrate CI/CD from Deno/JSR to Bun/npm - (b4cc3bc) - malik ben
31
+ - add prepublish/postpublish scripts to extension packages for standalone compatibility - (4d6108f) - malik ben
32
+ - centralize studio app.css in @lobb-js/studio package, remove local copies - (05192dc) - malik ben
33
+ - rename @lobb/ scope to @lobb-js/ across all packages and apps - (cce4ce0) - malik ben
34
+ - add start/build scripts and gitignore build dir across all projects - (58f539d) - malik ben
35
+ - update CLAUDE.md to enforce no-commit-without-explicit-instruction rule - (6d63a42) - malik ben
36
+ - remove all deno.json and deno.lock files from the monorepo - (84ca5d4) - malik ben
37
+ - replace workspace:* with exact versions in all package.json files - (74fbdb7) - malik ben
38
+ - rename __studio to studio and remove unused studio dirs - (77fb932) - malik ben
39
+ - rename studio directory to __studio for faker-ext, llm-ext, mail-ext, reports-ext, storage-ext - (47e754a) - malik ben
40
+
41
+ - - -
42
+
43
+ ## storage-ext@0.7.1 - 2026-03-03
44
+ #### Bug Fixes
45
+ - (**storage-ext**) use ctx.lobb instead of Lobb.instance, add extra form data test - (27101f7) - malik ben
7
46
  - (**storage-ext**) fix tests to work from project root and fix foreignKeyObject persistence on file upload - (4b5bdd8) - malik ben
8
47
  #### Miscellaneous Chores
9
- - (**version**) 0.22.0 - (6510e32) - Cocogitto Bot
10
- - (**version**) 0.21.0 - (c973aa9) - Cocogitto Bot
48
+ - (**version**) 0.20.0 - (06cc303) - Cocogitto Bot
11
49
 
12
50
  - - -
13
51
 
14
- ## storage-ext-studio@0.5.7 - 2026-03-01
52
+ ## storage-ext@0.7.0 - 2026-03-01
53
+ #### Features
54
+ - (**mindhar**) add storage extension integration - (bca6368) - malik ben
55
+ #### Miscellaneous Chores
56
+ - (**version**) 0.18.0 - (efc553f) - Cocogitto Bot
57
+ - (**version**) 0.17.0 - (4174f0c) - Cocogitto Bot
58
+ - (**version**) 0.16.0 - (9508655) - Cocogitto Bot
59
+ - (**version**) 0.14.11 - (ad92b61) - Cocogitto Bot
60
+
61
+ - - -
62
+
63
+ ## storage-ext@0.6.8 - 2026-02-25
15
64
  #### Bug Fixes
16
- - (**studio**) prevent @lobb-js/studio version shadowing in extensions - (cd674b9) - malik ben
65
+ - publishing the storage extension - (033ab43) - Malik Najjar
17
66
  #### Miscellaneous Chores
18
- - (**version**) 0.15.0 - (0c2c345) - Cocogitto Bot
19
- - fixing the /studio base issue - (de6686f) - Malik Najjar
67
+ - filling some logic in the chat compoenent and adding the force feature - (5cd0dc8) - Malik Najjar
68
+ - fixing the deleteOne and deleteMany tests - (0e42622) - Malik Najjar
69
+ - making the directories test pass - (4229229) - Malik Najjar
70
+ - making the files tests pass - (f312a3a) - Malik Najjar
71
+ - passing more tests - (93ee276) - Malik Najjar
72
+ - adding a todo for the storage extension - (cb68710) - malik ben
73
+ - implementing the store using the new nice way - (106b320) - Malik Najjar
20
74
 
21
75
  - - -
22
76
 
23
- ## storage-ext-studio@0.5.6 - 2026-02-22
77
+ ## storage-ext@0.6.7 - 2026-02-23
24
78
  #### Bug Fixes
25
- - adding a studio prefix for the studio app - (6607b5a) - malik ben
79
+ - the core broke because of the override events - (f650f4c) - Malik Najjar
26
80
  #### Miscellaneous Chores
27
- - (**version**) 0.14.2 - (6ecdc1d) - Cocogitto Bot
81
+ - adding the ability to specify input and output types for the collectionServices methods - (72045f1) - Malik Najjar
82
+ - adding neccessary override events and workflows for the storage extension - (f09698f) - Malik Najjar
28
83
 
29
84
  - - -
30
85
 
31
- ## storage-ext-studio@0.5.5 - 2026-02-21
86
+ ## storage-ext@0.6.6 - 2026-02-23
87
+ #### Bug Fixes
88
+ - lobb crashing on missing event fix - (e0a9a75) - Malik Najjar
89
+
90
+ - - -
91
+
92
+ ## storage-ext@0.6.5 - 2026-02-23
93
+ #### Bug Fixes
94
+ - lobb crashed because of this non existing event - (0aa47c9) - Malik Najjar
95
+
96
+ - - -
97
+
98
+ ## storage-ext@0.6.4 - 2026-02-22
99
+ #### Bug Fixes
100
+ - coggito publishing packages order fix - (573c75e) - malik ben
101
+
102
+ - - -
103
+
104
+ ## storage-ext@0.6.3 - 2026-02-22
105
+ #### Bug Fixes
106
+ - adjusted the names of the events - (6543d8c) - malik ben
107
+
108
+ - - -
109
+
110
+ ## storage-ext@0.6.2 - 2026-02-22
111
+ #### Bug Fixes
112
+ - made the collectionService become an property in the main lobb object - (146e4cb) - malik ben
113
+
114
+ - - -
115
+
116
+ ## storage-ext@0.6.1 - 2026-02-21
32
117
  #### Bug Fixes
33
118
  - using default export instead of named export for extensions - (37dd485) - malik ben
34
119
  #### Miscellaneous Chores
35
- - (**version**) 0.14.0 - (7d2eb87) - Cocogitto Bot
120
+ - (**version**) 0.13.2 - (39b0145) - Cocogitto Bot
121
+ - (**version**) 0.12.3 - (cd06fc0) - Cocogitto Bot
122
+ - (**version**) 0.12.2 - (35b2ff3) - Cocogitto Bot
36
123
  - (**version**) 0.12.1 - (c548105) - Cocogitto Bot
124
+ - (**version**) 0.11.1 - (659ebd3) - Cocogitto Bot
125
+ - adding a comment - (c5c603b) - Malik Najjar
126
+
127
+ - - -
128
+
129
+ ## storage-ext@0.6.0 - 2026-02-17
130
+ #### Features
131
+ - implement event overrides for collection creation and update workflows - (8a05d74) - Malik Najjar
37
132
 
38
133
  - - -
39
134
 
40
- ## storage-ext-studio@0.5.4 - 2026-02-17
135
+ ## storage-ext@0.5.3 - 2026-02-17
41
136
  #### Bug Fixes
42
- - fixing the standalone issue - (1a70a51) - Malik Najjar
137
+ - fixing the publishing issue - (f4d1641) - Malik Najjar
138
+
139
+ - - -
140
+
141
+ ## storage-ext@0.5.2 - 2026-02-17
142
+ #### Bug Fixes
143
+ - publishing the storage studio - (d7dd43e) - Malik Najjar
43
144
  #### Miscellaneous Chores
44
- - (**version**) 0.10.9 - (19ac765) - Cocogitto Bot
145
+ - (**version**) 0.10.2 - (2c92a7d) - Cocogitto Bot
45
146
 
46
147
  - - -
47
148
 
48
- ## storage-ext-studio@0.1.29 - 2026-02-17
149
+ ## storage-ext@0.5.1 - 2026-02-17
49
150
  #### Bug Fixes
50
- - fixing the publishing issue - (f4d1641) - Malik Najjar
151
+ - fixing the storage publish issue - (b75d8d1) - Malik Najjar
51
152
 
52
153
  - - -
53
154
 
54
- ## storage-ext-studio@0.0.1 - 2026-02-17
155
+ ## storage-ext@0.5.0 - 2026-02-17
156
+ #### Features
157
+ - implement storage workflows and controllers for file management - (b9efd0f) - Malik Najjar
158
+ #### Bug Fixes
159
+ - update the auth extension - (5318dda) - Malik Najjar
55
160
  #### Miscellaneous Chores
56
- - (**version**) 0.10.4 - (d0d0474) - Cocogitto Bot
161
+ - added important todo to the storage extension - (43d0bec) - Malik Najjar
162
+ - seperating types from the services file - (8c7bdce) - Malik Najjar
163
+
164
+ - - -
165
+
166
+ ## storage-ext@0.4.0 - 2026-02-16
167
+ #### Features
168
+ - adding the ability to upload files in the ui - (1d7b346) - Malik Najjar
169
+ - update event name in storage workflow and enhance Instagram webhook file handling - (a0cb186) - Malik Najjar
170
+
171
+ - - -
172
+
173
+ ## storage-ext@0.3.0 - 2026-02-16
174
+ #### Features
175
+ - enhance storage services with URL file creation and path validation - (1a33fa6) - Malik Najjar
57
176
 
58
177
  - - -
59
178
 
60
- ## storage-ext-studio@0.0.1 - 2026-02-17
179
+ ## storage-ext@0.2.0 - 2026-02-16
180
+ #### Features
181
+ - implement storage adapter and services, refactor workflows - (abd9ee5) - Malik Najjar
182
+
183
+ - - -
184
+
185
+ ## storage-ext@0.1.29 - 2026-02-15
61
186
  #### Bug Fixes
62
- - publishing the storage studio - (d7dd43e) - Malik Najjar
63
- #### Refactoring
64
- - restructure storage-ext studio components and remove unused files - (a3e375a) - Malik Najjar
187
+ - fix deno publish issue - (e8dcc4f) - malik ben
188
+ - issue fix - (63d66d3) - malik ben
65
189
  #### Miscellaneous Chores
66
- - (**version**) 0.10.2 - (2c92a7d) - Cocogitto Bot
67
190
  - (**version**) 0.5.5 - (d4dedeb) - Cocogitto Bot
68
191
  - (**version**) 0.5.4 - (1ca3970) - Cocogitto Bot
69
192
  - (**version**) 0.5.3 - (dcdb9cb) - Cocogitto Bot
70
193
  - (**version**) 0.5.2 - (aa66e29) - Cocogitto Bot
71
194
  - (**version**) 0.5.1 - (41b7c35) - Cocogitto Bot
72
- - (**version**) 0.4.2 - (4395d99) - Cocogitto Bot
73
- - (**version**) 0.4.1 - (5e9f152) - Cocogitto Bot
74
- - (**version**) 0.4.0 - (aafd2d6) - Cocogitto Bot
75
- #### Style
76
- - Update background color from bg-soft to bg-muted/30 across various components - (ad2240a) - Malik Najjar
195
+ - (**version**) 0.5.0 - (af63147) - Cocogitto Bot
196
+ - (**version**) 0.4.4 - (eaed3b4) - Cocogitto Bot
197
+ - (**version**) 0.4.3 - (ea9ec49) - Cocogitto Bot
77
198
 
78
199
  - - -
79
200
 
package/README.md CHANGED
@@ -1,35 +1 @@
1
- # Storage Extension - Studio
2
-
3
- This directory contains the frontend/dashboard interface for the storage extension.
4
-
5
- ## Structure
6
-
7
- ```
8
- studio/
9
- ├── src/
10
- │ ├── index.ts # Extension entry point
11
- │ ├── main.ts # Vite app entry
12
- │ ├── components/ # UI components
13
- │ │ ├── fileExplorer.svelte
14
- │ │ ├── childrenFileExplorer.svelte
15
- │ │ ├── fileIcon.svelte
16
- │ │ ├── fileManagerBreadCrumbs.svelte
17
- │ │ └── explorerNotSupported.svelte
18
- │ ├── pages/ # UI pages
19
- │ │ └── fileExplorerPage.svelte
20
- │ └── foreignKeyComponent.svelte
21
- ├── public/ # Static assets
22
- ├── index.html # HTML entry point
23
- ├── vite.config.ts # Vite configuration
24
- ├── tailwind.config.ts # Tailwind CSS configuration
25
- └── tsconfig.json # TypeScript configuration
26
- ```
27
-
28
- ## Features
29
-
30
- The studio interface includes:
31
- - File explorer with directory navigation
32
- - File upload and management
33
- - Visual file icons
34
- - Breadcrumb navigation
35
- - Foreign key component integration
1
+ # @lobb-js/lobb-ext-storage
@@ -0,0 +1,18 @@
1
+ import type { StorageAdapter } from "./storageAdapter.ts";
2
+ import type { ExtensionConfig } from "../config/extensionConfigSchema.ts";
3
+ import { LobbError } from "@lobb-js/core";
4
+ import { LocalStorageAdapter } from "./localAdapter.ts";
5
+
6
+ export { StorageAdapter } from "./storageAdapter.ts";
7
+
8
+ export function initStorageAdapter(config: ExtensionConfig): StorageAdapter {
9
+ if (config.adapter === "local") {
10
+ return new LocalStorageAdapter(config);
11
+ } else {
12
+ throw new LobbError({
13
+ code: "INTERNAL_SERVER_ERROR",
14
+ message:
15
+ `The (${config.adapter}) storage adapter is not implemented`,
16
+ });
17
+ }
18
+ }
@@ -0,0 +1,60 @@
1
+ import { LobbError } from "@lobb-js/core";
2
+ import { join } from "node:path";
3
+ import { writeFileSync, readFile, unlink } from "node:fs";
4
+ import { promisify } from "node:util";
5
+ import { StorageAdapter } from "./storageAdapter.ts";
6
+
7
+ const readFileAsync = promisify(readFile);
8
+ const unlinkAsync = promisify(unlink);
9
+
10
+ export class LocalStorageAdapter extends StorageAdapter {
11
+ public async createFile(id: string, file: File): Promise<void> {
12
+ const fullPath = join(
13
+ this.config.storagePath,
14
+ String(id),
15
+ );
16
+
17
+ writeFileSync(fullPath, Buffer.from(await file.arrayBuffer()));
18
+ }
19
+
20
+ public async readFile(id: string): Promise<Uint8Array> {
21
+ const fullPath = join(
22
+ this.config.storagePath,
23
+ String(id),
24
+ );
25
+
26
+ try {
27
+ return new Uint8Array(await readFileAsync(fullPath));
28
+ } catch (error: any) {
29
+ if (error.code === "ENOENT") {
30
+ throw new LobbError({
31
+ code: "NOT_FOUND",
32
+ message: `The file doesn't exist in the file system`,
33
+ });
34
+ }
35
+
36
+ throw error;
37
+ }
38
+ }
39
+
40
+ public async removeFile(id: string): Promise<void> {
41
+ const fullPath = join(
42
+ this.config.storagePath,
43
+ String(id),
44
+ );
45
+
46
+ try {
47
+ await unlinkAsync(fullPath);
48
+ } catch (error: any) {
49
+ if (error.code === "ENOENT") {
50
+ // TODO: when you implement the logging part dont forget to
51
+ // add a log here with the neccessarry information
52
+ console.warn(
53
+ `STORAGE EXTENSION: couldnt delete this file ${fullPath} because it doesnt exist`,
54
+ );
55
+ } else {
56
+ throw error;
57
+ }
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,13 @@
1
+ import type { ExtensionConfig } from "../config/extensionConfigSchema.ts";
2
+
3
+ export abstract class StorageAdapter {
4
+ protected config: ExtensionConfig;
5
+
6
+ constructor(config: ExtensionConfig) {
7
+ this.config = config;
8
+ }
9
+
10
+ public abstract createFile(id: string, file: File): Promise<void>;
11
+ public abstract readFile(id: string): Promise<Uint8Array>;
12
+ public abstract removeFile(id: string): Promise<void>;
13
+ }
@@ -0,0 +1,58 @@
1
+ import type { CollectionConfig } from "@lobb-js/core";
2
+ import type { ExtensionConfig } from "../config/extensionConfigSchema.ts";
3
+
4
+ export function getFileSystemCollection(config: ExtensionConfig): CollectionConfig {
5
+ return {
6
+ "indexes": {},
7
+ "fields": {
8
+ "id": {
9
+ "type": "integer",
10
+ },
11
+ "name": {
12
+ "type": "string",
13
+ "length": 255,
14
+ "validators": {
15
+ "required": true,
16
+ },
17
+ },
18
+ "path": {
19
+ "type": "string",
20
+ "length": 255,
21
+ "pre_processors": {
22
+ "default": "/",
23
+ },
24
+ },
25
+ "type": {
26
+ "type": "string",
27
+ "length": 255,
28
+ "pre_processors": {
29
+ "default": "directory",
30
+ },
31
+ "validators": {
32
+ "enum": [
33
+ "file",
34
+ "directory",
35
+ ],
36
+ },
37
+ },
38
+ "icon": {
39
+ "type": "string",
40
+ "length": 255,
41
+ },
42
+ "is_pinned_sidebar": {
43
+ "type": "bool",
44
+ "pre_processors": {
45
+ "default": "false",
46
+ },
47
+ },
48
+ "file_mime_type": {
49
+ "type": "string",
50
+ "length": 255,
51
+ },
52
+ "file_size": {
53
+ "type": "long",
54
+ },
55
+ ...config.extend_fs?.fields,
56
+ },
57
+ };
58
+ }
@@ -0,0 +1,12 @@
1
+ import type { CollectionConfig } from "@lobb-js/core";
2
+ import type { ExtensionConfig } from "../config/extensionConfigSchema.ts";
3
+ import { getFileSystemCollection } from "./fileSystem.ts";
4
+
5
+ export function collections(extensionConfig: ExtensionConfig): Record<string, CollectionConfig> {
6
+ const collectionsSchemas: Record<string, CollectionConfig> = {};
7
+
8
+ // create the user collection
9
+ collectionsSchemas["storage_fs"] = getFileSystemCollection(extensionConfig);
10
+
11
+ return collectionsSchemas;
12
+ }
@@ -0,0 +1,15 @@
1
+ import type { CollectionFieldsWithoutId } from "@lobb-js/core";
2
+
3
+ type BaseSchema = {};
4
+
5
+ interface ExtendFs {
6
+ fields: CollectionFieldsWithoutId;
7
+ }
8
+
9
+ type LocalAdapter = BaseSchema & {
10
+ adapter: "local";
11
+ storagePath: string;
12
+ extend_fs?: ExtendFs;
13
+ };
14
+
15
+ export type ExtensionConfig = LocalAdapter;
@@ -0,0 +1,26 @@
1
+ import type { Extension } from "@lobb-js/core";
2
+ import type { ExtensionConfig } from "./config/extensionConfigSchema.ts";
3
+ export type { StorageFsCreateOne, StorageFsFindOne } from "./types.ts";
4
+
5
+ import packageJson from "../../package.json" with { type: "json" };
6
+ import studioExtension from "./studioExtension.json" with { type: "json" };
7
+ import { collections } from "./collections/index.ts";
8
+ import { init } from "./init.ts";
9
+ import { meta } from "./meta.ts";
10
+ import { migrations } from "./migrations.ts";
11
+ import { openapi } from "./openapi.ts";
12
+ import { getWorkflows } from "./workflows/index.ts";
13
+
14
+ export default function storage(extensionConfig: ExtensionConfig): Extension {
15
+ return {
16
+ version: packageJson.version,
17
+ name: "storage",
18
+ init: () => init(extensionConfig),
19
+ collections: (_lobb: any) => collections(extensionConfig),
20
+ migrations: migrations,
21
+ meta: meta,
22
+ workflows: getWorkflows(extensionConfig),
23
+ openapi: openapi,
24
+ dashboard: studioExtension,
25
+ };
26
+ }
@@ -0,0 +1,6 @@
1
+ import { mkdir } from "node:fs/promises";
2
+ import type { ExtensionConfig } from "./config/extensionConfigSchema.ts";
3
+
4
+ export async function init(storageConfig: ExtensionConfig) {
5
+ await mkdir(storageConfig.storagePath, { recursive: true });
6
+ }
@@ -0,0 +1,5 @@
1
+ export async function meta() {
2
+ return {
3
+ storageCollectionName: "storage_fs",
4
+ };
5
+ }
@@ -0,0 +1,3 @@
1
+ import type { MigrationProps, Migrations } from "@lobb-js/core";
2
+
3
+ export const migrations: Migrations = {};
@@ -0,0 +1,84 @@
1
+ import type { OpenAPIV3_1 } from "openapi-types";
2
+
3
+ export const paths: OpenAPIV3_1.Document["paths"] = {
4
+ "/api/collections/storage_fs/{id}": {
5
+ "get": {
6
+ "summary": "Get a record Or a file",
7
+ "description": "Get a record Or a file from the file system",
8
+ "parameters": [
9
+ {
10
+ "name": "id",
11
+ "in": "path",
12
+ "required": true,
13
+ "description": "The record ID of record in the file system.",
14
+ "schema": {
15
+ "type": "integer",
16
+ "example": 10,
17
+ },
18
+ },
19
+ {
20
+ "name": "action",
21
+ "in": "query",
22
+ "description": "used to respond with the file itself.",
23
+ "schema": {
24
+ "type": "string",
25
+ "examples": [
26
+ "view",
27
+ "download",
28
+ ],
29
+ },
30
+ },
31
+ ],
32
+ "responses": {
33
+ "200": {
34
+ "description": "Successful operation",
35
+ "content": {
36
+ "application/octet-stream": {
37
+ "schema": {
38
+ "type": "string",
39
+ "format": "binary",
40
+ },
41
+ },
42
+ },
43
+ },
44
+ },
45
+ },
46
+ },
47
+ "/api/collections/storage_fs": {
48
+ "post": {
49
+ "summary": "Create a record Or upload a file",
50
+ "description": "Add new record or upload a file to the file system",
51
+ "requestBody": {
52
+ "required": true,
53
+ "content": {
54
+ "multipart/form-data": {
55
+ "schema": {
56
+ "type": "object",
57
+ "required": ["file"],
58
+ "properties": {
59
+ "file": {
60
+ "type": "string",
61
+ "format": "binary",
62
+ "description": "The file to be uploaded",
63
+ },
64
+ "data": {
65
+ "type": "string",
66
+ "description": "data of the record",
67
+ },
68
+ },
69
+ },
70
+ },
71
+ },
72
+ },
73
+ "responses": {
74
+ "201": {
75
+ "description": "Successful operation",
76
+ },
77
+ },
78
+ },
79
+ },
80
+ };
81
+
82
+ export const openapi = {
83
+ paths: paths,
84
+ };