@shware/http 0.2.27 → 0.3.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/dist/hono/index.d.cts +1 -1
- package/dist/hono/index.d.ts +1 -1
- package/dist/hono/validator.cjs.map +1 -1
- package/dist/hono/validator.d.cts +14 -14
- package/dist/hono/validator.d.ts +14 -14
- package/dist/hono/validator.mjs.map +1 -1
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -1
- package/dist/response.cjs +5 -5
- package/dist/response.cjs.map +1 -1
- package/dist/response.d.cts +3 -11
- package/dist/response.d.ts +3 -11
- package/dist/response.mjs +1 -1
- package/dist/response.mjs.map +1 -1
- package/dist/utils/invariant.cjs +37 -0
- package/dist/utils/invariant.cjs.map +1 -0
- package/dist/utils/invariant.d.cts +3 -0
- package/dist/utils/invariant.d.ts +3 -0
- package/dist/utils/invariant.mjs +12 -0
- package/dist/utils/invariant.mjs.map +1 -0
- package/dist/utils/token-bucket.cjs +67 -0
- package/dist/utils/token-bucket.cjs.map +1 -0
- package/dist/utils/token-bucket.d.cts +18 -0
- package/dist/utils/token-bucket.d.ts +18 -0
- package/dist/utils/token-bucket.mjs +42 -0
- package/dist/utils/token-bucket.mjs.map +1 -0
- package/dist/vaild.cjs.map +1 -1
- package/dist/vaild.d.cts +3 -3
- package/dist/vaild.d.ts +3 -3
- package/dist/vaild.mjs.map +1 -1
- package/package.json +3 -3
package/dist/hono/index.d.cts
CHANGED
package/dist/hono/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hono/validator.ts"],"sourcesContent":["import type { z,
|
|
1
|
+
{"version":3,"sources":["../../src/hono/validator.ts"],"sourcesContent":["import type { z, ZodType } from 'zod/v4';\nimport type { ValidationTargets } from 'hono';\nimport { validator } from 'hono/validator';\nimport { Status } from '../status';\nimport { Details } from '../detail';\nimport type { BadRequest } from '../detail';\n\nexport function zValidator<S extends ZodType>(target: keyof ValidationTargets, schema: S) {\n return validator(target, async (value) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return result.data as z.infer<S>;\n\n const fieldViolations: BadRequest['fieldViolations'] = result.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n throw Status.invalidArgument().error(details);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uBAA0B;AAC1B,oBAAuB;AACvB,oBAAwB;AAGjB,SAAS,WAA8B,QAAiC,QAAW;AACxF,aAAO,4BAAU,QAAQ,OAAO,UAAU;AACxC,UAAM,SAAS,MAAM,OAAO,eAAe,KAAK;AAChD,QAAI,OAAO,QAAS,QAAO,OAAO;AAElC,UAAM,kBAAiD,OAAO,MAAM,OAAO;AAAA,MACzE,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,IACxE;AACA,UAAM,UAAU,sBAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,UAAM,qBAAO,gBAAgB,EAAE,MAAM,OAAO;AAAA,EAC9C,CAAC;AACH;","names":[]}
|
|
@@ -2,24 +2,24 @@ import * as hono_utils_headers from 'hono/utils/headers';
|
|
|
2
2
|
import * as hono_types from 'hono/types';
|
|
3
3
|
import * as hono from 'hono';
|
|
4
4
|
import { ValidationTargets } from 'hono';
|
|
5
|
-
import {
|
|
5
|
+
import { ZodType, z } from 'zod/v4';
|
|
6
6
|
|
|
7
|
-
declare function zValidator<S extends
|
|
7
|
+
declare function zValidator<S extends ZodType>(target: keyof ValidationTargets, schema: S): hono.MiddlewareHandler<any, string, {
|
|
8
8
|
in: {
|
|
9
|
-
json: z.
|
|
10
|
-
form: (z.
|
|
11
|
-
query: (z.
|
|
12
|
-
param: (z.
|
|
13
|
-
header: (z.
|
|
14
|
-
cookie: (z.
|
|
9
|
+
json: z.core.output<S> extends infer T ? T extends z.core.output<S> ? T extends Response & hono.TypedResponse<any> ? never : T : never : never;
|
|
10
|
+
form: (z.core.output<S> extends infer T_2 ? T_2 extends z.core.output<S> ? T_2 extends Response & hono.TypedResponse<any> ? never : T_2 : never : never) extends infer T_1 ? { [K2 in keyof T_1]: Record<string, hono_types.ParsedFormValue | hono_types.ParsedFormValue[]>[K2]; } : never;
|
|
11
|
+
query: (z.core.output<S> extends infer T_4 ? T_4 extends z.core.output<S> ? T_4 extends Response & hono.TypedResponse<any> ? never : T_4 : never : never) extends infer T_3 ? { [K2_1 in keyof T_3]: Record<string, string | string[]>[K2_1]; } : never;
|
|
12
|
+
param: (z.core.output<S> extends infer T_6 ? T_6 extends z.core.output<S> ? T_6 extends Response & hono.TypedResponse<any> ? never : T_6 : never : never) extends infer T_5 ? { [K2_2 in keyof T_5]: Record<string, string>[K2_2]; } : never;
|
|
13
|
+
header: (z.core.output<S> extends infer T_8 ? T_8 extends z.core.output<S> ? T_8 extends Response & hono.TypedResponse<any> ? never : T_8 : never : never) extends infer T_7 ? { [K2_3 in keyof T_7]: Record<hono_utils_headers.RequestHeader | hono_utils_headers.CustomHeader, string>[K2_3]; } : never;
|
|
14
|
+
cookie: (z.core.output<S> extends infer T_10 ? T_10 extends z.core.output<S> ? T_10 extends Response & hono.TypedResponse<any> ? never : T_10 : never : never) extends infer T_9 ? { [K2_4 in keyof T_9]: Record<string, string>[K2_4]; } : never;
|
|
15
15
|
};
|
|
16
16
|
out: {
|
|
17
|
-
json: z.
|
|
18
|
-
form: z.
|
|
19
|
-
query: z.
|
|
20
|
-
param: z.
|
|
21
|
-
header: z.
|
|
22
|
-
cookie: z.
|
|
17
|
+
json: z.core.output<S> extends infer T_11 ? T_11 extends z.core.output<S> ? T_11 extends Response & hono.TypedResponse<any> ? never : T_11 : never : never;
|
|
18
|
+
form: z.core.output<S> extends infer T_12 ? T_12 extends z.core.output<S> ? T_12 extends Response & hono.TypedResponse<any> ? never : T_12 : never : never;
|
|
19
|
+
query: z.core.output<S> extends infer T_13 ? T_13 extends z.core.output<S> ? T_13 extends Response & hono.TypedResponse<any> ? never : T_13 : never : never;
|
|
20
|
+
param: z.core.output<S> extends infer T_14 ? T_14 extends z.core.output<S> ? T_14 extends Response & hono.TypedResponse<any> ? never : T_14 : never : never;
|
|
21
|
+
header: z.core.output<S> extends infer T_15 ? T_15 extends z.core.output<S> ? T_15 extends Response & hono.TypedResponse<any> ? never : T_15 : never : never;
|
|
22
|
+
cookie: z.core.output<S> extends infer T_16 ? T_16 extends z.core.output<S> ? T_16 extends Response & hono.TypedResponse<any> ? never : T_16 : never : never;
|
|
23
23
|
};
|
|
24
24
|
}>;
|
|
25
25
|
|
package/dist/hono/validator.d.ts
CHANGED
|
@@ -2,24 +2,24 @@ import * as hono_utils_headers from 'hono/utils/headers';
|
|
|
2
2
|
import * as hono_types from 'hono/types';
|
|
3
3
|
import * as hono from 'hono';
|
|
4
4
|
import { ValidationTargets } from 'hono';
|
|
5
|
-
import {
|
|
5
|
+
import { ZodType, z } from 'zod/v4';
|
|
6
6
|
|
|
7
|
-
declare function zValidator<S extends
|
|
7
|
+
declare function zValidator<S extends ZodType>(target: keyof ValidationTargets, schema: S): hono.MiddlewareHandler<any, string, {
|
|
8
8
|
in: {
|
|
9
|
-
json: z.
|
|
10
|
-
form: (z.
|
|
11
|
-
query: (z.
|
|
12
|
-
param: (z.
|
|
13
|
-
header: (z.
|
|
14
|
-
cookie: (z.
|
|
9
|
+
json: z.core.output<S> extends infer T ? T extends z.core.output<S> ? T extends Response & hono.TypedResponse<any> ? never : T : never : never;
|
|
10
|
+
form: (z.core.output<S> extends infer T_2 ? T_2 extends z.core.output<S> ? T_2 extends Response & hono.TypedResponse<any> ? never : T_2 : never : never) extends infer T_1 ? { [K2 in keyof T_1]: Record<string, hono_types.ParsedFormValue | hono_types.ParsedFormValue[]>[K2]; } : never;
|
|
11
|
+
query: (z.core.output<S> extends infer T_4 ? T_4 extends z.core.output<S> ? T_4 extends Response & hono.TypedResponse<any> ? never : T_4 : never : never) extends infer T_3 ? { [K2_1 in keyof T_3]: Record<string, string | string[]>[K2_1]; } : never;
|
|
12
|
+
param: (z.core.output<S> extends infer T_6 ? T_6 extends z.core.output<S> ? T_6 extends Response & hono.TypedResponse<any> ? never : T_6 : never : never) extends infer T_5 ? { [K2_2 in keyof T_5]: Record<string, string>[K2_2]; } : never;
|
|
13
|
+
header: (z.core.output<S> extends infer T_8 ? T_8 extends z.core.output<S> ? T_8 extends Response & hono.TypedResponse<any> ? never : T_8 : never : never) extends infer T_7 ? { [K2_3 in keyof T_7]: Record<hono_utils_headers.RequestHeader | hono_utils_headers.CustomHeader, string>[K2_3]; } : never;
|
|
14
|
+
cookie: (z.core.output<S> extends infer T_10 ? T_10 extends z.core.output<S> ? T_10 extends Response & hono.TypedResponse<any> ? never : T_10 : never : never) extends infer T_9 ? { [K2_4 in keyof T_9]: Record<string, string>[K2_4]; } : never;
|
|
15
15
|
};
|
|
16
16
|
out: {
|
|
17
|
-
json: z.
|
|
18
|
-
form: z.
|
|
19
|
-
query: z.
|
|
20
|
-
param: z.
|
|
21
|
-
header: z.
|
|
22
|
-
cookie: z.
|
|
17
|
+
json: z.core.output<S> extends infer T_11 ? T_11 extends z.core.output<S> ? T_11 extends Response & hono.TypedResponse<any> ? never : T_11 : never : never;
|
|
18
|
+
form: z.core.output<S> extends infer T_12 ? T_12 extends z.core.output<S> ? T_12 extends Response & hono.TypedResponse<any> ? never : T_12 : never : never;
|
|
19
|
+
query: z.core.output<S> extends infer T_13 ? T_13 extends z.core.output<S> ? T_13 extends Response & hono.TypedResponse<any> ? never : T_13 : never : never;
|
|
20
|
+
param: z.core.output<S> extends infer T_14 ? T_14 extends z.core.output<S> ? T_14 extends Response & hono.TypedResponse<any> ? never : T_14 : never : never;
|
|
21
|
+
header: z.core.output<S> extends infer T_15 ? T_15 extends z.core.output<S> ? T_15 extends Response & hono.TypedResponse<any> ? never : T_15 : never : never;
|
|
22
|
+
cookie: z.core.output<S> extends infer T_16 ? T_16 extends z.core.output<S> ? T_16 extends Response & hono.TypedResponse<any> ? never : T_16 : never : never;
|
|
23
23
|
};
|
|
24
24
|
}>;
|
|
25
25
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hono/validator.ts"],"sourcesContent":["import type { z,
|
|
1
|
+
{"version":3,"sources":["../../src/hono/validator.ts"],"sourcesContent":["import type { z, ZodType } from 'zod/v4';\nimport type { ValidationTargets } from 'hono';\nimport { validator } from 'hono/validator';\nimport { Status } from '../status';\nimport { Details } from '../detail';\nimport type { BadRequest } from '../detail';\n\nexport function zValidator<S extends ZodType>(target: keyof ValidationTargets, schema: S) {\n return validator(target, async (value) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return result.data as z.infer<S>;\n\n const fieldViolations: BadRequest['fieldViolations'] = result.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n throw Status.invalidArgument().error(details);\n });\n}\n"],"mappings":";AAEA,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,eAAe;AAGjB,SAAS,WAA8B,QAAiC,QAAW;AACxF,SAAO,UAAU,QAAQ,OAAO,UAAU;AACxC,UAAM,SAAS,MAAM,OAAO,eAAe,KAAK;AAChD,QAAI,OAAO,QAAS,QAAO,OAAO;AAElC,UAAM,kBAAiD,OAAO,MAAM,OAAO;AAAA,MACzE,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,IACxE;AACA,UAAM,UAAU,QAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,UAAM,OAAO,gBAAgB,EAAE,MAAM,OAAO;AAAA,EAC9C,CAAC;AACH;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -21,7 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
|
+
TokenBucket: () => import_token_bucket.TokenBucket,
|
|
24
25
|
hasText: () => import_string.hasText,
|
|
26
|
+
invariant: () => import_invariant.invariant,
|
|
25
27
|
timing: () => import_timing.timing,
|
|
26
28
|
verifyStandardWebhook: () => import_webhook.verifyStandardWebhook
|
|
27
29
|
});
|
|
@@ -34,9 +36,13 @@ __reExport(index_exports, require("./response.cjs"), module.exports);
|
|
|
34
36
|
var import_string = require("./utils/string.cjs");
|
|
35
37
|
var import_timing = require("./utils/timing.cjs");
|
|
36
38
|
var import_webhook = require("./webhook.cjs");
|
|
39
|
+
var import_invariant = require("./utils/invariant.cjs");
|
|
40
|
+
var import_token_bucket = require("./utils/token-bucket.cjs");
|
|
37
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
42
|
0 && (module.exports = {
|
|
43
|
+
TokenBucket,
|
|
39
44
|
hasText,
|
|
45
|
+
invariant,
|
|
40
46
|
timing,
|
|
41
47
|
verifyStandardWebhook,
|
|
42
48
|
...require("./detail.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 { 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":[]}
|
|
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';\nexport { invariant } from './utils/invariant';\nexport { TokenBucket, type TokenBucketOptions } from './utils/token-bucket';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;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;AACtC,uBAA0B;AAC1B,0BAAqD;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -7,4 +7,6 @@ export { Cursor, Empty, Entity, EntityId, InitParams, NextParams, PageParams, Pa
|
|
|
7
7
|
export { hasText } from './utils/string.cjs';
|
|
8
8
|
export { timing } from './utils/timing.cjs';
|
|
9
9
|
export { verifyStandardWebhook } from './webhook.cjs';
|
|
10
|
-
|
|
10
|
+
export { invariant } from './utils/invariant.cjs';
|
|
11
|
+
export { TokenBucket, TokenBucketOptions } from './utils/token-bucket.cjs';
|
|
12
|
+
import 'zod/v4';
|
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,6 @@ export { Cursor, Empty, Entity, EntityId, InitParams, NextParams, PageParams, Pa
|
|
|
7
7
|
export { hasText } from './utils/string.js';
|
|
8
8
|
export { timing } from './utils/timing.js';
|
|
9
9
|
export { verifyStandardWebhook } from './webhook.js';
|
|
10
|
-
|
|
10
|
+
export { invariant } from './utils/invariant.js';
|
|
11
|
+
export { TokenBucket, TokenBucketOptions } from './utils/token-bucket.js';
|
|
12
|
+
import 'zod/v4';
|
package/dist/index.mjs
CHANGED
|
@@ -7,8 +7,12 @@ export * from "./response.mjs";
|
|
|
7
7
|
import { hasText } from "./utils/string.mjs";
|
|
8
8
|
import { timing } from "./utils/timing.mjs";
|
|
9
9
|
import { verifyStandardWebhook } from "./webhook.mjs";
|
|
10
|
+
import { invariant } from "./utils/invariant.mjs";
|
|
11
|
+
import { TokenBucket } from "./utils/token-bucket.mjs";
|
|
10
12
|
export {
|
|
13
|
+
TokenBucket,
|
|
11
14
|
hasText,
|
|
15
|
+
invariant,
|
|
12
16
|
timing,
|
|
13
17
|
verifyStandardWebhook
|
|
14
18
|
};
|
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 { 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":[]}
|
|
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';\nexport { invariant } from './utils/invariant';\nexport { TokenBucket, type TokenBucketOptions } from './utils/token-bucket';\n"],"mappings":";AAuBA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,eAAe;AACxB,SAAS,cAAc;AACvB,SAAS,6BAA6B;AACtC,SAAS,iBAAiB;AAC1B,SAAS,mBAA4C;","names":[]}
|
package/dist/response.cjs
CHANGED
|
@@ -24,12 +24,12 @@ __export(response_exports, {
|
|
|
24
24
|
pageParamsSchema: () => pageParamsSchema
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(response_exports);
|
|
27
|
-
var
|
|
27
|
+
var import_v4 = require("zod/v4");
|
|
28
28
|
function pageParamsSchema(max = 100, defaultLimit = 20) {
|
|
29
|
-
return
|
|
30
|
-
limit:
|
|
31
|
-
prev:
|
|
32
|
-
next:
|
|
29
|
+
return import_v4.z.object({
|
|
30
|
+
limit: import_v4.z.coerce.number().int().min(1).max(max).default(defaultLimit),
|
|
31
|
+
prev: import_v4.z.string().optional(),
|
|
32
|
+
next: import_v4.z.string().optional()
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
var Cursor = {
|
package/dist/response.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/response.ts"],"sourcesContent":["import { z } from 'zod';\n\nexport type Empty = {};\nexport type EntityId = string | number;\nexport type Entity = { id: EntityId };\n\nexport type Response<T = never> = { data: T };\n\nexport type InitParams = { limit: number; parent?: string };\nexport type NextParams = { limit: number; parent?: string; next: string };\nexport type PrevParams = { limit: number; parent?: string; prev: string };\nexport type PageParams = { limit: number; prev?: string; next?: string };\nexport type ParentPageParams = { limit: number; parent: string; prev?: string; next?: string };\n\nexport type PagedResponse<T = never> = { data: T[]; paging: { next: string; prev: string } };\n\nexport function pageParamsSchema(max: number = 100, defaultLimit: number = 20) {\n return z.object({\n limit: z.coerce.number().int().min(1).max(max).default(defaultLimit),\n prev: z.string().optional(),\n next: z.string().optional(),\n });\n}\n\nexport const Cursor = {\n of(prev: bigint | number | string, next: bigint | number | string) {\n return { prev: this.encode(prev), next: this.encode(next) };\n },\n empty() {\n return { prev: '', next: '' };\n },\n encode(id: bigint | number | string): string {\n return Buffer.from(id.toString(), 'utf-8').toString('base64');\n },\n decode<T extends 'bigint' | 'number' | 'string' = 'bigint'>(\n token: string,\n type: T = 'bigint' as T\n ): T extends 'bigint' ? bigint : T extends 'number' ? number : string {\n const value = Buffer.from(token, 'base64').toString('utf-8');\n if (type === 'bigint') return BigInt(value) as any;\n if (type === 'number') return Number(value) as any;\n return value as any;\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/response.ts"],"sourcesContent":["import { z } from 'zod/v4';\n\nexport type Empty = {};\nexport type EntityId = string | number;\nexport type Entity = { id: EntityId };\n\nexport type Response<T = never> = { data: T };\n\nexport type InitParams = { limit: number; parent?: string };\nexport type NextParams = { limit: number; parent?: string; next: string };\nexport type PrevParams = { limit: number; parent?: string; prev: string };\nexport type PageParams = { limit: number; prev?: string; next?: string };\nexport type ParentPageParams = { limit: number; parent: string; prev?: string; next?: string };\n\nexport type PagedResponse<T = never> = { data: T[]; paging: { next: string; prev: string } };\n\nexport function pageParamsSchema(max: number = 100, defaultLimit: number = 20) {\n return z.object({\n limit: z.coerce.number().int().min(1).max(max).default(defaultLimit),\n prev: z.string().optional(),\n next: z.string().optional(),\n });\n}\n\nexport const Cursor = {\n of(prev: bigint | number | string, next: bigint | number | string) {\n return { prev: this.encode(prev), next: this.encode(next) };\n },\n empty() {\n return { prev: '', next: '' };\n },\n encode(id: bigint | number | string): string {\n return Buffer.from(id.toString(), 'utf-8').toString('base64');\n },\n decode<T extends 'bigint' | 'number' | 'string' = 'bigint'>(\n token: string,\n type: T = 'bigint' as T\n ): T extends 'bigint' ? bigint : T extends 'number' ? number : string {\n const value = Buffer.from(token, 'base64').toString('utf-8');\n if (type === 'bigint') return BigInt(value) as any;\n if (type === 'number') return Number(value) as any;\n return value as any;\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAkB;AAgBX,SAAS,iBAAiB,MAAc,KAAK,eAAuB,IAAI;AAC7E,SAAO,YAAE,OAAO;AAAA,IACd,OAAO,YAAE,OAAO,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,QAAQ,YAAY;AAAA,IACnE,MAAM,YAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,MAAM,YAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,CAAC;AACH;AAEO,IAAM,SAAS;AAAA,EACpB,GAAG,MAAgC,MAAgC;AACjE,WAAO,EAAE,MAAM,KAAK,OAAO,IAAI,GAAG,MAAM,KAAK,OAAO,IAAI,EAAE;AAAA,EAC5D;AAAA,EACA,QAAQ;AACN,WAAO,EAAE,MAAM,IAAI,MAAM,GAAG;AAAA,EAC9B;AAAA,EACA,OAAO,IAAsC;AAC3C,WAAO,OAAO,KAAK,GAAG,SAAS,GAAG,OAAO,EAAE,SAAS,QAAQ;AAAA,EAC9D;AAAA,EACA,OACE,OACA,OAAU,UAC0D;AACpE,UAAM,QAAQ,OAAO,KAAK,OAAO,QAAQ,EAAE,SAAS,OAAO;AAC3D,QAAI,SAAS,SAAU,QAAO,OAAO,KAAK;AAC1C,QAAI,SAAS,SAAU,QAAO,OAAO,KAAK;AAC1C,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/response.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
2
|
|
|
3
3
|
type Empty = {};
|
|
4
4
|
type EntityId = string | number;
|
|
@@ -41,18 +41,10 @@ type PagedResponse<T = never> = {
|
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
43
|
declare function pageParamsSchema(max?: number, defaultLimit?: number): z.ZodObject<{
|
|
44
|
-
limit: z.ZodDefault<z.
|
|
44
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
45
45
|
prev: z.ZodOptional<z.ZodString>;
|
|
46
46
|
next: z.ZodOptional<z.ZodString>;
|
|
47
|
-
},
|
|
48
|
-
limit: number;
|
|
49
|
-
prev?: string | undefined;
|
|
50
|
-
next?: string | undefined;
|
|
51
|
-
}, {
|
|
52
|
-
limit?: number | undefined;
|
|
53
|
-
prev?: string | undefined;
|
|
54
|
-
next?: string | undefined;
|
|
55
|
-
}>;
|
|
47
|
+
}, z.core.$strip>;
|
|
56
48
|
declare const Cursor: {
|
|
57
49
|
of(prev: bigint | number | string, next: bigint | number | string): {
|
|
58
50
|
prev: string;
|
package/dist/response.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
2
|
|
|
3
3
|
type Empty = {};
|
|
4
4
|
type EntityId = string | number;
|
|
@@ -41,18 +41,10 @@ type PagedResponse<T = never> = {
|
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
43
|
declare function pageParamsSchema(max?: number, defaultLimit?: number): z.ZodObject<{
|
|
44
|
-
limit: z.ZodDefault<z.
|
|
44
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
45
45
|
prev: z.ZodOptional<z.ZodString>;
|
|
46
46
|
next: z.ZodOptional<z.ZodString>;
|
|
47
|
-
},
|
|
48
|
-
limit: number;
|
|
49
|
-
prev?: string | undefined;
|
|
50
|
-
next?: string | undefined;
|
|
51
|
-
}, {
|
|
52
|
-
limit?: number | undefined;
|
|
53
|
-
prev?: string | undefined;
|
|
54
|
-
next?: string | undefined;
|
|
55
|
-
}>;
|
|
47
|
+
}, z.core.$strip>;
|
|
56
48
|
declare const Cursor: {
|
|
57
49
|
of(prev: bigint | number | string, next: bigint | number | string): {
|
|
58
50
|
prev: string;
|
package/dist/response.mjs
CHANGED
package/dist/response.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/response.ts"],"sourcesContent":["import { z } from 'zod';\n\nexport type Empty = {};\nexport type EntityId = string | number;\nexport type Entity = { id: EntityId };\n\nexport type Response<T = never> = { data: T };\n\nexport type InitParams = { limit: number; parent?: string };\nexport type NextParams = { limit: number; parent?: string; next: string };\nexport type PrevParams = { limit: number; parent?: string; prev: string };\nexport type PageParams = { limit: number; prev?: string; next?: string };\nexport type ParentPageParams = { limit: number; parent: string; prev?: string; next?: string };\n\nexport type PagedResponse<T = never> = { data: T[]; paging: { next: string; prev: string } };\n\nexport function pageParamsSchema(max: number = 100, defaultLimit: number = 20) {\n return z.object({\n limit: z.coerce.number().int().min(1).max(max).default(defaultLimit),\n prev: z.string().optional(),\n next: z.string().optional(),\n });\n}\n\nexport const Cursor = {\n of(prev: bigint | number | string, next: bigint | number | string) {\n return { prev: this.encode(prev), next: this.encode(next) };\n },\n empty() {\n return { prev: '', next: '' };\n },\n encode(id: bigint | number | string): string {\n return Buffer.from(id.toString(), 'utf-8').toString('base64');\n },\n decode<T extends 'bigint' | 'number' | 'string' = 'bigint'>(\n token: string,\n type: T = 'bigint' as T\n ): T extends 'bigint' ? bigint : T extends 'number' ? number : string {\n const value = Buffer.from(token, 'base64').toString('utf-8');\n if (type === 'bigint') return BigInt(value) as any;\n if (type === 'number') return Number(value) as any;\n return value as any;\n },\n};\n"],"mappings":";AAAA,SAAS,SAAS;AAgBX,SAAS,iBAAiB,MAAc,KAAK,eAAuB,IAAI;AAC7E,SAAO,EAAE,OAAO;AAAA,IACd,OAAO,EAAE,OAAO,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,QAAQ,YAAY;AAAA,IACnE,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,CAAC;AACH;AAEO,IAAM,SAAS;AAAA,EACpB,GAAG,MAAgC,MAAgC;AACjE,WAAO,EAAE,MAAM,KAAK,OAAO,IAAI,GAAG,MAAM,KAAK,OAAO,IAAI,EAAE;AAAA,EAC5D;AAAA,EACA,QAAQ;AACN,WAAO,EAAE,MAAM,IAAI,MAAM,GAAG;AAAA,EAC9B;AAAA,EACA,OAAO,IAAsC;AAC3C,WAAO,OAAO,KAAK,GAAG,SAAS,GAAG,OAAO,EAAE,SAAS,QAAQ;AAAA,EAC9D;AAAA,EACA,OACE,OACA,OAAU,UAC0D;AACpE,UAAM,QAAQ,OAAO,KAAK,OAAO,QAAQ,EAAE,SAAS,OAAO;AAC3D,QAAI,SAAS,SAAU,QAAO,OAAO,KAAK;AAC1C,QAAI,SAAS,SAAU,QAAO,OAAO,KAAK;AAC1C,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/response.ts"],"sourcesContent":["import { z } from 'zod/v4';\n\nexport type Empty = {};\nexport type EntityId = string | number;\nexport type Entity = { id: EntityId };\n\nexport type Response<T = never> = { data: T };\n\nexport type InitParams = { limit: number; parent?: string };\nexport type NextParams = { limit: number; parent?: string; next: string };\nexport type PrevParams = { limit: number; parent?: string; prev: string };\nexport type PageParams = { limit: number; prev?: string; next?: string };\nexport type ParentPageParams = { limit: number; parent: string; prev?: string; next?: string };\n\nexport type PagedResponse<T = never> = { data: T[]; paging: { next: string; prev: string } };\n\nexport function pageParamsSchema(max: number = 100, defaultLimit: number = 20) {\n return z.object({\n limit: z.coerce.number().int().min(1).max(max).default(defaultLimit),\n prev: z.string().optional(),\n next: z.string().optional(),\n });\n}\n\nexport const Cursor = {\n of(prev: bigint | number | string, next: bigint | number | string) {\n return { prev: this.encode(prev), next: this.encode(next) };\n },\n empty() {\n return { prev: '', next: '' };\n },\n encode(id: bigint | number | string): string {\n return Buffer.from(id.toString(), 'utf-8').toString('base64');\n },\n decode<T extends 'bigint' | 'number' | 'string' = 'bigint'>(\n token: string,\n type: T = 'bigint' as T\n ): T extends 'bigint' ? bigint : T extends 'number' ? number : string {\n const value = Buffer.from(token, 'base64').toString('utf-8');\n if (type === 'bigint') return BigInt(value) as any;\n if (type === 'number') return Number(value) as any;\n return value as any;\n },\n};\n"],"mappings":";AAAA,SAAS,SAAS;AAgBX,SAAS,iBAAiB,MAAc,KAAK,eAAuB,IAAI;AAC7E,SAAO,EAAE,OAAO;AAAA,IACd,OAAO,EAAE,OAAO,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,QAAQ,YAAY;AAAA,IACnE,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,CAAC;AACH;AAEO,IAAM,SAAS;AAAA,EACpB,GAAG,MAAgC,MAAgC;AACjE,WAAO,EAAE,MAAM,KAAK,OAAO,IAAI,GAAG,MAAM,KAAK,OAAO,IAAI,EAAE;AAAA,EAC5D;AAAA,EACA,QAAQ;AACN,WAAO,EAAE,MAAM,IAAI,MAAM,GAAG;AAAA,EAC9B;AAAA,EACA,OAAO,IAAsC;AAC3C,WAAO,OAAO,KAAK,GAAG,SAAS,GAAG,OAAO,EAAE,SAAS,QAAQ;AAAA,EAC9D;AAAA,EACA,OACE,OACA,OAAU,UAC0D;AACpE,UAAM,QAAQ,OAAO,KAAK,OAAO,QAAQ,EAAE,SAAS,OAAO;AAC3D,QAAI,SAAS,SAAU,QAAO,OAAO,KAAK;AAC1C,QAAI,SAAS,SAAU,QAAO,OAAO,KAAK;AAC1C,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
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/invariant.ts
|
|
21
|
+
var invariant_exports = {};
|
|
22
|
+
__export(invariant_exports, {
|
|
23
|
+
invariant: () => invariant
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(invariant_exports);
|
|
26
|
+
var prefix = "Invariant failed";
|
|
27
|
+
function invariant(condition, message) {
|
|
28
|
+
if (condition) return;
|
|
29
|
+
const provided = typeof message === "function" ? message() : message;
|
|
30
|
+
const value = provided ? `${prefix}: ${provided}` : prefix;
|
|
31
|
+
throw new Error(value);
|
|
32
|
+
}
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
invariant
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=invariant.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/invariant.ts"],"sourcesContent":["const prefix = 'Invariant failed';\n\nexport function invariant(condition: any, message?: string | (() => string)): asserts condition {\n if (condition) return;\n const provided: string | undefined = typeof message === 'function' ? message() : message;\n const value: string = provided ? `${prefix}: ${provided}` : prefix;\n throw new Error(value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAM,SAAS;AAER,SAAS,UAAU,WAAgB,SAAsD;AAC9F,MAAI,UAAW;AACf,QAAM,WAA+B,OAAO,YAAY,aAAa,QAAQ,IAAI;AACjF,QAAM,QAAgB,WAAW,GAAG,MAAM,KAAK,QAAQ,KAAK;AAC5D,QAAM,IAAI,MAAM,KAAK;AACvB;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/utils/invariant.ts
|
|
2
|
+
var prefix = "Invariant failed";
|
|
3
|
+
function invariant(condition, message) {
|
|
4
|
+
if (condition) return;
|
|
5
|
+
const provided = typeof message === "function" ? message() : message;
|
|
6
|
+
const value = provided ? `${prefix}: ${provided}` : prefix;
|
|
7
|
+
throw new Error(value);
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
invariant
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=invariant.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/invariant.ts"],"sourcesContent":["const prefix = 'Invariant failed';\n\nexport function invariant(condition: any, message?: string | (() => string)): asserts condition {\n if (condition) return;\n const provided: string | undefined = typeof message === 'function' ? message() : message;\n const value: string = provided ? `${prefix}: ${provided}` : prefix;\n throw new Error(value);\n}\n"],"mappings":";AAAA,IAAM,SAAS;AAER,SAAS,UAAU,WAAgB,SAAsD;AAC9F,MAAI,UAAW;AACf,QAAM,WAA+B,OAAO,YAAY,aAAa,QAAQ,IAAI;AACjF,QAAM,QAAgB,WAAW,GAAG,MAAM,KAAK,QAAQ,KAAK;AAC5D,QAAM,IAAI,MAAM,KAAK;AACvB;","names":[]}
|
|
@@ -0,0 +1,67 @@
|
|
|
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/token-bucket.ts
|
|
21
|
+
var token_bucket_exports = {};
|
|
22
|
+
__export(token_bucket_exports, {
|
|
23
|
+
TokenBucket: () => TokenBucket
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(token_bucket_exports);
|
|
26
|
+
var TokenBucket = class {
|
|
27
|
+
rate;
|
|
28
|
+
capacity;
|
|
29
|
+
requested;
|
|
30
|
+
timer;
|
|
31
|
+
tokens;
|
|
32
|
+
constructor({ rate, capacity, requested }) {
|
|
33
|
+
if (rate <= 0) throw new Error("rate must be greater than 0");
|
|
34
|
+
if (capacity <= 0) throw new Error("capacity must be greater than 0");
|
|
35
|
+
if (requested <= 0) throw new Error("requested must be greater than 0");
|
|
36
|
+
if (requested > capacity) throw new Error("requested must be less than or equal to capacity");
|
|
37
|
+
this.rate = rate;
|
|
38
|
+
this.capacity = capacity;
|
|
39
|
+
this.requested = requested;
|
|
40
|
+
this.tokens = capacity;
|
|
41
|
+
this.timer = setInterval(() => {
|
|
42
|
+
if (this.tokens < this.capacity) {
|
|
43
|
+
const tokens = this.tokens + this.rate;
|
|
44
|
+
this.tokens = Math.min(tokens, this.capacity);
|
|
45
|
+
}
|
|
46
|
+
}, 1e3);
|
|
47
|
+
}
|
|
48
|
+
wait(ms) {
|
|
49
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
50
|
+
}
|
|
51
|
+
async removeTokens() {
|
|
52
|
+
while (this.tokens < this.requested) {
|
|
53
|
+
const ms = Math.ceil(1e3 * (this.requested - this.tokens) / this.rate);
|
|
54
|
+
await this.wait(ms);
|
|
55
|
+
}
|
|
56
|
+
this.tokens -= this.requested;
|
|
57
|
+
return this.tokens;
|
|
58
|
+
}
|
|
59
|
+
destroy() {
|
|
60
|
+
clearInterval(this.timer);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
TokenBucket
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=token-bucket.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/token-bucket.ts"],"sourcesContent":["export interface TokenBucketOptions {\n rate: number;\n capacity: number;\n requested: number;\n}\n\nexport class TokenBucket {\n readonly rate: number;\n readonly capacity: number;\n readonly requested: number;\n private readonly timer: number | NodeJS.Timeout;\n private tokens: number;\n\n constructor({ rate, capacity, requested }: TokenBucketOptions) {\n if (rate <= 0) throw new Error('rate must be greater than 0');\n if (capacity <= 0) throw new Error('capacity must be greater than 0');\n if (requested <= 0) throw new Error('requested must be greater than 0');\n if (requested > capacity) throw new Error('requested must be less than or equal to capacity');\n\n this.rate = rate;\n this.capacity = capacity;\n this.requested = requested;\n this.tokens = capacity;\n this.timer = setInterval(() => {\n if (this.tokens < this.capacity) {\n const tokens = this.tokens + this.rate;\n this.tokens = Math.min(tokens, this.capacity);\n }\n }, 1000);\n }\n\n private wait(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n async removeTokens(): Promise<number> {\n while (this.tokens < this.requested) {\n const ms = Math.ceil((1000 * (this.requested - this.tokens)) / this.rate);\n await this.wait(ms);\n }\n this.tokens -= this.requested;\n return this.tokens;\n }\n\n destroy() {\n clearInterval(this.timer);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,IAAM,cAAN,MAAkB;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACQ;AAAA,EACT;AAAA,EAER,YAAY,EAAE,MAAM,UAAU,UAAU,GAAuB;AAC7D,QAAI,QAAQ,EAAG,OAAM,IAAI,MAAM,6BAA6B;AAC5D,QAAI,YAAY,EAAG,OAAM,IAAI,MAAM,iCAAiC;AACpE,QAAI,aAAa,EAAG,OAAM,IAAI,MAAM,kCAAkC;AACtE,QAAI,YAAY,SAAU,OAAM,IAAI,MAAM,kDAAkD;AAE5F,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,SAAK,YAAY;AACjB,SAAK,SAAS;AACd,SAAK,QAAQ,YAAY,MAAM;AAC7B,UAAI,KAAK,SAAS,KAAK,UAAU;AAC/B,cAAM,SAAS,KAAK,SAAS,KAAK;AAClC,aAAK,SAAS,KAAK,IAAI,QAAQ,KAAK,QAAQ;AAAA,MAC9C;AAAA,IACF,GAAG,GAAI;AAAA,EACT;AAAA,EAEQ,KAAK,IAA2B;AACtC,WAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AAAA,EACzD;AAAA,EAEA,MAAM,eAAgC;AACpC,WAAO,KAAK,SAAS,KAAK,WAAW;AACnC,YAAM,KAAK,KAAK,KAAM,OAAQ,KAAK,YAAY,KAAK,UAAW,KAAK,IAAI;AACxE,YAAM,KAAK,KAAK,EAAE;AAAA,IACpB;AACA,SAAK,UAAU,KAAK;AACpB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,UAAU;AACR,kBAAc,KAAK,KAAK;AAAA,EAC1B;AACF;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface TokenBucketOptions {
|
|
2
|
+
rate: number;
|
|
3
|
+
capacity: number;
|
|
4
|
+
requested: number;
|
|
5
|
+
}
|
|
6
|
+
declare class TokenBucket {
|
|
7
|
+
readonly rate: number;
|
|
8
|
+
readonly capacity: number;
|
|
9
|
+
readonly requested: number;
|
|
10
|
+
private readonly timer;
|
|
11
|
+
private tokens;
|
|
12
|
+
constructor({ rate, capacity, requested }: TokenBucketOptions);
|
|
13
|
+
private wait;
|
|
14
|
+
removeTokens(): Promise<number>;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { TokenBucket, type TokenBucketOptions };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface TokenBucketOptions {
|
|
2
|
+
rate: number;
|
|
3
|
+
capacity: number;
|
|
4
|
+
requested: number;
|
|
5
|
+
}
|
|
6
|
+
declare class TokenBucket {
|
|
7
|
+
readonly rate: number;
|
|
8
|
+
readonly capacity: number;
|
|
9
|
+
readonly requested: number;
|
|
10
|
+
private readonly timer;
|
|
11
|
+
private tokens;
|
|
12
|
+
constructor({ rate, capacity, requested }: TokenBucketOptions);
|
|
13
|
+
private wait;
|
|
14
|
+
removeTokens(): Promise<number>;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { TokenBucket, type TokenBucketOptions };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/utils/token-bucket.ts
|
|
2
|
+
var TokenBucket = class {
|
|
3
|
+
rate;
|
|
4
|
+
capacity;
|
|
5
|
+
requested;
|
|
6
|
+
timer;
|
|
7
|
+
tokens;
|
|
8
|
+
constructor({ rate, capacity, requested }) {
|
|
9
|
+
if (rate <= 0) throw new Error("rate must be greater than 0");
|
|
10
|
+
if (capacity <= 0) throw new Error("capacity must be greater than 0");
|
|
11
|
+
if (requested <= 0) throw new Error("requested must be greater than 0");
|
|
12
|
+
if (requested > capacity) throw new Error("requested must be less than or equal to capacity");
|
|
13
|
+
this.rate = rate;
|
|
14
|
+
this.capacity = capacity;
|
|
15
|
+
this.requested = requested;
|
|
16
|
+
this.tokens = capacity;
|
|
17
|
+
this.timer = setInterval(() => {
|
|
18
|
+
if (this.tokens < this.capacity) {
|
|
19
|
+
const tokens = this.tokens + this.rate;
|
|
20
|
+
this.tokens = Math.min(tokens, this.capacity);
|
|
21
|
+
}
|
|
22
|
+
}, 1e3);
|
|
23
|
+
}
|
|
24
|
+
wait(ms) {
|
|
25
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
26
|
+
}
|
|
27
|
+
async removeTokens() {
|
|
28
|
+
while (this.tokens < this.requested) {
|
|
29
|
+
const ms = Math.ceil(1e3 * (this.requested - this.tokens) / this.rate);
|
|
30
|
+
await this.wait(ms);
|
|
31
|
+
}
|
|
32
|
+
this.tokens -= this.requested;
|
|
33
|
+
return this.tokens;
|
|
34
|
+
}
|
|
35
|
+
destroy() {
|
|
36
|
+
clearInterval(this.timer);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export {
|
|
40
|
+
TokenBucket
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=token-bucket.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/token-bucket.ts"],"sourcesContent":["export interface TokenBucketOptions {\n rate: number;\n capacity: number;\n requested: number;\n}\n\nexport class TokenBucket {\n readonly rate: number;\n readonly capacity: number;\n readonly requested: number;\n private readonly timer: number | NodeJS.Timeout;\n private tokens: number;\n\n constructor({ rate, capacity, requested }: TokenBucketOptions) {\n if (rate <= 0) throw new Error('rate must be greater than 0');\n if (capacity <= 0) throw new Error('capacity must be greater than 0');\n if (requested <= 0) throw new Error('requested must be greater than 0');\n if (requested > capacity) throw new Error('requested must be less than or equal to capacity');\n\n this.rate = rate;\n this.capacity = capacity;\n this.requested = requested;\n this.tokens = capacity;\n this.timer = setInterval(() => {\n if (this.tokens < this.capacity) {\n const tokens = this.tokens + this.rate;\n this.tokens = Math.min(tokens, this.capacity);\n }\n }, 1000);\n }\n\n private wait(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n async removeTokens(): Promise<number> {\n while (this.tokens < this.requested) {\n const ms = Math.ceil((1000 * (this.requested - this.tokens)) / this.rate);\n await this.wait(ms);\n }\n this.tokens -= this.requested;\n return this.tokens;\n }\n\n destroy() {\n clearInterval(this.timer);\n }\n}\n"],"mappings":";AAMO,IAAM,cAAN,MAAkB;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACQ;AAAA,EACT;AAAA,EAER,YAAY,EAAE,MAAM,UAAU,UAAU,GAAuB;AAC7D,QAAI,QAAQ,EAAG,OAAM,IAAI,MAAM,6BAA6B;AAC5D,QAAI,YAAY,EAAG,OAAM,IAAI,MAAM,iCAAiC;AACpE,QAAI,aAAa,EAAG,OAAM,IAAI,MAAM,kCAAkC;AACtE,QAAI,YAAY,SAAU,OAAM,IAAI,MAAM,kDAAkD;AAE5F,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,SAAK,YAAY;AACjB,SAAK,SAAS;AACd,SAAK,QAAQ,YAAY,MAAM;AAC7B,UAAI,KAAK,SAAS,KAAK,UAAU;AAC/B,cAAM,SAAS,KAAK,SAAS,KAAK;AAClC,aAAK,SAAS,KAAK,IAAI,QAAQ,KAAK,QAAQ;AAAA,MAC9C;AAAA,IACF,GAAG,GAAI;AAAA,EACT;AAAA,EAEQ,KAAK,IAA2B;AACtC,WAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AAAA,EACzD;AAAA,EAEA,MAAM,eAAgC;AACpC,WAAO,KAAK,SAAS,KAAK,WAAW;AACnC,YAAM,KAAK,KAAK,KAAM,OAAQ,KAAK,YAAY,KAAK,UAAW,KAAK,IAAI;AACxE,YAAM,KAAK,KAAK,EAAE;AAAA,IACpB;AACA,SAAK,UAAU,KAAK;AACpB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,UAAU;AACR,kBAAc,KAAK,KAAK;AAAA,EAC1B;AACF;","names":[]}
|
package/dist/vaild.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vaild.ts"],"sourcesContent":["import type { z,
|
|
1
|
+
{"version":3,"sources":["../src/vaild.ts"],"sourcesContent":["import type { z, ZodType } from 'zod/v4';\nimport { Details } from './detail';\nimport { BadRequest } from './detail';\nimport { Status } from './status';\n\nexport type Result<S extends ZodType> =\n | { data: z.infer<S>; error: null }\n | { data: null; error: Response };\n\ntype Target = 'json' | 'form' | 'query' | 'param' | 'header' | 'cookie';\n\nasync function getTarget(request: Request, target: Target): Promise<any> {\n switch (target) {\n case 'json':\n return request.json();\n default:\n throw new Error(`Unsupported target: ${target}`);\n }\n}\n\nexport async function valid<S extends ZodType>(\n request: Request,\n target: Target,\n schema: S\n): Promise<Result<S>> {\n const value = await getTarget(request, target);\n const validator = await schema.safeParseAsync(value);\n if (validator.success) return { data: validator.data, error: null };\n const fieldViolations: BadRequest['fieldViolations'] = validator.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n const error = Status.invalidArgument().response(details);\n return { data: null, error };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAwB;AAExB,oBAAuB;AAQvB,eAAe,UAAU,SAAkB,QAA8B;AACvE,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO,QAAQ,KAAK;AAAA,IACtB;AACE,YAAM,IAAI,MAAM,uBAAuB,MAAM,EAAE;AAAA,EACnD;AACF;AAEA,eAAsB,MACpB,SACA,QACA,QACoB;AACpB,QAAM,QAAQ,MAAM,UAAU,SAAS,MAAM;AAC7C,QAAM,YAAY,MAAM,OAAO,eAAe,KAAK;AACnD,MAAI,UAAU,QAAS,QAAO,EAAE,MAAM,UAAU,MAAM,OAAO,KAAK;AAClE,QAAM,kBAAiD,UAAU,MAAM,OAAO;AAAA,IAC5E,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,EACxE;AACA,QAAM,UAAU,sBAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,QAAM,QAAQ,qBAAO,gBAAgB,EAAE,SAAS,OAAO;AACvD,SAAO,EAAE,MAAM,MAAM,MAAM;AAC7B;","names":[]}
|
package/dist/vaild.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ZodType, z } from 'zod/v4';
|
|
2
2
|
|
|
3
|
-
type Result<S extends
|
|
3
|
+
type Result<S extends ZodType> = {
|
|
4
4
|
data: z.infer<S>;
|
|
5
5
|
error: null;
|
|
6
6
|
} | {
|
|
@@ -8,6 +8,6 @@ type Result<S extends ZodSchema> = {
|
|
|
8
8
|
error: Response;
|
|
9
9
|
};
|
|
10
10
|
type Target = 'json' | 'form' | 'query' | 'param' | 'header' | 'cookie';
|
|
11
|
-
declare function valid<S extends
|
|
11
|
+
declare function valid<S extends ZodType>(request: Request, target: Target, schema: S): Promise<Result<S>>;
|
|
12
12
|
|
|
13
13
|
export { type Result, valid };
|
package/dist/vaild.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ZodType, z } from 'zod/v4';
|
|
2
2
|
|
|
3
|
-
type Result<S extends
|
|
3
|
+
type Result<S extends ZodType> = {
|
|
4
4
|
data: z.infer<S>;
|
|
5
5
|
error: null;
|
|
6
6
|
} | {
|
|
@@ -8,6 +8,6 @@ type Result<S extends ZodSchema> = {
|
|
|
8
8
|
error: Response;
|
|
9
9
|
};
|
|
10
10
|
type Target = 'json' | 'form' | 'query' | 'param' | 'header' | 'cookie';
|
|
11
|
-
declare function valid<S extends
|
|
11
|
+
declare function valid<S extends ZodType>(request: Request, target: Target, schema: S): Promise<Result<S>>;
|
|
12
12
|
|
|
13
13
|
export { type Result, valid };
|
package/dist/vaild.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vaild.ts"],"sourcesContent":["import type { z,
|
|
1
|
+
{"version":3,"sources":["../src/vaild.ts"],"sourcesContent":["import type { z, ZodType } from 'zod/v4';\nimport { Details } from './detail';\nimport { BadRequest } from './detail';\nimport { Status } from './status';\n\nexport type Result<S extends ZodType> =\n | { data: z.infer<S>; error: null }\n | { data: null; error: Response };\n\ntype Target = 'json' | 'form' | 'query' | 'param' | 'header' | 'cookie';\n\nasync function getTarget(request: Request, target: Target): Promise<any> {\n switch (target) {\n case 'json':\n return request.json();\n default:\n throw new Error(`Unsupported target: ${target}`);\n }\n}\n\nexport async function valid<S extends ZodType>(\n request: Request,\n target: Target,\n schema: S\n): Promise<Result<S>> {\n const value = await getTarget(request, target);\n const validator = await schema.safeParseAsync(value);\n if (validator.success) return { data: validator.data, error: null };\n const fieldViolations: BadRequest['fieldViolations'] = validator.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n const error = Status.invalidArgument().response(details);\n return { data: null, error };\n}\n"],"mappings":";AACA,SAAS,eAAe;AAExB,SAAS,cAAc;AAQvB,eAAe,UAAU,SAAkB,QAA8B;AACvE,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO,QAAQ,KAAK;AAAA,IACtB;AACE,YAAM,IAAI,MAAM,uBAAuB,MAAM,EAAE;AAAA,EACnD;AACF;AAEA,eAAsB,MACpB,SACA,QACA,QACoB;AACpB,QAAM,QAAQ,MAAM,UAAU,SAAS,MAAM;AAC7C,QAAM,YAAY,MAAM,OAAO,eAAe,KAAK;AACnD,MAAI,UAAU,QAAS,QAAO,EAAE,MAAM,UAAU,MAAM,OAAO,KAAK;AAClE,QAAM,kBAAiD,UAAU,MAAM,OAAO;AAAA,IAC5E,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,EACxE;AACA,QAAM,UAAU,QAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,QAAM,QAAQ,OAAO,gBAAgB,EAAE,SAAS,OAAO;AACvD,SAAO,EAAE,MAAM,MAAM,MAAM;AAC7B;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shware/http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
],
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/jest": "^29.5.14",
|
|
33
|
-
"@types/node": "^22.15.
|
|
33
|
+
"@types/node": "^22.15.30",
|
|
34
34
|
"jest": "^29.7.0",
|
|
35
35
|
"ts-jest": "^29.3.4",
|
|
36
36
|
"typescript": "^5.8.3"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"zod": "^3.
|
|
39
|
+
"zod": "^3.25.53"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"hono": "^4.7.9"
|