data-of-loathing 3.0.3 → 3.0.4
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.
- package/dist/vite.d.ts +2 -0
- package/dist/vite.js +18 -0
- package/package.json +4 -2
- package/dist/browser-client.d.ts +0 -17
- package/dist/browser-client.js +0 -58
- package/dist/browser-strategies.d.ts +0 -9
- package/dist/browser-strategies.js +0 -37
- package/dist/client.d.ts +0 -11
- package/dist/client.js +0 -29
- package/dist/http-range-worker.d.ts +0 -1
- package/dist/http-range-worker.js +0 -25844
- package/dist/http-vfs-dialect.d.ts +0 -9
- package/dist/http-vfs-dialect.js +0 -93
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -5
- package/dist/sqlite3.wasm +0 -0
- package/dist/strategies.d.ts +0 -15
- package/dist/strategies.js +0 -46
package/dist/vite.d.ts
ADDED
package/dist/vite.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import sqlocalPlugin from "sqlocal/vite";
|
|
2
|
+
import { nodePolyfills } from "vite-plugin-node-polyfills";
|
|
3
|
+
export default function dol() {
|
|
4
|
+
return [
|
|
5
|
+
sqlocalPlugin({ coi: false }),
|
|
6
|
+
nodePolyfills({ include: ["buffer"] }),
|
|
7
|
+
{
|
|
8
|
+
name: "data-of-loathing-coi",
|
|
9
|
+
configureServer(server) {
|
|
10
|
+
server.middlewares.use((_, res, next) => {
|
|
11
|
+
res.setHeader("Cross-Origin-Embedder-Policy", "credentialless");
|
|
12
|
+
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
|
|
13
|
+
next();
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-of-loathing",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"packageManager": "yarn@4.6.0",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
],
|
|
26
26
|
"typesVersions": {
|
|
27
27
|
"*": {
|
|
28
|
-
"vite": [
|
|
28
|
+
"vite": [
|
|
29
|
+
"./dist/vite.d.ts"
|
|
30
|
+
]
|
|
29
31
|
}
|
|
30
32
|
},
|
|
31
33
|
"scripts": {
|
package/dist/browser-client.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type EntityManager } from "@mikro-orm/core";
|
|
2
|
-
export type Strategy = {
|
|
3
|
-
strategy?: "cache";
|
|
4
|
-
url?: string;
|
|
5
|
-
} | {
|
|
6
|
-
strategy: "remote";
|
|
7
|
-
url?: string;
|
|
8
|
-
};
|
|
9
|
-
export declare class Client {
|
|
10
|
-
private _orm?;
|
|
11
|
-
private readonly _strategy;
|
|
12
|
-
constructor(strategy?: Strategy);
|
|
13
|
-
get em(): EntityManager;
|
|
14
|
-
load(): Promise<void>;
|
|
15
|
-
private _db?;
|
|
16
|
-
}
|
|
17
|
-
export declare function createClient(strategy?: Strategy): Client;
|
package/dist/browser-client.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { SqlMikroORM, SqliteDriver } from "@mikro-orm/sql";
|
|
2
|
-
import { HttpVFSDialect } from "./http-vfs-dialect.js";
|
|
3
|
-
import { entities } from "data-of-loathing-schema";
|
|
4
|
-
const DEFAULT_URL = "https://data.loathers.net/dol.sqlite";
|
|
5
|
-
const ETAG_KEY = "dol-etag";
|
|
6
|
-
export class Client {
|
|
7
|
-
_orm;
|
|
8
|
-
_strategy;
|
|
9
|
-
constructor(strategy = {}) {
|
|
10
|
-
this._strategy = strategy;
|
|
11
|
-
}
|
|
12
|
-
get em() {
|
|
13
|
-
if (!this._orm)
|
|
14
|
-
throw new Error("Call await client.load() before querying");
|
|
15
|
-
return this._orm.em;
|
|
16
|
-
}
|
|
17
|
-
async load() {
|
|
18
|
-
await this._orm?.close();
|
|
19
|
-
const url = this._strategy.url ?? DEFAULT_URL;
|
|
20
|
-
if (this._strategy.strategy === "remote") {
|
|
21
|
-
this._orm = await SqlMikroORM.init({
|
|
22
|
-
driver: SqliteDriver,
|
|
23
|
-
driverOptions: new HttpVFSDialect(url),
|
|
24
|
-
dbName: url,
|
|
25
|
-
entities,
|
|
26
|
-
allowGlobalContext: true,
|
|
27
|
-
});
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const { SQLocalKysely } = await import("sqlocal/kysely");
|
|
31
|
-
if (!this._db) {
|
|
32
|
-
this._db = new SQLocalKysely("dol.sqlite");
|
|
33
|
-
}
|
|
34
|
-
const storedEtag = localStorage.getItem(ETAG_KEY);
|
|
35
|
-
const head = await fetch(url, { method: "HEAD" });
|
|
36
|
-
const remoteEtag = head.headers.get("etag");
|
|
37
|
-
if (!storedEtag || storedEtag !== remoteEtag) {
|
|
38
|
-
const response = await fetch(url);
|
|
39
|
-
if (!response.ok)
|
|
40
|
-
throw new Error(`Failed to fetch database: ${response.status}`);
|
|
41
|
-
await this._db.overwriteDatabaseFile(await response.arrayBuffer());
|
|
42
|
-
if (remoteEtag)
|
|
43
|
-
localStorage.setItem(ETAG_KEY, remoteEtag);
|
|
44
|
-
}
|
|
45
|
-
this._orm = await SqlMikroORM.init({
|
|
46
|
-
driver: SqliteDriver,
|
|
47
|
-
driverOptions: this._db.dialect,
|
|
48
|
-
dbName: "dol.sqlite",
|
|
49
|
-
entities,
|
|
50
|
-
allowGlobalContext: true,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
// sqlocal instance kept across load() calls to preserve OPFS connection
|
|
54
|
-
_db;
|
|
55
|
-
}
|
|
56
|
-
export function createClient(strategy = {}) {
|
|
57
|
-
return new Client(strategy);
|
|
58
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const DEFAULT_URL = "https://data.loathers.net/data-of-loathing.sqlite";
|
|
2
|
-
export type BrowserStrategy = {
|
|
3
|
-
strategy?: "cache";
|
|
4
|
-
url?: string;
|
|
5
|
-
} | {
|
|
6
|
-
strategy: "remote";
|
|
7
|
-
url?: string;
|
|
8
|
-
};
|
|
9
|
-
export declare function resolveDbPath(opts: BrowserStrategy): Promise<string>;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_URL = "https://data.loathers.net/data-of-loathing.sqlite";
|
|
2
|
-
const OPFS_FILENAME = "data-of-loathing.sqlite";
|
|
3
|
-
const ETAG_KEY = "data-of-loathing-etag";
|
|
4
|
-
async function writeToOpfs(data) {
|
|
5
|
-
const root = await navigator.storage.getDirectory();
|
|
6
|
-
const handle = await root.getFileHandle(OPFS_FILENAME, { create: true });
|
|
7
|
-
const writable = await handle.createWritable();
|
|
8
|
-
await writable.write(data);
|
|
9
|
-
await writable.close();
|
|
10
|
-
}
|
|
11
|
-
async function opfsFileExists() {
|
|
12
|
-
try {
|
|
13
|
-
const root = await navigator.storage.getDirectory();
|
|
14
|
-
await root.getFileHandle(OPFS_FILENAME);
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export async function resolveDbPath(opts) {
|
|
22
|
-
if (opts.strategy === "remote")
|
|
23
|
-
throw new Error("HTTP range request strategy not yet implemented");
|
|
24
|
-
const url = opts.url ?? DEFAULT_URL;
|
|
25
|
-
const storedEtag = localStorage.getItem(ETAG_KEY);
|
|
26
|
-
const head = await fetch(url, { method: "HEAD" });
|
|
27
|
-
const remoteEtag = head.headers.get("etag");
|
|
28
|
-
if (!(await opfsFileExists()) || storedEtag !== remoteEtag) {
|
|
29
|
-
const response = await fetch(url);
|
|
30
|
-
if (!response.ok)
|
|
31
|
-
throw new Error(`Failed to fetch database: ${response.status}`);
|
|
32
|
-
await writeToOpfs(await response.arrayBuffer());
|
|
33
|
-
if (remoteEtag)
|
|
34
|
-
localStorage.setItem(ETAG_KEY, remoteEtag);
|
|
35
|
-
}
|
|
36
|
-
return OPFS_FILENAME;
|
|
37
|
-
}
|
package/dist/client.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { EntityManager } from "@mikro-orm/core";
|
|
2
|
-
import { type Strategy } from "./strategies.js";
|
|
3
|
-
export type { Strategy };
|
|
4
|
-
export declare class Client {
|
|
5
|
-
private _orm?;
|
|
6
|
-
private readonly _strategy;
|
|
7
|
-
constructor(strategy?: Strategy);
|
|
8
|
-
get em(): EntityManager;
|
|
9
|
-
load(): Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
export declare function createClient(strategy?: Strategy): Client;
|
package/dist/client.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { NodeSqliteDialect, SqliteDriver, SqlMikroORM } from "@mikro-orm/sql";
|
|
2
|
-
import { entities } from "data-of-loathing-schema";
|
|
3
|
-
import { resolveDbPath } from "./strategies.js";
|
|
4
|
-
export class Client {
|
|
5
|
-
_orm;
|
|
6
|
-
_strategy;
|
|
7
|
-
constructor(strategy = {}) {
|
|
8
|
-
this._strategy = strategy;
|
|
9
|
-
}
|
|
10
|
-
get em() {
|
|
11
|
-
if (!this._orm)
|
|
12
|
-
throw new Error("Call await client.load() before querying");
|
|
13
|
-
return this._orm.em;
|
|
14
|
-
}
|
|
15
|
-
async load() {
|
|
16
|
-
await this._orm?.close();
|
|
17
|
-
const path = await resolveDbPath(this._strategy);
|
|
18
|
-
this._orm = await SqlMikroORM.init({
|
|
19
|
-
driver: SqliteDriver,
|
|
20
|
-
driverOptions: new NodeSqliteDialect(path),
|
|
21
|
-
dbName: path,
|
|
22
|
-
entities,
|
|
23
|
-
allowGlobalContext: true,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export function createClient(strategy = {}) {
|
|
28
|
-
return new Client(strategy);
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|