@kitledger/core 0.0.8 → 0.0.9
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/accounts.d.ts +4 -3
- package/dist/accounts.js +10 -13
- package/dist/art.d.ts +5 -0
- package/dist/art.js +5 -0
- package/dist/db.d.ts +34 -2
- package/dist/db.js +26 -2
- package/dist/entities.d.ts +47 -0
- package/dist/entities.js +13 -0
- package/dist/factories.d.ts +0 -4
- package/dist/factories.js +0 -15
- package/dist/fields.d.ts +116 -0
- package/dist/fields.js +62 -0
- package/dist/forms.d.ts +63 -0
- package/dist/forms.js +33 -0
- package/dist/ledgers.d.ts +39 -22
- package/dist/ledgers.js +14 -141
- package/dist/main.d.ts +20 -3
- package/dist/main.js +6 -0
- package/dist/migrations/0003_familiar_lila_cheney.sql +9 -0
- package/dist/migrations/0004_magenta_hairball.sql +1 -0
- package/dist/migrations/meta/0003_snapshot.json +694 -0
- package/dist/migrations/meta/0004_snapshot.json +694 -0
- package/dist/migrations/meta/_journal.json +40 -26
- package/dist/schema.d.ts +5 -154
- package/dist/schema.js +1 -10
- package/dist/transactions.d.ts +40 -0
- package/dist/transactions.js +12 -0
- package/dist/ui.d.ts +16 -0
- package/dist/ui.js +6 -0
- package/dist/units.d.ts +46 -0
- package/dist/units.js +12 -0
- package/package.json +7 -1
package/dist/accounts.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as v from "valibot";
|
|
|
3
3
|
import { InferOutput } from "valibot";
|
|
4
4
|
import { KitledgerDb } from "./db.js";
|
|
5
5
|
import { FilterOperationParameters, GetOperationResult } from "./db.js";
|
|
6
|
+
import { Ledger } from "./ledgers.js";
|
|
6
7
|
import { accounts } from "./schema.js";
|
|
7
8
|
import { ValidationFailure, ValidationSuccess } from "./validation.js";
|
|
8
9
|
export declare enum BalanceType {
|
|
@@ -29,7 +30,7 @@ export type AccountCreateData = InferOutput<typeof AccountCreateSchema>;
|
|
|
29
30
|
* @param params
|
|
30
31
|
* @returns
|
|
31
32
|
*/
|
|
32
|
-
export declare function filterAccounts(db: KitledgerDb, params: FilterOperationParameters): Promise<GetOperationResult<Account>>;
|
|
33
|
+
export declare function filterAccounts(db: KitledgerDb, ledgers: Ledger[], params: FilterOperationParameters): Promise<GetOperationResult<Account>>;
|
|
33
34
|
/**
|
|
34
35
|
* Finds the parent account by ID or ref_id or alt_id.
|
|
35
36
|
* Returns the ID of the parent account if found, otherwise returns null.
|
|
@@ -40,5 +41,5 @@ export declare function findParentAccount(db: KitledgerDb, parentId: string, led
|
|
|
40
41
|
* @param ledgerId
|
|
41
42
|
* @returns
|
|
42
43
|
*/
|
|
43
|
-
export declare function findLedgerId(
|
|
44
|
-
export declare function createAccount(db: KitledgerDb, data: AccountCreateData): Promise<ValidationSuccess<Account> | ValidationFailure<AccountCreateData>>;
|
|
44
|
+
export declare function findLedgerId(ledgers: Ledger[], ledgerId: string): Promise<string | null>;
|
|
45
|
+
export declare function createAccount(db: KitledgerDb, ledgers: Ledger[], data: AccountCreateData): Promise<ValidationSuccess<Account> | ValidationFailure<AccountCreateData>>;
|
package/dist/accounts.js
CHANGED
|
@@ -2,7 +2,7 @@ import { and, eq, or, sql } from "drizzle-orm";
|
|
|
2
2
|
import { v7 } from "uuid";
|
|
3
3
|
import * as v from "valibot";
|
|
4
4
|
import { ANY, defaultLimit, defaultOffset, maxLimit, parseBooleanFilterValue, } from "./db.js";
|
|
5
|
-
import { accounts
|
|
5
|
+
import { accounts } from "./schema.js";
|
|
6
6
|
import { parseValibotIssues, } from "./validation.js";
|
|
7
7
|
export var BalanceType;
|
|
8
8
|
(function (BalanceType) {
|
|
@@ -26,7 +26,7 @@ export const AccountCreateSchema = v.object({
|
|
|
26
26
|
* @param params
|
|
27
27
|
* @returns
|
|
28
28
|
*/
|
|
29
|
-
export async function filterAccounts(db, params) {
|
|
29
|
+
export async function filterAccounts(db, ledgers, params) {
|
|
30
30
|
const { limit = defaultLimit, offset = defaultOffset, ...filters } = params;
|
|
31
31
|
const filterConditions = [];
|
|
32
32
|
let ledgerId = null;
|
|
@@ -47,7 +47,7 @@ export async function filterAccounts(db, params) {
|
|
|
47
47
|
filterConditions.push(sql `${accounts.name} ILIKE ${"%" + String(value) + "%"}`);
|
|
48
48
|
}
|
|
49
49
|
if (key === accounts.ledger_id.name && String(value).length > 0) {
|
|
50
|
-
ledgerId = await findLedgerId(
|
|
50
|
+
ledgerId = await findLedgerId(ledgers, String(value));
|
|
51
51
|
if (ledgerId) {
|
|
52
52
|
filterConditions.push(eq(accounts.ledger_id, ledgerId));
|
|
53
53
|
}
|
|
@@ -106,12 +106,9 @@ export async function findParentAccount(db, parentId, ledgerId) {
|
|
|
106
106
|
* @param ledgerId
|
|
107
107
|
* @returns
|
|
108
108
|
*/
|
|
109
|
-
export async function findLedgerId(
|
|
110
|
-
const ledger =
|
|
111
|
-
|
|
112
|
-
columns: { id: true },
|
|
113
|
-
});
|
|
114
|
-
return ledger ? ledger.id : null;
|
|
109
|
+
export async function findLedgerId(ledgers, ledgerId) {
|
|
110
|
+
const ledger = ledgers.find((l) => l.refId === ledgerId);
|
|
111
|
+
return ledger ? ledger.refId : null;
|
|
115
112
|
}
|
|
116
113
|
// ACTIONS
|
|
117
114
|
async function refIdAlreadyExists(db, refId) {
|
|
@@ -131,7 +128,7 @@ async function altIdAlreadyExists(db, altId) {
|
|
|
131
128
|
});
|
|
132
129
|
return results.length > 0;
|
|
133
130
|
}
|
|
134
|
-
async function validateAccountCreate(db, data) {
|
|
131
|
+
async function validateAccountCreate(db, ledgers, data) {
|
|
135
132
|
const result = v.safeParse(AccountCreateSchema, data);
|
|
136
133
|
let success = result.success;
|
|
137
134
|
if (!result.success) {
|
|
@@ -141,7 +138,7 @@ async function validateAccountCreate(db, data) {
|
|
|
141
138
|
const [refIdError, altIdError, ledgerId] = await Promise.all([
|
|
142
139
|
refIdAlreadyExists(db, result.output.ref_id),
|
|
143
140
|
altIdAlreadyExists(db, result.output.alt_id ?? null),
|
|
144
|
-
findLedgerId(
|
|
141
|
+
findLedgerId(ledgers, result.output.ledger_id),
|
|
145
142
|
]);
|
|
146
143
|
if (refIdError) {
|
|
147
144
|
success = false;
|
|
@@ -187,8 +184,8 @@ async function validateAccountCreate(db, data) {
|
|
|
187
184
|
}
|
|
188
185
|
return { success, data: result.output, errors: errors };
|
|
189
186
|
}
|
|
190
|
-
export async function createAccount(db, data) {
|
|
191
|
-
const validation = await validateAccountCreate(db, data);
|
|
187
|
+
export async function createAccount(db, ledgers, data) {
|
|
188
|
+
const validation = await validateAccountCreate(db, ledgers, data);
|
|
192
189
|
if (!validation.success || !validation.data) {
|
|
193
190
|
return {
|
|
194
191
|
success: false,
|
package/dist/art.d.ts
CHANGED
package/dist/art.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns an ASCII representation of the logo for display in the console.
|
|
3
|
+
*
|
|
4
|
+
* @returns A string representation of the ASCII logo.
|
|
5
|
+
*/
|
|
1
6
|
export function getAsciiLogo() {
|
|
2
7
|
return `.................................................................
|
|
3
8
|
.................................................................
|
package/dist/db.d.ts
CHANGED
|
@@ -2,6 +2,13 @@ import { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
|
2
2
|
import postgres from "postgres";
|
|
3
3
|
import * as v from "valibot";
|
|
4
4
|
import * as schema from "./schema.js";
|
|
5
|
+
/**
|
|
6
|
+
* Options for configuring the Kitledger database connection.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Includes parameters for connection URL, SSL, connection pool size,
|
|
10
|
+
* migrations table and schema, and auto-migration setting.
|
|
11
|
+
*/
|
|
5
12
|
export type KitledgerDbOptions = {
|
|
6
13
|
url: string;
|
|
7
14
|
ssl?: boolean;
|
|
@@ -10,10 +17,26 @@ export type KitledgerDbOptions = {
|
|
|
10
17
|
migrationsSchema?: string;
|
|
11
18
|
autoMigrate?: boolean;
|
|
12
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Database instance type for Kitledger, extending PostgresJsDatabase with the defined schema.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Includes a reference to the underlying Postgres client.
|
|
25
|
+
*/
|
|
13
26
|
export type KitledgerDb = PostgresJsDatabase<typeof schema> & {
|
|
14
27
|
$client: postgres.Sql<{}>;
|
|
15
28
|
};
|
|
16
29
|
export declare function runMigrations(db: KitledgerDb, migrationsTable: string, migrationsSchema: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Initializes the Kitledger database with the provided options.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* Sets up the database connection, applies migrations automatically if enabled,
|
|
35
|
+
* and returns the initialized database instance.
|
|
36
|
+
*
|
|
37
|
+
* @param options - Configuration options for the database connection.
|
|
38
|
+
* @returns A promise that resolves to the initialized Kitledger database instance.
|
|
39
|
+
*/
|
|
17
40
|
export declare function initializeDatabase(options: KitledgerDbOptions): Promise<KitledgerDb>;
|
|
18
41
|
/**
|
|
19
42
|
* Supported operation types for get operations.
|
|
@@ -43,13 +66,22 @@ export type GetOperationResult<T> = {
|
|
|
43
66
|
message: string;
|
|
44
67
|
}[];
|
|
45
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Type definition for a single row in a query result.
|
|
71
|
+
*/
|
|
46
72
|
export type QueryResultRow = v.InferInput<typeof QueryResultRowSchema>;
|
|
73
|
+
/**
|
|
74
|
+
* Schema definition for a single row in a query result.
|
|
75
|
+
*/
|
|
47
76
|
export declare const QueryResultRowSchema: v.RecordSchema<v.StringSchema<undefined>, v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.DateSchema<undefined>, v.NullSchema<undefined>, v.RecordSchema<v.StringSchema<undefined>, v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.DateSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>], undefined>, undefined>;
|
|
77
|
+
/**
|
|
78
|
+
* Schema definition for an array of query result rows.
|
|
79
|
+
*/
|
|
48
80
|
export declare const QueryResultSchema: v.ArraySchema<v.RecordSchema<v.StringSchema<undefined>, v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.DateSchema<undefined>, v.NullSchema<undefined>, v.RecordSchema<v.StringSchema<undefined>, v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.DateSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>], undefined>, undefined>, undefined>;
|
|
49
81
|
/**
|
|
50
82
|
* Utility function to parse boolean filter values from strings or booleans to be used in queries and filters.
|
|
51
|
-
* @param value
|
|
52
|
-
* @returns
|
|
83
|
+
* @param value The value to parse, which can be a string or a boolean.
|
|
84
|
+
* @returns The parsed boolean value, or null if the input is not a valid boolean string.
|
|
53
85
|
*/
|
|
54
86
|
export declare function parseBooleanFilterValue(value: string | boolean): boolean | null;
|
|
55
87
|
/**
|
package/dist/db.js
CHANGED
|
@@ -7,6 +7,14 @@ import * as v from "valibot";
|
|
|
7
7
|
import * as schema from "./schema.js";
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
9
|
const __dirname = dirname(__filename);
|
|
10
|
+
/*
|
|
11
|
+
* Runs database migrations using the specified migrations table and schema.
|
|
12
|
+
*
|
|
13
|
+
* @param db - The Kitledger database instance.
|
|
14
|
+
* @param migrationsTable - The name of the migrations table.
|
|
15
|
+
* @param migrationsSchema - The schema where the migrations table is located.
|
|
16
|
+
* @returns A promise that resolves when migrations are complete.
|
|
17
|
+
*/
|
|
10
18
|
export async function runMigrations(db, migrationsTable, migrationsSchema) {
|
|
11
19
|
const migrationsPath = resolve(__dirname, "../dist/migrations");
|
|
12
20
|
await migrate(db, {
|
|
@@ -15,6 +23,16 @@ export async function runMigrations(db, migrationsTable, migrationsSchema) {
|
|
|
15
23
|
migrationsSchema: migrationsSchema,
|
|
16
24
|
});
|
|
17
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Initializes the Kitledger database with the provided options.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* Sets up the database connection, applies migrations automatically if enabled,
|
|
31
|
+
* and returns the initialized database instance.
|
|
32
|
+
*
|
|
33
|
+
* @param options - Configuration options for the database connection.
|
|
34
|
+
* @returns A promise that resolves to the initialized Kitledger database instance.
|
|
35
|
+
*/
|
|
18
36
|
export async function initializeDatabase(options) {
|
|
19
37
|
const dbConfig = {
|
|
20
38
|
url: options.url,
|
|
@@ -57,6 +75,9 @@ export var GetOperationType;
|
|
|
57
75
|
GetOperationType["SEARCH"] = "search";
|
|
58
76
|
GetOperationType["QUERY"] = "query";
|
|
59
77
|
})(GetOperationType || (GetOperationType = {}));
|
|
78
|
+
/**
|
|
79
|
+
* Schema definition for a single row in a query result.
|
|
80
|
+
*/
|
|
60
81
|
export const QueryResultRowSchema = v.record(v.string(), v.union([
|
|
61
82
|
v.string(),
|
|
62
83
|
v.number(),
|
|
@@ -65,11 +86,14 @@ export const QueryResultRowSchema = v.record(v.string(), v.union([
|
|
|
65
86
|
v.null(),
|
|
66
87
|
v.record(v.string(), v.union([v.string(), v.number(), v.boolean(), v.date(), v.null()])),
|
|
67
88
|
]));
|
|
89
|
+
/**
|
|
90
|
+
* Schema definition for an array of query result rows.
|
|
91
|
+
*/
|
|
68
92
|
export const QueryResultSchema = v.array(QueryResultRowSchema);
|
|
69
93
|
/**
|
|
70
94
|
* Utility function to parse boolean filter values from strings or booleans to be used in queries and filters.
|
|
71
|
-
* @param value
|
|
72
|
-
* @returns
|
|
95
|
+
* @param value The value to parse, which can be a string or a boolean.
|
|
96
|
+
* @returns The parsed boolean value, or null if the input is not a valid boolean string.
|
|
73
97
|
*/
|
|
74
98
|
export function parseBooleanFilterValue(value) {
|
|
75
99
|
if (typeof value === "boolean") {
|
package/dist/entities.d.ts
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import type { Field } from "./fields.js";
|
|
2
|
+
/**
|
|
3
|
+
* Enumeration for the status of an entity model.
|
|
4
|
+
*/
|
|
2
5
|
export declare enum EntityModelStatus {
|
|
3
6
|
ACTIVE = 0,
|
|
4
7
|
INACTIVE = 1
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Infers the meta type of an entity based on its fields.
|
|
11
|
+
*
|
|
12
|
+
* @param TFields - An array of Field definitions.
|
|
13
|
+
* @returns A mapped type where each field's refId is the key and its value type is the value.
|
|
14
|
+
*/
|
|
6
15
|
export type InferEntityMetaType<TFields extends readonly Field[]> = {
|
|
7
16
|
[K in TFields[number] as K["refId"]]: K["__valueType"];
|
|
8
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Type definition for an entity in the system.
|
|
20
|
+
*
|
|
21
|
+
* @param TData - The type of the data contained within the entity.
|
|
22
|
+
* @returns An object representing the entity with its metadata and data.
|
|
23
|
+
*/
|
|
9
24
|
export type Entity<TData = Record<string, any>> = {
|
|
10
25
|
id: string;
|
|
11
26
|
modelRefId: string;
|
|
@@ -13,7 +28,18 @@ export type Entity<TData = Record<string, any>> = {
|
|
|
13
28
|
updatedAt: Date;
|
|
14
29
|
data: TData;
|
|
15
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Type definition for a hook function that operates on an entity.
|
|
33
|
+
*
|
|
34
|
+
* @param TData - The type of the data contained within the entity.
|
|
35
|
+
* @returns A promise that resolves to the modified entity.
|
|
36
|
+
*/
|
|
16
37
|
export type EntityHook<TData> = (entity: Entity<TData>) => Promise<Entity<TData>>;
|
|
38
|
+
/**
|
|
39
|
+
* Type definition for the hooks associated with an entity.
|
|
40
|
+
* @param TData - The type of the data contained within the entity.
|
|
41
|
+
* @returns An object containing arrays of hook functions for various entity lifecycle events.
|
|
42
|
+
*/
|
|
17
43
|
export type EntityHooks<TData = Record<string, any>> = {
|
|
18
44
|
creating?: EntityHook<TData>[];
|
|
19
45
|
updating?: EntityHook<TData>[];
|
|
@@ -22,6 +48,11 @@ export type EntityHooks<TData = Record<string, any>> = {
|
|
|
22
48
|
updated?: EntityHook<TData>[];
|
|
23
49
|
deleted?: EntityHook<TData>[];
|
|
24
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Type definition for an entity model in the system.
|
|
53
|
+
*
|
|
54
|
+
* @returns An object representing the entity model with its metadata, fields, and hooks.
|
|
55
|
+
*/
|
|
25
56
|
export type EntityModel = {
|
|
26
57
|
refId: string;
|
|
27
58
|
altId?: string;
|
|
@@ -30,6 +61,12 @@ export type EntityModel = {
|
|
|
30
61
|
fields?: Field[];
|
|
31
62
|
hooks?: EntityHooks<any>;
|
|
32
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* Options for defining an entity model.
|
|
66
|
+
*
|
|
67
|
+
* @param TFields - An array of Field definitions.
|
|
68
|
+
* @returns An object containing the options for the entity model.
|
|
69
|
+
*/
|
|
33
70
|
export type EntityModelOptions<TFields extends readonly Field[]> = {
|
|
34
71
|
refId: string;
|
|
35
72
|
altId?: string;
|
|
@@ -38,6 +75,16 @@ export type EntityModelOptions<TFields extends readonly Field[]> = {
|
|
|
38
75
|
fields?: TFields;
|
|
39
76
|
hooks?: EntityHooks<InferEntityMetaType<TFields>>;
|
|
40
77
|
};
|
|
78
|
+
/**
|
|
79
|
+
* Defines an entity model with the provided options.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* This function helps in creating a strongly typed entity model by inferring
|
|
83
|
+
* the types of the fields provided.
|
|
84
|
+
*
|
|
85
|
+
* @param options The options for defining the entity model.
|
|
86
|
+
* @returns A strongly typed entity model.
|
|
87
|
+
*/
|
|
41
88
|
export declare function defineEntityModel<const TFields extends readonly Field[]>(options: EntityModelOptions<TFields>): EntityModel & {
|
|
42
89
|
fields: TFields;
|
|
43
90
|
};
|
package/dist/entities.js
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration for the status of an entity model.
|
|
3
|
+
*/
|
|
1
4
|
export var EntityModelStatus;
|
|
2
5
|
(function (EntityModelStatus) {
|
|
3
6
|
EntityModelStatus[EntityModelStatus["ACTIVE"] = 0] = "ACTIVE";
|
|
4
7
|
EntityModelStatus[EntityModelStatus["INACTIVE"] = 1] = "INACTIVE";
|
|
5
8
|
})(EntityModelStatus || (EntityModelStatus = {}));
|
|
9
|
+
/**
|
|
10
|
+
* Defines an entity model with the provided options.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* This function helps in creating a strongly typed entity model by inferring
|
|
14
|
+
* the types of the fields provided.
|
|
15
|
+
*
|
|
16
|
+
* @param options The options for defining the entity model.
|
|
17
|
+
* @returns A strongly typed entity model.
|
|
18
|
+
*/
|
|
6
19
|
export function defineEntityModel(options) {
|
|
7
20
|
return {
|
|
8
21
|
...options,
|
package/dist/factories.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Account } from "./accounts.js";
|
|
2
2
|
import { ApiToken, Permission, PermissionAssignment, Role, SystemPermission, User, UserRole } from "./auth.js";
|
|
3
|
-
import { Ledger } from "./ledgers.js";
|
|
4
3
|
/**
|
|
5
4
|
* A generic factory function to create an array of items.
|
|
6
5
|
* @param factory A function that creates a single item.
|
|
@@ -37,9 +36,6 @@ export declare class UserFactory extends BaseFactory<User> {
|
|
|
37
36
|
export declare class UserRoleFactory extends BaseFactory<UserRole> {
|
|
38
37
|
constructor();
|
|
39
38
|
}
|
|
40
|
-
export declare class LedgerFactory extends BaseFactory<Ledger> {
|
|
41
|
-
constructor();
|
|
42
|
-
}
|
|
43
39
|
export declare class AccountFactory extends BaseFactory<Account> {
|
|
44
40
|
constructor();
|
|
45
41
|
}
|
package/dist/factories.js
CHANGED
|
@@ -115,26 +115,11 @@ const makeUserRole = () => ({
|
|
|
115
115
|
created_at: faker.date.past(),
|
|
116
116
|
updated_at: faker.date.recent(),
|
|
117
117
|
});
|
|
118
|
-
export class LedgerFactory extends BaseFactory {
|
|
119
|
-
constructor() {
|
|
120
|
-
super(makeLedger);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
118
|
export class AccountFactory extends BaseFactory {
|
|
124
119
|
constructor() {
|
|
125
120
|
super(makeAccount);
|
|
126
121
|
}
|
|
127
122
|
}
|
|
128
|
-
const makeLedger = () => ({
|
|
129
|
-
id: v7(),
|
|
130
|
-
ref_id: v7(),
|
|
131
|
-
alt_id: v7(),
|
|
132
|
-
name: faker.company.name(),
|
|
133
|
-
description: faker.company.catchPhrase(),
|
|
134
|
-
active: true,
|
|
135
|
-
created_at: faker.date.past(),
|
|
136
|
-
updated_at: faker.date.recent(),
|
|
137
|
-
});
|
|
138
123
|
const makeAccount = () => ({
|
|
139
124
|
id: v7(),
|
|
140
125
|
ref_id: v7(),
|
package/dist/fields.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration of supported field types.
|
|
3
|
+
*/
|
|
1
4
|
export declare enum FieldType {
|
|
2
5
|
TEXT = "text",
|
|
3
6
|
NUMBER = "number",
|
|
@@ -7,18 +10,27 @@ export declare enum FieldType {
|
|
|
7
10
|
SELECT = "select",
|
|
8
11
|
RELATION = "relation"
|
|
9
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Base interface for all field definitions.
|
|
15
|
+
*/
|
|
10
16
|
interface BaseField {
|
|
11
17
|
readonly refId: string;
|
|
12
18
|
name: string;
|
|
13
19
|
description?: string;
|
|
14
20
|
required: boolean;
|
|
15
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Type definition for a text field.
|
|
24
|
+
*/
|
|
16
25
|
export interface TextField extends BaseField {
|
|
17
26
|
type: FieldType.TEXT;
|
|
18
27
|
readonly __valueType: string;
|
|
19
28
|
maxLength?: number;
|
|
20
29
|
format?: "email" | "plain" | "rich_text";
|
|
21
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Type definition for a number field.
|
|
33
|
+
*/
|
|
22
34
|
export type NumberFormatting = {
|
|
23
35
|
style: "integer";
|
|
24
36
|
} | {
|
|
@@ -28,6 +40,9 @@ export type NumberFormatting = {
|
|
|
28
40
|
style: "currency";
|
|
29
41
|
currencyCode: string;
|
|
30
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Type definition for a number field.
|
|
45
|
+
*/
|
|
31
46
|
export interface NumberField extends BaseField {
|
|
32
47
|
type: FieldType.NUMBER;
|
|
33
48
|
readonly __valueType: number;
|
|
@@ -35,23 +50,38 @@ export interface NumberField extends BaseField {
|
|
|
35
50
|
max?: number;
|
|
36
51
|
formatting: NumberFormatting;
|
|
37
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Type definition for a date field.
|
|
55
|
+
*/
|
|
38
56
|
export interface DateField extends BaseField {
|
|
39
57
|
type: FieldType.DATE;
|
|
40
58
|
readonly __valueType: Date;
|
|
41
59
|
includeTime: boolean;
|
|
42
60
|
formatStr: string;
|
|
43
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Type definition for a boolean field.
|
|
64
|
+
*/
|
|
44
65
|
export interface BooleanField extends BaseField {
|
|
45
66
|
type: FieldType.BOOLEAN;
|
|
46
67
|
readonly __valueType: boolean;
|
|
47
68
|
defaultValue?: boolean;
|
|
48
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Type definition for a URL field.
|
|
72
|
+
*/
|
|
49
73
|
export interface URLField extends BaseField {
|
|
50
74
|
type: FieldType.URL;
|
|
51
75
|
readonly __valueType: string;
|
|
52
76
|
defaultValue?: string;
|
|
53
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* TEMPORARY: Type definition for query configuration in relation fields.
|
|
80
|
+
*/
|
|
54
81
|
export type QueryConfig = {};
|
|
82
|
+
/**
|
|
83
|
+
* Type definition for a select field.
|
|
84
|
+
*/
|
|
55
85
|
export interface SelectField extends BaseField {
|
|
56
86
|
type: FieldType.SELECT;
|
|
57
87
|
readonly __valueType: string | number | (string | number)[];
|
|
@@ -63,6 +93,9 @@ export interface SelectField extends BaseField {
|
|
|
63
93
|
}>;
|
|
64
94
|
defaultValue?: string | number | Array<string | number>;
|
|
65
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Type definition for a relation field.
|
|
98
|
+
*/
|
|
66
99
|
export interface RelationField extends BaseField {
|
|
67
100
|
type: FieldType.RELATION;
|
|
68
101
|
readonly __valueType: any;
|
|
@@ -71,28 +104,61 @@ export interface RelationField extends BaseField {
|
|
|
71
104
|
displayFieldId: string;
|
|
72
105
|
query: QueryConfig;
|
|
73
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Union type for all field definitions.
|
|
109
|
+
*/
|
|
74
110
|
export type Field = TextField | NumberField | DateField | BooleanField | URLField | SelectField | RelationField;
|
|
111
|
+
/**
|
|
112
|
+
* Options for defining a text field.
|
|
113
|
+
*/
|
|
75
114
|
export type TextFieldOptions = Omit<TextField, "type" | "__valueType" | "refId" | "required"> & {
|
|
76
115
|
required?: boolean;
|
|
77
116
|
};
|
|
117
|
+
/**
|
|
118
|
+
* Options for defining other field types.
|
|
119
|
+
*/
|
|
78
120
|
export type NumberFieldOptions = Omit<NumberField, "type" | "__valueType" | "refId" | "required"> & {
|
|
79
121
|
required?: boolean;
|
|
80
122
|
};
|
|
123
|
+
/**
|
|
124
|
+
* Options for defining other field types.
|
|
125
|
+
*/
|
|
81
126
|
export type DateFieldOptions = Omit<DateField, "type" | "__valueType" | "refId" | "required"> & {
|
|
82
127
|
required?: boolean;
|
|
83
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* Options for defining other field types.
|
|
131
|
+
*/
|
|
84
132
|
export type BooleanFieldOptions = Omit<BooleanField, "type" | "__valueType" | "refId" | "required"> & {
|
|
85
133
|
required?: boolean;
|
|
86
134
|
};
|
|
135
|
+
/**
|
|
136
|
+
* Options for defining other field types.
|
|
137
|
+
*/
|
|
87
138
|
export type URLFieldOptions = Omit<URLField, "type" | "__valueType" | "refId" | "required"> & {
|
|
88
139
|
required?: boolean;
|
|
89
140
|
};
|
|
141
|
+
/**
|
|
142
|
+
* Options for defining other field types.
|
|
143
|
+
*/
|
|
90
144
|
export type SelectFieldOptions = Omit<SelectField, "type" | "__valueType" | "refId" | "required"> & {
|
|
91
145
|
required?: boolean;
|
|
92
146
|
};
|
|
147
|
+
/**
|
|
148
|
+
* Options for defining other field types.
|
|
149
|
+
*/
|
|
93
150
|
export type RelationFieldOptions = Omit<RelationField, "type" | "__valueType" | "refId" | "required"> & {
|
|
94
151
|
required?: boolean;
|
|
95
152
|
};
|
|
153
|
+
/**
|
|
154
|
+
* Factory functions to define fields of various types.
|
|
155
|
+
*
|
|
156
|
+
* @remarks
|
|
157
|
+
* These functions help in creating strongly typed field definitions by inferring
|
|
158
|
+
*
|
|
159
|
+
* @param options - The options for defining the field.
|
|
160
|
+
* @returns The defined field with its type.
|
|
161
|
+
*/
|
|
96
162
|
export declare function defineTextField<const T extends string, const R extends boolean = false>(options: TextFieldOptions & {
|
|
97
163
|
refId: T;
|
|
98
164
|
required?: R;
|
|
@@ -100,6 +166,15 @@ export declare function defineTextField<const T extends string, const R extends
|
|
|
100
166
|
refId: T;
|
|
101
167
|
required: R;
|
|
102
168
|
};
|
|
169
|
+
/**
|
|
170
|
+
* Factory function to define a number field.
|
|
171
|
+
*
|
|
172
|
+
* @remarks
|
|
173
|
+
* These functions help in creating strongly typed field definitions by inferring
|
|
174
|
+
*
|
|
175
|
+
* @param options - The options for defining the field.
|
|
176
|
+
* @returns The defined field with its type.
|
|
177
|
+
*/
|
|
103
178
|
export declare function defineNumberField<const T extends string, const R extends boolean = false>(options: NumberFieldOptions & {
|
|
104
179
|
refId: T;
|
|
105
180
|
required?: R;
|
|
@@ -107,6 +182,15 @@ export declare function defineNumberField<const T extends string, const R extend
|
|
|
107
182
|
refId: T;
|
|
108
183
|
required: R;
|
|
109
184
|
};
|
|
185
|
+
/**
|
|
186
|
+
* Factory function to define a date field.
|
|
187
|
+
*
|
|
188
|
+
* @remarks
|
|
189
|
+
* These functions help in creating strongly typed field definitions by inferring
|
|
190
|
+
*
|
|
191
|
+
* @param options - The options for defining the field.
|
|
192
|
+
* @returns The defined field with its type.
|
|
193
|
+
*/
|
|
110
194
|
export declare function defineDateField<const T extends string, const R extends boolean = false>(options: DateFieldOptions & {
|
|
111
195
|
refId: T;
|
|
112
196
|
required?: R;
|
|
@@ -114,6 +198,15 @@ export declare function defineDateField<const T extends string, const R extends
|
|
|
114
198
|
refId: T;
|
|
115
199
|
required: R;
|
|
116
200
|
};
|
|
201
|
+
/**
|
|
202
|
+
* Factory function to define a boolean field.
|
|
203
|
+
*
|
|
204
|
+
* @remarks
|
|
205
|
+
* These functions help in creating strongly typed field definitions by inferring
|
|
206
|
+
*
|
|
207
|
+
* @param options - The options for defining the field.
|
|
208
|
+
* @returns The defined field with its type.
|
|
209
|
+
*/
|
|
117
210
|
export declare function defineBooleanField<const T extends string, const R extends boolean = false>(options: BooleanFieldOptions & {
|
|
118
211
|
refId: T;
|
|
119
212
|
required?: R;
|
|
@@ -121,6 +214,11 @@ export declare function defineBooleanField<const T extends string, const R exten
|
|
|
121
214
|
refId: T;
|
|
122
215
|
required: R;
|
|
123
216
|
};
|
|
217
|
+
/**
|
|
218
|
+
* Factory function to define a URL field.
|
|
219
|
+
* @param options - The options for defining the field.
|
|
220
|
+
* @returns The defined field with its type.
|
|
221
|
+
*/
|
|
124
222
|
export declare function defineURLField<const T extends string, const R extends boolean = false>(options: URLFieldOptions & {
|
|
125
223
|
refId: T;
|
|
126
224
|
required?: R;
|
|
@@ -128,6 +226,15 @@ export declare function defineURLField<const T extends string, const R extends b
|
|
|
128
226
|
refId: T;
|
|
129
227
|
required: R;
|
|
130
228
|
};
|
|
229
|
+
/**
|
|
230
|
+
* Factory function to define a select field.
|
|
231
|
+
*
|
|
232
|
+
* @remarks
|
|
233
|
+
* These functions help in creating strongly typed field definitions by inferring
|
|
234
|
+
*
|
|
235
|
+
* @param options - The options for defining the field.
|
|
236
|
+
* @returns The defined field with its type.
|
|
237
|
+
*/
|
|
131
238
|
export declare function defineSelectField<const T extends string, const R extends boolean = false>(options: SelectFieldOptions & {
|
|
132
239
|
refId: T;
|
|
133
240
|
required?: R;
|
|
@@ -135,6 +242,15 @@ export declare function defineSelectField<const T extends string, const R extend
|
|
|
135
242
|
refId: T;
|
|
136
243
|
required: R;
|
|
137
244
|
};
|
|
245
|
+
/**
|
|
246
|
+
* Factory function to define a relation field.
|
|
247
|
+
*
|
|
248
|
+
* @remarks
|
|
249
|
+
* These functions help in creating strongly typed field definitions by inferring
|
|
250
|
+
*
|
|
251
|
+
* @param options - The options for defining the field.
|
|
252
|
+
* @returns The defined field with its type.
|
|
253
|
+
*/
|
|
138
254
|
export declare function defineRelationField<const T extends string, const R extends boolean = false>(options: RelationFieldOptions & {
|
|
139
255
|
refId: T;
|
|
140
256
|
required?: R;
|