@seedprotocol/sdk 0.7.4 → 0.7.5-next.871.g8788c94

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 (135) hide show
  1. package/README.md +99 -0
  2. package/dist/{BasePathResolver-DrzGVH9L.js → BasePathResolver-B-fK7_N_.js} +142 -8
  3. package/dist/BasePathResolver-B-fK7_N_.js.map +1 -0
  4. package/dist/{ClientManager-Dfu4jcgm.js → ClientManager-C7VkO5Hg.js} +342 -206
  5. package/dist/ClientManager-C7VkO5Hg.js.map +1 -0
  6. package/dist/{Item-BUUFuywT.js → Item-BDmsdNTQ.js} +234 -163
  7. package/dist/Item-BDmsdNTQ.js.map +1 -0
  8. package/dist/{ModelProperty-B6cnRvIz.js → ModelProperty-Cqw6yn7y.js} +37 -37
  9. package/dist/{ModelProperty-B6cnRvIz.js.map → ModelProperty-Cqw6yn7y.js.map} +1 -1
  10. package/dist/{Schema-Bf-jOLq0.js → Schema-BJLYOUgp.js} +57 -37
  11. package/dist/Schema-BJLYOUgp.js.map +1 -0
  12. package/dist/{SchemaValidationService-BNYMacsx.js → SchemaValidationService-CzybXLiS.js} +6 -6
  13. package/dist/{SchemaValidationService-BNYMacsx.js.map → SchemaValidationService-CzybXLiS.js.map} +1 -1
  14. package/dist/{backfillMetadataPropertyIds-C2-s_jUa.js → backfillMetadataPropertyIds-DAsETfD_.js} +3 -3
  15. package/dist/{backfillMetadataPropertyIds-C2-s_jUa.js.map → backfillMetadataPropertyIds-DAsETfD_.js.map} +1 -1
  16. package/dist/{configurePlatform-BzfirKuM.js → configurePlatform-CFQF_i1T.js} +2 -2
  17. package/dist/{configurePlatform-BzfirKuM.js.map → configurePlatform-CFQF_i1T.js.map} +1 -1
  18. package/dist/{detachRowsBeforeDelete-B0Daoz9Z.js → detachRowsBeforeDelete-D4gxxk46.js} +2 -2
  19. package/dist/{detachRowsBeforeDelete-B0Daoz9Z.js.map → detachRowsBeforeDelete-D4gxxk46.js.map} +1 -1
  20. package/dist/discardNewDraft-g8w3uHFM.js +78 -0
  21. package/dist/discardNewDraft-g8w3uHFM.js.map +1 -0
  22. package/dist/{eas-Dq5Kx_Nd.js → eas-BcXZ2hIn.js} +25 -12
  23. package/dist/eas-BcXZ2hIn.js.map +1 -0
  24. package/dist/{errors-DdWbxb_n.js → errors-CCMxedOB.js} +43 -38
  25. package/dist/errors-CCMxedOB.js.map +1 -0
  26. package/dist/{getItem-9bYSErSj.js → getItem-BUs1Xa48.js} +4 -4
  27. package/dist/{getItem-9bYSErSj.js.map → getItem-BUs1Xa48.js.map} +1 -1
  28. package/dist/{getPublishPayload-DPy-uMrR.js → getPublishPayload-CwNOhnir.js} +25 -15
  29. package/dist/getPublishPayload-CwNOhnir.js.map +1 -0
  30. package/dist/{getPublishUploads-J-143iSV.js → getPublishUploads-pEOrXJbF.js} +506 -45
  31. package/dist/getPublishUploads-pEOrXJbF.js.map +1 -0
  32. package/dist/{index-7y2f_iQz.js → index-BQSK-r_A.js} +2 -2
  33. package/dist/index-BQSK-r_A.js.map +1 -0
  34. package/dist/{index-C61Rxy0F.js → index-zAs84LDi.js} +8 -8
  35. package/dist/index-zAs84LDi.js.map +1 -0
  36. package/dist/{index.browser-C1pisOEa.js → index.browser-irwaBIj0.js} +11 -11
  37. package/dist/{index.browser-C1pisOEa.js.map → index.browser-irwaBIj0.js.map} +1 -1
  38. package/dist/{index.node-BAlST8pD.js → index.node-BYkndQN7.js} +6 -6
  39. package/dist/{index.node-BAlST8pD.js.map → index.node-BYkndQN7.js.map} +1 -1
  40. package/dist/main.js +91 -504
  41. package/dist/main.js.map +1 -1
  42. package/dist/{mimeTypes-DHAHC4eZ.js → mimeTypes-C9r76DCH.js} +7 -2
  43. package/dist/{mimeTypes-DHAHC4eZ.js.map → mimeTypes-C9r76DCH.js.map} +1 -1
  44. package/dist/node.js +10 -10
  45. package/dist/platform.browser.js +6 -6
  46. package/dist/platform.node.js +4 -4
  47. package/dist/{property-zFPMtR3T.js → property-5AD2naVS.js} +7 -7
  48. package/dist/{property-zFPMtR3T.js.map → property-5AD2naVS.js.map} +1 -1
  49. package/dist/{propertyValidationRules-CeFVhdQg.js → propertyValidationRules-Bdgz0Nrr.js} +10 -10
  50. package/dist/{propertyValidationRules-CeFVhdQg.js.map → propertyValidationRules-Bdgz0Nrr.js.map} +1 -1
  51. package/dist/{publishDraftGraph-CuVq6iAR.js → publishDraftGraph-DGhC9ifI.js} +6 -6
  52. package/dist/{publishDraftGraph-CuVq6iAR.js.map → publishDraftGraph-DGhC9ifI.js.map} +1 -1
  53. package/dist/{resetAmbiguousLegacyItemData-DsFTnMBz.js → resetAmbiguousLegacyItemData-HSB77N9c.js} +2 -2
  54. package/dist/{resetAmbiguousLegacyItemData-DsFTnMBz.js.map → resetAmbiguousLegacyItemData-HSB77N9c.js.map} +1 -1
  55. package/dist/{resolveModelForSyncedSeed-RUsgAZXG.js → resolveModelForSyncedSeed-CAKAJgr6.js} +2 -2
  56. package/dist/{resolveModelForSyncedSeed-RUsgAZXG.js.map → resolveModelForSyncedSeed-CAKAJgr6.js.map} +1 -1
  57. package/dist/src/Item/Item.d.ts +4 -1
  58. package/dist/src/Item/Item.d.ts.map +1 -1
  59. package/dist/src/Item/errors.d.ts +3 -1
  60. package/dist/src/Item/errors.d.ts.map +1 -1
  61. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
  62. package/dist/src/Model/Model.d.ts +2 -1
  63. package/dist/src/Model/Model.d.ts.map +1 -1
  64. package/dist/src/Schema/Schema.d.ts.map +1 -1
  65. package/dist/src/Schema/service/schemaMachine.d.ts +3 -0
  66. package/dist/src/Schema/service/schemaMachine.d.ts.map +1 -1
  67. package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
  68. package/dist/src/db/alignRowPublishers.d.ts +25 -0
  69. package/dist/src/db/alignRowPublishers.d.ts.map +1 -0
  70. package/dist/src/db/canonicalizeModelTypes.d.ts +2 -2
  71. package/dist/src/db/canonicalizeModelTypes.d.ts.map +1 -1
  72. package/dist/src/db/read/getModelSchemas.d.ts +3 -2
  73. package/dist/src/db/read/getModelSchemas.d.ts.map +1 -1
  74. package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
  75. package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
  76. package/dist/src/db/read/getSchemaUidForModel.d.ts.map +1 -1
  77. package/dist/src/db/read/getSeedPublisher.d.ts +7 -0
  78. package/dist/src/db/read/getSeedPublisher.d.ts.map +1 -0
  79. package/dist/src/db/read/nameMatchLevels.d.ts +64 -0
  80. package/dist/src/db/read/nameMatchLevels.d.ts.map +1 -0
  81. package/dist/src/db/read/resolveModelRecord.d.ts.map +1 -1
  82. package/dist/src/db/read/summarizePublishWork.d.ts +2 -0
  83. package/dist/src/db/read/summarizePublishWork.d.ts.map +1 -1
  84. package/dist/src/db/write/applyArweaveL1TransactionIdLocal.d.ts +5 -3
  85. package/dist/src/db/write/applyArweaveL1TransactionIdLocal.d.ts.map +1 -1
  86. package/dist/src/db/write/claimUnpublishedDrafts.d.ts +4 -2
  87. package/dist/src/db/write/claimUnpublishedDrafts.d.ts.map +1 -1
  88. package/dist/src/db/write/createMetadata.d.ts.map +1 -1
  89. package/dist/src/db/write/createNewItem.d.ts.map +1 -1
  90. package/dist/src/db/write/createSeed.d.ts.map +1 -1
  91. package/dist/src/db/write/createVersion.d.ts.map +1 -1
  92. package/dist/src/db/write/discardNewDraft.d.ts +8 -0
  93. package/dist/src/db/write/discardNewDraft.d.ts.map +1 -0
  94. package/dist/src/db/write/restoreDataItemIdsOverwrittenByL1.d.ts +18 -0
  95. package/dist/src/db/write/restoreDataItemIdsOverwrittenByL1.d.ts.map +1 -0
  96. package/dist/src/db/write/updateItemPropertyValue.d.ts.map +1 -1
  97. package/dist/src/eas.d.ts.map +1 -1
  98. package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
  99. package/dist/src/helpers/constants.d.ts.map +1 -1
  100. package/dist/src/helpers/db.d.ts.map +1 -1
  101. package/dist/src/helpers/easValueTypes.d.ts +16 -0
  102. package/dist/src/helpers/easValueTypes.d.ts.map +1 -0
  103. package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts +13 -2
  104. package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts.map +1 -1
  105. package/dist/src/helpers/ownership.d.ts +9 -12
  106. package/dist/src/helpers/ownership.d.ts.map +1 -1
  107. package/dist/src/helpers/publishConfig.d.ts +9 -4
  108. package/dist/src/helpers/publishConfig.d.ts.map +1 -1
  109. package/dist/src/imports/index.d.ts +1 -1
  110. package/dist/src/imports/index.d.ts.map +1 -1
  111. package/dist/src/imports/json.d.ts.map +1 -1
  112. package/dist/src/index.d.ts +2 -1
  113. package/dist/src/index.d.ts.map +1 -1
  114. package/dist/src/types/import.d.ts +20 -0
  115. package/dist/src/types/import.d.ts.map +1 -1
  116. package/dist/{syncDbWithEas-CRpnkq00.js → syncDbWithEas-BmJXqfgN.js} +92 -22
  117. package/dist/syncDbWithEas-BmJXqfgN.js.map +1 -0
  118. package/dist/{tabEvents-nBUq_1u1.js → tabEvents-DXun7vdK.js} +4 -4
  119. package/dist/{tabEvents-nBUq_1u1.js.map → tabEvents-DXun7vdK.js.map} +1 -1
  120. package/dist/{tolerantWebAccess-DIt3R8_u.js → tolerantWebAccess-DXxgX2x7.js} +7 -7
  121. package/dist/{tolerantWebAccess-DIt3R8_u.js.map → tolerantWebAccess-DXxgX2x7.js.map} +1 -1
  122. package/dist/{updateSeedRevokedAt-DtTPSzpM.js → updateSeedRevokedAt-DkLSDwUX.js} +3 -3
  123. package/dist/{updateSeedRevokedAt-DtTPSzpM.js.map → updateSeedRevokedAt-DkLSDwUX.js.map} +1 -1
  124. package/package.json +9 -5
  125. package/dist/BasePathResolver-DrzGVH9L.js.map +0 -1
  126. package/dist/ClientManager-Dfu4jcgm.js.map +0 -1
  127. package/dist/Item-BUUFuywT.js.map +0 -1
  128. package/dist/Schema-Bf-jOLq0.js.map +0 -1
  129. package/dist/eas-Dq5Kx_Nd.js.map +0 -1
  130. package/dist/errors-DdWbxb_n.js.map +0 -1
  131. package/dist/getPublishPayload-DPy-uMrR.js.map +0 -1
  132. package/dist/getPublishUploads-J-143iSV.js.map +0 -1
  133. package/dist/index-7y2f_iQz.js.map +0 -1
  134. package/dist/index-C61Rxy0F.js.map +0 -1
  135. package/dist/syncDbWithEas-CRpnkq00.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { waitFor, fromCallback, setup, assign, stateIn, createActor, isMachineSnapshot } from 'xstate';
2
- import { E as BaseDb, C as versions, m as metadata, A as seeds, F as resolveStorageNameToSchemaName, aV as toSchemaPropertyName, z as schemas, s as models, q as modelSchemas, aT as getOwnedAddressesFromDb, ac as ZERO_BYTES32, aE as normalizeAddressList, a0 as normalizeHexAddress, aB as getAddressesForItemsFilter, ag as INTERNAL_PROPERTY_NAMES, J as BaseFileManager, aW as getStorageTransactionIdForSeedUid, aX as convertTxIdToImage, i as isDataType, X as normalizePublisher, n as normalizeDataType, aY as getMetadataPropertyNamesForQuery, aA as ensureImageLocal, as as ImageSize, aZ as downloadTransactionIdWithDedupe, a_ as resolveMetadataRecord, u as properties, M as ModelPropertyDataTypes, $ as generateId, aj as INTERNAL_DATA_TYPES, r as modelUids, a1 as listRelationEasPropertyName, a2 as easPropertyNameForPublish, L as resolveItemModelFileId, a$ as getPropertyIdForSchemaFileId, K as getPropertyIdForModelAndName, a3 as toMetadataPropertyName, b0 as getDataTypeFromString, b1 as getMimeType, ap as INTERNAL_STORAGE_MODEL_FILE_IDS, V as getItemStorageSubdir, W as getItemStorageLocalFileName, g as normalizePropertyRecordSchema, b2 as listRelationStoragePropertyName, b3 as PROPERTY_NAMES_EXEMPT_FROM_ID_SUFFIX_STRIP, a8 as getCorrectId, H as eventEmitter, b4 as getAlternatePropertyNameForInstanceLookup, ah as isStorageSeedRef } from './BasePathResolver-DrzGVH9L.js';
2
+ import { B as BaseDb, F as versions, m as metadata, C as seeds, G as resolveStorageNameToSchemaName, a_ as toSchemaPropertyName, A as schemas, t as models, r as modelSchemas, aY as getOwnedAddressesFromDb, a5 as ZERO_BYTES32, aG as normalizeAddressList, am as normalizeHexAddress, aD as getAddressesForItemsFilter, a9 as INTERNAL_PROPERTY_NAMES, h as BaseFileManager, a$ as getStorageTransactionIdForSeedUid, b0 as convertTxIdToImage, i as isDataType, ah as normalizePublisher, n as normalizeDataType, b1 as getMetadataPropertyNamesForQuery, aC as ensureImageLocal, au as ImageSize, b2 as downloadTransactionIdWithDedupe, b3 as resolveMetadataRecord, v as properties, M as ModelPropertyDataTypes, al as generateId, ac as INTERNAL_DATA_TYPES, s as modelUids, ad as listRelationEasPropertyName, ae as easPropertyNameForPublish, N as resolveItemModelFileId, b4 as getPropertyIdForSchemaFileId, L as getPropertyIdForModelAndName, an as toMetadataPropertyName, b5 as getDataTypeFromString, b6 as getMimeType, _ as INTERNAL_STORAGE_MODEL_FILE_IDS, a2 as getItemStorageSubdir, a3 as getItemStorageLocalFileName, g as normalizePropertyRecordSchema, b7 as listRelationStoragePropertyName, b8 as PROPERTY_NAMES_EXEMPT_FROM_ID_SUFFIX_STRIP, R as getCorrectId, I as eventEmitter, b9 as getAlternatePropertyNameForInstanceLookup, aa as isStorageSeedRef } from './BasePathResolver-B-fK7_N_.js';
3
3
  import { or, isNull, eq, max, count, and, getTableColumns, sql, desc, inArray, isNotNull, gt } from 'drizzle-orm';
4
4
  import debug from 'debug';
5
5
  import { BehaviorSubject } from 'rxjs';
@@ -7,7 +7,7 @@ import pluralize from 'pluralize';
7
7
  import { startCase, upperFirst, camelCase, orderBy } from 'lodash-es';
8
8
  import { isValidEasAttestationUid, easName, isPlaceholderUid, BaseQueryClient, BaseEasClient, GET_SCHEMAS, getEasSchemaUidForSchemaDefinition, getSchemaUidForModelFromCache, setSchemaUidForModel, cachedSchemaLookup, getEasSchemaUidForExactDefinition } from '@seedprotocol/eas';
9
9
  import { fetchArweaveRawTextAcrossGateways } from '@seedprotocol/arweave';
10
- import { d as notifyFileSaved, f as withTabLock } from './tabEvents-nBUq_1u1.js';
10
+ import { d as notifyFileSaved, f as withTabLock } from './tabEvents-DXun7vdK.js';
11
11
  import { modelPropertiesToObject } from './model-oHA3YhOd.js';
12
12
 
13
13
  /**
@@ -580,7 +580,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
580
580
  const itemPropertyMod = await Promise.resolve().then(function () { return ItemProperty$1; });
581
581
  const { ItemProperty } = itemPropertyMod;
582
582
  const { modelPropertiesToObject } = await import('./model-oHA3YhOd.js');
583
- const _mod_0 = await import('./errors-DdWbxb_n.js');
583
+ const _mod_0 = await import('./errors-CCMxedOB.js');
584
584
  const _ns_0 = _mod_0.h;
585
585
  const { Model } = _ns_0;
586
586
  // Resolve Model and build property schemas (use getByNameAsync for models not yet in cache)
@@ -598,7 +598,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
598
598
  const schemaNameToTry = schemaName ?? model?.schemaName;
599
599
  if (schemaNameToTry) {
600
600
  try {
601
- const _mod_1 = await import('./Schema-Bf-jOLq0.js');
601
+ const _mod_1 = await import('./Schema-BJLYOUgp.js');
602
602
  const _ns_1 = _mod_1.b;
603
603
  const { Schema } = _ns_1;
604
604
  const schemaInstance = Schema.create(schemaNameToTry, { waitForReady: false });
@@ -614,8 +614,8 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
614
614
  }
615
615
  if (Object.keys(propertySchemas).length === 0) {
616
616
  try {
617
- const _mod_2 = await import('./ClientManager-Dfu4jcgm.js');
618
- const _ns_2 = _mod_2.L;
617
+ const _mod_2 = await import('./ClientManager-C7VkO5Hg.js');
618
+ const _ns_2 = _mod_2.M;
619
619
  const { loadAllSchemasFromDb } = _ns_2;
620
620
  const allSchemas = await loadAllSchemasFromDb();
621
621
  for (const { schema: schemaFile } of allSchemas) {
@@ -635,11 +635,11 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
635
635
  }
636
636
  if (Object.keys(propertySchemas).length === 0) {
637
637
  try {
638
- const _mod_3 = await import('./ClientManager-Dfu4jcgm.js');
639
- const _ns_3 = _mod_3.L;
638
+ const _mod_3 = await import('./ClientManager-C7VkO5Hg.js');
639
+ const _ns_3 = _mod_3.M;
640
640
  const { listCompleteSchemaFiles } = _ns_3;
641
- const _mod_4 = await import('./BasePathResolver-DrzGVH9L.js');
642
- const _ns_4 = _mod_4.b7;
641
+ const _mod_4 = await import('./BasePathResolver-B-fK7_N_.js');
642
+ const _ns_4 = _mod_4.bc;
643
643
  const { BaseFileManager } = _ns_4;
644
644
  const schemaFiles = await listCompleteSchemaFiles();
645
645
  for (const { filePath } of schemaFiles) {
@@ -659,7 +659,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
659
659
  }
660
660
  }
661
661
  if (Object.keys(propertySchemas).length === 0) {
662
- const schemaMod = await import('./index-C61Rxy0F.js');
662
+ const schemaMod = await import('./index-zAs84LDi.js');
663
663
  const { ModelPropertyDataTypes } = schemaMod;
664
664
  const KNOWN_MODEL_FALLBACKS = {
665
665
  Post: {
@@ -676,7 +676,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
676
676
  }
677
677
  }
678
678
  // Fallbacks above may return schema-file shape ({ type, model, items }); normalize to dataType/ref/refValueType.
679
- const { normalizePropertyRecordSchema } = await import('./property-zFPMtR3T.js');
679
+ const { normalizePropertyRecordSchema } = await import('./property-5AD2naVS.js');
680
680
  propertySchemas = Object.fromEntries(Object.entries(propertySchemas).map(([name, def]) => [name, normalizePropertyRecordSchema(def)]));
681
681
  // Collapse rows that map to the same instance key (e.g. authorIdentityIds + authors -> authors).
682
682
  // ItemProperty.create cache does not sync propertyValue on hit; processing order would otherwise
@@ -709,7 +709,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
709
709
  // Infer propertyRecordSchema from metadata when schema is missing (enables persistence)
710
710
  let propSchema = propertySchemas[propertyName];
711
711
  if (!propSchema && isRefTypeFromMeta) {
712
- const schemaMod = await import('./index-C61Rxy0F.js');
712
+ const schemaMod = await import('./index-zAs84LDi.js');
713
713
  const { ModelPropertyDataTypes } = schemaMod;
714
714
  propSchema = {
715
715
  dataType: refSeedType === 'html' ? ModelPropertyDataTypes.Html
@@ -1595,14 +1595,14 @@ function publisherIsInOwnedSet(publisher, ownedAddresses) {
1595
1595
  }
1596
1596
  /**
1597
1597
  * Shared ownership predicate.
1598
- * - Session has owned addresses: only a publisher in that set is owned (null is never owned).
1599
- * - Session has no owned addresses: local unsealed drafts are owned so pre-connect authoring works.
1598
+ * - A local unsealed draft (never given a publisher) is owned whatever the owned addresses are:
1599
+ * it belongs to no wallet yet, and the next wallet to connect claims it (claimUnpublishedDrafts).
1600
+ * - Any other row is owned when its publisher (or attester) is in the owned addresses.
1600
1601
  */
1601
1602
  function isSeedRowOwned(row, ownedAddresses) {
1602
1603
  const publisher = resolvePublisherFromSeedRow(row);
1603
- if (ownedAddresses.length === 0) {
1604
- return isLocalUnsealedDraft({ ...row, publisher: publisher ?? row.publisher });
1605
- }
1604
+ if (isLocalUnsealedDraft({ ...row, publisher: publisher ?? row.publisher }))
1605
+ return true;
1606
1606
  return publisherIsInOwnedSet(publisher, ownedAddresses);
1607
1607
  }
1608
1608
  /**
@@ -1635,8 +1635,8 @@ function localUnsealedDraftSql() {
1635
1635
  }
1636
1636
  /**
1637
1637
  * SQL for `addressFilter: 'owned'`: a row passes exactly when {@link isSeedRowOwned} is true.
1638
- * - Empty owned → local unsealed drafts (pre-connect authoring), not every row.
1639
- * - Owned set → `lower(trim(publisher))` in the set, or, when publisher is blank, the
1638
+ * - Local unsealed drafts always pass.
1639
+ * - Otherwise `lower(trim(publisher))` is in the owned set, or, when publisher is blank, the
1640
1640
  * `attestationRaw.attester` ({@link resolvePublisherFromSeedRow}). `json_valid` guards
1641
1641
  * `json_extract`, which throws on malformed JSON.
1642
1642
  */
@@ -1646,17 +1646,13 @@ function ownedSeedsSql(ownedAddresses) {
1646
1646
  return localUnsealedDraftSql();
1647
1647
  }
1648
1648
  const attester = sql `CASE WHEN json_valid(${seeds.attestationRaw}) THEN lower(trim(json_extract(${seeds.attestationRaw}, '$.attester'))) END`;
1649
- return or(inArray(sql `lower(trim(${seeds.publisher}))`, normalized), and(isBlankSql(seeds.publisher), inArray(attester, normalized)));
1649
+ return or(localUnsealedDraftSql(), inArray(sql `lower(trim(${seeds.publisher}))`, normalized), and(isBlankSql(seeds.publisher), inArray(attester, normalized)));
1650
1650
  }
1651
1651
  /**
1652
- * Checks if the current user owns the item (publisher is in persisted owned addresses).
1653
- *
1654
- * When the session has owned addresses, only a matching publisher is owned —
1655
- * `publisher IS NULL` is not treated as owned. Call `claimUnpublishedDrafts`
1656
- * after connect to stamp local drafts.
1657
- *
1658
- * When owned is empty, local unsealed drafts (no publisher, no real uid, no
1659
- * attestationRaw) are still owned so create/edit works before a wallet is connected.
1652
+ * Checks if the current user owns the item: its publisher is in the persisted owned addresses,
1653
+ * or it's a local unsealed draft (no publisher, no real uid, no attestationRaw). Such a draft
1654
+ * was made with no wallet connected and is editable until `claimUnpublishedDrafts`, which
1655
+ * connecting a wallet calls, gives it that wallet as publisher.
1660
1656
  *
1661
1657
  * Does not include `getAdditionalSyncAddresses` (those are extra EAS indexers,
1662
1658
  * not wallets the user controls).
@@ -1715,8 +1711,8 @@ const getItemsData = async ({ modelName, modelFileId, schemaName, deleted, inclu
1715
1711
  conditions.push(eq(seeds.type, easName(modelName)));
1716
1712
  }
1717
1713
  if (!modelFileId && schemaName && modelName) {
1718
- const _mod_5 = await import('./BasePathResolver-DrzGVH9L.js');
1719
- const _ns_5 = _mod_5.ba;
1714
+ const _mod_5 = await import('./BasePathResolver-B-fK7_N_.js');
1715
+ const _ns_5 = _mod_5.bf;
1720
1716
  const { resolveModelRecord } = _ns_5;
1721
1717
  modelFileId = (await resolveModelRecord(modelName, { schemaName }))?.schemaFileId ?? undefined;
1722
1718
  if (!modelFileId)
@@ -1998,7 +1994,7 @@ const resolveRelatedValue = fromCallback(({ sendBack, input: { context } }) => {
1998
1994
  const { isRelation, propertyValue, propertyName, seedUid, propertyRecordSchema, populatedFromDb, schemaUid, } = context;
1999
1995
  const _resolveRelatedValue = async () => {
2000
1996
  // Use dynamic import to break circular dependency
2001
- const schemaMod = await import('./index-C61Rxy0F.js');
1997
+ const schemaMod = await import('./index-zAs84LDi.js');
2002
1998
  const { ModelPropertyDataTypes } = schemaMod;
2003
1999
  if (!propertyValue || !isRelation || populatedFromDb) {
2004
2000
  return;
@@ -2433,8 +2429,8 @@ async function readHtmlBodyFromChildStorageArweave(seedLocalId) {
2433
2429
  /* offline / bad tx id */
2434
2430
  }
2435
2431
  try {
2436
- const _mod_6 = await import('./BasePathResolver-DrzGVH9L.js');
2437
- const _ns_6 = _mod_6.bc;
2432
+ const _mod_6 = await import('./BasePathResolver-B-fK7_N_.js');
2433
+ const _ns_6 = _mod_6.bh;
2438
2434
  const { downloadTransactionIdWithDedupe } = _ns_6;
2439
2435
  await downloadTransactionIdWithDedupe(txId);
2440
2436
  const retryFp = BaseFileManager.getFilesPath('html', `${seedLocalId}.html`);
@@ -2494,7 +2490,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
2494
2490
  // to use dynamically imported ModelPropertyDataTypes
2495
2491
  const _hydrateFromDb = async () => {
2496
2492
  // Use dynamic import to break circular dependency
2497
- const schemaMod = await import('./index-C61Rxy0F.js');
2493
+ const schemaMod = await import('./index-zAs84LDi.js');
2498
2494
  const { ModelPropertyDataTypes } = schemaMod;
2499
2495
  const appDb = BaseDb.getAppDb();
2500
2496
  const whereClauses = [];
@@ -2775,12 +2771,12 @@ const loadOrCreateProperty = fromCallback(({ sendBack, input: { context } }) =>
2775
2771
  const modelNameForNew = context.modelName;
2776
2772
  if (modelNameForNew) {
2777
2773
  try {
2778
- const _mod_7 = await import('./errors-DdWbxb_n.js');
2774
+ const _mod_7 = await import('./errors-CCMxedOB.js');
2779
2775
  const _ns_7 = _mod_7.h;
2780
2776
  const { Model } = _ns_7;
2781
2777
  const { modelPropertiesToObject } = await import('./model-oHA3YhOd.js');
2782
- const _mod_8 = await import('./BasePathResolver-DrzGVH9L.js');
2783
- const _ns_8 = _mod_8.ba;
2778
+ const _mod_8 = await import('./BasePathResolver-B-fK7_N_.js');
2779
+ const _ns_8 = _mod_8.bf;
2784
2780
  const { resolveItemModelFileId } = _ns_8;
2785
2781
  const normalizedModelName = upperFirst(camelCase(modelNameForNew));
2786
2782
  const itemModelFileId = await resolveItemModelFileId({
@@ -2833,8 +2829,8 @@ const loadOrCreateProperty = fromCallback(({ sendBack, input: { context } }) =>
2833
2829
  // It ends up in the context below, and later lookups by name (Model.getByName) can't match it.
2834
2830
  const modelName = context.modelName || (metadataRecord.modelType ? upperFirst(camelCase(metadataRecord.modelType)) : undefined);
2835
2831
  // Model names are only unique per schema: pin lookups to the item's own model row.
2836
- const _mod_9 = await import('./BasePathResolver-DrzGVH9L.js');
2837
- const _ns_9 = _mod_9.ba;
2832
+ const _mod_9 = await import('./BasePathResolver-B-fK7_N_.js');
2833
+ const _ns_9 = _mod_9.bf;
2838
2834
  const { resolveItemModelFileId, resolveModelRecord } = _ns_9;
2839
2835
  const modelFileId = await resolveItemModelFileId({
2840
2836
  modelFileId: context.modelFileId,
@@ -2878,7 +2874,7 @@ const loadOrCreateProperty = fromCallback(({ sendBack, input: { context } }) =>
2878
2874
  required: propRecord.required ?? undefined,
2879
2875
  };
2880
2876
  // Validation rules (enum, pattern, ...) aren't in the properties table
2881
- const { resolvePropertyValidationRules } = await import('./propertyValidationRules-CeFVhdQg.js');
2877
+ const { resolvePropertyValidationRules } = await import('./propertyValidationRules-Bdgz0Nrr.js');
2882
2878
  const validation = await resolvePropertyValidationRules(normalizedModelName, propertyName, {
2883
2879
  modelFileId: modelRecord?.schemaFileId ?? modelFileId,
2884
2880
  });
@@ -2895,7 +2891,7 @@ const loadOrCreateProperty = fromCallback(({ sendBack, input: { context } }) =>
2895
2891
  }
2896
2892
  if (!propertyRecordSchema && modelName) {
2897
2893
  try {
2898
- const _mod_10 = await import('./errors-DdWbxb_n.js');
2894
+ const _mod_10 = await import('./errors-CCMxedOB.js');
2899
2895
  const _ns_10 = _mod_10.h;
2900
2896
  const { Model } = _ns_10;
2901
2897
  const { modelPropertiesToObject } = await import('./model-oHA3YhOd.js');
@@ -3117,6 +3113,27 @@ const getVersionData = async ({ localId, seedLocalId, uid, }) => {
3117
3113
  return queryRows[0];
3118
3114
  };
3119
3115
 
3116
+ /**
3117
+ * The publisher a seed's version and property rows take: the seed's own (its `publisher`, else the
3118
+ * attester of its stored attestation). Undefined for a draft that belongs to no wallet yet; those
3119
+ * rows are then claimed together with their seed (claimUnpublishedDrafts).
3120
+ */
3121
+ async function getSeedPublisher(seedLocalId) {
3122
+ if (!seedLocalId)
3123
+ return undefined;
3124
+ const appDb = BaseDb.getAppDb();
3125
+ if (!appDb)
3126
+ return undefined;
3127
+ const [row] = await appDb
3128
+ .select({ publisher: seeds.publisher, attestationRaw: seeds.attestationRaw, uid: seeds.uid })
3129
+ .from(seeds)
3130
+ .where(eq(seeds.localId, seedLocalId))
3131
+ .limit(1);
3132
+ if (!row)
3133
+ return undefined;
3134
+ return normalizePublisher(resolvePublisherFromSeedRow(row));
3135
+ }
3136
+
3120
3137
  const logger$2 = debug('seedSdk:write:updateItemPropertyValue');
3121
3138
  const updateItemPropertyValue = async ({ localId: localIdParam, propertyName, newValue, seedUid, seedLocalId, modelName, refSeedType, refResolvedValue, refResolvedDisplayValue, versionLocalId, versionUid, schemaUid, localStorageDir, dataType, refValueType, }) => {
3122
3139
  if (!localIdParam && !seedLocalId) {
@@ -3168,10 +3185,13 @@ const updateItemPropertyValue = async ({ localId: localIdParam, propertyName, ne
3168
3185
  }
3169
3186
  if (rows && rows.length > 0) {
3170
3187
  const { localId, uid, propertyName: propertyNameFromDb, propertyValue: propertyValueFromDb, modelType, seedUid, seedLocalId: seedLocalIdFromDb, versionLocalId, versionUid, schemaUid, easDataType, localStorageDir: localStorageDirFromDb, refSeedType: refSeedTypeFromDb, refResolvedValue: refResolvedValueFromDb, refResolvedDisplayValue: refResolvedDisplayValueFromDb, } = rows[0];
3188
+ // Stored model types are the model's EAS name (ADR 0008): `blog_post` for BlogPost.
3189
+ const modelTypeForName = modelName ? easName(modelName) : undefined;
3171
3190
  if (propertyValueFromDb === newValue &&
3172
- modelType === modelName?.toLowerCase() &&
3173
- refSeedTypeFromDb === refSeedType &&
3174
- refResolvedValueFromDb === refResolvedValue) {
3191
+ modelType === modelTypeForName &&
3192
+ // The DB holds null where callers leave a field out (plain values pass no ref fields).
3193
+ (refSeedTypeFromDb ?? null) === (refSeedType ?? null) &&
3194
+ (refResolvedValueFromDb ?? null) === (refResolvedValue ?? null)) {
3175
3195
  logger$2(`[db/write] [updateItemPropertyValue] value is the same as most recent record for property: ${propertyNameFromDb}`);
3176
3196
  return;
3177
3197
  }
@@ -3204,11 +3224,14 @@ const updateItemPropertyValue = async ({ localId: localIdParam, propertyName, ne
3204
3224
  const versionDataFromDb = versionLocalId ? await getVersionData({ localId: versionLocalId }) : null;
3205
3225
  // Here we don't have a local-only record so we need to create a new one
3206
3226
  const newLocalId = generateId();
3227
+ // The row belongs to its seed's wallet, like createMetadata's.
3228
+ const publisher = await getSeedPublisher(seedLocalIdFromDb ?? seedLocalId);
3207
3229
  await appDb.insert(metadata).values({
3208
3230
  localId: newLocalId,
3231
+ ...(publisher && { publisher }),
3209
3232
  propertyName: propertyNameFromDb,
3210
3233
  propertyValue: safeNewValue ?? null,
3211
- modelType: modelType || modelName?.toLowerCase() || null,
3234
+ modelType: modelType || modelTypeForName || null,
3212
3235
  seedUid: seedDataFromDb?.uid || null,
3213
3236
  seedLocalId: seedLocalIdFromDb,
3214
3237
  versionLocalId,
@@ -3240,11 +3263,13 @@ const updateItemPropertyValue = async ({ localId: localIdParam, propertyName, ne
3240
3263
  versionUid = versionData.uid;
3241
3264
  }
3242
3265
  }
3266
+ const publisher = await getSeedPublisher(seedLocalId);
3243
3267
  await appDb.insert(metadata).values({
3244
3268
  localId: newLocalId,
3269
+ ...(publisher && { publisher }),
3245
3270
  propertyName,
3246
3271
  propertyValue: safeNewValue ?? null,
3247
- modelType: modelName?.toLowerCase() || '',
3272
+ modelType: modelName ? easName(modelName) : '',
3248
3273
  seedUid: seedUid || null,
3249
3274
  seedLocalId: seedLocalId || '',
3250
3275
  versionLocalId: versionLocalId || '',
@@ -3329,9 +3354,9 @@ const analyzeInput = fromCallback(({ sendBack, input: { context, event } }) => {
3329
3354
  return false;
3330
3355
  }
3331
3356
  // Use dynamic import to break circular dependency
3332
- const schemaMod = await import('./index-C61Rxy0F.js');
3357
+ const schemaMod = await import('./index-zAs84LDi.js');
3333
3358
  const { ModelPropertyDataTypes } = schemaMod;
3334
- const { SchemaValidationService } = await import('./SchemaValidationService-BNYMacsx.js');
3359
+ const { SchemaValidationService } = await import('./SchemaValidationService-CzybXLiS.js');
3335
3360
  let propertyName = propertyNameRaw;
3336
3361
  if (!propertyName) {
3337
3362
  throw new Error('propertyName is required');
@@ -3522,21 +3547,22 @@ const getEasSchemaUidForModel = async (modelName) => {
3522
3547
  return uid;
3523
3548
  }
3524
3549
  }
3525
- const modeType = modelName.toLowerCase();
3550
+ // The name publish registers the model's schema under (ADR 0008): `blog_post` for BlogPost.
3551
+ const modelType = easName(modelName);
3526
3552
  let easSchemaUid;
3527
3553
  try {
3528
3554
  // Misses are cached too (most local models have no EAS schema).
3529
- easSchemaUid = await cachedSchemaLookup(`model:${modeType}`, async () => {
3555
+ easSchemaUid = await cachedSchemaLookup(`model:${modelType}`, async () => {
3530
3556
  const queryClient = BaseQueryClient.getQueryClient();
3531
3557
  const easClient = BaseEasClient.getEasClient();
3532
3558
  const modelSchemaQuery = await queryClient.fetchQuery({
3533
- queryKey: [`getEasSchemaUidForModel`, modeType],
3559
+ queryKey: [`getEasSchemaUidForModel`, modelType],
3534
3560
  queryFn: async () => easClient.request(GET_SCHEMAS, {
3535
3561
  where: {
3536
3562
  schemaNames: {
3537
3563
  some: {
3538
3564
  name: {
3539
- equals: modeType,
3565
+ equals: modelType,
3540
3566
  },
3541
3567
  },
3542
3568
  },
@@ -3563,7 +3589,15 @@ const createSeed = async ({ type, seedUid, modelFileId }) => {
3563
3589
  // if the EAS schema hasn't been published yet
3564
3590
  const appDb = BaseDb.getAppDb();
3565
3591
  const newSeedLocalId = generateId();
3566
- const publisher = normalizePublisher(await getPublisherForNewSeedsWithTimeout());
3592
+ // When nothing supplies a publisher (no getter, as in Node scripts, or no wallet connected yet)
3593
+ // and exactly one owned address is set, the draft is that address's. With several, which one would
3594
+ // publish isn't known: the draft gets none, stays editable, and the next wallet to connect claims it.
3595
+ let publisher = normalizePublisher(await getPublisherForNewSeedsWithTimeout());
3596
+ if (!publisher) {
3597
+ const owned = await getOwnedAddressesFromDb();
3598
+ if (owned.length === 1)
3599
+ publisher = normalizePublisher(owned[0]);
3600
+ }
3567
3601
  await appDb.insert(seeds).values({
3568
3602
  localId: newSeedLocalId,
3569
3603
  type,
@@ -3579,7 +3613,8 @@ const createSeed = async ({ type, seedUid, modelFileId }) => {
3579
3613
  const createVersion = async ({ seedLocalId, seedUid, seedType, uid, }) => {
3580
3614
  const appDb = BaseDb.getAppDb();
3581
3615
  const newVersionLocalId = generateId();
3582
- const publisher = normalizePublisher(await getPublisherForNewSeedsWithTimeout());
3616
+ // A version belongs to its seed's wallet (none yet for a draft made with no wallet connected).
3617
+ const publisher = await getSeedPublisher(seedLocalId);
3583
3618
  await appDb.insert(versions).values({
3584
3619
  localId: newVersionLocalId,
3585
3620
  createdAt: Date.now(),
@@ -3603,7 +3638,8 @@ class MetadataValidationError extends Error {
3603
3638
  const createMetadata = async (metadataValues, propertyRecordSchema, options) => {
3604
3639
  const appDb = BaseDb.getAppDb();
3605
3640
  metadataValues.localId = generateId();
3606
- const publisher = normalizePublisher(await getPublisherForNewSeedsWithTimeout());
3641
+ // A property row belongs to its seed's wallet (none yet for a draft made with no wallet connected).
3642
+ const publisher = await getSeedPublisher(metadataValues.seedLocalId);
3607
3643
  if (publisher) {
3608
3644
  metadataValues.publisher = publisher;
3609
3645
  }
@@ -3643,7 +3679,7 @@ const createMetadata = async (metadataValues, propertyRecordSchema, options) =>
3643
3679
  propertyRecordSchema?.validation &&
3644
3680
  metadataValues.propertyValue != null &&
3645
3681
  metadataValues.propertyValue !== '') {
3646
- const { SchemaValidationService } = await import('./SchemaValidationService-BNYMacsx.js');
3682
+ const { SchemaValidationService } = await import('./SchemaValidationService-CzybXLiS.js');
3647
3683
  const validationService = new SchemaValidationService();
3648
3684
  const validationResult = validationService.validatePropertyValue(metadataValues.propertyValue, normalizeDataType(propertyRecordSchema.dataType), propertyRecordSchema.validation, propertyRecordSchema.refValueType
3649
3685
  ? normalizeDataType(String(propertyRecordSchema.refValueType))
@@ -4256,7 +4292,7 @@ const saveRelation = fromCallback(({ sendBack, input: { context, event } }) => {
4256
4292
  }
4257
4293
  const _saveRelation = async () => {
4258
4294
  // Use dynamic import to break circular dependency
4259
- const schemaMod = await import('./index-C61Rxy0F.js');
4295
+ const schemaMod = await import('./index-zAs84LDi.js');
4260
4296
  const { ModelPropertyDataTypes } = schemaMod;
4261
4297
  if (!propertyNameRaw) {
4262
4298
  throw new Error('propertyName is required');
@@ -4490,7 +4526,7 @@ const saveItemStorage = fromCallback(({ sendBack, input: { context, event } }) =
4490
4526
  return createMetadata({
4491
4527
  propertyName,
4492
4528
  propertyValue: filename,
4493
- modelType: (modelName ?? knownRow?.modelType ?? '').toLowerCase() || undefined,
4529
+ modelType: (modelName ? easName(modelName) : knownRow?.modelType) || undefined,
4494
4530
  seedLocalId: draftSeedLocalId,
4495
4531
  seedUid: draftSeedUid,
4496
4532
  versionLocalId,
@@ -4975,11 +5011,11 @@ const getPropertyData = async ({ propertyName, seedLocalId, seedUid, modelName,
4975
5011
  let names = [...getMetadataPropertyNamesForQuery(propertyName)];
4976
5012
  if (modelName) {
4977
5013
  try {
4978
- const _mod_11 = await import('./errors-DdWbxb_n.js');
5014
+ const _mod_11 = await import('./errors-CCMxedOB.js');
4979
5015
  const _ns_11 = _mod_11.h;
4980
5016
  const { Model } = _ns_11;
4981
- const _mod_12 = await import('./BasePathResolver-DrzGVH9L.js');
4982
- const _ns_12 = _mod_12.ba;
5017
+ const _mod_12 = await import('./BasePathResolver-B-fK7_N_.js');
5018
+ const _ns_12 = _mod_12.bf;
4983
5019
  const { resolveItemModelFileId } = _ns_12;
4984
5020
  // Model names are only unique per schema: use the seed's own model when it is recorded.
4985
5021
  const modelFileId = await resolveItemModelFileId({ seedLocalId, seedUid });
@@ -5179,8 +5215,8 @@ const HTML_PROP_SEED_UID_RE = /^0x[a-fA-F0-9]{64}$/;
5179
5215
  */
5180
5216
  const resolvePropertyRecordSchemaFromSchemaData = async (modelName, propertyName, modelType, schemaName) => {
5181
5217
  try {
5182
- const _mod_13 = await import('./ClientManager-Dfu4jcgm.js');
5183
- const _ns_13 = _mod_13.L;
5218
+ const _mod_13 = await import('./ClientManager-C7VkO5Hg.js');
5219
+ const _ns_13 = _mod_13.M;
5184
5220
  const { loadAllSchemasFromDb } = _ns_13;
5185
5221
  const allSchemas = await loadAllSchemasFromDb();
5186
5222
  const modelNameAlt = modelType ? upperFirst(camelCase(modelType)) : '';
@@ -5233,12 +5269,12 @@ hints = {}) => {
5233
5269
  return undefined;
5234
5270
  }
5235
5271
  try {
5236
- const _mod_14 = await import('./errors-DdWbxb_n.js');
5272
+ const _mod_14 = await import('./errors-CCMxedOB.js');
5237
5273
  const _ns_14 = _mod_14.h;
5238
5274
  const { Model } = _ns_14;
5239
5275
  const { modelPropertiesToObject } = await import('./model-oHA3YhOd.js');
5240
- const _mod_15 = await import('./BasePathResolver-DrzGVH9L.js');
5241
- const _ns_15 = _mod_15.ba;
5276
+ const _mod_15 = await import('./BasePathResolver-B-fK7_N_.js');
5277
+ const _ns_15 = _mod_15.bf;
5242
5278
  const { resolveItemModelFileId } = _ns_15;
5243
5279
  const modelFileId = await resolveItemModelFileId(hints);
5244
5280
  let model = modelFileId
@@ -5397,7 +5433,7 @@ class ItemProperty {
5397
5433
  return;
5398
5434
  }
5399
5435
  // Use dynamic import to break circular dependency
5400
- const schemaMod = await import('./index-C61Rxy0F.js');
5436
+ const schemaMod = await import('./index-zAs84LDi.js');
5401
5437
  const { ModelPropertyDataTypes } = schemaMod;
5402
5438
  const { context } = snapshot;
5403
5439
  const { propertyRecordSchema } = context;
@@ -5568,7 +5604,7 @@ class ItemProperty {
5568
5604
  const normalizedRefValueType = normalizeDataType(propertyRecordSchema?.refValueType);
5569
5605
  const propertyNames = getMetadataPropertyNamesForQuery(propertyName, normalizedDataType, normalizedRefValueType);
5570
5606
  const propertyNameVariant = propertyNames.length > 1 ? propertyNames[1] : undefined;
5571
- const _mod_16 = await import('./index-7y2f_iQz.js');
5607
+ const _mod_16 = await import('./index-BQSK-r_A.js');
5572
5608
  const _ns_16 = _mod_16.s;
5573
5609
  const seedSchemaMod = _ns_16;
5574
5610
  const { metadata } = seedSchemaMod;
@@ -5792,8 +5828,8 @@ class ItemProperty {
5792
5828
  const ctx = this._service.getSnapshot().context;
5793
5829
  let modelFileId;
5794
5830
  try {
5795
- const _mod_17 = await import('./BasePathResolver-DrzGVH9L.js');
5796
- const _ns_17 = _mod_17.ba;
5831
+ const _mod_17 = await import('./BasePathResolver-B-fK7_N_.js');
5832
+ const _ns_17 = _mod_17.bf;
5797
5833
  const { resolveItemModelFileId } = _ns_17;
5798
5834
  modelFileId = await resolveItemModelFileId({
5799
5835
  modelFileId: ctx.modelFileId,
@@ -6155,8 +6191,8 @@ class ItemProperty {
6155
6191
  const propertiesData = await getItemProperties({ seedLocalId, seedUid });
6156
6192
  const instances = [];
6157
6193
  const seenNormalized = new Set();
6158
- const _mod_18 = await import('./BasePathResolver-DrzGVH9L.js');
6159
- const _ns_18 = _mod_18.ba;
6194
+ const _mod_18 = await import('./BasePathResolver-B-fK7_N_.js');
6195
+ const _ns_18 = _mod_18.bf;
6160
6196
  const { resolveItemModelFileId } = _ns_18;
6161
6197
  const itemModelFileId = await resolveItemModelFileId({ seedLocalId, seedUid });
6162
6198
  for (const data of propertiesData) {
@@ -6173,7 +6209,7 @@ class ItemProperty {
6173
6209
  }
6174
6210
  else if (baseName) {
6175
6211
  try {
6176
- const _mod_19 = await import('./errors-DdWbxb_n.js');
6212
+ const _mod_19 = await import('./errors-CCMxedOB.js');
6177
6213
  const _ns_19 = _mod_19.h;
6178
6214
  const { Model } = _ns_19;
6179
6215
  const { modelPropertiesToObject } = await import('./model-oHA3YhOd.js');
@@ -6190,7 +6226,7 @@ class ItemProperty {
6190
6226
  }
6191
6227
  if (modelName && propertyName) {
6192
6228
  try {
6193
- const _mod_20 = await import('./errors-DdWbxb_n.js');
6229
+ const _mod_20 = await import('./errors-CCMxedOB.js');
6194
6230
  const _ns_20 = _mod_20.h;
6195
6231
  const { Model } = _ns_20;
6196
6232
  const { modelPropertiesToObject } = await import('./model-oHA3YhOd.js');
@@ -6522,7 +6558,7 @@ class ItemProperty {
6522
6558
  if (!propertyName || (!seedLocalId && !seedUid))
6523
6559
  return;
6524
6560
  if (db) {
6525
- const _mod_21 = await import('./index-7y2f_iQz.js');
6561
+ const _mod_21 = await import('./index-BQSK-r_A.js');
6526
6562
  const _ns_21 = _mod_21.s;
6527
6563
  const seedSchemaMod = _ns_21;
6528
6564
  const { metadata } = seedSchemaMod;
@@ -6567,7 +6603,7 @@ const createNewItem = async ({ modelName, modelFileId, ...propertyData }) => {
6567
6603
  }
6568
6604
  const seedType = easName(modelName);
6569
6605
  // Dynamic import to break circular dependency
6570
- const _mod_22 = await import('./errors-DdWbxb_n.js');
6606
+ const _mod_22 = await import('./errors-CCMxedOB.js');
6571
6607
  const _ns_22 = _mod_22.h;
6572
6608
  const modelMod = _ns_22;
6573
6609
  const { Model } = modelMod;
@@ -6575,57 +6611,69 @@ const createNewItem = async ({ modelName, modelFileId, ...propertyData }) => {
6575
6611
  const propertySchemas = model?.properties ? modelPropertiesToObject(model.properties) : undefined;
6576
6612
  modelFileId ?? (modelFileId = model?.id);
6577
6613
  const newSeedId = await createSeed({ type: seedType, modelFileId });
6578
- const newVersionId = await createVersion({ seedLocalId: newSeedId, seedType: easName(modelName) });
6579
- // Build set of all properties to create metadata for: union of model schema + propertyData
6580
- // This ensures we create metadata for ALL model properties even when creating with no initial values
6581
- // (fixes first-item persistence: loadOrCreateItem needs metadata rows to run createItemPropertyInstances)
6582
- const allPropertyNames = new Set(Object.keys(propertyData));
6583
- if (propertySchemas) {
6584
- for (const name of Object.keys(propertySchemas)) {
6585
- allPropertyNames.add(name);
6586
- }
6587
- }
6588
- for (const propertyName of allPropertyNames) {
6589
- const propertyValue = propertyData[propertyName];
6590
- const propertyRecordSchema = propertySchemas?.[propertyName];
6591
- // ItemStorage content lives in the property's file (`<seedLocalId><extension>`), as a save puts
6592
- // it; the row records where. Stored verbatim in the row, publish would never upload it.
6593
- const isItemStorageValue = propertyRecordSchema?.storageType === 'ItemStorage' &&
6594
- propertyValue != null &&
6595
- propertyValue !== '';
6596
- const insertRow = (storageFields) => createMetadata({
6614
+ try {
6615
+ return await writeVersionAndRows(newSeedId);
6616
+ }
6617
+ catch (error) {
6618
+ // The rows are separate inserts (no transaction): remove what was written so a failure leaves
6619
+ // no half-made draft.
6620
+ const { discardNewDraft } = await import('./discardNewDraft-g8w3uHFM.js');
6621
+ await discardNewDraft(newSeedId).catch(() => undefined);
6622
+ throw error;
6623
+ }
6624
+ async function writeVersionAndRows(newSeedId) {
6625
+ const newVersionId = await createVersion({ seedLocalId: newSeedId, seedType: easName(modelName) });
6626
+ // Build set of all properties to create metadata for: union of model schema + propertyData
6627
+ // This ensures we create metadata for ALL model properties even when creating with no initial values
6628
+ // (fixes first-item persistence: loadOrCreateItem needs metadata rows to run createItemPropertyInstances)
6629
+ const allPropertyNames = new Set(Object.keys(propertyData));
6630
+ if (propertySchemas) {
6631
+ for (const name of Object.keys(propertySchemas)) {
6632
+ allPropertyNames.add(name);
6633
+ }
6634
+ }
6635
+ for (const propertyName of allPropertyNames) {
6636
+ const propertyValue = propertyData[propertyName];
6637
+ const propertyRecordSchema = propertySchemas?.[propertyName];
6638
+ // ItemStorage content lives in the property's file (`<seedLocalId><extension>`), as a save puts
6639
+ // it; the row records where. Stored verbatim in the row, publish would never upload it.
6640
+ const isItemStorageValue = propertyRecordSchema?.storageType === 'ItemStorage' &&
6641
+ propertyValue != null &&
6642
+ propertyValue !== '';
6643
+ const insertRow = (storageFields) => createMetadata({
6644
+ seedLocalId: newSeedId,
6645
+ versionLocalId: newVersionId,
6646
+ propertyName,
6647
+ propertyValue: storageFields ? undefined : propertyValue,
6648
+ ...storageFields,
6649
+ modelName,
6650
+ }, propertyRecordSchema, { skipValidation: true, modelFileId });
6651
+ if (!isItemStorageValue) {
6652
+ await insertRow();
6653
+ continue;
6654
+ }
6655
+ // File and row under the file's lock, like every writer of a local draft's file (see
6656
+ // withItemStorageFileLock). The seed is new, so nothing else should be writing it yet.
6657
+ const target = {
6658
+ seedId: newSeedId,
6659
+ localStorageDir: propertyRecordSchema.localStorageDir,
6660
+ filenameSuffix: propertyRecordSchema.filenameSuffix,
6661
+ };
6662
+ await withItemStorageFileLock(getItemStorageFilePath(target), async () => {
6663
+ const written = await writeItemStorageFile(target, propertyValue);
6664
+ await insertRow({
6665
+ refResolvedValue: written.fileName,
6666
+ localStorageDir: written.localStorageDir,
6667
+ refValueType: 'file',
6668
+ });
6669
+ });
6670
+ }
6671
+ return {
6672
+ modelName,
6597
6673
  seedLocalId: newSeedId,
6598
6674
  versionLocalId: newVersionId,
6599
- propertyName,
6600
- propertyValue: storageFields ? undefined : propertyValue,
6601
- ...storageFields,
6602
- modelName,
6603
- }, propertyRecordSchema, { skipValidation: true, modelFileId });
6604
- if (!isItemStorageValue) {
6605
- await insertRow();
6606
- continue;
6607
- }
6608
- // File and row under the file's lock, like every writer of a local draft's file (see
6609
- // withItemStorageFileLock). The seed is new, so nothing else should be writing it yet.
6610
- const target = {
6611
- seedId: newSeedId,
6612
- localStorageDir: propertyRecordSchema.localStorageDir,
6613
- filenameSuffix: propertyRecordSchema.filenameSuffix,
6614
6675
  };
6615
- await withItemStorageFileLock(getItemStorageFilePath(target), async () => {
6616
- const written = await writeItemStorageFile(target, propertyValue);
6617
- await insertRow({
6618
- refResolvedValue: written.fileName,
6619
- localStorageDir: written.localStorageDir,
6620
- refValueType: 'file',
6621
- });
6622
- });
6623
6676
  }
6624
- return {
6625
- modelName,
6626
- seedLocalId: newSeedId,
6627
- versionLocalId: newVersionId,
6628
- };
6629
6677
  };
6630
6678
 
6631
6679
  /**
@@ -6750,7 +6798,7 @@ const getModel = () => {
6750
6798
  // the fragile `import(...).then(n => n.X)` chunk-namespace pattern.
6751
6799
  if (!modelImportPromise) {
6752
6800
  modelImportPromise = (async () => {
6753
- const _mod_23 = await import('./errors-DdWbxb_n.js');
6801
+ const _mod_23 = await import('./errors-CCMxedOB.js');
6754
6802
  const _ns_23 = _mod_23.h;
6755
6803
  const mod = _ns_23;
6756
6804
  ModelClass = mod.Model;
@@ -6918,14 +6966,16 @@ class Item {
6918
6966
  };
6919
6967
  this.getPublishUploads = async (options) => {
6920
6968
  // Use dynamic import to break circular dependency
6921
- const getPublishUploadsMod = await import('./getPublishUploads-J-143iSV.js');
6969
+ const _mod_24 = await import('./getPublishUploads-pEOrXJbF.js');
6970
+ const _ns_24 = _mod_24.o;
6971
+ const getPublishUploadsMod = _ns_24;
6922
6972
  const { getPublishUploads } = getPublishUploadsMod;
6923
6973
  return await getPublishUploads(this, [], undefined, options);
6924
6974
  };
6925
6975
  this.getPublishPayload = async (uploadedTransactions, options) => {
6926
- const _mod_24 = await import('./getPublishPayload-DPy-uMrR.js');
6927
- const _ns_24 = _mod_24.g;
6928
- const getPublishPayloadMod = _ns_24;
6976
+ const _mod_25 = await import('./getPublishPayload-CwNOhnir.js');
6977
+ const _ns_25 = _mod_25.g;
6978
+ const getPublishPayloadMod = _ns_25;
6929
6979
  const { getPublishPayload } = getPublishPayloadMod;
6930
6980
  return await getPublishPayload(this, uploadedTransactions, options);
6931
6981
  };
@@ -7459,18 +7509,18 @@ class Item {
7459
7509
  const db = BaseDb.getAppDb();
7460
7510
  if (db && props.modelName) {
7461
7511
  // Model names are only unique per schema: resolve the exact models row from the most specific scope.
7462
- const _mod_25 = await import('./BasePathResolver-DrzGVH9L.js');
7463
- const _ns_25 = _mod_25.ba;
7464
- const { resolveModelRecord } = _ns_25;
7512
+ const _mod_26 = await import('./BasePathResolver-B-fK7_N_.js');
7513
+ const _ns_26 = _mod_26.bf;
7514
+ const { resolveModelRecord } = _ns_26;
7465
7515
  const modelRecord = await resolveModelRecord(props.modelName, {
7466
7516
  modelFileId: props.modelFileId ?? modelInstance?.id,
7467
7517
  schemaName: schemaName ?? modelInstance?.schemaName,
7468
7518
  });
7469
7519
  const modelRecords = modelRecord ? [modelRecord] : [];
7470
7520
  if (!modelRecord) {
7471
- const _mod_26 = await import('./errors-DdWbxb_n.js');
7472
- const _ns_26 = _mod_26.j;
7473
- const { UnknownModelError } = _ns_26;
7521
+ const _mod_27 = await import('./errors-CCMxedOB.js');
7522
+ const _ns_27 = _mod_27.j;
7523
+ const { UnknownModelError } = _ns_27;
7474
7524
  throw new UnknownModelError(props.modelName, schemaName ?? modelInstance?.schemaName);
7475
7525
  }
7476
7526
  if (modelRecord?.schemaFileId) {
@@ -7479,12 +7529,12 @@ class Item {
7479
7529
  // Scope the constructor's Model lookup to this model's schema (as getItemData does on reload),
7480
7530
  // so a same-named model cached from another schema can't supply the property set.
7481
7531
  if (modelRecord && !props.schemaName) {
7482
- const _mod_27 = await import('./BasePathResolver-DrzGVH9L.js');
7483
- const _ns_27 = _mod_27.b9;
7484
- const { modelSchemas } = _ns_27;
7485
- const _mod_28 = await import('./BasePathResolver-DrzGVH9L.js');
7486
- const _ns_28 = _mod_28.b8;
7487
- const { schemas: schemasTable } = _ns_28;
7532
+ const _mod_28 = await import('./BasePathResolver-B-fK7_N_.js');
7533
+ const _ns_28 = _mod_28.be;
7534
+ const { modelSchemas } = _ns_28;
7535
+ const _mod_29 = await import('./BasePathResolver-B-fK7_N_.js');
7536
+ const _ns_29 = _mod_29.bd;
7537
+ const { schemas: schemasTable } = _ns_29;
7488
7538
  const schemaRows = await db
7489
7539
  .select({ schemaName: schemasTable.name })
7490
7540
  .from(modelSchemas)
@@ -7653,22 +7703,35 @@ class Item {
7653
7703
  return proxiedInstance;
7654
7704
  try {
7655
7705
  await this.waitForItemInstanceReadyForRead(proxiedInstance, readyTimeout);
7706
+ await this.savePipelineValues(proxiedInstance, pipelineValues, readyTimeout);
7656
7707
  }
7657
7708
  catch (err) {
7658
- try {
7659
- proxiedInstance.unload();
7660
- }
7661
- catch {
7662
- /* best-effort cache cleanup */
7663
- }
7709
+ // A rejected create leaves nothing behind, so a retry doesn't make a second draft.
7710
+ await this.discardCreatedItem(proxiedInstance, seedLocalId);
7664
7711
  throw err;
7665
7712
  }
7666
- await this.savePipelineValues(proxiedInstance, pipelineValues, readyTimeout);
7667
7713
  return proxiedInstance;
7668
7714
  }
7715
+ /** Stops a just-created item and deletes what create wrote (see discardNewDraft). */
7716
+ static async discardCreatedItem(item, seedLocalId) {
7717
+ try {
7718
+ this.dropCachedInstancesForSeedIds([seedLocalId]);
7719
+ }
7720
+ catch {
7721
+ /* best-effort cache cleanup */
7722
+ }
7723
+ try {
7724
+ const { discardNewDraft } = await import('./discardNewDraft-g8w3uHFM.js');
7725
+ await discardNewDraft(seedLocalId);
7726
+ }
7727
+ catch (error) {
7728
+ itemLogger(`Item.create: could not remove the draft ${seedLocalId} after a failure:`, error);
7729
+ }
7730
+ }
7669
7731
  /**
7670
7732
  * Run each File/Image/Html/ItemStorage initial value through its ItemProperty save pipeline (sequentially, to
7671
- * avoid SQLite write contention). Rejects on the first failure; the item itself has been created.
7733
+ * avoid SQLite write contention). Rejects on the first failure, with ItemCreateValidationError when the
7734
+ * value breaks its property's rules; Item.create then removes the item.
7672
7735
  */
7673
7736
  static async savePipelineValues(item, pipelineValues, timeout) {
7674
7737
  for (const [propertyName, value] of pipelineValues) {
@@ -7681,6 +7744,14 @@ class Item {
7681
7744
  await property.save();
7682
7745
  }
7683
7746
  catch (error) {
7747
+ if (error instanceof ItemPropertySaveValidationError) {
7748
+ const _mod_30 = await import('./errors-CCMxedOB.js');
7749
+ const _ns_30 = _mod_30.j;
7750
+ const { ItemCreateValidationError } = _ns_30;
7751
+ const created = new ItemCreateValidationError(item.modelName, error.validationErrors.map((e) => ({ property: propertyName, code: e.code, message: e.message })));
7752
+ created.cause = error;
7753
+ throw created;
7754
+ }
7684
7755
  throw new Error(`Item.create: failed to save ${item.modelName}.${propertyName} for item ${item.seedLocalId}: ` +
7685
7756
  (error instanceof Error ? error.message : String(error)), { cause: error });
7686
7757
  }
@@ -7841,9 +7912,9 @@ class Item {
7841
7912
  if (!appDb || Item.instanceCache.size === 0) {
7842
7913
  return;
7843
7914
  }
7844
- const _mod_29 = await import('./index-7y2f_iQz.js');
7845
- const _ns_29 = _mod_29.s;
7846
- const { metadata } = _ns_29;
7915
+ const _mod_31 = await import('./index-BQSK-r_A.js');
7916
+ const _ns_31 = _mod_31.s;
7917
+ const { metadata } = _ns_31;
7847
7918
  const { eq, and } = await import('drizzle-orm');
7848
7919
  const dedupedInstances = new Map();
7849
7920
  for (const entry of Item.instanceCache.values()) {
@@ -8004,11 +8075,11 @@ class Item {
8004
8075
  }
8005
8076
  /** Throws ItemCreateValidationError for unknown keys and values that break their property's rules. */
8006
8077
  static async assertValidCreateValues(props, propertyNames, dataTypeByPropertyName, skipKeys) {
8007
- const _mod_30 = await import('./errors-DdWbxb_n.js');
8008
- const _ns_30 = _mod_30.j;
8009
- const { ItemCreateValidationError } = _ns_30;
8010
- const { getPropertySchema } = await import('./property-zFPMtR3T.js');
8011
- const { SchemaValidationService } = await import('./SchemaValidationService-BNYMacsx.js');
8078
+ const _mod_32 = await import('./errors-CCMxedOB.js');
8079
+ const _ns_32 = _mod_32.j;
8080
+ const { ItemCreateValidationError } = _ns_32;
8081
+ const { getPropertySchema } = await import('./property-5AD2naVS.js');
8082
+ const { SchemaValidationService } = await import('./SchemaValidationService-CzybXLiS.js');
8012
8083
  const validationService = new SchemaValidationService();
8013
8084
  const modelName = props.modelName;
8014
8085
  const known = new Set(propertyNames);
@@ -8045,7 +8116,7 @@ class Item {
8045
8116
  // Not JSON: validated as given, and rejected as a non-array
8046
8117
  }
8047
8118
  }
8048
- const { resolvePropertyValidationRules } = await import('./propertyValidationRules-CeFVhdQg.js');
8119
+ const { resolvePropertyValidationRules } = await import('./propertyValidationRules-Bdgz0Nrr.js');
8049
8120
  const rules = propertySchema?.validation ??
8050
8121
  (await resolvePropertyValidationRules(modelName, key, {
8051
8122
  modelFileId: props.modelFileId,
@@ -8376,9 +8447,9 @@ class Item {
8376
8447
  itemActor.send(event);
8377
8448
  };
8378
8449
  try {
8379
- const _mod_31 = await import('./index-7y2f_iQz.js');
8380
- const _ns_31 = _mod_31.s;
8381
- const seedSchemaMod = _ns_31;
8450
+ const _mod_33 = await import('./index-BQSK-r_A.js');
8451
+ const _ns_33 = _mod_33.s;
8452
+ const seedSchemaMod = _ns_33;
8382
8453
  const { seeds, versions, metadata } = seedSchemaMod;
8383
8454
  const drizzleMod = await import('drizzle-orm');
8384
8455
  const { eq, and } = drizzleMod;
@@ -8740,5 +8811,5 @@ var Item$1 = /*#__PURE__*/Object.freeze({
8740
8811
  Item: Item
8741
8812
  });
8742
8813
 
8743
- export { unloadEntity as $, getPublishExecutor as A, getRevokeExecutor as B, ClientManagerState as C, DEFAULT_READY_TIMEOUT_MS as D, getUploadExecutor as E, getVersionData$1 as F, isLocalUnsealedDraft as G, isSeedRowOwned as H, Item as I, localUnsealedDraftSql as J, ownedPublisherSql as K, ownedSeedsSql as L, METADATA_LATEST_FIRST_ORDER_SQL as M, pickLatestMetadataRowPerProperty as N, OwnershipError as O, PUBLISH_NOT_CONFIGURED_MESSAGE as P, placeholderUidSql as Q, propertyMachine as R, publisherInAddressListSql as S, publisherIsInOwnedSet as T, setAdditionalSyncAddresses as U, setGetPublisherForNewSeeds as V, setPublishExecutor as W, setRevokeExecutor as X, setUploadExecutor as Y, getInvariantSafePropertyDescriptor as Z, clearDestroySubscriptions as _, chunkValues as a, ClientManagerEvents as a0, withLockedItemStorageRow as a1, getItemStorageFilePath as a2, writeItemStorageFile as a3, resolvePublisherFromSeedRow as a4, getPropertyData$1 as a5, Item$1 as a6, getGetAdditionalSyncAddresses as b, compareMetadataRowsLatestFirst as c, ItemProperty as d, ItemPropertySaveValidationError as e, assertItemOwned as f, getItemData as g, getEasSchemaUidForModel as h, isItemOwned as i, getLatestPublishedVersionRow as j, isVersionRevoked as k, waitForEntityIdle as l, createReactiveProxy as m, findEntity as n, forceRemoveFromCaches as o, parseListPropertyValueFromStorage as p, runDestroyLifecycle as q, rowsPerInsert as r, selectInBatches as s, isPublishedMetadataRow as t, MachineIds as u, createNewItem as v, writeInBatches as w, getEasSchemaForItemProperty as x, getGetPublisherForNewSeeds as y, getMetadataLatest as z };
8744
- //# sourceMappingURL=Item-BUUFuywT.js.map
8814
+ export { unloadEntity as $, getPublishExecutor as A, getRevokeExecutor as B, ClientManagerState as C, DEFAULT_READY_TIMEOUT_MS as D, getUploadExecutor as E, getVersionData$1 as F, isLocalUnsealedDraft as G, isSeedRowOwned as H, Item as I, localUnsealedDraftSql as J, ownedPublisherSql as K, ownedSeedsSql as L, METADATA_LATEST_FIRST_ORDER_SQL as M, pickLatestMetadataRowPerProperty as N, OwnershipError as O, PUBLISH_NOT_CONFIGURED_MESSAGE as P, placeholderUidSql as Q, propertyMachine as R, publisherInAddressListSql as S, publisherIsInOwnedSet as T, setAdditionalSyncAddresses as U, setGetPublisherForNewSeeds as V, setPublishExecutor as W, setRevokeExecutor as X, setUploadExecutor as Y, getInvariantSafePropertyDescriptor as Z, clearDestroySubscriptions as _, ItemProperty as a, ClientManagerEvents as a0, withLockedItemStorageRow as a1, getItemStorageFilePath as a2, writeItemStorageFile as a3, resolvePublisherFromSeedRow as a4, getPropertyData$1 as a5, Item$1 as a6, ItemPropertySaveValidationError as b, assertItemOwned as c, waitForEntityIdle as d, compareMetadataRowsLatestFirst as e, getEasSchemaUidForModel as f, getItemData as g, getLatestPublishedVersionRow as h, isItemOwned as i, isVersionRevoked as j, chunkValues as k, getGetAdditionalSyncAddresses as l, createReactiveProxy as m, findEntity as n, forceRemoveFromCaches as o, parseListPropertyValueFromStorage as p, runDestroyLifecycle as q, rowsPerInsert as r, selectInBatches as s, isPublishedMetadataRow as t, MachineIds as u, createNewItem as v, writeInBatches as w, getEasSchemaForItemProperty as x, getGetPublisherForNewSeeds as y, getMetadataLatest as z };
8815
+ //# sourceMappingURL=Item-BDmsdNTQ.js.map