@objectstack/runtime 1.0.7 → 1.0.9
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 +8 -8
- package/CHANGELOG.md +16 -0
- package/dist/index.cjs +36 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/app-plugin.ts +24 -0
- package/src/driver-plugin.ts +29 -0
package/src/app-plugin.ts
CHANGED
|
@@ -97,5 +97,29 @@ export class AppPlugin implements Plugin {
|
|
|
97
97
|
} else {
|
|
98
98
|
ctx.logger.debug('No runtime.onEnable function found', { appId });
|
|
99
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
|
+
}
|
|
100
124
|
}
|
|
101
125
|
}
|
package/src/driver-plugin.ts
CHANGED
|
@@ -40,6 +40,35 @@ export class DriverPlugin implements Plugin {
|
|
|
40
40
|
|
|
41
41
|
start = async (ctx: PluginContext) => {
|
|
42
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
|
+
|
|
43
72
|
ctx.logger.debug('Driver plugin started', { driverName: this.driver.name || 'unknown' });
|
|
44
73
|
}
|
|
45
74
|
}
|