@seedprotocol/sdk 0.4.28 → 0.4.30

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 (95) hide show
  1. package/dist/{ArweaveClient-BeW65rGS.js → ArweaveClient-BA7b13Dl.js} +3 -3
  2. package/dist/{ArweaveClient-BeW65rGS.js.map → ArweaveClient-BA7b13Dl.js.map} +1 -1
  3. package/dist/{ArweaveClient-lm4d-WFB.js → ArweaveClient-DJ8Q63JQ.js} +3 -3
  4. package/dist/{ArweaveClient-lm4d-WFB.js.map → ArweaveClient-DJ8Q63JQ.js.map} +1 -1
  5. package/dist/{Db-VYLhDCFW.js → Db-BHMXF86s.js} +4 -4
  6. package/dist/{Db-VYLhDCFW.js.map → Db-BHMXF86s.js.map} +1 -1
  7. package/dist/{Db-CbS7T1_D.js → Db-qgwjsLKI.js} +4 -4
  8. package/dist/{Db-CbS7T1_D.js.map → Db-qgwjsLKI.js.map} +1 -1
  9. package/dist/{EasClient-BsdrEbha.js → EasClient-BqU4c27A.js} +2 -2
  10. package/dist/{EasClient-BsdrEbha.js.map → EasClient-BqU4c27A.js.map} +1 -1
  11. package/dist/{EasClient-McZ-yLnh.js → EasClient-DjSKI-Jp.js} +2 -2
  12. package/dist/{EasClient-McZ-yLnh.js.map → EasClient-DjSKI-Jp.js.map} +1 -1
  13. package/dist/{FileManager-wXAlwkmU.js → FileManager-DIbVCWke.js} +5 -5
  14. package/dist/FileManager-DIbVCWke.js.map +1 -0
  15. package/dist/{FileManager-8X0RFG8j.js → FileManager-DJ-mFSmc.js} +2 -2
  16. package/dist/{FileManager-8X0RFG8j.js.map → FileManager-DJ-mFSmc.js.map} +1 -1
  17. package/dist/{ModelProperty-e1IIoSSC.js → ModelProperty-jBpPbg3l.js} +17 -17
  18. package/dist/{ModelProperty-e1IIoSSC.js.map → ModelProperty-jBpPbg3l.js.map} +1 -1
  19. package/dist/{PathResolver-C_AdI9lp.js → PathResolver-CxmIkVyO.js} +2 -2
  20. package/dist/{PathResolver-C_AdI9lp.js.map → PathResolver-CxmIkVyO.js.map} +1 -1
  21. package/dist/{PathResolver-CCuiAvIu.js → PathResolver-DmFG4fR1.js} +2 -2
  22. package/dist/{PathResolver-CCuiAvIu.js.map → PathResolver-DmFG4fR1.js.map} +1 -1
  23. package/dist/{QueryClient-BCuLIB8_.js → QueryClient-7vk66LoN.js} +2 -2
  24. package/dist/{QueryClient-BCuLIB8_.js.map → QueryClient-7vk66LoN.js.map} +1 -1
  25. package/dist/{QueryClient-F2a7YH_K.js → QueryClient-CHayftHv.js} +2 -2
  26. package/dist/{QueryClient-F2a7YH_K.js.map → QueryClient-CHayftHv.js.map} +1 -1
  27. package/dist/{Schema-3_R_m7fn.js → Schema-CyWoCyDH.js} +22 -22
  28. package/dist/{Schema-3_R_m7fn.js.map → Schema-CyWoCyDH.js.map} +1 -1
  29. package/dist/{SchemaValidationService-BAPhc_z8.js → SchemaValidationService-ByxyqvS9.js} +2 -2
  30. package/dist/{SchemaValidationService-BAPhc_z8.js.map → SchemaValidationService-ByxyqvS9.js.map} +1 -1
  31. package/dist/{backfillMetadataPropertyIds-pnhgDwmf.js → backfillMetadataPropertyIds-CUenpA6t.js} +2 -2
  32. package/dist/{backfillMetadataPropertyIds-pnhgDwmf.js.map → backfillMetadataPropertyIds-CUenpA6t.js.map} +1 -1
  33. package/dist/cjs/{ModelProperty-B_wtA6Tp.js → ModelProperty-BEpPD4wH.js} +17 -17
  34. package/dist/cjs/{ModelProperty-B_wtA6Tp.js.map → ModelProperty-BEpPD4wH.js.map} +1 -1
  35. package/dist/cjs/{Schema-DycmdXix.js → Schema-DgvWd1wc.js} +20 -20
  36. package/dist/cjs/{Schema-DycmdXix.js.map → Schema-DgvWd1wc.js.map} +1 -1
  37. package/dist/cjs/{SchemaValidationService-CutWcs3L.js → SchemaValidationService-DazyAm6l.js} +2 -2
  38. package/dist/cjs/{SchemaValidationService-CutWcs3L.js.map → SchemaValidationService-DazyAm6l.js.map} +1 -1
  39. package/dist/cjs/{backfillMetadataPropertyIds-BtL7WeI5.js → backfillMetadataPropertyIds-BHJnW-NK.js} +2 -2
  40. package/dist/cjs/{backfillMetadataPropertyIds-BtL7WeI5.js.map → backfillMetadataPropertyIds-BHJnW-NK.js.map} +1 -1
  41. package/dist/cjs/{getItem-B1qXuyLl.js → getItem-CStbsCge.js} +2 -2
  42. package/dist/cjs/{getItem-B1qXuyLl.js.map → getItem-CStbsCge.js.map} +1 -1
  43. package/dist/cjs/{getPublishPayload-DGtDyXfX.js → getPublishPayload-Bws1mdNc.js} +11 -11
  44. package/dist/cjs/{getPublishPayload-DGtDyXfX.js.map → getPublishPayload-Bws1mdNc.js.map} +1 -1
  45. package/dist/cjs/{getPublishUploads-BMVJ2gfR.js → getPublishUploads-BNYeCNf_.js} +4 -4
  46. package/dist/cjs/{getPublishUploads-BMVJ2gfR.js.map → getPublishUploads-BNYeCNf_.js.map} +1 -1
  47. package/dist/cjs/{getSegmentedItemProperties-V0HYWzgM.js → getSegmentedItemProperties-CkhTBPSP.js} +3 -3
  48. package/dist/cjs/{getSegmentedItemProperties-V0HYWzgM.js.map → getSegmentedItemProperties-CkhTBPSP.js.map} +1 -1
  49. package/dist/cjs/{index-Dbu8yrzO.js → index-BLco2YiE.js} +3 -3
  50. package/dist/cjs/index-BLco2YiE.js.map +1 -0
  51. package/dist/cjs/{index-C0v35eOT.js → index-CZ7yR-bZ.js} +41 -41
  52. package/dist/cjs/{index-C0v35eOT.js.map → index-CZ7yR-bZ.js.map} +1 -1
  53. package/dist/cjs/{ownership-BPK6LY7d.js → ownership-B1I8eLiv.js} +2 -2
  54. package/dist/cjs/{ownership-BPK6LY7d.js.map → ownership-B1I8eLiv.js.map} +1 -1
  55. package/dist/cjs/{property-Ctv4ZGoa.js → property-sm3N2yBU.js} +4 -4
  56. package/dist/cjs/{property-Ctv4ZGoa.js.map → property-sm3N2yBU.js.map} +1 -1
  57. package/dist/cjs/{syncDbWithEas-DgZ7Acmb.js → syncDbWithEas-Dh9HSiwm.js} +5 -5
  58. package/dist/cjs/{syncDbWithEas-DgZ7Acmb.js.map → syncDbWithEas-Dh9HSiwm.js.map} +1 -1
  59. package/dist/{getItem-2pjRoJa0.js → getItem-CdgsloEB.js} +2 -2
  60. package/dist/{getItem-2pjRoJa0.js.map → getItem-CdgsloEB.js.map} +1 -1
  61. package/dist/{getPublishPayload-BAPoXumQ.js → getPublishPayload-DlkHAsOA.js} +11 -11
  62. package/dist/{getPublishPayload-BAPoXumQ.js.map → getPublishPayload-DlkHAsOA.js.map} +1 -1
  63. package/dist/{getPublishUploads-D75w3Et5.js → getPublishUploads-BeukCBiR.js} +4 -4
  64. package/dist/{getPublishUploads-D75w3Et5.js.map → getPublishUploads-BeukCBiR.js.map} +1 -1
  65. package/dist/{getSegmentedItemProperties-BLU_UBYI.js → getSegmentedItemProperties-B_yciZHD.js} +3 -3
  66. package/dist/{getSegmentedItemProperties-BLU_UBYI.js.map → getSegmentedItemProperties-B_yciZHD.js.map} +1 -1
  67. package/dist/{index-DKXcFcFk.js → index-C3oIxmh-.js} +52 -52
  68. package/dist/{index-DKXcFcFk.js.map → index-C3oIxmh-.js.map} +1 -1
  69. package/dist/{index-CKY29lZp.js → index-CfZAy_U1.js} +2 -2
  70. package/dist/index-CfZAy_U1.js.map +1 -0
  71. package/dist/{index-CjrqUOwu.js → index-j0nIoPTo.js} +3 -3
  72. package/dist/index-j0nIoPTo.js.map +1 -0
  73. package/dist/main.cjs +1 -1
  74. package/dist/main.js +13 -13
  75. package/dist/node.js +10 -10
  76. package/dist/{ownership-BbSCKuz4.js → ownership-Br40yugt.js} +2 -2
  77. package/dist/{ownership-BbSCKuz4.js.map → ownership-Br40yugt.js.map} +1 -1
  78. package/dist/{property-D0iZYPNc.js → property-DlfKPjHu.js} +5 -5
  79. package/dist/{property-D0iZYPNc.js.map → property-DlfKPjHu.js.map} +1 -1
  80. package/dist/{queries-D4DDYMy9.js → queries-CIlWKRoN.js} +2 -2
  81. package/dist/{queries-D4DDYMy9.js.map → queries-CIlWKRoN.js.map} +1 -1
  82. package/dist/src/vite/index.d.ts.map +1 -1
  83. package/dist/{syncDbWithEas-D3gGL9OM.js → syncDbWithEas-Dsa5kEMM.js} +6 -6
  84. package/dist/{syncDbWithEas-D3gGL9OM.js.map → syncDbWithEas-Dsa5kEMM.js.map} +1 -1
  85. package/dist/{updateSeedRevokedAt-DrtFzF85.js → updateSeedRevokedAt-DHDIH0zy.js} +2 -2
  86. package/dist/{updateSeedRevokedAt-DrtFzF85.js.map → updateSeedRevokedAt-DHDIH0zy.js.map} +1 -1
  87. package/dist/vite.cjs +110 -4
  88. package/dist/vite.cjs.map +1 -1
  89. package/dist/vite.js +110 -4
  90. package/dist/vite.js.map +1 -1
  91. package/package.json +1 -1
  92. package/dist/FileManager-wXAlwkmU.js.map +0 -1
  93. package/dist/cjs/index-Dbu8yrzO.js.map +0 -1
  94. package/dist/index-CKY29lZp.js.map +0 -1
  95. package/dist/index-CjrqUOwu.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"getPublishUploads-BMVJ2gfR.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,IAAI,EAAE;QACvD,OAAO,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;IACjD;AACA,IAAA,OAAO,IAAI,UAAU,CAAC,IAAc,CAAC;AACvC,CAAC;AAEM,MAAM,yBAAyB,GAAG,OACvC,IAAyB,EACzB,WAA+B,EAC/B,WA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,EAAE;QACrD,MAAM,QAAQ,GAAG,gBAAgB,CAAC,UAAU,EAAE,CAAC,WAAW,EAAE;AAC5D,QAAA,MAAM,OAAO,GAAG,SAAS,IAAI,QAAQ,GAAG,QAAQ,CAAC,OAAO,GAAG,IAAI;QAC/D,IAAI,CAAC,OAAO,EAAE;YACZ;QACF;AACA,QAAA,MAAM,aAAa,GAAI,OAAe,CAAC,aAAa;AAEpD,QAAA,IAAI,CAAC,aAAa,IAAI,gBAAgB,CAAC,GAAG,EAAE;YAC1C;QACF;AAEA,QAAA,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAGR,oCAA2B,CAC1DC,uCAA8B,CAAC,aAAa,CAAC,IAAI,EAAE,CACpD;AACD,QAAA,IAAI,CAAC,WAAW,IAAI,CAAC,OAAO,EAAE;YAC5B,MAAM,IAAI,KAAK,CACb,CAAA,2BAAA,EAA8B,gBAAgB,CAAC,YAAY,CAAA,kCAAA,CAAoC,CAChG;QACH;AAEA,QAAA,MAAM,WAAW,GAAG,MAAMM,aAAI,CAAC,IAAI,CAAC;YAClC,WAAW;YACX,OAAO;AACR,SAAA,CAAC;QAEF,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
+ {"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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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-C0v35eOT.js');
5
- var property = require('./property-Ctv4ZGoa.js');
4
+ var main_cjs = require('./index-CZ7yR-bZ.js');
5
+ var property = require('./property-sm3N2yBU.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-V0HYWzgM.js.map
147
+ //# sourceMappingURL=getSegmentedItemProperties-CkhTBPSP.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getSegmentedItemProperties-V0HYWzgM.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,MAA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A,+BAAsB,CAAC,QAAQ,EAAE;AAC5D,gBAAA,sBAAsB,CAAC,IAAI,CAAC,YAAY,CAAC;YAC3C;YACA;QACF;QAEA,IAAI,WAAW,CAAC,QAAQ,KAAKA,+BAAsB,CAAC,QAAQ,EAAE;AAC5D,YAAA,sBAAsB,CAAC,IAAI,CAAC,YAAY,CAAC;YACzC;QACF;QAEA,IAAI,WAAW,CAAC,QAAQ,KAAKA,+BAAsB,CAAC,IAAI,EAAE;;;YAGxD,MAAM,OAAO,GACX,WAAW,CAAC,GAAG,IAAK,WAAyC,CAAC,YAAY;YAC5E,IAAI,OAAO,EAAE;AACX,gBAAA,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC;YACvC;iBAAO;AACL,gBAAA,mBAAmB,CAAC,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
+ {"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,aA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E,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-C0v35eOT.js');
5
- var property = require('./property-Ctv4ZGoa.js');
4
+ var main_cjs = require('./index-CZ7yR-bZ.js');
5
+ var property = require('./property-sm3N2yBU.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-Dbu8yrzO.js.map
67
+ //# sourceMappingURL=index-BLco2YiE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-BLco2YiE.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -2248,7 +2248,7 @@ const createPropertyInstances = async (propertyFileIds) => {
2248
2248
  return;
2249
2249
  }
2250
2250
  try {
2251
- const mod = await Promise.resolve().then(function () { return require('./ModelProperty-B_wtA6Tp.js'); });
2251
+ const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BEpPD4wH.js'); });
2252
2252
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
2253
2253
  if (!ModelProperty) {
2254
2254
  logger$y('createPropertyInstances: ModelProperty not available from dynamic import');
@@ -2432,7 +2432,7 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
2432
2432
  // Step 2: Fallback to Schema context (only if database doesn't have the model)
2433
2433
  // This handles the case where model exists in schema file but not yet in database
2434
2434
  try {
2435
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DycmdXix.js'); });
2435
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DgvWd1wc.js'); });
2436
2436
  const { Schema } = schemaMod;
2437
2437
  const schema = Schema.create(schemaName, { waitForReady: false });
2438
2438
  const schemaSnapshot = schema.getService().getSnapshot();
@@ -2676,7 +2676,7 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
2676
2676
  }
2677
2677
  // Mark schema as draft when a new model is created so saveNewVersion() can persist it
2678
2678
  try {
2679
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DycmdXix.js'); });
2679
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DgvWd1wc.js'); });
2680
2680
  const { Schema } = schemaMod;
2681
2681
  const schema = Schema.create(schemaName, { waitForReady: false });
2682
2682
  schema.getService().send({ type: 'markAsDraft', propertyKey: 'schema:models' });
@@ -2720,10 +2720,10 @@ const validateModel = xstate.fromCallback(({ sendBack, input: { context } }) =>
2720
2720
  const _validateModel = async () => {
2721
2721
  try {
2722
2722
  // Use dynamic imports to break circular dependencies
2723
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-CutWcs3L.js'); });
2723
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DazyAm6l.js'); });
2724
2724
  const { SchemaValidationService } = validationServiceMod;
2725
2725
  const validationService = new SchemaValidationService();
2726
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DycmdXix.js'); });
2726
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DgvWd1wc.js'); });
2727
2727
  const { Schema } = schemaMod;
2728
2728
  // Validate model structure
2729
2729
  const structureResult = validationService.validateModelStructure(context);
@@ -2833,7 +2833,7 @@ const createModelProperties = xstate.fromCallback(({ sendBack, input }) => {
2833
2833
  return;
2834
2834
  }
2835
2835
  logger$w(`Creating ${Object.keys(propertyDefinitions).length} properties for model "${modelName}" (id: ${_dbId})`);
2836
- const mod = await Promise.resolve().then(function () { return require('./ModelProperty-B_wtA6Tp.js'); });
2836
+ const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BEpPD4wH.js'); });
2837
2837
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
2838
2838
  if (!ModelProperty) {
2839
2839
  logger$w('ModelProperty not available from dynamic import');
@@ -2937,7 +2937,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
2937
2937
  const structureMsg = `[validateEntity] Validating model structure`;
2938
2938
  logger$v(structureMsg);
2939
2939
  // Use existing Model validation
2940
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-CutWcs3L.js'); });
2940
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DazyAm6l.js'); });
2941
2941
  const { SchemaValidationService } = validationServiceMod;
2942
2942
  const validationService = new SchemaValidationService();
2943
2943
  // Validate model structure
@@ -2955,7 +2955,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
2955
2955
  if (entityInput.entityData.schemaName) {
2956
2956
  try {
2957
2957
  logger$v(`[validateEntity] Validating model against schema "${entityInput.entityData.schemaName}"`);
2958
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DycmdXix.js'); });
2958
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DgvWd1wc.js'); });
2959
2959
  const { Schema } = schemaMod;
2960
2960
  const schema = Schema.create(entityInput.entityData.schemaName, {
2961
2961
  waitForReady: false,
@@ -2991,7 +2991,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
2991
2991
  }
2992
2992
  else if (entityInput.entityType === 'modelProperty') {
2993
2993
  // Use existing ModelProperty validation
2994
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-CutWcs3L.js'); });
2994
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DazyAm6l.js'); });
2995
2995
  const { SchemaValidationService } = validationServiceMod;
2996
2996
  const validationService = new SchemaValidationService();
2997
2997
  // Validate property structure
@@ -3006,7 +3006,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
3006
3006
  // If schema name and model name provided, validate against schema
3007
3007
  if (entityInput.entityData._schemaName && entityInput.entityData.modelName) {
3008
3008
  try {
3009
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DycmdXix.js'); });
3009
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DgvWd1wc.js'); });
3010
3010
  const { Schema } = schemaMod;
3011
3011
  const schema = Schema.create(entityInput.entityData._schemaName, {
3012
3012
  waitForReady: false,
@@ -3035,7 +3035,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
3035
3035
  }
3036
3036
  else if (entityInput.entityType === 'schema') {
3037
3037
  // Schema validation - use existing validation
3038
- const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-CutWcs3L.js'); });
3038
+ const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DazyAm6l.js'); });
3039
3039
  const { SchemaValidationService } = validationServiceMod;
3040
3040
  const validationService = new SchemaValidationService();
3041
3041
  const schemaResult = validationService.validateSchema(entityInput.entityData);
@@ -4987,7 +4987,7 @@ const writeToDatabase = xstate.fromCallback(({ sendBack, input }) => {
4987
4987
  // initial write completes is not overwritten by the stale requestWrite payload.
4988
4988
  let dataToWrite = input.entityData;
4989
4989
  try {
4990
- const mod = await Promise.resolve().then(function () { return require('./ModelProperty-B_wtA6Tp.js'); });
4990
+ const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BEpPD4wH.js'); });
4991
4991
  const ModelProperty = mod?.ModelProperty ?? mod?.default;
4992
4992
  if (ModelProperty && typeof ModelProperty.getById === 'function') {
4993
4993
  const instance = ModelProperty.getById(input.entityId);
@@ -5367,7 +5367,7 @@ const modelMachine = xstate.setup({
5367
5367
  // Create ModelProperty instances for any new property IDs
5368
5368
  if (Array.isArray(newPropertyIds) && newPropertyIds.length > 0) {
5369
5369
  // Import and create instances asynchronously (fire-and-forget)
5370
- Promise.resolve().then(function () { return require('./ModelProperty-B_wtA6Tp.js'); }).then(({ ModelProperty }) => {
5370
+ Promise.resolve().then(function () { return require('./ModelProperty-BEpPD4wH.js'); }).then(({ ModelProperty }) => {
5371
5371
  const createPromises = newPropertyIds.map(async (propertyFileId) => {
5372
5372
  try {
5373
5373
  const property = await ModelProperty.createById(propertyFileId);
@@ -6748,7 +6748,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
6748
6748
  const schemaNameToTry = model$1?.schemaName;
6749
6749
  if (schemaNameToTry) {
6750
6750
  try {
6751
- const { Schema } = await Promise.resolve().then(function () { return require('./Schema-DycmdXix.js'); });
6751
+ const { Schema } = await Promise.resolve().then(function () { return require('./Schema-DgvWd1wc.js'); });
6752
6752
  const schemaInstance = Schema.create(schemaNameToTry, { waitForReady: false });
6753
6753
  const schemaContext = schemaInstance.getService().getSnapshot().context;
6754
6754
  if (schemaContext.models?.[modelName]?.properties) {
@@ -6797,7 +6797,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
6797
6797
  }
6798
6798
  }
6799
6799
  if (Object.keys(propertySchemas).length === 0) {
6800
- const schemaMod = await Promise.resolve().then(function () { return require('./index-Dbu8yrzO.js'); });
6800
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-BLco2YiE.js'); });
6801
6801
  const { ModelPropertyDataTypes } = schemaMod;
6802
6802
  const KNOWN_MODEL_FALLBACKS = {
6803
6803
  Post: {
@@ -6844,7 +6844,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
6844
6844
  // Infer propertyRecordSchema from metadata when schema is missing (enables persistence)
6845
6845
  let propSchema = propertySchemas[propertyName];
6846
6846
  if (!propSchema && isRefTypeFromMeta) {
6847
- const schemaMod = await Promise.resolve().then(function () { return require('./index-Dbu8yrzO.js'); });
6847
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-BLco2YiE.js'); });
6848
6848
  const { ModelPropertyDataTypes } = schemaMod;
6849
6849
  propSchema = {
6850
6850
  dataType: refSeedType === 'html' ? ModelPropertyDataTypes.Html
@@ -7101,9 +7101,9 @@ const runPublish = xstate.fromCallback(({ sendBack, input: { context } }) => {
7101
7101
  sendBack({ type: 'publishError', error: new Error(`Item not found for seedLocalId: ${seedLocalId}`) });
7102
7102
  return;
7103
7103
  }
7104
- const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-BMVJ2gfR.js'); });
7104
+ const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-BNYeCNf_.js'); });
7105
7105
  const { getPublishUploads } = getPublishUploadsMod;
7106
- const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-DGtDyXfX.js'); });
7106
+ const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-Bws1mdNc.js'); });
7107
7107
  const { getPublishPayload } = getPublishPayloadMod;
7108
7108
  const uploads = await getPublishUploads(item);
7109
7109
  let uploadedTransactions = [];
@@ -7943,7 +7943,7 @@ const resolveRelatedValue = xstate.fromCallback(({ sendBack, input: { context }
7943
7943
  const { isRelation, propertyValue, propertyName, seedUid, propertyRecordSchema, populatedFromDb, schemaUid, } = context;
7944
7944
  const _resolveRelatedValue = async () => {
7945
7945
  // Use dynamic import to break circular dependency
7946
- const schemaMod = await Promise.resolve().then(function () { return require('./index-Dbu8yrzO.js'); });
7946
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-BLco2YiE.js'); });
7947
7947
  const { ModelPropertyDataTypes } = schemaMod;
7948
7948
  if (!propertyValue || !isRelation || populatedFromDb) {
7949
7949
  return;
@@ -8951,7 +8951,7 @@ const hydrateFromDb = xstate.fromCallback(({ sendBack, input: { context } }) =>
8951
8951
  // to use dynamically imported ModelPropertyDataTypes
8952
8952
  const _hydrateFromDb = async () => {
8953
8953
  // Use dynamic import to break circular dependency
8954
- const schemaMod = await Promise.resolve().then(function () { return require('./index-Dbu8yrzO.js'); });
8954
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-BLco2YiE.js'); });
8955
8955
  const { ModelPropertyDataTypes } = schemaMod;
8956
8956
  const appDb = BaseDb.getAppDb();
8957
8957
  const whereClauses = [];
@@ -9314,7 +9314,7 @@ const loadOrCreateProperty = xstate.fromCallback(({ sendBack, input: { context }
9314
9314
  };
9315
9315
  // Merge with schema from file/DB to get validation rules (enum, pattern, etc.) - properties table doesn't store these
9316
9316
  try {
9317
- const { getPropertySchema } = await Promise.resolve().then(function () { return require('./property-Ctv4ZGoa.js'); });
9317
+ const { getPropertySchema } = await Promise.resolve().then(function () { return require('./property-sm3N2yBU.js'); });
9318
9318
  let schemaFromFile = await getPropertySchema(normalizedModelName, propertyName);
9319
9319
  if (!schemaFromFile?.validation) {
9320
9320
  // Fallback: get validation from schemaData in database (Schema context may not be loaded yet)
@@ -9779,9 +9779,9 @@ const analyzeInput = xstate.fromCallback(({ sendBack, input: { context, event }
9779
9779
  }
9780
9780
  const _analyzeInput = async () => {
9781
9781
  // Use dynamic import to break circular dependency
9782
- const schemaMod = await Promise.resolve().then(function () { return require('./index-Dbu8yrzO.js'); });
9782
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-BLco2YiE.js'); });
9783
9783
  const { ModelPropertyDataTypes } = schemaMod;
9784
- const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-CutWcs3L.js'); });
9784
+ const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-DazyAm6l.js'); });
9785
9785
  let propertyName = propertyNameRaw;
9786
9786
  if (!propertyName) {
9787
9787
  throw new Error('propertyName is required');
@@ -9979,7 +9979,7 @@ const createMetadata = async (metadataValues, propertyRecordSchema, options) =>
9979
9979
  propertyRecordSchema?.validation &&
9980
9980
  metadataValues.propertyValue != null &&
9981
9981
  metadataValues.propertyValue !== '') {
9982
- const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-CutWcs3L.js'); });
9982
+ const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-DazyAm6l.js'); });
9983
9983
  const validationService = new SchemaValidationService();
9984
9984
  const validationResult = validationService.validatePropertyValue(metadataValues.propertyValue, propertyRecordSchema.dataType, propertyRecordSchema.validation, propertyRecordSchema.refValueType);
9985
9985
  if (!validationResult.isValid && validationResult.errors.length > 0) {
@@ -10570,7 +10570,7 @@ const saveRelation = xstate.fromCallback(({ sendBack, input: { context, event }
10570
10570
  }
10571
10571
  const _saveRelation = async () => {
10572
10572
  // Use dynamic import to break circular dependency
10573
- const schemaMod = await Promise.resolve().then(function () { return require('./index-Dbu8yrzO.js'); });
10573
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-BLco2YiE.js'); });
10574
10574
  const { ModelPropertyDataTypes } = schemaMod;
10575
10575
  if (!propertyNameRaw) {
10576
10576
  throw new Error('propertyName is required');
@@ -11614,7 +11614,7 @@ class ItemProperty {
11614
11614
  return;
11615
11615
  }
11616
11616
  // Use dynamic import to break circular dependency
11617
- const schemaMod = await Promise.resolve().then(function () { return require('./index-Dbu8yrzO.js'); });
11617
+ const schemaMod = await Promise.resolve().then(function () { return require('./index-BLco2YiE.js'); });
11618
11618
  const { ModelPropertyDataTypes } = schemaMod;
11619
11619
  const { context } = snapshot;
11620
11620
  const { propertyRecordSchema } = context;
@@ -12513,7 +12513,7 @@ class ItemProperty {
12513
12513
  }
12514
12514
  async save() {
12515
12515
  const ctx = this._getSnapshotContext();
12516
- const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-BPK6LY7d.js'); });
12516
+ const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-B1I8eLiv.js'); });
12517
12517
  await assertItemOwned({
12518
12518
  seedLocalId: ctx?.seedLocalId ?? undefined,
12519
12519
  seedUid: ctx?.seedUid ?? undefined,
@@ -12852,7 +12852,7 @@ class Item {
12852
12852
  });
12853
12853
  };
12854
12854
  this.unpublish = async () => {
12855
- const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-BPK6LY7d.js'); });
12855
+ const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-B1I8eLiv.js'); });
12856
12856
  const { getRevokeExecutor } = await Promise.resolve().then(function () { return publishConfig; });
12857
12857
  await assertItemOwned(this);
12858
12858
  const seedUid = this.seedUid;
@@ -12876,7 +12876,7 @@ class Item {
12876
12876
  this._service.send({ type: 'updateContext', revokedAt });
12877
12877
  };
12878
12878
  this.publish = async () => {
12879
- const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-BPK6LY7d.js'); });
12879
+ const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-B1I8eLiv.js'); });
12880
12880
  await assertItemOwned(this);
12881
12881
  this._service.send({ type: 'startPublish' });
12882
12882
  return new Promise((resolve, reject) => {
@@ -12912,12 +12912,12 @@ class Item {
12912
12912
  };
12913
12913
  this.getPublishUploads = async (options) => {
12914
12914
  // Use dynamic import to break circular dependency
12915
- const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-BMVJ2gfR.js'); });
12915
+ const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-BNYeCNf_.js'); });
12916
12916
  const { getPublishUploads } = getPublishUploadsMod;
12917
12917
  return await getPublishUploads(this, [], undefined, options);
12918
12918
  };
12919
12919
  this.getPublishPayload = async (uploadedTransactions, options) => {
12920
- const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-DGtDyXfX.js'); });
12920
+ const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-Bws1mdNc.js'); });
12921
12921
  const { getPublishPayload } = getPublishPayloadMod;
12922
12922
  return await getPublishPayload(this, uploadedTransactions, options);
12923
12923
  };
@@ -14411,7 +14411,7 @@ class Item {
14411
14411
  * Destroy the item: soft delete in DB, remove from caches, clean up subscriptions, stop service.
14412
14412
  */
14413
14413
  async destroy() {
14414
- const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-BPK6LY7d.js'); });
14414
+ const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-B1I8eLiv.js'); });
14415
14415
  await assertItemOwned(this);
14416
14416
  const context = this._getSnapshotContext();
14417
14417
  const cacheKeys = Item.collectInstanceCacheKeysForInstance(this);
@@ -14567,7 +14567,7 @@ const runEasSync = xstate.fromPromise(async ({ input, }) => {
14567
14567
  requestPayload: input.requestPayload,
14568
14568
  persistedSnapshot: input.runningSnapshot,
14569
14569
  });
14570
- const { runSyncFromEas } = await Promise.resolve().then(function () { return require('./syncDbWithEas-DgZ7Acmb.js'); });
14570
+ const { runSyncFromEas } = await Promise.resolve().then(function () { return require('./syncDbWithEas-Dh9HSiwm.js'); });
14571
14571
  try {
14572
14572
  await runSyncFromEas(toRunSyncArg(input.options));
14573
14573
  await finalizeEasSyncProcessRow(rowId, {
@@ -18182,7 +18182,7 @@ const saveDraftLogger = debug('seedSdk:model:saveDraftToDb');
18182
18182
  // Lazy import cache for ModelProperty to avoid circular dependency
18183
18183
  // Eagerly start loading to minimize delay on first access
18184
18184
  let ModelPropertyClass = null;
18185
- const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-B_wtA6Tp.js'); })
18185
+ const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-BEpPD4wH.js'); })
18186
18186
  .then(module => {
18187
18187
  ModelPropertyClass = module.ModelProperty;
18188
18188
  return ModelPropertyClass;
@@ -18199,7 +18199,7 @@ function getModelProperty() {
18199
18199
  }
18200
18200
  // Lazy import cache for Schema to avoid circular dependency
18201
18201
  let SchemaClass = null;
18202
- const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-DycmdXix.js'); })
18202
+ const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-DgvWd1wc.js'); })
18203
18203
  .then(module => {
18204
18204
  SchemaClass = module.Schema;
18205
18205
  return SchemaClass;
@@ -20040,10 +20040,10 @@ class FileManager extends BaseFileManager {
20040
20040
  }
20041
20041
  else if (content instanceof Blob) {
20042
20042
  const arrayBuffer = await content.arrayBuffer();
20043
- await fsAsync__namespace.writeFile(filePath, Buffer.from(arrayBuffer));
20043
+ await fsAsync__namespace.writeFile(filePath, new Uint8Array(arrayBuffer));
20044
20044
  }
20045
20045
  else if (content instanceof ArrayBuffer) {
20046
- await fsAsync__namespace.writeFile(filePath, Buffer.from(content));
20046
+ await fsAsync__namespace.writeFile(filePath, new Uint8Array(content));
20047
20047
  }
20048
20048
  else {
20049
20049
  throw new Error('Unsupported content type');
@@ -20066,7 +20066,7 @@ class FileManager extends BaseFileManager {
20066
20066
  throw new Error('Blob content not supported in saveFileSync. Use saveFile() instead or convert to ArrayBuffer first.');
20067
20067
  }
20068
20068
  else if (content instanceof ArrayBuffer) {
20069
- fs__namespace.writeFileSync(filePath, Buffer.from(content));
20069
+ fs__namespace.writeFileSync(filePath, new Uint8Array(content));
20070
20070
  }
20071
20071
  else {
20072
20072
  throw new Error('Unsupported content type');
@@ -20153,7 +20153,7 @@ class Db extends BaseDb {
20153
20153
  // You can inspect what will happen before applying
20154
20154
  await apply();
20155
20155
  this.db = db;
20156
- const { backfillMetadataPropertyIds } = await Promise.resolve().then(function () { return require('./backfillMetadataPropertyIds-BtL7WeI5.js'); });
20156
+ const { backfillMetadataPropertyIds } = await Promise.resolve().then(function () { return require('./backfillMetadataPropertyIds-BHJnW-NK.js'); });
20157
20157
  await backfillMetadataPropertyIds();
20158
20158
  return this.db;
20159
20159
  }
@@ -20800,7 +20800,7 @@ const getTsImport = async (filePath) => {
20800
20800
 
20801
20801
  // Get the directory of this file to resolve relative paths
20802
20802
  // @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-C0v35eOT.js', document.baseURI).href)));
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)));
20804
20804
  path.dirname(__filename$1);
20805
20805
  const commandExists = (command) => {
20806
20806
  try {
@@ -21398,4 +21398,4 @@ exports.versions = versions;
21398
21398
  exports.waitForEntityIdle = waitForEntityIdle;
21399
21399
  exports.withSeed = withSeed;
21400
21400
  exports.writeProcessMachine = writeProcessMachine;
21401
- //# sourceMappingURL=index-C0v35eOT.js.map
21401
+ //# sourceMappingURL=index-CZ7yR-bZ.js.map