@vercel/build-utils 14.13.2 → 14.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.
- package/CHANGELOG.md +12 -0
- package/dist/daemons.d.ts +30 -0
- package/dist/daemons.js +37 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -3
- package/dist/schedules.d.ts +12 -0
- package/dist/schedules.js +148 -0
- package/dist/types.d.ts +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FlatBuildOutputSchedule, Schedule, ScheduleTarget } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A `vercel.json` schedule in the nested shape. `entrypoint` targets are
|
|
4
|
+
* resolved to `function` before the schedule reaches Build Output.
|
|
5
|
+
*/
|
|
6
|
+
export type VercelJsonSchedule = Omit<Schedule, 'target'> & {
|
|
7
|
+
target: ScheduleTarget | {
|
|
8
|
+
entrypoint: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare function parseScheduleDefinition(raw: unknown): VercelJsonSchedule;
|
|
12
|
+
export declare function formatBuildOutputSchedule(schedule: Schedule): FlatBuildOutputSchedule;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var schedules_exports = {};
|
|
20
|
+
__export(schedules_exports, {
|
|
21
|
+
formatBuildOutputSchedule: () => formatBuildOutputSchedule,
|
|
22
|
+
parseScheduleDefinition: () => parseScheduleDefinition
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(schedules_exports);
|
|
25
|
+
const FLAT_TARGET_KEYS = ["path", "function", "topic", "entrypoint"];
|
|
26
|
+
function isRecord(value) {
|
|
27
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
28
|
+
}
|
|
29
|
+
function isLegacyScheduleDefinition(obj) {
|
|
30
|
+
return "expression" in obj && "target" in obj;
|
|
31
|
+
}
|
|
32
|
+
function isFlatScheduleDefinition(obj) {
|
|
33
|
+
return "schedule" in obj;
|
|
34
|
+
}
|
|
35
|
+
function assertNotMixedFields(obj) {
|
|
36
|
+
const hasLegacy = "expression" in obj || "target" in obj;
|
|
37
|
+
const hasFlatSchedule = "schedule" in obj;
|
|
38
|
+
const flatTargetCount = FLAT_TARGET_KEYS.filter((key) => key in obj).length;
|
|
39
|
+
if (hasLegacy && (hasFlatSchedule || flatTargetCount > 0)) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
"Schedule cannot mix legacy fields (`expression`, `target`) with flat fields (`schedule`, `path`, `function`, `topic`, `entrypoint`)."
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function parseLegacySchedule(obj) {
|
|
46
|
+
const { name, expression, target, timezone } = obj;
|
|
47
|
+
if (typeof name !== "string") {
|
|
48
|
+
throw new Error("Schedule `name` must be a string.");
|
|
49
|
+
}
|
|
50
|
+
if (!isRecord(expression) || typeof expression.cron !== "string") {
|
|
51
|
+
throw new Error("Schedule `expression.cron` must be a string.");
|
|
52
|
+
}
|
|
53
|
+
for (const key of Object.keys(expression)) {
|
|
54
|
+
if (key !== "cron" && key !== "jitter") {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Schedule \`expression\` cannot include \`${key}\`. Use top-level \`timezone\` for IANA timezones.`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!isRecord(target)) {
|
|
61
|
+
throw new Error("Schedule `target` must be an object.");
|
|
62
|
+
}
|
|
63
|
+
const parsedExpression = {
|
|
64
|
+
cron: expression.cron,
|
|
65
|
+
...expression.jitter !== void 0 ? { jitter: expression.jitter } : {}
|
|
66
|
+
};
|
|
67
|
+
let parsedTarget;
|
|
68
|
+
if (typeof target.function === "string") {
|
|
69
|
+
parsedTarget = { function: target.function };
|
|
70
|
+
} else if (typeof target.path === "string") {
|
|
71
|
+
parsedTarget = { path: target.path };
|
|
72
|
+
} else if (typeof target.topic === "string") {
|
|
73
|
+
parsedTarget = { topic: target.topic };
|
|
74
|
+
} else if (typeof target.entrypoint === "string") {
|
|
75
|
+
parsedTarget = { entrypoint: target.entrypoint };
|
|
76
|
+
} else {
|
|
77
|
+
throw new Error(
|
|
78
|
+
"Schedule `target` must include exactly one of `function`, `path`, `topic`, or `entrypoint`."
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
name,
|
|
83
|
+
expression: parsedExpression,
|
|
84
|
+
target: parsedTarget,
|
|
85
|
+
...typeof timezone === "string" ? { timezone } : {}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function parseFlatSchedule(obj) {
|
|
89
|
+
const { name, schedule, timezone, jitter } = obj;
|
|
90
|
+
if (typeof name !== "string") {
|
|
91
|
+
throw new Error("Schedule `name` must be a string.");
|
|
92
|
+
}
|
|
93
|
+
if (typeof schedule !== "string") {
|
|
94
|
+
throw new Error("Schedule `schedule` must be a string.");
|
|
95
|
+
}
|
|
96
|
+
const targetKeys = FLAT_TARGET_KEYS.filter((key) => key in obj);
|
|
97
|
+
if (targetKeys.length !== 1) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
"Flat schedule must include exactly one of `path`, `function`, `topic`, or `entrypoint`."
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
const targetKey = targetKeys[0];
|
|
103
|
+
const targetValue = obj[targetKey];
|
|
104
|
+
if (typeof targetValue !== "string") {
|
|
105
|
+
throw new Error(`Schedule \`${targetKey}\` must be a string.`);
|
|
106
|
+
}
|
|
107
|
+
const target = {
|
|
108
|
+
[targetKey]: targetValue
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
name,
|
|
112
|
+
expression: {
|
|
113
|
+
cron: schedule,
|
|
114
|
+
...jitter !== void 0 ? { jitter } : {}
|
|
115
|
+
},
|
|
116
|
+
target,
|
|
117
|
+
...typeof timezone === "string" ? { timezone } : {}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function parseScheduleDefinition(raw) {
|
|
121
|
+
if (!isRecord(raw)) {
|
|
122
|
+
throw new Error("Schedule must be an object.");
|
|
123
|
+
}
|
|
124
|
+
assertNotMixedFields(raw);
|
|
125
|
+
if (isLegacyScheduleDefinition(raw)) {
|
|
126
|
+
return parseLegacySchedule(raw);
|
|
127
|
+
}
|
|
128
|
+
if (isFlatScheduleDefinition(raw)) {
|
|
129
|
+
return parseFlatSchedule(raw);
|
|
130
|
+
}
|
|
131
|
+
throw new Error(
|
|
132
|
+
"Schedule must use either the legacy shape (`expression`, `target`, `name`) or the flat shape (`schedule`, `name`, and one target field)."
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
function formatBuildOutputSchedule(schedule) {
|
|
136
|
+
return {
|
|
137
|
+
name: schedule.name,
|
|
138
|
+
schedule: schedule.expression.cron,
|
|
139
|
+
...schedule.target,
|
|
140
|
+
...schedule.timezone !== void 0 ? { timezone: schedule.timezone } : {},
|
|
141
|
+
...schedule.expression.jitter !== void 0 ? { jitter: schedule.expression.jitter } : {}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
145
|
+
0 && (module.exports = {
|
|
146
|
+
formatBuildOutputSchedule,
|
|
147
|
+
parseScheduleDefinition
|
|
148
|
+
});
|
package/dist/types.d.ts
CHANGED
|
@@ -669,6 +669,19 @@ export interface Schedule {
|
|
|
669
669
|
timezone?: string;
|
|
670
670
|
target: ScheduleTarget;
|
|
671
671
|
}
|
|
672
|
+
/** Flat schedule shape in Build Output API `config.json`. */
|
|
673
|
+
export type FlatBuildOutputSchedule = {
|
|
674
|
+
name: string;
|
|
675
|
+
schedule: string;
|
|
676
|
+
timezone?: string;
|
|
677
|
+
jitter?: number;
|
|
678
|
+
} & ({
|
|
679
|
+
path: string;
|
|
680
|
+
} | {
|
|
681
|
+
function: string;
|
|
682
|
+
} | {
|
|
683
|
+
topic: string;
|
|
684
|
+
});
|
|
672
685
|
export interface ServiceQueueTopic {
|
|
673
686
|
topic: string;
|
|
674
687
|
retryAfterSeconds?: number;
|