UNPKG

lib0

Version:

isomorphic utility functions

189 lines • 9.69 kB
export function $tresult<A extends import("../delta.js").DeltaConf, B extends import("../delta.js").DeltaConf>($a: s.Schema<import("../delta.js").Delta<A>>, $b: s.Schema<import("../delta.js").Delta<B>>): s.Schema<TransformResult<A, B>>; export function createTransformResult<DeltaA extends import("../delta.js").DeltaBuilderAny = delta.DeltaBuilderAny, DeltaB extends import("../delta.js").DeltaBuilderAny = delta.DeltaBuilderAny>(a: DeltaA | null, b: DeltaB | null): TransformResult<any, any>; /** * A stateful, schema-bound mapper between changes of side A and side B, materialized from a * {@link Template} via `init()`. * * ## Deltas are manipulated in place * * `apply`/`applyA`/`applyB` **mutate their input deltas directly** — they rebase nodes and splice op * lists in place, and some transformers `apply(other, { move: true })` the input into an accumulator — * rather than editing only through the copy-on-write `apply`/`rebase` surface. This is a deliberate * exception to the general rule (a delta is normally edited only via `apply`/`rebase`, which re-clone * frozen content on first touch); it keeps the transform allocation-free, but it means a transformer is * an *owning* consumer of the delta it is given. **Callers must pass a privately-owned, fully-mutable * delta** — never a shared or `done` (frozen) one. A caller holding a shared read delta must * {@link import('../delta.js').cloneDeep deep-clone} it first (this is exactly what a * {@link import('../rdt.js').Binding} does before routing a change through its transformer). * * @template {import('../delta.js').DeltaConf} A * @template {import('../delta.js').DeltaConf} B */ export class Transformer<A extends import("../delta.js").DeltaConf, B extends import("../delta.js").DeltaConf> { /** * @param {s.Schema<import('../delta.js').Delta<A>>} $in input delta schema * @param {s.Schema<import('../delta.js').Delta<B>>} $out output delta schema (computed by the factory) */ constructor($in: s.Schema<import("../delta.js").Delta<A>>, $out: s.Schema<import("../delta.js").Delta<B>>); /** * @type {s.Schema<import('../delta.js').Delta<A>>} */ $in: s.Schema<import("../delta.js").Delta<A>>; /** * @type {s.Schema<import('../delta.js').Delta<B>>} */ $out: s.Schema<import("../delta.js").Delta<B>>; /** * @param {TransformResult<A, B>} tin * @return {TransformResult<A,B>} */ apply(tin: TransformResult<A, B>): TransformResult<A, B>; /** * @param {import('../delta.js').DeltaBuilder<A>} t * @return {TransformResult<A,B>} */ applyA(t: import("../delta.js").DeltaBuilder<A>): TransformResult<A, B>; /** * @param {import('../delta.js').DeltaBuilder<B>} t * @return {TransformResult<A,B>} */ applyB(t: import("../delta.js").DeltaBuilder<B>): TransformResult<A, B>; $type: s.Schema<Transformer<any, any>>; } /** * Recognize a {@link Transformer} by its `$type` tag. Every value is either a `Transformer` or a * {@link Template}, never both, so the two roles can each own a single prototype `$type`. * * @type {s.Schema<Transformer<any,any>>} */ export const $transformer: s.Schema<Transformer<any, any>>; export function transformerWith<A extends import("../delta.js").DeltaConf, B extends import("../delta.js").DeltaConf>(_a: s.Schema<import("../delta.js").Delta<A>> | A, _b: s.Schema<import("../delta.js").Delta<B>> | A): s.Schema<Transformer<A, B>>; /** * A function from an input delta schema to a {@link Template} — the schema-deferred form of a * transformer factory. Used for `pipe` stages, recursive composition, and `bind`. * * @template {import('../delta.js').DeltaConf} In * @template {import('../delta.js').DeltaConf} Out * @typedef {($in: s.Schema<import('../delta.js').Delta<In>>) => Template<In, Out>} TemplateFactory */ /** * Force a factory's computed output conf to display fully-resolved (flatten `Omit<…> & {…}` / bare * alias artifacts) while staying a valid `DeltaConf` for use as a `Transformer`/`Delta` type * argument — conf-aware and depth-limited (nested `Delta<…>` stay intact). Implemented as an * overwrite-with-nothing, reusing {@link import('../delta.js').DeltaConfOverwrite}'s * prettify+coerce recipe. Apply to every factory's `OUT` typedef whose result is not already * produced by `DeltaConfOverwrite`. * * @template {import('../delta.js').DeltaConf} Conf * @typedef {import('../delta.js').DeltaConfOverwrite<Conf, {}>} ResolveOut */ /** * The reusable, schema-bound form of a transformer: built by a factory (`attr($d, …)`), it holds the * input/output delta schemas (`$in`/`$out`) and materializes a fresh stateful {@link Transformer} via * the parameterless `init()`. Concrete templates `extend Template`. * * Templates are {@link fingerprintTrait.Fingerprintable}: this is what lets them be embedded as values * (holes) in a `delta.create(...)` projection spec without collapsing the spec's type. * * @template {import('../delta.js').DeltaConf} [IN=any] * @template {import('../delta.js').DeltaConf} [OUT=any] */ export class Template<IN extends import("../delta.js").DeltaConf = any, OUT extends import("../delta.js").DeltaConf = any> { /** * @param {s.Schema<import('../delta.js').Delta<IN>>} $in input delta schema * @param {s.Schema<import('../delta.js').Delta<OUT>>} $out output delta schema (computed by the factory) */ constructor($in: s.Schema<import("../delta.js").Delta<IN>>, $out: s.Schema<import("../delta.js").Delta<OUT>>); /** * @type {s.Schema<import('../delta.js').Delta<IN>>} */ $in: s.Schema<import("../delta.js").Delta<IN>>; /** * @type {s.Schema<import('../delta.js').Delta<OUT>>} */ $out: s.Schema<import("../delta.js").Delta<OUT>>; /** * Stable, mangle-safe identifier folded into this template's fingerprint. Subclasses with * configuration override it so that e.g. `attr('a')` and `attr('b')` fingerprint differently * (do NOT use `constructor.name` — class names do not survive mangling). * * @return {string} */ get name(): string; /** * Instantiate a fresh stateful {@link Transformer} bound to this template's schema. * * @return {Transformer<IN, OUT>} */ init(): Transformer<IN, OUT>; $type: s.Schema<Template>; /** * @return {string} */ [fingerprintTrait.FingerprintTraitSymbol](): string; } export function transform<IN extends import("../delta.js").DeltaConf, T extends Template<IN, any>>($d: s.Schema<import("../delta.js").Delta<IN>>, fn: ($d: s.Schema<import("../delta.js").Delta<IN>>) => T): T; export function withAttrs($in: s.Schema<import("../delta.js").DeltaAny>, newAttrsShape: { [k: string | number]: s.Schema<any>; }): s.Schema<import("../delta.js").DeltaAny>; export function withName($in: s.Schema<import("../delta.js").DeltaAny>, name: string): s.Schema<import("../delta.js").DeltaAny>; export function attrsShapeOf($in: s.Schema<import("../delta.js").DeltaAny>): { [k: string | number]: s.Schema<any>; } | null; /** * Recognize a {@link Template} by its `$type` tag. Used to detect transformer "holes" embedded in a * `project` spec. * * @type {s.Schema<Template>} */ export const $template: s.Schema<Template>; export type TransformResultAny = TransformResult<any, any>; /** * A function from an input delta schema to a {@link Template} — the schema-deferred form of a * transformer factory. Used for `pipe` stages, recursive composition, and `bind`. */ export type TemplateFactory<In extends import("../delta.js").DeltaConf, Out extends import("../delta.js").DeltaConf> = ($in: s.Schema<import("../delta.js").Delta<In>>) => Template<In, Out>; /** * Force a factory's computed output conf to display fully-resolved (flatten `Omit<…> & {…}` / bare * alias artifacts) while staying a valid `DeltaConf` for use as a `Transformer`/`Delta` type * argument — conf-aware and depth-limited (nested `Delta<…>` stay intact). Implemented as an * overwrite-with-nothing, reusing {@link import ('../delta.js').DeltaConfOverwrite}'s * prettify+coerce recipe. Apply to every factory's `OUT` typedef whose result is not already * produced by `DeltaConfOverwrite`. */ export type ResolveOut<Conf extends import("../delta.js").DeltaConf> = import("../delta.js").DeltaConfOverwrite<Conf, {}>; import * as s from '../../schema.js'; /** * @template {import('../delta.js').DeltaConf} [A={}] * @template {import('../delta.js').DeltaConf} [B={}] */ declare class TransformResult<A extends import("../delta.js").DeltaConf = {}, B extends import("../delta.js").DeltaConf = {}> { /** * @param {import('../delta.js').DeltaBuilder<A>?} a * @param {import('../delta.js').DeltaBuilder<B>?} b */ constructor(a: import("../delta.js").DeltaBuilder<A> | null, b: import("../delta.js").DeltaBuilder<B> | null); /** * @type {import('../delta.js').DeltaBuilder<A>?} */ a: import("../delta.js").DeltaBuilder<A> | null; /** * @type {import('../delta.js').DeltaBuilder<B>?} */ b: import("../delta.js").DeltaBuilder<B> | null; isEmpty(): boolean; clear(): void; /** * @param {import('../delta.js').DeltaBuilder<A>?} a */ applyA(a: import("../delta.js").DeltaBuilder<A> | null): this; /** * @param {import('../delta.js').DeltaBuilder<B>?} b */ applyB(b: import("../delta.js").DeltaBuilder<B> | null): this; reverse(): TransformResult<B, A>; } import * as delta from '../delta.js'; import * as fingerprintTrait from '../../trait/fingerprint.js'; export {}; //# sourceMappingURL=core.d.ts.map