@objectql/core 4.0.4 → 4.0.6
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +63 -0
- package/dist/app.js +29 -7
- package/dist/app.js.map +1 -1
- package/dist/gateway.d.ts +36 -0
- package/dist/gateway.js +89 -0
- package/dist/gateway.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +8 -0
- package/dist/plugin.js.map +1 -1
- package/dist/protocol.d.ts +180 -0
- package/dist/protocol.js +260 -0
- package/dist/protocol.js.map +1 -0
- package/jest.config.js +3 -3
- package/package.json +8 -8
- package/src/app.ts +28 -7
- package/src/gateway.ts +101 -0
- package/src/index.ts +2 -0
- package/src/plugin.ts +10 -0
- package/src/protocol.ts +291 -0
- package/test/__mocks__/@objectstack/core.ts +27 -0
- package/test/__mocks__/@objectstack/objectql.ts +45 -0
- package/test/gateway.test.ts +88 -0
- package/test/protocol.test.ts +143 -0
- package/tsconfig.tsbuildinfo +1 -1
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ObjectStack Protocol Implementation
|
|
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.ObjectStackProtocolImplementation = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* Bridges the ObjectStack Protocol (Specification) to the ObjectQL Engine (Implementation)
|
|
13
|
+
*/
|
|
14
|
+
class ObjectStackProtocolImplementation {
|
|
15
|
+
constructor(engine) {
|
|
16
|
+
this.engine = engine;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get API Discovery Document
|
|
20
|
+
*/
|
|
21
|
+
async getDiscovery(args) {
|
|
22
|
+
return {
|
|
23
|
+
name: 'ObjectQL Engine',
|
|
24
|
+
version: '4.0.0',
|
|
25
|
+
protocols: ['rest', 'graphql', 'json-rpc', 'odata'],
|
|
26
|
+
auth: {
|
|
27
|
+
type: 'bearer',
|
|
28
|
+
url: '/auth/token'
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get Metadata Types (e.g., ['object', 'action'])
|
|
34
|
+
*/
|
|
35
|
+
async getMetaTypes(args) {
|
|
36
|
+
let types = ['object'];
|
|
37
|
+
if (this.engine.metadata && typeof this.engine.metadata.getTypes === 'function') {
|
|
38
|
+
types = this.engine.metadata.getTypes();
|
|
39
|
+
}
|
|
40
|
+
return { types };
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get Metadata Items for a Type
|
|
44
|
+
*/
|
|
45
|
+
async getMetaItems(args) {
|
|
46
|
+
const { type } = args;
|
|
47
|
+
let items = [];
|
|
48
|
+
if (this.engine.metadata && typeof this.engine.metadata.list === 'function') {
|
|
49
|
+
items = this.engine.metadata.list(type);
|
|
50
|
+
}
|
|
51
|
+
return { type, items };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get Metadata Item
|
|
55
|
+
*/
|
|
56
|
+
async getMetaItem(args) {
|
|
57
|
+
const { type, name } = args;
|
|
58
|
+
if (this.engine.metadata && typeof this.engine.metadata.get === 'function') {
|
|
59
|
+
return this.engine.metadata.get(type, name);
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get Cached Metadata Item
|
|
65
|
+
*/
|
|
66
|
+
async getMetaItemCached(args) {
|
|
67
|
+
// Fallback to non-cached version for now
|
|
68
|
+
return this.getMetaItem(args);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get UI View
|
|
72
|
+
*/
|
|
73
|
+
async getUiView(args) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Find Data Records
|
|
78
|
+
*/
|
|
79
|
+
async findData(args) {
|
|
80
|
+
const { object, query } = args;
|
|
81
|
+
// Use direct kernel method if available (preferred)
|
|
82
|
+
if (typeof this.engine.find === 'function') {
|
|
83
|
+
const result = await this.engine.find(object, query || {});
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
// Fallback to createContext (if engine is IObjectQL)
|
|
87
|
+
if (typeof this.engine.createContext === 'function') {
|
|
88
|
+
const ctx = this.engine.createContext({ isSystem: true });
|
|
89
|
+
try {
|
|
90
|
+
const repo = ctx.object(object);
|
|
91
|
+
return await repo.find(query || {});
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
throw new Error(`Data access failed: ${error.message}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
throw new Error('Engine does not support find operation');
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Count Data Records
|
|
101
|
+
*/
|
|
102
|
+
async countData(args) {
|
|
103
|
+
const { object, query } = args;
|
|
104
|
+
// Basic fallback
|
|
105
|
+
const result = await this.findData(args);
|
|
106
|
+
return Array.isArray(result) ? result.length : (result.value ? result.value.length : 0);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get Single Data Record
|
|
110
|
+
*/
|
|
111
|
+
async getData(args) {
|
|
112
|
+
const { object, id } = args;
|
|
113
|
+
if (typeof this.engine.get === 'function') {
|
|
114
|
+
return await this.engine.get(object, id);
|
|
115
|
+
}
|
|
116
|
+
if (typeof this.engine.createContext === 'function') {
|
|
117
|
+
const ctx = this.engine.createContext({ isSystem: true });
|
|
118
|
+
try {
|
|
119
|
+
const repo = ctx.object(object);
|
|
120
|
+
return await repo.findOne(id);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
throw new Error(`Data retrieval failed: ${error.message}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
throw new Error('Engine does not support get operation');
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Create Data Record
|
|
130
|
+
*/
|
|
131
|
+
async createData(args) {
|
|
132
|
+
const { object, data } = args;
|
|
133
|
+
if (typeof this.engine.create === 'function') {
|
|
134
|
+
return await this.engine.create(object, data);
|
|
135
|
+
}
|
|
136
|
+
if (typeof this.engine.createContext === 'function') {
|
|
137
|
+
const ctx = this.engine.createContext({ isSystem: true });
|
|
138
|
+
try {
|
|
139
|
+
const repo = ctx.object(object);
|
|
140
|
+
// Protocol expects returned data
|
|
141
|
+
return await repo.create(data);
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
throw new Error(`Data creation failed: ${error.message}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
throw new Error('Engine does not support create operation');
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Update Data Record
|
|
151
|
+
*/
|
|
152
|
+
async updateData(args) {
|
|
153
|
+
const { object, id, data } = args;
|
|
154
|
+
if (typeof this.engine.update === 'function') {
|
|
155
|
+
return await this.engine.update(object, id, data);
|
|
156
|
+
}
|
|
157
|
+
if (typeof this.engine.createContext === 'function') {
|
|
158
|
+
const ctx = this.engine.createContext({ isSystem: true });
|
|
159
|
+
try {
|
|
160
|
+
const repo = ctx.object(object);
|
|
161
|
+
return await repo.update(id, data);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
throw new Error(`Data update failed: ${error.message}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
throw new Error('Engine does not support update operation');
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Delete Data Record
|
|
171
|
+
*/
|
|
172
|
+
async deleteData(args) {
|
|
173
|
+
const { object, id } = args;
|
|
174
|
+
if (typeof this.engine.delete === 'function') {
|
|
175
|
+
const success = await this.engine.delete(object, id);
|
|
176
|
+
return { object, id, success: !!success };
|
|
177
|
+
}
|
|
178
|
+
if (typeof this.engine.createContext === 'function') {
|
|
179
|
+
const ctx = this.engine.createContext({ isSystem: true });
|
|
180
|
+
try {
|
|
181
|
+
const repo = ctx.object(object);
|
|
182
|
+
await repo.delete(id);
|
|
183
|
+
return { object, id, success: true };
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
throw new Error(`Data deletion failed: ${error.message}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
throw new Error('Engine does not support delete operation');
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Create Many Data Records
|
|
193
|
+
*/
|
|
194
|
+
async createManyData(args) {
|
|
195
|
+
throw new Error('createManyData not implemented');
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Update Many Data Records
|
|
199
|
+
*/
|
|
200
|
+
async updateManyData(args) {
|
|
201
|
+
throw new Error('updateManyData not implemented');
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Delete Many Data Records
|
|
205
|
+
*/
|
|
206
|
+
async deleteManyData(args) {
|
|
207
|
+
throw new Error('deleteManyData not implemented');
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Batch Operations
|
|
211
|
+
*/
|
|
212
|
+
async batchData(args) {
|
|
213
|
+
throw new Error('batchData not implemented');
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Execute Action/Operation
|
|
217
|
+
*/
|
|
218
|
+
async performAction(args) {
|
|
219
|
+
// Not implemented in this shim yet
|
|
220
|
+
throw new Error('Action execution not implemented in protocol shim');
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Analytics Query - Execute analytics query
|
|
224
|
+
*/
|
|
225
|
+
async analyticsQuery(args) {
|
|
226
|
+
throw new Error('analyticsQuery not implemented');
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Get Analytics Metadata
|
|
230
|
+
*/
|
|
231
|
+
async getAnalyticsMeta(args) {
|
|
232
|
+
throw new Error('getAnalyticsMeta not implemented');
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Trigger Automation
|
|
236
|
+
*/
|
|
237
|
+
async triggerAutomation(args) {
|
|
238
|
+
throw new Error('triggerAutomation not implemented');
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* List Spaces (Hub/Workspace Management)
|
|
242
|
+
*/
|
|
243
|
+
async listSpaces(args) {
|
|
244
|
+
throw new Error('listSpaces not implemented');
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Create Space (Hub/Workspace Management)
|
|
248
|
+
*/
|
|
249
|
+
async createSpace(args) {
|
|
250
|
+
throw new Error('createSpace not implemented');
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Install Plugin (Hub/Extension Management)
|
|
254
|
+
*/
|
|
255
|
+
async installPlugin(args) {
|
|
256
|
+
throw new Error('installPlugin not implemented');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
exports.ObjectStackProtocolImplementation = ObjectStackProtocolImplementation;
|
|
260
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAKH;;GAEG;AACH,MAAa,iCAAiC;IAC1C,YAAoB,MAAiB;QAAjB,WAAM,GAAN,MAAM,CAAW;IAAG,CAAC;IAEzC;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,IAAS;QACxB,OAAO;YACH,IAAI,EAAE,iBAAiB;YACvB,OAAO,EAAE,OAAO;YAChB,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC;YACnD,IAAI,EAAE;gBACF,IAAI,EAAE,QAAQ;gBACd,GAAG,EAAE,aAAa;aACrB;SACJ,CAAC;IACN,CAAC;IAED;;OAEG;IACH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6 +12,9 @@ module.exports = {
|
|
|
12
12
|
testMatch: ['**/test/**/*.test.ts'],
|
|
13
13
|
moduleNameMapper: {
|
|
14
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',
|
|
15
18
|
},
|
|
16
19
|
transform: {
|
|
17
20
|
'^.+\\.(t|j)sx?$': ['ts-jest', {
|
|
@@ -23,7 +26,4 @@ module.exports = {
|
|
|
23
26
|
}
|
|
24
27
|
}],
|
|
25
28
|
},
|
|
26
|
-
transformIgnorePatterns: [
|
|
27
|
-
"/node_modules/(?!(@objectstack|.pnpm))"
|
|
28
|
-
],
|
|
29
29
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@objectql/core",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.6",
|
|
4
4
|
"description": "Universal runtime engine for ObjectQL - AI-native metadata-driven ORM with validation, repository pattern, and driver orchestration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"objectql",
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
"main": "dist/index.js",
|
|
19
19
|
"types": "dist/index.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@objectstack/
|
|
22
|
-
"@objectstack/
|
|
23
|
-
"@objectstack/
|
|
24
|
-
"@objectstack/
|
|
21
|
+
"@objectstack/core": "^1.0.0",
|
|
22
|
+
"@objectstack/objectql": "^1.0.0",
|
|
23
|
+
"@objectstack/runtime": "^1.0.0",
|
|
24
|
+
"@objectstack/spec": "^1.0.0",
|
|
25
25
|
"js-yaml": "^4.1.0",
|
|
26
|
-
"@objectql/
|
|
27
|
-
"@objectql/plugin-
|
|
28
|
-
"@objectql/
|
|
26
|
+
"@objectql/plugin-formula": "4.0.6",
|
|
27
|
+
"@objectql/plugin-validator": "4.0.6",
|
|
28
|
+
"@objectql/types": "4.0.6"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/js-yaml": "^4.0.5",
|
package/src/app.ts
CHANGED
|
@@ -110,18 +110,24 @@ export class ObjectQL implements IObjectQL {
|
|
|
110
110
|
return items.map(unwrapContent);
|
|
111
111
|
},
|
|
112
112
|
unregister: (type: string, name: string) => {
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
113
|
+
// Use the official unregisterItem API when available (added in @objectstack/objectql v0.9.2)
|
|
114
|
+
// Fallback to direct metadata access for older versions or test mocks
|
|
115
|
+
if (typeof SchemaRegistry.unregisterItem === 'function') {
|
|
116
|
+
SchemaRegistry.unregisterItem(type, name);
|
|
117
|
+
} else {
|
|
118
|
+
// Fallback: try to access metadata Map directly
|
|
119
|
+
const metadata = (SchemaRegistry as any).metadata;
|
|
120
|
+
if (metadata && metadata instanceof Map) {
|
|
121
|
+
const collection = metadata.get(type);
|
|
122
|
+
if (collection && collection instanceof Map) {
|
|
123
|
+
collection.delete(name);
|
|
124
|
+
}
|
|
119
125
|
}
|
|
120
126
|
}
|
|
121
127
|
},
|
|
122
128
|
unregisterPackage: (packageName: string) => {
|
|
123
129
|
const metadata = (SchemaRegistry as any).metadata;
|
|
124
|
-
if (metadata instanceof Map) {
|
|
130
|
+
if (metadata && metadata instanceof Map) {
|
|
125
131
|
for (const [type, collection] of metadata.entries()) {
|
|
126
132
|
if (collection instanceof Map) {
|
|
127
133
|
for (const [key, item] of collection.entries()) {
|
|
@@ -395,6 +401,21 @@ export class ObjectQL implements IObjectQL {
|
|
|
395
401
|
await (this.kernel as any).bootstrap();
|
|
396
402
|
} else {
|
|
397
403
|
console.warn('ObjectKernel does not have start() or bootstrap() method');
|
|
404
|
+
|
|
405
|
+
// Manually initialize plugins if kernel doesn't support lifecycle
|
|
406
|
+
for (const plugin of this.kernelPlugins) {
|
|
407
|
+
try {
|
|
408
|
+
if (typeof (plugin as any).init === 'function') {
|
|
409
|
+
await (plugin as any).init();
|
|
410
|
+
}
|
|
411
|
+
if (typeof (plugin as any).start === 'function') {
|
|
412
|
+
await (plugin as any).start();
|
|
413
|
+
}
|
|
414
|
+
} catch (error) {
|
|
415
|
+
console.error(`Failed to initialize plugin ${(plugin as any).name || 'unknown'}:`, error);
|
|
416
|
+
// Continue with other plugins even if one fails
|
|
417
|
+
}
|
|
418
|
+
}
|
|
398
419
|
}
|
|
399
420
|
|
|
400
421
|
// TEMPORARY: Set driver for backward compatibility during migration
|
package/src/gateway.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,8 @@ export type QueryAST = Data.QueryAST;
|
|
|
19
19
|
export type DriverInterface = Data.DriverInterface;
|
|
20
20
|
export type DriverOptions = Data.DriverOptions;
|
|
21
21
|
|
|
22
|
+
export * from './gateway';
|
|
23
|
+
|
|
22
24
|
// Export our enhanced runtime components (actual implementations)
|
|
23
25
|
export * from './repository';
|
|
24
26
|
export * from './app';
|
package/src/plugin.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { ValidatorPlugin, ValidatorPluginConfig } from '@objectql/plugin-validat
|
|
|
11
11
|
import { FormulaPlugin, FormulaPluginConfig } from '@objectql/plugin-formula';
|
|
12
12
|
import { QueryService } from './query/query-service';
|
|
13
13
|
import { QueryAnalyzer } from './query/query-analyzer';
|
|
14
|
+
import { ObjectStackProtocolImplementation } from './protocol';
|
|
14
15
|
import type { Driver } from '@objectql/types';
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -190,6 +191,15 @@ export class ObjectQLPlugin implements RuntimePlugin {
|
|
|
190
191
|
engine: kernel,
|
|
191
192
|
getKernel: () => kernel
|
|
192
193
|
};
|
|
194
|
+
|
|
195
|
+
// Register Protocol Service
|
|
196
|
+
// If kernel supports service registration (PluginContext or ExtendedKernel with custom registry)
|
|
197
|
+
if (kernel && typeof kernel.registerService === 'function') {
|
|
198
|
+
console.log(`[${this.name}] Registering protocol service...`);
|
|
199
|
+
const protocolShim = new ObjectStackProtocolImplementation(kernel as any);
|
|
200
|
+
kernel.registerService('protocol', protocolShim);
|
|
201
|
+
}
|
|
202
|
+
|
|
193
203
|
return this.install(ctx);
|
|
194
204
|
}
|
|
195
205
|
|