-
-
Notifications
You must be signed in to change notification settings - Fork 5
Feat/support idb paths #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
New, updated, and removed dependencies detected. Learn more about Socket for GitHub ↗︎
|
WalkthroughThe changes introduce support for IndexedDB semantic paths for file uploads. A new section in the README documents the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant UploaderWeb
participant PathHelper
participant IndexedDB
User->>UploaderWeb: Request file retrieval (filePath)
UploaderWeb->>PathHelper: isIndexedDBPath(filePath)
PathHelper-->>UploaderWeb: true/false
alt Path is IndexedDB
UploaderWeb->>UploaderWeb: parseIndexedDBPath(filePath)
UploaderWeb->>IndexedDB: openDB(database) & fetch blob using key
IndexedDB-->>UploaderWeb: blob
UploaderWeb->>UploaderWeb: Convert blob to File
else
UploaderWeb->>UploaderWeb: getFileFromSystem(filePath)
end
UploaderWeb-->>User: Return File or error
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (6)
src/web.ts (3)
100-107
: Consider fallback or error-handling for non-standard paths.
Currently, if the path is not identified as IndexedDB, it defaults to a system file fetch. If there's a possibility of invalid or malformed paths that are neither valid IDB nor valid system paths, you may want to validate further or handle errors more explicitly.
109-137
: Validate database version and store creation approach.
Initializing the database with version1
and creating a store on the fly can cause confusion over time or in multi-process scenarios. Consider a more robust strategy for versioning and object store creation to ensure the schema is managed as it evolves.
142-143
: Refine error-handling and logging for system paths.
The simplified comment states potential expansions, but future logic might benefit from distinct error handling for different path types (e.g., local file URLs, remote URLs, etc.). Also, decide if you want to propagate errors or remain silent with anull
return.Also applies to: 150-150
src/PathHelper.ts (1)
1-23
: Translate static-only class into plain functions if no state or polymorphism is needed.
According to the static analysis hint, consider using standalone functions for clarity if you only need these static helpers. This can reduce boilerplate and keep your code simpler.-export class PathHelper { - static isIndexedDBPath(path: string): boolean { - const regex = /^idb:\/\/([^/]+)\/([^/]+)\/(.+)$/; - return regex.test(path); - } - - static parseIndexedDBPath(path: string): { database: string, storeName: string, key: string } { - const regex = /^idb:\/\/([^/]+)\/([^/]+)\/(.+)$/; - const match = path.match(regex); - if (!match) { - throw new Error('Invalid IndexedDB path format'); - } - return { - database: match[1], - storeName: match[2], - key: match[3], - }; - } -} +export function isIndexedDBPath(path: string): boolean { + const regex = /^idb:\/\/([^/]+)\/([^/]+)\/(.+)$/; + return regex.test(path); +} + +export function parseIndexedDBPath(path: string): { + database: string; + storeName: string; + key: string; +} { + const regex = /^idb:\/\/([^/]+)\/([^/]+)\/(.+)$/; + const match = path.match(regex); + if (!match) { + throw new Error('Invalid IndexedDB path format'); + } + return { + database: match[1], + storeName: match[2], + key: match[3], + }; +}🧰 Tools
🪛 Biome (1.9.4)
[error] 1-23: Avoid classes that contain only static members.
Prefer using simple functions instead of classes with only static members.
(lint/complexity/noStaticOnlyClass)
README.md (2)
71-71
: Markdown Style Improvement: Remove Trailing Punctuation.
The heading “### Example upload to a custom server:” ends with a colon. Removing the colon will comply with markdown lint rules (MD026).🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
71-71: Trailing punctuation in heading
Punctuation: ':'(MD026, no-trailing-punctuation)
128-128
: Markdown Style Improvement: Remove Trailing Punctuation.
Similarly, the heading “### Example with Capacitor Camera preview:” has a trailing colon. Removing it will enhance consistency with markdown style guidelines.🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
128-128: Trailing punctuation in heading
Punctuation: ':'(MD026, no-trailing-punctuation)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (5)
README.md
(3 hunks)package.json
(1 hunks)rollup.config.mjs
(2 hunks)src/PathHelper.ts
(1 hunks)src/web.ts
(2 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
README.md
71-71: Trailing punctuation in heading
Punctuation: ':'
(MD026, no-trailing-punctuation)
128-128: Trailing punctuation in heading
Punctuation: ':'
(MD026, no-trailing-punctuation)
🪛 Biome (1.9.4)
src/PathHelper.ts
[error] 1-23: Avoid classes that contain only static members.
Prefer using simple functions instead of classes with only static members.
(lint/complexity/noStaticOnlyClass)
🔇 Additional comments (4)
src/web.ts (1)
2-4
: New imports look good.
These new imports (openDB
from 'idb' andPathHelper
) properly align with the IndexedDB functionality and external helper usage.rollup.config.mjs (1)
10-10
: External and globals mappings look correct.
Adding'idb'
to theglobals
object and treating it as an external dependency is consistent with your usage insrc/web.ts
. Ensure the environment providesidb
as a global if your IIFE bundle requires it at runtime.Would you like me to generate a script to confirm the global is properly exposed during bundling or to check your build logs?
Also applies to: 22-22
package.json (1)
101-103
: Addition of IndexedDB Dependency.
The new"dependencies"
block adding"idb": "^8.0.2"
supports the IndexedDB semantic paths feature. Please ensure that this version is compatible with the rest of the project and that the dependency is correctly integrated (e.g., in your Rollup configuration as noted in the README).README.md (1)
15-17
: Enhanced Documentation for IndexedDB Paths.
This new section clearly explains theidb://[database-name]/[collection-name]/[key]
path format for file uploads on the web. To further help users, consider adding a link or reference to the officialidb
library documentation.
Summary by CodeRabbit