-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #428 from a-type/sqlite
Alternative persistence support alpha
- Loading branch information
Showing
109 changed files
with
8,305 additions
and
1,990 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"mode": "pre", | ||
"tag": "alpha", | ||
"initialVersions": { | ||
"@verdant-web/cli": "4.7.0", | ||
"@verdant-web/common": "2.6.0", | ||
"@verdant-web/create-app": "0.6.1", | ||
"@verdant-web/s3-file-storage": "1.0.30", | ||
"@verdant-web/persistence-capacitor-sqlite": "0.1.0-alpha.1", | ||
"@verdant-web/persistence-sqlite": "0.1.0-alpha.1", | ||
"@verdant-web/react": "39.0.0", | ||
"@verdant-web/react-router": "0.6.5", | ||
"@verdant-web/server": "3.3.3", | ||
"@verdant-web/store": "4.0.0" | ||
}, | ||
"changesets": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@verdant-web/common': minor | ||
'@verdant-web/store': minor | ||
--- | ||
|
||
Beginning of support for alternative persistence implementations. This involves major internal refactoring and some undocumented internal-use-only library API changes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "@verdant-web/persistence-capacitor-sqlite", | ||
"version": "0.1.0-alpha.1", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"development": "./src/index.ts", | ||
"import": "./dist/esm/index.js", | ||
"types": "./dist/esm/index.d.ts" | ||
} | ||
}, | ||
"publishConfig": { | ||
"exports": { | ||
".": { | ||
"import": "./dist/esm/index.js", | ||
"types": "./dist/esm/index.d.ts" | ||
} | ||
}, | ||
"access": "public" | ||
}, | ||
"files": [ | ||
"dist/", | ||
"src/" | ||
], | ||
"scripts": { | ||
"test": "vitest", | ||
"build": "tsc", | ||
"prepublishOnly": "pnpm run build" | ||
}, | ||
"dependencies": { | ||
"@capacitor-community/sqlite": "^6.0.2", | ||
"@capacitor/filesystem": "^6.0.1", | ||
"@verdant-web/persistence-sqlite": "workspace:*", | ||
"capacitor-sqlite-kysely": "^1.0.1", | ||
"kysely": "^0.27.4" | ||
}, | ||
"peerDependencies": { | ||
"@verdant-web/store": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@verdant-web/store": "workspace:*", | ||
"vitest": "2.1.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { CapacitorSQLite, SQLiteConnection } from '@capacitor-community/sqlite'; | ||
import { | ||
SqlitePersistence, | ||
FilesystemImplementation, | ||
} from '@verdant-web/persistence-sqlite'; | ||
import CapacitorSQLiteKyselyDialect from 'capacitor-sqlite-kysely'; | ||
import { Kysely } from 'kysely'; | ||
import { Directory, Filesystem } from '@capacitor/filesystem'; | ||
import path from 'path'; | ||
|
||
function getKysely(databaseFile: string) { | ||
return new Kysely({ | ||
dialect: new CapacitorSQLiteKyselyDialect( | ||
new SQLiteConnection(CapacitorSQLite), | ||
{ name: databaseFile }, | ||
) as any, | ||
}); | ||
} | ||
|
||
class CapacitorFilesystem implements FilesystemImplementation { | ||
copyDirectory = async (options: { from: string; to: string }) => { | ||
await Filesystem.copy({ | ||
from: options.from, | ||
to: options.to, | ||
}); | ||
}; | ||
deleteFile = (path: string) => Filesystem.deleteFile({ path }); | ||
readDirectory = async (path: string) => { | ||
const result = await Filesystem.readdir({ path }); | ||
return result.files.map((f) => f.name); | ||
}; | ||
writeFile = async (path: string, data: Blob) => { | ||
await Filesystem.writeFile({ | ||
path, | ||
data, | ||
}); | ||
}; | ||
copyFile = async (options: { from: string; to: string }) => { | ||
await Filesystem.copy({ | ||
from: options.from, | ||
to: options.to, | ||
}); | ||
}; | ||
readFile = async (path: string) => { | ||
const res = await Filesystem.readFile({ | ||
path, | ||
}); | ||
if (typeof res.data === 'string') { | ||
throw new Error( | ||
"Verdant doesn't support non-Web Capacitor runtime environments.", | ||
); | ||
} | ||
return res.data; | ||
}; | ||
} | ||
|
||
export class CapacitorSQLitePersistence extends SqlitePersistence { | ||
constructor() { | ||
super({ | ||
getKysely, | ||
filesystem: new CapacitorFilesystem(), | ||
databaseDirectory: path.resolve(Directory.Data, 'databases'), | ||
userFilesDirectory: path.resolve(Directory.Data, 'userFiles'), | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"outDir": "./dist/esm", | ||
"lib": ["esnext", "dom"], | ||
"moduleResolution": "bundler", | ||
"module": "es2020" | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.mts", "./typings"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
environment: 'jsdom', | ||
clearMocks: true, | ||
|
||
setupFiles: ['src/__tests__/setup/indexedDB.ts'], | ||
}, | ||
resolve: { | ||
conditions: ['development', 'default'], | ||
}, | ||
}); |
Oops, something went wrong.