lamp-core-lst 2025.11.1-3.basic
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/.github/workflows/publish.yml +34 -0
- package/LICENSE.md +29 -0
- package/MANUAL.md +26 -0
- package/README.md +126 -0
- package/cli.js +2 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +311 -0
- package/dist/model/Activity.d.ts +81 -0
- package/dist/model/Activity.js +30 -0
- package/dist/model/ActivityEvent.d.ts +51 -0
- package/dist/model/ActivityEvent.js +21 -0
- package/dist/model/ActivitySpec.d.ts +38 -0
- package/dist/model/ActivitySpec.js +12 -0
- package/dist/model/Credential.d.ts +21 -0
- package/dist/model/Credential.js +12 -0
- package/dist/model/DynamicAttachment.d.ts +34 -0
- package/dist/model/DynamicAttachment.js +12 -0
- package/dist/model/Participant.d.ts +30 -0
- package/dist/model/Participant.js +12 -0
- package/dist/model/Researcher.d.ts +27 -0
- package/dist/model/Researcher.js +12 -0
- package/dist/model/ResearcherSettings.d.ts +57 -0
- package/dist/model/ResearcherSettings.js +12 -0
- package/dist/model/Sensor.d.ts +22 -0
- package/dist/model/Sensor.js +12 -0
- package/dist/model/SensorEvent.d.ts +18 -0
- package/dist/model/SensorEvent.js +12 -0
- package/dist/model/SensorSpec.d.ts +13 -0
- package/dist/model/SensorSpec.js +12 -0
- package/dist/model/Study.d.ts +24 -0
- package/dist/model/Study.js +12 -0
- package/dist/model/Type.d.ts +56 -0
- package/dist/model/Type.js +30 -0
- package/dist/model/index.d.ts +12 -0
- package/dist/model/index.js +24 -0
- package/dist/service/API.service.d.ts +12 -0
- package/dist/service/API.service.js +82 -0
- package/dist/service/Activity.service.d.ts +101 -0
- package/dist/service/Activity.service.js +756 -0
- package/dist/service/ActivityEvent.service.d.ts +46 -0
- package/dist/service/ActivityEvent.service.js +303 -0
- package/dist/service/ActivitySpec.service.d.ts +31 -0
- package/dist/service/ActivitySpec.service.js +173 -0
- package/dist/service/Credential.service.d.ts +38 -0
- package/dist/service/Credential.service.js +319 -0
- package/dist/service/Demo.d.ts +14 -0
- package/dist/service/Demo.js +24 -0
- package/dist/service/Fetch.d.ts +30 -0
- package/dist/service/Fetch.js +245 -0
- package/dist/service/Participant.service.d.ts +42 -0
- package/dist/service/Participant.service.js +312 -0
- package/dist/service/Researcher.service.d.ts +34 -0
- package/dist/service/Researcher.service.js +252 -0
- package/dist/service/ResearcherSettings.service.d.ts +16 -0
- package/dist/service/ResearcherSettings.service.js +114 -0
- package/dist/service/Sensor.service.d.ts +47 -0
- package/dist/service/Sensor.service.js +372 -0
- package/dist/service/SensorEvent.service.d.ts +44 -0
- package/dist/service/SensorEvent.service.js +302 -0
- package/dist/service/SensorSpec.service.d.ts +31 -0
- package/dist/service/SensorSpec.service.js +171 -0
- package/dist/service/Study.service.d.ts +42 -0
- package/dist/service/Study.service.js +286 -0
- package/dist/service/Type.service.d.ts +48 -0
- package/dist/service/Type.service.js +352 -0
- package/dist/service/index.d.ts +13 -0
- package/dist/service/index.js +25 -0
- package/docs/APIApi.md +82 -0
- package/docs/AccessCitation.md +11 -0
- package/docs/Activity.md +13 -0
- package/docs/ActivityApi.md +356 -0
- package/docs/ActivityEvent.md +13 -0
- package/docs/ActivityEventApi.md +251 -0
- package/docs/ActivitySpec.md +14 -0
- package/docs/ActivitySpecApi.md +222 -0
- package/docs/Credential.md +12 -0
- package/docs/CredentialApi.md +175 -0
- package/docs/Document.md +9 -0
- package/docs/DurationInterval.md +11 -0
- package/docs/DurationIntervalLegacy.md +10 -0
- package/docs/DynamicAttachment.md +14 -0
- package/docs/Error.md +8 -0
- package/docs/Metadata.md +8 -0
- package/docs/Participant.md +14 -0
- package/docs/ParticipantApi.md +312 -0
- package/docs/Researcher.md +12 -0
- package/docs/ResearcherApi.md +223 -0
- package/docs/Sensor.md +12 -0
- package/docs/SensorApi.md +356 -0
- package/docs/SensorEvent.md +11 -0
- package/docs/SensorEventApi.md +250 -0
- package/docs/SensorSpec.md +10 -0
- package/docs/SensorSpecApi.md +222 -0
- package/docs/Study.md +11 -0
- package/docs/StudyApi.md +268 -0
- package/docs/TemporalSlice.md +13 -0
- package/docs/TypeApi.md +274 -0
- package/package.json +44 -0
- package/src/index.ts +256 -0
- package/src/model/Activity.ts +93 -0
- package/src/model/ActivityEvent.ts +63 -0
- package/src/model/ActivitySpec.ts +45 -0
- package/src/model/Credential.ts +26 -0
- package/src/model/DynamicAttachment.ts +42 -0
- package/src/model/Participant.ts +37 -0
- package/src/model/Researcher.ts +33 -0
- package/src/model/ResearcherSettings.ts +65 -0
- package/src/model/Sensor.ts +27 -0
- package/src/model/SensorEvent.ts +22 -0
- package/src/model/SensorSpec.ts +16 -0
- package/src/model/Study.ts +29 -0
- package/src/model/Type.ts +68 -0
- package/src/model/index.ts +12 -0
- package/src/service/API.service.ts +29 -0
- package/src/service/Activity.service.ts +625 -0
- package/src/service/ActivityEvent.service.ts +244 -0
- package/src/service/ActivitySpec.service.ts +98 -0
- package/src/service/Credential.service.ts +268 -0
- package/src/service/Demo.ts +21 -0
- package/src/service/Fetch.ts +187 -0
- package/src/service/Participant.service.ts +217 -0
- package/src/service/Researcher.service.ts +147 -0
- package/src/service/ResearcherSettings.service.ts +62 -0
- package/src/service/Sensor.service.ts +256 -0
- package/src/service/SensorEvent.service.ts +239 -0
- package/src/service/SensorSpec.service.ts +96 -0
- package/src/service/Study.service.ts +187 -0
- package/src/service/Type.service.ts +297 -0
- package/src/service/index.ts +13 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { Fetch, Configuration } from "./Fetch"
|
|
2
|
+
import { Identifier } from "../model/Type"
|
|
3
|
+
import { Study } from "../model/Study"
|
|
4
|
+
import { Demo } from "./Demo"
|
|
5
|
+
import jsonata from "jsonata"
|
|
6
|
+
|
|
7
|
+
export class StudyService {
|
|
8
|
+
public configuration?: Configuration
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get the set of all studies.
|
|
12
|
+
*/
|
|
13
|
+
public async all(transform?: string): Promise<Study[]> {
|
|
14
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
15
|
+
// DEMO
|
|
16
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
17
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
18
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
19
|
+
|
|
20
|
+
let output = Demo.Study.map(x => Object.assign(new Study(), x))
|
|
21
|
+
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
22
|
+
return Promise.resolve(output)
|
|
23
|
+
}
|
|
24
|
+
return (await Fetch.get<{ data: any[] }>(`/study`, this.configuration)).data.map(x => Object.assign(new Study(), x))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Get the set of studies for a single researcher.
|
|
29
|
+
* @param researcherId
|
|
30
|
+
*/
|
|
31
|
+
public async allByResearcher(researcherId: Identifier, transform?: string): Promise<Study[]> {
|
|
32
|
+
if (researcherId === null || researcherId === undefined)
|
|
33
|
+
throw new Error("Required parameter researcherId was null or undefined when calling studyAllByResearcher.")
|
|
34
|
+
|
|
35
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
36
|
+
// DEMO
|
|
37
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
38
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
39
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
40
|
+
if (researcherId === "me") researcherId = credential.length > 0 ? credential[0]["origin"] : researcherId
|
|
41
|
+
|
|
42
|
+
if (Demo.Researcher.filter(x => x["id"] === researcherId).length > 0) {
|
|
43
|
+
let output = Demo.Study.filter(x => x["#parent"] === researcherId).map(x => Object.assign(new Study(), x))
|
|
44
|
+
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
45
|
+
return Promise.resolve(output)
|
|
46
|
+
} else {
|
|
47
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return (await Fetch.get<{ data: any[] }>(`/researcher/${researcherId}/study`, this.configuration)).data.map(x =>
|
|
51
|
+
Object.assign(new Study(), x)
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Create a new Study for the given Researcher.
|
|
57
|
+
* @param researcherId
|
|
58
|
+
* @param study
|
|
59
|
+
*/
|
|
60
|
+
public async create(researcherId: Identifier, study: Study): Promise<Identifier> {
|
|
61
|
+
if (researcherId === null || researcherId === undefined)
|
|
62
|
+
throw new Error("Required parameter researcherId was null or undefined when calling studyCreate.")
|
|
63
|
+
if (study === null || study === undefined)
|
|
64
|
+
throw new Error("Required parameter study was null or undefined when calling studyCreate.")
|
|
65
|
+
|
|
66
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
67
|
+
// DEMO
|
|
68
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
69
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
70
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
71
|
+
if (researcherId === "me") researcherId = credential.length > 0 ? credential[0]["origin"] : researcherId
|
|
72
|
+
|
|
73
|
+
if (Demo.Researcher.filter(x => x["id"] === researcherId).length > 0) {
|
|
74
|
+
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
75
|
+
} else {
|
|
76
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return await Fetch.post(`/researcher/${researcherId}/study`, study, this.configuration)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Delete a study.
|
|
84
|
+
* @param studyId
|
|
85
|
+
*/
|
|
86
|
+
public async delete(studyId: Identifier): Promise<Identifier> {
|
|
87
|
+
if (studyId === null || studyId === undefined)
|
|
88
|
+
throw new Error("Required parameter studyId was null or undefined when calling studyDelete.")
|
|
89
|
+
|
|
90
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
91
|
+
// DEMO
|
|
92
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
93
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
94
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
95
|
+
if (studyId === "me") studyId = credential.length > 0 ? credential[0]["origin"] : studyId
|
|
96
|
+
|
|
97
|
+
if (Demo.Study.filter(x => x["id"] === studyId).length > 0) {
|
|
98
|
+
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
99
|
+
} else {
|
|
100
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return await Fetch.delete(`/study/${studyId}`, this.configuration)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Update the study.
|
|
108
|
+
* @param studyId
|
|
109
|
+
* @param study
|
|
110
|
+
*/
|
|
111
|
+
public async update(studyId: Identifier, study: Study): Promise<Identifier> {
|
|
112
|
+
if (studyId === null || studyId === undefined)
|
|
113
|
+
throw new Error("Required parameter studyId was null or undefined when calling studyUpdate.")
|
|
114
|
+
if (study === null || study === undefined)
|
|
115
|
+
throw new Error("Required parameter study was null or undefined when calling studyUpdate.")
|
|
116
|
+
|
|
117
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
118
|
+
// DEMO
|
|
119
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
120
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
121
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
122
|
+
if (studyId === "me") studyId = credential.length > 0 ? credential[0]["origin"] : studyId
|
|
123
|
+
|
|
124
|
+
if (Demo.Study.filter(x => x["id"] === studyId).length > 0) {
|
|
125
|
+
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
126
|
+
} else {
|
|
127
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return await Fetch.put(`/study/${studyId}`, study, this.configuration)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Get a single study, by identifier.
|
|
135
|
+
* @param studyId
|
|
136
|
+
*/
|
|
137
|
+
public async view(studyId: Identifier, transform?: string): Promise<Study> {
|
|
138
|
+
if (studyId === null || studyId === undefined)
|
|
139
|
+
throw new Error("Required parameter studyId was null or undefined when calling studyView.")
|
|
140
|
+
|
|
141
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
142
|
+
// DEMO
|
|
143
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
144
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
145
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
146
|
+
if (studyId === "me") studyId = credential.length > 0 ? credential[0]["origin"] : studyId
|
|
147
|
+
|
|
148
|
+
let data = Demo.Study.filter(x => x["id"] === studyId).map(x => Object.assign(new Study(), x))
|
|
149
|
+
if (data.length > 0) {
|
|
150
|
+
let output = data[0]
|
|
151
|
+
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
152
|
+
return Promise.resolve(output)
|
|
153
|
+
} else {
|
|
154
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return (await Fetch.get<{ data: any[] }>(`/study/${studyId}`, this.configuration)).data.map(x =>
|
|
158
|
+
Object.assign(new Study(), x)
|
|
159
|
+
)[0]
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get a single study, by identifier.
|
|
163
|
+
* @param studyId
|
|
164
|
+
*/
|
|
165
|
+
public async lookup(studyId: Identifier, mode:number, transform?: string): Promise<any> {
|
|
166
|
+
if (studyId === null || studyId === undefined)
|
|
167
|
+
throw new Error("Required parameter studyId was null or undefined when calling studyView.")
|
|
168
|
+
|
|
169
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
170
|
+
// DEMO
|
|
171
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
172
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
173
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
174
|
+
if (studyId === "me") studyId = credential.length > 0 ? credential[0]["origin"] : studyId
|
|
175
|
+
|
|
176
|
+
let data = Demo.Study.filter(x => x["id"] === studyId).map(x => Object.assign(new Study(), x))
|
|
177
|
+
if (data.length > 0) {
|
|
178
|
+
let output = data[0]
|
|
179
|
+
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
180
|
+
return Promise.resolve(output)
|
|
181
|
+
} else {
|
|
182
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return (await Fetch.get<{ data: any[] }>(`/study/${studyId}/_lookup/participant/mode/${mode}`, this.configuration))
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { Fetch, Configuration } from "./Fetch"
|
|
2
|
+
import { Identifier } from "../model/Type"
|
|
3
|
+
import { DynamicAttachment } from "../model/DynamicAttachment"
|
|
4
|
+
import { Demo } from "./Demo"
|
|
5
|
+
import jsonata from "jsonata"
|
|
6
|
+
|
|
7
|
+
export class TypeService {
|
|
8
|
+
public configuration?: Configuration
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param typeId
|
|
13
|
+
* @param attachmentKey
|
|
14
|
+
*/
|
|
15
|
+
public async getAttachment(typeId: Identifier, attachmentKey: string): Promise<any[]> {
|
|
16
|
+
if (attachmentKey === null || attachmentKey === undefined)
|
|
17
|
+
throw new Error("Required parameter attachmentKey was null or undefined when calling typeGetAttachment.")
|
|
18
|
+
|
|
19
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
20
|
+
// DEMO
|
|
21
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
22
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
23
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
24
|
+
if (typeId === "me") typeId = credential.length > 0 ? credential[0]["origin"] : typeId
|
|
25
|
+
|
|
26
|
+
let exists = [].concat(
|
|
27
|
+
Demo.Researcher.filter(x => x["id"] === typeId),
|
|
28
|
+
Demo.Study.filter(x => x["id"] === typeId),
|
|
29
|
+
Demo.Participant.filter(x => x["id"] === typeId),
|
|
30
|
+
Demo.Activity.filter(x => x["id"] === typeId) // ???
|
|
31
|
+
)
|
|
32
|
+
if (exists.length > 0) {
|
|
33
|
+
// FIXME: Sibling Tags? (Participant, Activity, Sensor)
|
|
34
|
+
const ancestors = (obj: any) =>
|
|
35
|
+
obj["#type"] === "Researcher"
|
|
36
|
+
? []
|
|
37
|
+
: obj["#type"] === "Study"
|
|
38
|
+
? [obj["#parent"]]
|
|
39
|
+
: obj["#type"] === "Participant"
|
|
40
|
+
? [obj["#parent"], Demo.Study.filter(x => x["id"] === obj["#parent"]).map(x => x["#parent"])[0]]
|
|
41
|
+
: obj["#type"] === "Activity"
|
|
42
|
+
? [obj["#parent"], Demo.Study.filter(x => x["id"] === obj["#parent"]).map(x => x["#parent"])[0]]
|
|
43
|
+
: []
|
|
44
|
+
const tagSelf = (tag: any) => [typeId].includes(tag["#parent"]) && [typeId, "me"].includes(tag["target"]) // implicit & explicit
|
|
45
|
+
const tagParent = (tag: any) =>
|
|
46
|
+
ancestors(exists[0]).includes(tag["#parent"]) && [typeId, exists[0]["#type"]].includes(tag["target"]) // implicit & explicit
|
|
47
|
+
let data = Demo.Tags.filter(x => (tagSelf(x) || tagParent(x)) && x["key"] === attachmentKey)
|
|
48
|
+
return Promise.resolve(
|
|
49
|
+
data.length > 0 ? ({ data: data[0]["value"] } as any) : ({ error: "404.not-found" } as any)
|
|
50
|
+
)
|
|
51
|
+
} else {
|
|
52
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return await Fetch.get(`/type/${typeId}/attachment/${attachmentKey}`, this.configuration)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @param typeId
|
|
61
|
+
* @param attachmentKey
|
|
62
|
+
* @param invokeAlways
|
|
63
|
+
* @param includeLogs
|
|
64
|
+
* @param ignoreOutput
|
|
65
|
+
*/
|
|
66
|
+
public async getDynamicAttachment(
|
|
67
|
+
typeId: Identifier,
|
|
68
|
+
attachmentKey: string,
|
|
69
|
+
invokeAlways: boolean,
|
|
70
|
+
includeLogs: boolean,
|
|
71
|
+
ignoreOutput: boolean
|
|
72
|
+
): Promise<DynamicAttachment[]> {
|
|
73
|
+
if (attachmentKey === null || attachmentKey === undefined)
|
|
74
|
+
throw new Error("Required parameter attachmentKey was null or undefined when calling typeGetDynamicAttachment.")
|
|
75
|
+
if (invokeAlways === null || invokeAlways === undefined)
|
|
76
|
+
throw new Error("Required parameter invokeAlways was null or undefined when calling typeGetDynamicAttachment.")
|
|
77
|
+
if (includeLogs === null || includeLogs === undefined)
|
|
78
|
+
throw new Error("Required parameter includeLogs was null or undefined when calling typeGetDynamicAttachment.")
|
|
79
|
+
if (ignoreOutput === null || ignoreOutput === undefined)
|
|
80
|
+
throw new Error("Required parameter ignoreOutput was null or undefined when calling typeGetDynamicAttachment.")
|
|
81
|
+
|
|
82
|
+
let queryParameters = new URLSearchParams()
|
|
83
|
+
if (invokeAlways !== undefined && invokeAlways !== null) queryParameters.set("invoke_always", <any>invokeAlways)
|
|
84
|
+
if (includeLogs !== undefined && includeLogs !== null) queryParameters.set("include_logs", <any>includeLogs)
|
|
85
|
+
if (ignoreOutput !== undefined && ignoreOutput !== null) queryParameters.set("ignore_output", <any>ignoreOutput)
|
|
86
|
+
|
|
87
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
88
|
+
// DEMO
|
|
89
|
+
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
90
|
+
}
|
|
91
|
+
return await Fetch.get(
|
|
92
|
+
`/type/${typeId}/attachment/dynamic/${attachmentKey}?${queryParameters.toString()}`,
|
|
93
|
+
this.configuration
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param typeId
|
|
100
|
+
*/
|
|
101
|
+
public async listAttachments(typeId: Identifier): Promise<any[]> {
|
|
102
|
+
|
|
103
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
104
|
+
// DEMO
|
|
105
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
106
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
107
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
108
|
+
if (typeId === "me") typeId = credential.length > 0 ? credential[0]["origin"] : typeId
|
|
109
|
+
|
|
110
|
+
let exists = [].concat(
|
|
111
|
+
Demo.Researcher.filter(x => x["id"] === typeId),
|
|
112
|
+
Demo.Study.filter(x => x["id"] === typeId),
|
|
113
|
+
Demo.Participant.filter(x => x["id"] === typeId),
|
|
114
|
+
Demo.Activity.filter(x => x["id"] === typeId) // ???
|
|
115
|
+
)
|
|
116
|
+
if (exists.length > 0) {
|
|
117
|
+
// FIXME: Sibling Tags? (Participant, Activity, Sensor)
|
|
118
|
+
const ancestors = (obj: any) =>
|
|
119
|
+
obj["#type"] === "Researcher"
|
|
120
|
+
? []
|
|
121
|
+
: obj["#type"] === "Study"
|
|
122
|
+
? [obj["#parent"]]
|
|
123
|
+
: obj["#type"] === "Participant"
|
|
124
|
+
? [obj["#parent"], Demo.Study.filter(x => x["id"] === obj["#parent"]).map(x => x["#parent"])[0]]
|
|
125
|
+
: obj["#type"] === "Activity"
|
|
126
|
+
? [obj["#parent"], Demo.Study.filter(x => x["id"] === obj["#parent"]).map(x => x["#parent"])[0]]
|
|
127
|
+
: []
|
|
128
|
+
const tagSelf = (tag: any) => [typeId].includes(tag["#parent"]) && [typeId, "me"].includes(tag["target"]) // implicit & explicit
|
|
129
|
+
const tagParent = (tag: any) =>
|
|
130
|
+
ancestors(exists[0]).includes(tag["#parent"]) && [typeId, exists[0]["#type"]].includes(tag["target"]) // implicit & explicit
|
|
131
|
+
return Promise.resolve({ data: Demo.Tags.filter(x => tagSelf(x) || tagParent(x)).map(x => x.key) } as any)
|
|
132
|
+
} else {
|
|
133
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return await Fetch.get(`/type/${typeId}/attachment`, this.configuration)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Get the parent type identifier of the data structure referenced by the identifier.
|
|
141
|
+
* @param typeId
|
|
142
|
+
*/
|
|
143
|
+
public async parent(typeId: Identifier, transform?: string): Promise<any> {
|
|
144
|
+
|
|
145
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
146
|
+
// DEMO
|
|
147
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
148
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
149
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
150
|
+
if (typeId === "me") typeId = credential.length > 0 ? credential[0]["origin"] : typeId
|
|
151
|
+
|
|
152
|
+
let possible = []
|
|
153
|
+
possible = Demo.Researcher.filter(x => x["id"] === typeId)
|
|
154
|
+
if (possible.length > 0) {
|
|
155
|
+
let output = { data: {} } as any
|
|
156
|
+
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
157
|
+
return Promise.resolve(output)
|
|
158
|
+
}
|
|
159
|
+
possible = Demo.Study.filter(x => x["id"] === typeId)
|
|
160
|
+
if (possible.length > 0) {
|
|
161
|
+
let output = { data: { Researcher: possible[0]["#parent"] } } as any
|
|
162
|
+
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
163
|
+
return Promise.resolve(output)
|
|
164
|
+
}
|
|
165
|
+
possible = Demo.Participant.filter(x => x["id"] === typeId)
|
|
166
|
+
if (possible.length > 0) {
|
|
167
|
+
let output = {
|
|
168
|
+
data: {
|
|
169
|
+
Researcher: Demo.Study.filter(x => x["id"] === possible[0]["#parent"])[0],
|
|
170
|
+
Study: possible[0]["#parent"]
|
|
171
|
+
}
|
|
172
|
+
} as any
|
|
173
|
+
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
174
|
+
return Promise.resolve(output)
|
|
175
|
+
}
|
|
176
|
+
possible = Demo.Activity.filter(x => x["id"] === typeId)
|
|
177
|
+
if (possible.length > 0) {
|
|
178
|
+
let output = {
|
|
179
|
+
data: {
|
|
180
|
+
Researcher: Demo.Study.filter(x => x["id"] === possible[0]["#parent"])[0],
|
|
181
|
+
Study: possible[0]["#parent"]
|
|
182
|
+
}
|
|
183
|
+
} as any
|
|
184
|
+
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
185
|
+
return Promise.resolve(output)
|
|
186
|
+
}
|
|
187
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
188
|
+
}
|
|
189
|
+
return await Fetch.get(`/type/${typeId}/parent`, this.configuration)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
*
|
|
194
|
+
* @param typeId
|
|
195
|
+
* @param target
|
|
196
|
+
* @param attachmentKey
|
|
197
|
+
* @param attachmentValue
|
|
198
|
+
*/
|
|
199
|
+
public async setAttachment(
|
|
200
|
+
typeId: Identifier,
|
|
201
|
+
target: string,
|
|
202
|
+
attachmentKey: string,
|
|
203
|
+
attachmentValue: any
|
|
204
|
+
): Promise<Identifier> {
|
|
205
|
+
if (target === null || target === undefined)
|
|
206
|
+
throw new Error("Required parameter target was null or undefined when calling typeSetAttachment.")
|
|
207
|
+
if (attachmentKey === null || attachmentKey === undefined)
|
|
208
|
+
throw new Error("Required parameter attachmentKey was null or undefined when calling typeSetAttachment.")
|
|
209
|
+
if (attachmentValue === undefined)
|
|
210
|
+
throw new Error("Required parameter attachmentValue was null or undefined when calling typeSetAttachment.")
|
|
211
|
+
|
|
212
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
213
|
+
// DEMO
|
|
214
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
215
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
216
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
217
|
+
if (typeId === "me") typeId = credential.length > 0 ? credential[0]["origin"] : typeId
|
|
218
|
+
|
|
219
|
+
let exists = [].concat(
|
|
220
|
+
Demo.Researcher.filter(x => x["id"] === typeId),
|
|
221
|
+
Demo.Study.filter(x => x["id"] === typeId),
|
|
222
|
+
Demo.Participant.filter(x => x["id"] === typeId),
|
|
223
|
+
Demo.Activity.filter(x => x["id"] === typeId) // ???
|
|
224
|
+
)
|
|
225
|
+
if (exists.length > 0) {
|
|
226
|
+
// FIXME: Sibling Tags? (Participant, Activity, Sensor)
|
|
227
|
+
if (attachmentValue === null) {
|
|
228
|
+
// DELETE
|
|
229
|
+
Demo.Tags = Demo.Tags.filter(
|
|
230
|
+
x => !(x["#parent"] === typeId && x["target"] === target && x["key"] === attachmentKey)
|
|
231
|
+
)
|
|
232
|
+
} else {
|
|
233
|
+
let idx = Demo.Tags.findIndex(
|
|
234
|
+
x => x["#parent"] === typeId && x["target"] === target && x["key"] === attachmentKey
|
|
235
|
+
)
|
|
236
|
+
if (idx >= 0) {
|
|
237
|
+
// UPDATE
|
|
238
|
+
console.dir("update")
|
|
239
|
+
Demo.Tags[idx]["value"] = attachmentValue
|
|
240
|
+
} else {
|
|
241
|
+
// INSERT
|
|
242
|
+
console.dir("insert")
|
|
243
|
+
Demo.Tags.push({
|
|
244
|
+
"#type": "Tag",
|
|
245
|
+
"#parent": typeId,
|
|
246
|
+
target: target,
|
|
247
|
+
key: attachmentKey,
|
|
248
|
+
value: attachmentValue
|
|
249
|
+
})
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return Promise.resolve({} as any)
|
|
253
|
+
} else {
|
|
254
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return await Fetch.put(`/type/${typeId}/attachment/${attachmentKey}/${target}`, attachmentValue, this.configuration)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
*
|
|
262
|
+
* @param invokeOnce
|
|
263
|
+
* @param typeId
|
|
264
|
+
* @param target
|
|
265
|
+
* @param attachmentKey
|
|
266
|
+
* @param attachmentValue
|
|
267
|
+
*/
|
|
268
|
+
public async setDynamicAttachment(
|
|
269
|
+
invokeOnce: boolean,
|
|
270
|
+
typeId: Identifier,
|
|
271
|
+
target: string,
|
|
272
|
+
attachmentKey: string,
|
|
273
|
+
attachmentValue: DynamicAttachment
|
|
274
|
+
): Promise<Identifier> {
|
|
275
|
+
if (invokeOnce === null || invokeOnce === undefined)
|
|
276
|
+
throw new Error("Required parameter invokeOnce was null or undefined when calling typeSetDynamicAttachment.")
|
|
277
|
+
if (target === null || target === undefined)
|
|
278
|
+
throw new Error("Required parameter target was null or undefined when calling typeSetDynamicAttachment.")
|
|
279
|
+
if (attachmentKey === null || attachmentKey === undefined)
|
|
280
|
+
throw new Error("Required parameter attachmentKey was null or undefined when calling typeSetDynamicAttachment.")
|
|
281
|
+
if (attachmentValue === null || attachmentValue === undefined)
|
|
282
|
+
throw new Error("Required parameter attachmentValue was null or undefined when calling typeSetDynamicAttachment.")
|
|
283
|
+
|
|
284
|
+
let queryParameters = new URLSearchParams()
|
|
285
|
+
if (invokeOnce !== undefined && invokeOnce !== null) queryParameters.set("invoke_once", <any>invokeOnce)
|
|
286
|
+
|
|
287
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
288
|
+
// DEMO
|
|
289
|
+
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
290
|
+
}
|
|
291
|
+
return await Fetch.put(
|
|
292
|
+
`/type/${typeId}/attachment/dynamic/${attachmentKey}/${target}?${queryParameters.toString()}`,
|
|
293
|
+
attachmentValue,
|
|
294
|
+
this.configuration
|
|
295
|
+
)
|
|
296
|
+
}
|
|
297
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./Activity.service"
|
|
2
|
+
export * from "./ActivityEvent.service"
|
|
3
|
+
export * from "./ActivitySpec.service"
|
|
4
|
+
export * from "./Credential.service"
|
|
5
|
+
export * from "./Participant.service"
|
|
6
|
+
export * from "./Researcher.service"
|
|
7
|
+
export * from "./ResearcherSettings.service"
|
|
8
|
+
export * from "./Sensor.service"
|
|
9
|
+
export * from "./SensorEvent.service"
|
|
10
|
+
export * from "./SensorSpec.service"
|
|
11
|
+
export * from "./Study.service"
|
|
12
|
+
export * from "./Type.service"
|
|
13
|
+
export * from "./API.service"
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"esnext"
|
|
8
|
+
],
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"allowJs": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
"alwaysStrict": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"module": "commonjs",
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"isolatedModules": true,
|
|
19
|
+
"jsx": "preserve",
|
|
20
|
+
"outDir": "dist"
|
|
21
|
+
},
|
|
22
|
+
"include": [
|
|
23
|
+
"src"
|
|
24
|
+
],
|
|
25
|
+
"exclude": [
|
|
26
|
+
"node_modules",
|
|
27
|
+
"dist"
|
|
28
|
+
]
|
|
29
|
+
}
|