@shware/http 2.4.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/response.cjs +4 -1
- package/dist/response.cjs.map +1 -1
- package/dist/response.d.cts +1 -4
- package/dist/response.d.ts +1 -4
- package/dist/response.mjs +4 -1
- package/dist/response.mjs.map +1 -1
- package/package.json +1 -1
package/dist/response.cjs
CHANGED
|
@@ -38,7 +38,10 @@ function pageParamsSchema(max = 100, defaultLimit = 20) {
|
|
|
38
38
|
}
|
|
39
39
|
var Cursor = {
|
|
40
40
|
of(prev, next) {
|
|
41
|
-
return {
|
|
41
|
+
return {
|
|
42
|
+
prev: prev ? this.encode(prev) : void 0,
|
|
43
|
+
next: next ? this.encode(next) : void 0
|
|
44
|
+
};
|
|
42
45
|
},
|
|
43
46
|
empty() {
|
|
44
47
|
return { prev: void 0, next: void 0 };
|
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?: 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
|
|
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(\n prev: bigint | number | string | undefined,\n next: bigint | number | string | undefined\n ): Page['paging'] {\n return {\n prev: prev ? this.encode(prev) : undefined,\n next: next ? this.encode(next) : undefined,\n };\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,GACE,MACA,MACgB;AAChB,WAAO;AAAA,MACL,MAAM,OAAO,KAAK,OAAO,IAAI,IAAI;AAAA,MACjC,MAAM,OAAO,KAAK,OAAO,IAAI,IAAI;AAAA,IACnC;AAAA,EACF;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
|
@@ -47,10 +47,7 @@ declare function pageParamsSchema(max?: number, defaultLimit?: number): zod_mini
|
|
|
47
47
|
next: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
48
48
|
}, zod_v4_core.$strip>;
|
|
49
49
|
declare const Cursor: {
|
|
50
|
-
of(prev: bigint | number | string | undefined, next: bigint | number | string | undefined):
|
|
51
|
-
prev: string | undefined;
|
|
52
|
-
next: string | undefined;
|
|
53
|
-
};
|
|
50
|
+
of(prev: bigint | number | string | undefined, next: bigint | number | string | undefined): Page["paging"];
|
|
54
51
|
empty(): Page["paging"];
|
|
55
52
|
encode(id: bigint | number | string | undefined): string | undefined;
|
|
56
53
|
decode<T extends "bigint" | "number" | "string" = "bigint">(token: string, type?: T): T extends "bigint" ? bigint : T extends "number" ? number : string;
|
package/dist/response.d.ts
CHANGED
|
@@ -47,10 +47,7 @@ declare function pageParamsSchema(max?: number, defaultLimit?: number): zod_mini
|
|
|
47
47
|
next: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
48
48
|
}, zod_v4_core.$strip>;
|
|
49
49
|
declare const Cursor: {
|
|
50
|
-
of(prev: bigint | number | string | undefined, next: bigint | number | string | undefined):
|
|
51
|
-
prev: string | undefined;
|
|
52
|
-
next: string | undefined;
|
|
53
|
-
};
|
|
50
|
+
of(prev: bigint | number | string | undefined, next: bigint | number | string | undefined): Page["paging"];
|
|
54
51
|
empty(): Page["paging"];
|
|
55
52
|
encode(id: bigint | number | string | undefined): string | undefined;
|
|
56
53
|
decode<T extends "bigint" | "number" | "string" = "bigint">(token: string, type?: T): T extends "bigint" ? bigint : T extends "number" ? number : string;
|
package/dist/response.mjs
CHANGED
|
@@ -10,7 +10,10 @@ function pageParamsSchema(max = 100, defaultLimit = 20) {
|
|
|
10
10
|
}
|
|
11
11
|
var Cursor = {
|
|
12
12
|
of(prev, next) {
|
|
13
|
-
return {
|
|
13
|
+
return {
|
|
14
|
+
prev: prev ? this.encode(prev) : void 0,
|
|
15
|
+
next: next ? this.encode(next) : void 0
|
|
16
|
+
};
|
|
14
17
|
},
|
|
15
18
|
empty() {
|
|
16
19
|
return { prev: void 0, next: void 0 };
|
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?: 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
|
|
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(\n prev: bigint | number | string | undefined,\n next: bigint | number | string | undefined\n ): Page['paging'] {\n return {\n prev: prev ? this.encode(prev) : undefined,\n next: next ? this.encode(next) : undefined,\n };\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,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