@stll/template-conditions 0.6.3 → 0.6.4
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 +2 -5
- package/dist/index.js +1 -27
- package/dist/path.d.ts +17 -0
- package/dist/path.js +27 -0
- package/package.json +7 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
+
import { resolvePath } from "./path.js";
|
|
1
2
|
import { CompareNode, CompareOp, Condition, ConditionNode, ConditionNode as ConditionNode$1, GroupNode, Operand, PredicateNode, PredicateOp, conditionHasFormula, conditionNodeSchema, conditionSchema, emptyCondition } from "@stll/conditions";
|
|
2
|
-
//#region src/path.d.ts
|
|
3
|
-
/** Resolve a dotted path like `company.name` against data. */
|
|
4
|
-
export declare const resolvePath: (path: string, data: Record<string, unknown>) => unknown;
|
|
5
|
-
//#endregion
|
|
6
3
|
//#region src/parse.d.ts
|
|
7
4
|
/** Maximum combined nesting of parentheses and unary negation. */
|
|
8
5
|
export declare const MAX_CONDITION_NESTING = 256;
|
|
@@ -624,4 +621,4 @@ export declare const MAX_CONDITION_DEPTH = 50;
|
|
|
624
621
|
*/
|
|
625
622
|
export declare const evaluateCondition: (expression: string, data: Record<string, unknown>, namedConditions?: readonly NamedCondition[], _resolved?: ReadonlySet<string>, _depth?: number) => boolean;
|
|
626
623
|
//#endregion
|
|
627
|
-
export { type BlockDirectiveKind, type CompareNode, type CompareOp, type Condition, type ConditionNode, type ConditionTagOptions, type DateFormatStyle, type DeterministicFieldConfig, type DirectiveKind, type FieldDateFormat, type FilterArgument, type FilterCall, type FilterName, type ForOpenerOptions, type GroupNode, type InvalidMarker, type LoopProperty, type MarkerDefect, type MarkerDefectKind, type MarkerFieldConfig, type MarkerFieldInputType, type MarkerFieldLookup, type MarkerFieldSource, type MarkerFieldValidation, type MarkerForm, type MarkerLiteral, type MarkerMeta, type MarkerPrefix, type NumericFunctionName, type Operand, type PredicateNode, type PredicateOp, type RowBlockMarker, type RowBlockPair, type RowScope, type ScannedMarker, type UnwritableReason, conditionHasFormula, conditionNodeSchema, conditionSchema, emptyCondition };
|
|
624
|
+
export { type BlockDirectiveKind, type CompareNode, type CompareOp, type Condition, type ConditionNode, type ConditionTagOptions, type DateFormatStyle, type DeterministicFieldConfig, type DirectiveKind, type FieldDateFormat, type FilterArgument, type FilterCall, type FilterName, type ForOpenerOptions, type GroupNode, type InvalidMarker, type LoopProperty, type MarkerDefect, type MarkerDefectKind, type MarkerFieldConfig, type MarkerFieldInputType, type MarkerFieldLookup, type MarkerFieldSource, type MarkerFieldValidation, type MarkerForm, type MarkerLiteral, type MarkerMeta, type MarkerPrefix, type NumericFunctionName, type Operand, type PredicateNode, type PredicateOp, type RowBlockMarker, type RowBlockPair, type RowScope, type ScannedMarker, type UnwritableReason, conditionHasFormula, conditionNodeSchema, conditionSchema, emptyCondition, resolvePath };
|
package/dist/index.js
CHANGED
|
@@ -1,33 +1,7 @@
|
|
|
1
|
+
import { resolvePath } from "./path.js";
|
|
1
2
|
import { conditionHasFormula, conditionNodeSchema, conditionSchema, emptyCondition, evaluateCondition as evaluateCondition$1 } from "@stll/conditions";
|
|
2
3
|
import { Result, panic } from "better-result";
|
|
3
4
|
import { Temporal } from "temporal-polyfill/full";
|
|
4
|
-
//#region src/path.ts
|
|
5
|
-
/**
|
|
6
|
-
* Dotted-path resolution against a data record. Extracted from index.ts so both
|
|
7
|
-
* the condition engine (index.ts) and the arithmetic evaluator (compute.ts) can
|
|
8
|
-
* import it without a dependency cycle.
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Narrow `unknown` to something a path segment can be read from.
|
|
12
|
-
*
|
|
13
|
-
* Unlike the same-named predicates that screen JSON payload shapes, this one
|
|
14
|
-
* accepts arrays on purpose: a dotted path segment may be an array index
|
|
15
|
-
* (`parties.1.name`), and rejecting arrays would silently resolve those to
|
|
16
|
-
* `undefined`.
|
|
17
|
-
*/
|
|
18
|
-
const isNonNullObject = (v) => typeof v === "object" && v !== null;
|
|
19
|
-
/** Resolve a dotted path like `company.name` against data. */
|
|
20
|
-
const resolvePath = (path, data) => {
|
|
21
|
-
if (Object.hasOwn(data, path)) return data[path];
|
|
22
|
-
const parts = path.split(".");
|
|
23
|
-
let current = data;
|
|
24
|
-
for (const part of parts) {
|
|
25
|
-
if (!isNonNullObject(current)) return;
|
|
26
|
-
current = current[part];
|
|
27
|
-
}
|
|
28
|
-
return current;
|
|
29
|
-
};
|
|
30
|
-
//#endregion
|
|
31
5
|
//#region src/compute.ts
|
|
32
6
|
/**
|
|
33
7
|
* Arithmetic evaluator for computed template fields.
|
package/dist/path.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/path.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Dotted-path resolution against a data record. Extracted from index.ts so both
|
|
4
|
+
* the condition engine (index.ts) and the arithmetic evaluator (compute.ts) can
|
|
5
|
+
* import it without a dependency cycle.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Narrow `unknown` to something a path segment can be read from.
|
|
9
|
+
*
|
|
10
|
+
* Accepts arrays and class instances. A dotted path segment may be an array index
|
|
11
|
+
* (`parties.1.name`), and rejecting arrays would silently resolve those to
|
|
12
|
+
* `undefined`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const isNonNullObject: (v: unknown) => v is Record<string, unknown>;
|
|
15
|
+
/** Resolve a dotted path like `company.name` against data. */
|
|
16
|
+
export declare const resolvePath: (path: string, data: Record<string, unknown>) => unknown;
|
|
17
|
+
//#endregion
|
package/dist/path.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/path.ts
|
|
2
|
+
/**
|
|
3
|
+
* Dotted-path resolution against a data record. Extracted from index.ts so both
|
|
4
|
+
* the condition engine (index.ts) and the arithmetic evaluator (compute.ts) can
|
|
5
|
+
* import it without a dependency cycle.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Narrow `unknown` to something a path segment can be read from.
|
|
9
|
+
*
|
|
10
|
+
* Accepts arrays and class instances. A dotted path segment may be an array index
|
|
11
|
+
* (`parties.1.name`), and rejecting arrays would silently resolve those to
|
|
12
|
+
* `undefined`.
|
|
13
|
+
*/
|
|
14
|
+
const isNonNullObject = (v) => typeof v === "object" && v !== null;
|
|
15
|
+
/** Resolve a dotted path like `company.name` against data. */
|
|
16
|
+
const resolvePath = (path, data) => {
|
|
17
|
+
if (Object.hasOwn(data, path)) return data[path];
|
|
18
|
+
const parts = path.split(".");
|
|
19
|
+
let current = data;
|
|
20
|
+
for (const part of parts) {
|
|
21
|
+
if (!isNonNullObject(current)) return;
|
|
22
|
+
current = current[part];
|
|
23
|
+
}
|
|
24
|
+
return current;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { isNonNullObject, resolvePath };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stll/template-conditions",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "A document-template marker and condition engine: {{...}} marker grammar, parse, compute, serialize, field values.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"condition",
|
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
".": {
|
|
32
32
|
"types": "./dist/index.d.ts",
|
|
33
33
|
"import": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./path": {
|
|
36
|
+
"types": "./dist/path.d.ts",
|
|
37
|
+
"import": "./dist/path.js"
|
|
34
38
|
}
|
|
35
39
|
},
|
|
36
40
|
"publishConfig": {
|
|
@@ -41,7 +45,7 @@
|
|
|
41
45
|
"build": "tsdown",
|
|
42
46
|
"pack:dry-run": "bun pm pack --dry-run",
|
|
43
47
|
"test": "bun test",
|
|
44
|
-
"test:property": "bun test --preload @stll/property-testing/preload $(grep -
|
|
48
|
+
"test:property": "bun test --preload @stll/property-testing/preload $(grep -rlE 'fc\\.assert|assertProperty' src --include='*.test.ts')",
|
|
45
49
|
"typecheck": "bun ../../packages/scripts/src/tsc-native.ts --noEmit",
|
|
46
50
|
"lint": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --report-unused-disable-directives-severity=error --type-aware --type-check packages/template-conditions",
|
|
47
51
|
"lint:fix": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --type-aware --fix packages/template-conditions",
|
|
@@ -57,7 +61,7 @@
|
|
|
57
61
|
"@stll/property-testing": "0.0.0",
|
|
58
62
|
"@stll/typescript-config": "0.0.0",
|
|
59
63
|
"bun-types": "1.4.2",
|
|
60
|
-
"fast-check": "^4.10.
|
|
64
|
+
"fast-check": "^4.10.2",
|
|
61
65
|
"tsdown": "0.23.0"
|
|
62
66
|
},
|
|
63
67
|
"main": "./dist/index.js",
|