Skip to main content

SerializerRegistry

The process-wide registry every dialect plugin package registers itself into. This is the entire public surface of SQB's dialect plugin system — see The Dialect Plugin System for how it's used in practice, and a full walkthrough of writing your own dialect extension.

SerializerRegistry is not instantiated — every member is static, backed by a single in-memory array shared by the whole process (module-level singleton, since ES modules are cached).

import { SerializerRegistry } from '@sqb/builder';

SerializerRegistry.register({
dialect: 'my-custom-db',
serialize(ctx, type, obj, defaultFn) {
return undefined; // fall through to the default renderer
},
});

Properties

KeyTypeReadonlyDescription
sizenumberYesTotal number of registered extensions, across all dialects.

Methods

register()

static register(...extensions: SerializerExtension[]): void

Appends one or more SerializerExtensions to the registry. Throws TypeError if an extension has no dialect. Does not check for or replace an existing extension with the same dialect — registering two extensions for 'postgres' keeps both, and both are tried (in registration order) when serializing for that dialect.

unRegister()

static unRegister(...extensions: SerializerExtension[]): void

Removes extensions by object reference, not by dialect name — you need to keep a handle to the exact instance you passed to register(). This is how the builder's own test suite avoids one test's dialect extension leaking into another (register() in a before() hook, unRegister() in the matching after()).

getAll()

static getAll(dialect: string): SerializerExtension[]

Returns every extension currently registered for dialect, in registration order.

findDialect()

static findDialect(dialect: string): SerializerExtension | undefined

Returns the first extension registered for dialect, or undefined if none is.

has()

static has(extension: SerializerExtension): boolean

Whether the exact extension instance is currently registered.

items()

static items(): IterableIterator<SerializerExtension>

Iterates every registered extension, across all dialects — this is what SerializeContext.serialize() walks internally, filtering by dialect as it goes.

forEach()

static forEach(
callback: (extension: SerializerExtension, index: number) => void,
thisArg?: any,
): void

Same iteration as items(), callback-style.

get()

static get(index: number): SerializerExtension | undefined

Positional access into the underlying array.

See also