@objectstack/objectql 0.6.0 → 0.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @objectstack/objectql
2
2
 
3
+ ## 0.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Patch release for maintenance and stability improvements
8
+ - Updated dependencies
9
+ - @objectstack/spec@0.6.1
10
+ - @objectstack/types@0.6.1
11
+ - @objectstack/core@0.6.1
12
+
3
13
  ## 0.6.0
4
14
 
5
15
  ### Minor Changes
package/README.md CHANGED
@@ -69,7 +69,8 @@ When building full applications, use the `ObjectKernel` to manage plugins and co
69
69
 
70
70
  ```typescript
71
71
  import { ObjectKernel } from '@objectstack/core';
72
- import { ObjectQLPlugin, DriverPlugin } from '@objectstack/runtime';
72
+ import { DriverPlugin } from '@objectstack/runtime';
73
+ import { ObjectQLPlugin } from '@objectstack/objectql';
73
74
  import { InMemoryDriver } from '@objectstack/driver-memory';
74
75
 
75
76
  const kernel = new ObjectKernel();
@@ -0,0 +1,196 @@
1
+ import { HookContext } from '@objectstack/spec/data';
2
+ import { DriverOptions } from '@objectstack/spec/system';
3
+ import { DriverInterface, IDataEngine, DataEngineQueryOptions } from '@objectstack/core';
4
+ export type HookHandler = (context: HookContext) => Promise<void> | void;
5
+ /**
6
+ * Host Context provided to plugins (Internal ObjectQL Plugin System)
7
+ */
8
+ export interface ObjectQLHostContext {
9
+ ql: ObjectQL;
10
+ logger: Console;
11
+ [key: string]: any;
12
+ }
13
+ /**
14
+ * ObjectQL Engine
15
+ *
16
+ * Implements the IDataEngine interface for data persistence.
17
+ */
18
+ export declare class ObjectQL implements IDataEngine {
19
+ private drivers;
20
+ private defaultDriver;
21
+ private hooks;
22
+ private hostContext;
23
+ constructor(hostContext?: Record<string, any>);
24
+ /**
25
+ * Load and Register a Plugin
26
+ */
27
+ use(manifestPart: any, runtimePart?: any): Promise<void>;
28
+ /**
29
+ * Register a hook
30
+ * @param event The event name (e.g. 'beforeFind', 'afterInsert')
31
+ * @param handler The handler function
32
+ */
33
+ registerHook(event: string, handler: HookHandler): void;
34
+ triggerHooks(event: string, context: HookContext): Promise<void>;
35
+ registerApp(manifestPart: any): void;
36
+ /**
37
+ * Register a new storage driver
38
+ */
39
+ registerDriver(driver: DriverInterface, isDefault?: boolean): void;
40
+ /**
41
+ * Helper to get object definition
42
+ */
43
+ getSchema(objectName: string): {
44
+ fields: Record<string, {
45
+ type: "number" | "boolean" | "code" | "date" | "text" | "textarea" | "email" | "url" | "phone" | "password" | "markdown" | "html" | "richtext" | "currency" | "percent" | "datetime" | "time" | "toggle" | "select" | "multiselect" | "radio" | "checkboxes" | "lookup" | "master_detail" | "tree" | "image" | "file" | "avatar" | "video" | "audio" | "formula" | "summary" | "autonumber" | "location" | "address" | "json" | "color" | "rating" | "slider" | "signature" | "qrcode" | "progress" | "tags" | "vector";
46
+ required: boolean;
47
+ searchable: boolean;
48
+ multiple: boolean;
49
+ unique: boolean;
50
+ deleteBehavior: "set_null" | "cascade" | "restrict";
51
+ hidden: boolean;
52
+ readonly: boolean;
53
+ encryption: boolean;
54
+ index: boolean;
55
+ externalId: boolean;
56
+ options?: {
57
+ value: string;
58
+ label: string;
59
+ color?: string | undefined;
60
+ default?: boolean | undefined;
61
+ }[] | undefined;
62
+ min?: number | undefined;
63
+ max?: number | undefined;
64
+ formula?: string | undefined;
65
+ label?: string | undefined;
66
+ precision?: number | undefined;
67
+ name?: string | undefined;
68
+ description?: string | undefined;
69
+ format?: string | undefined;
70
+ defaultValue?: any;
71
+ maxLength?: number | undefined;
72
+ minLength?: number | undefined;
73
+ scale?: number | undefined;
74
+ reference?: string | undefined;
75
+ referenceFilters?: string[] | undefined;
76
+ writeRequiresMasterRead?: boolean | undefined;
77
+ expression?: string | undefined;
78
+ summaryOperations?: {
79
+ object: string;
80
+ function: "count" | "sum" | "avg" | "min" | "max";
81
+ field: string;
82
+ } | undefined;
83
+ language?: string | undefined;
84
+ theme?: string | undefined;
85
+ lineNumbers?: boolean | undefined;
86
+ maxRating?: number | undefined;
87
+ allowHalf?: boolean | undefined;
88
+ displayMap?: boolean | undefined;
89
+ allowGeocoding?: boolean | undefined;
90
+ addressFormat?: "us" | "uk" | "international" | undefined;
91
+ colorFormat?: "hex" | "rgb" | "rgba" | "hsl" | undefined;
92
+ allowAlpha?: boolean | undefined;
93
+ presetColors?: string[] | undefined;
94
+ step?: number | undefined;
95
+ showValue?: boolean | undefined;
96
+ marks?: Record<string, string> | undefined;
97
+ barcodeFormat?: "qr" | "ean13" | "ean8" | "code128" | "code39" | "upca" | "upce" | undefined;
98
+ qrErrorCorrection?: "L" | "M" | "Q" | "H" | undefined;
99
+ displayValue?: boolean | undefined;
100
+ allowScanning?: boolean | undefined;
101
+ currencyConfig?: {
102
+ precision: number;
103
+ currencyMode: "dynamic" | "fixed";
104
+ defaultCurrency: string;
105
+ } | undefined;
106
+ vectorConfig?: {
107
+ dimensions: number;
108
+ distanceMetric: "cosine" | "euclidean" | "dotProduct" | "manhattan";
109
+ normalized: boolean;
110
+ indexed: boolean;
111
+ indexType?: "flat" | "hnsw" | "ivfflat" | undefined;
112
+ } | undefined;
113
+ }>;
114
+ name: string;
115
+ active: boolean;
116
+ isSystem: boolean;
117
+ abstract: boolean;
118
+ datasource: string;
119
+ tags?: string[] | undefined;
120
+ label?: string | undefined;
121
+ description?: string | undefined;
122
+ search?: {
123
+ fields: string[];
124
+ displayFields?: string[] | undefined;
125
+ filters?: string[] | undefined;
126
+ } | undefined;
127
+ pluralLabel?: string | undefined;
128
+ icon?: string | undefined;
129
+ tableName?: string | undefined;
130
+ indexes?: {
131
+ fields: string[];
132
+ type?: "hash" | "btree" | "gin" | "gist" | undefined;
133
+ name?: string | undefined;
134
+ unique?: boolean | undefined;
135
+ }[] | undefined;
136
+ validations?: any[] | undefined;
137
+ titleFormat?: string | undefined;
138
+ compactLayout?: string[] | undefined;
139
+ enable?: {
140
+ searchable: boolean;
141
+ trackHistory: boolean;
142
+ apiEnabled: boolean;
143
+ files: boolean;
144
+ feeds: boolean;
145
+ activities: boolean;
146
+ trash: boolean;
147
+ mru: boolean;
148
+ clone: boolean;
149
+ apiMethods?: ("update" | "delete" | "get" | "list" | "create" | "upsert" | "bulk" | "aggregate" | "history" | "search" | "restore" | "purge" | "import" | "export")[] | undefined;
150
+ } | undefined;
151
+ } | undefined;
152
+ /**
153
+ * Helper to get the target driver
154
+ */
155
+ private getDriver;
156
+ /**
157
+ * Initialize the engine and all registered drivers
158
+ */
159
+ init(): Promise<void>;
160
+ destroy(): Promise<void>;
161
+ /**
162
+ * Find records matching a query (IDataEngine interface)
163
+ *
164
+ * @param object - Object name
165
+ * @param query - Query options (IDataEngine format)
166
+ * @returns Promise resolving to array of records
167
+ */
168
+ find(object: string, query?: DataEngineQueryOptions): Promise<any[]>;
169
+ findOne(object: string, idOrQuery: string | any, options?: DriverOptions): Promise<any>;
170
+ /**
171
+ * Insert a new record (IDataEngine interface)
172
+ *
173
+ * @param object - Object name
174
+ * @param data - Data to insert
175
+ * @returns Promise resolving to the created record
176
+ */
177
+ insert(object: string, data: any): Promise<any>;
178
+ /**
179
+ * Update a record by ID (IDataEngine interface)
180
+ *
181
+ * @param object - Object name
182
+ * @param id - Record ID
183
+ * @param data - Updated data
184
+ * @returns Promise resolving to the updated record
185
+ */
186
+ update(object: string, id: any, data: any): Promise<any>;
187
+ /**
188
+ * Delete a record by ID (IDataEngine interface)
189
+ *
190
+ * @param object - Object name
191
+ * @param id - Record ID
192
+ * @returns Promise resolving to true if deleted, false otherwise
193
+ */
194
+ delete(object: string, id: any): Promise<boolean>;
195
+ }
196
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE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jectQL Engine
4
+ *
5
+ * Implements the IDataEngine interface for data persistence.
6
+ */
7
+ export class ObjectQL {
8
+ constructor(hostContext = {}) {
9
+ this.drivers = new Map();
10
+ this.defaultDriver = null;
11
+ // Hooks Registry
12
+ this.hooks = {
13
+ 'beforeFind': [], 'afterFind': [],
14
+ 'beforeInsert': [], 'afterInsert': [],
15
+ 'beforeUpdate': [], 'afterUpdate': [],
16
+ 'beforeDelete': [], 'afterDelete': [],
17
+ };
18
+ // Host provided context additions (e.g. Server router)
19
+ this.hostContext = {};
20
+ this.hostContext = hostContext;
21
+ console.log(`[ObjectQL] Engine Instance Created`);
22
+ }
23
+ /**
24
+ * Load and Register a Plugin
25
+ */
26
+ async use(manifestPart, runtimePart) {
27
+ // 1. Validate / Register Manifest
28
+ if (manifestPart) {
29
+ this.registerApp(manifestPart);
30
+ }
31
+ // 2. Execute Runtime
32
+ if (runtimePart) {
33
+ const pluginDef = runtimePart.default || runtimePart;
34
+ if (pluginDef.onEnable) {
35
+ const context = {
36
+ ql: this,
37
+ logger: console,
38
+ // Expose the driver registry helper explicitly if needed
39
+ drivers: {
40
+ register: (driver) => this.registerDriver(driver)
41
+ },
42
+ ...this.hostContext
43
+ };
44
+ await pluginDef.onEnable(context);
45
+ }
46
+ }
47
+ }
48
+ /**
49
+ * Register a hook
50
+ * @param event The event name (e.g. 'beforeFind', 'afterInsert')
51
+ * @param handler The handler function
52
+ */
53
+ registerHook(event, handler) {
54
+ if (!this.hooks[event]) {
55
+ this.hooks[event] = [];
56
+ }
57
+ this.hooks[event].push(handler);
58
+ console.log(`[ObjectQL] Registered hook for ${event}`);
59
+ }
60
+ async triggerHooks(event, context) {
61
+ const handlers = this.hooks[event] || [];
62
+ for (const handler of handlers) {
63
+ // In a real system, we might want to catch errors here or allow them to bubble up
64
+ await handler(context);
65
+ }
66
+ }
67
+ registerApp(manifestPart) {
68
+ // 1. Handle Module Imports (commonjs/esm interop)
69
+ // If the passed object is a module namespace with a default export, use that.
70
+ const raw = manifestPart.default || manifestPart;
71
+ // Support nested manifest property (Stack Definition)
72
+ // We merge the inner manifest metadata (id, version, etc) with the outer container (objects, apps)
73
+ const manifest = raw.manifest ? { ...raw, ...raw.manifest } : raw;
74
+ // In a real scenario, we might strictly parse this using Zod
75
+ // For now, simple ID check
76
+ const id = manifest.id || manifest.name;
77
+ if (!id) {
78
+ console.warn(`[ObjectQL] Plugin manifest missing ID (keys: ${Object.keys(manifest)})`, manifest);
79
+ // Don't return, try to proceed if it looks like an App (Apps might use 'name' instead of 'id')
80
+ // return;
81
+ }
82
+ console.log(`[ObjectQL] Loading App: ${id}`);
83
+ SchemaRegistry.registerPlugin(manifest);
84
+ // Register Objects from App/Plugin
85
+ if (manifest.objects) {
86
+ for (const obj of manifest.objects) {
87
+ // Ensure object name is registered globally
88
+ SchemaRegistry.registerObject(obj);
89
+ console.log(`[ObjectQL] Registered Object: ${obj.name}`);
90
+ }
91
+ }
92
+ // Register contributions
93
+ if (manifest.contributes?.kinds) {
94
+ for (const kind of manifest.contributes.kinds) {
95
+ SchemaRegistry.registerKind(kind);
96
+ }
97
+ }
98
+ }
99
+ /**
100
+ * Register a new storage driver
101
+ */
102
+ registerDriver(driver, isDefault = false) {
103
+ if (this.drivers.has(driver.name)) {
104
+ console.warn(`[ObjectQL] Driver ${driver.name} is already registered. Skipping.`);
105
+ return;
106
+ }
107
+ this.drivers.set(driver.name, driver);
108
+ console.log(`[ObjectQL] Registered driver: ${driver.name} v${driver.version}`);
109
+ if (isDefault || this.drivers.size === 1) {
110
+ this.defaultDriver = driver.name;
111
+ }
112
+ }
113
+ /**
114
+ * Helper to get object definition
115
+ */
116
+ getSchema(objectName) {
117
+ return SchemaRegistry.getObject(objectName);
118
+ }
119
+ /**
120
+ * Helper to get the target driver
121
+ */
122
+ getDriver(objectName) {
123
+ const object = SchemaRegistry.getObject(objectName);
124
+ // 1. If object definition exists, check for explicit datasource
125
+ if (object) {
126
+ const datasourceName = object.datasource || 'default';
127
+ // If configured for 'default', try to find the default driver
128
+ if (datasourceName === 'default') {
129
+ if (this.defaultDriver && this.drivers.has(this.defaultDriver)) {
130
+ return this.drivers.get(this.defaultDriver);
131
+ }
132
+ // Fallback: If 'default' not explicitly set, use the first available driver?
133
+ // Better to be strict.
134
+ }
135
+ else {
136
+ // Specific datasource requested
137
+ if (this.drivers.has(datasourceName)) {
138
+ return this.drivers.get(datasourceName);
139
+ }
140
+ // If not found, fall back to default? Or error?
141
+ // Standard behavior: Error if specific datasource is missing.
142
+ throw new Error(`[ObjectQL] Datasource '${datasourceName}' configured for object '${objectName}' is not registered.`);
143
+ }
144
+ }
145
+ // 2. Fallback for ad-hoc objects or missing definitions
146
+ // If we have a default driver, use it.
147
+ if (this.defaultDriver) {
148
+ if (!object) {
149
+ console.warn(`[ObjectQL] Object '${objectName}' not found in registry. Using default driver.`);
150
+ }
151
+ return this.drivers.get(this.defaultDriver);
152
+ }
153
+ throw new Error(`[ObjectQL] No driver available for object '${objectName}'`);
154
+ }
155
+ /**
156
+ * Initialize the engine and all registered drivers
157
+ */
158
+ async init() {
159
+ console.log('[ObjectQL] Initializing drivers...');
160
+ for (const [name, driver] of this.drivers) {
161
+ try {
162
+ await driver.connect();
163
+ }
164
+ catch (e) {
165
+ console.error(`[ObjectQL] Failed to connect driver ${name}`, e);
166
+ }
167
+ }
168
+ // In a real app, we would sync schemas here
169
+ }
170
+ async destroy() {
171
+ for (const driver of this.drivers.values()) {
172
+ await driver.disconnect();
173
+ }
174
+ }
175
+ // ============================================
176
+ // Data Access Methods (IDataEngine Interface)
177
+ // ============================================
178
+ /**
179
+ * Find records matching a query (IDataEngine interface)
180
+ *
181
+ * @param object - Object name
182
+ * @param query - Query options (IDataEngine format)
183
+ * @returns Promise resolving to array of records
184
+ */
185
+ async find(object, query) {
186
+ const driver = this.getDriver(object);
187
+ // Convert DataEngineQueryOptions to QueryAST
188
+ let ast = { object };
189
+ if (query) {
190
+ // Map DataEngineQueryOptions to QueryAST
191
+ if (query.filter) {
192
+ ast.where = query.filter;
193
+ }
194
+ if (query.select) {
195
+ ast.fields = query.select;
196
+ }
197
+ if (query.sort) {
198
+ // Convert sort Record to orderBy array
199
+ // sort: { createdAt: -1, name: 'asc' } => orderBy: [{ field: 'createdAt', order: 'desc' }, { field: 'name', order: 'asc' }]
200
+ ast.orderBy = Object.entries(query.sort).map(([field, order]) => ({
201
+ field,
202
+ order: (order === -1 || order === 'desc') ? 'desc' : 'asc'
203
+ }));
204
+ }
205
+ // Handle both limit and top (top takes precedence)
206
+ if (query.top !== undefined) {
207
+ ast.limit = query.top;
208
+ }
209
+ else if (query.limit !== undefined) {
210
+ ast.limit = query.limit;
211
+ }
212
+ if (query.skip !== undefined) {
213
+ ast.offset = query.skip;
214
+ }
215
+ }
216
+ // Set default limit if not specified
217
+ if (ast.limit === undefined)
218
+ ast.limit = 100;
219
+ // Trigger Before Hook
220
+ const hookContext = {
221
+ object,
222
+ event: 'beforeFind',
223
+ input: { ast, options: undefined },
224
+ ql: this
225
+ };
226
+ await this.triggerHooks('beforeFind', hookContext);
227
+ try {
228
+ const result = await driver.find(object, hookContext.input.ast, hookContext.input.options);
229
+ // Trigger After Hook
230
+ hookContext.event = 'afterFind';
231
+ hookContext.result = result;
232
+ await this.triggerHooks('afterFind', hookContext);
233
+ return hookContext.result;
234
+ }
235
+ catch (e) {
236
+ // hookContext.error = e;
237
+ throw e;
238
+ }
239
+ }
240
+ async findOne(object, idOrQuery, options) {
241
+ const driver = this.getDriver(object);
242
+ let ast;
243
+ if (typeof idOrQuery === 'string') {
244
+ ast = {
245
+ object,
246
+ where: { _id: idOrQuery }
247
+ };
248
+ }
249
+ else {
250
+ // Assume query object
251
+ // reuse logic from find() or just wrap it
252
+ if (idOrQuery.where || idOrQuery.fields) {
253
+ ast = { object, ...idOrQuery };
254
+ }
255
+ else {
256
+ ast = { object, where: idOrQuery };
257
+ }
258
+ }
259
+ // Limit 1 for findOne
260
+ ast.limit = 1;
261
+ return driver.findOne(object, ast, options);
262
+ }
263
+ /**
264
+ * Insert a new record (IDataEngine interface)
265
+ *
266
+ * @param object - Object name
267
+ * @param data - Data to insert
268
+ * @returns Promise resolving to the created record
269
+ */
270
+ async insert(object, data) {
271
+ const driver = this.getDriver(object);
272
+ // 1. Get Schema
273
+ const schema = SchemaRegistry.getObject(object);
274
+ if (schema) {
275
+ // TODO: Validation Logic
276
+ // validate(schema, data);
277
+ }
278
+ // 2. Trigger Before Hook
279
+ const hookContext = {
280
+ object,
281
+ event: 'beforeInsert',
282
+ input: { data, options: undefined },
283
+ ql: this
284
+ };
285
+ await this.triggerHooks('beforeInsert', hookContext);
286
+ // 3. Execute Driver
287
+ const result = await driver.create(object, hookContext.input.data, hookContext.input.options);
288
+ // 4. Trigger After Hook
289
+ hookContext.event = 'afterInsert';
290
+ hookContext.result = result;
291
+ await this.triggerHooks('afterInsert', hookContext);
292
+ return hookContext.result;
293
+ }
294
+ /**
295
+ * Update a record by ID (IDataEngine interface)
296
+ *
297
+ * @param object - Object name
298
+ * @param id - Record ID
299
+ * @param data - Updated data
300
+ * @returns Promise resolving to the updated record
301
+ */
302
+ async update(object, id, data) {
303
+ const driver = this.getDriver(object);
304
+ const hookContext = {
305
+ object,
306
+ event: 'beforeUpdate',
307
+ input: { id, data, options: undefined },
308
+ ql: this
309
+ };
310
+ await this.triggerHooks('beforeUpdate', hookContext);
311
+ const result = await driver.update(object, hookContext.input.id, hookContext.input.data, hookContext.input.options);
312
+ hookContext.event = 'afterUpdate';
313
+ hookContext.result = result;
314
+ await this.triggerHooks('afterUpdate', hookContext);
315
+ return hookContext.result;
316
+ }
317
+ /**
318
+ * Delete a record by ID (IDataEngine interface)
319
+ *
320
+ * @param object - Object name
321
+ * @param id - Record ID
322
+ * @returns Promise resolving to true if deleted, false otherwise
323
+ */
324
+ async delete(object, id) {
325
+ const driver = this.getDriver(object);
326
+ const hookContext = {
327
+ object,
328
+ event: 'beforeDelete',
329
+ input: { id, options: undefined },
330
+ ql: this
331
+ };
332
+ await this.triggerHooks('beforeDelete', hookContext);
333
+ const result = await driver.delete(object, hookContext.input.id, hookContext.input.options);
334
+ hookContext.event = 'afterDelete';
335
+ hookContext.result = result;
336
+ await this.triggerHooks('afterDelete', hookContext);
337
+ // Driver.delete() already returns boolean per DriverInterface spec
338
+ return hookContext.result;
339
+ }
340
+ }