@cloudsnorkel/cdk-github-runners 0.14.24 → 0.15.1

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 (142) hide show
  1. package/.jsii +5953 -602
  2. package/API.md +1349 -115
  3. package/README.md +53 -1
  4. package/assets/delete-failed-runner.lambda/index.js +122 -9
  5. package/assets/idle-runner-repear.lambda/index.js +153 -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 +118 -8
  11. package/assets/status.lambda/index.js +121 -8
  12. package/assets/token-retriever.lambda/index.js +121 -8
  13. package/assets/warm-runner-manager.lambda/index.js +5909 -0
  14. package/assets/webhook-handler.lambda/index.js +126 -11
  15. package/assets/webhook-redelivery.lambda/index.js +139 -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 +18 -2
  39. package/lib/providers/codebuild.js +15 -4
  40. package/lib/providers/common.d.ts +47 -3
  41. package/lib/providers/common.js +29 -5
  42. package/lib/providers/composite.js +14 -19
  43. package/lib/providers/ec2.d.ts +9 -2
  44. package/lib/providers/ec2.js +84 -42
  45. package/lib/providers/ecs.d.ts +19 -2
  46. package/lib/providers/ecs.js +49 -44
  47. package/lib/providers/fargate.d.ts +2 -2
  48. package/lib/providers/fargate.js +19 -36
  49. package/lib/providers/lambda.d.ts +2 -2
  50. package/lib/providers/lambda.js +3 -3
  51. package/lib/runner.d.ts +31 -3
  52. package/lib/runner.js +171 -46
  53. package/lib/secrets.js +1 -1
  54. package/lib/setup.lambda.js +2 -2
  55. package/lib/utils.d.ts +10 -1
  56. package/lib/utils.js +15 -1
  57. package/lib/warm-runner-manager-function.d.ts +18 -0
  58. package/lib/warm-runner-manager-function.js +24 -0
  59. package/lib/warm-runner-manager.lambda.d.ts +41 -0
  60. package/lib/warm-runner-manager.lambda.js +487 -0
  61. package/lib/warm-runner.d.ts +155 -0
  62. package/lib/warm-runner.js +217 -0
  63. package/lib/webhook-handler.lambda.js +5 -3
  64. package/lib/webhook-redelivery.lambda.js +17 -16
  65. package/lib/webhook.d.ts +4 -0
  66. package/lib/webhook.js +2 -1
  67. package/node_modules/cron-parser/LICENSE +21 -0
  68. package/node_modules/cron-parser/README.md +408 -0
  69. package/node_modules/cron-parser/dist/CronDate.js +518 -0
  70. package/node_modules/cron-parser/dist/CronExpression.js +520 -0
  71. package/node_modules/cron-parser/dist/CronExpressionParser.js +382 -0
  72. package/node_modules/cron-parser/dist/CronFieldCollection.js +371 -0
  73. package/node_modules/cron-parser/dist/CronFileParser.js +109 -0
  74. package/node_modules/cron-parser/dist/fields/CronDayOfMonth.js +44 -0
  75. package/node_modules/cron-parser/dist/fields/CronDayOfWeek.js +51 -0
  76. package/node_modules/cron-parser/dist/fields/CronField.js +214 -0
  77. package/node_modules/cron-parser/dist/fields/CronHour.js +40 -0
  78. package/node_modules/cron-parser/dist/fields/CronMinute.js +40 -0
  79. package/node_modules/cron-parser/dist/fields/CronMonth.js +44 -0
  80. package/node_modules/cron-parser/dist/fields/CronSecond.js +40 -0
  81. package/node_modules/cron-parser/dist/fields/index.js +24 -0
  82. package/node_modules/cron-parser/dist/fields/types.js +2 -0
  83. package/node_modules/cron-parser/dist/index.js +31 -0
  84. package/node_modules/cron-parser/dist/types/CronDate.d.ts +288 -0
  85. package/node_modules/cron-parser/dist/types/CronExpression.d.ts +118 -0
  86. package/node_modules/cron-parser/dist/types/CronExpressionParser.d.ts +70 -0
  87. package/node_modules/cron-parser/dist/types/CronFieldCollection.d.ts +153 -0
  88. package/node_modules/cron-parser/dist/types/CronFileParser.d.ts +30 -0
  89. package/node_modules/cron-parser/dist/types/fields/CronDayOfMonth.d.ts +25 -0
  90. package/node_modules/cron-parser/dist/types/fields/CronDayOfWeek.d.ts +30 -0
  91. package/node_modules/cron-parser/dist/types/fields/CronField.d.ts +130 -0
  92. package/node_modules/cron-parser/dist/types/fields/CronHour.d.ts +23 -0
  93. package/node_modules/cron-parser/dist/types/fields/CronMinute.d.ts +23 -0
  94. package/node_modules/cron-parser/dist/types/fields/CronMonth.d.ts +24 -0
  95. package/node_modules/cron-parser/dist/types/fields/CronSecond.d.ts +23 -0
  96. package/node_modules/cron-parser/dist/types/fields/index.d.ts +8 -0
  97. package/node_modules/cron-parser/dist/types/fields/types.d.ts +18 -0
  98. package/node_modules/cron-parser/dist/types/index.d.ts +8 -0
  99. package/node_modules/cron-parser/dist/types/utils/random.d.ts +10 -0
  100. package/node_modules/cron-parser/dist/utils/random.js +38 -0
  101. package/node_modules/cron-parser/package.json +117 -0
  102. package/node_modules/luxon/LICENSE.md +7 -0
  103. package/node_modules/luxon/README.md +55 -0
  104. package/node_modules/luxon/build/amd/luxon.js +8741 -0
  105. package/node_modules/luxon/build/amd/luxon.js.map +1 -0
  106. package/node_modules/luxon/build/cjs-browser/luxon.js +8739 -0
  107. package/node_modules/luxon/build/cjs-browser/luxon.js.map +1 -0
  108. package/node_modules/luxon/build/es6/luxon.mjs +8133 -0
  109. package/node_modules/luxon/build/es6/luxon.mjs.map +1 -0
  110. package/node_modules/luxon/build/global/luxon.js +8744 -0
  111. package/node_modules/luxon/build/global/luxon.js.map +1 -0
  112. package/node_modules/luxon/build/global/luxon.min.js +1 -0
  113. package/node_modules/luxon/build/global/luxon.min.js.map +1 -0
  114. package/node_modules/luxon/build/node/luxon.js +7792 -0
  115. package/node_modules/luxon/build/node/luxon.js.map +1 -0
  116. package/node_modules/luxon/package.json +87 -0
  117. package/node_modules/luxon/src/datetime.js +2603 -0
  118. package/node_modules/luxon/src/duration.js +1009 -0
  119. package/node_modules/luxon/src/errors.js +61 -0
  120. package/node_modules/luxon/src/impl/conversions.js +206 -0
  121. package/node_modules/luxon/src/impl/diff.js +95 -0
  122. package/node_modules/luxon/src/impl/digits.js +94 -0
  123. package/node_modules/luxon/src/impl/english.js +233 -0
  124. package/node_modules/luxon/src/impl/formats.js +176 -0
  125. package/node_modules/luxon/src/impl/formatter.js +434 -0
  126. package/node_modules/luxon/src/impl/invalid.js +14 -0
  127. package/node_modules/luxon/src/impl/locale.js +569 -0
  128. package/node_modules/luxon/src/impl/regexParser.js +335 -0
  129. package/node_modules/luxon/src/impl/tokenParser.js +505 -0
  130. package/node_modules/luxon/src/impl/util.js +330 -0
  131. package/node_modules/luxon/src/impl/zoneUtil.js +34 -0
  132. package/node_modules/luxon/src/info.js +205 -0
  133. package/node_modules/luxon/src/interval.js +669 -0
  134. package/node_modules/luxon/src/luxon.js +26 -0
  135. package/node_modules/luxon/src/package.json +4 -0
  136. package/node_modules/luxon/src/settings.js +180 -0
  137. package/node_modules/luxon/src/zone.js +97 -0
  138. package/node_modules/luxon/src/zones/IANAZone.js +235 -0
  139. package/node_modules/luxon/src/zones/fixedOffsetZone.js +150 -0
  140. package/node_modules/luxon/src/zones/invalidZone.js +53 -0
  141. package/node_modules/luxon/src/zones/systemZone.js +61 -0
  142. package/package.json +33 -24
@@ -0,0 +1,176 @@
1
+ /**
2
+ * @private
3
+ */
4
+
5
+ const n = "numeric",
6
+ s = "short",
7
+ l = "long";
8
+
9
+ export const DATE_SHORT = {
10
+ year: n,
11
+ month: n,
12
+ day: n,
13
+ };
14
+
15
+ export const DATE_MED = {
16
+ year: n,
17
+ month: s,
18
+ day: n,
19
+ };
20
+
21
+ export const DATE_MED_WITH_WEEKDAY = {
22
+ year: n,
23
+ month: s,
24
+ day: n,
25
+ weekday: s,
26
+ };
27
+
28
+ export const DATE_FULL = {
29
+ year: n,
30
+ month: l,
31
+ day: n,
32
+ };
33
+
34
+ export const DATE_HUGE = {
35
+ year: n,
36
+ month: l,
37
+ day: n,
38
+ weekday: l,
39
+ };
40
+
41
+ export const TIME_SIMPLE = {
42
+ hour: n,
43
+ minute: n,
44
+ };
45
+
46
+ export const TIME_WITH_SECONDS = {
47
+ hour: n,
48
+ minute: n,
49
+ second: n,
50
+ };
51
+
52
+ export const TIME_WITH_SHORT_OFFSET = {
53
+ hour: n,
54
+ minute: n,
55
+ second: n,
56
+ timeZoneName: s,
57
+ };
58
+
59
+ export const TIME_WITH_LONG_OFFSET = {
60
+ hour: n,
61
+ minute: n,
62
+ second: n,
63
+ timeZoneName: l,
64
+ };
65
+
66
+ export const TIME_24_SIMPLE = {
67
+ hour: n,
68
+ minute: n,
69
+ hourCycle: "h23",
70
+ };
71
+
72
+ export const TIME_24_WITH_SECONDS = {
73
+ hour: n,
74
+ minute: n,
75
+ second: n,
76
+ hourCycle: "h23",
77
+ };
78
+
79
+ export const TIME_24_WITH_SHORT_OFFSET = {
80
+ hour: n,
81
+ minute: n,
82
+ second: n,
83
+ hourCycle: "h23",
84
+ timeZoneName: s,
85
+ };
86
+
87
+ export const TIME_24_WITH_LONG_OFFSET = {
88
+ hour: n,
89
+ minute: n,
90
+ second: n,
91
+ hourCycle: "h23",
92
+ timeZoneName: l,
93
+ };
94
+
95
+ export const DATETIME_SHORT = {
96
+ year: n,
97
+ month: n,
98
+ day: n,
99
+ hour: n,
100
+ minute: n,
101
+ };
102
+
103
+ export const DATETIME_SHORT_WITH_SECONDS = {
104
+ year: n,
105
+ month: n,
106
+ day: n,
107
+ hour: n,
108
+ minute: n,
109
+ second: n,
110
+ };
111
+
112
+ export const DATETIME_MED = {
113
+ year: n,
114
+ month: s,
115
+ day: n,
116
+ hour: n,
117
+ minute: n,
118
+ };
119
+
120
+ export const DATETIME_MED_WITH_SECONDS = {
121
+ year: n,
122
+ month: s,
123
+ day: n,
124
+ hour: n,
125
+ minute: n,
126
+ second: n,
127
+ };
128
+
129
+ export const DATETIME_MED_WITH_WEEKDAY = {
130
+ year: n,
131
+ month: s,
132
+ day: n,
133
+ weekday: s,
134
+ hour: n,
135
+ minute: n,
136
+ };
137
+
138
+ export const DATETIME_FULL = {
139
+ year: n,
140
+ month: l,
141
+ day: n,
142
+ hour: n,
143
+ minute: n,
144
+ timeZoneName: s,
145
+ };
146
+
147
+ export const DATETIME_FULL_WITH_SECONDS = {
148
+ year: n,
149
+ month: l,
150
+ day: n,
151
+ hour: n,
152
+ minute: n,
153
+ second: n,
154
+ timeZoneName: s,
155
+ };
156
+
157
+ export const DATETIME_HUGE = {
158
+ year: n,
159
+ month: l,
160
+ day: n,
161
+ weekday: l,
162
+ hour: n,
163
+ minute: n,
164
+ timeZoneName: l,
165
+ };
166
+
167
+ export const DATETIME_HUGE_WITH_SECONDS = {
168
+ year: n,
169
+ month: l,
170
+ day: n,
171
+ weekday: l,
172
+ hour: n,
173
+ minute: n,
174
+ second: n,
175
+ timeZoneName: l,
176
+ };
@@ -0,0 +1,434 @@
1
+ import * as English from "./english.js";
2
+ import * as Formats from "./formats.js";
3
+ import { padStart } from "./util.js";
4
+
5
+ function stringifyTokens(splits, tokenToString) {
6
+ let s = "";
7
+ for (const token of splits) {
8
+ if (token.literal) {
9
+ s += token.val;
10
+ } else {
11
+ s += tokenToString(token.val);
12
+ }
13
+ }
14
+ return s;
15
+ }
16
+
17
+ const macroTokenToFormatOpts = {
18
+ D: Formats.DATE_SHORT,
19
+ DD: Formats.DATE_MED,
20
+ DDD: Formats.DATE_FULL,
21
+ DDDD: Formats.DATE_HUGE,
22
+ t: Formats.TIME_SIMPLE,
23
+ tt: Formats.TIME_WITH_SECONDS,
24
+ ttt: Formats.TIME_WITH_SHORT_OFFSET,
25
+ tttt: Formats.TIME_WITH_LONG_OFFSET,
26
+ T: Formats.TIME_24_SIMPLE,
27
+ TT: Formats.TIME_24_WITH_SECONDS,
28
+ TTT: Formats.TIME_24_WITH_SHORT_OFFSET,
29
+ TTTT: Formats.TIME_24_WITH_LONG_OFFSET,
30
+ f: Formats.DATETIME_SHORT,
31
+ ff: Formats.DATETIME_MED,
32
+ fff: Formats.DATETIME_FULL,
33
+ ffff: Formats.DATETIME_HUGE,
34
+ F: Formats.DATETIME_SHORT_WITH_SECONDS,
35
+ FF: Formats.DATETIME_MED_WITH_SECONDS,
36
+ FFF: Formats.DATETIME_FULL_WITH_SECONDS,
37
+ FFFF: Formats.DATETIME_HUGE_WITH_SECONDS,
38
+ };
39
+
40
+ /**
41
+ * @private
42
+ */
43
+
44
+ export default class Formatter {
45
+ static create(locale, opts = {}) {
46
+ return new Formatter(locale, opts);
47
+ }
48
+
49
+ static parseFormat(fmt) {
50
+ // white-space is always considered a literal in user-provided formats
51
+ // the " " token has a special meaning (see unitForToken)
52
+
53
+ let current = null,
54
+ currentFull = "",
55
+ bracketed = false;
56
+ const splits = [];
57
+ for (let i = 0; i < fmt.length; i++) {
58
+ const c = fmt.charAt(i);
59
+ if (c === "'") {
60
+ // turn '' into a literal signal quote instead of just skipping the empty literal
61
+ if (currentFull.length > 0 || bracketed) {
62
+ splits.push({
63
+ literal: bracketed || /^\s+$/.test(currentFull),
64
+ val: currentFull === "" ? "'" : currentFull,
65
+ });
66
+ }
67
+ current = null;
68
+ currentFull = "";
69
+ bracketed = !bracketed;
70
+ } else if (bracketed) {
71
+ currentFull += c;
72
+ } else if (c === current) {
73
+ currentFull += c;
74
+ } else {
75
+ if (currentFull.length > 0) {
76
+ splits.push({ literal: /^\s+$/.test(currentFull), val: currentFull });
77
+ }
78
+ currentFull = c;
79
+ current = c;
80
+ }
81
+ }
82
+
83
+ if (currentFull.length > 0) {
84
+ splits.push({ literal: bracketed || /^\s+$/.test(currentFull), val: currentFull });
85
+ }
86
+
87
+ return splits;
88
+ }
89
+
90
+ static macroTokenToFormatOpts(token) {
91
+ return macroTokenToFormatOpts[token];
92
+ }
93
+
94
+ constructor(locale, formatOpts) {
95
+ this.opts = formatOpts;
96
+ this.loc = locale;
97
+ this.systemLoc = null;
98
+ }
99
+
100
+ formatWithSystemDefault(dt, opts) {
101
+ if (this.systemLoc === null) {
102
+ this.systemLoc = this.loc.redefaultToSystem();
103
+ }
104
+ const df = this.systemLoc.dtFormatter(dt, { ...this.opts, ...opts });
105
+ return df.format();
106
+ }
107
+
108
+ dtFormatter(dt, opts = {}) {
109
+ return this.loc.dtFormatter(dt, { ...this.opts, ...opts });
110
+ }
111
+
112
+ formatDateTime(dt, opts) {
113
+ return this.dtFormatter(dt, opts).format();
114
+ }
115
+
116
+ formatDateTimeParts(dt, opts) {
117
+ return this.dtFormatter(dt, opts).formatToParts();
118
+ }
119
+
120
+ formatInterval(interval, opts) {
121
+ const df = this.dtFormatter(interval.start, opts);
122
+ return df.dtf.formatRange(interval.start.toJSDate(), interval.end.toJSDate());
123
+ }
124
+
125
+ resolvedOptions(dt, opts) {
126
+ return this.dtFormatter(dt, opts).resolvedOptions();
127
+ }
128
+
129
+ num(n, p = 0, signDisplay = undefined) {
130
+ // we get some perf out of doing this here, annoyingly
131
+ if (this.opts.forceSimple) {
132
+ return padStart(n, p);
133
+ }
134
+
135
+ const opts = { ...this.opts };
136
+
137
+ if (p > 0) {
138
+ opts.padTo = p;
139
+ }
140
+ if (signDisplay) {
141
+ opts.signDisplay = signDisplay;
142
+ }
143
+
144
+ return this.loc.numberFormatter(opts).format(n);
145
+ }
146
+
147
+ formatDateTimeFromString(dt, fmt) {
148
+ const knownEnglish = this.loc.listingMode() === "en",
149
+ useDateTimeFormatter = this.loc.outputCalendar && this.loc.outputCalendar !== "gregory",
150
+ string = (opts, extract) => this.loc.extract(dt, opts, extract),
151
+ formatOffset = (opts) => {
152
+ if (dt.isOffsetFixed && dt.offset === 0 && opts.allowZ) {
153
+ return "Z";
154
+ }
155
+
156
+ return dt.isValid ? dt.zone.formatOffset(dt.ts, opts.format) : "";
157
+ },
158
+ meridiem = () =>
159
+ knownEnglish
160
+ ? English.meridiemForDateTime(dt)
161
+ : string({ hour: "numeric", hourCycle: "h12" }, "dayperiod"),
162
+ month = (length, standalone) =>
163
+ knownEnglish
164
+ ? English.monthForDateTime(dt, length)
165
+ : string(standalone ? { month: length } : { month: length, day: "numeric" }, "month"),
166
+ weekday = (length, standalone) =>
167
+ knownEnglish
168
+ ? English.weekdayForDateTime(dt, length)
169
+ : string(
170
+ standalone ? { weekday: length } : { weekday: length, month: "long", day: "numeric" },
171
+ "weekday"
172
+ ),
173
+ maybeMacro = (token) => {
174
+ const formatOpts = Formatter.macroTokenToFormatOpts(token);
175
+ if (formatOpts) {
176
+ return this.formatWithSystemDefault(dt, formatOpts);
177
+ } else {
178
+ return token;
179
+ }
180
+ },
181
+ era = (length) =>
182
+ knownEnglish ? English.eraForDateTime(dt, length) : string({ era: length }, "era"),
183
+ tokenToString = (token) => {
184
+ // Where possible: https://cldr.unicode.org/translation/date-time/date-time-symbols
185
+ switch (token) {
186
+ // ms
187
+ case "S":
188
+ return this.num(dt.millisecond);
189
+ case "u":
190
+ // falls through
191
+ case "SSS":
192
+ return this.num(dt.millisecond, 3);
193
+ // seconds
194
+ case "s":
195
+ return this.num(dt.second);
196
+ case "ss":
197
+ return this.num(dt.second, 2);
198
+ // fractional seconds
199
+ case "uu":
200
+ return this.num(Math.floor(dt.millisecond / 10), 2);
201
+ case "uuu":
202
+ return this.num(Math.floor(dt.millisecond / 100));
203
+ // minutes
204
+ case "m":
205
+ return this.num(dt.minute);
206
+ case "mm":
207
+ return this.num(dt.minute, 2);
208
+ // hours
209
+ case "h":
210
+ return this.num(dt.hour % 12 === 0 ? 12 : dt.hour % 12);
211
+ case "hh":
212
+ return this.num(dt.hour % 12 === 0 ? 12 : dt.hour % 12, 2);
213
+ case "H":
214
+ return this.num(dt.hour);
215
+ case "HH":
216
+ return this.num(dt.hour, 2);
217
+ // offset
218
+ case "Z":
219
+ // like +6
220
+ return formatOffset({ format: "narrow", allowZ: this.opts.allowZ });
221
+ case "ZZ":
222
+ // like +06:00
223
+ return formatOffset({ format: "short", allowZ: this.opts.allowZ });
224
+ case "ZZZ":
225
+ // like +0600
226
+ return formatOffset({ format: "techie", allowZ: this.opts.allowZ });
227
+ case "ZZZZ":
228
+ // like EST
229
+ return dt.zone.offsetName(dt.ts, { format: "short", locale: this.loc.locale });
230
+ case "ZZZZZ":
231
+ // like Eastern Standard Time
232
+ return dt.zone.offsetName(dt.ts, { format: "long", locale: this.loc.locale });
233
+ // zone
234
+ case "z":
235
+ // like America/New_York
236
+ return dt.zoneName;
237
+ // meridiems
238
+ case "a":
239
+ return meridiem();
240
+ // dates
241
+ case "d":
242
+ return useDateTimeFormatter ? string({ day: "numeric" }, "day") : this.num(dt.day);
243
+ case "dd":
244
+ return useDateTimeFormatter ? string({ day: "2-digit" }, "day") : this.num(dt.day, 2);
245
+ // weekdays - standalone
246
+ case "c":
247
+ // like 1
248
+ return this.num(dt.weekday);
249
+ case "ccc":
250
+ // like 'Tues'
251
+ return weekday("short", true);
252
+ case "cccc":
253
+ // like 'Tuesday'
254
+ return weekday("long", true);
255
+ case "ccccc":
256
+ // like 'T'
257
+ return weekday("narrow", true);
258
+ // weekdays - format
259
+ case "E":
260
+ // like 1
261
+ return this.num(dt.weekday);
262
+ case "EEE":
263
+ // like 'Tues'
264
+ return weekday("short", false);
265
+ case "EEEE":
266
+ // like 'Tuesday'
267
+ return weekday("long", false);
268
+ case "EEEEE":
269
+ // like 'T'
270
+ return weekday("narrow", false);
271
+ // months - standalone
272
+ case "L":
273
+ // like 1
274
+ return useDateTimeFormatter
275
+ ? string({ month: "numeric", day: "numeric" }, "month")
276
+ : this.num(dt.month);
277
+ case "LL":
278
+ // like 01, doesn't seem to work
279
+ return useDateTimeFormatter
280
+ ? string({ month: "2-digit", day: "numeric" }, "month")
281
+ : this.num(dt.month, 2);
282
+ case "LLL":
283
+ // like Jan
284
+ return month("short", true);
285
+ case "LLLL":
286
+ // like January
287
+ return month("long", true);
288
+ case "LLLLL":
289
+ // like J
290
+ return month("narrow", true);
291
+ // months - format
292
+ case "M":
293
+ // like 1
294
+ return useDateTimeFormatter
295
+ ? string({ month: "numeric" }, "month")
296
+ : this.num(dt.month);
297
+ case "MM":
298
+ // like 01
299
+ return useDateTimeFormatter
300
+ ? string({ month: "2-digit" }, "month")
301
+ : this.num(dt.month, 2);
302
+ case "MMM":
303
+ // like Jan
304
+ return month("short", false);
305
+ case "MMMM":
306
+ // like January
307
+ return month("long", false);
308
+ case "MMMMM":
309
+ // like J
310
+ return month("narrow", false);
311
+ // years
312
+ case "y":
313
+ // like 2014
314
+ return useDateTimeFormatter ? string({ year: "numeric" }, "year") : this.num(dt.year);
315
+ case "yy":
316
+ // like 14
317
+ return useDateTimeFormatter
318
+ ? string({ year: "2-digit" }, "year")
319
+ : this.num(dt.year.toString().slice(-2), 2);
320
+ case "yyyy":
321
+ // like 0012
322
+ return useDateTimeFormatter
323
+ ? string({ year: "numeric" }, "year")
324
+ : this.num(dt.year, 4);
325
+ case "yyyyyy":
326
+ // like 000012
327
+ return useDateTimeFormatter
328
+ ? string({ year: "numeric" }, "year")
329
+ : this.num(dt.year, 6);
330
+ // eras
331
+ case "G":
332
+ // like AD
333
+ return era("short");
334
+ case "GG":
335
+ // like Anno Domini
336
+ return era("long");
337
+ case "GGGGG":
338
+ return era("narrow");
339
+ case "kk":
340
+ return this.num(dt.weekYear.toString().slice(-2), 2);
341
+ case "kkkk":
342
+ return this.num(dt.weekYear, 4);
343
+ case "W":
344
+ return this.num(dt.weekNumber);
345
+ case "WW":
346
+ return this.num(dt.weekNumber, 2);
347
+ case "n":
348
+ return this.num(dt.localWeekNumber);
349
+ case "nn":
350
+ return this.num(dt.localWeekNumber, 2);
351
+ case "ii":
352
+ return this.num(dt.localWeekYear.toString().slice(-2), 2);
353
+ case "iiii":
354
+ return this.num(dt.localWeekYear, 4);
355
+ case "o":
356
+ return this.num(dt.ordinal);
357
+ case "ooo":
358
+ return this.num(dt.ordinal, 3);
359
+ case "q":
360
+ // like 1
361
+ return this.num(dt.quarter);
362
+ case "qq":
363
+ // like 01
364
+ return this.num(dt.quarter, 2);
365
+ case "X":
366
+ return this.num(Math.floor(dt.ts / 1000));
367
+ case "x":
368
+ return this.num(dt.ts);
369
+ default:
370
+ return maybeMacro(token);
371
+ }
372
+ };
373
+
374
+ return stringifyTokens(Formatter.parseFormat(fmt), tokenToString);
375
+ }
376
+
377
+ formatDurationFromString(dur, fmt) {
378
+ const invertLargest = this.opts.signMode === "negativeLargestOnly" ? -1 : 1;
379
+ const tokenToField = (token) => {
380
+ switch (token[0]) {
381
+ case "S":
382
+ return "milliseconds";
383
+ case "s":
384
+ return "seconds";
385
+ case "m":
386
+ return "minutes";
387
+ case "h":
388
+ return "hours";
389
+ case "d":
390
+ return "days";
391
+ case "w":
392
+ return "weeks";
393
+ case "M":
394
+ return "months";
395
+ case "y":
396
+ return "years";
397
+ default:
398
+ return null;
399
+ }
400
+ },
401
+ tokenToString = (lildur, info) => (token) => {
402
+ const mapped = tokenToField(token);
403
+ if (mapped) {
404
+ const inversionFactor =
405
+ info.isNegativeDuration && mapped !== info.largestUnit ? invertLargest : 1;
406
+ let signDisplay;
407
+ if (this.opts.signMode === "negativeLargestOnly" && mapped !== info.largestUnit) {
408
+ signDisplay = "never";
409
+ } else if (this.opts.signMode === "all") {
410
+ signDisplay = "always";
411
+ } else {
412
+ // "auto" and "negative" are the same, but "auto" has better support
413
+ signDisplay = "auto";
414
+ }
415
+ return this.num(lildur.get(mapped) * inversionFactor, token.length, signDisplay);
416
+ } else {
417
+ return token;
418
+ }
419
+ },
420
+ tokens = Formatter.parseFormat(fmt),
421
+ realTokens = tokens.reduce(
422
+ (found, { literal, val }) => (literal ? found : found.concat(val)),
423
+ []
424
+ ),
425
+ collapsed = dur.shiftTo(...realTokens.map(tokenToField).filter((t) => t)),
426
+ durationInfo = {
427
+ isNegativeDuration: collapsed < 0,
428
+ // this relies on "collapsed" being based on "shiftTo", which builds up the object
429
+ // in order
430
+ largestUnit: Object.keys(collapsed.values)[0],
431
+ };
432
+ return stringifyTokens(tokens, tokenToString(collapsed, durationInfo));
433
+ }
434
+ }
@@ -0,0 +1,14 @@
1
+ export default class Invalid {
2
+ constructor(reason, explanation) {
3
+ this.reason = reason;
4
+ this.explanation = explanation;
5
+ }
6
+
7
+ toMessage() {
8
+ if (this.explanation) {
9
+ return `${this.reason}: ${this.explanation}`;
10
+ } else {
11
+ return this.reason;
12
+ }
13
+ }
14
+ }