@fatehan/tsrp 1.3.45 → 1.3.47

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.
@@ -1,5 +1,6 @@
1
1
  import { ShownIo, SystemIo } from "./fatehan/devices/devices";
2
2
  import { Data } from "./fatehan/packets/dataModel";
3
3
  declare const SystemIoCast: (systemIo: SystemIo[], deviceIo: SystemIo[], data: Data) => ShownIo[];
4
+ export declare function evalExpressionSafe(template: string, context: any): number | boolean | string | null;
4
5
  export default SystemIoCast;
5
6
  //# sourceMappingURL=system.io.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"system.io.d.ts","sourceRoot":"","sources":["../src/system.io.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,QAAQ,EAET,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAEnD,QAAA,MAAM,YAAY,GAChB,UAAU,QAAQ,EAAE,EACpB,UAAU,QAAQ,EAAE,EACpB,MAAM,IAAI,KACT,OAAO,EA4FT,CAAC;AA8IF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"system.io.d.ts","sourceRoot":"","sources":["../src/system.io.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,QAAQ,EAET,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAEnD,QAAA,MAAM,YAAY,GAChB,UAAU,QAAQ,EAAE,EACpB,UAAU,QAAQ,EAAE,EACpB,MAAM,IAAI,KACT,OAAO,EA4FT,CAAC;AAkGF,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CA4BnG;AACD,eAAe,YAAY,CAAC"}
package/dist/system.io.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.evalExpressionSafe = evalExpressionSafe;
3
4
  const devices_1 = require("./fatehan/devices/devices");
4
5
  const SystemIoCast = (systemIo, deviceIo, data) => {
5
6
  let list = [];
@@ -139,16 +140,20 @@ function getValueByPathCaseInsensitive(obj, path) {
139
140
  for (const rawPart of parts) {
140
141
  if (cur == null)
141
142
  return undefined;
142
- if (/^\d+$/.test(rawPart)) {
143
- const idx = Number(rawPart);
143
+ const isIndex = /^\d+$/.test(rawPart);
144
+ if (isIndex) {
145
+ const idx = rawPart;
144
146
  if (Array.isArray(cur) || cur instanceof Uint8Array) {
145
- cur = cur[idx];
147
+ cur = cur[Number(idx)];
146
148
  continue;
147
149
  }
148
- else {
149
- return undefined;
150
+ if (typeof cur === "object" && cur !== null && idx in cur) {
151
+ cur = cur[idx];
152
+ continue;
150
153
  }
154
+ return undefined;
151
155
  }
156
+ // حالت 3: object معمولی (case-insensitive)
152
157
  if (isPlainObject(cur)) {
153
158
  const lower = rawPart.toLowerCase();
154
159
  const foundKey = Object.keys(cur).find(k => k.toLowerCase() === lower);
@@ -168,7 +173,7 @@ function evalExpressionSafe(template, context) {
168
173
  try {
169
174
  if (typeof template !== 'string')
170
175
  return null;
171
- const replaced = template.replace(/\$([A-Za-z0-9_.\[\]]+)/gi, (_m, expr) => {
176
+ const replaced = template.replace(/\$([A-Za-z0-9_.\[\]]+)/gi, (_, expr) => {
172
177
  const value = getValueByPathCaseInsensitive(context, expr);
173
178
  if (value === undefined || value === null)
174
179
  return "null";
@@ -180,38 +185,20 @@ function evalExpressionSafe(template, context) {
180
185
  return JSON.stringify(value);
181
186
  if (value instanceof Uint8Array)
182
187
  return `[${Array.from(value).join(',')}]`;
183
- if (Array.isArray(value)) {
184
- return `[${value.map(v => (typeof v === 'string' ? JSON.stringify(v) : String(v))).join(',')}]`;
185
- }
188
+ if (Array.isArray(value))
189
+ return `[${value.map(v => (typeof v === "string" ? JSON.stringify(v) : v)).join(',')}]`;
186
190
  return "null";
187
191
  });
188
- if (replaced.includes("null")) {
189
- return null;
190
- }
191
- const cleaned = replaced
192
- .replace(/;/g, ' ')
193
- .replace(/`/g, ' ')
194
- .replace(/\\/g, ' ')
195
- .trim();
196
- const allowedPattern = /^[0-9+\-*/ %().,<>=!&|"\[\]truefalsenull,':\s]*$/i;
197
- if (!allowedPattern.test(cleaned))
198
- return null;
199
- const forbidden = [/constructor\b/i, /process\b/i, /require\b/i, /global\b/i, /__proto__\b/i];
200
- if (forbidden.some(rx => rx.test(cleaned)))
192
+ const cleaned = replaced.replace(/;/g, ' ').replace(/`/g, ' ').replace(/\\/g, ' ').trim();
193
+ if (!/^[0-9+\-*/ ().><=!&|,"'\[\]truefalsenull]*$/i.test(cleaned))
201
194
  return null;
202
- if (cleaned.length === 0)
203
- return null;
204
- let result;
205
- try {
206
- const fn = new Function(`return (${cleaned});`);
207
- result = fn();
208
- }
209
- catch {
210
- return null;
211
- }
212
- if (result === undefined || result === null)
213
- return null;
214
- if (typeof result === "number" || typeof result === "boolean" || typeof result === "string")
195
+ const fn = new Function(`return (${cleaned});`);
196
+ const result = fn();
197
+ if (typeof result === "number" && !isNaN(result))
198
+ return result;
199
+ if (typeof result === "boolean")
200
+ return result;
201
+ if (typeof result === "string")
215
202
  return result;
216
203
  return null;
217
204
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fatehan/tsrp",
3
- "version": "1.3.45",
3
+ "version": "1.3.47",
4
4
  "description": "fatehan main models",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",