@xyo-network/id-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/package.json +18 -14
- package/src/spec/Plugin.spec.ts +18 -0
- package/src/spec/Witness.dom.spec.ts +33 -0
- package/src/spec/Witness.spec.ts +86 -0
- package/typedoc.json +0 -5
- package/xy.config.ts +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/id-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,22 +28,26 @@
|
|
|
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
|
-
"@xylabs/promise": "
|
|
33
|
-
"@xyo-network/abstract-witness": "
|
|
34
|
-
"@xyo-network/id-payload-plugin": "
|
|
35
|
-
"@xyo-network/module-model": "
|
|
36
|
-
"@xyo-network/payload-model": "
|
|
37
|
-
"@xyo-network/payloadset-plugin": "
|
|
38
|
-
"@xyo-network/witness-model": "
|
|
36
|
+
"@xylabs/promise": "~5.0.7",
|
|
37
|
+
"@xyo-network/abstract-witness": "~5.0.2",
|
|
38
|
+
"@xyo-network/id-payload-plugin": "~5.0.2",
|
|
39
|
+
"@xyo-network/module-model": "~5.0.2",
|
|
40
|
+
"@xyo-network/payload-model": "~5.0.2",
|
|
41
|
+
"@xyo-network/payloadset-plugin": "~5.0.2",
|
|
42
|
+
"@xyo-network/witness-model": "~5.0.2"
|
|
39
43
|
},
|
|
40
44
|
"devDependencies": {
|
|
41
|
-
"@xylabs/ts-scripts-yarn3": "
|
|
42
|
-
"@xylabs/tsconfig": "
|
|
43
|
-
"@xylabs/vitest-extended": "
|
|
44
|
-
"@xyo-network/payload-wrapper": "
|
|
45
|
-
"typescript": "
|
|
46
|
-
"vitest": "
|
|
45
|
+
"@xylabs/ts-scripts-yarn3": "~7.1.0",
|
|
46
|
+
"@xylabs/tsconfig": "~7.1.0",
|
|
47
|
+
"@xylabs/vitest-extended": "~5.0.7",
|
|
48
|
+
"@xyo-network/payload-wrapper": "~5.0.2",
|
|
49
|
+
"typescript": "~5.9.2",
|
|
50
|
+
"vitest": "~3.2.4"
|
|
47
51
|
},
|
|
48
52
|
"publishConfig": {
|
|
49
53
|
"access": "public"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import { PayloadSetPluginResolver } from '@xyo-network/payloadset-plugin'
|
|
4
|
+
import {
|
|
5
|
+
describe, expect,
|
|
6
|
+
test,
|
|
7
|
+
} from 'vitest'
|
|
8
|
+
|
|
9
|
+
import { IdPlugin } from '../Plugin.ts'
|
|
10
|
+
|
|
11
|
+
describe('IdPlugin', () => {
|
|
12
|
+
test('Add to Resolver', async () => {
|
|
13
|
+
const plugin = IdPlugin()
|
|
14
|
+
const resolver = await new PayloadSetPluginResolver().register(plugin)
|
|
15
|
+
expect(await resolver.resolve(plugin.set)).toBeObject()
|
|
16
|
+
expect(await resolver.witness(plugin.set)).toBeObject()
|
|
17
|
+
})
|
|
18
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import { IdSchema } from '@xyo-network/id-payload-plugin'
|
|
4
|
+
import type { Payload } from '@xyo-network/payload-model'
|
|
5
|
+
import { PayloadWrapper } from '@xyo-network/payload-wrapper'
|
|
6
|
+
import {
|
|
7
|
+
describe, expect,
|
|
8
|
+
test,
|
|
9
|
+
} from 'vitest'
|
|
10
|
+
|
|
11
|
+
import { IdWitness, IdWitnessConfigSchema } from '../Witness.ts'
|
|
12
|
+
|
|
13
|
+
describe('IdWitness [Browser]', () => {
|
|
14
|
+
test('observe', async () => {
|
|
15
|
+
const witness = await IdWitness.create({
|
|
16
|
+
account: 'random',
|
|
17
|
+
config: { salt: 'test', schema: IdWitnessConfigSchema },
|
|
18
|
+
})
|
|
19
|
+
const [observation] = await witness.observe([{ salt: 'test', schema: IdSchema } as Payload])
|
|
20
|
+
expect(observation.schema).toBe(IdSchema)
|
|
21
|
+
expect(await PayloadWrapper.wrap(observation).getValid()).toBe(true)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('observe [no salt]', async () => {
|
|
25
|
+
const witness = await IdWitness.create({
|
|
26
|
+
account: 'random',
|
|
27
|
+
config: { schema: IdWitnessConfigSchema },
|
|
28
|
+
})
|
|
29
|
+
const [observation] = await witness.observe([{ salt: 'test', schema: IdSchema } as Payload])
|
|
30
|
+
expect(observation.schema).toBe(IdSchema)
|
|
31
|
+
expect(await PayloadWrapper.wrap(observation).getValid()).toBe(true)
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import type { Id } from '@xyo-network/id-payload-plugin'
|
|
4
|
+
import { IdSchema } from '@xyo-network/id-payload-plugin'
|
|
5
|
+
import type { Payload } from '@xyo-network/payload-model'
|
|
6
|
+
import { PayloadWrapper } from '@xyo-network/payload-wrapper'
|
|
7
|
+
import {
|
|
8
|
+
describe, expect,
|
|
9
|
+
it,
|
|
10
|
+
} from 'vitest'
|
|
11
|
+
|
|
12
|
+
import { IdWitness, IdWitnessConfigSchema } from '../Witness.ts'
|
|
13
|
+
|
|
14
|
+
describe('IdWitness', () => {
|
|
15
|
+
describe('observe', () => {
|
|
16
|
+
const payloadSalt = 'payload salt'
|
|
17
|
+
describe('with config', () => {
|
|
18
|
+
const configSalt = 'config salt'
|
|
19
|
+
const config = {
|
|
20
|
+
salt: configSalt,
|
|
21
|
+
schema: IdWitnessConfigSchema,
|
|
22
|
+
targetSchema: IdSchema,
|
|
23
|
+
}
|
|
24
|
+
describe('with payloads supplied to observe', () => {
|
|
25
|
+
it('without salt uses config salt', async () => {
|
|
26
|
+
const witness = await IdWitness.create({ account: 'random', config })
|
|
27
|
+
const observations = (await witness.observe()) as Id[]
|
|
28
|
+
await validateObservationShape(observations)
|
|
29
|
+
const [observation] = observations
|
|
30
|
+
expect(observation.salt).toBe(witness.config.salt)
|
|
31
|
+
})
|
|
32
|
+
it('with salt uses payload salt', async () => {
|
|
33
|
+
const witness = await IdWitness.create({ account: 'random', config })
|
|
34
|
+
const observations = (await witness.observe([{ salt: payloadSalt, schema: IdSchema }] as Id[])) as Id[]
|
|
35
|
+
await validateObservationShape(observations)
|
|
36
|
+
const [observation] = observations
|
|
37
|
+
expect(observation.salt).toBe(payloadSalt)
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
describe('with no payloads supplied to observe', () => {
|
|
41
|
+
it('uses config salt', async () => {
|
|
42
|
+
const witness = await IdWitness.create({ account: 'random', config })
|
|
43
|
+
const observations = (await witness.observe()) as Id[]
|
|
44
|
+
await validateObservationShape(observations)
|
|
45
|
+
const [observation] = observations
|
|
46
|
+
expect(observation.salt).toBe(witness.config.salt)
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
describe('with no config', () => {
|
|
51
|
+
describe('with payloads supplied to observe', () => {
|
|
52
|
+
it('without salt uses random numeric string', async () => {
|
|
53
|
+
const witness = await IdWitness.create({ account: 'random' })
|
|
54
|
+
const observations = (await witness.observe()) as Id[]
|
|
55
|
+
await validateObservationShape(observations)
|
|
56
|
+
const [observation] = observations
|
|
57
|
+
expect(Number.parseInt(observation.salt)).toBeInteger()
|
|
58
|
+
})
|
|
59
|
+
it('with salt uses payload salt', async () => {
|
|
60
|
+
const witness = await IdWitness.create({ account: 'random' })
|
|
61
|
+
const observations = (await witness.observe([{ salt: payloadSalt, schema: IdSchema } as Payload])) as Id[]
|
|
62
|
+
await validateObservationShape(observations)
|
|
63
|
+
const [observation] = observations
|
|
64
|
+
expect(observation.salt).toBe(payloadSalt)
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
describe('with no payloads supplied to observe', () => {
|
|
68
|
+
it('uses random numeric string', async () => {
|
|
69
|
+
const witness = await IdWitness.create({ account: 'random' })
|
|
70
|
+
const observations = (await witness.observe()) as Id[]
|
|
71
|
+
await validateObservationShape(observations)
|
|
72
|
+
const [observation] = observations
|
|
73
|
+
expect(Number.parseInt(observation.salt)).toBeInteger()
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const validateObservationShape = async (observations: Id[]) => {
|
|
81
|
+
expect(observations).toBeArrayOfSize(1)
|
|
82
|
+
const [observation] = observations
|
|
83
|
+
expect(observation.salt).toBeString()
|
|
84
|
+
expect(observation.schema).toBe(IdSchema)
|
|
85
|
+
expect(await PayloadWrapper.wrap(observation).getValid()).toBe(true)
|
|
86
|
+
}
|
package/typedoc.json
DELETED