@vercel/build-utils 14.18.0 → 14.19.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 +8 -0
- package/DEV_MANIFEST.md +1 -1
- package/dist/index.js +2 -2
- package/dist/schedules.d.ts +15 -24
- package/dist/schedules.js +15 -131
- package/dist/types.d.ts +12 -29
- package/package.json +3 -3
package/dist/schedules.d.ts
CHANGED
|
@@ -1,29 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Schedule } from './types';
|
|
2
2
|
/**
|
|
3
|
-
* A `vercel.json` schedule
|
|
4
|
-
*
|
|
3
|
+
* A `vercel.json` schedule. `entrypoint` targets are resolved to `function`
|
|
4
|
+
* before the schedule reaches Build Output.
|
|
5
5
|
*/
|
|
6
|
-
export type VercelJsonSchedule =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
declare const FLAT_TARGET_KEYS: readonly ["path", "function", "topic", "entrypoint"];
|
|
12
|
-
type FlatTargetKey = (typeof FLAT_TARGET_KEYS)[number];
|
|
6
|
+
export type VercelJsonSchedule = Schedule | (Pick<Schedule, 'name' | 'schedule' | 'timezone' | 'jitter'> & {
|
|
7
|
+
entrypoint: string;
|
|
8
|
+
});
|
|
9
|
+
declare const SCHEDULE_TARGET_KEYS: readonly ["path", "function", "topic", "entrypoint"];
|
|
10
|
+
export type ScheduleTargetKey = (typeof SCHEDULE_TARGET_KEYS)[number];
|
|
13
11
|
/**
|
|
14
|
-
* Name for a
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
12
|
+
* Name for a schedule without one: a hex hash of `type|ref|expression`, which
|
|
13
|
+
* always satisfies the schedule name pattern. Build Output omits these names
|
|
14
|
+
* (except for entrypoint schedules) and the API derives its own; using the
|
|
15
|
+
* same hash keeps `vercel dev` names the same as deployed ones.
|
|
18
16
|
*/
|
|
19
|
-
export declare function defaultScheduleName(type:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* Format a schedule for Build Output `config.json`. Pass `includeName: false`
|
|
23
|
-
* for a name derived by `parseScheduleDefinition`; the API derives the same
|
|
24
|
-
* name for a flat Build Output schedule without one.
|
|
25
|
-
*/
|
|
26
|
-
export declare function formatBuildOutputSchedule(schedule: Schedule, { includeName }?: {
|
|
27
|
-
includeName?: boolean;
|
|
28
|
-
}): FlatBuildOutputSchedule;
|
|
17
|
+
export declare function defaultScheduleName(type: ScheduleTargetKey, ref: string, expression: string): string;
|
|
18
|
+
/** The schedule's `name`, or its default name when it has none. */
|
|
19
|
+
export declare function getScheduleName(schedule: VercelJsonSchedule): string;
|
|
29
20
|
export {};
|
package/dist/schedules.js
CHANGED
|
@@ -19,150 +19,34 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var schedules_exports = {};
|
|
20
20
|
__export(schedules_exports, {
|
|
21
21
|
defaultScheduleName: () => defaultScheduleName,
|
|
22
|
-
|
|
23
|
-
parseScheduleDefinition: () => parseScheduleDefinition
|
|
22
|
+
getScheduleName: () => getScheduleName
|
|
24
23
|
});
|
|
25
24
|
module.exports = __toCommonJS(schedules_exports);
|
|
26
25
|
var import_crypto = require("crypto");
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
26
|
+
const SCHEDULE_TARGET_KEYS = [
|
|
27
|
+
"path",
|
|
28
|
+
"function",
|
|
29
|
+
"topic",
|
|
30
|
+
"entrypoint"
|
|
31
31
|
];
|
|
32
32
|
const DEFAULT_NAME_HASH_LENGTH = 12;
|
|
33
33
|
function defaultScheduleName(type, ref, expression) {
|
|
34
34
|
return (0, import_crypto.createHash)("sha1").update(`${type}|${ref}|${expression}`).digest("hex").slice(0, DEFAULT_NAME_HASH_LENGTH);
|
|
35
35
|
}
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
function isFlatScheduleDefinition(obj) {
|
|
43
|
-
return "schedule" in obj;
|
|
44
|
-
}
|
|
45
|
-
function assertNotMixedFields(obj) {
|
|
46
|
-
const hasLegacy = "expression" in obj || "target" in obj;
|
|
47
|
-
const hasFlatSchedule = "schedule" in obj || "requestMethod" in obj;
|
|
48
|
-
const flatTargetCount = FLAT_TARGET_KEYS.filter((key) => key in obj).length;
|
|
49
|
-
if (hasLegacy && (hasFlatSchedule || flatTargetCount > 0)) {
|
|
50
|
-
throw new Error(
|
|
51
|
-
"Schedule cannot mix legacy fields (`expression`, `target`) with flat fields (`schedule`, `path`, `requestMethod`, `function`, `topic`, `entrypoint`)."
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function parseLegacySchedule(obj) {
|
|
56
|
-
const { name, expression, target, timezone } = obj;
|
|
57
|
-
if (typeof name !== "string") {
|
|
58
|
-
throw new Error("Schedule `name` must be a string.");
|
|
59
|
-
}
|
|
60
|
-
if (!isRecord(expression) || typeof expression.cron !== "string") {
|
|
61
|
-
throw new Error("Schedule `expression.cron` must be a string.");
|
|
62
|
-
}
|
|
63
|
-
for (const key of Object.keys(expression)) {
|
|
64
|
-
if (key !== "cron" && key !== "jitter") {
|
|
65
|
-
throw new Error(
|
|
66
|
-
`Schedule \`expression\` cannot include \`${key}\`. Use top-level \`timezone\` for IANA timezones.`
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (!isRecord(target)) {
|
|
71
|
-
throw new Error("Schedule `target` must be an object.");
|
|
72
|
-
}
|
|
73
|
-
const parsedExpression = {
|
|
74
|
-
cron: expression.cron,
|
|
75
|
-
...expression.jitter !== void 0 ? { jitter: expression.jitter } : {}
|
|
76
|
-
};
|
|
77
|
-
let parsedTarget;
|
|
78
|
-
if (typeof target.function === "string") {
|
|
79
|
-
parsedTarget = { function: target.function };
|
|
80
|
-
} else if (typeof target.path === "string") {
|
|
81
|
-
parsedTarget = { path: target.path };
|
|
82
|
-
} else if (typeof target.topic === "string") {
|
|
83
|
-
parsedTarget = { topic: target.topic };
|
|
84
|
-
} else if (typeof target.entrypoint === "string") {
|
|
85
|
-
parsedTarget = { entrypoint: target.entrypoint };
|
|
86
|
-
} else {
|
|
87
|
-
throw new Error(
|
|
88
|
-
"Schedule `target` must include exactly one of `function`, `path`, `topic`, or `entrypoint`."
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
name,
|
|
93
|
-
expression: parsedExpression,
|
|
94
|
-
target: parsedTarget,
|
|
95
|
-
...typeof timezone === "string" ? { timezone } : {}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
function parseFlatSchedule(obj) {
|
|
99
|
-
const { name, schedule, timezone, jitter, requestMethod } = obj;
|
|
100
|
-
if (name !== void 0 && typeof name !== "string") {
|
|
101
|
-
throw new Error("Schedule `name` must be a string.");
|
|
102
|
-
}
|
|
103
|
-
if (typeof schedule !== "string") {
|
|
104
|
-
throw new Error("Schedule `schedule` must be a string.");
|
|
105
|
-
}
|
|
106
|
-
const targetKeys = FLAT_TARGET_KEYS.filter((key) => key in obj);
|
|
107
|
-
if (targetKeys.length !== 1) {
|
|
36
|
+
function getScheduleName(schedule) {
|
|
37
|
+
if (schedule.name !== void 0)
|
|
38
|
+
return schedule.name;
|
|
39
|
+
const type = SCHEDULE_TARGET_KEYS.find((key) => key in schedule);
|
|
40
|
+
if (type === void 0) {
|
|
108
41
|
throw new Error(
|
|
109
|
-
"
|
|
42
|
+
"Schedule must include one of `path`, `function`, `topic`, or `entrypoint`."
|
|
110
43
|
);
|
|
111
44
|
}
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
if (typeof targetValue !== "string") {
|
|
115
|
-
throw new Error(`Schedule \`${targetKey}\` must be a string.`);
|
|
116
|
-
}
|
|
117
|
-
if (requestMethod !== void 0) {
|
|
118
|
-
if (targetKey !== "path") {
|
|
119
|
-
throw new Error("Schedule `requestMethod` is only valid with `path`.");
|
|
120
|
-
}
|
|
121
|
-
if (!SCHEDULE_REQUEST_METHODS.includes(requestMethod)) {
|
|
122
|
-
throw new Error("Schedule `requestMethod` must be `GET` or `POST`.");
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const target = {
|
|
126
|
-
[targetKey]: targetValue,
|
|
127
|
-
...requestMethod !== void 0 ? { requestMethod } : {}
|
|
128
|
-
};
|
|
129
|
-
return {
|
|
130
|
-
name: name ?? defaultScheduleName(targetKey, targetValue, schedule),
|
|
131
|
-
expression: {
|
|
132
|
-
cron: schedule,
|
|
133
|
-
...jitter !== void 0 ? { jitter } : {}
|
|
134
|
-
},
|
|
135
|
-
target,
|
|
136
|
-
...typeof timezone === "string" ? { timezone } : {}
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
function parseScheduleDefinition(raw) {
|
|
140
|
-
if (!isRecord(raw)) {
|
|
141
|
-
throw new Error("Schedule must be an object.");
|
|
142
|
-
}
|
|
143
|
-
assertNotMixedFields(raw);
|
|
144
|
-
if (isLegacyScheduleDefinition(raw)) {
|
|
145
|
-
return parseLegacySchedule(raw);
|
|
146
|
-
}
|
|
147
|
-
if (isFlatScheduleDefinition(raw)) {
|
|
148
|
-
return parseFlatSchedule(raw);
|
|
149
|
-
}
|
|
150
|
-
throw new Error(
|
|
151
|
-
"Schedule must use either the legacy shape (`expression`, `target`, `name`) or the flat shape (`schedule` and one target field)."
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
function formatBuildOutputSchedule(schedule, { includeName = true } = {}) {
|
|
155
|
-
return {
|
|
156
|
-
...includeName ? { name: schedule.name } : {},
|
|
157
|
-
schedule: schedule.expression.cron,
|
|
158
|
-
...schedule.target,
|
|
159
|
-
...schedule.timezone !== void 0 ? { timezone: schedule.timezone } : {},
|
|
160
|
-
...schedule.expression.jitter !== void 0 ? { jitter: schedule.expression.jitter } : {}
|
|
161
|
-
};
|
|
45
|
+
const ref = schedule[type];
|
|
46
|
+
return defaultScheduleName(type, ref ?? "", schedule.schedule);
|
|
162
47
|
}
|
|
163
48
|
// Annotate the CommonJS export names for ESM import in node:
|
|
164
49
|
0 && (module.exports = {
|
|
165
50
|
defaultScheduleName,
|
|
166
|
-
|
|
167
|
-
parseScheduleDefinition
|
|
51
|
+
getScheduleName
|
|
168
52
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -654,46 +654,29 @@ export interface Cron {
|
|
|
654
654
|
path: string;
|
|
655
655
|
schedule: string;
|
|
656
656
|
}
|
|
657
|
-
export interface ScheduleExpression {
|
|
658
|
-
/** Cron expression describing when the schedule fires (REQUIRED) */
|
|
659
|
-
cron: string;
|
|
660
|
-
/** Maximum random delay applied to each firing, from 1 to 15 whole minutes (OPTIONAL) */
|
|
661
|
-
jitter?: number;
|
|
662
|
-
}
|
|
663
657
|
export type ScheduleRequestMethod = 'GET' | 'POST';
|
|
664
|
-
export type
|
|
665
|
-
/**
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
path: string;
|
|
670
|
-
/** HTTP method used to invoke `path`. Defaults to `POST`. */
|
|
671
|
-
requestMethod?: ScheduleRequestMethod;
|
|
672
|
-
} | {
|
|
673
|
-
/** Name of the queue topic to publish to */
|
|
674
|
-
topic: string;
|
|
675
|
-
};
|
|
676
|
-
export interface Schedule {
|
|
677
|
-
/** Unique name of the schedule within the deployment (REQUIRED) */
|
|
678
|
-
name: string;
|
|
679
|
-
expression: ScheduleExpression;
|
|
680
|
-
/** IANA timezone for cron evaluation, e.g. "America/New_York". Defaults to UTC. */
|
|
681
|
-
timezone?: string;
|
|
682
|
-
target: ScheduleTarget;
|
|
683
|
-
}
|
|
684
|
-
/** Flat schedule shape in Build Output API `config.json`. */
|
|
685
|
-
export type FlatBuildOutputSchedule = {
|
|
686
|
-
/** Defaults to a hash of the target and cron expression. */
|
|
658
|
+
export type Schedule = {
|
|
659
|
+
/**
|
|
660
|
+
* Unique name of the schedule within the deployment. Defaults to a hash of
|
|
661
|
+
* the target and cron expression.
|
|
662
|
+
*/
|
|
687
663
|
name?: string;
|
|
664
|
+
/** Cron expression describing when the schedule fires (REQUIRED) */
|
|
688
665
|
schedule: string;
|
|
666
|
+
/** IANA timezone for cron evaluation, e.g. "America/New_York". Defaults to UTC. */
|
|
689
667
|
timezone?: string;
|
|
668
|
+
/** Maximum random delay applied to each firing, from 1 to 15 whole minutes (OPTIONAL) */
|
|
690
669
|
jitter?: number;
|
|
691
670
|
} & ({
|
|
671
|
+
/** Deployment path to invoke over HTTP, like `crons[].path`. Must start with `/`. */
|
|
692
672
|
path: string;
|
|
673
|
+
/** HTTP method used to invoke `path`. Defaults to `POST`. */
|
|
693
674
|
requestMethod?: ScheduleRequestMethod;
|
|
694
675
|
} | {
|
|
676
|
+
/** Build output path of the function to invoke, e.g. "api/cron" */
|
|
695
677
|
function: string;
|
|
696
678
|
} | {
|
|
679
|
+
/** Name of the queue topic to publish to */
|
|
697
680
|
topic: string;
|
|
698
681
|
});
|
|
699
682
|
export interface ServiceQueueTopic {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/build-utils",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.19.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.js",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"vitest": "4.1.10",
|
|
53
53
|
"typescript": "4.9.5",
|
|
54
54
|
"yazl": "2.5.1",
|
|
55
|
-
"@vercel/
|
|
56
|
-
"@vercel/
|
|
55
|
+
"@vercel/error-utils": "2.2.1",
|
|
56
|
+
"@vercel/routing-utils": "6.6.0"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "node build.mjs",
|