@seedprotocol/sdk 0.6.7 → 0.6.8

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 (201) hide show
  1. package/dist/{BasePathResolver-qV0apdVY.js → BasePathResolver-B6CKqoKw.js} +16 -5
  2. package/dist/BasePathResolver-B6CKqoKw.js.map +1 -0
  3. package/dist/{ClientManager-Y5EWQuJj.js → ClientManager-ChcmUL47.js} +619 -264
  4. package/dist/ClientManager-ChcmUL47.js.map +1 -0
  5. package/dist/{ModelProperty-DuB5nk6A.js → ModelProperty-D79uV42p.js} +33 -30
  6. package/dist/ModelProperty-D79uV42p.js.map +1 -0
  7. package/dist/{Schema-BYM-GNdE.js → Schema-a8uO-hIZ.js} +43 -43
  8. package/dist/Schema-a8uO-hIZ.js.map +1 -0
  9. package/dist/{SchemaValidationService-Dr6nmwPm.js → SchemaValidationService-Y49vqast.js} +13 -12
  10. package/dist/SchemaValidationService-Y49vqast.js.map +1 -0
  11. package/dist/{backfillMetadataPropertyIds-BzbAB-C5.js → backfillMetadataPropertyIds-CBsf7LnU.js} +5 -3
  12. package/dist/{backfillMetadataPropertyIds-BzbAB-C5.js.map → backfillMetadataPropertyIds-CBsf7LnU.js.map} +1 -1
  13. package/dist/cjs/{ModelProperty-CDTOx5zi.js → ModelProperty-D9FGaGuE.js} +21 -17
  14. package/dist/cjs/ModelProperty-D9FGaGuE.js.map +1 -0
  15. package/dist/cjs/{Schema-XXcwj3hV.js → Schema-BiJIPLEL.js} +25 -24
  16. package/dist/cjs/Schema-BiJIPLEL.js.map +1 -0
  17. package/dist/cjs/{SchemaValidationService-Z7OhtGn5.js → SchemaValidationService-DtYs_CNY.js} +5 -3
  18. package/dist/cjs/SchemaValidationService-DtYs_CNY.js.map +1 -0
  19. package/dist/cjs/{backfillMetadataPropertyIds-Bt4fzfIV.js → backfillMetadataPropertyIds-2XaN3b9S.js} +3 -2
  20. package/dist/cjs/{backfillMetadataPropertyIds-Bt4fzfIV.js.map → backfillMetadataPropertyIds-2XaN3b9S.js.map} +1 -1
  21. package/dist/cjs/{eas-DdI-4vwl.js → eas-CMNppmGE.js} +4 -3
  22. package/dist/cjs/{eas-DdI-4vwl.js.map → eas-CMNppmGE.js.map} +1 -1
  23. package/dist/cjs/{getItem-B_2GeTQf.js → getItem-B6jEINjW.js} +3 -2
  24. package/dist/cjs/{getItem-B_2GeTQf.js.map → getItem-B6jEINjW.js.map} +1 -1
  25. package/dist/cjs/{getPublishPayload-Jmgi1RUj.js → getPublishPayload-D5DhLGvN.js} +64 -59
  26. package/dist/cjs/getPublishPayload-D5DhLGvN.js.map +1 -0
  27. package/dist/cjs/{getPublishUploads-DNULcrN5.js → getPublishUploads-DMhCCKYF.js} +17 -10
  28. package/dist/cjs/getPublishUploads-DMhCCKYF.js.map +1 -0
  29. package/dist/cjs/{getSegmentedItemProperties-DK82kjri.js → getSegmentedItemProperties-CU8rtBAo.js} +3 -51
  30. package/dist/cjs/getSegmentedItemProperties-CU8rtBAo.js.map +1 -0
  31. package/dist/cjs/{index-DM1WR83P.js → index-CSNtEnbF.js} +879 -467
  32. package/dist/cjs/index-CSNtEnbF.js.map +1 -0
  33. package/dist/cjs/{index-tpO1Nj4v.js → index-DPp9rdRL.js} +6 -3
  34. package/dist/cjs/index-DPp9rdRL.js.map +1 -0
  35. package/dist/cjs/{property-DmvgA8FD.js → property-DlKiAWt4.js} +7 -4
  36. package/dist/cjs/{property-DmvgA8FD.js.map → property-DlKiAWt4.js.map} +1 -1
  37. package/dist/cjs/{syncDbWithEas-3hOoPdu1.js → syncDbWithEas-C6n34o_Q.js} +11 -6
  38. package/dist/cjs/syncDbWithEas-C6n34o_Q.js.map +1 -0
  39. package/dist/{configurePlatform-CCYQruij.js → configurePlatform-CE0Vew17.js} +5 -5
  40. package/dist/{configurePlatform-CCYQruij.js.map → configurePlatform-CE0Vew17.js.map} +1 -1
  41. package/dist/db/drizzle/0014_add_error_code_to_publish_processes.sql +1 -0
  42. package/dist/db/drizzle/meta/0014_snapshot.json +1269 -0
  43. package/dist/db/drizzle/meta/_journal.json +7 -0
  44. package/dist/{db-CceyWksv.js → db-WbrzEf7c.js} +254 -35
  45. package/dist/db-WbrzEf7c.js.map +1 -0
  46. package/dist/{eas-CH8iFIST.js → eas-CfYCu4IX.js} +6 -6
  47. package/dist/{eas-CH8iFIST.js.map → eas-CfYCu4IX.js.map} +1 -1
  48. package/dist/{getItem-C7Mtfz6O.js → getItem-Br-bGNFO.js} +6 -6
  49. package/dist/{getItem-C7Mtfz6O.js.map → getItem-Br-bGNFO.js.map} +1 -1
  50. package/dist/{getPublishPayload-2gnnDdMh.js → getPublishPayload-BIrTVUxb.js} +66 -62
  51. package/dist/getPublishPayload-BIrTVUxb.js.map +1 -0
  52. package/dist/{getPublishUploads-AKISt3JA.js → getPublishUploads-C6cDeZdz.js} +19 -13
  53. package/dist/getPublishUploads-C6cDeZdz.js.map +1 -0
  54. package/dist/{getSegmentedItemProperties-eIjvhCP_.js → getSegmentedItemProperties-BmKE71vU.js} +5 -5
  55. package/dist/{getSegmentedItemProperties-eIjvhCP_.js.map → getSegmentedItemProperties-BmKE71vU.js.map} +1 -1
  56. package/dist/{constants-DSqHBPNe.js → index-280bL-n4.js} +32 -257
  57. package/dist/index-280bL-n4.js.map +1 -0
  58. package/dist/{index-CHi212ST.js → index-ClSv5pTA.js} +13 -13
  59. package/dist/index-ClSv5pTA.js.map +1 -0
  60. package/dist/{index-CsmiM0RI.js → index-Djd3667v.js} +2 -2
  61. package/dist/index-Djd3667v.js.map +1 -0
  62. package/dist/{index-BFpbtEsg.js → index-HRHkbVQd.js} +24 -24
  63. package/dist/{index-BFpbtEsg.js.map → index-HRHkbVQd.js.map} +1 -1
  64. package/dist/{index.node-CbWB4MDz.js → index.node-DBtQkEfz.js} +8 -6
  65. package/dist/index.node-DBtQkEfz.js.map +1 -0
  66. package/dist/main.cjs +6 -1
  67. package/dist/main.cjs.map +1 -1
  68. package/dist/main.js +36 -38
  69. package/dist/main.js.map +1 -1
  70. package/dist/node.js +15 -14
  71. package/dist/node.js.map +1 -1
  72. package/dist/platform.browser.js +108 -46
  73. package/dist/platform.browser.js.map +1 -1
  74. package/dist/platform.node.js +4 -3
  75. package/dist/platform.node.js.map +1 -1
  76. package/dist/{property-CWKcZ5YZ.js → property-CQjuZ4JW.js} +14 -13
  77. package/dist/property-CQjuZ4JW.js.map +1 -0
  78. package/dist/seedSchema/PublishProcessSchema.ts +1 -0
  79. package/dist/src/Item/Item.d.ts +6 -0
  80. package/dist/src/Item/Item.d.ts.map +1 -1
  81. package/dist/src/Item/service/actors/loadOrCreateItem.d.ts.map +1 -1
  82. package/dist/src/ItemProperty/ItemProperty.d.ts +10 -1
  83. package/dist/src/ItemProperty/ItemProperty.d.ts.map +1 -1
  84. package/dist/src/ItemProperty/service/actors/resolveRelatedValue.d.ts.map +1 -1
  85. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveRelation.d.ts.map +1 -1
  86. package/dist/src/ItemProperty/service/propertyMachine.d.ts.map +1 -1
  87. package/dist/src/ModelProperty/ModelProperty.d.ts.map +1 -1
  88. package/dist/src/Schema/service/actors/loadOrCreateSchema.d.ts.map +1 -1
  89. package/dist/src/Schema/service/actors/writeModelsToDb.d.ts.map +1 -1
  90. package/dist/src/Schema/service/addModelsMachine.d.ts.map +1 -1
  91. package/dist/src/Schema/service/validation/SchemaValidationService.d.ts.map +1 -1
  92. package/dist/src/browser/db/drizzleFiles.d.ts +3 -2
  93. package/dist/src/browser/db/drizzleFiles.d.ts.map +1 -1
  94. package/dist/src/browser/helpers/ArweaveClient.d.ts.map +1 -1
  95. package/dist/src/browser/helpers/EasClient.d.ts +2 -1
  96. package/dist/src/browser/helpers/EasClient.d.ts.map +1 -1
  97. package/dist/src/browser/helpers/FileManager.d.ts +1 -1
  98. package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
  99. package/dist/src/browser/workers/FileDownloader.d.ts +1 -1
  100. package/dist/src/browser/workers/FileDownloader.d.ts.map +1 -1
  101. package/dist/src/browser/workers/filesDownload.d.ts.map +1 -1
  102. package/dist/src/client/actors/platformClassesInit.d.ts.map +1 -1
  103. package/dist/src/client/actors/saveConfig.d.ts.map +1 -1
  104. package/dist/src/client/constants.d.ts +4 -0
  105. package/dist/src/client/constants.d.ts.map +1 -1
  106. package/dist/src/client/nodeEndpointDefaults.d.ts +8 -0
  107. package/dist/src/client/nodeEndpointDefaults.d.ts.map +1 -0
  108. package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
  109. package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
  110. package/dist/src/db/read/getRelatedItemsForPublish.d.ts.map +1 -1
  111. package/dist/src/db/write/createMetadata.d.ts.map +1 -1
  112. package/dist/src/events/files/download.d.ts.map +1 -1
  113. package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
  114. package/dist/src/helpers/ArweaveClient/index.d.ts.map +1 -1
  115. package/dist/src/helpers/FileManager/BaseFileManager.d.ts +2 -2
  116. package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
  117. package/dist/src/helpers/FileManager/IFileManager.d.ts +4 -0
  118. package/dist/src/helpers/FileManager/IFileManager.d.ts.map +1 -1
  119. package/dist/src/helpers/constants.d.ts +8 -0
  120. package/dist/src/helpers/constants.d.ts.map +1 -1
  121. package/dist/src/helpers/db.d.ts +6 -0
  122. package/dist/src/helpers/db.d.ts.map +1 -1
  123. package/dist/src/helpers/gateway/gatewayState.d.ts +1 -1
  124. package/dist/src/helpers/gateway/gatewayState.d.ts.map +1 -1
  125. package/dist/src/helpers/localDbChain.d.ts +22 -0
  126. package/dist/src/helpers/localDbChain.d.ts.map +1 -0
  127. package/dist/src/helpers/metadataPropertyNames.d.ts +9 -0
  128. package/dist/src/helpers/metadataPropertyNames.d.ts.map +1 -1
  129. package/dist/src/helpers/property/index.d.ts +12 -0
  130. package/dist/src/helpers/property/index.d.ts.map +1 -1
  131. package/dist/src/helpers/readHtmlBodyForStorageSeed.d.ts.map +1 -1
  132. package/dist/src/helpers/relationSeedRef.d.ts +8 -0
  133. package/dist/src/helpers/relationSeedRef.d.ts.map +1 -1
  134. package/dist/src/index.d.ts +9 -5
  135. package/dist/src/index.d.ts.map +1 -1
  136. package/dist/src/node/easLodashHook.d.ts +2 -0
  137. package/dist/src/node/easLodashHook.d.ts.map +1 -0
  138. package/dist/src/node/easLodashRegister.d.ts +2 -0
  139. package/dist/src/node/easLodashRegister.d.ts.map +1 -0
  140. package/dist/src/node/helpers/FileManager.d.ts +2 -1
  141. package/dist/src/node/helpers/FileManager.d.ts.map +1 -1
  142. package/dist/src/node/index.d.ts +2 -1
  143. package/dist/src/node/index.d.ts.map +1 -1
  144. package/dist/src/seedSchema/PublishProcessSchema.d.ts +19 -0
  145. package/dist/src/seedSchema/PublishProcessSchema.d.ts.map +1 -1
  146. package/dist/src/types/fileManager.d.ts +4 -0
  147. package/dist/src/types/fileManager.d.ts.map +1 -1
  148. package/dist/src/types/index.d.ts +15 -1
  149. package/dist/src/types/index.d.ts.map +1 -1
  150. package/dist/{syncDbWithEas-5kZneTEL.js → syncDbWithEas-CuARXfyN.js} +16 -12
  151. package/dist/syncDbWithEas-CuARXfyN.js.map +1 -0
  152. package/dist/{updateSeedRevokedAt-CgfOBtqJ.js → updateSeedRevokedAt-CBcLfHWs.js} +2 -2
  153. package/dist/{updateSeedRevokedAt-CgfOBtqJ.js.map → updateSeedRevokedAt-CBcLfHWs.js.map} +1 -1
  154. package/package.json +11 -7
  155. package/src/node/easLodashHook.js +22 -0
  156. package/src/node/easLodashRegister.js +13 -0
  157. package/dist/BasePathResolver-qV0apdVY.js.map +0 -1
  158. package/dist/ClientManager-Y5EWQuJj.js.map +0 -1
  159. package/dist/ModelProperty-DuB5nk6A.js.map +0 -1
  160. package/dist/Schema-BYM-GNdE.js.map +0 -1
  161. package/dist/SchemaValidationService-Dr6nmwPm.js.map +0 -1
  162. package/dist/cjs/ModelProperty-CDTOx5zi.js.map +0 -1
  163. package/dist/cjs/Schema-XXcwj3hV.js.map +0 -1
  164. package/dist/cjs/SchemaValidationService-Z7OhtGn5.js.map +0 -1
  165. package/dist/cjs/getPublishPayload-Jmgi1RUj.js.map +0 -1
  166. package/dist/cjs/getPublishUploads-DNULcrN5.js.map +0 -1
  167. package/dist/cjs/getSegmentedItemProperties-DK82kjri.js.map +0 -1
  168. package/dist/cjs/index-DM1WR83P.js.map +0 -1
  169. package/dist/cjs/index-tpO1Nj4v.js.map +0 -1
  170. package/dist/cjs/syncDbWithEas-3hOoPdu1.js.map +0 -1
  171. package/dist/constants-DSqHBPNe.js.map +0 -1
  172. package/dist/db-CceyWksv.js.map +0 -1
  173. package/dist/getPublishPayload-2gnnDdMh.js.map +0 -1
  174. package/dist/getPublishUploads-AKISt3JA.js.map +0 -1
  175. package/dist/index-CHi212ST.js.map +0 -1
  176. package/dist/index-CsmiM0RI.js.map +0 -1
  177. package/dist/index.node-CbWB4MDz.js.map +0 -1
  178. package/dist/property-CWKcZ5YZ.js.map +0 -1
  179. package/dist/seedSchema/AppStateSchema.d.ts +0 -82
  180. package/dist/seedSchema/AppStateSchema.d.ts.map +0 -1
  181. package/dist/seedSchema/ConfigSchema.d.ts +0 -101
  182. package/dist/seedSchema/ConfigSchema.d.ts.map +0 -1
  183. package/dist/seedSchema/MetadataSchema.d.ts +0 -422
  184. package/dist/seedSchema/MetadataSchema.d.ts.map +0 -1
  185. package/dist/seedSchema/ModelSchema.d.ts +0 -243
  186. package/dist/seedSchema/ModelSchema.d.ts.map +0 -1
  187. package/dist/seedSchema/ModelSchemaSchema.d.ts +0 -61
  188. package/dist/seedSchema/ModelSchemaSchema.d.ts.map +0 -1
  189. package/dist/seedSchema/ModelUidSchema.d.ts +0 -64
  190. package/dist/seedSchema/ModelUidSchema.d.ts.map +0 -1
  191. package/dist/seedSchema/PropertyUidSchema.d.ts +0 -64
  192. package/dist/seedSchema/PropertyUidSchema.d.ts.map +0 -1
  193. package/dist/seedSchema/SchemaSchema.d.ts +0 -169
  194. package/dist/seedSchema/SchemaSchema.d.ts.map +0 -1
  195. package/dist/seedSchema/SeedSchema.d.ts +0 -192
  196. package/dist/seedSchema/SeedSchema.d.ts.map +0 -1
  197. package/dist/seedSchema/VersionSchema.d.ts +0 -194
  198. package/dist/seedSchema/VersionSchema.d.ts.map +0 -1
  199. package/dist/seedSchema/index.d.ts +0 -14
  200. package/dist/seedSchema/index.d.ts.map +0 -1
  201. package/dist/syncDbWithEas-5kZneTEL.js.map +0 -1
@@ -99,6 +99,13 @@
99
99
  "when": 1774300000000,
100
100
  "tag": "0013_eas_sync_processes",
101
101
  "breakpoints": true
102
+ },
103
+ {
104
+ "idx": 14,
105
+ "version": "6",
106
+ "when": 1774400000000,
107
+ "tag": "0014_add_error_code_to_publish_processes",
108
+ "breakpoints": true
102
109
  }
103
110
  ]
104
111
  }
@@ -1,8 +1,218 @@
1
- import { a as BaseDb, c as appState, m as models, i as modelSchemas, p as properties, s as schemas, b as metadata } from './BasePathResolver-qV0apdVY.js';
1
+ import { a as BaseDb, c as appState, m as models, i as modelSchemas, p as properties, s as schemas, b as metadata } from './BasePathResolver-B6CKqoKw.js';
2
2
  import { toSnakeCase } from 'drizzle-orm/casing';
3
3
  import { eq, and, isNull } from 'drizzle-orm';
4
4
  import { upperFirst, camelCase } from 'lodash-es';
5
5
  import debug from 'debug';
6
+ import 'pluralize';
7
+ import { Type } from '@sinclair/typebox';
8
+
9
+ /** Default maximum length for Text properties when not explicitly set. Html holds arbitrary-length content and does not use this limit. */
10
+ const DEFAULT_TEXT_MAX_LENGTH = 255;
11
+ /**
12
+ * TypeBox schema for ValidationRules
13
+ */
14
+ const TValidationRules = Type.Object({
15
+ pattern: Type.Optional(Type.String()),
16
+ minLength: Type.Optional(Type.Integer({ minimum: 0 })),
17
+ maxLength: Type.Optional(Type.Integer({ minimum: 1 })),
18
+ enum: Type.Optional(Type.Array(Type.Any())),
19
+ custom: Type.Optional(Type.String()),
20
+ }, { additionalProperties: true });
21
+
22
+ /**
23
+ * Enum for all property data types
24
+ */
25
+ var ModelPropertyDataTypes;
26
+ (function (ModelPropertyDataTypes) {
27
+ ModelPropertyDataTypes["Text"] = "Text";
28
+ ModelPropertyDataTypes["Number"] = "Number";
29
+ ModelPropertyDataTypes["List"] = "List";
30
+ ModelPropertyDataTypes["Relation"] = "Relation";
31
+ ModelPropertyDataTypes["Image"] = "Image";
32
+ ModelPropertyDataTypes["Json"] = "Json";
33
+ ModelPropertyDataTypes["File"] = "File";
34
+ ModelPropertyDataTypes["Boolean"] = "Boolean";
35
+ ModelPropertyDataTypes["Date"] = "Date";
36
+ ModelPropertyDataTypes["Html"] = "Html";
37
+ })(ModelPropertyDataTypes || (ModelPropertyDataTypes = {}));
38
+ /** Known data types in lowercase for normalization */
39
+ const DATA_TYPE_LOWER_MAP = {
40
+ text: 'Text',
41
+ string: 'Text', // JSON Schema convention
42
+ number: 'Number',
43
+ list: 'List',
44
+ relation: 'Relation',
45
+ image: 'Image',
46
+ json: 'Json',
47
+ file: 'File',
48
+ boolean: 'Boolean',
49
+ date: 'Date',
50
+ html: 'Html',
51
+ blob: 'Blob',
52
+ };
53
+ /**
54
+ * Normalize dataType to canonical PascalCase form.
55
+ * Accepts lowercase (e.g. 'text') or mixed case and returns 'Text'.
56
+ * Use when ingesting dataType from JSON schema files.
57
+ */
58
+ function normalizeDataType(value) {
59
+ if (!value || typeof value !== 'string')
60
+ return value ?? '';
61
+ const lower = value.toLowerCase().trim();
62
+ return DATA_TYPE_LOWER_MAP[lower] ?? value.charAt(0).toUpperCase() + value.slice(1).toLowerCase();
63
+ }
64
+ /**
65
+ * Case-insensitive dataType check. Use instead of `dataType === 'List'` so schemas
66
+ * (or existing DB rows) with lowercase types like "list" still match.
67
+ */
68
+ function isDataType(value, expected) {
69
+ if (!value)
70
+ return false;
71
+ return normalizeDataType(value) === expected;
72
+ }
73
+ /**
74
+ * Normalize a property definition to the internal shape ItemProperty reads (`dataType`,
75
+ * `refValueType`, `ref`, `storageType`, ...). Accepts schema-file shape (`type`, `model`,
76
+ * `items`, `storage`) and any casing. Mirrors the conversion in imports/json createModelFromJson
77
+ * for the fallback paths that read schema-file properties directly.
78
+ */
79
+ function normalizePropertyRecordSchema(def) {
80
+ if (!def || typeof def !== 'object')
81
+ return def;
82
+ const src = def;
83
+ const out = { ...src };
84
+ const rawType = src.dataType ?? src.type;
85
+ if (typeof rawType === 'string' && rawType)
86
+ out.dataType = normalizeDataType(rawType);
87
+ const ref = src.ref ?? src.refModelName ?? src.items?.model ?? src.model;
88
+ if (ref && !out.ref)
89
+ out.ref = ref;
90
+ if (ref && !out.refModelName)
91
+ out.refModelName = ref;
92
+ const rawRefValueType = src.refValueType ?? src.items?.type;
93
+ if (typeof rawRefValueType === 'string' && rawRefValueType) {
94
+ out.refValueType = normalizeDataType(rawRefValueType);
95
+ }
96
+ else if (out.dataType === ModelPropertyDataTypes.List && ref) {
97
+ out.refValueType = ModelPropertyDataTypes.Relation;
98
+ }
99
+ if (src.storage && typeof src.storage === 'object' && !out.storageType) {
100
+ out.storageType = src.storage.type === 'ItemStorage' ? 'ItemStorage' : 'PropertyStorage';
101
+ if (src.storage.path !== undefined && out.localStorageDir === undefined)
102
+ out.localStorageDir = src.storage.path;
103
+ if (src.storage.extension !== undefined && out.filenameSuffix === undefined)
104
+ out.filenameSuffix = src.storage.extension;
105
+ }
106
+ return out;
107
+ }
108
+ const TPropertyDataType = Type.Union([
109
+ Type.Literal(ModelPropertyDataTypes.Text),
110
+ Type.Literal(ModelPropertyDataTypes.Number),
111
+ Type.Literal(ModelPropertyDataTypes.List),
112
+ Type.Literal(ModelPropertyDataTypes.Relation),
113
+ Type.Literal(ModelPropertyDataTypes.Image),
114
+ Type.Literal(ModelPropertyDataTypes.Json),
115
+ Type.Literal(ModelPropertyDataTypes.File),
116
+ Type.Literal(ModelPropertyDataTypes.Boolean),
117
+ Type.Literal(ModelPropertyDataTypes.Date),
118
+ Type.Literal(ModelPropertyDataTypes.Html),
119
+ ]);
120
+ const TStorageType = Type.Union([
121
+ Type.Literal('ItemStorage'), // Looks for a storageTransactionId property on the item
122
+ Type.Literal('PropertyStorage'), // Looks for a storageTransactionId value on the property
123
+ ]);
124
+ /** How publish handles `data:image/*` URIs inside Html storage. Only applies when `dataType === 'Html'`. */
125
+ const THtmlEmbeddedDataUriPolicy = Type.Union([
126
+ Type.Literal('materialize'),
127
+ Type.Literal('preserve'),
128
+ ]);
129
+ const TProperty = Type.Object({
130
+ id: Type.Optional(Type.String()), // schemaFileId (string) - public ID
131
+ _dbId: Type.Optional(Type.Number()), // Database integer ID - internal only
132
+ name: Type.Optional(Type.String()),
133
+ dataType: TPropertyDataType,
134
+ ref: Type.Optional(Type.String()),
135
+ // modelId: string (modelFileId) in code; number only for DB foreign keys when resolved
136
+ modelId: Type.Optional(Type.Union([Type.Number(), Type.String()])),
137
+ modelName: Type.Optional(Type.String()),
138
+ refModelId: Type.Optional(Type.Number()),
139
+ refModelName: Type.Optional(Type.String()),
140
+ refValueType: Type.Optional(TPropertyDataType),
141
+ storageType: Type.Optional(TStorageType),
142
+ localStorageDir: Type.Optional(Type.String()),
143
+ filenameSuffix: Type.Optional(Type.String()),
144
+ validation: Type.Optional(TValidationRules),
145
+ required: Type.Optional(Type.Boolean()),
146
+ /** When set on an Html property: `materialize` uploads embedded images as Image seeds and rewrites src; `preserve` leaves data URIs. */
147
+ htmlEmbeddedDataUriPolicy: Type.Optional(THtmlEmbeddedDataUriPolicy),
148
+ });
149
+ const TPropertyConstructor = Type.Function([
150
+ Type.Optional(Type.Union([Type.String(), TStorageType, Type.Undefined()])),
151
+ Type.Optional(Type.Union([Type.String(), TPropertyDataType])),
152
+ Type.Optional(Type.Union([Type.String(), Type.Boolean()])),
153
+ ], TProperty);
154
+ const TPropertyDefs = Type.Record(TPropertyDataType, TPropertyConstructor);
155
+ function htmlPropertyFactory(opts) {
156
+ return {
157
+ dataType: ModelPropertyDataTypes.Html,
158
+ ...(opts?.htmlEmbeddedDataUriPolicy
159
+ ? { htmlEmbeddedDataUriPolicy: opts.htmlEmbeddedDataUriPolicy }
160
+ : {}),
161
+ };
162
+ }
163
+ const Property = {
164
+ Text: (storageType, localStorageDir, filenameSuffix) => ({
165
+ dataType: ModelPropertyDataTypes.Text,
166
+ storageType,
167
+ localStorageDir,
168
+ filenameSuffix,
169
+ TObject: Type.String(),
170
+ }),
171
+ Json: () => ({ dataType: ModelPropertyDataTypes.Json }),
172
+ File: () => ({ dataType: ModelPropertyDataTypes.File }),
173
+ Number: () => ({ dataType: ModelPropertyDataTypes.Number }),
174
+ /**
175
+ * Create a List property. refValueType is required; ref is required only for list of relations.
176
+ * @param refValueType - Element type: 'Text', 'Number', 'Relation', etc.
177
+ * @param ref - Model name when refValueType is 'Relation' (optional for primitives)
178
+ * @example List('Text') - list of strings
179
+ * @example List('Relation', 'Tag') - list of relations to Tag model
180
+ */
181
+ List: (refValueType, ref) => ({
182
+ dataType: ModelPropertyDataTypes.List,
183
+ ref,
184
+ refValueType,
185
+ }),
186
+ Relation: (ref, refValueType, required) => ({
187
+ dataType: ModelPropertyDataTypes.Relation,
188
+ ref,
189
+ refValueType,
190
+ required,
191
+ }),
192
+ Image: () => ({ dataType: ModelPropertyDataTypes.Image }),
193
+ Boolean: () => ({ dataType: ModelPropertyDataTypes.Boolean }),
194
+ Date: () => ({ dataType: ModelPropertyDataTypes.Date }),
195
+ Html: htmlPropertyFactory,
196
+ /** `Html` opts are not representable in `TPropertyConstructor`; keep runtime shape via double assert. */
197
+ };
198
+ const PropertyMetadataKey = Symbol('property');
199
+ const PropertyConstructor = (propertyType) => {
200
+ return function (parentClassPrototype, propertyKey) {
201
+ const existingProperties = Reflect.getMetadata(PropertyMetadataKey, parentClassPrototype) || [];
202
+ existingProperties.push({ propertyKey, propertyType });
203
+ Reflect.defineMetadata(PropertyMetadataKey, existingProperties, parentClassPrototype);
204
+ };
205
+ };
206
+ const Text = (storageType, srcDir, filenameSuffix) => PropertyConstructor(Property.Text(storageType, srcDir, filenameSuffix));
207
+ const Number$1 = () => PropertyConstructor(Property.Number());
208
+ const Json = () => PropertyConstructor(Property.Json());
209
+ const File = () => PropertyConstructor(Property.File());
210
+ const Image = () => PropertyConstructor(Property.Image());
211
+ const Relation = (ref, refValueType, required) => PropertyConstructor(Property.Relation(ref, refValueType, required)); // Adjust for actual relation type
212
+ const List = (refValueType, ref) => PropertyConstructor(Property.List(refValueType, ref));
213
+ const Boolean = () => PropertyConstructor(Property.Boolean());
214
+ const Date$1 = () => PropertyConstructor(Property.Date());
215
+ const Html = (opts) => PropertyConstructor(htmlPropertyFactory(opts));
6
216
 
7
217
  /**
8
218
  * Detect SQLite UNIQUE constraint failures across better-sqlite3 and drizzle/wasm wrappers.
@@ -109,6 +319,23 @@ function normalizeAddressConfig(addresses) {
109
319
  }
110
320
 
111
321
  const logger = debug('seedSdk:helpers:db');
322
+ /**
323
+ * Resolve property_id (integer properties.id) from a property's schemaFileId (the string `id` in
324
+ * schema files and propertyRecordSchema). Scoped to the model since schemaFileIds are per schema file.
325
+ * @returns properties.id or null if not found
326
+ */
327
+ async function getPropertyIdForSchemaFileId(modelNameOrType, schemaFileId) {
328
+ const db = BaseDb.getAppDb();
329
+ if (!db || !modelNameOrType || !schemaFileId)
330
+ return null;
331
+ const rows = await db
332
+ .select({ id: properties.id })
333
+ .from(properties)
334
+ .innerJoin(models, eq(properties.modelId, models.id))
335
+ .where(and(eq(models.name, upperFirst(camelCase(modelNameOrType))), eq(properties.schemaFileId, schemaFileId)))
336
+ .limit(1);
337
+ return rows[0]?.id ?? null;
338
+ }
112
339
  /**
113
340
  * Resolve property_id from model name/type and property name.
114
341
  * Handles property name variants (e.g. htmlId -> html, avatarImageIds -> avatarImages).
@@ -159,19 +386,10 @@ async function migrateMetadataForPropertyRename(modelName, oldPropertyName, newP
159
386
  logger('[migrateMetadataForPropertyRename] Database not available, skipping');
160
387
  return 0;
161
388
  }
162
- const normalizedModelName = upperFirst(camelCase(modelName));
163
389
  // Find the property row by schemaFileId (preferred) or by name
164
390
  let propertyId = null;
165
391
  if (propertySchemaFileId) {
166
- const rows = await db
167
- .select({ id: properties.id })
168
- .from(properties)
169
- .innerJoin(models, eq(properties.modelId, models.id))
170
- .where(and(eq(models.name, normalizedModelName), eq(properties.schemaFileId, propertySchemaFileId)))
171
- .limit(1);
172
- if (rows.length > 0 && rows[0].id != null) {
173
- propertyId = rows[0].id;
174
- }
392
+ propertyId = await getPropertyIdForSchemaFileId(modelName, propertySchemaFileId);
175
393
  }
176
394
  if (propertyId == null) {
177
395
  propertyId = await getPropertyIdForModelAndName(modelName, oldPropertyName);
@@ -653,8 +871,8 @@ const renameModelInDb = async (oldName, newName, schemaNameOrId) => {
653
871
  if (!db) {
654
872
  throw new Error('Database not found');
655
873
  }
656
- const _mod_0 = await import('./BasePathResolver-qV0apdVY.js');
657
- const _ns_0 = _mod_0.L;
874
+ const _mod_0 = await import('./BasePathResolver-B6CKqoKw.js');
875
+ const _ns_0 = _mod_0.O;
658
876
  const { schemas: schemasTable } = _ns_0;
659
877
  // Find the model by old name, optionally scoped by schema
660
878
  let existingModels;
@@ -973,7 +1191,7 @@ const addModelsToDb = async (models$1, schema, modelRenames, schemaFileData) =>
973
1191
  const propertyData = {
974
1192
  name: propertyName,
975
1193
  modelId: modelRecord.id,
976
- dataType: propertyValues.dataType,
1194
+ dataType: normalizeDataType(propertyValues.dataType),
977
1195
  schemaFileId: propertyFileId || null,
978
1196
  required: propertyValues.required ?? false,
979
1197
  };
@@ -999,7 +1217,7 @@ const addModelsToDb = async (models$1, schema, modelRenames, schemaFileData) =>
999
1217
  propertyData.refModelId = null;
1000
1218
  }
1001
1219
  if (propertyValues.refValueType) {
1002
- propertyData.refValueType = propertyValues.refValueType;
1220
+ propertyData.refValueType = normalizeDataType(propertyValues.refValueType);
1003
1221
  }
1004
1222
  else {
1005
1223
  // If refValueType is not set, ensure it's null
@@ -1194,7 +1412,7 @@ const loadModelsFromDbForSchema = async (schemaId) => {
1194
1412
  // Note: This is a simplified reconstruction - full property schemas
1195
1413
  // (like Relation details, List configs, etc.) should come from schemaData
1196
1414
  const propertyData = {
1197
- dataType: prop.dataType,
1415
+ dataType: normalizeDataType(prop.dataType ?? undefined),
1198
1416
  };
1199
1417
  if (prop.schemaFileId) {
1200
1418
  propertyData.schemaFileId = prop.schemaFileId;
@@ -1212,7 +1430,7 @@ const loadModelsFromDbForSchema = async (schemaId) => {
1212
1430
  }
1213
1431
  }
1214
1432
  if (prop.refValueType) {
1215
- propertyData.refValueType = prop.refValueType;
1433
+ propertyData.refValueType = normalizeDataType(prop.refValueType ?? undefined);
1216
1434
  }
1217
1435
  modelProperties[prop.name] = propertyData;
1218
1436
  }
@@ -1384,7 +1602,7 @@ const savePropertyToDb = async (property) => {
1384
1602
  const propertyData = {
1385
1603
  name: property.name,
1386
1604
  modelId: modelRecord.id,
1387
- dataType: property.dataType || '',
1605
+ dataType: normalizeDataType(property.dataType),
1388
1606
  };
1389
1607
  // Preserve schemaFileId if we have it
1390
1608
  if (schemaFileId) {
@@ -1405,7 +1623,7 @@ const savePropertyToDb = async (property) => {
1405
1623
  propertyData.refModelId = null;
1406
1624
  }
1407
1625
  if (property.refValueType) {
1408
- propertyData.refValueType = property.refValueType;
1626
+ propertyData.refValueType = normalizeDataType(property.refValueType);
1409
1627
  }
1410
1628
  else {
1411
1629
  // If refValueType is not set, ensure it's null
@@ -1633,8 +1851,8 @@ async function writeModelToDb(modelFileId, data) {
1633
1851
  throw new Error(`Model with id ${modelId} does not exist in database. Cannot create join record.`);
1634
1852
  }
1635
1853
  // Verify schemaId exists and get name/fileId for invalidation broadcast
1636
- const _mod_1 = await import('./BasePathResolver-qV0apdVY.js');
1637
- const _ns_1 = _mod_1.L;
1854
+ const _mod_1 = await import('./BasePathResolver-B6CKqoKw.js');
1855
+ const _ns_1 = _mod_1.O;
1638
1856
  const schemaSchemaMod = _ns_1;
1639
1857
  const { schemas: schemasTable } = schemaSchemaMod;
1640
1858
  const schemaCheck = await db
@@ -1743,7 +1961,7 @@ async function writePropertyToDb(propertyFileId, data, isEdited = false) {
1743
1961
  const propertyData = {
1744
1962
  name: data.name,
1745
1963
  modelId: data.modelId,
1746
- dataType: data.dataType || '',
1964
+ dataType: normalizeDataType(data.dataType),
1747
1965
  schemaFileId: propertyFileId,
1748
1966
  isEdited: isEdited, // Persist isEdited flag
1749
1967
  };
@@ -1764,7 +1982,7 @@ async function writePropertyToDb(propertyFileId, data, isEdited = false) {
1764
1982
  propertyData.refModelId = null;
1765
1983
  }
1766
1984
  if (data.refValueType) {
1767
- propertyData.refValueType = data.refValueType;
1985
+ propertyData.refValueType = normalizeDataType(data.refValueType);
1768
1986
  }
1769
1987
  else {
1770
1988
  // If refValueType is not set, ensure it's null
@@ -1843,8 +2061,8 @@ async function getSchemaId(schemaNameOrFileId) {
1843
2061
  if (!db) {
1844
2062
  throw new Error('Database not available');
1845
2063
  }
1846
- const _mod_2 = await import('./BasePathResolver-qV0apdVY.js');
1847
- const _ns_2 = _mod_2.L;
2064
+ const _mod_2 = await import('./BasePathResolver-B6CKqoKw.js');
2065
+ const _ns_2 = _mod_2.O;
1848
2066
  const schemaSchemaMod = _ns_2;
1849
2067
  const { schemas: schemasTable } = schemaSchemaMod;
1850
2068
  const drizzleMod = await import('drizzle-orm');
@@ -1881,8 +2099,8 @@ async function getSchemaIdByFileId(schemaFileId) {
1881
2099
  if (!db) {
1882
2100
  throw new Error('Database not available');
1883
2101
  }
1884
- const _mod_3 = await import('./BasePathResolver-qV0apdVY.js');
1885
- const _ns_3 = _mod_3.L;
2102
+ const _mod_3 = await import('./BasePathResolver-B6CKqoKw.js');
2103
+ const _ns_3 = _mod_3.O;
1886
2104
  const schemaSchemaMod = _ns_3;
1887
2105
  const { schemas: schemasTable } = schemaSchemaMod;
1888
2106
  const drizzleMod = await import('drizzle-orm');
@@ -1910,7 +2128,7 @@ async function getModelId(modelNameOrFileId, schemaNameOrId) {
1910
2128
  if (!db) {
1911
2129
  throw new Error('Database not available');
1912
2130
  }
1913
- const _mod_4 = await import('./BasePathResolver-qV0apdVY.js');
2131
+ const _mod_4 = await import('./BasePathResolver-B6CKqoKw.js');
1914
2132
  const _ns_4 = _mod_4.M;
1915
2133
  const modelSchemaMod = _ns_4;
1916
2134
  const { models: modelsTable } = modelSchemaMod;
@@ -1927,12 +2145,12 @@ async function getModelId(modelNameOrFileId, schemaNameOrId) {
1927
2145
  [eq(modelsTable.name, modelNameOrFileId)];
1928
2146
  // If schema is provided, narrow the search
1929
2147
  if (schemaNameOrId !== undefined) {
1930
- const _mod_5 = await import('./BasePathResolver-qV0apdVY.js');
1931
- const _ns_5 = _mod_5.N;
2148
+ const _mod_5 = await import('./BasePathResolver-B6CKqoKw.js');
2149
+ const _ns_5 = _mod_5.Q;
1932
2150
  const modelSchemaSchemaMod = _ns_5;
1933
2151
  const { modelSchemas } = modelSchemaSchemaMod;
1934
- const _mod_6 = await import('./BasePathResolver-qV0apdVY.js');
1935
- const _ns_6 = _mod_6.L;
2152
+ const _mod_6 = await import('./BasePathResolver-B6CKqoKw.js');
2153
+ const _ns_6 = _mod_6.O;
1936
2154
  const schemaSchemaMod = _ns_6;
1937
2155
  const { schemas: schemasTable } = schemaSchemaMod;
1938
2156
  if (typeof schemaNameOrId === 'number') {
@@ -1981,7 +2199,7 @@ async function getModelIdByFileId(modelFileId) {
1981
2199
  if (!db) {
1982
2200
  throw new Error('Database not available');
1983
2201
  }
1984
- const _mod_7 = await import('./BasePathResolver-qV0apdVY.js');
2202
+ const _mod_7 = await import('./BasePathResolver-B6CKqoKw.js');
1985
2203
  const _ns_7 = _mod_7.M;
1986
2204
  const modelSchemaMod = _ns_7;
1987
2205
  const { models: modelsTable } = modelSchemaMod;
@@ -2014,6 +2232,7 @@ var db = /*#__PURE__*/Object.freeze({
2014
2232
  getObjectForRow: getObjectForRow,
2015
2233
  getOwnedAddressesFromDb: getOwnedAddressesFromDb,
2016
2234
  getPropertyIdForModelAndName: getPropertyIdForModelAndName,
2235
+ getPropertyIdForSchemaFileId: getPropertyIdForSchemaFileId,
2017
2236
  getPropertyModelNameAndDataType: getPropertyModelNameAndDataType,
2018
2237
  getSchemaId: getSchemaId,
2019
2238
  getSchemaIdByFileId: getSchemaIdByFileId,
@@ -2027,5 +2246,5 @@ var db = /*#__PURE__*/Object.freeze({
2027
2246
  writePropertyToDb: writePropertyToDb
2028
2247
  });
2029
2248
 
2030
- export { getAllAddressesFromDb as a, normalizeHexAddress as b, addModelsToDb as c, getModelIdByFileId as d, escapeSqliteString as e, getModelId as f, getPropertyIdForModelAndName as g, getAddressesForItemsFilter as h, normalizeAddressConfig as i, normalizeAddressList as j, writePropertyToDb as k, addSchemaToDb as l, loadModelsFromDbForSchema as m, normalizePublisher as n, getOwnedAddressesFromDb as o, getWatchedAddressesFromDb as p, db as q, renameModelInDb as r, writeModelToDb as w };
2031
- //# sourceMappingURL=db-CceyWksv.js.map
2249
+ export { addSchemaToDb as A, Boolean as B, renameModelInDb as C, DEFAULT_TEXT_MAX_LENGTH as D, loadModelsFromDbForSchema as E, File as F, getOwnedAddressesFromDb as G, Html as H, Image as I, Json as J, getPropertyIdForSchemaFileId as K, List as L, ModelPropertyDataTypes as M, Number$1 as N, getWatchedAddressesFromDb as O, Property as P, db as Q, Relation as R, THtmlEmbeddedDataUriPolicy as T, Date$1 as a, PropertyConstructor as b, PropertyMetadataKey as c, TProperty as d, TPropertyConstructor as e, TPropertyDataType as f, TPropertyDefs as g, TStorageType as h, TValidationRules as i, Text as j, isDataType as k, normalizePropertyRecordSchema as l, getPropertyIdForModelAndName as m, normalizeDataType as n, normalizePublisher as o, getAllAddressesFromDb as p, escapeSqliteString as q, normalizeHexAddress as r, addModelsToDb as s, getModelIdByFileId as t, getModelId as u, getAddressesForItemsFilter as v, normalizeAddressConfig as w, normalizeAddressList as x, writeModelToDb as y, writePropertyToDb as z };
2250
+ //# sourceMappingURL=db-WbrzEf7c.js.map