@tokamakdev/plugin-location 0.1.0-beta.129 → 0.1.0-beta.131

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.
@@ -1,6 +1,7 @@
1
1
  // Generated by `tok plugin generate android`. Do not edit.
2
2
  package com.tokamak.plugins.location
3
3
 
4
+ import com.tokamak.runtime.TokamakCodec
4
5
  import com.tokamak.runtime.TokamakDispatch
5
6
  import com.tokamak.runtime.TokamakHost
6
7
  import com.tokamak.runtime.TokamakPluginBytesReply
@@ -10,7 +11,7 @@ import kotlin.reflect.KClass
10
11
  import org.json.JSONArray
11
12
  import org.json.JSONObject
12
13
 
13
- /** Routes the Worker's requests to the methods [TokamakLocationPlugin] exports, and encodes the events it emits. */
14
+ /** Routes the Worker's requests to the methods [TokamakLocationPlugin] exports. */
14
15
  class TokamakLocationPluginDispatch(host: TokamakHost) : TokamakDispatch<TokamakLocationPlugin>(TokamakLocationPlugin(host), host) {
15
16
  override fun callBytes(method: String, payload: ByteArray, reply: TokamakPluginBytesReply): (() -> Unit)? {
16
17
  val arguments by lazy(LazyThreadSafetyMode.NONE) { TokamakValue.arguments(payload) }
@@ -56,209 +57,212 @@ class TokamakLocationPluginDispatch(host: TokamakHost) : TokamakDispatch<Tokamak
56
57
  }
57
58
  }
58
59
 
59
- override fun eventPayload(name: String, event: Any): ByteArray =
60
- when (name) {
61
- "update" -> encodeEvent(name, event, LocationUpdate::class) { json(it) }
62
- "region" -> encodeEvent(name, event, RegionTransition::class) { json(it) }
63
- "error" -> encodeEvent(name, event, LocationErrorEvent::class) { json(it) }
64
- else -> super.eventPayload(name, event)
65
- }
60
+ /** Converts the values and events of [TokamakLocationPlugin] to and from JSON. */
61
+ companion object : TokamakCodec {
62
+ override fun eventPayload(name: String, event: Any): ByteArray =
63
+ when (name) {
64
+ "update" -> encodeEvent(name, event, LocationUpdate::class) { json(it) }
65
+ "region" -> encodeEvent(name, event, RegionTransition::class) { json(it) }
66
+ "error" -> encodeEvent(name, event, LocationErrorEvent::class) { json(it) }
67
+ else -> super.eventPayload(name, event)
68
+ }
66
69
 
67
- override fun encodeValue(value: Any): Any =
68
- when (value) {
69
- is Coordinates -> json(value)
70
- is LocationErrorEvent -> json(value)
71
- is LocationPermission -> json(value)
72
- is LocationUpdate -> json(value)
73
- is MonitoredRegion -> json(value)
74
- is PermissionRequest -> json(value)
75
- is Position -> json(value)
76
- is Region -> json(value)
77
- is RegionTransition -> json(value)
78
- is ServiceNotification -> json(value)
79
- is SetupConfig -> json(value)
80
- is UpdateOptions -> json(value)
81
- else -> super.encodeValue(value)
82
- }
70
+ override fun encodeValue(value: Any): Any =
71
+ when (value) {
72
+ is Coordinates -> json(value)
73
+ is LocationErrorEvent -> json(value)
74
+ is LocationPermission -> json(value)
75
+ is LocationUpdate -> json(value)
76
+ is MonitoredRegion -> json(value)
77
+ is PermissionRequest -> json(value)
78
+ is Position -> json(value)
79
+ is Region -> json(value)
80
+ is RegionTransition -> json(value)
81
+ is ServiceNotification -> json(value)
82
+ is SetupConfig -> json(value)
83
+ is UpdateOptions -> json(value)
84
+ else -> super.encodeValue(value)
85
+ }
83
86
 
84
- override fun decodeValue(json: TokamakValue, type: KClass<*>): Any =
85
- when (type) {
86
- Coordinates::class -> json.asCoordinates()
87
- LocationErrorEvent::class -> json.asLocationErrorEvent()
88
- LocationPermission::class -> json.asLocationPermission()
89
- LocationUpdate::class -> json.asLocationUpdate()
90
- MonitoredRegion::class -> json.asMonitoredRegion()
91
- PermissionRequest::class -> json.asPermissionRequest()
92
- Position::class -> json.asPosition()
93
- Region::class -> json.asRegion()
94
- RegionTransition::class -> json.asRegionTransition()
95
- ServiceNotification::class -> json.asServiceNotification()
96
- SetupConfig::class -> json.asSetupConfig()
97
- UpdateOptions::class -> json.asUpdateOptions()
98
- else -> super.decodeValue(json, type)
99
- }
87
+ override fun decodeValue(json: TokamakValue, type: KClass<*>): Any =
88
+ when (type) {
89
+ Coordinates::class -> json.asCoordinates()
90
+ LocationErrorEvent::class -> json.asLocationErrorEvent()
91
+ LocationPermission::class -> json.asLocationPermission()
92
+ LocationUpdate::class -> json.asLocationUpdate()
93
+ MonitoredRegion::class -> json.asMonitoredRegion()
94
+ PermissionRequest::class -> json.asPermissionRequest()
95
+ Position::class -> json.asPosition()
96
+ Region::class -> json.asRegion()
97
+ RegionTransition::class -> json.asRegionTransition()
98
+ ServiceNotification::class -> json.asServiceNotification()
99
+ SetupConfig::class -> json.asSetupConfig()
100
+ UpdateOptions::class -> json.asUpdateOptions()
101
+ else -> super.decodeValue(json, type)
102
+ }
100
103
 
101
- private fun TokamakValue.asCoordinates(): Coordinates =
102
- Coordinates(
103
- latitude = this["latitude"].double(),
104
- longitude = this["longitude"].double(),
105
- accuracy = this["accuracy"].double(),
106
- altitude = this["altitude"].nullable { it.double() },
107
- altitudeAccuracy = this["altitudeAccuracy"].nullable { it.double() },
108
- heading = this["heading"].nullable { it.double() },
109
- speed = this["speed"].nullable { it.double() },
110
- )
104
+ private fun TokamakValue.asCoordinates(): Coordinates =
105
+ Coordinates(
106
+ latitude = this["latitude"].double(),
107
+ longitude = this["longitude"].double(),
108
+ accuracy = this["accuracy"].double(),
109
+ altitude = this["altitude"].nullable { it.double() },
110
+ altitudeAccuracy = this["altitudeAccuracy"].nullable { it.double() },
111
+ heading = this["heading"].nullable { it.double() },
112
+ speed = this["speed"].nullable { it.double() },
113
+ )
111
114
 
112
- private fun json(value: Coordinates): JSONObject =
113
- JSONObject()
114
- .put("latitude", value.latitude)
115
- .put("longitude", value.longitude)
116
- .put("accuracy", value.accuracy)
117
- .putOpt("altitude", value.altitude)
118
- .putOpt("altitudeAccuracy", value.altitudeAccuracy)
119
- .putOpt("heading", value.heading)
120
- .putOpt("speed", value.speed)
115
+ private fun json(value: Coordinates): JSONObject =
116
+ JSONObject()
117
+ .put("latitude", value.latitude)
118
+ .put("longitude", value.longitude)
119
+ .put("accuracy", value.accuracy)
120
+ .putOpt("altitude", value.altitude)
121
+ .putOpt("altitudeAccuracy", value.altitudeAccuracy)
122
+ .putOpt("heading", value.heading)
123
+ .putOpt("speed", value.speed)
121
124
 
122
- private fun TokamakValue.asLocationErrorEvent(): LocationErrorEvent =
123
- LocationErrorEvent(
124
- name = this["name"].string(),
125
- message = this["message"].string(),
126
- )
125
+ private fun TokamakValue.asLocationErrorEvent(): LocationErrorEvent =
126
+ LocationErrorEvent(
127
+ name = this["name"].string(),
128
+ message = this["message"].string(),
129
+ )
127
130
 
128
- private fun json(value: LocationErrorEvent): JSONObject =
129
- JSONObject()
130
- .put("name", value.name)
131
- .put("message", value.message)
131
+ private fun json(value: LocationErrorEvent): JSONObject =
132
+ JSONObject()
133
+ .put("name", value.name)
134
+ .put("message", value.message)
132
135
 
133
- private fun TokamakValue.asLocationPermission(): LocationPermission =
134
- LocationPermission(
135
- inUse = this["inUse"].enum(Permission.entries),
136
- background = this["background"].enum(Permission.entries),
137
- precision = this["precision"].enum(Precision.entries),
138
- )
136
+ private fun TokamakValue.asLocationPermission(): LocationPermission =
137
+ LocationPermission(
138
+ inUse = this["inUse"].enum(Permission.entries),
139
+ background = this["background"].enum(Permission.entries),
140
+ precision = this["precision"].enum(Precision.entries),
141
+ )
139
142
 
140
- private fun json(value: LocationPermission): JSONObject =
141
- JSONObject()
142
- .put("inUse", value.inUse.name)
143
- .put("background", value.background.name)
144
- .put("precision", value.precision.name)
143
+ private fun json(value: LocationPermission): JSONObject =
144
+ JSONObject()
145
+ .put("inUse", value.inUse.name)
146
+ .put("background", value.background.name)
147
+ .put("precision", value.precision.name)
145
148
 
146
- private fun TokamakValue.asLocationUpdate(): LocationUpdate =
147
- LocationUpdate(
148
- positions = this["positions"].list { it.asPosition() },
149
- )
149
+ private fun TokamakValue.asLocationUpdate(): LocationUpdate =
150
+ LocationUpdate(
151
+ positions = this["positions"].list { it.asPosition() },
152
+ )
150
153
 
151
- private fun json(value: LocationUpdate): JSONObject =
152
- JSONObject()
153
- .put("positions", JSONArray(value.positions.map { json(it) }))
154
+ private fun json(value: LocationUpdate): JSONObject =
155
+ JSONObject()
156
+ .put("positions", JSONArray(value.positions.map { json(it) }))
154
157
 
155
- private fun TokamakValue.asMonitoredRegion(): MonitoredRegion =
156
- MonitoredRegion(
157
- id = this["id"].string(),
158
- latitude = this["latitude"].double(),
159
- longitude = this["longitude"].double(),
160
- radius = this["radius"].double(),
161
- onEntry = this["onEntry"].boolean(),
162
- onExit = this["onExit"].boolean(),
163
- )
158
+ private fun TokamakValue.asMonitoredRegion(): MonitoredRegion =
159
+ MonitoredRegion(
160
+ id = this["id"].string(),
161
+ latitude = this["latitude"].double(),
162
+ longitude = this["longitude"].double(),
163
+ radius = this["radius"].double(),
164
+ onEntry = this["onEntry"].boolean(),
165
+ onExit = this["onExit"].boolean(),
166
+ )
164
167
 
165
- private fun json(value: MonitoredRegion): JSONObject =
166
- JSONObject()
167
- .put("id", value.id)
168
- .put("latitude", value.latitude)
169
- .put("longitude", value.longitude)
170
- .put("radius", value.radius)
171
- .put("onEntry", value.onEntry)
172
- .put("onExit", value.onExit)
168
+ private fun json(value: MonitoredRegion): JSONObject =
169
+ JSONObject()
170
+ .put("id", value.id)
171
+ .put("latitude", value.latitude)
172
+ .put("longitude", value.longitude)
173
+ .put("radius", value.radius)
174
+ .put("onEntry", value.onEntry)
175
+ .put("onExit", value.onExit)
173
176
 
174
- private fun TokamakValue.asPermissionRequest(): PermissionRequest =
175
- PermissionRequest(
176
- background = this["background"].nullable { it.boolean() },
177
- precision = this["precision"].nullable { it.enum(Precision.entries) },
178
- )
177
+ private fun TokamakValue.asPermissionRequest(): PermissionRequest =
178
+ PermissionRequest(
179
+ background = this["background"].nullable { it.boolean() },
180
+ precision = this["precision"].nullable { it.enum(Precision.entries) },
181
+ )
179
182
 
180
- private fun json(value: PermissionRequest): JSONObject =
181
- JSONObject()
182
- .putOpt("background", value.background)
183
- .putOpt("precision", value.precision?.name)
183
+ private fun json(value: PermissionRequest): JSONObject =
184
+ JSONObject()
185
+ .putOpt("background", value.background)
186
+ .putOpt("precision", value.precision?.name)
184
187
 
185
- private fun TokamakValue.asPosition(): Position =
186
- Position(
187
- coords = this["coords"].asCoordinates(),
188
- timestamp = this["timestamp"].long(),
189
- )
188
+ private fun TokamakValue.asPosition(): Position =
189
+ Position(
190
+ coords = this["coords"].asCoordinates(),
191
+ timestamp = this["timestamp"].long(),
192
+ )
190
193
 
191
- private fun json(value: Position): JSONObject =
192
- JSONObject()
193
- .put("coords", json(value.coords))
194
- .put("timestamp", value.timestamp)
194
+ private fun json(value: Position): JSONObject =
195
+ JSONObject()
196
+ .put("coords", json(value.coords))
197
+ .put("timestamp", value.timestamp)
195
198
 
196
- private fun TokamakValue.asRegion(): Region =
197
- Region(
198
- id = this["id"].string(),
199
- latitude = this["latitude"].double(),
200
- longitude = this["longitude"].double(),
201
- radius = this["radius"].double(),
202
- onEntry = this["onEntry"].nullable { it.boolean() },
203
- onExit = this["onExit"].nullable { it.boolean() },
204
- )
199
+ private fun TokamakValue.asRegion(): Region =
200
+ Region(
201
+ id = this["id"].string(),
202
+ latitude = this["latitude"].double(),
203
+ longitude = this["longitude"].double(),
204
+ radius = this["radius"].double(),
205
+ onEntry = this["onEntry"].nullable { it.boolean() },
206
+ onExit = this["onExit"].nullable { it.boolean() },
207
+ )
205
208
 
206
- private fun json(value: Region): JSONObject =
207
- JSONObject()
208
- .put("id", value.id)
209
- .put("latitude", value.latitude)
210
- .put("longitude", value.longitude)
211
- .put("radius", value.radius)
212
- .putOpt("onEntry", value.onEntry)
213
- .putOpt("onExit", value.onExit)
209
+ private fun json(value: Region): JSONObject =
210
+ JSONObject()
211
+ .put("id", value.id)
212
+ .put("latitude", value.latitude)
213
+ .put("longitude", value.longitude)
214
+ .put("radius", value.radius)
215
+ .putOpt("onEntry", value.onEntry)
216
+ .putOpt("onExit", value.onExit)
214
217
 
215
- private fun TokamakValue.asRegionTransition(): RegionTransition =
216
- RegionTransition(
217
- id = this["id"].string(),
218
- transition = this["transition"].enum(Transition.entries),
219
- timestamp = this["timestamp"].long(),
220
- )
218
+ private fun TokamakValue.asRegionTransition(): RegionTransition =
219
+ RegionTransition(
220
+ id = this["id"].string(),
221
+ transition = this["transition"].enum(Transition.entries),
222
+ timestamp = this["timestamp"].long(),
223
+ )
221
224
 
222
- private fun json(value: RegionTransition): JSONObject =
223
- JSONObject()
224
- .put("id", value.id)
225
- .put("transition", value.transition.name)
226
- .put("timestamp", value.timestamp)
225
+ private fun json(value: RegionTransition): JSONObject =
226
+ JSONObject()
227
+ .put("id", value.id)
228
+ .put("transition", value.transition.name)
229
+ .put("timestamp", value.timestamp)
227
230
 
228
- private fun TokamakValue.asServiceNotification(): ServiceNotification =
229
- ServiceNotification(
230
- title = this["title"].string(),
231
- body = this["body"].string(),
232
- channel = this["channel"].string(),
233
- )
231
+ private fun TokamakValue.asServiceNotification(): ServiceNotification =
232
+ ServiceNotification(
233
+ title = this["title"].string(),
234
+ body = this["body"].string(),
235
+ channel = this["channel"].string(),
236
+ )
234
237
 
235
- private fun json(value: ServiceNotification): JSONObject =
236
- JSONObject()
237
- .put("title", value.title)
238
- .put("body", value.body)
239
- .put("channel", value.channel)
238
+ private fun json(value: ServiceNotification): JSONObject =
239
+ JSONObject()
240
+ .put("title", value.title)
241
+ .put("body", value.body)
242
+ .put("channel", value.channel)
240
243
 
241
- private fun TokamakValue.asSetupConfig(): SetupConfig =
242
- SetupConfig(
243
- significantChanges = this["significantChanges"].nullable { it.boolean() },
244
- )
244
+ private fun TokamakValue.asSetupConfig(): SetupConfig =
245
+ SetupConfig(
246
+ significantChanges = this["significantChanges"].nullable { it.boolean() },
247
+ )
245
248
 
246
- private fun json(value: SetupConfig): JSONObject =
247
- JSONObject()
248
- .putOpt("significantChanges", value.significantChanges)
249
+ private fun json(value: SetupConfig): JSONObject =
250
+ JSONObject()
251
+ .putOpt("significantChanges", value.significantChanges)
249
252
 
250
- private fun TokamakValue.asUpdateOptions(): UpdateOptions =
251
- UpdateOptions(
252
- accuracy = this["accuracy"].nullable { it.enum(Accuracy.entries) },
253
- distance = this["distance"].nullable { it.double() },
254
- interval = this["interval"].nullable { it.long() },
255
- foregroundService = this["foregroundService"].nullable { it.asServiceNotification() },
256
- )
253
+ private fun TokamakValue.asUpdateOptions(): UpdateOptions =
254
+ UpdateOptions(
255
+ accuracy = this["accuracy"].nullable { it.enum(Accuracy.entries) },
256
+ distance = this["distance"].nullable { it.double() },
257
+ interval = this["interval"].nullable { it.long() },
258
+ foregroundService = this["foregroundService"].nullable { it.asServiceNotification() },
259
+ )
257
260
 
258
- private fun json(value: UpdateOptions): JSONObject =
259
- JSONObject()
260
- .putOpt("accuracy", value.accuracy?.name)
261
- .putOpt("distance", value.distance)
262
- .putOpt("interval", value.interval)
263
- .putOpt("foregroundService", value.foregroundService?.let { json(it) })
261
+ private fun json(value: UpdateOptions): JSONObject =
262
+ JSONObject()
263
+ .putOpt("accuracy", value.accuracy?.name)
264
+ .putOpt("distance", value.distance)
265
+ .putOpt("interval", value.interval)
266
+ .putOpt("foregroundService", value.foregroundService?.let { json(it) })
267
+ }
264
268
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokamakdev/plugin-location",
3
- "version": "0.1.0-beta.129",
3
+ "version": "0.1.0-beta.131",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/mantty/tokamak.git",
@@ -14,7 +14,7 @@
14
14
  "./events": "./src/events.ts"
15
15
  },
16
16
  "peerDependencies": {
17
- "@tokamakdev/plugin": "0.1.0-beta.129"
17
+ "@tokamakdev/plugin": "0.1.0-beta.131"
18
18
  },
19
19
  "files": [
20
20
  "android",