@xyo-network/archivist 2.32.1 → 2.33.0-rc.10

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/Archivist.d.ts +6 -6
  2. package/dist/cjs/Archivist.d.ts.map +1 -1
  3. package/dist/cjs/XyoArchivist.d.ts +3 -3
  4. package/dist/cjs/XyoArchivist.d.ts.map +1 -1
  5. package/dist/cjs/XyoArchivist.js +8 -1
  6. package/dist/cjs/XyoArchivist.js.map +1 -1
  7. package/dist/cjs/XyoCookieArchivist.d.ts +1 -1
  8. package/dist/cjs/XyoCookieArchivist.d.ts.map +1 -1
  9. package/dist/cjs/XyoCookieArchivist.js +9 -2
  10. package/dist/cjs/XyoCookieArchivist.js.map +1 -1
  11. package/dist/cjs/XyoMemoryArchivist.d.ts +1 -1
  12. package/dist/cjs/XyoMemoryArchivist.d.ts.map +1 -1
  13. package/dist/cjs/XyoMemoryArchivist.js +9 -2
  14. package/dist/cjs/XyoMemoryArchivist.js.map +1 -1
  15. package/dist/cjs/XyoStorageArchivist.d.ts +1 -1
  16. package/dist/cjs/XyoStorageArchivist.d.ts.map +1 -1
  17. package/dist/cjs/XyoStorageArchivist.js +9 -2
  18. package/dist/cjs/XyoStorageArchivist.js.map +1 -1
  19. package/dist/docs.json +5048 -3367
  20. package/dist/esm/Archivist.d.ts +6 -6
  21. package/dist/esm/Archivist.d.ts.map +1 -1
  22. package/dist/esm/XyoArchivist.d.ts +3 -3
  23. package/dist/esm/XyoArchivist.d.ts.map +1 -1
  24. package/dist/esm/XyoArchivist.js +5 -1
  25. package/dist/esm/XyoArchivist.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 +9 -2
  29. package/dist/esm/XyoCookieArchivist.js.map +1 -1
  30. package/dist/esm/XyoMemoryArchivist.d.ts +1 -1
  31. package/dist/esm/XyoMemoryArchivist.d.ts.map +1 -1
  32. package/dist/esm/XyoMemoryArchivist.js +9 -2
  33. package/dist/esm/XyoMemoryArchivist.js.map +1 -1
  34. package/dist/esm/XyoStorageArchivist.d.ts +1 -1
  35. package/dist/esm/XyoStorageArchivist.d.ts.map +1 -1
  36. package/dist/esm/XyoStorageArchivist.js +9 -2
  37. package/dist/esm/XyoStorageArchivist.js.map +1 -1
  38. package/package.json +7 -5
  39. package/src/Archivist.ts +19 -9
  40. package/src/XyoArchivist.ts +10 -6
  41. package/src/XyoCookieArchivist.ts +11 -4
  42. package/src/XyoMemoryArchivist.ts +10 -3
  43. package/src/XyoStorageArchivist.ts +10 -3
@@ -1,7 +1,7 @@
1
1
  import { assertEx } from '@xylabs/sdk-js'
2
2
  import { XyoBoundWitness } from '@xyo-network/boundwitness'
3
3
  import { XyoPayload, XyoPayloadWrapper } from '@xyo-network/payload'
4
- import { PromisableArray } from '@xyo-network/promisable'
4
+ import { PromisableArray } from '@xyo-network/promise'
5
5
  import Cookies from 'js-cookie'
6
6
  import compact from 'lodash/compact'
7
7
 
@@ -81,6 +81,7 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
81
81
  return true
82
82
  })
83
83
  } catch (ex) {
84
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
84
85
  throw new CookieArchivistError('delete', ex, 'unexpected')
85
86
  }
86
87
  }
@@ -93,6 +94,7 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
93
94
  }
94
95
  })
95
96
  } catch (ex) {
97
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
96
98
  throw new CookieArchivistError('clear', ex, 'unexpected')
97
99
  }
98
100
  }
@@ -106,13 +108,14 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
106
108
  }),
107
109
  )
108
110
  } catch (ex) {
111
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
109
112
  throw new CookieArchivistError('get', ex, 'unexpected')
110
113
  }
111
114
  }
112
115
 
113
116
  public async insert(payloads: XyoPayload[]): Promise<XyoBoundWitness> {
114
117
  try {
115
- const storedPayloads = payloads.map((payload) => {
118
+ const storedPayloads: XyoPayload[] = payloads.map((payload) => {
116
119
  const wrapper = new XyoPayloadWrapper(payload)
117
120
  const key = this.keyFromHash(wrapper.hash)
118
121
  const value = JSON.stringify(wrapper.payload)
@@ -120,12 +123,13 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
120
123
  Cookies.set(key, JSON.stringify(wrapper.payload))
121
124
  return wrapper.payload
122
125
  })
123
- const boundwitness = this.bindPayloads(storedPayloads)
126
+ const [boundwitness] = await this.bindPayloads(storedPayloads)
124
127
  if (this.writeThrough) {
125
128
  await this.writeToParents([boundwitness, ...storedPayloads])
126
129
  }
127
130
  return boundwitness
128
131
  } catch (ex) {
132
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
129
133
  throw new CookieArchivistError('insert', ex, 'unexpected')
130
134
  }
131
135
  }
@@ -140,6 +144,7 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
140
144
  })
141
145
  return x
142
146
  } catch (ex) {
147
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
143
148
  throw new CookieArchivistError('find', ex, 'unexpected')
144
149
  }
145
150
  }
@@ -150,6 +155,7 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
150
155
  .filter(([key]) => key.startsWith(`${this.namespace}-`))
151
156
  .map(([, value]) => JSON.parse(value))
152
157
  } catch (ex) {
158
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
153
159
  throw new CookieArchivistError('all', ex, 'unexpected')
154
160
  }
155
161
  }
@@ -158,7 +164,7 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
158
164
  try {
159
165
  const payloads = await this.all()
160
166
  assertEx(payloads.length > 0, 'Nothing to commit')
161
- const block = this.bindPayloads(payloads)
167
+ const [block] = await this.bindPayloads(payloads)
162
168
  await Promise.allSettled(
163
169
  compact(
164
170
  Object.values(this.parents?.commit ?? [])?.map(async (parent) => {
@@ -170,6 +176,7 @@ export class XyoCookieArchivist extends XyoArchivist<XyoCookieArchivistConfig> {
170
176
  await this.clear()
171
177
  return block
172
178
  } catch (ex) {
179
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
173
180
  throw new CookieArchivistError('commit', ex, 'unexpected')
174
181
  }
175
182
  }
@@ -1,7 +1,7 @@
1
1
  import { assertEx } from '@xylabs/sdk-js'
2
2
  import { XyoBoundWitness } from '@xyo-network/boundwitness'
3
3
  import { XyoPayload, XyoPayloadWrapper } from '@xyo-network/payload'
4
- import { PromisableArray } from '@xyo-network/promisable'
4
+ import { PromisableArray } from '@xyo-network/promise'
5
5
  import compact from 'lodash/compact'
6
6
  import LruCache from 'lru-cache'
7
7
 
@@ -66,6 +66,7 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
66
66
  return this.cache.delete(hash)
67
67
  })
68
68
  } catch (ex) {
69
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
69
70
  throw new MemoryArchivistError('delete', ex, 'unexpected')
70
71
  }
71
72
  }
@@ -74,6 +75,7 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
74
75
  try {
75
76
  this.cache.clear()
76
77
  } catch (ex) {
78
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
77
79
  throw new MemoryArchivistError('clear', ex, 'unexpected')
78
80
  }
79
81
  }
@@ -90,6 +92,7 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
90
92
  }),
91
93
  )
92
94
  } catch (ex) {
95
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
93
96
  throw new MemoryArchivistError('get', ex, 'unexpected')
94
97
  }
95
98
  }
@@ -102,12 +105,13 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
102
105
  this.cache.set(payloadWithmeta._hash, payloadWithmeta)
103
106
  return payloadWithmeta
104
107
  })
105
- const boundwitness = this.bindPayloads(payloads)
108
+ const [boundwitness] = await this.bindPayloads(payloads)
106
109
  if (this.writeThrough) {
107
110
  await this.writeToParents(payloads)
108
111
  }
109
112
  return boundwitness
110
113
  } catch (ex) {
114
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
111
115
  throw new MemoryArchivistError('insert', ex, 'unexpected')
112
116
  }
113
117
  }
@@ -122,6 +126,7 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
122
126
  })
123
127
  return result
124
128
  } catch (ex) {
129
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
125
130
  throw new MemoryArchivistError('find', ex, 'unexpected')
126
131
  }
127
132
  }
@@ -130,6 +135,7 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
130
135
  try {
131
136
  return this.cache.dump().map((value) => value[1].value)
132
137
  } catch (ex) {
138
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
133
139
  throw new MemoryArchivistError('all', ex, 'unexpected')
134
140
  }
135
141
  }
@@ -137,7 +143,7 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
137
143
  public async commit(): Promise<XyoBoundWitness> {
138
144
  try {
139
145
  const payloads = assertEx(await this.all(), 'Nothing to commit')
140
- const block = this.bindPayloads(payloads)
146
+ const [block] = await this.bindPayloads(payloads)
141
147
  await Promise.allSettled(
142
148
  compact(
143
149
  Object.values(this.parents?.commit ?? [])?.map(async (parent) => {
@@ -149,6 +155,7 @@ export class XyoMemoryArchivist extends XyoArchivist<XyoMemoryArchivistConfig> {
149
155
  await this.clear()
150
156
  return block
151
157
  } catch (ex) {
158
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
152
159
  throw new MemoryArchivistError('commit', ex, 'unexpected')
153
160
  }
154
161
  }
@@ -1,7 +1,7 @@
1
1
  import { assertEx } from '@xylabs/sdk-js'
2
2
  import { XyoBoundWitness } from '@xyo-network/boundwitness'
3
3
  import { XyoPayload, XyoPayloadWrapper } from '@xyo-network/payload'
4
- import { PromisableArray } from '@xyo-network/promisable'
4
+ import { PromisableArray } from '@xyo-network/promise'
5
5
  import compact from 'lodash/compact'
6
6
  import store, { StoreBase } from 'store2'
7
7
 
@@ -78,6 +78,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
78
78
  return true
79
79
  })
80
80
  } catch (ex) {
81
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
81
82
  throw new StorageArchivistError('delete', ex, 'unexpected')
82
83
  }
83
84
  }
@@ -86,6 +87,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
86
87
  try {
87
88
  this.storage.clear()
88
89
  } catch (ex) {
90
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
89
91
  throw new StorageArchivistError('clear', ex, 'unexpected')
90
92
  }
91
93
  }
@@ -99,6 +101,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
99
101
  }),
100
102
  )
101
103
  } catch (ex) {
104
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
102
105
  throw new StorageArchivistError('get', ex, 'unexpected')
103
106
  }
104
107
  }
@@ -113,12 +116,13 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
113
116
  this.storage.set(hash, wrapper.payload)
114
117
  return wrapper.payload
115
118
  })
116
- const boundwitness = this.bindPayloads(storedPayloads)
119
+ const [boundwitness] = await this.bindPayloads(storedPayloads)
117
120
  if (this.writeThrough) {
118
121
  await this.writeToParents([boundwitness, ...storedPayloads])
119
122
  }
120
123
  return boundwitness
121
124
  } catch (ex) {
125
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
122
126
  throw new StorageArchivistError('insert', ex, 'unexpected')
123
127
  }
124
128
  }
@@ -133,6 +137,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
133
137
  })
134
138
  return x
135
139
  } catch (ex) {
140
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
136
141
  throw new StorageArchivistError('find', ex, 'unexpected')
137
142
  }
138
143
  }
@@ -141,6 +146,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
141
146
  try {
142
147
  return Object.entries(this.storage.getAll()).map(([, value]) => value)
143
148
  } catch (ex) {
149
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
144
150
  throw new StorageArchivistError('all', ex, 'unexpected')
145
151
  }
146
152
  }
@@ -149,7 +155,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
149
155
  try {
150
156
  const payloads = await this.all()
151
157
  assertEx(payloads.length > 0, 'Nothing to commit')
152
- const block = this.bindPayloads(payloads)
158
+ const [block] = await this.bindPayloads(payloads)
153
159
  await Promise.allSettled(
154
160
  compact(
155
161
  Object.values(this.parents?.commit ?? [])?.map(async (parent) => {
@@ -161,6 +167,7 @@ export class XyoStorageArchivist extends XyoArchivist<XyoStorageArchivistConfig>
161
167
  await this.clear()
162
168
  return block
163
169
  } catch (ex) {
170
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`)
164
171
  throw new StorageArchivistError('commit', ex, 'unexpected')
165
172
  }
166
173
  }