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.
Files changed (130) hide show
  1. package/.github/workflows/publish.yml +34 -0
  2. package/LICENSE.md +29 -0
  3. package/MANUAL.md +26 -0
  4. package/README.md +126 -0
  5. package/cli.js +2 -0
  6. package/dist/index.d.ts +64 -0
  7. package/dist/index.js +311 -0
  8. package/dist/model/Activity.d.ts +81 -0
  9. package/dist/model/Activity.js +30 -0
  10. package/dist/model/ActivityEvent.d.ts +51 -0
  11. package/dist/model/ActivityEvent.js +21 -0
  12. package/dist/model/ActivitySpec.d.ts +38 -0
  13. package/dist/model/ActivitySpec.js +12 -0
  14. package/dist/model/Credential.d.ts +21 -0
  15. package/dist/model/Credential.js +12 -0
  16. package/dist/model/DynamicAttachment.d.ts +34 -0
  17. package/dist/model/DynamicAttachment.js +12 -0
  18. package/dist/model/Participant.d.ts +30 -0
  19. package/dist/model/Participant.js +12 -0
  20. package/dist/model/Researcher.d.ts +27 -0
  21. package/dist/model/Researcher.js +12 -0
  22. package/dist/model/ResearcherSettings.d.ts +57 -0
  23. package/dist/model/ResearcherSettings.js +12 -0
  24. package/dist/model/Sensor.d.ts +22 -0
  25. package/dist/model/Sensor.js +12 -0
  26. package/dist/model/SensorEvent.d.ts +18 -0
  27. package/dist/model/SensorEvent.js +12 -0
  28. package/dist/model/SensorSpec.d.ts +13 -0
  29. package/dist/model/SensorSpec.js +12 -0
  30. package/dist/model/Study.d.ts +24 -0
  31. package/dist/model/Study.js +12 -0
  32. package/dist/model/Type.d.ts +56 -0
  33. package/dist/model/Type.js +30 -0
  34. package/dist/model/index.d.ts +12 -0
  35. package/dist/model/index.js +24 -0
  36. package/dist/service/API.service.d.ts +12 -0
  37. package/dist/service/API.service.js +82 -0
  38. package/dist/service/Activity.service.d.ts +101 -0
  39. package/dist/service/Activity.service.js +756 -0
  40. package/dist/service/ActivityEvent.service.d.ts +46 -0
  41. package/dist/service/ActivityEvent.service.js +303 -0
  42. package/dist/service/ActivitySpec.service.d.ts +31 -0
  43. package/dist/service/ActivitySpec.service.js +173 -0
  44. package/dist/service/Credential.service.d.ts +38 -0
  45. package/dist/service/Credential.service.js +319 -0
  46. package/dist/service/Demo.d.ts +14 -0
  47. package/dist/service/Demo.js +24 -0
  48. package/dist/service/Fetch.d.ts +30 -0
  49. package/dist/service/Fetch.js +245 -0
  50. package/dist/service/Participant.service.d.ts +42 -0
  51. package/dist/service/Participant.service.js +312 -0
  52. package/dist/service/Researcher.service.d.ts +34 -0
  53. package/dist/service/Researcher.service.js +252 -0
  54. package/dist/service/ResearcherSettings.service.d.ts +16 -0
  55. package/dist/service/ResearcherSettings.service.js +114 -0
  56. package/dist/service/Sensor.service.d.ts +47 -0
  57. package/dist/service/Sensor.service.js +372 -0
  58. package/dist/service/SensorEvent.service.d.ts +44 -0
  59. package/dist/service/SensorEvent.service.js +302 -0
  60. package/dist/service/SensorSpec.service.d.ts +31 -0
  61. package/dist/service/SensorSpec.service.js +171 -0
  62. package/dist/service/Study.service.d.ts +42 -0
  63. package/dist/service/Study.service.js +286 -0
  64. package/dist/service/Type.service.d.ts +48 -0
  65. package/dist/service/Type.service.js +352 -0
  66. package/dist/service/index.d.ts +13 -0
  67. package/dist/service/index.js +25 -0
  68. package/docs/APIApi.md +82 -0
  69. package/docs/AccessCitation.md +11 -0
  70. package/docs/Activity.md +13 -0
  71. package/docs/ActivityApi.md +356 -0
  72. package/docs/ActivityEvent.md +13 -0
  73. package/docs/ActivityEventApi.md +251 -0
  74. package/docs/ActivitySpec.md +14 -0
  75. package/docs/ActivitySpecApi.md +222 -0
  76. package/docs/Credential.md +12 -0
  77. package/docs/CredentialApi.md +175 -0
  78. package/docs/Document.md +9 -0
  79. package/docs/DurationInterval.md +11 -0
  80. package/docs/DurationIntervalLegacy.md +10 -0
  81. package/docs/DynamicAttachment.md +14 -0
  82. package/docs/Error.md +8 -0
  83. package/docs/Metadata.md +8 -0
  84. package/docs/Participant.md +14 -0
  85. package/docs/ParticipantApi.md +312 -0
  86. package/docs/Researcher.md +12 -0
  87. package/docs/ResearcherApi.md +223 -0
  88. package/docs/Sensor.md +12 -0
  89. package/docs/SensorApi.md +356 -0
  90. package/docs/SensorEvent.md +11 -0
  91. package/docs/SensorEventApi.md +250 -0
  92. package/docs/SensorSpec.md +10 -0
  93. package/docs/SensorSpecApi.md +222 -0
  94. package/docs/Study.md +11 -0
  95. package/docs/StudyApi.md +268 -0
  96. package/docs/TemporalSlice.md +13 -0
  97. package/docs/TypeApi.md +274 -0
  98. package/package.json +44 -0
  99. package/src/index.ts +256 -0
  100. package/src/model/Activity.ts +93 -0
  101. package/src/model/ActivityEvent.ts +63 -0
  102. package/src/model/ActivitySpec.ts +45 -0
  103. package/src/model/Credential.ts +26 -0
  104. package/src/model/DynamicAttachment.ts +42 -0
  105. package/src/model/Participant.ts +37 -0
  106. package/src/model/Researcher.ts +33 -0
  107. package/src/model/ResearcherSettings.ts +65 -0
  108. package/src/model/Sensor.ts +27 -0
  109. package/src/model/SensorEvent.ts +22 -0
  110. package/src/model/SensorSpec.ts +16 -0
  111. package/src/model/Study.ts +29 -0
  112. package/src/model/Type.ts +68 -0
  113. package/src/model/index.ts +12 -0
  114. package/src/service/API.service.ts +29 -0
  115. package/src/service/Activity.service.ts +625 -0
  116. package/src/service/ActivityEvent.service.ts +244 -0
  117. package/src/service/ActivitySpec.service.ts +98 -0
  118. package/src/service/Credential.service.ts +268 -0
  119. package/src/service/Demo.ts +21 -0
  120. package/src/service/Fetch.ts +187 -0
  121. package/src/service/Participant.service.ts +217 -0
  122. package/src/service/Researcher.service.ts +147 -0
  123. package/src/service/ResearcherSettings.service.ts +62 -0
  124. package/src/service/Sensor.service.ts +256 -0
  125. package/src/service/SensorEvent.service.ts +239 -0
  126. package/src/service/SensorSpec.service.ts +96 -0
  127. package/src/service/Study.service.ts +187 -0
  128. package/src/service/Type.service.ts +297 -0
  129. package/src/service/index.ts +13 -0
  130. package/tsconfig.json +29 -0
@@ -0,0 +1,256 @@
1
+ import { Fetch, Configuration } from "./Fetch"
2
+ import { Sensor } from "../model/Sensor"
3
+ import { Identifier } from "../model/Type"
4
+ import { Participant } from "../model/Participant"
5
+ import { Demo } from "./Demo"
6
+ import jsonata from "jsonata"
7
+
8
+ export class SensorService {
9
+ public configuration?: Configuration
10
+
11
+ /**
12
+ * Get the set of all activities.
13
+ */
14
+ public async all(transform?: string): Promise<Sensor[]> {
15
+ if (this.configuration.base === "https://demo.lamp.digital") {
16
+ // DEMO
17
+ let auth = (this.configuration.authorization || ":").split(":")
18
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
19
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
20
+ let output = Demo.Sensor.map(x => Object.assign(new Sensor(), x))
21
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
22
+ return Promise.resolve(output)
23
+ }
24
+ return (await Fetch.get<{ data: any[] }>(`/sensor`, this.configuration)).data.map(x =>
25
+ Object.assign(new Sensor(), x)
26
+ )
27
+ }
28
+
29
+ /**
30
+ * Get the set of all activities available to a participant, by participant identifier.
31
+ * @param participantId
32
+ */
33
+ public async allByParticipant(participantId: Identifier, transform?: string, ignore_binary?: boolean): Promise<Sensor[]> {
34
+ if (participantId === null || participantId === undefined)
35
+ throw new Error("Required parameter participantId was null or undefined when calling sensorAllByParticipant.")
36
+ if (ignore_binary === null || ignore_binary === undefined) ignore_binary = false
37
+ if (this.configuration.base === "https://demo.lamp.digital") {
38
+ // DEMO
39
+ let auth = (this.configuration.authorization || ":").split(":")
40
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
41
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
42
+ if (participantId === "me") participantId = credential.length > 0 ? credential[0]["origin"] : participantId
43
+
44
+ if (Demo.Participant.filter(x => x["id"] === participantId).length > 0) {
45
+ let output = Demo.Sensor.filter(x =>
46
+ Demo.Participant.filter(y => y["id"] === participantId)
47
+ .map(y => y["#parent"])
48
+ .includes(x["#parent"])
49
+ ).map(x => Object.assign(new Sensor(), x))
50
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
51
+ return Promise.resolve(output)
52
+ } else {
53
+ return Promise.resolve({ error: "404.not-found" } as any)
54
+ }
55
+ }
56
+ return (await Fetch.get<{ data: any[] }>(`/participant/${participantId}/sensor?ignore_binary=${ignore_binary}`, this.configuration)).data.map(x =>
57
+ Object.assign(new Sensor(), x)
58
+ )
59
+ }
60
+
61
+ /**
62
+ * Get the set of all activities available to participants of any study conducted by a researcher, by researcher identifier.
63
+ * @param researcherId
64
+ */
65
+ public async allByResearcher(researcherId: Identifier, transform?: string): Promise<Sensor[]> {
66
+ if (researcherId === null || researcherId === undefined)
67
+ throw new Error("Required parameter researcherId was null or undefined when calling sensorAllByResearcher.")
68
+
69
+ if (this.configuration.base === "https://demo.lamp.digital") {
70
+ // DEMO
71
+ let auth = (this.configuration.authorization || ":").split(":")
72
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
73
+ if (credential.length === 0) {
74
+ return Promise.resolve({ error: "403.invalid-credentials" } as any)
75
+ }
76
+ if (researcherId === "me") {
77
+ researcherId = credential.length > 0 ? credential[0]["origin"] : researcherId
78
+ }
79
+
80
+ if (Demo.Researcher.filter(x => x["id"] === researcherId).length > 0) {
81
+ let output = Demo.Sensor.filter(x =>
82
+ Demo.Study.filter(y => y["#parent"] === researcherId)
83
+ .map(y => y["id"])
84
+ .includes(x["#parent"])
85
+ ).map(x => Object.assign(new Sensor(), x))
86
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
87
+ return Promise.resolve(output)
88
+ } else {
89
+ return Promise.resolve({ error: "404.not-found" } as any)
90
+ }
91
+ }
92
+ return (await Fetch.get<{ data: any[] }>(`/researcher/${researcherId}/sensor`, this.configuration)).data.map(x =>
93
+ Object.assign(new Sensor(), x)
94
+ )
95
+ }
96
+
97
+ /**
98
+ * Get the set of all activities available to participants of a single study, by study identifier.
99
+ * @param studyId
100
+ */
101
+ public async allByStudy(studyId: Identifier, transform?: string, ignore_binary?: boolean): Promise<Sensor[]> {
102
+ if (studyId === null || studyId === undefined)
103
+ throw new Error("Required parameter studyId was null or undefined when calling sensorAllByStudy.")
104
+ if (ignore_binary === null || ignore_binary === undefined) ignore_binary = false
105
+ if (this.configuration.base === "https://demo.lamp.digital") {
106
+ // DEMO
107
+ let auth = (this.configuration.authorization || ":").split(":")
108
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
109
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
110
+ if (studyId === "me") studyId = credential.length > 0 ? credential[0]["origin"] : studyId
111
+
112
+ if (Demo.Study.filter(x => x["id"] === studyId).length > 0) {
113
+ let output = Demo.Sensor.filter(x => x["#parent"] === studyId).map(x => Object.assign(new Sensor(), x))
114
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
115
+ return Promise.resolve(output)
116
+ } else {
117
+ return Promise.resolve({ error: "404.not-found" } as any)
118
+ }
119
+ }
120
+ return (await Fetch.get<{ data: any[] }>(`/study/${studyId}/sensor?ignore_binary=${ignore_binary}`, this.configuration)).data.map(x =>
121
+ Object.assign(new Sensor(), x)
122
+ )
123
+ }
124
+
125
+ /**
126
+ * Create a new Sensor under the given Study.
127
+ * @param studyId
128
+ * @param sensor
129
+ */
130
+ public async create(studyId: Identifier, sensor: Sensor): Promise<Identifier> {
131
+ if (studyId === null || studyId === undefined)
132
+ throw new Error("Required parameter studyId was null or undefined when calling sensorCreate.")
133
+ if (sensor === null || sensor === undefined)
134
+ throw new Error("Required parameter sensor was null or undefined when calling sensorCreate.")
135
+
136
+ if (this.configuration.base === "https://demo.lamp.digital") {
137
+ // DEMO
138
+ let auth = (this.configuration.authorization || ":").split(":")
139
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
140
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
141
+ if (studyId === "me") studyId = credential.length > 0 ? credential[0]["origin"] : studyId
142
+
143
+ if (Demo.Study.filter(x => x["id"] === studyId).length > 0) {
144
+ let data = {
145
+ "#type": "Sensor",
146
+ "#parent": studyId,
147
+ ...(sensor as any),
148
+ id:
149
+ "sensor" +
150
+ Math.random()
151
+ .toString()
152
+ .substring(2, 6)
153
+ }
154
+ Demo.Sensor.push(data)
155
+ return Promise.resolve({ data: data["id"] } as any)
156
+ } else {
157
+ return Promise.resolve({ error: "404.not-found" } as any)
158
+ }
159
+ }
160
+ return await Fetch.post(`/study/${studyId}/sensor`, sensor, this.configuration)
161
+ }
162
+
163
+ /**
164
+ * Delete an Sensor.
165
+ * @param sensorId
166
+ */
167
+ public async delete(sensorId: Identifier): Promise<Identifier> {
168
+ if (sensorId === null || sensorId === undefined)
169
+ throw new Error("Required parameter sensorId was null or undefined when calling sensorDelete.")
170
+
171
+ if (this.configuration.base === "https://demo.lamp.digital") {
172
+ // DEMO
173
+ let auth = (this.configuration.authorization || ":").split(":")
174
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
175
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
176
+ if (sensorId === "me") sensorId = credential.length > 0 ? credential[0]["origin"] : sensorId
177
+
178
+ let idx = Demo.Sensor.findIndex(x => x["id"] === sensorId)
179
+ if (idx >= 0) {
180
+ Demo.Sensor.splice(idx, 1)
181
+ Demo.SensorEvent = Demo.SensorEvent.filter(x => x["sensor"] !== sensorId)
182
+ Demo.Credential = Demo.Credential.filter(x => x["#parent"] !== sensorId)
183
+ Demo.Tags = Demo.Tags.filter(x => x["#parent"] !== sensorId && x["target"] !== sensorId)
184
+ return Promise.resolve({} as any)
185
+ } else {
186
+ return Promise.resolve({ error: "404.not-found" } as any)
187
+ }
188
+ }
189
+ return await Fetch.delete(`/sensor/${sensorId}`, this.configuration)
190
+ }
191
+
192
+ /**
193
+ * Update an Sensor's settings.
194
+ * @param sensorId
195
+ * @param sensor
196
+ */
197
+ public async update(sensorId: Identifier, sensor: Sensor): Promise<Identifier> {
198
+ if (sensorId === null || sensorId === undefined)
199
+ throw new Error("Required parameter sensorId was null or undefined when calling sensorUpdate.")
200
+ if (sensor === null || sensor === undefined)
201
+ throw new Error("Required parameter sensor was null or undefined when calling sensorUpdate.")
202
+
203
+ if (this.configuration.base === "https://demo.lamp.digital") {
204
+ // DEMO
205
+ let auth = (this.configuration.authorization || ":").split(":")
206
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
207
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
208
+ if (sensorId === "me") sensorId = credential.length > 0 ? credential[0]["origin"] : sensorId
209
+
210
+ let idx = Demo.Sensor.findIndex(x => x["id"] === sensorId)
211
+ if (idx >= 0) {
212
+ Demo.Sensor[idx] = {
213
+ "#type": "Sensor",
214
+ "#parent": Demo.Sensor[idx]["#parent"],
215
+ id: Demo.Sensor[idx]["id"],
216
+ spec: Demo.Sensor[idx]["spec"],
217
+ name: sensor.name ?? Demo.Sensor[idx]["name"],
218
+ settings: sensor.settings as any
219
+ }
220
+ return Promise.resolve({} as any)
221
+ } else {
222
+ return Promise.resolve({ error: "404.not-found" } as any)
223
+ }
224
+ }
225
+ return await Fetch.put(`/sensor/${sensorId}`, sensor, this.configuration)
226
+ }
227
+
228
+ /**
229
+ * Get a single sensor, by identifier.
230
+ * @param sensorId
231
+ */
232
+ public async view(sensorId: Identifier, transform?: string, ignore_binary?:boolean): Promise<Sensor> {
233
+ if (sensorId === null || sensorId === undefined)
234
+ throw new Error("Required parameter sensorId was null or undefined when calling sensorView.")
235
+ if (ignore_binary === null || ignore_binary === undefined) ignore_binary = false
236
+ if (this.configuration.base === "https://demo.lamp.digital") {
237
+ // DEMO
238
+ let auth = (this.configuration.authorization || ":").split(":")
239
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
240
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
241
+ if (sensorId === "me") sensorId = credential.length > 0 ? credential[0]["origin"] : sensorId
242
+
243
+ let data = Demo.Sensor.filter(x => x["id"] === sensorId).map(x => Object.assign(new Sensor(), x))
244
+ if (data.length > 0) {
245
+ let output = data[0]
246
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
247
+ return Promise.resolve(output)
248
+ } else {
249
+ return Promise.resolve({ error: "404.not-found" } as any)
250
+ }
251
+ }
252
+ return (await Fetch.get<{ data: any[] }>(`/sensor/${sensorId}?ignore_binary=${ignore_binary}`, this.configuration)).data.map(x =>
253
+ Object.assign(new Sensor(), x)
254
+ )[0]
255
+ }
256
+ }
@@ -0,0 +1,239 @@
1
+ import { Fetch, Configuration } from "./Fetch"
2
+ import { Identifier } from "../model/Type"
3
+ import { SensorEvent } from "../model/SensorEvent"
4
+ import { Demo } from "./Demo"
5
+ import jsonata from "jsonata"
6
+
7
+ export class SensorEventService {
8
+ public configuration?: Configuration
9
+
10
+ /**
11
+ * Get the set of all sensor events produced by the given participant.
12
+ * @param participantId
13
+ * @param origin
14
+ * @param from
15
+ * @param to
16
+ */
17
+ public async allByParticipant(
18
+ participantId: Identifier,
19
+ origin?: string,
20
+ from?: number,
21
+ to?: number,
22
+ limit?: number,
23
+ transform?: string
24
+ ): Promise<SensorEvent[]> {
25
+ if (participantId === null || participantId === undefined)
26
+ throw new Error(
27
+ "Required parameter participantId was null or undefined when calling sensorEventAllByParticipant."
28
+ )
29
+
30
+ let queryParameters = new URLSearchParams()
31
+ if (origin !== undefined && origin !== null) queryParameters.set("origin", <any>origin)
32
+ if (from !== undefined && from !== null) queryParameters.set("from", <any>from)
33
+ if (to !== undefined && to !== null) queryParameters.set("to", <any>to)
34
+ if (limit !== undefined && limit !== null) queryParameters.set("limit", <any>limit)
35
+
36
+ if (this.configuration.base === "https://demo.lamp.digital") {
37
+ // DEMO
38
+ let auth = (this.configuration.authorization || ":").split(":")
39
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
40
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
41
+ if (participantId === "me") participantId = credential.length > 0 ? credential[0]["origin"] : participantId
42
+
43
+ if (Demo.Participant.filter(x => x["id"] === participantId).length > 0) {
44
+ let output = Demo.SensorEvent.filter(
45
+ x => x["#parent"] === participantId && (!!origin ? x["sensor"] === origin : true)
46
+ ).map(x => Object.assign(new SensorEvent(), x))
47
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
48
+ return Promise.resolve(output)
49
+ } else {
50
+ return Promise.resolve({ error: "404.not-found" } as any)
51
+ }
52
+ }
53
+ return (
54
+ await Fetch.get<{ data: any[] }>(
55
+ `/participant/${participantId}/sensor_event?${queryParameters.toString()}`,
56
+ this.configuration
57
+ )
58
+ )?.data?.map(x => Object.assign(new SensorEvent(), x))
59
+ }
60
+
61
+ /**
62
+ * Get the set of all sensor events produced by participants of any study conducted by a researcher, by researcher identifier.
63
+ * @param researcherId
64
+ * @param origin
65
+ * @param from
66
+ * @param to
67
+ */
68
+ public async allByResearcher(
69
+ researcherId: Identifier,
70
+ origin?: string,
71
+ from?: number,
72
+ to?: number,
73
+ limit?: number,
74
+ transform?: string
75
+ ): Promise<SensorEvent[]> {
76
+ if (researcherId === null || researcherId === undefined)
77
+ throw new Error("Required parameter researcherId was null or undefined when calling sensorEventAllByResearcher.")
78
+
79
+ let queryParameters = new URLSearchParams()
80
+ if (origin !== undefined && origin !== null) queryParameters.set("origin", <any>origin)
81
+ if (from !== undefined && from !== null) queryParameters.set("from", <any>from)
82
+ if (to !== undefined && to !== null) queryParameters.set("to", <any>to)
83
+ if (limit !== undefined && limit !== null) queryParameters.set("limit", <any>limit)
84
+
85
+ if (this.configuration.base === "https://demo.lamp.digital") {
86
+ // DEMO
87
+ let auth = (this.configuration.authorization || ":").split(":")
88
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
89
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
90
+ if (researcherId === "me") researcherId = credential.length > 0 ? credential[0]["origin"] : researcherId
91
+
92
+ if (Demo.Researcher.filter(x => x["id"] === researcherId).length > 0) {
93
+ let participants = Demo.Study.filter(x => x["#parent"] === researcherId)
94
+ .map(x => Demo.Participant.filter(y => y["#parent"] === x["id"]))
95
+ .flat(1)
96
+ let fn = (id: string) =>
97
+ Demo.SensorEvent.filter(x => x["#parent"] === id && (!!origin ? x["sensor"] === origin : true)).map(x =>
98
+ Object.assign(new SensorEvent(), x)
99
+ )
100
+ let output = participants.reduce(
101
+ (all, participant) => ({ ...all, [participant["id"]]: fn(participant["id"]) }),
102
+ {}
103
+ ) as any
104
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
105
+ return Promise.resolve(output)
106
+ } else {
107
+ return Promise.resolve({ error: "404.not-found" } as any)
108
+ }
109
+ }
110
+ return (
111
+ await Fetch.get<{ data: any[] }>(
112
+ `/researcher/${researcherId}/sensor_event?${queryParameters.toString()}`,
113
+ this.configuration
114
+ )
115
+ )?.data?.map(x => Object.assign(new SensorEvent(), x))
116
+ }
117
+
118
+ /**
119
+ * Get the set of all sensor events produced by participants participants of a single study, by study identifier.
120
+ * @param studyId
121
+ * @param origin
122
+ * @param from
123
+ * @param to
124
+ */
125
+ public async allByStudy(
126
+ studyId: Identifier,
127
+ origin?: string,
128
+ from?: number,
129
+ to?: number,
130
+ limit?: number,
131
+ transform?: string
132
+ ): Promise<SensorEvent[]> {
133
+ if (studyId === null || studyId === undefined)
134
+ throw new Error("Required parameter studyId was null or undefined when calling sensorEventAllByStudy.")
135
+
136
+ let queryParameters = new URLSearchParams()
137
+ if (origin !== undefined && origin !== null) queryParameters.set("origin", <any>origin)
138
+ if (from !== undefined && from !== null) queryParameters.set("from", <any>from)
139
+ if (to !== undefined && to !== null) queryParameters.set("to", <any>to)
140
+ if (limit !== undefined && limit !== null) queryParameters.set("limit", <any>limit)
141
+
142
+ if (this.configuration.base === "https://demo.lamp.digital") {
143
+ // DEMO
144
+ let auth = (this.configuration.authorization || ":").split(":")
145
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
146
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
147
+ if (studyId === "me") studyId = credential.length > 0 ? credential[0]["origin"] : studyId
148
+
149
+ if (Demo.Study.filter(x => x["id"] === studyId).length > 0) {
150
+ let participants = Demo.Participant.filter(x => x["#parent"] === studyId)
151
+ let fn = (id: string) =>
152
+ Demo.SensorEvent.filter(x => x["#parent"] === id && (!!origin ? x["sensor"] === origin : true)).map(x =>
153
+ Object.assign(new SensorEvent(), x)
154
+ )
155
+ let output = participants.reduce(
156
+ (all, participant) => ({ ...all, [participant["id"]]: fn(participant["id"]) }),
157
+ {}
158
+ ) as any
159
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
160
+ return Promise.resolve(output)
161
+ } else {
162
+ return Promise.resolve({ error: "404.not-found" } as any)
163
+ }
164
+ }
165
+ return (
166
+ await Fetch.get<{ data: any[] }>(
167
+ `/study/${studyId}/sensor_event?${queryParameters.toString()}`,
168
+ this.configuration
169
+ )
170
+ )?.data?.map(x => Object.assign(new SensorEvent(), x))
171
+ }
172
+
173
+ /**
174
+ * Create a new SensorEvent for the given Participant.
175
+ * @param participantId
176
+ * @param sensorEvent
177
+ */
178
+ public async create(participantId: Identifier, sensorEvent: SensorEvent): Promise<Identifier> {
179
+ if (participantId === null || participantId === undefined)
180
+ throw new Error("Required parameter participantId was null or undefined when calling sensorEventCreate.")
181
+ if (sensorEvent === null || sensorEvent === undefined)
182
+ throw new Error("Required parameter sensorEvent was null or undefined when calling sensorEventCreate.")
183
+
184
+ if (this.configuration.base === "https://demo.lamp.digital") {
185
+ // DEMO
186
+ let auth = (this.configuration.authorization || ":").split(":")
187
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
188
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
189
+ if (participantId === "me") participantId = credential.length > 0 ? credential[0]["origin"] : participantId
190
+
191
+ if (Demo.Participant.filter(x => x["id"] === participantId).length > 0) {
192
+ Demo.SensorEvent.push({
193
+ "#type": "SensorEvent",
194
+ "#parent": participantId,
195
+ ...(sensorEvent as any)
196
+ })
197
+ return Promise.resolve({} as any)
198
+ } else {
199
+ return Promise.resolve({ error: "404.not-found" } as any)
200
+ }
201
+ }
202
+ return await Fetch.post(`/participant/${participantId}/sensor_event`, sensorEvent, this.configuration)
203
+ }
204
+
205
+ /**
206
+ * Delete a sensor event.
207
+ * @param participantId
208
+ * @param origin
209
+ * @param from
210
+ * @param to
211
+ */
212
+ public async delete(participantId: Identifier, origin?: string, from?: number, to?: number): Promise<Identifier> {
213
+ if (participantId === null || participantId === undefined)
214
+ throw new Error("Required parameter participantId was null or undefined when calling sensorEventDelete.")
215
+
216
+ let queryParameters = new URLSearchParams()
217
+ if (origin !== undefined && origin !== null) queryParameters.set("origin", <any>origin)
218
+ if (from !== undefined && from !== null) queryParameters.set("from", <any>from)
219
+ if (to !== undefined && to !== null) queryParameters.set("to", <any>to)
220
+
221
+ if (this.configuration.base === "https://demo.lamp.digital") {
222
+ // DEMO
223
+ let auth = (this.configuration.authorization || ":").split(":")
224
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
225
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
226
+ if (participantId === "me") participantId = credential.length > 0 ? credential[0]["origin"] : participantId
227
+
228
+ if (Demo.Participant.filter(x => x["id"] === participantId).length > 0) {
229
+ return Promise.resolve({ error: "500.demo-restriction" } as any)
230
+ } else {
231
+ return Promise.resolve({ error: "404.not-found" } as any)
232
+ }
233
+ }
234
+ return await Fetch.delete(
235
+ `/participant/${participantId}/sensor_event?${queryParameters.toString()}`,
236
+ this.configuration
237
+ )
238
+ }
239
+ }
@@ -0,0 +1,96 @@
1
+ import { Fetch, Configuration } from "./Fetch"
2
+ import { Identifier } from "../model/Type"
3
+ import { SensorSpec } from "../model/SensorSpec"
4
+ import { Demo } from "./Demo"
5
+ import jsonata from "jsonata"
6
+
7
+ export class SensorSpecService {
8
+ public configuration?: Configuration
9
+
10
+ /**
11
+ * Get all SensorSpecs registered by any Researcher.
12
+ */
13
+ public async all(transform?: string): Promise<SensorSpec[]> {
14
+ if (this.configuration.base === "https://demo.lamp.digital") {
15
+ // DEMO
16
+ let output = Demo.SensorSpec.map(x => Object.assign(new SensorSpec(), x))
17
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
18
+ return Promise.resolve(output)
19
+ }
20
+ return (await Fetch.get<{ data: any[] }>(`/sensor_spec`, this.configuration)).data.map(x =>
21
+ Object.assign(new SensorSpec(), x)
22
+ )
23
+ }
24
+
25
+ /**
26
+ * Create a new SensorSpec.
27
+ * @param sensorSpec
28
+ */
29
+ public async create(sensorSpec: SensorSpec): Promise<Identifier> {
30
+ if (sensorSpec === null || sensorSpec === undefined)
31
+ throw new Error("Required parameter sensorSpec was null or undefined when calling sensorSpecCreate.")
32
+
33
+ if (this.configuration.base === "https://demo.lamp.digital") {
34
+ // DEMO
35
+ return Promise.resolve({ error: "500.demo-restriction" } as any)
36
+ }
37
+ return await Fetch.post(`/sensor_spec`, sensorSpec, this.configuration)
38
+ }
39
+
40
+ /**
41
+ * Delete an SensorSpec.
42
+ * @param sensorSpecName
43
+ */
44
+ public async delete(sensorSpecName: string): Promise<Identifier> {
45
+ if (sensorSpecName === null || sensorSpecName === undefined)
46
+ throw new Error("Required parameter sensorSpecName was null or undefined when calling sensorSpecDelete.")
47
+
48
+ if (this.configuration.base === "https://demo.lamp.digital") {
49
+ // DEMO
50
+ return Promise.resolve({ error: "500.demo-restriction" } as any)
51
+ }
52
+ return await Fetch.delete(`/sensor_spec/${sensorSpecName}`, this.configuration)
53
+ }
54
+
55
+ /**
56
+ * Update an SensorSpec.
57
+ * @param sensorSpecName
58
+ * @param sensorSpec
59
+ */
60
+ public async update(sensorSpecName: string, sensorSpec: SensorSpec): Promise<Identifier> {
61
+ if (sensorSpecName === null || sensorSpecName === undefined)
62
+ throw new Error("Required parameter sensorSpecName was null or undefined when calling sensorSpecUpdate.")
63
+ if (sensorSpec === null || sensorSpec === undefined)
64
+ throw new Error("Required parameter sensorSpec was null or undefined when calling sensorSpecUpdate.")
65
+
66
+ if (this.configuration.base === "https://demo.lamp.digital") {
67
+ // DEMO
68
+ return Promise.resolve({ error: "500.demo-restriction" } as any)
69
+ }
70
+ return await Fetch.put(`/sensor_spec/${sensorSpecName}`, sensorSpec, this.configuration)
71
+ }
72
+
73
+ /**
74
+ * Get a SensorSpec.
75
+ * @param sensorSpecName
76
+ */
77
+ public async view(sensorSpecName: string, transform?: string): Promise<SensorSpec> {
78
+ if (sensorSpecName === null || sensorSpecName === undefined)
79
+ throw new Error("Required parameter sensorSpecName was null or undefined when calling sensorSpecView.")
80
+
81
+ if (this.configuration.base === "https://demo.lamp.digital") {
82
+ // DEMO
83
+ let data = Demo.SensorSpec.filter(x => x["name"] === sensorSpecName).map(x => Object.assign(new SensorSpec(), x))
84
+ if (data.length > 0) {
85
+ let output = data[0]
86
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
87
+ return Promise.resolve(output)
88
+ } else {
89
+ return Promise.resolve({ error: "404.not-found" } as any)
90
+ }
91
+ }
92
+ return (await Fetch.get<{ data: any[] }>(`/sensor_spec/${sensorSpecName}`, this.configuration)).data.map(x =>
93
+ Object.assign(new SensorSpec(), x)
94
+ )[0]
95
+ }
96
+ }