@xyo-network/location-plugin 2.42.0

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 (41) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +80 -0
  3. package/dist/cjs/CurrentLocationPayloadSet.d.ts +3 -0
  4. package/dist/cjs/CurrentLocationPayloadSet.d.ts.map +1 -0
  5. package/dist/cjs/CurrentLocationPayloadSet.js +15 -0
  6. package/dist/cjs/CurrentLocationPayloadSet.js.map +1 -0
  7. package/dist/cjs/CurrentLocationWitness.d.ts +21 -0
  8. package/dist/cjs/CurrentLocationWitness.d.ts.map +1 -0
  9. package/dist/cjs/CurrentLocationWitness.js +64 -0
  10. package/dist/cjs/CurrentLocationWitness.js.map +1 -0
  11. package/dist/cjs/Plugin.d.ts +15 -0
  12. package/dist/cjs/Plugin.d.ts.map +1 -0
  13. package/dist/cjs/Plugin.js +16 -0
  14. package/dist/cjs/Plugin.js.map +1 -0
  15. package/dist/cjs/index.d.ts +6 -0
  16. package/dist/cjs/index.d.ts.map +1 -0
  17. package/dist/cjs/index.js +11 -0
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/docs.json +4638 -0
  20. package/dist/esm/CurrentLocationPayloadSet.d.ts +3 -0
  21. package/dist/esm/CurrentLocationPayloadSet.d.ts.map +1 -0
  22. package/dist/esm/CurrentLocationPayloadSet.js +12 -0
  23. package/dist/esm/CurrentLocationPayloadSet.js.map +1 -0
  24. package/dist/esm/CurrentLocationWitness.d.ts +21 -0
  25. package/dist/esm/CurrentLocationWitness.d.ts.map +1 -0
  26. package/dist/esm/CurrentLocationWitness.js +48 -0
  27. package/dist/esm/CurrentLocationWitness.js.map +1 -0
  28. package/dist/esm/Plugin.d.ts +15 -0
  29. package/dist/esm/Plugin.d.ts.map +1 -0
  30. package/dist/esm/Plugin.js +11 -0
  31. package/dist/esm/Plugin.js.map +1 -0
  32. package/dist/esm/index.d.ts +6 -0
  33. package/dist/esm/index.d.ts.map +1 -0
  34. package/dist/esm/index.js +7 -0
  35. package/dist/esm/index.js.map +1 -0
  36. package/package.json +55 -0
  37. package/src/CurrentLocationPayloadSet.ts +12 -0
  38. package/src/CurrentLocationWitness.ts +67 -0
  39. package/src/Plugin.spec.ts +25 -0
  40. package/src/Plugin.ts +17 -0
  41. package/src/index.ts +9 -0
@@ -0,0 +1,3 @@
1
+ import { PayloadSetPayload } from '@xyo-network/payload';
2
+ export declare const CurrentLocationPayloadSet: PayloadSetPayload;
3
+ //# sourceMappingURL=CurrentLocationPayloadSet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CurrentLocationPayloadSet.d.ts","sourceRoot":"","sources":["../../src/CurrentLocationPayloadSet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAoB,MAAM,sBAAsB,CAAA;AAE1E,eAAO,MAAM,yBAAyB,EAAE,iBAQvC,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { LocationHeadingSchema, LocationSchema } from '@xyo-network/location-payload-plugin';
2
+ import { PayloadSetSchema } from '@xyo-network/payload';
3
+ export const CurrentLocationPayloadSet = {
4
+ optional: {
5
+ [LocationHeadingSchema]: 1,
6
+ },
7
+ required: {
8
+ [LocationSchema]: 1,
9
+ },
10
+ schema: PayloadSetSchema,
11
+ };
12
+ //# sourceMappingURL=CurrentLocationPayloadSet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CurrentLocationPayloadSet.js","sourceRoot":"","sources":["../../src/CurrentLocationPayloadSet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAA;AAC5F,OAAO,EAAqB,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAE1E,MAAM,CAAC,MAAM,yBAAyB,GAAsB;IAC1D,QAAQ,EAAE;QACR,CAAC,qBAAqB,CAAC,EAAE,CAAC;KAC3B;IACD,QAAQ,EAAE;QACR,CAAC,cAAc,CAAC,EAAE,CAAC;KACpB;IACD,MAAM,EAAE,gBAAgB;CACzB,CAAA"}
@@ -0,0 +1,21 @@
1
+ import { XyoModuleParams } from '@xyo-network/module';
2
+ import { XyoPayload } from '@xyo-network/payload';
3
+ import { AbstractWitness, XyoWitnessConfig } from '@xyo-network/witness';
4
+ export type CurrentLocationWitnessConfigSchema = 'network.xyo.location.current.config';
5
+ export declare const CurrentLocationWitnessConfigSchema: CurrentLocationWitnessConfigSchema;
6
+ export type CurrentLocationWitnessConfig = XyoWitnessConfig<{
7
+ schema: CurrentLocationWitnessConfigSchema;
8
+ }>;
9
+ export type CurrentLocationWitnessParams = XyoModuleParams<CurrentLocationWitnessConfig> & {
10
+ geolocation: Geolocation;
11
+ };
12
+ export declare class CurrentLocationWitness extends AbstractWitness<CurrentLocationWitnessConfig> {
13
+ static configSchema: "network.xyo.location.current.config";
14
+ private _geolocation;
15
+ constructor(params: CurrentLocationWitnessParams);
16
+ get geolocation(): Geolocation;
17
+ static create(params?: XyoModuleParams<CurrentLocationWitnessConfig>): Promise<CurrentLocationWitness>;
18
+ getCurrentPosition(): Promise<GeolocationPosition>;
19
+ observe(_fields: XyoPayload[]): Promise<XyoPayload[]>;
20
+ }
21
+ //# sourceMappingURL=CurrentLocationWitness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CurrentLocationWitness.d.ts","sourceRoot":"","sources":["../../src/CurrentLocationWitness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAExE,MAAM,MAAM,kCAAkC,GAAG,qCAAqC,CAAA;AACtF,eAAO,MAAM,kCAAkC,EAAE,kCAA0E,CAAA;AAE3H,MAAM,MAAM,4BAA4B,GAAG,gBAAgB,CAAC;IAC1D,MAAM,EAAE,kCAAkC,CAAA;CAC3C,CAAC,CAAA;AAEF,MAAM,MAAM,4BAA4B,GAAG,eAAe,CAAC,4BAA4B,CAAC,GAAG;IAAE,WAAW,EAAE,WAAW,CAAA;CAAE,CAAA;AAEvH,qBAAa,sBAAuB,SAAQ,eAAe,CAAC,4BAA4B,CAAC;IACvF,OAAgB,YAAY,wCAAqC;IAEjE,OAAO,CAAC,YAAY,CAAa;gBAErB,MAAM,EAAE,4BAA4B;IAKhD,IAAW,WAAW,IAAI,WAAW,CAEpC;WAEqB,MAAM,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC,4BAA4B,CAAC,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAI9G,kBAAkB;IAaV,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;CAoBrE"}
@@ -0,0 +1,48 @@
1
+ import { assertEx } from '@xylabs/assert';
2
+ import { LocationHeadingSchema, LocationSchema } from '@xyo-network/location-payload-plugin';
3
+ import { AbstractWitness } from '@xyo-network/witness';
4
+ export const CurrentLocationWitnessConfigSchema = 'network.xyo.location.current.config';
5
+ export class CurrentLocationWitness extends AbstractWitness {
6
+ static configSchema = CurrentLocationWitnessConfigSchema;
7
+ _geolocation;
8
+ constructor(params) {
9
+ super(params);
10
+ this._geolocation = params?.geolocation;
11
+ }
12
+ get geolocation() {
13
+ return assertEx(this._geolocation, 'No geolocation provided');
14
+ }
15
+ static async create(params) {
16
+ return (await super.create(params));
17
+ }
18
+ getCurrentPosition() {
19
+ return new Promise((resolve, reject) => {
20
+ this.geolocation?.getCurrentPosition((position) => {
21
+ resolve(position);
22
+ }, (error) => {
23
+ reject(error);
24
+ });
25
+ });
26
+ }
27
+ async observe(_fields) {
28
+ const location = await this.getCurrentPosition();
29
+ const locationPayload = {
30
+ altitude: location.coords.altitude ?? undefined,
31
+ altitudeAccuracy: location.coords.altitudeAccuracy ?? undefined,
32
+ latitude: location.coords.latitude,
33
+ longitude: location.coords.longitude,
34
+ schema: LocationSchema,
35
+ };
36
+ const heading = location.coords.heading
37
+ ? [
38
+ {
39
+ heading: location.coords.heading ?? undefined,
40
+ schema: LocationHeadingSchema,
41
+ speed: location.coords.speed ?? undefined,
42
+ },
43
+ ]
44
+ : [];
45
+ return super.observe([locationPayload, ...heading]);
46
+ }
47
+ }
48
+ //# sourceMappingURL=CurrentLocationWitness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CurrentLocationWitness.js","sourceRoot":"","sources":["../../src/CurrentLocationWitness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAA0B,qBAAqB,EAAmB,cAAc,EAAE,MAAM,sCAAsC,CAAA;AAGrI,OAAO,EAAE,eAAe,EAAoB,MAAM,sBAAsB,CAAA;AAGxE,MAAM,CAAC,MAAM,kCAAkC,GAAuC,qCAAqC,CAAA;AAQ3H,MAAM,OAAO,sBAAuB,SAAQ,eAA6C;IACvF,MAAM,CAAU,YAAY,GAAG,kCAAkC,CAAA;IAEzD,YAAY,CAAa;IAEjC,YAAY,MAAoC;QAC9C,KAAK,CAAC,MAAM,CAAC,CAAA;QACb,IAAI,CAAC,YAAY,GAAG,MAAM,EAAE,WAAW,CAAA;IACzC,CAAC;IAED,IAAW,WAAW;QACpB,OAAO,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,yBAAyB,CAAC,CAAA;IAC/D,CAAC;IAED,MAAM,CAAU,KAAK,CAAC,MAAM,CAAC,MAAsD;QACjF,OAAO,CAAC,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAA2B,CAAA;IAC/D,CAAC;IAEM,kBAAkB;QACvB,OAAO,IAAI,OAAO,CAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC1D,IAAI,CAAC,WAAW,EAAE,kBAAkB,CAClC,CAAC,QAA6B,EAAE,EAAE;gBAChC,OAAO,CAAC,QAAQ,CAAC,CAAA;YACnB,CAAC,EACD,CAAC,KAA+B,EAAE,EAAE;gBAClC,MAAM,CAAC,KAAK,CAAC,CAAA;YACf,CAAC,CACF,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAEQ,KAAK,CAAC,OAAO,CAAC,OAAqB;QAC1C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAA;QAChD,MAAM,eAAe,GAAoB;YACvC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,IAAI,SAAS;YAC/C,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,gBAAgB,IAAI,SAAS;YAC/D,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ;YAClC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS;YACpC,MAAM,EAAE,cAAc;SACvB,CAAA;QACD,MAAM,OAAO,GAA6B,QAAQ,CAAC,MAAM,CAAC,OAAO;YAC/D,CAAC,CAAC;gBACE;oBACE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,IAAI,SAAS;oBAC7C,MAAM,EAAE,qBAAqB;oBAC7B,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,IAAI,SAAS;iBAC1C;aACF;YACH,CAAC,CAAC,EAAE,CAAA;QACN,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,eAAe,EAAE,GAAG,OAAO,CAAC,CAAC,CAAA;IACrD,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { XyoModuleParams } from '@xyo-network/module';
2
+ import { PayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin';
3
+ export declare const LocationPlugin: () => PayloadSetWitnessPlugin<XyoModuleParams<import("@xyo-network/payload").SchemaFields & import("@xyo-network/payload").PayloadFields & {
4
+ security?: {
5
+ allowed?: Record<string, string[][]> | undefined;
6
+ disallowed?: Record<string, string[]> | undefined;
7
+ } | undefined;
8
+ } & {
9
+ schema: "network.xyo.location.current.config";
10
+ } & {
11
+ targetSet?: (import("@xyo-network/payload").SchemaFields & import("@xyo-network/payload").PayloadFields & import("@xyo-network/payload").PayloadSet & {
12
+ schema: "network.xyo.payload.set";
13
+ }) | undefined;
14
+ }>>;
15
+ //# sourceMappingURL=Plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD,OAAO,EAA0B,uBAAuB,EAAE,MAAM,gCAAgC,CAAA;AAIhG,eAAO,MAAM,cAAc;;;;;;;;;;;GASxB,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { LocationSchema } from '@xyo-network/location-payload-plugin';
2
+ import { PayloadSetSchema } from '@xyo-network/payload';
3
+ import { createPayloadSetPlugin } from '@xyo-network/payloadset-plugin';
4
+ import { CurrentLocationWitness } from './CurrentLocationWitness';
5
+ export const LocationPlugin = () => createPayloadSetPlugin({ required: { [LocationSchema]: 1 }, schema: PayloadSetSchema }, {
6
+ witness: async (params) => {
7
+ const result = await CurrentLocationWitness.create(params);
8
+ return result;
9
+ },
10
+ });
11
+ //# sourceMappingURL=Plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plugin.js","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAA;AAErE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,sBAAsB,EAA2B,MAAM,gCAAgC,CAAA;AAEhG,OAAO,EAAE,sBAAsB,EAAgC,MAAM,0BAA0B,CAAA;AAE/F,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE,CACjC,sBAAsB,CACpB,EAAE,QAAQ,EAAE,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAC/D;IACE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QACxB,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAC1D,OAAO,MAAM,CAAA;IACf,CAAC;CACF,CACF,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { LocationPlugin } from './Plugin';
2
+ export * from './CurrentLocationPayloadSet';
3
+ export * from './CurrentLocationWitness';
4
+ export { LocationPlugin };
5
+ export default LocationPlugin;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAEzC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,0BAA0B,CAAA;AAExC,OAAO,EAAE,cAAc,EAAE,CAAA;AAGzB,eAAe,cAAc,CAAA"}
@@ -0,0 +1,7 @@
1
+ import { LocationPlugin } from './Plugin';
2
+ export * from './CurrentLocationPayloadSet';
3
+ export * from './CurrentLocationWitness';
4
+ export { LocationPlugin };
5
+ // eslint-disable-next-line import/no-default-export
6
+ export default LocationPlugin;
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAEzC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,0BAA0B,CAAA;AAExC,OAAO,EAAE,cAAc,EAAE,CAAA;AAEzB,oDAAoD;AACpD,eAAe,cAAc,CAAA"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@xyo-network/location-plugin",
3
+ "author": {
4
+ "email": "support@xyo.network",
5
+ "name": "XYO Development Team",
6
+ "url": "https://xyo.network"
7
+ },
8
+ "bugs": {
9
+ "email": "support@xyo.network",
10
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
+ },
12
+ "dependencies": {
13
+ "@xylabs/assert": "^2.6.9",
14
+ "@xyo-network/location-payload-plugin": "^2.42.0",
15
+ "@xyo-network/module": "^2.42.0",
16
+ "@xyo-network/payload": "^2.42.0",
17
+ "@xyo-network/payloadset-plugin": "^2.42.0",
18
+ "@xyo-network/witness": "^2.42.0",
19
+ "tslib": "^2.4.1"
20
+ },
21
+ "description": "Primary SDK for using XYO Protocol 2.0",
22
+ "browser": "dist/esm/index.js",
23
+ "docs": "dist/docs.json",
24
+ "exports": {
25
+ ".": {
26
+ "node": {
27
+ "import": "./dist/esm/index.js",
28
+ "require": "./dist/cjs/index.js"
29
+ },
30
+ "browser": {
31
+ "import": "./dist/esm/index.js",
32
+ "require": "./dist/cjs/index.js"
33
+ },
34
+ "default": "./dist/esm/index.js"
35
+ },
36
+ "./dist/docs.json": {
37
+ "default": "./dist/docs.json"
38
+ },
39
+ "./package.json": "./package.json"
40
+ },
41
+ "main": "dist/cjs/index.js",
42
+ "module": "dist/esm/index.js",
43
+ "homepage": "https://xyo.network",
44
+ "license": "LGPL-3.0-only",
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
51
+ },
52
+ "sideEffects": false,
53
+ "types": "dist/esm/index.d.ts",
54
+ "version": "2.42.0"
55
+ }
@@ -0,0 +1,12 @@
1
+ import { LocationHeadingSchema, LocationSchema } from '@xyo-network/location-payload-plugin'
2
+ import { PayloadSetPayload, PayloadSetSchema } from '@xyo-network/payload'
3
+
4
+ export const CurrentLocationPayloadSet: PayloadSetPayload = {
5
+ optional: {
6
+ [LocationHeadingSchema]: 1,
7
+ },
8
+ required: {
9
+ [LocationSchema]: 1,
10
+ },
11
+ schema: PayloadSetSchema,
12
+ }
@@ -0,0 +1,67 @@
1
+ import { assertEx } from '@xylabs/assert'
2
+ import { LocationHeadingPayload, LocationHeadingSchema, LocationPayload, LocationSchema } from '@xyo-network/location-payload-plugin'
3
+ import { XyoModuleParams } from '@xyo-network/module'
4
+ import { XyoPayload } from '@xyo-network/payload'
5
+ import { AbstractWitness, XyoWitnessConfig } from '@xyo-network/witness'
6
+
7
+ export type CurrentLocationWitnessConfigSchema = 'network.xyo.location.current.config'
8
+ export const CurrentLocationWitnessConfigSchema: CurrentLocationWitnessConfigSchema = 'network.xyo.location.current.config'
9
+
10
+ export type CurrentLocationWitnessConfig = XyoWitnessConfig<{
11
+ schema: CurrentLocationWitnessConfigSchema
12
+ }>
13
+
14
+ export type CurrentLocationWitnessParams = XyoModuleParams<CurrentLocationWitnessConfig> & { geolocation: Geolocation }
15
+
16
+ export class CurrentLocationWitness extends AbstractWitness<CurrentLocationWitnessConfig> {
17
+ static override configSchema = CurrentLocationWitnessConfigSchema
18
+
19
+ private _geolocation: Geolocation
20
+
21
+ constructor(params: CurrentLocationWitnessParams) {
22
+ super(params)
23
+ this._geolocation = params?.geolocation
24
+ }
25
+
26
+ public get geolocation(): Geolocation {
27
+ return assertEx(this._geolocation, 'No geolocation provided')
28
+ }
29
+
30
+ static override async create(params?: XyoModuleParams<CurrentLocationWitnessConfig>): Promise<CurrentLocationWitness> {
31
+ return (await super.create(params)) as CurrentLocationWitness
32
+ }
33
+
34
+ public getCurrentPosition() {
35
+ return new Promise<GeolocationPosition>((resolve, reject) => {
36
+ this.geolocation?.getCurrentPosition(
37
+ (position: GeolocationPosition) => {
38
+ resolve(position)
39
+ },
40
+ (error: GeolocationPositionError) => {
41
+ reject(error)
42
+ },
43
+ )
44
+ })
45
+ }
46
+
47
+ override async observe(_fields: XyoPayload[]): Promise<XyoPayload[]> {
48
+ const location = await this.getCurrentPosition()
49
+ const locationPayload: LocationPayload = {
50
+ altitude: location.coords.altitude ?? undefined,
51
+ altitudeAccuracy: location.coords.altitudeAccuracy ?? undefined,
52
+ latitude: location.coords.latitude,
53
+ longitude: location.coords.longitude,
54
+ schema: LocationSchema,
55
+ }
56
+ const heading: LocationHeadingPayload[] = location.coords.heading
57
+ ? [
58
+ {
59
+ heading: location.coords.heading ?? undefined,
60
+ schema: LocationHeadingSchema,
61
+ speed: location.coords.speed ?? undefined,
62
+ },
63
+ ]
64
+ : []
65
+ return super.observe([locationPayload, ...heading])
66
+ }
67
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+
5
+ import { CurrentLocationSchema } from '@xyo-network/location-payload-plugin'
6
+ import { PayloadSetPluginResolver } from '@xyo-network/payloadset-plugin'
7
+
8
+ import { CurrentLocationWitnessConfigSchema } from './CurrentLocationWitness'
9
+ import { LocationPlugin } from './Plugin'
10
+
11
+ describe('LocationPlugin', () => {
12
+ test('Add to Resolver', () => {
13
+ const plugin = LocationPlugin()
14
+ const resolver = new PayloadSetPluginResolver().register(plugin, {
15
+ witness: {
16
+ config: {
17
+ schema: CurrentLocationWitnessConfigSchema,
18
+ },
19
+ geolocation: navigator.geolocation,
20
+ },
21
+ })
22
+ expect(resolver.resolve(plugin.set)).toBeObject()
23
+ expect(resolver.witness(CurrentLocationSchema)).toBeObject()
24
+ })
25
+ })
package/src/Plugin.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { LocationSchema } from '@xyo-network/location-payload-plugin'
2
+ import { XyoModuleParams } from '@xyo-network/module'
3
+ import { PayloadSetSchema } from '@xyo-network/payload'
4
+ import { createPayloadSetPlugin, PayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'
5
+
6
+ import { CurrentLocationWitness, CurrentLocationWitnessConfig } from './CurrentLocationWitness'
7
+
8
+ export const LocationPlugin = () =>
9
+ createPayloadSetPlugin<PayloadSetWitnessPlugin<XyoModuleParams<CurrentLocationWitnessConfig>>>(
10
+ { required: { [LocationSchema]: 1 }, schema: PayloadSetSchema },
11
+ {
12
+ witness: async (params) => {
13
+ const result = await CurrentLocationWitness.create(params)
14
+ return result
15
+ },
16
+ },
17
+ )
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { LocationPlugin } from './Plugin'
2
+
3
+ export * from './CurrentLocationPayloadSet'
4
+ export * from './CurrentLocationWitness'
5
+
6
+ export { LocationPlugin }
7
+
8
+ // eslint-disable-next-line import/no-default-export
9
+ export default LocationPlugin