Skip to content

tyneq


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

ts
import { OperatorRegistry } from "tyneq/plugin";

OperatorRegistry.has("where"); // -> true
OperatorRegistry.list(); // -> OperatorMetadata[]

Classes

registerSource()

static registerSource(name, factory, source?): void

Defined in: src/core/registry/TyneqOperatorRegistry.ts:344

Registers a source operator (a static factory, not a prototype method).

Parameters

ParameterTypeDefault valueDescription
namestringundefinedThe operator name, matching the operatorName on the QueryPlanNode.
factory(...args) => unknownundefinedThe factory function; receives the node args in order, this is null.
sourceOperatorSource"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 null as this - 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

ts
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()

static register(input): void

Defined in: src/core/registry/TyneqOperatorRegistry.ts:47

Registers an operator entry and patches the method onto entry.metadata.targetClass.prototype.

Parameters

ParameterType
inputOperatorEntry

Returns

void

Throws

When an operator with the same name is already registered on the same targetClass.


unregister()

static unregister(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

ParameterType
namestring

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()

static unregisterOperator(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

ParameterType
namestring
targetClassSequenceConstructor

Returns

boolean

true if the entry was found and removed; false otherwise.


unregisterSource()

static unregisterSource(name): boolean

Defined in: src/core/registry/TyneqOperatorRegistry.ts:149

Removes a source factory registration.

Parameters

ParameterType
namestring

Returns

boolean

true if the source was found and removed; false otherwise.


onRegister()

static onRegister(hook): () => void

Defined in: src/core/registry/TyneqOperatorRegistry.ts:158

Registers a hook called after every successful operator registration (both namespaces).

Parameters

ParameterType
hook(entry) => void

Returns

A function that removes the hook when called.

(): void

Returns

void


addGuard()

static addGuard(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

ParameterType
guard(entry) => void

Returns

A function that removes the guard when called.

(): void

Returns

void


has()

static has(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

ParameterType
namestring

Returns

boolean


hasSource()

static hasSource(name): boolean

Defined in: src/core/registry/TyneqOperatorRegistry.ts:191

Returns true if a source factory with name is registered.

Parameters

ParameterType
namestring

Returns

boolean


hasOperator()

static hasOperator(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

ParameterType
namestring
targetClass?SequenceConstructor

Returns

boolean


get()

static get(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

ParameterType
namestring

Returns

Maybe<OperatorEntry>


getSource()

static getSource(name): Maybe<OperatorEntry>

Defined in: src/core/registry/TyneqOperatorRegistry.ts:226

Returns the source factory entry for name, or undefined if not registered.

Parameters

ParameterType
namestring

Returns

Maybe<OperatorEntry>


getOperator()

static getOperator(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

ParameterType
namestring
targetClass?SequenceConstructor

Returns

Maybe<OperatorEntry>


getMetadata()

static getMetadata(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

ParameterType
namestring

Returns

Maybe<OperatorMetadata>


list()

static list(): readonly OperatorMetadata[]

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()

static listSources(): readonly OperatorMetadata[]

Defined in: src/core/registry/TyneqOperatorRegistry.ts:266

Returns metadata for all registered source factories.

Returns

readonly OperatorMetadata[]


listOperators()

static listOperators(targetClass?): readonly OperatorMetadata[]

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

ParameterType
targetClass?SequenceConstructor

Returns

readonly OperatorMetadata[]


listByKind()

static listByKind(kind): readonly OperatorMetadata[]

Defined in: src/core/registry/TyneqOperatorRegistry.ts:293

Returns metadata for all operators of kind across both namespaces.

Parameters

ParameterType
kindOperatorKind

Returns

readonly OperatorMetadata[]


listBySource()

static listBySource(source): readonly OperatorMetadata[]

Defined in: src/core/registry/TyneqOperatorRegistry.ts:298

Returns metadata for all operators from source across both namespaces.

Parameters

ParameterType
sourceOperatorSource

Returns

readonly OperatorMetadata[]


count()

static count(): number

Defined in: src/core/registry/TyneqOperatorRegistry.ts:303

Returns the total number of registered operators across both namespaces.

Returns

number