trilean 1.13.11 → 2.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.
Files changed (65) hide show
  1. package/README.md +1 -1
  2. package/dist/evaluator-operations.js +24 -4
  3. package/dist-cli/trilean.mjs +25 -5
  4. package/package.json +10 -20
  5. package/schemas/trilean.schema.json +1 -1
  6. package/dist/builtin-functions.cjs +0 -242
  7. package/dist/builtin-functions.d.cts +0 -13
  8. package/dist/complex-division.cjs +0 -47
  9. package/dist/complex-division.d.cts +0 -23
  10. package/dist/complex.cjs +0 -35
  11. package/dist/complex.d.cts +0 -23
  12. package/dist/computed-value.cjs +0 -80
  13. package/dist/computed-value.d.cts +0 -48
  14. package/dist/derived-aggregates.cjs +0 -73
  15. package/dist/derived-aggregates.d.cts +0 -9
  16. package/dist/derived-connectives.cjs +0 -39
  17. package/dist/derived-connectives.d.cts +0 -14
  18. package/dist/derived-patterns.cjs +0 -93
  19. package/dist/derived-patterns.d.cts +0 -4
  20. package/dist/derived-values.cjs +0 -23
  21. package/dist/derived-values.d.cts +0 -7
  22. package/dist/dist-ed78Tuwe.js +0 -1612
  23. package/dist/dist-ySX7cb5d.cjs +0 -1612
  24. package/dist/duration-order.cjs +0 -83
  25. package/dist/duration-order.d.cts +0 -21
  26. package/dist/evaluate-document.cjs +0 -92
  27. package/dist/evaluate-document.d.cts +0 -42
  28. package/dist/evaluation.cjs +0 -47
  29. package/dist/evaluation.d.cts +0 -29
  30. package/dist/evaluator-budget.cjs +0 -37
  31. package/dist/evaluator-budget.d.cts +0 -22
  32. package/dist/evaluator-collection.cjs +0 -33
  33. package/dist/evaluator-collection.d.cts +0 -21
  34. package/dist/evaluator-compiled.cjs +0 -310
  35. package/dist/evaluator-compiled.d.cts +0 -18
  36. package/dist/evaluator-effect.cjs +0 -57
  37. package/dist/evaluator-effect.d.cts +0 -40
  38. package/dist/evaluator-factory.cjs +0 -31
  39. package/dist/evaluator-factory.d.cts +0 -34
  40. package/dist/evaluator-literals.cjs +0 -42
  41. package/dist/evaluator-literals.d.cts +0 -8
  42. package/dist/evaluator-operations.cjs +0 -440
  43. package/dist/evaluator-operations.d.cts +0 -27
  44. package/dist/evaluator-test-helpers.cjs +0 -15030
  45. package/dist/evaluator-test-helpers.d.cts +0 -10
  46. package/dist/evaluator-test-helpers.d.ts +0 -10
  47. package/dist/evaluator-test-helpers.js +0 -14902
  48. package/dist/evaluator.cjs +0 -228
  49. package/dist/evaluator.d.cts +0 -12
  50. package/dist/functions.cjs +0 -4
  51. package/dist/functions.d.cts +0 -12
  52. package/dist/index.cjs +0 -97
  53. package/dist/index.d.cts +0 -18
  54. package/dist/input-resolvers.cjs +0 -109
  55. package/dist/input-resolvers.d.cts +0 -22
  56. package/dist/integer-power.cjs +0 -19
  57. package/dist/integer-power.d.cts +0 -11
  58. package/dist/json-value.cjs +0 -12
  59. package/dist/json-value.d.cts +0 -8
  60. package/dist/plain-record.cjs +0 -7
  61. package/dist/plain-record.d.cts +0 -2
  62. package/dist/resolvers.cjs +0 -0
  63. package/dist/resolvers.d.cts +0 -54
  64. package/dist/tree.cjs +0 -332
  65. package/dist/tree.d.cts +0 -446
package/dist/complex.cjs DELETED
@@ -1,35 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- // src/complex.ts
3
- const complexFromPolar = (magnitude, phase, unit) => ({
4
- kind: "complex",
5
- re: magnitude * Math.cos(phase),
6
- im: magnitude * Math.sin(phase),
7
- unit
8
- });
9
- /** The `complexLiteral` node counterpart of `complexFromPolar`, for authoring a tree in polar terms; the conversion itself is done once, there, rather than repeated here. */
10
- const complexLiteralFromPolar = (magnitude, phase, unit) => {
11
- const { re, im } = complexFromPolar(magnitude, phase, unit);
12
- return {
13
- kind: "complexLiteral",
14
- re,
15
- im,
16
- unit
17
- };
18
- };
19
- /** |z|, as a real number in the same unit the complex value itself carries -- the magnitude of an impedance in ohms is a real quantity in ohms. */
20
- const complexMagnitude = (value) => ({
21
- kind: "number",
22
- value: Math.hypot(value.re, value.im),
23
- unit: value.unit
24
- });
25
- /**
26
- * arg(z), as a dimensionless real number of radians: an angle is a ratio of two lengths, so it carries no unit of its own regardless of what the value it was read from carried. The range is [-pi, pi]: `Math.atan2` returns -pi for a negative real number whose imaginary part is `-0` and +pi when it is `+0`, although the two are the same number and JSON writes both zeros as `0`, and the closed range is what the result can be because a tiny negative imaginary part also rounds to exactly -pi (`phase(-1 - 1e-17i)` is -pi, the true angle being a hair inside). Adding `+0` turns `-0` into `+0` without changing any other value, so a signed zero never gives -pi: a negative real number is +pi whatever the sign of its zero, and zero is 0.
27
- */
28
- const complexPhase = (value) => ({
29
- kind: "number",
30
- value: Math.atan2(value.im + 0, value.re + 0)
31
- });
32
- exports.complexFromPolar = complexFromPolar;
33
- exports.complexLiteralFromPolar = complexLiteralFromPolar;
34
- exports.complexMagnitude = complexMagnitude;
35
- exports.complexPhase = complexPhase;
@@ -1,23 +0,0 @@
1
- import { ComputedValue, Unit } from "./computed-value.cjs";
2
- import { ComplexLiteralNode } from "./tree.cjs";
3
- /**
4
- * The `complex` computed-value kind stores one canonical representation, rectangular (`re` + `im`i), with no `form` discriminant offering a polar alternative alongside it -- see the "Complex values" section of README.md for the reasoning. These four helpers are what keep the magnitude-and-phase view reachable for the domains that reason that way, as conversions at the edges rather than a second encoding of the same value that every operator would then have to branch on.
5
- *
6
- * Phase is in radians throughout, measured from the positive real axis, in the range [-pi, pi] that `complexPhase` below states, which differs from `Math.atan2`'s only for a zero imaginary part of either sign.
7
- */
8
- type ComplexValue = Extract<ComputedValue, {
9
- kind: "complex";
10
- }>;
11
- type NumberValue = Extract<ComputedValue, {
12
- kind: "number";
13
- }>;
14
- export declare const complexFromPolar: (magnitude: number, phase: number, unit?: Unit) => ComplexValue;
15
- /** The `complexLiteral` node counterpart of `complexFromPolar`, for authoring a tree in polar terms; the conversion itself is done once, there, rather than repeated here. */
16
- export declare const complexLiteralFromPolar: (magnitude: number, phase: number, unit?: Unit) => ComplexLiteralNode;
17
- /** |z|, as a real number in the same unit the complex value itself carries -- the magnitude of an impedance in ohms is a real quantity in ohms. */
18
- export declare const complexMagnitude: (value: ComplexValue) => NumberValue;
19
- /**
20
- * arg(z), as a dimensionless real number of radians: an angle is a ratio of two lengths, so it carries no unit of its own regardless of what the value it was read from carried. The range is [-pi, pi]: `Math.atan2` returns -pi for a negative real number whose imaginary part is `-0` and +pi when it is `+0`, although the two are the same number and JSON writes both zeros as `0`, and the closed range is what the result can be because a tiny negative imaginary part also rounds to exactly -pi (`phase(-1 - 1e-17i)` is -pi, the true angle being a hair inside). Adding `+0` turns `-0` into `+0` without changing any other value, so a signed zero never gives -pi: a negative real number is +pi whatever the sign of its zero, and zero is 0.
21
- */
22
- export declare const complexPhase: (value: ComplexValue) => NumberValue;
23
- export {};
@@ -1,80 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- let zod = require("zod");
3
- // src/computed-value.ts
4
- /** Dimension symbol -\> exponent, e.g. `{ m: 1, s: -1 }` for metres per second. A bare symbol like `"kg"` is shorthand for `{ kg: 1 }`. */
5
- const UnitSchema = zod.z.record(zod.z.string(), zod.z.number());
6
- const DurationUnitSchema = zod.z.enum([
7
- "ms",
8
- "s",
9
- "min",
10
- "h",
11
- "d"
12
- ]);
13
- const ComputedValueSchema = zod.z.discriminatedUnion("kind", [
14
- zod.z.object({
15
- kind: zod.z.literal("number"),
16
- value: zod.z.number(),
17
- unit: UnitSchema.optional()
18
- }),
19
- zod.z.object({
20
- kind: zod.z.literal("text"),
21
- value: zod.z.string()
22
- }),
23
- zod.z.object({
24
- kind: zod.z.literal("boolean"),
25
- value: zod.z.boolean()
26
- }),
27
- zod.z.object({
28
- kind: zod.z.literal("instant"),
29
- value: zod.z.string()
30
- }),
31
- zod.z.object({
32
- kind: zod.z.literal("duration"),
33
- value: zod.z.number(),
34
- unit: DurationUnitSchema
35
- }),
36
- zod.z.object({
37
- kind: zod.z.literal("complex"),
38
- re: zod.z.number(),
39
- im: zod.z.number(),
40
- unit: UnitSchema.optional()
41
- })
42
- ]);
43
- /** Drops zero-exponent dimensions so that, e.g., dividing a unit by itself normalises to the same dimensionless `{}` as an absent unit -- without this, `{ m: 0 }` and `{}` would compare unequal despite representing the same dimension. */
44
- function normalizeUnit(unit) {
45
- if (unit === void 0) return {};
46
- const normalized = {};
47
- for (const [dimension, exponent] of Object.entries(unit)) if (exponent !== 0) normalized[dimension] = exponent;
48
- return normalized;
49
- }
50
- /** An operand with no `unit` is dimensionless (an empty map) for comparison purposes. */
51
- function unitsEqual(a, b) {
52
- const normalizedA = normalizeUnit(a);
53
- const normalizedB = normalizeUnit(b);
54
- const dimensionsA = Object.keys(normalizedA);
55
- const dimensionsB = Object.keys(normalizedB);
56
- if (dimensionsA.length !== dimensionsB.length) return false;
57
- return dimensionsA.every((dimension) => normalizedA[dimension] === normalizedB[dimension]);
58
- }
59
- /** Multiplying two unit-tagged numbers adds exponents per dimension. An operand with no `unit` is treated as dimensionless (an empty map). */
60
- function combineUnitsForMultiply(a, b) {
61
- const normalizedA = normalizeUnit(a);
62
- const normalizedB = normalizeUnit(b);
63
- const combined = { ...normalizedA };
64
- for (const [dimension, exponent] of Object.entries(normalizedB)) combined[dimension] = (combined[dimension] ?? 0) + exponent;
65
- return normalizeUnit(combined);
66
- }
67
- /** Dividing two unit-tagged numbers subtracts exponents per dimension. An operand with no `unit` is treated as dimensionless (an empty map). */
68
- function combineUnitsForDivide(a, b) {
69
- const normalizedA = normalizeUnit(a);
70
- const normalizedB = normalizeUnit(b);
71
- const combined = { ...normalizedA };
72
- for (const [dimension, exponent] of Object.entries(normalizedB)) combined[dimension] = (combined[dimension] ?? 0) - exponent;
73
- return normalizeUnit(combined);
74
- }
75
- exports.ComputedValueSchema = ComputedValueSchema;
76
- exports.DurationUnitSchema = DurationUnitSchema;
77
- exports.UnitSchema = UnitSchema;
78
- exports.combineUnitsForDivide = combineUnitsForDivide;
79
- exports.combineUnitsForMultiply = combineUnitsForMultiply;
80
- exports.unitsEqual = unitsEqual;
@@ -1,48 +0,0 @@
1
- import { z } from "zod";
2
- /** Dimension symbol -\> exponent, e.g. `{ m: 1, s: -1 }` for metres per second. A bare symbol like `"kg"` is shorthand for `{ kg: 1 }`. */
3
- export declare const UnitSchema: z.ZodRecord<z.ZodString, z.ZodNumber>;
4
- export type Unit = z.infer<typeof UnitSchema>;
5
- export declare const DurationUnitSchema: z.ZodEnum<{
6
- ms: "ms";
7
- s: "s";
8
- min: "min";
9
- h: "h";
10
- d: "d";
11
- }>;
12
- export type DurationUnit = z.infer<typeof DurationUnitSchema>;
13
- export declare const ComputedValueSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
14
- kind: z.ZodLiteral<"number">;
15
- value: z.ZodNumber;
16
- unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
17
- }, z.core.$strip>, z.ZodObject<{
18
- kind: z.ZodLiteral<"text">;
19
- value: z.ZodString;
20
- }, z.core.$strip>, z.ZodObject<{
21
- kind: z.ZodLiteral<"boolean">;
22
- value: z.ZodBoolean;
23
- }, z.core.$strip>, z.ZodObject<{
24
- kind: z.ZodLiteral<"instant">;
25
- value: z.ZodString;
26
- }, z.core.$strip>, z.ZodObject<{
27
- kind: z.ZodLiteral<"duration">;
28
- value: z.ZodNumber;
29
- unit: z.ZodEnum<{
30
- ms: "ms";
31
- s: "s";
32
- min: "min";
33
- h: "h";
34
- d: "d";
35
- }>;
36
- }, z.core.$strip>, z.ZodObject<{
37
- kind: z.ZodLiteral<"complex">;
38
- re: z.ZodNumber;
39
- im: z.ZodNumber;
40
- unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
41
- }, z.core.$strip>], "kind">;
42
- export type ComputedValue = z.infer<typeof ComputedValueSchema>;
43
- /** An operand with no `unit` is dimensionless (an empty map) for comparison purposes. */
44
- export declare function unitsEqual(a: Unit | undefined, b: Unit | undefined): boolean;
45
- /** Multiplying two unit-tagged numbers adds exponents per dimension. An operand with no `unit` is treated as dimensionless (an empty map). */
46
- export declare function combineUnitsForMultiply(a: Unit | undefined, b: Unit | undefined): Unit;
47
- /** Dividing two unit-tagged numbers subtracts exponents per dimension. An operand with no `unit` is treated as dimensionless (an empty map). */
48
- export declare function combineUnitsForDivide(a: Unit | undefined, b: Unit | undefined): Unit;
@@ -1,73 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- // src/derived-aggregates.ts
3
- /**
4
- * `sum`, `count`, and `average` are never their own `FoldCombiner` mode -- each is a builder function that assembles an ordinary `fold` (and, for `average`, one `arithmetic` division of two ordinary folds), exactly the same treatment `derived-connectives.ts` already gives `xor`/`nand`/`nor`/`implies`/`iff`/`none` (see the "Derived aggregates" section of README.md).
5
- */
6
- const sum = (collection, item, filter) => ({
7
- kind: "fold",
8
- collection,
9
- filter,
10
- combiner: {
11
- mode: "reduce",
12
- initial: {
13
- kind: "numberLiteral",
14
- value: 0
15
- },
16
- combine: {
17
- kind: "arithmetic",
18
- op: "add",
19
- left: { kind: "accumulator" },
20
- right: item
21
- }
22
- }
23
- });
24
- const presenceOf = (probe) => ({
25
- kind: "conditional",
26
- cases: [{
27
- when: {
28
- kind: "memberOf",
29
- op: "in",
30
- operand: probe,
31
- candidates: [probe]
32
- },
33
- then: {
34
- kind: "numberLiteral",
35
- value: 1
36
- }
37
- }],
38
- fallback: {
39
- kind: "numberLiteral",
40
- value: 0
41
- }
42
- });
43
- const count = (collection, filter, probe) => ({
44
- kind: "fold",
45
- collection,
46
- filter,
47
- combiner: {
48
- mode: "reduce",
49
- initial: {
50
- kind: "numberLiteral",
51
- value: 0
52
- },
53
- combine: {
54
- kind: "arithmetic",
55
- op: "add",
56
- left: { kind: "accumulator" },
57
- right: probe ? presenceOf(probe) : {
58
- kind: "numberLiteral",
59
- value: 1
60
- }
61
- }
62
- }
63
- });
64
- const average = (collection, item, filter) => ({
65
- kind: "arithmetic",
66
- op: "divide",
67
- left: sum(collection, item, filter),
68
- right: count(collection, filter)
69
- });
70
- exports.average = average;
71
- exports.count = count;
72
- exports.presenceOf = presenceOf;
73
- exports.sum = sum;
@@ -1,9 +0,0 @@
1
- import { JsonValue } from "./json-value.cjs";
2
- import { ExpressionNode, PredicateNode } from "./tree.cjs";
3
- /**
4
- * `sum`, `count`, and `average` are never their own `FoldCombiner` mode -- each is a builder function that assembles an ordinary `fold` (and, for `average`, one `arithmetic` division of two ordinary folds), exactly the same treatment `derived-connectives.ts` already gives `xor`/`nand`/`nor`/`implies`/`iff`/`none` (see the "Derived aggregates" section of README.md).
5
- */
6
- export declare const sum: (collection: JsonValue, item: ExpressionNode, filter?: PredicateNode) => ExpressionNode;
7
- export declare const presenceOf: (probe: ExpressionNode) => ExpressionNode;
8
- export declare const count: (collection: JsonValue, filter?: PredicateNode, probe?: ExpressionNode) => ExpressionNode;
9
- export declare const average: (collection: JsonValue, item: ExpressionNode, filter?: PredicateNode) => ExpressionNode;
@@ -1,39 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- // src/derived-connectives.ts
3
- /**
4
- * `not`/`and`/`or` are the primitive `PredicateNode` object-constructors -- everything else in this file is built purely by composing these three, so its three-valued correctness is inherited from the already-verified AND/OR/NOT tables rather than requiring a separate proof (see the "Derived connectives" section of README.md).
5
- */
6
- const not = (a) => ({
7
- kind: "not",
8
- operand: a
9
- });
10
- const and = (a, b) => ({
11
- kind: "and",
12
- left: a,
13
- right: b
14
- });
15
- const or = (a, b) => ({
16
- kind: "or",
17
- left: a,
18
- right: b
19
- });
20
- const xor = (a, b) => or(and(a, not(b)), and(not(a), b));
21
- const nand = (a, b) => not(and(a, b));
22
- const nor = (a, b) => not(or(a, b));
23
- const implies = (a, b) => or(not(a), b);
24
- const iff = (a, b) => not(xor(a, b));
25
- const none = (collection, item, filter) => not({
26
- kind: "some",
27
- collection,
28
- item,
29
- filter
30
- });
31
- exports.and = and;
32
- exports.iff = iff;
33
- exports.implies = implies;
34
- exports.nand = nand;
35
- exports.none = none;
36
- exports.nor = nor;
37
- exports.not = not;
38
- exports.or = or;
39
- exports.xor = xor;
@@ -1,14 +0,0 @@
1
- import { JsonValue } from "./json-value.cjs";
2
- import { PredicateNode } from "./tree.cjs";
3
- /**
4
- * `not`/`and`/`or` are the primitive `PredicateNode` object-constructors -- everything else in this file is built purely by composing these three, so its three-valued correctness is inherited from the already-verified AND/OR/NOT tables rather than requiring a separate proof (see the "Derived connectives" section of README.md).
5
- */
6
- export declare const not: (a: PredicateNode) => PredicateNode;
7
- export declare const and: (a: PredicateNode, b: PredicateNode) => PredicateNode;
8
- export declare const or: (a: PredicateNode, b: PredicateNode) => PredicateNode;
9
- export declare const xor: (a: PredicateNode, b: PredicateNode) => PredicateNode;
10
- export declare const nand: (a: PredicateNode, b: PredicateNode) => PredicateNode;
11
- export declare const nor: (a: PredicateNode, b: PredicateNode) => PredicateNode;
12
- export declare const implies: (a: PredicateNode, b: PredicateNode) => PredicateNode;
13
- export declare const iff: (a: PredicateNode, b: PredicateNode) => PredicateNode;
14
- export declare const none: (collection: JsonValue, item: PredicateNode, filter?: PredicateNode) => PredicateNode;
@@ -1,93 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- // src/derived-patterns.ts
3
- /**
4
- * `prefixPattern`/`wildcardPattern`/`hierarchicalGlobPattern` are never their own node kind and add no evaluator branch -- each is a builder function that compiles its pattern string into a portable regular-expression string and assembles an ordinary `textCompare` node with `op: "matches"` around it, exactly the same treatment `derived-connectives.ts`/`derived-aggregates.ts`/`derived-values.ts` already give `xor`/`sum`/`coalesce` (see the "Pattern-matching builders" section of README.md). The compilation happens once, when the tree is built, so what is stored and evaluated is an ordinary `textCompare` tree indistinguishable from one written out by hand.
5
- */
6
- /** The characters a compiled pattern must backslash-escape to match literally. Deliberately exactly ECMAScript's own `SyntaxCharacter` set plus `/`: those are the only escapes that stay valid under a `u`/`v`-flagged `RegExp` as well as an unflagged one, so a compiled pattern string remains usable however a consumer chooses to compile it -- including pasted verbatim into a `/.../` literal, which is what `/` earns its place for. Escaping anything outside this set (a quote, say) would be inert under the evaluator's own unflagged `new RegExp` but a `SyntaxError` under `u`. */
7
- const REGEX_SYNTAX_CHARACTERS = "^$\\.*+?()[]{}|/";
8
- /** `[\s\S]*` rather than `.*` because the compiled string carries no flags of its own: `.` excludes line terminators unless the `s` flag is set, and `textCompare`'s evaluator compiles the pattern with `new RegExp(right.value)` and no flags at all. A character class covering both `\s` and `\S` is the flag-free spelling of "any character", so the same string behaves identically wherever it is compiled. */
9
- const ANY_CHARACTERS = "[\\s\\S]*";
10
- /** A hierarchical glob's single `*`: any run of characters that stays inside one `/`-delimited segment. The separator is written `\/` rather than a bare `/` because `v`-mode reserves `/` as a `ClassSetReservedPunctuator` and rejects it unescaped inside a character class -- a bare `[^/]` is a `SyntaxError` under `v`, while `[^\/]` compiles identically under `v`, `u` and no flags at all, which is the portability `REGEX_SYNTAX_CHARACTERS` already promises for every literal character. */
11
- const ANY_CHARACTERS_WITHIN_SEGMENT = "[^\\/]*";
12
- /** A hierarchical glob's `?`: exactly one character, still constrained to a single segment. Escaped for the same `v`-mode reason as `ANY_CHARACTERS_WITHIN_SEGMENT` above. */
13
- const ANY_CHARACTER_WITHIN_SEGMENT = "[^\\/]";
14
- function escapeRegexLiteral(character) {
15
- return REGEX_SYNTAX_CHARACTERS.includes(character) ? `\\${character}` : character;
16
- }
17
- /** A prefix match that respects word boundaries: the subject is either the prefix exactly, or the prefix followed by a space and anything at all. `"ls"` therefore matches `"ls"` and `"ls -la"` but never `"lsof"`. The prefix itself is a plain literal -- every character in it is escaped, so it carries no wildcard or escape syntax of its own. */
18
- function compilePrefixPattern(prefix) {
19
- return `^${Array.from(prefix, escapeRegexLiteral).join("")}(?: ${ANY_CHARACTERS})?$`;
20
- }
21
- /**
22
- * A flat wildcard dialect with no notion of path segments: an unescaped `*` matches any run of characters, `\*` matches a literal asterisk, and `\\` matches a literal backslash. Compiled in a single left-to-right pass rather than by successive `String.replace` phases over sentinel placeholders, so a pattern containing whatever string a sentinel happened to use cannot be corrupted by its own restoration step.
23
- *
24
- * The trailing-single-wildcard convenience is the one non-obvious rule: a pattern whose only wildcard is a trailing `" *"` also matches the bare prefix, so `"git *"` matches `"git"` as well as `"git add file"`. It applies only when that wildcard is the pattern's sole unescaped one -- `"git * *"` keeps requiring both.
25
- */
26
- function compileWildcardPattern(pattern) {
27
- const trimmed = pattern.trim();
28
- let compiled = "";
29
- let unescapedWildcards = 0;
30
- let index = 0;
31
- while (index < trimmed.length) {
32
- const character = trimmed.charAt(index);
33
- if (character === "\\" && index + 1 < trimmed.length) {
34
- const next = trimmed.charAt(index + 1);
35
- if (next === "*" || next === "\\") {
36
- compiled += `\\${next}`;
37
- index += 2;
38
- continue;
39
- }
40
- }
41
- if (character === "*") {
42
- compiled += ANY_CHARACTERS;
43
- unescapedWildcards += 1;
44
- index += 1;
45
- continue;
46
- }
47
- compiled += escapeRegexLiteral(character);
48
- index += 1;
49
- }
50
- if (unescapedWildcards === 1 && trimmed.endsWith(" *")) compiled = `${compiled.slice(0, -8)}(?: ${ANY_CHARACTERS})?`;
51
- return `^${compiled}$`;
52
- }
53
- /** A hierarchy-aware glob dialect, distinct from `compileWildcardPattern`'s flat one and never mixed with it: `*` matches within a single `/`-delimited segment, `**` matches across segments, and `?` matches one character within a segment. `**` is consumed as a unit during the same left-to-right pass, so an odd run such as `"***"` reads as `**` followed by `*` -- exactly what successive-replacement would produce, without needing a placeholder to survive between passes. This dialect has no escape syntax: a backslash in the pattern is a literal backslash. */
54
- function compileHierarchicalGlobPattern(pattern) {
55
- let compiled = "";
56
- let index = 0;
57
- while (index < pattern.length) {
58
- const character = pattern.charAt(index);
59
- if (character === "*") {
60
- if (pattern.charAt(index + 1) === "*") {
61
- compiled += ANY_CHARACTERS;
62
- index += 2;
63
- continue;
64
- }
65
- compiled += ANY_CHARACTERS_WITHIN_SEGMENT;
66
- index += 1;
67
- continue;
68
- }
69
- if (character === "?") {
70
- compiled += ANY_CHARACTER_WITHIN_SEGMENT;
71
- index += 1;
72
- continue;
73
- }
74
- compiled += escapeRegexLiteral(character);
75
- index += 1;
76
- }
77
- return `^${compiled}$`;
78
- }
79
- const matchesCompiledPattern = (text, compiled) => ({
80
- kind: "textCompare",
81
- op: "matches",
82
- left: text,
83
- right: {
84
- kind: "textLiteral",
85
- value: compiled
86
- }
87
- });
88
- const prefixPattern = (text, prefix) => matchesCompiledPattern(text, compilePrefixPattern(prefix));
89
- const wildcardPattern = (text, pattern) => matchesCompiledPattern(text, compileWildcardPattern(pattern));
90
- const hierarchicalGlobPattern = (text, pattern) => matchesCompiledPattern(text, compileHierarchicalGlobPattern(pattern));
91
- exports.hierarchicalGlobPattern = hierarchicalGlobPattern;
92
- exports.prefixPattern = prefixPattern;
93
- exports.wildcardPattern = wildcardPattern;
@@ -1,4 +0,0 @@
1
- import { ExpressionNode, PredicateNode } from "./tree.cjs";
2
- export declare const prefixPattern: (text: ExpressionNode, prefix: string) => PredicateNode;
3
- export declare const wildcardPattern: (text: ExpressionNode, pattern: string) => PredicateNode;
4
- export declare const hierarchicalGlobPattern: (text: ExpressionNode, pattern: string) => PredicateNode;
@@ -1,23 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- // src/derived-values.ts
3
- /**
4
- * `coalesce` is never its own evaluated node kind -- it assembles an ordinary `conditional` whose single case's `when` is an `exists` probe of the current candidate, the same "derived = composition, not new logic" treatment derived-connectives.ts and derived-aggregates.ts already give `xor`/`sum`/`average` (see the "Derived values" section of README.md). Falling through to the next candidate happens only on `exists`'s own `false` -- a genuinely absent value (`not-found`) -- never on a candidate that resolved to something unusable (`wrong-type`/`domain-error`): `exists` already draws exactly that line (see the `exists` section of README.md), and `coalesce` inherits it unmodified rather than re-deciding it. A candidate that is `not-yet-known` (a resolver reported it as not yet supplied) is not a known absence, so `exists` is indeterminate on it and the whole `coalesce` stays indeterminate: falling through would answer with a later candidate that the earlier one's arrival could displace.
5
- *
6
- * Built right-to-left over the full `[first, second, ...rest]` candidate list via `reduceRight`, which needs no seed value here -- `first`/`second` being required arguments (rather than accepting a single `ExpressionNode[]`) guarantees the list always has at least two elements, so the no-initial-value overload of `reduceRight` never hits an empty array.
7
- */
8
- const coalesce = (first, second, ...rest) => [
9
- first,
10
- second,
11
- ...rest
12
- ].reduceRight((fallback, candidate) => ({
13
- kind: "conditional",
14
- cases: [{
15
- when: {
16
- kind: "exists",
17
- operand: candidate
18
- },
19
- then: candidate
20
- }],
21
- fallback
22
- }));
23
- exports.coalesce = coalesce;
@@ -1,7 +0,0 @@
1
- import { ExpressionNode } from "./tree.cjs";
2
- /**
3
- * `coalesce` is never its own evaluated node kind -- it assembles an ordinary `conditional` whose single case's `when` is an `exists` probe of the current candidate, the same "derived = composition, not new logic" treatment derived-connectives.ts and derived-aggregates.ts already give `xor`/`sum`/`average` (see the "Derived values" section of README.md). Falling through to the next candidate happens only on `exists`'s own `false` -- a genuinely absent value (`not-found`) -- never on a candidate that resolved to something unusable (`wrong-type`/`domain-error`): `exists` already draws exactly that line (see the `exists` section of README.md), and `coalesce` inherits it unmodified rather than re-deciding it. A candidate that is `not-yet-known` (a resolver reported it as not yet supplied) is not a known absence, so `exists` is indeterminate on it and the whole `coalesce` stays indeterminate: falling through would answer with a later candidate that the earlier one's arrival could displace.
4
- *
5
- * Built right-to-left over the full `[first, second, ...rest]` candidate list via `reduceRight`, which needs no seed value here -- `first`/`second` being required arguments (rather than accepting a single `ExpressionNode[]`) guarantees the list always has at least two elements, so the no-initial-value overload of `reduceRight` never hits an empty array.
6
- */
7
- export declare const coalesce: (first: ExpressionNode, second: ExpressionNode, ...rest: readonly ExpressionNode[]) => ExpressionNode;