@xyo-network/location-certainty-plugin 2.73.2 → 2.73.4

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 (39) hide show
  1. package/dist/docs.json +53 -53
  2. package/dist/index.d.mts +82 -0
  3. package/dist/index.d.ts +82 -0
  4. package/dist/index.js +128 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +99 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +38 -25
  9. package/tsup.config.ts +16 -0
  10. package/dist/cjs/Diviner/Config.js +0 -5
  11. package/dist/cjs/Diviner/Config.js.map +0 -1
  12. package/dist/cjs/Diviner/Diviner.js +0 -77
  13. package/dist/cjs/Diviner/Diviner.js.map +0 -1
  14. package/dist/cjs/Diviner/index.js +0 -6
  15. package/dist/cjs/Diviner/index.js.map +0 -1
  16. package/dist/cjs/Plugin.js +0 -15
  17. package/dist/cjs/Plugin.js.map +0 -1
  18. package/dist/cjs/index.js +0 -10
  19. package/dist/cjs/index.js.map +0 -1
  20. package/dist/esm/Diviner/Config.js +0 -2
  21. package/dist/esm/Diviner/Config.js.map +0 -1
  22. package/dist/esm/Diviner/Diviner.js +0 -69
  23. package/dist/esm/Diviner/Diviner.js.map +0 -1
  24. package/dist/esm/Diviner/index.js +0 -3
  25. package/dist/esm/Diviner/index.js.map +0 -1
  26. package/dist/esm/Plugin.js +0 -10
  27. package/dist/esm/Plugin.js.map +0 -1
  28. package/dist/esm/index.js +0 -6
  29. package/dist/esm/index.js.map +0 -1
  30. package/dist/types/Diviner/Config.d.ts +0 -10
  31. package/dist/types/Diviner/Config.d.ts.map +0 -1
  32. package/dist/types/Diviner/Diviner.d.ts +0 -15
  33. package/dist/types/Diviner/Diviner.d.ts.map +0 -1
  34. package/dist/types/Diviner/index.d.ts +0 -3
  35. package/dist/types/Diviner/index.d.ts.map +0 -1
  36. package/dist/types/Plugin.d.ts +0 -53
  37. package/dist/types/Plugin.d.ts.map +0 -1
  38. package/dist/types/index.d.ts +0 -5
  39. package/dist/types/index.d.ts.map +0 -1
package/dist/index.js ADDED
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ LocationCertaintyDiviner: () => LocationCertaintyDiviner,
24
+ LocationCertaintyDivinerConfigSchema: () => LocationCertaintyDivinerConfigSchema,
25
+ LocationCertaintyPlugin: () => LocationCertaintyPlugin,
26
+ default: () => src_default
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
29
+
30
+ // src/Plugin.ts
31
+ var import_location_certainty_payload_plugin2 = require("@xyo-network/location-certainty-payload-plugin");
32
+ var import_payload_model = require("@xyo-network/payload-model");
33
+ var import_payloadset_plugin = require("@xyo-network/payloadset-plugin");
34
+
35
+ // src/Diviner/Config.ts
36
+ var LocationCertaintyDivinerConfigSchema = "network.xyo.location.elevation.diviner.config";
37
+
38
+ // src/Diviner/Diviner.ts
39
+ var import_abstract_diviner = require("@xyo-network/abstract-diviner");
40
+ var import_elevation_plugin = require("@xyo-network/elevation-plugin");
41
+ var import_location_certainty_payload_plugin = require("@xyo-network/location-certainty-payload-plugin");
42
+ var import_location_payload_plugin = require("@xyo-network/location-payload-plugin");
43
+ var import_payload_builder = require("@xyo-network/payload-builder");
44
+ var LocationCertaintyDiviner = class _LocationCertaintyDiviner extends import_abstract_diviner.AbstractDiviner {
45
+ static configSchemas = [LocationCertaintyDivinerConfigSchema];
46
+ static targetSchema = import_location_certainty_payload_plugin.LocationCertaintySchema;
47
+ /* Given an array of numbers, find the min/max/mean */
48
+ static calcHeuristic(heuristic) {
49
+ return {
50
+ max: heuristic.reduce((prev, value) => {
51
+ return value !== null ? value > prev ? value : prev : prev;
52
+ }, -Infinity),
53
+ mean: (() => {
54
+ const values = heuristic.reduce(
55
+ (prev, value) => {
56
+ return value !== null ? [value + prev[0], prev[1] + 1] : prev;
57
+ },
58
+ [0, 0]
59
+ );
60
+ return values[0] / values[1];
61
+ })(),
62
+ min: heuristic.reduce((prev, value) => {
63
+ return value !== null ? value < prev ? value : prev : prev;
64
+ }, Infinity)
65
+ };
66
+ }
67
+ /* Given elevation and location payloads, generate heuristic arrays */
68
+ static locationsToHeuristics(elevations, locations) {
69
+ const heuristics = elevations.reduce(
70
+ (prev, elev, index) => {
71
+ const elevation = elev.elevation;
72
+ if (elevation === void 0 || elevation === null) {
73
+ throw Error("Invalid Elevation");
74
+ }
75
+ const altitude = locations[index].altitude;
76
+ prev.altitude.push(altitude ?? null);
77
+ prev.elevation.push(elevation);
78
+ prev.variance.push(altitude !== void 0 && altitude !== null ? altitude - elevation : null);
79
+ return prev;
80
+ },
81
+ { altitude: [], elevation: [], variance: [] }
82
+ );
83
+ return heuristics;
84
+ }
85
+ /** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */
86
+ async divineHandler(payloads) {
87
+ const locations = payloads?.filter((payload) => payload?.schema === import_location_payload_plugin.LocationSchema);
88
+ if (locations && locations?.length > 0) {
89
+ const elevationWitness = await import_elevation_plugin.ElevationWitness.create({
90
+ account: this.account,
91
+ config: {
92
+ locations,
93
+ schema: import_elevation_plugin.ElevationWitnessConfigSchema
94
+ }
95
+ });
96
+ const elevations = await elevationWitness.observe();
97
+ const heuristics = _LocationCertaintyDiviner.locationsToHeuristics(elevations, locations);
98
+ const result = new import_payload_builder.PayloadBuilder({ schema: import_location_certainty_payload_plugin.LocationCertaintySchema }).fields({
99
+ altitude: _LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),
100
+ elevation: _LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),
101
+ variance: _LocationCertaintyDiviner.calcHeuristic(heuristics.variance)
102
+ }).build();
103
+ this.logger?.log("LocationCertaintyDiviner.Divine: Processed query");
104
+ return [result];
105
+ }
106
+ return [];
107
+ }
108
+ };
109
+
110
+ // src/Plugin.ts
111
+ var LocationCertaintyPlugin = () => (0, import_payloadset_plugin.createPayloadSetDivinerPlugin)(
112
+ { required: { [import_location_certainty_payload_plugin2.LocationCertaintySchema]: 1 }, schema: import_payload_model.PayloadSetSchema },
113
+ {
114
+ diviner: async (params) => {
115
+ return await LocationCertaintyDiviner.create(params);
116
+ }
117
+ }
118
+ );
119
+
120
+ // src/index.ts
121
+ var src_default = LocationCertaintyPlugin;
122
+ // Annotate the CommonJS export names for ESM import in node:
123
+ 0 && (module.exports = {
124
+ LocationCertaintyDiviner,
125
+ LocationCertaintyDivinerConfigSchema,
126
+ LocationCertaintyPlugin
127
+ });
128
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/Plugin.ts","../src/Diviner/Config.ts","../src/Diviner/Diviner.ts"],"sourcesContent":["import { LocationCertaintyPlugin } from './Plugin'\n\nexport * from './Diviner'\n\nexport { LocationCertaintyPlugin }\n\n// eslint-disable-next-line import/no-default-export\nexport default LocationCertaintyPlugin\n","import { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { LocationCertaintyDiviner } from './Diviner'\n\nexport const LocationCertaintyPlugin = () =>\n createPayloadSetDivinerPlugin<LocationCertaintyDiviner>(\n { required: { [LocationCertaintySchema]: 1 }, schema: PayloadSetSchema },\n {\n diviner: async (params) => {\n return (await LocationCertaintyDiviner.create(params)) as LocationCertaintyDiviner\n },\n },\n )\n","import { DivinerConfig } from '@xyo-network/diviner-model'\nimport { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport type LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config'\nexport const LocationCertaintyDivinerConfigSchema: LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config'\n\nexport type LocationCertaintyDivinerConfig<TConfig extends Payload = Payload> = DivinerConfig<\n TConfig & {\n schema: LocationCertaintyDivinerConfigSchema\n targetSchema?: LocationCertaintySchema\n }\n>\n","import { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport { DivinerModule, DivinerParams } from '@xyo-network/diviner-model'\nimport { ElevationPayload } from '@xyo-network/elevation-payload-plugin'\nimport { ElevationWitness, ElevationWitnessConfigSchema } from '@xyo-network/elevation-plugin'\nimport { LocationCertaintyHeuristic, LocationCertaintyPayload, LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { LocationPayload, LocationSchema } from '@xyo-network/location-payload-plugin'\nimport { AnyConfigSchema } from '@xyo-network/module'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { LocationCertaintyDivinerConfig, LocationCertaintyDivinerConfigSchema } from './Config'\n\nexport type LocationCertaintyDivinerParams = DivinerParams<AnyConfigSchema<LocationCertaintyDivinerConfig>>\n\nexport class LocationCertaintyDiviner<TParam extends LocationCertaintyDivinerParams = LocationCertaintyDivinerParams>\n extends AbstractDiviner<TParam>\n implements DivinerModule\n{\n static override configSchemas = [LocationCertaintyDivinerConfigSchema]\n static override targetSchema = LocationCertaintySchema\n\n /* Given an array of numbers, find the min/max/mean */\n private static calcHeuristic(heuristic: (number | null)[]): LocationCertaintyHeuristic {\n return {\n max: heuristic.reduce<number>((prev, value) => {\n return value !== null ? (value > prev ? value : prev) : prev\n }, -Infinity),\n mean: (() => {\n const values = heuristic.reduce<number[]>(\n (prev, value) => {\n return value !== null ? [value + prev[0], prev[1] + 1] : prev\n },\n [0, 0],\n )\n return values[0] / values[1]\n })(),\n min: heuristic.reduce<number>((prev, value) => {\n return value !== null ? (value < prev ? value : prev) : prev\n }, Infinity),\n }\n }\n\n /* Given elevation and location payloads, generate heuristic arrays */\n private static locationsToHeuristics(elevations: ElevationPayload[], locations: LocationPayload[]) {\n const heuristics = elevations.reduce<{ altitude: (number | null)[]; elevation: number[]; variance: (number | null)[] }>(\n (prev, elev, index) => {\n const elevation = elev.elevation\n if (elevation === undefined || elevation === null) {\n throw Error('Invalid Elevation')\n }\n const altitude = locations[index].altitude\n prev.altitude.push(altitude ?? null)\n prev.elevation.push(elevation)\n prev.variance.push(altitude !== undefined && altitude !== null ? altitude - elevation : null)\n return prev\n },\n { altitude: [], elevation: [], variance: [] },\n )\n return heuristics\n }\n\n /** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const locations = payloads?.filter<LocationPayload>((payload): payload is LocationPayload => payload?.schema === LocationSchema)\n // If this is a query we support\n if (locations && locations?.length > 0) {\n const elevationWitness = await ElevationWitness.create({\n account: this.account,\n config: {\n locations,\n schema: ElevationWitnessConfigSchema,\n },\n })\n const elevations = (await elevationWitness.observe()) as ElevationPayload[]\n\n const heuristics = LocationCertaintyDiviner.locationsToHeuristics(elevations, locations)\n\n const result = new PayloadBuilder<LocationCertaintyPayload>({ schema: LocationCertaintySchema })\n .fields({\n altitude: LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),\n elevation: LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),\n variance: LocationCertaintyDiviner.calcHeuristic(heuristics.variance),\n })\n .build()\n\n this.logger?.log('LocationCertaintyDi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dist/index.mjs ADDED
@@ -0,0 +1,99 @@
1
+ // src/Plugin.ts
2
+ import { LocationCertaintySchema as LocationCertaintySchema2 } from "@xyo-network/location-certainty-payload-plugin";
3
+ import { PayloadSetSchema } from "@xyo-network/payload-model";
4
+ import { createPayloadSetDivinerPlugin } from "@xyo-network/payloadset-plugin";
5
+
6
+ // src/Diviner/Config.ts
7
+ var LocationCertaintyDivinerConfigSchema = "network.xyo.location.elevation.diviner.config";
8
+
9
+ // src/Diviner/Diviner.ts
10
+ import { AbstractDiviner } from "@xyo-network/abstract-diviner";
11
+ import { ElevationWitness, ElevationWitnessConfigSchema } from "@xyo-network/elevation-plugin";
12
+ import { LocationCertaintySchema } from "@xyo-network/location-certainty-payload-plugin";
13
+ import { LocationSchema } from "@xyo-network/location-payload-plugin";
14
+ import { PayloadBuilder } from "@xyo-network/payload-builder";
15
+ var LocationCertaintyDiviner = class _LocationCertaintyDiviner extends AbstractDiviner {
16
+ static configSchemas = [LocationCertaintyDivinerConfigSchema];
17
+ static targetSchema = LocationCertaintySchema;
18
+ /* Given an array of numbers, find the min/max/mean */
19
+ static calcHeuristic(heuristic) {
20
+ return {
21
+ max: heuristic.reduce((prev, value) => {
22
+ return value !== null ? value > prev ? value : prev : prev;
23
+ }, -Infinity),
24
+ mean: (() => {
25
+ const values = heuristic.reduce(
26
+ (prev, value) => {
27
+ return value !== null ? [value + prev[0], prev[1] + 1] : prev;
28
+ },
29
+ [0, 0]
30
+ );
31
+ return values[0] / values[1];
32
+ })(),
33
+ min: heuristic.reduce((prev, value) => {
34
+ return value !== null ? value < prev ? value : prev : prev;
35
+ }, Infinity)
36
+ };
37
+ }
38
+ /* Given elevation and location payloads, generate heuristic arrays */
39
+ static locationsToHeuristics(elevations, locations) {
40
+ const heuristics = elevations.reduce(
41
+ (prev, elev, index) => {
42
+ const elevation = elev.elevation;
43
+ if (elevation === void 0 || elevation === null) {
44
+ throw Error("Invalid Elevation");
45
+ }
46
+ const altitude = locations[index].altitude;
47
+ prev.altitude.push(altitude ?? null);
48
+ prev.elevation.push(elevation);
49
+ prev.variance.push(altitude !== void 0 && altitude !== null ? altitude - elevation : null);
50
+ return prev;
51
+ },
52
+ { altitude: [], elevation: [], variance: [] }
53
+ );
54
+ return heuristics;
55
+ }
56
+ /** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */
57
+ async divineHandler(payloads) {
58
+ const locations = payloads?.filter((payload) => payload?.schema === LocationSchema);
59
+ if (locations && locations?.length > 0) {
60
+ const elevationWitness = await ElevationWitness.create({
61
+ account: this.account,
62
+ config: {
63
+ locations,
64
+ schema: ElevationWitnessConfigSchema
65
+ }
66
+ });
67
+ const elevations = await elevationWitness.observe();
68
+ const heuristics = _LocationCertaintyDiviner.locationsToHeuristics(elevations, locations);
69
+ const result = new PayloadBuilder({ schema: LocationCertaintySchema }).fields({
70
+ altitude: _LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),
71
+ elevation: _LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),
72
+ variance: _LocationCertaintyDiviner.calcHeuristic(heuristics.variance)
73
+ }).build();
74
+ this.logger?.log("LocationCertaintyDiviner.Divine: Processed query");
75
+ return [result];
76
+ }
77
+ return [];
78
+ }
79
+ };
80
+
81
+ // src/Plugin.ts
82
+ var LocationCertaintyPlugin = () => createPayloadSetDivinerPlugin(
83
+ { required: { [LocationCertaintySchema2]: 1 }, schema: PayloadSetSchema },
84
+ {
85
+ diviner: async (params) => {
86
+ return await LocationCertaintyDiviner.create(params);
87
+ }
88
+ }
89
+ );
90
+
91
+ // src/index.ts
92
+ var src_default = LocationCertaintyPlugin;
93
+ export {
94
+ LocationCertaintyDiviner,
95
+ LocationCertaintyDivinerConfigSchema,
96
+ LocationCertaintyPlugin,
97
+ src_default as default
98
+ };
99
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Plugin.ts","../src/Diviner/Config.ts","../src/Diviner/Diviner.ts","../src/index.ts"],"sourcesContent":["import { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { LocationCertaintyDiviner } from './Diviner'\n\nexport const LocationCertaintyPlugin = () =>\n createPayloadSetDivinerPlugin<LocationCertaintyDiviner>(\n { required: { [LocationCertaintySchema]: 1 }, schema: PayloadSetSchema },\n {\n diviner: async (params) => {\n return (await LocationCertaintyDiviner.create(params)) as LocationCertaintyDiviner\n },\n },\n )\n","import { DivinerConfig } from '@xyo-network/diviner-model'\nimport { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport type LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config'\nexport const LocationCertaintyDivinerConfigSchema: LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config'\n\nexport type LocationCertaintyDivinerConfig<TConfig extends Payload = Payload> = DivinerConfig<\n TConfig & {\n schema: LocationCertaintyDivinerConfigSchema\n targetSchema?: LocationCertaintySchema\n }\n>\n","import { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport { DivinerModule, DivinerParams } from '@xyo-network/diviner-model'\nimport { ElevationPayload } from '@xyo-network/elevation-payload-plugin'\nimport { ElevationWitness, ElevationWitnessConfigSchema } from '@xyo-network/elevation-plugin'\nimport { LocationCertaintyHeuristic, LocationCertaintyPayload, LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { LocationPayload, LocationSchema } from '@xyo-network/location-payload-plugin'\nimport { AnyConfigSchema } from '@xyo-network/module'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { LocationCertaintyDivinerConfig, LocationCertaintyDivinerConfigSchema } from './Config'\n\nexport type LocationCertaintyDivinerParams = DivinerParams<AnyConfigSchema<LocationCertaintyDivinerConfig>>\n\nexport class LocationCertaintyDiviner<TParam extends LocationCertaintyDivinerParams = LocationCertaintyDivinerParams>\n extends AbstractDiviner<TParam>\n implements DivinerModule\n{\n static override configSchemas = [LocationCertaintyDivinerConfigSchema]\n static override targetSchema = LocationCertaintySchema\n\n /* Given an array of numbers, find the min/max/mean */\n private static calcHeuristic(heuristic: (number | null)[]): LocationCertaintyHeuristic {\n return {\n max: heuristic.reduce<number>((prev, value) => {\n return value !== null ? (value > prev ? value : prev) : prev\n }, -Infinity),\n mean: (() => {\n const values = heuristic.reduce<number[]>(\n (prev, value) => {\n return value !== null ? [value + prev[0], prev[1] + 1] : prev\n },\n [0, 0],\n )\n return values[0] / values[1]\n })(),\n min: heuristic.reduce<number>((prev, value) => {\n return value !== null ? (value < prev ? value : prev) : prev\n }, Infinity),\n }\n }\n\n /* Given elevation and location payloads, generate heuristic arrays */\n private static locationsToHeuristics(elevations: ElevationPayload[], locations: LocationPayload[]) {\n const heuristics = elevations.reduce<{ altitude: (number | null)[]; elevation: number[]; variance: (number | null)[] }>(\n (prev, elev, index) => {\n const elevation = elev.elevation\n if (elevation === undefined || elevation === null) {\n throw Error('Invalid Elevation')\n }\n const altitude = locations[index].altitude\n prev.altitude.push(altitude ?? null)\n prev.elevation.push(elevation)\n prev.variance.push(altitude !== undefined && altitude !== null ? altitude - elevation : null)\n return prev\n },\n { altitude: [], elevation: [], variance: [] },\n )\n return heuristics\n }\n\n /** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const locations = payloads?.filter<LocationPayload>((payload): payload is LocationPayload => payload?.schema === LocationSchema)\n // If this is a query we support\n if (locations && locations?.length > 0) {\n const elevationWitness = await ElevationWitness.create({\n account: this.account,\n config: {\n locations,\n schema: ElevationWitnessConfigSchema,\n },\n })\n const elevations = (await elevationWitness.observe()) as ElevationPayload[]\n\n const heuristics = LocationCertaintyDiviner.locationsToHeuristics(elevations, locations)\n\n const result = new PayloadBuilder<LocationCertaintyPayload>({ schema: LocationCertaintySchema })\n .fields({\n altitude: LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),\n elevation: LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),\n variance: LocationCertaintyDiviner.calcHeuristic(heuristics.variance),\n })\n .build()\n\n this.logger?.log('LocationCertaintyDiviner.Divine: Processed query')\n return [result]\n }\n return []\n }\n}\n","import { LocationCertaintyPlugin } from './Plugin'\n\nexport * from './Diviner'\n\nexport { LocationCertaintyPlugin }\n\n// eslint-disable-next-line import/no-default-export\nexport default LocationCertaintyPlugin\n"],"mappings":";AAAA,SAAS,2BAAAA,gCAA+B;AACxC,SAAS,wBAAwB;AACjC,SAAS,qCAAqC;;;ACGvC,IAAM,uCAA6E;;;ACL1F,SAAS,uBAAuB;AAGhC,SAAS,kBAAkB,oCAAoC;AAC/D,SAA+D,+BAA+B;AAC9F,SAA0B,sBAAsB;AAEhD,SAAS,sBAAsB;AAOxB,IAAM,2BAAN,MAAM,kCACH,gBAEV;AAAA,EACE,OAAgB,gBAAgB,CAAC,oCAAoC;AAAA,EACrE,OAAgB,eAAe;AAAA;AAAA,EAG/B,OAAe,cAAc,WAA0D;AACrF,WAAO;AAAA,MACL,KAAK,UAAU,OAAe,CAAC,MAAM,UAAU;AAC7C,eAAO,UAAU,OAAQ,QAAQ,OAAO,QAAQ,OAAQ;AAAA,MAC1D,GAAG,SAAS;AAAA,MACZ,OAAO,MAAM;AACX,cAAM,SAAS,UAAU;AAAA,UACvB,CAAC,MAAM,UAAU;AACf,mBAAO,UAAU,OAAO,CAAC,QAAQ,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI;AAAA,UAC3D;AAAA,UACA,CAAC,GAAG,CAAC;AAAA,QACP;AACA,eAAO,OAAO,CAAC,IAAI,OAAO,CAAC;AAAA,MAC7B,GAAG;AAAA,MACH,KAAK,UAAU,OAAe,CAAC,MAAM,UAAU;AAC7C,eAAO,UAAU,OAAQ,QAAQ,OAAO,QAAQ,OAAQ;A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AO,CAAC;AAAA,EACV;AACF;;;AFpFO,IAAM,0BAA0B,MACrC;AAAA,EACE,EAAE,UAAU,EAAE,CAACC,wBAAuB,GAAG,EAAE,GAAG,QAAQ,iBAAiB;AAAA,EACvE;AAAA,IACE,SAAS,OAAO,WAAW;AACzB,aAAQ,MAAM,yBAAyB,OAAO,MAAM;AAAA,IACtD;AAAA,EACF;AACF;;;AGPF,IAAO,cAAQ;","names":["LocationCertaintySchema","LocationCertaintySchema"]}
package/package.json CHANGED
@@ -10,44 +10,58 @@
10
10
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xyo-network/abstract-diviner": "~2.73.2",
14
- "@xyo-network/diviner-model": "~2.73.2",
15
- "@xyo-network/elevation-payload-plugin": "~2.73.2",
16
- "@xyo-network/elevation-plugin": "~2.73.2",
17
- "@xyo-network/location-certainty-payload-plugin": "~2.73.2",
18
- "@xyo-network/location-payload-plugin": "~2.73.2",
19
- "@xyo-network/module": "~2.73.2",
20
- "@xyo-network/payload-builder": "~2.73.2",
21
- "@xyo-network/payload-model": "~2.73.2",
22
- "@xyo-network/payloadset-plugin": "~2.73.2"
13
+ "@xyo-network/abstract-diviner": "~2.73.4",
14
+ "@xyo-network/diviner-model": "~2.73.4",
15
+ "@xyo-network/elevation-payload-plugin": "~2.73.4",
16
+ "@xyo-network/elevation-plugin": "~2.73.4",
17
+ "@xyo-network/location-certainty-payload-plugin": "~2.73.4",
18
+ "@xyo-network/location-payload-plugin": "~2.73.4",
19
+ "@xyo-network/module": "~2.73.4",
20
+ "@xyo-network/payload-builder": "~2.73.4",
21
+ "@xyo-network/payload-model": "~2.73.4",
22
+ "@xyo-network/payloadset-plugin": "~2.73.4"
23
23
  },
24
24
  "devDependencies": {
25
- "@xylabs/ts-scripts-yarn3": "^2.19.5",
26
- "@xylabs/tsconfig": "^2.19.5",
25
+ "@xylabs/ts-scripts-yarn3": "^2.19.12",
26
+ "@xylabs/tsconfig": "^2.19.12",
27
+ "publint": "^0.2.2",
28
+ "tsup": "^7.2.0",
27
29
  "typescript": "^5.2.2"
28
30
  },
31
+ "scripts": {
32
+ "package-compile": "tsup && publint",
33
+ "package-recompile": "tsup && publint"
34
+ },
29
35
  "description": "Primary SDK for using XYO Protocol 2.0",
30
- "browser": "dist/esm/index.js",
31
36
  "docs": "dist/docs.json",
37
+ "types": "dist/index.d.ts",
32
38
  "exports": {
33
39
  ".": {
34
- "node": {
35
- "import": "./dist/esm/index.js",
36
- "require": "./dist/cjs/index.js"
37
- },
38
- "browser": {
39
- "import": "./dist/esm/index.js",
40
- "require": "./dist/cjs/index.js"
40
+ "require": {
41
+ "types": "./dist/index.d.ts",
42
+ "default": "./dist/index.js"
41
43
  },
42
- "default": "./dist/esm/index.js"
44
+ "import": {
45
+ "types": "./dist/index.d.mts",
46
+ "default": "./dist/index.mjs"
47
+ }
43
48
  },
44
49
  "./dist/docs.json": {
45
50
  "default": "./dist/docs.json"
46
51
  },
52
+ "./cjs": {
53
+ "default": "./dist/index.js"
54
+ },
55
+ "./docs": {
56
+ "default": "./dist/docs.json"
57
+ },
58
+ "./esm": {
59
+ "default": "./dist/index.mjs"
60
+ },
47
61
  "./package.json": "./package.json"
48
62
  },
49
- "main": "dist/cjs/index.js",
50
- "module": "dist/esm/index.js",
63
+ "main": "dist/index.js",
64
+ "module": "dist/index.mjs",
51
65
  "homepage": "https://xyo.network",
52
66
  "license": "LGPL-3.0",
53
67
  "publishConfig": {
@@ -58,6 +72,5 @@
58
72
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
59
73
  },
60
74
  "sideEffects": false,
61
- "types": "dist/types/index.d.ts",
62
- "version": "2.73.2"
75
+ "version": "2.73.4"
63
76
  }
package/tsup.config.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from 'tsup'
2
+
3
+ // eslint-disable-next-line import/no-default-export
4
+ export default defineConfig({
5
+ bundle: true,
6
+ cjsInterop: true,
7
+ clean: false,
8
+ dts: {
9
+ entry: ['src/index.ts'],
10
+ },
11
+ entry: ['src/index.ts'],
12
+ format: ['cjs', 'esm'],
13
+ sourcemap: true,
14
+ splitting: false,
15
+ tsconfig: 'tsconfig.json',
16
+ })
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LocationCertaintyDivinerConfigSchema = void 0;
4
- exports.LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config';
5
- //# sourceMappingURL=Config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Config.js","sourceRoot":"","sources":["../../../src/Diviner/Config.ts"],"names":[],"mappings":";;;AAKa,QAAA,oCAAoC,GAAyC,+CAA+C,CAAA"}
@@ -1,77 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LocationCertaintyDiviner = void 0;
4
- const tslib_1 = require("tslib");
5
- const abstract_diviner_1 = require("@xyo-network/abstract-diviner");
6
- const elevation_plugin_1 = require("@xyo-network/elevation-plugin");
7
- const location_certainty_payload_plugin_1 = require("@xyo-network/location-certainty-payload-plugin");
8
- const location_payload_plugin_1 = require("@xyo-network/location-payload-plugin");
9
- const payload_builder_1 = require("@xyo-network/payload-builder");
10
- const Config_1 = require("./Config");
11
- class LocationCertaintyDiviner extends abstract_diviner_1.AbstractDiviner {
12
- /* Given an array of numbers, find the min/max/mean */
13
- static calcHeuristic(heuristic) {
14
- return {
15
- max: heuristic.reduce((prev, value) => {
16
- return value !== null ? (value > prev ? value : prev) : prev;
17
- }, -Infinity),
18
- mean: (() => {
19
- const values = heuristic.reduce((prev, value) => {
20
- return value !== null ? [value + prev[0], prev[1] + 1] : prev;
21
- }, [0, 0]);
22
- return values[0] / values[1];
23
- })(),
24
- min: heuristic.reduce((prev, value) => {
25
- return value !== null ? (value < prev ? value : prev) : prev;
26
- }, Infinity),
27
- };
28
- }
29
- /* Given elevation and location payloads, generate heuristic arrays */
30
- static locationsToHeuristics(elevations, locations) {
31
- const heuristics = elevations.reduce((prev, elev, index) => {
32
- const elevation = elev.elevation;
33
- if (elevation === undefined || elevation === null) {
34
- throw Error('Invalid Elevation');
35
- }
36
- const altitude = locations[index].altitude;
37
- prev.altitude.push(altitude !== null && altitude !== void 0 ? altitude : null);
38
- prev.elevation.push(elevation);
39
- prev.variance.push(altitude !== undefined && altitude !== null ? altitude - elevation : null);
40
- return prev;
41
- }, { altitude: [], elevation: [], variance: [] });
42
- return heuristics;
43
- }
44
- /** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */
45
- divineHandler(payloads) {
46
- var _a;
47
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
48
- const locations = payloads === null || payloads === void 0 ? void 0 : payloads.filter((payload) => (payload === null || payload === void 0 ? void 0 : payload.schema) === location_payload_plugin_1.LocationSchema);
49
- // If this is a query we support
50
- if (locations && (locations === null || locations === void 0 ? void 0 : locations.length) > 0) {
51
- const elevationWitness = yield elevation_plugin_1.ElevationWitness.create({
52
- account: this.account,
53
- config: {
54
- locations,
55
- schema: elevation_plugin_1.ElevationWitnessConfigSchema,
56
- },
57
- });
58
- const elevations = (yield elevationWitness.observe());
59
- const heuristics = LocationCertaintyDiviner.locationsToHeuristics(elevations, locations);
60
- const result = new payload_builder_1.PayloadBuilder({ schema: location_certainty_payload_plugin_1.LocationCertaintySchema })
61
- .fields({
62
- altitude: LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),
63
- elevation: LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),
64
- variance: LocationCertaintyDiviner.calcHeuristic(heuristics.variance),
65
- })
66
- .build();
67
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.log('LocationCertaintyDiviner.Divine: Processed query');
68
- return [result];
69
- }
70
- return [];
71
- });
72
- }
73
- }
74
- exports.LocationCertaintyDiviner = LocationCertaintyDiviner;
75
- LocationCertaintyDiviner.configSchemas = [Config_1.LocationCertaintyDivinerConfigSchema];
76
- LocationCertaintyDiviner.targetSchema = location_certainty_payload_plugin_1.LocationCertaintySchema;
77
- //# sourceMappingURL=Diviner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Diviner.js","sourceRoot":"","sources":["../../../src/Diviner/Diviner.ts"],"names":[],"mappings":";;;;AAAA,oEAA+D;AAG/D,oEAA8F;AAC9F,sGAA8I;AAC9I,kFAAsF;AAEtF,kEAA6D;AAG7D,qCAA+F;AAI/F,MAAa,wBACX,SAAQ,kCAAuB;IAM/B,sDAAsD;IAC9C,MAAM,CAAC,aAAa,CAAC,SAA4B;QACvD,OAAO;YACL,GAAG,EAAE,SAAS,CAAC,MAAM,CAAS,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;gBAC5C,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;YAC9D,CAAC,EAAE,CAAC,QAAQ,CAAC;YACb,IAAI,EAAE,CAAC,GAAG,EAAE;gBACV,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAC7B,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;oBACd,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;gBAC/D,CAAC,EACD,CAAC,CAAC,EAAE,CAAC,CAAC,CACP,CAAA;gBACD,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;YAC9B,CAAC,CAAC,EAAE;YACJ,GAAG,EAAE,SAAS,CAAC,MAAM,CAAS,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;gBAC5C,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,C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CAAc,CAAC,CAAA;YAChI,gCAAgC;YAChC,IAAI,SAAS,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,MAAM,IAAG,CAAC,EAAE;gBACtC,MAAM,gBAAgB,GAAG,MAAM,mCAAgB,CAAC,MAAM,CAAC;oBACrD,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,MAAM,EAAE;wBACN,SAAS;wBACT,MAAM,EAAE,+CAA4B;qBACrC;iBACF,CAAC,CAAA;gBACF,MAAM,UAAU,GAAG,CAAC,MAAM,gBAAgB,CAAC,OAAO,EAAE,CAAuB,CAAA;gBAE3E,MAAM,UAAU,GAAG,wBAAwB,CAAC,qBAAqB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;gBAExF,MAAM,MAAM,GAAG,IAAI,gCAAc,CAA2B,EAAE,MAAM,EAAE,2DAAuB,EAAE,CAAC;qBAC7F,MAAM,CAAC;oBACN,QAAQ,EAAE,wBAAwB,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC;oBACrE,SAAS,EAAE,wBAAwB,CAAC,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC;oBACvE,QAAQ,EAAE,wBAAwB,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC;iBACtE,CAAC;qBACD,KAAK,EAAE,CAAA;gBAEV,MAAA,IAAI,CAAC,MAAM,0CAAE,GAAG,CAAC,kDAAkD,CAAC,CAAA;gBACpE,OAAO,CAAC,MAAM,CAAC,CAAA;aAChB;YACD,OAAO,EAAE,CAAA;;KACV;;AA3EH,4DA4EC;AAxEiB,sCAAa,GAAG,CAAC,6CAAoC,CAAC,CAAA;AACtD,qCAAY,GAAG,2DAAuB,CAAA"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./Config"), exports);
5
- tslib_1.__exportStar(require("./Diviner"), exports);
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Diviner/index.ts"],"names":[],"mappings":";;;AAAA,mDAAwB;AACxB,oDAAyB"}
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LocationCertaintyPlugin = void 0;
4
- const tslib_1 = require("tslib");
5
- const location_certainty_payload_plugin_1 = require("@xyo-network/location-certainty-payload-plugin");
6
- const payload_model_1 = require("@xyo-network/payload-model");
7
- const payloadset_plugin_1 = require("@xyo-network/payloadset-plugin");
8
- const Diviner_1 = require("./Diviner");
9
- const LocationCertaintyPlugin = () => (0, payloadset_plugin_1.createPayloadSetDivinerPlugin)({ required: { [location_certainty_payload_plugin_1.LocationCertaintySchema]: 1 }, schema: payload_model_1.PayloadSetSchema }, {
10
- diviner: (params) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
11
- return (yield Diviner_1.LocationCertaintyDiviner.create(params));
12
- }),
13
- });
14
- exports.LocationCertaintyPlugin = LocationCertaintyPlugin;
15
- //# sourceMappingURL=Plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Plugin.js","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":";;;;AAAA,sGAAwF;AACxF,8DAA6D;AAC7D,sEAA8E;AAE9E,uCAAoD;AAE7C,MAAM,uBAAuB,GAAG,GAAG,EAAE,CAC1C,IAAA,iDAA6B,EAC3B,EAAE,QAAQ,EAAE,EAAE,CAAC,2DAAuB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,gCAAgB,EAAE,EACxE;IACE,OAAO,EAAE,CAAO,MAAM,EAAE,EAAE;QACxB,OAAO,CAAC,MAAM,kCAAwB,CAAC,MAAM,CAAC,MAAM,CAAC,CAA6B,CAAA;IACpF,CAAC,CAAA;CACF,CACF,CAAA;AARU,QAAA,uBAAuB,2BAQjC"}
package/dist/cjs/index.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LocationCertaintyPlugin = void 0;
4
- const tslib_1 = require("tslib");
5
- const Plugin_1 = require("./Plugin");
6
- Object.defineProperty(exports, "LocationCertaintyPlugin", { enumerable: true, get: function () { return Plugin_1.LocationCertaintyPlugin; } });
7
- tslib_1.__exportStar(require("./Diviner"), exports);
8
- // eslint-disable-next-line import/no-default-export
9
- exports.default = Plugin_1.LocationCertaintyPlugin;
10
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,qCAAkD;AAIzC,wGAJA,gCAAuB,OAIA;AAFhC,oDAAyB;AAIzB,oDAAoD;AACpD,kBAAe,gCAAuB,CAAA"}
@@ -1,2 +0,0 @@
1
- export const LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config';
2
- //# sourceMappingURL=Config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Config.js","sourceRoot":"","sources":["../../../src/Diviner/Config.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,oCAAoC,GAAyC,+CAA+C,CAAA"}
@@ -1,69 +0,0 @@
1
- import { AbstractDiviner } from '@xyo-network/abstract-diviner';
2
- import { ElevationWitness, ElevationWitnessConfigSchema } from '@xyo-network/elevation-plugin';
3
- import { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin';
4
- import { LocationSchema } from '@xyo-network/location-payload-plugin';
5
- import { PayloadBuilder } from '@xyo-network/payload-builder';
6
- import { LocationCertaintyDivinerConfigSchema } from './Config';
7
- export class LocationCertaintyDiviner extends AbstractDiviner {
8
- static configSchemas = [LocationCertaintyDivinerConfigSchema];
9
- static targetSchema = LocationCertaintySchema;
10
- /* Given an array of numbers, find the min/max/mean */
11
- static calcHeuristic(heuristic) {
12
- return {
13
- max: heuristic.reduce((prev, value) => {
14
- return value !== null ? (value > prev ? value : prev) : prev;
15
- }, -Infinity),
16
- mean: (() => {
17
- const values = heuristic.reduce((prev, value) => {
18
- return value !== null ? [value + prev[0], prev[1] + 1] : prev;
19
- }, [0, 0]);
20
- return values[0] / values[1];
21
- })(),
22
- min: heuristic.reduce((prev, value) => {
23
- return value !== null ? (value < prev ? value : prev) : prev;
24
- }, Infinity),
25
- };
26
- }
27
- /* Given elevation and location payloads, generate heuristic arrays */
28
- static locationsToHeuristics(elevations, locations) {
29
- const heuristics = elevations.reduce((prev, elev, index) => {
30
- const elevation = elev.elevation;
31
- if (elevation === undefined || elevation === null) {
32
- throw Error('Invalid Elevation');
33
- }
34
- const altitude = locations[index].altitude;
35
- prev.altitude.push(altitude ?? null);
36
- prev.elevation.push(elevation);
37
- prev.variance.push(altitude !== undefined && altitude !== null ? altitude - elevation : null);
38
- return prev;
39
- }, { altitude: [], elevation: [], variance: [] });
40
- return heuristics;
41
- }
42
- /** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */
43
- async divineHandler(payloads) {
44
- const locations = payloads?.filter((payload) => payload?.schema === LocationSchema);
45
- // If this is a query we support
46
- if (locations && locations?.length > 0) {
47
- const elevationWitness = await ElevationWitness.create({
48
- account: this.account,
49
- config: {
50
- locations,
51
- schema: ElevationWitnessConfigSchema,
52
- },
53
- });
54
- const elevations = (await elevationWitness.observe());
55
- const heuristics = LocationCertaintyDiviner.locationsToHeuristics(elevations, locations);
56
- const result = new PayloadBuilder({ schema: LocationCertaintySchema })
57
- .fields({
58
- altitude: LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),
59
- elevation: LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),
60
- variance: LocationCertaintyDiviner.calcHeuristic(heuristics.variance),
61
- })
62
- .build();
63
- this.logger?.log('LocationCertaintyDiviner.Divine: Processed query');
64
- return [result];
65
- }
66
- return [];
67
- }
68
- }
69
- //# sourceMappingURL=Diviner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Diviner.js","sourceRoot":"","sources":["../../../src/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K,CAAC,aAAa,CAAC,QAAoB;QACzD,MAAM,SAAS,GAAG,QAAQ,EAAE,MAAM,CAAkB,CAAC,OAAO,EAA8B,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,cAAc,CAAC,CAAA;QAChI,gCAAgC;QAChC,IAAI,SAAS,IAAI,SAAS,EAAE,MAAM,GAAG,CAAC,EAAE;YACtC,MAAM,gBAAgB,GAAG,MAAM,gBAAgB,CAAC,MAAM,CAAC;gBACrD,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,MAAM,EAAE;oBACN,SAAS;oBACT,MAAM,EAAE,4BAA4B;iBACrC;aACF,CAAC,CAAA;YACF,MAAM,UAAU,GAAG,CAAC,MAAM,gBAAgB,CAAC,OAAO,EAAE,CAAuB,CAAA;YAE3E,MAAM,UAAU,GAAG,wBAAwB,CAAC,qBAAqB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;YAExF,MAAM,MAAM,GAAG,IAAI,cAAc,CAA2B,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAC;iBAC7F,MAAM,CAAC;gBACN,QAAQ,EAAE,wBAAwB,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC;gBACrE,SAAS,EAAE,wBAAwB,CAAC,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC;gBACvE,QAAQ,EAAE,wBAAwB,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC;aACtE,CAAC;iBACD,KAAK,EAAE,CAAA;YAEV,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,kDAAkD,CAAC,CAAA;YACpE,OAAO,CAAC,MAAM,CAAC,CAAA;SAChB;QACD,OAAO,EAAE,CAAA;IACX,CAAC"}
@@ -1,3 +0,0 @@
1
- export * from './Config';
2
- export * from './Diviner';
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Diviner/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA"}
@@ -1,10 +0,0 @@
1
- import { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin';
2
- import { PayloadSetSchema } from '@xyo-network/payload-model';
3
- import { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin';
4
- import { LocationCertaintyDiviner } from './Diviner';
5
- export const LocationCertaintyPlugin = () => createPayloadSetDivinerPlugin({ required: { [LocationCertaintySchema]: 1 }, schema: PayloadSetSchema }, {
6
- diviner: async (params) => {
7
- return (await LocationCertaintyDiviner.create(params));
8
- },
9
- });
10
- //# sourceMappingURL=Plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Plugin.js","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAA;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAA;AAE9E,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAA;AAEpD,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,EAAE,CAC1C,6BAA6B,CAC3B,EAAE,QAAQ,EAAE,EAAE,CAAC,uBAAuB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE,EACxE;IACE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QACxB,OAAO,CAAC,MAAM,wBAAwB,CAAC,MAAM,CAAC,MAAM,CAAC,CAA6B,CAAA;IACpF,CAAC;CACF,CACF,CAAA"}
package/dist/esm/index.js DELETED
@@ -1,6 +0,0 @@
1
- import { LocationCertaintyPlugin } from './Plugin';
2
- export * from './Diviner';
3
- export { LocationCertaintyPlugin };
4
- // eslint-disable-next-line import/no-default-export
5
- export default LocationCertaintyPlugin;
6
- //# sourceMappingURL=index.js.map