index
index<
T>(entries,opts?):Registry<T>
Build the reverse index over labeled pattern-sets. Retains entry order and compiles each entry’s patterns once, up front.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type | Description |
|---|---|---|
T | string | The id type, inferred from entries. |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
entries | Iterable<Labeled<T>> | The labeled pattern-sets to index, in significant order. |
opts? | Options | Matching semantics (Options) applied to every entry. |
Returns
Section titled “Returns”Registry<T>
A Registry whose queries echo matching ids in registration order.
Throws
Section titled “Throws”Error duplicate registry id '<id>' if any id is supplied twice —
rejected at construction rather than silently keeping first or last.
Remarks
Section titled “Remarks”Registration order is significant and preserved: register general-to-specific and read a query result as a prioritization (first = most general, last = most specific). Intersect returns the order; the caller picks the precedence rule. Pure — target paths need not exist.
Examples
Section titled “Examples”const guidelines = index([ { id: "guidelines/api", patterns: ["src/api/**"] }, { id: "guidelines/db", patterns: ["src/db/**"] },]);
guidelines.applicableTo("src/api/**"); // ["guidelines/api"] — db does not overlapguidelines.matching("src/db/pool.ts"); // ["guidelines/db"]Duplicate ids throw at construction:
index([ { id: "a", patterns: ["src/**"] }, { id: "a", patterns: ["docs/**"] }, // same id, registered twice]);// → Error: duplicate registry id 'a'