@seedprotocol/sdk 0.4.30 → 0.4.32

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 (101) hide show
  1. package/dist/{ArweaveClient-BA7b13Dl.js → ArweaveClient-CZpZgmR2.js} +3 -3
  2. package/dist/{ArweaveClient-BA7b13Dl.js.map → ArweaveClient-CZpZgmR2.js.map} +1 -1
  3. package/dist/{ArweaveClient-DJ8Q63JQ.js → ArweaveClient-Cs7AL9dp.js} +3 -3
  4. package/dist/{ArweaveClient-DJ8Q63JQ.js.map → ArweaveClient-Cs7AL9dp.js.map} +1 -1
  5. package/dist/{Db-BHMXF86s.js → Db-CF6R7HIy.js} +4 -4
  6. package/dist/{Db-BHMXF86s.js.map → Db-CF6R7HIy.js.map} +1 -1
  7. package/dist/{Db-qgwjsLKI.js → Db-CZkONsdT.js} +4 -4
  8. package/dist/{Db-qgwjsLKI.js.map → Db-CZkONsdT.js.map} +1 -1
  9. package/dist/{EasClient-BqU4c27A.js → EasClient-PXOzSzPG.js} +2 -2
  10. package/dist/{EasClient-DjSKI-Jp.js.map → EasClient-PXOzSzPG.js.map} +1 -1
  11. package/dist/{EasClient-DjSKI-Jp.js → EasClient-qfTiM2we.js} +2 -2
  12. package/dist/{EasClient-BqU4c27A.js.map → EasClient-qfTiM2we.js.map} +1 -1
  13. package/dist/{FileManager-DJ-mFSmc.js → FileManager-5GkHtxF7.js} +2 -2
  14. package/dist/{FileManager-DJ-mFSmc.js.map → FileManager-5GkHtxF7.js.map} +1 -1
  15. package/dist/{FileManager-DIbVCWke.js → FileManager-jORQ8Bb6.js} +2 -2
  16. package/dist/{FileManager-DIbVCWke.js.map → FileManager-jORQ8Bb6.js.map} +1 -1
  17. package/dist/{ModelProperty-jBpPbg3l.js → ModelProperty-e_hXSFvf.js} +17 -17
  18. package/dist/{ModelProperty-jBpPbg3l.js.map → ModelProperty-e_hXSFvf.js.map} +1 -1
  19. package/dist/{PathResolver-DmFG4fR1.js → PathResolver-B4_X69Rd.js} +2 -2
  20. package/dist/{PathResolver-DmFG4fR1.js.map → PathResolver-B4_X69Rd.js.map} +1 -1
  21. package/dist/{PathResolver-CxmIkVyO.js → PathResolver-Dz0RVGIz.js} +2 -2
  22. package/dist/{PathResolver-CxmIkVyO.js.map → PathResolver-Dz0RVGIz.js.map} +1 -1
  23. package/dist/{QueryClient-7vk66LoN.js → QueryClient-CXHZ239d.js} +2 -2
  24. package/dist/{QueryClient-7vk66LoN.js.map → QueryClient-CXHZ239d.js.map} +1 -1
  25. package/dist/{QueryClient-CHayftHv.js → QueryClient-D_UK4YLm.js} +2 -2
  26. package/dist/{QueryClient-CHayftHv.js.map → QueryClient-D_UK4YLm.js.map} +1 -1
  27. package/dist/{Schema-CyWoCyDH.js → Schema-DonRkUOJ.js} +22 -22
  28. package/dist/{Schema-CyWoCyDH.js.map → Schema-DonRkUOJ.js.map} +1 -1
  29. package/dist/{SchemaValidationService-ByxyqvS9.js → SchemaValidationService-DcmfhQae.js} +2 -2
  30. package/dist/{SchemaValidationService-ByxyqvS9.js.map → SchemaValidationService-DcmfhQae.js.map} +1 -1
  31. package/dist/{backfillMetadataPropertyIds-CUenpA6t.js → backfillMetadataPropertyIds-CKTfvFgQ.js} +2 -2
  32. package/dist/{backfillMetadataPropertyIds-CUenpA6t.js.map → backfillMetadataPropertyIds-CKTfvFgQ.js.map} +1 -1
  33. package/dist/cjs/{ModelProperty-BEpPD4wH.js → ModelProperty-BQYU5hPQ.js} +17 -17
  34. package/dist/cjs/{ModelProperty-BEpPD4wH.js.map → ModelProperty-BQYU5hPQ.js.map} +1 -1
  35. package/dist/cjs/{Schema-DgvWd1wc.js → Schema-BcRHcQ0W.js} +20 -20
  36. package/dist/cjs/{Schema-DgvWd1wc.js.map → Schema-BcRHcQ0W.js.map} +1 -1
  37. package/dist/cjs/{SchemaValidationService-DazyAm6l.js → SchemaValidationService-CQNDgyZl.js} +2 -2
  38. package/dist/cjs/{SchemaValidationService-DazyAm6l.js.map → SchemaValidationService-CQNDgyZl.js.map} +1 -1
  39. package/dist/cjs/{backfillMetadataPropertyIds-BHJnW-NK.js → backfillMetadataPropertyIds-Dn4oVmEv.js} +2 -2
  40. package/dist/cjs/{backfillMetadataPropertyIds-BHJnW-NK.js.map → backfillMetadataPropertyIds-Dn4oVmEv.js.map} +1 -1
  41. package/dist/cjs/{getItem-CStbsCge.js → getItem-DpnPrzl3.js} +2 -2
  42. package/dist/cjs/{getItem-CStbsCge.js.map → getItem-DpnPrzl3.js.map} +1 -1
  43. package/dist/cjs/{getPublishPayload-Bws1mdNc.js → getPublishPayload-CGKMEL3H.js} +11 -11
  44. package/dist/cjs/{getPublishPayload-Bws1mdNc.js.map → getPublishPayload-CGKMEL3H.js.map} +1 -1
  45. package/dist/cjs/{getPublishUploads-BNYeCNf_.js → getPublishUploads-DeI0f2UN.js} +4 -4
  46. package/dist/cjs/{getPublishUploads-BNYeCNf_.js.map → getPublishUploads-DeI0f2UN.js.map} +1 -1
  47. package/dist/cjs/{getSegmentedItemProperties-CkhTBPSP.js → getSegmentedItemProperties-BgS_FhAx.js} +3 -3
  48. package/dist/cjs/{getSegmentedItemProperties-CkhTBPSP.js.map → getSegmentedItemProperties-BgS_FhAx.js.map} +1 -1
  49. package/dist/cjs/{index-BLco2YiE.js → index-BnAqr2le.js} +3 -3
  50. package/dist/cjs/index-BnAqr2le.js.map +1 -0
  51. package/dist/cjs/{index-CZ7yR-bZ.js → index-ByozbTn_.js} +50 -38
  52. package/dist/cjs/index-ByozbTn_.js.map +1 -0
  53. package/dist/cjs/{ownership-B1I8eLiv.js → ownership-CsWuaNfH.js} +2 -2
  54. package/dist/cjs/{ownership-B1I8eLiv.js.map → ownership-CsWuaNfH.js.map} +1 -1
  55. package/dist/cjs/{property-sm3N2yBU.js → property-CeR45LMx.js} +4 -4
  56. package/dist/cjs/{property-sm3N2yBU.js.map → property-CeR45LMx.js.map} +1 -1
  57. package/dist/cjs/{syncDbWithEas-Dh9HSiwm.js → syncDbWithEas-CA2Lum5V.js} +5 -5
  58. package/dist/cjs/{syncDbWithEas-Dh9HSiwm.js.map → syncDbWithEas-CA2Lum5V.js.map} +1 -1
  59. package/dist/debug-default-shim.js +27 -0
  60. package/dist/{getItem-CdgsloEB.js → getItem-GOXWo_Iy.js} +2 -2
  61. package/dist/{getItem-CdgsloEB.js.map → getItem-GOXWo_Iy.js.map} +1 -1
  62. package/dist/{getPublishPayload-DlkHAsOA.js → getPublishPayload-D16enahU.js} +11 -11
  63. package/dist/{getPublishPayload-DlkHAsOA.js.map → getPublishPayload-D16enahU.js.map} +1 -1
  64. package/dist/{getPublishUploads-BeukCBiR.js → getPublishUploads-wGqH19UY.js} +4 -4
  65. package/dist/{getPublishUploads-BeukCBiR.js.map → getPublishUploads-wGqH19UY.js.map} +1 -1
  66. package/dist/{getSegmentedItemProperties-B_yciZHD.js → getSegmentedItemProperties-Be3kYWY3.js} +3 -3
  67. package/dist/{getSegmentedItemProperties-B_yciZHD.js.map → getSegmentedItemProperties-Be3kYWY3.js.map} +1 -1
  68. package/dist/{index-CfZAy_U1.js → index-BFyMxc7e.js} +2 -2
  69. package/dist/index-BFyMxc7e.js.map +1 -0
  70. package/dist/{index-C3oIxmh-.js → index-BcXKZQpX.js} +64 -52
  71. package/dist/index-BcXKZQpX.js.map +1 -0
  72. package/dist/{index-j0nIoPTo.js → index-C9p-skT3.js} +3 -3
  73. package/dist/index-C9p-skT3.js.map +1 -0
  74. package/dist/main.cjs +1 -1
  75. package/dist/main.js +13 -13
  76. package/dist/node.js +10 -10
  77. package/dist/{ownership-Br40yugt.js → ownership-C17YhE7J.js} +2 -2
  78. package/dist/{ownership-Br40yugt.js.map → ownership-C17YhE7J.js.map} +1 -1
  79. package/dist/{property-DlfKPjHu.js → property-CRAau-Q-.js} +5 -5
  80. package/dist/{property-DlfKPjHu.js.map → property-CRAau-Q-.js.map} +1 -1
  81. package/dist/{queries-CIlWKRoN.js → queries-Ct7CcQ3g.js} +2 -2
  82. package/dist/{queries-CIlWKRoN.js.map → queries-Ct7CcQ3g.js.map} +1 -1
  83. package/dist/src/ItemProperty/ItemProperty.d.ts.map +1 -1
  84. package/dist/src/helpers/mediaRef.d.ts.map +1 -1
  85. package/dist/src/vite/debug-default-shim.d.ts +3 -0
  86. package/dist/src/vite/debug-default-shim.d.ts.map +1 -0
  87. package/dist/src/vite/index.d.ts.map +1 -1
  88. package/dist/{syncDbWithEas-Dsa5kEMM.js → syncDbWithEas-CB5aXPtf.js} +6 -6
  89. package/dist/{syncDbWithEas-Dsa5kEMM.js.map → syncDbWithEas-CB5aXPtf.js.map} +1 -1
  90. package/dist/{updateSeedRevokedAt-DHDIH0zy.js → updateSeedRevokedAt-BIu5Q4Po.js} +2 -2
  91. package/dist/{updateSeedRevokedAt-DHDIH0zy.js.map → updateSeedRevokedAt-BIu5Q4Po.js.map} +1 -1
  92. package/dist/vite.cjs +67 -1
  93. package/dist/vite.cjs.map +1 -1
  94. package/dist/vite.js +67 -1
  95. package/dist/vite.js.map +1 -1
  96. package/package.json +4 -4
  97. package/dist/cjs/index-BLco2YiE.js.map +0 -1
  98. package/dist/cjs/index-CZ7yR-bZ.js.map +0 -1
  99. package/dist/index-C3oIxmh-.js.map +0 -1
  100. package/dist/index-CfZAy_U1.js.map +0 -1
  101. package/dist/index-j0nIoPTo.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"getPublishUploads-BNYeCNf_.js","sources":["../../../src/db/read/getPublishUploads.ts"],"sourcesContent":["import { BaseFileManager } from '@/helpers'\nimport {\n normalizeRelationPropertyValue,\n resolveSeedIdsFromRefString,\n} from '@/helpers/relationSeedRef'\nimport { BaseArweaveClient } from '@/helpers/ArweaveClient/BaseArweaveClient'\nimport { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'\nimport debug from 'debug'\nimport { IItem, IItemProperty } from '@/interfaces'\nimport { getContentHash } from '@/helpers/crypto'\nimport { Item } from '@/Item/Item'\nimport type { ArweaveTransaction, TransactionTag } from '@/types/arweave'\nimport { PublishUpload } from '@/types/publish'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { htmlEmbeddedImageCoPublish } from '@/seedSchema/HtmlEmbeddedImageCoPublishSchema'\nimport { eq } from 'drizzle-orm'\nimport { ModelPropertyDataTypes } from '@/helpers/property'\n\nconst logger = debug('seedSdk:item:getPublishUploads')\n\n/** Optional tags merged into each Arweave tx after Content-SHA-256 / Content-Type. */\nexport type GetPublishUploadsOptions = {\n arweaveUploadTags?: TransactionTag[]\n /**\n * Html storage seed local ids to skip (phase 1 of two-phase embedded-image publish).\n */\n deferHtmlStorageSeedLocalIds?: string[]\n /**\n * When set, only Html storage seeds in this list are included (phase 2). Non-Html storage uploads are omitted.\n */\n onlyHtmlStorageSeedLocalIds?: string[]\n /** When true, do not recurse into relation properties (phase 2 must not re-upload related items). */\n skipRelationRecursion?: boolean\n}\n\nconst EXTENSION_TO_MIME: Record<string, string> = {\n png: 'image/png',\n jpg: 'image/jpeg',\n jpeg: 'image/jpeg',\n gif: 'image/gif',\n webp: 'image/webp',\n svg: 'image/svg+xml',\n html: 'text/html',\n htm: 'text/html',\n json: 'application/json',\n txt: 'text/plain',\n}\n\nconst getMimeTypeFromPath = (filePathOrName: string): string | undefined => {\n const ext = filePathOrName.split('.').pop()?.toLowerCase()\n return ext ? EXTENSION_TO_MIME[ext] : undefined\n}\n\nconst toUint8Array = async (data: Buffer | Blob): Promise<Uint8Array> => {\n if (typeof Blob !== 'undefined' && data instanceof Blob) {\n return new Uint8Array(await data.arrayBuffer())\n }\n return new Uint8Array(data as Buffer)\n}\n\nexport const prepareArweaveTransaction = async (\n data: string | Uint8Array,\n contentHash: string | undefined,\n contentType?: string,\n additionalTags?: TransactionTag[],\n): Promise<ArweaveTransaction> => {\n const tags: TransactionTag[] = []\n if (contentHash) {\n tags.push({ name: 'Content-SHA-256', value: contentHash })\n logger('contentHash', contentHash)\n logger('adding content hash tag')\n }\n if (contentType) {\n tags.push({ name: 'Content-Type', value: contentType })\n }\n if (additionalTags?.length) {\n tags.push(...additionalTags)\n }\n\n const tx = await BaseArweaveClient.createTransaction(data, {\n tags: tags.length ? tags : undefined,\n })\n\n return tx\n}\n\n\nconst getStorageDirForDataType = (dataType: string): string => {\n switch (dataType) {\n case 'Image':\n return BaseFileManager.getFilesPath('images')\n case 'File':\n return BaseFileManager.getFilesPath('files')\n case 'Html':\n return BaseFileManager.getFilesPath('html')\n case 'Json':\n return BaseFileManager.getFilesPath('json')\n default:\n return BaseFileManager.getFilesPath('images')\n }\n}\n\nconst DATA_URI_IMAGE = /^data:(image\\/[a-zA-Z0-9.+-]+);base64,([\\s\\S]*)$/i\n\nfunction decodeDataUriImage(dataUri: string): { mimeType: string; bytes: Uint8Array } | null {\n const m = DATA_URI_IMAGE.exec((dataUri ?? '').trim())\n if (!m) return null\n try {\n const mimeType = m[1]!.toLowerCase().trim()\n const base64 = m[2]!.replace(/\\s/g, '')\n const binary = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0))\n return { mimeType, bytes: binary }\n } catch {\n return null\n }\n}\n\nconst getStorageSeedUploads = async (\n itemStorageSeedProperties: IItemProperty<any>[],\n options?: GetPublishUploadsOptions,\n) => {\n const uploads: PublishUpload[] = []\n const extra = options?.arweaveUploadTags\n\n for (const itemProperty of itemStorageSeedProperties) {\n const snapshot = itemProperty.getService().getSnapshot()\n const context = 'context' in snapshot ? snapshot.context : null\n if (!context) {\n continue\n }\n const propertyValue = (context as any).propertyValue\n const refResolvedValue = (context as any).refResolvedValue\n if (!refResolvedValue) {\n continue\n }\n\n // propertyValue is the storage seed's seedLocalId; use it for the upload so processRelationOrImageProperty can match\n const { seedLocalId } = resolveSeedIdsFromRefString(\n normalizeRelationPropertyValue(propertyValue) ?? '',\n )\n if (!seedLocalId) {\n continue\n }\n\n const dataType =\n itemProperty.propertyDef?.refValueType ??\n itemProperty.propertyDef?.dataType ??\n 'Image'\n\n if (dataType === ModelPropertyDataTypes.Html) {\n if (options?.deferHtmlStorageSeedLocalIds?.includes(seedLocalId)) {\n continue\n }\n if (\n options?.onlyHtmlStorageSeedLocalIds?.length &&\n !options.onlyHtmlStorageSeedLocalIds.includes(seedLocalId)\n ) {\n continue\n }\n } else if (options?.onlyHtmlStorageSeedLocalIds?.length) {\n continue\n }\n\n const baseDir = getStorageDirForDataType(dataType)\n const filePath = `${baseDir}/${refResolvedValue}`\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n continue\n }\n\n const fileBuffer = await BaseFileManager.readFileAsBuffer(filePath)\n const fileContents = await toUint8Array(fileBuffer)\n\n const contentHash = await getContentHash(fileContents)\n const contentType = getMimeTypeFromPath(refResolvedValue)\n\n const transaction = await prepareArweaveTransaction(\n fileContents,\n contentHash,\n contentType,\n extra,\n )\n\n uploads.push({\n itemPropertyName: itemProperty.propertyName,\n itemPropertyLocalId: itemProperty.localId,\n seedLocalId,\n versionLocalId: itemProperty.versionLocalId!,\n transactionToSign: transaction,\n })\n }\n\n return uploads\n}\n\nasync function appendCoPublishedImageUploads(\n item: IItem<any>,\n uploads: PublishUpload[],\n options?: GetPublishUploadsOptions,\n): Promise<PublishUpload[]> {\n const appDb = BaseDb.getAppDb()\n if (!appDb || options?.onlyHtmlStorageSeedLocalIds?.length) return uploads\n\n const rows = await appDb\n .select()\n .from(htmlEmbeddedImageCoPublish)\n .where(eq(htmlEmbeddedImageCoPublish.parentSeedLocalId, item.seedLocalId))\n\n const seen = new Set(uploads.map((u) => u.seedLocalId))\n\n for (const row of rows) {\n if (seen.has(row.imageSeedLocalId)) continue\n const imageItem = await Item.find({ seedLocalId: row.imageSeedLocalId, modelName: 'Image' })\n if (!imageItem) continue\n const st =\n imageItem.internalProperties['storageTransactionId'] ??\n imageItem.allProperties['storageTransactionId']\n const stSnap = st?.getService().getSnapshot()\n const stCtx = stSnap && 'context' in stSnap ? stSnap.context : undefined\n const stValue = typeof (stCtx as { propertyValue?: unknown } | undefined)?.propertyValue === 'string'\n ? ((stCtx as { propertyValue?: string }).propertyValue ?? '')\n : ''\n const decoded = decodeDataUriImage(stValue)\n\n const more: PublishUpload[] = []\n if (decoded && st && st.localId && st.versionLocalId) {\n const contentHash = await getContentHash(decoded.bytes)\n const transaction = await prepareArweaveTransaction(\n decoded.bytes,\n contentHash,\n decoded.mimeType,\n options?.arweaveUploadTags,\n )\n more.push({\n itemPropertyName: st.propertyName,\n itemPropertyLocalId: st.localId,\n seedLocalId: imageItem.seedLocalId,\n versionLocalId: st.versionLocalId,\n transactionToSign: transaction,\n })\n }\n for (const u of more) {\n if (!seen.has(u.seedLocalId)) {\n uploads.push(u)\n seen.add(u.seedLocalId)\n }\n }\n }\n return uploads\n}\n\nexport type UploadProperty = {\n itemProperty: IItemProperty<any>\n childProperties: IItemProperty<any>[]\n}\ntype ChildUploadData = {\n propertyName: string\n localStoragePath: string\n}\n\n/**\n * True if publish would include at least one Arweave upload (local file / storage seed present).\n * Does not create Arweave transactions or hit the network — use for routing (e.g. skip EAS-only)\n * when {@link getPublishUploads} would fail early (e.g. gateway unreachable during tx creation).\n */\nasync function storageSeedHasUploadCandidates(\n itemStorageSeedProperties: IItemProperty<any>[],\n): Promise<boolean> {\n for (const itemProperty of itemStorageSeedProperties) {\n const snapshot = itemProperty.getService().getSnapshot()\n const context = 'context' in snapshot ? snapshot.context : null\n if (!context) {\n continue\n }\n const propertyValue = (context as any).propertyValue\n const refResolvedValue = (context as any).refResolvedValue\n if (!refResolvedValue) {\n continue\n }\n\n const { seedLocalId } = resolveSeedIdsFromRefString(\n normalizeRelationPropertyValue(propertyValue) ?? '',\n )\n if (!seedLocalId) {\n continue\n }\n\n const dataType =\n itemProperty.propertyDef?.refValueType ??\n itemProperty.propertyDef?.dataType ??\n 'Image'\n const baseDir = getStorageDirForDataType(dataType)\n const filePath = `${baseDir}/${refResolvedValue}`\n\n if (await BaseFileManager.pathExists(filePath)) {\n return true\n }\n }\n\n return false\n}\n\nasync function uploadPropertyWouldUpload(\n uploadProperty: UploadProperty,\n relatedItemProperty?: IItemProperty<any>,\n): Promise<boolean> {\n const childUploads: ChildUploadData[] = []\n\n for (const childProperty of uploadProperty.childProperties) {\n const filePath = childProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n continue\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n continue\n }\n\n childUploads.push({\n propertyName: childProperty.propertyName,\n localStoragePath: filePath,\n })\n }\n\n if (childUploads.length > 0) {\n return true\n }\n\n if (relatedItemProperty && relatedItemProperty.localStoragePath) {\n const filePath = relatedItemProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n return false\n }\n\n return await BaseFileManager.pathExists(filePath)\n }\n\n return false\n}\n\nexport async function itemHasPublishUploadCandidates(\n item: IItem<any>,\n relatedItemProperty?: IItemProperty<any>,\n): Promise<boolean> {\n const { itemUploadProperties, itemRelationProperties, itemImageProperties } =\n await getSegmentedItemProperties(item)\n\n for (const uploadProperty of itemUploadProperties) {\n if (await uploadPropertyWouldUpload(uploadProperty, relatedItemProperty)) {\n return true\n }\n }\n\n if (await storageSeedHasUploadCandidates(itemImageProperties)) {\n return true\n }\n\n for (const relationProperty of itemRelationProperties) {\n const snapshot = relationProperty.getService().getSnapshot()\n const context = 'context' in snapshot ? snapshot.context : null\n if (!context) {\n continue\n }\n const propertyValue = (context as any).propertyValue\n\n if (!propertyValue || relationProperty.uid) {\n continue\n }\n\n const { seedLocalId, seedUid } = resolveSeedIdsFromRefString(\n normalizeRelationPropertyValue(propertyValue) ?? '',\n )\n if (!seedLocalId && !seedUid) {\n throw new Error(\n `Invalid relation value for ${relationProperty.propertyName}: expected local seed id or 0x uid`,\n )\n }\n\n const relatedItem = await Item.find({\n seedLocalId,\n seedUid,\n })\n\n if (!relatedItem) {\n throw new Error(\n `No relatedItem found for ${relationProperty.propertyName}`,\n )\n }\n\n if (await itemHasPublishUploadCandidates(relatedItem, relationProperty)) {\n return true\n }\n }\n\n return false\n}\n\nconst processUploadProperty = async (\n uploadProperty: UploadProperty,\n uploads: PublishUpload[],\n relatedItemProperty?: IItemProperty<any>,\n options?: GetPublishUploadsOptions,\n): Promise<PublishUpload[]> => {\n const extra = options?.arweaveUploadTags\n const itemProperty = uploadProperty.itemProperty\n\n const childUploads: ChildUploadData[] = []\n\n for (const childProperty of uploadProperty.childProperties) {\n const filePath = childProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n continue\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n continue\n }\n\n childUploads.push({\n propertyName: childProperty.propertyName,\n localStoragePath: filePath,\n })\n }\n\n let fileContents\n let transaction: ArweaveTransaction\n\n if (!childUploads || childUploads.length === 0) {\n if (relatedItemProperty && relatedItemProperty.localStoragePath) {\n const filePath = relatedItemProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n return uploads\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n return uploads\n }\n\n try {\n const fileBuffer = await BaseFileManager.readFileAsBuffer(filePath)\n fileContents = await toUint8Array(fileBuffer)\n } catch (e) {\n const fs = await BaseFileManager.getFs()\n fileContents = await toUint8Array(fs.readFileSync(filePath))\n }\n }\n if (!fileContents) {\n return uploads\n }\n }\n\n if (childUploads.length > 0) {\n const separator = '===FILE_SEPARATOR==='\n // let compositeFileContents = `${itemProperty.propertyName}${separator}${mainFileContents}`\n let compositeFileContents = ''\n\n for (const childUpload of childUploads) {\n let childUploadContents\n\n const fs = await BaseFileManager.getFs()\n\n try {\n childUploadContents = await fs.promises.readFile(\n childUpload.localStoragePath,\n )\n } catch (e) {\n childUploadContents = fs.readFileSync(childUpload.localStoragePath)\n }\n\n compositeFileContents += `${separator}${childUpload.propertyName}${separator}${childUploadContents}`\n }\n\n if (typeof document !== 'undefined') {\n fileContents = new TextEncoder().encode(compositeFileContents)\n } else {\n fileContents = Buffer.from(compositeFileContents)\n }\n }\n\n if (!fileContents) {\n throw new Error(`No file contents found for ${itemProperty.propertyName}`)\n }\n\n const uint8Array = new Uint8Array(fileContents)\n\n const contentHash = await getContentHash(uint8Array)\n\n let contentType: string | undefined\n if (childUploads.length === 0 && relatedItemProperty?.localStoragePath) {\n contentType = getMimeTypeFromPath(relatedItemProperty.localStoragePath)\n } else if (childUploads.length > 0) {\n contentType = 'application/octet-stream'\n }\n\n transaction = await prepareArweaveTransaction(\n uint8Array,\n contentHash,\n contentType,\n extra,\n )\n\n let itemPropertyLocalId = relatedItemProperty\n ? relatedItemProperty.localId\n : itemProperty.localId\n let itemPropertyName = relatedItemProperty\n ? relatedItemProperty.propertyName\n : itemProperty.propertyName\n\n uploads.push({\n itemPropertyName,\n itemPropertyLocalId,\n seedLocalId: itemProperty.seedLocalId!,\n versionLocalId: itemProperty.versionLocalId!,\n transactionToSign: transaction,\n })\n\n return uploads\n}\n\nexport const getPublishUploads = async (\n item: IItem<any>,\n uploads: PublishUpload[] = [],\n relatedItemProperty?: IItemProperty<any>,\n options?: GetPublishUploadsOptions,\n) => {\n const { itemUploadProperties, itemRelationProperties, itemImageProperties } =\n await getSegmentedItemProperties(item)\n\n if (!relatedItemProperty && options?.onlyHtmlStorageSeedLocalIds?.length) {\n const storageSeedUploads = await getStorageSeedUploads(itemImageProperties, options)\n uploads.push(...storageSeedUploads)\n return uploads\n }\n\n for (const uploadProperty of itemUploadProperties) {\n uploads = await processUploadProperty(\n uploadProperty,\n uploads,\n relatedItemProperty,\n options,\n )\n }\n\n const storageSeedUploads = await getStorageSeedUploads(itemImageProperties, options)\n uploads.push(...storageSeedUploads)\n\n if (!relatedItemProperty && !options?.onlyHtmlStorageSeedLocalIds?.length) {\n uploads = await appendCoPublishedImageUploads(item, uploads, options)\n }\n\n if (options?.skipRelationRecursion) {\n return uploads\n }\n\n for (const relationProperty of itemRelationProperties) {\n const snapshot = relationProperty.getService().getSnapshot()\n const context = 'context' in snapshot ? snapshot.context : null\n if (!context) {\n continue\n }\n const propertyValue = (context as any).propertyValue\n\n if (!propertyValue || relationProperty.uid) {\n continue\n }\n\n const { seedLocalId, seedUid } = resolveSeedIdsFromRefString(\n normalizeRelationPropertyValue(propertyValue) ?? '',\n )\n if (!seedLocalId && !seedUid) {\n throw new Error(\n `Invalid relation value for ${relationProperty.propertyName}: expected local seed id or 0x uid`,\n )\n }\n\n const relatedItem = await Item.find({\n seedLocalId,\n seedUid,\n })\n\n if (!relatedItem) {\n throw new Error(\n `No relatedItem found for ${relationProperty.propertyName}`,\n )\n }\n\n uploads = await getPublishUploads(relatedItem, uploads, relationProperty, options)\n }\n\n return uploads\n}\n"],"names":["BaseArweaveClient","BaseFileManager","resolveSeedIdsFromRefString","normalizeRelationPropertyValue","ModelPropertyDataTypes","getContentHash","BaseDb","htmlEmbeddedImageCoPublish","eq","Item","getSegmentedItemProperties"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAM,MAAM,GAAG,KAAK,CAAC,gCAAgC,CAAC;AAiBtD,MAAM,iBAAiB,GAA2B;AAChD,IAAA,GAAG,EAAE,WAAW;AAChB,IAAA,GAAG,EAAE,YAAY;AACjB,IAAA,IAAI,EAAE,YAAY;AAClB,IAAA,GAAG,EAAE,WAAW;AAChB,IAAA,IAAI,EAAE,YAAY;AAClB,IAAA,GAAG,EAAE,eAAe;AACpB,IAAA,IAAI,EAAE,WAAW;AACjB,IAAA,GAAG,EAAE,WAAW;AAChB,IAAA,IAAI,EAAE,kBAAkB;AACxB,IAAA,GAAG,EAAE,YAAY;CAClB;AAED,MAAM,mBAAmB,GAAG,CAAC,cAAsB,KAAwB;AACzE,IAAA,MAAM,GAAG,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE;AAC1D,IAAA,OAAO,GAAG,GAAG,iBAAiB,CAAC,GAAG,CAAC,GAAG,SAAS;AACjD,CAAC;AAED,MAAM,YAAY,GAAG,OAAO,IAAmB,KAAyB;IACtE,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,YAAY,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ishUploads.ts"],"sourcesContent":["import { BaseFileManager } from '@/helpers'\nimport {\n normalizeRelationPropertyValue,\n resolveSeedIdsFromRefString,\n} from '@/helpers/relationSeedRef'\nimport { BaseArweaveClient } from '@/helpers/ArweaveClient/BaseArweaveClient'\nimport { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'\nimport debug from 'debug'\nimport { IItem, IItemProperty } from '@/interfaces'\nimport { getContentHash } from '@/helpers/crypto'\nimport { Item } from '@/Item/Item'\nimport type { ArweaveTransaction, TransactionTag } from '@/types/arweave'\nimport { PublishUpload } from '@/types/publish'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { htmlEmbeddedImageCoPublish } from '@/seedSchema/HtmlEmbeddedImageCoPublishSchema'\nimport { eq } from 'drizzle-orm'\nimport { ModelPropertyDataTypes } from '@/helpers/property'\n\nconst logger = debug('seedSdk:item:getPublishUploads')\n\n/** Optional tags merged into each Arweave tx after Content-SHA-256 / Content-Type. */\nexport type GetPublishUploadsOptions = {\n arweaveUploadTags?: TransactionTag[]\n /**\n * Html storage seed local ids to skip (phase 1 of two-phase embedded-image publish).\n */\n deferHtmlStorageSeedLocalIds?: string[]\n /**\n * When set, only Html storage seeds in this list are included (phase 2). Non-Html storage uploads are omitted.\n */\n onlyHtmlStorageSeedLocalIds?: string[]\n /** When true, do not recurse into relation properties (phase 2 must not re-upload related items). */\n skipRelationRecursion?: boolean\n}\n\nconst EXTENSION_TO_MIME: Record<string, string> = {\n png: 'image/png',\n jpg: 'image/jpeg',\n jpeg: 'image/jpeg',\n gif: 'image/gif',\n webp: 'image/webp',\n svg: 'image/svg+xml',\n html: 'text/html',\n htm: 'text/html',\n json: 'application/json',\n txt: 'text/plain',\n}\n\nconst getMimeTypeFromPath = (filePathOrName: string): string | undefined => {\n const ext = filePathOrName.split('.').pop()?.toLowerCase()\n return ext ? EXTENSION_TO_MIME[ext] : undefined\n}\n\nconst toUint8Array = async (data: Buffer | Blob): Promise<Uint8Array> => {\n if (typeof Blob !== 'undefined' && data instanceof Blob) {\n return new Uint8Array(await data.arrayBuffer())\n }\n return new Uint8Array(data as Buffer)\n}\n\nexport const prepareArweaveTransaction = async (\n data: string | Uint8Array,\n contentHash: string | undefined,\n contentType?: string,\n additionalTags?: TransactionTag[],\n): Promise<ArweaveTransaction> => {\n const tags: TransactionTag[] = []\n if (contentHash) {\n tags.push({ name: 'Content-SHA-256', value: contentHash })\n logger('contentHash', contentHash)\n logger('adding content hash tag')\n }\n if (contentType) {\n tags.push({ name: 'Content-Type', value: contentType })\n }\n if (additionalTags?.length) {\n tags.push(...additionalTags)\n }\n\n const tx = await BaseArweaveClient.createTransaction(data, {\n tags: tags.length ? tags : undefined,\n })\n\n return tx\n}\n\n\nconst getStorageDirForDataType = (dataType: string): string => {\n switch (dataType) {\n case 'Image':\n return BaseFileManager.getFilesPath('images')\n case 'File':\n return BaseFileManager.getFilesPath('files')\n case 'Html':\n return BaseFileManager.getFilesPath('html')\n case 'Json':\n return BaseFileManager.getFilesPath('json')\n default:\n return BaseFileManager.getFilesPath('images')\n }\n}\n\nconst DATA_URI_IMAGE = /^data:(image\\/[a-zA-Z0-9.+-]+);base64,([\\s\\S]*)$/i\n\nfunction decodeDataUriImage(dataUri: string): { mimeType: string; bytes: Uint8Array } | null {\n const m = DATA_URI_IMAGE.exec((dataUri ?? '').trim())\n if (!m) return null\n try {\n const mimeType = m[1]!.toLowerCase().trim()\n const base64 = m[2]!.replace(/\\s/g, '')\n const binary = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0))\n return { mimeType, bytes: binary }\n } catch {\n return null\n }\n}\n\nconst getStorageSeedUploads = async (\n itemStorageSeedProperties: IItemProperty<any>[],\n options?: GetPublishUploadsOptions,\n) => {\n const uploads: PublishUpload[] = []\n const extra = options?.arweaveUploadTags\n\n for (const itemProperty of itemStorageSeedProperties) {\n const snapshot = itemProperty.getService().getSnapshot()\n const context = 'context' in snapshot ? snapshot.context : null\n if (!context) {\n continue\n }\n const propertyValue = (context as any).propertyValue\n const refResolvedValue = (context as any).refResolvedValue\n if (!refResolvedValue) {\n continue\n }\n\n // propertyValue is the storage seed's seedLocalId; use it for the upload so processRelationOrImageProperty can match\n const { seedLocalId } = resolveSeedIdsFromRefString(\n normalizeRelationPropertyValue(propertyValue) ?? '',\n )\n if (!seedLocalId) {\n continue\n }\n\n const dataType =\n itemProperty.propertyDef?.refValueType ??\n itemProperty.propertyDef?.dataType ??\n 'Image'\n\n if (dataType === ModelPropertyDataTypes.Html) {\n if (options?.deferHtmlStorageSeedLocalIds?.includes(seedLocalId)) {\n continue\n }\n if (\n options?.onlyHtmlStorageSeedLocalIds?.length &&\n !options.onlyHtmlStorageSeedLocalIds.includes(seedLocalId)\n ) {\n continue\n }\n } else if (options?.onlyHtmlStorageSeedLocalIds?.length) {\n continue\n }\n\n const baseDir = getStorageDirForDataType(dataType)\n const filePath = `${baseDir}/${refResolvedValue}`\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n continue\n }\n\n const fileBuffer = await BaseFileManager.readFileAsBuffer(filePath)\n const fileContents = await toUint8Array(fileBuffer)\n\n const contentHash = await getContentHash(fileContents)\n const contentType = getMimeTypeFromPath(refResolvedValue)\n\n const transaction = await prepareArweaveTransaction(\n fileContents,\n contentHash,\n contentType,\n extra,\n )\n\n uploads.push({\n itemPropertyName: itemProperty.propertyName,\n itemPropertyLocalId: itemProperty.localId,\n seedLocalId,\n versionLocalId: itemProperty.versionLocalId!,\n transactionToSign: transaction,\n })\n }\n\n return uploads\n}\n\nasync function appendCoPublishedImageUploads(\n item: IItem<any>,\n uploads: PublishUpload[],\n options?: GetPublishUploadsOptions,\n): Promise<PublishUpload[]> {\n const appDb = BaseDb.getAppDb()\n if (!appDb || options?.onlyHtmlStorageSeedLocalIds?.length) return uploads\n\n const rows = await appDb\n .select()\n .from(htmlEmbeddedImageCoPublish)\n .where(eq(htmlEmbeddedImageCoPublish.parentSeedLocalId, item.seedLocalId))\n\n const seen = new Set(uploads.map((u) => u.seedLocalId))\n\n for (const row of rows) {\n if (seen.has(row.imageSeedLocalId)) continue\n const imageItem = await Item.find({ seedLocalId: row.imageSeedLocalId, modelName: 'Image' })\n if (!imageItem) continue\n const st =\n imageItem.internalProperties['storageTransactionId'] ??\n imageItem.allProperties['storageTransactionId']\n const stSnap = st?.getService().getSnapshot()\n const stCtx = stSnap && 'context' in stSnap ? stSnap.context : undefined\n const stValue = typeof (stCtx as { propertyValue?: unknown } | undefined)?.propertyValue === 'string'\n ? ((stCtx as { propertyValue?: string }).propertyValue ?? '')\n : ''\n const decoded = decodeDataUriImage(stValue)\n\n const more: PublishUpload[] = []\n if (decoded && st && st.localId && st.versionLocalId) {\n const contentHash = await getContentHash(decoded.bytes)\n const transaction = await prepareArweaveTransaction(\n decoded.bytes,\n contentHash,\n decoded.mimeType,\n options?.arweaveUploadTags,\n )\n more.push({\n itemPropertyName: st.propertyName,\n itemPropertyLocalId: st.localId,\n seedLocalId: imageItem.seedLocalId,\n versionLocalId: st.versionLocalId,\n transactionToSign: transaction,\n })\n }\n for (const u of more) {\n if (!seen.has(u.seedLocalId)) {\n uploads.push(u)\n seen.add(u.seedLocalId)\n }\n }\n }\n return uploads\n}\n\nexport type UploadProperty = {\n itemProperty: IItemProperty<any>\n childProperties: IItemProperty<any>[]\n}\ntype ChildUploadData = {\n propertyName: string\n localStoragePath: string\n}\n\n/**\n * True if publish would include at least one Arweave upload (local file / storage seed present).\n * Does not create Arweave transactions or hit the network — use for routing (e.g. skip EAS-only)\n * when {@link getPublishUploads} would fail early (e.g. gateway unreachable during tx creation).\n */\nasync function storageSeedHasUploadCandidates(\n itemStorageSeedProperties: IItemProperty<any>[],\n): Promise<boolean> {\n for (const itemProperty of itemStorageSeedProperties) {\n const snapshot = itemProperty.getService().getSnapshot()\n const context = 'context' in snapshot ? snapshot.context : null\n if (!context) {\n continue\n }\n const propertyValue = (context as any).propertyValue\n const refResolvedValue = (context as any).refResolvedValue\n if (!refResolvedValue) {\n continue\n }\n\n const { seedLocalId } = resolveSeedIdsFromRefString(\n normalizeRelationPropertyValue(propertyValue) ?? '',\n )\n if (!seedLocalId) {\n continue\n }\n\n const dataType =\n itemProperty.propertyDef?.refValueType ??\n itemProperty.propertyDef?.dataType ??\n 'Image'\n const baseDir = getStorageDirForDataType(dataType)\n const filePath = `${baseDir}/${refResolvedValue}`\n\n if (await BaseFileManager.pathExists(filePath)) {\n return true\n }\n }\n\n return false\n}\n\nasync function uploadPropertyWouldUpload(\n uploadProperty: UploadProperty,\n relatedItemProperty?: IItemProperty<any>,\n): Promise<boolean> {\n const childUploads: ChildUploadData[] = []\n\n for (const childProperty of uploadProperty.childProperties) {\n const filePath = childProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n continue\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n continue\n }\n\n childUploads.push({\n propertyName: childProperty.propertyName,\n localStoragePath: filePath,\n })\n }\n\n if (childUploads.length > 0) {\n return true\n }\n\n if (relatedItemProperty && relatedItemProperty.localStoragePath) {\n const filePath = relatedItemProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n return false\n }\n\n return await BaseFileManager.pathExists(filePath)\n }\n\n return false\n}\n\nexport async function itemHasPublishUploadCandidates(\n item: IItem<any>,\n relatedItemProperty?: IItemProperty<any>,\n): Promise<boolean> {\n const { itemUploadProperties, itemRelationProperties, itemImageProperties } =\n await getSegmentedItemProperties(item)\n\n for (const uploadProperty of itemUploadProperties) {\n if (await uploadPropertyWouldUpload(uploadProperty, relatedItemProperty)) {\n return true\n }\n }\n\n if (await storageSeedHasUploadCandidates(itemImageProperties)) {\n return true\n }\n\n for (const relationProperty of itemRelationProperties) {\n const snapshot = relationProperty.getService().getSnapshot()\n const context = 'context' in snapshot ? snapshot.context : null\n if (!context) {\n continue\n }\n const propertyValue = (context as any).propertyValue\n\n if (!propertyValue || relationProperty.uid) {\n continue\n }\n\n const { seedLocalId, seedUid } = resolveSeedIdsFromRefString(\n normalizeRelationPropertyValue(propertyValue) ?? '',\n )\n if (!seedLocalId && !seedUid) {\n throw new Error(\n `Invalid relation value for ${relationProperty.propertyName}: expected local seed id or 0x uid`,\n )\n }\n\n const relatedItem = await Item.find({\n seedLocalId,\n seedUid,\n })\n\n if (!relatedItem) {\n throw new Error(\n `No relatedItem found for ${relationProperty.propertyName}`,\n )\n }\n\n if (await itemHasPublishUploadCandidates(relatedItem, relationProperty)) {\n return true\n }\n }\n\n return false\n}\n\nconst processUploadProperty = async (\n uploadProperty: UploadProperty,\n uploads: PublishUpload[],\n relatedItemProperty?: IItemProperty<any>,\n options?: GetPublishUploadsOptions,\n): Promise<PublishUpload[]> => {\n const extra = options?.arweaveUploadTags\n const itemProperty = uploadProperty.itemProperty\n\n const childUploads: ChildUploadData[] = []\n\n for (const childProperty of uploadProperty.childProperties) {\n const filePath = childProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n continue\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n continue\n }\n\n childUploads.push({\n propertyName: childProperty.propertyName,\n localStoragePath: filePath,\n })\n }\n\n let fileContents\n let transaction: ArweaveTransaction\n\n if (!childUploads || childUploads.length === 0) {\n if (relatedItemProperty && relatedItemProperty.localStoragePath) {\n const filePath = relatedItemProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n return uploads\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n return uploads\n }\n\n try {\n const fileBuffer = await BaseFileManager.readFileAsBuffer(filePath)\n fileContents = await toUint8Array(fileBuffer)\n } catch (e) {\n const fs = await BaseFileManager.getFs()\n fileContents = await toUint8Array(fs.readFileSync(filePath))\n }\n }\n if (!fileContents) {\n return uploads\n }\n }\n\n if (childUploads.length > 0) {\n const separator = '===FILE_SEPARATOR==='\n // let compositeFileContents = `${itemProperty.propertyName}${separator}${mainFileContents}`\n let compositeFileContents = ''\n\n for (const childUpload of childUploads) {\n let childUploadContents\n\n const fs = await BaseFileManager.getFs()\n\n try {\n childUploadContents = await fs.promises.readFile(\n childUpload.localStoragePath,\n )\n } catch (e) {\n childUploadContents = fs.readFileSync(childUpload.localStoragePath)\n }\n\n compositeFileContents += `${separator}${childUpload.propertyName}${separator}${childUploadContents}`\n }\n\n if (typeof document !== 'undefined') {\n fileContents = new TextEncoder().encode(compositeFileContents)\n } else {\n fileContents = Buffer.from(compositeFileContents)\n }\n }\n\n if (!fileContents) {\n throw new Error(`No file contents found for ${itemProperty.propertyName}`)\n }\n\n const uint8Array = new Uint8Array(fileContents)\n\n const contentHash = await getContentHash(uint8Array)\n\n let contentType: string | undefined\n if (childUploads.length === 0 && relatedItemProperty?.localStoragePath) {\n contentType = getMimeTypeFromPath(relatedItemProperty.localStoragePath)\n } else if (childUploads.length > 0) {\n contentType = 'application/octet-stream'\n }\n\n transaction = await prepareArweaveTransaction(\n uint8Array,\n contentHash,\n contentType,\n extra,\n )\n\n let itemPropertyLocalId = relatedItemProperty\n ? relatedItemProperty.localId\n : itemProperty.localId\n let itemPropertyName = relatedItemProperty\n ? relatedItemProperty.propertyName\n : itemProperty.propertyName\n\n uploads.push({\n itemPropertyName,\n itemPropertyLocalId,\n seedLocalId: itemProperty.seedLocalId!,\n versionLocalId: itemProperty.versionLocalId!,\n transactionToSign: transaction,\n })\n\n return uploads\n}\n\nexport const getPublishUploads = async (\n item: IItem<any>,\n uploads: PublishUpload[] = [],\n relatedItemProperty?: IItemProperty<any>,\n options?: GetPublishUploadsOptions,\n) => {\n const { itemUploadProperties, itemRelationProperties, itemImageProperties } =\n await getSegmentedItemProperties(item)\n\n if (!relatedItemProperty && options?.onlyHtmlStorageSeedLocalIds?.length) {\n const storageSeedUploads = await getStorageSeedUploads(itemImageProperties, options)\n uploads.push(...storageSeedUploads)\n return uploads\n }\n\n for (const uploadProperty of itemUploadProperties) {\n uploads = await processUploadProperty(\n uploadProperty,\n uploads,\n relatedItemProperty,\n options,\n )\n }\n\n const storageSeedUploads = await getStorageSeedUploads(itemImageProperties, options)\n uploads.push(...storageSeedUploads)\n\n if (!relatedItemProperty && !options?.onlyHtmlStorageSeedLocalIds?.length) {\n uploads = await appendCoPublishedImageUploads(item, uploads, options)\n }\n\n if (options?.skipRelationRecursion) {\n return uploads\n }\n\n for (const relationProperty of itemRelationProperties) {\n const snapshot = relationProperty.getService().getSnapshot()\n const context = 'context' in snapshot ? snapshot.context : null\n if (!context) {\n continue\n }\n const propertyValue = (context as any).propertyValue\n\n if (!propertyValue || relationProperty.uid) {\n continue\n }\n\n const { seedLocalId, seedUid } = resolveSeedIdsFromRefString(\n normalizeRelationPropertyValue(propertyValue) ?? '',\n )\n if (!seedLocalId && !seedUid) {\n throw new Error(\n `Invalid relation value for ${relationProperty.propertyName}: expected local seed id or 0x uid`,\n )\n }\n\n const relatedItem = await Item.find({\n seedLocalId,\n seedUid,\n })\n\n if (!relatedItem) {\n throw new Error(\n `No relatedItem found for ${relationProperty.propertyName}`,\n )\n }\n\n uploads = await getPublishUploads(relatedItem, uploads, relationProperty, options)\n }\n\n return uploads\n}\n"],"names":["BaseArweaveClient","BaseFileManager","resolveSeedIdsFromRefString","normalizeRelationPropertyValue","ModelPropertyDataTypes","getContentHash","BaseDb","htmlEmbeddedImageCoPublish","eq","Item","getSegmentedItemProperties"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAM,MAAM,GAAG,KAAK,CAAC,gCAAgC,CAAC;AAiBtD,MAAM,iBAAiB,GAA2B;AAChD,IAAA,GAAG,EAAE,WAAW;AAChB,IAAA,GAAG,EAAE,YAAY;AACjB,IAAA,IAAI,EAAE,YAAY;AAClB,IAAA,GAAG,EAAE,WAAW;AAChB,IAAA,IAAI,EAAE,YAAY;AAClB,IAAA,GAAG,EAAE,eAAe;AACpB,IAAA,IAAI,EAAE,WAAW;AACjB,IAAA,GAAG,EAAE,WAAW;AAChB,IAAA,IAAI,EAAE,kBAAkB;AACxB,IAAA,GAAG,EAAE,YAAY;CAClB;AAED,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AEF,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,KAAK,CACb,CAAA,yBAAA,EAA4B,gBAAgB,CAAC,YAAY,CAAA,CAAE,CAC5D;QACH;AAEA,QAAA,OAAO,GAAG,MAAM,iBAAiB,CAAC,WAAW,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,CAAC;IACpF;AAEA,IAAA,OAAO,OAAO;AAChB;;;;;;"}
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  require('reflect-metadata');
4
- var main_cjs = require('./index-CZ7yR-bZ.js');
5
- var property = require('./property-sm3N2yBU.js');
4
+ var main_cjs = require('./index-ByozbTn_.js');
5
+ var property = require('./property-CeR45LMx.js');
6
6
  var drizzleOrm = require('drizzle-orm');
7
7
  var lodashEs = require('lodash-es');
8
8
 
@@ -144,4 +144,4 @@ const getSegmentedItemProperties = async (item) => {
144
144
  };
145
145
 
146
146
  exports.getSegmentedItemProperties = getSegmentedItemProperties;
147
- //# sourceMappingURL=getSegmentedItemProperties-CkhTBPSP.js.map
147
+ //# sourceMappingURL=getSegmentedItemProperties-BgS_FhAx.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getSegmentedItemProperties-CkhTBPSP.js","sources":["../../../src/helpers/getSegmentedItemProperties.ts"],"sourcesContent":["import { UploadProperty } from '@/db/read/getPublishUploads'\nimport { IItem } from '@/interfaces'\nimport { ModelPropertyDataTypes } from '@/Schema'\nimport { getPropertySchema, TProperty } from '@/helpers/property'\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'\nasync function resolvePropertyDef(\n modelName: string,\n propertyName: string,\n): Promise<{ dataType?: string; ref?: string; refValueType?: string; storageType?: string; localStorageDir?: string; filenameSuffix?: string; required?: boolean } | undefined> {\n let schema = await getPropertySchema(modelName, propertyName)\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 modelRecords = await db\n .select({ id: models.id })\n .from(models)\n .where(eq(models.name, normalizedModelName))\n .limit(1)\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\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 const resolved = await resolvePropertyDef(item.modelName, itemProperty.propertyName)\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 propertyDef.dataType === ModelPropertyDataTypes.Image ||\n propertyDef.dataType === ModelPropertyDataTypes.File ||\n propertyDef.dataType === ModelPropertyDataTypes.Html ||\n propertyDef.dataType === ModelPropertyDataTypes.Json ||\n (propertyDef.dataType === ModelPropertyDataTypes.Relation &&\n (propertyDef.refValueType === ModelPropertyDataTypes.Image ||\n propertyDef.refValueType === ModelPropertyDataTypes.File ||\n propertyDef.refValueType === ModelPropertyDataTypes.Html ||\n propertyDef.refValueType === ModelPropertyDataTypes.Json))\n\n if (isStorageSeedType) {\n itemImageProperties.push(itemProperty)\n if (propertyDef.dataType === ModelPropertyDataTypes.Relation) {\n itemRelationProperties.push(itemProperty)\n }\n continue\n }\n\n if (propertyDef.dataType === ModelPropertyDataTypes.Relation) {\n itemRelationProperties.push(itemProperty)\n continue\n }\n\n if (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"],"names":["getPropertySchema","BaseDb","upperFirst","camelCase","models","eq","properties","and","ModelPropertyDataTypes"],"mappings":";;;;;;;;AASA,eAAe,kBAAkB,CAC/B,SAAiB,EACjB,YAAoB,EAAA;IAEpB,IAAI,MAAM,GAAG,MAAMA,0BAAiB,CAAC,SAAS,EAAE,YAAY,CAAC;AAC7D,IAAA,IAAI,MAAM;AAAE,QAAA,OAAO,MAAM;AACzB,IAAA,MAAM,EAAE,GAAGC,eAAM,CAAC,QAAQ,EAAE;AAC5B,IAAA,IAAI,CAAC,EAAE;AAAE,QAAA,OAAO,SAAS;AACzB,IAAA,IAAI;QACF,MAAM,mBAAmB,GAAGC,mBAAU,CAACC,kBAAS,CAAC,SAAS,CAAC,CAAC;QAC5D,MAAM,YAAY,GAAG,MAAM;aACxB,MAAM,CAAC,EAAE,EAAE,EAAEC,eAAM,CAAC,EAAE,EAAE;aACxB,IAAI,CAACA,eAAM;aACX,KAAK,CAACC,aAAE,CAACD,eAAM,CAAC,IAAI,EAAE,mBAAmB,CAAC;aAC1C,KAAK,CAAC,CAAC,CAAC;AACX,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,CAACE,mBAAU;aACf,KAAK,CACJC,cAAG,CACDF,aAAE,CAACC,mBAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAC1CD,aAAE,CAACC,mBAAU,CAAC,IAAI,EAAE,YAAY,CAAC,CAClC;aAEF,KAAK,CAAC,CAAC,CAAC;AACX,QAAA,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC;AAAE,YAAA,OAAO,SAAS;AAClD,QAAA,MAAM,UAAU,GAAG,eAAe,CAAC,CA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oB;QACpB,mBAAmB;KACpB;AACH;;;;"}
1
+ {"version":3,"file":"getSegmentedItemProperties-BgS_FhAx.js","sources":["../../../src/helpers/getSegmentedItemProperties.ts"],"sourcesContent":["import { UploadProperty } from '@/db/read/getPublishUploads'\nimport { IItem } from '@/interfaces'\nimport { ModelPropertyDataTypes } from '@/Schema'\nimport { getPropertySchema, TProperty } from '@/helpers/property'\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'\nasync function resolvePropertyDef(\n modelName: string,\n propertyName: string,\n): Promise<{ dataType?: string; ref?: string; refValueType?: string; storageType?: string; localStorageDir?: string; filenameSuffix?: string; required?: boolean } | undefined> {\n let schema = await getPropertySchema(modelName, propertyName)\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 modelRecords = await db\n .select({ id: models.id })\n .from(models)\n .where(eq(models.name, normalizedModelName))\n .limit(1)\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\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 const resolved = await resolvePropertyDef(item.modelName, itemProperty.propertyName)\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 propertyDef.dataType === ModelPropertyDataTypes.Image ||\n propertyDef.dataType === ModelPropertyDataTypes.File ||\n propertyDef.dataType === ModelPropertyDataTypes.Html ||\n propertyDef.dataType === ModelPropertyDataTypes.Json ||\n (propertyDef.dataType === ModelPropertyDataTypes.Relation &&\n (propertyDef.refValueType === ModelPropertyDataTypes.Image ||\n propertyDef.refValueType === ModelPropertyDataTypes.File ||\n propertyDef.refValueType === ModelPropertyDataTypes.Html ||\n propertyDef.refValueType === ModelPropertyDataTypes.Json))\n\n if (isStorageSeedType) {\n itemImageProperties.push(itemProperty)\n if (propertyDef.dataType === ModelPropertyDataTypes.Relation) {\n itemRelationProperties.push(itemProperty)\n }\n continue\n }\n\n if (propertyDef.dataType === ModelPropertyDataTypes.Relation) {\n itemRelationProperties.push(itemProperty)\n continue\n }\n\n if (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"],"names":["getPropertySchema","BaseDb","upperFirst","camelCase","models","eq","properties","and","ModelPropertyDataTypes"],"mappings":";;;;;;;;AASA,eAAe,kBAAkB,CAC/B,SAAiB,EACjB,YAAoB,EAAA;IAEpB,IAAI,MAAM,GAAG,MAAMA,0BAAiB,CAAC,SAAS,EAAE,YAAY,CAAC;AAC7D,IAAA,IAAI,MAAM;AAAE,QAAA,OAAO,MAAM;AACzB,IAAA,MAAM,EAAE,GAAGC,eAAM,CAAC,QAAQ,EAAE;AAC5B,IAAA,IAAI,CAAC,EAAE;AAAE,QAAA,OAAO,SAAS;AACzB,IAAA,IAAI;QACF,MAAM,mBAAmB,GAAGC,mBAAU,CAACC,kBAAS,CAAC,SAAS,CAAC,CAAC;QAC5D,MAAM,YAAY,GAAG,MAAM;aACxB,MAAM,CAAC,EAAE,EAAE,EAAEC,eAAM,CAAC,EAAE,EAAE;aACxB,IAAI,CAACA,eAAM;aACX,KAAK,CAACC,aAAE,CAACD,eAAM,CAAC,IAAI,EAAE,mB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C,IAAI,CAAC,YAAY,CAAC;YACxC;YACA;QACF;QAEA,IAAI,aAAa,EAAE;AACjB,YAAA,qBAAqB,CAAC,IAAI,CAAC,YAAY,CAAC;YACxC;QACF;QAEA,IAAI,oBAAoB,EAAE;YACxB,8BAA8B,GAAG,EAAE,YAAY,EAAE,eAAe,EAAE,EAAE,EAAE;YACtE;QACF;AAEA,QAAA,mBAAmB,CAAC,IAAI,CAAC,YAAY,CAAC;IACxC;IAEA,IAAI,8BAA8B,IAAI,qBAAqB,CAAC,MAAM,GAAG,CAAC,EAAE;AACtE,QAAA,8BAA8B,CAAC,eAAe,GAAG,qBAAqB;IACxE;IAEA,IAAI,8BAA8B,EAAE;AAClC,QAAA,oBAAoB,CAAC,IAAI,CAAC,8BAA8B,CAAC;IAC3D;IAEA,OAAO;QACL,mBAAmB;QACnB,sBAAsB;QACtB,kBAAkB;QAClB,oBAAoB;QACpB,mBAAmB;KACpB;AACH;;;;"}
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  require('reflect-metadata');
4
- var main_cjs = require('./index-CZ7yR-bZ.js');
5
- var property = require('./property-sm3N2yBU.js');
4
+ var main_cjs = require('./index-ByozbTn_.js');
5
+ var property = require('./property-CeR45LMx.js');
6
6
  require('immer');
7
7
  require('xstate');
8
8
  require('drizzle-orm/sqlite-core');
@@ -64,4 +64,4 @@ exports.TValidationRules = main_cjs.TValidationRules;
64
64
  exports.Text = main_cjs.Text;
65
65
  exports.normalizeDataType = main_cjs.normalizeDataType;
66
66
  exports.getPropertySchema = property.getPropertySchema;
67
- //# sourceMappingURL=index-BLco2YiE.js.map
67
+ //# sourceMappingURL=index-BnAqr2le.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-BnAqr2le.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1729,6 +1729,8 @@ const getStorageTransactionIdForSeedUid = async (seedUid) => {
1729
1729
  return results[0].storageTransactionId;
1730
1730
  };
1731
1731
 
1732
+ // #region agent log
1733
+ fetch('http://127.0.0.1:7754/ingest/2810478a-7cf0-49a8-bc23-760b81417972', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Debug-Session-Id': '30ce80' }, body: JSON.stringify({ sessionId: '30ce80', runId: 'pre-fix', hypothesisId: 'B', location: 'mediaRef.ts:3', message: 'mediaRef debug import', data: { debugType: typeof debug, debugName: debug?.name ?? null }, timestamp: Date.now() }) }).catch(() => { });
1732
1734
  const logger$A = debug('seedSdk:helpers:mediaRef');
1733
1735
  /** Typical Arweave transaction id: 43 URL-safe base64 characters. */
1734
1736
  const ARWEAVE_TX_ID = /^[a-zA-Z0-9_-]{43}$/;
@@ -2248,7 +2250,7 @@ const createPropertyInstances = async (propertyFileIds) => {
2248
2250
  return;
2249
2251
  }
2250
2252
  try {
2251
- const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BEpPD4wH.js'); });
2253
+ const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BQYU5hPQ.js'); });
2252
2254
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
2253
2255
  if (!ModelProperty) {
2254
2256
  logger$y('createPropertyInstances: ModelProperty not available from dynamic import');
@@ -2432,7 +2434,7 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
2432
2434
  // Step 2: Fallback to Schema context (only if database doesn't have the model)
2433
2435
  // This handles the case where model exists in schema file but not yet in database
2434
2436
  try {
2435
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DgvWd1wc.js'); });
2437
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-BcRHcQ0W.js'); });
2436
2438
  const { Schema } = schemaMod;
2437
2439
  const schema = Schema.create(schemaName, { waitForReady: false });
2438
2440
  const schemaSnapshot = schema.getService().getSnapshot();
@@ -2676,7 +2678,7 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
2676
2678
  }
2677
2679
  // Mark schema as draft when a new model is created so saveNewVersion() can persist it
2678
2680
  try {
2679
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DgvWd1wc.js'); });
2681
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-BcRHcQ0W.js'); });
2680
2682
  const { Schema } = schemaMod;
2681
2683
  const schema = Schema.create(schemaName, { waitForReady: false });
2682
2684
  schema.getService().send({ type: 'markAsDraft', propertyKey: 'schema:models' });
@@ -2720,10 +2722,10 @@ const validateModel = xstate.fromCallback(({ sendBack, input: { context } }) =>
2720
2722
  const _validateModel = async () => {
2721
2723
  try {
2722
2724
  // Use dynamic imports to break circular dependencies
2723
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DazyAm6l.js'); });
2725
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-CQNDgyZl.js'); });
2724
2726
  const { SchemaValidationService } = validationServiceMod;
2725
2727
  const validationService = new SchemaValidationService();
2726
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DgvWd1wc.js'); });
2728
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-BcRHcQ0W.js'); });
2727
2729
  const { Schema } = schemaMod;
2728
2730
  // Validate model structure
2729
2731
  const structureResult = validationService.validateModelStructure(context);
@@ -2833,7 +2835,7 @@ const createModelProperties = xstate.fromCallback(({ sendBack, input }) => {
2833
2835
  return;
2834
2836
  }
2835
2837
  logger$w(`Creating ${Object.keys(propertyDefinitions).length} properties for model "${modelName}" (id: ${_dbId})`);
2836
- const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BEpPD4wH.js'); });
2838
+ const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BQYU5hPQ.js'); });
2837
2839
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
2838
2840
  if (!ModelProperty) {
2839
2841
  logger$w('ModelProperty not available from dynamic import');
@@ -2937,7 +2939,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
2937
2939
  const structureMsg = `[validateEntity] Validating model structure`;
2938
2940
  logger$v(structureMsg);
2939
2941
  // Use existing Model validation
2940
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DazyAm6l.js'); });
2942
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-CQNDgyZl.js'); });
2941
2943
  const { SchemaValidationService } = validationServiceMod;
2942
2944
  const validationService = new SchemaValidationService();
2943
2945
  // Validate model structure
@@ -2955,7 +2957,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
2955
2957
  if (entityInput.entityData.schemaName) {
2956
2958
  try {
2957
2959
  logger$v(`[validateEntity] Validating model against schema "${entityInput.entityData.schemaName}"`);
2958
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DgvWd1wc.js'); });
2960
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-BcRHcQ0W.js'); });
2959
2961
  const { Schema } = schemaMod;
2960
2962
  const schema = Schema.create(entityInput.entityData.schemaName, {
2961
2963
  waitForReady: false,
@@ -2991,7 +2993,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
2991
2993
  }
2992
2994
  else if (entityInput.entityType === 'modelProperty') {
2993
2995
  // Use existing ModelProperty validation
2994
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DazyAm6l.js'); });
2996
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-CQNDgyZl.js'); });
2995
2997
  const { SchemaValidationService } = validationServiceMod;
2996
2998
  const validationService = new SchemaValidationService();
2997
2999
  // Validate property structure
@@ -3006,7 +3008,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
3006
3008
  // If schema name and model name provided, validate against schema
3007
3009
  if (entityInput.entityData._schemaName && entityInput.entityData.modelName) {
3008
3010
  try {
3009
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DgvWd1wc.js'); });
3011
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-BcRHcQ0W.js'); });
3010
3012
  const { Schema } = schemaMod;
3011
3013
  const schema = Schema.create(entityInput.entityData._schemaName, {
3012
3014
  waitForReady: false,
@@ -3035,7 +3037,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
3035
3037
  }
3036
3038
  else if (entityInput.entityType === 'schema') {
3037
3039
  // Schema validation - use existing validation
3038
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DazyAm6l.js'); });
3040
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-CQNDgyZl.js'); });
3039
3041
  const { SchemaValidationService } = validationServiceMod;
3040
3042
  const validationService = new SchemaValidationService();
3041
3043
  const schemaResult = validationService.validateSchema(entityInput.entityData);
@@ -4987,7 +4989,7 @@ const writeToDatabase = xstate.fromCallback(({ sendBack, input }) => {
4987
4989
  // initial write completes is not overwritten by the stale requestWrite payload.
4988
4990
  let dataToWrite = input.entityData;
4989
4991
  try {
4990
- const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BEpPD4wH.js'); });
4992
+ const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BQYU5hPQ.js'); });
4991
4993
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
4992
4994
  if (ModelProperty && typeof ModelProperty.getById === 'function') {
4993
4995
  const instance = ModelProperty.getById(input.entityId);
@@ -5367,7 +5369,7 @@ const modelMachine = xstate.setup({
5367
5369
  // Create ModelProperty instances for any new property IDs
5368
5370
  if (Array.isArray(newPropertyIds) && newPropertyIds.length > 0) {
5369
5371
  // Import and create instances asynchronously (fire-and-forget)
5370
- Promise.resolve().then(function () { return require('./ModelProperty-BEpPD4wH.js'); }).then(({ ModelProperty }) => {
5372
+ Promise.resolve().then(function () { return require('./ModelProperty-BQYU5hPQ.js'); }).then(({ ModelProperty }) => {
5371
5373
  const createPromises = newPropertyIds.map(async (propertyFileId) => {
5372
5374
  try {
5373
5375
  const property = await ModelProperty.createById(propertyFileId);
@@ -6748,7 +6750,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
6748
6750
  const schemaNameToTry = model$1?.schemaName;
6749
6751
  if (schemaNameToTry) {
6750
6752
  try {
6751
- const { Schema } = await Promise.resolve().then(function () { return require('./Schema-DgvWd1wc.js'); });
6753
+ const { Schema } = await Promise.resolve().then(function () { return require('./Schema-BcRHcQ0W.js'); });
6752
6754
  const schemaInstance = Schema.create(schemaNameToTry, { waitForReady: false });
6753
6755
  const schemaContext = schemaInstance.getService().getSnapshot().context;
6754
6756
  if (schemaContext.models?.[modelName]?.properties) {
@@ -6797,7 +6799,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
6797
6799
  }
6798
6800
  }
6799
6801
  if (Object.keys(propertySchemas).length === 0) {
6800
- const schemaMod = await Promise.resolve().then(function () { return require('./index-BLco2YiE.js'); });
6802
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-BnAqr2le.js'); });
6801
6803
  const { ModelPropertyDataTypes } = schemaMod;
6802
6804
  const KNOWN_MODEL_FALLBACKS = {
6803
6805
  Post: {
@@ -6844,7 +6846,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
6844
6846
  // Infer propertyRecordSchema from metadata when schema is missing (enables persistence)
6845
6847
  let propSchema = propertySchemas[propertyName];
6846
6848
  if (!propSchema && isRefTypeFromMeta) {
6847
- const schemaMod = await Promise.resolve().then(function () { return require('./index-BLco2YiE.js'); });
6849
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-BnAqr2le.js'); });
6848
6850
  const { ModelPropertyDataTypes } = schemaMod;
6849
6851
  propSchema = {
6850
6852
  dataType: refSeedType === 'html' ? ModelPropertyDataTypes.Html
@@ -7101,9 +7103,9 @@ const runPublish = xstate.fromCallback(({ sendBack, input: { context } }) => {
7101
7103
  sendBack({ type: 'publishError', error: new Error(`Item not found for seedLocalId: ${seedLocalId}`) });
7102
7104
  return;
7103
7105
  }
7104
- const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-BNYeCNf_.js'); });
7106
+ const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-DeI0f2UN.js'); });
7105
7107
  const { getPublishUploads } = getPublishUploadsMod;
7106
- const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-Bws1mdNc.js'); });
7108
+ const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-CGKMEL3H.js'); });
7107
7109
  const { getPublishPayload } = getPublishPayloadMod;
7108
7110
  const uploads = await getPublishUploads(item);
7109
7111
  let uploadedTransactions = [];
@@ -7943,7 +7945,7 @@ const resolveRelatedValue = xstate.fromCallback(({ sendBack, input: { context }
7943
7945
  const { isRelation, propertyValue, propertyName, seedUid, propertyRecordSchema, populatedFromDb, schemaUid, } = context;
7944
7946
  const _resolveRelatedValue = async () => {
7945
7947
  // Use dynamic import to break circular dependency
7946
- const schemaMod = await Promise.resolve().then(function () { return require('./index-BLco2YiE.js'); });
7948
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-BnAqr2le.js'); });
7947
7949
  const { ModelPropertyDataTypes } = schemaMod;
7948
7950
  if (!propertyValue || !isRelation || populatedFromDb) {
7949
7951
  return;
@@ -8951,7 +8953,7 @@ const hydrateFromDb = xstate.fromCallback(({ sendBack, input: { context } }) =>
8951
8953
  // to use dynamically imported ModelPropertyDataTypes
8952
8954
  const _hydrateFromDb = async () => {
8953
8955
  // Use dynamic import to break circular dependency
8954
- const schemaMod = await Promise.resolve().then(function () { return require('./index-BLco2YiE.js'); });
8956
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-BnAqr2le.js'); });
8955
8957
  const { ModelPropertyDataTypes } = schemaMod;
8956
8958
  const appDb = BaseDb.getAppDb();
8957
8959
  const whereClauses = [];
@@ -9314,7 +9316,7 @@ const loadOrCreateProperty = xstate.fromCallback(({ sendBack, input: { context }
9314
9316
  };
9315
9317
  // Merge with schema from file/DB to get validation rules (enum, pattern, etc.) - properties table doesn't store these
9316
9318
  try {
9317
- const { getPropertySchema } = await Promise.resolve().then(function () { return require('./property-sm3N2yBU.js'); });
9319
+ const { getPropertySchema } = await Promise.resolve().then(function () { return require('./property-CeR45LMx.js'); });
9318
9320
  let schemaFromFile = await getPropertySchema(normalizedModelName, propertyName);
9319
9321
  if (!schemaFromFile?.validation) {
9320
9322
  // Fallback: get validation from schemaData in database (Schema context may not be loaded yet)
@@ -9779,9 +9781,9 @@ const analyzeInput = xstate.fromCallback(({ sendBack, input: { context, event }
9779
9781
  }
9780
9782
  const _analyzeInput = async () => {
9781
9783
  // Use dynamic import to break circular dependency
9782
- const schemaMod = await Promise.resolve().then(function () { return require('./index-BLco2YiE.js'); });
9784
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-BnAqr2le.js'); });
9783
9785
  const { ModelPropertyDataTypes } = schemaMod;
9784
- const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-DazyAm6l.js'); });
9786
+ const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-CQNDgyZl.js'); });
9785
9787
  let propertyName = propertyNameRaw;
9786
9788
  if (!propertyName) {
9787
9789
  throw new Error('propertyName is required');
@@ -9979,7 +9981,7 @@ const createMetadata = async (metadataValues, propertyRecordSchema, options) =>
9979
9981
  propertyRecordSchema?.validation &&
9980
9982
  metadataValues.propertyValue != null &&
9981
9983
  metadataValues.propertyValue !== '') {
9982
- const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-DazyAm6l.js'); });
9984
+ const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-CQNDgyZl.js'); });
9983
9985
  const validationService = new SchemaValidationService();
9984
9986
  const validationResult = validationService.validatePropertyValue(metadataValues.propertyValue, propertyRecordSchema.dataType, propertyRecordSchema.validation, propertyRecordSchema.refValueType);
9985
9987
  if (!validationResult.isValid && validationResult.errors.length > 0) {
@@ -10570,7 +10572,7 @@ const saveRelation = xstate.fromCallback(({ sendBack, input: { context, event }
10570
10572
  }
10571
10573
  const _saveRelation = async () => {
10572
10574
  // Use dynamic import to break circular dependency
10573
- const schemaMod = await Promise.resolve().then(function () { return require('./index-BLco2YiE.js'); });
10575
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-BnAqr2le.js'); });
10574
10576
  const { ModelPropertyDataTypes } = schemaMod;
10575
10577
  if (!propertyNameRaw) {
10576
10578
  throw new Error('propertyName is required');
@@ -11614,7 +11616,7 @@ class ItemProperty {
11614
11616
  return;
11615
11617
  }
11616
11618
  // Use dynamic import to break circular dependency
11617
- const schemaMod = await Promise.resolve().then(function () { return require('./index-BLco2YiE.js'); });
11619
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-BnAqr2le.js'); });
11618
11620
  const { ModelPropertyDataTypes } = schemaMod;
11619
11621
  const { context } = snapshot;
11620
11622
  const { propertyRecordSchema } = context;
@@ -12117,6 +12119,16 @@ class ItemProperty {
12117
12119
  // but cached instance doesn't (e.g. Item constructor created from schema first, then loadOrCreateItem
12118
12120
  // has metadata with refResolvedValue - we must not lose display data).
12119
12121
  const ctx = instance._getSnapshotContext();
12122
+ const incomingSchema = props.propertyRecordSchema;
12123
+ if (incomingSchema && !ctx.propertyRecordSchema) {
12124
+ instance._dataType = incomingSchema.dataType;
12125
+ instance._isRelation = incomingSchema.dataType === 'Relation';
12126
+ instance._isList = incomingSchema.dataType === 'List';
12127
+ instance._service.send({
12128
+ type: 'updateContext',
12129
+ propertyRecordSchema: incomingSchema,
12130
+ });
12131
+ }
12120
12132
  const needsRefSync = (props.refResolvedValue != null && !ctx.refResolvedValue) ||
12121
12133
  (props.refResolvedDisplayValue != null && !ctx.refResolvedDisplayValue) ||
12122
12134
  (props.localStorageDir != null && !ctx.localStorageDir) ||
@@ -12513,7 +12525,7 @@ class ItemProperty {
12513
12525
  }
12514
12526
  async save() {
12515
12527
  const ctx = this._getSnapshotContext();
12516
- const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-B1I8eLiv.js'); });
12528
+ const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-CsWuaNfH.js'); });
12517
12529
  await assertItemOwned({
12518
12530
  seedLocalId: ctx?.seedLocalId ?? undefined,
12519
12531
  seedUid: ctx?.seedUid ?? undefined,
@@ -12852,7 +12864,7 @@ class Item {
12852
12864
  });
12853
12865
  };
12854
12866
  this.unpublish = async () => {
12855
- const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-B1I8eLiv.js'); });
12867
+ const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-CsWuaNfH.js'); });
12856
12868
  const { getRevokeExecutor } = await Promise.resolve().then(function () { return publishConfig; });
12857
12869
  await assertItemOwned(this);
12858
12870
  const seedUid = this.seedUid;
@@ -12876,7 +12888,7 @@ class Item {
12876
12888
  this._service.send({ type: 'updateContext', revokedAt });
12877
12889
  };
12878
12890
  this.publish = async () => {
12879
- const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-B1I8eLiv.js'); });
12891
+ const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-CsWuaNfH.js'); });
12880
12892
  await assertItemOwned(this);
12881
12893
  this._service.send({ type: 'startPublish' });
12882
12894
  return new Promise((resolve, reject) => {
@@ -12912,12 +12924,12 @@ class Item {
12912
12924
  };
12913
12925
  this.getPublishUploads = async (options) => {
12914
12926
  // Use dynamic import to break circular dependency
12915
- const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-BNYeCNf_.js'); });
12927
+ const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-DeI0f2UN.js'); });
12916
12928
  const { getPublishUploads } = getPublishUploadsMod;
12917
12929
  return await getPublishUploads(this, [], undefined, options);
12918
12930
  };
12919
12931
  this.getPublishPayload = async (uploadedTransactions, options) => {
12920
- const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-Bws1mdNc.js'); });
12932
+ const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-CGKMEL3H.js'); });
12921
12933
  const { getPublishPayload } = getPublishPayloadMod;
12922
12934
  return await getPublishPayload(this, uploadedTransactions, options);
12923
12935
  };
@@ -14411,7 +14423,7 @@ class Item {
14411
14423
  * Destroy the item: soft delete in DB, remove from caches, clean up subscriptions, stop service.
14412
14424
  */
14413
14425
  async destroy() {
14414
- const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-B1I8eLiv.js'); });
14426
+ const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-CsWuaNfH.js'); });
14415
14427
  await assertItemOwned(this);
14416
14428
  const context = this._getSnapshotContext();
14417
14429
  const cacheKeys = Item.collectInstanceCacheKeysForInstance(this);
@@ -14567,7 +14579,7 @@ const runEasSync = xstate.fromPromise(async ({ input, }) => {
14567
14579
  requestPayload: input.requestPayload,
14568
14580
  persistedSnapshot: input.runningSnapshot,
14569
14581
  });
14570
- const { runSyncFromEas } = await Promise.resolve().then(function () { return require('./syncDbWithEas-Dh9HSiwm.js'); });
14582
+ const { runSyncFromEas } = await Promise.resolve().then(function () { return require('./syncDbWithEas-CA2Lum5V.js'); });
14571
14583
  try {
14572
14584
  await runSyncFromEas(toRunSyncArg(input.options));
14573
14585
  await finalizeEasSyncProcessRow(rowId, {
@@ -18182,7 +18194,7 @@ const saveDraftLogger = debug('seedSdk:model:saveDraftToDb');
18182
18194
  // Lazy import cache for ModelProperty to avoid circular dependency
18183
18195
  // Eagerly start loading to minimize delay on first access
18184
18196
  let ModelPropertyClass = null;
18185
- const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-BEpPD4wH.js'); })
18197
+ const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-BQYU5hPQ.js'); })
18186
18198
  .then(module => {
18187
18199
  ModelPropertyClass = module.ModelProperty;
18188
18200
  return ModelPropertyClass;
@@ -18199,7 +18211,7 @@ function getModelProperty() {
18199
18211
  }
18200
18212
  // Lazy import cache for Schema to avoid circular dependency
18201
18213
  let SchemaClass = null;
18202
- const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-DgvWd1wc.js'); })
18214
+ const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-BcRHcQ0W.js'); })
18203
18215
  .then(module => {
18204
18216
  SchemaClass = module.Schema;
18205
18217
  return SchemaClass;
@@ -20153,7 +20165,7 @@ class Db extends BaseDb {
20153
20165
  // You can inspect what will happen before applying
20154
20166
  await apply();
20155
20167
  this.db = db;
20156
- const { backfillMetadataPropertyIds } = await Promise.resolve().then(function () { return require('./backfillMetadataPropertyIds-BHJnW-NK.js'); });
20168
+ const { backfillMetadataPropertyIds } = await Promise.resolve().then(function () { return require('./backfillMetadataPropertyIds-Dn4oVmEv.js'); });
20157
20169
  await backfillMetadataPropertyIds();
20158
20170
  return this.db;
20159
20171
  }
@@ -20800,7 +20812,7 @@ const getTsImport = async (filePath) => {
20800
20812
 
20801
20813
  // Get the directory of this file to resolve relative paths
20802
20814
  // @ts-ignore - rollup plugin-typescript doesn't recognize import.meta with module: "preserve"
20803
- const __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cjs/index-CZ7yR-bZ.js', document.baseURI).href)));
20815
+ const __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cjs/index-ByozbTn_.js', document.baseURI).href)));
20804
20816
  path.dirname(__filename$1);
20805
20817
  const commandExists = (command) => {
20806
20818
  try {
@@ -21398,4 +21410,4 @@ exports.versions = versions;
21398
21410
  exports.waitForEntityIdle = waitForEntityIdle;
21399
21411
  exports.withSeed = withSeed;
21400
21412
  exports.writeProcessMachine = writeProcessMachine;
21401
- //# sourceMappingURL=index-CZ7yR-bZ.js.map
21413
+ //# sourceMappingURL=index-ByozbTn_.js.map