@idb-orm/core 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/client/compiled-query.d.ts +4 -14
- package/dist/client/delete.d.ts +14 -0
- package/dist/client/helpers.d.ts +1 -2
- package/dist/client/index.d.ts +4 -32
- package/dist/client/types/find.d.ts +15 -99
- package/dist/client/types/index.d.ts +41 -77
- package/dist/client/types/mutation.d.ts +41 -220
- package/dist/field/property.d.ts +70 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/model-types.d.ts +24 -111
- package/dist/model/model.d.ts +5 -23
- package/dist/object-store.d.ts +1 -2
- package/dist/transaction.d.ts +11 -22
- package/dist/types/common.d.ts +4 -1
- package/dist/utils.d.ts +1 -2
- package/package.json +1 -1
- package/eslint.config.js +0 -55
- package/playwright.config.ts +0 -79
- package/tests/helpers.ts +0 -72
- package/tests/test.spec.ts +0 -101
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Literable, ValidKeyType } from "../types/common.js";
|
|
2
|
+
import { FunctionMatch, ReferenceActions, RelationOptions } from "./field-types.js";
|
|
3
|
+
import PrimaryKey from "./primary-key.js";
|
|
4
|
+
import { Relation } from "./relation.js";
|
|
5
|
+
export interface PropertyOptions {
|
|
6
|
+
unique: boolean;
|
|
7
|
+
}
|
|
8
|
+
type InputOptions = Partial<PropertyOptions>;
|
|
9
|
+
declare enum PropertType {
|
|
10
|
+
String = 0,
|
|
11
|
+
Number = 1,
|
|
12
|
+
BigInt = 2,
|
|
13
|
+
Boolean = 3,
|
|
14
|
+
Symbol = 4,
|
|
15
|
+
Array = 5,
|
|
16
|
+
Object = 6,
|
|
17
|
+
Unknown = 7
|
|
18
|
+
}
|
|
19
|
+
export type ParseResult<T> = {
|
|
20
|
+
success: true;
|
|
21
|
+
data: T;
|
|
22
|
+
error?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
success: false;
|
|
25
|
+
data?: undefined;
|
|
26
|
+
error: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A function to parse and validate an unknown value. It should also handle applying defaults
|
|
30
|
+
*/
|
|
31
|
+
export type ParseFn<T> = (value: unknown) => ParseResult<T>;
|
|
32
|
+
export declare abstract class AbstractProperty<Value, HasDefault extends boolean> {
|
|
33
|
+
readonly validate: (value: unknown) => ParseResult<Value>;
|
|
34
|
+
protected type: PropertType;
|
|
35
|
+
protected hasDefault: HasDefault;
|
|
36
|
+
protected options: PropertyOptions;
|
|
37
|
+
constructor(validate: (value: unknown) => ParseResult<Value>, type: PropertType, options?: InputOptions);
|
|
38
|
+
abstract array(...args: unknown[]): AbstractProperty<Value[], false>;
|
|
39
|
+
abstract optional(...args: unknown[]): AbstractProperty<Value | undefined, false>;
|
|
40
|
+
abstract default(defaultValue: Value): AbstractProperty<NonNullable<Value>, true>;
|
|
41
|
+
static array<T>(_prop: AbstractProperty<T, boolean> | ParseFn<T>, _options?: InputOptions): AbstractProperty<T[], false>;
|
|
42
|
+
static literal<const V extends Literable>(_value: V, _options?: InputOptions): AbstractProperty<V, false>;
|
|
43
|
+
static custom<T>(_fn: ParseFn<T>, _options?: InputOptions): AbstractProperty<T, false>;
|
|
44
|
+
static string(_options?: InputOptions): AbstractProperty<string, false>;
|
|
45
|
+
static number(_options?: InputOptions): AbstractProperty<number, false>;
|
|
46
|
+
static boolean(_options?: InputOptions): AbstractProperty<boolean, false>;
|
|
47
|
+
/**
|
|
48
|
+
* Indicates that a field must be unique across all documents
|
|
49
|
+
*
|
|
50
|
+
* **NOTE**: The field type must be a primitive. If this is applied to a non-primitive, it returns `null`
|
|
51
|
+
*/
|
|
52
|
+
unique(): Value extends string | number | boolean | symbol ? this : null;
|
|
53
|
+
hasDefaultValue(): HasDefault;
|
|
54
|
+
static relation<To extends string, Name extends string = never>(to: To, options?: RelationOptions<Name, ReferenceActions>): Relation<To, Name>;
|
|
55
|
+
static primaryKey<V extends ValidKeyType = "number">(type?: V): PrimaryKey<false, FunctionMatch<V>>;
|
|
56
|
+
}
|
|
57
|
+
export declare class Property<Value, HasDefault extends boolean> extends AbstractProperty<Value, HasDefault> {
|
|
58
|
+
array(): Property<Value[], false>;
|
|
59
|
+
default(defaultValue: NonNullable<Value>): Property<NonNullable<Value>, true>;
|
|
60
|
+
optional(): Property<Value | undefined, false>;
|
|
61
|
+
static literal<const V extends Literable>(value: V, options?: InputOptions): Property<V, false>;
|
|
62
|
+
static string(options?: InputOptions): Property<string, false>;
|
|
63
|
+
static number(options?: InputOptions): Property<number, false>;
|
|
64
|
+
static boolean(options?: InputOptions): Property<boolean, false>;
|
|
65
|
+
static custom<T>(fn: ParseFn<T>, options?: InputOptions): Property<T, false>;
|
|
66
|
+
static array<T>(item: ParseFn<T> | Property<T, boolean>, options?: InputOptions): Property<T[], false>;
|
|
67
|
+
private static literalToType;
|
|
68
|
+
private static generateArrayValidator;
|
|
69
|
+
}
|
|
70
|
+
export {};
|