@vercel/functions 3.0.0 → 3.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @vercel/functions
2
2
 
3
+ ## 3.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Stronger detection of Vercel Runtime to reduce warnings ([#13776](https://github.com/vercel/vercel/pull/13776))
8
+
9
+ - Updated dependencies [[`da6ca6d80915221b7f60cd711e4fada41a828e4c`](https://github.com/vercel/vercel/commit/da6ca6d80915221b7f60cd711e4fada41a828e4c), [`da6ca6d80915221b7f60cd711e4fada41a828e4c`](https://github.com/vercel/vercel/commit/da6ca6d80915221b7f60cd711e4fada41a828e4c), [`da6ca6d80915221b7f60cd711e4fada41a828e4c`](https://github.com/vercel/vercel/commit/da6ca6d80915221b7f60cd711e4fada41a828e4c)]:
10
+ - @vercel/oidc@3.0.1
11
+
12
+ ## 3.1.0
13
+
14
+ ### Minor Changes
15
+
16
+ - Introduces Vercel Purge APIs: invalidateByTag, dangerouslyDeleteByTag ([#13867](https://github.com/vercel/vercel/pull/13867))
17
+
3
18
  ## 3.0.0
4
19
 
5
20
  ### Major Changes
@@ -61,7 +61,8 @@ let idleTimeoutResolve = () => {
61
61
  const bootTime = Date.now();
62
62
  const maximumDuration = 15 * 60 * 1e3 - 1e3;
63
63
  function waitUntilIdleTimeout(dbPool) {
64
- if (!process.env.VERCEL_URL) {
64
+ if (!process.env.VERCEL_URL || // This is not set during builds where we don't need to wait for idle connections using the mechanism
65
+ !process.env.VERCEL_REGION) {
65
66
  return;
66
67
  }
67
68
  if (idleTimeout) {
@@ -0,0 +1,22 @@
1
+ # Interface: DangerouslyDeleteOptions
2
+
3
+ [index](../modules/index.md).DangerouslyDeleteOptions
4
+
5
+ ## Table of contents
6
+
7
+ ### Properties
8
+
9
+ - [revalidationDeadlineSeconds](index.DangerouslyDeleteOptions.md#revalidationdeadlineseconds)
10
+
11
+ ## Properties
12
+
13
+ ### revalidationDeadlineSeconds
14
+
15
+ • `Optional` **revalidationDeadlineSeconds**: `number`
16
+
17
+ The time in seconds for how long the stale content can be served while revalidating the new content in the background.
18
+ If none is provided, the default is 0 and the content will be deleted immediately.
19
+
20
+ #### Defined in
21
+
22
+ [packages/functions/src/purge/types.ts:6](https://github.com/vercel/vercel/blob/main/packages/functions/src/purge/types.ts#L6)
@@ -0,0 +1,72 @@
1
+ # Interface: PurgeApi
2
+
3
+ [index](../modules/index.md).PurgeApi
4
+
5
+ Vercel Cache Purge APIs.
6
+
7
+ ## Table of contents
8
+
9
+ ### Properties
10
+
11
+ - [dangerouslyDeleteByTag](index.PurgeApi.md#dangerouslydeletebytag)
12
+ - [invalidateByTag](index.PurgeApi.md#invalidatebytag)
13
+
14
+ ## Properties
15
+
16
+ ### dangerouslyDeleteByTag
17
+
18
+ • **dangerouslyDeleteByTag**: (`tag`: `string` \| `string`[], `options?`: [`DangerouslyDeleteOptions`](index.DangerouslyDeleteOptions.md)) => [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
19
+
20
+ #### Type declaration
21
+
22
+ ▸ (`tag`, `options?`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
23
+
24
+ Delete all content associated with a tag or tags after a specified revalidation deadline.
25
+ If accessed prior to the revalidation deadline, the stale content will be served and a background revalidation will be triggered. After the revalidation deadline is reached, the content will be deleted.
26
+ The default revalidation deadline is 0 and the content will be deleted immediately.
27
+
28
+ ##### Parameters
29
+
30
+ | Name | Type | Description |
31
+ | :--------- | :-------------------------------------------------------------- | :----------------------------------------------------------------- |
32
+ | `tag` | `string` \| `string`[] | The tag or tags to delete. |
33
+ | `options?` | [`DangerouslyDeleteOptions`](index.DangerouslyDeleteOptions.md) | The options for the delete that specify the revalidation deadline. |
34
+
35
+ ##### Returns
36
+
37
+ [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
38
+
39
+ A promise that resolves when the delete is complete.
40
+
41
+ #### Defined in
42
+
43
+ [packages/functions/src/purge/types.ts:31](https://github.com/vercel/vercel/blob/main/packages/functions/src/purge/types.ts#L31)
44
+
45
+ ---
46
+
47
+ ### invalidateByTag
48
+
49
+ • **invalidateByTag**: (`tag`: `string` \| `string`[]) => [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
50
+
51
+ #### Type declaration
52
+
53
+ ▸ (`tag`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
54
+
55
+ Invalidate all content associated with a tag or tags by marking them as stale.
56
+ On the next access to content associated with any of the tags, the stale content will be served and a background revalidation will be triggered.
57
+
58
+ ##### Parameters
59
+
60
+ | Name | Type | Description |
61
+ | :---- | :--------------------- | :----------------------------- |
62
+ | `tag` | `string` \| `string`[] | The tag or tags to invalidate. |
63
+
64
+ ##### Returns
65
+
66
+ [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
67
+
68
+ A promise that resolves when the invalidate is complete.
69
+
70
+ #### Defined in
71
+
72
+ [packages/functions/src/purge/types.ts:20](https://github.com/vercel/vercel/blob/main/packages/functions/src/purge/types.ts#L20)
@@ -4,17 +4,21 @@
4
4
 
5
5
  ### Interfaces
6
6
 
7
+ - [DangerouslyDeleteOptions](../interfaces/index.DangerouslyDeleteOptions.md)
7
8
  - [Geo](../interfaces/index.Geo.md)
9
+ - [PurgeApi](../interfaces/index.PurgeApi.md)
8
10
  - [Request](../interfaces/index.Request.md)
9
11
  - [RuntimeCache](../interfaces/index.RuntimeCache.md)
10
12
 
11
13
  ### Functions
12
14
 
13
15
  - [attachDatabasePool](index.md#attachdatabasepool)
16
+ - [dangerouslyDeleteByTag](index.md#dangerouslydeletebytag)
14
17
  - [experimental_attachDatabasePool](index.md#experimental_attachdatabasepool)
15
18
  - [geolocation](index.md#geolocation)
16
19
  - [getCache](index.md#getcache)
17
20
  - [getEnv](index.md#getenv)
21
+ - [invalidateByTag](index.md#invalidatebytag)
18
22
  - [ipAddress](index.md#ipaddress)
19
23
  - [next](index.md#next)
20
24
  - [rewrite](index.md#rewrite)
@@ -52,7 +56,28 @@ attachDatabasePool(pgPool);
52
56
 
53
57
  #### Defined in
54
58
 
55
- [packages/functions/src/db-connections/index.ts:221](https://github.com/vercel/vercel/blob/main/packages/functions/src/db-connections/index.ts#L221)
59
+ [packages/functions/src/db-connections/index.ts:225](https://github.com/vercel/vercel/blob/main/packages/functions/src/db-connections/index.ts#L225)
60
+
61
+ ---
62
+
63
+ ### dangerouslyDeleteByTag
64
+
65
+ ▸ **dangerouslyDeleteByTag**(`tag`, `options?`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
66
+
67
+ #### Parameters
68
+
69
+ | Name | Type |
70
+ | :--------- | :---------------------------------------------------------------------------- |
71
+ | `tag` | `string` \| `string`[] |
72
+ | `options?` | [`DangerouslyDeleteOptions`](../interfaces/index.DangerouslyDeleteOptions.md) |
73
+
74
+ #### Returns
75
+
76
+ [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
77
+
78
+ #### Defined in
79
+
80
+ [packages/functions/src/purge/index.ts:13](https://github.com/vercel/vercel/blob/main/packages/functions/src/purge/index.ts#L13)
56
81
 
57
82
  ---
58
83
 
@@ -76,7 +101,7 @@ Use attachDatabasePool instead.
76
101
 
77
102
  #### Defined in
78
103
 
79
- [packages/functions/src/db-connections/index.ts:221](https://github.com/vercel/vercel/blob/main/packages/functions/src/db-connections/index.ts#L221)
104
+ [packages/functions/src/db-connections/index.ts:225](https://github.com/vercel/vercel/blob/main/packages/functions/src/db-connections/index.ts#L225)
80
105
 
81
106
  ---
82
107
 
@@ -213,6 +238,26 @@ https://vercel.com/docs/projects/environment-variables/system-environment-variab
213
238
 
214
239
  ---
215
240
 
241
+ ### invalidateByTag
242
+
243
+ ▸ **invalidateByTag**(`tag`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
244
+
245
+ #### Parameters
246
+
247
+ | Name | Type |
248
+ | :---- | :--------------------- |
249
+ | `tag` | `string` \| `string`[] |
250
+
251
+ #### Returns
252
+
253
+ [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
254
+
255
+ #### Defined in
256
+
257
+ [packages/functions/src/purge/index.ts:5](https://github.com/vercel/vercel/blob/main/packages/functions/src/purge/index.ts#L5)
258
+
259
+ ---
260
+
216
261
  ### ipAddress
217
262
 
218
263
  ▸ **ipAddress**(`input`): `string` \| `undefined`
package/get-context.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { RuntimeCache } from './cache/types';
2
+ import { PurgeApi } from './purge/types';
2
3
  type Context = {
3
4
  waitUntil?: (promise: Promise<unknown>) => void;
4
5
  cache?: RuntimeCache;
6
+ purge?: PurgeApi;
5
7
  headers?: Record<string, string>;
6
8
  };
7
9
  export declare const SYMBOL_FOR_REQ_CONTEXT: unique symbol;
package/index.d.ts CHANGED
@@ -6,3 +6,5 @@ export { rewrite, next } from './middleware';
6
6
  export { getCache } from './cache';
7
7
  export { attachDatabasePool, experimental_attachDatabasePool, } from './db-connections';
8
8
  export type { RuntimeCache } from './cache/types';
9
+ export { invalidateByTag, dangerouslyDeleteByTag } from './purge';
10
+ export type { PurgeApi, DangerouslyDeleteOptions } from './purge/types';
package/index.js CHANGED
@@ -19,10 +19,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var src_exports = {};
20
20
  __export(src_exports, {
21
21
  attachDatabasePool: () => import_db_connections.attachDatabasePool,
22
+ dangerouslyDeleteByTag: () => import_purge.dangerouslyDeleteByTag,
22
23
  experimental_attachDatabasePool: () => import_db_connections.experimental_attachDatabasePool,
23
24
  geolocation: () => import_headers.geolocation,
24
25
  getCache: () => import_cache.getCache,
25
26
  getEnv: () => import_get_env.getEnv,
27
+ invalidateByTag: () => import_purge.invalidateByTag,
26
28
  ipAddress: () => import_headers.ipAddress,
27
29
  next: () => import_middleware.next,
28
30
  rewrite: () => import_middleware.rewrite,
@@ -35,13 +37,16 @@ var import_wait_until = require("./wait-until");
35
37
  var import_middleware = require("./middleware");
36
38
  var import_cache = require("./cache");
37
39
  var import_db_connections = require("./db-connections");
40
+ var import_purge = require("./purge");
38
41
  // Annotate the CommonJS export names for ESM import in node:
39
42
  0 && (module.exports = {
40
43
  attachDatabasePool,
44
+ dangerouslyDeleteByTag,
41
45
  experimental_attachDatabasePool,
42
46
  geolocation,
43
47
  getCache,
44
48
  getEnv,
49
+ invalidateByTag,
45
50
  ipAddress,
46
51
  next,
47
52
  rewrite,
package/package.json CHANGED
@@ -30,7 +30,7 @@
30
30
  "require": "./middleware.js"
31
31
  }
32
32
  },
33
- "version": "3.0.0",
33
+ "version": "3.1.1",
34
34
  "repository": {
35
35
  "directory": "packages/functions",
36
36
  "type": "git",
@@ -72,7 +72,7 @@
72
72
  "access": "public"
73
73
  },
74
74
  "dependencies": {
75
- "@vercel/oidc": "3.0.0"
75
+ "@vercel/oidc": "3.0.1"
76
76
  },
77
77
  "scripts": {
78
78
  "pretest": "pnpm run build:code",
@@ -0,0 +1,4 @@
1
+ import { DangerouslyDeleteOptions } from './types';
2
+ export * from './types';
3
+ export declare const invalidateByTag: (tag: string | string[]) => Promise<void>;
4
+ export declare const dangerouslyDeleteByTag: (tag: string | string[], options?: DangerouslyDeleteOptions) => Promise<void>;
package/purge/index.js ADDED
@@ -0,0 +1,47 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var purge_exports = {};
21
+ __export(purge_exports, {
22
+ dangerouslyDeleteByTag: () => dangerouslyDeleteByTag,
23
+ invalidateByTag: () => invalidateByTag
24
+ });
25
+ module.exports = __toCommonJS(purge_exports);
26
+ var import_get_context = require("../get-context");
27
+ __reExport(purge_exports, require("./types"), module.exports);
28
+ const invalidateByTag = (tag) => {
29
+ const api = (0, import_get_context.getContext)().purge;
30
+ if (api) {
31
+ return api.invalidateByTag(tag);
32
+ }
33
+ return Promise.resolve();
34
+ };
35
+ const dangerouslyDeleteByTag = (tag, options) => {
36
+ const api = (0, import_get_context.getContext)().purge;
37
+ if (api) {
38
+ return api.dangerouslyDeleteByTag(tag, options);
39
+ }
40
+ return Promise.resolve();
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ dangerouslyDeleteByTag,
45
+ invalidateByTag,
46
+ ...require("./types")
47
+ });
@@ -0,0 +1,30 @@
1
+ export interface DangerouslyDeleteOptions {
2
+ /**
3
+ * The time in seconds for how long the stale content can be served while revalidating the new content in the background.
4
+ * If none is provided, the default is 0 and the content will be deleted immediately.
5
+ */
6
+ revalidationDeadlineSeconds?: number;
7
+ }
8
+ /**
9
+ * Vercel Cache Purge APIs.
10
+ */
11
+ export interface PurgeApi {
12
+ /**
13
+ * Invalidate all content associated with a tag or tags by marking them as stale.
14
+ * On the next access to content associated with any of the tags, the stale content will be served and a background revalidation will be triggered.
15
+ *
16
+ * @param tag The tag or tags to invalidate.
17
+ * @returns A promise that resolves when the invalidate is complete.
18
+ */
19
+ invalidateByTag: (tag: string | string[]) => Promise<void>;
20
+ /**
21
+ * Delete all content associated with a tag or tags after a specified revalidation deadline.
22
+ * If accessed prior to the revalidation deadline, the stale content will be served and a background revalidation will be triggered. After the revalidation deadline is reached, the content will be deleted.
23
+ * The default revalidation deadline is 0 and the content will be deleted immediately.
24
+ *
25
+ * @param tag The tag or tags to delete.
26
+ * @param options The options for the delete that specify the revalidation deadline.
27
+ * @returns A promise that resolves when the delete is complete.
28
+ */
29
+ dangerouslyDeleteByTag: (tag: string | string[], options?: DangerouslyDeleteOptions) => Promise<void>;
30
+ }
package/purge/types.js ADDED
@@ -0,0 +1,16 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);