trilean 1.7.12 → 1.9.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.
- package/README.md +36 -14
- package/dist/builtin-functions.cjs +146 -0
- package/dist/builtin-functions.d.cts +13 -0
- package/dist/builtin-functions.d.ts +13 -0
- package/dist/builtin-functions.js +145 -0
- package/dist/complex-division.cjs +48 -0
- package/dist/complex-division.d.cts +25 -0
- package/dist/complex-division.d.ts +25 -0
- package/dist/complex-division.js +47 -0
- package/dist/complex.cjs +4 -2
- package/dist/complex.d.cts +4 -2
- package/dist/complex.d.ts +4 -2
- package/dist/complex.js +4 -2
- package/dist/duration-order.cjs +84 -0
- package/dist/duration-order.d.cts +22 -0
- package/dist/duration-order.d.ts +22 -0
- package/dist/duration-order.js +82 -0
- package/dist/evaluate-document.cjs +93 -0
- package/dist/evaluate-document.d.cts +44 -0
- package/dist/evaluate-document.d.ts +44 -0
- package/dist/evaluate-document.js +92 -0
- package/dist/evaluator-collection.d.cts +1 -1
- package/dist/evaluator-collection.d.ts +1 -1
- package/dist/evaluator-factory.d.cts +1 -1
- package/dist/evaluator-factory.d.ts +1 -1
- package/dist/evaluator-indeterminacy-helpers.d.cts +1 -1
- package/dist/evaluator-indeterminacy-helpers.d.ts +1 -1
- package/dist/evaluator-operations.cjs +75 -24
- package/dist/evaluator-operations.d.cts +3 -3
- package/dist/evaluator-operations.d.ts +3 -3
- package/dist/evaluator-operations.js +74 -23
- package/dist/evaluator.d.cts +1 -1
- package/dist/evaluator.d.ts +1 -1
- package/dist/functions.d.cts +8 -4
- package/dist/functions.d.ts +8 -4
- package/dist/index.cjs +8 -1
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/dist/input-resolvers.cjs +110 -0
- package/dist/input-resolvers.d.cts +24 -0
- package/dist/input-resolvers.d.ts +24 -0
- package/dist/input-resolvers.js +108 -0
- package/dist/integer-power.cjs +20 -0
- package/dist/integer-power.d.cts +13 -0
- package/dist/integer-power.d.ts +13 -0
- package/dist/integer-power.js +19 -0
- package/dist/plain-record.cjs +8 -0
- package/dist/plain-record.d.cts +4 -0
- package/dist/plain-record.d.ts +4 -0
- package/dist/plain-record.js +7 -0
- package/dist-cli/trilean.mjs +1848 -0
- package/package.json +5 -1
- package/schemas/trilean.schema.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { a as Unit, c as combineUnitsForMultiply, i as DurationUnitSchema, l as unitsEqual, n as ComputedValueSchema, o as UnitSchema, r as DurationUnit, s as combineUnitsForDivide, t as ComputedValue } from "./computed-value-CbRF0Izc.cjs";
|
|
2
|
+
import { FunctionFailure, FunctionRegistry, emptyFunctionRegistry } from "./functions.cjs";
|
|
3
|
+
import { builtinFunctions } from "./builtin-functions.cjs";
|
|
2
4
|
import { n as JsonValueSchema, t as JsonValue } from "./json-value-B1Hjjjri.cjs";
|
|
3
5
|
import { AccumulatorNode, AccumulatorNodeSchema, AllOfNode, AllOfNodeSchema, AndNode, AndNodeSchema, AnyOfNode, AnyOfNodeSchema, ArithmeticNode, ArithmeticNodeSchema, ArithmeticOperator, ArithmeticOperatorSchema, BooleanLiteralNode, BooleanLiteralNodeSchema, CallNode, CallNodeSchema, CompareNode, CompareNodeSchema, ComparisonOperator, ComparisonOperatorSchema, ComplexLiteralNode, ComplexLiteralNodeSchema, ComplexPolarLiteralNode, ComplexPolarLiteralNodeSchema, ComplexRectangularLiteralNode, ComplexRectangularLiteralNodeSchema, ConditionalCase, ConditionalCaseSchema, ConditionalNode, ConditionalNodeSchema, DelegateNode, DelegateNodeSchema, DurationLiteralNode, DurationLiteralNodeSchema, EveryNode, EveryNodeSchema, ExistsNode, ExistsNodeSchema, ExpressionNode, ExpressionNodeSchema, FoldCombiner, FoldCombinerSchema, FoldNode, FoldNodeSchema, HitPolicy, HitPolicySchema, InstantLiteralNode, InstantLiteralNodeSchema, LookupNode, LookupNodeSchema, MemberOfNode, MemberOfNodeSchema, MembershipOperator, MembershipOperatorSchema, NegateNode, NegateNodeSchema, NotNode, NotNodeSchema, NumberLiteralNode, NumberLiteralNodeSchema, OrNode, OrNodeSchema, PredicateNode, PredicateNodeSchema, ReferenceNode, ReferenceNodeSchema, SomeNode, SomeNodeSchema, TextCompareNode, TextCompareNodeSchema, TextComparisonOperator, TextComparisonOperatorSchema, TextLiteralNode, TextLiteralNodeSchema, TreeReferenceNode, TreeReferenceNodeSchema } from "./tree.cjs";
|
|
4
6
|
import { complexFromPolar, complexLiteralFromPolar, complexMagnitude, complexPhase } from "./complex.cjs";
|
|
@@ -7,7 +9,8 @@ import { and, iff, implies, nand, none, nor, not, or, xor } from "./derived-conn
|
|
|
7
9
|
import { hierarchicalGlobPattern, prefixPattern, wildcardPattern } from "./derived-patterns.cjs";
|
|
8
10
|
import { coalesce } from "./derived-values.cjs";
|
|
9
11
|
import { Evaluation, IndeterminateReason, IndeterminateReasonSchema, definite, firstIndeterminate, indeterminate } from "./evaluation.cjs";
|
|
10
|
-
import {
|
|
12
|
+
import { DocumentEvaluation, EvaluateDocumentOptions, TreeKind, evaluateDocument } from "./evaluate-document.cjs";
|
|
11
13
|
import { EvaluationContext, Resolution, Resolvers, SyncResolvers, TreeResolution } from "./resolvers.cjs";
|
|
12
14
|
import { EvaluatorOptions, createEvaluator, createSyncEvaluator, evaluatePredicate, evaluateValue } from "./evaluator-factory.cjs";
|
|
13
|
-
|
|
15
|
+
import { InputItem, InputsParseResult, createInputResolvers, parseInputs } from "./input-resolvers.cjs";
|
|
16
|
+
export { type AccumulatorNode, AccumulatorNodeSchema, type AllOfNode, AllOfNodeSchema, type AndNode, AndNodeSchema, type AnyOfNode, AnyOfNodeSchema, type ArithmeticNode, ArithmeticNodeSchema, type ArithmeticOperator, ArithmeticOperatorSchema, type BooleanLiteralNode, BooleanLiteralNodeSchema, type CallNode, CallNodeSchema, type CompareNode, CompareNodeSchema, type ComparisonOperator, ComparisonOperatorSchema, type ComplexLiteralNode, ComplexLiteralNodeSchema, type ComplexPolarLiteralNode, ComplexPolarLiteralNodeSchema, type ComplexRectangularLiteralNode, ComplexRectangularLiteralNodeSchema, type ComputedValue, ComputedValueSchema, type ConditionalCase, ConditionalCaseSchema, type ConditionalNode, ConditionalNodeSchema, type DelegateNode, DelegateNodeSchema, type DocumentEvaluation, type DurationLiteralNode, DurationLiteralNodeSchema, type DurationUnit, DurationUnitSchema, type EvaluateDocumentOptions, type Evaluation, type EvaluationContext, type EvaluatorOptions, type EveryNode, EveryNodeSchema, type ExistsNode, ExistsNodeSchema, type ExpressionNode, ExpressionNodeSchema, type FoldCombiner, FoldCombinerSchema, type FoldNode, FoldNodeSchema, type FunctionFailure, type FunctionRegistry, type HitPolicy, HitPolicySchema, type IndeterminateReason, IndeterminateReasonSchema, type InputItem, type InputsParseResult, type InstantLiteralNode, InstantLiteralNodeSchema, type JsonValue, JsonValueSchema, type LookupNode, LookupNodeSchema, type MemberOfNode, MemberOfNodeSchema, type MembershipOperator, MembershipOperatorSchema, type NegateNode, NegateNodeSchema, type NotNode, NotNodeSchema, type NumberLiteralNode, NumberLiteralNodeSchema, type OrNode, OrNodeSchema, type PredicateNode, PredicateNodeSchema, type ReferenceNode, ReferenceNodeSchema, type Resolution, type Resolvers, type SomeNode, SomeNodeSchema, type SyncResolvers, type TextCompareNode, TextCompareNodeSchema, type TextComparisonOperator, TextComparisonOperatorSchema, type TextLiteralNode, TextLiteralNodeSchema, type TreeKind, type TreeReferenceNode, TreeReferenceNodeSchema, type TreeResolution, type Unit, UnitSchema, and, average, builtinFunctions, coalesce, combineUnitsForDivide, combineUnitsForMultiply, complexFromPolar, complexLiteralFromPolar, complexMagnitude, complexPhase, count, createEvaluator, createInputResolvers, createSyncEvaluator, definite, emptyFunctionRegistry, evaluateDocument, evaluatePredicate, evaluateValue, firstIndeterminate, hierarchicalGlobPattern, iff, implies, indeterminate, nand, none, nor, not, or, parseInputs, prefixPattern, presenceOf, sum, unitsEqual, wildcardPattern, xor };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { a as Unit, c as combineUnitsForMultiply, i as DurationUnitSchema, l as unitsEqual, n as ComputedValueSchema, o as UnitSchema, r as DurationUnit, s as combineUnitsForDivide, t as ComputedValue } from "./computed-value-CbRF0Izc.js";
|
|
2
|
+
import { FunctionFailure, FunctionRegistry, emptyFunctionRegistry } from "./functions.js";
|
|
3
|
+
import { builtinFunctions } from "./builtin-functions.js";
|
|
2
4
|
import { n as JsonValueSchema, t as JsonValue } from "./json-value-B1Hjjjri.js";
|
|
3
5
|
import { AccumulatorNode, AccumulatorNodeSchema, AllOfNode, AllOfNodeSchema, AndNode, AndNodeSchema, AnyOfNode, AnyOfNodeSchema, ArithmeticNode, ArithmeticNodeSchema, ArithmeticOperator, ArithmeticOperatorSchema, BooleanLiteralNode, BooleanLiteralNodeSchema, CallNode, CallNodeSchema, CompareNode, CompareNodeSchema, ComparisonOperator, ComparisonOperatorSchema, ComplexLiteralNode, ComplexLiteralNodeSchema, ComplexPolarLiteralNode, ComplexPolarLiteralNodeSchema, ComplexRectangularLiteralNode, ComplexRectangularLiteralNodeSchema, ConditionalCase, ConditionalCaseSchema, ConditionalNode, ConditionalNodeSchema, DelegateNode, DelegateNodeSchema, DurationLiteralNode, DurationLiteralNodeSchema, EveryNode, EveryNodeSchema, ExistsNode, ExistsNodeSchema, ExpressionNode, ExpressionNodeSchema, FoldCombiner, FoldCombinerSchema, FoldNode, FoldNodeSchema, HitPolicy, HitPolicySchema, InstantLiteralNode, InstantLiteralNodeSchema, LookupNode, LookupNodeSchema, MemberOfNode, MemberOfNodeSchema, MembershipOperator, MembershipOperatorSchema, NegateNode, NegateNodeSchema, NotNode, NotNodeSchema, NumberLiteralNode, NumberLiteralNodeSchema, OrNode, OrNodeSchema, PredicateNode, PredicateNodeSchema, ReferenceNode, ReferenceNodeSchema, SomeNode, SomeNodeSchema, TextCompareNode, TextCompareNodeSchema, TextComparisonOperator, TextComparisonOperatorSchema, TextLiteralNode, TextLiteralNodeSchema, TreeReferenceNode, TreeReferenceNodeSchema } from "./tree.js";
|
|
4
6
|
import { complexFromPolar, complexLiteralFromPolar, complexMagnitude, complexPhase } from "./complex.js";
|
|
@@ -7,7 +9,8 @@ import { and, iff, implies, nand, none, nor, not, or, xor } from "./derived-conn
|
|
|
7
9
|
import { hierarchicalGlobPattern, prefixPattern, wildcardPattern } from "./derived-patterns.js";
|
|
8
10
|
import { coalesce } from "./derived-values.js";
|
|
9
11
|
import { Evaluation, IndeterminateReason, IndeterminateReasonSchema, definite, firstIndeterminate, indeterminate } from "./evaluation.js";
|
|
10
|
-
import {
|
|
12
|
+
import { DocumentEvaluation, EvaluateDocumentOptions, TreeKind, evaluateDocument } from "./evaluate-document.js";
|
|
11
13
|
import { EvaluationContext, Resolution, Resolvers, SyncResolvers, TreeResolution } from "./resolvers.js";
|
|
12
14
|
import { EvaluatorOptions, createEvaluator, createSyncEvaluator, evaluatePredicate, evaluateValue } from "./evaluator-factory.js";
|
|
13
|
-
|
|
15
|
+
import { InputItem, InputsParseResult, createInputResolvers, parseInputs } from "./input-resolvers.js";
|
|
16
|
+
export { type AccumulatorNode, AccumulatorNodeSchema, type AllOfNode, AllOfNodeSchema, type AndNode, AndNodeSchema, type AnyOfNode, AnyOfNodeSchema, type ArithmeticNode, ArithmeticNodeSchema, type ArithmeticOperator, ArithmeticOperatorSchema, type BooleanLiteralNode, BooleanLiteralNodeSchema, type CallNode, CallNodeSchema, type CompareNode, CompareNodeSchema, type ComparisonOperator, ComparisonOperatorSchema, type ComplexLiteralNode, ComplexLiteralNodeSchema, type ComplexPolarLiteralNode, ComplexPolarLiteralNodeSchema, type ComplexRectangularLiteralNode, ComplexRectangularLiteralNodeSchema, type ComputedValue, ComputedValueSchema, type ConditionalCase, ConditionalCaseSchema, type ConditionalNode, ConditionalNodeSchema, type DelegateNode, DelegateNodeSchema, type DocumentEvaluation, type DurationLiteralNode, DurationLiteralNodeSchema, type DurationUnit, DurationUnitSchema, type EvaluateDocumentOptions, type Evaluation, type EvaluationContext, type EvaluatorOptions, type EveryNode, EveryNodeSchema, type ExistsNode, ExistsNodeSchema, type ExpressionNode, ExpressionNodeSchema, type FoldCombiner, FoldCombinerSchema, type FoldNode, FoldNodeSchema, type FunctionFailure, type FunctionRegistry, type HitPolicy, HitPolicySchema, type IndeterminateReason, IndeterminateReasonSchema, type InputItem, type InputsParseResult, type InstantLiteralNode, InstantLiteralNodeSchema, type JsonValue, JsonValueSchema, type LookupNode, LookupNodeSchema, type MemberOfNode, MemberOfNodeSchema, type MembershipOperator, MembershipOperatorSchema, type NegateNode, NegateNodeSchema, type NotNode, NotNodeSchema, type NumberLiteralNode, NumberLiteralNodeSchema, type OrNode, OrNodeSchema, type PredicateNode, PredicateNodeSchema, type ReferenceNode, ReferenceNodeSchema, type Resolution, type Resolvers, type SomeNode, SomeNodeSchema, type SyncResolvers, type TextCompareNode, TextCompareNodeSchema, type TextComparisonOperator, TextComparisonOperatorSchema, type TextLiteralNode, TextLiteralNodeSchema, type TreeKind, type TreeReferenceNode, TreeReferenceNodeSchema, type TreeResolution, type Unit, UnitSchema, and, average, builtinFunctions, coalesce, combineUnitsForDivide, combineUnitsForMultiply, complexFromPolar, complexLiteralFromPolar, complexMagnitude, complexPhase, count, createEvaluator, createInputResolvers, createSyncEvaluator, definite, emptyFunctionRegistry, evaluateDocument, evaluatePredicate, evaluateValue, firstIndeterminate, hierarchicalGlobPattern, iff, implies, indeterminate, nand, none, nor, not, or, parseInputs, prefixPattern, presenceOf, sum, unitsEqual, wildcardPattern, xor };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { complexFromPolar, complexLiteralFromPolar, complexMagnitude, complexPhase } from "./complex.js";
|
|
2
1
|
import { ComputedValueSchema, DurationUnitSchema, UnitSchema, combineUnitsForDivide, combineUnitsForMultiply, unitsEqual } from "./computed-value.js";
|
|
2
|
+
import { complexFromPolar, complexLiteralFromPolar, complexMagnitude, complexPhase } from "./complex.js";
|
|
3
|
+
import { builtinFunctions } from "./builtin-functions.js";
|
|
3
4
|
import { average, count, presenceOf, sum } from "./derived-aggregates.js";
|
|
4
5
|
import { and, iff, implies, nand, none, nor, not, or, xor } from "./derived-connectives.js";
|
|
5
6
|
import { hierarchicalGlobPattern, prefixPattern, wildcardPattern } from "./derived-patterns.js";
|
|
@@ -9,4 +10,6 @@ import { JsonValueSchema } from "./json-value.js";
|
|
|
9
10
|
import { AccumulatorNodeSchema, AllOfNodeSchema, AndNodeSchema, AnyOfNodeSchema, ArithmeticNodeSchema, ArithmeticOperatorSchema, BooleanLiteralNodeSchema, CallNodeSchema, CompareNodeSchema, ComparisonOperatorSchema, ComplexLiteralNodeSchema, ComplexPolarLiteralNodeSchema, ComplexRectangularLiteralNodeSchema, ConditionalCaseSchema, ConditionalNodeSchema, DelegateNodeSchema, DurationLiteralNodeSchema, EveryNodeSchema, ExistsNodeSchema, ExpressionNodeSchema, FoldCombinerSchema, FoldNodeSchema, HitPolicySchema, InstantLiteralNodeSchema, LookupNodeSchema, MemberOfNodeSchema, MembershipOperatorSchema, NegateNodeSchema, NotNodeSchema, NumberLiteralNodeSchema, OrNodeSchema, PredicateNodeSchema, ReferenceNodeSchema, SomeNodeSchema, TextCompareNodeSchema, TextComparisonOperatorSchema, TextLiteralNodeSchema, TreeReferenceNodeSchema } from "./tree.js";
|
|
10
11
|
import { emptyFunctionRegistry } from "./functions.js";
|
|
11
12
|
import { createEvaluator, createSyncEvaluator, evaluatePredicate, evaluateValue } from "./evaluator-factory.js";
|
|
12
|
-
|
|
13
|
+
import { createInputResolvers, parseInputs } from "./input-resolvers.js";
|
|
14
|
+
import { evaluateDocument } from "./evaluate-document.js";
|
|
15
|
+
export { AccumulatorNodeSchema, AllOfNodeSchema, AndNodeSchema, AnyOfNodeSchema, ArithmeticNodeSchema, ArithmeticOperatorSchema, BooleanLiteralNodeSchema, CallNodeSchema, CompareNodeSchema, ComparisonOperatorSchema, ComplexLiteralNodeSchema, ComplexPolarLiteralNodeSchema, ComplexRectangularLiteralNodeSchema, ComputedValueSchema, ConditionalCaseSchema, ConditionalNodeSchema, DelegateNodeSchema, DurationLiteralNodeSchema, DurationUnitSchema, EveryNodeSchema, ExistsNodeSchema, ExpressionNodeSchema, FoldCombinerSchema, FoldNodeSchema, HitPolicySchema, IndeterminateReasonSchema, InstantLiteralNodeSchema, JsonValueSchema, LookupNodeSchema, MemberOfNodeSchema, MembershipOperatorSchema, NegateNodeSchema, NotNodeSchema, NumberLiteralNodeSchema, OrNodeSchema, PredicateNodeSchema, ReferenceNodeSchema, SomeNodeSchema, TextCompareNodeSchema, TextComparisonOperatorSchema, TextLiteralNodeSchema, TreeReferenceNodeSchema, UnitSchema, and, average, builtinFunctions, coalesce, combineUnitsForDivide, combineUnitsForMultiply, complexFromPolar, complexLiteralFromPolar, complexMagnitude, complexPhase, count, createEvaluator, createInputResolvers, createSyncEvaluator, definite, emptyFunctionRegistry, evaluateDocument, evaluatePredicate, evaluateValue, firstIndeterminate, hierarchicalGlobPattern, iff, implies, indeterminate, nand, none, nor, not, or, parseInputs, prefixPattern, presenceOf, sum, unitsEqual, wildcardPattern, xor };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_computed_value = require("./computed-value.cjs");
|
|
3
|
+
const require_plain_record = require("./plain-record.cjs");
|
|
4
|
+
//#region src/input-resolvers.ts
|
|
5
|
+
/** A plain JSON number, string or boolean is the unit-less value of that kind; anything else must already be a complete `ComputedValue` (the only way to supply units, durations, instants or complex values). Both routes end in `ComputedValueSchema`, so a number that is not finite (`1e999` parses to `Infinity`) is refused whichever way it was written, and a field the schema does not define is dropped rather than carried along. */
|
|
6
|
+
function toComputedValue(raw) {
|
|
7
|
+
const candidate = typeof raw === "number" ? {
|
|
8
|
+
kind: "number",
|
|
9
|
+
value: raw
|
|
10
|
+
} : typeof raw === "string" ? {
|
|
11
|
+
kind: "text",
|
|
12
|
+
value: raw
|
|
13
|
+
} : typeof raw === "boolean" ? {
|
|
14
|
+
kind: "boolean",
|
|
15
|
+
value: raw
|
|
16
|
+
} : raw;
|
|
17
|
+
const parsed = require_computed_value.ComputedValueSchema.safeParse(candidate);
|
|
18
|
+
return parsed.success ? parsed.data : void 0;
|
|
19
|
+
}
|
|
20
|
+
const NOT_A_VALUE = "expected a finite number, text, boolean or a complete computed value";
|
|
21
|
+
/**
|
|
22
|
+
* The evaluation context while a `fold`, `some` or `every` is evaluating one item. `resolveCollection` wraps each element in one of these, and `resolveValue` reads names from an item only when its context is one, so scope follows what the resolver itself handed out and not the identity or shape of anything else. The class is not exported, so no value passed as a context can be mistaken for an item. The guarantee is about this resolver's own `resolveCollection`: a list served by it is scoped, and the supported way to give it lists is the `collections` argument of `createInputResolvers`. An embedder that composes resolvers, spreading these and overriding `resolveCollection` to serve its own items while keeping this `resolveValue`, serves items that are not wrappers, and a fold over them reads names from the top-level inputs; scoping those items is the embedder's responsibility.
|
|
23
|
+
*/
|
|
24
|
+
var ScopedItem = class {
|
|
25
|
+
values;
|
|
26
|
+
constructor(values) {
|
|
27
|
+
this.values = values;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/** Validates one element of a list input: a plain object whose every entry is a value, each by the same rules as a top-level input. */
|
|
31
|
+
function parseItem(label, raw) {
|
|
32
|
+
if (!require_plain_record.isPlainRecord(raw)) return {
|
|
33
|
+
item: void 0,
|
|
34
|
+
issues: [`${label}: expected an object of named values`]
|
|
35
|
+
};
|
|
36
|
+
const item = /* @__PURE__ */ new Map();
|
|
37
|
+
const issues = [];
|
|
38
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
39
|
+
const computed = toComputedValue(value);
|
|
40
|
+
if (computed === void 0) issues.push(`${label}.${name}: ${NOT_A_VALUE}`);
|
|
41
|
+
else item.set(name, computed);
|
|
42
|
+
}
|
|
43
|
+
if (issues.length > 0) return {
|
|
44
|
+
item: void 0,
|
|
45
|
+
issues
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
item,
|
|
49
|
+
issues
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Validates a plain object of inputs and splits it into named values and lists of items. An entry that is an array is a list: every element must be an object of named values (see `toComputedValue` for the accepted shapes of each value), and the list is what a `fold`, `some` or `every` resolves its `collection` to. Any other entry is one named value. Every entry is checked up front, so a malformed input is reported as one by name and position rather than surfacing later as a `not-found` reference.
|
|
54
|
+
*/
|
|
55
|
+
function parseInputs(raw) {
|
|
56
|
+
if (!require_plain_record.isPlainRecord(raw)) return {
|
|
57
|
+
ok: false,
|
|
58
|
+
issues: ["inputs must be a JSON object of named values"]
|
|
59
|
+
};
|
|
60
|
+
const inputs = /* @__PURE__ */ new Map();
|
|
61
|
+
const collections = /* @__PURE__ */ new Map();
|
|
62
|
+
const issues = [];
|
|
63
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
64
|
+
if (Array.isArray(value)) {
|
|
65
|
+
const items = [];
|
|
66
|
+
value.forEach((element, index) => {
|
|
67
|
+
const parsedItem = parseItem(`inputs.${name}[${String(index)}]`, element);
|
|
68
|
+
issues.push(...parsedItem.issues);
|
|
69
|
+
if (parsedItem.item !== void 0) items.push(parsedItem.item);
|
|
70
|
+
});
|
|
71
|
+
collections.set(name, items);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const computed = toComputedValue(value);
|
|
75
|
+
if (computed === void 0) issues.push(`inputs.${name}: ${NOT_A_VALUE}`);
|
|
76
|
+
else inputs.set(name, computed);
|
|
77
|
+
}
|
|
78
|
+
return issues.length === 0 ? {
|
|
79
|
+
ok: true,
|
|
80
|
+
inputs,
|
|
81
|
+
collections
|
|
82
|
+
} : {
|
|
83
|
+
ok: false,
|
|
84
|
+
issues
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Synchronous resolvers over named inputs and lists of items. A `reference` whose key is a string resolves to the value of that name: against the top-level inputs outside a `fold`, `some` or `every`, and against the current item alone inside one, since descending into a collection replaces the evaluation context with the item (an item does not see the top-level inputs, so a value an item needs is written into the item). Every other key, and every `lookup`, is `not-found`. `resolveCollection` returns the items the inputs hold under the collection's name, each wrapped so that only the wrapper this module created is read as an item (a list built by the embedder works the same as a parsed one), and throws for a collection the inputs do not hold: an empty list would silently change what a `fold`, `some` or `every` means, and a missing list is a mistake in the tree or the inputs, not an empty collection. `delegate` and `treeReference` nodes are left unresolved, so they are `wrong-type` like any node whose optional resolver is absent.
|
|
89
|
+
*/
|
|
90
|
+
function createInputResolvers(inputs, collections = /* @__PURE__ */ new Map()) {
|
|
91
|
+
return {
|
|
92
|
+
resolveValue: (key, context) => {
|
|
93
|
+
const scope = context instanceof ScopedItem ? context.values : inputs;
|
|
94
|
+
const value = typeof key === "string" ? scope.get(key) : void 0;
|
|
95
|
+
return value === void 0 ? { found: false } : {
|
|
96
|
+
found: true,
|
|
97
|
+
value
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
resolveLookup: () => ({ found: false }),
|
|
101
|
+
resolveCollection: (collection) => {
|
|
102
|
+
const items = typeof collection === "string" ? collections.get(collection) : void 0;
|
|
103
|
+
if (items === void 0) throw new Error(`collection ${JSON.stringify(collection)} cannot be resolved: the inputs hold no list of items under that name`);
|
|
104
|
+
return items.map((values) => new ScopedItem(values));
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
exports.createInputResolvers = createInputResolvers;
|
|
110
|
+
exports.parseInputs = parseInputs;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { t as ComputedValue } from "./computed-value-CbRF0Izc.cjs";
|
|
2
|
+
import { SyncResolvers } from "./resolvers.cjs";
|
|
3
|
+
//#region src/input-resolvers.d.ts
|
|
4
|
+
/** One element of a list input: the named values a `reference` resolves against while a `fold`, `some` or `every` is evaluating that element. */
|
|
5
|
+
export type InputItem = ReadonlyMap<string, ComputedValue>;
|
|
6
|
+
export type InputsParseResult = {
|
|
7
|
+
ok: true;
|
|
8
|
+
/** The named values: every entry that is not an array. */
|
|
9
|
+
inputs: ReadonlyMap<string, ComputedValue>;
|
|
10
|
+
/** The lists of items: every entry that is an array, which a `fold`, `some` or `every` names as its `collection`. */
|
|
11
|
+
collections: ReadonlyMap<string, readonly InputItem[]>;
|
|
12
|
+
} | {
|
|
13
|
+
ok: false;
|
|
14
|
+
issues: readonly string[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Validates a plain object of inputs and splits it into named values and lists of items. An entry that is an array is a list: every element must be an object of named values (see `toComputedValue` for the accepted shapes of each value), and the list is what a `fold`, `some` or `every` resolves its `collection` to. Any other entry is one named value. Every entry is checked up front, so a malformed input is reported as one by name and position rather than surfacing later as a `not-found` reference.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseInputs(raw: unknown): InputsParseResult;
|
|
20
|
+
/**
|
|
21
|
+
* Synchronous resolvers over named inputs and lists of items. A `reference` whose key is a string resolves to the value of that name: against the top-level inputs outside a `fold`, `some` or `every`, and against the current item alone inside one, since descending into a collection replaces the evaluation context with the item (an item does not see the top-level inputs, so a value an item needs is written into the item). Every other key, and every `lookup`, is `not-found`. `resolveCollection` returns the items the inputs hold under the collection's name, each wrapped so that only the wrapper this module created is read as an item (a list built by the embedder works the same as a parsed one), and throws for a collection the inputs do not hold: an empty list would silently change what a `fold`, `some` or `every` means, and a missing list is a mistake in the tree or the inputs, not an empty collection. `delegate` and `treeReference` nodes are left unresolved, so they are `wrong-type` like any node whose optional resolver is absent.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createInputResolvers(inputs: ReadonlyMap<string, ComputedValue>, collections?: ReadonlyMap<string, readonly InputItem[]>): SyncResolvers;
|
|
24
|
+
//#endregion
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { t as ComputedValue } from "./computed-value-CbRF0Izc.js";
|
|
2
|
+
import { SyncResolvers } from "./resolvers.js";
|
|
3
|
+
//#region src/input-resolvers.d.ts
|
|
4
|
+
/** One element of a list input: the named values a `reference` resolves against while a `fold`, `some` or `every` is evaluating that element. */
|
|
5
|
+
export type InputItem = ReadonlyMap<string, ComputedValue>;
|
|
6
|
+
export type InputsParseResult = {
|
|
7
|
+
ok: true;
|
|
8
|
+
/** The named values: every entry that is not an array. */
|
|
9
|
+
inputs: ReadonlyMap<string, ComputedValue>;
|
|
10
|
+
/** The lists of items: every entry that is an array, which a `fold`, `some` or `every` names as its `collection`. */
|
|
11
|
+
collections: ReadonlyMap<string, readonly InputItem[]>;
|
|
12
|
+
} | {
|
|
13
|
+
ok: false;
|
|
14
|
+
issues: readonly string[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Validates a plain object of inputs and splits it into named values and lists of items. An entry that is an array is a list: every element must be an object of named values (see `toComputedValue` for the accepted shapes of each value), and the list is what a `fold`, `some` or `every` resolves its `collection` to. Any other entry is one named value. Every entry is checked up front, so a malformed input is reported as one by name and position rather than surfacing later as a `not-found` reference.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseInputs(raw: unknown): InputsParseResult;
|
|
20
|
+
/**
|
|
21
|
+
* Synchronous resolvers over named inputs and lists of items. A `reference` whose key is a string resolves to the value of that name: against the top-level inputs outside a `fold`, `some` or `every`, and against the current item alone inside one, since descending into a collection replaces the evaluation context with the item (an item does not see the top-level inputs, so a value an item needs is written into the item). Every other key, and every `lookup`, is `not-found`. `resolveCollection` returns the items the inputs hold under the collection's name, each wrapped so that only the wrapper this module created is read as an item (a list built by the embedder works the same as a parsed one), and throws for a collection the inputs do not hold: an empty list would silently change what a `fold`, `some` or `every` means, and a missing list is a mistake in the tree or the inputs, not an empty collection. `delegate` and `treeReference` nodes are left unresolved, so they are `wrong-type` like any node whose optional resolver is absent.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createInputResolvers(inputs: ReadonlyMap<string, ComputedValue>, collections?: ReadonlyMap<string, readonly InputItem[]>): SyncResolvers;
|
|
24
|
+
//#endregion
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { ComputedValueSchema } from "./computed-value.js";
|
|
2
|
+
import { isPlainRecord } from "./plain-record.js";
|
|
3
|
+
//#region src/input-resolvers.ts
|
|
4
|
+
/** A plain JSON number, string or boolean is the unit-less value of that kind; anything else must already be a complete `ComputedValue` (the only way to supply units, durations, instants or complex values). Both routes end in `ComputedValueSchema`, so a number that is not finite (`1e999` parses to `Infinity`) is refused whichever way it was written, and a field the schema does not define is dropped rather than carried along. */
|
|
5
|
+
function toComputedValue(raw) {
|
|
6
|
+
const candidate = typeof raw === "number" ? {
|
|
7
|
+
kind: "number",
|
|
8
|
+
value: raw
|
|
9
|
+
} : typeof raw === "string" ? {
|
|
10
|
+
kind: "text",
|
|
11
|
+
value: raw
|
|
12
|
+
} : typeof raw === "boolean" ? {
|
|
13
|
+
kind: "boolean",
|
|
14
|
+
value: raw
|
|
15
|
+
} : raw;
|
|
16
|
+
const parsed = ComputedValueSchema.safeParse(candidate);
|
|
17
|
+
return parsed.success ? parsed.data : void 0;
|
|
18
|
+
}
|
|
19
|
+
const NOT_A_VALUE = "expected a finite number, text, boolean or a complete computed value";
|
|
20
|
+
/**
|
|
21
|
+
* The evaluation context while a `fold`, `some` or `every` is evaluating one item. `resolveCollection` wraps each element in one of these, and `resolveValue` reads names from an item only when its context is one, so scope follows what the resolver itself handed out and not the identity or shape of anything else. The class is not exported, so no value passed as a context can be mistaken for an item. The guarantee is about this resolver's own `resolveCollection`: a list served by it is scoped, and the supported way to give it lists is the `collections` argument of `createInputResolvers`. An embedder that composes resolvers, spreading these and overriding `resolveCollection` to serve its own items while keeping this `resolveValue`, serves items that are not wrappers, and a fold over them reads names from the top-level inputs; scoping those items is the embedder's responsibility.
|
|
22
|
+
*/
|
|
23
|
+
var ScopedItem = class {
|
|
24
|
+
values;
|
|
25
|
+
constructor(values) {
|
|
26
|
+
this.values = values;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/** Validates one element of a list input: a plain object whose every entry is a value, each by the same rules as a top-level input. */
|
|
30
|
+
function parseItem(label, raw) {
|
|
31
|
+
if (!isPlainRecord(raw)) return {
|
|
32
|
+
item: void 0,
|
|
33
|
+
issues: [`${label}: expected an object of named values`]
|
|
34
|
+
};
|
|
35
|
+
const item = /* @__PURE__ */ new Map();
|
|
36
|
+
const issues = [];
|
|
37
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
38
|
+
const computed = toComputedValue(value);
|
|
39
|
+
if (computed === void 0) issues.push(`${label}.${name}: ${NOT_A_VALUE}`);
|
|
40
|
+
else item.set(name, computed);
|
|
41
|
+
}
|
|
42
|
+
if (issues.length > 0) return {
|
|
43
|
+
item: void 0,
|
|
44
|
+
issues
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
item,
|
|
48
|
+
issues
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Validates a plain object of inputs and splits it into named values and lists of items. An entry that is an array is a list: every element must be an object of named values (see `toComputedValue` for the accepted shapes of each value), and the list is what a `fold`, `some` or `every` resolves its `collection` to. Any other entry is one named value. Every entry is checked up front, so a malformed input is reported as one by name and position rather than surfacing later as a `not-found` reference.
|
|
53
|
+
*/
|
|
54
|
+
function parseInputs(raw) {
|
|
55
|
+
if (!isPlainRecord(raw)) return {
|
|
56
|
+
ok: false,
|
|
57
|
+
issues: ["inputs must be a JSON object of named values"]
|
|
58
|
+
};
|
|
59
|
+
const inputs = /* @__PURE__ */ new Map();
|
|
60
|
+
const collections = /* @__PURE__ */ new Map();
|
|
61
|
+
const issues = [];
|
|
62
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
63
|
+
if (Array.isArray(value)) {
|
|
64
|
+
const items = [];
|
|
65
|
+
value.forEach((element, index) => {
|
|
66
|
+
const parsedItem = parseItem(`inputs.${name}[${String(index)}]`, element);
|
|
67
|
+
issues.push(...parsedItem.issues);
|
|
68
|
+
if (parsedItem.item !== void 0) items.push(parsedItem.item);
|
|
69
|
+
});
|
|
70
|
+
collections.set(name, items);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const computed = toComputedValue(value);
|
|
74
|
+
if (computed === void 0) issues.push(`inputs.${name}: ${NOT_A_VALUE}`);
|
|
75
|
+
else inputs.set(name, computed);
|
|
76
|
+
}
|
|
77
|
+
return issues.length === 0 ? {
|
|
78
|
+
ok: true,
|
|
79
|
+
inputs,
|
|
80
|
+
collections
|
|
81
|
+
} : {
|
|
82
|
+
ok: false,
|
|
83
|
+
issues
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Synchronous resolvers over named inputs and lists of items. A `reference` whose key is a string resolves to the value of that name: against the top-level inputs outside a `fold`, `some` or `every`, and against the current item alone inside one, since descending into a collection replaces the evaluation context with the item (an item does not see the top-level inputs, so a value an item needs is written into the item). Every other key, and every `lookup`, is `not-found`. `resolveCollection` returns the items the inputs hold under the collection's name, each wrapped so that only the wrapper this module created is read as an item (a list built by the embedder works the same as a parsed one), and throws for a collection the inputs do not hold: an empty list would silently change what a `fold`, `some` or `every` means, and a missing list is a mistake in the tree or the inputs, not an empty collection. `delegate` and `treeReference` nodes are left unresolved, so they are `wrong-type` like any node whose optional resolver is absent.
|
|
88
|
+
*/
|
|
89
|
+
function createInputResolvers(inputs, collections = /* @__PURE__ */ new Map()) {
|
|
90
|
+
return {
|
|
91
|
+
resolveValue: (key, context) => {
|
|
92
|
+
const scope = context instanceof ScopedItem ? context.values : inputs;
|
|
93
|
+
const value = typeof key === "string" ? scope.get(key) : void 0;
|
|
94
|
+
return value === void 0 ? { found: false } : {
|
|
95
|
+
found: true,
|
|
96
|
+
value
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
resolveLookup: () => ({ found: false }),
|
|
100
|
+
resolveCollection: (collection) => {
|
|
101
|
+
const items = typeof collection === "string" ? collections.get(collection) : void 0;
|
|
102
|
+
if (items === void 0) throw new Error(`collection ${JSON.stringify(collection)} cannot be resolved: the inputs hold no list of items under that name`);
|
|
103
|
+
return items.map((values) => new ScopedItem(values));
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
export { createInputResolvers, parseInputs };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/integer-power.ts
|
|
3
|
+
/**
|
|
4
|
+
* `base` raised to a non-negative integer `exponent` by exponentiation by squaring: one squaring and at most one product per bit of the exponent, so the number of `multiply` calls grows with the logarithm of the exponent where repeated multiplication grows with the exponent itself (an exponent of 1e9 is a few dozen products rather than a billion). `identity` is the value of exponent zero and the start of the product; `multiply` must be associative, which squaring relies on. With a rounding `multiply` the grouping matters: squaring compounds a rounding error through each successive square, so its error grows in proportion to the exponent, and for large exponents the result is many times less accurate than a plain loop's, in exchange for work that does not grow with the exponent.
|
|
5
|
+
*
|
|
6
|
+
* The exponent is halved with `Math.floor(remaining / 2)` and tested for oddness with `% 2`, both exact for any finite double, including those past the largest safe integer, whose low bits are all zero. The last squaring is skipped, so no unused product is formed and a base too large to square is not squared once more than the result needs.
|
|
7
|
+
*/
|
|
8
|
+
function powerByRepeatedSquaring({ base, exponent, identity, multiply }) {
|
|
9
|
+
let result = identity;
|
|
10
|
+
let factor = base;
|
|
11
|
+
let remaining = exponent;
|
|
12
|
+
while (remaining > 0) {
|
|
13
|
+
if (remaining % 2 === 1) result = multiply(result, factor);
|
|
14
|
+
remaining = Math.floor(remaining / 2);
|
|
15
|
+
if (remaining > 0) factor = multiply(factor, factor);
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.powerByRepeatedSquaring = powerByRepeatedSquaring;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/integer-power.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* `base` raised to a non-negative integer `exponent` by exponentiation by squaring: one squaring and at most one product per bit of the exponent, so the number of `multiply` calls grows with the logarithm of the exponent where repeated multiplication grows with the exponent itself (an exponent of 1e9 is a few dozen products rather than a billion). `identity` is the value of exponent zero and the start of the product; `multiply` must be associative, which squaring relies on. With a rounding `multiply` the grouping matters: squaring compounds a rounding error through each successive square, so its error grows in proportion to the exponent, and for large exponents the result is many times less accurate than a plain loop's, in exchange for work that does not grow with the exponent.
|
|
4
|
+
*
|
|
5
|
+
* The exponent is halved with `Math.floor(remaining / 2)` and tested for oddness with `% 2`, both exact for any finite double, including those past the largest safe integer, whose low bits are all zero. The last squaring is skipped, so no unused product is formed and a base too large to square is not squared once more than the result needs.
|
|
6
|
+
*/
|
|
7
|
+
export declare function powerByRepeatedSquaring<T>({ base, exponent, identity, multiply }: {
|
|
8
|
+
base: T;
|
|
9
|
+
exponent: number;
|
|
10
|
+
identity: T;
|
|
11
|
+
multiply: (left: T, right: T) => T;
|
|
12
|
+
}): T;
|
|
13
|
+
//#endregion
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/integer-power.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* `base` raised to a non-negative integer `exponent` by exponentiation by squaring: one squaring and at most one product per bit of the exponent, so the number of `multiply` calls grows with the logarithm of the exponent where repeated multiplication grows with the exponent itself (an exponent of 1e9 is a few dozen products rather than a billion). `identity` is the value of exponent zero and the start of the product; `multiply` must be associative, which squaring relies on. With a rounding `multiply` the grouping matters: squaring compounds a rounding error through each successive square, so its error grows in proportion to the exponent, and for large exponents the result is many times less accurate than a plain loop's, in exchange for work that does not grow with the exponent.
|
|
4
|
+
*
|
|
5
|
+
* The exponent is halved with `Math.floor(remaining / 2)` and tested for oddness with `% 2`, both exact for any finite double, including those past the largest safe integer, whose low bits are all zero. The last squaring is skipped, so no unused product is formed and a base too large to square is not squared once more than the result needs.
|
|
6
|
+
*/
|
|
7
|
+
export declare function powerByRepeatedSquaring<T>({ base, exponent, identity, multiply }: {
|
|
8
|
+
base: T;
|
|
9
|
+
exponent: number;
|
|
10
|
+
identity: T;
|
|
11
|
+
multiply: (left: T, right: T) => T;
|
|
12
|
+
}): T;
|
|
13
|
+
//#endregion
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/integer-power.ts
|
|
2
|
+
/**
|
|
3
|
+
* `base` raised to a non-negative integer `exponent` by exponentiation by squaring: one squaring and at most one product per bit of the exponent, so the number of `multiply` calls grows with the logarithm of the exponent where repeated multiplication grows with the exponent itself (an exponent of 1e9 is a few dozen products rather than a billion). `identity` is the value of exponent zero and the start of the product; `multiply` must be associative, which squaring relies on. With a rounding `multiply` the grouping matters: squaring compounds a rounding error through each successive square, so its error grows in proportion to the exponent, and for large exponents the result is many times less accurate than a plain loop's, in exchange for work that does not grow with the exponent.
|
|
4
|
+
*
|
|
5
|
+
* The exponent is halved with `Math.floor(remaining / 2)` and tested for oddness with `% 2`, both exact for any finite double, including those past the largest safe integer, whose low bits are all zero. The last squaring is skipped, so no unused product is formed and a base too large to square is not squared once more than the result needs.
|
|
6
|
+
*/
|
|
7
|
+
function powerByRepeatedSquaring({ base, exponent, identity, multiply }) {
|
|
8
|
+
let result = identity;
|
|
9
|
+
let factor = base;
|
|
10
|
+
let remaining = exponent;
|
|
11
|
+
while (remaining > 0) {
|
|
12
|
+
if (remaining % 2 === 1) result = multiply(result, factor);
|
|
13
|
+
remaining = Math.floor(remaining / 2);
|
|
14
|
+
if (remaining > 0) factor = multiply(factor, factor);
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { powerByRepeatedSquaring };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/plain-record.ts
|
|
3
|
+
/** Narrows `unknown` to a plain JSON-style object: not `null`, not an array. The guard parsed JSON is checked with before its fields are read, in place of an `as Record<string, unknown>` assertion. */
|
|
4
|
+
function isPlainRecord(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.isPlainRecord = isPlainRecord;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
//#region src/plain-record.d.ts
|
|
2
|
+
/** Narrows `unknown` to a plain JSON-style object: not `null`, not an array. The guard parsed JSON is checked with before its fields are read, in place of an `as Record<string, unknown>` assertion. */
|
|
3
|
+
export declare function isPlainRecord(value: unknown): value is Record<string, unknown>;
|
|
4
|
+
//#endregion
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
//#region src/plain-record.d.ts
|
|
2
|
+
/** Narrows `unknown` to a plain JSON-style object: not `null`, not an array. The guard parsed JSON is checked with before its fields are read, in place of an `as Record<string, unknown>` assertion. */
|
|
3
|
+
export declare function isPlainRecord(value: unknown): value is Record<string, unknown>;
|
|
4
|
+
//#endregion
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/plain-record.ts
|
|
2
|
+
/** Narrows `unknown` to a plain JSON-style object: not `null`, not an array. The guard parsed JSON is checked with before its fields are read, in place of an `as Record<string, unknown>` assertion. */
|
|
3
|
+
function isPlainRecord(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { isPlainRecord };
|