@cnstra/core 2.0.0 → 2.0.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 +5 -1
- package/dist/CNSPersistOptionsRegistry.d.ts +22 -0
- package/dist/CNSPersistOptionsRegistry.d.ts.map +1 -0
- package/dist/CNSStimulation.d.ts.map +1 -1
- package/dist/index.cjs +50 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +50 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/CNSDrainGuard.d.ts +27 -0
- package/dist/utils/CNSDrainGuard.d.ts.map +1 -0
- package/package.json +17 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @cnstra/core
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Workflow / orchestration engine for TypeScript — deterministic, embeddable, in-memory.**
|
|
4
4
|
|
|
5
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)
|
|
6
6
|
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
**Zero dependencies** • **No pub/sub** • **CNS approach** (Central Neural Network of your app)
|
|
12
12
|
|
|
13
|
+
Common backend use-cases:
|
|
14
|
+
- **Jobs** (queues/workers), **sync/integrations** (webhooks), **ETL/pipelines**
|
|
15
|
+
- **Retries/timeouts/cancellation** and **saga-style compensations**
|
|
16
|
+
|
|
13
17
|
👉 **[Read the full documentation →](https://cnstra.org/)**
|
|
14
18
|
|
|
15
19
|
## Quick Start
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CNSCollateral } from './CNSCollateral';
|
|
2
|
+
import { CNSStimulation } from './CNSStimulation';
|
|
3
|
+
import { TCNSAxon } from './types/TCNSAxon';
|
|
4
|
+
import { TCNSNeuron } from './types/TCNSNeuron';
|
|
5
|
+
import { TCNSCollateralPersistOptions, TCNSNeuronPersistOptions, TCNSStimulationPersistOptions } from './types/TCNSPersist';
|
|
6
|
+
export declare class CNSPersistOptionsRegistry {
|
|
7
|
+
private neurons;
|
|
8
|
+
private neuronNames;
|
|
9
|
+
private collaterals;
|
|
10
|
+
private stimulations;
|
|
11
|
+
addNeuron(neuron: TCNSNeuron<unknown, TCNSAxon>, options: TCNSNeuronPersistOptions<TCNSNeuron<unknown, TCNSAxon>>): void;
|
|
12
|
+
getNeuron(name: string): TCNSNeuron<unknown, TCNSAxon> | undefined;
|
|
13
|
+
getNeuronName(neuron: TCNSNeuron<unknown, TCNSAxon>): string | undefined;
|
|
14
|
+
removeNeuron(name: string): void;
|
|
15
|
+
addCollateral(collateral: CNSCollateral<unknown>, options: TCNSCollateralPersistOptions): void;
|
|
16
|
+
getCollateral(name: string): CNSCollateral<unknown> | undefined;
|
|
17
|
+
removeCollateral(name: string): void;
|
|
18
|
+
addStimulation(stimulation: CNSStimulation<TCNSNeuron<unknown, TCNSAxon>>, options: TCNSStimulationPersistOptions): void;
|
|
19
|
+
getStimulation(stimulationId: string): CNSStimulation<TCNSNeuron<unknown, TCNSAxon>> | undefined;
|
|
20
|
+
removeStimulation(stimulationId: string): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=CNSPersistOptionsRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CNSPersistOptionsRegistry.d.ts","sourceRoot":"","sources":["../src/CNSPersistOptionsRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EACH,4BAA4B,EAC5B,w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OAAO,CAAC,CAAC,EAChD,YAAY,CAAC,EAAE,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EACjD,KAAK,CAAC,EAAE,GAAG,GACZ,IAAI;IA0FA,gBAAgB,CACnB,eAAe,EACT,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,GAClC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE,GAC3C,IAAI;CAcV"}
|
package/dist/index.cjs
CHANGED
|
@@ -957,6 +957,55 @@ var CNSCollateral = class {
|
|
|
957
957
|
}
|
|
958
958
|
};
|
|
959
959
|
|
|
960
|
+
// src/utils/CNSDrainGuard.ts
|
|
961
|
+
var CNSDrainGuard = class {
|
|
962
|
+
constructor(guardOptions) {
|
|
963
|
+
this.guardOptions = guardOptions;
|
|
964
|
+
}
|
|
965
|
+
isDraining() {
|
|
966
|
+
return this.currentDrain !== void 0;
|
|
967
|
+
}
|
|
968
|
+
getCurrentStimulation() {
|
|
969
|
+
return this.currentStimulation;
|
|
970
|
+
}
|
|
971
|
+
drain() {
|
|
972
|
+
if (this.currentDrain) return this.currentDrain;
|
|
973
|
+
const stimulation = this.guardOptions.cns.stimulate(
|
|
974
|
+
this.guardOptions.signal,
|
|
975
|
+
this.createStimulationOptions()
|
|
976
|
+
);
|
|
977
|
+
const drain = stimulation.waitUntilComplete().finally(() => {
|
|
978
|
+
if (this.currentDrain !== drain) return;
|
|
979
|
+
this.currentDrain = void 0;
|
|
980
|
+
this.currentStimulation = void 0;
|
|
981
|
+
this.currentAbortController = void 0;
|
|
982
|
+
});
|
|
983
|
+
this.currentStimulation = stimulation;
|
|
984
|
+
this.currentDrain = drain;
|
|
985
|
+
return drain;
|
|
986
|
+
}
|
|
987
|
+
abort(reason) {
|
|
988
|
+
if (!this.currentAbortController) return false;
|
|
989
|
+
if (this.currentAbortController.signal.aborted) return false;
|
|
990
|
+
this.currentAbortController.abort(reason);
|
|
991
|
+
return true;
|
|
992
|
+
}
|
|
993
|
+
createStimulationOptions() {
|
|
994
|
+
const options = this.guardOptions.options;
|
|
995
|
+
if (options?.abortSignal) {
|
|
996
|
+
return options;
|
|
997
|
+
}
|
|
998
|
+
if (typeof AbortController === "undefined") {
|
|
999
|
+
return options ?? {};
|
|
1000
|
+
}
|
|
1001
|
+
this.currentAbortController = new AbortController();
|
|
1002
|
+
return {
|
|
1003
|
+
...options,
|
|
1004
|
+
abortSignal: this.currentAbortController.signal
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
|
|
960
1009
|
// src/factory/index.ts
|
|
961
1010
|
var collateral = () => new CNSCollateral();
|
|
962
1011
|
var neuron = (axon) => {
|
|
@@ -1102,6 +1151,7 @@ var modality = (afferentPaths) => {
|
|
|
1102
1151
|
|
|
1103
1152
|
exports.CNS = CNS;
|
|
1104
1153
|
exports.CNSCollateral = CNSCollateral;
|
|
1154
|
+
exports.CNSDrainGuard = CNSDrainGuard;
|
|
1105
1155
|
exports.CNSStimulationContextStore = CNSStimulationContextStore;
|
|
1106
1156
|
exports.afferentPath = afferentPath;
|
|
1107
1157
|
exports.collateral = collateral;
|