@objectql/types 1.2.0 → 1.3.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 (46) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/app.d.ts +22 -0
  3. package/dist/app.js +3 -0
  4. package/dist/app.js.map +1 -0
  5. package/dist/config.d.ts +36 -0
  6. package/dist/config.js +3 -0
  7. package/dist/config.js.map +1 -0
  8. package/dist/context.d.ts +35 -0
  9. package/dist/context.js +3 -0
  10. package/dist/context.js.map +1 -0
  11. package/dist/index.d.ts +6 -1
  12. package/dist/index.js +6 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/loader.d.ts +14 -0
  15. package/dist/loader.js +3 -0
  16. package/dist/loader.js.map +1 -0
  17. package/dist/plugin.d.ts +5 -0
  18. package/dist/plugin.js +3 -0
  19. package/dist/plugin.js.map +1 -0
  20. package/dist/registry.d.ts +1 -1
  21. package/dist/registry.js +3 -3
  22. package/dist/registry.js.map +1 -1
  23. package/dist/repository.d.ts +16 -0
  24. package/dist/repository.js +3 -0
  25. package/dist/repository.js.map +1 -0
  26. package/package.json +2 -2
  27. package/src/app.ts +26 -0
  28. package/src/config.ts +37 -0
  29. package/src/context.ts +45 -0
  30. package/src/index.ts +6 -1
  31. package/src/loader.ts +17 -0
  32. package/src/plugin.ts +6 -0
  33. package/src/registry.ts +1 -1
  34. package/src/repository.ts +17 -0
  35. package/tsconfig.tsbuildinfo +1 -1
  36. package/dist/types.d.ts +0 -103
  37. package/dist/types.js +0 -22
  38. package/dist/types.js.map +0 -1
  39. package/src/types.ts +0 -120
  40. package/test/dynamic.test.ts +0 -34
  41. package/test/fixtures/project.action.ts +0 -6
  42. package/test/fixtures/project.object.yml +0 -41
  43. package/test/loader.test.ts +0 -22
  44. package/test/metadata.test.ts +0 -49
  45. package/test/mock-driver.ts +0 -86
  46. package/test/repository.test.ts +0 -151
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @objectql/core
2
2
 
3
+ ## 1.3.1
4
+
5
+ ## 1.3.0
6
+
7
+ ### Minor Changes
8
+
9
+ - Refactor core architecture: split logic into modules (driver, remote, action, hook, object, plugin).
10
+ Rename `ObjectRegistry` to `MetadataRegistry` to support generic metadata.
11
+ Add `addLoader` API to support custom metadata loaders in plugins.
12
+ Update initialization lifecycle to allow plugins to register loaders before source scanning.
13
+
3
14
  ## 1.2.0
4
15
 
5
16
  ### Minor Changes
package/dist/app.d.ts ADDED
@@ -0,0 +1,22 @@
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
+ export interface IObjectQL {
8
+ getObject(name: string): ObjectConfig | undefined;
9
+ getConfigs(): Record<string, ObjectConfig>;
10
+ datasource(name: string): Driver;
11
+ init(): Promise<void>;
12
+ addPackage(name: string): void;
13
+ removePackage(name: string): void;
14
+ metadata: MetadataRegistry;
15
+ registerObject(object: ObjectConfig): void;
16
+ loadFromDirectory(dir: string): void;
17
+ addLoader(plugin: LoaderPlugin): void;
18
+ on(event: HookName, objectName: string, handler: HookHandler): void;
19
+ triggerHook(event: HookName, objectName: string, ctx: HookContext): Promise<void>;
20
+ registerAction(objectName: string, actionName: string, handler: ActionHandler): void;
21
+ executeAction(objectName: string, actionName: string, ctx: ActionContext): Promise<any>;
22
+ }
package/dist/app.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ import { MetadataRegistry } from "./registry";
2
+ import { Driver } from "./driver";
3
+ import { ObjectConfig } from "./object";
4
+ import { ObjectQLPlugin } from "./plugin";
5
+ export interface ObjectQLConfig {
6
+ registry?: MetadataRegistry;
7
+ datasources?: Record<string, Driver>;
8
+ /**
9
+ * Optional connection string for auto-configuration.
10
+ * e.g. "sqlite://dev.db", "postgres://localhost/db", "mongodb://localhost/db"
11
+ */
12
+ connection?: string;
13
+ /**
14
+ * Path(s) to the directory containing schema files (*.object.yml).
15
+ */
16
+ source?: string | string[];
17
+ objects?: Record<string, ObjectConfig>;
18
+ /**
19
+ * @deprecated Use 'presets' instead.
20
+ */
21
+ packages?: string[];
22
+ /**
23
+ * List of npm packages or presets to load.
24
+ */
25
+ presets?: string[];
26
+ /**
27
+ * List of plugins to load.
28
+ * Can be an instance of ObjectQLPlugin or a package name string.
29
+ */
30
+ plugins?: (ObjectQLPlugin | string)[];
31
+ /**
32
+ * List of remote ObjectQL instances to connect to.
33
+ * e.g. ["http://user-service:3000", "http://order-service:3000"]
34
+ */
35
+ remotes?: string[];
36
+ }
package/dist/config.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ import { IObjectRepository } from './repository';
2
+ export interface ObjectQLContext {
3
+ userId?: string;
4
+ spaceId?: string;
5
+ roles: string[];
6
+ /**
7
+ * Sudo Mode / System Bypass.
8
+ */
9
+ isSystem?: boolean;
10
+ /**
11
+ * Returns a repository proxy bound to this context.
12
+ * All operations performed via this proxy inherit userId, spaceId, and transaction.
13
+ */
14
+ object(entityName: string): IObjectRepository;
15
+ /**
16
+ * Execute a function within a transaction.
17
+ * The callback receives a new context 'trxCtx' which inherits userId, spaceId from this context.
18
+ */
19
+ transaction(callback: (trxCtx: ObjectQLContext) => Promise<any>): Promise<any>;
20
+ /**
21
+ * Returns a new context with system privileges (isSystem: true).
22
+ * It shares the same transaction scope as the current context.
23
+ */
24
+ sudo(): ObjectQLContext;
25
+ /**
26
+ * Internal: Driver-specific transaction handle.
27
+ */
28
+ transactionHandle?: any;
29
+ }
30
+ export interface ObjectQLContextOptions {
31
+ userId?: string;
32
+ spaceId?: string;
33
+ roles?: string[];
34
+ isSystem?: boolean;
35
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,13 @@
1
1
  export * from './field';
2
2
  export * from './object';
3
- export * from './types';
4
3
  export * from './driver';
5
4
  export * from './query';
6
5
  export * from './registry';
7
6
  export * from './hook';
8
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 './loader';
package/dist/index.js CHANGED
@@ -16,10 +16,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./field"), exports);
18
18
  __exportStar(require("./object"), exports);
19
- __exportStar(require("./types"), exports);
20
19
  __exportStar(require("./driver"), exports);
21
20
  __exportStar(require("./query"), exports);
22
21
  __exportStar(require("./registry"), exports);
23
22
  __exportStar(require("./hook"), exports);
24
23
  __exportStar(require("./action"), exports);
24
+ __exportStar(require("./repository"), exports);
25
+ __exportStar(require("./app"), exports);
26
+ __exportStar(require("./plugin"), exports);
27
+ __exportStar(require("./config"), exports);
28
+ __exportStar(require("./context"), exports);
29
+ __exportStar(require("./loader"), exports);
25
30
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,yCAAuB;AACvB,2CAAyB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,yCAAuB;AACvB,2CAAyB;AACzB,+CAA6B;AAC7B,wCAAsB;AACtB,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAG1B,2CAAyB"}
@@ -0,0 +1,14 @@
1
+ import { MetadataRegistry } from './registry';
2
+ export interface LoaderHandlerContext {
3
+ file: string;
4
+ content: string;
5
+ registry: MetadataRegistry;
6
+ packageName?: string;
7
+ }
8
+ export type LoaderHandler = (ctx: LoaderHandlerContext) => void;
9
+ export interface LoaderPlugin {
10
+ name: string;
11
+ glob: string[];
12
+ handler: LoaderHandler;
13
+ options?: any;
14
+ }
package/dist/loader.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { IObjectQL } from './app';
2
+ export interface ObjectQLPlugin {
3
+ name: string;
4
+ setup(app: IObjectQL): void | Promise<void>;
5
+ }
package/dist/plugin.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":""}
@@ -5,7 +5,7 @@ export interface Metadata {
5
5
  package?: string;
6
6
  content: any;
7
7
  }
8
- export declare class ObjectRegistry {
8
+ export declare class MetadataRegistry {
9
9
  private store;
10
10
  register(type: string, metadata: Metadata): void;
11
11
  unregister(type: string, id: string): void;
package/dist/registry.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ObjectRegistry = void 0;
4
- class ObjectRegistry {
3
+ exports.MetadataRegistry = void 0;
4
+ class MetadataRegistry {
5
5
  constructor() {
6
6
  // Map<type, Map<id, Metadata>>
7
7
  this.store = new Map();
@@ -42,5 +42,5 @@ class ObjectRegistry {
42
42
  return this.store.get(type)?.get(id);
43
43
  }
44
44
  }
45
- exports.ObjectRegistry = ObjectRegistry;
45
+ exports.MetadataRegistry = MetadataRegistry;
46
46
  //# sourceMappingURL=registry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":";;;AAQA,MAAa,cAAc;IAA3B;QACI,+BAA+B;QACvB,UAAK,GAAuC,IAAI,GAAG,EAAE,CAAC;IA2ClE,CAAC;IAzCG,QAAQ,CAAC,IAAY,EAAE,QAAkB;QACrC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QACpC,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IACrD,CAAC;IAED,UAAU,CAAC,IAAY,EAAE,EAAU;QAC/B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;IAED,iBAAiB,CAAC,WAAmB;QACjC,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAC7C,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,IAAI,CAAC,GAAG;YAAE,OAAO,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAY,CAAC,CAAC;IAC7D,CAAC;IAED,QAAQ,CAAC,IAAY,EAAE,EAAU;QAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IACzC,CAAC;CACJ;AA7CD,4CA6CC"}
@@ -0,0 +1,16 @@
1
+ import { UnifiedQuery } from "./query";
2
+ export interface IObjectRepository {
3
+ find(query?: UnifiedQuery): Promise<any[]>;
4
+ findOne(idOrQuery: string | number | UnifiedQuery): Promise<any>;
5
+ count(filters: any): Promise<number>;
6
+ create(doc: any): Promise<any>;
7
+ update(id: string | number, doc: any, options?: any): Promise<any>;
8
+ delete(id: string | number): Promise<any>;
9
+ aggregate(query: any): Promise<any>;
10
+ distinct(field: string, filters?: any): Promise<any[]>;
11
+ findOneAndUpdate?(filters: any, update: any, options?: any): Promise<any>;
12
+ createMany(data: any[]): Promise<any>;
13
+ updateMany(filters: any, data: any): Promise<any>;
14
+ deleteMany(filters: any): Promise<any>;
15
+ execute(actionName: string, id: string | number | undefined, params: any): Promise<any>;
16
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository.js","sourceRoot":"","sources":["../src/repository.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@objectql/types",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "dependencies": {},
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "test": "jest"
9
+ "test": "jest --passWithNoTests"
10
10
  }
11
11
  }
package/src/app.ts ADDED
@@ -0,0 +1,26 @@
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
+ addPackage(name: string): void;
14
+ removePackage(name: string): void;
15
+ metadata: MetadataRegistry;
16
+
17
+ registerObject(object: ObjectConfig): void;
18
+ loadFromDirectory(dir: string): void;
19
+ addLoader(plugin: LoaderPlugin): void;
20
+
21
+ on(event: HookName, objectName: string, handler: HookHandler): void;
22
+ triggerHook(event: HookName, objectName: string, ctx: HookContext): Promise<void>;
23
+
24
+ registerAction(objectName: string, actionName: string, handler: ActionHandler): void;
25
+ executeAction(objectName: string, actionName: string, ctx: ActionContext): Promise<any>;
26
+ }
package/src/config.ts ADDED
@@ -0,0 +1,37 @@
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 ADDED
@@ -0,0 +1,45 @@
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/index.ts CHANGED
@@ -1,10 +1,15 @@
1
1
  export * from './field';
2
2
  export * from './object';
3
- export * from './types';
4
3
  export * from './driver';
5
4
  export * from './query';
6
5
  export * from './registry';
7
6
  export * from './hook';
8
7
  export * from './action';
8
+ export * from './repository';
9
+ export * from './app';
10
+ export * from './plugin';
11
+ export * from './config';
12
+ export * from './context';
9
13
 
10
14
 
15
+ export * from './loader';
package/src/loader.ts ADDED
@@ -0,0 +1,17 @@
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/plugin.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { IObjectQL } from './app';
2
+
3
+ export interface ObjectQLPlugin {
4
+ name: string;
5
+ setup(app: IObjectQL): void | Promise<void>;
6
+ }
package/src/registry.ts CHANGED
@@ -6,7 +6,7 @@ export interface Metadata {
6
6
  content: any;
7
7
  }
8
8
 
9
- export class ObjectRegistry {
9
+ export class MetadataRegistry {
10
10
  // Map<type, Map<id, Metadata>>
11
11
  private store: Map<string, Map<string, Metadata>> = new Map();
12
12
 
@@ -0,0 +1,17 @@
1
+ import { UnifiedQuery } from "./query";
2
+
3
+ export interface IObjectRepository {
4
+ find(query?: UnifiedQuery): Promise<any[]>;
5
+ findOne(idOrQuery: string | number | UnifiedQuery): Promise<any>;
6
+ count(filters: any): Promise<number>;
7
+ create(doc: any): Promise<any>;
8
+ update(id: string | number, doc: any, options?: any): Promise<any>;
9
+ delete(id: string | number): Promise<any>;
10
+ aggregate(query: any): Promise<any>;
11
+ distinct(field: string, filters?: any): Promise<any[]>;
12
+ findOneAndUpdate?(filters: any, update: any, options?: any): Promise<any>;
13
+ createMany(data: any[]): Promise<any>;
14
+ updateMany(filters: any, data: any): Promise<any>;
15
+ deleteMany(filters: any): Promise<any>;
16
+ execute(actionName: string, id: string | number | undefined, params: any): Promise<any>;
17
+ }