tyneq / OperatorRegistry
Class: OperatorRegistry
Defined in: src/core/registry/TyneqOperatorRegistry.ts:35
Central registry for all Tyneq operators.
Every registration path - @operator, @terminal, createOperator, createGeneratorOperator, createTerminalOperator - flows through this class. It is the single source of truth for which operators exist, their kind, and their prototype-level implementation.
Internally the registry maintains two separate namespaces:
- Source factories (
Tyneq.from,Tyneq.range, etc.) - keyed by name alone. - Instance operators (
.where,.select, etc.) - keyed by (name, targetClass).
This means a source factory and an instance method can share a name without conflict (e.g. Tyneq.concat and seq.concat), and two instance operators with the same name on different prototype chains (e.g. ordered.foo and cached.foo) also coexist without conflict.
Example
import { OperatorRegistry } from "tyneq/plugin";
OperatorRegistry.has("where"); // -> true
OperatorRegistry.list(); // -> OperatorMetadata[]Classes
registerSource()
staticregisterSource(name,factory,source?):void
Defined in: src/core/registry/TyneqOperatorRegistry.ts:344
Registers a source operator (a static factory, not a prototype method).
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
name | string | undefined | The operator name, matching the operatorName on the QueryPlanNode. |
factory | (...args) => unknown | undefined | The factory function; receives the node args in order, this is null. |
source | OperatorSource | "external" | Whether this is a built-in or external source operator. Defaults to "external". |
Returns
void
Remarks
Source operators differ from prototype operators in two ways:
- They are called with
nullasthis- they have no instance. - They are looked up by the compiler via getSource rather than being patched onto a prototype.
The entry is stored in the source namespace and is never patched onto any prototype. Registration guards run for "external" sources (same policy as register). Guards are skipped for "internal" sources (same policy used for internal builtins).
Third-party source operators registered here are automatically compiled by QueryPlanCompiler without any changes to the compiler.
Example
import { OperatorRegistry } from "tyneq/plugin";
import { Tyneq } from "tyneq";
OperatorRegistry.registerSource("fibonacci", (count) => {
// return a Tyneq sequence of fibonacci numbers
});Constructors
Constructor
new OperatorRegistry():
OperatorRegistry
Returns
OperatorRegistry
Methods
register()
staticregister(input):void
Defined in: src/core/registry/TyneqOperatorRegistry.ts:47
Registers an operator entry and patches the method onto entry.metadata.targetClass.prototype.
Parameters
| Parameter | Type |
|---|---|
input | OperatorEntry |
Returns
void
Throws
When an operator with the same name is already registered on the same targetClass.
unregister()
staticunregister(name):boolean
Defined in: src/core/registry/TyneqOperatorRegistry.ts:98
Removes an operator registration and deletes the prototype method for external operators.
Checks the instance operator namespace first, then the source namespace.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
boolean
true if the operator was found and removed; false if no operator with that name existed.
Remarks
Internal operators (source "internal") are not removed from the prototype - only their registry entry is deleted.
For targeted removal use unregisterOperator or unregisterSource.
unregisterOperator()
staticunregisterOperator(name,targetClass):boolean
Defined in: src/core/registry/TyneqOperatorRegistry.ts:125
Removes a specific instance operator registration for a given (name, targetClass) pair and deletes the prototype method for external operators.
Parameters
| Parameter | Type |
|---|---|
name | string |
targetClass | SequenceConstructor |
Returns
boolean
true if the entry was found and removed; false otherwise.
unregisterSource()
staticunregisterSource(name):boolean
Defined in: src/core/registry/TyneqOperatorRegistry.ts:149
Removes a source factory registration.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
boolean
true if the source was found and removed; false otherwise.
onRegister()
staticonRegister(hook): () =>void
Defined in: src/core/registry/TyneqOperatorRegistry.ts:158
Registers a hook called after every successful operator registration (both namespaces).
Parameters
| Parameter | Type |
|---|---|
hook | (entry) => void |
Returns
A function that removes the hook when called.
():
void
Returns
void
addGuard()
staticaddGuard(guard): () =>void
Defined in: src/core/registry/TyneqOperatorRegistry.ts:172
Registers a guard called before every registration (both namespaces). Throw from the guard to reject the registration.
Parameters
| Parameter | Type |
|---|---|
guard | (entry) => void |
Returns
A function that removes the guard when called.
():
void
Returns
void
has()
statichas(name):boolean
Defined in: src/core/registry/TyneqOperatorRegistry.ts:184
Returns true if a name exists in either the source or instance operator namespace. Use hasSource or hasOperator for namespace-specific checks.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
boolean
hasSource()
statichasSource(name):boolean
Defined in: src/core/registry/TyneqOperatorRegistry.ts:191
Returns true if a source factory with name is registered.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
boolean
hasOperator()
statichasOperator(name,targetClass?):boolean
Defined in: src/core/registry/TyneqOperatorRegistry.ts:200
Returns true if an instance operator with name is registered. When targetClass is provided, checks only that specific (name, targetClass) pair. When omitted, returns true if any target has an operator with that name.
Parameters
| Parameter | Type |
|---|---|
name | string |
targetClass? | SequenceConstructor |
Returns
boolean
get()
staticget(name):Maybe<OperatorEntry>
Defined in: src/core/registry/TyneqOperatorRegistry.ts:213
Returns the operator entry for name from either namespace, or undefined if not found. Checks the instance operator namespace first, then the source namespace. For namespace-specific retrieval use getSource or getOperator.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
getSource()
staticgetSource(name):Maybe<OperatorEntry>
Defined in: src/core/registry/TyneqOperatorRegistry.ts:226
Returns the source factory entry for name, or undefined if not registered.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
getOperator()
staticgetOperator(name,targetClass?):Maybe<OperatorEntry>
Defined in: src/core/registry/TyneqOperatorRegistry.ts:234
Returns the instance operator entry for name on targetClass, or undefined. When targetClass is omitted, returns the first entry found across all targets.
Parameters
| Parameter | Type |
|---|---|
name | string |
targetClass? | SequenceConstructor |
Returns
getMetadata()
staticgetMetadata(name):Maybe<OperatorMetadata>
Defined in: src/core/registry/TyneqOperatorRegistry.ts:251
Returns the metadata for name from either namespace, or undefined if not found. Checks instance operators first, then sources.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
list()
staticlist(): readonlyOperatorMetadata[]
Defined in: src/core/registry/TyneqOperatorRegistry.ts:259
Returns metadata for all registered operators and source factories. Use listOperators or listSources for namespace-specific lists.
Returns
readonly OperatorMetadata[]
listSources()
staticlistSources(): readonlyOperatorMetadata[]
Defined in: src/core/registry/TyneqOperatorRegistry.ts:266
Returns metadata for all registered source factories.
Returns
readonly OperatorMetadata[]
listOperators()
staticlistOperators(targetClass?): readonlyOperatorMetadata[]
Defined in: src/core/registry/TyneqOperatorRegistry.ts:274
Returns metadata for all registered instance operators. When targetClass is provided, returns only entries for that specific target class.
Parameters
| Parameter | Type |
|---|---|
targetClass? | SequenceConstructor |
Returns
readonly OperatorMetadata[]
listByKind()
staticlistByKind(kind): readonlyOperatorMetadata[]
Defined in: src/core/registry/TyneqOperatorRegistry.ts:293
Returns metadata for all operators of kind across both namespaces.
Parameters
| Parameter | Type |
|---|---|
kind | OperatorKind |
Returns
readonly OperatorMetadata[]
listBySource()
staticlistBySource(source): readonlyOperatorMetadata[]
Defined in: src/core/registry/TyneqOperatorRegistry.ts:298
Returns metadata for all operators from source across both namespaces.
Parameters
| Parameter | Type |
|---|---|
source | OperatorSource |
Returns
readonly OperatorMetadata[]
count()
staticcount():number
Defined in: src/core/registry/TyneqOperatorRegistry.ts:303
Returns the total number of registered operators across both namespaces.
Returns
number