@seedprotocol/sdk 0.7.4-next.784.g879c6a3 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/dist/{BasePathResolver-DxdS0wJ0.js → BasePathResolver-DrzGVH9L.js} +232 -40
  2. package/dist/BasePathResolver-DrzGVH9L.js.map +1 -0
  3. package/dist/{ClientManager-De-vKHGe.js → ClientManager-Dfu4jcgm.js} +583 -219
  4. package/dist/ClientManager-Dfu4jcgm.js.map +1 -0
  5. package/dist/{Item-cq9VcsAY.js → Item-BUUFuywT.js} +175 -306
  6. package/dist/Item-BUUFuywT.js.map +1 -0
  7. package/dist/{ModelProperty-DuuoFXaC.js → ModelProperty-B6cnRvIz.js} +38 -39
  8. package/dist/ModelProperty-B6cnRvIz.js.map +1 -0
  9. package/dist/{Schema-Dc5EA8Yb.js → Schema-Bf-jOLq0.js} +37 -36
  10. package/dist/{Schema-Dc5EA8Yb.js.map → Schema-Bf-jOLq0.js.map} +1 -1
  11. package/dist/{SchemaValidationService-DViJ056F.js → SchemaValidationService-BNYMacsx.js} +7 -8
  12. package/dist/{SchemaValidationService-DViJ056F.js.map → SchemaValidationService-BNYMacsx.js.map} +1 -1
  13. package/dist/{backfillMetadataPropertyIds-DacVthS5.js → backfillMetadataPropertyIds-C2-s_jUa.js} +4 -5
  14. package/dist/{backfillMetadataPropertyIds-DacVthS5.js.map → backfillMetadataPropertyIds-C2-s_jUa.js.map} +1 -1
  15. package/dist/{configurePlatform-DlZ23w7e.js → configurePlatform-BzfirKuM.js} +3 -4
  16. package/dist/{configurePlatform-DlZ23w7e.js.map → configurePlatform-BzfirKuM.js.map} +1 -1
  17. package/dist/{detachRowsBeforeDelete-YRSZY6dO.js → detachRowsBeforeDelete-B0Daoz9Z.js} +3 -4
  18. package/dist/{detachRowsBeforeDelete-YRSZY6dO.js.map → detachRowsBeforeDelete-B0Daoz9Z.js.map} +1 -1
  19. package/dist/{eas-D_6ptL_F.js → eas-Dq5Kx_Nd.js} +14 -32
  20. package/dist/eas-Dq5Kx_Nd.js.map +1 -0
  21. package/dist/{errors-Cl8rbtKR.js → errors-DdWbxb_n.js} +42 -39
  22. package/dist/errors-DdWbxb_n.js.map +1 -0
  23. package/dist/{getItem-BcmJcUZB.js → getItem-9bYSErSj.js} +4 -5
  24. package/dist/{getItem-BcmJcUZB.js.map → getItem-9bYSErSj.js.map} +1 -1
  25. package/dist/{getPublishPayload-C278kK9P.js → getPublishPayload-DPy-uMrR.js} +28 -29
  26. package/dist/getPublishPayload-DPy-uMrR.js.map +1 -0
  27. package/dist/{getPublishUploads-DJ1UPh7i.js → getPublishUploads-J-143iSV.js} +10 -11
  28. package/dist/{getPublishUploads-DJ1UPh7i.js.map → getPublishUploads-J-143iSV.js.map} +1 -1
  29. package/dist/{index-DAl9U4rn.js → index-7y2f_iQz.js} +2 -2
  30. package/dist/index-7y2f_iQz.js.map +1 -0
  31. package/dist/{index-CqnU-5i0.js → index-C61Rxy0F.js} +9 -10
  32. package/dist/index-C61Rxy0F.js.map +1 -0
  33. package/dist/{index.browser-J6QZ9smP.js → index.browser-C1pisOEa.js} +10 -10
  34. package/dist/{index.browser-J6QZ9smP.js.map → index.browser-C1pisOEa.js.map} +1 -1
  35. package/dist/{index.node-C9VB9NlX.js → index.node-BAlST8pD.js} +6 -6
  36. package/dist/{index.node-C9VB9NlX.js.map → index.node-BAlST8pD.js.map} +1 -1
  37. package/dist/main.js +27 -28
  38. package/dist/main.js.map +1 -1
  39. package/dist/node.js +12 -13
  40. package/dist/node.js.map +1 -1
  41. package/dist/platform.browser.js +6 -7
  42. package/dist/platform.browser.js.map +1 -1
  43. package/dist/platform.node.js +5 -6
  44. package/dist/platform.node.js.map +1 -1
  45. package/dist/{property-Brgr5RdT.js → property-zFPMtR3T.js} +10 -14
  46. package/dist/property-zFPMtR3T.js.map +1 -0
  47. package/dist/{propertyValidationRules-CDRitiiK.js → propertyValidationRules-CeFVhdQg.js} +10 -10
  48. package/dist/{propertyValidationRules-CDRitiiK.js.map → propertyValidationRules-CeFVhdQg.js.map} +1 -1
  49. package/dist/{publishDraftGraph-C37ibxb5.js → publishDraftGraph-CuVq6iAR.js} +7 -6
  50. package/dist/{publishDraftGraph-C37ibxb5.js.map → publishDraftGraph-CuVq6iAR.js.map} +1 -1
  51. package/dist/{resetAmbiguousLegacyItemData-CcLFRREE.js → resetAmbiguousLegacyItemData-DsFTnMBz.js} +5 -6
  52. package/dist/resetAmbiguousLegacyItemData-DsFTnMBz.js.map +1 -0
  53. package/dist/{resolveModelForSyncedSeed-BTAeCOJE.js → resolveModelForSyncedSeed-RUsgAZXG.js} +2 -2
  54. package/dist/{resolveModelForSyncedSeed-BTAeCOJE.js.map → resolveModelForSyncedSeed-RUsgAZXG.js.map} +1 -1
  55. package/dist/src/Item/Item.d.ts.map +1 -1
  56. package/dist/src/ItemProperty/service/propertyMachine.d.ts +4 -4
  57. package/dist/src/Model/Model.d.ts +3 -2
  58. package/dist/src/Model/Model.d.ts.map +1 -1
  59. package/dist/src/ModelProperty/ModelProperty.d.ts +1 -1
  60. package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts +1 -1
  61. package/dist/src/Schema/service/schemaMachine.d.ts +2 -2
  62. package/dist/src/client/ClientManager.d.ts +6 -6
  63. package/dist/src/client/ClientManager.d.ts.map +1 -1
  64. package/dist/src/client/actors/addModelsToDb.d.ts.map +1 -1
  65. package/dist/src/client/actors/saveConfig.d.ts.map +1 -1
  66. package/dist/src/client/clientManagerMachine.d.ts +2 -2
  67. package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
  68. package/dist/src/db/canonicalizeModelTypes.d.ts +18 -0
  69. package/dist/src/db/canonicalizeModelTypes.d.ts.map +1 -0
  70. package/dist/src/db/read/getModelSchemas.d.ts +6 -0
  71. package/dist/src/db/read/getModelSchemas.d.ts.map +1 -1
  72. package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
  73. package/dist/src/db/read/getSchemaUidForModel.d.ts +6 -0
  74. package/dist/src/db/read/getSchemaUidForModel.d.ts.map +1 -1
  75. package/dist/src/db/read/resolveModelRecord.d.ts.map +1 -1
  76. package/dist/src/db/removeForeignAttestationRows.d.ts +27 -0
  77. package/dist/src/db/removeForeignAttestationRows.d.ts.map +1 -0
  78. package/dist/src/db/write/createMetadata.d.ts.map +1 -1
  79. package/dist/src/db/write/easSyncProcess.d.ts +9 -1
  80. package/dist/src/db/write/easSyncProcess.d.ts.map +1 -1
  81. package/dist/src/db/write/updateMetadata.d.ts.map +1 -1
  82. package/dist/src/eas.d.ts.map +1 -1
  83. package/dist/src/events/item/easSyncManager.d.ts.map +1 -1
  84. package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
  85. package/dist/src/helpers/db.d.ts +20 -0
  86. package/dist/src/helpers/db.d.ts.map +1 -1
  87. package/dist/src/helpers/index.d.ts +3 -1
  88. package/dist/src/helpers/index.d.ts.map +1 -1
  89. package/dist/src/helpers/metadataPropertyNames.d.ts +12 -0
  90. package/dist/src/helpers/metadataPropertyNames.d.ts.map +1 -1
  91. package/dist/src/helpers/retryWhenOnline.d.ts +20 -0
  92. package/dist/src/helpers/retryWhenOnline.d.ts.map +1 -0
  93. package/dist/src/imports/json.d.ts +10 -0
  94. package/dist/src/imports/json.d.ts.map +1 -1
  95. package/dist/src/index.d.ts +4 -2
  96. package/dist/src/index.d.ts.map +1 -1
  97. package/dist/src/query/createLocalQueryDataSource.d.ts.map +1 -1
  98. package/dist/src/types/import.d.ts +4 -0
  99. package/dist/src/types/import.d.ts.map +1 -1
  100. package/dist/{syncDbWithEas-B-Ho0IOB.js → syncDbWithEas-CRpnkq00.js} +157 -61
  101. package/dist/syncDbWithEas-CRpnkq00.js.map +1 -0
  102. package/dist/{tabEvents-BTzckWrN.js → tabEvents-nBUq_1u1.js} +6 -6
  103. package/dist/{tabEvents-BTzckWrN.js.map → tabEvents-nBUq_1u1.js.map} +1 -1
  104. package/dist/{tolerantWebAccess-DOm2Xv-f.js → tolerantWebAccess-DIt3R8_u.js} +7 -8
  105. package/dist/{tolerantWebAccess-DOm2Xv-f.js.map → tolerantWebAccess-DIt3R8_u.js.map} +1 -1
  106. package/dist/{updateSeedRevokedAt-IHXnJI-i.js → updateSeedRevokedAt-DtTPSzpM.js} +3 -3
  107. package/dist/{updateSeedRevokedAt-IHXnJI-i.js.map → updateSeedRevokedAt-DtTPSzpM.js.map} +1 -1
  108. package/package.json +5 -5
  109. package/dist/BasePathResolver-DxdS0wJ0.js.map +0 -1
  110. package/dist/ClientManager-De-vKHGe.js.map +0 -1
  111. package/dist/Item-cq9VcsAY.js.map +0 -1
  112. package/dist/ModelProperty-DuuoFXaC.js.map +0 -1
  113. package/dist/eas-D_6ptL_F.js.map +0 -1
  114. package/dist/errors-Cl8rbtKR.js.map +0 -1
  115. package/dist/getPublishPayload-C278kK9P.js.map +0 -1
  116. package/dist/index-CqnU-5i0.js.map +0 -1
  117. package/dist/index-DAl9U4rn.js.map +0 -1
  118. package/dist/property-Brgr5RdT.js.map +0 -1
  119. package/dist/resetAmbiguousLegacyItemData-CcLFRREE.js.map +0 -1
  120. package/dist/syncDbWithEas-B-Ho0IOB.js.map +0 -1
@@ -1,22 +1,21 @@
1
- import { E as BaseDb, r as modelUids, s as models, H as toSnakeCase, X as normalizePublisher, A as seeds, Y as getAllAddressesFromDb, Z as scheduleBulkFilesDownloadFromEasSync, _ as EAS_SEED_DATA_SYNCED_TO_DB_EVENT, $ as generateId, a0 as normalizeHexAddress, C as versions, m as metadata, K as getPropertyIdForModelAndName, L as resolveItemModelFileId, a1 as getItemStoragePropertiesForModel } from './BasePathResolver-DxdS0wJ0.js';
2
- import { r as resolveModelForSyncedSeed, s as skipSeedOnAmbiguousModel } from './resolveModelForSyncedSeed-BTAeCOJE.js';
1
+ import { E as BaseDb, r as modelUids, s as models, X as normalizePublisher, A as seeds, Y as getAllAddressesFromDb, Z as scheduleBulkFilesDownloadFromEasSync, _ as EAS_SEED_DATA_SYNCED_TO_DB_EVENT, $ as generateId, a0 as normalizeHexAddress, C as versions, m as metadata, K as getPropertyIdForModelAndName, L as resolveItemModelFileId, n as normalizeDataType, a1 as listRelationEasPropertyName, a2 as easPropertyNameForPublish, a3 as toMetadataPropertyName, a4 as getItemStoragePropertiesForModel } from './BasePathResolver-DrzGVH9L.js';
2
+ import { r as resolveModelForSyncedSeed, s as skipSeedOnAmbiguousModel } from './resolveModelForSyncedSeed-RUsgAZXG.js';
3
3
  import { camelCase } from 'lodash-es';
4
- import { getSeedsFromSchemaUids, getItemVersionsFromEas, partitionByRefAttester, getItemPropertiesFromEas, BaseEasClient, GET_SEEDS, pickLatestPropertyAttestationsByRefAndSchema, setSchemaUidForSchemaDefinition } from '@seedprotocol/eas';
5
- import { parseEasPropertyMetadata, parseEasRelationPropertyName } from '@seedprotocol/query';
4
+ import { easName, matchEasName, getSeedsFromSchemaUids, getItemVersionsFromEas, partitionByRefAttester, getItemPropertiesFromEas, BaseEasClient, GET_SEEDS, pickLatestPropertyAttestationsByRefAndSchema, setSchemaUidForSchemaDefinition } from '@seedprotocol/eas';
5
+ import pluralize from 'pluralize';
6
6
  import { eq, inArray, and, or, isNull, ne, isNotNull } from 'drizzle-orm';
7
7
  import { modelPropertiesToObject } from './model-oHA3YhOd.js';
8
- import pluralize from 'pluralize';
9
- import { a as chunkValues, b as rowsPerInsert, d as getGetAdditionalSyncAddresses, s as selectInBatches, w as writeInBatches } from './Item-cq9VcsAY.js';
10
- import { u as updateSeedRevokedAt } from './updateSeedRevokedAt-IHXnJI-i.js';
11
- import { getModelSchemasFromEas } from './eas-D_6ptL_F.js';
12
- import { w as waitForEasReadChain, a as assertLocalDbChain } from './ClientManager-De-vKHGe.js';
13
- import { e as emitAcrossTabs } from './tabEvents-BTzckWrN.js';
8
+ import { parseEasPropertyMetadata, parseEasRelationPropertyName } from '@seedprotocol/query';
9
+ import { a as chunkValues, r as rowsPerInsert, b as getGetAdditionalSyncAddresses, s as selectInBatches, w as writeInBatches } from './Item-BUUFuywT.js';
10
+ import { u as updateSeedRevokedAt } from './updateSeedRevokedAt-DtTPSzpM.js';
11
+ import { getModelSchemasFromEas } from './eas-Dq5Kx_Nd.js';
12
+ import { w as waitForEasReadChain, a as assertLocalDbChain } from './ClientManager-Dfu4jcgm.js';
13
+ import { e as emitAcrossTabs } from './tabEvents-nBUq_1u1.js';
14
14
  import 'debug';
15
15
  import '@seedprotocol/arweave';
16
16
  import 'xstate';
17
17
  import '@sinclair/typebox';
18
18
  import 'drizzle-orm/sqlite-core';
19
- import 'drizzle-orm/casing';
20
19
  import 'nanoid';
21
20
  import 'nanoid-dictionary';
22
21
  import '@noble/hashes/sha256';
@@ -29,7 +28,7 @@ import 'rxjs';
29
28
  const schemaStringToModelRecord = new Map();
30
29
  const getModelSchemas = async () => {
31
30
  // Dynamic import to break circular dependency
32
- const _mod_0 = await import('./errors-Cl8rbtKR.js');
31
+ const _mod_0 = await import('./errors-DdWbxb_n.js');
33
32
  const _ns_0 = _mod_0.h;
34
33
  const modelMod = _ns_0;
35
34
  const { Model } = modelMod;
@@ -65,12 +64,26 @@ const getModelSchemas = async () => {
65
64
  if (modelName === 'Seed') {
66
65
  continue;
67
66
  }
68
- const schemaString = `bytes32 ${toSnakeCase(modelName)}`;
67
+ const schemaString = `bytes32 ${easName(modelName)}`;
69
68
  schemaStringToModelRecord.set(schemaString, foundModel);
70
69
  }
70
+ // One candidate per name: same-named models in several schemas share one EAS schema.
71
+ const byName = new Map();
72
+ for (const record of modelRecords) {
73
+ if (record.name !== 'Seed')
74
+ byName.set(record.name, record);
75
+ }
76
+ const candidates = [...byName.values()].map((record) => ({ value: record, name: record.name }));
77
+ const matchModelRecord = (schemaString) => {
78
+ if (!schemaString.startsWith('bytes32 '))
79
+ return undefined;
80
+ const match = matchEasName(schemaString.slice('bytes32 '.length), candidates);
81
+ return match.kind === 'match' ? match.value : undefined;
82
+ };
71
83
  return {
72
84
  schemaStringToModelRecord,
73
85
  modelRecords,
86
+ matchModelRecord,
74
87
  };
75
88
  };
76
89
 
@@ -132,22 +145,100 @@ const createSyncRunState = () => ({
132
145
  const isRelationPropertyName = (propertyNameSnake) => (propertyNameSnake.endsWith('_id') || propertyNameSnake.endsWith('_ids')) &&
133
146
  propertyNameSnake !== 'storage_transaction_id' &&
134
147
  propertyNameSnake !== 'storage_provider_transaction_id';
148
+ const RELATION_DATA_TYPES = new Set(['Relation', 'Image', 'File', 'Html']);
149
+ /**
150
+ * The local property an EAS property name stands for (ADR 0008): matched against the model's
151
+ * properties by the names publish writes for them (exact, then normalized, then fuzzy), not by
152
+ * reversing the EAS name. The row is stored under the name sync has always used for that property:
153
+ * a list relation's schema key, a single relation's `<key>Id`, anything else its key. A relation is
154
+ * whatever the local property is, whatever its EAS name ends in.
155
+ *
156
+ * With no model, or no matching property, the EAS name decides as before (`_id`/`_ids` are
157
+ * relations), so related seeds are still followed for discovery. Undefined: the name matches
158
+ * several local properties equally well, and the attestation is skipped.
159
+ */
160
+ const resolveSyncedPropertyName = (easPropertyName, value, modelSchema) => {
161
+ const internal = easPropertyName === 'storage_transaction_id' || easPropertyName === 'storage_provider_transaction_id';
162
+ if (modelSchema && !internal) {
163
+ const candidates = Object.entries(modelSchema).map(([key, def]) => {
164
+ const dataType = normalizeDataType(def?.dataType);
165
+ const refValueType = normalizeDataType(def?.refValueType);
166
+ const isListRelation = !!listRelationEasPropertyName(key, def);
167
+ const isSingleRef = !isListRelation && (RELATION_DATA_TYPES.has(dataType) || RELATION_DATA_TYPES.has(refValueType));
168
+ return {
169
+ value: { key, def, isListRelation, isSingleRef },
170
+ name: easPropertyNameForPublish(key, { ...def, name: key }),
171
+ relation: isListRelation || isSingleRef,
172
+ };
173
+ });
174
+ const match = matchEasName(easPropertyName, candidates);
175
+ if (match.kind === 'ambiguous') {
176
+ console.warn(`[item/events] [syncDbWithEas] EAS property "${easPropertyName}" matches several local properties (${match.values
177
+ .map((v) => v.key)
178
+ .join(', ')}); skipping it`);
179
+ return undefined;
180
+ }
181
+ if (match.kind === 'match') {
182
+ const { key, def, isListRelation, isSingleRef } = match.value;
183
+ if (isListRelation) {
184
+ return { propertyName: key, isRelation: true, isList: true, refSeedType: def?.ref ? easName(def.ref) : undefined };
185
+ }
186
+ if (isSingleRef) {
187
+ return {
188
+ propertyName: toMetadataPropertyName(key, def?.dataType, def?.refValueType),
189
+ isRelation: true,
190
+ isList: false,
191
+ };
192
+ }
193
+ return { propertyName: key, isRelation: false, isList: false };
194
+ }
195
+ }
196
+ if (!isRelationPropertyName(easPropertyName)) {
197
+ return { propertyName: camelCase(easPropertyName), isRelation: false, isList: false };
198
+ }
199
+ if (Array.isArray(value)) {
200
+ const parsed = parseEasRelationPropertyName(easPropertyName);
201
+ return {
202
+ propertyName: camelCase(parsed?.propertyName ?? easPropertyName),
203
+ isRelation: true,
204
+ isList: true,
205
+ refSeedType: parsed?.modelName,
206
+ };
207
+ }
208
+ return { propertyName: camelCase(easPropertyName), isRelation: true, isList: false };
209
+ };
210
+ /** The local model schema (properties object) of the seed a property attestation belongs to. */
211
+ const modelSchemaForSyncedProperty = async (Model, property, state) => {
212
+ const seedUid = state.versionUidToSeedUid.get(property.refUID);
213
+ const modelType = seedUid ? state.seedUidToModelType.get(seedUid) : undefined;
214
+ if (modelType == null)
215
+ return undefined;
216
+ const seedLocalId = state.seedUidToLocalId.get(seedUid);
217
+ const model = await skipSeedOnAmbiguousModel({ seedLocalId, seedUid }, 'easSync.metadata', async () => resolveSyncedSeedModel(Model, modelType, { seedLocalId, seedUid }));
218
+ return model?.properties ? modelPropertiesToObject(model.properties) : undefined;
219
+ };
135
220
  /**
136
221
  * Seed UIDs that relation properties point at. Collected from every property the run fetched, not
137
222
  * only newly stored ones, so related seeds are refreshed (new versions, revocations) on each sync.
138
223
  */
139
- const collectRelatedSeedUids = (properties, into) => {
224
+ const collectRelatedSeedUids = async (properties, state) => {
225
+ const _mod_1 = await import('./errors-DdWbxb_n.js');
226
+ const _ns_1 = _mod_1.h;
227
+ const { Model } = _ns_1;
140
228
  for (const property of properties) {
141
229
  const parsed = parseEasPropertyMetadata(property.decodedDataJson);
142
230
  if (!parsed.ok)
143
231
  continue;
144
232
  const { name, value } = parsed.metadata;
145
- if (!name || !isRelationPropertyName(name))
233
+ if (!name)
234
+ continue;
235
+ const modelSchema = await modelSchemaForSyncedProperty(Model, property, state);
236
+ if (!resolveSyncedPropertyName(name, value, modelSchema)?.isRelation)
146
237
  continue;
147
238
  const values = Array.isArray(value) ? value : [value];
148
239
  for (const v of values) {
149
240
  if (typeof v === 'string' && v && !relationValuesToExclude.includes(v))
150
- into.add(v);
241
+ state.relatedSeedUids.add(v);
151
242
  }
152
243
  }
153
244
  };
@@ -182,6 +273,23 @@ const isSqlEscapedAttestationRaw = (stored, fresh) => {
182
273
  };
183
274
  return stored === JSON.stringify(withStoredRevocation).replace(/'/g, "''");
184
275
  };
276
+ /**
277
+ * seeds.type for a seed whose EAS model name is `easModelName`: the type of the local model it
278
+ * matches (ADR 0008), so `htmlpage` from an older SDK is stored as `html_page`, the type local seeds
279
+ * of HTMLPage have. A name matching no local model, or several, is kept as it is.
280
+ */
281
+ const localModelType = async (easModelName) => {
282
+ const _mod_2 = await import('./errors-DdWbxb_n.js');
283
+ const _ns_2 = _mod_2.h;
284
+ const { Model } = _ns_2;
285
+ try {
286
+ const model = Model.findByModelType(easModelName);
287
+ return model?.modelName ? easName(model.modelName) : easModelName;
288
+ }
289
+ catch {
290
+ return easModelName;
291
+ }
292
+ };
185
293
  const saveEasSeedsToDb = async ({ itemSeeds, state }) => {
186
294
  const { seedUidToLocalId, seedUidToModelType } = state;
187
295
  const appDb = BaseDb.getAppDb();
@@ -234,7 +342,8 @@ const saveEasSeedsToDb = async ({ itemSeeds, state }) => {
234
342
  const newSeedsData = [];
235
343
  for (let i = 0; i < newSeeds.length; i++) {
236
344
  const seed = newSeeds[i];
237
- seedUidToModelType.set(seed.id, seed.schema.schemaNames[0].name);
345
+ const modelType = await localModelType(seed.schema.schemaNames[0].name);
346
+ seedUidToModelType.set(seed.id, modelType);
238
347
  const seedLocalId = generateId();
239
348
  seedUidToLocalId.set(seed.id, seedLocalId);
240
349
  // createSeeds binds parameters: store the JSON as is.
@@ -243,14 +352,13 @@ const saveEasSeedsToDb = async ({ itemSeeds, state }) => {
243
352
  // EAS only knows the model by name; the seam may match it to a local model (not built yet).
244
353
  const modelFileId = await resolveModelForSyncedSeed({
245
354
  seedUid: seed.id,
246
- modelType: seed.schema.schemaNames[0].name,
247
355
  schemaUid: seed.schemaId,
248
356
  });
249
357
  newSeedsData.push({
250
358
  localId: seedLocalId,
251
359
  uid: seed.id,
252
360
  schemaUid: seed.schemaId,
253
- type: seed.schema.schemaNames[0].name,
361
+ type: modelType,
254
362
  ...(modelFileId && { modelFileId }),
255
363
  publisher: seed.attester ? normalizeHexAddress(seed.attester) : seed.attester,
256
364
  createdAt: Date.now(),
@@ -442,7 +550,7 @@ let saveEasPropertiesDbChain = Promise.resolve();
442
550
  const saveEasPropertiesToDbBody = async ({ fetchedProperties, itemSeeds, state, }) => {
443
551
  const itemProperties = pickLatestPropertyAttestationsByRefAndSchema(fetchedProperties, SYNC_CANONICAL_OPTIONS);
444
552
  const propertyUids = itemProperties.map((property) => property.id);
445
- collectRelatedSeedUids(itemProperties, state.relatedSeedUids);
553
+ await collectRelatedSeedUids(itemProperties, state);
446
554
  const appDb = BaseDb.getAppDb();
447
555
  const storedRows = await selectInBatches(fetchedProperties.map((property) => property.id), (chunk) => appDb
448
556
  .select({ uid: metadata.uid, revokedAt: metadata.revokedAt })
@@ -569,9 +677,9 @@ const resolveSyncedSeedModel = async (Model, modelType, seed) => {
569
677
  const insertSyncedProperties = async ({ newProperties, itemSeeds, state, }) => {
570
678
  const { seedUidToLocalId, seedUidToModelType, versionUidToLocalId, versionUidToSeedUid } = state;
571
679
  // Dynamic import to break circular dependency
572
- const _mod_1 = await import('./errors-Cl8rbtKR.js');
573
- const _ns_1 = _mod_1.h;
574
- const modelMod = _ns_1;
680
+ const _mod_3 = await import('./errors-DdWbxb_n.js');
681
+ const _ns_3 = _mod_3.h;
682
+ const modelMod = _ns_3;
575
683
  const { Model } = modelMod;
576
684
  // Loads every model into Model's cache, where resolveSyncedSeedModel looks them up.
577
685
  await Model.all();
@@ -596,37 +704,36 @@ const insertSyncedProperties = async ({ newProperties, itemSeeds, state, }) => {
596
704
  continue;
597
705
  }
598
706
  const propertyMetadata = parsed.metadata;
599
- let propertyNameSnake = propertyMetadata.name;
707
+ const propertyNameSnake = propertyMetadata.name;
600
708
  if (!propertyNameSnake) {
601
709
  console.warn('[item/events] [syncDbWithEas] no propertyName found for property: ', property);
602
710
  continue;
603
711
  }
604
- let isRelation = false;
605
- let refValueType;
606
712
  let refSeedType;
607
713
  let refSchemaUid;
608
- let isList = false;
609
714
  const schemaUid = property.schemaId;
610
715
  setSchemaUidForSchemaDefinition({
611
716
  text: propertyNameSnake,
612
717
  schemaUid,
613
718
  });
614
- if (isRelationPropertyName(propertyNameSnake)) {
615
- isRelation = true;
616
- if (Array.isArray(propertyMetadata.value)) {
617
- isList = true;
618
- refValueType = 'list';
619
- const result = parseEasRelationPropertyName(propertyNameSnake);
620
- if (result) {
621
- propertyNameSnake = result.propertyName;
622
- refSeedType = result.modelName;
623
- }
624
- }
625
- if (!isList) {
626
- if (relationValuesToExclude.includes(propertyMetadata.value)) {
627
- continue;
628
- }
629
- }
719
+ const easDataType = propertyMetadata.type;
720
+ const versionUid = property.refUID;
721
+ const versionLocalId = versionUidToLocalId.get(versionUid);
722
+ const attestationCreatedAt = property.timeCreated * 1000;
723
+ const seedUid = versionUidToSeedUid.get(versionUid);
724
+ const seedLocalId = seedUidToLocalId.get(seedUid);
725
+ const modelType = seedUidToModelType.get(seedUid);
726
+ const modelSchema = await modelSchemaForSyncedProperty(Model, property, state);
727
+ // ADR 0008: the local property this EAS name stands for, and whether it's a relation.
728
+ const resolvedName = resolveSyncedPropertyName(propertyNameSnake, propertyMetadata.value, modelSchema);
729
+ if (!resolvedName)
730
+ continue;
731
+ const { propertyName, isRelation, isList } = resolvedName;
732
+ const refValueType = isRelation && isList ? 'list' : undefined;
733
+ if (isList)
734
+ refSeedType = resolvedName.refSeedType;
735
+ if (isRelation && !isList && relationValuesToExclude.includes(propertyMetadata.value)) {
736
+ continue;
630
737
  }
631
738
  let propertyValue = propertyMetadata.value;
632
739
  if (typeof propertyValue !== 'string') {
@@ -646,18 +753,6 @@ const insertSyncedProperties = async ({ newProperties, itemSeeds, state, }) => {
646
753
  refSchemaUid = relatedSeeds[0].schemaId;
647
754
  }
648
755
  }
649
- const propertyName = camelCase(propertyNameSnake);
650
- const easDataType = propertyMetadata.type;
651
- const versionUid = property.refUID;
652
- const versionLocalId = versionUidToLocalId.get(versionUid);
653
- const attestationCreatedAt = property.timeCreated * 1000;
654
- const seedUid = versionUidToSeedUid.get(versionUid);
655
- const seedLocalId = seedUidToLocalId.get(seedUid);
656
- const modelType = seedUidToModelType.get(seedUid);
657
- const model = modelType != null
658
- ? await skipSeedOnAmbiguousModel({ seedLocalId, seedUid }, 'easSync.metadata', async () => resolveSyncedSeedModel(Model, modelType, { seedLocalId, seedUid }))
659
- : undefined;
660
- const modelSchema = model?.properties ? modelPropertiesToObject(model.properties) : undefined;
661
756
  if (propertyNameSnake === 'storage_transaction_id') {
662
757
  await createMetadataRecordsForStorageTransactionId(property, modelSchema, state);
663
758
  }
@@ -811,11 +906,12 @@ const runSyncFromEas = async (options) => {
811
906
  // Never mix attestations from two chains in one local DB.
812
907
  await assertLocalDbChain();
813
908
  const appDb = BaseDb.getAppDb();
814
- const { schemaStringToModelRecord } = await getModelSchemas();
909
+ const { matchModelRecord } = await getModelSchemas();
815
910
  const modelSchemas = await getModelSchemasFromEas();
816
911
  const schemaUids = [];
817
912
  for (const modelSchema of modelSchemas) {
818
- const foundModel = schemaStringToModelRecord.get(modelSchema.schema);
913
+ // ADR 0008: matched by name, so seeds published under an older SDK's name are found too.
914
+ const foundModel = matchModelRecord(modelSchema.schema);
819
915
  if (!foundModel) {
820
916
  // Skip schemas that don't have a corresponding model in the user's config
821
917
  // This can happen with "bytes32 image" if there's no Image model defined
@@ -861,9 +957,9 @@ const runSyncFromEas = async (options) => {
861
957
  await getRelatedSeedsAndVersions(state);
862
958
  scheduleBulkFilesDownloadFromEasSync(addresses);
863
959
  try {
864
- const _mod_2 = await import('./Item-cq9VcsAY.js');
865
- const _ns_2 = _mod_2.a8;
866
- const itemMod = _ns_2;
960
+ const _mod_4 = await import('./Item-BUUFuywT.js');
961
+ const _ns_4 = _mod_4.a6;
962
+ const itemMod = _ns_4;
867
963
  await itemMod.Item.rehydrateCachedItemsFromDbAfterEasSync();
868
964
  }
869
965
  catch (err) {
@@ -874,4 +970,4 @@ const runSyncFromEas = async (options) => {
874
970
  };
875
971
 
876
972
  export { VERSION_INSERT_BATCH, isSqlEscapedAttestationRaw, runSyncFromEas };
877
- //# sourceMappingURL=syncDbWithEas-B-Ho0IOB.js.map
973
+ //# sourceMappingURL=syncDbWithEas-CRpnkq00.js.map