@cloudsnorkel/cdk-github-runners 0.14.23 → 0.15.0

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 (139) hide show
  1. package/.jsii +5397 -252
  2. package/API.md +1048 -24
  3. package/README.md +52 -0
  4. package/assets/delete-failed-runner.lambda/index.js +105 -9
  5. package/assets/idle-runner-repear.lambda/index.js +136 -14
  6. package/assets/image-builders/aws-image-builder/delete-resources.lambda/index.js +1 -1
  7. package/assets/image-builders/build-image.lambda/index.js +1 -1
  8. package/assets/providers/ami-root-device.lambda/index.js +1 -1
  9. package/assets/setup.lambda/index.html +7 -7
  10. package/assets/setup.lambda/index.js +101 -8
  11. package/assets/status.lambda/index.js +104 -8
  12. package/assets/token-retriever.lambda/index.js +104 -8
  13. package/assets/warm-runner-manager.lambda/index.js +5892 -0
  14. package/assets/webhook-handler.lambda/index.js +109 -11
  15. package/assets/webhook-redelivery.lambda/index.js +122 -24
  16. package/lib/access.js +1 -1
  17. package/lib/delete-failed-runner.lambda.js +2 -2
  18. package/lib/idle-runner-repear.lambda.js +33 -7
  19. package/lib/image-builders/api.js +1 -1
  20. package/lib/image-builders/aws-image-builder/base-image.d.ts +13 -0
  21. package/lib/image-builders/aws-image-builder/base-image.js +36 -3
  22. package/lib/image-builders/aws-image-builder/builder.js +4 -4
  23. package/lib/image-builders/aws-image-builder/delete-resources.lambda.js +2 -2
  24. package/lib/image-builders/aws-image-builder/deprecated/ami.js +1 -1
  25. package/lib/image-builders/aws-image-builder/deprecated/container.js +1 -1
  26. package/lib/image-builders/aws-image-builder/deprecated/linux-components.js +1 -1
  27. package/lib/image-builders/aws-image-builder/deprecated/windows-components.js +1 -1
  28. package/lib/image-builders/build-image.lambda.js +2 -2
  29. package/lib/image-builders/codebuild-deprecated.js +1 -1
  30. package/lib/image-builders/components.js +3 -3
  31. package/lib/image-builders/static.js +1 -1
  32. package/lib/index.d.ts +1 -0
  33. package/lib/index.js +2 -1
  34. package/lib/lambda-github.d.ts +1 -1
  35. package/lib/lambda-github.js +3 -2
  36. package/lib/lambda-helpers.js +4 -4
  37. package/lib/providers/ami-root-device.lambda.js +2 -2
  38. package/lib/providers/codebuild.d.ts +16 -0
  39. package/lib/providers/codebuild.js +16 -5
  40. package/lib/providers/common.js +3 -3
  41. package/lib/providers/composite.js +1 -1
  42. package/lib/providers/ec2.d.ts +5 -0
  43. package/lib/providers/ec2.js +42 -29
  44. package/lib/providers/ecs.d.ts +17 -0
  45. package/lib/providers/ecs.js +43 -38
  46. package/lib/providers/fargate.js +10 -32
  47. package/lib/providers/lambda.js +2 -2
  48. package/lib/runner.d.ts +25 -2
  49. package/lib/runner.js +119 -17
  50. package/lib/secrets.js +1 -1
  51. package/lib/setup.lambda.js +2 -2
  52. package/lib/utils.d.ts +10 -1
  53. package/lib/utils.js +15 -1
  54. package/lib/warm-runner-manager-function.d.ts +18 -0
  55. package/lib/warm-runner-manager-function.js +24 -0
  56. package/lib/warm-runner-manager.lambda.d.ts +41 -0
  57. package/lib/warm-runner-manager.lambda.js +487 -0
  58. package/lib/warm-runner.d.ts +147 -0
  59. package/lib/warm-runner.js +210 -0
  60. package/lib/webhook-handler.lambda.js +5 -3
  61. package/lib/webhook-redelivery.lambda.js +17 -16
  62. package/lib/webhook.d.ts +4 -0
  63. package/lib/webhook.js +2 -1
  64. package/node_modules/cron-parser/LICENSE +21 -0
  65. package/node_modules/cron-parser/README.md +408 -0
  66. package/node_modules/cron-parser/dist/CronDate.js +518 -0
  67. package/node_modules/cron-parser/dist/CronExpression.js +520 -0
  68. package/node_modules/cron-parser/dist/CronExpressionParser.js +382 -0
  69. package/node_modules/cron-parser/dist/CronFieldCollection.js +371 -0
  70. package/node_modules/cron-parser/dist/CronFileParser.js +109 -0
  71. package/node_modules/cron-parser/dist/fields/CronDayOfMonth.js +44 -0
  72. package/node_modules/cron-parser/dist/fields/CronDayOfWeek.js +51 -0
  73. package/node_modules/cron-parser/dist/fields/CronField.js +214 -0
  74. package/node_modules/cron-parser/dist/fields/CronHour.js +40 -0
  75. package/node_modules/cron-parser/dist/fields/CronMinute.js +40 -0
  76. package/node_modules/cron-parser/dist/fields/CronMonth.js +44 -0
  77. package/node_modules/cron-parser/dist/fields/CronSecond.js +40 -0
  78. package/node_modules/cron-parser/dist/fields/index.js +24 -0
  79. package/node_modules/cron-parser/dist/fields/types.js +2 -0
  80. package/node_modules/cron-parser/dist/index.js +31 -0
  81. package/node_modules/cron-parser/dist/types/CronDate.d.ts +288 -0
  82. package/node_modules/cron-parser/dist/types/CronExpression.d.ts +118 -0
  83. package/node_modules/cron-parser/dist/types/CronExpressionParser.d.ts +70 -0
  84. package/node_modules/cron-parser/dist/types/CronFieldCollection.d.ts +153 -0
  85. package/node_modules/cron-parser/dist/types/CronFileParser.d.ts +30 -0
  86. package/node_modules/cron-parser/dist/types/fields/CronDayOfMonth.d.ts +25 -0
  87. package/node_modules/cron-parser/dist/types/fields/CronDayOfWeek.d.ts +30 -0
  88. package/node_modules/cron-parser/dist/types/fields/CronField.d.ts +130 -0
  89. package/node_modules/cron-parser/dist/types/fields/CronHour.d.ts +23 -0
  90. package/node_modules/cron-parser/dist/types/fields/CronMinute.d.ts +23 -0
  91. package/node_modules/cron-parser/dist/types/fields/CronMonth.d.ts +24 -0
  92. package/node_modules/cron-parser/dist/types/fields/CronSecond.d.ts +23 -0
  93. package/node_modules/cron-parser/dist/types/fields/index.d.ts +8 -0
  94. package/node_modules/cron-parser/dist/types/fields/types.d.ts +18 -0
  95. package/node_modules/cron-parser/dist/types/index.d.ts +8 -0
  96. package/node_modules/cron-parser/dist/types/utils/random.d.ts +10 -0
  97. package/node_modules/cron-parser/dist/utils/random.js +38 -0
  98. package/node_modules/cron-parser/package.json +117 -0
  99. package/node_modules/luxon/LICENSE.md +7 -0
  100. package/node_modules/luxon/README.md +55 -0
  101. package/node_modules/luxon/build/amd/luxon.js +8741 -0
  102. package/node_modules/luxon/build/amd/luxon.js.map +1 -0
  103. package/node_modules/luxon/build/cjs-browser/luxon.js +8739 -0
  104. package/node_modules/luxon/build/cjs-browser/luxon.js.map +1 -0
  105. package/node_modules/luxon/build/es6/luxon.mjs +8133 -0
  106. package/node_modules/luxon/build/es6/luxon.mjs.map +1 -0
  107. package/node_modules/luxon/build/global/luxon.js +8744 -0
  108. package/node_modules/luxon/build/global/luxon.js.map +1 -0
  109. package/node_modules/luxon/build/global/luxon.min.js +1 -0
  110. package/node_modules/luxon/build/global/luxon.min.js.map +1 -0
  111. package/node_modules/luxon/build/node/luxon.js +7792 -0
  112. package/node_modules/luxon/build/node/luxon.js.map +1 -0
  113. package/node_modules/luxon/package.json +87 -0
  114. package/node_modules/luxon/src/datetime.js +2603 -0
  115. package/node_modules/luxon/src/duration.js +1009 -0
  116. package/node_modules/luxon/src/errors.js +61 -0
  117. package/node_modules/luxon/src/impl/conversions.js +206 -0
  118. package/node_modules/luxon/src/impl/diff.js +95 -0
  119. package/node_modules/luxon/src/impl/digits.js +94 -0
  120. package/node_modules/luxon/src/impl/english.js +233 -0
  121. package/node_modules/luxon/src/impl/formats.js +176 -0
  122. package/node_modules/luxon/src/impl/formatter.js +434 -0
  123. package/node_modules/luxon/src/impl/invalid.js +14 -0
  124. package/node_modules/luxon/src/impl/locale.js +569 -0
  125. package/node_modules/luxon/src/impl/regexParser.js +335 -0
  126. package/node_modules/luxon/src/impl/tokenParser.js +505 -0
  127. package/node_modules/luxon/src/impl/util.js +330 -0
  128. package/node_modules/luxon/src/impl/zoneUtil.js +34 -0
  129. package/node_modules/luxon/src/info.js +205 -0
  130. package/node_modules/luxon/src/interval.js +669 -0
  131. package/node_modules/luxon/src/luxon.js +26 -0
  132. package/node_modules/luxon/src/package.json +4 -0
  133. package/node_modules/luxon/src/settings.js +180 -0
  134. package/node_modules/luxon/src/zone.js +97 -0
  135. package/node_modules/luxon/src/zones/IANAZone.js +235 -0
  136. package/node_modules/luxon/src/zones/fixedOffsetZone.js +150 -0
  137. package/node_modules/luxon/src/zones/invalidZone.js +53 -0
  138. package/node_modules/luxon/src/zones/systemZone.js +61 -0
  139. package/package.json +33 -24
@@ -0,0 +1,569 @@
1
+ import { hasLocaleWeekInfo, hasRelative, padStart, roundTo, validateWeekSettings } from "./util.js";
2
+ import * as English from "./english.js";
3
+ import Settings from "../settings.js";
4
+ import DateTime from "../datetime.js";
5
+ import IANAZone from "../zones/IANAZone.js";
6
+
7
+ // todo - remap caching
8
+
9
+ let intlLFCache = {};
10
+ function getCachedLF(locString, opts = {}) {
11
+ const key = JSON.stringify([locString, opts]);
12
+ let dtf = intlLFCache[key];
13
+ if (!dtf) {
14
+ dtf = new Intl.ListFormat(locString, opts);
15
+ intlLFCache[key] = dtf;
16
+ }
17
+ return dtf;
18
+ }
19
+
20
+ const intlDTCache = new Map();
21
+ function getCachedDTF(locString, opts = {}) {
22
+ const key = JSON.stringify([locString, opts]);
23
+ let dtf = intlDTCache.get(key);
24
+ if (dtf === undefined) {
25
+ dtf = new Intl.DateTimeFormat(locString, opts);
26
+ intlDTCache.set(key, dtf);
27
+ }
28
+ return dtf;
29
+ }
30
+
31
+ const intlNumCache = new Map();
32
+ function getCachedINF(locString, opts = {}) {
33
+ const key = JSON.stringify([locString, opts]);
34
+ let inf = intlNumCache.get(key);
35
+ if (inf === undefined) {
36
+ inf = new Intl.NumberFormat(locString, opts);
37
+ intlNumCache.set(key, inf);
38
+ }
39
+ return inf;
40
+ }
41
+
42
+ const intlRelCache = new Map();
43
+ function getCachedRTF(locString, opts = {}) {
44
+ const { base, ...cacheKeyOpts } = opts; // exclude `base` from the options
45
+ const key = JSON.stringify([locString, cacheKeyOpts]);
46
+ let inf = intlRelCache.get(key);
47
+ if (inf === undefined) {
48
+ inf = new Intl.RelativeTimeFormat(locString, opts);
49
+ intlRelCache.set(key, inf);
50
+ }
51
+ return inf;
52
+ }
53
+
54
+ let sysLocaleCache = null;
55
+ function systemLocale() {
56
+ if (sysLocaleCache) {
57
+ return sysLocaleCache;
58
+ } else {
59
+ sysLocaleCache = new Intl.DateTimeFormat().resolvedOptions().locale;
60
+ return sysLocaleCache;
61
+ }
62
+ }
63
+
64
+ const intlResolvedOptionsCache = new Map();
65
+ function getCachedIntResolvedOptions(locString) {
66
+ let opts = intlResolvedOptionsCache.get(locString);
67
+ if (opts === undefined) {
68
+ opts = new Intl.DateTimeFormat(locString).resolvedOptions();
69
+ intlResolvedOptionsCache.set(locString, opts);
70
+ }
71
+ return opts;
72
+ }
73
+
74
+ const weekInfoCache = new Map();
75
+ function getCachedWeekInfo(locString) {
76
+ let data = weekInfoCache.get(locString);
77
+ if (!data) {
78
+ const locale = new Intl.Locale(locString);
79
+ // browsers currently implement this as a property, but spec says it should be a getter function
80
+ data = "getWeekInfo" in locale ? locale.getWeekInfo() : locale.weekInfo;
81
+ // minimalDays was removed from WeekInfo: https://github.com/tc39/proposal-intl-locale-info/issues/86
82
+ if (!("minimalDays" in data)) {
83
+ data = { ...fallbackWeekSettings, ...data };
84
+ }
85
+ weekInfoCache.set(locString, data);
86
+ }
87
+ return data;
88
+ }
89
+
90
+ function parseLocaleString(localeStr) {
91
+ // I really want to avoid writing a BCP 47 parser
92
+ // see, e.g. https://github.com/wooorm/bcp-47
93
+ // Instead, we'll do this:
94
+
95
+ // a) if the string has no -u extensions, just leave it alone
96
+ // b) if it does, use Intl to resolve everything
97
+ // c) if Intl fails, try again without the -u
98
+
99
+ // private subtags and unicode subtags have ordering requirements,
100
+ // and we're not properly parsing this, so just strip out the
101
+ // private ones if they exist.
102
+ const xIndex = localeStr.indexOf("-x-");
103
+ if (xIndex !== -1) {
104
+ localeStr = localeStr.substring(0, xIndex);
105
+ }
106
+
107
+ const uIndex = localeStr.indexOf("-u-");
108
+ if (uIndex === -1) {
109
+ return [localeStr];
110
+ } else {
111
+ let options;
112
+ let selectedStr;
113
+ try {
114
+ options = getCachedDTF(localeStr).resolvedOptions();
115
+ selectedStr = localeStr;
116
+ } catch (e) {
117
+ const smaller = localeStr.substring(0, uIndex);
118
+ options = getCachedDTF(smaller).resolvedOptions();
119
+ selectedStr = smaller;
120
+ }
121
+
122
+ const { numberingSystem, calendar } = options;
123
+ return [selectedStr, numberingSystem, calendar];
124
+ }
125
+ }
126
+
127
+ function intlConfigString(localeStr, numberingSystem, outputCalendar) {
128
+ if (outputCalendar || numberingSystem) {
129
+ if (!localeStr.includes("-u-")) {
130
+ localeStr += "-u";
131
+ }
132
+
133
+ if (outputCalendar) {
134
+ localeStr += `-ca-${outputCalendar}`;
135
+ }
136
+
137
+ if (numberingSystem) {
138
+ localeStr += `-nu-${numberingSystem}`;
139
+ }
140
+ return localeStr;
141
+ } else {
142
+ return localeStr;
143
+ }
144
+ }
145
+
146
+ function mapMonths(f) {
147
+ const ms = [];
148
+ for (let i = 1; i <= 12; i++) {
149
+ const dt = DateTime.utc(2009, i, 1);
150
+ ms.push(f(dt));
151
+ }
152
+ return ms;
153
+ }
154
+
155
+ function mapWeekdays(f) {
156
+ const ms = [];
157
+ for (let i = 1; i <= 7; i++) {
158
+ const dt = DateTime.utc(2016, 11, 13 + i);
159
+ ms.push(f(dt));
160
+ }
161
+ return ms;
162
+ }
163
+
164
+ function listStuff(loc, length, englishFn, intlFn) {
165
+ const mode = loc.listingMode();
166
+
167
+ if (mode === "error") {
168
+ return null;
169
+ } else if (mode === "en") {
170
+ return englishFn(length);
171
+ } else {
172
+ return intlFn(length);
173
+ }
174
+ }
175
+
176
+ function supportsFastNumbers(loc) {
177
+ if (loc.numberingSystem && loc.numberingSystem !== "latn") {
178
+ return false;
179
+ } else {
180
+ return (
181
+ loc.numberingSystem === "latn" ||
182
+ !loc.locale ||
183
+ loc.locale.startsWith("en") ||
184
+ getCachedIntResolvedOptions(loc.locale).numberingSystem === "latn"
185
+ );
186
+ }
187
+ }
188
+
189
+ /**
190
+ * @private
191
+ */
192
+
193
+ class PolyNumberFormatter {
194
+ constructor(intl, forceSimple, opts) {
195
+ this.padTo = opts.padTo || 0;
196
+ this.floor = opts.floor || false;
197
+
198
+ const { padTo, floor, ...otherOpts } = opts;
199
+
200
+ if (!forceSimple || Object.keys(otherOpts).length > 0) {
201
+ const intlOpts = { useGrouping: false, ...opts };
202
+ if (opts.padTo > 0) intlOpts.minimumIntegerDigits = opts.padTo;
203
+ this.inf = getCachedINF(intl, intlOpts);
204
+ }
205
+ }
206
+
207
+ format(i) {
208
+ if (this.inf) {
209
+ const fixed = this.floor ? Math.floor(i) : i;
210
+ return this.inf.format(fixed);
211
+ } else {
212
+ // to match the browser's numberformatter defaults
213
+ const fixed = this.floor ? Math.floor(i) : roundTo(i, 3);
214
+ return padStart(fixed, this.padTo);
215
+ }
216
+ }
217
+ }
218
+
219
+ /**
220
+ * @private
221
+ */
222
+
223
+ class PolyDateFormatter {
224
+ constructor(dt, intl, opts) {
225
+ this.opts = opts;
226
+ this.originalZone = undefined;
227
+
228
+ let z = undefined;
229
+ if (this.opts.timeZone) {
230
+ // Don't apply any workarounds if a timeZone is explicitly provided in opts
231
+ this.dt = dt;
232
+ } else if (dt.zone.type === "fixed") {
233
+ // UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like.
234
+ // That is why fixed-offset TZ is set to that unless it is:
235
+ // 1. Representing offset 0 when UTC is used to maintain previous behavior and does not become GMT.
236
+ // 2. Unsupported by the browser:
237
+ // - some do not support Etc/
238
+ // - < Etc/GMT-14, > Etc/GMT+12, and 30-minute or 45-minute offsets are not part of tzdata
239
+ const gmtOffset = -1 * (dt.offset / 60);
240
+ const offsetZ = gmtOffset >= 0 ? `Etc/GMT+${gmtOffset}` : `Etc/GMT${gmtOffset}`;
241
+ if (dt.offset !== 0 && IANAZone.create(offsetZ).valid) {
242
+ z = offsetZ;
243
+ this.dt = dt;
244
+ } else {
245
+ // Not all fixed-offset zones like Etc/+4:30 are present in tzdata so
246
+ // we manually apply the offset and substitute the zone as needed.
247
+ z = "UTC";
248
+ this.dt = dt.offset === 0 ? dt : dt.setZone("UTC").plus({ minutes: dt.offset });
249
+ this.originalZone = dt.zone;
250
+ }
251
+ } else if (dt.zone.type === "system") {
252
+ this.dt = dt;
253
+ } else if (dt.zone.type === "iana") {
254
+ this.dt = dt;
255
+ z = dt.zone.name;
256
+ } else {
257
+ // Custom zones can have any offset / offsetName so we just manually
258
+ // apply the offset and substitute the zone as needed.
259
+ z = "UTC";
260
+ this.dt = dt.setZone("UTC").plus({ minutes: dt.offset });
261
+ this.originalZone = dt.zone;
262
+ }
263
+
264
+ const intlOpts = { ...this.opts };
265
+ intlOpts.timeZone = intlOpts.timeZone || z;
266
+ this.dtf = getCachedDTF(intl, intlOpts);
267
+ }
268
+
269
+ format() {
270
+ if (this.originalZone) {
271
+ // If we have to substitute in the actual zone name, we have to use
272
+ // formatToParts so that the timezone can be replaced.
273
+ return this.formatToParts()
274
+ .map(({ value }) => value)
275
+ .join("");
276
+ }
277
+ return this.dtf.format(this.dt.toJSDate());
278
+ }
279
+
280
+ formatToParts() {
281
+ const parts = this.dtf.formatToParts(this.dt.toJSDate());
282
+ if (this.originalZone) {
283
+ return parts.map((part) => {
284
+ if (part.type === "timeZoneName") {
285
+ const offsetName = this.originalZone.offsetName(this.dt.ts, {
286
+ locale: this.dt.locale,
287
+ format: this.opts.timeZoneName,
288
+ });
289
+ return {
290
+ ...part,
291
+ value: offsetName,
292
+ };
293
+ } else {
294
+ return part;
295
+ }
296
+ });
297
+ }
298
+ return parts;
299
+ }
300
+
301
+ resolvedOptions() {
302
+ return this.dtf.resolvedOptions();
303
+ }
304
+ }
305
+
306
+ /**
307
+ * @private
308
+ */
309
+ class PolyRelFormatter {
310
+ constructor(intl, isEnglish, opts) {
311
+ this.opts = { style: "long", ...opts };
312
+ if (!isEnglish && hasRelative()) {
313
+ this.rtf = getCachedRTF(intl, opts);
314
+ }
315
+ }
316
+
317
+ format(count, unit) {
318
+ if (this.rtf) {
319
+ return this.rtf.format(count, unit);
320
+ } else {
321
+ return English.formatRelativeTime(unit, count, this.opts.numeric, this.opts.style !== "long");
322
+ }
323
+ }
324
+
325
+ formatToParts(count, unit) {
326
+ if (this.rtf) {
327
+ return this.rtf.formatToParts(count, unit);
328
+ } else {
329
+ return [];
330
+ }
331
+ }
332
+ }
333
+
334
+ const fallbackWeekSettings = {
335
+ firstDay: 1,
336
+ minimalDays: 4,
337
+ weekend: [6, 7],
338
+ };
339
+
340
+ /**
341
+ * @private
342
+ */
343
+ export default class Locale {
344
+ static fromOpts(opts) {
345
+ return Locale.create(
346
+ opts.locale,
347
+ opts.numberingSystem,
348
+ opts.outputCalendar,
349
+ opts.weekSettings,
350
+ opts.defaultToEN
351
+ );
352
+ }
353
+
354
+ static create(locale, numberingSystem, outputCalendar, weekSettings, defaultToEN = false) {
355
+ const specifiedLocale = locale || Settings.defaultLocale;
356
+ // the system locale is useful for human-readable strings but annoying for parsing/formatting known formats
357
+ const localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale());
358
+ const numberingSystemR = numberingSystem || Settings.defaultNumberingSystem;
359
+ const outputCalendarR = outputCalendar || Settings.defaultOutputCalendar;
360
+ const weekSettingsR = validateWeekSettings(weekSettings) || Settings.defaultWeekSettings;
361
+ return new Locale(localeR, numberingSystemR, outputCalendarR, weekSettingsR, specifiedLocale);
362
+ }
363
+
364
+ static resetCache() {
365
+ sysLocaleCache = null;
366
+ intlDTCache.clear();
367
+ intlNumCache.clear();
368
+ intlRelCache.clear();
369
+ intlResolvedOptionsCache.clear();
370
+ weekInfoCache.clear();
371
+ }
372
+
373
+ static fromObject({ locale, numberingSystem, outputCalendar, weekSettings } = {}) {
374
+ return Locale.create(locale, numberingSystem, outputCalendar, weekSettings);
375
+ }
376
+
377
+ constructor(locale, numbering, outputCalendar, weekSettings, specifiedLocale) {
378
+ const [parsedLocale, parsedNumberingSystem, parsedOutputCalendar] = parseLocaleString(locale);
379
+
380
+ this.locale = parsedLocale;
381
+ this.numberingSystem = numbering || parsedNumberingSystem || null;
382
+ this.outputCalendar = outputCalendar || parsedOutputCalendar || null;
383
+ this.weekSettings = weekSettings;
384
+ this.intl = intlConfigString(this.locale, this.numberingSystem, this.outputCalendar);
385
+
386
+ this.weekdaysCache = { format: {}, standalone: {} };
387
+ this.monthsCache = { format: {}, standalone: {} };
388
+ this.meridiemCache = null;
389
+ this.eraCache = {};
390
+
391
+ this.specifiedLocale = specifiedLocale;
392
+ this.fastNumbersCached = null;
393
+ }
394
+
395
+ get fastNumbers() {
396
+ if (this.fastNumbersCached == null) {
397
+ this.fastNumbersCached = supportsFastNumbers(this);
398
+ }
399
+
400
+ return this.fastNumbersCached;
401
+ }
402
+
403
+ listingMode() {
404
+ const isActuallyEn = this.isEnglish();
405
+ const hasNoWeirdness =
406
+ (this.numberingSystem === null || this.numberingSystem === "latn") &&
407
+ (this.outputCalendar === null || this.outputCalendar === "gregory");
408
+ return isActuallyEn && hasNoWeirdness ? "en" : "intl";
409
+ }
410
+
411
+ clone(alts) {
412
+ if (!alts || Object.getOwnPropertyNames(alts).length === 0) {
413
+ return this;
414
+ } else {
415
+ return Locale.create(
416
+ alts.locale || this.specifiedLocale,
417
+ alts.numberingSystem || this.numberingSystem,
418
+ alts.outputCalendar || this.outputCalendar,
419
+ validateWeekSettings(alts.weekSettings) || this.weekSettings,
420
+ alts.defaultToEN || false
421
+ );
422
+ }
423
+ }
424
+
425
+ redefaultToEN(alts = {}) {
426
+ return this.clone({ ...alts, defaultToEN: true });
427
+ }
428
+
429
+ redefaultToSystem(alts = {}) {
430
+ return this.clone({ ...alts, defaultToEN: false });
431
+ }
432
+
433
+ months(length, format = false) {
434
+ return listStuff(this, length, English.months, () => {
435
+ // Workaround for "ja" locale: formatToParts does not label all parts of the month
436
+ // as "month" and for this locale there is no difference between "format" and "non-format".
437
+ // As such, just use format() instead of formatToParts() and take the whole string
438
+ const monthSpecialCase = this.intl === "ja" || this.intl.startsWith("ja-");
439
+ format &= !monthSpecialCase;
440
+ const intl = format ? { month: length, day: "numeric" } : { month: length },
441
+ formatStr = format ? "format" : "standalone";
442
+ if (!this.monthsCache[formatStr][length]) {
443
+ const mapper = !monthSpecialCase
444
+ ? (dt) => this.extract(dt, intl, "month")
445
+ : (dt) => this.dtFormatter(dt, intl).format();
446
+ this.monthsCache[formatStr][length] = mapMonths(mapper);
447
+ }
448
+ return this.monthsCache[formatStr][length];
449
+ });
450
+ }
451
+
452
+ weekdays(length, format = false) {
453
+ return listStuff(this, length, English.weekdays, () => {
454
+ const intl = format
455
+ ? { weekday: length, year: "numeric", month: "long", day: "numeric" }
456
+ : { weekday: length },
457
+ formatStr = format ? "format" : "standalone";
458
+ if (!this.weekdaysCache[formatStr][length]) {
459
+ this.weekdaysCache[formatStr][length] = mapWeekdays((dt) =>
460
+ this.extract(dt, intl, "weekday")
461
+ );
462
+ }
463
+ return this.weekdaysCache[formatStr][length];
464
+ });
465
+ }
466
+
467
+ meridiems() {
468
+ return listStuff(
469
+ this,
470
+ undefined,
471
+ () => English.meridiems,
472
+ () => {
473
+ // In theory there could be aribitrary day periods. We're gonna assume there are exactly two
474
+ // for AM and PM. This is probably wrong, but it's makes parsing way easier.
475
+ if (!this.meridiemCache) {
476
+ const intl = { hour: "numeric", hourCycle: "h12" };
477
+ this.meridiemCache = [DateTime.utc(2016, 11, 13, 9), DateTime.utc(2016, 11, 13, 19)].map(
478
+ (dt) => this.extract(dt, intl, "dayperiod")
479
+ );
480
+ }
481
+
482
+ return this.meridiemCache;
483
+ }
484
+ );
485
+ }
486
+
487
+ eras(length) {
488
+ return listStuff(this, length, English.eras, () => {
489
+ const intl = { era: length };
490
+
491
+ // This is problematic. Different calendars are going to define eras totally differently. What I need is the minimum set of dates
492
+ // to definitely enumerate them.
493
+ if (!this.eraCache[length]) {
494
+ this.eraCache[length] = [DateTime.utc(-40, 1, 1), DateTime.utc(2017, 1, 1)].map((dt) =>
495
+ this.extract(dt, intl, "era")
496
+ );
497
+ }
498
+
499
+ return this.eraCache[length];
500
+ });
501
+ }
502
+
503
+ extract(dt, intlOpts, field) {
504
+ const df = this.dtFormatter(dt, intlOpts),
505
+ results = df.formatToParts(),
506
+ matching = results.find((m) => m.type.toLowerCase() === field);
507
+ return matching ? matching.value : null;
508
+ }
509
+
510
+ numberFormatter(opts = {}) {
511
+ // this forcesimple option is never used (the only caller short-circuits on it, but it seems safer to leave)
512
+ // (in contrast, the rest of the condition is used heavily)
513
+ return new PolyNumberFormatter(this.intl, opts.forceSimple || this.fastNumbers, opts);
514
+ }
515
+
516
+ dtFormatter(dt, intlOpts = {}) {
517
+ return new PolyDateFormatter(dt, this.intl, intlOpts);
518
+ }
519
+
520
+ relFormatter(opts = {}) {
521
+ return new PolyRelFormatter(this.intl, this.isEnglish(), opts);
522
+ }
523
+
524
+ listFormatter(opts = {}) {
525
+ return getCachedLF(this.intl, opts);
526
+ }
527
+
528
+ isEnglish() {
529
+ return (
530
+ this.locale === "en" ||
531
+ this.locale.toLowerCase() === "en-us" ||
532
+ getCachedIntResolvedOptions(this.intl).locale.startsWith("en-us")
533
+ );
534
+ }
535
+
536
+ getWeekSettings() {
537
+ if (this.weekSettings) {
538
+ return this.weekSettings;
539
+ } else if (!hasLocaleWeekInfo()) {
540
+ return fallbackWeekSettings;
541
+ } else {
542
+ return getCachedWeekInfo(this.locale);
543
+ }
544
+ }
545
+
546
+ getStartOfWeek() {
547
+ return this.getWeekSettings().firstDay;
548
+ }
549
+
550
+ getMinDaysInFirstWeek() {
551
+ return this.getWeekSettings().minimalDays;
552
+ }
553
+
554
+ getWeekendDays() {
555
+ return this.getWeekSettings().weekend;
556
+ }
557
+
558
+ equals(other) {
559
+ return (
560
+ this.locale === other.locale &&
561
+ this.numberingSystem === other.numberingSystem &&
562
+ this.outputCalendar === other.outputCalendar
563
+ );
564
+ }
565
+
566
+ toString() {
567
+ return `Locale(${this.locale}, ${this.numberingSystem}, ${this.outputCalendar})`;
568
+ }
569
+ }