@xyo-network/archivist 2.38.0-rc.9 → 2.38.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 (43) hide show
  1. package/dist/cjs/XyoArchivist.d.ts +1 -2
  2. package/dist/cjs/XyoArchivist.d.ts.map +1 -1
  3. package/dist/cjs/XyoArchivist.js +36 -30
  4. package/dist/cjs/XyoArchivist.js.map +1 -1
  5. package/dist/cjs/XyoArchivistWrapper.d.ts.map +1 -1
  6. package/dist/cjs/XyoArchivistWrapper.js +18 -7
  7. package/dist/cjs/XyoArchivistWrapper.js.map +1 -1
  8. package/dist/cjs/XyoCookieArchivist.d.ts +1 -1
  9. package/dist/cjs/XyoCookieArchivist.d.ts.map +1 -1
  10. package/dist/cjs/XyoCookieArchivist.js.map +1 -1
  11. package/dist/cjs/XyoMemoryArchivist.d.ts +3 -4
  12. package/dist/cjs/XyoMemoryArchivist.d.ts.map +1 -1
  13. package/dist/cjs/XyoMemoryArchivist.js.map +1 -1
  14. package/dist/cjs/XyoStorageArchivist.d.ts +3 -3
  15. package/dist/cjs/XyoStorageArchivist.d.ts.map +1 -1
  16. package/dist/cjs/XyoStorageArchivist.js +2 -2
  17. package/dist/cjs/XyoStorageArchivist.js.map +1 -1
  18. package/dist/docs.json +4026 -2946
  19. package/dist/esm/XyoArchivist.d.ts +1 -2
  20. package/dist/esm/XyoArchivist.d.ts.map +1 -1
  21. package/dist/esm/XyoArchivist.js +37 -31
  22. package/dist/esm/XyoArchivist.js.map +1 -1
  23. package/dist/esm/XyoArchivistWrapper.d.ts.map +1 -1
  24. package/dist/esm/XyoArchivistWrapper.js +18 -7
  25. package/dist/esm/XyoArchivistWrapper.js.map +1 -1
  26. package/dist/esm/XyoCookieArchivist.d.ts +1 -1
  27. package/dist/esm/XyoCookieArchivist.d.ts.map +1 -1
  28. package/dist/esm/XyoCookieArchivist.js.map +1 -1
  29. package/dist/esm/XyoMemoryArchivist.d.ts +3 -4
  30. package/dist/esm/XyoMemoryArchivist.d.ts.map +1 -1
  31. package/dist/esm/XyoMemoryArchivist.js.map +1 -1
  32. package/dist/esm/XyoStorageArchivist.d.ts +3 -3
  33. package/dist/esm/XyoStorageArchivist.d.ts.map +1 -1
  34. package/dist/esm/XyoStorageArchivist.js +2 -2
  35. package/dist/esm/XyoStorageArchivist.js.map +1 -1
  36. package/package.json +6 -7
  37. package/src/XyoArchivist.ts +36 -33
  38. package/src/XyoArchivistWrapper.ts +18 -7
  39. package/src/XyoCookieArchivist.spec.ts +3 -9
  40. package/src/XyoCookieArchivist.ts +2 -2
  41. package/src/XyoMemoryArchivist.ts +4 -6
  42. package/src/XyoStorageArchivist.spec.ts +10 -13
  43. package/src/XyoStorageArchivist.ts +6 -6
@@ -25,20 +25,24 @@ export class XyoArchivistWrapper extends XyoModuleWrapper implements PayloadArch
25
25
  public async delete(hashes: string[]) {
26
26
  const queryPayload = PayloadWrapper.parse<XyoArchivistDeleteQuery>({ hashes, schema: XyoArchivistDeleteQuerySchema })
27
27
  const query = await this.bindQuery(queryPayload)
28
- await this.module.query(query[0], query[1])
29
- return (await this.module.query(query[0], query[1]))[0].payload_hashes.map(() => true)
28
+ const result = await this.module.query(query[0], query[1])
29
+ this.throwErrors(query, result)
30
+ return result[0].payload_hashes.map(() => true)
30
31
  }
31
32
 
32
33
  public async clear(): Promise<void> {
33
34
  const queryPayload = PayloadWrapper.parse<XyoArchivistClearQuery>({ schema: XyoArchivistClearQuerySchema })
34
35
  const query = await this.bindQuery(queryPayload)
35
- await this.module.query(query[0], query[1])
36
+ const result = await this.module.query(query[0], query[1])
37
+ this.throwErrors(query, result)
36
38
  }
37
39
 
38
40
  public async get(hashes: string[]): Promise<(XyoPayload | null)[]> {
39
41
  const queryPayload = PayloadWrapper.parse<XyoArchivistGetQuery>({ hashes, schema: XyoArchivistGetQuerySchema })
40
42
  const query = await this.bindQuery(queryPayload)
41
- return (await this.module.query(query[0], query[1]))[1]
43
+ const result = await this.module.query(query[0], query[1])
44
+ this.throwErrors(query, result)
45
+ return result[1]
42
46
  }
43
47
 
44
48
  public async insert(payloads: XyoPayload[]): Promise<XyoBoundWitness[]> {
@@ -50,24 +54,31 @@ export class XyoArchivistWrapper extends XyoModuleWrapper implements PayloadArch
50
54
  const result = await this.module.query(query[0], [queryPayload.payload, ...payloads])
51
55
  const innerBoundWitnesses =
52
56
  result[1]?.filter<XyoBoundWitness>((payload): payload is XyoBoundWitness => payload?.schema === XyoBoundWitnessSchema) ?? []
57
+ this.throwErrors(query, result)
53
58
  return [result[0], ...innerBoundWitnesses]
54
59
  }
55
60
 
56
61
  public async find(filter?: XyoPayloadFindFilter): Promise<XyoPayload[]> {
57
62
  const queryPayload = PayloadWrapper.parse<XyoArchivistFindQuery>({ filter, schema: XyoArchivistFindQuerySchema })
58
63
  const query = await this.bindQuery(queryPayload)
59
- return compact((await this.module.query(query[0], [queryPayload.payload]))[1])
64
+ const result = await this.module.query(query[0], [queryPayload.payload])
65
+ this.throwErrors(query, result)
66
+ return compact(result[1])
60
67
  }
61
68
 
62
69
  public async all(): Promise<XyoPayload[]> {
63
70
  const queryPayload = PayloadWrapper.parse<XyoArchivistAllQuery>({ schema: XyoArchivistAllQuerySchema })
64
71
  const query = await this.bindQuery(queryPayload)
65
- return compact((await this.module.query(query[0], query[1]))[1])
72
+ const result = await this.module.query(query[0], query[1])
73
+ this.throwErrors(query, result)
74
+ return compact(result[1])
66
75
  }
67
76
 
68
77
  public async commit(): Promise<XyoBoundWitness[]> {
69
78
  const queryPayload = PayloadWrapper.parse<XyoArchivistCommitQuery>({ schema: XyoArchivistCommitQuerySchema })
70
79
  const query = await this.bindQuery(queryPayload)
71
- return (await this.module.query(query[0], query[1]))[1] as XyoBoundWitness[]
80
+ const result = await this.module.query(query[0], query[1])
81
+ this.throwErrors(query, result)
82
+ return result[1] as XyoBoundWitness[]
72
83
  }
73
84
  }
@@ -3,13 +3,7 @@
3
3
  */
4
4
 
5
5
  import { testArchivistAll, testArchivistRoundTrip } from './test.spec.test'
6
- import { XyoCookieArchivist, XyoCookieArchivistConfig, XyoCookieArchivistConfigSchema } from './XyoCookieArchivist'
6
+ import { XyoCookieArchivist, XyoCookieArchivistConfigSchema } from './XyoCookieArchivist'
7
7
 
8
- testArchivistRoundTrip(
9
- XyoCookieArchivist.create({ config: { namespace: 'test', schema: XyoCookieArchivistConfigSchema } as XyoCookieArchivistConfig }),
10
- 'cookie',
11
- )
12
- testArchivistAll(
13
- XyoCookieArchivist.create({ config: { namespace: 'test', schema: XyoCookieArchivistConfigSchema } as XyoCookieArchivistConfig }),
14
- 'cookie',
15
- )
8
+ testArchivistRoundTrip(XyoCookieArchivist.create({ config: { namespace: 'test', schema: XyoCookieArchivistConfigSchema } }), 'cookie')
9
+ testArchivistAll(XyoCookieArchivist.create({ config: { namespace: 'test', schema: XyoCookieArchivistConfigSchema } }), 'cookie')
@@ -30,8 +30,8 @@ export type XyoCookieArchivistConfig = XyoArchivistConfig<{
30
30
  }>
31
31
 
32
32
  export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
33
- static override async create(params?: XyoModuleParams): Promise<XyoCookieArchivist> {
34
- const module = new XyoCookieArchivist(params as XyoModuleParams<XyoCookieArchivistConfig>)
33
+ static override async create(params?: XyoModuleParams<XyoCookieArchivistConfig>): Promise<XyoCookieArchivist> {
34
+ const module = new XyoCookieArchivist(params)
35
35
  await module.start()
36
36
  return module
37
37
  }
@@ -16,7 +16,7 @@ import {
16
16
  XyoArchivistInsertQuery,
17
17
  XyoArchivistInsertQuerySchema,
18
18
  } from './Queries'
19
- import { XyoArchivist, XyoArchivistParams } from './XyoArchivist'
19
+ import { XyoArchivist } from './XyoArchivist'
20
20
 
21
21
  export type XyoMemoryArchivistConfigSchema = 'network.xyo.module.config.archivist.memory'
22
22
  export const XyoMemoryArchivistConfigSchema: XyoMemoryArchivistConfigSchema = 'network.xyo.module.config.archivist.memory'
@@ -26,15 +26,13 @@ export type XyoMemoryArchivistConfig = XyoArchivistConfig<{
26
26
  max?: number
27
27
  }>
28
28
 
29
- export type XyoMemoryArchivistParams<TConfig extends XyoMemoryArchivistConfig = XyoMemoryArchivistConfig> = XyoArchivistParams<TConfig>
30
-
31
29
  export class XyoMemoryArchivist<TConfig extends XyoMemoryArchivistConfig = XyoMemoryArchivistConfig> extends XyoArchivist<TConfig> {
32
30
  public get max() {
33
31
  return this.config?.max ?? 10000
34
32
  }
35
33
 
36
- static override async create(params?: XyoModuleParams): Promise<XyoMemoryArchivist> {
37
- const module: XyoMemoryArchivist = new XyoMemoryArchivist(params as XyoMemoryArchivistParams)
34
+ static override async create(params?: XyoModuleParams<XyoMemoryArchivistConfig>): Promise<XyoMemoryArchivist> {
35
+ const module: XyoMemoryArchivist = new XyoMemoryArchivist(params)
38
36
  await module.start()
39
37
  return module
40
38
  }
@@ -52,7 +50,7 @@ export class XyoMemoryArchivist<TConfig extends XyoMemoryArchivistConfig = XyoMe
52
50
  ]
53
51
  }
54
52
 
55
- protected constructor(params?: XyoMemoryArchivistParams<TConfig>) {
53
+ protected constructor(params?: XyoModuleParams<TConfig>) {
56
54
  super(params)
57
55
  this.cache = new LruCache<string, XyoPayload>({ max: this.max })
58
56
  }
@@ -7,52 +7,49 @@ import { PayloadWrapper } from '@xyo-network/payload'
7
7
 
8
8
  import { testArchivistAll, testArchivistRoundTrip } from './test.spec.test'
9
9
  import { XyoMemoryArchivist } from './XyoMemoryArchivist'
10
- import { XyoStorageArchivist, XyoStorageArchivistConfig, XyoStorageArchivistConfigSchema } from './XyoStorageArchivist'
10
+ import { XyoStorageArchivist, XyoStorageArchivistConfigSchema } from './XyoStorageArchivist'
11
11
 
12
- testArchivistRoundTrip(
13
- XyoStorageArchivist.create({ config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'local' } as XyoStorageArchivistConfig }),
14
- 'local',
15
- )
12
+ testArchivistRoundTrip(XyoStorageArchivist.create({ config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'local' } }), 'local')
16
13
  testArchivistRoundTrip(
17
14
  XyoStorageArchivist.create({
18
- config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'session' } as XyoStorageArchivistConfig,
15
+ config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'session' },
19
16
  }),
20
17
  'session',
21
18
  )
22
19
  testArchivistRoundTrip(
23
20
  XyoStorageArchivist.create({
24
- config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'page' } as XyoStorageArchivistConfig,
21
+ config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'page' },
25
22
  }),
26
23
  'page',
27
24
  )
28
25
 
29
26
  testArchivistAll(
30
27
  XyoStorageArchivist.create({
31
- config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'local' } as XyoStorageArchivistConfig,
28
+ config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'local' },
32
29
  }),
33
30
  'local',
34
31
  )
35
32
  testArchivistAll(
36
33
  XyoStorageArchivist.create({
37
- config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'session' } as XyoStorageArchivistConfig,
34
+ config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'session' },
38
35
  }),
39
36
  'session',
40
37
  )
41
38
  testArchivistAll(
42
39
  XyoStorageArchivist.create({
43
- config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'page' } as XyoStorageArchivistConfig,
40
+ config: { namespace: 'test', schema: XyoStorageArchivistConfigSchema, type: 'page' },
44
41
  }),
45
42
  'page',
46
43
  )
47
44
 
48
45
  test('XyoArchivist Private Key Save', async () => {
49
46
  const storage = await XyoStorageArchivist.create({
50
- config: { namespace: 'test', persistAccount: true, schema: XyoStorageArchivistConfigSchema, type: 'local' } as XyoStorageArchivistConfig,
47
+ config: { namespace: 'test', persistAccount: true, schema: XyoStorageArchivistConfigSchema, type: 'local' },
51
48
  logger: console,
52
49
  })
53
50
  const address = storage.address
54
51
  const storage2 = await XyoStorageArchivist.create({
55
- config: { namespace: 'test', persistAccount: true, schema: XyoStorageArchivistConfigSchema, type: 'local' } as XyoStorageArchivistConfig,
52
+ config: { namespace: 'test', persistAccount: true, schema: XyoStorageArchivistConfigSchema, type: 'local' },
56
53
  logger: console,
57
54
  })
58
55
  expect(storage2.address).toBe(address)
@@ -68,7 +65,7 @@ test('XyoArchivist Parent Write Through', async () => {
68
65
  persistAccount: true,
69
66
  schema: XyoStorageArchivistConfigSchema,
70
67
  type: 'local',
71
- } as XyoStorageArchivistConfig,
68
+ },
72
69
  logger: console,
73
70
  resolver: new XyoModuleResolver().add(memory),
74
71
  })
@@ -17,7 +17,7 @@ import {
17
17
  XyoArchivistInsertQuery,
18
18
  XyoArchivistInsertQuerySchema,
19
19
  } from './Queries'
20
- import { XyoArchivist, XyoArchivistParams } from './XyoArchivist'
20
+ import { XyoArchivist } from './XyoArchivist'
21
21
 
22
22
  export type XyoStorageArchivistConfigSchema = 'network.xyo.module.config.archivist.storage'
23
23
  export const XyoStorageArchivistConfigSchema: XyoStorageArchivistConfigSchema = 'network.xyo.module.config.archivist.storage'
@@ -32,8 +32,8 @@ export type XyoStorageArchivistConfig = XyoArchivistConfig<{
32
32
  }>
33
33
 
34
34
  export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig> {
35
- static override async create(params?: XyoModuleParams): Promise<XyoStorageArchivist> {
36
- const module = new XyoStorageArchivist(params as XyoModuleParams<XyoStorageArchivistConfig>)
35
+ static override async create(params?: XyoModuleParams<XyoStorageArchivistConfig>): Promise<XyoStorageArchivist> {
36
+ const module = new XyoStorageArchivist(params)
37
37
  await module.start()
38
38
  return module
39
39
  }
@@ -83,7 +83,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
83
83
  return this._privateStorage
84
84
  }
85
85
 
86
- constructor(params?: XyoArchivistParams<XyoStorageArchivistConfig>) {
86
+ constructor(params?: XyoModuleParams<XyoStorageArchivistConfig>) {
87
87
  super(params)
88
88
  this.loadAccount()
89
89
  }
@@ -100,7 +100,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
100
100
  if (privateKey) {
101
101
  try {
102
102
  const account = new XyoAccount({ privateKey })
103
- this.logger?.log(account.addressValue.hex, 'loadAccount')
103
+ this.logger?.log(account.addressValue.hex)
104
104
  return account
105
105
  } catch (ex) {
106
106
  console.error(`Error reading Account from storage [${this.type}, ${ex}] - Recreating Account`)
@@ -113,7 +113,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
113
113
 
114
114
  protected saveAccount() {
115
115
  if (this.persistAccount) {
116
- this.logger?.log(this.account.addressValue.hex, 'saveAccount')
116
+ this.logger?.log(this.account.addressValue.hex)
117
117
  this.privateStorage.set('privateKey', this.account.private.hex)
118
118
  }
119
119
  }