skeleton-crew-runtime 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/dist/types.js ADDED
@@ -0,0 +1,93 @@
1
+ // Core type definitions will be implemented in task 2
2
+ // Error Classes
3
+ /**
4
+ * Error thrown when validation fails for a resource
5
+ * @see Requirements 14.1, 14.2, 14.3, 14.4, 14.5, 14.6
6
+ */
7
+ export class ValidationError extends Error {
8
+ resourceType;
9
+ field;
10
+ resourceId;
11
+ constructor(resourceType, field, resourceId) {
12
+ super(`Validation failed for ${resourceType}${resourceId ? ` "${resourceId}"` : ''}: missing or invalid field "${field}"`);
13
+ this.resourceType = resourceType;
14
+ this.field = field;
15
+ this.resourceId = resourceId;
16
+ this.name = 'ValidationError';
17
+ }
18
+ }
19
+ /**
20
+ * Error thrown when attempting to register a duplicate resource
21
+ * @see Requirements 15.1, 15.2, 15.3, 15.4, 15.5
22
+ */
23
+ export class DuplicateRegistrationError extends Error {
24
+ resourceType;
25
+ identifier;
26
+ constructor(resourceType, identifier) {
27
+ super(`${resourceType} with identifier "${identifier}" is already registered`);
28
+ this.resourceType = resourceType;
29
+ this.identifier = identifier;
30
+ this.name = 'DuplicateRegistrationError';
31
+ }
32
+ }
33
+ /**
34
+ * Error thrown when an action execution exceeds its timeout
35
+ * @see Requirements 11.1, 11.2, 11.3, 11.4, 11.5
36
+ */
37
+ export class ActionTimeoutError extends Error {
38
+ actionId;
39
+ timeoutMs;
40
+ constructor(actionId, timeoutMs) {
41
+ super(`Action "${actionId}" timed out after ${timeoutMs}ms`);
42
+ this.actionId = actionId;
43
+ this.timeoutMs = timeoutMs;
44
+ this.name = 'ActionTimeoutError';
45
+ }
46
+ }
47
+ /**
48
+ * Error thrown when an action handler throws an error
49
+ * @see Requirements 3.1, 3.2, 3.3, 3.4, 3.5
50
+ */
51
+ export class ActionExecutionError extends Error {
52
+ actionId;
53
+ cause;
54
+ constructor(actionId, cause) {
55
+ super(`Action "${actionId}" execution failed: ${cause.message}`);
56
+ this.actionId = actionId;
57
+ this.cause = cause;
58
+ this.name = 'ActionExecutionError';
59
+ this.cause = cause;
60
+ }
61
+ }
62
+ /**
63
+ * Default console-based logger implementation
64
+ * @see Requirements 7.1, 7.2, 7.3, 7.4, 7.5, 7.6
65
+ */
66
+ export class ConsoleLogger {
67
+ debug(message, ...args) {
68
+ console.debug(message, ...args);
69
+ }
70
+ info(message, ...args) {
71
+ console.info(message, ...args);
72
+ }
73
+ warn(message, ...args) {
74
+ console.warn(message, ...args);
75
+ }
76
+ error(message, ...args) {
77
+ console.error(message, ...args);
78
+ }
79
+ }
80
+ // Runtime State Enum
81
+ /**
82
+ * Runtime lifecycle states
83
+ * @see Requirements 16.1, 16.2, 16.3, 16.4, 16.5
84
+ */
85
+ export var RuntimeState;
86
+ (function (RuntimeState) {
87
+ RuntimeState["Uninitialized"] = "uninitialized";
88
+ RuntimeState["Initializing"] = "initializing";
89
+ RuntimeState["Initialized"] = "initialized";
90
+ RuntimeState["ShuttingDown"] = "shutting_down";
91
+ RuntimeState["Shutdown"] = "shutdown";
92
+ })(RuntimeState || (RuntimeState = {}));
93
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,sDAAsD;AAEtD,gBAAgB;AAEhB;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAE/B;IACA;IACA;IAHT,YACS,YAAoB,EACpB,KAAa,EACb,UAAmB;QAE1B,KAAK,CACH,yBAAyB,YAAY,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,GAAG,CAAC,CAAC,CAAC,EAAE,+BAA+B,KAAK,GAAG,CACpH,CAAC;QANK,iBAAY,GAAZ,YAAY,CAAQ;QACpB,UAAK,GAAL,KAAK,CAAQ;QACb,eAAU,GAAV,UAAU,CAAS;QAK1B,IAAI,CAAC,IAAI,GAAG,iBAAiB,C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,OAAe,EAAE,GAAG,IAAe;QACtC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACjC,CAAC;IACD,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;QACvC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AAED,qBAAqB;AAErB;;;GAGG;AACH,MAAM,CAAN,IAAY,YAMX;AAND,WAAY,YAAY;IACtB,+CAA+B,CAAA;IAC/B,6CAA6B,CAAA;IAC7B,2CAA2B,CAAA;IAC3B,8CAA8B,CAAA;IAC9B,qCAAqB,CAAA;AACvB,CAAC,EANW,YAAY,KAAZ,YAAY,QAMvB"}
@@ -0,0 +1,39 @@
1
+ import { UIProvider, ScreenDefinition, Logger } from './types.js';
2
+ /**
3
+ * UIBridge manages optional UI provider registration and screen rendering.
4
+ * Validates provider implements required methods and rejects duplicate registration.
5
+ * @see Requirements 9.1, 9.2, 9.3, 9.4, 9.5, 14.1, 14.2, 14.3, 14.4, 14.5, 14.6, 15.1, 15.2, 15.3, 15.4, 15.5
6
+ */
7
+ export declare class UIBridge {
8
+ private provider;
9
+ private logger;
10
+ constructor(logger: Logger);
11
+ /**
12
+ * Register a UI provider with the runtime.
13
+ * @throws ValidationError if provider is missing required methods
14
+ * @throws DuplicateRegistrationError if provider is already registered
15
+ * @see Requirements 9.1, 9.2, 9.4, 14.1, 14.2, 14.3, 14.4, 14.5, 14.6, 15.1, 15.2, 15.3, 15.4, 15.5
16
+ */
17
+ setProvider(provider: UIProvider): void;
18
+ /**
19
+ * Get the registered UI provider.
20
+ * @returns The registered UIProvider or null if none registered
21
+ */
22
+ getProvider(): UIProvider | null;
23
+ /**
24
+ * Render a screen using the registered UI provider.
25
+ * @throws Error if no UI provider is registered
26
+ * @see Requirements 9.2
27
+ */
28
+ renderScreen(screen: ScreenDefinition): unknown;
29
+ /**
30
+ * Shutdown the UI provider by calling unmount if it exists.
31
+ * @see Requirements 9.5
32
+ */
33
+ shutdown(): Promise<void>;
34
+ /**
35
+ * Clear the UI provider during shutdown.
36
+ */
37
+ clear(): void;
38
+ }
39
+ //# sourceMappingURL=ui-bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui-bridge.d.ts","sourceRoot":"","sources":["../src/ui-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,EAA+C,MAAM,YAAY,CAAC;AAE/G;;;;GAIG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,MAAM;IAI1B;;;;;OAKG;IACH,WAAW,CAAC,QAAQ,EAAE,UAAU,GAAG,IAAI;IAkBvC;;;OAGG;IACH,WAAW,IAAI,UAAU,GAAG,IAAI;IAIhC;;;;OAIG;IACH,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO;IAQ/C;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAY/B;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd"}
@@ -0,0 +1,74 @@
1
+ import { ValidationError, DuplicateRegistrationError } from './types.js';
2
+ /**
3
+ * UIBridge manages optional UI provider registration and screen rendering.
4
+ * Validates provider implements required methods and rejects duplicate registration.
5
+ * @see Requirements 9.1, 9.2, 9.3, 9.4, 9.5, 14.1, 14.2, 14.3, 14.4, 14.5, 14.6, 15.1, 15.2, 15.3, 15.4, 15.5
6
+ */
7
+ export class UIBridge {
8
+ provider = null;
9
+ logger;
10
+ constructor(logger) {
11
+ this.logger = logger;
12
+ }
13
+ /**
14
+ * Register a UI provider with the runtime.
15
+ * @throws ValidationError if provider is missing required methods
16
+ * @throws DuplicateRegistrationError if provider is already registered
17
+ * @see Requirements 9.1, 9.2, 9.4, 14.1, 14.2, 14.3, 14.4, 14.5, 14.6, 15.1, 15.2, 15.3, 15.4, 15.5
18
+ */
19
+ setProvider(provider) {
20
+ // Reject duplicate provider registration
21
+ if (this.provider !== null) {
22
+ throw new DuplicateRegistrationError('UIProvider', 'default');
23
+ }
24
+ // Validate provider has required methods
25
+ if (typeof provider.mount !== 'function') {
26
+ throw new ValidationError('UIProvider', 'mount');
27
+ }
28
+ if (typeof provider.renderScreen !== 'function') {
29
+ throw new ValidationError('UIProvider', 'renderScreen');
30
+ }
31
+ this.provider = provider;
32
+ }
33
+ /**
34
+ * Get the registered UI provider.
35
+ * @returns The registered UIProvider or null if none registered
36
+ */
37
+ getProvider() {
38
+ return this.provider;
39
+ }
40
+ /**
41
+ * Render a screen using the registered UI provider.
42
+ * @throws Error if no UI provider is registered
43
+ * @see Requirements 9.2
44
+ */
45
+ renderScreen(screen) {
46
+ if (this.provider === null) {
47
+ throw new Error('No UI provider registered');
48
+ }
49
+ return this.provider.renderScreen(screen);
50
+ }
51
+ /**
52
+ * Shutdown the UI provider by calling unmount if it exists.
53
+ * @see Requirements 9.5
54
+ */
55
+ async shutdown() {
56
+ if (this.provider?.unmount) {
57
+ try {
58
+ await Promise.resolve(this.provider.unmount());
59
+ this.logger.debug('UI provider unmounted');
60
+ }
61
+ catch (error) {
62
+ this.logger.error('UI provider unmount failed', error);
63
+ }
64
+ }
65
+ this.provider = null;
66
+ }
67
+ /**
68
+ * Clear the UI provider during shutdown.
69
+ */
70
+ clear() {
71
+ this.provider = null;
72
+ }
73
+ }
74
+ //# sourceMappingURL=ui-bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui-bridge.js","sourceRoot":"","sources":["../src/ui-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,eAAe,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAE/G;;;;GAIG;AACH,MAAM,OAAO,QAAQ;IACX,QAAQ,GAAsB,IAAI,CAAC;IACnC,MAAM,CAAS;IAEvB,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB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;QACH,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "skeleton-crew-runtime",
3
+ "version": "0.1.1",
4
+ "description": "A minimal, plugin-based application runtime for building internal tools and modular applications",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist/",
10
+ "LICENSE",
11
+ "README.md",
12
+ "package.json"
13
+ ],
14
+ "exclude": [
15
+ "dist-example/"
16
+ ],
17
+ "scripts": {
18
+ "build": "rm -rf dist 2>&1 & tsc",
19
+ "build:examples": "tsc -p tsconfig.examples.json",
20
+ "test": "vitest run",
21
+ "test:watch": "vitest",
22
+ "example": "npm run build:examples && node dist-example/example/index.js",
23
+ "example:01": "npm run build:examples && node dist-example/example/01-plugin-system/index.js",
24
+ "example:02": "npm run build:examples && node dist-example/example/02-screen-registry/index.js",
25
+ "example:03": "npm run build:examples && node dist-example/example/03-action-engine/index.js",
26
+ "example:04": "npm run build:examples && node dist-example/example/04-event-bus/index.js",
27
+ "example:05": "npm run build:examples && node dist-example/example/05-runtime-context/index.js",
28
+ "tutorial:01": "npm run build:examples && node dist-example/example/tutorial/01-basic-task-plugin/index.js",
29
+ "tutorial:02": "npm run build:examples && node dist-example/example/tutorial/02-multiple-plugins/index.js",
30
+ "tutorial:03": "npm run build:examples && node dist-example/example/tutorial/03-event-communication/index.js",
31
+ "tutorial:04": "npm run build:examples && vite dist-example/example/tutorial/04-ui-provider-swap",
32
+ "tutorial:05": "npm run build:examples && node dist-example/example/tutorial/05-custom-plugin/index.js"
33
+ },
34
+ "keywords": [
35
+ "runtime",
36
+ "plugin",
37
+ "framework",
38
+ "internal-tools",
39
+ "modular",
40
+ "ui-agnostic"
41
+ ],
42
+ "author": "skcrew",
43
+ "email": "skeleton-crew-runtime@gmail.com",
44
+ "license": "MIT",
45
+ "devDependencies": {
46
+ "@types/node": "^20.10.0",
47
+ "@vitest/coverage-v8": "^1.6.1",
48
+ "fast-check": "^3.15.0",
49
+ "typescript": "^5.3.3",
50
+ "vitest": "^1.1.0"
51
+ },
52
+ "optionalDependencies": {
53
+ "@types/react": "^18.2.0",
54
+ "@types/react-dom": "^18.2.0",
55
+ "@vitejs/plugin-react": "^4.2.0",
56
+ "react": "^18.2.0",
57
+ "react-dom": "^18.2.0",
58
+ "vite": "^5.0.0"
59
+ }
60
+ }