@microverse.ts/host-surface 0.1.0 → 0.3.0

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.
Files changed (53) hide show
  1. package/README.md +53 -22
  2. package/dist/application/ports/ScriptReferenceResolverPort.d.ts +13 -0
  3. package/dist/application/ports/ScriptReferenceResolverPort.d.ts.map +1 -0
  4. package/dist/application/useCases/compileBridgeDeclarationsFromHostSurfaceSpec.d.ts +4 -4
  5. package/dist/application/useCases/compileBridgeDeclarationsFromHostSurfaceSpec.d.ts.map +1 -1
  6. package/dist/application/useCases/compileHostSurface.d.ts +7 -6
  7. package/dist/application/useCases/compileHostSurface.d.ts.map +1 -1
  8. package/dist/domain/componentSlotPrelude.d.ts +11 -0
  9. package/dist/domain/componentSlotPrelude.d.ts.map +1 -0
  10. package/dist/domain/componentTypeSpec.d.ts +12 -0
  11. package/dist/domain/componentTypeSpec.d.ts.map +1 -0
  12. package/dist/domain/hostSurfaceManifest.d.ts +3 -2
  13. package/dist/domain/hostSurfaceManifest.d.ts.map +1 -1
  14. package/dist/domain/hostSurfaceSpecTypes.d.ts +89 -0
  15. package/dist/domain/hostSurfaceSpecTypes.d.ts.map +1 -0
  16. package/dist/domain/hostSurfaceTypes.d.ts +16 -92
  17. package/dist/domain/hostSurfaceTypes.d.ts.map +1 -1
  18. package/dist/domain/luaGlobalHook.d.ts +1 -1
  19. package/dist/domain/safeObjectKey.d.ts +1 -1
  20. package/dist/domain/safeObjectKey.d.ts.map +1 -1
  21. package/dist/domain/scriptCatalogManifest.d.ts +14 -0
  22. package/dist/domain/scriptCatalogManifest.d.ts.map +1 -0
  23. package/dist/domain/scriptContextSymbol.d.ts +6 -0
  24. package/dist/domain/scriptContextSymbol.d.ts.map +1 -0
  25. package/dist/domain/scriptProfileSpec.d.ts +31 -0
  26. package/dist/domain/scriptProfileSpec.d.ts.map +1 -0
  27. package/dist/domain/scriptPropertyMergeEnv.d.ts +6 -0
  28. package/dist/domain/scriptPropertyMergeEnv.d.ts.map +1 -0
  29. package/dist/domain/surfaceCapabilities.d.ts +1 -1
  30. package/dist/domain/surfaceCapabilities.d.ts.map +1 -1
  31. package/dist/domain/surfaceMethodDef.d.ts +1 -1
  32. package/dist/domain/surfaceMethodDef.d.ts.map +1 -1
  33. package/dist/index.d.ts +30 -14
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +846 -258
  36. package/dist/index.js.map +1 -1
  37. package/dist/infrastructure/adapters/augmentHostWithCapabilityRegistry.d.ts +1 -1
  38. package/dist/infrastructure/adapters/augmentHostWithCapabilityRegistry.d.ts.map +1 -1
  39. package/dist/infrastructure/adapters/augmentHostWithScriptContext.d.ts +4 -0
  40. package/dist/infrastructure/adapters/augmentHostWithScriptContext.d.ts.map +1 -0
  41. package/dist/infrastructure/adapters/zodSchemaValidationAdapter.d.ts +1 -1
  42. package/dist/infrastructure/adapters/zodSchemaValidationAdapter.d.ts.map +1 -1
  43. package/dist/infrastructure/builders/bridgeMergeEnv.d.ts +6 -8
  44. package/dist/infrastructure/builders/bridgeMergeEnv.d.ts.map +1 -1
  45. package/dist/infrastructure/builders/defineHostSurfaceFacade.d.ts +5 -5
  46. package/dist/infrastructure/builders/defineHostSurfaceFacade.d.ts.map +1 -1
  47. package/dist/infrastructure/builders/filterBridgeDeclarations.d.ts +11 -0
  48. package/dist/infrastructure/builders/filterBridgeDeclarations.d.ts.map +1 -0
  49. package/dist/infrastructure/builders/surfaceBuilder.d.ts +16 -11
  50. package/dist/infrastructure/builders/surfaceBuilder.d.ts.map +1 -1
  51. package/dist/infrastructure/components/hostScriptSession.d.ts +42 -72
  52. package/dist/infrastructure/components/hostScriptSession.d.ts.map +1 -1
  53. package/package.json +10 -9
@@ -1,29 +1,34 @@
1
- import { SchemaValidationPort } from '../../application/ports/SchemaValidationPort.js';
2
- import { InferSurfaceCapabilities } from '../../domain/surfaceCapabilities.js';
3
- import { SurfaceMethodDef } from '../../domain/surfaceMethodDef.js';
4
- import { AnyHostSurfaceMethod, HostSurface, HostSurfaceSpec, HostWorkflowHooksSpec } from '../../domain/hostSurfaceTypes.js';
1
+ import { SchemaValidationPort } from '../../application/ports/SchemaValidationPort';
2
+ import { ComponentTypeDefInput } from '../../domain/componentTypeSpec';
3
+ import { InferSurfaceCapabilities } from '../../domain/surfaceCapabilities';
4
+ import { SurfaceMethodDef } from '../../domain/surfaceMethodDef';
5
+ import { AnyHostSurfaceMethod, HostSurface, HostSurfaceSpec, HostComponentHooksSpec } from '../../domain/hostSurfaceTypes';
5
6
  type MutableHostSurfaceSpec = Record<string, Record<string, AnyHostSurfaceMethod>>;
7
+ type MutableComponentTypeRegistry = Record<string, ComponentTypeDefInput>;
6
8
  /**
7
9
  * Fluent builder for a host surface. Created via {@link defineHostSurfaceFor} / {@link defineHostSurface} factory overloads.
8
10
  */
9
- export declare class SurfaceBuilder<THost, const THooks extends HostWorkflowHooksSpec | undefined = undefined> {
11
+ export declare class SurfaceBuilder<THost, const THooks extends HostComponentHooksSpec | undefined = undefined> {
10
12
  private readonly spec;
11
- private workflowHooksSpec;
13
+ private readonly componentTypeRegistry;
14
+ private componentHooksSpec;
12
15
  private readonly ports;
13
- constructor(ports: readonly [SchemaValidationPort], workflowHooks?: THooks, initialSpec?: MutableHostSurfaceSpec);
16
+ constructor(ports: readonly [SchemaValidationPort], componentHooks?: THooks, initialSpec?: MutableHostSurfaceSpec, initialComponentTypes?: MutableComponentTypeRegistry);
17
+ /** Declares a typed Lua component profile (props, state, capabilities, hooks). */
18
+ componentType<const N extends string>(name: N, def: ComponentTypeDefInput<`${string}:${string}`, THooks>): SurfaceBuilder<THost, THooks>;
14
19
  /** Opens a Lua bridge table (e.g. `orders`, `greet`). */
15
20
  bridge<const B extends string>(name: B): BridgeBuilder<THost, B, THooks>;
16
- /** Attaches workflow hook Zod schemas (emitted into `.d.lua` as `on*` methods). */
17
- workflowHooks<const H extends HostWorkflowHooksSpec>(hooks: H): SurfaceBuilder<THost, H>;
21
+ /** Attaches component domain-event Zod schemas (emitted into `.d.lua` as `on*` methods on component types). */
22
+ componentHooks<const H extends HostComponentHooksSpec>(hooks: H): SurfaceBuilder<THost, H>;
18
23
  /** Compiles the accumulated spec into a {@link HostSurface}. */
19
- build(): THooks extends HostWorkflowHooksSpec ? HostSurface<THooks, InferSurfaceCapabilities<HostSurfaceSpec>> : HostSurface<undefined, InferSurfaceCapabilities<HostSurfaceSpec>>;
24
+ build(): THooks extends HostComponentHooksSpec ? HostSurface<THooks, InferSurfaceCapabilities<HostSurfaceSpec>> : HostSurface<undefined, InferSurfaceCapabilities<HostSurfaceSpec>>;
20
25
  /** @internal */
21
26
  addMethod<const B extends string, const M extends string>(bridgeName: B, methodName: M, entry: AnyHostSurfaceMethod): SurfaceBuilder<THost, THooks>;
22
27
  }
23
28
  /**
24
29
  * Per-bridge step in the fluent surface DSL. Return to {@link SurfaceBuilder} via `.method(…)`.
25
30
  */
26
- export declare class BridgeBuilder<THost, const B extends string, THooks extends HostWorkflowHooksSpec | undefined> {
31
+ export declare class BridgeBuilder<THost, const B extends string, THooks extends HostComponentHooksSpec | undefined> {
27
32
  private readonly parent;
28
33
  private readonly bridgeName;
29
34
  constructor(parent: SurfaceBuilder<THost, THooks>, bridgeName: B);
@@ -1 +1 @@
1
- {"version":3,"file":"surfaceBuilder.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/builders/surfaceBuilder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AACpF,OAAO,EAAsB,KAAK,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAE7F,OAAO,KAAK,EACV,oBAAoB,EACpB,WAAW,EACX,eAAe,EACf,qBAAqB,EACtB,MAAM,kCAAkC,CAAC;AAE1C,KAAK,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,oBAA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CAAC,UAAU;gBADV,MAAM,EAAE,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,EACrC,UAAU,EAAE,CAAC;IAGhC,4FAA4F;IAC5F,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,SAAS,GAAG,MAAM,IAAI,MAAM,EAAE,EAC1E,IAAI,EAAE,CAAC,EACP,GAAG,EAAE,gBAAgB,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,GAC5C,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC;CAGjC"}
@@ -1,94 +1,64 @@
1
- import { CapabilityId, InMemoryCapabilityRegistry } from '@microverse.ts/runtime-capabilities';
2
1
  import { Result } from '@microverse.ts/shared';
3
2
  import { z } from 'zod';
4
- import { ExecutionFailure, RunScriptResult, MicroverseId, MicroverseRuntime, TimeoutPolicy } from '@microverse.ts/runtime-core';
5
- import { HostSurface, HostWorkflowHooksSpec } from '../../domain/hostSurfaceTypes.js';
6
- import { LuaGlobalHookName } from '../../domain/luaGlobalHook.js';
7
- /**
8
- * Tuple accepted by {@link HostScriptSession.invokeGlobalHookIfPresent} when the session is specialised with
9
- * the same Zod map as {@link HostSurface} `workflowHooks` on the surface you pass in.
10
- */
11
- export type WorkflowHookInvokeArgs<TH extends HostWorkflowHooksSpec> = {
3
+ import { ExecutionFailure, RunScriptResult, MicroverseId, MicroverseRuntime, ScriptAuditEvent, ScriptInstanceContext, ScriptPropertyBag, ScriptPropertyValue, TimeoutPolicy } from '@microverse.ts/runtime-core';
4
+ import { SchemaValidationPort } from '../../application/ports/SchemaValidationPort';
5
+ import { ScriptReferenceResolverPort } from '../../application/ports/ScriptReferenceResolverPort';
6
+ import { ResolvedScriptProfile } from '../../domain/scriptProfileSpec';
7
+ import { HostSurface, HostComponentHooksSpec } from '../../domain/hostSurfaceTypes';
8
+ import { LuaGlobalHookName } from '../../domain/luaGlobalHook';
9
+ export type ComponentEventHookInvokeArgs<TH extends HostComponentHooksSpec> = {
12
10
  [K in keyof TH & string]: readonly [hook: LuaGlobalHookName<K>, payload: Readonly<z.infer<TH[K]>>];
13
11
  }[keyof TH & string];
14
- type InvokeGlobalHookIfPresentFn<THooks extends HostWorkflowHooksSpec | undefined> = THooks extends HostWorkflowHooksSpec ? (...args: WorkflowHookInvokeArgs<THooks>) => Promise<Result<RunScriptResult, ExecutionFailure>> : (globalName: string, payload: Readonly<Record<string, string | number | boolean>>) => Promise<Result<RunScriptResult, ExecutionFailure>>;
15
- /**
16
- * Options for {@link HostScriptSession}: one Wasm (or other) slot, a surface, host services, and a capability allowlist.
17
- *
18
- * @typeParam THost - Your engine context; must match the `THost` used in {@link defineHostSurfaceFor} (or {@link defineHostSurface}).
19
- * @typeParam THooks - When the surface was built with workflow hooks, pass the same `THooks` so {@link HostScriptSession.invokeGlobalHookIfPresent} narrows to those payloads (match `surface`’s `workflowHooks` typing).
20
- */
21
- export type HostScriptSessionOptions<THost, THooks extends HostWorkflowHooksSpec | undefined = undefined> = {
22
- /** Shared runtime (typically one Wasmoon VM for many slots). */
12
+ type InvokeComponentEventHookFn<THooks extends HostComponentHooksSpec | undefined> = THooks extends HostComponentHooksSpec ? (...args: ComponentEventHookInvokeArgs<THooks>) => Promise<Result<RunScriptResult, ExecutionFailure>> : (hookName: string, payload: Readonly<Record<string, string | number | boolean>>) => Promise<Result<RunScriptResult, ExecutionFailure>>;
13
+ export type HostScriptSessionOptions<THost, THooks extends HostComponentHooksSpec | undefined = undefined> = {
23
14
  readonly runtime: MicroverseRuntime;
24
- /** Surface produced by {@link defineHostSurface}. */
25
15
  readonly surface: HostSurface<THooks>;
26
- /** Host services passed into bridge handlers (orders, clock, …). */
27
16
  readonly host: THost;
28
- /** Stable sandbox id for this script / workflow / entity. */
29
17
  readonly slotKey: MicroverseId;
30
- /** Exact capability ids this session may invoke on any bridge method. */
31
- readonly allowedCapabilities: readonly CapabilityId[];
32
- /** Optional default timeout forwarded to {@link MicroverseSlot.run}. */
33
18
  readonly defaultTimeout?: TimeoutPolicy | undefined;
19
+ readonly script: ScriptInstanceContext;
20
+ /** Host-selected script profile (surface component type name). Applied at openSession before the main chunk. */
21
+ readonly profileId?: string | undefined;
22
+ /** When set, used instead of {@link HostSurfaceCore.getComponentType} (inline catalog profiles). */
23
+ readonly resolvedProfile?: ResolvedScriptProfile | undefined;
24
+ /** Lua singleton global for `Type:extend()` (e.g. `SortingAlgorithm`). Defaults to `profileId`. */
25
+ readonly profileSingleton?: string | undefined;
26
+ readonly enableComponentRuntime?: boolean | undefined;
27
+ readonly schemaValidation?: SchemaValidationPort | undefined;
28
+ readonly referenceResolver?: ScriptReferenceResolverPort | undefined;
29
+ readonly onScriptAudit?: ((event: ScriptAuditEvent) => void) | undefined;
34
30
  };
35
- /**
36
- * Binds one **Lua slot** to a {@link HostSurface}: capability allowlist, Zod validation, and `mergeEnv` wiring.
37
- *
38
- * @remarks
39
- * - **Lua → host (bridges):** tables/methods from {@link defineHostSurface} on `_ENV` call into TypeScript with Zod validation.
40
- * - **Host → Lua (hooks):** when the surface defines `workflowHooks`, {@link HostScriptSession.openSession} installs
41
- * a small `workflow` helper (`workflow:extend()` → handler table + slot registration) and
42
- * {@link HostScriptSession.invokeGlobalHookIfPresent} dispatches `on…` methods on that table. Each session has its own
43
- * slot env, so many workflows run concurrently without sharing Lua globals. Without `workflowHooks`, hooks are optional
44
- * globals (`onSmoke`, …) invoked as plain functions.
45
- * - Call {@link HostScriptSession.openSession} once before running chunks or invocations; {@link HostScriptSession.dispose} when the slot is torn down.
46
- *
47
- * @typeParam THost - Same host type as your surface handlers.
48
- * @typeParam THooks - Align with {@link HostSurface} `workflowHooks` on the surface you pass in (or `undefined` when the surface has no workflow hooks).
49
- */
50
- export declare class HostScriptSession<THost, THooks extends HostWorkflowHooksSpec | undefined = undefined> {
31
+ export declare class HostScriptSession<THost, THooks extends HostComponentHooksSpec | undefined = undefined> {
51
32
  private readonly opts;
52
33
  private sandbox;
53
- private readonly registry;
34
+ private readonly hostProps;
35
+ private readonly schemaValidation;
36
+ private activeComponentType;
37
+ private hostProfileApplied;
38
+ readonly context: ScriptInstanceContext;
54
39
  constructor(opts: HostScriptSessionOptions<THost, THooks>);
55
- /**
56
- * Allocates the underlying {@link MicroverseSlot} for this `slotKey` on the shared runtime.
57
- */
58
40
  readonly openSession: () => Promise<void>;
59
- /**
60
- * Exposes the in-memory registry (e.g. to mutate allowlists in advanced tests).
61
- */
62
- readonly getCapabilityRegistry: () => InMemoryCapabilityRegistry;
63
41
  private requireMicroverseSlot;
64
42
  private mergeEnv;
65
- /**
66
- * Executes Lua source in the slot environment with surface bridges on `_ENV`.
67
- *
68
- * @param source - Full Lua chunk (compiled with `load(..., "t", env)` in the Wasm adapter).
69
- */
43
+ private wrapReference;
44
+ private emitAudit;
45
+ private getActiveProfileName;
46
+ private profileSingletonName;
47
+ private singletonTypeNames;
48
+ private tryGetActiveProfile;
49
+ private validatePropsBag;
50
+ readonly getProps: () => Readonly<ScriptPropertyBag>;
51
+ readonly setProps: (bag: ScriptPropertyBag) => Promise<void>;
52
+ readonly patchProps: (partial: ScriptPropertyBag) => Promise<void>;
53
+ readonly flushDirtyProps: () => Promise<ScriptPropertyBag | null>;
70
54
  readonly runChunk: (source: string) => Promise<Result<RunScriptResult, ExecutionFailure>>;
71
- /**
72
- * Host → Lua: when the surface has `workflowHooks`, invokes `impl:onHook(evt)` on the handler table registered by
73
- * `workflow:extend()` in this slot. Otherwise invokes `_ENV[globalName](evt)` when that entry is a function.
74
- *
75
- * @param globalName - Hook method name, e.g. `onOrderPlaced` (same as {@link luaGlobalHookName}).
76
- * @param payload - Table fields: only string, finite number, or boolean (Lua literals).
77
- */
78
- readonly invokeGlobalHookIfPresent: InvokeGlobalHookIfPresentFn<THooks>;
79
- /**
80
- * Host → Lua: invokes `_ENV[tableName][methodName](literalTable)` where `literalTable` is built only from
81
- * string, finite number, or boolean fields in `payload`.
82
- *
83
- * @param tableName - Global table name in the slot env.
84
- * @param methodName - Function field on that table.
85
- * @param payload - Plain serializable fields for the Lua table literal.
86
- */
55
+ readonly invokeComponentHook: (hookName: string, ...args: (string | ScriptPropertyValue | Readonly<Record<string, string | number | boolean>>)[]) => Promise<Result<RunScriptResult, ExecutionFailure>>;
56
+ readonly invokeComponentEventHook: InvokeComponentEventHookFn<THooks>;
87
57
  readonly call: (tableName: string, methodName: string, payload: Record<string, unknown>) => Promise<Result<RunScriptResult, ExecutionFailure>>;
88
- /**
89
- * Releases the slot in the runtime adapter and clears the session handle.
90
- */
91
58
  readonly dispose: () => Promise<void>;
59
+ /** Seeds host props bag without Lua sync (call before setProps after mount). */
60
+ readonly seedHostProps: (bag: ScriptPropertyBag) => void;
61
+ readonly getHostProfileApplied: () => boolean;
92
62
  }
93
63
  export {};
94
64
  //# sourceMappingURL=hostScriptSession.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hostScriptSession.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/components/hostScriptSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EACjB,0BAA0B,EAC3B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EAEpB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,6BAA6B,CAAC;AAIrC,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAC3F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAGvE;;;GAGG;AACH,MAAM,MAAM,sBAAsB,CAAC,EAAE,SAAS,qBAAqB,IAAI;KACpE,CAAC,IAAI,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAAC,IAAI,EA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"0.1.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
7
- "description": "Declarative host surface (Zod + capabilities) bridge tables and LuaDefManifest for .d.lua.",
7
+ "description": "Fluent host surface DSL: Zod bridges, capability checks, component hooks, and LuaDefManifest for runtime + LuaLS stubs.",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/QADRAX/Microverse.ts.git",
@@ -27,18 +27,19 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "zod": "^3.24.0",
30
- "@microverse.ts/lua-defs": "0.1.0",
31
- "@microverse.ts/runtime-capabilities": "0.1.0",
32
- "@microverse.ts/runtime-bridge": "0.1.0",
33
- "@microverse.ts/runtime-core": "0.1.0",
34
- "@microverse.ts/shared": "0.1.0",
35
- "@microverse.ts/runtime-zod": "0.1.0"
30
+ "@microverse.ts/lua-defs": "0.3.0",
31
+ "@microverse.ts/runtime-bridge": "0.3.0",
32
+ "@microverse.ts/runtime-capabilities": "0.3.0",
33
+ "@microverse.ts/runtime-core": "0.3.0",
34
+ "@microverse.ts/runtime-zod": "0.3.0",
35
+ "@microverse.ts/shared": "0.3.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "typescript": "^5.8.3",
39
39
  "vite": "^8.0.0",
40
40
  "vite-plugin-dts": "^4.5.4",
41
- "vitest": "^3.1.4"
41
+ "vitest": "^3.1.4",
42
+ "@microverse.ts/runtime-wasm": "0.3.0"
42
43
  },
43
44
  "scripts": {
44
45
  "build": "vite build",