@kitledger/core 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/entities.d.ts +32 -3
- package/dist/entities.js +7 -1
- package/dist/fields.d.ts +77 -32
- package/dist/fields.js +20 -2
- package/dist/transactions.d.ts +23 -15
- package/dist/transactions.js +2 -1
- package/dist/units.d.ts +41 -0
- package/dist/units.js +14 -0
- package/package.json +11 -4
package/dist/entities.d.ts
CHANGED
|
@@ -1,12 +1,41 @@
|
|
|
1
|
+
import type { Field } from "./fields.js";
|
|
1
2
|
export declare enum EntityModelStatus {
|
|
2
3
|
ACTIVE = 0,
|
|
3
4
|
INACTIVE = 1
|
|
4
5
|
}
|
|
5
|
-
export type
|
|
6
|
+
export type InferEntityMetaType<TFields extends readonly Field[]> = {
|
|
7
|
+
[K in TFields[number] as K["ref_id"]]: K["__primitive_type"];
|
|
8
|
+
};
|
|
9
|
+
export type Entity<TData = Record<string, any>> = {
|
|
10
|
+
id: string;
|
|
11
|
+
model_ref_id: string;
|
|
12
|
+
created_at: Date;
|
|
13
|
+
updated_at: Date;
|
|
14
|
+
data: TData;
|
|
15
|
+
};
|
|
16
|
+
export type EntityHook<TData> = (entity: Entity<TData>) => Promise<Entity<TData>>;
|
|
17
|
+
export type EntityHooks<TData = Record<string, any>> = {
|
|
18
|
+
creating?: EntityHook<TData>[];
|
|
19
|
+
updating?: EntityHook<TData>[];
|
|
20
|
+
deleting?: EntityHook<TData>[];
|
|
21
|
+
created?: EntityHook<TData>[];
|
|
22
|
+
updated?: EntityHook<TData>[];
|
|
23
|
+
deleted?: EntityHook<TData>[];
|
|
24
|
+
};
|
|
25
|
+
export type EntityModel = {
|
|
26
|
+
ref_id: string;
|
|
27
|
+
alt_id?: string;
|
|
28
|
+
name: string;
|
|
29
|
+
status: EntityModelStatus;
|
|
30
|
+
fields?: Field[];
|
|
31
|
+
hooks?: EntityHooks<any>;
|
|
32
|
+
};
|
|
33
|
+
export type EntityModelOptions<TFields extends readonly Field[]> = {
|
|
6
34
|
ref_id: string;
|
|
7
35
|
alt_id?: string;
|
|
8
36
|
name: string;
|
|
9
37
|
status?: EntityModelStatus;
|
|
38
|
+
fields?: TFields;
|
|
39
|
+
hooks?: EntityHooks<InferEntityMetaType<TFields>>;
|
|
10
40
|
};
|
|
11
|
-
export
|
|
12
|
-
export declare function defineEntityModel(options: EntityModelOptions): EntityModelOptions;
|
|
41
|
+
export declare function defineEntityModel<const TFields extends readonly Field[]>(options: EntityModelOptions<TFields>): EntityModel;
|
package/dist/entities.js
CHANGED
|
@@ -4,5 +4,11 @@ export var EntityModelStatus;
|
|
|
4
4
|
EntityModelStatus[EntityModelStatus["INACTIVE"] = 1] = "INACTIVE";
|
|
5
5
|
})(EntityModelStatus || (EntityModelStatus = {}));
|
|
6
6
|
export function defineEntityModel(options) {
|
|
7
|
-
|
|
7
|
+
const entityModel = {
|
|
8
|
+
...options,
|
|
9
|
+
status: options.status ?? EntityModelStatus.ACTIVE,
|
|
10
|
+
fields: options.fields,
|
|
11
|
+
hooks: options.hooks,
|
|
12
|
+
};
|
|
13
|
+
return entityModel;
|
|
8
14
|
}
|
package/dist/fields.d.ts
CHANGED
|
@@ -8,16 +8,15 @@ export declare enum FieldType {
|
|
|
8
8
|
RELATION = "relation"
|
|
9
9
|
}
|
|
10
10
|
interface BaseField {
|
|
11
|
-
ref_id: string;
|
|
11
|
+
readonly ref_id: string;
|
|
12
12
|
name: string;
|
|
13
13
|
description?: string;
|
|
14
14
|
}
|
|
15
15
|
export interface TextField extends BaseField {
|
|
16
16
|
type: FieldType.TEXT;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
17
|
+
readonly __primitive_type?: string;
|
|
18
|
+
maxLength?: number;
|
|
19
|
+
format?: "email" | "plain" | "rich_text";
|
|
21
20
|
}
|
|
22
21
|
export type NumberFormatting = {
|
|
23
22
|
style: "integer";
|
|
@@ -30,42 +29,88 @@ export type NumberFormatting = {
|
|
|
30
29
|
};
|
|
31
30
|
export interface NumberField extends BaseField {
|
|
32
31
|
type: FieldType.NUMBER;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
32
|
+
readonly __primitive_type?: number;
|
|
33
|
+
min?: number;
|
|
34
|
+
max?: number;
|
|
35
|
+
formatting: NumberFormatting;
|
|
38
36
|
}
|
|
39
37
|
export interface DateField extends BaseField {
|
|
40
38
|
type: FieldType.DATE;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
readonly __primitive_type?: Date;
|
|
40
|
+
includeTime: boolean;
|
|
41
|
+
formatStr: string;
|
|
42
|
+
}
|
|
43
|
+
export interface BooleanField extends BaseField {
|
|
44
|
+
type: FieldType.BOOLEAN;
|
|
45
|
+
readonly __primitive_type?: boolean;
|
|
46
|
+
defaultValue?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface URLField extends BaseField {
|
|
49
|
+
type: FieldType.URL;
|
|
50
|
+
readonly __primitive_type?: string;
|
|
51
|
+
defaultValue?: string;
|
|
45
52
|
}
|
|
46
53
|
export type QueryConfig = {};
|
|
47
54
|
export interface SelectField extends BaseField {
|
|
48
55
|
type: FieldType.SELECT;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
};
|
|
56
|
+
readonly __primitive_type?: string | number | (string | number)[];
|
|
57
|
+
multiSelect: boolean;
|
|
58
|
+
items: Array<{
|
|
59
|
+
label: string;
|
|
60
|
+
value: string | number;
|
|
61
|
+
color?: string;
|
|
62
|
+
}>;
|
|
63
|
+
defaultValue?: string | number | Array<string | number>;
|
|
58
64
|
}
|
|
59
65
|
export interface RelationField extends BaseField {
|
|
60
66
|
type: FieldType.RELATION;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
67
|
+
readonly __primitive_type?: any;
|
|
68
|
+
multiSelect: boolean;
|
|
69
|
+
targetEntityId: string;
|
|
70
|
+
displayFieldId: string;
|
|
71
|
+
query: QueryConfig;
|
|
67
72
|
}
|
|
68
|
-
export type Field = TextField | NumberField | DateField | SelectField | RelationField;
|
|
69
|
-
export type
|
|
70
|
-
export
|
|
73
|
+
export type Field = TextField | NumberField | DateField | BooleanField | URLField | SelectField | RelationField;
|
|
74
|
+
export type TextFieldOptions = Omit<TextField, "type" | "__primitive_type" | "ref_id">;
|
|
75
|
+
export type NumberFieldOptions = Omit<NumberField, "type" | "__primitive_type" | "ref_id">;
|
|
76
|
+
export type DateFieldOptions = Omit<DateField, "type" | "__primitive_type" | "ref_id">;
|
|
77
|
+
export type BooleanFieldOptions = Omit<BooleanField, "type" | "__primitive_type" | "ref_id">;
|
|
78
|
+
export type URLFieldOptions = Omit<URLField, "type" | "__primitive_type" | "ref_id">;
|
|
79
|
+
export type SelectFieldOptions = Omit<SelectField, "type" | "__primitive_type" | "ref_id">;
|
|
80
|
+
export type RelationFieldOptions = Omit<RelationField, "type" | "__primitive_type" | "ref_id">;
|
|
81
|
+
export declare function defineTextField<const T extends string>(options: TextFieldOptions & {
|
|
82
|
+
ref_id: T;
|
|
83
|
+
}): TextField & {
|
|
84
|
+
ref_id: T;
|
|
85
|
+
};
|
|
86
|
+
export declare function defineNumberField<const T extends string>(options: NumberFieldOptions & {
|
|
87
|
+
ref_id: T;
|
|
88
|
+
}): NumberField & {
|
|
89
|
+
ref_id: T;
|
|
90
|
+
};
|
|
91
|
+
export declare function defineDateField<const T extends string>(options: DateFieldOptions & {
|
|
92
|
+
ref_id: T;
|
|
93
|
+
}): DateField & {
|
|
94
|
+
ref_id: T;
|
|
95
|
+
};
|
|
96
|
+
export declare function defineBooleanField<const T extends string>(options: BooleanFieldOptions & {
|
|
97
|
+
ref_id: T;
|
|
98
|
+
}): BooleanField & {
|
|
99
|
+
ref_id: T;
|
|
100
|
+
};
|
|
101
|
+
export declare function defineURLField<const T extends string>(options: URLFieldOptions & {
|
|
102
|
+
ref_id: T;
|
|
103
|
+
}): URLField & {
|
|
104
|
+
ref_id: T;
|
|
105
|
+
};
|
|
106
|
+
export declare function defineSelectField<const T extends string>(options: SelectFieldOptions & {
|
|
107
|
+
ref_id: T;
|
|
108
|
+
}): SelectField & {
|
|
109
|
+
ref_id: T;
|
|
110
|
+
};
|
|
111
|
+
export declare function defineRelationField<const T extends string>(options: RelationFieldOptions & {
|
|
112
|
+
ref_id: T;
|
|
113
|
+
}): RelationField & {
|
|
114
|
+
ref_id: T;
|
|
115
|
+
};
|
|
71
116
|
export {};
|
package/dist/fields.js
CHANGED
|
@@ -8,6 +8,24 @@ export var FieldType;
|
|
|
8
8
|
FieldType["SELECT"] = "select";
|
|
9
9
|
FieldType["RELATION"] = "relation";
|
|
10
10
|
})(FieldType || (FieldType = {}));
|
|
11
|
-
export function
|
|
12
|
-
return options;
|
|
11
|
+
export function defineTextField(options) {
|
|
12
|
+
return { type: FieldType.TEXT, ...options };
|
|
13
|
+
}
|
|
14
|
+
export function defineNumberField(options) {
|
|
15
|
+
return { type: FieldType.NUMBER, ...options };
|
|
16
|
+
}
|
|
17
|
+
export function defineDateField(options) {
|
|
18
|
+
return { type: FieldType.DATE, ...options };
|
|
19
|
+
}
|
|
20
|
+
export function defineBooleanField(options) {
|
|
21
|
+
return { type: FieldType.BOOLEAN, ...options };
|
|
22
|
+
}
|
|
23
|
+
export function defineURLField(options) {
|
|
24
|
+
return { type: FieldType.URL, ...options };
|
|
25
|
+
}
|
|
26
|
+
export function defineSelectField(options) {
|
|
27
|
+
return { type: FieldType.SELECT, ...options };
|
|
28
|
+
}
|
|
29
|
+
export function defineRelationField(options) {
|
|
30
|
+
return { type: FieldType.RELATION, ...options };
|
|
13
31
|
}
|
package/dist/transactions.d.ts
CHANGED
|
@@ -1,33 +1,41 @@
|
|
|
1
|
+
import type { Field } from "./fields.js";
|
|
1
2
|
export declare enum TransactionModelStatus {
|
|
2
3
|
ACTIVE = 0,
|
|
3
|
-
INACTIVE = 1
|
|
4
|
-
FROZEN = 2
|
|
4
|
+
INACTIVE = 1
|
|
5
5
|
}
|
|
6
|
-
export type
|
|
6
|
+
export type InferTransactionMetaType<TFields extends readonly Field[]> = {
|
|
7
|
+
[K in TFields[number] as K["ref_id"]]: K["__primitive_type"];
|
|
8
|
+
};
|
|
9
|
+
export type Transaction<TData = Record<string, any>> = {
|
|
7
10
|
id: string;
|
|
8
11
|
model_ref_id: string;
|
|
9
12
|
created_at: Date;
|
|
10
13
|
updated_at: Date;
|
|
11
|
-
data:
|
|
14
|
+
data: TData;
|
|
15
|
+
};
|
|
16
|
+
export type TransactionHook<TData> = (transaction: Transaction<TData>) => Promise<Transaction<TData>>;
|
|
17
|
+
export type TransactionHooks<TData = Record<string, any>> = {
|
|
18
|
+
creating?: TransactionHook<TData>[];
|
|
19
|
+
updating?: TransactionHook<TData>[];
|
|
20
|
+
deleting?: TransactionHook<TData>[];
|
|
21
|
+
created?: TransactionHook<TData>[];
|
|
22
|
+
updated?: TransactionHook<TData>[];
|
|
23
|
+
deleted?: TransactionHook<TData>[];
|
|
12
24
|
};
|
|
13
|
-
export type
|
|
14
|
-
export type TransactionListener<T> = (transaction: Readonly<Transaction<T>>) => Promise<void>;
|
|
15
|
-
export type TransactionModel<T = Record<string, any>> = {
|
|
25
|
+
export type TransactionModel = {
|
|
16
26
|
ref_id: string;
|
|
17
27
|
alt_id?: string;
|
|
18
28
|
name: string;
|
|
19
29
|
status: TransactionModelStatus;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
updating?: TransactionPipe<T>[];
|
|
23
|
-
created?: TransactionListener<T>[];
|
|
24
|
-
updated?: TransactionListener<T>[];
|
|
25
|
-
};
|
|
30
|
+
fields?: Field[];
|
|
31
|
+
hooks?: TransactionHooks<any>;
|
|
26
32
|
};
|
|
27
|
-
export type TransactionModelOptions = {
|
|
33
|
+
export type TransactionModelOptions<TFields extends readonly Field[]> = {
|
|
28
34
|
ref_id: string;
|
|
29
35
|
alt_id?: string;
|
|
30
36
|
name: string;
|
|
31
37
|
status?: TransactionModelStatus;
|
|
38
|
+
fields?: TFields;
|
|
39
|
+
hooks?: TransactionHooks<InferTransactionMetaType<TFields>>;
|
|
32
40
|
};
|
|
33
|
-
export declare function defineTransactionModel(options: TransactionModelOptions): TransactionModel;
|
|
41
|
+
export declare function defineTransactionModel<const TFields extends readonly Field[]>(options: TransactionModelOptions<TFields>): TransactionModel;
|
package/dist/transactions.js
CHANGED
|
@@ -2,12 +2,13 @@ export var TransactionModelStatus;
|
|
|
2
2
|
(function (TransactionModelStatus) {
|
|
3
3
|
TransactionModelStatus[TransactionModelStatus["ACTIVE"] = 0] = "ACTIVE";
|
|
4
4
|
TransactionModelStatus[TransactionModelStatus["INACTIVE"] = 1] = "INACTIVE";
|
|
5
|
-
TransactionModelStatus[TransactionModelStatus["FROZEN"] = 2] = "FROZEN";
|
|
6
5
|
})(TransactionModelStatus || (TransactionModelStatus = {}));
|
|
7
6
|
export function defineTransactionModel(options) {
|
|
8
7
|
const transactionModel = {
|
|
9
8
|
...options,
|
|
10
9
|
status: options.status ?? TransactionModelStatus.ACTIVE,
|
|
10
|
+
fields: options.fields,
|
|
11
|
+
hooks: options.hooks,
|
|
11
12
|
};
|
|
12
13
|
return transactionModel;
|
|
13
14
|
}
|
package/dist/units.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Field } from "./fields.js";
|
|
2
|
+
export declare enum UnitModelStatus {
|
|
3
|
+
ACTIVE = 0,
|
|
4
|
+
INACTIVE = 1
|
|
5
|
+
}
|
|
6
|
+
export type InferUnitMetaType<TFields extends readonly Field[]> = {
|
|
7
|
+
[K in TFields[number] as K["ref_id"]]: K["__primitive_type"];
|
|
8
|
+
};
|
|
9
|
+
export type Unit<TData = Record<string, any>> = {
|
|
10
|
+
id: string;
|
|
11
|
+
model_ref_id: string;
|
|
12
|
+
created_at: Date;
|
|
13
|
+
updated_at: Date;
|
|
14
|
+
data: TData;
|
|
15
|
+
};
|
|
16
|
+
export type UnitHook<TData> = (unit: Unit<TData>) => Promise<Unit<TData>>;
|
|
17
|
+
export type UnitHooks<TData = Record<string, any>> = {
|
|
18
|
+
creating?: UnitHook<TData>[];
|
|
19
|
+
updating?: UnitHook<TData>[];
|
|
20
|
+
deleting?: UnitHook<TData>[];
|
|
21
|
+
created?: UnitHook<TData>[];
|
|
22
|
+
updated?: UnitHook<TData>[];
|
|
23
|
+
deleted?: UnitHook<TData>[];
|
|
24
|
+
};
|
|
25
|
+
export type UnitModel = {
|
|
26
|
+
ref_id: string;
|
|
27
|
+
alt_id?: string;
|
|
28
|
+
name: string;
|
|
29
|
+
status: UnitModelStatus;
|
|
30
|
+
fields?: Field[];
|
|
31
|
+
hooks?: UnitHooks<any>;
|
|
32
|
+
};
|
|
33
|
+
export type UnitModelOptions<TFields extends readonly Field[]> = {
|
|
34
|
+
ref_id: string;
|
|
35
|
+
alt_id?: string;
|
|
36
|
+
name: string;
|
|
37
|
+
status?: UnitModelStatus;
|
|
38
|
+
fields?: TFields;
|
|
39
|
+
hooks?: UnitHooks<InferUnitMetaType<TFields>>;
|
|
40
|
+
};
|
|
41
|
+
export declare function defineUnitModel<const TFields extends readonly Field[]>(options: UnitModelOptions<TFields>): UnitModel;
|
package/dist/units.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export var UnitModelStatus;
|
|
2
|
+
(function (UnitModelStatus) {
|
|
3
|
+
UnitModelStatus[UnitModelStatus["ACTIVE"] = 0] = "ACTIVE";
|
|
4
|
+
UnitModelStatus[UnitModelStatus["INACTIVE"] = 1] = "INACTIVE";
|
|
5
|
+
})(UnitModelStatus || (UnitModelStatus = {}));
|
|
6
|
+
export function defineUnitModel(options) {
|
|
7
|
+
const unitModel = {
|
|
8
|
+
...options,
|
|
9
|
+
status: options.status ?? UnitModelStatus.ACTIVE,
|
|
10
|
+
fields: options.fields,
|
|
11
|
+
hooks: options.hooks,
|
|
12
|
+
};
|
|
13
|
+
return unitModel;
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitledger/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"types": "./dist/entities.d.ts",
|
|
14
14
|
"default": "./dist/entities.js"
|
|
15
15
|
},
|
|
16
|
+
"./fields": {
|
|
17
|
+
"types": "./dist/fields.d.ts",
|
|
18
|
+
"default": "./dist/fields.js"
|
|
19
|
+
},
|
|
16
20
|
"./transactions": {
|
|
17
21
|
"types": "./dist/transactions.d.ts",
|
|
18
22
|
"default": "./dist/transactions.js"
|
|
@@ -20,9 +24,14 @@
|
|
|
20
24
|
"./ui": {
|
|
21
25
|
"types": "./dist/ui.d.ts",
|
|
22
26
|
"default": "./dist/ui.js"
|
|
27
|
+
},
|
|
28
|
+
"./units": {
|
|
29
|
+
"types": "./dist/units.d.ts",
|
|
30
|
+
"default": "./dist/units.js"
|
|
23
31
|
}
|
|
24
32
|
},
|
|
25
33
|
"files": [
|
|
34
|
+
"!dist/**/*.test.js",
|
|
26
35
|
"dist"
|
|
27
36
|
],
|
|
28
37
|
"dependencies": {
|
|
@@ -33,15 +42,13 @@
|
|
|
33
42
|
"pg": "^8.16.3",
|
|
34
43
|
"postgres": "^3.4.7",
|
|
35
44
|
"uuid": "^13.0.0",
|
|
45
|
+
"valibot": "^1.1.0",
|
|
36
46
|
"@kitledger/query": "0.0.15"
|
|
37
47
|
},
|
|
38
48
|
"devDependencies": {
|
|
39
49
|
"@faker-js/faker": "^10.1.0",
|
|
40
50
|
"drizzle-kit": "^0.31.8"
|
|
41
51
|
},
|
|
42
|
-
"peerDependencies": {
|
|
43
|
-
"valibot": "^1.1.0"
|
|
44
|
-
},
|
|
45
52
|
"publishConfig": {
|
|
46
53
|
"access": "public"
|
|
47
54
|
},
|