@idb-orm/core 1.0.7 → 1.0.8
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/README.md +17 -20
- package/package.json +12 -13
- package/dist/builder.d.ts +0 -25
- package/dist/client/compiled-query.d.ts +0 -13
- package/dist/client/delete.d.ts +0 -14
- package/dist/client/helpers.d.ts +0 -10
- package/dist/client/index.d.ts +0 -33
- package/dist/client/types/find.d.ts +0 -27
- package/dist/client/types/index.d.ts +0 -62
- package/dist/client/types/mutation.d.ts +0 -46
- package/dist/dev-types.d.ts +0 -4
- package/dist/dev.d.ts +0 -5
- package/dist/error.d.ts +0 -194
- package/dist/field/constants.d.ts +0 -9
- package/dist/field/field-types.d.ts +0 -36
- package/dist/field/field.d.ts +0 -40
- package/dist/field/index.d.ts +0 -5
- package/dist/field/primary-key.d.ts +0 -20
- package/dist/field/property.d.ts +0 -69
- package/dist/field/relation.d.ts +0 -77
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -1
- package/dist/model/index.d.ts +0 -3
- package/dist/model/model-types.d.ts +0 -38
- package/dist/model/model.d.ts +0 -23
- package/dist/object-store.d.ts +0 -26
- package/dist/transaction.d.ts +0 -39
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/common.d.ts +0 -48
- package/dist/types.d.ts +0 -48
- package/dist/util-types.d.ts +0 -37
- package/dist/utils.d.ts +0 -29
package/README.md
CHANGED
|
@@ -9,34 +9,31 @@
|
|
|
9
9
|
- [x] "Include" query field
|
|
10
10
|
- [x] Enforce that either "include" xor "select" is in the query object
|
|
11
11
|
- [x] modify the query object so that on relations it is recursive
|
|
12
|
-
- [
|
|
13
|
-
|
|
14
|
-
- [
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
12
|
+
- [x] Make sure non-optional and non-array relations do not have the `SetNull` onDelete action on model compilation
|
|
13
|
+
- [x] Complete update action
|
|
14
|
+
- [x] Redo Mutation type. It should provide structurally no change:
|
|
15
|
+
- [x] Split `add` and `update` mutation until completely separate interfaces?
|
|
16
|
+
- [x] -Many or -All are only present on `ArrayRelation`'s,
|
|
17
|
+
- [x] Cannot use `delete` or `disconnect` on non-nullable (1-1) relations
|
|
18
|
+
- [x] Add additional functions to the storeInterface
|
|
19
|
+
- [x] get([primaryKey], [include/select])
|
|
20
|
+
- [x] update([primaryKey], [updateMutation without where])
|
|
21
|
+
- [x] Error Handling: Instead of needing to type `tx.abort(...)` just use the `throw new ...` syntax and catch the error and automatically abort the transaction. This will require actions to be wrapped in some kind of try-catch block.
|
|
17
22
|
- [ ] Dump database to different formats:
|
|
18
23
|
- [ ] JSON
|
|
19
24
|
- [ ] CSV
|
|
20
|
-
|
|
21
|
-
- [ ] Add extra object syntax to "where"
|
|
22
|
-
- [ ]
|
|
23
|
-
|
|
24
|
-
- [ ] deleteMany
|
|
25
|
-
- [ ] findMany
|
|
26
|
-
- [ ] updateMany
|
|
27
|
-
- [ ] Convert internal string unions to enums
|
|
28
|
-
- [x] Remove external dependencies
|
|
29
|
-
- [x] deep-equal
|
|
30
|
-
- [x] type-fest
|
|
31
|
-
- [x] uuid
|
|
32
|
-
- [x] zod
|
|
25
|
+
- [ ] Make package to wrap Tanstack query for react application
|
|
26
|
+
- [ ] Add extra object syntax to "where" clause (i.e. `in`/`ne`/`gt`/...)
|
|
27
|
+
- [ ] Allow object types in where clauses
|
|
28
|
+
- [x] Convert internal string unions to enums
|
|
33
29
|
- [ ] Make subpackages for adapters for different validation languages
|
|
34
|
-
- [
|
|
30
|
+
- [x] Zod
|
|
35
31
|
- [ ] Yup
|
|
36
32
|
- [ ] Joi
|
|
37
33
|
- [ ] schema.js
|
|
34
|
+
- [ ] Migrate to vite instead of rollup
|
|
38
35
|
|
|
39
36
|
### Roadmap - Maybe
|
|
40
37
|
|
|
38
|
+
- [ ] Optimize batch `add` editing with cursor functionality
|
|
41
39
|
- [ ] Discriminated union models: Be able to differentiate subtypes of a model by a discriminator key
|
|
42
|
-
- [ ] Error Handling: Instead of needing to type `tx.abort(...)` just use the `throw new ...` syntax and catch the error and automatically abort the transaction. This will require actions to be wrapped in some kind of try-catch block.
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idb-orm/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "dist/index.js",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "
|
|
10
|
-
"watch": "
|
|
9
|
+
"build": "vite build",
|
|
10
|
+
"watch": "vite build --watch",
|
|
11
11
|
"check": "eslint . && tsc -b --noEmit",
|
|
12
|
-
"
|
|
12
|
+
"b": "vite build"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"typescript",
|
|
@@ -19,18 +19,14 @@
|
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
|
-
"import": "./dist/index.js",
|
|
23
|
-
"require": "./dist/index.js"
|
|
24
|
-
},
|
|
25
|
-
"./dev": {
|
|
26
|
-
"types": "./dist/dev.d.ts",
|
|
27
|
-
"default": "./dist/dev.d.ts"
|
|
22
|
+
"import": "./dist/index.es.js",
|
|
23
|
+
"require": "./dist/index.cjs.js"
|
|
28
24
|
}
|
|
29
25
|
},
|
|
30
26
|
"license": "ISC",
|
|
31
27
|
"devDependencies": {
|
|
32
28
|
"@eslint/js": "^9.38.0",
|
|
33
|
-
"@
|
|
29
|
+
"@rolldown/binding-win32-x64-msvc": "^1.0.0-beta.51",
|
|
34
30
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
35
31
|
"@rollup/plugin-terser": "^0.4.4",
|
|
36
32
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
@@ -38,8 +34,11 @@
|
|
|
38
34
|
"eslint": "^9.38.0",
|
|
39
35
|
"rollup": "^4.52.4",
|
|
40
36
|
"serve": "^14.2.5",
|
|
37
|
+
"terser": "^5.44.1",
|
|
41
38
|
"tslib": "^2.8.1",
|
|
42
39
|
"typescript": "^5.9.3",
|
|
43
|
-
"typescript-eslint": "^8.46.2"
|
|
40
|
+
"typescript-eslint": "^8.46.2",
|
|
41
|
+
"vite": "^7.2.4",
|
|
42
|
+
"vite-plugin-dts": "^4.5.4"
|
|
44
43
|
}
|
|
45
44
|
}
|
package/dist/builder.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { CollectionSchema, Model } from "./model";
|
|
2
|
-
import { DbClient } from "./client";
|
|
3
|
-
import { PrimaryKey, type ValidValue } from "./field";
|
|
4
|
-
import type { Dict } from "./util-types";
|
|
5
|
-
export type CollectionObject<Names extends string> = {
|
|
6
|
-
[K in Names]: Model<K, any>;
|
|
7
|
-
};
|
|
8
|
-
export declare class Builder<Name extends string, Names extends string> {
|
|
9
|
-
readonly name: Name;
|
|
10
|
-
readonly names: Names[];
|
|
11
|
-
private models;
|
|
12
|
-
constructor(name: Name, names: Names[]);
|
|
13
|
-
defineModel<N extends Names, T extends Dict<ValidValue<Names>>>(name: N, values: T): Model<N, T, Extract<{ [K in keyof T]: T[K] extends PrimaryKey<any, any> ? K : never; }[keyof T], string>>;
|
|
14
|
-
compile<M extends CollectionObject<Names>>(models: M): CompiledDb<Name, Names, M>;
|
|
15
|
-
}
|
|
16
|
-
export declare class CompiledDb<Name extends string, Names extends string, C extends CollectionObject<Names>> {
|
|
17
|
-
readonly name: Name;
|
|
18
|
-
private readonly models;
|
|
19
|
-
readonly schemas: CollectionSchema<C>;
|
|
20
|
-
private readonly modelKeys;
|
|
21
|
-
constructor(name: Name, models: C);
|
|
22
|
-
getModel<N extends Names>(name: N): C[N];
|
|
23
|
-
createClient(version?: number): Promise<DbClient<Name, Names, C>>;
|
|
24
|
-
keys(): Names[];
|
|
25
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { CollectionObject } from "../builder.ts";
|
|
2
|
-
import type { DbClient } from "./index.ts";
|
|
3
|
-
import type { FindInput, FindOutput } from "./types/find.ts";
|
|
4
|
-
export declare class CompiledQuery<Stores extends string, Models extends CollectionObject<string>, Db extends DbClient<string, Stores, Models>, Input extends FindInput<Stores, Models[Stores], Models> = FindInput<Stores, Models[Stores], Models>, Output = FindOutput<Stores, Models[Stores], Models, Input>> {
|
|
5
|
-
private readonly client;
|
|
6
|
-
private readonly name;
|
|
7
|
-
private readonly accessedStores;
|
|
8
|
-
private readonly selectClause;
|
|
9
|
-
constructor(client: Db, name: Stores, input: Input);
|
|
10
|
-
find(): Promise<Output[]>;
|
|
11
|
-
findFirst(): Promise<Output>;
|
|
12
|
-
private _find;
|
|
13
|
-
}
|
package/dist/client/delete.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { CollectionObject } from "../builder.js";
|
|
2
|
-
import { ExtractFields } from "../model/model-types.js";
|
|
3
|
-
import { WhereObject } from "./types/find.js";
|
|
4
|
-
import { MutationState } from "./types";
|
|
5
|
-
import { DbClient } from "./index.js";
|
|
6
|
-
/**
|
|
7
|
-
* Deletes document(s) from a store
|
|
8
|
-
* @param name Name of the store
|
|
9
|
-
* @param client DbClient object
|
|
10
|
-
* @param stopOnFirst Stop after the first deletion
|
|
11
|
-
* @param _state Optional state for multi-stage actions
|
|
12
|
-
* @returns Number of items removed
|
|
13
|
-
*/
|
|
14
|
-
export declare function deleteItems<ModelNames extends string, Name extends ModelNames, Models extends CollectionObject<ModelNames>>(name: Name, client: DbClient<string, ModelNames, Models>, where?: WhereObject<ExtractFields<Models[Name]>>, stopOnFirst?: boolean, _state?: MutationState<ModelNames>): Promise<number>;
|
package/dist/client/helpers.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Dict, Promisable } from "../util-types.js";
|
|
2
|
-
import type { DbClient } from "./index.ts";
|
|
3
|
-
import type { CollectionObject } from "../builder.ts";
|
|
4
|
-
import type { QueryInput } from "./types/find.ts";
|
|
5
|
-
import type { Transaction } from "../transaction.js";
|
|
6
|
-
export declare function generateWhereClause(where?: Dict): (obj: unknown) => boolean;
|
|
7
|
-
export declare function generateSelector<ModelNames extends string, Models extends CollectionObject<ModelNames>, Db extends DbClient<string, ModelNames, Models>, Q extends QueryInput<ModelNames, any, Models> = QueryInput<ModelNames, any, Models>>(name: ModelNames, client: Db, query?: Q, initTx?: Transaction<IDBTransactionMode, ModelNames>): (item: Dict, tx: Transaction<IDBTransactionMode, ModelNames>) => Promisable<Dict | undefined>;
|
|
8
|
-
export declare function getAccessedStores<ModelNames extends string, Models extends CollectionObject<ModelNames>>(name: ModelNames, query: Dict, type: "mutation" | "query", client: DbClient<string, ModelNames, Models>): Set<ModelNames>;
|
|
9
|
-
export declare function getSearchableQuery(q: QueryInput<any, any, any>): import("./types/find.ts").SelectObject<any, any, any>;
|
|
10
|
-
export declare function promiseCatch(tx: Transaction<IDBTransactionMode, string>): (error: any) => never;
|
package/dist/client/index.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { CollectionObject, CompiledDb } from "../builder";
|
|
2
|
-
import type { Arrayable } from "../util-types";
|
|
3
|
-
import { Transaction, type TransactionOptions } from "../transaction";
|
|
4
|
-
import { type InterfaceMap } from "./types";
|
|
5
|
-
export declare class DbClient<Name extends string, ModelNames extends string, Models extends CollectionObject<ModelNames>> {
|
|
6
|
-
private readonly db;
|
|
7
|
-
private readonly models;
|
|
8
|
-
readonly name: Name;
|
|
9
|
-
readonly version: number;
|
|
10
|
-
readonly stores: InterfaceMap<ModelNames, Models>;
|
|
11
|
-
constructor(db: IDBDatabase, models: CompiledDb<Name, ModelNames, Models>);
|
|
12
|
-
getStore<Name extends ModelNames>(name: Name): (typeof this.stores)[Name];
|
|
13
|
-
createTransaction<Mode extends IDBTransactionMode, Names extends ModelNames>(mode: Mode, stores: Arrayable<Names>, options?: TransactionOptions): Transaction<Mode, Names>;
|
|
14
|
-
deleteDb(): Promise<void>;
|
|
15
|
-
deleteAllStores(): void;
|
|
16
|
-
deleteStore(storeNames: Arrayable<ModelNames>): void;
|
|
17
|
-
getModel<N extends ModelNames>(name: N): Models[N];
|
|
18
|
-
private getAccessedStores;
|
|
19
|
-
private createInterface;
|
|
20
|
-
private add;
|
|
21
|
-
private clear;
|
|
22
|
-
/**
|
|
23
|
-
* Finds documents from the store that match the filter
|
|
24
|
-
* @param name Name of the store
|
|
25
|
-
* @param item Object containing the filter and the selection query
|
|
26
|
-
* @param stopOnFirst Flag to stop after one successful find
|
|
27
|
-
* @param _state Optional state for mutli-stage actions
|
|
28
|
-
* @returns Transformed selection item
|
|
29
|
-
*/
|
|
30
|
-
private find;
|
|
31
|
-
private update;
|
|
32
|
-
private updateSingleton;
|
|
33
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Dict, If, Keyof, RemoveNeverValues } from "../../util-types.js";
|
|
2
|
-
import type { ExtractFields, ModelStructure, RelationlessModelStructure } from "../../model/model-types.js";
|
|
3
|
-
import type { Model } from "../../model";
|
|
4
|
-
import type { BaseRelation, AbstractProperty, PrimaryKey, RelationOutputStructure, ValidValue } from "../../field";
|
|
5
|
-
import type { CollectionObject } from "../../builder.ts";
|
|
6
|
-
export type FilterFn<Input> = (item: Input) => boolean;
|
|
7
|
-
/**
|
|
8
|
-
* If an property is an object type (dictionary, array, map, set, etc...) return never. If it's a union it strips out any object types
|
|
9
|
-
*/
|
|
10
|
-
export type ProhibitObjects<T> = T extends object ? never : T;
|
|
11
|
-
export type WhereObject<Fields extends Dict<ValidValue>> = Partial<RemoveNeverValues<{
|
|
12
|
-
[K in keyof Fields]: Fields[K] extends AbstractProperty<infer Output, any> ? Output | FilterFn<Output> : Fields[K] extends PrimaryKey<any, infer Type> ? ProhibitObjects<Type> | FilterFn<Type> : never;
|
|
13
|
-
}>>;
|
|
14
|
-
export type SelectObject<All extends string, Fields extends Dict<ValidValue>, C extends CollectionObject<All>> = {
|
|
15
|
-
[K in keyof Fields]?: Fields[K] extends AbstractProperty<any, any> ? true : Fields[K] extends PrimaryKey<any, any> ? true : Fields[K] extends BaseRelation<infer To, any> ? true | (To extends Keyof<C> ? C[To] extends Model<any, infer SubFields, any> ? QueryInput<All, SubFields, C> : never : never) : never;
|
|
16
|
-
};
|
|
17
|
-
export interface QueryInput<All extends string, Fields extends Dict<ValidValue>, C extends CollectionObject<All>> {
|
|
18
|
-
where?: WhereObject<Fields>;
|
|
19
|
-
select?: SelectObject<All, Fields, C>;
|
|
20
|
-
include?: SelectObject<All, Fields, C>;
|
|
21
|
-
}
|
|
22
|
-
export type FindInput<All extends string, Struct extends object, C extends CollectionObject<All>> = Struct extends Model<any, infer Fields, any> ? QueryInput<All, Fields, C> : never;
|
|
23
|
-
type _FindOutput<All extends string, Select extends Dict<Dict | true>, Fields extends Dict<ValidValue>, C extends CollectionObject<All>> = {
|
|
24
|
-
[K in Keyof<Select>]: Fields[K] extends BaseRelation<infer To, any> ? To extends Keyof<C> ? C[To] extends Model<any, infer Sub, any> ? If<Select[K] extends true ? true : false, RelationOutputStructure<Fields[K], RelationlessModelStructure<C[To]>>, Select[K] extends Dict<Dict | true> ? RelationOutputStructure<Fields[K], _FindOutput<All, Select[K], Sub, C>> : never> : never : never : Fields[K] extends PrimaryKey<any, infer Type> ? Type : Fields[K] extends AbstractProperty<infer Type, any> ? Type : never;
|
|
25
|
-
} | undefined;
|
|
26
|
-
export type FindOutput<All extends string, Struct extends Model<any, any, any>, C extends CollectionObject<All>, F extends FindInput<All, Struct, C>> = Struct extends Model<any, infer Fields, any> ? F extends object ? (F["select"] extends Dict<true | Dict> ? _FindOutput<All, F["select"], Fields, C> : ModelStructure<ExtractFields<Struct>, C>) | undefined : never : never;
|
|
27
|
-
export {};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { CollectionObject } from "../../builder.ts";
|
|
2
|
-
import type { Dict, ValidKey } from "../../util-types.js";
|
|
3
|
-
import type { ExtractFields, Model, ModelStructure, PrimaryKeyType } from "../../model";
|
|
4
|
-
import type { AddMutation, UpdateMutation } from "./mutation.ts";
|
|
5
|
-
import type { FindInput, FindOutput, WhereObject } from "./find.ts";
|
|
6
|
-
import type { CompiledQuery } from "../compiled-query.ts";
|
|
7
|
-
import type { DbClient } from "../index.ts";
|
|
8
|
-
import { Transaction } from "../../transaction.js";
|
|
9
|
-
import { BaseRelation } from "../../field";
|
|
10
|
-
export type InsertMutation<N extends string, C extends Dict> = C[N] extends Model<N, infer F, any> ? ModelStructure<F, C> : never;
|
|
11
|
-
export interface StoreInterface<Name extends Names, Names extends string, C extends CollectionObject<Names>, KeyType = PrimaryKeyType<C[Name]>, Add = AddMutation<Name, Names, C[Name], C>, Update = UpdateMutation<Name, Names, C[Name], C>> {
|
|
12
|
-
add(mutation: Add, transaction?: Transaction<"readwrite", Names>): Promise<KeyType>;
|
|
13
|
-
addMany(mutations: Add[], transaction?: Transaction<"readwrite", Names>): Promise<KeyType[]>;
|
|
14
|
-
find<T extends FindInput<Names, C[Name], C>>(query: T, transaction?: Transaction<IDBTransactionMode, Names>): Promise<FindOutput<Names, C[Name], C, T>[]>;
|
|
15
|
-
findFirst<T extends FindInput<Names, C[Name], C>>(query: T, transaction?: Transaction<IDBTransactionMode, Names>): Promise<FindOutput<Names, C[Name], C, T>>;
|
|
16
|
-
put(): Promise<void>;
|
|
17
|
-
insert(item: InsertMutation<Name, C>, transaction?: Transaction<"readwrite", Names>): Promise<KeyType>;
|
|
18
|
-
updateFirst(item: Update, transaction?: Transaction<"readwrite", Names>): Promise<KeyType | undefined>;
|
|
19
|
-
updateMany(item: Update, transaction?: Transaction<"readwrite", Names>): Promise<KeyType[]>;
|
|
20
|
-
delete(key: KeyType): Promise<boolean>;
|
|
21
|
-
deleteFirst(where?: WhereObject<ExtractFields<C[Name]>>): Promise<boolean>;
|
|
22
|
-
deleteMany(where: WhereObject<ExtractFields<C[Name]>>): Promise<number>;
|
|
23
|
-
/**
|
|
24
|
-
* Clears a store (does not update any relations)
|
|
25
|
-
*/
|
|
26
|
-
clear(transaction?: Transaction<"readwrite", Names>): Promise<void>;
|
|
27
|
-
compileQuery<T extends FindInput<Names, C[Name], C>>(query: T): CompiledQuery<Names, C, DbClient<string, Names, C>, T>;
|
|
28
|
-
get(key: KeyType): Promise<any>;
|
|
29
|
-
}
|
|
30
|
-
export type InterfaceMap<Names extends string, C extends CollectionObject<Names>> = {
|
|
31
|
-
[K in Names]: StoreInterface<K, Names, C>;
|
|
32
|
-
};
|
|
33
|
-
export interface QueryState<Names extends string> {
|
|
34
|
-
tx?: Transaction<IDBTransactionMode, Names>;
|
|
35
|
-
}
|
|
36
|
-
export declare const enum MutationBreath {
|
|
37
|
-
Find = 0,
|
|
38
|
-
Singleton = 1
|
|
39
|
-
}
|
|
40
|
-
export interface MutationState<Names extends string> extends Partial<{
|
|
41
|
-
tx: Transaction<"readwrite", Names>;
|
|
42
|
-
relation: {
|
|
43
|
-
id: ValidKey;
|
|
44
|
-
key: string;
|
|
45
|
-
};
|
|
46
|
-
singleton: {
|
|
47
|
-
id: ValidKey;
|
|
48
|
-
};
|
|
49
|
-
finalStep: boolean;
|
|
50
|
-
}> {
|
|
51
|
-
}
|
|
52
|
-
export type KeyObject<Index = string> = {
|
|
53
|
-
isFun: boolean;
|
|
54
|
-
key: Index;
|
|
55
|
-
} & ({
|
|
56
|
-
isRelation: true;
|
|
57
|
-
relation: BaseRelation<any, any>;
|
|
58
|
-
} | {
|
|
59
|
-
isRelation: false;
|
|
60
|
-
relation?: undefined;
|
|
61
|
-
});
|
|
62
|
-
export type { AddMutation, UpdateMutation };
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { MakeArrayable, MakeOptional, RemoveNeverValues, PartialOnUndefined } from "../../util-types.js";
|
|
2
|
-
import type { BaseRelation, AbstractProperty, OptionalRelation, PrimaryKey, ArrayRelation } from "../../field";
|
|
3
|
-
import type { CollectionObject } from "../../builder.ts";
|
|
4
|
-
import { WhereObject } from "./find.js";
|
|
5
|
-
import { Model, FindRelationKey, RelationValue } from "../../model";
|
|
6
|
-
export type MutationActions = "$connect" | "$connectMany" | "$create" | "$createMany" | "$update" | "$updateMany" | "$delete" | "$deleteMany" | "$deleteAll" | "$disconnect" | "$disconnectMany" | "$disconnectAll";
|
|
7
|
-
export type Mutation<This extends All, All extends string, Struct extends object, C extends CollectionObject<All>, MutType extends string = "add"> = PartialOnUndefined<RemoveNeverValues<Struct extends Model<any, infer Fields, any> ? {
|
|
8
|
-
[K in keyof Fields]: Fields[K] extends AbstractProperty<infer Type, infer HasDefault> ? MutType extends "update" ? Type | undefined | ((value: Type) => Type) : HasDefault extends true ? Type | undefined : Type : Fields[K] extends PrimaryKey<infer IsAuto, infer Type> ? MutType extends "update" ? never : IsAuto extends true ? never : Type : Fields[K] extends BaseRelation<infer To, infer Name> ? To extends All ? MakeOptional<Fields[K] extends OptionalRelation<any, any> ? true : Fields[K] extends ArrayRelation<any, any> ? true : MutType extends "update" ? true : false, MakeArrayable<Fields[K] extends ArrayRelation<any, any> ? true : false, {
|
|
9
|
-
$connect: RelationValue<To, C>;
|
|
10
|
-
} | {
|
|
11
|
-
$create: Omit<Mutation<To, All, C[To], C, "add">, FindRelationKey<This, Name, C[To]>>;
|
|
12
|
-
} | (MutType extends "update" ? {
|
|
13
|
-
$update: Fields[K] extends ArrayRelation<any, any> ? {
|
|
14
|
-
where?: WhereSelection<C[To]>;
|
|
15
|
-
data: Mutation<To, All, C[To], C, MutType>;
|
|
16
|
-
} : Mutation<To, All, C[To], C, MutType>;
|
|
17
|
-
} | {
|
|
18
|
-
$delete: Fields[K] extends ArrayRelation<any, any> ? RelationValue<To, C> : true;
|
|
19
|
-
} | {
|
|
20
|
-
$disconnect: Fields[K] extends ArrayRelation<any, any> ? RelationValue<To, C> : true;
|
|
21
|
-
} : never)> | (Fields[K] extends ArrayRelation<any, any> ? {
|
|
22
|
-
$connectMany: RelationValue<To, C>[];
|
|
23
|
-
} | {
|
|
24
|
-
$createMany: Omit<Mutation<To, All, C[To], C, "add">, FindRelationKey<This, Name, C[To]>>[];
|
|
25
|
-
} | {
|
|
26
|
-
$updateMany: {
|
|
27
|
-
where?: WhereSelection<C[To]>;
|
|
28
|
-
data: Mutation<To, All, C[To], C, MutType>;
|
|
29
|
-
}[];
|
|
30
|
-
} | {
|
|
31
|
-
$deleteMany: RelationValue<To, C>[];
|
|
32
|
-
} | {
|
|
33
|
-
$deleteAll: true;
|
|
34
|
-
} | {
|
|
35
|
-
$disconnectMany: RelationValue<To, C>[];
|
|
36
|
-
} | {
|
|
37
|
-
$disconnectAll: true;
|
|
38
|
-
} : never)> : never : never;
|
|
39
|
-
} : never>>;
|
|
40
|
-
export type AddMutation<This extends All, All extends string, Struct extends object, C extends CollectionObject<All>> = Mutation<This, All, Struct, C, "add">;
|
|
41
|
-
export interface UpdateMutation<This extends All, All extends string, Struct extends object, C extends CollectionObject<All>> {
|
|
42
|
-
where?: WhereSelection<Struct>;
|
|
43
|
-
data: Mutation<This, All, Struct, C, "update">;
|
|
44
|
-
}
|
|
45
|
-
type WhereSelection<Struct extends object> = Struct extends Model<any, infer Fields, any> ? WhereObject<Fields> : never;
|
|
46
|
-
export {};
|
package/dist/dev-types.d.ts
DELETED
package/dist/dev.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ParseFn, AbstractProperty, PropertyOptions, PropertyInputOptions } from "./field/property.js";
|
|
2
|
-
import { PropertyUnion } from "./field/field-types.js";
|
|
3
|
-
import * as util from "./util-types.js";
|
|
4
|
-
import { Type } from "./utils.js";
|
|
5
|
-
export { ParseFn, AbstractProperty, util, PropertyOptions, Type, PropertyInputOptions, PropertyUnion, };
|
package/dist/error.d.ts
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
export type ErrorType = "ID_EXISTS" | "INVALID_ITEM" | "ADD_FAILED" | "UPDATE_FAILED" | "DELETE_FAILED" | "OVERWRITE_RELATION" | "NOT_FOUND" | "GET_FAILED"
|
|
2
|
-
/**
|
|
3
|
-
* The given transaction is invalid for the store it is trying to access
|
|
4
|
-
*/
|
|
5
|
-
| "INVALID_TX"
|
|
6
|
-
/**
|
|
7
|
-
* The database is not found
|
|
8
|
-
*/
|
|
9
|
-
| "NO_DB" | "CUSTOM" | "INVALID_CONFIG" | "ASSERTION_FAILED" | "OPEN_CURSOR" | "UNKNOWN";
|
|
10
|
-
export declare class StoreError extends Error {
|
|
11
|
-
readonly code: ErrorType;
|
|
12
|
-
readonly message: string;
|
|
13
|
-
constructor(code: ErrorType, message: string);
|
|
14
|
-
}
|
|
15
|
-
export declare const InvalidConfigError: {
|
|
16
|
-
new (message?: string): {
|
|
17
|
-
readonly code: ErrorType;
|
|
18
|
-
readonly message: string;
|
|
19
|
-
name: string;
|
|
20
|
-
stack?: string;
|
|
21
|
-
cause?: unknown;
|
|
22
|
-
};
|
|
23
|
-
readonly code: "INVALID_CONFIG";
|
|
24
|
-
of(message: string): void;
|
|
25
|
-
isError(error: unknown): error is Error;
|
|
26
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
27
|
-
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
28
|
-
stackTraceLimit: number;
|
|
29
|
-
};
|
|
30
|
-
export declare const InvalidTransactionError: {
|
|
31
|
-
new (message?: string): {
|
|
32
|
-
readonly code: ErrorType;
|
|
33
|
-
readonly message: string;
|
|
34
|
-
name: string;
|
|
35
|
-
stack?: string;
|
|
36
|
-
cause?: unknown;
|
|
37
|
-
};
|
|
38
|
-
readonly code: "INVALID_TX";
|
|
39
|
-
of(message: string): void;
|
|
40
|
-
isError(error: unknown): error is Error;
|
|
41
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
42
|
-
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
43
|
-
stackTraceLimit: number;
|
|
44
|
-
};
|
|
45
|
-
export declare const InvalidItemError: {
|
|
46
|
-
new (message?: string): {
|
|
47
|
-
readonly code: ErrorType;
|
|
48
|
-
readonly message: string;
|
|
49
|
-
name: string;
|
|
50
|
-
stack?: string;
|
|
51
|
-
cause?: unknown;
|
|
52
|
-
};
|
|
53
|
-
readonly code: "INVALID_ITEM";
|
|
54
|
-
of(message: string): void;
|
|
55
|
-
isError(error: unknown): error is Error;
|
|
56
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
57
|
-
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
58
|
-
stackTraceLimit: number;
|
|
59
|
-
};
|
|
60
|
-
export declare const AssertionError: {
|
|
61
|
-
new (message?: string): {
|
|
62
|
-
readonly code: ErrorType;
|
|
63
|
-
readonly message: string;
|
|
64
|
-
name: string;
|
|
65
|
-
stack?: string;
|
|
66
|
-
cause?: unknown;
|
|
67
|
-
};
|
|
68
|
-
readonly code: "ASSERTION_FAILED";
|
|
69
|
-
of(message: string): void;
|
|
70
|
-
isError(error: unknown): error is Error;
|
|
71
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
72
|
-
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
73
|
-
stackTraceLimit: number;
|
|
74
|
-
};
|
|
75
|
-
export declare const UnknownError: {
|
|
76
|
-
new (message?: string): {
|
|
77
|
-
readonly code: ErrorType;
|
|
78
|
-
readonly message: string;
|
|
79
|
-
name: string;
|
|
80
|
-
stack?: string;
|
|
81
|
-
cause?: unknown;
|
|
82
|
-
};
|
|
83
|
-
readonly code: "UNKNOWN";
|
|
84
|
-
of(message: string): void;
|
|
85
|
-
isError(error: unknown): error is Error;
|
|
86
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
87
|
-
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
88
|
-
stackTraceLimit: number;
|
|
89
|
-
};
|
|
90
|
-
export declare const DeleteError: {
|
|
91
|
-
new (message?: string): {
|
|
92
|
-
readonly code: ErrorType;
|
|
93
|
-
readonly message: string;
|
|
94
|
-
name: string;
|
|
95
|
-
stack?: string;
|
|
96
|
-
cause?: unknown;
|
|
97
|
-
};
|
|
98
|
-
readonly code: "DELETE_FAILED";
|
|
99
|
-
of(message: string): void;
|
|
100
|
-
isError(error: unknown): error is Error;
|
|
101
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
102
|
-
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
103
|
-
stackTraceLimit: number;
|
|
104
|
-
};
|
|
105
|
-
export declare const ObjectStoreNotFoundError: {
|
|
106
|
-
new (message?: string): {
|
|
107
|
-
readonly code: ErrorType;
|
|
108
|
-
readonly message: string;
|
|
109
|
-
name: string;
|
|
110
|
-
stack?: string;
|
|
111
|
-
cause?: unknown;
|
|
112
|
-
};
|
|
113
|
-
readonly code: "NOT_FOUND";
|
|
114
|
-
of(message: string): void;
|
|
115
|
-
isError(error: unknown): error is Error;
|
|
116
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
117
|
-
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
118
|
-
stackTraceLimit: number;
|
|
119
|
-
};
|
|
120
|
-
export declare const DocumentNotFoundError: {
|
|
121
|
-
new (message?: string): {
|
|
122
|
-
readonly code: ErrorType;
|
|
123
|
-
readonly message: string;
|
|
124
|
-
name: string;
|
|
125
|
-
stack?: string;
|
|
126
|
-
cause?: unknown;
|
|
127
|
-
};
|
|
128
|
-
readonly code: "NOT_FOUND";
|
|
129
|
-
of(message: string): void;
|
|
130
|
-
isError(error: unknown): error is Error;
|
|
131
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
132
|
-
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
133
|
-
stackTraceLimit: number;
|
|
134
|
-
};
|
|
135
|
-
export declare const UpdateError: {
|
|
136
|
-
new (message?: string): {
|
|
137
|
-
readonly code: ErrorType;
|
|
138
|
-
readonly message: string;
|
|
139
|
-
name: string;
|
|
140
|
-
stack?: string;
|
|
141
|
-
cause?: unknown;
|
|
142
|
-
};
|
|
143
|
-
readonly code: "UPDATE_FAILED";
|
|
144
|
-
of(message: string): void;
|
|
145
|
-
isError(error: unknown): error is Error;
|
|
146
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
147
|
-
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
148
|
-
stackTraceLimit: number;
|
|
149
|
-
};
|
|
150
|
-
export declare const AddError: {
|
|
151
|
-
new (message?: string): {
|
|
152
|
-
readonly code: ErrorType;
|
|
153
|
-
readonly message: string;
|
|
154
|
-
name: string;
|
|
155
|
-
stack?: string;
|
|
156
|
-
cause?: unknown;
|
|
157
|
-
};
|
|
158
|
-
readonly code: "ADD_FAILED";
|
|
159
|
-
of(message: string): void;
|
|
160
|
-
isError(error: unknown): error is Error;
|
|
161
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
162
|
-
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
163
|
-
stackTraceLimit: number;
|
|
164
|
-
};
|
|
165
|
-
export declare const OpenCursorError: {
|
|
166
|
-
new (message?: string): {
|
|
167
|
-
readonly code: ErrorType;
|
|
168
|
-
readonly message: string;
|
|
169
|
-
name: string;
|
|
170
|
-
stack?: string;
|
|
171
|
-
cause?: unknown;
|
|
172
|
-
};
|
|
173
|
-
readonly code: "OPEN_CURSOR";
|
|
174
|
-
of(message: string): void;
|
|
175
|
-
isError(error: unknown): error is Error;
|
|
176
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
177
|
-
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
178
|
-
stackTraceLimit: number;
|
|
179
|
-
};
|
|
180
|
-
export declare const RetrievalError: {
|
|
181
|
-
new (message?: string): {
|
|
182
|
-
readonly code: ErrorType;
|
|
183
|
-
readonly message: string;
|
|
184
|
-
name: string;
|
|
185
|
-
stack?: string;
|
|
186
|
-
cause?: unknown;
|
|
187
|
-
};
|
|
188
|
-
readonly code: "GET_FAILED";
|
|
189
|
-
of(message: string): void;
|
|
190
|
-
isError(error: unknown): error is Error;
|
|
191
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
192
|
-
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
193
|
-
stackTraceLimit: number;
|
|
194
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Dict, ValidKey, ValidKeyType } from "../util-types.js";
|
|
2
|
-
import PrimaryKey from "./primary-key.js";
|
|
3
|
-
import { AbstractProperty, ParseFn, Property } from "./property.js";
|
|
4
|
-
import { BaseRelation, OptionalRelation, ArrayRelation } from "./relation.js";
|
|
5
|
-
export type ReferenceActions = "Cascade" | "None" | "Restrict";
|
|
6
|
-
export type OptionalActions = "SetNull" | ReferenceActions;
|
|
7
|
-
export interface RelationOptions<Name extends string, OnDelete> {
|
|
8
|
-
name?: Name;
|
|
9
|
-
onDelete?: OnDelete;
|
|
10
|
-
}
|
|
11
|
-
export interface RelationActions {
|
|
12
|
-
onDelete: OptionalActions;
|
|
13
|
-
}
|
|
14
|
-
export declare const enum FieldTypes {
|
|
15
|
-
Field = 0,
|
|
16
|
-
Relation = 1,
|
|
17
|
-
PrimaryKey = 2,
|
|
18
|
-
Invalid = 3
|
|
19
|
-
}
|
|
20
|
-
export type GenFunction<T extends ValidKey> = () => T;
|
|
21
|
-
export type FunctionMatch<E> = E extends "string" ? string : E extends "number" ? number : E extends "date" ? Date : never;
|
|
22
|
-
export type GetPrimaryKeyType<T> = T extends PrimaryKey<any, infer Type> ? Type : never;
|
|
23
|
-
export interface FieldOptions {
|
|
24
|
-
unique: boolean;
|
|
25
|
-
}
|
|
26
|
-
export type RelationOutput<T> = T extends PrimaryKey<any, infer Type> ? Type : never;
|
|
27
|
-
export type RelationOutputStructure<R extends BaseRelation<any, any>, Output> = R extends ArrayRelation<any, any> ? Output[] : R extends OptionalRelation<any, any> ? Output | undefined : Output;
|
|
28
|
-
export type NonRelationOutput<T> = T extends AbstractProperty<infer Out, any> ? Out : T extends PrimaryKey<any, infer Type> ? Type : never;
|
|
29
|
-
export type ValidValue<N extends string = string> = BaseRelation<N, string> | AbstractProperty<any, any> | PrimaryKey<boolean, ValidKey>;
|
|
30
|
-
export type ParseFnWrap<T extends Dict> = {
|
|
31
|
-
[K in keyof T]: ParseFn<T[K]>;
|
|
32
|
-
};
|
|
33
|
-
export type PropertyUnion<T extends readonly (Property<any, boolean> | ParseFn<any>)[]> = T[number] extends Property<infer Type, boolean> ? Type : T extends ParseFn<infer Type> ? Type : never;
|
|
34
|
-
export declare const VALIDATORS: {
|
|
35
|
-
[K in ValidKeyType]: ParseFn<FunctionMatch<K>>;
|
|
36
|
-
};
|
package/dist/field/field.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import z from "zod";
|
|
2
|
-
import type { ValidKeyType } from "../types/common.js";
|
|
3
|
-
import type { FieldOptions, FunctionMatch, ReferenceActions, RelationOptions } from "./field-types.js";
|
|
4
|
-
import PrimaryKey from "./primary-key.js";
|
|
5
|
-
import { Relation } from "./relation.js";
|
|
6
|
-
export declare class Field<OutputType, HasDefault extends boolean = false> {
|
|
7
|
-
schema: z.ZodType<OutputType>;
|
|
8
|
-
private hasDefault;
|
|
9
|
-
static readonly schemas: {
|
|
10
|
-
string: z.ZodString;
|
|
11
|
-
boolean: z.ZodBoolean;
|
|
12
|
-
number: z.ZodNumber;
|
|
13
|
-
array: z.ZodArray<z.ZodAny>;
|
|
14
|
-
object: z.ZodObject<{}, z.core.$loose>;
|
|
15
|
-
date: z.ZodDate;
|
|
16
|
-
};
|
|
17
|
-
private options;
|
|
18
|
-
constructor(schema: z.ZodType<OutputType>, options?: Partial<FieldOptions>);
|
|
19
|
-
array(): Field<OutputType[], false>;
|
|
20
|
-
optional(): Field<OutputType | undefined, false>;
|
|
21
|
-
default(defaultValue: Exclude<OutputType, undefined>): Field<Exclude<OutputType, undefined>, true>;
|
|
22
|
-
refine(refineFn: (val: OutputType) => boolean): void;
|
|
23
|
-
parse(value: unknown): z.ZodSafeParseResult<OutputType>;
|
|
24
|
-
hasDefaultValue(): HasDefault;
|
|
25
|
-
/**
|
|
26
|
-
* Indicates that a field must be unique across all documents
|
|
27
|
-
*
|
|
28
|
-
* **NOTE**: The field type must be a primitive. If this is applied to a non-primitive, it returns `null`
|
|
29
|
-
*/
|
|
30
|
-
unique(): OutputType extends string | number | boolean | symbol ? this : null;
|
|
31
|
-
static array<T>(item: z.ZodType<T> | Field<T>, options?: FieldOptions): Field<T[], false>;
|
|
32
|
-
static boolean(schema?: z.ZodType<boolean>, options?: FieldOptions): Field<boolean, false>;
|
|
33
|
-
static custom<T>(schema: z.ZodType<T>, options?: FieldOptions): Field<T, false>;
|
|
34
|
-
static object<T extends Record<string, z.ZodType>>(item: T, options?: FieldOptions): Field<z.core.$InferObjectOutput<{ -readonly [P in keyof T]: T[P]; }, {}>, false>;
|
|
35
|
-
static primaryKey<V extends ValidKeyType = "number">(type?: V): PrimaryKey<false, FunctionMatch<V>>;
|
|
36
|
-
static literal<V extends string | number | boolean>(value: V): Field<V, false>;
|
|
37
|
-
static number(schema?: z.ZodType<number>, options?: FieldOptions): Field<number, false>;
|
|
38
|
-
static string(schema?: z.ZodType<string>, options?: FieldOptions): Field<string, false>;
|
|
39
|
-
static relation<To extends string, Name extends string = never>(to: To, options?: RelationOptions<Name, ReferenceActions>): Relation<To, Name>;
|
|
40
|
-
}
|
package/dist/field/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ValidKey, ValidKeyType } from "../util-types.js";
|
|
2
|
-
import { GenFunction } from "./field-types.js";
|
|
3
|
-
export default class PrimaryKey<AutoGenerate extends boolean, Type extends ValidKey> {
|
|
4
|
-
private genFn?;
|
|
5
|
-
private autoGenerate;
|
|
6
|
-
readonly type: ValidKeyType;
|
|
7
|
-
constructor();
|
|
8
|
-
constructor(type: ValidKeyType);
|
|
9
|
-
constructor(type: ValidKeyType, generator: GenFunction<Type>);
|
|
10
|
-
autoIncrement(): PrimaryKey<true, number>;
|
|
11
|
-
generator(genFn: GenFunction<Type>): PrimaryKey<true, Type>;
|
|
12
|
-
uuid(): PrimaryKey<true, string>;
|
|
13
|
-
genKey(): Type;
|
|
14
|
-
getSchema(): import("./property.js").ParseFn<string> | import("./property.js").ParseFn<number> | import("./property.js").ParseFn<Date>;
|
|
15
|
-
/**
|
|
16
|
-
* If the internal objectStore "autoIncrement" utility is being used
|
|
17
|
-
* @returns
|
|
18
|
-
*/
|
|
19
|
-
isAutoIncremented(): boolean;
|
|
20
|
-
}
|
package/dist/field/property.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Literable, NoUndefined, ValidKeyType } from "../util-types.js";
|
|
2
|
-
import { Type } from "../utils.js";
|
|
3
|
-
import { FunctionMatch, PropertyUnion, ReferenceActions, RelationOptions } from "./field-types.js";
|
|
4
|
-
import PrimaryKey from "./primary-key.js";
|
|
5
|
-
import { Relation } from "./relation.js";
|
|
6
|
-
export interface PropertyOptions {
|
|
7
|
-
unique: boolean;
|
|
8
|
-
}
|
|
9
|
-
export type PropertyInputOptions = Partial<PropertyOptions>;
|
|
10
|
-
export type ParseResult<T> = {
|
|
11
|
-
success: true;
|
|
12
|
-
data: T;
|
|
13
|
-
error?: undefined;
|
|
14
|
-
} | {
|
|
15
|
-
success: false;
|
|
16
|
-
data?: undefined;
|
|
17
|
-
error: string;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* A function to parse and validateFn an unknown value. It should also handle applying defaults
|
|
21
|
-
*/
|
|
22
|
-
export type ParseFn<T> = (value: unknown) => ParseResult<T>;
|
|
23
|
-
export declare abstract class AbstractProperty<Value, HasDefault extends boolean> {
|
|
24
|
-
protected validateFn: (value: unknown) => ParseResult<Value>;
|
|
25
|
-
protected type: Type;
|
|
26
|
-
protected hasDefault: HasDefault;
|
|
27
|
-
protected options: PropertyOptions;
|
|
28
|
-
constructor(validateFn: (value: unknown) => ParseResult<Value>, type: Type, options?: PropertyInputOptions);
|
|
29
|
-
get validate(): (value: unknown) => ParseResult<Value>;
|
|
30
|
-
abstract array(...args: unknown[]): AbstractProperty<Value[], false>;
|
|
31
|
-
abstract optional(...args: unknown[]): AbstractProperty<Value | undefined, false>;
|
|
32
|
-
abstract default(defaultValue: NoUndefined<Value>): AbstractProperty<NoUndefined<Value>, true>;
|
|
33
|
-
static array<T>(..._args: unknown[]): AbstractProperty<T[], false>;
|
|
34
|
-
static literal<const V extends Literable>(_item: V, ..._: unknown[]): AbstractProperty<V, false>;
|
|
35
|
-
static custom<T>(..._: unknown[]): AbstractProperty<T, false>;
|
|
36
|
-
static union<const _T extends readonly (ParseFn<any> | AbstractProperty<any, boolean>)[]>(..._: unknown[]): AbstractProperty<unknown, false>;
|
|
37
|
-
static string(..._: unknown[]): AbstractProperty<string, false>;
|
|
38
|
-
static number(..._: unknown[]): AbstractProperty<number, false>;
|
|
39
|
-
static boolean(..._: unknown[]): AbstractProperty<boolean, false>;
|
|
40
|
-
/**
|
|
41
|
-
* Indicates that a field must be unique across all documents
|
|
42
|
-
*
|
|
43
|
-
* **NOTE**: The field type must be a primitive. If this is applied to a non-primitive, it returns `null`
|
|
44
|
-
*/
|
|
45
|
-
unique(): Value extends string | number | boolean | symbol ? this : null;
|
|
46
|
-
hasDefaultValue(): HasDefault;
|
|
47
|
-
static relation<To extends string, Name extends string = never>(to: To, options?: RelationOptions<Name, ReferenceActions>): Relation<To, Name>;
|
|
48
|
-
static primaryKey<V extends ValidKeyType = "number">(type?: V): PrimaryKey<false, FunctionMatch<V>>;
|
|
49
|
-
static readonly validators: {
|
|
50
|
-
string: ParseFn<string>;
|
|
51
|
-
number: ParseFn<number>;
|
|
52
|
-
date: ParseFn<Date>;
|
|
53
|
-
};
|
|
54
|
-
protected static literalToType(value: Literable): Type;
|
|
55
|
-
protected static nameToType(typeName: string): Type;
|
|
56
|
-
}
|
|
57
|
-
export declare class Property<Value, HasDefault extends boolean> extends AbstractProperty<Value, HasDefault> {
|
|
58
|
-
array(): Property<Value[], false>;
|
|
59
|
-
default(defaultValue: NoUndefined<Value>): Property<NoUndefined<Value>, true>;
|
|
60
|
-
optional(): Property<Value | undefined, false>;
|
|
61
|
-
static literal<const V extends Literable>(value: V, options?: PropertyInputOptions): Property<V, false>;
|
|
62
|
-
static string(options?: PropertyInputOptions): Property<string, false>;
|
|
63
|
-
static number(options?: PropertyInputOptions): Property<number, false>;
|
|
64
|
-
static boolean(options?: PropertyInputOptions): Property<boolean, false>;
|
|
65
|
-
static union<const T extends readonly (ParseFn<any> | AbstractProperty<any, boolean>)[]>(items: T, options?: PropertyInputOptions): Property<PropertyUnion<T>, false>;
|
|
66
|
-
static custom<T>(fn: ParseFn<T>, options?: PropertyInputOptions): Property<T, false>;
|
|
67
|
-
static array<T>(item: ParseFn<T> | Property<T, boolean>, options?: PropertyInputOptions): Property<T[], false>;
|
|
68
|
-
private static generateArrayValidator;
|
|
69
|
-
}
|
package/dist/field/relation.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { OptionalActions, ReferenceActions, RelationActions, RelationOptions } from "./field-types.js";
|
|
2
|
-
export declare class BaseRelation<To extends string, Name extends string = never> {
|
|
3
|
-
/**
|
|
4
|
-
* The name of the model this relation is pointing to
|
|
5
|
-
*/
|
|
6
|
-
readonly to: To;
|
|
7
|
-
/**
|
|
8
|
-
* An optional label to give to the relation. This helps distinguish it from others
|
|
9
|
-
*/
|
|
10
|
-
readonly name: Name;
|
|
11
|
-
/**
|
|
12
|
-
* If the relation is optional or not
|
|
13
|
-
*/
|
|
14
|
-
readonly isOptional: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* If the relation is an array or not
|
|
17
|
-
*/
|
|
18
|
-
readonly isArray: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Actions to be performed under certain conditions
|
|
21
|
-
*/
|
|
22
|
-
protected actions: RelationActions;
|
|
23
|
-
/**
|
|
24
|
-
* The corresponding relation key on the model this relation points to
|
|
25
|
-
*/
|
|
26
|
-
private relatedKey;
|
|
27
|
-
constructor(
|
|
28
|
-
/**
|
|
29
|
-
* The name of the model this relation is pointing to
|
|
30
|
-
*/
|
|
31
|
-
to: To,
|
|
32
|
-
/**
|
|
33
|
-
* An optional label to give to the relation. This helps distinguish it from others
|
|
34
|
-
*/
|
|
35
|
-
name?: Name,
|
|
36
|
-
/**
|
|
37
|
-
* If the relation is optional or not
|
|
38
|
-
*/
|
|
39
|
-
isOptional?: boolean,
|
|
40
|
-
/**
|
|
41
|
-
* If the relation is an array or not
|
|
42
|
-
*/
|
|
43
|
-
isArray?: boolean, onDelete?: OptionalActions);
|
|
44
|
-
getActions(): {
|
|
45
|
-
onDelete: OptionalActions;
|
|
46
|
-
};
|
|
47
|
-
setRelatedKey(key: string): void;
|
|
48
|
-
/**
|
|
49
|
-
* Gets the key on the corresponding model this relation points to
|
|
50
|
-
*/
|
|
51
|
-
getRelatedKey(): string;
|
|
52
|
-
}
|
|
53
|
-
export declare class Relation<To extends string, Name extends string> extends BaseRelation<To, Name> {
|
|
54
|
-
private readonly _brand;
|
|
55
|
-
constructor(to: To, options?: RelationOptions<Name, ReferenceActions>);
|
|
56
|
-
/**
|
|
57
|
-
* Creates an array relation to the specified model
|
|
58
|
-
*
|
|
59
|
-
* **Note: Calling this function will reset any relation actions to the default**
|
|
60
|
-
*/
|
|
61
|
-
array({ onDelete, }?: Omit<RelationOptions<Name, OptionalActions>, "name">): ArrayRelation<To, Name>;
|
|
62
|
-
/**
|
|
63
|
-
* Creates an optional relation to the specified model
|
|
64
|
-
*
|
|
65
|
-
* **Note: Calling this function will reset any relation actions to the default**
|
|
66
|
-
*/
|
|
67
|
-
optional({ onDelete, }?: Omit<RelationOptions<Name, OptionalActions>, "name">): OptionalRelation<To, Name>;
|
|
68
|
-
onDelete(action: ReferenceActions): this;
|
|
69
|
-
}
|
|
70
|
-
export declare class ArrayRelation<To extends string, Name extends string> extends BaseRelation<To, Name> {
|
|
71
|
-
private readonly _brand;
|
|
72
|
-
constructor(to: To, name?: Name, action?: OptionalActions);
|
|
73
|
-
}
|
|
74
|
-
export declare class OptionalRelation<To extends string, Name extends string> extends BaseRelation<To, Name> {
|
|
75
|
-
private readonly _brand;
|
|
76
|
-
constructor(to: To, name?: Name, action?: OptionalActions);
|
|
77
|
-
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Builder } from "./builder.js";
|
|
2
|
-
import { StoreError, type ErrorType } from "./error.js";
|
|
3
|
-
import "./dev.js";
|
|
4
|
-
export { Builder, StoreError, ErrorType };
|
|
5
|
-
import { Property } from "./field";
|
|
6
|
-
export { Property };
|
|
7
|
-
import { CompiledQuery } from "./client/compiled-query.js";
|
|
8
|
-
export { CompiledQuery };
|
|
9
|
-
import type { ModelType } from "./model";
|
|
10
|
-
export { ModelType };
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
class e extends Error{code;message;constructor(e,t){super(),this.code=e,this.message=t}}function t(t,n){return class extends e{static code;constructor(e=n){super(t,e)}static of(e){new this(e)}}}const n=t("INVALID_CONFIG","Configuration is invalid"),s=t("INVALID_TX","Transaction is invalid"),r=t("INVALID_ITEM","Item is invalid"),o=t("ASSERTION_FAILED","Assertion failed"),a=t("UNKNOWN","An unknown error occurred"),i=t("DELETE_FAILED","Item could not be deleted"),c=t("NOT_FOUND","Object Store Not Found"),l=t("NOT_FOUND","Document Not Found"),u=t("UPDATE_FAILED","Item could not be updated"),d=t("ADD_FAILED","Item could not be added"),h=t("OPEN_CURSOR","Cursor could not be opened"),y=t("GET_FAILED","Item could not be retrieved");async function f(e,t){return await new Promise(t=>{e.onsuccess=()=>{t(e.result)},e.onerror=()=>{}})}function w(e){return Object.keys(e)}function m(e){return Array.isArray(e)||(e=[e]),e}function g(e){switch(e){case"date":return A.Date;case"number":return A.Number;case"string":return A.String}}function b(){return crypto.randomUUID()}function p(e){return e}function k(e,t){for(const n of t.keys())e.add(n);return e}var A;!function(e){e[e.String=0]="String",e[e.Number=1]="Number",e[e.BigInt=2]="BigInt",e[e.Boolean=3]="Boolean",e[e.Symbol=4]="Symbol",e[e.Array=5]="Array",e[e.Date=6]="Date",e[e.Object=7]="Object",e[e.Unknown=8]="Unknown"}(A||(A={}));const S={string:e=>"string"==typeof e?{success:!0,data:e}:{success:!1,error:"Value is not a string"},number:e=>"number"==typeof e?{success:!0,data:e}:{success:!1,error:"Value is not a string"},date:e=>e instanceof Date?isNaN(e.getTime())?{success:!1,error:"Value is not a valid date"}:{success:!0,data:e}:{success:!1,error:"Value is not a date"}};class ${genFn;autoGenerate;type;constructor(e,t){e?(this.type=e,t?(this.autoGenerate=!0,this.genFn=t):this.autoGenerate=!1):(this.autoGenerate=!1,this.type="number")}autoIncrement(){if("number"===this.type)return this.genFn=void 0,this.autoGenerate=!0,this;const e=new $;return e.genFn=void 0,e.autoGenerate=!0,e}generator(e){return this.genFn=e,this.autoGenerate=!0,this}uuid(){if(!window.isSecureContext)throw new Error("Window is not in a secure context");return new $("string",b)}genKey(){if(this.genFn)return this.genFn();throw new Error("Generator function not defined")}getSchema(){return S[this.type]}isAutoIncremented(){return this.autoGenerate&&!this.genFn}}class N{to;name;isOptional;isArray;actions;relatedKey;constructor(e,t="",n=!1,s=!1,r){this.to=e,this.name=t,this.isOptional=n,this.isArray=s,this.relatedKey="",this.actions={onDelete:r||"Restrict"}}getActions(){return{...this.actions}}setRelatedKey(e){this.relatedKey=e}getRelatedKey(){return this.relatedKey}}class v extends N{constructor(e,t={}){super(e,t.name,!1,!1,t.onDelete)}array({onDelete:e}={}){return new I(this.to,this.name,e)}optional({onDelete:e}={}){return new K(this.to,this.name,e)}onDelete(e){return this.actions.onDelete=e,this}}class I extends N{constructor(e,t,n="SetNull"){super(e,t,!1,!0,n)}}class K extends N{constructor(e,t,n="SetNull"){super(e,t,!0,!1,n)}}class D{validateFn;type;hasDefault=!1;options;constructor(e,t,n){this.validateFn=e,this.type=t,this.options={unique:n?.unique??!1}}get validate(){return this.validateFn}static array(...e){throw new Error("Method Not Implemented")}static literal(e,...t){throw new Error("Method Not Implemented")}static custom(...e){throw new Error("Method Not Implemented")}static union(...e){throw new Error("Method Not Implemented")}static string(...e){throw new Error("Method Not Implemented")}static number(...e){throw new Error("Method Not Implemented")}static boolean(...e){throw new Error("Method Not Implemented")}unique(){switch(this.type){case A.Boolean:case A.String:case A.Number:case A.Symbol:return this.options.unique=!0,this;default:return console.error("A non-primitive cannot be a unique value"),null}}hasDefaultValue(){return this.hasDefault}static relation(e,t){return new v(e,t)}static primaryKey(e="number"){return new $(e)}static validators=S;static literalToType(e){return D.nameToType(typeof e)}static nameToType(e){switch(e){case"boolean":return A.Boolean;case"bigint":return A.BigInt;case"number":case"string":return A.Number;case"object":return A.Object;case"symbol":return A.Symbol;default:return A.Unknown}}}class M extends D{array(){return new M(M.generateArrayValidator(this.validateFn),A.Array,this.options)}default(e){return this.hasDefault=!0,new M(t=>null==t?{success:!0,data:e}:this.validateFn(t),this.type,this.options)}optional(){return new M(e=>null==e?{success:!0,data:void 0}:this.validateFn(e),this.type,this.options)}static literal(e,t){return new M(t=>t===e?{success:!0,data:e}:{success:!1,error:`${t} !== ${e}`},M.literalToType(e),t)}static string(e){return new M(D.validators.string,A.String,e)}static number(e){return new M(D.validators.number,A.Number,e)}static boolean(e){return new M(e=>"boolean"==typeof e?{success:!0,data:e}:{success:!1,error:"Value is not a string"},A.Boolean,e)}static union(e,t){const n=e.map(e=>e instanceof D?e.validate:e);return new M(e=>{for(const t of n){const n=t(e);if(n.success)return n}return{success:!1,error:"Value did not match any of the items"}},A.Unknown,t)}static custom(e,t){return new M(e,A.Unknown,t)}static array(e,t){return new M(M.generateArrayValidator(e instanceof M?e.validateFn:e),A.Array,t)}static generateArrayValidator(e){return t=>{if(Array.isArray(t)){const n=[];for(const s of t){const t=e(s);if(!t.success)return t;n.push(t.data)}return{success:!0,data:n}}return{success:!1,error:"Value is not an array"}}}}class O{name;fields;fieldKeys;relationLinks=new Set;cache={};primaryKey;constructor(t,n){this.name=t,this.fields=n,this.fieldKeys=w(n);for(const e of this.fieldKeys){const t=this.fields[e];t instanceof N&&t.to!==this.name&&this.relationLinks.add(t.to)}const s=this.fieldKeys.find(e=>this.fields[e]instanceof $);if(!s)throw new e("INVALID_CONFIG",`Model ${this.name} has no primary key`);this.primaryKey=s}get(e){return this.fields[e]}getModelField(e){const t=this.fields[e];if(t&&t instanceof D)return t}getPrimaryKey(){return this.fields[this.primaryKey]}getRelation(e){const t=this.fields[e];if(t&&t instanceof N)return t}keyType(e){const t=this.fields[e];return t?t instanceof D?0:t instanceof N?1:t instanceof $?2:3:3}links(){return this.relationLinks.keys()}keys(){return[...this.fieldKeys]}parseField(e,t){return this.fields[e]instanceof D?this.fields[e].validate(t):null}getDeletedStores(e){if(this.cache.delete)return this.cache.delete;const t=new Set,n=[this.name];let s;for(;n.length>0;){const r=n.shift();if(t.has(r))continue;s=e.getModel(r);const o=s.cache.delete;if(o)k(t,o);else{t.add(r);for(const e of s.links())t.has(e)||n.push(e)}}return this.cache.delete=t,t}}class F{tx;store;constructor(e,t){this.tx=e,this.store=t}async add(e){return await this.handleRequest(this.store.add(e),()=>new d)}async get(e){return await this.handleRequest(this.store.get(e),()=>new y)}async put(e){return await this.handleRequest(this.store.put(e),()=>new u)}async delete(e){return await this.handleRequest(this.store.delete(e),()=>new i)}async openCursor(e,t={}){const n=t.onError||(()=>new h),s=this.store.openCursor(t.query,t.direction);await new Promise(t=>{s.onsuccess=async s=>{if(!s.target)throw this.tx.abort(n());const r=s.target.result;r&&await e(r,this.tx)||t()},s.onerror=()=>{throw this.tx.abort(n())}})}async handleRequest(e,t){return await new Promise(n=>{e.onsuccess=()=>{n(e.result)},e.onerror=()=>{throw this.tx.abort(t())}})}}class x{internal;status;error=null;storeNames;objectStores;constructor(e,t,n,s={}){this.internal=e.transaction(t,n),this.status="running",this.storeNames=Array.from(this.internal.objectStoreNames),this.objectStores={};for(const e of this.storeNames)this.objectStores[e]=this.getObjectstore(e);this.internal.onabort=this.registerHandler("aborted",s.onAbort),this.internal.onerror=this.registerHandler("error",s.onError),this.internal.oncomplete=this.registerHandler("complete",s.onComplete)}abort(e){return this.internal.abort(),this.error=e,this.error}commit(){this.internal.commit()}getInternal(){return this.internal}getStore(e){const t=this.objectStores[e];if(!t)throw this.abort(new s(`Store '${e}' is not a part of this transaction`));return t}get mode(){return this.internal.mode}is(e){return this.status===e}contains(e){Array.isArray(e)||(e=[e]);for(const t of e)if(!this.internal.objectStoreNames.contains(t))return!1;return!0}assertIsArray(e,t="Value is not an array"){if(!Array.isArray(e))throw this.abort(new o(t))}getObjectstore(e){try{return new F(this,this.internal.objectStore(e))}catch{throw this.abort(new c(`No ObjectStore with the name '${e}' found`))}}registerHandler(e,t=()=>{}){return n=>{this.status=e,t(this,n)}}async wrap(t){try{return await t(this)}catch(t){throw t instanceof e&&"aborted"===this.status?t:this.abort(new a)}}}function R(e){if(!e)return()=>!0;const t=[];for(const n in e)if(Object.hasOwn(e,n))switch(typeof e[n]){case"function":t.push([n,e[n]]);break;case"object":break;default:t.push([n,t=>t===e[n]])}return e=>{if(!e||"object"!=typeof e)return!1;for(const n of t)if(!n[1](e[n[0]]))return!1;return!0}}function j(e,t,n={},s){const o=t.getModel(e);if(n.include&&n.select)throw s?s.abort(new r("include and select cannot both be defined")):new r("include and select cannot both be defined");const a=R(n.where),i=n.select?"select":n.include?"include":"";if(i){const e=n[i],r=!!n.select,c=[];for(const n in e)if(Object.hasOwn(e,n)&&e[n])switch(o.keyType(n)){case 1:{const r=o.getRelation(n),a="object"==typeof e[n]?j(r.to,t,e[n],s):p;if(r.isArray){const e=async(e,t)=>{const n=[],s=t.getStore(r.to);for(const r of e){const e=await a(await s.get(r),t);e&&n.push(e)}return n};c.push({key:n,getValue:e})}else{const e=async(e,t)=>await a(await t.getStore(r.to).get(e),t);c.push({key:n,getValue:e})}break}case 0:case 2:r&&c.push({key:n})}return r?async(e,t)=>{if(!a(e))return;const n={};for(const{key:s,getValue:r}of c)n[s]=r?await r(e[s],t):e[s];return n}:async(e,t)=>{if(a(e)){for(const{key:n,getValue:s}of c)e[n]=await s(e[n],t);return e}}}return e=>a(e)?e:void 0}function T(e,t,n,s){const r=new Set([e]);if("mutation"===n){const o=w(t),a=s.getModel(e);for(const e of o){const o=a.getRelation(e),i=m(t[e]);if(o)for(const e of i)if(e&&"object"==typeof e)for(const t in e)if(Object.hasOwn(e,t))switch(t){case"$connect":case"$connectMany":case"$disconnect":case"$disconnectMany":r.add(o.to);break;case"$delete":case"$deleteMany":k(r,a.getDeletedStores(s));break;case"$create":k(r,T(o.to,e[t],n,s));break;case"$createMany":e[t].forEach(e=>k(r,T(o.to,e,n,s)))}}}else{const n=s.getModel(e);for(const e of w(t)){const o=n.getRelation(e);if(o)switch(typeof t[e]){case"object":k(r,T(o.to,E(t[e]),"query",s));break;case"boolean":r.add(o.to)}}}return r}function E(e){return e.include?e.include:e.select?e.select:{}}function C(t){return n=>{throw n instanceof e?t.abort(n):t.abort(new a(String(n)))}}class V{client;name;accessedStores;selectClause;constructor(e,t,n){this.client=e,this.name=t,this.accessedStores=Array.from(T(t,E(n),"query",this.client)),this.selectClause=j(t,this.client,n)}async find(){return await this._find(!1)}async findFirst(){return(await this._find(!0))[0]}async _find(e){const t=this.client.createTransaction("readonly",this.accessedStores),n=[],s=t.getStore(this.name);return await s.openCursor(async s=>{const r=await this.selectClause(s.value,t);return r&&n.push(r),(!e||!n.length)&&(s.continue(),!0)}),n}}async function _(e,t,s,r=!1,o={}){const{singleton:a,finalStep:c=!0}=o,l=t.getModel(e),u=o.tx?o.tx.storeNames:Array.from(l.getDeletedStores(t)),d=o.tx??t.createTransaction("readwrite",u),h=d.getStore(e);let y=0;const w=async s=>{if(!s)return!1;const r=s[l.primaryKey];for(const o of l.links()){const a=l.getRelation(o),{onDelete:c}=a.getActions(),u=s[o],h=t.getModel(a.to);switch(c){case"Cascade":if(a.isArray){d.assertIsArray(u);for(const e of u)await _(a.to,t,void 0,void 0,{tx:d,singleton:{id:e}})}else u&&await _(a.to,t,void 0,void 0,{tx:d,singleton:{id:u}});break;case"SetNull":{if(!u)break;const e=m(u),t=d.getStore(a.to),s=a.getRelatedKey(),o=h.getRelation(s);if(!o)throw d.abort(new n(`Relation '${a.name}' has an invalid relation key '${a.getRelatedKey()}'`));if(!o.isArray&&!o.isOptional)throw d.abort(new n(`Key '${s}' on model '${s}': Non-optional relation cannot have the 'SetNull' action`));for(const n of e){const e=await t.get(n);if(!e)continue;const a=e[s];if(o.isArray){d.assertIsArray(a);const e=a.indexOf(r);if(-1===e)continue;a.splice(e,1)}else e[s]=null;await t.put(e)}break}case"Restrict":if(Array.isArray(u)&&u.length>0||u)throw d.abort(new i(`Key '${o}' on model '${e}' deletion is restricted while there is an active relation`))}}return!0};if(a)await w(await h.get(a.id))&&(await h.delete(a.id),y++);else{const e=R(s);let t;await h.openCursor(async n=>{const s=n.value;return e(s)&&await w(s)&&(t=n.delete()),r&&y>0?(t&&c&&await f(t),!1):(n.continue(),!0)})}return y}class q{db;models;name;version;stores;constructor(e,t){this.db=e,this.models=t,this.name=this.db.name,this.version=this.db.version,this.stores={};for(const e of this.models.keys())this.stores[e]=this.createInterface(e)}getStore(e){return this.stores[e]}createTransaction(e,t,n){return new x(this.db,t,e,n)}async deleteDb(){await f(window.indexedDB.deleteDatabase(this.name))}deleteAllStores(){for(const e of this.models.keys())this.db.deleteObjectStore(e)}deleteStore(e){Array.isArray(e)||(e=[e]);for(const t of e)this.db.deleteObjectStore(t)}getModel(e){return this.models.getModel(e)}getAccessedStores(e,t,n="mutation"){return Array.from(T(e,t,n,this))}createInterface(e){return{add:async(t,n)=>await this.add(e,t,{tx:n}),addMany:async(t,n)=>{if(!n){const s=new Set;for(const n of t)k(s,T(e,n,"mutation",this));n=this.createTransaction("readwrite",Array.from(s))}const s=[];let r;for(const o of t)r=this.add(e,o,{tx:n}),r.then(e=>s.push(e)).catch(C(n));return r&&await r,s},clear:async t=>await this.clear(e,{tx:t}),findFirst:async(t,n)=>(await this.find(e,t,!0,{tx:n}))[0],find:async(t,n)=>await this.find(e,t,!1,{tx:n}),put:async()=>{},get:async t=>{const n=this.createTransaction("readonly",e);return await n.getStore(e).get(t)},insert:async(e,t)=>(await new Promise(e=>e()),5),updateFirst:async(t,n)=>(await this.update(e,t,!0,{tx:n}))[0],updateMany:async(t,n)=>await this.update(e,t,!1,{tx:n}),compileQuery:t=>new V(this,e,t),delete:async t=>await _(e,this,void 0,void 0,{singleton:{id:t}})>0,deleteFirst:async t=>await _(e,this,t,!0)>0,deleteMany:async t=>await _(e,this,t,!1)}}async add(e,t,n={}){let{tx:s}=n;const{relation:o}=n,i=s?s.storeNames:this.getAccessedStores(e,t,"mutation");s=s??new x(this.db,i,"readwrite");const c=s.getStore(e),u=this.getModel(e),d=u.getPrimaryKey(),h=o?{[o.key]:u.getRelation(o.key)?.isArray?[o.id]:o.id}:{},y=d.isAutoIncremented()?{...h}:{...h,[u.primaryKey]:t[u.primaryKey]??d.genKey()},f=await c.add(y),g={},b=new Set;for(const n of w(t)){b.add(n);const o=t[n];switch(u.keyType(n)){case 3:throw s.abort(new r(`Key '${n}' does ont exist on model '${e}'`));case 0:{const e=u.parseField(n,o);if(!e)throw s.abort(new a);if(!e.success)throw s.abort(new r(`Key '${n}' has the following validation error: ${e.error}`));g[n]=e.data;break}case 1:{if(!o)continue;const e=m(o),t=u.getRelation(n);if(t.isArray&&(g[n]=[],"$createMany"in o||"$connectMany"in o)){const t=[];for(const e of o.$createMany??[])t.push({$create:e});for(const e of o.$connectMany??[])t.push({$connect:e});e.push(...t)}const a=this.getModel(t.to).getRelation(t.getRelatedKey()),i=s.getStore(t.to),c=new Set;for(const o of e){const e=w(o)[0];if(!e)throw s.abort(new r(`Key '${n}' cannot be an empty connection object`));switch(e){case"$connect":{const u=o[e];if(c.has(u))throw s.abort(new r(`Primary key '${u}' was already used for a connection`));c.add(u);const d=await i.get(u);if(!d)throw s.abort(new l(`Document with Primary Key '${u}' could not be found in model '${t.to}'`));if(!a)throw s.abort(new r(`Could not find corresponding relation '${t.name}'`));if(a.isArray)d[t.getRelatedKey()].push(f);else{const e=t.getRelatedKey();d[e],d[e]=f}i.put(d).catch(C(s)),t.isArray?g[n].push(u):g[n]=u;break}case"$create":{const r=await this.add(t.to,o[e],{tx:s,relation:{id:f,key:t.getRelatedKey()}});t.isArray?g[n].push(r):g[n]=r;break}case"$connectMany":case"$createMany":break;default:throw s.abort(new r(`Connection Object on key '${n}' has an unknown key '${e}'`))}if(!t.isArray)break}break}}}const p=Array.from(new Set(u.keys()).difference(b));for(const e of p)switch(u.keyType(e)){case 0:{const t=u.parseField(e,void 0);if(!t)throw s.abort(new a);if(!t.success)throw s.abort(new r(`Key '${e}' is missing`));g[e]=t.data;break}case 1:{const t=u.getRelation(e),n=h[e];if(t.isArray)g[e]=n??[];else if(t.isOptional)g[e]=n??null;else{if(!n)throw s.abort(new r(`Required relation '${e}' is not defined`));g[e]=n}break}}return await c.put({[u.primaryKey]:f,...g})}async clear(e,t){await _(e,this,void 0,!1,t)}async find(e,t,n,s={}){let{tx:r}=s;const o=r?r.storeNames:this.getAccessedStores(e,E(t),"query");r=r??new x(this.db,o,"readonly");const a=[],i=r.getStore(e),c=j(e,this,t,r);return await i.openCursor(async e=>{const t=await c(e.value,r);return t&&a.push(t),(!n||!a.length)&&(e.continue(),!0)}),a}async update(e,t,n,s={}){let{tx:o}=s;const{singleton:i=!1}=s,c=o?o.storeNames:this.getAccessedStores(e,t.data,"mutation");o=o??new x(this.db,c,"readwrite");const l=[],d=o.getStore(e),h=this.getModel(e),{where:y,data:f}=t,g=[];for(const e of w(f))switch(h.keyType(e)){case 0:g.push({key:e,isFun:"function"==typeof f[e],isRelation:!1});break;case 1:g.push({key:e,isFun:!1,isRelation:!0,relation:h.getRelation(e)});break;case 2:throw o.abort(new u("Primary key field cannot be updated"));default:throw o.abort(new a(`Unknown key '${e}'`))}const b=R(y),p=async e=>{if(y&&!b(e))return!1;for(const{key:t,isRelation:n,isFun:s,relation:a}of g){if(!n){e[t]=s?f[t](e[t]):f[t];continue}const i=m(f[t]);for(const n of i)for(const s in n){if(!Object.hasOwn(n,t))continue;const i=n[t];switch(s){case"$connect":case"$create":case"$updateMany":case"$delete":case"$disconnect":break;case"$update":a.isArray?await this.update(a.to,i,!0,{tx:o}):e[t]&&await this.updateSingleton(a.to,e[t],i,{tx:o});break;case"$connectMany":case"$createMany":case"$deleteMany":case"$disconnectMany":case"$disconnectAll":case"$deleteAll":throw o.abort(new r(`Connection Object on key '${t}' has an unknown key '${s}'`))}break}}};return i?await p(await d.get(i.id)):await d.openCursor(async e=>(await p(e.value),(!n||!l.length)&&(e.continue(),!0))),l}async updateSingleton(e,t,n,s){let{tx:r}=s;const o=r?r.storeNames:this.getAccessedStores(e,n,"mutation");r=r??new x(this.db,o,"readwrite");const a=r.getStore(e),i=this.getModel(e),c=await a.get(t);if(!c)throw r.abort(new l(`No document with key '${t}' could be found in store '${i.name}'`));return c}}class L{name;names;models;constructor(e,t){this.name=e,this.names=t,this.models={}}defineModel(e,t){const n=new O(e,t);return this.models[e]=n,n}compile(e){return new G(this.name,e)}}class G{name;models;schemas;modelKeys;constructor(t,n){this.name=t,this.models=n,this.modelKeys=w(this.models),this.schemas={};for(const t of this.modelKeys){const n=this.models[t],s={};for(const r of n.keys()){const o=n.get(r);if(o instanceof D)s[r]=o.validate;else if(o instanceof N){const a=this.models[o.to],i=a.getPrimaryKey();s[r]=D.validators[i.type],o.isOptional?s[r]=new M(s[r],g(i.type)).optional().validate:o.isArray&&(s[r]=s[r]=new M(s[r],g(i.type)).array().validate);let c=!!o.getRelatedKey();if(!c)for(const e of a.keys()){const t=a.get(e);if(r!==e&&t instanceof N&&t.to===n.name&&t.name===o.name){c=t.to!==o.to||r!==e,c&&(o.setRelatedKey(e),t.setRelatedKey(r));break}}if(!c)throw new e("INVALID_CONFIG",`Relation '${o.name}' of model ${t} does not have an equivalent relation on model '${o.to}'`)}else{if(!(o instanceof $))throw new e("INVALID_CONFIG",`Unknown field value detected: ${JSON.stringify(o)}`);s[r]=D.validators[o.type]}}this.schemas[t]=s}}getModel(e){return this.models[e]}async createClient(e=1){const t=window.indexedDB.open(this.name,e);t.onupgradeneeded=e=>{const t=e.target.result;for(const e of this.modelKeys){const n=this.models[e];t.objectStoreNames.contains(n.name)||t.createObjectStore(n.name,{autoIncrement:n.getPrimaryKey().isAutoIncremented(),keyPath:n.primaryKey})}};const n=await f(t);return new q(n,this)}keys(){return[...this.modelKeys]}}export{L as Builder,V as CompiledQuery,M as Property,e as StoreError};
|
package/dist/model/index.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { CompiledDb } from "../builder.js";
|
|
2
|
-
import { ValidValue, BaseRelation, OptionalRelation, ArrayRelation, RelationOutput, Relation, AbstractProperty, PrimaryKey, ParseFnWrap } from "../field";
|
|
3
|
-
import { Dict, Keyof } from "../util-types.js";
|
|
4
|
-
import Model from "./model.js";
|
|
5
|
-
export type FindPrimaryKey<F extends Record<string, ValidValue>> = Extract<{
|
|
6
|
-
[K in keyof F]: F[K] extends PrimaryKey<any, any> ? K : never;
|
|
7
|
-
}[keyof F], string>;
|
|
8
|
-
export type PrimaryKeyType<M extends Model<any, any, any>> = M extends Model<any, infer F, any> ? {
|
|
9
|
-
[K in keyof F]: F[K] extends PrimaryKey<any, infer Type> ? Type : never;
|
|
10
|
-
}[keyof F] : never;
|
|
11
|
-
export interface ModelCache {
|
|
12
|
-
delete?: Set<string>;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Gets the type of a relation given its name
|
|
16
|
-
*/
|
|
17
|
-
export type RelationValue<Name extends string, C> = Name extends keyof C ? C[Name] extends Model<any, infer Fields, infer PrimaryKey> ? RelationOutput<Fields[PrimaryKey]> : never : never;
|
|
18
|
-
/**
|
|
19
|
-
* Gets the primitive type of the relation field
|
|
20
|
-
*/
|
|
21
|
-
export type GetRelationField<F, C> = F extends Relation<infer To, any> ? RelationValue<To, C> : F extends OptionalRelation<infer To, any> ? RelationValue<To, C> | undefined : F extends ArrayRelation<infer To, any> ? RelationValue<To, C>[] : never;
|
|
22
|
-
export type ModelStructure<F extends Dict<ValidValue>, C> = {
|
|
23
|
-
[K in keyof F]: F[K] extends AbstractProperty<infer Output, any> ? Output : F[K] extends PrimaryKey<any, infer Type> ? Type : GetRelationField<F[K], C>;
|
|
24
|
-
};
|
|
25
|
-
export type ModelType<M extends Model<any, any, any>, C extends CompiledDb<any, any, any>> = M extends Model<any, infer Fields, any> ? C extends CompiledDb<any, any, infer Collection> ? ModelStructure<Fields, Collection> : never : never;
|
|
26
|
-
export type ExtractFields<M extends Model<any, any, any>> = M extends Model<any, infer Fields, any> ? Fields : never;
|
|
27
|
-
export type AllRelationKeys<M extends Model<any, any, any>> = M extends Model<any, infer Fields, any> ? {
|
|
28
|
-
[K in Keyof<Fields>]: Fields[K] extends BaseRelation<any, any> ? K : never;
|
|
29
|
-
}[Keyof<Fields>] : never;
|
|
30
|
-
export type RelationlessModelStructure<M extends Model<any, any, any>> = M extends Model<any, infer Fields, any> ? Omit<{
|
|
31
|
-
[K in Keyof<Fields>]: Fields[K] extends BaseRelation<any, any> ? unknown : Fields[K] extends AbstractProperty<infer Type, any> ? Type : Fields[K] extends PrimaryKey<any, infer Type> ? Type : never;
|
|
32
|
-
}, AllRelationKeys<M>> : never;
|
|
33
|
-
export type CollectionSchema<C> = C extends Record<infer Keys, Model<any, any, any>> ? {
|
|
34
|
-
[K in Keys]: C[K] extends Model<any, infer Fields, any> ? ParseFnWrap<ModelStructure<Fields, C>> : never;
|
|
35
|
-
} : never;
|
|
36
|
-
export type FindRelationKey<From extends string, RelationName extends string, M extends Model<any, any, any>> = M extends Model<any, infer Fields, any> ? {
|
|
37
|
-
[K in Keyof<Fields>]: Fields[K] extends BaseRelation<From, infer CurName> ? CurName extends RelationName ? K : never : never;
|
|
38
|
-
}[Keyof<Fields>] : never;
|
package/dist/model/model.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { CollectionObject } from "../builder.js";
|
|
2
|
-
import { DbClient } from "../client/index.js";
|
|
3
|
-
import { BaseRelation, AbstractProperty, FieldTypes, PrimaryKey, ValidValue, ParseResult } from "../field";
|
|
4
|
-
import { Keyof, ValidKey } from "../util-types.js";
|
|
5
|
-
import { FindPrimaryKey } from "./model-types.js";
|
|
6
|
-
export default class Model<Name extends string, F extends Record<string, ValidValue>, Primary extends FindPrimaryKey<F> = FindPrimaryKey<F>> {
|
|
7
|
-
readonly name: Name;
|
|
8
|
-
private readonly fields;
|
|
9
|
-
private readonly fieldKeys;
|
|
10
|
-
private readonly relationLinks;
|
|
11
|
-
private cache;
|
|
12
|
-
readonly primaryKey: Primary;
|
|
13
|
-
constructor(name: Name, fields: F);
|
|
14
|
-
get<K extends Keyof<F>>(key: K): F[K];
|
|
15
|
-
getModelField(key: string): AbstractProperty<any, any> | undefined;
|
|
16
|
-
getPrimaryKey(): PrimaryKey<boolean, ValidKey>;
|
|
17
|
-
getRelation<Models extends string>(key: string): BaseRelation<Models, string> | undefined;
|
|
18
|
-
keyType(key: Keyof<F>): FieldTypes;
|
|
19
|
-
links<Names extends string = string>(): SetIterator<Names>;
|
|
20
|
-
keys(): Keyof<F>[];
|
|
21
|
-
parseField<K extends Keyof<F>>(field: K, value: unknown): ParseResult<any>;
|
|
22
|
-
getDeletedStores<ModelNames extends string, Models extends CollectionObject<ModelNames>>(client: DbClient<string, ModelNames, Models>): Set<ModelNames>;
|
|
23
|
-
}
|
package/dist/object-store.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A paper thin wrapper around IDBObjectStore
|
|
3
|
-
*/
|
|
4
|
-
import { StoreError } from "./error.js";
|
|
5
|
-
import { Transaction } from "./transaction.js";
|
|
6
|
-
import { Dict, Promisable, ValidKey } from "./util-types.js";
|
|
7
|
-
export declare class ObjectStore {
|
|
8
|
-
private readonly tx;
|
|
9
|
-
readonly store: IDBObjectStore;
|
|
10
|
-
constructor(tx: Transaction<IDBTransactionMode, string>, store: IDBObjectStore);
|
|
11
|
-
add(item: Dict): Promise<ValidKey>;
|
|
12
|
-
/**
|
|
13
|
-
* Attempts to retrieve the value from the object store.
|
|
14
|
-
*
|
|
15
|
-
* Returns `undefined` if no value was found
|
|
16
|
-
*/
|
|
17
|
-
get(key: ValidKey): Promise<Dict>;
|
|
18
|
-
put(item: Dict): Promise<ValidKey>;
|
|
19
|
-
delete(key: ValidKey): Promise<undefined>;
|
|
20
|
-
openCursor(callback: (cursor: IDBCursorWithValue, tx: Transaction<IDBTransactionMode, string>) => Promisable<boolean>, options?: {
|
|
21
|
-
query?: IDBValidKey | IDBKeyRange;
|
|
22
|
-
direction?: IDBCursorDirection;
|
|
23
|
-
onError?: () => StoreError;
|
|
24
|
-
}): Promise<void>;
|
|
25
|
-
private handleRequest;
|
|
26
|
-
}
|
package/dist/transaction.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { StoreError } from "./error";
|
|
2
|
-
import { ObjectStore } from "./object-store.js";
|
|
3
|
-
import { Arrayable } from "./util-types.js";
|
|
4
|
-
export type TransactionStatus = "running" | "aborted" | "complete" | "error";
|
|
5
|
-
export type TransactionEventHandler = (tx: Transaction<IDBTransactionMode>, ev: Event) => void;
|
|
6
|
-
export interface TransactionOptions extends Partial<{
|
|
7
|
-
onAbort: TransactionEventHandler;
|
|
8
|
-
onError: TransactionEventHandler;
|
|
9
|
-
onComplete: TransactionEventHandler;
|
|
10
|
-
}> {
|
|
11
|
-
}
|
|
12
|
-
export declare class Transaction<Mode extends IDBTransactionMode, Stores extends string = string> {
|
|
13
|
-
private internal;
|
|
14
|
-
status: TransactionStatus;
|
|
15
|
-
error: StoreError | null;
|
|
16
|
-
readonly storeNames: Stores[];
|
|
17
|
-
/**
|
|
18
|
-
* A record of store names to `IDBObjectStore` objects
|
|
19
|
-
*/
|
|
20
|
-
private readonly objectStores;
|
|
21
|
-
constructor(db: IDBDatabase, stores: Arrayable<Stores>, mode: Mode, options?: TransactionOptions);
|
|
22
|
-
abort(error: StoreError): StoreError;
|
|
23
|
-
commit(): void;
|
|
24
|
-
/**
|
|
25
|
-
* Gets the internal `IDBTransaction` object
|
|
26
|
-
*
|
|
27
|
-
* It's recommended you don't use this function and use the built-in functions of the wrapper
|
|
28
|
-
* @returns Internal transaction object
|
|
29
|
-
*/
|
|
30
|
-
getInternal(): IDBTransaction;
|
|
31
|
-
getStore(store: Stores): ObjectStore;
|
|
32
|
-
get mode(): Mode;
|
|
33
|
-
is(status: TransactionStatus): boolean;
|
|
34
|
-
contains(stores: Arrayable<string>): boolean;
|
|
35
|
-
assertIsArray(value: any, message?: string): asserts value is any[];
|
|
36
|
-
private getObjectstore;
|
|
37
|
-
private registerHandler;
|
|
38
|
-
wrap<Output>(fn: (tx: this) => Promise<Output>): Promise<Output>;
|
|
39
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"root":["../src/builder.ts","../src/error.ts","../src/index.ts","../src/object-store.ts","../src/transaction.ts","../src/types.ts","../src/utils.ts","../src/client/compiled-query.ts","../src/client/delete.ts","../src/client/helpers.ts","../src/client/index.ts","../src/client/types/find.ts","../src/client/types/index.ts","../src/client/types/mutation.ts","../src/field/field-types.ts","../src/field/index.ts","../src/field/primary-key.ts","../src/field/property.ts","../src/field/relation.ts","../src/model/index.ts","../src/model/model-types.ts","../src/model/model.ts","../tests/helpers.ts","../tests/test.spec.ts"],"version":"5.9.3"}
|
package/dist/types/common.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts the string keys of an object
|
|
3
|
-
*/
|
|
4
|
-
export type Keyof<T extends Record<any, any>> = Extract<keyof T, string>;
|
|
5
|
-
export type Arrayable<T> = T | T[];
|
|
6
|
-
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
7
|
-
export type Promisable<T> = T | Promise<T>;
|
|
8
|
-
export type NoUndefined<T> = Exclude<T, undefined>;
|
|
9
|
-
export declare enum Type {
|
|
10
|
-
String = 0,
|
|
11
|
-
Number = 1,
|
|
12
|
-
BigInt = 2,
|
|
13
|
-
Boolean = 3,
|
|
14
|
-
Symbol = 4,
|
|
15
|
-
Array = 5,
|
|
16
|
-
Date = 6,
|
|
17
|
-
Object = 7,
|
|
18
|
-
Unknown = 8
|
|
19
|
-
}
|
|
20
|
-
export type MakeOptional<B extends boolean, T> = B extends true ? T | undefined : T;
|
|
21
|
-
export type MakeArray<B extends boolean, T> = B extends true ? T[] : T;
|
|
22
|
-
export type MakeArrayable<B extends boolean, T> = B extends true ? Arrayable<T> : T;
|
|
23
|
-
export type ValidKey = string | number | Date;
|
|
24
|
-
export type ValidKeyType = "string" | "number" | "date";
|
|
25
|
-
export type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
26
|
-
export type RemoveNeverValues<T extends object> = {
|
|
27
|
-
[K in keyof T as T[K] extends never ? never : K]: T[K];
|
|
28
|
-
};
|
|
29
|
-
export type Dict<T = unknown> = Record<string, T>;
|
|
30
|
-
export type ConnectionObject<M extends boolean = false, T = object, K = ValidKey> = {
|
|
31
|
-
$create: T;
|
|
32
|
-
$connect: K;
|
|
33
|
-
} & If<M, {
|
|
34
|
-
$createMany: T[];
|
|
35
|
-
$connectMany: K[];
|
|
36
|
-
}, Dict>;
|
|
37
|
-
type UndefinedKeys<T extends Dict> = {
|
|
38
|
-
[K in Keyof<T>]: undefined extends T[K] ? K : never;
|
|
39
|
-
}[Keyof<T>];
|
|
40
|
-
type Optional<T extends Dict> = Partial<Pick<T, UndefinedKeys<T>>>;
|
|
41
|
-
type Required<T extends Dict> = Omit<T, UndefinedKeys<T>>;
|
|
42
|
-
export type PartialOnUndefined<T extends Dict> = Required<T> & Optional<T>;
|
|
43
|
-
/**
|
|
44
|
-
* Types that can be resolved to specific boolean values
|
|
45
|
-
*/
|
|
46
|
-
export type BooleanLike = boolean | undefined | null | 0;
|
|
47
|
-
export type Literable = string | number | bigint | boolean | null | undefined;
|
|
48
|
-
export {};
|
package/dist/types.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts the string keys of an object
|
|
3
|
-
*/
|
|
4
|
-
export type Keyof<T extends Record<any, any>> = Extract<keyof T, string>;
|
|
5
|
-
export type Arrayable<T> = T | T[];
|
|
6
|
-
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
7
|
-
export type Promisable<T> = T | Promise<T>;
|
|
8
|
-
export type NoUndefined<T> = Exclude<T, undefined>;
|
|
9
|
-
export declare enum Type {
|
|
10
|
-
String = 0,
|
|
11
|
-
Number = 1,
|
|
12
|
-
BigInt = 2,
|
|
13
|
-
Boolean = 3,
|
|
14
|
-
Symbol = 4,
|
|
15
|
-
Array = 5,
|
|
16
|
-
Date = 6,
|
|
17
|
-
Object = 7,
|
|
18
|
-
Unknown = 8
|
|
19
|
-
}
|
|
20
|
-
export type MakeOptional<B extends boolean, T> = B extends true ? T | undefined : T;
|
|
21
|
-
export type MakeArray<B extends boolean, T> = B extends true ? T[] : T;
|
|
22
|
-
export type MakeArrayable<B extends boolean, T> = B extends true ? Arrayable<T> : T;
|
|
23
|
-
export type ValidKey = string | number | Date;
|
|
24
|
-
export type ValidKeyType = "string" | "number" | "date";
|
|
25
|
-
export type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
26
|
-
export type RemoveNeverValues<T extends object> = {
|
|
27
|
-
[K in keyof T as T[K] extends never ? never : K]: T[K];
|
|
28
|
-
};
|
|
29
|
-
export type Dict<T = unknown> = Record<string, T>;
|
|
30
|
-
export type ConnectionObject<M extends boolean = false, T = object, K = ValidKey> = {
|
|
31
|
-
$create: T;
|
|
32
|
-
$connect: K;
|
|
33
|
-
} & If<M, {
|
|
34
|
-
$createMany: T[];
|
|
35
|
-
$connectMany: K[];
|
|
36
|
-
}, Dict>;
|
|
37
|
-
type UndefinedKeys<T extends Dict> = {
|
|
38
|
-
[K in Keyof<T>]: undefined extends T[K] ? K : never;
|
|
39
|
-
}[Keyof<T>];
|
|
40
|
-
type Optional<T extends Dict> = Partial<Pick<T, UndefinedKeys<T>>>;
|
|
41
|
-
type Required<T extends Dict> = Omit<T, UndefinedKeys<T>>;
|
|
42
|
-
export type PartialOnUndefined<T extends Dict> = Required<T> & Optional<T>;
|
|
43
|
-
/**
|
|
44
|
-
* Types that can be resolved to specific boolean values
|
|
45
|
-
*/
|
|
46
|
-
export type BooleanLike = boolean | undefined | null | 0;
|
|
47
|
-
export type Literable = string | number | bigint | boolean | null | undefined;
|
|
48
|
-
export {};
|
package/dist/util-types.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts the string keys of an object
|
|
3
|
-
*/
|
|
4
|
-
export type Keyof<T extends Record<any, any>> = Extract<keyof T, string>;
|
|
5
|
-
export type Arrayable<T> = T | T[];
|
|
6
|
-
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
7
|
-
export type Promisable<T> = T | Promise<T>;
|
|
8
|
-
export type NoUndefined<T> = Exclude<T, undefined>;
|
|
9
|
-
export type MakeOptional<B extends boolean, T> = B extends true ? T | undefined : T;
|
|
10
|
-
export type MakeArray<B extends boolean, T> = B extends true ? T[] : T;
|
|
11
|
-
export type MakeArrayable<B extends boolean, T> = B extends true ? Arrayable<T> : T;
|
|
12
|
-
export type ValidKey = string | number | Date;
|
|
13
|
-
export type ValidKeyType = "string" | "number" | "date";
|
|
14
|
-
export type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
15
|
-
export type RemoveNeverValues<T extends object> = {
|
|
16
|
-
[K in keyof T as T[K] extends never ? never : K]: T[K];
|
|
17
|
-
};
|
|
18
|
-
export type Dict<T = unknown> = Record<string, T>;
|
|
19
|
-
export type ConnectionObject<M extends boolean = false, T = object, K = ValidKey> = {
|
|
20
|
-
$create: T;
|
|
21
|
-
$connect: K;
|
|
22
|
-
} & If<M, {
|
|
23
|
-
$createMany: T[];
|
|
24
|
-
$connectMany: K[];
|
|
25
|
-
}, Dict>;
|
|
26
|
-
type UndefinedKeys<T extends Dict> = {
|
|
27
|
-
[K in Keyof<T>]: undefined extends T[K] ? K : never;
|
|
28
|
-
}[Keyof<T>];
|
|
29
|
-
type Optional<T extends Dict> = Partial<Pick<T, UndefinedKeys<T>>>;
|
|
30
|
-
type Required<T extends Dict> = Omit<T, UndefinedKeys<T>>;
|
|
31
|
-
export type PartialOnUndefined<T extends Dict> = Required<T> & Optional<T>;
|
|
32
|
-
/**
|
|
33
|
-
* Types that can be resolved to specific boolean values
|
|
34
|
-
*/
|
|
35
|
-
export type BooleanLike = boolean | undefined | null | 0;
|
|
36
|
-
export type Literable = string | number | bigint | boolean | null | undefined;
|
|
37
|
-
export {};
|
package/dist/utils.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Arrayable, Keyof, ValidKeyType } from "./util-types";
|
|
2
|
-
import type { Transaction } from "./transaction.js";
|
|
3
|
-
export declare function handleRequest<T>(req: IDBRequest<T>, tx?: Transaction<any, any>): Promise<T>;
|
|
4
|
-
export declare function getKeys<T extends object>(obj: T): Keyof<T>[];
|
|
5
|
-
export declare function addToSet<T>(set: Set<T>, items: T[]): Set<T>;
|
|
6
|
-
export declare function toArray<T>(value: Arrayable<T>): T[];
|
|
7
|
-
export declare function stringTypeToEnum(type: ValidKeyType): Type;
|
|
8
|
-
export declare function uuid(): `${string}-${string}-${string}-${string}-${string}`;
|
|
9
|
-
/**
|
|
10
|
-
* Identity Function, it returns the first argument it is given, all others are ignored
|
|
11
|
-
* @param value Value
|
|
12
|
-
* @returns Same Value
|
|
13
|
-
*/
|
|
14
|
-
export declare function identity<T>(value: T): T;
|
|
15
|
-
/**
|
|
16
|
-
* Performs a union over `set1` and `set2`, modifying `set1` to be union of the two sets
|
|
17
|
-
*/
|
|
18
|
-
export declare function unionSets<T>(set: Set<T>, other: Set<T>): Set<T>;
|
|
19
|
-
export declare enum Type {
|
|
20
|
-
String = 0,
|
|
21
|
-
Number = 1,
|
|
22
|
-
BigInt = 2,
|
|
23
|
-
Boolean = 3,
|
|
24
|
-
Symbol = 4,
|
|
25
|
-
Array = 5,
|
|
26
|
-
Date = 6,
|
|
27
|
-
Object = 7,
|
|
28
|
-
Unknown = 8
|
|
29
|
-
}
|