@vercel/functions 3.7.7 → 3.9.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/deadline.d.ts +5 -0
- package/deadline.js +39 -0
- package/docs/index/README.md +2 -0
- package/docs/index/functions/getDeadline.md +16 -0
- package/docs/index/functions/metric.md +45 -0
- package/get-context.d.ts +1 -0
- package/index.d.ts +2 -0
- package/index.js +6 -0
- package/metric.d.ts +18 -0
- package/metric.js +32 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @vercel/functions
|
|
2
2
|
|
|
3
|
+
## 3.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 0b0a4a8: Add a `metric()` helper for reporting custom metrics from Vercel Functions.
|
|
8
|
+
|
|
9
|
+
## 3.8.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 8fb6c4f: Adds getDeadline
|
|
14
|
+
|
|
3
15
|
## 3.7.7
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/deadline.d.ts
ADDED
package/deadline.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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 deadline_exports = {};
|
|
20
|
+
__export(deadline_exports, {
|
|
21
|
+
getDeadline: () => getDeadline
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(deadline_exports);
|
|
24
|
+
var import_get_context = require("./get-context");
|
|
25
|
+
function getDeadline() {
|
|
26
|
+
const deadline = (0, import_get_context.getContext)().deadline;
|
|
27
|
+
if (deadline === void 0) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
const date = new Date(deadline);
|
|
31
|
+
if (isNaN(date.getTime())) {
|
|
32
|
+
return void 0;
|
|
33
|
+
}
|
|
34
|
+
return date;
|
|
35
|
+
}
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
getDeadline
|
|
39
|
+
});
|
package/docs/index/README.md
CHANGED
|
@@ -33,10 +33,12 @@
|
|
|
33
33
|
- [experimental_upgradeWebSocket](functions/experimental_upgradeWebSocket.md)
|
|
34
34
|
- [geolocation](functions/geolocation.md)
|
|
35
35
|
- [getCache](functions/getCache.md)
|
|
36
|
+
- [getDeadline](functions/getDeadline.md)
|
|
36
37
|
- [getEnv](functions/getEnv.md)
|
|
37
38
|
- [invalidateBySrcImage](functions/invalidateBySrcImage.md)
|
|
38
39
|
- [invalidateByTag](functions/invalidateByTag.md)
|
|
39
40
|
- [ipAddress](functions/ipAddress.md)
|
|
41
|
+
- [metric](functions/metric.md)
|
|
40
42
|
- [next](functions/next.md)
|
|
41
43
|
- [rewrite](functions/rewrite.md)
|
|
42
44
|
- [waitUntil](functions/waitUntil.md)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[**@vercel/functions**](../../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
# Function: getDeadline()
|
|
6
|
+
|
|
7
|
+
> **getDeadline**(): [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) \| `undefined`
|
|
8
|
+
|
|
9
|
+
Defined in: [packages/functions/src/deadline.ts:7](https://github.com/vercel/vercel/blob/main/packages/functions/src/deadline.ts#L7)
|
|
10
|
+
|
|
11
|
+
Returns the shared invocation deadline for the
|
|
12
|
+
current function invocation, as a Date object.
|
|
13
|
+
|
|
14
|
+
## Returns
|
|
15
|
+
|
|
16
|
+
[`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) \| `undefined`
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[**@vercel/functions**](../../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
# Function: metric()
|
|
6
|
+
|
|
7
|
+
> **metric**(`name`, `value`, `tags?`): `void`
|
|
8
|
+
|
|
9
|
+
Defined in: [packages/functions/src/metric.ts:28](https://github.com/vercel/vercel/blob/main/packages/functions/src/metric.ts#L28)
|
|
10
|
+
|
|
11
|
+
Reports a custom metric for the current Vercel Function invocation.
|
|
12
|
+
|
|
13
|
+
## Parameters
|
|
14
|
+
|
|
15
|
+
### name
|
|
16
|
+
|
|
17
|
+
`string`
|
|
18
|
+
|
|
19
|
+
The name of the metric.
|
|
20
|
+
|
|
21
|
+
### value
|
|
22
|
+
|
|
23
|
+
`number`
|
|
24
|
+
|
|
25
|
+
The numeric value of the metric.
|
|
26
|
+
|
|
27
|
+
### tags?
|
|
28
|
+
|
|
29
|
+
[`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)\<`string`, `string`\>
|
|
30
|
+
|
|
31
|
+
Optional tags to attach to the metric.
|
|
32
|
+
|
|
33
|
+
## Returns
|
|
34
|
+
|
|
35
|
+
`void`
|
|
36
|
+
|
|
37
|
+
## Example
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import { metric } from '@vercel/functions';
|
|
41
|
+
|
|
42
|
+
metric('tinybird.query_ms', 100, {
|
|
43
|
+
query: 'getUser',
|
|
44
|
+
});
|
|
45
|
+
```
|
package/get-context.d.ts
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export type { Request, Geo } from './headers';
|
|
2
2
|
export { geolocation, ipAddress } from './headers';
|
|
3
3
|
export { getEnv } from './get-env';
|
|
4
|
+
export { getDeadline } from './deadline';
|
|
4
5
|
export { waitUntil } from './wait-until';
|
|
6
|
+
export { metric } from './metric';
|
|
5
7
|
export { rewrite, next } from './middleware';
|
|
6
8
|
export { getCache } from './cache';
|
|
7
9
|
export { attachDatabasePool, experimental_attachDatabasePool, } from './db-connections';
|
package/index.js
CHANGED
|
@@ -26,10 +26,12 @@ __export(src_exports, {
|
|
|
26
26
|
experimental_upgradeWebSocket: () => import_websocket.experimental_upgradeWebSocket,
|
|
27
27
|
geolocation: () => import_headers.geolocation,
|
|
28
28
|
getCache: () => import_cache.getCache,
|
|
29
|
+
getDeadline: () => import_deadline.getDeadline,
|
|
29
30
|
getEnv: () => import_get_env.getEnv,
|
|
30
31
|
invalidateBySrcImage: () => import_purge.invalidateBySrcImage,
|
|
31
32
|
invalidateByTag: () => import_purge.invalidateByTag,
|
|
32
33
|
ipAddress: () => import_headers.ipAddress,
|
|
34
|
+
metric: () => import_metric.metric,
|
|
33
35
|
next: () => import_middleware.next,
|
|
34
36
|
rewrite: () => import_middleware.rewrite,
|
|
35
37
|
waitUntil: () => import_wait_until.waitUntil
|
|
@@ -37,7 +39,9 @@ __export(src_exports, {
|
|
|
37
39
|
module.exports = __toCommonJS(src_exports);
|
|
38
40
|
var import_headers = require("./headers");
|
|
39
41
|
var import_get_env = require("./get-env");
|
|
42
|
+
var import_deadline = require("./deadline");
|
|
40
43
|
var import_wait_until = require("./wait-until");
|
|
44
|
+
var import_metric = require("./metric");
|
|
41
45
|
var import_middleware = require("./middleware");
|
|
42
46
|
var import_cache = require("./cache");
|
|
43
47
|
var import_db_connections = require("./db-connections");
|
|
@@ -54,10 +58,12 @@ var import_websocket = require("./websocket");
|
|
|
54
58
|
experimental_upgradeWebSocket,
|
|
55
59
|
geolocation,
|
|
56
60
|
getCache,
|
|
61
|
+
getDeadline,
|
|
57
62
|
getEnv,
|
|
58
63
|
invalidateBySrcImage,
|
|
59
64
|
invalidateByTag,
|
|
60
65
|
ipAddress,
|
|
66
|
+
metric,
|
|
61
67
|
next,
|
|
62
68
|
rewrite,
|
|
63
69
|
waitUntil
|
package/metric.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reports a custom metric for the current Vercel Function invocation.
|
|
3
|
+
*
|
|
4
|
+
* @param name The name of the metric.
|
|
5
|
+
* @param value The numeric value of the metric.
|
|
6
|
+
* @param tags Optional tags to attach to the metric.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```js
|
|
11
|
+
* import { metric } from '@vercel/functions';
|
|
12
|
+
*
|
|
13
|
+
* metric('tinybird.query_ms', 100, {
|
|
14
|
+
* query: 'getUser',
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function metric(name: string, value: number, tags?: Record<string, string>): void;
|
package/metric.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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 metric_exports = {};
|
|
20
|
+
__export(metric_exports, {
|
|
21
|
+
metric: () => metric
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(metric_exports);
|
|
24
|
+
const RUSTY_RUNTIME_IPC_SYMBOL = Symbol.for("@vercel/rusty-runtime-ipc");
|
|
25
|
+
function metric(name, value, tags) {
|
|
26
|
+
const ipc = globalThis[RUSTY_RUNTIME_IPC_SYMBOL];
|
|
27
|
+
ipc?.sendMetric?.(name, value, tags);
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
metric
|
|
32
|
+
});
|