@seedprotocol/sdk 0.3.8 → 0.3.10
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/addModel.js +4 -0
- package/dist/addModel.js.map +1 -1
- package/dist/bin.js +182 -111
- package/dist/bin.js.map +1 -1
- package/dist/main.js +13 -1
- package/dist/main.js.map +1 -1
- package/dist/node/db/node.app.db.config.ts +7 -26
- package/dist/scripts/bin.d.ts +4 -4
- package/dist/scripts/bin.d.ts.map +1 -1
- package/dist/seedData.json +23 -0
- package/dist/src/Item/BaseItem.js +3 -3
- package/dist/src/Item/BaseItem.js.map +1 -1
- package/dist/src/ItemProperty/BaseItemProperty.d.ts +4 -1
- package/dist/src/ItemProperty/BaseItemProperty.d.ts.map +1 -1
- package/dist/src/ItemProperty/BaseItemProperty.js +65 -21
- package/dist/src/ItemProperty/BaseItemProperty.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.js +27 -17
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/initialize.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/initialize.js +25 -20
- package/dist/src/ItemProperty/service/actors/initialize.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.js +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.js.map +1 -1
- package/dist/src/ItemProperty/service/propertyMachine.d.ts +11 -11
- package/dist/src/browser/Item/Item.js +0 -1
- package/dist/src/browser/Item/Item.js.map +1 -1
- package/dist/src/browser/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/src/browser/ItemProperty/ItemProperty.js +0 -1
- package/dist/src/browser/ItemProperty/ItemProperty.js.map +1 -1
- package/dist/src/browser/db/Db.d.ts.map +1 -1
- package/dist/src/browser/db/Db.js +35 -10
- package/dist/src/browser/db/Db.js.map +1 -1
- package/dist/src/browser/helpers/FileManager.d.ts +3 -1
- package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
- package/dist/src/browser/helpers/FileManager.js +24 -12
- package/dist/src/browser/helpers/FileManager.js.map +1 -1
- package/dist/src/browser/helpers/eas.d.ts +20 -0
- package/dist/src/browser/helpers/eas.d.ts.map +1 -0
- package/dist/src/browser/helpers/eas.js +89 -0
- package/dist/src/browser/helpers/eas.js.map +1 -0
- package/dist/src/browser/index.d.ts +0 -1
- package/dist/src/browser/index.d.ts.map +1 -1
- package/dist/src/browser/react/SeedImage.d.ts +11 -0
- package/dist/src/browser/react/SeedImage.d.ts.map +1 -0
- package/dist/src/browser/react/SeedImage.js +105 -0
- package/dist/src/browser/react/SeedImage.js.map +1 -0
- package/dist/src/browser/react/index.d.ts +2 -1
- package/dist/src/browser/react/index.d.ts.map +1 -1
- package/dist/src/browser/react/item.d.ts +8 -8
- package/dist/src/browser/react/item.d.ts.map +1 -1
- package/dist/src/browser/react/item.js +9 -53
- package/dist/src/browser/react/item.js.map +1 -1
- package/dist/src/browser/react/model.d.ts +7 -0
- package/dist/src/browser/react/model.d.ts.map +1 -0
- package/dist/src/browser/react/model.js +20 -0
- package/dist/src/browser/react/model.js.map +1 -0
- package/dist/src/browser/react/property.d.ts +3 -3
- package/dist/src/browser/react/property.d.ts.map +1 -1
- package/dist/src/browser/react/property.js.map +1 -1
- package/dist/src/browser/react/services.d.ts.map +1 -1
- package/dist/src/browser/react/services.js +6 -1
- package/dist/src/browser/react/services.js.map +1 -1
- package/dist/src/browser/workers/FileDownloader.d.ts.map +1 -1
- package/dist/src/browser/workers/FileDownloader.js +4 -1
- package/dist/src/browser/workers/FileDownloader.js.map +1 -1
- package/dist/src/browser/workers/ImageResizer.d.ts.map +1 -1
- package/dist/src/browser/workers/ImageResizer.js +1 -0
- package/dist/src/browser/workers/ImageResizer.js.map +1 -1
- package/dist/src/browser/workers/filesDownload.d.ts.map +1 -1
- package/dist/src/browser/workers/filesDownload.js +4 -0
- package/dist/src/browser/workers/filesDownload.js.map +1 -1
- package/dist/src/browser/workers/imageResize.d.ts.map +1 -1
- package/dist/src/browser/workers/imageResize.js +4 -1
- package/dist/src/browser/workers/imageResize.js.map +1 -1
- package/dist/src/client/BaseClientManager.d.ts.map +1 -1
- package/dist/src/client/ClientManager.d.ts +184 -22
- package/dist/src/client/ClientManager.d.ts.map +1 -1
- package/dist/src/client/ClientManager.js +29 -0
- package/dist/src/client/ClientManager.js.map +1 -1
- package/dist/src/client/actors/initialize.d.ts +2 -2
- package/dist/src/client/actors/initialize.d.ts.map +1 -1
- package/dist/src/client/actors/initialize.js +9 -0
- package/dist/src/client/actors/initialize.js.map +1 -1
- package/dist/src/client/actors/saveAppState.js +3 -3
- package/dist/src/client/actors/saveAppState.js.map +1 -1
- package/dist/src/client/clientManagerMachine.d.ts +86 -10
- package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
- package/dist/src/client/clientManagerMachine.js +3 -1
- package/dist/src/client/clientManagerMachine.js.map +1 -1
- package/dist/src/db/read/getModelSchemas.d.ts +1 -2
- package/dist/src/db/read/getModelSchemas.d.ts.map +1 -1
- package/dist/src/db/read/getModelSchemas.js +1 -21
- package/dist/src/db/read/getModelSchemas.js.map +1 -1
- package/dist/src/db/read/getModels.d.ts +5 -0
- package/dist/src/db/read/getModels.d.ts.map +1 -0
- package/dist/src/db/read/getModels.js +16 -0
- package/dist/src/db/read/getModels.js.map +1 -0
- package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/src/db/read/getPublishPayload.js +52 -14
- package/dist/src/db/read/getPublishPayload.js.map +1 -1
- package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
- package/dist/src/db/read/getPublishUploads.js +34 -3
- package/dist/src/db/read/getPublishUploads.js.map +1 -1
- package/dist/src/events/files/download.d.ts.map +1 -1
- package/dist/src/events/files/download.js +0 -1
- package/dist/src/events/files/download.js.map +1 -1
- package/dist/src/events/files/index.d.ts.map +1 -1
- package/dist/src/events/files/index.js +0 -1
- package/dist/src/events/files/index.js.map +1 -1
- package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/src/events/item/syncDbWithEas.js +9 -28
- package/dist/src/events/item/syncDbWithEas.js.map +1 -1
- package/dist/src/events/services/allItems.d.ts.map +1 -1
- package/dist/src/events/services/allItems.js +0 -1
- package/dist/src/events/services/allItems.js.map +1 -1
- package/dist/src/helpers/FileManager/BaseFileManager.d.ts +2 -0
- package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
- package/dist/src/helpers/FileManager/BaseFileManager.js +6 -0
- package/dist/src/helpers/FileManager/BaseFileManager.js.map +1 -1
- package/dist/src/helpers/constants.d.ts +2 -2
- package/dist/src/helpers/constants.d.ts.map +1 -1
- package/dist/src/helpers/constants.js +14 -6
- package/dist/src/helpers/constants.js.map +1 -1
- package/dist/src/helpers/environment.js +1 -1
- package/dist/src/helpers/environment.js.map +1 -1
- package/dist/src/helpers/getSegmentedItemProperties.d.ts +1 -0
- package/dist/src/helpers/getSegmentedItemProperties.d.ts.map +1 -1
- package/dist/src/helpers/getSegmentedItemProperties.js +6 -2
- package/dist/src/helpers/getSegmentedItemProperties.js.map +1 -1
- package/dist/src/helpers/index.d.ts +2 -1
- package/dist/src/helpers/index.d.ts.map +1 -1
- package/dist/src/helpers/index.js +3 -10
- package/dist/src/helpers/index.js.map +1 -1
- package/dist/src/helpers/scripts.d.ts +2 -0
- package/dist/src/helpers/scripts.d.ts.map +1 -0
- package/dist/src/helpers/scripts.js +14 -0
- package/dist/src/helpers/scripts.js.map +1 -0
- package/dist/src/index.d.ts +11 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/interfaces/IItemProperty.d.ts +7 -0
- package/dist/src/interfaces/IItemProperty.d.ts.map +1 -1
- package/dist/src/node/PathResolver.d.ts +39 -0
- package/dist/src/node/PathResolver.d.ts.map +1 -0
- package/dist/src/node/PathResolver.js +150 -0
- package/dist/src/node/PathResolver.js.map +1 -0
- package/dist/src/node/codegen/drizzle.d.ts.map +1 -1
- package/dist/src/node/codegen/drizzle.js +25 -4
- package/dist/src/node/codegen/drizzle.js.map +1 -1
- package/dist/src/node/constants.d.ts +0 -11
- package/dist/src/node/constants.d.ts.map +1 -1
- package/dist/src/node/constants.js +1 -32
- package/dist/src/node/constants.js.map +1 -1
- package/dist/src/node/db/node.app.db.config.d.ts.map +1 -1
- package/dist/src/node/helpers/FileManager.d.ts +2 -0
- package/dist/src/node/helpers/FileManager.d.ts.map +1 -1
- package/dist/src/node/helpers/index.d.ts.map +1 -1
- package/dist/src/node/helpers/index.js +0 -1
- package/dist/src/node/helpers/index.js.map +1 -1
- package/dist/src/schema/image/model.d.ts +8 -0
- package/dist/src/schema/image/model.d.ts.map +1 -0
- package/dist/src/schema/image/model.js +29 -0
- package/dist/src/schema/image/model.js.map +1 -0
- package/dist/src/schema/model/index.d.ts +8 -8
- package/dist/src/schema/property/index.d.ts +33 -45
- package/dist/src/schema/property/index.d.ts.map +1 -1
- package/dist/src/schema/property/index.js +0 -1
- package/dist/src/schema/property/index.js.map +1 -1
- package/dist/src/seedSchema/ConfigSchema.js +18 -0
- package/dist/src/seedSchema/ConfigSchema.js.map +1 -0
- package/dist/src/services/db/actors/migrate.js +2 -2
- package/dist/src/services/db/actors/migrate.js.map +1 -1
- package/dist/src/services/global/globalMachine.d.ts +90 -90
- package/dist/src/services/internal/helpers.js +3 -3
- package/dist/src/services/internal/helpers.js.map +1 -1
- package/dist/src/stores/eas.d.ts +12 -5
- package/dist/src/stores/eas.d.ts.map +1 -1
- package/dist/src/stores/eas.js +13 -8
- package/dist/src/stores/eas.js.map +1 -1
- package/dist/src/stores/modelClass.d.ts.map +1 -1
- package/dist/src/stores/modelClass.js.map +1 -1
- package/dist/src/types/model.d.ts +2 -15
- package/dist/src/types/model.d.ts.map +1 -1
- package/package.json +8 -7
- package/dist/src/Item/index.d.ts +0 -5
- package/dist/src/Item/index.d.ts.map +0 -1
- package/dist/src/Item/index.js +0 -4
- package/dist/src/Item/index.js.map +0 -1
- package/dist/src/ItemProperty/index.d.ts +0 -5
- package/dist/src/ItemProperty/index.d.ts.map +0 -1
- package/dist/src/ItemProperty/service/actors/index.d.ts +0 -4
- package/dist/src/ItemProperty/service/actors/index.d.ts.map +0 -1
- package/dist/src/browser/Item/index.d.ts +0 -2
- package/dist/src/browser/Item/index.d.ts.map +0 -1
- package/dist/src/browser/Item/index.js +0 -2
- package/dist/src/browser/Item/index.js.map +0 -1
- package/dist/src/browser/ItemProperty/index.d.ts +0 -2
- package/dist/src/browser/ItemProperty/index.d.ts.map +0 -1
|
@@ -9,16 +9,12 @@ import { modelUids } from '../../seedSchema/ModelUidSchema.js';
|
|
|
9
9
|
import { eq } from 'drizzle-orm';
|
|
10
10
|
import pluralize from 'pluralize';
|
|
11
11
|
import { toSnakeCase } from '../../helpers/index.js';
|
|
12
|
-
import { GET_SCHEMAS } from '../../Item/queries.js';
|
|
13
|
-
import { BaseEasClient } from '../../helpers/EasClient/BaseEasClient.js';
|
|
14
|
-
import { BaseQueryClient } from '../../helpers/QueryClient/BaseQueryClient.js';
|
|
15
12
|
|
|
13
|
+
const schemaStringToModelRecord = new Map();
|
|
16
14
|
const getModelSchemas = async () => {
|
|
17
15
|
const models$1 = getModels();
|
|
18
16
|
const modelRecords = [];
|
|
19
|
-
const schemaStringToModelRecord = new Map();
|
|
20
17
|
const appDb = BaseDb.getAppDb();
|
|
21
|
-
const OR = [];
|
|
22
18
|
for (const [modelName, _] of Object.entries(models$1)) {
|
|
23
19
|
const foundModelQuery = await appDb
|
|
24
20
|
.select({
|
|
@@ -41,25 +37,9 @@ const getModelSchemas = async () => {
|
|
|
41
37
|
continue;
|
|
42
38
|
}
|
|
43
39
|
const schemaString = `bytes32 ${toSnakeCase(modelName)}`;
|
|
44
|
-
OR.push({
|
|
45
|
-
schema: {
|
|
46
|
-
equals: `bytes32 ${toSnakeCase(modelName)}`,
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
40
|
schemaStringToModelRecord.set(schemaString, foundModel);
|
|
50
41
|
}
|
|
51
|
-
const queryClient = BaseQueryClient.getQueryClient();
|
|
52
|
-
const easClient = BaseEasClient.getEasClient();
|
|
53
|
-
const modelSchemas = await queryClient.fetchQuery({
|
|
54
|
-
queryKey: [`getSchemasAllModels`],
|
|
55
|
-
queryFn: async () => easClient.request(GET_SCHEMAS, {
|
|
56
|
-
where: {
|
|
57
|
-
OR,
|
|
58
|
-
},
|
|
59
|
-
}),
|
|
60
|
-
});
|
|
61
42
|
return {
|
|
62
|
-
modelSchemas,
|
|
63
43
|
schemaStringToModelRecord,
|
|
64
44
|
modelRecords,
|
|
65
45
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getModelSchemas.js","sources":["../../../../../src/db/read/getModelSchemas.ts"],"sourcesContent":["import { getModels } from '@/stores/modelClass'\nimport { GetSchemasQuery, Schema } from '@/graphql/gql/graphql'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { models as modelsTable, modelUids } from '@/seedSchema'\nimport { eq } from 'drizzle-orm'\nimport pluralize from 'pluralize'\nimport { toSnakeCase } from '@/helpers'\
|
|
1
|
+
{"version":3,"file":"getModelSchemas.js","sources":["../../../../../src/db/read/getModelSchemas.ts"],"sourcesContent":["import { getModels } from '@/stores/modelClass'\nimport { GetSchemasQuery, Schema } from '@/graphql/gql/graphql'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { models as modelsTable, modelUids } from '@/seedSchema'\nimport { eq } from 'drizzle-orm'\nimport pluralize from 'pluralize'\nimport { toSnakeCase } from '@/helpers'\n\nconst schemaStringToModelRecord = new Map<string, Schema>()\n\ntype GetModelSchemasReturn = {\n schemaStringToModelRecord: Map<string, Schema>\n modelRecords: Record<string, unknown>\n}\n\ntype GetModelSchemas = () => Promise<GetModelSchemasReturn>\n\nexport const getModelSchemas: GetModelSchemas = async () => {\n const models = getModels()\n const modelRecords = [] as Record<string, unknown>[]\n\n \n\n const appDb = BaseDb.getAppDb()\n\n for (const [modelName, _] of Object.entries(models)) {\n const foundModelQuery = await appDb\n .select({\n id: modelsTable.id,\n name: modelsTable.name,\n uid: modelUids.uid,\n })\n .from(modelsTable)\n .leftJoin(modelUids, eq(modelsTable.id, modelUids.modelId))\n .where(eq(modelsTable.name, modelName))\n .limit(1)\n\n const foundModel: Schema = { ...foundModelQuery[0] }\n\n if (!foundModel) {\n console.error(\n `[item/events] [syncDbWithEas] model ${modelName} not found in SDK DB`,\n )\n return\n }\n\n foundModel.tableName = pluralize(foundModel.name).toLowerCase()\n\n modelRecords!.push(foundModel)\n\n if (modelName === 'Seed' || modelName === 'Version') {\n continue\n }\n\n const schemaString = `bytes32 ${toSnakeCase(modelName)}`\n\n schemaStringToModelRecord.set(schemaString, foundModel)\n }\n\n return {\n schemaStringToModelRecord,\n modelRecords,\n }\n}\n"],"names":["models","modelsTable"],"mappings":";;;;;;;;;;;;AAQA,MAAM,yBAAyB,GAAG,IAAI,GAAG,EAAkB;AAS9C,MAAA,eAAe,GAAoB,YAAW;AACzD,IAAA,MAAMA,QAAM,GAAG,SAAS,EAAE;IAC1B,MAAM,YAAY,GAAG,EAA+B;AAIpD,IAAA,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE;AAE/B,IAAA,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAACA,QAAM,CAAC,EAAE;QACnD,MAAM,eAAe,GAAG,MAAM;AAC3B,aAAA,MAAM,CAAC;YACN,EAAE,EAAEC,MAAW,CAAC,EAAE;YAClB,IAAI,EAAEA,MAAW,CAAC,IAAI;YACtB,GAAG,EAAE,SAAS,CAAC,GAAG;SACnB;aACA,IAAI,CAACA,MAAW;AAChB,aAAA,QAAQ,CAAC,SAAS,EAAE,EAAE,CAACA,MAAW,CAAC,EAAE,EAAE,SAAS,CAAC,OAAO,CAAC;aACzD,KAAK,CAAC,EAAE,CAACA,MAAW,CAAC,IAAI,EAAE,SAAS,CAAC;aACrC,KAAK,CAAC,CAAC,CAAC;QAEX,MAAM,UAAU,GAAW,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC,EAAE;QAEpD,IAAI,CAAC,UAAU,EAAE;AACf,YAAA,OAAO,CAAC,KAAK,CACX,uCAAuC,SAAS,CAAA,oBAAA,CAAsB,CACvE;YACD;;AAGF,QAAA,UAAU,CAAC,SAAS,GAAG,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE;AAE/D,QAAA,YAAa,CAAC,IAAI,CAAC,UAAU,CAAC;QAE9B,IAAI,SAAS,KAAK,MAAM,IAAI,SAAS,KAAK,SAAS,EAAE;YACnD;;QAGF,MAAM,YAAY,GAAG,CAAW,QAAA,EAAA,WAAW,CAAC,SAAS,CAAC,EAAE;AAExD,QAAA,yBAAyB,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC;;IAGzD,OAAO;QACL,yBAAyB;QACzB,YAAY;KACb;AACH;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getModels.d.ts","sourceRoot":"","sources":["../../../../src/db/read/getModels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAU,MAAM,cAAc,CAAA;AAGtD,KAAK,SAAS,GAAG,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC,CAAA;AAEjD,eAAO,MAAM,SAAS,EAAE,SAOvB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import '../../seedSchema/SeedSchema.js';
|
|
2
|
+
import '../../seedSchema/VersionSchema.js';
|
|
3
|
+
import '../../seedSchema/MetadataSchema.js';
|
|
4
|
+
import '../../seedSchema/AppStateSchema.js';
|
|
5
|
+
import { models } from '../../seedSchema/ModelSchema.js';
|
|
6
|
+
import '../../seedSchema/ModelUidSchema.js';
|
|
7
|
+
import { BaseDb } from '../Db/BaseDb.js';
|
|
8
|
+
|
|
9
|
+
const getModels = async () => {
|
|
10
|
+
const appDb = BaseDb.getAppDb();
|
|
11
|
+
const modelsData = await appDb.select().from(models);
|
|
12
|
+
return modelsData || [];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { getModels };
|
|
16
|
+
//# sourceMappingURL=getModels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getModels.js","sources":["../../../../../src/db/read/getModels.ts"],"sourcesContent":["import { ModelRecordType, models } from '@/seedSchema'\nimport { BaseDb } from '@/db/Db/BaseDb'\n\ntype GetModels = () => Promise<ModelRecordType[]>\n\nexport const getModels: GetModels = async () => {\n\n const appDb = BaseDb.getAppDb()\n\n const modelsData = await appDb.select().from(models)\n\n return modelsData || []\n}\n"],"names":[],"mappings":";;;;;;;;AAKa,MAAA,SAAS,GAAc,YAAW;AAE7C,IAAA,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE;AAE/B,IAAA,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC;IAEpD,OAAO,UAAU,IAAI,EAAE;AACzB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPublishPayload.d.ts","sourceRoot":"","sources":["../../../../src/db/read/getPublishPayload.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,kBAAkB,EAGnB,MAAM,uCAAuC,CAAA;AAW9C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"getPublishPayload.d.ts","sourceRoot":"","sources":["../../../../src/db/read/getPublishPayload.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,kBAAkB,EAGnB,MAAM,uCAAuC,CAAA;AAW9C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAoS1C,KAAK,cAAc,GAAG;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,OAAO,CAAA;IACxB,aAAa,EAAE,MAAM,CAAA;IACrB,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,kBAAkB,EAAE,kBAAkB,EAAE,CAAA;IACxC,kBAAkB,EAAE,GAAG,EAAE,CAAA;CAC1B,CAAA;AAED,KAAK,mBAAmB,GAAG,cAAc,EAAE,CAAA;AAE3C,KAAK,mBAAmB,GAAG;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,iBAAiB,SACtB,QAAQ,CAAC,GAAG,CAAC,wBACG,mBAAmB,EAAE,KAC1C,OAAO,CAAC,mBAAmB,CA0E7B,CAAA"}
|
|
@@ -7,7 +7,10 @@ import pluralize from 'pluralize';
|
|
|
7
7
|
import { getSchemaUidForModel } from './getSchemaUidForModel.js';
|
|
8
8
|
import { getSchemaUidForSchemaDefinition } from '../../stores/eas.js';
|
|
9
9
|
import { getSegmentedItemProperties } from '../../helpers/getSegmentedItemProperties.js';
|
|
10
|
+
import debug from 'debug';
|
|
11
|
+
import { ethers } from 'ethers';
|
|
10
12
|
|
|
13
|
+
debug('seedSdk:db:getPublishPayload');
|
|
11
14
|
const getVersionUid = (item) => {
|
|
12
15
|
let versionUid;
|
|
13
16
|
if (item.latestVersionUid &&
|
|
@@ -23,7 +26,7 @@ const getPropertyData = async (itemProperty) => {
|
|
|
23
26
|
const propertyNameForSchema = toSnakeCase(itemProperty.propertyName);
|
|
24
27
|
const schemaDef = `${easDataType} ${propertyNameForSchema}`;
|
|
25
28
|
if (!schemaUid) {
|
|
26
|
-
schemaUid = getSchemaUidForSchemaDefinition(schemaDef);
|
|
29
|
+
schemaUid = await getSchemaUidForSchemaDefinition({ schemaText: schemaDef });
|
|
27
30
|
if (!schemaUid) {
|
|
28
31
|
const schema = await getSchemaForItemProperty({
|
|
29
32
|
propertyName: 'version',
|
|
@@ -43,13 +46,27 @@ const getPropertyData = async (itemProperty) => {
|
|
|
43
46
|
};
|
|
44
47
|
const processBasicProperties = async (itemBasicProperties, itemPublishData) => {
|
|
45
48
|
for (const basicProperty of itemBasicProperties) {
|
|
46
|
-
|
|
49
|
+
let value = basicProperty.getService().getSnapshot().context.propertyValue;
|
|
47
50
|
if (!value || basicProperty.uid) {
|
|
48
51
|
continue;
|
|
49
52
|
}
|
|
50
53
|
const { schemaUid, easDataType, schemaDef } = await getPropertyData(basicProperty);
|
|
51
54
|
const propertyNameForSchema = toSnakeCase(basicProperty.propertyName);
|
|
52
|
-
|
|
55
|
+
if (schemaDef.startsWith('bytes32[]') && !Array.isArray(value)) {
|
|
56
|
+
throw new Error(`Invalid value for property: ${basicProperty.propertyName}. Expected an array of bytes32, got ${value}.`);
|
|
57
|
+
}
|
|
58
|
+
if (schemaDef.startsWith('bytes32[]')) {
|
|
59
|
+
const newValues = [];
|
|
60
|
+
for (const seedId of value) {
|
|
61
|
+
if (seedId.length !== 66 && !seedId.startsWith('0x')) {
|
|
62
|
+
newValues.push(ethers.encodeBytes32String(seedId));
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
newValues.push(seedId);
|
|
66
|
+
}
|
|
67
|
+
value = newValues;
|
|
68
|
+
}
|
|
69
|
+
let data = [
|
|
53
70
|
{
|
|
54
71
|
name: propertyNameForSchema,
|
|
55
72
|
type: easDataType,
|
|
@@ -70,10 +87,13 @@ const processBasicProperties = async (itemBasicProperties, itemPublishData) => {
|
|
|
70
87
|
}
|
|
71
88
|
return itemPublishData;
|
|
72
89
|
};
|
|
73
|
-
const
|
|
74
|
-
|
|
90
|
+
const processRelationOrImageProperty = async (relationOrImageProperty, multiPublishPayload, uploadedTransactions, originalSeedLocalId) => {
|
|
91
|
+
if (!relationOrImageProperty.schemaUid) {
|
|
92
|
+
throw new Error(`Schema uid not found for relation or image property: ${relationOrImageProperty.propertyName}`);
|
|
93
|
+
}
|
|
94
|
+
const value = relationOrImageProperty.getService().getSnapshot()
|
|
75
95
|
.context.propertyValue;
|
|
76
|
-
if (!value ||
|
|
96
|
+
if (!value || relationOrImageProperty.uid) {
|
|
77
97
|
return multiPublishPayload;
|
|
78
98
|
}
|
|
79
99
|
const { localId: seedLocalId, uid: seedUid } = getCorrectId(value);
|
|
@@ -82,12 +102,19 @@ const processRelationProperty = async (relationProperty, multiPublishPayload, up
|
|
|
82
102
|
seedUid,
|
|
83
103
|
});
|
|
84
104
|
if (!relatedItem) {
|
|
85
|
-
throw new Error(`No related item found for relation property: ${
|
|
105
|
+
throw new Error(`No related item found for relation or image property: ${relationOrImageProperty.propertyName}`);
|
|
86
106
|
}
|
|
87
107
|
const versionUid = getVersionUid(relatedItem);
|
|
88
|
-
|
|
108
|
+
let modelName;
|
|
109
|
+
if (relationOrImageProperty.propertyDef?.dataType === 'Image') {
|
|
110
|
+
modelName = 'Image';
|
|
111
|
+
}
|
|
112
|
+
if (relationOrImageProperty.propertyDef?.dataType === 'Relation') {
|
|
113
|
+
modelName = relationOrImageProperty.propertyDef.ref;
|
|
114
|
+
}
|
|
115
|
+
const seedSchemaUid = await getSchemaUidForModel(modelName);
|
|
89
116
|
let publishPayload = {
|
|
90
|
-
localId:
|
|
117
|
+
localId: relationOrImageProperty.localId,
|
|
91
118
|
seedIsRevocable: true,
|
|
92
119
|
versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
|
|
93
120
|
seedUid: seedUid || ZERO_BYTES32,
|
|
@@ -97,7 +124,7 @@ const processRelationProperty = async (relationProperty, multiPublishPayload, up
|
|
|
97
124
|
propertiesToUpdate: [
|
|
98
125
|
{
|
|
99
126
|
publishLocalId: originalSeedLocalId,
|
|
100
|
-
propertySchemaUid:
|
|
127
|
+
propertySchemaUid: relationOrImageProperty.schemaUid,
|
|
101
128
|
},
|
|
102
129
|
],
|
|
103
130
|
};
|
|
@@ -117,6 +144,9 @@ const processRelationProperty = async (relationProperty, multiPublishPayload, up
|
|
|
117
144
|
return multiPublishPayload;
|
|
118
145
|
};
|
|
119
146
|
const processListProperty = async (listProperty, multiPublishPayload, originalSeedLocalId) => {
|
|
147
|
+
if (!listProperty.schemaUid) {
|
|
148
|
+
throw new Error(`Schema uid not found for list property: ${listProperty.propertyName}`);
|
|
149
|
+
}
|
|
120
150
|
let value = listProperty.getService().getSnapshot().context.propertyValue;
|
|
121
151
|
if (!value || listProperty.uid) {
|
|
122
152
|
return multiPublishPayload;
|
|
@@ -148,7 +178,14 @@ const processListProperty = async (listProperty, multiPublishPayload, originalSe
|
|
|
148
178
|
return multiPublishPayload;
|
|
149
179
|
}
|
|
150
180
|
const versionUid = getVersionUid(relatedItem);
|
|
151
|
-
|
|
181
|
+
let modelName;
|
|
182
|
+
if (listProperty.propertyDef?.ref) {
|
|
183
|
+
modelName = listProperty.propertyDef.ref;
|
|
184
|
+
}
|
|
185
|
+
if (listProperty.propertyDef?.dataType === 'Image') {
|
|
186
|
+
modelName = 'Image';
|
|
187
|
+
}
|
|
188
|
+
const seedSchemaUid = await getSchemaUidForModel(modelName);
|
|
152
189
|
let publishPayload = {
|
|
153
190
|
localId: relatedItem.seedLocalId,
|
|
154
191
|
seedIsRevocable: true,
|
|
@@ -185,7 +222,8 @@ const getPublishPayload = async (item, uploadedTransactions) => {
|
|
|
185
222
|
listOfAttestations: [],
|
|
186
223
|
propertiesToUpdate: [],
|
|
187
224
|
};
|
|
188
|
-
const { itemBasicProperties,
|
|
225
|
+
const { itemBasicProperties, itemListProperties, itemUploadProperties, itemImageProperties, itemRelationProperties, } = getSegmentedItemProperties(item);
|
|
226
|
+
const relationAndImageProperties = [...itemRelationProperties, ...itemImageProperties];
|
|
189
227
|
if (itemUploadProperties.length === 1) {
|
|
190
228
|
const uploadProperty = itemUploadProperties[0];
|
|
191
229
|
const itemProperty = uploadProperty.itemProperty;
|
|
@@ -196,8 +234,8 @@ const getPublishPayload = async (item, uploadedTransactions) => {
|
|
|
196
234
|
itemBasicProperties.push(itemProperty);
|
|
197
235
|
}
|
|
198
236
|
}
|
|
199
|
-
for (const relationProperty of
|
|
200
|
-
multiPublishPayload = await
|
|
237
|
+
for (const relationProperty of relationAndImageProperties) {
|
|
238
|
+
multiPublishPayload = await processRelationOrImageProperty(relationProperty, multiPublishPayload, uploadedTransactions, item.seedLocalId);
|
|
201
239
|
itemBasicProperties.push(relationProperty);
|
|
202
240
|
}
|
|
203
241
|
for (const listProperty of itemListProperties) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPublishPayload.js","sources":["../../../../../src/db/read/getPublishPayload.ts"],"sourcesContent":["import { getItem } from '@/db/read/getItem'\nimport {\n defaultAttestationData,\n INTERNAL_DATA_TYPES,\n VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,\n} from '@/helpers/constants'\nimport {\n AttestationRequest,\n SchemaEncoder,\n ZERO_BYTES32,\n} from '@ethereum-attestation-service/eas-sdk'\n\nimport { getSchemaForItemProperty } from '@/helpers/getSchemaForItemProperty'\nimport { toSnakeCase } from '@/helpers'\nimport pluralize from 'pluralize'\nimport { getSchemaUidForModel } from '@/db/read/getSchemaUidForModel'\nimport { getSchemaUidForSchemaDefinition } from '@/stores/eas'\nimport { getCorrectId } from '@/helpers'\nimport { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'\nimport { IItemProperty } from '@/interfaces'\nimport { IItem } from '@/interfaces'\nimport { BaseItem } from '@/Item/BaseItem'\n\nconst getVersionUid = (item: IItem<any>) => {\n let versionUid\n\n if (\n item.latestVersionUid &&\n item.latestVersionUid !== 'NULL' &&\n item.latestVersionUid !== 'undefined'\n ) {\n versionUid = item.latestVersionUid\n }\n return versionUid || ZERO_BYTES32\n}\n\nconst getPropertyData = async (itemProperty: IItemProperty<any>) => {\n const easDataType =\n INTERNAL_DATA_TYPES[itemProperty.propertyDef!.dataType].eas\n\n let schemaUid: string | undefined = itemProperty.schemaUid\n\n const propertyNameForSchema = toSnakeCase(itemProperty.propertyName)\n\n const schemaDef = `${easDataType} ${propertyNameForSchema}`\n\n if (!schemaUid) {\n schemaUid = getSchemaUidForSchemaDefinition(schemaDef)\n if (!schemaUid) {\n const schema = await getSchemaForItemProperty({\n propertyName: 'version',\n easDataType: 'bytes32',\n })\n if (schema) {\n schemaUid = schema.id\n }\n }\n }\n\n return {\n schemaUid,\n easDataType,\n schemaDef,\n propertyNameForSchema,\n }\n}\n\nconst processBasicProperties = async (\n itemBasicProperties: IItemProperty<any>[],\n itemPublishData: PublishPayload,\n): Promise<PublishPayload> => {\n for (const basicProperty of itemBasicProperties) {\n const value = basicProperty.getService().getSnapshot().context.propertyValue\n\n if (!value || basicProperty.uid) {\n continue\n }\n\n const { schemaUid, easDataType, schemaDef } =\n await getPropertyData(basicProperty)\n\n const propertyNameForSchema = toSnakeCase(basicProperty.propertyName)\n\n const data = [\n {\n name: propertyNameForSchema,\n type: easDataType,\n value,\n },\n ]\n\n const dataEncoder = new SchemaEncoder(schemaDef)\n\n const encodedData = dataEncoder.encodeData(data)\n\n itemPublishData.listOfAttestations.push({\n schema: schemaUid!,\n data: [\n {\n ...defaultAttestationData,\n data: encodedData,\n },\n ],\n })\n }\n\n return itemPublishData\n}\n\nconst processRelationProperty = async (\n relationProperty: IItemProperty<any>,\n multiPublishPayload: MultiPublishPayload,\n uploadedTransactions: UploadedTransaction[],\n originalSeedLocalId: string,\n): Promise<MultiPublishPayload> => {\n const value = relationProperty.getService().getSnapshot()\n .context.propertyValue\n if (!value || relationProperty.uid) {\n return multiPublishPayload\n }\n\n const { localId: seedLocalId, uid: seedUid } = getCorrectId(value)\n\n const relatedItem = await getItem({\n seedLocalId,\n seedUid,\n })\n\n if (!relatedItem) {\n throw new Error(\n `No related item found for relation property: ${relationProperty.propertyName}`,\n )\n }\n\n const versionUid = getVersionUid(relatedItem)\n\n const seedSchemaUid = await getSchemaUidForModel(\n relationProperty.propertyDef!.ref as string,\n )\n\n let publishPayload: PublishPayload = {\n localId: relationProperty.localId,\n seedIsRevocable: true,\n versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,\n seedUid: seedUid || ZERO_BYTES32,\n seedSchemaUid,\n versionUid,\n listOfAttestations: [],\n propertiesToUpdate: [\n {\n publishLocalId: originalSeedLocalId,\n propertySchemaUid: relationProperty.schemaUid,\n },\n ],\n }\n\n const { itemBasicProperties, itemUploadProperties } =\n getSegmentedItemProperties(relatedItem)\n\n if (itemUploadProperties.length === 1) {\n const uploadProperty = itemUploadProperties[0]\n const itemProperty = uploadProperty.itemProperty\n const transactionData = uploadedTransactions.find(\n (transaction) => transaction.seedLocalId === relatedItem.seedLocalId,\n )\n if (transactionData) {\n itemProperty.value = transactionData.txId\n await itemProperty.save()\n itemBasicProperties.push(itemProperty)\n }\n }\n\n publishPayload = await processBasicProperties(\n itemBasicProperties,\n publishPayload,\n )\n\n multiPublishPayload.push(publishPayload)\n\n return multiPublishPayload\n}\n\nconst processListProperty = async (\n listProperty: IItemProperty<any>,\n multiPublishPayload: MultiPublishPayload,\n originalSeedLocalId: string,\n): Promise<MultiPublishPayload> => {\n let value = listProperty.getService().getSnapshot().context.propertyValue\n if (!value || listProperty.uid) {\n return multiPublishPayload\n }\n\n const singularPropertyName = pluralize.singular(listProperty.propertyName)\n const propertyNameForSchema = `${singularPropertyName}${listProperty.propertyDef!.ref}Ids`\n if (typeof value === 'string' && value.length === 66) {\n value = [value]\n }\n if (typeof value === 'string' && value.length > 66) {\n try {\n value = JSON.parse(value)\n } catch (error) {\n value = value.split(',')\n }\n }\n\n for (const seedId of value) {\n const { localId: seedLocalId, uid: seedUid } = getCorrectId(seedId)\n\n const relatedItem = await getItem({\n seedLocalId,\n seedUid,\n })\n\n if (!relatedItem) {\n console.error(\n `No related item found for list property: ${listProperty.propertyName}`,\n )\n continue\n }\n\n if (relatedItem.seedUid) {\n return multiPublishPayload\n }\n\n const versionUid = getVersionUid(relatedItem)\n\n const seedSchemaUid = await getSchemaUidForModel(\n listProperty.propertyDef!.ref as string,\n )\n\n let publishPayload: PublishPayload = {\n localId: relatedItem.seedLocalId,\n seedIsRevocable: true,\n versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,\n seedUid: seedUid || ZERO_BYTES32,\n seedSchemaUid,\n versionUid,\n listOfAttestations: [],\n propertiesToUpdate: [\n {\n publishLocalId: originalSeedLocalId,\n propertySchemaUid: listProperty.schemaUid,\n },\n ],\n }\n\n const { itemBasicProperties } = getSegmentedItemProperties(relatedItem)\n\n publishPayload = await processBasicProperties(\n itemBasicProperties,\n publishPayload,\n )\n\n multiPublishPayload.push(publishPayload)\n }\n\n return multiPublishPayload\n}\n\ntype PublishPayload = {\n localId: string\n seedIsRevocable: boolean\n seedSchemaUid: string\n seedUid: string\n versionSchemaUid: string\n versionUid: string\n listOfAttestations: AttestationRequest[]\n propertiesToUpdate: any[]\n}\n\ntype MultiPublishPayload = PublishPayload[]\n\ntype UploadedTransaction = {\n txId: string\n itemPropertyLocalId?: string\n seedLocalId?: string\n versionLocalId?: string\n itemPropertyName?: string\n}\n\nexport const getPublishPayload = async (\n item: BaseItem<any>,\n uploadedTransactions: UploadedTransaction[],\n): Promise<MultiPublishPayload> => {\n\n let multiPublishPayload: MultiPublishPayload = []\n\n // Each PublishPayload is generated from a Seed that needs publishing\n\n // First we need to determine all Seeds to publish\n\n // That means the Seed of the Item, plus any Seeds pointed to by Relations\n\n let itemPublishData: PublishPayload = {\n localId: item.seedLocalId,\n seedUid: item.seedUid || ZERO_BYTES32,\n seedIsRevocable: true,\n seedSchemaUid: item.schemaUid,\n versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,\n versionUid: getVersionUid(item),\n listOfAttestations: [],\n propertiesToUpdate: [],\n }\n\n const {\n itemBasicProperties,\n itemRelationProperties,\n itemListProperties,\n itemUploadProperties,\n } = getSegmentedItemProperties(item)\n\n if (itemUploadProperties.length === 1) {\n const uploadProperty = itemUploadProperties[0]\n const itemProperty = uploadProperty.itemProperty\n const transactionData = uploadedTransactions.find(\n (transaction) => transaction.seedLocalId === item.seedLocalId,\n )\n if (transactionData) {\n itemProperty.value = transactionData.txId\n await itemProperty.save()\n itemBasicProperties.push(itemProperty)\n }\n }\n\n for (const relationProperty of itemRelationProperties) {\n multiPublishPayload = await processRelationProperty(\n relationProperty,\n multiPublishPayload,\n uploadedTransactions,\n item.seedLocalId,\n )\n itemBasicProperties.push(relationProperty)\n }\n\n for (const listProperty of itemListProperties) {\n multiPublishPayload = await processListProperty(\n listProperty,\n multiPublishPayload,\n item.seedLocalId,\n )\n itemBasicProperties.push(listProperty)\n }\n \n itemPublishData = await processBasicProperties(\n itemBasicProperties,\n itemPublishData,\n )\n\n multiPublishPayload.push(itemPublishData)\n\n\n \n\n return multiPublishPayload\n}\n"],"names":[],"mappings":";;;;;;;;;;AAuBA,MAAM,aAAa,GAAG,CAAC,IAAgB,KAAI;AACzC,IAAA,IAAI,UAAU;IAEd,IACE,IAAI,CAAC,gBAAgB;QACrB,IAAI,CAAC,gBAAgB,KAAK,MAAM;AAChC,QAAA,IAAI,CAAC,gBAAgB,KAAK,WAAW,EACrC;AACA,QAAA,UAAU,GAAG,IAAI,CAAC,gBAAgB;;IAEpC,OAAO,UAAU,IAAI,YAAY;AACnC,CAAC;AAED,MAAM,eAAe,GAAG,OAAO,YAAgC,KAAI;AACjE,IAAA,MAAM,WAAW,GACf,mBAAmB,CAAC,YAAY,CAAC,WAAY,CAAC,QAAQ,CAAC,CAAC,GAAG;AAE7D,IAAA,IAAI,SAAS,GAAuB,YAAY,CAAC,SAAS;IAE1D,MAAM,qBAAqB,GAAG,WAAW,CAAC,YAAY,CAAC,YAAY,CAAC;AAEpE,IAAA,MAAM,SAAS,GAAG,CAAA,EAAG,WAAW,CAAI,CAAA,EAAA,qBAAqB,EAAE;IAE3D,IAAI,CAAC,S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B,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,IAAI,CAAC,WAAW,CACjB;AACD,QAAA,mBAAmB,CAAC,IAAI,CAAC,gBAAgB,CAAC;;AAG5C,IAAA,KAAK,MAAM,YAAY,IAAI,kBAAkB,EAAE;AAC7C,QAAA,mBAAmB,GAAG,MAAM,mBAAmB,CAC7C,YAAY,EACZ,mBAAmB,EACnB,IAAI,CAAC,WAAW,CACjB;AACD,QAAA,mBAAmB,CAAC,IAAI,CAAC,YAAY,CAAC;;IAGxC,eAAe,GAAG,MAAM,sBAAsB,CAC5C,mBAAmB,EACnB,eAAe,CAChB;AAED,IAAA,mBAAmB,CAAC,IAAI,CAAC,eAAe,CAAC;AAKzC,IAAA,OAAO,mBAAmB;AAC5B;;;;"}
|
|
1
|
+
{"version":3,"file":"getPublishPayload.js","sources":["../../../../../src/db/read/getPublishPayload.ts"],"sourcesContent":["import { getItem } from '@/db/read/getItem'\nimport {\n defaultAttestationData,\n INTERNAL_DATA_TYPES,\n VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,\n} from '@/helpers/constants'\nimport {\n AttestationRequest,\n SchemaEncoder,\n ZERO_BYTES32,\n} from '@ethereum-attestation-service/eas-sdk'\n\nimport { getSchemaForItemProperty } from '@/helpers/getSchemaForItemProperty'\nimport { toSnakeCase } from '@/helpers'\nimport pluralize from 'pluralize'\nimport { getSchemaUidForModel } from '@/db/read/getSchemaUidForModel'\nimport { getSchemaUidForSchemaDefinition } from '@/stores/eas'\nimport { getCorrectId } from '@/helpers'\nimport { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'\nimport { IItemProperty } from '@/interfaces'\nimport { IItem } from '@/interfaces'\nimport { BaseItem } from '@/Item/BaseItem'\nimport debug from 'debug'\nimport {ethers} from 'ethers'\nconst logger = debug('seedSdk:db:getPublishPayload')\n\nconst getVersionUid = (item: IItem<any>) => {\n let versionUid\n\n if (\n item.latestVersionUid &&\n item.latestVersionUid !== 'NULL' &&\n item.latestVersionUid !== 'undefined'\n ) {\n versionUid = item.latestVersionUid\n }\n return versionUid || ZERO_BYTES32\n}\n\nconst getPropertyData = async (itemProperty: IItemProperty<any>) => {\n const easDataType =\n INTERNAL_DATA_TYPES[itemProperty.propertyDef!.dataType].eas\n\n let schemaUid: string | undefined = itemProperty.schemaUid\n\n const propertyNameForSchema = toSnakeCase(itemProperty.propertyName)\n\n const schemaDef = `${easDataType} ${propertyNameForSchema}`\n\n if (!schemaUid) {\n schemaUid = await getSchemaUidForSchemaDefinition({ schemaText: schemaDef })\n if (!schemaUid) {\n const schema = await getSchemaForItemProperty({\n propertyName: 'version',\n easDataType: 'bytes32',\n })\n if (schema) {\n schemaUid = schema.id\n }\n }\n }\n\n return {\n schemaUid,\n easDataType,\n schemaDef,\n propertyNameForSchema,\n }\n}\n\nconst processBasicProperties = async (\n itemBasicProperties: IItemProperty<any>[],\n itemPublishData: PublishPayload,\n): Promise<PublishPayload> => {\n for (const basicProperty of itemBasicProperties) {\n let value = basicProperty.getService().getSnapshot().context.propertyValue\n\n if (!value || basicProperty.uid) {\n continue\n }\n\n const { schemaUid, easDataType, schemaDef } =\n await getPropertyData(basicProperty)\n\n const propertyNameForSchema = toSnakeCase(basicProperty.propertyName)\n\n if (schemaDef.startsWith('bytes32[]') && !Array.isArray(value)) {\n throw new Error(`Invalid value for property: ${basicProperty.propertyName}. Expected an array of bytes32, got ${value}.`)\n }\n\n if (schemaDef.startsWith('bytes32[]')) {\n const newValues = []\n for (const seedId of value) {\n if (seedId.length !== 66 && !seedId.startsWith('0x')) {\n newValues.push(ethers.encodeBytes32String(seedId))\n continue\n }\n newValues.push(seedId)\n }\n value = newValues\n }\n\n let data = [\n {\n name: propertyNameForSchema,\n type: easDataType,\n value,\n },\n ]\n\n const dataEncoder = new SchemaEncoder(schemaDef)\n\n const encodedData = dataEncoder.encodeData(data)\n\n itemPublishData.listOfAttestations.push({\n schema: schemaUid!,\n data: [\n {\n ...defaultAttestationData,\n data: encodedData,\n },\n ],\n })\n }\n\n return itemPublishData\n}\n\n\nconst processRelationOrImageProperty = async (\n relationOrImageProperty: IItemProperty<any>,\n multiPublishPayload: MultiPublishPayload,\n uploadedTransactions: UploadedTransaction[],\n originalSeedLocalId: string,\n): Promise<MultiPublishPayload> => {\n\n if (!relationOrImageProperty.schemaUid) {\n throw new Error(\n `Schema uid not found for relation or image property: ${relationOrImageProperty.propertyName}`,\n )\n }\n\n const value = relationOrImageProperty.getService().getSnapshot()\n .context.propertyValue\n if (!value || relationOrImageProperty.uid) {\n return multiPublishPayload\n }\n\n const { localId: seedLocalId, uid: seedUid } = getCorrectId(value)\n\n const relatedItem = await getItem({\n seedLocalId,\n seedUid,\n })\n\n if (!relatedItem) {\n throw new Error(\n `No related item found for relation or image property: ${relationOrImageProperty.propertyName}`,\n )\n }\n\n const versionUid = getVersionUid(relatedItem)\n\n let modelName: string\n\n if (relationOrImageProperty.propertyDef?.dataType === 'Image') {\n modelName = 'Image'\n }\n\n if (relationOrImageProperty.propertyDef?.dataType === 'Relation') {\n modelName = relationOrImageProperty.propertyDef!.ref as string\n }\n\n const seedSchemaUid = await getSchemaUidForModel(\n modelName!,\n )\n\n let publishPayload: PublishPayload = {\n localId: relationOrImageProperty.localId,\n seedIsRevocable: true,\n versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,\n seedUid: seedUid || ZERO_BYTES32,\n seedSchemaUid,\n versionUid,\n listOfAttestations: [],\n propertiesToUpdate: [\n {\n publishLocalId: originalSeedLocalId,\n propertySchemaUid: relationOrImageProperty.schemaUid,\n },\n ],\n }\n\n const { itemBasicProperties, itemUploadProperties } =\n getSegmentedItemProperties(relatedItem)\n\n if (itemUploadProperties.length === 1) {\n const uploadProperty = itemUploadProperties[0]\n const itemProperty = uploadProperty.itemProperty\n const transactionData = uploadedTransactions.find(\n (transaction) => transaction.seedLocalId === relatedItem.seedLocalId,\n )\n if (transactionData) {\n itemProperty.value = transactionData.txId\n await itemProperty.save()\n itemBasicProperties.push(itemProperty)\n }\n }\n\n publishPayload = await processBasicProperties(\n itemBasicProperties,\n publishPayload,\n )\n\n multiPublishPayload.push(publishPayload)\n\n return multiPublishPayload\n}\n\nconst processListProperty = async (\n listProperty: IItemProperty<any>,\n multiPublishPayload: MultiPublishPayload,\n originalSeedLocalId: string,\n): Promise<MultiPublishPayload> => {\n\n if (!listProperty.schemaUid) {\n throw new Error(\n `Schema uid not found for list property: ${listProperty.propertyName}`,\n )\n }\n\n let value = listProperty.getService().getSnapshot().context.propertyValue\n if (!value || listProperty.uid) {\n return multiPublishPayload\n }\n\n const singularPropertyName = pluralize.singular(listProperty.propertyName)\n const propertyNameForSchema = `${singularPropertyName}${listProperty.propertyDef!.ref}Ids`\n if (typeof value === 'string' && value.length === 66) {\n value = [value]\n }\n if (typeof value === 'string' && value.length > 66) {\n try {\n value = JSON.parse(value)\n } catch (error) {\n value = value.split(',')\n }\n }\n\n for (const seedId of value) {\n const { localId: seedLocalId, uid: seedUid } = getCorrectId(seedId)\n\n const relatedItem = await getItem({\n seedLocalId,\n seedUid,\n })\n\n if (!relatedItem) {\n console.error(\n `No related item found for list property: ${listProperty.propertyName}`,\n )\n continue\n }\n\n if (relatedItem.seedUid) {\n return multiPublishPayload\n }\n\n const versionUid = getVersionUid(relatedItem)\n\n let modelName: string\n\n if (listProperty.propertyDef?.ref) {\n modelName = listProperty.propertyDef!.ref as string\n }\n\n if (listProperty.propertyDef?.dataType === 'Image') {\n modelName = 'Image'\n }\n\n const seedSchemaUid = await getSchemaUidForModel(\n modelName!,\n )\n\n let publishPayload: PublishPayload = {\n localId: relatedItem.seedLocalId,\n seedIsRevocable: true,\n versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,\n seedUid: seedUid || ZERO_BYTES32,\n seedSchemaUid,\n versionUid,\n listOfAttestations: [],\n propertiesToUpdate: [\n {\n publishLocalId: originalSeedLocalId,\n propertySchemaUid: listProperty.schemaUid,\n },\n ],\n }\n\n const { itemBasicProperties } = getSegmentedItemProperties(relatedItem)\n\n publishPayload = await processBasicProperties(\n itemBasicProperties,\n publishPayload,\n )\n\n multiPublishPayload.push(publishPayload)\n }\n\n return multiPublishPayload\n}\n\ntype PublishPayload = {\n localId: string\n seedIsRevocable: boolean\n seedSchemaUid: string\n seedUid: string\n versionSchemaUid: string\n versionUid: string\n listOfAttestations: AttestationRequest[]\n propertiesToUpdate: any[]\n}\n\ntype MultiPublishPayload = PublishPayload[]\n\ntype UploadedTransaction = {\n txId: string\n itemPropertyLocalId?: string\n seedLocalId?: string\n versionLocalId?: string\n itemPropertyName?: string\n}\n\nexport const getPublishPayload = async (\n item: BaseItem<any>,\n uploadedTransactions: UploadedTransaction[],\n): Promise<MultiPublishPayload> => {\n\n let multiPublishPayload: MultiPublishPayload = []\n\n // Each PublishPayload is generated from a Seed that needs publishing\n\n // First we need to determine all Seeds to publish\n\n // That means the Seed of the Item, plus any Seeds pointed to by Relations\n\n let itemPublishData: PublishPayload = {\n localId: item.seedLocalId,\n seedUid: item.seedUid || ZERO_BYTES32,\n seedIsRevocable: true,\n seedSchemaUid: item.schemaUid,\n versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,\n versionUid: getVersionUid(item),\n listOfAttestations: [],\n propertiesToUpdate: [],\n }\n\n const {\n itemBasicProperties,\n itemListProperties,\n itemUploadProperties,\n itemImageProperties,\n itemRelationProperties,\n } = getSegmentedItemProperties(item)\n\n const relationAndImageProperties = [...itemRelationProperties, ...itemImageProperties]\n\n if (itemUploadProperties.length === 1) {\n const uploadProperty = itemUploadProperties[0]\n const itemProperty = uploadProperty.itemProperty\n const transactionData = uploadedTransactions.find(\n (transaction) => transaction.seedLocalId === item.seedLocalId,\n )\n if (transactionData) {\n itemProperty.value = transactionData.txId\n await itemProperty.save()\n itemBasicProperties.push(itemProperty)\n }\n }\n\n for (const relationProperty of relationAndImageProperties) {\n multiPublishPayload = await processRelationOrImageProperty(\n relationProperty,\n multiPublishPayload,\n uploadedTransactions,\n item.seedLocalId,\n )\n itemBasicProperties.push(relationProperty)\n }\n\n for (const listProperty of itemListProperties) {\n multiPublishPayload = await processListProperty(\n listProperty,\n multiPublishPayload,\n item.seedLocalId,\n )\n itemBasicProperties.push(listProperty)\n }\n \n itemPublishData = await processBasicProperties(\n itemBasicProperties,\n itemPublishData,\n )\n\n multiPublishPayload.push(itemPublishData)\n\n\n \n\n return multiPublishPayload\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAwBe,KAAK,CAAC,8BAA8B;AAEnD,MAAM,aAAa,GAAG,CAAC,IAAgB,KAAI;AACzC,IAAA,IAAI,UAAU;IAEd,IACE,IAAI,CAAC,gBAAgB;QACrB,IAAI,CAAC,gBAAgB,KAAK,MAAM;AAChC,QAAA,IAAI,CAAC,gBAAgB,KAAK,WAAW,EACrC;AACA,QAAA,UAAU,GAAG,IAAI,CAAC,gBAAgB;;IAEpC,OAAO,UAAU,IAAI,YAAY;AACnC,CAAC;AAED,MAAM,eAAe,GAAG,OAAO,YAAgC,KAAI;AACjE,IAAA,MAAM,WAAW,GACf,mBAAmB,CAAC,YAAY,CAAC,WAAY,CAAC,QAAQ,CAAC,CAAC,GAAG;AAE7D,IAAA,IAAI,SAAS,GAAuB,YAAY,CAAC,SAAS;IAE1D,MAAM,qBAAqB,GAAG,WAAW,CAAC,YAAY,CAAC,YAAY,CAAC;AAEpE,IAAA,MAAM,SAAS,GAAG,CAAA,EAAG,WAAW,CAAI,CAAA,EAAA,qBAAqB,EAAE;IAE3D,IAAI,CAAC,SAAS,EAAE;QACd,SAAS,GAAG,MAAM,+BAA+B,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;QAC5E,IAAI,CAAC,SAAS,EAAE;AACd,YAAA,MAAM,MAAM,GAAG,MAAM,wBAAwB,CAAC;AAC5C,gBAAA,YAAY,EAAE,SAAS;AACvB,gBAAA,WAAW,EAAE,SAAS;AACvB,aAAA,CAAC;YACF,IAAI,MAAM,EAAE;AACV,gBAAA,SAAS,GAAG,MA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mB,CAAC,IAAI,CAAC,gBAAgB,CAAC;;AAG5C,IAAA,KAAK,MAAM,YAAY,IAAI,kBAAkB,EAAE;AAC7C,QAAA,mBAAmB,GAAG,MAAM,mBAAmB,CAC7C,YAAY,EACZ,mBAAmB,EACnB,IAAI,CAAC,WAAW,CACjB;AACD,QAAA,mBAAmB,CAAC,IAAI,CAAC,YAAY,CAAC;;IAGxC,eAAe,GAAG,MAAM,sBAAsB,CAC5C,mBAAmB,EACnB,eAAe,CAChB;AAED,IAAA,mBAAmB,CAAC,IAAI,CAAC,eAAe,CAAC;AAKzC,IAAA,OAAO,mBAAmB;AAC5B;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPublishUploads.d.ts","sourceRoot":"","sources":["../../../../src/db/read/getPublishUploads.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,SAAS,CAAA;AAMjC,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAMnD,eAAO,MAAM,yBAAyB,SAC9B,MAAM,GAAG,UAAU,eACZ,MAAM,GAAG,SAAS,KAC9B,OAAO,CAAC,WAAW,CAerB,CAAA;
|
|
1
|
+
{"version":3,"file":"getPublishUploads.d.ts","sourceRoot":"","sources":["../../../../src/db/read/getPublishUploads.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,SAAS,CAAA;AAMjC,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAMnD,eAAO,MAAM,yBAAyB,SAC9B,MAAM,GAAG,UAAU,eACZ,MAAM,GAAG,SAAS,KAC9B,OAAO,CAAC,WAAW,CAerB,CAAA;AAsCD,MAAM,MAAM,cAAc,GAAG;IAC3B,YAAY,EAAE,aAAa,CAAC,GAAG,CAAC,CAAA;IAChC,eAAe,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,CAAA;CACtC,CAAA;AA0HD,MAAM,MAAM,aAAa,GAAG;IAC1B,gBAAgB,EAAE,MAAM,CAAA;IACxB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,MAAM,CAAA;IACtB,iBAAiB,EAAE,WAAW,CAAA;CAC/B,CAAA;AACD,eAAO,MAAM,iBAAiB,SACtB,KAAK,CAAC,GAAG,CAAC,YACP,aAAa,EAAE,wBACF,aAAa,CAAC,GAAG,CAAC,6BAkDzC,CAAA"}
|
|
@@ -19,6 +19,30 @@ const prepareArweaveTransaction = async (data, contentHash) => {
|
|
|
19
19
|
}
|
|
20
20
|
return tx;
|
|
21
21
|
};
|
|
22
|
+
const getImageUploads = async (itemImageProperties) => {
|
|
23
|
+
const uploads = [];
|
|
24
|
+
for (const itemImageProperty of itemImageProperties) {
|
|
25
|
+
const filePath = `/files/images/${itemImageProperty.refResolvedValue}`;
|
|
26
|
+
if (!filePath) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const exists = await BaseFileManager.pathExists(filePath);
|
|
30
|
+
if (!exists) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const fileContents = await BaseFileManager.readFileAsString(filePath);
|
|
34
|
+
const contentHash = await getContentHash(fileContents);
|
|
35
|
+
const transaction = await prepareArweaveTransaction(fileContents, contentHash);
|
|
36
|
+
uploads.push({
|
|
37
|
+
itemPropertyName: itemImageProperty.propertyName,
|
|
38
|
+
itemPropertyLocalId: itemImageProperty.localId,
|
|
39
|
+
seedLocalId: itemImageProperty.seedLocalId,
|
|
40
|
+
versionLocalId: itemImageProperty.versionLocalId,
|
|
41
|
+
transactionToSign: transaction,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return uploads;
|
|
45
|
+
};
|
|
22
46
|
const processUploadProperty = async (uploadProperty, uploads, relatedItemProperty) => {
|
|
23
47
|
const itemProperty = uploadProperty.itemProperty;
|
|
24
48
|
const childUploads = [];
|
|
@@ -75,13 +99,18 @@ const processUploadProperty = async (uploadProperty, uploads, relatedItemPropert
|
|
|
75
99
|
}
|
|
76
100
|
compositeFileContents += `${separator}${childUpload.propertyName}${separator}${childUploadContents}`;
|
|
77
101
|
}
|
|
78
|
-
|
|
102
|
+
if (typeof document !== 'undefined') {
|
|
103
|
+
fileContents = new TextEncoder().encode(compositeFileContents);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
fileContents = Buffer.from(compositeFileContents);
|
|
107
|
+
}
|
|
79
108
|
}
|
|
80
109
|
if (!fileContents) {
|
|
81
110
|
throw new Error(`No file contents found for ${itemProperty.propertyName}`);
|
|
82
111
|
}
|
|
83
112
|
const uint8Array = new Uint8Array(fileContents.buffer, fileContents.byteOffset, fileContents.byteLength);
|
|
84
|
-
const contentHash = await getContentHash(
|
|
113
|
+
const contentHash = await getContentHash(uint8Array);
|
|
85
114
|
transaction = await prepareArweaveTransaction(fileContents, contentHash);
|
|
86
115
|
let itemPropertyLocalId = relatedItemProperty
|
|
87
116
|
? relatedItemProperty.localId
|
|
@@ -107,10 +136,12 @@ const getPublishUploads = async (item, uploads = [], relatedItemProperty) => {
|
|
|
107
136
|
// ]
|
|
108
137
|
// }
|
|
109
138
|
// }
|
|
110
|
-
const { itemUploadProperties, itemRelationProperties } = getSegmentedItemProperties(item);
|
|
139
|
+
const { itemUploadProperties, itemRelationProperties, itemImageProperties } = getSegmentedItemProperties(item);
|
|
111
140
|
for (const uploadProperty of itemUploadProperties) {
|
|
112
141
|
uploads = await processUploadProperty(uploadProperty, uploads, relatedItemProperty);
|
|
113
142
|
}
|
|
143
|
+
const imageUploads = await getImageUploads(itemImageProperties);
|
|
144
|
+
uploads.push(...imageUploads);
|
|
114
145
|
for (const relationProperty of itemRelationProperties) {
|
|
115
146
|
const propertyValue = relationProperty.getService().getSnapshot()
|
|
116
147
|
.context.propertyValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPublishUploads.js","sources":["../../../../../src/db/read/getPublishUploads.ts"],"sourcesContent":["import Transaction from 'arweave'\nimport { CreateTransactionInterface } from 'arweave/web'\nimport { getArweave } from '@/helpers/ArweaveClient'\nimport { BaseFileManager, getCorrectId } from '@/helpers'\nimport { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'\nimport debug from 'debug'\nimport { IItem, IItemProperty } from '@/interfaces'\nimport { getContentHash } from '@/helpers'\nimport { BaseItem } from '@/Item/BaseItem'\nconst logger = debug('seedSdk:item:getPublishUploads')\n\n\nexport const prepareArweaveTransaction = async (\n data: string | Uint8Array,\n contentHash: string | undefined,\n): Promise<Transaction> => {\n const transactionData: Partial<CreateTransactionInterface> = {\n data,\n tags: [],\n }\n\n const tx = await getArweave()!.createTransaction(transactionData)\n\n if (contentHash) {\n logger('contentHash', contentHash)\n logger('adding content hash tag to tx.id:', tx.id)\n tx.addTag('Content-SHA-256', contentHash)\n }\n\n return tx\n}\nexport type UploadProperty = {\n itemProperty: IItemProperty<any>\n childProperties: IItemProperty<any>[]\n}\ntype ChildUploadData = {\n propertyName: string\n localStoragePath: string\n}\nconst processUploadProperty = async (\n uploadProperty: UploadProperty,\n uploads: PublishUpload[],\n relatedItemProperty?: IItemProperty<any>,\n): Promise<PublishUpload[]> => {\n const itemProperty = uploadProperty.itemProperty\n\n const childUploads: ChildUploadData[] = []\n\n for (const childProperty of uploadProperty.childProperties) {\n const filePath = childProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n continue\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n continue\n }\n\n childUploads.push({\n propertyName: childProperty.propertyName,\n localStoragePath: filePath,\n })\n }\n\n let fileContents\n let transaction: Transaction\n\n if (!childUploads || childUploads.length === 0) {\n if (relatedItemProperty && relatedItemProperty.localStoragePath) {\n const filePath = relatedItemProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n return uploads\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n return uploads\n\n }\n\n try {\n fileContents = await BaseFileManager.readFileAsString(filePath)\n } catch (e) {\n const fs = await BaseFileManager.getFs()\n fileContents = fs.readFileSync(filePath)\n }\n }\n if (!fileContents) {\n return uploads\n }\n }\n\n if (childUploads.length > 0) {\n const separator = '===FILE_SEPARATOR==='\n // let compositeFileContents = `${itemProperty.propertyName}${separator}${mainFileContents}`\n let compositeFileContents = ''\n\n for (const childUpload of childUploads) {\n let childUploadContents\n\n const fs = await BaseFileManager.getFs()\n\n try {\n childUploadContents = await fs.promises.readFile(\n childUpload.localStoragePath,\n )\n } catch (e) {\n childUploadContents = fs.readFileSync(childUpload.localStoragePath)\n }\n\n compositeFileContents += `${separator}${childUpload.propertyName}${separator}${childUploadContents}`\n }\n\n fileContents = Buffer.from(compositeFileContents)\n }\n\n if (!fileContents) {\n throw new Error(`No file contents found for ${itemProperty.propertyName}`)\n }\n\n const uint8Array = new Uint8Array(\n fileContents.buffer,\n fileContents.byteOffset,\n fileContents.byteLength,\n )\n\n const contentHash = await getContentHash(null, uint8Array)\n\n transaction = await prepareArweaveTransaction(fileContents, contentHash)\n\n let itemPropertyLocalId = relatedItemProperty\n ? relatedItemProperty.localId\n : itemProperty.localId\n let itemPropertyName = relatedItemProperty\n ? relatedItemProperty.propertyName\n : itemProperty.propertyName\n\n uploads.push({\n itemPropertyName,\n itemPropertyLocalId,\n seedLocalId: itemProperty.seedLocalId!,\n versionLocalId: itemProperty.versionLocalId!,\n transactionToSign: transaction,\n })\n\n return uploads\n}\nexport type PublishUpload = {\n itemPropertyName: string\n itemPropertyLocalId: string\n seedLocalId: string\n versionLocalId: string\n transactionToSign: Transaction\n}\nexport const getPublishUploads = async (\n item: IItem<any>,\n uploads: PublishUpload[] = [],\n relatedItemProperty?: IItemProperty<any>,\n) => {\n // if (item.modelName === 'Post') {\n // if (!item.authors) {\n // item.authors = [\n // 'Sr0bIx9Fwj',\n // '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',\n // ]\n // }\n // }\n\n const { itemUploadProperties, itemRelationProperties } =\n getSegmentedItemProperties(item)\n\n for (const uploadProperty of itemUploadProperties) {\n uploads = await processUploadProperty(\n uploadProperty,\n uploads,\n relatedItemProperty,\n )\n }\n\n for (const relationProperty of itemRelationProperties) {\n const propertyValue = relationProperty.getService().getSnapshot()\n .context.propertyValue\n\n if (!propertyValue || relationProperty.uid) {\n continue\n }\n\n const { localId: seedLocalId, uid: seedUid } = getCorrectId(propertyValue)\n\n const relatedItem = await BaseItem.find({\n seedLocalId,\n seedUid,\n })\n\n if (!relatedItem) {\n throw new Error(\n `No relatedItem found for ${relationProperty.propertyName}`,\n )\n }\n\n uploads = await getPublishUploads(relatedItem, uploads, relationProperty)\n }\n\n return uploads\n}\n"],"names":[],"mappings":";;;;;;;AASA,MAAM,MAAM,GAAG,KAAK,CAAC,gCAAgC,CAAC;AAGzC,MAAA,yBAAyB,GAAG,OACvC,IAAyB,EACzB,WAA+B,KACP;AACxB,IAAA,MAAM,eAAe,GAAwC;QAC3D,IAAI;AACJ,QAAA,IAAI,EAAE,EAAE;KACT;IAED,MAAM,EAAE,GAAG,MAAM,UAAU,EAAG,CAAC,iBAAiB,CAAC,eAAe,CAAC;IAEjE,IAAI,WAAW,EAAE;AACf,QAAA,MAAM,CAAC,aAAa,EAAE,WAAW,CAAC;AAClC,QAAA,MAAM,CAAC,mCAAmC,EAAE,EAAE,CAAC,EAAE,CAAC;AAClD,QAAA,EAAE,CAAC,MAAM,CAAC,iBAAiB,EAAE,WAAW,CAAC;;AAG3C,IAAA,OAAO,EAAE;AACX;AASA,MAAM,qBAAqB,GAAG,OAC5B,cAA8B,EAC9B,OAAwB,EACxB,mBAAwC,KACZ;AAC5B,IAAA,MAAM,YAAY,GAAG,cAAc,CAAC,YAAY;IAEhD,MAAM,YAAY,GAAsB,EAAE;AAE1C,IAAA,KAAK,MAAM,aAAa,IAAI,cAAc,CAAC,eAAe,EAAE;AAC1D,QAAA,MAAM,QAAQ,GAAG,aAAa,CAAC,gBAAgB;QAE/C,IAAI,CAAC,QAAQ,IAAI,Q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AAG,OAC/B,IAAgB,EAChB,OAA2B,GAAA,EAAE,EAC7B,mBAAwC,KACtC;;;;;;;;;IAUF,MAAM,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,GACpD,0BAA0B,CAAC,IAAI,CAAC;AAElC,IAAA,KAAK,MAAM,cAAc,IAAI,oBAAoB,EAAE;QACjD,OAAO,GAAG,MAAM,qBAAqB,CACnC,cAAc,EACd,OAAO,EACP,mBAAmB,CACpB;;AAGH,IAAA,KAAK,MAAM,gBAAgB,IAAI,sBAAsB,EAAE;QACrD,MAAM,aAAa,GAAG,gBAAgB,CAAC,UAAU,EAAE,CAAC,WAAW;aAC5D,OAAO,CAAC,aAAa;AAExB,QAAA,IAAI,CAAC,aAAa,IAAI,gBAAgB,CAAC,GAAG,EAAE;YAC1C;;AAGF,QAAA,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC,aAAa,CAAC;AAE1E,QAAA,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC;YACtC,WAAW;YACX,OAAO;AACR,SAAA,CAAC;QAEF,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,KAAK,CACb,CAAA,yBAAA,EAA4B,gBAAgB,CAAC,YAAY,CAAE,CAAA,CAC5D;;QAGH,OAAO,GAAG,MAAM,iBAAiB,CAAC,WAAW,EAAE,OAAO,EAAE,gBAAgB,CAAC;;AAG3E,IAAA,OAAO,OAAO;AAChB;;;;"}
|
|
1
|
+
{"version":3,"file":"getPublishUploads.js","sources":["../../../../../src/db/read/getPublishUploads.ts"],"sourcesContent":["import Transaction from 'arweave'\nimport { CreateTransactionInterface } from 'arweave/web'\nimport { getArweave } from '@/helpers/ArweaveClient'\nimport { BaseFileManager, getCorrectId } from '@/helpers'\nimport { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'\nimport debug from 'debug'\nimport { IItem, IItemProperty } from '@/interfaces'\nimport { getContentHash } from '@/helpers'\nimport { BaseItem } from '@/Item/BaseItem'\nconst logger = debug('seedSdk:item:getPublishUploads')\n\n\nexport const prepareArweaveTransaction = async (\n data: string | Uint8Array,\n contentHash: string | undefined,\n): Promise<Transaction> => {\n const transactionData: Partial<CreateTransactionInterface> = {\n data,\n tags: [],\n }\n\n const tx = await getArweave()!.createTransaction(transactionData)\n\n if (contentHash) {\n logger('contentHash', contentHash)\n logger('adding content hash tag to tx.id:', tx.id)\n tx.addTag('Content-SHA-256', contentHash)\n }\n\n return tx\n}\n\n\nconst getImageUploads = async (itemImageProperties: IItemProperty<any>[]) => {\n const uploads: PublishUpload[] = []\n\n for (const itemImageProperty of itemImageProperties) {\n\n const filePath = `/files/images/${itemImageProperty.refResolvedValue}`\n\n if (!filePath) {\n continue\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n continue\n }\n\n const fileContents = await BaseFileManager.readFileAsString(filePath)\n\n const contentHash = await getContentHash(fileContents)\n\n const transaction = await prepareArweaveTransaction(fileContents, contentHash)\n\n uploads.push({\n itemPropertyName: itemImageProperty.propertyName,\n itemPropertyLocalId: itemImageProperty.localId,\n seedLocalId: itemImageProperty.seedLocalId!,\n versionLocalId: itemImageProperty.versionLocalId!,\n transactionToSign: transaction,\n })\n }\n\n return uploads\n}\n\n\nexport type UploadProperty = {\n itemProperty: IItemProperty<any>\n childProperties: IItemProperty<any>[]\n}\ntype ChildUploadData = {\n propertyName: string\n localStoragePath: string\n}\nconst processUploadProperty = async (\n uploadProperty: UploadProperty,\n uploads: PublishUpload[],\n relatedItemProperty?: IItemProperty<any>,\n): Promise<PublishUpload[]> => {\n const itemProperty = uploadProperty.itemProperty\n\n const childUploads: ChildUploadData[] = []\n\n for (const childProperty of uploadProperty.childProperties) {\n const filePath = childProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n continue\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n continue\n }\n\n childUploads.push({\n propertyName: childProperty.propertyName,\n localStoragePath: filePath,\n })\n }\n\n let fileContents\n let transaction: Transaction\n\n if (!childUploads || childUploads.length === 0) {\n if (relatedItemProperty && relatedItemProperty.localStoragePath) {\n const filePath = relatedItemProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n return uploads\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n return uploads\n\n }\n\n try {\n fileContents = await BaseFileManager.readFileAsString(filePath)\n } catch (e) {\n const fs = await BaseFileManager.getFs()\n fileContents = fs.readFileSync(filePath)\n }\n }\n if (!fileContents) {\n return uploads\n }\n }\n\n if (childUploads.length > 0) {\n const separator = '===FILE_SEPARATOR==='\n // let compositeFileContents = `${itemProperty.propertyName}${separator}${mainFileContents}`\n let compositeFileContents = ''\n\n for (const childUpload of childUploads) {\n let childUploadContents\n\n const fs = await BaseFileManager.getFs()\n\n try {\n childUploadContents = await fs.promises.readFile(\n childUpload.localStoragePath,\n )\n } catch (e) {\n childUploadContents = fs.readFileSync(childUpload.localStoragePath)\n }\n\n compositeFileContents += `${separator}${childUpload.propertyName}${separator}${childUploadContents}`\n }\n\n if (typeof document !== 'undefined') {\n fileContents = new TextEncoder().encode(compositeFileContents)\n } else {\n fileContents = Buffer.from(compositeFileContents)\n }\n }\n\n if (!fileContents) {\n throw new Error(`No file contents found for ${itemProperty.propertyName}`)\n }\n\n const uint8Array = new Uint8Array(\n fileContents.buffer,\n fileContents.byteOffset,\n fileContents.byteLength,\n )\n\n const contentHash = await getContentHash(uint8Array)\n\n transaction = await prepareArweaveTransaction(fileContents, contentHash)\n\n let itemPropertyLocalId = relatedItemProperty\n ? relatedItemProperty.localId\n : itemProperty.localId\n let itemPropertyName = relatedItemProperty\n ? relatedItemProperty.propertyName\n : itemProperty.propertyName\n\n uploads.push({\n itemPropertyName,\n itemPropertyLocalId,\n seedLocalId: itemProperty.seedLocalId!,\n versionLocalId: itemProperty.versionLocalId!,\n transactionToSign: transaction,\n })\n\n return uploads\n}\n\n\nexport type PublishUpload = {\n itemPropertyName: string\n itemPropertyLocalId: string\n seedLocalId: string\n versionLocalId: string\n transactionToSign: Transaction\n}\nexport const getPublishUploads = async (\n item: IItem<any>,\n uploads: PublishUpload[] = [],\n relatedItemProperty?: IItemProperty<any>,\n) => {\n // if (item.modelName === 'Post') {\n // if (!item.authors) {\n // item.authors = [\n // 'Sr0bIx9Fwj',\n // '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',\n // ]\n // }\n // }\n\n const { itemUploadProperties, itemRelationProperties, itemImageProperties } =\n getSegmentedItemProperties(item)\n\n for (const uploadProperty of itemUploadProperties) {\n uploads = await processUploadProperty(\n uploadProperty,\n uploads,\n relatedItemProperty,\n )\n }\n\n const imageUploads = await getImageUploads(itemImageProperties)\n uploads.push(...imageUploads)\n\n for (const relationProperty of itemRelationProperties) {\n const propertyValue = relationProperty.getService().getSnapshot()\n .context.propertyValue\n\n if (!propertyValue || relationProperty.uid) {\n continue\n }\n\n const { localId: seedLocalId, uid: seedUid } = getCorrectId(propertyValue)\n\n const relatedItem = await BaseItem.find({\n seedLocalId,\n seedUid,\n })\n\n if (!relatedItem) {\n throw new Error(\n `No relatedItem found for ${relationProperty.propertyName}`,\n )\n }\n\n uploads = await getPublishUploads(relatedItem, uploads, relationProperty)\n }\n\n return uploads\n}\n"],"names":[],"mappings":";;;;;;;AASA,MAAM,MAAM,GAAG,KAAK,CAAC,gCAAgC,CAAC;AAGzC,MAAA,yBAAyB,GAAG,OACvC,IAAyB,EACzB,WAA+B,KACP;AACxB,IAAA,MAAM,eAAe,GAAwC;QAC3D,IAAI;AACJ,QAAA,IAAI,EAAE,EAAE;KACT;IAED,MAAM,EAAE,GAAG,MAAM,UAAU,EAAG,CAAC,iBAAiB,CAAC,eAAe,CAAC;IAEjE,IAAI,WAAW,EAAE;AACf,QAAA,MAAM,CAAC,aAAa,EAAE,WAAW,CAAC;AAClC,QAAA,MAAM,CAAC,mCAAmC,EAAE,EAAE,CAAC,EAAE,C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-
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../../../src/events/files/download.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,8BAA8B;;;mBAa1C,CAAA;AAED,eAAO,MAAM,oCAAoC,
|
|
1
|
+
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../../../src/events/files/download.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,8BAA8B;;;mBAa1C,CAAA;AAED,eAAO,MAAM,oCAAoC,oCAmKhD,CAAA"}
|
|
@@ -145,7 +145,6 @@ const downloadAllFilesBinaryRequestHandler = async () => {
|
|
|
145
145
|
logger(error);
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
console.log('[download] Calling downloadAllFiles with transactionIdsToDownload', transactionIdsToDownload);
|
|
149
148
|
await BaseFileManager.downloadAllFiles({
|
|
150
149
|
transactionIds: transactionIdsToDownload,
|
|
151
150
|
arweaveHost: ARWEAVE_HOST,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.js","sources":["../../../../../src/events/files/download.ts"],"sourcesContent":["import { syncDbFiles } from '@/services/internal/helpers'\nimport { eventEmitter } from '@/eventBus'\nimport { ARWEAVE_HOST } from '@/services/internal/constants'\nimport { appState } from '@/seedSchema'\nimport { eq } from 'drizzle-orm'\nimport { getAddressesFromDb } from '@/helpers/db'\nimport {\n BaseFileManager,\n} from '@/helpers'\nimport { GET_FILES_METADATA } from '@/schema/file/queries'\nimport debug from 'debug'\nimport { getGlobalService } from '@/services/global/globalMachine'\nimport { waitFor } from 'xstate'\nimport { getMetadata } from '@/db/read/getMetadata'\nimport { saveMetadata } from '@/db/write/saveMetadata'\nimport { GET_TRANSACTION_TAGS } from '@/helpers/ArweaveClient/queries'\nimport { saveAppState } from '@/db/write/saveAppState'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { BaseEasClient, BaseQueryClient, BaseArweaveClient } from '@/helpers'\nimport { getArweave } from '@/helpers/ArweaveClient'\nimport { isBrowser } from '@/helpers/environment'\n\n\nconst logger = debug('seedSdk:files:download')\n\n\nexport const downloadAllFilesRequestHandler = async ({\n endpoints,\n eventId,\n}) => {\n\n if (!isBrowser()) {\n return\n }\n\n await syncDbFiles(endpoints)\n\n eventEmitter.emit('fs.downloadAll.success', { eventId })\n eventEmitter.emit('fs.downloadAllBinary.request', { endpoints })\n}\n\nexport const downloadAllFilesBinaryRequestHandler = async () => {\n let addresses: string[] | undefined\n\n if (BaseDb.isAppDbReady()) {\n addresses = await getAddressesFromDb()\n }\n\n if (!BaseDb.isAppDbReady()) {\n const globalService = getGlobalService()\n const internalService = globalService.getSnapshot().context.internalService\n if (internalService) {\n await waitFor(internalService, (snapshot) => {\n return snapshot.value === 'ready'\n })\n addresses = await getAddressesFromDb()\n }\n }\n\n if (!addresses || addresses.length === 0) {\n return\n }\n\n const queryClient = BaseQueryClient.getQueryClient()\n const easClient = BaseEasClient.getEasClient()\n\n const { filesMetadata } = await queryClient.fetchQuery({\n queryKey: ['getFilesMetadata', ...addresses],\n queryFn: async () =>\n easClient.request(GET_FILES_METADATA, {\n where: {\n attester: {\n in: addresses,\n },\n schema: {\n is: {\n id: {\n equals:\n '0x55fdefb36fcbbaebeb7d6b41dc3a1a9666e4e42154267c889de064faa7ede517',\n },\n },\n },\n },\n }),\n })\n\n await BaseFileManager.createDirIfNotExists('/files')\n await BaseFileManager.createDirIfNotExists('/files/html')\n await BaseFileManager.createDirIfNotExists('/files/json')\n await BaseFileManager.createDirIfNotExists('/files/images')\n\n const appDb = BaseDb.getAppDb()\n\n if (!appDb) {\n console.warn('[fetchAll/actors] [fetchAllBinaryData] seedDb not available')\n return []\n }\n\n const excludedTransactionsQuery = await appDb\n .select()\n .from(appState)\n .where(eq(appState.key, 'excludedTransactions'))\n\n let excludedTransactions = new Set<string>()\n\n if (excludedTransactionsQuery && excludedTransactionsQuery.length === 1) {\n const valueString = excludedTransactionsQuery[0].value\n if (valueString) {\n const excludedTransactionsArray = JSON.parse(valueString)\n excludedTransactions = new Set(excludedTransactionsArray)\n }\n }\n\n const transactionIds = []\n\n for (const fileMetadata of filesMetadata) {\n const json = JSON.parse(fileMetadata.decodedDataJson)\n const transactionId = json[0].value.value\n if (excludedTransactions.has(transactionId)) {\n continue\n }\n transactionIds.push(transactionId)\n }\n\n const arweave = getArweave()\n\n if (!arweave) {\n console.warn(\n '[fetchAll/actors] [fetchAllBinaryData] arweave not available',\n )\n return []\n }\n\n const arweaveClient = BaseArweaveClient.getArweaveClient()\n\n const transactionIdsToDownload = []\n\n for (const transactionId of transactionIds) {\n\n try {\n const res = await fetch(\n `https://${ARWEAVE_HOST}/tx/${transactionId}/status`,\n )\n\n if (res.status !== 200) {\n logger(\n `[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`,\n )\n\n excludedTransactions.add(transactionId)\n\n await saveAppState(\n 'excludedTransactions',\n JSON.stringify(Array.from(excludedTransactions)),\n )\n\n continue\n }\n \n const { tags: tagsResult } = await queryClient.fetchQuery({\n queryKey: ['getTransactionTags', transactionId],\n queryFn: async () =>\n arweaveClient.request(GET_TRANSACTION_TAGS, {\n transactionId,\n }),\n })\n\n const tags = tagsResult.tags || []\n\n if (tagsResult.tags && tagsResult.tags.length > 0) {\n for (const { name, value } of tags) {\n if (name === 'Content-SHA-256') {\n const metadataRecord = await getMetadata({\n storageTransactionId: transactionId,\n })\n\n if (metadataRecord) {\n await saveMetadata(metadataRecord, {\n contentHash: value,\n })\n }\n }\n }\n }\n\n transactionIdsToDownload.push(transactionId)\n\n \n\n } catch (error) {\n logger(error)\n }\n }\n\n
|
|
1
|
+
{"version":3,"file":"download.js","sources":["../../../../../src/events/files/download.ts"],"sourcesContent":["import { syncDbFiles } from '@/services/internal/helpers'\nimport { eventEmitter } from '@/eventBus'\nimport { ARWEAVE_HOST } from '@/services/internal/constants'\nimport { appState } from '@/seedSchema'\nimport { eq } from 'drizzle-orm'\nimport { getAddressesFromDb } from '@/helpers/db'\nimport {\n BaseFileManager,\n} from '@/helpers'\nimport { GET_FILES_METADATA } from '@/schema/file/queries'\nimport debug from 'debug'\nimport { getGlobalService } from '@/services/global/globalMachine'\nimport { waitFor } from 'xstate'\nimport { getMetadata } from '@/db/read/getMetadata'\nimport { saveMetadata } from '@/db/write/saveMetadata'\nimport { GET_TRANSACTION_TAGS } from '@/helpers/ArweaveClient/queries'\nimport { saveAppState } from '@/db/write/saveAppState'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { BaseEasClient, BaseQueryClient, BaseArweaveClient } from '@/helpers'\nimport { getArweave } from '@/helpers/ArweaveClient'\nimport { isBrowser } from '@/helpers/environment'\n\n\nconst logger = debug('seedSdk:files:download')\n\n\nexport const downloadAllFilesRequestHandler = async ({\n endpoints,\n eventId,\n}) => {\n\n if (!isBrowser()) {\n return\n }\n\n await syncDbFiles(endpoints)\n\n eventEmitter.emit('fs.downloadAll.success', { eventId })\n eventEmitter.emit('fs.downloadAllBinary.request', { endpoints })\n}\n\nexport const downloadAllFilesBinaryRequestHandler = async () => {\n let addresses: string[] | undefined\n\n if (BaseDb.isAppDbReady()) {\n addresses = await getAddressesFromDb()\n }\n\n if (!BaseDb.isAppDbReady()) {\n const globalService = getGlobalService()\n const internalService = globalService.getSnapshot().context.internalService\n if (internalService) {\n await waitFor(internalService, (snapshot) => {\n return snapshot.value === 'ready'\n })\n addresses = await getAddressesFromDb()\n }\n }\n\n if (!addresses || addresses.length === 0) {\n return\n }\n\n const queryClient = BaseQueryClient.getQueryClient()\n const easClient = BaseEasClient.getEasClient()\n\n const { filesMetadata } = await queryClient.fetchQuery({\n queryKey: ['getFilesMetadata', ...addresses],\n queryFn: async () =>\n easClient.request(GET_FILES_METADATA, {\n where: {\n attester: {\n in: addresses,\n },\n schema: {\n is: {\n id: {\n equals:\n '0x55fdefb36fcbbaebeb7d6b41dc3a1a9666e4e42154267c889de064faa7ede517',\n },\n },\n },\n },\n }),\n })\n\n await BaseFileManager.createDirIfNotExists('/files')\n await BaseFileManager.createDirIfNotExists('/files/html')\n await BaseFileManager.createDirIfNotExists('/files/json')\n await BaseFileManager.createDirIfNotExists('/files/images')\n\n const appDb = BaseDb.getAppDb()\n\n if (!appDb) {\n console.warn('[fetchAll/actors] [fetchAllBinaryData] seedDb not available')\n return []\n }\n\n const excludedTransactionsQuery = await appDb\n .select()\n .from(appState)\n .where(eq(appState.key, 'excludedTransactions'))\n\n let excludedTransactions = new Set<string>()\n\n if (excludedTransactionsQuery && excludedTransactionsQuery.length === 1) {\n const valueString = excludedTransactionsQuery[0].value\n if (valueString) {\n const excludedTransactionsArray = JSON.parse(valueString)\n excludedTransactions = new Set(excludedTransactionsArray)\n }\n }\n\n const transactionIds = []\n\n for (const fileMetadata of filesMetadata) {\n const json = JSON.parse(fileMetadata.decodedDataJson)\n const transactionId = json[0].value.value\n if (excludedTransactions.has(transactionId)) {\n continue\n }\n transactionIds.push(transactionId)\n }\n\n const arweave = getArweave()\n\n if (!arweave) {\n console.warn(\n '[fetchAll/actors] [fetchAllBinaryData] arweave not available',\n )\n return []\n }\n\n const arweaveClient = BaseArweaveClient.getArweaveClient()\n\n const transactionIdsToDownload = []\n\n for (const transactionId of transactionIds) {\n\n try {\n const res = await fetch(\n `https://${ARWEAVE_HOST}/tx/${transactionId}/status`,\n )\n\n if (res.status !== 200) {\n logger(\n `[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`,\n )\n\n excludedTransactions.add(transactionId)\n\n await saveAppState(\n 'excludedTransactions',\n JSON.stringify(Array.from(excludedTransactions)),\n )\n\n continue\n }\n \n const { tags: tagsResult } = await queryClient.fetchQuery({\n queryKey: ['getTransactionTags', transactionId],\n queryFn: async () =>\n arweaveClient.request(GET_TRANSACTION_TAGS, {\n transactionId,\n }),\n })\n\n const tags = tagsResult.tags || []\n\n if (tagsResult.tags && tagsResult.tags.length > 0) {\n for (const { name, value } of tags) {\n if (name === 'Content-SHA-256') {\n const metadataRecord = await getMetadata({\n storageTransactionId: transactionId,\n })\n\n if (metadataRecord) {\n await saveMetadata(metadataRecord, {\n contentHash: value,\n })\n }\n }\n }\n }\n\n transactionIdsToDownload.push(transactionId)\n\n \n\n } catch (error) {\n logger(error)\n }\n }\n\n await BaseFileManager.downloadAllFiles({\n transactionIds: transactionIdsToDownload,\n arweaveHost: ARWEAVE_HOST,\n excludedTransactions,\n })\n\n await BaseFileManager.resizeAllImages({\n width: 480,\n height: 480,\n })\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,MAAM,GAAG,KAAK,CAAC,wBAAwB,CAAC;AAGvC,MAAM,8BAA8B,GAAG,OAAO,EACnD,SAAS,EACT,OAAO,GACR,KAAI;AAEH,IAAA,IAAI,CAAC,SAAS,EAAE,EAAE;QAChB;;AAGF,IAAA,MAAM,WAAW,CAAC,SAAS,CAAC;IAE5B,YAAY,CAAC,IAAI,CAAC,wBAAwB,EAAE,EAAE,OAAO,EAAE,CAAC;IACxD,YAAY,CAAC,IAAI,CAAC,8BAA8B,EAAE,EAAE,SAAS,EAAE,CAAC;AAClE;AAEa,MAAA,oCAAoC,GAAG,YAAW;AAC7D,IAAA,IAAI,SAA+B;AAEnC,IAAA,IAAI,MAAM,CAAC,YAAY,EAAE,EAAE;AACzB,QAAA,SAAS,GAAG,MAAM,kBAAkB,EAAE;;AAGxC,IAAA,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE;AAC1B,QAAA,MAAM,aAAa,GAAG,gBAAgB,EAAE;QACxC,MAAM,eAAe,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,eAAe;QAC3E,IAAI,eAAe,EAAE;AACnB,YAAA,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC,QAAQ,KAAI;AAC1C,gBAAA,OAAO,QAAQ,CAAC,KAAK,KAAK,OAAO;AACnC,aAAC,CAAC;AACF,YAAA,SAAS,GAAG,MAAM,kBAAkB,EAAE;;;IAI1C,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,MAAM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Root":"","sources":["../../../../src/events/files/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/events/files/index.ts"],"names":[],"mappings":"AA0DA,eAAO,MAAM,gBAAgB,YAW5B,CAAA;AAED,eAAO,MAAM,mBAAmB,eAE/B,CAAA;AAED,eAAO,MAAM,eAAe,eAE3B,CAAA"}
|
|
@@ -22,7 +22,6 @@ const fsInitHandler = async () => {
|
|
|
22
22
|
// })
|
|
23
23
|
if (isBrowser()) {
|
|
24
24
|
const FileManager = (await import('../../browser/helpers/FileManager.js')).FileManager;
|
|
25
|
-
console.log('FileManager', FileManager);
|
|
26
25
|
BaseFileManager.setPlatformClass(FileManager);
|
|
27
26
|
}
|
|
28
27
|
// if (!isBrowser()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../src/events/files/index.ts"],"sourcesContent":["import { eventEmitter } from '@/eventBus'\nimport { downloadAllFilesBinaryRequestHandler, downloadAllFilesRequestHandler } from './download'\nimport { BaseFileManager } from '@/helpers'\nimport { isBrowser } from '@/helpers/environment'\n\n\nlet isInitialized = false\n\n\nconst fsInitHandler = async () => {\n if ( isInitialized ) {\n eventEmitter.emit('fs.init.response', { success: true })\n return\n }\n\n try {\n\n // console.log('fsInitHandler isBrowser', isBrowser())\n\n // console.log({\n // environment: process.env.NEXT_RUNTIME || 'unknown',\n // isServer: typeof window === 'undefined',\n // nodeEnv: process.env.NODE_ENV,\n // // Log what's available in global scope\n // hasWindow: typeof window !== 'undefined',\n // hasDocument: typeof document !== 'undefined',\n // })\n\n if (\n isBrowser()\n ) {\n const FileManager = (await import('../../browser/helpers/FileManager')).FileManager\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/events/files/index.ts"],"sourcesContent":["import { eventEmitter } from '@/eventBus'\nimport { downloadAllFilesBinaryRequestHandler, downloadAllFilesRequestHandler } from './download'\nimport { BaseFileManager } from '@/helpers'\nimport { isBrowser } from '@/helpers/environment'\n\n\nlet isInitialized = false\n\n\nconst fsInitHandler = async () => {\n if ( isInitialized ) {\n eventEmitter.emit('fs.init.response', { success: true })\n return\n }\n\n try {\n\n // console.log('fsInitHandler isBrowser', isBrowser())\n\n // console.log({\n // environment: process.env.NEXT_RUNTIME || 'unknown',\n // isServer: typeof window === 'undefined',\n // nodeEnv: process.env.NODE_ENV,\n // // Log what's available in global scope\n // hasWindow: typeof window !== 'undefined',\n // hasDocument: typeof document !== 'undefined',\n // })\n\n if (\n isBrowser()\n ) {\n const FileManager = (await import('../../browser/helpers/FileManager')).FileManager\n BaseFileManager.setPlatformClass(FileManager)\n }\n\n // if (!isBrowser()) {\n // await import('@/node/helpers/FileManager')\n // }\n\n await BaseFileManager.initializeFileSystem()\n\n isInitialized = true\n\n eventEmitter.emit('fs.init.response', { success: true })\n } catch ( e ) {\n if ( !isInitialized ) {\n console.error('[fs.init] error initializing fs', e)\n eventEmitter.emit('fs.init.response', {\n success: false,\n error: e,\n })\n }\n // TODO: We can ignore this for now but should figure out if this is being called excessively\n }\n}\n\nlet areReady = false\n\nexport const setupFsListeners = () => {\n eventEmitter.addListener(\n 'fs.downloadAll.request',\n downloadAllFilesRequestHandler,\n )\n eventEmitter.addListener(\n 'fs.downloadAllBinary.request',\n downloadAllFilesBinaryRequestHandler,\n )\n eventEmitter.addListener('fs.init', fsInitHandler)\n areReady = true\n}\n\nexport const areFsListenersReady = () => {\n return areReady\n}\n\nexport const isFsInitialized = () => {\n return isInitialized\n}\n"],"names":[],"mappings":";;;;;;AAMA,IAAI,aAAa,GAAG,KAAK;AAGzB,MAAM,aAAa,GAAG,YAAW;IAC/B,IAAK,aAAa,EAAG;QACnB,YAAY,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACxD;;AAGF,IAAA,IAAI;;;;;;;;;;QAaF,IACE,SAAS,EAAE,EACX;YACA,MAAM,WAAW,GAAG,CAAC,MAAM,OAAO,sCAAmC,CAAC,EAAE,WAAW;AACnF,YAAA,eAAe,CAAC,gBAAgB,CAAC,WAAW,CAAC;;;;;AAO/C,QAAA,MAAM,eAAe,CAAC,oBAAoB,EAAE;QAE5C,aAAa,GAAG,IAAI;QAEpB,YAAY,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;IACxD,OAAQ,CAAC,EAAG;QACZ,IAAK,CAAC,aAAa,EAAG;AACpB,YAAA,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,CAAC,CAAC;AACnD,YAAA,YAAY,CAAC,IAAI,CAAC,kBAAkB,EAAE;AACpC,gBAAA,OAAO,EAAE,KAAK;AACd,gBAAA,KAAK,EAAE,CAAC;AACT,aAAA,CAAC;;;;AAIR,CAAC;AAED,IAAI,QAAQ,GAAG,KAAK;AAEb,MAAM,gBAAgB,GAAG,MAAK;AACnC,IAAA,YAAY,CAAC,WAAW,CACtB,wBAAwB,EACxB,8BAA8B,CAC/B;AACD,IAAA,YAAY,CAAC,WAAW,CACtB,8BAA8B,EAC9B,oCAAoC,CACrC;AACD,IAAA,YAAY,CAAC,WAAW,CAAC,SAAS,EAAE,aAAa,CAAC;IAClD,QAAQ,GAAG,IAAI;AACjB;AAEO,MAAM,mBAAmB,GAAG,MAAK;AACtC,IAAA,OAAO,QAAQ;AACjB;AAEO,MAAM,eAAe,GAAG,MAAK;AAClC,IAAA,OAAO,aAAa;AACtB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncDbWithEas.d.ts","sourceRoot":"","sources":["../../../../src/events/item/syncDbWithEas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,aAAa,EAAuB,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"syncDbWithEas.d.ts","sourceRoot":"","sources":["../../../../src/events/item/syncDbWithEas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,aAAa,EAAuB,MAAM,WAAW,CAAA;AAihBzE,QAAA,MAAM,oBAAoB,EAAE,aAAa,CAAC,GAAG,CAsE5C,CAAA;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAA"}
|