phecda-vue 1.1.1 → 1.1.2

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.d.ts CHANGED
@@ -60,6 +60,7 @@ declare function createFilter<Data extends Record<string, any>>(initState?: Obje
60
60
  expressionRE?: RegExp;
61
61
  fnRE?: RegExp;
62
62
  exclude?: string[];
63
+ errorHandler?: (error?: Error, errorPath?: string) => any;
63
64
  }): {
64
65
  filter: <Schema>(obj: Schema) => SchemaToObj<Schema>;
65
66
  data: [Data] extends [vue.Ref<any>] ? Data : vue.Ref<vue.UnwrapRef<Data>>;
package/dist/index.js CHANGED
@@ -324,19 +324,21 @@ function createFilter(initState = {}, option = {}) {
324
324
  const scope = (0, import_vue4.effectScope)(true);
325
325
  let data = scope.run(() => (0, import_vue4.ref)(initState));
326
326
  let store = {};
327
- function traverse(obj) {
327
+ function traverse(obj, path) {
328
328
  for (const i in obj) {
329
329
  if (Array.isArray(obj[i]) || resolveOption.exclude.includes(i))
330
330
  continue;
331
+ const errorPath = path ? `${path}.${i}` : i;
331
332
  if (typeof obj[i] === "object" && obj[i])
332
- traverse(obj[i]);
333
+ traverse(obj[i], errorPath);
333
334
  if (typeof obj[i] === "string") {
334
335
  if (resolveOption.expressionRE.test(obj[i])) {
335
336
  const body = obj[i].match(resolveOption.expressionRE)[1];
336
337
  Object.defineProperty(obj, i, {
337
338
  get() {
338
- return new Function(...Object.keys(data.value), `return ${body}`)(
339
- ...Object.values(data.value)
339
+ return new Function(...Object.keys(data.value), "_eh", resolveOption.errorHandler ? `try{return ${body}}catch(e){return _eh(e,"${errorPath}")}` : `return ${body}`)(
340
+ ...Object.values(data.value),
341
+ resolveOption.errorHandler
340
342
  );
341
343
  }
342
344
  });
@@ -345,8 +347,9 @@ function createFilter(initState = {}, option = {}) {
345
347
  const body = obj[i].match(resolveOption.fnRE)[1];
346
348
  Object.defineProperty(obj, i, {
347
349
  get() {
348
- return new Function(...Object.keys(data.value), `${body}`)(
349
- ...Object.values(data.value)
350
+ return new Function(...Object.keys(data.value), "_eh", resolveOption.errorHandler ? `try{${body}}catch(e){return _eh(e,"${errorPath}")}` : `${body}`)(
351
+ ...Object.values(data.value),
352
+ resolveOption.errorHandler
350
353
  );
351
354
  }
352
355
  });
package/dist/index.mjs CHANGED
@@ -262,19 +262,21 @@ function createFilter(initState = {}, option = {}) {
262
262
  const scope = effectScope2(true);
263
263
  let data = scope.run(() => ref(initState));
264
264
  let store = {};
265
- function traverse(obj) {
265
+ function traverse(obj, path) {
266
266
  for (const i in obj) {
267
267
  if (Array.isArray(obj[i]) || resolveOption.exclude.includes(i))
268
268
  continue;
269
+ const errorPath = path ? `${path}.${i}` : i;
269
270
  if (typeof obj[i] === "object" && obj[i])
270
- traverse(obj[i]);
271
+ traverse(obj[i], errorPath);
271
272
  if (typeof obj[i] === "string") {
272
273
  if (resolveOption.expressionRE.test(obj[i])) {
273
274
  const body = obj[i].match(resolveOption.expressionRE)[1];
274
275
  Object.defineProperty(obj, i, {
275
276
  get() {
276
- return new Function(...Object.keys(data.value), `return ${body}`)(
277
- ...Object.values(data.value)
277
+ return new Function(...Object.keys(data.value), "_eh", resolveOption.errorHandler ? `try{return ${body}}catch(e){return _eh(e,"${errorPath}")}` : `return ${body}`)(
278
+ ...Object.values(data.value),
279
+ resolveOption.errorHandler
278
280
  );
279
281
  }
280
282
  });
@@ -283,8 +285,9 @@ function createFilter(initState = {}, option = {}) {
283
285
  const body = obj[i].match(resolveOption.fnRE)[1];
284
286
  Object.defineProperty(obj, i, {
285
287
  get() {
286
- return new Function(...Object.keys(data.value), `${body}`)(
287
- ...Object.values(data.value)
288
+ return new Function(...Object.keys(data.value), "_eh", resolveOption.errorHandler ? `try{${body}}catch(e){return _eh(e,"${errorPath}")}` : `${body}`)(
289
+ ...Object.values(data.value),
290
+ resolveOption.errorHandler
288
291
  );
289
292
  }
290
293
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-vue",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",