@idb-orm/core 1.0.3

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.
@@ -0,0 +1,3 @@
1
+ import Model from "./model.js";
2
+ export * from "./model-types.js";
3
+ export { Model };
@@ -0,0 +1,125 @@
1
+ import { CompiledDb } from "../builder.js";
2
+ import {
3
+ BaseRelation,
4
+ Field,
5
+ OptionalRelation,
6
+ PrimaryKey,
7
+ Relation,
8
+ RelationArray,
9
+ RelationOutput,
10
+ ValidValue,
11
+ } from "../field/index.js";
12
+ import { Dict, Keyof, ZodWrap } from "../types/common.js";
13
+ import Model from "./model.js";
14
+ export type FindPrimaryKey<F extends Record<string, ValidValue>> = Extract<
15
+ {
16
+ [K in keyof F]: F[K] extends PrimaryKey<any, any> ? K : never;
17
+ }[keyof F],
18
+ string
19
+ >;
20
+ export type PrimaryKeyType<M extends Model<any, any, any>> = M extends Model<
21
+ any,
22
+ infer F,
23
+ any
24
+ >
25
+ ? {
26
+ [K in keyof F]: F[K] extends PrimaryKey<any, infer Type>
27
+ ? Type
28
+ : never;
29
+ }[keyof F]
30
+ : never;
31
+ export interface ModelCache {
32
+ delete?: Set<string>;
33
+ }
34
+ /**
35
+ * Gets the type of a relation given its name
36
+ */
37
+ export type RelationValue<Name extends string, C> = Name extends keyof C
38
+ ? C[Name] extends Model<any, infer Fields, infer PrimaryKey>
39
+ ? RelationOutput<Fields[PrimaryKey]>
40
+ : never
41
+ : never;
42
+ /**
43
+ * Gets the primitive type of the relation field
44
+ */
45
+ export type GetRelationField<F, C> = F extends Relation<infer To, any>
46
+ ? RelationValue<To, C>
47
+ : F extends OptionalRelation<infer To, any>
48
+ ? RelationValue<To, C> | undefined
49
+ : F extends RelationArray<infer To, any>
50
+ ? RelationValue<To, C>[]
51
+ : never;
52
+ export type ModelStructure<F extends Dict<ValidValue>, C> = {
53
+ [K in keyof F]: F[K] extends Field<infer Output, any>
54
+ ? Output
55
+ : F[K] extends PrimaryKey<any, infer Type>
56
+ ? Type
57
+ : GetRelationField<F[K], C>;
58
+ };
59
+ export type ModelType<
60
+ M extends Model<any, any, any>,
61
+ C extends CompiledDb<any, any, any>
62
+ > = M extends Model<any, infer Fields, any>
63
+ ? C extends CompiledDb<any, any, infer Collection>
64
+ ? ModelStructure<Fields, Collection>
65
+ : never
66
+ : never;
67
+ export type ExtractFields<M extends Model<any, any, any>> = M extends Model<
68
+ any,
69
+ infer Fields,
70
+ any
71
+ >
72
+ ? Fields
73
+ : never;
74
+ export type AllRelationKeys<M extends Model<any, any, any>> = M extends Model<
75
+ any,
76
+ infer Fields,
77
+ any
78
+ >
79
+ ? {
80
+ [K in Keyof<Fields>]: Fields[K] extends BaseRelation<any, any>
81
+ ? K
82
+ : never;
83
+ }[Keyof<Fields>]
84
+ : never;
85
+ export type RelationlessModelStructure<M extends Model<any, any, any>> =
86
+ M extends Model<any, infer Fields, any>
87
+ ? Omit<
88
+ {
89
+ [K in Keyof<Fields>]: Fields[K] extends BaseRelation<any, any>
90
+ ? unknown
91
+ : Fields[K] extends Field<infer Type, any>
92
+ ? Type
93
+ : Fields[K] extends PrimaryKey<any, infer Type>
94
+ ? Type
95
+ : never;
96
+ },
97
+ AllRelationKeys<M>
98
+ >
99
+ : never;
100
+ export type CollectionZodSchema<C> = C extends Record<
101
+ infer Keys,
102
+ Model<any, any, any>
103
+ >
104
+ ? {
105
+ [K in Keys]: C[K] extends Model<any, infer Fields, any>
106
+ ? ZodWrap<ModelStructure<Fields, C>>
107
+ : never;
108
+ }
109
+ : never;
110
+ export type FindRelationKey<
111
+ From extends string,
112
+ RelationName extends string,
113
+ M extends Model<any, any, any>
114
+ > = M extends Model<any, infer Fields, any>
115
+ ? {
116
+ [K in Keyof<Fields>]: Fields[K] extends BaseRelation<
117
+ From,
118
+ infer CurName
119
+ >
120
+ ? CurName extends RelationName
121
+ ? K
122
+ : never
123
+ : never;
124
+ }[Keyof<Fields>]
125
+ : never;
@@ -0,0 +1,42 @@
1
+ import z from "zod";
2
+ import { CollectionObject } from "../builder.js";
3
+ import { DbClient } from "../client/index.js";
4
+ import {
5
+ BaseRelation,
6
+ Field,
7
+ FieldTypes,
8
+ PrimaryKey,
9
+ ValidValue,
10
+ } from "../field/index.js";
11
+ import { Keyof, ValidKey } from "../types/common.js";
12
+ import { FindPrimaryKey } from "./model-types.js";
13
+ export default class Model<
14
+ Name extends string,
15
+ F extends Record<string, ValidValue>,
16
+ Primary extends FindPrimaryKey<F> = FindPrimaryKey<F>
17
+ > {
18
+ readonly name: Name;
19
+ private readonly fields;
20
+ private readonly fieldKeys;
21
+ private readonly relationLinks;
22
+ private cache;
23
+ readonly primaryKey: Primary;
24
+ constructor(name: Name, fields: F);
25
+ get<K extends Keyof<F>>(key: K): F[K];
26
+ getModelField(key: string): Field<any, any> | undefined;
27
+ getPrimaryKey(): PrimaryKey<boolean, ValidKey>;
28
+ getRelation<Models extends string>(
29
+ key: string
30
+ ): BaseRelation<Models, string> | undefined;
31
+ keyType(key: Keyof<F>): FieldTypes;
32
+ links<Names extends string = string>(): SetIterator<Names>;
33
+ keys(): Keyof<F>[];
34
+ parseField<K extends Keyof<F>>(
35
+ field: K,
36
+ value: unknown
37
+ ): z.ZodSafeParseResult<any>;
38
+ getDeletedStores<
39
+ ModelNames extends string,
40
+ Models extends CollectionObject<ModelNames>
41
+ >(client: DbClient<string, ModelNames, Models>): Set<ModelNames>;
42
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * A paper thin wrapper around IDBObjectStore
3
+ */
4
+ import { Promisable } from "type-fest";
5
+ import { StoreError } from "./error.js";
6
+ import { Transaction } from "./transaction.js";
7
+ import { Dict, ValidKey } from "./types/common.js";
8
+ export declare class ObjectStore {
9
+ private readonly tx;
10
+ readonly store: IDBObjectStore;
11
+ constructor(tx: Transaction<IDBTransactionMode, string>, store: IDBObjectStore);
12
+ add(item: Dict): Promise<ValidKey>;
13
+ /**
14
+ * Attempts to retrieve the value from the object store.
15
+ *
16
+ * Returns `undefined` if no value was found
17
+ */
18
+ get(key: ValidKey): Promise<Dict>;
19
+ put(item: Dict): Promise<ValidKey>;
20
+ delete(key: ValidKey): Promise<undefined>;
21
+ openCursor(callback: (cursor: IDBCursorWithValue, tx: Transaction<IDBTransactionMode, string>) => Promisable<boolean>, options?: {
22
+ query?: IDBValidKey | IDBKeyRange;
23
+ direction?: IDBCursorDirection;
24
+ onError?: () => StoreError;
25
+ }): Promise<void>;
26
+ private handleRequest;
27
+ }
@@ -0,0 +1,50 @@
1
+ import type { Arrayable } from "type-fest";
2
+ import { StoreError } from "./error.js";
3
+ import { ObjectStore } from "./object-store.js";
4
+ export type TransactionStatus = "running" | "aborted" | "complete" | "error";
5
+ export type TransactionEventHandler = (
6
+ tx: Transaction<IDBTransactionMode>,
7
+ ev: Event
8
+ ) => void;
9
+ export interface TransactionOptions
10
+ extends Partial<{
11
+ onAbort: TransactionEventHandler;
12
+ onError: TransactionEventHandler;
13
+ onComplete: TransactionEventHandler;
14
+ }> {}
15
+ export declare class Transaction<
16
+ Mode extends IDBTransactionMode,
17
+ Stores extends string = string
18
+ > {
19
+ private internal;
20
+ status: TransactionStatus;
21
+ error: StoreError | null;
22
+ readonly storeNames: Stores[];
23
+ /**
24
+ * A record of store names to `IDBObjectStore` objects
25
+ */
26
+ private readonly objectStores;
27
+ constructor(
28
+ db: IDBDatabase,
29
+ stores: Arrayable<Stores>,
30
+ mode: Mode,
31
+ options?: TransactionOptions
32
+ );
33
+ abort(error: StoreError): StoreError;
34
+ commit(): void;
35
+ /**
36
+ * Gets the internal `IDBTransaction` object
37
+ *
38
+ * It's recommended you don't use this function and use the built-in functions of the wrapper
39
+ * @returns Internal transaction object
40
+ */
41
+ getInternal(): IDBTransaction;
42
+ getStore(store: Stores): ObjectStore;
43
+ get mode(): Mode;
44
+ is(status: TransactionStatus): boolean;
45
+ contains(stores: Arrayable<string>): boolean;
46
+ assertIsArray(value: any, message?: string): asserts value is any[];
47
+ private getObjectstore;
48
+ private registerHandler;
49
+ wrap<Output>(fn: (tx: this) => Promise<Output>): Promise<Output>;
50
+ }
@@ -0,0 +1,37 @@
1
+ import type { Arrayable, IsNever } from "type-fest";
2
+ import type z from "zod";
3
+ /**
4
+ * Extracts the string keys of an object
5
+ */
6
+ export type Keyof<T extends Record<any, any>> = Extract<keyof T, string>;
7
+ export type MakeOptional<B extends boolean, T> = B extends true ? T | undefined : T;
8
+ export type MakeArray<B extends boolean, T> = B extends true ? T[] : T;
9
+ export type MakeArrayable<B extends boolean, T> = B extends true ? Arrayable<T> : T;
10
+ export type ValidKey = string | number | Date;
11
+ export type ValidKeyType = "string" | "number" | "date";
12
+ export type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
13
+ export type RemoveNeverValues<T extends object> = {
14
+ [K in keyof T as T[K] extends never ? never : K]: T[K];
15
+ };
16
+ export type Dict<T = unknown> = Record<string, T>;
17
+ export type ConnectionObject<M extends boolean = false, T = object, K = ValidKey> = {
18
+ $create: T;
19
+ $connect: K;
20
+ } & If<M, {
21
+ $createMany: T[];
22
+ $connectMany: K[];
23
+ }, Dict>;
24
+ export type ZodWrap<T extends Dict> = {
25
+ [K in keyof T]: z.ZodType<T[K]>;
26
+ };
27
+ type UndefinedKeys<T extends Dict> = {
28
+ [K in Keyof<T>]: undefined extends T[K] ? K : never;
29
+ }[Keyof<T>];
30
+ type Optional<T extends Dict> = Partial<Pick<T, UndefinedKeys<T>>>;
31
+ type Required<T extends Dict> = Omit<T, UndefinedKeys<T>>;
32
+ export type PartialOnUndefined<T extends Dict> = Required<T> & Optional<T>;
33
+ /**
34
+ * Types that can be resolved to specific boolean values
35
+ */
36
+ export type BooleanLike = boolean | undefined | null | 0;
37
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { Keyof } from "./types/common";
2
+ import type { Arrayable } from "type-fest";
3
+ import type { Transaction } from "./transaction.js";
4
+ export declare function handleRequest<T>(req: IDBRequest<T>, tx?: Transaction<any, any>): Promise<T>;
5
+ export declare function getKeys<T extends object>(obj: T): Keyof<T>[];
6
+ export declare function addToSet<T>(set: Set<T>, items: T[]): Set<T>;
7
+ export declare function toArray<T>(value: Arrayable<T>): T[];
8
+ /**
9
+ * Identity Function, it returns the first argument it is given, all others are ignored
10
+ * @param value Value
11
+ * @returns Same Value
12
+ */
13
+ export declare function identity<T>(value: T): T;
14
+ /**
15
+ * Performs a union over `set1` and `set2`, modifying `set1` to be union of the two sets
16
+ */
17
+ export declare function unionSets<T>(set: Set<T>, other: Set<T>): Set<T>;
@@ -0,0 +1,55 @@
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/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@idb-orm/core",
3
+ "version": "1.0.3",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "build": "rollup --config rollup.config.ts --configPlugin typescript",
9
+ "watch": "rollup --watch --config rollup.config.ts --configPlugin typescript",
10
+ "check": "eslint . && tsc -b --noEmit",
11
+ "test": "playwright test"
12
+ },
13
+ "keywords": [],
14
+ "workspaces": [
15
+ "packages/*"
16
+ ],
17
+ "author": "jtb",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js",
22
+ "require": "./dist/index.js"
23
+ }
24
+ },
25
+ "license": "ISC",
26
+ "devDependencies": {
27
+ "@eslint/js": "^9.38.0",
28
+ "@playwright/test": "^1.56.1",
29
+ "@rollup/plugin-node-resolve": "^16.0.3",
30
+ "@rollup/plugin-terser": "^0.4.4",
31
+ "@rollup/plugin-typescript": "^12.1.4",
32
+ "@types/node": "^24.9.1",
33
+ "eslint": "^9.38.0",
34
+ "rollup": "^4.52.4",
35
+ "serve": "^14.2.5",
36
+ "tslib": "^2.8.1",
37
+ "typescript": "^5.9.3",
38
+ "typescript-eslint": "^8.46.2"
39
+ },
40
+ "dependencies": {
41
+ "@gilbarbara/deep-equal": "^0.3.1",
42
+ "uuid": "^13.0.0",
43
+ "zod": "^4.1.3"
44
+ }
45
+ }
@@ -0,0 +1,79 @@
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
+ });
@@ -0,0 +1,72 @@
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
+ }
@@ -0,0 +1,101 @@
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
+ });