@vercel/build-utils 14.22.0 → 14.23.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.
@@ -1,21 +1,26 @@
1
- import type { Schedule } from './types';
1
+ import type { Schedule, ScheduleDefinition, Schedules } from './types';
2
2
  /**
3
- * A `vercel.json` schedule. `entrypoint` targets are resolved to `function`
4
- * before the schedule reaches Build Output.
3
+ * A `vercel.json` schedule without its name, which is its key in `schedules`.
4
+ * `entrypoint` targets are resolved to `function` before the schedule reaches
5
+ * Build Output.
5
6
  */
6
- export type VercelJsonSchedule = Schedule | (Pick<Schedule, 'name' | 'schedule' | 'timezone' | 'jitter'> & {
7
+ export type VercelJsonScheduleDefinition = ScheduleDefinition | (Pick<ScheduleDefinition, 'schedule' | 'timezone' | 'jitter'> & {
7
8
  entrypoint: string;
8
9
  });
9
- declare const SCHEDULE_TARGET_KEYS: readonly ["path", "function", "topic", "entrypoint"];
10
- export type ScheduleTargetKey = (typeof SCHEDULE_TARGET_KEYS)[number];
10
+ /** `vercel.json#schedules`: schedules keyed by name. */
11
+ export type VercelJsonSchedules = Record<string, VercelJsonScheduleDefinition>;
12
+ /** A `vercel.json` schedule with its name. */
13
+ export type VercelJsonSchedule = {
14
+ name: string;
15
+ } & VercelJsonScheduleDefinition;
11
16
  /**
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. A function
16
- * target's service is appended as `|service`, matching the API.
17
+ * The schedules in `schedules` with their names, in key order. Accepts the
18
+ * deprecated array format, which already names each schedule.
17
19
  */
18
- export declare function defaultScheduleName(type: ScheduleTargetKey, ref: string, expression: string, service?: string): string;
19
- /** The schedule's `name`, or its default name when it has none. */
20
- export declare function getScheduleName(schedule: VercelJsonSchedule): string;
21
- export {};
20
+ export declare function getNamedSchedules(schedules: Schedules | readonly Schedule[] | undefined): Schedule[];
21
+ export declare function getNamedSchedules(schedules: VercelJsonSchedules | readonly VercelJsonSchedule[] | undefined): VercelJsonSchedule[];
22
+ /** Named schedules keyed by name, for `schedules` in Build Output. */
23
+ export declare function toScheduleRecord(schedules: readonly Schedule[]): Schedules;
24
+ export declare function toScheduleRecord(schedules: readonly VercelJsonSchedule[]): VercelJsonSchedules;
25
+ /** Warning for `schedules` in the deprecated array format. */
26
+ export declare function getSchedulesArrayDeprecationWarning(source: string): string;
package/dist/schedules.js CHANGED
@@ -18,37 +18,32 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var schedules_exports = {};
20
20
  __export(schedules_exports, {
21
- defaultScheduleName: () => defaultScheduleName,
22
- getScheduleName: () => getScheduleName
21
+ getNamedSchedules: () => getNamedSchedules,
22
+ getSchedulesArrayDeprecationWarning: () => getSchedulesArrayDeprecationWarning,
23
+ toScheduleRecord: () => toScheduleRecord
23
24
  });
24
25
  module.exports = __toCommonJS(schedules_exports);
25
- var import_crypto = require("crypto");
26
- const SCHEDULE_TARGET_KEYS = [
27
- "path",
28
- "function",
29
- "topic",
30
- "entrypoint"
31
- ];
32
- const DEFAULT_NAME_HASH_LENGTH = 12;
33
- function defaultScheduleName(type, ref, expression, service) {
34
- const input = `${type}|${ref}|${expression}`;
35
- return (0, import_crypto.createHash)("sha1").update(service === void 0 ? input : `${input}|${service}`).digest("hex").slice(0, DEFAULT_NAME_HASH_LENGTH);
26
+ function getNamedSchedules(schedules) {
27
+ if (schedules === void 0)
28
+ return [];
29
+ if (Array.isArray(schedules))
30
+ return [...schedules];
31
+ return Object.entries(schedules).map(([name, schedule]) => ({
32
+ name,
33
+ ...schedule
34
+ }));
36
35
  }
37
- function getScheduleName(schedule) {
38
- if (schedule.name !== void 0)
39
- return schedule.name;
40
- const type = SCHEDULE_TARGET_KEYS.find((key) => key in schedule);
41
- if (type === void 0) {
42
- throw new Error(
43
- "Schedule must include one of `path`, `function`, `topic`, or `entrypoint`."
44
- );
45
- }
46
- const ref = schedule[type];
47
- const service = type === "function" && "service" in schedule ? schedule.service : void 0;
48
- return defaultScheduleName(type, ref ?? "", schedule.schedule, service);
36
+ function toScheduleRecord(schedules) {
37
+ return Object.fromEntries(
38
+ schedules.map(({ name, ...schedule }) => [name, schedule])
39
+ );
40
+ }
41
+ function getSchedulesArrayDeprecationWarning(source) {
42
+ return `Listing \`schedules\` as an array in ${source} is deprecated. Key each schedule by its name instead, like \`"schedules": { "nightly": { "schedule": "0 0 * * *", "path": "/api/cron" } }\`.`;
49
43
  }
50
44
  // Annotate the CommonJS export names for ESM import in node:
51
45
  0 && (module.exports = {
52
- defaultScheduleName,
53
- getScheduleName
46
+ getNamedSchedules,
47
+ getSchedulesArrayDeprecationWarning,
48
+ toScheduleRecord
54
49
  });
package/dist/types.d.ts CHANGED
@@ -535,8 +535,11 @@ export interface GetDevManifestOptions {
535
535
  export interface DevManifest {
536
536
  /** Complete replacement snapshot for the invoking builder scope. */
537
537
  functions: DevFunction[];
538
- /** Native framework schedules, using the static Build Output API schema. */
539
- schedules?: Schedule[];
538
+ /**
539
+ * Native framework schedules keyed by name, using the static Build Output
540
+ * API schema. The array format is deprecated.
541
+ */
542
+ schedules?: Schedules | Schedule[];
540
543
  /** Authored functions keys resolved by this provider, for unmatched diagnostics. */
541
544
  matchedFunctionPatterns: string[];
542
545
  }
@@ -668,12 +671,10 @@ export interface Cron {
668
671
  schedule: string;
669
672
  }
670
673
  export type ScheduleRequestMethod = 'GET' | 'POST';
671
- export type Schedule = {
672
- /**
673
- * Unique name of the schedule within the deployment. Defaults to a hash of
674
- * the target and cron expression.
675
- */
676
- name?: string;
674
+ /**
675
+ * A schedule without its name, which is its key in `schedules`.
676
+ */
677
+ export type ScheduleDefinition = {
677
678
  /** Cron expression describing when the schedule fires (REQUIRED) */
678
679
  schedule: string;
679
680
  /** IANA timezone for cron evaluation, e.g. "America/New_York". Defaults to UTC. */
@@ -697,6 +698,13 @@ export type Schedule = {
697
698
  /** Name of the queue topic to publish to */
698
699
  topic: string;
699
700
  });
701
+ /** Schedules keyed by name, as in Build Output `config.json#schedules`. */
702
+ export type Schedules = Record<string, ScheduleDefinition>;
703
+ /** A schedule with its name. */
704
+ export type Schedule = {
705
+ /** Unique name of the schedule within the deployment (REQUIRED) */
706
+ name: string;
707
+ } & ScheduleDefinition;
700
708
  export interface ServiceQueueTopic {
701
709
  topic: string;
702
710
  retryAfterSeconds?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/build-utils",
3
- "version": "14.22.0",
3
+ "version": "14.23.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/error-utils": "2.2.1",
56
- "@vercel/routing-utils": "6.6.0"
55
+ "@vercel/routing-utils": "6.6.0",
56
+ "@vercel/error-utils": "2.2.1"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "node build.mjs",