@shware/http 0.2.25 → 0.2.27
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/dist/hono/handler.cjs +5 -0
- package/dist/hono/handler.cjs.map +1 -1
- package/dist/hono/handler.mjs +5 -0
- package/dist/hono/handler.mjs.map +1 -1
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/utils/timing.cjs +74 -0
- package/dist/utils/timing.cjs.map +1 -0
- package/dist/utils/timing.d.cts +13 -0
- package/dist/utils/timing.d.ts +13 -0
- package/dist/utils/timing.mjs +49 -0
- package/dist/utils/timing.mjs.map +1 -0
- package/package.json +1 -1
package/dist/hono/handler.cjs
CHANGED
|
@@ -33,6 +33,11 @@ function errorHandler(error, c) {
|
|
|
33
33
|
error.body?.error?.details?.push(...details.list);
|
|
34
34
|
return c.json(error.body, error.status);
|
|
35
35
|
}
|
|
36
|
+
if (error instanceof SyntaxError) {
|
|
37
|
+
if (/^Cannot convert .* to a BigInt$/.test(error.message)) {
|
|
38
|
+
return import_status.Status.invalidArgument(`Invalid number. ${error.message}`).response(details);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
36
41
|
console.error(error);
|
|
37
42
|
return import_status.Status.internal("Unknown error").response(details);
|
|
38
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { HTTPResponseError, Bindings } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport { Status, StatusError } from '../status';\nimport { Details } from '../detail';\n\ntype Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\nexport function errorHandler<E extends Env = any>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.path}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n console.error(error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAAoC;AACpC,oBAAwB;AAOjB,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI;AAClD,QAAM,UAAU,sBAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,2BAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,UAAQ,MAAM,KAAK;AACnB,SAAO,qBAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { HTTPResponseError, Bindings } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport { Status, StatusError } from '../status';\nimport { Details } from '../detail';\n\ntype Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\nexport function errorHandler<E extends Env = any>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.path}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n if (error instanceof SyntaxError) {\n if (/^Cannot convert .* to a BigInt$/.test(error.message)) {\n return Status.invalidArgument(`Invalid number. ${error.message}`).response(details);\n }\n }\n\n console.error(error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAAoC;AACpC,oBAAwB;AAOjB,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI;AAClD,QAAM,UAAU,sBAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,2BAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,MAAI,iBAAiB,aAAa;AAChC,QAAI,kCAAkC,KAAK,MAAM,OAAO,GAAG;AACzD,aAAO,qBAAO,gBAAgB,mBAAmB,MAAM,OAAO,EAAE,EAAE,SAAS,OAAO;AAAA,IACpF;AAAA,EACF;AAEA,UAAQ,MAAM,KAAK;AACnB,SAAO,qBAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
|
package/dist/hono/handler.mjs
CHANGED
|
@@ -9,6 +9,11 @@ function errorHandler(error, c) {
|
|
|
9
9
|
error.body?.error?.details?.push(...details.list);
|
|
10
10
|
return c.json(error.body, error.status);
|
|
11
11
|
}
|
|
12
|
+
if (error instanceof SyntaxError) {
|
|
13
|
+
if (/^Cannot convert .* to a BigInt$/.test(error.message)) {
|
|
14
|
+
return Status.invalidArgument(`Invalid number. ${error.message}`).response(details);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
12
17
|
console.error(error);
|
|
13
18
|
return Status.internal("Unknown error").response(details);
|
|
14
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { HTTPResponseError, Bindings } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport { Status, StatusError } from '../status';\nimport { Details } from '../detail';\n\ntype Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\nexport function errorHandler<E extends Env = any>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.path}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n console.error(error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";AAIA,SAAS,QAAQ,mBAAmB;AACpC,SAAS,eAAe;AAOjB,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI;AAClD,QAAM,UAAU,QAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,aAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,UAAQ,MAAM,KAAK;AACnB,SAAO,OAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { HTTPResponseError, Bindings } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport { Status, StatusError } from '../status';\nimport { Details } from '../detail';\n\ntype Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\nexport function errorHandler<E extends Env = any>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.path}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n if (error instanceof SyntaxError) {\n if (/^Cannot convert .* to a BigInt$/.test(error.message)) {\n return Status.invalidArgument(`Invalid number. ${error.message}`).response(details);\n }\n }\n\n console.error(error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";AAIA,SAAS,QAAQ,mBAAmB;AACpC,SAAS,eAAe;AAOjB,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI;AAClD,QAAM,UAAU,QAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,aAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,MAAI,iBAAiB,aAAa;AAChC,QAAI,kCAAkC,KAAK,MAAM,OAAO,GAAG;AACzD,aAAO,OAAO,gBAAgB,mBAAmB,MAAM,OAAO,EAAE,EAAE,SAAS,OAAO;AAAA,IACpF;AAAA,EACF;AAEA,UAAQ,MAAM,KAAK;AACnB,SAAO,OAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
24
|
hasText: () => import_string.hasText,
|
|
25
|
+
timing: () => import_timing.timing,
|
|
25
26
|
verifyStandardWebhook: () => import_webhook.verifyStandardWebhook
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -31,10 +32,12 @@ __reExport(index_exports, require("./vaild.cjs"), module.exports);
|
|
|
31
32
|
__reExport(index_exports, require("./snowflake.cjs"), module.exports);
|
|
32
33
|
__reExport(index_exports, require("./response.cjs"), module.exports);
|
|
33
34
|
var import_string = require("./utils/string.cjs");
|
|
35
|
+
var import_timing = require("./utils/timing.cjs");
|
|
34
36
|
var import_webhook = require("./webhook.cjs");
|
|
35
37
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
38
|
0 && (module.exports = {
|
|
37
39
|
hasText,
|
|
40
|
+
timing,
|
|
38
41
|
verifyStandardWebhook,
|
|
39
42
|
...require("./detail.cjs"),
|
|
40
43
|
...require("./status.cjs"),
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport type {\n NetworkErrorReason,\n StatusErrorReason,\n AuthenticationErrorReason,\n ModerationErrorReason,\n MultipartErrorReason,\n AppErrorReason,\n ErrorReason,\n} from './reason';\n\nexport * from './detail';\nexport * from './status';\nexport * from './vaild';\nexport * from './snowflake';\nexport * from './response';\nexport { hasText } from './utils/string';\nexport { verifyStandardWebhook } from './webhook';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBA,0BAAc,yBAvBd;AAwBA,0BAAc,yBAxBd;AAyBA,0BAAc,wBAzBd;AA0BA,0BAAc,4BA1Bd;AA2BA,0BAAc,2BA3Bd;AA4BA,oBAAwB;AACxB,qBAAsC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport type {\n NetworkErrorReason,\n StatusErrorReason,\n AuthenticationErrorReason,\n ModerationErrorReason,\n MultipartErrorReason,\n AppErrorReason,\n ErrorReason,\n} from './reason';\n\nexport * from './detail';\nexport * from './status';\nexport * from './vaild';\nexport * from './snowflake';\nexport * from './response';\nexport { hasText } from './utils/string';\nexport { timing } from './utils/timing';\nexport { verifyStandardWebhook } from './webhook';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBA,0BAAc,yBAvBd;AAwBA,0BAAc,yBAxBd;AAyBA,0BAAc,wBAzBd;AA0BA,0BAAc,4BA1Bd;AA2BA,0BAAc,2BA3Bd;AA4BA,oBAAwB;AACxB,oBAAuB;AACvB,qBAAsC;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -5,5 +5,6 @@ export { Result, valid } from './vaild.cjs';
|
|
|
5
5
|
export { UidGenerator, uid } from './snowflake.cjs';
|
|
6
6
|
export { Cursor, Empty, Entity, EntityId, InitParams, NextParams, PageParams, PagedResponse, ParentPageParams, PrevParams, Response, pageParamsSchema } from './response.cjs';
|
|
7
7
|
export { hasText } from './utils/string.cjs';
|
|
8
|
+
export { timing } from './utils/timing.cjs';
|
|
8
9
|
export { verifyStandardWebhook } from './webhook.cjs';
|
|
9
10
|
import 'zod';
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export { Result, valid } from './vaild.js';
|
|
|
5
5
|
export { UidGenerator, uid } from './snowflake.js';
|
|
6
6
|
export { Cursor, Empty, Entity, EntityId, InitParams, NextParams, PageParams, PagedResponse, ParentPageParams, PrevParams, Response, pageParamsSchema } from './response.js';
|
|
7
7
|
export { hasText } from './utils/string.js';
|
|
8
|
+
export { timing } from './utils/timing.js';
|
|
8
9
|
export { verifyStandardWebhook } from './webhook.js';
|
|
9
10
|
import 'zod';
|
package/dist/index.mjs
CHANGED
|
@@ -5,9 +5,11 @@ export * from "./vaild.mjs";
|
|
|
5
5
|
export * from "./snowflake.mjs";
|
|
6
6
|
export * from "./response.mjs";
|
|
7
7
|
import { hasText } from "./utils/string.mjs";
|
|
8
|
+
import { timing } from "./utils/timing.mjs";
|
|
8
9
|
import { verifyStandardWebhook } from "./webhook.mjs";
|
|
9
10
|
export {
|
|
10
11
|
hasText,
|
|
12
|
+
timing,
|
|
11
13
|
verifyStandardWebhook
|
|
12
14
|
};
|
|
13
15
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport type {\n NetworkErrorReason,\n StatusErrorReason,\n AuthenticationErrorReason,\n ModerationErrorReason,\n MultipartErrorReason,\n AppErrorReason,\n ErrorReason,\n} from './reason';\n\nexport * from './detail';\nexport * from './status';\nexport * from './vaild';\nexport * from './snowflake';\nexport * from './response';\nexport { hasText } from './utils/string';\nexport { verifyStandardWebhook } from './webhook';\n"],"mappings":";AAuBA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,eAAe;AACxB,SAAS,6BAA6B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport type {\n NetworkErrorReason,\n StatusErrorReason,\n AuthenticationErrorReason,\n ModerationErrorReason,\n MultipartErrorReason,\n AppErrorReason,\n ErrorReason,\n} from './reason';\n\nexport * from './detail';\nexport * from './status';\nexport * from './vaild';\nexport * from './snowflake';\nexport * from './response';\nexport { hasText } from './utils/string';\nexport { timing } from './utils/timing';\nexport { verifyStandardWebhook } from './webhook';\n"],"mappings":";AAuBA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,eAAe;AACxB,SAAS,cAAc;AACvB,SAAS,6BAA6B;","names":[]}
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
|
|
20
|
+
// src/utils/timing.ts
|
|
21
|
+
var timing_exports = {};
|
|
22
|
+
__export(timing_exports, {
|
|
23
|
+
timing: () => timing
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(timing_exports);
|
|
26
|
+
function timing(options = { enabled: true }) {
|
|
27
|
+
const { enabled = true, crossOrigin } = options;
|
|
28
|
+
let start = performance.now();
|
|
29
|
+
const headers = [];
|
|
30
|
+
const timers = /* @__PURE__ */ new Map();
|
|
31
|
+
return {
|
|
32
|
+
startTime: (name, description) => {
|
|
33
|
+
timers.set(name, { description, start: performance.now() });
|
|
34
|
+
},
|
|
35
|
+
endTime: (name, precision) => {
|
|
36
|
+
const timer = timers.get(name);
|
|
37
|
+
if (!timer) {
|
|
38
|
+
console.warn(`timing: ${name} not found`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const { start: start2, description } = timer;
|
|
42
|
+
const dur = (performance.now() - start2).toFixed(precision ?? 1);
|
|
43
|
+
timers.delete(name);
|
|
44
|
+
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
|
|
45
|
+
headers.push(metric);
|
|
46
|
+
},
|
|
47
|
+
mark: (name, description, precision) => {
|
|
48
|
+
const dur = (performance.now() - start).toFixed(precision ?? 1);
|
|
49
|
+
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
|
|
50
|
+
headers.push(metric);
|
|
51
|
+
start = performance.now();
|
|
52
|
+
},
|
|
53
|
+
setMetric: (name, value, description, precision) => {
|
|
54
|
+
if (typeof value === "number") {
|
|
55
|
+
const dur = value.toFixed(precision ?? 1);
|
|
56
|
+
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
|
|
57
|
+
headers.push(metric);
|
|
58
|
+
} else {
|
|
59
|
+
const metric = value ? `${name};desc="${value}"` : `${name}`;
|
|
60
|
+
headers.push(metric);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
setTiming: (response) => {
|
|
64
|
+
if (!enabled) return;
|
|
65
|
+
response.headers.append("Server-Timing", headers.join(","));
|
|
66
|
+
response.headers.append("Timing-Allow-Origin", crossOrigin ?? "*");
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
timing
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=timing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/timing.ts"],"sourcesContent":["interface Timer {\n description?: string;\n start: number;\n}\n\nexport interface Options {\n enabled: boolean;\n crossOrigin?: string;\n}\n\nexport function timing(options: Options = { enabled: true }) {\n const { enabled = true, crossOrigin } = options;\n let start = performance.now();\n const headers: string[] = [];\n const timers = new Map<string, Timer>();\n\n return {\n startTime: (name: Lowercase<string>, description?: string) => {\n timers.set(name, { description, start: performance.now() });\n },\n endTime: (name: Lowercase<string>, precision?: number) => {\n const timer = timers.get(name);\n if (!timer) {\n console.warn(`timing: ${name} not found`);\n return;\n }\n const { start, description } = timer;\n const dur = (performance.now() - start).toFixed(precision ?? 1);\n timers.delete(name);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n },\n mark: (name: Lowercase<string>, description?: string, precision?: number) => {\n const dur = (performance.now() - start).toFixed(precision ?? 1);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n start = performance.now();\n },\n setMetric: (\n name: Lowercase<string>,\n value: number | string | undefined,\n description?: string,\n precision?: number\n ) => {\n if (typeof value === 'number') {\n const dur = value.toFixed(precision ?? 1);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n } else {\n const metric = value ? `${name};desc=\"${value}\"` : `${name}`;\n headers.push(metric);\n }\n },\n setTiming: (response: Response) => {\n if (!enabled) return;\n response.headers.append('Server-Timing', headers.join(','));\n response.headers.append('Timing-Allow-Origin', crossOrigin ?? '*');\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,SAAS,OAAO,UAAmB,EAAE,SAAS,KAAK,GAAG;AAC3D,QAAM,EAAE,UAAU,MAAM,YAAY,IAAI;AACxC,MAAI,QAAQ,YAAY,IAAI;AAC5B,QAAM,UAAoB,CAAC;AAC3B,QAAM,SAAS,oBAAI,IAAmB;AAEtC,SAAO;AAAA,IACL,WAAW,CAAC,MAAyB,gBAAyB;AAC5D,aAAO,IAAI,MAAM,EAAE,aAAa,OAAO,YAAY,IAAI,EAAE,CAAC;AAAA,IAC5D;AAAA,IACA,SAAS,CAAC,MAAyB,cAAuB;AACxD,YAAM,QAAQ,OAAO,IAAI,IAAI;AAC7B,UAAI,CAAC,OAAO;AACV,gBAAQ,KAAK,WAAW,IAAI,YAAY;AACxC;AAAA,MACF;AACA,YAAM,EAAE,OAAAA,QAAO,YAAY,IAAI;AAC/B,YAAM,OAAO,YAAY,IAAI,IAAIA,QAAO,QAAQ,aAAa,CAAC;AAC9D,aAAO,OAAO,IAAI;AAClB,YAAM,SAAS,cACX,GAAG,IAAI,QAAQ,GAAG,UAAU,WAAW,MACvC,GAAG,IAAI,QAAQ,GAAG;AACtB,cAAQ,KAAK,MAAM;AAAA,IACrB;AAAA,IACA,MAAM,CAAC,MAAyB,aAAsB,cAAuB;AAC3E,YAAM,OAAO,YAAY,IAAI,IAAI,OAAO,QAAQ,aAAa,CAAC;AAC9D,YAAM,SAAS,cACX,GAAG,IAAI,QAAQ,GAAG,UAAU,WAAW,MACvC,GAAG,IAAI,QAAQ,GAAG;AACtB,cAAQ,KAAK,MAAM;AACnB,cAAQ,YAAY,IAAI;AAAA,IAC1B;AAAA,IACA,WAAW,CACT,MACA,OACA,aACA,cACG;AACH,UAAI,OAAO,UAAU,UAAU;AAC7B,cAAM,MAAM,MAAM,QAAQ,aAAa,CAAC;AACxC,cAAM,SAAS,cACX,GAAG,IAAI,QAAQ,GAAG,UAAU,WAAW,MACvC,GAAG,IAAI,QAAQ,GAAG;AACtB,gBAAQ,KAAK,MAAM;AAAA,MACrB,OAAO;AACL,cAAM,SAAS,QAAQ,GAAG,IAAI,UAAU,KAAK,MAAM,GAAG,IAAI;AAC1D,gBAAQ,KAAK,MAAM;AAAA,MACrB;AAAA,IACF;AAAA,IACA,WAAW,CAAC,aAAuB;AACjC,UAAI,CAAC,QAAS;AACd,eAAS,QAAQ,OAAO,iBAAiB,QAAQ,KAAK,GAAG,CAAC;AAC1D,eAAS,QAAQ,OAAO,uBAAuB,eAAe,GAAG;AAAA,IACnE;AAAA,EACF;AACF;","names":["start"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
crossOrigin?: string;
|
|
4
|
+
}
|
|
5
|
+
declare function timing(options?: Options): {
|
|
6
|
+
startTime: (name: Lowercase<string>, description?: string) => void;
|
|
7
|
+
endTime: (name: Lowercase<string>, precision?: number) => void;
|
|
8
|
+
mark: (name: Lowercase<string>, description?: string, precision?: number) => void;
|
|
9
|
+
setMetric: (name: Lowercase<string>, value: number | string | undefined, description?: string, precision?: number) => void;
|
|
10
|
+
setTiming: (response: Response) => void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { type Options, timing };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
crossOrigin?: string;
|
|
4
|
+
}
|
|
5
|
+
declare function timing(options?: Options): {
|
|
6
|
+
startTime: (name: Lowercase<string>, description?: string) => void;
|
|
7
|
+
endTime: (name: Lowercase<string>, precision?: number) => void;
|
|
8
|
+
mark: (name: Lowercase<string>, description?: string, precision?: number) => void;
|
|
9
|
+
setMetric: (name: Lowercase<string>, value: number | string | undefined, description?: string, precision?: number) => void;
|
|
10
|
+
setTiming: (response: Response) => void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { type Options, timing };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/utils/timing.ts
|
|
2
|
+
function timing(options = { enabled: true }) {
|
|
3
|
+
const { enabled = true, crossOrigin } = options;
|
|
4
|
+
let start = performance.now();
|
|
5
|
+
const headers = [];
|
|
6
|
+
const timers = /* @__PURE__ */ new Map();
|
|
7
|
+
return {
|
|
8
|
+
startTime: (name, description) => {
|
|
9
|
+
timers.set(name, { description, start: performance.now() });
|
|
10
|
+
},
|
|
11
|
+
endTime: (name, precision) => {
|
|
12
|
+
const timer = timers.get(name);
|
|
13
|
+
if (!timer) {
|
|
14
|
+
console.warn(`timing: ${name} not found`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const { start: start2, description } = timer;
|
|
18
|
+
const dur = (performance.now() - start2).toFixed(precision ?? 1);
|
|
19
|
+
timers.delete(name);
|
|
20
|
+
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
|
|
21
|
+
headers.push(metric);
|
|
22
|
+
},
|
|
23
|
+
mark: (name, description, precision) => {
|
|
24
|
+
const dur = (performance.now() - start).toFixed(precision ?? 1);
|
|
25
|
+
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
|
|
26
|
+
headers.push(metric);
|
|
27
|
+
start = performance.now();
|
|
28
|
+
},
|
|
29
|
+
setMetric: (name, value, description, precision) => {
|
|
30
|
+
if (typeof value === "number") {
|
|
31
|
+
const dur = value.toFixed(precision ?? 1);
|
|
32
|
+
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
|
|
33
|
+
headers.push(metric);
|
|
34
|
+
} else {
|
|
35
|
+
const metric = value ? `${name};desc="${value}"` : `${name}`;
|
|
36
|
+
headers.push(metric);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
setTiming: (response) => {
|
|
40
|
+
if (!enabled) return;
|
|
41
|
+
response.headers.append("Server-Timing", headers.join(","));
|
|
42
|
+
response.headers.append("Timing-Allow-Origin", crossOrigin ?? "*");
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
timing
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=timing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/timing.ts"],"sourcesContent":["interface Timer {\n description?: string;\n start: number;\n}\n\nexport interface Options {\n enabled: boolean;\n crossOrigin?: string;\n}\n\nexport function timing(options: Options = { enabled: true }) {\n const { enabled = true, crossOrigin } = options;\n let start = performance.now();\n const headers: string[] = [];\n const timers = new Map<string, Timer>();\n\n return {\n startTime: (name: Lowercase<string>, description?: string) => {\n timers.set(name, { description, start: performance.now() });\n },\n endTime: (name: Lowercase<string>, precision?: number) => {\n const timer = timers.get(name);\n if (!timer) {\n console.warn(`timing: ${name} not found`);\n return;\n }\n const { start, description } = timer;\n const dur = (performance.now() - start).toFixed(precision ?? 1);\n timers.delete(name);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n },\n mark: (name: Lowercase<string>, description?: string, precision?: number) => {\n const dur = (performance.now() - start).toFixed(precision ?? 1);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n start = performance.now();\n },\n setMetric: (\n name: Lowercase<string>,\n value: number | string | undefined,\n description?: string,\n precision?: number\n ) => {\n if (typeof value === 'number') {\n const dur = value.toFixed(precision ?? 1);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n } else {\n const metric = value ? `${name};desc=\"${value}\"` : `${name}`;\n headers.push(metric);\n }\n },\n setTiming: (response: Response) => {\n if (!enabled) return;\n response.headers.append('Server-Timing', headers.join(','));\n response.headers.append('Timing-Allow-Origin', crossOrigin ?? '*');\n },\n };\n}\n"],"mappings":";AAUO,SAAS,OAAO,UAAmB,EAAE,SAAS,KAAK,GAAG;AAC3D,QAAM,EAAE,UAAU,MAAM,YAAY,IAAI;AACxC,MAAI,QAAQ,YAAY,IAAI;AAC5B,QAAM,UAAoB,CAAC;AAC3B,QAAM,SAAS,oBAAI,IAAmB;AAEtC,SAAO;AAAA,IACL,WAAW,CAAC,MAAyB,gBAAyB;AAC5D,aAAO,IAAI,MAAM,EAAE,aAAa,OAAO,YAAY,IAAI,EAAE,CAAC;AAAA,IAC5D;AAAA,IACA,SAAS,CAAC,MAAyB,cAAuB;AACxD,YAAM,QAAQ,OAAO,IAAI,IAAI;AAC7B,UAAI,CAAC,OAAO;AACV,gBAAQ,KAAK,WAAW,IAAI,YAAY;AACxC;AAAA,MACF;AACA,YAAM,EAAE,OAAAA,QAAO,YAAY,IAAI;AAC/B,YAAM,OAAO,YAAY,IAAI,IAAIA,QAAO,QAAQ,aAAa,CAAC;AAC9D,aAAO,OAAO,IAAI;AAClB,YAAM,SAAS,cACX,GAAG,IAAI,QAAQ,GAAG,UAAU,WAAW,MACvC,GAAG,IAAI,QAAQ,GAAG;AACtB,cAAQ,KAAK,MAAM;AAAA,IACrB;AAAA,IACA,MAAM,CAAC,MAAyB,aAAsB,cAAuB;AAC3E,YAAM,OAAO,YAAY,IAAI,IAAI,OAAO,QAAQ,aAAa,CAAC;AAC9D,YAAM,SAAS,cACX,GAAG,IAAI,QAAQ,GAAG,UAAU,WAAW,MACvC,GAAG,IAAI,QAAQ,GAAG;AACtB,cAAQ,KAAK,MAAM;AACnB,cAAQ,YAAY,IAAI;AAAA,IAC1B;AAAA,IACA,WAAW,CACT,MACA,OACA,aACA,cACG;AACH,UAAI,OAAO,UAAU,UAAU;AAC7B,cAAM,MAAM,MAAM,QAAQ,aAAa,CAAC;AACxC,cAAM,SAAS,cACX,GAAG,IAAI,QAAQ,GAAG,UAAU,WAAW,MACvC,GAAG,IAAI,QAAQ,GAAG;AACtB,gBAAQ,KAAK,MAAM;AAAA,MACrB,OAAO;AACL,cAAM,SAAS,QAAQ,GAAG,IAAI,UAAU,KAAK,MAAM,GAAG,IAAI;AAC1D,gBAAQ,KAAK,MAAM;AAAA,MACrB;AAAA,IACF;AAAA,IACA,WAAW,CAAC,aAAuB;AACjC,UAAI,CAAC,QAAS;AACd,eAAS,QAAQ,OAAO,iBAAiB,QAAQ,KAAK,GAAG,CAAC;AAC1D,eAAS,QAAQ,OAAO,uBAAuB,eAAe,GAAG;AAAA,IACnE;AAAA,EACF;AACF;","names":["start"]}
|