@xyo-network/location-certainty-plugin 4.2.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +24 -20
- package/src/Diviner/Diviner.ts +3 -3
- package/src/Diviner/spec/Diviner.spec.ts +143 -0
- package/src/spec/Plugin.dom.spec.ts +23 -0
- package/typedoc.json +0 -5
- package/xy.config.ts +0 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Diviner/Config.ts","../../src/Diviner/Diviner.ts","../../src/Plugin.ts"],"sourcesContent":["import type { DivinerConfig } from '@xyo-network/diviner-model'\nimport type { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport type { 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/diviner-abstract'\nimport type { DivinerModule, DivinerParams } from '@xyo-network/diviner-model'\nimport type { ElevationPayload } from '@xyo-network/elevation-payload-plugin'\nimport { ElevationWitness, ElevationWitnessConfigSchema } from '@xyo-network/elevation-plugin'\nimport type { LocationCertaintyHeuristic, LocationCertaintyPayload } from '@xyo-network/location-certainty-payload-plugin'\nimport { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport type { LocationPayload } from '@xyo-network/location-payload-plugin'\nimport { LocationSchema } from '@xyo-network/location-payload-plugin'\nimport type { AnyConfigSchema } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { Payload, Schema } from '@xyo-network/payload-model'\n\nimport type { LocationCertaintyDivinerConfig } from './Config.ts'\nimport { LocationCertaintyDivinerConfigSchema } from './Config.ts'\n\nexport type LocationCertaintyDivinerParams = DivinerParams<AnyConfigSchema<LocationCertaintyDivinerConfig>>\n\nexport class LocationCertaintyDiviner<TParam extends LocationCertaintyDivinerParams = LocationCertaintyDivinerParams>\n extends AbstractDiviner<TParam>\n implements DivinerModule {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, LocationCertaintyDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = LocationCertaintyDivinerConfigSchema\n static override readonly 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 // eslint-disable-next-line unicorn/no-array-reduce\n max: heuristic.reduce<number>((prev, value) => {\n return (\n value === null\n ? prev\n : Math.max(value, prev)\n )\n }, Number.NEGATIVE_INFINITY),\n mean: (() => {\n // eslint-disable-next-line unicorn/no-array-reduce\n const values = heuristic.reduce<number[]>(\n (prev, value) => {\n return value === null ? prev : [value + prev[0], prev[1] + 1]\n },\n [0, 0],\n )\n return values[0] / values[1]\n })(),\n // eslint-disable-next-line unicorn/no-array-reduce\n min: heuristic.reduce<number>((prev, value) => {\n return (\n value === null\n ? prev\n : Math.min(value, prev)\n )\n }, Number.POSITIVE_INFINITY),\n }\n }\n\n /* Given elevation and location payloads, generate heuristic arrays */\n private static locationsToHeuristics(elevations: ElevationPayload[], locations: LocationPayload[]) {\n // eslint-disable-next-line unicorn/no-array-reduce\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 new 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
|
|
1
|
+
{"version":3,"sources":["../../src/Diviner/Config.ts","../../src/Diviner/Diviner.ts","../../src/Plugin.ts"],"sourcesContent":["import type { DivinerConfig } from '@xyo-network/diviner-model'\nimport type { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport type { 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/diviner-abstract'\nimport type { DivinerModule, DivinerParams } from '@xyo-network/diviner-model'\nimport type { ElevationPayload } from '@xyo-network/elevation-payload-plugin'\nimport { ElevationWitness, ElevationWitnessConfigSchema } from '@xyo-network/elevation-plugin'\nimport type { LocationCertaintyHeuristic, LocationCertaintyPayload } from '@xyo-network/location-certainty-payload-plugin'\nimport { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport type { LocationPayload } from '@xyo-network/location-payload-plugin'\nimport { LocationSchema } from '@xyo-network/location-payload-plugin'\nimport type { AnyConfigSchema } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { Payload, Schema } from '@xyo-network/payload-model'\n\nimport type { LocationCertaintyDivinerConfig } from './Config.ts'\nimport { LocationCertaintyDivinerConfigSchema } from './Config.ts'\n\nexport type LocationCertaintyDivinerParams = DivinerParams<AnyConfigSchema<LocationCertaintyDivinerConfig>>\n\nexport class LocationCertaintyDiviner<TParam extends LocationCertaintyDivinerParams = LocationCertaintyDivinerParams>\n extends AbstractDiviner<TParam>\n implements DivinerModule {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, LocationCertaintyDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = LocationCertaintyDivinerConfigSchema\n static override readonly 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 // eslint-disable-next-line unicorn/no-array-reduce\n max: heuristic.reduce<number>((prev, value) => {\n return (\n value === null\n ? prev\n : Math.max(value, prev)\n )\n }, Number.NEGATIVE_INFINITY),\n mean: (() => {\n // eslint-disable-next-line unicorn/no-array-reduce\n const values = heuristic.reduce<number[]>(\n (prev, value) => {\n return value === null ? prev : [value + prev[0], prev[1] + 1]\n },\n [0, 0],\n )\n return values[0] / values[1]\n })(),\n // eslint-disable-next-line unicorn/no-array-reduce\n min: heuristic.reduce<number>((prev, value) => {\n return (\n value === null\n ? prev\n : Math.min(value, prev)\n )\n }, Number.POSITIVE_INFINITY),\n }\n }\n\n /* Given elevation and location payloads, generate heuristic arrays */\n private static locationsToHeuristics(elevations: ElevationPayload[], locations: LocationPayload[]) {\n // eslint-disable-next-line unicorn/no-array-reduce\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 new 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 {\n altitude: [], elevation: [], variance: [],\n },\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 { 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/index.ts'\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"],"mappings":"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","names":["LocationCertaintySchema","LocationCertaintySchema"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/location-certainty-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Typescript/Javascript Plugins for XYO Platform",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -28,28 +28,32 @@
|
|
|
28
28
|
},
|
|
29
29
|
"module": "dist/neutral/index.mjs",
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"src"
|
|
34
|
+
],
|
|
31
35
|
"dependencies": {
|
|
32
|
-
"@xyo-network/diviner-abstract": "
|
|
33
|
-
"@xyo-network/diviner-model": "
|
|
34
|
-
"@xyo-network/elevation-plugin": "
|
|
35
|
-
"@xyo-network/location-certainty-payload-plugin": "
|
|
36
|
-
"@xyo-network/location-payload-plugin": "
|
|
37
|
-
"@xyo-network/module-model": "
|
|
38
|
-
"@xyo-network/payload-builder": "
|
|
39
|
-
"@xyo-network/payload-model": "
|
|
40
|
-
"@xyo-network/payloadset-plugin": "
|
|
36
|
+
"@xyo-network/diviner-abstract": "~5.0.2",
|
|
37
|
+
"@xyo-network/diviner-model": "~5.0.2",
|
|
38
|
+
"@xyo-network/elevation-plugin": "~5.0.1",
|
|
39
|
+
"@xyo-network/location-certainty-payload-plugin": "~5.0.1",
|
|
40
|
+
"@xyo-network/location-payload-plugin": "~5.0.1",
|
|
41
|
+
"@xyo-network/module-model": "~5.0.2",
|
|
42
|
+
"@xyo-network/payload-builder": "~5.0.2",
|
|
43
|
+
"@xyo-network/payload-model": "~5.0.2",
|
|
44
|
+
"@xyo-network/payloadset-plugin": "~5.0.2"
|
|
41
45
|
},
|
|
42
46
|
"devDependencies": {
|
|
43
|
-
"@xylabs/ts-scripts-yarn3": "
|
|
44
|
-
"@xylabs/tsconfig": "
|
|
45
|
-
"@xylabs/vitest-extended": "
|
|
46
|
-
"@xyo-network/archivist-abstract": "
|
|
47
|
-
"@xyo-network/archivist-memory": "
|
|
48
|
-
"@xyo-network/elevation-payload-plugin": "
|
|
49
|
-
"@xyo-network/module-resolver": "
|
|
50
|
-
"fast-text-encoding": "
|
|
51
|
-
"typescript": "
|
|
52
|
-
"vitest": "
|
|
47
|
+
"@xylabs/ts-scripts-yarn3": "~7.1.0",
|
|
48
|
+
"@xylabs/tsconfig": "~7.1.0",
|
|
49
|
+
"@xylabs/vitest-extended": "~5.0.7",
|
|
50
|
+
"@xyo-network/archivist-abstract": "~5.0.2",
|
|
51
|
+
"@xyo-network/archivist-memory": "~5.0.2",
|
|
52
|
+
"@xyo-network/elevation-payload-plugin": "~5.0.1",
|
|
53
|
+
"@xyo-network/module-resolver": "~5.0.2",
|
|
54
|
+
"fast-text-encoding": "~1.0.6",
|
|
55
|
+
"typescript": "~5.9.2",
|
|
56
|
+
"vitest": "~3.2.4"
|
|
53
57
|
},
|
|
54
58
|
"publishConfig": {
|
|
55
59
|
"access": "public"
|
package/src/Diviner/Diviner.ts
CHANGED
|
@@ -69,9 +69,9 @@ export class LocationCertaintyDiviner<TParam extends LocationCertaintyDivinerPar
|
|
|
69
69
|
prev.variance.push(altitude !== undefined && altitude !== null ? altitude - elevation : null)
|
|
70
70
|
return prev
|
|
71
71
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
{
|
|
73
|
+
altitude: [], elevation: [], variance: [],
|
|
74
|
+
},
|
|
75
75
|
)
|
|
76
76
|
return heuristics
|
|
77
77
|
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import type { AbstractArchivist } from '@xyo-network/archivist-abstract'
|
|
4
|
+
import { MemoryArchivist } from '@xyo-network/archivist-memory'
|
|
5
|
+
import type { LocationCertaintyPayload } from '@xyo-network/location-certainty-payload-plugin'
|
|
6
|
+
import { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'
|
|
7
|
+
import type { LocationPayload } from '@xyo-network/location-payload-plugin'
|
|
8
|
+
import { LocationSchema } from '@xyo-network/location-payload-plugin'
|
|
9
|
+
import { CompositeModuleResolver } from '@xyo-network/module-resolver'
|
|
10
|
+
import {
|
|
11
|
+
beforeEach,
|
|
12
|
+
describe, expect, it,
|
|
13
|
+
} from 'vitest'
|
|
14
|
+
|
|
15
|
+
import { LocationCertaintyDivinerConfigSchema } from '../Config.ts'
|
|
16
|
+
import { LocationCertaintyDiviner } from '../Diviner.ts'
|
|
17
|
+
|
|
18
|
+
const sample1: LocationPayload[] = [
|
|
19
|
+
{
|
|
20
|
+
altitude: -5,
|
|
21
|
+
latitude: 32.716_64,
|
|
22
|
+
longitude: -117.120_33,
|
|
23
|
+
schema: LocationSchema,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
altitude: -9,
|
|
27
|
+
latitude: 32.7174,
|
|
28
|
+
longitude: -117.116_74,
|
|
29
|
+
schema: LocationSchema,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
altitude: -11,
|
|
33
|
+
latitude: 32.717_88,
|
|
34
|
+
longitude: -117.113_77,
|
|
35
|
+
schema: LocationSchema,
|
|
36
|
+
},
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
const sample2: LocationPayload[] = [
|
|
40
|
+
{
|
|
41
|
+
altitude: 50,
|
|
42
|
+
latitude: 32.716_64,
|
|
43
|
+
longitude: -117.120_33,
|
|
44
|
+
schema: LocationSchema,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
altitude: 53,
|
|
48
|
+
latitude: 32.7174,
|
|
49
|
+
longitude: -117.116_74,
|
|
50
|
+
schema: LocationSchema,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
altitude: 55,
|
|
54
|
+
latitude: 32.717_88,
|
|
55
|
+
longitude: -117.113_77,
|
|
56
|
+
schema: LocationSchema,
|
|
57
|
+
},
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
const sample3: LocationPayload[] = [
|
|
61
|
+
{
|
|
62
|
+
altitude: 151,
|
|
63
|
+
latitude: 32.716_64,
|
|
64
|
+
longitude: -117.120_33,
|
|
65
|
+
schema: LocationSchema,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
altitude: 163,
|
|
69
|
+
latitude: 32.7174,
|
|
70
|
+
longitude: -117.116_74,
|
|
71
|
+
schema: LocationSchema,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
altitude: 168,
|
|
75
|
+
latitude: 32.717_88,
|
|
76
|
+
longitude: -117.113_77,
|
|
77
|
+
schema: LocationSchema,
|
|
78
|
+
},
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
describe.skip('MongoDBLocationCertaintyDiviner', () => {
|
|
82
|
+
let payloadsArchivist: AbstractArchivist
|
|
83
|
+
let sut: LocationCertaintyDiviner
|
|
84
|
+
beforeEach(async () => {
|
|
85
|
+
payloadsArchivist = await MemoryArchivist.create({ account: 'random' })
|
|
86
|
+
const params = {
|
|
87
|
+
config: {
|
|
88
|
+
schema: LocationCertaintyDivinerConfigSchema,
|
|
89
|
+
targetSchema: LocationCertaintySchema,
|
|
90
|
+
},
|
|
91
|
+
resolver: new CompositeModuleResolver({ root: sut }).add(payloadsArchivist),
|
|
92
|
+
}
|
|
93
|
+
sut = (await LocationCertaintyDiviner.create(params)) as LocationCertaintyDiviner
|
|
94
|
+
})
|
|
95
|
+
describe('divine', () => {
|
|
96
|
+
describe('with valid query', () => {
|
|
97
|
+
it('divines', async () => {
|
|
98
|
+
const noLocations: LocationPayload[] = []
|
|
99
|
+
const noLocationsResult = await sut.divine(noLocations)
|
|
100
|
+
expect(noLocationsResult).toBeArrayOfSize(0)
|
|
101
|
+
const locations: LocationPayload[] = [
|
|
102
|
+
{
|
|
103
|
+
altitude: 5, quadkey: '0203', schema: LocationSchema,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
altitude: 300, quadkey: '0102', schema: LocationSchema,
|
|
107
|
+
},
|
|
108
|
+
]
|
|
109
|
+
const locationsResult = await sut.divine(locations)
|
|
110
|
+
expect(locationsResult).toBeArrayOfSize(1)
|
|
111
|
+
const actual = locationsResult[0] as LocationCertaintyPayload
|
|
112
|
+
expect(actual).toBeObject()
|
|
113
|
+
expect(actual.schema).toBe(LocationCertaintySchema)
|
|
114
|
+
|
|
115
|
+
const locationsResult1 = (await sut.divine(sample1)) as LocationCertaintyPayload[]
|
|
116
|
+
const locationsResult2 = (await sut.divine(sample2)) as LocationCertaintyPayload[]
|
|
117
|
+
const locationsResult3 = (await sut.divine(sample3)) as LocationCertaintyPayload[]
|
|
118
|
+
for (let r of [locationsResult1, locationsResult2, locationsResult3]) {
|
|
119
|
+
validateLocationResult(r)
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
const validateLocationResult = (results: LocationCertaintyPayload[]) => {
|
|
127
|
+
expect(results).toBeArrayOfSize(1)
|
|
128
|
+
const [result] = results
|
|
129
|
+
expect(result).toBeObject()
|
|
130
|
+
expect(result.schema).toBe(LocationCertaintySchema)
|
|
131
|
+
expect(result.altitude).toBeObject()
|
|
132
|
+
expect(result.altitude.max).toBeNumber()
|
|
133
|
+
expect(result.altitude.mean).toBeNumber()
|
|
134
|
+
expect(result.altitude.min).toBeNumber()
|
|
135
|
+
expect(result.elevation).toBeObject()
|
|
136
|
+
expect(result.elevation.max).toBeNumber()
|
|
137
|
+
expect(result.elevation.mean).toBeNumber()
|
|
138
|
+
expect(result.elevation.min).toBeNumber()
|
|
139
|
+
expect(result.variance).toBeObject()
|
|
140
|
+
expect(result.variance.max).toBeNumber()
|
|
141
|
+
expect(result.variance.mean).toBeNumber()
|
|
142
|
+
expect(result.variance.min).toBeNumber()
|
|
143
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Polyfill TextDecoder
|
|
2
|
+
import 'fast-text-encoding'
|
|
3
|
+
import '@xylabs/vitest-extended'
|
|
4
|
+
|
|
5
|
+
import { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'
|
|
6
|
+
import { PayloadSetPluginResolver } from '@xyo-network/payloadset-plugin'
|
|
7
|
+
import {
|
|
8
|
+
describe, expect,
|
|
9
|
+
test,
|
|
10
|
+
} from 'vitest'
|
|
11
|
+
|
|
12
|
+
import { LocationCertaintyDivinerConfigSchema } from '../Diviner/index.ts'
|
|
13
|
+
import { LocationCertaintyPlugin } from '../Plugin.ts'
|
|
14
|
+
|
|
15
|
+
describe('LocationCertaintyPlugin', () => {
|
|
16
|
+
test('Add to Resolver', async () => {
|
|
17
|
+
const plugin = LocationCertaintyPlugin()
|
|
18
|
+
const resolver = await new PayloadSetPluginResolver()
|
|
19
|
+
.register(plugin, { config: { schema: LocationCertaintyDivinerConfigSchema, targetSchema: LocationCertaintySchema } })
|
|
20
|
+
expect(await resolver.resolve(plugin.set)).toBeObject()
|
|
21
|
+
expect(await resolver.diviner(plugin.set)).toBeObject()
|
|
22
|
+
})
|
|
23
|
+
})
|
package/typedoc.json
DELETED