@powerhousedao/reactor-workflow 6.2.3-dev.32 → 6.2.3-dev.34

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.
@@ -8,7 +8,7 @@ import { promisify } from "node:util";
8
8
  import { gunzip } from "node:zlib";
9
9
  import { childLogger } from "document-model";
10
10
  import { fileURLToPath } from "node:url";
11
- import { BRANCH_PORTS, CORE_PIECE_NAME, NEXT_PORT, PIECE_ACTION_PORTS, SCHEDULE_MODES, SCHEDULE_UNIT_MS, TRIGGER_PORTS, undeclaredPortEdges } from "@powerhousedao/pieces-framework/workflow";
11
+ import { BRANCH_PORTS, CORE_PIECE_NAME, CORE_PIECE_NAME as CORE_PIECE_NAME$1, NEXT_PORT, PIECE_ACTION_PORTS, SCHEDULE_MODES, SCHEDULE_UNIT_MS, TRIGGER_PORTS, undeclaredPortEdges } from "@powerhousedao/pieces-framework/workflow";
12
12
  import { createHash, randomUUID } from "node:crypto";
13
13
  import { blockKey, isExactVersion } from "@powerhousedao/pieces-framework/block-type";
14
14
  //#region src/pieces/activepieces/registry-source.ts
@@ -1036,6 +1036,162 @@ function evaluateCondition(condition, scope) {
1036
1036
  return Boolean(resolved);
1037
1037
  }
1038
1038
  //#endregion
1039
+ //#region src/pieces/core/branch-operators.ts
1040
+ var BranchConfigError = class extends Error {
1041
+ constructor(message) {
1042
+ super(`Branch: ${message}`);
1043
+ this.name = "BranchConfigError";
1044
+ }
1045
+ };
1046
+ function describe(value) {
1047
+ if (value === void 0) return "nothing";
1048
+ const text = JSON.stringify(value);
1049
+ return text.length > 60 ? `${text.slice(0, 57)}...` : text;
1050
+ }
1051
+ function asText(value, side, caseSensitive) {
1052
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") throw new BranchConfigError(`${side} must be text, got ${describe(value)}`);
1053
+ const text = String(value);
1054
+ return caseSensitive ? text : text.toLowerCase();
1055
+ }
1056
+ const DECIMAL = /^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?$/;
1057
+ function asNumber(value, side) {
1058
+ if (typeof value === "number" && Number.isFinite(value)) return value;
1059
+ if (typeof value === "string" && DECIMAL.test(value.trim())) return Number(value.trim());
1060
+ throw new BranchConfigError(`${side} must be a number, got ${describe(value)}`);
1061
+ }
1062
+ function asBoolean(value, side) {
1063
+ if (typeof value === "boolean") return value;
1064
+ if (value === "true") return true;
1065
+ if (value === "false") return false;
1066
+ throw new BranchConfigError(`${side} must be true or false, got ${describe(value)}`);
1067
+ }
1068
+ function asDate(value, side) {
1069
+ const time = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? Date.parse(value) : NaN;
1070
+ if (!Number.isFinite(time)) throw new BranchConfigError(`${side} must be a date, got ${describe(value)}`);
1071
+ return time;
1072
+ }
1073
+ function asList(value, side) {
1074
+ if (Array.isArray(value)) return value;
1075
+ throw new BranchConfigError(`${side} must be a list, got ${describe(value)}`);
1076
+ }
1077
+ const blank = (value) => value === void 0 || value === null || value === "";
1078
+ function textOp(label, test) {
1079
+ return {
1080
+ label,
1081
+ left: "text",
1082
+ binary: true,
1083
+ text: true,
1084
+ test: (left, right, caseSensitive) => test(asText(left, "left", caseSensitive), asText(right, "right", caseSensitive))
1085
+ };
1086
+ }
1087
+ function numberOp(label, test) {
1088
+ return {
1089
+ label,
1090
+ left: "number",
1091
+ binary: true,
1092
+ text: false,
1093
+ test: (left, right) => test(asNumber(left, "left"), asNumber(right, "right"))
1094
+ };
1095
+ }
1096
+ function dateOp(label, test) {
1097
+ return {
1098
+ label,
1099
+ left: "date",
1100
+ binary: true,
1101
+ text: false,
1102
+ test: (left, right) => test(asDate(left, "left"), asDate(right, "right"))
1103
+ };
1104
+ }
1105
+ function unary(label, left, test) {
1106
+ return {
1107
+ label,
1108
+ left,
1109
+ binary: false,
1110
+ text: false,
1111
+ test
1112
+ };
1113
+ }
1114
+ function listHas(left, right, caseSensitive) {
1115
+ const wanted = asText(right, "right", caseSensitive);
1116
+ return asList(left, "left").some((item) => {
1117
+ if (typeof item === "object" && item !== null) return false;
1118
+ const text = String(item);
1119
+ return (caseSensitive ? text : text.toLowerCase()) === wanted;
1120
+ });
1121
+ }
1122
+ const BRANCH_OPERATORS = {
1123
+ TEXT_EXACTLY_MATCHES: textOp("Text is exactly", (a, b) => a === b),
1124
+ TEXT_DOES_NOT_EXACTLY_MATCH: textOp("Text is not exactly", (a, b) => a !== b),
1125
+ TEXT_CONTAINS: textOp("Text contains", (a, b) => a.includes(b)),
1126
+ TEXT_DOES_NOT_CONTAIN: textOp("Text does not contain", (a, b) => !a.includes(b)),
1127
+ TEXT_STARTS_WITH: textOp("Text starts with", (a, b) => a.startsWith(b)),
1128
+ TEXT_DOES_NOT_START_WITH: textOp("Text does not start with", (a, b) => !a.startsWith(b)),
1129
+ TEXT_ENDS_WITH: textOp("Text ends with", (a, b) => a.endsWith(b)),
1130
+ TEXT_DOES_NOT_END_WITH: textOp("Text does not end with", (a, b) => !a.endsWith(b)),
1131
+ NUMBER_IS_EQUAL_TO: numberOp("Number equals", (a, b) => a === b),
1132
+ NUMBER_IS_GREATER_THAN: numberOp("Number is greater than", (a, b) => a > b),
1133
+ NUMBER_IS_LESS_THAN: numberOp("Number is less than", (a, b) => a < b),
1134
+ DATE_IS_EQUAL: dateOp("Date is", (a, b) => a === b),
1135
+ DATE_IS_BEFORE: dateOp("Date is before", (a, b) => a < b),
1136
+ DATE_IS_AFTER: dateOp("Date is after", (a, b) => a > b),
1137
+ BOOLEAN_IS_TRUE: unary("Is true", "boolean", (v) => asBoolean(v, "left")),
1138
+ BOOLEAN_IS_FALSE: unary("Is false", "boolean", (v) => !asBoolean(v, "left")),
1139
+ LIST_CONTAINS: {
1140
+ label: "List contains",
1141
+ left: "list",
1142
+ binary: true,
1143
+ text: true,
1144
+ test: listHas
1145
+ },
1146
+ LIST_DOES_NOT_CONTAIN: {
1147
+ label: "List does not contain",
1148
+ left: "list",
1149
+ binary: true,
1150
+ text: true,
1151
+ test: (left, right, caseSensitive) => !listHas(left, right, caseSensitive)
1152
+ },
1153
+ LIST_IS_EMPTY: unary("List is empty", "list", (v) => asList(v, "left").length === 0),
1154
+ LIST_IS_NOT_EMPTY: unary("List is not empty", "list", (v) => asList(v, "left").length > 0),
1155
+ EXISTS: unary("Exists", "any", (v) => !blank(v)),
1156
+ DOES_NOT_EXIST: unary("Does not exist", "any", blank)
1157
+ };
1158
+ const EXISTENCE_OPERATORS = /* @__PURE__ */ new Set(["EXISTS", "DOES_NOT_EXIST"]);
1159
+ const OPERATORS = BRANCH_OPERATORS;
1160
+ const DEFAULT_BRANCH_OPERATOR = "TEXT_EXACTLY_MATCHES";
1161
+ function evaluateBranch(config) {
1162
+ if (config === null || typeof config !== "object" || Array.isArray(config)) throw new BranchConfigError("the config must be an object");
1163
+ const { operator, left, right, caseSensitive } = config;
1164
+ if (operator === void 0 || operator === null || operator === "") throw new BranchConfigError("an operator is required");
1165
+ if (typeof operator !== "string" || !Object.hasOwn(OPERATORS, operator)) throw new BranchConfigError(`unknown operator ${describe(operator)}`);
1166
+ if (caseSensitive !== void 0 && typeof caseSensitive !== "boolean") throw new BranchConfigError("caseSensitive must be true or false");
1167
+ const spec = OPERATORS[operator];
1168
+ const result = spec.test(left, right, caseSensitive === true);
1169
+ return {
1170
+ operator,
1171
+ left,
1172
+ ...spec.binary ? { right } : {},
1173
+ result
1174
+ };
1175
+ }
1176
+ //#endregion
1177
+ //#region src/pieces/engine/step-input.ts
1178
+ function resolveStepInput(step, scope) {
1179
+ const { config } = step;
1180
+ if (step.pieceName !== CORE_PIECE_NAME || step.actionName !== "branch" || config === null || typeof config !== "object" || Array.isArray(config) || !Object.hasOwn(config, "left")) return resolveExpressions(config, scope);
1181
+ const record = config;
1182
+ const operator = resolveExpressions(record.operator, scope);
1183
+ if (typeof operator !== "string" || !EXISTENCE_OPERATORS.has(operator)) return resolveExpressions(config, scope);
1184
+ return Object.fromEntries(Object.entries(record).map(([key, value]) => [key, key === "left" ? resolveOrMissing(value, scope) : resolveExpressions(value, scope)]));
1185
+ }
1186
+ function resolveOrMissing(value, scope) {
1187
+ try {
1188
+ return resolveExpressions(value, scope);
1189
+ } catch (error) {
1190
+ if (error instanceof UnresolvedReferenceError) return void 0;
1191
+ throw error;
1192
+ }
1193
+ }
1194
+ //#endregion
1039
1195
  //#region src/pieces/engine/connections.ts
1040
1196
  var ConnectionNotFoundError = class extends Error {
1041
1197
  constructor(connectionId) {
@@ -1196,143 +1352,6 @@ var BoundConnectionResolver = class {
1196
1352
  }
1197
1353
  };
1198
1354
  //#endregion
1199
- //#region src/pieces/core/branch-operators.ts
1200
- var BranchConfigError = class extends Error {
1201
- constructor(message) {
1202
- super(`Branch: ${message}`);
1203
- this.name = "BranchConfigError";
1204
- }
1205
- };
1206
- function describe(value) {
1207
- if (value === void 0) return "nothing";
1208
- const text = JSON.stringify(value);
1209
- return text.length > 60 ? `${text.slice(0, 57)}...` : text;
1210
- }
1211
- function asText(value, side, caseSensitive) {
1212
- if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") throw new BranchConfigError(`${side} must be text, got ${describe(value)}`);
1213
- const text = String(value);
1214
- return caseSensitive ? text : text.toLowerCase();
1215
- }
1216
- const DECIMAL = /^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?$/;
1217
- function asNumber(value, side) {
1218
- if (typeof value === "number" && Number.isFinite(value)) return value;
1219
- if (typeof value === "string" && DECIMAL.test(value.trim())) return Number(value.trim());
1220
- throw new BranchConfigError(`${side} must be a number, got ${describe(value)}`);
1221
- }
1222
- function asBoolean(value, side) {
1223
- if (typeof value === "boolean") return value;
1224
- if (value === "true") return true;
1225
- if (value === "false") return false;
1226
- throw new BranchConfigError(`${side} must be true or false, got ${describe(value)}`);
1227
- }
1228
- function asDate(value, side) {
1229
- const time = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? Date.parse(value) : NaN;
1230
- if (!Number.isFinite(time)) throw new BranchConfigError(`${side} must be a date, got ${describe(value)}`);
1231
- return time;
1232
- }
1233
- function asList(value, side) {
1234
- if (Array.isArray(value)) return value;
1235
- throw new BranchConfigError(`${side} must be a list, got ${describe(value)}`);
1236
- }
1237
- const blank = (value) => value === void 0 || value === null || value === "";
1238
- function textOp(label, test) {
1239
- return {
1240
- label,
1241
- left: "text",
1242
- binary: true,
1243
- text: true,
1244
- test: (left, right, caseSensitive) => test(asText(left, "left", caseSensitive), asText(right, "right", caseSensitive))
1245
- };
1246
- }
1247
- function numberOp(label, test) {
1248
- return {
1249
- label,
1250
- left: "number",
1251
- binary: true,
1252
- text: false,
1253
- test: (left, right) => test(asNumber(left, "left"), asNumber(right, "right"))
1254
- };
1255
- }
1256
- function dateOp(label, test) {
1257
- return {
1258
- label,
1259
- left: "date",
1260
- binary: true,
1261
- text: false,
1262
- test: (left, right) => test(asDate(left, "left"), asDate(right, "right"))
1263
- };
1264
- }
1265
- function unary(label, left, test) {
1266
- return {
1267
- label,
1268
- left,
1269
- binary: false,
1270
- text: false,
1271
- test
1272
- };
1273
- }
1274
- function listHas(left, right, caseSensitive) {
1275
- const wanted = asText(right, "right", caseSensitive);
1276
- return asList(left, "left").some((item) => {
1277
- if (typeof item === "object" && item !== null) return false;
1278
- const text = String(item);
1279
- return (caseSensitive ? text : text.toLowerCase()) === wanted;
1280
- });
1281
- }
1282
- const BRANCH_OPERATORS = {
1283
- TEXT_EXACTLY_MATCHES: textOp("Text is exactly", (a, b) => a === b),
1284
- TEXT_DOES_NOT_EXACTLY_MATCH: textOp("Text is not exactly", (a, b) => a !== b),
1285
- TEXT_CONTAINS: textOp("Text contains", (a, b) => a.includes(b)),
1286
- TEXT_DOES_NOT_CONTAIN: textOp("Text does not contain", (a, b) => !a.includes(b)),
1287
- TEXT_STARTS_WITH: textOp("Text starts with", (a, b) => a.startsWith(b)),
1288
- TEXT_DOES_NOT_START_WITH: textOp("Text does not start with", (a, b) => !a.startsWith(b)),
1289
- TEXT_ENDS_WITH: textOp("Text ends with", (a, b) => a.endsWith(b)),
1290
- TEXT_DOES_NOT_END_WITH: textOp("Text does not end with", (a, b) => !a.endsWith(b)),
1291
- NUMBER_IS_EQUAL_TO: numberOp("Number equals", (a, b) => a === b),
1292
- NUMBER_IS_GREATER_THAN: numberOp("Number is greater than", (a, b) => a > b),
1293
- NUMBER_IS_LESS_THAN: numberOp("Number is less than", (a, b) => a < b),
1294
- DATE_IS_EQUAL: dateOp("Date is", (a, b) => a === b),
1295
- DATE_IS_BEFORE: dateOp("Date is before", (a, b) => a < b),
1296
- DATE_IS_AFTER: dateOp("Date is after", (a, b) => a > b),
1297
- BOOLEAN_IS_TRUE: unary("Is true", "boolean", (v) => asBoolean(v, "left")),
1298
- BOOLEAN_IS_FALSE: unary("Is false", "boolean", (v) => !asBoolean(v, "left")),
1299
- LIST_CONTAINS: {
1300
- label: "List contains",
1301
- left: "list",
1302
- binary: true,
1303
- text: true,
1304
- test: listHas
1305
- },
1306
- LIST_DOES_NOT_CONTAIN: {
1307
- label: "List does not contain",
1308
- left: "list",
1309
- binary: true,
1310
- text: true,
1311
- test: (left, right, caseSensitive) => !listHas(left, right, caseSensitive)
1312
- },
1313
- LIST_IS_EMPTY: unary("List is empty", "list", (v) => asList(v, "left").length === 0),
1314
- LIST_IS_NOT_EMPTY: unary("List is not empty", "list", (v) => asList(v, "left").length > 0),
1315
- EXISTS: unary("Exists", "any", (v) => !blank(v)),
1316
- DOES_NOT_EXIST: unary("Does not exist", "any", blank)
1317
- };
1318
- const OPERATORS = BRANCH_OPERATORS;
1319
- const DEFAULT_BRANCH_OPERATOR = "TEXT_EXACTLY_MATCHES";
1320
- function evaluateBranch(config) {
1321
- if (config === null || typeof config !== "object" || Array.isArray(config)) throw new BranchConfigError("the config must be an object");
1322
- const { operator, left, right, caseSensitive } = config;
1323
- if (operator === void 0 || operator === null || operator === "") throw new BranchConfigError("an operator is required");
1324
- if (typeof operator !== "string" || !Object.hasOwn(OPERATORS, operator)) throw new BranchConfigError(`unknown operator ${describe(operator)}`);
1325
- if (caseSensitive !== void 0 && typeof caseSensitive !== "boolean") throw new BranchConfigError("caseSensitive must be true or false");
1326
- const spec = OPERATORS[operator];
1327
- const result = spec.test(left, right, caseSensitive === true);
1328
- return {
1329
- operator,
1330
- left,
1331
- ...spec.binary ? { right } : {},
1332
- result
1333
- };
1334
- }
1335
- //#endregion
1336
1355
  //#region src/pieces/core/hints.ts
1337
1356
  function withHints(property, hints) {
1338
1357
  return {
@@ -1663,7 +1682,7 @@ const manualTrigger = createTrigger({
1663
1682
  });
1664
1683
  //#endregion
1665
1684
  //#region src/pieces/core/version.ts
1666
- const CORE_PIECE_VERSION = "6.2.3-dev.32";
1685
+ const CORE_PIECE_VERSION = "6.2.3-dev.34";
1667
1686
  //#endregion
1668
1687
  //#region src/pieces/core/index.ts
1669
1688
  const corePiece = createPiece({
@@ -1683,7 +1702,7 @@ const corePiece = createPiece({
1683
1702
  //#endregion
1684
1703
  //#region src/pieces/builtin.ts
1685
1704
  const BUILTIN_PIECES = [{
1686
- name: CORE_PIECE_NAME,
1705
+ name: CORE_PIECE_NAME$1,
1687
1706
  version: CORE_PIECE_VERSION,
1688
1707
  piece: corePiece
1689
1708
  }];
@@ -2308,7 +2327,7 @@ async function runWorkflow(options) {
2308
2327
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
2309
2328
  let input;
2310
2329
  try {
2311
- input = resolveExpressions(step.config, scope);
2330
+ input = resolveStepInput(step, scope);
2312
2331
  checkDynamicProperties(input, step.propertySettings);
2313
2332
  const result = await executor.execute({
2314
2333
  block: stepBlock(step),
@@ -2442,6 +2461,6 @@ function installedPieces() {
2442
2461
  return [...builtinLocalPieces(), ...packagePieces.entries().filter((piece) => !isBuiltinPiece(piece.name))];
2443
2462
  }
2444
2463
  //#endregion
2445
- export { expressionsIn as A, PieceWorker as B, describeBuiltinPiece as C, StaticConnectionResolver as D, BoundConnectionResolver as E, parseSecretRef as F, sourcedResolver as G, PieceWorkerTimeoutError as H, secretRefFromId as I, npmRegistryBaseUrl as J, ensurePieceBundle as K, stepBlock as L, InMemorySecretProvider as M, SecretDeletedError as N, declaredConnectionIds as O, SecretNotFoundError as P, triggerBlock as R, builtinPiece as S, CORE_PIECE_VERSION as T, bundleResolver as U, PieceWorkerError as V, pieceModuleRef as W, setPieceRegistryUrl as X, pieceRegistrySource as Y, servesReactorPort as _, runWorkflow as a, unpinnedNote as b, stepConfigHash as c, ActivepiecesBlockExecutor as d, CompositeBlockExecutor as f, resolvedBlock as g, reactorHandlers as h, packagePieces as i, resolveExpressions as j, shapeConnection as k, DynamicPropertiesError as l, isHostBound as m, installedPiece as n, canonicalJson as o, REACTOR_PORT_PIECE as p, fetchPieceBundle as q, installedPieces as r, hashOf as s, PieceRegistry as t, checkDynamicProperties as u, storeHandlers as v, CORE_PIECE_NAME as w, blockPorts as x, blockLabel as y, PieceWorkerPool as z };
2464
+ export { resolveStepInput as A, PieceWorker as B, describeBuiltinPiece as C, StaticConnectionResolver as D, BoundConnectionResolver as E, parseSecretRef as F, sourcedResolver as G, PieceWorkerTimeoutError as H, secretRefFromId as I, npmRegistryBaseUrl as J, ensurePieceBundle as K, stepBlock as L, InMemorySecretProvider as M, SecretDeletedError as N, declaredConnectionIds as O, SecretNotFoundError as P, triggerBlock as R, builtinPiece as S, CORE_PIECE_VERSION as T, bundleResolver as U, PieceWorkerError as V, pieceModuleRef as W, setPieceRegistryUrl as X, pieceRegistrySource as Y, servesReactorPort as _, runWorkflow as a, unpinnedNote as b, stepConfigHash as c, ActivepiecesBlockExecutor as d, CompositeBlockExecutor as f, resolvedBlock as g, reactorHandlers as h, packagePieces as i, expressionsIn as j, shapeConnection as k, DynamicPropertiesError as l, isHostBound as m, installedPiece as n, canonicalJson as o, REACTOR_PORT_PIECE as p, fetchPieceBundle as q, installedPieces as r, hashOf as s, PieceRegistry as t, checkDynamicProperties as u, storeHandlers as v, CORE_PIECE_NAME$1 as w, blockPorts as x, blockLabel as y, PieceWorkerPool as z };
2446
2465
 
2447
- //# sourceMappingURL=piece-registry-BAm8pRDY.js.map
2466
+ //# sourceMappingURL=piece-registry-CAMLtGeP.js.map