@listen-fire/engine 0.13.1 → 0.14.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.
@@ -1,5 +1,4 @@
1
1
  export * from '../services/translation_graph/triggers/types';
2
- export * from '../services/translation_graph/triggers/trigger_event';
3
2
  export * from '../services/translation_graph/triggers/listen_config';
4
3
  export * from '../services/translation_graph/triggers/listen_plans';
5
4
  export * from '../services/translation_graph/engine/inbound/discriminate';
@@ -20,7 +20,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  __exportStar(require("../services/translation_graph/triggers/types"), exports);
23
- __exportStar(require("../services/translation_graph/triggers/trigger_event"), exports);
24
23
  __exportStar(require("../services/translation_graph/triggers/listen_config"), exports);
25
24
  __exportStar(require("../services/translation_graph/triggers/listen_plans"), exports);
26
25
  __exportStar(require("../services/translation_graph/engine/inbound/discriminate"), exports);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@listen-fire/engine",
3
3
  "license": "Apache-2.0",
4
- "version": "0.13.1",
4
+ "version": "0.14.0",
5
5
  "description": "The movement engine for this release's language and its host contract: the Rust engine's shim, the EngineHost families, the run host, the embed kit, and the adapter and model types they reach. Every shell (the hosted product, the `listen-fire` command line, an embedder) runs the same engine. A run pinned to a release this one does not read is refused by name. Embedders reach it only through public/* (the exports map); the internals resolve only under the `movement-engine-internals` condition, which only test runners set",
6
6
  "engines": {
7
7
  "node": ">=22.23.4 <23"
@@ -17,8 +17,8 @@
17
17
  "dependencies": {
18
18
  "safe-stable-stringify": "2.5.0",
19
19
  "zod": "4.1.12",
20
- "@listen-fire/engine-contracts": "^0.13.1",
21
- "@listen-fire/movement-lang": "^0.13.1",
20
+ "@listen-fire/engine-contracts": "^0.14.0",
21
+ "@listen-fire/movement-lang": "^0.14.0",
22
22
  "@listen-fire/module-runtime": "^0.12.8"
23
23
  },
24
24
  "devDependencies": {
@@ -1,6 +0,0 @@
1
- import type { LoopGuard } from './loop_guard';
2
- export interface LoopGuardContractCase {
3
- name: string;
4
- run(guard: LoopGuard): Promise<void>;
5
- }
6
- export declare const loopGuardContractCases: LoopGuardContractCase[];
@@ -1,47 +0,0 @@
1
- "use strict";
2
- // The loop guard slot's contract suite: one set of cases every guard is held
3
- // to — the built-in in this process (FingerprintGuard), listen-fire's Rust one over
4
- // the guard wire (`listen-fire --contract-guard`, a file and a Postgres database), and
5
- // a guard module listen-fire drives as a process (`listen-fire --contract-guard-slot`), all in
6
- // apps/cli's tests. A guard is only told of writes, so each case holds it to
7
- // taking them; what it remembers, and for how long, is its own business.
8
- //
9
- // Runner-agnostic, as the run host's suite is: each case is a name and an
10
- // async body that throws on failure (node:assert). Every case uses records
11
- // of its own, so one guard can serve the whole list.
12
- var __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.loopGuardContractCases = void 0;
17
- const strict_1 = __importDefault(require("node:assert/strict"));
18
- const node_crypto_1 = require("node:crypto");
19
- const WRITER = 'listen:sync:stamp';
20
- function aRecord() {
21
- return { adapter: 'attio', recordType: 'Companies', externalId: `rec-${(0, node_crypto_1.randomUUID)()}` };
22
- }
23
- const seen = { name: 'Acme', description: 'Seen by lf' };
24
- const edited = { name: 'Acme', description: 'Edited by Bob' };
25
- exports.loopGuardContractCases = [
26
- {
27
- name: 'a write is taken, and answers nothing',
28
- async run(guard) {
29
- strict_1.default.equal(await guard.recordWrite({ ...aRecord(), writer: WRITER, record: seen }), undefined);
30
- },
31
- },
32
- {
33
- name: 'a write that left the record gone is taken',
34
- async run(guard) {
35
- await guard.recordWrite({ ...aRecord(), writer: WRITER, record: null });
36
- },
37
- },
38
- {
39
- name: 'a writer\'s later write to the same record is taken, beside another writer\'s',
40
- async run(guard) {
41
- const one = aRecord();
42
- await guard.recordWrite({ ...one, writer: WRITER, record: seen });
43
- await guard.recordWrite({ ...one, writer: 'listen:audit:log', record: edited });
44
- await guard.recordWrite({ ...one, writer: WRITER, record: edited });
45
- },
46
- },
47
- ];
@@ -1,20 +0,0 @@
1
- /** A record write, with the record as the source answered it right after
2
- * (`null`: the record is gone). `writer` is the listen that wrote it. */
3
- export interface RecordWrite {
4
- adapter: string;
5
- recordType: string;
6
- externalId: string;
7
- writer: string;
8
- record: unknown;
9
- }
10
- export interface LoopGuard {
11
- /** `writer`'s write, remembered; its later write to the same record replaces it. */
12
- recordWrite(write: RecordWrite): Promise<void>;
13
- }
14
- /** How long the built-in remembers a write. */
15
- export declare const REMEMBERED_MS = 3600000;
16
- /** The built-in, in this process. */
17
- export declare class FingerprintGuard implements LoopGuard {
18
- private readonly remembered;
19
- recordWrite(write: RecordWrite): Promise<void>;
20
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- // The loop guard slot: a module told of each record write a run makes
3
- // (plans/cloud-native-2026-10-06/22_everywhere_plan.md, Henry 2026-10-18).
4
- // Empty unless a project names one in `core:`.
5
- //
6
- // The host reads a record back after a run writes it and tells the guard
7
- // (`recordWrite`). Nothing asks the guard anything back: the host's loop
8
- // breaker caps every chain of writes and arrivals, and the slot's `isEcho`
9
- // is retired. The contract is docs/contracts/loop-guard-slot.md; the
10
- // built-in, `@lf/fingerprint-guard`, is `FingerprintGuard` here and in
11
- // listen-fire (crates/lf/src/loop_guard.rs).
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.FingerprintGuard = exports.REMEMBERED_MS = void 0;
14
- const node_crypto_1 = require("node:crypto");
15
- /** How long the built-in remembers a write. */
16
- exports.REMEMBERED_MS = 3_600_000;
17
- function fingerprint(record) {
18
- return (0, node_crypto_1.createHash)('sha256').update(JSON.stringify(record) ?? 'null').digest('hex');
19
- }
20
- /** The built-in, in this process. */
21
- class FingerprintGuard {
22
- remembered = new Map();
23
- async recordWrite(write) {
24
- const now = Date.now();
25
- for (const [key, one] of this.remembered)
26
- if (one.expiresAt <= now)
27
- this.remembered.delete(key);
28
- this.remembered.set(JSON.stringify([write.adapter, write.externalId, write.writer]), { fingerprint: fingerprint(write.record), expiresAt: now + exports.REMEMBERED_MS });
29
- }
30
- }
31
- exports.FingerprintGuard = FingerprintGuard;
@@ -1,12 +0,0 @@
1
- import { type SlotAddress } from '@listen-fire/module-runtime/module_wire/wire';
2
- import type { LoopGuard, RecordWrite } from './loop_guard';
3
- export declare class RpcLoopGuard implements LoopGuard {
4
- private readonly started;
5
- /** The guard module `command` starts, or the one already at `address`. */
6
- constructor(command: string, args: readonly string[]);
7
- constructor(address: SlotAddress);
8
- private call;
9
- open(settings?: Record<string, string>): Promise<void>;
10
- recordWrite(write: RecordWrite): Promise<void>;
11
- close(): Promise<void>;
12
- }
@@ -1,34 +0,0 @@
1
- "use strict";
2
- // A loop guard a loop guard module serves: the slot's methods
3
- // (docs/contracts/loop-guard-slot.md) carried as adapter protocol 2 calls
4
- // over HTTP (a Unix socket on this box). How the contract suite
5
- // (contract.ts) holds listen-fire's guard (`listen-fire --contract-guard`), and a guard module
6
- // listen-fire drives, to the meaning every guard has.
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.RpcLoopGuard = void 0;
9
- const zod_1 = require("zod");
10
- const wire_1 = require("@listen-fire/module-runtime/module_wire/wire");
11
- const Nothing = zod_1.z.null();
12
- class RpcLoopGuard {
13
- started;
14
- constructor(target, args = []) {
15
- this.started =
16
- typeof target === 'string'
17
- ? (0, wire_1.startModule)(target, args).then((module) => ({ client: new wire_1.SlotClient(module.address), close: () => module.close() }))
18
- : Promise.resolve({ client: new wire_1.SlotClient(target), close: async () => undefined });
19
- this.started.catch(() => undefined);
20
- }
21
- async call(method, params, schema) {
22
- return (await this.started).client.read(method, params, schema);
23
- }
24
- async open(settings = {}) {
25
- await this.call('guard.open', { settings }, Nothing);
26
- }
27
- async recordWrite(write) {
28
- await this.call('guard.recordWrite', write, Nothing);
29
- }
30
- async close() {
31
- await (await this.started.catch(() => undefined))?.close();
32
- }
33
- }
34
- exports.RpcLoopGuard = RpcLoopGuard;
@@ -1,16 +0,0 @@
1
- import type { DiscriminableEvent, EventType } from '../adapter';
2
- import type { TriggerType } from '@listen-fire/engine-contracts/mutation_context';
3
- import type { TriggerEvent } from './types';
4
- /** @deprecated The 0.12 trigger, which no 0.13 host makes: build a run's
5
- * event with `arrivalTriggerOf` (listen_plans.ts). Removed in 0.14.0. */
6
- export declare function triggerEventOf(input: {
7
- pipelineInputId: string;
8
- adapterType: string;
9
- triggerType: TriggerType;
10
- event: DiscriminableEvent;
11
- eventTypes: readonly EventType[];
12
- now: Date;
13
- }): {
14
- triggerEvent: TriggerEvent;
15
- discriminated: boolean;
16
- };
@@ -1,50 +0,0 @@
1
- "use strict";
2
- // An inbound event as the engine is handed it: discriminated into a concrete
3
- // root type (honouring a pre-set `tag`), so the engine seeds a typed record
4
- // position rather than the raw payload. Every shell builds the TriggerEvent
5
- // here, so an event reaches a run the same way in each.
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.triggerEventOf = triggerEventOf;
8
- const discriminate_1 = require("../engine/inbound/discriminate");
9
- /** @deprecated The 0.12 trigger, which no 0.13 host makes: build a run's
10
- * event with `arrivalTriggerOf` (listen_plans.ts). Removed in 0.14.0. */
11
- function triggerEventOf(input) {
12
- const { adapterType, triggerType, event, eventTypes, now } = input;
13
- let rootRecordType;
14
- if (eventTypes.length > 0) {
15
- const discriminated = (0, discriminate_1.discriminateEvent)({ adapterType, event, eventTypes });
16
- if (discriminated)
17
- rootRecordType = discriminated.eventType.positionType;
18
- }
19
- // The external-side record type: the source's own type id when the adapter
20
- // names it directly (Attio's object id), else the discriminated position
21
- // type (the poll path's behaviour).
22
- const externalRecordRefType = event.recordType ?? rootRecordType;
23
- const triggerEvent = {
24
- pipelineInputId: input.pipelineInputId,
25
- adapterType,
26
- triggerType,
27
- payload: event.payload,
28
- ...(event.changeType ? { changeType: event.changeType } : {}),
29
- ...(rootRecordType ? { rootRecordType } : {}),
30
- // A mutation event is about a record the host itself keeps (a store's
31
- // node), so it anchors by the host's id; every other event names the
32
- // source system's record.
33
- ...(event.externalId !== undefined
34
- ? triggerType === 'mutation'
35
- ? { recordId: event.externalId }
36
- : {
37
- externalRecordRef: {
38
- adapterType,
39
- externalId: event.externalId,
40
- ...(externalRecordRefType ? { recordType: externalRecordRefType } : {}),
41
- },
42
- }
43
- : {}),
44
- ...(event.actor ? { actor: event.actor } : {}),
45
- ...(event.changedFields ? { changedFields: event.changedFields } : {}),
46
- ...(event.idempotencyKey ? { idempotencyKey: event.idempotencyKey } : {}),
47
- occurredAt: event.occurredAt ?? now.toISOString(),
48
- };
49
- return { triggerEvent, discriminated: rootRecordType !== undefined };
50
- }