UNPKG

@comyata/run

Version:

Simplify data workflows and management with data templates, for browser and server.

27 lines (26 loc) 1.78 kB
import { IDataNode } from '@comyata/run/DataNode'; import { NodeRuntimeBaggageComplete } from '@comyata/run/Runtime'; declare const PROXY_VALUE: unique symbol; /** * @todo verify behaviour with arrays, especially for `arr.slice(0, 2)` and similar * e.g. this expression doesn't resolve the second entry: * `l: [1, "${1+1}", 3, "${$root().l[[0..1]]}"]` => `{ "l": [1, 2, 3, [1, {}] ] }` * (which may be that jsonata doesn't support Promise resolving in range-query) * @todo this doesn't work if the whole object is accessed, doesn't prevent recursion if accessing a parent object which contains computed fields; * to support that, a tree/graph must be build, which allows checking where computed fields are included and tracking the path during recursive proxy creation * e.g. this doesn't fail but creates a cyclic reference: `{ a: "${$root().b}", b: { b1: "${$root().a}" } }` * but it could be detected: * `a` > `b` * `b.b1` > `a` > `b` * note that this doesn't result in a deadLock, as `a` > `b` can be resolved without waiting for `b.b1` and the final result of `b.b1` is set via reference, * yet it still leads to circular references instead of materialized data * @todo support adding to usages graph for transparent reporting on what uses what (interop with `addUsage` of DataFile) * @experimental */ export declare function createValueProxy<TData = unknown>(data: TData, dataNode: IDataNode, getNodeContext: NodeRuntimeBaggageComplete<IDataNode>['getNodeContext'], path?: (string | number)[]): TData; export declare function isProxy(proxy: unknown): proxy is ValueProxy; type ValueProxy = (typeof Proxy) & { [PROXY_VALUE]: any; }; export declare function toRaw(proxy: ValueProxy): any; export {};