integreat 0.7.37 → 0.7.38
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/index.d.ts +45 -40
- package/lib/integreat.js +1 -1
- package/lib/service/mapFromService.js +44 -22
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export as namespace integreat
|
|
2
2
|
export = integreat
|
|
3
3
|
|
|
4
|
-
declare function integreat
|
|
4
|
+
declare function integreat(
|
|
5
5
|
defs: integreat.Definitions,
|
|
6
6
|
resources: integreat.Resources,
|
|
7
7
|
middlewares?: integreat.Middleware[]
|
|
@@ -20,58 +20,63 @@ declare namespace integreat {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export interface Ident {
|
|
23
|
-
id?: string
|
|
23
|
+
id?: string
|
|
24
24
|
root?: boolean
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export interface Meta {
|
|
28
|
-
queue?: boolean
|
|
29
|
-
ident?: Ident
|
|
28
|
+
queue?: boolean
|
|
29
|
+
ident?: Ident
|
|
30
30
|
[key: string]: unknown
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export interface Action<P = Payload> {
|
|
34
|
-
type: string
|
|
35
|
-
payload: P
|
|
34
|
+
type: string
|
|
35
|
+
payload: P
|
|
36
36
|
meta?: Meta
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export type ActionHandlerResources = {
|
|
40
40
|
dispatch: Dispatch
|
|
41
|
+
setProgress: (progress: number) => void
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
export interface Instance {
|
|
44
|
-
version: string
|
|
45
|
-
schemas: object
|
|
46
|
-
services: object
|
|
47
|
-
identType: string
|
|
45
|
+
version: string
|
|
46
|
+
schemas: object
|
|
47
|
+
services: object
|
|
48
|
+
identType: string
|
|
48
49
|
|
|
49
|
-
dispatch: Dispatch
|
|
50
|
-
on: (
|
|
50
|
+
dispatch: Dispatch
|
|
51
|
+
on: (
|
|
52
|
+
eventName: string,
|
|
53
|
+
serviceId: string,
|
|
54
|
+
listener: (request: Request, response: Response) => void
|
|
55
|
+
) => void
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
export interface IdentDefinitions {
|
|
54
59
|
type: string
|
|
55
60
|
props?: {
|
|
56
|
-
id?: string
|
|
57
|
-
roles?: string
|
|
61
|
+
id?: string
|
|
62
|
+
roles?: string
|
|
58
63
|
tokens?: string
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
export interface Definitions {
|
|
63
|
-
schemas: object[]
|
|
64
|
-
services: object[]
|
|
65
|
-
mappings: object[]
|
|
66
|
-
auths?: object[]
|
|
68
|
+
schemas: object[]
|
|
69
|
+
services: object[]
|
|
70
|
+
mappings: object[]
|
|
71
|
+
auths?: object[]
|
|
67
72
|
ident?: IdentDefinitions
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
export interface Resources {
|
|
71
|
-
adapters: any
|
|
72
|
-
authenticators?: any
|
|
73
|
-
transformers?: any
|
|
74
|
-
filters?: any
|
|
76
|
+
adapters: any
|
|
77
|
+
authenticators?: any
|
|
78
|
+
transformers?: any
|
|
79
|
+
filters?: any
|
|
75
80
|
actions?: any
|
|
76
81
|
}
|
|
77
82
|
|
|
@@ -80,9 +85,9 @@ declare namespace integreat {
|
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
export interface Queue {
|
|
83
|
-
queue: object
|
|
84
|
-
setDispatch: (dispatch: Dispatch) => Promise<void
|
|
85
|
-
middleware: Middleware
|
|
88
|
+
queue: object
|
|
89
|
+
setDispatch: (dispatch: Dispatch) => Promise<void>
|
|
90
|
+
middleware: Middleware
|
|
86
91
|
schedule: (schedule: object) => Promise<Response>
|
|
87
92
|
}
|
|
88
93
|
|
|
@@ -97,10 +102,10 @@ declare namespace integreat {
|
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
type Relationship = {
|
|
100
|
-
id: string | null | undefined
|
|
101
|
-
type: string
|
|
102
|
-
attributes?: Attributes
|
|
103
|
-
relationships?: Relationships
|
|
105
|
+
id: string | null | undefined
|
|
106
|
+
type: string
|
|
107
|
+
attributes?: Attributes
|
|
108
|
+
relationships?: Relationships
|
|
104
109
|
meta?: object
|
|
105
110
|
}
|
|
106
111
|
|
|
@@ -109,30 +114,30 @@ declare namespace integreat {
|
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
export type Data = {
|
|
112
|
-
id: string | null | undefined
|
|
113
|
-
type: string
|
|
114
|
-
attributes: Attributes
|
|
117
|
+
id: string | null | undefined
|
|
118
|
+
type: string
|
|
119
|
+
attributes: Attributes
|
|
115
120
|
relationships: Relationships
|
|
116
121
|
}
|
|
117
122
|
|
|
118
123
|
interface Request<T = Data[] | Data | null> {
|
|
119
|
-
action: string
|
|
124
|
+
action: string
|
|
120
125
|
params?: {
|
|
121
126
|
[param: string]: any
|
|
122
|
-
}
|
|
127
|
+
}
|
|
123
128
|
endpoint?: {
|
|
124
129
|
[option: string]: any
|
|
125
130
|
}
|
|
126
|
-
data: T
|
|
127
|
-
auth?: object | boolean
|
|
131
|
+
data: T
|
|
132
|
+
auth?: object | boolean
|
|
128
133
|
access?: { ident: Ident }
|
|
129
134
|
}
|
|
130
135
|
|
|
131
136
|
interface Response<T = Data[]> {
|
|
132
|
-
status: string
|
|
133
|
-
data?: T
|
|
134
|
-
error?: string
|
|
135
|
-
responses?: Response[]
|
|
137
|
+
status: string
|
|
138
|
+
data?: T
|
|
139
|
+
error?: string
|
|
140
|
+
responses?: Response[]
|
|
136
141
|
access?: object
|
|
137
142
|
}
|
|
138
143
|
}
|
package/lib/integreat.js
CHANGED
|
@@ -5,13 +5,19 @@ const mergeWithParams = (response, params) => ({
|
|
|
5
5
|
...response,
|
|
6
6
|
params: {
|
|
7
7
|
...params,
|
|
8
|
-
...response.params
|
|
9
|
-
}
|
|
8
|
+
...response.params,
|
|
9
|
+
},
|
|
10
10
|
})
|
|
11
11
|
|
|
12
12
|
const mapWithEndpoint = (responseMapper, response, params, actionType) => {
|
|
13
|
-
if (
|
|
14
|
-
|
|
13
|
+
if (
|
|
14
|
+
responseMapper ||
|
|
15
|
+
actionType.startsWith('GET') ||
|
|
16
|
+
actionType === 'REQUEST'
|
|
17
|
+
) {
|
|
18
|
+
return responseMapper
|
|
19
|
+
? responseMapper(mergeWithParams(response, params)) || {}
|
|
20
|
+
: response
|
|
15
21
|
} else {
|
|
16
22
|
return {}
|
|
17
23
|
}
|
|
@@ -25,8 +31,14 @@ const mapWithEndpoint = (responseMapper, response, params, actionType) => {
|
|
|
25
31
|
* @param {Object} options - mappings, params, onlyMappedValues, and endpoint
|
|
26
32
|
* @returns {Object[]} Array of mapped items
|
|
27
33
|
*/
|
|
28
|
-
function mapFromService
|
|
29
|
-
return ({
|
|
34
|
+
function mapFromService() {
|
|
35
|
+
return ({
|
|
36
|
+
response,
|
|
37
|
+
request,
|
|
38
|
+
responseMapper,
|
|
39
|
+
mappings,
|
|
40
|
+
mapResponseWithType = true,
|
|
41
|
+
}) => {
|
|
30
42
|
const type = request.params.type || Object.keys(mappings)
|
|
31
43
|
const { onlyMappedValues, unmapped = false } = request.params
|
|
32
44
|
|
|
@@ -34,28 +46,38 @@ function mapFromService () {
|
|
|
34
46
|
return response
|
|
35
47
|
}
|
|
36
48
|
|
|
37
|
-
const {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
const { data, status, error, paging, params } = mapWithEndpoint(
|
|
50
|
+
responseMapper,
|
|
51
|
+
response,
|
|
52
|
+
request.params,
|
|
53
|
+
request.action
|
|
54
|
+
)
|
|
55
|
+
|
|
44
56
|
const responseError = [response.error, error].filter(Boolean).join(' | ')
|
|
57
|
+
const responseStatus =
|
|
58
|
+
response.status !== 'ok'
|
|
59
|
+
? response.status
|
|
60
|
+
: status || (responseError ? 'error' : 'ok')
|
|
45
61
|
|
|
46
62
|
const ret = {
|
|
47
63
|
...response,
|
|
48
|
-
status:
|
|
49
|
-
...(
|
|
50
|
-
...(
|
|
51
|
-
...(
|
|
52
|
-
...(
|
|
64
|
+
status: responseStatus,
|
|
65
|
+
...(responseError ? { error: responseError } : {}),
|
|
66
|
+
...(paging ? { paging } : {}),
|
|
67
|
+
...(params ? { params } : {}),
|
|
68
|
+
...(responseStatus === 'ok' || data
|
|
69
|
+
? { data: data === null ? undefined : data }
|
|
70
|
+
: {}),
|
|
53
71
|
}
|
|
54
72
|
|
|
55
|
-
if (status === 'ok' && data && mapResponseWithType) {
|
|
56
|
-
const mapType = (type) =>
|
|
57
|
-
|
|
58
|
-
|
|
73
|
+
if (ret.status === 'ok' && data && mapResponseWithType) {
|
|
74
|
+
const mapType = (type) =>
|
|
75
|
+
mappings[type]
|
|
76
|
+
? mappings[type].fromService(
|
|
77
|
+
{ ...request, data },
|
|
78
|
+
{ onlyMappedValues }
|
|
79
|
+
)
|
|
80
|
+
: []
|
|
59
81
|
ret.data = flatten(mapAny(mapType, type))
|
|
60
82
|
}
|
|
61
83
|
|