@xyo-network/archivist 2.38.15 → 2.38.16

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 (77) hide show
  1. package/dist/cjs/Archivist.d.ts +3 -3
  2. package/dist/cjs/Archivist.d.ts.map +1 -1
  3. package/dist/cjs/Config.d.ts +2 -2
  4. package/dist/cjs/Config.d.ts.map +1 -1
  5. package/dist/cjs/Queries/Delete.d.ts +1 -1
  6. package/dist/cjs/Queries/Delete.d.ts.map +1 -1
  7. package/dist/cjs/Queries/Find.d.ts +1 -1
  8. package/dist/cjs/Queries/Find.d.ts.map +1 -1
  9. package/dist/cjs/Queries/Get.d.ts +1 -1
  10. package/dist/cjs/Queries/Get.d.ts.map +1 -1
  11. package/dist/cjs/Queries/Insert.d.ts +1 -1
  12. package/dist/cjs/Queries/Insert.d.ts.map +1 -1
  13. package/dist/cjs/XyoArchivist.d.ts +7 -7
  14. package/dist/cjs/XyoArchivist.d.ts.map +1 -1
  15. package/dist/cjs/XyoArchivist.js +26 -26
  16. package/dist/cjs/XyoArchivist.js.map +1 -1
  17. package/dist/cjs/XyoArchivistWrapper.d.ts +4 -4
  18. package/dist/cjs/XyoArchivistWrapper.d.ts.map +1 -1
  19. package/dist/cjs/XyoArchivistWrapper.js +24 -24
  20. package/dist/cjs/XyoArchivistWrapper.js.map +1 -1
  21. package/dist/cjs/XyoCookieArchivist.d.ts +9 -9
  22. package/dist/cjs/XyoCookieArchivist.d.ts.map +1 -1
  23. package/dist/cjs/XyoCookieArchivist.js +63 -63
  24. package/dist/cjs/XyoCookieArchivist.js.map +1 -1
  25. package/dist/cjs/XyoMemoryArchivist.d.ts +8 -8
  26. package/dist/cjs/XyoMemoryArchivist.d.ts.map +1 -1
  27. package/dist/cjs/XyoMemoryArchivist.js +51 -51
  28. package/dist/cjs/XyoMemoryArchivist.js.map +1 -1
  29. package/dist/cjs/XyoStorageArchivist.d.ts +18 -18
  30. package/dist/cjs/XyoStorageArchivist.d.ts.map +1 -1
  31. package/dist/cjs/XyoStorageArchivist.js +101 -99
  32. package/dist/cjs/XyoStorageArchivist.js.map +1 -1
  33. package/dist/docs.json +2388 -2388
  34. package/dist/esm/Archivist.d.ts +3 -3
  35. package/dist/esm/Archivist.d.ts.map +1 -1
  36. package/dist/esm/Config.d.ts +2 -2
  37. package/dist/esm/Config.d.ts.map +1 -1
  38. package/dist/esm/Queries/Delete.d.ts +1 -1
  39. package/dist/esm/Queries/Delete.d.ts.map +1 -1
  40. package/dist/esm/Queries/Find.d.ts +1 -1
  41. package/dist/esm/Queries/Find.d.ts.map +1 -1
  42. package/dist/esm/Queries/Get.d.ts +1 -1
  43. package/dist/esm/Queries/Get.d.ts.map +1 -1
  44. package/dist/esm/Queries/Insert.d.ts +1 -1
  45. package/dist/esm/Queries/Insert.d.ts.map +1 -1
  46. package/dist/esm/XyoArchivist.d.ts +7 -7
  47. package/dist/esm/XyoArchivist.d.ts.map +1 -1
  48. package/dist/esm/XyoArchivist.js +25 -25
  49. package/dist/esm/XyoArchivist.js.map +1 -1
  50. package/dist/esm/XyoArchivistWrapper.d.ts +4 -4
  51. package/dist/esm/XyoArchivistWrapper.d.ts.map +1 -1
  52. package/dist/esm/XyoArchivistWrapper.js +23 -23
  53. package/dist/esm/XyoArchivistWrapper.js.map +1 -1
  54. package/dist/esm/XyoCookieArchivist.d.ts +9 -9
  55. package/dist/esm/XyoCookieArchivist.d.ts.map +1 -1
  56. package/dist/esm/XyoCookieArchivist.js +54 -54
  57. package/dist/esm/XyoCookieArchivist.js.map +1 -1
  58. package/dist/esm/XyoMemoryArchivist.d.ts +8 -8
  59. package/dist/esm/XyoMemoryArchivist.d.ts.map +1 -1
  60. package/dist/esm/XyoMemoryArchivist.js +50 -50
  61. package/dist/esm/XyoMemoryArchivist.js.map +1 -1
  62. package/dist/esm/XyoStorageArchivist.d.ts +18 -18
  63. package/dist/esm/XyoStorageArchivist.d.ts.map +1 -1
  64. package/dist/esm/XyoStorageArchivist.js +89 -89
  65. package/dist/esm/XyoStorageArchivist.js.map +1 -1
  66. package/package.json +6 -6
  67. package/src/Archivist.ts +3 -3
  68. package/src/Config.ts +3 -2
  69. package/src/Queries/Delete.ts +1 -1
  70. package/src/Queries/Find.ts +1 -1
  71. package/src/Queries/Get.ts +1 -1
  72. package/src/Queries/Insert.ts +1 -1
  73. package/src/XyoArchivist.ts +30 -29
  74. package/src/XyoArchivistWrapper.ts +24 -24
  75. package/src/XyoCookieArchivist.ts +61 -61
  76. package/src/XyoMemoryArchivist.ts +58 -57
  77. package/src/XyoStorageArchivist.ts +98 -96
@@ -23,25 +23,23 @@ export type XyoStorageArchivistConfigSchema = 'network.xyo.module.config.archivi
23
23
  export const XyoStorageArchivistConfigSchema: XyoStorageArchivistConfigSchema = 'network.xyo.module.config.archivist.storage'
24
24
 
25
25
  export type XyoStorageArchivistConfig = XyoArchivistConfig<{
26
- schema: XyoStorageArchivistConfigSchema
27
- type?: 'local' | 'session' | 'page'
28
- namespace?: string
29
26
  maxEntries?: number
30
27
  maxEntrySize?: number
28
+ namespace?: string
31
29
  persistAccount?: boolean
30
+ schema: XyoStorageArchivistConfigSchema
31
+ type?: 'local' | 'session' | 'page'
32
32
  }>
33
33
 
34
34
  export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig> {
35
- static override async create(params?: XyoModuleParams<XyoStorageArchivistConfig>): Promise<XyoStorageArchivist> {
36
- return (await super.create(params)) as XyoStorageArchivist
37
- }
35
+ static override configSchema = XyoStorageArchivistConfigSchema
38
36
 
39
- public get type() {
40
- return this.config?.type ?? 'local'
41
- }
37
+ private _privateStorage: StoreBase | undefined
38
+ private _storage: StoreBase | undefined
42
39
 
43
- public get namespace() {
44
- return this.config?.namespace ?? 'xyo-archivist'
40
+ constructor(params?: XyoModuleParams<XyoStorageArchivistConfig>) {
41
+ super(params)
42
+ this.loadAccount()
45
43
  }
46
44
 
47
45
  public get maxEntries() {
@@ -52,87 +50,90 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
52
50
  return this.config?.maxEntries ?? 16000
53
51
  }
54
52
 
55
- public get persistAccount() {
56
- return this.config?.persistAccount ?? false
53
+ public get namespace() {
54
+ return this.config?.namespace ?? 'xyo-archivist'
57
55
  }
58
56
 
59
- public override queries() {
60
- return [
61
- XyoArchivistAllQuerySchema,
62
- XyoArchivistDeleteQuerySchema,
63
- XyoArchivistClearQuerySchema,
64
- XyoArchivistFindQuerySchema,
65
- XyoArchivistCommitQuerySchema,
66
- ...super.queries(),
67
- ]
57
+ public get persistAccount() {
58
+ return this.config?.persistAccount ?? false
68
59
  }
69
60
 
70
- /* This has to be a getter so that it can access it during construction */
71
- private _storage: StoreBase | undefined
72
- private get storage(): StoreBase {
73
- this._storage = this._storage ?? store[this.type].namespace(this.namespace)
74
- return this._storage
61
+ public get type() {
62
+ return this.config?.type ?? 'local'
75
63
  }
76
64
 
77
65
  /* This has to be a getter so that it can access it during construction */
78
- private _privateStorage: StoreBase | undefined
79
66
  private get privateStorage(): StoreBase {
80
67
  this._privateStorage = this._storage ?? store[this.type].namespace(`${this.namespace}|private`)
81
68
  return this._privateStorage
82
69
  }
83
70
 
84
- constructor(params?: XyoModuleParams<XyoStorageArchivistConfig>) {
85
- super(params)
86
- this.loadAccount()
71
+ /* This has to be a getter so that it can access it during construction */
72
+ private get storage(): StoreBase {
73
+ this._storage = this._storage ?? store[this.type].namespace(this.namespace)
74
+ return this._storage
87
75
  }
88
76
 
89
- override async start() {
90
- await super.start()
91
- this.saveAccount()
92
- return this
77
+ static override async create(params?: XyoModuleParams<XyoStorageArchivistConfig>): Promise<XyoStorageArchivist> {
78
+ return (await super.create(params)) as XyoStorageArchivist
93
79
  }
94
80
 
95
- protected override loadAccount() {
96
- if (this.persistAccount) {
97
- const privateKey = this.privateStorage.get('privateKey')
98
- if (privateKey) {
99
- try {
100
- const account = new XyoAccount({ privateKey })
101
- this.logger?.log(account.addressValue.hex)
102
- return account
103
- } catch (ex) {
104
- console.error(`Error reading Account from storage [${this.type}, ${ex}] - Recreating Account`)
105
- this.privateStorage.remove('privateKey')
106
- }
107
- }
81
+ public override all(): PromisableArray<XyoPayload> {
82
+ this.logger?.log(`this.storage.length: ${this.storage.length}`)
83
+ try {
84
+ return Object.entries(this.storage.getAll()).map(([, value]) => value)
85
+ } catch (ex) {
86
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
87
+ throw ex
108
88
  }
109
- return super.loadAccount()
110
89
  }
111
90
 
112
- protected saveAccount() {
113
- if (this.persistAccount) {
114
- this.logger?.log(this.account.addressValue.hex)
115
- this.privateStorage.set('privateKey', this.account.private.hex)
91
+ public override clear(): void | Promise<void> {
92
+ this.logger?.log(`this.storage.length: ${this.storage.length}`)
93
+ try {
94
+ this.storage.clear()
95
+ } catch (ex) {
96
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
97
+ throw ex
116
98
  }
117
99
  }
118
100
 
119
- public override delete(hashes: string[]): PromisableArray<boolean> {
120
- this.logger?.log(`hashes.length: ${hashes.length}`)
101
+ public override async commit(): Promise<XyoBoundWitness[]> {
102
+ this.logger?.log(`this.storage.length: ${this.storage.length}`)
121
103
  try {
122
- return hashes.map((hash) => {
123
- this.storage.remove(hash)
124
- return true
125
- })
104
+ const payloads = await this.all()
105
+ assertEx(payloads.length > 0, 'Nothing to commit')
106
+ const settled = await Promise.allSettled(
107
+ compact(
108
+ Object.values(this.parents?.commit ?? [])?.map(async (parent) => {
109
+ const queryPayload = PayloadWrapper.parse<XyoArchivistInsertQuery>({
110
+ payloads: payloads.map((payload) => PayloadWrapper.hash(payload)),
111
+ schema: XyoArchivistInsertQuerySchema,
112
+ })
113
+ const query = await this.bindQuery(queryPayload)
114
+ return (await parent?.query(query[0], query[1]))?.[0]
115
+ }),
116
+ ),
117
+ )
118
+ await this.clear()
119
+ return compact(
120
+ settled.map((result) => {
121
+ return result.status === 'fulfilled' ? result.value : null
122
+ }),
123
+ )
126
124
  } catch (ex) {
127
125
  console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
128
126
  throw ex
129
127
  }
130
128
  }
131
129
 
132
- public override clear(): void | Promise<void> {
133
- this.logger?.log(`this.storage.length: ${this.storage.length}`)
130
+ public override delete(hashes: string[]): PromisableArray<boolean> {
131
+ this.logger?.log(`hashes.length: ${hashes.length}`)
134
132
  try {
135
- this.storage.clear()
133
+ return hashes.map((hash) => {
134
+ this.storage.remove(hash)
135
+ return true
136
+ })
136
137
  } catch (ex) {
137
138
  console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
138
139
  throw ex
@@ -178,43 +179,44 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
178
179
  }
179
180
  }
180
181
 
181
- public override all(): PromisableArray<XyoPayload> {
182
- this.logger?.log(`this.storage.length: ${this.storage.length}`)
183
- try {
184
- return Object.entries(this.storage.getAll()).map(([, value]) => value)
185
- } catch (ex) {
186
- console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
187
- throw ex
182
+ public override queries() {
183
+ return [
184
+ XyoArchivistAllQuerySchema,
185
+ XyoArchivistDeleteQuerySchema,
186
+ XyoArchivistClearQuerySchema,
187
+ XyoArchivistFindQuerySchema,
188
+ XyoArchivistCommitQuerySchema,
189
+ ...super.queries(),
190
+ ]
191
+ }
192
+
193
+ override async start() {
194
+ await super.start()
195
+ this.saveAccount()
196
+ return this
197
+ }
198
+
199
+ protected override loadAccount() {
200
+ if (this.persistAccount) {
201
+ const privateKey = this.privateStorage.get('privateKey')
202
+ if (privateKey) {
203
+ try {
204
+ const account = new XyoAccount({ privateKey })
205
+ this.logger?.log(account.addressValue.hex)
206
+ return account
207
+ } catch (ex) {
208
+ console.error(`Error reading Account from storage [${this.type}, ${ex}] - Recreating Account`)
209
+ this.privateStorage.remove('privateKey')
210
+ }
211
+ }
188
212
  }
213
+ return super.loadAccount()
189
214
  }
190
215
 
191
- public override async commit(): Promise<XyoBoundWitness[]> {
192
- this.logger?.log(`this.storage.length: ${this.storage.length}`)
193
- try {
194
- const payloads = await this.all()
195
- assertEx(payloads.length > 0, 'Nothing to commit')
196
- const settled = await Promise.allSettled(
197
- compact(
198
- Object.values(this.parents?.commit ?? [])?.map(async (parent) => {
199
- const queryPayload = PayloadWrapper.parse<XyoArchivistInsertQuery>({
200
- payloads: payloads.map((payload) => PayloadWrapper.hash(payload)),
201
- schema: XyoArchivistInsertQuerySchema,
202
- })
203
- const query = await this.bindQuery(queryPayload)
204
- return (await parent?.query(query[0], query[1]))?.[0]
205
- }),
206
- ),
207
- )
208
- await this.clear()
209
- return compact(
210
- settled.map((result) => {
211
- return result.status === 'fulfilled' ? result.value : null
212
- }),
213
- )
214
- } catch (ex) {
215
- console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
216
- throw ex
216
+ protected saveAccount() {
217
+ if (this.persistAccount) {
218
+ this.logger?.log(this.account.addressValue.hex)
219
+ this.privateStorage.set('privateKey', this.account.private.hex)
217
220
  }
218
221
  }
219
- static override configSchema = XyoStorageArchivistConfigSchema
220
222
  }