@gobing-ai/ts-utils 0.4.6 → 0.4.7
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/cursor.d.ts.map +1 -1
- package/dist/cursor.js +14 -4
- package/package.json +1 -1
- package/src/cursor.ts +14 -4
package/dist/cursor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../src/cursor.ts"],"names":[],"mappings":"AAEA,wDAAwD;AACxD,MAAM,WAAW,UAAU;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAQD,yDAAyD;AACzD,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../src/cursor.ts"],"names":[],"mappings":"AAEA,wDAAwD;AACxD,MAAM,WAAW,UAAU;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAQD,yDAAyD;AACzD,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,CAgB/F;AAED,mGAAmG;AACnG,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAyB9E;AAED,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAEvD;AAED,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,4EAA4E;AAC5E,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAEnG;AAED,oIAAoI;AACpI,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAKhE;AAED,yJAAyJ;AACzJ,wBAAgB,eAAe,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAC/E,KAAK,EAAE,CAAC,EAAE,EACV,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,GACjB;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAc1D"}
|
package/dist/cursor.js
CHANGED
|
@@ -9,11 +9,15 @@ export function createCursor(id, createdAt, offset) {
|
|
|
9
9
|
const cursor = { id };
|
|
10
10
|
if (createdAt !== undefined) {
|
|
11
11
|
const ms = toMs(createdAt);
|
|
12
|
-
if (ms
|
|
13
|
-
cursor
|
|
12
|
+
if (ms === null || !Number.isFinite(ms)) {
|
|
13
|
+
throw new Error('Invalid cursor: createdAt must be a finite timestamp');
|
|
14
14
|
}
|
|
15
|
+
cursor.createdAt = ms;
|
|
15
16
|
}
|
|
16
17
|
if (offset !== undefined) {
|
|
18
|
+
if (!Number.isInteger(offset) || offset < 0) {
|
|
19
|
+
throw new Error('Invalid cursor: offset must be a non-negative integer');
|
|
20
|
+
}
|
|
17
21
|
cursor.offset = offset;
|
|
18
22
|
}
|
|
19
23
|
return cursor;
|
|
@@ -28,10 +32,16 @@ export function parseCursor(data) {
|
|
|
28
32
|
throw new Error('Invalid cursor: missing or invalid id');
|
|
29
33
|
}
|
|
30
34
|
const result = { id: parsed.id };
|
|
31
|
-
if (
|
|
35
|
+
if (parsed.createdAt !== undefined) {
|
|
36
|
+
if (typeof parsed.createdAt !== 'number' || !Number.isFinite(parsed.createdAt)) {
|
|
37
|
+
throw new Error('Invalid cursor: createdAt must be a finite timestamp');
|
|
38
|
+
}
|
|
32
39
|
result.createdAt = parsed.createdAt;
|
|
33
40
|
}
|
|
34
|
-
if (
|
|
41
|
+
if (parsed.offset !== undefined) {
|
|
42
|
+
if (typeof parsed.offset !== 'number' || !Number.isInteger(parsed.offset) || parsed.offset < 0) {
|
|
43
|
+
throw new Error('Invalid cursor: offset must be a non-negative integer');
|
|
44
|
+
}
|
|
35
45
|
result.offset = parsed.offset;
|
|
36
46
|
}
|
|
37
47
|
return result;
|
package/package.json
CHANGED
package/src/cursor.ts
CHANGED
|
@@ -18,11 +18,15 @@ export function createCursor(id: string, createdAt?: Date | number, offset?: num
|
|
|
18
18
|
const cursor: CursorData = { id };
|
|
19
19
|
if (createdAt !== undefined) {
|
|
20
20
|
const ms = toMs(createdAt);
|
|
21
|
-
if (ms
|
|
22
|
-
cursor
|
|
21
|
+
if (ms === null || !Number.isFinite(ms)) {
|
|
22
|
+
throw new Error('Invalid cursor: createdAt must be a finite timestamp');
|
|
23
23
|
}
|
|
24
|
+
cursor.createdAt = ms;
|
|
24
25
|
}
|
|
25
26
|
if (offset !== undefined) {
|
|
27
|
+
if (!Number.isInteger(offset) || offset < 0) {
|
|
28
|
+
throw new Error('Invalid cursor: offset must be a non-negative integer');
|
|
29
|
+
}
|
|
26
30
|
cursor.offset = offset;
|
|
27
31
|
}
|
|
28
32
|
return cursor;
|
|
@@ -41,10 +45,16 @@ export function parseCursor(data: string | Record<string, unknown>): CursorData
|
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
const result: CursorData = { id: parsed.id };
|
|
44
|
-
if (
|
|
48
|
+
if (parsed.createdAt !== undefined) {
|
|
49
|
+
if (typeof parsed.createdAt !== 'number' || !Number.isFinite(parsed.createdAt)) {
|
|
50
|
+
throw new Error('Invalid cursor: createdAt must be a finite timestamp');
|
|
51
|
+
}
|
|
45
52
|
result.createdAt = parsed.createdAt;
|
|
46
53
|
}
|
|
47
|
-
if (
|
|
54
|
+
if (parsed.offset !== undefined) {
|
|
55
|
+
if (typeof parsed.offset !== 'number' || !Number.isInteger(parsed.offset) || parsed.offset < 0) {
|
|
56
|
+
throw new Error('Invalid cursor: offset must be a non-negative integer');
|
|
57
|
+
}
|
|
48
58
|
result.offset = parsed.offset;
|
|
49
59
|
}
|
|
50
60
|
return result;
|