@shapeshift-labs/frontier-triggers
v0.1.1
Published
Capability-gated event trigger registry and deterministic event-to-action orchestration for Frontier apps and games.
Maintainers
Readme
@shapeshift-labs/frontier-triggers
Capability-gated event trigger registry and deterministic event-to-action orchestration for Frontier apps and games. The package lets game, DOM, state, route, and custom runtime systems emit scoped event facts, then evaluates declarative trigger rules that can reject, schedule, dispatch, consume, replay, and inspect downstream actions without taking a hard dependency on those higher-level packages.
- npm:
@shapeshift-labs/frontier-triggers - source:
siliconjungle/-shapeshift-labs-frontier-triggers - license: MIT
API Shape
import { createTriggerRuntime } from '@shapeshift-labs/frontier-triggers';
const runtime = createTriggerRuntime({
actions,
scheduler,
eventLog,
capabilities: ['game.room.enter', 'inventory.write']
});
runtime.register({
id: 'room.enter.grant-key',
event: 'game.room.enter',
scope: { kind: 'world', id: 'demo-world' },
subjects: [{ kind: 'entity', role: 'player' }],
requires: ['inventory.write'],
when: [
{ path: 'payload.roomId', equals: 'crypt' },
{ path: 'state.flags.cryptKeyGranted', exists: false }
],
oncePer: (event) => event.subject ?? event.id,
cooldownMs: 250,
action: {
id: 'inventory.add',
lane: 'gameplay',
key: (event) => 'inventory:' + event.subject
},
input: (event) => ({ itemId: 'crypt-key', sourceEvent: event.id }),
emits: ['inventory.changed'],
tags: ['gameplay']
});
const result = runtime.require({
type: 'game.room.enter',
source: 'inkwell.runtime',
subject: 'player:local',
scope: { kind: 'world', id: 'demo-world' },
subjects: [{ kind: 'entity', id: 'player-local', role: 'player' }],
payload: { roomId: 'crypt' }
});
if (!result.accepted) {
console.log(result.rejection?.code);
}Design Notes
frontier-triggers does not detect collisions, DOM clicks, room transitions, physics, network messages, or state diffs itself. Those systems emit event facts. This package owns the high-level trigger layer that decides whether a matching rule may fire and how its downstream action should be represented.
- Events use CloudEvents-style routing fields:
id,type,source,subject,timestamp, plus Frontier-specificscope,subjects,payload,causeId, andtick. - Trigger rules can match event type patterns, source, world/app/DOM/game scopes, one or more entity subjects, arbitrary runtime custom events, and JSON-path-like state or payload conditions.
- Capability gates are first-class. Missing capabilities produce structured
missing-capabilityrejections; callers can useruntime.require(...)when they need a hard accept/reject result. - Outcomes are records, not callback side effects. Every emit returns matched, scheduled, completed, rejected, and failed outcomes with stable rejection codes.
- Scheduling and action dispatch are structural adapters. A mutation action registry, direct scheduler, game runtime, DOM host, or test harness can be passed in without becoming a dependency.
- Action bindings can emit follow-up event facts with
emit. Cascaded events inherit source, actor, scope, subject, subjects, and tick by default, carrycauseIdprovenance back to the parent event, and are returned inresult.records/result.cascaded. once,oncePer,cooldownMs,exclusive, andconsumeprovide common game/event-bus controls while staying deterministic and snapshot-friendly.maxCascadeDepthbounds recursive trigger chains. When a loop would exceed the configured depth, the runtime records a structuredcascade-depthrejection instead of recursing forever.snapshot()andrestore()capture once/cooldown gates and optional history for rewindable runtimes.replay()re-emits event facts through the same matching rules.- Event-log integration appends trigger emit records using the
frontier-event-logshape by default, or raw records for simple custom sinks. inspect(),registryGraph(), andimpact()expose trigger, event, capability, subject, action, and runtime record relationships for Frontier inspection and AI review flows.
App And Game Use
The same event grammar covers game events such as game.room.enter, game.room.exit, physics.collision.start, physics.collision.end, player.jump, and DOM/app events such as dom.click, route.enter, form.submit, or any runtime-defined custom event.
Actions can trigger downstream rules without leaving the runtime:
runtime.register({
id: 'collision.damage',
event: 'physics.collision.start',
action: {
id: 'player.damage',
mode: 'dispatch',
input: { amount: 1 },
emit: { type: 'player.damaged', payload: { amount: 1 } }
}
});
runtime.register({
id: 'damage.toast',
event: 'player.damaged',
action: { id: 'ui.toast', mode: 'dispatch', input: { text: 'Ouch' } }
});
const result = runtime.require({ type: 'physics.collision.start' });
console.log(result.records.map((record) => record.event.type));Related Packages
The published Frontier package family is generated from one shared package catalog so READMEs stay in sync across packages:
@shapeshift-labs/frontier: Core JSON diff/apply, compact patch tuples, JSON Pointer, equality, clone, validation, Unicode helpers, and tiny dependency-free runtime budget/scheduler primitives.@shapeshift-labs/frontier-query: Shared query-key, selector path, condition, entity identity, and table-shape primitives.@shapeshift-labs/frontier-codec: Patch serialization, binary frames, canonical JSON, and patch-history codecs.@shapeshift-labs/frontier-engine: Stateful planned diff engine, adaptive profiles, schema plans, and engine-level history helpers.@shapeshift-labs/frontier-state: Patch-routed app-state subscriptions, owned commits, maintained views, and path mapping.@shapeshift-labs/frontier-state-cache: Normalized query-result cache with entity/query watchers, persistence, change logs, optimistic layers, scheduled persistence, and mutation bridge.@shapeshift-labs/frontier-state-cache-idb: IndexedDB persistence adapter for Frontier state-cache snapshots and durable change logs.@shapeshift-labs/frontier-state-cache-file: Structured file persistence adapter for Frontier state-cache snapshots and change logs.@shapeshift-labs/frontier-state-cache-sql: SQL persistence adapter for Frontier state-cache snapshots and change logs.@shapeshift-labs/frontier-schema: JSON Schema validation, Frontier profile generation, CloudEvent envelopes, and query/table schema helpers.@shapeshift-labs/frontier-migrations: Boundary-first data migrations, import normalization, plugin/API version mapping, versioned envelopes, graph diagnostics, patch path rewrites, dry-run reports, and current-shape rehydration.@shapeshift-labs/frontier-event-log: Bounded event logs, replay cursors, consumer acknowledgements, keyed compaction, checkpoints, and Frontier patch event records.@shapeshift-labs/frontier-inspect: Cross-package inspection/evidence bundles, registry graph snapshots, feature/resource impact reports, timeline/event normalization, redaction, JSONL import/export, and AI-readable app feature maps.@shapeshift-labs/frontier-scheduler: Deterministic work scheduling, lanes, cancellation, backpressure, frame policies, replay snapshots, and work graphs.@shapeshift-labs/frontier-logging: Opt-in structured logging, browser telemetry, scheduled sinks, file sinks, exporters, benchmark traces, and Frontier patch/update summaries.@shapeshift-labs/frontier-mutation: Explicit mutation and selector plans compiled to Frontier patches or CRDT operations.@shapeshift-labs/frontier-virtual: DOM-neutral virtualization, layout providers, range materialization, grids, spatial/frustum indexes, patch invalidation, camera anchors, and serializable layout state.@shapeshift-labs/frontier-scene: Patch-native 2D/3D scene graph, transform propagation, bounds queries, virtual/culling adapters, spatial invalidation, and camera/frustum materialization.@shapeshift-labs/frontier-pathfinding: Patch-native grid pathfinding, typed-array A*/Dijkstra search, flow fields, connected components, line-of-sight smoothing, dirty-cell invalidation, and scheduler-friendly path jobs.@shapeshift-labs/frontier-lod: Patch-native level-of-detail and significance selection for rendering and computation workloads, compact typed hot paths, multi-observer selection, budget degradation, materialization frames, and scheduler work plans.@shapeshift-labs/frontier-route: DOM-neutral app/game route resources, route and scene manifests, match/resolve/transition planning, dependency metadata, sessions, registry graph output, and impact queries.@shapeshift-labs/frontier-trace: Serializable traces, spans, events, causal links, W3C trace context helpers, timeline/resource/path queries, critical-path analysis, registry graph output, JSONL/proof helpers, Chrome trace export, and redaction for app-wide feature observability.@shapeshift-labs/frontier-dom: Patch-native DOM and host renderer bindings, manifest hydration, JSX runtime/compiler helpers, SSR, devtools, and logging bridges.@shapeshift-labs/frontier-playwright: Playwright/headless automation probes for Frontier state, DOM, devtools, marks, and timeline queries.@shapeshift-labs/frontier-crdt: Native CRDT documents, update tooling, awareness, branches, conflict introspection, version frames, and undo.@shapeshift-labs/frontier-crdt-sync: CRDT sync endpoints, repo/storage/provider contracts, scheduled sync work, document URLs, local networks, model checking, forensics, and text binding contracts.@shapeshift-labs/frontier-crdt-websocket: WebSocket client/server transports for Frontier CRDT sync providers.@shapeshift-labs/frontier-react: React external-store hooks and adapters for Frontier state, cache, and CRDT surfaces.@shapeshift-labs/frontier-richtext: Rich text Delta normalization/application, marks, embeds, ranges, and cursor/selection transforms for local editor integrations.@shapeshift-labs/frontier-realtime: Shared realtime command, tick, snapshot, prediction, reconciliation, interpolation, rollback, message, and delta primitives.@shapeshift-labs/frontier-realtime-server: Authoritative realtime room, tick, command validation, rate-limit, session, and snapshot-history runtime.@shapeshift-labs/frontier-realtime-websocket: WebSocket client, wire, and Node room-server transport for Frontier realtime.@shapeshift-labs/frontier-game: Game-facing entity, component, player, room, ownership, spatial interest, rollback, physics, and replication helpers above realtime.
Package source repositories:
siliconjungle/-shapeshift-labs-frontiersiliconjungle/-shapeshift-labs-frontier-querysiliconjungle/-shapeshift-labs-frontier-codecsiliconjungle/-shapeshift-labs-frontier-enginesiliconjungle/-shapeshift-labs-frontier-statesiliconjungle/-shapeshift-labs-frontier-state-cachesiliconjungle/-shapeshift-labs-frontier-state-cache-idbsiliconjungle/-shapeshift-labs-frontier-state-cache-filesiliconjungle/-shapeshift-labs-frontier-state-cache-sqlsiliconjungle/-shapeshift-labs-frontier-schemasiliconjungle/-shapeshift-labs-frontier-migrationssiliconjungle/-shapeshift-labs-frontier-event-logsiliconjungle/-shapeshift-labs-frontier-inspectsiliconjungle/-shapeshift-labs-frontier-schedulersiliconjungle/-shapeshift-labs-frontier-loggingsiliconjungle/-shapeshift-labs-frontier-mutationsiliconjungle/-shapeshift-labs-frontier-triggerssiliconjungle/-shapeshift-labs-frontier-virtualsiliconjungle/-shapeshift-labs-frontier-scenesiliconjungle/-shapeshift-labs-frontier-pathfindingsiliconjungle/-shapeshift-labs-frontier-lodsiliconjungle/-shapeshift-labs-frontier-routesiliconjungle/-shapeshift-labs-frontier-tracesiliconjungle/-shapeshift-labs-frontier-domsiliconjungle/-shapeshift-labs-frontier-playwrightsiliconjungle/-shapeshift-labs-frontier-crdtsiliconjungle/-shapeshift-labs-frontier-crdt-syncsiliconjungle/-shapeshift-labs-frontier-crdt-websocketsiliconjungle/-shapeshift-labs-frontier-reactsiliconjungle/-shapeshift-labs-frontier-richtextsiliconjungle/-shapeshift-labs-frontier-realtimesiliconjungle/-shapeshift-labs-frontier-realtime-serversiliconjungle/-shapeshift-labs-frontier-realtime-websocketsiliconjungle/-shapeshift-labs-frontier-game
Install
npm install @shapeshift-labs/frontier-triggersBenchmarks
Run the package-local benchmark with:
npm run benchFrontier-only package measurements cover trigger registration, scoped matching, capability rejection, action scheduling, replay, and registry graph generation using package-local fixtures only. They do not include competitor comparisons.
