react-semaphor 0.1.443 → 0.1.445
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/CHANGELOG.md +7 -0
- package/dist/analytics-protocol/index.cjs +1 -1
- package/dist/analytics-protocol/index.js +123 -107
- package/dist/appearance/index.cjs +1 -1
- package/dist/brand-studio/index.cjs +2 -2
- package/dist/brand-studio/index.js +5 -4
- package/dist/briefings/index.cjs +1 -1
- package/dist/briefings/index.js +526 -457
- package/dist/chunks/analyze-result-contract-BHb7sUUW.cjs +1 -0
- package/dist/chunks/analyze-result-contract-DUv3QnMl.js +29 -0
- package/dist/chunks/{braces-CbO-aIwH.js → braces-BKimshER.cjs} +1 -1
- package/dist/chunks/{code-editor-BpADiIlq.js → code-editor-B4gTfvc5.js} +6800 -6560
- package/dist/chunks/code-editor-BYVorgOf.cjs +138 -0
- package/dist/chunks/common-types-CQ6SHfLk.cjs +1 -0
- package/dist/chunks/{common-types-ClkOI-3O.js → common-types-DFsDdpH7.js} +22 -21
- package/dist/chunks/dashboard-CAiwJW3L.cjs +1397 -0
- package/dist/chunks/{dashboard-briefing-launcher-C60n8LqW.js → dashboard-briefing-launcher-2SLNOaTg.js} +26 -24
- package/dist/chunks/{dashboard-briefing-launcher-BYMLjZxG.js → dashboard-briefing-launcher-CHwjpUYz.cjs} +2 -2
- package/dist/chunks/{dashboard-controls-ti9Rcel2.js → dashboard-controls-BfL14aqO.js} +11 -9
- package/dist/chunks/{dashboard-controls-BH_fZYDU.js → dashboard-controls-BgGTg4yw.cjs} +2 -2
- package/dist/chunks/dashboard-date-comparison-definition-DZq0htjG.cjs +1 -0
- package/dist/chunks/dashboard-json-BOv8tCa9.cjs +1 -0
- package/dist/chunks/{dashboard-json-Bturr634.js → dashboard-json-BZwq3EcS.js} +14 -12
- package/dist/chunks/{dashboard-Bd1Quco-.js → dashboard-u61yfU6u.js} +50081 -47351
- package/dist/chunks/edit-dashboard-visual-BdVCH0DJ.cjs +182 -0
- package/dist/chunks/{edit-dashboard-visual-DglMds57.js → edit-dashboard-visual-njLPYip3.js} +6825 -6656
- package/dist/chunks/{editor-action-buttons-CRi0fhVW.js → editor-action-buttons-BhLX5Q6m.js} +24 -23
- package/dist/chunks/{editor-action-buttons-Cxo7_tNG.js → editor-action-buttons-CBVMFipA.cjs} +1 -1
- package/dist/chunks/{index-D7KJindZ.js → format-types-CSv0V7mm.cjs} +1 -1
- package/dist/chunks/{index-CnujJ3fa.js → format-types-CZH5w1lo.js} +23 -17
- package/dist/chunks/{layout-grid-B08pP7v6.js → layout-grid-3-HWzEwU.cjs} +1 -1
- package/dist/chunks/{metric-comparison-CPoDx56y.js → metric-comparison-BJ_Qu1ZF.js} +1 -1
- package/dist/chunks/metric-comparison-CUAJ8n4y.cjs +1 -0
- package/dist/chunks/{palette-C0yjT5Tv.js → palette-DW_l7Jr0.cjs} +1 -1
- package/dist/chunks/pivot-result-identity-B6QCWOSi.js +94 -0
- package/dist/chunks/pivot-result-identity-CDLRT-YG.cjs +1 -0
- package/dist/chunks/pivot-result-lifecycle-BM3Pl-D1.js +914 -0
- package/dist/chunks/pivot-result-lifecycle-DPc0ANwk.cjs +4 -0
- package/dist/chunks/presentation-execution-BTV-Q43g.cjs +1 -0
- package/dist/chunks/presentation-execution-CGlb7YZ6.js +637 -0
- package/dist/chunks/{report-preferences-dialog-TtwdAuNn.js → report-preferences-dialog-D_NJu2wU.js} +7 -6
- package/dist/chunks/report-preferences-dialog-r8QzOSFb.cjs +1 -0
- package/dist/chunks/report-runtime-context-C8LZFsqV.cjs +1 -0
- package/dist/chunks/report-runtime-context-Qzn11HQe.js +387 -0
- package/dist/chunks/{save-Xdc4pnys.js → save-4_uMnE6s.cjs} +1 -1
- package/dist/chunks/{search-Dcud9ajy.js → search-6ZmeMq55.cjs} +1 -1
- package/dist/chunks/temporal-bucket-BnPxGrAi.js +446 -0
- package/dist/chunks/temporal-bucket-authoring-BUZMuVca.js +205 -0
- package/dist/chunks/temporal-bucket-authoring-CPTwHzvs.cjs +1 -0
- package/dist/chunks/temporal-bucket-contract-B2bJ1oe4.js +108 -0
- package/dist/chunks/temporal-bucket-contract-ChDBWX8I.cjs +1 -0
- package/dist/chunks/temporal-bucket-pMnV-4Nj.cjs +1 -0
- package/dist/chunks/{comparison-document-migration-Dj6xZMCb.js → temporal-result-owner-Cb27SSG9.js} +152 -123
- package/dist/chunks/temporal-result-owner-f6-i65Fb.cjs +1 -0
- package/dist/chunks/token-types-BdQ8kHBm.cjs +1 -0
- package/dist/chunks/token-types-DLo91nOf.js +8 -0
- package/dist/chunks/{update-policy-DnF_74zC.js → update-policy-BxvYMYz0.cjs} +1 -1
- package/dist/chunks/{update-policy-De2NswtM.js → update-policy-eg59mQqv.js} +1 -1
- package/dist/chunks/validators-9D4KBqKD.cjs +1 -0
- package/dist/chunks/validators-wZ2WlNHc.js +4640 -0
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +2 -2
- package/dist/dashboard-authoring/index.cjs +3 -3
- package/dist/dashboard-authoring/index.js +136 -126
- package/dist/data-app-builder/index.cjs +1 -1
- package/dist/data-app-builder/index.js +2 -2
- package/dist/data-app-codegen/index.cjs +1 -1
- package/dist/data-app-codegen/index.js +2 -2
- package/dist/data-app-codegen-node/index.cjs +1 -1
- package/dist/data-app-codegen-node/index.js +3 -3
- package/dist/data-app-sdk/index.cjs +2 -2
- package/dist/data-app-sdk/index.js +34 -35
- package/dist/data-app-sdk-adapters/index.cjs +1 -1
- package/dist/data-app-sdk-adapters/index.js +5 -5
- package/dist/data-app-sdk-validation/index.cjs +1 -1
- package/dist/data-app-sdk-validation/index.js +9 -10
- package/dist/format-utils/index.cjs +3 -3
- package/dist/format-utils/index.js +155 -176
- package/dist/index.cjs +1 -1
- package/dist/index.js +180 -174
- package/dist/report-runtime-context/index.cjs +1 -1
- package/dist/report-runtime-context/index.js +7 -392
- package/dist/shared/index.cjs +1 -1
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +3 -3
- package/dist/types/analytics-protocol.d.ts +257 -48
- package/dist/types/briefings.d.ts +138 -50
- package/dist/types/dashboard-assistant.d.ts +207 -52
- package/dist/types/dashboard-authoring.d.ts +182 -50
- package/dist/types/dashboard.d.ts +290 -48
- package/dist/types/data-app-builder.d.ts +48 -42
- package/dist/types/data-app-codegen-node.d.ts +50 -44
- package/dist/types/data-app-codegen.d.ts +50 -44
- package/dist/types/data-app-sdk-adapters.d.ts +48 -42
- package/dist/types/data-app-sdk-validation.d.ts +81 -43
- package/dist/types/data-app-sdk.d.ts +83 -45
- package/dist/types/format-utils.d.ts +645 -67
- package/dist/types/index.cjs +1 -1
- package/dist/types/index.js +19 -19
- package/dist/types/main.d.ts +298 -94
- package/dist/types/report-runtime-context.d.ts +3 -0
- package/dist/types/shared.d.ts +116 -41
- package/dist/types/surfboard.d.ts +290 -48
- package/dist/types/types.d.ts +455 -65
- package/package.json +3 -1
- package/dist/chunks/analyze-result-contract-BswhsmWT.js +0 -1
- package/dist/chunks/analyze-result-contract-CfOBEwaC.js +0 -1998
- package/dist/chunks/code-editor-M7HTUhdF.js +0 -138
- package/dist/chunks/common-types-C73-Ud1-.js +0 -1
- package/dist/chunks/comparison-document-migration-DbU_BTxR.js +0 -1
- package/dist/chunks/csv-utils-BZDvO2Fw.js +0 -376
- package/dist/chunks/csv-utils-Co0WxHke.js +0 -4
- package/dist/chunks/dashboard-cB3xmTNn.js +0 -1402
- package/dist/chunks/dashboard-date-comparison-definition-DGZr3m-b.js +0 -1
- package/dist/chunks/dashboard-json-Dw_55vSZ.js +0 -1
- package/dist/chunks/edit-dashboard-visual-BUc3NBQ4.js +0 -182
- package/dist/chunks/metric-comparison-DVy3fll_.js +0 -1
- package/dist/chunks/numeric-presentation-BJs5lSar.js +0 -517
- package/dist/chunks/numeric-presentation-Dlb-Dk4c.js +0 -1
- package/dist/chunks/report-preferences-dialog-CCvFqH4Q.js +0 -1
- package/dist/chunks/source-identity-5OPV4gvg.js +0 -92
- package/dist/chunks/source-identity-Cbo2LOHQ.js +0 -1
- package/dist/chunks/validators-B2vUAqTf.js +0 -1
- package/dist/chunks/validators-Bce_J7Vd.js +0 -2448
- /package/dist/chunks/{card-config-utils-15sRtebL.js → card-config-utils-15sRtebL.cjs} +0 -0
- /package/dist/chunks/{catalog-field-grounding-Bnx-3tE0.js → catalog-field-grounding-Bnx-3tE0.cjs} +0 -0
- /package/dist/chunks/{dashboard-input-contract-DV3cshjz.js → dashboard-input-contract-DV3cshjz.cjs} +0 -0
- /package/dist/chunks/{index-Dpm_VET4.js → index-Dpm_VET4.cjs} +0 -0
- /package/dist/chunks/{index-jSrCwPQz.js → index-jSrCwPQz.cjs} +0 -0
- /package/dist/chunks/{normalize-dashboard-for-dirty-check-BXRUMVb2.js → normalize-dashboard-for-dirty-check-BXRUMVb2.cjs} +0 -0
- /package/dist/chunks/{operators-DrTQsJXv.js → operators-DrTQsJXv.cjs} +0 -0
- /package/dist/chunks/{use-debounced-dirty-check-XHSwAefL.js → use-debounced-dirty-check-XHSwAefL.cjs} +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { t as i, T as l, d as u } from "./validators-wZ2WlNHc.js";
|
|
2
|
+
function c(e) {
|
|
3
|
+
const r = i.safeParse(e);
|
|
4
|
+
return r.success ? { ok: !0, value: r.data } : {
|
|
5
|
+
ok: !1,
|
|
6
|
+
error: {
|
|
7
|
+
code: l.invalidMetadata,
|
|
8
|
+
message: "Temporal bucket metadata is invalid.",
|
|
9
|
+
path: "temporalBucket"
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function s(e, r) {
|
|
14
|
+
if (!e.temporalBucket)
|
|
15
|
+
return r.metadataRequired ? {
|
|
16
|
+
ok: !1,
|
|
17
|
+
error: {
|
|
18
|
+
code: l.missingMetadata,
|
|
19
|
+
message: "Activated temporal bucket result is missing metadata.",
|
|
20
|
+
path: "temporalBucket"
|
|
21
|
+
}
|
|
22
|
+
} : { ok: !0 };
|
|
23
|
+
const t = c(
|
|
24
|
+
e.temporalBucket
|
|
25
|
+
);
|
|
26
|
+
if (!t.ok || !t.value)
|
|
27
|
+
return t;
|
|
28
|
+
const a = u(
|
|
29
|
+
t.value.granularity
|
|
30
|
+
);
|
|
31
|
+
return e.dataType !== a ? {
|
|
32
|
+
ok: !1,
|
|
33
|
+
error: {
|
|
34
|
+
code: l.invalidMetadata,
|
|
35
|
+
message: `${t.value.granularity} temporal buckets require dataType ${a}.`,
|
|
36
|
+
path: "dataType"
|
|
37
|
+
}
|
|
38
|
+
} : t;
|
|
39
|
+
}
|
|
40
|
+
function d(e, r) {
|
|
41
|
+
var t, a, o, n;
|
|
42
|
+
return e.granularity === r.granularity && e.calendar.tz === r.calendar.tz && e.calendar.weekStart === r.calendar.weekStart && ((t = e.calendar.fiscalCalendar) == null ? void 0 : t.kind) === ((a = r.calendar.fiscalCalendar) == null ? void 0 : a.kind) && ((o = e.calendar.fiscalCalendar) == null ? void 0 : o.yearStartMonth) === ((n = r.calendar.fiscalCalendar) == null ? void 0 : n.yearStartMonth);
|
|
43
|
+
}
|
|
44
|
+
function k(e, r) {
|
|
45
|
+
const t = /* @__PURE__ */ new Map();
|
|
46
|
+
for (const a of e) {
|
|
47
|
+
if (t.has(a.key))
|
|
48
|
+
return {
|
|
49
|
+
ok: !1,
|
|
50
|
+
error: {
|
|
51
|
+
code: l.invalidMetadata,
|
|
52
|
+
message: `Canonical result contains duplicate column key "${a.key}".`,
|
|
53
|
+
path: "columns"
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
if (t.set(a.key, a), a.temporalBucket) {
|
|
57
|
+
const o = s(a, {
|
|
58
|
+
metadataRequired: !1
|
|
59
|
+
});
|
|
60
|
+
if (!o.ok)
|
|
61
|
+
return {
|
|
62
|
+
ok: !1,
|
|
63
|
+
error: {
|
|
64
|
+
...o.error,
|
|
65
|
+
path: `columns.${a.key}.${o.error.path || "temporalBucket"}`
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
for (const a of r) {
|
|
71
|
+
const o = t.get(a.key);
|
|
72
|
+
if (!o)
|
|
73
|
+
return {
|
|
74
|
+
ok: !1,
|
|
75
|
+
error: {
|
|
76
|
+
code: l.missingMetadata,
|
|
77
|
+
message: `Activated temporal bucket result is missing column "${a.key}".`,
|
|
78
|
+
path: `columns.${a.key}`
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const n = s(o, {
|
|
82
|
+
metadataRequired: !0
|
|
83
|
+
});
|
|
84
|
+
if (!n.ok)
|
|
85
|
+
return {
|
|
86
|
+
ok: !1,
|
|
87
|
+
error: {
|
|
88
|
+
...n.error,
|
|
89
|
+
path: `columns.${a.key}.${n.error.path || "temporalBucket"}`
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
if (!n.value || !d(n.value, a.metadata))
|
|
93
|
+
return {
|
|
94
|
+
ok: !1,
|
|
95
|
+
error: {
|
|
96
|
+
code: l.invalidMetadata,
|
|
97
|
+
message: `Temporal bucket metadata for column "${a.key}" contradicts the governed query context.`,
|
|
98
|
+
path: `columns.${a.key}.temporalBucket`
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return { ok: !0, value: e };
|
|
103
|
+
}
|
|
104
|
+
export {
|
|
105
|
+
k as a,
|
|
106
|
+
s as b,
|
|
107
|
+
c as v
|
|
108
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const n=require("./validators-9D4KBqKD.cjs");function s(e){const r=n.temporalBucketMetadataSchema.safeParse(e);return r.success?{ok:!0,value:r.data}:{ok:!1,error:{code:n.TEMPORAL_BUCKET_CONTRACT_ERROR_CODES.invalidMetadata,message:"Temporal bucket metadata is invalid.",path:"temporalBucket"}}}function u(e,r){if(!e.temporalBucket)return r.metadataRequired?{ok:!1,error:{code:n.TEMPORAL_BUCKET_CONTRACT_ERROR_CODES.missingMetadata,message:"Activated temporal bucket result is missing metadata.",path:"temporalBucket"}}:{ok:!0};const t=s(e.temporalBucket);if(!t.ok||!t.value)return t;const a=n.temporalBucketDataTypeForGrain(t.value.granularity);return e.dataType!==a?{ok:!1,error:{code:n.TEMPORAL_BUCKET_CONTRACT_ERROR_CODES.invalidMetadata,message:`${t.value.granularity} temporal buckets require dataType ${a}.`,path:"dataType"}}:t}function i(e,r){var t,a,o,l;return e.granularity===r.granularity&&e.calendar.tz===r.calendar.tz&&e.calendar.weekStart===r.calendar.weekStart&&((t=e.calendar.fiscalCalendar)==null?void 0:t.kind)===((a=r.calendar.fiscalCalendar)==null?void 0:a.kind)&&((o=e.calendar.fiscalCalendar)==null?void 0:o.yearStartMonth)===((l=r.calendar.fiscalCalendar)==null?void 0:l.yearStartMonth)}function c(e,r){const t=new Map;for(const a of e){if(t.has(a.key))return{ok:!1,error:{code:n.TEMPORAL_BUCKET_CONTRACT_ERROR_CODES.invalidMetadata,message:`Canonical result contains duplicate column key "${a.key}".`,path:"columns"}};if(t.set(a.key,a),a.temporalBucket){const o=u(a,{metadataRequired:!1});if(!o.ok)return{ok:!1,error:{...o.error,path:`columns.${a.key}.${o.error.path||"temporalBucket"}`}}}}for(const a of r){const o=t.get(a.key);if(!o)return{ok:!1,error:{code:n.TEMPORAL_BUCKET_CONTRACT_ERROR_CODES.missingMetadata,message:`Activated temporal bucket result is missing column "${a.key}".`,path:`columns.${a.key}`}};const l=u(o,{metadataRequired:!0});if(!l.ok)return{ok:!1,error:{...l.error,path:`columns.${a.key}.${l.error.path||"temporalBucket"}`}};if(!l.value||!i(l.value,a.metadata))return{ok:!1,error:{code:n.TEMPORAL_BUCKET_CONTRACT_ERROR_CODES.invalidMetadata,message:`Temporal bucket metadata for column "${a.key}" contradicts the governed query context.`,path:`columns.${a.key}.temporalBucket`}}}return{ok:!0,value:e}}exports.validateActivatedTemporalBucketResultColumns=c;exports.validateTemporalBucketMetadata=s;exports.validateTemporalBucketResultColumn=u;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var q=Object.defineProperty;var F=(e,t,r)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var b=(e,t,r)=>F(e,typeof t!="symbol"?t+"":t,r);const w=require("../value-format-preferences/index.cjs"),Y=["YYYY","MMMM","MMM","YY","MM","DD","HH","mm","ss"],O=new Set([" ","-","/",":",".",",","T"]),A={week_of_short:"week",week_of_long:"week",quarter_short:"quarter",quarter_long:"quarter",fiscal_quarter_short:"quarter",fiscal_year:"year"};function E(e){return typeof e=="string"&&Object.prototype.hasOwnProperty.call(A,e)}function N(e,t){return Y.find(r=>e.startsWith(r,t))}function p(e){var a;if(!e||e.trim()!==e)return{ok:!1,code:"invalid_temporal_bucket_pattern",message:"Temporal bucket patterns must be non-empty and trimmed."};const t=[];let r=0,n=!1;for(;r<e.length;){const o=N(e,r);if(o){if(n)return{ok:!1,code:"invalid_temporal_bucket_pattern",message:"Adjacent temporal bucket tokens require a separator."};t.push({kind:"token",value:o}),r+=o.length,n=!0;continue}const u=e[r];if(!O.has(u))return{ok:!1,code:"invalid_temporal_bucket_pattern",message:`Unsupported temporal bucket pattern character "${u}".`};if(t.length===0)return{ok:!1,code:"invalid_temporal_bucket_pattern",message:"Temporal bucket patterns cannot begin with a separator."};const s=t[t.length-1];s.kind==="literal"?s.value+=u:t.push({kind:"literal",value:u}),r+=1,n=!1}return((a=t[t.length-1])==null?void 0:a.kind)!=="token"?{ok:!1,code:"invalid_temporal_bucket_pattern",message:"Temporal bucket patterns cannot end with a separator."}:{ok:!0,segments:t}}function H(e){return e.flatMap(t=>t.kind==="token"?[t.value]:[])}function g(e,t){return e.filter(r=>t.includes(r)).length===1}function m(e,t){return e.some(r=>t.includes(r))}function R(e){return new Set(e).size!==e.length}function C(e,t){if(R(e))return!1;const r=["YYYY","YY"],n=["MMMM","MMM","MM"],a=["HH","mm","ss"],o=g(e,r),u=g(e,n),s=e.includes("DD"),d=m(e,a);switch(t){case"second":return e.includes("HH")&&e.includes("mm")&&e.includes("ss")&&(!m(e,[...r,...n,"DD"])||o&&u&&s);case"minute":return e.includes("HH")&&e.includes("mm")&&(!m(e,[...r,...n,"DD"])||o&&u&&s);case"hour":return e.includes("HH")&&(!m(e,[...r,...n,"DD"])||o&&u&&s);case"day":case"week":return o&&u&&s&&!d;case"month":return o&&u&&!s&&!d;case"quarter":return!1;case"year":return o&&!u&&!s&&!d}}function y(e,t){if(e.presentation.mode==="auto")return{ok:!0};if(e.presentation.mode==="preset"){const n=A[e.presentation.preset];return n===t?{ok:!0}:{ok:!1,code:"incompatible_temporal_bucket_preset",message:`Preset ${e.presentation.preset} requires ${n} granularity.`}}const r=p(e.presentation.pattern);return r.ok?C(H(r.segments),t)?{ok:!0,segments:r.segments}:{ok:!1,code:"incompatible_temporal_bucket_pattern",message:`Pattern ${e.presentation.pattern} is not compatible with ${t} granularity.`}:r}function x(e,t){if(!(!e||!t))return y(e,t).ok?e:void 0}class i extends Error{constructor(r,n){super(n);b(this,"code");this.name="TemporalBucketContractError",this.code=r}}const j={type:"temporal_bucket",presentation:{mode:"auto"}},P=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],U=["January","February","March","April","May","June","July","August","September","October","November","December"];function h(e){return{ok:!1,error:{code:"invalid_temporal_bucket_value",message:e}}}function z(e){return e%4===0&&(e%100!==0||e%400===0)}function L(e,t){return t===2?z(e)?29:28:[4,6,9,11].includes(t)?30:31}function J(e,t,r){const n=[0,3,2,5,0,3,5,1,4,6,2,4],a=t<3?e-1:e;return(a+Math.floor(a/4)-Math.floor(a/100)+Math.floor(a/400)+n[t-1]+r)%7}function _(e){var t;return(t=e.calendar.fiscalCalendar)==null?void 0:t.yearStartMonth}function K(e,t){return(e-t+12)%12%3===0}function I(e,t){const{granularity:r}=t,n=_(t)??1;switch(r){case"second":return!0;case"minute":return e.second===0;case"hour":return e.minute===0&&e.second===0;case"day":return!0;case"week":return J(e.year,e.month,e.day)===t.calendar.weekStart;case"month":return e.day===1;case"quarter":return e.day===1&&K(e.month,n);case"year":return e.day===1&&e.month===n}}function S(e,t){if(e===null)return{ok:!0,value:null};const r=t.granularity==="second"||t.granularity==="minute"||t.granularity==="hour",n=r?/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})$/.exec(e):/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!n)return h(`Expected ${r?"YYYY-MM-DDTHH:mm:ss":"YYYY-MM-DD"} for ${t.granularity} granularity.`);const a={year:Number(n[1]),month:Number(n[2]),day:Number(n[3]),hour:r?Number(n[4]):0,minute:r?Number(n[5]):0,second:r?Number(n[6]):0};return a.year<1||a.month<1||a.month>12||a.day<1||a.day>L(a.year,a.month)||a.hour>23||a.minute>59||a.second>59?h(`Invalid canonical ${t.granularity} bucket value ${e}.`):I(a,t)?{ok:!0,value:a}:h(`Canonical value ${e} is not aligned to ${t.granularity} granularity and its governed Calendar.`)}function T(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function B(e){if(!T(e))return{ok:!1,issues:[{path:"$",message:"Resolved temporal bucket format must be an object."}]};const t=[],r=new Set(["type","presentation","locale"]);for(const o of Object.keys(e))r.has(o)||t.push({path:o,message:`Unknown property "${o}".`});e.type!=="temporal_bucket"&&t.push({path:"type",message:"Expected temporal_bucket."});const n=e.presentation;if(!T(n))t.push({path:"presentation",message:"Expected a presentation object."});else{const o=n.mode,u=o==="preset"?new Set(["mode","preset"]):o==="pattern"?new Set(["mode","pattern"]):new Set(["mode"]);for(const s of Object.keys(n))u.has(s)||t.push({path:`presentation.${s}`,message:`Unknown property "${s}".`});if(o==="preset")E(n.preset)||t.push({path:"presentation.preset",message:"Expected a supported preset."});else if(o==="pattern")if(typeof n.pattern!="string"||!n.pattern)t.push({path:"presentation.pattern",message:"Expected a non-empty pattern."});else{const s=p(n.pattern);s.ok||t.push({path:"presentation.pattern",message:s.message})}else o!=="auto"&&t.push({path:"presentation.mode",message:"Expected auto, preset, or pattern."})}const a=w.canonicalizeSupportedLocale(e.locale);return a||t.push({path:"locale",message:"Expected a supported base BCP 47 locale."}),t.length>0||!a?{ok:!1,issues:t}:{ok:!0,value:{type:"temporal_bucket",presentation:n,locale:a}}}function G(e,t){const r=!!t.calendar.fiscalCalendar;return e==="fiscal_quarter_short"||e==="fiscal_year"?r:e==="quarter_short"||e==="quarter_long"?!r:!0}function D(e,t){return y(e,t.granularity).ok?e.presentation.mode==="preset"?G(e.presentation.preset,t):!(e.presentation.mode==="pattern"&&t.calendar.fiscalCalendar&&(t.granularity==="quarter"||t.granularity==="year")):!1}function M(e,t){if(!(!e||e.presentation.mode==="auto"))return D(e,t)?e:void 0}function Q(e){var a;const t=w.canonicalizeSupportedLocale(e.locale);if(!t)throw new i("invalid_temporal_bucket_format","Temporal bucket locale must be a supported base BCP 47 locale.");const r=M(e.cardFormat,e.metadata);if(r)return{format:{...r,locale:t},source:"card"};const n=((a=e.semanticFormat)==null?void 0:a.granularity)===e.metadata.granularity?M(e.semanticFormat.format,e.metadata):void 0;return n?{format:{...n,locale:t},source:"semantic"}:{format:{...j,locale:t},source:"automatic"}}function c(e,t=2){return String(e).padStart(t,"0")}function l(e,t,r){if(t==="en-US")return(r==="short"?P:U)[e-1];const n=new Date(Date.UTC(2e3,e-1,15));return new Intl.DateTimeFormat(t,{month:r,timeZone:"UTC"}).format(n)}function V(e,t,r){return t.map(n=>{if(n.kind==="literal")return n.value;switch(n.value){case"YYYY":return c(e.year,4);case"YY":return c(e.year%100);case"MMMM":return l(e.month,r,"long");case"MMM":return l(e.month,r,"short");case"MM":return c(e.month);case"DD":return c(e.day);case"HH":return c(e.hour);case"mm":return c(e.minute);case"ss":return c(e.second)}}).join("")}function $(e,t){return`${e.hour%12||12}:${c(e.minute)}${t?`:${c(e.second)}`:""} ${e.hour<12?"AM":"PM"}`}function k(e){return`${P[e.month-1]} ${e.day}, ${e.year}`}function W(e,t){return Math.floor((e.month-t+12)%12/3)+1}function v(e,t){return t===1||e.month<t?e.year:e.year+1}function Z(e){return e===1?"1st":e===2?"2nd":e===3?"3rd":`${e}th`}function f(e,t,r,n){const a=_(n)??1,o=W(e,a);switch(t){case"week_of_short":return`Week of ${l(e.month,r,"short")} ${e.day}, ${e.year}`;case"week_of_long":return`Week of ${l(e.month,r,"long")} ${e.day}, ${e.year}`;case"quarter_short":return`Q${o} ${e.year}`;case"quarter_long":return`${Z(o)} Quarter ${e.year}`;case"fiscal_quarter_short":return`Q${o} FY${v(e,a)}`;case"fiscal_year":return`FY${v(e,a)}`}}function X(e,t,r){const n=_(t);switch(t.granularity){case"second":return`${k(e)}, ${$(e,!0)}`;case"minute":case"hour":return`${k(e)}, ${$(e,!1)}`;case"day":return k(e);case"week":return f(e,"week_of_short",r,t);case"month":return`${l(e.month,r,"short")} ${e.year}`;case"quarter":return f(e,n?"fiscal_quarter_short":"quarter_short",r,t);case"year":return n?f(e,"fiscal_year",r,t):String(e.year)}}function ee(e){const t=B(e.format);if(!t.ok||!D(t.value,e.metadata))throw new i("invalid_temporal_bucket_format","Resolved temporal bucket format is invalid or inapplicable to its metadata.");const r=S(e.value,e.metadata);if(!r.ok)throw new i(r.error.code,r.error.message);if(r.value===null)return"(Blank)";const{presentation:n,locale:a}=t.value;if(n.mode==="auto")return X(r.value,e.metadata,a);if(n.mode==="preset")return f(r.value,n.preset,a,e.metadata);const o=p(n.pattern);if(!o.ok)throw new i("invalid_temporal_bucket_format",o.message);return V(r.value,o.segments,a)}exports.TEMPORAL_BUCKET_PATTERN_TOKENS=Y;exports.TemporalBucketContractError=i;exports.formatTemporalBucket=ee;exports.isTemporalBucketPreset=E;exports.parseResolvedTemporalBucketFormat=B;exports.parseTemporalBucketValue=S;exports.resolveApplicableTemporalBucketFormat=x;exports.resolveTemporalBucketPresentation=Q;exports.tokenizeTemporalBucketPattern=p;exports.validateTemporalBucketFormatApplicability=y;
|