@objectql/types 1.6.1 → 1.7.1

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/src/action.ts DELETED
@@ -1,96 +0,0 @@
1
- import { FieldConfig } from "./field";
2
- import { HookAPI } from "./hook"; // Reuse the restricted API interface
3
-
4
- /**
5
- * Defines the scope of the action.
6
- * - `record`: Acts on a specific record instance (e.g. "Approve Order").
7
- * - `global`: Acts on the collection or system (e.g. "Import CSV", "Daily Report").
8
- */
9
- export type ActionType = 'record' | 'global';
10
-
11
- /**
12
- * Re-using FieldConfig allows us to describe input parameters
13
- * using the same rich vocabulary as database fields (validation, UI hints, etc).
14
- */
15
- export type ActionInputDefinition = Record<string, FieldConfig>;
16
-
17
- /**
18
- * Context passed to the action handler execution.
19
- */
20
- export interface ActionContext<BaseT = any, InputT = any> {
21
- /** The object this action belongs to. */
22
- objectName: string;
23
-
24
- /** The name of the action being executed. */
25
- actionName: string;
26
-
27
- /**
28
- * The ID of the record being acted upon.
29
- * Only available if type is 'record'.
30
- */
31
- id?: string | number;
32
-
33
- /**
34
- * The validated input arguments.
35
- */
36
- input: InputT;
37
-
38
- /**
39
- * Database Access API (Same as Hooks).
40
- */
41
- api: HookAPI;
42
-
43
- /**
44
- * User Session.
45
- */
46
- user?: {
47
- id: string | number;
48
- [key: string]: any;
49
- };
50
- }
51
-
52
- /**
53
- * The configuration of an Action visible to the Metadata engine (YAML/JSON side).
54
- */
55
- export interface ActionConfig {
56
- label?: string;
57
- description?: string;
58
- icon?: string;
59
-
60
- /**
61
- * Default: 'global' if no fields defined, but usually specified explicitly.
62
- */
63
- type?: ActionType; // 'record' | 'global'
64
-
65
- /**
66
- * Message to show before executing. If present, UI should prompt confirmation.
67
- */
68
- confirm_text?: string;
69
-
70
- /**
71
- * If true, this action is not exposed via API directly (server-internal).
72
- */
73
- internal?: boolean;
74
-
75
- /**
76
- * Input parameter schema.
77
- */
78
- params?: ActionInputDefinition;
79
-
80
- /**
81
- * Output data shape description (optional, for content negotiation).
82
- */
83
- return_type?: string | FieldConfig;
84
- }
85
-
86
- /**
87
- * The full implementation definition (Code side).
88
- */
89
- export interface ActionDefinition<BaseT = any, InputT = any, ReturnT = any> extends ActionConfig {
90
- /**
91
- * The business logic implementation.
92
- */
93
- handler: (ctx: ActionContext<BaseT, InputT>) => Promise<ReturnT>;
94
- }
95
-
96
- export type ActionHandler<BaseT = any, InputT = any, ReturnT = any> = (ctx: ActionContext<BaseT, InputT>) => Promise<ReturnT>;
package/src/app.ts DELETED
@@ -1,23 +0,0 @@
1
- import { ObjectConfig } from "./object";
2
- import { Driver } from "./driver";
3
- import { MetadataRegistry } from "./registry";
4
- import { HookName, HookHandler, HookContext } from "./hook";
5
- import { ActionHandler, ActionContext } from "./action";
6
- import { LoaderPlugin } from "./loader";
7
-
8
- export interface IObjectQL {
9
- getObject(name: string): ObjectConfig | undefined;
10
- getConfigs(): Record<string, ObjectConfig>;
11
- datasource(name: string): Driver;
12
- init(): Promise<void>;
13
- removePackage(name: string): void;
14
- metadata: MetadataRegistry;
15
-
16
- registerObject(object: ObjectConfig): void;
17
-
18
- on(event: HookName, objectName: string, handler: HookHandler): void;
19
- triggerHook(event: HookName, objectName: string, ctx: HookContext): Promise<void>;
20
-
21
- registerAction(objectName: string, actionName: string, handler: ActionHandler): void;
22
- executeAction(objectName: string, actionName: string, ctx: ActionContext): Promise<any>;
23
- }
@@ -1,46 +0,0 @@
1
- export interface AppConfig {
2
- /**
3
- * Unique identifier for the application
4
- */
5
- name: string;
6
-
7
- /**
8
- * Display label for the application
9
- */
10
- label: string;
11
-
12
- /**
13
- * Description of what this application does
14
- */
15
- description?: string;
16
-
17
- /**
18
- * Icon name/class for the application
19
- */
20
- icon?: string;
21
-
22
- /**
23
- * URL to the application logo
24
- */
25
- logo?: string;
26
-
27
- /**
28
- * Default path to redirect when opening the app
29
- */
30
- homepage?: string;
31
-
32
- /**
33
- * Sort order for display
34
- */
35
- sort_no?: number;
36
-
37
- /**
38
- * Whether the application is enabled
39
- */
40
- is_active?: boolean;
41
-
42
- /**
43
- * Custom metadata/settings
44
- */
45
- [key: string]: any;
46
- }
package/src/config.ts DELETED
@@ -1,37 +0,0 @@
1
- import { MetadataRegistry } from "./registry";
2
- import { Driver } from "./driver";
3
- import { ObjectConfig } from "./object";
4
- import { ObjectQLPlugin } from "./plugin";
5
-
6
- export interface ObjectQLConfig {
7
- registry?: MetadataRegistry;
8
- datasources?: Record<string, Driver>;
9
- /**
10
- * Optional connection string for auto-configuration.
11
- * e.g. "sqlite://dev.db", "postgres://localhost/db", "mongodb://localhost/db"
12
- */
13
- connection?: string;
14
- /**
15
- * Path(s) to the directory containing schema files (*.object.yml).
16
- */
17
- source?: string | string[];
18
- objects?: Record<string, ObjectConfig>;
19
- /**
20
- * @deprecated Use 'presets' instead.
21
- */
22
- packages?: string[];
23
- /**
24
- * List of npm packages or presets to load.
25
- */
26
- presets?: string[];
27
- /**
28
- * List of plugins to load.
29
- * Can be an instance of ObjectQLPlugin or a package name string.
30
- */
31
- plugins?: (ObjectQLPlugin | string)[];
32
- /**
33
- * List of remote ObjectQL instances to connect to.
34
- * e.g. ["http://user-service:3000", "http://order-service:3000"]
35
- */
36
- remotes?: string[];
37
- }
package/src/context.ts DELETED
@@ -1,45 +0,0 @@
1
- import { IObjectRepository } from './repository';
2
-
3
- export interface ObjectQLContext {
4
- // === Identity & Isolation ===
5
- userId?: string; // Current User ID
6
- spaceId?: string; // Multi-tenancy Isolation (Organization ID)
7
- roles: string[]; // RBAC Roles
8
-
9
- // === Execution Flags ===
10
- /**
11
- * Sudo Mode / System Bypass.
12
- */
13
- isSystem?: boolean;
14
-
15
- // === Data Entry Point ===
16
- /**
17
- * Returns a repository proxy bound to this context.
18
- * All operations performed via this proxy inherit userId, spaceId, and transaction.
19
- */
20
- object(entityName: string): IObjectRepository;
21
-
22
- /**
23
- * Execute a function within a transaction.
24
- * The callback receives a new context 'trxCtx' which inherits userId, spaceId from this context.
25
- */
26
- transaction(callback: (trxCtx: ObjectQLContext) => Promise<any>): Promise<any>;
27
-
28
- /**
29
- * Returns a new context with system privileges (isSystem: true).
30
- * It shares the same transaction scope as the current context.
31
- */
32
- sudo(): ObjectQLContext;
33
-
34
- /**
35
- * Internal: Driver-specific transaction handle.
36
- */
37
- transactionHandle?: any;
38
- }
39
-
40
- export interface ObjectQLContextOptions {
41
- userId?: string;
42
- spaceId?: string;
43
- roles?: string[];
44
- isSystem?: boolean;
45
- }
package/src/driver.ts DELETED
@@ -1,27 +0,0 @@
1
- export interface Driver {
2
- find(objectName: string, query: any, options?: any): Promise<any[]>;
3
- findOne(objectName: string, id: string | number, query?: any, options?: any): Promise<any>;
4
- create(objectName: string, data: any, options?: any): Promise<any>;
5
- update(objectName: string, id: string | number, data: any, options?: any): Promise<any>;
6
- delete(objectName: string, id: string | number, options?: any): Promise<any>;
7
- count(objectName: string, filters: any, options?: any): Promise<number>;
8
-
9
- // Schema / Lifecycle
10
- init?(objects: any[]): Promise<void>;
11
-
12
- // Advanced
13
- aggregate?(objectName: string, query: any, options?: any): Promise<any>;
14
- distinct?(objectName: string, field: string, filters?: any, options?: any): Promise<any[]>;
15
-
16
- // Bulk / Atomic
17
- createMany?(objectName: string, data: any[], options?: any): Promise<any>;
18
- updateMany?(objectName: string, filters: any, data: any, options?: any): Promise<any>;
19
- deleteMany?(objectName: string, filters: any, options?: any): Promise<any>;
20
- findOneAndUpdate?(objectName: string, filters: any, update: any, options?: any): Promise<any>;
21
-
22
- // Transaction
23
- beginTransaction?(): Promise<any>;
24
- commitTransaction?(trx: any): Promise<void>;
25
- rollbackTransaction?(trx: any): Promise<void>;
26
- }
27
-
package/src/field.ts DELETED
@@ -1,149 +0,0 @@
1
- import { FieldValidation, ValidationAiContext } from './validation';
2
-
3
- /**
4
- * Represents the supported field data types in the ObjectQL schema.
5
- * These types determine how data is stored, validated, and rendered.
6
- *
7
- * - `text`: Simple string.
8
- * - `textarea`: Long string.
9
- * - `select`: Choice from a list.
10
- * - `lookup`: Relationship to another object.
11
- */
12
- export type FieldType =
13
- | 'text'
14
- | 'textarea'
15
- | 'markdown'
16
- | 'html'
17
- | 'select'
18
- | 'date'
19
- | 'datetime'
20
- | 'time'
21
- | 'number'
22
- | 'currency'
23
- | 'percent'
24
- | 'boolean'
25
- | 'email'
26
- | 'phone'
27
- | 'url'
28
- | 'image'
29
- | 'file'
30
- | 'avatar'
31
- | 'location'
32
- | 'lookup'
33
- | 'master_detail'
34
- | 'password'
35
- | 'formula'
36
- | 'summary'
37
- | 'auto_number'
38
- | 'object'
39
- | 'vector'
40
- | 'grid';
41
-
42
- /**
43
- * Defines a single option for select/multiselect fields.
44
- */
45
- export interface FieldOption {
46
- /** The display label for the option. */
47
- label: string;
48
- /** The actual value stored in the database. */
49
- value: string | number;
50
- }
51
-
52
- /**
53
- * Configuration for a single field on an object.
54
- * This defines the schema, validation rules, and UI hints for the attribute.
55
- */
56
- export interface FieldConfig {
57
- /**
58
- * The unique API name of the field.
59
- * If defined within an object map, this is often automatically populated from the key.
60
- */
61
- name?: string;
62
-
63
- /** The human-readable label used in UIs. */
64
- label?: string;
65
-
66
- /** Description of the field for documentation or tooltip. */
67
- description?: string;
68
-
69
- /** The data type of the field. */
70
- type: FieldType;
71
-
72
- /** Whether the field is mandatory. Defaults to false. */
73
- required?: boolean;
74
-
75
- /** Whether the field is unique in the table. */
76
- unique?: boolean;
77
-
78
- /** Whether to create a database index for this field. */
79
- index?: boolean;
80
-
81
- /** Whether the field is read-only in UI. */
82
- readonly?: boolean;
83
-
84
- /** Whether the field is hidden from default UI/API response. */
85
- hidden?: boolean;
86
-
87
- /** The default value if not provided during creation. */
88
- defaultValue?: any;
89
-
90
- /** Tooltip or help text for the user. */
91
- help_text?: string;
92
-
93
- /**
94
- * Whether the field allows multiple values.
95
- * Supported by 'select', 'lookup', 'file', 'image'.
96
- */
97
- multiple?: boolean;
98
-
99
- /**
100
- * Options for select fields.
101
- * List of available choices for select/multiselect fields.
102
- */
103
- options?: FieldOption[];
104
-
105
- /**
106
- * Reference to another object for lookup/master_detail fields.
107
- * Specifies the target object name for relationship fields.
108
- */
109
- reference_to?: string;
110
-
111
- // Validation properties
112
- /** Minimum for number/currency/percent. */
113
- min?: number;
114
- /** Maximum for number/currency/percent. */
115
- max?: number;
116
- /** Minimum length for text based fields. */
117
- min_length?: number;
118
- /** Maximum length for text based fields. */
119
- max_length?: number;
120
- /** Regular expression pattern for validation. */
121
- regex?: string;
122
-
123
- /**
124
- * Field validation configuration.
125
- * Defines validation rules applied at the field level.
126
- */
127
- validation?: FieldValidation;
128
-
129
- /**
130
- * AI context for the field.
131
- * Provides semantic information for AI tools.
132
- */
133
- ai_context?: ValidationAiContext;
134
-
135
- // Vector properties
136
- /** Dimension of the vector for 'vector' type fields. */
137
- dimension?: number;
138
-
139
- // Formula & Summary
140
- /** Formula expression. */
141
- formula?: string;
142
- /** Object to summarize. */
143
- summary_object?: string;
144
- /** Field on the summary object. */
145
- summary_field?: string;
146
- /** Type of summary (count, sum, min, max, avg). */
147
- summary_type?: string;
148
- filters?: any[];
149
- }
package/src/hook.ts DELETED
@@ -1,131 +0,0 @@
1
- import { UnifiedQuery } from "./query";
2
-
3
- /**
4
- * Standard CRUD operations supported by hooks.
5
- */
6
- export type HookOperation = 'find' | 'count' | 'create' | 'update' | 'delete';
7
-
8
- /**
9
- * Execution timing relative to the database operation.
10
- */
11
- export type HookTiming = 'before' | 'after';
12
-
13
- /**
14
- * Minimal API surface exposed to hooks for performing side-effects or checks.
15
- */
16
- export interface HookAPI {
17
- // We use 'any' here to avoid circular dependencies with core/ObjectQL
18
- // In practice, this is the ObjectQL instance.
19
- find(objectName: string, query?: any): Promise<any[]>;
20
- findOne(objectName: string, id: string | number): Promise<any>;
21
- count(objectName: string, query?: any): Promise<number>;
22
- create(objectName: string, data: any): Promise<any>;
23
- update(objectName: string, id: string | number, data: any): Promise<any>;
24
- delete(objectName: string, id: string | number): Promise<any>;
25
- }
26
-
27
- /**
28
- * Base context available in all hooks.
29
- */
30
- export interface BaseHookContext<T = any> {
31
- /** The name of the object (entity) being acted upon. */
32
- objectName: string;
33
-
34
- /** The triggering operation. */
35
- operation: HookOperation;
36
-
37
- /** Access to the database/engine to perform extra queries. */
38
- api: HookAPI;
39
-
40
- /** User/Session context (Authentication info). */
41
- user?: {
42
- id: string | number;
43
- [key: string]: any;
44
- };
45
-
46
- /**
47
- * Shared state for passing data between matching 'before' and 'after' hooks.
48
- * e.g. Calculate a diff in 'beforeUpdate' and read it in 'afterUpdate'.
49
- */
50
- state: Record<string, any>;
51
- }
52
-
53
- /**
54
- * Context for Retrieval operations (Find, Count).
55
- */
56
- export interface RetrievalHookContext<T = any> extends BaseHookContext<T> {
57
- operation: 'find' | 'count';
58
-
59
- /** The query criteria being executed. Modifiable in 'before' hooks. */
60
- query: any;
61
-
62
- /** The result of the query. Only available in 'after' hooks. */
63
- result?: T[] | number;
64
- }
65
-
66
- /**
67
- * Context for Modification operations (Create, Update, Delete).
68
- */
69
- export interface MutationHookContext<T = any> extends BaseHookContext<T> {
70
- operation: 'create' | 'update' | 'delete';
71
-
72
- /** The record ID. Undefined for 'create'. */
73
- id?: string | number;
74
-
75
- /**
76
- * The incoming data changes.
77
- * - For 'create': The full object to insert.
78
- * - For 'update': The partial fields to update.
79
- * - For 'delete': Undefined.
80
- */
81
- data?: Partial<T>;
82
-
83
- /**
84
- * The final result record from the database.
85
- * Only available in 'after' hooks.
86
- */
87
- result?: T;
88
-
89
- /**
90
- * The existing record fetched from DB before operation.
91
- * Available in 'update' and 'delete' hooks.
92
- */
93
- previousData?: T;
94
- }
95
-
96
- /**
97
- * Specialized context for Updates, including change tracking.
98
- */
99
- export interface UpdateHookContext<T = any> extends MutationHookContext<T> {
100
- operation: 'update';
101
-
102
- /**
103
- * Helper to check if a specific field is being modified.
104
- * Checks if the field exists in 'data' AND is different from 'previousData'.
105
- */
106
- isModified(field: keyof T): boolean;
107
- }
108
-
109
- /**
110
- * Definition interface for a set of hooks for a specific object.
111
- */
112
- export interface ObjectHookDefinition<T = any> {
113
- beforeFind?: (ctx: RetrievalHookContext<T>) => Promise<void> | void;
114
- afterFind?: (ctx: RetrievalHookContext<T>) => Promise<void> | void;
115
-
116
- beforeCount?: (ctx: RetrievalHookContext<T>) => Promise<void> | void;
117
- afterCount?: (ctx: RetrievalHookContext<T>) => Promise<void> | void;
118
-
119
- beforeDelete?: (ctx: MutationHookContext<T>) => Promise<void> | void;
120
- afterDelete?: (ctx: MutationHookContext<T>) => Promise<void> | void;
121
-
122
- beforeCreate?: (ctx: MutationHookContext<T>) => Promise<void> | void;
123
- afterCreate?: (ctx: MutationHookContext<T>) => Promise<void> | void;
124
-
125
- beforeUpdate?: (ctx: UpdateHookContext<T>) => Promise<void> | void;
126
- afterUpdate?: (ctx: UpdateHookContext<T>) => Promise<void> | void;
127
- }
128
-
129
- export type HookName = keyof ObjectHookDefinition;
130
- export type HookContext<T = any> = RetrievalHookContext<T> | MutationHookContext<T> | UpdateHookContext<T>;
131
- export type HookHandler<T = any> = (ctx: HookContext<T>) => Promise<void> | void;
package/src/index.ts DELETED
@@ -1,18 +0,0 @@
1
- export * from './field';
2
- export * from './object';
3
- export * from './driver';
4
- export * from './query';
5
- export * from './registry';
6
- export * from './hook';
7
- export * from './action';
8
- export * from './repository';
9
- export * from './app';
10
- export * from './plugin';
11
- export * from './config';
12
- export * from './context';
13
- export * from './validation';
14
- export * from './permission';
15
- export * from './page';
16
- export * from './loader';
17
- export * from './application';
18
- export * from './menu';
package/src/loader.ts DELETED
@@ -1,17 +0,0 @@
1
- import { MetadataRegistry } from './registry';
2
-
3
- export interface LoaderHandlerContext {
4
- file: string;
5
- content: string;
6
- registry: MetadataRegistry;
7
- packageName?: string;
8
- }
9
-
10
- export type LoaderHandler = (ctx: LoaderHandlerContext) => void;
11
-
12
- export interface LoaderPlugin {
13
- name: string;
14
- glob: string[];
15
- handler: LoaderHandler;
16
- options?: any;
17
- }
package/src/menu.ts DELETED
@@ -1,102 +0,0 @@
1
- export type MenuType = 'sidebar' | 'topnav' | 'context' | 'mobile' | 'admin';
2
-
3
- export type MenuItemType = 'page' | 'section' | 'url' | 'folder' | 'object' | 'action';
4
-
5
- export interface MenuItem {
6
- /**
7
- * Unique identifier for the menu item
8
- */
9
- name: string;
10
-
11
- /**
12
- * Display label
13
- */
14
- label: string;
15
-
16
- /**
17
- * Icon name
18
- */
19
- icon?: string;
20
-
21
- /**
22
- * Item type
23
- */
24
- type?: MenuItemType;
25
-
26
- /**
27
- * Navigation path (for type: page/url)
28
- */
29
- path?: string;
30
-
31
- /**
32
- * Associated Object name (for type: object)
33
- */
34
- object?: string;
35
-
36
- /**
37
- * Object View name (for type: object)
38
- */
39
- view?: string;
40
-
41
- /**
42
- * Nested menu items
43
- */
44
- items?: MenuItem[];
45
-
46
- /**
47
- * Link target (e.g. _blank)
48
- */
49
- target?: string;
50
-
51
- /**
52
- * Visibility condition
53
- */
54
- hidden?: boolean | string;
55
-
56
- /**
57
- * Badge value or expression
58
- */
59
- badge?: string;
60
-
61
- /**
62
- * Custom properties
63
- */
64
- [key: string]: any;
65
- }
66
-
67
- export interface MenuConfig {
68
- /**
69
- * Unique identifier for the menu
70
- */
71
- name: string;
72
-
73
- /**
74
- * Display label
75
- */
76
- label: string;
77
-
78
- /**
79
- * Menu type/location
80
- */
81
- type?: MenuType;
82
-
83
- /**
84
- * The application this menu belongs to
85
- */
86
- app?: string;
87
-
88
- /**
89
- * Menu items
90
- */
91
- items: MenuItem[];
92
-
93
- /**
94
- * Whether the menu is active
95
- */
96
- is_active?: boolean;
97
-
98
- /**
99
- * Custom properties
100
- */
101
- [key: string]: any;
102
- }