react-semaphor 0.1.369 → 0.1.370
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/analytics-protocol/index.cjs +1 -1
- package/dist/analytics-protocol/index.js +1 -1
- package/dist/chunks/validation-DYL3ArlL.js +1 -0
- package/dist/chunks/{validation-nOPr0mTk.js → validation-PPSpYtVf.js} +304 -207
- package/dist/chunks/validators-CgxWT8UX.js +1 -0
- package/dist/chunks/validators-DBNa-eb1.js +1799 -0
- package/dist/dashboard-authoring/index.cjs +1 -1
- package/dist/dashboard-authoring/index.js +1 -1
- package/dist/data-app-sdk/index.cjs +1 -1
- package/dist/data-app-sdk/index.js +251 -180
- package/dist/data-app-sdk-validation/index.cjs +1 -1
- package/dist/data-app-sdk-validation/index.js +3 -3
- package/dist/types/analytics-protocol.d.ts +451 -2
- package/dist/types/dashboard-assistant.d.ts +448 -2
- package/dist/types/dashboard-authoring.d.ts +159 -1
- package/dist/types/data-app-builder.d.ts +156 -1
- package/dist/types/data-app-sdk-validation.d.ts +470 -3
- package/dist/types/data-app-sdk.d.ts +490 -5
- package/dist/types/main.d.ts +156 -1
- package/package.json +1 -1
- package/dist/chunks/validation-Dsf7PydY.js +0 -1
- package/dist/chunks/validators-CVuWOHYv.js +0 -1032
- package/dist/chunks/validators-oc8qtP4q.js +0 -1
package/dist/types/main.d.ts
CHANGED
|
@@ -4420,7 +4420,7 @@ declare type SemaphorAnalyticsFilterBase = {
|
|
|
4420
4420
|
|
|
4421
4421
|
declare type SemaphorAnalyticsFilterOperator = SemaphorInputOperator | 'not_contains' | 'is_null' | 'is_not_null';
|
|
4422
4422
|
|
|
4423
|
-
declare type SemaphorAnalyticsIntent = SemaphorMetricIntent | SemaphorRecordsIntent | SemaphorInputOptionsIntent | SemaphorSqlIntent;
|
|
4423
|
+
declare type SemaphorAnalyticsIntent = SemaphorMetricIntent | SemaphorRecordsIntent | SemaphorInputOptionsIntent | SemaphorSqlIntent | SemaphorMatrixIntent;
|
|
4424
4424
|
|
|
4425
4425
|
declare type SemaphorAnalyticsNullFilter = SemaphorAnalyticsFilterBase & {
|
|
4426
4426
|
operator: SemaphorAnalyticsNullFilterOperator;
|
|
@@ -4443,6 +4443,14 @@ export declare const SemaphorContextProvider: ({ children, dashboardProps, }: {
|
|
|
4443
4443
|
|
|
4444
4444
|
declare type SemaphorDialect = 'postgres' | 'mysql' | 'mssql' | 'snowflake' | 'clickhouse' | 'bigquery' | 'redshift' | 'duckdb' | 'sqlite' | 'unknown';
|
|
4445
4445
|
|
|
4446
|
+
/**
|
|
4447
|
+
* Explorer-backed table source. This is intentionally distinct from raw SQL:
|
|
4448
|
+
* matrix planning needs stable source metadata, fields, and dialect context.
|
|
4449
|
+
*/
|
|
4450
|
+
declare type SemaphorExplorerSourceRef = Extract<SemaphorSourceRef, {
|
|
4451
|
+
kind: 'physical';
|
|
4452
|
+
}>;
|
|
4453
|
+
|
|
4446
4454
|
declare type SemaphorFieldRef = {
|
|
4447
4455
|
name: string;
|
|
4448
4456
|
label?: string;
|
|
@@ -4473,6 +4481,149 @@ declare type SemaphorInputOptionsIntent = {
|
|
|
4473
4481
|
limit?: number;
|
|
4474
4482
|
};
|
|
4475
4483
|
|
|
4484
|
+
declare type SemaphorMatrixAxisExpansionOptions = {
|
|
4485
|
+
defaultDepth?: number;
|
|
4486
|
+
lazy?: boolean;
|
|
4487
|
+
expandedPaths?: SemaphorMatrixMemberPathSegment[][];
|
|
4488
|
+
};
|
|
4489
|
+
|
|
4490
|
+
declare type SemaphorMatrixAxisLevel = {
|
|
4491
|
+
id?: string;
|
|
4492
|
+
field: SemaphorFieldRef;
|
|
4493
|
+
grain?: SemaphorTimeGrain;
|
|
4494
|
+
label?: string;
|
|
4495
|
+
subtotal?: boolean | SemaphorMatrixSubtotalOptions;
|
|
4496
|
+
sortBy?: SemaphorMatrixAxisSortRule;
|
|
4497
|
+
};
|
|
4498
|
+
|
|
4499
|
+
declare type SemaphorMatrixAxisSortRule = {
|
|
4500
|
+
direction: 'asc' | 'desc';
|
|
4501
|
+
by: {
|
|
4502
|
+
kind: 'label';
|
|
4503
|
+
} | {
|
|
4504
|
+
kind: 'field';
|
|
4505
|
+
field: SemaphorFieldRef;
|
|
4506
|
+
aggregate?: SemaphorAggregateFunction;
|
|
4507
|
+
};
|
|
4508
|
+
nulls?: 'warehouseDefault' | 'first' | 'last';
|
|
4509
|
+
scope?: 'global' | 'withinParent';
|
|
4510
|
+
};
|
|
4511
|
+
|
|
4512
|
+
declare type SemaphorMatrixDisplayLimitOptions = {
|
|
4513
|
+
rows?: SemaphorMatrixDisplayLimitRule;
|
|
4514
|
+
columns?: SemaphorMatrixDisplayLimitRule;
|
|
4515
|
+
};
|
|
4516
|
+
|
|
4517
|
+
declare type SemaphorMatrixDisplayLimitRule = {
|
|
4518
|
+
limit: number;
|
|
4519
|
+
by?: 'label' | 'value';
|
|
4520
|
+
direction?: 'top' | 'bottom';
|
|
4521
|
+
others?: boolean | {
|
|
4522
|
+
label?: string;
|
|
4523
|
+
};
|
|
4524
|
+
};
|
|
4525
|
+
|
|
4526
|
+
declare type SemaphorMatrixExpansionOptions = {
|
|
4527
|
+
rows?: SemaphorMatrixAxisExpansionOptions;
|
|
4528
|
+
columns?: SemaphorMatrixAxisExpansionOptions;
|
|
4529
|
+
};
|
|
4530
|
+
|
|
4531
|
+
declare type SemaphorMatrixIntent = {
|
|
4532
|
+
kind: 'matrix';
|
|
4533
|
+
version?: SemaphorProtocolVersion;
|
|
4534
|
+
id?: string;
|
|
4535
|
+
label?: string;
|
|
4536
|
+
source: SemaphorMatrixSourceRef;
|
|
4537
|
+
rows: SemaphorMatrixAxisLevel[];
|
|
4538
|
+
columns?: SemaphorMatrixAxisLevel[];
|
|
4539
|
+
values: SemaphorMatrixValueField[];
|
|
4540
|
+
filters?: SemaphorAnalyticsFilter[];
|
|
4541
|
+
inputs?: SemaphorInputBinding[];
|
|
4542
|
+
totals?: SemaphorMatrixTotalOptions;
|
|
4543
|
+
sort?: SemaphorMatrixSortRule[];
|
|
4544
|
+
expansion?: SemaphorMatrixExpansionOptions;
|
|
4545
|
+
layout?: SemaphorMatrixLayoutOptions;
|
|
4546
|
+
displayLimits?: SemaphorMatrixDisplayLimitOptions;
|
|
4547
|
+
};
|
|
4548
|
+
|
|
4549
|
+
declare type SemaphorMatrixLayoutOptions = {
|
|
4550
|
+
hierarchy?: 'compact' | 'tabular' | 'outline';
|
|
4551
|
+
valuesPlacement?: 'columns' | 'rows';
|
|
4552
|
+
stickyRowHeaders?: boolean;
|
|
4553
|
+
stickyColumnHeaders?: boolean;
|
|
4554
|
+
};
|
|
4555
|
+
|
|
4556
|
+
declare type SemaphorMatrixMemberPathSegment = {
|
|
4557
|
+
levelId: string;
|
|
4558
|
+
value: unknown;
|
|
4559
|
+
};
|
|
4560
|
+
|
|
4561
|
+
declare type SemaphorMatrixSortRule = {
|
|
4562
|
+
axis: 'row' | 'column';
|
|
4563
|
+
targetId?: string;
|
|
4564
|
+
direction: 'asc' | 'desc';
|
|
4565
|
+
by: {
|
|
4566
|
+
kind: 'label';
|
|
4567
|
+
} | {
|
|
4568
|
+
kind: 'field';
|
|
4569
|
+
field: SemaphorFieldRef;
|
|
4570
|
+
aggregate?: SemaphorAggregateFunction;
|
|
4571
|
+
} | {
|
|
4572
|
+
kind: 'value';
|
|
4573
|
+
valueId: string;
|
|
4574
|
+
rowPath?: SemaphorMatrixMemberPathSegment[];
|
|
4575
|
+
columnPath?: SemaphorMatrixMemberPathSegment[];
|
|
4576
|
+
};
|
|
4577
|
+
nulls?: 'warehouseDefault' | 'first' | 'last';
|
|
4578
|
+
scope?: 'global' | 'withinParent';
|
|
4579
|
+
};
|
|
4580
|
+
|
|
4581
|
+
declare type SemaphorMatrixSourceRef = SemaphorSemanticSourceRef | SemaphorExplorerSourceRef;
|
|
4582
|
+
|
|
4583
|
+
declare type SemaphorMatrixSubtotalOptions = {
|
|
4584
|
+
enabled?: boolean;
|
|
4585
|
+
position?: 'before' | 'after';
|
|
4586
|
+
label?: string;
|
|
4587
|
+
};
|
|
4588
|
+
|
|
4589
|
+
declare type SemaphorMatrixTotalCalculation = {
|
|
4590
|
+
kind: 'defaultAggregate';
|
|
4591
|
+
} | {
|
|
4592
|
+
kind: 'blank';
|
|
4593
|
+
} | {
|
|
4594
|
+
kind: 'labelOnly';
|
|
4595
|
+
label?: string;
|
|
4596
|
+
} | {
|
|
4597
|
+
kind: 'customAggregate';
|
|
4598
|
+
aggregate: SemaphorAggregateFunction;
|
|
4599
|
+
} | {
|
|
4600
|
+
kind: 'percentOfParent';
|
|
4601
|
+
} | {
|
|
4602
|
+
kind: 'percentOfGrandTotal';
|
|
4603
|
+
} | {
|
|
4604
|
+
kind: 'customExpression';
|
|
4605
|
+
expressionId: string;
|
|
4606
|
+
};
|
|
4607
|
+
|
|
4608
|
+
declare type SemaphorMatrixTotalOptions = {
|
|
4609
|
+
rows?: boolean | 'perLevel';
|
|
4610
|
+
columns?: boolean | 'perLevel';
|
|
4611
|
+
grandTotal?: boolean | {
|
|
4612
|
+
rows?: boolean;
|
|
4613
|
+
columns?: boolean;
|
|
4614
|
+
};
|
|
4615
|
+
rowPosition?: 'top' | 'bottom';
|
|
4616
|
+
columnPosition?: 'left' | 'right';
|
|
4617
|
+
};
|
|
4618
|
+
|
|
4619
|
+
declare type SemaphorMatrixValueField = {
|
|
4620
|
+
id?: string;
|
|
4621
|
+
field: SemaphorFieldRef;
|
|
4622
|
+
aggregate?: SemaphorAggregateFunction;
|
|
4623
|
+
label?: string;
|
|
4624
|
+
totalBehavior?: SemaphorMatrixTotalCalculation;
|
|
4625
|
+
};
|
|
4626
|
+
|
|
4476
4627
|
declare type SemaphorMetricAnalysis = {
|
|
4477
4628
|
kind: 'period_change';
|
|
4478
4629
|
orderBy?: 'absolute_change' | 'positive_change' | 'negative_change' | 'period';
|
|
@@ -4547,6 +4698,10 @@ declare type SemaphorRelativeTimeWindow = {
|
|
|
4547
4698
|
completeness?: 'include_partial' | 'complete_periods';
|
|
4548
4699
|
};
|
|
4549
4700
|
|
|
4701
|
+
declare type SemaphorSemanticSourceRef = Extract<SemaphorSourceRef, {
|
|
4702
|
+
kind: 'semantic';
|
|
4703
|
+
}>;
|
|
4704
|
+
|
|
4550
4705
|
declare type SemaphorSourceRef = {
|
|
4551
4706
|
kind: 'semantic';
|
|
4552
4707
|
domainId: string;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const w=require("./validators-oc8qtP4q.js"),u=require("./source-identity-C-xaeE_I.js");function v(e){var t;const r=j(e);return{version:1,kind:"metric",id:e.id,label:e.label,source:S(e),metrics:r,primaryMetric:Q(e,r),dateField:e.dateField?a(e.dateField,"date"):void 0,timeGrain:e.timeGrain,dimensions:(t=e.dimensions)==null?void 0:t.map(o=>a(o,"dimension")),comparison:Z(e.comparison),orderBy:e.orderBy?{field:a(e.orderBy.field),direction:e.orderBy.direction}:void 0,inputs:p(e.inputs),limit:e.limit}}function M(e){var t;return{...v(e),...e.timeWindow?{timeWindow:e.timeWindow}:{},...(t=e.filters)!=null&&t.length?{filters:e.filters}:{},...e.analysis?{analysis:e.analysis}:{}}}function D(e){return{...e.chartTitle?{chartTitle:e.chartTitle}:{},...e.chartType?{chartType:e.chartType}:{},...e.driverMode?{driverMode:e.driverMode}:{},...e.includePopulation!==void 0?{includePopulation:e.includePopulation}:{},...e.calendarContext?{calendarContext:e.calendarContext}:{}}}function Q(e,r){if(!e.primaryMetric)return r[0]||{name:"",role:"measure"};const t=a(e.primaryMetric,"measure"),o=V(t,r),i=o.length===1?o[0]:void 0;return i?_(t,i):t}function j(e){const r=[];for(const t of e.metrics.map(o=>a(o,"measure"))){if(!t.name)continue;const o=r.findIndex(i=>K(i,t));if(o===-1){r.push(t);continue}r[o]=_(r[o],t)}return r}function K(e,r){return u.semaphorFieldRefsMatch(e,r)&&f(e)===f(r)}function E(e,r){return f(r)===f(e)}function N(e,r){return r.name!==e.name||e.source&&!u.semaphorFieldRefsMatch(r,e)?!1:E(e,r)}function V(e,r){const t=r.filter(o=>N(e,o));return e.aggregate!==void 0,t}function f(e){return(e.aggregate||"SUM").toUpperCase()}function _(e,r){if(e.aggregate&&r.aggregate&&e.aggregate!==r.aggregate)throw new Error(`Metric "${e.name}" was requested with conflicting aggregate semantics: ${e.aggregate} and ${r.aggregate}.`);return{...u.preferSemaphorFieldRefMetadata(e,r),aggregate:e.aggregate||r.aggregate}}function C(e){var t;if("sort"in e)throw new Error("semaphor.records supports orderBy for a single deterministic sort. Multiple sort clauses are not supported by the analytics protocol yet.");if(!Y(e))throw new Error("semaphor.records needs at least one field.");const r=W(e.fields);return{version:1,kind:"records",id:e.id,label:e.label,source:S(e),fields:r,dateField:e.dateField?a(e.dateField,"date"):void 0,timeGrain:e.timeGrain,...e.timeWindow?{timeWindow:e.timeWindow}:{},...(t=e.filters)!=null&&t.length?{filters:e.filters}:{},orderBy:e.orderBy?{field:a(e.orderBy.field),direction:e.orderBy.direction}:void 0,inputs:p(e.inputs),limit:e.limit,...e.pagination?{pagination:e.pagination}:{}}}function W(e){return e.map(r=>{const t=a(r);if(!t.role)throw new Error(`semaphor.records field "${t.name}" needs an explicit role.`);return t})}function R(e){return{version:1,kind:"inputOptions",id:e.id,label:e.label,source:S(e),field:a(e.field,"dimension"),search:e.search,limit:e.limit}}function $(e){var r;return{version:1,kind:"sql",id:e.id,label:e.label,source:e.source,sql:e.sql,...e.defaultParameters?{defaultParameters:e.defaultParameters}:{},...e.pythonCode?{pythonCode:e.pythonCode}:{},...(r=e.fields)!=null&&r.length?{fields:e.fields.map(t=>a(t))}:{},inputs:p(e.inputs),limit:e.limit,...e.pagination?{pagination:e.pagination}:{},rationale:e.rationale}}function T(e){if("toAnalyticsInput"in e){const n=e.toAnalyticsInput();return{inputId:n.inputId,kind:n.kind,...n.controlRole?{controlRole:n.controlRole}:{},...n.operator?{operator:n.operator}:{},...n.field?{field:n.field}:{}}}if("id"in e){const n=I(e);return{inputId:n.inputId,kind:n.kind,...n.controlRole?{controlRole:n.controlRole}:{},...n.operator?{operator:n.operator}:{},...n.field?{field:n.field}:{}}}const r="kind"in e?e.kind:void 0,t="operator"in e?F(e.operator,e.inputId):void 0,o="controlRole"in e?e.controlRole:"role"in e?e.role:void 0,i=U(o)?o:void 0;return{inputId:e.inputId,...r?{kind:r}:{},...i?{controlRole:i}:{},...t?{operator:t}:{},...e.field?{field:e.field}:{}}}function U(e){return e==="grain"||e==="metric"||e==="dimension"||e==="aggregation"||e==="sqlParam"}function G(e){const r=p(e);return r.length>0?r:void 0}function P(e){return(e||[]).map(X)}function L(e){return P(e).filter(r=>r.isActive)}function I(e){if(e.kind==="filter"){const r=F(e.operator,e.id);return{inputId:e.id,kind:e.kind,label:e.label,field:a(e.field,"dimension"),operator:r||"in"}}return{inputId:e.id,kind:e.kind,label:e.label,controlRole:e.role}}function J(e=[]){return e.map(r=>typeof r=="object"?r:{label:String(r),value:r})}function h(e){return e==null?!1:Array.isArray(e)?e.length>0:typeof e=="string"?e.trim().length>0:!0}function X(e){if("toAnalyticsInput"in e)return e.toAnalyticsInput();if("kind"in e&&"isActive"in e)return e;if("id"in e){const r=I(e),t=Object.prototype.hasOwnProperty.call(e,"value")?e.value:e.defaultValue;return{inputId:r.inputId,kind:r.kind,label:r.label,...r.field?{field:r.field}:{},...r.operator?{operator:r.operator}:{},...r.controlRole?{controlRole:r.controlRole}:{},value:t,isActive:h(t)}}return{...e,kind:"filter",isActive:h(e.value),value:e.value}}function S(e){return e.source}function Y(e){var r;return!!((r=e.fields)!=null&&r.length)}function a(e,r){return{...e,role:e.role||r}}function p(e){return(e||[]).map(T)}function Z(e){if(e)return e}function F(e,r){if(e===void 0)return;const t=w.normalizeSemaphorInputOperator(e);if(!t)throw new Error(`useSemaphorInput "${r}" uses unsupported filter operator "${e}".`);return t}function H(e,r={}){const t=r.pathPrefix||"analysisOptions";if(e===void 0)return{ok:!0};if(!e||typeof e!="object"||Array.isArray(e))return s(t,"Data App analysis options must be an object.");const o=e,i={};if(o.chartTitle!==void 0){if(typeof o.chartTitle!="string")return s(`${t}.chartTitle`,'Data App analysis option "chartTitle" must be a string.');i.chartTitle=o.chartTitle}if(o.chartType!==void 0){if(typeof o.chartType!="string")return s(`${t}.chartType`,'Data App analysis option "chartType" must be a string.');i.chartType=o.chartType}if(o.driverMode!==void 0){if(!te(o.driverMode))return s(`${t}.driverMode`,'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.');i.driverMode=o.driverMode}if(o.includePopulation!==void 0){if(typeof o.includePopulation!="boolean")return s(`${t}.includePopulation`,'Data App analysis option "includePopulation" must be a boolean.');i.includePopulation=o.includePopulation}if(o.calendarContext!==void 0){const n=oe(o.calendarContext,{pathPrefix:`${t}.calendarContext`,validateTimezone:r.validateTimezone});if(!n.ok)return n;i.calendarContext=n.calendarContext}return{ok:!0,analysisOptions:i}}function ee(e){const r=e.queries.map((i,n)=>re(i,n,{fieldCatalogs:e.fieldCatalogs||[],requireFieldCatalog:!!e.requireFieldCatalog,validateTimezone:e.validateTimezone})),t=r.flatMap(i=>i.diagnostics),o=r.map(i=>i.executionResult);return{ok:t.every(i=>i.severity!=="error"),diagnostics:t,queries:r,intents:r.flatMap(i=>i.intent?[i.intent]:[]),executionResults:o}}function re(e,r,t){const o=`queries.${r}`;try{const i=ne(e),n=he(e,i),d=w.validateSemaphorAnalyticsIntent(i),l=[...ce({querySpec:e,queryId:n,intent:i,pathPrefix:o}),...d.errors.map(y=>q(y,{queryHook:e.queryHook,queryId:n,pathPrefix:o,severity:"error",intent:i})),...d.warnings.map(y=>q(y,{queryHook:e.queryHook,queryId:n,pathPrefix:o,severity:"warning",intent:i})),...se({querySpec:e,queryId:n,intent:i,pathPrefix:o,fieldCatalogs:t.fieldCatalogs,requireFieldCatalog:t.requireFieldCatalog}),...ue({querySpec:e,queryId:n,intent:i,pathPrefix:o,validateTimezone:t.validateTimezone})],c=ye(d,l);return{queryHook:e.queryHook,queryId:n,intent:i,diagnostics:l,executionResult:b({intent:i,validation:c,diagnostics:l})}}catch(i){const n={severity:"error",code:"invalid_query_spec",message:i instanceof Error?i.message:String(i),path:o,queryHook:e.queryHook,queryId:O(e.spec)},d=B([n]);return{queryHook:e.queryHook,queryId:n.queryId,diagnostics:[n],executionResult:b({validation:d,diagnostics:[n]})}}}function s(e,r){return{ok:!1,issues:[{code:"invalid_analysis_option",message:r,path:e}]}}function x(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function te(e){return e==="absolute_delta"||e==="largest_negative"||e==="largest_positive"||e==="positive_and_negative"||e==="all"}function ie(e){return e.trim().length>0&&!Number.isNaN(Date.parse(e))}function oe(e,r){var c;if(!e||typeof e!="object"||Array.isArray(e))return s(r.pathPrefix,'Data App analysis option "calendarContext" must be an object.');const t=e,o=t.tz,i=t.weekStart,n=t.anchor,d=n&&typeof n=="object"&&!Array.isArray(n)?n.iso:void 0,l=typeof o=="string"?((c=r.validateTimezone)==null?void 0:c.call(r,o))??o:null;return l?typeof i!="number"||!Number.isInteger(i)||i<0||i>6?s(`${r.pathPrefix}.weekStart`,'Data App analysis option "calendarContext.weekStart" must be an integer from 0 to 6.'):n!=="now"&&!(typeof d=="string"&&ie(d))?s(`${r.pathPrefix}.anchor`,'Data App analysis option "calendarContext.anchor" must be "now" or an object with a valid iso string.'):{ok:!0,calendarContext:{tz:l,weekStart:i,anchor:n}}:s(`${r.pathPrefix}.tz`,'Data App analysis option "calendarContext.tz" must be a valid timezone string.')}function ne(e){return ae(e.spec)}function ae(e){if(!x(e))throw new Error("useSemaphorQuery spec must be an object.");if(e.queryKind==="metric")return v(e);if(e.queryKind==="analysis")return M(e);if(e.queryKind==="records")return C(e);if(e.queryKind==="sql")return $(e);if(e.queryKind==="inputOptions")return R(e);throw new Error("useSemaphorQuery spec.queryKind must be metric, analysis, records, inputOptions, or sql.")}function se(e){if(e.intent.kind==="sql")return[];if(e.fieldCatalogs.length===0&&!e.requireFieldCatalog)return[];const r=me(e.fieldCatalogs,e.intent.source);return r?[...de({...e,catalog:r}),...le({...e,catalog:r})]:[{severity:"error",code:"invalid_source_ref",message:`Source ref for ${e.querySpec.queryHook} does not match a visible Semaphor source.`,path:`${e.pathPrefix}.spec.source`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}]}function de(e){return fe(e.intent).flatMap(({field:r,path:t})=>z(e.catalog,r,e.intent.source)?[]:[{severity:"error",code:"missing_field",message:`Field "${r.name}" is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.${t}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:m(r,e.intent.source),field:r}])}function le(e){return("inputs"in e.intent?e.intent.inputs||[]:[]).flatMap((t,o)=>{if(!t.field)return[];const i=m(t.field,e.intent.source);return u.semaphorSourcesReferToSameDataset(i,e.intent.source)?z(e.catalog,t.field,e.intent.source)?[]:[{severity:"error",code:"missing_field",message:`Input "${t.inputId}" references field "${t.field.name}", which is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.spec.inputs.${o}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:t.field}]:[{severity:"error",code:"unsupported_input_filter_composition",message:`Input "${t.inputId}" filters a different Semaphor source than the query. Cross-source Data App inputs are not supported yet.`,path:`${e.pathPrefix}.spec.inputs.${o}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:t.field}]})}function ue(e){if(e.querySpec.spec.queryKind!=="analysis")return[];const r=H(e.querySpec.spec,{pathPrefix:`${e.pathPrefix}.spec`,validateTimezone:e.validateTimezone});return r.ok?[]:r.issues.map(t=>({severity:"error",code:t.code,message:t.message,path:t.path,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}))}function ce(e){return e.querySpec.spec.queryKind!=="sql"?[]:x(e.querySpec.spec)?Object.prototype.hasOwnProperty.call(e.querySpec.spec,"parameters")?[{severity:"error",code:"deprecated_sql_parameters",message:"semaphor.sql uses defaultParameters for static SQL param(...) fallback values. The legacy parameters field is not supported.",path:`${e.pathPrefix}.spec.parameters`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id}]:[]:[]}function fe(e){return e.kind==="metric"?[...e.metrics.map((r,t)=>({field:r,path:`spec.metrics.${t}`})),...e.primaryMetric?[{field:e.primaryMetric,path:"spec.primaryMetric"}]:[],...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...(e.dimensions||[]).map((r,t)=>({field:r,path:`spec.dimensions.${t}`})),...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,t)=>({field:r.field,path:`spec.filters.${t}.field`}))]:e.kind==="records"?[...e.fields.map((r,t)=>({field:r,path:`spec.fields.${t}`})),...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,t)=>({field:r.field,path:`spec.filters.${t}.field`}))]:e.kind==="inputOptions"?[{field:e.field,path:"spec.field"}]:[]}function me(e,r){return e.find(t=>g(t,r))}function z(e,r,t){const o=m(r,t);if(g(e,o))return e.fields.find(i=>pe(i,r)&&g(e,m(i,e.source)))}function g(e,r){return[e.source,...e.sourceAliases||[]].some(t=>u.semaphorSourcesReferToSameDataset(t,r))}function m(e,r){return e.source||r}function pe(e,r){return!!(e.name&&r.name&&e.name===r.name)}function q(e,r){return{severity:r.severity,code:e.code||"invalid_analytics_intent",message:e.message,path:e.path?`${r.pathPrefix}.spec.${e.path}`:r.pathPrefix,queryHook:r.queryHook,queryId:r.queryId,intentId:r.intent.id,source:r.intent.source}}function ye(e,r){const t=B(r);return{ok:t.ok&&e.ok,errors:A([...e.errors,...t.errors]),warnings:A([...e.warnings,...t.warnings]),repairHints:[...e.repairHints,...t.repairHints]}}function B(e){const r=e.filter(o=>o.severity==="error").map(k),t=e.filter(o=>o.severity==="warning").map(k);return{ok:r.length===0,errors:r,warnings:t,repairHints:r.map(o=>{var i,n;return{code:o.code,message:o.message,fieldRole:o.fieldRole,invalidField:(i=o.repairHint)==null?void 0:i.invalidField,recommendedNextStep:((n=o.repairHint)==null?void 0:n.recommendedNextStep)||"Update the Data App SDK query spec to use visible Semaphor source and field refs."}})}}function k(e){var r;return{code:e.code,message:e.message,path:e.path,fieldRole:e.code==="invalid_source_ref"?"source":void 0,repairHint:{code:e.code,message:e.message,invalidField:(r=e.field)==null?void 0:r.name,fieldRole:e.code==="invalid_source_ref"?"source":void 0,recommendedNextStep:e.code==="unsupported_input_filter_composition"?"Use an input field from the same Semaphor source as the query, or split the query into separate source-scoped queries.":"Update the query spec to use a visible Semaphor source and field ref."}}}function A(e){const r=new Set;return e.filter(t=>{const o=`${t.code}:${t.path||""}:${t.message}`;return r.has(o)?!1:(r.add(o),!0)})}function b(e){var t,o;const r=e.diagnostics.filter(i=>i.severity==="error");return{intentId:(t=e.intent)==null?void 0:t.id,status:r.length?"failed":"answered",resultShape:(o=e.intent)==null?void 0:o.kind,intent:e.intent,validation:e.validation,coverage:{answeredObligations:r.length?[]:["query_spec_validation"],missingObligations:r.length?["query_spec_validation"]:[],warnings:e.validation.warnings},missingFields:r.filter(i=>i.code==="missing_field").flatMap(i=>{var n;return(n=i.field)!=null&&n.name?[i.field.name]:[]}),warnings:e.diagnostics.filter(i=>i.severity==="warning").map(i=>i.message),metadata:{validationKind:"data_app_sdk_query_spec"}}}function he(e,r){return r.id||O(e.spec)}function O(e){if(!e||typeof e!="object"||!("id"in e))return;const r=e.id;return typeof r=="string"&&r.trim()?r:void 0}exports.hasSemaphorInputValue=h;exports.normalizeSemaphorAnalysisQueryOptions=H;exports.normalizeSemaphorInputOptions=J;exports.toSemaphorActiveInputSnapshots=L;exports.toSemaphorAnalysisIntent=M;exports.toSemaphorAnalysisQueryOptions=D;exports.toSemaphorInputBinding=T;exports.toSemaphorInputBindings=G;exports.toSemaphorInputOptionsIntent=R;exports.toSemaphorInputSnapshots=P;exports.toSemaphorInputSpec=I;exports.toSemaphorMetricIntent=v;exports.toSemaphorRecordsIntent=C;exports.toSemaphorSqlIntent=$;exports.validateSemaphorDataAppQuerySpecs=ee;
|