@utiliread/http 1.26.0 → 1.27.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/cursor.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ // Needed for old module resolution which does not use the exports section in package.json
2
+ export * from "./dist/plugins/cursor";
@@ -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,13 @@
1
+ import { TypeOrMapper } from "@utiliread/http";
2
+ export interface ICursorPage<T> {
3
+ items: T[];
4
+ nextCursor: string | null;
5
+ hasMore: boolean;
6
+ }
7
+ declare const _default: {};
8
+ export default _default;
9
+ declare module "@utiliread/http" {
10
+ interface HttpBuilder {
11
+ expectCursorPage<T>(typeOrMapper: TypeOrMapper<T>): HttpBuilderOfT<ICursorPage<T>>;
12
+ }
13
+ }
@@ -0,0 +1,27 @@
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
+ };
21
+ });
22
+ return promise;
23
+ });
24
+ };
25
+
26
+ module.exports = index;
27
+ //# 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":";;;;;AAaA;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;aACnB;AACH,QAAA,CAAC,CAAC;AACJ,QAAA,OAAO,OAAO;AAChB,IAAA,CAAC,CAAC;AACJ,CAAC;;;;"}
@@ -0,0 +1,25 @@
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
+ };
19
+ });
20
+ return promise;
21
+ });
22
+ };
23
+
24
+ export { index as default };
25
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/plugins/cursor/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAaA;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;aACnB;AACH,QAAA,CAAC,CAAC;AACJ,QAAA,OAAO,OAAO;AAChB,IAAA,CAAC,CAAC;AACJ,CAAC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utiliread/http",
3
- "version": "1.26.0",
3
+ "version": "1.27.0",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -25,19 +25,26 @@
25
25
  "types": "./dist/plugins/msgpack/index.d.ts",
26
26
  "import": "./dist/plugins/msgpack/index.mjs",
27
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"
28
33
  }
29
34
  },
30
35
  "sideEffects": [
31
36
  "./dist/plugins/json/index.{mjs,js}",
32
37
  "./dist/plugins/jsonpatch/index.{mjs,js}",
33
- "./dist/plugins/msgpack/index.{mjs,js}"
38
+ "./dist/plugins/msgpack/index.{mjs,js}",
39
+ "./dist/plugins/cursor/index.{mjs,js}"
34
40
  ],
35
41
  "scripts": {
36
- "build": "rollup -c && npm run build:json && npm run build:jsonpatch && npm run build:msgpack",
42
+ "build": "rollup -c && npm run build:json && npm run build:jsonpatch && npm run build:msgpack && npm run build:cursor",
37
43
  "build:core": "rollup -c",
38
44
  "build:json": "rollup -c json.rollup.config.mjs",
39
45
  "build:jsonpatch": "rollup -c jsonpatch.rollup.config.mjs",
40
46
  "build:msgpack": "rollup -c msgpack.rollup.config.mjs",
47
+ "build:cursor": "rollup -c cursor.rollup.config.mjs",
41
48
  "prettier": "prettier --write package.json tsconfig.json *.mjs src/**/*.ts",
42
49
  "test": "npm run build:core && web-test-runner",
43
50
  "clean": "rimraf dist"
@@ -0,0 +1,45 @@
1
+ import {
2
+ HttpBuilder,
3
+ TypeOrMapper,
4
+ getMapper,
5
+ } from "@utiliread/http";
6
+ import { deserialize } from "@utiliread/json";
7
+
8
+ export interface ICursorPage<T> {
9
+ items: T[];
10
+ nextCursor: string | null;
11
+ hasMore: boolean;
12
+ }
13
+
14
+ // Force declarations to be module augmentations instead of ambient module declarations
15
+ // https://www.typescriptlang.org/docs/handbook/modules/reference.html#ambient-modules
16
+ export default {};
17
+
18
+ // https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
19
+ declare module "@utiliread/http" {
20
+ interface HttpBuilder {
21
+ expectCursorPage<T>(
22
+ typeOrMapper: TypeOrMapper<T>,
23
+ ): HttpBuilderOfT<ICursorPage<T>>;
24
+ }
25
+ }
26
+
27
+ HttpBuilder.prototype.expectCursorPage = function <T>(
28
+ this: HttpBuilder,
29
+ typeOrMapper: TypeOrMapper<T>,
30
+ ) {
31
+ this.message.headers.set("Accept", "application/json");
32
+ return this.useHandler((response) => {
33
+ const promise = response.rawResponse
34
+ .json()
35
+ .then((x: ICursorPage<any>): ICursorPage<T> => {
36
+ const itemFactory = getMapper(deserialize, typeOrMapper);
37
+ return {
38
+ items: x.items.map(itemFactory),
39
+ nextCursor: x.nextCursor,
40
+ hasMore: x.hasMore,
41
+ };
42
+ });
43
+ return promise;
44
+ });
45
+ };