@seedprotocol/sdk 0.4.19 → 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 (93) hide show
  1. package/dist/{ArweaveClient-V62RJhsZ.js → ArweaveClient-C1bakApw.js} +3 -3
  2. package/dist/{ArweaveClient-V62RJhsZ.js.map → ArweaveClient-C1bakApw.js.map} +1 -1
  3. package/dist/{ArweaveClient-CAdWVQnJ.js → ArweaveClient-Ck4wflb3.js} +3 -3
  4. package/dist/{ArweaveClient-CAdWVQnJ.js.map → ArweaveClient-Ck4wflb3.js.map} +1 -1
  5. package/dist/{Db-DS2GBY6h.js → Db-CCMLWMi-.js} +4 -4
  6. package/dist/{Db-DS2GBY6h.js.map → Db-CCMLWMi-.js.map} +1 -1
  7. package/dist/{Db-8N3-le9a.js → Db-YFg99EDt.js} +4 -4
  8. package/dist/{Db-8N3-le9a.js.map → Db-YFg99EDt.js.map} +1 -1
  9. package/dist/{EasClient-D1eibg8b.js → EasClient-BmYeAnq7.js} +2 -2
  10. package/dist/{EasClient-nOmY5meW.js.map → EasClient-BmYeAnq7.js.map} +1 -1
  11. package/dist/{EasClient-nOmY5meW.js → EasClient-Bqzb-xF2.js} +2 -2
  12. package/dist/{EasClient-D1eibg8b.js.map → EasClient-Bqzb-xF2.js.map} +1 -1
  13. package/dist/{FileManager-Cze8qmS1.js → FileManager-Ba1qAT8_.js} +2 -2
  14. package/dist/{FileManager-Cze8qmS1.js.map → FileManager-Ba1qAT8_.js.map} +1 -1
  15. package/dist/{FileManager-DSTAwkqw.js → FileManager-rVAH7uNp.js} +2 -2
  16. package/dist/{FileManager-DSTAwkqw.js.map → FileManager-rVAH7uNp.js.map} +1 -1
  17. package/dist/{ModelProperty-ChevZoUy.js → ModelProperty-Csj84uQv.js} +17 -17
  18. package/dist/{ModelProperty-ChevZoUy.js.map → ModelProperty-Csj84uQv.js.map} +1 -1
  19. package/dist/{PathResolver-C5gj9EU2.js → PathResolver-B5XBxiLt.js} +2 -2
  20. package/dist/{PathResolver-C5gj9EU2.js.map → PathResolver-B5XBxiLt.js.map} +1 -1
  21. package/dist/{PathResolver-3TuYA9yv.js → PathResolver-CzhXp_OH.js} +2 -2
  22. package/dist/{PathResolver-3TuYA9yv.js.map → PathResolver-CzhXp_OH.js.map} +1 -1
  23. package/dist/{QueryClient-BGv6JOls.js → QueryClient-5NAcOOvw.js} +2 -2
  24. package/dist/{QueryClient-BGv6JOls.js.map → QueryClient-5NAcOOvw.js.map} +1 -1
  25. package/dist/{QueryClient-By2vdhIz.js → QueryClient-BqpbpJEP.js} +2 -2
  26. package/dist/{QueryClient-By2vdhIz.js.map → QueryClient-BqpbpJEP.js.map} +1 -1
  27. package/dist/{Schema-BQ5W3aOW.js → Schema-QjwZN91G.js} +22 -22
  28. package/dist/{Schema-BQ5W3aOW.js.map → Schema-QjwZN91G.js.map} +1 -1
  29. package/dist/{SchemaValidationService-DQx83Cte.js → SchemaValidationService-Cwkeb4fG.js} +2 -2
  30. package/dist/{SchemaValidationService-DQx83Cte.js.map → SchemaValidationService-Cwkeb4fG.js.map} +1 -1
  31. package/dist/{backfillMetadataPropertyIds-CMsU83q9.js → backfillMetadataPropertyIds-DCYUHZDQ.js} +2 -2
  32. package/dist/{backfillMetadataPropertyIds-CMsU83q9.js.map → backfillMetadataPropertyIds-DCYUHZDQ.js.map} +1 -1
  33. package/dist/cjs/{ModelProperty-Cuj839nX.js → ModelProperty-m4dACdoX.js} +17 -17
  34. package/dist/cjs/{ModelProperty-Cuj839nX.js.map → ModelProperty-m4dACdoX.js.map} +1 -1
  35. package/dist/cjs/{Schema-TFe24NNG.js → Schema-DlSTkGtE.js} +20 -20
  36. package/dist/cjs/{Schema-TFe24NNG.js.map → Schema-DlSTkGtE.js.map} +1 -1
  37. package/dist/cjs/{SchemaValidationService-DVQrRpse.js → SchemaValidationService-C06zlv2z.js} +2 -2
  38. package/dist/cjs/{SchemaValidationService-DVQrRpse.js.map → SchemaValidationService-C06zlv2z.js.map} +1 -1
  39. package/dist/cjs/{backfillMetadataPropertyIds-BiXK4hT1.js → backfillMetadataPropertyIds-gyFrK_ny.js} +2 -2
  40. package/dist/cjs/{backfillMetadataPropertyIds-BiXK4hT1.js.map → backfillMetadataPropertyIds-gyFrK_ny.js.map} +1 -1
  41. package/dist/cjs/{getItem-FgLv9abh.js → getItem-gFz18nL2.js} +2 -2
  42. package/dist/cjs/{getItem-FgLv9abh.js.map → getItem-gFz18nL2.js.map} +1 -1
  43. package/dist/cjs/{getPublishPayload-h_Rz8nVX.js → getPublishPayload-DHNfV-GE.js} +10 -10
  44. package/dist/cjs/{getPublishPayload-h_Rz8nVX.js.map → getPublishPayload-DHNfV-GE.js.map} +1 -1
  45. package/dist/cjs/{getPublishUploads-DdSwst2x.js → getPublishUploads-Dt-3g6eW.js} +18 -13
  46. package/dist/cjs/getPublishUploads-Dt-3g6eW.js.map +1 -0
  47. package/dist/cjs/{getSegmentedItemProperties-Bu4P_MG8.js → getSegmentedItemProperties-D3XpxCt8.js} +3 -3
  48. package/dist/cjs/{getSegmentedItemProperties-Bu4P_MG8.js.map → getSegmentedItemProperties-D3XpxCt8.js.map} +1 -1
  49. package/dist/cjs/{index-CKJeh6ic.js → index-4M2KX6s4.js} +3 -3
  50. package/dist/cjs/index-4M2KX6s4.js.map +1 -0
  51. package/dist/cjs/{index-pyKmk9hA.js → index-CHrEZZ71.js} +39 -39
  52. package/dist/cjs/{index-pyKmk9hA.js.map → index-CHrEZZ71.js.map} +1 -1
  53. package/dist/cjs/{ownership-gfm5thj7.js → ownership-CC_YF-XC.js} +2 -2
  54. package/dist/cjs/{ownership-gfm5thj7.js.map → ownership-CC_YF-XC.js.map} +1 -1
  55. package/dist/cjs/{property-Dw0b_Sf8.js → property-DtCxuPrc.js} +4 -4
  56. package/dist/cjs/{property-Dw0b_Sf8.js.map → property-DtCxuPrc.js.map} +1 -1
  57. package/dist/{getItem-Bd9U9Yih.js → getItem-CpjN3MFQ.js} +2 -2
  58. package/dist/{getItem-Bd9U9Yih.js.map → getItem-CpjN3MFQ.js.map} +1 -1
  59. package/dist/{getPublishPayload-eJL7ktes.js → getPublishPayload-CMhy9jfz.js} +10 -10
  60. package/dist/{getPublishPayload-eJL7ktes.js.map → getPublishPayload-CMhy9jfz.js.map} +1 -1
  61. package/dist/{getPublishUploads-CKm5dsL6.js → getPublishUploads-DTE4SEWk.js} +18 -13
  62. package/dist/getPublishUploads-DTE4SEWk.js.map +1 -0
  63. package/dist/{getSegmentedItemProperties-B74LN_bz.js → getSegmentedItemProperties-DzPjQtcg.js} +3 -3
  64. package/dist/{getSegmentedItemProperties-B74LN_bz.js.map → getSegmentedItemProperties-DzPjQtcg.js.map} +1 -1
  65. package/dist/{index-BvZCYMxA.js → index-C1HlP_fU.js} +52 -52
  66. package/dist/{index-BvZCYMxA.js.map → index-C1HlP_fU.js.map} +1 -1
  67. package/dist/{index-BxfqPvtu.js → index-DvUyNZc9.js} +3 -3
  68. package/dist/index-DvUyNZc9.js.map +1 -0
  69. package/dist/{index-BQv2k74p.js → index-dDmXPEJC.js} +2 -2
  70. package/dist/index-dDmXPEJC.js.map +1 -0
  71. package/dist/main.cjs +1 -1
  72. package/dist/main.js +12 -12
  73. package/dist/node.js +10 -10
  74. package/dist/{ownership-tVhYQomL.js → ownership-C7GyMbsf.js} +2 -2
  75. package/dist/{ownership-tVhYQomL.js.map → ownership-C7GyMbsf.js.map} +1 -1
  76. package/dist/{property-BOdk-wW1.js → property-BNt7Dkmw.js} +5 -5
  77. package/dist/{property-BOdk-wW1.js.map → property-BNt7Dkmw.js.map} +1 -1
  78. package/dist/{queries-DBqVwEdv.js → queries-D09IIJg_.js} +2 -2
  79. package/dist/{queries-DBqVwEdv.js.map → queries-D09IIJg_.js.map} +1 -1
  80. package/dist/src/Item/Item.d.ts +1 -1
  81. package/dist/src/Item/Item.d.ts.map +1 -1
  82. package/dist/src/db/read/getPublishUploads.d.ts +7 -3
  83. package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
  84. package/dist/src/index.d.ts +1 -1
  85. package/dist/src/index.d.ts.map +1 -1
  86. package/dist/src/interfaces/IItem.d.ts +1 -1
  87. package/dist/src/interfaces/IItem.d.ts.map +1 -1
  88. package/package.json +1 -1
  89. package/dist/cjs/getPublishUploads-DdSwst2x.js.map +0 -1
  90. package/dist/cjs/index-CKJeh6ic.js.map +0 -1
  91. package/dist/getPublishUploads-CKm5dsL6.js.map +0 -1
  92. package/dist/index-BQv2k74p.js.map +0 -1
  93. package/dist/index-BxfqPvtu.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var main_cjs = require('./index-pyKmk9hA.js');
3
+ var main_cjs = require('./index-CHrEZZ71.js');
4
4
  var drizzleOrm = require('drizzle-orm');
5
5
  require('immer');
6
6
  require('reflect-metadata');
@@ -117,4 +117,4 @@ async function assertItemOwned(item) {
117
117
 
118
118
  exports.assertItemOwned = assertItemOwned;
119
119
  exports.isItemOwned = isItemOwned;
120
- //# sourceMappingURL=ownership-gfm5thj7.js.map
120
+ //# sourceMappingURL=ownership-CC_YF-XC.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ownership-gfm5thj7.js","sources":["../../../src/helpers/ownership.ts"],"sourcesContent":["import type { IItem } from '@/interfaces/IItem'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { seeds } from '@/seedSchema'\nimport { eq, or } from 'drizzle-orm'\nimport { getOwnedAddressesFromDb } from '@/helpers/db'\nimport { getGetAdditionalSyncAddresses } from '@/helpers/publishConfig'\n\nconst READ_ONLY_ERROR = 'Item is read-only: you do not own this item'\n\ntype ItemLike = { seedLocalId?: string; seedUid?: string }\n\ntype SeedRow = { publisher: string | null; attestationRaw: string | null; uid: string | null }\n\nasync function getSeedRowForItem(item: ItemLike): Promise<SeedRow | null> {\n const appDb = BaseDb.getAppDb()\n if (!appDb) return null\n\n const conditions = []\n if (item.seedLocalId) conditions.push(eq(seeds.localId, item.seedLocalId))\n if (item.seedUid) conditions.push(eq(seeds.uid, item.seedUid))\n if (conditions.length === 0) return null\n\n const seedRows = await appDb\n .select({\n publisher: seeds.publisher,\n attestationRaw: seeds.attestationRaw,\n uid: seeds.uid,\n })\n .from(seeds)\n .where(conditions.length === 1 ? conditions[0] : (or(...conditions) as any))\n .limit(1)\n\n if (!seedRows || seedRows.length === 0) return null\n return seedRows[0]\n}\n\nfunction getPublisherFromRow(row: SeedRow): string | null {\n if (row.publisher) return row.publisher\n if (row.attestationRaw) {\n try {\n const parsed = JSON.parse(row.attestationRaw) as { attester?: string }\n return parsed.attester ?? null\n } catch {\n return null\n }\n }\n return null\n}\n\n/**\n * Checks if the current user owns the item (publisher is in owned addresses).\n * Locally created items (no publisher, no attestationRaw) are considered owned.\n * Includes getAdditionalSyncAddresses (e.g. modular executor contract) so ownership\n * aligns with EAS sync - items attested by the executor are considered owned.\n */\nexport async function isItemOwned(item: ItemLike | IItem<any>): Promise<boolean> {\n const row = await getSeedRowForItem(item)\n if (!row) return false\n\n const publisher = getPublisherFromRow(row)\n if (!publisher) {\n if (!row.uid && !row.attestationRaw) {\n return true\n }\n return false\n }\n\n let addressesToCheck = await getOwnedAddressesFromDb()\n const additionalGetter = getGetAdditionalSyncAddresses()\n if (additionalGetter) {\n const additional = await additionalGetter()\n if (additional?.length) {\n const seen = new Set(addressesToCheck.map((a) => a.toLowerCase()))\n for (const addr of additional) {\n if (addr && !seen.has(addr.toLowerCase())) {\n seen.add(addr.toLowerCase())\n addressesToCheck = [...addressesToCheck, addr]\n }\n }\n }\n }\n\n const ownedSet = new Set(addressesToCheck.map((a) => a.toLowerCase()))\n return ownedSet.has(publisher.toLowerCase())\n}\n\n/**\n * Throws if the item is not owned. Use before write operations (publish, save, destroy).\n */\nexport async function assertItemOwned(item: ItemLike | IItem<any>): Promise<void> {\n const owned = await isItemOwned(item)\n if (!owned) {\n throw new Error(READ_ONLY_ERROR)\n }\n}\n"],"names":["BaseDb","eq","seeds","or","getOwnedAddressesFromDb","get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,IAAI,CAAC;gBAChD;YACF;QACF;IACF;IAEA,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IACtE,OAAO,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;AAC9C;AAEA;;AAEG;AACI,eAAe,eAAe,CAAC,IAA2B,EAAA;AAC/D,IAAA,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC;IACrC,IAAI,CAAC,KAAK,EAAE;AACV,QAAA,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC;IAClC;AACF;;;;;"}
1
+ {"version":3,"file":"ownership-CC_YF-XC.js","sources":["../../../src/helpers/ownership.ts"],"sourcesContent":["import type { IItem } from '@/interfaces/IItem'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { seeds } from '@/seedSchema'\nimport { eq, or } from 'drizzle-orm'\nimport { getOwnedAddressesFromDb } from '@/helpers/db'\nimport { getGetAdditionalSyncAddresses } from '@/helpers/publishConfig'\n\nconst READ_ONLY_ERROR = 'Item is read-only: you do not own this item'\n\ntype ItemLike = { seedLocalId?: string; seedUid?: string }\n\ntype SeedRow = { publisher: string | null; attestationRaw: string | null; uid: string | null }\n\nasync function getSeedRowForItem(item: ItemLike): Promise<SeedRow | null> {\n const appDb = BaseDb.getAppDb()\n if (!appDb) return null\n\n const conditions = []\n if (item.seedLocalId) conditions.push(eq(seeds.localId, item.seedLocalId))\n if (item.seedUid) conditions.push(eq(seeds.uid, item.seedUid))\n if (conditions.length === 0) return null\n\n const seedRows = await appDb\n .select({\n publisher: seeds.publisher,\n attestationRaw: seeds.attestationRaw,\n uid: seeds.uid,\n })\n .from(seeds)\n .where(conditions.length === 1 ? conditions[0] : (or(...conditions) as any))\n .limit(1)\n\n if (!seedRows || seedRows.length === 0) return null\n return seedRows[0]\n}\n\nfunction getPublisherFromRow(row: SeedRow): string | null {\n if (row.publisher) return row.publisher\n if (row.attestationRaw) {\n try {\n const parsed = JSON.parse(row.attestationRaw) as { attester?: string }\n return parsed.attester ?? null\n } catch {\n return null\n }\n }\n return null\n}\n\n/**\n * Checks if the current user owns the item (publisher is in owned addresses).\n * Locally created items (no publisher, no attestationRaw) are considered owned.\n * Includes getAdditionalSyncAddresses (e.g. modular executor contract) so ownership\n * aligns with EAS sync - items attested by the executor are considered owned.\n */\nexport async function isItemOwned(item: ItemLike | IItem<any>): Promise<boolean> {\n const row = await getSeedRowForItem(item)\n if (!row) return false\n\n const publisher = getPublisherFromRow(row)\n if (!publisher) {\n if (!row.uid && !row.attestationRaw) {\n return true\n }\n return false\n }\n\n let addressesToCheck = await getOwnedAddressesFromDb()\n const additionalGetter = getGetAdditionalSyncAddresses()\n if (additionalGetter) {\n const additional = await additionalGetter()\n if (additional?.length) {\n const seen = new Set(addressesToCheck.map((a) => a.toLowerCase()))\n for (const addr of additional) {\n if (addr && !seen.has(addr.toLowerCase())) {\n seen.add(addr.toLowerCase())\n addressesToCheck = [...addressesToCheck, addr]\n }\n }\n }\n }\n\n const ownedSet = new Set(addressesToCheck.map((a) => a.toLowerCase()))\n return ownedSet.has(publisher.toLowerCase())\n}\n\n/**\n * Throws if the item is not owned. Use before write operations (publish, save, destroy).\n */\nexport async function assertItemOwned(item: ItemLike | IItem<any>): Promise<void> {\n const owned = await isItemOwned(item)\n if (!owned) {\n throw new Error(READ_ONLY_ERROR)\n }\n}\n"],"names":["BaseDb","eq","seeds","or","getOwnedAddressesFromDb","getGetAdditionalSyncAddresses"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAM,eAAe,GAAG,6CAA6C;AAMrE,eAAe,iBAAiB,CAAC,IAAc,EAAA;AAC7C,IAAA,MAAM,KAAK,GAAGA,eAAM,CAAC,QAAQ,EAAE;AAC/B,IAAA,IAAI,CAAC,KAAK;AAAE,QAAA,OAAO,IAAI;IAEvB,MAAM,UA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C,IAA2B,EAAA;AAC/D,IAAA,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC;IACrC,IAAI,CAAC,KAAK,EAAE;AACV,QAAA,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC;IAClC;AACF;;;;;"}
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var pluralize = require('pluralize');
4
- var main_cjs = require('./index-pyKmk9hA.js');
4
+ var main_cjs = require('./index-CHrEZZ71.js');
5
5
  var drizzleOrm = require('drizzle-orm');
6
6
  require('immer');
7
7
  require('reflect-metadata');
@@ -68,9 +68,9 @@ require('graphql-request');
68
68
  */
69
69
  const getPropertySchema = async (modelName, propertyName) => {
70
70
  // Dynamic import to break circular dependency
71
- const modelMod = await Promise.resolve().then(function () { return require('./index-pyKmk9hA.js'); }).then(function (n) { return n.Model$1; });
71
+ const modelMod = await Promise.resolve().then(function () { return require('./index-CHrEZZ71.js'); }).then(function (n) { return n.Model$1; });
72
72
  const { Model } = modelMod;
73
- const schemaMod = await Promise.resolve().then(function () { return require('./Schema-TFe24NNG.js'); });
73
+ const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DlSTkGtE.js'); });
74
74
  const { Schema } = schemaMod;
75
75
  const model = await Model.getByNameAsync(modelName);
76
76
  if (!model) {
@@ -315,4 +315,4 @@ exports.TStorageType = main_cjs.TStorageType;
315
315
  exports.Text = main_cjs.Text;
316
316
  exports.normalizeDataType = main_cjs.normalizeDataType;
317
317
  exports.getPropertySchema = getPropertySchema;
318
- //# sourceMappingURL=property-Dw0b_Sf8.js.map
318
+ //# sourceMappingURL=property-DtCxuPrc.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"property-Dw0b_Sf8.js","sources":["../../../src/helpers/property.ts"],"sourcesContent":["import { Static } from '@sinclair/typebox'\nimport { TProperty } from '@/Schema'\n// Dynamic import to break circular dependency: Model -> ... -> helpers/property -> Model\n// import { Model } from '@/Model/Model'\nimport pluralize from 'pluralize'\nimport { resolveStorageNameToSchemaName } from '@/helpers/metadataPropertyNames'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { models as modelsTable, properties, PropertyType } from '@/seedSchema'\nimport { eq, and } from 'drizzle-orm'\nimport { modelPropertiesToObject } from '@/helpers/model'\n\n// Re-export everything from property/index.ts to make it available when importing from helpers/property\nexport * from './property/index'\n\n/**\n * Gets the propertyRecordSchema object for a given model and property name.\n * \n * The propertyRecordSchema is the property definition object that contains\n * information about the property's data type, storage configuration, and\n * relationship details (for Relation and List types).\n * \n * This function first checks the database for property definitions (which may\n * have been edited), then falls back to schema files. This ensures that\n * edited properties persist across page reloads.\n * \n * This function handles property names that end with 'Id' or 'Ids' by automatically\n * looking up the base property name in the schema (e.g., 'authorId' -> 'author',\n * 'tagIds' -> 'tags').\n * \n * @param modelName - The name of the model (e.g., 'Article', 'Author')\n * @param propertyName - The name of the property (e.g., 'title', 'author', 'authorId', 'tags', 'tagIds')\n * @returns The propertyRecordSchema object (TProperty with optional _propertyFileId) or undefined if not found\n * \n * @example\n * ```typescript\n * const schema = await getPropertySchema('Article', 'title')\n * // Returns: { dataType: 'Text', ... }\n * \n * const relationSchema = await getPropertySchema('Article', 'author')\n * // Returns: { dataType: 'Relation', ref: 'Author', ... }\n * \n * // Also works with Id/Ids suffixes\n * const relationSchemaById = await getPropertySchema('Article', 'authorId')\n * // Returns: { dataType: 'Relation', ref: 'Author', ... }\n * ```\n */\nexport const getPropertySchema = async (\n modelName: string,\n propertyName: string,\n): Promise<(Static<typeof TProperty> & { _propertyFileId?: string }) | undefined> => {\n // Dynamic import to break circular dependency\n const modelMod = await import('../Model/Model')\n const { Model } = modelMod\n const schemaMod = await import('../Schema/Schema')\n const { Schema } = schemaMod\n const model = await Model.getByNameAsync(modelName)\n\n if (!model) {\n return undefined\n }\n \n // Get the original schema from Schema instance context (has ref fields from schema file)\n // This is more reliable than modelPropertiesToObject which depends on ModelProperty instances\n let schema: { [propertyName: string]: any } = {}\n try {\n const schemaName = model.schemaName\n if (schemaName) {\n const schemaInstance = Schema.create(schemaName, {\n waitForReady: false,\n }) as import('@/Schema/Schema').Schema\n const schemaContext = schemaInstance.getService().getSnapshot().context\n if (schemaContext.models && schemaContext.models[modelName]) {\n // Get properties from Schema context (original schema file data)\n const modelDef = schemaContext.models[modelName]\n schema = modelDef.properties || {}\n }\n }\n } catch (error) {\n // Fall through to modelPropertiesToObject\n }\n \n // Fallback to modelPropertiesToObject if Schema context doesn't have the data\n if (Object.keys(schema).length === 0) {\n const properties = model.properties || []\n if (properties.length === 0) {\n return undefined\n }\n schema = modelPropertiesToObject(properties)\n }\n \n // Helper to resolve property name (handles Id/Ids suffixes)\n const resolvePropertyName = (propName: string): string | undefined => {\n // First, try direct lookup\n if (schema[propName]) {\n return propName\n }\n\n // List-of-relation storage name (e.g. authorIdentityIds) -> schema key (authors)\n const listSchemaKey = resolveStorageNameToSchemaName(schema, propName)\n if (listSchemaKey && schema[listSchemaKey]) {\n return listSchemaKey\n }\n\n // Handle properties ending with 'Id' or 'Ids'\n let propertyNameWithoutId: string | undefined\n \n if (propName.endsWith('Id')) {\n propertyNameWithoutId = propName.slice(0, -2)\n } else if (propName.endsWith('Ids')) {\n propertyNameWithoutId = propName.slice(0, -3)\n propertyNameWithoutId = pluralize(propertyNameWithoutId)\n }\n \n if (propertyNameWithoutId && schema[propertyNameWithoutId]) {\n return propertyNameWithoutId\n }\n \n return undefined\n }\n \n const resolvedPropertyName = resolvePropertyName(propertyName)\n if (!resolvedPropertyName) {\n return undefined\n }\n \n // Try to get property from database first (may have edited values)\n try {\n const db = BaseDb.getAppDb()\n if (db) {\n // Find the model in the database\n const modelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, modelName))\n .limit(1)\n \n if (modelRecords.length > 0) {\n const modelRecord = modelRecords[0]\n \n // Find the property in the database by name\n let propertyRecords = await db\n .select()\n .from(properties)\n .where(\n and(\n eq(properties.name, resolvedPropertyName),\n eq(properties.modelId, modelRecord.id!),\n ),\n )\n .limit(1)\n \n // If not found by name, check for renamed properties (orphaned DB properties)\n if (propertyRecords.length === 0) {\n // Get all properties for this model\n const allDbProperties = await db\n .select()\n .from(properties)\n .where(eq(properties.modelId, modelRecord.id!))\n \n // Get all schema property names to identify orphaned properties\n const schemaPropertyNames = new Set(Object.keys(schema))\n \n // Get the schema property definition to match characteristics\n const schemaPropertyDef = schema[resolvedPropertyName]\n \n if (schemaPropertyDef) {\n // Find orphaned properties (don't match any schema property name) that match characteristics\n const orphanedProperties = allDbProperties.filter((p: PropertyType) => \n !schemaPropertyNames.has(p.name) && // Doesn't match any schema property name\n p.dataType === schemaPropertyDef.dataType // Same dataType\n )\n \n // If there's exactly one orphaned property with matching characteristics, it's likely the renamed property\n // We can also match by refModelId if it's a relation\n if (orphanedProperties.length > 0) {\n let matchedProperty = orphanedProperties[0]\n \n // If it's a relation, try to match by refModelId\n if (schemaPropertyDef.ref) {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, schemaPropertyDef.ref))\n .limit(1)\n \n if (refModelRecords.length > 0) {\n const expectedRefModelId = refModelRecords[0].id\n const matchingByRef = orphanedProperties.find((p: PropertyType) => p.refModelId === expectedRefModelId)\n if (matchingByRef) {\n matchedProperty = matchingByRef\n }\n }\n } else {\n // For non-relation properties, prefer ones without refModelId\n const withoutRef = orphanedProperties.find((p: PropertyType) => p.refModelId === null)\n if (withoutRef) {\n matchedProperty = withoutRef\n }\n }\n \n propertyRecords = [matchedProperty]\n }\n }\n }\n \n if (propertyRecords.length > 0) {\n const propertyRecord = propertyRecords[0]\n \n // Get the base schema from file to merge with database values\n // Use the schema object created earlier, not model.schema (which doesn't exist)\n const schemaFromFile = schema[resolvedPropertyName]\n \n // Build property schema from database, merging with file schema for fields not in DB\n // Use the schema property name (resolvedPropertyName) even if DB has different name (renamed)\n const propertySchema: Static<typeof TProperty> & { _propertyFileId?: string; _dbId?: number } = {\n ...schemaFromFile, // Start with file schema (has all fields like storageType, etc.)\n id: propertyRecord.schemaFileId || propertyRecord.id?.toString(), // id should be schemaFileId (string), not database ID\n _dbId: propertyRecord.id, // Store database integer ID separately\n name: resolvedPropertyName, // Use schema name, not DB name (for renamed properties)\n dataType: propertyRecord.dataType as any,\n modelId: propertyRecord.modelId,\n modelName,\n refModelId: propertyRecord.refModelId || undefined,\n refValueType: (propertyRecord.refValueType as any) || undefined,\n required: (propertyRecord as { required?: boolean }).required ?? undefined,\n // Include schemaFileId from database as _propertyFileId for ModelProperty.create()\n _propertyFileId: propertyRecord.schemaFileId || undefined,\n }\n \n // If refModelId is set, try to get the refModelName\n if (propertyRecord.refModelId) {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.id, propertyRecord.refModelId))\n .limit(1)\n \n if (refModelRecords.length > 0) {\n propertySchema.refModelName = refModelRecords[0].name\n propertySchema.ref = refModelRecords[0].name\n }\n } else if (schemaFromFile?.ref) {\n // If refModelId is not set but schema file has ref, resolve it from the database\n // This handles cases where the property was just created and refModelId hasn't been set yet\n propertySchema.ref = schemaFromFile.ref\n propertySchema.refModelName = schemaFromFile.ref\n \n // Try to resolve refModelId from the database using the model name\n try {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, schemaFromFile.ref))\n .limit(1)\n \n if (refModelRecords.length > 0 && refModelRecords[0].id) {\n propertySchema.refModelId = refModelRecords[0].id\n }\n } catch (error) {\n // Ignore errors - model might not exist yet\n }\n }\n \n return propertySchema\n }\n }\n }\n } catch (error) {\n // Database not available or error - fall through to schema file lookup\n }\n \n // Fall back to schema file lookup\n const schemaFromFile = schema[resolvedPropertyName]\n if (schemaFromFile) {\n const propertySchema: Static<typeof TProperty> & { _propertyFileId?: string } = { ...schemaFromFile, name: resolvedPropertyName }\n \n // If schema file has id as a string (propertyFileId), set it as _propertyFileId\n // This handles cases where the property hasn't been saved to the database yet\n if (typeof schemaFromFile.id === 'string') {\n propertySchema._propertyFileId = schemaFromFile.id\n }\n \n // If the schema file has ref but no refModelId, try to resolve it from the database\n if (schemaFromFile.ref && !propertySchema.refModelId) {\n try {\n const db = BaseDb.getAppDb()\n if (db) {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, schemaFromFile.ref))\n .limit(1)\n \n if (refModelRecords.length > 0 && refModelRecords[0].id) {\n propertySchema.refModelId = refModelRecords[0].id\n propertySchema.refModelName = schemaFromFile.ref\n }\n }\n } catch (error) {\n // Ignore errors - model might not exist yet or database not available\n }\n }\n \n return propertySchema\n }\n return undefined\n}\n"],"names":["modelPropertiesToObject","resolveStorageNameToSchemaName","BaseDb","modelsTable","eq","properties","and"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AACA;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BG;AACI,MAAM,iBAAiB,GAAG,OAC/B,SAAiB,EACjB,YAAoB,KAC8D;;AAElF,IAAA,MAAM,QAAQ,GAAG,MAAM,oDAAO,qBAAgB,8CAAC;AAC/C,IAAA,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ;AAC1B,IAAA,MAAM,SAAS,GAAG,MAAM,oDAAO,sBAAkB,KAAC;AAClD,IAAA,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS;IAC5B,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC;IAEnD,IAAI,CAAC,KAAK,EAAE;AACV,QAAA,OAAO,SAAS;IAClB;;;IAIA,IAAI,MAAM,GAAoC,EAAE;AAChD,IAAA,IAAI;AACF,QAAA,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU;QACnC,IAAI,UAAU,EAAE;AACd,YAAA,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;AAC/C,gBAAA,YAAY,EAAE,KAAK;AACpB,aAAA,CAAqC;YACtC,MAAM,aAAa,GAAG,cAAc,CAAC,UAAU,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO;Y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E,EAAE;wBACvD,cAAc,CAAC,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE;AACjD,wBAAA,cAAc,CAAC,YAAY,GAAG,cAAc,CAAC,GAAG;oBAClD;gBACF;YACF;YAAE,OAAO,KAAK,EAAE;;YAEhB;QACF;AAEA,QAAA,OAAO,cAAc;IACvB;AACA,IAAA,OAAO,SAAS;AAClB;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"property-DtCxuPrc.js","sources":["../../../src/helpers/property.ts"],"sourcesContent":["import { Static } from '@sinclair/typebox'\nimport { TProperty } from '@/Schema'\n// Dynamic import to break circular dependency: Model -> ... -> helpers/property -> Model\n// import { Model } from '@/Model/Model'\nimport pluralize from 'pluralize'\nimport { resolveStorageNameToSchemaName } from '@/helpers/metadataPropertyNames'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { models as modelsTable, properties, PropertyType } from '@/seedSchema'\nimport { eq, and } from 'drizzle-orm'\nimport { modelPropertiesToObject } from '@/helpers/model'\n\n// Re-export everything from property/index.ts to make it available when importing from helpers/property\nexport * from './property/index'\n\n/**\n * Gets the propertyRecordSchema object for a given model and property name.\n * \n * The propertyRecordSchema is the property definition object that contains\n * information about the property's data type, storage configuration, and\n * relationship details (for Relation and List types).\n * \n * This function first checks the database for property definitions (which may\n * have been edited), then falls back to schema files. This ensures that\n * edited properties persist across page reloads.\n * \n * This function handles property names that end with 'Id' or 'Ids' by automatically\n * looking up the base property name in the schema (e.g., 'authorId' -> 'author',\n * 'tagIds' -> 'tags').\n * \n * @param modelName - The name of the model (e.g., 'Article', 'Author')\n * @param propertyName - The name of the property (e.g., 'title', 'author', 'authorId', 'tags', 'tagIds')\n * @returns The propertyRecordSchema object (TProperty with optional _propertyFileId) or undefined if not found\n * \n * @example\n * ```typescript\n * const schema = await getPropertySchema('Article', 'title')\n * // Returns: { dataType: 'Text', ... }\n * \n * const relationSchema = await getPropertySchema('Article', 'author')\n * // Returns: { dataType: 'Relation', ref: 'Author', ... }\n * \n * // Also works with Id/Ids suffixes\n * const relationSchemaById = await getPropertySchema('Article', 'authorId')\n * // Returns: { dataType: 'Relation', ref: 'Author', ... }\n * ```\n */\nexport const getPropertySchema = async (\n modelName: string,\n propertyName: string,\n): Promise<(Static<typeof TProperty> & { _propertyFileId?: string }) | undefined> => {\n // Dynamic import to break circular dependency\n const modelMod = await import('../Model/Model')\n const { Model } = modelMod\n const schemaMod = await import('../Schema/Schema')\n const { Schema } = schemaMod\n const model = await Model.getByNameAsync(modelName)\n\n if (!model) {\n return undefined\n }\n \n // Get the original schema from Schema instance context (has ref fields from schema file)\n // This is more reliable than modelPropertiesToObject which depends on ModelProperty instances\n let schema: { [propertyName: string]: any } = {}\n try {\n const schemaName = model.schemaName\n if (schemaName) {\n const schemaInstance = Schema.create(schemaName, {\n waitForReady: false,\n }) as import('@/Schema/Schema').Schema\n const schemaContext = schemaInstance.getService().getSnapshot().context\n if (schemaContext.models && schemaContext.models[modelName]) {\n // Get properties from Schema context (original schema file data)\n const modelDef = schemaContext.models[modelName]\n schema = modelDef.properties || {}\n }\n }\n } catch (error) {\n // Fall through to modelPropertiesToObject\n }\n \n // Fallback to modelPropertiesToObject if Schema context doesn't have the data\n if (Object.keys(schema).length === 0) {\n const properties = model.properties || []\n if (properties.length === 0) {\n return undefined\n }\n schema = modelPropertiesToObject(properties)\n }\n \n // Helper to resolve property name (handles Id/Ids suffixes)\n const resolvePropertyName = (propName: string): string | undefined => {\n // First, try direct lookup\n if (schema[propName]) {\n return propName\n }\n\n // List-of-relation storage name (e.g. authorIdentityIds) -> schema key (authors)\n const listSchemaKey = resolveStorageNameToSchemaName(schema, propName)\n if (listSchemaKey && schema[listSchemaKey]) {\n return listSchemaKey\n }\n\n // Handle properties ending with 'Id' or 'Ids'\n let propertyNameWithoutId: string | undefined\n \n if (propName.endsWith('Id')) {\n propertyNameWithoutId = propName.slice(0, -2)\n } else if (propName.endsWith('Ids')) {\n propertyNameWithoutId = propName.slice(0, -3)\n propertyNameWithoutId = pluralize(propertyNameWithoutId)\n }\n \n if (propertyNameWithoutId && schema[propertyNameWithoutId]) {\n return propertyNameWithoutId\n }\n \n return undefined\n }\n \n const resolvedPropertyName = resolvePropertyName(propertyName)\n if (!resolvedPropertyName) {\n return undefined\n }\n \n // Try to get property from database first (may have edited values)\n try {\n const db = BaseDb.getAppDb()\n if (db) {\n // Find the model in the database\n const modelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, modelName))\n .limit(1)\n \n if (modelRecords.length > 0) {\n const modelRecord = modelRecords[0]\n \n // Find the property in the database by name\n let propertyRecords = await db\n .select()\n .from(properties)\n .where(\n and(\n eq(properties.name, resolvedPropertyName),\n eq(properties.modelId, modelRecord.id!),\n ),\n )\n .limit(1)\n \n // If not found by name, check for renamed properties (orphaned DB properties)\n if (propertyRecords.length === 0) {\n // Get all properties for this model\n const allDbProperties = await db\n .select()\n .from(properties)\n .where(eq(properties.modelId, modelRecord.id!))\n \n // Get all schema property names to identify orphaned properties\n const schemaPropertyNames = new Set(Object.keys(schema))\n \n // Get the schema property definition to match characteristics\n const schemaPropertyDef = schema[resolvedPropertyName]\n \n if (schemaPropertyDef) {\n // Find orphaned properties (don't match any schema property name) that match characteristics\n const orphanedProperties = allDbProperties.filter((p: PropertyType) => \n !schemaPropertyNames.has(p.name) && // Doesn't match any schema property name\n p.dataType === schemaPropertyDef.dataType // Same dataType\n )\n \n // If there's exactly one orphaned property with matching characteristics, it's likely the renamed property\n // We can also match by refModelId if it's a relation\n if (orphanedProperties.length > 0) {\n let matchedProperty = orphanedProperties[0]\n \n // If it's a relation, try to match by refModelId\n if (schemaPropertyDef.ref) {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, schemaPropertyDef.ref))\n .limit(1)\n \n if (refModelRecords.length > 0) {\n const expectedRefModelId = refModelRecords[0].id\n const matchingByRef = orphanedProperties.find((p: PropertyType) => p.refModelId === expectedRefModelId)\n if (matchingByRef) {\n matchedProperty = matchingByRef\n }\n }\n } else {\n // For non-relation properties, prefer ones without refModelId\n const withoutRef = orphanedProperties.find((p: PropertyType) => p.refModelId === null)\n if (withoutRef) {\n matchedProperty = withoutRef\n }\n }\n \n propertyRecords = [matchedProperty]\n }\n }\n }\n \n if (propertyRecords.length > 0) {\n const propertyRecord = propertyRecords[0]\n \n // Get the base schema from file to merge with database values\n // Use the schema object created earlier, not model.schema (which doesn't exist)\n const schemaFromFile = schema[resolvedPropertyName]\n \n // Build property schema from database, merging with file schema for fields not in DB\n // Use the schema property name (resolvedPropertyName) even if DB has different name (renamed)\n const propertySchema: Static<typeof TProperty> & { _propertyFileId?: string; _dbId?: number } = {\n ...schemaFromFile, // Start with file schema (has all fields like storageType, etc.)\n id: propertyRecord.schemaFileId || propertyRecord.id?.toString(), // id should be schemaFileId (string), not database ID\n _dbId: propertyRecord.id, // Store database integer ID separately\n name: resolvedPropertyName, // Use schema name, not DB name (for renamed properties)\n dataType: propertyRecord.dataType as any,\n modelId: propertyRecord.modelId,\n modelName,\n refModelId: propertyRecord.refModelId || undefined,\n refValueType: (propertyRecord.refValueType as any) || undefined,\n required: (propertyRecord as { required?: boolean }).required ?? undefined,\n // Include schemaFileId from database as _propertyFileId for ModelProperty.create()\n _propertyFileId: propertyRecord.schemaFileId || undefined,\n }\n \n // If refModelId is set, try to get the refModelName\n if (propertyRecord.refModelId) {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.id, propertyRecord.refModelId))\n .limit(1)\n \n if (refModelRecords.length > 0) {\n propertySchema.refModelName = refModelRecords[0].name\n propertySchema.ref = refModelRecords[0].name\n }\n } else if (schemaFromFile?.ref) {\n // If refModelId is not set but schema file has ref, resolve it from the database\n // This handles cases where the property was just created and refModelId hasn't been set yet\n propertySchema.ref = schemaFromFile.ref\n propertySchema.refModelName = schemaFromFile.ref\n \n // Try to resolve refModelId from the database using the model name\n try {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, schemaFromFile.ref))\n .limit(1)\n \n if (refModelRecords.length > 0 && refModelRecords[0].id) {\n propertySchema.refModelId = refModelRecords[0].id\n }\n } catch (error) {\n // Ignore errors - model might not exist yet\n }\n }\n \n return propertySchema\n }\n }\n }\n } catch (error) {\n // Database not available or error - fall through to schema file lookup\n }\n \n // Fall back to schema file lookup\n const schemaFromFile = schema[resolvedPropertyName]\n if (schemaFromFile) {\n const propertySchema: Static<typeof TProperty> & { _propertyFileId?: string } = { ...schemaFromFile, name: resolvedPropertyName }\n \n // If schema file has id as a string (propertyFileId), set it as _propertyFileId\n // This handles cases where the property hasn't been saved to the database yet\n if (typeof schemaFromFile.id === 'string') {\n propertySchema._propertyFileId = schemaFromFile.id\n }\n \n // If the schema file has ref but no refModelId, try to resolve it from the database\n if (schemaFromFile.ref && !propertySchema.refModelId) {\n try {\n const db = BaseDb.getAppDb()\n if (db) {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, schemaFromFile.ref))\n .limit(1)\n \n if (refModelRecords.length > 0 && refModelRecords[0].id) {\n propertySchema.refModelId = refModelRecords[0].id\n propertySchema.refModelName = schemaFromFile.ref\n }\n }\n } catch (error) {\n // Ignore errors - model might not exist yet or database not available\n }\n }\n \n return propertySchema\n }\n return undefined\n}\n"],"names":["modelPropertiesToObject","resolveStorageNameToSchemaName","BaseDb","modelsTable","eq","properties","and"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AACA;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BG;AACI,MAAM,iBAAiB,GAAG,OAC/B,SAAiB,EACjB,YAAoB,KAC8D;;AAElF,IAAA,MAAM,QAAQ,GAAG,MAAM,oDAAO,qBAAgB,8CAAC;AAC/C,IAAA,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ;AAC1B,IAAA,MAAM,SAAS,GAAG,MAAM,oDAAO,sBAAkB,KAAC;AAClD,IAAA,MAA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AAe,GAAG,cAAc,CAAC,EAAE;QACpD;;QAGA,IAAI,cAAc,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE;AACpD,YAAA,IAAI;AACF,gBAAA,MAAM,EAAE,GAAGD,eAAM,CAAC,QAAQ,EAAE;gBAC5B,IAAI,EAAE,EAAE;oBACN,MAAM,eAAe,GAAG,MAAM;AAC3B,yBAAA,MAAM;yBACN,IAAI,CAACC,eAAW;yBAChB,KAAK,CAACC,aAAE,CAACD,eAAW,CAAC,IAAI,EAAE,cAAc,CAAC,GAAG,CAAC;yBAC9C,KAAK,CAAC,CAAC,CAAC;AAEX,oBAAA,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;wBACvD,cAAc,CAAC,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE;AACjD,wBAAA,cAAc,CAAC,YAAY,GAAG,cAAc,CAAC,GAAG;oBAClD;gBACF;YACF;YAAE,OAAO,KAAK,EAAE;;YAEhB;QACF;AAEA,QAAA,OAAO,cAAc;IACvB;AACA,IAAA,OAAO,SAAS;AAClB;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,4 +1,4 @@
1
- import { W as getItemData, t as Item } from './index-BvZCYMxA.js';
1
+ import { W as getItemData, t as Item } from './index-C1HlP_fU.js';
2
2
  import { startCase } from 'lodash-es';
3
3
  import 'xstate';
4
4
  import 'drizzle-orm/sqlite-core';
@@ -36,4 +36,4 @@ const getItem = async ({ modelName, seedLocalId, seedUid }) => {
36
36
  };
37
37
 
38
38
  export { getItem };
39
- //# sourceMappingURL=getItem-Bd9U9Yih.js.map
39
+ //# sourceMappingURL=getItem-CpjN3MFQ.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getItem-Bd9U9Yih.js","sources":["../../src/db/read/getItem.ts"],"sourcesContent":["import { getItemData } from './getItemData'\nimport { GetItem } from '@/types'\nimport { Item } from '@/Item/Item'\nimport { startCase } from 'lodash-es'\n\nexport const getItem: GetItem = async ({ modelName, seedLocalId, seedUid }) => {\n const itemInitObj = await getItemData({\n modelName,\n seedLocalId,\n seedUid,\n })\n\n if (!itemInitObj) {\n console.error(\n `[db/queries] [getItem] no itemInitObj modelName: ${modelName} seedLocalId: ${seedLocalId} seedUid: ${seedUid}`,\n )\n return\n }\n\n if (!itemInitObj.seedLocalId) {\n console.error(\n `[db/queries] [getItem] no itemInitObj.seedLocalId modelName: ${modelName} seedLocalId: ${seedLocalId} seedUid: ${seedUid}`,\n )\n return\n }\n\n if (!itemInitObj.modelName && itemInitObj.type) {\n itemInitObj.modelName = startCase(itemInitObj.type)\n }\n\n return Item.create(itemInitObj)\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAKO,MAAM,OAAO,GAAY,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,KAAI;AAC5E,IAAA,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC;QACpC,SAAS;QACT,WAAW;QACX,OAAO;AACR,KAAA,CAAC;IAEF,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,CAAC,KAAK,CACX,CAAA,iDAAA,EAAoD,SAAS,CAAA,cAAA,EAAiB,WAAW,CAAA,UAAA,EAAa,OAAO,CAAA,CAAE,CAChH;QACD;IACF;AAEA,IAAA,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE;QAC5B,OAAO,CAAC,KAAK,CACX,CAAA,6DAAA,EAAgE,SAAS,CAAA,cAAA,EAAiB,WAAW,CAAA,UAAA,EAAa,OAAO,CAAA,CAAE,CAC5H;QACD;IACF;IAEA,IAAI,CAAC,WAAW,CAAC,SAAS,IAAI,WAAW,CAAC,IAAI,EAAE;QAC9C,WAAW,CAAC,SAAS,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC;IACrD;AAEA,IAAA,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;AACjC;;;;"}
1
+ {"version":3,"file":"getItem-CpjN3MFQ.js","sources":["../../src/db/read/getItem.ts"],"sourcesContent":["import { getItemData } from './getItemData'\nimport { GetItem } from '@/types'\nimport { Item } from '@/Item/Item'\nimport { startCase } from 'lodash-es'\n\nexport const getItem: GetItem = async ({ modelName, seedLocalId, seedUid }) => {\n const itemInitObj = await getItemData({\n modelName,\n seedLocalId,\n seedUid,\n })\n\n if (!itemInitObj) {\n console.error(\n `[db/queries] [getItem] no itemInitObj modelName: ${modelName} seedLocalId: ${seedLocalId} seedUid: ${seedUid}`,\n )\n return\n }\n\n if (!itemInitObj.seedLocalId) {\n console.error(\n `[db/queries] [getItem] no itemInitObj.seedLocalId modelName: ${modelName} seedLocalId: ${seedLocalId} seedUid: ${seedUid}`,\n )\n return\n }\n\n if (!itemInitObj.modelName && itemInitObj.type) {\n itemInitObj.modelName = startCase(itemInitObj.type)\n }\n\n return Item.create(itemInitObj)\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAKO,MAAM,OAAO,GAAY,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,KAAI;AAC5E,IAAA,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC;QACpC,SAAS;QACT,WAAW;QACX,OAAO;AACR,KAAA,CAAC;IAEF,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,CAAC,KAAK,CACX,CAAA,iDAAA,EAAoD,SAAS,CAAA,cAAA,EAAiB,WAAW,CAAA,UAAA,EAAa,OAAO,CAAA,CAAE,CAChH;QACD;IACF;AAEA,IAAA,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE;QAC5B,OAAO,CAAC,KAAK,CACX,CAAA,6DAAA,EAAgE,SAAS,CAAA,cAAA,EAAiB,WAAW,CAAA,UAAA,EAAa,OAAO,CAAA,CAAE,CAC5H;QACD;IACF;IAEA,IAAI,CAAC,WAAW,CAAC,SAAS,IAAI,WAAW,CAAC,IAAI,EAAE;QAC9C,WAAW,CAAC,SAAS,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC;IACrD;AAEA,IAAA,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;AACjC;;;;"}
@@ -1,8 +1,8 @@
1
- import { Z as ZERO_BYTES32, x as getEasSchemaUidForModel, o as BaseDb, y as models, z as properties, V as VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA, A as versions, C as modelPropertiesToObject, b as ModelPropertyDataTypes, r as resolveSeedIdsFromRefString, q as normalizeRelationPropertyValue, E as parseListPropertyValueFromStorage, G as getCorrectId, H as INTERNAL_PROPERTY_NAMES, K as defaultAttestationData, O as INTERNAL_DATA_TYPES, Q as toSnakeCase$1, S as getEasSchemaUidForSchemaDefinition, U as getEasSchemaForItemProperty } from './index-BvZCYMxA.js';
1
+ import { Z as ZERO_BYTES32, x as getEasSchemaUidForModel, o as BaseDb, y as models, z as properties, V as VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA, A as versions, C as modelPropertiesToObject, b as ModelPropertyDataTypes, r as resolveSeedIdsFromRefString, q as normalizeRelationPropertyValue, E as parseListPropertyValueFromStorage, G as getCorrectId, H as INTERNAL_PROPERTY_NAMES, K as defaultAttestationData, O as INTERNAL_DATA_TYPES, Q as toSnakeCase$1, S as getEasSchemaUidForSchemaDefinition, U as getEasSchemaForItemProperty } from './index-C1HlP_fU.js';
2
2
  import { toSnakeCase } from 'drizzle-orm/casing';
3
3
  import pluralize from 'pluralize';
4
- import { g as getSegmentedItemProperties } from './getSegmentedItemProperties-B74LN_bz.js';
5
- import { getPropertySchema } from './property-BOdk-wW1.js';
4
+ import { g as getSegmentedItemProperties } from './getSegmentedItemProperties-DzPjQtcg.js';
5
+ import { getPropertySchema } from './property-BNt7Dkmw.js';
6
6
  import { upperFirst, camelCase } from 'lodash-es';
7
7
  import { eq, and, desc } from 'drizzle-orm';
8
8
  import debug from 'debug';
@@ -101,7 +101,7 @@ async function resolveVersionUid(seedLocalId, seedUid) {
101
101
  return uid;
102
102
  }
103
103
  try {
104
- const _mod_0 = await import('./index-BvZCYMxA.js');
104
+ const _mod_0 = await import('./index-C1HlP_fU.js');
105
105
  const _ns_0 = _mod_0.bB;
106
106
  const { getItemVersionsFromEas } = _ns_0;
107
107
  const attestations = await getItemVersionsFromEas({ seedUids: [seedUid] });
@@ -173,7 +173,7 @@ const ensurePropertyDefs = async (targetItem) => {
173
173
  schema = await getPropertySchema(targetItem.modelName, itemProperty.propertyName);
174
174
  if (!schema) {
175
175
  try {
176
- const _mod_1 = await import('./index-BvZCYMxA.js');
176
+ const _mod_1 = await import('./index-C1HlP_fU.js');
177
177
  const _ns_1 = _mod_1.bF;
178
178
  const { Model } = _ns_1;
179
179
  const normalizedModelName = upperFirst(camelCase(targetItem.modelName));
@@ -341,7 +341,7 @@ const processBasicProperties = async (itemBasicProperties, itemPublishData, ctx,
341
341
  }
342
342
  // Validate against property validation rules (enum, pattern, minLength, maxLength) before encoding
343
343
  if (propertyDef?.validation) {
344
- const { SchemaValidationService } = await import('./SchemaValidationService-DQx83Cte.js');
344
+ const { SchemaValidationService } = await import('./SchemaValidationService-Cwkeb4fG.js');
345
345
  const validationService = new SchemaValidationService();
346
346
  const validationResult = validationService.validatePropertyValue(value, propertyDef.dataType, propertyDef.validation, propertyDef.refValueType);
347
347
  if (!validationResult.isValid && validationResult.errors.length > 0) {
@@ -478,7 +478,7 @@ const processRelationOrImageProperty = async (relationOrImageProperty, multiPubl
478
478
  relationOrImageProperty.propertyDef?.refValueType === ModelPropertyDataTypes.Html ||
479
479
  relationOrImageProperty.propertyDef?.refValueType === ModelPropertyDataTypes.Json));
480
480
  if (isStorageSeed && (context.seedLocalId || context.seedUid)) {
481
- const _mod_2 = await import('./index-BvZCYMxA.js');
481
+ const _mod_2 = await import('./index-C1HlP_fU.js');
482
482
  const _ns_2 = _mod_2.bC;
483
483
  const { getPropertyData: getPropertyDataFromDb } = _ns_2;
484
484
  const metaRow = await getPropertyDataFromDb({
@@ -566,7 +566,7 @@ const processRelationOrImageProperty = async (relationOrImageProperty, multiPubl
566
566
  return multiPublishPayload;
567
567
  }
568
568
  // Use dynamic import to break circular dependency
569
- const getItemMod = await import('./getItem-Bd9U9Yih.js');
569
+ const getItemMod = await import('./getItem-CpjN3MFQ.js');
570
570
  const { getItem } = getItemMod;
571
571
  const relatedItem = await getItem({
572
572
  seedLocalId,
@@ -713,7 +713,7 @@ const processListProperty = async (listProperty, multiPublishPayload, originalSe
713
713
  if (!seedLocalId && !seedUid)
714
714
  continue;
715
715
  // Use dynamic import to break circular dependency
716
- const getItemMod = await import('./getItem-Bd9U9Yih.js');
716
+ const getItemMod = await import('./getItem-CpjN3MFQ.js');
717
717
  const { getItem } = getItemMod;
718
718
  const relatedItem = await getItem({
719
719
  seedLocalId,
@@ -1320,4 +1320,4 @@ const resolvePublishPayloadValues = async (multiPayload, resolvedUids) => {
1320
1320
  };
1321
1321
 
1322
1322
  export { PublishValidationFailedError, getPublishPayload, resolvePublishPayloadValues, validateItemForPublish };
1323
- //# sourceMappingURL=getPublishPayload-eJL7ktes.js.map
1323
+ //# sourceMappingURL=getPublishPayload-CMhy9jfz.js.map