@moku-labs/core 0.1.0-alpha.6 → 0.1.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/README.md +1 -1
- package/dist/index.cjs +48 -9
- package/dist/index.mjs +47 -7
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -308,7 +308,7 @@ The full specification lives in [`specification/`](specification/):
|
|
|
308
308
|
|
|
309
309
|
## Status
|
|
310
310
|
|
|
311
|
-
|
|
311
|
+
Early release (`0.1.x`). The public API — `createCoreConfig` → `createCore` → `createApp` — is stable; pre-1.0 means internals may still be refined. Published to npm: `bun add @moku-labs/core`.
|
|
312
312
|
|
|
313
313
|
## License
|
|
314
314
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value:
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
2
|
//#region src/utilities.ts
|
|
4
3
|
/**
|
|
5
4
|
* Checks whether a value is a non-null, non-array object record.
|
|
@@ -141,7 +140,6 @@ function validateCorePlugins(id, corePlugins) {
|
|
|
141
140
|
function checkCorePluginConflicts(id, plugins, corePluginNames) {
|
|
142
141
|
for (const plugin of plugins) if (corePluginNames.has(plugin.name)) throw new TypeError(`[${id}] Plugin name "${plugin.name}" conflicts with core plugin "${plugin.name}".\n Choose a different plugin name.`);
|
|
143
142
|
}
|
|
144
|
-
|
|
145
143
|
//#endregion
|
|
146
144
|
//#region src/app.ts
|
|
147
145
|
/**
|
|
@@ -416,6 +414,14 @@ function buildApp(runtime, flatPlugins, buildPluginContext, corePluginData, cons
|
|
|
416
414
|
const appRequire = createRequire(runtime, (name) => `[${runtime.id}] app.require("${name}") failed: "${name}" is not registered.\n Check your plugin list.`);
|
|
417
415
|
const appHas = createHas(runtime);
|
|
418
416
|
const app = {
|
|
417
|
+
/**
|
|
418
|
+
* Run onStart for all plugins, then consumer onStart.
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```ts
|
|
422
|
+
* await app.start();
|
|
423
|
+
* ```
|
|
424
|
+
*/
|
|
419
425
|
start: async () => {
|
|
420
426
|
if (started) throw new Error(`[${runtime.id}] App already started.\n start() can only be called once.`);
|
|
421
427
|
for (const plugin of corePluginData.plugins) if (plugin.spec.onStart) await plugin.spec.onStart({
|
|
@@ -426,6 +432,14 @@ function buildApp(runtime, flatPlugins, buildPluginContext, corePluginData, cons
|
|
|
426
432
|
if (consumer?.onStart) await consumer.onStart(buildCallbackContext(runtime));
|
|
427
433
|
started = true;
|
|
428
434
|
},
|
|
435
|
+
/**
|
|
436
|
+
* Run onStop for all plugins in reverse, then consumer onStop.
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* ```ts
|
|
440
|
+
* await app.stop();
|
|
441
|
+
* ```
|
|
442
|
+
*/
|
|
429
443
|
stop: async () => {
|
|
430
444
|
if (!started) throw new Error(`[${runtime.id}] App not started.\n Call start() before stop().`);
|
|
431
445
|
await executeStop(flatPlugins, runtime.globalConfig);
|
|
@@ -435,10 +449,40 @@ function buildApp(runtime, flatPlugins, buildPluginContext, corePluginData, cons
|
|
|
435
449
|
});
|
|
436
450
|
if (consumer?.onStop) await consumer.onStop(buildCallbackContext(runtime));
|
|
437
451
|
},
|
|
452
|
+
/**
|
|
453
|
+
* Emit an event with an optional payload.
|
|
454
|
+
*
|
|
455
|
+
* @param eventName - The event name to emit.
|
|
456
|
+
* @param payload - The optional event payload.
|
|
457
|
+
* @example
|
|
458
|
+
* ```ts
|
|
459
|
+
* app.emit("page:view", { path: "/" });
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
438
462
|
emit: (eventName, payload) => {
|
|
439
463
|
runtime.emit(eventName, payload);
|
|
440
464
|
},
|
|
465
|
+
/**
|
|
466
|
+
* Look up a plugin API by instance reference.
|
|
467
|
+
*
|
|
468
|
+
* @param instance - The plugin instance to look up.
|
|
469
|
+
* @returns The plugin's API object.
|
|
470
|
+
* @example
|
|
471
|
+
* ```ts
|
|
472
|
+
* const routerApi = app.require(routerPlugin);
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
441
475
|
require: (instance) => appRequire(instance),
|
|
476
|
+
/**
|
|
477
|
+
* Check if a plugin name is registered.
|
|
478
|
+
*
|
|
479
|
+
* @param name - The plugin name to check.
|
|
480
|
+
* @returns True if the plugin is registered.
|
|
481
|
+
* @example
|
|
482
|
+
* ```ts
|
|
483
|
+
* app.has("router"); // => true or false
|
|
484
|
+
* ```
|
|
485
|
+
*/
|
|
442
486
|
has: (name) => appHas(name)
|
|
443
487
|
};
|
|
444
488
|
for (const [name, api] of runtime.apis) app[name] = api;
|
|
@@ -544,7 +588,6 @@ function kernel(parameters) {
|
|
|
544
588
|
states: coreStates
|
|
545
589
|
}, consumer);
|
|
546
590
|
}
|
|
547
|
-
|
|
548
591
|
//#endregion
|
|
549
592
|
//#region src/core.ts
|
|
550
593
|
/**
|
|
@@ -628,7 +671,6 @@ function createCoreFactory(frameworkId, configDefaults, createPlugin, corePlugin
|
|
|
628
671
|
};
|
|
629
672
|
return createCore;
|
|
630
673
|
}
|
|
631
|
-
|
|
632
674
|
//#endregion
|
|
633
675
|
//#region src/plugin.ts
|
|
634
676
|
/**
|
|
@@ -816,7 +858,6 @@ function createPluginFactory(frameworkId) {
|
|
|
816
858
|
};
|
|
817
859
|
return createPlugin;
|
|
818
860
|
}
|
|
819
|
-
|
|
820
861
|
//#endregion
|
|
821
862
|
//#region src/config.ts
|
|
822
863
|
/**
|
|
@@ -852,7 +893,6 @@ function createCoreConfig(id, options) {
|
|
|
852
893
|
createCore: createCoreFactory(frameworkId, configDefaults, createPlugin, corePlugins, corePluginConfigs)
|
|
853
894
|
};
|
|
854
895
|
}
|
|
855
|
-
|
|
856
896
|
//#endregion
|
|
857
897
|
//#region src/core-plugin.ts
|
|
858
898
|
/**
|
|
@@ -973,7 +1013,6 @@ function createCorePlugin(name, spec) {
|
|
|
973
1013
|
_phantom: {}
|
|
974
1014
|
};
|
|
975
1015
|
}
|
|
976
|
-
|
|
977
1016
|
//#endregion
|
|
978
1017
|
exports.createCoreConfig = createCoreConfig;
|
|
979
|
-
exports.createCorePlugin = createCorePlugin;
|
|
1018
|
+
exports.createCorePlugin = createCorePlugin;
|
package/dist/index.mjs
CHANGED
|
@@ -139,7 +139,6 @@ function validateCorePlugins(id, corePlugins) {
|
|
|
139
139
|
function checkCorePluginConflicts(id, plugins, corePluginNames) {
|
|
140
140
|
for (const plugin of plugins) if (corePluginNames.has(plugin.name)) throw new TypeError(`[${id}] Plugin name "${plugin.name}" conflicts with core plugin "${plugin.name}".\n Choose a different plugin name.`);
|
|
141
141
|
}
|
|
142
|
-
|
|
143
142
|
//#endregion
|
|
144
143
|
//#region src/app.ts
|
|
145
144
|
/**
|
|
@@ -414,6 +413,14 @@ function buildApp(runtime, flatPlugins, buildPluginContext, corePluginData, cons
|
|
|
414
413
|
const appRequire = createRequire(runtime, (name) => `[${runtime.id}] app.require("${name}") failed: "${name}" is not registered.\n Check your plugin list.`);
|
|
415
414
|
const appHas = createHas(runtime);
|
|
416
415
|
const app = {
|
|
416
|
+
/**
|
|
417
|
+
* Run onStart for all plugins, then consumer onStart.
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* ```ts
|
|
421
|
+
* await app.start();
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
417
424
|
start: async () => {
|
|
418
425
|
if (started) throw new Error(`[${runtime.id}] App already started.\n start() can only be called once.`);
|
|
419
426
|
for (const plugin of corePluginData.plugins) if (plugin.spec.onStart) await plugin.spec.onStart({
|
|
@@ -424,6 +431,14 @@ function buildApp(runtime, flatPlugins, buildPluginContext, corePluginData, cons
|
|
|
424
431
|
if (consumer?.onStart) await consumer.onStart(buildCallbackContext(runtime));
|
|
425
432
|
started = true;
|
|
426
433
|
},
|
|
434
|
+
/**
|
|
435
|
+
* Run onStop for all plugins in reverse, then consumer onStop.
|
|
436
|
+
*
|
|
437
|
+
* @example
|
|
438
|
+
* ```ts
|
|
439
|
+
* await app.stop();
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
427
442
|
stop: async () => {
|
|
428
443
|
if (!started) throw new Error(`[${runtime.id}] App not started.\n Call start() before stop().`);
|
|
429
444
|
await executeStop(flatPlugins, runtime.globalConfig);
|
|
@@ -433,10 +448,40 @@ function buildApp(runtime, flatPlugins, buildPluginContext, corePluginData, cons
|
|
|
433
448
|
});
|
|
434
449
|
if (consumer?.onStop) await consumer.onStop(buildCallbackContext(runtime));
|
|
435
450
|
},
|
|
451
|
+
/**
|
|
452
|
+
* Emit an event with an optional payload.
|
|
453
|
+
*
|
|
454
|
+
* @param eventName - The event name to emit.
|
|
455
|
+
* @param payload - The optional event payload.
|
|
456
|
+
* @example
|
|
457
|
+
* ```ts
|
|
458
|
+
* app.emit("page:view", { path: "/" });
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
436
461
|
emit: (eventName, payload) => {
|
|
437
462
|
runtime.emit(eventName, payload);
|
|
438
463
|
},
|
|
464
|
+
/**
|
|
465
|
+
* Look up a plugin API by instance reference.
|
|
466
|
+
*
|
|
467
|
+
* @param instance - The plugin instance to look up.
|
|
468
|
+
* @returns The plugin's API object.
|
|
469
|
+
* @example
|
|
470
|
+
* ```ts
|
|
471
|
+
* const routerApi = app.require(routerPlugin);
|
|
472
|
+
* ```
|
|
473
|
+
*/
|
|
439
474
|
require: (instance) => appRequire(instance),
|
|
475
|
+
/**
|
|
476
|
+
* Check if a plugin name is registered.
|
|
477
|
+
*
|
|
478
|
+
* @param name - The plugin name to check.
|
|
479
|
+
* @returns True if the plugin is registered.
|
|
480
|
+
* @example
|
|
481
|
+
* ```ts
|
|
482
|
+
* app.has("router"); // => true or false
|
|
483
|
+
* ```
|
|
484
|
+
*/
|
|
440
485
|
has: (name) => appHas(name)
|
|
441
486
|
};
|
|
442
487
|
for (const [name, api] of runtime.apis) app[name] = api;
|
|
@@ -542,7 +587,6 @@ function kernel(parameters) {
|
|
|
542
587
|
states: coreStates
|
|
543
588
|
}, consumer);
|
|
544
589
|
}
|
|
545
|
-
|
|
546
590
|
//#endregion
|
|
547
591
|
//#region src/core.ts
|
|
548
592
|
/**
|
|
@@ -626,7 +670,6 @@ function createCoreFactory(frameworkId, configDefaults, createPlugin, corePlugin
|
|
|
626
670
|
};
|
|
627
671
|
return createCore;
|
|
628
672
|
}
|
|
629
|
-
|
|
630
673
|
//#endregion
|
|
631
674
|
//#region src/plugin.ts
|
|
632
675
|
/**
|
|
@@ -814,7 +857,6 @@ function createPluginFactory(frameworkId) {
|
|
|
814
857
|
};
|
|
815
858
|
return createPlugin;
|
|
816
859
|
}
|
|
817
|
-
|
|
818
860
|
//#endregion
|
|
819
861
|
//#region src/config.ts
|
|
820
862
|
/**
|
|
@@ -850,7 +892,6 @@ function createCoreConfig(id, options) {
|
|
|
850
892
|
createCore: createCoreFactory(frameworkId, configDefaults, createPlugin, corePlugins, corePluginConfigs)
|
|
851
893
|
};
|
|
852
894
|
}
|
|
853
|
-
|
|
854
895
|
//#endregion
|
|
855
896
|
//#region src/core-plugin.ts
|
|
856
897
|
/**
|
|
@@ -971,6 +1012,5 @@ function createCorePlugin(name, spec) {
|
|
|
971
1012
|
_phantom: {}
|
|
972
1013
|
};
|
|
973
1014
|
}
|
|
974
|
-
|
|
975
1015
|
//#endregion
|
|
976
|
-
export { createCoreConfig, createCorePlugin };
|
|
1016
|
+
export { createCoreConfig, createCorePlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moku-labs/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"author": "Alex Kucherenko",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"jiti": "2.6.1",
|
|
24
24
|
"lefthook": "2.1.1",
|
|
25
25
|
"publint": "0.3.17",
|
|
26
|
-
"tsdown": "0.
|
|
27
|
-
"typescript": "
|
|
28
|
-
"typescript-eslint": "8.
|
|
26
|
+
"tsdown": "0.22.1",
|
|
27
|
+
"typescript": "6.0.3",
|
|
28
|
+
"typescript-eslint": "8.58.0",
|
|
29
29
|
"vitest": "4.0.18"
|
|
30
30
|
},
|
|
31
31
|
"exports": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
+
"sideEffects": false,
|
|
43
44
|
"bugs": {
|
|
44
45
|
"url": "https://github.com/moku-labs/core/issues"
|
|
45
46
|
},
|