@oneuptime/common 14.0.91 → 14.0.92

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.
Files changed (90) hide show
  1. package/Models/DatabaseModels/AutoRemediationRule.js +1 -1
  2. package/Models/DatabaseModels/CodeRepository.d.mts +1 -0
  3. package/Models/DatabaseModels/CodeRepository.d.ts +1 -0
  4. package/Models/DatabaseModels/CodeRepository.js +69 -6
  5. package/Types/AI/CodeTask.d.mts +1 -0
  6. package/Types/AI/CodeTask.d.ts +1 -0
  7. package/Types/AI/TelemetryAiActivity.d.mts +1 -0
  8. package/Types/AI/TelemetryAiActivity.d.ts +1 -0
  9. package/Types/AI/TelemetryAiActivity.js +4 -0
  10. package/Types/CodeRepository/CodeRepositorySetting.d.mts +15 -0
  11. package/Types/CodeRepository/CodeRepositorySetting.d.ts +15 -0
  12. package/Types/CodeRepository/CodeRepositorySetting.js +49 -0
  13. package/Types/CodeRepository/CodeRepositorySetting.mjs +3 -0
  14. package/Types/Date.d.mts +10 -0
  15. package/Types/Date.d.ts +10 -0
  16. package/Types/Date.js +385 -98
  17. package/Types/DateLanguage.d.mts +67 -0
  18. package/Types/DateLanguage.d.ts +67 -0
  19. package/Types/DateLanguage.js +478 -0
  20. package/Types/DateLanguage.mjs +21 -0
  21. package/Types/Runner/CodeRepositoryRunner.d.mts +7 -0
  22. package/Types/Runner/CodeRepositoryRunner.d.ts +7 -0
  23. package/Types/Runner/CodeRepositoryRunner.js +60 -14
  24. package/Types/Runner/CodeRepositoryRunner.mjs +1 -0
  25. package/Types/SecurityEvent/OcsfProcessActivity.d.mts +25 -0
  26. package/Types/SecurityEvent/OcsfProcessActivity.d.ts +25 -0
  27. package/Types/SecurityEvent/OcsfProcessActivity.js +131 -0
  28. package/Types/SecurityEvent/OcsfProcessActivity.mjs +8 -0
  29. package/UI/Utils/TranslateTemplate.d.mts +73 -0
  30. package/UI/Utils/TranslateTemplate.d.ts +73 -0
  31. package/Utils/CronTab.d.mts +41 -3
  32. package/Utils/CronTab.d.ts +41 -3
  33. package/Utils/CronTab.js +112 -38
  34. package/Utils/Monitor/MonitorOverviewTargetUtil.d.mts +2 -0
  35. package/Utils/Monitor/MonitorOverviewTargetUtil.d.ts +2 -0
  36. package/Utils/Monitor/MonitorOverviewTargetUtil.js +13 -2
  37. package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.d.mts +5 -0
  38. package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.d.ts +5 -0
  39. package/Utils/SecurityEvent/Destinations/GoogleSecOpsUdmMapper.js +219 -58
  40. package/Utils/SecurityEvent/OcsfNormalizer.js +22 -13
  41. package/Utils/Slo/SloDuration.d.mts +1 -0
  42. package/Utils/Slo/SloDuration.d.ts +1 -0
  43. package/Utils/Slo/SloDuration.js +57 -8
  44. package/Utils/Slo/SloDuration.mjs +1 -0
  45. package/Utils/Suggestions/CodeFixSuggestion.d.mts +15 -0
  46. package/Utils/Suggestions/CodeFixSuggestion.d.ts +15 -0
  47. package/Utils/Suggestions/CodeFixSuggestion.js +62 -1
  48. package/Utils/Suggestions/CodeFixSuggestion.mjs +4 -0
  49. package/Utils/Suggestions/ProfileFixSuggestion.js +4 -0
  50. package/Utils/Suggestions/SuggestionBlocker.d.mts +8 -0
  51. package/Utils/Suggestions/SuggestionBlocker.d.ts +8 -0
  52. package/Utils/Suggestions/SuggestionBlocker.js +51 -0
  53. package/Utils/Suggestions/SuggestionBlocker.mjs +4 -0
  54. package/Utils/Suggestions/SuggestionOffer.d.mts +2 -1
  55. package/Utils/Suggestions/SuggestionOffer.d.ts +2 -1
  56. package/Utils/Suggestions/SuggestionOffer.js +5 -0
  57. package/Utils/Suggestions/TelemetryAiFixSuggestion.d.mts +2 -7
  58. package/Utils/Suggestions/TelemetryAiFixSuggestion.d.ts +2 -7
  59. package/Utils/Suggestions/TelemetryAiFixSuggestion.js +8 -36
  60. package/Utils/Suggestions/TelemetryImprovementSuggestion.d.mts +1 -0
  61. package/Utils/Suggestions/TelemetryImprovementSuggestion.d.ts +1 -0
  62. package/Utils/Suggestions/TelemetryImprovementSuggestion.js +1 -0
  63. package/Utils/Suggestions/TracePerformanceFixSuggestion.d.mts +6 -0
  64. package/Utils/Suggestions/TracePerformanceFixSuggestion.d.ts +6 -0
  65. package/Utils/Suggestions/TracePerformanceFixSuggestion.js +46 -5
  66. package/package.json +8 -1
  67. package/Utils/Monitor/MonitorCheckScheduleUtil.d.mts +0 -61
  68. package/Utils/Monitor/MonitorCheckScheduleUtil.d.ts +0 -61
  69. package/Utils/Monitor/MonitorCheckScheduleUtil.js +0 -476
  70. package/Utils/Monitor/MonitorCheckScheduleUtil.mjs +0 -3
  71. package/Utils/Monitor/MonitorOverviewFamily.d.mts +0 -39
  72. package/Utils/Monitor/MonitorOverviewFamily.d.ts +0 -39
  73. package/Utils/Monitor/MonitorOverviewFamily.js +0 -206
  74. package/Utils/Monitor/MonitorOverviewFamily.mjs +0 -4
  75. package/Utils/Monitor/MonitorOverviewPresentationUtil.d.mts +0 -189
  76. package/Utils/Monitor/MonitorOverviewPresentationUtil.d.ts +0 -189
  77. package/Utils/Monitor/MonitorOverviewPresentationUtil.js +0 -1480
  78. package/Utils/Monitor/MonitorOverviewPresentationUtil.mjs +0 -5
  79. package/Utils/Monitor/MonitorOverviewProbeUtil.d.mts +0 -112
  80. package/Utils/Monitor/MonitorOverviewProbeUtil.d.ts +0 -112
  81. package/Utils/Monitor/MonitorOverviewProbeUtil.js +0 -640
  82. package/Utils/Monitor/MonitorOverviewProbeUtil.mjs +0 -3
  83. package/Utils/Monitor/MonitorStatusHistoryUtil.d.mts +0 -27
  84. package/Utils/Monitor/MonitorStatusHistoryUtil.d.ts +0 -27
  85. package/Utils/Monitor/MonitorStatusHistoryUtil.js +0 -132
  86. package/Utils/Monitor/MonitorStatusHistoryUtil.mjs +0 -2
  87. package/Utils/Monitor/MonitorUptimeSummaryUtil.d.mts +0 -42
  88. package/Utils/Monitor/MonitorUptimeSummaryUtil.d.ts +0 -42
  89. package/Utils/Monitor/MonitorUptimeSummaryUtil.js +0 -468
  90. package/Utils/Monitor/MonitorUptimeSummaryUtil.mjs +0 -2
@@ -0,0 +1,67 @@
1
+ export declare const ENGLISH_DATE_LANGUAGE: string;
2
+ export declare const isEnglishDateLanguage: (language: string | null | undefined) => boolean;
3
+ export declare const getDateDisplayLanguage: () => string;
4
+ export declare const setDateDisplayLanguage: (language: string | null | undefined) => void;
5
+ export declare function withDateDisplayLanguage<T>(language: string | null | undefined, work: () => T): T;
6
+ export declare function inEnglishDates<T>(work: () => T): T;
7
+ export declare const getDateLocale: (language: string | null | undefined) => string;
8
+ export declare const MAX_REMEMBERED_DATE_TEXTS: number;
9
+ export declare const rememberEnglishOf: (localized: string, english: () => string) => void;
10
+ export declare const getEnglishOf: (text: string) => string | undefined;
11
+ export declare const forgetRememberedDateTexts: () => void;
12
+ export declare const writeInDateDisplayLanguage: (english: () => string, localized: (language: string, locale: string) => string | null | undefined) => string;
13
+ export declare const getDateTimeFormat: (data: {
14
+ locale: string;
15
+ timezones: Array<string>;
16
+ options: Intl.DateTimeFormatOptions;
17
+ }) => Intl.DateTimeFormat | null;
18
+ export interface DateTextShape {
19
+ onlyShowDate?: boolean | undefined;
20
+ showSeconds?: boolean | undefined;
21
+ use12HourFormat?: boolean | undefined;
22
+ showWeekday?: boolean | undefined;
23
+ hideYear?: boolean | undefined;
24
+ twoDigitDay?: boolean | undefined;
25
+ }
26
+ export declare const getDateTimeOptions: (shape: DateTextShape) => Intl.DateTimeFormatOptions;
27
+ export declare const formatDateText: (data: {
28
+ date: Date;
29
+ locale: string;
30
+ timezones: Array<string>;
31
+ shape: DateTextShape;
32
+ }) => string | null;
33
+ export type RelativeDateUnit = "second" | "minute" | "hour" | "day" | "month" | "year";
34
+ export interface RelativeDistance {
35
+ isNow: boolean;
36
+ count: number;
37
+ unit: RelativeDateUnit;
38
+ isFuture: boolean;
39
+ }
40
+ export declare const getRelativeDistance: (date: Date, now: Date) => RelativeDistance;
41
+ export declare const formatRelativeDate: (data: {
42
+ date: Date;
43
+ now: Date;
44
+ locale: string;
45
+ }) => string | null;
46
+ export type DurationTextUnit = "year" | "month" | "week" | "day" | "hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond";
47
+ export interface DurationTextPart {
48
+ count: number;
49
+ unit: DurationTextUnit;
50
+ }
51
+ export declare const formatDurationUnit: (data: {
52
+ part: DurationTextPart;
53
+ locale: string;
54
+ unitDisplay: "long" | "short" | "narrow";
55
+ maximumFractionDigits?: number | undefined;
56
+ }) => string | null;
57
+ export declare const formatDurationText: (data: {
58
+ parts: Array<DurationTextPart>;
59
+ locale: string;
60
+ unitDisplay: "long" | "short" | "narrow";
61
+ listStyle: "long" | "short" | "narrow";
62
+ }) => string | null;
63
+ export declare const formatDecimal: (data: {
64
+ value: number;
65
+ locale: string;
66
+ maximumFractionDigits: number;
67
+ }) => string | null;
@@ -0,0 +1,67 @@
1
+ export declare const ENGLISH_DATE_LANGUAGE: string;
2
+ export declare const isEnglishDateLanguage: (language: string | null | undefined) => boolean;
3
+ export declare const getDateDisplayLanguage: () => string;
4
+ export declare const setDateDisplayLanguage: (language: string | null | undefined) => void;
5
+ export declare function withDateDisplayLanguage<T>(language: string | null | undefined, work: () => T): T;
6
+ export declare function inEnglishDates<T>(work: () => T): T;
7
+ export declare const getDateLocale: (language: string | null | undefined) => string;
8
+ export declare const MAX_REMEMBERED_DATE_TEXTS: number;
9
+ export declare const rememberEnglishOf: (localized: string, english: () => string) => void;
10
+ export declare const getEnglishOf: (text: string) => string | undefined;
11
+ export declare const forgetRememberedDateTexts: () => void;
12
+ export declare const writeInDateDisplayLanguage: (english: () => string, localized: (language: string, locale: string) => string | null | undefined) => string;
13
+ export declare const getDateTimeFormat: (data: {
14
+ locale: string;
15
+ timezones: Array<string>;
16
+ options: Intl.DateTimeFormatOptions;
17
+ }) => Intl.DateTimeFormat | null;
18
+ export interface DateTextShape {
19
+ onlyShowDate?: boolean | undefined;
20
+ showSeconds?: boolean | undefined;
21
+ use12HourFormat?: boolean | undefined;
22
+ showWeekday?: boolean | undefined;
23
+ hideYear?: boolean | undefined;
24
+ twoDigitDay?: boolean | undefined;
25
+ }
26
+ export declare const getDateTimeOptions: (shape: DateTextShape) => Intl.DateTimeFormatOptions;
27
+ export declare const formatDateText: (data: {
28
+ date: Date;
29
+ locale: string;
30
+ timezones: Array<string>;
31
+ shape: DateTextShape;
32
+ }) => string | null;
33
+ export type RelativeDateUnit = "second" | "minute" | "hour" | "day" | "month" | "year";
34
+ export interface RelativeDistance {
35
+ isNow: boolean;
36
+ count: number;
37
+ unit: RelativeDateUnit;
38
+ isFuture: boolean;
39
+ }
40
+ export declare const getRelativeDistance: (date: Date, now: Date) => RelativeDistance;
41
+ export declare const formatRelativeDate: (data: {
42
+ date: Date;
43
+ now: Date;
44
+ locale: string;
45
+ }) => string | null;
46
+ export type DurationTextUnit = "year" | "month" | "week" | "day" | "hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond";
47
+ export interface DurationTextPart {
48
+ count: number;
49
+ unit: DurationTextUnit;
50
+ }
51
+ export declare const formatDurationUnit: (data: {
52
+ part: DurationTextPart;
53
+ locale: string;
54
+ unitDisplay: "long" | "short" | "narrow";
55
+ maximumFractionDigits?: number | undefined;
56
+ }) => string | null;
57
+ export declare const formatDurationText: (data: {
58
+ parts: Array<DurationTextPart>;
59
+ locale: string;
60
+ unitDisplay: "long" | "short" | "narrow";
61
+ listStyle: "long" | "short" | "narrow";
62
+ }) => string | null;
63
+ export declare const formatDecimal: (data: {
64
+ value: number;
65
+ locale: string;
66
+ maximumFractionDigits: number;
67
+ }) => string | null;
@@ -0,0 +1,478 @@
1
+ "use strict";
2
+ /*
3
+ * DATES, TIMES AND DURATIONS IN THE READER'S LANGUAGE.
4
+ *
5
+ * OneUptimeDate wrote every date with moment's English - "Oct 16 2026,
6
+ * 10:12 AM BST", "5 hours ago", "2 days, 3 hours" - under a German or a
7
+ * Japanese page. Each frontend now tells this module the language its reader
8
+ * reads (setDateDisplayLanguage, from its i18n set-up), and OneUptimeDate
9
+ * writes the words of a date in it: month and weekday names, "vor 5
10
+ * Stunden", "2 Tage, 3 Stunden", a decimal comma. The words come from the
11
+ * browser's Intl data, so no locale is shipped for them; the calendar is
12
+ * always the Gregorian one and the digits Latin, so a Persian reader's dates
13
+ * line up with every other number on the page.
14
+ *
15
+ * English is what nothing has set - the server, a worker, an email, a test -
16
+ * and every function writes it exactly as it always has.
17
+ *
18
+ * A date often goes into a sentence ("Checked {{time}}"). A sentence is
19
+ * wholly in the reader's language or wholly in English, never a German date
20
+ * inside an English sentence: a language that has not worded the sentence
21
+ * yet reads the English one. So every date written in another language is
22
+ * remembered with its English (rememberEnglishOf), and the translation layer
23
+ * puts the English back when it fills an English sentence (getEnglishOf), as
24
+ * a component inside a sentence draws its date in the sentence's language
25
+ * (withDateDisplayLanguage).
26
+ *
27
+ * React-free and free of the rest of OneUptime, so OneUptimeDate, the
28
+ * translation layer and any frontend can use it.
29
+ */
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.formatDecimal = exports.formatDurationText = exports.formatDurationUnit = exports.formatRelativeDate = exports.getRelativeDistance = exports.formatDateText = exports.getDateTimeOptions = exports.getDateTimeFormat = exports.writeInDateDisplayLanguage = exports.forgetRememberedDateTexts = exports.getEnglishOf = exports.rememberEnglishOf = exports.MAX_REMEMBERED_DATE_TEXTS = exports.getDateLocale = exports.setDateDisplayLanguage = exports.getDateDisplayLanguage = exports.isEnglishDateLanguage = exports.ENGLISH_DATE_LANGUAGE = void 0;
35
+ exports.withDateDisplayLanguage = withDateDisplayLanguage;
36
+ exports.inEnglishDates = inEnglishDates;
37
+ const moment_timezone_1 = __importDefault(require("moment-timezone"));
38
+ exports.ENGLISH_DATE_LANGUAGE = "en";
39
+ let displayLanguage = exports.ENGLISH_DATE_LANGUAGE;
40
+ // "en", "en-GB", "EN": English, written the way OneUptimeDate always has.
41
+ const isEnglishDateLanguage = (language) => {
42
+ if (!language) {
43
+ return true;
44
+ }
45
+ const lower = language.trim().toLowerCase();
46
+ return lower === "" || lower === "en" || lower.startsWith("en-");
47
+ };
48
+ exports.isEnglishDateLanguage = isEnglishDateLanguage;
49
+ const normalizeLanguage = (language) => {
50
+ const trimmed = (language || "").trim();
51
+ return (0, exports.isEnglishDateLanguage)(trimmed) ? exports.ENGLISH_DATE_LANGUAGE : trimmed;
52
+ };
53
+ // The language dates are written in right now: "en" unless a frontend set one.
54
+ const getDateDisplayLanguage = () => {
55
+ return displayLanguage;
56
+ };
57
+ exports.getDateDisplayLanguage = getDateDisplayLanguage;
58
+ /*
59
+ * Set by each frontend from its i18n language, at start-up and on every
60
+ * switch. Anything that is not a language Intl knows is written in English.
61
+ */
62
+ const setDateDisplayLanguage = (language) => {
63
+ displayLanguage = normalizeLanguage(language);
64
+ };
65
+ exports.setDateDisplayLanguage = setDateDisplayLanguage;
66
+ /*
67
+ * `work`'s dates written in `language`: a date drawn inside a sentence takes
68
+ * the sentence's language, which is English while the reader's language has
69
+ * not worded the sentence.
70
+ */
71
+ function withDateDisplayLanguage(language, work) {
72
+ const previous = displayLanguage;
73
+ displayLanguage = normalizeLanguage(language);
74
+ try {
75
+ return work();
76
+ }
77
+ finally {
78
+ displayLanguage = previous;
79
+ }
80
+ }
81
+ /*
82
+ * `work`'s dates written in English: for text that stays English whatever
83
+ * the reader's language - an export, a prompt handed to OneUptime AI, a
84
+ * message not translated yet - so it never holds a German date.
85
+ */
86
+ function inEnglishDates(work) {
87
+ return withDateDisplayLanguage(exports.ENGLISH_DATE_LANGUAGE, work);
88
+ }
89
+ const localeCache = new Map();
90
+ /*
91
+ * The Intl locale a language writes dates in: its own words and order, the
92
+ * Gregorian calendar and Latin digits ("fa" alone would give the Solar
93
+ * Hijri calendar in Persian digits). A language Intl does not know reads
94
+ * English, never the browser's own default, so a page never mixes two
95
+ * languages.
96
+ */
97
+ const getDateLocale = (language) => {
98
+ const requested = normalizeLanguage(language);
99
+ const cached = localeCache.get(requested);
100
+ if (cached) {
101
+ return cached;
102
+ }
103
+ let locale = `${exports.ENGLISH_DATE_LANGUAGE}-u-ca-gregory-nu-latn`;
104
+ try {
105
+ const supported = Intl.DateTimeFormat.supportedLocalesOf([
106
+ requested,
107
+ ]);
108
+ if (supported.length > 0 && supported[0]) {
109
+ locale = `${supported[0]}-u-ca-gregory-nu-latn`;
110
+ // Throws on a tag Intl cannot take an extension on.
111
+ new Intl.DateTimeFormat(locale);
112
+ }
113
+ }
114
+ catch (_a) {
115
+ locale = `${exports.ENGLISH_DATE_LANGUAGE}-u-ca-gregory-nu-latn`;
116
+ }
117
+ localeCache.set(requested, locale);
118
+ return locale;
119
+ };
120
+ exports.getDateLocale = getDateLocale;
121
+ /*
122
+ * THE ENGLISH OF A DATE WRITTEN IN ANOTHER LANGUAGE.
123
+ *
124
+ * Kept for the most recent texts only: a page writes its dates again on
125
+ * every render, so an old one that is no longer on screen is never asked
126
+ * for. The English is worked out only when a sentence asks for it.
127
+ */
128
+ exports.MAX_REMEMBERED_DATE_TEXTS = 5000;
129
+ const englishOfText = new Map();
130
+ const rememberEnglishOf = (localized, english) => {
131
+ if (!localized) {
132
+ return;
133
+ }
134
+ // The newest last, so the oldest is the first to go.
135
+ englishOfText.delete(localized);
136
+ englishOfText.set(localized, english);
137
+ if (englishOfText.size > exports.MAX_REMEMBERED_DATE_TEXTS) {
138
+ const oldest = englishOfText.keys().next().value;
139
+ if (oldest !== undefined) {
140
+ englishOfText.delete(oldest);
141
+ }
142
+ }
143
+ };
144
+ exports.rememberEnglishOf = rememberEnglishOf;
145
+ /*
146
+ * The English of `text` when it is a date, a time or a duration this module
147
+ * wrote in another language; undefined for anything else.
148
+ */
149
+ const getEnglishOf = (text) => {
150
+ const english = englishOfText.get(text);
151
+ if (!english) {
152
+ return undefined;
153
+ }
154
+ try {
155
+ return english();
156
+ }
157
+ catch (_a) {
158
+ return undefined;
159
+ }
160
+ };
161
+ exports.getEnglishOf = getEnglishOf;
162
+ // For tests: forget every remembered text.
163
+ const forgetRememberedDateTexts = () => {
164
+ englishOfText.clear();
165
+ };
166
+ exports.forgetRememberedDateTexts = forgetRememberedDateTexts;
167
+ /*
168
+ * A date's text in the display language: `english()` while that is English,
169
+ * `localized(language, locale)` otherwise - remembered with its English -
170
+ * and the English again when the language's text cannot be written.
171
+ */
172
+ const writeInDateDisplayLanguage = (english, localized) => {
173
+ const language = (0, exports.getDateDisplayLanguage)();
174
+ const locale = (0, exports.getDateLocale)(language);
175
+ // English, or a language Intl does not know: moment's English, exactly.
176
+ if ((0, exports.isEnglishDateLanguage)(language) ||
177
+ locale.startsWith(`${exports.ENGLISH_DATE_LANGUAGE}-`)) {
178
+ return english();
179
+ }
180
+ let text = null;
181
+ try {
182
+ text = localized(language, locale);
183
+ }
184
+ catch (_a) {
185
+ text = null;
186
+ }
187
+ if (!text) {
188
+ return english();
189
+ }
190
+ /*
191
+ * Worked out in English when asked for, whatever the display language is
192
+ * then: the English of "06. Okt." names October as "Oct".
193
+ */
194
+ (0, exports.rememberEnglishOf)(text, () => {
195
+ return withDateDisplayLanguage(exports.ENGLISH_DATE_LANGUAGE, english);
196
+ });
197
+ return text;
198
+ };
199
+ exports.writeInDateDisplayLanguage = writeInDateDisplayLanguage;
200
+ /*
201
+ * DATE AND TIME OF DAY.
202
+ */
203
+ const dateTimeFormatCache = new Map();
204
+ /*
205
+ * A formatter for `options` in `locale`, read in the first of `timezones`
206
+ * this engine's Intl knows (an engine with older tzdata knows "Europe/Kiev"
207
+ * but not "Europe/Kyiv"); none means the runtime's own zone. Null when no
208
+ * zone works, so the caller writes the English moment knows how to write.
209
+ * Built once per locale, zone and shape: a table writes hundreds of dates.
210
+ */
211
+ const getDateTimeFormat = (data) => {
212
+ const zones = data.timezones.length > 0 ? data.timezones : [undefined];
213
+ const shape = JSON.stringify(data.options);
214
+ for (const zone of zones) {
215
+ const key = `${data.locale}|${zone || ""}|${shape}`;
216
+ if (dateTimeFormatCache.has(key)) {
217
+ const cached = dateTimeFormatCache.get(key) || null;
218
+ if (cached) {
219
+ return cached;
220
+ }
221
+ continue;
222
+ }
223
+ try {
224
+ const format = new Intl.DateTimeFormat(data.locale, zone ? Object.assign(Object.assign({}, data.options), { timeZone: zone }) : data.options);
225
+ dateTimeFormatCache.set(key, format);
226
+ return format;
227
+ }
228
+ catch (_a) {
229
+ dateTimeFormatCache.set(key, null);
230
+ }
231
+ }
232
+ return null;
233
+ };
234
+ exports.getDateTimeFormat = getDateTimeFormat;
235
+ // The Intl options a shape of OneUptimeDate's dates asks for.
236
+ const getDateTimeOptions = (shape) => {
237
+ const options = {
238
+ month: "short",
239
+ day: shape.twoDigitDay ? "2-digit" : "numeric",
240
+ };
241
+ if (!shape.hideYear) {
242
+ options.year = "numeric";
243
+ }
244
+ if (shape.showWeekday) {
245
+ options.weekday = "short";
246
+ }
247
+ if (!shape.onlyShowDate) {
248
+ options.hour = "2-digit";
249
+ options.minute = "2-digit";
250
+ options.hour12 = Boolean(shape.use12HourFormat);
251
+ if (shape.showSeconds) {
252
+ options.second = "2-digit";
253
+ }
254
+ }
255
+ return options;
256
+ };
257
+ exports.getDateTimeOptions = getDateTimeOptions;
258
+ /*
259
+ * `date` in `locale`, read in the first zone of `timezones` Intl knows, in
260
+ * the shape asked for; null when Intl cannot write it.
261
+ */
262
+ const formatDateText = (data) => {
263
+ if (Number.isNaN(data.date.getTime())) {
264
+ return null;
265
+ }
266
+ const format = (0, exports.getDateTimeFormat)({
267
+ locale: data.locale,
268
+ timezones: data.timezones,
269
+ options: (0, exports.getDateTimeOptions)(data.shape),
270
+ });
271
+ return format ? format.format(data.date) : null;
272
+ };
273
+ exports.formatDateText = formatDateText;
274
+ const relativeTimeFormatCache = new Map();
275
+ const getRelativeTimeFormatter = (locale, numeric) => {
276
+ const key = `${locale}|${numeric}`;
277
+ if (relativeTimeFormatCache.has(key)) {
278
+ return relativeTimeFormatCache.get(key) || null;
279
+ }
280
+ let formatter = null;
281
+ try {
282
+ const RelativeTimeFormat = Intl.RelativeTimeFormat;
283
+ if (RelativeTimeFormat) {
284
+ formatter = new RelativeTimeFormat(locale, {
285
+ numeric: numeric,
286
+ style: "long",
287
+ });
288
+ }
289
+ }
290
+ catch (_a) {
291
+ formatter = null;
292
+ }
293
+ relativeTimeFormatCache.set(key, formatter);
294
+ return formatter;
295
+ };
296
+ /*
297
+ * How far `date` is from `now`, counted and rounded the way moment's fromNow
298
+ * counts and rounds - the same calendar months and the same thresholds - so
299
+ * a status that read "a day ago" in English reads "vor 1 Tag" in German,
300
+ * never "vor 2 Tagen": up to 44 seconds is "a few seconds"; then minutes up
301
+ * to 44, hours up to 21, days up to 25, months up to 10, then years.
302
+ */
303
+ const getRelativeDistance = (date, now) => {
304
+ const isFuture = date.getTime() - now.getTime() > 0;
305
+ // The calendar distance fromNow reads (whole months, then the rest).
306
+ const duration = moment_timezone_1.default
307
+ .duration({ from: now, to: date })
308
+ .abs();
309
+ const seconds = Math.round(duration.as("s"));
310
+ const minutes = Math.round(duration.as("m"));
311
+ const hours = Math.round(duration.as("h"));
312
+ const days = Math.round(duration.as("d"));
313
+ const months = Math.round(duration.as("M"));
314
+ const years = Math.round(duration.as("y"));
315
+ const distance = (count, unit) => {
316
+ return { isNow: false, count, unit, isFuture };
317
+ };
318
+ if (seconds <= 44) {
319
+ return { isNow: true, count: 0, unit: "second", isFuture };
320
+ }
321
+ if (minutes <= 1) {
322
+ return distance(1, "minute");
323
+ }
324
+ if (minutes < 45) {
325
+ return distance(minutes, "minute");
326
+ }
327
+ if (hours <= 1) {
328
+ return distance(1, "hour");
329
+ }
330
+ if (hours < 22) {
331
+ return distance(hours, "hour");
332
+ }
333
+ if (days <= 1) {
334
+ return distance(1, "day");
335
+ }
336
+ if (days < 26) {
337
+ return distance(days, "day");
338
+ }
339
+ if (months <= 1) {
340
+ return distance(1, "month");
341
+ }
342
+ if (months < 11) {
343
+ return distance(months, "month");
344
+ }
345
+ if (years <= 1) {
346
+ return distance(1, "year");
347
+ }
348
+ return distance(years, "year");
349
+ };
350
+ exports.getRelativeDistance = getRelativeDistance;
351
+ /*
352
+ * "vor 5 Stunden", "in 3 Tagen", "jetzt" - how far `date` is from `now`, in
353
+ * `locale`; null when this engine has no Intl.RelativeTimeFormat.
354
+ */
355
+ const formatRelativeDate = (data) => {
356
+ if (Number.isNaN(data.date.getTime())) {
357
+ return null;
358
+ }
359
+ const distance = (0, exports.getRelativeDistance)(data.date, data.now);
360
+ if (distance.isNow) {
361
+ const auto = getRelativeTimeFormatter(data.locale, "auto");
362
+ return auto ? auto.format(0, "second") : null;
363
+ }
364
+ const always = getRelativeTimeFormatter(data.locale, "always");
365
+ if (!always) {
366
+ return null;
367
+ }
368
+ return always.format(distance.isFuture ? distance.count : -distance.count, distance.unit);
369
+ };
370
+ exports.formatRelativeDate = formatRelativeDate;
371
+ const unitFormatCache = new Map();
372
+ // The Intl.NumberFormat the cache was built with: another one starts afresh.
373
+ let unitFormatCacheOwner = null;
374
+ const getUnitFormatter = (data) => {
375
+ const key = `${data.locale}|${data.unit}|${data.unitDisplay}|${data.maximumFractionDigits}`;
376
+ if (unitFormatCacheOwner !== Intl.NumberFormat) {
377
+ unitFormatCache.clear();
378
+ unitFormatCacheOwner = Intl.NumberFormat;
379
+ }
380
+ if (unitFormatCache.has(key)) {
381
+ return unitFormatCache.get(key) || null;
382
+ }
383
+ let formatter = null;
384
+ try {
385
+ const candidate = new Intl.NumberFormat(data.locale, {
386
+ style: "unit",
387
+ unit: data.unit,
388
+ unitDisplay: data.unitDisplay,
389
+ maximumFractionDigits: data.maximumFractionDigits,
390
+ });
391
+ // An engine without the unit style writes the bare number.
392
+ const probe = candidate.format(2);
393
+ formatter =
394
+ probe === (2).toLocaleString(data.locale)
395
+ ? null
396
+ : candidate;
397
+ }
398
+ catch (_a) {
399
+ formatter = null;
400
+ }
401
+ unitFormatCache.set(key, formatter);
402
+ return formatter;
403
+ };
404
+ // "2 Stunden", "2 Std.", "2h": one unit of a duration in `locale`.
405
+ const formatDurationUnit = (data) => {
406
+ var _a;
407
+ const formatter = getUnitFormatter({
408
+ locale: data.locale,
409
+ unit: data.part.unit,
410
+ unitDisplay: data.unitDisplay,
411
+ maximumFractionDigits: (_a = data.maximumFractionDigits) !== null && _a !== void 0 ? _a : 0,
412
+ });
413
+ return formatter ? formatter.format(data.part.count) : null;
414
+ };
415
+ exports.formatDurationUnit = formatDurationUnit;
416
+ /*
417
+ * A duration's units in `locale`, with the language's own unit names,
418
+ * plurals and list: "10 Tage, 23 Stunden", "10 jours et 23 heures", "10 日
419
+ * 23 時間". `listStyle` "narrow" joins them as a compact reading does ("2 J.
420
+ * 3 Mon."). Null when this engine cannot write one of the units.
421
+ */
422
+ const formatDurationText = (data) => {
423
+ if (data.parts.length === 0) {
424
+ return null;
425
+ }
426
+ const words = [];
427
+ for (const part of data.parts) {
428
+ const word = (0, exports.formatDurationUnit)({
429
+ part,
430
+ locale: data.locale,
431
+ unitDisplay: data.unitDisplay,
432
+ });
433
+ if (!word) {
434
+ return null;
435
+ }
436
+ words.push(word);
437
+ }
438
+ if (words.length === 1) {
439
+ return words[0];
440
+ }
441
+ try {
442
+ const ListFormat = Intl.ListFormat;
443
+ if (!ListFormat) {
444
+ return words.join(data.listStyle === "narrow" ? " " : ", ");
445
+ }
446
+ return new ListFormat(data.locale, {
447
+ type: "unit",
448
+ style: data.listStyle,
449
+ }).format(words);
450
+ }
451
+ catch (_a) {
452
+ return words.join(data.listStyle === "narrow" ? " " : ", ");
453
+ }
454
+ };
455
+ exports.formatDurationText = formatDurationText;
456
+ const numberFormatCache = new Map();
457
+ /*
458
+ * A number as `locale` writes it - "1,72" in German - with at most
459
+ * `maximumFractionDigits` decimals and no thousands separator, as a
460
+ * duration's figure is read. Null when Intl cannot.
461
+ */
462
+ const formatDecimal = (data) => {
463
+ const key = `${data.locale}|${data.maximumFractionDigits}`;
464
+ if (!numberFormatCache.has(key)) {
465
+ try {
466
+ numberFormatCache.set(key, new Intl.NumberFormat(data.locale, {
467
+ maximumFractionDigits: data.maximumFractionDigits,
468
+ useGrouping: false,
469
+ }));
470
+ }
471
+ catch (_a) {
472
+ numberFormatCache.set(key, null);
473
+ }
474
+ }
475
+ const format = numberFormatCache.get(key) || null;
476
+ return format ? format.format(data.value) : null;
477
+ };
478
+ exports.formatDecimal = formatDecimal;
@@ -0,0 +1,21 @@
1
+ import commonJsModule from "./DateLanguage.js";
2
+ export const ENGLISH_DATE_LANGUAGE = commonJsModule.ENGLISH_DATE_LANGUAGE;
3
+ export const MAX_REMEMBERED_DATE_TEXTS = commonJsModule.MAX_REMEMBERED_DATE_TEXTS;
4
+ export const forgetRememberedDateTexts = commonJsModule.forgetRememberedDateTexts;
5
+ export const formatDateText = commonJsModule.formatDateText;
6
+ export const formatDecimal = commonJsModule.formatDecimal;
7
+ export const formatDurationText = commonJsModule.formatDurationText;
8
+ export const formatDurationUnit = commonJsModule.formatDurationUnit;
9
+ export const formatRelativeDate = commonJsModule.formatRelativeDate;
10
+ export const getDateDisplayLanguage = commonJsModule.getDateDisplayLanguage;
11
+ export const getDateLocale = commonJsModule.getDateLocale;
12
+ export const getDateTimeFormat = commonJsModule.getDateTimeFormat;
13
+ export const getDateTimeOptions = commonJsModule.getDateTimeOptions;
14
+ export const getEnglishOf = commonJsModule.getEnglishOf;
15
+ export const getRelativeDistance = commonJsModule.getRelativeDistance;
16
+ export const inEnglishDates = commonJsModule.inEnglishDates;
17
+ export const isEnglishDateLanguage = commonJsModule.isEnglishDateLanguage;
18
+ export const rememberEnglishOf = commonJsModule.rememberEnglishOf;
19
+ export const setDateDisplayLanguage = commonJsModule.setDateDisplayLanguage;
20
+ export const withDateDisplayLanguage = commonJsModule.withDateDisplayLanguage;
21
+ export const writeInDateDisplayLanguage = commonJsModule.writeInDateDisplayLanguage;
@@ -1,12 +1,16 @@
1
1
  import ObjectID from "../ObjectID.mjs";
2
2
  export declare enum CodeRepositoryRunnerChoiceKind {
3
3
  Custom = "custom",
4
+ ProjectDefault = "project-default",
4
5
  Global = "global",
5
6
  NoRunner = "no-runner"
6
7
  }
7
8
  export type CodeRepositoryRunnerDecision = {
8
9
  kind: CodeRepositoryRunnerChoiceKind.Custom;
9
10
  runnerId: string;
11
+ } | {
12
+ kind: CodeRepositoryRunnerChoiceKind.ProjectDefault;
13
+ runnerId: string;
10
14
  } | {
11
15
  kind: CodeRepositoryRunnerChoiceKind.Global;
12
16
  } | {
@@ -14,8 +18,11 @@ export type CodeRepositoryRunnerDecision = {
14
18
  };
15
19
  export interface CodeRepositoryRunnerFacts {
16
20
  repositoryRunnerId?: ObjectID | string | null | undefined;
21
+ picksGlobalRunner?: boolean | null | undefined;
22
+ projectDefaultRunnerId?: ObjectID | string | null | undefined;
17
23
  projectUsesGlobalRunners: boolean;
18
24
  }
25
+ export declare function followsProjectDefaultRunner(facts: Pick<CodeRepositoryRunnerFacts, "repositoryRunnerId" | "picksGlobalRunner">): boolean;
19
26
  export declare enum CodeWorkerKind {
20
27
  ProjectRunner = "project-runner",
21
28
  GlobalRunner = "global-runner",
@@ -1,12 +1,16 @@
1
1
  import ObjectID from "../ObjectID";
2
2
  export declare enum CodeRepositoryRunnerChoiceKind {
3
3
  Custom = "custom",
4
+ ProjectDefault = "project-default",
4
5
  Global = "global",
5
6
  NoRunner = "no-runner"
6
7
  }
7
8
  export type CodeRepositoryRunnerDecision = {
8
9
  kind: CodeRepositoryRunnerChoiceKind.Custom;
9
10
  runnerId: string;
11
+ } | {
12
+ kind: CodeRepositoryRunnerChoiceKind.ProjectDefault;
13
+ runnerId: string;
10
14
  } | {
11
15
  kind: CodeRepositoryRunnerChoiceKind.Global;
12
16
  } | {
@@ -14,8 +18,11 @@ export type CodeRepositoryRunnerDecision = {
14
18
  };
15
19
  export interface CodeRepositoryRunnerFacts {
16
20
  repositoryRunnerId?: ObjectID | string | null | undefined;
21
+ picksGlobalRunner?: boolean | null | undefined;
22
+ projectDefaultRunnerId?: ObjectID | string | null | undefined;
17
23
  projectUsesGlobalRunners: boolean;
18
24
  }
25
+ export declare function followsProjectDefaultRunner(facts: Pick<CodeRepositoryRunnerFacts, "repositoryRunnerId" | "picksGlobalRunner">): boolean;
19
26
  export declare enum CodeWorkerKind {
20
27
  ProjectRunner = "project-runner",
21
28
  GlobalRunner = "global-runner",