@shware/http 0.2.19 → 0.2.21
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/index.cjs +27 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +21 -1
- package/dist/index.mjs.map +1 -1
- package/dist/response.cjs +57 -0
- package/dist/response.cjs.map +1 -0
- package/dist/response.d.cts +69 -0
- package/dist/response.d.ts +69 -0
- package/dist/response.mjs +31 -0
- package/dist/response.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/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
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
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -16,18 +20,38 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
20
|
|
|
17
21
|
// src/index.ts
|
|
18
22
|
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
AppErrorReason: () => import_reason.AppErrorReason,
|
|
25
|
+
AuthenticationErrorReason: () => import_reason.AuthenticationErrorReason,
|
|
26
|
+
ErrorReason: () => import_reason.ErrorReason,
|
|
27
|
+
ModerationErrorReason: () => import_reason.ModerationErrorReason,
|
|
28
|
+
MultipartErrorReason: () => import_reason.MultipartErrorReason,
|
|
29
|
+
NetworkErrorReason: () => import_reason.NetworkErrorReason,
|
|
30
|
+
StatusErrorReason: () => import_reason.StatusErrorReason,
|
|
31
|
+
hasText: () => import_string.hasText
|
|
32
|
+
});
|
|
19
33
|
module.exports = __toCommonJS(index_exports);
|
|
20
|
-
|
|
34
|
+
var import_reason = require("./reason.cjs");
|
|
21
35
|
__reExport(index_exports, require("./detail.cjs"), module.exports);
|
|
22
36
|
__reExport(index_exports, require("./status.cjs"), module.exports);
|
|
23
37
|
__reExport(index_exports, require("./vaild.cjs"), module.exports);
|
|
24
38
|
__reExport(index_exports, require("./snowflake.cjs"), module.exports);
|
|
39
|
+
__reExport(index_exports, require("./response.cjs"), module.exports);
|
|
40
|
+
var import_string = require("./utils/string.cjs");
|
|
25
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
42
|
0 && (module.exports = {
|
|
27
|
-
|
|
43
|
+
AppErrorReason,
|
|
44
|
+
AuthenticationErrorReason,
|
|
45
|
+
ErrorReason,
|
|
46
|
+
ModerationErrorReason,
|
|
47
|
+
MultipartErrorReason,
|
|
48
|
+
NetworkErrorReason,
|
|
49
|
+
StatusErrorReason,
|
|
50
|
+
hasText,
|
|
28
51
|
...require("./detail.cjs"),
|
|
29
52
|
...require("./status.cjs"),
|
|
30
53
|
...require("./vaild.cjs"),
|
|
31
|
-
...require("./snowflake.cjs")
|
|
54
|
+
...require("./snowflake.cjs"),
|
|
55
|
+
...require("./response.cjs")
|
|
32
56
|
});
|
|
33
57
|
//# sourceMappingURL=index.cjs.map
|
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
|
|
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 {\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';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,oBAQO;AAEP,0BAAc,yBAvBd;AAwBA,0BAAc,yBAxBd;AAyBA,0BAAc,wBAzBd;AA0BA,0BAAc,4BA1Bd;AA2BA,0BAAc,2BA3Bd;AA4BA,oBAAwB;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -3,4 +3,6 @@ export { BadRequest, DebugInfo, Detail, DetailType, Details, ErrorInfo, Help, Lo
|
|
|
3
3
|
export { Code, DEFAULT_MESSAGES, ErrorBody, Status, StatusCode, StatusError } from './status.cjs';
|
|
4
4
|
export { Result, valid } from './vaild.cjs';
|
|
5
5
|
export { UidGenerator, uid } from './snowflake.cjs';
|
|
6
|
+
export { Cursor, Empty, Entity, EntityId, InitParams, NextParams, PageParams, PagedResponse, ParentPageParams, PrevParams, Response, pageParamsSchema } from './response.cjs';
|
|
7
|
+
export { hasText } from './utils/string.cjs';
|
|
6
8
|
import 'zod';
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ export { BadRequest, DebugInfo, Detail, DetailType, Details, ErrorInfo, Help, Lo
|
|
|
3
3
|
export { Code, DEFAULT_MESSAGES, ErrorBody, Status, StatusCode, StatusError } from './status.js';
|
|
4
4
|
export { Result, valid } from './vaild.js';
|
|
5
5
|
export { UidGenerator, uid } from './snowflake.js';
|
|
6
|
+
export { Cursor, Empty, Entity, EntityId, InitParams, NextParams, PageParams, PagedResponse, ParentPageParams, PrevParams, Response, pageParamsSchema } from './response.js';
|
|
7
|
+
export { hasText } from './utils/string.js';
|
|
6
8
|
import 'zod';
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
|
|
2
|
+
import {
|
|
3
|
+
NetworkErrorReason,
|
|
4
|
+
StatusErrorReason,
|
|
5
|
+
AuthenticationErrorReason,
|
|
6
|
+
ModerationErrorReason,
|
|
7
|
+
MultipartErrorReason,
|
|
8
|
+
AppErrorReason,
|
|
9
|
+
ErrorReason
|
|
10
|
+
} from "./reason.mjs";
|
|
3
11
|
export * from "./detail.mjs";
|
|
4
12
|
export * from "./status.mjs";
|
|
5
13
|
export * from "./vaild.mjs";
|
|
6
14
|
export * from "./snowflake.mjs";
|
|
15
|
+
export * from "./response.mjs";
|
|
16
|
+
import { hasText } from "./utils/string.mjs";
|
|
17
|
+
export {
|
|
18
|
+
AppErrorReason,
|
|
19
|
+
AuthenticationErrorReason,
|
|
20
|
+
ErrorReason,
|
|
21
|
+
ModerationErrorReason,
|
|
22
|
+
MultipartErrorReason,
|
|
23
|
+
NetworkErrorReason,
|
|
24
|
+
StatusErrorReason,
|
|
25
|
+
hasText
|
|
26
|
+
};
|
|
7
27
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport
|
|
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 {\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';\n"],"mappings":";AAaA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,eAAe;","names":[]}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
pageParamsSchema: () => pageParamsSchema
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(response_exports);
|
|
27
|
+
var import_zod = require("zod");
|
|
28
|
+
function pageParamsSchema(max = 100, defaultLimit = 20) {
|
|
29
|
+
return import_zod.z.object({
|
|
30
|
+
limit: import_zod.z.coerce.number().int().min(1).max(max).default(defaultLimit),
|
|
31
|
+
prev: import_zod.z.string().optional(),
|
|
32
|
+
next: import_zod.z.string().optional()
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
var Cursor = {
|
|
36
|
+
of(prev, next) {
|
|
37
|
+
return { prev: this.encode(prev), next: this.encode(next) };
|
|
38
|
+
},
|
|
39
|
+
empty() {
|
|
40
|
+
return { prev: "", next: "" };
|
|
41
|
+
},
|
|
42
|
+
encode(id) {
|
|
43
|
+
return Buffer.from(id.toString(), "utf-8").toString("base64");
|
|
44
|
+
},
|
|
45
|
+
decode(token, type = "bigint") {
|
|
46
|
+
const value = Buffer.from(token, "base64").toString("utf-8");
|
|
47
|
+
if (type === "bigint") return BigInt(value);
|
|
48
|
+
if (type === "number") return Number(value);
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
Cursor,
|
|
55
|
+
pageParamsSchema
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=response.cjs.map
|
|
@@ -0,0 +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,iBAAkB;AAgBX,SAAS,iBAAiB,MAAc,KAAK,eAAuB,IAAI;AAC7E,SAAO,aAAE,OAAO;AAAA,IACd,OAAO,aAAE,OAAO,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,QAAQ,YAAY;AAAA,IACnE,MAAM,aAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,MAAM,aAAE,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,69 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
type Empty = {};
|
|
4
|
+
type EntityId = string | number;
|
|
5
|
+
type Entity = {
|
|
6
|
+
id: EntityId;
|
|
7
|
+
};
|
|
8
|
+
type Response<T = never> = {
|
|
9
|
+
data: T;
|
|
10
|
+
};
|
|
11
|
+
type InitParams = {
|
|
12
|
+
limit: number;
|
|
13
|
+
parent?: string;
|
|
14
|
+
};
|
|
15
|
+
type NextParams = {
|
|
16
|
+
limit: number;
|
|
17
|
+
parent?: string;
|
|
18
|
+
next: string;
|
|
19
|
+
};
|
|
20
|
+
type PrevParams = {
|
|
21
|
+
limit: number;
|
|
22
|
+
parent?: string;
|
|
23
|
+
prev: string;
|
|
24
|
+
};
|
|
25
|
+
type PageParams = {
|
|
26
|
+
limit: number;
|
|
27
|
+
prev?: string;
|
|
28
|
+
next?: string;
|
|
29
|
+
};
|
|
30
|
+
type ParentPageParams = {
|
|
31
|
+
limit: number;
|
|
32
|
+
parent: string;
|
|
33
|
+
prev?: string;
|
|
34
|
+
next?: string;
|
|
35
|
+
};
|
|
36
|
+
type PagedResponse<T = never> = {
|
|
37
|
+
data: T[];
|
|
38
|
+
paging: {
|
|
39
|
+
next: string;
|
|
40
|
+
prev: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
declare function pageParamsSchema(max?: number, defaultLimit?: number): z.ZodObject<{
|
|
44
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
45
|
+
prev: z.ZodOptional<z.ZodString>;
|
|
46
|
+
next: z.ZodOptional<z.ZodString>;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
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
|
+
}>;
|
|
56
|
+
declare const Cursor: {
|
|
57
|
+
of(prev: bigint | number | string, next: bigint | number | string): {
|
|
58
|
+
prev: string;
|
|
59
|
+
next: string;
|
|
60
|
+
};
|
|
61
|
+
empty(): {
|
|
62
|
+
prev: string;
|
|
63
|
+
next: string;
|
|
64
|
+
};
|
|
65
|
+
encode(id: bigint | number | string): string;
|
|
66
|
+
decode<T extends "bigint" | "number" | "string" = "bigint">(token: string, type?: T): T extends "bigint" ? bigint : T extends "number" ? number : string;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { Cursor, type Empty, type Entity, type EntityId, type InitParams, type NextParams, type PageParams, type PagedResponse, type ParentPageParams, type PrevParams, type Response, pageParamsSchema };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
type Empty = {};
|
|
4
|
+
type EntityId = string | number;
|
|
5
|
+
type Entity = {
|
|
6
|
+
id: EntityId;
|
|
7
|
+
};
|
|
8
|
+
type Response<T = never> = {
|
|
9
|
+
data: T;
|
|
10
|
+
};
|
|
11
|
+
type InitParams = {
|
|
12
|
+
limit: number;
|
|
13
|
+
parent?: string;
|
|
14
|
+
};
|
|
15
|
+
type NextParams = {
|
|
16
|
+
limit: number;
|
|
17
|
+
parent?: string;
|
|
18
|
+
next: string;
|
|
19
|
+
};
|
|
20
|
+
type PrevParams = {
|
|
21
|
+
limit: number;
|
|
22
|
+
parent?: string;
|
|
23
|
+
prev: string;
|
|
24
|
+
};
|
|
25
|
+
type PageParams = {
|
|
26
|
+
limit: number;
|
|
27
|
+
prev?: string;
|
|
28
|
+
next?: string;
|
|
29
|
+
};
|
|
30
|
+
type ParentPageParams = {
|
|
31
|
+
limit: number;
|
|
32
|
+
parent: string;
|
|
33
|
+
prev?: string;
|
|
34
|
+
next?: string;
|
|
35
|
+
};
|
|
36
|
+
type PagedResponse<T = never> = {
|
|
37
|
+
data: T[];
|
|
38
|
+
paging: {
|
|
39
|
+
next: string;
|
|
40
|
+
prev: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
declare function pageParamsSchema(max?: number, defaultLimit?: number): z.ZodObject<{
|
|
44
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
45
|
+
prev: z.ZodOptional<z.ZodString>;
|
|
46
|
+
next: z.ZodOptional<z.ZodString>;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
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
|
+
}>;
|
|
56
|
+
declare const Cursor: {
|
|
57
|
+
of(prev: bigint | number | string, next: bigint | number | string): {
|
|
58
|
+
prev: string;
|
|
59
|
+
next: string;
|
|
60
|
+
};
|
|
61
|
+
empty(): {
|
|
62
|
+
prev: string;
|
|
63
|
+
next: string;
|
|
64
|
+
};
|
|
65
|
+
encode(id: bigint | number | string): string;
|
|
66
|
+
decode<T extends "bigint" | "number" | "string" = "bigint">(token: string, type?: T): T extends "bigint" ? bigint : T extends "number" ? number : string;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { Cursor, type Empty, type Entity, type EntityId, type InitParams, type NextParams, type PageParams, type PagedResponse, type ParentPageParams, type PrevParams, type Response, pageParamsSchema };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/response.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
function pageParamsSchema(max = 100, defaultLimit = 20) {
|
|
4
|
+
return z.object({
|
|
5
|
+
limit: z.coerce.number().int().min(1).max(max).default(defaultLimit),
|
|
6
|
+
prev: z.string().optional(),
|
|
7
|
+
next: z.string().optional()
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
var Cursor = {
|
|
11
|
+
of(prev, next) {
|
|
12
|
+
return { prev: this.encode(prev), next: this.encode(next) };
|
|
13
|
+
},
|
|
14
|
+
empty() {
|
|
15
|
+
return { prev: "", next: "" };
|
|
16
|
+
},
|
|
17
|
+
encode(id) {
|
|
18
|
+
return Buffer.from(id.toString(), "utf-8").toString("base64");
|
|
19
|
+
},
|
|
20
|
+
decode(token, type = "bigint") {
|
|
21
|
+
const value = Buffer.from(token, "base64").toString("utf-8");
|
|
22
|
+
if (type === "bigint") return BigInt(value);
|
|
23
|
+
if (type === "number") return Number(value);
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
Cursor,
|
|
29
|
+
pageParamsSchema
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=response.mjs.map
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
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/string.ts
|
|
21
|
+
var string_exports = {};
|
|
22
|
+
__export(string_exports, {
|
|
23
|
+
hasText: () => hasText
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(string_exports);
|
|
26
|
+
function hasText(str) {
|
|
27
|
+
return typeof str === "string" && str.trim().length !== 0;
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
hasText
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=string.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/string.ts"],"sourcesContent":["/**\n * Check whether the given String contains actual text.\n * */\nexport function hasText(str: string | null | undefined): str is string {\n return typeof str === 'string' && str.trim().length !== 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,QAAQ,KAA+C;AACrE,SAAO,OAAO,QAAQ,YAAY,IAAI,KAAK,EAAE,WAAW;AAC1D;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/string.ts"],"sourcesContent":["/**\n * Check whether the given String contains actual text.\n * */\nexport function hasText(str: string | null | undefined): str is string {\n return typeof str === 'string' && str.trim().length !== 0;\n}\n"],"mappings":";AAGO,SAAS,QAAQ,KAA+C;AACrE,SAAO,OAAO,QAAQ,YAAY,IAAI,KAAK,EAAE,WAAW;AAC1D;","names":[]}
|