@idb-orm/core 1.0.3 → 1.0.5
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/LICENSE +7 -0
- package/README.md +4 -0
- package/dist/client/compiled-query.d.ts +4 -14
- package/dist/client/delete.d.ts +14 -0
- package/dist/client/helpers.d.ts +1 -2
- package/dist/client/index.d.ts +4 -32
- package/dist/client/types/find.d.ts +15 -99
- package/dist/client/types/index.d.ts +41 -77
- package/dist/client/types/mutation.d.ts +41 -220
- package/dist/field/field.d.ts +1 -1
- package/dist/field/property.d.ts +70 -0
- package/dist/index.js +1 -2
- package/dist/model/model-types.d.ts +24 -111
- package/dist/model/model.d.ts +5 -23
- package/dist/object-store.d.ts +1 -2
- package/dist/transaction.d.ts +11 -22
- package/dist/types/common.d.ts +4 -1
- package/dist/utils.d.ts +1 -2
- package/package.json +4 -4
- package/test-results/.last-run.json +8 -0
- package/test-results/test-1-page-multi-test-Sample-DB-chromium/error-context.md +8 -0
- package/test-results/test-1-page-multi-test-Sample-DB-firefox/error-context.md +8 -0
- package/test-results/test-1-page-multi-test-Sample-DB-webkit/error-context.md +8 -0
- package/dist/index.js.map +0 -1
- package/eslint.config.js +0 -55
- package/playwright.config.ts +0 -79
- package/tests/helpers.ts +0 -72
- package/tests/test.spec.ts +0 -101
package/eslint.config.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import eslint from "@eslint/js";
|
|
2
|
-
import { defineConfig } from "eslint/config";
|
|
3
|
-
import tseslint from "typescript-eslint";
|
|
4
|
-
import globals from "globals";
|
|
5
|
-
import path from "path";
|
|
6
|
-
|
|
7
|
-
export default defineConfig(
|
|
8
|
-
eslint.configs.recommended,
|
|
9
|
-
tseslint.configs.recommendedTypeChecked,
|
|
10
|
-
{
|
|
11
|
-
rules: {
|
|
12
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
13
|
-
"@typescript-eslint/no-unsafe-function-type": "off",
|
|
14
|
-
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
15
|
-
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
16
|
-
"@typescript-eslint/restrict-template-expressions": "off",
|
|
17
|
-
"@typescript-eslint/no-empty-object-type": "off",
|
|
18
|
-
"@typescript-eslint/switch-exhaustiveness-check": [
|
|
19
|
-
"error",
|
|
20
|
-
{
|
|
21
|
-
considerDefaultExhaustiveForUnions: true,
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
"@typescript-eslint/no-unused-vars": [
|
|
25
|
-
"error",
|
|
26
|
-
{
|
|
27
|
-
args: "all",
|
|
28
|
-
argsIgnorePattern: "^_",
|
|
29
|
-
caughtErrors: "all",
|
|
30
|
-
caughtErrorsIgnorePattern: "^_",
|
|
31
|
-
destructuredArrayIgnorePattern: "^_",
|
|
32
|
-
varsIgnorePattern: "^_",
|
|
33
|
-
ignoreRestSiblings: true,
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
languageOptions: {
|
|
38
|
-
parserOptions: {
|
|
39
|
-
projectService: true,
|
|
40
|
-
tsconfigRootDir: path.resolve("./packages/core"),
|
|
41
|
-
},
|
|
42
|
-
globals: globals.browser,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
ignores: [
|
|
47
|
-
"eslint.config.js",
|
|
48
|
-
"rollup.config.ts",
|
|
49
|
-
"**/dist/*",
|
|
50
|
-
"**/test-client/*",
|
|
51
|
-
"**/*.config.*",
|
|
52
|
-
"**/tests/*",
|
|
53
|
-
],
|
|
54
|
-
}
|
|
55
|
-
);
|
package/playwright.config.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { defineConfig, devices } from "@playwright/test";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Read environment variables from file.
|
|
5
|
-
* https://github.com/motdotla/dotenv
|
|
6
|
-
*/
|
|
7
|
-
// import dotenv from 'dotenv';
|
|
8
|
-
// import path from 'path';
|
|
9
|
-
// dotenv.config({ path: path.resolve(__dirname, '.env') });
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* See https://playwright.dev/docs/test-configuration.
|
|
13
|
-
*/
|
|
14
|
-
export default defineConfig({
|
|
15
|
-
testDir: "./tests",
|
|
16
|
-
/* Run tests in files in parallel */
|
|
17
|
-
fullyParallel: true,
|
|
18
|
-
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
|
19
|
-
forbidOnly: !!process.env.CI,
|
|
20
|
-
/* Retry on CI only */
|
|
21
|
-
retries: process.env.CI ? 2 : 0,
|
|
22
|
-
/* Opt out of parallel tests on CI. */
|
|
23
|
-
workers: process.env.CI ? 1 : undefined,
|
|
24
|
-
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
|
25
|
-
// reporter: "html",
|
|
26
|
-
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
27
|
-
use: {
|
|
28
|
-
/* Base URL to use in actions like `await page.goto('')`. */
|
|
29
|
-
// baseURL: 'http://localhost:3000',
|
|
30
|
-
|
|
31
|
-
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
32
|
-
trace: "on-first-retry",
|
|
33
|
-
headless: true,
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
/* Configure projects for major browsers */
|
|
37
|
-
projects: [
|
|
38
|
-
{
|
|
39
|
-
name: "chromium",
|
|
40
|
-
use: { ...devices["Desktop Chrome"] },
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
{
|
|
44
|
-
name: "firefox",
|
|
45
|
-
use: { ...devices["Desktop Firefox"] },
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
{
|
|
49
|
-
name: "webkit",
|
|
50
|
-
use: { ...devices["Desktop Safari"] },
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
/* Test against mobile viewports. */
|
|
54
|
-
// {
|
|
55
|
-
// name: 'Mobile Chrome',
|
|
56
|
-
// use: { ...devices['Pixel 5'] },
|
|
57
|
-
// },
|
|
58
|
-
// {
|
|
59
|
-
// name: 'Mobile Safari',
|
|
60
|
-
// use: { ...devices['iPhone 12'] },
|
|
61
|
-
// },
|
|
62
|
-
|
|
63
|
-
/* Test against branded browsers. */
|
|
64
|
-
// {
|
|
65
|
-
// name: 'Microsoft Edge',
|
|
66
|
-
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
|
67
|
-
// },
|
|
68
|
-
// {
|
|
69
|
-
// name: 'Google Chrome',
|
|
70
|
-
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
|
|
71
|
-
// },
|
|
72
|
-
],
|
|
73
|
-
|
|
74
|
-
/* Run your local dev server before starting the tests */
|
|
75
|
-
webServer: {
|
|
76
|
-
command: "npx serve dist -l 4173",
|
|
77
|
-
port: 4173,
|
|
78
|
-
},
|
|
79
|
-
});
|
package/tests/helpers.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Page } from "@playwright/test";
|
|
2
|
-
import { Keyof } from "../src/types/common.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Will navigate to the served page and import zod and the package
|
|
6
|
-
*
|
|
7
|
-
* Will also ensure that the package is properly loaded
|
|
8
|
-
* @param context Playwright BrowserContext
|
|
9
|
-
*/
|
|
10
|
-
export async function populatePage<P extends Record<string, any>>(
|
|
11
|
-
page: Page,
|
|
12
|
-
vars: Record<keyof P, string | EvalFn<P, any>>
|
|
13
|
-
) {
|
|
14
|
-
await page.goto("http://localhost:4173/");
|
|
15
|
-
const manager = new ContextSession<P>(page, vars);
|
|
16
|
-
await manager.populate();
|
|
17
|
-
return manager;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function getFn(fn: Function) {
|
|
21
|
-
return fn.toString().match(/^async \(\{([^\}]+)\}\) \=\> \{([\s\S]*)\}$/m);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type EvalFn<
|
|
25
|
-
Types extends Record<string, any>,
|
|
26
|
-
This extends keyof Types
|
|
27
|
-
> = (args: Omit<Types, This>) => Promise<any>;
|
|
28
|
-
|
|
29
|
-
export class ContextSession<Types extends Record<string, any>> {
|
|
30
|
-
constructor(
|
|
31
|
-
private page: Page,
|
|
32
|
-
private variables: {
|
|
33
|
-
[K in keyof Types]: string | EvalFn<Types, K>;
|
|
34
|
-
}
|
|
35
|
-
) {}
|
|
36
|
-
|
|
37
|
-
async populate() {
|
|
38
|
-
// Construct the script
|
|
39
|
-
await this.page.addScriptTag({
|
|
40
|
-
type: "module",
|
|
41
|
-
content: `
|
|
42
|
-
window.isReady = (async () => {
|
|
43
|
-
window.vars = {};
|
|
44
|
-
${Object.keys(this.variables)
|
|
45
|
-
.map((key) => {
|
|
46
|
-
const element = this.variables[key];
|
|
47
|
-
switch (typeof element) {
|
|
48
|
-
case "function":
|
|
49
|
-
return `window.vars.${key} = await (${element.toString()})(window.vars);`;
|
|
50
|
-
default:
|
|
51
|
-
return `window.vars.${key} = await ${element};`;
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
.join("\n")}
|
|
55
|
-
})();
|
|
56
|
-
`,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
await this.page.evaluate(async () => {
|
|
60
|
-
await (window as any).isReady;
|
|
61
|
-
await new Promise((res) => setTimeout(res, 100));
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async evaluate<Result>(
|
|
66
|
-
fn: (args: Types) => Promise<Result>
|
|
67
|
-
): Promise<Result> {
|
|
68
|
-
return await this.page.evaluate(
|
|
69
|
-
`(async () => await (${fn.toString()})(window.vars))();`
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
}
|
package/tests/test.spec.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { test, expect, Page } from "@playwright/test";
|
|
2
|
-
import { ContextSession, EvalFn, populatePage } from "./helpers.js";
|
|
3
|
-
import { Builder, Field } from "../dist/index.js";
|
|
4
|
-
import * as idbOrm from "../dist/index.js";
|
|
5
|
-
import * as zod from "zod";
|
|
6
|
-
|
|
7
|
-
export type Packages = {
|
|
8
|
-
pkg: typeof idbOrm;
|
|
9
|
-
zod: typeof zod;
|
|
10
|
-
};
|
|
11
|
-
export type SessionArguments = Packages & {
|
|
12
|
-
client: Awaited<ReturnType<typeof createDb>>;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const createDb = async ({ zod, pkg }: Packages) => {
|
|
16
|
-
const Builder = pkg.Builder;
|
|
17
|
-
const Field = pkg.Field;
|
|
18
|
-
const z = zod;
|
|
19
|
-
const builder = new Builder("testdb", ["classes", "spellLists", "spells"]);
|
|
20
|
-
|
|
21
|
-
const classStore = builder.defineModel("classes", {
|
|
22
|
-
id: Field.primaryKey().autoIncrement(),
|
|
23
|
-
name: Field.string(),
|
|
24
|
-
description: Field.string().array(),
|
|
25
|
-
spellList: Field.relation("spellLists", {
|
|
26
|
-
name: "spellList2class",
|
|
27
|
-
}).optional({ onDelete: "SetNull" }),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const spellListStore = builder.defineModel("spellLists", {
|
|
31
|
-
id: Field.primaryKey().autoIncrement(),
|
|
32
|
-
name: Field.string(),
|
|
33
|
-
class: Field.relation("classes", {
|
|
34
|
-
name: "spellList2class",
|
|
35
|
-
onDelete: "Cascade",
|
|
36
|
-
}).optional(),
|
|
37
|
-
spells: Field.relation("spells", {
|
|
38
|
-
name: "spells2spellLists",
|
|
39
|
-
}).array(),
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const spellStore = builder.defineModel("spells", {
|
|
43
|
-
id: Field.primaryKey().autoIncrement(),
|
|
44
|
-
name: Field.string(),
|
|
45
|
-
range: Field.string(),
|
|
46
|
-
components: Field.custom(z.enum(["V", "S", "M"]).array()),
|
|
47
|
-
level: Field.number().default(0),
|
|
48
|
-
lists: Field.relation("spellLists", {
|
|
49
|
-
name: "spells2spellLists",
|
|
50
|
-
}).array(),
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const db = builder.compile({
|
|
54
|
-
classes: classStore,
|
|
55
|
-
spellLists: spellListStore,
|
|
56
|
-
spells: spellStore,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const client = await db.createClient();
|
|
60
|
-
return client;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
test.describe.configure({ mode: "default" });
|
|
64
|
-
test.describe("1 page multi-test", () => {
|
|
65
|
-
let page: Page;
|
|
66
|
-
let session: ContextSession<SessionArguments>;
|
|
67
|
-
test.beforeAll(async ({ browser }) => {
|
|
68
|
-
const context = await browser.newContext();
|
|
69
|
-
page = await context.newPage();
|
|
70
|
-
session = await populatePage<SessionArguments>(page, {
|
|
71
|
-
pkg: "import('./index.js')",
|
|
72
|
-
zod: 'import("https://cdn.jsdelivr.net/npm/zod@4.1.12/+esm")',
|
|
73
|
-
client: createDb as any,
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test.afterAll(async ({ browser }) => {
|
|
78
|
-
await browser.close();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("Sample DB", async () => {
|
|
82
|
-
const result = await session.evaluate(async ({ client }) => {
|
|
83
|
-
const stores = client.stores;
|
|
84
|
-
await stores.spells.add({
|
|
85
|
-
name: "Acid Splash",
|
|
86
|
-
level: 0,
|
|
87
|
-
components: ["V"],
|
|
88
|
-
range: "15 feet",
|
|
89
|
-
});
|
|
90
|
-
await stores.spells.add({
|
|
91
|
-
name: "Chromatic Orb",
|
|
92
|
-
level: 1,
|
|
93
|
-
components: ["V", "S"],
|
|
94
|
-
range: "120 feet",
|
|
95
|
-
});
|
|
96
|
-
return await stores.spells.find({ where: { level: 0 } });
|
|
97
|
-
});
|
|
98
|
-
expect(result).toBeInstanceOf(Array);
|
|
99
|
-
expect(result.length === 1).toBeTruthy();
|
|
100
|
-
});
|
|
101
|
-
});
|