@microverse.ts/runtime-core 0.2.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.
@@ -6,4 +6,6 @@ export type ExecutionFailure = {
6
6
  readonly _tag: 'AdapterError';
7
7
  readonly message: string;
8
8
  };
9
+ /** Human-readable detail for logging or `Error` messages. */
10
+ export declare function formatExecutionFailure(failure: ExecutionFailure): string;
9
11
  //# sourceMappingURL=ExecutionFailure.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExecutionFailure.d.ts","sourceRoot":"","sources":["../../../src/domain/runtime/ExecutionFailure.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GAC9B;IAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC"}
1
+ {"version":3,"file":"ExecutionFailure.d.ts","sourceRoot":"","sources":["../../../src/domain/runtime/ExecutionFailure.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GAC9B;IAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE,6DAA6D;AAC7D,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CASxE"}
@@ -1,14 +1,23 @@
1
1
  import { z } from 'zod';
2
2
  import { ScriptPropertyBag } from '../scriptProps/ScriptPropertyValue';
3
+ import { ScriptProfileDefInput } from './scriptProfileDef';
3
4
  export type LuaScriptSource = string | (() => string | Promise<string>);
4
5
  /** Catalog entry: what a script is, not where it runs. */
5
6
  export type LuaScriptDefinition = {
6
7
  readonly scriptId: string;
7
8
  readonly source: LuaScriptSource;
9
+ /**
10
+ * Resolved script profile id (matches a `.componentType()` / surface profile name).
11
+ * Host applies this profile at mount before props/`init`.
12
+ */
13
+ readonly profileId?: string | undefined;
14
+ /** Inline profile when not registered on the surface (advanced). */
15
+ readonly profile?: ScriptProfileDefInput | undefined;
8
16
  readonly propsSchema?: z.ZodObject<z.ZodRawShape> | undefined;
9
17
  readonly defaultProps?: ScriptPropertyBag | undefined;
10
18
  readonly description?: string | undefined;
11
19
  readonly injectLuaChunks?: readonly string[] | undefined;
12
20
  };
21
+ export declare function resolveLuaScriptProfileId(def: LuaScriptDefinition): string | undefined;
13
22
  export declare function resolveLuaScriptSource(source: LuaScriptSource): Promise<string>;
14
23
  //# sourceMappingURL=LuaScriptDefinition.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LuaScriptDefinition.d.ts","sourceRoot":"","sources":["../../../src/domain/script/LuaScriptDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAE5E,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AAExE,0DAA0D;AAC1D,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC;IAC9D,QAAQ,CAAC,YAAY,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACtD,QAAQ,CAAC,WAAW,CA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AAmB,GAAG,MAAM,GAAG,SAAS,CAEtF;AAED,wBAAsB,sBAAsB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAKrF"}
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ import { ScriptReferenceFieldSchema } from './scriptReferenceSchema';
3
+ /** Declarative script profile (catalog / mount); resolved against a host surface at runtime. */
4
+ export type ScriptProfileDefInput<TCap extends `${string}:${string}` = `${string}:${string}`> = {
5
+ readonly extends?: string | undefined;
6
+ readonly capabilities: readonly TCap[];
7
+ readonly props: z.ZodObject<z.ZodRawShape>;
8
+ readonly state?: z.ZodObject<z.ZodRawShape> | undefined;
9
+ readonly hooks?: readonly string[] | undefined;
10
+ readonly references?: ScriptReferenceFieldSchema | undefined;
11
+ };
12
+ //# sourceMappingURL=scriptProfileDef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scriptProfileDef.d.ts","sourceRoot":"","sources":["../../../src/domain/script/scriptProfileDef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAE1E,gGAAgG;AAChG,MAAM,MAAM,qBAAqB,CAC/B,IAAI,SAAS,GAAG,MAAM,IAAI,MAAM,EAAE,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,IACxD;IACF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,YAAY,EAAE,SAAS,IAAI,EAAE,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC;IACxD,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IAC/C,QAAQ,CAAC,UAAU,CAAC,EAAE,0BAA0B,GAAG,SAAS,CAAC;CAC9D,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** Reference field kinds for script property schemas (engine-agnostic). */
2
+ export type ScriptReferenceKind = 'entityRef' | 'entityRefArray' | 'entityComponentRef' | 'entityComponentRefArray';
3
+ export type ScriptReferenceFieldDef = {
4
+ readonly kind: 'entityRef';
5
+ } | {
6
+ readonly kind: 'entityRefArray';
7
+ } | {
8
+ readonly kind: 'entityComponentRef';
9
+ readonly componentType: string;
10
+ } | {
11
+ readonly kind: 'entityComponentRefArray';
12
+ readonly componentType: string;
13
+ };
14
+ /** Maps property keys to reference kinds (non-reference keys use Zod props only). */
15
+ export type ScriptReferenceFieldSchema = Readonly<Record<string, ScriptReferenceFieldDef>>;
16
+ //# sourceMappingURL=scriptReferenceSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scriptReferenceSchema.d.ts","sourceRoot":"","sources":["../../../src/domain/script/scriptReferenceSchema.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,MAAM,mBAAmB,GAC3B,WAAW,GACX,gBAAgB,GAChB,oBAAoB,GACpB,yBAAyB,CAAC;AAE9B,MAAM,MAAM,uBAAuB,GAC/B;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GAC9B;IAAE,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,GACnC;IACE,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,yBAAyB,CAAC;IACzC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC,CAAC;AAEN,qFAAqF;AACrF,MAAM,MAAM,0BAA0B,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { neverCancelledToken, type CancellationToken } from './domain/runtime/CancellationToken';
2
2
  export type { ExecutionContext } from './domain/runtime/ExecutionContext';
3
- export type { ExecutionFailure } from './domain/runtime/ExecutionFailure';
3
+ export { formatExecutionFailure, type ExecutionFailure, } from './domain/runtime/ExecutionFailure';
4
4
  export type { RuntimeAdapter } from './domain/runtime/RuntimeAdapter';
5
5
  export type { RunScriptInput } from './domain/runtime/RunScriptInput';
6
6
  export type { RunScriptResult, MicroverseScalar } from './domain/runtime/RunScriptResult';
@@ -19,8 +19,10 @@ export { IsolatedMicroverseRuntimeMap } from './infrastructure/composition/Isola
19
19
  export type { ScriptPropertyScalar, ScriptPropertyValue, ScriptPropertyBag, MutableScriptPropertyBag, } from './domain/scriptProps/ScriptPropertyValue';
20
20
  export { assertValidScriptPropertyBag, assertValidScriptPropertyValue, cloneScriptPropertyBag, cloneScriptPropertyValue, DEFAULT_SCRIPT_PROPERTY_LIMITS, type ScriptPropertyLimits, } from './domain/scriptProps/scriptPropertyLimits';
21
21
  export { applyScriptPropertyChanges, diffScriptProperties, mergeScriptPropertyBags, shallowEqualScriptPropertyValue, } from './domain/scriptProps/scriptProperties';
22
+ export type { ScriptReferenceFieldDef, ScriptReferenceFieldSchema, ScriptReferenceKind } from './domain/script/scriptReferenceSchema';
23
+ export type { ScriptProfileDefInput } from './domain/script/scriptProfileDef';
22
24
  export type { LuaScriptDefinition, LuaScriptSource } from './domain/script/LuaScriptDefinition';
23
- export { resolveLuaScriptSource } from './domain/script/LuaScriptDefinition';
25
+ export { resolveLuaScriptProfileId, resolveLuaScriptSource } from './domain/script/LuaScriptDefinition';
24
26
  export type { ScriptInstanceContext, ScriptInstanceId, ScriptAuditTags, } from './domain/script/ScriptInstanceContext';
25
27
  export { createScriptInstanceContext, createScriptInstanceId } from './domain/script/ScriptInstanceContext';
26
28
  export type { ScriptAuditEvent } from './domain/script/Script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qBAAqB,EACrB,gBAAgB,EAChB,eAAe,GAChB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC5G,YAAY,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC"}
package/dist/index.js CHANGED
@@ -2,6 +2,16 @@ import { err, ok } from "@microverse.ts/shared";
2
2
  //#region src/domain/runtime/CancellationToken.ts
3
3
  var neverCancelledToken = { isCancelled: () => false };
4
4
  //#endregion
5
+ //#region src/domain/runtime/ExecutionFailure.ts
6
+ /** Human-readable detail for logging or `Error` messages. */
7
+ function formatExecutionFailure(failure) {
8
+ switch (failure._tag) {
9
+ case "AdapterError": return failure.message;
10
+ case "Timeout": return "execution timed out";
11
+ case "Cancelled": return "execution cancelled";
12
+ }
13
+ }
14
+ //#endregion
5
15
  //#region src/domain/runtime/MicroverseInstanceId.ts
6
16
  function createMicroverseInstanceId(value) {
7
17
  return value;
@@ -234,6 +244,9 @@ function mergeScriptPropertyBags(base, override) {
234
244
  }
235
245
  //#endregion
236
246
  //#region src/domain/script/LuaScriptDefinition.ts
247
+ function resolveLuaScriptProfileId(def) {
248
+ return def.profileId;
249
+ }
237
250
  async function resolveLuaScriptSource(source) {
238
251
  if (typeof source === "string") return source;
239
252
  return source();
@@ -253,6 +266,6 @@ function createScriptInstanceContext(args) {
253
266
  };
254
267
  }
255
268
  //#endregion
256
- export { ConsoleLogger, DEFAULT_SCRIPT_PROPERTY_LIMITS, IsolatedMicroverseRuntimeMap, StubMicroverseRuntime, StubRuntimeAdapter, applyScriptPropertyChanges, assertValidScriptPropertyBag, assertValidScriptPropertyValue, cloneScriptPropertyBag, cloneScriptPropertyValue, createLuaEnvSlotKey, createMicroverseId, createMicroverseId as createSlotKey, createMicroverseInstanceId, createMicroverseScript, createScriptInstanceContext, createScriptInstanceId, createStubMicroverseRuntime, diffScriptProperties, fixedTimeout, mergeScriptPropertyBags, neverCancelledToken, noTimeout, resolveLuaScriptSource, shallowEqualScriptPropertyValue };
269
+ export { ConsoleLogger, DEFAULT_SCRIPT_PROPERTY_LIMITS, IsolatedMicroverseRuntimeMap, StubMicroverseRuntime, StubRuntimeAdapter, applyScriptPropertyChanges, assertValidScriptPropertyBag, assertValidScriptPropertyValue, cloneScriptPropertyBag, cloneScriptPropertyValue, createLuaEnvSlotKey, createMicroverseId, createMicroverseId as createSlotKey, createMicroverseInstanceId, createMicroverseScript, createScriptInstanceContext, createScriptInstanceId, createStubMicroverseRuntime, diffScriptProperties, fixedTimeout, formatExecutionFailure, mergeScriptPropertyBags, neverCancelledToken, noTimeout, resolveLuaScriptProfileId, resolveLuaScriptSource, shallowEqualScriptPropertyValue };
257
270
 
258
271
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/domain/runtime/CancellationToken.ts","../src/domain/runtime/MicroverseInstanceId.ts","../src/domain/runtime/TimeoutPolicy.ts","../src/domain/microverse/MicroverseId.ts","../src/domain/microverse/MicroverseScript.ts","../src/infrastructure/logging/ConsoleLogger.ts","../src/infrastructure/runtime/StubRuntimeAdapter.ts","../src/application/useCases/executeScript.ts","../src/infrastructure/runtime/StubMicroverseRuntime.ts","../src/infrastructure/composition/IsolatedMicroverseRuntimeMap.ts","../src/domain/scriptProps/scriptPropertyLimits.ts","../src/domain/scriptProps/scriptProperties.ts","../src/domain/script/LuaScriptDefinition.ts","../src/domain/script/ScriptInstanceContext.ts"],"sourcesContent":["export type CancellationToken = {\n readonly isCancelled: () => boolean;\n};\n\nexport const neverCancelledToken: CancellationToken = {\n isCancelled: () => false,\n};\n","/**\n * Opaque id for one **isolated** sandbox runtime instance in the host process.\n * Typical use: one id per entity, per script, or per worker — each maps to its own `MicroverseRuntime`.\n */\nexport type MicroverseInstanceId = string & { readonly __brand: 'MicroverseInstanceId' };\n\nexport function createMicroverseInstanceId(value: string): MicroverseInstanceId {\n return value as MicroverseInstanceId;\n}\n","export type TimeoutPolicy =\n | { readonly kind: 'none' }\n | { readonly kind: 'fixed'; readonly milliseconds: number };\n\nexport const noTimeout: TimeoutPolicy = { kind: 'none' };\n\nexport function fixedTimeout(milliseconds: number): TimeoutPolicy {\n return { kind: 'fixed', milliseconds };\n}\n","export type MicroverseId = string & { readonly __brand: 'MicroverseId' };\n\nexport function createMicroverseId(value: string): MicroverseId {\n return value as MicroverseId;\n}\n\n/**\n * Branded id for **one Lua environment slot** (`_ENV`) inside a shared Wasm VM — same value as {@link createMicroverseId},\n * wording aimed at host/workflow code (pairs with {@link MicroverseRuntime.createMicroverse}'s `slotKey`).\n */\nexport function createLuaEnvSlotKey(label: string): MicroverseId {\n return createMicroverseId(label);\n}\n","export type MicroverseScript = string & { readonly __brand: 'MicroverseScript' };\n\nexport function createMicroverseScript(source: string): MicroverseScript {\n return source as MicroverseScript;\n}\n","import type { LoggerPort } from '../../application/ports/LoggerPort';\n\nexport class ConsoleLogger implements LoggerPort {\n readonly info = (message: string): void => {\n const g = globalThis as typeof globalThis & {\n console?: { log: (line: string) => void };\n };\n g.console?.log(`[runtime-core] ${message}`);\n };\n}\n","import { ok, type Result } from '@microverse.ts/shared';\n\nimport type { RuntimeAdapter } from '../../domain/runtime/RuntimeAdapter';\nimport type { ExecutionContext } from '../../domain/runtime/ExecutionContext';\nimport type { ExecutionFailure } from '../../domain/runtime/ExecutionFailure';\nimport type { RunScriptResult } from '../../domain/runtime/RunScriptResult';\nimport type { RunScriptInput } from '../../domain/runtime/RunScriptInput';\n\nexport class StubRuntimeAdapter implements RuntimeAdapter {\n readonly execute = async (\n _ctx: ExecutionContext,\n input: RunScriptInput,\n ): Promise<Result<RunScriptResult, ExecutionFailure>> => {\n return ok({ output: `stub:${String(input.script)}` });\n };\n}\n","import type { AsyncUseCase } from '@microverse.ts/shared';\nimport { err, type Result } from '@microverse.ts/shared';\n\nimport type { LoggerPort } from '../ports/LoggerPort';\nimport type { RuntimeAdapterPort } from '../ports/RuntimeAdapterPort';\nimport type { ExecutionContext } from '../../domain/runtime/ExecutionContext';\nimport type { ExecutionFailure } from '../../domain/runtime/ExecutionFailure';\nimport type { RunScriptInput } from '../../domain/runtime/RunScriptInput';\nimport type { RunScriptResult } from '../../domain/runtime/RunScriptResult';\n\nexport type ExecuteScriptPorts = readonly [RuntimeAdapterPort, LoggerPort];\n\n/**\n * Port tuple order: `[RuntimeAdapterPort, LoggerPort]`.\n */\nexport const executeScript: AsyncUseCase<\n ExecuteScriptPorts,\n readonly [ExecutionContext, RunScriptInput],\n Result<RunScriptResult, ExecutionFailure>\n> = async (ports, ctx, input) => {\n const [adapter, logger] = ports;\n if (ctx.cancellation.isCancelled()) {\n return err({ _tag: 'Cancelled' });\n }\n logger.info('executeScript:start');\n const result = await adapter.execute(ctx, input);\n logger.info('executeScript:end');\n return result;\n};\n","import { executeScript } from '../../application/useCases/executeScript';\nimport type { LoggerPort } from '../../application/ports/LoggerPort';\nimport type { RuntimeAdapter } from '../../domain/runtime/RuntimeAdapter';\nimport type { RunScriptInput } from '../../domain/runtime/RunScriptInput';\nimport type { CreateMicroverseOptions, MicroverseSlot, MicroverseRuntime } from '../../domain/runtime/MicroverseRuntime';\nimport { neverCancelledToken } from '../../domain/runtime/CancellationToken';\nimport type { TimeoutPolicy } from '../../domain/runtime/TimeoutPolicy';\nimport { createMicroverseId, type MicroverseId } from '../../domain/microverse/MicroverseId';\n\nexport type StubMicroverseRuntimeDeps = {\n readonly adapter: RuntimeAdapter;\n readonly logger: LoggerPort;\n /** Applied when neither {@link RunScriptInput.timeout} nor {@link CreateMicroverseOptions.defaultTimeout} is set. */\n readonly defaultTimeout?: TimeoutPolicy | undefined;\n};\n\nexport class StubMicroverseRuntime implements MicroverseRuntime {\n private readonly usedSlotKeys = new Set<string>();\n\n constructor(private readonly deps: StubMicroverseRuntimeDeps) {}\n\n readonly createMicroverse = async (options: CreateMicroverseOptions): Promise<MicroverseSlot> => {\n const id =\n options.slotKey !== undefined ? options.slotKey : createMicroverseId(createRandomId());\n if (options.slotKey !== undefined) {\n const k = String(options.slotKey);\n if (this.usedSlotKeys.has(k)) {\n throw new Error(`duplicate slotKey: ${k}`);\n }\n this.usedSlotKeys.add(k);\n }\n return createStubMicroverseSlot({\n id,\n deps: this.deps,\n options,\n explicitSlotKey: options.slotKey !== undefined,\n usedSlotKeys: this.usedSlotKeys,\n });\n };\n}\n\nfunction createRandomId(): string {\n const g = globalThis as typeof globalThis & {\n crypto?: { randomUUID?: () => string };\n };\n if (g.crypto?.randomUUID) {\n return g.crypto.randomUUID();\n }\n return `sandbox-${Math.random().toString(16).slice(2)}`;\n}\n\nfunction createStubMicroverseSlot(input: {\n readonly id: MicroverseId;\n readonly deps: StubMicroverseRuntimeDeps;\n readonly options: CreateMicroverseOptions;\n readonly explicitSlotKey: boolean;\n readonly usedSlotKeys: Set<string>;\n}): MicroverseSlot {\n const ctx = { microverseId: input.id, cancellation: neverCancelledToken };\n return {\n id: input.id,\n run: async (runInput) => {\n const resolvedTimeout =\n runInput.timeout ?? input.options.defaultTimeout ?? input.deps.defaultTimeout;\n const inputMerged: RunScriptInput =\n resolvedTimeout !== undefined ? { ...runInput, timeout: resolvedTimeout } : { ...runInput };\n return executeScript([input.deps.adapter, input.deps.logger], ctx, inputMerged);\n },\n dispose: async () => {\n await input.deps.adapter.disposeMicroverse?.(input.id);\n if (input.explicitSlotKey) {\n input.usedSlotKeys.delete(String(input.id));\n }\n },\n };\n}\n\nexport function createStubMicroverseRuntime(deps: StubMicroverseRuntimeDeps): MicroverseRuntime {\n return new StubMicroverseRuntime(deps);\n}\n","import type { MicroverseRuntime } from '../../domain/runtime/MicroverseRuntime';\nimport type { MicroverseInstanceId } from '../../domain/runtime/MicroverseInstanceId';\n\n/**\n * Keeps many {@link MicroverseRuntime} instances keyed by {@link MicroverseInstanceId}.\n * Each entry is typically its own `MicroverseRuntime` (hence its own Wasmoon/Lua VM when using `@microverse.ts/runtime-wasm`).\n *\n * This type does **not** dispose Lua engines: call `MicroverseSlot.dispose()` on every\n * created sandbox before `unregister`, and dispose any other host resources yourself.\n */\nexport class IsolatedMicroverseRuntimeMap {\n private readonly runtimes = new Map<MicroverseInstanceId, MicroverseRuntime>();\n\n readonly register = (id: MicroverseInstanceId, runtime: MicroverseRuntime): void => {\n if (this.runtimes.has(id)) {\n throw new Error(`duplicate sandbox instance id: ${String(id)}`);\n }\n this.runtimes.set(id, runtime);\n };\n\n readonly unregister = (id: MicroverseInstanceId): void => {\n this.runtimes.delete(id);\n };\n\n readonly get = (id: MicroverseInstanceId): MicroverseRuntime | undefined => this.runtimes.get(id);\n\n readonly has = (id: MicroverseInstanceId): boolean => this.runtimes.has(id);\n\n readonly ids = (): IterableIterator<MicroverseInstanceId> => this.runtimes.keys();\n\n readonly clear = (): void => {\n this.runtimes.clear();\n };\n}\n","import type {\n MutableScriptPropertyBag,\n ScriptPropertyBag,\n ScriptPropertyValue,\n} from './ScriptPropertyValue';\n\nexport type ScriptPropertyLimits = {\n readonly maxDepth?: number | undefined;\n readonly maxKeys?: number | undefined;\n readonly maxArrayLength?: number | undefined;\n};\n\nexport const DEFAULT_SCRIPT_PROPERTY_LIMITS = {\n maxDepth: 16,\n maxKeys: 256,\n maxArrayLength: 1024,\n} as const satisfies Required<ScriptPropertyLimits>;\n\nexport function assertValidScriptPropertyValue(\n value: unknown,\n limits: ScriptPropertyLimits = DEFAULT_SCRIPT_PROPERTY_LIMITS,\n depth = 0,\n): asserts value is ScriptPropertyValue {\n const maxDepth: number = limits.maxDepth ?? DEFAULT_SCRIPT_PROPERTY_LIMITS.maxDepth;\n const maxKeys: number = limits.maxKeys ?? DEFAULT_SCRIPT_PROPERTY_LIMITS.maxKeys;\n const maxArrayLength: number =\n limits.maxArrayLength ?? DEFAULT_SCRIPT_PROPERTY_LIMITS.maxArrayLength;\n\n if (depth > maxDepth) {\n throw new Error(`script property exceeds max depth (${maxDepth})`);\n }\n\n if (value === null) {\n return;\n }\n\n const t = typeof value;\n if (t === 'string' || t === 'number' || t === 'boolean') {\n if (t === 'number' && !Number.isFinite(value)) {\n throw new Error('script property number must be finite');\n }\n return;\n }\n\n if (Array.isArray(value)) {\n const items = value as readonly unknown[];\n if (items.length > maxArrayLength) {\n throw new Error(`script property array exceeds max length (${maxArrayLength})`);\n }\n for (const item of items) {\n assertValidScriptPropertyValue(item, limits, depth + 1);\n }\n return;\n }\n\n if (t === 'object' && value !== null && !Array.isArray(value)) {\n const keys = Object.keys(value as Record<string, unknown>);\n if (keys.length > maxKeys) {\n throw new Error(`script property object exceeds max keys (${maxKeys})`);\n }\n for (const key of keys) {\n assertValidScriptPropertyValue((value as Record<string, unknown>)[key], limits, depth + 1);\n }\n return;\n }\n\n throw new Error(`script property value type not allowed: ${t}`);\n}\n\nexport function assertValidScriptPropertyBag(\n bag: unknown,\n limits?: ScriptPropertyLimits,\n): asserts bag is Readonly<Record<string, ScriptPropertyValue>> {\n if (typeof bag !== 'object' || bag === null || Array.isArray(bag)) {\n throw new Error('script property bag must be a plain object');\n }\n const keys = Object.keys(bag);\n const maxKeys: number = limits?.maxKeys ?? DEFAULT_SCRIPT_PROPERTY_LIMITS.maxKeys;\n if (keys.length > maxKeys) {\n throw new Error(`script property bag exceeds max keys (${maxKeys})`);\n }\n for (const key of keys) {\n assertValidScriptPropertyValue((bag as Record<string, unknown>)[key], limits, 1);\n }\n}\n\nexport function cloneScriptPropertyValue(value: ScriptPropertyValue): ScriptPropertyValue {\n if (value === null || typeof value !== 'object') {\n return value;\n }\n if (Array.isArray(value)) {\n const items = value as readonly ScriptPropertyValue[];\n return items.map((item) => cloneScriptPropertyValue(item));\n }\n const out: Record<string, ScriptPropertyValue> = {};\n for (const [k, v] of Object.entries(value)) {\n out[k] = cloneScriptPropertyValue(v);\n }\n return out;\n}\n\nexport function cloneScriptPropertyBag(bag: ScriptPropertyBag): MutableScriptPropertyBag {\n const out: MutableScriptPropertyBag = {};\n for (const [k, v] of Object.entries(bag)) {\n out[k] = cloneScriptPropertyValue(v);\n }\n return out;\n}\n","import type { MutableScriptPropertyBag, ScriptPropertyBag, ScriptPropertyValue } from './ScriptPropertyValue';\n\nexport function shallowEqualScriptPropertyValue(\n a: ScriptPropertyValue | undefined,\n b: ScriptPropertyValue | undefined,\n): boolean {\n if (a === b) {\n return true;\n }\n if (a == null || b == null) {\n return false;\n }\n if (typeof a !== typeof b) {\n return false;\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n const aItems = a as readonly ScriptPropertyValue[];\n const bItems = b as readonly ScriptPropertyValue[];\n if (aItems.length !== bItems.length) {\n return false;\n }\n for (let i = 0; i < aItems.length; i++) {\n if (!shallowEqualScriptPropertyValue(aItems[i], bItems[i])) {\n return false;\n }\n }\n return true;\n }\n\n if (typeof a === 'object' && typeof b === 'object' && !Array.isArray(a) && !Array.isArray(b)) {\n const aObj = a as { readonly [key: string]: ScriptPropertyValue };\n const bObj = b as { readonly [key: string]: ScriptPropertyValue };\n const aKeys = Object.keys(aObj);\n const bKeys = Object.keys(bObj);\n if (aKeys.length !== bKeys.length) {\n return false;\n }\n for (const key of aKeys) {\n if (!shallowEqualScriptPropertyValue(aObj[key], bObj[key])) {\n return false;\n }\n }\n return true;\n }\n\n return false;\n}\n\n/**\n * Returns keys whose values changed between two property bags (shallow per key).\n */\nexport function diffScriptProperties(prev: ScriptPropertyBag, next: ScriptPropertyBag): string[] {\n const changed: string[] = [];\n\n for (const key of Object.keys(next)) {\n if (!shallowEqualScriptPropertyValue(prev[key], next[key])) {\n changed.push(key);\n }\n }\n\n for (const key of Object.keys(prev)) {\n if (!(key in next)) {\n changed.push(key);\n }\n }\n\n return changed;\n}\n\n/** Applies changed keys from `source` into `target`. */\nexport function applyScriptPropertyChanges(\n target: MutableScriptPropertyBag,\n source: ScriptPropertyBag,\n changedKeys: ReadonlyArray<string>,\n): void {\n for (const key of changedKeys) {\n if (key in source) {\n target[key] = source[key]!;\n } else {\n delete target[key];\n }\n }\n}\n\nexport function mergeScriptPropertyBags(\n base: ScriptPropertyBag,\n override: ScriptPropertyBag,\n): MutableScriptPropertyBag {\n return { ...base, ...override };\n}\n","import type { z } from 'zod';\n\nimport type { ScriptPropertyBag } from '../scriptProps/ScriptPropertyValue';\n\nexport type LuaScriptSource = string | (() => string | Promise<string>);\n\n/** Catalog entry: what a script is, not where it runs. */\nexport type LuaScriptDefinition = {\n readonly scriptId: string;\n readonly source: LuaScriptSource;\n readonly propsSchema?: z.ZodObject<z.ZodRawShape> | undefined;\n readonly defaultProps?: ScriptPropertyBag | undefined;\n readonly description?: string | undefined;\n readonly injectLuaChunks?: readonly string[] | undefined;\n};\n\nexport async function resolveLuaScriptSource(source: LuaScriptSource): Promise<string> {\n if (typeof source === 'string') {\n return source;\n }\n return source();\n}\n","export type ScriptInstanceId = string & { readonly __brand: 'ScriptInstanceId' };\n\nexport function createScriptInstanceId(id: string): ScriptInstanceId {\n if (id.length === 0) {\n throw new Error('ScriptInstanceId must be non-empty');\n }\n return id as ScriptInstanceId;\n}\n\nexport type ScriptAuditTags = Readonly<Record<string, string | number | boolean>>;\n\nexport type ScriptInstanceContext = {\n readonly instanceId: ScriptInstanceId;\n readonly scriptId: string;\n readonly slotKey: string;\n readonly audit: ScriptAuditTags;\n};\n\nexport function createScriptInstanceContext(args: {\n readonly instanceId: string;\n readonly scriptId: string;\n readonly slotKey: string;\n readonly audit?: ScriptAuditTags | undefined;\n}): ScriptInstanceContext {\n return {\n instanceId: createScriptInstanceId(args.instanceId),\n scriptId: args.scriptId,\n slotKey: args.slotKey,\n audit: args.audit ?? {},\n };\n}\n"],"mappings":";;AAIA,IAAa,sBAAyC,EACpD,mBAAmB,MACrB;;;ACAA,SAAgB,2BAA2B,OAAqC;CAC9E,OAAO;AACT;;;ACJA,IAAa,YAA2B,EAAE,MAAM,OAAO;AAEvD,SAAgB,aAAa,cAAqC;CAChE,OAAO;EAAE,MAAM;EAAS;CAAa;AACvC;;;ACNA,SAAgB,mBAAmB,OAA6B;CAC9D,OAAO;AACT;;;;;AAMA,SAAgB,oB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O;EAGX,OAAO;CACT;CAEA,OAAO;AACT;;;;AAKA,SAAgB,qBAAqB,MAAyB,MAAmC;CAC/F,MAAM,UAAoB,CAAC;CAE3B,KAAK,MAAM,OAAO,OAAO,KAAK,IAAI,GAChC,IAAI,CAAC,gCAAgC,KAAK,MAAM,KAAK,IAAI,GACvD,QAAQ,KAAK,GAAG;CAIpB,KAAK,MAAM,OAAO,OAAO,KAAK,IAAI,GAChC,IAAI,EAAE,OAAO,OACX,QAAQ,KAAK,GAAG;CAIpB,OAAO;AACT;;AAGA,SAAgB,2BACd,QACA,QACA,aACM;CACN,KAAK,MAAM,OAAO,aAChB,IAAI,OAAO,QACT,OAAO,OAAO,OAAO;MAErB,OAAO,OAAO;AAGpB;AAEA,SAAgB,wBACd,MACA,UAC0B;CAC1B,OAAO;EAAE,GAAG;EAAM,GAAG;CAAS;AAChC;;;AC1EA,eAAsB,uBAAuB,QAA0C;CACrF,IAAI,OAAO,WAAW,UACpB,OAAO;CAET,OAAO,OAAO;AAChB;;;ACnBA,SAAgB,uBAAuB,IAA8B;CACnE,IAAI,GAAG,WAAW,GAChB,MAAM,IAAI,MAAM,oCAAoC;CAEtD,OAAO;AACT;AAWA,SAAgB,4BAA4B,MAKlB;CACxB,OAAO;EACL,YAAY,uBAAuB,KAAK,UAAU;EAClD,UAAU,KAAK;EACf,SAAS,KAAK;EACd,OAAO,KAAK,SAAS,CAAC;CACxB;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/domain/runtime/CancellationToken.ts","../src/domain/runtime/ExecutionFailure.ts","../src/domain/runtime/MicroverseInstanceId.ts","../src/domain/runtime/TimeoutPolicy.ts","../src/domain/microverse/MicroverseId.ts","../src/domain/microverse/MicroverseScript.ts","../src/infrastructure/logging/ConsoleLogger.ts","../src/infrastructure/runtime/StubRuntimeAdapter.ts","../src/application/useCases/executeScript.ts","../src/infrastructure/runtime/StubMicroverseRuntime.ts","../src/infrastructure/composition/IsolatedMicroverseRuntimeMap.ts","../src/domain/scriptProps/scriptPropertyLimits.ts","../src/domain/scriptProps/scriptProperties.ts","../src/domain/script/LuaScriptDefinition.ts","../src/domain/script/ScriptInstanceContext.ts"],"sourcesContent":["export type CancellationToken = {\n readonly isCancelled: () => boolean;\n};\n\nexport const neverCancelledToken: CancellationToken = {\n isCancelled: () => false,\n};\n","export type ExecutionFailure =\n | { readonly _tag: 'Timeout' }\n | { readonly _tag: 'Cancelled' }\n | { readonly _tag: 'AdapterError'; readonly message: string };\n\n/** Human-readable detail for logging or `Error` messages. */\nexport function formatExecutionFailure(failure: ExecutionFailure): string {\n switch (failure._tag) {\n case 'AdapterError':\n return failure.message;\n case 'Timeout':\n return 'execution timed out';\n case 'Cancelled':\n return 'execution cancelled';\n }\n}\n","/**\n * Opaque id for one **isolated** sandbox runtime instance in the host process.\n * Typical use: one id per entity, per script, or per worker — each maps to its own `MicroverseRuntime`.\n */\nexport type MicroverseInstanceId = string & { readonly __brand: 'MicroverseInstanceId' };\n\nexport function createMicroverseInstanceId(value: string): MicroverseInstanceId {\n return value as MicroverseInstanceId;\n}\n","export type TimeoutPolicy =\n | { readonly kind: 'none' }\n | { readonly kind: 'fixed'; readonly milliseconds: number };\n\nexport const noTimeout: TimeoutPolicy = { kind: 'none' };\n\nexport function fixedTimeout(milliseconds: number): TimeoutPolicy {\n return { kind: 'fixed', milliseconds };\n}\n","export type MicroverseId = string & { readonly __brand: 'MicroverseId' };\n\nexport function createMicroverseId(value: string): MicroverseId {\n return value as MicroverseId;\n}\n\n/**\n * Branded id for **one Lua environment slot** (`_ENV`) inside a shared Wasm VM — same value as {@link createMicroverseId},\n * wording aimed at host/workflow code (pairs with {@link MicroverseRuntime.createMicroverse}'s `slotKey`).\n */\nexport function createLuaEnvSlotKey(label: string): MicroverseId {\n return createMicroverseId(label);\n}\n","export type MicroverseScript = string & { readonly __brand: 'MicroverseScript' };\n\nexport function createMicroverseScript(source: string): MicroverseScript {\n return source as MicroverseScript;\n}\n","import type { LoggerPort } from '../../application/ports/LoggerPort';\n\nexport class ConsoleLogger implements LoggerPort {\n readonly info = (message: string): void => {\n const g = globalThis as typeof globalThis & {\n console?: { log: (line: string) => void };\n };\n g.console?.log(`[runtime-core] ${message}`);\n };\n}\n","import { ok, type Result } from '@microverse.ts/shared';\n\nimport type { RuntimeAdapter } from '../../domain/runtime/RuntimeAdapter';\nimport type { ExecutionContext } from '../../domain/runtime/ExecutionContext';\nimport type { ExecutionFailure } from '../../domain/runtime/ExecutionFailure';\nimport type { RunScriptResult } from '../../domain/runtime/RunScriptResult';\nimport type { RunScriptInput } from '../../domain/runtime/RunScriptInput';\n\nexport class StubRuntimeAdapter implements RuntimeAdapter {\n readonly execute = async (\n _ctx: ExecutionContext,\n input: RunScriptInput,\n ): Promise<Result<RunScriptResult, ExecutionFailure>> => {\n return ok({ output: `stub:${String(input.script)}` });\n };\n}\n","import type { AsyncUseCase } from '@microverse.ts/shared';\nimport { err, type Result } from '@microverse.ts/shared';\n\nimport type { LoggerPort } from '../ports/LoggerPort';\nimport type { RuntimeAdapterPort } from '../ports/RuntimeAdapterPort';\nimport type { ExecutionContext } from '../../domain/runtime/ExecutionContext';\nimport type { ExecutionFailure } from '../../domain/runtime/ExecutionFailure';\nimport type { RunScriptInput } from '../../domain/runtime/RunScriptInput';\nimport type { RunScriptResult } from '../../domain/runtime/RunScriptResult';\n\nexport type ExecuteScriptPorts = readonly [RuntimeAdapterPort, LoggerPort];\n\n/**\n * Port tuple order: `[RuntimeAdapterPort, LoggerPort]`.\n */\nexport const executeScript: AsyncUseCase<\n ExecuteScriptPorts,\n readonly [ExecutionContext, RunScriptInput],\n Result<RunScriptResult, ExecutionFailure>\n> = async (ports, ctx, input) => {\n const [adapter, logger] = ports;\n if (ctx.cancellation.isCancelled()) {\n return err({ _tag: 'Cancelled' });\n }\n logger.info('executeScript:start');\n const result = await adapter.execute(ctx, input);\n logger.info('executeScript:end');\n return result;\n};\n","import { executeScript } from '../../application/useCases/executeScript';\nimport type { LoggerPort } from '../../application/ports/LoggerPort';\nimport type { RuntimeAdapter } from '../../domain/runtime/RuntimeAdapter';\nimport type { RunScriptInput } from '../../domain/runtime/RunScriptInput';\nimport type { CreateMicroverseOptions, MicroverseSlot, MicroverseRuntime } from '../../domain/runtime/MicroverseRuntime';\nimport { neverCancelledToken } from '../../domain/runtime/CancellationToken';\nimport type { TimeoutPolicy } from '../../domain/runtime/TimeoutPolicy';\nimport { createMicroverseId, type MicroverseId } from '../../domain/microverse/MicroverseId';\n\nexport type StubMicroverseRuntimeDeps = {\n readonly adapter: RuntimeAdapter;\n readonly logger: LoggerPort;\n /** Applied when neither {@link RunScriptInput.timeout} nor {@link CreateMicroverseOptions.defaultTimeout} is set. */\n readonly defaultTimeout?: TimeoutPolicy | undefined;\n};\n\nexport class StubMicroverseRuntime implements MicroverseRuntime {\n private readonly usedSlotKeys = new Set<string>();\n\n constructor(private readonly deps: StubMicroverseRuntimeDeps) {}\n\n readonly createMicroverse = async (options: CreateMicroverseOptions): Promise<MicroverseSlot> => {\n const id =\n options.slotKey !== undefined ? options.slotKey : createMicroverseId(createRandomId());\n if (options.slotKey !== undefined) {\n const k = String(options.slotKey);\n if (this.usedSlotKeys.has(k)) {\n throw new Error(`duplicate slotKey: ${k}`);\n }\n this.usedSlotKeys.add(k);\n }\n return createStubMicroverseSlot({\n id,\n deps: this.deps,\n options,\n explicitSlotKey: options.slotKey !== undefined,\n usedSlotKeys: this.usedSlotKeys,\n });\n };\n}\n\nfunction createRandomId(): string {\n const g = globalThis as typeof globalThis & {\n crypto?: { randomUUID?: () => string };\n };\n if (g.crypto?.randomUUID) {\n return g.crypto.randomUUID();\n }\n return `sandbox-${Math.random().toString(16).slice(2)}`;\n}\n\nfunction createStubMicroverseSlot(input: {\n readonly id: MicroverseId;\n readonly deps: StubMicroverseRuntimeDeps;\n readonly options: CreateMicroverseOptions;\n readonly explicitSlotKey: boolean;\n readonly usedSlotKeys: Set<string>;\n}): MicroverseSlot {\n const ctx = { microverseId: input.id, cancellation: neverCancelledToken };\n return {\n id: input.id,\n run: async (runInput) => {\n const resolvedTimeout =\n runInput.timeout ?? input.options.defaultTimeout ?? input.deps.defaultTimeout;\n const inputMerged: RunScriptInput =\n resolvedTimeout !== undefined ? { ...runInput, timeout: resolvedTimeout } : { ...runInput };\n return executeScript([input.deps.adapter, input.deps.logger], ctx, inputMerged);\n },\n dispose: async () => {\n await input.deps.adapter.disposeMicroverse?.(input.id);\n if (input.explicitSlotKey) {\n input.usedSlotKeys.delete(String(input.id));\n }\n },\n };\n}\n\nexport function createStubMicroverseRuntime(deps: StubMicroverseRuntimeDeps): MicroverseRuntime {\n return new StubMicroverseRuntime(deps);\n}\n","import type { MicroverseRuntime } from '../../domain/runtime/MicroverseRuntime';\nimport type { MicroverseInstanceId } from '../../domain/runtime/MicroverseInstanceId';\n\n/**\n * Keeps many {@link MicroverseRuntime} instances keyed by {@link MicroverseInstanceId}.\n * Each entry is typically its own `MicroverseRuntime` (hence its own Wasmoon/Lua VM when using `@microverse.ts/runtime-wasm`).\n *\n * This type does **not** dispose Lua engines: call `MicroverseSlot.dispose()` on every\n * created sandbox before `unregister`, and dispose any other host resources yourself.\n */\nexport class IsolatedMicroverseRuntimeMap {\n private readonly runtimes = new Map<MicroverseInstanceId, MicroverseRuntime>();\n\n readonly register = (id: MicroverseInstanceId, runtime: MicroverseRuntime): void => {\n if (this.runtimes.has(id)) {\n throw new Error(`duplicate sandbox instance id: ${String(id)}`);\n }\n this.runtimes.set(id, runtime);\n };\n\n readonly unregister = (id: MicroverseInstanceId): void => {\n this.runtimes.delete(id);\n };\n\n readonly get = (id: MicroverseInstanceId): MicroverseRuntime | undefined => this.runtimes.get(id);\n\n readonly has = (id: MicroverseInstanceId): boolean => this.runtimes.has(id);\n\n readonly ids = (): IterableIterator<MicroverseInstanceId> => this.runtimes.keys();\n\n readonly clear = (): void => {\n this.runtimes.clear();\n };\n}\n","import type {\n MutableScriptPropertyBag,\n ScriptPropertyBag,\n ScriptPropertyValue,\n} from './ScriptPropertyValue';\n\nexport type ScriptPropertyLimits = {\n readonly maxDepth?: number | undefined;\n readonly maxKeys?: number | undefined;\n readonly maxArrayLength?: number | undefined;\n};\n\nexport const DEFAULT_SCRIPT_PROPERTY_LIMITS = {\n maxDepth: 16,\n maxKeys: 256,\n maxArrayLength: 1024,\n} as const satisfies Required<ScriptPropertyLimits>;\n\nexport function assertValidScriptPropertyValue(\n value: unknown,\n limits: ScriptPropertyLimits = DEFAULT_SCRIPT_PROPERTY_LIMITS,\n depth = 0,\n): asserts value is ScriptPropertyValue {\n const maxDepth: number = limits.maxDepth ?? DEFAULT_SCRIPT_PROPERTY_LIMITS.maxDepth;\n const maxKeys: number = limits.maxKeys ?? DEFAULT_SCRIPT_PROPERTY_LIMITS.maxKeys;\n const maxArrayLength: number =\n limits.maxArrayLength ?? DEFAULT_SCRIPT_PROPERTY_LIMITS.maxArrayLength;\n\n if (depth > maxDepth) {\n throw new Error(`script property exceeds max depth (${maxDepth})`);\n }\n\n if (value === null) {\n return;\n }\n\n const t = typeof value;\n if (t === 'string' || t === 'number' || t === 'boolean') {\n if (t === 'number' && !Number.isFinite(value)) {\n throw new Error('script property number must be finite');\n }\n return;\n }\n\n if (Array.isArray(value)) {\n const items = value as readonly unknown[];\n if (items.length > maxArrayLength) {\n throw new Error(`script property array exceeds max length (${maxArrayLength})`);\n }\n for (const item of items) {\n assertValidScriptPropertyValue(item, limits, depth + 1);\n }\n return;\n }\n\n if (t === 'object' && value !== null && !Array.isArray(value)) {\n const keys = Object.keys(value as Record<string, unknown>);\n if (keys.length > maxKeys) {\n throw new Error(`script property object exceeds max keys (${maxKeys})`);\n }\n for (const key of keys) {\n assertValidScriptPropertyValue((value as Record<string, unknown>)[key], limits, depth + 1);\n }\n return;\n }\n\n throw new Error(`script property value type not allowed: ${t}`);\n}\n\nexport function assertValidScriptPropertyBag(\n bag: unknown,\n limits?: ScriptPropertyLimits,\n): asserts bag is Readonly<Record<string, ScriptPropertyValue>> {\n if (typeof bag !== 'object' || bag === null || Array.isArray(bag)) {\n throw new Error('script property bag must be a plain object');\n }\n const keys = Object.keys(bag);\n const maxKeys: number = limits?.maxKeys ?? DEFAULT_SCRIPT_PROPERTY_LIMITS.maxKeys;\n if (keys.length > maxKeys) {\n throw new Error(`script property bag exceeds max keys (${maxKeys})`);\n }\n for (const key of keys) {\n assertValidScriptPropertyValue((bag as Record<string, unknown>)[key], limits, 1);\n }\n}\n\nexport function cloneScriptPropertyValue(value: ScriptPropertyValue): ScriptPropertyValue {\n if (value === null || typeof value !== 'object') {\n return value;\n }\n if (Array.isArray(value)) {\n const items = value as readonly ScriptPropertyValue[];\n return items.map((item) => cloneScriptPropertyValue(item));\n }\n const out: Record<string, ScriptPropertyValue> = {};\n for (const [k, v] of Object.entries(value)) {\n out[k] = cloneScriptPropertyValue(v);\n }\n return out;\n}\n\nexport function cloneScriptPropertyBag(bag: ScriptPropertyBag): MutableScriptPropertyBag {\n const out: MutableScriptPropertyBag = {};\n for (const [k, v] of Object.entries(bag)) {\n out[k] = cloneScriptPropertyValue(v);\n }\n return out;\n}\n","import type { MutableScriptPropertyBag, ScriptPropertyBag, ScriptPropertyValue } from './ScriptPropertyValue';\n\nexport function shallowEqualScriptPropertyValue(\n a: ScriptPropertyValue | undefined,\n b: ScriptPropertyValue | undefined,\n): boolean {\n if (a === b) {\n return true;\n }\n if (a == null || b == null) {\n return false;\n }\n if (typeof a !== typeof b) {\n return false;\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n const aItems = a as readonly ScriptPropertyValue[];\n const bItems = b as readonly ScriptPropertyValue[];\n if (aItems.length !== bItems.length) {\n return false;\n }\n for (let i = 0; i < aItems.length; i++) {\n if (!shallowEqualScriptPropertyValue(aItems[i], bItems[i])) {\n return false;\n }\n }\n return true;\n }\n\n if (typeof a === 'object' && typeof b === 'object' && !Array.isArray(a) && !Array.isArray(b)) {\n const aObj = a as { readonly [key: string]: ScriptPropertyValue };\n const bObj = b as { readonly [key: string]: ScriptPropertyValue };\n const aKeys = Object.keys(aObj);\n const bKeys = Object.keys(bObj);\n if (aKeys.length !== bKeys.length) {\n return false;\n }\n for (const key of aKeys) {\n if (!shallowEqualScriptPropertyValue(aObj[key], bObj[key])) {\n return false;\n }\n }\n return true;\n }\n\n return false;\n}\n\n/**\n * Returns keys whose values changed between two property bags (shallow per key).\n */\nexport function diffScriptProperties(prev: ScriptPropertyBag, next: ScriptPropertyBag): string[] {\n const changed: string[] = [];\n\n for (const key of Object.keys(next)) {\n if (!shallowEqualScriptPropertyValue(prev[key], next[key])) {\n changed.push(key);\n }\n }\n\n for (const key of Object.keys(prev)) {\n if (!(key in next)) {\n changed.push(key);\n }\n }\n\n return changed;\n}\n\n/** Applies changed keys from `source` into `target`. */\nexport function applyScriptPropertyChanges(\n target: MutableScriptPropertyBag,\n source: ScriptPropertyBag,\n changedKeys: ReadonlyArray<string>,\n): void {\n for (const key of changedKeys) {\n if (key in source) {\n target[key] = source[key]!;\n } else {\n delete target[key];\n }\n }\n}\n\nexport function mergeScriptPropertyBags(\n base: ScriptPropertyBag,\n override: ScriptPropertyBag,\n): MutableScriptPropertyBag {\n return { ...base, ...override };\n}\n","import type { z } from 'zod';\n\nimport type { ScriptPropertyBag } from '../scriptProps/ScriptPropertyValue';\nimport type { ScriptProfileDefInput } from './scriptProfileDef';\n\nexport type LuaScriptSource = string | (() => string | Promise<string>);\n\n/** Catalog entry: what a script is, not where it runs. */\nexport type LuaScriptDefinition = {\n readonly scriptId: string;\n readonly source: LuaScriptSource;\n /**\n * Resolved script profile id (matches a `.componentType()` / surface profile name).\n * Host applies this profile at mount before props/`init`.\n */\n readonly profileId?: string | undefined;\n /** Inline profile when not registered on the surface (advanced). */\n readonly profile?: ScriptProfileDefInput | undefined;\n readonly propsSchema?: z.ZodObject<z.ZodRawShape> | undefined;\n readonly defaultProps?: ScriptPropertyBag | undefined;\n readonly description?: string | undefined;\n readonly injectLuaChunks?: readonly string[] | undefined;\n};\n\nexport function resolveLuaScriptProfileId(def: LuaScriptDefinition): string | undefined {\n return def.profileId;\n}\n\nexport async function resolveLuaScriptSource(source: LuaScriptSource): Promise<string> {\n if (typeof source === 'string') {\n return source;\n }\n return source();\n}\n","export type ScriptInstanceId = string & { readonly __brand: 'ScriptInstanceId' };\n\nexport function createScriptInstanceId(id: string): ScriptInstanceId {\n if (id.length === 0) {\n throw new Error('ScriptInstanceId must be non-empty');\n }\n return id as ScriptInstanceId;\n}\n\nexport type ScriptAuditTags = Readonly<Record<string, string | number | boolean>>;\n\nexport type ScriptInstanceContext = {\n readonly instanceId: ScriptInstanceId;\n readonly scriptId: string;\n readonly slotKey: string;\n readonly audit: ScriptAuditTags;\n};\n\nexport function createScriptInstanceContext(args: {\n readonly instanceId: string;\n readonly scriptId: string;\n readonly slotKey: string;\n readonly audit?: ScriptAuditTags | undefined;\n}): ScriptInstanceContext {\n return {\n instanceId: createScriptInstanceId(args.instanceId),\n scriptId: args.scriptId,\n slotKey: args.slotKey,\n audit: args.audit ?? {},\n };\n}\n"],"mappings":";;AAIA,IAAa,sBAAyC,EACpD,mBAAmB,MACrB;;;;ACAA,SAAgB,uBAAuB,SAAmC;CACxE,QAAQ,QAAQ,MAAhB;EACE,KAAK,gBACH,OAAO,QAAQ;EACjB,KAAK,WACH,OAAO;EACT,KAAK,aACH,OAAO;CACX;AACF;;;ACTA,SAAgB,2BAA2B,OAAqC;CAC9E,OAAO;AACT;;;ACJA,IAAa,YAA2B,EAAE,MAAM,OAAO;AAEvD,SAAgB,aAAa,cAAqC;CAChE,OAAO;EAAE,MAAM;EAAS;CAAa;AACvC;;;ACNA,SAAgB,mBAAmB,OAA6B;CAC9D,OAAO;AACT;;;;;AAMA,SAAgB,oBAAoB,OAA6B;CAC/D,OAAO,mBAAmB,KAAK;AACjC;;;ACVA,SAAgB,uBAAuB,QAAkC;CACvE,OAAO;AACT;;;ACFA,IAAa,gBAAb,MAAiD;CAC/C,QAAiB,YAA0B;EAIzC,WAAE,SAAS,IAAI,kBAAkB,SAAS;C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AK,IAAI,GACvD,QAAQ,KAAK,GAAG;CAIpB,KAAK,MAAM,OAAO,OAAO,KAAK,IAAI,GAChC,IAAI,EAAE,OAAO,OACX,QAAQ,KAAK,GAAG;CAIpB,OAAO;AACT;;AAGA,SAAgB,2BACd,QACA,QACA,aACM;CACN,KAAK,MAAM,OAAO,aAChB,IAAI,OAAO,QACT,OAAO,OAAO,OAAO;MAErB,OAAO,OAAO;AAGpB;AAEA,SAAgB,wBACd,MACA,UAC0B;CAC1B,OAAO;EAAE,GAAG;EAAM,GAAG;CAAS;AAChC;;;AClEA,SAAgB,0BAA0B,KAA8C;CACtF,OAAO,IAAI;AACb;AAEA,eAAsB,uBAAuB,QAA0C;CACrF,IAAI,OAAO,WAAW,UACpB,OAAO;CAET,OAAO,OAAO;AAChB;;;AC/BA,SAAgB,uBAAuB,IAA8B;CACnE,IAAI,GAAG,WAAW,GAChB,MAAM,IAAI,MAAM,oCAAoC;CAEtD,OAAO;AACT;AAWA,SAAgB,4BAA4B,MAKlB;CACxB,OAAO;EACL,YAAY,uBAAuB,KAAK,UAAU;EAClD,UAAU,KAAK;EACf,SAAS,KAAK;EACd,OAAO,KAAK,SAAS,CAAC;CACxB;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microverse.ts/runtime-core",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "zod": "^3.24.0",
30
- "@microverse.ts/shared": "0.2.0"
30
+ "@microverse.ts/shared": "0.3.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "typescript": "^5.8.3",