@shware/http 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/response.cjs +5 -4
- package/dist/response.cjs.map +1 -1
- package/dist/response.d.cts +9 -12
- package/dist/response.d.ts +9 -12
- package/dist/response.mjs +5 -4
- package/dist/response.mjs.map +1 -1
- package/package.json +1 -1
package/dist/response.cjs
CHANGED
|
@@ -41,9 +41,10 @@ var Cursor = {
|
|
|
41
41
|
return { prev: prev ? this.encode(prev) : "", next: next ? this.encode(next) : "" };
|
|
42
42
|
},
|
|
43
43
|
empty() {
|
|
44
|
-
return { prev:
|
|
44
|
+
return { prev: void 0, next: void 0 };
|
|
45
45
|
},
|
|
46
46
|
encode(id) {
|
|
47
|
+
if (!id) return void 0;
|
|
47
48
|
return Buffer.from(id.toString(), "utf-8").toString("base64");
|
|
48
49
|
},
|
|
49
50
|
decode(token, type = "bigint") {
|
|
@@ -55,12 +56,12 @@ var Cursor = {
|
|
|
55
56
|
return value;
|
|
56
57
|
}
|
|
57
58
|
};
|
|
58
|
-
var initialPageParam = { next:
|
|
59
|
+
var initialPageParam = { next: void 0, prev: void 0 };
|
|
59
60
|
function getPreviousPageParam(first) {
|
|
60
|
-
return (0, import_utils.hasText)(first.paging.prev) ? {
|
|
61
|
+
return (0, import_utils.hasText)(first.paging.prev) ? { prev: first.paging.prev } : null;
|
|
61
62
|
}
|
|
62
63
|
function getNextPageParam(last) {
|
|
63
|
-
return (0, import_utils.hasText)(last.paging.next) ? { next: last.paging.next
|
|
64
|
+
return (0, import_utils.hasText)(last.paging.next) ? { next: last.paging.next } : null;
|
|
64
65
|
}
|
|
65
66
|
// Annotate the CommonJS export names for ESM import in node:
|
|
66
67
|
0 && (module.exports = {
|
package/dist/response.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/response.ts"],"sourcesContent":["import { hasText } from '@shware/utils';\nimport { _default, coerce, int, maximum, minimum, object, optional, string } from 'zod/mini';\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
|
|
1
|
+
{"version":3,"sources":["../src/response.ts"],"sourcesContent":["import { hasText } from '@shware/utils';\nimport { _default, coerce, int, maximum, minimum, object, optional, string } from 'zod/mini';\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 = 100, defaultLimit = 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(): Page['paging'] {\n return { prev: undefined, next: undefined };\n },\n encode(id: bigint | number | string | undefined): string | undefined {\n if (!id) return undefined;\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: Page['paging'] = { next: undefined, prev: undefined };\n\nexport function getPreviousPageParam<T = never>(first: Page<T>): Page['paging'] | null {\n return hasText(first.paging.prev) ? { prev: first.paging.prev } : null;\n}\n\nexport function getNextPageParam<T = never>(last: Page<T>): Page['paging'] | null {\n return hasText(last.paging.next) ? { next: last.paging.next } : null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwB;AACxB,kBAAkF;AAgB3E,SAAS,iBAAiB,MAAM,KAAK,eAAe,IAAI;AAC7D,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,QAAwB;AACtB,WAAO,EAAE,MAAM,QAAW,MAAM,OAAU;AAAA,EAC5C;AAAA,EACA,OAAO,IAA8D;AACnE,QAAI,CAAC,GAAI,QAAO;AAChB,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,mBAAmC,EAAE,MAAM,QAAW,MAAM,OAAU;AAE5E,SAAS,qBAAgC,OAAuC;AACrF,aAAO,sBAAQ,MAAM,OAAO,IAAI,IAAI,EAAE,MAAM,MAAM,OAAO,KAAK,IAAI;AACpE;AAEO,SAAS,iBAA4B,MAAsC;AAChF,aAAO,sBAAQ,KAAK,OAAO,IAAI,IAAI,EAAE,MAAM,KAAK,OAAO,KAAK,IAAI;AAClE;","names":[]}
|
package/dist/response.d.cts
CHANGED
|
@@ -37,8 +37,8 @@ type ParentPageParams = {
|
|
|
37
37
|
type Page<T = never> = {
|
|
38
38
|
data: T[];
|
|
39
39
|
paging: {
|
|
40
|
-
next
|
|
41
|
-
prev
|
|
40
|
+
next?: string;
|
|
41
|
+
prev?: string;
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
44
|
declare function pageParamsSchema(max?: number, defaultLimit?: number): zod_mini.ZodMiniObject<{
|
|
@@ -48,18 +48,15 @@ declare function pageParamsSchema(max?: number, defaultLimit?: number): zod_mini
|
|
|
48
48
|
}, zod_v4_core.$strip>;
|
|
49
49
|
declare const Cursor: {
|
|
50
50
|
of(prev: bigint | number | string | undefined, next: bigint | number | string | undefined): {
|
|
51
|
-
prev: string;
|
|
52
|
-
next: string;
|
|
51
|
+
prev: string | undefined;
|
|
52
|
+
next: string | undefined;
|
|
53
53
|
};
|
|
54
|
-
empty():
|
|
55
|
-
|
|
56
|
-
next: string;
|
|
57
|
-
};
|
|
58
|
-
encode(id: bigint | number | string): string;
|
|
54
|
+
empty(): Page["paging"];
|
|
55
|
+
encode(id: bigint | number | string | undefined): string | undefined;
|
|
59
56
|
decode<T extends "bigint" | "number" | "string" = "bigint">(token: string, type?: T): T extends "bigint" ? bigint : T extends "number" ? number : string;
|
|
60
57
|
};
|
|
61
|
-
declare const initialPageParam:
|
|
62
|
-
declare function getPreviousPageParam<T = never>(first: Page<T>):
|
|
63
|
-
declare function getNextPageParam<T = never>(last: Page<T>):
|
|
58
|
+
declare const initialPageParam: Page['paging'];
|
|
59
|
+
declare function getPreviousPageParam<T = never>(first: Page<T>): Page['paging'] | null;
|
|
60
|
+
declare function getNextPageParam<T = never>(last: Page<T>): Page['paging'] | null;
|
|
64
61
|
|
|
65
62
|
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 };
|
package/dist/response.d.ts
CHANGED
|
@@ -37,8 +37,8 @@ type ParentPageParams = {
|
|
|
37
37
|
type Page<T = never> = {
|
|
38
38
|
data: T[];
|
|
39
39
|
paging: {
|
|
40
|
-
next
|
|
41
|
-
prev
|
|
40
|
+
next?: string;
|
|
41
|
+
prev?: string;
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
44
|
declare function pageParamsSchema(max?: number, defaultLimit?: number): zod_mini.ZodMiniObject<{
|
|
@@ -48,18 +48,15 @@ declare function pageParamsSchema(max?: number, defaultLimit?: number): zod_mini
|
|
|
48
48
|
}, zod_v4_core.$strip>;
|
|
49
49
|
declare const Cursor: {
|
|
50
50
|
of(prev: bigint | number | string | undefined, next: bigint | number | string | undefined): {
|
|
51
|
-
prev: string;
|
|
52
|
-
next: string;
|
|
51
|
+
prev: string | undefined;
|
|
52
|
+
next: string | undefined;
|
|
53
53
|
};
|
|
54
|
-
empty():
|
|
55
|
-
|
|
56
|
-
next: string;
|
|
57
|
-
};
|
|
58
|
-
encode(id: bigint | number | string): string;
|
|
54
|
+
empty(): Page["paging"];
|
|
55
|
+
encode(id: bigint | number | string | undefined): string | undefined;
|
|
59
56
|
decode<T extends "bigint" | "number" | "string" = "bigint">(token: string, type?: T): T extends "bigint" ? bigint : T extends "number" ? number : string;
|
|
60
57
|
};
|
|
61
|
-
declare const initialPageParam:
|
|
62
|
-
declare function getPreviousPageParam<T = never>(first: Page<T>):
|
|
63
|
-
declare function getNextPageParam<T = never>(last: Page<T>):
|
|
58
|
+
declare const initialPageParam: Page['paging'];
|
|
59
|
+
declare function getPreviousPageParam<T = never>(first: Page<T>): Page['paging'] | null;
|
|
60
|
+
declare function getNextPageParam<T = never>(last: Page<T>): Page['paging'] | null;
|
|
64
61
|
|
|
65
62
|
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 };
|
package/dist/response.mjs
CHANGED
|
@@ -13,9 +13,10 @@ var Cursor = {
|
|
|
13
13
|
return { prev: prev ? this.encode(prev) : "", next: next ? this.encode(next) : "" };
|
|
14
14
|
},
|
|
15
15
|
empty() {
|
|
16
|
-
return { prev:
|
|
16
|
+
return { prev: void 0, next: void 0 };
|
|
17
17
|
},
|
|
18
18
|
encode(id) {
|
|
19
|
+
if (!id) return void 0;
|
|
19
20
|
return Buffer.from(id.toString(), "utf-8").toString("base64");
|
|
20
21
|
},
|
|
21
22
|
decode(token, type = "bigint") {
|
|
@@ -27,12 +28,12 @@ var Cursor = {
|
|
|
27
28
|
return value;
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
|
-
var initialPageParam = { next:
|
|
31
|
+
var initialPageParam = { next: void 0, prev: void 0 };
|
|
31
32
|
function getPreviousPageParam(first) {
|
|
32
|
-
return hasText(first.paging.prev) ? {
|
|
33
|
+
return hasText(first.paging.prev) ? { prev: first.paging.prev } : null;
|
|
33
34
|
}
|
|
34
35
|
function getNextPageParam(last) {
|
|
35
|
-
return hasText(last.paging.next) ? { next: last.paging.next
|
|
36
|
+
return hasText(last.paging.next) ? { next: last.paging.next } : null;
|
|
36
37
|
}
|
|
37
38
|
export {
|
|
38
39
|
Cursor,
|
package/dist/response.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/response.ts"],"sourcesContent":["import { hasText } from '@shware/utils';\nimport { _default, coerce, int, maximum, minimum, object, optional, string } from 'zod/mini';\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
|
|
1
|
+
{"version":3,"sources":["../src/response.ts"],"sourcesContent":["import { hasText } from '@shware/utils';\nimport { _default, coerce, int, maximum, minimum, object, optional, string } from 'zod/mini';\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 = 100, defaultLimit = 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(): Page['paging'] {\n return { prev: undefined, next: undefined };\n },\n encode(id: bigint | number | string | undefined): string | undefined {\n if (!id) return undefined;\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: Page['paging'] = { next: undefined, prev: undefined };\n\nexport function getPreviousPageParam<T = never>(first: Page<T>): Page['paging'] | null {\n return hasText(first.paging.prev) ? { prev: first.paging.prev } : null;\n}\n\nexport function getNextPageParam<T = never>(last: Page<T>): Page['paging'] | null {\n return hasText(last.paging.next) ? { next: last.paging.next } : null;\n}\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAS,UAAU,QAAQ,KAAK,SAAS,SAAS,QAAQ,UAAU,cAAc;AAgB3E,SAAS,iBAAiB,MAAM,KAAK,eAAe,IAAI;AAC7D,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,QAAwB;AACtB,WAAO,EAAE,MAAM,QAAW,MAAM,OAAU;AAAA,EAC5C;AAAA,EACA,OAAO,IAA8D;AACnE,QAAI,CAAC,GAAI,QAAO;AAChB,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,mBAAmC,EAAE,MAAM,QAAW,MAAM,OAAU;AAE5E,SAAS,qBAAgC,OAAuC;AACrF,SAAO,QAAQ,MAAM,OAAO,IAAI,IAAI,EAAE,MAAM,MAAM,OAAO,KAAK,IAAI;AACpE;AAEO,SAAS,iBAA4B,MAAsC;AAChF,SAAO,QAAQ,KAAK,OAAO,IAAI,IAAI,EAAE,MAAM,KAAK,OAAO,KAAK,IAAI;AAClE;","names":[]}
|