-
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #209 from StarfilesFileSharing/alpha
Alpha
- Loading branch information
Showing
23 changed files
with
297 additions
and
289 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 |
---|---|---|
|
@@ -110,4 +110,6 @@ build/ | |
|
||
__sysdb__.sqlite | ||
public/docs/ | ||
typedoc-theme/ | ||
typedoc-theme/ | ||
|
||
sandbox/ |
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 |
---|---|---|
|
@@ -10,9 +10,11 @@ console.log( | |
format: "esm", | ||
platform: "browser", | ||
sourcemap: true, | ||
minify: true, | ||
treeShaking: true, | ||
keepNames: true, | ||
minify: false, // TODO: Toggle for dev/prod | ||
treeShaking: false, // TODO: Toggle for dev/prod | ||
sourcesContent: true, // TODO: Toggle for dev/prod | ||
metafile: true, | ||
}), | ||
await esbuild.build({ | ||
plugins: [...denoPlugins()], | ||
|
@@ -22,10 +24,12 @@ console.log( | |
format: "esm", | ||
platform: "browser", | ||
sourcemap: true, | ||
minify: true, | ||
treeShaking: true, | ||
external: ["https://esm.sh/[email protected]"], | ||
keepNames: true, | ||
minify: false, // TODO: Toggle for dev/prod | ||
treeShaking: false, // TODO: Toggle for dev/prod | ||
sourcesContent: true, // TODO: Toggle for dev/prod | ||
metafile: true, | ||
external: ["https://esm.sh/[email protected]"], | ||
}), | ||
); | ||
|
||
|
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import type { Database as SQLite } from "jsr:@db/sqlite"; | ||
import type { indexedDB } from "https://deno.land/x/[email protected]/ponyfill.ts"; | ||
import { ErrorMissingRequiredProperty, ErrorNotFound, ErrorNotInitialised } from "./errors.ts"; | ||
import Hydrafiles, { type NonEmptyString } from "./hydrafiles.ts"; | ||
import Hydrafiles from "./hydrafiles.ts"; | ||
import type { NonEmptyString } from "./utils.ts"; | ||
|
||
export interface ModelType { | ||
tableName: string; | ||
|
@@ -66,7 +67,7 @@ export default class Database<T extends ModelType> { | |
|
||
if (typeof window === "undefined") { | ||
const SQLite = (await import("jsr:@db/sqlite")).Database; | ||
const db: DatabaseWrapperSQLite = { type: "SQLITE", db: new SQLite(`${model.tableName}.db`) }; | ||
const db: DatabaseWrapperSQLite = { type: "SQLITE", db: new SQLite(`${client.config.baseDir}${model.tableName}.db`) }; | ||
database.db = db; | ||
|
||
const columns = Object.entries(model.columns) | ||
|
@@ -83,11 +84,11 @@ export default class Database<T extends ModelType> { | |
Object.entries(model.columns).forEach(([name, def]) => addColumnIfNotExists(db.db, model.tableName, name, def.type)); | ||
} else { | ||
const db = await new Promise<IDBDatabase>((resolve, reject) => { | ||
console.log(`Startup: ${model.tableName}DB: Opening IndexedDB Connection`); | ||
console.log(`Database: ${model.tableName}DB: Opening IndexedDB Connection`); | ||
// @ts-expect-error: | ||
const request = indexedDB.open(model.tableName, 2); | ||
request.onupgradeneeded = (event): void => { | ||
console.log(`Startup: ${model.tableName}DB: On Upgrade Needed`); | ||
console.log(`Database: ${model.tableName}DB: On Upgrade Needed`); | ||
// @ts-expect-error: | ||
if (!event.target.result.objectStoreNames.contains(model.tableName)) { | ||
// @ts-expect-error: | ||
|
@@ -102,15 +103,15 @@ export default class Database<T extends ModelType> { | |
} | ||
}; | ||
request.onsuccess = () => { | ||
console.log(`Startup: ${model.tableName}DB: On Success`); | ||
console.log(`Database: ${model.tableName}DB: On Success`); | ||
resolve(request.result as unknown as IDBDatabase); | ||
}; | ||
request.onerror = () => { | ||
console.error(`Startup: ${model.tableName}DB error:`, request.error); | ||
console.error(`Database: ${model.tableName}DB error:`, request.error); | ||
reject(request.error); | ||
}; | ||
request.onblocked = () => { | ||
console.error(`Startup: ${model.tableName}DB: Blocked. Close other tabs with this site open.`); | ||
console.error(`Database: ${model.tableName}DB: Blocked. Close other tabs with this site open.`); | ||
}; | ||
}); | ||
database.db = { type: "INDEXEDDB", db: db }; | ||
|
@@ -361,7 +362,7 @@ export default class Database<T extends ModelType> { | |
} as Partial<DatabaseModal<T>>; | ||
|
||
for (const [key, def] of Object.entries(this.model.columns)) { | ||
if (!def.default && !def.isNullable && result[key as keyof DatabaseModal<T>] === undefined) return new ErrorMissingRequiredProperty(`Missing required property: ${key}`); | ||
if (!def.default && !def.isNullable && result[key as keyof DatabaseModal<T>] === undefined) return new ErrorMissingRequiredProperty(key); | ||
} | ||
|
||
return result as DatabaseModal<T>; | ||
|
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
Oops, something went wrong.