@holistics/anfra-sdk 0.13.3 → 0.13.5

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/dist/api.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Client } from 'openapi-fetch';
2
- import { ak as paths, al as components } from './types-B9DqPgWS.js';
2
+ import { ak as paths, al as components } from './types-CWNv6N0y.js';
3
3
  import { DatasetDescriptor, Backend, BackendExportRequest, BackendQueryRequest } from './app.js';
4
4
  import { DataAppError } from './app.js';
5
5
 
package/dist/app.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { S as Sdk } from './bootstrap-DctKHBAj.js';
2
- export { A as AnfraPlugins, a as App, C as Control, b as CrossFilter, D as DateDrillControl, c as DeprecatedFeatures, E as Edge, F as Filter, d as FrameKernel, I as InstalledPlugins, M as Mapping, O as OVERLAY_ID, e as PluginApi, f as PluginMembers, g as PluginName, P as PluginSetup, Q as Query, h as STRUCTURE_ATTRIBUTES, V as VERSION, i as bootstrap, j as buildStructure, k as createSdk, p as parseRef } from './bootstrap-DctKHBAj.js';
1
+ import { S as Sdk } from './bootstrap-BbsNvZ8s.js';
2
+ export { A as AnfraPlugins, a as App, C as Control, b as CrossFilter, D as DateDrillControl, c as DeprecatedFeatures, E as Edge, F as Filter, d as FrameKernel, I as InstalledPlugins, M as Mapping, O as OVERLAY_ID, e as PluginApi, f as PluginMembers, g as PluginName, P as PluginSetup, Q as Query, h as STRUCTURE_ATTRIBUTES, V as VERSION, i as bootstrap, j as buildStructure, k as createSdk, p as parseRef } from './bootstrap-BbsNvZ8s.js';
3
3
  export { D as DataAppError, P as PermissionError, Q as QueryError, T as TransportError, V as ValidationError } from './errors-CKvqVaqU.js';
4
- export { A as Aggregation, a as AppDeclaration, b as AppJson, c as ArrowType, B as Backend, d as BackendCondition, e as BackendDateDrill, f as BackendExportRequest, g as BackendFilter, h as BackendLineageRequest, i as BackendQueryRequest, j as BackendQueryResult, k as BackendSort, C as ColumnMeta, l as Condition, m as ConditionValue, n as ControlMappingJson, o as CrossFilterJson, D as DatasetDescriptor, p as DateDrillDeclaration, q as DateGrain, r as DateTransformation, E as EntityKind, s as EntityRef, t as EntityUsage, u as ExecuteOptions, v as ExecuteSummary, w as ExportFormat, x as ExportFormatOptions, y as ExportOptions, z as ExportResult, F as FILTER_AGGREGATIONS, G as FieldLineage, H as FieldSuggestionsRequest, I as FilterAggregation, J as FilterDeclaration, K as FilterValueType, L as InspectedApp, M as InspectedControl, N as InspectedError, O as InspectedQuery, P as InspectedSelection, Q as InspectedStructure, R as LineageCard, S as LineageDiagram, T as LineageNode, U as LineageOptions, V as LineageResult, W as LineageTarget, X as Listener, Y as LocateKind, Z as LocateTarget, _ as MappingJson, $ as Operator, a0 as QueryDebug, a1 as QueryDeclaration, a2 as QueryInput, a3 as QueryResult, a4 as QuerySort, a5 as QueryState, a6 as QueryTimings, a7 as RenderFormat, a8 as RenderRequest, a9 as Rendering, aa as Row, ab as SdkEnvironment, ac as SdkFeatures, ad as Selection, ae as SelectionCondition, af as SemanticType, ag as StructureKind, ah as StructureNode, ai as Unsubscribe, aj as User } from './types-B9DqPgWS.js';
5
- export { B as BridgeError, a as BridgeMessage, F as FrameMessage, H as HostMessage, P as PROVISION_ELEMENT_ID, b as PluginInfo, c as Provision } from './bridge-_Ez5VZV9.js';
4
+ export { A as Aggregation, a as AppDeclaration, b as AppJson, c as ArrowType, B as Backend, d as BackendCondition, e as BackendDateDrill, f as BackendExportRequest, g as BackendFilter, h as BackendLineageRequest, i as BackendQueryRequest, j as BackendQueryResult, k as BackendSort, C as ColumnMeta, l as Condition, m as ConditionValue, n as ControlMappingJson, o as CrossFilterJson, D as DatasetDescriptor, p as DateDrillDeclaration, q as DateGrain, r as DateTransformation, E as EntityKind, s as EntityRef, t as EntityUsage, u as ExecuteOptions, v as ExecuteSummary, w as ExportFormat, x as ExportFormatOptions, y as ExportOptions, z as ExportResult, F as FILTER_AGGREGATIONS, G as FieldLineage, H as FieldSuggestionsRequest, I as FilterAggregation, J as FilterDeclaration, K as FilterValueType, L as InspectedApp, M as InspectedControl, N as InspectedError, O as InspectedQuery, P as InspectedSelection, Q as InspectedStructure, R as LineageCard, S as LineageDiagram, T as LineageNode, U as LineageOptions, V as LineageResult, W as LineageTarget, X as Listener, Y as LocateKind, Z as LocateTarget, _ as MappingJson, $ as Operator, a0 as QueryDebug, a1 as QueryDeclaration, a2 as QueryInput, a3 as QueryResult, a4 as QuerySort, a5 as QueryState, a6 as QueryTimings, a7 as RenderFormat, a8 as RenderRequest, a9 as Rendering, aa as Row, ab as SdkEnvironment, ac as SdkFeatures, ad as Selection, ae as SelectionCondition, af as SemanticType, ag as StructureKind, ah as StructureNode, ai as Unsubscribe, aj as User } from './types-CWNv6N0y.js';
5
+ export { B as BridgeError, a as BridgeMessage, F as FrameMessage, H as HostMessage, P as PROVISION_ELEMENT_ID, b as PluginInfo, c as Provision } from './bridge-WC7GliCH.js';
6
6
 
7
7
  declare const SANDBOX_GLOBAL = "Anfra";
8
8
  /**
package/dist/app.js CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  createSdk,
20
20
  installSandbox,
21
21
  parseRef
22
- } from "./chunk-Q5PSFCLL.js";
22
+ } from "./chunk-KI5CAVAR.js";
23
23
  import {
24
24
  FILTER_AGGREGATIONS
25
25
  } from "./chunk-XIUFHRZE.js";
@@ -27,7 +27,7 @@ import "./chunk-ADWBOQW2.js";
27
27
  import {
28
28
  PROVISION_ELEMENT_ID
29
29
  } from "./chunk-33B2D4U5.js";
30
- import "./chunk-7KEYWCZZ.js";
30
+ import "./chunk-OJ5WIKWE.js";
31
31
  import {
32
32
  DataAppError,
33
33
  PermissionError,
@@ -1,6 +1,6 @@
1
1
  import { D as DataAppError, V as ValidationError, Q as QueryError, P as PermissionError, T as TransportError } from './errors-CKvqVaqU.js';
2
- import { X as Listener, ai as Unsubscribe, D as DatasetDescriptor, y as ExportOptions, z as ExportResult, a8 as RenderRequest, a9 as Rendering, W as LineageTarget, U as LineageOptions, V as LineageResult, E as EntityKind, l as Condition, J as FilterDeclaration, K as FilterValueType, B as Backend, m as ConditionValue, p as DateDrillDeclaration, q as DateGrain, I as FilterAggregation, n as ControlMappingJson, o as CrossFilterJson, ac as SdkFeatures, ad as Selection, ae as SelectionCondition, aa as Row, Y as LocateKind, a1 as QueryDeclaration, a5 as QueryState, a3 as QueryResult, a4 as QuerySort, a as AppDeclaration, u as ExecuteOptions, v as ExecuteSummary, f as BackendExportRequest, b as AppJson, L as InspectedApp, aj as User, ab as SdkEnvironment, Q as InspectedStructure } from './types-B9DqPgWS.js';
3
- import { b as PluginInfo } from './bridge-_Ez5VZV9.js';
2
+ import { X as Listener, ai as Unsubscribe, D as DatasetDescriptor, y as ExportOptions, z as ExportResult, a8 as RenderRequest, a9 as Rendering, W as LineageTarget, U as LineageOptions, V as LineageResult, E as EntityKind, l as Condition, J as FilterDeclaration, K as FilterValueType, B as Backend, m as ConditionValue, p as DateDrillDeclaration, q as DateGrain, I as FilterAggregation, n as ControlMappingJson, o as CrossFilterJson, ac as SdkFeatures, ad as Selection, ae as SelectionCondition, aa as Row, Y as LocateKind, a1 as QueryDeclaration, a5 as QueryState, a3 as QueryResult, a4 as QuerySort, a as AppDeclaration, u as ExecuteOptions, v as ExecuteSummary, f as BackendExportRequest, b as AppJson, L as InspectedApp, aj as User, ab as SdkEnvironment, Q as InspectedStructure } from './types-CWNv6N0y.js';
3
+ import { b as PluginInfo } from './bridge-WC7GliCH.js';
4
4
 
5
5
  interface NotificationTarget {
6
6
  notifyChange(): void;
@@ -1,4 +1,4 @@
1
- import { D as DatasetDescriptor, aj as User } from './types-B9DqPgWS.js';
1
+ import { D as DatasetDescriptor, aj as User } from './types-CWNv6N0y.js';
2
2
 
3
3
  /**
4
4
  * The bridge: the postMessage protocol between a Data App's frame (`app`'s bootstrap) and the
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-33B2D4U5.js";
10
10
  import {
11
11
  version
12
- } from "./chunk-7KEYWCZZ.js";
12
+ } from "./chunk-OJ5WIKWE.js";
13
13
  import {
14
14
  DataAppError,
15
15
  PermissionError,
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.13.3";
2
+ var version = "0.13.5";
3
3
 
4
4
  export {
5
5
  version
package/dist/common.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { D as DataAppError, P as PermissionError, Q as QueryError, T as TransportError, V as ValidationError } from './errors-CKvqVaqU.js';
2
- export { A as Aggregation, a as AppDeclaration, b as AppJson, c as ArrowType, B as Backend, d as BackendCondition, e as BackendDateDrill, f as BackendExportRequest, g as BackendFilter, h as BackendLineageRequest, i as BackendQueryRequest, j as BackendQueryResult, k as BackendSort, C as ColumnMeta, l as Condition, m as ConditionValue, n as ControlMappingJson, o as CrossFilterJson, D as DatasetDescriptor, p as DateDrillDeclaration, q as DateGrain, r as DateTransformation, E as EntityKind, s as EntityRef, t as EntityUsage, u as ExecuteOptions, v as ExecuteSummary, w as ExportFormat, x as ExportFormatOptions, y as ExportOptions, z as ExportResult, F as FILTER_AGGREGATIONS, G as FieldLineage, H as FieldSuggestionsRequest, I as FilterAggregation, J as FilterDeclaration, K as FilterValueType, L as InspectedApp, M as InspectedControl, N as InspectedError, O as InspectedQuery, P as InspectedSelection, Q as InspectedStructure, R as LineageCard, S as LineageDiagram, T as LineageNode, U as LineageOptions, V as LineageResult, W as LineageTarget, X as Listener, Y as LocateKind, Z as LocateTarget, _ as MappingJson, $ as Operator, a0 as QueryDebug, a1 as QueryDeclaration, a2 as QueryInput, a3 as QueryResult, a4 as QuerySort, a5 as QueryState, a6 as QueryTimings, a7 as RenderFormat, a8 as RenderRequest, a9 as Rendering, aa as Row, ab as SdkEnvironment, ac as SdkFeatures, ad as Selection, ae as SelectionCondition, af as SemanticType, ag as StructureKind, ah as StructureNode, ai as Unsubscribe, aj as User } from './types-B9DqPgWS.js';
3
- export { B as BridgeError, a as BridgeMessage, F as FrameMessage, H as HostMessage, P as PROVISION_ELEMENT_ID, b as PluginInfo, c as Provision } from './bridge-_Ez5VZV9.js';
2
+ export { A as Aggregation, a as AppDeclaration, b as AppJson, c as ArrowType, B as Backend, d as BackendCondition, e as BackendDateDrill, f as BackendExportRequest, g as BackendFilter, h as BackendLineageRequest, i as BackendQueryRequest, j as BackendQueryResult, k as BackendSort, C as ColumnMeta, l as Condition, m as ConditionValue, n as ControlMappingJson, o as CrossFilterJson, D as DatasetDescriptor, p as DateDrillDeclaration, q as DateGrain, r as DateTransformation, E as EntityKind, s as EntityRef, t as EntityUsage, u as ExecuteOptions, v as ExecuteSummary, w as ExportFormat, x as ExportFormatOptions, y as ExportOptions, z as ExportResult, F as FILTER_AGGREGATIONS, G as FieldLineage, H as FieldSuggestionsRequest, I as FilterAggregation, J as FilterDeclaration, K as FilterValueType, L as InspectedApp, M as InspectedControl, N as InspectedError, O as InspectedQuery, P as InspectedSelection, Q as InspectedStructure, R as LineageCard, S as LineageDiagram, T as LineageNode, U as LineageOptions, V as LineageResult, W as LineageTarget, X as Listener, Y as LocateKind, Z as LocateTarget, _ as MappingJson, $ as Operator, a0 as QueryDebug, a1 as QueryDeclaration, a2 as QueryInput, a3 as QueryResult, a4 as QuerySort, a5 as QueryState, a6 as QueryTimings, a7 as RenderFormat, a8 as RenderRequest, a9 as Rendering, aa as Row, ab as SdkEnvironment, ac as SdkFeatures, ad as Selection, ae as SelectionCondition, af as SemanticType, ag as StructureKind, ah as StructureNode, ai as Unsubscribe, aj as User } from './types-CWNv6N0y.js';
3
+ export { B as BridgeError, a as BridgeMessage, F as FrameMessage, H as HostMessage, P as PROVISION_ELEMENT_ID, b as PluginInfo, c as Provision } from './bridge-WC7GliCH.js';
package/dist/host.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  import "./chunk-PKBMQBKP.js";
17
17
 
18
18
  // anfra-sdk:anfra-sdk:frame-script
19
- var anfra_sdk_frame_script_default = '"use strict";var __anfraKernel=(()=>{var N=Object.defineProperty;var dt=Object.getOwnPropertyDescriptor;var ct=Object.getOwnPropertyNames;var pt=Object.prototype.hasOwnProperty;var ut=(t,n,e)=>n in t?N(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var o=(t,n)=>N(t,"name",{value:n,configurable:!0});var ft=(t,n)=>{for(var e in n)N(t,e,{get:n[e],enumerable:!0})},mt=(t,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of ct(n))!pt.call(t,i)&&i!==e&&N(t,i,{get:()=>n[i],enumerable:!(r=dt(n,i))||r.enumerable});return t};var ht=t=>mt(N({},"__esModule",{value:!0}),t);var c=(t,n,e)=>ut(t,typeof n!="symbol"?n+"":n,e);var rn={};ft(rn,{bootstrap:()=>at});var Se="anfra-provision";var U=class U extends Error{constructor(e,r){super(e);c(this,"entity");this.name=new.target.name,this.entity=r,Object.setPrototypeOf(this,new.target.prototype)}};o(U,"DataAppError");var S=U,H=class H extends S{};o(H,"ValidationError");var u=H,Y=class Y extends S{constructor(e,r,i){super(e,r);c(this,"cause");this.cause=i}};o(Y,"QueryError");var D=Y,W=class W extends S{};o(W,"PermissionError");var R=W,X=class X extends S{constructor(e,r,i){super(e,i);c(this,"status");this.status=r}};o(X,"TransportError");var C=X;function Ce(){let t=new Error("Aborted");return t.name="AbortError",t}o(Ce,"abortError");function gt(t){return t?.name==="AbortError"}o(gt,"isAbortError");var yt=new Set(["ValidationError","QueryError","PermissionError","TransportError"]);function bt(t){let n=t;return n instanceof Error&&yt.has(n.name)?{name:n.name,message:n.message||"The call failed."}:{name:"QueryError",message:"The call failed."}}o(bt,"toBridgeError");function wt(t){switch(t?.name){case"PermissionError":return new R(t.message);case"TransportError":return new C(t.message);case"ValidationError":return new u(t.message);default:return new D(t?.message||"The call failed.")}}o(wt,"fromBridgeError");function Ae(t,n){let e=new Map,r=new Map,i=1,s=o((l,a,d)=>{let p=new AbortController;r.set(l,p),Promise.resolve().then(()=>n.answer(a,d,p.signal)).then(g=>{p.signal.aborted||t({type:"anfra:result",id:l,ok:!0,result:g})}).catch(g=>{p.signal.aborted||gt(g)||t({type:"anfra:result",id:l,ok:!1,error:bt(g)})}).finally(()=>{r.get(l)===p&&r.delete(l)})},"answer");return{call(l,a,d){return new Promise((p,g)=>{if(d?.aborted){g(Ce());return}let x=i++;e.set(x,{resolve:p,reject:g}),d?.addEventListener("abort",()=>{e.delete(x)&&(t({type:"anfra:cancel",id:x}),g(Ce()))},{once:!0}),t({type:"anfra:call",id:x,name:l,request:a})})},emit(l,a){t({type:"anfra:event",name:l,payload:a})},receive(l){switch(l?.type){case"anfra:call":return s(l.id,l.name,l.request),!0;case"anfra:result":{let a=e.get(l.id);return a&&(e.delete(l.id),l.ok?a.resolve(l.result):a.reject(wt(l.error))),!0}case"anfra:cancel":return r.get(l.id)?.abort(),r.delete(l.id),!0;case"anfra:event":return n.event(l.name,l.payload),!0;default:return!1}},close(l){r.forEach(a=>a.abort()),r.clear(),e.forEach(({reject:a})=>a(l)),e.clear()}}}o(Ae,"createEndpoint");var Z=class Z{constructor(n){c(this,"listeners",new Set);c(this,"parent");this.parent=n}subscribe(n){return this.listeners.add(n),()=>{this.listeners.delete(n)}}notifyChange(){this.listeners.forEach(n=>n()),this.parent?.notifyChange()}notify(){this.notifyChange()}};o(Z,"Observable");var $=Z;var De=["year","quarter","month","week","day","hour","minute"];function xt(t,n){if(!De.includes(n))throw new u(`Invalid grain \'${n}\'. Expected one of: ${De.join(", ")}.`,t)}o(xt,"assertGrain");function Re(t,n){return n?(xt(t,n),{operator:"transform_date_drill",values:[`datetrunc ${n}`]}):{operator:"none"}}o(Re,"drillCondition");function kt(t){let n=t.toLowerCase();return n.includes("date")||n.includes("time")?"date":n.includes("int")||n.includes("number")||n.includes("float")||n.includes("decimal")?"number":n.includes("bool")?"boolean":"string"}o(kt,"inferType");function Et(t,n){return JSON.stringify(t??null)===JSON.stringify(n??null)}o(Et,"sameCondition");var ee=class ee extends ${constructor(e,r,i){super(r);c(this,"name");c(this,"app");c(this,"pending");c(this,"applied");c(this,"initial");this.name=e,this.app=r,this.initial=i,this.pending=i}locate(){return this.app.locate("control",this.name)}get condition(){return this.pending}get appliedCondition(){return this.applied}get isDirty(){return this.applied!==void 0&&!Et(this.pending,this.applied)}setCondition(e){this.pending=e,this.notify()}reset(){this.setCondition(this.initial)}commit(){this.applied=this.pending}};o(ee,"Control");var O=ee,te=class te extends O{constructor(e,r,i,s,l){super(e,r,i.default??{operator:"is",values:[]});c(this,"kind","filter");c(this,"declaration");c(this,"type");c(this,"resolved");c(this,"datasetName");c(this,"backend");c(this,"loadedOptions");if(this.declaration=i,this.backend=l,i.field){if(!s)throw new u(`Filter \'${e}\' names a field but no dataset. Pass \\`dataset\\` alongside \\`field\\`.`,e);this.resolved=s.resolve(i.field,e),this.datasetName=s.descriptor.name,this.type=i.type??kt(this.resolved.type)}else{if(!i.type)throw new u(`Filter \'${e}\' is a manual filter, so it needs a \\`type\\`.`,e);this.type=i.type}this.assertValues(this.condition.values??[]),this.assertValues(i.options??[])}setCondition(e){this.assertValues(e.values??[]),super.setCondition(e)}assertValues(e){if(this.type!=="number")return;let r=e.find(i=>typeof i=="number");if(r!==void 0)throw new u(`Filter \'${this.name}\' filters numbers: give its values as strings, as query results give them (${JSON.stringify(String(r))}, not ${String(r)}), so none has lost a digit.`,this.name)}get isFieldBacked(){return this.resolved!==void 0}get options(){return this.loadedOptions??this.declaration.options??[]}async loadOptions(e,r=new AbortController().signal){let i=this.resolved?.modelName;if(!this.resolved||!i||!this.backend||!this.datasetName)return this.options;let s=await this.backend.fieldSuggestions({dataset:this.datasetName,model:i,field:this.resolved.fieldName,q:e??""},r);return this.loadedOptions=[...s??[]],this.notify(),this.loadedOptions}toJSON(){return this.declaration}};o(te,"Filter");var P=te,ne=class ne extends O{constructor(e,r,i={}){super(e,r,Re(e,i.default));c(this,"kind","dateDrill");c(this,"declaration");this.declaration=i}setGrain(e){this.setCondition(Re(this.name,e))}toJSON(){return this.declaration}};o(ne,"DateDrillControl");var z=ne;var v={container:"data-anfra-container",block:"data-anfra-block",query:"data-anfra-query",control:"data-anfra-control",label:"data-anfra-label"},_e=`[${v.container}],[${v.block}],[${v.query}],[${v.control}]`;function $e(t){let n=/^(?:(\\d+)\\/)?([^/\\s]+)$/.exec(t);if(n)return{app:n[1]===void 0?0:Number(n[1]),name:n[2]}}o($e,"parseRef");var Oe=o(t=>(t??"").split(/\\s+/).filter(Boolean),"tokens");function Te(t,n,e,r){let i=n==="query"?v.query:v.control;return[...t.querySelectorAll(`[${i}]`)].filter(s=>Oe(s.getAttribute(i)).some(l=>{let a=$e(l);return a?.app===e&&a.name===r}))}o(Te,"markersFor");var vt=o((t,n,e)=>{let r=t[e.app];return r?Object.prototype.hasOwnProperty.call(n==="query"?r.queries:r.controls,e.name):!1},"hasEntity");function Fe(t,n){var x;let e=[],r=new Map,i=new Map,s=new Map,l=new Map,a={container:new Set,block:new Set},d={},p=o((h,E,m)=>{let y=h?s.get(h).children:e,f=h?`${s.get(h).key}.`:"",b={...E,key:`${f}${y.length}`,children:[]};return y.push(b),r.set(b.key,m),i.set(m,[...i.get(m)??[],b.key]),b},"place");for(let h of t.querySelectorAll(_e)){let E=h.parentElement?.closest(_e)??null,m=h.getAttribute(v.container),y=h.getAttribute(v.block),f=h.getAttribute(v.label)??void 0,b=E&&(l.get(E)==="block"?E:E.closest(`[${v.block}]`)),_;if(m!==null||y!==null){let k=m!==null?"container":"block",A=(m??y??"").trim(),w=[];m!==null&&y!==null&&w.push("This element is marked as a container and as a block. It counts as a container."),A?a[k].has(A)?w.push(`Another ${k} already has the id "${A}".`):a[k].add(A):w.push(`This ${k} has no id.`),b&&w.push(`A block can\'t hold a ${k}. This one is inside the block "${b.getAttribute(v.block)}".`),_=p(E,{kind:k,id:A,...f!==void 0?{label:f}:{},problems:w},h),s.set(h,_),l.set(h,k)}let M=_?h:E;for(let k of["query","control"])for(let A of Oe(h.getAttribute(k==="query"?v.query:v.control))){let w=$e(A),L=[];if(w?vt(n,k,w)||L.push(n[w.app]?`No ${k} is called "${w.name}" in app ${w.app}.`:`The page has no app ${w.app}.`):L.push(`Can\'t read "${A}". Write the ${k}\'s name, or app/name when the page has several apps.`),p(M,{kind:k,name:w?.name??A,app:w?.app??0,problems:L},h),w&&!L.length){let lt=`${w.app}/${w.name}`,Ee=d[x=`${k}:${lt}`]??(d[x]={elements:new Set,blocks:new Set});Ee.elements.add(h);let ve=_?.kind==="block"?_.id:b?.getAttribute(v.block);ve&&Ee.blocks.add(ve)}}}let g=Object.fromEntries(Object.entries(d).map(([h,E])=>[h,{markers:E.elements.size,blocks:[...E.blocks]}]));return{nodes:e,usage:g,elements:r,keysOf:i}}o(Fe,"buildStructure");var Me="data-anfra-layer",St="position:absolute;top:0;left:0;width:0;height:0;overflow:visible;z-index:2147483647;";function Ct(t){let n=t.querySelector(`[${Me}]`);if(n instanceof(t.defaultView?.HTMLElement??HTMLElement))return n;let e=t.createElement("div");return e.setAttribute(Me,""),e.setAttribute("style",St),(t.body??t.documentElement).appendChild(e),e}o(Ct,"layerOf");function Q(t,n){let e=Ct(t),r=[...e.children].find(s=>s.getAttribute("data-part")===n);if(r?.shadowRoot)return r.shadowRoot;let i=t.createElement("div");return i.setAttribute("data-part",n),e.appendChild(i),i.attachShadow({mode:"open"})}o(Q,"layerRoot");var Ne="anfra-overlay",At=1500,Dt="position:fixed;box-sizing:border-box;background:rgba(37,99,235,0.22);outline:1px solid #2563eb;outline-offset:-1px;",Rt="position:fixed;max-width:60vw;display:flex;gap:6px;align-items:baseline;padding:3px 8px;border-radius:4px;background:#0f172a;color:#f8fafc;font:12px/1.4 system-ui,sans-serif;white-space:nowrap;box-shadow:0 2px 8px rgba(0,0,0,0.35);",_t={kind:"color:#94a3b8;",name:"color:#93c5fd;font-weight:700;",label:"color:#f8fafc;",note:"color:#94a3b8;",size:"color:#94a3b8;margin-left:10px;"},ie=class ie{constructor(n){c(this,"doc",n);c(this,"root");c(this,"shown",[]);c(this,"text",{kind:"",name:""});c(this,"timer");c(this,"reposition",o(()=>this.draw(),"reposition"));let e=Q(n,"anfra"),r=e.getElementById(Ne);r instanceof(n.defaultView?.HTMLElement??HTMLElement)?this.root=r:(this.root=n.createElement("div"),this.root.id=Ne,this.root.setAttribute("aria-hidden","true"),this.root.setAttribute("style","position:fixed;inset:0;z-index:2147483647;pointer-events:none;display:none;"),e.appendChild(this.root))}show(n,e){if(this.clearTimer(),this.root.isConnected||Q(this.doc,"anfra").appendChild(this.root),this.shown=[...n],this.text=e,!this.shown.length){this.hide();return}this.root.style.display="block",this.draw(),this.doc.addEventListener("scroll",this.reposition,{capture:!0,passive:!0}),this.doc.defaultView?.addEventListener("resize",this.reposition)}flash(n,e,r=At){this.show(n,e),this.timer=setTimeout(()=>this.hide(),r)}hide(){this.clearTimer(),this.shown=[],this.root.style.display="none",this.root.replaceChildren(),this.doc.removeEventListener("scroll",this.reposition,{capture:!0}),this.doc.defaultView?.removeEventListener("resize",this.reposition)}get visible(){return this.shown.length>0}clearTimer(){this.timer!==void 0&&clearTimeout(this.timer),this.timer=void 0}draw(){let n=this.shown.map(a=>{let d=a.getBoundingClientRect(),p=this.doc.createElement("div");return p.setAttribute("style",`${Dt}left:${d.left}px;top:${d.top}px;width:${d.width}px;height:${d.height}px;`),p}),e=this.shown[0].getBoundingClientRect(),r=this.doc.createElement("div");r.setAttribute("data-testid","anfra-overlay-label");let i=this.doc.defaultView?.innerHeight??0,s=e.top>=26?e.top-24:Math.max(4,e.top+4),l=Math.max(4,Math.min(e.left,(this.doc.defaultView?.innerWidth??0)-24));r.setAttribute("style",`${Rt}left:${l}px;top:${Math.min(s,i-24)}px;`);for(let a of["kind","name","label","note","size"]){let d=this.text[a];if(!d)continue;let p=this.doc.createElement("span");p.setAttribute("style",_t[a]),p.setAttribute("data-part",a),p.textContent=d,r.appendChild(p)}this.root.replaceChildren(...n,r)}};o(ie,"Overlay");var re=ie,Qe=new WeakMap;function V(t){let n=Qe.get(t);return n||(n=new re(t),Qe.set(t,n)),n}o(V,"overlayFor");function Ie(t){typeof t.scrollIntoView=="function"&&t.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}o(Ie,"scrollTo");function oe(t,n,e,r,i){if(r in n||t.has(r))throw new u(`Plugin \'${r}\' can\'t add \'${r}\' to a ${e}: it already has one.`);t.set(r,i)}o(oe,"addExtension");function j(t,n){return n?.forEach((e,r)=>{let i=!1,s;Object.defineProperty(t,r,{configurable:!0,enumerable:!1,get(){return i||(s=e(t),i=!0),s}})}),t}o(j,"applyExtensions");var $t="anfra.body",se="__anfraBodyExports",Ot={DataAppError:S,ValidationError:u,QueryError:D,PermissionError:R,TransportError:C};function Tt(t,n){let e=t,r=t.document.createElement("script");r.textContent=`(function () { var __anfraBody;\n${n}\n;self[${JSON.stringify(se)}] = __anfraBody; })();`,(t.document.head??t.document.documentElement).appendChild(r),r.remove();let i=e[se];if(delete e[se],!i)throw new u("The host sent a plugin body that did not run.");return i.default??i}o(Tt,"runBody");function Be(t,n,e){let{window:r,sdk:i,endpoint:s}=n,l;return{plugin:t,window:r,sdk:i,errors:Ot,get overlay(){return V(r.document)},structure:o(()=>Fe(r.document,i.apps),"structure"),call:o((a,d,p)=>s.call(a,d??null,p),"call"),emit:o((a,d)=>s.emit(`${t}.${a}`,d??null),"emit"),handle(a,d){n.handlers.set(`${t}.${a}`,d)},on(a,d){let p=`${t}.${a}`;n.listeners.has(p)||n.listeners.set(p,new Set),n.listeners.get(p).add(d)},onApp(a){n.appListeners.add(a),i.apps.forEach(d=>a(d))},provide(a){if(t in i)throw new u(`Plugin \'${t}\' can\'t add a member Anfra already has.`);Object.defineProperty(i,t,{value:a,enumerable:!0})},provideOnQuery:o(a=>oe(i.extensions.query,e.Query.prototype,"query",t,a),"provideOnQuery"),provideOnControl:o(a=>oe(i.extensions.control,e.Control.prototype,"control",t,a),"provideOnControl"),layer:o(()=>Q(r.document,t),"layer"),body(){return l??(l=s.call($t,{plugin:t}).then(a=>Tt(r,a)).catch(a=>{throw l=void 0,a})),l}}}o(Be,"createKernel");var ae=class ae extends ${constructor(e,r,i){super(r);c(this,"kind","query");c(this,"name");c(this,"declaration");c(this,"dataset");c(this,"app");c(this,"_state","idle");c(this,"_result");c(this,"_error");c(this,"_page",1);c(this,"_sort",[]);c(this,"lastRunSignature");c(this,"lastPageRows",0);c(this,"controller");if(!i.aql?.trim())throw new u(`Query \'${e}\' declares no AQL.`,e);let{pageSize:s}=i;if(s!==void 0&&!(Number.isInteger(s)&&s>=1))throw new u(`Query \'${e}\' declares pageSize ${s}; it must be a whole number of at least 1.`,e);this.name=e,this.app=r,this.declaration=i,this.dataset=r.datasetIndex(i.dataset,e)}locate(){return this.app.locate("query",this.name)}get state(){return this._state}get result(){return this._result}get error(){return this._error}get pageSize(){return this.declaration.pageSize}get page(){return this._page}get sort(){return this._sort}setSort(e){this._sort=[...e],this.notify()}get hasMore(){return!this._result||this.pageSize===void 0?!1:this._result.meta.hasMore??this.lastPageRows>=this.pageSize}signature(){let e=this.app.mappingsTo(this.name).map(r=>({field:r.field,aggregation:r.aggregation,condition:r.from.condition})).sort((r,i)=>r.field.localeCompare(i.field)||JSON.stringify(r).localeCompare(JSON.stringify(i)));return JSON.stringify({declaration:this.declaration,conditions:e,selection:this.app.selectionConditionsFor(this.name,"pending"),selectionExpression:this.app.selectionExpressionFor(this.name,"pending"),sort:this._sort,timezone:this.app.timezone,page:this._page})}get isDirty(){return this.lastRunSignature!==void 0&&this.signature()!==this.lastRunSignature}shouldRun(e=!1){return e||this.lastRunSignature===void 0||this.isDirty}abort(){this.controller?.abort()}async fetchMore(){if(this.pageSize===void 0)throw new u(`Query \'${this.name}\' declares no pageSize, so it has no more pages.`,this.name);this.hasMore&&(this._page+=1,await this.app.fetchPage(this))}select(e,r={}){this.app.select(this,Array.isArray(e)?e:[e],r.fields)}get selectedRows(){let{selection:e}=this.app;if(e?.source!==this.name)return[];let r=this._result?.rows;if(!r)return e.rows;let i=o(l=>JSON.stringify(e.fields.map(a=>l[a]??null)),"key"),s=new Set(e.rows.map(i));return r.filter(l=>s.has(i(l)))}markExecuting(){this._state="executing",this._error=void 0,this.notify()}markSuccess(e,r,i){if(this._state="success",this._error=void 0,this.lastRunSignature=r,this.lastPageRows=e.rows.length,i&&this._result){let s=[...this._result.rows,...e.rows];this._result={...e,rows:s,meta:{...e.meta,numRows:s.length}}}else this._result=e;this.notify()}markError(e){this._state="error",this._error=e,this.notify()}rewindPage(){this._page>1&&(this._page-=1)}resetPage(){this._page=1,this.lastPageRows=0}toJSON(){return this.declaration}};o(ae,"Query");var T=ae;var le=class le{constructor(n,e,r,i){c(this,"kind","control");c(this,"from");c(this,"to");c(this,"field");c(this,"aggregation");this.from=n,this.to=e,this.field=r,this.aggregation=i}get id(){return`${this.from.name}.${this.to.name}.${this.field}`}toJSON(){return{kind:this.kind,id:this.id,from:{kind:this.from.kind,name:this.from.name},to:{kind:"query",name:this.to.name},field:this.field,...this.aggregation?{aggregation:this.aggregation}:{}}}};o(le,"Mapping");var J=le,de=class de{constructor(n,e){c(this,"kind","crossFilter");c(this,"from");c(this,"to");this.from=n,this.to=e}get id(){return`${this.from.name}.${this.to.name}`}toJSON(){return{kind:this.kind,id:this.id,from:{kind:"query",name:this.from.name},to:{kind:"query",name:this.to.name}}}};o(de,"CrossFilter");var q=de;var ce=["sum","avg","max","min","count","count distinct","median","stdev","stdevp","var","varp"];function Ft(t,n){let e=t.length+1,r=n.length+1,i=Array.from({length:r},(s,l)=>l);for(let s=1;s<e;s++){let l=[s];for(let a=1;a<r;a++)l[a]=Math.min(i[a]+1,l[a-1]+1,i[a-1]+(t[s-1]===n[a-1]?0:1));i=l}return i[r-1]}o(Ft,"editDistance");function Mt(t,n){let e,r=1/0;n.forEach(s=>{let l=Ft(t.toLowerCase(),s.toLowerCase());l<r&&(r=l,e=s)});let i=Math.max(2,Math.floor(t.length/3));return r<=i?e:void 0}o(Mt,"suggest");function F(t,n,e){let r=Mt(n,e);return r?`${t} Did you mean \'${r}\'?`:t}o(F,"withSuggestion");var pe=class pe{constructor(n){c(this,"descriptor");c(this,"fields",new Map);c(this,"references");this.descriptor=n,n.data_models.forEach(e=>{e.fields.forEach(r=>{let i=String(e.name);this.fields.set(`${i}.${r.name}`,{modelName:i,fieldName:r.name,isMetric:!1,type:r.type,label:r.label??r.name})})}),n.metrics.forEach(e=>{this.fields.set(e.name,{fieldName:e.name,isMetric:!0,type:e.type,label:e.label??e.name})}),this.references=[...this.fields.keys()]}resolve(n,e){let r=this.fields.get(n);if(r)return r;throw new u(F(`Unknown field \'${n}\' on dataset \'${this.descriptor.name}\'.`,n,this.references),e)}};o(pe,"DatasetIndex");var G=pe;function Le(t,n,e){let r=t[n];if(r)return r;throw new u(F(`Unknown dataset \'${n}\'.`,n,Object.keys(t)),e)}o(Le,"resolveDataset");function Pe(t,n){if(!ce.includes(t))throw new u(F(`Invalid filter aggregation \'${t}\'.`,t,[...ce]),n)}o(Pe,"assertValidFilterAggregation");function ze(t,n,e){if(!n)throw new u(`A ${e} needs a name.`);for(let r of t)if(r===n)throw new u(`\'${n}\' is already declared in this app.`,n)}o(ze,"assertUniqueName");function Nt(t,n){if(!(!n||n.operator==="none"||n.operator==="transform_date_drill"||!["is_null","not_null","is_true","is_false","transform_pop_none"].includes(n.operator)&&!n.values?.length))return{field:t.field,operator:n.operator,values:n.values??[],...n.modifier?{modifier:n.modifier}:{},...t.aggregation?{aggregation:t.aggregation}:{}}}o(Nt,"toFilter");function Qt(t,n){if(n?.operator!=="transform_date_drill")return;let e=n.values?.[0];if(typeof e!="string")return;let r=e.replace(/^datetrunc\\s+/,"");return{field:t.field,grain:r}}o(Qt,"toDateDrill");function It(t,n){let e=n.columns??[],r=(n.values??[]).map(s=>{let l={};return e.forEach((a,d)=>{l[a.name]=s[d]}),l}),{pageSize:i}=t;return{columns:e,rows:r,meta:{...i!==void 0?{page:n.meta?.page??t.page,pageSize:n.meta?.pageSize??i,...n.meta?.hasMore!==void 0?{hasMore:n.meta.hasMore}:{}}:{},numRows:n.meta?.numRows??r.length},...n.debug?{debug:n.debug}:{}}}o(It,"toResult");function Ve(t,n,e,r){let i=n.map(d=>Nt(d,d.from.appliedCondition)).filter(d=>d!==void 0),s=n.map(d=>Qt(d,d.from.appliedCondition)).filter(d=>d!==void 0),l=e.conditions.map(d=>({field:d.field,operator:d.operator,values:d.values})),a=e.expression?[{expr:e.expression}]:[];return{dataset:t.dataset.descriptor.name,aql:t.declaration.aql,input:{filters:[...i,...l],conditions:a,sorts:t.sort.map(d=>({field:d.field,direction:d.direction??"asc"})),dateDrills:s},...r.timezone?{timezone:r.timezone}:{}}}o(Ve,"buildQuery");function Bt(t,n,e,r){return{...Ve(t,n,e,r),...t.pageSize!==void 0?{page:t.page,pageSize:t.pageSize}:{},...r.bustCache?{bustCache:!0}:{}}}o(Bt,"buildRequest");function Lt(t,n){let e=n?.replace(/[/\\\\]/g,"-").replace(/\\p{Cc}/gu,"").trim();return e?`${e} - ${t.name}`:t.name}o(Lt,"defaultExportFilename");function je(t,n,e,r,i){let s=i.format??"csv",l=s==="csv"?{bom:!0,...i.formatOptions}:i.formatOptions;return{...Ve(t,n,e,r),format:s,...l?{formatOptions:l}:{},filename:i.filename?.trim()||Lt(t,r.title)}}o(je,"buildExportRequest");async function ue(t,n,e,r,i){let s=Bt(t,n,e,r),l=await r.backend.submitQuery(s,i);return It(t,l)}o(ue,"runQuery");function Pt(t,n){if(t===null)return"null";if(typeof t=="boolean")return t?"true":"false";if(n==="number"&&typeof t=="string")return jt(t);if(typeof t=="number"){if(!Number.isFinite(t))throw new RangeError(`Cannot express ${t} in AQL.`);return Math.abs(t)>=1e21?BigInt(t).toString():String(t)}return JSON.stringify(t).split("\\u2028").join("\\\\u2028").split("\\u2029").join("\\\\u2029")}o(Pt,"literal");function Je(t,n,e){return n===null?`is(${t}, null)`:`${t} is ${Pt(n,e)}`}o(Je,"equals");var zt=new Set(["NaN","Infinity","-Infinity"]),Vt=/^(-?)(0|[1-9]\\d*)(?:\\.(\\d+))?(?:[eE]([+-]?\\d+))?$/;function jt(t){let n=Vt.exec(t);if(!n)throw zt.has(t)?new RangeError(`Cannot express ${t} in AQL.`):new TypeError(`${JSON.stringify(t)} is not a number: a number is a string in JSON\'s number syntax.`);let[,e,r,i="",s]=n;if(s===void 0)return t;let l=r+i,a=r.length+Number(s),d;return a<=0?d=`0.${"0".repeat(-a)}${l}`:a>=l.length?d=l+"0".repeat(a-l.length):d=`${l.slice(0,a)}.${l.slice(a)}`,e+d.replace(/^0+(?=\\d)/,"")}o(jt,"numberLiteral");function qe(t,n,e){return`${t} matches @(${n} until ${e})`}o(qe,"dateRange");function Ge(t,n){if(n.length===0)throw new RangeError(`\\`${t}\\` needs at least one operand.`);return n.length===1?n[0]:`${t}(${n.join(", ")})`}o(Ge,"combine");var Ke=o(t=>Ge("and",t),"and"),Ue=o(t=>Ge("or",t),"or");var Jt=/^(\\d{4})-(\\d{2})-(\\d{2})(?:[T ](\\d{2}):(\\d{2})(?::(\\d{2}))?)?/,qt={week:7*864e5,day:864e5,hour:36e5,minute:6e4};function He(t){if(typeof t!="string")return;let n=Jt.exec(t);if(n)return{year:Number(n[1]),month:Number(n[2])-1,day:Number(n[3]),hour:Number(n[4]??0),minute:Number(n[5]??0),second:Number(n[6]??0),hasTime:n[4]!==void 0}}o(He,"parseStamp");function I(t,n){let e=new Date(t),r=o(s=>String(s).padStart(2,"0"),"pad"),i=`${e.getUTCFullYear()}-${r(e.getUTCMonth()+1)}-${r(e.getUTCDate())}`;return n?`${i} ${r(e.getUTCHours())}:${r(e.getUTCMinutes())}:${r(e.getUTCSeconds())}`:i}o(I,"format");function Ye(t){return Date.UTC(t.year,t.month,t.day,t.hour,t.minute,t.second)}o(Ye,"toMs");function fe(t){let n=He(t);if(n)return I(Ye(n),n.hasTime)}o(fe,"normalise");function me(t,n){let e=He(t);if(!e)return;let{year:r,month:i,day:s,hour:l,minute:a,second:d,hasTime:p}=e;return I(n==="year"?Date.UTC(r+1,i,s,l,a,d):n==="quarter"?Date.UTC(r,i+3,s,l,a,d):n==="month"?Date.UTC(r,i+1,s,l,a,d):Ye(e)+qt[n],p)}o(me,"addGrain");function We(t){if(t?.startsWith("datetrunc "))return t.slice(10)}o(We,"grainOf");function Gt(t){let n=new Set;return t.filter(e=>{let r=`${typeof e}:${String(e)}`;return n.has(r)?!1:(n.add(r),!0)})}o(Gt,"distinct");function Kt(t,n){let e=t.map(fe);if(e.some(i=>i===void 0))return!1;let r=e.slice().sort();for(let i=1;i<r.length;i+=1)if(me(r[i-1],n)!==r[i])return!1;return!0}o(Kt,"isContiguous");function Ut(t,n,e){let r=n.map(fe);if(r.some(d=>d===void 0))return;let i=r.slice().sort(),s=i[0],l=me(i[i.length-1],e);if(!l)return;let a=Kt(n,e);return{condition:{field:t,operator:"matches",values:[`${s} until ${l}`]},admits:a?n.length:Number.POSITIVE_INFINITY,lossy:!a}}o(Ut,"dateRange");function Ht(t,n,e){let r=e.filter(a=>a!=null),i=Gt(r);if(!i.length)return{condition:{field:t,operator:"is_null",values:[]},admits:1,lossy:!1};let s=r.length!==e.length,l=We(n);if(l){let a=Ut(t,i,l);if(a)return{...a,lossy:a.lossy||s}}return{condition:{field:t,operator:"is",values:i},admits:i.length,lossy:s}}o(Ht,"deriveOne");function Xe(t){return t.modelId?`${t.modelId}.${t.fieldName}`:t.fieldName}o(Xe,"fieldReferenceOf");function Yt(t,n,e,r){try{let i=e.map(s=>Ke(n.map(l=>{let a=t.get(l),d=Xe(a),p=s[l]??null,g=We(r[d]);if(g&&typeof p=="string"){let x=fe(p),h=me(p,g);if(x&&h)return qe(d,x,h)}if(p!==null&&typeof p!="string"&&typeof p!="number"&&typeof p!="boolean")throw new TypeError("no AQL spelling");return Je(d,p,a.semantic_type)})));return Ue(i)}catch{return}}o(Yt,"selectionExpression");function Ze(t,n,e,r={}){let i=t.result?.columns??[],s=new Map(i.map(f=>[f.name,f]));e?.forEach(f=>{let b=s.get(f);if(b){if(b.adhoc)throw new u(`Query \'${t.name}\' cannot cross-filter on \'${f}\': it is a query-local AQL expression, which only this query\'s result carries. The target query would receive a condition naming a field it has never heard of.`,t.name);if(b.isMeasure)throw new u(`Query \'${t.name}\' cannot cross-filter on \'${f}\': it is a measure, and a selection conditions dimensions only.`,t.name);return}throw new u(F(`Query \'${t.name}\' has no column \'${f}\' in its last result.`,f,[...s.keys()]),t.name)});let l=i.filter(f=>!f.isMeasure),a=l.filter(f=>!f.adhoc).map(f=>f.name),d=e?[...e]:a;if(!n.length||!d.length)return;let p=[],g=1,x=!e&&a.length!==l.length,h=!1;d.forEach(f=>{let b=s.get(f),_=Xe(b),M=Ht(_,r[_],n.map(k=>k[f]));p.push(M.condition),g*=M.admits,h=h||M.lossy});let E=new Set(n.map(f=>JSON.stringify(d.map(b=>f[b]??null))));g>E.size&&(h=!0);let m=p.sort((f,b)=>f.field.localeCompare(b.field)),y={source:t.name,rows:[...n],fields:d};if(h){let f=Yt(s,d,n,r);if(f)return{...y,conditions:[],expression:f,lossy:x}}return{...y,conditions:m,lossy:x||h}}o(Ze,"deriveSelection");var he=Object.freeze([]);function ge(t){return t instanceof Error&&t.name==="AbortError"}o(ge,"isAbort");function et(t,n){return t.controller!==n}o(et,"superseded");function Wt(t){return{name:t.name,message:t.message,...t.entity?{entity:t.entity}:{},...typeof t.status=="number"?{status:t.status}:{},...t.stack?{stack:t.stack}:{}}}o(Wt,"inspectError");function Xt(t){let{result:n}=t;return{state:t.state,isDirty:t.isDirty,page:t.page,hasMore:t.hasMore,columns:n?n.columns.map(e=>({...e})):[],rowCount:n?.meta.numRows??0,selectedRowCount:t.selectedRows.length,signature:t.signature(),...t.error?{error:Wt(t.error)}:{},...n?.debug?{debug:{...n.debug}}:{}}}o(Xt,"inspectQuery");function Zt(t){let{options:n}=t;return{kind:t.kind,condition:{...t.condition},...t.appliedCondition?{appliedCondition:{...t.appliedCondition}}:{},isDirty:t.isDirty,...n?{options:[...n]}:{}}}o(Zt,"inspectControl");function tt(t){return{source:t.source,fields:[...t.fields],rowCount:t.rows.length,conditions:t.conditions.map(n=>({...n})),...t.expression?{expression:t.expression}:{},lossy:t.lossy}}o(tt,"inspectSelection");function nt(t){return t?JSON.stringify({source:t.source,conditions:t.conditions,expression:t.expression}):"none"}o(nt,"selectionKey");function rt(t,n){return t instanceof S?t:new D(t?.message??"The query failed.",n,t)}o(rt,"toDataAppError");function en(t,n){if(t instanceof S&&t.entity)return t;let e=t?.message||"The export failed.";return t instanceof R?new R(e,n):t instanceof C?new C(e,t.status,n):t instanceof u?new u(e,n):new D(e,n,t)}o(en,"toExportError");var ye=class ye extends ${constructor(e,r,i,s,l){super();c(this,"extensions",l);c(this,"title");c(this,"_timezone");c(this,"datasets");c(this,"backend");c(this,"features");c(this,"_queries",new Map);c(this,"_controls",new Map);c(this,"_mappings",[]);c(this,"_crossFilters",[]);c(this,"_selection");c(this,"_appliedSelection");c(this,"selectionCommitted",!1);c(this,"index",0);this.title=e.title,this._timezone=e.timezone,this.datasets=r,this.backend=i,this.features=s}get queries(){return Object.fromEntries(this._queries)}get controls(){return Object.fromEntries(this._controls)}get mappings(){return[...this._mappings,...this._crossFilters]}get crossFilters(){return this._crossFilters}createQuery(e,r){this.assertNameFree(e,"query");let i=j(new T(e,this,r),this.extensions?.query);return this._queries.set(e,i),this.notify(),i}createFilter(e,r){this.assertNameFree(e,"filter");let i=r.dataset?this.datasetIndex(r.dataset,e):this.soleDataset(e,r.field),s=j(new P(e,this,r,i,this.backend),this.extensions?.control);return this._controls.set(e,s),this.notify(),s}createDateDrill(e,r={}){if(this.features?.dateDrill===!1)throw new u(`Date drill \'${e}\' needs a capability this workspace has not enabled. Ask an admin to turn on \\`interactive_control:date_drill\\`.`,e);this.assertNameFree(e,"date drill control");let i=j(new z(e,this,r),this.extensions?.control);return this._controls.set(e,i),this.notify(),i}mapControl(e,r,i){if(!(e instanceof O))throw new u("mapControl expects a control as its source. To let one query cross-filter another, use app.mapCrossFilter(from, to) \\u2014 a cross-filter edge names no field.");if(this._controls.get(e.name)!==e)throw new u(`Control \'${e.name}\' belongs to a different app.`,e.name);if(this._queries.get(r.name)!==r)throw new u(`Query \'${r.name}\' belongs to a different app.`,r.name);i.aggregation&&Pe(i.aggregation,e.name);let s=new J(e,r,i.field,i.aggregation);if(this._mappings.some(l=>l.id===s.id))throw new u(`Mapping \'${s.id}\' is already declared.`,e.name);return this.assertAcyclic(s),this._mappings.push(s),this.notify(),s}mapCrossFilter(e,r){if(!(e instanceof T)||!(r instanceof T))throw new u("mapCrossFilter expects two queries. To let a control condition a query, use app.mapControl(from, to, { field }).");if(this._queries.get(e.name)!==e)throw new u(`Query \'${e.name}\' belongs to a different app.`,e.name);if(this._queries.get(r.name)!==r)throw new u(`Query \'${r.name}\' belongs to a different app.`,r.name);if(e===r)throw new u(`Query \'${e.name}\' cannot cross-filter itself. A source keeps its own rows so it can show what is selected; filtering it would erase the very rows the reader clicked.`,e.name);if(e.declaration.dataset!==r.declaration.dataset)throw new u(`Cross-filter \'${e.name}\' -> \'${r.name}\' spans two datasets (\'${e.declaration.dataset}\' and \'${r.declaration.dataset}\'). A selection carries field references, which mean nothing outside the dataset that resolved them.`,e.name);let i=new q(e,r);if(this._crossFilters.some(s=>s.id===i.id))throw new u(`Cross-filter \'${i.id}\' is already declared.`,e.name);return this._crossFilters.push(i),this.notify(),i}get selection(){return this._selection}get appliedSelection(){return this._appliedSelection}clearSelection(){this._selection&&(this._selection=void 0,this.notify())}setTimezone(e){this._timezone=e,this.notify()}get timezone(){return this._timezone}datasetIndex(e,r){return Le(this.datasets,e,r)}mappingsTo(e){return this._mappings.filter(r=>r.to.name===e)}selectionExpressionFor(e,r){return this.selectionFor(e,r)?.expression}selectionFor(e,r){let i=r==="pending"?this._selection:this._appliedSelection;return!i||i.source===e?void 0:this._crossFilters.some(l=>l.from.name===i.source&&l.to.name===e)?i:void 0}selectionConditionsFor(e,r){let i=r==="pending"?this._selection:this._appliedSelection;return!i||i.source===e?he:this._crossFilters.some(l=>l.from.name===i.source&&l.to.name===e)?i.conditions:he}drillTransformations(e){let r={};return this._mappings.forEach(i=>{if(i.to!==e)return;let s=i.from.appliedCondition;if(s?.operator!=="transform_date_drill")return;let[l]=s.values??[];typeof l=="string"&&(r[i.field]=l)}),r}select(e,r,i){if(this._queries.get(e.name)!==e)throw new u(`Query \'${e.name}\' belongs to a different app.`,e.name);let s=Ze(e,r,i,this.drillTransformations(e));s?.lossy&&console.warn(`[anfra-sdk] The selection in \'${e.name}\' filters more broadly than it was made. Its conditions are combined field by field and ANDed, which cannot express "(A and B) or (C and D)", so the targets will also show combinations that were not selected. Select within one dimension, or narrow with \\`fields\\`, to avoid this.`),this._selection=s,this.notify()}get hasChanges(){return[...this._controls.values()].some(e=>e.isDirty)||this.isSelectionDirty}get isSelectionDirty(){return this.selectionCommitted?nt(this._selection)!==nt(this._appliedSelection):!1}async execute(e={}){let r=[...this._queries.values()].filter(a=>a.shouldRun(e.force));this._controls.forEach(a=>a.commit()),this._appliedSelection=this._selection,this.selectionCommitted=!0,r.forEach(a=>{a.controller?.abort(),a.resetPage()});let i={backend:this.backend,timezone:this._timezone,bustCache:e.bustCache},s=[],l=[];return await Promise.all(r.map(async a=>{let d=new AbortController;a.controller=d;let p=a.signature();a.markExecuting();try{let g=await ue(a,this.mappingsTo(a.name),{conditions:this.selectionConditionsFor(a.name,"applied"),expression:this.selectionExpressionFor(a.name,"applied")},i,d.signal);if(et(a,d))return;a.markSuccess(g,p,!1),s.push(a.name)}catch(g){if(et(a,d)||ge(g))return;a.markError(rt(g,a.name)),l.push(a.name)}finally{a.controller===d&&(a.controller=void 0)}})),{succeeded:s,failed:l}}async refresh(){return this.execute({force:!0,bustCache:!0})}abort(){this._queries.forEach(e=>e.abort())}async fetchPage(e){let r=new AbortController;e.controller=r;let i=e.signature();e.markExecuting();try{let s=await ue(e,this.mappingsTo(e.name),{conditions:this.selectionConditionsFor(e.name,"applied"),expression:this.selectionExpressionFor(e.name,"applied")},{backend:this.backend,timezone:this._timezone},r.signal);e.markSuccess(s,i,!0)}catch(s){if(e.rewindPage(),ge(s))return;let l=rt(s,e.name);throw e.markError(l),l}finally{e.controller===r&&(e.controller=void 0)}}async exportQuery(e,r,i){let s=je(e,this.mappingsTo(e.name),{conditions:this.selectionConditionsFor(e.name,"applied"),expression:this.selectionExpressionFor(e.name,"applied")},{backend:this.backend,timezone:this._timezone,title:this.title},r);try{return await i(s,r.signal??new AbortController().signal)}catch(l){throw ge(l)?l:en(l,e.name)}}toJSON(){let e=o(r=>Object.fromEntries([...this._controls.entries()].filter(([,i])=>i.kind===r).map(([i,s])=>[i,s.toJSON()])),"byKind");return{...this.title?{title:this.title}:{},...this._timezone?{timezone:this._timezone}:{},queries:Object.fromEntries([...this._queries.entries()].map(([r,i])=>[r,i.toJSON()])),filters:e("filter"),dateDrills:e("dateDrill"),mappings:[...this._mappings.map(r=>r.toJSON()),...this._crossFilters.map(r=>r.toJSON())]}}toInspectJSON(){return{...this.title?{title:this.title}:{},...this._timezone?{timezone:this._timezone}:{},hasChanges:this.hasChanges,declaration:this.toJSON(),queries:Object.fromEntries([...this._queries.entries()].map(([e,r])=>[e,Xt(r)])),controls:Object.fromEntries([...this._controls.entries()].map(([e,r])=>[e,Zt(r)])),...this._selection?{selection:tt(this._selection)}:{},...this._appliedSelection?{appliedSelection:tt(this._appliedSelection)}:{}}}locate(e,r){let i=globalThis.document;if(!i)return!1;let s=Te(i,e,this.index,r);return s.length?(Ie(s[0]),V(i).flash(s,{kind:e,name:r,...s.length>1?{note:`in ${s.length} places`}:{}}),!0):!1}assertNameFree(e,r){ze([...this._queries.keys(),...this._controls.keys()],e,r)}soleDataset(e,r){if(!r)return;let i=Object.keys(this.datasets);if(i.length===1)return this.datasets[i[0]];throw new u(i.length?`Filter \'${e}\' names a field but the environment has ${i.length} datasets. Say which one: ${i.join(", ")}.`:`Filter \'${e}\' names a field but the environment has no datasets.`,e)}assertAcyclic(e){let r=[...this._mappings,e],i=new Map;r.forEach(d=>{let p=d.from.name;i.set(p,[...i.get(p)??[],d.to.name])});let s=new Set,l=new Set,a=o(d=>{if(s.has(d))return!0;if(l.has(d))return!1;s.add(d);let p=(i.get(d)??[]).some(a);return s.delete(d),l.add(d),p},"walk");if([...i.keys()].some(a))throw new u(`Mapping \'${e.id}\' would make the app\'s mappings cyclic.`,e.from.name)}};o(ye,"App");var K=ye;var it="0.13.3";var xe=class xe{constructor(n){c(this,"list");this.list=Object.freeze(n.map(({name:e,version:r})=>Object.freeze({name:e,version:r})))}has(n){return this.list.some(e=>e.name===n)}version(n){return this.list.find(e=>e.name===n)?.version}};o(xe,"InstalledPlugins");var be=xe,nn=it,ke=class ke{constructor(n){c(this,"version",nn);c(this,"_apps",[]);c(this,"datasets");c(this,"user");c(this,"indices");c(this,"backend");c(this,"plugins");c(this,"gates");c(this,"deprecatedFeatures");c(this,"extensions",{query:new Map,control:new Map});if(!n?.datasets)throw new u("No datasets provided. The host must call createSdk({ datasets }) before an app can be declared.");if(!n.user)throw new u("No user provided. The host must call createSdk({ user }) before an app can be declared.");if(!n.backend)throw new u("No backend provided. The host must call createSdk({ backend }) before an app can run a query.");this.datasets=Object.freeze({...n.datasets}),this.user=Object.freeze({...n.user,permissions:Object.freeze({...n.user.permissions})}),this.indices=Object.fromEntries(Object.entries(n.datasets).map(([e,r])=>[e,new G(r)])),this.backend=n.backend,this.gates=Object.freeze({...n.features}),this.plugins=new be(n.plugins??[])}get features(){return this.deprecatedFeatures||(console.warn("anfra: Anfra.features is deprecated and will be removed. Check Anfra.plugins.has(\'export\'), Anfra.plugins.has(\'render\') or Anfra.plugins.has(\'lineage\') instead."),this.deprecatedFeatures=Object.freeze({...this.gates,export:this.plugins.has("export"),render:this.plugins.has("render"),lineage:this.plugins.has("lineage")})),this.deprecatedFeatures}createApp(n={}){let e=new K(n,this.indices,this.backend,this.gates,this.extensions);return e.index=this._apps.length,this._apps.push(e),e}get apps(){return this._apps}};o(ke,"Sdk");var we=ke;function ot(t){return new we(t)}o(ot,"createSdk");var B="Anfra";function st(t,n=globalThis){let e=n[B],r=B in n;return n[B]=t,()=>{r?n[B]=e:delete n[B]}}o(st,"installSandbox");function at(t,n=[]){let e=t.document.getElementById(Se);if(!e?.textContent)throw new Error("anfra: this frame was not provisioned by a host.");let r=JSON.parse(e.textContent),i=o(m=>t.parent.postMessage(m,r.hostOrigin),"post"),s=new Map,l=new Map,a=Ae(i,{answer:o(async(m,y,f)=>{let b=s.get(m);if(!b)throw new C(`Nothing in this frame answers \'${m}\'.`);return b(y,f)},"answer"),event:o((m,y)=>{l.get(m)?.forEach(f=>{try{f(y)}catch{}})},"event")}),d=o(m=>m.source===t.parent||!!r.hostOrigin&&r.hostOrigin!=="null"&&m.origin===r.hostOrigin,"fromHost");t.addEventListener("message",m=>{d(m)&&a.receive(m.data)});let p={submitQuery:o((m,y)=>a.call("core.submitQuery",m,y).then(f=>(f.debug?.executedAt&&(f.debug.executedAt=new Date(f.debug.executedAt)),f)),"submitQuery"),fieldSuggestions:o((m,y)=>a.call("core.fieldSuggestions",m,y),"fieldSuggestions")},g=ot({datasets:r.datasets,user:r.user,backend:p,plugins:r.plugins??[]}),x=new Set,h=g.createApp.bind(g);g.createApp=m=>{let y=h(m);return x.forEach(f=>{try{f(y)}catch{}}),y};let E={window:t,sdk:g,endpoint:a,handlers:s,listeners:l,appListeners:x};for(let[m,y]of n)if(typeof y=="function")try{y(Be(m,E,{Query:T,Control:O}))}catch(f){t.console?.error(`anfra: plugin \'${m}\' failed to set up:`,f)}st(g,t),i({type:"anfra:ready"})}o(at,"bootstrap");return ht(rn);})();\n';
19
+ var anfra_sdk_frame_script_default = '"use strict";var __anfraKernel=(()=>{var N=Object.defineProperty;var dt=Object.getOwnPropertyDescriptor;var ct=Object.getOwnPropertyNames;var pt=Object.prototype.hasOwnProperty;var ut=(t,n,e)=>n in t?N(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var o=(t,n)=>N(t,"name",{value:n,configurable:!0});var ft=(t,n)=>{for(var e in n)N(t,e,{get:n[e],enumerable:!0})},mt=(t,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of ct(n))!pt.call(t,i)&&i!==e&&N(t,i,{get:()=>n[i],enumerable:!(r=dt(n,i))||r.enumerable});return t};var ht=t=>mt(N({},"__esModule",{value:!0}),t);var c=(t,n,e)=>ut(t,typeof n!="symbol"?n+"":n,e);var rn={};ft(rn,{bootstrap:()=>at});var Se="anfra-provision";var U=class U extends Error{constructor(e,r){super(e);c(this,"entity");this.name=new.target.name,this.entity=r,Object.setPrototypeOf(this,new.target.prototype)}};o(U,"DataAppError");var S=U,H=class H extends S{};o(H,"ValidationError");var u=H,Y=class Y extends S{constructor(e,r,i){super(e,r);c(this,"cause");this.cause=i}};o(Y,"QueryError");var D=Y,W=class W extends S{};o(W,"PermissionError");var R=W,X=class X extends S{constructor(e,r,i){super(e,i);c(this,"status");this.status=r}};o(X,"TransportError");var C=X;function Ce(){let t=new Error("Aborted");return t.name="AbortError",t}o(Ce,"abortError");function gt(t){return t?.name==="AbortError"}o(gt,"isAbortError");var yt=new Set(["ValidationError","QueryError","PermissionError","TransportError"]);function bt(t){let n=t;return n instanceof Error&&yt.has(n.name)?{name:n.name,message:n.message||"The call failed."}:{name:"QueryError",message:"The call failed."}}o(bt,"toBridgeError");function wt(t){switch(t?.name){case"PermissionError":return new R(t.message);case"TransportError":return new C(t.message);case"ValidationError":return new u(t.message);default:return new D(t?.message||"The call failed.")}}o(wt,"fromBridgeError");function Ae(t,n){let e=new Map,r=new Map,i=1,s=o((l,a,d)=>{let p=new AbortController;r.set(l,p),Promise.resolve().then(()=>n.answer(a,d,p.signal)).then(g=>{p.signal.aborted||t({type:"anfra:result",id:l,ok:!0,result:g})}).catch(g=>{p.signal.aborted||gt(g)||t({type:"anfra:result",id:l,ok:!1,error:bt(g)})}).finally(()=>{r.get(l)===p&&r.delete(l)})},"answer");return{call(l,a,d){return new Promise((p,g)=>{if(d?.aborted){g(Ce());return}let x=i++;e.set(x,{resolve:p,reject:g}),d?.addEventListener("abort",()=>{e.delete(x)&&(t({type:"anfra:cancel",id:x}),g(Ce()))},{once:!0}),t({type:"anfra:call",id:x,name:l,request:a})})},emit(l,a){t({type:"anfra:event",name:l,payload:a})},receive(l){switch(l?.type){case"anfra:call":return s(l.id,l.name,l.request),!0;case"anfra:result":{let a=e.get(l.id);return a&&(e.delete(l.id),l.ok?a.resolve(l.result):a.reject(wt(l.error))),!0}case"anfra:cancel":return r.get(l.id)?.abort(),r.delete(l.id),!0;case"anfra:event":return n.event(l.name,l.payload),!0;default:return!1}},close(l){r.forEach(a=>a.abort()),r.clear(),e.forEach(({reject:a})=>a(l)),e.clear()}}}o(Ae,"createEndpoint");var Z=class Z{constructor(n){c(this,"listeners",new Set);c(this,"parent");this.parent=n}subscribe(n){return this.listeners.add(n),()=>{this.listeners.delete(n)}}notifyChange(){this.listeners.forEach(n=>n()),this.parent?.notifyChange()}notify(){this.notifyChange()}};o(Z,"Observable");var $=Z;var De=["year","quarter","month","week","day","hour","minute"];function xt(t,n){if(!De.includes(n))throw new u(`Invalid grain \'${n}\'. Expected one of: ${De.join(", ")}.`,t)}o(xt,"assertGrain");function Re(t,n){return n?(xt(t,n),{operator:"transform_date_drill",values:[`datetrunc ${n}`]}):{operator:"none"}}o(Re,"drillCondition");function kt(t){let n=t.toLowerCase();return n.includes("date")||n.includes("time")?"date":n.includes("int")||n.includes("number")||n.includes("float")||n.includes("decimal")?"number":n.includes("bool")?"boolean":"string"}o(kt,"inferType");function Et(t,n){return JSON.stringify(t??null)===JSON.stringify(n??null)}o(Et,"sameCondition");var ee=class ee extends ${constructor(e,r,i){super(r);c(this,"name");c(this,"app");c(this,"pending");c(this,"applied");c(this,"initial");this.name=e,this.app=r,this.initial=i,this.pending=i}locate(){return this.app.locate("control",this.name)}get condition(){return this.pending}get appliedCondition(){return this.applied}get isDirty(){return this.applied!==void 0&&!Et(this.pending,this.applied)}setCondition(e){this.pending=e,this.notify()}reset(){this.setCondition(this.initial)}commit(){this.applied=this.pending}};o(ee,"Control");var O=ee,te=class te extends O{constructor(e,r,i,s,l){super(e,r,i.default??{operator:"is",values:[]});c(this,"kind","filter");c(this,"declaration");c(this,"type");c(this,"resolved");c(this,"datasetName");c(this,"backend");c(this,"loadedOptions");if(this.declaration=i,this.backend=l,i.field){if(!s)throw new u(`Filter \'${e}\' names a field but no dataset. Pass \\`dataset\\` alongside \\`field\\`.`,e);this.resolved=s.resolve(i.field,e),this.datasetName=s.descriptor.name,this.type=i.type??kt(this.resolved.type)}else{if(!i.type)throw new u(`Filter \'${e}\' is a manual filter, so it needs a \\`type\\`.`,e);this.type=i.type}this.assertValues(this.condition.values??[]),this.assertValues(i.options??[])}setCondition(e){this.assertValues(e.values??[]),super.setCondition(e)}assertValues(e){if(this.type!=="number")return;let r=e.find(i=>typeof i=="number");if(r!==void 0)throw new u(`Filter \'${this.name}\' filters numbers: give its values as strings, as query results give them (${JSON.stringify(String(r))}, not ${String(r)}), so none has lost a digit.`,this.name)}get isFieldBacked(){return this.resolved!==void 0}get options(){return this.loadedOptions??this.declaration.options??[]}async loadOptions(e,r=new AbortController().signal){let i=this.resolved?.modelName;if(!this.resolved||!i||!this.backend||!this.datasetName)return this.options;let s=await this.backend.fieldSuggestions({dataset:this.datasetName,model:i,field:this.resolved.fieldName,q:e??""},r);return this.loadedOptions=[...s??[]],this.notify(),this.loadedOptions}toJSON(){return this.declaration}};o(te,"Filter");var P=te,ne=class ne extends O{constructor(e,r,i={}){super(e,r,Re(e,i.default));c(this,"kind","dateDrill");c(this,"declaration");this.declaration=i}setGrain(e){this.setCondition(Re(this.name,e))}toJSON(){return this.declaration}};o(ne,"DateDrillControl");var z=ne;var v={container:"data-anfra-container",block:"data-anfra-block",query:"data-anfra-query",control:"data-anfra-control",label:"data-anfra-label"},_e=`[${v.container}],[${v.block}],[${v.query}],[${v.control}]`;function $e(t){let n=/^(?:(\\d+)\\/)?([^/\\s]+)$/.exec(t);if(n)return{app:n[1]===void 0?0:Number(n[1]),name:n[2]}}o($e,"parseRef");var Oe=o(t=>(t??"").split(/\\s+/).filter(Boolean),"tokens");function Te(t,n,e,r){let i=n==="query"?v.query:v.control;return[...t.querySelectorAll(`[${i}]`)].filter(s=>Oe(s.getAttribute(i)).some(l=>{let a=$e(l);return a?.app===e&&a.name===r}))}o(Te,"markersFor");var vt=o((t,n,e)=>{let r=t[e.app];return r?Object.prototype.hasOwnProperty.call(n==="query"?r.queries:r.controls,e.name):!1},"hasEntity");function Fe(t,n){var x;let e=[],r=new Map,i=new Map,s=new Map,l=new Map,a={container:new Set,block:new Set},d={},p=o((h,E,m)=>{let y=h?s.get(h).children:e,f=h?`${s.get(h).key}.`:"",b={...E,key:`${f}${y.length}`,children:[]};return y.push(b),r.set(b.key,m),i.set(m,[...i.get(m)??[],b.key]),b},"place");for(let h of t.querySelectorAll(_e)){let E=h.parentElement?.closest(_e)??null,m=h.getAttribute(v.container),y=h.getAttribute(v.block),f=h.getAttribute(v.label)??void 0,b=E&&(l.get(E)==="block"?E:E.closest(`[${v.block}]`)),_;if(m!==null||y!==null){let k=m!==null?"container":"block",A=(m??y??"").trim(),w=[];m!==null&&y!==null&&w.push("This element is marked as a container and as a block. It counts as a container."),A?a[k].has(A)?w.push(`Another ${k} already has the id "${A}".`):a[k].add(A):w.push(`This ${k} has no id.`),b&&w.push(`A block can\'t hold a ${k}. This one is inside the block "${b.getAttribute(v.block)}".`),_=p(E,{kind:k,id:A,...f!==void 0?{label:f}:{},problems:w},h),s.set(h,_),l.set(h,k)}let M=_?h:E;for(let k of["query","control"])for(let A of Oe(h.getAttribute(k==="query"?v.query:v.control))){let w=$e(A),L=[];if(w?vt(n,k,w)||L.push(n[w.app]?`No ${k} is called "${w.name}" in app ${w.app}.`:`The page has no app ${w.app}.`):L.push(`Can\'t read "${A}". Write the ${k}\'s name, or app/name when the page has several apps.`),p(M,{kind:k,name:w?.name??A,app:w?.app??0,problems:L},h),w&&!L.length){let lt=`${w.app}/${w.name}`,Ee=d[x=`${k}:${lt}`]??(d[x]={elements:new Set,blocks:new Set});Ee.elements.add(h);let ve=_?.kind==="block"?_.id:b?.getAttribute(v.block);ve&&Ee.blocks.add(ve)}}}let g=Object.fromEntries(Object.entries(d).map(([h,E])=>[h,{markers:E.elements.size,blocks:[...E.blocks]}]));return{nodes:e,usage:g,elements:r,keysOf:i}}o(Fe,"buildStructure");var Me="data-anfra-layer",St="position:absolute;top:0;left:0;width:0;height:0;overflow:visible;z-index:2147483647;";function Ct(t){let n=t.querySelector(`[${Me}]`);if(n instanceof(t.defaultView?.HTMLElement??HTMLElement))return n;let e=t.createElement("div");return e.setAttribute(Me,""),e.setAttribute("style",St),(t.body??t.documentElement).appendChild(e),e}o(Ct,"layerOf");function Q(t,n){let e=Ct(t),r=[...e.children].find(s=>s.getAttribute("data-part")===n);if(r?.shadowRoot)return r.shadowRoot;let i=t.createElement("div");return i.setAttribute("data-part",n),e.appendChild(i),i.attachShadow({mode:"open"})}o(Q,"layerRoot");var Ne="anfra-overlay",At=1500,Dt="position:fixed;box-sizing:border-box;background:rgba(37,99,235,0.22);outline:1px solid #2563eb;outline-offset:-1px;",Rt="position:fixed;max-width:60vw;display:flex;gap:6px;align-items:baseline;padding:3px 8px;border-radius:4px;background:#0f172a;color:#f8fafc;font:12px/1.4 system-ui,sans-serif;white-space:nowrap;box-shadow:0 2px 8px rgba(0,0,0,0.35);",_t={kind:"color:#94a3b8;",name:"color:#93c5fd;font-weight:700;",label:"color:#f8fafc;",note:"color:#94a3b8;",size:"color:#94a3b8;margin-left:10px;"},ie=class ie{constructor(n){c(this,"doc",n);c(this,"root");c(this,"shown",[]);c(this,"text",{kind:"",name:""});c(this,"timer");c(this,"reposition",o(()=>this.draw(),"reposition"));let e=Q(n,"anfra"),r=e.getElementById(Ne);r instanceof(n.defaultView?.HTMLElement??HTMLElement)?this.root=r:(this.root=n.createElement("div"),this.root.id=Ne,this.root.setAttribute("aria-hidden","true"),this.root.setAttribute("style","position:fixed;inset:0;z-index:2147483647;pointer-events:none;display:none;"),e.appendChild(this.root))}show(n,e){if(this.clearTimer(),this.root.isConnected||Q(this.doc,"anfra").appendChild(this.root),this.shown=[...n],this.text=e,!this.shown.length){this.hide();return}this.root.style.display="block",this.draw(),this.doc.addEventListener("scroll",this.reposition,{capture:!0,passive:!0}),this.doc.defaultView?.addEventListener("resize",this.reposition)}flash(n,e,r=At){this.show(n,e),this.timer=setTimeout(()=>this.hide(),r)}hide(){this.clearTimer(),this.shown=[],this.root.style.display="none",this.root.replaceChildren(),this.doc.removeEventListener("scroll",this.reposition,{capture:!0}),this.doc.defaultView?.removeEventListener("resize",this.reposition)}get visible(){return this.shown.length>0}clearTimer(){this.timer!==void 0&&clearTimeout(this.timer),this.timer=void 0}draw(){let n=this.shown.map(a=>{let d=a.getBoundingClientRect(),p=this.doc.createElement("div");return p.setAttribute("style",`${Dt}left:${d.left}px;top:${d.top}px;width:${d.width}px;height:${d.height}px;`),p}),e=this.shown[0].getBoundingClientRect(),r=this.doc.createElement("div");r.setAttribute("data-testid","anfra-overlay-label");let i=this.doc.defaultView?.innerHeight??0,s=e.top>=26?e.top-24:Math.max(4,e.top+4),l=Math.max(4,Math.min(e.left,(this.doc.defaultView?.innerWidth??0)-24));r.setAttribute("style",`${Rt}left:${l}px;top:${Math.min(s,i-24)}px;`);for(let a of["kind","name","label","note","size"]){let d=this.text[a];if(!d)continue;let p=this.doc.createElement("span");p.setAttribute("style",_t[a]),p.setAttribute("data-part",a),p.textContent=d,r.appendChild(p)}this.root.replaceChildren(...n,r)}};o(ie,"Overlay");var re=ie,Qe=new WeakMap;function V(t){let n=Qe.get(t);return n||(n=new re(t),Qe.set(t,n)),n}o(V,"overlayFor");function Ie(t){typeof t.scrollIntoView=="function"&&t.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}o(Ie,"scrollTo");function oe(t,n,e,r,i){if(r in n||t.has(r))throw new u(`Plugin \'${r}\' can\'t add \'${r}\' to a ${e}: it already has one.`);t.set(r,i)}o(oe,"addExtension");function j(t,n){return n?.forEach((e,r)=>{let i=!1,s;Object.defineProperty(t,r,{configurable:!0,enumerable:!1,get(){return i||(s=e(t),i=!0),s}})}),t}o(j,"applyExtensions");var $t="anfra.body",se="__anfraBodyExports",Ot={DataAppError:S,ValidationError:u,QueryError:D,PermissionError:R,TransportError:C};function Tt(t,n){let e=t,r=t.document.createElement("script");r.textContent=`(function () { var __anfraBody;\n${n}\n;self[${JSON.stringify(se)}] = __anfraBody; })();`,(t.document.head??t.document.documentElement).appendChild(r),r.remove();let i=e[se];if(delete e[se],!i)throw new u("The host sent a plugin body that did not run.");return i.default??i}o(Tt,"runBody");function Be(t,n,e){let{window:r,sdk:i,endpoint:s}=n,l;return{plugin:t,window:r,sdk:i,errors:Ot,get overlay(){return V(r.document)},structure:o(()=>Fe(r.document,i.apps),"structure"),call:o((a,d,p)=>s.call(a,d??null,p),"call"),emit:o((a,d)=>s.emit(`${t}.${a}`,d??null),"emit"),handle(a,d){n.handlers.set(`${t}.${a}`,d)},on(a,d){let p=`${t}.${a}`;n.listeners.has(p)||n.listeners.set(p,new Set),n.listeners.get(p).add(d)},onApp(a){n.appListeners.add(a),i.apps.forEach(d=>a(d))},provide(a){if(t in i)throw new u(`Plugin \'${t}\' can\'t add a member Anfra already has.`);Object.defineProperty(i,t,{value:a,enumerable:!0})},provideOnQuery:o(a=>oe(i.extensions.query,e.Query.prototype,"query",t,a),"provideOnQuery"),provideOnControl:o(a=>oe(i.extensions.control,e.Control.prototype,"control",t,a),"provideOnControl"),layer:o(()=>Q(r.document,t),"layer"),body(){return l??(l=s.call($t,{plugin:t}).then(a=>Tt(r,a)).catch(a=>{throw l=void 0,a})),l}}}o(Be,"createKernel");var ae=class ae extends ${constructor(e,r,i){super(r);c(this,"kind","query");c(this,"name");c(this,"declaration");c(this,"dataset");c(this,"app");c(this,"_state","idle");c(this,"_result");c(this,"_error");c(this,"_page",1);c(this,"_sort",[]);c(this,"lastRunSignature");c(this,"lastPageRows",0);c(this,"controller");if(!i.aql?.trim())throw new u(`Query \'${e}\' declares no AQL.`,e);let{pageSize:s}=i;if(s!==void 0&&!(Number.isInteger(s)&&s>=1))throw new u(`Query \'${e}\' declares pageSize ${s}; it must be a whole number of at least 1.`,e);this.name=e,this.app=r,this.declaration=i,this.dataset=r.datasetIndex(i.dataset,e)}locate(){return this.app.locate("query",this.name)}get state(){return this._state}get result(){return this._result}get error(){return this._error}get pageSize(){return this.declaration.pageSize}get page(){return this._page}get sort(){return this._sort}setSort(e){this._sort=[...e],this.notify()}get hasMore(){return!this._result||this.pageSize===void 0?!1:this._result.meta.hasMore??this.lastPageRows>=this.pageSize}signature(){let e=this.app.mappingsTo(this.name).map(r=>({field:r.field,aggregation:r.aggregation,condition:r.from.condition})).sort((r,i)=>r.field.localeCompare(i.field)||JSON.stringify(r).localeCompare(JSON.stringify(i)));return JSON.stringify({declaration:this.declaration,conditions:e,selection:this.app.selectionConditionsFor(this.name,"pending"),selectionExpression:this.app.selectionExpressionFor(this.name,"pending"),sort:this._sort,timezone:this.app.timezone,page:this._page})}get isDirty(){return this.lastRunSignature!==void 0&&this.signature()!==this.lastRunSignature}shouldRun(e=!1){return e||this.lastRunSignature===void 0||this.isDirty}abort(){this.controller?.abort()}async fetchMore(){if(this.pageSize===void 0)throw new u(`Query \'${this.name}\' declares no pageSize, so it has no more pages.`,this.name);this.hasMore&&(this._page+=1,await this.app.fetchPage(this))}select(e,r={}){this.app.select(this,Array.isArray(e)?e:[e],r.fields)}get selectedRows(){let{selection:e}=this.app;if(e?.source!==this.name)return[];let r=this._result?.rows;if(!r)return e.rows;let i=o(l=>JSON.stringify(e.fields.map(a=>l[a]??null)),"key"),s=new Set(e.rows.map(i));return r.filter(l=>s.has(i(l)))}markExecuting(){this._state="executing",this._error=void 0,this.notify()}markSuccess(e,r,i){if(this._state="success",this._error=void 0,this.lastRunSignature=r,this.lastPageRows=e.rows.length,i&&this._result){let s=[...this._result.rows,...e.rows];this._result={...e,rows:s,meta:{...e.meta,numRows:s.length}}}else this._result=e;this.notify()}markError(e){this._state="error",this._error=e,this.notify()}rewindPage(){this._page>1&&(this._page-=1)}resetPage(){this._page=1,this.lastPageRows=0}toJSON(){return this.declaration}};o(ae,"Query");var T=ae;var le=class le{constructor(n,e,r,i){c(this,"kind","control");c(this,"from");c(this,"to");c(this,"field");c(this,"aggregation");this.from=n,this.to=e,this.field=r,this.aggregation=i}get id(){return`${this.from.name}.${this.to.name}.${this.field}`}toJSON(){return{kind:this.kind,id:this.id,from:{kind:this.from.kind,name:this.from.name},to:{kind:"query",name:this.to.name},field:this.field,...this.aggregation?{aggregation:this.aggregation}:{}}}};o(le,"Mapping");var J=le,de=class de{constructor(n,e){c(this,"kind","crossFilter");c(this,"from");c(this,"to");this.from=n,this.to=e}get id(){return`${this.from.name}.${this.to.name}`}toJSON(){return{kind:this.kind,id:this.id,from:{kind:"query",name:this.from.name},to:{kind:"query",name:this.to.name}}}};o(de,"CrossFilter");var q=de;var ce=["sum","avg","max","min","count","count distinct","median","stdev","stdevp","var","varp"];function Ft(t,n){let e=t.length+1,r=n.length+1,i=Array.from({length:r},(s,l)=>l);for(let s=1;s<e;s++){let l=[s];for(let a=1;a<r;a++)l[a]=Math.min(i[a]+1,l[a-1]+1,i[a-1]+(t[s-1]===n[a-1]?0:1));i=l}return i[r-1]}o(Ft,"editDistance");function Mt(t,n){let e,r=1/0;n.forEach(s=>{let l=Ft(t.toLowerCase(),s.toLowerCase());l<r&&(r=l,e=s)});let i=Math.max(2,Math.floor(t.length/3));return r<=i?e:void 0}o(Mt,"suggest");function F(t,n,e){let r=Mt(n,e);return r?`${t} Did you mean \'${r}\'?`:t}o(F,"withSuggestion");var pe=class pe{constructor(n){c(this,"descriptor");c(this,"fields",new Map);c(this,"references");this.descriptor=n,n.data_models.forEach(e=>{e.fields.forEach(r=>{let i=String(e.name);this.fields.set(`${i}.${r.name}`,{modelName:i,fieldName:r.name,isMetric:!1,type:r.type,label:r.label??r.name})})}),n.metrics.forEach(e=>{this.fields.set(e.name,{fieldName:e.name,isMetric:!0,type:e.type,label:e.label??e.name})}),this.references=[...this.fields.keys()]}resolve(n,e){let r=this.fields.get(n);if(r)return r;throw new u(F(`Unknown field \'${n}\' on dataset \'${this.descriptor.name}\'.`,n,this.references),e)}};o(pe,"DatasetIndex");var G=pe;function Le(t,n,e){let r=t[n];if(r)return r;throw new u(F(`Unknown dataset \'${n}\'.`,n,Object.keys(t)),e)}o(Le,"resolveDataset");function Pe(t,n){if(!ce.includes(t))throw new u(F(`Invalid filter aggregation \'${t}\'.`,t,[...ce]),n)}o(Pe,"assertValidFilterAggregation");function ze(t,n,e){if(!n)throw new u(`A ${e} needs a name.`);for(let r of t)if(r===n)throw new u(`\'${n}\' is already declared in this app.`,n)}o(ze,"assertUniqueName");function Nt(t,n){if(!(!n||n.operator==="none"||n.operator==="transform_date_drill"||!["is_null","not_null","is_true","is_false","transform_pop_none"].includes(n.operator)&&!n.values?.length))return{field:t.field,operator:n.operator,values:n.values??[],...n.modifier?{modifier:n.modifier}:{},...t.aggregation?{aggregation:t.aggregation}:{}}}o(Nt,"toFilter");function Qt(t,n){if(n?.operator!=="transform_date_drill")return;let e=n.values?.[0];if(typeof e!="string")return;let r=e.replace(/^datetrunc\\s+/,"");return{field:t.field,grain:r}}o(Qt,"toDateDrill");function It(t,n){let e=n.columns??[],r=(n.values??[]).map(s=>{let l={};return e.forEach((a,d)=>{l[a.name]=s[d]}),l}),{pageSize:i}=t;return{columns:e,rows:r,meta:{...i!==void 0?{page:n.meta?.page??t.page,pageSize:n.meta?.pageSize??i,...n.meta?.hasMore!==void 0?{hasMore:n.meta.hasMore}:{}}:{},numRows:n.meta?.numRows??r.length},...n.debug?{debug:n.debug}:{}}}o(It,"toResult");function Ve(t,n,e,r){let i=n.map(d=>Nt(d,d.from.appliedCondition)).filter(d=>d!==void 0),s=n.map(d=>Qt(d,d.from.appliedCondition)).filter(d=>d!==void 0),l=e.conditions.map(d=>({field:d.field,operator:d.operator,values:d.values})),a=e.expression?[{expr:e.expression}]:[];return{dataset:t.dataset.descriptor.name,aql:t.declaration.aql,input:{filters:[...i,...l],conditions:a,sorts:t.sort.map(d=>({field:d.field,direction:d.direction??"asc"})),dateDrills:s},...r.timezone?{timezone:r.timezone}:{}}}o(Ve,"buildQuery");function Bt(t,n,e,r){return{...Ve(t,n,e,r),...t.pageSize!==void 0?{page:t.page,pageSize:t.pageSize}:{},...r.bustCache?{bustCache:!0}:{}}}o(Bt,"buildRequest");function Lt(t,n){let e=n?.replace(/[/\\\\]/g,"-").replace(/\\p{Cc}/gu,"").trim();return e?`${e} - ${t.name}`:t.name}o(Lt,"defaultExportFilename");function je(t,n,e,r,i){let s=i.format??"csv",l=s==="csv"?{bom:!0,...i.formatOptions}:i.formatOptions;return{...Ve(t,n,e,r),format:s,...l?{formatOptions:l}:{},filename:i.filename?.trim()||Lt(t,r.title)}}o(je,"buildExportRequest");async function ue(t,n,e,r,i){let s=Bt(t,n,e,r),l=await r.backend.submitQuery(s,i);return It(t,l)}o(ue,"runQuery");function Pt(t,n){if(t===null)return"null";if(typeof t=="boolean")return t?"true":"false";if(n==="number"&&typeof t=="string")return jt(t);if(typeof t=="number"){if(!Number.isFinite(t))throw new RangeError(`Cannot express ${t} in AQL.`);return Math.abs(t)>=1e21?BigInt(t).toString():String(t)}return JSON.stringify(t).split("\\u2028").join("\\\\u2028").split("\\u2029").join("\\\\u2029")}o(Pt,"literal");function Je(t,n,e){return n===null?`is(${t}, null)`:`${t} is ${Pt(n,e)}`}o(Je,"equals");var zt=new Set(["NaN","Infinity","-Infinity"]),Vt=/^(-?)(0|[1-9]\\d*)(?:\\.(\\d+))?(?:[eE]([+-]?\\d+))?$/;function jt(t){let n=Vt.exec(t);if(!n)throw zt.has(t)?new RangeError(`Cannot express ${t} in AQL.`):new TypeError(`${JSON.stringify(t)} is not a number: a number is a string in JSON\'s number syntax.`);let[,e,r,i="",s]=n;if(s===void 0)return t;let l=r+i,a=r.length+Number(s),d;return a<=0?d=`0.${"0".repeat(-a)}${l}`:a>=l.length?d=l+"0".repeat(a-l.length):d=`${l.slice(0,a)}.${l.slice(a)}`,e+d.replace(/^0+(?=\\d)/,"")}o(jt,"numberLiteral");function qe(t,n,e){return`${t} matches @(${n} until ${e})`}o(qe,"dateRange");function Ge(t,n){if(n.length===0)throw new RangeError(`\\`${t}\\` needs at least one operand.`);return n.length===1?n[0]:`${t}(${n.join(", ")})`}o(Ge,"combine");var Ke=o(t=>Ge("and",t),"and"),Ue=o(t=>Ge("or",t),"or");var Jt=/^(\\d{4})-(\\d{2})-(\\d{2})(?:[T ](\\d{2}):(\\d{2})(?::(\\d{2}))?)?/,qt={week:7*864e5,day:864e5,hour:36e5,minute:6e4};function He(t){if(typeof t!="string")return;let n=Jt.exec(t);if(n)return{year:Number(n[1]),month:Number(n[2])-1,day:Number(n[3]),hour:Number(n[4]??0),minute:Number(n[5]??0),second:Number(n[6]??0),hasTime:n[4]!==void 0}}o(He,"parseStamp");function I(t,n){let e=new Date(t),r=o(s=>String(s).padStart(2,"0"),"pad"),i=`${e.getUTCFullYear()}-${r(e.getUTCMonth()+1)}-${r(e.getUTCDate())}`;return n?`${i} ${r(e.getUTCHours())}:${r(e.getUTCMinutes())}:${r(e.getUTCSeconds())}`:i}o(I,"format");function Ye(t){return Date.UTC(t.year,t.month,t.day,t.hour,t.minute,t.second)}o(Ye,"toMs");function fe(t){let n=He(t);if(n)return I(Ye(n),n.hasTime)}o(fe,"normalise");function me(t,n){let e=He(t);if(!e)return;let{year:r,month:i,day:s,hour:l,minute:a,second:d,hasTime:p}=e;return I(n==="year"?Date.UTC(r+1,i,s,l,a,d):n==="quarter"?Date.UTC(r,i+3,s,l,a,d):n==="month"?Date.UTC(r,i+1,s,l,a,d):Ye(e)+qt[n],p)}o(me,"addGrain");function We(t){if(t?.startsWith("datetrunc "))return t.slice(10)}o(We,"grainOf");function Gt(t){let n=new Set;return t.filter(e=>{let r=`${typeof e}:${String(e)}`;return n.has(r)?!1:(n.add(r),!0)})}o(Gt,"distinct");function Kt(t,n){let e=t.map(fe);if(e.some(i=>i===void 0))return!1;let r=e.slice().sort();for(let i=1;i<r.length;i+=1)if(me(r[i-1],n)!==r[i])return!1;return!0}o(Kt,"isContiguous");function Ut(t,n,e){let r=n.map(fe);if(r.some(d=>d===void 0))return;let i=r.slice().sort(),s=i[0],l=me(i[i.length-1],e);if(!l)return;let a=Kt(n,e);return{condition:{field:t,operator:"matches",values:[`${s} until ${l}`]},admits:a?n.length:Number.POSITIVE_INFINITY,lossy:!a}}o(Ut,"dateRange");function Ht(t,n,e){let r=e.filter(a=>a!=null),i=Gt(r);if(!i.length)return{condition:{field:t,operator:"is_null",values:[]},admits:1,lossy:!1};let s=r.length!==e.length,l=We(n);if(l){let a=Ut(t,i,l);if(a)return{...a,lossy:a.lossy||s}}return{condition:{field:t,operator:"is",values:i},admits:i.length,lossy:s}}o(Ht,"deriveOne");function Xe(t){return t.modelId?`${t.modelId}.${t.fieldName}`:t.fieldName}o(Xe,"fieldReferenceOf");function Yt(t,n,e,r){try{let i=e.map(s=>Ke(n.map(l=>{let a=t.get(l),d=Xe(a),p=s[l]??null,g=We(r[d]);if(g&&typeof p=="string"){let x=fe(p),h=me(p,g);if(x&&h)return qe(d,x,h)}if(p!==null&&typeof p!="string"&&typeof p!="number"&&typeof p!="boolean")throw new TypeError("no AQL spelling");return Je(d,p,a.semantic_type)})));return Ue(i)}catch{return}}o(Yt,"selectionExpression");function Ze(t,n,e,r={}){let i=t.result?.columns??[],s=new Map(i.map(f=>[f.name,f]));e?.forEach(f=>{let b=s.get(f);if(b){if(b.adhoc)throw new u(`Query \'${t.name}\' cannot cross-filter on \'${f}\': it is a query-local AQL expression, which only this query\'s result carries. The target query would receive a condition naming a field it has never heard of.`,t.name);if(b.isMeasure)throw new u(`Query \'${t.name}\' cannot cross-filter on \'${f}\': it is a measure, and a selection conditions dimensions only.`,t.name);return}throw new u(F(`Query \'${t.name}\' has no column \'${f}\' in its last result.`,f,[...s.keys()]),t.name)});let l=i.filter(f=>!f.isMeasure),a=l.filter(f=>!f.adhoc).map(f=>f.name),d=e?[...e]:a;if(!n.length||!d.length)return;let p=[],g=1,x=!e&&a.length!==l.length,h=!1;d.forEach(f=>{let b=s.get(f),_=Xe(b),M=Ht(_,r[_],n.map(k=>k[f]));p.push(M.condition),g*=M.admits,h=h||M.lossy});let E=new Set(n.map(f=>JSON.stringify(d.map(b=>f[b]??null))));g>E.size&&(h=!0);let m=p.sort((f,b)=>f.field.localeCompare(b.field)),y={source:t.name,rows:[...n],fields:d};if(h){let f=Yt(s,d,n,r);if(f)return{...y,conditions:[],expression:f,lossy:x}}return{...y,conditions:m,lossy:x||h}}o(Ze,"deriveSelection");var he=Object.freeze([]);function ge(t){return t instanceof Error&&t.name==="AbortError"}o(ge,"isAbort");function et(t,n){return t.controller!==n}o(et,"superseded");function Wt(t){return{name:t.name,message:t.message,...t.entity?{entity:t.entity}:{},...typeof t.status=="number"?{status:t.status}:{},...t.stack?{stack:t.stack}:{}}}o(Wt,"inspectError");function Xt(t){let{result:n}=t;return{state:t.state,isDirty:t.isDirty,page:t.page,hasMore:t.hasMore,columns:n?n.columns.map(e=>({...e})):[],rowCount:n?.meta.numRows??0,selectedRowCount:t.selectedRows.length,signature:t.signature(),...t.error?{error:Wt(t.error)}:{},...n?.debug?{debug:{...n.debug}}:{}}}o(Xt,"inspectQuery");function Zt(t){let{options:n}=t;return{kind:t.kind,condition:{...t.condition},...t.appliedCondition?{appliedCondition:{...t.appliedCondition}}:{},isDirty:t.isDirty,...n?{options:[...n]}:{}}}o(Zt,"inspectControl");function tt(t){return{source:t.source,fields:[...t.fields],rowCount:t.rows.length,conditions:t.conditions.map(n=>({...n})),...t.expression?{expression:t.expression}:{},lossy:t.lossy}}o(tt,"inspectSelection");function nt(t){return t?JSON.stringify({source:t.source,conditions:t.conditions,expression:t.expression}):"none"}o(nt,"selectionKey");function rt(t,n){return t instanceof S?t:new D(t?.message??"The query failed.",n,t)}o(rt,"toDataAppError");function en(t,n){if(t instanceof S&&t.entity)return t;let e=t?.message||"The export failed.";return t instanceof R?new R(e,n):t instanceof C?new C(e,t.status,n):t instanceof u?new u(e,n):new D(e,n,t)}o(en,"toExportError");var ye=class ye extends ${constructor(e,r,i,s,l){super();c(this,"extensions",l);c(this,"title");c(this,"_timezone");c(this,"datasets");c(this,"backend");c(this,"features");c(this,"_queries",new Map);c(this,"_controls",new Map);c(this,"_mappings",[]);c(this,"_crossFilters",[]);c(this,"_selection");c(this,"_appliedSelection");c(this,"selectionCommitted",!1);c(this,"index",0);this.title=e.title,this._timezone=e.timezone,this.datasets=r,this.backend=i,this.features=s}get queries(){return Object.fromEntries(this._queries)}get controls(){return Object.fromEntries(this._controls)}get mappings(){return[...this._mappings,...this._crossFilters]}get crossFilters(){return this._crossFilters}createQuery(e,r){this.assertNameFree(e,"query");let i=j(new T(e,this,r),this.extensions?.query);return this._queries.set(e,i),this.notify(),i}createFilter(e,r){this.assertNameFree(e,"filter");let i=r.dataset?this.datasetIndex(r.dataset,e):this.soleDataset(e,r.field),s=j(new P(e,this,r,i,this.backend),this.extensions?.control);return this._controls.set(e,s),this.notify(),s}createDateDrill(e,r={}){if(this.features?.dateDrill===!1)throw new u(`Date drill \'${e}\' needs a capability this workspace has not enabled. Ask an admin to turn on \\`interactive_control:date_drill\\`.`,e);this.assertNameFree(e,"date drill control");let i=j(new z(e,this,r),this.extensions?.control);return this._controls.set(e,i),this.notify(),i}mapControl(e,r,i){if(!(e instanceof O))throw new u("mapControl expects a control as its source. To let one query cross-filter another, use app.mapCrossFilter(from, to) \\u2014 a cross-filter edge names no field.");if(this._controls.get(e.name)!==e)throw new u(`Control \'${e.name}\' belongs to a different app.`,e.name);if(this._queries.get(r.name)!==r)throw new u(`Query \'${r.name}\' belongs to a different app.`,r.name);i.aggregation&&Pe(i.aggregation,e.name);let s=new J(e,r,i.field,i.aggregation);if(this._mappings.some(l=>l.id===s.id))throw new u(`Mapping \'${s.id}\' is already declared.`,e.name);return this.assertAcyclic(s),this._mappings.push(s),this.notify(),s}mapCrossFilter(e,r){if(!(e instanceof T)||!(r instanceof T))throw new u("mapCrossFilter expects two queries. To let a control condition a query, use app.mapControl(from, to, { field }).");if(this._queries.get(e.name)!==e)throw new u(`Query \'${e.name}\' belongs to a different app.`,e.name);if(this._queries.get(r.name)!==r)throw new u(`Query \'${r.name}\' belongs to a different app.`,r.name);if(e===r)throw new u(`Query \'${e.name}\' cannot cross-filter itself. A source keeps its own rows so it can show what is selected; filtering it would erase the very rows the reader clicked.`,e.name);if(e.declaration.dataset!==r.declaration.dataset)throw new u(`Cross-filter \'${e.name}\' -> \'${r.name}\' spans two datasets (\'${e.declaration.dataset}\' and \'${r.declaration.dataset}\'). A selection carries field references, which mean nothing outside the dataset that resolved them.`,e.name);let i=new q(e,r);if(this._crossFilters.some(s=>s.id===i.id))throw new u(`Cross-filter \'${i.id}\' is already declared.`,e.name);return this._crossFilters.push(i),this.notify(),i}get selection(){return this._selection}get appliedSelection(){return this._appliedSelection}clearSelection(){this._selection&&(this._selection=void 0,this.notify())}setTimezone(e){this._timezone=e,this.notify()}get timezone(){return this._timezone}datasetIndex(e,r){return Le(this.datasets,e,r)}mappingsTo(e){return this._mappings.filter(r=>r.to.name===e)}selectionExpressionFor(e,r){return this.selectionFor(e,r)?.expression}selectionFor(e,r){let i=r==="pending"?this._selection:this._appliedSelection;return!i||i.source===e?void 0:this._crossFilters.some(l=>l.from.name===i.source&&l.to.name===e)?i:void 0}selectionConditionsFor(e,r){let i=r==="pending"?this._selection:this._appliedSelection;return!i||i.source===e?he:this._crossFilters.some(l=>l.from.name===i.source&&l.to.name===e)?i.conditions:he}drillTransformations(e){let r={};return this._mappings.forEach(i=>{if(i.to!==e)return;let s=i.from.appliedCondition;if(s?.operator!=="transform_date_drill")return;let[l]=s.values??[];typeof l=="string"&&(r[i.field]=l)}),r}select(e,r,i){if(this._queries.get(e.name)!==e)throw new u(`Query \'${e.name}\' belongs to a different app.`,e.name);let s=Ze(e,r,i,this.drillTransformations(e));s?.lossy&&console.warn(`[anfra-sdk] The selection in \'${e.name}\' filters more broadly than it was made. Its conditions are combined field by field and ANDed, which cannot express "(A and B) or (C and D)", so the targets will also show combinations that were not selected. Select within one dimension, or narrow with \\`fields\\`, to avoid this.`),this._selection=s,this.notify()}get hasChanges(){return[...this._controls.values()].some(e=>e.isDirty)||this.isSelectionDirty}get isSelectionDirty(){return this.selectionCommitted?nt(this._selection)!==nt(this._appliedSelection):!1}async execute(e={}){let r=[...this._queries.values()].filter(a=>a.shouldRun(e.force));this._controls.forEach(a=>a.commit()),this._appliedSelection=this._selection,this.selectionCommitted=!0,r.forEach(a=>{a.controller?.abort(),a.resetPage()});let i={backend:this.backend,timezone:this._timezone,bustCache:e.bustCache},s=[],l=[];return await Promise.all(r.map(async a=>{let d=new AbortController;a.controller=d;let p=a.signature();a.markExecuting();try{let g=await ue(a,this.mappingsTo(a.name),{conditions:this.selectionConditionsFor(a.name,"applied"),expression:this.selectionExpressionFor(a.name,"applied")},i,d.signal);if(et(a,d))return;a.markSuccess(g,p,!1),s.push(a.name)}catch(g){if(et(a,d)||ge(g))return;a.markError(rt(g,a.name)),l.push(a.name)}finally{a.controller===d&&(a.controller=void 0)}})),{succeeded:s,failed:l}}async refresh(){return this.execute({force:!0,bustCache:!0})}abort(){this._queries.forEach(e=>e.abort())}async fetchPage(e){let r=new AbortController;e.controller=r;let i=e.signature();e.markExecuting();try{let s=await ue(e,this.mappingsTo(e.name),{conditions:this.selectionConditionsFor(e.name,"applied"),expression:this.selectionExpressionFor(e.name,"applied")},{backend:this.backend,timezone:this._timezone},r.signal);e.markSuccess(s,i,!0)}catch(s){if(e.rewindPage(),ge(s))return;let l=rt(s,e.name);throw e.markError(l),l}finally{e.controller===r&&(e.controller=void 0)}}async exportQuery(e,r,i){let s=je(e,this.mappingsTo(e.name),{conditions:this.selectionConditionsFor(e.name,"applied"),expression:this.selectionExpressionFor(e.name,"applied")},{backend:this.backend,timezone:this._timezone,title:this.title},r);try{return await i(s,r.signal??new AbortController().signal)}catch(l){throw ge(l)?l:en(l,e.name)}}toJSON(){let e=o(r=>Object.fromEntries([...this._controls.entries()].filter(([,i])=>i.kind===r).map(([i,s])=>[i,s.toJSON()])),"byKind");return{...this.title?{title:this.title}:{},...this._timezone?{timezone:this._timezone}:{},queries:Object.fromEntries([...this._queries.entries()].map(([r,i])=>[r,i.toJSON()])),filters:e("filter"),dateDrills:e("dateDrill"),mappings:[...this._mappings.map(r=>r.toJSON()),...this._crossFilters.map(r=>r.toJSON())]}}toInspectJSON(){return{...this.title?{title:this.title}:{},...this._timezone?{timezone:this._timezone}:{},hasChanges:this.hasChanges,declaration:this.toJSON(),queries:Object.fromEntries([...this._queries.entries()].map(([e,r])=>[e,Xt(r)])),controls:Object.fromEntries([...this._controls.entries()].map(([e,r])=>[e,Zt(r)])),...this._selection?{selection:tt(this._selection)}:{},...this._appliedSelection?{appliedSelection:tt(this._appliedSelection)}:{}}}locate(e,r){let i=globalThis.document;if(!i)return!1;let s=Te(i,e,this.index,r);return s.length?(Ie(s[0]),V(i).flash(s,{kind:e,name:r,...s.length>1?{note:`in ${s.length} places`}:{}}),!0):!1}assertNameFree(e,r){ze([...this._queries.keys(),...this._controls.keys()],e,r)}soleDataset(e,r){if(!r)return;let i=Object.keys(this.datasets);if(i.length===1)return this.datasets[i[0]];throw new u(i.length?`Filter \'${e}\' names a field but the environment has ${i.length} datasets. Say which one: ${i.join(", ")}.`:`Filter \'${e}\' names a field but the environment has no datasets.`,e)}assertAcyclic(e){let r=[...this._mappings,e],i=new Map;r.forEach(d=>{let p=d.from.name;i.set(p,[...i.get(p)??[],d.to.name])});let s=new Set,l=new Set,a=o(d=>{if(s.has(d))return!0;if(l.has(d))return!1;s.add(d);let p=(i.get(d)??[]).some(a);return s.delete(d),l.add(d),p},"walk");if([...i.keys()].some(a))throw new u(`Mapping \'${e.id}\' would make the app\'s mappings cyclic.`,e.from.name)}};o(ye,"App");var K=ye;var it="0.13.5";var xe=class xe{constructor(n){c(this,"list");this.list=Object.freeze(n.map(({name:e,version:r})=>Object.freeze({name:e,version:r})))}has(n){return this.list.some(e=>e.name===n)}version(n){return this.list.find(e=>e.name===n)?.version}};o(xe,"InstalledPlugins");var be=xe,nn=it,ke=class ke{constructor(n){c(this,"version",nn);c(this,"_apps",[]);c(this,"datasets");c(this,"user");c(this,"indices");c(this,"backend");c(this,"plugins");c(this,"gates");c(this,"deprecatedFeatures");c(this,"extensions",{query:new Map,control:new Map});if(!n?.datasets)throw new u("No datasets provided. The host must call createSdk({ datasets }) before an app can be declared.");if(!n.user)throw new u("No user provided. The host must call createSdk({ user }) before an app can be declared.");if(!n.backend)throw new u("No backend provided. The host must call createSdk({ backend }) before an app can run a query.");this.datasets=Object.freeze({...n.datasets}),this.user=Object.freeze({...n.user,permissions:Object.freeze({...n.user.permissions})}),this.indices=Object.fromEntries(Object.entries(n.datasets).map(([e,r])=>[e,new G(r)])),this.backend=n.backend,this.gates=Object.freeze({...n.features}),this.plugins=new be(n.plugins??[])}get features(){return this.deprecatedFeatures||(console.warn("anfra: Anfra.features is deprecated and will be removed. Check Anfra.plugins.has(\'export\'), Anfra.plugins.has(\'render\') or Anfra.plugins.has(\'lineage\') instead."),this.deprecatedFeatures=Object.freeze({...this.gates,export:this.plugins.has("export"),render:this.plugins.has("render"),lineage:this.plugins.has("lineage")})),this.deprecatedFeatures}createApp(n={}){let e=new K(n,this.indices,this.backend,this.gates,this.extensions);return e.index=this._apps.length,this._apps.push(e),e}get apps(){return this._apps}};o(ke,"Sdk");var we=ke;function ot(t){return new we(t)}o(ot,"createSdk");var B="Anfra";function st(t,n=globalThis){let e=n[B],r=B in n;return n[B]=t,()=>{r?n[B]=e:delete n[B]}}o(st,"installSandbox");function at(t,n=[]){let e=t.document.getElementById(Se);if(!e?.textContent)throw new Error("anfra: this frame was not provisioned by a host.");let r=JSON.parse(e.textContent),i=o(m=>t.parent.postMessage(m,r.hostOrigin),"post"),s=new Map,l=new Map,a=Ae(i,{answer:o(async(m,y,f)=>{let b=s.get(m);if(!b)throw new C(`Nothing in this frame answers \'${m}\'.`);return b(y,f)},"answer"),event:o((m,y)=>{l.get(m)?.forEach(f=>{try{f(y)}catch{}})},"event")}),d=o(m=>m.source===t.parent||!!r.hostOrigin&&r.hostOrigin!=="null"&&m.origin===r.hostOrigin,"fromHost");t.addEventListener("message",m=>{d(m)&&a.receive(m.data)});let p={submitQuery:o((m,y)=>a.call("core.submitQuery",m,y).then(f=>(f.debug?.executedAt&&(f.debug.executedAt=new Date(f.debug.executedAt)),f)),"submitQuery"),fieldSuggestions:o((m,y)=>a.call("core.fieldSuggestions",m,y),"fieldSuggestions")},g=ot({datasets:r.datasets,user:r.user,backend:p,plugins:r.plugins??[]}),x=new Set,h=g.createApp.bind(g);g.createApp=m=>{let y=h(m);return x.forEach(f=>{try{f(y)}catch{}}),y};let E={window:t,sdk:g,endpoint:a,handlers:s,listeners:l,appListeners:x};for(let[m,y]of n)if(typeof y=="function")try{y(Be(m,E,{Query:T,Control:O}))}catch(f){t.console?.error(`anfra: plugin \'${m}\' failed to set up:`,f)}st(g,t),i({type:"anfra:ready"})}o(at,"bootstrap");return ht(rn);})();\n';
20
20
 
21
21
  // src/host/frameScript.ts
22
22
  function builtFrameScript() {
package/dist/plugins.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-TQ7S5DRE.js";
4
4
  import {
5
5
  version
6
- } from "./chunk-7KEYWCZZ.js";
6
+ } from "./chunk-OJ5WIKWE.js";
7
7
  import {
8
8
  ValidationError
9
9
  } from "./chunk-KCTLO3CO.js";
package/dist/testing.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  bootstrap
3
- } from "./chunk-Q5PSFCLL.js";
3
+ } from "./chunk-KI5CAVAR.js";
4
4
  import "./chunk-XIUFHRZE.js";
5
5
  import {
6
6
  createEndpoint
@@ -8,7 +8,7 @@ import {
8
8
  import {
9
9
  PROVISION_ELEMENT_ID
10
10
  } from "./chunk-33B2D4U5.js";
11
- import "./chunk-7KEYWCZZ.js";
11
+ import "./chunk-OJ5WIKWE.js";
12
12
  import "./chunk-KCTLO3CO.js";
13
13
  import "./chunk-PKBMQBKP.js";
14
14
 
@@ -779,6 +779,16 @@ interface components {
779
779
  max_rows?: number;
780
780
  };
781
781
  SearchInput: {
782
+ /**
783
+ * Format: int64
784
+ * @description at most this many entities; absent, 50
785
+ */
786
+ limit?: number;
787
+ /**
788
+ * Format: int64
789
+ * @description skip this many entities first, to page with limit
790
+ */
791
+ offset?: number;
782
792
  /** @description search query */
783
793
  query?: string[];
784
794
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holistics/anfra-sdk",
3
- "version": "0.13.3",
3
+ "version": "0.13.5",
4
4
  "description": "Data Apps on anfra: the authoring layer (app), what hosts one (host), anfra's plugins (plugins), the core API client (api), and their shared contract (common)",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {