@seedprotocol/sdk 0.4.18 → 0.4.20

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 (123) hide show
  1. package/dist/{ArweaveClient-WfxkMgxb.js → ArweaveClient-C1bakApw.js} +3 -3
  2. package/dist/{ArweaveClient-WfxkMgxb.js.map → ArweaveClient-C1bakApw.js.map} +1 -1
  3. package/dist/{ArweaveClient-CpShI0B0.js → ArweaveClient-Ck4wflb3.js} +3 -3
  4. package/dist/{ArweaveClient-CpShI0B0.js.map → ArweaveClient-Ck4wflb3.js.map} +1 -1
  5. package/dist/{Db-DWvxJG22.js → Db-CCMLWMi-.js} +133 -6
  6. package/dist/Db-CCMLWMi-.js.map +1 -0
  7. package/dist/{Db-29bu0gJx.js → Db-YFg99EDt.js} +4 -4
  8. package/dist/{Db-29bu0gJx.js.map → Db-YFg99EDt.js.map} +1 -1
  9. package/dist/{EasClient-BwBg9Kkd.js → EasClient-BmYeAnq7.js} +2 -2
  10. package/dist/{EasClient-BwBg9Kkd.js.map → EasClient-BmYeAnq7.js.map} +1 -1
  11. package/dist/{EasClient-CtLqK_qz.js → EasClient-Bqzb-xF2.js} +2 -2
  12. package/dist/{EasClient-CtLqK_qz.js.map → EasClient-Bqzb-xF2.js.map} +1 -1
  13. package/dist/{FileManager-DgraLHZS.js → FileManager-Ba1qAT8_.js} +2 -2
  14. package/dist/{FileManager-DgraLHZS.js.map → FileManager-Ba1qAT8_.js.map} +1 -1
  15. package/dist/{FileManager-DSihj6Sj.js → FileManager-rVAH7uNp.js} +2 -2
  16. package/dist/{FileManager-DSihj6Sj.js.map → FileManager-rVAH7uNp.js.map} +1 -1
  17. package/dist/{ModelProperty-Bz3V3LoI.js → ModelProperty-Csj84uQv.js} +24 -24
  18. package/dist/{ModelProperty-Bz3V3LoI.js.map → ModelProperty-Csj84uQv.js.map} +1 -1
  19. package/dist/{PathResolver-DQ5hyu8X.js → PathResolver-B5XBxiLt.js} +2 -2
  20. package/dist/{PathResolver-DQ5hyu8X.js.map → PathResolver-B5XBxiLt.js.map} +1 -1
  21. package/dist/{PathResolver-DOu-0k75.js → PathResolver-CzhXp_OH.js} +2 -2
  22. package/dist/{PathResolver-DOu-0k75.js.map → PathResolver-CzhXp_OH.js.map} +1 -1
  23. package/dist/{QueryClient-DYaqIx7e.js → QueryClient-5NAcOOvw.js} +2 -2
  24. package/dist/{QueryClient-DYaqIx7e.js.map → QueryClient-5NAcOOvw.js.map} +1 -1
  25. package/dist/{QueryClient-CJV1m2rc.js → QueryClient-BqpbpJEP.js} +2 -2
  26. package/dist/{QueryClient-CJV1m2rc.js.map → QueryClient-BqpbpJEP.js.map} +1 -1
  27. package/dist/{Schema-CFMbnImW.js → Schema-QjwZN91G.js} +38 -38
  28. package/dist/{Schema-CFMbnImW.js.map → Schema-QjwZN91G.js.map} +1 -1
  29. package/dist/{SchemaValidationService-D4ZVetLE.js → SchemaValidationService-Cwkeb4fG.js} +2 -2
  30. package/dist/{SchemaValidationService-D4ZVetLE.js.map → SchemaValidationService-Cwkeb4fG.js.map} +1 -1
  31. package/dist/{backfillMetadataPropertyIds-DptGKVzG.js → backfillMetadataPropertyIds-DCYUHZDQ.js} +2 -2
  32. package/dist/{backfillMetadataPropertyIds-DptGKVzG.js.map → backfillMetadataPropertyIds-DCYUHZDQ.js.map} +1 -1
  33. package/dist/cjs/{ModelProperty-TPey_B4m.js → ModelProperty-m4dACdoX.js} +17 -17
  34. package/dist/cjs/{ModelProperty-TPey_B4m.js.map → ModelProperty-m4dACdoX.js.map} +1 -1
  35. package/dist/cjs/{Schema-B-IQEtpX.js → Schema-DlSTkGtE.js} +20 -20
  36. package/dist/cjs/{Schema-B-IQEtpX.js.map → Schema-DlSTkGtE.js.map} +1 -1
  37. package/dist/cjs/{SchemaValidationService-IQ0Gc9HM.js → SchemaValidationService-C06zlv2z.js} +2 -2
  38. package/dist/cjs/{SchemaValidationService-IQ0Gc9HM.js.map → SchemaValidationService-C06zlv2z.js.map} +1 -1
  39. package/dist/cjs/{backfillMetadataPropertyIds-BBPgBc2W.js → backfillMetadataPropertyIds-gyFrK_ny.js} +2 -2
  40. package/dist/cjs/{backfillMetadataPropertyIds-BBPgBc2W.js.map → backfillMetadataPropertyIds-gyFrK_ny.js.map} +1 -1
  41. package/dist/cjs/{getItem-CWf0OO0F.js → getItem-gFz18nL2.js} +2 -2
  42. package/dist/cjs/{getItem-CWf0OO0F.js.map → getItem-gFz18nL2.js.map} +1 -1
  43. package/dist/cjs/{getPublishPayload-muuS1j0F.js → getPublishPayload-DHNfV-GE.js} +18 -10
  44. package/dist/cjs/getPublishPayload-DHNfV-GE.js.map +1 -0
  45. package/dist/cjs/{getPublishUploads-CONYV9QQ.js → getPublishUploads-Dt-3g6eW.js} +18 -13
  46. package/dist/cjs/getPublishUploads-Dt-3g6eW.js.map +1 -0
  47. package/dist/cjs/{getSegmentedItemProperties-Dl3J_uCe.js → getSegmentedItemProperties-D3XpxCt8.js} +3 -3
  48. package/dist/cjs/{getSegmentedItemProperties-Dl3J_uCe.js.map → getSegmentedItemProperties-D3XpxCt8.js.map} +1 -1
  49. package/dist/cjs/{index-D7a8oFJP.js → index-4M2KX6s4.js} +3 -3
  50. package/dist/cjs/index-4M2KX6s4.js.map +1 -0
  51. package/dist/cjs/{index-Bte-I6OD.js → index-CHrEZZ71.js} +163 -40
  52. package/dist/cjs/index-CHrEZZ71.js.map +1 -0
  53. package/dist/cjs/{ownership-Bxv6CUrH.js → ownership-CC_YF-XC.js} +2 -2
  54. package/dist/cjs/{ownership-Bxv6CUrH.js.map → ownership-CC_YF-XC.js.map} +1 -1
  55. package/dist/cjs/{property-xOF5k4ka.js → property-DtCxuPrc.js} +4 -4
  56. package/dist/cjs/{property-xOF5k4ka.js.map → property-DtCxuPrc.js.map} +1 -1
  57. package/dist/db/drizzle/drizzle/0010_add_arweave_l1_finalize_jobs.sql +16 -0
  58. package/dist/db/drizzle/drizzle/meta/0010_snapshot.json +1182 -0
  59. package/dist/db/drizzle/drizzle/meta/_journal.json +7 -0
  60. package/dist/{getItem-Hubs_yxu.js → getItem-CpjN3MFQ.js} +2 -2
  61. package/dist/{getItem-Hubs_yxu.js.map → getItem-CpjN3MFQ.js.map} +1 -1
  62. package/dist/{getPublishPayload-CqUCIlu1.js → getPublishPayload-CMhy9jfz.js} +21 -13
  63. package/dist/getPublishPayload-CMhy9jfz.js.map +1 -0
  64. package/dist/{getPublishUploads-QgfPyhcs.js → getPublishUploads-DTE4SEWk.js} +18 -13
  65. package/dist/getPublishUploads-DTE4SEWk.js.map +1 -0
  66. package/dist/{getSegmentedItemProperties-Dzscmm_m.js → getSegmentedItemProperties-DzPjQtcg.js} +3 -3
  67. package/dist/{getSegmentedItemProperties-Dzscmm_m.js.map → getSegmentedItemProperties-DzPjQtcg.js.map} +1 -1
  68. package/dist/{index-CtzvJMAE.js → index-C1HlP_fU.js} +190 -55
  69. package/dist/index-C1HlP_fU.js.map +1 -0
  70. package/dist/{index-VmIdPfTW.js → index-DvUyNZc9.js} +3 -3
  71. package/dist/index-DvUyNZc9.js.map +1 -0
  72. package/dist/{index-QSl4EYun.js → index-dDmXPEJC.js} +3 -2
  73. package/dist/index-dDmXPEJC.js.map +1 -0
  74. package/dist/main.cjs +1 -1
  75. package/dist/main.js +55 -14
  76. package/dist/main.js.map +1 -1
  77. package/dist/node.js +10 -10
  78. package/dist/{ownership-loPNh3_a.js → ownership-C7GyMbsf.js} +2 -2
  79. package/dist/{ownership-loPNh3_a.js.map → ownership-C7GyMbsf.js.map} +1 -1
  80. package/dist/{property-D8HimAKw.js → property-BNt7Dkmw.js} +6 -6
  81. package/dist/{property-D8HimAKw.js.map → property-BNt7Dkmw.js.map} +1 -1
  82. package/dist/{queries-DPADHnwy.js → queries-D09IIJg_.js} +2 -2
  83. package/dist/{queries-DPADHnwy.js.map → queries-D09IIJg_.js.map} +1 -1
  84. package/dist/seedSchema/ArweaveL1FinalizeSchema.ts +28 -0
  85. package/dist/seedSchema/index.d.ts +3 -0
  86. package/dist/seedSchema/index.ts +1 -0
  87. package/dist/src/Item/Item.d.ts +1 -1
  88. package/dist/src/Item/Item.d.ts.map +1 -1
  89. package/dist/src/browser/db/drizzleFiles.d.ts +3 -2
  90. package/dist/src/browser/db/drizzleFiles.d.ts.map +1 -1
  91. package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
  92. package/dist/src/db/read/getPublishUploads.d.ts +7 -3
  93. package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
  94. package/dist/src/db/write/applyArweaveL1TransactionIdLocal.d.ts +12 -0
  95. package/dist/src/db/write/applyArweaveL1TransactionIdLocal.d.ts.map +1 -0
  96. package/dist/src/eas.d.ts +6 -0
  97. package/dist/src/eas.d.ts.map +1 -1
  98. package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
  99. package/dist/src/helpers/ArweaveClient/arweaveL1UploadApi.d.ts +46 -0
  100. package/dist/src/helpers/ArweaveClient/arweaveL1UploadApi.d.ts.map +1 -0
  101. package/dist/src/helpers/constants.d.ts +2 -0
  102. package/dist/src/helpers/constants.d.ts.map +1 -1
  103. package/dist/src/helpers/index.d.ts +1 -0
  104. package/dist/src/helpers/index.d.ts.map +1 -1
  105. package/dist/src/index.d.ts +7 -5
  106. package/dist/src/index.d.ts.map +1 -1
  107. package/dist/src/interfaces/IItem.d.ts +1 -1
  108. package/dist/src/interfaces/IItem.d.ts.map +1 -1
  109. package/dist/src/seedSchema/ArweaveL1FinalizeSchema.d.ts +233 -0
  110. package/dist/src/seedSchema/ArweaveL1FinalizeSchema.d.ts.map +1 -0
  111. package/dist/src/seedSchema/index.d.ts +1 -0
  112. package/dist/src/seedSchema/index.d.ts.map +1 -1
  113. package/package.json +1 -1
  114. package/dist/Db-DWvxJG22.js.map +0 -1
  115. package/dist/cjs/getPublishPayload-muuS1j0F.js.map +0 -1
  116. package/dist/cjs/getPublishUploads-CONYV9QQ.js.map +0 -1
  117. package/dist/cjs/index-Bte-I6OD.js.map +0 -1
  118. package/dist/cjs/index-D7a8oFJP.js.map +0 -1
  119. package/dist/getPublishPayload-CqUCIlu1.js.map +0 -1
  120. package/dist/getPublishUploads-QgfPyhcs.js.map +0 -1
  121. package/dist/index-CtzvJMAE.js.map +0 -1
  122. package/dist/index-QSl4EYun.js.map +0 -1
  123. package/dist/index-VmIdPfTW.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { r as resolveSeedIdsFromRefString, q as normalizeRelationPropertyValue, t as Item, u as BaseFileManager, v as getContentHash, w as BaseArweaveClient } from './index-CtzvJMAE.js';
2
- import { g as getSegmentedItemProperties } from './getSegmentedItemProperties-Dzscmm_m.js';
1
+ import { r as resolveSeedIdsFromRefString, q as normalizeRelationPropertyValue, t as Item, u as BaseFileManager, v as getContentHash, w as BaseArweaveClient } from './index-C1HlP_fU.js';
2
+ import { g as getSegmentedItemProperties } from './getSegmentedItemProperties-DzPjQtcg.js';
3
3
  import debug from 'debug';
4
4
  import 'xstate';
5
5
  import 'drizzle-orm/sqlite-core';
@@ -16,7 +16,7 @@ import 'eventemitter3';
16
16
  import 'arweave';
17
17
  import 'js-sha3';
18
18
  import 'reflect-metadata';
19
- import './property-D8HimAKw.js';
19
+ import './property-BNt7Dkmw.js';
20
20
 
21
21
  const logger = debug('seedSdk:item:getPublishUploads');
22
22
  const EXTENSION_TO_MIME = {
@@ -41,7 +41,7 @@ const toUint8Array = async (data) => {
41
41
  }
42
42
  return new Uint8Array(data);
43
43
  };
44
- const prepareArweaveTransaction = async (data, contentHash, contentType) => {
44
+ const prepareArweaveTransaction = async (data, contentHash, contentType, additionalTags) => {
45
45
  const tags = [];
46
46
  if (contentHash) {
47
47
  tags.push({ name: 'Content-SHA-256', value: contentHash });
@@ -51,6 +51,9 @@ const prepareArweaveTransaction = async (data, contentHash, contentType) => {
51
51
  if (contentType) {
52
52
  tags.push({ name: 'Content-Type', value: contentType });
53
53
  }
54
+ if (additionalTags?.length) {
55
+ tags.push(...additionalTags);
56
+ }
54
57
  const tx = await BaseArweaveClient.createTransaction(data, {
55
58
  tags: tags.length ? tags : undefined,
56
59
  });
@@ -70,8 +73,9 @@ const getStorageDirForDataType = (dataType) => {
70
73
  return BaseFileManager.getFilesPath('images');
71
74
  }
72
75
  };
73
- const getStorageSeedUploads = async (itemStorageSeedProperties) => {
76
+ const getStorageSeedUploads = async (itemStorageSeedProperties, options) => {
74
77
  const uploads = [];
78
+ const extra = options?.arweaveUploadTags;
75
79
  for (const itemProperty of itemStorageSeedProperties) {
76
80
  const snapshot = itemProperty.getService().getSnapshot();
77
81
  const context = 'context' in snapshot ? snapshot.context : null;
@@ -101,7 +105,7 @@ const getStorageSeedUploads = async (itemStorageSeedProperties) => {
101
105
  const fileContents = await toUint8Array(fileBuffer);
102
106
  const contentHash = await getContentHash(fileContents);
103
107
  const contentType = getMimeTypeFromPath(refResolvedValue);
104
- const transaction = await prepareArweaveTransaction(fileContents, contentHash, contentType);
108
+ const transaction = await prepareArweaveTransaction(fileContents, contentHash, contentType, extra);
105
109
  uploads.push({
106
110
  itemPropertyName: itemProperty.propertyName,
107
111
  itemPropertyLocalId: itemProperty.localId,
@@ -209,7 +213,8 @@ async function itemHasPublishUploadCandidates(item, relatedItemProperty) {
209
213
  }
210
214
  return false;
211
215
  }
212
- const processUploadProperty = async (uploadProperty, uploads, relatedItemProperty) => {
216
+ const processUploadProperty = async (uploadProperty, uploads, relatedItemProperty, options) => {
217
+ const extra = options?.arweaveUploadTags;
213
218
  const itemProperty = uploadProperty.itemProperty;
214
219
  const childUploads = [];
215
220
  for (const childProperty of uploadProperty.childProperties) {
@@ -285,7 +290,7 @@ const processUploadProperty = async (uploadProperty, uploads, relatedItemPropert
285
290
  else if (childUploads.length > 0) {
286
291
  contentType = 'application/octet-stream';
287
292
  }
288
- transaction = await prepareArweaveTransaction(uint8Array, contentHash, contentType);
293
+ transaction = await prepareArweaveTransaction(uint8Array, contentHash, contentType, extra);
289
294
  let itemPropertyLocalId = relatedItemProperty
290
295
  ? relatedItemProperty.localId
291
296
  : itemProperty.localId;
@@ -301,7 +306,7 @@ const processUploadProperty = async (uploadProperty, uploads, relatedItemPropert
301
306
  });
302
307
  return uploads;
303
308
  };
304
- const getPublishUploads = async (item, uploads = [], relatedItemProperty) => {
309
+ const getPublishUploads = async (item, uploads = [], relatedItemProperty, options) => {
305
310
  // if (item.modelName === 'Post') {
306
311
  // if (!item.authors) {
307
312
  // item.authors = [
@@ -312,9 +317,9 @@ const getPublishUploads = async (item, uploads = [], relatedItemProperty) => {
312
317
  // }
313
318
  const { itemUploadProperties, itemRelationProperties, itemImageProperties } = await getSegmentedItemProperties(item);
314
319
  for (const uploadProperty of itemUploadProperties) {
315
- uploads = await processUploadProperty(uploadProperty, uploads, relatedItemProperty);
320
+ uploads = await processUploadProperty(uploadProperty, uploads, relatedItemProperty, options);
316
321
  }
317
- const storageSeedUploads = await getStorageSeedUploads(itemImageProperties);
322
+ const storageSeedUploads = await getStorageSeedUploads(itemImageProperties, options);
318
323
  uploads.push(...storageSeedUploads);
319
324
  for (const relationProperty of itemRelationProperties) {
320
325
  const snapshot = relationProperty.getService().getSnapshot();
@@ -337,10 +342,10 @@ const getPublishUploads = async (item, uploads = [], relatedItemProperty) => {
337
342
  if (!relatedItem) {
338
343
  throw new Error(`No relatedItem found for ${relationProperty.propertyName}`);
339
344
  }
340
- uploads = await getPublishUploads(relatedItem, uploads, relationProperty);
345
+ uploads = await getPublishUploads(relatedItem, uploads, relationProperty, options);
341
346
  }
342
347
  return uploads;
343
348
  };
344
349
 
345
350
  export { getPublishUploads, itemHasPublishUploadCandidates, prepareArweaveTransaction };
346
- //# sourceMappingURL=getPublishUploads-QgfPyhcs.js.map
351
+ //# sourceMappingURL=getPublishUploads-DTE4SEWk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPublishUploads-DTE4SEWk.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'\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\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 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 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\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 // if (item.modelName === 'Post') {\n // if (!item.authors) {\n // item.authors = [\n // 'Sr0bIx9Fwj',\n // '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',\n // ]\n // }\n // }\n\n const { itemUploadProperties, itemRelationProperties, itemImageProperties } =\n await getSegmentedItemProperties(item)\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 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":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAcA,MAAM,MAAM,GAAG,KAAK,CAAC,gCAAgC,CAAC;AAOtD,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;AACl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5B,MAAM,IAAI,KAAK,CACb,CAAA,2BAAA,EAA8B,gBAAgB,CAAC,YAAY,CAAA,kCAAA,CAAoC,CAChG;QACH;AAEA,QAAA,MAAM,WAAW,GAAG,MAAM,IAAI,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,6 +1,6 @@
1
1
  import 'reflect-metadata';
2
- import { b as ModelPropertyDataTypes, o as BaseDb, y as models, z as properties } from './index-CtzvJMAE.js';
3
- import { getPropertySchema } from './property-D8HimAKw.js';
2
+ import { b as ModelPropertyDataTypes, o as BaseDb, y as models, z as properties } from './index-C1HlP_fU.js';
3
+ import { getPropertySchema } from './property-BNt7Dkmw.js';
4
4
  import { eq, and } from 'drizzle-orm';
5
5
  import { upperFirst, camelCase } from 'lodash-es';
6
6
 
@@ -142,4 +142,4 @@ const getSegmentedItemProperties = async (item) => {
142
142
  };
143
143
 
144
144
  export { getSegmentedItemProperties as g };
145
- //# sourceMappingURL=getSegmentedItemProperties-Dzscmm_m.js.map
145
+ //# sourceMappingURL=getSegmentedItemProperties-DzPjQtcg.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getSegmentedItemProperties-Dzscmm_m.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":[],"mappings":";;;;;;AASA,eAAe,kBAAkB,CAC/B,SAAiB,EACjB,YAAoB,EAAA;IAEpB,IAAI,MAAM,GAAG,MAAM,iBAAiB,CAAC,SAAS,EAAE,YAAY,CAAC;AAC7D,IAAA,IAAI,MAAM;AAAE,QAAA,OAAO,MAAM;AACzB,IAAA,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE;AAC5B,IAAA,IAAI,CAAC,EAAE;AAAE,QAAA,OAAO,SAAS;AACzB,IAAA,IAAI;QACF,MAAM,mBAAmB,GAAG,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC5D,MAAM,YAAY,GAAG,MAAM;aACxB,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;aACxB,IAAI,CAAC,MAAM;aACX,KAAK,CAAC,EAAE,CAAC,MAAM,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,CAAC,UAAU;aACf,KAAK,CACJ,GAAG,CACD,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAC1C,EAAE,CAAC,UAAU,CAAC,I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;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-DzPjQtcg.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":[],"mappings":";;;;;;AASA,eAAe,kBAAkB,CAC/B,SAAiB,EACjB,YAAoB,EAAA;IAEpB,IAAI,MAAM,GAAG,MAAM,iBAAiB,CAAC,SAAS,EAAE,YAAY,CAAC;AAC7D,IAAA,IAAI,MAAM;AAAE,QAAA,OAAO,MAAM;AACzB,IAAA,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE;AAC5B,IAAA,IAAI,CAAC,EAAE;AAAE,QAAA,OAAO,SAAS;AACzB,IAAA,IAAI;QACF,MAAM,mBAAmB,GAAG,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC5D,MAAM,YAAY,GAAG,MAAM;aACxB,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,E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