resultar 3.7.0 → 3.9.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/index.js CHANGED
@@ -918,129 +918,6 @@ var ServiceTagValue = class {
918
918
  };
919
919
  /** Creates a service tag that can be requested with `yield*` inside `ResultTask.gen`. */
920
920
  const serviceTag = (identifier) => new ServiceTagValue(identifier);
921
- const applySuccessContinuation = (continuation, exit) => {
922
- switch (continuation._tag) {
923
- case "Map": try {
924
- return {
925
- current: void 0,
926
- currentExit: success(continuation.f(exit.value))
927
- };
928
- } catch (error) {
929
- return {
930
- current: void 0,
931
- currentExit: died(error)
932
- };
933
- }
934
- case "FlatMap": try {
935
- return {
936
- current: continuation.f(exit.value),
937
- currentExit: void 0
938
- };
939
- } catch (error) {
940
- return {
941
- current: void 0,
942
- currentExit: died(error)
943
- };
944
- }
945
- case "Tap": try {
946
- const res = continuation.f(exit.value);
947
- return ResultTask.toTapContinuationStep(res, () => ResultTask.succeed(exit.value), exit);
948
- } catch (error) {
949
- return {
950
- current: void 0,
951
- currentExit: died(error)
952
- };
953
- }
954
- case "MapError": return {
955
- current: void 0,
956
- currentExit: exit
957
- };
958
- case "TapError": return {
959
- current: void 0,
960
- currentExit: exit
961
- };
962
- case "CatchAll": return {
963
- current: void 0,
964
- currentExit: exit
965
- };
966
- default: return {
967
- current: void 0,
968
- currentExit: exit
969
- };
970
- }
971
- };
972
- const applyFailureContinuation = (continuation, exit) => {
973
- switch (continuation._tag) {
974
- case "MapError":
975
- if (exit.cause._tag === "Fail") try {
976
- return {
977
- current: void 0,
978
- currentExit: failed(continuation.f(exit.cause.error))
979
- };
980
- } catch (error) {
981
- return {
982
- current: void 0,
983
- currentExit: died(error)
984
- };
985
- }
986
- return {
987
- current: void 0,
988
- currentExit: exit
989
- };
990
- case "TapError":
991
- if (exit.cause._tag === "Fail") try {
992
- const failError = exit.cause.error;
993
- const res = continuation.f(failError);
994
- return ResultTask.toTapContinuationStep(res, () => ResultTask.fail(failError), exit);
995
- } catch (error) {
996
- return {
997
- current: void 0,
998
- currentExit: died(error)
999
- };
1000
- }
1001
- return {
1002
- current: void 0,
1003
- currentExit: exit
1004
- };
1005
- case "CatchAll":
1006
- if (exit.cause._tag === "Sequential") return {
1007
- current: void 0,
1008
- currentExit: died(new ResultTaskCauseError(exit.cause))
1009
- };
1010
- if (exit.cause._tag === "Fail") try {
1011
- return {
1012
- current: continuation.f(exit.cause.error),
1013
- currentExit: void 0
1014
- };
1015
- } catch (error) {
1016
- return {
1017
- current: void 0,
1018
- currentExit: died(error)
1019
- };
1020
- }
1021
- return {
1022
- current: void 0,
1023
- currentExit: exit
1024
- };
1025
- case "Map": return {
1026
- current: void 0,
1027
- currentExit: exit
1028
- };
1029
- case "FlatMap": return {
1030
- current: void 0,
1031
- currentExit: exit
1032
- };
1033
- case "Tap": return {
1034
- current: void 0,
1035
- currentExit: exit
1036
- };
1037
- default: return {
1038
- current: void 0,
1039
- currentExit: exit
1040
- };
1041
- }
1042
- };
1043
- const applyContinuation = (continuation, exit) => exit._tag === "Success" ? applySuccessContinuation(continuation, exit) : applyFailureContinuation(continuation, exit);
1044
921
  const executeInstruction = async (instruction, continuations, context) => {
1045
922
  switch (instruction._tag) {
1046
923
  case "FlatMap":
@@ -1101,8 +978,129 @@ var ResultTask = class ResultTask extends Pipeable {
1101
978
  } : instructionOrExecute;
1102
979
  this.execute = (context) => ResultTask.runTaskLoop(this, context);
1103
980
  }
1104
- /** @internal */
1105
- static toTapContinuationStep(res, onSuccess, passThroughExit) {
981
+ static #applySuccessContinuation(continuation, exit) {
982
+ switch (continuation._tag) {
983
+ case "Map": try {
984
+ return {
985
+ current: void 0,
986
+ currentExit: success(continuation.f(exit.value))
987
+ };
988
+ } catch (error) {
989
+ return {
990
+ current: void 0,
991
+ currentExit: died(error)
992
+ };
993
+ }
994
+ case "FlatMap": try {
995
+ return {
996
+ current: continuation.f(exit.value),
997
+ currentExit: void 0
998
+ };
999
+ } catch (error) {
1000
+ return {
1001
+ current: void 0,
1002
+ currentExit: died(error)
1003
+ };
1004
+ }
1005
+ case "Tap": try {
1006
+ const res = continuation.f(exit.value);
1007
+ return ResultTask.#toTapContinuationStep(res, () => ResultTask.succeed(exit.value), exit);
1008
+ } catch (error) {
1009
+ return {
1010
+ current: void 0,
1011
+ currentExit: died(error)
1012
+ };
1013
+ }
1014
+ case "MapError": return {
1015
+ current: void 0,
1016
+ currentExit: exit
1017
+ };
1018
+ case "TapError": return {
1019
+ current: void 0,
1020
+ currentExit: exit
1021
+ };
1022
+ case "CatchAll": return {
1023
+ current: void 0,
1024
+ currentExit: exit
1025
+ };
1026
+ default: return {
1027
+ current: void 0,
1028
+ currentExit: exit
1029
+ };
1030
+ }
1031
+ }
1032
+ static #applyFailureContinuation(continuation, exit) {
1033
+ switch (continuation._tag) {
1034
+ case "MapError":
1035
+ if (exit.cause._tag === "Fail") try {
1036
+ return {
1037
+ current: void 0,
1038
+ currentExit: failed(continuation.f(exit.cause.error))
1039
+ };
1040
+ } catch (error) {
1041
+ return {
1042
+ current: void 0,
1043
+ currentExit: died(error)
1044
+ };
1045
+ }
1046
+ return {
1047
+ current: void 0,
1048
+ currentExit: exit
1049
+ };
1050
+ case "TapError":
1051
+ if (exit.cause._tag === "Fail") try {
1052
+ const failError = exit.cause.error;
1053
+ const res = continuation.f(failError);
1054
+ return ResultTask.#toTapContinuationStep(res, () => ResultTask.fail(failError), exit);
1055
+ } catch (error) {
1056
+ return {
1057
+ current: void 0,
1058
+ currentExit: died(error)
1059
+ };
1060
+ }
1061
+ return {
1062
+ current: void 0,
1063
+ currentExit: exit
1064
+ };
1065
+ case "CatchAll":
1066
+ if (exit.cause._tag === "Sequential") return {
1067
+ current: void 0,
1068
+ currentExit: died(new ResultTaskCauseError(exit.cause))
1069
+ };
1070
+ if (exit.cause._tag === "Fail") try {
1071
+ return {
1072
+ current: continuation.f(exit.cause.error),
1073
+ currentExit: void 0
1074
+ };
1075
+ } catch (error) {
1076
+ return {
1077
+ current: void 0,
1078
+ currentExit: died(error)
1079
+ };
1080
+ }
1081
+ return {
1082
+ current: void 0,
1083
+ currentExit: exit
1084
+ };
1085
+ case "Map": return {
1086
+ current: void 0,
1087
+ currentExit: exit
1088
+ };
1089
+ case "FlatMap": return {
1090
+ current: void 0,
1091
+ currentExit: exit
1092
+ };
1093
+ case "Tap": return {
1094
+ current: void 0,
1095
+ currentExit: exit
1096
+ };
1097
+ default: return {
1098
+ current: void 0,
1099
+ currentExit: exit
1100
+ };
1101
+ }
1102
+ }
1103
+ static #toTapContinuationStep(res, onSuccess, passThroughExit) {
1106
1104
  if (res instanceof ResultTask) return {
1107
1105
  current: res.flatMap(onSuccess),
1108
1106
  currentExit: void 0
@@ -1132,7 +1130,7 @@ var ResultTask = class ResultTask extends Pipeable {
1132
1130
  const nextContinuation = continuations.pop();
1133
1131
  if (nextContinuation === void 0) return currentExit;
1134
1132
  const resolvedExit = context.signal.aborted && currentExit._tag === "Success" ? interrupted(context.signal) : currentExit;
1135
- const step = applyContinuation(nextContinuation, resolvedExit);
1133
+ const step = resolvedExit._tag === "Success" ? ResultTask.#applySuccessContinuation(nextContinuation, resolvedExit) : ResultTask.#applyFailureContinuation(nextContinuation, resolvedExit);
1136
1134
  current = step.current;
1137
1135
  currentExit = step.currentExit;
1138
1136
  }
@@ -1224,8 +1222,8 @@ var ResultTask = class ResultTask extends Pipeable {
1224
1222
  return interruptSuccess(await scope.close(interruptSuccess(exit, context.signal)), context.signal);
1225
1223
  });
1226
1224
  }
1227
- /** Creates a service tag that can be requested with `yield*` inside `ResultTask.gen`. */
1228
1225
  static service(identifier) {
1226
+ if (identifier === void 0) return (name) => new ServiceTagValue(name);
1229
1227
  return new ServiceTagValue(identifier);
1230
1228
  }
1231
1229
  /** Builds a task from a generator and short-circuits on the first failed task. */
@@ -1410,6 +1408,12 @@ var ResultTask = class ResultTask extends Pipeable {
1410
1408
  const pending = /* @__PURE__ */ new Set();
1411
1409
  let closing = void 0;
1412
1410
  return {
1411
+ addFinalizer: (release) => {
1412
+ if (closing !== void 0) throw new Error("Cannot acquire into a closing ResultTask scope");
1413
+ scope.add((exit) => ResultTask.runExit(ResultTask.gen(function* () {
1414
+ yield* release(exit);
1415
+ })));
1416
+ },
1413
1417
  use: (task) => new ResultTask(async (context) => {
1414
1418
  if (closing !== void 0) return died(/* @__PURE__ */ new Error("Cannot execute in a closed ResultTask scope"));
1415
1419
  const attempt = new TaskScope();
package/dist/llms.txt ADDED
@@ -0,0 +1,11 @@
1
+ # Resultar 3.9.0
2
+
3
+ Documentation bundled with this package version. Installed declarations remain authoritative.
4
+
5
+ - [Agent guide](agent/SKILL.md)
6
+ - [API semantics](agent/references/api.md)
7
+ - [Services and HTTP scopes](agent/references/services.md)
8
+ - [Compiled core example](agent/examples/workflow.mjs)
9
+ - [Companion versions used to write this guide](agent/versions.json)
10
+
11
+ Read companion packages' installed READMEs when their versions differ from versions.json.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resultar",
3
- "version": "3.7.0",
3
+ "version": "3.9.0",
4
4
  "description": "Result pattern for TypeScript",
5
5
  "keywords": [
6
6
  "error-handling",
@@ -43,13 +43,13 @@
43
43
  "devDependencies": {
44
44
  "@stryker-mutator/core": "10.0.0",
45
45
  "@stryker-mutator/vitest-runner": "10.0.0",
46
- "@types/node": "26.5.0",
46
+ "@types/node": "26.5.1",
47
47
  "@vitest/coverage-v8": "4.1.11",
48
48
  "@vitest/ui": "4.1.11",
49
- "fallow": "3.23.0",
49
+ "fallow": "3.25.0",
50
50
  "tsx": "4.23.13",
51
51
  "typescript": "7.0.2",
52
- "vite-plus": "0.3.0",
52
+ "vite-plus": "0.3.2",
53
53
  "vitest": "4.1.11"
54
54
  },
55
55
  "peerDependencies": {
@@ -71,7 +71,7 @@
71
71
  ],
72
72
  "scripts": {
73
73
  "analyze": "fallow",
74
- "build": "vp pack",
74
+ "build": "vp pack && node ../../scripts/build-agent-guide.mjs",
75
75
  "check": "vp check",
76
76
  "check:full": "pnpm run build && pnpm run check && vp test run --coverage",
77
77
  "fmt": "vp fmt",