@seedprotocol/sdk 0.2.44 → 0.2.46

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 (116) hide show
  1. package/dist/{ArweaveClient-CA1Vsnow.js → ArweaveClient-CoFomTCN.js} +2 -2
  2. package/dist/{ArweaveClient-MgJXScYG.js.map → ArweaveClient-CoFomTCN.js.map} +1 -1
  3. package/dist/{ArweaveClient-MgJXScYG.js → ArweaveClient-DQrXvrNN.js} +2 -2
  4. package/dist/{ArweaveClient-CA1Vsnow.js.map → ArweaveClient-DQrXvrNN.js.map} +1 -1
  5. package/dist/{Db-BEoczaGe.js → Db-5C5VqRWb.js} +16 -14
  6. package/dist/Db-5C5VqRWb.js.map +1 -0
  7. package/dist/{Db-Y1GWsyNL.js → Db-Dv890NJZ.js} +5 -4
  8. package/dist/{Db-Y1GWsyNL.js.map → Db-Dv890NJZ.js.map} +1 -1
  9. package/dist/{EasClient-BjlbuffX.js → EasClient-CBu9ENAi.js} +2 -2
  10. package/dist/{EasClient-Cg1q8lBu.js.map → EasClient-CBu9ENAi.js.map} +1 -1
  11. package/dist/{EasClient-Cg1q8lBu.js → EasClient-sCbTHcO8.js} +2 -2
  12. package/dist/{EasClient-BjlbuffX.js.map → EasClient-sCbTHcO8.js.map} +1 -1
  13. package/dist/{FileManager-D53H3aUS.js → FileManager-AhAsy_F_.js} +21 -8
  14. package/dist/{FileManager-D53H3aUS.js.map → FileManager-AhAsy_F_.js.map} +1 -1
  15. package/dist/{FileManager-t4zcT3NL.js → FileManager-COOp89Mj.js} +2 -2
  16. package/dist/{FileManager-t4zcT3NL.js.map → FileManager-COOp89Mj.js.map} +1 -1
  17. package/dist/{Item-BleJyiA2.js → Item-BmPvgaG4.js} +5 -4
  18. package/dist/{Item-BleJyiA2.js.map → Item-BmPvgaG4.js.map} +1 -1
  19. package/dist/{ItemProperty-CH7JmVg-.js → ItemProperty-BW4k1h0o.js} +5 -4
  20. package/dist/{ItemProperty-CH7JmVg-.js.map → ItemProperty-BW4k1h0o.js.map} +1 -1
  21. package/dist/{QueryClient-CDsEencG.js → QueryClient-BBaE-LKI.js} +2 -2
  22. package/dist/{QueryClient-CDsEencG.js.map → QueryClient-BBaE-LKI.js.map} +1 -1
  23. package/dist/{QueryClient-BKjgZnSt.js → QueryClient-C-ZzUnWq.js} +2 -2
  24. package/dist/{QueryClient-BKjgZnSt.js.map → QueryClient-C-ZzUnWq.js.map} +1 -1
  25. package/dist/bin.js +5 -5
  26. package/dist/{constants-BIdH8wc3.js → constants-Dgv-tSO3.js} +13 -3
  27. package/dist/constants-Dgv-tSO3.js.map +1 -0
  28. package/dist/{index-DanGFTTF.js → index-CGeSKilQ.js} +283 -206
  29. package/dist/index-CGeSKilQ.js.map +1 -0
  30. package/dist/{index-Dk6K4W4n.js → index-CPxn1SR4.js} +5 -4
  31. package/dist/index-CPxn1SR4.js.map +1 -0
  32. package/dist/main.js +4 -3
  33. package/dist/main.js.map +1 -1
  34. package/dist/{seed.schema.config-DdCq87m_.js → seed.schema.config-BXWvwsZQ.js} +11 -10
  35. package/dist/seed.schema.config-BXWvwsZQ.js.map +1 -0
  36. package/dist/src/BaseFileManager.ts +11 -2
  37. package/dist/src/BaseItem.ts +1 -1
  38. package/dist/src/BaseItemProperty.ts +7 -6
  39. package/dist/src/actors.ts +1 -1
  40. package/dist/src/client.ts +12 -0
  41. package/dist/src/configureFs.ts +19 -6
  42. package/dist/src/createMetadata.ts +11 -4
  43. package/dist/src/dbMachine.ts +6 -0
  44. package/dist/src/download.ts +4 -2
  45. package/dist/src/files.ts +15 -4
  46. package/dist/src/getItemProperties.ts +9 -19
  47. package/dist/src/getPublishPayload.ts +15 -8
  48. package/dist/src/getPublishUploads.ts +1 -28
  49. package/dist/src/gql.ts +9 -4
  50. package/dist/src/graphql.ts +12 -4
  51. package/dist/src/helpers.ts +21 -4
  52. package/dist/src/hydrateFromDb.ts +5 -2
  53. package/dist/src/internalMachine.ts +16 -0
  54. package/dist/src/metadataLatest.ts +34 -0
  55. package/dist/src/migrate.ts +1 -25
  56. package/dist/src/property.ts +10 -7
  57. package/dist/src/resolveRelatedValue.ts +1 -1
  58. package/dist/src/resolveRemoteStorage.ts +1 -1
  59. package/dist/src/saveImageSrc.ts +2 -2
  60. package/dist/src/saveItemStorage.ts +1 -1
  61. package/dist/src/updateItemPropertyValue.ts +1 -1
  62. package/dist/src/validate.ts +7 -4
  63. package/dist/src/waitForDb.ts +12 -9
  64. package/dist/src/waitForFiles.ts +9 -8
  65. package/dist/types/src/Item/queries.d.ts +2 -2
  66. package/dist/types/src/Item/queries.d.ts.map +1 -1
  67. package/dist/types/src/Item/service/actors/fetchDataFromEas.d.ts +1 -2
  68. package/dist/types/src/Item/service/actors/fetchDataFromEas.d.ts.map +1 -1
  69. package/dist/types/src/Item/service/actors/waitForDb.d.ts +3 -1
  70. package/dist/types/src/Item/service/actors/waitForDb.d.ts.map +1 -1
  71. package/dist/types/src/ItemProperty/BaseItemProperty.d.ts +1 -1
  72. package/dist/types/src/ItemProperty/BaseItemProperty.d.ts.map +1 -1
  73. package/dist/types/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
  74. package/dist/types/src/ItemProperty/service/actors/waitForDb.d.ts.map +1 -1
  75. package/dist/types/src/ItemProperty/service/propertyMachine.d.ts +6 -6
  76. package/dist/types/src/browser/db/Db.d.ts.map +1 -1
  77. package/dist/types/src/browser/helpers/FileManager.d.ts.map +1 -1
  78. package/dist/types/src/browser/react/property.d.ts +1 -1
  79. package/dist/types/src/browser/react/property.d.ts.map +1 -1
  80. package/dist/types/src/client.d.ts +1 -0
  81. package/dist/types/src/client.d.ts.map +1 -1
  82. package/dist/types/src/db/read/getItemProperties.d.ts.map +1 -1
  83. package/dist/types/src/db/read/getPublishPayload.d.ts.map +1 -1
  84. package/dist/types/src/db/read/getPublishUploads.d.ts.map +1 -1
  85. package/dist/types/src/db/read/subqueries/metadataLatest.d.ts +5 -0
  86. package/dist/types/src/db/read/subqueries/metadataLatest.d.ts.map +1 -0
  87. package/dist/types/src/db/write/createMetadata.d.ts.map +1 -1
  88. package/dist/types/src/events/files/download.d.ts.map +1 -1
  89. package/dist/types/src/graphql/gql/gql.d.ts +12 -5
  90. package/dist/types/src/graphql/gql/gql.d.ts.map +1 -1
  91. package/dist/types/src/graphql/gql/graphql.d.ts +31 -15
  92. package/dist/types/src/graphql/gql/graphql.d.ts.map +1 -1
  93. package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts +2 -0
  94. package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
  95. package/dist/types/src/helpers/files.d.ts.map +1 -1
  96. package/dist/types/src/schema/file/queries.d.ts.map +1 -1
  97. package/dist/types/src/schema/model/index.d.ts.map +1 -1
  98. package/dist/types/src/services/db/actors/migrate.d.ts.map +1 -1
  99. package/dist/types/src/services/db/actors/validate.d.ts.map +1 -1
  100. package/dist/types/src/services/db/dbMachine.d.ts +10 -0
  101. package/dist/types/src/services/db/dbMachine.d.ts.map +1 -1
  102. package/dist/types/src/services/global/globalMachine.d.ts +90 -90
  103. package/dist/types/src/services/internal/actors/configureFs.d.ts.map +1 -1
  104. package/dist/types/src/services/internal/actors/waitForFiles.d.ts +4 -0
  105. package/dist/types/src/services/internal/actors/waitForFiles.d.ts.map +1 -0
  106. package/dist/types/src/services/internal/helpers.d.ts.map +1 -1
  107. package/dist/types/src/services/internal/internalMachine.d.ts +10 -0
  108. package/dist/types/src/services/internal/internalMachine.d.ts.map +1 -1
  109. package/package.json +3 -3
  110. package/dist/Db-BEoczaGe.js.map +0 -1
  111. package/dist/constants-BIdH8wc3.js.map +0 -1
  112. package/dist/index-DanGFTTF.js.map +0 -1
  113. package/dist/index-Dk6K4W4n.js.map +0 -1
  114. package/dist/seed.schema.config-DdCq87m_.js.map +0 -1
  115. package/dist/types/src/Item/service/actors/saveDataToDb.d.ts +0 -3
  116. package/dist/types/src/Item/service/actors/saveDataToDb.d.ts.map +0 -1
@@ -1,10 +1,11 @@
1
- export { I as Item } from './index-DanGFTTF.js';
1
+ export { I as Item } from './index-CGeSKilQ.js';
2
2
  import 'immer';
3
3
  import 'reflect-metadata';
4
4
  import '@sinclair/typebox';
5
5
  import 'xstate';
6
- import './constants-BIdH8wc3.js';
6
+ import './constants-Dgv-tSO3.js';
7
7
  import '@ethereum-attestation-service/eas-sdk';
8
+ import 'debug';
8
9
  import 'pluralize';
9
10
  import 'drizzle-orm/sqlite-core';
10
11
  import 'drizzle-orm';
@@ -12,14 +13,14 @@ import 'eventemitter3';
12
13
  import 'nanoid';
13
14
  import 'nanoid-dictionary';
14
15
  import '@zenfs/core';
15
- import 'debug';
16
16
  import 'lodash-es';
17
17
  import '@statelyai/inspect';
18
18
  import 'node:fs';
19
19
  import 'path';
20
20
  import 'arweave';
21
21
  import 'rxjs';
22
+ import 'drizzle-orm/casing';
22
23
  import 'react';
23
24
  import 'use-immer';
24
25
  import '@xstate/react';
25
- //# sourceMappingURL=index-Dk6K4W4n.js.map
26
+ //# sourceMappingURL=index-CPxn1SR4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-CPxn1SR4.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/main.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import 'immer';
2
2
  import 'reflect-metadata';
3
- export { D as Db, c as ImageSrc, d as Item, e as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, v as client, r as eventEmitter, p as getCorrectId, q as getGlobalService, h as useCreateItem, j as useDeleteItem, k as useGlobalServiceStatus, f as useItem, g as useItemProperties, i as useItemProperty, u as useItems, m as usePersistedSnapshots, l as usePublishItem, o as useService, n as useServices, t as withSeed } from './index-DanGFTTF.js';
4
- export { B as BaseArweaveClient, a as BaseEasClient, c as BaseFileManager, b as BaseQueryClient } from './constants-BIdH8wc3.js';
3
+ export { D as Db, c as ImageSrc, d as Item, e as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, v as client, r as eventEmitter, p as getCorrectId, q as getGlobalService, h as useCreateItem, j as useDeleteItem, k as useGlobalServiceStatus, f as useItem, g as useItemProperties, i as useItemProperty, u as useItems, m as usePersistedSnapshots, l as usePublishItem, o as useService, n as useServices, t as withSeed } from './index-CGeSKilQ.js';
4
+ export { B as BaseArweaveClient, a as BaseEasClient, c as BaseFileManager, b as BaseQueryClient } from './constants-Dgv-tSO3.js';
5
5
  import '@sinclair/typebox';
6
6
  import 'xstate';
7
+ import 'debug';
7
8
  import 'pluralize';
8
9
  import 'drizzle-orm/sqlite-core';
9
10
  import 'drizzle-orm';
@@ -11,13 +12,13 @@ import 'eventemitter3';
11
12
  import 'nanoid';
12
13
  import 'nanoid-dictionary';
13
14
  import '@zenfs/core';
14
- import 'debug';
15
15
  import 'lodash-es';
16
16
  import '@statelyai/inspect';
17
17
  import 'node:fs';
18
18
  import 'path';
19
19
  import 'arweave';
20
20
  import 'rxjs';
21
+ import 'drizzle-orm/casing';
21
22
  import '@ethereum-attestation-service/eas-sdk';
22
23
  import 'react';
23
24
  import 'use-immer';
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"main.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,11 +1,12 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
2
  import 'reflect-metadata';
3
- import { T as Text, M as Model } from './index-DanGFTTF.js';
3
+ import { T as Text, M as Model } from './index-CGeSKilQ.js';
4
4
  import 'immer';
5
5
  import '@sinclair/typebox';
6
6
  import 'xstate';
7
- import './constants-BIdH8wc3.js';
7
+ import './constants-Dgv-tSO3.js';
8
8
  import '@ethereum-attestation-service/eas-sdk';
9
+ import 'debug';
9
10
  import 'pluralize';
10
11
  import 'drizzle-orm/sqlite-core';
11
12
  import 'drizzle-orm';
@@ -13,13 +14,13 @@ import 'eventemitter3';
13
14
  import 'nanoid';
14
15
  import 'nanoid-dictionary';
15
16
  import '@zenfs/core';
16
- import 'debug';
17
17
  import 'lodash-es';
18
18
  import '@statelyai/inspect';
19
19
  import 'node:fs';
20
20
  import 'path';
21
21
  import 'arweave';
22
22
  import 'rxjs';
23
+ import 'drizzle-orm/casing';
23
24
  import 'react';
24
25
  import 'use-immer';
25
26
  import '@xstate/react';
@@ -29,11 +30,11 @@ let Seed = class Seed {
29
30
  __decorate([
30
31
  Text(),
31
32
  __metadata("design:type", String)
32
- ], Seed.prototype, "uid", void 0);
33
+ ], Seed.prototype, "uid", undefined);
33
34
  __decorate([
34
35
  Text(),
35
36
  __metadata("design:type", String)
36
- ], Seed.prototype, "type", void 0);
37
+ ], Seed.prototype, "type", undefined);
37
38
  Seed = __decorate([
38
39
  Model
39
40
  ], Seed);
@@ -42,11 +43,11 @@ let Version = class Version {
42
43
  __decorate([
43
44
  Text(),
44
45
  __metadata("design:type", String)
45
- ], Version.prototype, "seedUid", void 0);
46
+ ], Version.prototype, "seedUid", undefined);
46
47
  __decorate([
47
48
  Text(),
48
49
  __metadata("design:type", String)
49
- ], Version.prototype, "note", void 0);
50
+ ], Version.prototype, "note", undefined);
50
51
  Version = __decorate([
51
52
  Model
52
53
  ], Version);
@@ -55,11 +56,11 @@ let Metadata = class Metadata {
55
56
  __decorate([
56
57
  Text(),
57
58
  __metadata("design:type", String)
58
- ], Metadata.prototype, "key", void 0);
59
+ ], Metadata.prototype, "key", undefined);
59
60
  __decorate([
60
61
  Text(),
61
62
  __metadata("design:type", String)
62
- ], Metadata.prototype, "value", void 0);
63
+ ], Metadata.prototype, "value", undefined);
63
64
  Metadata = __decorate([
64
65
  Model
65
66
  ], Metadata);
@@ -70,4 +71,4 @@ const models = {
70
71
  };
71
72
 
72
73
  export { models };
73
- //# sourceMappingURL=seed.schema.config-DdCq87m_.js.map
74
+ //# sourceMappingURL=seed.schema.config-BXWvwsZQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.schema.config-BXWvwsZQ.js","sources":["../../src/db/configs/seed.schema.config.ts"],"sourcesContent":["import { Model, Text } from '@/schema'\n\n@Model\nclass Seed {\n @Text() uid!: string\n @Text() type!: string\n}\n\n@Model\nclass Version {\n @Text() seedUid!: string\n @Text() note!: string\n}\n\n@Model\nclass Metadata {\n @Text() key!: string\n @Text() value!: string\n}\n\nexport const models = {\n Seed,\n Version,\n Metadata,\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAM,IAAI,GAAV,MAAM,IAAI,CAAA;CAGT;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,KAAA,EAAA,SAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,MAAA,EAAA,SAAA,CAAA;AAFjB,IAAI,GAAA,UAAA,CAAA;IADT;AACK,CAAA,EAAA,IAAI,CAGT;AAGD,IAAM,OAAO,GAAb,MAAM,OAAO,CAAA;CAGZ;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAiB,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,SAAA,EAAA,SAAA,CAAA;AAChB,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,MAAA,EAAA,SAAA,CAAA;AAFjB,OAAO,GAAA,UAAA,CAAA;IADZ;AACK,CAAA,EAAA,OAAO,CAGZ;AAGD,IAAM,QAAQ,GAAd,MAAM,QAAQ,CAAA;CAGb;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,KAAA,EAAA,SAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAe,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,SAAA,CAAA;AAFlB,QAAQ,GAAA,UAAA,CAAA;IADb;AACK,CAAA,EAAA,QAAQ,CAGb;AAEY,MAAA,MAAM,GAAG;IACpB,IAAI;IACJ,OAAO;IACP,QAAQ;;;;;"}
@@ -1,12 +1,21 @@
1
1
  export abstract class BaseFileManager {
2
+ private fileSystemInitialized = false
3
+ private initializing = false
4
+
2
5
  static PlatformClass: typeof BaseFileManager
3
6
 
4
7
  static setPlatformClass( platformClass: typeof BaseFileManager ) {
5
8
  this.PlatformClass = platformClass
6
9
  }
7
10
 
8
- static initializeFileSystem(): Promise<void> {
9
- return this.PlatformClass.initializeFileSystem()
11
+ static async initializeFileSystem(): Promise<void> {
12
+ if (this.initializing || this.fileSystemInitialized) {
13
+ return Promise.resolve()
14
+ }
15
+ this.initializing = true
16
+ await this.PlatformClass.initializeFileSystem()
17
+ this.fileSystemInitialized = true
18
+ this.initializing = false
10
19
  }
11
20
 
12
21
  static getContentUrlFromPath( path: string ): Promise<string | undefined> {
@@ -110,7 +110,7 @@ export abstract class BaseItem<T extends ModelValues<ModelSchema>> implements II
110
110
  }
111
111
 
112
112
  this._propertiesSubject.next(propertiesObj)
113
- eventEmitter.emit(`item.${modelName}.${seedUid || seedLocalId}.update`)
113
+ // eventEmitter.emit(`item.${modelName}.${seedUid || seedLocalId}.update`)
114
114
  })
115
115
 
116
116
  this._service.start()
@@ -201,12 +201,13 @@ export abstract class BaseItemProperty<PropertyType> implements IItemProperty<Pr
201
201
  }
202
202
 
203
203
  this._subject.next(renderValue)
204
- if (context.seedLocalId) {
205
- eventEmitter.emit(`item.${modelName}.${context.seedLocalId}.update`)
206
- }
207
- if (context.seedUid) {
208
- eventEmitter.emit(`item.${modelName}.${context.seedUid}.update`)
209
- }
204
+ // TODO: Maybe have this only update the property?
205
+ // if (context.seedLocalId) {
206
+ // eventEmitter.emit(`item.${modelName}.${context.seedLocalId}.update`)
207
+ // }
208
+ // if (context.seedUid) {
209
+ // eventEmitter.emit(`item.${modelName}.${context.seedUid}.update`)
210
+ // }
210
211
  },
211
212
  )
212
213
 
@@ -3,7 +3,7 @@ import { fetchAllFilesMachine } from '@/schema/file/fetchAll/index'
3
3
  import { ARWEAVE_HOST } from '@/services/internal/constants'
4
4
  import { GET_FILES_METADATA } from '@/schema/file/queries'
5
5
  import { getArweave } from '@/helpers/ArweaveClient'
6
- import { fs } from '@zenfs/core'
6
+ import fs from '@zenfs/core'
7
7
  import {
8
8
  getDataTypeFromString,
9
9
  getMimeType,
@@ -18,9 +18,21 @@ import { initEasClient } from './helpers/EasClient'
18
18
  import { initQueryClient } from './helpers/QueryClient'
19
19
  import { initFileManager } from './helpers/FileManager'
20
20
  import { initDb } from './db/Db'
21
+ import debug from 'debug'
22
+
23
+ const logger = debug('app:client')
21
24
 
22
25
  const client = {
26
+ isInitialized: false,
23
27
  init: async (options: SeedConstructorOptions) => {
28
+ logger('init client')
29
+
30
+ if (client.isInitialized) {
31
+ return
32
+ }
33
+
34
+ client.isInitialized = true
35
+
24
36
  const { config, addresses } = options
25
37
 
26
38
  await initItem()
@@ -6,7 +6,7 @@ import {
6
6
  DB_WAITING_FOR_FILES_RECEIVED,
7
7
  INTERNAL_CONFIGURING_FS_SUCCESS,
8
8
  } from '@/services/internal/constants'
9
- import { fs } from '@zenfs/core'
9
+ import fs from '@zenfs/core'
10
10
  import debug from 'debug'
11
11
  import { FromCallbackInput, InternalMachineContext } from '@/types'
12
12
 
@@ -20,7 +20,7 @@ export const configureFs = fromCallback<
20
20
 
21
21
  logger('[internal/actors] [configureFs] Configuring FS')
22
22
 
23
- const _configureFs = async (): Promise<void> => {
23
+ const _configureFs = async (): Promise<boolean> => {
24
24
  logger('[internal/actors] [configureFs] calling _configureFs')
25
25
 
26
26
  logger(
@@ -44,12 +44,24 @@ export const configureFs = fromCallback<
44
44
 
45
45
  const journalPath = `${filesDir || BROWSER_FS_TOP_DIR}/db/meta/_journal.json`
46
46
 
47
- const journalExists = await fs.promises.exists(journalPath)
47
+
48
+ let journalExists = await fs.promises.exists(journalPath)
49
+
50
+ if (!journalExists) {
51
+ journalExists = fs.existsSync(journalPath)
52
+ }
48
53
 
49
54
  if (journalExists) {
50
55
  appDbService.send({ type: DB_WAITING_FOR_FILES_RECEIVED })
56
+ logger('[internal/actors] [configureFs] fs configured!')
57
+ return true
51
58
  }
52
59
 
60
+ sendBack({ type: 'shouldWaitForFiles' })
61
+
62
+
63
+ return false
64
+
53
65
  // return new Promise<void>((resolve) => {
54
66
  // const interval = setInterval(() => {
55
67
  // journalExistsSync = fs.existsSync(journalPath)
@@ -65,15 +77,16 @@ export const configureFs = fromCallback<
65
77
  // }, 200)
66
78
  // })
67
79
 
68
- logger('[internal/actors] [configureFs] fs configured!')
69
80
  }
70
81
 
71
82
  // Some of our dependencies use fs sync functions, which don't work with
72
83
  // OPFS. ZenFS creates an async cache of all files so that the sync functions
73
84
  // work, but we have to wait for it to be built. Otherwise things like
74
85
  // drizzleMigrate will fail since they can't see the migration files yet.
75
- _configureFs().then(() => {
76
- sendBack({ type: INTERNAL_CONFIGURING_FS_SUCCESS })
86
+ _configureFs().then((fsConfigured) => {
87
+ if (fsConfigured) {
88
+ sendBack({ type: INTERNAL_CONFIGURING_FS_SUCCESS })
89
+ }
77
90
  return
78
91
  })
79
92
 
@@ -2,8 +2,10 @@ import { metadata, MetadataType } from '@/seedSchema'
2
2
  import { BaseEasClient, BaseQueryClient, generateId } from '@/helpers'
3
3
  import { PropertyType } from '@/types'
4
4
  import { BaseDb } from '../Db/BaseDb'
5
- import { GET_SCHEMA_BY_NAME, GET_SCHEMAS } from '@/Item/queries'
5
+ import { GET_SCHEMA_BY_NAME, } from '@/Item/queries'
6
6
  import { INTERNAL_DATA_TYPES } from '@/helpers/constants'
7
+ import { toSnakeCase } from 'drizzle-orm/casing'
8
+ import { Schema } from '@/graphql/gql/graphql'
7
9
 
8
10
  type CreateMetadata = (
9
11
  metadataValues: Partial<MetadataType>,
@@ -38,20 +40,25 @@ export const createMetadata: CreateMetadata = async (
38
40
  const easClient = BaseEasClient.getEasClient()
39
41
 
40
42
  const easDataType = INTERNAL_DATA_TYPES[propertyRecordSchema.dataType].eas
43
+
44
+ const propertyNameSnakeCase = toSnakeCase(metadataValues.propertyName)
41
45
 
42
46
  const queryResult = await queryClient.fetchQuery({
43
47
  queryKey: [`getSchemaByName${metadataValues.propertyName}`],
44
- queryFn: async () =>
48
+ queryFn: async (): Promise<{schemas: Schema[]}> =>
45
49
  easClient.request(GET_SCHEMA_BY_NAME, {
46
50
  where: {
47
51
  schema: {
48
- equals: `${easDataType} ${metadataValues.propertyName}`,
52
+ equals: `${easDataType} ${propertyNameSnakeCase}`,
49
53
  },
50
54
  },
51
55
  }),
52
56
  })
53
57
 
54
- metadataValues.schemaUid = queryResult.data[0].schema
58
+ if (queryResult && queryResult.schemas.length > 0) {
59
+ metadataValues.schemaUid = queryResult.schemas[0].id
60
+ }
61
+
55
62
  }
56
63
 
57
64
  return appDb
@@ -17,6 +17,7 @@ import { checkStatus } from '@/services/db/actors/checkStatus'
17
17
  import { connectToDb } from '@/services/db/actors/connectToDb'
18
18
  import { validate } from '@/services/db/actors/validate'
19
19
  import { migrate } from '@/services/db/actors/migrate'
20
+ import { waitForFiles } from './actors/waitForFiles'
20
21
 
21
22
  const logger = debug('app:services:db:machine')
22
23
 
@@ -38,6 +39,7 @@ const dbMachine = setup({
38
39
  validate,
39
40
  connectToDb,
40
41
  migrate,
42
+ waitForFiles,
41
43
  },
42
44
  }).createMachine({
43
45
  id: MachineIds.DB,
@@ -146,6 +148,10 @@ const dbMachine = setup({
146
148
  },
147
149
  [DB_MIGRATING_SUCCESS]: 'ready',
148
150
  },
151
+ invoke: {
152
+ src: 'waitForFiles',
153
+ input: ({ context }) => ({ context }),
154
+ },
149
155
  },
150
156
  [MIGRATING]: {
151
157
  on: {
@@ -1,6 +1,6 @@
1
1
  import { syncDbFiles } from '@/services/internal/helpers'
2
2
  import { eventEmitter } from '@/eventBus'
3
- import { fs } from '@zenfs/core'
3
+ import fs from '@zenfs/core'
4
4
  import { ARWEAVE_HOST } from '@/services/internal/constants'
5
5
  import { appState } from '@/seedSchema'
6
6
  import { eq } from 'drizzle-orm'
@@ -44,7 +44,9 @@ export const downloadAllFilesBinaryRequestHandler = async () => {
44
44
  const globalService = getGlobalService()
45
45
  const internalService = globalService.getSnapshot().context.internalService
46
46
  if (internalService) {
47
- await waitFor(internalService, (snapshot) => snapshot.value === 'ready')
47
+ await waitFor(internalService, (snapshot) => {
48
+ return snapshot.value === 'ready'
49
+ })
48
50
  addresses = await getAddressesFromDb()
49
51
  }
50
52
  }
package/dist/src/files.ts CHANGED
@@ -1,5 +1,8 @@
1
- import { fs } from '@zenfs/core'
1
+ import fs from '@zenfs/core'
2
2
  import * as fsNode from 'node:fs'
3
+ import debug from 'debug'
4
+
5
+ const logger = debug('app:helpers:files')
3
6
  // import * as retry from 'async-es/retry'
4
7
 
5
8
  export const listFilesInOPFSRoot = async () => {
@@ -28,13 +31,20 @@ export const listFilesInOPFSRoot = async () => {
28
31
  */
29
32
  export const waitForFile = (
30
33
  filePath: string,
31
- interval: number = 500,
32
- timeout: number = 10000,
34
+ interval: number = 1000,
35
+ timeout: number = 60000,
33
36
  ): Promise<boolean> => {
34
37
  return new Promise((resolve, reject) => {
35
38
  const startTime = Date.now()
36
39
 
37
- const _interval = setInterval(() => {
40
+ let isBusy = false
41
+
42
+ const _interval = setInterval(async () => {
43
+ logger('waitForFile', filePath)
44
+ if (isBusy) {
45
+ return
46
+ }
47
+ isBusy = true
38
48
  if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {
39
49
  clearInterval(_interval)
40
50
  resolve(true)
@@ -43,6 +53,7 @@ export const waitForFile = (
43
53
  clearInterval(_interval)
44
54
  reject(new Error('Timeout exceeded while waiting for file'))
45
55
  }
56
+ isBusy = false
46
57
  }, interval)
47
58
 
48
59
  // retry(
@@ -1,7 +1,8 @@
1
1
  import { GetItemProperties, PropertyData } from '@/types'
2
2
  import { metadata, seeds, versions } from '@/seedSchema'
3
- import { and, eq, getTableColumns, isNotNull, isNull, SQL } from 'drizzle-orm'
3
+ import { and, eq, getTableColumns, isNotNull, isNull, sql, SQL } from 'drizzle-orm'
4
4
  import { BaseDb } from '@/db/Db/BaseDb'
5
+ import { getMetadataLatest } from './subqueries/metadataLatest'
5
6
 
6
7
 
7
8
  export const getItemProperties: GetItemProperties = async ({
@@ -21,16 +22,7 @@ export const getItemProperties: GetItemProperties = async ({
21
22
  whereClauses.push(eq(seeds.localId, seedLocalId))
22
23
  }
23
24
 
24
- // const uidWhereClause: SQL = seedUid
25
- // ? eq(seeds.uid, seedUid)
26
- // : isNull(seeds.uid)
27
- // const localWhereClause: SQL = seedLocalId
28
- // ? eq(seeds.localId, seedLocalId)
29
- // : isNull(seeds.localId)
30
-
31
- // whereClauses.push(or(localWhereClause, uidWhereClause) as SQL)
32
25
  whereClauses.push(isNotNull(metadata.propertyName))
33
- // whereClauses.push(isNotNull(metadata.easDataType))
34
26
 
35
27
  if (typeof edited !== 'undefined') {
36
28
  if (edited) {
@@ -41,17 +33,15 @@ export const getItemProperties: GetItemProperties = async ({
41
33
  }
42
34
  }
43
35
 
44
- const metadataColumns = getTableColumns(metadata)
36
+ // const metadataColumns = getTableColumns(metadata)
37
+
38
+ const metadataLatest = getMetadataLatest({seedLocalId, seedUid})
45
39
 
46
40
  const propertiesData = await appDb
47
- .select({
48
- ...metadataColumns,
49
- })
50
- .from(seeds)
51
- .leftJoin(metadata, eq(metadata.seedLocalId, seeds.localId))
52
- .leftJoin(versions, eq(versions.localId, seeds.localId))
53
- .where(and(...whereClauses))
54
- .groupBy(metadata.propertyName)
41
+ .with(metadataLatest)
42
+ .select()
43
+ .from(metadataLatest)
44
+ .where(eq(metadataLatest.rowNum, 1))
55
45
 
56
46
  return propertiesData.map(data => ({
57
47
  ...data,
@@ -111,6 +111,7 @@ const processRelationProperty = async (
111
111
  relationProperty: IItemProperty<any>,
112
112
  multiPublishPayload: MultiPublishPayload,
113
113
  uploadedTransactions: UploadedTransaction[],
114
+ originalSeedLocalId: string,
114
115
  ): Promise<MultiPublishPayload> => {
115
116
  const value = relationProperty.getService().getSnapshot()
116
117
  .context.propertyValue
@@ -147,7 +148,7 @@ const processRelationProperty = async (
147
148
  listOfAttestations: [],
148
149
  propertiesToUpdate: [
149
150
  {
150
- publishLocalId: relationProperty.localId,
151
+ publishLocalId: originalSeedLocalId,
151
152
  propertySchemaUid: relationProperty.schemaUid,
152
153
  },
153
154
  ],
@@ -182,6 +183,7 @@ const processRelationProperty = async (
182
183
  const processListProperty = async (
183
184
  listProperty: IItemProperty<any>,
184
185
  multiPublishPayload: MultiPublishPayload,
186
+ originalSeedLocalId: string,
185
187
  ): Promise<MultiPublishPayload> => {
186
188
  let value = listProperty.getService().getSnapshot().context.propertyValue
187
189
  if (!value || listProperty.uid) {
@@ -236,7 +238,7 @@ const processListProperty = async (
236
238
  listOfAttestations: [],
237
239
  propertiesToUpdate: [
238
240
  {
239
- publishLocalId: listProperty.localId,
241
+ publishLocalId: originalSeedLocalId,
240
242
  propertySchemaUid: listProperty.schemaUid,
241
243
  },
242
244
  ],
@@ -325,9 +327,19 @@ export const getPublishPayload = async (
325
327
  relationProperty,
326
328
  multiPublishPayload,
327
329
  uploadedTransactions,
330
+ item.seedLocalId,
328
331
  )
329
332
  itemBasicProperties.push(relationProperty)
330
333
  }
334
+
335
+ for (const listProperty of itemListProperties) {
336
+ multiPublishPayload = await processListProperty(
337
+ listProperty,
338
+ multiPublishPayload,
339
+ item.seedLocalId,
340
+ )
341
+ itemBasicProperties.push(listProperty)
342
+ }
331
343
 
332
344
  itemPublishData = await processBasicProperties(
333
345
  itemBasicProperties,
@@ -337,12 +349,7 @@ export const getPublishPayload = async (
337
349
  multiPublishPayload.push(itemPublishData)
338
350
 
339
351
 
340
- for (const listProperty of itemListProperties) {
341
- multiPublishPayload = await processListProperty(
342
- listProperty,
343
- multiPublishPayload,
344
- )
345
- }
352
+
346
353
 
347
354
  return multiPublishPayload
348
355
  }
@@ -1,7 +1,7 @@
1
1
  import Transaction from 'arweave'
2
2
  import { CreateTransactionInterface } from 'arweave/web'
3
3
  import { getArweave } from '@/helpers/ArweaveClient'
4
- import { fs } from '@zenfs/core'
4
+ import fs from '@zenfs/core'
5
5
  import { getCorrectId } from '@/helpers'
6
6
  import { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'
7
7
  import debug from 'debug'
@@ -66,27 +66,6 @@ const processUploadProperty = async (
66
66
  })
67
67
  }
68
68
 
69
- // const filePath = itemProperty.localStoragePath
70
- //
71
- // if (!filePath) {
72
- // throw new Error(
73
- // `No localStoragePath found for ItemProperty ${itemProperty.propertyName}`,
74
- // )
75
- // }
76
- //
77
- // const exists = await fs.promises.exists(filePath)
78
- // if (!exists) {
79
- // throw new Error(`File doesn't exist at ${filePath}`)
80
- //
81
- // // const handle = await navigator.storage.getDirectory()
82
- // //
83
- // // await configureSingle({
84
- // // backend: WebAccess,
85
- // // handle,
86
- // // })
87
- // }
88
- //
89
- // const mainFileContents = await fs.promises.readFile(filePath)
90
69
  let fileContents
91
70
  let transaction: Transaction
92
71
 
@@ -102,12 +81,6 @@ const processUploadProperty = async (
102
81
  if (!exists) {
103
82
  return uploads
104
83
 
105
- // const handle = await navigator.storage.getDirectory()
106
- //
107
- // await configureSingle({
108
- // backend: WebAccess,
109
- // handle,
110
- // })
111
84
  }
112
85
 
113
86
  try {
package/dist/src/gql.ts CHANGED
@@ -14,10 +14,11 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
14
14
  * Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size
15
15
  */
16
16
  const documents = {
17
- "\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n": types.GetTransactionTagsDocument,
18
17
  "\n fragment attestationFields on Attestation {\n id\n decodedDataJson\n attester\n schema {\n schemaNames {\n name\n }\n }\n refUID\n revoked\n schemaId\n txid\n timeCreated\n time\n isOffchain\n }\n": types.AttestationFieldsFragmentDoc,
19
18
  "\n fragment schemaFields on Schema {\n id\n resolver\n revocable\n schema\n index\n schemaNames {\n name\n }\n time\n txid\n creator\n }\n": types.SchemaFieldsFragmentDoc,
19
+ "\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n": types.GetTransactionTagsDocument,
20
20
  "\n query GetSchemas($where: SchemaWhereInput!) {\n schemas: schemata(where: $where) {\n id\n schema\n schemaNames {\n name\n }\n }\n }\n": types.GetSchemasDocument,
21
+ "\n query GetSchemaByName($where: SchemaWhereInput!) {\n schemas: schemata(where: $where) {\n id\n schema\n schemaNames {\n name\n }\n }\n }\n": types.GetSchemaByNameDocument,
21
22
  "\n query GetSeeds($where: AttestationWhereInput!) {\n itemSeeds: attestations(where: $where, orderBy: [{ timeCreated: desc }]) {\n id\n decodedDataJson\n attester\n schema {\n schemaNames {\n name\n }\n }\n refUID\n revoked\n schemaId\n timeCreated\n isOffchain\n }\n }\n": types.GetSeedsDocument,
22
23
  "\n query GetSeedIds($where: AttestationWhereInput!) {\n itemSeedIds: attestations(where: $where, orderBy: [{ timeCreated: desc }]) {\n id\n }\n }\n": types.GetSeedIdsDocument,
23
24
  "\n query GetStorageTransactionId($where: AttestationWhereInput!) {\n storageTransactionId: attestations(\n where: $where\n orderBy: [{ timeCreated: desc }]\n ) {\n id\n decodedDataJson\n }\n }\n": types.GetStorageTransactionIdDocument,
@@ -48,19 +49,23 @@ export function graphql(source: string): unknown;
48
49
  /**
49
50
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
50
51
  */
51
- export function graphql(source: "\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n"): (typeof documents)["\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n"];
52
+ export function graphql(source: "\n fragment attestationFields on Attestation {\n id\n decodedDataJson\n attester\n schema {\n schemaNames {\n name\n }\n }\n refUID\n revoked\n schemaId\n txid\n timeCreated\n time\n isOffchain\n }\n"): (typeof documents)["\n fragment attestationFields on Attestation {\n id\n decodedDataJson\n attester\n schema {\n schemaNames {\n name\n }\n }\n refUID\n revoked\n schemaId\n txid\n timeCreated\n time\n isOffchain\n }\n"];
52
53
  /**
53
54
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
54
55
  */
55
- export function graphql(source: "\n fragment attestationFields on Attestation {\n id\n decodedDataJson\n attester\n schema {\n schemaNames {\n name\n }\n }\n refUID\n revoked\n schemaId\n txid\n timeCreated\n time\n isOffchain\n }\n"): (typeof documents)["\n fragment attestationFields on Attestation {\n id\n decodedDataJson\n attester\n schema {\n schemaNames {\n name\n }\n }\n refUID\n revoked\n schemaId\n txid\n timeCreated\n time\n isOffchain\n }\n"];
56
+ export function graphql(source: "\n fragment schemaFields on Schema {\n id\n resolver\n revocable\n schema\n index\n schemaNames {\n name\n }\n time\n txid\n creator\n }\n"): (typeof documents)["\n fragment schemaFields on Schema {\n id\n resolver\n revocable\n schema\n index\n schemaNames {\n name\n }\n time\n txid\n creator\n }\n"];
56
57
  /**
57
58
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
58
59
  */
59
- export function graphql(source: "\n fragment schemaFields on Schema {\n id\n resolver\n revocable\n schema\n index\n schemaNames {\n name\n }\n time\n txid\n creator\n }\n"): (typeof documents)["\n fragment schemaFields on Schema {\n id\n resolver\n revocable\n schema\n index\n schemaNames {\n name\n }\n time\n txid\n creator\n }\n"];
60
+ export function graphql(source: "\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n"): (typeof documents)["\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n"];
60
61
  /**
61
62
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
62
63
  */
63
64
  export function graphql(source: "\n query GetSchemas($where: SchemaWhereInput!) {\n schemas: schemata(where: $where) {\n id\n schema\n schemaNames {\n name\n }\n }\n }\n"): (typeof documents)["\n query GetSchemas($where: SchemaWhereInput!) {\n schemas: schemata(where: $where) {\n id\n schema\n schemaNames {\n name\n }\n }\n }\n"];
65
+ /**
66
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
67
+ */
68
+ export function graphql(source: "\n query GetSchemaByName($where: SchemaWhereInput!) {\n schemas: schemata(where: $where) {\n id\n schema\n schemaNames {\n name\n }\n }\n }\n"): (typeof documents)["\n query GetSchemaByName($where: SchemaWhereInput!) {\n schemas: schemata(where: $where) {\n id\n schema\n schemaNames {\n name\n }\n }\n }\n"];
64
69
  /**
65
70
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
66
71
  */