@utiliread/http 1.26.0 → 1.27.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/cursor.d.ts +2 -0
- package/cursor.rollup.config.mjs +35 -0
- package/dist/plugins/cursor/index.d.ts +14 -0
- package/dist/plugins/cursor/index.js +28 -0
- package/dist/plugins/cursor/index.js.map +1 -0
- package/dist/plugins/cursor/index.mjs +26 -0
- package/dist/plugins/cursor/index.mjs.map +1 -0
- package/package.json +91 -84
- package/src/errors/http-error.ts +52 -52
- package/src/http-builder.ts +318 -318
- package/src/plugins/cursor/index.ts +47 -0
- package/src/query-string.spec.ts +96 -96
- package/src/query-string.ts +75 -75
package/cursor.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import typescript from "@rollup/plugin-typescript";
|
|
2
|
+
|
|
3
|
+
/** @type {import('rollup').RollupOptions} */
|
|
4
|
+
const options = {
|
|
5
|
+
input: "src/plugins/cursor/index.ts",
|
|
6
|
+
external: [
|
|
7
|
+
"@utiliread/http",
|
|
8
|
+
"@utiliread/json",
|
|
9
|
+
],
|
|
10
|
+
treeshake: false,
|
|
11
|
+
plugins: [typescript({ declaration: false })],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default [
|
|
15
|
+
Object.assign(
|
|
16
|
+
{
|
|
17
|
+
output: {
|
|
18
|
+
file: "dist/plugins/cursor/index.mjs",
|
|
19
|
+
sourcemap: true,
|
|
20
|
+
format: "es",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
options,
|
|
24
|
+
),
|
|
25
|
+
Object.assign(
|
|
26
|
+
{
|
|
27
|
+
output: {
|
|
28
|
+
file: "dist/plugins/cursor/index.js",
|
|
29
|
+
sourcemap: true,
|
|
30
|
+
format: "cjs",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
options,
|
|
34
|
+
),
|
|
35
|
+
];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TypeOrMapper } from "@utiliread/http";
|
|
2
|
+
export interface ICursorPage<T> {
|
|
3
|
+
items: T[];
|
|
4
|
+
nextCursor: string | null;
|
|
5
|
+
hasMore: boolean;
|
|
6
|
+
totalCount?: number;
|
|
7
|
+
}
|
|
8
|
+
declare const _default: {};
|
|
9
|
+
export default _default;
|
|
10
|
+
declare module "@utiliread/http" {
|
|
11
|
+
interface HttpBuilder {
|
|
12
|
+
expectCursorPage<T>(typeOrMapper: TypeOrMapper<T>): HttpBuilderOfT<ICursorPage<T>>;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var http = require('@utiliread/http');
|
|
4
|
+
var json = require('@utiliread/json');
|
|
5
|
+
|
|
6
|
+
// Force declarations to be module augmentations instead of ambient module declarations
|
|
7
|
+
// https://www.typescriptlang.org/docs/handbook/modules/reference.html#ambient-modules
|
|
8
|
+
var index = {};
|
|
9
|
+
http.HttpBuilder.prototype.expectCursorPage = function (typeOrMapper) {
|
|
10
|
+
this.message.headers.set("Accept", "application/json");
|
|
11
|
+
return this.useHandler((response) => {
|
|
12
|
+
const promise = response.rawResponse
|
|
13
|
+
.json()
|
|
14
|
+
.then((x) => {
|
|
15
|
+
const itemFactory = http.getMapper(json.deserialize, typeOrMapper);
|
|
16
|
+
return {
|
|
17
|
+
items: x.items.map(itemFactory),
|
|
18
|
+
nextCursor: x.nextCursor,
|
|
19
|
+
hasMore: x.hasMore,
|
|
20
|
+
totalCount: x.totalCount,
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
return promise;
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
module.exports = index;
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/plugins/cursor/index.ts"],"sourcesContent":[null],"names":["HttpBuilder","getMapper","deserialize"],"mappings":";;;;;AAcA;AACA;AACA,YAAe,EAAE;AAWjBA,gBAAW,CAAC,SAAS,CAAC,gBAAgB,GAAG,UAEvC,YAA6B,EAAA;IAE7B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,kBAAkB,CAAC;AACtD,IAAA,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,KAAI;AAClC,QAAA,MAAM,OAAO,GAAG,QAAQ,CAAC;AACtB,aAAA,IAAI;AACJ,aAAA,IAAI,CAAC,CAAC,CAAmB,KAAoB;YAC5C,MAAM,WAAW,GAAGC,cAAS,CAACC,gBAAW,EAAE,YAAY,CAAC;YACxD,OAAO;gBACL,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC;gBAC/B,UAAU,EAAE,CAAC,CAAC,UAAU;gBACxB,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,UAAU,EAAE,CAAC,CAAC,UAAU;aACzB;AACH,QAAA,CAAC,CAAC;AACJ,QAAA,OAAO,OAAO;AAChB,IAAA,CAAC,CAAC;AACJ,CAAC;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { HttpBuilder, getMapper } from '@utiliread/http';
|
|
2
|
+
import { deserialize } from '@utiliread/json';
|
|
3
|
+
|
|
4
|
+
// Force declarations to be module augmentations instead of ambient module declarations
|
|
5
|
+
// https://www.typescriptlang.org/docs/handbook/modules/reference.html#ambient-modules
|
|
6
|
+
var index = {};
|
|
7
|
+
HttpBuilder.prototype.expectCursorPage = function (typeOrMapper) {
|
|
8
|
+
this.message.headers.set("Accept", "application/json");
|
|
9
|
+
return this.useHandler((response) => {
|
|
10
|
+
const promise = response.rawResponse
|
|
11
|
+
.json()
|
|
12
|
+
.then((x) => {
|
|
13
|
+
const itemFactory = getMapper(deserialize, typeOrMapper);
|
|
14
|
+
return {
|
|
15
|
+
items: x.items.map(itemFactory),
|
|
16
|
+
nextCursor: x.nextCursor,
|
|
17
|
+
hasMore: x.hasMore,
|
|
18
|
+
totalCount: x.totalCount,
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
return promise;
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { index as default };
|
|
26
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/plugins/cursor/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAcA;AACA;AACA,YAAe,EAAE;AAWjB,WAAW,CAAC,SAAS,CAAC,gBAAgB,GAAG,UAEvC,YAA6B,EAAA;IAE7B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,kBAAkB,CAAC;AACtD,IAAA,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,KAAI;AAClC,QAAA,MAAM,OAAO,GAAG,QAAQ,CAAC;AACtB,aAAA,IAAI;AACJ,aAAA,IAAI,CAAC,CAAC,CAAmB,KAAoB;YAC5C,MAAM,WAAW,GAAG,SAAS,CAAC,WAAW,EAAE,YAAY,CAAC;YACxD,OAAO;gBACL,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC;gBAC/B,UAAU,EAAE,CAAC,CAAC,UAAU;gBACxB,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,UAAU,EAAE,CAAC,CAAC,UAAU;aACzB;AACH,QAAA,CAAC,CAAC;AACJ,QAAA,OAAO,OAAO;AAChB,IAAA,CAAC,CAAC;AACJ,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,84 +1,91 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@utiliread/http",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"source": "src/index.ts",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.mjs",
|
|
12
|
-
"require": "./dist/index.js"
|
|
13
|
-
},
|
|
14
|
-
"./json": {
|
|
15
|
-
"types": "./dist/plugins/json/index.d.ts",
|
|
16
|
-
"import": "./dist/plugins/json/index.mjs",
|
|
17
|
-
"require": "./dist/plugins/json/index.js"
|
|
18
|
-
},
|
|
19
|
-
"./jsonpatch": {
|
|
20
|
-
"types": "./dist/plugins/jsonpatch/index.d.ts",
|
|
21
|
-
"import": "./dist/plugins/jsonpatch/index.mjs",
|
|
22
|
-
"require": "./dist/plugins/jsonpatch/index.js"
|
|
23
|
-
},
|
|
24
|
-
"./msgpack": {
|
|
25
|
-
"types": "./dist/plugins/msgpack/index.d.ts",
|
|
26
|
-
"import": "./dist/plugins/msgpack/index.mjs",
|
|
27
|
-
"require": "./dist/plugins/msgpack/index.js"
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"@
|
|
57
|
-
"@
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"@utiliread/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@utiliread/http",
|
|
3
|
+
"version": "1.27.1",
|
|
4
|
+
"source": "src/index.ts",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./json": {
|
|
15
|
+
"types": "./dist/plugins/json/index.d.ts",
|
|
16
|
+
"import": "./dist/plugins/json/index.mjs",
|
|
17
|
+
"require": "./dist/plugins/json/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./jsonpatch": {
|
|
20
|
+
"types": "./dist/plugins/jsonpatch/index.d.ts",
|
|
21
|
+
"import": "./dist/plugins/jsonpatch/index.mjs",
|
|
22
|
+
"require": "./dist/plugins/jsonpatch/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./msgpack": {
|
|
25
|
+
"types": "./dist/plugins/msgpack/index.d.ts",
|
|
26
|
+
"import": "./dist/plugins/msgpack/index.mjs",
|
|
27
|
+
"require": "./dist/plugins/msgpack/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./cursor": {
|
|
30
|
+
"types": "./dist/plugins/cursor/index.d.ts",
|
|
31
|
+
"import": "./dist/plugins/cursor/index.mjs",
|
|
32
|
+
"require": "./dist/plugins/cursor/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"sideEffects": [
|
|
36
|
+
"./dist/plugins/json/index.{mjs,js}",
|
|
37
|
+
"./dist/plugins/jsonpatch/index.{mjs,js}",
|
|
38
|
+
"./dist/plugins/msgpack/index.{mjs,js}",
|
|
39
|
+
"./dist/plugins/cursor/index.{mjs,js}"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "rollup -c && npm run build:json && npm run build:jsonpatch && npm run build:msgpack && npm run build:cursor",
|
|
43
|
+
"build:core": "rollup -c",
|
|
44
|
+
"build:json": "rollup -c json.rollup.config.mjs",
|
|
45
|
+
"build:jsonpatch": "rollup -c jsonpatch.rollup.config.mjs",
|
|
46
|
+
"build:msgpack": "rollup -c msgpack.rollup.config.mjs",
|
|
47
|
+
"build:cursor": "rollup -c cursor.rollup.config.mjs",
|
|
48
|
+
"prettier": "prettier --write package.json tsconfig.json *.mjs src/**/*.ts",
|
|
49
|
+
"test": "npm run build:core && web-test-runner",
|
|
50
|
+
"clean": "rimraf dist"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@rollup/plugin-typescript": "^12.1.1",
|
|
57
|
+
"@types/chai": "^5.0.1",
|
|
58
|
+
"@types/luxon": "^3.0.1",
|
|
59
|
+
"@types/mocha": "^10.0.0",
|
|
60
|
+
"@utiliread/json": "^1.3.0",
|
|
61
|
+
"@utiliread/jsonpatch": "^1.1.0",
|
|
62
|
+
"@utiliread/msgpack": "^1.1.0",
|
|
63
|
+
"@web/dev-server-esbuild": "^1.0.1",
|
|
64
|
+
"@web/test-runner": "^0.20.2",
|
|
65
|
+
"chai": "^6.2.0",
|
|
66
|
+
"luxon": "^3.0.4",
|
|
67
|
+
"mocha": "^11.5.0",
|
|
68
|
+
"prettier": "^3.2.4",
|
|
69
|
+
"rimraf": "^6.0.1",
|
|
70
|
+
"rollup": "^4.21.3",
|
|
71
|
+
"tslib": "^2.7.0",
|
|
72
|
+
"typescript": "^6.0.2"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@utiliread/json": "^1.3.0",
|
|
76
|
+
"@utiliread/jsonpatch": "^1.1.0",
|
|
77
|
+
"@utiliread/msgpack": "^1.1.0",
|
|
78
|
+
"luxon": "^2.1.0 || ^3.0.0"
|
|
79
|
+
},
|
|
80
|
+
"peerDependenciesMeta": {
|
|
81
|
+
"@utiliread/json": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"@utiliread/jsonpatch": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"@utiliread/msgpack": {
|
|
88
|
+
"optional": true
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
package/src/errors/http-error.ts
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { HttpResponse } from "../http-response";
|
|
2
|
-
import { ProblemDetails } from "../problem-details";
|
|
3
|
-
|
|
4
|
-
export class HttpError extends Error {
|
|
5
|
-
private jsonPromise?: Promise<any>;
|
|
6
|
-
|
|
7
|
-
readonly name: "HttpError" = "HttpError";
|
|
8
|
-
|
|
9
|
-
get hasDetails() {
|
|
10
|
-
const contentType = this.response?.rawResponse?.headers.get("Content-Type");
|
|
11
|
-
return contentType?.includes("application/problem+json");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
constructor(
|
|
15
|
-
public statusCode: number,
|
|
16
|
-
private response: HttpResponse | undefined = undefined,
|
|
17
|
-
) {
|
|
18
|
-
super(`The response was not successful: ${statusCode}`);
|
|
19
|
-
|
|
20
|
-
// Set the prototype explicitly to allow for "... instanceof HttpError",
|
|
21
|
-
// see https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
22
|
-
Object.setPrototypeOf(this, HttpError.prototype);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
details<TDetails = ProblemDetails>() {
|
|
26
|
-
const rawResponse = this.response?.rawResponse;
|
|
27
|
-
|
|
28
|
-
if (rawResponse && this.hasDetails) {
|
|
29
|
-
this.jsonPromise ??= rawResponse.json();
|
|
30
|
-
return this.jsonPromise.then((details) => <TDetails>details);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return Promise.reject(
|
|
34
|
-
new Error("There are no problem details in the response"),
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
json() {
|
|
39
|
-
const rawResponse = this.response?.rawResponse;
|
|
40
|
-
|
|
41
|
-
if (rawResponse) {
|
|
42
|
-
this.jsonPromise ??= rawResponse.json();
|
|
43
|
-
return this.jsonPromise;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return Promise.reject(new Error("There is no response"));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function isHttpError(error: unknown): error is HttpError {
|
|
51
|
-
return error instanceof Error && error.name === "HttpError";
|
|
52
|
-
}
|
|
1
|
+
import { HttpResponse } from "../http-response";
|
|
2
|
+
import { ProblemDetails } from "../problem-details";
|
|
3
|
+
|
|
4
|
+
export class HttpError extends Error {
|
|
5
|
+
private jsonPromise?: Promise<any>;
|
|
6
|
+
|
|
7
|
+
readonly name: "HttpError" = "HttpError";
|
|
8
|
+
|
|
9
|
+
get hasDetails() {
|
|
10
|
+
const contentType = this.response?.rawResponse?.headers.get("Content-Type");
|
|
11
|
+
return contentType?.includes("application/problem+json");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
public statusCode: number,
|
|
16
|
+
private response: HttpResponse | undefined = undefined,
|
|
17
|
+
) {
|
|
18
|
+
super(`The response was not successful: ${statusCode}`);
|
|
19
|
+
|
|
20
|
+
// Set the prototype explicitly to allow for "... instanceof HttpError",
|
|
21
|
+
// see https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
22
|
+
Object.setPrototypeOf(this, HttpError.prototype);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
details<TDetails = ProblemDetails>() {
|
|
26
|
+
const rawResponse = this.response?.rawResponse;
|
|
27
|
+
|
|
28
|
+
if (rawResponse && this.hasDetails) {
|
|
29
|
+
this.jsonPromise ??= rawResponse.json();
|
|
30
|
+
return this.jsonPromise.then((details) => <TDetails>details);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return Promise.reject(
|
|
34
|
+
new Error("There are no problem details in the response"),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
json() {
|
|
39
|
+
const rawResponse = this.response?.rawResponse;
|
|
40
|
+
|
|
41
|
+
if (rawResponse) {
|
|
42
|
+
this.jsonPromise ??= rawResponse.json();
|
|
43
|
+
return this.jsonPromise;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return Promise.reject(new Error("There is no response"));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function isHttpError(error: unknown): error is HttpError {
|
|
51
|
+
return error instanceof Error && error.name === "HttpError";
|
|
52
|
+
}
|