@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/dist/index.d.ts
CHANGED
|
@@ -81,6 +81,7 @@ declare class Runtime {
|
|
|
81
81
|
*/
|
|
82
82
|
declare class DriverPlugin implements Plugin {
|
|
83
83
|
name: string;
|
|
84
|
+
type: string;
|
|
84
85
|
version: string;
|
|
85
86
|
private driver;
|
|
86
87
|
constructor(driver: any, driverName?: string);
|
|
@@ -99,6 +100,7 @@ declare class DriverPlugin implements Plugin {
|
|
|
99
100
|
*/
|
|
100
101
|
declare class AppPlugin implements Plugin {
|
|
101
102
|
name: string;
|
|
103
|
+
type: string;
|
|
102
104
|
version?: string;
|
|
103
105
|
private bundle;
|
|
104
106
|
constructor(bundle: any);
|
package/dist/index.js
CHANGED
|
@@ -319,6 +319,18 @@ var RestServer = class {
|
|
|
319
319
|
handler: async (_req, res) => {
|
|
320
320
|
try {
|
|
321
321
|
const discovery = await this.protocol.getDiscovery({});
|
|
322
|
+
discovery.version = this.config.api.version;
|
|
323
|
+
if (discovery.endpoints) {
|
|
324
|
+
if (this.config.api.enableCrud) {
|
|
325
|
+
discovery.endpoints.data = `${basePath}${this.config.crud.dataPrefix}`;
|
|
326
|
+
}
|
|
327
|
+
if (this.config.api.enableMetadata) {
|
|
328
|
+
discovery.endpoints.metadata = `${basePath}${this.config.metadata.prefix}`;
|
|
329
|
+
}
|
|
330
|
+
if (discovery.endpoints.auth) {
|
|
331
|
+
discovery.endpoints.auth = `${basePath}/auth`;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
322
334
|
res.json(discovery);
|
|
323
335
|
} catch (error) {
|
|
324
336
|
res.status(500).json({ error: error.message });
|
|
@@ -741,6 +753,7 @@ var Runtime = class {
|
|
|
741
753
|
// src/driver-plugin.ts
|
|
742
754
|
var DriverPlugin = class {
|
|
743
755
|
constructor(driver, driverName) {
|
|
756
|
+
this.type = "driver";
|
|
744
757
|
this.version = "1.0.0";
|
|
745
758
|
this.init = async (ctx) => {
|
|
746
759
|
const serviceName = `driver.${this.driver.name || "unknown"}`;
|
|
@@ -752,6 +765,25 @@ var DriverPlugin = class {
|
|
|
752
765
|
});
|
|
753
766
|
};
|
|
754
767
|
this.start = async (ctx) => {
|
|
768
|
+
if (this.name.startsWith("com.objectstack.driver.")) {
|
|
769
|
+
}
|
|
770
|
+
try {
|
|
771
|
+
const metadata = ctx.getService("metadata");
|
|
772
|
+
if (metadata && metadata.addDatasource) {
|
|
773
|
+
const datasources = metadata.getDatasources ? metadata.getDatasources() : [];
|
|
774
|
+
const hasDefault = datasources.some((ds) => ds.name === "default");
|
|
775
|
+
if (!hasDefault) {
|
|
776
|
+
ctx.logger.info(`[DriverPlugin] No 'default' datasource found. Auto-configuring '${this.driver.name}' as default.`);
|
|
777
|
+
await metadata.addDatasource({
|
|
778
|
+
name: "default",
|
|
779
|
+
driver: this.driver.name
|
|
780
|
+
// The driver's internal name (e.g. com.objectstack.driver.memory)
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
} catch (e) {
|
|
785
|
+
ctx.logger.debug("[DriverPlugin] Failed to auto-configure default datasource (Metadata service missing?)", { error: e });
|
|
786
|
+
}
|
|
755
787
|
ctx.logger.debug("Driver plugin started", { driverName: this.driver.name || "unknown" });
|
|
756
788
|
};
|
|
757
789
|
this.driver = driver;
|
|
@@ -762,6 +794,7 @@ var DriverPlugin = class {
|
|
|
762
794
|
// src/app-plugin.ts
|
|
763
795
|
var AppPlugin = class {
|
|
764
796
|
constructor(bundle) {
|
|
797
|
+
this.type = "app";
|
|
765
798
|
this.init = async (ctx) => {
|
|
766
799
|
const sys = this.bundle.manifest || this.bundle;
|
|
767
800
|
const appId = sys.id || sys.name;
|
|
@@ -811,6 +844,23 @@ var AppPlugin = class {
|
|
|
811
844
|
} else {
|
|
812
845
|
ctx.logger.debug("No runtime.onEnable function found", { appId });
|
|
813
846
|
}
|
|
847
|
+
const manifest = this.bundle.manifest || this.bundle;
|
|
848
|
+
if (manifest && Array.isArray(manifest.data)) {
|
|
849
|
+
ctx.logger.info(`[AppPlugin] Found initial data for ${appId}`, { count: manifest.data.length });
|
|
850
|
+
for (const dataset of manifest.data) {
|
|
851
|
+
if (dataset.object && Array.isArray(dataset.records)) {
|
|
852
|
+
ctx.logger.info(`[Seeder] Seeding ${dataset.records.length} records for ${dataset.object}`);
|
|
853
|
+
for (const record of dataset.records) {
|
|
854
|
+
try {
|
|
855
|
+
await ql.insert(dataset.object, record);
|
|
856
|
+
} catch (err) {
|
|
857
|
+
ctx.logger.warn(`[Seeder] Failed to insert ${dataset.object} record:`, { error: err.message });
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
ctx.logger.info("[Seeder] Data seeding complete.");
|
|
863
|
+
}
|
|
814
864
|
};
|
|
815
865
|
this.bundle = bundle;
|
|
816
866
|
const sys = bundle.manifest || bundle;
|