@seedprotocol/sdk 0.2.51 → 0.2.52

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 (205) hide show
  1. package/dist/{ArweaveClient-D1TsTBoj.js → ArweaveClient-D5iJisYr.js} +2 -2
  2. package/dist/{ArweaveClient-DpdXUcVJ.js.map → ArweaveClient-D5iJisYr.js.map} +1 -1
  3. package/dist/{ArweaveClient-DpdXUcVJ.js → ArweaveClient-HEIIuOfB.js} +2 -2
  4. package/dist/{ArweaveClient-D1TsTBoj.js.map → ArweaveClient-HEIIuOfB.js.map} +1 -1
  5. package/dist/{Db-quJxmvHH.js → Db-D-BsZYlN.js} +3 -3
  6. package/dist/{Db-quJxmvHH.js.map → Db-D-BsZYlN.js.map} +1 -1
  7. package/dist/{Db-DMJ0v3gO.js → Db-Dpsbk_T7.js} +3 -3
  8. package/dist/{Db-DMJ0v3gO.js.map → Db-Dpsbk_T7.js.map} +1 -1
  9. package/dist/{EasClient-ClZDuT3o.js → EasClient-D3wKgt0o.js} +2 -2
  10. package/dist/{EasClient-DfnGY_2X.js.map → EasClient-D3wKgt0o.js.map} +1 -1
  11. package/dist/{EasClient-DfnGY_2X.js → EasClient-jqkT2ZBt.js} +2 -2
  12. package/dist/{EasClient-ClZDuT3o.js.map → EasClient-jqkT2ZBt.js.map} +1 -1
  13. package/dist/{FileManager-texI7UwL.js → FileManager-4mWYO3Mt.js} +3 -5
  14. package/dist/FileManager-4mWYO3Mt.js.map +1 -0
  15. package/dist/{Item-D4n439Ei.js → Item-CqWdJsyg.js} +3 -3
  16. package/dist/{Item-D4n439Ei.js.map → Item-CqWdJsyg.js.map} +1 -1
  17. package/dist/{ItemProperty-Be5ymRVT.js → ItemProperty-BpBW3IWx.js} +3 -3
  18. package/dist/{ItemProperty-Be5ymRVT.js.map → ItemProperty-BpBW3IWx.js.map} +1 -1
  19. package/dist/{QueryClient-B1HkAaJo.js → QueryClient-CBOP3OoU.js} +2 -2
  20. package/dist/{QueryClient-B1HkAaJo.js.map → QueryClient-CBOP3OoU.js.map} +1 -1
  21. package/dist/{QueryClient-BPoc9eBn.js → QueryClient-bKb3SB0W.js} +2 -2
  22. package/dist/{QueryClient-BPoc9eBn.js.map → QueryClient-bKb3SB0W.js.map} +1 -1
  23. package/dist/bin.js +5 -5
  24. package/dist/{constants-5PxfAeqj.js → constants-CIDbABDz.js} +2 -2
  25. package/dist/{constants-5PxfAeqj.js.map → constants-CIDbABDz.js.map} +1 -1
  26. package/dist/{index-BeKRizLf.js → index-BRxO1tLl.js} +257 -145
  27. package/dist/index-BRxO1tLl.js.map +1 -0
  28. package/dist/{index-BLla2o05.js → index-d8Qsot6w.js} +3 -3
  29. package/dist/index-d8Qsot6w.js.map +1 -0
  30. package/dist/main.js +2 -2
  31. package/dist/package.json +189 -0
  32. package/dist/{seed.schema.config-CMpV_hyS.js → seed.schema.config-CPRn6KVL.js} +3 -3
  33. package/dist/{seed.schema.config-CMpV_hyS.js.map → seed.schema.config-CPRn6KVL.js.map} +1 -1
  34. package/dist/types/src/client/BaseClientManager.d.ts +7 -0
  35. package/dist/types/src/client/BaseClientManager.d.ts.map +1 -0
  36. package/dist/types/src/client/actions/setAddresses.d.ts +2 -0
  37. package/dist/types/src/client/actions/setAddresses.d.ts.map +1 -0
  38. package/dist/types/src/client/actors/initialize.d.ts +4 -0
  39. package/dist/types/src/client/actors/initialize.d.ts.map +1 -0
  40. package/dist/types/src/client/actors/saveAppState.d.ts +5 -0
  41. package/dist/types/src/client/actors/saveAppState.d.ts.map +1 -0
  42. package/dist/types/src/client/clientManagerMachine.d.ts +19 -0
  43. package/dist/types/src/client/clientManagerMachine.d.ts.map +1 -0
  44. package/dist/types/src/client/index.d.ts +41 -0
  45. package/dist/types/src/client/index.d.ts.map +1 -0
  46. package/dist/types/src/client.d.ts.map +1 -1
  47. package/dist/types/src/node/helpers/FileManager.d.ts.map +1 -1
  48. package/dist/types/src/services/internal/actors/validateInput.d.ts.map +1 -1
  49. package/dist/types/src/types/machines.d.ts +5 -0
  50. package/dist/types/src/types/machines.d.ts.map +1 -1
  51. package/package.json +2 -2
  52. package/dist/FileManager-texI7UwL.js.map +0 -1
  53. package/dist/index-BLla2o05.js.map +0 -1
  54. package/dist/index-BeKRizLf.js.map +0 -1
  55. package/dist/src/AppStateSchema.ts +0 -10
  56. package/dist/src/ArweaveClient.ts +0 -13
  57. package/dist/src/Attestation.ts +0 -21
  58. package/dist/src/BaseArweaveClient.ts +0 -13
  59. package/dist/src/BaseDb.ts +0 -35
  60. package/dist/src/BaseEasClient.ts +0 -13
  61. package/dist/src/BaseFileManager.ts +0 -56
  62. package/dist/src/BaseItem.ts +0 -413
  63. package/dist/src/BaseItemProperty.ts +0 -416
  64. package/dist/src/BaseQueryClient.ts +0 -13
  65. package/dist/src/ConfigSchema.ts +0 -15
  66. package/dist/src/Db.ts +0 -78
  67. package/dist/src/EasClient.ts +0 -13
  68. package/dist/src/FileDownloader.ts +0 -63
  69. package/dist/src/FileManager.ts +0 -57
  70. package/dist/src/IDb.ts +0 -7
  71. package/dist/src/IEasClient.ts +0 -2
  72. package/dist/src/IItem.ts +0 -26
  73. package/dist/src/IItemProperty.ts +0 -28
  74. package/dist/src/IQueryClient.ts +0 -4
  75. package/dist/src/ImageResizer.ts +0 -81
  76. package/dist/src/Item.ts +0 -12
  77. package/dist/src/ItemProperty.ts +0 -9
  78. package/dist/src/MetadataSchema.ts +0 -28
  79. package/dist/src/ModelSchema.ts +0 -46
  80. package/dist/src/ModelUidSchema.ts +0 -16
  81. package/dist/src/PropertyUidSchema.ts +0 -16
  82. package/dist/src/QueryClient.ts +0 -22
  83. package/dist/src/Schema.ts +0 -17
  84. package/dist/src/SeedProtocolSdk.d.ts +0 -19
  85. package/dist/src/SeedSchema.ts +0 -29
  86. package/dist/src/VersionSchema.ts +0 -16
  87. package/dist/src/actors.ts +0 -295
  88. package/dist/src/addModelsToDb.ts +0 -152
  89. package/dist/src/allItems.ts +0 -31
  90. package/dist/src/analyzeInput.ts +0 -144
  91. package/dist/src/browser.app.db.config.ts +0 -27
  92. package/dist/src/browser.ts +0 -30
  93. package/dist/src/checkStatus.ts +0 -50
  94. package/dist/src/client.ts +0 -148
  95. package/dist/src/configureFs.ts +0 -94
  96. package/dist/src/connectToDb.ts +0 -41
  97. package/dist/src/connectionManager.ts +0 -67
  98. package/dist/src/constants.ts +0 -125
  99. package/dist/src/content-hash.ts +0 -30
  100. package/dist/src/create.ts +0 -39
  101. package/dist/src/createMetadata.ts +0 -77
  102. package/dist/src/createNewItem.ts +0 -61
  103. package/dist/src/createPublishAttempt.ts +0 -16
  104. package/dist/src/createSeed.ts +0 -31
  105. package/dist/src/createSeeds.ts +0 -24
  106. package/dist/src/createVersion.ts +0 -33
  107. package/dist/src/dbMachine.ts +0 -182
  108. package/dist/src/deleteItem.ts +0 -19
  109. package/dist/src/download.ts +0 -202
  110. package/dist/src/drizzle.ts +0 -78
  111. package/dist/src/eas.ts +0 -40
  112. package/dist/src/environment.ts +0 -35
  113. package/dist/src/eventBus.ts +0 -5
  114. package/dist/src/events.ts +0 -14
  115. package/dist/src/fetchDataFromEas.ts +0 -94
  116. package/dist/src/fetchDbData.ts +0 -19
  117. package/dist/src/fetchRelatedItems.ts +0 -184
  118. package/dist/src/fetchSeeds.ts +0 -52
  119. package/dist/src/fetchVersions.ts +0 -49
  120. package/dist/src/files.ts +0 -81
  121. package/dist/src/filesDownload.ts +0 -326
  122. package/dist/src/fragment-masking.ts +0 -87
  123. package/dist/src/getExistingItem.ts +0 -60
  124. package/dist/src/getItem.ts +0 -32
  125. package/dist/src/getItemData.ts +0 -99
  126. package/dist/src/getItemProperties.ts +0 -56
  127. package/dist/src/getItemProperty.ts +0 -34
  128. package/dist/src/getItems.ts +0 -70
  129. package/dist/src/getMetadata.ts +0 -40
  130. package/dist/src/getModelSchemas.ts +0 -89
  131. package/dist/src/getPropertyData.ts +0 -50
  132. package/dist/src/getPublishPayload.ts +0 -355
  133. package/dist/src/getPublishUploads.ts +0 -207
  134. package/dist/src/getRelationValueData.ts +0 -27
  135. package/dist/src/getSchemaForItemProperty.ts +0 -68
  136. package/dist/src/getSchemaForModel.ts +0 -42
  137. package/dist/src/getSchemaUidForModel.ts +0 -32
  138. package/dist/src/getSeedData.ts +0 -34
  139. package/dist/src/getSegmentedItemProperties.ts +0 -65
  140. package/dist/src/getStorageTransactionIdForSeedUid.ts +0 -38
  141. package/dist/src/getVersionData.ts +0 -46
  142. package/dist/src/getVersionsForVersionUids.ts +0 -39
  143. package/dist/src/globalMachine.ts +0 -280
  144. package/dist/src/gql.ts +0 -118
  145. package/dist/src/graphql.ts +0 -3209
  146. package/dist/src/helpers.ts +0 -273
  147. package/dist/src/hydrateExistingItem.ts +0 -137
  148. package/dist/src/hydrateFromDb.ts +0 -270
  149. package/dist/src/hydrateNewItem.ts +0 -34
  150. package/dist/src/imageResize.ts +0 -507
  151. package/dist/src/index.d.ts +0 -5
  152. package/dist/src/index.ts +0 -4
  153. package/dist/src/initialize.ts +0 -124
  154. package/dist/src/internalMachine.ts +0 -238
  155. package/dist/src/itemMachineAll.ts +0 -157
  156. package/dist/src/itemMachineSingle.ts +0 -158
  157. package/dist/src/loadAppDb.ts +0 -47
  158. package/dist/src/machines.ts +0 -60
  159. package/dist/src/metadataLatest.ts +0 -34
  160. package/dist/src/migrate.ts +0 -53
  161. package/dist/src/model.ts +0 -72
  162. package/dist/src/modelClass.ts +0 -19
  163. package/dist/src/node.app.db.config.ts +0 -41
  164. package/dist/src/prepareDb.ts +0 -29
  165. package/dist/src/preparePublishRequestData.ts +0 -81
  166. package/dist/src/processItems.ts +0 -74
  167. package/dist/src/property.ts +0 -156
  168. package/dist/src/propertyMachine.ts +0 -202
  169. package/dist/src/publish.ts +0 -28
  170. package/dist/src/publishMachine.ts +0 -77
  171. package/dist/src/queries.ts +0 -13
  172. package/dist/src/recoverDeletedItem.ts +0 -14
  173. package/dist/src/reload.ts +0 -33
  174. package/dist/src/request.ts +0 -45
  175. package/dist/src/requestAll.ts +0 -157
  176. package/dist/src/resolveRelatedValue.ts +0 -367
  177. package/dist/src/resolveRemoteStorage.ts +0 -88
  178. package/dist/src/saveAppState.ts +0 -19
  179. package/dist/src/saveConfig.ts +0 -88
  180. package/dist/src/saveDataToDb.ts +0 -145
  181. package/dist/src/saveImageSrc.ts +0 -242
  182. package/dist/src/saveItemStorage.ts +0 -156
  183. package/dist/src/saveMetadata.ts +0 -18
  184. package/dist/src/savePublishService.ts +0 -30
  185. package/dist/src/saveRelation.ts +0 -112
  186. package/dist/src/seed.schema.config.ts +0 -25
  187. package/dist/src/seed.ts +0 -10
  188. package/dist/src/seedProtocol.ts +0 -17
  189. package/dist/src/services.ts +0 -365
  190. package/dist/src/sqlWasmClient.ts +0 -88
  191. package/dist/src/syncDbWithEas.ts +0 -628
  192. package/dist/src/trash.ts +0 -29
  193. package/dist/src/ts-to-proto.ts +0 -101
  194. package/dist/src/types.ts +0 -12
  195. package/dist/src/updateItemPropertyValue.ts +0 -243
  196. package/dist/src/updateMachineContext.ts +0 -21
  197. package/dist/src/updateMetadata.ts +0 -59
  198. package/dist/src/upload.ts +0 -86
  199. package/dist/src/validate.ts +0 -45
  200. package/dist/src/validateInput.ts +0 -47
  201. package/dist/src/validateItemData.ts +0 -20
  202. package/dist/src/versionData.ts +0 -24
  203. package/dist/src/waitForDb.ts +0 -25
  204. package/dist/src/waitForFiles.ts +0 -34
  205. package/dist/src/wasm.d.ts +0 -8300
@@ -1,416 +0,0 @@
1
- import { ActorRefFrom, createActor, SnapshotFrom, Subscription, waitFor } from 'xstate'
2
- import { BehaviorSubject, Subscriber } from 'rxjs'
3
- import { Static } from '@sinclair/typebox'
4
- import { IItemProperty } from '@/interfaces/IItemProperty'
5
- import { immerable } from 'immer'
6
- import { CreatePropertyInstanceProps, PropertyMachineContext } from '@/types'
7
- import { getModel } from '@/stores/modelClass'
8
- import { propertyMachine } from './service/propertyMachine'
9
- import { internalPropertyNames } from '@/helpers/constants'
10
- import debug from 'debug'
11
- import pluralize from 'pluralize'
12
- import { eventEmitter } from '@/eventBus'
13
- import fs from '@zenfs/core'
14
- import { getPropertyData } from '@/db/read/getPropertyData'
15
- import { getCorrectId } from '@/helpers'
16
- import { TProperty } from '@/schema'
17
-
18
- const logger = debug('app:property:class')
19
-
20
- type ItemPropertyService = ActorRefFrom<typeof propertyMachine>
21
- type ItemPropertySnapshot = SnapshotFrom<typeof propertyMachine>
22
-
23
- type ItemPropertyFindProps = {
24
- propertyName: string
25
- propertyLocalId?: string
26
- seedLocalId?: string
27
- seedUid?: string
28
- }
29
-
30
- export abstract class BaseItemProperty<PropertyType> implements IItemProperty<PropertyType> {
31
- protected static instanceCache: Map<
32
- string,
33
- { instance: BaseItemProperty<any>; refCount: number }
34
- > = new Map()
35
- protected readonly _service: ItemPropertyService
36
- protected _subject: BehaviorSubject<any>
37
- protected readonly _isRelation: boolean = false
38
- protected readonly _isList: boolean = false
39
- protected readonly _alias: string | undefined
40
- protected _subscription: Subscription
41
- protected _dataType: string | undefined
42
- protected _schemaUid: string | undefined
43
- [immerable] = true
44
-
45
- constructor(initialValues: Partial<CreatePropertyInstanceProps>) {
46
- const { modelName, propertyName, propertyValue, seedLocalId, seedUid, versionLocalId, versionUid, storageTransactionId, schemaUid } = initialValues
47
-
48
- if (!modelName) {
49
- throw new Error('Model name is required')
50
- }
51
-
52
- const ModelClass = getModel(modelName)
53
-
54
- if (!ModelClass) {
55
- throw new Error(`Model ${modelName} not found`)
56
- }
57
-
58
- if (!propertyName) {
59
- throw new Error(`Property name not provided`)
60
- }
61
-
62
- const serviceInput: Partial<PropertyMachineContext> = {
63
- propertyValue,
64
- propertyName,
65
- seedLocalId,
66
- seedUid,
67
- versionLocalId,
68
- versionUid,
69
- modelName: modelName,
70
- storageTransactionId,
71
- propertyRecordSchema: ModelClass.schema[propertyName],
72
- schemaUid,
73
- }
74
-
75
-
76
-
77
- if (!internalPropertyNames.includes(propertyName)) {
78
- let propertyNameWithoutId
79
-
80
- const propertyRecordSchema =
81
- ModelClass.schema[propertyNameWithoutId || propertyName]
82
- if (propertyRecordSchema) {
83
- this._dataType = propertyRecordSchema.dataType
84
-
85
- serviceInput.propertyRecordSchema = propertyRecordSchema
86
-
87
- if (propertyRecordSchema.dataType === 'Relation') {
88
- this._isRelation = true
89
- }
90
-
91
- if (
92
- propertyRecordSchema.dataType === 'List' &&
93
- propertyRecordSchema.ref
94
- ) {
95
- this._isList = true
96
- this._isRelation = true
97
-
98
- if (propertyValue) {
99
- try {
100
- serviceInput.propertyValue = JSON.parse(propertyValue)
101
- } catch (e) {
102
- logger('List property value is not JSON', e)
103
- }
104
- }
105
-
106
- const propertyNameSingular = pluralize(propertyName!, 1)
107
-
108
- this._alias = propertyName
109
-
110
- serviceInput.propertyName = `${propertyNameSingular}${propertyRecordSchema.ref}Ids`
111
- }
112
-
113
- if (!this._alias && propertyNameWithoutId) {
114
- this._alias = propertyNameWithoutId
115
- }
116
- }
117
- }
118
-
119
- serviceInput.isRelation = this._isRelation
120
-
121
- this._subject = new BehaviorSubject(propertyValue)
122
- this._service = createActor(propertyMachine, {
123
- input: serviceInput,
124
- })
125
-
126
- this._subscription = this._service.subscribe(
127
- async (snapshot: ItemPropertySnapshot) => {
128
- if (!snapshot || !snapshot.context) {
129
- return
130
- }
131
-
132
- const { context } = snapshot
133
- const { propertyRecordSchema } = context
134
-
135
- if (context.seedLocalId) {
136
- const cacheKey = BaseItemProperty.cacheKey(
137
- context.seedLocalId,
138
- context.propertyName,
139
- )
140
- if (!BaseItemProperty.instanceCache.has(cacheKey)) {
141
- BaseItemProperty.instanceCache.set(cacheKey, {
142
- instance: this,
143
- refCount: 1,
144
- })
145
- }
146
- }
147
-
148
- let renderValue
149
-
150
- if (
151
- propertyRecordSchema &&
152
- propertyRecordSchema.storageType &&
153
- propertyRecordSchema.storageType === 'ItemStorage' &&
154
- context.refResolvedValue &&
155
- context.localStorageDir
156
- ) {
157
- const filePath = `/files/${context.localStorageDir}/${context.refResolvedValue}`
158
- try {
159
- const exists = await fs.promises.exists(filePath)
160
- if (exists) {
161
- renderValue = await fs.promises.readFile(filePath, 'utf-8')
162
- }
163
- if (!exists) {
164
- renderValue = 'No file found'
165
- }
166
- } catch (e) {
167
- logger(
168
- `[ItemProperty] [${context.seedLocalId}] [${context.propertyName}] [storageType] error`,
169
- e,
170
- )
171
- renderValue = 'No file found'
172
- }
173
- }
174
-
175
- if (!renderValue) {
176
- renderValue = context.renderValue || context.propertyValue
177
- }
178
-
179
- let transformedPropertyName = propertyName
180
-
181
- const skipTransform =
182
- internalPropertyNames.includes(propertyName) || !!this._alias
183
-
184
- if (!skipTransform && transformedPropertyName.endsWith('Id')) {
185
- transformedPropertyName = transformedPropertyName.slice(0, -2)
186
- }
187
-
188
- if (!skipTransform && transformedPropertyName.endsWith('Ids')) {
189
- transformedPropertyName = transformedPropertyName.slice(0, -3)
190
- }
191
-
192
- if (skipTransform && this._alias) {
193
- transformedPropertyName = this._alias
194
- }
195
-
196
- if (skipTransform && !this._alias) {
197
- }
198
-
199
- if (this._subject.value === renderValue) {
200
- return
201
- }
202
-
203
- this._subject.next(renderValue)
204
- // TODO: Maybe have this only update the property?
205
- // if (context.seedLocalId || context.seedUid) {
206
- // eventEmitter.emit(`property.${context.seedUid || context.seedLocalId}.${propertyName}.update`)
207
- // }
208
- // if (context.seedUid) {
209
- // eventEmitter.emit(`item.${modelName}.${context.seedUid}.update`)
210
- // }
211
- },
212
- )
213
-
214
- this._service.start()
215
- }
216
-
217
- static PlatformClass: typeof BaseItemProperty
218
-
219
- static setPlatformClass(platformClass: typeof BaseItemProperty) {
220
- this.PlatformClass = platformClass
221
- }
222
-
223
- static create(
224
- props: Partial<CreatePropertyInstanceProps>,
225
- ): BaseItemProperty<any> | undefined {
226
- const { propertyName, seedLocalId, seedUid, versionLocalId, versionUid } =
227
- props
228
- if (!propertyName || (!seedLocalId && !seedUid)) {
229
- return
230
- }
231
- const cacheKey = this.cacheKey(
232
- (seedUid || seedLocalId) as string,
233
- propertyName,
234
- )
235
- if (seedLocalId && propertyName) {
236
- if (this.instanceCache.has(cacheKey)) {
237
- const { instance, refCount } = this.instanceCache.get(cacheKey)!
238
- this.instanceCache.set(cacheKey, {
239
- instance,
240
- refCount: refCount + 1,
241
- })
242
- return instance
243
- }
244
- if (!this.instanceCache.has(cacheKey)) {
245
- const newInstance = new this(props)
246
- this.instanceCache.set(cacheKey, {
247
- instance: newInstance,
248
- refCount: 1,
249
- })
250
- return newInstance
251
- }
252
- }
253
- if (seedUid && propertyName) {
254
- if (this.instanceCache.has(cacheKey)) {
255
- const { instance, refCount } = this.instanceCache.get(cacheKey)!
256
- this.instanceCache.set(cacheKey, { instance, refCount: refCount + 1 })
257
- return instance
258
- }
259
- if (!this.instanceCache.has(cacheKey)) {
260
- const newInstance = new this(props)
261
- this.instanceCache.set(cacheKey, { instance: newInstance, refCount: 1 })
262
- return newInstance
263
- }
264
- }
265
- return new this(props)
266
- }
267
-
268
- static async find({
269
- propertyName,
270
- seedLocalId,
271
- seedUid,
272
- }: ItemPropertyFindProps): Promise<IItemProperty<any> | undefined> {
273
- if ((!seedLocalId && !seedUid) || !propertyName) {
274
- return
275
- }
276
- const cacheKeyId = seedUid || seedLocalId
277
- const cacheKey = BaseItemProperty.cacheKey(cacheKeyId!, propertyName)
278
- if (this.instanceCache.has(cacheKey)) {
279
- const { instance, refCount } = this.instanceCache.get(cacheKey)!
280
- this.instanceCache.set(cacheKey, {
281
- instance,
282
- refCount: refCount + 1,
283
- })
284
- return instance
285
- }
286
- const propertyData = await getPropertyData({
287
- propertyName,
288
- seedLocalId,
289
- seedUid,
290
- })
291
- if (!propertyData) {
292
- return
293
- }
294
- return BaseItemProperty.create(propertyData)
295
- }
296
-
297
- static cacheKey(seedLocalIdOrUid: string, propertyName: string): string {
298
- const { uid, localId } = getCorrectId(seedLocalIdOrUid)
299
- return `Item_${uid || localId}_${propertyName}`
300
- }
301
-
302
- getService() {
303
- return this._service
304
- }
305
-
306
- private _getSnapshot(): ItemPropertySnapshot {
307
- return this._service.getSnapshot() as ItemPropertySnapshot
308
- }
309
-
310
- get localId() {
311
- return this._getSnapshot().context.localId
312
- }
313
-
314
- get uid() {
315
- return this._getSnapshot().context.uid
316
- }
317
-
318
- get seedLocalId() {
319
- return this._getSnapshot().context.seedLocalId
320
- }
321
-
322
- get seedUid() {
323
- return this._getSnapshot().context.seedUid
324
- }
325
-
326
- get schemaUid() {
327
- return this._getSnapshot().context.schemaUid
328
- }
329
-
330
- get propertyName() {
331
- if (this._alias) {
332
- return this._alias
333
- }
334
- return this._getSnapshot().context.propertyName
335
- }
336
-
337
- get modelName() {
338
- return this._getSnapshot().context.modelName
339
- }
340
-
341
- get propertyDef(): Static<typeof TProperty> | undefined {
342
- return this._getSnapshot().context.propertyRecordSchema
343
- }
344
-
345
- get localStoragePath(): string | void {
346
- if (this.propertyDef && this.propertyDef.localStorageDir) {
347
- return `/files${this.propertyDef.localStorageDir}/${this._getSnapshot().context.refResolvedValue}`
348
- }
349
- if (this._getSnapshot().context.localStorageDir) {
350
- return `/files${this._getSnapshot().context.localStorageDir}/${this._getSnapshot().context.refResolvedValue}`
351
- }
352
- }
353
-
354
- get versionLocalId(): string | undefined {
355
- return this._getSnapshot().context.versionLocalId
356
- }
357
-
358
- get status() {
359
- return this._getSnapshot().value
360
- }
361
-
362
- get alias() {
363
- return this._alias
364
- }
365
-
366
- get value() {
367
- // logger(
368
- // `[XXXXXXXXXX] [value] [get] subjectValue: ${this._subject.value} serviceValue: ${this._service.getSnapshot().context.renderValue}`,
369
- // )
370
- return this._subject.value
371
- }
372
-
373
- set value(value: any) {
374
- if (this._subject.value === value) {
375
- return
376
- }
377
- const context = this._service.getSnapshot().context
378
- if (!context.propertyRecordSchema) {
379
- this._subject.next(value)
380
- }
381
- this._service.send({
382
- type: 'save',
383
- newValue: value,
384
- })
385
- }
386
-
387
- get published(): boolean {
388
- return !!this._getSnapshot().context.uid
389
- }
390
-
391
- subscribe(callback: Partial<Subscriber<any>>) {
392
- return this._subject.subscribe(callback)
393
- }
394
-
395
- async save(): Promise<void> {
396
- await waitFor(
397
- this._service,
398
- (snapshot) => !snapshot.context.isSaving && snapshot.value === 'idle',
399
- {
400
- timeout: 10_000,
401
- },
402
- )
403
- // return new Promise((resolve) => {
404
- // const saveSub = this._service.subscribe((snapshot) => {
405
- // if (!snapshot.context.isSaving) {
406
- // saveSub.unsubscribe()
407
- // resolve()
408
- // }
409
- // })
410
- // })
411
- }
412
-
413
- unload() {
414
- this._service.stop()
415
- }
416
- }
@@ -1,13 +0,0 @@
1
- import { IQueryClient } from "@/interfaces/IQueryClient"
2
-
3
- export abstract class BaseQueryClient {
4
- static PlatformClass: typeof BaseQueryClient
5
-
6
- static setPlatformClass(platformClass: typeof BaseQueryClient) {
7
- this.PlatformClass = platformClass
8
- }
9
-
10
- static getQueryClient(): IQueryClient {
11
- return this.PlatformClass.getQueryClient()
12
- }
13
- }
@@ -1,15 +0,0 @@
1
- import { blob, int, sqliteTable, text, check, } from 'drizzle-orm/sqlite-core'
2
- import { sql } from 'drizzle-orm'
3
-
4
- export const config = sqliteTable('config', {
5
- id: int('id').primaryKey({ autoIncrement: true }),
6
- key: text('key').notNull(),
7
- text: text('text'),
8
- json: text('json', {mode: 'json'}),
9
- blob: blob('blob', {mode: 'buffer'}),
10
- }, () => {
11
- return {
12
- // Add a custom check constraint
13
- atLeastOneNotNull: check('hasValue', sql`key IS NOT NULL OR text IS NOT NULL OR json IS NOT NULL OR blob IS NOT NULL`),
14
- }
15
- })
package/dist/src/Db.ts DELETED
@@ -1,78 +0,0 @@
1
- import { BaseDb } from "@/db/Db/BaseDb";
2
- import { IDb } from "@/interfaces";
3
- import nodeAppDbConfig from "./node.app.db.config";
4
- import { drizzle } from "drizzle-orm/better-sqlite3";
5
- import { defineConfig, } from "drizzle-kit";
6
- import path from "path";
7
- import { DrizzleConfig, } from "drizzle-orm";
8
- import Database from "better-sqlite3";
9
-
10
- const getConfig = (filesDir: string) => {
11
-
12
- const dotSeedDir = path.join(filesDir, '.seed')
13
- let schemaDir = `${dotSeedDir}/schema/*Schema.ts`
14
-
15
- const nodeDbConfig = defineConfig({
16
- schema: schemaDir,
17
- dialect: 'sqlite',
18
- out: `${dotSeedDir}/db`,
19
- dbCredentials: {
20
- url: `${dotSeedDir}/db/app_db.sqlite3`,
21
- }
22
- }) as DrizzleConfig & { dbCredentials: { url: string } }
23
-
24
- return nodeDbConfig
25
- }
26
-
27
- class Db extends BaseDb implements IDb {
28
- constructor() {
29
- super()
30
- }
31
-
32
- static getAppDb() {
33
- return drizzle(nodeAppDbConfig)
34
- }
35
-
36
- static isAppDbReady() {
37
- return true
38
- }
39
-
40
- static async prepareDb(filesDir: string) {
41
- const nodeDbConfig = getConfig(filesDir)
42
-
43
- let db
44
-
45
- try {
46
- db = drizzle(nodeDbConfig)
47
- } catch (error) {
48
- console.error(error)
49
- }
50
-
51
- try {
52
- const client = new Database(nodeDbConfig.dbCredentials.url)
53
- db = drizzle({ client })
54
- } catch (error) {
55
- console.error(error)
56
- }
57
-
58
- return db
59
- }
60
-
61
- static async connectToDb(pathToDir: string, dbName: string) {
62
-
63
- const nodeDbConfig = getConfig(pathToDir)
64
-
65
- return {
66
- id: drizzle(nodeDbConfig).$client.name
67
- }
68
- }
69
-
70
- static async migrate(pathToDbDir: string, dbName: string, dbId: string) {
71
- const nodeDbConfig = getConfig(pathToDbDir)
72
- return drizzle(nodeDbConfig)
73
- }
74
- }
75
-
76
- BaseDb.setPlatformClass(Db)
77
-
78
- export { Db }
@@ -1,13 +0,0 @@
1
- import { BaseEasClient } from "@/helpers/EasClient/BaseEasClient"
2
- import { EAS_ENDPOINT } from "@/services/internal/constants"
3
- import { GraphQLClient } from "graphql-request"
4
-
5
- class EasClient extends BaseEasClient {
6
- static getEasClient() {
7
- return new GraphQLClient(EAS_ENDPOINT)
8
- }
9
- }
10
-
11
- BaseEasClient.setPlatformClass(EasClient)
12
-
13
- export { EasClient }
@@ -1,63 +0,0 @@
1
- import { saveAppState } from '@/db/write/saveAppState.js';
2
- import filesDownload from './filesDownload.js'
3
-
4
-
5
-
6
- export class FileDownloader {
7
- private cores: number
8
- private workersArchive: Worker[] = []
9
- private workerBlobUrl: string
10
-
11
- constructor() {
12
- this.cores = Math.min(navigator.hardwareConcurrency || 4, 4);
13
-
14
- this.workerBlobUrl = globalThis.URL.createObjectURL(
15
- new Blob([filesDownload], { type: 'application/javascript' })
16
- )
17
- }
18
-
19
- public downloadAll = async ({transactionIds, arweaveHost, excludedTransactions}: DownloadAllFilesParams): Promise<void> => {
20
-
21
- if (this.workersArchive.length > 0) {
22
- for (let i = 0; i < this.workersArchive.length; i++) {
23
- this.workersArchive[i].terminate()
24
- delete this.workersArchive[i]
25
- }
26
- this.workersArchive = []
27
- }
28
-
29
- const worker = new Worker(this.workerBlobUrl);
30
-
31
- this.workersArchive.push(worker)
32
-
33
- const localExcludedTransactions = new Set(excludedTransactions)
34
-
35
- return new Promise((resolve, reject) => {
36
- worker.onmessage = (e) => {
37
- console.log('filesDownload main thread onmessage', e.data);
38
-
39
- if (e.data.message === 'excludeTransaction') {
40
- localExcludedTransactions.add(e.data.transactionId)
41
- }
42
-
43
- if (e.data.done) {
44
- saveAppState('excludedTransactions', JSON.stringify(Array.from(localExcludedTransactions)))
45
- .then(() => {
46
- resolve(e.data)
47
- })
48
- .catch((error) => {
49
- reject(error)
50
- })
51
- }
52
- if (e.data.error) {
53
- reject(e.data.error)
54
- }
55
- }
56
-
57
- worker.postMessage({
58
- transactionIds,
59
- arweaveHost,
60
- });
61
- })
62
- }
63
- }
@@ -1,57 +0,0 @@
1
- import * as fsAsync from 'fs/promises'
2
- import { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'
3
-
4
- class FileManager extends BaseFileManager {
5
-
6
- static async readFileAsBuffer( filePath: string ): Promise<Buffer> {
7
- return await fsAsync.readFile(filePath)
8
- }
9
-
10
- static async getContentUrlFromPath( path: string ): Promise<string | undefined> {
11
- return new Promise(( resolve, reject ) => {
12
- reject(new Error('Not implemented'))
13
- })
14
- }
15
-
16
- static async initializeFileSystem(): Promise<void> {
17
- return new Promise(( resolve, reject ) => {
18
- reject(new Error('Not implemented'))
19
- })
20
- }
21
-
22
- static async downloadAllFiles(): Promise<void> {
23
- return new Promise(( resolve, reject ) => {
24
- reject(new Error('Not implemented'))
25
- })
26
- }
27
-
28
- static async resizeImage(): Promise<void> {
29
- return new Promise(( resolve, reject ) => {
30
- reject(new Error('Not implemented'))
31
- })
32
- }
33
-
34
- static async resizeAllImages(): Promise<void> {
35
- return new Promise(( resolve, reject ) => {
36
- reject(new Error('Not implemented'))
37
- })
38
- }
39
-
40
- static async pathExists(filePath: string): Promise<boolean> {
41
- return new Promise(( resolve, reject ) => {
42
- reject(new Error('Not implemented'))
43
- })
44
- }
45
-
46
- static async createDirIfNotExists(filePath: string): Promise<void> {
47
- return new Promise(( resolve, reject ) => {
48
- reject(new Error('Not implemented'))
49
- })
50
- }
51
-
52
- }
53
-
54
- BaseFileManager.setPlatformClass(FileManager)
55
-
56
- export { FileManager }
57
-
package/dist/src/IDb.ts DELETED
@@ -1,7 +0,0 @@
1
- import { ItemData, ModelSchema, ModelValues, PropertyData } from '@/types'
2
- import { VersionsType } from '@/seedSchema/VersionSchema'
3
- import { IItem } from '@/interfaces'
4
-
5
- export interface IDb {
6
-
7
- }
@@ -1,2 +0,0 @@
1
- export interface IEasClient {
2
- }
package/dist/src/IItem.ts DELETED
@@ -1,26 +0,0 @@
1
- import { ActorRefFrom, Subscription } from 'xstate'
2
- import { ModelSchema, ModelValues, PropertyData } from '@/types'
3
- import { VersionsType } from '@/seedSchema/VersionSchema'
4
- import { IItemProperty } from './IItemProperty'
5
-
6
- export interface IItem<T extends ModelValues<ModelSchema>> {
7
-
8
- subscribe(callback: (itemProps: any) => void): Subscription
9
- getService(): ActorRefFrom<any>
10
- getEditedProperties(): Promise<PropertyData[]>
11
- publish(): Promise<void>
12
- getPublishUploads(): Promise<any>
13
- getPublishPayload(uploadedTransactions: any[]): Promise<any>
14
- unload(): void
15
-
16
- readonly seedLocalId: string
17
- readonly seedUid?: string
18
- readonly schemaUid: string
19
- readonly latestVersionUid: VersionsType
20
- readonly latestVersionLocalId: string
21
- readonly modelName: string
22
- readonly properties: Record<string, IItemProperty<any>>
23
- readonly attestationCreatedAt: number
24
- readonly versionsCount: number
25
- readonly lastVersionPublishedAt: number
26
- }