@objectstack/runtime 1.0.6 → 1.0.8
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 +10 -10
- package/CHANGELOG.md +17 -0
- package/dist/index.cjs +50 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/app-plugin.ts +25 -0
- package/src/driver-plugin.ts +30 -0
- package/src/rest-server.ts +20 -0
package/src/app-plugin.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { Plugin, PluginContext } from '@objectstack/core';
|
|
|
11
11
|
*/
|
|
12
12
|
export class AppPlugin implements Plugin {
|
|
13
13
|
name: string;
|
|
14
|
+
type = 'app';
|
|
14
15
|
version?: string;
|
|
15
16
|
|
|
16
17
|
private bundle: any;
|
|
@@ -96,5 +97,29 @@ export class AppPlugin implements Plugin {
|
|
|
96
97
|
} else {
|
|
97
98
|
ctx.logger.debug('No runtime.onEnable function found', { appId });
|
|
98
99
|
}
|
|
100
|
+
|
|
101
|
+
// Data Seeding
|
|
102
|
+
// Check for 'data' in manifest (Legacy or Stack Definition)
|
|
103
|
+
const manifest = this.bundle.manifest || this.bundle;
|
|
104
|
+
if (manifest && Array.isArray(manifest.data)) {
|
|
105
|
+
ctx.logger.info(`[AppPlugin] Found initial data for ${appId}`, { count: manifest.data.length });
|
|
106
|
+
for (const dataset of manifest.data) {
|
|
107
|
+
if (dataset.object && Array.isArray(dataset.records)) {
|
|
108
|
+
ctx.logger.info(`[Seeder] Seeding ${dataset.records.length} records for ${dataset.object}`);
|
|
109
|
+
for (const record of dataset.records) {
|
|
110
|
+
try {
|
|
111
|
+
// Use ObjectQL engine to insert data
|
|
112
|
+
// This ensures driver resolution and hook execution
|
|
113
|
+
// Use 'insert' which corresponds to 'create' in driver
|
|
114
|
+
await ql.insert(dataset.object, record);
|
|
115
|
+
} catch (err: any) {
|
|
116
|
+
// Ignore duplicate errors if needed, or log/warn
|
|
117
|
+
ctx.logger.warn(`[Seeder] Failed to insert ${dataset.object} record:`, { error: err.message });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
ctx.logger.info('[Seeder] Data seeding complete.');
|
|
123
|
+
}
|
|
99
124
|
}
|
|
100
125
|
}
|
package/src/driver-plugin.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { Plugin, PluginContext } from '@objectstack/core';
|
|
|
16
16
|
*/
|
|
17
17
|
export class DriverPlugin implements Plugin {
|
|
18
18
|
name: string;
|
|
19
|
+
type = 'driver';
|
|
19
20
|
version = '1.0.0';
|
|
20
21
|
// dependencies = ['com.objectstack.engine.objectql']; // Removed: Driver is a producer, not strictly a consumer during init
|
|
21
22
|
|
|
@@ -39,6 +40,35 @@ export class DriverPlugin implements Plugin {
|
|
|
39
40
|
|
|
40
41
|
start = async (ctx: PluginContext) => {
|
|
41
42
|
// Drivers don't need start phase, initialization happens in init
|
|
43
|
+
// Auto-configure alias for shorter access if it follows reverse domain standard
|
|
44
|
+
if (this.name.startsWith('com.objectstack.driver.')) {
|
|
45
|
+
// const shortName = this.name.split('.').pop();
|
|
46
|
+
// Optional: ctx.registerService(`driver.${shortName}`, this.driver);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Auto-configure 'default' datasource if none exists
|
|
50
|
+
// We do this in 'start' phase to ensure metadata service is likely available
|
|
51
|
+
try {
|
|
52
|
+
const metadata = ctx.getService<any>('metadata');
|
|
53
|
+
if (metadata && metadata.addDatasource) {
|
|
54
|
+
// Check if default datasource exists
|
|
55
|
+
const datasources = metadata.getDatasources ? metadata.getDatasources() : [];
|
|
56
|
+
const hasDefault = datasources.some((ds: any) => ds.name === 'default');
|
|
57
|
+
|
|
58
|
+
if (!hasDefault) {
|
|
59
|
+
ctx.logger.info(`[DriverPlugin] No 'default' datasource found. Auto-configuring '${this.driver.name}' as default.`);
|
|
60
|
+
await metadata.addDatasource({
|
|
61
|
+
name: 'default',
|
|
62
|
+
driver: this.driver.name, // The driver's internal name (e.g. com.objectstack.driver.memory)
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} catch (e) {
|
|
67
|
+
// Metadata service might not be ready or available, which is fine
|
|
68
|
+
// We just skip auto-configuration
|
|
69
|
+
ctx.logger.debug('[DriverPlugin] Failed to auto-configure default datasource (Metadata service missing?)', { error: e });
|
|
70
|
+
}
|
|
71
|
+
|
|
42
72
|
ctx.logger.debug('Driver plugin started', { driverName: this.driver.name || 'unknown' });
|
|
43
73
|
}
|
|
44
74
|
}
|
package/src/rest-server.ts
CHANGED
|
@@ -213,6 +213,26 @@ export class RestServer {
|
|
|
213
213
|
handler: async (_req: any, res: any) => {
|
|
214
214
|
try {
|
|
215
215
|
const discovery = await this.protocol.getDiscovery({});
|
|
216
|
+
|
|
217
|
+
// Override discovery information with actual server configuration
|
|
218
|
+
discovery.version = this.config.api.version;
|
|
219
|
+
|
|
220
|
+
if (discovery.endpoints) {
|
|
221
|
+
// Ensure endpoints match the actual mounted paths
|
|
222
|
+
if (this.config.api.enableCrud) {
|
|
223
|
+
discovery.endpoints.data = `${basePath}${this.config.crud.dataPrefix}`;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (this.config.api.enableMetadata) {
|
|
227
|
+
discovery.endpoints.metadata = `${basePath}${this.config.metadata.prefix}`;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Align auth endpoint with the versioned base path if present
|
|
231
|
+
if (discovery.endpoints.auth) {
|
|
232
|
+
discovery.endpoints.auth = `${basePath}/auth`;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
216
236
|
res.json(discovery);
|
|
217
237
|
} catch (error: any) {
|
|
218
238
|
res.status(500).json({ error: error.message });
|