@seedprotocol/sdk 0.1.105 → 0.1.106
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.
- package/dist/bin.js +1 -1
- package/dist/{constants-rmQ8zg8_.js → constants-qIJt7998.js} +2 -1
- package/dist/{constants-rmQ8zg8_.js.map → constants-qIJt7998.js.map} +1 -1
- package/dist/{index--nvTinP_.js → index-CvfKxmFw.js} +1453 -1252
- package/dist/index-CvfKxmFw.js.map +1 -0
- package/dist/{index-D5tYjtxh.js → index-DyEsLJAK.js} +4 -4
- package/dist/{index-D5tYjtxh.js.map → index-DyEsLJAK.js.map} +1 -1
- package/dist/main.js +3 -3
- package/dist/{seed.schema.config-wQXee2fb.js → seed.schema.config-C37yDUmq.js} +4 -4
- package/dist/{seed.schema.config-wQXee2fb.js.map → seed.schema.config-C37yDUmq.js.map} +1 -1
- package/dist/src/eas.ts +40 -0
- package/dist/src/getPublishPayload.ts +290 -78
- package/dist/src/initialize.ts +6 -11
- package/dist/src/saveImageSrc.ts +21 -1
- package/dist/src/syncDbWithEas.ts +13 -5
- package/dist/types/src/browser/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/types/src/browser/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/types/src/browser/item/Item.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/initialize.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
- package/dist/types/src/browser/property/index.d.ts +0 -1
- package/dist/types/src/browser/property/index.d.ts.map +1 -1
- package/dist/types/src/browser/react/services.d.ts +1 -1
- package/dist/types/src/browser/services/global/actors/initialize.d.ts +1 -1
- package/dist/types/src/browser/services/global/actors/initialize.d.ts.map +1 -1
- package/dist/types/src/browser/services/global/globalMachine.d.ts +613 -44
- package/dist/types/src/browser/services/global/globalMachine.d.ts.map +1 -1
- package/dist/types/src/browser/stores/eas.d.ts +7 -0
- package/dist/types/src/browser/stores/eas.d.ts.map +1 -0
- package/dist/types/src/shared/helpers/constants.d.ts.map +1 -1
- package/dist/types/src/shared/helpers/index.d.ts +1 -0
- package/dist/types/src/shared/helpers/index.d.ts.map +1 -1
- package/dist/types/src/types/item.d.ts +1 -0
- package/dist/types/src/types/item.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/index--nvTinP_.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { g as GET_ALL_PROPERTIES_FOR_ALL_VERSIONS, f as GET_PROPERTIES, G as GET_SCHEMAS, a as GET_SCHEMA_BY_NAME, b as GET_SEEDS, c as GET_SEED_IDS, d as GET_STORAGE_TRANSACTION_ID, e as GET_VERSIONS, I as Item, h as itemMachineAll, i as itemMachineSingle } from './index
|
|
2
|
-
import './constants-
|
|
1
|
+
export { g as GET_ALL_PROPERTIES_FOR_ALL_VERSIONS, f as GET_PROPERTIES, G as GET_SCHEMAS, a as GET_SCHEMA_BY_NAME, b as GET_SEEDS, c as GET_SEED_IDS, d as GET_STORAGE_TRANSACTION_ID, e as GET_VERSIONS, I as Item, h as itemMachineAll, i as itemMachineSingle } from './index-CvfKxmFw.js';
|
|
2
|
+
import './constants-qIJt7998.js';
|
|
3
3
|
import '@ethereum-attestation-service/eas-sdk';
|
|
4
4
|
import 'thirdweb';
|
|
5
5
|
import 'path';
|
|
@@ -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 'immer';
|
|
26
26
|
import 'pluralize';
|
|
27
27
|
import '@statelyai/inspect';
|
|
@@ -29,4 +29,4 @@ import 'rxjs';
|
|
|
29
29
|
import 'drizzle-orm/sqlite-proxy';
|
|
30
30
|
import '@zenfs/dom';
|
|
31
31
|
import 'arweave';
|
|
32
|
-
//# sourceMappingURL=index-
|
|
32
|
+
//# sourceMappingURL=index-DyEsLJAK.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-DyEsLJAK.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
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
|
|
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-CvfKxmFw.js';
|
|
2
2
|
import 'immer';
|
|
3
3
|
import 'reflect-metadata';
|
|
4
|
-
import './constants-
|
|
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-
|
|
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
|
|
3
|
+
import { T as Text, M as Model } from './index-CvfKxmFw.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-
|
|
79
|
+
//# sourceMappingURL=seed.schema.config-C37yDUmq.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.schema.config-
|
|
1
|
+
{"version":3,"file":"seed.schema.config-C37yDUmq.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;;;;;"}
|
package/dist/src/eas.ts
ADDED
|
@@ -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
|
+
}
|
|
@@ -13,109 +13,126 @@ import {
|
|
|
13
13
|
import { getSchemaForItemProperty } from '@/browser/helpers/getSchemaForItemProperty'
|
|
14
14
|
import { toSnakeCase } from '@/shared/helpers'
|
|
15
15
|
import pluralize from 'pluralize'
|
|
16
|
+
import { getSchemaUidForModel } from '@/browser/db/read/getSchemaUidForModel'
|
|
17
|
+
import { getSchemaUidForSchemaDefinition } from '@/browser/stores/eas'
|
|
18
|
+
import { ItemProperty } from '@/browser/property/ItemProperty'
|
|
19
|
+
import { getCorrectId } from '@/browser/helpers'
|
|
20
|
+
import { Item } from '@/browser/item/Item'
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const getVersionUid = (item: Item<any>) => {
|
|
23
|
+
let versionUid
|
|
24
|
+
|
|
25
|
+
if (
|
|
26
|
+
item.latestVersionUid &&
|
|
27
|
+
item.latestVersionUid !== 'NULL' &&
|
|
28
|
+
item.latestVersionUid !== 'undefined'
|
|
29
|
+
) {
|
|
30
|
+
versionUid = item.latestVersionUid
|
|
31
|
+
}
|
|
32
|
+
return versionUid || ZERO_ADDRESS
|
|
26
33
|
}
|
|
27
34
|
|
|
28
|
-
|
|
35
|
+
const getPropertyData = async (itemProperty: ItemProperty<any>) => {
|
|
36
|
+
const easDataType =
|
|
37
|
+
INTERNAL_DATA_TYPES[itemProperty.propertyDef!.dataType].eas
|
|
29
38
|
|
|
30
|
-
|
|
31
|
-
seedLocalId: string,
|
|
32
|
-
): Promise<MultiPublishPayload> => {
|
|
33
|
-
const item = await getItem({ seedLocalId })
|
|
39
|
+
let schemaUid = itemProperty.schemaUid
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
throw new Error('Item not found')
|
|
37
|
-
}
|
|
41
|
+
const propertyNameForSchema = toSnakeCase(itemProperty.propertyName)
|
|
38
42
|
|
|
39
|
-
const
|
|
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 = []
|
|
43
|
+
const schemaDef = `${easDataType} ${propertyNameForSchema}`
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
if (!schemaUid) {
|
|
46
|
+
schemaUid = getSchemaUidForSchemaDefinition(schemaDef)
|
|
47
|
+
if (!schemaUid) {
|
|
48
|
+
const schema = await getSchemaForItemProperty({
|
|
49
|
+
propertyName: 'version',
|
|
50
|
+
easDataType: 'bytes32',
|
|
51
|
+
})
|
|
52
|
+
if (schema) {
|
|
53
|
+
schemaUid = schema.id
|
|
54
|
+
}
|
|
50
55
|
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
schemaUid,
|
|
60
|
+
easDataType,
|
|
61
|
+
schemaDef,
|
|
62
|
+
propertyNameForSchema,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
51
65
|
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
const getSegmentedItemProperties = (item: Item<any>) => {
|
|
67
|
+
const itemBasicProperties = []
|
|
68
|
+
const itemRelationProperties = []
|
|
69
|
+
const itemListProperties = []
|
|
70
|
+
const itemStorageProperties = []
|
|
54
71
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
72
|
+
for (const itemProperty of Object.values(item.properties)) {
|
|
73
|
+
if (!itemProperty.propertyDef) {
|
|
74
|
+
continue
|
|
75
|
+
}
|
|
59
76
|
|
|
60
77
|
if (itemProperty.propertyDef.dataType === 'Relation') {
|
|
61
|
-
|
|
78
|
+
itemRelationProperties.push(itemProperty)
|
|
79
|
+
continue
|
|
62
80
|
}
|
|
63
81
|
|
|
64
|
-
if (
|
|
65
|
-
itemProperty
|
|
66
|
-
|
|
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
|
-
}
|
|
82
|
+
if (itemProperty.propertyDef.dataType === 'List') {
|
|
83
|
+
itemListProperties.push(itemProperty)
|
|
84
|
+
continue
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
if (
|
|
83
88
|
itemProperty.propertyDef.storageType &&
|
|
84
89
|
itemProperty.propertyDef.storageType === 'ItemStorage'
|
|
85
90
|
) {
|
|
91
|
+
itemStorageProperties.push(itemProperty)
|
|
86
92
|
continue
|
|
87
93
|
}
|
|
88
94
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
propertyName: propertyNameForSchema,
|
|
92
|
-
easDataType,
|
|
93
|
-
})
|
|
95
|
+
itemBasicProperties.push(itemProperty)
|
|
96
|
+
}
|
|
94
97
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
return {
|
|
99
|
+
itemBasicProperties,
|
|
100
|
+
itemRelationProperties,
|
|
101
|
+
itemListProperties,
|
|
102
|
+
itemStorageProperties,
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const processBasicProperties = async (
|
|
107
|
+
itemBasicProperties: ItemProperty<any>[],
|
|
108
|
+
itemPublishData: PublishPayload,
|
|
109
|
+
): Promise<PublishPayload> => {
|
|
110
|
+
for (const basicProperty of itemBasicProperties) {
|
|
111
|
+
const value = basicProperty.getService().getSnapshot().context.propertyValue
|
|
112
|
+
|
|
113
|
+
if (!value || basicProperty.uid) {
|
|
114
|
+
continue
|
|
99
115
|
}
|
|
100
116
|
|
|
101
|
-
schemaUid =
|
|
117
|
+
const { schemaUid, easDataType, schemaDef } =
|
|
118
|
+
await getPropertyData(basicProperty)
|
|
119
|
+
|
|
120
|
+
const propertyNameForSchema = toSnakeCase(basicProperty.propertyName)
|
|
102
121
|
|
|
103
122
|
const data = [
|
|
104
123
|
{
|
|
105
|
-
name:
|
|
124
|
+
name: propertyNameForSchema,
|
|
106
125
|
type: easDataType,
|
|
107
|
-
value
|
|
126
|
+
value,
|
|
108
127
|
},
|
|
109
128
|
]
|
|
110
129
|
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
const dataEncoder = new SchemaEncoder(easSchemaDefinition)
|
|
130
|
+
const dataEncoder = new SchemaEncoder(schemaDef)
|
|
114
131
|
|
|
115
132
|
const encodedData = dataEncoder.encodeData(data)
|
|
116
133
|
|
|
117
|
-
listOfAttestations.push({
|
|
118
|
-
schema: schemaUid
|
|
134
|
+
itemPublishData.listOfAttestations.push({
|
|
135
|
+
schema: schemaUid!,
|
|
119
136
|
data: [
|
|
120
137
|
{
|
|
121
138
|
...defaultAttestationData,
|
|
@@ -125,16 +142,211 @@ export const getPublishPayload = async (
|
|
|
125
142
|
})
|
|
126
143
|
}
|
|
127
144
|
|
|
128
|
-
return
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
145
|
+
return itemPublishData
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const processRelationProperty = async (
|
|
149
|
+
relationProperty: ItemProperty<any>,
|
|
150
|
+
multiPublishPayload: MultiPublishPayload,
|
|
151
|
+
): Promise<MultiPublishPayload> => {
|
|
152
|
+
const value = relationProperty.getService().getSnapshot()
|
|
153
|
+
.context.propertyValue
|
|
154
|
+
if (!value || relationProperty.uid) {
|
|
155
|
+
return multiPublishPayload
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const { localId: seedLocalId, uid: seedUid } = getCorrectId(value)
|
|
159
|
+
|
|
160
|
+
const relatedItem = await getItem({
|
|
161
|
+
seedLocalId,
|
|
162
|
+
seedUid,
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
if (!relatedItem) {
|
|
166
|
+
throw new Error(
|
|
167
|
+
`No related item found for relation property: ${relationProperty.propertyName}`,
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const versionUid = getVersionUid(relatedItem)
|
|
172
|
+
|
|
173
|
+
const seedSchemaUid = await getSchemaUidForModel(
|
|
174
|
+
relationProperty.propertyDef!.ref as string,
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
let publishPayload: PublishPayload = {
|
|
178
|
+
localId: relationProperty.localId,
|
|
179
|
+
seedIsRevocable: true,
|
|
180
|
+
versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
|
|
181
|
+
seedUid: seedUid || ZERO_ADDRESS,
|
|
182
|
+
seedSchemaUid,
|
|
183
|
+
versionUid,
|
|
184
|
+
listOfAttestations: [],
|
|
185
|
+
propertiesToUpdate: [],
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const { itemBasicProperties } = getSegmentedItemProperties(relatedItem)
|
|
189
|
+
|
|
190
|
+
publishPayload = await processBasicProperties(
|
|
191
|
+
itemBasicProperties,
|
|
192
|
+
publishPayload,
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
multiPublishPayload.push(publishPayload)
|
|
196
|
+
|
|
197
|
+
return multiPublishPayload
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const processListProperty = async (
|
|
201
|
+
listProperty: ItemProperty<any>,
|
|
202
|
+
multiPublishPayload: MultiPublishPayload,
|
|
203
|
+
): Promise<MultiPublishPayload> => {
|
|
204
|
+
let value = listProperty.getService().getSnapshot().context.propertyValue
|
|
205
|
+
if (!value || listProperty.uid) {
|
|
206
|
+
return multiPublishPayload
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const singularPropertyName = pluralize.singular(listProperty.propertyName)
|
|
210
|
+
const propertyNameForSchema = `${singularPropertyName}${listProperty.propertyDef!.ref}Ids`
|
|
211
|
+
if (typeof value === 'string' && value.length === 66) {
|
|
212
|
+
value = [value]
|
|
213
|
+
}
|
|
214
|
+
if (typeof value === 'string' && value.length > 66) {
|
|
215
|
+
try {
|
|
216
|
+
value = JSON.parse(value)
|
|
217
|
+
} catch (error) {
|
|
218
|
+
value = value.split(',')
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
for (const seedId of value) {
|
|
223
|
+
const { localId: seedLocalId, uid: seedUid } = getCorrectId(seedId)
|
|
224
|
+
|
|
225
|
+
const relatedItem = await getItem({
|
|
226
|
+
seedLocalId,
|
|
227
|
+
seedUid,
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
if (!relatedItem) {
|
|
231
|
+
throw new Error(
|
|
232
|
+
`No related item found for list property: ${listProperty.propertyName}`,
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (relatedItem.seedUid) {
|
|
237
|
+
return multiPublishPayload
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const versionUid = getVersionUid(relatedItem)
|
|
241
|
+
|
|
242
|
+
const seedSchemaUid = await getSchemaUidForModel(
|
|
243
|
+
listProperty.propertyDef!.ref as string,
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
let publishPayload: PublishPayload = {
|
|
247
|
+
localId: relatedItem.seedLocalId,
|
|
248
|
+
seedIsRevocable: true,
|
|
249
|
+
versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
|
|
133
250
|
seedUid: seedUid || ZERO_ADDRESS,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
listOfAttestations,
|
|
137
|
-
propertiesToUpdate
|
|
138
|
-
|
|
139
|
-
|
|
251
|
+
seedSchemaUid,
|
|
252
|
+
versionUid,
|
|
253
|
+
listOfAttestations: [],
|
|
254
|
+
propertiesToUpdate: [
|
|
255
|
+
{
|
|
256
|
+
publishLocalId: listProperty.localId,
|
|
257
|
+
propertySchemaUid: listProperty.schemaUid,
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const { itemBasicProperties } = getSegmentedItemProperties(relatedItem)
|
|
263
|
+
|
|
264
|
+
publishPayload = await processBasicProperties(
|
|
265
|
+
itemBasicProperties,
|
|
266
|
+
publishPayload,
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
multiPublishPayload.push(publishPayload)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return multiPublishPayload
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
type PublishPayload = {
|
|
276
|
+
localId: string
|
|
277
|
+
seedIsRevocable: boolean
|
|
278
|
+
seedSchemaUid: string
|
|
279
|
+
seedUid: string
|
|
280
|
+
versionSchemaUid: string
|
|
281
|
+
versionUid: string
|
|
282
|
+
listOfAttestations: AttestationRequest[]
|
|
283
|
+
propertiesToUpdate: any[]
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
type MultiPublishPayload = PublishPayload[]
|
|
287
|
+
|
|
288
|
+
export const getPublishPayload = async (
|
|
289
|
+
seedLocalId: string,
|
|
290
|
+
): Promise<MultiPublishPayload> => {
|
|
291
|
+
const item = await getItem({ seedLocalId })
|
|
292
|
+
|
|
293
|
+
if (!item) {
|
|
294
|
+
throw new Error('Item not found')
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// if (item.modelName === 'Post') {
|
|
298
|
+
// item.authors = [
|
|
299
|
+
// 'Sr0bIx9Fwj',
|
|
300
|
+
// '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',
|
|
301
|
+
// ]
|
|
302
|
+
// }
|
|
303
|
+
|
|
304
|
+
let multiPublishPayload: MultiPublishPayload = []
|
|
305
|
+
|
|
306
|
+
// Each PublishPayload is generated from a Seed that needs publishing
|
|
307
|
+
|
|
308
|
+
// First we need to determine all Seeds to publish
|
|
309
|
+
|
|
310
|
+
// That means the Seed of the Item, plus any Seeds pointed to by Relations
|
|
311
|
+
|
|
312
|
+
let itemPublishData: PublishPayload = {
|
|
313
|
+
localId: item.seedLocalId,
|
|
314
|
+
seedUid: item.seedUid || ZERO_ADDRESS,
|
|
315
|
+
seedIsRevocable: true,
|
|
316
|
+
seedSchemaUid: item.schemaUid,
|
|
317
|
+
versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
|
|
318
|
+
versionUid: item.latestVersionUid || ZERO_ADDRESS,
|
|
319
|
+
listOfAttestations: [],
|
|
320
|
+
propertiesToUpdate: [],
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const {
|
|
324
|
+
itemBasicProperties,
|
|
325
|
+
itemRelationProperties,
|
|
326
|
+
itemListProperties,
|
|
327
|
+
itemStorageProperties,
|
|
328
|
+
} = getSegmentedItemProperties(item)
|
|
329
|
+
|
|
330
|
+
itemPublishData = await processBasicProperties(
|
|
331
|
+
itemBasicProperties,
|
|
332
|
+
itemPublishData,
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
multiPublishPayload.push(itemPublishData)
|
|
336
|
+
|
|
337
|
+
for (const relationProperty of itemRelationProperties) {
|
|
338
|
+
multiPublishPayload = await processRelationProperty(
|
|
339
|
+
relationProperty,
|
|
340
|
+
multiPublishPayload,
|
|
341
|
+
)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
for (const listProperty of itemListProperties) {
|
|
345
|
+
multiPublishPayload = await processListProperty(
|
|
346
|
+
listProperty,
|
|
347
|
+
multiPublishPayload,
|
|
348
|
+
)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return multiPublishPayload
|
|
140
352
|
}
|
package/dist/src/initialize.ts
CHANGED
|
@@ -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
|
-
|
|
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 })
|
package/dist/src/saveImageSrc.ts
CHANGED
|
@@ -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
|
|