fig-tree-evaluator 2.23.2 → 3.0.0-preview.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.d.ts CHANGED
@@ -1,279 +1,822 @@
1
- /// <reference types="node" />
2
- import { Client } from 'pg';
3
- import { Database } from 'sqlite';
4
- import { AxiosStatic } from 'axios';
5
- import { RequestInfo, RequestInit, Response } from 'node-fetch';
6
- export { dequal } from 'dequal/lite';
7
-
8
- interface CacheOptions {
9
- maxSize?: number;
10
- maxTime?: number;
11
- }
12
- interface Store {
13
- [key: string]: {
14
- result: EvaluatorOutput;
15
- timestamp: number;
16
- };
1
+ declare const version = "3.0.0-preview.2";
2
+
3
+ interface HttpRequest {
4
+ url: string;
5
+ method: 'get' | 'post';
6
+ headers: Record<string, string>;
7
+ body?: unknown;
8
+ signal: AbortSignal;
17
9
  }
18
- declare class FigTreeCache {
19
- private store;
20
- private queue;
21
- private maxSize;
22
- private maxTime;
23
- constructor(options?: CacheOptions);
24
- useCache: (shouldUseCache: boolean, action: UnknownFunction, ...args: unknown[]) => Promise<EvaluatorOutput>;
25
- getMax: () => number;
26
- setMax: (size: number) => void;
27
- getMaxTime: () => number;
28
- setMaxTime: (time: number) => void;
29
- getCache: () => Store;
30
- setCache: (cache: Store) => Store;
31
- private resizeCache;
32
- }
33
-
34
- interface QueryInput {
35
- query: string;
36
- values?: (string | number | boolean)[] | object;
37
- single?: boolean;
38
- flatten?: boolean;
39
- }
40
- type QueryOutput = Exclude<EvaluatorOutput, undefined>;
41
- interface SQLConnection {
42
- query: (input: QueryInput) => Promise<QueryOutput>;
43
- }
44
-
45
- type BasicType = 'any' | 'string' | 'boolean' | 'number' | 'array' | 'object' | 'null' | 'undefined';
46
- type LiteralType = {
47
- literal: (string | undefined)[];
48
- };
49
- type ExpectedType = BasicType | LiteralType | BasicType[];
50
- type TypeCheckInput = {
51
- name?: string;
52
- value: unknown;
53
- expectedType: ExpectedType;
10
+ interface HttpClient {
11
+ request(req: HttpRequest): Promise<unknown>;
12
+ }
13
+ interface SqlRequest {
14
+ text: string;
15
+ values?: unknown[] | Record<string, unknown>;
16
+ signal?: AbortSignal;
17
+ }
18
+ interface SqlConnection {
19
+ query(req: SqlRequest): Promise<Record<string, unknown>[]>;
20
+ }
21
+ interface CacheStore {
22
+ get(key: string): unknown | Promise<unknown>;
23
+ set(key: string, value: unknown): void;
24
+ delete(key: string): void;
25
+ clear(): void;
26
+ }
27
+
28
+ type FigTreeErrorCode = string;
29
+ declare const ErrorCodes: {
30
+ readonly unknownOperator: "unknown-operator";
31
+ readonly typeCheck: "type-check";
32
+ readonly operatorFailure: "operator-failure";
33
+ readonly timeout: "timeout";
34
+ readonly requestTimeout: "request-timeout";
35
+ readonly aborted: "aborted";
36
+ readonly unknownNodeKey: "unknown-node-key";
37
+ readonly unresolvedVar: "unresolved-var";
38
+ readonly unrecognizedIdentifier: "unrecognized-identifier";
39
+ readonly depthCeiling: "depth-ceiling";
40
+ readonly nonFiniteResult: "non-finite-result";
41
+ readonly escapedHandle: "escaped-handle";
42
+ readonly emptyAggregate: "empty-aggregate";
43
+ readonly malformedNode: "malformed-node";
44
+ readonly unknownFragment: "unknown-fragment";
45
+ readonly positionalArity: "positional-arity";
46
+ readonly invalidVars: "invalid-vars";
47
+ readonly invalidReference: "invalid-reference";
48
+ readonly uselessModifier: "useless-modifier";
49
+ readonly unreferencedVar: "unreferenced-var";
50
+ readonly missingRequired: "missing-required";
51
+ readonly unresolvedParam: "unresolved-param";
52
+ readonly unresolvedBinding: "unresolved-binding";
53
+ readonly deadBinding: "dead-binding";
54
+ readonly invalidAs: "invalid-as";
55
+ readonly maxDepthExceeded: "max-depth";
56
+ readonly maxNodesExceeded: "max-nodes";
57
+ readonly returnsMismatch: "returns-mismatch";
58
+ readonly operatorValidate: "operator-validate";
59
+ readonly missingDataPath: "missing-data-path";
60
+ readonly shadowedVar: "shadowed-var";
61
+ readonly varCycle: "var-cycle";
62
+ readonly bareVars: "bare-vars";
63
+ readonly fragmentCycle: "fragment-cycle";
64
+ readonly unboundToken: "unbound-token";
65
+ readonly unusedSubstitution: "unused-substitution";
66
+ readonly tokenRenumber: "token-renumber";
67
+ readonly inertReferenceToken: "inert-reference-token";
68
+ readonly invalidDefinition: "invalid-definition";
69
+ readonly invalidName: "invalid-name";
70
+ readonly reservedName: "reserved-name";
71
+ readonly invalidNullPolicy: "invalid-null-policy";
72
+ readonly duplicateOperator: "duplicate-operator";
73
+ readonly invalidOptions: "invalid-options";
54
74
  };
55
75
 
56
- interface HttpClient {
57
- get: (req: Omit<HttpRequest, 'method'>) => Promise<unknown>;
58
- post: (req: Omit<HttpRequest, 'method'>) => Promise<unknown>;
59
- throwError: (err: unknown) => void;
76
+ type Severity = 'error' | 'warning' | 'hint';
77
+ interface Issue {
78
+ severity: Severity;
79
+ code: FigTreeErrorCode;
80
+ message: string;
81
+ path: (string | number)[];
82
+ operator?: string;
83
+ fragment?: string;
84
+ parameter?: string;
85
+ suggestion?: string;
60
86
  }
61
- interface HttpRequest {
62
- url: string;
63
- params?: {
64
- [key: string]: string;
65
- };
66
- data?: Record<string, unknown>;
67
- headers?: Record<string, unknown>;
68
- method?: 'get' | 'post';
87
+ interface ValidationResult {
88
+ valid: boolean;
89
+ issues: Issue[];
90
+ timeoutShielded: boolean;
69
91
  }
70
92
 
71
- interface GraphQLConnection {
72
- endpoint: string;
73
- headers?: {
74
- [key: string]: string;
93
+ declare const LAZY_HANDLE: unique symbol;
94
+ interface LazyValue<T = unknown> {
95
+ readonly [LAZY_HANDLE]: true;
96
+ evaluate(): Promise<T>;
97
+ }
98
+ interface Settlement {
99
+ index: number;
100
+ ok: boolean;
101
+ value?: unknown;
102
+ error?: unknown;
103
+ }
104
+ type SettlementStream = AsyncIterable<Settlement> & {
105
+ readonly [LAZY_HANDLE]: true;
106
+ length: number;
107
+ };
108
+ interface PerElement<T = unknown> {
109
+ readonly [LAZY_HANDLE]: true;
110
+ evaluate(index: number): Promise<T>;
111
+ settle(): SettlementStream;
112
+ }
113
+ type TraceEvent = {
114
+ type: string;
115
+ [key: string]: unknown;
116
+ };
117
+ interface OperatorContext {
118
+ signal: AbortSignal;
119
+ options: Readonly<EvaluationOptions>;
120
+ cache: {
121
+ memo<T>(key: unknown, fn: () => Promise<T>): Promise<T>;
122
+ };
123
+ trace: {
124
+ note(event: TraceEvent): void;
75
125
  };
76
- httpClient?: HttpClient;
77
126
  }
78
127
 
79
- declare const operatorAliases: OperatorAliases;
80
-
81
- declare const Operators: readonly ["AND", "OR", "EQUAL", "NOT_EQUAL", "PLUS", "SUBTRACT", "MULTIPLY", "DIVIDE", "GREATER_THAN", "LESS_THAN", "CONDITIONAL", "REGEX", "OBJECT_PROPERTIES", "STRING_SUBSTITUTION", "SPLIT", "COUNT", "GET", "POST", "SQL", "GRAPHQL", "BUILD_OBJECT", "MATCH", "CUSTOM_FUNCTIONS", "PASSTHRU"];
82
- type Operator = (typeof Operators)[number];
83
- type OperatorAlias = keyof typeof operatorAliases;
84
- type OperatorAliases = Record<string, Operator>;
85
- type Fragments = Record<string, Fragment>;
86
- type UnknownFunction = (...args: any[]) => EvaluatorOutput;
87
- interface FigTreeOptions {
88
- data?: Record<string, unknown>;
89
- objects?: Record<string, unknown>;
90
- functions?: Record<string, UnknownFunction | FunctionDefinition>;
91
- fragments?: Fragments;
92
- httpClient?: HttpClient;
93
- graphQLConnection?: GraphQLConnection;
94
- sqlConnection?: SQLConnection;
95
- baseEndpoint?: string;
96
- headers?: {
97
- [key: string]: string;
98
- };
99
- returnErrorAsString?: boolean;
100
- nullEqualsUndefined?: boolean;
101
- caseInsensitive?: boolean;
102
- allowJSONStringInput?: boolean;
103
- noShorthand?: boolean;
104
- skipRuntimeTypeCheck?: boolean;
105
- evaluateFullObject?: boolean;
106
- excludeOperators?: OperatorAlias[];
107
- useCache?: boolean;
108
- maxCacheSize?: number;
109
- maxCacheTime?: number;
110
- supportDeprecatedValueNodes?: boolean;
111
- }
112
- interface FigTreeConfig {
113
- options: FigTreeOptions;
114
- operators: OperatorReference;
115
- operatorAliases: OperatorAliases;
116
- typeChecker: (...args: TypeCheckInput[] | [TypeCheckInput[]]) => void;
117
- resolvedAliasNodes: {
118
- [key: string]: EvaluatorOutput;
128
+ type TraceStatus = 'value' | 'failed' | 'fallback' | 'cancelled' | 'skipped';
129
+ type TraceKind = 'operator' | 'fragment' | 'reference' | 'literal' | 'skeleton';
130
+ interface TraceNode {
131
+ path: (string | number)[];
132
+ source?: {
133
+ fragment: string;
119
134
  };
120
- cache: FigTreeCache;
121
- httpClient?: HttpClient;
122
- graphQLClient?: HttpClient;
123
- }
124
- type OutputType = 'string' | 'number' | 'boolean' | 'bool' | 'array';
125
- interface OperatorNode {
126
- operator: OperatorAlias;
127
- outputType?: OutputType;
128
- children?: EvaluatorNode[];
129
- fallback?: EvaluatorNode;
130
- useCache?: boolean;
131
- [key: string]: EvaluatorNode;
135
+ kind: TraceKind;
136
+ operator?: string;
137
+ ref?: string;
138
+ var?: string;
139
+ status: TraceStatus;
140
+ value?: unknown;
141
+ error?: FigTreeError;
142
+ events?: TraceEvent[];
143
+ children?: TraceNode[];
144
+ elapsed?: number;
145
+ warnings?: Issue[];
132
146
  }
133
- interface FragmentNode {
134
- fragment: string;
135
- parameters?: Record<string, EvaluatorNode>;
136
- [key: string]: EvaluatorNode;
147
+ interface CacheTraceEvent {
148
+ type: 'cache';
149
+ hit: boolean;
137
150
  }
138
- interface FragmentData {
139
- description?: string;
140
- parameters?: FragmentParameterMetadata[];
141
- textColor?: string;
142
- backgroundColor?: string;
151
+ interface RequestTraceEvent {
152
+ type: 'request';
153
+ method: string;
154
+ url: string;
155
+ headers: string[];
143
156
  }
144
- interface FunctionDefinition {
145
- function: UnknownFunction;
146
- description?: string;
147
- argsDefault?: unknown[];
148
- inputDefault?: unknown;
149
- textColor?: string;
150
- backgroundColor?: string;
151
- }
152
- type Fragment = (EvaluatorNode & {
153
- metadata?: FragmentData;
154
- }) | null;
155
- type EvaluatorOutput = string | boolean | number | object | null | undefined | Array<EvaluatorOutput>;
156
- type EvaluatorNode = OperatorNode | FragmentNode | EvaluatorOutput;
157
- type OperatorObject = {
158
- propertyAliases: Record<string, string>;
159
- operatorData: OperatorData;
160
- evaluate: EvaluateMethod;
161
- parseChildren: ParseChildrenMethod;
157
+ interface QueryTraceEvent {
158
+ type: 'query';
159
+ text: string;
160
+ }
161
+ interface RenderTraceEvent {
162
+ type: 'render';
163
+ token: string;
164
+ rendered: 'literal' | 'placeholder' | 'empty' | 'gap-closed';
165
+ }
166
+ interface KeyOverwriteTraceEvent {
167
+ type: 'key-overwrite';
168
+ key: string;
169
+ }
170
+ interface ShieldedFallbackTraceEvent {
171
+ type: 'shielded-fallback';
172
+ }
173
+ type KnownTraceEvent = CacheTraceEvent | RequestTraceEvent | QueryTraceEvent | RenderTraceEvent | KeyOverwriteTraceEvent | ShieldedFallbackTraceEvent;
174
+
175
+ interface FigTreeErrorInit {
176
+ code: FigTreeErrorCode;
177
+ message: string;
178
+ path: (string | number)[];
179
+ holePath?: (string | number)[];
180
+ operator?: string;
181
+ fragment?: string;
182
+ fragmentPath?: (string | number)[];
183
+ errorData?: Record<string, unknown>;
184
+ related?: FigTreeError[];
185
+ cause?: unknown;
186
+ issues?: Issue[];
187
+ trace?: TraceNode;
188
+ }
189
+ declare class FigTreeError extends Error {
190
+ code: FigTreeErrorCode;
191
+ path: (string | number)[];
192
+ holePath?: (string | number)[];
193
+ operator?: string;
194
+ fragment?: string;
195
+ fragmentPath?: (string | number)[];
196
+ errorData?: Record<string, unknown>;
197
+ related?: FigTreeError[];
198
+ cause?: unknown;
199
+ issues?: Issue[];
200
+ trace?: TraceNode;
201
+ constructor(init: FigTreeErrorInit);
202
+ prettyPrint(): string;
203
+ }
204
+ declare const isFigTreeError: (input: unknown) => input is FigTreeError;
205
+
206
+ type BasicType = 'any' | 'string' | 'number' | 'boolean' | 'array' | 'object' | 'null' | 'integer';
207
+ type LiteralType = {
208
+ literal: readonly (string | number | boolean)[];
162
209
  };
163
- type EvaluateMethod = (expression: OperatorNode, config: FigTreeConfig) => Promise<EvaluatorOutput>;
164
- type ParseChildrenMethod = (expression: OperatorNode, config: FigTreeConfig) => OperatorNode;
165
- type OperatorReference = {
166
- [key in Operator]: OperatorObject;
210
+ type ExpectedType = BasicType | LiteralType | readonly BasicType[];
211
+ interface Constraints {
212
+ length?: number;
213
+ homogeneous?: readonly BasicType[];
214
+ elementShape?: Record<string, TypeDeclaration>;
215
+ }
216
+ interface TypeDeclaration {
217
+ type?: ExpectedType;
218
+ required?: boolean;
219
+ constraints?: Constraints;
220
+ }
221
+ type TypeCheckResult = {
222
+ ok: true;
223
+ } | {
224
+ ok: false;
225
+ expected: string;
226
+ actual: string;
167
227
  };
168
- interface OperatorParameterMetadata {
169
- name: string;
170
- description: string;
171
- aliases: string[];
172
- required: boolean;
173
- type: ExpectedType;
228
+
229
+ declare const validateHelpers: Readonly<{
230
+ parsePath: (path: string) => PathSegment[];
231
+ resolvePath: (source: unknown, path: string | PathSegment[]) => ResolveResult;
232
+ checkType: (value: unknown, expected: ExpectedType) => TypeCheckResult;
233
+ checkConstraints: (value: unknown, constraints: Constraints) => TypeCheckResult;
234
+ describeType: (value: unknown) => string;
235
+ renderText: (value: unknown) => string;
236
+ isTruthy: (value: unknown) => boolean;
237
+ }>;
238
+ type ValidateHelpers = typeof validateHelpers;
239
+
240
+ type TypeOf<T> = T extends 'string' ? string : T extends 'number' | 'integer' ? number : T extends 'boolean' ? boolean : T extends 'array' ? unknown[] : T extends 'object' ? Record<string, unknown> : T extends 'null' ? null : T extends 'any' ? unknown : T extends {
241
+ literal: readonly (infer M)[];
242
+ } ? M : T extends readonly (infer B)[] ? TypeOf<B> : unknown;
243
+ type DeclaredType<P> = P extends {
244
+ type: infer T;
245
+ } ? T : 'any';
246
+ type KeepsNull<P> = P extends {
247
+ nullPolicy: 'value';
248
+ } ? true : P extends {
249
+ nullPolicy: NullPolicyValue;
250
+ } ? false : P extends {
251
+ nullPolicy: (...args: any) => any;
252
+ } ? true : false;
253
+ type Delivered<P> = KeepsNull<P> extends true ? TypeOf<DeclaredType<P>> : Exclude<TypeOf<DeclaredType<P>>, null>;
254
+ type Truthy<P> = P extends {
255
+ type: 'array';
256
+ } ? boolean[] : P extends {
257
+ type: 'object';
258
+ } ? Record<string, boolean> : boolean;
259
+ type ParamValue<P> = P extends {
260
+ evaluation: 'structural';
261
+ } ? TypeOf<DeclaredType<P>> : P extends {
262
+ evaluation: 'race';
263
+ } ? SettlementStream : P extends {
264
+ evaluation: 'lazyElements';
265
+ } ? LazyValue[] : P extends {
266
+ evaluation: 'lazyEntries';
267
+ } ? Record<string, LazyValue> : P extends {
268
+ evaluation: 'perElement';
269
+ } ? PerElement<P extends {
270
+ truthiness: true;
271
+ } ? boolean : Delivered<P>> : P extends {
272
+ evaluation: 'lazy';
273
+ } ? LazyValue<Delivered<P>> : P extends {
274
+ truthiness: true;
275
+ } ? Truthy<P> : Delivered<P>;
276
+ type IsHolder<P> = P extends {
277
+ replacesNullAt: readonly string[];
278
+ } ? true : false;
279
+ type IsOptional<P> = P extends {
280
+ default: unknown;
281
+ } ? false : P extends {
282
+ required: false;
283
+ } ? true : false;
284
+ type BodyKeys<D> = {
285
+ [K in keyof D]: IsHolder<D[K]> extends true ? never : K;
286
+ }[keyof D];
287
+ type OptionalKeys<D> = {
288
+ [K in BodyKeys<D>]: IsOptional<D[K]> extends true ? K : never;
289
+ }[BodyKeys<D>];
290
+ type RequiredKeys<D> = Exclude<BodyKeys<D>, OptionalKeys<D>>;
291
+ type Simplify<T> = {
292
+ [K in keyof T]: T[K];
293
+ } & {};
294
+ type ResolvedParams<D extends ParameterDeclarations = ParameterDeclarations> = Simplify<{
295
+ [K in RequiredKeys<D>]: ParamValue<D[K]>;
296
+ } & {
297
+ [K in OptionalKeys<D>]?: ParamValue<D[K]>;
298
+ }>;
299
+
300
+ type EvaluationMode = 'eager' | 'race' | 'lazy' | 'lazyElements' | 'lazyEntries' | 'perElement' | 'structural';
301
+ declare const OPERATOR_CATEGORIES: readonly ["logic", "comparison", "math", "string", "array", "data", "io", "other"];
302
+ type OperatorCategory = (typeof OPERATOR_CATEGORIES)[number];
303
+ type NullPolicyValue = 'propagate' | 'value';
304
+ type ConditionalNullPolicy = (selectorValue: any) => NullPolicyValue;
305
+ type NullPolicy = NullPolicyValue | ConditionalNullPolicy;
306
+ interface CompiledNullPolicy {
307
+ selector: string;
308
+ table: {
309
+ value: string | number | boolean;
310
+ policy: NullPolicyValue;
311
+ }[];
312
+ }
313
+ declare const EvaluationData: unique symbol;
314
+ type OperatorEvaluate = (params: Record<string, unknown>, context: OperatorContext) => unknown;
315
+ interface ValidateFinding {
316
+ severity: Severity;
317
+ message: string;
318
+ parameter?: string;
319
+ }
320
+ type OperatorValidate = (literalParams: Record<string, unknown>, helpers: ValidateHelpers) => ValidateFinding[];
321
+ interface ParameterDeclaration extends TypeDeclaration {
174
322
  default?: unknown;
323
+ description?: string;
324
+ metadata?: Record<string, unknown>;
325
+ evaluation?: EvaluationMode;
326
+ over?: string;
327
+ truthiness?: boolean;
328
+ nullPolicy?: NullPolicy;
329
+ elementNullPolicy?: NullPolicyValue;
330
+ replacesNullAt?: readonly string[];
175
331
  }
176
- interface FragmentParameterMetadata {
332
+ type ParameterDeclarations = Record<string, ParameterDeclaration>;
333
+ interface OperatorDefinition<P extends ParameterDeclarations = ParameterDeclarations> {
177
334
  name: string;
178
- type: string | string[];
335
+ alias?: string;
336
+ category: OperatorCategory;
337
+ description: string;
338
+ metadata?: Record<string, unknown>;
339
+ parameters: P;
340
+ positionalParams?: readonly string[];
341
+ timeoutParam?: string;
342
+ useCache?: boolean;
343
+ cache?: 'auto' | 'manual';
344
+ validate?: OperatorValidate;
345
+ evaluate: (params: ResolvedParams<P>, context: OperatorContext) => unknown;
346
+ returns?: ExpectedType;
347
+ }
348
+ declare const VALIDATED_OPERATOR: unique symbol;
349
+ interface ValidatedParameter {
350
+ type: ExpectedType;
179
351
  required: boolean;
180
- description?: string;
181
352
  default?: unknown;
353
+ description?: string;
354
+ metadata?: Record<string, unknown>;
355
+ evaluation: EvaluationMode;
356
+ truthiness: boolean;
357
+ nullPolicy: NullPolicyValue | CompiledNullPolicy;
358
+ elementNullPolicy?: NullPolicyValue;
359
+ constraints?: Constraints;
360
+ over?: string;
361
+ replacesNullAt?: string[];
182
362
  }
183
- interface OperatorData {
363
+ interface ValidatedOperatorDefinition {
364
+ readonly [VALIDATED_OPERATOR]: true;
365
+ name: string;
366
+ alias?: string;
367
+ category: OperatorCategory;
184
368
  description: string;
185
- aliases: string[];
186
- parameters: OperatorParameterMetadata[];
369
+ metadata?: Record<string, unknown>;
370
+ parameters: Record<string, ValidatedParameter>;
371
+ positionalParams?: string[];
372
+ restParam: string | null;
373
+ resolution: ResolutionPlan;
374
+ deliversLazily: boolean;
375
+ timeoutParam: string | null;
376
+ useCache: boolean;
377
+ cache: 'auto' | 'manual';
378
+ fingerprint: string;
379
+ validate?: OperatorValidate;
380
+ evaluate: OperatorEvaluate;
381
+ returns: ExpectedType;
382
+ }
383
+ type DeclarationEntry = readonly [name: string, declared: ValidatedParameter];
384
+ interface ResolutionPlan {
385
+ readonly entries: readonly DeclarationEntry[];
386
+ readonly whole: readonly DeclarationEntry[];
387
+ readonly perElement: readonly DeclarationEntry[];
388
+ }
389
+
390
+ declare const isTruthy: (value: unknown) => boolean;
391
+
392
+ declare const compareValues: (a: number | string, b: number | string) => -1 | 0 | 1;
393
+
394
+ declare const ARRAY = "<array>";
395
+ declare const OBJECT = "<object>";
396
+ declare const renderText: (value: unknown) => string;
397
+
398
+ declare const WILDCARD: unique symbol;
399
+ type Wildcard = typeof WILDCARD;
400
+ type PathSegment = string | number | Wildcard;
401
+ interface ResolveResult {
402
+ found: boolean;
403
+ value: unknown;
187
404
  }
188
- type OperatorMetadata = OperatorData & {
189
- name: Operator;
190
- parseChildren: ParseChildrenMethod;
405
+ declare const parsePath: (path: string) => PathSegment[];
406
+ declare const resolvePath: (source: unknown, path: string | PathSegment[]) => ResolveResult;
407
+
408
+ declare const deepEqual: (foo: any, bar: any) => boolean;
409
+
410
+ type ReferenceNamespace = 'data' | 'vars' | 'params' | 'element' | 'index';
411
+
412
+ type ReferenceRecognition = {
413
+ kind: 'reference';
414
+ namespace: ReferenceNamespace;
415
+ segments: PathSegment[];
416
+ drill: string;
417
+ } | {
418
+ kind: 'invalid';
419
+ namespace: ReferenceNamespace;
420
+ reason: string;
421
+ code?: string;
422
+ } | {
423
+ kind: 'unrecognized';
424
+ } | {
425
+ kind: 'plain';
191
426
  };
192
- type FragmentMetadata = FragmentData & {
193
- name: string;
427
+
428
+ type ObjectClass = {
429
+ kind: 'operator';
430
+ } | {
431
+ kind: 'fragment';
432
+ } | {
433
+ kind: 'shorthand';
434
+ key: string;
435
+ } | {
436
+ kind: 'plain';
437
+ } | {
438
+ kind: 'malformed';
439
+ message: string;
194
440
  };
195
- type CustomFunctionMetadata = {
196
- name: string;
197
- numRequiredArgs: number;
198
- } & Omit<FunctionDefinition, 'function'>;
199
-
200
- declare class FigTreeEvaluator {
201
- private options;
202
- private operators;
203
- private operatorAliases;
204
- private cache;
205
- private graphQLClient?;
206
- private httpClient?;
207
- constructor(options?: FigTreeOptions);
208
- private typeChecker;
209
- evaluate(expression: EvaluatorNode, options?: FigTreeOptions): Promise<EvaluatorOutput>;
210
- isFigTreeExpression(expression: EvaluatorNode): boolean;
211
- getOptions(): FigTreeOptions;
212
- updateOptions(options: FigTreeOptions): void;
213
- getCache: () => Store;
214
- setCache: (cache: Store) => Store;
215
- getOperators(): readonly OperatorMetadata[];
216
- getFragments(): readonly FragmentMetadata[];
217
- getCustomFunctions(): readonly CustomFunctionMetadata[];
218
- getConfig(): {
219
- options: FigTreeOptions;
220
- operators: OperatorReference;
221
- operatorAliases: OperatorAliases;
222
- typeChecker: (...args: TypeCheckInput[] | [TypeCheckInput[]]) => void;
223
- resolvedAliasNodes: {};
224
- cache: FigTreeCache;
225
- graphQLClient: HttpClient | undefined;
226
- httpClient: HttpClient | undefined;
441
+ interface PositionalShape {
442
+ positionalParams?: readonly string[];
443
+ restParam: string | null;
444
+ }
445
+ interface PositionalLayout {
446
+ bound: number;
447
+ restAt: number | null;
448
+ }
449
+
450
+ interface FragmentParameterDeclaration extends TypeDeclaration {
451
+ default?: unknown;
452
+ description?: string;
453
+ metadata?: Record<string, unknown>;
454
+ }
455
+ interface FragmentDefinition {
456
+ expression: unknown;
457
+ parameters?: Record<string, FragmentParameterDeclaration>;
458
+ description?: string;
459
+ metadata?: Record<string, unknown>;
460
+ }
461
+ interface FragmentParameter {
462
+ type: ExpectedType;
463
+ required: boolean;
464
+ default?: unknown;
465
+ description?: string;
466
+ metadata?: Record<string, unknown>;
467
+ constraints?: Constraints;
468
+ }
469
+
470
+ type EvaluationOptions = Omit<FigTreeOptions, 'operators' | 'fragments'>;
471
+ type CallOptions = Pick<FigTreeOptions, 'data' | 'signal' | 'timeout' | 'mode' | 'trace'>;
472
+ type OnlyCallOptions<CallOpts> = CallOpts & {
473
+ [Key in Exclude<keyof CallOpts, keyof CallOptions>]: never;
474
+ };
475
+ interface FigTreeOptions {
476
+ data?: Record<string, unknown>;
477
+ fragments?: Record<string, FragmentDefinition>;
478
+ operators?: (ValidatedOperatorDefinition | ValidatedOperatorDefinition[])[];
479
+ operatorDefaults?: {
480
+ [operator: string]: {
481
+ [param: string]: unknown;
482
+ };
483
+ };
484
+ http?: {
485
+ baseEndpoint?: string;
486
+ headers?: Record<string, string>;
487
+ };
488
+ graphQL?: {
489
+ endpoint?: string;
490
+ headers?: Record<string, string>;
491
+ };
492
+ strictDataPaths?: boolean;
493
+ maxDepth?: number;
494
+ maxNodes?: number;
495
+ timeout?: number;
496
+ signal?: AbortSignal;
497
+ useCache?: boolean;
498
+ cache?: {
499
+ store?: CacheStore;
500
+ maxSize?: number;
501
+ maxTime?: number;
227
502
  };
228
- getVersion: () => string;
503
+ runtimeTypeCheck?: boolean;
504
+ mode?: 'throw' | 'report';
505
+ trace?: boolean;
229
506
  }
230
- declare const evaluateExpression: (expression: EvaluatorNode, options?: FigTreeOptions) => Promise<EvaluatorOutput>;
507
+ interface EvaluationResult {
508
+ result: unknown;
509
+ errors: FigTreeError[];
510
+ trace?: TraceNode;
511
+ }
512
+ type NoOptions = Record<never, never>;
513
+ type Merge<Instance, Call> = Omit<Instance, keyof Call> & Call;
514
+ type ResultShape<O> = O extends {
515
+ mode: 'report';
516
+ } | {
517
+ trace: true;
518
+ } ? EvaluationResult : unknown;
231
519
 
232
- declare class FigTreeError extends Error {
233
- operator?: Operator;
520
+ interface Dependencies {
521
+ data: {
522
+ paths: string[];
523
+ dynamic: boolean;
524
+ };
525
+ operators: string[];
526
+ fragments: string[];
527
+ }
528
+ interface ParameterInfo extends ValidatedParameter {
529
+ instanceDefault?: unknown;
530
+ }
531
+ interface OperatorInfo extends Omit<ValidatedOperatorDefinition, typeof VALIDATED_OPERATOR | 'evaluate' | 'validate' | 'deliversLazily' | 'resolution' | 'fingerprint' | 'parameters'> {
532
+ parameters: Record<string, ParameterInfo>;
533
+ hasValidate: boolean;
534
+ instanceUseCache?: boolean;
535
+ instanceFallback?: unknown;
536
+ }
537
+ interface FragmentInfo {
538
+ name: string;
539
+ description?: string;
540
+ metadata?: Record<string, unknown>;
541
+ parameters: Record<string, FragmentParameter>;
542
+ returns: ExpectedType;
543
+ warnings: Issue[];
544
+ dependencies: Dependencies;
545
+ }
546
+
547
+ declare class FigTree<InstanceOpts extends FigTreeOptions = NoOptions> {
548
+ private state;
549
+ private readonly results;
550
+ readonly version = "3.0.0-preview.2";
551
+ constructor(options?: InstanceOpts);
552
+ updateOptions(options?: FigTreeOptions): void;
553
+ clearCache(): void;
554
+ getOptions(): EvaluationOptions;
555
+ getOperators(): OperatorInfo[];
556
+ getFragments(): FragmentInfo[];
557
+ validate(expression: unknown, options?: CallOptions): ValidationResult;
558
+ getDependencies(expression: unknown): Dependencies;
559
+ isEvaluable(expression: unknown): boolean;
560
+ evaluate<CallOpts extends CallOptions = NoOptions>(expression: unknown, options?: OnlyCallOptions<CallOpts>): Promise<ResultShape<Merge<InstanceOpts, CallOpts>>>;
561
+ compile(expression: unknown): CompiledExpression<InstanceOpts>;
562
+ }
563
+ declare class CompiledExpression<InstanceOpts extends FigTreeOptions = NoOptions> {
564
+ #private;
565
+ private constructor();
566
+ get expression(): unknown;
567
+ get issues(): readonly Issue[];
568
+ get hasErrors(): boolean;
569
+ evaluate<CallOpts extends CallOptions = NoOptions>(options?: OnlyCallOptions<CallOpts>): Promise<ResultShape<Merge<InstanceOpts, CallOpts>>>;
570
+ getDependencies(): Dependencies;
571
+ }
572
+
573
+ declare function defineOperator(definition: ValidatedOperatorDefinition): ValidatedOperatorDefinition;
574
+ declare function defineOperator<const P extends ParameterDeclarations>(definition: OperatorDefinition<P>): ValidatedOperatorDefinition;
575
+
576
+ declare const coreOperators: ValidatedOperatorDefinition[];
577
+
578
+ interface OperatorFailureInit {
579
+ code?: string;
234
580
  errorData?: Record<string, unknown>;
235
- expression?: EvaluatorNode;
236
- prettyPrint: string;
237
- constructor(error: Error & {
238
- errorData?: Record<string, unknown>;
239
- }, operator?: Operator, name?: string, expression?: EvaluatorNode);
240
581
  }
241
- declare const isFigTreeError: (input: unknown) => input is FigTreeError;
582
+ declare class OperatorFailure extends Error {
583
+ code?: string;
584
+ errorData?: Record<string, unknown>;
585
+ constructor(message: string, init?: OperatorFailureInit);
586
+ }
587
+ declare const isOperatorFailure: (input: unknown) => input is OperatorFailure;
242
588
 
243
- declare const SQLNodePostgres: (client: Client) => {
244
- query: ({ query, values }: QueryInput) => Promise<QueryOutput>;
245
- };
246
- declare const SQLite: (db: Database) => {
247
- query: ({ query, values }: QueryInput) => Promise<any[]>;
248
- };
589
+ declare const httpOperators: (client?: HttpClient) => ValidatedOperatorDefinition[];
590
+ declare const sqlOperators: (connection: SqlConnection) => ValidatedOperatorDefinition[];
249
591
 
250
- type Fetch = (input: URL | string | RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
251
- declare const AxiosClient: (axios: AxiosStatic) => {
252
- get: (req: Omit<HttpRequest, 'method'>) => Promise<any>;
253
- post: (req: Omit<HttpRequest, 'method'>) => Promise<any>;
254
- throwError: (err: unknown) => never;
255
- };
256
- declare const FetchClient: (fetch: Fetch) => {
257
- get: (req: Omit<HttpRequest, 'method'>) => Promise<any>;
258
- post: (req: Omit<HttpRequest, 'method'>) => Promise<any>;
259
- throwError: (err: unknown) => never;
592
+ type FetchLike = (input: string, init?: {
593
+ method?: string;
594
+ headers?: Record<string, string>;
595
+ body?: string;
596
+ signal?: AbortSignal;
597
+ }) => Promise<FetchResponseLike>;
598
+ interface FetchResponseLike {
599
+ ok: boolean;
600
+ status: number;
601
+ statusText: string;
602
+ url: string;
603
+ text(): Promise<string>;
604
+ }
605
+ interface AxiosLike {
606
+ (config: {
607
+ url: string;
608
+ method: 'get' | 'post';
609
+ headers?: Record<string, string>;
610
+ data?: unknown;
611
+ signal?: AbortSignal;
612
+ }): Promise<{
613
+ data: unknown;
614
+ status: number;
615
+ statusText: string;
616
+ }>;
617
+ isAxiosError(payload: unknown): payload is AxiosErrorLike;
618
+ }
619
+ interface AxiosErrorLike {
620
+ message: string;
621
+ config?: {
622
+ url?: string;
623
+ };
624
+ response?: {
625
+ status: number;
626
+ statusText: string;
627
+ data: unknown;
628
+ };
629
+ }
630
+ declare class FetchClient implements HttpClient {
631
+ private readonly supplied?;
632
+ constructor(fetchImpl?: FetchLike);
633
+ request: (req: HttpRequest) => Promise<unknown>;
634
+ }
635
+ declare class AxiosClient implements HttpClient {
636
+ private readonly axios;
637
+ constructor(axios: AxiosLike);
638
+ request: (req: HttpRequest) => Promise<unknown>;
639
+ }
640
+
641
+ interface PgClientLike {
642
+ query(config: {
643
+ text: string;
644
+ values?: unknown[];
645
+ }): Promise<{
646
+ rows: Record<string, unknown>[];
647
+ }>;
648
+ }
649
+ interface SqliteDatabaseLike {
650
+ all(sql: string, params?: unknown[] | Record<string, unknown>): Promise<Record<string, unknown>[]>;
651
+ }
652
+ declare class PostgresConnection implements SqlConnection {
653
+ private readonly client;
654
+ constructor(client: PgClientLike);
655
+ query: (req: SqlRequest) => Promise<Record<string, unknown>[]>;
656
+ }
657
+ declare class SQLiteConnection implements SqlConnection {
658
+ private readonly db;
659
+ constructor(db: SqliteDatabaseLike);
660
+ query: (req: SqlRequest) => Promise<Record<string, unknown>[]>;
661
+ }
662
+
663
+ type Json = null | boolean | number | string | Json[] | {
664
+ [key: string]: Json;
260
665
  };
666
+ type Path = (string | number)[];
261
667
 
262
- declare const preProcessShorthand: (expression: EvaluatorNode, fragments: Fragments | undefined, functionNames: string[], useShorthand?: boolean) => EvaluatorNode | FragmentNode;
668
+ type NodeMap = Record<string, InspectNode>;
669
+ type InspectNode = {
670
+ order: number;
671
+ path: Path;
672
+ } & ({
673
+ kind: 'constant';
674
+ value: Json;
675
+ } | {
676
+ kind: 'reference';
677
+ reference: string;
678
+ authored: string;
679
+ binding?: string;
680
+ } | {
681
+ kind: 'operator';
682
+ vars?: NodeMap;
683
+ operator: string;
684
+ params: NodeMap;
685
+ fallback?: InspectNode;
686
+ timeoutFallback?: Json;
687
+ useCache?: boolean;
688
+ instanceDefaults?: string[];
689
+ } | {
690
+ kind: 'fragmentCall';
691
+ vars?: NodeMap;
692
+ fragment: string;
693
+ resolved: boolean;
694
+ argumentsMode: 'static' | 'dynamic';
695
+ parameters?: NodeMap | InspectNode;
696
+ fallback?: InspectNode;
697
+ timeoutFallback?: Json;
698
+ } | {
699
+ kind: 'skeleton';
700
+ vars?: NodeMap;
701
+ shape: Json;
702
+ holes: {
703
+ at: Path;
704
+ node: InspectNode;
705
+ }[];
706
+ } | {
707
+ kind: 'elements';
708
+ elements: InspectNode[];
709
+ } | {
710
+ kind: 'entries';
711
+ vars?: NodeMap;
712
+ entries: NodeMap;
713
+ } | {
714
+ kind: 'invalid';
715
+ raw: Json;
716
+ });
263
717
 
264
- declare const isOperatorNode: (input: EvaluatorNode) => input is OperatorNode;
265
- declare const isFragmentNode: (input: EvaluatorNode) => input is FragmentNode;
266
- declare const standardiseOperatorName: (name: string) => string;
267
- declare const truncateString: (string: string, length?: number) => string;
268
- declare const isAliasString: (value: string) => boolean;
269
- declare const isObject: (input: unknown) => input is object;
270
- declare const isFigTreeExpression: (expression: EvaluatorNode) => boolean;
718
+ type InspectIssue = Issue & {
719
+ order?: number;
720
+ };
721
+ interface InspectDependencies {
722
+ dataPaths: string[];
723
+ dynamic: boolean;
724
+ operators: string[];
725
+ fragments: string[];
726
+ }
727
+ interface InspectReport {
728
+ version: string;
729
+ expression: Json;
730
+ options: Record<string, Json>;
731
+ canonicalForm: InspectNode;
732
+ issues: InspectIssue[];
733
+ timeoutShielded: boolean;
734
+ nodeCount: number;
735
+ maxDepth: number;
736
+ dependencies: InspectDependencies;
737
+ own: {
738
+ nodeCount: number;
739
+ maxDepth: number;
740
+ dependencies: InspectDependencies;
741
+ };
742
+ }
743
+ declare const inspect: <InstanceOpts extends FigTreeOptions>(compiled: CompiledExpression<InstanceOpts>, options?: CallOptions) => InspectReport;
271
744
 
272
- declare const convertV1ToV2: (expression: EvaluatorNode, figTree: FigTreeEvaluator) => string | number | boolean | Record<string, unknown> | null | undefined;
273
- declare const isV1Node: (node: EvaluatorNode) => node is OperatorNode;
745
+ interface OperatorHints {
746
+ displayName: string;
747
+ docUrl: string;
748
+ backgroundColor: string;
749
+ textColor: string;
750
+ seeds?: {
751
+ [parameter: string]: unknown;
752
+ };
753
+ }
754
+ type FragmentHints = Omit<OperatorHints, 'docUrl'> & {
755
+ docUrl?: string;
756
+ };
757
+ interface CategoryHints {
758
+ displayName: string;
759
+ order: number;
760
+ backgroundColor: string;
761
+ textColor: string;
762
+ }
763
+ type OperatorHintMap = {
764
+ [operator: string]: OperatorHints;
765
+ };
766
+ type CategoryHintMap = {
767
+ [category in OperatorCategory]: CategoryHints;
768
+ };
769
+ type TypeSeeds = {
770
+ [type in BasicType]: unknown;
771
+ };
274
772
 
275
- declare const convertToShorthand: (expression: EvaluatorNode, figTree: FigTreeEvaluator, arrayThreshold?: number) => EvaluatorNode;
773
+ interface MigrationIssue {
774
+ code: 'split-trailing-empty' | 'remainder-sign' | 'template-numbering' | 'named-token-source' | 'response-collapse' | 'computed-delimiter' | 'computed-branches' | 'graphql-relative-url' | 'output-type' | 'missing-data-fallback' | 'unprefixed-parameter' | 'instance-case-insensitive' | 'values-cut' | 'fallback-converted' | 'malformed-entry' | 'unreachable-branches' | 'overridden-value' | 'discarded-expression' | 'fragment-shorthand-payload' | 'shadowed-argument' | 'unknown-argument' | 'fragment-use-cache' | 'name-renamed' | 'unknown-parameter-type' | 'default-outside-type' | 'unused-output-type' | 'deciding-value' | 'drilled-substitution-token' | 'number-mapping' | 'template-escape' | 'computed-dollar-template' | 'custom-function-call' | 'computed-function-name' | 'computed-arguments' | 'body-override' | 'computed-fragment-name' | 'replaced-output-type' | 'computed-children' | 'unknown-operator' | 'unconvertible-input';
775
+ tag: 'non-convertible' | 'intentional-semantic-change' | 'lossy-default';
776
+ path: (string | number)[];
777
+ message: string;
778
+ }
779
+ interface MigrationResult {
780
+ expression: unknown;
781
+ issues: MigrationIssue[];
782
+ }
783
+ interface FragmentMigrationResult {
784
+ fragments: Record<string, FragmentDefinition>;
785
+ issues: MigrationIssue[];
786
+ }
787
+ interface V2Options {
788
+ fragments?: Record<string, unknown>;
789
+ functions?: readonly string[] | Record<string, unknown>;
790
+ evaluateFullObject?: boolean;
791
+ noShorthand?: boolean;
792
+ caseInsensitive?: boolean;
793
+ useCache?: boolean;
794
+ }
276
795
 
277
- declare const convertFromShorthand: (expression: EvaluatorNode, figTree: FigTreeEvaluator) => EvaluatorNode;
796
+ interface Registry {
797
+ getOperators(): readonly {
798
+ name: string;
799
+ alias?: string;
800
+ positionalParams?: readonly string[];
801
+ restParam: string | null;
802
+ }[];
803
+ getFragments(): readonly {
804
+ name: string;
805
+ }[];
806
+ }
807
+ type Spelling = 'preserve' | 'canonical' | 'alias';
808
+ interface NameOptions {
809
+ referenceNames?: Spelling;
810
+ }
811
+ interface CanonicalOptions extends NameOptions {
812
+ operatorNames?: Spelling;
813
+ referencesAsGet?: boolean;
814
+ }
815
+ interface ShorthandOptions extends NameOptions {
816
+ operatorNames?: Spelling;
817
+ arguments?: 'positional' | 'named';
818
+ getAsReference?: boolean;
819
+ }
278
820
 
279
- export { AxiosClient, type BasicType, type CustomFunctionMetadata, type EvaluatorNode, type EvaluatorOutput, type ExpectedType, FetchClient, type FigTreeConfig, FigTreeError, FigTreeEvaluator, type FigTreeOptions, type Fragment, type FragmentMetadata, type FragmentNode, type FragmentParameterMetadata, type Fragments, type FunctionDefinition, type GraphQLConnection, type LiteralType, type Operator, type OperatorAlias, type OperatorData, type OperatorMetadata, type OperatorNode, type OperatorParameterMetadata, type OutputType, SQLNodePostgres, SQLite, type UnknownFunction, convertFromShorthand, convertToShorthand, convertV1ToV2, evaluateExpression, isAliasString, isFigTreeError, isFigTreeExpression, isFragmentNode, isObject, isOperatorNode, isV1Node, preProcessShorthand, standardiseOperatorName, truncateString };
821
+ export { ARRAY, AxiosClient, CompiledExpression, ErrorCodes, EvaluationData, FetchClient, FigTree, FigTreeError, OBJECT, OPERATOR_CATEGORIES, OperatorFailure, PostgresConnection, SQLiteConnection, WILDCARD, compareValues, coreOperators, deepEqual, defineOperator, httpOperators, inspect, isFigTreeError, isOperatorFailure, isTruthy, parsePath, renderText, resolvePath, sqlOperators, version };
822
+ export type { AxiosErrorLike, AxiosLike, BasicType, CacheStore, CacheTraceEvent, CallOptions, CanonicalOptions, CategoryHintMap, CategoryHints, CompiledNullPolicy, ConditionalNullPolicy, Constraints, Dependencies, EvaluationMode, EvaluationOptions, EvaluationResult, ExpectedType, FetchLike, FetchResponseLike, FigTreeErrorCode, FigTreeErrorInit, FigTreeOptions, FragmentDefinition, FragmentHints, FragmentInfo, FragmentMigrationResult, FragmentParameter, FragmentParameterDeclaration, HttpClient, HttpRequest, InspectDependencies, InspectIssue, InspectNode, InspectReport, Issue, KeyOverwriteTraceEvent, KnownTraceEvent, LazyValue, LiteralType, Merge, MigrationIssue, MigrationResult, NameOptions, NoOptions, NullPolicy, NullPolicyValue, ObjectClass, OnlyCallOptions, OperatorCategory, OperatorContext, OperatorDefinition, OperatorEvaluate, OperatorFailureInit, OperatorHintMap, OperatorHints, OperatorInfo, OperatorValidate, ParamValue, ParameterDeclaration, ParameterDeclarations, ParameterInfo, PathSegment, PerElement, PgClientLike, PositionalLayout, PositionalShape, QueryTraceEvent, ReferenceNamespace, ReferenceRecognition, Registry, RenderTraceEvent, RequestTraceEvent, ResolveResult, ResolvedParams, ResultShape, Settlement, SettlementStream, Severity, ShieldedFallbackTraceEvent, ShorthandOptions, Spelling, SqlConnection, SqlRequest, SqliteDatabaseLike, TraceEvent, TraceKind, TraceNode, TraceStatus, TypeCheckResult, TypeDeclaration, TypeOf, TypeSeeds, V2Options, ValidateFinding, ValidateHelpers, ValidatedOperatorDefinition, ValidatedParameter, ValidationResult, Wildcard };