@objectstack/objectql 0.4.2 → 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/dist/index.d.ts CHANGED
@@ -1,164 +1,6 @@
1
- import { HookContext } from '@objectstack/spec/data';
2
- import { DriverInterface, DriverOptions } from '@objectstack/spec/system';
3
1
  export { SchemaRegistry } from './registry';
4
- export type HookHandler = (context: HookContext) => Promise<void> | void;
5
- /**
6
- * Host Context provided to plugins
7
- */
8
- export interface PluginContext {
9
- ql: ObjectQL;
10
- logger: Console;
11
- [key: string]: any;
12
- }
13
- /**
14
- * ObjectQL Engine
15
- */
16
- export declare class ObjectQL {
17
- private drivers;
18
- private defaultDriver;
19
- private hooks;
20
- private hostContext;
21
- constructor(hostContext?: Record<string, any>);
22
- /**
23
- * Load and Register a Plugin
24
- */
25
- use(manifestPart: any, runtimePart?: any): Promise<void>;
26
- /**
27
- * Register a hook
28
- * @param event The event name (e.g. 'beforeFind', 'afterInsert')
29
- * @param handler The handler function
30
- */
31
- registerHook(event: string, handler: HookHandler): void;
32
- private triggerHooks;
33
- /**
34
- * Register a new storage driver
35
- */
36
- registerDriver(driver: DriverInterface, isDefault?: boolean): void;
37
- /**
38
- * Helper to get object definition
39
- */
40
- getSchema(objectName: string): {
41
- fields: Record<string, {
42
- 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";
43
- required: boolean;
44
- searchable: boolean;
45
- multiple: boolean;
46
- unique: boolean;
47
- deleteBehavior: "set_null" | "cascade" | "restrict";
48
- hidden: boolean;
49
- readonly: boolean;
50
- encryption: boolean;
51
- index: boolean;
52
- externalId: boolean;
53
- options?: {
54
- value: string;
55
- label: string;
56
- color?: string | undefined;
57
- default?: boolean | undefined;
58
- }[] | undefined;
59
- min?: number | undefined;
60
- max?: number | undefined;
61
- formula?: string | undefined;
62
- label?: string | undefined;
63
- precision?: number | undefined;
64
- name?: string | undefined;
65
- description?: string | undefined;
66
- format?: string | undefined;
67
- defaultValue?: any;
68
- maxLength?: number | undefined;
69
- minLength?: number | undefined;
70
- scale?: number | undefined;
71
- reference?: string | undefined;
72
- referenceFilters?: string[] | undefined;
73
- writeRequiresMasterRead?: boolean | undefined;
74
- expression?: string | undefined;
75
- summaryOperations?: {
76
- object: string;
77
- function: "count" | "sum" | "avg" | "min" | "max";
78
- field: string;
79
- } | undefined;
80
- language?: string | undefined;
81
- theme?: string | undefined;
82
- lineNumbers?: boolean | undefined;
83
- maxRating?: number | undefined;
84
- allowHalf?: boolean | undefined;
85
- displayMap?: boolean | undefined;
86
- allowGeocoding?: boolean | undefined;
87
- addressFormat?: "us" | "uk" | "international" | undefined;
88
- colorFormat?: "hex" | "rgb" | "rgba" | "hsl" | undefined;
89
- allowAlpha?: boolean | undefined;
90
- presetColors?: string[] | undefined;
91
- step?: number | undefined;
92
- showValue?: boolean | undefined;
93
- marks?: Record<string, string> | undefined;
94
- barcodeFormat?: "qr" | "ean13" | "ean8" | "code128" | "code39" | "upca" | "upce" | undefined;
95
- qrErrorCorrection?: "L" | "M" | "Q" | "H" | undefined;
96
- displayValue?: boolean | undefined;
97
- allowScanning?: boolean | undefined;
98
- currencyConfig?: {
99
- precision: number;
100
- currencyMode: "dynamic" | "fixed";
101
- defaultCurrency: string;
102
- } | undefined;
103
- vectorConfig?: {
104
- dimensions: number;
105
- distanceMetric: "cosine" | "euclidean" | "dotProduct" | "manhattan";
106
- normalized: boolean;
107
- indexed: boolean;
108
- indexType?: "flat" | "hnsw" | "ivfflat" | undefined;
109
- } | undefined;
110
- }>;
111
- name: string;
112
- active: boolean;
113
- isSystem: boolean;
114
- abstract: boolean;
115
- datasource: string;
116
- tags?: string[] | undefined;
117
- label?: string | undefined;
118
- description?: string | undefined;
119
- search?: {
120
- fields: string[];
121
- displayFields?: string[] | undefined;
122
- filters?: string[] | undefined;
123
- } | undefined;
124
- pluralLabel?: string | undefined;
125
- icon?: string | undefined;
126
- tableName?: string | undefined;
127
- indexes?: {
128
- fields: string[];
129
- type?: "hash" | "btree" | "gin" | "gist" | undefined;
130
- name?: string | undefined;
131
- unique?: boolean | undefined;
132
- }[] | undefined;
133
- validations?: any[] | undefined;
134
- titleFormat?: string | undefined;
135
- compactLayout?: string[] | undefined;
136
- enable?: {
137
- searchable: boolean;
138
- trackHistory: boolean;
139
- apiEnabled: boolean;
140
- files: boolean;
141
- feeds: boolean;
142
- activities: boolean;
143
- trash: boolean;
144
- mru: boolean;
145
- clone: boolean;
146
- apiMethods?: ("update" | "delete" | "get" | "list" | "create" | "upsert" | "bulk" | "aggregate" | "history" | "search" | "restore" | "purge" | "import" | "export")[] | undefined;
147
- } | undefined;
148
- } | undefined;
149
- /**
150
- * Helper to get the target driver
151
- */
152
- private getDriver;
153
- /**
154
- * Initialize the engine and all registered drivers
155
- */
156
- init(): Promise<void>;
157
- destroy(): Promise<void>;
158
- find(object: string, query?: any, options?: DriverOptions): Promise<any>;
159
- findOne(object: string, idOrQuery: string | any, options?: DriverOptions): Promise<Record<string, any> | null>;
160
- insert(object: string, data: Record<string, any>, options?: DriverOptions): Promise<any>;
161
- update(object: string, id: string | number, data: Record<string, any>, options?: DriverOptions): Promise<any>;
162
- delete(object: string, id: string | number, options?: DriverOptions): Promise<any>;
163
- }
2
+ export { ObjectStackProtocolImplementation } from './protocol';
3
+ export { ObjectQL } from './engine';
4
+ export type { ObjectQLHostContext, HookHandler } from './engine';
5
+ export { ObjectQLPlugin } from './plugin';
164
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA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,OAAO,EAAE,iCAAiC,EAAE,MAAM,YAAY,CAAC;AAG/D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,YAAY,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGjE,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -1,286 +1,9 @@
1
- import { SchemaRegistry } from './registry';
2
- // Export Registry for consumers
1
+ // Export Registry
3
2
  export { SchemaRegistry } from './registry';
4
- /**
5
- * ObjectQL Engine
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
- // 1. Handle Module Imports (commonjs/esm interop)
30
- // If the passed object is a module namespace with a default export, use that.
31
- const manifest = manifestPart.default || manifestPart;
32
- // In a real scenario, we might strictly parse this using Zod
33
- // For now, simple ID check
34
- const id = manifest.id || manifest.name;
35
- if (!id) {
36
- console.warn(`[ObjectQL] Plugin manifest missing ID (keys: ${Object.keys(manifest)})`, manifest);
37
- // Don't return, try to proceed if it looks like an App (Apps might use 'name' instead of 'id')
38
- // return;
39
- }
40
- console.log(`[ObjectQL] Loading Plugin: ${id}`);
41
- SchemaRegistry.registerPlugin(manifest);
42
- // Register Objects from App/Plugin
43
- if (manifest.objects) {
44
- for (const obj of manifest.objects) {
45
- // Ensure object name is registered globally
46
- SchemaRegistry.registerObject(obj);
47
- console.log(`[ObjectQL] Registered Object: ${obj.name}`);
48
- }
49
- }
50
- // Register contributions
51
- if (manifest.contributes?.kinds) {
52
- for (const kind of manifest.contributes.kinds) {
53
- SchemaRegistry.registerKind(kind);
54
- }
55
- }
56
- // Register Data Seeding (Lazy execution or immediate?)
57
- // We store it in a temporary registry or execute immediately if engine is ready.
58
- // Since `use` is init time, we might need to store it and run later in `seed()`.
59
- // For this MVP, let's attach it to the manifest object in registry so Kernel can find it.
60
- }
61
- // 2. Execute Runtime
62
- if (runtimePart) {
63
- const pluginDef = runtimePart.default || runtimePart;
64
- if (pluginDef.onEnable) {
65
- const context = {
66
- ql: this,
67
- logger: console,
68
- // Expose the driver registry helper explicitly if needed
69
- drivers: {
70
- register: (driver) => this.registerDriver(driver)
71
- },
72
- ...this.hostContext
73
- };
74
- await pluginDef.onEnable(context);
75
- }
76
- }
77
- }
78
- /**
79
- * Register a hook
80
- * @param event The event name (e.g. 'beforeFind', 'afterInsert')
81
- * @param handler The handler function
82
- */
83
- registerHook(event, handler) {
84
- if (!this.hooks[event]) {
85
- this.hooks[event] = [];
86
- }
87
- this.hooks[event].push(handler);
88
- console.log(`[ObjectQL] Registered hook for ${event}`);
89
- }
90
- async triggerHooks(event, context) {
91
- const handlers = this.hooks[event] || [];
92
- for (const handler of handlers) {
93
- // In a real system, we might want to catch errors here or allow them to bubble up
94
- await handler(context);
95
- }
96
- }
97
- /**
98
- * Register a new storage driver
99
- */
100
- registerDriver(driver, isDefault = false) {
101
- if (this.drivers.has(driver.name)) {
102
- console.warn(`[ObjectQL] Driver ${driver.name} is already registered. Skipping.`);
103
- return;
104
- }
105
- this.drivers.set(driver.name, driver);
106
- console.log(`[ObjectQL] Registered driver: ${driver.name} v${driver.version}`);
107
- if (isDefault || this.drivers.size === 1) {
108
- this.defaultDriver = driver.name;
109
- }
110
- }
111
- /**
112
- * Helper to get object definition
113
- */
114
- getSchema(objectName) {
115
- return SchemaRegistry.getObject(objectName);
116
- }
117
- /**
118
- * Helper to get the target driver
119
- */
120
- getDriver(objectName) {
121
- const object = SchemaRegistry.getObject(objectName);
122
- // 1. If object definition exists, check for explicit datasource
123
- if (object) {
124
- const datasourceName = object.datasource || 'default';
125
- // If configured for 'default', try to find the default driver
126
- if (datasourceName === 'default') {
127
- if (this.defaultDriver && this.drivers.has(this.defaultDriver)) {
128
- return this.drivers.get(this.defaultDriver);
129
- }
130
- // Fallback: If 'default' not explicitly set, use the first available driver?
131
- // Better to be strict.
132
- }
133
- else {
134
- // Specific datasource requested
135
- if (this.drivers.has(datasourceName)) {
136
- return this.drivers.get(datasourceName);
137
- }
138
- // If not found, fall back to default? Or error?
139
- // Standard behavior: Error if specific datasource is missing.
140
- throw new Error(`[ObjectQL] Datasource '${datasourceName}' configured for object '${objectName}' is not registered.`);
141
- }
142
- }
143
- // 2. Fallback for ad-hoc objects or missing definitions
144
- // If we have a default driver, use it.
145
- if (this.defaultDriver) {
146
- if (!object) {
147
- console.warn(`[ObjectQL] Object '${objectName}' not found in registry. Using default driver.`);
148
- }
149
- return this.drivers.get(this.defaultDriver);
150
- }
151
- throw new Error(`[ObjectQL] No driver available for object '${objectName}'`);
152
- }
153
- /**
154
- * Initialize the engine and all registered drivers
155
- */
156
- async init() {
157
- console.log('[ObjectQL] Initializing drivers...');
158
- for (const [name, driver] of this.drivers) {
159
- try {
160
- await driver.connect();
161
- }
162
- catch (e) {
163
- console.error(`[ObjectQL] Failed to connect driver ${name}`, e);
164
- }
165
- }
166
- // In a real app, we would sync schemas here
167
- }
168
- async destroy() {
169
- for (const driver of this.drivers.values()) {
170
- await driver.disconnect();
171
- }
172
- }
173
- // ============================================
174
- // Data Access Methods
175
- // ============================================
176
- async find(object, query = {}, options) {
177
- const driver = this.getDriver(object);
178
- // Normalize QueryAST
179
- let ast;
180
- if (query.where || query.fields || query.orderBy || query.limit) {
181
- ast = { object, ...query };
182
- }
183
- else {
184
- ast = { object, where: query };
185
- }
186
- if (ast.limit === undefined)
187
- ast.limit = 100;
188
- // Trigger Before Hook
189
- const hookContext = {
190
- object,
191
- event: 'beforeFind',
192
- input: { ast, options }, // Hooks can modify AST here
193
- ql: this
194
- };
195
- await this.triggerHooks('beforeFind', hookContext);
196
- try {
197
- const result = await driver.find(object, hookContext.input.ast, hookContext.input.options);
198
- // Trigger After Hook
199
- hookContext.event = 'afterFind';
200
- hookContext.result = result;
201
- await this.triggerHooks('afterFind', hookContext);
202
- return hookContext.result;
203
- }
204
- catch (e) {
205
- // hookContext.error = e;
206
- throw e;
207
- }
208
- }
209
- async findOne(object, idOrQuery, options) {
210
- const driver = this.getDriver(object);
211
- let ast;
212
- if (typeof idOrQuery === 'string') {
213
- ast = {
214
- object,
215
- where: { _id: idOrQuery }
216
- };
217
- }
218
- else {
219
- // Assume query object
220
- // reuse logic from find() or just wrap it
221
- if (idOrQuery.where || idOrQuery.fields) {
222
- ast = { object, ...idOrQuery };
223
- }
224
- else {
225
- ast = { object, where: idOrQuery };
226
- }
227
- }
228
- // Limit 1 for findOne
229
- ast.limit = 1;
230
- return driver.findOne(object, ast, options);
231
- }
232
- async insert(object, data, options) {
233
- const driver = this.getDriver(object);
234
- // 1. Get Schema
235
- const schema = SchemaRegistry.getObject(object);
236
- if (schema) {
237
- // TODO: Validation Logic
238
- // validate(schema, data);
239
- }
240
- // 2. Trigger Before Hook
241
- const hookContext = {
242
- object,
243
- event: 'beforeInsert',
244
- input: { data, options },
245
- ql: this
246
- };
247
- await this.triggerHooks('beforeInsert', hookContext);
248
- // 3. Execute Driver
249
- const result = await driver.create(object, hookContext.input.data, hookContext.input.options);
250
- // 4. Trigger After Hook
251
- hookContext.event = 'afterInsert';
252
- hookContext.result = result;
253
- await this.triggerHooks('afterInsert', hookContext);
254
- return hookContext.result;
255
- }
256
- async update(object, id, data, options) {
257
- const driver = this.getDriver(object);
258
- const hookContext = {
259
- object,
260
- event: 'beforeUpdate',
261
- input: { id, data, options },
262
- ql: this
263
- };
264
- await this.triggerHooks('beforeUpdate', hookContext);
265
- const result = await driver.update(object, hookContext.input.id, hookContext.input.data, hookContext.input.options);
266
- hookContext.event = 'afterUpdate';
267
- hookContext.result = result;
268
- await this.triggerHooks('afterUpdate', hookContext);
269
- return hookContext.result;
270
- }
271
- async delete(object, id, options) {
272
- const driver = this.getDriver(object);
273
- const hookContext = {
274
- object,
275
- event: 'beforeDelete',
276
- input: { id, options },
277
- ql: this
278
- };
279
- await this.triggerHooks('beforeDelete', hookContext);
280
- const result = await driver.delete(object, hookContext.input.id, hookContext.input.options);
281
- hookContext.event = 'afterDelete';
282
- hookContext.result = result;
283
- await this.triggerHooks('afterDelete', hookContext);
284
- return hookContext.result;
285
- }
286
- }
3
+ // Export Protocol Implementation
4
+ export { ObjectStackProtocolImplementation } from './protocol';
5
+ // Export Engine
6
+ export { ObjectQL } from './engine';
7
+ // Export Plugin Shim
8
+ export { ObjectQLPlugin } from './plugin';
9
+ // Moved logic to engine.ts
@@ -0,0 +1,14 @@
1
+ import { ObjectQL } from './engine';
2
+ import { Plugin, PluginContext } from '@objectstack/core';
3
+ export type { Plugin, PluginContext };
4
+ export declare class ObjectQLPlugin implements Plugin {
5
+ name: string;
6
+ type: "objectql";
7
+ version: string;
8
+ private ql;
9
+ private hostContext?;
10
+ constructor(ql?: ObjectQL, hostContext?: Record<string, any>);
11
+ init(ctx: PluginContext): Promise<void>;
12
+ start(ctx: PluginContext): Promise<void>;
13
+ }
14
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAE1D,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;AAEtC,qBAAa,cAAe,YAAW,MAAM;IAC3C,IAAI,SAAqC;IACzC,IAAI,EAAG,UAAU,CAAU;IAC3B,OAAO,SAAW;IAElB,OAAO,CAAC,EAAE,CAAuB;IACjC,OAAO,CAAC,WAAW,CAAC,CAAsB;gBAE9B,EAAE,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAStD,IAAI,CAAC,GAAG,EAAE,aAAa;IAkBvB,KAAK,CAAC,GAAG,EAAE,aAAa;CAoB/B"}
package/dist/plugin.js ADDED
@@ -0,0 +1,54 @@
1
+ import { ObjectQL } from './engine';
2
+ import { ObjectStackProtocolImplementation } from './protocol';
3
+ export class ObjectQLPlugin {
4
+ constructor(ql, hostContext) {
5
+ this.name = 'com.objectstack.engine.objectql';
6
+ this.type = 'objectql';
7
+ this.version = '1.0.0';
8
+ if (ql) {
9
+ this.ql = ql;
10
+ }
11
+ else {
12
+ this.hostContext = hostContext;
13
+ // Lazily created in init
14
+ }
15
+ }
16
+ async init(ctx) {
17
+ if (!this.ql) {
18
+ this.ql = new ObjectQL(this.hostContext);
19
+ }
20
+ ctx.registerService('objectql', this.ql);
21
+ if (ctx.logger)
22
+ ctx.logger.log(`[ObjectQLPlugin] ObjectQL engine registered as service`);
23
+ // Register Protocol Implementation
24
+ if (!this.ql) {
25
+ throw new Error('ObjectQL engine not initialized');
26
+ }
27
+ const protocolShim = new ObjectStackProtocolImplementation(this.ql);
28
+ ctx.registerService('protocol', protocolShim);
29
+ if (ctx.logger)
30
+ ctx.logger.log(`[ObjectQLPlugin] Protocol service registered`);
31
+ }
32
+ async start(ctx) {
33
+ if (ctx.logger)
34
+ ctx.logger.log(`[ObjectQLPlugin] ObjectQL engine initialized`);
35
+ // Discover features from Kernel Services
36
+ if (ctx.getServices && this.ql) {
37
+ const services = ctx.getServices();
38
+ for (const [name, service] of services.entries()) {
39
+ if (name.startsWith('driver.')) {
40
+ // Register Driver
41
+ this.ql.registerDriver(service);
42
+ if (ctx.logger)
43
+ ctx.logger.log(`[ObjectQLPlugin] Discovered and registered driver service: ${name}`);
44
+ }
45
+ if (name.startsWith('app.')) {
46
+ // Register App
47
+ this.ql.registerApp(service); // service is Manifest
48
+ if (ctx.logger)
49
+ ctx.logger.log(`[ObjectQLPlugin] Discovered and registered app service: ${name}`);
50
+ }
51
+ }
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,43 @@
1
+ import { IObjectStackProtocol } from '@objectstack/spec/api';
2
+ import { IDataEngine } from '@objectstack/core';
3
+ export declare class ObjectStackProtocolImplementation implements IObjectStackProtocol {
4
+ private engine;
5
+ constructor(engine: IDataEngine);
6
+ getDiscovery(): {
7
+ name: string;
8
+ version: string;
9
+ capabilities: {
10
+ metadata: boolean;
11
+ data: boolean;
12
+ ui: boolean;
13
+ };
14
+ };
15
+ getMetaTypes(): string[];
16
+ getMetaItems(type: string): unknown[];
17
+ getMetaItem(type: string, name: string): unknown;
18
+ getUiView(object: string, type: 'list' | 'form'): {
19
+ type: string;
20
+ object: string;
21
+ columns: {
22
+ field: string;
23
+ label: string;
24
+ }[];
25
+ sections?: undefined;
26
+ } | {
27
+ type: string;
28
+ object: string;
29
+ sections: {
30
+ label: string;
31
+ fields: {
32
+ field: string;
33
+ }[];
34
+ }[];
35
+ columns?: undefined;
36
+ };
37
+ findData(object: string, query: any): Promise<any[]>;
38
+ getData(object: string, id: string): Promise<any>;
39
+ createData(object: string, data: any): Promise<any>;
40
+ updateData(object: string, id: string, data: any): Promise<any>;
41
+ deleteData(object: string, id: string): Promise<boolean>;
42
+ }
43
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKhD,qBAAa,iCAAkC,YAAW,oBAAoB;IAC1E,OAAO,CAAC,MAAM,CAAc;gBAEhB,MAAM,EAAE,WAAW;IAI/B,YAAY;;;;;;;;;IAYZ,YAAY;IAIZ,YAAY,CAAC,IAAI,EAAE,MAAM;IAIzB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAItC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;;;;;;;;;;;;;;;;;;;IA6B/C,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG;IAI7B,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAsBxC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;IAIpC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;IAIhD,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;CAGxC"}
@@ -0,0 +1,87 @@
1
+ // We import SchemaRegistry directly since this class lives in the same package
2
+ import { SchemaRegistry } from './registry';
3
+ export class ObjectStackProtocolImplementation {
4
+ constructor(engine) {
5
+ this.engine = engine;
6
+ }
7
+ getDiscovery() {
8
+ return {
9
+ name: 'ObjectStack API',
10
+ version: '1.0',
11
+ capabilities: {
12
+ metadata: true,
13
+ data: true,
14
+ ui: true
15
+ }
16
+ };
17
+ }
18
+ getMetaTypes() {
19
+ return SchemaRegistry.getRegisteredTypes();
20
+ }
21
+ getMetaItems(type) {
22
+ return SchemaRegistry.listItems(type);
23
+ }
24
+ getMetaItem(type, name) {
25
+ return SchemaRegistry.getItem(type, name);
26
+ }
27
+ getUiView(object, type) {
28
+ const schema = SchemaRegistry.getObject(object);
29
+ if (!schema)
30
+ throw new Error(`Object ${object} not found`);
31
+ if (type === 'list') {
32
+ return {
33
+ type: 'list',
34
+ object: object,
35
+ columns: Object.keys(schema.fields || {}).slice(0, 5).map(f => ({
36
+ field: f,
37
+ label: schema.fields[f].label || f
38
+ }))
39
+ };
40
+ }
41
+ else {
42
+ return {
43
+ type: 'form',
44
+ object: object,
45
+ sections: [
46
+ {
47
+ label: 'General',
48
+ fields: Object.keys(schema.fields || {}).map(f => ({
49
+ field: f
50
+ }))
51
+ }
52
+ ]
53
+ };
54
+ }
55
+ }
56
+ findData(object, query) {
57
+ return this.engine.find(object, query);
58
+ }
59
+ async getData(object, id) {
60
+ // IDataEngine doesn't have findOne, so we simulate it with find and limit 1
61
+ // Assuming the ID field is named '_id' or 'id'.
62
+ // For broad compatibility, we might need to know the ID field name.
63
+ // But traditionally it is _id in ObjectStack/mongo or id in others.
64
+ // Let's rely on finding by ID if the engine supports it via find?
65
+ // Actually, ObjectQL (the implementation) DOES have findOne.
66
+ // But we are programming against IDataEngine interface here.
67
+ // If the engine IS ObjectQL (which it practically is), we could cast it.
68
+ // But let's try to stick to interface.
69
+ const results = await this.engine.find(object, {
70
+ filter: { _id: id }, // Default Assumption: _id
71
+ limit: 1
72
+ });
73
+ if (results && results.length > 0) {
74
+ return results[0];
75
+ }
76
+ throw new Error(`Record ${id} not found in ${object}`);
77
+ }
78
+ createData(object, data) {
79
+ return this.engine.insert(object, data);
80
+ }
81
+ updateData(object, id, data) {
82
+ return this.engine.update(object, id, data);
83
+ }
84
+ deleteData(object, id) {
85
+ return this.engine.delete(object, id);
86
+ }
87
+ }