@seedprotocol/sdk 0.2.6 → 0.2.8

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 (100) hide show
  1. package/dist/EasClient-DdahV-My.js +13 -0
  2. package/dist/EasClient-DdahV-My.js.map +1 -0
  3. package/dist/EasClient-virlpmud.js +13 -0
  4. package/dist/EasClient-virlpmud.js.map +1 -0
  5. package/dist/FileManager-5GT-dMg0.js +16 -0
  6. package/dist/FileManager-5GT-dMg0.js.map +1 -0
  7. package/dist/FileManager-hdyZkwYe.js +18 -0
  8. package/dist/FileManager-hdyZkwYe.js.map +1 -0
  9. package/dist/{Item-5bbmH1H4.js → Item-Da3oF6rX.js} +3 -3
  10. package/dist/{Item-5bbmH1H4.js.map → Item-Da3oF6rX.js.map} +1 -1
  11. package/dist/QueryClient-DI1wuuAt.js +23 -0
  12. package/dist/QueryClient-DI1wuuAt.js.map +1 -0
  13. package/dist/QueryClient-J0ohccHX.js +21 -0
  14. package/dist/QueryClient-J0ohccHX.js.map +1 -0
  15. package/dist/bin.js +4 -26
  16. package/dist/bin.js.map +1 -1
  17. package/dist/{constants-CtWTDW5q.js → constants-C0HNnrob.js} +11 -2
  18. package/dist/constants-C0HNnrob.js.map +1 -0
  19. package/dist/{index-CoqbOXfg.js → index-BAqEY103.js} +3 -3
  20. package/dist/index-BAqEY103.js.map +1 -0
  21. package/dist/{index-s_H8DdLb.js → index-vIPO_QrC.js} +67 -46
  22. package/dist/index-vIPO_QrC.js.map +1 -0
  23. package/dist/main.js +2 -2
  24. package/dist/{seed.schema.config-CTpDY6LU.js → seed.schema.config-DrHfhLwp.js} +3 -3
  25. package/dist/{seed.schema.config-CTpDY6LU.js.map → seed.schema.config-DrHfhLwp.js.map} +1 -1
  26. package/dist/src/BaseArweaveClient.ts +1 -1
  27. package/dist/src/{EasClientNode.ts → EasClient.ts} +4 -4
  28. package/dist/src/FileManager.ts +13 -0
  29. package/dist/src/{QueryClientNode.ts → QueryClient.ts} +4 -6
  30. package/dist/src/actors.ts +7 -292
  31. package/dist/src/client.ts +6 -0
  32. package/dist/src/download.ts +5 -3
  33. package/dist/src/fetchDataFromEas.ts +3 -3
  34. package/dist/src/fetchRelatedItems.ts +5 -4
  35. package/dist/src/fetchSeeds.ts +5 -4
  36. package/dist/src/fetchVersions.ts +2 -2
  37. package/dist/src/getModelSchemas.ts +2 -2
  38. package/dist/src/getSchemaUidForModel.ts +2 -2
  39. package/dist/src/index.ts +21 -4
  40. package/dist/src/queries.ts +25 -37
  41. package/dist/src/saveImageSrc.ts +1 -1
  42. package/dist/src/syncDbWithEas.ts +2 -2
  43. package/dist/src/waitForDb.ts +17 -18
  44. package/dist/types/scripts/bin.d.ts +3 -3
  45. package/dist/types/scripts/bin.d.ts.map +1 -1
  46. package/dist/types/src/Item/service/actors/fetchDataFromEas.d.ts.map +1 -1
  47. package/dist/types/src/browser/helpers/EasClient.d.ts +7 -0
  48. package/dist/types/src/browser/helpers/EasClient.d.ts.map +1 -0
  49. package/dist/types/src/browser/helpers/FileManager.d.ts +6 -0
  50. package/dist/types/src/browser/helpers/FileManager.d.ts.map +1 -0
  51. package/dist/types/src/browser/helpers/QueryClient.d.ts +7 -0
  52. package/dist/types/src/browser/helpers/QueryClient.d.ts.map +1 -0
  53. package/dist/types/src/client.d.ts.map +1 -1
  54. package/dist/types/src/events/files/download.d.ts.map +1 -1
  55. package/dist/types/src/helpers/EasClient/BaseEasClient.d.ts.map +1 -0
  56. package/dist/types/src/helpers/EasClient/index.d.ts +5 -0
  57. package/dist/types/src/helpers/EasClient/index.d.ts.map +1 -0
  58. package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -0
  59. package/dist/types/src/helpers/FileManager/index.d.ts +5 -0
  60. package/dist/types/src/helpers/FileManager/index.d.ts.map +1 -0
  61. package/dist/types/src/helpers/QueryClient/BaseQueryClient.d.ts.map +1 -0
  62. package/dist/types/src/helpers/QueryClient/index.d.ts +5 -0
  63. package/dist/types/src/helpers/QueryClient/index.d.ts.map +1 -0
  64. package/dist/types/src/helpers/index.d.ts +3 -3
  65. package/dist/types/src/helpers/index.d.ts.map +1 -1
  66. package/dist/types/src/node/helpers/EasClient.d.ts +7 -0
  67. package/dist/types/src/node/helpers/EasClient.d.ts.map +1 -0
  68. package/dist/types/src/node/helpers/FileManager.d.ts +6 -0
  69. package/dist/types/src/node/helpers/FileManager.d.ts.map +1 -0
  70. package/dist/types/src/node/helpers/QueryClient.d.ts +9 -0
  71. package/dist/types/src/node/helpers/QueryClient.d.ts.map +1 -0
  72. package/dist/types/src/services/allItems/actors/fetchRelatedItems.d.ts.map +1 -1
  73. package/dist/types/src/services/allItems/actors/fetchSeeds.d.ts.map +1 -1
  74. package/dist/types/src/services/allItems/actors/initialize.d.ts.map +1 -1
  75. package/package.json +3 -4
  76. package/dist/constants-CtWTDW5q.js.map +0 -1
  77. package/dist/index-CoqbOXfg.js.map +0 -1
  78. package/dist/index-s_H8DdLb.js.map +0 -1
  79. package/dist/src/EasClientWeb.ts +0 -13
  80. package/dist/src/FileManagerNode.ts +0 -31
  81. package/dist/src/FileManagerWeb.ts +0 -18
  82. package/dist/src/QueryClientWeb.ts +0 -20
  83. package/dist/types/src/browser/helpers/EasClientWeb.d.ts +0 -7
  84. package/dist/types/src/browser/helpers/EasClientWeb.d.ts.map +0 -1
  85. package/dist/types/src/browser/helpers/FileManagerWeb.d.ts +0 -5
  86. package/dist/types/src/browser/helpers/FileManagerWeb.d.ts.map +0 -1
  87. package/dist/types/src/browser/helpers/QueryClientWeb.d.ts +0 -7
  88. package/dist/types/src/browser/helpers/QueryClientWeb.d.ts.map +0 -1
  89. package/dist/types/src/helpers/BaseEasClient.d.ts.map +0 -1
  90. package/dist/types/src/helpers/BaseFileManager.d.ts.map +0 -1
  91. package/dist/types/src/helpers/BaseQueryClient.d.ts.map +0 -1
  92. package/dist/types/src/node/helpers/EasClientNode.d.ts +0 -7
  93. package/dist/types/src/node/helpers/EasClientNode.d.ts.map +0 -1
  94. package/dist/types/src/node/helpers/FileManagerNode.d.ts +0 -9
  95. package/dist/types/src/node/helpers/FileManagerNode.d.ts.map +0 -1
  96. package/dist/types/src/node/helpers/QueryClientNode.d.ts +0 -9
  97. package/dist/types/src/node/helpers/QueryClientNode.d.ts.map +0 -1
  98. /package/dist/types/src/helpers/{BaseEasClient.d.ts → EasClient/BaseEasClient.d.ts} +0 -0
  99. /package/dist/types/src/helpers/{BaseFileManager.d.ts → FileManager/BaseFileManager.d.ts} +0 -0
  100. /package/dist/types/src/helpers/{BaseQueryClient.d.ts → QueryClient/BaseQueryClient.d.ts} +0 -0
package/dist/main.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import 'immer';
2
2
  import 'reflect-metadata';
3
- export { l as BaseFileManager, a as ImageSrc, I as Item, b as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, n as client, m as eventEmitter, k as getCorrectId, j as getGlobalService, e as useCreateItem, g as useDeleteItem, h as useGlobalServiceStatus, c as useItem, d as useItemProperties, f as useItemProperty, u as useItems, i as useServices, w as withSeed } from './index-s_H8DdLb.js';
3
+ export { a as ImageSrc, I as Item, b as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, m as client, l as eventEmitter, k as getCorrectId, j as getGlobalService, e as useCreateItem, g as useDeleteItem, h as useGlobalServiceStatus, c as useItem, d as useItemProperties, f as useItemProperty, u as useItems, i as useServices, w as withSeed } from './index-vIPO_QrC.js';
4
4
  import 'tslib';
5
5
  import 'xstate';
6
6
  import 'arweave';
7
7
  import 'drizzle-orm';
8
- export { b as BaseArweaveClient, B as BaseEasClient, a as BaseQueryClient } from './constants-CtWTDW5q.js';
8
+ export { c as BaseArweaveClient, B as BaseEasClient, b as BaseFileManager, a as BaseQueryClient } from './constants-C0HNnrob.js';
9
9
  import '@sinclair/typebox';
10
10
  import 'rxjs';
11
11
  import '@zenfs/core';
@@ -1,6 +1,6 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
2
  import 'drizzle-orm';
3
- import { T as Text, M as Model } from './index-s_H8DdLb.js';
3
+ import { T as Text, M as Model } from './index-vIPO_QrC.js';
4
4
  import 'react';
5
5
  import 'reflect-metadata';
6
6
  import 'xstate';
@@ -13,7 +13,7 @@ import 'dayjs';
13
13
  import 'nanoid';
14
14
  import 'nanoid-dictionary';
15
15
  import 'debug';
16
- import './constants-CtWTDW5q.js';
16
+ import './constants-C0HNnrob.js';
17
17
  import '@ethereum-attestation-service/eas-sdk';
18
18
  import 'drizzle-orm/sqlite-core';
19
19
  import 'path';
@@ -75,4 +75,4 @@ const models = {
75
75
  };
76
76
 
77
77
  export { models };
78
- //# sourceMappingURL=seed.schema.config-CTpDY6LU.js.map
78
+ //# sourceMappingURL=seed.schema.config-DrHfhLwp.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"seed.schema.config-CTpDY6LU.js","sources":["../../src/shared/configs/seed.schema.config.ts"],"sourcesContent":["import { Model, Text } from '@/browser'\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,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,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,KAAA,CAAA,CAAA;AAChB,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,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,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAe,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,KAAA,CAAA,CAAA;AAFlB,QAAQ,GAAA,UAAA,CAAA;IADb;AACK,CAAA,EAAA,QAAQ,CAGb;AAEY,MAAA,MAAM,GAAG;IACpB,IAAI;IACJ,OAAO;IACP,QAAQ;;;;;"}
1
+ {"version":3,"file":"seed.schema.config-DrHfhLwp.js","sources":["../../src/shared/configs/seed.schema.config.ts"],"sourcesContent":["import { Model, Text } from '@/browser'\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,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,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,KAAA,CAAA,CAAA;AAChB,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,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,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAe,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,KAAA,CAAA,CAAA;AAFlB,QAAQ,GAAA,UAAA,CAAA;IADb;AACK,CAAA,EAAA,QAAQ,CAGb;AAEY,MAAA,MAAM,GAAG;IACpB,IAAI;IACJ,OAAO;IACP,QAAQ;;;;;"}
@@ -10,4 +10,4 @@ export abstract class BaseArweaveClient {
10
10
  static getArweaveClient(): GraphQLClient {
11
11
  return this.PlatformClass.getArweaveClient()
12
12
  }
13
- }
13
+ }
@@ -1,13 +1,13 @@
1
- import { BaseEasClient } from "@/helpers/BaseEasClient"
1
+ import { BaseEasClient } from "@/helpers/EasClient/BaseEasClient"
2
2
  import { EAS_ENDPOINT } from "@/services/internal/constants"
3
3
  import { GraphQLClient } from "graphql-request"
4
4
 
5
- class EasClientNode extends BaseEasClient {
5
+ class EasClient extends BaseEasClient {
6
6
  static getEasClient() {
7
7
  return new GraphQLClient(EAS_ENDPOINT)
8
8
  }
9
9
  }
10
10
 
11
- BaseEasClient.setPlatformClass(EasClientNode)
11
+ BaseEasClient.setPlatformClass(EasClient)
12
12
 
13
- export { EasClientNode }
13
+ export { EasClient }
@@ -0,0 +1,13 @@
1
+ import { promises as fs } from 'fs';
2
+ import { BaseFileManager } from '@/helpers/FileManager/BaseFileManager';
3
+
4
+ class FileManager extends BaseFileManager {
5
+ static async readFileAsBuffer(filePath: string): Promise<Buffer> {
6
+ return await fs.readFile(filePath);
7
+ }
8
+
9
+ }
10
+
11
+ BaseFileManager.setPlatformClass(FileManager);
12
+
13
+ export { FileManager };
@@ -1,8 +1,6 @@
1
- import { BaseQueryClient } from "@/helpers/BaseQueryClient"
2
- import { EAS_ENDPOINT } from "@/services/internal/constants"
3
- import { GraphQLClient } from "graphql-request"
1
+ import { BaseQueryClient } from "@/helpers/QueryClient/BaseQueryClient"
4
2
 
5
- class QueryClientNode extends BaseQueryClient {
3
+ class QueryClient extends BaseQueryClient {
6
4
  static getQueryClient() {
7
5
  return {
8
6
  fetchQuery: () => {
@@ -19,6 +17,6 @@ class QueryClientNode extends BaseQueryClient {
19
17
  }
20
18
  }
21
19
 
22
- BaseQueryClient.setPlatformClass(QueryClientNode)
20
+ BaseQueryClient.setPlatformClass(QueryClient)
23
21
 
24
- export { QueryClientNode }
22
+ export { QueryClient }
@@ -1,295 +1,10 @@
1
1
  import { EventObject, fromCallback } from 'xstate'
2
- import { fetchAllFilesMachine } from '@/browser/schema/file/fetchAll/index'
3
- import { ARWEAVE_HOST } from '@/services/internal/constants'
4
- import { GET_FILES_METADATA } from '@/browser/schema/file/queries'
5
- import { getArweave } from '@/browser/helpers/arweave'
6
- import { fs } from '@zenfs/core'
7
- import {
8
- getDataTypeFromString,
9
- getMimeType,
10
- identifyString,
11
- } from '@/helpers'
12
- import { appState } from '@/seedSchema'
13
- import { eq } from 'drizzle-orm'
14
- import { BaseEasClient } from '@/helpers/BaseEasClient'
15
- import { BaseQueryClient } from '@/helpers/BaseQueryClient'
16
- import debug from 'debug'
17
- import { BaseDb } from '@/db/BaseDb'
18
- import { saveAppState } from '@/db/write/saveAppState'
2
+ import { uploadMachine } from '@/browser/schema/file/upload/index'
19
3
 
20
- const logger = debug('app:file:actors:fetchAll')
4
+ export const uploadBinaryData = fromCallback<EventObject, typeof uploadMachine>(
5
+ ({ sendBack, receive, input }) => {},
6
+ )
21
7
 
22
- type FileType = {
23
- mimeType: string
24
- extension: string
25
- }
26
-
27
- // Map of common MIME types to file extensions
28
- const fileTypeMap: Record<string, FileType> = {
29
- 'image/jpeg': { mimeType: 'image/jpeg', extension: '.jpg' },
30
- 'image/png': { mimeType: 'image/png', extension: '.png' },
31
- 'application/json': { mimeType: 'application/json', extension: '.json' },
32
- 'text/plain': { mimeType: 'text/plain', extension: '.txt' },
33
- // Add more MIME types and file extensions as needed
34
- }
35
-
36
- export const fetchAllMetadataRecords = fromCallback<
37
- EventObject,
38
- typeof fetchAllFilesMachine
39
- >(({ sendBack, receive, input: { context, event } }) => {
40
- const { addresses } = context
41
-
42
- const _fetchAllMetadataRecords = async () => {
43
- const queryClient = BaseQueryClient.getQueryClient()
44
- const easClient = BaseEasClient.getEasClient()
45
-
46
- const { filesMetadata } = await queryClient.fetchQuery({
47
- queryKey: ['getFilesMetadata', ...addresses],
48
- queryFn: async () =>
49
- easClient.request(GET_FILES_METADATA, {
50
- where: {
51
- attester: {
52
- in: addresses,
53
- },
54
- schema: {
55
- is: {
56
- id: {
57
- equals:
58
- '0x55fdefb36fcbbaebeb7d6b41dc3a1a9666e4e42154267c889de064faa7ede517',
59
- },
60
- },
61
- },
62
- },
63
- }),
64
- })
65
-
66
- return filesMetadata
67
- }
68
-
69
- _fetchAllMetadataRecords().then((filesMetadata) => {
70
- sendBack({ type: 'fetchingAllMetadataRecordsSuccess', filesMetadata })
71
- })
72
-
73
- return () => { }
74
- })
75
-
76
- export const fetchAllBinaryData = fromCallback<
77
- EventObject,
78
- typeof fetchAllFilesMachine
79
- >(({ sendBack, input: { context } }) => {
80
- const { filesMetadata, addresses } = context
81
-
82
- const _fetchAllBinaryData = async () => {
83
- if (!(await fs.promises.exists('/files'))) {
84
- await fs.promises.mkdir('/files', { recursive: true })
85
- }
86
-
87
- if (!(await fs.promises.exists('/files/html'))) {
88
- await fs.promises.mkdir('/files/html', { recursive: true })
89
- }
90
-
91
- if (!(await fs.promises.exists('/files/json'))) {
92
- await fs.promises.mkdir('/files/json', { recursive: true })
93
- }
94
-
95
- if (!(await fs.promises.exists('/files/images'))) {
96
- await fs.promises.mkdir('/files/images', { recursive: true })
97
- }
98
-
99
- const appDb = BaseDb.getAppDb()
100
-
101
- if (!appDb) {
102
- logger('[fetchAll/actors] [fetchAllBinaryData] seedDb not available')
103
- return []
104
- }
105
-
106
- for (const fileMetadata of filesMetadata) {
107
- const json = JSON.parse(fileMetadata.decodedDataJson)
108
- const transactionId = json[0].value.value
109
-
110
- const excludedTransactionsQuery = await appDb
111
- .select()
112
- .from(appState)
113
- .where(eq(appState.key, 'excludedTransactions'))
114
-
115
- let excludedTransactions = new Set<string>()
116
-
117
- if (excludedTransactionsQuery && excludedTransactionsQuery.length === 1) {
118
- const valueString = excludedTransactionsQuery[0].value
119
- if (valueString) {
120
- const excludedTransactionsArray = JSON.parse(valueString)
121
- excludedTransactions = new Set(excludedTransactionsArray)
122
- }
123
- }
124
-
125
- if (excludedTransactions.has(transactionId)) {
126
- continue
127
- }
128
-
129
- const arweave = getArweave()
130
-
131
- if (!arweave) {
132
- logger('[fetchAll/actors] [fetchAllBinaryData] arweave not available')
133
- return []
134
- }
135
-
136
- try {
137
- const res = await fetch(
138
- `https://${ARWEAVE_HOST}/tx/${transactionId}/status`,
139
- )
140
-
141
- if (res.status !== 200) {
142
- logger(
143
- `[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`,
144
- )
145
-
146
- excludedTransactions.add(transactionId)
147
-
148
- await saveAppState(
149
- 'excludedTransactions',
150
- JSON.stringify(Array.from(excludedTransactions)),
151
- )
152
-
153
- logger(
154
- '[fetchAll/actors] [fetchAllBinaryData] updated excludedTransactions:',
155
- excludedTransactions,
156
- )
157
-
158
- continue
159
- }
160
-
161
- const dataString = await arweave.transactions
162
- .getData(transactionId, {
163
- decode: true,
164
- string: true,
165
- })
166
- .catch((error) => {
167
- logger(
168
- `[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`,
169
- error,
170
- )
171
- })
172
-
173
- const dataUint8Array = await arweave.transactions.getData(transactionId)
174
- // let buffer
175
- //
176
- // if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
177
- // }
178
-
179
- let contentType = identifyString(dataString)
180
- if (
181
- contentType !== 'json' &&
182
- contentType !== 'base64' &&
183
- contentType !== 'html'
184
- ) {
185
- const possibleImageType = getDataTypeFromString(dataString)
186
- if (!possibleImageType) {
187
- logger(
188
- `[fetchAll/actors] [fetchAllBinaryData] transaction ${transactionId} data not in expected format: ${possibleImageType}`,
189
- )
190
- continue
191
- }
192
-
193
- contentType = possibleImageType
194
- }
195
-
196
- if (contentType === 'url') {
197
- const url = dataString as string
198
- const response = await fetch(url)
199
- if (!response.ok) {
200
- throw new Error(`Failed to fetch image: ${response.statusText}`)
201
- }
202
-
203
- // Get the image as a Blob
204
- const blob = await response.blob()
205
- const buffer = await blob.arrayBuffer()
206
- const bufferUint8Array = new Uint8Array(buffer)
207
-
208
- // Extract the file extension from the URL
209
- const extensionMatch = url.match(
210
- /\.(jpg|jpeg|png|gif|bmp|webp|svg)$/i,
211
- )
212
- if (!extensionMatch) {
213
- throw new Error(
214
- 'Unable to determine the file extension from the URL.',
215
- )
216
- }
217
- const fileExtension = extensionMatch[0] // e.g., ".jpg"
218
-
219
- // Set the file name (you can customize this)
220
- // const fileNameFromUrl = `${transactionId}${fileExtension}`
221
-
222
- await fs.promises.writeFile(
223
- `/files/images/${transactionId}`,
224
- bufferUint8Array,
225
- {
226
- encoding: 'binary',
227
- },
228
- )
229
-
230
- continue
231
- }
232
-
233
- let mimeType = getMimeType(dataString as string)
234
- let fileExtension = mimeType
235
-
236
- if (fileExtension && fileExtension?.startsWith('image')) {
237
- fileExtension = fileExtension.replace('image/', '')
238
- }
239
-
240
- let fileName = transactionId
241
-
242
- if (contentType === 'base64') {
243
- if (mimeType) {
244
- fileName += `.${fileExtension}`
245
- }
246
-
247
- // Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
248
- const base64Data = dataString.split(',').pop() || ''
249
-
250
- // Decode the Base64 string to binary
251
- const binaryString = atob(base64Data)
252
- const length = binaryString.length
253
- const binaryData = new Uint8Array(length)
254
-
255
- for (let i = 0; i < length; i++) {
256
- binaryData[i] = binaryString.charCodeAt(i)
257
- }
258
-
259
- console.log(`attempting to writeFile to /files/images/${fileName}`)
260
-
261
- await fs.promises.writeFile(`/files/images/${fileName}`, binaryData, {
262
- encoding: 'binary',
263
- })
264
-
265
- // if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
266
- // await fs.promises.writeFile(
267
- // `/files/images/${fileName}`,
268
- // dataUint8Array,
269
- // )
270
- // }
271
- }
272
-
273
- if (contentType === 'html') {
274
- fileName += '.html'
275
- await fs.promises.writeFile(`/files/html/${fileName}`, dataString)
276
- }
277
-
278
- if (contentType === 'json') {
279
- fileName += '.json'
280
- await fs.promises.writeFile(`/files/json/${fileName}`, dataString)
281
- }
282
- } catch (error) {
283
- logger(error)
284
- }
285
- }
286
-
287
- return []
288
- }
289
-
290
- _fetchAllBinaryData().then((binaryData) => {
291
- sendBack({ type: 'fetchingAllBinaryDataSuccess', binaryData })
292
- })
293
-
294
- return () => { }
295
- })
8
+ export const uploadMetadata = fromCallback<EventObject, typeof uploadMachine>(
9
+ ({ sendBack, receive, input }) => {},
10
+ )
@@ -14,12 +14,18 @@ import { setupServiceHandlers } from '@/events/services'
14
14
  import { setArweaveDomain } from '@/browser/helpers/arweave'
15
15
  import { initItem } from './Item'
16
16
  import { initItemProperty } from './ItemProperty'
17
+ import { initEasClient } from './helpers/EasClient'
18
+ import { initQueryClient } from './helpers/QueryClient'
19
+ import { initFileManager } from './helpers/FileManager'
17
20
 
18
21
  const client = {
19
22
  init: async ({ config, addresses }: Promise<SeedConstructorOptions>) => {
20
23
 
21
24
  await initItem()
22
25
  await initItemProperty()
26
+ await initEasClient()
27
+ await initQueryClient()
28
+ await initFileManager()
23
29
 
24
30
  const { endpoints, models, arweaveDomain } = config
25
31
 
@@ -22,9 +22,6 @@ import { saveAppState } from '@/db/write/saveAppState'
22
22
  import { BaseDb } from '@/db/BaseDb'
23
23
  import { BaseEasClient, BaseQueryClient, BaseArweaveClient } from '@/helpers'
24
24
 
25
- const easClient = BaseEasClient.getEasClient()
26
- const queryClient = BaseQueryClient.getQueryClient()
27
- const arweaveClient = BaseArweaveClient.getArweaveClient()
28
25
 
29
26
  const logger = debug('app:files:download')
30
27
 
@@ -58,6 +55,9 @@ export const downloadAllFilesBinaryRequestHandler = async () => {
58
55
  return
59
56
  }
60
57
 
58
+ const queryClient = BaseQueryClient.getQueryClient()
59
+ const easClient = BaseEasClient.getEasClient()
60
+
61
61
  const { filesMetadata } = await queryClient.fetchQuery({
62
62
  queryKey: ['getFilesMetadata', ...addresses],
63
63
  queryFn: async () =>
@@ -157,6 +157,8 @@ export const downloadAllFilesBinaryRequestHandler = async () => {
157
157
  console.log('transactionId', transactionId)
158
158
  }
159
159
 
160
+ const arweaveClient = BaseArweaveClient.getArweaveClient()
161
+
160
162
  const { tags: tagsResult } = await queryClient.fetchQuery({
161
163
  queryKey: ['getTransactionTags', transactionId],
162
164
  queryFn: async () =>
@@ -6,9 +6,6 @@ import { Attestation } from '@/graphql/gql/graphql'
6
6
  import { ModelClassType } from '@/types'
7
7
  import { BaseEasClient, BaseQueryClient } from '@/helpers'
8
8
 
9
- const easClient = BaseEasClient.getEasClient()
10
- const queryClient = BaseQueryClient.getQueryClient()
11
-
12
9
 
13
10
  export const fetchDataFromEas = fromCallback<
14
11
  EventObject,
@@ -37,6 +34,9 @@ export const fetchDataFromEas = fromCallback<
37
34
  }
38
35
 
39
36
  const _fetchDataFromEas = async (): Promise<void> => {
37
+ const queryClient = BaseQueryClient.getQueryClient()
38
+ const easClient = BaseEasClient.getEasClient()
39
+
40
40
  // Fetch Properties by versionUid
41
41
  const { itemProperties } = await queryClient.fetchQuery({
42
42
  queryKey: ['getProperties', versionUid],
@@ -18,11 +18,9 @@ import {
18
18
  import { getAddressesFromDb } from '@/helpers/db'
19
19
  import { eq } from 'drizzle-orm'
20
20
  import { BaseDb } from '@/db/BaseDb'
21
- import { BaseEasClient } from '@/helpers/BaseEasClient'
22
- import { BaseQueryClient } from '@/helpers/BaseQueryClient'
21
+ import { BaseEasClient } from '@/helpers/EasClient/BaseEasClient'
22
+ import { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'
23
23
 
24
- const easClient = BaseEasClient.getEasClient()
25
- const queryClient = BaseQueryClient.getQueryClient()
26
24
 
27
25
  export const fetchRelatedItems = fromCallback<
28
26
  EventObject,
@@ -76,6 +74,9 @@ export const fetchRelatedItems = fromCallback<
76
74
 
77
75
  const queryKey = [`getRelatedSeedIds${modelName}`]
78
76
 
77
+ const queryClient = BaseQueryClient.getQueryClient()
78
+ const easClient = BaseEasClient.getEasClient()
79
+
79
80
  const { itemSeedIds: relatedSeedIdAttestations } =
80
81
  await queryClient.fetchQuery({
81
82
  queryKey,
@@ -2,12 +2,10 @@ import { EventObject, fromCallback } from 'xstate'
2
2
  import { GET_SEEDS } from '@/Item/queries'
3
3
  import { AllItemsMachineContext, FromCallbackInput } from '@/types'
4
4
  import { Attestation } from '@/graphql/gql/graphql'
5
- import { BaseEasClient } from '@/helpers/BaseEasClient'
6
- import { BaseQueryClient } from '@/helpers/BaseQueryClient'
5
+ import { BaseEasClient } from '@/helpers/EasClient/BaseEasClient'
6
+ import { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'
7
7
  import debug from 'debug'
8
8
 
9
- const easClient = BaseEasClient.getEasClient()
10
- const queryClient = BaseQueryClient.getQueryClient()
11
9
 
12
10
  const logger = debug('app:allItemsActors:fetchSeeds')
13
11
 
@@ -27,6 +25,9 @@ export const fetchSeeds = fromCallback<
27
25
  const _fetchSeeds = async () => {
28
26
  const queryKey = [`getSeeds${modelName}`]
29
27
 
28
+ const queryClient = BaseQueryClient.getQueryClient()
29
+ const easClient = BaseEasClient.getEasClient()
30
+
30
31
  const cachedResults = queryClient.getQueryData(queryKey)
31
32
 
32
33
  logger(
@@ -2,8 +2,8 @@ import { EventObject, fromCallback } from 'xstate'
2
2
  import { GET_VERSIONS } from '@/Item/queries'
3
3
  import { AllItemsMachineContext, FromCallbackInput } from '@/types'
4
4
  import { Attestation } from '@/graphql/gql/graphql'
5
- import { BaseEasClient } from '@/helpers/BaseEasClient'
6
- import { BaseQueryClient } from '@/helpers/BaseQueryClient'
5
+ import { BaseEasClient } from '@/helpers/EasClient/BaseEasClient'
6
+ import { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'
7
7
 
8
8
 
9
9
  export const fetchVersions = fromCallback<
@@ -6,8 +6,8 @@ import { eq } from 'drizzle-orm'
6
6
  import pluralize from 'pluralize'
7
7
  import { toSnakeCase } from '@/helpers'
8
8
  import { GET_SCHEMAS } from '@/Item/queries'
9
- import { BaseEasClient } from '@/helpers/BaseEasClient'
10
- import { BaseQueryClient } from '@/helpers/BaseQueryClient'
9
+ import { BaseEasClient } from '@/helpers/EasClient/BaseEasClient'
10
+ import { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'
11
11
 
12
12
 
13
13
  type GetModelSchemasReturn = {
@@ -1,6 +1,6 @@
1
1
  import { GET_SCHEMAS } from '@/Item/queries'
2
- import { BaseEasClient } from '@/helpers/BaseEasClient'
3
- import { BaseQueryClient } from '@/helpers/BaseQueryClient'
2
+ import { BaseEasClient } from '@/helpers/EasClient/BaseEasClient'
3
+ import { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'
4
4
 
5
5
 
6
6
  export const getSchemaUidForModel = async (
package/dist/src/index.ts CHANGED
@@ -1,4 +1,21 @@
1
- export * from './analyzeInput'
2
- export * from './saveImageSrc'
3
- export * from './saveRelation'
4
- export * from './saveItemStorage'
1
+ import { setup } from 'xstate'
2
+ import {
3
+ uploadBinaryData,
4
+ uploadMetadata,
5
+ } from '@/browser/schema/file/upload/actors'
6
+
7
+ export const uploadMachine = setup({
8
+ actors: {
9
+ uploadBinaryData,
10
+ uploadMetadata,
11
+ },
12
+ }).createMachine({
13
+ id: 'upload',
14
+ initial: 'idle',
15
+ context: {
16
+ file: '',
17
+ },
18
+ states: {
19
+ idle: {},
20
+ },
21
+ })
@@ -1,46 +1,34 @@
1
1
  import { graphql } from '@/graphql/gql'
2
2
 
3
- export const GET_FILES_METADATA = graphql(/* GraphQL */ `
4
- query GetFilesMetadata($where: AttestationWhereInput!) {
5
- filesMetadata: attestations(
6
- where: $where
7
- orderBy: [{ timeCreated: desc }]
8
- ) {
9
- ...attestationFields
3
+ export const GET_IMAGE_SEEDS = graphql(/* GraphQL */ `
4
+ query GetImageSeeds($where: AttestationWhereInput!) {
5
+ imageSeeds: attestations(where: $where, orderBy: [{ timeCreated: desc }]) {
6
+ id
7
+ decodedDataJson
8
+ attester
9
+ schema {
10
+ schemaNames {
11
+ name
12
+ }
13
+ }
14
+ refUID
15
+ revoked
16
+ schemaId
17
+ txid
18
+ timeCreated
19
+ time
20
+ isOffchain
10
21
  }
11
22
  }
12
23
  `)
13
24
 
14
- export const GET_ARWEAVE_TRANSACTIONS = graphql(/* GraphQL */ `
15
- query GetArweaveTransactions(
16
- $owners: [String!]
17
- $first: Int
18
- $after: String
19
- ) {
20
- transactions(owners: $owners, first: $first, after: $after) {
21
- edges {
22
- cursor
23
- node {
24
- id
25
- anchor
26
- signature
27
- block {
28
- id
29
- height
30
- }
31
- data {
32
- size
33
- type
34
- }
35
- tags {
36
- name
37
- value
38
- }
39
- }
40
- }
41
- pageInfo {
42
- hasNextPage
43
- }
25
+ export const GET_IMAGE_VERSIONS = graphql(/* GraphQL */ `
26
+ query GetImageVersions($where: AttestationWhereInput!) {
27
+ imageVersions: attestations(
28
+ where: $where
29
+ orderBy: [{ timeCreated: desc }]
30
+ ) {
31
+ ...attestationFields
44
32
  }
45
33
  }
46
34
  `)
@@ -14,7 +14,7 @@ import { createMetadata } from '@/db/write/createMetadata'
14
14
  import { updateItemPropertyValue } from '@/db/write/updateItemPropertyValue'
15
15
  import { getSchemaUidForSchemaDefinition } from '@/stores/eas'
16
16
  import { getSchemaUidForModel } from '@/db/read/getSchemaUidForModel'
17
- import { BaseFileManager } from '@/helpers/BaseFileManager'
17
+ import { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'
18
18
 
19
19
  const readFileAsDataUrl = async (file: File): Promise<string> => {
20
20
  return new Promise((resolve) => {