nestjs-business-engine 1.0.0

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.
@@ -0,0 +1,47 @@
1
+ import type { RuleIssue } from './validation';
2
+ /** The step of a rule in which a failure happened. */
3
+ export type RuleStage = 'transform' | 'when' | 'produce';
4
+ /**
5
+ * Base class of every error thrown by the business engine, so all of them can
6
+ * be caught with a single `instanceof BusinessEngineError` check.
7
+ */
8
+ export declare class BusinessEngineError extends Error {
9
+ constructor(message: string, options?: {
10
+ cause?: unknown;
11
+ });
12
+ }
13
+ /** Thrown when a rule fails while it is being evaluated. */
14
+ export declare class RuleEvaluationError extends BusinessEngineError {
15
+ /** Id of the rule that failed. */
16
+ readonly ruleId: string;
17
+ /** Step of the rule that failed. */
18
+ readonly stage: RuleStage;
19
+ /** Transform key being computed, when `stage` is `transform`. */
20
+ readonly key?: string;
21
+ /** JSONata error code (for example `S0207` or `T1006`), when available. */
22
+ readonly code?: string;
23
+ /** Position of the error in the formula, when available. */
24
+ readonly position?: number;
25
+ constructor(ruleId: string, stage: RuleStage, cause: unknown, key?: string);
26
+ }
27
+ /** Thrown before evaluation when a rule is malformed or unsafe. */
28
+ export declare class InvalidRuleError extends BusinessEngineError {
29
+ /** Every problem found. */
30
+ readonly issues: readonly RuleIssue[];
31
+ /** Id of the first invalid rule, when it has one. */
32
+ readonly ruleId?: string;
33
+ constructor(issues: readonly RuleIssue[]);
34
+ }
35
+ /**
36
+ * Thrown (as the `cause` of a RuleEvaluationError) when a formula runs longer
37
+ * than the configured timeout.
38
+ */
39
+ export declare class FormulaTimeoutError extends BusinessEngineError {
40
+ /** The timeout that was exceeded, in milliseconds. */
41
+ readonly timeout: number;
42
+ /** Always `TIMEOUT`. */
43
+ readonly code = "TIMEOUT";
44
+ constructor(
45
+ /** The timeout that was exceeded, in milliseconds. */
46
+ timeout: number);
47
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FormulaTimeoutError = exports.InvalidRuleError = exports.RuleEvaluationError = exports.BusinessEngineError = void 0;
4
+ /**
5
+ * Base class of every error thrown by the business engine, so all of them can
6
+ * be caught with a single `instanceof BusinessEngineError` check.
7
+ */
8
+ class BusinessEngineError extends Error {
9
+ constructor(message, options) {
10
+ super(message, options);
11
+ this.name = new.target.name;
12
+ }
13
+ }
14
+ exports.BusinessEngineError = BusinessEngineError;
15
+ /** Thrown when a rule fails while it is being evaluated. */
16
+ class RuleEvaluationError extends BusinessEngineError {
17
+ /** Id of the rule that failed. */
18
+ ruleId;
19
+ /** Step of the rule that failed. */
20
+ stage;
21
+ /** Transform key being computed, when `stage` is `transform`. */
22
+ key;
23
+ /** JSONata error code (for example `S0207` or `T1006`), when available. */
24
+ code;
25
+ /** Position of the error in the formula, when available. */
26
+ position;
27
+ constructor(ruleId, stage, cause, key) {
28
+ const details = describeCause(cause);
29
+ const target = key === undefined ? stage : `${stage} "${key}"`;
30
+ super(`Rule "${ruleId}" failed at ${target}: ${details.message}`, {
31
+ cause,
32
+ });
33
+ this.ruleId = ruleId;
34
+ this.stage = stage;
35
+ this.key = key;
36
+ this.code = details.code;
37
+ this.position = details.position;
38
+ }
39
+ }
40
+ exports.RuleEvaluationError = RuleEvaluationError;
41
+ /**
42
+ * JSONata throws plain objects (`{ code, position, token, message }`) instead
43
+ * of Error instances; extract what is useful from either form.
44
+ */
45
+ function describeCause(cause) {
46
+ if (cause !== null && typeof cause === 'object') {
47
+ const { message, code, position } = cause;
48
+ const text = typeof message === 'string' ? message : String(cause);
49
+ const codeText = typeof code === 'string' ? code : undefined;
50
+ const pos = typeof position === 'number' ? position : undefined;
51
+ const suffix = codeText
52
+ ? pos === undefined
53
+ ? ` (${codeText})`
54
+ : ` (${codeText} at position ${pos})`
55
+ : '';
56
+ return { message: text + suffix, code: codeText, position: pos };
57
+ }
58
+ return { message: String(cause) };
59
+ }
60
+ /** Thrown before evaluation when a rule is malformed or unsafe. */
61
+ class InvalidRuleError extends BusinessEngineError {
62
+ /** Every problem found. */
63
+ issues;
64
+ /** Id of the first invalid rule, when it has one. */
65
+ ruleId;
66
+ constructor(issues) {
67
+ const [first] = issues;
68
+ const more = issues.length > 1 ? ` (and ${issues.length - 1} more issues)` : '';
69
+ super(`${first?.message ?? 'Invalid rules'}${more}`);
70
+ this.issues = issues;
71
+ this.ruleId = first?.ruleId;
72
+ }
73
+ }
74
+ exports.InvalidRuleError = InvalidRuleError;
75
+ /**
76
+ * Thrown (as the `cause` of a RuleEvaluationError) when a formula runs longer
77
+ * than the configured timeout.
78
+ */
79
+ class FormulaTimeoutError extends BusinessEngineError {
80
+ timeout;
81
+ /** Always `TIMEOUT`. */
82
+ code = 'TIMEOUT';
83
+ constructor(
84
+ /** The timeout that was exceeded, in milliseconds. */
85
+ timeout) {
86
+ super(`Formula evaluation exceeded the ${timeout} ms timeout`);
87
+ this.timeout = timeout;
88
+ }
89
+ }
90
+ exports.FormulaTimeoutError = FormulaTimeoutError;
@@ -0,0 +1,8 @@
1
+ export * from './business-engine.module';
2
+ export * from './business-engine.service';
3
+ export * from './types';
4
+ export * from './errors';
5
+ export * from './business-engine.options';
6
+ export { rulesSchema, validateRules } from './validation';
7
+ export type { RuleIssue } from './validation';
8
+ export type { StandardSchemaV1 } from './standard-schema';
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.validateRules = exports.rulesSchema = void 0;
18
+ __exportStar(require("./business-engine.module"), exports);
19
+ __exportStar(require("./business-engine.service"), exports);
20
+ __exportStar(require("./types"), exports);
21
+ __exportStar(require("./errors"), exports);
22
+ __exportStar(require("./business-engine.options"), exports);
23
+ var validation_1 = require("./validation");
24
+ Object.defineProperty(exports, "rulesSchema", { enumerable: true, get: function () { return validation_1.rulesSchema; } });
25
+ Object.defineProperty(exports, "validateRules", { enumerable: true, get: function () { return validation_1.validateRules; } });
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Standard Schema v1 interface (https://standardschema.dev), copied here so
3
+ * the package does not depend on any schema library. Lets `rulesSchema` be
4
+ * used anywhere a Standard Schema is accepted.
5
+ */
6
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
7
+ readonly '~standard': StandardSchemaV1.Props<Input, Output>;
8
+ }
9
+ export declare namespace StandardSchemaV1 {
10
+ interface Props<Input = unknown, Output = Input> {
11
+ readonly version: 1;
12
+ readonly vendor: string;
13
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
14
+ readonly types?: Types<Input, Output> | undefined;
15
+ }
16
+ type Result<Output> = SuccessResult<Output> | FailureResult;
17
+ interface SuccessResult<Output> {
18
+ readonly value: Output;
19
+ readonly issues?: undefined;
20
+ }
21
+ interface FailureResult {
22
+ readonly issues: ReadonlyArray<Issue>;
23
+ }
24
+ interface Issue {
25
+ readonly message: string;
26
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
27
+ }
28
+ interface PathSegment {
29
+ readonly key: PropertyKey;
30
+ }
31
+ interface Types<Input = unknown, Output = Input> {
32
+ readonly input: Input;
33
+ readonly output: Output;
34
+ }
35
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,72 @@
1
+ import type { RuleEvaluationError } from './errors';
2
+ /** A derived value computed by a JSONata formula before the condition runs. */
3
+ export type RuleTransform = {
4
+ /** Payload key that receives the value. Later transforms can read it. */
5
+ key: string;
6
+ /** JSONata expression evaluated against the payload. */
7
+ formula: string;
8
+ };
9
+ /** How a rule computes its result. */
10
+ export type RuleProduce = {
11
+ /** Result when the condition does not match or the formula yields nothing. */
12
+ default?: unknown;
13
+ /** JSONata expression evaluated against the transformed payload. */
14
+ formula: string;
15
+ };
16
+ /** A business rule: transform the payload, test a condition, produce a result. */
17
+ export type Rule = {
18
+ /** Unique id. Results are keyed by it. */
19
+ id: string;
20
+ /** Set to `false` to skip the rule (it produces no result). Defaults to `true`. */
21
+ enabled?: boolean;
22
+ /** Optional group, used to run a subset of rules with `RunOptions.group`. */
23
+ group?: string;
24
+ /** Derived values computed in order before the condition. Defaults to none. */
25
+ transform?: Array<RuleTransform>;
26
+ /** MongoDB-style condition (sift). Defaults to `{}`, which always matches. */
27
+ when?: Record<string, unknown>;
28
+ produce: RuleProduce;
29
+ };
30
+ /** Options for a single `run()` call. */
31
+ export type RunOptions = {
32
+ /** Return a step-by-step trace in `RunResult.debug`. Defaults to `false`. */
33
+ debug?: boolean;
34
+ /** Only run rules whose `group` is this value (or one of these values). */
35
+ group?: string | readonly string[];
36
+ /**
37
+ * Variables and functions available to every formula as `$name`, for
38
+ * example `{ vat: 0.2, round: (n: number) => Math.round(n) }`.
39
+ */
40
+ bindings?: Record<string, unknown>;
41
+ /**
42
+ * When `true`, a rule that fails keeps its default and the error is
43
+ * reported in `RunResult.errors` instead of rejecting the whole run.
44
+ * Invalid rules (`InvalidRuleError`) are always rejected. Defaults to `false`.
45
+ */
46
+ continueOnError?: boolean;
47
+ /**
48
+ * Maximum duration of each formula evaluation, in milliseconds. A formula
49
+ * that runs longer fails with a RuleEvaluationError whose code is
50
+ * `TIMEOUT`. Protects against runaway formulas such as infinite
51
+ * recursion. Defaults to no limit.
52
+ */
53
+ timeout?: number;
54
+ };
55
+ /** What `run()` resolves to. */
56
+ export type RunResult<TResults extends Record<string, unknown> = Record<string, unknown>> = {
57
+ /** Unique id of this execution (UUID v4). */
58
+ executionId: string;
59
+ /** Result of every rule that ran, keyed by rule id. */
60
+ results: TResults;
61
+ /** Ids of the rules whose condition matched, in execution order. */
62
+ matched: string[];
63
+ /** Failures of individual rules. Only filled when `continueOnError` is `true`. */
64
+ errors: RuleEvaluationError[];
65
+ /** Step-by-step trace, only when `RunOptions.debug` is `true`. */
66
+ debug?: DebugStep[];
67
+ };
68
+ /** One entry of the debug trace returned by `run()` when debug is enabled. */
69
+ export type DebugStep = {
70
+ message: string;
71
+ context: Record<string, unknown>;
72
+ };
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,39 @@
1
+ import jsonata from 'jsonata';
2
+ /** Default number of compiled formulas kept in memory. */
3
+ export declare const DEFAULT_FORMULA_CACHE_SIZE = 500;
4
+ /**
5
+ * Returns why a parsed formula is unsafe to run, or `undefined` if it is fine.
6
+ *
7
+ * JSONata's transform operator (`obj ~> | pattern | update |`) copies its input
8
+ * with whatever `$clone` resolves to in the current scope. A formula that
9
+ * rebinds `$clone` (to `function($o){ $o }`, say) makes the operator write into
10
+ * the original objects: the caller's payload, bindings and module defaults.
11
+ * `$eval` is rejected too, because the formula it evaluates is only known at
12
+ * run time and could rebind `$clone` without this check seeing it.
13
+ */
14
+ export declare function findUnsafeFormulaUsage(ast: unknown): string | undefined;
15
+ /** Parses a formula and rejects unsafe usage. Throws on invalid formulas. */
16
+ export declare function parseFormula(formula: string): jsonata.Expression;
17
+ /** Options for a single formula evaluation. */
18
+ export interface EvaluateOptions {
19
+ bindings?: Record<string, unknown>;
20
+ /** Maximum duration in milliseconds. No limit when undefined or 0. */
21
+ timeout?: number;
22
+ }
23
+ /**
24
+ * Compiles JSONata formulas and keeps the most recently used ones, so rules
25
+ * evaluated on every request are parsed once. `maxSize: 0` disables caching.
26
+ */
27
+ export declare class FormulaCache {
28
+ private readonly maxSize;
29
+ private readonly entries;
30
+ constructor(maxSize?: number);
31
+ get size(): number;
32
+ /**
33
+ * Returns the compiled formula. Throws JSONata's error if it is invalid,
34
+ * or an `UNSAFE_FORMULA` error if it uses unsafe features.
35
+ */
36
+ compile(formula: string): jsonata.Expression;
37
+ /** Compiles (or reuses) and evaluates a formula. */
38
+ evaluate(formula: string, input: unknown, options?: EvaluateOptions): Promise<unknown>;
39
+ }
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FormulaCache = exports.DEFAULT_FORMULA_CACHE_SIZE = void 0;
7
+ exports.findUnsafeFormulaUsage = findUnsafeFormulaUsage;
8
+ exports.parseFormula = parseFormula;
9
+ const node_async_hooks_1 = require("node:async_hooks");
10
+ const jsonata_1 = __importDefault(require("jsonata"));
11
+ const errors_1 = require("../errors");
12
+ /** Default number of compiled formulas kept in memory. */
13
+ exports.DEFAULT_FORMULA_CACHE_SIZE = 500;
14
+ /**
15
+ * JSONata calls the function bound to this symbol before evaluating every
16
+ * node of the expression tree. It is how the JSONata exerciser time-boxes
17
+ * expressions, and it is the only way to stop a runaway formula (JSONata
18
+ * optimizes tail calls, so infinite recursion never overflows the stack).
19
+ */
20
+ const EVALUATE_ENTRY = Symbol.for('jsonata.__evaluate_entry');
21
+ /**
22
+ * Deadline of the evaluation in progress. It is kept outside JSONata so a
23
+ * formula cannot reach it: bindings are JSONata variables, and a formula can
24
+ * shadow any variable with `:=`, which would disable the timeout.
25
+ */
26
+ const deadlines = new node_async_hooks_1.AsyncLocalStorage();
27
+ function checkDeadline() {
28
+ const deadline = deadlines.getStore();
29
+ if (deadline && Date.now() > deadline.at) {
30
+ throw new errors_1.FormulaTimeoutError(deadline.timeout);
31
+ }
32
+ }
33
+ /**
34
+ * Returns why a parsed formula is unsafe to run, or `undefined` if it is fine.
35
+ *
36
+ * JSONata's transform operator (`obj ~> | pattern | update |`) copies its input
37
+ * with whatever `$clone` resolves to in the current scope. A formula that
38
+ * rebinds `$clone` (to `function($o){ $o }`, say) makes the operator write into
39
+ * the original objects: the caller's payload, bindings and module defaults.
40
+ * `$eval` is rejected too, because the formula it evaluates is only known at
41
+ * run time and could rebind `$clone` without this check seeing it.
42
+ */
43
+ function findUnsafeFormulaUsage(ast) {
44
+ const seen = new Set();
45
+ const visit = (node) => {
46
+ if (node === null || typeof node !== 'object' || seen.has(node)) {
47
+ return undefined;
48
+ }
49
+ seen.add(node);
50
+ const n = node;
51
+ if (n.type === 'variable' && n.value === 'eval') {
52
+ return '$eval is not supported';
53
+ }
54
+ const lhs = n.lhs;
55
+ const rebindsClone = (n.type === 'bind' &&
56
+ lhs?.type === 'variable' &&
57
+ lhs.value === 'clone') ||
58
+ (n.type === 'lambda' &&
59
+ Array.isArray(n.arguments) &&
60
+ n.arguments.some(argument => argument?.value === 'clone')) ||
61
+ n.focus === 'clone' ||
62
+ n.index === 'clone';
63
+ if (rebindsClone) {
64
+ return '$clone cannot be redefined';
65
+ }
66
+ for (const value of Object.values(n)) {
67
+ const reason = visit(value);
68
+ if (reason !== undefined) {
69
+ return reason;
70
+ }
71
+ }
72
+ return undefined;
73
+ };
74
+ return visit(ast);
75
+ }
76
+ /** Parses a formula and rejects unsafe usage. Throws on invalid formulas. */
77
+ function parseFormula(formula) {
78
+ const expression = (0, jsonata_1.default)(formula);
79
+ const reason = findUnsafeFormulaUsage(expression.ast());
80
+ if (reason !== undefined) {
81
+ throw Object.assign(new Error(reason), { code: 'UNSAFE_FORMULA' });
82
+ }
83
+ return expression;
84
+ }
85
+ /**
86
+ * Compiles JSONata formulas and keeps the most recently used ones, so rules
87
+ * evaluated on every request are parsed once. `maxSize: 0` disables caching.
88
+ */
89
+ class FormulaCache {
90
+ maxSize;
91
+ entries = new Map();
92
+ constructor(maxSize = exports.DEFAULT_FORMULA_CACHE_SIZE) {
93
+ this.maxSize = maxSize;
94
+ }
95
+ get size() {
96
+ return this.entries.size;
97
+ }
98
+ /**
99
+ * Returns the compiled formula. Throws JSONata's error if it is invalid,
100
+ * or an `UNSAFE_FORMULA` error if it uses unsafe features.
101
+ */
102
+ compile(formula) {
103
+ const cached = this.entries.get(formula);
104
+ if (cached) {
105
+ // Refresh the entry so the least recently used one is evicted first.
106
+ this.entries.delete(formula);
107
+ this.entries.set(formula, cached);
108
+ return cached;
109
+ }
110
+ const expression = parseFormula(formula);
111
+ // assign() is typed for string names, but JSONata looks this hook up by symbol.
112
+ expression.assign(EVALUATE_ENTRY, checkDeadline);
113
+ if (this.maxSize > 0) {
114
+ if (this.entries.size >= this.maxSize) {
115
+ const oldest = this.entries.keys().next().value;
116
+ this.entries.delete(oldest);
117
+ }
118
+ this.entries.set(formula, expression);
119
+ }
120
+ return expression;
121
+ }
122
+ /** Compiles (or reuses) and evaluates a formula. */
123
+ evaluate(formula, input, options = {}) {
124
+ const expression = this.compile(formula);
125
+ const { bindings, timeout } = options;
126
+ const deadline = timeout
127
+ ? { at: Date.now() + timeout, timeout }
128
+ : undefined;
129
+ // Always set the store, so a nested evaluation without a timeout (for
130
+ // example from a binding function) does not inherit the outer deadline.
131
+ return deadlines.run(deadline, () => expression.evaluate(input, bindings));
132
+ }
133
+ }
134
+ exports.FormulaCache = FormulaCache;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * JSONata marks the arrays it builds with enumerable flags such as
3
+ * `sequence: true`, which leak into `Object.keys`, spreads and strict
4
+ * equality checks. Returns the value with those arrays replaced by plain
5
+ * arrays. Values that need no change keep their identity, and cycles are
6
+ * handled.
7
+ */
8
+ export declare function toPlainValue<T>(value: T): T;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toPlainValue = toPlainValue;
4
+ /**
5
+ * JSONata marks the arrays it builds with enumerable flags such as
6
+ * `sequence: true`, which leak into `Object.keys`, spreads and strict
7
+ * equality checks. Returns the value with those arrays replaced by plain
8
+ * arrays. Values that need no change keep their identity, and cycles are
9
+ * handled.
10
+ */
11
+ function toPlainValue(value) {
12
+ return normalize(value, new Map());
13
+ }
14
+ function normalize(value, seen) {
15
+ if (value === null || typeof value !== 'object') {
16
+ return value;
17
+ }
18
+ if (seen.has(value)) {
19
+ return seen.get(value);
20
+ }
21
+ if (Array.isArray(value)) {
22
+ // Provisional entry so cycles resolve to the original array.
23
+ seen.set(value, value);
24
+ const items = value.map(item => normalize(item, seen));
25
+ const changed = Object.keys(value).length !== value.length ||
26
+ items.some((item, index) => item !== value[index]);
27
+ const result = changed ? items : value;
28
+ seen.set(value, result);
29
+ return result;
30
+ }
31
+ const prototype = Object.getPrototypeOf(value);
32
+ if (prototype !== Object.prototype && prototype !== null) {
33
+ // Dates, class instances, buffers...: leave untouched.
34
+ return value;
35
+ }
36
+ seen.set(value, value);
37
+ const source = value;
38
+ let copy;
39
+ for (const key of Object.keys(source)) {
40
+ const item = normalize(source[key], seen);
41
+ if (item !== source[key]) {
42
+ copy ??= { ...source };
43
+ copy[key] = item;
44
+ }
45
+ }
46
+ const result = copy ?? value;
47
+ seen.set(value, result);
48
+ return result;
49
+ }
@@ -0,0 +1,30 @@
1
+ import type { StandardSchemaV1 } from './standard-schema';
2
+ import type { Rule } from './types';
3
+ /** A problem found in a rule set. */
4
+ export interface RuleIssue {
5
+ /** Human-readable description. */
6
+ readonly message: string;
7
+ /** Location in the rule set, for example `[0, 'transform', 1, 'formula']`. */
8
+ readonly path: ReadonlyArray<string | number>;
9
+ /** Id of the rule, when it has a valid one. */
10
+ readonly ruleId?: string;
11
+ }
12
+ interface CheckOptions {
13
+ /** Also compile formulas, reject unsafe formula usage and look for `$where` in conditions. */
14
+ deep: boolean;
15
+ }
16
+ /** @internal Structural and safety checks shared by run() and validateRules(). */
17
+ export declare function checkRules(rules: unknown, options: CheckOptions): RuleIssue[];
18
+ /**
19
+ * Checks a rule set without running it: structure, ids, forbidden keys,
20
+ * formula syntax and unsupported operators. Use it when rules are created or
21
+ * edited (for example before saving them). Returns an empty array when the
22
+ * rules are valid.
23
+ */
24
+ export declare function validateRules(rules: unknown): RuleIssue[];
25
+ /**
26
+ * Standard Schema for a rule set, backed by `validateRules()`. Works with any
27
+ * library that accepts a Standard Schema.
28
+ */
29
+ export declare const rulesSchema: StandardSchemaV1<unknown, Rule[]>;
30
+ export {};