@listen-fire/engine 0.13.0 → 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.
- package/dist/public/inbound.d.ts +0 -1
- package/dist/public/inbound.js +0 -1
- package/dist/services/embed/in_process_host.js +10 -1
- package/dist/services/inbound/contract.js +3 -3
- package/dist/services/inbound/deliver.d.ts +2 -1
- package/dist/services/inbound/deliver.js +3 -1
- package/dist/services/translation_graph/engine/adapter_table.d.ts +6 -0
- package/dist/services/translation_graph/engine/adapter_table.js +8 -0
- package/dist/services/translation_graph/movement/catalog_snapshot.d.ts +4 -0
- package/dist/services/translation_graph/movement/catalog_snapshot.js +1 -0
- package/dist/services/translation_graph/triggers/listen_plans.d.ts +10 -6
- package/dist/services/translation_graph/triggers/listen_plans.js +20 -13
- package/package.json +4 -4
- package/dist/services/loop_guard/contract.d.ts +0 -6
- package/dist/services/loop_guard/contract.js +0 -90
- package/dist/services/loop_guard/loop_guard.d.ts +0 -42
- package/dist/services/loop_guard/loop_guard.js +0 -47
- package/dist/services/loop_guard/rpc_loop_guard.d.ts +0 -13
- package/dist/services/loop_guard/rpc_loop_guard.js +0 -38
- package/dist/services/translation_graph/triggers/trigger_event.d.ts +0 -14
- package/dist/services/translation_graph/triggers/trigger_event.js +0 -48
package/dist/public/inbound.d.ts
CHANGED
|
@@ -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';
|
package/dist/public/inbound.js
CHANGED
|
@@ -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);
|
|
@@ -92,7 +92,16 @@ function inProcessHost(options = {}) {
|
|
|
92
92
|
return (0, host_kit_1.actingPrincipalOf)(await resolve({
|
|
93
93
|
teamId: segments.facts(segmentId).teamId,
|
|
94
94
|
...(triggerId !== undefined ? { triggerId } : {}),
|
|
95
|
-
|
|
95
|
+
// The module's own candidates where it offers them (an API lookup,
|
|
96
|
+
// a mail's relays); else who acted on the arrival, as its module
|
|
97
|
+
// said at the door (adapter protocol 2.7).
|
|
98
|
+
getCandidates: async () => {
|
|
99
|
+
if (table.offers({ segmentId, instance, method: 'getActorCandidates' })) {
|
|
100
|
+
return table.answer({ segmentId, instance, method: 'getActorCandidates', args: { event } });
|
|
101
|
+
}
|
|
102
|
+
const actor = event.arrival?.actor;
|
|
103
|
+
return actor === undefined ? [] : [{ identity: actor, source: 'originator' }];
|
|
104
|
+
},
|
|
96
105
|
}));
|
|
97
106
|
},
|
|
98
107
|
},
|
|
@@ -210,11 +210,11 @@ exports.INBOUND_CONTRACT_CASES = [
|
|
|
210
210
|
},
|
|
211
211
|
},
|
|
212
212
|
{
|
|
213
|
-
name: 'arrivals are logged whether or not any event came with them',
|
|
213
|
+
name: 'arrivals are logged whether or not any event came with them, and counted in the acknowledgement',
|
|
214
214
|
async run(backend) {
|
|
215
215
|
await arrangeAnd(backend);
|
|
216
216
|
const answer = await post(backend, CRM_DOOR, json({ arrivals: [ARRIVAL, GONE] }), crmSigned);
|
|
217
|
-
strict_1.default.deepEqual([answer.status, answer.body], [200, { ok: true, eventsProcessed:
|
|
217
|
+
strict_1.default.deepEqual([answer.status, answer.body], [200, { ok: true, eventsProcessed: 2 }]);
|
|
218
218
|
strict_1.default.deepEqual((await backend.observed()).arrivals, [ARRIVAL, GONE]);
|
|
219
219
|
},
|
|
220
220
|
},
|
|
@@ -246,7 +246,7 @@ exports.INBOUND_CONTRACT_CASES = [
|
|
|
246
246
|
strict_1.default.deepEqual([failed.status, failed.body], [500, { error: 'internal' }]);
|
|
247
247
|
strict_1.default.deepEqual((await backend.observed()).arrivals, []);
|
|
248
248
|
const retried = await post(backend, CRM_DOOR, delivery, crmSigned);
|
|
249
|
-
strict_1.default.deepEqual([retried.status, retried.body], [200, { ok: true, eventsProcessed:
|
|
249
|
+
strict_1.default.deepEqual([retried.status, retried.body], [200, { ok: true, eventsProcessed: 3 }]);
|
|
250
250
|
const seen = await backend.observed();
|
|
251
251
|
strict_1.default.deepEqual([seen.enqueued, seen.arrivals], [2, [ARRIVAL]]);
|
|
252
252
|
},
|
|
@@ -130,7 +130,8 @@ export type ReceivedDelivery<Captured> = {
|
|
|
130
130
|
reply: InboundAnswer;
|
|
131
131
|
} | {
|
|
132
132
|
ok: true;
|
|
133
|
-
/**
|
|
133
|
+
/** What the delivery brought: the events captured (receipted and
|
|
134
|
+
* ready to run) and the arrivals it reported. */
|
|
134
135
|
eventsProcessed: number;
|
|
135
136
|
/** The delivery's one write, made before the ack. Absent when the
|
|
136
137
|
* delivery carried nothing to run or log. Rejects when it could not
|
|
@@ -118,7 +118,9 @@ async function receiveDelivery(store, delivery) {
|
|
|
118
118
|
};
|
|
119
119
|
return {
|
|
120
120
|
ok: true,
|
|
121
|
-
|
|
121
|
+
// A module reports arrivals since 0.13: counting its events alone
|
|
122
|
+
// answered 0 for every delivery.
|
|
123
|
+
eventsProcessed: captured.length + arrivals.length,
|
|
122
124
|
queue,
|
|
123
125
|
...(store.verifiesSignature(subscription) ? {} : { drainFirst: true }),
|
|
124
126
|
...(replyOnceKept !== undefined ? { replyOnceKept } : {}),
|
|
@@ -36,6 +36,12 @@ export interface AdapterTable extends HostAdapters {
|
|
|
36
36
|
/** A call the host makes itself (the acting-user lookup asks the source
|
|
37
37
|
* instance for the event's actors): its result, or its failure thrown. */
|
|
38
38
|
answer<M extends AdapterMethod>(input: AdapterCall<M>): Promise<AdapterCallMap[M]['result']>;
|
|
39
|
+
/** Whether an instance the segment holds offers `method`. */
|
|
40
|
+
offers(input: {
|
|
41
|
+
segmentId: string;
|
|
42
|
+
instance: string;
|
|
43
|
+
method: AdapterMethod;
|
|
44
|
+
}): boolean;
|
|
39
45
|
/** Forget a segment's instances once the segment has closed. */
|
|
40
46
|
closeSegment(segmentId: string): void;
|
|
41
47
|
/** The instances a segment holds, as a file's owner is found among them. */
|
|
@@ -174,6 +174,10 @@ class SegmentInstances {
|
|
|
174
174
|
(owner.constructionArgs === undefined || args(resolution.constructionArgs) === args(owner.constructionArgs)));
|
|
175
175
|
return matching.length === 1 ? matching[0]?.adapter : undefined;
|
|
176
176
|
}
|
|
177
|
+
/** The instance resolved as `id`, if it was. */
|
|
178
|
+
found(id) {
|
|
179
|
+
return this.byId.get(id);
|
|
180
|
+
}
|
|
177
181
|
instance(id) {
|
|
178
182
|
const adapter = this.byId.get(id);
|
|
179
183
|
if (adapter === undefined) {
|
|
@@ -259,6 +263,10 @@ function adapterTable(options) {
|
|
|
259
263
|
});
|
|
260
264
|
},
|
|
261
265
|
call,
|
|
266
|
+
offers({ segmentId, instance, method }) {
|
|
267
|
+
const adapter = instances.get(segmentId)?.found(instance);
|
|
268
|
+
return adapter !== undefined && typeof Reflect.get(adapter, method) === 'function';
|
|
269
|
+
},
|
|
262
270
|
async answer(input) {
|
|
263
271
|
const answered = await call(input);
|
|
264
272
|
if ('error' in answered)
|
|
@@ -26,6 +26,10 @@ export interface CatalogAdapterInput {
|
|
|
26
26
|
/** How the adapter is connected — a product-shell fact (the hosted product's
|
|
27
27
|
* connect links); absent where the shell has no such affordance. */
|
|
28
28
|
connect?: AdapterSpec['connect'];
|
|
29
|
+
/** The package the host installed the module from (`@lf/github`), which a
|
|
30
|
+
* program's `connect` names it by; absent for a host's own module, named
|
|
31
|
+
* `#` and its adapter type. */
|
|
32
|
+
package?: string;
|
|
29
33
|
/** Instance schemas by `instanceSchemaKey`; absent ⇒ none introspected yet. */
|
|
30
34
|
schemas?: Record<string, InstanceSchema>;
|
|
31
35
|
/** Why a schema is missing, keyed like `schemas`. */
|
|
@@ -56,6 +56,7 @@ function adapterSnapshotOf(input) {
|
|
|
56
56
|
.map((b) => ({ kind: b.actionKind, label: b.label }));
|
|
57
57
|
return {
|
|
58
58
|
constructionArgs: input.constructionArgs ?? constructionArgsOf(manifest),
|
|
59
|
+
...(input.package !== undefined ? { package: input.package } : {}),
|
|
59
60
|
...(manifest.declaredCredentials !== undefined ? { declaredCredentials: [...manifest.declaredCredentials] } : {}),
|
|
60
61
|
// A construction-free manifest fact: an adapter that names no trigger
|
|
61
62
|
// type has no inbound surface to listen to. Only `true` projects — see
|
|
@@ -131,18 +131,19 @@ export declare function namedArrival(arrival: Exclude<Arrival, {
|
|
|
131
131
|
}>;
|
|
132
132
|
/** The edges a fired function waits on off the records its run is handed at
|
|
133
133
|
* delivery: off the trigger itself (`own`), and off each record the
|
|
134
|
-
* arrival carries,
|
|
134
|
+
* arrival carries, by the record type it states (`carried`): an arrival
|
|
135
|
+
* that fires carries each record of the type its hop lands on, whichever
|
|
136
|
+
* member of a union it is under. */
|
|
135
137
|
export interface TriggerAwaits {
|
|
136
138
|
own: string[];
|
|
137
|
-
carried: string[]
|
|
139
|
+
carried: Readonly<Record<string, readonly string[]>>;
|
|
138
140
|
}
|
|
139
141
|
/** The edges the check stamps on the parameter of the function `plan` fires,
|
|
140
142
|
* which `program` declares: where a run of it enters its trigger, and so
|
|
141
143
|
* the waits a delivery opens for the run as it is kept
|
|
142
144
|
* (crates/lf/src/routing.rs `trigger_awaits_of`). Those awaited off the
|
|
143
145
|
* trigger (`opensWaits`), and off each record type the arrival carries
|
|
144
|
-
* (`carriedAwaits`),
|
|
145
|
-
* carried hop lands on. `stamps` is the check's of `program`. */
|
|
146
|
+
* (`carriedAwaits`), by that type. `stamps` is the check's of `program`. */
|
|
146
147
|
export declare function triggerAwaitsOf(input: {
|
|
147
148
|
program: Program;
|
|
148
149
|
stamps: CheckAnswer['stamps'];
|
|
@@ -155,8 +156,11 @@ export declare function arrivalReceiptKey(arrival: Exclude<Arrival, {
|
|
|
155
156
|
gone: true;
|
|
156
157
|
}>): string;
|
|
157
158
|
/** The event a run fired by an arrival is handed: what landed on the
|
|
158
|
-
* listen's last edge, which its function's parameter binds,
|
|
159
|
-
*
|
|
159
|
+
* listen's last edge, which its function's parameter binds, what it carries,
|
|
160
|
+
* what it is about and who acted; stamped with when it happened at its
|
|
161
|
+
* provider, else `now`, so the run's writes say when the change they follow
|
|
162
|
+
* happened (crates/lf/src/routing.rs `arrival_trigger_of`; both read
|
|
163
|
+
* engine-contracts/conformance/arrival-triggers.json). */
|
|
160
164
|
export declare function arrivalTriggerOf(input: {
|
|
161
165
|
pipelineInputId: string;
|
|
162
166
|
adapterType: string;
|
|
@@ -169,7 +169,7 @@ function plannedListensOf(input) {
|
|
|
169
169
|
*/
|
|
170
170
|
function listenFires(listen, arrival, delivery, nowMs) {
|
|
171
171
|
const { plan } = listen;
|
|
172
|
-
if ('gone' in arrival || plan.adapter !== delivery.adapterType ||
|
|
172
|
+
if ('gone' in arrival || plan.adapter !== delivery.adapterType || (0, engine_contracts_1.lastEdgeOf)(plan) !== arrival.edge)
|
|
173
173
|
return null;
|
|
174
174
|
if (!(0, listen_config_1.listenHearsCredential)(listen.credentialName, delivery.credentialName) || arrival.notFor === listen.pipeline)
|
|
175
175
|
return null;
|
|
@@ -241,22 +241,17 @@ function arrivedRecord(landing) {
|
|
|
241
241
|
* the waits a delivery opens for the run as it is kept
|
|
242
242
|
* (crates/lf/src/routing.rs `trigger_awaits_of`). Those awaited off the
|
|
243
243
|
* trigger (`opensWaits`), and off each record type the arrival carries
|
|
244
|
-
* (`carriedAwaits`),
|
|
245
|
-
* carried hop lands on. `stamps` is the check's of `program`. */
|
|
244
|
+
* (`carriedAwaits`), by that type. `stamps` is the check's of `program`. */
|
|
246
245
|
function triggerAwaitsOf(input) {
|
|
247
246
|
const { plan } = input;
|
|
248
247
|
const index = input.program.statements.findIndex((statement) => statement.kind === 'movement' && statement.name === plan.movement);
|
|
249
248
|
if (index === -1)
|
|
250
|
-
return { own: [], carried:
|
|
249
|
+
return { own: [], carried: {} };
|
|
251
250
|
const path = `/statements/${index}/params/0`;
|
|
252
251
|
const onParam = input.stamps.filter((stamp) => stamp.file === undefined && stamp.path === path);
|
|
253
252
|
// The parameter's one stamp of each, as listen-fire reads them (`trigger_awaits_of`).
|
|
254
253
|
const own = onParam.flatMap((stamp) => ('opensWaits' in stamp ? [[...stamp.opensWaits]] : []))[0] ?? [];
|
|
255
|
-
const
|
|
256
|
-
const carried = (plan.carries ?? []).map((edge) => {
|
|
257
|
-
const landed = plan.hops.find((hop) => hop.edge === edge)?.to;
|
|
258
|
-
return landed === undefined ? [] : [...(byType[landed] ?? [])];
|
|
259
|
-
});
|
|
254
|
+
const carried = onParam.flatMap((stamp) => ('carriedAwaits' in stamp ? [stamp.carriedAwaits] : []))[0] ?? {};
|
|
260
255
|
return { own, carried };
|
|
261
256
|
}
|
|
262
257
|
/** The receipt a listen takes of `arrival` as it runs it, so a redelivery
|
|
@@ -266,15 +261,27 @@ function arrivalReceiptKey(arrival) {
|
|
|
266
261
|
return `${arrival.edge}:${arrival.key ?? ''}:${arrival.identity}:${arrival.version ?? ''}`;
|
|
267
262
|
}
|
|
268
263
|
/** The event a run fired by an arrival is handed: what landed on the
|
|
269
|
-
* listen's last edge, which its function's parameter binds,
|
|
270
|
-
*
|
|
264
|
+
* listen's last edge, which its function's parameter binds, what it carries,
|
|
265
|
+
* what it is about and who acted; stamped with when it happened at its
|
|
266
|
+
* provider, else `now`, so the run's writes say when the change they follow
|
|
267
|
+
* happened (crates/lf/src/routing.rs `arrival_trigger_of`; both read
|
|
268
|
+
* engine-contracts/conformance/arrival-triggers.json). */
|
|
271
269
|
function arrivalTriggerOf(input) {
|
|
272
270
|
const { adapterType, arrival } = input;
|
|
271
|
+
const occurred = arrival.occurredAt === undefined ? undefined : new Date(arrival.occurredAt);
|
|
272
|
+
const occurredAt = occurred !== undefined && !Number.isNaN(occurred.getTime()) ? occurred : input.now;
|
|
273
273
|
return {
|
|
274
274
|
pipelineInputId: input.pipelineInputId,
|
|
275
275
|
adapterType,
|
|
276
276
|
triggerType: 'arrival',
|
|
277
|
-
arrival: {
|
|
278
|
-
|
|
277
|
+
arrival: {
|
|
278
|
+
adapterType,
|
|
279
|
+
edge: arrival.edge,
|
|
280
|
+
landing: arrival.landing,
|
|
281
|
+
...(arrival.parents !== undefined && arrival.parents.length > 0 ? { parents: arrival.parents } : {}),
|
|
282
|
+
...(arrival.about !== undefined ? { about: arrival.about } : {}),
|
|
283
|
+
...(arrival.actor !== undefined ? { actor: arrival.actor } : {}),
|
|
284
|
+
},
|
|
285
|
+
occurredAt: occurredAt.toISOString(),
|
|
279
286
|
};
|
|
280
287
|
}
|
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.
|
|
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,9 +17,9 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"safe-stable-stringify": "2.5.0",
|
|
19
19
|
"zod": "4.1.12",
|
|
20
|
-
"@listen-fire/engine-contracts": "^0.
|
|
21
|
-
"@listen-fire/
|
|
22
|
-
"@listen-fire/
|
|
20
|
+
"@listen-fire/engine-contracts": "^0.14.0",
|
|
21
|
+
"@listen-fire/movement-lang": "^0.14.0",
|
|
22
|
+
"@listen-fire/module-runtime": "^0.12.8"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/jest": "29.5.14",
|
|
@@ -1,90 +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. How long a guard remembers is its own business, so no
|
|
7
|
-
// case waits on it.
|
|
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
|
-
async function isEcho(guard, question) {
|
|
26
|
-
return guard.isEcho(question);
|
|
27
|
-
}
|
|
28
|
-
exports.loopGuardContractCases = [
|
|
29
|
-
{
|
|
30
|
-
name: 'a record nothing was written to is no echo, and needs no read',
|
|
31
|
-
async run(guard) {
|
|
32
|
-
const { adapter, externalId } = aRecord();
|
|
33
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER }), { echo: false });
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: 'a written record asks to be read, and unchanged is the writer\'s echo',
|
|
38
|
-
async run(guard) {
|
|
39
|
-
const one = aRecord();
|
|
40
|
-
await guard.recordWrite({ ...one, writer: WRITER, record: seen });
|
|
41
|
-
const { adapter, externalId } = one;
|
|
42
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER }), { read: { recordType: 'Companies' } });
|
|
43
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER, current: { recordType: 'Companies', record: structuredClone(seen) } }), { echo: true });
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: 'a record changed since the write is not an echo',
|
|
48
|
-
async run(guard) {
|
|
49
|
-
const one = aRecord();
|
|
50
|
-
await guard.recordWrite({ ...one, writer: WRITER, record: seen });
|
|
51
|
-
const { adapter, externalId } = one;
|
|
52
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER, current: { recordType: 'Companies', record: edited } }), { echo: false });
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: 'the write is the echo for its writer only, on its record only',
|
|
57
|
-
async run(guard) {
|
|
58
|
-
const one = aRecord();
|
|
59
|
-
await guard.recordWrite({ ...one, writer: WRITER, record: seen });
|
|
60
|
-
const { adapter, externalId } = one;
|
|
61
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: 'listen:audit:log' }), { echo: false });
|
|
62
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId: `${externalId}-other`, writer: WRITER }), { echo: false });
|
|
63
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter: 'airtable', externalId, writer: WRITER }), { echo: false });
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: 'the same writer\'s later write replaces the earlier one, and a writer\'s own writes do not touch another\'s',
|
|
68
|
-
async run(guard) {
|
|
69
|
-
const one = aRecord();
|
|
70
|
-
const { adapter, externalId } = one;
|
|
71
|
-
await guard.recordWrite({ ...one, writer: WRITER, record: seen });
|
|
72
|
-
await guard.recordWrite({ ...one, writer: 'listen:audit:log', record: edited });
|
|
73
|
-
await guard.recordWrite({ ...one, writer: WRITER, record: edited });
|
|
74
|
-
const now = { recordType: 'Companies', record: structuredClone(seen) };
|
|
75
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER, current: now }), { echo: false });
|
|
76
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER, current: { ...now, record: edited } }), { echo: true });
|
|
77
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: 'listen:audit:log', current: { ...now, record: edited } }), { echo: true });
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
name: 'a record that is gone can be the echo of its own deletion',
|
|
82
|
-
async run(guard) {
|
|
83
|
-
const one = aRecord();
|
|
84
|
-
const { adapter, externalId } = one;
|
|
85
|
-
await guard.recordWrite({ ...one, writer: WRITER, record: null });
|
|
86
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER, current: { recordType: 'Companies', record: null } }), { echo: true });
|
|
87
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER, current: { recordType: 'Companies', record: seen } }), { echo: false });
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
];
|
|
@@ -1,42 +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
|
-
/** Whether an event naming `externalId` is the echo of `writer`'s write.
|
|
11
|
-
* `current` is the record as it stands now, sent once the guard has said
|
|
12
|
-
* which type to read. */
|
|
13
|
-
export interface EchoQuestion {
|
|
14
|
-
adapter: string;
|
|
15
|
-
externalId: string;
|
|
16
|
-
writer: string;
|
|
17
|
-
current?: {
|
|
18
|
-
recordType: string;
|
|
19
|
-
record: unknown;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/** `echo`: the answer. `read`: the guard needs `current` of this type to say. */
|
|
23
|
-
export type EchoAnswer = {
|
|
24
|
-
echo: boolean;
|
|
25
|
-
} | {
|
|
26
|
-
read: {
|
|
27
|
-
recordType: string;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
export interface LoopGuard {
|
|
31
|
-
/** `writer`'s write, remembered; its later write to the same record replaces it. */
|
|
32
|
-
recordWrite(write: RecordWrite): Promise<void>;
|
|
33
|
-
isEcho(question: EchoQuestion): Promise<EchoAnswer>;
|
|
34
|
-
}
|
|
35
|
-
/** How long the built-in remembers a write. */
|
|
36
|
-
export declare const REMEMBERED_MS = 3600000;
|
|
37
|
-
/** The built-in, in this process. */
|
|
38
|
-
export declare class FingerprintGuard implements LoopGuard {
|
|
39
|
-
private readonly remembered;
|
|
40
|
-
recordWrite(write: RecordWrite): Promise<void>;
|
|
41
|
-
isEcho(question: EchoQuestion): Promise<EchoAnswer>;
|
|
42
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// The loop guard slot: a module that keeps a run's own writes from firing it
|
|
3
|
-
// again (plans/cloud-native-2026-10-06/22_everywhere_plan.md, Henry
|
|
4
|
-
// 2026-10-18). Empty unless a project names one in `core:`; with none, a
|
|
5
|
-
// movement that writes to a source it listens to hears its own write come
|
|
6
|
-
// back and runs again. The platform's opt-in `suppress_self` listen flag is
|
|
7
|
-
// separate and unchanged.
|
|
8
|
-
//
|
|
9
|
-
// The host reads a record back after a run writes it (`recordWrite`) and,
|
|
10
|
-
// when an inbound event names a record, asks whether the event is the echo
|
|
11
|
-
// of that listen's own write (`isEcho`). Everything else is the guard's: how
|
|
12
|
-
// long it remembers, what "unchanged" means, where its memory lives. The
|
|
13
|
-
// contract is docs/contracts/loop-guard-slot.md; the built-in,
|
|
14
|
-
// `@lf/fingerprint-guard`, is `FingerprintGuard` here and in listen-fire
|
|
15
|
-
// (crates/lf/src/loop_guard.rs).
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.FingerprintGuard = exports.REMEMBERED_MS = void 0;
|
|
18
|
-
const node_crypto_1 = require("node:crypto");
|
|
19
|
-
/** How long the built-in remembers a write. */
|
|
20
|
-
exports.REMEMBERED_MS = 3_600_000;
|
|
21
|
-
function fingerprint(record) {
|
|
22
|
-
return (0, node_crypto_1.createHash)('sha256').update(JSON.stringify(record) ?? 'null').digest('hex');
|
|
23
|
-
}
|
|
24
|
-
/** The built-in, in this process. */
|
|
25
|
-
class FingerprintGuard {
|
|
26
|
-
remembered = new Map();
|
|
27
|
-
async recordWrite(write) {
|
|
28
|
-
const now = Date.now();
|
|
29
|
-
for (const [key, one] of this.remembered)
|
|
30
|
-
if (one.expiresAt <= now)
|
|
31
|
-
this.remembered.delete(key);
|
|
32
|
-
this.remembered.set(JSON.stringify([write.adapter, write.externalId, write.writer]), {
|
|
33
|
-
recordType: write.recordType,
|
|
34
|
-
fingerprint: fingerprint(write.record),
|
|
35
|
-
expiresAt: now + exports.REMEMBERED_MS,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
async isEcho(question) {
|
|
39
|
-
const one = this.remembered.get(JSON.stringify([question.adapter, question.externalId, question.writer]));
|
|
40
|
-
if (one === undefined || one.expiresAt <= Date.now())
|
|
41
|
-
return { echo: false };
|
|
42
|
-
if (question.current === undefined)
|
|
43
|
-
return { read: { recordType: one.recordType } };
|
|
44
|
-
return { echo: fingerprint(question.current.record) === one.fingerprint };
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.FingerprintGuard = FingerprintGuard;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type SlotAddress } from '@listen-fire/module-runtime/module_wire/wire';
|
|
2
|
-
import type { EchoAnswer, EchoQuestion, 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
|
-
isEcho(question: EchoQuestion): Promise<EchoAnswer>;
|
|
12
|
-
close(): Promise<void>;
|
|
13
|
-
}
|
|
@@ -1,38 +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 Answer = zod_1.z.union([zod_1.z.object({ echo: zod_1.z.boolean() }), zod_1.z.object({ read: zod_1.z.object({ recordType: zod_1.z.string() }) })]);
|
|
12
|
-
const Nothing = zod_1.z.null();
|
|
13
|
-
class RpcLoopGuard {
|
|
14
|
-
started;
|
|
15
|
-
constructor(target, args = []) {
|
|
16
|
-
this.started =
|
|
17
|
-
typeof target === 'string'
|
|
18
|
-
? (0, wire_1.startModule)(target, args).then((module) => ({ client: new wire_1.SlotClient(module.address), close: () => module.close() }))
|
|
19
|
-
: Promise.resolve({ client: new wire_1.SlotClient(target), close: async () => undefined });
|
|
20
|
-
this.started.catch(() => undefined);
|
|
21
|
-
}
|
|
22
|
-
async call(method, params, schema) {
|
|
23
|
-
return (await this.started).client.read(method, params, schema);
|
|
24
|
-
}
|
|
25
|
-
async open(settings = {}) {
|
|
26
|
-
await this.call('guard.open', { settings }, Nothing);
|
|
27
|
-
}
|
|
28
|
-
async recordWrite(write) {
|
|
29
|
-
await this.call('guard.recordWrite', write, Nothing);
|
|
30
|
-
}
|
|
31
|
-
isEcho(question) {
|
|
32
|
-
return this.call('guard.isEcho', question, Answer);
|
|
33
|
-
}
|
|
34
|
-
async close() {
|
|
35
|
-
await (await this.started.catch(() => undefined))?.close();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.RpcLoopGuard = RpcLoopGuard;
|
|
@@ -1,14 +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
|
-
export declare function triggerEventOf(input: {
|
|
5
|
-
pipelineInputId: string;
|
|
6
|
-
adapterType: string;
|
|
7
|
-
triggerType: TriggerType;
|
|
8
|
-
event: DiscriminableEvent;
|
|
9
|
-
eventTypes: readonly EventType[];
|
|
10
|
-
now: Date;
|
|
11
|
-
}): {
|
|
12
|
-
triggerEvent: TriggerEvent;
|
|
13
|
-
discriminated: boolean;
|
|
14
|
-
};
|
|
@@ -1,48 +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
|
-
function triggerEventOf(input) {
|
|
10
|
-
const { adapterType, triggerType, event, eventTypes, now } = input;
|
|
11
|
-
let rootRecordType;
|
|
12
|
-
if (eventTypes.length > 0) {
|
|
13
|
-
const discriminated = (0, discriminate_1.discriminateEvent)({ adapterType, event, eventTypes });
|
|
14
|
-
if (discriminated)
|
|
15
|
-
rootRecordType = discriminated.eventType.positionType;
|
|
16
|
-
}
|
|
17
|
-
// The external-side record type: the source's own type id when the adapter
|
|
18
|
-
// names it directly (Attio's object id), else the discriminated position
|
|
19
|
-
// type (the poll path's behaviour).
|
|
20
|
-
const externalRecordRefType = event.recordType ?? rootRecordType;
|
|
21
|
-
const triggerEvent = {
|
|
22
|
-
pipelineInputId: input.pipelineInputId,
|
|
23
|
-
adapterType,
|
|
24
|
-
triggerType,
|
|
25
|
-
payload: event.payload,
|
|
26
|
-
...(event.changeType ? { changeType: event.changeType } : {}),
|
|
27
|
-
...(rootRecordType ? { rootRecordType } : {}),
|
|
28
|
-
// A mutation event is about a record the host itself keeps (a store's
|
|
29
|
-
// node), so it anchors by the host's id; every other event names the
|
|
30
|
-
// source system's record.
|
|
31
|
-
...(event.externalId !== undefined
|
|
32
|
-
? triggerType === 'mutation'
|
|
33
|
-
? { recordId: event.externalId }
|
|
34
|
-
: {
|
|
35
|
-
externalRecordRef: {
|
|
36
|
-
adapterType,
|
|
37
|
-
externalId: event.externalId,
|
|
38
|
-
...(externalRecordRefType ? { recordType: externalRecordRefType } : {}),
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
-
: {}),
|
|
42
|
-
...(event.actor ? { actor: event.actor } : {}),
|
|
43
|
-
...(event.changedFields ? { changedFields: event.changedFields } : {}),
|
|
44
|
-
...(event.idempotencyKey ? { idempotencyKey: event.idempotencyKey } : {}),
|
|
45
|
-
occurredAt: event.occurredAt ?? now.toISOString(),
|
|
46
|
-
};
|
|
47
|
-
return { triggerEvent, discriminated: rootRecordType !== undefined };
|
|
48
|
-
}
|