@runic-artifex/angular 0.2.0-preview.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 ADDED
@@ -0,0 +1,24 @@
1
+ # @runic-artifex/angular
2
+
3
+ Angular DI and signal projection for the framework-neutral Runic Application
4
+ Bridge. The package owns Angular lifecycle integration; the supplied Application
5
+ Bridge Layer remains the only Effect runtime owner.
6
+
7
+ ```ts
8
+ bootstrapApplication(App, {
9
+ providers: [provideApplicationBridge({
10
+ controller: createApplicationBridgeController(
11
+ CounterContract,
12
+ ApplicationBridgeLive(CounterContract, createDesktopFrameChannel()),
13
+ ),
14
+ snapshotFromEvent: event => event._tag === "CounterChanged" ? event.snapshot : undefined,
15
+ })],
16
+ });
17
+ ```
18
+
19
+ Components inject the typed facade with `injectApplicationBridge()`. The same
20
+ provided controller can target Runic Desktop, CS-WebUI compatibility, a hosted
21
+ WebSocket, or a mock Layer; it does not bind Angular to a particular host or let
22
+ Angular own the controller runtime. `DestroyRef` releases Angular's event
23
+ subscription; the application composition that created the controller disposes
24
+ its Effect scope during application teardown.
@@ -0,0 +1,30 @@
1
+ import { type EnvironmentProviders, type Signal } from "@angular/core";
2
+ import { type ApplicationBridgeController, type BridgeError } from "@runic-artifex/application-bridge";
3
+ /** Host-neutral composition for an Angular Application Bridge client. */
4
+ export interface ApplicationBridgeAngularConfiguration<Command, Receipt, HostEvent, Snapshot, Failure = BridgeError> {
5
+ /** The composition-owned neutral controller. Angular never creates or disposes its runtime. */
6
+ readonly controller: ApplicationBridgeController<Command, Receipt, HostEvent, Snapshot, Failure>;
7
+ /** Projects validated host events into the authoritative snapshot, when applicable. */
8
+ readonly snapshotFromEvent?: (event: HostEvent) => Snapshot | undefined;
9
+ }
10
+ /** Angular-facing facade over the controller's one owned Effect runtime. */
11
+ export interface ApplicationBridgeClient<Command, Receipt, HostEvent, Snapshot, Failure = BridgeError> {
12
+ readonly snapshot: Signal<Snapshot | undefined>;
13
+ readonly error: Signal<Failure | undefined>;
14
+ readonly initialized: Signal<boolean>;
15
+ initialize(): Promise<Snapshot>;
16
+ dispatch(command: Command): Promise<Receipt>;
17
+ cancel(operationId: string): Promise<void>;
18
+ reconnect(): Promise<Snapshot>;
19
+ uiReady(): Promise<void>;
20
+ uiRendered(): Promise<void>;
21
+ subscribe(onEvent: (event: HostEvent) => void): () => void;
22
+ }
23
+ /**
24
+ * Registers a single bridge client in the application injector. The supplied
25
+ * controller can target Runic Desktop, CS-WebUI compatibility, a hosted
26
+ * WebSocket, or a mock without changing the Angular package boundary.
27
+ */
28
+ export declare function provideApplicationBridge<Command, Receipt, HostEvent, Snapshot, Failure = BridgeError>(configuration: ApplicationBridgeAngularConfiguration<Command, Receipt, HostEvent, Snapshot, Failure>): EnvironmentProviders;
29
+ /** Injects the typed facade registered by {@link provideApplicationBridge}. */
30
+ export declare function injectApplicationBridge<Command, Receipt, HostEvent, Snapshot, Failure = BridgeError>(): ApplicationBridgeClient<Command, Receipt, HostEvent, Snapshot, Failure>;
@@ -0,0 +1,69 @@
1
+ import { DestroyRef, InjectionToken, inject, makeEnvironmentProviders, signal, } from "@angular/core";
2
+ import { Cause, Effect, Exit, Option, } from "effect";
3
+ import { bridgeError, } from "@runic-artifex/application-bridge";
4
+ const configurationToken = new InjectionToken("RunicApplicationBridgeConfiguration");
5
+ const clientToken = new InjectionToken("RunicApplicationBridgeClient");
6
+ /**
7
+ * Registers a single bridge client in the application injector. The supplied
8
+ * controller can target Runic Desktop, CS-WebUI compatibility, a hosted
9
+ * WebSocket, or a mock without changing the Angular package boundary.
10
+ */
11
+ export function provideApplicationBridge(configuration) {
12
+ return makeEnvironmentProviders([
13
+ { provide: configurationToken, useValue: configuration },
14
+ {
15
+ provide: clientToken,
16
+ useFactory: () => createClient(inject(configurationToken), inject(DestroyRef)),
17
+ },
18
+ ]);
19
+ }
20
+ /** Injects the typed facade registered by {@link provideApplicationBridge}. */
21
+ export function injectApplicationBridge() {
22
+ return inject(clientToken);
23
+ }
24
+ function createClient(configuration, destroyRef) {
25
+ const controller = configuration.controller;
26
+ const snapshot = signal(undefined);
27
+ const error = signal(undefined);
28
+ const initialized = signal(false);
29
+ const unsubscribe = controller.subscribe((event) => {
30
+ const projected = configuration.snapshotFromEvent?.(event);
31
+ if (projected !== undefined)
32
+ snapshot.set(projected);
33
+ }, (failure) => error.set(failure));
34
+ destroyRef.onDestroy(() => {
35
+ unsubscribe();
36
+ });
37
+ return {
38
+ snapshot: snapshot.asReadonly(),
39
+ error: error.asReadonly(),
40
+ initialized: initialized.asReadonly(),
41
+ initialize: () => run(controller, controller.effects.initialize, snapshot, error, initialized),
42
+ dispatch: (command) => run(controller, controller.effects.dispatch(command), undefined, error),
43
+ cancel: (operationId) => run(controller, controller.effects.cancel(operationId), undefined, error),
44
+ reconnect: () => run(controller, controller.effects.reconnect, snapshot, error, initialized),
45
+ uiReady: () => run(controller, controller.effects.uiReady, undefined, error),
46
+ uiRendered: () => run(controller, controller.effects.uiRendered, undefined, error),
47
+ subscribe: (onEvent) => controller.subscribe(onEvent, (failure) => error.set(failure)),
48
+ };
49
+ }
50
+ async function run(controller, operation, snapshot, error, initialized) {
51
+ error.set(undefined);
52
+ try {
53
+ const outcome = await controller.runExit(operation);
54
+ if (Exit.isFailure(outcome)) {
55
+ const failure = Cause.findErrorOption(outcome.cause);
56
+ throw Option.isSome(failure)
57
+ ? failure.value
58
+ : bridgeError("OperationFailed", "The Application Bridge operation was interrupted.");
59
+ }
60
+ const value = outcome.value;
61
+ snapshot?.set(value);
62
+ initialized?.set(true);
63
+ return value;
64
+ }
65
+ catch (failure) {
66
+ error.set(failure);
67
+ throw failure;
68
+ }
69
+ }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@runic-artifex/angular",
3
+ "version": "0.2.0-preview.1",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/Runic-Artifex/runic-sdk.git",
7
+ "directory": "packages/web/angular"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public",
11
+ "tag": "preview"
12
+ },
13
+ "description": "Angular DI and signal adapter for the Runic Application Bridge.",
14
+ "homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/main/packages/web/angular#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/Runic-Artifex/runic-sdk/issues"
17
+ },
18
+ "keywords": [
19
+ "runic-artifex",
20
+ "angular",
21
+ "application-bridge",
22
+ "signals",
23
+ "desktop"
24
+ ],
25
+ "license": "MIT",
26
+ "type": "module",
27
+ "sideEffects": false,
28
+ "main": "./dist/esm/index.js",
29
+ "module": "./dist/esm/index.js",
30
+ "types": "./dist/esm/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/esm/index.d.ts",
34
+ "import": "./dist/esm/index.js",
35
+ "default": "./dist/esm/index.js"
36
+ },
37
+ "./package.json": "./package.json"
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "README.md"
42
+ ],
43
+ "engines": {
44
+ "node": ">=24.18.0 <25"
45
+ },
46
+ "scripts": {
47
+ "clean": "bun --input-type=module --eval \"import { rmSync } from 'node:fs'; rmSync('dist', { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });\"",
48
+ "build": "bun run --bun clean && tsc --project tsconfig.json",
49
+ "prepack": "bun run --bun build"
50
+ },
51
+ "dependencies": {
52
+ "@runic-artifex/application-bridge": "0.2.0-preview.1"
53
+ },
54
+ "peerDependencies": {
55
+ "@angular/core": ">=20.3.26 <23"
56
+ },
57
+ "devDependencies": {
58
+ "@angular/compiler": "22.1.5",
59
+ "@angular/compiler-cli": "22.1.5",
60
+ "@angular/core": "22.1.5",
61
+ "typescript": "6.0.3"
62
+ },
63
+ "packageManager": "bun@1.4.2",
64
+ "gitHead": "c9d444a218cc3fdda190c02af41e91d6c53b2641"
65
+ }