rhachet 1.1.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/LICENSE +21 -0
- package/dist/__nonpublished_modules__/file-fns/src/getFile.d.ts +6 -0
- package/dist/__nonpublished_modules__/file-fns/src/getFile.js +14 -0
- package/dist/__nonpublished_modules__/file-fns/src/getFile.js.map +1 -0
- package/dist/__test_assets__/directory.d.ts +1 -0
- package/dist/__test_assets__/directory.js +5 -0
- package/dist/__test_assets__/directory.js.map +1 -0
- package/dist/__test_assets__/genContextLogTrail.d.ts +2 -0
- package/dist/__test_assets__/genContextLogTrail.js +12 -0
- package/dist/__test_assets__/genContextLogTrail.js.map +1 -0
- package/dist/__test_assets__/genContextStitchTrail.d.ts +2 -0
- package/dist/__test_assets__/genContextStitchTrail.js +8 -0
- package/dist/__test_assets__/genContextStitchTrail.js.map +1 -0
- package/dist/__test_assets__/getContextOpenAI.d.ts +2 -0
- package/dist/__test_assets__/getContextOpenAI.js +18 -0
- package/dist/__test_assets__/getContextOpenAI.js.map +1 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeFileRead.d.ts +14 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeFileRead.js +23 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeFileRead.js.map +1 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeFileWrite.d.ts +16 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeFileWrite.js +29 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeFileWrite.js.map +1 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeReviewImagine.d.ts +15 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeReviewImagine.js +97 -0
- package/dist/__test_assets__/stitchers/genStitcherCodeReviewImagine.js.map +1 -0
- package/dist/__test_assets__/stitchers/stitcherCodeDiffImagine.d.ts +13 -0
- package/dist/__test_assets__/stitchers/stitcherCodeDiffImagine.js +33 -0
- package/dist/__test_assets__/stitchers/stitcherCodeDiffImagine.js.map +1 -0
- package/dist/__test_assets__/stitchers/stitcherFanoutRandomSum.d.ts +13 -0
- package/dist/__test_assets__/stitchers/stitcherFanoutRandomSum.js +45 -0
- package/dist/__test_assets__/stitchers/stitcherFanoutRandomSum.js.map +1 -0
- package/dist/__test_assets__/stitchers/stitcherFanoutSubroutes.d.ts +29 -0
- package/dist/__test_assets__/stitchers/stitcherFanoutSubroutes.js +76 -0
- package/dist/__test_assets__/stitchers/stitcherFanoutSubroutes.js.map +1 -0
- package/dist/__test_assets__/threads/codeArtist.d.ts +6 -0
- package/dist/__test_assets__/threads/codeArtist.js +26 -0
- package/dist/__test_assets__/threads/codeArtist.js.map +1 -0
- package/dist/__test_assets__/threads/codeCritic.d.ts +6 -0
- package/dist/__test_assets__/threads/codeCritic.js +21 -0
- package/dist/__test_assets__/threads/codeCritic.js.map +1 -0
- package/dist/__test_assets__/threads/director.d.ts +6 -0
- package/dist/__test_assets__/threads/director.js +14 -0
- package/dist/__test_assets__/threads/director.js.map +1 -0
- package/dist/contract/sdk.d.ts +8 -0
- package/dist/contract/sdk.js +33 -0
- package/dist/contract/sdk.js.map +1 -0
- package/dist/domain/objects/Stitch.d.ts +42 -0
- package/dist/domain/objects/Stitch.js +9 -0
- package/dist/domain/objects/Stitch.js.map +1 -0
- package/dist/domain/objects/StitchChoice.d.ts +30 -0
- package/dist/domain/objects/StitchChoice.js +8 -0
- package/dist/domain/objects/StitchChoice.js.map +1 -0
- package/dist/domain/objects/StitchCycle.d.ts +44 -0
- package/dist/domain/objects/StitchCycle.js +8 -0
- package/dist/domain/objects/StitchCycle.js.map +1 -0
- package/dist/domain/objects/StitchFanout.d.ts +35 -0
- package/dist/domain/objects/StitchFanout.js +8 -0
- package/dist/domain/objects/StitchFanout.js.map +1 -0
- package/dist/domain/objects/StitchRoute.d.ts +22 -0
- package/dist/domain/objects/StitchRoute.js +8 -0
- package/dist/domain/objects/StitchRoute.js.map +1 -0
- package/dist/domain/objects/StitchSetEvent.d.ts +23 -0
- package/dist/domain/objects/StitchSetEvent.js +8 -0
- package/dist/domain/objects/StitchSetEvent.js.map +1 -0
- package/dist/domain/objects/StitchStep.d.ts +55 -0
- package/dist/domain/objects/StitchStep.js +11 -0
- package/dist/domain/objects/StitchStep.js.map +1 -0
- package/dist/domain/objects/StitchTrail.d.ts +26 -0
- package/dist/domain/objects/StitchTrail.js +19 -0
- package/dist/domain/objects/StitchTrail.js.map +1 -0
- package/dist/domain/objects/Stitcher.d.ts +105 -0
- package/dist/domain/objects/Stitcher.js +49 -0
- package/dist/domain/objects/Stitcher.js.map +1 -0
- package/dist/domain/objects/Stitcher.test.d.ts +1 -0
- package/dist/domain/objects/Stitcher.test.js +78 -0
- package/dist/domain/objects/Stitcher.test.js.map +1 -0
- package/dist/domain/objects/Thread.d.ts +31 -0
- package/dist/domain/objects/Thread.js +11 -0
- package/dist/domain/objects/Thread.js.map +1 -0
- package/dist/domain/objects/Threads.d.ts +56 -0
- package/dist/domain/objects/Threads.js +26 -0
- package/dist/domain/objects/Threads.js.map +1 -0
- package/dist/domain/objects/Weave.d.ts +0 -0
- package/dist/domain/objects/Weave.js +2 -0
- package/dist/domain/objects/Weave.js.map +1 -0
- package/dist/domain/objects/Weaver.d.ts +5 -0
- package/dist/domain/objects/Weaver.js +7 -0
- package/dist/domain/objects/Weaver.js.map +1 -0
- package/dist/domain/objects/index.d.ts +11 -0
- package/dist/domain/objects/index.js +30 -0
- package/dist/domain/objects/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/logic/stitch/adapters/imagineViaOpenAI.d.ts +13 -0
- package/dist/logic/stitch/adapters/imagineViaOpenAI.js +36 -0
- package/dist/logic/stitch/adapters/imagineViaOpenAI.js.map +1 -0
- package/dist/logic/stitch/enstitch.d.ts +27 -0
- package/dist/logic/stitch/enstitch.js +97 -0
- package/dist/logic/stitch/enstitch.js.map +1 -0
- package/dist/logic/stitch/enstitch.test.d.ts +1 -0
- package/dist/logic/stitch/enstitch.test.js +87 -0
- package/dist/logic/stitch/enstitch.test.js.map +1 -0
- package/dist/logic/stitch/invokeImagineStitcher.d.ts +10 -0
- package/dist/logic/stitch/invokeImagineStitcher.integration.test.d.ts +1 -0
- package/dist/logic/stitch/invokeImagineStitcher.integration.test.js +193 -0
- package/dist/logic/stitch/invokeImagineStitcher.integration.test.js.map +1 -0
- package/dist/logic/stitch/invokeImagineStitcher.js +23 -0
- package/dist/logic/stitch/invokeImagineStitcher.js.map +1 -0
- package/dist/logic/stitch/withStitchTrail.d.ts +16 -0
- package/dist/logic/stitch/withStitchTrail.js +40 -0
- package/dist/logic/stitch/withStitchTrail.js.map +1 -0
- package/dist/logic/thread/enroleThread.d.ts +4 -0
- package/dist/logic/thread/enroleThread.js +6 -0
- package/dist/logic/thread/enroleThread.js.map +1 -0
- package/dist/logic/thread/genThread.d.ts +7 -0
- package/dist/logic/thread/genThread.js +10 -0
- package/dist/logic/thread/genThread.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromChoice.generic.d.ts +17 -0
- package/dist/logic/weave/compose/GStitcherInferredFromChoice.generic.js +3 -0
- package/dist/logic/weave/compose/GStitcherInferredFromChoice.generic.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromChoice.generic.test.d.ts +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromChoice.generic.test.js +67 -0
- package/dist/logic/weave/compose/GStitcherInferredFromChoice.generic.test.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromCycle.generic.d.ts +18 -0
- package/dist/logic/weave/compose/GStitcherInferredFromCycle.generic.js +3 -0
- package/dist/logic/weave/compose/GStitcherInferredFromCycle.generic.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromCycle.generic.test.d.ts +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromCycle.generic.test.js +132 -0
- package/dist/logic/weave/compose/GStitcherInferredFromCycle.generic.test.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromFanout.generic.d.ts +23 -0
- package/dist/logic/weave/compose/GStitcherInferredFromFanout.generic.js +3 -0
- package/dist/logic/weave/compose/GStitcherInferredFromFanout.generic.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromFanout.generic.test.d.ts +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromFanout.generic.test.js +74 -0
- package/dist/logic/weave/compose/GStitcherInferredFromFanout.generic.test.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromRoute.generic.d.ts +24 -0
- package/dist/logic/weave/compose/GStitcherInferredFromRoute.generic.js +3 -0
- package/dist/logic/weave/compose/GStitcherInferredFromRoute.generic.js.map +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromRoute.generic.test.d.ts +1 -0
- package/dist/logic/weave/compose/GStitcherInferredFromRoute.generic.test.js +190 -0
- package/dist/logic/weave/compose/GStitcherInferredFromRoute.generic.test.js.map +1 -0
- package/dist/logic/weave/compose/ProcedureContextMerged.generic.d.ts +36 -0
- package/dist/logic/weave/compose/ProcedureContextMerged.generic.js +3 -0
- package/dist/logic/weave/compose/ProcedureContextMerged.generic.js.map +1 -0
- package/dist/logic/weave/compose/ProcedureContextMerged.generic.test.d.ts +1 -0
- package/dist/logic/weave/compose/ProcedureContextMerged.generic.test.js +29 -0
- package/dist/logic/weave/compose/ProcedureContextMerged.generic.test.js.map +1 -0
- package/dist/logic/weave/compose/ThreadsMerged.generic.d.ts +65 -0
- package/dist/logic/weave/compose/ThreadsMerged.generic.js +3 -0
- package/dist/logic/weave/compose/ThreadsMerged.generic.js.map +1 -0
- package/dist/logic/weave/compose/ThreadsMerged.generic.test.d.ts +1 -0
- package/dist/logic/weave/compose/ThreadsMerged.generic.test.js +420 -0
- package/dist/logic/weave/compose/ThreadsMerged.generic.test.js.map +1 -0
- package/dist/logic/weave/compose/asStitcher.d.ts +12 -0
- package/dist/logic/weave/compose/asStitcher.js +15 -0
- package/dist/logic/weave/compose/asStitcher.js.map +1 -0
- package/dist/logic/weave/compose/asStitcher.test.d.ts +1 -0
- package/dist/logic/weave/compose/asStitcher.test.js +95 -0
- package/dist/logic/weave/compose/asStitcher.test.js.map +1 -0
- package/dist/logic/weave/compose/asStitcherFlat.d.ts +10 -0
- package/dist/logic/weave/compose/asStitcherFlat.js +13 -0
- package/dist/logic/weave/compose/asStitcherFlat.js.map +1 -0
- package/dist/logic/weave/compose/asStitcherFlat.test.d.ts +1 -0
- package/dist/logic/weave/compose/asStitcherFlat.test.js +96 -0
- package/dist/logic/weave/compose/asStitcherFlat.test.js.map +1 -0
- package/dist/logic/weave/compose/genStitchChoice.d.ts +22 -0
- package/dist/logic/weave/compose/genStitchChoice.js +23 -0
- package/dist/logic/weave/compose/genStitchChoice.js.map +1 -0
- package/dist/logic/weave/compose/genStitchChoice.test.d.ts +1 -0
- package/dist/logic/weave/compose/genStitchChoice.test.js +200 -0
- package/dist/logic/weave/compose/genStitchChoice.test.js.map +1 -0
- package/dist/logic/weave/compose/genStitchCycle.d.ts +28 -0
- package/dist/logic/weave/compose/genStitchCycle.js +30 -0
- package/dist/logic/weave/compose/genStitchCycle.js.map +1 -0
- package/dist/logic/weave/compose/genStitchCycle.test.d.ts +1 -0
- package/dist/logic/weave/compose/genStitchCycle.test.js +152 -0
- package/dist/logic/weave/compose/genStitchCycle.test.js.map +1 -0
- package/dist/logic/weave/compose/genStitchFanout.d.ts +17 -0
- package/dist/logic/weave/compose/genStitchFanout.js +21 -0
- package/dist/logic/weave/compose/genStitchFanout.js.map +1 -0
- package/dist/logic/weave/compose/genStitchFanout.test.d.ts +1 -0
- package/dist/logic/weave/compose/genStitchFanout.test.js +79 -0
- package/dist/logic/weave/compose/genStitchFanout.test.js.map +1 -0
- package/dist/logic/weave/compose/genStitchRoute.d.ts +15 -0
- package/dist/logic/weave/compose/genStitchRoute.js +20 -0
- package/dist/logic/weave/compose/genStitchRoute.js.map +1 -0
- package/dist/logic/weave/compose/genStitchRoute.test.d.ts +1 -0
- package/dist/logic/weave/compose/genStitchRoute.test.js +120 -0
- package/dist/logic/weave/compose/genStitchRoute.test.js.map +1 -0
- package/dist/logic/weave/enweave.d.ts +0 -0
- package/dist/logic/weave/enweave.js +2 -0
- package/dist/logic/weave/enweave.js.map +1 -0
- package/dist/logic/weave/enweaveAllStitchers.d.ts +0 -0
- package/dist/logic/weave/enweaveAllStitchers.js +2 -0
- package/dist/logic/weave/enweaveAllStitchers.js.map +1 -0
- package/dist/logic/weave/enweaveOneChoice.d.ts +14 -0
- package/dist/logic/weave/enweaveOneChoice.js +48 -0
- package/dist/logic/weave/enweaveOneChoice.js.map +1 -0
- package/dist/logic/weave/enweaveOneChoice.test.d.ts +1 -0
- package/dist/logic/weave/enweaveOneChoice.test.js +181 -0
- package/dist/logic/weave/enweaveOneChoice.test.js.map +1 -0
- package/dist/logic/weave/enweaveOneCycle.d.ts +19 -0
- package/dist/logic/weave/enweaveOneCycle.js +98 -0
- package/dist/logic/weave/enweaveOneCycle.js.map +1 -0
- package/dist/logic/weave/enweaveOneCycle.test.d.ts +1 -0
- package/dist/logic/weave/enweaveOneCycle.test.js +180 -0
- package/dist/logic/weave/enweaveOneCycle.test.js.map +1 -0
- package/dist/logic/weave/enweaveOneFanout.d.ts +12 -0
- package/dist/logic/weave/enweaveOneFanout.integration.test.d.ts +1 -0
- package/dist/logic/weave/enweaveOneFanout.integration.test.js +166 -0
- package/dist/logic/weave/enweaveOneFanout.integration.test.js.map +1 -0
- package/dist/logic/weave/enweaveOneFanout.js +37 -0
- package/dist/logic/weave/enweaveOneFanout.js.map +1 -0
- package/dist/logic/weave/enweaveOneRoute.d.ts +12 -0
- package/dist/logic/weave/enweaveOneRoute.integration.test.d.ts +1 -0
- package/dist/logic/weave/enweaveOneRoute.integration.test.js +159 -0
- package/dist/logic/weave/enweaveOneRoute.integration.test.js.map +1 -0
- package/dist/logic/weave/enweaveOneRoute.js +33 -0
- package/dist/logic/weave/enweaveOneRoute.js.map +1 -0
- package/dist/logic/weave/enweaveOneStitcher.d.ts +11 -0
- package/dist/logic/weave/enweaveOneStitcher.integration.test.d.ts +2 -0
- package/dist/logic/weave/enweaveOneStitcher.integration.test.js +258 -0
- package/dist/logic/weave/enweaveOneStitcher.integration.test.js.map +1 -0
- package/dist/logic/weave/enweaveOneStitcher.js +42 -0
- package/dist/logic/weave/enweaveOneStitcher.js.map +1 -0
- package/package.json +88 -0
- package/readme.md +61 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const test_fns_1 = require("test-fns");
|
|
4
|
+
const genContextLogTrail_1 = require("../../../__test_assets__/genContextLogTrail");
|
|
5
|
+
const genContextStitchTrail_1 = require("../../../__test_assets__/genContextStitchTrail");
|
|
6
|
+
const StitchStep_1 = require("../../../domain/objects/StitchStep");
|
|
7
|
+
const genThread_1 = require("../../thread/genThread");
|
|
8
|
+
const asStitcher_1 = require("./asStitcher");
|
|
9
|
+
const genStitchRoute_1 = require("./genStitchRoute");
|
|
10
|
+
describe('GStitcherInferredFromCycle', () => {
|
|
11
|
+
(0, test_fns_1.given)('a single compute step as the repeatee', () => {
|
|
12
|
+
const repeatee = new StitchStep_1.StitchStepCompute({
|
|
13
|
+
slug: 'do-one-thing',
|
|
14
|
+
form: 'COMPUTE',
|
|
15
|
+
readme: null,
|
|
16
|
+
stitchee: 'main',
|
|
17
|
+
invoke: () => ({ input: null, output: 'done' }),
|
|
18
|
+
});
|
|
19
|
+
const decider = new StitchStep_1.StitchStepCompute({
|
|
20
|
+
slug: 'decide-again',
|
|
21
|
+
form: 'COMPUTE',
|
|
22
|
+
readme: null,
|
|
23
|
+
stitchee: 'main',
|
|
24
|
+
invoke: () => ({ input: null, output: { choice: 'release' } }),
|
|
25
|
+
});
|
|
26
|
+
(0, test_fns_1.then)('it should merge threads correctly', () => {
|
|
27
|
+
const threads = {
|
|
28
|
+
main: (0, genThread_1.genThread)({ role: 'main' }),
|
|
29
|
+
};
|
|
30
|
+
expect(threads);
|
|
31
|
+
const badThreads = {
|
|
32
|
+
// @ts-expect-error: extra thread
|
|
33
|
+
foo: (0, genThread_1.genThread)({ role: 'foo' }),
|
|
34
|
+
};
|
|
35
|
+
expect(badThreads);
|
|
36
|
+
});
|
|
37
|
+
(0, test_fns_1.then)('it should merge context from both steps', () => {
|
|
38
|
+
const context = {
|
|
39
|
+
foo: 123,
|
|
40
|
+
flag: true,
|
|
41
|
+
...(0, genContextLogTrail_1.genContextLogTrail)(),
|
|
42
|
+
...(0, genContextStitchTrail_1.genContextStitchTrail)(),
|
|
43
|
+
};
|
|
44
|
+
expect(context);
|
|
45
|
+
// @ts-expect-error: missing context key 'foo'
|
|
46
|
+
const invalid = {
|
|
47
|
+
flag: true,
|
|
48
|
+
};
|
|
49
|
+
expect(invalid);
|
|
50
|
+
});
|
|
51
|
+
(0, test_fns_1.then)('it should infer the output from repeatee', () => {
|
|
52
|
+
const result = 'done';
|
|
53
|
+
expect(result);
|
|
54
|
+
// @ts-expect-error: incorrect type
|
|
55
|
+
const invalid = 'not-done';
|
|
56
|
+
expect(invalid);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
(0, test_fns_1.given)('a repeatee route and a decider', () => {
|
|
60
|
+
const stepA = new StitchStep_1.StitchStepCompute({
|
|
61
|
+
slug: 'step-a',
|
|
62
|
+
form: 'COMPUTE',
|
|
63
|
+
readme: null,
|
|
64
|
+
stitchee: 'main',
|
|
65
|
+
invoke: () => ({ input: null, output: 'A' }),
|
|
66
|
+
});
|
|
67
|
+
const stepB = new StitchStep_1.StitchStepCompute({
|
|
68
|
+
slug: 'step-b',
|
|
69
|
+
form: 'COMPUTE',
|
|
70
|
+
readme: null,
|
|
71
|
+
stitchee: 'main',
|
|
72
|
+
invoke: () => ({ input: null, output: 'B' }),
|
|
73
|
+
});
|
|
74
|
+
const repeatee = (0, asStitcher_1.asStitcher)((0, genStitchRoute_1.genStitchRoute)({
|
|
75
|
+
slug: 'route:combo',
|
|
76
|
+
readme: null,
|
|
77
|
+
sequence: [stepA, stepB],
|
|
78
|
+
}));
|
|
79
|
+
const decider = new StitchStep_1.StitchStepCompute({
|
|
80
|
+
slug: 'decide-loop',
|
|
81
|
+
form: 'COMPUTE',
|
|
82
|
+
readme: null,
|
|
83
|
+
stitchee: 'main',
|
|
84
|
+
invoke: () => ({
|
|
85
|
+
input: null,
|
|
86
|
+
output: { choice: 'release' },
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
89
|
+
(0, test_fns_1.then)('it should merge threads correctly', () => {
|
|
90
|
+
const threads = {
|
|
91
|
+
main: (0, genThread_1.genThread)({ role: 'main' }),
|
|
92
|
+
};
|
|
93
|
+
expect(threads);
|
|
94
|
+
const badThreads = {
|
|
95
|
+
// @ts-expect-error: extra thread not allowed
|
|
96
|
+
foo: (0, genThread_1.genThread)({ role: 'foo' }),
|
|
97
|
+
};
|
|
98
|
+
expect(badThreads);
|
|
99
|
+
});
|
|
100
|
+
(0, test_fns_1.then)('it should merge context from both repeatee and decider', () => {
|
|
101
|
+
const context = {
|
|
102
|
+
a: 'alpha',
|
|
103
|
+
b: 123,
|
|
104
|
+
d: new Date(),
|
|
105
|
+
...(0, genContextLogTrail_1.genContextLogTrail)(),
|
|
106
|
+
...(0, genContextStitchTrail_1.genContextStitchTrail)(),
|
|
107
|
+
};
|
|
108
|
+
expect(context);
|
|
109
|
+
// @ts-expect-error: missing 'b'
|
|
110
|
+
const missingContext = {
|
|
111
|
+
a: 'alpha',
|
|
112
|
+
d: new Date(),
|
|
113
|
+
};
|
|
114
|
+
expect(missingContext);
|
|
115
|
+
const badContext = {
|
|
116
|
+
a: 'alpha',
|
|
117
|
+
b: 123,
|
|
118
|
+
// @ts-expect-error: wrong type for 'd'
|
|
119
|
+
d: 'not-a-date',
|
|
120
|
+
};
|
|
121
|
+
expect(badContext);
|
|
122
|
+
});
|
|
123
|
+
(0, test_fns_1.then)('it should infer output from repeatee', () => {
|
|
124
|
+
const output = 'B';
|
|
125
|
+
expect(output);
|
|
126
|
+
// @ts-expect-error: invalid output
|
|
127
|
+
const badOutput = 42;
|
|
128
|
+
expect(badOutput);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
//# sourceMappingURL=GStitcherInferredFromCycle.generic.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GStitcherInferredFromCycle.generic.test.js","sourceRoot":"","sources":["../../../../src/logic/weave/compose/GStitcherInferredFromCycle.generic.test.ts"],"names":[],"mappings":";;AAAA,uCAAuC;AAGvC,oFAAiF;AACjF,0FAAuF;AAEvF,mEAAuE;AAGvE,sDAAmD;AAEnD,6CAA0C;AAC1C,qDAAkD;AAElD,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC1C,IAAA,gBAAK,EAAC,uCAAuC,EAAE,GAAG,EAAE;QAClD,MAAM,QAAQ,GAAG,IAAI,8BAAiB,CAMpC;YACA,IAAI,EAAE,cAAc;YACpB,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,IAAI;YACZ,QAAQ,EAAE,MAAM;YAChB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;SAChD,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,IAAI,8BAAiB,CAMnC;YACA,IAAI,EAAE,cAAc;YACpB,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,IAAI;YACZ,QAAQ,EAAE,MAAM;YAChB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC;SAC/D,CAAC,CAAC;QAIH,IAAA,eAAI,EAAC,mCAAmC,EAAE,GAAG,EAAE;YAC7C,MAAM,OAAO,GAAwB;gBACnC,IAAI,EAAE,IAAA,qBAAS,EAAC,EAAE,IA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CAAC,EAAE,IAAI,IAAI,EAAE;gBACb,GAAG,IAAA,uCAAkB,GAAE;gBACvB,GAAG,IAAA,6CAAqB,GAAE;aAC3B,CAAC;YACF,MAAM,CAAC,OAAO,CAAC,CAAC;YAEhB,gCAAgC;YAChC,MAAM,cAAc,GAAwB;gBAC1C,CAAC,EAAE,OAAO;gBACV,CAAC,EAAE,IAAI,IAAI,EAAE;aACd,CAAC;YACF,MAAM,CAAC,cAAc,CAAC,CAAC;YAEvB,MAAM,UAAU,GAAwB;gBACtC,CAAC,EAAE,OAAO;gBACV,CAAC,EAAE,GAAG;gBACN,uCAAuC;gBACvC,CAAC,EAAE,YAAY;aAChB,CAAC;YACF,MAAM,CAAC,UAAU,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,IAAA,eAAI,EAAC,sCAAsC,EAAE,GAAG,EAAE;YAChD,MAAM,MAAM,GAAuB,GAAG,CAAC;YACvC,MAAM,CAAC,MAAM,CAAC,CAAC;YAEf,mCAAmC;YACnC,MAAM,SAAS,GAAuB,EAAE,CAAC;YACzC,MAAM,CAAC,SAAS,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ThreadsFromFanout } from '../../../domain/objects/StitchFanout';
|
|
2
|
+
import { StitchStep } from '../../../domain/objects/StitchStep';
|
|
3
|
+
import { GStitcher, Stitcher } from '../../../domain/objects/Stitcher';
|
|
4
|
+
import { GStitcherInferredFromRoute } from './GStitcherInferredFromRoute.generic';
|
|
5
|
+
import { ProcedureContextMerged, ProcedureContextSpread } from './ProcedureContextMerged.generic';
|
|
6
|
+
import { ThreadsMerged } from './ThreadsMerged.generic';
|
|
7
|
+
/**
|
|
8
|
+
* .what = a mech to infer a GStitcher from a StitchFanout setup
|
|
9
|
+
* - i.e., infers the composite stitcher for StitchFanout
|
|
10
|
+
* .how =
|
|
11
|
+
* - merges the required threads from all parallels
|
|
12
|
+
* - merges the required procedure.context into a superset
|
|
13
|
+
* - uses the concluder's output as the final output
|
|
14
|
+
* .note =
|
|
15
|
+
* - parallels must be typed as const
|
|
16
|
+
* - concluder must accept ThreadsFromFanout
|
|
17
|
+
*/
|
|
18
|
+
export type GStitcherInferredFromFanout<TParallels extends readonly [Stitcher<GStitcher>, ...Stitcher<GStitcher>[]], TConcluder extends StitchStep<GStitcher<ThreadsFromFanout<GStitcherInferredFromRoute<TParallels>>, any, any>>> = GStitcher<ThreadsMerged<{
|
|
19
|
+
[K in keyof TParallels]: TParallels[K] extends Stitcher<infer G> ? G['threads'] : never;
|
|
20
|
+
}>, ProcedureContextMerged<[
|
|
21
|
+
TConcluder extends Stitcher<infer G> ? G['context'] : never,
|
|
22
|
+
...ProcedureContextSpread<TParallels>
|
|
23
|
+
]> & GStitcher['context'], TConcluder extends StitchStep<infer G> ? G['output'] : never>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GStitcherInferredFromFanout.generic.js","sourceRoot":"","sources":["../../../../src/logic/weave/compose/GStitcherInferredFromFanout.generic.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const test_fns_1 = require("test-fns");
|
|
4
|
+
const genContextLogTrail_1 = require("../../../__test_assets__/genContextLogTrail");
|
|
5
|
+
const genContextStitchTrail_1 = require("../../../__test_assets__/genContextStitchTrail");
|
|
6
|
+
const StitchStep_1 = require("../../../domain/objects/StitchStep");
|
|
7
|
+
const genThread_1 = require("../../thread/genThread");
|
|
8
|
+
const stitcherComputeRandom = new StitchStep_1.StitchStepCompute({
|
|
9
|
+
slug: `compute-random`,
|
|
10
|
+
form: 'COMPUTE',
|
|
11
|
+
readme: null,
|
|
12
|
+
stitchee: 'main',
|
|
13
|
+
invoke: () => ({
|
|
14
|
+
input: null,
|
|
15
|
+
output: Math.floor(Math.random() * 100),
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
const stitcherAddAll = new StitchStep_1.StitchStepCompute({
|
|
19
|
+
slug: 'sum-up',
|
|
20
|
+
form: 'COMPUTE',
|
|
21
|
+
readme: null,
|
|
22
|
+
stitchee: 'main',
|
|
23
|
+
invoke: ({ threads }) => {
|
|
24
|
+
const numbers = threads.main.peers.map((t) => {
|
|
25
|
+
const last = t.stitches.at(-1);
|
|
26
|
+
if (!last)
|
|
27
|
+
throw new Error('Missing stitch on thread');
|
|
28
|
+
return last.output;
|
|
29
|
+
});
|
|
30
|
+
const sum = numbers.reduce((a, b) => a + b, 0);
|
|
31
|
+
return {
|
|
32
|
+
input: numbers,
|
|
33
|
+
output: sum,
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
describe('GStitcherInferredFromFanout', () => {
|
|
38
|
+
(0, test_fns_1.given)('two parallel single-threaded compute steps', () => {
|
|
39
|
+
const parallels = [stitcherComputeRandom, stitcherComputeRandom];
|
|
40
|
+
const concluder = stitcherAddAll;
|
|
41
|
+
(0, test_fns_1.then)('it should merge the thread maps and infer the output from the concluder', () => {
|
|
42
|
+
// prove can assign to threads
|
|
43
|
+
const threads = {
|
|
44
|
+
main: (0, genThread_1.genThread)({ role: 'main' }),
|
|
45
|
+
};
|
|
46
|
+
expect(threads);
|
|
47
|
+
const context = {
|
|
48
|
+
...(0, genContextLogTrail_1.genContextLogTrail)(),
|
|
49
|
+
...(0, genContextStitchTrail_1.genContextStitchTrail)(),
|
|
50
|
+
};
|
|
51
|
+
expect(context);
|
|
52
|
+
const output = 42;
|
|
53
|
+
expect(typeof output).toBe('number');
|
|
54
|
+
});
|
|
55
|
+
(0, test_fns_1.then)('it should error if threads has unknown keys', () => {
|
|
56
|
+
const badThreads = {
|
|
57
|
+
// @ts-expect-error unknown thread key "notreal"
|
|
58
|
+
notreal: (0, genThread_1.genThread)({ role: 'notreal' }),
|
|
59
|
+
};
|
|
60
|
+
expect(badThreads);
|
|
61
|
+
});
|
|
62
|
+
(0, test_fns_1.then)('it should error if context is missing required fields', () => {
|
|
63
|
+
// @ts-expect-error missing ContextLogTrail + ContextStitchTrail
|
|
64
|
+
const badContext = {};
|
|
65
|
+
expect(badContext);
|
|
66
|
+
});
|
|
67
|
+
(0, test_fns_1.then)('it should error if output is not a number', () => {
|
|
68
|
+
// @ts-expect-error string is not assignable to number
|
|
69
|
+
const badOutput = 'not-a-number';
|
|
70
|
+
expect(badOutput);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=GStitcherInferredFromFanout.generic.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GStitcherInferredFromFanout.generic.test.js","sourceRoot":"","sources":["../../../../src/logic/weave/compose/GStitcherInferredFromFanout.generic.test.ts"],"names":[],"mappings":";;AAAA,uCAAuC;AAGvC,oFAAiF;AACjF,0FAAuF;AAEvF,mEAAuE;AAGvE,sDAAmD;AAGnD,MAAM,qBAAqB,GAAG,IAAI,8BAAiB,CAEjD;IACA,IAAI,EAAE,gBAAgB;IACtB,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,IAAI;IACZ,QAAQ,EAAE,MAAM;IAChB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QACb,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;KACxC,CAAC;CACH,CAAC,CAAC;AAEH,MAAM,cAAc,GAAG,IAAI,8BAAiB,CAE1C;IACA,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,IAAI;IACZ,QAAQ,EAAE,MAAM;IAChB,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;QACtB,MAAM,OAAO,GAAG,OAAO,CAA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C,6CAA6C,EAAE,GAAG,EAAE;YACvD,MAAM,UAAU,GAAwB;gBACtC,gDAAgD;gBAChD,OAAO,EAAE,IAAA,qBAAS,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;aACxC,CAAC;YACF,MAAM,CAAC,UAAU,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,IAAA,eAAI,EAAC,uDAAuD,EAAE,GAAG,EAAE;YACjE,gEAAgE;YAChE,MAAM,UAAU,GAAwB,EAAE,CAAC;YAC3C,MAAM,CAAC,UAAU,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,IAAA,eAAI,EAAC,2CAA2C,EAAE,GAAG,EAAE;YACrD,sDAAsD;YACtD,MAAM,SAAS,GAAuB,cAAc,CAAC;YACrD,MAAM,CAAC,SAAS,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { GStitcher, Stitcher } from '../../../domain/objects/Stitcher';
|
|
2
|
+
import { Threads } from '../../../domain/objects/Threads';
|
|
3
|
+
import { ProcedureContextMerged } from './ProcedureContextMerged.generic';
|
|
4
|
+
import { ThreadsMerged } from './ThreadsMerged.generic';
|
|
5
|
+
type Last<T extends readonly any[]> = T extends readonly [...any[], infer L] ? L : never;
|
|
6
|
+
/**
|
|
7
|
+
* .what = a mech to infer a GStitcher from a StitchRoute.Sequence
|
|
8
|
+
* - i.e., infers the composite stitcher
|
|
9
|
+
* .how =
|
|
10
|
+
* - merges the required threads into a superset
|
|
11
|
+
* - merges the required procedure.context into a superset
|
|
12
|
+
* - picks the last output as the overall output
|
|
13
|
+
* .note =
|
|
14
|
+
* - requires an [...stitchers,] as const input, to ensure type propagation safely (fails fast to prevent type info loss)
|
|
15
|
+
*/
|
|
16
|
+
export type GStitcherInferredFromRoute<TSequence extends readonly [
|
|
17
|
+
Stitcher<GStitcher<Threads<any, 'single'>, any, any>>,
|
|
18
|
+
...Stitcher<GStitcher<Threads<any, 'single'>, any, any>>[]
|
|
19
|
+
]> = GStitcher<ThreadsMerged<{
|
|
20
|
+
[K in keyof TSequence]: TSequence[K] extends Stitcher<infer G> ? G['threads'] : never;
|
|
21
|
+
}>, ProcedureContextMerged<{
|
|
22
|
+
[K in keyof TSequence]: TSequence[K] extends Stitcher<infer G> ? G['context'] : never;
|
|
23
|
+
}> & GStitcher['context'], Last<TSequence> extends Stitcher<infer G> ? G['output'] : never>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GStitcherInferredFromRoute.generic.js","sourceRoot":"","sources":["../../../../src/logic/weave/compose/GStitcherInferredFromRoute.generic.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const uni_time_1 = require("@ehmpathy/uni-time");
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
const test_fns_1 = require("test-fns");
|
|
6
|
+
const genContextLogTrail_1 = require("../../../__test_assets__/genContextLogTrail");
|
|
7
|
+
const genContextStitchTrail_1 = require("../../../__test_assets__/genContextStitchTrail");
|
|
8
|
+
const StitchStep_1 = require("../../../domain/objects/StitchStep");
|
|
9
|
+
const Thread_1 = require("../../../domain/objects/Thread");
|
|
10
|
+
describe('GStitcherInferredFromRoute', () => {
|
|
11
|
+
const exampleContext = {
|
|
12
|
+
...(0, genContextLogTrail_1.genContextLogTrail)(),
|
|
13
|
+
...(0, genContextStitchTrail_1.genContextStitchTrail)(),
|
|
14
|
+
};
|
|
15
|
+
const stitcherGetTime = new StitchStep_1.StitchStepCompute({
|
|
16
|
+
form: 'COMPUTE',
|
|
17
|
+
readme: null,
|
|
18
|
+
slug: 'get-time',
|
|
19
|
+
stitchee: 'main',
|
|
20
|
+
invoke: () => ({ input: null, output: (0, uni_time_1.asUniDateTime)(new Date()) }),
|
|
21
|
+
});
|
|
22
|
+
const stitcherAddHours = new StitchStep_1.StitchStepCompute({
|
|
23
|
+
form: 'COMPUTE',
|
|
24
|
+
readme: null,
|
|
25
|
+
slug: 'add-time',
|
|
26
|
+
stitchee: 'main',
|
|
27
|
+
invoke: ({ threads }) => {
|
|
28
|
+
const lastStitch = threads.main.stitches.slice(-1)[0] ??
|
|
29
|
+
helpful_errors_1.UnexpectedCodePathError.throw('no stitches found on main thread yet.', {
|
|
30
|
+
threads,
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
input: lastStitch.output,
|
|
34
|
+
output: (0, uni_time_1.addDuration)(uni_time_1.isUniDateTime.assure(lastStitch.output), {
|
|
35
|
+
hours: 1,
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
(0, test_fns_1.given)('a sequence of stitchers declared not readonly', () => {
|
|
41
|
+
const sequence = [stitcherGetTime, stitcherAddHours];
|
|
42
|
+
(0, test_fns_1.then)('there should be a type error at usage, as we enforce readonly consts to maximize type inference, and fail fast when omitted', () => {
|
|
43
|
+
expect(true); // just to satisfy the linter of unused type
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
(0, test_fns_1.given)('a sequence of two compatible stitchers on the same thread', () => {
|
|
47
|
+
const sequence = [stitcherGetTime, stitcherAddHours];
|
|
48
|
+
(0, test_fns_1.then)('procedure context should be assignable', () => {
|
|
49
|
+
const assertContext = { ...exampleContext };
|
|
50
|
+
expect(assertContext);
|
|
51
|
+
});
|
|
52
|
+
(0, test_fns_1.then)('expected threads should be assignable', () => {
|
|
53
|
+
const threadsExpected = {
|
|
54
|
+
main: new Thread_1.Thread({ context: { role: 'main' }, stitches: [] }),
|
|
55
|
+
};
|
|
56
|
+
const threadsInferred = threadsExpected;
|
|
57
|
+
expect(threadsInferred);
|
|
58
|
+
});
|
|
59
|
+
(0, test_fns_1.then)('output should match expected shape', () => {
|
|
60
|
+
// positive case
|
|
61
|
+
const assertOutput = (0, uni_time_1.asUniDateTime)(new Date());
|
|
62
|
+
expect(assertOutput);
|
|
63
|
+
// negative case
|
|
64
|
+
// @ts-expect-error: number is not assignable to UniDateTime
|
|
65
|
+
const expectError = 821;
|
|
66
|
+
expect(expectError);
|
|
67
|
+
});
|
|
68
|
+
(0, test_fns_1.then)('extra thread SHOULD be assignable', { because: 'all of the required threads are still available' }, () => {
|
|
69
|
+
const threadsExpected = {
|
|
70
|
+
main: new Thread_1.Thread({ context: { role: 'main' }, stitches: [] }),
|
|
71
|
+
extra: new Thread_1.Thread({ context: { role: 'extra' }, stitches: [] }),
|
|
72
|
+
};
|
|
73
|
+
const threadsInferred = threadsExpected;
|
|
74
|
+
expect(threadsInferred);
|
|
75
|
+
});
|
|
76
|
+
(0, test_fns_1.then)('missing required thread should not be assignable', () => {
|
|
77
|
+
const threadsExpected = {
|
|
78
|
+
extra: new Thread_1.Thread({ context: { role: 'extra' }, stitches: [] }),
|
|
79
|
+
};
|
|
80
|
+
// @ts-expect-error: Property 'main' is missing in type 'Threads<{ extra: Empty; }>' but required in type 'ThreadsMerged<Threads<{ main: Empty; }>[]>'.ts(2741)
|
|
81
|
+
const threadsInferred = threadsExpected;
|
|
82
|
+
expect(threadsInferred);
|
|
83
|
+
});
|
|
84
|
+
(0, test_fns_1.then)('thread with extra context shape SHOULD be assignable', () => {
|
|
85
|
+
const threadsExpected = {
|
|
86
|
+
main: new Thread_1.Thread({
|
|
87
|
+
context: { role: 'main', foo: 'unexpected' },
|
|
88
|
+
stitches: [],
|
|
89
|
+
}),
|
|
90
|
+
};
|
|
91
|
+
const threadsInferred = threadsExpected;
|
|
92
|
+
expect(threadsInferred);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
(0, test_fns_1.given)('a sequence of stitchers with different thread roles or output', () => {
|
|
96
|
+
const stitcherWithClock = new StitchStep_1.StitchStepCompute({
|
|
97
|
+
form: 'COMPUTE',
|
|
98
|
+
readme: null,
|
|
99
|
+
slug: 'with-clock',
|
|
100
|
+
stitchee: 'clock',
|
|
101
|
+
invoke: () => ({ input: null, output: (0, uni_time_1.asUniDateTime)(new Date()) }),
|
|
102
|
+
});
|
|
103
|
+
const sequence = [stitcherGetTime, stitcherWithClock];
|
|
104
|
+
(0, test_fns_1.then)('GStitcherInferred merges thread roles', () => {
|
|
105
|
+
const keys = ['main', 'clock'];
|
|
106
|
+
expect(keys).toEqual(expect.arrayContaining(['main', 'clock']));
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
(0, test_fns_1.given)('a custom context', () => {
|
|
110
|
+
(0, test_fns_1.when)('use any stitcher', () => {
|
|
111
|
+
(0, test_fns_1.then)('when only one context is defined, it should infer that context', () => {
|
|
112
|
+
const context = { foo: 123, ...exampleContext };
|
|
113
|
+
expect(context.foo).toBe(123);
|
|
114
|
+
// @ts-expect-error: 'bob' does not exist in type '{ foo: number; log: LogMethods
|
|
115
|
+
const contextFail = { bob: 123 };
|
|
116
|
+
expect(contextFail);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
(0, test_fns_1.when)('use a compute step ', () => {
|
|
120
|
+
(0, test_fns_1.then)('when only one context is defined, it should infer that context', () => {
|
|
121
|
+
const context = { foo: 123, ...exampleContext };
|
|
122
|
+
expect(context.foo).toBe(123);
|
|
123
|
+
// @ts-expect-error: 'bob' does not exist in type '{ foo: number; log: LogMethods
|
|
124
|
+
const contextFail = { bob: 123 };
|
|
125
|
+
expect(contextFail);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
(0, test_fns_1.given)('a sequence of stitchers with varied procedure.contexts', () => {
|
|
130
|
+
const stitcherWithEmptyContext = new StitchStep_1.StitchStepCompute({
|
|
131
|
+
form: 'COMPUTE',
|
|
132
|
+
readme: null,
|
|
133
|
+
slug: 'slug',
|
|
134
|
+
stitchee: 'one',
|
|
135
|
+
invoke: () => ({ input: null, output: (0, uni_time_1.asUniDateTime)(new Date()) }),
|
|
136
|
+
});
|
|
137
|
+
const stitcherWithFooContext = new StitchStep_1.StitchStepCompute({
|
|
138
|
+
form: 'COMPUTE',
|
|
139
|
+
readme: null,
|
|
140
|
+
slug: 'slug',
|
|
141
|
+
stitchee: 'two',
|
|
142
|
+
invoke: () => ({ input: null, output: (0, uni_time_1.asUniDateTime)(new Date()) }),
|
|
143
|
+
});
|
|
144
|
+
(0, test_fns_1.then)('when only one context is defined, it should infer that context', () => {
|
|
145
|
+
const sequence = [stitcherWithFooContext];
|
|
146
|
+
const context = { foo: 123, ...exampleContext };
|
|
147
|
+
expect(context.foo).toBe(123);
|
|
148
|
+
// @ts-expect-error: 'bob' does not exist in type '{ foo: number;
|
|
149
|
+
const failure = { bob: 123, ...exampleContext };
|
|
150
|
+
expect(failure);
|
|
151
|
+
});
|
|
152
|
+
const stitcherWithBarContext = new StitchStep_1.StitchStepCompute({
|
|
153
|
+
form: 'COMPUTE',
|
|
154
|
+
readme: null,
|
|
155
|
+
slug: 'slug',
|
|
156
|
+
stitchee: 'three',
|
|
157
|
+
invoke: () => ({ input: null, output: (0, uni_time_1.asUniDateTime)(new Date()) }),
|
|
158
|
+
});
|
|
159
|
+
(0, test_fns_1.then)('when multiple contexts are defined, it should merge them', () => {
|
|
160
|
+
const sequence = [
|
|
161
|
+
stitcherWithFooContext,
|
|
162
|
+
stitcherWithBarContext,
|
|
163
|
+
];
|
|
164
|
+
const context = {
|
|
165
|
+
foo: 123,
|
|
166
|
+
bar: 'hello',
|
|
167
|
+
...exampleContext,
|
|
168
|
+
};
|
|
169
|
+
expect(context.foo).toBe(123);
|
|
170
|
+
expect(context.bar).toBe('hello');
|
|
171
|
+
});
|
|
172
|
+
(0, test_fns_1.then)('when all contexts are Empty, result should be Empty', () => {
|
|
173
|
+
const sequence = [stitcherWithEmptyContext];
|
|
174
|
+
const context = { ...exampleContext };
|
|
175
|
+
expect(context);
|
|
176
|
+
});
|
|
177
|
+
(0, test_fns_1.then)('when mix of Empty and defined, it should merge correctly', () => {
|
|
178
|
+
const sequence = [
|
|
179
|
+
stitcherWithEmptyContext,
|
|
180
|
+
stitcherWithBarContext,
|
|
181
|
+
];
|
|
182
|
+
const context = {
|
|
183
|
+
bar: 'hello',
|
|
184
|
+
...exampleContext,
|
|
185
|
+
};
|
|
186
|
+
expect(context.bar).toBe('hello');
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
//# sourceMappingURL=GStitcherInferredFromRoute.generic.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GStitcherInferredFromRoute.generic.test.js","sourceRoot":"","sources":["../../../../src/logic/weave/compose/GStitcherInferredFromRoute.generic.test.ts"],"names":[],"mappings":";;AAAA,iDAK4B;AAE5B,mDAAyD;AACzD,uCAA6C;AAG7C,oFAAiF;AACjF,0FAAuF;AAEvF,mEAAuE;AAEvE,2DAAwD;AAKxD,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC1C,MAAM,cAAc,GAAG;QACrB,GAAG,IAAA,uCAAkB,GAAE;QACvB,GAAG,IAAA,6CAAqB,GAAE;KAC3B,CAAC;IAEF,MAAM,eAAe,GAAG,IAAI,8BAAiB,CAE3C;QACA,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,IAAI;QACZ,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAA,wBAAa,EAAC,IAAI,IAAI,EAAE,CAAC,EAAE,CAAC;KACnE,CAAC,CAAC;IAEH,MAAM,gBAAgB,GAAG,IAAI,8BAAiB,CAE5C;QACA,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,IAAI;QACZ,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,CAAC,EAAE,OAAO,E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C,qDAAqD,EAAE,GAAG,EAAE;YAC/D,MAAM,QAAQ,GAAG,CAAC,wBAAwB,CAAU,CAAC;YAGrD,MAAM,OAAO,GAAwB,EAAE,GAAG,cAAc,EAAE,CAAC;YAC3D,MAAM,CAAC,OAAO,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,IAAA,eAAI,EAAC,0DAA0D,EAAE,GAAG,EAAE;YACpE,MAAM,QAAQ,GAAG;gBACf,wBAAwB;gBACxB,sBAAsB;aACd,CAAC;YAGX,MAAM,OAAO,GAAwB;gBACnC,GAAG,EAAE,OAAO;gBACZ,GAAG,cAAc;aAClB,CAAC;YACF,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { GStitcher, Stitcher } from '../../../domain/objects/Stitcher';
|
|
2
|
+
/**
|
|
3
|
+
* .what = transforms a union into an intersection of its members
|
|
4
|
+
* .why = needed to merge multiple object types into one composite type (e.g. { foo } | { bar } → { foo } & { bar })
|
|
5
|
+
*/
|
|
6
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
7
|
+
/**
|
|
8
|
+
* .what = merges a tuple of object types into one composite object type
|
|
9
|
+
* .why = uses `UnionToIntersection` to combine all tuple elements, then removes any leftover index signatures (e.g. from `Record<string, never>`)
|
|
10
|
+
*/
|
|
11
|
+
type MergeUnion<T extends readonly any[]> = UnionToIntersection<T[number]> extends infer I ? {
|
|
12
|
+
[K in keyof I]: I[K];
|
|
13
|
+
} : never;
|
|
14
|
+
/**
|
|
15
|
+
* .what = semantic alias for any object type used as a procedure context
|
|
16
|
+
* .why = improves readability and conveys the intent of "context-like" shape
|
|
17
|
+
*/
|
|
18
|
+
type ProcedureContext<T extends GStitcher['context']> = T;
|
|
19
|
+
/**
|
|
20
|
+
* .what = merges a readonly tuple of one or more procedure contexts into a single composite context
|
|
21
|
+
* .why = used to infer the combined required context from a sequence of stitchers
|
|
22
|
+
*/
|
|
23
|
+
export type ProcedureContextMerged<TList extends readonly [ProcedureContext<any>, ...ProcedureContext<any>[]]> = MergeUnion<TList>;
|
|
24
|
+
/**
|
|
25
|
+
* .what = enables [...spread, plus] composition of context tuple, pre merge
|
|
26
|
+
*/
|
|
27
|
+
export type ProcedureContextSpread<T extends readonly [Stitcher<GStitcher>, ...Stitcher<GStitcher>[]]> = T extends readonly [
|
|
28
|
+
infer A extends Stitcher<GStitcher>,
|
|
29
|
+
...infer R extends Stitcher<GStitcher>[]
|
|
30
|
+
] ? [
|
|
31
|
+
A extends Stitcher<infer GA> ? GA['context'] : never,
|
|
32
|
+
...{
|
|
33
|
+
[K in keyof R]: R[K] extends Stitcher<infer GR> ? GR['context'] : never;
|
|
34
|
+
}
|
|
35
|
+
] : never;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcedureContextMerged.generic.js","sourceRoot":"","sources":["../../../../src/logic/weave/compose/ProcedureContextMerged.generic.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const test_fns_1 = require("test-fns");
|
|
4
|
+
describe('ProcedureContextMerged', () => {
|
|
5
|
+
(0, test_fns_1.given)('a tuple with only one context', () => {
|
|
6
|
+
(0, test_fns_1.then)('it should infer that context directly', () => {
|
|
7
|
+
const context = { foo: 123 };
|
|
8
|
+
expect(context.foo).toBe(123);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
(0, test_fns_1.given)('a tuple with multiple contexts', () => {
|
|
12
|
+
(0, test_fns_1.then)('it should merge them into one', () => {
|
|
13
|
+
const context = { foo: 1, bar: 'hello' };
|
|
14
|
+
expect(context.foo).toBe(1);
|
|
15
|
+
expect(context.bar).toBe('hello');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
(0, test_fns_1.given)('a tuple with overlapping keys', () => {
|
|
19
|
+
(0, test_fns_1.then)('the intersection should be used (number & string = never)', () => {
|
|
20
|
+
// @ts-expect-error: 'foo' cannot be both number and string
|
|
21
|
+
const context = { foo: 123 };
|
|
22
|
+
expect(context);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
(0, test_fns_1.given)('an input that is not a tuple of at least one context', () => {
|
|
26
|
+
expect(true);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=ProcedureContextMerged.generic.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcedureContextMerged.generic.test.js","sourceRoot":"","sources":["../../../../src/logic/weave/compose/ProcedureContextMerged.generic.test.ts"],"names":[],"mappings":";;AAAA,uCAAuC;AAIvC,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,IAAA,gBAAK,EAAC,+BAA+B,EAAE,GAAG,EAAE;QAG1C,IAAA,eAAI,EAAC,uCAAuC,EAAE,GAAG,EAAE;YACjD,MAAM,OAAO,GAAW,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;YACrC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAA,gBAAK,EAAC,gCAAgC,EAAE,GAAG,EAAE;QAK3C,IAAA,eAAI,EAAC,+BAA+B,EAAE,GAAG,EAAE;YACzC,MAAM,OAAO,GAAW,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;YACjD,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC5B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