@objectql/core 4.0.0 → 4.0.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +17 -3
  2. package/README.md +3 -3
  3. package/dist/app.d.ts +1 -1
  4. package/dist/app.js +1 -1
  5. package/dist/app.js.map +1 -1
  6. package/dist/formula-plugin.d.ts +1 -1
  7. package/dist/index.d.ts +5 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/plugin.d.ts +2 -2
  10. package/dist/plugin.js +40 -3
  11. package/dist/plugin.js.map +1 -1
  12. package/dist/query/filter-translator.d.ts +3 -1
  13. package/dist/query/filter-translator.js.map +1 -1
  14. package/dist/query/query-analyzer.d.ts +3 -1
  15. package/dist/query/query-analyzer.js.map +1 -1
  16. package/dist/query/query-builder.d.ts +3 -1
  17. package/dist/query/query-builder.js.map +1 -1
  18. package/dist/query/query-service.d.ts +3 -1
  19. package/dist/query/query-service.js.map +1 -1
  20. package/dist/repository.js +19 -1
  21. package/dist/repository.js.map +1 -1
  22. package/dist/validator-plugin.d.ts +1 -1
  23. package/jest.config.js +1 -1
  24. package/package.json +4 -5
  25. package/src/app.ts +3 -3
  26. package/src/formula-plugin.ts +1 -1
  27. package/src/index.ts +5 -2
  28. package/src/plugin.ts +50 -5
  29. package/src/query/filter-translator.ts +2 -1
  30. package/src/query/query-analyzer.ts +3 -1
  31. package/src/query/query-builder.ts +2 -1
  32. package/src/query/query-service.ts +2 -1
  33. package/src/repository.ts +22 -3
  34. package/src/validator-plugin.ts +1 -1
  35. package/test/__mocks__/@objectstack/runtime.ts +1 -1
  36. package/test/formula-plugin.test.ts +1 -1
  37. package/test/validator-plugin.test.ts +1 -1
  38. package/tsconfig.json +0 -1
  39. package/tsconfig.tsbuildinfo +1 -1
  40. package/IMPLEMENTATION_STATUS.md +0 -364
  41. package/RUNTIME_INTEGRATION.md +0 -391
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
 
9
- import type { RuntimePlugin, RuntimeContext, ObjectStackKernel } from '@objectstack/runtime';
9
+ import type { RuntimePlugin, RuntimeContext, ObjectStackKernel } from '@objectql/runtime';
10
10
  import { FormulaEngine } from './formula-engine';
11
11
  import type { FormulaEngineConfig } from '@objectql/types';
12
12
 
package/src/index.ts CHANGED
@@ -7,13 +7,16 @@
7
7
  */
8
8
 
9
9
  // Re-export types from @objectstack packages for API compatibility
10
- export type { ObjectStackKernel, ObjectStackRuntimeProtocol } from '@objectstack/runtime';
10
+ export type { ObjectStackKernel, ObjectStackRuntimeProtocol } from '@objectql/runtime';
11
11
  // Note: @objectstack/objectql types temporarily commented out due to type incompatibilities
12
12
  // in the published package. Will be re-enabled when package is updated.
13
13
  // export type { ObjectQL as ObjectQLEngine, SchemaRegistry } from '@objectstack/objectql';
14
14
 
15
15
  // Export ObjectStack spec types for driver development
16
- export type { DriverInterface, DriverOptions, QueryAST } from '@objectstack/spec';
16
+ import { Data, System } from '@objectstack/spec';
17
+ export type QueryAST = Data.QueryAST;
18
+ export type DriverInterface = System.DriverInterface;
19
+ export type DriverOptions = System.DriverOptions;
17
20
 
18
21
  // Export our enhanced runtime components (actual implementations)
19
22
  export * from './repository';
package/src/plugin.ts CHANGED
@@ -6,8 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
 
9
- import type { RuntimePlugin, RuntimeContext } from '@objectstack/runtime';
10
- import type { ObjectStackKernel } from '@objectstack/runtime';
9
+ import type { RuntimePlugin, RuntimeContext } from '@objectql/runtime';
10
+ import type { ObjectStackKernel } from '@objectql/runtime';
11
11
  import { ValidatorPlugin, ValidatorPluginConfig } from './validator-plugin';
12
12
  import { FormulaPlugin, FormulaPluginConfig } from './formula-plugin';
13
13
  import { QueryService } from './query/query-service';
@@ -78,7 +78,7 @@ export interface ObjectQLPluginConfig {
78
78
  /**
79
79
  * ObjectQL Plugin
80
80
  *
81
- * Implements the RuntimePlugin interface from @objectstack/runtime
81
+ * Implements the RuntimePlugin interface from @objectql/runtime
82
82
  * to provide ObjectQL's enhanced features (Repository, Validator, Formula, AI)
83
83
  * on top of the ObjectStack kernel.
84
84
  */
@@ -162,8 +162,53 @@ export class ObjectQLPlugin implements RuntimePlugin {
162
162
  * @private
163
163
  */
164
164
  private async registerRepository(kernel: ObjectStackKernel): Promise<void> {
165
- // TODO: Implement repository registration
166
- // For now, this is a placeholder to establish the structure
165
+ if (!this.config.datasources) {
166
+ console.log(`[${this.name}] No datasources configured, skipping repository registration`);
167
+ return;
168
+ }
169
+
170
+ const datasources = this.config.datasources;
171
+
172
+ // Helper function to get the driver for an object
173
+ const getDriver = (objectName: string): Driver => {
174
+ const objectConfig = kernel.metadata.get<any>('object', objectName);
175
+ const datasourceName = objectConfig?.datasource || 'default';
176
+ const driver = datasources[datasourceName];
177
+ if (!driver) {
178
+ throw new Error(`Datasource '${datasourceName}' not found for object '${objectName}'`);
179
+ }
180
+ return driver;
181
+ };
182
+
183
+ // Override kernel CRUD methods to use drivers
184
+ kernel.create = async (objectName: string, data: any): Promise<any> => {
185
+ const driver = getDriver(objectName);
186
+ return await driver.create(objectName, data, {});
187
+ };
188
+
189
+ kernel.update = async (objectName: string, id: string, data: any): Promise<any> => {
190
+ const driver = getDriver(objectName);
191
+ return await driver.update(objectName, id, data, {});
192
+ };
193
+
194
+ kernel.delete = async (objectName: string, id: string): Promise<boolean> => {
195
+ const driver = getDriver(objectName);
196
+ const result = await driver.delete(objectName, id, {});
197
+ return !!result;
198
+ };
199
+
200
+ kernel.find = async (objectName: string, query: any): Promise<{ value: any[]; count: number }> => {
201
+ const driver = getDriver(objectName);
202
+ const value = await driver.find(objectName, query);
203
+ const count = value.length;
204
+ return { value, count };
205
+ };
206
+
207
+ kernel.get = async (objectName: string, id: string): Promise<any> => {
208
+ const driver = getDriver(objectName);
209
+ return await driver.findOne(objectName, id);
210
+ };
211
+
167
212
  console.log(`[${this.name}] Repository pattern registered`);
168
213
  }
169
214
 
@@ -7,7 +7,8 @@
7
7
  */
8
8
 
9
9
  import type { Filter } from '@objectql/types';
10
- import type { FilterNode } from '@objectstack/spec';
10
+ import { Data } from '@objectstack/spec';
11
+ type FilterNode = Data.FilterNode;
11
12
  import { ObjectQLError } from '@objectql/types';
12
13
 
13
14
  /**
@@ -7,7 +7,9 @@
7
7
  */
8
8
 
9
9
  import type { UnifiedQuery, ObjectConfig, MetadataRegistry } from '@objectql/types';
10
- import type { QueryAST, FilterNode } from '@objectstack/spec';
10
+ import { Data } from '@objectstack/spec';
11
+ type QueryAST = Data.QueryAST;
12
+ type FilterNode = Data.FilterNode;
11
13
  import { QueryService, QueryOptions } from './query-service';
12
14
 
13
15
  /**
@@ -7,7 +7,8 @@
7
7
  */
8
8
 
9
9
  import type { UnifiedQuery } from '@objectql/types';
10
- import type { QueryAST } from '@objectstack/spec';
10
+ import { Data } from '@objectstack/spec';
11
+ type QueryAST = Data.QueryAST;
11
12
  import { FilterTranslator } from './filter-translator';
12
13
 
13
14
  /**
@@ -13,7 +13,8 @@ import type {
13
13
  Filter,
14
14
  MetadataRegistry
15
15
  } from '@objectql/types';
16
- import type { QueryAST } from '@objectstack/spec';
16
+ import { Data } from '@objectstack/spec';
17
+ type QueryAST = Data.QueryAST;
17
18
  import { QueryBuilder } from './query-builder';
18
19
 
19
20
  /**
package/src/repository.ts CHANGED
@@ -7,8 +7,11 @@
7
7
  */
8
8
 
9
9
  import { ObjectQLContext, IObjectQL, ObjectConfig, Driver, UnifiedQuery, ActionContext, HookAPI, RetrievalHookContext, MutationHookContext, UpdateHookContext, ValidationContext, ValidationError, ValidationRuleResult, FormulaContext, Filter } from '@objectql/types';
10
- import type { ObjectStackKernel } from '@objectstack/runtime';
11
- import type { QueryAST, FilterNode, SortNode } from '@objectstack/spec';
10
+ import type { ObjectStackKernel } from '@objectql/runtime';
11
+ import { Data } from '@objectstack/spec';
12
+ type QueryAST = Data.QueryAST;
13
+ type FilterNode = Data.FilterNode;
14
+ type SortNode = Data.SortNode;
12
15
  import { Validator } from './validator';
13
16
  import { FormulaEngine } from './formula-engine';
14
17
  import { QueryBuilder } from './query';
@@ -311,6 +314,22 @@ export class ObjectRepository {
311
314
  }
312
315
 
313
316
  async count(filters: any): Promise<number> {
317
+ // Normalize filters to UnifiedQuery format
318
+ // If filters is an array, wrap it in a query object
319
+ // If filters is already a UnifiedQuery (has UnifiedQuery-specific properties), use it as-is
320
+ let query: UnifiedQuery;
321
+ if (Array.isArray(filters)) {
322
+ query = { filters };
323
+ } else if (filters && typeof filters === 'object' && (filters.fields || filters.sort || filters.limit !== undefined || filters.skip !== undefined)) {
324
+ // It's already a UnifiedQuery object
325
+ query = filters;
326
+ } else if (filters) {
327
+ // It's a raw filter object, wrap it
328
+ query = { filters };
329
+ } else {
330
+ query = {};
331
+ }
332
+
314
333
  const hookCtx: RetrievalHookContext = {
315
334
  ...this.context,
316
335
  objectName: this.objectName,
@@ -318,7 +337,7 @@ export class ObjectRepository {
318
337
  api: this.getHookAPI(),
319
338
  user: this.getUserFromContext(),
320
339
  state: {},
321
- query: filters
340
+ query
322
341
  };
323
342
  await this.app.triggerHook('beforeCount', this.objectName, hookCtx);
324
343
 
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
 
9
- import type { RuntimePlugin, RuntimeContext, ObjectStackKernel } from '@objectstack/runtime';
9
+ import type { RuntimePlugin, RuntimeContext, ObjectStackKernel } from '@objectql/runtime';
10
10
  import { Validator, ValidatorOptions } from './validator';
11
11
 
12
12
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Mock for @objectstack/runtime
2
+ * Mock for @objectql/runtime
3
3
  * This mock is needed because the npm package has issues with Jest
4
4
  * and we want to focus on testing ObjectQL's logic, not the kernel integration.
5
5
  *
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import { FormulaPlugin } from '../src/formula-plugin';
10
- import { ObjectStackKernel } from '@objectstack/runtime';
10
+ import { ObjectStackKernel } from '@objectql/runtime';
11
11
 
12
12
  describe('FormulaPlugin', () => {
13
13
  let plugin: FormulaPlugin;
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import { ValidatorPlugin } from '../src/validator-plugin';
10
- import { ObjectStackKernel } from '@objectstack/runtime';
10
+ import { ObjectStackKernel } from '@objectql/runtime';
11
11
 
12
12
  describe('ValidatorPlugin', () => {
13
13
  let plugin: ValidatorPlugin;
package/tsconfig.json CHANGED
@@ -13,7 +13,6 @@
13
13
  "../../../node_modules/@objectstack+objectql"
14
14
  ],
15
15
  "references": [
16
- { "path": "../../objectstack/spec" },
17
16
  { "path": "../../objectstack/runtime" },
18
17
  { "path": "../types" }
19
18
  ]