fig-tree-evaluator 3.0.0-preview.1 → 3.0.0-preview.10
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.d.ts +80 -0
- package/build/authoring/index.js +1 -0
- package/build/chunks/engine.js +1 -0
- package/build/chunks/shared.js +1 -1
- package/build/editor-hints/index.js +1 -1
- package/build/format/index.d.ts +74 -1
- package/build/format/index.js +1 -1
- package/build/index.d.ts +224 -47
- package/build/index.js +1 -1
- package/build/migrate/index.d.ts +1 -1
- package/build/migrate/index.js +1 -1
- package/package.json +11 -1
package/build/format/index.d.ts
CHANGED
|
@@ -23,9 +23,82 @@ interface ShorthandOptions extends NameOptions {
|
|
|
23
23
|
getAsReference?: boolean;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
type ObjectClass = {
|
|
27
|
+
kind: 'operator';
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'fragment';
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'shorthand';
|
|
32
|
+
key: string;
|
|
33
|
+
} | {
|
|
34
|
+
kind: 'plain';
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'malformed';
|
|
37
|
+
message: string;
|
|
38
|
+
};
|
|
39
|
+
declare const classifyObject: (raw: Record<string, unknown>, recognizes: (name: string) => boolean) => ObjectClass;
|
|
40
|
+
interface PositionalShape {
|
|
41
|
+
positionalParams?: readonly string[];
|
|
42
|
+
restParam: string | null;
|
|
43
|
+
}
|
|
44
|
+
interface PositionalLayout {
|
|
45
|
+
bound: number;
|
|
46
|
+
restAt: number | null;
|
|
47
|
+
}
|
|
48
|
+
declare const positionalLayout: (shape: PositionalShape, length: number) => PositionalLayout | null;
|
|
49
|
+
declare const singlePositionalTarget: (shape: PositionalShape) => string | null;
|
|
50
|
+
|
|
51
|
+
declare const WILDCARD: unique symbol;
|
|
52
|
+
type Wildcard = typeof WILDCARD;
|
|
53
|
+
type PathSegment = string | number | Wildcard;
|
|
54
|
+
|
|
55
|
+
declare const NAMESPACE_TOKENS: {
|
|
56
|
+
readonly data: "data";
|
|
57
|
+
readonly d: "data";
|
|
58
|
+
readonly vars: "vars";
|
|
59
|
+
readonly v: "vars";
|
|
60
|
+
readonly params: "params";
|
|
61
|
+
readonly p: "params";
|
|
62
|
+
readonly element: "element";
|
|
63
|
+
readonly e: "element";
|
|
64
|
+
readonly index: "index";
|
|
65
|
+
readonly i: "index";
|
|
66
|
+
readonly error: "error";
|
|
67
|
+
readonly err: "error";
|
|
68
|
+
};
|
|
69
|
+
type ReferenceNamespace = (typeof NAMESPACE_TOKENS)[keyof typeof NAMESPACE_TOKENS];
|
|
70
|
+
type ReferenceRecognition = {
|
|
71
|
+
kind: 'reference';
|
|
72
|
+
namespace: ReferenceNamespace;
|
|
73
|
+
segments: PathSegment[];
|
|
74
|
+
drill: string;
|
|
75
|
+
binding?: string;
|
|
76
|
+
} | {
|
|
77
|
+
kind: 'invalid';
|
|
78
|
+
namespace: ReferenceNamespace;
|
|
79
|
+
reason: string;
|
|
80
|
+
code?: string;
|
|
81
|
+
} | {
|
|
82
|
+
kind: 'unrecognized';
|
|
83
|
+
} | {
|
|
84
|
+
kind: 'plain';
|
|
85
|
+
};
|
|
86
|
+
interface ReferenceScope {
|
|
87
|
+
bindings?: readonly string[];
|
|
88
|
+
}
|
|
89
|
+
declare const recognizeReference: (value: string, scope?: ReferenceScope) => ReferenceRecognition;
|
|
90
|
+
|
|
91
|
+
type BasicType = 'any' | 'string' | 'number' | 'boolean' | 'array' | 'object' | 'null' | 'integer';
|
|
92
|
+
type LiteralType = {
|
|
93
|
+
literal: readonly (string | number | boolean)[];
|
|
94
|
+
};
|
|
95
|
+
type ExpectedType = BasicType | LiteralType | readonly BasicType[];
|
|
96
|
+
|
|
97
|
+
declare const typesIntersect: (a: ExpectedType, b: ExpectedType) => boolean;
|
|
98
|
+
|
|
26
99
|
declare const toCanonical: (expression: unknown, fig: Registry, options?: CanonicalOptions) => unknown;
|
|
27
100
|
declare const toShorthand: (expression: unknown, fig: Registry, options?: ShorthandOptions) => unknown;
|
|
28
101
|
declare const toGet: (reference: unknown, options?: NameOptions) => Record<string, unknown> | null;
|
|
29
102
|
declare const toReference: (node: unknown, options?: NameOptions) => string | null;
|
|
30
103
|
|
|
31
|
-
export { toCanonical, toGet, toReference, toShorthand };
|
|
104
|
+
export { classifyObject, positionalLayout, recognizeReference, singlePositionalTarget, toCanonical, toGet, toReference, toShorthand, typesIntersect };
|
package/build/format/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as e,E as r,p as t,S as n,i as a,a as s,R as o,s as i,r as l,b as u,d as f,W as c,G as p,e as m,F as d,D as h}from"../chunks/shared.js";const k=e=>{const r=new Map;for(const{name:t,alias:n,positionalParams:a,restParam:s}of e.getOperators()){const e={name:t,alias:n,positionalParams:a,restParam:s};r.set(t,e),void 0!==n&&r.set(n,e)}const t=new Set(e.getFragments().map(({name:e})=>e));return{operators:r,fragments:t,recognizes:e=>"literal"===e||r.has(e)||t.has(e)}},g=(e,r)=>{const n=t(e,r.length);if(null===n)return null;const a=e.positionalParams,s=[];for(let e=0;e<n.bound;e++)s.push([a[e],r[e]]);return null!==n.restAt&&s.push([e.restParam,0===n.restAt?r:r.slice(n.restAt)]),s},v=/*#__PURE__*/new Set(["fallback","useCache","vars"]),y=(e,t,n)=>{const a=e.operator;if("string"!=typeof a)return n(r.malformedNode,"the 'operator' value must be a literal string");if("literal"===a)return $(e,n);const s=t.operators.get(a);if(void 0===s)return n(r.unknownOperator,`'${a}' names no registered operator`);const o=[],i=[];for(const t in e){const a=e[t];if(void 0!==a)if("operator"===t)o.push({kind:"invocation"});else if("//"===t||v.has(t))o.push({kind:"keep",key:t,value:a});else{if("parameters"===t)return n(r.malformedNode,"'parameters' is reserved and unused on operator nodes");o.push({kind:"param",name:t,value:a}),i.push([t,a])}}return{kind:"operator",operator:s,spelling:a,slots:o,params:i,fromPayload:!1}},$=(e,t)=>{if(!("value"in e))return t(r.malformedNode,"'literal' requires its content in 'value'");const n=[];for(const a in e){const s=e[a];if("operator"===a)n.push({kind:"invocation"});else if("value"===a)n.push({kind:"param",name:"value",value:s});else{if(void 0===s)continue;if("//"!==a&&!v.has(a))return t(r.unknownNodeKey,`'${a}' is not a key of 'literal' — content goes in 'value'`);n.push({kind:"keep",key:a,value:s})}}return{kind:"literal",content:e.value,slots:n,fromPayload:!1}},w=(e,t,n)=>{const a=e.fragment;if("string"!=typeof a)return n(r.malformedNode,"the 'fragment' value must be a literal string");if(!t.fragments.has(a))return n(r.unknownFragment,`'${a}' names no registered fragment`);const s=[];for(const a in e){const o=e[a];if(void 0!==o)if("fragment"===a)s.push({kind:"invocation"});else if("parameters"===a)P(o,t,n),s.push({kind:"param",name:a,value:o});else{if("//"!==a&&"fallback"!==a&&"vars"!==a)return"useCache"===a?n(r.malformedNode,"'useCache' is not available on fragment calls — caching stays operator-level"):n(r.unknownNodeKey,`'${a}' is not a key of a fragment call — arguments live only in 'parameters'`);s.push({kind:"keep",key:a,value:o})}}return{kind:"fragment",name:a,slots:s,parameters:e.parameters,fromPayload:!1}},P=(e,t,n)=>{a(e)||s(e,t.recognizes)||"string"==typeof e&&"reference"===l(e).kind||n(r.malformedNode,"a fragment's 'parameters' must be a named-arguments object or a node computing one")},A=(e,t,s,o)=>{const i=t.slice(1),l="literal"===i,u=!l&&s.fragments.has(i),f=[];for(const a in e){const s=e[a];if(a!==t){if(!n.has(a)||u&&"useCache"===a)return o(r.malformedNode,`'${a}' may not sit beside the shorthand key '${t}' — reserved modifiers only`);void 0!==s&&f.push({kind:"keep",key:a,value:s})}else f.push({kind:"invocation"})}const c=e[t];if(l)return{kind:"literal",content:c,slots:f,fromPayload:!0};if(u)return a(c)?{kind:"fragment",name:i,slots:f,parameters:c,fromPayload:!0}:o(r.malformedNode,`fragments have no single-value or positional form — '${t}' takes a named-arguments object`);const p=s.operators.get(i);return{kind:"operator",operator:p,spelling:i,slots:f,params:N(p,c,s,o),fromPayload:!0}},N=(e,t,n,l)=>{const u=()=>l(r.positionalArity,`'${e.name}' takes no positional arguments — use the named form`);if(Array.isArray(t)){const n=g(e,t);if(null!==n)return n;if(void 0===e.positionalParams)return u();const a=e.positionalParams;return l(r.positionalArity,`'${e.name}' takes at most ${a.length} positional argument${1===a.length?"":"s"} (${a.join(", ")}), got ${t.length}`)}if(a(t)&&!s(t,n.recognizes)){const n=[];for(const a in t){const s=t[a];if(void 0!==s){if("//"!==a&&o.has(a))return l(r.unknownNodeKey,`'${a}' is not a parameter of '${e.name}'`);n.push([a,s])}}return n}const f=i(e);return null===f?u():[[f,t]]},b={positionalParams:p,restParam:null},z=/*#__PURE__*/new Set(["path","from","default"]),W={data:"d",vars:"v",params:"p",element:"e",index:"i"},j=(e,r,t)=>"canonical"===t?r:"alias"===t?W[r]:e,C=(e,r)=>{if("preserve"===r)return e;const t=l(e);if("reference"!==t.kind)return e;const{token:n,rest:a}=u(e);return`$${j(n,t.namespace,r)}${a}`},x=e=>e.startsWith(".")?e.slice(1):e,M=(e,r)=>{if("string"!=typeof e)return null;const t=l(e);if("reference"!==t.kind)return null;const{namespace:n}=t,{token:a,rest:s}=u(e),o=`$${j(a,n,r)}`;switch(n){case"data":return{operator:"get",path:x(s)};case"element":return{operator:"get",path:x(s),from:o};case"vars":case"params":{if(0===t.segments.length)return{operator:"get",path:"",from:o};const e=(e=>{if(e.startsWith(".")){let r=1;for(;r<e.length&&"."!==e[r]&&"["!==e[r];)r++;return r>1?r:null}const r=e[1];if("["!==e[0]||'"'!==r&&"'"!==r)return null;for(let t=2;t<e.length;t++)if("\\"===e[t])t++;else if(e[t]===r)return"]"===e[t+1]?t+2:null;return null})(s);return null===e?null:{operator:"get",path:x(s.slice(e)),from:`${o}${s.slice(0,e)}`}}default:return null}},S=(e,r)=>{if(e.has("default"))return null;const t=(e=>{if("string"==typeof e){if(e.startsWith("$"))return null;try{return m(e)}catch{return null}}if(!Array.isArray(e))return null;for(const r of e)if(!("string"==typeof r&&!r.startsWith("$")||"number"==typeof r&&Number.isInteger(r)&&r>=0))return null;return e})(e.get("path"));if(null===t)return null;const n=f(t);let a;const s=e.get("from");if(void 0===s)a="canonical"===r?"$data":"$d";else{if("string"!=typeof s)return null;const e=l(s);if("reference"!==e.kind||"index"===e.namespace)return null;if(""!==n&&e.segments.includes(c))return null;a=C(s,r).replace(/\.$/,"")}return""===n?a:n.startsWith("[")?`${a}${n}`:`${a}.${n}`},F=e=>{const r=[];for(let t=e;null!==t;t=t.parent)r.push(t.key);return r.reverse()};class K{lookup;writer;path=null;depth=0;constructor(e,r){this.lookup=e,this.writer=r}fail=(e,r)=>{throw new d({code:e,message:r,path:F(this.path)})};child(e,r){return this.within(r,()=>this.value(e))}within(e,r){const{path:t,depth:n}=this;this.path={parent:t,key:e},this.depth=n+1;const a=r();return this.path=t,this.depth=n,a}value(t){if(this.depth>h&&this.fail(r.depthCeiling,`the expression nests deeper than the engine's ceiling of ${h} levels`),"string"==typeof t)return this.writer.string(t);if(Array.isArray(t))return t.map((e,r)=>this.child(e,r));if(!a(t))return t;const n=((t,n,a)=>{const s=e(t,n.recognizes);switch(s.kind){case"malformed":return a(r.malformedNode,s.message);case"plain":return s;case"operator":return y(t,n,a);case"fragment":return w(t,n,a);case"shorthand":return A(t,s.key,n,a)}})(t,this.lookup,this.fail);switch(n.kind){case"plain":return this.entries(t,!0);case"operator":return this.writer.operator(n,this);case"fragment":return this.writer.fragment(n,this);case"literal":return this.writer.literal(n,this)}}keep({key:e,value:r}){return"fallback"===e?this.child(r,e):"vars"===e?this.vars(r):r}parameters(e){return!a(e)||s(e,this.lookup.recognizes)?this.child(e,"parameters"):this.within("parameters",()=>this.entries(e,!1))}entries(e,r){const t={};for(const n in e){const a=e[n];t[n]="//"===n?a:r&&"vars"===n?this.vars(a):this.child(a,n)}return t}vars(e){return a(e)?this.within("vars",()=>this.entries(e,!1)):e}}const O=(e,r)=>"canonical"===r?e.operator.name:"alias"===r?e.operator.alias??e.operator.name:e.spelling,E=e=>Array.isArray(e)?e:[e],G=(e,r)=>[...E(e),...E(r)],R=e=>e.params.find(([e])=>"//"===e)?.[1],q=e=>e.slots.some(e=>"keep"===e.kind&&"//"===e.key),D={kind:"named"},I=(e,r)=>!(Array.isArray(e)||a(e)&&!s(e,r.recognizes)),B=(e={})=>{const r=e.operatorNames??"preserve",t=e.referenceNames??"preserve",n="named"===e.arguments,a=e.getAsReference??!0;return{operator:(e,s)=>{const o=e.params.map(([e,r])=>[e,"//"===e?r:s.child(r,e)]),i=o.filter(([e])=>"//"!==e);if(a&&"get"===e.operator.name){const r=e.slots.some(e=>"keep"===e.kind&&"//"!==e.key)?null:S(new Map(i),t);if(null!==r)return r}const l=n?D:((e,r,t)=>{const n=e.positionalParams;if(void 0===n||0===r.length)return D;const a=e.restParam,s=null===a?n:n.slice(0,-1),o=new Map(r);for(const e of o.keys())if(e!==a&&!s.includes(e))return D;let i=0;for(;i<s.length&&o.has(s[i]);)i++;for(let e=i;e<s.length;e++)if(o.has(s[e]))return D;const l=null!==a&&o.has(a);if(null!==a&&l!==(i===s.length))return D;const u=s.slice(0,i).map(e=>o.get(e));if(l){const e=o.get(a);return Array.isArray(e)?{kind:"array",value:[...u,...e]}:0===s.length&&I(e,t)?{kind:"single",value:e}:D}return 1===i&&I(u[0],t)?{kind:"single",value:u[0]}:{kind:"array",value:u}})(e.operator,i,s.lookup),u="named"===l.kind?void 0:R(e),f=void 0!==u&&q(e),c={};for(const t of e.slots)"invocation"===t.kind?(void 0===u||f||(c["//"]=u),c[`$${O(e,r)}`]="named"===l.kind?Object.fromEntries(o):l.value):"keep"===t.kind&&(c[t.key]="//"===t.key&&f?G(t.value,u):s.keep(t));return c},fragment:(e,r)=>{const t=void 0===e.parameters?{}:r.parameters(e.parameters),n="string"==typeof t,a={};for(const s of e.slots)"invocation"===s.kind?n?(a.fragment=e.name,e.fromPayload&&(a.parameters=t)):a[`$${e.name}`]=t:"param"===s.kind?n&&(a.parameters=t):a[s.key]=r.keep(s);return a},literal:(e,r)=>{const t={};for(const n of e.slots)"invocation"===n.kind?t.$literal=e.content:"keep"===n.kind&&(t[n.key]=r.keep(n));return t},string:e=>C(e,t)}},H=(e,r,t)=>new K(k(r),((e={})=>{const r=e.operatorNames??"preserve",t=e.referenceNames??"preserve",n=e.referencesAsGet??!1;return{operator:(e,t)=>{const n={},a=e.fromPayload?R(e):void 0,s=void 0!==a&&q(e);for(const o of e.slots)if("invocation"===o.kind){if(void 0===a||s||(n["//"]=a),n.operator=O(e,r),e.fromPayload)for(const[r,a]of e.params)"//"!==r&&(n[r]=t.child(a,r))}else"param"===o.kind?n[o.name]=t.child(o.value,o.name):"//"===o.key&&s?n["//"]=G(o.value,a):n[o.key]=t.keep(o);return n},fragment:(e,r)=>{const t={};for(const n of e.slots)"invocation"===n.kind?(t.fragment=e.name,e.fromPayload&&(t.parameters=r.parameters(e.parameters))):"param"===n.kind?t.parameters=r.parameters(n.value):t[n.key]=r.keep(n);return t},literal:(e,r)=>{const t={};for(const n of e.slots)"invocation"===n.kind?(t.operator="literal",e.fromPayload&&(t.value=e.content)):"param"===n.kind?t.value=e.content:t[n.key]=r.keep(n);return t},string:e=>{if(n){const r=M(e,t);if(null!==r)return r}return C(e,t)}}})(t)).value(e),J=(e,r,t)=>new K(k(r),B(t)).value(e),L=(e,r)=>M(e,r?.referenceNames??"preserve"),Q=(e,r)=>{const t=(e=>{if(!a(e))return null;const r=new Map;if("operator"in e){if("get"!==e.operator)return null;for(const t in e){const n=e[t];if("operator"!==t&&"//"!==t&&void 0!==n){if(!z.has(t))return null;r.set(t,n)}}return r}for(const r in e)if("$get"!==r&&"//"!==r)return null;if(!("$get"in e))return null;const t=e.$get;if(Array.isArray(t)){const e=g(b,t);if(null===e)return null;for(const[t,n]of e)r.set(t,n);return r}if(a(t)){for(const e in t){const n=t[e];if("//"!==e&&void 0!==n){if(!z.has(e))return null;r.set(e,n)}}return r}return r.set(i(b),t),r})(e);return null===t?null:S(t,r?.referenceNames??"preserve")};export{H as toCanonical,L as toGet,Q as toReference,J as toShorthand};
|
|
1
|
+
import{d as e,E as r,p as n,S as a,e as s,f as o,R as i,s as l,g as u,h as f,G as p,j as c,k as m,W as d,l as h,N as k,F as g,D as v}from"../chunks/shared.js";export{t as typesIntersect}from"../chunks/shared.js";const y=e=>{const r=new Map;for(const{name:t,alias:n,positionalParams:a,restParam:s}of e.getOperators()){const e={name:t,alias:n,positionalParams:a,restParam:s};r.set(t,e),void 0!==n&&r.set(n,e)}const t=new Set(e.getFragments().map(({name:e})=>e));return{operators:r,fragments:t,recognizes:e=>"literal"===e||r.has(e)||t.has(e)}},$=(e,r)=>{const t=n(e,r.length);if(null===t)return null;const a=e.positionalParams,s=[];for(let e=0;e<t.bound;e++)s.push([a[e],r[e]]);return null!==t.restAt&&s.push([e.restParam,0===t.restAt?r:r.slice(t.restAt)]),s},w=/*#__PURE__*/new Set(["fallback","noCache","vars"]),P="'noCache' takes only the literal true — it is settled before the subtree runs",N=(e,t,n)=>{const a=e.operator;if("string"!=typeof a)return n(r.malformedNode,"the 'operator' value must be a literal string");if("literal"===a)return A(e,n);const s=t.operators.get(a);if(void 0===s)return n(r.unknownOperator,`'${a}' names no registered operator`);const o=[],i=[];for(const t in e){const a=e[t];if(void 0!==a)if("operator"===t)o.push({kind:"invocation"});else{if("noCache"===t&&!0!==a)return n(r.malformedNode,P);if("//"===t||w.has(t))o.push({kind:"keep",key:t,value:a});else{if("parameters"===t)return n(r.malformedNode,"'parameters' is reserved and unused on operator nodes");o.push({kind:"param",name:t,value:a}),i.push([t,a])}}}return{kind:"operator",operator:s,spelling:a,slots:o,params:i,fromPayload:!1}},A=(e,t)=>{if(!("value"in e))return t(r.malformedNode,"'literal' requires its content in 'value'");const n=[];for(const a in e){const s=e[a];if("operator"===a)n.push({kind:"invocation"});else if("value"===a)n.push({kind:"param",name:"value",value:s});else{if(void 0===s)continue;if("//"!==a&&!w.has(a))return t(r.unknownNodeKey,`'${a}' is not a key of 'literal' — content goes in 'value'`);n.push({kind:"keep",key:a,value:s})}}return{kind:"literal",content:e.value,slots:n,fromPayload:!1}},b=(e,t,n)=>{const a=e.fragment;if("string"!=typeof a)return n(r.malformedNode,"the 'fragment' value must be a literal string");if(!t.fragments.has(a))return n(r.unknownFragment,`'${a}' names no registered fragment`);const s=[];for(const a in e){const o=e[a];if(void 0!==o)if("fragment"===a)s.push({kind:"invocation"});else if("parameters"===a)j(o,t,n),s.push({kind:"param",name:a,value:o});else{if("noCache"===a&&!0!==o)return n(r.malformedNode,P);if("//"!==a&&!w.has(a))return n(r.unknownNodeKey,`'${a}' is not a key of a fragment call — arguments live only in 'parameters'`);s.push({kind:"keep",key:a,value:o})}}return{kind:"fragment",name:a,slots:s,parameters:e.parameters,fromPayload:!1}},j=(e,t,n)=>{s(e)||o(e,t.recognizes)||"string"==typeof e&&"reference"===u(e).kind||n(r.malformedNode,"a fragment's 'parameters' must be a named-arguments object or a node computing one")},z=(e,t,n,o)=>{const i=t.slice(1),l="literal"===i,u=!l&&n.fragments.has(i),f=[];for(const n in e){const s=e[n];if(n!==t){if(!a.has(n))return o(r.malformedNode,`'${n}' may not sit beside the shorthand key '${t}' — reserved modifiers only`);if("noCache"===n&&!0!==s&&!l)return o(r.malformedNode,P);void 0!==s&&f.push({kind:"keep",key:n,value:s})}else f.push({kind:"invocation"})}const p=e[t];if(l)return{kind:"literal",content:p,slots:f,fromPayload:!0};if(u)return s(p)?{kind:"fragment",name:i,slots:f,parameters:p,fromPayload:!0}:o(r.malformedNode,`fragments have no single-value or positional form — '${t}' takes a named-arguments object`);const c=n.operators.get(i);return{kind:"operator",operator:c,spelling:i,slots:f,params:C(c,p,n,o),fromPayload:!0}},C=(e,t,n,a)=>{const u=()=>a(r.positionalArity,`'${e.name}' takes no positional arguments — use the named form`);if(Array.isArray(t)){const n=$(e,t);if(null!==n)return n;if(void 0===e.positionalParams)return u();const s=e.positionalParams;return a(r.positionalArity,`'${e.name}' takes at most ${s.length} positional argument${1===s.length?"":"s"} (${s.join(", ")}), got ${t.length}`)}if(s(t)&&!o(t,n.recognizes)){const n=[];for(const s in t){const o=t[s];if(void 0!==o){if("//"!==s&&i.has(s))return a(r.unknownNodeKey,`'${s}' is not a parameter of '${e.name}'`);n.push([s,o])}}return n}const f=l(e);return null===f?u():[[f,t]]},W={positionalParams:p,restParam:null},x=/*#__PURE__*/new Set(["path","from","default"]),M=(e,r,t)=>"canonical"===t?r:"alias"===t?(e=>{for(const[r,t]of Object.entries(k))if(t===e&&r!==e)return r;return e})(r):e,O=(e,r)=>{if("preserve"===r)return e;const t=u(e);if("reference"!==t.kind)return e;const{token:n,rest:a}=f(e);return`$${M(n,t.namespace,r)}${a}`},S=e=>"index"!==e&&"error"!==e,F=(e,r)=>{if("string"!=typeof e)return null;const t=u(e);if("reference"!==t.kind)return null;const{namespace:n,segments:a}=t;if(!S(n))return null;const{token:s,rest:o}=f(e),i=(l=o).startsWith(".")?l.slice(1):l;var l;return"data"===n?{operator:"get",path:i}:"element"!==n&&a.length>0&&"string"!=typeof a[0]?null:{operator:"get",path:i,from:`$${M(s,n,r)}`}},K=(e,r)=>{if(e.has("default"))return null;const t=(e=>{if("string"==typeof e){if(e.startsWith("$"))return null;try{return h(e)}catch{return null}}if(!Array.isArray(e))return null;for(const r of e)if(!("string"==typeof r&&!r.startsWith("$")||"number"==typeof r&&Number.isInteger(r)&&r>=0))return null;return e})(e.get("path"));if(null===t)return null;const n=c(t);let a;const s=e.get("from");if(void 0===s)a="canonical"===r?"$data":"$d";else{if("string"!=typeof s)return null;const e=m(s);if("vars"===e||"params"===e){if(0===t.length?"vars"===e:"string"!=typeof t[0])return null;a=`$${M(f(s).token,e,r)}`}else{const e=u(s);if("reference"!==e.kind||!S(e.namespace))return null;if(""!==n&&e.segments.includes(d))return null;a=O(s,r).replace(/\.$/,"")}}return""===n?a:n.startsWith("[")?`${a}${n}`:`${a}.${n}`},E=e=>{const r=[];for(let t=e;null!==t;t=t.parent)r.push(t.key);return r.reverse()};class G{lookup;writer;path=null;depth=0;constructor(e,r){this.lookup=e,this.writer=r}fail=(e,r)=>{throw new g({code:e,message:r,path:E(this.path)})};child(e,r){return this.within(r,()=>this.value(e))}within(e,r){const{path:t,depth:n}=this;this.path={parent:t,key:e},this.depth=n+1;const a=r();return this.path=t,this.depth=n,a}value(t){if(this.depth>v&&this.fail(r.depthCeiling,`the expression nests deeper than the engine's ceiling of ${v} levels`),"string"==typeof t)return this.writer.string(t);if(Array.isArray(t))return t.map((e,r)=>this.child(e,r));if(!s(t))return t;const n=((t,n,a)=>{const s=e(t,n.recognizes);switch(s.kind){case"malformed":return a(r.malformedNode,s.message);case"plain":return s;case"operator":return N(t,n,a);case"fragment":return b(t,n,a);case"shorthand":return z(t,s.key,n,a)}})(t,this.lookup,this.fail);switch(n.kind){case"plain":return this.entries(t,!0);case"operator":return this.writer.operator(n,this);case"fragment":return this.writer.fragment(n,this);case"literal":return this.writer.literal(n,this)}}keep({key:e,value:r}){return"fallback"===e?this.child(r,e):"vars"===e?this.vars(r):r}parameters(e){return!s(e)||o(e,this.lookup.recognizes)?this.child(e,"parameters"):this.within("parameters",()=>this.entries(e,!1))}entries(e,r){const t={};for(const n in e){const a=e[n];t[n]="//"===n?a:r&&"vars"===n?this.vars(a):this.child(a,n)}return t}vars(e){return s(e)?this.within("vars",()=>this.entries(e,!1)):e}}const I=(e,r)=>"canonical"===r?e.operator.name:"alias"===r?e.operator.alias??e.operator.name:e.spelling,R=e=>Array.isArray(e)?e:[e],q=(e,r)=>[...R(e),...R(r)],D=e=>e.params.find(([e])=>"//"===e)?.[1],B=e=>e.slots.some(e=>"keep"===e.kind&&"//"===e.key),H={kind:"named"},J=(e,r)=>!(Array.isArray(e)||s(e)&&!o(e,r.recognizes)),L=(e={})=>{const r=e.operatorNames??"preserve",t=e.referenceNames??"preserve",n="named"===e.arguments,a=e.getAsReference??!0;return{operator:(e,s)=>{const o=e.params.map(([e,r])=>[e,"//"===e?r:s.child(r,e)]),i=o.filter(([e])=>"//"!==e);if(a&&"get"===e.operator.name){const r=e.slots.some(e=>"keep"===e.kind)||e.params.some(([e])=>"//"===e)?null:K(new Map(i),t);if(null!==r)return r}const l=n?H:((e,r,t)=>{const n=e.positionalParams;if(void 0===n||0===r.length)return H;const a=e.restParam,s=null===a?n:n.slice(0,-1),o=new Map(r);for(const e of o.keys())if(e!==a&&!s.includes(e))return H;let i=0;for(;i<s.length&&o.has(s[i]);)i++;for(let e=i;e<s.length;e++)if(o.has(s[e]))return H;const l=null!==a&&o.has(a);if(null!==a&&l!==(i===s.length))return H;const u=s.slice(0,i).map(e=>o.get(e));if(l){const e=o.get(a);return Array.isArray(e)?{kind:"array",value:[...u,...e]}:0===s.length&&J(e,t)?{kind:"single",value:e}:H}return 1===i&&J(u[0],t)?{kind:"single",value:u[0]}:{kind:"array",value:u}})(e.operator,i,s.lookup),u="named"===l.kind?void 0:D(e),f=void 0!==u&&B(e),p={};for(const t of e.slots)"invocation"===t.kind?(void 0===u||f||(p["//"]=u),p[`$${I(e,r)}`]="named"===l.kind?Object.fromEntries(o):l.value):"keep"===t.kind&&(p[t.key]="//"===t.key&&f?q(t.value,u):s.keep(t));return p},fragment:(e,r)=>{const t=void 0===e.parameters?{}:r.parameters(e.parameters),n="string"==typeof t,a={};for(const s of e.slots)"invocation"===s.kind?n?(a.fragment=e.name,e.fromPayload&&(a.parameters=t)):a[`$${e.name}`]=t:"param"===s.kind?n&&(a.parameters=t):a[s.key]=r.keep(s);return a},literal:(e,r)=>{const t={};for(const n of e.slots)"invocation"===n.kind?t.$literal=e.content:"keep"===n.kind&&(t[n.key]=r.keep(n));return t},string:e=>O(e,t)}},Q=(e,r,t)=>new G(y(r),((e={})=>{const r=e.operatorNames??"preserve",t=e.referenceNames??"preserve",n=e.referencesAsGet??!1;return{operator:(e,t)=>{const n={},a=e.fromPayload?D(e):void 0,s=void 0!==a&&B(e);for(const o of e.slots)if("invocation"===o.kind){if(void 0===a||s||(n["//"]=a),n.operator=I(e,r),e.fromPayload)for(const[r,a]of e.params)"//"!==r&&(n[r]=t.child(a,r))}else"param"===o.kind?n[o.name]=t.child(o.value,o.name):"//"===o.key&&s?n["//"]=q(o.value,a):n[o.key]=t.keep(o);return n},fragment:(e,r)=>{const t={};for(const n of e.slots)"invocation"===n.kind?(t.fragment=e.name,e.fromPayload&&(t.parameters=r.parameters(e.parameters))):"param"===n.kind?t.parameters=r.parameters(n.value):t[n.key]=r.keep(n);return t},literal:(e,r)=>{const t={};for(const n of e.slots)"invocation"===n.kind?(t.operator="literal",e.fromPayload&&(t.value=e.content)):"param"===n.kind?t.value=e.content:t[n.key]=r.keep(n);return t},string:e=>{if(n){const r=F(e,t);if(null!==r)return r}return O(e,t)}}})(t)).value(e),T=(e,r,t)=>new G(y(r),L(t)).value(e),U=(e,r)=>F(e,r?.referenceNames??"preserve"),V=(e,r)=>{const t=(e=>{if(!s(e))return null;const r=new Map;if("operator"in e){if("get"!==e.operator)return null;for(const t in e){const n=e[t];if("operator"!==t&&"//"!==t&&void 0!==n){if(!x.has(t))return null;r.set(t,n)}}return r}for(const r in e)if("$get"!==r&&"//"!==r)return null;if(!("$get"in e))return null;const t=e.$get;if(Array.isArray(t)){const e=$(W,t);if(null===e)return null;for(const[t,n]of e)r.set(t,n);return r}if(s(t)){for(const e in t){const n=t[e];if("//"!==e&&void 0!==n){if(!x.has(e))return null;r.set(e,n)}}return r}return r.set(l(W),t),r})(e);return null===t?null:K(t,r?.referenceNames??"preserve")};export{e as classifyObject,n as positionalLayout,u as recognizeReference,l as singlePositionalTarget,Q as toCanonical,U as toGet,V as toReference,T as toShorthand};
|
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.10";
|
|
2
2
|
|
|
3
3
|
interface HttpRequest {
|
|
4
4
|
url: string;
|
|
@@ -25,55 +25,63 @@ interface CacheStore {
|
|
|
25
25
|
clear(): void;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
type FigTreeErrorCode = string;
|
|
29
28
|
declare const ErrorCodes: {
|
|
30
|
-
readonly unknownOperator: "unknown-operator";
|
|
31
29
|
readonly typeCheck: "type-check";
|
|
32
30
|
readonly operatorFailure: "operator-failure";
|
|
33
|
-
readonly timeout: "timeout";
|
|
34
31
|
readonly requestTimeout: "request-timeout";
|
|
35
|
-
readonly
|
|
36
|
-
readonly
|
|
37
|
-
readonly
|
|
38
|
-
readonly
|
|
39
|
-
readonly
|
|
32
|
+
readonly httpStatus: "http-status";
|
|
33
|
+
readonly invalidResponse: "invalid-response";
|
|
34
|
+
readonly graphQLErrors: "graphql-errors";
|
|
35
|
+
readonly sqlError: "sql-error";
|
|
36
|
+
readonly requestFailure: "request-failure";
|
|
40
37
|
readonly nonFiniteResult: "non-finite-result";
|
|
41
38
|
readonly escapedHandle: "escaped-handle";
|
|
42
39
|
readonly emptyAggregate: "empty-aggregate";
|
|
40
|
+
readonly missingDataPath: "missing-data-path";
|
|
41
|
+
readonly missingRequired: "missing-required";
|
|
42
|
+
readonly timeout: "timeout";
|
|
43
|
+
readonly aborted: "aborted";
|
|
43
44
|
readonly malformedNode: "malformed-node";
|
|
45
|
+
readonly unknownOperator: "unknown-operator";
|
|
44
46
|
readonly unknownFragment: "unknown-fragment";
|
|
47
|
+
readonly unknownNodeKey: "unknown-node-key";
|
|
48
|
+
readonly unrecognizedIdentifier: "unrecognized-identifier";
|
|
45
49
|
readonly positionalArity: "positional-arity";
|
|
46
50
|
readonly invalidVars: "invalid-vars";
|
|
47
51
|
readonly invalidReference: "invalid-reference";
|
|
48
|
-
readonly
|
|
49
|
-
readonly
|
|
50
|
-
readonly missingRequired: "missing-required";
|
|
52
|
+
readonly invalidAs: "invalid-as";
|
|
53
|
+
readonly unresolvedVar: "unresolved-var";
|
|
51
54
|
readonly unresolvedParam: "unresolved-param";
|
|
52
55
|
readonly unresolvedBinding: "unresolved-binding";
|
|
53
|
-
readonly
|
|
54
|
-
readonly
|
|
56
|
+
readonly bareVars: "bare-vars";
|
|
57
|
+
readonly varCycle: "var-cycle";
|
|
58
|
+
readonly depthCeiling: "depth-ceiling";
|
|
55
59
|
readonly maxDepthExceeded: "max-depth";
|
|
56
60
|
readonly maxNodesExceeded: "max-nodes";
|
|
57
61
|
readonly returnsMismatch: "returns-mismatch";
|
|
58
62
|
readonly operatorValidate: "operator-validate";
|
|
59
|
-
readonly
|
|
63
|
+
readonly uselessModifier: "useless-modifier";
|
|
64
|
+
readonly unreferencedVar: "unreferenced-var";
|
|
60
65
|
readonly shadowedVar: "shadowed-var";
|
|
61
|
-
readonly
|
|
62
|
-
readonly
|
|
63
|
-
readonly fragmentCycle: "fragment-cycle";
|
|
66
|
+
readonly deadBinding: "dead-binding";
|
|
67
|
+
readonly fallbackMismatch: "fallback-mismatch";
|
|
64
68
|
readonly unboundToken: "unbound-token";
|
|
65
69
|
readonly unusedSubstitution: "unused-substitution";
|
|
66
|
-
readonly tokenRenumber: "token-renumber";
|
|
67
70
|
readonly inertReferenceToken: "inert-reference-token";
|
|
68
71
|
readonly invalidDefinition: "invalid-definition";
|
|
69
72
|
readonly invalidName: "invalid-name";
|
|
70
73
|
readonly reservedName: "reserved-name";
|
|
71
74
|
readonly invalidNullPolicy: "invalid-null-policy";
|
|
72
75
|
readonly duplicateOperator: "duplicate-operator";
|
|
76
|
+
readonly fragmentCycle: "fragment-cycle";
|
|
73
77
|
readonly invalidOptions: "invalid-options";
|
|
74
78
|
};
|
|
79
|
+
type KnownErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
80
|
+
type FigTreeErrorCode = KnownErrorCode | (string & {});
|
|
81
|
+
type KnownFallbackErrorCode = (typeof ErrorCodes)['typeCheck' | 'operatorFailure' | 'requestTimeout' | 'httpStatus' | 'invalidResponse' | 'graphQLErrors' | 'sqlError' | 'requestFailure' | 'nonFiniteResult' | 'escapedHandle' | 'emptyAggregate' | 'missingDataPath' | 'missingRequired' | 'timeout'];
|
|
82
|
+
type FallbackErrorCode = KnownFallbackErrorCode | (string & {});
|
|
75
83
|
|
|
76
|
-
type Severity = 'error' | 'warning'
|
|
84
|
+
type Severity = 'error' | 'warning';
|
|
77
85
|
interface Issue {
|
|
78
86
|
severity: Severity;
|
|
79
87
|
code: FigTreeErrorCode;
|
|
@@ -82,11 +90,11 @@ interface Issue {
|
|
|
82
90
|
operator?: string;
|
|
83
91
|
fragment?: string;
|
|
84
92
|
parameter?: string;
|
|
93
|
+
suggestion?: string;
|
|
85
94
|
}
|
|
86
95
|
interface ValidationResult {
|
|
87
96
|
valid: boolean;
|
|
88
97
|
issues: Issue[];
|
|
89
|
-
timeoutShielded: boolean;
|
|
90
98
|
}
|
|
91
99
|
|
|
92
100
|
declare const LAZY_HANDLE: unique symbol;
|
|
@@ -171,11 +179,19 @@ interface ShieldedFallbackTraceEvent {
|
|
|
171
179
|
}
|
|
172
180
|
type KnownTraceEvent = CacheTraceEvent | RequestTraceEvent | QueryTraceEvent | RenderTraceEvent | KeyOverwriteTraceEvent | ShieldedFallbackTraceEvent;
|
|
173
181
|
|
|
182
|
+
interface FallbackError {
|
|
183
|
+
code: FallbackErrorCode;
|
|
184
|
+
message: string;
|
|
185
|
+
path: (string | number)[];
|
|
186
|
+
operator?: string;
|
|
187
|
+
fragment?: string;
|
|
188
|
+
fragmentPath?: (string | number)[];
|
|
189
|
+
errorData?: Record<string, unknown>;
|
|
190
|
+
}
|
|
174
191
|
interface FigTreeErrorInit {
|
|
175
192
|
code: FigTreeErrorCode;
|
|
176
193
|
message: string;
|
|
177
194
|
path: (string | number)[];
|
|
178
|
-
holePath?: (string | number)[];
|
|
179
195
|
operator?: string;
|
|
180
196
|
fragment?: string;
|
|
181
197
|
fragmentPath?: (string | number)[];
|
|
@@ -188,7 +204,6 @@ interface FigTreeErrorInit {
|
|
|
188
204
|
declare class FigTreeError extends Error {
|
|
189
205
|
code: FigTreeErrorCode;
|
|
190
206
|
path: (string | number)[];
|
|
191
|
-
holePath?: (string | number)[];
|
|
192
207
|
operator?: string;
|
|
193
208
|
fragment?: string;
|
|
194
209
|
fragmentPath?: (string | number)[];
|
|
@@ -236,6 +251,96 @@ declare const validateHelpers: Readonly<{
|
|
|
236
251
|
}>;
|
|
237
252
|
type ValidateHelpers = typeof validateHelpers;
|
|
238
253
|
|
|
254
|
+
interface FallbackCoverage {
|
|
255
|
+
uncovered: CoverageFinding[];
|
|
256
|
+
covered: CoveredFinding[];
|
|
257
|
+
}
|
|
258
|
+
interface CoverageFinding {
|
|
259
|
+
path: (string | number)[];
|
|
260
|
+
code: FigTreeErrorCode;
|
|
261
|
+
message: string;
|
|
262
|
+
certainty: 'may' | 'always';
|
|
263
|
+
operator?: string;
|
|
264
|
+
parameter?: string;
|
|
265
|
+
fragment?: string;
|
|
266
|
+
fragmentPath?: (string | number)[];
|
|
267
|
+
}
|
|
268
|
+
interface CoveredFinding extends CoverageFinding {
|
|
269
|
+
coveredBy: (string | number)[];
|
|
270
|
+
coveredByFragmentPath?: (string | number)[];
|
|
271
|
+
givesNull?: true;
|
|
272
|
+
}
|
|
273
|
+
interface FallbackCoverageOptions {
|
|
274
|
+
strictNumbers?: boolean;
|
|
275
|
+
}
|
|
276
|
+
interface OperatorAnalysis {
|
|
277
|
+
failures?: FailureRule[];
|
|
278
|
+
external?: true;
|
|
279
|
+
output?: DeclaredOutput;
|
|
280
|
+
}
|
|
281
|
+
interface FailureRule {
|
|
282
|
+
code: FallbackErrorCode;
|
|
283
|
+
parameter?: string;
|
|
284
|
+
when?: Record<string, FailureTest>;
|
|
285
|
+
options?: Record<string, unknown>;
|
|
286
|
+
may?: true;
|
|
287
|
+
overflow?: true;
|
|
288
|
+
}
|
|
289
|
+
type FailureTest = string | number | boolean | null | {
|
|
290
|
+
type: ExpectedType;
|
|
291
|
+
} | {
|
|
292
|
+
below: number;
|
|
293
|
+
} | {
|
|
294
|
+
empty: true;
|
|
295
|
+
} | {
|
|
296
|
+
supplied: boolean;
|
|
297
|
+
} | {
|
|
298
|
+
invalid: true;
|
|
299
|
+
} | {
|
|
300
|
+
some: FailureTest;
|
|
301
|
+
} | {
|
|
302
|
+
not: FailureTest;
|
|
303
|
+
};
|
|
304
|
+
type DeclaredOutput = ExpectedType | {
|
|
305
|
+
type: 'number' | 'integer';
|
|
306
|
+
min?: number;
|
|
307
|
+
max?: number;
|
|
308
|
+
} | {
|
|
309
|
+
type: 'string' | 'array';
|
|
310
|
+
minLength?: number;
|
|
311
|
+
} | {
|
|
312
|
+
param: string;
|
|
313
|
+
} | {
|
|
314
|
+
elementOf: string;
|
|
315
|
+
} | {
|
|
316
|
+
kindOf: string;
|
|
317
|
+
} | {
|
|
318
|
+
arrayOf: DeclaredOutput;
|
|
319
|
+
minLength?: number;
|
|
320
|
+
} | {
|
|
321
|
+
oneOf: DeclaredOutput[];
|
|
322
|
+
} | {
|
|
323
|
+
typeNamedBy: string;
|
|
324
|
+
} | {
|
|
325
|
+
byParam: string;
|
|
326
|
+
cases: Record<string, DeclaredOutput>;
|
|
327
|
+
otherwise?: DeclaredOutput;
|
|
328
|
+
} | {
|
|
329
|
+
firstNonNull: string;
|
|
330
|
+
} | {
|
|
331
|
+
sum: string;
|
|
332
|
+
} | {
|
|
333
|
+
product: string;
|
|
334
|
+
} | {
|
|
335
|
+
difference: [string, string];
|
|
336
|
+
} | {
|
|
337
|
+
abs: string;
|
|
338
|
+
} | {
|
|
339
|
+
min: string;
|
|
340
|
+
} | {
|
|
341
|
+
max: string;
|
|
342
|
+
};
|
|
343
|
+
|
|
239
344
|
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
345
|
literal: readonly (infer M)[];
|
|
241
346
|
} ? M : T extends readonly (infer B)[] ? TypeOf<B> : unknown;
|
|
@@ -338,9 +443,9 @@ interface OperatorDefinition<P extends ParameterDeclarations = ParameterDeclarat
|
|
|
338
443
|
parameters: P;
|
|
339
444
|
positionalParams?: readonly string[];
|
|
340
445
|
timeoutParam?: string;
|
|
341
|
-
|
|
342
|
-
cache?: 'auto' | 'manual';
|
|
446
|
+
cache?: true;
|
|
343
447
|
validate?: OperatorValidate;
|
|
448
|
+
analysis?: OperatorAnalysis;
|
|
344
449
|
evaluate: (params: ResolvedParams<P>, context: OperatorContext) => unknown;
|
|
345
450
|
returns?: ExpectedType;
|
|
346
451
|
}
|
|
@@ -372,10 +477,10 @@ interface ValidatedOperatorDefinition {
|
|
|
372
477
|
resolution: ResolutionPlan;
|
|
373
478
|
deliversLazily: boolean;
|
|
374
479
|
timeoutParam: string | null;
|
|
375
|
-
|
|
376
|
-
cache: 'auto' | 'manual';
|
|
480
|
+
cache: boolean;
|
|
377
481
|
fingerprint: string;
|
|
378
482
|
validate?: OperatorValidate;
|
|
483
|
+
analysis?: OperatorAnalysis;
|
|
379
484
|
evaluate: OperatorEvaluate;
|
|
380
485
|
returns: ExpectedType;
|
|
381
486
|
}
|
|
@@ -406,6 +511,63 @@ declare const resolvePath: (source: unknown, path: string | PathSegment[]) => Re
|
|
|
406
511
|
|
|
407
512
|
declare const deepEqual: (foo: any, bar: any) => boolean;
|
|
408
513
|
|
|
514
|
+
declare const NAMESPACE_TOKENS: {
|
|
515
|
+
readonly data: "data";
|
|
516
|
+
readonly d: "data";
|
|
517
|
+
readonly vars: "vars";
|
|
518
|
+
readonly v: "vars";
|
|
519
|
+
readonly params: "params";
|
|
520
|
+
readonly p: "params";
|
|
521
|
+
readonly element: "element";
|
|
522
|
+
readonly e: "element";
|
|
523
|
+
readonly index: "index";
|
|
524
|
+
readonly i: "index";
|
|
525
|
+
readonly error: "error";
|
|
526
|
+
readonly err: "error";
|
|
527
|
+
};
|
|
528
|
+
type ReferenceNamespace = (typeof NAMESPACE_TOKENS)[keyof typeof NAMESPACE_TOKENS];
|
|
529
|
+
type ReferenceRecognition = {
|
|
530
|
+
kind: 'reference';
|
|
531
|
+
namespace: ReferenceNamespace;
|
|
532
|
+
segments: PathSegment[];
|
|
533
|
+
drill: string;
|
|
534
|
+
binding?: string;
|
|
535
|
+
} | {
|
|
536
|
+
kind: 'invalid';
|
|
537
|
+
namespace: ReferenceNamespace;
|
|
538
|
+
reason: string;
|
|
539
|
+
code?: string;
|
|
540
|
+
} | {
|
|
541
|
+
kind: 'unrecognized';
|
|
542
|
+
} | {
|
|
543
|
+
kind: 'plain';
|
|
544
|
+
};
|
|
545
|
+
interface ReferenceScope {
|
|
546
|
+
bindings?: readonly string[];
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
type ObjectClass = {
|
|
550
|
+
kind: 'operator';
|
|
551
|
+
} | {
|
|
552
|
+
kind: 'fragment';
|
|
553
|
+
} | {
|
|
554
|
+
kind: 'shorthand';
|
|
555
|
+
key: string;
|
|
556
|
+
} | {
|
|
557
|
+
kind: 'plain';
|
|
558
|
+
} | {
|
|
559
|
+
kind: 'malformed';
|
|
560
|
+
message: string;
|
|
561
|
+
};
|
|
562
|
+
interface PositionalShape {
|
|
563
|
+
positionalParams?: readonly string[];
|
|
564
|
+
restParam: string | null;
|
|
565
|
+
}
|
|
566
|
+
interface PositionalLayout {
|
|
567
|
+
bound: number;
|
|
568
|
+
restAt: number | null;
|
|
569
|
+
}
|
|
570
|
+
|
|
409
571
|
interface FragmentParameterDeclaration extends TypeDeclaration {
|
|
410
572
|
default?: unknown;
|
|
411
573
|
description?: string;
|
|
@@ -427,7 +589,7 @@ interface FragmentParameter {
|
|
|
427
589
|
}
|
|
428
590
|
|
|
429
591
|
type EvaluationOptions = Omit<FigTreeOptions, 'operators' | 'fragments'>;
|
|
430
|
-
type CallOptions = Pick<FigTreeOptions, 'data' | 'signal' | 'timeout' | '
|
|
592
|
+
type CallOptions = Pick<FigTreeOptions, 'data' | 'signal' | 'timeout' | 'trace'>;
|
|
431
593
|
type OnlyCallOptions<CallOpts> = CallOpts & {
|
|
432
594
|
[Key in Exclude<keyof CallOpts, keyof CallOptions>]: never;
|
|
433
595
|
};
|
|
@@ -437,6 +599,8 @@ interface FigTreeOptions {
|
|
|
437
599
|
operators?: (ValidatedOperatorDefinition | ValidatedOperatorDefinition[])[];
|
|
438
600
|
operatorDefaults?: {
|
|
439
601
|
[operator: string]: {
|
|
602
|
+
noCache?: true;
|
|
603
|
+
fallback?: unknown;
|
|
440
604
|
[param: string]: unknown;
|
|
441
605
|
};
|
|
442
606
|
};
|
|
@@ -453,26 +617,27 @@ interface FigTreeOptions {
|
|
|
453
617
|
maxNodes?: number;
|
|
454
618
|
timeout?: number;
|
|
455
619
|
signal?: AbortSignal;
|
|
456
|
-
useCache?: boolean;
|
|
457
620
|
cache?: {
|
|
458
621
|
store?: CacheStore;
|
|
459
622
|
maxSize?: number;
|
|
460
623
|
maxTime?: number;
|
|
461
624
|
};
|
|
462
|
-
runtimeTypeCheck?: boolean;
|
|
463
|
-
mode?: 'throw' | 'report';
|
|
464
625
|
trace?: boolean;
|
|
465
626
|
}
|
|
627
|
+
type OptionsUpdate = {
|
|
628
|
+
[Key in keyof FigTreeOptions]?: (Key extends MergedBlock ? Removable<NonNullable<FigTreeOptions[Key]>> : FigTreeOptions[Key]) | null;
|
|
629
|
+
};
|
|
630
|
+
type MergedBlock = 'fragments' | 'operatorDefaults' | 'http' | 'graphQL' | 'cache';
|
|
631
|
+
type Removable<Block> = {
|
|
632
|
+
[Key in keyof Block]?: Block[Key] | null;
|
|
633
|
+
};
|
|
466
634
|
interface EvaluationResult {
|
|
467
635
|
result: unknown;
|
|
468
|
-
|
|
469
|
-
trace?: TraceNode;
|
|
636
|
+
trace: TraceNode;
|
|
470
637
|
}
|
|
471
638
|
type NoOptions = Record<never, never>;
|
|
472
639
|
type Merge<Instance, Call> = Omit<Instance, keyof Call> & Call;
|
|
473
640
|
type ResultShape<O> = O extends {
|
|
474
|
-
mode: 'report';
|
|
475
|
-
} | {
|
|
476
641
|
trace: true;
|
|
477
642
|
} ? EvaluationResult : unknown;
|
|
478
643
|
|
|
@@ -485,29 +650,31 @@ interface Dependencies {
|
|
|
485
650
|
fragments: string[];
|
|
486
651
|
}
|
|
487
652
|
interface ParameterInfo extends ValidatedParameter {
|
|
488
|
-
|
|
653
|
+
hostDefault?: unknown;
|
|
489
654
|
}
|
|
490
655
|
interface OperatorInfo extends Omit<ValidatedOperatorDefinition, typeof VALIDATED_OPERATOR | 'evaluate' | 'validate' | 'deliversLazily' | 'resolution' | 'fingerprint' | 'parameters'> {
|
|
491
656
|
parameters: Record<string, ParameterInfo>;
|
|
492
657
|
hasValidate: boolean;
|
|
493
|
-
|
|
494
|
-
|
|
658
|
+
hostNoCache?: true;
|
|
659
|
+
hostFallback?: unknown;
|
|
495
660
|
}
|
|
496
661
|
interface FragmentInfo {
|
|
497
662
|
name: string;
|
|
498
663
|
description?: string;
|
|
499
664
|
metadata?: Record<string, unknown>;
|
|
500
665
|
parameters: Record<string, FragmentParameter>;
|
|
666
|
+
returns: ExpectedType;
|
|
501
667
|
warnings: Issue[];
|
|
502
668
|
dependencies: Dependencies;
|
|
669
|
+
caches: boolean;
|
|
503
670
|
}
|
|
504
671
|
|
|
505
672
|
declare class FigTree<InstanceOpts extends FigTreeOptions = NoOptions> {
|
|
506
673
|
private state;
|
|
507
674
|
private readonly results;
|
|
508
|
-
readonly version = "3.0.0-preview.
|
|
675
|
+
readonly version = "3.0.0-preview.10";
|
|
509
676
|
constructor(options?: InstanceOpts);
|
|
510
|
-
updateOptions(options?:
|
|
677
|
+
updateOptions(options?: OptionsUpdate): void;
|
|
511
678
|
clearCache(): void;
|
|
512
679
|
getOptions(): EvaluationOptions;
|
|
513
680
|
getOperators(): OperatorInfo[];
|
|
@@ -534,11 +701,11 @@ declare function defineOperator<const P extends ParameterDeclarations>(definitio
|
|
|
534
701
|
declare const coreOperators: ValidatedOperatorDefinition[];
|
|
535
702
|
|
|
536
703
|
interface OperatorFailureInit {
|
|
537
|
-
code?:
|
|
704
|
+
code?: FallbackErrorCode;
|
|
538
705
|
errorData?: Record<string, unknown>;
|
|
539
706
|
}
|
|
540
707
|
declare class OperatorFailure extends Error {
|
|
541
|
-
code?:
|
|
708
|
+
code?: FallbackErrorCode;
|
|
542
709
|
errorData?: Record<string, unknown>;
|
|
543
710
|
constructor(message: string, init?: OperatorFailureInit);
|
|
544
711
|
}
|
|
@@ -618,6 +785,15 @@ declare class SQLiteConnection implements SqlConnection {
|
|
|
618
785
|
query: (req: SqlRequest) => Promise<Record<string, unknown>[]>;
|
|
619
786
|
}
|
|
620
787
|
|
|
788
|
+
interface HttpFailureInfo {
|
|
789
|
+
status: number;
|
|
790
|
+
statusText: string;
|
|
791
|
+
url: string;
|
|
792
|
+
response: unknown;
|
|
793
|
+
}
|
|
794
|
+
declare const httpFailure: (info: HttpFailureInfo) => OperatorFailure;
|
|
795
|
+
declare const sqlFailure: (driver: string, error: unknown) => OperatorFailure;
|
|
796
|
+
|
|
621
797
|
type Json = null | boolean | number | string | Json[] | {
|
|
622
798
|
[key: string]: Json;
|
|
623
799
|
};
|
|
@@ -642,8 +818,8 @@ type InspectNode = {
|
|
|
642
818
|
params: NodeMap;
|
|
643
819
|
fallback?: InspectNode;
|
|
644
820
|
timeoutFallback?: Json;
|
|
645
|
-
|
|
646
|
-
|
|
821
|
+
noCache?: true;
|
|
822
|
+
hostDefaults?: string[];
|
|
647
823
|
} | {
|
|
648
824
|
kind: 'fragmentCall';
|
|
649
825
|
vars?: NodeMap;
|
|
@@ -653,6 +829,7 @@ type InspectNode = {
|
|
|
653
829
|
parameters?: NodeMap | InspectNode;
|
|
654
830
|
fallback?: InspectNode;
|
|
655
831
|
timeoutFallback?: Json;
|
|
832
|
+
noCache?: true;
|
|
656
833
|
} | {
|
|
657
834
|
kind: 'skeleton';
|
|
658
835
|
vars?: NodeMap;
|
|
@@ -729,7 +906,7 @@ type TypeSeeds = {
|
|
|
729
906
|
};
|
|
730
907
|
|
|
731
908
|
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' | '
|
|
909
|
+
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';
|
|
733
910
|
tag: 'non-convertible' | 'intentional-semantic-change' | 'lossy-default';
|
|
734
911
|
path: (string | number)[];
|
|
735
912
|
message: string;
|
|
@@ -776,5 +953,5 @@ interface ShorthandOptions extends NameOptions {
|
|
|
776
953
|
getAsReference?: boolean;
|
|
777
954
|
}
|
|
778
955
|
|
|
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 };
|
|
956
|
+
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 };
|
|
957
|
+
export type { AxiosErrorLike, AxiosLike, BasicType, CacheStore, CacheTraceEvent, CallOptions, CanonicalOptions, CategoryHintMap, CategoryHints, CompiledNullPolicy, ConditionalNullPolicy, Constraints, CoverageFinding, CoveredFinding, DeclaredOutput, Dependencies, EvaluationMode, EvaluationOptions, EvaluationResult, ExpectedType, FailureRule, FailureTest, FallbackCoverage, FallbackCoverageOptions, FallbackError, FallbackErrorCode, FetchLike, FetchResponseLike, FigTreeErrorCode, FigTreeErrorInit, FigTreeOptions, FragmentDefinition, FragmentHints, FragmentInfo, FragmentMigrationResult, FragmentParameter, FragmentParameterDeclaration, HttpClient, HttpFailureInfo, HttpRequest, InspectDependencies, InspectIssue, InspectNode, InspectReport, Issue, KeyOverwriteTraceEvent, KnownTraceEvent, LazyValue, LiteralType, Merge, MigrationIssue, MigrationResult, NameOptions, NoOptions, NullPolicy, NullPolicyValue, ObjectClass, OnlyCallOptions, OperatorAnalysis, OperatorCategory, OperatorContext, OperatorDefinition, OperatorEvaluate, OperatorFailureInit, OperatorHintMap, OperatorHints, OperatorInfo, 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, ValidatedOperatorDefinition, ValidatedParameter, ValidationResult, Wildcard };
|