@microverse.ts/host-surface 0.1.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.
- package/LICENSE +21 -0
- package/README.md +93 -0
- package/dist/application/ports/SchemaValidationPort.d.ts +9 -0
- package/dist/application/ports/SchemaValidationPort.d.ts.map +1 -0
- package/dist/application/useCases/compileBridgeDeclarationsFromHostSurfaceSpec.d.ts +9 -0
- package/dist/application/useCases/compileBridgeDeclarationsFromHostSurfaceSpec.d.ts.map +1 -0
- package/dist/application/useCases/compileHostSurface.d.ts +13 -0
- package/dist/application/useCases/compileHostSurface.d.ts.map +1 -0
- package/dist/domain/capabilityRegistrySymbol.d.ts +14 -0
- package/dist/domain/capabilityRegistrySymbol.d.ts.map +1 -0
- package/dist/domain/hostSurfaceManifest.d.ts +8 -0
- package/dist/domain/hostSurfaceManifest.d.ts.map +1 -0
- package/dist/domain/hostSurfaceTypes.d.ts +135 -0
- package/dist/domain/hostSurfaceTypes.d.ts.map +1 -0
- package/dist/domain/inferMethodAsync.d.ts +10 -0
- package/dist/domain/inferMethodAsync.d.ts.map +1 -0
- package/dist/domain/luaGlobalHook.d.ts +12 -0
- package/dist/domain/luaGlobalHook.d.ts.map +1 -0
- package/dist/domain/luaTypeAtoms.d.ts +4 -0
- package/dist/domain/luaTypeAtoms.d.ts.map +1 -0
- package/dist/domain/safeObjectKey.d.ts +7 -0
- package/dist/domain/safeObjectKey.d.ts.map +1 -0
- package/dist/domain/surfaceCapabilities.d.ts +21 -0
- package/dist/domain/surfaceCapabilities.d.ts.map +1 -0
- package/dist/domain/surfaceCapabilityString.d.ts +6 -0
- package/dist/domain/surfaceCapabilityString.d.ts.map +1 -0
- package/dist/domain/surfaceMethodDef.d.ts +25 -0
- package/dist/domain/surfaceMethodDef.d.ts.map +1 -0
- package/dist/domain/zodLuaType.d.ts +18 -0
- package/dist/domain/zodLuaType.d.ts.map +1 -0
- package/dist/domain/zodToLuaTypeRef.d.ts +17 -0
- package/dist/domain/zodToLuaTypeRef.d.ts.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +848 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/adapters/augmentHostWithCapabilityRegistry.d.ts +11 -0
- package/dist/infrastructure/adapters/augmentHostWithCapabilityRegistry.d.ts.map +1 -0
- package/dist/infrastructure/adapters/zodSchemaValidationAdapter.d.ts +3 -0
- package/dist/infrastructure/adapters/zodSchemaValidationAdapter.d.ts.map +1 -0
- package/dist/infrastructure/builders/bridgeMergeEnv.d.ts +11 -0
- package/dist/infrastructure/builders/bridgeMergeEnv.d.ts.map +1 -0
- package/dist/infrastructure/builders/defineHostSurfaceFacade.d.ts +41 -0
- package/dist/infrastructure/builders/defineHostSurfaceFacade.d.ts.map +1 -0
- package/dist/infrastructure/builders/surfaceBuilder.d.ts +34 -0
- package/dist/infrastructure/builders/surfaceBuilder.d.ts.map +1 -0
- package/dist/infrastructure/components/hostScriptSession.d.ts +94 -0
- package/dist/infrastructure/components/hostScriptSession.d.ts.map +1 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 QADRAX
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# `@microverse.ts/host-surface`
|
|
2
|
+
|
|
3
|
+
Declare a **host surface** in TypeScript: Zod schemas, capabilities, and handlers that compile into:
|
|
4
|
+
|
|
5
|
+
1. **Runtime bridge tables** for `mergeEnv` (what Lua calls at execution time).
|
|
6
|
+
2. A **`LuaDefManifest`** for `@microverse.ts/lua-defs` (`.d.lua` stubs for LuaLS).
|
|
7
|
+
|
|
8
|
+
Most applications import **`defineHostSurfaceFor`** from **`@microverse.ts/microverse-lua`** instead of this package directly. Use `@microverse.ts/host-surface` when you need `HostScriptSession` or custom runtime wiring.
|
|
9
|
+
|
|
10
|
+
Monorepo overview: [root README](../../README.md). Lua microverse lifecycle: [`@microverse.ts/microverse-lua`](../microverse-lua/README.md).
|
|
11
|
+
|
|
12
|
+
## Defining a surface
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { defineHostSurfaceFor } from '@microverse.ts/microverse-lua';
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
|
|
18
|
+
export default defineHostSurfaceFor<MyHost>()
|
|
19
|
+
.bridge('orders')
|
|
20
|
+
.method('get', {
|
|
21
|
+
requires: 'orders:read',
|
|
22
|
+
input: z.object({ orderId: z.string() }),
|
|
23
|
+
output: orderDto,
|
|
24
|
+
description: 'Load order by id',
|
|
25
|
+
handler: ({ host }, { orderId }) => host.orders.get(orderId),
|
|
26
|
+
})
|
|
27
|
+
.workflowHooks(workflowHooks) // optional
|
|
28
|
+
.build();
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
| Step | Role |
|
|
32
|
+
|------|------|
|
|
33
|
+
| `defineHostSurfaceFor<THost>()` | Start builder; `handler` receives typed `host`. |
|
|
34
|
+
| `.bridge('orders')` | Lua global table name. |
|
|
35
|
+
| `.method('get', { … })` | One bridge method: `requires`, `input`, `output`, `handler`. |
|
|
36
|
+
| `.workflowHooks(…)` | Optional Zod map → `on*` hooks in Lua. |
|
|
37
|
+
| `.build()` | Compiled {@link HostSurface}. |
|
|
38
|
+
|
|
39
|
+
`requires` is a `domain:action` capability string. `async` is inferred from `async function` handlers.
|
|
40
|
+
|
|
41
|
+
Bridge names become **Lua global tables** (`orders`, `billing`, …). Do not use `workflow` as a bridge name when workflow hooks are enabled—that name is reserved for the injected `workflow:extend()` helper.
|
|
42
|
+
|
|
43
|
+
### Host object
|
|
44
|
+
|
|
45
|
+
The **host** is your engine context (services, repos, config). It is not generated here—you construct it in your app and pass it to `MicroverseLua.create({ host, surface })` or `HostScriptSession`.
|
|
46
|
+
|
|
47
|
+
### Workflow hooks
|
|
48
|
+
|
|
49
|
+
Call `.workflowHooks({ OrderPlaced: z.object({ … }), … })` before `.build()`.
|
|
50
|
+
|
|
51
|
+
- TypeScript emits via `emitToAllScripts('OrderPlaced', payload)`.
|
|
52
|
+
- Lua implements `onOrderPlaced` on the table from `workflow:extend()`.
|
|
53
|
+
- Manifest includes `MicroverseWorkflowEvt_*` classes in `.d.lua`.
|
|
54
|
+
|
|
55
|
+
## `HostScriptSession`
|
|
56
|
+
|
|
57
|
+
Lower-level API when you manage slots yourself (one session = one env slot + capability allowlist):
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
const session = new HostScriptSession({
|
|
61
|
+
runtime,
|
|
62
|
+
surface,
|
|
63
|
+
host,
|
|
64
|
+
slotKey: createLuaEnvSlotKey('script:my-id'),
|
|
65
|
+
allowedCapabilities: surface.pickCapabilities('orders:read'),
|
|
66
|
+
});
|
|
67
|
+
await session.openSession();
|
|
68
|
+
await session.runChunk(luaSource);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`MicroverseLua` in `@microverse.ts/microverse-lua` wraps this for the common case (shared VM, `registerScript`, broadcast hooks).
|
|
72
|
+
|
|
73
|
+
## Generating `.d.lua`
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
microverse generate-lua-defs --surface src/mySurface.ts
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Requires `export default` of the compiled surface (`.build()` result). See [`@microverse.ts/cli`](../cli/README.md) and [`@microverse.ts/lua-defs`](../lua-defs/README.md).
|
|
80
|
+
|
|
81
|
+
Optional **Lua type names** on Zod schemas (`luaType('OrderDto', z.object({ … }))`) improve stub names—see `examples/business-scripting-engine/src/schemas/surface/bridgePayloads.ts`.
|
|
82
|
+
|
|
83
|
+
## Async bridges and Lua patterns
|
|
84
|
+
|
|
85
|
+
Bridge handlers are **synchronous at the Lua boundary**; Wasmoon does not auto-resolve `Promise` into Lua values. For async TypeScript work, use the async bridge pattern (`:await()` or `onComplete` callback) documented in:
|
|
86
|
+
|
|
87
|
+
- [docs/async-subroutines-components.md](docs/async-subroutines-components.md)
|
|
88
|
+
- [examples/business-scripting-engine/docs/COMPONENT_PATTERN.md](../../examples/business-scripting-engine/docs/COMPONENT_PATTERN.md)
|
|
89
|
+
|
|
90
|
+
## Reference
|
|
91
|
+
|
|
92
|
+
- Example surface: [`examples/business-scripting-engine/src/businessSurface.ts`](../../examples/business-scripting-engine/src/businessSurface.ts)
|
|
93
|
+
- Tests: `src/domain/`, `src/application/`, `src/infrastructure/`
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Result } from '@microverse.ts/shared';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Validates unknown payloads against Zod schemas (bridge IO, etc.).
|
|
5
|
+
*/
|
|
6
|
+
export type SchemaValidationPort = {
|
|
7
|
+
readonly validateWithZodSchema: <T>(schema: z.ZodType<T>, payload: unknown) => Result<T, string>;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=SchemaValidationPort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaValidationPort.d.ts","sourceRoot":"","sources":["../../../src/application/ports/SchemaValidationPort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,qBAAqB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;CAClG,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DeclarativeBridgeDeclaration } from '@microverse.ts/runtime-bridge';
|
|
2
|
+
import { WithMicroverseCapabilityRegistry } from '../../domain/capabilityRegistrySymbol.js';
|
|
3
|
+
import { HostSurfaceSpec } from '../../domain/hostSurfaceTypes.js';
|
|
4
|
+
import { SchemaValidationPort } from '../ports/SchemaValidationPort.js';
|
|
5
|
+
/**
|
|
6
|
+
* Builds declarative bridge declarations from a host surface spec, using the schema validation port for Lua ↔ host payloads.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createBridgeDeclarationsFromHostSurfaceSpec<TSpec extends HostSurfaceSpec>(schemaValidation: SchemaValidationPort, spec: TSpec): ReadonlyArray<DeclarativeBridgeDeclaration<WithMicroverseCapabilityRegistry, string>>;
|
|
9
|
+
//# sourceMappingURL=compileBridgeDeclarationsFromHostSurfaceSpec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compileBridgeDeclarationsFromHostSurfaceSpec.d.ts","sourceRoot":"","sources":["../../../src/application/useCases/compileBridgeDeclarationsFromHostSurfaceSpec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAGlF,OAAO,EAAkC,KAAK,gCAAgC,EAAE,MAAM,0CAA0C,CAAC;AAGjI,OAAO,KAAK,EAAwB,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAC9F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAa7E;;GAEG;AACH,wBAAgB,2CAA2C,CAAC,KAAK,SAAS,eAAe,EACvF,gBAAgB,EAAE,oBAAoB,EACtC,IAAI,EAAE,KAAK,GACV,aAAa,CAAC,4BAA4B,CAAC,gCAAgC,EAAE,MAAM,CAAC,CAAC,CA+CvF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { InferSurfaceCapabilities } from '../../domain/surfaceCapabilities.js';
|
|
2
|
+
import { HostSurface, HostSurfaceSpec, HostWorkflowHooksSpec } from '../../domain/hostSurfaceTypes.js';
|
|
3
|
+
import { SchemaValidationPort } from '../ports/SchemaValidationPort.js';
|
|
4
|
+
/**
|
|
5
|
+
* Compiles a host surface using the injected schema validation port (tuple matches `UseCase` conventions in `@microverse.ts/shared`).
|
|
6
|
+
*/
|
|
7
|
+
export declare function compileHostSurface<const TSpec extends HostSurfaceSpec>(ports: readonly [SchemaValidationPort], spec: TSpec): HostSurface<undefined, InferSurfaceCapabilities<TSpec>>;
|
|
8
|
+
export declare function compileHostSurface<const TSpec extends HostSurfaceSpec, const THooks extends HostWorkflowHooksSpec>(ports: readonly [SchemaValidationPort], spec: TSpec, workflowHooks: THooks): HostSurface<THooks, InferSurfaceCapabilities<TSpec>>;
|
|
9
|
+
/**
|
|
10
|
+
* Same as {@link compileHostSurface}, but requires every bridge method to be typed with the same `THost`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function compileHostSurfaceFor<const TSpec extends HostSurfaceSpec, const THooks extends HostWorkflowHooksSpec | undefined = undefined>(ports: readonly [SchemaValidationPort], spec: TSpec, workflowHooks?: THooks): THooks extends HostWorkflowHooksSpec ? HostSurface<THooks, InferSurfaceCapabilities<TSpec>> : HostSurface<undefined, InferSurfaceCapabilities<TSpec>>;
|
|
13
|
+
//# sourceMappingURL=compileHostSurface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compileHostSurface.d.ts","sourceRoot":"","sources":["../../../src/application/useCases/compileHostSurface.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EACV,WAAW,EAEX,eAAe,EACf,qBAAqB,EACtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAoB7E;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,CAAC,KAAK,SAAS,eAAe,EACpE,KAAK,EAAE,SAAS,CAAC,oBAAoB,CAAC,EACtC,IAAI,EAAE,KAAK,GACV,WAAW,CAAC,SAAS,EAAE,wBAAwB,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3D,wBAAgB,kBAAkB,CAChC,KAAK,CAAC,KAAK,SAAS,eAAe,EACnC,KAAK,CAAC,MAAM,SAAS,qBAAqB,EAE1C,KAAK,EAAE,SAAS,CAAC,oBAAoB,CAAC,EACtC,IAAI,EAAE,KAAK,EACX,aAAa,EAAE,MAAM,GACpB,WAAW,CAAC,MAAM,EAAE,wBAAwB,CAAC,KAAK,CAAC,CAAC,CAAC;AAcxD;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,CAAC,KAAK,SAAS,eAAe,EACnC,KAAK,CAAC,MAAM,SAAS,qBAAqB,GAAG,SAAS,GAAG,SAAS,EAElE,KAAK,EAAE,SAAS,CAAC,oBAAoB,CAAC,EACtC,IAAI,EAAE,KAAK,EACX,aAAa,CAAC,EAAE,MAAM,GACrB,MAAM,SAAS,qBAAqB,GACnC,WAAW,CAAC,MAAM,EAAE,wBAAwB,CAAC,KAAK,CAAC,CAAC,GACpD,WAAW,CAAC,SAAS,EAAE,wBAAwB,CAAC,KAAK,CAAC,CAAC,CAQ1D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CapabilityRegistryPort } from '@microverse.ts/runtime-capabilities';
|
|
2
|
+
/**
|
|
3
|
+
* Well-known symbol key used to attach a {@link CapabilityRegistryPort} on the host object
|
|
4
|
+
* while surface bridge methods run. Populated by {@link augmentHostWithCapabilityRegistry} or
|
|
5
|
+
* internally by {@link HostScriptSession}.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MICROVERSE_CAPABILITY_REGISTRY: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* Host object extended with the capability registry required by host-surface bridge wrappers.
|
|
10
|
+
*/
|
|
11
|
+
export type WithMicroverseCapabilityRegistry = {
|
|
12
|
+
readonly [MICROVERSE_CAPABILITY_REGISTRY]: CapabilityRegistryPort;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=capabilityRegistrySymbol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilityRegistrySymbol.d.ts","sourceRoot":"","sources":["../../src/domain/capabilityRegistrySymbol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAElF;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,eAA8C,CAAC;AAE1F;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,QAAQ,CAAC,CAAC,8BAA8B,CAAC,EAAE,sBAAsB,CAAC;CACnE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LuaDefManifest } from '@microverse.ts/lua-defs';
|
|
2
|
+
import { HostSurfaceSpec, HostWorkflowHooksSpec } from './hostSurfaceTypes.js';
|
|
3
|
+
export declare function buildLuaDefManifestFromHostSurfaceSpec(spec: HostSurfaceSpec, opts: {
|
|
4
|
+
readonly output: string;
|
|
5
|
+
readonly headerNote?: string | undefined;
|
|
6
|
+
readonly luaTypeAliases?: Readonly<Record<string, string>> | undefined;
|
|
7
|
+
}, workflowHooks?: HostWorkflowHooksSpec): LuaDefManifest;
|
|
8
|
+
//# sourceMappingURL=hostSurfaceManifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostSurfaceManifest.d.ts","sourceRoot":"","sources":["../../src/domain/hostSurfaceManifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAMf,MAAM,yBAAyB,CAAC;AAGjC,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AA0DpF,wBAAgB,sCAAsC,CACpD,IAAI,EAAE,eAAe,EACrB,IAAI,EAAE;IACJ,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;CACxE,EACD,aAAa,CAAC,EAAE,qBAAqB,GACpC,cAAc,CAiGhB"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { LuaDefManifest } from '@microverse.ts/lua-defs';
|
|
2
|
+
import { DeclarativeBridgeDeclaration } from '@microverse.ts/runtime-bridge';
|
|
3
|
+
import { CapabilityId } from '@microverse.ts/runtime-capabilities';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { SurfaceCapabilityString } from './surfaceCapabilityString.js';
|
|
6
|
+
import { WithMicroverseCapabilityRegistry } from './capabilityRegistrySymbol.js';
|
|
7
|
+
/**
|
|
8
|
+
* Context passed to every surface `handler`: your typed host plus the active Lua **slot key** (string form).
|
|
9
|
+
*
|
|
10
|
+
* @typeParam THost - Host services / world object you declare for bridge handlers.
|
|
11
|
+
*/
|
|
12
|
+
export type HostFnContext<THost> = {
|
|
13
|
+
readonly host: THost;
|
|
14
|
+
/** Stable slot identifier for this sandbox (same convention as `DeclarativeBridgeDeclaration`). */
|
|
15
|
+
readonly slotKey: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Strongly typed description of one bridge method (produced by the fluent `.method(…)` builder).
|
|
19
|
+
* TypeScript checks `handler` against `input` / `output` schemas.
|
|
20
|
+
*
|
|
21
|
+
* @typeParam THost - Host type available as `ctx.host` inside `handler`.
|
|
22
|
+
* @typeParam TIn - Payload type after Zod `input` parsing (Lua calls the bridge with one table argument).
|
|
23
|
+
* @typeParam TOut - Return type validated by Zod `output` before crossing back to Lua.
|
|
24
|
+
* @typeParam TCap - Capability id for this method (from fluent `requires: 'domain:action'`).
|
|
25
|
+
*/
|
|
26
|
+
export type HostSurfaceMethodEntry<THost, TIn, TOut, TCap extends CapabilityId = CapabilityId> = {
|
|
27
|
+
/** Capability required to invoke this method; checked against the session registry before the handler runs. */
|
|
28
|
+
readonly capability: TCap;
|
|
29
|
+
/** Zod schema for the single payload object from Lua (e.g. `z.object({ id: z.string() })`). */
|
|
30
|
+
readonly input: z.ZodType<TIn>;
|
|
31
|
+
/** Zod schema for the value returned to Lua. */
|
|
32
|
+
readonly output: z.ZodType<TOut>;
|
|
33
|
+
/**
|
|
34
|
+
* Host logic at the Lua↔JS boundary. May return `Promise<TOut>`; Lua must use `:await()` on the returned handle
|
|
35
|
+
* or pass an `onComplete` callback as the second argument (see `MICROVERSE_LUA_SLOT_VM_BOOTSTRAP` in `@microverse.ts/runtime-wasm`).
|
|
36
|
+
*/
|
|
37
|
+
readonly handler: (ctx: HostFnContext<THost>, input: TIn) => TOut | Promise<TOut>;
|
|
38
|
+
/**
|
|
39
|
+
* When true, manifest and Lua runtime treat this method as async (`MethodHandle` + optional `onComplete`).
|
|
40
|
+
* Set automatically for `async function` handlers in the fluent builder.
|
|
41
|
+
*/
|
|
42
|
+
readonly async?: boolean | undefined;
|
|
43
|
+
/** Optional description emitted into the LuaCATS manifest. */
|
|
44
|
+
readonly description?: string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Advanced escape hatch for manifest emission. Prefer registering Zod schemas with {@link luaType}
|
|
47
|
+
* (see `bridgePayloads` in the business example) so `.d.lua` stays inferred from `input` / `output`.
|
|
48
|
+
* Does not replace async bridge typing (`async: true` emits handle + `onComplete` in `.d.lua`).
|
|
49
|
+
* `paramTypes` keys must match `input` object keys (or `value` for non-object inputs).
|
|
50
|
+
*/
|
|
51
|
+
readonly lua?: {
|
|
52
|
+
readonly paramTypes?: Partial<Record<string, string>> | undefined;
|
|
53
|
+
readonly returns?: string | undefined;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Erased method entry stored inside a {@link HostSurfaceSpec}. Assignability widens at the spec boundary.
|
|
58
|
+
*/
|
|
59
|
+
export type AnyHostSurfaceMethod = {
|
|
60
|
+
readonly capability: CapabilityId;
|
|
61
|
+
readonly input: z.ZodTypeAny;
|
|
62
|
+
readonly output: z.ZodTypeAny;
|
|
63
|
+
readonly handler: (ctx: HostFnContext<any>, input: any) => unknown;
|
|
64
|
+
readonly async?: boolean | undefined;
|
|
65
|
+
readonly description?: string | undefined;
|
|
66
|
+
readonly lua?: {
|
|
67
|
+
readonly paramTypes?: Partial<Record<string, string>> | undefined;
|
|
68
|
+
readonly returns?: string | undefined;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Tree shape accepted by {@link defineHostSurface}: top-level keys become Lua global bridge **tables**
|
|
73
|
+
* (e.g. `orders`, `billing`); inner keys become **methods** on that table.
|
|
74
|
+
*/
|
|
75
|
+
export type HostSurfaceSpec = Readonly<Record<string, Readonly<Record<string, AnyHostSurfaceMethod | HostSurfaceMethodEntry<any, any, any, any>>>>>;
|
|
76
|
+
/**
|
|
77
|
+
* Surface spec where every method entry uses the same host type as your engine context
|
|
78
|
+
* (the `THost` you pass as `host` into {@link HostScriptSession}).
|
|
79
|
+
*/
|
|
80
|
+
export type HostSurfaceSpecForHost<THost> = Readonly<{
|
|
81
|
+
readonly [bridge: string]: Readonly<{
|
|
82
|
+
readonly [method: string]: HostSurfaceMethodEntry<THost, any, any, any>;
|
|
83
|
+
}>;
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* Zod object schemas keyed by PascalCase event kind (`OrderPlaced` → Lua method `onOrderPlaced` on the handler from `workflow:extend()`).
|
|
87
|
+
* Passed as the second argument to {@link defineHostSurface} to emit workflow hook typings into `.d.lua`.
|
|
88
|
+
*/
|
|
89
|
+
export type HostWorkflowHooksSpec = Readonly<Record<string, z.ZodObject<any>>>;
|
|
90
|
+
/**
|
|
91
|
+
* Bridge + manifest API shared by every {@link HostSurface} (with or without workflow hooks).
|
|
92
|
+
*
|
|
93
|
+
* @typeParam TCapabilities - Union of capability ids declared on the surface spec (see {@link InferSurfaceCapabilities}).
|
|
94
|
+
*/
|
|
95
|
+
export type HostSurfaceCore<TCapabilities extends CapabilityId = CapabilityId> = {
|
|
96
|
+
/**
|
|
97
|
+
* Declarative bridge declarations compatible with {@link buildDeclarativeBridgeTable}.
|
|
98
|
+
* The host must satisfy {@link WithMicroverseCapabilityRegistry} (see {@link HostScriptSession}).
|
|
99
|
+
*/
|
|
100
|
+
readonly toBridgeDeclarations: () => ReadonlyArray<DeclarativeBridgeDeclaration<WithMicroverseCapabilityRegistry, string>>;
|
|
101
|
+
/**
|
|
102
|
+
* Builds a `LuaDefManifest` for `@microverse.ts/lua-defs` (`buildLuaCatsDocument`, `generateDefs`, CLI).
|
|
103
|
+
*
|
|
104
|
+
* @param opts.output - Default `.d.lua` output path recorded in the manifest.
|
|
105
|
+
* @param opts.headerNote - Optional banner comment in the generated file.
|
|
106
|
+
* @param opts.luaTypeAliases - Optional overrides / extra `---@alias` entries; by default aliases come from {@link luaType} on Zod schemas used in the surface.
|
|
107
|
+
*/
|
|
108
|
+
readonly toLuaDefManifest: (opts: {
|
|
109
|
+
readonly output: string;
|
|
110
|
+
readonly headerNote?: string | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Optional extra `---@alias` entries, or overrides for inferred aliases (same key replaces inferred).
|
|
113
|
+
*/
|
|
114
|
+
readonly luaTypeAliases?: Readonly<Record<string, string>> | undefined;
|
|
115
|
+
}) => LuaDefManifest;
|
|
116
|
+
/** Every capability id referenced by a method on this surface (deduplicated). */
|
|
117
|
+
readonly capabilities: readonly TCapabilities[];
|
|
118
|
+
/**
|
|
119
|
+
* Subset allowlist for a script session. Only capabilities declared on this surface are accepted.
|
|
120
|
+
*/
|
|
121
|
+
pickCapabilities<const T extends readonly SurfaceCapabilityString<TCapabilities>[]>(...capabilities: T): ReadonlyArray<Extract<T[number], TCapabilities>>;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Compiled host surface: bridge factories for `mergeEnv` plus manifest builder for `.d.lua` generation.
|
|
125
|
+
*
|
|
126
|
+
* @typeParam THooks - When you pass `workflowHooks` to {@link defineHostSurface}, the returned surface includes
|
|
127
|
+
* `workflowHooks` so callers can type workflow events from the surface object alone.
|
|
128
|
+
* @typeParam TCapabilities - Capability ids declared on the surface (for script allowlists).
|
|
129
|
+
*/
|
|
130
|
+
export type HostSurface<THooks extends HostWorkflowHooksSpec | undefined = undefined, TCapabilities extends CapabilityId = CapabilityId> = [undefined] extends [THooks] ? HostSurfaceCore<TCapabilities> : HostSurfaceCore<TCapabilities> & {
|
|
131
|
+
readonly workflowHooks: THooks;
|
|
132
|
+
};
|
|
133
|
+
/** Options passed to {@link HostSurfaceCore.toLuaDefManifest}. */
|
|
134
|
+
export type LuaDefManifestGeneratorOpts = Parameters<HostSurfaceCore['toLuaDefManifest']>[0];
|
|
135
|
+
//# sourceMappingURL=hostSurfaceTypes.d.ts.map
|
|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AACH,MAAM,MAAM,WAAW,CACrB,MAAM,SAAS,qBAAqB,GAAG,SAAS,GAAG,SAAS,EAC5D,aAAa,SAAS,YAAY,GAAG,YAAY,IAC/C,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,GAC5B,eAAe,CAAC,aAAa,CAAC,GAC9B,eAAe,CAAC,aAAa,CAAC,GAAG;IAAE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAExE,kEAAkE;AAClE,MAAM,MAAM,2BAA2B,GAAG,UAAU,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Infers {@link HostSurfaceMethodEntry.async} from handler shape unless overridden explicitly. */
|
|
2
|
+
export declare function inferMethodAsync(def: {
|
|
3
|
+
readonly handler: {
|
|
4
|
+
constructor: {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
readonly async?: boolean | undefined;
|
|
9
|
+
}): boolean;
|
|
10
|
+
//# sourceMappingURL=inferMethodAsync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inferMethodAsync.d.ts","sourceRoot":"","sources":["../../src/domain/inferMethodAsync.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,wBAAgB,gBAAgB,CAAC,GAAG,EAAE;IACpC,QAAQ,CAAC,OAAO,EAAE;QAAE,WAAW,EAAE;YAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IAC7D,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACtC,GAAG,OAAO,CAQV"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lua convention for domain hooks: PascalCase event kind → method name `on{Kind}` on the workflow
|
|
3
|
+
* handler table from `workflow:extend()` in each Lua slot (e.g. `OrderPlaced` → `onOrderPlaced`).
|
|
4
|
+
*/
|
|
5
|
+
export type LuaGlobalHookName<Kind extends string> = `on${Kind}`;
|
|
6
|
+
/**
|
|
7
|
+
* Builds the `on{Kind}` method name dispatched on the slot’s workflow handler for a PascalCase event `kind`
|
|
8
|
+
* (e.g. `InventoryLow` → `onInventoryLow`).
|
|
9
|
+
* Throws if `kind` is not a safe Lua identifier fragment.
|
|
10
|
+
*/
|
|
11
|
+
export declare function luaGlobalHookName<const Kind extends string>(kind: Kind): LuaGlobalHookName<Kind>;
|
|
12
|
+
//# sourceMappingURL=luaGlobalHook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"luaGlobalHook.d.ts","sourceRoot":"","sources":["../../src/domain/luaGlobalHook.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,iBAAiB,CAAC,IAAI,SAAS,MAAM,IAAI,KAAK,IAAI,EAAE,CAAC;AAEjE;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,IAAI,SAAS,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAMhG"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Lua / LuaCATS type atoms: never emit `---@alias` for these names from `lua.paramTypes` / `lua.returns` tokens. */
|
|
2
|
+
export declare const LUA_TYPE_ATOMS: Set<string>;
|
|
3
|
+
export declare function isLuaTypeAtom(name: string): boolean;
|
|
4
|
+
//# sourceMappingURL=luaTypeAtoms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"luaTypeAtoms.d.ts","sourceRoot":"","sources":["../../src/domain/luaTypeAtoms.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,eAAO,MAAM,cAAc,aAazB,CAAC;AAEH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEnD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rejects bridge/method names that could trigger prototype pollution when used as object keys.
|
|
3
|
+
*/
|
|
4
|
+
export declare function assertSafeObjectKey(kind: 'bridge' | 'method', name: string): void;
|
|
5
|
+
/** Record with no inherited prototype — safe for dynamic string keys at runtime. */
|
|
6
|
+
export declare function createNullPrototypeRecord<T extends object>(): T;
|
|
7
|
+
//# sourceMappingURL=safeObjectKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeObjectKey.d.ts","sourceRoot":"","sources":["../../src/domain/safeObjectKey.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAIjF;AAED,oFAAoF;AACpF,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,MAAM,KAAK,CAAC,CAE/D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CapabilityId } from '@microverse.ts/runtime-capabilities';
|
|
2
|
+
import { HostSurfaceMethodEntry, HostSurfaceSpec } from './hostSurfaceTypes.js';
|
|
3
|
+
type InferMethodCapability<M> = M extends {
|
|
4
|
+
readonly capability: infer C extends CapabilityId;
|
|
5
|
+
} ? C : never;
|
|
6
|
+
type InferBridgeCapabilities<B> = B extends Readonly<Record<string, unknown>> ? InferMethodCapability<B[keyof B]> : never;
|
|
7
|
+
/**
|
|
8
|
+
* Union of every {@link CapabilityId} declared on methods in a {@link HostSurfaceSpec}
|
|
9
|
+
* (via `requires: 'domain:action'` on each fluent `.method(…)` entry).
|
|
10
|
+
*/
|
|
11
|
+
export type InferSurfaceCapabilities<TSpec extends HostSurfaceSpec> = InferBridgeCapabilities<TSpec[keyof TSpec]>;
|
|
12
|
+
/** Runtime list of capability ids declared on a compiled surface spec. */
|
|
13
|
+
export declare function collectCapabilitiesFromHostSurfaceSpec<const TSpec extends HostSurfaceSpec>(spec: TSpec): readonly InferSurfaceCapabilities<TSpec>[];
|
|
14
|
+
/** Narrows `capabilities` to those declared on the surface (runtime check). */
|
|
15
|
+
export declare function pickSurfaceCapabilities<const TSurface extends readonly CapabilityId[], const T extends readonly `${string}:${string}`[]>(surfaceCapabilities: TSurface, ...capabilities: T): ReadonlyArray<Extract<TSurface[number], CapabilityId>>;
|
|
16
|
+
/** Helper type for method entries that preserve a specific capability literal. */
|
|
17
|
+
export type SurfaceCapabilityEntry<TCap extends CapabilityId> = HostSurfaceMethodEntry<unknown, unknown, unknown> & {
|
|
18
|
+
readonly capability: TCap;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=surfaceCapabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surfaceCapabilities.d.ts","sourceRoot":"","sources":["../../src/domain/surfaceCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,KAAK,EAAwB,sBAAsB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE3G,KAAK,qBAAqB,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,SAAS,YAAY,CAAA;CAAE,GAC3F,CAAC,GACD,KAAK,CAAC;AAEV,KAAK,uBAAuB,CAAC,CAAC,IAAI,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACzE,qBAAqB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GACjC,KAAK,CAAC;AAEV;;;GAGG;AACH,MAAM,MAAM,wBAAwB,CAAC,KAAK,SAAS,eAAe,IAAI,uBAAuB,CAC3F,KAAK,CAAC,MAAM,KAAK,CAAC,CACnB,CAAC;AAEF,0EAA0E;AAC1E,wBAAgB,sCAAsC,CAAC,KAAK,CAAC,KAAK,SAAS,eAAe,EACxF,IAAI,EAAE,KAAK,GACV,SAAS,wBAAwB,CAAC,KAAK,CAAC,EAAE,CAgB5C;AAED,+EAA+E;AAC/E,wBAAgB,uBAAuB,CACrC,KAAK,CAAC,QAAQ,SAAS,SAAS,YAAY,EAAE,EAC9C,KAAK,CAAC,CAAC,SAAS,SAAS,GAAG,MAAM,IAAI,MAAM,EAAE,EAAE,EAEhD,mBAAmB,EAAE,QAAQ,EAC7B,GAAG,YAAY,EAAE,CAAC,GACjB,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC,CAUxD;AAED,kFAAkF;AAClF,MAAM,MAAM,sBAAsB,CAAC,IAAI,SAAS,YAAY,IAAI,sBAAsB,CACpF,OAAO,EACP,OAAO,EACP,OAAO,CACR,GAAG;IAAE,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CapabilityId } from '@microverse.ts/runtime-capabilities';
|
|
2
|
+
/**
|
|
3
|
+
* Unbranded string literal(s) for capabilities on a surface — use as {@link HostSurfaceCore.pickCapabilities} arguments.
|
|
4
|
+
*/
|
|
5
|
+
export type SurfaceCapabilityString<TCap extends CapabilityId> = TCap extends CapabilityId & (infer S extends `${string}:${string}`) ? S : TCap extends CapabilityId ? `${string}:${string}` : never;
|
|
6
|
+
//# sourceMappingURL=surfaceCapabilityString.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surfaceCapabilityString.d.ts","sourceRoot":"","sources":["../../src/domain/surfaceCapabilityString.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,uBAAuB,CAAC,IAAI,SAAS,YAAY,IAAI,IAAI,SAAS,YAAY,GACxF,CAAC,MAAM,CAAC,SAAS,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC,GACrC,CAAC,GACD,IAAI,SAAS,YAAY,GACvB,GAAG,MAAM,IAAI,MAAM,EAAE,GACrB,KAAK,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CapabilityId } from '@microverse.ts/runtime-capabilities';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { HostFnContext, HostSurfaceMethodEntry } from './hostSurfaceTypes.js';
|
|
4
|
+
/**
|
|
5
|
+
* Consumer-facing method definition for the fluent {@link SurfaceBuilder} API.
|
|
6
|
+
* Use `requires: 'domain:action'` for the capability id.
|
|
7
|
+
*/
|
|
8
|
+
export type SurfaceMethodDef<THost, TIn, TOut, TCap extends `${string}:${string}` = `${string}:${string}`> = {
|
|
9
|
+
/** Capability id required to invoke this method (`domain:action`). */
|
|
10
|
+
readonly requires: TCap;
|
|
11
|
+
readonly input: z.ZodType<TIn>;
|
|
12
|
+
readonly output: z.ZodType<TOut>;
|
|
13
|
+
readonly handler: (ctx: HostFnContext<THost>, input: TIn) => TOut | Promise<TOut>;
|
|
14
|
+
readonly async?: boolean | undefined;
|
|
15
|
+
readonly description?: string | undefined;
|
|
16
|
+
readonly lua?: {
|
|
17
|
+
readonly paramTypes?: Partial<Record<string, string>> | undefined;
|
|
18
|
+
readonly returns?: string | undefined;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Converts a {@link SurfaceMethodDef} into a compiled {@link HostSurfaceMethodEntry}.
|
|
23
|
+
*/
|
|
24
|
+
export declare function normalizeMethodDef<THost, TIn, TOut, const TCap extends `${string}:${string}`>(def: SurfaceMethodDef<THost, TIn, TOut, TCap>): HostSurfaceMethodEntry<THost, TIn, TOut, CapabilityId & TCap>;
|
|
25
|
+
//# sourceMappingURL=surfaceMethodDef.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surfaceMethodDef.d.ts","sourceRoot":"","sources":["../../src/domain/surfaceMethodDef.ts"],"names":[],"mappings":"AAAA,OA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,IAAI,EAAE,IAAI,CAAC,GAC5C,sBAAsB,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC,CAW/D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Registers a nominal LuaCATS name for a Zod schema. {@link zodToLuaTypeRef} emits the name;
|
|
4
|
+
* `.d.lua` generation adds a matching `---@alias` with the structural shape.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* export const orderDto = luaType('OrderDto', z.object({ id: z.string() }));
|
|
9
|
+
* // bridge: output: orderDto.optional() → returns `OrderDto|nil` in manifest
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function luaType<T extends z.ZodTypeAny>(name: string, schema: T): T;
|
|
13
|
+
/** @internal Root schema that carries a {@link luaType} registration (after unwrapping optional/nullable/…). */
|
|
14
|
+
export declare function getLuaTypeRegistrationRoot(schema: z.ZodTypeAny): z.ZodTypeAny | undefined;
|
|
15
|
+
/** @internal Nominal LuaCATS name for this schema, if registered via {@link luaType}. */
|
|
16
|
+
export declare function resolveZodLuaTypeAlias(schema: z.ZodTypeAny): string | undefined;
|
|
17
|
+
export declare function getRegisteredLuaTypeName(root: z.ZodTypeAny): string | undefined;
|
|
18
|
+
//# sourceMappingURL=zodLuaType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zodLuaType.d.ts","sourceRoot":"","sources":["../../src/domain/zodLuaType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAM1E;AAED,gHAAgH;AAChH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,GAAG,SAAS,CAazF;AAED,yFAAyF;AACzF,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,MAAM,GAAG,SAAS,CAG/E;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,CAAC,CAAC,UAAU,GAAG,MAAM,GAAG,SAAS,CAE/E"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export type ZodToLuaTypeRefOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* When `false`, expands {@link luaType} registrations to structural shapes (for `---@alias` bodies).
|
|
5
|
+
* Default `true` emits registered nominal names at use sites.
|
|
6
|
+
*/
|
|
7
|
+
readonly emitAliasNames?: boolean | undefined;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Maps a Zod schema to a LuaCATS type reference string for manifest emission.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Register nominal types with {@link luaType} on shared Zod schemas (e.g. `orderDto`, `orderId`).
|
|
14
|
+
* Prefer that over per-method `lua.paramTypes` / `lua.returns` escape hatches on bridge methods.
|
|
15
|
+
*/
|
|
16
|
+
export declare function zodToLuaTypeRef(schema: z.ZodTypeAny, options?: ZodToLuaTypeRefOptions): string;
|
|
17
|
+
//# sourceMappingURL=zodToLuaTypeRef.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zodToLuaTypeRef.d.ts","sourceRoot":"","sources":["../../src/domain/zodToLuaTypeRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC/C,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM,CA0G9F"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declarative **host surface** for Lua sandboxes: Zod-validated bridge methods, capability checks,
|
|
3
|
+
* `LuaDefManifest` generation for `.d.lua`, and {@link HostScriptSession} helpers.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
export { buildBridgeMergeEnvForHost, } from './infrastructure/builders/bridgeMergeEnv.js';
|
|
8
|
+
export { BridgeBuilder, defineHostSurface, defineHostSurfaceFor, SurfaceBuilder, type AnyHostSurfaceMethod, type HostFnContext, type HostSurface, type HostSurfaceCore, type HostSurfaceMethodEntry, type HostSurfaceSpec, type HostSurfaceSpecForHost, type HostWorkflowHooksSpec, type LuaDefManifestGeneratorOpts, type SurfaceMethodDef, } from './infrastructure/builders/defineHostSurfaceFacade.js';
|
|
9
|
+
export { compileHostSurface, compileHostSurfaceFor, } from './application/useCases/compileHostSurface.js';
|
|
10
|
+
export { createBridgeDeclarationsFromHostSurfaceSpec } from './application/useCases/compileBridgeDeclarationsFromHostSurfaceSpec.js';
|
|
11
|
+
export type { SchemaValidationPort } from './application/ports/SchemaValidationPort.js';
|
|
12
|
+
export { HostScriptSession, type HostScriptSessionOptions, type WorkflowHookInvokeArgs, } from './infrastructure/components/hostScriptSession.js';
|
|
13
|
+
export { luaGlobalHookName, type LuaGlobalHookName } from './domain/luaGlobalHook.js';
|
|
14
|
+
export { luaType } from './domain/zodLuaType.js';
|
|
15
|
+
export { zodToLuaTypeRef, type ZodToLuaTypeRefOptions } from './domain/zodToLuaTypeRef.js';
|
|
16
|
+
export { MICROVERSE_CAPABILITY_REGISTRY, type WithMicroverseCapabilityRegistry } from './domain/capabilityRegistrySymbol.js';
|
|
17
|
+
export { augmentHostWithCapabilityRegistry } from './infrastructure/adapters/augmentHostWithCapabilityRegistry.js';
|
|
18
|
+
export type { InferSurfaceCapabilities } from './domain/surfaceCapabilities.js';
|
|
19
|
+
export type { SurfaceCapabilityString } from './domain/surfaceCapabilityString.js';
|
|
20
|
+
export { collectCapabilitiesFromHostSurfaceSpec, pickSurfaceCapabilities } from './domain/surfaceCapabilities.js';
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,0BAA0B,GAC3B,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,gBAAgB,GACtB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,2CAA2C,EAAE,MAAM,wEAAwE,CAAC;AACrI,YAAY,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,GAC5B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACtF,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAC3F,OAAO,EAAE,8BAA8B,EAAE,KAAK,gCAAgC,EAAE,MAAM,sCAAsC,CAAC;AAC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