@objectql/core 4.1.0 → 4.2.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 (107) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +42 -0
  3. package/dist/app.d.ts +61 -51
  4. package/dist/app.js +101 -431
  5. package/dist/app.js.map +1 -1
  6. package/dist/index.d.ts +4 -11
  7. package/dist/index.js +13 -9
  8. package/dist/index.js.map +1 -1
  9. package/dist/kernel-factory.d.ts +38 -0
  10. package/dist/kernel-factory.js +38 -0
  11. package/dist/kernel-factory.js.map +1 -0
  12. package/dist/plugin.d.ts +10 -16
  13. package/dist/plugin.js +104 -58
  14. package/dist/plugin.js.map +1 -1
  15. package/dist/repository.d.ts +4 -31
  16. package/dist/repository.js +7 -275
  17. package/dist/repository.js.map +1 -1
  18. package/dist/util.js +4 -2
  19. package/dist/util.js.map +1 -1
  20. package/package.json +19 -11
  21. package/src/app.ts +157 -531
  22. package/src/index.ts +8 -23
  23. package/src/kernel-factory.ts +47 -0
  24. package/src/plugin.ts +116 -94
  25. package/src/repository.ts +4 -313
  26. package/src/util.ts +5 -3
  27. package/test/__mocks__/@objectstack/core.ts +250 -1
  28. package/test/__mocks__/@objectstack/objectql.ts +127 -0
  29. package/test/__mocks__/@objectstack/runtime.ts +14 -5
  30. package/test/introspection.test.ts +1 -1
  31. package/test/mock-driver.ts +5 -5
  32. package/test/optimizations.test.ts +2 -2
  33. package/test/plugin-integration.test.ts +4 -5
  34. package/test/utils.ts +6 -6
  35. package/tsconfig.json +3 -1
  36. package/tsconfig.tsbuildinfo +1 -1
  37. package/dist/gateway.d.ts +0 -36
  38. package/dist/gateway.js +0 -89
  39. package/dist/gateway.js.map +0 -1
  40. package/dist/optimizations/CompiledHookManager.d.ts +0 -55
  41. package/dist/optimizations/CompiledHookManager.js +0 -164
  42. package/dist/optimizations/CompiledHookManager.js.map +0 -1
  43. package/dist/optimizations/DependencyGraph.d.ts +0 -82
  44. package/dist/optimizations/DependencyGraph.js +0 -211
  45. package/dist/optimizations/DependencyGraph.js.map +0 -1
  46. package/dist/optimizations/GlobalConnectionPool.d.ts +0 -89
  47. package/dist/optimizations/GlobalConnectionPool.js +0 -193
  48. package/dist/optimizations/GlobalConnectionPool.js.map +0 -1
  49. package/dist/optimizations/LazyMetadataLoader.d.ts +0 -75
  50. package/dist/optimizations/LazyMetadataLoader.js +0 -149
  51. package/dist/optimizations/LazyMetadataLoader.js.map +0 -1
  52. package/dist/optimizations/OptimizedMetadataRegistry.d.ts +0 -26
  53. package/dist/optimizations/OptimizedMetadataRegistry.js +0 -117
  54. package/dist/optimizations/OptimizedMetadataRegistry.js.map +0 -1
  55. package/dist/optimizations/OptimizedValidationEngine.d.ts +0 -73
  56. package/dist/optimizations/OptimizedValidationEngine.js +0 -141
  57. package/dist/optimizations/OptimizedValidationEngine.js.map +0 -1
  58. package/dist/optimizations/QueryCompiler.d.ts +0 -51
  59. package/dist/optimizations/QueryCompiler.js +0 -216
  60. package/dist/optimizations/QueryCompiler.js.map +0 -1
  61. package/dist/optimizations/SQLQueryOptimizer.d.ts +0 -96
  62. package/dist/optimizations/SQLQueryOptimizer.js +0 -265
  63. package/dist/optimizations/SQLQueryOptimizer.js.map +0 -1
  64. package/dist/optimizations/index.d.ts +0 -32
  65. package/dist/optimizations/index.js +0 -44
  66. package/dist/optimizations/index.js.map +0 -1
  67. package/dist/protocol.d.ts +0 -180
  68. package/dist/protocol.js +0 -260
  69. package/dist/protocol.js.map +0 -1
  70. package/dist/query/filter-translator.d.ts +0 -27
  71. package/dist/query/filter-translator.js +0 -38
  72. package/dist/query/filter-translator.js.map +0 -1
  73. package/dist/query/index.d.ts +0 -22
  74. package/dist/query/index.js +0 -39
  75. package/dist/query/index.js.map +0 -1
  76. package/dist/query/query-analyzer.d.ts +0 -188
  77. package/dist/query/query-analyzer.js +0 -348
  78. package/dist/query/query-analyzer.js.map +0 -1
  79. package/dist/query/query-builder.d.ts +0 -35
  80. package/dist/query/query-builder.js +0 -61
  81. package/dist/query/query-builder.js.map +0 -1
  82. package/dist/query/query-service.d.ts +0 -153
  83. package/dist/query/query-service.js +0 -272
  84. package/dist/query/query-service.js.map +0 -1
  85. package/jest.config.js +0 -29
  86. package/src/gateway.ts +0 -101
  87. package/src/optimizations/CompiledHookManager.ts +0 -185
  88. package/src/optimizations/DependencyGraph.ts +0 -255
  89. package/src/optimizations/GlobalConnectionPool.ts +0 -251
  90. package/src/optimizations/LazyMetadataLoader.ts +0 -180
  91. package/src/optimizations/OptimizedMetadataRegistry.ts +0 -132
  92. package/src/optimizations/OptimizedValidationEngine.ts +0 -172
  93. package/src/optimizations/QueryCompiler.ts +0 -242
  94. package/src/optimizations/SQLQueryOptimizer.ts +0 -329
  95. package/src/optimizations/index.ts +0 -34
  96. package/src/protocol.ts +0 -291
  97. package/src/query/filter-translator.ts +0 -41
  98. package/src/query/index.ts +0 -24
  99. package/src/query/query-analyzer.ts +0 -533
  100. package/src/query/query-builder.ts +0 -64
  101. package/src/query/query-service.ts +0 -398
  102. package/test/app.test.ts +0 -578
  103. package/test/filter-syntax.test.ts +0 -233
  104. package/test/gateway.test.ts +0 -88
  105. package/test/protocol.test.ts +0 -143
  106. package/test/repository-validation.test.ts +0 -351
  107. package/test/repository.test.ts +0 -151
@@ -1,272 +0,0 @@
1
- "use strict";
2
- /**
3
- * ObjectQL Query Service
4
- * Copyright (c) 2026-present ObjectStack Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE file in the root directory of this source tree.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.QueryService = void 0;
11
- const query_builder_1 = require("./query-builder");
12
- const QueryCompiler_1 = require("../optimizations/QueryCompiler");
13
- /**
14
- * Query Service
15
- *
16
- * Handles all query execution logic, separating query concerns from
17
- * the repository pattern. This service is responsible for:
18
- * - Building QueryAST from UnifiedQuery
19
- * - Executing queries via drivers
20
- * - Optional query profiling and analysis
21
- *
22
- * The QueryService is registered as a service in the ObjectQLPlugin
23
- * and can be used by Repository for all read operations.
24
- */
25
- class QueryService {
26
- constructor(datasources, metadata) {
27
- this.datasources = datasources;
28
- this.metadata = metadata;
29
- this.queryBuilder = new query_builder_1.QueryBuilder();
30
- this.queryCompiler = new QueryCompiler_1.QueryCompiler(1000);
31
- }
32
- /**
33
- * Get the driver for a specific object
34
- * @private
35
- */
36
- getDriver(objectName) {
37
- const obj = this.getSchema(objectName);
38
- const datasourceName = obj.datasource || 'default';
39
- const driver = this.datasources[datasourceName];
40
- if (!driver) {
41
- throw new Error(`Datasource '${datasourceName}' not found for object '${objectName}'`);
42
- }
43
- return driver;
44
- }
45
- /**
46
- * Get the schema for an object
47
- * @private
48
- */
49
- getSchema(objectName) {
50
- const obj = this.metadata.get('object', objectName);
51
- if (!obj) {
52
- throw new Error(`Object '${objectName}' not found in metadata`);
53
- }
54
- return obj;
55
- }
56
- /**
57
- * Build QueryAST from UnifiedQuery
58
- * @private
59
- */
60
- buildQueryAST(objectName, query) {
61
- const ast = this.queryBuilder.build(objectName, query);
62
- const compiled = this.queryCompiler.compile(objectName, ast);
63
- return compiled.ast;
64
- }
65
- /**
66
- * Execute a find query
67
- *
68
- * @param objectName - The object to query
69
- * @param query - The unified query
70
- * @param options - Query execution options
71
- * @returns Array of matching records
72
- */
73
- async find(objectName, query = {}, options = {}) {
74
- const driver = this.getDriver(objectName);
75
- const startTime = options.profile ? Date.now() : 0;
76
- // Build QueryAST
77
- const ast = this.buildQueryAST(objectName, query);
78
- // Execute query via driver
79
- const driverOptions = {
80
- transaction: options.transaction,
81
- ...options.driverOptions
82
- };
83
- let results;
84
- let count;
85
- if (driver.find) {
86
- // Legacy driver interface
87
- const result = await driver.find(objectName, query, driverOptions);
88
- results = Array.isArray(result) ? result : ((result === null || result === void 0 ? void 0 : result.value) || []);
89
- count = (typeof result === 'object' && !Array.isArray(result) && (result === null || result === void 0 ? void 0 : result.count) !== undefined) ? result.count : undefined;
90
- }
91
- else if (driver.executeQuery) {
92
- // New DriverInterface
93
- const result = await driver.executeQuery(ast, driverOptions);
94
- results = result.value || [];
95
- count = result.count;
96
- }
97
- else {
98
- throw new Error(`Driver does not support query execution`);
99
- }
100
- const executionTime = options.profile ? Date.now() - startTime : 0;
101
- return {
102
- value: results,
103
- count,
104
- profile: options.profile ? {
105
- executionTime,
106
- ast,
107
- rowsScanned: results.length,
108
- } : undefined
109
- };
110
- }
111
- /**
112
- * Execute a findOne query by ID
113
- *
114
- * @param objectName - The object to query
115
- * @param id - The record ID
116
- * @param options - Query execution options
117
- * @returns The matching record or undefined
118
- */
119
- async findOne(objectName, id, options = {}) {
120
- var _a;
121
- const driver = this.getDriver(objectName);
122
- const startTime = options.profile ? Date.now() : 0;
123
- const driverOptions = {
124
- transaction: options.transaction,
125
- ...options.driverOptions
126
- };
127
- let result;
128
- if (driver.findOne) {
129
- // Legacy driver interface
130
- result = await driver.findOne(objectName, id, driverOptions);
131
- }
132
- else if (driver.get) {
133
- // Alternative method name
134
- result = await driver.get(objectName, String(id), driverOptions);
135
- }
136
- else if (driver.executeQuery) {
137
- // Fallback to query with ID filter
138
- const query = {
139
- where: { _id: id }
140
- };
141
- const ast = this.buildQueryAST(objectName, query);
142
- const queryResult = await driver.executeQuery(ast, driverOptions);
143
- result = (_a = queryResult.value) === null || _a === void 0 ? void 0 : _a[0];
144
- }
145
- else {
146
- throw new Error(`Driver does not support findOne operation`);
147
- }
148
- const executionTime = options.profile ? Date.now() - startTime : 0;
149
- return {
150
- value: result,
151
- profile: options.profile ? {
152
- executionTime,
153
- rowsScanned: result ? 1 : 0,
154
- } : undefined
155
- };
156
- }
157
- /**
158
- * Execute a count query
159
- *
160
- * @param objectName - The object to query
161
- * @param where - Optional filter condition
162
- * @param options - Query execution options
163
- * @returns Count of matching records
164
- */
165
- async count(objectName, where, options = {}) {
166
- var _a, _b, _c;
167
- const driver = this.getDriver(objectName);
168
- const startTime = options.profile ? Date.now() : 0;
169
- const query = where ? { where } : {};
170
- const ast = this.buildQueryAST(objectName, query);
171
- const driverOptions = {
172
- transaction: options.transaction,
173
- ...options.driverOptions
174
- };
175
- let count;
176
- if (driver.count) {
177
- // Legacy driver interface
178
- count = await driver.count(objectName, where || {}, driverOptions);
179
- }
180
- else if (driver.executeQuery) {
181
- // Use executeQuery and count results
182
- // Note: This is inefficient for large datasets
183
- // Ideally, driver should support count-specific optimization
184
- const result = await driver.executeQuery(ast, driverOptions);
185
- count = (_c = (_a = result.count) !== null && _a !== void 0 ? _a : (_b = result.value) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
186
- }
187
- else {
188
- throw new Error(`Driver does not support count operation`);
189
- }
190
- const executionTime = options.profile ? Date.now() - startTime : 0;
191
- return {
192
- value: count,
193
- profile: options.profile ? {
194
- executionTime,
195
- ast,
196
- } : undefined
197
- };
198
- }
199
- /**
200
- * Execute an aggregate query
201
- *
202
- * @param objectName - The object to query
203
- * @param query - The aggregation query using UnifiedQuery format
204
- * @param options - Query execution options
205
- * @returns Aggregation results
206
- */
207
- async aggregate(objectName, query, options = {}) {
208
- const driver = this.getDriver(objectName);
209
- const startTime = options.profile ? Date.now() : 0;
210
- const driverOptions = {
211
- transaction: options.transaction,
212
- ...options.driverOptions
213
- };
214
- let results;
215
- if (driver.aggregate) {
216
- // Driver supports aggregation
217
- results = await driver.aggregate(objectName, query, driverOptions);
218
- }
219
- else {
220
- // Driver doesn't support aggregation
221
- throw new Error(`Driver does not support aggregate operations. Consider using a driver that supports aggregation.`);
222
- }
223
- const executionTime = options.profile ? Date.now() - startTime : 0;
224
- return {
225
- value: results,
226
- profile: options.profile ? {
227
- executionTime,
228
- rowsScanned: results.length,
229
- } : undefined
230
- };
231
- }
232
- /**
233
- * Execute a direct SQL/query passthrough
234
- *
235
- * This bypasses ObjectQL's query builder and executes raw queries.
236
- * Use with caution as it bypasses security and validation.
237
- *
238
- * @param objectName - The object (determines which datasource to use)
239
- * @param queryString - Raw query string (SQL, MongoDB query, etc.)
240
- * @param params - Query parameters (for parameterized queries)
241
- * @param options - Query execution options
242
- * @returns Query results
243
- */
244
- async directQuery(objectName, queryString, params, options = {}) {
245
- const driver = this.getDriver(objectName);
246
- const startTime = options.profile ? Date.now() : 0;
247
- const driverOptions = {
248
- transaction: options.transaction,
249
- ...options.driverOptions
250
- };
251
- let results;
252
- if (driver.directQuery) {
253
- results = await driver.directQuery(queryString, params);
254
- }
255
- else if (driver.query) {
256
- // Alternative method name
257
- results = await driver.query(queryString, params);
258
- }
259
- else {
260
- throw new Error(`Driver does not support direct query execution`);
261
- }
262
- const executionTime = options.profile ? Date.now() - startTime : 0;
263
- return {
264
- value: results,
265
- profile: options.profile ? {
266
- executionTime,
267
- } : undefined
268
- };
269
- }
270
- }
271
- exports.QueryService = QueryService;
272
- //# sourceMappingURL=query-service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"query-service.js","sourceRoot":"","sources":["../../src/query/query-service.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAWH,mDAA+C;AAC/C,kEAA+D;AAwE/D;;;;;;;;;;;GAWG;AACH,MAAa,YAAY;IAIrB,YACY,WAAmC,EACnC,QAA0B;QAD1B,gBAAW,GAAX,WAAW,CAAwB;QACnC,aAAQ,GAAR,QAAQ,CAAkB;QAElC,IAAI,CAAC,YAAY,GAAG,IAAI,4BAAY,EAAE,CAAC;QACvC,IAAI,CAAC,aAAa,GAAG,IAAI,6BAAa,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;IAED;;;OAGG;IACK,SAAS,CAAC,UAAkB;QAChC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACvC,MAAM,cAAc,GAAG,GAAG,CAAC,UAAU,IAAI,SAAS,CAAC;QACnD,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QAEhD,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,eA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AAC;IACN,CAAC;CACJ;AAvSD,oCAuSC"}
package/jest.config.js DELETED
@@ -1,29 +0,0 @@
1
- /**
2
- * ObjectQL
3
- * Copyright (c) 2026-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- module.exports = {
10
- preset: 'ts-jest',
11
- testEnvironment: 'node',
12
- testMatch: ['**/test/**/*.test.ts'],
13
- moduleNameMapper: {
14
- '^@objectql/(.*)$': '<rootDir>/../$1/src',
15
- '^@objectstack/core$': '<rootDir>/test/__mocks__/@objectstack/core.ts',
16
- '^@objectstack/objectql$': '<rootDir>/test/__mocks__/@objectstack/objectql.ts',
17
- '^@objectstack/runtime$': '<rootDir>/test/__mocks__/@objectstack/runtime.ts',
18
- },
19
- transform: {
20
- '^.+\\.(t|j)sx?$': ['ts-jest', {
21
- isolatedModules: true,
22
- tsconfig: {
23
- esModuleInterop: true,
24
- allowSyntheticDefaultImports: true,
25
- allowJs: true,
26
- }
27
- }],
28
- },
29
- };
package/src/gateway.ts DELETED
@@ -1,101 +0,0 @@
1
- /**
2
- * ObjectQL
3
- * Copyright (c) 2026-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- import { ApiRequest, ApiResponse, GatewayProtocol } from '@objectql/types';
10
-
11
- export type RequestTransformer = (request: ApiRequest) => Promise<ApiRequest>;
12
- export type ResponseTransformer = (response: ApiResponse) => Promise<ApiResponse>;
13
-
14
- /**
15
- * Unified API Gateway
16
- * Routtes generic API requests to specific protocol implementations
17
- */
18
- export class ObjectGateway {
19
- private protocols: GatewayProtocol[] = [];
20
- private requestTransforms: RequestTransformer[] = [];
21
- private responseTransforms: ResponseTransformer[] = [];
22
-
23
- constructor(protocols: GatewayProtocol[] = []) {
24
- this.protocols = protocols;
25
- }
26
-
27
- /**
28
- * Register a new protocol handler
29
- */
30
- registerProtocol(protocol: GatewayProtocol) {
31
- this.protocols.push(protocol);
32
- }
33
-
34
- /**
35
- * Add a request transformer (middleware)
36
- */
37
- addRequestTransform(transformer: RequestTransformer) {
38
- this.requestTransforms.push(transformer);
39
- }
40
-
41
- /**
42
- * Add a response transformer (middleware)
43
- */
44
- addResponseTransform(transformer: ResponseTransformer) {
45
- this.responseTransforms.push(transformer);
46
- }
47
-
48
- /**
49
- * Handle an incoming API request
50
- */
51
- async handle(request: ApiRequest): Promise<ApiResponse> {
52
- let req = request;
53
-
54
- // 1. Apply Request Transforms
55
- for (const transform of this.requestTransforms) {
56
- req = await transform(req);
57
- }
58
-
59
- // 2. Find matching protocol
60
- const protocol = this.protocols.find(p => p.route(req));
61
-
62
- if (!protocol) {
63
- return {
64
- status: 404,
65
- headers: { 'Content-Type': 'application/json' },
66
- body: {
67
- error: {
68
- code: 'PROTOCOL_NOT_FOUND',
69
- message: `No protocol found to handle path: ${req.path}`
70
- }
71
- }
72
- };
73
- }
74
-
75
- let response: ApiResponse;
76
-
77
- // 3. Delegate to protocol
78
- try {
79
- response = await protocol.handle(req);
80
- } catch (error: any) {
81
- console.error(`[ObjectGateway] Error in ${protocol.name}:`, error);
82
- response = {
83
- status: 500,
84
- headers: { 'Content-Type': 'application/json' },
85
- body: {
86
- error: {
87
- code: 'INTERNAL_ERROR',
88
- message: error.message || 'Internal Gateway Error'
89
- }
90
- }
91
- };
92
- }
93
-
94
- // 4. Apply Response Transforms
95
- for (const transform of this.responseTransforms) {
96
- response = await transform(response);
97
- }
98
-
99
- return response;
100
- }
101
- }
@@ -1,185 +0,0 @@
1
- /**
2
- * ObjectQL
3
- * Copyright (c) 2026-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- /**
10
- * Hook definition
11
- */
12
- export interface Hook {
13
- pattern: string;
14
- handler: (context: any) => Promise<void> | void;
15
- packageName?: string;
16
- priority?: number;
17
- }
18
-
19
- /**
20
- * Compiled Hook Manager
21
- *
22
- * Improvement: Pre-compiles hook pipelines by event pattern at registration time.
23
- * No runtime pattern matching required.
24
- *
25
- * Expected: 5x faster hook execution, parallel async support
26
- */
27
- export class CompiledHookManager {
28
- // Direct event -> hooks mapping (no pattern matching at runtime)
29
- private pipelines = new Map<string, Hook[]>();
30
-
31
- // Keep track of all registered hooks for management
32
- private allHooks = new Map<string, Hook>();
33
-
34
- /**
35
- * Expand a pattern like "before*" to all matching events
36
- */
37
- private expandPattern(pattern: string): string[] {
38
- // Common event patterns
39
- const eventTypes = [
40
- 'beforeCreate', 'afterCreate',
41
- 'beforeUpdate', 'afterUpdate',
42
- 'beforeDelete', 'afterDelete',
43
- 'beforeFind', 'afterFind',
44
- 'beforeCount', 'afterCount'
45
- ];
46
-
47
- // Handle wildcards
48
- if (pattern === '*') {
49
- return eventTypes;
50
- }
51
-
52
- if (pattern.includes('*')) {
53
- // Use global replace to handle all occurrences of *
54
- const regex = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$');
55
- return eventTypes.filter(event => regex.test(event));
56
- }
57
-
58
- // Exact match
59
- return [pattern];
60
- }
61
-
62
- /**
63
- * Register a hook - pre-groups by event pattern
64
- */
65
- registerHook(event: string, objectName: string, handler: any, packageName?: string): void {
66
- const hook: Hook = {
67
- pattern: `${event}:${objectName}`,
68
- handler,
69
- packageName,
70
- priority: 0
71
- };
72
-
73
- // Store in all hooks registry
74
- const hookId = `${event}:${objectName}:${Date.now()}`;
75
- this.allHooks.set(hookId, hook);
76
-
77
- // Expand event patterns
78
- const events = this.expandPattern(event);
79
-
80
- // Handle wildcard object names
81
- if (objectName === '*') {
82
- for (const concreteEvent of events) {
83
- // Register for all potential object names
84
- // Since we don't know all object names upfront, we keep a special '*' pipeline
85
- const wildcardKey = `${concreteEvent}:*`;
86
- if (!this.pipelines.has(wildcardKey)) {
87
- this.pipelines.set(wildcardKey, []);
88
- }
89
- this.pipelines.get(wildcardKey)!.push(hook);
90
- }
91
- } else {
92
- // Pre-group hooks by concrete event names (only for non-wildcard objects)
93
- for (const concreteEvent of events) {
94
- const key = `${concreteEvent}:${objectName}`;
95
- if (!this.pipelines.has(key)) {
96
- this.pipelines.set(key, []);
97
- }
98
- this.pipelines.get(key)!.push(hook);
99
- }
100
- }
101
- }
102
-
103
- /**
104
- * Run hooks for an event - direct lookup, no pattern matching
105
- */
106
- async runHooks(event: string, objectName: string, context: any): Promise<void> {
107
- const key = `${event}:${objectName}`;
108
- const wildcardKey = `${event}:*`;
109
-
110
- // Collect all applicable hooks
111
- const hooks: Hook[] = [];
112
-
113
- // Add object-specific hooks
114
- const objectHooks = this.pipelines.get(key);
115
- if (objectHooks) {
116
- hooks.push(...objectHooks);
117
- }
118
-
119
- // Add wildcard hooks
120
- const wildcardHooks = this.pipelines.get(wildcardKey);
121
- if (wildcardHooks) {
122
- hooks.push(...wildcardHooks);
123
- }
124
-
125
- if (hooks.length === 0) {
126
- return;
127
- }
128
-
129
- // Sort by priority (higher priority first)
130
- hooks.sort((a, b) => (b.priority || 0) - (a.priority || 0));
131
-
132
- // Execute hooks in parallel for better performance
133
- // Note: If order matters, change to sequential execution
134
- await Promise.all(hooks.map(hook => {
135
- try {
136
- return Promise.resolve(hook.handler(context));
137
- } catch (error) {
138
- console.error(`Hook execution failed for ${event}:${objectName}`, error);
139
- return Promise.resolve();
140
- }
141
- }));
142
- }
143
-
144
- /**
145
- * Remove all hooks from a package
146
- */
147
- removePackage(packageName: string): void {
148
- // Remove from all hooks registry
149
- const hooksToRemove: string[] = [];
150
- for (const [hookId, hook] of this.allHooks.entries()) {
151
- if (hook.packageName === packageName) {
152
- hooksToRemove.push(hookId);
153
- }
154
- }
155
- hooksToRemove.forEach(id => this.allHooks.delete(id));
156
-
157
- // Remove from pipelines
158
- for (const [key, hooks] of this.pipelines.entries()) {
159
- const filtered = hooks.filter(h => h.packageName !== packageName);
160
- if (filtered.length === 0) {
161
- this.pipelines.delete(key);
162
- } else {
163
- this.pipelines.set(key, filtered);
164
- }
165
- }
166
- }
167
-
168
- /**
169
- * Clear all hooks
170
- */
171
- clear(): void {
172
- this.pipelines.clear();
173
- this.allHooks.clear();
174
- }
175
-
176
- /**
177
- * Get statistics about registered hooks
178
- */
179
- getStats(): { totalHooks: number; totalPipelines: number } {
180
- return {
181
- totalHooks: this.allHooks.size,
182
- totalPipelines: this.pipelines.size
183
- };
184
- }
185
- }