@shware/http 1.2.0 → 1.2.2
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/README.md +1 -3
- package/dist/__tests__/index.test.cjs +27 -0
- package/dist/__tests__/index.test.cjs.map +1 -0
- package/dist/__tests__/index.test.d.cts +2 -0
- package/dist/__tests__/index.test.d.ts +2 -0
- package/dist/__tests__/index.test.mjs +25 -0
- package/dist/__tests__/index.test.mjs.map +1 -0
- package/dist/cache/index.cjs +32 -0
- package/dist/cache/index.cjs.map +1 -0
- package/dist/cache/index.d.cts +9 -0
- package/dist/cache/index.d.ts +9 -0
- package/dist/cache/index.mjs +7 -0
- package/dist/cache/index.mjs.map +1 -0
- package/dist/error/detail.cjs +93 -0
- package/dist/error/detail.cjs.map +1 -0
- package/dist/error/detail.d.cts +99 -0
- package/dist/error/detail.d.ts +99 -0
- package/dist/error/detail.mjs +67 -0
- package/dist/error/detail.mjs.map +1 -0
- package/dist/error/i18n/en-us.cjs +31 -0
- package/dist/error/i18n/en-us.cjs.map +1 -0
- package/dist/error/i18n/en-us.d.cts +3 -0
- package/dist/error/i18n/en-us.d.ts +3 -0
- package/dist/error/i18n/en-us.mjs +6 -0
- package/dist/error/i18n/en-us.mjs.map +1 -0
- package/dist/error/index.cjs +63 -0
- package/dist/error/index.cjs.map +1 -0
- package/dist/error/index.d.cts +19 -0
- package/dist/error/index.d.ts +19 -0
- package/dist/error/index.mjs +35 -0
- package/dist/error/index.mjs.map +1 -0
- package/dist/error/parse.cjs +52 -0
- package/dist/error/parse.cjs.map +1 -0
- package/dist/error/parse.d.cts +16 -0
- package/dist/error/parse.d.ts +16 -0
- package/dist/error/parse.mjs +27 -0
- package/dist/error/parse.mjs.map +1 -0
- package/dist/error/reason.cjs +19 -0
- package/dist/error/reason.cjs.map +1 -0
- package/dist/error/reason.d.cts +66 -0
- package/dist/error/reason.d.ts +66 -0
- package/dist/error/reason.mjs +1 -0
- package/dist/error/reason.mjs.map +1 -0
- package/dist/error/status.cjs +263 -0
- package/dist/error/status.cjs.map +1 -0
- package/dist/error/status.d.cts +69 -0
- package/dist/error/status.d.ts +69 -0
- package/dist/error/status.mjs +234 -0
- package/dist/error/status.mjs.map +1 -0
- package/dist/google-one-tap/index.cjs +51 -0
- package/dist/google-one-tap/index.cjs.map +1 -0
- package/dist/google-one-tap/index.d.cts +17 -0
- package/dist/google-one-tap/index.d.ts +17 -0
- package/dist/google-one-tap/index.mjs +26 -0
- package/dist/google-one-tap/index.mjs.map +1 -0
- package/dist/google-one-tap/types.cjs +19 -0
- package/dist/google-one-tap/types.cjs.map +1 -0
- package/dist/google-one-tap/types.d.cts +155 -0
- package/dist/google-one-tap/types.d.ts +155 -0
- package/dist/google-one-tap/types.mjs +1 -0
- package/dist/google-one-tap/types.mjs.map +1 -0
- package/dist/hono/__tests__/authorizer.test.cjs +483 -0
- package/dist/hono/__tests__/authorizer.test.cjs.map +1 -0
- package/dist/hono/__tests__/authorizer.test.d.cts +2 -0
- package/dist/hono/__tests__/authorizer.test.d.ts +2 -0
- package/dist/hono/__tests__/authorizer.test.mjs +481 -0
- package/dist/hono/__tests__/authorizer.test.mjs.map +1 -0
- package/dist/hono/__tests__/csrf.test.cjs +162 -0
- package/dist/hono/__tests__/csrf.test.cjs.map +1 -0
- package/dist/hono/__tests__/csrf.test.d.cts +2 -0
- package/dist/hono/__tests__/csrf.test.d.ts +2 -0
- package/dist/hono/__tests__/csrf.test.mjs +160 -0
- package/dist/hono/__tests__/csrf.test.mjs.map +1 -0
- package/dist/hono/authorizer.cjs +67 -0
- package/dist/hono/authorizer.cjs.map +1 -0
- package/dist/hono/authorizer.d.cts +18 -0
- package/dist/hono/authorizer.d.ts +18 -0
- package/dist/hono/authorizer.mjs +42 -0
- package/dist/hono/authorizer.mjs.map +1 -0
- package/dist/hono/csrf.cjs +95 -0
- package/dist/hono/csrf.cjs.map +1 -0
- package/dist/hono/csrf.d.cts +65 -0
- package/dist/hono/csrf.d.ts +65 -0
- package/dist/hono/csrf.mjs +70 -0
- package/dist/hono/csrf.mjs.map +1 -0
- package/dist/hono/geolocation.cjs +75 -0
- package/dist/hono/geolocation.cjs.map +1 -0
- package/dist/hono/geolocation.d.cts +17 -0
- package/dist/hono/geolocation.d.ts +17 -0
- package/dist/hono/geolocation.mjs +50 -0
- package/dist/hono/geolocation.mjs.map +1 -0
- package/dist/hono/handler.cjs +68 -0
- package/dist/hono/handler.cjs.map +1 -0
- package/dist/hono/handler.d.cts +13 -0
- package/dist/hono/handler.d.ts +13 -0
- package/dist/hono/handler.mjs +42 -0
- package/dist/hono/handler.mjs.map +1 -0
- package/dist/hono/index.cjs +45 -0
- package/dist/hono/index.cjs.map +1 -0
- package/dist/hono/index.d.cts +12 -0
- package/dist/hono/index.d.ts +12 -0
- package/dist/hono/index.mjs +15 -0
- package/dist/hono/index.mjs.map +1 -0
- package/dist/hono/validator.cjs +64 -0
- package/dist/hono/validator.cjs.map +1 -0
- package/dist/hono/validator.d.cts +28 -0
- package/dist/hono/validator.d.ts +28 -0
- package/dist/hono/validator.mjs +38 -0
- package/dist/hono/validator.mjs.map +1 -0
- package/dist/index-BnPgRQDl.d.cts +129 -0
- package/dist/index-BnPgRQDl.d.ts +129 -0
- package/dist/index.cjs +91 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.mjs +46 -0
- package/dist/index.mjs.map +1 -0
- package/dist/iso/iso_3601_1.cjs +292 -0
- package/dist/iso/iso_3601_1.cjs.map +1 -0
- package/dist/iso/iso_3601_1.d.cts +9 -0
- package/dist/iso/iso_3601_1.d.ts +9 -0
- package/dist/iso/iso_3601_1.mjs +267 -0
- package/dist/iso/iso_3601_1.mjs.map +1 -0
- package/dist/max-length/index.cjs +94 -0
- package/dist/max-length/index.cjs.map +1 -0
- package/dist/max-length/index.d.cts +1 -0
- package/dist/max-length/index.d.ts +1 -0
- package/dist/max-length/index.mjs +48 -0
- package/dist/max-length/index.mjs.map +1 -0
- package/dist/message.cjs +32 -0
- package/dist/message.cjs.map +1 -0
- package/dist/message.d.cts +3 -0
- package/dist/message.d.ts +3 -0
- package/dist/message.mjs +7 -0
- package/dist/message.mjs.map +1 -0
- package/dist/polyfills/index.cjs +7 -0
- package/dist/polyfills/index.cjs.map +1 -0
- package/dist/polyfills/index.d.cts +2 -0
- package/dist/polyfills/index.d.ts +2 -0
- package/dist/polyfills/index.mjs +5 -0
- package/dist/polyfills/index.mjs.map +1 -0
- package/dist/response.cjs +73 -0
- package/dist/response.cjs.map +1 -0
- package/dist/response.d.cts +65 -0
- package/dist/response.d.ts +65 -0
- package/dist/response.mjs +44 -0
- package/dist/response.mjs.map +1 -0
- package/dist/snowflake.cjs +75 -0
- package/dist/snowflake.cjs.map +1 -0
- package/dist/snowflake.d.cts +29 -0
- package/dist/snowflake.d.ts +29 -0
- package/dist/snowflake.mjs +49 -0
- package/dist/snowflake.mjs.map +1 -0
- package/dist/utils/__tests__/ip.test.cjs +38 -0
- package/dist/utils/__tests__/ip.test.cjs.map +1 -0
- package/dist/utils/__tests__/ip.test.d.cts +2 -0
- package/dist/utils/__tests__/ip.test.d.ts +2 -0
- package/dist/utils/__tests__/ip.test.mjs +36 -0
- package/dist/utils/__tests__/ip.test.mjs.map +1 -0
- 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/ip.cjs +53 -0
- package/dist/utils/ip.cjs.map +1 -0
- package/dist/utils/ip.d.cts +3 -0
- package/dist/utils/ip.d.ts +3 -0
- package/dist/utils/ip.mjs +28 -0
- package/dist/utils/ip.mjs.map +1 -0
- package/dist/utils/promise.cjs +47 -0
- package/dist/utils/promise.cjs.map +1 -0
- package/dist/utils/promise.d.cts +3 -0
- package/dist/utils/promise.d.ts +3 -0
- package/dist/utils/promise.mjs +22 -0
- package/dist/utils/promise.mjs.map +1 -0
- package/dist/utils/string.cjs +33 -0
- package/dist/utils/string.cjs.map +1 -0
- package/dist/utils/string.d.cts +6 -0
- package/dist/utils/string.d.ts +6 -0
- package/dist/utils/string.mjs +8 -0
- package/dist/utils/string.mjs.map +1 -0
- 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/dist/utils/token-bucket.cjs +73 -0
- package/dist/utils/token-bucket.cjs.map +1 -0
- package/dist/utils/token-bucket.d.cts +20 -0
- package/dist/utils/token-bucket.d.ts +20 -0
- package/dist/utils/token-bucket.mjs +48 -0
- package/dist/utils/token-bucket.mjs.map +1 -0
- package/dist/vaild.cjs +51 -0
- package/dist/vaild.cjs.map +1 -0
- package/dist/vaild.d.cts +13 -0
- package/dist/vaild.d.ts +13 -0
- package/dist/vaild.mjs +26 -0
- package/dist/vaild.mjs.map +1 -0
- package/dist/webhook/index.cjs +77 -0
- package/dist/webhook/index.cjs.map +1 -0
- package/dist/webhook/index.d.cts +10 -0
- package/dist/webhook/index.d.ts +10 -0
- package/dist/webhook/index.mjs +52 -0
- package/dist/webhook/index.mjs.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/polyfills/index.ts"],"sourcesContent":["// @ts-expect-error fixed: Do not know how to serialize a BigInt\nBigInt.prototype.toJSON = function () {\n return this.toString();\n};\n"],"mappings":";AACA,OAAO,UAAU,SAAS,WAAY;AACpC,SAAO,KAAK,SAAS;AACvB;","names":[]}
|
|
@@ -0,0 +1,73 @@
|
|
|
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/response.ts
|
|
21
|
+
var response_exports = {};
|
|
22
|
+
__export(response_exports, {
|
|
23
|
+
Cursor: () => Cursor,
|
|
24
|
+
getNextPageParam: () => getNextPageParam,
|
|
25
|
+
getPreviousPageParam: () => getPreviousPageParam,
|
|
26
|
+
initialPageParam: () => initialPageParam,
|
|
27
|
+
pageParamsSchema: () => pageParamsSchema
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(response_exports);
|
|
30
|
+
var import_mini = require("zod/mini");
|
|
31
|
+
var import_string = require("./utils/string.cjs");
|
|
32
|
+
function pageParamsSchema(max = 100, defaultLimit = 20) {
|
|
33
|
+
return (0, import_mini.object)({
|
|
34
|
+
limit: (0, import_mini._default)(import_mini.coerce.number().check((0, import_mini.int)(), (0, import_mini.minimum)(1), (0, import_mini.maximum)(max)), defaultLimit),
|
|
35
|
+
prev: (0, import_mini.optional)((0, import_mini.string)()),
|
|
36
|
+
next: (0, import_mini.optional)((0, import_mini.string)())
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
var Cursor = {
|
|
40
|
+
of(prev, next) {
|
|
41
|
+
return { prev: prev ? this.encode(prev) : "", next: next ? this.encode(next) : "" };
|
|
42
|
+
},
|
|
43
|
+
empty() {
|
|
44
|
+
return { prev: "", next: "" };
|
|
45
|
+
},
|
|
46
|
+
encode(id) {
|
|
47
|
+
return Buffer.from(id.toString(), "utf-8").toString("base64");
|
|
48
|
+
},
|
|
49
|
+
decode(token, type = "bigint") {
|
|
50
|
+
const value = Buffer.from(token, "base64").toString("utf-8");
|
|
51
|
+
if (type === "bigint")
|
|
52
|
+
return BigInt(value);
|
|
53
|
+
if (type === "number")
|
|
54
|
+
return Number(value);
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var initialPageParam = { next: "", prev: "" };
|
|
59
|
+
function getPreviousPageParam(first) {
|
|
60
|
+
return (0, import_string.hasText)(first.paging.prev) ? { next: "", prev: first.paging.prev } : null;
|
|
61
|
+
}
|
|
62
|
+
function getNextPageParam(last) {
|
|
63
|
+
return (0, import_string.hasText)(last.paging.next) ? { next: last.paging.next, prev: "" } : null;
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
Cursor,
|
|
68
|
+
getNextPageParam,
|
|
69
|
+
getPreviousPageParam,
|
|
70
|
+
initialPageParam,
|
|
71
|
+
pageParamsSchema
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=response.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/response.ts"],"sourcesContent":["import { _default, coerce, int, maximum, minimum, object, optional, string } from 'zod/mini';\nimport { hasText } from './utils/string';\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\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 };\nexport type Page<T = never> = { data: T[]; paging: { next: string; prev: string } };\n\nexport function pageParamsSchema(max: number = 100, defaultLimit: number = 20) {\n return object({\n limit: _default(coerce.number().check(int(), minimum(1), maximum(max)), defaultLimit),\n prev: optional(string()),\n next: optional(string()),\n });\n}\n\nexport const Cursor = {\n of(prev: bigint | number | string | undefined, next: bigint | number | string | undefined) {\n return { prev: prev ? this.encode(prev) : '', next: 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')\n return BigInt(value) as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n if (type === 'number')\n return Number(value) as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n return value as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n },\n};\n\nexport const initialPageParam: Omit<PageParams, 'limit'> = { next: '', prev: '' };\n\nexport function getPreviousPageParam<T = never>(first: Page<T>): Omit<PageParams, 'limit'> | null {\n return hasText(first.paging.prev) ? { next: '', prev: first.paging.prev } : null;\n}\n\nexport function getNextPageParam<T = never>(last: Page<T>): Omit<PageParams, 'limit'> | null {\n return hasText(last.paging.next) ? { next: last.paging.next, prev: '' } : null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAkF;AAClF,oBAAwB;AAgBjB,SAAS,iBAAiB,MAAc,KAAK,eAAuB,IAAI;AAC7E,aAAO,oBAAO;AAAA,IACZ,WAAO,sBAAS,mBAAO,OAAO,EAAE,UAAM,iBAAI,OAAG,qBAAQ,CAAC,OAAG,qBAAQ,GAAG,CAAC,GAAG,YAAY;AAAA,IACpF,UAAM,0BAAS,oBAAO,CAAC;AAAA,IACvB,UAAM,0BAAS,oBAAO,CAAC;AAAA,EACzB,CAAC;AACH;AAEO,IAAM,SAAS;AAAA,EACpB,GAAG,MAA4C,MAA4C;AACzF,WAAO,EAAE,MAAM,OAAO,KAAK,OAAO,IAAI,IAAI,IAAI,MAAM,OAAO,KAAK,OAAO,IAAI,IAAI,GAAG;AAAA,EACpF;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;AACX,aAAO,OAAO,KAAK;AACrB,QAAI,SAAS;AACX,aAAO,OAAO,KAAK;AACrB,WAAO;AAAA,EACT;AACF;AAEO,IAAM,mBAA8C,EAAE,MAAM,IAAI,MAAM,GAAG;AAEzE,SAAS,qBAAgC,OAAkD;AAChG,aAAO,uBAAQ,MAAM,OAAO,IAAI,IAAI,EAAE,MAAM,IAAI,MAAM,MAAM,OAAO,KAAK,IAAI;AAC9E;AAEO,SAAS,iBAA4B,MAAiD;AAC3F,aAAO,uBAAQ,KAAK,OAAO,IAAI,IAAI,EAAE,MAAM,KAAK,OAAO,MAAM,MAAM,GAAG,IAAI;AAC5E;","names":[]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as zod_v4_core from 'zod/v4/core';
|
|
2
|
+
import * as zod_mini from 'zod/mini';
|
|
3
|
+
|
|
4
|
+
type Empty = {};
|
|
5
|
+
type EntityId = string | number;
|
|
6
|
+
type Entity = {
|
|
7
|
+
id: EntityId;
|
|
8
|
+
};
|
|
9
|
+
type Response<T = never> = {
|
|
10
|
+
data: T;
|
|
11
|
+
};
|
|
12
|
+
type InitParams = {
|
|
13
|
+
limit: number;
|
|
14
|
+
parent?: string;
|
|
15
|
+
};
|
|
16
|
+
type NextParams = {
|
|
17
|
+
limit: number;
|
|
18
|
+
parent?: string;
|
|
19
|
+
next: string;
|
|
20
|
+
};
|
|
21
|
+
type PrevParams = {
|
|
22
|
+
limit: number;
|
|
23
|
+
parent?: string;
|
|
24
|
+
prev: string;
|
|
25
|
+
};
|
|
26
|
+
type PageParams = {
|
|
27
|
+
limit: number;
|
|
28
|
+
prev?: string;
|
|
29
|
+
next?: string;
|
|
30
|
+
};
|
|
31
|
+
type ParentPageParams = {
|
|
32
|
+
limit: number;
|
|
33
|
+
parent: string;
|
|
34
|
+
prev?: string;
|
|
35
|
+
next?: string;
|
|
36
|
+
};
|
|
37
|
+
type Page<T = never> = {
|
|
38
|
+
data: T[];
|
|
39
|
+
paging: {
|
|
40
|
+
next: string;
|
|
41
|
+
prev: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
declare function pageParamsSchema(max?: number, defaultLimit?: number): zod_mini.ZodMiniObject<{
|
|
45
|
+
limit: zod_mini.ZodMiniDefault<zod_mini.ZodMiniNumber<unknown>>;
|
|
46
|
+
prev: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
47
|
+
next: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
48
|
+
}, zod_v4_core.$strip>;
|
|
49
|
+
declare const Cursor: {
|
|
50
|
+
of(prev: bigint | number | string | undefined, next: bigint | number | string | undefined): {
|
|
51
|
+
prev: string;
|
|
52
|
+
next: string;
|
|
53
|
+
};
|
|
54
|
+
empty(): {
|
|
55
|
+
prev: string;
|
|
56
|
+
next: string;
|
|
57
|
+
};
|
|
58
|
+
encode(id: bigint | number | string): string;
|
|
59
|
+
decode<T extends "bigint" | "number" | "string" = "bigint">(token: string, type?: T): T extends "bigint" ? bigint : T extends "number" ? number : string;
|
|
60
|
+
};
|
|
61
|
+
declare const initialPageParam: Omit<PageParams, 'limit'>;
|
|
62
|
+
declare function getPreviousPageParam<T = never>(first: Page<T>): Omit<PageParams, 'limit'> | null;
|
|
63
|
+
declare function getNextPageParam<T = never>(last: Page<T>): Omit<PageParams, 'limit'> | null;
|
|
64
|
+
|
|
65
|
+
export { Cursor, type Empty, type Entity, type EntityId, type InitParams, type NextParams, type Page, type PageParams, type ParentPageParams, type PrevParams, type Response, getNextPageParam, getPreviousPageParam, initialPageParam, pageParamsSchema };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as zod_v4_core from 'zod/v4/core';
|
|
2
|
+
import * as zod_mini from 'zod/mini';
|
|
3
|
+
|
|
4
|
+
type Empty = {};
|
|
5
|
+
type EntityId = string | number;
|
|
6
|
+
type Entity = {
|
|
7
|
+
id: EntityId;
|
|
8
|
+
};
|
|
9
|
+
type Response<T = never> = {
|
|
10
|
+
data: T;
|
|
11
|
+
};
|
|
12
|
+
type InitParams = {
|
|
13
|
+
limit: number;
|
|
14
|
+
parent?: string;
|
|
15
|
+
};
|
|
16
|
+
type NextParams = {
|
|
17
|
+
limit: number;
|
|
18
|
+
parent?: string;
|
|
19
|
+
next: string;
|
|
20
|
+
};
|
|
21
|
+
type PrevParams = {
|
|
22
|
+
limit: number;
|
|
23
|
+
parent?: string;
|
|
24
|
+
prev: string;
|
|
25
|
+
};
|
|
26
|
+
type PageParams = {
|
|
27
|
+
limit: number;
|
|
28
|
+
prev?: string;
|
|
29
|
+
next?: string;
|
|
30
|
+
};
|
|
31
|
+
type ParentPageParams = {
|
|
32
|
+
limit: number;
|
|
33
|
+
parent: string;
|
|
34
|
+
prev?: string;
|
|
35
|
+
next?: string;
|
|
36
|
+
};
|
|
37
|
+
type Page<T = never> = {
|
|
38
|
+
data: T[];
|
|
39
|
+
paging: {
|
|
40
|
+
next: string;
|
|
41
|
+
prev: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
declare function pageParamsSchema(max?: number, defaultLimit?: number): zod_mini.ZodMiniObject<{
|
|
45
|
+
limit: zod_mini.ZodMiniDefault<zod_mini.ZodMiniNumber<unknown>>;
|
|
46
|
+
prev: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
47
|
+
next: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
48
|
+
}, zod_v4_core.$strip>;
|
|
49
|
+
declare const Cursor: {
|
|
50
|
+
of(prev: bigint | number | string | undefined, next: bigint | number | string | undefined): {
|
|
51
|
+
prev: string;
|
|
52
|
+
next: string;
|
|
53
|
+
};
|
|
54
|
+
empty(): {
|
|
55
|
+
prev: string;
|
|
56
|
+
next: string;
|
|
57
|
+
};
|
|
58
|
+
encode(id: bigint | number | string): string;
|
|
59
|
+
decode<T extends "bigint" | "number" | "string" = "bigint">(token: string, type?: T): T extends "bigint" ? bigint : T extends "number" ? number : string;
|
|
60
|
+
};
|
|
61
|
+
declare const initialPageParam: Omit<PageParams, 'limit'>;
|
|
62
|
+
declare function getPreviousPageParam<T = never>(first: Page<T>): Omit<PageParams, 'limit'> | null;
|
|
63
|
+
declare function getNextPageParam<T = never>(last: Page<T>): Omit<PageParams, 'limit'> | null;
|
|
64
|
+
|
|
65
|
+
export { Cursor, type Empty, type Entity, type EntityId, type InitParams, type NextParams, type Page, type PageParams, type ParentPageParams, type PrevParams, type Response, getNextPageParam, getPreviousPageParam, initialPageParam, pageParamsSchema };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/response.ts
|
|
2
|
+
import { _default, coerce, int, maximum, minimum, object, optional, string } from "zod/mini";
|
|
3
|
+
import { hasText } from "./utils/string.mjs";
|
|
4
|
+
function pageParamsSchema(max = 100, defaultLimit = 20) {
|
|
5
|
+
return object({
|
|
6
|
+
limit: _default(coerce.number().check(int(), minimum(1), maximum(max)), defaultLimit),
|
|
7
|
+
prev: optional(string()),
|
|
8
|
+
next: optional(string())
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
var Cursor = {
|
|
12
|
+
of(prev, next) {
|
|
13
|
+
return { prev: prev ? this.encode(prev) : "", next: next ? this.encode(next) : "" };
|
|
14
|
+
},
|
|
15
|
+
empty() {
|
|
16
|
+
return { prev: "", next: "" };
|
|
17
|
+
},
|
|
18
|
+
encode(id) {
|
|
19
|
+
return Buffer.from(id.toString(), "utf-8").toString("base64");
|
|
20
|
+
},
|
|
21
|
+
decode(token, type = "bigint") {
|
|
22
|
+
const value = Buffer.from(token, "base64").toString("utf-8");
|
|
23
|
+
if (type === "bigint")
|
|
24
|
+
return BigInt(value);
|
|
25
|
+
if (type === "number")
|
|
26
|
+
return Number(value);
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var initialPageParam = { next: "", prev: "" };
|
|
31
|
+
function getPreviousPageParam(first) {
|
|
32
|
+
return hasText(first.paging.prev) ? { next: "", prev: first.paging.prev } : null;
|
|
33
|
+
}
|
|
34
|
+
function getNextPageParam(last) {
|
|
35
|
+
return hasText(last.paging.next) ? { next: last.paging.next, prev: "" } : null;
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
Cursor,
|
|
39
|
+
getNextPageParam,
|
|
40
|
+
getPreviousPageParam,
|
|
41
|
+
initialPageParam,
|
|
42
|
+
pageParamsSchema
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=response.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/response.ts"],"sourcesContent":["import { _default, coerce, int, maximum, minimum, object, optional, string } from 'zod/mini';\nimport { hasText } from './utils/string';\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\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 };\nexport type Page<T = never> = { data: T[]; paging: { next: string; prev: string } };\n\nexport function pageParamsSchema(max: number = 100, defaultLimit: number = 20) {\n return object({\n limit: _default(coerce.number().check(int(), minimum(1), maximum(max)), defaultLimit),\n prev: optional(string()),\n next: optional(string()),\n });\n}\n\nexport const Cursor = {\n of(prev: bigint | number | string | undefined, next: bigint | number | string | undefined) {\n return { prev: prev ? this.encode(prev) : '', next: 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')\n return BigInt(value) as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n if (type === 'number')\n return Number(value) as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n return value as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n },\n};\n\nexport const initialPageParam: Omit<PageParams, 'limit'> = { next: '', prev: '' };\n\nexport function getPreviousPageParam<T = never>(first: Page<T>): Omit<PageParams, 'limit'> | null {\n return hasText(first.paging.prev) ? { next: '', prev: first.paging.prev } : null;\n}\n\nexport function getNextPageParam<T = never>(last: Page<T>): Omit<PageParams, 'limit'> | null {\n return hasText(last.paging.next) ? { next: last.paging.next, prev: '' } : null;\n}\n"],"mappings":";AAAA,SAAS,UAAU,QAAQ,KAAK,SAAS,SAAS,QAAQ,UAAU,cAAc;AAClF,SAAS,eAAe;AAgBjB,SAAS,iBAAiB,MAAc,KAAK,eAAuB,IAAI;AAC7E,SAAO,OAAO;AAAA,IACZ,OAAO,SAAS,OAAO,OAAO,EAAE,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,QAAQ,GAAG,CAAC,GAAG,YAAY;AAAA,IACpF,MAAM,SAAS,OAAO,CAAC;AAAA,IACvB,MAAM,SAAS,OAAO,CAAC;AAAA,EACzB,CAAC;AACH;AAEO,IAAM,SAAS;AAAA,EACpB,GAAG,MAA4C,MAA4C;AACzF,WAAO,EAAE,MAAM,OAAO,KAAK,OAAO,IAAI,IAAI,IAAI,MAAM,OAAO,KAAK,OAAO,IAAI,IAAI,GAAG;AAAA,EACpF;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;AACX,aAAO,OAAO,KAAK;AACrB,QAAI,SAAS;AACX,aAAO,OAAO,KAAK;AACrB,WAAO;AAAA,EACT;AACF;AAEO,IAAM,mBAA8C,EAAE,MAAM,IAAI,MAAM,GAAG;AAEzE,SAAS,qBAAgC,OAAkD;AAChG,SAAO,QAAQ,MAAM,OAAO,IAAI,IAAI,EAAE,MAAM,IAAI,MAAM,MAAM,OAAO,KAAK,IAAI;AAC9E;AAEO,SAAS,iBAA4B,MAAiD;AAC3F,SAAO,QAAQ,KAAK,OAAO,IAAI,IAAI,EAAE,MAAM,KAAK,OAAO,MAAM,MAAM,GAAG,IAAI;AAC5E;","names":[]}
|
|
@@ -0,0 +1,75 @@
|
|
|
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/snowflake.ts
|
|
21
|
+
var snowflake_exports = {};
|
|
22
|
+
__export(snowflake_exports, {
|
|
23
|
+
UidGenerator: () => UidGenerator,
|
|
24
|
+
uid: () => uid
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(snowflake_exports);
|
|
27
|
+
function getNextMillisecond(timestamp) {
|
|
28
|
+
let now = BigInt(Date.now());
|
|
29
|
+
while (now < timestamp) {
|
|
30
|
+
now = BigInt(Date.now());
|
|
31
|
+
}
|
|
32
|
+
return now;
|
|
33
|
+
}
|
|
34
|
+
var UidGenerator = class {
|
|
35
|
+
MAX = (1n << 63n) - 1n;
|
|
36
|
+
machineBits = BigInt(10);
|
|
37
|
+
sequenceBits = BigInt(12);
|
|
38
|
+
epochMillisecond = BigInt(1577808e6);
|
|
39
|
+
// 2020-1-1 00:00:00
|
|
40
|
+
sequenceMask = ~(BigInt(-1) << this.sequenceBits);
|
|
41
|
+
maxMachineId = ~(BigInt(-1) << this.machineBits);
|
|
42
|
+
machineIdShift = this.sequenceBits;
|
|
43
|
+
timeStampShift = this.machineBits + this.sequenceBits;
|
|
44
|
+
machineId;
|
|
45
|
+
sequence = BigInt(0);
|
|
46
|
+
lastTimestamp = BigInt(-1);
|
|
47
|
+
constructor(mackineId) {
|
|
48
|
+
this.machineId = BigInt(mackineId) % this.maxMachineId;
|
|
49
|
+
}
|
|
50
|
+
next = () => {
|
|
51
|
+
let timestamp = BigInt(Date.now());
|
|
52
|
+
if (timestamp < this.lastTimestamp) {
|
|
53
|
+
console.error(`Clock moved backwards. time gap = ${this.lastTimestamp - timestamp}`);
|
|
54
|
+
timestamp = getNextMillisecond(this.lastTimestamp);
|
|
55
|
+
}
|
|
56
|
+
if (timestamp === this.lastTimestamp) {
|
|
57
|
+
this.sequence = this.sequence + BigInt(1) & this.sequenceMask;
|
|
58
|
+
if (this.sequence === BigInt(0)) {
|
|
59
|
+
timestamp = getNextMillisecond(timestamp);
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
this.sequence = BigInt(0);
|
|
63
|
+
}
|
|
64
|
+
this.lastTimestamp = timestamp;
|
|
65
|
+
return timestamp - this.epochMillisecond << this.timeStampShift | this.machineId << this.machineIdShift | this.sequence;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
var machineId = Math.floor(Math.random() * 1024);
|
|
69
|
+
var uid = new UidGenerator(machineId);
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
UidGenerator,
|
|
73
|
+
uid
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=snowflake.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/snowflake.ts"],"sourcesContent":["/**\n * A distributed unique ID generator inspired by Twitter's Snowflake.\n *\n * ID data bits:\n * +----------------------+----------------+-----------+\n * | delta millisecond | machine id | sequence |\n * +----------------------+----------------+-----------+\n * | 41bits | 10bits | 12bits |\n * +----------------------+----------------+-----------+\n *\n */\n\nfunction getNextMillisecond(timestamp: bigint) {\n let now = BigInt(Date.now());\n while (now < timestamp) {\n now = BigInt(Date.now());\n }\n return now;\n}\n\nexport class UidGenerator {\n public readonly MAX = (1n << 63n) - 1n;\n private readonly machineBits = BigInt(10);\n private readonly sequenceBits = BigInt(12);\n private readonly epochMillisecond = BigInt(1577808000000); // 2020-1-1 00:00:00\n private readonly sequenceMask = ~(BigInt(-1) << this.sequenceBits);\n private readonly maxMachineId = ~(BigInt(-1) << this.machineBits);\n private readonly machineIdShift = this.sequenceBits;\n private readonly timeStampShift = this.machineBits + this.sequenceBits;\n private readonly machineId: bigint;\n private sequence = BigInt(0);\n private lastTimestamp = BigInt(-1);\n\n constructor(mackineId: number) {\n this.machineId = BigInt(mackineId) % this.maxMachineId;\n }\n\n public readonly next = (): bigint => {\n let timestamp = BigInt(Date.now());\n if (timestamp < this.lastTimestamp) {\n console.error(`Clock moved backwards. time gap = ${this.lastTimestamp - timestamp}`);\n timestamp = getNextMillisecond(this.lastTimestamp);\n }\n if (timestamp === this.lastTimestamp) {\n this.sequence = (this.sequence + BigInt(1)) & this.sequenceMask;\n if (this.sequence === BigInt(0)) {\n timestamp = getNextMillisecond(timestamp);\n }\n } else {\n this.sequence = BigInt(0);\n }\n this.lastTimestamp = timestamp;\n return (\n ((timestamp - this.epochMillisecond) << this.timeStampShift) |\n (this.machineId << this.machineIdShift) |\n this.sequence\n );\n };\n}\n\nconst machineId = Math.floor(Math.random() * 1024);\nexport const uid = new UidGenerator(machineId);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,SAAS,mBAAmB,WAAmB;AAC7C,MAAI,MAAM,OAAO,KAAK,IAAI,CAAC;AAC3B,SAAO,MAAM,WAAW;AACtB,UAAM,OAAO,KAAK,IAAI,CAAC;AAAA,EACzB;AACA,SAAO;AACT;AAEO,IAAM,eAAN,MAAmB;AAAA,EACR,OAAO,MAAM,OAAO;AAAA,EACnB,cAAc,OAAO,EAAE;AAAA,EACvB,eAAe,OAAO,EAAE;AAAA,EACxB,mBAAmB,OAAO,SAAa;AAAA;AAAA,EACvC,eAAe,EAAE,OAAO,EAAE,KAAK,KAAK;AAAA,EACpC,eAAe,EAAE,OAAO,EAAE,KAAK,KAAK;AAAA,EACpC,iBAAiB,KAAK;AAAA,EACtB,iBAAiB,KAAK,cAAc,KAAK;AAAA,EACzC;AAAA,EACT,WAAW,OAAO,CAAC;AAAA,EACnB,gBAAgB,OAAO,EAAE;AAAA,EAEjC,YAAY,WAAmB;AAC7B,SAAK,YAAY,OAAO,SAAS,IAAI,KAAK;AAAA,EAC5C;AAAA,EAEgB,OAAO,MAAc;AACnC,QAAI,YAAY,OAAO,KAAK,IAAI,CAAC;AACjC,QAAI,YAAY,KAAK,eAAe;AAClC,cAAQ,MAAM,qCAAqC,KAAK,gBAAgB,SAAS,EAAE;AACnF,kBAAY,mBAAmB,KAAK,aAAa;AAAA,IACnD;AACA,QAAI,cAAc,KAAK,eAAe;AACpC,WAAK,WAAY,KAAK,WAAW,OAAO,CAAC,IAAK,KAAK;AACnD,UAAI,KAAK,aAAa,OAAO,CAAC,GAAG;AAC/B,oBAAY,mBAAmB,SAAS;AAAA,MAC1C;AAAA,IACF,OAAO;AACL,WAAK,WAAW,OAAO,CAAC;AAAA,IAC1B;AACA,SAAK,gBAAgB;AACrB,WACI,YAAY,KAAK,oBAAqB,KAAK,iBAC5C,KAAK,aAAa,KAAK,iBACxB,KAAK;AAAA,EAET;AACF;AAEA,IAAM,YAAY,KAAK,MAAM,KAAK,OAAO,IAAI,IAAI;AAC1C,IAAM,MAAM,IAAI,aAAa,SAAS;","names":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A distributed unique ID generator inspired by Twitter's Snowflake.
|
|
3
|
+
*
|
|
4
|
+
* ID data bits:
|
|
5
|
+
* +----------------------+----------------+-----------+
|
|
6
|
+
* | delta millisecond | machine id | sequence |
|
|
7
|
+
* +----------------------+----------------+-----------+
|
|
8
|
+
* | 41bits | 10bits | 12bits |
|
|
9
|
+
* +----------------------+----------------+-----------+
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
declare class UidGenerator {
|
|
13
|
+
readonly MAX: bigint;
|
|
14
|
+
private readonly machineBits;
|
|
15
|
+
private readonly sequenceBits;
|
|
16
|
+
private readonly epochMillisecond;
|
|
17
|
+
private readonly sequenceMask;
|
|
18
|
+
private readonly maxMachineId;
|
|
19
|
+
private readonly machineIdShift;
|
|
20
|
+
private readonly timeStampShift;
|
|
21
|
+
private readonly machineId;
|
|
22
|
+
private sequence;
|
|
23
|
+
private lastTimestamp;
|
|
24
|
+
constructor(mackineId: number);
|
|
25
|
+
readonly next: () => bigint;
|
|
26
|
+
}
|
|
27
|
+
declare const uid: UidGenerator;
|
|
28
|
+
|
|
29
|
+
export { UidGenerator, uid };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A distributed unique ID generator inspired by Twitter's Snowflake.
|
|
3
|
+
*
|
|
4
|
+
* ID data bits:
|
|
5
|
+
* +----------------------+----------------+-----------+
|
|
6
|
+
* | delta millisecond | machine id | sequence |
|
|
7
|
+
* +----------------------+----------------+-----------+
|
|
8
|
+
* | 41bits | 10bits | 12bits |
|
|
9
|
+
* +----------------------+----------------+-----------+
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
declare class UidGenerator {
|
|
13
|
+
readonly MAX: bigint;
|
|
14
|
+
private readonly machineBits;
|
|
15
|
+
private readonly sequenceBits;
|
|
16
|
+
private readonly epochMillisecond;
|
|
17
|
+
private readonly sequenceMask;
|
|
18
|
+
private readonly maxMachineId;
|
|
19
|
+
private readonly machineIdShift;
|
|
20
|
+
private readonly timeStampShift;
|
|
21
|
+
private readonly machineId;
|
|
22
|
+
private sequence;
|
|
23
|
+
private lastTimestamp;
|
|
24
|
+
constructor(mackineId: number);
|
|
25
|
+
readonly next: () => bigint;
|
|
26
|
+
}
|
|
27
|
+
declare const uid: UidGenerator;
|
|
28
|
+
|
|
29
|
+
export { UidGenerator, uid };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/snowflake.ts
|
|
2
|
+
function getNextMillisecond(timestamp) {
|
|
3
|
+
let now = BigInt(Date.now());
|
|
4
|
+
while (now < timestamp) {
|
|
5
|
+
now = BigInt(Date.now());
|
|
6
|
+
}
|
|
7
|
+
return now;
|
|
8
|
+
}
|
|
9
|
+
var UidGenerator = class {
|
|
10
|
+
MAX = (1n << 63n) - 1n;
|
|
11
|
+
machineBits = BigInt(10);
|
|
12
|
+
sequenceBits = BigInt(12);
|
|
13
|
+
epochMillisecond = BigInt(1577808e6);
|
|
14
|
+
// 2020-1-1 00:00:00
|
|
15
|
+
sequenceMask = ~(BigInt(-1) << this.sequenceBits);
|
|
16
|
+
maxMachineId = ~(BigInt(-1) << this.machineBits);
|
|
17
|
+
machineIdShift = this.sequenceBits;
|
|
18
|
+
timeStampShift = this.machineBits + this.sequenceBits;
|
|
19
|
+
machineId;
|
|
20
|
+
sequence = BigInt(0);
|
|
21
|
+
lastTimestamp = BigInt(-1);
|
|
22
|
+
constructor(mackineId) {
|
|
23
|
+
this.machineId = BigInt(mackineId) % this.maxMachineId;
|
|
24
|
+
}
|
|
25
|
+
next = () => {
|
|
26
|
+
let timestamp = BigInt(Date.now());
|
|
27
|
+
if (timestamp < this.lastTimestamp) {
|
|
28
|
+
console.error(`Clock moved backwards. time gap = ${this.lastTimestamp - timestamp}`);
|
|
29
|
+
timestamp = getNextMillisecond(this.lastTimestamp);
|
|
30
|
+
}
|
|
31
|
+
if (timestamp === this.lastTimestamp) {
|
|
32
|
+
this.sequence = this.sequence + BigInt(1) & this.sequenceMask;
|
|
33
|
+
if (this.sequence === BigInt(0)) {
|
|
34
|
+
timestamp = getNextMillisecond(timestamp);
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
this.sequence = BigInt(0);
|
|
38
|
+
}
|
|
39
|
+
this.lastTimestamp = timestamp;
|
|
40
|
+
return timestamp - this.epochMillisecond << this.timeStampShift | this.machineId << this.machineIdShift | this.sequence;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
var machineId = Math.floor(Math.random() * 1024);
|
|
44
|
+
var uid = new UidGenerator(machineId);
|
|
45
|
+
export {
|
|
46
|
+
UidGenerator,
|
|
47
|
+
uid
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=snowflake.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/snowflake.ts"],"sourcesContent":["/**\n * A distributed unique ID generator inspired by Twitter's Snowflake.\n *\n * ID data bits:\n * +----------------------+----------------+-----------+\n * | delta millisecond | machine id | sequence |\n * +----------------------+----------------+-----------+\n * | 41bits | 10bits | 12bits |\n * +----------------------+----------------+-----------+\n *\n */\n\nfunction getNextMillisecond(timestamp: bigint) {\n let now = BigInt(Date.now());\n while (now < timestamp) {\n now = BigInt(Date.now());\n }\n return now;\n}\n\nexport class UidGenerator {\n public readonly MAX = (1n << 63n) - 1n;\n private readonly machineBits = BigInt(10);\n private readonly sequenceBits = BigInt(12);\n private readonly epochMillisecond = BigInt(1577808000000); // 2020-1-1 00:00:00\n private readonly sequenceMask = ~(BigInt(-1) << this.sequenceBits);\n private readonly maxMachineId = ~(BigInt(-1) << this.machineBits);\n private readonly machineIdShift = this.sequenceBits;\n private readonly timeStampShift = this.machineBits + this.sequenceBits;\n private readonly machineId: bigint;\n private sequence = BigInt(0);\n private lastTimestamp = BigInt(-1);\n\n constructor(mackineId: number) {\n this.machineId = BigInt(mackineId) % this.maxMachineId;\n }\n\n public readonly next = (): bigint => {\n let timestamp = BigInt(Date.now());\n if (timestamp < this.lastTimestamp) {\n console.error(`Clock moved backwards. time gap = ${this.lastTimestamp - timestamp}`);\n timestamp = getNextMillisecond(this.lastTimestamp);\n }\n if (timestamp === this.lastTimestamp) {\n this.sequence = (this.sequence + BigInt(1)) & this.sequenceMask;\n if (this.sequence === BigInt(0)) {\n timestamp = getNextMillisecond(timestamp);\n }\n } else {\n this.sequence = BigInt(0);\n }\n this.lastTimestamp = timestamp;\n return (\n ((timestamp - this.epochMillisecond) << this.timeStampShift) |\n (this.machineId << this.machineIdShift) |\n this.sequence\n );\n };\n}\n\nconst machineId = Math.floor(Math.random() * 1024);\nexport const uid = new UidGenerator(machineId);\n"],"mappings":";AAYA,SAAS,mBAAmB,WAAmB;AAC7C,MAAI,MAAM,OAAO,KAAK,IAAI,CAAC;AAC3B,SAAO,MAAM,WAAW;AACtB,UAAM,OAAO,KAAK,IAAI,CAAC;AAAA,EACzB;AACA,SAAO;AACT;AAEO,IAAM,eAAN,MAAmB;AAAA,EACR,OAAO,MAAM,OAAO;AAAA,EACnB,cAAc,OAAO,EAAE;AAAA,EACvB,eAAe,OAAO,EAAE;AAAA,EACxB,mBAAmB,OAAO,SAAa;AAAA;AAAA,EACvC,eAAe,EAAE,OAAO,EAAE,KAAK,KAAK;AAAA,EACpC,eAAe,EAAE,OAAO,EAAE,KAAK,KAAK;AAAA,EACpC,iBAAiB,KAAK;AAAA,EACtB,iBAAiB,KAAK,cAAc,KAAK;AAAA,EACzC;AAAA,EACT,WAAW,OAAO,CAAC;AAAA,EACnB,gBAAgB,OAAO,EAAE;AAAA,EAEjC,YAAY,WAAmB;AAC7B,SAAK,YAAY,OAAO,SAAS,IAAI,KAAK;AAAA,EAC5C;AAAA,EAEgB,OAAO,MAAc;AACnC,QAAI,YAAY,OAAO,KAAK,IAAI,CAAC;AACjC,QAAI,YAAY,KAAK,eAAe;AAClC,cAAQ,MAAM,qCAAqC,KAAK,gBAAgB,SAAS,EAAE;AACnF,kBAAY,mBAAmB,KAAK,aAAa;AAAA,IACnD;AACA,QAAI,cAAc,KAAK,eAAe;AACpC,WAAK,WAAY,KAAK,WAAW,OAAO,CAAC,IAAK,KAAK;AACnD,UAAI,KAAK,aAAa,OAAO,CAAC,GAAG;AAC/B,oBAAY,mBAAmB,SAAS;AAAA,MAC1C;AAAA,IACF,OAAO;AACL,WAAK,WAAW,OAAO,CAAC;AAAA,IAC1B;AACA,SAAK,gBAAgB;AACrB,WACI,YAAY,KAAK,oBAAqB,KAAK,iBAC5C,KAAK,aAAa,KAAK,iBACxB,KAAK;AAAA,EAET;AACF;AAEA,IAAM,YAAY,KAAK,MAAM,KAAK,OAAO,IAAI,IAAI;AAC1C,IAAM,MAAM,IAAI,aAAa,SAAS;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// src/utils/__tests__/ip.test.ts
|
|
4
|
+
var import_ip = require("../ip.cjs");
|
|
5
|
+
describe("extractIpAddress", () => {
|
|
6
|
+
it("should extract the ipv4 address from the request", () => {
|
|
7
|
+
expect((0, import_ip.extractIpAddress)("127.0.0.1")).toBe("127.0.0.1");
|
|
8
|
+
expect((0, import_ip.extractIpAddress)("192.168.0.1")).toBe("192.168.0.1");
|
|
9
|
+
expect((0, import_ip.extractIpAddress)("127.0.0.1:8080")).toBe("127.0.0.1");
|
|
10
|
+
expect((0, import_ip.extractIpAddress)("192.168.0.1:8080")).toBe("192.168.0.1");
|
|
11
|
+
expect((0, import_ip.extractIpAddress)("127.0.0.1:8080/path")).toBe("127.0.0.1");
|
|
12
|
+
});
|
|
13
|
+
it("should extract the ipv6 address from the request", () => {
|
|
14
|
+
expect((0, import_ip.extractIpAddress)("::1")).toBe("::1");
|
|
15
|
+
expect((0, import_ip.extractIpAddress)("[::1]:8080")).toBe("::1");
|
|
16
|
+
expect((0, import_ip.extractIpAddress)("2001:0db8:85a3:0000:0000:8a2e:0370:7334")).toBe(
|
|
17
|
+
"2001:0db8:85a3:0000:0000:8a2e:0370:7334"
|
|
18
|
+
);
|
|
19
|
+
expect((0, import_ip.extractIpAddress)("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80")).toBe(
|
|
20
|
+
"2001:db8:85a3::8a2e:370:7334"
|
|
21
|
+
// remove leading zeros
|
|
22
|
+
);
|
|
23
|
+
expect((0, import_ip.extractIpAddress)("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80/path")).toBe(
|
|
24
|
+
"2001:db8:85a3::8a2e:370:7334"
|
|
25
|
+
// remove leading zeros
|
|
26
|
+
);
|
|
27
|
+
expect((0, import_ip.extractIpAddress)("2404:7ac0:614d:bba7:cf41:992e:98e:9186:60704")).toBe(
|
|
28
|
+
"2404:7ac0:614d:bba7:cf41:992e:98e:9186"
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
it("should return null if the ip address is not valid", () => {
|
|
32
|
+
expect((0, import_ip.extractIpAddress)(null)).toBeNull();
|
|
33
|
+
expect((0, import_ip.extractIpAddress)(void 0)).toBeNull();
|
|
34
|
+
expect((0, import_ip.extractIpAddress)("invalid")).toBeNull();
|
|
35
|
+
expect((0, import_ip.extractIpAddress)("example.com")).toBeNull();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=ip.test.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/__tests__/ip.test.ts"],"sourcesContent":["import { extractIpAddress } from '../ip';\n\ndescribe('extractIpAddress', () => {\n it('should extract the ipv4 address from the request', () => {\n expect(extractIpAddress('127.0.0.1')).toBe('127.0.0.1');\n expect(extractIpAddress('192.168.0.1')).toBe('192.168.0.1');\n expect(extractIpAddress('127.0.0.1:8080')).toBe('127.0.0.1');\n expect(extractIpAddress('192.168.0.1:8080')).toBe('192.168.0.1');\n expect(extractIpAddress('127.0.0.1:8080/path')).toBe('127.0.0.1');\n });\n\n it('should extract the ipv6 address from the request', () => {\n expect(extractIpAddress('::1')).toBe('::1');\n expect(extractIpAddress('[::1]:8080')).toBe('::1');\n\n expect(extractIpAddress('2001:0db8:85a3:0000:0000:8a2e:0370:7334')).toBe(\n '2001:0db8:85a3:0000:0000:8a2e:0370:7334'\n );\n expect(extractIpAddress('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80')).toBe(\n '2001:db8:85a3::8a2e:370:7334' // remove leading zeros\n );\n expect(extractIpAddress('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80/path')).toBe(\n '2001:db8:85a3::8a2e:370:7334' // remove leading zeros\n );\n\n expect(extractIpAddress('2404:7ac0:614d:bba7:cf41:992e:98e:9186:60704')).toBe(\n '2404:7ac0:614d:bba7:cf41:992e:98e:9186'\n );\n });\n\n it('should return null if the ip address is not valid', () => {\n expect(extractIpAddress(null)).toBeNull();\n expect(extractIpAddress(undefined)).toBeNull();\n expect(extractIpAddress('invalid')).toBeNull();\n expect(extractIpAddress('example.com')).toBeNull();\n });\n});\n"],"mappings":";;;AAAA,gBAAiC;AAEjC,SAAS,oBAAoB,MAAM;AACjC,KAAG,oDAAoD,MAAM;AAC3D,eAAO,4BAAiB,WAAW,CAAC,EAAE,KAAK,WAAW;AACtD,eAAO,4BAAiB,aAAa,CAAC,EAAE,KAAK,aAAa;AAC1D,eAAO,4BAAiB,gBAAgB,CAAC,EAAE,KAAK,WAAW;AAC3D,eAAO,4BAAiB,kBAAkB,CAAC,EAAE,KAAK,aAAa;AAC/D,eAAO,4BAAiB,qBAAqB,CAAC,EAAE,KAAK,WAAW;AAAA,EAClE,CAAC;AAED,KAAG,oDAAoD,MAAM;AAC3D,eAAO,4BAAiB,KAAK,CAAC,EAAE,KAAK,KAAK;AAC1C,eAAO,4BAAiB,YAAY,CAAC,EAAE,KAAK,KAAK;AAEjD,eAAO,4BAAiB,yCAAyC,CAAC,EAAE;AAAA,MAClE;AAAA,IACF;AACA,eAAO,4BAAiB,8CAA8C,CAAC,EAAE;AAAA,MACvE;AAAA;AAAA,IACF;AACA,eAAO,4BAAiB,mDAAmD,CAAC,EAAE;AAAA,MAC5E;AAAA;AAAA,IACF;AAEA,eAAO,4BAAiB,8CAA8C,CAAC,EAAE;AAAA,MACvE;AAAA,IACF;AAAA,EACF,CAAC;AAED,KAAG,qDAAqD,MAAM;AAC5D,eAAO,4BAAiB,IAAI,CAAC,EAAE,SAAS;AACxC,eAAO,4BAAiB,MAAS,CAAC,EAAE,SAAS;AAC7C,eAAO,4BAAiB,SAAS,CAAC,EAAE,SAAS;AAC7C,eAAO,4BAAiB,aAAa,CAAC,EAAE,SAAS;AAAA,EACnD,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/utils/__tests__/ip.test.ts
|
|
2
|
+
import { extractIpAddress } from "../ip.mjs";
|
|
3
|
+
describe("extractIpAddress", () => {
|
|
4
|
+
it("should extract the ipv4 address from the request", () => {
|
|
5
|
+
expect(extractIpAddress("127.0.0.1")).toBe("127.0.0.1");
|
|
6
|
+
expect(extractIpAddress("192.168.0.1")).toBe("192.168.0.1");
|
|
7
|
+
expect(extractIpAddress("127.0.0.1:8080")).toBe("127.0.0.1");
|
|
8
|
+
expect(extractIpAddress("192.168.0.1:8080")).toBe("192.168.0.1");
|
|
9
|
+
expect(extractIpAddress("127.0.0.1:8080/path")).toBe("127.0.0.1");
|
|
10
|
+
});
|
|
11
|
+
it("should extract the ipv6 address from the request", () => {
|
|
12
|
+
expect(extractIpAddress("::1")).toBe("::1");
|
|
13
|
+
expect(extractIpAddress("[::1]:8080")).toBe("::1");
|
|
14
|
+
expect(extractIpAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334")).toBe(
|
|
15
|
+
"2001:0db8:85a3:0000:0000:8a2e:0370:7334"
|
|
16
|
+
);
|
|
17
|
+
expect(extractIpAddress("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80")).toBe(
|
|
18
|
+
"2001:db8:85a3::8a2e:370:7334"
|
|
19
|
+
// remove leading zeros
|
|
20
|
+
);
|
|
21
|
+
expect(extractIpAddress("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80/path")).toBe(
|
|
22
|
+
"2001:db8:85a3::8a2e:370:7334"
|
|
23
|
+
// remove leading zeros
|
|
24
|
+
);
|
|
25
|
+
expect(extractIpAddress("2404:7ac0:614d:bba7:cf41:992e:98e:9186:60704")).toBe(
|
|
26
|
+
"2404:7ac0:614d:bba7:cf41:992e:98e:9186"
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
it("should return null if the ip address is not valid", () => {
|
|
30
|
+
expect(extractIpAddress(null)).toBeNull();
|
|
31
|
+
expect(extractIpAddress(void 0)).toBeNull();
|
|
32
|
+
expect(extractIpAddress("invalid")).toBeNull();
|
|
33
|
+
expect(extractIpAddress("example.com")).toBeNull();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=ip.test.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/__tests__/ip.test.ts"],"sourcesContent":["import { extractIpAddress } from '../ip';\n\ndescribe('extractIpAddress', () => {\n it('should extract the ipv4 address from the request', () => {\n expect(extractIpAddress('127.0.0.1')).toBe('127.0.0.1');\n expect(extractIpAddress('192.168.0.1')).toBe('192.168.0.1');\n expect(extractIpAddress('127.0.0.1:8080')).toBe('127.0.0.1');\n expect(extractIpAddress('192.168.0.1:8080')).toBe('192.168.0.1');\n expect(extractIpAddress('127.0.0.1:8080/path')).toBe('127.0.0.1');\n });\n\n it('should extract the ipv6 address from the request', () => {\n expect(extractIpAddress('::1')).toBe('::1');\n expect(extractIpAddress('[::1]:8080')).toBe('::1');\n\n expect(extractIpAddress('2001:0db8:85a3:0000:0000:8a2e:0370:7334')).toBe(\n '2001:0db8:85a3:0000:0000:8a2e:0370:7334'\n );\n expect(extractIpAddress('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80')).toBe(\n '2001:db8:85a3::8a2e:370:7334' // remove leading zeros\n );\n expect(extractIpAddress('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80/path')).toBe(\n '2001:db8:85a3::8a2e:370:7334' // remove leading zeros\n );\n\n expect(extractIpAddress('2404:7ac0:614d:bba7:cf41:992e:98e:9186:60704')).toBe(\n '2404:7ac0:614d:bba7:cf41:992e:98e:9186'\n );\n });\n\n it('should return null if the ip address is not valid', () => {\n expect(extractIpAddress(null)).toBeNull();\n expect(extractIpAddress(undefined)).toBeNull();\n expect(extractIpAddress('invalid')).toBeNull();\n expect(extractIpAddress('example.com')).toBeNull();\n });\n});\n"],"mappings":";AAAA,SAAS,wBAAwB;AAEjC,SAAS,oBAAoB,MAAM;AACjC,KAAG,oDAAoD,MAAM;AAC3D,WAAO,iBAAiB,WAAW,CAAC,EAAE,KAAK,WAAW;AACtD,WAAO,iBAAiB,aAAa,CAAC,EAAE,KAAK,aAAa;AAC1D,WAAO,iBAAiB,gBAAgB,CAAC,EAAE,KAAK,WAAW;AAC3D,WAAO,iBAAiB,kBAAkB,CAAC,EAAE,KAAK,aAAa;AAC/D,WAAO,iBAAiB,qBAAqB,CAAC,EAAE,KAAK,WAAW;AAAA,EAClE,CAAC;AAED,KAAG,oDAAoD,MAAM;AAC3D,WAAO,iBAAiB,KAAK,CAAC,EAAE,KAAK,KAAK;AAC1C,WAAO,iBAAiB,YAAY,CAAC,EAAE,KAAK,KAAK;AAEjD,WAAO,iBAAiB,yCAAyC,CAAC,EAAE;AAAA,MAClE;AAAA,IACF;AACA,WAAO,iBAAiB,8CAA8C,CAAC,EAAE;AAAA,MACvE;AAAA;AAAA,IACF;AACA,WAAO,iBAAiB,mDAAmD,CAAC,EAAE;AAAA,MAC5E;AAAA;AAAA,IACF;AAEA,WAAO,iBAAiB,8CAA8C,CAAC,EAAE;AAAA,MACvE;AAAA,IACF;AAAA,EACF,CAAC;AAED,KAAG,qDAAqD,MAAM;AAC5D,WAAO,iBAAiB,IAAI,CAAC,EAAE,SAAS;AACxC,WAAO,iBAAiB,MAAS,CAAC,EAAE,SAAS;AAC7C,WAAO,iBAAiB,SAAS,CAAC,EAAE,SAAS;AAC7C,WAAO,iBAAiB,aAAa,CAAC,EAAE,SAAS;AAAA,EACnD,CAAC;AACH,CAAC;","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(\n condition: unknown,\n message?: string | (() => string)\n): 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,UACd,WACA,SACmB;AACnB,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
|