Runtime Layers
A runtime layer exposes an instance whose startup and shutdown are supervised by the Core. Its pack has a unique label and a dedicated typology. Several libraries can use library, while a runtime typology such as targetApi identifies one layer in the stack.
Create the Manifest
Create system-lrpcks/sometarget/manifest.json. Here, sometarget is the pack label and targetApi is its runtime typology. The example permits a pack labelled whorequest to request access.
{
"label": "sometarget",
"typology": "targetApi",
"icon": "M",
"version": "1.0.0",
"method": "main.js",
"require": false,
"permits": ["whorequest"],
"description": "A target layer with a managed lifecycle"
}
Set permits to an array of caller pack labels to select consumers. true allows other packs to request access, while false denies access from other packs. The Core retains its own lifecycle access.
Implement the Lifecycle
Save this as system-lrpcks/sometarget/main.js. The factory returns an object with attach and detach. Each returns the bundle supplied by the Core, populated through engine.bundleAssign(bundle, reference, assets).
import { defineLayer } from '#core:layers'
export default defineLayer(({ engine, layers }) => new class {
#value = 'Example value from Staxis'
getValue = () => this.#value
attach(bundle) {
return engine.bundleAssign(bundle, layers.current, {
active: true,
getValue: this.getValue
})
}
detach(bundle) {
return engine.bundleAssign(bundle, layers.current, {
active: false
})
}
})
For a server or connection, acquire resources during attach and release them during detach. These methods can be asynchronous. Preserve the supplied bundle and its identity markers. The Core freezes the returned bundle after validation. Your published API is in its assets property.
Configure the Pack
Add sometarget to the stack and provide a dedicated KEY:TARGETAPI entry in the private .keys file. Use the key-generation procedure in First setup. After reviewing the pack, run node project updateHMAC before starting with integrity checks enabled.
Request the Instance
In this example, whorequest is the caller's pack label, sometarget is the target pack's label, and targetApi is the target's runtime typology. The target manifest grants access to whorequest. Use labels when requesting the Vault token, then the typology when requesting the instance.
A consumer declares "require": ["sometarget"] and comes later in the stack. This fragment belongs inside the factory or a method of the permitted whorequest pack, which receives engine and layers.
const token = engine.vault.requireAccess(
'whorequest', // Requester's manifest.label
'sometarget' // Provider's manifest.label
)
if (typeof token !== 'string' || token.startsWith('error:')) {
throw new Error('Access to the targetApi layer was denied')
}
const targetInstance = layers.require(
'targetApi', // Provider's manifest.typology: runtime slot
token,
false
)
if (!targetInstance || typeof targetInstance.assets?.getValue !== 'function') {
throw new Error('The target layer is unavailable')
}
const value = targetInstance.assets.getValue()
Passing false requests the published instance. Passing true requests the lifecycle API, whose operations require appropriate safeguards. For ordinary application calls, use the instance's assets.
See init for Manager-assisted creation. The current generated lifecycle template needs review, including its bundleAssign arguments and undefined stopReport reference.