fig-tree-evaluator 3.0.0-preview.13 → 3.0.0-preview.15
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/authoring/index.js +1 -1
- package/build/catalog/index.d.ts +25 -21
- package/build/catalog/index.js +1 -1
- package/build/chunks/engine.js +1 -1
- package/build/chunks/shared.js +1 -1
- package/build/index.d.ts +52 -39
- package/build/index.js +1 -1
- package/build/migrate/index.js +1 -1
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const version = "3.0.0-preview.
|
|
1
|
+
declare const version = "3.0.0-preview.15";
|
|
2
2
|
|
|
3
3
|
interface HttpRequest {
|
|
4
4
|
url: string;
|
|
@@ -421,7 +421,7 @@ interface ValidateFinding {
|
|
|
421
421
|
message: string;
|
|
422
422
|
parameter?: string;
|
|
423
423
|
}
|
|
424
|
-
type OperatorValidate = (literalParams: Record<string, unknown>, helpers: ValidateHelpers) => ValidateFinding[];
|
|
424
|
+
type OperatorValidate = (literalParams: Record<string, unknown>, helpers: ValidateHelpers, authored: ReadonlySet<string>) => ValidateFinding[];
|
|
425
425
|
interface ParameterDeclaration extends TypeDeclaration {
|
|
426
426
|
default?: unknown;
|
|
427
427
|
metadata?: Record<string, unknown>;
|
|
@@ -480,6 +480,7 @@ interface ValidatedOperatorDefinition {
|
|
|
480
480
|
evaluate: OperatorEvaluate;
|
|
481
481
|
returns: ExpectedType;
|
|
482
482
|
}
|
|
483
|
+
type OperatorEntry = ValidatedOperatorDefinition | readonly ValidatedOperatorDefinition[];
|
|
483
484
|
type DeclarationEntry = readonly [name: string, declared: ValidatedParameter];
|
|
484
485
|
interface ResolutionPlan {
|
|
485
486
|
readonly entries: readonly DeclarationEntry[];
|
|
@@ -579,7 +580,7 @@ interface Dependencies {
|
|
|
579
580
|
interface ParameterInfo extends ValidatedParameter {
|
|
580
581
|
hostDefault?: unknown;
|
|
581
582
|
}
|
|
582
|
-
interface OperatorInfo extends Omit<ValidatedOperatorDefinition, typeof VALIDATED_OPERATOR | 'evaluate' | 'validate' | 'deliversLazily' | 'resolution' | 'fingerprint' | 'parameters'> {
|
|
583
|
+
interface OperatorInfo extends Omit<ValidatedOperatorDefinition, typeof VALIDATED_OPERATOR | 'evaluate' | 'validate' | 'deliversLazily' | 'resolution' | 'fingerprint' | 'analysis' | 'parameters'> {
|
|
583
584
|
parameters: Record<string, ParameterInfo>;
|
|
584
585
|
hasValidate: boolean;
|
|
585
586
|
hostNoCache?: true;
|
|
@@ -628,7 +629,10 @@ type TypeSeeds = {
|
|
|
628
629
|
interface CatalogCategory extends CategoryListing {
|
|
629
630
|
name: OperatorCategory;
|
|
630
631
|
}
|
|
632
|
+
type NullOutcome = 'propagate' | 'value' | 'unset' | 'error' | 'none';
|
|
631
633
|
interface CatalogParameter extends ParameterInfo {
|
|
634
|
+
nullOutcome: NullOutcome | CompiledNullPolicy;
|
|
635
|
+
elementNullOutcome?: NullPolicyValue | 'error';
|
|
632
636
|
description?: string;
|
|
633
637
|
seed: unknown;
|
|
634
638
|
}
|
|
@@ -681,16 +685,14 @@ interface FragmentParameter {
|
|
|
681
685
|
|
|
682
686
|
type EvaluationOptions = Omit<FigTreeOptions, 'operators' | 'fragments'>;
|
|
683
687
|
type CallOptions = Pick<FigTreeOptions, 'data' | 'signal' | 'timeout' | 'trace'>;
|
|
684
|
-
type OnlyCallOptions<CallOpts> = CallOpts & {
|
|
685
|
-
[Key in Exclude<keyof CallOpts, keyof CallOptions>]: never;
|
|
686
|
-
};
|
|
687
688
|
type ValidateOptions = CallOptions & {
|
|
688
689
|
params?: readonly string[];
|
|
689
690
|
};
|
|
691
|
+
type HeaderDefaults = Record<string, string | number | boolean | null>;
|
|
690
692
|
interface FigTreeOptions {
|
|
691
693
|
data?: Record<string, unknown>;
|
|
692
694
|
fragments?: Record<string, FragmentDefinition>;
|
|
693
|
-
operators?:
|
|
695
|
+
operators?: readonly OperatorEntry[];
|
|
694
696
|
operatorDefaults?: {
|
|
695
697
|
[operator: string]: {
|
|
696
698
|
noCache?: true;
|
|
@@ -700,11 +702,11 @@ interface FigTreeOptions {
|
|
|
700
702
|
};
|
|
701
703
|
http?: {
|
|
702
704
|
baseEndpoint?: string;
|
|
703
|
-
headers?:
|
|
705
|
+
headers?: HeaderDefaults;
|
|
704
706
|
};
|
|
705
707
|
graphQL?: {
|
|
706
708
|
endpoint?: string;
|
|
707
|
-
headers?:
|
|
709
|
+
headers?: HeaderDefaults;
|
|
708
710
|
};
|
|
709
711
|
strictDataPaths?: boolean;
|
|
710
712
|
maxDepth?: number;
|
|
@@ -729,20 +731,18 @@ interface EvaluationResult {
|
|
|
729
731
|
result: unknown;
|
|
730
732
|
trace: TraceNode;
|
|
731
733
|
}
|
|
732
|
-
type
|
|
733
|
-
type Merge<Instance, Call> = Omit<Instance, keyof Call> & Call;
|
|
734
|
-
type ResultShape<O> = O extends {
|
|
735
|
-
trace: true;
|
|
736
|
-
} ? EvaluationResult : unknown;
|
|
734
|
+
type ResultShape<Trace extends boolean> = Trace extends true ? EvaluationResult : unknown;
|
|
737
735
|
|
|
738
|
-
declare class FigTree<
|
|
736
|
+
declare class FigTree<Trace extends boolean = false> {
|
|
739
737
|
private state;
|
|
740
738
|
private readonly results;
|
|
741
|
-
readonly version = "3.0.0-preview.
|
|
742
|
-
constructor(options?:
|
|
739
|
+
readonly version = "3.0.0-preview.15";
|
|
740
|
+
constructor(options?: FigTreeOptions & {
|
|
741
|
+
trace?: Trace;
|
|
742
|
+
});
|
|
743
743
|
private static fromState;
|
|
744
744
|
updateOptions(options?: OptionsUpdate): void;
|
|
745
|
-
with(update?: OptionsUpdate): FigTree<
|
|
745
|
+
with(update?: OptionsUpdate): FigTree<Trace>;
|
|
746
746
|
clearCache(): void;
|
|
747
747
|
getOptions(): EvaluationOptions;
|
|
748
748
|
getOperators(): OperatorInfo[];
|
|
@@ -750,16 +750,20 @@ declare class FigTree<InstanceOpts extends FigTreeOptions = NoOptions> {
|
|
|
750
750
|
validate(expression: unknown, options?: ValidateOptions): ValidationResult;
|
|
751
751
|
getDependencies(expression: unknown): Dependencies;
|
|
752
752
|
isEvaluable(expression: unknown): boolean;
|
|
753
|
-
evaluate<
|
|
754
|
-
|
|
753
|
+
evaluate<CallTrace extends boolean = Trace>(expression: unknown, options?: CallOptions & {
|
|
754
|
+
trace?: CallTrace;
|
|
755
|
+
}): Promise<ResultShape<CallTrace>>;
|
|
756
|
+
compile(expression: unknown): CompiledExpression<Trace>;
|
|
755
757
|
}
|
|
756
|
-
declare class CompiledExpression<
|
|
758
|
+
declare class CompiledExpression<Trace extends boolean = false> {
|
|
757
759
|
#private;
|
|
758
760
|
private constructor();
|
|
759
761
|
get expression(): unknown;
|
|
760
762
|
get issues(): readonly Issue[];
|
|
761
763
|
get hasErrors(): boolean;
|
|
762
|
-
evaluate<
|
|
764
|
+
evaluate<CallTrace extends boolean = Trace>(options?: CallOptions & {
|
|
765
|
+
trace?: CallTrace;
|
|
766
|
+
}): Promise<ResultShape<CallTrace>>;
|
|
763
767
|
getDependencies(): Dependencies;
|
|
764
768
|
}
|
|
765
769
|
|
|
@@ -768,6 +772,17 @@ declare function defineOperator<const P extends ParameterDeclarations>(definitio
|
|
|
768
772
|
|
|
769
773
|
declare const coreOperators: ValidatedOperatorDefinition[];
|
|
770
774
|
|
|
775
|
+
type OperatorSelector = string | {
|
|
776
|
+
category: OperatorCategory;
|
|
777
|
+
except?: string | readonly string[];
|
|
778
|
+
};
|
|
779
|
+
interface OperatorSetOptions {
|
|
780
|
+
only?: OperatorSelector | readonly OperatorSelector[];
|
|
781
|
+
except?: OperatorSelector | readonly OperatorSelector[];
|
|
782
|
+
replace?: ValidatedOperatorDefinition | readonly ValidatedOperatorDefinition[];
|
|
783
|
+
}
|
|
784
|
+
declare const operatorSet: (...args: [...operators: OperatorEntry[], options: OperatorSetOptions]) => ValidatedOperatorDefinition[];
|
|
785
|
+
|
|
771
786
|
interface OperatorFailureInit {
|
|
772
787
|
code?: FallbackErrorCode;
|
|
773
788
|
errorData?: Record<string, unknown>;
|
|
@@ -795,21 +810,19 @@ interface FetchResponseLike {
|
|
|
795
810
|
url: string;
|
|
796
811
|
text(): Promise<string>;
|
|
797
812
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
}>;
|
|
810
|
-
isAxiosError(payload: unknown): payload is AxiosErrorLike;
|
|
811
|
-
}
|
|
813
|
+
type AxiosLike = (config: {
|
|
814
|
+
url: string;
|
|
815
|
+
method: 'get' | 'post';
|
|
816
|
+
headers?: Record<string, string>;
|
|
817
|
+
data?: string;
|
|
818
|
+
signal?: AbortSignal;
|
|
819
|
+
}) => Promise<{
|
|
820
|
+
data: unknown;
|
|
821
|
+
status: number;
|
|
822
|
+
statusText: string;
|
|
823
|
+
}>;
|
|
812
824
|
interface AxiosErrorLike {
|
|
825
|
+
isAxiosError: true;
|
|
813
826
|
message: string;
|
|
814
827
|
config?: {
|
|
815
828
|
url?: string;
|
|
@@ -945,7 +958,7 @@ interface InspectReport {
|
|
|
945
958
|
dependencies: InspectDependencies;
|
|
946
959
|
};
|
|
947
960
|
}
|
|
948
|
-
declare const inspect: <
|
|
961
|
+
declare const inspect: <Trace extends boolean>(compiled: CompiledExpression<Trace>, options?: CallOptions) => InspectReport;
|
|
949
962
|
|
|
950
963
|
interface MigrationIssue {
|
|
951
964
|
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' | 'cache-opt-in' | 'instance-case-insensitive' | 'values-cut' | 'fallback-converted' | 'malformed-entry' | 'unreachable-branches' | 'overridden-value' | 'discarded-expression' | 'fragment-shorthand-payload' | 'shadowed-argument' | 'unknown-argument' | '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';
|
|
@@ -995,5 +1008,5 @@ interface ShorthandOptions extends NameOptions {
|
|
|
995
1008
|
getAsReference?: boolean;
|
|
996
1009
|
}
|
|
997
1010
|
|
|
998
|
-
export { ARRAY, AxiosClient, CompiledExpression, ErrorCodes, EvaluationData, FetchClient, FigTree, FigTreeError, OBJECT, OPERATOR_CATEGORIES, OperatorFailure, PostgresConnection, SQLiteConnection, WILDCARD, compareValues, coreOperators, deepEqual, defineOperator, httpFailure, httpOperators, inspect, isFigTreeError, isOperatorFailure, isTruthy, parsePath, renderText, resolvePath, sqlFailure, sqlOperators, version };
|
|
999
|
-
export type { AxiosErrorLike, AxiosLike, BasicType, CacheStore, CacheTraceEvent, CallOptions, CanonicalOptions, Catalog, CatalogCategory, CatalogFragment, CatalogFragmentParameter, CatalogOperator, CatalogParameter, CategoryListing, CategoryListingMap, CompiledNullPolicy, ConditionalNullPolicy, Constraints, CoverageFinding, CoveredFinding, DeclaredOutput, Dependencies, EvaluationMode, EvaluationOptions, EvaluationResult, ExpectedType, FailureRule, FailureTest, FallbackCoverage, FallbackCoverageOptions, FallbackError, FallbackErrorCode, FetchLike, FetchResponseLike, FigTreeErrorCode, FigTreeErrorInit, FigTreeOptions, FragmentDefinition, FragmentInfo, FragmentMetadata, FragmentMigrationResult, FragmentParameter, FragmentParameterDeclaration, HttpClient, HttpFailureInfo, HttpRequest, InspectDependencies, InspectIssue, InspectNode, InspectReport, Issue, KeyOverwriteTraceEvent, KnownTraceEvent, LazyValue, LiteralType,
|
|
1011
|
+
export { ARRAY, AxiosClient, CompiledExpression, ErrorCodes, EvaluationData, FetchClient, FigTree, FigTreeError, OBJECT, OPERATOR_CATEGORIES, OperatorFailure, PostgresConnection, SQLiteConnection, WILDCARD, compareValues, coreOperators, deepEqual, defineOperator, httpFailure, httpOperators, inspect, isFigTreeError, isOperatorFailure, isTruthy, operatorSet, parsePath, renderText, resolvePath, sqlFailure, sqlOperators, version };
|
|
1012
|
+
export type { AxiosErrorLike, AxiosLike, BasicType, CacheStore, CacheTraceEvent, CallOptions, CanonicalOptions, Catalog, CatalogCategory, CatalogFragment, CatalogFragmentParameter, CatalogOperator, CatalogParameter, CategoryListing, CategoryListingMap, CompiledNullPolicy, ConditionalNullPolicy, Constraints, CoverageFinding, CoveredFinding, DeclaredOutput, Dependencies, EvaluationMode, EvaluationOptions, EvaluationResult, ExpectedType, FailureRule, FailureTest, FallbackCoverage, FallbackCoverageOptions, FallbackError, FallbackErrorCode, FetchLike, FetchResponseLike, FigTreeErrorCode, FigTreeErrorInit, FigTreeOptions, FragmentDefinition, FragmentInfo, FragmentMetadata, FragmentMigrationResult, FragmentParameter, FragmentParameterDeclaration, HttpClient, HttpFailureInfo, HttpRequest, InspectDependencies, InspectIssue, InspectNode, InspectReport, Issue, KeyOverwriteTraceEvent, KnownTraceEvent, LazyValue, LiteralType, MigrationIssue, MigrationResult, NameOptions, NullOutcome, NullPolicy, NullPolicyValue, ObjectClass, OperatorAnalysis, OperatorCategory, OperatorContext, OperatorDefinition, OperatorEntry, OperatorEvaluate, OperatorFailureInit, OperatorInfo, OperatorListing, OperatorListingMap, OperatorSelector, OperatorSetOptions, OperatorValidate, OptionsUpdate, ParamValue, ParameterDeclaration, ParameterDeclarations, ParameterInfo, PathSegment, PerElement, PgClientLike, PositionalLayout, PositionalShape, QueryTraceEvent, ReferenceNamespace, ReferenceRecognition, ReferenceScope, 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, ValidateOptions, ValidatedOperatorDefinition, ValidatedParameter, ValidationResult, Wildcard };
|
package/build/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as t,k as r,O as n,l as i,m as o,o as s,E as l,c as u,p as c,b as p,R as m,q as f,u as y,f as h,w as v,x as b,y as g,z as w,A as P,B as j,t as $,s as D,h as O,C as N,D as q}from"./chunks/engine.js";export{G as ARRAY,F as FigTree,H as OBJECT,I as compareValues,e as coreOperators,J as deepEqual,d as isTruthy}from"./chunks/engine.js";import{E as x,l as A,R as E,m as C,i as S,r as L,d as T,D as R,n as z}from"./chunks/shared.js";export{F as FigTreeError,W as WILDCARD,a as isFigTreeError,k as parsePath}from"./chunks/shared.js";const Q=/*#__PURE__*/new Set(["failures","external","output"]),U=/*#__PURE__*/new Set(["code","parameter","when","options","may","overflow"]),M=e=>{if(null===e||["string","number","boolean"].includes(typeof e))return!0;if(!t(e))return!1;const a=Object.keys(e);if(1!==a.length)return!1;const n=e[a[0]];switch(a[0]){case"type":return r(n);case"below":return"number"==typeof n&&Number.isFinite(n);case"empty":case"invalid":return!0===n;case"supplied":return"boolean"==typeof n;case"some":case"not":return M(n);default:return!1}},V=["param","elementOf","kindOf","typeNamedBy","firstNonNull","sum","product","abs","min","max"],B=e=>void 0===e||"number"==typeof e&&Number.isFinite(e),Y=e=>void 0===e||Number.isInteger(e)&&e>=0,K=(e,t,...a)=>t in e&&Object.keys(e).every(e=>e===t||a.includes(e)),X=(e,a)=>{if(r(e))return!0;if(!t(e))return!1;const n=Object.keys(e);return 1===n.length&&V.includes(n[0])?a(e[n[0]]):"type"in e?(e=>{const{type:t,min:a,max:r,minLength:n}=e;return"number"===t||"integer"===t?K(e,"type","min","max")&&B(a)&&B(r)&&!(a>r):("string"===t||"array"===t)&&K(e,"type","minLength")&&Y(n)})(e):K(e,"difference")?Array.isArray(e.difference)&&2===e.difference.length&&e.difference.every(a):K(e,"arrayOf","minLength")?Y(e.minLength)&&X(e.arrayOf,a):K(e,"oneOf")?Array.isArray(e.oneOf)&&e.oneOf.length>0&&e.oneOf.every(e=>X(e,a)):!(!K(e,"byParam","cases","otherwise")||!("cases"in e))&&(a(e.byParam)&&t(e.cases)&&Object.values(e.cases).every(e=>X(e,a))&&(void 0===e.otherwise||X(e.otherwise,a)))},Z=/[a-z]Default$/,_=/*#__PURE__*/new Set(["eager","race","lazy","lazyElements","lazyEntries","perElement","structural"]),ee=/*#__PURE__*/new Set(n),te=/*#__PURE__*/new Set(["propagate","value"]),ae=e=>u([],e).ok,re=e=>ae(e)||u({},e).ok;function ne(e){if(i(e))return e;const a=[],n=t(e)?e.name:void 0,d="string"==typeof n?n:void 0,y=(e,t,r,n)=>{a.push({severity:"error",code:e,message:t,path:r,...void 0!==d?{operator:d}:{},...void 0!==n?{parameter:n}:{}})};if(!t(e))throw y(x.invalidDefinition,"a definition must be a plain object",[]),o(x.invalidDefinition,a);const h=e;if("string"!=typeof h.name&&y(x.invalidDefinition,"'name' is required and must be a string",["name"]),t(h.parameters)||y(x.invalidDefinition,"'parameters' is required and must be an object of declarations (may be {})",["parameters"]),"function"!=typeof h.evaluate&&y(x.invalidDefinition,"'evaluate' is required and must be a function",["evaluate"]),a.length>0)throw o(x.invalidDefinition,a,d);"string"!=typeof h.category?y(x.invalidDefinition,`'category' is required and must be one of ${[...ee].join(", ")}`,["category"]):ee.has(h.category)||y(x.invalidDefinition,`'${h.category}' is not a category — expected one of ${[...ee].join(", ")}`,["category"]),void 0!==h.alias&&"string"!=typeof h.alias&&y(x.invalidDefinition,"'alias' must be a string",["alias"]),void 0!==h.cache&&!0!==h.cache&&y(x.invalidDefinition,"'cache' must be the literal true",["cache"]),void 0===h.metadata||t(h.metadata)||y(x.invalidDefinition,"'metadata' must be a plain object",["metadata"]),void 0===h.positionalParams||Array.isArray(h.positionalParams)&&!h.positionalParams.some(e=>"string"!=typeof e)||y(x.invalidDefinition,"'positionalParams' must be an array of parameter names",["positionalParams"]),void 0!==h.timeoutParam&&"string"!=typeof h.timeoutParam&&y(x.invalidDefinition,"'timeoutParam' must be a parameter name",["timeoutParam"]),void 0!==h.validate&&"function"!=typeof h.validate&&y(x.invalidDefinition,"'validate' must be a function",["validate"]),void 0===h.returns||r(h.returns)||y(x.invalidDefinition,"'returns' must be a metadata-vocabulary type",["returns"]);const v=(e,t,a)=>{e===l?y(x.invalidDefinition,"the EvaluationData sentinel is legal only as a parameter 'default'",t,a):Array.isArray(e)&&e.forEach((e,r)=>{e===l&&v(e,[...t,r],a)})};for(const[e,t]of Object.entries(h))"parameters"!==e&&"metadata"!==e&&v(t,[e]);const b=(e,t)=>{const a=A(e);a.ok?C(e)&&y(x.reservedName,`'${e}' is a reserved name`,t):y(x.invalidName,`'${e}': ${a.reason}`,t)};"string"==typeof h.name&&b(h.name,["name"]),"string"==typeof h.alias&&b(h.alias,["alias"]);const g=h.parameters,w={};for(const[e,a]of Object.entries(g)){const r=["parameters",e],n=A(e);n.ok?E.has(e)&&y(x.reservedName,`'${e}' is a reserved node key and cannot name a parameter`,r,e):y(x.invalidName,`'${e}': ${n.reason}`,r,e),t(a)?w[e]=a:y(x.invalidDefinition,`the declaration for '${e}' must be a plain object`,r,e)}const P={};for(const[e,a]of Object.entries(w)){const n=["parameters",e],i=e=>[...n,e],o=a;for(const[t,a]of Object.entries(o))"default"!==t&&"metadata"!==t&&v(a,i(t),e);let d=!0;void 0===o.type||r(o.type)||(y(x.invalidDefinition,"'type' must be a metadata-vocabulary type",i("type"),e),d=!1),d&&(P[e]=o.type??"any");let m=!1;if(void 0!==o.constraints){const t=s(o.constraints);t.ok?m=!0:y(x.invalidDefinition,`'constraints' is malformed: expected ${t.expected}, got ${t.actual}`,i("constraints"),e)}void 0!==o.required&&"boolean"!=typeof o.required&&y(x.invalidDefinition,"'required' must be a boolean",i("required"),e),void 0===o.metadata||t(o.metadata)||y(x.invalidDefinition,"'metadata' must be a plain object",i("metadata"),e);const f="default"in o;if(f&&!0===o.required&&y(x.invalidDefinition,"a 'default' contradicts 'required: true' — a default implies the parameter is optional",i("default"),e),f&&o.default!==l){const t=P[e];if(void 0!==t){const a=u(o.default,t);if(a.ok){if(m){const t=c(o.default,o);t.ok||y(x.typeCheck,`'default' violates the declared constraints: expected ${t.expected}, got ${t.actual}`,i("default"),e)}}else y(x.typeCheck,`'default' does not satisfy the declared type: expected ${a.expected}, got ${a.actual}`,i("default"),e)}}if(void 0===o.evaluation||_.has(o.evaluation)||y(x.invalidDefinition,`'evaluation' must be one of ${[..._].join(", ")}`,i("evaluation"),e),void 0!==o.truthiness&&"boolean"!=typeof o.truthiness&&y(x.invalidDefinition,"'truthiness' must be a boolean",i("truthiness"),e),void 0!==o.over&&"string"!=typeof o.over&&y(x.invalidDefinition,"'over' must be a parameter name",i("over"),e),void 0===o.replacesNullAt||Array.isArray(o.replacesNullAt)&&!o.replacesNullAt.some(e=>"string"!=typeof e)||y(x.invalidDefinition,"'replacesNullAt' must be an array of sibling parameter names",i("replacesNullAt"),e),void 0!==o.nullPolicy){const t=o.nullPolicy;"function"==typeof t||te.has(t)||y(x.invalidNullPolicy,"'nullPolicy' must be 'propagate', 'value' or a conditional function",i("nullPolicy"),e);const a=P[e];void 0===a||p(a)||y(x.invalidNullPolicy,"'nullPolicy' is legal only where the declared type names 'null' — a type without 'null' is the reject declaration",i("nullPolicy"),e),!0===o.truthiness&&"propagate"===t&&y(x.invalidNullPolicy,"'truthiness' implies null policy 'value' (null is falsy) — declaring 'propagate' is a conflict",i("nullPolicy"),e)}if(void 0!==o.elementNullPolicy){te.has(o.elementNullPolicy)||y(x.invalidNullPolicy,"'elementNullPolicy' must be 'propagate' or 'value' — the conditional form is not admitted here",i("elementNullPolicy"),e);const t=P[e];void 0===t||re(t)||y(x.invalidNullPolicy,"'elementNullPolicy' applies to container parameters only",i("elementNullPolicy"),e)}}if(Array.isArray(h.positionalParams)&&h.positionalParams.every(e=>"string"==typeof e)){const e=new Set,t=h.positionalParams;t.forEach((a,r)=>{const n=a.startsWith(m),i=n?a.slice(m.length):a;n&&r!==t.length-1&&y(x.invalidDefinition,`the rest entry '${a}' must be the last positional entry`,["positionalParams",r]),i in w||y(x.invalidDefinition,`positional entry '${a}' names no declared parameter`,["positionalParams",r]),e.has(i)&&y(x.invalidDefinition,`duplicate positional entry '${a}'`,["positionalParams",r]),e.add(i)})}for(const[e,t]of Object.entries(w)){const a=["parameters",e],r="perElement"===t.evaluation;if(void 0!==t.over&&"string"==typeof t.over)if(r){const r=t.over;if(r in w&&r!==e){const t=P[r];void 0===t||ae(t)||y(x.invalidDefinition,`the 'over' target '${r}' must admit an array`,[...a,"over"],e)}else y(x.invalidDefinition,`'over' names no sibling parameter ('${r}')`,[...a,"over"],e)}else y(x.invalidDefinition,"'over' is legal only with evaluation: 'perElement'",[...a,"over"],e);else r&&y(x.invalidDefinition,"evaluation: 'perElement' requires 'over' to name the iterated sibling",[...a,"evaluation"],e)}for(const[e,t]of Object.entries(w)){if(void 0===t.replacesNullAt)continue;if(!Array.isArray(t.replacesNullAt)||t.replacesNullAt.some(e=>"string"!=typeof e))continue;const a=["parameters",e,"replacesNullAt"];"lazy"!==t.evaluation&&y(x.invalidDefinition,"a 'replacesNullAt' holder must declare evaluation: 'lazy'",a,e);(t.required??!("default"in t))&&y(x.invalidDefinition,"a 'replacesNullAt' holder must be optional",a,e),"default"in t&&y(x.invalidDefinition,"a 'replacesNullAt' holder may not carry a 'default' — it is presence-sensitive by construction",a,e),t.replacesNullAt.forEach((t,r)=>{t===e?y(x.invalidDefinition,"'replacesNullAt' may not target the holder itself",[...a,r],e):t in w||y(x.invalidDefinition,`'replacesNullAt' target '${t}' names no sibling parameter`,[...a,r],e)})}for(const[e,t]of Object.entries(w))Z.test(e)&&"lazy"!==t.evaluation&&y(x.invalidDefinition,`'${e}' is named for the '…Default' family, so it must declare evaluation: 'lazy' — add 'replacesNullAt', read it as a LazyValue in the body, or rename it`,["parameters",e,"evaluation"],e);const j=ie(w,P,y);if("string"==typeof h.timeoutParam){void 0===w[h.timeoutParam]?y(x.invalidDefinition,`'timeoutParam' names no declared parameter ('${h.timeoutParam}')`,["timeoutParam"]):"integer"!==P[h.timeoutParam]&&y(x.invalidDefinition,"the 'timeoutParam' target must be 'integer'-typed",["timeoutParam"])}if(void 0!==h.analysis&&((e,a,r)=>{const n=(e,...t)=>r(x.invalidDefinition,e,["analysis",...t]);if(!t(e))return n("'analysis' must be a plain object");for(const t of Object.keys(e))Q.has(t)||n(`'${t}' is not an analysis field`,t);const{failures:i,external:o,output:s}=e,l=e=>"string"==typeof e&&Object.hasOwn(a,e);if(void 0!==o&&!0!==o&&n("'external' must be the literal true","external"),void 0===s||X(s,l)||n("'output' must be a type, or an output declaration naming declared parameters","output"),void 0!==i){if(!Array.isArray(i))return n("'failures' must be an array of rules","failures");!0===o&&n("an external operator declares no 'failures': it may fail whatever its inputs","failures"),i.forEach((e,a)=>{const r=(...e)=>["failures",a,...e];if(!t(e))return n("a rule must be a plain object",...r());for(const t of Object.keys(e))U.has(t)||n(`'${t}' is not a rule field`,...r(t));if("string"==typeof e.code&&""!==e.code||n("a rule's 'code' must be a non-empty string",...r("code")),void 0===e.parameter||l(e.parameter)||n("'parameter' names no declared parameter",...r("parameter")),void 0!==e.when)if(t(e.when))for(const[t,a]of Object.entries(e.when))l(t)?M(a)||n(`the test on '${t}' is malformed`,...r("when",t)):n(`'${t}' is not a declared parameter`,...r("when",t));else n("'when' must be an object of tests",...r("when"));void 0===e.options||t(e.options)||n("'options' must be a plain object",...r("options"));for(const t of["may","overflow"])void 0!==e[t]&&!0!==e[t]&&n(`'${t}' must be the literal true`,...r(t))})}})(h.analysis,w,(e,t,a)=>y(e,t,a)),a.length>0)throw o(x.invalidDefinition,a,d);return f(h,j)}const ie=(e,t,a)=>{const r=Object.entries(t).filter(([,e])=>S(e)).map(([e])=>e),n=new Map;for(const[i,o]of Object.entries(e)){if("function"!=typeof o.nullPolicy)continue;const e=["parameters",i,"nullPolicy"];if(1!==r.length){a(x.invalidNullPolicy,`a conditional 'nullPolicy' requires exactly one literal-union parameter in the definition — found ${r.length}`,e,i);continue}const s=r[0],l=t[s];if(!S(l))continue;const u=[];let c=!0;for(const t of l.literal){let r;try{r=o.nullPolicy(t)}catch(r){a(x.invalidNullPolicy,`the conditional 'nullPolicy' threw during compilation for member ${JSON.stringify(t)}: ${String(r)}`,e,i),c=!1;break}if("string"!=typeof r||!te.has(r)){a(x.invalidNullPolicy,`the conditional 'nullPolicy' must return 'propagate' or 'value' for every member — got ${JSON.stringify(r)} for ${JSON.stringify(t)}`,e,i),c=!1;break}u.push({value:t,policy:r})}c&&n.set(i,{selector:s,table:u})}return n},oe=e=>new y(`request failed (${e.status}): ${e.url}`,{code:x.httpStatus,errorData:{status:e.status,statusText:e.statusText,url:e.url,response:de(e.response)}}),se=(e,t,a)=>new y(e,{code:x.invalidResponse,errorData:{url:t,response:de(a)}}),le=(e,t)=>{const a=t instanceof Error?t.message:String(t),r=t??{},n={driver:e};"string"==typeof r.code&&(n.driverCode=r.code);for(const e of["table","column","constraint"])"string"==typeof r[e]&&(n[e]=r[e]);return new y(`${e}: ${a}`,{code:x.sqlError,errorData:n})},ue={http:{"http-status":{status:"number",statusText:"string",url:"string",response:"any"},"invalid-response":{url:"string",response:"any"}},sql:{"sql-error":{driver:"string",driverCode:["string","null"]}}},ce=async(e,t)=>{try{return await e()}catch(e){throw((e,t)=>{const a=ue[t];if(h(e)&&void 0!==e.code&&Object.hasOwn(a,e.code)){const t=e.errorData??{},r=a[e.code];if(Object.entries(r).every(([e,a])=>u(t[e]??null,a).ok))return e}return new y(e instanceof Error?e.message:String(e),{code:x.requestFailure})})(e,t)}},de=(e,t=500)=>"string"!=typeof e||e.length<=t?e:`${e.slice(0,t)}… (${e.length} characters)`;class pe{supplied;constructor(e){if(void 0===e&&"function"!=typeof globalThis.fetch)throw new y("FetchClient(): this runtime has no global fetch — pass one, new FetchClient(myFetch), or use another client such as new AxiosClient(axios)");this.supplied=e}request=async e=>{const t=this.supplied??globalThis.fetch,a=await t.call(globalThis,e.url,{method:e.method.toUpperCase(),headers:e.headers,...void 0!==e.body?{body:JSON.stringify(e.body)}:{},signal:e.signal}),r=await a.text();if(!a.ok)throw oe({status:a.status,statusText:a.statusText,url:a.url||e.url,response:ye(r)});return fe(r,a.url||e.url,a.status)}}class me{axios;constructor(e){if(this.axios=e,"function"!=typeof e||"function"!=typeof e.isAxiosError)throw new y("AxiosClient(axios): pass the axios import itself — new AxiosClient(axios)")}request=async e=>{try{const t=await this.axios({url:e.url,method:e.method,headers:e.headers,...void 0!==e.body?{data:e.body}:{},signal:e.signal});return""===t.data||void 0===t.data?null:t.data}catch(t){if(this.axios.isAxiosError(t)&&t.response)throw oe({status:t.response.status,statusText:t.response.statusText,url:t.config?.url??e.url,response:t.response.data});throw t}}}const fe=(e,t,a)=>{if(""===e.trim())return null;try{return JSON.parse(e)}catch{throw se(`response was not JSON (${a}): ${t}`,t,e)}},ye=e=>{if(""===e.trim())return null;try{return JSON.parse(e)}catch{return e}},he=/^https?:\/\//i,ve=(e,t,a)=>{const r=he.test(e)?e:be(a,e),n=ge(t),i=""===n?r:`${r}${r.includes("?")?"&":"?"}${n}`;try{new URL(i)}catch{throw new y(`'${i}' is not a valid URL`,{code:x.typeCheck})}return i},be=(e,t)=>{if(void 0===e||""===e)throw new y(`'${t}' is a relative URL and no http.baseEndpoint is configured`,{code:x.typeCheck});return""===t?e:`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`},ge=e=>{if(void 0===e)return"";const t=new URLSearchParams;for(const[a,r]of Object.entries(e))null!=r&&t.append(a,je(r,`query['${a}']`,"query"));return t.toString()},we=(...e)=>{const t={};for(const a of e)if(void 0!==a)for(const[e,r]of Object.entries(a))null!=r?t[e]=je(r,`headers['${e}']`,"header"):delete t[e];return t},Pe=e=>({Accept:"application/json",...e?{"Content-Type":"application/json"}:{}}),je=(e,t,a)=>{if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return b(e);throw new y(`${t} is ${g(e)} — a ${a} value must be a string, number or boolean; render it explicitly (join) or supply a fully-formed URL`,{code:x.typeCheck})},$e=e=>({method:e.method,url:e.url,headers:Object.fromEntries(Object.entries(e.headers).sort(([e],[t])=>e<t?-1:e>t?1:0)),...void 0!==e.body?{body:e.body}:{}}),ke=e=>Array.isArray(e)?e.length>0:t(e)?Object.keys(e).length>0:null!=e,De=(e,t)=>{if(void 0===t)return e;const a=L(e,v(t));return a.found?a.value:null},Oe=(e,a)=>{if(!t(e))throw new y("a row was not an object");const r=Object.values(e);if(1!==r.length)throw new y(`shape: '${a}' needs a single-column result — this row has ${r.length} columns; name the one column you want in the SQL`,{code:x.typeCheck});return r[0]},Ne={type:"integer",required:!1},qe={type:["string","array"],required:!1},xe=e=>P({name:"http",category:"io",parameters:{url:{type:"string"},method:{type:{literal:["get","post"]},default:"get"},query:{type:"object",required:!1,elementNullPolicy:"value"},body:{type:["string","number","boolean","array","object"],required:!1},headers:{type:"object",required:!1,elementNullPolicy:"value"},returnPath:qe,timeout:Ne},positionalParams:["url"],timeoutParam:"timeout",cache:!0,returns:"any",validate:({returnPath:e,method:t,body:a})=>[...j(e,"returnPath"),...Ce(t,a)],evaluate:async({url:t,method:a,query:r,body:n,headers:i,returnPath:o},s)=>{if("get"===a&&void 0!==n)throw new y("a GET carries no body — did you mean method: 'post'?",{code:x.typeCheck});const l={method:a,url:ve(t,r,s.options.http?.baseEndpoint),headers:we(Pe(void 0!==n),s.options.http?.headers,i),...void 0!==n?{body:n}:{}},u=await s.cache.memo($e(l),()=>(Te(s,l),ce(()=>e.request({...l,signal:s.signal}),"http")));return De(u,o)}}),Ae=e=>P({name:"graphQL",category:"io",parameters:{query:{type:"string"},variables:{type:"object",required:!1,elementNullPolicy:"value"},url:{type:"string",required:!1},headers:{type:"object",required:!1,elementNullPolicy:"value"},returnPath:qe,timeout:Ne},positionalParams:["query","variables"],timeoutParam:"timeout",cache:!0,returns:"any",validate:({returnPath:e})=>j(e,"returnPath"),evaluate:async({query:a,variables:r,url:n,headers:i,returnPath:o},s)=>{const l=n??s.options.graphQL?.endpoint;if(void 0===l)throw new y("no endpoint — supply url, or set the graphQL.endpoint option");const u={method:"post",url:ve(l,void 0,s.options.http?.baseEndpoint),headers:we(Pe(!0),s.options.http?.headers,s.options.graphQL?.headers,i),body:{query:a,...ke(r)?{variables:r}:{}}},c=await s.cache.memo($e(u),async()=>{Te(s,u);return((e,a)=>{if(!t(e))throw se("the GraphQL response was not an object",a,e);const r=e.errors;if(Array.isArray(r)&&r.length>0){const e=r[0]?.message;throw new y(`the GraphQL response carried ${r.length} error${1===r.length?"":"s"}`+("string"==typeof e?`: ${e}`:""),{code:x.graphQLErrors,errorData:{errors:r}})}if(!("data"in e))throw se("the GraphQL response carried neither data nor errors",a,e);return e.data??null})(await ce(()=>e.request({...u,signal:s.signal}),"http"),u.url)});return De(c,o)}}),Ee=e=>P({name:"sql",category:"io",parameters:{query:{type:"string"},values:{type:["array","object"],required:!1,elementNullPolicy:"value"},shape:{type:{literal:["rows","firstRow","column","firstValue"]},default:"rows"},noRowDefault:{type:"any",default:null,nullPolicy:"value",evaluation:"lazy"},timeout:Ne},positionalParams:["query","...values"],timeoutParam:"timeout",cache:!0,returns:"any",evaluate:async({query:t,values:a,shape:r,noRowDefault:n},i)=>{const o={text:t,...ke(a)?{values:a}:{}};return(async(e,t,a)=>{switch(t){case"rows":return e;case"firstRow":return 0===e.length?a.evaluate():e[0];case"column":return e.map(e=>Oe(e,"column"));case"firstValue":return 0===e.length?a.evaluate():Oe(e[0],"firstValue")}})(await i.cache.memo(o,()=>(i.trace.note({type:"query",text:o.text}),ce(()=>e.query({...o,signal:i.signal}),"sql"))),r,n)}}),Ce=(e,t)=>void 0!==t&&"get"===e?[{severity:"error",parameter:"body",message:"a GET carries no body — add method: 'post', or drop the body"}]:[],Se=(e=new pe)=>[w(xe(e)),w(Ae(e))],Le=e=>[w(Ee(e))],Te=(e,t)=>{e.trace.note({type:"request",method:t.method,url:t.url,headers:Object.keys(t.headers)})};class Fe{client;constructor(e){if(this.client=e,"function"!=typeof e?.query)throw new y("PostgresConnection(client): pass a connected node-postgres Client or Pool")}query=async e=>{if(void 0!==e.values&&!Array.isArray(e.values))throw le("postgres","takes positional binds ($1, $2, …) — an object of named binds needs a driver that supports them");try{const t=await this.client.query({text:e.text,...void 0!==e.values?{values:e.values}:{}});return t?.rows??[]}catch(e){throw le("postgres",e)}}}class Re{db;constructor(e){if(this.db=e,"function"!=typeof e?.all)throw new y("SQLiteConnection(db): pass an open sqlite Database")}query=async e=>{try{return await this.db.all(e.text,e.values)??[]}catch(e){throw le("sqlite",e)}}}const ze=e=>Qe(e,0,new Set),Qe=(e,t,a)=>{if(null===e||"boolean"==typeof e||"string"==typeof e)return e;if("number"==typeof e&&Number.isFinite(e)&&!Object.is(e,-0))return e;if("object"!=typeof e)return Je(e);if(!Array.isArray(e)&&!T(e))return Ge(e);if(a.has(e))return"[circular]";if(t>=R)return"[too deep]";a.add(e);const r=Array.isArray(e)?Array.from(e,e=>Qe(e,t+1,a)):Object.fromEntries(Object.entries(e).map(([e,r])=>[e,Qe(r,t+1,a)]));return a.delete(e),r},Je=e=>{switch(typeof e){case"function":return""===e.name?"[function]":`[function ${e.name}]`;case"symbol":return`[${String(e)}]`;case"bigint":return`[bigint ${e}]`;case"number":return Object.is(e,-0)?"[-0]":`[${e}]`;default:return"[undefined]"}},Ge=e=>{const t=Ue(e);try{const a=e.toJSON;if("function"==typeof a){const r=a.call(e);if("string"==typeof r)return`[${t} ${r}]`}}catch{}return`[${t}]`},Ue=e=>{try{const t=e.constructor?.name;return"string"==typeof t&&""!==t?t:"Object"}catch{return"Object"}},Me=e=>{const t=new Map;for(const a of e.holes)void 0!==a.timeoutFallback&&t.set(a.node,a.timeoutFallback);const a=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,n(t)])),r=e=>{const a=t.get(e);return void 0===a?{}:{timeoutFallback:ze(a.value)}},n=e=>{const t={order:e.order,kind:e.kind,path:$(e.path)},i="vars"in e&&void 0!==e.vars?{vars:a(e.vars)}:{};switch(e.kind){case"constant":return{...t,kind:e.kind,value:ze(e.value)};case"reference":return{...t,kind:e.kind,reference:z(e.binding??e.namespace,e.segments),authored:e.raw,...void 0===e.binding?{}:{binding:e.binding}};case"operator":return{...t,kind:e.kind,...i,operator:e.name,params:a(e.params),...void 0===e.fallback?{}:{fallback:n(e.fallback)},...r(e),...void 0===e.noCache?{}:{noCache:e.noCache},...void 0===e.entry.hostDefaults?{}:{hostDefaults:Object.keys(e.entry.hostDefaults)}};case"fragmentCall":return{...t,kind:e.kind,...i,fragment:e.name,resolved:void 0!==e.entry,argumentsMode:e.argumentsMode,...void 0===e.parameters?{}:{parameters:"dynamic"===e.argumentsMode?n(e.parameters):a(e.parameters)},...void 0===e.fallback?{}:{fallback:n(e.fallback)},...r(e),...void 0===e.noCache?{}:{noCache:e.noCache}};case"skeleton":{const a=D(e.skeleton,e.holes,e.holes.map(()=>"<hole>"));return{...t,kind:e.kind,...i,shape:ze(a),holes:e.holes.map(e=>({at:[...e.at],node:n(e.node)}))}}case"elements":return{...t,kind:e.kind,elements:e.nodes.map(n)};case"entries":return{...t,kind:e.kind,...i,entries:a(e.entries)};case"invalid":return{...t,kind:e.kind,raw:ze(e.raw)}}};return n(e.root)},Ve=(e,t)=>{const a=O(e,t);if(void 0===a)throw new TypeError("inspect() takes a CompiledExpression — the handle fig.compile() returns");const{expression:r,artifact:n,options:i}=a;return{version:N,expression:ze(r),options:Ie(i),canonicalForm:Me(n),issues:q(n,i,({issue:e,order:t})=>({order:t,...e,path:[...e.path]})),timeoutShielded:n.timeoutShielded,nodeCount:n.nodeCount,maxDepth:n.maxDepth,dependencies:Ye(n.dependencies),own:{nodeCount:n.own.nodeCount,maxDepth:n.own.maxDepth,dependencies:Ye(n.own.dependencies)}}},Be="[supplied]",Ie=e=>Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e).map(([e,t])=>[e,We(e,t)])),We=(e,t)=>{switch(e){case"data":{const e="object"==typeof t&&null!==t?Object.keys(t).length:0;return`[supplied: ${e} top-level key${1===e?"":"s"}]`}case"signal":return Be;case"http":case"graphQL":return He(t,"headers",e=>"object"==typeof e&&null!==e?Object.fromEntries(Object.keys(e).map(e=>[e,"[redacted]"])):ze(e));case"cache":return He(t,"store",()=>Be);default:return ze(t)}},He=(e,t,a)=>"object"==typeof e&&null!==e?Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e).map(([e,r])=>[e,e===t?a(r):ze(r)])):ze(e),Ye=e=>({dataPaths:[...e.dataPaths.keys()],dynamic:e.dynamic,paramNames:[...e.paramNames],paramsDynamic:e.paramsDynamic,operators:[...e.operators],fragments:[...e.fragments]});export{me as AxiosClient,x as ErrorCodes,l as EvaluationData,pe as FetchClient,n as OPERATOR_CATEGORIES,y as OperatorFailure,Fe as PostgresConnection,Re as SQLiteConnection,ne as defineOperator,oe as httpFailure,Se as httpOperators,Ve as inspect,h as isOperatorFailure,b as renderText,L as resolvePath,le as sqlFailure,Le as sqlOperators,N as version};
|
|
1
|
+
import{i as t,o as n,O as r,p as i,q as o,u as s,E as l,c,w as u,b as d,R as p,x as m,y,z as h,A as v,B as g,C as b,j as w,D as $,G as O,H as j,I as D,J as x,K as N,t as A,s as q,l as C,L as E,M as L}from"./chunks/engine.js";export{P as ARRAY,F as FigTree,Q as OBJECT,S as compareValues,f as coreOperators,T as deepEqual,e as isTruthy}from"./chunks/engine.js";import{E as R,l as z,R as J,m as M,i as G,d as U,F as V,r as B,D as I,n as H}from"./chunks/shared.js";export{W as WILDCARD,a as isFigTreeError,k as parsePath}from"./chunks/shared.js";const K=/*#__PURE__*/new Set(["failures","external","output"]),Y=/*#__PURE__*/new Set(["code","parameter","when","options","may","overflow"]),X=e=>{if(null===e||["string","number","boolean"].includes(typeof e))return!0;if(!t(e))return!1;const a=Object.keys(e);if(1!==a.length)return!1;const r=e[a[0]];switch(a[0]){case"type":return n(r);case"below":return"number"==typeof r&&Number.isFinite(r);case"empty":case"invalid":return!0===r;case"supplied":return"boolean"==typeof r;case"some":case"not":return X(r);default:return!1}},Z=["param","elementOf","kindOf","typeNamedBy","firstNonNull","sum","product","abs","min","max"],_=e=>void 0===e||"number"==typeof e&&Number.isFinite(e),ee=e=>void 0===e||Number.isInteger(e)&&e>=0,te=(e,t,...a)=>t in e&&Object.keys(e).every(e=>e===t||a.includes(e)),ae=(e,a)=>{if(n(e))return!0;if(!t(e))return!1;const r=Object.keys(e);return 1===r.length&&Z.includes(r[0])?a(e[r[0]]):"type"in e?(e=>{const{type:t,min:a,max:n,minLength:r}=e;return"number"===t||"integer"===t?te(e,"type","min","max")&&_(a)&&_(n)&&!(a>n):("string"===t||"array"===t)&&te(e,"type","minLength")&&ee(r)})(e):te(e,"difference")?Array.isArray(e.difference)&&2===e.difference.length&&e.difference.every(a):te(e,"arrayOf","minLength")?ee(e.minLength)&&ae(e.arrayOf,a):te(e,"oneOf")?Array.isArray(e.oneOf)&&e.oneOf.length>0&&e.oneOf.every(e=>ae(e,a)):!(!te(e,"byParam","cases","otherwise")||!("cases"in e))&&(a(e.byParam)&&t(e.cases)&&Object.values(e.cases).every(e=>ae(e,a))&&(void 0===e.otherwise||ae(e.otherwise,a)))},ne=/[a-z]Default$/,re=/*#__PURE__*/new Set(["eager","race","lazy","lazyElements","lazyEntries","perElement","structural"]),ie=/*#__PURE__*/new Set(r),oe=/*#__PURE__*/new Set(["propagate","value"]),se=e=>c([],e).ok,le=e=>se(e)||c({},e).ok;function ce(e){if(i(e))return e;const a=[],r=t(e)?e.name:void 0,f="string"==typeof r?r:void 0,y=(e,t,n,r)=>{a.push({severity:"error",code:e,message:t,path:n,...void 0!==f?{operator:f}:{},...void 0!==r?{parameter:r}:{}})};if(!t(e))throw y(R.invalidDefinition,"a definition must be a plain object",[]),o(R.invalidDefinition,a);const h=e;if("string"!=typeof h.name&&y(R.invalidDefinition,"'name' is required and must be a string",["name"]),t(h.parameters)||y(R.invalidDefinition,"'parameters' is required and must be an object of declarations (may be {})",["parameters"]),"function"!=typeof h.evaluate&&y(R.invalidDefinition,"'evaluate' is required and must be a function",["evaluate"]),a.length>0)throw o(R.invalidDefinition,a,f);"string"!=typeof h.category?y(R.invalidDefinition,`'category' is required and must be one of ${[...ie].join(", ")}`,["category"]):ie.has(h.category)||y(R.invalidDefinition,`'${h.category}' is not a category — expected one of ${[...ie].join(", ")}`,["category"]),void 0!==h.alias&&"string"!=typeof h.alias&&y(R.invalidDefinition,"'alias' must be a string",["alias"]),void 0!==h.cache&&!0!==h.cache&&y(R.invalidDefinition,"'cache' must be the literal true",["cache"]),void 0===h.metadata||t(h.metadata)||y(R.invalidDefinition,"'metadata' must be a plain object",["metadata"]),void 0===h.positionalParams||Array.isArray(h.positionalParams)&&!h.positionalParams.some(e=>"string"!=typeof e)||y(R.invalidDefinition,"'positionalParams' must be an array of parameter names",["positionalParams"]),void 0!==h.timeoutParam&&"string"!=typeof h.timeoutParam&&y(R.invalidDefinition,"'timeoutParam' must be a parameter name",["timeoutParam"]),void 0!==h.validate&&"function"!=typeof h.validate&&y(R.invalidDefinition,"'validate' must be a function",["validate"]),void 0===h.returns||n(h.returns)||y(R.invalidDefinition,"'returns' must be a metadata-vocabulary type",["returns"]);const v=(e,t,a)=>{e===l?y(R.invalidDefinition,"the EvaluationData sentinel is legal only as a parameter 'default'",t,a):Array.isArray(e)&&e.forEach((e,n)=>{e===l&&v(e,[...t,n],a)})};for(const[e,t]of Object.entries(h))"parameters"!==e&&"metadata"!==e&&v(t,[e]);const g=(e,t)=>{const a=z(e);a.ok?M(e)&&y(R.reservedName,`'${e}' is a reserved name`,t):y(R.invalidName,`'${e}': ${a.reason}`,t)};"string"==typeof h.name&&g(h.name,["name"]),"string"==typeof h.alias&&g(h.alias,["alias"]);const b=h.parameters,w={};for(const[e,a]of Object.entries(b)){const n=["parameters",e],r=z(e);r.ok?J.has(e)&&y(R.reservedName,`'${e}' is a reserved node key and cannot name a parameter`,n,e):y(R.invalidName,`'${e}': ${r.reason}`,n,e),t(a)?w[e]=a:y(R.invalidDefinition,`the declaration for '${e}' must be a plain object`,n,e)}const $={};for(const[e,a]of Object.entries(w)){const r=["parameters",e],i=e=>[...r,e],o=a;for(const[t,a]of Object.entries(o))"default"!==t&&"metadata"!==t&&v(a,i(t),e);let p=!0;void 0===o.type||n(o.type)||(y(R.invalidDefinition,"'type' must be a metadata-vocabulary type",i("type"),e),p=!1),p&&($[e]=o.type??"any");let f=!1;if(void 0!==o.constraints){const t=s(o.constraints);t.ok?f=!0:y(R.invalidDefinition,`'constraints' is malformed: expected ${t.expected}, got ${t.actual}`,i("constraints"),e)}void 0!==o.required&&"boolean"!=typeof o.required&&y(R.invalidDefinition,"'required' must be a boolean",i("required"),e),void 0===o.metadata||t(o.metadata)||y(R.invalidDefinition,"'metadata' must be a plain object",i("metadata"),e);const m="default"in o;if(m&&!0===o.required&&y(R.invalidDefinition,"a 'default' contradicts 'required: true' — a default implies the parameter is optional",i("default"),e),m&&o.default!==l){const t=$[e];if(void 0!==t){const a=c(o.default,t);if(a.ok){if(f){const t=u(o.default,o);t.ok||y(R.typeCheck,`'default' violates the declared constraints: expected ${t.expected}, got ${t.actual}`,i("default"),e)}}else y(R.typeCheck,`'default' does not satisfy the declared type: expected ${a.expected}, got ${a.actual}`,i("default"),e)}}if(void 0===o.evaluation||re.has(o.evaluation)||y(R.invalidDefinition,`'evaluation' must be one of ${[...re].join(", ")}`,i("evaluation"),e),void 0!==o.truthiness&&"boolean"!=typeof o.truthiness&&y(R.invalidDefinition,"'truthiness' must be a boolean",i("truthiness"),e),void 0!==o.over&&"string"!=typeof o.over&&y(R.invalidDefinition,"'over' must be a parameter name",i("over"),e),void 0===o.replacesNullAt||Array.isArray(o.replacesNullAt)&&!o.replacesNullAt.some(e=>"string"!=typeof e)||y(R.invalidDefinition,"'replacesNullAt' must be an array of sibling parameter names",i("replacesNullAt"),e),void 0!==o.nullPolicy){const t=o.nullPolicy;"function"==typeof t||oe.has(t)||y(R.invalidNullPolicy,"'nullPolicy' must be 'propagate', 'value' or a conditional function",i("nullPolicy"),e);const a=$[e];void 0===a||d(a)||y(R.invalidNullPolicy,"'nullPolicy' is legal only where the declared type names 'null' — a type without 'null' is the reject declaration",i("nullPolicy"),e),!0===o.truthiness&&"propagate"===t&&y(R.invalidNullPolicy,"'truthiness' implies null policy 'value' (null is falsy) — declaring 'propagate' is a conflict",i("nullPolicy"),e)}if(void 0!==o.elementNullPolicy){oe.has(o.elementNullPolicy)||y(R.invalidNullPolicy,"'elementNullPolicy' must be 'propagate' or 'value' — the conditional form is not admitted here",i("elementNullPolicy"),e);const t=$[e];void 0===t||le(t)||y(R.invalidNullPolicy,"'elementNullPolicy' applies to container parameters only",i("elementNullPolicy"),e)}}if(Array.isArray(h.positionalParams)&&h.positionalParams.every(e=>"string"==typeof e)){const e=new Set,t=h.positionalParams;t.forEach((a,n)=>{const r=a.startsWith(p),i=r?a.slice(p.length):a;r&&n!==t.length-1&&y(R.invalidDefinition,`the rest entry '${a}' must be the last positional entry`,["positionalParams",n]),i in w||y(R.invalidDefinition,`positional entry '${a}' names no declared parameter`,["positionalParams",n]),e.has(i)&&y(R.invalidDefinition,`duplicate positional entry '${a}'`,["positionalParams",n]),e.add(i)})}for(const[e,t]of Object.entries(w)){const a=["parameters",e],n="perElement"===t.evaluation;if(void 0!==t.over&&"string"==typeof t.over)if(n){const n=t.over;if(n in w&&n!==e){const t=$[n];void 0===t||se(t)||y(R.invalidDefinition,`the 'over' target '${n}' must admit an array`,[...a,"over"],e)}else y(R.invalidDefinition,`'over' names no sibling parameter ('${n}')`,[...a,"over"],e)}else y(R.invalidDefinition,"'over' is legal only with evaluation: 'perElement'",[...a,"over"],e);else n&&y(R.invalidDefinition,"evaluation: 'perElement' requires 'over' to name the iterated sibling",[...a,"evaluation"],e)}for(const[e,t]of Object.entries(w)){if(void 0===t.replacesNullAt)continue;if(!Array.isArray(t.replacesNullAt)||t.replacesNullAt.some(e=>"string"!=typeof e))continue;const a=["parameters",e,"replacesNullAt"];"lazy"!==t.evaluation&&y(R.invalidDefinition,"a 'replacesNullAt' holder must declare evaluation: 'lazy'",a,e);(t.required??!("default"in t))&&y(R.invalidDefinition,"a 'replacesNullAt' holder must be optional",a,e),"default"in t&&y(R.invalidDefinition,"a 'replacesNullAt' holder may not carry a 'default' — it is presence-sensitive by construction",a,e),t.replacesNullAt.forEach((t,n)=>{t===e?y(R.invalidDefinition,"'replacesNullAt' may not target the holder itself",[...a,n],e):t in w||y(R.invalidDefinition,`'replacesNullAt' target '${t}' names no sibling parameter`,[...a,n],e)})}for(const[e,t]of Object.entries(w))ne.test(e)&&"lazy"!==t.evaluation&&y(R.invalidDefinition,`'${e}' is named for the '…Default' family, so it must declare evaluation: 'lazy' — add 'replacesNullAt', read it as a LazyValue in the body, or rename it`,["parameters",e,"evaluation"],e);const O=ue(w,$,y);if("string"==typeof h.timeoutParam){void 0===w[h.timeoutParam]?y(R.invalidDefinition,`'timeoutParam' names no declared parameter ('${h.timeoutParam}')`,["timeoutParam"]):"integer"!==$[h.timeoutParam]&&y(R.invalidDefinition,"the 'timeoutParam' target must be 'integer'-typed",["timeoutParam"])}if(void 0!==h.analysis&&((e,a,n)=>{const r=(e,...t)=>n(R.invalidDefinition,e,["analysis",...t]);if(!t(e))return r("'analysis' must be a plain object");for(const t of Object.keys(e))K.has(t)||r(`'${t}' is not an analysis field`,t);const{failures:i,external:o,output:s}=e,l=e=>"string"==typeof e&&Object.hasOwn(a,e);if(void 0!==o&&!0!==o&&r("'external' must be the literal true","external"),void 0===s||ae(s,l)||r("'output' must be a type, or an output declaration naming declared parameters","output"),void 0!==i){if(!Array.isArray(i))return r("'failures' must be an array of rules","failures");!0===o&&r("an external operator declares no 'failures': it may fail whatever its inputs","failures"),i.forEach((e,a)=>{const n=(...e)=>["failures",a,...e];if(!t(e))return r("a rule must be a plain object",...n());for(const t of Object.keys(e))Y.has(t)||r(`'${t}' is not a rule field`,...n(t));if("string"==typeof e.code&&""!==e.code||r("a rule's 'code' must be a non-empty string",...n("code")),void 0===e.parameter||l(e.parameter)||r("'parameter' names no declared parameter",...n("parameter")),void 0!==e.when)if(t(e.when))for(const[t,a]of Object.entries(e.when))l(t)?X(a)||r(`the test on '${t}' is malformed`,...n("when",t)):r(`'${t}' is not a declared parameter`,...n("when",t));else r("'when' must be an object of tests",...n("when"));void 0===e.options||t(e.options)||r("'options' must be a plain object",...n("options"));for(const t of["may","overflow"])void 0!==e[t]&&!0!==e[t]&&r(`'${t}' must be the literal true`,...n(t))})}})(h.analysis,w,(e,t,a)=>y(e,t,a)),a.length>0)throw o(R.invalidDefinition,a,f);return m(h,O)}const ue=(e,t,a)=>{const n=Object.entries(t).filter(([,e])=>G(e)).map(([e])=>e),r=new Map;for(const[i,o]of Object.entries(e)){if("function"!=typeof o.nullPolicy)continue;const e=["parameters",i,"nullPolicy"];if(1!==n.length){a(R.invalidNullPolicy,`a conditional 'nullPolicy' requires exactly one literal-union parameter in the definition — found ${n.length}`,e,i);continue}const s=n[0],l=t[s];if(!G(l))continue;const c=[];let u=!0;for(const t of l.literal){let n;try{n=o.nullPolicy(t)}catch(n){a(R.invalidNullPolicy,`the conditional 'nullPolicy' threw during compilation for member ${JSON.stringify(t)}: ${String(n)}`,e,i),u=!1;break}if("string"!=typeof n||!oe.has(n)){a(R.invalidNullPolicy,`the conditional 'nullPolicy' must return 'propagate' or 'value' for every member — got ${JSON.stringify(n)} for ${JSON.stringify(t)}`,e,i),u=!1;break}c.push({value:t,policy:n})}u&&r.set(i,{selector:s,table:c})}return r},de=["only","except","replace"],pe=(e,t)=>Array.isArray(e)?e.map((e,a)=>({value:e,path:[...t,a]})):[{value:e,path:t}],fe=(...e)=>{const t=[],a=(e,a,n,r)=>{t.push({severity:"error",code:e,message:a,path:n,...r})},n=(e,n)=>{throw a(R.invalidOptions,e,n),o(R.invalidOptions,t)},s=e.length-1,l=e[s],c="operatorSet() needs at least one operator before its options";0===e.length&&n(c,[]),U(l)&&!i(l)&&"name"in l&&"evaluate"in l&&n("the last argument has 'name' and 'evaluate' — if it is an operator, build it with defineOperator(); the options object comes last",[s]),U(l)&&!i(l)||n("the last argument must be the options object",[s]),1===e.length&&n(c,[]);const{only:u,except:d,replace:p}=l;for(const e of Object.keys(l))de.includes(e)||a(R.invalidOptions,`unknown option '${e}' — the options are only, except and replace`,[e]);const f=[],m=new Map,b=new Map,w=new Map;y(e.slice(0,s),{prefix:[],name:"arguments"},a,(e,t)=>{const{name:n,alias:r,category:i}=e;if(m.has(n))return void a(R.duplicateOperator,`two operators named '${n}' in the input — to swap one for the other, pass it as 'replace'`,t,{operator:n});f.push(e),m.set(n,e),void 0!==r&&b.set(r,n);const o=w.get(i);void 0===o?w.set(i,[n]):o.push(n)});const $=(e,t)=>{if(m.has(e))return e;const n=b.get(e);if(void 0!==n)return void a(R.invalidOptions,`selectors take canonical names — use '${n}', not its alias '${e}'`,t,{operator:n,suggestion:n});const r=v(e,m.keys());a(R.unknownOperator,`'${e}' names no operator in the input${g(r)}`,t,void 0===r?void 0:{suggestion:r})},O=e=>a(R.invalidOptions,"a selector is an operator name or { category, except? }",e),j=(e,t)=>{if("string"==typeof e){const a=$(e,t);return void 0===a?void 0:new Set([a])}if(U(e)&&"string"==typeof e.category&&!Object.keys(e).some(e=>"category"!==e&&"except"!==e))return((e,t)=>{const n=e.category;if(!r.includes(n)){const e=v(n,r);return void a(R.invalidOptions,`'${n}' is not a category${g(e)}`,[...t,"category"],void 0===e?void 0:{suggestion:e})}const i=w.get(n);if(void 0===i)return void a(R.invalidOptions,`no operator in the input has category '${n}'`,t);const o=[];let s=!0;if(void 0!==e.except)for(const{value:r,path:i}of pe(e.except,[...t,"except"])){if("string"!=typeof r){O(i),s=!1;continue}const e=$(r,i);void 0!==e?m.get(e)?.category===n?o.push(e):(a(R.invalidOptions,`'${e}' is not in category '${n}'`,i,{operator:e}),s=!1):s=!1}if(!s)return;const l=new Set(i.filter(e=>!o.includes(e)));if(0===l.size){const e=o.map(e=>`'${e}'`).join(", ");return void a(R.invalidOptions,`{ category: '${n}', except: [${e}] } selects nothing`,t)}return l})(e,t);O(t)},k=(e,t)=>void 0===e?void 0:pe(e,[t]).map(({value:e,path:t})=>({selector:e,path:t,names:j(e,t)})),P=k(u,"only"),D=k(d,"except"),x=P?.every(({names:e})=>void 0!==e)??!0,N=x&&(D?.every(({names:e})=>void 0!==e)??!0),A=void 0===P?new Set(m.keys()):new Set(P.flatMap(({names:e})=>[...e??[]])),q=new Set;for(const{selector:e,path:t,names:n}of D??[]){if(void 0===n)continue;const r=[...n].filter(e=>A.has(e));if(0===r.length&&void 0!==P&&x)a(R.invalidOptions,"string"==typeof e?`'${e}' is not among the operators 'only' kept`:`no operator in category '${e.category}' is among the operators 'only' kept`,t,"string"==typeof e?{operator:e}:void 0);else for(const e of r)q.add(e)}const C=new Map;if(void 0!==p)for(const{value:e,path:t}of pe(p,["replace"])){if(Array.isArray(e)){a(R.invalidOptions,"'replace' takes definitions, not arrays of them",t);continue}const n=t.length>1?`replace[${t[1]}]`:"replace";if(!h(e,t,n,a))continue;const{name:r}=e;if(C.has(r))a(R.duplicateOperator,`two replacements for '${r}'`,t,{operator:r});else{if(C.set(r,e),!m.has(r)){const e=v(r,m.keys());a(R.unknownOperator,`'${r}' names no operator in the input — to add a new operator, put it in the input`,t,void 0===e?void 0:{suggestion:e});continue}!N||A.has(r)&&!q.has(r)||a(R.invalidOptions,`'${r}' is replaced but also removed by '${A.has(r)?"except":"only"}'`,t,{operator:r})}}const E=f.filter(({name:e})=>A.has(e)&&!q.has(e)).map(e=>C.get(e.name)??e);if(0===t.length&&0===E.length&&a(R.invalidOptions,"the selection leaves no operators",[]),t.length>0)throw o(R.invalidOptions,t,t[0].operator);return E},me=e=>new b(`request failed (${e.status}): ${e.url}`,{code:R.httpStatus,errorData:{status:e.status,statusText:e.statusText,url:e.url,response:be(e.response)}}),ye=(e,t,a)=>new b(e,{code:R.invalidResponse,errorData:{url:t,response:be(a)}}),he=(e,t)=>{const a=t instanceof Error?t.message:String(t),n=t??{},r={driver:e};"string"==typeof n.code&&(r.driverCode=n.code);for(const e of["table","column","constraint"])"string"==typeof n[e]&&(r[e]=n[e]);return new b(`${e}: ${a}`,{code:R.sqlError,errorData:r})},ve={http:{"http-status":{status:"number",statusText:"string",url:"string",response:"any"},"invalid-response":{url:"string",response:"any"}},sql:{"sql-error":{driver:"string",driverCode:["string","null"]}}},ge=async(e,t)=>{try{return await e()}catch(e){throw((e,t)=>{const a=ve[t];if(w(e)&&void 0!==e.code&&Object.hasOwn(a,e.code)){const t=e.errorData??{},n=a[e.code];if(Object.entries(n).every(([e,a])=>c(t[e]??null,a).ok))return e}return new b(e instanceof Error?e.message:String(e),{code:R.requestFailure})})(e,t)}},be=(e,t=500)=>"string"!=typeof e||e.length<=t?e:`${e.slice(0,t)}… (${e.length} characters)`,we=e=>new V({code:R.invalidOptions,message:e,path:[]});class $e{supplied;constructor(e){if(void 0===e&&"function"!=typeof globalThis.fetch)throw we("FetchClient(): this runtime has no global fetch — pass one, new FetchClient(myFetch), or use another client such as new AxiosClient(axios)");this.supplied=e}request=async e=>{const t=this.supplied??globalThis.fetch,a=await t.call(globalThis,e.url,{method:e.method.toUpperCase(),headers:e.headers,...void 0!==e.body?{body:JSON.stringify(e.body)}:{},signal:e.signal}),n=await a.text();if(!a.ok)throw me({status:a.status,statusText:a.statusText,url:a.url||e.url,response:Pe(n)});return ke(n,a.url||e.url,a.status)}}class Oe{axios;constructor(e){if(this.axios=e,"function"!=typeof e)throw we("AxiosClient(axios): pass the axios import or an instance from axios.create() — new AxiosClient(axios)")}request=async e=>{try{const t=await this.axios({url:e.url,method:e.method,headers:e.headers,...void 0!==e.body?{data:JSON.stringify(e.body)}:{},signal:e.signal});return""===t.data||void 0===t.data?null:t.data}catch(t){if(je(t)&&t.response)throw me({status:t.response.status,statusText:t.response.statusText,url:t.config?.url??e.url,response:t.response.data});throw t}}}const je=e=>"object"==typeof e&&null!==e&&!0===e.isAxiosError,ke=(e,t,a)=>{if(""===e.trim())return null;try{return JSON.parse(e)}catch{throw ye(`response was not JSON (${a}): ${t}`,t,e)}},Pe=e=>{if(""===e.trim())return null;try{return JSON.parse(e)}catch{return e}},De=/^https?:\/\//i,xe=(e,t,a)=>{const n=De.test(e)?e:Ne(a,e),r=Ae(t),i=""===r?n:`${n}${n.includes("?")?"&":"?"}${r}`;try{new URL(i)}catch{throw new b(`'${i}' is not a valid URL`,{code:R.typeCheck})}return i},Ne=(e,t)=>{if(void 0===e||""===e)throw new b(`'${t}' is a relative URL and no http.baseEndpoint is configured`,{code:R.typeCheck});return""===t?e:`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`},Ae=e=>{if(void 0===e)return"";const t=new URLSearchParams;for(const[a,n]of Object.entries(e))null!=n&&t.append(a,Ee(n,`query['${a}']`,"query"));return t.toString()},qe=(...e)=>{const t={};for(const a of e)if(void 0!==a)for(const[e,n]of Object.entries(a))null!=n?t[e]=Ee(n,`headers['${e}']`,"header"):delete t[e];return t},Ce=e=>({Accept:"application/json",...e?{"Content-Type":"application/json"}:{}}),Ee=(e,t,a)=>{if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return O(e);throw new b(`${t} is ${j(e)} — a ${a} value must be a string, number or boolean; render it explicitly (join) or supply a fully-formed URL`,{code:R.typeCheck})},Se=e=>({method:e.method,url:e.url,headers:Object.fromEntries(Object.entries(e.headers).sort(([e],[t])=>e<t?-1:e>t?1:0)),...void 0!==e.body?{body:e.body}:{}}),Le=e=>Array.isArray(e)?e.length>0:t(e)?Object.keys(e).length>0:null!=e,Te=(e,t)=>{if(void 0===t)return e;const a=B(e,$(t));return a.found?a.value:null},Fe=(e,a)=>{if(!t(e))throw new b("a row was not an object");const n=Object.values(e);if(1!==n.length)throw new b(`shape: '${a}' needs a single-column result — this row has ${n.length} columns; name the one column you want in the SQL`,{code:R.typeCheck});return n[0]},Re={type:"integer",required:!1},ze={type:["string","array"],required:!1},Qe=e=>x({name:"http",category:"io",parameters:{url:{type:"string"},method:{type:{literal:["get","post"]},default:"get"},query:{type:"object",required:!1,elementNullPolicy:"value"},body:{type:["string","number","boolean","array","object"],required:!1},headers:{type:"object",required:!1,elementNullPolicy:"value"},returnPath:ze,timeout:Re},positionalParams:["url"],timeoutParam:"timeout",cache:!0,returns:"any",validate:({returnPath:e,method:t,body:a})=>[...N(e,"returnPath"),...Ge(t,a)],evaluate:async({url:t,method:a,query:n,body:r,headers:i,returnPath:o},s)=>{if("get"===a&&void 0!==r)throw new b("a GET carries no body — did you mean method: 'post'?",{code:R.typeCheck});const l={method:a,url:xe(t,n,s.options.http?.baseEndpoint),headers:qe(Ce(void 0!==r),s.options.http?.headers,i),...void 0!==r?{body:r}:{}},c=await s.cache.memo(Se(l),()=>(Be(s,l),ge(()=>e.request({...l,signal:s.signal}),"http")));return Te(c,o)}}),Je=e=>x({name:"graphQL",category:"io",parameters:{query:{type:"string"},variables:{type:"object",required:!1,elementNullPolicy:"value"},url:{type:"string",required:!1},headers:{type:"object",required:!1,elementNullPolicy:"value"},returnPath:ze,timeout:Re},positionalParams:["query","variables"],timeoutParam:"timeout",cache:!0,returns:"any",validate:({returnPath:e})=>N(e,"returnPath"),evaluate:async({query:a,variables:n,url:r,headers:i,returnPath:o},s)=>{const l=r??s.options.graphQL?.endpoint;if(void 0===l)throw new b("no endpoint — supply url, or set the graphQL.endpoint option");const c={method:"post",url:xe(l,void 0,s.options.http?.baseEndpoint),headers:qe(Ce(!0),s.options.http?.headers,s.options.graphQL?.headers,i),body:{query:a,...Le(n)?{variables:n}:{}}},u=await s.cache.memo(Se(c),async()=>{Be(s,c);return((e,a)=>{if(!t(e))throw ye("the GraphQL response was not an object",a,e);const n=e.errors;if(Array.isArray(n)&&n.length>0){const e=n[0]?.message;throw new b(`the GraphQL response carried ${n.length} error${1===n.length?"":"s"}`+("string"==typeof e?`: ${e}`:""),{code:R.graphQLErrors,errorData:{errors:n}})}if(!("data"in e))throw ye("the GraphQL response carried neither data nor errors",a,e);return e.data??null})(await ge(()=>e.request({...c,signal:s.signal}),"http"),c.url)});return Te(u,o)}}),Me=e=>x({name:"sql",category:"io",parameters:{query:{type:"string"},values:{type:["array","object"],required:!1,elementNullPolicy:"value"},shape:{type:{literal:["rows","firstRow","column","firstValue"]},default:"rows"},noRowDefault:{type:"any",default:null,nullPolicy:"value",evaluation:"lazy"},timeout:Re},positionalParams:["query","...values"],timeoutParam:"timeout",cache:!0,returns:"any",evaluate:async({query:t,values:a,shape:n,noRowDefault:r},i)=>{const o={text:t,...Le(a)?{values:a}:{}};return(async(e,t,a)=>{switch(t){case"rows":return e;case"firstRow":return 0===e.length?a.evaluate():e[0];case"column":return e.map(e=>Fe(e,"column"));case"firstValue":return 0===e.length?a.evaluate():Fe(e[0],"firstValue")}})(await i.cache.memo(o,()=>(i.trace.note({type:"query",text:o.text}),ge(()=>e.query({...o,signal:i.signal}),"sql"))),n,r)}}),Ge=(e,t)=>void 0!==t&&"get"===e?[{severity:"error",parameter:"body",message:"a GET carries no body — add method: 'post', or drop the body"}]:[],Ue=(e=new $e)=>[D(Qe(e)),D(Je(e))],Ve=e=>[D(Me(e))],Be=(e,t)=>{e.trace.note({type:"request",method:t.method,url:t.url,headers:Object.keys(t.headers)})},Ie=e=>new V({code:R.invalidOptions,message:e,path:[]});class We{client;constructor(e){if(this.client=e,"function"!=typeof e?.query)throw Ie("PostgresConnection(client): pass a connected node-postgres Client or Pool")}query=async e=>{if(void 0!==e.values&&!Array.isArray(e.values))throw he("postgres","takes positional binds ($1, $2, …) — an object of named binds needs a driver that supports them");try{const t=await this.client.query({text:e.text,...void 0!==e.values?{values:e.values}:{}});return t?.rows??[]}catch(e){throw he("postgres",e)}}}class He{db;constructor(e){if(this.db=e,"function"!=typeof e?.all)throw Ie("SQLiteConnection(db): pass an open sqlite Database")}query=async e=>{try{return await this.db.all(e.text,e.values)??[]}catch(e){throw he("sqlite",e)}}}const Ke=e=>Ye(e,0,new Set),Ye=(e,t,a)=>{if(null===e||"boolean"==typeof e||"string"==typeof e)return e;if("number"==typeof e&&Number.isFinite(e)&&!Object.is(e,-0))return e;if("object"!=typeof e)return Xe(e);if(!Array.isArray(e)&&!U(e))return Ze(e);if(a.has(e))return"[circular]";if(t>=I)return"[too deep]";a.add(e);const n=Array.isArray(e)?Array.from(e,e=>Ye(e,t+1,a)):Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Ye(n,t+1,a)]));return a.delete(e),n},Xe=e=>{switch(typeof e){case"function":return""===e.name?"[function]":`[function ${e.name}]`;case"symbol":return`[${String(e)}]`;case"bigint":return`[bigint ${e}]`;case"number":return Object.is(e,-0)?"[-0]":`[${e}]`;default:return"[undefined]"}},Ze=e=>{const t=_e(e);try{const a=e.toJSON;if("function"==typeof a){const n=a.call(e);if("string"==typeof n)return`[${t} ${n}]`}}catch{}return`[${t}]`},_e=e=>{try{const t=e.constructor?.name;return"string"==typeof t&&""!==t?t:"Object"}catch{return"Object"}},et=e=>{const t=new Map;for(const a of e.holes)void 0!==a.timeoutFallback&&t.set(a.node,a.timeoutFallback);const a=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,r(t)])),n=e=>{const a=t.get(e);return void 0===a?{}:{timeoutFallback:Ke(a.value)}},r=e=>{const t={order:e.order,kind:e.kind,path:A(e.path)},i="vars"in e&&void 0!==e.vars?{vars:a(e.vars)}:{};switch(e.kind){case"constant":return{...t,kind:e.kind,value:Ke(e.value)};case"reference":return{...t,kind:e.kind,reference:H(e.binding??e.namespace,e.segments),authored:e.raw,...void 0===e.binding?{}:{binding:e.binding}};case"operator":return{...t,kind:e.kind,...i,operator:e.name,params:a(e.params),...void 0===e.fallback?{}:{fallback:r(e.fallback)},...n(e),...void 0===e.noCache?{}:{noCache:e.noCache},...void 0===e.entry.hostDefaults?{}:{hostDefaults:Object.keys(e.entry.hostDefaults)}};case"fragmentCall":return{...t,kind:e.kind,...i,fragment:e.name,resolved:void 0!==e.entry,argumentsMode:e.argumentsMode,...void 0===e.parameters?{}:{parameters:"dynamic"===e.argumentsMode?r(e.parameters):a(e.parameters)},...void 0===e.fallback?{}:{fallback:r(e.fallback)},...n(e),...void 0===e.noCache?{}:{noCache:e.noCache}};case"skeleton":{const a=q(e.skeleton,e.holes,e.holes.map(()=>"<hole>"));return{...t,kind:e.kind,...i,shape:Ke(a),holes:e.holes.map(e=>({at:[...e.at],node:r(e.node)}))}}case"elements":return{...t,kind:e.kind,elements:e.nodes.map(r)};case"entries":return{...t,kind:e.kind,...i,entries:a(e.entries)};case"invalid":return{...t,kind:e.kind,raw:Ke(e.raw)}}};return r(e.root)},tt=(e,t)=>{const a=C(e,t);if(void 0===a)throw new TypeError("inspect() takes a CompiledExpression — the handle fig.compile() returns");const{expression:n,artifact:r,options:i}=a;return{version:E,expression:Ke(n),options:nt(i),canonicalForm:et(r),issues:L(r,i,({issue:e,order:t})=>({order:t,...e,path:[...e.path]})),timeoutShielded:r.timeoutShielded,nodeCount:r.nodeCount,maxDepth:r.maxDepth,dependencies:ot(r.dependencies),own:{nodeCount:r.own.nodeCount,maxDepth:r.own.maxDepth,dependencies:ot(r.own.dependencies)}}},at="[supplied]",nt=e=>Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e).map(([e,t])=>[e,rt(e,t)])),rt=(e,t)=>{switch(e){case"data":{const e="object"==typeof t&&null!==t?Object.keys(t).length:0;return`[supplied: ${e} top-level key${1===e?"":"s"}]`}case"signal":return at;case"http":case"graphQL":return it(t,"headers",e=>"object"==typeof e&&null!==e?Object.fromEntries(Object.keys(e).map(e=>[e,"[redacted]"])):Ke(e));case"cache":return it(t,"store",()=>at);default:return Ke(t)}},it=(e,t,a)=>"object"==typeof e&&null!==e?Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e).map(([e,n])=>[e,e===t?a(n):Ke(n)])):Ke(e),ot=e=>({dataPaths:[...e.dataPaths.keys()],dynamic:e.dynamic,paramNames:[...e.paramNames],paramsDynamic:e.paramsDynamic,operators:[...e.operators],fragments:[...e.fragments]});export{Oe as AxiosClient,R as ErrorCodes,l as EvaluationData,$e as FetchClient,V as FigTreeError,r as OPERATOR_CATEGORIES,b as OperatorFailure,We as PostgresConnection,He as SQLiteConnection,ce as defineOperator,me as httpFailure,Ue as httpOperators,tt as inspect,w as isOperatorFailure,fe as operatorSet,O as renderText,B as resolvePath,he as sqlFailure,Ve as sqlOperators,E as version};
|