@cnstra/core 3.0.0 → 3.2.1
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/README.md +51 -34
- package/dist/CNS.d.ts +5 -2
- package/dist/CNS.d.ts.map +1 -1
- package/dist/CNSCollateral.d.ts +1 -0
- package/dist/CNSCollateral.d.ts.map +1 -1
- package/dist/CNSInstanceNeuronQueue.d.ts +2 -1
- package/dist/CNSInstanceNeuronQueue.d.ts.map +1 -1
- package/dist/CNSNetwork.d.ts +10 -3
- package/dist/CNSNetwork.d.ts.map +1 -1
- package/dist/CNSStimulation.d.ts +40 -5
- package/dist/CNSStimulation.d.ts.map +1 -1
- package/dist/createCNS.d.ts +4 -0
- package/dist/createCNS.d.ts.map +1 -0
- package/dist/factory/index.d.ts +13 -12
- package/dist/factory/index.d.ts.map +1 -1
- package/dist/index.cjs +512 -254
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +506 -249
- package/dist/index.js.map +1 -1
- package/dist/types/TCNSModalitySelection.d.ts +13 -0
- package/dist/types/TCNSModalitySelection.d.ts.map +1 -0
- package/dist/utils/cnsComposeModalityResponse.d.ts +2 -0
- package/dist/utils/cnsComposeModalityResponse.d.ts.map +1 -0
- package/dist/utils/cnsResolveModalityHandler.d.ts +4 -0
- package/dist/utils/cnsResolveModalityHandler.d.ts.map +1 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -2,27 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
**Orchestration engine for TypeScript — deterministic, embeddable, in-memory.**
|
|
4
4
|
|
|
5
|
-
📚 **[Full Documentation →](https://cnstra.org/)** | [Quick Start](https://cnstra.org/docs/core/quick-start) | [API Reference](https://cnstra.org/docs/core/api) | [Recipes](https://cnstra.org/docs/recipes)
|
|
5
|
+
📚 **[Full Documentation →](https://cnstra.org/)** | [Quick Start](https://cnstra.org/docs/core/quick-start) | [API Reference](https://cnstra.org/docs/core/api) | [Recipes](https://cnstra.org/docs/recipes/saga)
|
|
6
6
|
|
|
7
7
|
## What is CNStra?
|
|
8
8
|
|
|
9
|
-
**CNStra** (Central Nervous System Orchestrator)
|
|
9
|
+
**CNStra** (Central Nervous System Orchestrator) is a library for control flow you can read, type-check, and resume.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
You wire your app's steps into a graph and start a run with a signal. CNStra walks that graph deterministically, one hop at a time — and every hop is visible while it runs and re-drivable after it fails. It's a library, not a service: no server, no broker, no database to stand up, and no third-party dependencies.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
**Isolated units.** A neuron owns one responsibility. Change it and the compiler plus the graph show exactly what it affects — no hidden coupling to grep for, no subscriber you didn't wire yourself.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
- **Signal** — what actually flows through a run.
|
|
15
|
+
**Typed, and exhaustive.** Signals travel on typed collaterals, and the compiler makes you handle every collateral you subscribe to. An incomplete flow doesn't build.
|
|
16
|
+
|
|
17
|
+
**Traceable and resumable.** Devtools show every hop of every run and let you retry one. `@cnstra/persist` records what a run still has left to do, so a process that dies halfway comes back with exactly the unfinished work — not with the whole flow replayed.
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
Which makes it a good fit for:
|
|
21
20
|
|
|
22
21
|
- **Jobs & workers**, **webhooks & integrations**, **ETL / pipelines**
|
|
23
22
|
- **Retries, timeouts, cancellation**, and **saga-style compensations**
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
### The four primitives
|
|
25
|
+
|
|
26
|
+
- **Collateral** — a typed channel; a signal is a payload sent on one.
|
|
27
|
+
- **Neuron** — a unit of logic with one or more dendrites.
|
|
28
|
+
- **Dendrite** — a handler that reacts to a collateral and returns the next signal.
|
|
29
|
+
- **Signal** — what actually flows through a run.
|
|
30
|
+
|
|
31
|
+
A dendrite's returned signal **is** the edge to the next neuron. That's the entire wiring model.
|
|
26
32
|
|
|
27
33
|
👉 **[Read the full documentation →](https://cnstra.org/)**
|
|
28
34
|
|
|
@@ -33,14 +39,14 @@ npm install @cnstra/core
|
|
|
33
39
|
```
|
|
34
40
|
|
|
35
41
|
```typescript
|
|
36
|
-
import { CNS,
|
|
42
|
+
import { CNS, cnsCollateral, cnsNeuron } from '@cnstra/core';
|
|
37
43
|
|
|
38
44
|
// Define collaterals (communication channels)
|
|
39
|
-
const userCreated =
|
|
40
|
-
const userRegistered =
|
|
45
|
+
const userCreated = cnsCollateral<{ id: string; name: string }>();
|
|
46
|
+
const userRegistered = cnsCollateral<{ userId: string; status: string }>();
|
|
41
47
|
|
|
42
48
|
// Create a neuron
|
|
43
|
-
const userService =
|
|
49
|
+
const userService = cnsNeuron({
|
|
44
50
|
userRegistered
|
|
45
51
|
})
|
|
46
52
|
.dendrite({
|
|
@@ -66,62 +72,73 @@ await stimulation.waitUntilComplete();
|
|
|
66
72
|
|
|
67
73
|
## Registry & Naming
|
|
68
74
|
|
|
69
|
-
`CNSPersistOptionsRegistry` maps object references to stable string names — used by devtools, MCP server, and persistence/resume patterns.
|
|
75
|
+
`CNSPersistOptionsRegistry` (from `@cnstra/persist`) maps object references to stable string names — used by devtools, MCP server, and persistence/resume patterns.
|
|
70
76
|
|
|
71
77
|
**Per-file registration (recommended):**
|
|
72
78
|
|
|
73
|
-
```ts
|
|
79
|
+
```ts file=registry.ts
|
|
74
80
|
// src/neurons/registry.ts
|
|
75
|
-
import { CNSPersistOptionsRegistry } from '@cnstra/
|
|
81
|
+
import { CNSPersistOptionsRegistry } from '@cnstra/persist';
|
|
76
82
|
export const registry = new CNSPersistOptionsRegistry();
|
|
83
|
+
```
|
|
77
84
|
|
|
85
|
+
```ts file=deck.ts
|
|
78
86
|
// src/neurons/deck.ts — each neuron registers itself
|
|
79
|
-
import {
|
|
87
|
+
import { cnsCollateral, cnsNeuron } from '@cnstra/core';
|
|
80
88
|
import { registry } from './registry';
|
|
81
89
|
|
|
82
|
-
const deckCreated =
|
|
83
|
-
const importStarted =
|
|
90
|
+
const deckCreated = cnsCollateral<{ deckId: string }>();
|
|
91
|
+
const importStarted = cnsCollateral<{ importId: string }>(); // external entry point
|
|
84
92
|
|
|
85
|
-
const deckNeuron =
|
|
93
|
+
const deckNeuron = cnsNeuron({ deckCreated })
|
|
86
94
|
.bind({ importStarted }, {
|
|
87
95
|
importStarted: ({ importId }, axon) => axon.deckCreated.createSignal({ deckId: importId }),
|
|
88
96
|
});
|
|
89
97
|
|
|
90
98
|
registry
|
|
91
|
-
.register('deckNeuron', deckNeuron)
|
|
92
|
-
.
|
|
93
|
-
.registerCollateral('importStarted', importStarted); // standalone collateral (no neuron)
|
|
99
|
+
.register('deckNeuron', deckNeuron, { deckCreated: 'deck-created' }) // neuron + axon collaterals; default name 'deckNeuron.deckCreated'
|
|
100
|
+
.registerCollateral('importStarted', importStarted); // standalone cnsCollateral (no neuron)
|
|
94
101
|
```
|
|
95
102
|
|
|
96
103
|
**All at once (simple projects):**
|
|
97
104
|
|
|
105
|
+
```ts setup
|
|
106
|
+
import type { TCNSNeuron } from '@cnstra/types';
|
|
107
|
+
|
|
108
|
+
declare const deckNeuron: TCNSNeuron<any>;
|
|
109
|
+
declare const cardNeuron: TCNSNeuron<any>;
|
|
110
|
+
```
|
|
111
|
+
|
|
98
112
|
```ts
|
|
99
|
-
import {
|
|
113
|
+
import { CNSPersistOptionsRegistryFactory } from '@cnstra/persist';
|
|
100
114
|
|
|
101
|
-
export const registry =
|
|
115
|
+
export const registry = CNSPersistOptionsRegistryFactory.create({ deckNeuron, cardNeuron });
|
|
102
116
|
// explicit neuron name: { 'deck-neuron': deckNeuron }
|
|
103
117
|
// explicit collateral names: { 'deck-neuron': { neuron: deckNeuron, collaterals: { deckCreated: 'deck-created' } } }
|
|
118
|
+
// entry collaterals and modalities go in the same object; a nested object is a namespace: { decks: { deckNeuron } } → 'decks.deckNeuron'
|
|
104
119
|
```
|
|
105
120
|
|
|
106
|
-
**CNS + registry from one map:** if you're going to build both, `
|
|
121
|
+
**CNS + registry from one map:** if you're going to build both, `CNSFactory.create` from `@cnstra/factory` lists the
|
|
107
122
|
neuron set once and returns both — they derive from the same map, so the names can never
|
|
108
|
-
drift from the runtime graph. Accepts the same explicit-name syntax as `
|
|
123
|
+
drift from the runtime graph. Accepts the same explicit-name syntax as `CNSPersistOptionsRegistryFactory.create`.
|
|
109
124
|
|
|
110
125
|
```ts
|
|
111
|
-
import {
|
|
126
|
+
import { CNSFactory } from '@cnstra/factory';
|
|
112
127
|
|
|
113
|
-
const { cns, registry } =
|
|
128
|
+
const { cns, registry } = CNSFactory.create({ deckNeuron, cardNeuron });
|
|
114
129
|
// `cns` is the runtime engine; `registry` carries the names for devtools/mcp/persistence.
|
|
115
|
-
// Don't need naming/persistence?
|
|
130
|
+
// Don't need naming/persistence? `new CNS([deckNeuron, cardNeuron])`, or `createCNS(neuronFactories, dependencies)` when the neurons have dependencies.
|
|
116
131
|
```
|
|
117
132
|
|
|
133
|
+
**Neurons with dependencies (recommended):** write each neuron as a factory of its dependencies, in its own file, and build the CNS with `createCNS(neuronFactories, dependencies)`. Every factory gets the same dependencies, and TypeScript checks them against each factory's parameter. See [Dependencies](https://cnstra.org/docs/core/api#dependencies-a-store-a-database-a-clock).
|
|
134
|
+
|
|
118
135
|
## Documentation
|
|
119
136
|
|
|
120
137
|
- **[Quick Start Guide](https://cnstra.org/docs/core/quick-start)** — Get up and running in minutes
|
|
121
138
|
- **[API Reference](https://cnstra.org/docs/core/api)** — Complete API documentation
|
|
122
|
-
- **[Concepts](https://cnstra.org/docs/
|
|
123
|
-
- **[Recipes](https://cnstra.org/docs/recipes)** — Common patterns and use cases
|
|
124
|
-
- **[Advanced Topics](https://cnstra.org/docs/advanced)** — Performance, integrations
|
|
139
|
+
- **[Concepts](https://cnstra.org/docs/concepts/basics)** — Neurons, collaterals, signals, and the CNS model (Central Neural Network of your app)
|
|
140
|
+
- **[Recipes](https://cnstra.org/docs/recipes/saga)** — Common patterns and use cases
|
|
141
|
+
- **[Advanced Topics](https://cnstra.org/docs/advanced/performance)** — Performance, integrations
|
|
125
142
|
|
|
126
143
|
---
|
|
127
144
|
|
package/dist/CNS.d.ts
CHANGED
|
@@ -31,9 +31,11 @@ export declare class CNS<TNeuron extends TCNSNeuron<any>, TDendrite extends TCNS
|
|
|
31
31
|
* Global batch-boundary listeners applied to every stimulation.
|
|
32
32
|
*/
|
|
33
33
|
private readonly globalDrainListeners;
|
|
34
|
+
private batchDepth;
|
|
35
|
+
private batchedDrains;
|
|
34
36
|
/**
|
|
35
37
|
* Shared, app/organism-wide value handed to every dendrite as `ctx.global`.
|
|
36
|
-
* Stored untyped (the type is baked into neurons via `
|
|
38
|
+
* Stored untyped (the type is baked into neurons via `cnsNeuronFactory().withGlobal<T>()`);
|
|
37
39
|
* CNS is just a passthrough carrier, so injecting it here never touches the hot path.
|
|
38
40
|
*/
|
|
39
41
|
readonly global?: unknown;
|
|
@@ -43,13 +45,14 @@ export declare class CNS<TNeuron extends TCNSNeuron<any>, TDendrite extends TCNS
|
|
|
43
45
|
addResponseListener(listener: (response: TCNSStimulationResponse) => void | Promise<void>): () => void;
|
|
44
46
|
/**
|
|
45
47
|
* Register a listener called once at the end of every synchronous turn of
|
|
46
|
-
* every stimulation - see {@link TCNSStimulationDrain}. This is how an
|
|
48
|
+
* every stimulation (inside `batch`, when the batch ends) - see {@link TCNSStimulationDrain}. This is how an
|
|
47
49
|
* integration (a state manager, an in-memory database) installs a single
|
|
48
50
|
* commit point for the whole organism instead of passing `onDrain` per call.
|
|
49
51
|
*
|
|
50
52
|
* Returns an unsubscribe function.
|
|
51
53
|
*/
|
|
52
54
|
addDrainListener(listener: (drain: TCNSStimulationDrain) => void): () => void;
|
|
55
|
+
batch<TResult>(run: () => TResult): TResult;
|
|
53
56
|
/**
|
|
54
57
|
* Fan a drain out to the local and global listeners, or return undefined when
|
|
55
58
|
* there are none so the stimulation can skip the boundary check entirely.
|
package/dist/CNS.d.ts.map
CHANGED
|
@@ -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,WAAW,YAAA,EACrC,MAAM,CAAC,EAAE,OAAO;IAMpB,qEAAqE;IACrE,OAAO,CAAC,WAAW;IAWZ,mBAAmB,CACtB,QAAQ,EAAE,CAAC,QAAQ,EAAE,uBAAuB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACtE,MAAM,IAAI;IAIb;;;;;;;OAOG;IACI,gBAAgB,CACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,GAChD,MAAM,IAAI;IAIN,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,GAAG,OAAO;IAalD;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;IA0BnB,OAAO,CAAC,cAAc;IAiDtB,qFAAqF;IACrF,OAAO,CAAC,iBAAiB;IAYlB,SAAS,CACZ,eAAe,EACT,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,GACnC,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,EAAE,EAC3C,OAAO,CAAC,EAAE,sBAAsB,CAAC,uBAAuB,CAAC,GAC1D,cAAc,CAAC,OAAO,EAAE,SAAS,CAAC;IAMrC;;OAEG;IACI,QAAQ,CACX,KAAK,EAAE,wBAAwB,CAAC,OAAO,CAAC,EAAE,EAC1C,OAAO,CAAC,EAAE,sBAAsB,CAAC,uBAAuB,CAAC,GAC1D,cAAc,CAAC,OAAO,EAAE,SAAS,CAAC;CAKxC"}
|
package/dist/CNSCollateral.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TCNSSignal } from '@cnstra/types';
|
|
2
2
|
import { ICNSCollateral } from '@cnstra/types';
|
|
3
3
|
export declare class CNSCollateral<TPayload> implements ICNSCollateral<TPayload> {
|
|
4
|
+
readonly index: number;
|
|
4
5
|
createSignal(): TCNSSignal<CNSCollateral<TPayload>>;
|
|
5
6
|
createSignal(payload: TPayload): TCNSSignal<CNSCollateral<TPayload>>;
|
|
6
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CNSCollateral.d.ts","sourceRoot":"","sources":["../src/CNSCollateral.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"CNSCollateral.d.ts","sourceRoot":"","sources":["../src/CNSCollateral.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAI/C,qBAAa,aAAa,CAAC,QAAQ,CAAE,YAAW,cAAc,CAAC,QAAQ,CAAC;IACpE,SAAgB,KAAK,SAAyB;IAE9C,YAAY,IAAI,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACnD,YAAY,CAAC,OAAO,EAAE,QAAQ,GAAG,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;CAIvE"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export declare class CNSInstanceNeuronQueue<TNeuron extends {
|
|
2
|
+
readonly index: number;
|
|
2
3
|
concurrency?: number;
|
|
3
4
|
}> {
|
|
4
|
-
private readonly
|
|
5
|
+
private readonly gatesByNeuronIndex;
|
|
5
6
|
run(neuron: TNeuron, fn: () => (() => void) | Promise<() => void>): (() => void) | Promise<() => void>;
|
|
6
7
|
}
|
|
7
8
|
//# sourceMappingURL=CNSInstanceNeuronQueue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CNSInstanceNeuronQueue.d.ts","sourceRoot":"","sources":["../src/CNSInstanceNeuronQueue.ts"],"names":[],"mappings":"AAAA,qBAAa,sBAAsB,CAC/B,OAAO,SAAS;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE;
|
|
1
|
+
{"version":3,"file":"CNSInstanceNeuronQueue.d.ts","sourceRoot":"","sources":["../src/CNSInstanceNeuronQueue.ts"],"names":[],"mappings":"AAAA,qBAAa,sBAAsB,CAC/B,OAAO,SAAS;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE;IAEhE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoE;IAEvG,GAAG,CACC,MAAM,EAAE,OAAO,EACf,EAAE,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,GAC7C,CAAC,MAAM,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC;CAmDxC"}
|
package/dist/CNSNetwork.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ICNSCollateral } from '@cnstra/types';
|
|
1
|
+
import type { ICNSCollateral, TCNSAfferentPath, TCNSModality } from '@cnstra/types';
|
|
2
2
|
import { TCNSNeuron } from '@cnstra/types';
|
|
3
3
|
import { TCNSSubscriber } from '@cnstra/types';
|
|
4
4
|
import { TCNSDendrite } from '@cnstra/types';
|
|
@@ -31,11 +31,14 @@ export declare class CNSNetwork<TNeuron extends TCNSNeuron<any>, TDendrite exten
|
|
|
31
31
|
* Fast lookup: collateral -> list of (neuron, dendrite) subscribers.
|
|
32
32
|
* Built once at construction time.
|
|
33
33
|
*/
|
|
34
|
-
private
|
|
34
|
+
private subscribersByCollateralIndex;
|
|
35
|
+
private allSubscribersByCollateralIndex;
|
|
36
|
+
private modalityCollateralIndices;
|
|
37
|
+
private subscriberTablesByModalityIndex;
|
|
35
38
|
private parentNeuronByCollateral;
|
|
36
39
|
constructor(neurons: TNeuron[]);
|
|
37
40
|
/** Build the SCC analysis the first time anything needs it. */
|
|
38
|
-
private
|
|
41
|
+
private buildSccIndex;
|
|
39
42
|
/**
|
|
40
43
|
* Build the neuron graph where neurons are connected if one can stimulate the other.
|
|
41
44
|
*/
|
|
@@ -68,7 +71,11 @@ export declare class CNSNetwork<TNeuron extends TCNSNeuron<any>, TDendrite exten
|
|
|
68
71
|
* This is the core logic for safe context cleanup.
|
|
69
72
|
*/
|
|
70
73
|
canNeuronBeGuaranteedDone(neuron: TNeuron, activeSccCounts: Map<number, number>): boolean;
|
|
74
|
+
private describeNeuron;
|
|
75
|
+
private describeCollateral;
|
|
71
76
|
private buildIndexes;
|
|
77
|
+
getSubscriberTable(modality: TCNSModality | undefined, afferentPath: TCNSAfferentPath | undefined): TCNSSubscriber<TNeuron, TDendrite>[][];
|
|
78
|
+
private buildSubscriberTable;
|
|
72
79
|
getParentNeuronByCollateral(collateral: ICNSCollateral<unknown>): TNeuron | undefined;
|
|
73
80
|
getDendrites(): TDendrite[];
|
|
74
81
|
getCollaterals(): ICNSCollateral<unknown>[];
|
package/dist/CNSNetwork.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CNSNetwork.d.ts","sourceRoot":"","sources":["../src/CNSNetwork.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"CNSNetwork.d.ts","sourceRoot":"","sources":["../src/CNSNetwork.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAK7C,qBAAa,UAAU,CACnB,OAAO,SAAS,UAAU,CAAC,GAAG,CAAC,EAC/B,SAAS,SAAS,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IA+CjC,OAAO,CAAC,QAAQ,CAAC,OAAO;IA7CpC;;;;;;;OAOG;IACH,OAAO,CAAC,4BAA4B,CAAsB;IAC1D,OAAO,CAAC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UAAU,EAAE,cAAc,CAAC,OAAO,CAAC,GACpC,cAAc,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE;CAM1C"}
|
package/dist/CNSStimulation.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { TCNSSubscriber } from '@cnstra/types';
|
|
|
6
6
|
import { CNSInstanceNeuronQueue } from './CNSInstanceNeuronQueue';
|
|
7
7
|
import { TCNSSignal } from '@cnstra/types';
|
|
8
8
|
import { TCNSNeuronActivationTask } from '@cnstra/types';
|
|
9
|
+
import { TCNSContextStore } from '@cnstra/types';
|
|
9
10
|
import { CNS } from './CNS';
|
|
10
11
|
import { TCNSNeuronActivationTaskFailure } from '@cnstra/types';
|
|
11
12
|
import { TCNSStimulationResponse } from '@cnstra/types';
|
|
@@ -23,7 +24,11 @@ export declare class CNSStimulation<TNeuron extends TCNSNeuron<any>, TDendrite e
|
|
|
23
24
|
private pumping;
|
|
24
25
|
private needsPump;
|
|
25
26
|
private turnDepth;
|
|
26
|
-
private readonly
|
|
27
|
+
private readonly neuronVisitCounts?;
|
|
28
|
+
private readonly subscribersByCollateralIndex;
|
|
29
|
+
/** Read on every dequeue; both are fixed for the life of the stimulation. */
|
|
30
|
+
private readonly concurrencyLimit;
|
|
31
|
+
private readonly abortSignal?;
|
|
27
32
|
private readonly instanceNeuronQueue;
|
|
28
33
|
private scheduledCount;
|
|
29
34
|
private reservedActivations;
|
|
@@ -76,18 +81,33 @@ export declare class CNSStimulation<TNeuron extends TCNSNeuron<any>, TDendrite e
|
|
|
76
81
|
*/
|
|
77
82
|
private endTurn;
|
|
78
83
|
/**
|
|
79
|
-
* Activations that exist (or are reserved) but whose dendrite
|
|
80
|
-
* been invoked yet: sitting in the ring buffer, created and held in
|
|
84
|
+
* Activations that exist (or are reserved) but whose dendrite response has
|
|
85
|
+
* not been invoked yet: sitting in the ring buffer, created and held in
|
|
81
86
|
* pendingTasks, or reserved by an array fan-out mid-dispatch. Subscribers
|
|
82
87
|
* parked behind an async onResponse land here too - their body has not run.
|
|
83
88
|
*/
|
|
84
89
|
private get pendingActivations();
|
|
90
|
+
/**
|
|
91
|
+
* End the run because the machinery itself threw. Dendrite bodies never get
|
|
92
|
+
* here - runStarter catches those and records them as failed tasks; what
|
|
93
|
+
* lands here is a throw from dispatch, today the hop-limit guard in
|
|
94
|
+
* createSubscriberQueueItem. Nothing settles the counters after such a
|
|
95
|
+
* throw, so completion has to be forced: without it the stimulation neither
|
|
96
|
+
* resolves nor rejects, and a worker holds a job that never finishes and
|
|
97
|
+
* never fails.
|
|
98
|
+
*/
|
|
99
|
+
private endRunWithError;
|
|
85
100
|
private tryResolveCompleted;
|
|
86
101
|
waitUntilComplete(): Promise<void>;
|
|
87
102
|
/**
|
|
88
103
|
* Returns all current activation tasks: queued, active, and pending (scheduled but not yet enqueued)
|
|
89
104
|
*/
|
|
90
105
|
getAllActivationTasks(): TCNSNeuronActivationTask<TNeuron>[];
|
|
106
|
+
private getSubscribers;
|
|
107
|
+
private addPositionedTask;
|
|
108
|
+
private removePositionedTask;
|
|
109
|
+
private removeActiveTask;
|
|
110
|
+
private removePendingTask;
|
|
91
111
|
/**
|
|
92
112
|
* Returns all tasks that failed or were aborted
|
|
93
113
|
*/
|
|
@@ -98,6 +118,13 @@ export declare class CNSStimulation<TNeuron extends TCNSNeuron<any>, TDendrite e
|
|
|
98
118
|
* failed/aborted tasks. This is the set to persist for resume: re-activating
|
|
99
119
|
* it re-runs exactly the not-yet-done work. Safe to call at any point during
|
|
100
120
|
* a run (for progress) or after it fails.
|
|
121
|
+
*
|
|
122
|
+
* Each task appears exactly once. The two sources overlap: aborting marks
|
|
123
|
+
* every still-queued task as failed without dequeuing it, so a task sits in
|
|
124
|
+
* the ring buffer AND in failedTasks. Concatenating them blindly handed the
|
|
125
|
+
* broker a checkpoint with the whole queued frontier listed twice, and the
|
|
126
|
+
* resumed run re-executed every one of those tasks a second time - duplicate
|
|
127
|
+
* charges, emails and POSTs on every graceful shutdown.
|
|
101
128
|
*/
|
|
102
129
|
getOutstandingTasks(): TCNSNeuronActivationTask<TNeuron>[];
|
|
103
130
|
/**
|
|
@@ -108,8 +135,16 @@ export declare class CNSStimulation<TNeuron extends TCNSNeuron<any>, TDendrite e
|
|
|
108
135
|
protected createSubscriberQueueItem(subscriber: TCNSSubscriber<TNeuron, TDendrite>, inputSignal?: TCNSSignal<ICNSCollateral<unknown>>): TCNSNeuronActivationTask<TNeuron>;
|
|
109
136
|
private executeActivationTask;
|
|
110
137
|
private runStarter;
|
|
111
|
-
protected processResponseOrResponses(emitter: TNeuron | undefined, inputSignal?: TCNSSignal<ICNSCollateral<unknown>>, outputSignalOrSignals?: TCNSSignal<ICNSCollateral<unknown>> | TCNSSignal<ICNSCollateral<unknown>>[], error?: any): void;
|
|
112
|
-
|
|
138
|
+
protected processResponseOrResponses(emitter: TNeuron | undefined, inputSignal?: TCNSSignal<ICNSCollateral<unknown>>, outputSignalOrSignals?: TCNSSignal<ICNSCollateral<unknown>> | TCNSSignal<ICNSCollateral<unknown>>[], error?: any, startedAt?: number, activationContext?: TCNSContextStore): void;
|
|
139
|
+
/**
|
|
140
|
+
* The one response an aborted run emits: no neuron, no signals, an empty
|
|
141
|
+
* queue. It exists so `queueLength === 0` — the completion condition every
|
|
142
|
+
* listener uses — is reached on the abort path too. Listener errors are
|
|
143
|
+
* swallowed: the run is already over and rejecting, and there is nothing
|
|
144
|
+
* left to fail.
|
|
145
|
+
*/
|
|
146
|
+
private emitAbortedResponse;
|
|
147
|
+
protected processResponse(emitter: TNeuron | undefined, inputSignal?: TCNSSignal<ICNSCollateral<unknown>>, outputSignal?: TCNSSignal<ICNSCollateral<unknown>>, error?: any, startedAt?: number, duration?: number, activationContext?: TCNSContextStore): void;
|
|
113
148
|
responseToSignal(signalOrSignals: TCNSSignal<ICNSCollateral<unknown>> | TCNSSignal<ICNSCollateral<unknown>>[]): void;
|
|
114
149
|
}
|
|
115
150
|
//# sourceMappingURL=CNSStimulation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CNSStimulation.d.ts","sourceRoot":"","sources":["../src/CNSStimulation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"CNSStimulation.d.ts","sourceRoot":"","sources":["../src/CNSStimulation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe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C,EAAE,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,EAClD,KAAK,CAAC,EAAE,GAAG,EACX,SAAS,CAAC,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,EACjB,iBAAiB,CAAC,EAAE,gBAAgB,GACrC,IAAI;IAiKA,gBAAgB,CACnB,eAAe,EACT,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,GACnC,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,EAAE,GAC5C,IAAI;CA0BV"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { TCNSNeuron, TCNSOptions } from '@cnstra/types';
|
|
2
|
+
import { CNS } from './CNS';
|
|
3
|
+
export declare const createCNS: <TDependencies>(neuronFactories: readonly ((dependencies: TDependencies) => TCNSNeuron<any>)[], dependencies: TDependencies, options?: TCNSOptions) => CNS<TCNSNeuron<any>>;
|
|
4
|
+
//# sourceMappingURL=createCNS.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createCNS.d.ts","sourceRoot":"","sources":["../src/createCNS.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,eAAO,MAAM,SAAS,GAAI,aAAa,EACnC,iBAAiB,SAAS,CAAC,CAAC,YAAY,EAAE,aAAa,KAAK,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAC9E,cAAc,aAAa,EAC3B,UAAU,WAAW,KACtB,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAKrB,CAAC"}
|
package/dist/factory/index.d.ts
CHANGED
|
@@ -6,11 +6,12 @@ import { TCNSHandlerContext } from '@cnstra/types';
|
|
|
6
6
|
import { TCNSNeuronResponseReturn } from '@cnstra/types';
|
|
7
7
|
import { TCNSModality } from '@cnstra/types';
|
|
8
8
|
import { TCNSAfferentPath } from '@cnstra/types';
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const cnsCollateral: <TPayload = undefined>() => CNSCollateral<TPayload>;
|
|
10
10
|
type CollateralPayloadUnion<TCollaterals extends readonly ICNSCollateral<unknown>[]> = {
|
|
11
11
|
[K in keyof TCollaterals]: TCollaterals[K] extends ICNSCollateral<infer P> ? P : never;
|
|
12
12
|
}[number];
|
|
13
13
|
type InterNeuronAPI<TAxonType extends TCNSAxon = TCNSAxon, TGlobal = unknown> = {
|
|
14
|
+
readonly index: number;
|
|
14
15
|
axon: TAxonType;
|
|
15
16
|
concurrency?: number;
|
|
16
17
|
maxDuration?: number;
|
|
@@ -58,7 +59,7 @@ type InterNeuronAPI<TAxonType extends TCNSAxon = TCNSAxon, TGlobal = unknown> =
|
|
|
58
59
|
}): InterNeuronAPI<TAxonType, TGlobal>;
|
|
59
60
|
};
|
|
60
61
|
};
|
|
61
|
-
export declare const
|
|
62
|
+
export declare const cnsNeuron: <TProvidedAxon extends Record<string, ICNSCollateral<unknown>>, TGlobal = unknown>(axon: TProvidedAxon) => InterNeuronAPI<TCNSAxon<TProvidedAxon>, TGlobal>;
|
|
62
63
|
/**
|
|
63
64
|
* A composable neuron factory. Each `.withX<T>()` returns a *new typed view* of
|
|
64
65
|
* the same underlying builder (the layers are type-only — zero runtime cost, no
|
|
@@ -69,12 +70,12 @@ export declare const neuron: <TProvidedAxon extends Record<string, ICNSCollatera
|
|
|
69
70
|
* into it, so a base factory (`TExt = unknown`) hands neurons the plain ctx bag —
|
|
70
71
|
* nothing is forced onto anyone who didn't ask for it. `withGlobal<T>()` is the
|
|
71
72
|
* built-in layer; make `T` an object to carry as much as you want (store, clock,
|
|
72
|
-
* logger, …) through the single runtime channel wired at `
|
|
73
|
+
* logger, …) through the single runtime channel wired at `new CNS`/`CNSFactory.create`.
|
|
73
74
|
*
|
|
74
75
|
* @example
|
|
75
76
|
* // src/neurons/factory.ts — ctx shape baked once
|
|
76
77
|
* type TGlobal = { store: Store; now(): number; newId(): string };
|
|
77
|
-
* export const { neuron } =
|
|
78
|
+
* export const { neuron } = cnsNeuronFactory().withGlobal<TGlobal>();
|
|
78
79
|
*
|
|
79
80
|
* // any neuron file — plain value, reaches deps via ctx.global
|
|
80
81
|
* export const taskNeuron = neuron({ taskCreated }).bind({ createTask }, {
|
|
@@ -82,19 +83,19 @@ export declare const neuron: <TProvidedAxon extends Record<string, ICNSCollatera
|
|
|
82
83
|
* axon.taskCreated.createSignal({ id: global.newId(), title, at: global.now() }),
|
|
83
84
|
* });
|
|
84
85
|
*/
|
|
85
|
-
export type
|
|
86
|
-
/** Add `{ global: T }` to ctx; the value is injected once at `
|
|
87
|
-
withGlobal: <T>() =>
|
|
86
|
+
export type TCNSNeuronFactory<TExt = unknown> = {
|
|
87
|
+
/** Add `{ global: T }` to ctx; the value is injected once at `new CNS`/`CNSFactory.create`. */
|
|
88
|
+
withGlobal: <T>() => TCNSNeuronFactory<TExt & {
|
|
88
89
|
global: T;
|
|
89
90
|
}>;
|
|
90
91
|
neuron: <TProvidedAxon extends Record<string, ICNSCollateral<unknown>>>(axon: TProvidedAxon) => InterNeuronAPI<TCNSAxon<TProvidedAxon>, TExt>;
|
|
91
92
|
};
|
|
92
|
-
export declare const
|
|
93
|
-
/** Sugar: `
|
|
94
|
-
export declare const
|
|
93
|
+
export declare const cnsNeuronFactory: <TExt = unknown>() => TCNSNeuronFactory<TExt>;
|
|
94
|
+
/** Sugar: `cnsNeuronFactory().withGlobal<T>()`. */
|
|
95
|
+
export declare const withCNSGlobal: <T>() => TCNSNeuronFactory<{
|
|
95
96
|
global: T;
|
|
96
97
|
}>;
|
|
97
|
-
export declare const
|
|
98
|
-
export declare const
|
|
98
|
+
export declare const cnsAfferentPath: (parentAfferentPath?: TCNSAfferentPath) => TCNSAfferentPath;
|
|
99
|
+
export declare const cnsModality: (afferentPaths: Record<string | number, TCNSAfferentPath>) => TCNSModality;
|
|
99
100
|
export {};
|
|
100
101
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/factory/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/factory/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAUjD,eAAO,MAAM,aAAa,GAAI,QAAQ,GAAG,SAAS,8BACjB,CAAC;AAKlC,KAAK,sBAAsB,CACvB,YAAY,SAAS,SAAS,cAAc,CAAC,OAAO,CAAC,EAAE,IACvD;KACC,CAAC,IAAI,MAAM,YAAY,GAAG,YAAY,CAAC,CAAC,CAAC,SAAS,cAAc,CAAC,MAAM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