@seedprotocol/sdk 0.4.21 → 0.4.23
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/{ArweaveClient-DxpJnJXU.js → ArweaveClient-DoBABTLW.js} +3 -4
- package/dist/{ArweaveClient-DxpJnJXU.js.map → ArweaveClient-DoBABTLW.js.map} +1 -1
- package/dist/{ArweaveClient-Cz9ZLiEV.js → ArweaveClient-KF_T3NSr.js} +3 -4
- package/dist/{ArweaveClient-Cz9ZLiEV.js.map → ArweaveClient-KF_T3NSr.js.map} +1 -1
- package/dist/{Db-DkTBncAM.js → Db-Cg7Q5gIc.js} +4 -5
- package/dist/{Db-DkTBncAM.js.map → Db-Cg7Q5gIc.js.map} +1 -1
- package/dist/{Db-CXwQVLZv.js → Db-DA_e7Jcc.js} +107 -7
- package/dist/Db-DA_e7Jcc.js.map +1 -0
- package/dist/{EasClient-DjpbHjU9.js → EasClient-B4VivHxM.js} +2 -3
- package/dist/{EasClient-JYkmHxu1.js.map → EasClient-B4VivHxM.js.map} +1 -1
- package/dist/{EasClient-JYkmHxu1.js → EasClient-CVPHYGNP.js} +2 -3
- package/dist/{EasClient-DjpbHjU9.js.map → EasClient-CVPHYGNP.js.map} +1 -1
- package/dist/{FileManager-DHnyb040.js → FileManager-BOxbzROS.js} +18 -3
- package/dist/FileManager-BOxbzROS.js.map +1 -0
- package/dist/{FileManager-CKyoLrBP.js → FileManager-Ba5BCbCL.js} +2 -3
- package/dist/{FileManager-CKyoLrBP.js.map → FileManager-Ba5BCbCL.js.map} +1 -1
- package/dist/{ModelProperty-DWtv9fQr.js → ModelProperty-D6JLRqQW.js} +24 -25
- package/dist/ModelProperty-D6JLRqQW.js.map +1 -0
- package/dist/{PathResolver-Ce4K9acQ.js → PathResolver-D7WqjJCo.js} +2 -3
- package/dist/{PathResolver-Ce4K9acQ.js.map → PathResolver-D7WqjJCo.js.map} +1 -1
- package/dist/{PathResolver-pmw--Ea2.js → PathResolver-DHTAlCzo.js} +2 -3
- package/dist/{PathResolver-pmw--Ea2.js.map → PathResolver-DHTAlCzo.js.map} +1 -1
- package/dist/{QueryClient-unspcsWa.js → QueryClient-B12y2daD.js} +7 -4
- package/dist/QueryClient-B12y2daD.js.map +1 -0
- package/dist/{QueryClient-OUjfvY3g.js → QueryClient-BCxuWg7f.js} +3 -3
- package/dist/QueryClient-BCxuWg7f.js.map +1 -0
- package/dist/{Schema-CqqcEexA.js → Schema-B5_B8nM5.js} +38 -38
- package/dist/{Schema-CqqcEexA.js.map → Schema-B5_B8nM5.js.map} +1 -1
- package/dist/{SchemaValidationService-Cb-b4kpD.js → SchemaValidationService-DXYRdSYa.js} +2 -3
- package/dist/{SchemaValidationService-Cb-b4kpD.js.map → SchemaValidationService-DXYRdSYa.js.map} +1 -1
- package/dist/{backfillMetadataPropertyIds-CRyRez3h.js → backfillMetadataPropertyIds-BWEhAJPS.js} +2 -3
- package/dist/{backfillMetadataPropertyIds-CRyRez3h.js.map → backfillMetadataPropertyIds-BWEhAJPS.js.map} +1 -1
- package/dist/cjs/{ModelProperty-sNx_ZQZX.js → ModelProperty-Ov1_YL9l.js} +17 -18
- package/dist/cjs/{ModelProperty-sNx_ZQZX.js.map → ModelProperty-Ov1_YL9l.js.map} +1 -1
- package/dist/cjs/{Schema-B4RRA-0g.js → Schema-CeG5iRX_.js} +20 -21
- package/dist/cjs/{Schema-B4RRA-0g.js.map → Schema-CeG5iRX_.js.map} +1 -1
- package/dist/cjs/{SchemaValidationService-DCflhpcI.js → SchemaValidationService-C8mdrNnp.js} +2 -3
- package/dist/cjs/{SchemaValidationService-DCflhpcI.js.map → SchemaValidationService-C8mdrNnp.js.map} +1 -1
- package/dist/cjs/{backfillMetadataPropertyIds-DhAXAuSf.js → backfillMetadataPropertyIds-LDYghZxU.js} +2 -3
- package/dist/cjs/{backfillMetadataPropertyIds-DhAXAuSf.js.map → backfillMetadataPropertyIds-LDYghZxU.js.map} +1 -1
- package/dist/cjs/{getItem-lyM2x5pT.js → getItem-CW3BFytl.js} +2 -3
- package/dist/cjs/{getItem-lyM2x5pT.js.map → getItem-CW3BFytl.js.map} +1 -1
- package/dist/cjs/{getPublishPayload-DP2fm4q8.js → getPublishPayload-C0hWIYCX.js} +11 -12
- package/dist/cjs/{getPublishPayload-DP2fm4q8.js.map → getPublishPayload-C0hWIYCX.js.map} +1 -1
- package/dist/cjs/{getPublishUploads-DdVy-5fK.js → getPublishUploads-CMpPR2JJ.js} +39 -7
- package/dist/cjs/getPublishUploads-CMpPR2JJ.js.map +1 -0
- package/dist/cjs/{getSegmentedItemProperties-DtHofn5i.js → getSegmentedItemProperties-B4ao_B1Q.js} +3 -3
- package/dist/cjs/{getSegmentedItemProperties-DtHofn5i.js.map → getSegmentedItemProperties-B4ao_B1Q.js.map} +1 -1
- package/dist/cjs/{index-DTkoTvcq.js → index-Dty7eE10.js} +3 -4
- package/dist/cjs/index-Dty7eE10.js.map +1 -0
- package/dist/cjs/{index-D1qR8xnb.js → index-Far6-WGM.js} +2034 -1118
- package/dist/cjs/index-Far6-WGM.js.map +1 -0
- package/dist/cjs/{ownership-DanM_n8E.js → ownership-TCXiKRY_.js} +2 -3
- package/dist/cjs/{ownership-DanM_n8E.js.map → ownership-TCXiKRY_.js.map} +1 -1
- package/dist/cjs/{property-BQokoaRe.js → property-BT7i8Tl-.js} +4 -5
- package/dist/cjs/{property-BQokoaRe.js.map → property-BT7i8Tl-.js.map} +1 -1
- package/dist/cjs/syncDbWithEas-DUi78csI.js +609 -0
- package/dist/cjs/syncDbWithEas-DUi78csI.js.map +1 -0
- package/dist/db/drizzle/drizzle/0013_eas_sync_processes.sql +12 -0
- package/dist/db/drizzle/drizzle/meta/0013_snapshot.json +1262 -0
- package/dist/db/drizzle/drizzle/meta/_journal.json +7 -0
- package/dist/{getItem-VI3QqdZH.js → getItem-D5_bPYyC.js} +2 -3
- package/dist/{getItem-VI3QqdZH.js.map → getItem-D5_bPYyC.js.map} +1 -1
- package/dist/{getPublishPayload-DpYwi-rd.js → getPublishPayload-DEdHgrgC.js} +14 -15
- package/dist/getPublishPayload-DEdHgrgC.js.map +1 -0
- package/dist/{getPublishUploads-DS2dQ4Ho.js → getPublishUploads-CH72lAID.js} +39 -7
- package/dist/getPublishUploads-CH72lAID.js.map +1 -0
- package/dist/{getSegmentedItemProperties-Bz5B4DSA.js → getSegmentedItemProperties-Cp92QUHQ.js} +3 -3
- package/dist/{getSegmentedItemProperties-Bz5B4DSA.js.map → getSegmentedItemProperties-Cp92QUHQ.js.map} +1 -1
- package/dist/{index-BrD_NNaX.js → index-18lln0cM.js} +2045 -1130
- package/dist/index-18lln0cM.js.map +1 -0
- package/dist/{index-DdzhrbkF.js → index-Bp0ChnQr.js} +3 -2
- package/dist/index-Bp0ChnQr.js.map +1 -0
- package/dist/{index-Cqf_DxkJ.js → index-DB3nZ0lK.js} +3 -4
- package/dist/index-DB3nZ0lK.js.map +1 -0
- package/dist/main.cjs +1 -2
- package/dist/main.cjs.map +1 -1
- package/dist/main.js +16 -42
- package/dist/main.js.map +1 -1
- package/dist/node.js +10 -11
- package/dist/node.js.map +1 -1
- package/dist/{ownership-BK6suksO.js → ownership-D-KsIkxM.js} +2 -3
- package/dist/{ownership-BK6suksO.js.map → ownership-D-KsIkxM.js.map} +1 -1
- package/dist/{property-C63Ddzap.js → property-DViA9nga.js} +6 -7
- package/dist/property-DViA9nga.js.map +1 -0
- package/dist/{queries-BGuWjEqt.js → queries-ANFHy2e0.js} +2 -2
- package/dist/{queries-BGuWjEqt.js.map → queries-ANFHy2e0.js.map} +1 -1
- package/dist/seedSchema/EasSyncProcessSchema.ts +17 -0
- package/dist/seedSchema/index.ts +1 -0
- package/dist/src/Item/Item.d.ts +18 -0
- package/dist/src/Item/Item.d.ts.map +1 -1
- package/dist/src/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/loadOrCreateProperty.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImage.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/propertyMachine.d.ts +4 -1
- package/dist/src/ItemProperty/service/propertyMachine.d.ts.map +1 -1
- package/dist/src/Model/service/modelMachine.d.ts +20 -20
- package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts +2 -2
- package/dist/src/Schema/service/addModelsMachine.d.ts +1 -1
- package/dist/src/Schema/service/schemaMachine.d.ts +55 -55
- package/dist/src/browser/db/drizzleFiles.d.ts +3 -2
- package/dist/src/browser/db/drizzleFiles.d.ts.map +1 -1
- package/dist/src/browser/helpers/QueryClient.d.ts.map +1 -1
- package/dist/src/client/ClientManager.d.ts.map +1 -1
- package/dist/src/client/actors/addModelsToDb.d.ts.map +1 -1
- package/dist/src/client/actors/platformClassesInit.d.ts.map +1 -1
- package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
- package/dist/src/client/constants.d.ts +1 -0
- package/dist/src/client/constants.d.ts.map +1 -1
- package/dist/src/db/read/getPublishPendingDiff.d.ts.map +1 -1
- package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
- package/dist/src/db/write/applyPropertyAttestationUidsFromPublish.d.ts.map +1 -1
- package/dist/src/db/write/easSyncProcess.d.ts +12 -0
- package/dist/src/db/write/easSyncProcess.d.ts.map +1 -0
- package/dist/src/db/write/updateItemPropertyValue.d.ts.map +1 -1
- package/dist/src/eventBus.d.ts +13 -2
- package/dist/src/eventBus.d.ts.map +1 -1
- package/dist/src/events/files/download.d.ts +5 -1
- package/dist/src/events/files/download.d.ts.map +1 -1
- package/dist/src/events/item/easSyncManager.d.ts +71 -0
- package/dist/src/events/item/easSyncManager.d.ts.map +1 -0
- package/dist/src/events/item/index.d.ts.map +1 -1
- package/dist/src/events/item/mergeEasSyncOptions.d.ts +7 -0
- package/dist/src/events/item/mergeEasSyncOptions.d.ts.map +1 -0
- package/dist/src/events/item/syncDbWithEas.d.ts +0 -3
- package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/src/helpers/ArweaveClient/BaseArweaveClient.d.ts +17 -0
- package/dist/src/helpers/ArweaveClient/BaseArweaveClient.d.ts.map +1 -1
- package/dist/src/helpers/ArweaveClient/arweaveL1UploadApi.d.ts +6 -0
- package/dist/src/helpers/ArweaveClient/arweaveL1UploadApi.d.ts.map +1 -1
- package/dist/src/helpers/ArweaveClient/selectReadGateway.d.ts +16 -0
- package/dist/src/helpers/ArweaveClient/selectReadGateway.d.ts.map +1 -0
- package/dist/src/helpers/FileManager/BaseFileManager.d.ts +1 -0
- package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
- package/dist/src/helpers/compareMetadataRowsLatestFirst.d.ts +16 -0
- package/dist/src/helpers/compareMetadataRowsLatestFirst.d.ts.map +1 -0
- package/dist/src/helpers/constants.d.ts +20 -5
- package/dist/src/helpers/constants.d.ts.map +1 -1
- package/dist/src/helpers/environment.d.ts +5 -0
- package/dist/src/helpers/environment.d.ts.map +1 -1
- package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts.map +1 -1
- package/dist/src/helpers/index.d.ts +1 -0
- package/dist/src/helpers/index.d.ts.map +1 -1
- package/dist/src/helpers/readHtmlBodyForStorageSeed.d.ts +8 -0
- package/dist/src/helpers/readHtmlBodyForStorageSeed.d.ts.map +1 -0
- package/dist/src/index.d.ts +7 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/interfaces/IQueryClient.d.ts +4 -0
- package/dist/src/interfaces/IQueryClient.d.ts.map +1 -1
- package/dist/src/node/helpers/QueryClient.d.ts.map +1 -1
- package/dist/src/seedSchema/EasSyncProcessSchema.d.ts +190 -0
- package/dist/src/seedSchema/EasSyncProcessSchema.d.ts.map +1 -0
- package/dist/src/seedSchema/index.d.ts +1 -0
- package/dist/src/seedSchema/index.d.ts.map +1 -1
- package/dist/src/services/write/writeProcessMachine.d.ts +1 -1
- package/dist/src/types/fileManager.d.ts +5 -0
- package/dist/src/types/fileManager.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +3 -2
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/machines.d.ts +1 -1
- package/dist/src/types/machines.d.ts.map +1 -1
- package/dist/src/vite/index.d.ts.map +1 -1
- package/dist/syncDbWithEas-m-_3Ds7d.js +582 -0
- package/dist/syncDbWithEas-m-_3Ds7d.js.map +1 -0
- package/dist/updateSeedRevokedAt-BvAK-Rfh.js +22 -0
- package/dist/updateSeedRevokedAt-BvAK-Rfh.js.map +1 -0
- package/dist/vite.cjs +100 -26
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.js +100 -26
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
- package/dist/Db-CXwQVLZv.js.map +0 -1
- package/dist/FileManager-DHnyb040.js.map +0 -1
- package/dist/ModelProperty-DWtv9fQr.js.map +0 -1
- package/dist/QueryClient-OUjfvY3g.js.map +0 -1
- package/dist/QueryClient-unspcsWa.js.map +0 -1
- package/dist/cjs/getPublishUploads-DdVy-5fK.js.map +0 -1
- package/dist/cjs/index-D1qR8xnb.js.map +0 -1
- package/dist/cjs/index-DTkoTvcq.js.map +0 -1
- package/dist/getPublishPayload-DpYwi-rd.js.map +0 -1
- package/dist/getPublishUploads-DS2dQ4Ho.js.map +0 -1
- package/dist/index-BrD_NNaX.js.map +0 -1
- package/dist/index-Cqf_DxkJ.js.map +0 -1
- package/dist/index-DdzhrbkF.js.map +0 -1
- package/dist/property-C63Ddzap.js.map +0 -1
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import { camelCase, startCase } from 'lodash-es';
|
|
2
|
+
import { p as BaseDb, ae as modelUids, A as models, X as toSnakeCase, s as seeds, ap as getAllAddressesFromDb, q as getGetAdditionalSyncAddresses, aq as getModelSchemasFromEas, ar as getSeedsFromSchemaUids, as as getItemVersionsFromEas, at as getItemPropertiesFromEas, au as pickLatestPropertyAttestationsByRefAndSchema, av as scheduleBulkFilesDownloadFromEasSync, aw as eventEmitter, ax as EAS_SEED_DATA_SYNCED_TO_DB_EVENT, ay as generateId, az as escapeSqliteString, am as versions, a7 as BaseQueryClient, a5 as BaseEasClient, aA as GET_SEEDS, aB as GET_VERSIONS, aC as GET_PROPERTIES, ab as metadata, aD as setSchemaUidForSchemaDefinition, aE as parseEasRelationPropertyName, K as modelPropertiesToObject, ao as getPropertyIdForModelAndName } from './index-18lln0cM.js';
|
|
3
|
+
import { eq, inArray, sql, and } from 'drizzle-orm';
|
|
4
|
+
import pluralize from 'pluralize';
|
|
5
|
+
import { u as updateSeedRevokedAt } from './updateSeedRevokedAt-BvAK-Rfh.js';
|
|
6
|
+
import 'xstate';
|
|
7
|
+
import 'drizzle-orm/sqlite-core';
|
|
8
|
+
import 'nanoid';
|
|
9
|
+
import 'nanoid-dictionary';
|
|
10
|
+
import 'debug';
|
|
11
|
+
import 'ethers';
|
|
12
|
+
import '@sinclair/typebox';
|
|
13
|
+
import 'drizzle-orm/casing';
|
|
14
|
+
import 'rxjs';
|
|
15
|
+
import 'arweave';
|
|
16
|
+
import 'js-sha3';
|
|
17
|
+
|
|
18
|
+
// Dynamic import to break circular dependency: Model -> BaseItem -> ... -> getModelSchemas -> Model
|
|
19
|
+
// import { Model } from '@/Model/Model'
|
|
20
|
+
const schemaStringToModelRecord = new Map();
|
|
21
|
+
const getModelSchemas = async () => {
|
|
22
|
+
// Dynamic import to break circular dependency
|
|
23
|
+
const _mod_0 = await import('./index-18lln0cM.js');
|
|
24
|
+
const _ns_0 = _mod_0.cd;
|
|
25
|
+
const modelMod = _ns_0;
|
|
26
|
+
const { Model } = modelMod;
|
|
27
|
+
const allModels = await Model.all();
|
|
28
|
+
const modelRecords = [];
|
|
29
|
+
const appDb = BaseDb.getAppDb();
|
|
30
|
+
for (const model of allModels) {
|
|
31
|
+
const modelName = model.modelName;
|
|
32
|
+
if (!modelName)
|
|
33
|
+
continue;
|
|
34
|
+
const foundModelQuery = await appDb
|
|
35
|
+
.select({
|
|
36
|
+
id: models.id,
|
|
37
|
+
name: models.name,
|
|
38
|
+
uid: modelUids.uid,
|
|
39
|
+
})
|
|
40
|
+
.from(models)
|
|
41
|
+
.leftJoin(modelUids, eq(models.id, modelUids.modelId))
|
|
42
|
+
.where(eq(models.name, modelName))
|
|
43
|
+
.limit(1);
|
|
44
|
+
if (!foundModelQuery[0]) {
|
|
45
|
+
console.error(`[item/events] [syncDbWithEas] model ${modelName} not found in SDK DB`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const foundModel = {
|
|
49
|
+
id: foundModelQuery[0].id,
|
|
50
|
+
name: foundModelQuery[0].name,
|
|
51
|
+
uid: foundModelQuery[0].uid,
|
|
52
|
+
tableName: pluralize(foundModelQuery[0].name).toLowerCase(),
|
|
53
|
+
};
|
|
54
|
+
modelRecords.push(foundModel);
|
|
55
|
+
if (modelName === 'Seed') {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const schemaString = `bytes32 ${toSnakeCase(modelName)}`;
|
|
59
|
+
schemaStringToModelRecord.set(schemaString, foundModel);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
schemaStringToModelRecord,
|
|
63
|
+
modelRecords,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const createSeeds = async (newSeeds) => {
|
|
68
|
+
const appDb = BaseDb.getAppDb();
|
|
69
|
+
const results = await appDb
|
|
70
|
+
.insert(seeds)
|
|
71
|
+
.values(newSeeds)
|
|
72
|
+
.returning({ uid: seeds.uid });
|
|
73
|
+
const newUids = results.reduce((acc, result) => {
|
|
74
|
+
if (result.uid) {
|
|
75
|
+
acc.push(result.uid);
|
|
76
|
+
}
|
|
77
|
+
return acc;
|
|
78
|
+
}, []);
|
|
79
|
+
return newUids;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const relationValuesToExclude = [
|
|
83
|
+
'0x0000000000000000000000000000000000000000000000000000000000000020',
|
|
84
|
+
];
|
|
85
|
+
const seedUidToLocalId = new Map();
|
|
86
|
+
const seedUidToModelType = new Map();
|
|
87
|
+
const relatedSeedUids = new Set();
|
|
88
|
+
const versionUidToLocalId = new Map();
|
|
89
|
+
const versionUidToSeedUid = new Map();
|
|
90
|
+
const propertyUidToLocalId = new Map();
|
|
91
|
+
const saveEasSeedsToDb = async ({ itemSeeds }) => {
|
|
92
|
+
const appDb = BaseDb.getAppDb();
|
|
93
|
+
const seedUids = itemSeeds.map((seed) => seed.id);
|
|
94
|
+
const existingSeedRecordsRows = await appDb
|
|
95
|
+
.select()
|
|
96
|
+
.from(seeds)
|
|
97
|
+
.where(inArray(seeds.uid, seedUids));
|
|
98
|
+
const existingSeedUids = new Set();
|
|
99
|
+
if (existingSeedRecordsRows && existingSeedRecordsRows.length > 0) {
|
|
100
|
+
for (const row of existingSeedRecordsRows) {
|
|
101
|
+
if (row.uid) {
|
|
102
|
+
existingSeedUids.add(row.uid);
|
|
103
|
+
if (row.localId) {
|
|
104
|
+
seedUidToLocalId.set(row.uid, row.localId);
|
|
105
|
+
}
|
|
106
|
+
if (row.type) {
|
|
107
|
+
seedUidToModelType.set(row.uid, row.type);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const newSeeds = itemSeeds.filter((seed) => !existingSeedUids.has(seed.id));
|
|
113
|
+
// Update existing seeds when attestations are revoked on EAS
|
|
114
|
+
const seedByUid = new Map(itemSeeds.map((s) => [s.id, s]));
|
|
115
|
+
for (const row of existingSeedRecordsRows) {
|
|
116
|
+
if (!row.uid || !row.localId)
|
|
117
|
+
continue;
|
|
118
|
+
const attestation = seedByUid.get(row.uid);
|
|
119
|
+
if (!attestation?.revoked)
|
|
120
|
+
continue;
|
|
121
|
+
if (row.revokedAt != null)
|
|
122
|
+
continue;
|
|
123
|
+
const revokedAt = attestation.revocationTime > 0
|
|
124
|
+
? attestation.revocationTime
|
|
125
|
+
: Math.floor(Date.now() / 1000);
|
|
126
|
+
await updateSeedRevokedAt({ seedLocalId: row.localId, revokedAt });
|
|
127
|
+
}
|
|
128
|
+
if (newSeeds.length === 0) {
|
|
129
|
+
return { seedUidToLocalId, seedUids };
|
|
130
|
+
}
|
|
131
|
+
const newSeedsData = [];
|
|
132
|
+
for (let i = 0; i < newSeeds.length; i++) {
|
|
133
|
+
const seed = newSeeds[i];
|
|
134
|
+
seedUidToModelType.set(seed.id, seed.schema.schemaNames[0].name);
|
|
135
|
+
const seedLocalId = generateId();
|
|
136
|
+
seedUidToLocalId.set(seed.id, seedLocalId);
|
|
137
|
+
const attestationRaw = escapeSqliteString(JSON.stringify(seed));
|
|
138
|
+
const revokedAt = seed.revoked && seed.revocationTime != null && seed.revocationTime > 0
|
|
139
|
+
? seed.revocationTime
|
|
140
|
+
: seed.revoked
|
|
141
|
+
? Math.floor(Date.now() / 1000)
|
|
142
|
+
: undefined;
|
|
143
|
+
newSeedsData.push({
|
|
144
|
+
localId: seedLocalId,
|
|
145
|
+
uid: seed.id,
|
|
146
|
+
schemaUid: seed.schemaId,
|
|
147
|
+
type: seed.schema.schemaNames[0].name,
|
|
148
|
+
publisher: seed.attester,
|
|
149
|
+
createdAt: Date.now(),
|
|
150
|
+
attestationCreatedAt: seed.timeCreated * 1000,
|
|
151
|
+
attestationRaw,
|
|
152
|
+
...(revokedAt !== undefined && { revokedAt }),
|
|
153
|
+
});
|
|
154
|
+
seedUidToLocalId.set(seed.id, seedLocalId);
|
|
155
|
+
}
|
|
156
|
+
const newSeedUids = await createSeeds(newSeedsData);
|
|
157
|
+
return { seedUids: newSeedUids };
|
|
158
|
+
};
|
|
159
|
+
const saveEasVersionsToDb = async ({ itemVersions }) => {
|
|
160
|
+
const versionUids = itemVersions.map((version) => version.id);
|
|
161
|
+
const appDb = BaseDb.getAppDb();
|
|
162
|
+
const existingVersionRecordsRows = await appDb
|
|
163
|
+
.select()
|
|
164
|
+
.from(versions)
|
|
165
|
+
.where(inArray(versions.uid, versionUids));
|
|
166
|
+
const existingVersionUids = new Set();
|
|
167
|
+
if (existingVersionRecordsRows && existingVersionRecordsRows.length > 0) {
|
|
168
|
+
for (const row of existingVersionRecordsRows) {
|
|
169
|
+
if (row.uid) {
|
|
170
|
+
existingVersionUids.add(row.uid);
|
|
171
|
+
if (row.localId) {
|
|
172
|
+
versionUidToLocalId.set(row.uid, row.localId);
|
|
173
|
+
}
|
|
174
|
+
if (row.seedUid) {
|
|
175
|
+
versionUidToSeedUid.set(row.uid, row.seedUid);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const newVersions = itemVersions.filter((version) => !existingVersionUids.has(version.id));
|
|
181
|
+
if (newVersions.length === 0) {
|
|
182
|
+
return { versionUidToLocalId, versionUids };
|
|
183
|
+
}
|
|
184
|
+
let insertVersionsQuery = `INSERT INTO versions (local_id, uid, seed_uid, seed_local_id, seed_type, created_at,
|
|
185
|
+
attestation_created_at,
|
|
186
|
+
attestation_raw, publisher)
|
|
187
|
+
VALUES `;
|
|
188
|
+
for (let i = 0; i < newVersions.length; i++) {
|
|
189
|
+
const version = newVersions[i];
|
|
190
|
+
versionUidToSeedUid.set(version.id, version.refUID);
|
|
191
|
+
const versionLocalId = generateId();
|
|
192
|
+
versionUidToLocalId.set(version.id, versionLocalId);
|
|
193
|
+
const seedUid = versionUidToSeedUid.get(version.id);
|
|
194
|
+
const seedLocalId = seedUidToLocalId.get(seedUid);
|
|
195
|
+
const seedType = seedUidToModelType.get(seedUid);
|
|
196
|
+
const attestationRaw = escapeSqliteString(JSON.stringify(version));
|
|
197
|
+
const publisher = escapeSqliteString(version.attester ?? '');
|
|
198
|
+
const valuesString = `('${versionLocalId}', '${version.id}', '${seedUid}', '${seedLocalId}', '${seedType}', ${Date.now()}, ${version.timeCreated * 1000}, '${attestationRaw}', '${publisher}')`;
|
|
199
|
+
if (i < newVersions.length - 1) {
|
|
200
|
+
insertVersionsQuery += valuesString + ', ';
|
|
201
|
+
}
|
|
202
|
+
if (i === newVersions.length - 1) {
|
|
203
|
+
insertVersionsQuery += valuesString + ';';
|
|
204
|
+
}
|
|
205
|
+
versionUidToLocalId.set(version.id, versionLocalId);
|
|
206
|
+
}
|
|
207
|
+
await appDb.run(sql.raw(insertVersionsQuery));
|
|
208
|
+
return { versionUids };
|
|
209
|
+
};
|
|
210
|
+
const createMetadataRecordsForStorageTransactionId = async (storageTransactionIdProperty, modelSchema) => {
|
|
211
|
+
// Early return if modelSchema is not provided
|
|
212
|
+
if (!modelSchema) {
|
|
213
|
+
console.warn('[item/events] [syncDbWithEas] modelSchema is undefined for storageTransactionIdProperty: ', storageTransactionIdProperty.id);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
// Validate and parse decodedDataJson
|
|
217
|
+
if (!storageTransactionIdProperty.decodedDataJson || storageTransactionIdProperty.decodedDataJson.trim() === '') {
|
|
218
|
+
console.warn('[item/events] [syncDbWithEas] empty decodedDataJson for storageTransactionIdProperty: ', storageTransactionIdProperty.id);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
let parsedData;
|
|
222
|
+
try {
|
|
223
|
+
parsedData = JSON.parse(storageTransactionIdProperty.decodedDataJson);
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
console.warn('[item/events] [syncDbWithEas] failed to parse decodedDataJson for storageTransactionIdProperty: ', storageTransactionIdProperty.id, error);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (!Array.isArray(parsedData) || parsedData.length === 0 || !parsedData[0]?.value) {
|
|
230
|
+
console.warn('[item/events] [syncDbWithEas] invalid decodedDataJson structure for storageTransactionIdProperty: ', storageTransactionIdProperty.id);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const attestationData = parsedData[0].value;
|
|
234
|
+
camelCase(attestationData.name);
|
|
235
|
+
const propertyValue = attestationData.value;
|
|
236
|
+
const itemStorageProperties = new Map();
|
|
237
|
+
for (const [_propertyName, propertyDef] of Object.entries(modelSchema)) {
|
|
238
|
+
if (propertyDef?.storageType && propertyDef.storageType === 'ItemStorage') {
|
|
239
|
+
itemStorageProperties.set(_propertyName, propertyDef);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (itemStorageProperties.size === 0) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const appDb = BaseDb.getAppDb();
|
|
246
|
+
for (const [_propertyName, propertyDef] of itemStorageProperties.entries()) {
|
|
247
|
+
const existingMetadataRecordRows = await appDb
|
|
248
|
+
.select()
|
|
249
|
+
.from(metadata)
|
|
250
|
+
.where(and(eq(metadata.propertyName, _propertyName), eq(metadata.propertyValue, propertyValue), eq(metadata.versionUid, storageTransactionIdProperty.refUID)));
|
|
251
|
+
if (existingMetadataRecordRows && existingMetadataRecordRows.length > 0) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const seedUid = versionUidToSeedUid.get(storageTransactionIdProperty.refUID);
|
|
255
|
+
const seedLocalId = seedUidToLocalId.get(seedUid);
|
|
256
|
+
const versionUid = storageTransactionIdProperty.refUID;
|
|
257
|
+
const versionLocalId = versionUidToLocalId.get(versionUid);
|
|
258
|
+
const modelType = seedUidToModelType.get(seedUid);
|
|
259
|
+
const propertyId = modelType != null
|
|
260
|
+
? await getPropertyIdForModelAndName(modelType, _propertyName)
|
|
261
|
+
: null;
|
|
262
|
+
const propertyLocalId = generateId();
|
|
263
|
+
await appDb.insert(metadata).values({
|
|
264
|
+
localId: propertyLocalId,
|
|
265
|
+
propertyId: propertyId ?? undefined,
|
|
266
|
+
propertyName: _propertyName,
|
|
267
|
+
propertyValue,
|
|
268
|
+
localStorageDir: propertyDef.localStorageDir,
|
|
269
|
+
seedLocalId,
|
|
270
|
+
seedUid,
|
|
271
|
+
versionLocalId,
|
|
272
|
+
versionUid,
|
|
273
|
+
refValueType: 'file',
|
|
274
|
+
refResolvedValue: `${propertyValue}${propertyDef.filenameSuffix}`,
|
|
275
|
+
modelType: seedUidToModelType.get(seedUid),
|
|
276
|
+
createdAt: Date.now(),
|
|
277
|
+
updatedAt: Date.now(),
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
/** Serialize property saves: concurrent `runSyncFromEas` used to hit `isSavingToDb` and return `{}` with no insert. */
|
|
282
|
+
let saveEasPropertiesDbChain = Promise.resolve();
|
|
283
|
+
const saveEasPropertiesToDbBody = async ({ itemProperties, itemSeeds, }) => {
|
|
284
|
+
const propertyUids = itemProperties.map((property) => property.id);
|
|
285
|
+
// Dynamic import to break circular dependency
|
|
286
|
+
const _mod_1 = await import('./index-18lln0cM.js');
|
|
287
|
+
const _ns_1 = _mod_1.cd;
|
|
288
|
+
const modelMod = _ns_1;
|
|
289
|
+
const { Model } = modelMod;
|
|
290
|
+
const allModels = await Model.all();
|
|
291
|
+
const models = Object.fromEntries(allModels.map(m => [m.modelName, m]));
|
|
292
|
+
const appDb = BaseDb.getAppDb();
|
|
293
|
+
const existingMetadataRecordsRows = await appDb
|
|
294
|
+
.select()
|
|
295
|
+
.from(metadata)
|
|
296
|
+
.where(inArray(metadata.uid, propertyUids));
|
|
297
|
+
const existingPropertyRecordsUids = new Set();
|
|
298
|
+
if (existingMetadataRecordsRows && existingMetadataRecordsRows.length > 0) {
|
|
299
|
+
for (const row of existingMetadataRecordsRows) {
|
|
300
|
+
if (row.uid) {
|
|
301
|
+
existingPropertyRecordsUids.add(row.uid);
|
|
302
|
+
if (row.localId) {
|
|
303
|
+
propertyUidToLocalId.set(row.uid, row.localId);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
const newProperties = itemProperties.filter((property) => !existingPropertyRecordsUids.has(property.id));
|
|
309
|
+
if (newProperties.length === 0) {
|
|
310
|
+
return { propertyUidToLocalId, propertyUids };
|
|
311
|
+
}
|
|
312
|
+
let insertPropertiesQuery = `INSERT INTO metadata (local_id, uid, schema_uid, property_id, property_name, property_value,
|
|
313
|
+
eas_data_type, version_uid, version_local_id, seed_uid,
|
|
314
|
+
seed_local_id, model_type, ref_value_type, ref_seed_type,
|
|
315
|
+
ref_schema_uid,
|
|
316
|
+
created_at, attestation_created_at, attestation_raw,
|
|
317
|
+
local_storage_dir, ref_resolved_value, publisher)
|
|
318
|
+
VALUES `;
|
|
319
|
+
for (let i = 0; i < newProperties.length; i++) {
|
|
320
|
+
const property = newProperties[i];
|
|
321
|
+
const propertyLocalId = generateId();
|
|
322
|
+
// Validate and parse decodedDataJson
|
|
323
|
+
if (!property.decodedDataJson || property.decodedDataJson.trim() === '') {
|
|
324
|
+
console.warn('[item/events] [syncDbWithEas] empty decodedDataJson for property: ', property.id);
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
let parsedData;
|
|
328
|
+
try {
|
|
329
|
+
parsedData = JSON.parse(property.decodedDataJson);
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
console.warn('[item/events] [syncDbWithEas] failed to parse decodedDataJson for property: ', property.id, error);
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
if (!Array.isArray(parsedData) || parsedData.length === 0 || !parsedData[0]?.value) {
|
|
336
|
+
console.warn('[item/events] [syncDbWithEas] invalid decodedDataJson structure for property: ', property.id);
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const metadata = parsedData[0].value;
|
|
340
|
+
let propertyNameSnake = metadata.name;
|
|
341
|
+
if (!propertyNameSnake) {
|
|
342
|
+
console.warn('[item/events] [syncDbWithEas] no propertyName found for property: ', property);
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
let isRelation = false;
|
|
346
|
+
let refValueType;
|
|
347
|
+
let refSeedType;
|
|
348
|
+
let refSchemaUid;
|
|
349
|
+
let isList = false;
|
|
350
|
+
const schemaUid = property.schemaId;
|
|
351
|
+
setSchemaUidForSchemaDefinition({
|
|
352
|
+
text: propertyNameSnake,
|
|
353
|
+
schemaUid,
|
|
354
|
+
});
|
|
355
|
+
if ((propertyNameSnake.endsWith('_id') ||
|
|
356
|
+
propertyNameSnake.endsWith('_ids')) &&
|
|
357
|
+
propertyNameSnake !== 'storage_transaction_id' &&
|
|
358
|
+
propertyNameSnake !== 'storage_provider_transaction_id') {
|
|
359
|
+
isRelation = true;
|
|
360
|
+
if (Array.isArray(metadata.value)) {
|
|
361
|
+
isList = true;
|
|
362
|
+
refValueType = 'list';
|
|
363
|
+
const result = parseEasRelationPropertyName(propertyNameSnake);
|
|
364
|
+
if (result) {
|
|
365
|
+
propertyNameSnake = result.propertyName;
|
|
366
|
+
refSeedType = result.modelName;
|
|
367
|
+
}
|
|
368
|
+
metadata.value.forEach((value) => {
|
|
369
|
+
relatedSeedUids.add(value);
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
if (!isList) {
|
|
373
|
+
if (relationValuesToExclude.includes(metadata.value)) {
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
relatedSeedUids.add(metadata.value);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
let propertyValue = metadata.value;
|
|
380
|
+
if (typeof propertyValue !== 'string') {
|
|
381
|
+
propertyValue = JSON.stringify(propertyValue);
|
|
382
|
+
}
|
|
383
|
+
if (isRelation && !isList) {
|
|
384
|
+
const relatedSeed = itemSeeds.find((seed) => seed.id === metadata.value);
|
|
385
|
+
if (relatedSeed && relatedSeed.schema && relatedSeed.schema.schemaNames) {
|
|
386
|
+
refSeedType = relatedSeed.schema.schemaNames[0].name;
|
|
387
|
+
refSchemaUid = relatedSeed.schemaId;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (isRelation && isList) {
|
|
391
|
+
const relatedSeeds = itemSeeds.filter((seed) => metadata.value.includes(seed.id));
|
|
392
|
+
if (relatedSeeds && relatedSeeds.length > 0) {
|
|
393
|
+
refSeedType = relatedSeeds[0].schema.schemaNames[0].name;
|
|
394
|
+
refSchemaUid = relatedSeeds[0].schemaId;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
const propertyName = camelCase(propertyNameSnake);
|
|
398
|
+
propertyValue = escapeSqliteString(propertyValue);
|
|
399
|
+
const easDataType = metadata.type;
|
|
400
|
+
const versionUid = property.refUID;
|
|
401
|
+
const versionLocalId = versionUidToLocalId.get(versionUid);
|
|
402
|
+
const attestationCreatedAt = property.timeCreated * 1000;
|
|
403
|
+
const attestationRaw = escapeSqliteString(JSON.stringify(property));
|
|
404
|
+
const seedUid = versionUidToSeedUid.get(versionUid);
|
|
405
|
+
const seedLocalId = seedUidToLocalId.get(seedUid);
|
|
406
|
+
const modelType = seedUidToModelType.get(seedUid);
|
|
407
|
+
const modelName = startCase(modelType);
|
|
408
|
+
const model = models[modelName];
|
|
409
|
+
const modelSchema = model?.properties ? modelPropertiesToObject(model.properties) : undefined;
|
|
410
|
+
if (propertyNameSnake === 'storage_transaction_id') {
|
|
411
|
+
await createMetadataRecordsForStorageTransactionId(property, modelSchema);
|
|
412
|
+
}
|
|
413
|
+
const propertyId = modelType != null
|
|
414
|
+
? await getPropertyIdForModelAndName(modelType, propertyName)
|
|
415
|
+
: null;
|
|
416
|
+
const propertyIdSql = propertyId != null ? String(propertyId) : 'NULL';
|
|
417
|
+
const publisher = escapeSqliteString(property.attester ?? '');
|
|
418
|
+
const valuesString = `('${propertyLocalId}', '${property.id}',
|
|
419
|
+
'${property.schemaId}', ${propertyIdSql}, '${propertyName}',
|
|
420
|
+
'${propertyValue}', '${easDataType}', '${versionUid}',
|
|
421
|
+
'${versionLocalId}', '${seedUid}', '${seedLocalId}',
|
|
422
|
+
'${modelType}', ${refValueType ? `'${refValueType}'` : 'NULL'},
|
|
423
|
+
${refSeedType ? `'${refSeedType}'` : 'NULL'},
|
|
424
|
+
${refSchemaUid ? `'${refSchemaUid}'` : 'NULL'},
|
|
425
|
+
${Date.now()}, ${attestationCreatedAt}, '${attestationRaw}',
|
|
426
|
+
${'NULL'},
|
|
427
|
+
${'NULL'},
|
|
428
|
+
'${publisher}')`;
|
|
429
|
+
if (i < newProperties.length - 1) {
|
|
430
|
+
insertPropertiesQuery += valuesString + ', ';
|
|
431
|
+
}
|
|
432
|
+
if (i === newProperties.length - 1) {
|
|
433
|
+
insertPropertiesQuery += valuesString + ';';
|
|
434
|
+
}
|
|
435
|
+
propertyUidToLocalId.set(property.id, propertyLocalId);
|
|
436
|
+
}
|
|
437
|
+
if (insertPropertiesQuery.endsWith('VALUES ')) {
|
|
438
|
+
return { propertyUids };
|
|
439
|
+
}
|
|
440
|
+
if (insertPropertiesQuery.endsWith(', ')) {
|
|
441
|
+
insertPropertiesQuery = insertPropertiesQuery.slice(0, -2) + ';';
|
|
442
|
+
}
|
|
443
|
+
await appDb.run(sql.raw(insertPropertiesQuery));
|
|
444
|
+
return { propertyUids };
|
|
445
|
+
};
|
|
446
|
+
const saveEasPropertiesToDb = (params) => {
|
|
447
|
+
const next = saveEasPropertiesDbChain.then(() => saveEasPropertiesToDbBody(params));
|
|
448
|
+
saveEasPropertiesDbChain = next.then(() => undefined, () => undefined);
|
|
449
|
+
return next;
|
|
450
|
+
};
|
|
451
|
+
const getRelatedSeedsAndVersions = async () => {
|
|
452
|
+
BaseQueryClient.getQueryClient();
|
|
453
|
+
const easClient = BaseEasClient.getEasClient();
|
|
454
|
+
const { itemSeeds } = await easClient.request(GET_SEEDS, {
|
|
455
|
+
where: {
|
|
456
|
+
id: {
|
|
457
|
+
in: Array.from(relatedSeedUids),
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
});
|
|
461
|
+
await saveEasSeedsToDb({ itemSeeds });
|
|
462
|
+
const { itemVersions } = await easClient.request(GET_VERSIONS, {
|
|
463
|
+
where: {
|
|
464
|
+
refUID: {
|
|
465
|
+
in: Array.from(relatedSeedUids),
|
|
466
|
+
},
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
await saveEasVersionsToDb({ itemVersions });
|
|
470
|
+
const relatedVersionUids = itemVersions.map((v) => v.id);
|
|
471
|
+
const { itemProperties } = await easClient.request(GET_PROPERTIES, {
|
|
472
|
+
where: {
|
|
473
|
+
refUID: {
|
|
474
|
+
in: relatedVersionUids,
|
|
475
|
+
},
|
|
476
|
+
},
|
|
477
|
+
});
|
|
478
|
+
await saveEasPropertiesToDb({
|
|
479
|
+
itemProperties,
|
|
480
|
+
itemSeeds,
|
|
481
|
+
});
|
|
482
|
+
};
|
|
483
|
+
/**
|
|
484
|
+
* Core sync logic: fetches item attestations from EAS for configured models and given addresses,
|
|
485
|
+
* then saves seeds, versions, and properties to the local DB.
|
|
486
|
+
* Uses owned + watched addresses from DB when addresses are not provided.
|
|
487
|
+
*/
|
|
488
|
+
const runSyncFromEas = async (options) => {
|
|
489
|
+
let addresses = options?.addresses ?? (await getAllAddressesFromDb());
|
|
490
|
+
const additionalGetter = getGetAdditionalSyncAddresses();
|
|
491
|
+
if (additionalGetter) {
|
|
492
|
+
const additional = await additionalGetter();
|
|
493
|
+
if (additional?.length) {
|
|
494
|
+
const seen = new Set(addresses.map((a) => a.toLowerCase()));
|
|
495
|
+
for (const addr of additional) {
|
|
496
|
+
if (addr && !seen.has(addr.toLowerCase())) {
|
|
497
|
+
seen.add(addr.toLowerCase());
|
|
498
|
+
addresses = [...addresses, addr];
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (!addresses || addresses.length === 0) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const appDb = BaseDb.getAppDb();
|
|
507
|
+
const { schemaStringToModelRecord } = await getModelSchemas();
|
|
508
|
+
const modelSchemas = await getModelSchemasFromEas();
|
|
509
|
+
const schemaUids = [];
|
|
510
|
+
for (const modelSchema of modelSchemas) {
|
|
511
|
+
const foundModel = schemaStringToModelRecord.get(modelSchema.schema);
|
|
512
|
+
if (!foundModel) {
|
|
513
|
+
// Skip schemas that don't have a corresponding model in the user's config
|
|
514
|
+
// This can happen with "bytes32 image" if there's no Image model defined
|
|
515
|
+
console.warn(`[item/events] [syncDbWithEas] Model not found for schema ${modelSchema.schema}, skipping`);
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
try {
|
|
519
|
+
await appDb
|
|
520
|
+
.insert(modelUids)
|
|
521
|
+
.values({
|
|
522
|
+
modelId: foundModel.id,
|
|
523
|
+
uid: modelSchema.id,
|
|
524
|
+
})
|
|
525
|
+
.onConflictDoNothing();
|
|
526
|
+
}
|
|
527
|
+
catch (err) {
|
|
528
|
+
// Model may have been deleted by test teardown or another process; skip to avoid unhandled rejection
|
|
529
|
+
const e = err;
|
|
530
|
+
const code = e?.code ?? e?.rawCode ?? e?.cause?.code ?? e?.cause?.rawCode;
|
|
531
|
+
if (code === 'SQLITE_CONSTRAINT_FOREIGNKEY' || code === 787) {
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
throw err;
|
|
535
|
+
}
|
|
536
|
+
schemaUids.push(modelSchema.id);
|
|
537
|
+
}
|
|
538
|
+
// If no schemas were found, skip the rest of the sync process
|
|
539
|
+
// This can happen when models exist but don't have schemas registered in EAS yet
|
|
540
|
+
if (schemaUids.length === 0) {
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
const itemSeeds = await getSeedsFromSchemaUids({
|
|
544
|
+
schemaUids,
|
|
545
|
+
addresses,
|
|
546
|
+
excludeRevoked: false,
|
|
547
|
+
});
|
|
548
|
+
const { seedUids } = await saveEasSeedsToDb({
|
|
549
|
+
itemSeeds,
|
|
550
|
+
});
|
|
551
|
+
const itemVersions = await getItemVersionsFromEas({
|
|
552
|
+
seedUids,
|
|
553
|
+
excludeRevoked: false,
|
|
554
|
+
});
|
|
555
|
+
const { versionUids } = await saveEasVersionsToDb({
|
|
556
|
+
itemVersions,
|
|
557
|
+
});
|
|
558
|
+
const rawProperties = await getItemPropertiesFromEas({
|
|
559
|
+
versionUids,
|
|
560
|
+
excludeRevoked: false,
|
|
561
|
+
});
|
|
562
|
+
const itemProperties = pickLatestPropertyAttestationsByRefAndSchema(rawProperties);
|
|
563
|
+
await saveEasPropertiesToDb({
|
|
564
|
+
itemProperties,
|
|
565
|
+
itemSeeds,
|
|
566
|
+
});
|
|
567
|
+
await getRelatedSeedsAndVersions();
|
|
568
|
+
scheduleBulkFilesDownloadFromEasSync(addresses);
|
|
569
|
+
try {
|
|
570
|
+
const _mod_2 = await import('./index-18lln0cM.js');
|
|
571
|
+
const _ns_2 = _mod_2.ca;
|
|
572
|
+
const itemMod = _ns_2;
|
|
573
|
+
await itemMod.Item.rehydrateCachedItemsFromDbAfterEasSync();
|
|
574
|
+
}
|
|
575
|
+
catch (err) {
|
|
576
|
+
console.warn('[item/events] [syncDbWithEas] rehydrateCachedItemsFromDbAfterEasSync:', err);
|
|
577
|
+
}
|
|
578
|
+
eventEmitter.emit(EAS_SEED_DATA_SYNCED_TO_DB_EVENT);
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
export { runSyncFromEas };
|
|
582
|
+
//# sourceMappingURL=syncDbWithEas-m-_3Ds7d.js.map
|