@objectstack/runtime 0.4.2 → 0.6.0
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/CHANGELOG.md +18 -0
- package/README.md +196 -81
- package/dist/app-manifest-plugin.d.ts +19 -0
- package/dist/app-manifest-plugin.js +33 -0
- package/dist/driver-plugin.d.ts +23 -0
- package/dist/driver-plugin.js +31 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +9 -5
- package/dist/test-interfaces.d.ts +7 -0
- package/dist/test-interfaces.js +138 -0
- package/package.json +6 -4
- package/src/app-manifest-plugin.ts +48 -0
- package/src/driver-plugin.ts +40 -0
- package/src/index.ts +12 -5
- package/src/test-interfaces.ts +170 -0
- package/dist/kernel.d.ts +0 -147
- package/dist/kernel.js +0 -173
- package/dist/objectql-plugin.d.ts +0 -27
- package/dist/objectql-plugin.js +0 -41
- package/dist/protocol.d.ts +0 -68
- package/dist/protocol.js +0 -108
- package/dist/types.d.ts +0 -9
- package/dist/types.js +0 -1
- package/src/kernel.ts +0 -203
- package/src/objectql-plugin.ts +0 -47
- package/src/protocol.ts +0 -129
- package/src/types.ts +0 -11
package/dist/objectql-plugin.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ObjectQL } from '@objectstack/objectql';
|
|
2
|
-
/**
|
|
3
|
-
* ObjectQL Engine Plugin
|
|
4
|
-
*
|
|
5
|
-
* Registers the ObjectQL engine instance with the kernel.
|
|
6
|
-
* This allows users to provide their own ObjectQL implementation or configuration.
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* - new ObjectQLPlugin() - Creates new ObjectQL with default settings
|
|
10
|
-
* - new ObjectQLPlugin(existingQL) - Uses existing ObjectQL instance
|
|
11
|
-
* - new ObjectQLPlugin(undefined, { custom: 'context' }) - Creates new ObjectQL with custom context
|
|
12
|
-
*/
|
|
13
|
-
export class ObjectQLPlugin {
|
|
14
|
-
/**
|
|
15
|
-
* @param ql - Existing ObjectQL instance to use (optional)
|
|
16
|
-
* @param hostContext - Host context for new ObjectQL instance (ignored if ql is provided)
|
|
17
|
-
*/
|
|
18
|
-
constructor(ql, hostContext) {
|
|
19
|
-
this.name = 'com.objectstack.engine.objectql';
|
|
20
|
-
this.type = 'objectql';
|
|
21
|
-
if (ql && hostContext) {
|
|
22
|
-
console.warn('[ObjectQLPlugin] Both ql and hostContext provided. hostContext will be ignored.');
|
|
23
|
-
}
|
|
24
|
-
if (ql) {
|
|
25
|
-
this.ql = ql;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
this.ql = new ObjectQL(hostContext || {
|
|
29
|
-
env: process.env.NODE_ENV || 'development'
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Install the ObjectQL engine into the kernel
|
|
35
|
-
*/
|
|
36
|
-
async install(ctx) {
|
|
37
|
-
// Attach the ObjectQL engine to the kernel
|
|
38
|
-
ctx.engine.ql = this.ql;
|
|
39
|
-
console.log('[ObjectQLPlugin] ObjectQL engine registered');
|
|
40
|
-
}
|
|
41
|
-
}
|
package/dist/protocol.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { ObjectStackKernel } from './kernel';
|
|
2
|
-
export interface ApiRequest {
|
|
3
|
-
params: Record<string, string>;
|
|
4
|
-
query: Record<string, string | string[]>;
|
|
5
|
-
body?: any;
|
|
6
|
-
}
|
|
7
|
-
export declare class ObjectStackRuntimeProtocol {
|
|
8
|
-
private engine;
|
|
9
|
-
constructor(engine: ObjectStackKernel);
|
|
10
|
-
getDiscovery(): {
|
|
11
|
-
name: string;
|
|
12
|
-
version: string;
|
|
13
|
-
environment: string;
|
|
14
|
-
routes: {
|
|
15
|
-
discovery: string;
|
|
16
|
-
metadata: string;
|
|
17
|
-
data: string;
|
|
18
|
-
auth: string;
|
|
19
|
-
ui: string;
|
|
20
|
-
};
|
|
21
|
-
capabilities: {
|
|
22
|
-
search: boolean;
|
|
23
|
-
files: boolean;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
getMetaTypes(): {
|
|
27
|
-
data: {
|
|
28
|
-
type: string;
|
|
29
|
-
href: string;
|
|
30
|
-
count: number;
|
|
31
|
-
}[];
|
|
32
|
-
};
|
|
33
|
-
getMetaItems(typePlural: string): {
|
|
34
|
-
data: {
|
|
35
|
-
self: string;
|
|
36
|
-
path?: string | undefined;
|
|
37
|
-
id: any;
|
|
38
|
-
name: any;
|
|
39
|
-
label: any;
|
|
40
|
-
type: any;
|
|
41
|
-
icon: any;
|
|
42
|
-
description: any;
|
|
43
|
-
}[];
|
|
44
|
-
};
|
|
45
|
-
getMetaItem(typePlural: string, name: string): {};
|
|
46
|
-
getUiView(objectName: string, type: 'list' | 'form'): {
|
|
47
|
-
type: string;
|
|
48
|
-
title: string;
|
|
49
|
-
columns: {
|
|
50
|
-
field: string;
|
|
51
|
-
label: string;
|
|
52
|
-
width: number;
|
|
53
|
-
}[];
|
|
54
|
-
actions: string[];
|
|
55
|
-
};
|
|
56
|
-
findData(objectName: string, query: any): Promise<{
|
|
57
|
-
value: any;
|
|
58
|
-
count: any;
|
|
59
|
-
}>;
|
|
60
|
-
queryData(objectName: string, body: any): Promise<{
|
|
61
|
-
value: any;
|
|
62
|
-
count: any;
|
|
63
|
-
}>;
|
|
64
|
-
getData(objectName: string, id: string): Promise<any>;
|
|
65
|
-
createData(objectName: string, body: any): Promise<any>;
|
|
66
|
-
updateData(objectName: string, id: string, body: any): Promise<any>;
|
|
67
|
-
deleteData(objectName: string, id: string): Promise<any>;
|
|
68
|
-
}
|
package/dist/protocol.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { SchemaRegistry } from '@objectstack/objectql';
|
|
2
|
-
export class ObjectStackRuntimeProtocol {
|
|
3
|
-
constructor(engine) {
|
|
4
|
-
this.engine = engine;
|
|
5
|
-
}
|
|
6
|
-
// 1. Discovery
|
|
7
|
-
getDiscovery() {
|
|
8
|
-
return {
|
|
9
|
-
name: 'ObjectOS Server',
|
|
10
|
-
version: '1.0.0',
|
|
11
|
-
environment: process.env.NODE_ENV || 'development',
|
|
12
|
-
routes: {
|
|
13
|
-
discovery: '/api/v1',
|
|
14
|
-
metadata: '/api/v1/meta',
|
|
15
|
-
data: '/api/v1/data',
|
|
16
|
-
auth: '/api/v1/auth',
|
|
17
|
-
ui: '/api/v1/ui'
|
|
18
|
-
},
|
|
19
|
-
capabilities: {
|
|
20
|
-
search: true,
|
|
21
|
-
files: true
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
// 2. Metadata: List Types
|
|
26
|
-
getMetaTypes() {
|
|
27
|
-
const types = SchemaRegistry.getRegisteredTypes();
|
|
28
|
-
return {
|
|
29
|
-
data: types.map(type => ({
|
|
30
|
-
type,
|
|
31
|
-
href: `/api/v1/meta/${type}s`,
|
|
32
|
-
count: SchemaRegistry.listItems(type).length
|
|
33
|
-
}))
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
// 3. Metadata: List Items by Type
|
|
37
|
-
getMetaItems(typePlural) {
|
|
38
|
-
// Simple Singularization Mapping
|
|
39
|
-
const typeMap = {
|
|
40
|
-
'objects': 'object',
|
|
41
|
-
'apps': 'app',
|
|
42
|
-
'flows': 'flow',
|
|
43
|
-
'reports': 'report',
|
|
44
|
-
'plugins': 'plugin',
|
|
45
|
-
'kinds': 'kind'
|
|
46
|
-
};
|
|
47
|
-
const type = typeMap[typePlural] || typePlural;
|
|
48
|
-
const items = SchemaRegistry.listItems(type);
|
|
49
|
-
const summaries = items.map((item) => ({
|
|
50
|
-
id: item.id,
|
|
51
|
-
name: item.name,
|
|
52
|
-
label: item.label,
|
|
53
|
-
type: item.type,
|
|
54
|
-
icon: item.icon,
|
|
55
|
-
description: item.description,
|
|
56
|
-
...(type === 'object' ? { path: `/api/v1/data/${item.name}` } : {}),
|
|
57
|
-
self: `/api/v1/meta/${typePlural}/${item.name || item.id}`
|
|
58
|
-
}));
|
|
59
|
-
return { data: summaries };
|
|
60
|
-
}
|
|
61
|
-
// 4. Metadata: Get Single Item
|
|
62
|
-
getMetaItem(typePlural, name) {
|
|
63
|
-
const typeMap = {
|
|
64
|
-
'objects': 'object',
|
|
65
|
-
'apps': 'app',
|
|
66
|
-
'flows': 'flow',
|
|
67
|
-
'reports': 'report',
|
|
68
|
-
'plugins': 'plugin',
|
|
69
|
-
'kinds': 'kind'
|
|
70
|
-
};
|
|
71
|
-
const type = typeMap[typePlural] || typePlural;
|
|
72
|
-
const item = SchemaRegistry.getItem(type, name);
|
|
73
|
-
if (!item)
|
|
74
|
-
throw new Error(`Metadata not found: ${type}/${name}`);
|
|
75
|
-
return item;
|
|
76
|
-
}
|
|
77
|
-
// 5. UI: View Definition
|
|
78
|
-
getUiView(objectName, type) {
|
|
79
|
-
const view = this.engine.getView(objectName, type);
|
|
80
|
-
if (!view)
|
|
81
|
-
throw new Error('View not generated');
|
|
82
|
-
return view;
|
|
83
|
-
}
|
|
84
|
-
// 6. Data: Find
|
|
85
|
-
async findData(objectName, query) {
|
|
86
|
-
return await this.engine.find(objectName, query);
|
|
87
|
-
}
|
|
88
|
-
// 7. Data: Query (Advanced AST)
|
|
89
|
-
async queryData(objectName, body) {
|
|
90
|
-
return await this.engine.find(objectName, body);
|
|
91
|
-
}
|
|
92
|
-
// 8. Data: Get
|
|
93
|
-
async getData(objectName, id) {
|
|
94
|
-
return await this.engine.get(objectName, id);
|
|
95
|
-
}
|
|
96
|
-
// 9. Data: Create
|
|
97
|
-
async createData(objectName, body) {
|
|
98
|
-
return await this.engine.create(objectName, body);
|
|
99
|
-
}
|
|
100
|
-
// 10. Data: Update
|
|
101
|
-
async updateData(objectName, id, body) {
|
|
102
|
-
return await this.engine.update(objectName, id, body);
|
|
103
|
-
}
|
|
104
|
-
// 11. Data: Delete
|
|
105
|
-
async deleteData(objectName, id) {
|
|
106
|
-
return await this.engine.delete(objectName, id);
|
|
107
|
-
}
|
|
108
|
-
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ObjectStackKernel } from './kernel';
|
|
2
|
-
export interface RuntimeContext {
|
|
3
|
-
engine: ObjectStackKernel;
|
|
4
|
-
}
|
|
5
|
-
export interface RuntimePlugin {
|
|
6
|
-
name: string;
|
|
7
|
-
install?: (ctx: RuntimeContext) => void | Promise<void>;
|
|
8
|
-
onStart?: (ctx: RuntimeContext) => void | Promise<void>;
|
|
9
|
-
}
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/kernel.ts
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { ServiceObject } from '@objectstack/spec/data';
|
|
2
|
-
import { SchemaRegistry, ObjectQL } from '@objectstack/objectql';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* ObjectStack Kernel (Microkernel)
|
|
6
|
-
*
|
|
7
|
-
* The central container orchestrating the application lifecycle,
|
|
8
|
-
* plugins, and the core ObjectQL engine.
|
|
9
|
-
*/
|
|
10
|
-
export class ObjectStackKernel {
|
|
11
|
-
public ql?: ObjectQL; // Will be set by ObjectQLPlugin or fallback initialization
|
|
12
|
-
private plugins: any[];
|
|
13
|
-
|
|
14
|
-
constructor(plugins: any[] = []) {
|
|
15
|
-
this.plugins = plugins;
|
|
16
|
-
|
|
17
|
-
// Check if any plugin provides ObjectQL via type: 'objectql'
|
|
18
|
-
// This aligns with the manifest schema that supports objectql as a package type
|
|
19
|
-
const hasObjectQLPlugin = plugins.some(p =>
|
|
20
|
-
p && typeof p === 'object' && p.type === 'objectql'
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
if (!hasObjectQLPlugin) {
|
|
24
|
-
// Backward compatibility: Initialize ObjectQL directly if no plugin provides it
|
|
25
|
-
console.warn('[Kernel] No ObjectQL plugin found, using default initialization. Consider using ObjectQLPlugin.');
|
|
26
|
-
this.ql = new ObjectQL({
|
|
27
|
-
env: process.env.NODE_ENV || 'development'
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Ensure ObjectQL engine is initialized
|
|
34
|
-
* @throws Error if ObjectQL is not available
|
|
35
|
-
*/
|
|
36
|
-
private ensureObjectQL(): ObjectQL {
|
|
37
|
-
if (!this.ql) {
|
|
38
|
-
throw new Error('[Kernel] ObjectQL engine not initialized. Ensure ObjectQLPlugin is registered or kernel is properly initialized.');
|
|
39
|
-
}
|
|
40
|
-
return this.ql;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async start() {
|
|
44
|
-
console.log('[Kernel] Starting...');
|
|
45
|
-
|
|
46
|
-
// 0. Register Provided Plugins
|
|
47
|
-
for (const p of this.plugins) {
|
|
48
|
-
// Check if it is a Runtime Plugin (System Capability)
|
|
49
|
-
if ('onStart' in p || 'install' in p) {
|
|
50
|
-
console.log(`[Kernel] Loading Runtime Plugin: ${p.name}`);
|
|
51
|
-
if (p.install) await p.install({ engine: this });
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Otherwise treat as App Manifest
|
|
56
|
-
console.log(`[Kernel] Loading App Manifest: ${p.id || p.name}`);
|
|
57
|
-
SchemaRegistry.registerPlugin(p);
|
|
58
|
-
|
|
59
|
-
// Register Objects from App/Plugin
|
|
60
|
-
if (p.objects) {
|
|
61
|
-
for (const obj of p.objects) {
|
|
62
|
-
SchemaRegistry.registerObject(obj);
|
|
63
|
-
console.log(`[Kernel] Registered Object: ${obj.name}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// 1. Load Drivers (Default to Memory if none provided in plugins)
|
|
69
|
-
// TODO: Detect driver from plugins. For now, we still hard load memory driver if needed?
|
|
70
|
-
// In strict mode, user should pass driver in plugins array (DriverManifest).
|
|
71
|
-
// check if driver is registered
|
|
72
|
-
|
|
73
|
-
// For Backwards Compat / Easy Dev, try dynamic import of memory driver if installed
|
|
74
|
-
try {
|
|
75
|
-
// @ts-ignore
|
|
76
|
-
const { InMemoryDriver } = await import('@objectstack/driver-memory');
|
|
77
|
-
const driver = new InMemoryDriver();
|
|
78
|
-
this.ensureObjectQL().registerDriver(driver);
|
|
79
|
-
} catch (e) {
|
|
80
|
-
// Ignore if not present
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// 2. Initialize Engine
|
|
84
|
-
await this.ensureObjectQL().init();
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// 3. Seed Data
|
|
88
|
-
await this.seed();
|
|
89
|
-
|
|
90
|
-
// 4. Start Runtime Plugins
|
|
91
|
-
for (const p of this.plugins) {
|
|
92
|
-
if (('onStart' in p) && typeof p.onStart === 'function') {
|
|
93
|
-
console.log(`[Kernel] Starting Plugin: ${p.name}`);
|
|
94
|
-
await p.onStart({ engine: this });
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async seed() {
|
|
100
|
-
// If no driver registered yet, this might fail or wait.
|
|
101
|
-
// In real world, we wait for 'ready' event.
|
|
102
|
-
try {
|
|
103
|
-
// Mock System Table
|
|
104
|
-
try {
|
|
105
|
-
// We don't have SystemStatus defined in schema usually, skipping for general engine
|
|
106
|
-
// await this.ql.insert('SystemStatus', { status: 'OK', uptime: 0 });
|
|
107
|
-
} catch {}
|
|
108
|
-
|
|
109
|
-
// Iterate over all registered plugins/apps and check for 'data' property in manifest
|
|
110
|
-
|
|
111
|
-
const plugins = SchemaRegistry.getRegisteredTypes(); // This returns types like 'plugin', 'app'
|
|
112
|
-
|
|
113
|
-
// This is a bit hacky because we don't have a direct "getAllManifests" API exposed easily
|
|
114
|
-
// We will iterate known apps for now, or improve Registry API later.
|
|
115
|
-
// Actually, SchemaRegistry.listItems('app') returns the manifests!
|
|
116
|
-
|
|
117
|
-
const apps = [...SchemaRegistry.listItems('app'), ...SchemaRegistry.listItems('plugin')];
|
|
118
|
-
|
|
119
|
-
for (const appItem of apps) {
|
|
120
|
-
const app = appItem as any; // Cast to access data prop safely
|
|
121
|
-
if (app.data && Array.isArray(app.data)) {
|
|
122
|
-
console.log(`[Kernel] Seeding data for ${app.name || app.id}...`);
|
|
123
|
-
for (const seed of app.data) {
|
|
124
|
-
try {
|
|
125
|
-
// Check if data exists
|
|
126
|
-
const existing = await this.ensureObjectQL().find(seed.object, { top: 1 });
|
|
127
|
-
if (existing.length === 0) {
|
|
128
|
-
console.log(`[Kernel] Inserting ${seed.records.length} records into ${seed.object}`);
|
|
129
|
-
for (const record of seed.records) {
|
|
130
|
-
await this.ensureObjectQL().insert(seed.object, record);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
} catch (e) {
|
|
134
|
-
console.warn(`[Kernel] Failed to seed ${seed.object}`, e);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
} catch(e) {
|
|
141
|
-
console.warn('Seed failed (driver might not be ready):', e);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Forward methods to ObjectQL
|
|
146
|
-
async find(objectName: string, query: any) {
|
|
147
|
-
this.ensureSchema(objectName);
|
|
148
|
-
const results = await this.ensureObjectQL().find(objectName, { top: 100 });
|
|
149
|
-
return { value: results, count: results.length };
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
async get(objectName: string, id: string) {
|
|
153
|
-
this.ensureSchema(objectName);
|
|
154
|
-
// Find One
|
|
155
|
-
const results = await this.ensureObjectQL().find(objectName, { top: 1 }); // Mock implementation
|
|
156
|
-
return results[0];
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async create(objectName: string, data: any) {
|
|
160
|
-
this.ensureSchema(objectName);
|
|
161
|
-
return this.ensureObjectQL().insert(objectName, data);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
async update(objectName: string, id: string, data: any) {
|
|
165
|
-
this.ensureSchema(objectName);
|
|
166
|
-
return this.ensureObjectQL().update(objectName, id, data);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async delete(objectName: string, id: string) {
|
|
170
|
-
this.ensureSchema(objectName);
|
|
171
|
-
return this.ensureObjectQL().delete(objectName, id);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// [New Methods for ObjectUI]
|
|
175
|
-
getMetadata(objectName: string) {
|
|
176
|
-
return this.ensureSchema(objectName);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
getView(objectName: string, viewType: 'list' | 'form' = 'list') {
|
|
180
|
-
const schema = this.ensureSchema(objectName);
|
|
181
|
-
|
|
182
|
-
// Auto-Scaffold Default View
|
|
183
|
-
if (viewType === 'list') {
|
|
184
|
-
return {
|
|
185
|
-
type: 'datagrid',
|
|
186
|
-
title: `${schema.label || objectName} List`,
|
|
187
|
-
columns: Object.keys(schema.fields || {}).map(key => ({
|
|
188
|
-
field: key,
|
|
189
|
-
label: schema.fields?.[key]?.label || key,
|
|
190
|
-
width: 150
|
|
191
|
-
})),
|
|
192
|
-
actions: ['create', 'edit', 'delete']
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
private ensureSchema(name: string): ServiceObject {
|
|
199
|
-
const schema = SchemaRegistry.getObject(name);
|
|
200
|
-
if (!schema) throw new Error(`Unknown object: ${name}`);
|
|
201
|
-
return schema;
|
|
202
|
-
}
|
|
203
|
-
}
|
package/src/objectql-plugin.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ObjectQL } from '@objectstack/objectql';
|
|
2
|
-
import { RuntimePlugin, RuntimeContext } from '@objectstack/types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* ObjectQL Engine Plugin
|
|
6
|
-
*
|
|
7
|
-
* Registers the ObjectQL engine instance with the kernel.
|
|
8
|
-
* This allows users to provide their own ObjectQL implementation or configuration.
|
|
9
|
-
*
|
|
10
|
-
* Usage:
|
|
11
|
-
* - new ObjectQLPlugin() - Creates new ObjectQL with default settings
|
|
12
|
-
* - new ObjectQLPlugin(existingQL) - Uses existing ObjectQL instance
|
|
13
|
-
* - new ObjectQLPlugin(undefined, { custom: 'context' }) - Creates new ObjectQL with custom context
|
|
14
|
-
*/
|
|
15
|
-
export class ObjectQLPlugin implements RuntimePlugin {
|
|
16
|
-
name = 'com.objectstack.engine.objectql';
|
|
17
|
-
type = 'objectql' as const;
|
|
18
|
-
|
|
19
|
-
private ql: ObjectQL;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @param ql - Existing ObjectQL instance to use (optional)
|
|
23
|
-
* @param hostContext - Host context for new ObjectQL instance (ignored if ql is provided)
|
|
24
|
-
*/
|
|
25
|
-
constructor(ql?: ObjectQL, hostContext?: Record<string, any>) {
|
|
26
|
-
if (ql && hostContext) {
|
|
27
|
-
console.warn('[ObjectQLPlugin] Both ql and hostContext provided. hostContext will be ignored.');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (ql) {
|
|
31
|
-
this.ql = ql;
|
|
32
|
-
} else {
|
|
33
|
-
this.ql = new ObjectQL(hostContext || {
|
|
34
|
-
env: process.env.NODE_ENV || 'development'
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Install the ObjectQL engine into the kernel
|
|
41
|
-
*/
|
|
42
|
-
async install(ctx: RuntimeContext) {
|
|
43
|
-
// Attach the ObjectQL engine to the kernel
|
|
44
|
-
ctx.engine.ql = this.ql;
|
|
45
|
-
console.log('[ObjectQLPlugin] ObjectQL engine registered');
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/protocol.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { SchemaRegistry } from '@objectstack/objectql';
|
|
2
|
-
import { ObjectStackKernel } from './kernel';
|
|
3
|
-
|
|
4
|
-
export interface ApiRequest {
|
|
5
|
-
params: Record<string, string>;
|
|
6
|
-
query: Record<string, string | string[]>;
|
|
7
|
-
body?: any;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class ObjectStackRuntimeProtocol {
|
|
11
|
-
private engine: ObjectStackKernel;
|
|
12
|
-
|
|
13
|
-
constructor(engine: ObjectStackKernel) {
|
|
14
|
-
this.engine = engine;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// 1. Discovery
|
|
18
|
-
getDiscovery() {
|
|
19
|
-
return {
|
|
20
|
-
name: 'ObjectOS Server',
|
|
21
|
-
version: '1.0.0',
|
|
22
|
-
environment: process.env.NODE_ENV || 'development',
|
|
23
|
-
routes: {
|
|
24
|
-
discovery: '/api/v1',
|
|
25
|
-
metadata: '/api/v1/meta',
|
|
26
|
-
data: '/api/v1/data',
|
|
27
|
-
auth: '/api/v1/auth',
|
|
28
|
-
ui: '/api/v1/ui'
|
|
29
|
-
},
|
|
30
|
-
capabilities: {
|
|
31
|
-
search: true,
|
|
32
|
-
files: true
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 2. Metadata: List Types
|
|
38
|
-
getMetaTypes() {
|
|
39
|
-
const types = SchemaRegistry.getRegisteredTypes();
|
|
40
|
-
return {
|
|
41
|
-
data: types.map(type => ({
|
|
42
|
-
type,
|
|
43
|
-
href: `/api/v1/meta/${type}s`,
|
|
44
|
-
count: SchemaRegistry.listItems(type).length
|
|
45
|
-
}))
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// 3. Metadata: List Items by Type
|
|
50
|
-
getMetaItems(typePlural: string) {
|
|
51
|
-
// Simple Singularization Mapping
|
|
52
|
-
const typeMap: Record<string, string> = {
|
|
53
|
-
'objects': 'object',
|
|
54
|
-
'apps': 'app',
|
|
55
|
-
'flows': 'flow',
|
|
56
|
-
'reports': 'report',
|
|
57
|
-
'plugins': 'plugin',
|
|
58
|
-
'kinds': 'kind'
|
|
59
|
-
};
|
|
60
|
-
const type = typeMap[typePlural] || typePlural;
|
|
61
|
-
const items = SchemaRegistry.listItems(type);
|
|
62
|
-
|
|
63
|
-
const summaries = items.map((item: any) => ({
|
|
64
|
-
id: item.id,
|
|
65
|
-
name: item.name,
|
|
66
|
-
label: item.label,
|
|
67
|
-
type: item.type,
|
|
68
|
-
icon: item.icon,
|
|
69
|
-
description: item.description,
|
|
70
|
-
...(type === 'object' ? { path: `/api/v1/data/${item.name}` } : {}),
|
|
71
|
-
self: `/api/v1/meta/${typePlural}/${item.name || item.id}`
|
|
72
|
-
}));
|
|
73
|
-
|
|
74
|
-
return { data: summaries };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// 4. Metadata: Get Single Item
|
|
78
|
-
getMetaItem(typePlural: string, name: string) {
|
|
79
|
-
const typeMap: Record<string, string> = {
|
|
80
|
-
'objects': 'object',
|
|
81
|
-
'apps': 'app',
|
|
82
|
-
'flows': 'flow',
|
|
83
|
-
'reports': 'report',
|
|
84
|
-
'plugins': 'plugin',
|
|
85
|
-
'kinds': 'kind'
|
|
86
|
-
};
|
|
87
|
-
const type = typeMap[typePlural] || typePlural;
|
|
88
|
-
const item = SchemaRegistry.getItem(type, name);
|
|
89
|
-
if (!item) throw new Error(`Metadata not found: ${type}/${name}`);
|
|
90
|
-
return item;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// 5. UI: View Definition
|
|
94
|
-
getUiView(objectName: string, type: 'list' | 'form') {
|
|
95
|
-
const view = this.engine.getView(objectName, type);
|
|
96
|
-
if (!view) throw new Error('View not generated');
|
|
97
|
-
return view;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// 6. Data: Find
|
|
101
|
-
async findData(objectName: string, query: any) {
|
|
102
|
-
return await this.engine.find(objectName, query);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// 7. Data: Query (Advanced AST)
|
|
106
|
-
async queryData(objectName: string, body: any) {
|
|
107
|
-
return await this.engine.find(objectName, body);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// 8. Data: Get
|
|
111
|
-
async getData(objectName: string, id: string) {
|
|
112
|
-
return await this.engine.get(objectName, id);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// 9. Data: Create
|
|
116
|
-
async createData(objectName: string, body: any) {
|
|
117
|
-
return await this.engine.create(objectName, body);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// 10. Data: Update
|
|
121
|
-
async updateData(objectName: string, id: string, body: any) {
|
|
122
|
-
return await this.engine.update(objectName, id, body);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// 11. Data: Delete
|
|
126
|
-
async deleteData(objectName: string, id: string) {
|
|
127
|
-
return await this.engine.delete(objectName, id);
|
|
128
|
-
}
|
|
129
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ObjectStackKernel } from './kernel';
|
|
2
|
-
|
|
3
|
-
export interface RuntimeContext {
|
|
4
|
-
engine: ObjectStackKernel;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface RuntimePlugin {
|
|
8
|
-
name: string;
|
|
9
|
-
install?: (ctx: RuntimeContext) => void | Promise<void>;
|
|
10
|
-
onStart?: (ctx: RuntimeContext) => void | Promise<void>;
|
|
11
|
-
}
|