@seedprotocol/sdk 0.7.0 → 0.7.2-next.593.gd5bd4ea

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 (160) hide show
  1. package/dist/{BasePathResolver-ndE8XTpw.js → BasePathResolver-BdxCSIzn.js} +2 -2
  2. package/dist/{BasePathResolver-ndE8XTpw.js.map → BasePathResolver-BdxCSIzn.js.map} +1 -1
  3. package/dist/{ClientManager-DLleL_2e.js → ClientManager-ClCwwhwo.js} +28 -23
  4. package/dist/ClientManager-ClCwwhwo.js.map +1 -0
  5. package/dist/{Item-zBFWQDU9.js → Item-B9Y4VuK1.js} +140 -74
  6. package/dist/Item-B9Y4VuK1.js.map +1 -0
  7. package/dist/{ModelProperty-lth9L37R.js → ModelProperty-BMePcicQ.js} +64 -36
  8. package/dist/ModelProperty-BMePcicQ.js.map +1 -0
  9. package/dist/{Schema-DOhlrQ-N.js → Schema-COsEXXaR.js} +106 -58
  10. package/dist/Schema-COsEXXaR.js.map +1 -0
  11. package/dist/{SchemaValidationService-DDKr5piy.js → SchemaValidationService-DabGMzSE.js} +7 -8
  12. package/dist/{SchemaValidationService-DDKr5piy.js.map → SchemaValidationService-DabGMzSE.js.map} +1 -1
  13. package/dist/{backfillMetadataPropertyIds-fG3ujaSh.js → backfillMetadataPropertyIds-Ck6fumnm.js} +4 -4
  14. package/dist/{backfillMetadataPropertyIds-fG3ujaSh.js.map → backfillMetadataPropertyIds-Ck6fumnm.js.map} +1 -1
  15. package/dist/cjs/{ModelProperty-BEsIHAjk.js → ModelProperty-BT6Un_MB.js} +59 -30
  16. package/dist/cjs/ModelProperty-BT6Un_MB.js.map +1 -0
  17. package/dist/cjs/{Schema-qEp5mH1N.js → Schema-BXhXdUsA.js} +93 -44
  18. package/dist/cjs/Schema-BXhXdUsA.js.map +1 -0
  19. package/dist/cjs/{SchemaValidationService-CWEnZmOH.js → SchemaValidationService-CC18QDfc.js} +2 -2
  20. package/dist/cjs/{SchemaValidationService-CWEnZmOH.js.map → SchemaValidationService-CC18QDfc.js.map} +1 -1
  21. package/dist/cjs/{backfillMetadataPropertyIds-tw8JGMT0.js → backfillMetadataPropertyIds-DEHC9ejq.js} +3 -3
  22. package/dist/cjs/{backfillMetadataPropertyIds-tw8JGMT0.js.map → backfillMetadataPropertyIds-DEHC9ejq.js.map} +1 -1
  23. package/dist/cjs/{eas-CLiV2Hmn.js → eas-C3CL0l7l.js} +3 -3
  24. package/dist/cjs/{eas-CLiV2Hmn.js.map → eas-C3CL0l7l.js.map} +1 -1
  25. package/dist/cjs/{getItem-DSRtx_68.js → getItem-CrwWYCkj.js} +2 -2
  26. package/dist/cjs/{getItem-DSRtx_68.js.map → getItem-CrwWYCkj.js.map} +1 -1
  27. package/dist/cjs/{getPublishPayload-D5-dYtNq.js → getPublishPayload-DRJh7WR0.js} +171 -209
  28. package/dist/cjs/getPublishPayload-DRJh7WR0.js.map +1 -0
  29. package/dist/cjs/{getPublishUploads-B5Lq6q-_.js → getPublishUploads-Bh22D3zJ.js} +49 -10
  30. package/dist/cjs/getPublishUploads-Bh22D3zJ.js.map +1 -0
  31. package/dist/cjs/{index-B3UDbm1C.js → index-BA1RIYFG.js} +3 -3
  32. package/dist/cjs/index-BA1RIYFG.js.map +1 -0
  33. package/dist/cjs/{index-C66AfYDG.js → index-Dls7aMjr.js} +281 -90
  34. package/dist/cjs/index-Dls7aMjr.js.map +1 -0
  35. package/dist/cjs/{property-BVJIP7SX.js → property-ZerTWizX.js} +5 -5
  36. package/dist/cjs/{property-BVJIP7SX.js.map → property-ZerTWizX.js.map} +1 -1
  37. package/dist/cjs/publishDraftGraph-CPOAcQFf.js +403 -0
  38. package/dist/cjs/publishDraftGraph-CPOAcQFf.js.map +1 -0
  39. package/dist/cjs/{resetAmbiguousLegacyItemData-BaZqUui9.js → resetAmbiguousLegacyItemData-adDl4LcT.js} +2 -2
  40. package/dist/cjs/{resetAmbiguousLegacyItemData-BaZqUui9.js.map → resetAmbiguousLegacyItemData-adDl4LcT.js.map} +1 -1
  41. package/dist/cjs/{resolveModelForSyncedSeed-CC6dQctx.js → resolveModelForSyncedSeed-DoNThPdL.js} +2 -2
  42. package/dist/cjs/{resolveModelForSyncedSeed-CC6dQctx.js.map → resolveModelForSyncedSeed-DoNThPdL.js.map} +1 -1
  43. package/dist/cjs/{syncDbWithEas-Dk96sAG-.js → syncDbWithEas-CYfPkus9.js} +20 -7
  44. package/dist/cjs/{syncDbWithEas-Dk96sAG-.js.map → syncDbWithEas-CYfPkus9.js.map} +1 -1
  45. package/dist/{configurePlatform-BMoPG9vY.js → configurePlatform-xU3Hsno3.js} +4 -4
  46. package/dist/{configurePlatform-BMoPG9vY.js.map → configurePlatform-xU3Hsno3.js.map} +1 -1
  47. package/dist/{db-BJZN0a0a.js → db-W1g29qsM.js} +31 -27
  48. package/dist/{db-BJZN0a0a.js.map → db-W1g29qsM.js.map} +1 -1
  49. package/dist/{eas-B0hsMLqt.js → eas-CSwV6MvB.js} +6 -6
  50. package/dist/{eas-B0hsMLqt.js.map → eas-CSwV6MvB.js.map} +1 -1
  51. package/dist/{getItem-DEh4WfHG.js → getItem-BYQeM3DY.js} +5 -6
  52. package/dist/{getItem-DEh4WfHG.js.map → getItem-BYQeM3DY.js.map} +1 -1
  53. package/dist/{getPublishPayload-H032DHC7.js → getPublishPayload-D5CQZd-y.js} +167 -206
  54. package/dist/getPublishPayload-D5CQZd-y.js.map +1 -0
  55. package/dist/{getPublishUploads-CR66RlGJ.js → getPublishUploads-BGpDsrBp.js} +52 -14
  56. package/dist/getPublishUploads-BGpDsrBp.js.map +1 -0
  57. package/dist/{index-6bJuv5Tt.js → index-Bev-hZF-.js} +9 -10
  58. package/dist/index-Bev-hZF-.js.map +1 -0
  59. package/dist/{index-B0LgJblD.js → index-CSOQFAOn.js} +2 -2
  60. package/dist/index-CSOQFAOn.js.map +1 -0
  61. package/dist/{index-DtfjeuxC.js → index-DRXC5Mra.js} +167 -75
  62. package/dist/index-DRXC5Mra.js.map +1 -0
  63. package/dist/{index.browser-CNrqhvEA.js → index.browser-DO20vYuP.js} +9 -9
  64. package/dist/{index.browser-CNrqhvEA.js.map → index.browser-DO20vYuP.js.map} +1 -1
  65. package/dist/{index.node-DrHiTuOr.js → index.node-C4iyOhdo.js} +5 -5
  66. package/dist/{index.node-DrHiTuOr.js.map → index.node-C4iyOhdo.js.map} +1 -1
  67. package/dist/main.cjs +1 -1
  68. package/dist/main.js +258 -183
  69. package/dist/main.js.map +1 -1
  70. package/dist/node.js +14 -15
  71. package/dist/node.js.map +1 -1
  72. package/dist/platform.browser.js +5 -5
  73. package/dist/platform.node.js +3 -3
  74. package/dist/{property-D2Nnsmm1.js → property-BT1zDSkd.js} +10 -11
  75. package/dist/property-BT1zDSkd.js.map +1 -0
  76. package/dist/publishDraftGraph-Bcfrdj7-.js +405 -0
  77. package/dist/publishDraftGraph-Bcfrdj7-.js.map +1 -0
  78. package/dist/{resetAmbiguousLegacyItemData-BqbHNUYk.js → resetAmbiguousLegacyItemData-Ci6PM_vC.js} +2 -2
  79. package/dist/{resetAmbiguousLegacyItemData-BqbHNUYk.js.map → resetAmbiguousLegacyItemData-Ci6PM_vC.js.map} +1 -1
  80. package/dist/{resolveModelForSyncedSeed-DQK6JfXS.js → resolveModelForSyncedSeed-CLlumTBq.js} +2 -2
  81. package/dist/{resolveModelForSyncedSeed-DQK6JfXS.js.map → resolveModelForSyncedSeed-CLlumTBq.js.map} +1 -1
  82. package/dist/src/Item/Item.d.ts +11 -0
  83. package/dist/src/Item/Item.d.ts.map +1 -1
  84. package/dist/src/ItemProperty/ItemProperty.d.ts +10 -0
  85. package/dist/src/ItemProperty/ItemProperty.d.ts.map +1 -1
  86. package/dist/src/Model/Model.d.ts +15 -2
  87. package/dist/src/Model/Model.d.ts.map +1 -1
  88. package/dist/src/Model/service/actors/createModelProperties.d.ts.map +1 -1
  89. package/dist/src/Model/service/actors/loadOrCreateModel.d.ts.map +1 -1
  90. package/dist/src/Model/service/actors/validateModel.d.ts.map +1 -1
  91. package/dist/src/Model/service/modelMachine.d.ts.map +1 -1
  92. package/dist/src/ModelProperty/ModelProperty.d.ts +9 -1
  93. package/dist/src/ModelProperty/ModelProperty.d.ts.map +1 -1
  94. package/dist/src/ModelProperty/service/actors/compareAndMarkDraft.d.ts.map +1 -1
  95. package/dist/src/ModelProperty/service/actors/saveToSchema.d.ts.map +1 -1
  96. package/dist/src/ModelProperty/service/actors/validateProperty.d.ts.map +1 -1
  97. package/dist/src/Schema/Schema.d.ts +7 -0
  98. package/dist/src/Schema/Schema.d.ts.map +1 -1
  99. package/dist/src/Schema/service/actors/checkExistingSchema.d.ts.map +1 -1
  100. package/dist/src/Schema/service/actors/createModelInstances.d.ts.map +1 -1
  101. package/dist/src/Schema/service/actors/loadOrCreateSchema.d.ts.map +1 -1
  102. package/dist/src/db/read/getPublishPayload.d.ts +9 -0
  103. package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
  104. package/dist/src/db/read/getPublishUploads.d.ts +5 -0
  105. package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
  106. package/dist/src/db/read/publishDraftGraph.d.ts +57 -0
  107. package/dist/src/db/read/publishDraftGraph.d.ts.map +1 -0
  108. package/dist/src/db/read/summarizePublishWork.d.ts.map +1 -1
  109. package/dist/src/helpers/entity/entityLiveQuery.d.ts.map +1 -1
  110. package/dist/src/helpers/entity/evictionEpoch.d.ts +18 -0
  111. package/dist/src/helpers/entity/evictionEpoch.d.ts.map +1 -0
  112. package/dist/src/helpers/generateId.d.ts +4 -0
  113. package/dist/src/helpers/generateId.d.ts.map +1 -1
  114. package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts +28 -6
  115. package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts.map +1 -1
  116. package/dist/src/index.d.ts +2 -1
  117. package/dist/src/index.d.ts.map +1 -1
  118. package/dist/src/query/createLocalQueryDataSource.d.ts.map +1 -1
  119. package/dist/src/services/write/actors/validateEntity.d.ts.map +1 -1
  120. package/dist/src/types/item.d.ts +7 -8
  121. package/dist/src/types/item.d.ts.map +1 -1
  122. package/dist/{syncDbWithEas-LRKr_NZF.js → syncDbWithEas-BQsXjGhe.js} +15 -16
  123. package/dist/syncDbWithEas-BQsXjGhe.js.map +1 -0
  124. package/dist/{tabEvents-DYI2GU7i.js → tabEvents-C9qUKx_z.js} +28 -11
  125. package/dist/tabEvents-C9qUKx_z.js.map +1 -0
  126. package/dist/{tolerantWebAccess-CzOBz5M6.js → tolerantWebAccess-B-9bwxbw.js} +6 -6
  127. package/dist/{tolerantWebAccess-CzOBz5M6.js.map → tolerantWebAccess-B-9bwxbw.js.map} +1 -1
  128. package/dist/{updateSeedRevokedAt-B58ORbY3.js → updateSeedRevokedAt-D6q0h7pj.js} +3 -3
  129. package/dist/{updateSeedRevokedAt-B58ORbY3.js.map → updateSeedRevokedAt-D6q0h7pj.js.map} +1 -1
  130. package/package.json +13 -10
  131. package/dist/ClientManager-DLleL_2e.js.map +0 -1
  132. package/dist/Item-zBFWQDU9.js.map +0 -1
  133. package/dist/ModelProperty-lth9L37R.js.map +0 -1
  134. package/dist/Schema-DOhlrQ-N.js.map +0 -1
  135. package/dist/cjs/ModelProperty-BEsIHAjk.js.map +0 -1
  136. package/dist/cjs/Schema-qEp5mH1N.js.map +0 -1
  137. package/dist/cjs/getLatestVersionRow-DVizNNoI.js +0 -59
  138. package/dist/cjs/getLatestVersionRow-DVizNNoI.js.map +0 -1
  139. package/dist/cjs/getPublishPayload-D5-dYtNq.js.map +0 -1
  140. package/dist/cjs/getPublishUploads-B5Lq6q-_.js.map +0 -1
  141. package/dist/cjs/getSegmentedItemProperties-giHO7R3d.js +0 -147
  142. package/dist/cjs/getSegmentedItemProperties-giHO7R3d.js.map +0 -1
  143. package/dist/cjs/index-B3UDbm1C.js.map +0 -1
  144. package/dist/cjs/index-C66AfYDG.js.map +0 -1
  145. package/dist/generateId-BopUwD8F.js +0 -9
  146. package/dist/generateId-BopUwD8F.js.map +0 -1
  147. package/dist/getLatestVersionRow-Brrl1AnW.js +0 -46
  148. package/dist/getLatestVersionRow-Brrl1AnW.js.map +0 -1
  149. package/dist/getPublishPayload-H032DHC7.js.map +0 -1
  150. package/dist/getPublishUploads-CR66RlGJ.js.map +0 -1
  151. package/dist/getSegmentedItemProperties-C2EJ2G0N.js +0 -147
  152. package/dist/getSegmentedItemProperties-C2EJ2G0N.js.map +0 -1
  153. package/dist/index-6bJuv5Tt.js.map +0 -1
  154. package/dist/index-B0LgJblD.js.map +0 -1
  155. package/dist/index-DtfjeuxC.js.map +0 -1
  156. package/dist/property-D2Nnsmm1.js.map +0 -1
  157. package/dist/src/browser/helpers/index.d.ts +0 -4
  158. package/dist/src/browser/helpers/index.d.ts.map +0 -1
  159. package/dist/syncDbWithEas-LRKr_NZF.js.map +0 -1
  160. package/dist/tabEvents-DYI2GU7i.js.map +0 -1
@@ -0,0 +1,405 @@
1
+ import { a as BaseDb, p as properties, j as models, r as seeds, Z as ZERO_BYTES32, v as versions } from './BasePathResolver-BdxCSIzn.js';
2
+ import { i as isVersionRevoked, p as parseListPropertyValueFromStorage } from './Item-B9Y4VuK1.js';
3
+ import 'reflect-metadata';
4
+ import './index-DRXC5Mra.js';
5
+ import { q as getItemModelScope, M as ModelPropertyDataTypes, p as resolveModelRecord, n as normalizeDataType } from './db-W1g29qsM.js';
6
+ import { getPropertySchema } from './property-BT1zDSkd.js';
7
+ import { and, eq, isNotNull } from 'drizzle-orm';
8
+ import { upperFirst, camelCase } from 'lodash-es';
9
+ import { n as normalizeRelationPropertyValue, r as resolveSeedIdsFromRefString, i as isPublishedSeedRef } from './tabEvents-C9qUKx_z.js';
10
+ import 'pluralize';
11
+
12
+ const matchesDataType = (actual, expected) => normalizeDataType(actual) === expected;
13
+ async function resolvePropertyDef(modelName, propertyName, scope) {
14
+ let schema = await getPropertySchema(modelName, propertyName, scope);
15
+ if (schema)
16
+ return schema;
17
+ const db = BaseDb.getAppDb();
18
+ if (!db)
19
+ return undefined;
20
+ try {
21
+ const normalizedModelName = upperFirst(camelCase(modelName));
22
+ const modelRecord = await resolveModelRecord(normalizedModelName, scope, db);
23
+ const modelRecords = modelRecord ? [modelRecord] : [];
24
+ if (modelRecords.length === 0 || !modelRecords[0].id)
25
+ return undefined;
26
+ const propertyRecords = await db
27
+ .select()
28
+ .from(properties)
29
+ .where(and(eq(properties.modelId, modelRecords[0].id), eq(properties.name, propertyName)))
30
+ .limit(1);
31
+ if (propertyRecords.length === 0)
32
+ return undefined;
33
+ const propRecord = propertyRecords[0];
34
+ let refModelName;
35
+ if (propRecord.refModelId != null) {
36
+ const refModelRows = await db
37
+ .select({ name: models.name })
38
+ .from(models)
39
+ .where(eq(models.id, propRecord.refModelId))
40
+ .limit(1);
41
+ refModelName = refModelRows[0]?.name ?? undefined;
42
+ }
43
+ return {
44
+ dataType: propRecord.dataType,
45
+ ref: refModelName ?? undefined,
46
+ refValueType: propRecord.refValueType || undefined,
47
+ storageType: propRecord.storageType || undefined,
48
+ localStorageDir: propRecord.localStorageDir || undefined,
49
+ filenameSuffix: propRecord.filenameSuffix || undefined,
50
+ required: propRecord.required ?? undefined,
51
+ };
52
+ }
53
+ catch {
54
+ return undefined;
55
+ }
56
+ }
57
+ const getSegmentedItemProperties = async (item) => {
58
+ const itemBasicProperties = [];
59
+ const itemRelationProperties = [];
60
+ const itemListProperties = [];
61
+ const itemUploadProperties = [];
62
+ const itemImageProperties = [];
63
+ const itemStorageProperties = [];
64
+ let itemStorageTransactionProperty;
65
+ let itemScope;
66
+ for (const itemProperty of item.properties) {
67
+ let propertyDef = itemProperty.propertyDef;
68
+ // When propertyDef is missing (e.g. external app, Model not registered), resolve inline
69
+ // so properties are not skipped and metadata attestations can be created
70
+ if (!propertyDef && item.modelName) {
71
+ itemScope ?? (itemScope = await getItemModelScope(item));
72
+ const resolved = await resolvePropertyDef(item.modelName, itemProperty.propertyName, itemScope);
73
+ if (resolved) {
74
+ itemProperty.getService().send({ type: 'updateContext', propertyRecordSchema: resolved });
75
+ propertyDef = resolved;
76
+ }
77
+ else {
78
+ // Last resort: Model and DB don't have schema. Use Text so property routes to
79
+ // itemBasicProperties and can be attested (covers title, description, etc.)
80
+ const fallbackDef = { dataType: 'Text' };
81
+ itemProperty.getService().send({ type: 'updateContext', propertyRecordSchema: fallbackDef });
82
+ propertyDef = fallbackDef;
83
+ }
84
+ }
85
+ if (!propertyDef) {
86
+ continue;
87
+ }
88
+ const isItemStorage = propertyDef.storageType &&
89
+ propertyDef.storageType === 'ItemStorage';
90
+ const isStorageTransaction = itemProperty.propertyName === 'storageTransactionId' ||
91
+ itemProperty.propertyName === 'storage_transaction_id';
92
+ const isStorageSeedType = matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.Image) ||
93
+ matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.File) ||
94
+ matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.Html) ||
95
+ matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.Json) ||
96
+ (matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.Relation) &&
97
+ (matchesDataType(propertyDef.refValueType, ModelPropertyDataTypes.Image) ||
98
+ matchesDataType(propertyDef.refValueType, ModelPropertyDataTypes.File) ||
99
+ matchesDataType(propertyDef.refValueType, ModelPropertyDataTypes.Html) ||
100
+ matchesDataType(propertyDef.refValueType, ModelPropertyDataTypes.Json)));
101
+ if (isStorageSeedType) {
102
+ itemImageProperties.push(itemProperty);
103
+ if (matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.Relation)) {
104
+ itemRelationProperties.push(itemProperty);
105
+ }
106
+ continue;
107
+ }
108
+ if (matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.Relation)) {
109
+ itemRelationProperties.push(itemProperty);
110
+ continue;
111
+ }
112
+ if (matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.List)) {
113
+ // List-of-relations: ref present, goes to processListProperty
114
+ // List-of-primitives: ref absent, treat as basic property
115
+ const listRef = propertyDef.ref || propertyDef.refModelName;
116
+ if (listRef) {
117
+ itemListProperties.push(itemProperty);
118
+ }
119
+ else {
120
+ itemBasicProperties.push(itemProperty);
121
+ }
122
+ continue;
123
+ }
124
+ if (isItemStorage) {
125
+ itemStorageProperties.push(itemProperty);
126
+ continue;
127
+ }
128
+ if (isStorageTransaction) {
129
+ itemStorageTransactionProperty = { itemProperty, childProperties: [] };
130
+ continue;
131
+ }
132
+ itemBasicProperties.push(itemProperty);
133
+ }
134
+ if (itemStorageTransactionProperty && itemStorageProperties.length > 0) {
135
+ itemStorageTransactionProperty.childProperties = itemStorageProperties;
136
+ }
137
+ if (itemStorageTransactionProperty) {
138
+ itemUploadProperties.push(itemStorageTransactionProperty);
139
+ }
140
+ return {
141
+ itemBasicProperties,
142
+ itemRelationProperties,
143
+ itemListProperties,
144
+ itemUploadProperties,
145
+ itemImageProperties,
146
+ };
147
+ };
148
+
149
+ /**
150
+ * True when the item's seed attestation was revoked (`seeds.revoked_at` set, by unpublish or EAS
151
+ * sync). Such a seed can't take new versions: publishing again creates a new seed attestation
152
+ * (see "Republishing" in docs/ATTESTATION_REVOCATION.md).
153
+ */
154
+ const isSeedRevoked = async (seedLocalId) => {
155
+ if (!seedLocalId)
156
+ return false;
157
+ const appDb = BaseDb.getAppDb();
158
+ if (!appDb)
159
+ return false;
160
+ const [row] = await appDb
161
+ .select({ revokedAt: seeds.revokedAt })
162
+ .from(seeds)
163
+ .where(eq(seeds.localId, seedLocalId))
164
+ .limit(1);
165
+ return isVersionRevoked(row?.revokedAt);
166
+ };
167
+
168
+ const selectSeed = {
169
+ seedLocalId: seeds.localId,
170
+ seedUid: seeds.uid,
171
+ revokedAt: seeds.revokedAt,
172
+ type: seeds.type,
173
+ };
174
+ /**
175
+ * The local seed row a relation/list/image ref points at, by local id or uid. A uid that is no
176
+ * seed's current uid can be the old uid of a seed that was unpublished and published again (a new
177
+ * seed attestation, same local seed): its old version rows still record it, so it resolves to that
178
+ * seed. Null when nothing local matches (e.g. a published uid with no local copy).
179
+ */
180
+ const findRelatedSeedRow = async ({ seedLocalId, seedUid, }) => {
181
+ const appDb = BaseDb.getAppDb();
182
+ if (!appDb)
183
+ return null;
184
+ if (seedLocalId) {
185
+ const [row] = await appDb.select(selectSeed).from(seeds).where(eq(seeds.localId, seedLocalId)).limit(1);
186
+ if (row?.seedLocalId)
187
+ return row;
188
+ }
189
+ if (!seedUid || seedUid === ZERO_BYTES32)
190
+ return null;
191
+ const [byUid] = await appDb.select(selectSeed).from(seeds).where(eq(seeds.uid, seedUid)).limit(1);
192
+ if (byUid?.seedLocalId)
193
+ return byUid;
194
+ const [version] = await appDb
195
+ .select({ seedLocalId: versions.seedLocalId })
196
+ .from(versions)
197
+ .where(and(eq(versions.seedUid, seedUid), isNotNull(versions.seedLocalId)))
198
+ .limit(1);
199
+ if (!version?.seedLocalId)
200
+ return null;
201
+ const [republished] = await appDb
202
+ .select(selectSeed)
203
+ .from(seeds)
204
+ .where(eq(seeds.localId, version.seedLocalId))
205
+ .limit(1);
206
+ return republished?.seedLocalId ? republished : null;
207
+ };
208
+ /** The seed is attested and its attestation is live. */
209
+ const isLivePublishedSeed = (row) => !!row?.seedUid && row.seedUid !== ZERO_BYTES32 && !isVersionRevoked(row.revokedAt);
210
+ /** The seed was attested and that attestation was revoked (unpublished). */
211
+ const isUnpublishedSeed = (row) => !!row?.seedUid && row.seedUid !== ZERO_BYTES32 && isVersionRevoked(row.revokedAt);
212
+ /** Model a relation/list/image property points at, from its definition. */
213
+ function relatedModelNameFromDef(propertyDef) {
214
+ const def = propertyDef;
215
+ if (!def)
216
+ return undefined;
217
+ const dataType = normalizeDataType(def.dataType);
218
+ if (dataType === ModelPropertyDataTypes.Image)
219
+ return 'Image';
220
+ if (dataType === ModelPropertyDataTypes.File)
221
+ return 'File';
222
+ if (dataType === ModelPropertyDataTypes.Html)
223
+ return 'Html';
224
+ return def.ref ?? def.refModelName;
225
+ }
226
+ /**
227
+ * Name of the item's Html property whose value is the Html seed `htmlSeedLocalId`: the property
228
+ * that refers to the images embedded in that Html (htmlEmbeddedImageCoPublish rows).
229
+ */
230
+ function htmlPropertyNameForHtmlSeed(item, htmlSeedLocalId) {
231
+ const want = htmlSeedLocalId.trim();
232
+ for (const p of item.properties ?? []) {
233
+ if (normalizeDataType(p.propertyDef?.dataType) !== ModelPropertyDataTypes.Html)
234
+ continue;
235
+ const snap = p.getService().getSnapshot();
236
+ const value = 'context' in snap ? snap.context.propertyValue : undefined;
237
+ if (typeof value === 'string' && value.trim() === want)
238
+ return p.propertyName;
239
+ }
240
+ return 'html';
241
+ }
242
+
243
+ /**
244
+ * The draft items a publish of an item carries along, and how it walks to them.
245
+ *
246
+ * A publish attests the item and every draft item (no seed uid yet) reachable from it through
247
+ * relation and list-of-relation properties, each with its full property set. Already-published
248
+ * targets are referenced by their current uid and not walked into; revoked ones stop the publish
249
+ * (RelatedItemUnpublishedError). getPublishPayload, getPublishUploads, getPublishUploadData (publish
250
+ * package), summarizePublishWork and the Html-embedded image co-publish all walk this graph in the
251
+ * same order: depth first, properties in item order (relations, then lists), list members in order.
252
+ *
253
+ * Cycles: an item can only attest the uid of a seed published before it in the same publish, so a
254
+ * ref back to an item still being walked (an ancestor that gets a new seed in this publish) can't be
255
+ * attested. Such a property is deferred: left out of this publish (it keeps no uid, so the next
256
+ * publish of its item attests it, with the target's uid). For A ↔ B reached from A, A attests B's
257
+ * uid and B's relation to A is deferred.
258
+ */
259
+ /** Relation properties that point at model items (not Image/File/Html/Json storage seeds). */
260
+ function draftWalkProperties(segmented) {
261
+ const storage = new Set(segmented.itemImageProperties);
262
+ return {
263
+ relationProperties: segmented.itemRelationProperties.filter((p) => !storage.has(p)),
264
+ listProperties: segmented.itemListProperties,
265
+ };
266
+ }
267
+ const propertyContext = (prop) => {
268
+ const snapshot = prop.getService().getSnapshot();
269
+ return snapshot && 'context' in snapshot
270
+ ? (snapshot.context ?? null)
271
+ : null;
272
+ };
273
+ /** Seed refs held by a relation property (one) or a list property (each member). */
274
+ function propertySeedRefs(prop, isList) {
275
+ const context = propertyContext(prop);
276
+ if (!context)
277
+ return [];
278
+ let value = context.propertyValue;
279
+ if (isList) {
280
+ if (typeof value === 'string')
281
+ value = parseListPropertyValueFromStorage(value);
282
+ const arr = Array.isArray(value) ? value : value != null ? [value] : [];
283
+ return arr
284
+ .map((v) => v && typeof v === 'object'
285
+ ? normalizeRelationPropertyValue(v.seedLocalId ??
286
+ v.localId ??
287
+ v.seedUid ??
288
+ v.uid)
289
+ : normalizeRelationPropertyValue(v))
290
+ .filter((v) => !!v);
291
+ }
292
+ const ref = normalizeRelationPropertyValue(value);
293
+ return ref ? [ref] : [];
294
+ }
295
+ const isZeroUid = (uid) => !uid || uid === ZERO_BYTES32;
296
+ /** The item gets a new seed attestation in this publish: a draft, or a revoked seed published again. */
297
+ async function getsNewSeed(item) {
298
+ return isZeroUid(item.seedUid) || (await isSeedRevoked(item.seedLocalId));
299
+ }
300
+ /** Would the publish attest this property (so walk its refs)? Same rule as getPublishPayload. */
301
+ function walksProperty(prop, forceFullSnapshot) {
302
+ if (prop.uid && !forceFullSnapshot)
303
+ return false;
304
+ const ctx = propertyContext(prop);
305
+ const value = ctx?.propertyValue;
306
+ return value != null && value !== '' && !(Array.isArray(value) && value.length === 0);
307
+ }
308
+ async function loadItem(seedLocalId) {
309
+ const { getItem } = await import('./getItem-BYQeM3DY.js');
310
+ try {
311
+ return (await getItem({ seedLocalId })) ?? undefined;
312
+ }
313
+ catch {
314
+ return undefined;
315
+ }
316
+ }
317
+ async function getPublishDraftGraph(root, options) {
318
+ const forceFullSnapshot = options?.forceFullSnapshot === true;
319
+ const strict = options?.strict === true;
320
+ const drafts = [];
321
+ const deferredProperties = new Set();
322
+ const backReferences = new Map();
323
+ const visited = new Set([root.seedLocalId]);
324
+ const inProgress = new Set();
325
+ if (await getsNewSeed(root))
326
+ inProgress.add(root.seedLocalId);
327
+ /** Draft target of a ref, or undefined (published, revoked, unknown). */
328
+ const draftTarget = async (prop, ref, isList) => {
329
+ const { seedLocalId, seedUid } = resolveSeedIdsFromRefString(ref);
330
+ if (!seedLocalId && !seedUid) {
331
+ if (strict && !isList) {
332
+ throw new Error(`Invalid relation value for ${prop.propertyName}: expected local seed id or 0x uid`);
333
+ }
334
+ return undefined;
335
+ }
336
+ const row = await findRelatedSeedRow({ seedLocalId, seedUid });
337
+ const targetLocalId = row?.seedLocalId ?? seedLocalId;
338
+ if (!targetLocalId)
339
+ return undefined;
340
+ // An item getting a new seed in this publish, still being walked (also the root when it is a
341
+ // revoked seed published again): a back edge, whatever its current uid.
342
+ if (inProgress.has(targetLocalId))
343
+ return { seedLocalId: targetLocalId };
344
+ // Published (live or revoked): referenced by uid / reported, never walked into.
345
+ if (row && !isZeroUid(row.seedUid))
346
+ return undefined;
347
+ if (visited.has(targetLocalId))
348
+ return { seedLocalId: targetLocalId };
349
+ const item = await loadItem(targetLocalId);
350
+ if (!item) {
351
+ if (strict && !isList && !isPublishedSeedRef(ref)) {
352
+ throw new Error(`No relatedItem found for ${prop.propertyName}`);
353
+ }
354
+ return undefined;
355
+ }
356
+ if (!isZeroUid(item.seedUid))
357
+ return undefined;
358
+ return { seedLocalId: targetLocalId, item };
359
+ };
360
+ const visit = async (item) => {
361
+ const segmented = await getSegmentedItemProperties(item);
362
+ const { relationProperties, listProperties } = draftWalkProperties(segmented);
363
+ const walk = async (prop, isList) => {
364
+ if (!walksProperty(prop, forceFullSnapshot))
365
+ return;
366
+ const targets = [];
367
+ for (const ref of propertySeedRefs(prop, isList)) {
368
+ const t = await draftTarget(prop, ref, isList);
369
+ if (t)
370
+ targets.push(t);
371
+ }
372
+ const back = targets.filter((t) => inProgress.has(t.seedLocalId)).map((t) => t.seedLocalId);
373
+ if (back.length > 0) {
374
+ deferredProperties.add(prop);
375
+ backReferences.set(prop, new Set(back));
376
+ }
377
+ for (const t of targets) {
378
+ if (!t.item || visited.has(t.seedLocalId))
379
+ continue;
380
+ visited.add(t.seedLocalId);
381
+ inProgress.add(t.seedLocalId);
382
+ await visit(t.item);
383
+ inProgress.delete(t.seedLocalId);
384
+ drafts.push({ item: t.item, via: prop, viaList: isList });
385
+ }
386
+ };
387
+ for (const prop of relationProperties)
388
+ await walk(prop, false);
389
+ for (const prop of listProperties)
390
+ await walk(prop, true);
391
+ };
392
+ await visit(root);
393
+ return { drafts, deferredProperties, backReferences };
394
+ }
395
+
396
+ var publishDraftGraph = /*#__PURE__*/Object.freeze({
397
+ __proto__: null,
398
+ draftWalkProperties: draftWalkProperties,
399
+ getPublishDraftGraph: getPublishDraftGraph,
400
+ getsNewSeed: getsNewSeed,
401
+ propertySeedRefs: propertySeedRefs
402
+ });
403
+
404
+ export { getSegmentedItemProperties as a, isUnpublishedSeed as b, isLivePublishedSeed as c, draftWalkProperties as d, findRelatedSeedRow as f, getPublishDraftGraph as g, htmlPropertyNameForHtmlSeed as h, isSeedRevoked as i, publishDraftGraph as p, relatedModelNameFromDef as r };
405
+ //# sourceMappingURL=publishDraftGraph-Bcfrdj7-.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publishDraftGraph-Bcfrdj7-.js","sources":["../../src/helpers/getSegmentedItemProperties.ts","../../src/db/read/isSeedRevoked.ts","../../src/db/read/resolveRelatedSeedRef.ts","../../src/db/read/publishDraftGraph.ts"],"sourcesContent":["import { UploadProperty } from '@/db/read/getPublishUploads'\nimport { IItem } from '@/interfaces'\nimport { ModelPropertyDataTypes, normalizeDataType } from '@/Schema'\nimport { getPropertySchema, TProperty } from '@/helpers/property'\nimport { getItemModelScope, resolveModelRecord, type ModelScope } from '@/db/read/resolveModelRecord'\nimport type { Static } from '@sinclair/typebox'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { models, properties } from '@/seedSchema'\nimport { eq, and } from 'drizzle-orm'\nimport { camelCase, upperFirst } from 'lodash-es'\n\nconst matchesDataType = (\n actual: string | undefined,\n expected: ModelPropertyDataTypes | string,\n): boolean => normalizeDataType(actual) === expected\nasync function resolvePropertyDef(\n modelName: string,\n propertyName: string,\n scope: ModelScope,\n): Promise<{ dataType?: string; ref?: string; refValueType?: string; storageType?: string; localStorageDir?: string; filenameSuffix?: string; required?: boolean } | undefined> {\n let schema = await getPropertySchema(modelName, propertyName, scope)\n if (schema) return schema\n const db = BaseDb.getAppDb()\n if (!db) return undefined\n try {\n const normalizedModelName = upperFirst(camelCase(modelName))\n const modelRecord = await resolveModelRecord(normalizedModelName, scope, db)\n const modelRecords = modelRecord ? [modelRecord] : []\n if (modelRecords.length === 0 || !modelRecords[0].id) return undefined\n const propertyRecords = await db\n .select()\n .from(properties)\n .where(\n and(\n eq(properties.modelId, modelRecords[0].id),\n eq(properties.name, propertyName),\n ),\n )\n .limit(1)\n if (propertyRecords.length === 0) return undefined\n const propRecord = propertyRecords[0]\n let refModelName: string | undefined\n if (propRecord.refModelId != null) {\n const refModelRows = await db\n .select({ name: models.name })\n .from(models)\n .where(eq(models.id, propRecord.refModelId))\n .limit(1)\n refModelName = refModelRows[0]?.name ?? undefined\n }\n return {\n dataType: propRecord.dataType,\n ref: refModelName ?? undefined,\n refValueType: propRecord.refValueType || undefined,\n storageType: propRecord.storageType || undefined,\n localStorageDir: propRecord.localStorageDir || undefined,\n filenameSuffix: propRecord.filenameSuffix || undefined,\n required: propRecord.required ?? undefined,\n }\n } catch {\n return undefined\n }\n}\n\nexport const getSegmentedItemProperties = async (item: IItem<any>) => {\n const itemBasicProperties = []\n const itemRelationProperties = []\n const itemListProperties = []\n const itemUploadProperties: UploadProperty[] = []\n const itemImageProperties = []\n const itemStorageProperties = []\n let itemStorageTransactionProperty: UploadProperty | undefined\n let itemScope: ModelScope | undefined\n\n for (const itemProperty of item.properties) {\n let propertyDef = itemProperty.propertyDef\n // When propertyDef is missing (e.g. external app, Model not registered), resolve inline\n // so properties are not skipped and metadata attestations can be created\n if (!propertyDef && item.modelName) {\n itemScope ??= await getItemModelScope(item as any)\n const resolved = await resolvePropertyDef(item.modelName, itemProperty.propertyName, itemScope)\n if (resolved) {\n itemProperty.getService().send({ type: 'updateContext', propertyRecordSchema: resolved })\n propertyDef = resolved as Static<typeof TProperty>\n } else {\n // Last resort: Model and DB don't have schema. Use Text so property routes to\n // itemBasicProperties and can be attested (covers title, description, etc.)\n const fallbackDef = { dataType: 'Text' as const }\n itemProperty.getService().send({ type: 'updateContext', propertyRecordSchema: fallbackDef })\n propertyDef = fallbackDef as Static<typeof TProperty>\n }\n }\n if (!propertyDef) {\n continue\n }\n\n const isItemStorage =\n propertyDef.storageType &&\n propertyDef.storageType === 'ItemStorage'\n\n\n const isStorageTransaction =\n itemProperty.propertyName === 'storageTransactionId' ||\n itemProperty.propertyName === 'storage_transaction_id'\n\n const isStorageSeedType =\n matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.Image) ||\n matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.File) ||\n matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.Html) ||\n matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.Json) ||\n (matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.Relation) &&\n (matchesDataType(propertyDef.refValueType, ModelPropertyDataTypes.Image) ||\n matchesDataType(propertyDef.refValueType, ModelPropertyDataTypes.File) ||\n matchesDataType(propertyDef.refValueType, ModelPropertyDataTypes.Html) ||\n matchesDataType(propertyDef.refValueType, ModelPropertyDataTypes.Json)))\n\n if (isStorageSeedType) {\n itemImageProperties.push(itemProperty)\n if (matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.Relation)) {\n itemRelationProperties.push(itemProperty)\n }\n continue\n }\n\n if (matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.Relation)) {\n itemRelationProperties.push(itemProperty)\n continue\n }\n\n if (matchesDataType(propertyDef.dataType, ModelPropertyDataTypes.List)) {\n // List-of-relations: ref present, goes to processListProperty\n // List-of-primitives: ref absent, treat as basic property\n const listRef =\n propertyDef.ref || (propertyDef as { refModelName?: string }).refModelName\n if (listRef) {\n itemListProperties.push(itemProperty)\n } else {\n itemBasicProperties.push(itemProperty)\n }\n continue\n }\n\n if (isItemStorage) {\n itemStorageProperties.push(itemProperty)\n continue\n }\n\n if (isStorageTransaction) {\n itemStorageTransactionProperty = { itemProperty, childProperties: [] }\n continue\n }\n\n itemBasicProperties.push(itemProperty)\n }\n\n if (itemStorageTransactionProperty && itemStorageProperties.length > 0) {\n itemStorageTransactionProperty.childProperties = itemStorageProperties\n }\n\n if (itemStorageTransactionProperty) {\n itemUploadProperties.push(itemStorageTransactionProperty)\n }\n\n return {\n itemBasicProperties,\n itemRelationProperties,\n itemListProperties,\n itemUploadProperties,\n itemImageProperties,\n }\n}\n","import { BaseDb } from '@/db/Db/BaseDb'\nimport { seeds } from '@/seedSchema'\nimport { eq } from 'drizzle-orm'\nimport { isVersionRevoked } from './subqueries/liveVersion'\n\n/**\n * True when the item's seed attestation was revoked (`seeds.revoked_at` set, by unpublish or EAS\n * sync). Such a seed can't take new versions: publishing again creates a new seed attestation\n * (see \"Republishing\" in docs/ATTESTATION_REVOCATION.md).\n */\nexport const isSeedRevoked = async (seedLocalId: string | undefined): Promise<boolean> => {\n if (!seedLocalId) return false\n const appDb = BaseDb.getAppDb()\n if (!appDb) return false\n const [row] = await appDb\n .select({ revokedAt: seeds.revokedAt })\n .from(seeds)\n .where(eq(seeds.localId, seedLocalId))\n .limit(1)\n return isVersionRevoked(row?.revokedAt)\n}\n","import { BaseDb } from '@/db/Db/BaseDb'\nimport { seeds, versions } from '@/seedSchema'\nimport { and, eq, isNotNull } from 'drizzle-orm'\nimport { ZERO_BYTES32 } from '@/helpers/constants'\nimport { isVersionRevoked } from './subqueries/liveVersion'\nimport { ModelPropertyDataTypes, normalizeDataType } from '@/helpers/property'\nimport type { IItem } from '@/interfaces'\n\nexport type RelatedSeedRow = {\n seedLocalId: string\n /** The seed's current uid (null while it was never published). */\n seedUid: string | null\n revokedAt: number | null\n type: string | null\n}\n\nconst selectSeed = {\n seedLocalId: seeds.localId,\n seedUid: seeds.uid,\n revokedAt: seeds.revokedAt,\n type: seeds.type,\n}\n\n/**\n * The local seed row a relation/list/image ref points at, by local id or uid. A uid that is no\n * seed's current uid can be the old uid of a seed that was unpublished and published again (a new\n * seed attestation, same local seed): its old version rows still record it, so it resolves to that\n * seed. Null when nothing local matches (e.g. a published uid with no local copy).\n */\nexport const findRelatedSeedRow = async ({\n seedLocalId,\n seedUid,\n}: {\n seedLocalId?: string\n seedUid?: string\n}): Promise<RelatedSeedRow | null> => {\n const appDb = BaseDb.getAppDb()\n if (!appDb) return null\n if (seedLocalId) {\n const [row] = await appDb.select(selectSeed).from(seeds).where(eq(seeds.localId, seedLocalId)).limit(1)\n if (row?.seedLocalId) return row as RelatedSeedRow\n }\n if (!seedUid || seedUid === ZERO_BYTES32) return null\n const [byUid] = await appDb.select(selectSeed).from(seeds).where(eq(seeds.uid, seedUid)).limit(1)\n if (byUid?.seedLocalId) return byUid as RelatedSeedRow\n const [version] = await appDb\n .select({ seedLocalId: versions.seedLocalId })\n .from(versions)\n .where(and(eq(versions.seedUid, seedUid), isNotNull(versions.seedLocalId)))\n .limit(1)\n if (!version?.seedLocalId) return null\n const [republished] = await appDb\n .select(selectSeed)\n .from(seeds)\n .where(eq(seeds.localId, version.seedLocalId))\n .limit(1)\n return republished?.seedLocalId ? (republished as RelatedSeedRow) : null\n}\n\n/** The seed is attested and its attestation is live. */\nexport const isLivePublishedSeed = (row: RelatedSeedRow | null): row is RelatedSeedRow & { seedUid: string } =>\n !!row?.seedUid && row.seedUid !== ZERO_BYTES32 && !isVersionRevoked(row.revokedAt)\n\n/** The seed was attested and that attestation was revoked (unpublished). */\nexport const isUnpublishedSeed = (row: RelatedSeedRow | null): row is RelatedSeedRow & { seedUid: string } =>\n !!row?.seedUid && row.seedUid !== ZERO_BYTES32 && isVersionRevoked(row.revokedAt)\n\n/** Model a relation/list/image property points at, from its definition. */\nexport function relatedModelNameFromDef(propertyDef: unknown): string | undefined {\n const def = propertyDef as { dataType?: string; ref?: string; refModelName?: string } | undefined\n if (!def) return undefined\n const dataType = normalizeDataType(def.dataType)\n if (dataType === ModelPropertyDataTypes.Image) return 'Image'\n if (dataType === ModelPropertyDataTypes.File) return 'File'\n if (dataType === ModelPropertyDataTypes.Html) return 'Html'\n return def.ref ?? def.refModelName\n}\n\n/**\n * Name of the item's Html property whose value is the Html seed `htmlSeedLocalId`: the property\n * that refers to the images embedded in that Html (htmlEmbeddedImageCoPublish rows).\n */\nexport function htmlPropertyNameForHtmlSeed(item: IItem<any>, htmlSeedLocalId: string): string {\n const want = htmlSeedLocalId.trim()\n for (const p of item.properties ?? []) {\n if (normalizeDataType(p.propertyDef?.dataType) !== ModelPropertyDataTypes.Html) continue\n const snap = p.getService().getSnapshot()\n const value = 'context' in snap ? (snap.context as { propertyValue?: unknown }).propertyValue : undefined\n if (typeof value === 'string' && value.trim() === want) return p.propertyName\n }\n return 'html'\n}\n","import { ZERO_BYTES32 } from '@/helpers/constants'\nimport { parseListPropertyValueFromStorage } from '@/helpers/listPropertyValueFromStorage'\nimport { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'\nimport {\n isPublishedSeedRef,\n normalizeRelationPropertyValue,\n resolveSeedIdsFromRefString,\n} from '@/helpers/relationSeedRef'\nimport type { IItem, IItemProperty } from '@/interfaces'\nimport { findRelatedSeedRow } from '@/db/read/resolveRelatedSeedRef'\nimport { isSeedRevoked } from '@/db/read/isSeedRevoked'\n\n/**\n * The draft items a publish of an item carries along, and how it walks to them.\n *\n * A publish attests the item and every draft item (no seed uid yet) reachable from it through\n * relation and list-of-relation properties, each with its full property set. Already-published\n * targets are referenced by their current uid and not walked into; revoked ones stop the publish\n * (RelatedItemUnpublishedError). getPublishPayload, getPublishUploads, getPublishUploadData (publish\n * package), summarizePublishWork and the Html-embedded image co-publish all walk this graph in the\n * same order: depth first, properties in item order (relations, then lists), list members in order.\n *\n * Cycles: an item can only attest the uid of a seed published before it in the same publish, so a\n * ref back to an item still being walked (an ancestor that gets a new seed in this publish) can't be\n * attested. Such a property is deferred: left out of this publish (it keeps no uid, so the next\n * publish of its item attests it, with the target's uid). For A ↔ B reached from A, A attests B's\n * uid and B's relation to A is deferred.\n */\n\n/** Relation properties that point at model items (not Image/File/Html/Json storage seeds). */\nexport function draftWalkProperties(segmented: {\n itemRelationProperties: IItemProperty<any>[]\n itemImageProperties: IItemProperty<any>[]\n itemListProperties: IItemProperty<any>[]\n}): { relationProperties: IItemProperty<any>[]; listProperties: IItemProperty<any>[] } {\n const storage = new Set(segmented.itemImageProperties)\n return {\n relationProperties: segmented.itemRelationProperties.filter((p) => !storage.has(p)),\n listProperties: segmented.itemListProperties,\n }\n}\n\nconst propertyContext = (prop: IItemProperty<any>): Record<string, unknown> | null => {\n const snapshot = prop.getService().getSnapshot()\n return snapshot && 'context' in snapshot\n ? ((snapshot as { context?: Record<string, unknown> }).context ?? null)\n : null\n}\n\n/** Seed refs held by a relation property (one) or a list property (each member). */\nexport function propertySeedRefs(prop: IItemProperty<any>, isList: boolean): string[] {\n const context = propertyContext(prop)\n if (!context) return []\n let value = context.propertyValue\n if (isList) {\n if (typeof value === 'string') value = parseListPropertyValueFromStorage(value)\n const arr = Array.isArray(value) ? value : value != null ? [value] : []\n return arr\n .map((v) =>\n v && typeof v === 'object'\n ? normalizeRelationPropertyValue(\n (v as { seedLocalId?: string; localId?: string }).seedLocalId ??\n (v as { localId?: string }).localId ??\n (v as { seedUid?: string }).seedUid ??\n (v as { uid?: string }).uid,\n )\n : normalizeRelationPropertyValue(v),\n )\n .filter((v): v is string => !!v)\n }\n const ref = normalizeRelationPropertyValue(value)\n return ref ? [ref] : []\n}\n\nconst isZeroUid = (uid: string | undefined | null): boolean => !uid || uid === ZERO_BYTES32\n\n/** The item gets a new seed attestation in this publish: a draft, or a revoked seed published again. */\nexport async function getsNewSeed(item: IItem<any>): Promise<boolean> {\n return isZeroUid(item.seedUid) || (await isSeedRevoked(item.seedLocalId))\n}\n\n/** Local seed id a ref points at (also for a republished seed's old uid), or undefined. */\nexport async function resolveRefSeedLocalId(ref: string): Promise<string | undefined> {\n const { seedLocalId, seedUid } = resolveSeedIdsFromRefString(ref)\n if (!seedLocalId && !seedUid) return undefined\n const row = await findRelatedSeedRow({ seedLocalId, seedUid })\n return row?.seedLocalId ?? seedLocalId\n}\n\nexport type PublishDraftGraphNode = {\n item: IItem<any>\n /** The relation or list property the walk first reached the item through. */\n via: IItemProperty<any>\n viaList: boolean\n}\n\nexport type PublishDraftGraph = {\n /** Draft items reachable from the root (root excluded), in the order the walk finishes them. */\n drafts: PublishDraftGraphNode[]\n /** Properties pointing back at an item still being walked; left out of this publish. */\n deferredProperties: Set<IItemProperty<any>>\n /** For each deferred property, the seeds (local ids) of its back references. */\n backReferences: Map<IItemProperty<any>, Set<string>>\n}\n\nexport type GetPublishDraftGraphOptions = {\n /** `new_version` / republish: properties that already have a uid are attested (and walked) again. */\n forceFullSnapshot?: boolean\n /**\n * Throw like getPublishUploads always did when a relation holds an invalid value or a local id\n * with no local item. Otherwise such refs are skipped (getPublishPayload reports them).\n */\n strict?: boolean\n}\n\n/** Would the publish attest this property (so walk its refs)? Same rule as getPublishPayload. */\nfunction walksProperty(prop: IItemProperty<any>, forceFullSnapshot: boolean): boolean {\n if (prop.uid && !forceFullSnapshot) return false\n const ctx = propertyContext(prop)\n const value = ctx?.propertyValue\n return value != null && value !== '' && !(Array.isArray(value) && value.length === 0)\n}\n\nasync function loadItem(seedLocalId: string): Promise<IItem<any> | undefined> {\n const { getItem } = await import('./getItem')\n try {\n return (await getItem({ seedLocalId })) ?? undefined\n } catch {\n return undefined\n }\n}\n\nexport async function getPublishDraftGraph(\n root: IItem<any>,\n options?: GetPublishDraftGraphOptions,\n): Promise<PublishDraftGraph> {\n const forceFullSnapshot = options?.forceFullSnapshot === true\n const strict = options?.strict === true\n const drafts: PublishDraftGraphNode[] = []\n const deferredProperties = new Set<IItemProperty<any>>()\n const backReferences = new Map<IItemProperty<any>, Set<string>>()\n const visited = new Set<string>([root.seedLocalId])\n const inProgress = new Set<string>()\n if (await getsNewSeed(root)) inProgress.add(root.seedLocalId)\n\n /** Draft target of a ref, or undefined (published, revoked, unknown). */\n const draftTarget = async (\n prop: IItemProperty<any>,\n ref: string,\n isList: boolean,\n ): Promise<{ seedLocalId: string; item?: IItem<any> } | undefined> => {\n const { seedLocalId, seedUid } = resolveSeedIdsFromRefString(ref)\n if (!seedLocalId && !seedUid) {\n if (strict && !isList) {\n throw new Error(`Invalid relation value for ${prop.propertyName}: expected local seed id or 0x uid`)\n }\n return undefined\n }\n const row = await findRelatedSeedRow({ seedLocalId, seedUid })\n const targetLocalId = row?.seedLocalId ?? seedLocalId\n if (!targetLocalId) return undefined\n // An item getting a new seed in this publish, still being walked (also the root when it is a\n // revoked seed published again): a back edge, whatever its current uid.\n if (inProgress.has(targetLocalId)) return { seedLocalId: targetLocalId }\n // Published (live or revoked): referenced by uid / reported, never walked into.\n if (row && !isZeroUid(row.seedUid)) return undefined\n if (visited.has(targetLocalId)) return { seedLocalId: targetLocalId }\n const item = await loadItem(targetLocalId)\n if (!item) {\n if (strict && !isList && !isPublishedSeedRef(ref)) {\n throw new Error(`No relatedItem found for ${prop.propertyName}`)\n }\n return undefined\n }\n if (!isZeroUid(item.seedUid)) return undefined\n return { seedLocalId: targetLocalId, item }\n }\n\n const visit = async (item: IItem<any>): Promise<void> => {\n const segmented = await getSegmentedItemProperties(item)\n const { relationProperties, listProperties } = draftWalkProperties(segmented)\n const walk = async (prop: IItemProperty<any>, isList: boolean) => {\n if (!walksProperty(prop, forceFullSnapshot)) return\n const targets: { seedLocalId: string; item?: IItem<any> }[] = []\n for (const ref of propertySeedRefs(prop, isList)) {\n const t = await draftTarget(prop, ref, isList)\n if (t) targets.push(t)\n }\n const back = targets.filter((t) => inProgress.has(t.seedLocalId)).map((t) => t.seedLocalId)\n if (back.length > 0) {\n deferredProperties.add(prop)\n backReferences.set(prop, new Set(back))\n }\n for (const t of targets) {\n if (!t.item || visited.has(t.seedLocalId)) continue\n visited.add(t.seedLocalId)\n inProgress.add(t.seedLocalId)\n await visit(t.item)\n inProgress.delete(t.seedLocalId)\n drafts.push({ item: t.item, via: prop, viaList: isList })\n }\n }\n for (const prop of relationProperties) await walk(prop, false)\n for (const prop of listProperties) await walk(prop, true)\n }\n\n await visit(root)\n return { drafts, deferredProperties, backReferences }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAWA,MAAM,eAAe,GAAG,CACtB,MAA0B,EAC1B,QAAyC,KAC7B,iBAAiB,CAAC,MAAM,CAAC,KAAK,QAAQ;AACpD,eAAe,kBAAkB,CAC/B,SAAiB,EACjB,YAAoB,EACpB,KAAiB,EAAA;IAEjB,IAAI,MAAM,GAAG,MAAM,iBAAiB,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC;AACpE,IAAA,IAAI,MAAM;AAAE,QAAA,OAAO,MAAM;AACzB,IAAA,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE;AAC5B,IAAA,IAAI,CAAC,EAAE;AAAE,QAAA,OAAO,SAAS;AACzB,IAAA,IAAI;QACF,MAAM,mBAAmB,GAAG,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC5D,MAAM,WAAW,GAAG,MAAM,kBAAkB,CAAC,mBAAmB,EAAE,KAAK,EAAE,EAAE,CAAC;AAC5E,QAAA,MAAM,YAAY,GAAG,WAAW,GAAG,CAAC,WAAW,CAAC,GAAG,EAAE;AACrD,QAAA,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE;AAAE,YAAA,OAAO,SAAS;QACtE,MAAM,eAAe,GAAG,MAAM;AAC3B,aAAA,MAAM;aACN,IAAI,CAAC,UAAU;aACf,KAAK,CACJ,GAAG,CACD,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAC1C,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,YAAY,CAAC,CAClC;aAEF,KAAK,CAAC,CA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A,MAAM,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC;AAC3D,IAAA,CAAC;AAED,IAAA,MAAM,KAAK,CAAC,IAAI,CAAC;AACjB,IAAA,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE;AACvD;;;;;;;;;;"}
@@ -1,7 +1,7 @@
1
1
  import { eq, and, isNull, isNotNull } from 'drizzle-orm';
2
2
  import { toSnakeCase } from 'drizzle-orm/casing';
3
3
  import debug from 'debug';
4
- import { B as BaseDb, c as appState, r as seeds, s as schemas, m as models, i as modelSchemas, h as htmlEmbeddedImageCoPublish, d as arweaveL1FinalizeJobs, u as uploadProcesses, q as publishProcesses, f as easSyncProcesses, b as metadata, v as versions } from './BasePathResolver-ndE8XTpw.js';
4
+ import { a as BaseDb, b as appState, r as seeds, s as schemas, j as models, g as modelSchemas, h as htmlEmbeddedImageCoPublish, c as arweaveL1FinalizeJobs, u as uploadProcesses, q as publishProcesses, e as easSyncProcesses, m as metadata, v as versions } from './BasePathResolver-BdxCSIzn.js';
5
5
  import 'drizzle-orm/sqlite-core';
6
6
  import '@seedprotocol/arweave';
7
7
 
@@ -85,4 +85,4 @@ const resetAmbiguousLegacyItemData = async () => {
85
85
  };
86
86
 
87
87
  export { LEGACY_ITEM_MODEL_CHECK_KEY, resetAmbiguousLegacyItemData };
88
- //# sourceMappingURL=resetAmbiguousLegacyItemData-BqbHNUYk.js.map
88
+ //# sourceMappingURL=resetAmbiguousLegacyItemData-Ci6PM_vC.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resetAmbiguousLegacyItemData-BqbHNUYk.js","sources":["../../src/db/resetAmbiguousLegacyItemData.ts"],"sourcesContent":["import { eq, isNotNull, isNull, and } from 'drizzle-orm'\nimport { toSnakeCase } from 'drizzle-orm/casing'\nimport debug from 'debug'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport {\n appState,\n arweaveL1FinalizeJobs,\n easSyncProcesses,\n htmlEmbeddedImageCoPublish,\n metadata,\n models,\n publishProcesses,\n schemas,\n seeds,\n uploadProcesses,\n modelSchemas,\n versions,\n} from '@/seedSchema'\n\nconst logger = debug('seedSdk:db:resetAmbiguousLegacyItemData')\n\n/** appState key recording that the one-time check after migration 0015 has run. */\nexport const LEGACY_ITEM_MODEL_CHECK_KEY = 'legacyItemModelCheck:v1'\n\n/**\n * One-time check after seeds.model_file_id was introduced (migration 0015). Seeds from before then\n * that couldn't be backfilled have no model; if their model name now exists in more than one schema\n * there is no way to tell which model they belong to. In that case the local item data (seeds,\n * versions, metadata and the jobs that reference them) is cleared, keeping schemas and models;\n * published items come back on the next EAS sync.\n *\n * Runs once (not on every start): EAS-synced seeds also lack model_file_id until\n * resolveModelForSyncedSeed exists, and re-checking would clear the DB after every sync.\n * TODO: replace the reset with a migration path once there is real user data at stake.\n *\n * @returns true if item data was cleared\n */\nexport const resetAmbiguousLegacyItemData = async (): Promise<boolean> => {\n const db = BaseDb.getAppDb()\n if (!db) return false\n\n const done = await db.select({ key: appState.key }).from(appState).where(eq(appState.key, LEGACY_ITEM_MODEL_CHECK_KEY)).limit(1)\n if (done.length > 0) return false\n\n const markDone = () =>\n db\n .insert(appState)\n .values({ key: LEGACY_ITEM_MODEL_CHECK_KEY, value: String(Date.now()), createdAt: Date.now(), updatedAt: Date.now() })\n .onConflictDoNothing()\n\n const legacyTypes = (await db\n .selectDistinct({ type: seeds.type })\n .from(seeds)\n .where(and(isNull(seeds.modelFileId), isNotNull(seeds.type)))) as { type: string }[]\n if (legacyTypes.length === 0) {\n await markDone()\n return false\n }\n\n // Which seed types (snake_case model names) map to models in more than one schema\n const linkedModels = (await db\n .select({ modelId: models.id, modelName: models.name, schemaName: schemas.name })\n .from(models)\n .innerJoin(modelSchemas, eq(models.id, modelSchemas.modelId))\n .innerJoin(schemas, eq(modelSchemas.schemaId, schemas.id))) as {\n modelId: number\n modelName: string\n schemaName: string\n }[]\n const byType = new Map<string, { modelIds: Set<number>; schemaNames: Set<string> }>()\n for (const row of linkedModels) {\n const type = toSnakeCase(row.modelName)\n const entry = byType.get(type) ?? { modelIds: new Set(), schemaNames: new Set() }\n entry.modelIds.add(row.modelId)\n entry.schemaNames.add(row.schemaName)\n byType.set(type, entry)\n }\n const ambiguous = legacyTypes\n .map(({ type }) => ({ type, entry: byType.get(type) }))\n .filter(({ entry }) => entry && entry.modelIds.size > 1)\n\n if (ambiguous.length === 0) {\n await markDone()\n return false\n }\n\n const details = ambiguous\n .map(({ type, entry }) => `\"${type}\" (schemas: ${[...entry!.schemaNames].sort().join(', ')})`)\n .join('; ')\n console.warn(\n `[seed-protocol] Clearing local item data: items created before this SDK version don't record ` +\n `which model they belong to, and these model names now exist in more than one schema: ${details}. ` +\n `Schemas and models are kept; published items will be restored by the next EAS sync.`,\n )\n logger(`Clearing item data for ambiguous legacy seed types: ${details}`)\n\n for (const table of [\n htmlEmbeddedImageCoPublish,\n arweaveL1FinalizeJobs,\n uploadProcesses,\n publishProcesses,\n easSyncProcesses,\n metadata,\n versions,\n seeds,\n ]) {\n await db.delete(table)\n }\n await markDone()\n return true\n}\n"],"names":[],"mappings":";;;;;;;AAmBA,MAAM,MAAM,GAAG,KAAK,CAAC,yCAAyC,CAAC;AAE/D;AACO,MAAM,2BAA2B,GAAG;AAE3C;;;;;;;;;;;;AAYG;AACI,MAAM,4BAA4B,GAAG,YAA6B;AACvE,IAAA,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE;AAC5B,IAAA,IAAI,CAAC,EAAE;AAAE,QAAA,OAAO,KAAK;AAErB,IAAA,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,2BAA2B,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAChI,IAAA,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;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ClB,0BAA0B;QAC1B,qBAAqB;QACrB,eAAe;QACf,gBAAgB;QAChB,gBAAgB;QAChB,QAAQ;QACR,QAAQ;QACR,KAAK;AACN,KAAA,EAAE;AACD,QAAA,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;IACxB;IACA,MAAM,QAAQ,EAAE;AAChB,IAAA,OAAO,IAAI;AACb;;"}
1
+ {"version":3,"file":"resetAmbiguousLegacyItemData-Ci6PM_vC.js","sources":["../../src/db/resetAmbiguousLegacyItemData.ts"],"sourcesContent":["import { eq, isNotNull, isNull, and } from 'drizzle-orm'\nimport { toSnakeCase } from 'drizzle-orm/casing'\nimport debug from 'debug'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport {\n appState,\n arweaveL1FinalizeJobs,\n easSyncProcesses,\n htmlEmbeddedImageCoPublish,\n metadata,\n models,\n publishProcesses,\n schemas,\n seeds,\n uploadProcesses,\n modelSchemas,\n versions,\n} from '@/seedSchema'\n\nconst logger = debug('seedSdk:db:resetAmbiguousLegacyItemData')\n\n/** appState key recording that the one-time check after migration 0015 has run. */\nexport const LEGACY_ITEM_MODEL_CHECK_KEY = 'legacyItemModelCheck:v1'\n\n/**\n * One-time check after seeds.model_file_id was introduced (migration 0015). Seeds from before then\n * that couldn't be backfilled have no model; if their model name now exists in more than one schema\n * there is no way to tell which model they belong to. In that case the local item data (seeds,\n * versions, metadata and the jobs that reference them) is cleared, keeping schemas and models;\n * published items come back on the next EAS sync.\n *\n * Runs once (not on every start): EAS-synced seeds also lack model_file_id until\n * resolveModelForSyncedSeed exists, and re-checking would clear the DB after every sync.\n * TODO: replace the reset with a migration path once there is real user data at stake.\n *\n * @returns true if item data was cleared\n */\nexport const resetAmbiguousLegacyItemData = async (): Promise<boolean> => {\n const db = BaseDb.getAppDb()\n if (!db) return false\n\n const done = await db.select({ key: appState.key }).from(appState).where(eq(appState.key, LEGACY_ITEM_MODEL_CHECK_KEY)).limit(1)\n if (done.length > 0) return false\n\n const markDone = () =>\n db\n .insert(appState)\n .values({ key: LEGACY_ITEM_MODEL_CHECK_KEY, value: String(Date.now()), createdAt: Date.now(), updatedAt: Date.now() })\n .onConflictDoNothing()\n\n const legacyTypes = (await db\n .selectDistinct({ type: seeds.type })\n .from(seeds)\n .where(and(isNull(seeds.modelFileId), isNotNull(seeds.type)))) as { type: string }[]\n if (legacyTypes.length === 0) {\n await markDone()\n return false\n }\n\n // Which seed types (snake_case model names) map to models in more than one schema\n const linkedModels = (await db\n .select({ modelId: models.id, modelName: models.name, schemaName: schemas.name })\n .from(models)\n .innerJoin(modelSchemas, eq(models.id, modelSchemas.modelId))\n .innerJoin(schemas, eq(modelSchemas.schemaId, schemas.id))) as {\n modelId: number\n modelName: string\n schemaName: string\n }[]\n const byType = new Map<string, { modelIds: Set<number>; schemaNames: Set<string> }>()\n for (const row of linkedModels) {\n const type = toSnakeCase(row.modelName)\n const entry = byType.get(type) ?? { modelIds: new Set(), schemaNames: new Set() }\n entry.modelIds.add(row.modelId)\n entry.schemaNames.add(row.schemaName)\n byType.set(type, entry)\n }\n const ambiguous = legacyTypes\n .map(({ type }) => ({ type, entry: byType.get(type) }))\n .filter(({ entry }) => entry && entry.modelIds.size > 1)\n\n if (ambiguous.length === 0) {\n await markDone()\n return false\n }\n\n const details = ambiguous\n .map(({ type, entry }) => `\"${type}\" (schemas: ${[...entry!.schemaNames].sort().join(', ')})`)\n .join('; ')\n console.warn(\n `[seed-protocol] Clearing local item data: items created before this SDK version don't record ` +\n `which model they belong to, and these model names now exist in more than one schema: ${details}. ` +\n `Schemas and models are kept; published items will be restored by the next EAS sync.`,\n )\n logger(`Clearing item data for ambiguous legacy seed types: ${details}`)\n\n for (const table of [\n htmlEmbeddedImageCoPublish,\n arweaveL1FinalizeJobs,\n uploadProcesses,\n publishProcesses,\n easSyncProcesses,\n metadata,\n versions,\n seeds,\n ]) {\n await db.delete(table)\n }\n await markDone()\n return true\n}\n"],"names":[],"mappings":";;;;;;;AAmBA,MAAM,MAAM,GAA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OAAO,KAAK;IACd;IAEA,MAAM,OAAO,GAAG;AACb,SAAA,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAA,CAAA,EAAI,IAAI,CAAA,YAAA,EAAe,CAAC,GAAG,KAAM,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,CAAA,CAAG;SAC5F,IAAI,CAAC,IAAI,CAAC;IACb,OAAO,CAAC,IAAI,CACV,CAAA,6FAAA,CAA+F;AAC7F,QAAA,CAAA,qFAAA,EAAwF,OAAO,CAAA,EAAA,CAAI;AACnG,QAAA,CAAA,mFAAA,CAAqF,CACxF;AACD,IAAA,MAAM,CAAC,CAAA,oDAAA,EAAuD,OAAO,CAAA,CAAE,CAAC;IAExE,KAAK,MAAM,KAAK,IAAI;QAClB,0BAA0B;QAC1B,qBAAqB;QACrB,eAAe;QACf,gBAAgB;QAChB,gBAAgB;QAChB,QAAQ;QACR,QAAQ;QACR,KAAK;AACN,KAAA,EAAE;AACD,QAAA,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;IACxB;IACA,MAAM,QAAQ,EAAE;AAChB,IAAA,OAAO,IAAI;AACb;;"}
@@ -1,5 +1,5 @@
1
1
  import debug from 'debug';
2
- import { A as AmbiguousModelError, o as eventEmitter } from './db-BJZN0a0a.js';
2
+ import { A as AmbiguousModelError, m as eventEmitter } from './db-W1g29qsM.js';
3
3
 
4
4
  const logger = debug('seedSdk:db:read:resolveModelForSyncedSeed');
5
5
  /** Emitted when background work skips a seed whose model name exists in several schemas. */
@@ -43,4 +43,4 @@ const skipSeedOnAmbiguousModel = async (seed, context, work) => {
43
43
  };
44
44
 
45
45
  export { MODEL_AMBIGUOUS_EVENT as M, resolveModelForSyncedSeed as r, skipSeedOnAmbiguousModel as s };
46
- //# sourceMappingURL=resolveModelForSyncedSeed-DQK6JfXS.js.map
46
+ //# sourceMappingURL=resolveModelForSyncedSeed-CLlumTBq.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveModelForSyncedSeed-DQK6JfXS.js","sources":["../../src/db/read/resolveModelForSyncedSeed.ts"],"sourcesContent":["import debug from 'debug'\nimport { eventEmitter } from '@/eventBus'\nimport { AmbiguousModelError } from '@/Model/errors'\n\nconst logger = debug('seedSdk:db:read:resolveModelForSyncedSeed')\n\n/** Emitted when background work skips a seed whose model name exists in several schemas. */\nexport const MODEL_AMBIGUOUS_EVENT = 'model:ambiguous' as const\n\nexport type ModelAmbiguousEventPayload = {\n modelName: string\n schemaNames: string[]\n seedLocalId?: string\n seedUid?: string\n /** What was being done when the seed was skipped (e.g. 'easSync.metadata'). */\n context: string\n}\n\nexport type SyncedSeedInfo = {\n seedUid?: string | null\n seedLocalId?: string | null\n /** seeds.type as synced from EAS (the EAS schema name, i.e. snake_case model name). */\n modelType?: string | null\n /** EAS schema UID of the seed attestation. */\n schemaUid?: string | null\n}\n\n/**\n * Seam for matching an EAS-synced seed to a local model (its schemaFileId).\n *\n * EAS identifies a seed's model only by name (`bytes32 <model_name>`), so when several local schemas\n * define a model with that name the seed alone can't say which one it is. The plan is to match by\n * the seed's properties and metadata (see docs/EAS_SYNCED_SEED_MODEL_RESOLUTION.md).\n *\n * TODO(eas-synced-seed-model-resolution): not implemented yet. Returns undefined, so callers fall\n * back to the name, which throws AmbiguousModelError when the name is ambiguous.\n */\nexport const resolveModelForSyncedSeed = async (_seed: SyncedSeedInfo): Promise<string | undefined> => {\n return undefined\n}\n\n/**\n * Run background work for one seed; if it hits an ambiguous model name, log, emit\n * MODEL_AMBIGUOUS_EVENT and return undefined (skip) instead of failing the whole job. Loading the\n * item directly still throws, so the problem surfaces where the app touches it.\n */\nexport const skipSeedOnAmbiguousModel = async <T>(\n seed: { seedLocalId?: string | null; seedUid?: string | null },\n context: string,\n work: () => Promise<T>,\n): Promise<T | undefined> => {\n try {\n return await work()\n } catch (error) {\n if (!(error instanceof AmbiguousModelError)) throw error\n logger(`Skipping seed ${seed.seedLocalId ?? seed.seedUid} in ${context}: ${error.message}`)\n const payload: ModelAmbiguousEventPayload = {\n modelName: error.modelName,\n schemaNames: error.schemaNames,\n seedLocalId: seed.seedLocalId ?? undefined,\n seedUid: seed.seedUid ?? undefined,\n context,\n }\n eventEmitter.emit(MODEL_AMBIGUOUS_EVENT, payload)\n return undefined\n }\n}\n"],"names":[],"mappings":";;;AAIA,MAAM,MAAM,GAAG,KAAK,CAAC,2CAA2C,CAAC;AAEjE;AACO,MAAM,qBAAqB,GAAG;AAoBrC;;;;;;;;;AASG;MACU,yBAAyB,GAAG,OAAO,KAAqB,KAAiC;AACpG,IAAA,OAAO,SAAS;AAClB;AAEA;;;;AAIG;AACI,MAAM,wBAAwB,GAAG,OACtC,IAA8D,EAC9D,OAAe,EACf,IAAsB,KACI;AAC1B,IAAA,IAAI;QACF,OAAO,MAAM,IAAI,EAAE;IACrB;IAAE,OAAO,KAAK,EAAE;AACd,QAAA,IAAI,EAAE,KAAK,YAAY,mBAAmB,CAAC;AAAE,YAAA,MAAM,KAAK;AACxD,QAAA,MAAM,CAAC,CAAA,cAAA,EAAiB,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,OAAO,CAAA,IAAA,EAAO,OAAO,CAAA,EAAA,EAAK,KAAK,CAAC,OAAO,CAAA,CAAE,CAAC;AAC3F,QAAA,MAAM,OAAO,GAA+B;YAC1C,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;AAC9B,YAAA,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,SAAS;AAC1C,YAAA,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,SAAS;YAClC,OAAO;SACR;AACD,QAAA,YAAY,CAAC,IAAI,CAAC,qBAAqB,EAAE,OAAO,CAAC;AACjD,QAAA,OAAO,SAAS;IAClB;AACF;;"}
1
+ {"version":3,"file":"resolveModelForSyncedSeed-CLlumTBq.js","sources":["../../src/db/read/resolveModelForSyncedSeed.ts"],"sourcesContent":["import debug from 'debug'\nimport { eventEmitter } from '@/eventBus'\nimport { AmbiguousModelError } from '@/Model/errors'\n\nconst logger = debug('seedSdk:db:read:resolveModelForSyncedSeed')\n\n/** Emitted when background work skips a seed whose model name exists in several schemas. */\nexport const MODEL_AMBIGUOUS_EVENT = 'model:ambiguous' as const\n\nexport type ModelAmbiguousEventPayload = {\n modelName: string\n schemaNames: string[]\n seedLocalId?: string\n seedUid?: string\n /** What was being done when the seed was skipped (e.g. 'easSync.metadata'). */\n context: string\n}\n\nexport type SyncedSeedInfo = {\n seedUid?: string | null\n seedLocalId?: string | null\n /** seeds.type as synced from EAS (the EAS schema name, i.e. snake_case model name). */\n modelType?: string | null\n /** EAS schema UID of the seed attestation. */\n schemaUid?: string | null\n}\n\n/**\n * Seam for matching an EAS-synced seed to a local model (its schemaFileId).\n *\n * EAS identifies a seed's model only by name (`bytes32 <model_name>`), so when several local schemas\n * define a model with that name the seed alone can't say which one it is. The plan is to match by\n * the seed's properties and metadata (see docs/EAS_SYNCED_SEED_MODEL_RESOLUTION.md).\n *\n * TODO(eas-synced-seed-model-resolution): not implemented yet. Returns undefined, so callers fall\n * back to the name, which throws AmbiguousModelError when the name is ambiguous.\n */\nexport const resolveModelForSyncedSeed = async (_seed: SyncedSeedInfo): Promise<string | undefined> => {\n return undefined\n}\n\n/**\n * Run background work for one seed; if it hits an ambiguous model name, log, emit\n * MODEL_AMBIGUOUS_EVENT and return undefined (skip) instead of failing the whole job. Loading the\n * item directly still throws, so the problem surfaces where the app touches it.\n */\nexport const skipSeedOnAmbiguousModel = async <T>(\n seed: { seedLocalId?: string | null; seedUid?: string | null },\n context: string,\n work: () => Promise<T>,\n): Promise<T | undefined> => {\n try {\n return await work()\n } catch (error) {\n if (!(error instanceof AmbiguousModelError)) throw error\n logger(`Skipping seed ${seed.seedLocalId ?? seed.seedUid} in ${context}: ${error.message}`)\n const payload: ModelAmbiguousEventPayload = {\n modelName: error.modelName,\n schemaNames: error.schemaNames,\n seedLocalId: seed.seedLocalId ?? undefined,\n seedUid: seed.seedUid ?? undefined,\n context,\n }\n eventEmitter.emit(MODEL_AMBIGUOUS_EVENT, payload)\n return undefined\n }\n}\n"],"names":[],"mappings":";;;AAIA,MAAM,MAAM,GAAG,KAAK,CAAC,2CAA2C,CAAC;AAEjE;AACO,MAAM,qBAAqB,GAAG;AAoBrC;;;;;;;;;AASG;MACU,yBAAyB,GAAG,OAAO,KAAqB,KAAiC;AACpG,IAAA,OAAO,SAAS;AAClB;AAEA;;;;AAIG;AACI,MAAM,wBAAwB,GAAG,OACtC,IAA8D,EAC9D,OAAe,EACf,IAAsB,KACI;AAC1B,IAAA,IAAI;QACF,OAAO,MAAM,IAAI,EAAE;IACrB;IAAE,OAAO,KAAK,EAAE;AACd,QAAA,IAAI,EAAE,KAAK,YAAY,mBAAmB,CAAC;AAAE,YAAA,MAAM,KAAK;AACxD,QAAA,MAAM,CAAC,CAAA,cAAA,EAAiB,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,OAAO,CAAA,IAAA,EAAO,OAAO,CAAA,EAAA,EAAK,KAAK,CAAC,OAAO,CAAA,CAAE,CAAC;AAC3F,QAAA,MAAM,OAAO,GAA+B;YAC1C,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;AAC9B,YAAA,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,SAAS;AAC1C,YAAA,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,SAAS;YAClC,OAAO;SACR;AACD,QAAA,YAAY,CAAC,IAAI,CAAC,qBAAqB,EAAE,OAAO,CAAC;AACjD,QAAA,OAAO,SAAS;IAClB;AACF;;"}
@@ -27,6 +27,17 @@ export declare class Item<T extends ModelValues<ModelSchema>> implements IItem<T
27
27
  */
28
28
  private static sendTrackedPropertyUpdate;
29
29
  private static releaseItemInstanceCacheHold;
30
+ /**
31
+ * Idle, and not the shell the item machine can be in when it reaches `idle` before
32
+ * `propertyInstances` is merged (an item with a version but no property instances yet).
33
+ */
34
+ private static isItemSnapshotReadyForRead;
35
+ /**
36
+ * The cached Item for a seedLocalId or seedUid when it can be read right now: idle and hydrated,
37
+ * so at least what `Item.find()` would wait for. Otherwise undefined. Unlike `getById`, it takes
38
+ * no cache hold, so React hooks can call it during render.
39
+ */
40
+ static peekReady(id: string | undefined): Item<any> | undefined;
30
41
  /**
31
42
  * Item machine can reach `idle` before `propertyInstances` is merged (race) or while
32
43
  * child ItemProperty actors are still hydrating. useItems / Item.all must not return that shell.
@@ -1 +1 @@
1
- {"version":3,"file":"Item.d.ts","sourceRoot":"","sources":["../../../src/Item/Item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AAWpE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAI3C,OAAO,EACL,2BAA2B,EAC3B,QAAQ,EACR,aAAa,EACb,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACb,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AACtC,OAAO,EACL,YAAY,EACZ,YAAY,EAKb,MAAM,QAAQ,CAAA;AAgHf,qBAAa,IAAI,CAAC,CAAC,SAAS,WAAW,CAAC,WAAW,CAAC,CAAE,YAAW,KAAK,CAAC,CAAC,CAAC;IAEvE,SAAS,CAAC,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAa;IACnG,SAAS,CAAC,aAAa,EAAE,YAAY,GAAG,SAAS,CAAC;IAClD,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MA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BAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,SAAS,GAAG,MAAM,EAAE;IAiClH;;;;;;;OAOG;IACH,SAAS,CAAC,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,OAAO;IA6B3E;;;OAGG;IACH,IAAI,UAAU,IAAI,aAAa,EAAE,CA6BhC;IAED;;;OAGG;IACH,IAAI,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAOtD;IAED;;;OAGG;IACH,IAAI,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAEjD;IAED,IAAI,oBAAoB,IAAI,MAAM,CAEjC;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,IAAI,sBAAsB,IAAI,MAAM,CAEnC;IAED,IAAI,SAAS,IAAI,MAAM,GAAG,SAAS,CAWlC;IAED;;;OAGG;IACH,OAAO,CAAC,2BAA2B;IAsWnC,MAAM,IAAI,IAAI;IA6Bd;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CA2B/B"}
@@ -55,6 +55,16 @@ export declare class ItemProperty<PropertyType> implements IItemProperty<Propert
55
55
  waitForReady?: true;
56
56
  readyTimeout?: number;
57
57
  }): Promise<ItemProperty<any> | undefined>;
58
+ /**
59
+ * The cached ItemProperty when it can be read right now (idle, not saving), the state
60
+ * `ItemProperty.find()` waits for. Otherwise undefined. Unlike `find`, it takes no cache hold, so
61
+ * React hooks can call it during render.
62
+ */
63
+ static peekReady({ propertyName, seedLocalId, seedUid, }: {
64
+ propertyName?: string;
65
+ seedLocalId?: string;
66
+ seedUid?: string;
67
+ }): ItemProperty<any> | undefined;
58
68
  static find({ propertyName, seedLocalId, seedUid, modelName: modelNameOption, waitForReady, readyTimeout, }: ItemPropertyFindProps & {
59
69
  waitForReady?: boolean;
60
70
  readyTimeout?: number;