react-semaphor 0.1.366 → 0.1.367
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-WGWJOQsV.js → validation-CrUjNWby.js} +1 -1
- package/dist/chunks/{validation-DiCE3_4O.js → validation-DGl8wnTt.js} +1 -1
- package/dist/chunks/validators-Dq5X4mp0.js +1 -0
- package/dist/chunks/{validators-Bxc1OmZK.js → validators-L0xEXtjf.js} +257 -249
- package/dist/dashboard-authoring/index.cjs +3 -3
- package/dist/dashboard-authoring/index.js +200 -193
- package/dist/data-app-sdk/index.cjs +1 -1
- package/dist/data-app-sdk/index.js +400 -271
- package/dist/data-app-sdk-validation/index.cjs +1 -1
- package/dist/data-app-sdk-validation/index.js +2 -2
- package/dist/types/analytics-protocol.d.ts +1 -1
- package/dist/types/dashboard-assistant.d.ts +1 -1
- package/dist/types/dashboard-authoring.d.ts +1 -1
- package/dist/types/data-app-builder.d.ts +1 -1
- package/dist/types/data-app-sdk-validation.d.ts +1 -1
- package/dist/types/data-app-sdk.d.ts +5 -1
- package/dist/types/main.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunks/validators-BxhJ_NtM.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../chunks/validators-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../chunks/validators-Dq5X4mp0.js");require("../chunks/source-identity-C-xaeE_I.js");const e=require("../chunks/validation-DGl8wnTt.js");exports.normalizeSemaphorAnalysisQueryOptions=e.normalizeSemaphorAnalysisQueryOptions;exports.validateSemaphorDataAppHookSpecs=e.validateSemaphorDataAppHookSpecs;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../chunks/validators-
|
|
1
|
+
import "../chunks/validators-L0xEXtjf.js";
|
|
2
2
|
import "../chunks/source-identity-Dj3dryN9.js";
|
|
3
|
-
import { k as e, v as i } from "../chunks/validation-
|
|
3
|
+
import { k as e, v as i } from "../chunks/validation-CrUjNWby.js";
|
|
4
4
|
export {
|
|
5
5
|
e as normalizeSemaphorAnalysisQueryOptions,
|
|
6
6
|
i as validateSemaphorDataAppHookSpecs
|
|
@@ -531,7 +531,7 @@ export declare type SemaphorInputBinding = {
|
|
|
531
531
|
field?: SemaphorFieldRef;
|
|
532
532
|
};
|
|
533
533
|
|
|
534
|
-
export declare type SemaphorInputOperator = '=' | '!=' | 'in' | 'not_in' | 'contains' | 'between' | 'not_between' | '>' | '>=' | '<' | '<=';
|
|
534
|
+
export declare type SemaphorInputOperator = '=' | '!=' | 'in' | 'not_in' | 'contains' | 'not_contains' | 'between' | 'not_between' | '>' | '>=' | '<' | '<=';
|
|
535
535
|
|
|
536
536
|
export declare type SemaphorInputOperatorAlias = 'eq' | 'equals' | 'not_equals' | 'neq' | 'not equal' | 'not equals' | 'not in' | 'like' | 'not_contains' | 'not contains' | 'not_like' | 'not like' | 'not_between' | 'not between';
|
|
537
537
|
|
|
@@ -755,7 +755,7 @@ declare type SemaphorInputBinding = {
|
|
|
755
755
|
field?: SemaphorFieldRef;
|
|
756
756
|
};
|
|
757
757
|
|
|
758
|
-
declare type SemaphorInputOperator = '=' | '!=' | 'in' | 'not_in' | 'contains' | 'between' | 'not_between' | '>' | '>=' | '<' | '<=';
|
|
758
|
+
declare type SemaphorInputOperator = '=' | '!=' | 'in' | 'not_in' | 'contains' | 'not_contains' | 'between' | 'not_between' | '>' | '>=' | '<' | '<=';
|
|
759
759
|
|
|
760
760
|
declare type SemaphorInputOptionsIntent = {
|
|
761
761
|
kind: 'inputOptions';
|
|
@@ -1885,7 +1885,7 @@ declare type SemaphorInputBinding = {
|
|
|
1885
1885
|
field?: SemaphorFieldRef;
|
|
1886
1886
|
};
|
|
1887
1887
|
|
|
1888
|
-
declare type SemaphorInputOperator = '=' | '!=' | 'in' | 'not_in' | 'contains' | 'between' | 'not_between' | '>' | '>=' | '<' | '<=';
|
|
1888
|
+
declare type SemaphorInputOperator = '=' | '!=' | 'in' | 'not_in' | 'contains' | 'not_contains' | 'between' | 'not_between' | '>' | '>=' | '<' | '<=';
|
|
1889
1889
|
|
|
1890
1890
|
declare type SemaphorInputOperatorAlias = 'eq' | 'equals' | 'not_equals' | 'neq' | 'not equal' | 'not equals' | 'not in' | 'like' | 'not_contains' | 'not contains' | 'not_like' | 'not like' | 'not_between' | 'not between';
|
|
1891
1891
|
|
|
@@ -596,7 +596,7 @@ declare type SemaphorInputBinding = {
|
|
|
596
596
|
field?: SemaphorFieldRef;
|
|
597
597
|
};
|
|
598
598
|
|
|
599
|
-
declare type SemaphorInputOperator = '=' | '!=' | 'in' | 'not_in' | 'contains' | 'between' | 'not_between' | '>' | '>=' | '<' | '<=';
|
|
599
|
+
declare type SemaphorInputOperator = '=' | '!=' | 'in' | 'not_in' | 'contains' | 'not_contains' | 'between' | 'not_between' | '>' | '>=' | '<' | '<=';
|
|
600
600
|
|
|
601
601
|
declare type SemaphorInputOptionsIntent = {
|
|
602
602
|
kind: 'inputOptions';
|
|
@@ -296,7 +296,7 @@ declare type SemaphorInputHandle<TValue extends SemaphorInputValue = SemaphorInp
|
|
|
296
296
|
toAnalyticsInput(): SemaphorActiveInput<TValue>;
|
|
297
297
|
};
|
|
298
298
|
|
|
299
|
-
declare type SemaphorInputOperator = '=' | '!=' | 'in' | 'not_in' | 'contains' | 'between' | 'not_between' | '>' | '>=' | '<' | '<=';
|
|
299
|
+
declare type SemaphorInputOperator = '=' | '!=' | 'in' | 'not_in' | 'contains' | 'not_contains' | 'between' | 'not_between' | '>' | '>=' | '<' | '<=';
|
|
300
300
|
|
|
301
301
|
declare type SemaphorInputOption = {
|
|
302
302
|
label: string;
|
|
@@ -35,6 +35,8 @@ export declare function createSemaphorQueryExecutor(): SemaphorQueryExecutor;
|
|
|
35
35
|
|
|
36
36
|
export declare function hasSemaphorInputValue(value: unknown): boolean;
|
|
37
37
|
|
|
38
|
+
export declare function normalizeSemaphorAnalysisPayload(payload: SemaphorAnalysisPayload | undefined | null): SemaphorAnalysisPayload;
|
|
39
|
+
|
|
38
40
|
export declare function normalizeSemaphorAnalysisQueryOptions(value: unknown, options?: {
|
|
39
41
|
pathPrefix?: string;
|
|
40
42
|
validateTimezone?: SemaphorAnalysisTimezoneValidator;
|
|
@@ -74,7 +76,9 @@ export declare type SemaphorAnalysisPayload = {
|
|
|
74
76
|
mode?: string;
|
|
75
77
|
data?: Record<string, unknown>;
|
|
76
78
|
resultSets?: Record<string, SemaphorAnalysisResultSet>;
|
|
79
|
+
columns?: SemaphorResultColumn[];
|
|
77
80
|
records?: Array<Record<string, unknown>>;
|
|
81
|
+
rowCount?: number;
|
|
78
82
|
changes?: Array<Record<string, unknown>>;
|
|
79
83
|
drivers?: Array<Record<string, unknown>>;
|
|
80
84
|
largestNegativeChanges?: Array<Record<string, unknown>>;
|
|
@@ -388,7 +392,7 @@ export declare type SemaphorInputHandle<TValue extends SemaphorInputValue = Sema
|
|
|
388
392
|
toAnalyticsInput(): SemaphorActiveInput<TValue>;
|
|
389
393
|
};
|
|
390
394
|
|
|
391
|
-
export declare type SemaphorInputOperator = '=' | '!=' | 'in' | 'not_in' | 'contains' | 'between' | 'not_between' | '>' | '>=' | '<' | '<=';
|
|
395
|
+
export declare type SemaphorInputOperator = '=' | '!=' | 'in' | 'not_in' | 'contains' | 'not_contains' | 'between' | 'not_between' | '>' | '>=' | '<' | '<=';
|
|
392
396
|
|
|
393
397
|
declare type SemaphorInputOperatorAlias = 'eq' | 'equals' | 'not_equals' | 'neq' | 'not equal' | 'not equals' | 'not in' | 'like' | 'not_contains' | 'not contains' | 'not_like' | 'not like' | 'not_between' | 'not between';
|
|
394
398
|
|
package/dist/types/main.d.ts
CHANGED
|
@@ -4457,7 +4457,7 @@ declare type SemaphorInputBinding = {
|
|
|
4457
4457
|
field?: SemaphorFieldRef;
|
|
4458
4458
|
};
|
|
4459
4459
|
|
|
4460
|
-
declare type SemaphorInputOperator = '=' | '!=' | 'in' | 'not_in' | 'contains' | 'between' | 'not_between' | '>' | '>=' | '<' | '<=';
|
|
4460
|
+
declare type SemaphorInputOperator = '=' | '!=' | 'in' | 'not_in' | 'contains' | 'not_contains' | 'between' | 'not_between' | '>' | '>=' | '<' | '<=';
|
|
4461
4461
|
|
|
4462
4462
|
declare type SemaphorInputOptionsIntent = {
|
|
4463
4463
|
kind: 'inputOptions';
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const O=require("./source-identity-C-xaeE_I.js");function q(e){const i=N(e);return B(i)?i:void 0}function N(e){if(typeof e!="string"||e.trim().length===0)return;const i=e.trim().toLowerCase().replace(/_/g," ");switch(i){case"eq":case"equals":case"=":return"=";case"neq":case"not equals":case"not equal":case"!=":return"!=";case"in":return"in";case"not in":return"not_in";case"contains":case"like":return"contains";case"not contains":case"not like":return"not_contains";case"between":return"between";case"not between":return"not_between";case">":case">=":case"<":case"<=":return i;case"is null":return"is_null";case"is not null":return"is_not_null";default:return j(e)?e:void 0}}function B(e){return e==="="||e==="!="||e==="in"||e==="not_in"||e==="contains"||e==="between"||e==="not_between"||e===">"||e===">="||e==="<"||e==="<="}function j(e){return B(e)||e==="not_contains"||e==="is_null"||e==="is_not_null"}function t(e,i,n){return n?{code:e,message:i,path:n}:{code:e,message:i}}function C(e){for(let i=0;i<e.length;i+=1){const n=e[i];if(e.some((r,o)=>o!==i&&x(r,n)))return!1}return!0}function F(e,i){return O.semaphorFieldRefsMatch(e,i)}function x(e,i){return F(e,i)&&y(e)===y(i)}function E(e){return`Metric intent has duplicate metric "${e.name}" with the same aggregate (${y(e)}). Use different aggregates to request both, or remove one entry.`}function U(e,i){return w(e,i).length===1}function P(e,i){return w(e,i).length===1}function w(e,i){return i.filter(r=>G(e,r))}function G(e,i){return L(e,i)?e.source?F(i,e):!0:!1}function L(e,i){return!(i.name!==e.name||e.role!==void 0&&i.role!==void 0&&i.role!==e.role||H(e,i)&&y(i)!==y(e))}function H(e,i){return e.role==="measure"||i.role==="measure"||e.aggregate!==void 0||i.aggregate!==void 0}function y(e){return(e.aggregate||"SUM").toUpperCase()}const V=/^(\d{4})-(\d{2})-(\d{2})$/,Q=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2})$/;function v(e){if(typeof e!="string")return null;const i=e.trim(),n=V.exec(i);if(n){const[,g,S,I]=n;return M(g,S,I)?new Date(Date.UTC(Number(g),Number(S)-1,Number(I))):null}const r=Q.exec(i);if(!r)return null;const[,o,a,s,p,c,l="00",,f]=r;if(!M(o,a,s)||!_(p,0,23)||!_(c,0,59)||!_(l,0,59)||!z(f))return null;const h=new Date(i);return Number.isFinite(h.getTime())?h:null}function M(e,i,n){const r=Number(e),o=Number(i),a=Number(n);if(!Number.isInteger(r)||!Number.isInteger(o)||!Number.isInteger(a)||o<1||o>12)return!1;const s=new Date(Date.UTC(r,o-1,a));return s.getUTCFullYear()===r&&s.getUTCMonth()===o-1&&s.getUTCDate()===a}function _(e,i,n){const r=Number(e);return Number.isInteger(r)&&r>=i&&r<=n}function z(e){if(e==="Z")return!0;const i=/^([+-])(\d{2}):(\d{2})$/.exec(e);return!!(i&&_(i[2],0,23)&&_(i[3],0,59))}function d(e){return typeof e=="string"&&e.trim().length>0}function u(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function $(e){const i=new Set;for(const n of e){if(i.has(n))return n;i.add(n)}return null}const X=new Set(["SUM","COUNT","AVG","MIN","MAX","MEDIAN","DISTINCT"]);function R(e,i,n){if(!e||typeof e!="object"){n.push(t("missing_source","Analytics intent needs a source.",i));return}if(e.kind==="semantic"){d(e.domainId)||n.push(t("missing_semantic_domain","Semantic source needs a domainId.",`${i}.domainId`)),d(e.datasetName)||n.push(t("missing_dataset_name","Semantic source needs a datasetName.",`${i}.datasetName`));return}if(e.kind==="physical"){d(e.connectionId)||n.push(t("missing_connection_id","Physical source needs a connectionId.",`${i}.connectionId`)),d(e.tableName)||n.push(t("missing_table_name","Physical source needs a tableName.",`${i}.tableName`));return}if(e.kind==="sql"){d(e.connectionId)||n.push(t("missing_connection_id","SQL source needs a connectionId.",`${i}.connectionId`));return}n.push(t("invalid_source_kind","Source kind is not supported.",i))}function m(e,i,n,r={}){if(!e||!u(e)){r.required&&n.push(t("missing_field_ref","Field reference needs a name.",i));return}d(e.name)||n.push(t("missing_field_ref","Field reference needs a name.",`${i}.name`)),e.source!==void 0&&R(e.source,`${i}.source`,n),Y(e.aggregate,`${i}.aggregate`,n)}function Y(e,i,n){e!==void 0&&(typeof e!="string"||!X.has(e))&&n.push(t("invalid_aggregate","Field aggregate must be SUM, COUNT, AVG, MIN, MAX, MEDIAN, or DISTINCT.",i))}function Z(e,i){if(e.analysis===void 0)return;if(!u(e.analysis)){i.push(t("invalid_metric_analysis","Metric analysis must be a structured object.","analysis"));return}if(e.analysis.kind!=="period_change"){i.push(t("invalid_metric_analysis","Metric analysis kind is not supported.","analysis.kind"));return}e.dateField||i.push(t("missing_analysis_date_field","Period-change analysis needs a dateField.","dateField")),e.timeGrain||i.push(t("missing_analysis_time_grain","Period-change analysis needs a timeGrain.","timeGrain")),e.analysis.orderBy!==void 0&&e.analysis.orderBy!=="absolute_change"&&e.analysis.orderBy!=="positive_change"&&e.analysis.orderBy!=="negative_change"&&e.analysis.orderBy!=="period"&&i.push(t("invalid_metric_analysis","Period-change analysis orderBy must be absolute_change, positive_change, negative_change, or period.","analysis.orderBy"));const{timeWindow:n}=e.analysis;n!==void 0&&b(n,"analysis.timeWindow",i)}function b(e,i,n){if(!u(e)){n.push(t("invalid_time_window","Time window must be a structured object.",i));return}if(e.kind!==void 0&&e.kind!=="relative"&&e.kind!=="absolute"&&n.push(t("invalid_time_window","Time window kind must be relative or absolute.",`${i}.kind`)),e.kind==="absolute"){if(d(e.start)||n.push(t("invalid_time_window","Absolute time window start must be a non-empty ISO date or timestamp string.",`${i}.start`)),d(e.end)||n.push(t("invalid_time_window","Absolute time window end must be a non-empty ISO date or timestamp string.",`${i}.end`)),d(e.start)&&d(e.end)){const r=v(e.start),o=v(e.end);r||n.push(t("invalid_time_window","Absolute time window start must be a valid ISO date or timestamp.",`${i}.start`)),o||n.push(t("invalid_time_window","Absolute time window end must be a valid ISO date or timestamp.",`${i}.end`)),r&&o&&r.getTime()>o.getTime()&&n.push(t("invalid_time_window","Absolute time window start must be before or equal to end.",i))}return}e.unit!=="second"&&e.unit!=="minute"&&e.unit!=="hour"&&e.unit!=="day"&&e.unit!=="week"&&e.unit!=="month"&&e.unit!=="quarter"&&e.unit!=="year"&&n.push(t("invalid_time_window","Time window unit must be second, minute, hour, day, week, month, quarter, or year.",`${i}.unit`)),(typeof e.value!="number"||!Number.isFinite(e.value)||e.value<=0)&&n.push(t("invalid_time_window","Time window value must be a positive number.",`${i}.value`)),e.anchor!==void 0&&e.anchor!=="now"&&e.anchor!=="latest_available"&&n.push(t("invalid_time_window","Time window anchor must be now or latest_available.",`${i}.anchor`)),e.completeness!==void 0&&e.completeness!=="include_partial"&&e.completeness!=="complete_periods"&&n.push(t("invalid_time_window","Time window completeness must be include_partial or complete_periods.",`${i}.completeness`))}function k(e,i,n){if(e!==void 0){if(!Array.isArray(e)){n.push(t("invalid_analytics_filters","Analytics filters must be an array.",i));return}e.forEach((r,o)=>{var c;const a=`${i}.${o}`;if(!u(r)){n.push(t("invalid_analytics_filter","Analytics filter must be a structured object.",a));return}const s=r;m(s.field,`${a}.field`,n,{required:!0}),s.scope!==void 0&&s.scope!=="row"&&s.scope!=="aggregate"&&n.push(t("invalid_analytics_filter_scope","Analytics filter scope must be row or aggregate.",`${a}.scope`)),s.scope==="aggregate"&&((c=s.field)==null?void 0:c.role)!==void 0&&s.field.role!=="measure"&&n.push(t("invalid_analytics_filter_scope","Aggregate-scope analytics filters must target a measure field.",`${a}.scope`));const p=s.operator==="is_null"||s.operator==="is_not_null";if(s.operator!==void 0&&s.operator!=="="&&s.operator!=="!="&&s.operator!=="in"&&s.operator!=="not_in"&&s.operator!=="contains"&&s.operator!=="not_contains"&&s.operator!=="between"&&s.operator!=="not_between"&&s.operator!==">"&&s.operator!==">="&&s.operator!=="<"&&s.operator!=="<="&&s.operator!=="is_null"&&s.operator!=="is_not_null"&&n.push(t("invalid_analytics_filter_operator","Analytics filter operator is not supported.",`${a}.operator`)),s.values===void 0&&!p&&n.push(t("missing_analytics_filter_value","Analytics filter needs values unless it is a null check.",a)),p&&s.values!==void 0){n.push(t("invalid_analytics_filter_values","Null-check analytics filters must not include values.",`${a}.values`));return}if(s.values!==void 0&&!Array.isArray(s.values)){n.push(t("invalid_analytics_filter_values","Analytics filter values must be an array when provided.",`${a}.values`));return}if(s.values!==void 0){const l=s.values.length;if(s.operator==="between"||s.operator==="not_between"){l!==2&&n.push(t("invalid_analytics_filter_values","Between analytics filters must include exactly two values.",`${a}.values`));return}(s.operator==="contains"||s.operator==="not_contains"||s.operator==="="||s.operator==="!="||s.operator===">"||s.operator===">="||s.operator==="<"||s.operator==="<="||s.operator===void 0)&&l!==1&&n.push(t("invalid_analytics_filter_values","Scalar analytics filters must include exactly one value. Use in/not_in for multiple values.",`${a}.values`))}})}}function A(e){var r;const i=[],n=[];if(!e||typeof e!="object")return{ok:!1,errors:[t("invalid_analytics_intent","Analytics intent must be a structured object.")],warnings:n,repairHints:[{code:"invalid_analytics_intent",recommendedNextStep:"Send one structured analytics intent object with kind, source, and required fields."}]};if(e.version!==void 0&&e.version!==1&&i.push(t("invalid_version","Analytics intent version must be 1.","version")),R(e.source,"source",i),e.kind==="metric"){const o=Array.isArray(e.metrics)?e.metrics.filter(a=>u(a)&&d(a.name)):[];if(!Array.isArray(e.metrics)||e.metrics.length===0?i.push(t("missing_metric","Metric intent needs at least one metric.","metrics")):e.metrics.some(a=>!u(a)||!d(a.name))&&i.push(t("invalid_metric_list","Metric intent metrics must be an array of field references with names.","metrics")),o.forEach((a,s)=>{m(a,`metrics.${s}`,i,{required:!0})}),o.length>0&&!C(o)){const a=o.find((s,p)=>o.some((c,l)=>l!==p&&x(c,s)));a&&i.push(t("duplicate_metric",E(a),"metrics"))}if(u(e.primaryMetric)&&d(e.primaryMetric.name)&&w(e.primaryMetric,o).length>1&&i.push(t("ambiguous_primary_metric","Metric intent primaryMetric must identify exactly one selected metric.","primaryMetric")),e.primaryMetric!==void 0&&(m(e.primaryMetric,"primaryMetric",i,{required:!0}),u(e.primaryMetric)&&d(e.primaryMetric.name)&&o.length>0&&!U(e.primaryMetric,o)&&i.push(t("invalid_primary_metric","Metric intent primaryMetric must match one metric field reference.","primaryMetric"))),e.dimensions!==void 0&&!Array.isArray(e.dimensions)?i.push(t("invalid_metric_dimensions","Metric intent dimensions must be an array of field references.","dimensions")):Array.isArray(e.dimensions)&&e.dimensions.some(a=>!u(a)||!d(a.name))&&i.push(t("invalid_metric_dimensions","Metric intent dimensions must be an array of field references with names.","dimensions")),e.dateField!==void 0&&m(e.dateField,"dateField",i),e.timeWindow!==void 0&&(b(e.timeWindow,"timeWindow",i),e.dateField||i.push(t("missing_time_window_date_field","Metric timeWindow needs a dateField.","dateField"))),k(e.filters,"filters",i),Array.isArray(e.dimensions)&&e.dimensions.forEach((a,s)=>{m(a,`dimensions.${s}`,i)}),e.orderBy!==void 0){if(!u(e.orderBy))i.push(t("invalid_metric_order_by","Metric intent orderBy must be a structured object.","orderBy"));else if(m(e.orderBy.field,"orderBy.field",i,{required:!0}),e.orderBy.direction!=="asc"&&e.orderBy.direction!=="desc"&&i.push(t("invalid_metric_order_direction","Metric intent orderBy direction must be asc or desc.","orderBy.direction")),u(e.orderBy.field)&&d(e.orderBy.field.name)){const a=[...o,...e.timeGrain&&e.dateField&&u(e.dateField)?[e.dateField]:[],...Array.isArray(e.dimensions)?e.dimensions.filter(s=>u(s)&&d(s.name)):[]];a.length>0&&!P(e.orderBy.field,a)&&i.push(t("invalid_metric_order_by","Metric intent orderBy.field must match one selected metric, grouped dateField, or dimension.","orderBy.field"))}}Z(e,i)}else e.kind==="records"?(!Array.isArray(e.fields)||e.fields.length===0?i.push(t("missing_record_fields","Records intent needs at least one field.","fields")):e.fields.some(o=>!u(o)||!d(o.name))&&i.push(t("invalid_record_fields","Records intent fields must be field references with names.","fields")),Array.isArray(e.fields)&&e.fields.forEach((o,a)=>{m(o,`fields.${a}`,i)}),e.dateField!==void 0&&m(e.dateField,"dateField",i),e.timeWindow!==void 0&&(b(e.timeWindow,"timeWindow",i),e.dateField||i.push(t("missing_time_window_date_field","Records timeWindow needs a dateField.","dateField"))),k(e.filters,"filters",i),e.orderBy!==void 0&&(u(e.orderBy)?(m(e.orderBy.field,"orderBy.field",i,{required:!0}),e.orderBy.direction!=="asc"&&e.orderBy.direction!=="desc"&&i.push(t("invalid_record_order_direction","Records intent orderBy direction must be asc or desc.","orderBy.direction"))):i.push(t("invalid_record_order_by","Records intent orderBy must be a structured object.","orderBy")))):e.kind==="inputOptions"?((!e.field||!d(e.field.name))&&i.push(t("missing_input_options_field","Input options intent needs a field.","field")),m(e.field,"field",i,{required:!0})):e.kind==="sql"?(((r=e.source)==null?void 0:r.kind)!=="sql"&&i.push(t("invalid_sql_source","SQL analytics intent must use a SQL execution source.","source")),d(e.sql)||i.push(t("missing_sql","SQL analytics intent needs SQL text.","sql")),Array.isArray(e.fields)&&e.fields.forEach((o,a)=>{m(o,`fields.${a}`,i)})):i.push(t("invalid_analytics_kind","Analytics kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:n,repairHints:K(i)}}function T(e){const i=[],n=[];if(!e||typeof e!="object")return{ok:!1,errors:[t("invalid_operation_intent","Operation intent must be a structured object.")],warnings:n,repairHints:[{code:"invalid_operation_intent",recommendedNextStep:"Send one typed operation intent with version, kind, and required operation fields."}]};if(e.version!==1&&i.push(t("invalid_version","Operation intent version must be 1.","version")),e.kind==="answer_obligations")!Array.isArray(e.obligations)||e.obligations.length===0?i.push(t("missing_obligations","Answer-obligations operation intent needs at least one obligation.","obligations")):e.obligations.forEach((r,o)=>{d(r.id)||i.push(t("missing_obligation_id","Each analytics obligation needs an id.",`obligations.${o}.id`)),d(r.prompt)||i.push(t("missing_obligation_prompt","Each analytics obligation needs a prompt.",`obligations.${o}.prompt`))});else if(e.kind==="dashboard_change"||e.kind==="data_app_change"){if(d(e.instruction)||i.push(t("missing_instruction","Change operation intent needs an instruction.","instruction")),e.analyticsIntent){const r=A(e.analyticsIntent);i.push(...r.errors),n.push(...r.warnings)}}else i.push(t("invalid_operation_kind","Operation intent kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:n,repairHints:D(i)}}function J(e){const i=[],n=[];if(!e||typeof e!="object")return{ok:!1,errors:[t("invalid_recovery_plan","Analytics recovery plan must be a structured object.")],warnings:n,repairHints:[{code:"invalid_recovery_plan",recommendedNextStep:"Return a typed recovery plan with operationIntent and plannedToolCalls."}]};e.version!==1&&i.push(t("invalid_version","Recovery plan version must be 1.","version")),e.kind!=="analytics_recovery_plan"&&i.push(t("invalid_recovery_plan_kind","Recovery plan kind must be analytics_recovery_plan.","kind"));const r=T(e.operationIntent);return i.push(...r.errors),n.push(...r.warnings),Array.isArray(e.plannedToolCalls)||i.push(t("invalid_planned_tool_calls","Recovery plan plannedToolCalls must be an array.","plannedToolCalls")),{ok:i.length===0,errors:i,warnings:n,repairHints:D(i)}}function D(e){return e.map(i=>({code:i.code,recommendedNextStep:i.code==="missing_obligations"?"Normalize the user request into one or more typed analytics obligations before recovery planning.":"Correct the operation/recovery contract shape before planning execution."}))}function K(e){return e.map(i=>{switch(i.code){case"missing_source":return{code:i.code,fieldRole:"source",recommendedNextStep:"Provide a semantic, physical, or SQL source before executing analytics."};case"missing_metric":return{code:i.code,fieldRole:"metric",recommendedNextStep:"Choose one exact metric from the grounded schema candidates."};case"missing_record_fields":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Provide at least one field for the records intent."};case"missing_input_options_field":return{code:i.code,fieldRole:"input",recommendedNextStep:"Provide the exact field whose option values should be listed."};case"missing_sql":return{code:i.code,fieldRole:"sql",recommendedNextStep:"Provide bounded read-only SQL with an explicit outer LIMIT."};case"conflicting_sql":return{code:i.code,fieldRole:"sql",recommendedNextStep:"Use one canonical SQL text location for the intent; prefer top-level sql."};case"missing_semantic_domain":case"missing_dataset_name":case"missing_connection_id":case"missing_table_name":return{code:i.code,fieldRole:"source",recommendedNextStep:"Use grounded catalog metadata to fill the missing source reference."};default:return}}).filter(i=>!!i)}function W(e,i,n,r){if(!e||typeof e!="object"){n.push(t("invalid_view","Dashboard view must be an object.",i));return}if(d(e.title)||n.push(t("missing_view_title","Dashboard view needs a title.",i)),!e.presentation||typeof e.presentation!="object"){n.push(t("missing_presentation","Dashboard view needs a presentation.",`${i}.presentation`));return}if(e.presentation.kind==="text"){d(e.text)||r.push(t("missing_text_content","Text views should include text content.",`${i}.text`));return}if(!e.analytics){n.push(t("missing_view_analytics","Non-text dashboard views need analytics intent.",`${i}.analytics`));return}const o=A(e.analytics);for(const a of o.errors)n.push(t(a.code,a.message,`${i}.analytics${a.path?`.${a.path}`:""}`));for(const a of o.warnings)r.push(t(a.code,a.message,`${i}.analytics${a.path?`.${a.path}`:""}`))}function ee(e){const i=[],n=[];if(!e||typeof e!="object")return{ok:!1,errors:[t("invalid_dashboard_intent","Dashboard intent must be a structured object.")],warnings:n};e.version!==1&&i.push(t("invalid_version","Dashboard intent version must be 1.")),e.kind!=="dashboard"&&i.push(t("invalid_kind","Experience intent kind must be dashboard.")),d(e.title)||i.push(t("missing_title","Dashboard intent needs a title.","title"));const r=Array.isArray(e.inputs)?e.inputs:[],o=$(r.filter(u).map(c=>c.id).filter(c=>typeof c=="string"));o&&i.push(t("duplicate_input_id",`Duplicate input id: ${o}.`,"inputs"));for(const[c,l]of r.entries()){const f=`inputs.${c}`;if(!u(l)){i.push(t("invalid_input","Dashboard input must be an object.",f));continue}d(l.id)||i.push(t("missing_input_id","Input needs an id.",`${f}.id`)),d(l.label)||i.push(t("missing_input_label","Input needs a label.",`${f}.label`)),!l.field||!d(l.field.name)?i.push(t("missing_input_field","Input needs a field.",`${f}.field`)):m(l.field,`${f}.field`,i)}const a=Array.isArray(e.sections)?e.sections:[];a.length===0&&i.push(t("missing_sections","Dashboard intent needs at least one section.","sections"));const s=a.flatMap(c=>c&&typeof c=="object"&&Array.isArray(c.views)?c.views.filter(u).map(l=>l.id).filter(l=>!!l):[]),p=$(s);p&&i.push(t("duplicate_view_id",`Duplicate dashboard view id: ${p}.`,"sections"));for(const[c,l]of a.entries()){const f=`sections.${c}`;if(!l||typeof l!="object"){i.push(t("invalid_section","Dashboard section must be an object.",f));continue}if(d(l.title)||i.push(t("missing_section_title","Dashboard section needs a title.",f)),!Array.isArray(l.views)||l.views.length===0){i.push(t("missing_section_views","Dashboard section needs at least one view.",`${f}.views`));continue}for(const[h,g]of l.views.entries())W(g,`${f}.views.${h}`,i,n)}return{ok:i.length===0,errors:i,warnings:n}}exports.normalizeSemaphorAnalyticsFilterOperator=N;exports.normalizeSemaphorInputOperator=q;exports.parseSemaphorIsoTimeWindowBoundary=v;exports.validateSemaphorAnalyticsIntent=A;exports.validateSemaphorAnalyticsRecoveryPlan=J;exports.validateSemaphorDashboardIntent=ee;exports.validateSemaphorOperationIntent=T;
|