@metarisc/metarisc-js 0.0.1-alpha.101 → 0.0.1-alpha.103

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.
@@ -14,12 +14,14 @@ export type PaginationData = {
14
14
  total_pages: number;
15
15
  };
16
16
  type PaginationRequestConfig = {
17
+ method?: 'GET' | 'POST';
17
18
  headers?: {
18
19
  [name: string]: string | string[];
19
20
  };
20
21
  params?: {
21
22
  [param: string]: string | string[];
22
23
  };
24
+ data?: Record<string, unknown>;
23
25
  endpoint?: string;
24
26
  };
25
27
  export declare class Collection<T> {
package/lib/collection.js CHANGED
@@ -10,14 +10,24 @@ class Collection {
10
10
  * Fetch current page results.
11
11
  */
12
12
  async fetchPage(page, per_page) {
13
+ const paginationParams = {
14
+ page: page.toString(),
15
+ per_page: per_page.toString()
16
+ };
17
+ if (this.config.method === 'POST') {
18
+ return this.client.request({
19
+ method: 'POST',
20
+ endpoint: 'search/' + this.config.endpoint,
21
+ headers: this.config.headers,
22
+ body: this.config.data,
23
+ params: paginationParams
24
+ });
25
+ }
13
26
  return this.client.request({
14
27
  method: 'GET',
15
28
  endpoint: this.config.endpoint,
16
29
  headers: this.config.headers,
17
- params: { ...this.config.params, ...{
18
- page: page.toString(),
19
- per_page: per_page.toString()
20
- } }
30
+ params: { ...this.config.params, ...paginationParams }
21
31
  });
22
32
  }
23
33
  /**
package/lib/core.js CHANGED
@@ -22,8 +22,10 @@ class Core {
22
22
  }
23
23
  collect(config) {
24
24
  return new collection_1.Collection(this, {
25
+ method: config.method,
25
26
  endpoint: config.endpoint || "/",
26
27
  params: config.params,
28
+ data: config.body,
27
29
  headers: config.headers
28
30
  });
29
31
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@metarisc/metarisc-js",
3
3
  "main": "lib/index.js",
4
4
  "types": "lib/index.d.ts",
5
- "version": "0.0.1-alpha.101",
5
+ "version": "0.0.1-alpha.103",
6
6
  "scripts": {
7
7
  "lint": "eslint . --ext .ts --fix",
8
8
  "compile": "tsc",
package/src/collection.ts CHANGED
@@ -17,9 +17,11 @@ export type PaginationData = {
17
17
  };
18
18
 
19
19
  type PaginationRequestConfig = {
20
- headers ?: {[name: string]: string | string[]};
21
- params ?: {[param: string]: string | string[]};
22
- endpoint ?: string;
20
+ method?: 'GET' | 'POST';
21
+ headers?: {[name: string]: string | string[]};
22
+ params?: {[param: string]: string | string[]};
23
+ data?: Record<string, unknown>;
24
+ endpoint?: string;
23
25
  };
24
26
 
25
27
  export class Collection<T>
@@ -32,16 +34,27 @@ export class Collection<T>
32
34
  /**
33
35
  * Fetch current page results.
34
36
  */
35
- async fetchPage(page : number, per_page : number) : Promise<AxiosResponse<PaginationResults<T>>>
36
- {
37
+ async fetchPage(page: number, per_page: number): Promise<AxiosResponse<PaginationResults<T>>> {
38
+ const paginationParams = {
39
+ page: page.toString(),
40
+ per_page: per_page.toString()
41
+ };
42
+
43
+ if (this.config.method === 'POST') {
44
+ return this.client.request({
45
+ method: 'POST',
46
+ endpoint: 'search/' + this.config.endpoint,
47
+ headers: this.config.headers,
48
+ body: this.config.data,
49
+ params: paginationParams
50
+ });
51
+ }
52
+
37
53
  return this.client.request({
38
54
  method: 'GET',
39
55
  endpoint: this.config.endpoint,
40
56
  headers: this.config.headers,
41
- params: { ...this.config.params, ...{
42
- page: page.toString(),
43
- per_page: per_page.toString()
44
- } }
57
+ params: { ...this.config.params, ...paginationParams }
45
58
  });
46
59
  }
47
60
 
package/src/core.ts CHANGED
@@ -48,8 +48,10 @@ export class Core {
48
48
 
49
49
  collect<T>(config: RequestConfig): Collection<T> {
50
50
  return new Collection<T>(this, {
51
+ method: config.method as 'GET' | 'POST',
51
52
  endpoint: config.endpoint || "/",
52
53
  params: config.params,
54
+ data: config.body,
53
55
  headers: config.headers
54
56
  });
55
57
  }