@flusys/nestjs-shared 9.1.1 → 9.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/README.md +25 -0
- package/fesm/282.js +1580 -0
- package/fesm/index.js +50 -6
- package/fesm/interfaces/index.js +82 -2
- package/fesm/utils/index.js +16 -3
- package/interfaces/expression.interface.d.ts +45 -0
- package/interfaces/index.d.ts +1 -0
- package/package.json +3 -2
- package/utils/expression.util.d.ts +35 -0
- package/utils/index.d.ts +2 -0
- package/utils/safe-regex.util.d.ts +10 -0
- package/fesm/270.js +0 -659
package/README.md
CHANGED
|
@@ -807,6 +807,31 @@ async listForCurrentBranch(query: SelectQueryBuilder<Invoice>, user: ILoggedUser
|
|
|
807
807
|
}
|
|
808
808
|
```
|
|
809
809
|
|
|
810
|
+
## 10. Expressions
|
|
811
|
+
|
|
812
|
+
A JSON expression tree any package can store and evaluate (`@flusys/nestjs-shared/interfaces` for the types, `/utils` for the engine). Pure functions, no Nest dependencies; every slot that takes a value takes another expression.
|
|
813
|
+
|
|
814
|
+
| `type` | Shape | Result |
|
|
815
|
+
| --- | --- | --- |
|
|
816
|
+
| `literal` | `{ value }` | the value |
|
|
817
|
+
| `field_ref` | `{ ref }` | `ctx.resolveRef(ref)` |
|
|
818
|
+
| `arithmetic` | `{ op, operands[] }` | `sum`, `subtract`, `multiply`, `divide`, `modulo`, `power`, `average`, `min`, `max`; blank operands count as 0 |
|
|
819
|
+
| `concat` | `{ parts[], separator? }` | joined text; with a separator, blank parts are skipped |
|
|
820
|
+
| `template` | `{ template }` | `"{{ ref }}"` placeholders filled through `resolveRef` |
|
|
821
|
+
| `function` | `{ name, args[] }` | see `EXPRESSION_FUNCTIONS`: text (incl. `REGEX_EXTRACT` / `REGEX_REPLACE` / `REGEX_TEST`), number, date (UTC) and `COALESCE` |
|
|
822
|
+
| `if` | `{ condition, whenTrue, whenFalse? }` | `condition` is an AND / OR group of `{ left, comparison, right? }`, groups nest |
|
|
823
|
+
|
|
824
|
+
```typescript
|
|
825
|
+
import { evaluateExpression, assertValidExpression, isExpressionError } from '@flusys/nestjs-shared/utils';
|
|
826
|
+
|
|
827
|
+
assertValidExpression(expr, { isKnownRef: (ref) => fieldIds.has(ref) }); // on save
|
|
828
|
+
const value = evaluateExpression(expr, { resolveRef: (ref) => data[ref] });
|
|
829
|
+
```
|
|
830
|
+
|
|
831
|
+
- Errors are `ExpressionError { code, variables }` (plain, not HTTP) - map `code` to your own message key; check with `isExpressionError()`, not `instanceof`.
|
|
832
|
+
- Limits (`EXPRESSION_LIMITS`): depth 16, 500 nodes, 4000-char templates, 100k-char text results.
|
|
833
|
+
- Regex runs on RE2 via `safeRegexProblem()` / `compileSafeRegex()` (`SAFE_REGEX_LIMITS`): linear time, pattern length / counted-repeat caps. Never `new RegExp` on author input.
|
|
834
|
+
|
|
810
835
|
## License
|
|
811
836
|
|
|
812
837
|
MIT © FLUSYS
|