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

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,780 @@
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.1";
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;
60
85
  }
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';
86
+ interface ValidationResult {
87
+ valid: boolean;
88
+ issues: Issue[];
89
+ timeoutShielded: boolean;
69
90
  }
70
91
 
71
- interface GraphQLConnection {
72
- endpoint: string;
73
- headers?: {
74
- [key: string]: string;
92
+ declare const LAZY_HANDLE: unique symbol;
93
+ interface LazyValue<T = unknown> {
94
+ readonly [LAZY_HANDLE]: true;
95
+ evaluate(): Promise<T>;
96
+ }
97
+ interface Settlement {
98
+ index: number;
99
+ ok: boolean;
100
+ value?: unknown;
101
+ error?: unknown;
102
+ }
103
+ type SettlementStream = AsyncIterable<Settlement> & {
104
+ readonly [LAZY_HANDLE]: true;
105
+ length: number;
106
+ };
107
+ interface PerElement<T = unknown> {
108
+ readonly [LAZY_HANDLE]: true;
109
+ evaluate(index: number): Promise<T>;
110
+ settle(): SettlementStream;
111
+ }
112
+ type TraceEvent = {
113
+ type: string;
114
+ [key: string]: unknown;
115
+ };
116
+ interface OperatorContext {
117
+ signal: AbortSignal;
118
+ options: Readonly<EvaluationOptions>;
119
+ cache: {
120
+ memo<T>(key: unknown, fn: () => Promise<T>): Promise<T>;
121
+ };
122
+ trace: {
123
+ note(event: TraceEvent): void;
75
124
  };
76
- httpClient?: HttpClient;
77
125
  }
78
126
 
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;
127
+ type TraceStatus = 'value' | 'failed' | 'fallback' | 'cancelled' | 'skipped';
128
+ type TraceKind = 'operator' | 'fragment' | 'reference' | 'literal' | 'skeleton';
129
+ interface TraceNode {
130
+ path: (string | number)[];
131
+ source?: {
132
+ fragment: string;
98
133
  };
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;
119
- };
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;
134
+ kind: TraceKind;
135
+ operator?: string;
136
+ ref?: string;
137
+ var?: string;
138
+ status: TraceStatus;
139
+ value?: unknown;
140
+ error?: FigTreeError;
141
+ events?: TraceEvent[];
142
+ children?: TraceNode[];
143
+ elapsed?: number;
144
+ warnings?: Issue[];
132
145
  }
133
- interface FragmentNode {
134
- fragment: string;
135
- parameters?: Record<string, EvaluatorNode>;
136
- [key: string]: EvaluatorNode;
146
+ interface CacheTraceEvent {
147
+ type: 'cache';
148
+ hit: boolean;
137
149
  }
138
- interface FragmentData {
139
- description?: string;
140
- parameters?: FragmentParameterMetadata[];
141
- textColor?: string;
142
- backgroundColor?: string;
150
+ interface RequestTraceEvent {
151
+ type: 'request';
152
+ method: string;
153
+ url: string;
154
+ headers: string[];
143
155
  }
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;
156
+ interface QueryTraceEvent {
157
+ type: 'query';
158
+ text: string;
159
+ }
160
+ interface RenderTraceEvent {
161
+ type: 'render';
162
+ token: string;
163
+ rendered: 'literal' | 'placeholder' | 'empty' | 'gap-closed';
164
+ }
165
+ interface KeyOverwriteTraceEvent {
166
+ type: 'key-overwrite';
167
+ key: string;
168
+ }
169
+ interface ShieldedFallbackTraceEvent {
170
+ type: 'shielded-fallback';
171
+ }
172
+ type KnownTraceEvent = CacheTraceEvent | RequestTraceEvent | QueryTraceEvent | RenderTraceEvent | KeyOverwriteTraceEvent | ShieldedFallbackTraceEvent;
173
+
174
+ interface FigTreeErrorInit {
175
+ code: FigTreeErrorCode;
176
+ message: string;
177
+ path: (string | number)[];
178
+ holePath?: (string | number)[];
179
+ operator?: string;
180
+ fragment?: string;
181
+ fragmentPath?: (string | number)[];
182
+ errorData?: Record<string, unknown>;
183
+ related?: FigTreeError[];
184
+ cause?: unknown;
185
+ issues?: Issue[];
186
+ trace?: TraceNode;
187
+ }
188
+ declare class FigTreeError extends Error {
189
+ code: FigTreeErrorCode;
190
+ path: (string | number)[];
191
+ holePath?: (string | number)[];
192
+ operator?: string;
193
+ fragment?: string;
194
+ fragmentPath?: (string | number)[];
195
+ errorData?: Record<string, unknown>;
196
+ related?: FigTreeError[];
197
+ cause?: unknown;
198
+ issues?: Issue[];
199
+ trace?: TraceNode;
200
+ constructor(init: FigTreeErrorInit);
201
+ prettyPrint(): string;
202
+ }
203
+ declare const isFigTreeError: (input: unknown) => input is FigTreeError;
204
+
205
+ type BasicType = 'any' | 'string' | 'number' | 'boolean' | 'array' | 'object' | 'null' | 'integer';
206
+ type LiteralType = {
207
+ literal: readonly (string | number | boolean)[];
162
208
  };
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;
209
+ type ExpectedType = BasicType | LiteralType | readonly BasicType[];
210
+ interface Constraints {
211
+ length?: number;
212
+ homogeneous?: readonly BasicType[];
213
+ elementShape?: Record<string, TypeDeclaration>;
214
+ }
215
+ interface TypeDeclaration {
216
+ type?: ExpectedType;
217
+ required?: boolean;
218
+ constraints?: Constraints;
219
+ }
220
+ type TypeCheckResult = {
221
+ ok: true;
222
+ } | {
223
+ ok: false;
224
+ expected: string;
225
+ actual: string;
167
226
  };
168
- interface OperatorParameterMetadata {
227
+
228
+ declare const validateHelpers: Readonly<{
229
+ parsePath: (path: string) => PathSegment[];
230
+ resolvePath: (source: unknown, path: string | PathSegment[]) => ResolveResult;
231
+ checkType: (value: unknown, expected: ExpectedType) => TypeCheckResult;
232
+ checkConstraints: (value: unknown, constraints: Constraints) => TypeCheckResult;
233
+ describeType: (value: unknown) => string;
234
+ renderText: (value: unknown) => string;
235
+ isTruthy: (value: unknown) => boolean;
236
+ }>;
237
+ type ValidateHelpers = typeof validateHelpers;
238
+
239
+ 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 {
240
+ literal: readonly (infer M)[];
241
+ } ? M : T extends readonly (infer B)[] ? TypeOf<B> : unknown;
242
+ type DeclaredType<P> = P extends {
243
+ type: infer T;
244
+ } ? T : 'any';
245
+ type KeepsNull<P> = P extends {
246
+ nullPolicy: 'value';
247
+ } ? true : P extends {
248
+ nullPolicy: NullPolicyValue;
249
+ } ? false : P extends {
250
+ nullPolicy: (...args: any) => any;
251
+ } ? true : false;
252
+ type Delivered<P> = KeepsNull<P> extends true ? TypeOf<DeclaredType<P>> : Exclude<TypeOf<DeclaredType<P>>, null>;
253
+ type Truthy<P> = P extends {
254
+ type: 'array';
255
+ } ? boolean[] : P extends {
256
+ type: 'object';
257
+ } ? Record<string, boolean> : boolean;
258
+ type ParamValue<P> = P extends {
259
+ evaluation: 'structural';
260
+ } ? TypeOf<DeclaredType<P>> : P extends {
261
+ evaluation: 'race';
262
+ } ? SettlementStream : P extends {
263
+ evaluation: 'lazyElements';
264
+ } ? LazyValue[] : P extends {
265
+ evaluation: 'lazyEntries';
266
+ } ? Record<string, LazyValue> : P extends {
267
+ evaluation: 'perElement';
268
+ } ? PerElement<P extends {
269
+ truthiness: true;
270
+ } ? boolean : Delivered<P>> : P extends {
271
+ evaluation: 'lazy';
272
+ } ? LazyValue<Delivered<P>> : P extends {
273
+ truthiness: true;
274
+ } ? Truthy<P> : Delivered<P>;
275
+ type IsHolder<P> = P extends {
276
+ replacesNullAt: readonly string[];
277
+ } ? true : false;
278
+ type IsOptional<P> = P extends {
279
+ default: unknown;
280
+ } ? false : P extends {
281
+ required: false;
282
+ } ? true : false;
283
+ type BodyKeys<D> = {
284
+ [K in keyof D]: IsHolder<D[K]> extends true ? never : K;
285
+ }[keyof D];
286
+ type OptionalKeys<D> = {
287
+ [K in BodyKeys<D>]: IsOptional<D[K]> extends true ? K : never;
288
+ }[BodyKeys<D>];
289
+ type RequiredKeys<D> = Exclude<BodyKeys<D>, OptionalKeys<D>>;
290
+ type Simplify<T> = {
291
+ [K in keyof T]: T[K];
292
+ } & {};
293
+ type ResolvedParams<D extends ParameterDeclarations = ParameterDeclarations> = Simplify<{
294
+ [K in RequiredKeys<D>]: ParamValue<D[K]>;
295
+ } & {
296
+ [K in OptionalKeys<D>]?: ParamValue<D[K]>;
297
+ }>;
298
+
299
+ type EvaluationMode = 'eager' | 'race' | 'lazy' | 'lazyElements' | 'lazyEntries' | 'perElement' | 'structural';
300
+ declare const OPERATOR_CATEGORIES: readonly ["logic", "comparison", "math", "string", "array", "data", "io", "other"];
301
+ type OperatorCategory = (typeof OPERATOR_CATEGORIES)[number];
302
+ type NullPolicyValue = 'propagate' | 'value';
303
+ type ConditionalNullPolicy = (selectorValue: any) => NullPolicyValue;
304
+ type NullPolicy = NullPolicyValue | ConditionalNullPolicy;
305
+ interface CompiledNullPolicy {
306
+ selector: string;
307
+ table: {
308
+ value: string | number | boolean;
309
+ policy: NullPolicyValue;
310
+ }[];
311
+ }
312
+ declare const EvaluationData: unique symbol;
313
+ type OperatorEvaluate = (params: Record<string, unknown>, context: OperatorContext) => unknown;
314
+ interface ValidateFinding {
315
+ severity: Severity;
316
+ message: string;
317
+ parameter?: string;
318
+ }
319
+ type OperatorValidate = (literalParams: Record<string, unknown>, helpers: ValidateHelpers) => ValidateFinding[];
320
+ interface ParameterDeclaration extends TypeDeclaration {
321
+ default?: unknown;
322
+ description?: string;
323
+ metadata?: Record<string, unknown>;
324
+ evaluation?: EvaluationMode;
325
+ over?: string;
326
+ truthiness?: boolean;
327
+ nullPolicy?: NullPolicy;
328
+ elementNullPolicy?: NullPolicyValue;
329
+ replacesNullAt?: readonly string[];
330
+ }
331
+ type ParameterDeclarations = Record<string, ParameterDeclaration>;
332
+ interface OperatorDefinition<P extends ParameterDeclarations = ParameterDeclarations> {
169
333
  name: string;
334
+ alias?: string;
335
+ category: OperatorCategory;
170
336
  description: string;
171
- aliases: string[];
172
- required: boolean;
337
+ metadata?: Record<string, unknown>;
338
+ parameters: P;
339
+ positionalParams?: readonly string[];
340
+ timeoutParam?: string;
341
+ useCache?: boolean;
342
+ cache?: 'auto' | 'manual';
343
+ validate?: OperatorValidate;
344
+ evaluate: (params: ResolvedParams<P>, context: OperatorContext) => unknown;
345
+ returns?: ExpectedType;
346
+ }
347
+ declare const VALIDATED_OPERATOR: unique symbol;
348
+ interface ValidatedParameter {
173
349
  type: ExpectedType;
350
+ required: boolean;
174
351
  default?: unknown;
352
+ description?: string;
353
+ metadata?: Record<string, unknown>;
354
+ evaluation: EvaluationMode;
355
+ truthiness: boolean;
356
+ nullPolicy: NullPolicyValue | CompiledNullPolicy;
357
+ elementNullPolicy?: NullPolicyValue;
358
+ constraints?: Constraints;
359
+ over?: string;
360
+ replacesNullAt?: string[];
175
361
  }
176
- interface FragmentParameterMetadata {
362
+ interface ValidatedOperatorDefinition {
363
+ readonly [VALIDATED_OPERATOR]: true;
177
364
  name: string;
178
- type: string | string[];
179
- required: boolean;
180
- description?: string;
365
+ alias?: string;
366
+ category: OperatorCategory;
367
+ description: string;
368
+ metadata?: Record<string, unknown>;
369
+ parameters: Record<string, ValidatedParameter>;
370
+ positionalParams?: string[];
371
+ restParam: string | null;
372
+ resolution: ResolutionPlan;
373
+ deliversLazily: boolean;
374
+ timeoutParam: string | null;
375
+ useCache: boolean;
376
+ cache: 'auto' | 'manual';
377
+ fingerprint: string;
378
+ validate?: OperatorValidate;
379
+ evaluate: OperatorEvaluate;
380
+ returns: ExpectedType;
381
+ }
382
+ type DeclarationEntry = readonly [name: string, declared: ValidatedParameter];
383
+ interface ResolutionPlan {
384
+ readonly entries: readonly DeclarationEntry[];
385
+ readonly whole: readonly DeclarationEntry[];
386
+ readonly perElement: readonly DeclarationEntry[];
387
+ }
388
+
389
+ declare const isTruthy: (value: unknown) => boolean;
390
+
391
+ declare const compareValues: (a: number | string, b: number | string) => -1 | 0 | 1;
392
+
393
+ declare const ARRAY = "<array>";
394
+ declare const OBJECT = "<object>";
395
+ declare const renderText: (value: unknown) => string;
396
+
397
+ declare const WILDCARD: unique symbol;
398
+ type Wildcard = typeof WILDCARD;
399
+ type PathSegment = string | number | Wildcard;
400
+ interface ResolveResult {
401
+ found: boolean;
402
+ value: unknown;
403
+ }
404
+ declare const parsePath: (path: string) => PathSegment[];
405
+ declare const resolvePath: (source: unknown, path: string | PathSegment[]) => ResolveResult;
406
+
407
+ declare const deepEqual: (foo: any, bar: any) => boolean;
408
+
409
+ interface FragmentParameterDeclaration extends TypeDeclaration {
181
410
  default?: unknown;
411
+ description?: string;
412
+ metadata?: Record<string, unknown>;
182
413
  }
183
- interface OperatorData {
184
- description: string;
185
- aliases: string[];
186
- parameters: OperatorParameterMetadata[];
414
+ interface FragmentDefinition {
415
+ expression: unknown;
416
+ parameters?: Record<string, FragmentParameterDeclaration>;
417
+ description?: string;
418
+ metadata?: Record<string, unknown>;
187
419
  }
188
- type OperatorMetadata = OperatorData & {
189
- name: Operator;
190
- parseChildren: ParseChildrenMethod;
191
- };
192
- type FragmentMetadata = FragmentData & {
193
- name: string;
420
+ interface FragmentParameter {
421
+ type: ExpectedType;
422
+ required: boolean;
423
+ default?: unknown;
424
+ description?: string;
425
+ metadata?: Record<string, unknown>;
426
+ constraints?: Constraints;
427
+ }
428
+
429
+ type EvaluationOptions = Omit<FigTreeOptions, 'operators' | 'fragments'>;
430
+ type CallOptions = Pick<FigTreeOptions, 'data' | 'signal' | 'timeout' | 'mode' | 'trace'>;
431
+ type OnlyCallOptions<CallOpts> = CallOpts & {
432
+ [Key in Exclude<keyof CallOpts, keyof CallOptions>]: never;
194
433
  };
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;
434
+ interface FigTreeOptions {
435
+ data?: Record<string, unknown>;
436
+ fragments?: Record<string, FragmentDefinition>;
437
+ operators?: (ValidatedOperatorDefinition | ValidatedOperatorDefinition[])[];
438
+ operatorDefaults?: {
439
+ [operator: string]: {
440
+ [param: string]: unknown;
441
+ };
442
+ };
443
+ http?: {
444
+ baseEndpoint?: string;
445
+ headers?: Record<string, string>;
227
446
  };
228
- getVersion: () => string;
447
+ graphQL?: {
448
+ endpoint?: string;
449
+ headers?: Record<string, string>;
450
+ };
451
+ strictDataPaths?: boolean;
452
+ maxDepth?: number;
453
+ maxNodes?: number;
454
+ timeout?: number;
455
+ signal?: AbortSignal;
456
+ useCache?: boolean;
457
+ cache?: {
458
+ store?: CacheStore;
459
+ maxSize?: number;
460
+ maxTime?: number;
461
+ };
462
+ runtimeTypeCheck?: boolean;
463
+ mode?: 'throw' | 'report';
464
+ trace?: boolean;
229
465
  }
230
- declare const evaluateExpression: (expression: EvaluatorNode, options?: FigTreeOptions) => Promise<EvaluatorOutput>;
466
+ interface EvaluationResult {
467
+ result: unknown;
468
+ errors: FigTreeError[];
469
+ trace?: TraceNode;
470
+ }
471
+ type NoOptions = Record<never, never>;
472
+ type Merge<Instance, Call> = Omit<Instance, keyof Call> & Call;
473
+ type ResultShape<O> = O extends {
474
+ mode: 'report';
475
+ } | {
476
+ trace: true;
477
+ } ? EvaluationResult : unknown;
231
478
 
232
- declare class FigTreeError extends Error {
233
- operator?: Operator;
479
+ interface Dependencies {
480
+ data: {
481
+ paths: string[];
482
+ dynamic: boolean;
483
+ };
484
+ operators: string[];
485
+ fragments: string[];
486
+ }
487
+ interface ParameterInfo extends ValidatedParameter {
488
+ instanceDefault?: unknown;
489
+ }
490
+ interface OperatorInfo extends Omit<ValidatedOperatorDefinition, typeof VALIDATED_OPERATOR | 'evaluate' | 'validate' | 'deliversLazily' | 'resolution' | 'fingerprint' | 'parameters'> {
491
+ parameters: Record<string, ParameterInfo>;
492
+ hasValidate: boolean;
493
+ instanceUseCache?: boolean;
494
+ instanceFallback?: unknown;
495
+ }
496
+ interface FragmentInfo {
497
+ name: string;
498
+ description?: string;
499
+ metadata?: Record<string, unknown>;
500
+ parameters: Record<string, FragmentParameter>;
501
+ warnings: Issue[];
502
+ dependencies: Dependencies;
503
+ }
504
+
505
+ declare class FigTree<InstanceOpts extends FigTreeOptions = NoOptions> {
506
+ private state;
507
+ private readonly results;
508
+ readonly version = "3.0.0-preview.1";
509
+ constructor(options?: InstanceOpts);
510
+ updateOptions(options?: FigTreeOptions): void;
511
+ clearCache(): void;
512
+ getOptions(): EvaluationOptions;
513
+ getOperators(): OperatorInfo[];
514
+ getFragments(): FragmentInfo[];
515
+ validate(expression: unknown, options?: CallOptions): ValidationResult;
516
+ getDependencies(expression: unknown): Dependencies;
517
+ isEvaluable(expression: unknown): boolean;
518
+ evaluate<CallOpts extends CallOptions = NoOptions>(expression: unknown, options?: OnlyCallOptions<CallOpts>): Promise<ResultShape<Merge<InstanceOpts, CallOpts>>>;
519
+ compile(expression: unknown): CompiledExpression<InstanceOpts>;
520
+ }
521
+ declare class CompiledExpression<InstanceOpts extends FigTreeOptions = NoOptions> {
522
+ #private;
523
+ private constructor();
524
+ get expression(): unknown;
525
+ get issues(): readonly Issue[];
526
+ get hasErrors(): boolean;
527
+ evaluate<CallOpts extends CallOptions = NoOptions>(options?: OnlyCallOptions<CallOpts>): Promise<ResultShape<Merge<InstanceOpts, CallOpts>>>;
528
+ getDependencies(): Dependencies;
529
+ }
530
+
531
+ declare function defineOperator(definition: ValidatedOperatorDefinition): ValidatedOperatorDefinition;
532
+ declare function defineOperator<const P extends ParameterDeclarations>(definition: OperatorDefinition<P>): ValidatedOperatorDefinition;
533
+
534
+ declare const coreOperators: ValidatedOperatorDefinition[];
535
+
536
+ interface OperatorFailureInit {
537
+ code?: string;
234
538
  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
539
  }
241
- declare const isFigTreeError: (input: unknown) => input is FigTreeError;
540
+ declare class OperatorFailure extends Error {
541
+ code?: string;
542
+ errorData?: Record<string, unknown>;
543
+ constructor(message: string, init?: OperatorFailureInit);
544
+ }
545
+ declare const isOperatorFailure: (input: unknown) => input is OperatorFailure;
242
546
 
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
- };
547
+ declare const httpOperators: (client?: HttpClient) => ValidatedOperatorDefinition[];
548
+ declare const sqlOperators: (connection: SqlConnection) => ValidatedOperatorDefinition[];
249
549
 
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;
550
+ type FetchLike = (input: string, init?: {
551
+ method?: string;
552
+ headers?: Record<string, string>;
553
+ body?: string;
554
+ signal?: AbortSignal;
555
+ }) => Promise<FetchResponseLike>;
556
+ interface FetchResponseLike {
557
+ ok: boolean;
558
+ status: number;
559
+ statusText: string;
560
+ url: string;
561
+ text(): Promise<string>;
562
+ }
563
+ interface AxiosLike {
564
+ (config: {
565
+ url: string;
566
+ method: 'get' | 'post';
567
+ headers?: Record<string, string>;
568
+ data?: unknown;
569
+ signal?: AbortSignal;
570
+ }): Promise<{
571
+ data: unknown;
572
+ status: number;
573
+ statusText: string;
574
+ }>;
575
+ isAxiosError(payload: unknown): payload is AxiosErrorLike;
576
+ }
577
+ interface AxiosErrorLike {
578
+ message: string;
579
+ config?: {
580
+ url?: string;
581
+ };
582
+ response?: {
583
+ status: number;
584
+ statusText: string;
585
+ data: unknown;
586
+ };
587
+ }
588
+ declare class FetchClient implements HttpClient {
589
+ private readonly supplied?;
590
+ constructor(fetchImpl?: FetchLike);
591
+ request: (req: HttpRequest) => Promise<unknown>;
592
+ }
593
+ declare class AxiosClient implements HttpClient {
594
+ private readonly axios;
595
+ constructor(axios: AxiosLike);
596
+ request: (req: HttpRequest) => Promise<unknown>;
597
+ }
598
+
599
+ interface PgClientLike {
600
+ query(config: {
601
+ text: string;
602
+ values?: unknown[];
603
+ }): Promise<{
604
+ rows: Record<string, unknown>[];
605
+ }>;
606
+ }
607
+ interface SqliteDatabaseLike {
608
+ all(sql: string, params?: unknown[] | Record<string, unknown>): Promise<Record<string, unknown>[]>;
609
+ }
610
+ declare class PostgresConnection implements SqlConnection {
611
+ private readonly client;
612
+ constructor(client: PgClientLike);
613
+ query: (req: SqlRequest) => Promise<Record<string, unknown>[]>;
614
+ }
615
+ declare class SQLiteConnection implements SqlConnection {
616
+ private readonly db;
617
+ constructor(db: SqliteDatabaseLike);
618
+ query: (req: SqlRequest) => Promise<Record<string, unknown>[]>;
619
+ }
620
+
621
+ type Json = null | boolean | number | string | Json[] | {
622
+ [key: string]: Json;
260
623
  };
624
+ type Path = (string | number)[];
261
625
 
262
- declare const preProcessShorthand: (expression: EvaluatorNode, fragments: Fragments | undefined, functionNames: string[], useShorthand?: boolean) => EvaluatorNode | FragmentNode;
626
+ type NodeMap = Record<string, InspectNode>;
627
+ type InspectNode = {
628
+ order: number;
629
+ path: Path;
630
+ } & ({
631
+ kind: 'constant';
632
+ value: Json;
633
+ } | {
634
+ kind: 'reference';
635
+ reference: string;
636
+ authored: string;
637
+ binding?: string;
638
+ } | {
639
+ kind: 'operator';
640
+ vars?: NodeMap;
641
+ operator: string;
642
+ params: NodeMap;
643
+ fallback?: InspectNode;
644
+ timeoutFallback?: Json;
645
+ useCache?: boolean;
646
+ instanceDefaults?: string[];
647
+ } | {
648
+ kind: 'fragmentCall';
649
+ vars?: NodeMap;
650
+ fragment: string;
651
+ resolved: boolean;
652
+ argumentsMode: 'static' | 'dynamic';
653
+ parameters?: NodeMap | InspectNode;
654
+ fallback?: InspectNode;
655
+ timeoutFallback?: Json;
656
+ } | {
657
+ kind: 'skeleton';
658
+ vars?: NodeMap;
659
+ shape: Json;
660
+ holes: {
661
+ at: Path;
662
+ node: InspectNode;
663
+ }[];
664
+ } | {
665
+ kind: 'elements';
666
+ elements: InspectNode[];
667
+ } | {
668
+ kind: 'entries';
669
+ vars?: NodeMap;
670
+ entries: NodeMap;
671
+ } | {
672
+ kind: 'invalid';
673
+ raw: Json;
674
+ });
263
675
 
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;
676
+ type InspectIssue = Issue & {
677
+ order?: number;
678
+ };
679
+ interface InspectDependencies {
680
+ dataPaths: string[];
681
+ dynamic: boolean;
682
+ operators: string[];
683
+ fragments: string[];
684
+ }
685
+ interface InspectReport {
686
+ version: string;
687
+ expression: Json;
688
+ options: Record<string, Json>;
689
+ canonicalForm: InspectNode;
690
+ issues: InspectIssue[];
691
+ timeoutShielded: boolean;
692
+ nodeCount: number;
693
+ maxDepth: number;
694
+ dependencies: InspectDependencies;
695
+ own: {
696
+ nodeCount: number;
697
+ maxDepth: number;
698
+ dependencies: InspectDependencies;
699
+ };
700
+ }
701
+ declare const inspect: <InstanceOpts extends FigTreeOptions>(compiled: CompiledExpression<InstanceOpts>, options?: CallOptions) => InspectReport;
271
702
 
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;
703
+ interface OperatorHints {
704
+ displayName: string;
705
+ docUrl: string;
706
+ backgroundColor: string;
707
+ textColor: string;
708
+ seeds?: {
709
+ [parameter: string]: unknown;
710
+ };
711
+ }
712
+ type FragmentHints = Omit<OperatorHints, 'docUrl'> & {
713
+ docUrl?: string;
714
+ };
715
+ interface CategoryHints {
716
+ displayName: string;
717
+ order: number;
718
+ backgroundColor: string;
719
+ textColor: string;
720
+ }
721
+ type OperatorHintMap = {
722
+ [operator: string]: OperatorHints;
723
+ };
724
+ type CategoryHintMap = {
725
+ [category in OperatorCategory]: CategoryHints;
726
+ };
727
+ type TypeSeeds = {
728
+ [type in BasicType]: unknown;
729
+ };
274
730
 
275
- declare const convertToShorthand: (expression: EvaluatorNode, figTree: FigTreeEvaluator, arrayThreshold?: number) => EvaluatorNode;
731
+ interface MigrationIssue {
732
+ 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';
733
+ tag: 'non-convertible' | 'intentional-semantic-change' | 'lossy-default';
734
+ path: (string | number)[];
735
+ message: string;
736
+ }
737
+ interface MigrationResult {
738
+ expression: unknown;
739
+ issues: MigrationIssue[];
740
+ }
741
+ interface FragmentMigrationResult {
742
+ fragments: Record<string, FragmentDefinition>;
743
+ issues: MigrationIssue[];
744
+ }
745
+ interface V2Options {
746
+ fragments?: Record<string, unknown>;
747
+ functions?: readonly string[] | Record<string, unknown>;
748
+ evaluateFullObject?: boolean;
749
+ noShorthand?: boolean;
750
+ caseInsensitive?: boolean;
751
+ useCache?: boolean;
752
+ }
276
753
 
277
- declare const convertFromShorthand: (expression: EvaluatorNode, figTree: FigTreeEvaluator) => EvaluatorNode;
754
+ interface Registry {
755
+ getOperators(): readonly {
756
+ name: string;
757
+ alias?: string;
758
+ positionalParams?: readonly string[];
759
+ restParam: string | null;
760
+ }[];
761
+ getFragments(): readonly {
762
+ name: string;
763
+ }[];
764
+ }
765
+ type Spelling = 'preserve' | 'canonical' | 'alias';
766
+ interface NameOptions {
767
+ referenceNames?: Spelling;
768
+ }
769
+ interface CanonicalOptions extends NameOptions {
770
+ operatorNames?: Spelling;
771
+ referencesAsGet?: boolean;
772
+ }
773
+ interface ShorthandOptions extends NameOptions {
774
+ operatorNames?: Spelling;
775
+ arguments?: 'positional' | 'named';
776
+ getAsReference?: boolean;
777
+ }
278
778
 
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 };
779
+ 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 };
780
+ 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, OnlyCallOptions, OperatorCategory, OperatorContext, OperatorDefinition, OperatorEvaluate, OperatorFailureInit, OperatorHintMap, OperatorHints, OperatorInfo, OperatorValidate, ParamValue, ParameterDeclaration, ParameterDeclarations, ParameterInfo, PathSegment, PerElement, PgClientLike, QueryTraceEvent, 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 };