@seedprotocol/sdk 0.1.105 → 0.1.107

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 (36) hide show
  1. package/dist/bin.js +1 -1
  2. package/dist/{constants-rmQ8zg8_.js → constants-qIJt7998.js} +2 -1
  3. package/dist/{constants-rmQ8zg8_.js.map → constants-qIJt7998.js.map} +1 -1
  4. package/dist/{index-D5tYjtxh.js → index-BmzLHFCL.js} +4 -4
  5. package/dist/{index-D5tYjtxh.js.map → index-BmzLHFCL.js.map} +1 -1
  6. package/dist/{index--nvTinP_.js → index-Dg23uBJg.js} +1453 -1252
  7. package/dist/index-Dg23uBJg.js.map +1 -0
  8. package/dist/main.js +3 -3
  9. package/dist/{seed.schema.config-wQXee2fb.js → seed.schema.config-C1zm5m77.js} +4 -4
  10. package/dist/{seed.schema.config-wQXee2fb.js.map → seed.schema.config-C1zm5m77.js.map} +1 -1
  11. package/dist/src/eas.ts +40 -0
  12. package/dist/src/getPublishPayload.ts +291 -78
  13. package/dist/src/initialize.ts +6 -11
  14. package/dist/src/saveImageSrc.ts +21 -1
  15. package/dist/src/syncDbWithEas.ts +13 -5
  16. package/dist/types/src/browser/db/read/getPublishPayload.d.ts.map +1 -1
  17. package/dist/types/src/browser/events/item/syncDbWithEas.d.ts.map +1 -1
  18. package/dist/types/src/browser/item/Item.d.ts.map +1 -1
  19. package/dist/types/src/browser/property/actors/initialize.d.ts.map +1 -1
  20. package/dist/types/src/browser/property/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
  21. package/dist/types/src/browser/property/index.d.ts +0 -1
  22. package/dist/types/src/browser/property/index.d.ts.map +1 -1
  23. package/dist/types/src/browser/react/services.d.ts +1 -1
  24. package/dist/types/src/browser/services/global/actors/initialize.d.ts +1 -1
  25. package/dist/types/src/browser/services/global/actors/initialize.d.ts.map +1 -1
  26. package/dist/types/src/browser/services/global/globalMachine.d.ts +613 -44
  27. package/dist/types/src/browser/services/global/globalMachine.d.ts.map +1 -1
  28. package/dist/types/src/browser/stores/eas.d.ts +7 -0
  29. package/dist/types/src/browser/stores/eas.d.ts.map +1 -0
  30. package/dist/types/src/shared/helpers/constants.d.ts.map +1 -1
  31. package/dist/types/src/shared/helpers/index.d.ts +1 -0
  32. package/dist/types/src/shared/helpers/index.d.ts.map +1 -1
  33. package/dist/types/src/types/item.d.ts +1 -0
  34. package/dist/types/src/types/item.d.ts.map +1 -1
  35. package/package.json +2 -2
  36. package/dist/index--nvTinP_.js.map +0 -1
package/dist/main.js CHANGED
@@ -1,7 +1,7 @@
1
- export { j as ImageSrc, I as Item, k as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, t as client, v as getCorrectId, s as getGlobalService, n as useCreateItem, p as useDeleteItem, q as useGlobalServiceStatus, l as useItem, m as useItemProperties, o as useItemProperty, u as useItems, r as useServices, w as withSeed } from './index--nvTinP_.js';
1
+ export { j as ImageSrc, I as Item, k as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, t as client, v as getCorrectId, s as getGlobalService, n as useCreateItem, p as useDeleteItem, q as useGlobalServiceStatus, l as useItem, m as useItemProperties, o as useItemProperty, u as useItems, r as useServices, w as withSeed } from './index-Dg23uBJg.js';
2
2
  import 'immer';
3
3
  import 'reflect-metadata';
4
- import './constants-rmQ8zg8_.js';
4
+ import './constants-qIJt7998.js';
5
5
  import 'xstate';
6
6
  import 'arweave';
7
7
  import 'drizzle-orm';
@@ -12,7 +12,6 @@ import 'dayjs';
12
12
  import 'nanoid';
13
13
  import 'nanoid-dictionary';
14
14
  import 'debug';
15
- import 'lodash-es';
16
15
  import 'drizzle-orm/sqlite-core';
17
16
  import 'react';
18
17
  import '@tanstack/react-query';
@@ -22,6 +21,7 @@ import '@tanstack/react-query-persist-client';
22
21
  import 'use-immer';
23
22
  import '@xstate/react';
24
23
  import 'eventemitter3';
24
+ import 'lodash-es';
25
25
  import 'pluralize';
26
26
  import '@statelyai/inspect';
27
27
  import 'rxjs';
@@ -1,6 +1,6 @@
1
- import { _ as __decorate, a as __metadata } from './constants-rmQ8zg8_.js';
1
+ import { _ as __decorate, a as __metadata } from './constants-qIJt7998.js';
2
2
  import 'drizzle-orm';
3
- import { T as Text, M as Model } from './index--nvTinP_.js';
3
+ import { T as Text, M as Model } from './index-Dg23uBJg.js';
4
4
  import 'react';
5
5
  import 'reflect-metadata';
6
6
  import 'xstate';
@@ -15,7 +15,6 @@ import 'dayjs';
15
15
  import 'nanoid';
16
16
  import 'nanoid-dictionary';
17
17
  import 'debug';
18
- import 'lodash-es';
19
18
  import 'drizzle-orm/sqlite-core';
20
19
  import '@tanstack/react-query';
21
20
  import 'graphql-request';
@@ -24,6 +23,7 @@ import '@tanstack/react-query-persist-client';
24
23
  import 'use-immer';
25
24
  import '@xstate/react';
26
25
  import 'eventemitter3';
26
+ import 'lodash-es';
27
27
  import 'immer';
28
28
  import 'pluralize';
29
29
  import '@statelyai/inspect';
@@ -76,4 +76,4 @@ const models = {
76
76
  };
77
77
 
78
78
  export { models };
79
- //# sourceMappingURL=seed.schema.config-wQXee2fb.js.map
79
+ //# sourceMappingURL=seed.schema.config-C1zm5m77.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"seed.schema.config-wQXee2fb.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-C1zm5m77.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;;;;;"}
@@ -0,0 +1,40 @@
1
+ import { toSnakeCase } from '@/shared/helpers'
2
+ import { getSchemaForItemProperty } from '@/browser/helpers/getSchemaForItemProperty'
3
+
4
+ const schemaUidForSchemaDefinition = new Map<string, string>()
5
+
6
+ export const setSchemaUidForSchemaDefinition = ({ text, schemaUid }) => {
7
+ const propertySnakeCase = toSnakeCase(text)
8
+ schemaUidForSchemaDefinition.set(propertySnakeCase, schemaUid)
9
+ }
10
+
11
+ export const getSchemaUidForSchemaDefinition = (schemaText: string) => {
12
+ const textSnakeCase = toSnakeCase(schemaText)
13
+ if (!schemaUidForSchemaDefinition.has(textSnakeCase)) {
14
+ return
15
+ }
16
+ return schemaUidForSchemaDefinition.get(textSnakeCase)
17
+ }
18
+
19
+ export const fetchSchemaUids = async () => {
20
+ const versionSchemaUid = await getSchemaForItemProperty({
21
+ propertyName: 'version',
22
+ easDataType: 'bytes32',
23
+ })
24
+ if (versionSchemaUid) {
25
+ setSchemaUidForSchemaDefinition({
26
+ text: 'version',
27
+ schemaUid: versionSchemaUid,
28
+ })
29
+ }
30
+ const imageSchemaUid = await getSchemaForItemProperty({
31
+ propertyName: 'image',
32
+ easDataType: 'bytes32',
33
+ })
34
+ if (imageSchemaUid) {
35
+ setSchemaUidForSchemaDefinition({
36
+ text: 'image',
37
+ schemaUid: imageSchemaUid,
38
+ })
39
+ }
40
+ }
@@ -8,114 +8,132 @@ import {
8
8
  AttestationRequest,
9
9
  SchemaEncoder,
10
10
  ZERO_ADDRESS,
11
+ ZERO_BYTES32,
11
12
  } from '@ethereum-attestation-service/eas-sdk'
12
13
 
13
14
  import { getSchemaForItemProperty } from '@/browser/helpers/getSchemaForItemProperty'
14
15
  import { toSnakeCase } from '@/shared/helpers'
15
16
  import pluralize from 'pluralize'
17
+ import { getSchemaUidForModel } from '@/browser/db/read/getSchemaUidForModel'
18
+ import { getSchemaUidForSchemaDefinition } from '@/browser/stores/eas'
19
+ import { ItemProperty } from '@/browser/property/ItemProperty'
20
+ import { getCorrectId } from '@/browser/helpers'
21
+ import { Item } from '@/browser/item/Item'
16
22
 
17
- type PublishPayload = {
18
- localId: string
19
- seedIsRevocable: boolean
20
- seedSchemaUid: string
21
- seedUid: string
22
- versionSchemaUid: string
23
- versionUid: string
24
- listOfAttestations: AttestationRequest[]
25
- propertiesToUpdate: any[]
23
+ const getVersionUid = (item: Item<any>) => {
24
+ let versionUid
25
+
26
+ if (
27
+ item.latestVersionUid &&
28
+ item.latestVersionUid !== 'NULL' &&
29
+ item.latestVersionUid !== 'undefined'
30
+ ) {
31
+ versionUid = item.latestVersionUid
32
+ }
33
+ return versionUid || ZERO_ADDRESS
26
34
  }
27
35
 
28
- type MultiPublishPayload = PublishPayload[]
36
+ const getPropertyData = async (itemProperty: ItemProperty<any>) => {
37
+ const easDataType =
38
+ INTERNAL_DATA_TYPES[itemProperty.propertyDef!.dataType].eas
29
39
 
30
- export const getPublishPayload = async (
31
- seedLocalId: string,
32
- ): Promise<MultiPublishPayload> => {
33
- const item = await getItem({ seedLocalId })
40
+ let schemaUid = itemProperty.schemaUid
34
41
 
35
- if (!item) {
36
- throw new Error('Item not found')
37
- }
42
+ const propertyNameForSchema = toSnakeCase(itemProperty.propertyName)
38
43
 
39
- const localId = item.seedLocalId
40
- const seedIsRevocable = true
41
- const seedSchemaUid = item.schemaUid
42
- const seedUid = item.seedUid
43
- const versionSchemaUid = VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA
44
- const listOfAttestations = []
45
- const propertiesToUpdate = []
44
+ const schemaDef = `${easDataType} ${propertyNameForSchema}`
46
45
 
47
- for (const [propertyName, itemProperty] of Object.entries(item.properties)) {
48
- if (!itemProperty.value || !itemProperty.propertyDef) {
49
- continue
46
+ if (!schemaUid) {
47
+ schemaUid = getSchemaUidForSchemaDefinition(schemaDef)
48
+ if (!schemaUid) {
49
+ const schema = await getSchemaForItemProperty({
50
+ propertyName: 'version',
51
+ easDataType: 'bytes32',
52
+ })
53
+ if (schema) {
54
+ schemaUid = schema.id
55
+ }
50
56
  }
57
+ }
58
+
59
+ return {
60
+ schemaUid,
61
+ easDataType,
62
+ schemaDef,
63
+ propertyNameForSchema,
64
+ }
65
+ }
51
66
 
52
- const easDataType =
53
- INTERNAL_DATA_TYPES[itemProperty.propertyDef.dataType].eas
67
+ const getSegmentedItemProperties = (item: Item<any>) => {
68
+ const itemBasicProperties = []
69
+ const itemRelationProperties = []
70
+ const itemListProperties = []
71
+ const itemStorageProperties = []
54
72
 
55
- let schemaUid = itemProperty.schemaUid
56
- let propertyNameForSchema = propertyName
57
- let propertyValue = itemProperty.getService().getSnapshot()
58
- .context.propertyValue
73
+ for (const itemProperty of Object.values(item.properties)) {
74
+ if (!itemProperty.propertyDef) {
75
+ continue
76
+ }
59
77
 
60
78
  if (itemProperty.propertyDef.dataType === 'Relation') {
61
- propertyNameForSchema = `${propertyName}Id`
79
+ itemRelationProperties.push(itemProperty)
80
+ continue
62
81
  }
63
82
 
64
- if (
65
- itemProperty.propertyDef.dataType === 'List' &&
66
- itemProperty.propertyDef.ref
67
- ) {
68
- const singularPropertyName = pluralize.singular(propertyName)
69
- propertyNameForSchema = `${singularPropertyName}${itemProperty.propertyDef.ref}Ids`
70
- if (typeof propertyValue === 'string' && propertyValue.length === 66) {
71
- propertyValue = [propertyValue]
72
- }
73
- if (typeof propertyValue === 'string' && propertyValue.length > 66) {
74
- try {
75
- propertyValue = JSON.parse(propertyValue)
76
- } catch (error) {
77
- console.log('No-op due to error: ', error)
78
- }
79
- }
83
+ if (itemProperty.propertyDef.dataType === 'List') {
84
+ itemListProperties.push(itemProperty)
85
+ continue
80
86
  }
81
87
 
82
88
  if (
83
89
  itemProperty.propertyDef.storageType &&
84
90
  itemProperty.propertyDef.storageType === 'ItemStorage'
85
91
  ) {
92
+ itemStorageProperties.push(itemProperty)
86
93
  continue
87
94
  }
88
95
 
89
- const foundPropertySchema = await getSchemaForItemProperty({
90
- schemaUid,
91
- propertyName: propertyNameForSchema,
92
- easDataType,
93
- })
96
+ itemBasicProperties.push(itemProperty)
97
+ }
94
98
 
95
- if (!foundPropertySchema) {
96
- throw new Error(
97
- `No schema found for property ${itemProperty.propertyName} ${itemProperty.localId}`,
98
- )
99
+ return {
100
+ itemBasicProperties,
101
+ itemRelationProperties,
102
+ itemListProperties,
103
+ itemStorageProperties,
104
+ }
105
+ }
106
+
107
+ const processBasicProperties = async (
108
+ itemBasicProperties: ItemProperty<any>[],
109
+ itemPublishData: PublishPayload,
110
+ ): Promise<PublishPayload> => {
111
+ for (const basicProperty of itemBasicProperties) {
112
+ const value = basicProperty.getService().getSnapshot().context.propertyValue
113
+
114
+ if (!value || basicProperty.uid) {
115
+ continue
99
116
  }
100
117
 
101
- schemaUid = foundPropertySchema.id
118
+ const { schemaUid, easDataType, schemaDef } =
119
+ await getPropertyData(basicProperty)
120
+
121
+ const propertyNameForSchema = toSnakeCase(basicProperty.propertyName)
102
122
 
103
123
  const data = [
104
124
  {
105
- name: toSnakeCase(propertyNameForSchema),
125
+ name: propertyNameForSchema,
106
126
  type: easDataType,
107
- value: propertyValue,
127
+ value,
108
128
  },
109
129
  ]
110
130
 
111
- const easSchemaDefinition = foundPropertySchema.schema
112
-
113
- const dataEncoder = new SchemaEncoder(easSchemaDefinition)
131
+ const dataEncoder = new SchemaEncoder(schemaDef)
114
132
 
115
133
  const encodedData = dataEncoder.encodeData(data)
116
134
 
117
- listOfAttestations.push({
118
- schema: schemaUid,
135
+ itemPublishData.listOfAttestations.push({
136
+ schema: schemaUid!,
119
137
  data: [
120
138
  {
121
139
  ...defaultAttestationData,
@@ -125,16 +143,211 @@ export const getPublishPayload = async (
125
143
  })
126
144
  }
127
145
 
128
- return [
129
- {
130
- localId,
131
- seedIsRevocable,
132
- seedSchemaUid,
146
+ return itemPublishData
147
+ }
148
+
149
+ const processRelationProperty = async (
150
+ relationProperty: ItemProperty<any>,
151
+ multiPublishPayload: MultiPublishPayload,
152
+ ): Promise<MultiPublishPayload> => {
153
+ const value = relationProperty.getService().getSnapshot()
154
+ .context.propertyValue
155
+ if (!value || relationProperty.uid) {
156
+ return multiPublishPayload
157
+ }
158
+
159
+ const { localId: seedLocalId, uid: seedUid } = getCorrectId(value)
160
+
161
+ const relatedItem = await getItem({
162
+ seedLocalId,
163
+ seedUid,
164
+ })
165
+
166
+ if (!relatedItem) {
167
+ throw new Error(
168
+ `No related item found for relation property: ${relationProperty.propertyName}`,
169
+ )
170
+ }
171
+
172
+ const versionUid = getVersionUid(relatedItem)
173
+
174
+ const seedSchemaUid = await getSchemaUidForModel(
175
+ relationProperty.propertyDef!.ref as string,
176
+ )
177
+
178
+ let publishPayload: PublishPayload = {
179
+ localId: relationProperty.localId,
180
+ seedIsRevocable: true,
181
+ versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
182
+ seedUid: seedUid || ZERO_ADDRESS,
183
+ seedSchemaUid,
184
+ versionUid,
185
+ listOfAttestations: [],
186
+ propertiesToUpdate: [],
187
+ }
188
+
189
+ const { itemBasicProperties } = getSegmentedItemProperties(relatedItem)
190
+
191
+ publishPayload = await processBasicProperties(
192
+ itemBasicProperties,
193
+ publishPayload,
194
+ )
195
+
196
+ multiPublishPayload.push(publishPayload)
197
+
198
+ return multiPublishPayload
199
+ }
200
+
201
+ const processListProperty = async (
202
+ listProperty: ItemProperty<any>,
203
+ multiPublishPayload: MultiPublishPayload,
204
+ ): Promise<MultiPublishPayload> => {
205
+ let value = listProperty.getService().getSnapshot().context.propertyValue
206
+ if (!value || listProperty.uid) {
207
+ return multiPublishPayload
208
+ }
209
+
210
+ const singularPropertyName = pluralize.singular(listProperty.propertyName)
211
+ const propertyNameForSchema = `${singularPropertyName}${listProperty.propertyDef!.ref}Ids`
212
+ if (typeof value === 'string' && value.length === 66) {
213
+ value = [value]
214
+ }
215
+ if (typeof value === 'string' && value.length > 66) {
216
+ try {
217
+ value = JSON.parse(value)
218
+ } catch (error) {
219
+ value = value.split(',')
220
+ }
221
+ }
222
+
223
+ for (const seedId of value) {
224
+ const { localId: seedLocalId, uid: seedUid } = getCorrectId(seedId)
225
+
226
+ const relatedItem = await getItem({
227
+ seedLocalId,
228
+ seedUid,
229
+ })
230
+
231
+ if (!relatedItem) {
232
+ throw new Error(
233
+ `No related item found for list property: ${listProperty.propertyName}`,
234
+ )
235
+ }
236
+
237
+ if (relatedItem.seedUid) {
238
+ return multiPublishPayload
239
+ }
240
+
241
+ const versionUid = getVersionUid(relatedItem)
242
+
243
+ const seedSchemaUid = await getSchemaUidForModel(
244
+ listProperty.propertyDef!.ref as string,
245
+ )
246
+
247
+ let publishPayload: PublishPayload = {
248
+ localId: relatedItem.seedLocalId,
249
+ seedIsRevocable: true,
250
+ versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
133
251
  seedUid: seedUid || ZERO_ADDRESS,
134
- versionUid: item.latestVersionUid || ZERO_ADDRESS,
135
- versionSchemaUid,
136
- listOfAttestations,
137
- propertiesToUpdate,
138
- },
139
- ]
252
+ seedSchemaUid,
253
+ versionUid,
254
+ listOfAttestations: [],
255
+ propertiesToUpdate: [
256
+ {
257
+ publishLocalId: listProperty.localId,
258
+ propertySchemaUid: listProperty.schemaUid,
259
+ },
260
+ ],
261
+ }
262
+
263
+ const { itemBasicProperties } = getSegmentedItemProperties(relatedItem)
264
+
265
+ publishPayload = await processBasicProperties(
266
+ itemBasicProperties,
267
+ publishPayload,
268
+ )
269
+
270
+ multiPublishPayload.push(publishPayload)
271
+ }
272
+
273
+ return multiPublishPayload
274
+ }
275
+
276
+ type PublishPayload = {
277
+ localId: string
278
+ seedIsRevocable: boolean
279
+ seedSchemaUid: string
280
+ seedUid: string
281
+ versionSchemaUid: string
282
+ versionUid: string
283
+ listOfAttestations: AttestationRequest[]
284
+ propertiesToUpdate: any[]
285
+ }
286
+
287
+ type MultiPublishPayload = PublishPayload[]
288
+
289
+ export const getPublishPayload = async (
290
+ seedLocalId: string,
291
+ ): Promise<MultiPublishPayload> => {
292
+ const item = await getItem({ seedLocalId })
293
+
294
+ if (!item) {
295
+ throw new Error('Item not found')
296
+ }
297
+
298
+ // if (item.modelName === 'Post') {
299
+ // item.authors = [
300
+ // 'Sr0bIx9Fwj',
301
+ // '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',
302
+ // ]
303
+ // }
304
+
305
+ let multiPublishPayload: MultiPublishPayload = []
306
+
307
+ // Each PublishPayload is generated from a Seed that needs publishing
308
+
309
+ // First we need to determine all Seeds to publish
310
+
311
+ // That means the Seed of the Item, plus any Seeds pointed to by Relations
312
+
313
+ let itemPublishData: PublishPayload = {
314
+ localId: item.seedLocalId,
315
+ seedUid: item.seedUid || ZERO_BYTES32,
316
+ seedIsRevocable: true,
317
+ seedSchemaUid: item.schemaUid,
318
+ versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
319
+ versionUid: item.latestVersionUid || ZERO_BYTES32,
320
+ listOfAttestations: [],
321
+ propertiesToUpdate: [],
322
+ }
323
+
324
+ const {
325
+ itemBasicProperties,
326
+ itemRelationProperties,
327
+ itemListProperties,
328
+ itemStorageProperties,
329
+ } = getSegmentedItemProperties(item)
330
+
331
+ itemPublishData = await processBasicProperties(
332
+ itemBasicProperties,
333
+ itemPublishData,
334
+ )
335
+
336
+ multiPublishPayload.push(itemPublishData)
337
+
338
+ for (const relationProperty of itemRelationProperties) {
339
+ multiPublishPayload = await processRelationProperty(
340
+ relationProperty,
341
+ multiPublishPayload,
342
+ )
343
+ }
344
+
345
+ for (const listProperty of itemListProperties) {
346
+ multiPublishPayload = await processListProperty(
347
+ listProperty,
348
+ multiPublishPayload,
349
+ )
350
+ }
351
+
352
+ return multiPublishPayload
140
353
  }
@@ -10,12 +10,13 @@ import { FromCallbackInput, GlobalMachineContext } from '@/types'
10
10
  import { getAppDb } from '@/browser/db/sqlWasmClient'
11
11
  import { appState } from '@/shared/seedSchema'
12
12
  import { like } from 'drizzle-orm'
13
+ import { fetchSchemaUids } from '@/browser/stores/eas'
13
14
 
14
15
  const logger = debug('app:services:global:actors:initialize')
15
16
 
16
17
  export const initialize = fromCallback<
17
18
  EventObject,
18
- FromCallbackInput<GlobalMachineContext>
19
+ FromCallbackInput<GlobalMachineContext, EventObject>
19
20
  >(({ sendBack, input: { event, context } }) => {
20
21
  const { internalService, models, endpoints } = context
21
22
 
@@ -87,16 +88,7 @@ export const initialize = fromCallback<
87
88
  }
88
89
 
89
90
  const _initEas = async (): Promise<void> => {
90
- // const { easService } = await import('@/browser/eas')
91
- // easService.send({ type: 'init', endpoints, models })
92
- // return new Promise((resolve) => {
93
- // easSubscription = easService.subscribe((snapshot) => {
94
- // if (snapshot.value === 'ready') {
95
- // resolve()
96
- // }
97
- // })
98
- // easService.send({ type: 'init', endpoints, models })
99
- // })
91
+ await fetchSchemaUids()
100
92
  }
101
93
 
102
94
  _initFileSystem().then(() => {
@@ -107,6 +99,9 @@ export const initialize = fromCallback<
107
99
  .then(() => {
108
100
  return _initAllItemsServices()
109
101
  })
102
+ .then(() => {
103
+ return _initEas()
104
+ })
110
105
  .then(() => {
111
106
  logger('[global/actors] Internal initialized')
112
107
  sendBack({ type: GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY })
@@ -12,6 +12,8 @@ import { fs } from '@zenfs/core'
12
12
  import { getContentUrlFromPath } from '@/browser/helpers'
13
13
  import { createMetadata } from '@/browser/db/write/createMetadata'
14
14
  import { updateItemPropertyValue } from '@/browser/db/write/updateItemPropertyValue'
15
+ import { getSchemaUidForSchemaDefinition } from '@/browser/stores/eas'
16
+ import { getSchemaUidForModel } from '@/browser/db/read/getSchemaUidForModel'
15
17
 
16
18
  const readFileAsDataUrl = async (file: File): Promise<string> => {
17
19
  return new Promise((resolve) => {
@@ -61,6 +63,8 @@ const fetchImage = async (url: string) => {
61
63
  return base64
62
64
  }
63
65
 
66
+ let imageSchemaUid: string | undefined
67
+
64
68
  export const saveImageSrc = fromCallback<
65
69
  EventObject,
66
70
  FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>
@@ -75,9 +79,10 @@ export const saveImageSrc = fromCallback<
75
79
  seedUid,
76
80
  versionLocalId,
77
81
  versionUid,
78
- schemaUid,
79
82
  } = context
80
83
 
84
+ let { schemaUid } = context
85
+
81
86
  let newValue: ItemPropertyValueType
82
87
 
83
88
  if (event) {
@@ -101,6 +106,10 @@ export const saveImageSrc = fromCallback<
101
106
  let mimeType
102
107
  let fileName
103
108
 
109
+ if (!imageSchemaUid) {
110
+ imageSchemaUid = await getSchemaUidForModel('Image')
111
+ }
112
+
104
113
  if (typeof newValue === 'string') {
105
114
  newValueType = getDataTypeFromString(newValue)
106
115
  }
@@ -160,6 +169,10 @@ export const saveImageSrc = fromCallback<
160
169
 
161
170
  const refResolvedDisplayValue = await getContentUrlFromPath(filePath)
162
171
 
172
+ if (!schemaUid) {
173
+ schemaUid = getSchemaUidForSchemaDefinition(propertyName)
174
+ }
175
+
163
176
  if (!localId) {
164
177
  await createMetadata(
165
178
  {
@@ -172,6 +185,8 @@ export const saveImageSrc = fromCallback<
172
185
  modelName: itemModelName,
173
186
  schemaUid,
174
187
  refSeedType: 'image',
188
+ refModelUid: imageSchemaUid,
189
+ refSchemaUid: imageSchemaUid,
175
190
  refResolvedDisplayValue,
176
191
  refResolvedValue: fileName,
177
192
  localStorageDir: '/images',
@@ -193,6 +208,8 @@ export const saveImageSrc = fromCallback<
193
208
  refSeedType: 'image',
194
209
  refResolvedDisplayValue,
195
210
  refResolvedValue: fileName,
211
+ refModelUid: imageSchemaUid,
212
+ refSchemaUid: imageSchemaUid,
196
213
  localStorageDir: '/images',
197
214
  easDataType: 'bytes32',
198
215
  })
@@ -202,9 +219,12 @@ export const saveImageSrc = fromCallback<
202
219
  type: 'updateContext',
203
220
  propertyValue: newImageSeedLocalId,
204
221
  refSeedType: 'image',
222
+ refSchemaUid: imageSchemaUid,
205
223
  renderValue: refResolvedDisplayValue,
206
224
  resolvedDisplayValue: refResolvedDisplayValue,
207
225
  resolvedValue: fileName,
226
+ localStorageDir: '/images',
227
+ easDataType: 'bytes32',
208
228
  })
209
229
  }
210
230