@rkmodules/rules 0.0.89 → 0.0.91

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.cjs.js CHANGED
@@ -1131,6 +1131,75 @@ var tanDeg = {
1131
1131
  }); },
1132
1132
  };
1133
1133
 
1134
+ var ceil = {
1135
+ name: "ceil",
1136
+ label: "Round up",
1137
+ description: "Round a number up to the nearest integer",
1138
+ inputs: {
1139
+ x: { type: "number", default: 0 },
1140
+ },
1141
+ outputs: {
1142
+ ceil: "number",
1143
+ },
1144
+ impl: function (inputs) { return __awaiter(void 0, void 0, void 0, function () {
1145
+ return __generator(this, function (_a) {
1146
+ return [2 /*return*/, {
1147
+ ceil: mapTree(inputs.x, function (x) {
1148
+ if (x === undefined)
1149
+ return DISCARD;
1150
+ return Math.ceil(x);
1151
+ }),
1152
+ }];
1153
+ });
1154
+ }); },
1155
+ };
1156
+
1157
+ var floor = {
1158
+ name: "floor",
1159
+ label: "Round down",
1160
+ description: "Round a number down to the nearest integer",
1161
+ inputs: {
1162
+ x: { type: "number", default: 0 },
1163
+ },
1164
+ outputs: {
1165
+ floor: "number",
1166
+ },
1167
+ impl: function (inputs) { return __awaiter(void 0, void 0, void 0, function () {
1168
+ return __generator(this, function (_a) {
1169
+ return [2 /*return*/, {
1170
+ floor: mapTree(inputs.x, function (x) {
1171
+ if (x === undefined)
1172
+ return DISCARD;
1173
+ return Math.floor(x);
1174
+ }),
1175
+ }];
1176
+ });
1177
+ }); },
1178
+ };
1179
+
1180
+ var round = {
1181
+ name: "round",
1182
+ label: "Round",
1183
+ description: "Round a number to the nearest integer",
1184
+ inputs: {
1185
+ x: { type: "number", default: 0 },
1186
+ },
1187
+ outputs: {
1188
+ round: "number",
1189
+ },
1190
+ impl: function (inputs) { return __awaiter(void 0, void 0, void 0, function () {
1191
+ return __generator(this, function (_a) {
1192
+ return [2 /*return*/, {
1193
+ round: mapTree(inputs.x, function (x) {
1194
+ if (x === undefined)
1195
+ return DISCARD;
1196
+ return Math.round(x);
1197
+ }),
1198
+ }];
1199
+ });
1200
+ }); },
1201
+ };
1202
+
1134
1203
  var _a$6;
1135
1204
  var primitives$6 = (_a$6 = {},
1136
1205
  _a$6[calc.name] = calc,
@@ -1147,6 +1216,9 @@ var primitives$6 = (_a$6 = {},
1147
1216
  _a$6[tanDeg.name] = tanDeg,
1148
1217
  _a$6[sqrt.name] = sqrt,
1149
1218
  _a$6[pow.name] = pow,
1219
+ _a$6[round.name] = round,
1220
+ _a$6[ceil.name] = ceil,
1221
+ _a$6[floor.name] = floor,
1150
1222
  _a$6);
1151
1223
 
1152
1224
  var filterList = {
@@ -1736,7 +1808,7 @@ var Engine = /** @class */ (function () {
1736
1808
  };
1737
1809
  Engine.prototype.runGraph = function (node, inputs, params) {
1738
1810
  return __awaiter(this, void 0, void 0, function () {
1739
- var _a, body, executionId, context, startTime, _b, _c, _d, _i, name_1, fnCall, fn, inputs_1, params_1, result_1, cacheResult, startTime_1, endTime_1, result, endTime;
1811
+ var _a, body, executionId, context, startTime, _b, _c, _d, _i, name_1, fnCall, fn, inputs_1, params_1, result_1, cacheResult, startTime_1, endTime_1, result, endTime, response;
1740
1812
  return __generator(this, function (_e) {
1741
1813
  switch (_e.label) {
1742
1814
  case 0:
@@ -1796,6 +1868,7 @@ var Engine = /** @class */ (function () {
1796
1868
  });
1797
1869
  return [4 /*yield*/, fn.impl(inputs_1, params_1, this)];
1798
1870
  case 3:
1871
+ // call the implentation of sub functions
1799
1872
  result_1 = _e.sent();
1800
1873
  endTime_1 = performance.now();
1801
1874
  context.activations[name_1] = false;
@@ -1820,8 +1893,7 @@ var Engine = /** @class */ (function () {
1820
1893
  case 5:
1821
1894
  result = interpolate(node.outputs || {}, context.scope);
1822
1895
  endTime = performance.now();
1823
- // fire event
1824
- this.fireEvent("result", {
1896
+ response = {
1825
1897
  name: node.name,
1826
1898
  inputs: inputs,
1827
1899
  params: params,
@@ -1831,15 +1903,18 @@ var Engine = /** @class */ (function () {
1831
1903
  startTime: startTime,
1832
1904
  endTime: endTime,
1833
1905
  duration: endTime - startTime,
1834
- });
1906
+ };
1907
+ // fire event
1908
+ this.fireEvent("result", response);
1835
1909
  // console.log("Engine run done", result, context, endTime - startTime);
1836
- return [2 /*return*/, result];
1910
+ return [2 /*return*/, response];
1837
1911
  }
1838
1912
  });
1839
1913
  });
1840
1914
  };
1841
1915
  /**
1842
1916
  * creates an function that can be evaluated by calling its implementation
1917
+ * and registers it in the function index
1843
1918
  * @param node
1844
1919
  * @returns
1845
1920
  */
@@ -1850,6 +1925,7 @@ var Engine = /** @class */ (function () {
1850
1925
  return node;
1851
1926
  }
1852
1927
  var _a = node.body, body = _a === void 0 ? {} : _a, props = __rest(node, ["body"]);
1928
+ // create a primitive function, one that has an implementation and optional mounting function
1853
1929
  var primitive = __assign(__assign({}, props), { outputs: Object.fromEntries(Object.entries(node.outputs || {}).map(function (_a) {
1854
1930
  var _b = __read(_a, 2), key = _b[0]; _b[1];
1855
1931
  return [key, { type: "any" }];
@@ -1886,17 +1962,18 @@ var Engine = /** @class */ (function () {
1886
1962
  finally { if (e_1) throw e_1.error; }
1887
1963
  }
1888
1964
  };
1889
- }, impl: function (inputs, params) { return __awaiter(_this, void 0, void 0, function () {
1965
+ }, impl: function (inputs, params, engine) { return __awaiter(_this, void 0, void 0, function () {
1966
+ var response;
1890
1967
  return __generator(this, function (_a) {
1891
- // console.log(
1892
- // `Running function: ${node.name}`,
1893
- // node,
1894
- // inputs,
1895
- // params
1896
- // );
1897
- return [2 /*return*/, this.runGraph(node, inputs, params)];
1968
+ switch (_a.label) {
1969
+ case 0: return [4 /*yield*/, engine.runGraph(node, inputs, params)];
1970
+ case 1:
1971
+ response = _a.sent();
1972
+ return [2 /*return*/, response.result];
1973
+ }
1898
1974
  });
1899
1975
  }); } });
1976
+ // register the primitive
1900
1977
  this.fnIndex[primitive.name] = primitive;
1901
1978
  return primitive;
1902
1979
  };
@@ -1964,6 +2041,22 @@ var Engine = /** @class */ (function () {
1964
2041
  });
1965
2042
  });
1966
2043
  };
2044
+ Engine.prototype.runDetailed = function (node, inputs) {
2045
+ return __awaiter(this, void 0, void 0, function () {
2046
+ var _this = this;
2047
+ return __generator(this, function (_a) {
2048
+ return [2 /*return*/, new Promise(function (resolve) {
2049
+ var unsub = _this.subscribe("result", function (event) {
2050
+ if (event.name === node.name) {
2051
+ resolve(event);
2052
+ unsub();
2053
+ }
2054
+ });
2055
+ _this.run(node, inputs);
2056
+ })];
2057
+ });
2058
+ });
2059
+ };
1967
2060
  Engine.prototype.getFunction = function (name) {
1968
2061
  return this.fnIndex[name];
1969
2062
  };