@microverse.ts/microverse-lua 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 +97 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +131 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/facade/luaMicroverse.d.ts +86 -0
- package/dist/infrastructure/facade/luaMicroverse.d.ts.map +1 -0
- package/dist/infrastructure/facade/microverseLuaNamespace.d.ts +22 -0
- package/dist/infrastructure/facade/microverseLuaNamespace.d.ts.map +1 -0
- package/package.json +54 -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,97 @@
|
|
|
1
|
+
# `@microverse.ts/microverse-lua`
|
|
2
|
+
|
|
3
|
+
**Lua microverse** facade for TypeScript applications: `MicroverseLua.create`, Wasm VM, script slots, and the fluent host surface builder.
|
|
4
|
+
|
|
5
|
+
Monorepo overview: [root README](../../README.md).
|
|
6
|
+
|
|
7
|
+
## What is a Lua microverse?
|
|
8
|
+
|
|
9
|
+
One logical scripting universe in your process:
|
|
10
|
+
|
|
11
|
+
- **One** Wasm-backed Lua VM (Wasmoon), shared for efficiency.
|
|
12
|
+
- **Many** isolated **environment slots** — one per registered script.
|
|
13
|
+
- **One** host **surface** (declarative bridges + optional workflow hooks).
|
|
14
|
+
- **One** host **object** (your TypeScript services).
|
|
15
|
+
- **Per-script capability allowlists** at registration.
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
19
|
+
│ LuaMicroverse (MicroverseLua.create) │
|
|
20
|
+
│ ┌───────────────────────────────────────────────────────┐ │
|
|
21
|
+
│ │ Shared Wasm Lua VM │ │
|
|
22
|
+
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
|
|
23
|
+
│ │ │ slot: a │ │ slot: b │ │ slot: c │ │ │
|
|
24
|
+
│ │ │ caps: […] │ │ caps: […] │ │ caps: […] │ │ │
|
|
25
|
+
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
|
|
26
|
+
│ └───────────────────────────────────────────────────────┘ │
|
|
27
|
+
│ ▲ bridges from host surface + host services │
|
|
28
|
+
└─────────────────────────────────────────────────────────────┘
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pnpm add @microverse.ts/microverse-lua
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Workspace: `"@microverse.ts/microverse-lua": "workspace:*"`.
|
|
38
|
+
|
|
39
|
+
## Quick start
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { MicroverseLua, defineHostSurfaceFor } from '@microverse.ts/microverse-lua';
|
|
43
|
+
import { z } from 'zod';
|
|
44
|
+
|
|
45
|
+
type MyHost = { appName: string };
|
|
46
|
+
|
|
47
|
+
const surface = defineHostSurfaceFor<MyHost>()
|
|
48
|
+
.bridge('greet')
|
|
49
|
+
.method('hello', {
|
|
50
|
+
requires: 'demo:greet',
|
|
51
|
+
input: z.object({ name: z.string() }),
|
|
52
|
+
output: z.string(),
|
|
53
|
+
handler: ({ host }, { name }) => `Hello, ${name} from ${host.appName}`,
|
|
54
|
+
})
|
|
55
|
+
.build();
|
|
56
|
+
|
|
57
|
+
const microverse = MicroverseLua.create({
|
|
58
|
+
host: { appName: 'Acme' },
|
|
59
|
+
surface,
|
|
60
|
+
defaultTimeoutMs: 30_000,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await microverse.registerScript({
|
|
64
|
+
scriptId: 'welcome',
|
|
65
|
+
script: `local msg = greet:hello({ name = "world" })`,
|
|
66
|
+
capabilities: surface.pickCapabilities('demo:greet'),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
await microverse.dispose();
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## API
|
|
73
|
+
|
|
74
|
+
| Export | Purpose |
|
|
75
|
+
|--------|---------|
|
|
76
|
+
| `MicroverseLua.create` | Create a Lua microverse (Wasm VM included). |
|
|
77
|
+
| `registerScript` | New slot + optional preludes + main chunk. |
|
|
78
|
+
| `emitToAllScripts` | Call `on{Kind}` on every script (workflow hooks). |
|
|
79
|
+
| `defineHostSurfaceFor`, `defineHostSurface` | Fluent surface builder (`bridge` → `method` → `build`). |
|
|
80
|
+
|
|
81
|
+
## IDE stubs
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pnpm add -D @microverse.ts/cli
|
|
85
|
+
pnpm exec microverse generate-lua-defs --surface src/mySurface.ts
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Requires `export default` on the surface module (typically the result of `.build()`). Details: [`@microverse.ts/cli`](../cli/README.md).
|
|
89
|
+
|
|
90
|
+
## Reference example
|
|
91
|
+
|
|
92
|
+
[`examples/business-scripting-engine`](../../examples/business-scripting-engine) — rules engine with orders, billing, workflow Lua, and `BusinessScriptingEngine` wrapping this package.
|
|
93
|
+
|
|
94
|
+
## Related
|
|
95
|
+
|
|
96
|
+
- Async bridges: [`host-surface/docs/async-subroutines-components.md`](../host-surface/docs/async-subroutines-components.md)
|
|
97
|
+
- Component-style Lua: [`examples/.../COMPONENT_PATTERN.md`](../../examples/business-scripting-engine/docs/COMPONENT_PATTERN.md)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **@microverse.ts/microverse-lua** — Lua microverse entry for consuming applications.
|
|
3
|
+
*
|
|
4
|
+
* Plug-and-play Lua scripting: **{@link MicroverseLua.create}** (built-in Wasm VM) and the fluent
|
|
5
|
+
* **{@link defineHostSurfaceFor}** builder (`bridge` → `method` → `build`).
|
|
6
|
+
*/
|
|
7
|
+
export { augmentHostWithCapabilityRegistry, BridgeBuilder, buildBridgeMergeEnvForHost, collectCapabilitiesFromHostSurfaceSpec, compileHostSurface, compileHostSurfaceFor, createBridgeDeclarationsFromHostSurfaceSpec, defineHostSurface, defineHostSurfaceFor, HostScriptSession, luaGlobalHookName, luaType, MICROVERSE_CAPABILITY_REGISTRY, pickSurfaceCapabilities, SurfaceBuilder, zodToLuaTypeRef, type AnyHostSurfaceMethod, type HostFnContext, type HostScriptSessionOptions, type HostSurface, type HostSurfaceCore, type HostSurfaceMethodEntry, type HostSurfaceSpec, type HostSurfaceSpecForHost, type HostWorkflowHooksSpec, type InferSurfaceCapabilities, type LuaDefManifestGeneratorOpts, type LuaGlobalHookName, type SchemaValidationPort, type SurfaceCapabilityString, type SurfaceMethodDef, type WithMicroverseCapabilityRegistry, type WorkflowHookInvokeArgs, type ZodToLuaTypeRefOptions, } from '@microverse.ts/host-surface';
|
|
8
|
+
export * from '@microverse.ts/shared';
|
|
9
|
+
export * from '@microverse.ts/runtime-core';
|
|
10
|
+
export * from '@microverse.ts/runtime-lua';
|
|
11
|
+
export * from '@microverse.ts/runtime-wasm';
|
|
12
|
+
export * from '@microverse.ts/runtime-bridge';
|
|
13
|
+
export * from '@microverse.ts/runtime-capabilities';
|
|
14
|
+
export * from '@microverse.ts/runtime-zod';
|
|
15
|
+
export { MicroverseLua } from './infrastructure/facade/microverseLuaNamespace.js';
|
|
16
|
+
export { createLuaMicroverse, LuaMicroverse, type LuaMicroverseConfig, type InferScriptHooksFromHost, type InferScriptHooksFromSurface, type InferSurfaceCapabilitiesFromSurface, type TaggedLuaMicroverseHost, } from './infrastructure/facade/luaMicroverse.js';
|
|
17
|
+
//# 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,iCAAiC,EACjC,aAAa,EACb,0BAA0B,EAC1B,sCAAsC,EACtC,kBAAkB,EAClB,qBAAqB,EACrB,2CAA2C,EAC3C,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,OAAO,EACP,8BAA8B,EAC9B,uBAAuB,EACvB,cAAc,EACd,eAAe,EACf,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,wBAAwB,EAC7B,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,gCAAgC,EACrC,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,GAC5B,MAAM,6BAA6B,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,4BAA4B,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAClF,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,mCAAmC,EACxC,KAAK,uBAAuB,GAC7B,MAAM,0CAA0C,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { BridgeBuilder, HostScriptSession, HostScriptSession as HostScriptSession$1, MICROVERSE_CAPABILITY_REGISTRY, SurfaceBuilder, augmentHostWithCapabilityRegistry, buildBridgeMergeEnvForHost, collectCapabilitiesFromHostSurfaceSpec, compileHostSurface, compileHostSurfaceFor, createBridgeDeclarationsFromHostSurfaceSpec, defineHostSurface, defineHostSurfaceFor, luaGlobalHookName, luaGlobalHookName as luaGlobalHookName$1, luaType, pickSurfaceCapabilities, zodToLuaTypeRef } from "@microverse.ts/host-surface";
|
|
2
|
+
import { createLuaEnvSlotKey, fixedTimeout } from "@microverse.ts/runtime-core";
|
|
3
|
+
import { createWasmMicroverseRuntime } from "@microverse.ts/runtime-wasm";
|
|
4
|
+
export * from "@microverse.ts/shared";
|
|
5
|
+
export * from "@microverse.ts/runtime-core";
|
|
6
|
+
export * from "@microverse.ts/runtime-lua";
|
|
7
|
+
export * from "@microverse.ts/runtime-wasm";
|
|
8
|
+
export * from "@microverse.ts/runtime-bridge";
|
|
9
|
+
export * from "@microverse.ts/runtime-capabilities";
|
|
10
|
+
export * from "@microverse.ts/runtime-zod";
|
|
11
|
+
//#region src/infrastructure/facade/luaMicroverse.ts
|
|
12
|
+
function resolveDefaultTimeout(config) {
|
|
13
|
+
if (config.defaultTimeout !== void 0) return config.defaultTimeout;
|
|
14
|
+
if (config.defaultTimeoutMs !== void 0) return fixedTimeout(config.defaultTimeoutMs);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* One **Lua microverse**: a shared built-in Wasm Lua VM, {@link HostScriptSession}s keyed by `scriptId`, and helpers to
|
|
18
|
+
* register scripts and broadcast hook events. Capabilities per script come from the host surface
|
|
19
|
+
* ({@link HostSurfaceCore.pickCapabilities} / {@link HostSurfaceCore.capabilities}). Created via {@link MicroverseLua.create}
|
|
20
|
+
* or {@link createLuaMicroverse}.
|
|
21
|
+
*/
|
|
22
|
+
var LuaMicroverse = class {
|
|
23
|
+
config;
|
|
24
|
+
runtime;
|
|
25
|
+
sessions = /* @__PURE__ */ new Map();
|
|
26
|
+
host;
|
|
27
|
+
surface;
|
|
28
|
+
envSlotScope;
|
|
29
|
+
defaultTimeout;
|
|
30
|
+
sharedLuaChunks;
|
|
31
|
+
constructor(config) {
|
|
32
|
+
this.config = config;
|
|
33
|
+
this.host = config.host;
|
|
34
|
+
this.surface = config.surface;
|
|
35
|
+
this.defaultTimeout = resolveDefaultTimeout(config);
|
|
36
|
+
this.sharedLuaChunks = config.sharedLuaChunks ?? [];
|
|
37
|
+
this.runtime = createWasmMicroverseRuntime(this.defaultTimeout !== void 0 ? { defaultTimeout: this.defaultTimeout } : {});
|
|
38
|
+
this.envSlotScope = config.envSlotScope ?? "script";
|
|
39
|
+
}
|
|
40
|
+
/** Capability ids declared on the bound host surface. */
|
|
41
|
+
getSurfaceCapabilities = () => this.surface.capabilities;
|
|
42
|
+
/**
|
|
43
|
+
* Loads one Lua chunk in an isolated env slot; `scriptId` must be unique within this microverse.
|
|
44
|
+
*
|
|
45
|
+
* @param args.capabilities - Subset of {@link getSurfaceCapabilities}; use `surface.pickCapabilities(…)` at the call site.
|
|
46
|
+
*/
|
|
47
|
+
registerScript = async (args) => {
|
|
48
|
+
const { scriptId, script, capabilities, injectLuaChunks } = args;
|
|
49
|
+
const preludeChunks = [...this.sharedLuaChunks, ...injectLuaChunks ?? []];
|
|
50
|
+
if (this.sessions.has(scriptId)) throw new Error(`script already registered: ${scriptId}`);
|
|
51
|
+
const session = new HostScriptSession$1({
|
|
52
|
+
runtime: this.runtime,
|
|
53
|
+
surface: this.surface,
|
|
54
|
+
host: this.host,
|
|
55
|
+
slotKey: createLuaEnvSlotKey(`${this.envSlotScope}:${scriptId}`),
|
|
56
|
+
allowedCapabilities: capabilities,
|
|
57
|
+
defaultTimeout: this.defaultTimeout
|
|
58
|
+
});
|
|
59
|
+
await session.openSession();
|
|
60
|
+
for (const [index, chunk] of preludeChunks.entries()) {
|
|
61
|
+
const injected = await session.runChunk(chunk);
|
|
62
|
+
if (injected._tag !== "ok") {
|
|
63
|
+
await session.dispose();
|
|
64
|
+
const detail = injected._tag === "err" && injected.error._tag === "AdapterError" ? injected.error.message : JSON.stringify(injected.error);
|
|
65
|
+
const which = index < this.sharedLuaChunks.length ? `shared Lua prelude [${index}]` : `script injectLuaChunks [${index - this.sharedLuaChunks.length}]`;
|
|
66
|
+
throw new Error(`script "${scriptId}" failed injecting ${which}: ${detail}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const loaded = await session.runChunk(script);
|
|
70
|
+
if (loaded._tag !== "ok") {
|
|
71
|
+
await session.dispose();
|
|
72
|
+
const detail = loaded._tag === "err" && loaded.error._tag === "AdapterError" ? loaded.error.message : JSON.stringify(loaded.error);
|
|
73
|
+
throw new Error(`script "${scriptId}" failed to load: ${detail}`);
|
|
74
|
+
}
|
|
75
|
+
this.sessions.set(scriptId, session);
|
|
76
|
+
};
|
|
77
|
+
/** Invokes `on{Kind}` on every registered script with the same payload table (Lua literals only). */
|
|
78
|
+
emitToAllScripts = (async (kind, payload) => {
|
|
79
|
+
const hook = luaGlobalHookName$1(kind);
|
|
80
|
+
for (const [id, session] of this.sessions) {
|
|
81
|
+
const r = await session.invokeGlobalHookIfPresent(hook, payload);
|
|
82
|
+
if (r._tag !== "ok") {
|
|
83
|
+
const detail = r._tag === "err" && r.error._tag === "AdapterError" ? r.error.message : JSON.stringify(r.error);
|
|
84
|
+
throw new Error(`script "${id}" failed on emit: ${detail}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
dispose = async () => {
|
|
89
|
+
for (const s of this.sessions.values()) await s.dispose();
|
|
90
|
+
this.sessions.clear();
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Creates a {@link LuaMicroverse} with a **built-in** Wasm Lua VM (Wasmoon). Type `host` with
|
|
95
|
+
* {@link TaggedLuaMicroverseHost} so hook emits narrow correctly.
|
|
96
|
+
*/
|
|
97
|
+
function createLuaMicroverse(config) {
|
|
98
|
+
return new LuaMicroverse({
|
|
99
|
+
host: config.host,
|
|
100
|
+
surface: config.surface,
|
|
101
|
+
envSlotScope: config.envSlotScope,
|
|
102
|
+
defaultTimeout: config.defaultTimeout,
|
|
103
|
+
defaultTimeoutMs: config.defaultTimeoutMs,
|
|
104
|
+
sharedLuaChunks: config.sharedLuaChunks
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/infrastructure/facade/microverseLuaNamespace.ts
|
|
109
|
+
/**
|
|
110
|
+
* Plug-and-play **Lua microverse** entry point.
|
|
111
|
+
*
|
|
112
|
+
* A Wasmoon-backed VM is always created for you — pass only `host`, `surface`, and optional timeouts /
|
|
113
|
+
* shared Lua preludes. Define bridges with {@link defineHostSurfaceFor} (`bridge` → `method` → `build`).
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const microverse = MicroverseLua.create({
|
|
118
|
+
* host: myHost,
|
|
119
|
+
* surface: mySurface,
|
|
120
|
+
* defaultTimeoutMs: 30_000,
|
|
121
|
+
* });
|
|
122
|
+
* await microverse.registerScript({ scriptId: 'ai', script: lua, capabilities: surface.pickCapabilities('demo:tick') });
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
var MicroverseLua = {
|
|
126
|
+
/** Creates a {@link LuaMicroverse} with a built-in Wasm Lua runtime. */
|
|
127
|
+
create: createLuaMicroverse };
|
|
128
|
+
//#endregion
|
|
129
|
+
export { BridgeBuilder, HostScriptSession, LuaMicroverse, MICROVERSE_CAPABILITY_REGISTRY, MicroverseLua, SurfaceBuilder, augmentHostWithCapabilityRegistry, buildBridgeMergeEnvForHost, collectCapabilitiesFromHostSurfaceSpec, compileHostSurface, compileHostSurfaceFor, createBridgeDeclarationsFromHostSurfaceSpec, createLuaMicroverse, defineHostSurface, defineHostSurfaceFor, luaGlobalHookName, luaType, pickSurfaceCapabilities, zodToLuaTypeRef };
|
|
130
|
+
|
|
131
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/infrastructure/facade/luaMicroverse.ts","../src/infrastructure/facade/microverseLuaNamespace.ts"],"sourcesContent":["import type { z } from 'zod';\n\nimport {\n HostScriptSession,\n luaGlobalHookName,\n type HostSurface,\n type HostSurfaceCore,\n type HostWorkflowHooksSpec,\n} from '@microverse.ts/host-surface';\nimport type { CapabilityId } from '@microverse.ts/runtime-capabilities';\nimport {\n createLuaEnvSlotKey,\n fixedTimeout,\n type MicroverseRuntime,\n type TimeoutPolicy,\n} from '@microverse.ts/runtime-core';\nimport { createWasmMicroverseRuntime } from '@microverse.ts/runtime-wasm';\n\n/** Phantom key: optional on the host **type** so {@link InferScriptHooksFromHost} can recover hook Zod map typing. Never set at runtime. */\ndeclare const SCRIPT_HOOKS_TYPE: unique symbol;\n\n/**\n * Intersects `TBase` with an optional phantom field carrying `THooks` for {@link LuaMicroverse} / {@link createLuaMicroverse} inference.\n */\nexport type TaggedLuaMicroverseHost<\n THooks extends HostWorkflowHooksSpec,\n TBase = unknown,\n> = TBase & { readonly [SCRIPT_HOOKS_TYPE]?: THooks };\n\nexport type InferScriptHooksFromHost<THost> = THost extends TaggedLuaMicroverseHost<infer H, unknown>\n ? H extends HostWorkflowHooksSpec\n ? H\n : undefined\n : undefined;\n\nexport type InferScriptHooksFromSurface<S extends HostSurfaceCore> =\n S extends HostSurfaceCore<CapabilityId> & { readonly workflowHooks: infer H extends HostWorkflowHooksSpec }\n ? H\n : S extends HostSurface<infer H extends HostWorkflowHooksSpec, CapabilityId>\n ? H\n : undefined;\n\nexport type InferSurfaceCapabilitiesFromSurface<S extends HostSurfaceCore> = S extends HostSurfaceCore<\n infer C extends CapabilityId\n>\n ? C\n : CapabilityId;\n\ntype EffectiveScriptHooks<THost extends object, TSurface extends HostSurfaceCore> = [InferScriptHooksFromHost<THost>] extends [\n undefined,\n]\n ? InferScriptHooksFromSurface<TSurface>\n : InferScriptHooksFromHost<THost>;\n\nexport type LuaMicroverseConfig<\n THost extends object = object,\n THooks extends HostWorkflowHooksSpec | undefined = InferScriptHooksFromHost<THost>,\n TCapabilities extends CapabilityId = CapabilityId,\n> = {\n readonly host: THost;\n /** From {@link defineHostSurface} / {@link defineHostSurfaceFor}; hooks live on `surface.workflowHooks` when present. */\n readonly surface: HostSurface<THooks, TCapabilities>;\n /** Prefix for internal Lua env slot ids, default `script` (ids look like `script:my-id`). */\n readonly envSlotScope?: string | undefined;\n /** Wall-clock limit per `runChunk` / hook invocation (Wasm adapter + session forwarding). */\n readonly defaultTimeout?: TimeoutPolicy | undefined;\n /**\n * Shorthand for {@link defaultTimeout} as `fixedTimeout(ms)`. Ignored when `defaultTimeout` is set.\n */\n readonly defaultTimeoutMs?: number | undefined;\n /**\n * Lua sources run in **every** script slot after {@link HostScriptSession.openSession} and before that\n * script's main chunk. Define shared helpers/libraries here once instead of per {@link registerScript}.\n */\n readonly sharedLuaChunks?: readonly string[] | undefined;\n};\n\nfunction resolveDefaultTimeout<\n THost extends object,\n THooks extends HostWorkflowHooksSpec | undefined,\n TCapabilities extends CapabilityId,\n>(config: LuaMicroverseConfig<THost, THooks, TCapabilities>): TimeoutPolicy | undefined {\n if (config.defaultTimeout !== undefined) {\n return config.defaultTimeout;\n }\n if (config.defaultTimeoutMs !== undefined) {\n return fixedTimeout(config.defaultTimeoutMs);\n }\n return undefined;\n}\n\ntype EmitToAllScriptsFn<THooks extends HostWorkflowHooksSpec | undefined> = THooks extends HostWorkflowHooksSpec\n ? <const K extends keyof THooks & string>(kind: K, payload: Readonly<z.infer<THooks[K]>>) => Promise<void>\n : (\n kind: string,\n payload: Readonly<Record<string, string | number | boolean>>,\n ) => Promise<void>;\n\n/**\n * One **Lua microverse**: a shared built-in Wasm Lua VM, {@link HostScriptSession}s keyed by `scriptId`, and helpers to\n * register scripts and broadcast hook events. Capabilities per script come from the host surface\n * ({@link HostSurfaceCore.pickCapabilities} / {@link HostSurfaceCore.capabilities}). Created via {@link MicroverseLua.create}\n * or {@link createLuaMicroverse}.\n */\nexport class LuaMicroverse<\n THost extends object = object,\n THooks extends HostWorkflowHooksSpec | undefined = InferScriptHooksFromHost<THost>,\n TCapabilities extends CapabilityId = CapabilityId,\n> {\n private readonly runtime: MicroverseRuntime;\n\n private readonly sessions = new Map<string, HostScriptSession<THost, THooks>>();\n\n private readonly host: THost;\n\n private readonly surface: HostSurface<THooks, TCapabilities>;\n\n private readonly envSlotScope: string;\n\n private readonly defaultTimeout: TimeoutPolicy | undefined;\n\n private readonly sharedLuaChunks: readonly string[];\n\n constructor(private readonly config: LuaMicroverseConfig<THost, THooks, TCapabilities>) {\n this.host = config.host;\n this.surface = config.surface;\n this.defaultTimeout = resolveDefaultTimeout(config);\n this.sharedLuaChunks = config.sharedLuaChunks ?? [];\n this.runtime = createWasmMicroverseRuntime(\n this.defaultTimeout !== undefined ? { defaultTimeout: this.defaultTimeout } : {},\n );\n this.envSlotScope = config.envSlotScope ?? 'script';\n }\n\n /** Capability ids declared on the bound host surface. */\n readonly getSurfaceCapabilities = (): readonly TCapabilities[] => this.surface.capabilities;\n\n /**\n * Loads one Lua chunk in an isolated env slot; `scriptId` must be unique within this microverse.\n *\n * @param args.capabilities - Subset of {@link getSurfaceCapabilities}; use `surface.pickCapabilities(…)` at the call site.\n */\n readonly registerScript = async (args: {\n readonly scriptId: string;\n readonly script: string;\n readonly capabilities: readonly TCapabilities[];\n readonly injectLuaChunks?: readonly string[] | undefined;\n }): Promise<void> => {\n const { scriptId, script, capabilities, injectLuaChunks } = args;\n const preludeChunks = [...this.sharedLuaChunks, ...(injectLuaChunks ?? [])];\n if (this.sessions.has(scriptId)) {\n throw new Error(`script already registered: ${scriptId}`);\n }\n const session = new HostScriptSession<THost, THooks>({\n runtime: this.runtime,\n surface: this.surface,\n host: this.host,\n slotKey: createLuaEnvSlotKey(`${this.envSlotScope}:${scriptId}`),\n allowedCapabilities: capabilities,\n defaultTimeout: this.defaultTimeout,\n });\n await session.openSession();\n for (const [index, chunk] of preludeChunks.entries()) {\n const injected = await session.runChunk(chunk);\n if (injected._tag !== 'ok') {\n await session.dispose();\n const detail =\n injected._tag === 'err' && injected.error._tag === 'AdapterError'\n ? injected.error.message\n : JSON.stringify(injected.error);\n const which =\n index < this.sharedLuaChunks.length\n ? `shared Lua prelude [${index}]`\n : `script injectLuaChunks [${index - this.sharedLuaChunks.length}]`;\n throw new Error(`script \"${scriptId}\" failed injecting ${which}: ${detail}`);\n }\n }\n const loaded = await session.runChunk(script);\n if (loaded._tag !== 'ok') {\n await session.dispose();\n const detail =\n loaded._tag === 'err' && loaded.error._tag === 'AdapterError'\n ? loaded.error.message\n : JSON.stringify(loaded.error);\n throw new Error(`script \"${scriptId}\" failed to load: ${detail}`);\n }\n this.sessions.set(scriptId, session);\n };\n\n /** Invokes `on{Kind}` on every registered script with the same payload table (Lua literals only). */\n readonly emitToAllScripts = (async (\n kind: string,\n payload: Readonly<Record<string, string | number | boolean>>,\n ) => {\n const hook = luaGlobalHookName(kind);\n for (const [id, session] of this.sessions) {\n const r = await session.invokeGlobalHookIfPresent(hook, payload);\n if (r._tag !== 'ok') {\n const detail =\n r._tag === 'err' && r.error._tag === 'AdapterError' ? r.error.message : JSON.stringify(r.error);\n throw new Error(`script \"${id}\" failed on emit: ${detail}`);\n }\n }\n }) as EmitToAllScriptsFn<THooks>;\n\n readonly dispose = async (): Promise<void> => {\n for (const s of this.sessions.values()) {\n await s.dispose();\n }\n this.sessions.clear();\n };\n}\n\n/**\n * Creates a {@link LuaMicroverse} with a **built-in** Wasm Lua VM (Wasmoon). Type `host` with\n * {@link TaggedLuaMicroverseHost} so hook emits narrow correctly.\n */\nexport function createLuaMicroverse<\n THost extends object,\n const TSurface extends HostSurfaceCore<CapabilityId>,\n>(config: {\n readonly host: THost;\n readonly surface: TSurface;\n readonly envSlotScope?: string | undefined;\n readonly defaultTimeout?: TimeoutPolicy | undefined;\n readonly defaultTimeoutMs?: number | undefined;\n readonly sharedLuaChunks?: readonly string[] | undefined;\n}): LuaMicroverse<THost, EffectiveScriptHooks<THost, TSurface>, InferSurfaceCapabilitiesFromSurface<TSurface>> {\n type H = EffectiveScriptHooks<THost, TSurface>;\n type C = InferSurfaceCapabilitiesFromSurface<TSurface>;\n return new LuaMicroverse<THost, H, C>({\n host: config.host,\n surface: config.surface as unknown as HostSurface<H, C>,\n envSlotScope: config.envSlotScope,\n defaultTimeout: config.defaultTimeout,\n defaultTimeoutMs: config.defaultTimeoutMs,\n sharedLuaChunks: config.sharedLuaChunks,\n });\n}\n","import { createLuaMicroverse } from './luaMicroverse.js';\n\n/**\n * Plug-and-play **Lua microverse** entry point.\n *\n * A Wasmoon-backed VM is always created for you — pass only `host`, `surface`, and optional timeouts /\n * shared Lua preludes. Define bridges with {@link defineHostSurfaceFor} (`bridge` → `method` → `build`).\n *\n * @example\n * ```ts\n * const microverse = MicroverseLua.create({\n * host: myHost,\n * surface: mySurface,\n * defaultTimeoutMs: 30_000,\n * });\n * await microverse.registerScript({ scriptId: 'ai', script: lua, capabilities: surface.pickCapabilities('demo:tick') });\n * ```\n */\nexport const MicroverseLua = {\n /** Creates a {@link LuaMicroverse} with a built-in Wasm Lua runtime. */\n create: createLuaMicroverse,\n} as const;\n"],"mappings":";;;;;;;;;;;AA6EA,SAAS,sBAIP,QAAsF;CACtF,IAAI,OAAO,mBAAmB,KAAA,GAC5B,OAAO,OAAO;CAEhB,IAAI,OAAO,qBAAqB,KAAA,GAC9B,OAAO,aAAa,OAAO,gBAAgB;AAG/C;;;;;;;AAeA,IAAa,gBAAb,MAIE;CAe6B;CAd7B;CAEA,2BAA4B,IAAI,IAA8C;CAE9E;CAEA;CAEA;CAEA;CAEA;CAEA,YAAY,QAA4E;EAA3D,KAAA,SAAA;EAC3B,KAAK,OAAO,OAAO;EACnB,KAAK,UAAU,OAAO;EACtB,KAAK,iBAAiB,sBAAsB,MAAM;EAClD,KAAK,kBAAkB,OAAO,mBAAmB,CAAC;EAClD,KAAK,UAAU,4BACb,KAAK,mBAAmB,KAAA,IAAY,EAAE,gBAAgB,KAAK,eAAe,IAAI,CAAC,CACjF;EACA,KAAK,eAAe,OAAO,gBAAgB;CAC7C;;CAGA,+BAAkE,KAAK,QAAQ;;;;;;CAO/E,iBAA0B,OAAO,SAKZ;EACnB,MAAM,EAAE,UAAU,QAAQ,cAAc,oBAAoB;EAC5D,MAAM,gBAAgB,CAAC,GAAG,KAAK,iBAAiB,GAAI,mBAAmB,CAAC,CAAE;EAC1E,IAAI,KAAK,SAAS,IAAI,QAAQ,GAC5B,MAAM,IAAI,MAAM,8BAA8B,UAAU;EAE1D,MAAM,UAAU,IAAI,oBAAiC;GACnD,SAAS,KAAK;GACd,SAAS,KAAK;GACd,MAAM,KAAK;GACX,SAAS,oBAAoB,GAAG,KAAK,aAAa,GAAG,UAAU;GAC/D,qBAAqB;GACrB,gBAAgB,KAAK;EACvB,CAAC;EACD,MAAM,QAAQ,YAAY;EAC1B,KAAK,MAAM,CAAC,OAAO,UAA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;CAG7G,OAAO,IAAI,cAA2B;EACpC,MAAM,OAAO;EACb,SAAS,OAAO;EAChB,cAAc,OAAO;EACrB,gBAAgB,OAAO;EACvB,kBAAkB,OAAO;EACzB,iBAAiB,OAAO;CAC1B,CAAC;AACH;;;;;;;;;;;;;;;;;;;AC5NA,IAAa,gBAAgB;;AAE3B,QAAQ,oBACV"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { HostSurface, HostSurfaceCore, HostWorkflowHooksSpec } from '@microverse.ts/host-surface';
|
|
3
|
+
import { CapabilityId } from '@microverse.ts/runtime-capabilities';
|
|
4
|
+
import { TimeoutPolicy } from '@microverse.ts/runtime-core';
|
|
5
|
+
/** Phantom key: optional on the host **type** so {@link InferScriptHooksFromHost} can recover hook Zod map typing. Never set at runtime. */
|
|
6
|
+
declare const SCRIPT_HOOKS_TYPE: unique symbol;
|
|
7
|
+
/**
|
|
8
|
+
* Intersects `TBase` with an optional phantom field carrying `THooks` for {@link LuaMicroverse} / {@link createLuaMicroverse} inference.
|
|
9
|
+
*/
|
|
10
|
+
export type TaggedLuaMicroverseHost<THooks extends HostWorkflowHooksSpec, TBase = unknown> = TBase & {
|
|
11
|
+
readonly [SCRIPT_HOOKS_TYPE]?: THooks;
|
|
12
|
+
};
|
|
13
|
+
export type InferScriptHooksFromHost<THost> = THost extends TaggedLuaMicroverseHost<infer H, unknown> ? H extends HostWorkflowHooksSpec ? H : undefined : undefined;
|
|
14
|
+
export type InferScriptHooksFromSurface<S extends HostSurfaceCore> = S extends HostSurfaceCore<CapabilityId> & {
|
|
15
|
+
readonly workflowHooks: infer H extends HostWorkflowHooksSpec;
|
|
16
|
+
} ? H : S extends HostSurface<infer H extends HostWorkflowHooksSpec, CapabilityId> ? H : undefined;
|
|
17
|
+
export type InferSurfaceCapabilitiesFromSurface<S extends HostSurfaceCore> = S extends HostSurfaceCore<infer C extends CapabilityId> ? C : CapabilityId;
|
|
18
|
+
type EffectiveScriptHooks<THost extends object, TSurface extends HostSurfaceCore> = [InferScriptHooksFromHost<THost>] extends [
|
|
19
|
+
undefined
|
|
20
|
+
] ? InferScriptHooksFromSurface<TSurface> : InferScriptHooksFromHost<THost>;
|
|
21
|
+
export type LuaMicroverseConfig<THost extends object = object, THooks extends HostWorkflowHooksSpec | undefined = InferScriptHooksFromHost<THost>, TCapabilities extends CapabilityId = CapabilityId> = {
|
|
22
|
+
readonly host: THost;
|
|
23
|
+
/** From {@link defineHostSurface} / {@link defineHostSurfaceFor}; hooks live on `surface.workflowHooks` when present. */
|
|
24
|
+
readonly surface: HostSurface<THooks, TCapabilities>;
|
|
25
|
+
/** Prefix for internal Lua env slot ids, default `script` (ids look like `script:my-id`). */
|
|
26
|
+
readonly envSlotScope?: string | undefined;
|
|
27
|
+
/** Wall-clock limit per `runChunk` / hook invocation (Wasm adapter + session forwarding). */
|
|
28
|
+
readonly defaultTimeout?: TimeoutPolicy | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Shorthand for {@link defaultTimeout} as `fixedTimeout(ms)`. Ignored when `defaultTimeout` is set.
|
|
31
|
+
*/
|
|
32
|
+
readonly defaultTimeoutMs?: number | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Lua sources run in **every** script slot after {@link HostScriptSession.openSession} and before that
|
|
35
|
+
* script's main chunk. Define shared helpers/libraries here once instead of per {@link registerScript}.
|
|
36
|
+
*/
|
|
37
|
+
readonly sharedLuaChunks?: readonly string[] | undefined;
|
|
38
|
+
};
|
|
39
|
+
type EmitToAllScriptsFn<THooks extends HostWorkflowHooksSpec | undefined> = THooks extends HostWorkflowHooksSpec ? <const K extends keyof THooks & string>(kind: K, payload: Readonly<z.infer<THooks[K]>>) => Promise<void> : (kind: string, payload: Readonly<Record<string, string | number | boolean>>) => Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* One **Lua microverse**: a shared built-in Wasm Lua VM, {@link HostScriptSession}s keyed by `scriptId`, and helpers to
|
|
42
|
+
* register scripts and broadcast hook events. Capabilities per script come from the host surface
|
|
43
|
+
* ({@link HostSurfaceCore.pickCapabilities} / {@link HostSurfaceCore.capabilities}). Created via {@link MicroverseLua.create}
|
|
44
|
+
* or {@link createLuaMicroverse}.
|
|
45
|
+
*/
|
|
46
|
+
export declare class LuaMicroverse<THost extends object = object, THooks extends HostWorkflowHooksSpec | undefined = InferScriptHooksFromHost<THost>, TCapabilities extends CapabilityId = CapabilityId> {
|
|
47
|
+
private readonly config;
|
|
48
|
+
private readonly runtime;
|
|
49
|
+
private readonly sessions;
|
|
50
|
+
private readonly host;
|
|
51
|
+
private readonly surface;
|
|
52
|
+
private readonly envSlotScope;
|
|
53
|
+
private readonly defaultTimeout;
|
|
54
|
+
private readonly sharedLuaChunks;
|
|
55
|
+
constructor(config: LuaMicroverseConfig<THost, THooks, TCapabilities>);
|
|
56
|
+
/** Capability ids declared on the bound host surface. */
|
|
57
|
+
readonly getSurfaceCapabilities: () => readonly TCapabilities[];
|
|
58
|
+
/**
|
|
59
|
+
* Loads one Lua chunk in an isolated env slot; `scriptId` must be unique within this microverse.
|
|
60
|
+
*
|
|
61
|
+
* @param args.capabilities - Subset of {@link getSurfaceCapabilities}; use `surface.pickCapabilities(…)` at the call site.
|
|
62
|
+
*/
|
|
63
|
+
readonly registerScript: (args: {
|
|
64
|
+
readonly scriptId: string;
|
|
65
|
+
readonly script: string;
|
|
66
|
+
readonly capabilities: readonly TCapabilities[];
|
|
67
|
+
readonly injectLuaChunks?: readonly string[] | undefined;
|
|
68
|
+
}) => Promise<void>;
|
|
69
|
+
/** Invokes `on{Kind}` on every registered script with the same payload table (Lua literals only). */
|
|
70
|
+
readonly emitToAllScripts: EmitToAllScriptsFn<THooks>;
|
|
71
|
+
readonly dispose: () => Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a {@link LuaMicroverse} with a **built-in** Wasm Lua VM (Wasmoon). Type `host` with
|
|
75
|
+
* {@link TaggedLuaMicroverseHost} so hook emits narrow correctly.
|
|
76
|
+
*/
|
|
77
|
+
export declare function createLuaMicroverse<THost extends object, const TSurface extends HostSurfaceCore<CapabilityId>>(config: {
|
|
78
|
+
readonly host: THost;
|
|
79
|
+
readonly surface: TSurface;
|
|
80
|
+
readonly envSlotScope?: string | undefined;
|
|
81
|
+
readonly defaultTimeout?: TimeoutPolicy | undefined;
|
|
82
|
+
readonly defaultTimeoutMs?: number | undefined;
|
|
83
|
+
readonly sharedLuaChunks?: readonly string[] | undefined;
|
|
84
|
+
}): LuaMicroverse<THost, EffectiveScriptHooks<THost, TSurface>, InferSurfaceCapabilitiesFromSurface<TSurface>>;
|
|
85
|
+
export {};
|
|
86
|
+
//# sourceMappingURL=luaMicroverse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"luaMicroverse.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/facade/luaMicroverse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,6BAA6B,CAAC;AAGrC,4IAA4I;AAC5I,OAAO,CAAC,MAAM,iBAAiB,EAAE,OAAO,MAAM,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,uBAAuB,CACjC,MAAM,SAAS,qBAAqB,EACpC,KAAK,GAAG,OAAO,IACb,KAAK,GAAG;IAAE,QAAQ,CAAC,CAAC,iBAAiB,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtD,MAAM,MAAM,wBAAwB,CAAC,KAAK,IAAI,KAAK,SAAS,uBAAuB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,GACjG,CAAC,SAAS,qBAAqB,GA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created for you — pass only `host`, `surface`, and optional timeouts /
|
|
6
|
+
* shared Lua preludes. Define bridges with {@link defineHostSurfaceFor} (`bridge` → `method` → `build`).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const microverse = MicroverseLua.create({
|
|
11
|
+
* host: myHost,
|
|
12
|
+
* surface: mySurface,
|
|
13
|
+
* defaultTimeoutMs: 30_000,
|
|
14
|
+
* });
|
|
15
|
+
* await microverse.registerScript({ scriptId: 'ai', script: lua, capabilities: surface.pickCapabilities('demo:tick') });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const MicroverseLua: {
|
|
19
|
+
/** Creates a {@link LuaMicroverse} with a built-in Wasm Lua runtime. */
|
|
20
|
+
readonly create: typeof createLuaMicroverse;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=microverseLuaNamespace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"microverseLuaNamespace.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/facade/microverseLuaNamespace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa;IACxB,wEAAwE;;CAEhE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@microverse.ts/microverse-lua",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"description": "Plug-and-play Lua microverse facade: Wasm VM, MicroverseLua, and re-exports for host surfaces and bridges.",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/QADRAX/Microverse.ts.git",
|
|
11
|
+
"directory": "packages/microverse-lua"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/QADRAX/Microverse.ts/issues",
|
|
14
|
+
"homepage": "https://github.com/QADRAX/Microverse.ts/tree/main/packages/microverse-lua",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public",
|
|
17
|
+
"provenance": true
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=20.10.0"
|
|
21
|
+
},
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"zod": "^3.24.0",
|
|
33
|
+
"@microverse.ts/host-surface": "0.1.0",
|
|
34
|
+
"@microverse.ts/runtime-bridge": "0.1.0",
|
|
35
|
+
"@microverse.ts/runtime-capabilities": "0.1.0",
|
|
36
|
+
"@microverse.ts/runtime-core": "0.1.0",
|
|
37
|
+
"@microverse.ts/runtime-lua": "0.1.0",
|
|
38
|
+
"@microverse.ts/runtime-wasm": "0.1.0",
|
|
39
|
+
"@microverse.ts/runtime-zod": "0.1.0",
|
|
40
|
+
"@microverse.ts/shared": "0.1.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"typescript": "^5.8.3",
|
|
44
|
+
"vite": "^8.0.0",
|
|
45
|
+
"vite-plugin-dts": "^4.5.4",
|
|
46
|
+
"vitest": "^3.1.4"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "vite build",
|
|
50
|
+
"lint": "eslint .",
|
|
51
|
+
"test": "vitest run",
|
|
52
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
53
|
+
}
|
|
54
|
+
}
|