@iamjulianacosta/mobx-data 1.0.1

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 (215) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +366 -0
  3. package/dist/CacheHandler-BTU_rYkv.js +208 -0
  4. package/dist/CacheHandler-BTU_rYkv.js.map +1 -0
  5. package/dist/CacheHandler-CXgY9IJo.cjs +2 -0
  6. package/dist/CacheHandler-CXgY9IJo.cjs.map +1 -0
  7. package/dist/EmbeddedRecordsMixin-CBvqNdgC.cjs +2 -0
  8. package/dist/EmbeddedRecordsMixin-CBvqNdgC.cjs.map +1 -0
  9. package/dist/EmbeddedRecordsMixin-VoHluHCT.js +261 -0
  10. package/dist/EmbeddedRecordsMixin-VoHluHCT.js.map +1 -0
  11. package/dist/JsonApiSerializer-CC5HXp4b.js +194 -0
  12. package/dist/JsonApiSerializer-CC5HXp4b.js.map +1 -0
  13. package/dist/JsonApiSerializer-CKB02AgP.cjs +2 -0
  14. package/dist/JsonApiSerializer-CKB02AgP.cjs.map +1 -0
  15. package/dist/MemoryAdapter-Bx1e7ndV.js +123 -0
  16. package/dist/MemoryAdapter-Bx1e7ndV.js.map +1 -0
  17. package/dist/MemoryAdapter-D1cTyydm.cjs +2 -0
  18. package/dist/MemoryAdapter-D1cTyydm.cjs.map +1 -0
  19. package/dist/ODataAdapter-C4IHK4BK.js +157 -0
  20. package/dist/ODataAdapter-C4IHK4BK.js.map +1 -0
  21. package/dist/ODataAdapter-DyyF1sdA.cjs +2 -0
  22. package/dist/ODataAdapter-DyyF1sdA.cjs.map +1 -0
  23. package/dist/RestAdapter-B4aRvs4m.js +355 -0
  24. package/dist/RestAdapter-B4aRvs4m.js.map +1 -0
  25. package/dist/RestAdapter-CJOwTsKK.cjs +2 -0
  26. package/dist/RestAdapter-CJOwTsKK.cjs.map +1 -0
  27. package/dist/SchemaService-DZwkFgZu.js +102 -0
  28. package/dist/SchemaService-DZwkFgZu.js.map +1 -0
  29. package/dist/SchemaService-Di_yjVzU.cjs +2 -0
  30. package/dist/SchemaService-Di_yjVzU.cjs.map +1 -0
  31. package/dist/Serializer-95gi5edy.cjs +2 -0
  32. package/dist/Serializer-95gi5edy.cjs.map +1 -0
  33. package/dist/Serializer-FxJbsZ50.js +139 -0
  34. package/dist/Serializer-FxJbsZ50.js.map +1 -0
  35. package/dist/Store-BdwMrbDi.cjs +2 -0
  36. package/dist/Store-BdwMrbDi.cjs.map +1 -0
  37. package/dist/Store-CZ7Z-Nme.js +912 -0
  38. package/dist/Store-CZ7Z-Nme.js.map +1 -0
  39. package/dist/adapter/Adapter.d.ts +146 -0
  40. package/dist/adapter/Adapter.d.ts.map +1 -0
  41. package/dist/adapter/MemoryAdapter.d.ts +44 -0
  42. package/dist/adapter/MemoryAdapter.d.ts.map +1 -0
  43. package/dist/adapter/RestAdapter.d.ts +57 -0
  44. package/dist/adapter/RestAdapter.d.ts.map +1 -0
  45. package/dist/adapter/index.cjs +2 -0
  46. package/dist/adapter/index.cjs.map +1 -0
  47. package/dist/adapter/index.d.ts +4 -0
  48. package/dist/adapter/index.d.ts.map +1 -0
  49. package/dist/adapter/index.js +8 -0
  50. package/dist/adapter/index.js.map +1 -0
  51. package/dist/date-Bj4O2W1F.js +107 -0
  52. package/dist/date-Bj4O2W1F.js.map +1 -0
  53. package/dist/date-CRCe-9gf.cjs +2 -0
  54. package/dist/date-CRCe-9gf.cjs.map +1 -0
  55. package/dist/decorators-HQ1KnRdh.cjs +2 -0
  56. package/dist/decorators-HQ1KnRdh.cjs.map +1 -0
  57. package/dist/decorators-Zr35qr6A.js +50 -0
  58. package/dist/decorators-Zr35qr6A.js.map +1 -0
  59. package/dist/index.cjs +2 -0
  60. package/dist/index.cjs.map +1 -0
  61. package/dist/index.d.ts +10 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +52 -0
  64. package/dist/index.js.map +1 -0
  65. package/dist/json-api/JsonApiAdapter.d.ts +38 -0
  66. package/dist/json-api/JsonApiAdapter.d.ts.map +1 -0
  67. package/dist/json-api/JsonApiSerializer.d.ts +73 -0
  68. package/dist/json-api/JsonApiSerializer.d.ts.map +1 -0
  69. package/dist/json-api/index.cjs +2 -0
  70. package/dist/json-api/index.cjs.map +1 -0
  71. package/dist/json-api/index.d.ts +3 -0
  72. package/dist/json-api/index.d.ts.map +1 -0
  73. package/dist/json-api/index.js +6 -0
  74. package/dist/json-api/index.js.map +1 -0
  75. package/dist/model/Errors.d.ts +46 -0
  76. package/dist/model/Errors.d.ts.map +1 -0
  77. package/dist/model/Model.d.ts +226 -0
  78. package/dist/model/Model.d.ts.map +1 -0
  79. package/dist/model/Snapshot.d.ts +72 -0
  80. package/dist/model/Snapshot.d.ts.map +1 -0
  81. package/dist/model/StateMachine.d.ts +45 -0
  82. package/dist/model/StateMachine.d.ts.map +1 -0
  83. package/dist/model/index.cjs +2 -0
  84. package/dist/model/index.cjs.map +1 -0
  85. package/dist/model/index.d.ts +6 -0
  86. package/dist/model/index.d.ts.map +1 -0
  87. package/dist/model/index.js +11 -0
  88. package/dist/model/index.js.map +1 -0
  89. package/dist/model/relationships.d.ts +182 -0
  90. package/dist/model/relationships.d.ts.map +1 -0
  91. package/dist/odata/ODataAdapter.d.ts +67 -0
  92. package/dist/odata/ODataAdapter.d.ts.map +1 -0
  93. package/dist/odata/index.cjs +2 -0
  94. package/dist/odata/index.cjs.map +1 -0
  95. package/dist/odata/index.d.ts +2 -0
  96. package/dist/odata/index.d.ts.map +1 -0
  97. package/dist/odata/index.js +5 -0
  98. package/dist/odata/index.js.map +1 -0
  99. package/dist/relationships-B55LBaCW.cjs +2 -0
  100. package/dist/relationships-B55LBaCW.cjs.map +1 -0
  101. package/dist/relationships-BEXANmWg.js +821 -0
  102. package/dist/relationships-BEXANmWg.js.map +1 -0
  103. package/dist/request/CacheHandler.d.ts +50 -0
  104. package/dist/request/CacheHandler.d.ts.map +1 -0
  105. package/dist/request/FetchHandler.d.ts +41 -0
  106. package/dist/request/FetchHandler.d.ts.map +1 -0
  107. package/dist/request/RequestManager.d.ts +52 -0
  108. package/dist/request/RequestManager.d.ts.map +1 -0
  109. package/dist/request/index.cjs +2 -0
  110. package/dist/request/index.cjs.map +1 -0
  111. package/dist/request/index.d.ts +5 -0
  112. package/dist/request/index.d.ts.map +1 -0
  113. package/dist/request/index.js +7 -0
  114. package/dist/request/index.js.map +1 -0
  115. package/dist/request/types.d.ts +111 -0
  116. package/dist/request/types.d.ts.map +1 -0
  117. package/dist/schema/SchemaService.d.ts +58 -0
  118. package/dist/schema/SchemaService.d.ts.map +1 -0
  119. package/dist/schema/decorators.d.ts +50 -0
  120. package/dist/schema/decorators.d.ts.map +1 -0
  121. package/dist/schema/index.cjs +2 -0
  122. package/dist/schema/index.cjs.map +1 -0
  123. package/dist/schema/index.d.ts +4 -0
  124. package/dist/schema/index.d.ts.map +1 -0
  125. package/dist/schema/index.js +13 -0
  126. package/dist/schema/index.js.map +1 -0
  127. package/dist/schema/types.d.ts +61 -0
  128. package/dist/schema/types.d.ts.map +1 -0
  129. package/dist/serializer/EmbeddedRecordsMixin.d.ts +80 -0
  130. package/dist/serializer/EmbeddedRecordsMixin.d.ts.map +1 -0
  131. package/dist/serializer/JsonSerializer.d.ts +52 -0
  132. package/dist/serializer/JsonSerializer.d.ts.map +1 -0
  133. package/dist/serializer/RestSerializer.d.ts +43 -0
  134. package/dist/serializer/RestSerializer.d.ts.map +1 -0
  135. package/dist/serializer/Serializer.d.ts +202 -0
  136. package/dist/serializer/Serializer.d.ts.map +1 -0
  137. package/dist/serializer/index.cjs +2 -0
  138. package/dist/serializer/index.cjs.map +1 -0
  139. package/dist/serializer/index.d.ts +5 -0
  140. package/dist/serializer/index.d.ts.map +1 -0
  141. package/dist/serializer/index.js +9 -0
  142. package/dist/serializer/index.js.map +1 -0
  143. package/dist/store/IdentityMap.d.ts +53 -0
  144. package/dist/store/IdentityMap.d.ts.map +1 -0
  145. package/dist/store/RecordArray.d.ts +114 -0
  146. package/dist/store/RecordArray.d.ts.map +1 -0
  147. package/dist/store/Store.d.ts +395 -0
  148. package/dist/store/Store.d.ts.map +1 -0
  149. package/dist/store/index.cjs +2 -0
  150. package/dist/store/index.cjs.map +1 -0
  151. package/dist/store/index.d.ts +5 -0
  152. package/dist/store/index.d.ts.map +1 -0
  153. package/dist/store/index.js +8 -0
  154. package/dist/store/index.js.map +1 -0
  155. package/dist/transforms/Transform.d.ts +49 -0
  156. package/dist/transforms/Transform.d.ts.map +1 -0
  157. package/dist/transforms/boolean.d.ts +26 -0
  158. package/dist/transforms/boolean.d.ts.map +1 -0
  159. package/dist/transforms/date.d.ts +22 -0
  160. package/dist/transforms/date.d.ts.map +1 -0
  161. package/dist/transforms/index.cjs +2 -0
  162. package/dist/transforms/index.cjs.map +1 -0
  163. package/dist/transforms/index.d.ts +6 -0
  164. package/dist/transforms/index.d.ts.map +1 -0
  165. package/dist/transforms/index.js +9 -0
  166. package/dist/transforms/index.js.map +1 -0
  167. package/dist/transforms/number.d.ts +17 -0
  168. package/dist/transforms/number.d.ts.map +1 -0
  169. package/dist/transforms/string.d.ts +18 -0
  170. package/dist/transforms/string.d.ts.map +1 -0
  171. package/dist/types-C9NB2gRj.js +7 -0
  172. package/dist/types-C9NB2gRj.js.map +1 -0
  173. package/dist/types-uWOXMPWW.cjs +2 -0
  174. package/dist/types-uWOXMPWW.cjs.map +1 -0
  175. package/package.json +140 -0
  176. package/src/adapter/Adapter.ts +320 -0
  177. package/src/adapter/MemoryAdapter.ts +216 -0
  178. package/src/adapter/RestAdapter.ts +248 -0
  179. package/src/adapter/index.ts +7 -0
  180. package/src/index.ts +17 -0
  181. package/src/json-api/JsonApiAdapter.ts +93 -0
  182. package/src/json-api/JsonApiSerializer.ts +245 -0
  183. package/src/json-api/index.ts +2 -0
  184. package/src/model/Errors.ts +100 -0
  185. package/src/model/Model.ts +683 -0
  186. package/src/model/Snapshot.ts +162 -0
  187. package/src/model/StateMachine.ts +149 -0
  188. package/src/model/index.ts +20 -0
  189. package/src/model/relationships.ts +484 -0
  190. package/src/odata/ODataAdapter.ts +245 -0
  191. package/src/odata/index.ts +1 -0
  192. package/src/request/CacheHandler.ts +125 -0
  193. package/src/request/FetchHandler.ts +119 -0
  194. package/src/request/RequestManager.ts +112 -0
  195. package/src/request/index.ts +4 -0
  196. package/src/request/types.ts +139 -0
  197. package/src/schema/SchemaService.ts +161 -0
  198. package/src/schema/decorators.ts +162 -0
  199. package/src/schema/index.ts +3 -0
  200. package/src/schema/types.ts +66 -0
  201. package/src/serializer/EmbeddedRecordsMixin.ts +257 -0
  202. package/src/serializer/JsonSerializer.ts +173 -0
  203. package/src/serializer/RestSerializer.ts +138 -0
  204. package/src/serializer/Serializer.ts +397 -0
  205. package/src/serializer/index.ts +15 -0
  206. package/src/store/IdentityMap.ts +110 -0
  207. package/src/store/RecordArray.ts +210 -0
  208. package/src/store/Store.ts +1391 -0
  209. package/src/store/index.ts +11 -0
  210. package/src/transforms/Transform.ts +52 -0
  211. package/src/transforms/boolean.ts +57 -0
  212. package/src/transforms/date.ts +48 -0
  213. package/src/transforms/index.ts +5 -0
  214. package/src/transforms/number.ts +42 -0
  215. package/src/transforms/string.ts +35 -0
@@ -0,0 +1,2 @@
1
+ "use strict";const s=require("tsyringe");class f{}var a=Object.getOwnPropertyDescriptor,m=(o,r,e,t)=>{for(var n=t>1?void 0:t?a(r,e):r,u=o.length-1,l;u>=0;u--)(l=o[u])&&(n=l(n)||n);return n};exports.StringTransform=class extends f{deserialize(r){return r==null?null:typeof r=="string"?r:String(r)}serialize(r){return r==null?null:String(r)}};exports.StringTransform=m([s.injectable()],exports.StringTransform);var c=Object.getOwnPropertyDescriptor,b=(o,r,e,t)=>{for(var n=t>1?void 0:t?c(r,e):r,u=o.length-1,l;u>=0;u--)(l=o[u])&&(n=l(n)||n);return n};exports.NumberTransform=class extends f{static coerce(r){if(r==null||r==="")return null;if(typeof r=="number")return Number.isFinite(r)?r:null;if(typeof r=="string"){const e=r.trim();if(e==="")return null;const t=Number(e);return Number.isFinite(t)?t:null}return null}deserialize(r){return exports.NumberTransform.coerce(r)}serialize(r){return exports.NumberTransform.coerce(r)}};exports.NumberTransform=b([s.injectable()],exports.NumberTransform);var g=Object.getOwnPropertyDescriptor,T=(o,r,e,t)=>{for(var n=t>1?void 0:t?g(r,e):r,u=o.length-1,l;u>=0;u--)(l=o[u])&&(n=l(n)||n);return n};exports.BooleanTransform=class extends f{deserialize(r,e={}){if(r==null)return e.allowNull?null:!1;if(typeof r=="boolean")return r;if(typeof r=="number")return r===1;if(typeof r=="string"){const t=r.toLowerCase();return t==="true"||t==="t"||t==="1"}return!!r}serialize(r,e={}){return r==null?e.allowNull?null:!1:!!r}};exports.BooleanTransform=T([s.injectable()],exports.BooleanTransform);var p=Object.getOwnPropertyDescriptor,i=(o,r,e,t)=>{for(var n=t>1?void 0:t?p(r,e):r,u=o.length-1,l;u>=0;u--)(l=o[u])&&(n=l(n)||n);return n};exports.DateTransform=class extends f{deserialize(r){if(r==null||r==="")return null;if(r instanceof Date)return Number.isNaN(r.getTime())?null:r;if(typeof r=="number"||typeof r=="string"){const e=new Date(r);return Number.isNaN(e.getTime())?null:e}return null}serialize(r){return r==null?null:r instanceof Date?Number.isNaN(r.getTime())?null:r.toISOString():null}};exports.DateTransform=i([s.injectable()],exports.DateTransform);exports.BaseTransform=f;
2
+ //# sourceMappingURL=date-CRCe-9gf.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date-CRCe-9gf.cjs","sources":["../src/transforms/Transform.ts","../src/transforms/string.ts","../src/transforms/number.ts","../src/transforms/boolean.ts","../src/transforms/date.ts"],"sourcesContent":["/**\n * Interface and abstract base class for data transforms.\n *\n * A transform converts attribute values between the wire format used by the\n * server (External) and the in-memory format used by the application\n * (Internal).\n *\n * - `deserialize` — called when the store receives data from the server\n * (normalize direction, server → app).\n * - `serialize` — called when the store sends data to the server\n * (serialize direction, app → server).\n *\n * Built-in transforms: `StringTransform`, `NumberTransform`,\n * `BooleanTransform`, `DateTransform`.\n *\n * Custom transforms can be implemented by extending `BaseTransform`:\n *\n * ```ts\n * @injectable()\n * class UpperCaseTransform extends BaseTransform<string, string> {\n * deserialize(value: string) { return value.toUpperCase(); }\n * serialize(value: string) { return value.toLowerCase(); }\n * }\n * ```\n */\n\n/** Bidirectional value converter for a single attribute type. */\nexport interface Transform<External = unknown, Internal = unknown> {\n /**\n * Converts a raw server value to the application-side type.\n * @param serialized - Raw value as it arrived from the server.\n * @param options - Extra options forwarded from the `@attr` decorator.\n */\n deserialize(serialized: External, options?: Record<string, unknown>): Internal;\n\n /**\n * Converts an application-side value back to the wire format.\n * @param deserialized - Current in-memory value.\n * @param options - Extra options forwarded from the `@attr` decorator.\n */\n serialize(deserialized: Internal, options?: Record<string, unknown>): External;\n}\n\n/**\n * Convenience abstract class that implements `Transform` and can be extended\n * to create custom transforms without repeating the interface declaration.\n */\nexport abstract class BaseTransform<External = unknown, Internal = unknown>\nimplements Transform<External, Internal> {\n abstract deserialize(serialized: External, options?: Record<string, unknown>): Internal;\n abstract serialize(deserialized: Internal, options?: Record<string, unknown>): External;\n}\n","/**\n * Transform that converts between arbitrary wire values and strings.\n *\n * Deserialization:\n * - `null` / `undefined` → `null`\n * - `string` → passed through\n * - anything else → `String(value)`\n *\n * Serialization:\n * - `null` / `undefined` → `null`\n * - anything else → `String(value)`\n */\n\nimport { injectable } from 'tsyringe';\nimport { BaseTransform } from './Transform.js';\n\n@injectable()\nexport class StringTransform extends BaseTransform<unknown, string | null> {\n deserialize(serialized: unknown): string | null {\n if (serialized === null || serialized === undefined) {\n return null;\n }\n if (typeof serialized === 'string') {\n return serialized;\n }\n return String(serialized);\n }\n\n serialize(deserialized: string | null): unknown {\n if (deserialized === null || deserialized === undefined) {\n return null;\n }\n return String(deserialized);\n }\n}\n","/**\n * Transform that converts between arbitrary wire values and numbers.\n *\n * Deserialization / serialization coercions (identical in both directions):\n * - `null` / `undefined` / `''` → `null`\n * - finite `number` → passed through\n * - non-finite `number` (NaN, Infinity) → `null`\n * - `string` → trimmed and parsed; `null` when the result is not finite\n * - anything else → `null`\n */\n\nimport { injectable } from 'tsyringe';\nimport { BaseTransform } from './Transform.js';\n\n@injectable()\nexport class NumberTransform extends BaseTransform<unknown, number | null> {\n static coerce(value: unknown): number | null {\n if (value === null || value === undefined || value === '') {\n return null;\n }\n if (typeof value === 'number') {\n return Number.isFinite(value) ? value : null;\n }\n if (typeof value === 'string') {\n const trimmed = value.trim();\n if (trimmed === '') {\n return null;\n }\n const parsed = Number(trimmed);\n return Number.isFinite(parsed) ? parsed : null;\n }\n return null;\n }\n\n deserialize(serialized: unknown): number | null {\n return NumberTransform.coerce(serialized);\n }\n\n serialize(deserialized: number | null): unknown {\n return NumberTransform.coerce(deserialized);\n }\n}\n","/**\n * Transform that converts between arbitrary wire values and booleans.\n *\n * Deserialization coercions:\n * - `null` / `undefined` → `false` (or `null` when `allowNull: true`)\n * - `boolean` → passed through\n * - `number` → `true` only when the value is exactly `1`\n * - `string` → `true` for `'true'`, `'t'`, or `'1'` (case-insensitive)\n * - anything else → `Boolean(value)`\n *\n * Serialization: `Boolean(value)` (preserves `null` when `allowNull: true`).\n */\n\nimport { injectable } from 'tsyringe';\nimport { BaseTransform } from './Transform.js';\n\n/** Options accepted by `BooleanTransform`. */\nexport interface BooleanTransformOptions {\n /**\n * When `true`, `null` / `undefined` input is preserved as `null` rather\n * than coerced to `false`.\n */\n allowNull?: boolean;\n}\n\n@injectable()\nexport class BooleanTransform extends BaseTransform<unknown, boolean | null> {\n deserialize(\n serialized: unknown,\n options: BooleanTransformOptions = {},\n ): boolean | null {\n if (serialized === null || serialized === undefined) {\n return options.allowNull ? null : false;\n }\n if (typeof serialized === 'boolean') {\n return serialized;\n }\n if (typeof serialized === 'number') {\n return serialized === 1;\n }\n if (typeof serialized === 'string') {\n const normalized = serialized.toLowerCase();\n return normalized === 'true' || normalized === 't' || normalized === '1';\n }\n return Boolean(serialized);\n }\n\n serialize(\n deserialized: boolean | null,\n options: BooleanTransformOptions = {},\n ): unknown {\n if (deserialized === null || deserialized === undefined) {\n return options.allowNull ? null : false;\n }\n return Boolean(deserialized);\n }\n}\n","/**\n * Transform that converts between ISO 8601 strings (or numeric timestamps)\n * and JavaScript `Date` objects.\n *\n * Deserialization:\n * - `null` / `undefined` / `''` → `null`\n * - `Date` instance → returned as-is (or `null` when invalid)\n * - `number` (Unix ms) or `string` (ISO 8601) → parsed via `new Date(value)`,\n * returns `null` when parsing yields `NaN`\n * - anything else → `null`\n *\n * Serialization:\n * - `null` / `undefined` → `null`\n * - `Date` instance → ISO 8601 string via `.toISOString()` (or `null` when invalid)\n * - anything else → `null`\n */\n\nimport { injectable } from 'tsyringe';\nimport { BaseTransform } from './Transform.js';\n\n@injectable()\nexport class DateTransform extends BaseTransform<unknown, Date | null> {\n deserialize(serialized: unknown): Date | null {\n if (serialized === null || serialized === undefined || serialized === '') {\n return null;\n }\n if (serialized instanceof Date) {\n return Number.isNaN(serialized.getTime()) ? null : serialized;\n }\n if (typeof serialized === 'number' || typeof serialized === 'string') {\n const parsed = new Date(serialized);\n return Number.isNaN(parsed.getTime()) ? null : parsed;\n }\n return null;\n }\n\n serialize(deserialized: Date | null): unknown {\n if (deserialized === null || deserialized === undefined) {\n return null;\n }\n if (deserialized instanceof Date) {\n return Number.isNaN(deserialized.getTime())\n ? null\n : deserialized.toISOString();\n }\n return null;\n }\n}\n"],"names":["BaseTransform","StringTransform","serialized","deserialized","__decorateClass","injectable","NumberTransform","value","trimmed","parsed","BooleanTransform","options","normalized","DateTransform"],"mappings":"yCA+CO,MAAeA,CACmB,CAGzC,6IClCaC,QAAAA,gBAAN,cAA8BD,CAAsC,CACzE,YAAYE,EAAoC,CAC9C,OAAIA,GAAe,KACV,KAEL,OAAOA,GAAe,SACjBA,EAEF,OAAOA,CAAU,CAC1B,CAEA,UAAUC,EAAsC,CAC9C,OAAIA,GAAiB,KACZ,KAEF,OAAOA,CAAY,CAC5B,CACF,EAjBaF,QAAAA,gBAANG,EAAA,CADNC,EAAAA,WAAA,CAAW,EACCJ,uBAAA,8ICFAK,QAAAA,gBAAN,cAA8BN,CAAsC,CACzE,OAAO,OAAOO,EAA+B,CAC3C,GAAIA,GAAU,MAA+BA,IAAU,GACrD,OAAO,KAET,GAAI,OAAOA,GAAU,SACnB,OAAO,OAAO,SAASA,CAAK,EAAIA,EAAQ,KAE1C,GAAI,OAAOA,GAAU,SAAU,CAC7B,MAAMC,EAAUD,EAAM,KAAA,EACtB,GAAIC,IAAY,GACd,OAAO,KAET,MAAMC,EAAS,OAAOD,CAAO,EAC7B,OAAO,OAAO,SAASC,CAAM,EAAIA,EAAS,IAC5C,CACA,OAAO,IACT,CAEA,YAAYP,EAAoC,CAC9C,OAAOI,QAAAA,gBAAgB,OAAOJ,CAAU,CAC1C,CAEA,UAAUC,EAAsC,CAC9C,OAAOG,QAAAA,gBAAgB,OAAOH,CAAY,CAC5C,CACF,EA1BaG,QAAAA,gBAANF,EAAA,CADNC,EAAAA,WAAA,CAAW,EACCC,uBAAA,8ICWAI,QAAAA,iBAAN,cAA+BV,CAAuC,CAC3E,YACEE,EACAS,EAAmC,GACnB,CAChB,GAAIT,GAAe,KACjB,OAAOS,EAAQ,UAAY,KAAO,GAEpC,GAAI,OAAOT,GAAe,UACxB,OAAOA,EAET,GAAI,OAAOA,GAAe,SACxB,OAAOA,IAAe,EAExB,GAAI,OAAOA,GAAe,SAAU,CAClC,MAAMU,EAAaV,EAAW,YAAA,EAC9B,OAAOU,IAAe,QAAUA,IAAe,KAAOA,IAAe,GACvE,CACA,MAAO,EAAQV,CACjB,CAEA,UACEC,EACAQ,EAAmC,GAC1B,CACT,OAAIR,GAAiB,KACZQ,EAAQ,UAAY,KAAO,GAE7B,EAAQR,CACjB,CACF,EA9BaO,QAAAA,iBAANN,EAAA,CADNC,EAAAA,WAAA,CAAW,EACCK,wBAAA,8ICLAG,QAAAA,cAAN,cAA4Bb,CAAoC,CACrE,YAAYE,EAAkC,CAC5C,GAAIA,GAAe,MAAoCA,IAAe,GACpE,OAAO,KAET,GAAIA,aAAsB,KACxB,OAAO,OAAO,MAAMA,EAAW,QAAA,CAAS,EAAI,KAAOA,EAErD,GAAI,OAAOA,GAAe,UAAY,OAAOA,GAAe,SAAU,CACpE,MAAMO,EAAS,IAAI,KAAKP,CAAU,EAClC,OAAO,OAAO,MAAMO,EAAO,QAAA,CAAS,EAAI,KAAOA,CACjD,CACA,OAAO,IACT,CAEA,UAAUN,EAAoC,CAC5C,OAAIA,GAAiB,KACZ,KAELA,aAAwB,KACnB,OAAO,MAAMA,EAAa,QAAA,CAAS,EACtC,KACAA,EAAa,YAAA,EAEZ,IACT,CACF,EA1BaU,QAAAA,cAANT,EAAA,CADNC,EAAAA,WAAA,CAAW,EACCQ,qBAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";require("reflect-metadata");const i=require("./types-uWOXMPWW.cjs");function r(e){let n=Reflect.getOwnMetadata(i.ATTRIBUTES_META_KEY,e);return n||(n=new Map,Reflect.defineMetadata(i.ATTRIBUTES_META_KEY,n,e)),n}function c(e){let n=Reflect.getOwnMetadata(i.RELATIONSHIPS_META_KEY,e);return n||(n=new Map,Reflect.defineMetadata(i.RELATIONSHIPS_META_KEY,n,e)),n}function o(e,n){let t=null,a={};return typeof e=="string"?(t=e,a=n??{}):e===null?(t=null,a=n??{}):typeof e=="object"&&e!==null&&(a=e),(s,l)=>{r(s).set(l,{name:l,type:t,options:a,isAttribute:!0})}}function u(e,n,t={}){const a={async:t.async??!1,inverse:t.inverse===void 0?null:t.inverse,polymorphic:t.polymorphic??!1,...t};return(s,l)=>{c(s).set(l,{name:l,kind:e,type:n,options:a,isRelationship:!0})}}function T(e,n={}){return u("belongsTo",e,n)}function M(e,n={}){return u("hasMany",e,n)}exports.attr=o;exports.belongsTo=T;exports.hasMany=M;
2
+ //# sourceMappingURL=decorators-HQ1KnRdh.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators-HQ1KnRdh.cjs","sources":["../src/schema/decorators.ts"],"sourcesContent":["/**\n * Property decorators for declaring model attributes and relationships.\n *\n * `@attr` marks a property as a data attribute that is serialized to/from the\n * server payload. `@belongsTo` and `@hasMany` declare the two supported\n * association directions.\n *\n * All decorators write their metadata onto the class prototype via\n * `reflect-metadata` so `SchemaService` can walk the prototype chain and\n * merge inherited definitions.\n */\n\nimport 'reflect-metadata';\nimport {\n ATTRIBUTES_META_KEY,\n RELATIONSHIPS_META_KEY,\n type AttributeDef,\n type AttributeOptions,\n type RelationshipDef,\n type RelationshipOptions,\n} from './types.js';\n\n/**\n * Returns the own-prototype attribute map for `target`, creating one if it\n * doesn't exist yet. We deliberately avoid inheriting the parent map so each\n * class level stores only its own declarations; `SchemaService.walkPrototypeChain`\n * handles merging.\n */\nfunction getOwnAttrMap(target: object): Map<string, AttributeDef> {\n let map = Reflect.getOwnMetadata(ATTRIBUTES_META_KEY, target) as\n | Map<string, AttributeDef>\n | undefined;\n if (!map) {\n map = new Map();\n Reflect.defineMetadata(ATTRIBUTES_META_KEY, map, target);\n }\n return map;\n}\n\n/**\n * Returns the own-prototype relationship map for `target`, creating one if\n * it doesn't exist yet.\n */\nfunction getOwnRelMap(target: object): Map<string, RelationshipDef> {\n let map = Reflect.getOwnMetadata(RELATIONSHIPS_META_KEY, target) as\n | Map<string, RelationshipDef>\n | undefined;\n if (!map) {\n map = new Map();\n Reflect.defineMetadata(RELATIONSHIPS_META_KEY, map, target);\n }\n return map;\n}\n\n/**\n * Marks a class property as a serializable attribute.\n *\n * @example\n * ```ts\n * @attr('string') name!: string;\n * @attr('number', { defaultValue: 0 }) age!: number;\n * @attr({ defaultValue: () => [] }) tags!: string[];\n * ```\n */\nexport function attr(\n type?: string | null,\n options?: AttributeOptions,\n): PropertyDecorator;\nexport function attr(options: AttributeOptions): PropertyDecorator;\nexport function attr(\n typeOrOptions?: string | null | AttributeOptions,\n options?: AttributeOptions,\n): PropertyDecorator {\n let resolvedType: string | null = null;\n let resolvedOptions: AttributeOptions = {};\n\n if (typeof typeOrOptions === 'string') {\n resolvedType = typeOrOptions;\n resolvedOptions = options ?? {};\n } else if (typeOrOptions === null) {\n resolvedType = null;\n resolvedOptions = options ?? {};\n } else if (typeof typeOrOptions === 'object' && typeOrOptions !== null) {\n resolvedOptions = typeOrOptions;\n }\n\n return (target, propertyKey) => {\n const map = getOwnAttrMap(target as object);\n map.set(propertyKey as string, {\n name: propertyKey as string,\n type: resolvedType,\n options: resolvedOptions,\n isAttribute: true,\n });\n };\n}\n\n/**\n * Builds and returns a `PropertyDecorator` that registers a relationship\n * definition on the class prototype. Shared by `@belongsTo` and `@hasMany`.\n *\n * Options are normalised with sensible defaults so consumers can rely on\n * `async`, `inverse`, and `polymorphic` always being present.\n */\nfunction makeRelationship(\n kind: 'belongsTo' | 'hasMany',\n type: string,\n options: RelationshipOptions = {},\n): PropertyDecorator {\n const normalized: RelationshipOptions = {\n async: options.async ?? false,\n inverse: options.inverse === undefined ? null : options.inverse,\n polymorphic: options.polymorphic ?? false,\n ...options,\n };\n return (target, propertyKey) => {\n const map = getOwnRelMap(target as object);\n map.set(propertyKey as string, {\n name: propertyKey as string,\n kind,\n type,\n options: normalized,\n isRelationship: true,\n });\n };\n}\n\n/**\n * Declares a `belongsTo` (many-to-one) association.\n *\n * @param type - `modelName` of the related model.\n * @param options - Optional relationship options (async, inverse, …).\n *\n * @example\n * ```ts\n * @belongsTo('user') author!: User;\n * ```\n */\nexport function belongsTo(\n type: string,\n options: RelationshipOptions = {},\n): PropertyDecorator {\n return makeRelationship('belongsTo', type, options);\n}\n\n/**\n * Declares a `hasMany` (one-to-many) association.\n *\n * @param type - `modelName` of the related model.\n * @param options - Optional relationship options (async, inverse, …).\n *\n * @example\n * ```ts\n * @hasMany('comment') comments!: Comment[];\n * ```\n */\nexport function hasMany(\n type: string,\n options: RelationshipOptions = {},\n): PropertyDecorator {\n return makeRelationship('hasMany', type, options);\n}\n"],"names":["getOwnAttrMap","target","map","ATTRIBUTES_META_KEY","getOwnRelMap","RELATIONSHIPS_META_KEY","attr","typeOrOptions","options","resolvedType","resolvedOptions","propertyKey","makeRelationship","kind","type","normalized","belongsTo","hasMany"],"mappings":"iFA4BA,SAASA,EAAcC,EAA2C,CAChE,IAAIC,EAAM,QAAQ,eAAeC,EAAAA,oBAAqBF,CAAM,EAG5D,OAAKC,IACHA,MAAU,IACV,QAAQ,eAAeC,sBAAqBD,EAAKD,CAAM,GAElDC,CACT,CAMA,SAASE,EAAaH,EAA8C,CAClE,IAAIC,EAAM,QAAQ,eAAeG,EAAAA,uBAAwBJ,CAAM,EAG/D,OAAKC,IACHA,MAAU,IACV,QAAQ,eAAeG,yBAAwBH,EAAKD,CAAM,GAErDC,CACT,CAiBO,SAASI,EACdC,EACAC,EACmB,CACnB,IAAIC,EAA8B,KAC9BC,EAAoC,CAAA,EAExC,OAAI,OAAOH,GAAkB,UAC3BE,EAAeF,EACfG,EAAkBF,GAAW,CAAA,GACpBD,IAAkB,MAC3BE,EAAe,KACfC,EAAkBF,GAAW,CAAA,GACpB,OAAOD,GAAkB,UAAYA,IAAkB,OAChEG,EAAkBH,GAGb,CAACN,EAAQU,IAAgB,CAClBX,EAAcC,CAAgB,EACtC,IAAIU,EAAuB,CAC7B,KAAMA,EACN,KAAMF,EACN,QAASC,EACT,YAAa,EAAA,CACd,CACH,CACF,CASA,SAASE,EACPC,EACAC,EACAN,EAA+B,CAAA,EACZ,CACnB,MAAMO,EAAkC,CACtC,MAAOP,EAAQ,OAAS,GACxB,QAASA,EAAQ,UAAY,OAAY,KAAOA,EAAQ,QACxD,YAAaA,EAAQ,aAAe,GACpC,GAAGA,CAAA,EAEL,MAAO,CAACP,EAAQU,IAAgB,CAClBP,EAAaH,CAAgB,EACrC,IAAIU,EAAuB,CAC7B,KAAMA,EACN,KAAAE,EACA,KAAAC,EACA,QAASC,EACT,eAAgB,EAAA,CACjB,CACH,CACF,CAaO,SAASC,EACdF,EACAN,EAA+B,GACZ,CACnB,OAAOI,EAAiB,YAAaE,EAAMN,CAAO,CACpD,CAaO,SAASS,EACdH,EACAN,EAA+B,GACZ,CACnB,OAAOI,EAAiB,UAAWE,EAAMN,CAAO,CAClD"}
@@ -0,0 +1,50 @@
1
+ import "reflect-metadata";
2
+ import { A as s, R as f } from "./types-C9NB2gRj.js";
3
+ function c(e) {
4
+ let n = Reflect.getOwnMetadata(s, e);
5
+ return n || (n = /* @__PURE__ */ new Map(), Reflect.defineMetadata(s, n, e)), n;
6
+ }
7
+ function o(e) {
8
+ let n = Reflect.getOwnMetadata(f, e);
9
+ return n || (n = /* @__PURE__ */ new Map(), Reflect.defineMetadata(f, n, e)), n;
10
+ }
11
+ function d(e, n) {
12
+ let a = null, t = {};
13
+ return typeof e == "string" ? (a = e, t = n ?? {}) : e === null ? (a = null, t = n ?? {}) : typeof e == "object" && e !== null && (t = e), (i, l) => {
14
+ c(i).set(l, {
15
+ name: l,
16
+ type: a,
17
+ options: t,
18
+ isAttribute: !0
19
+ });
20
+ };
21
+ }
22
+ function u(e, n, a = {}) {
23
+ const t = {
24
+ async: a.async ?? !1,
25
+ inverse: a.inverse === void 0 ? null : a.inverse,
26
+ polymorphic: a.polymorphic ?? !1,
27
+ ...a
28
+ };
29
+ return (i, l) => {
30
+ o(i).set(l, {
31
+ name: l,
32
+ kind: e,
33
+ type: n,
34
+ options: t,
35
+ isRelationship: !0
36
+ });
37
+ };
38
+ }
39
+ function R(e, n = {}) {
40
+ return u("belongsTo", e, n);
41
+ }
42
+ function T(e, n = {}) {
43
+ return u("hasMany", e, n);
44
+ }
45
+ export {
46
+ d as a,
47
+ R as b,
48
+ T as h
49
+ };
50
+ //# sourceMappingURL=decorators-Zr35qr6A.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators-Zr35qr6A.js","sources":["../src/schema/decorators.ts"],"sourcesContent":["/**\n * Property decorators for declaring model attributes and relationships.\n *\n * `@attr` marks a property as a data attribute that is serialized to/from the\n * server payload. `@belongsTo` and `@hasMany` declare the two supported\n * association directions.\n *\n * All decorators write their metadata onto the class prototype via\n * `reflect-metadata` so `SchemaService` can walk the prototype chain and\n * merge inherited definitions.\n */\n\nimport 'reflect-metadata';\nimport {\n ATTRIBUTES_META_KEY,\n RELATIONSHIPS_META_KEY,\n type AttributeDef,\n type AttributeOptions,\n type RelationshipDef,\n type RelationshipOptions,\n} from './types.js';\n\n/**\n * Returns the own-prototype attribute map for `target`, creating one if it\n * doesn't exist yet. We deliberately avoid inheriting the parent map so each\n * class level stores only its own declarations; `SchemaService.walkPrototypeChain`\n * handles merging.\n */\nfunction getOwnAttrMap(target: object): Map<string, AttributeDef> {\n let map = Reflect.getOwnMetadata(ATTRIBUTES_META_KEY, target) as\n | Map<string, AttributeDef>\n | undefined;\n if (!map) {\n map = new Map();\n Reflect.defineMetadata(ATTRIBUTES_META_KEY, map, target);\n }\n return map;\n}\n\n/**\n * Returns the own-prototype relationship map for `target`, creating one if\n * it doesn't exist yet.\n */\nfunction getOwnRelMap(target: object): Map<string, RelationshipDef> {\n let map = Reflect.getOwnMetadata(RELATIONSHIPS_META_KEY, target) as\n | Map<string, RelationshipDef>\n | undefined;\n if (!map) {\n map = new Map();\n Reflect.defineMetadata(RELATIONSHIPS_META_KEY, map, target);\n }\n return map;\n}\n\n/**\n * Marks a class property as a serializable attribute.\n *\n * @example\n * ```ts\n * @attr('string') name!: string;\n * @attr('number', { defaultValue: 0 }) age!: number;\n * @attr({ defaultValue: () => [] }) tags!: string[];\n * ```\n */\nexport function attr(\n type?: string | null,\n options?: AttributeOptions,\n): PropertyDecorator;\nexport function attr(options: AttributeOptions): PropertyDecorator;\nexport function attr(\n typeOrOptions?: string | null | AttributeOptions,\n options?: AttributeOptions,\n): PropertyDecorator {\n let resolvedType: string | null = null;\n let resolvedOptions: AttributeOptions = {};\n\n if (typeof typeOrOptions === 'string') {\n resolvedType = typeOrOptions;\n resolvedOptions = options ?? {};\n } else if (typeOrOptions === null) {\n resolvedType = null;\n resolvedOptions = options ?? {};\n } else if (typeof typeOrOptions === 'object' && typeOrOptions !== null) {\n resolvedOptions = typeOrOptions;\n }\n\n return (target, propertyKey) => {\n const map = getOwnAttrMap(target as object);\n map.set(propertyKey as string, {\n name: propertyKey as string,\n type: resolvedType,\n options: resolvedOptions,\n isAttribute: true,\n });\n };\n}\n\n/**\n * Builds and returns a `PropertyDecorator` that registers a relationship\n * definition on the class prototype. Shared by `@belongsTo` and `@hasMany`.\n *\n * Options are normalised with sensible defaults so consumers can rely on\n * `async`, `inverse`, and `polymorphic` always being present.\n */\nfunction makeRelationship(\n kind: 'belongsTo' | 'hasMany',\n type: string,\n options: RelationshipOptions = {},\n): PropertyDecorator {\n const normalized: RelationshipOptions = {\n async: options.async ?? false,\n inverse: options.inverse === undefined ? null : options.inverse,\n polymorphic: options.polymorphic ?? false,\n ...options,\n };\n return (target, propertyKey) => {\n const map = getOwnRelMap(target as object);\n map.set(propertyKey as string, {\n name: propertyKey as string,\n kind,\n type,\n options: normalized,\n isRelationship: true,\n });\n };\n}\n\n/**\n * Declares a `belongsTo` (many-to-one) association.\n *\n * @param type - `modelName` of the related model.\n * @param options - Optional relationship options (async, inverse, …).\n *\n * @example\n * ```ts\n * @belongsTo('user') author!: User;\n * ```\n */\nexport function belongsTo(\n type: string,\n options: RelationshipOptions = {},\n): PropertyDecorator {\n return makeRelationship('belongsTo', type, options);\n}\n\n/**\n * Declares a `hasMany` (one-to-many) association.\n *\n * @param type - `modelName` of the related model.\n * @param options - Optional relationship options (async, inverse, …).\n *\n * @example\n * ```ts\n * @hasMany('comment') comments!: Comment[];\n * ```\n */\nexport function hasMany(\n type: string,\n options: RelationshipOptions = {},\n): PropertyDecorator {\n return makeRelationship('hasMany', type, options);\n}\n"],"names":["getOwnAttrMap","target","map","ATTRIBUTES_META_KEY","getOwnRelMap","RELATIONSHIPS_META_KEY","attr","typeOrOptions","options","resolvedType","resolvedOptions","propertyKey","makeRelationship","kind","type","normalized","belongsTo","hasMany"],"mappings":";;AA4BA,SAASA,EAAcC,GAA2C;AAChE,MAAIC,IAAM,QAAQ,eAAeC,GAAqBF,CAAM;AAG5D,SAAKC,MACHA,wBAAU,IAAA,GACV,QAAQ,eAAeC,GAAqBD,GAAKD,CAAM,IAElDC;AACT;AAMA,SAASE,EAAaH,GAA8C;AAClE,MAAIC,IAAM,QAAQ,eAAeG,GAAwBJ,CAAM;AAG/D,SAAKC,MACHA,wBAAU,IAAA,GACV,QAAQ,eAAeG,GAAwBH,GAAKD,CAAM,IAErDC;AACT;AAiBO,SAASI,EACdC,GACAC,GACmB;AACnB,MAAIC,IAA8B,MAC9BC,IAAoC,CAAA;AAExC,SAAI,OAAOH,KAAkB,YAC3BE,IAAeF,GACfG,IAAkBF,KAAW,CAAA,KACpBD,MAAkB,QAC3BE,IAAe,MACfC,IAAkBF,KAAW,CAAA,KACpB,OAAOD,KAAkB,YAAYA,MAAkB,SAChEG,IAAkBH,IAGb,CAACN,GAAQU,MAAgB;AAE9B,IADYX,EAAcC,CAAgB,EACtC,IAAIU,GAAuB;AAAA,MAC7B,MAAMA;AAAA,MACN,MAAMF;AAAA,MACN,SAASC;AAAA,MACT,aAAa;AAAA,IAAA,CACd;AAAA,EACH;AACF;AASA,SAASE,EACPC,GACAC,GACAN,IAA+B,CAAA,GACZ;AACnB,QAAMO,IAAkC;AAAA,IACtC,OAAOP,EAAQ,SAAS;AAAA,IACxB,SAASA,EAAQ,YAAY,SAAY,OAAOA,EAAQ;AAAA,IACxD,aAAaA,EAAQ,eAAe;AAAA,IACpC,GAAGA;AAAA,EAAA;AAEL,SAAO,CAACP,GAAQU,MAAgB;AAE9B,IADYP,EAAaH,CAAgB,EACrC,IAAIU,GAAuB;AAAA,MAC7B,MAAMA;AAAA,MACN,MAAAE;AAAA,MACA,MAAAC;AAAA,MACA,SAASC;AAAA,MACT,gBAAgB;AAAA,IAAA,CACjB;AAAA,EACH;AACF;AAaO,SAASC,EACdF,GACAN,IAA+B,IACZ;AACnB,SAAOI,EAAiB,aAAaE,GAAMN,CAAO;AACpD;AAaO,SAASS,EACdH,GACAN,IAA+B,IACZ;AACnB,SAAOI,EAAiB,WAAWE,GAAMN,CAAO;AAClD;"}
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./types-uWOXMPWW.cjs"),n=require("./decorators-HQ1KnRdh.cjs"),c=require("./SchemaService-Di_yjVzU.cjs"),e=require("./relationships-B55LBaCW.cjs"),t=require("./Store-BdwMrbDi.cjs"),s=require("./RestAdapter-CJOwTsKK.cjs"),u=require("./MemoryAdapter-D1cTyydm.cjs"),l=require("./Serializer-95gi5edy.cjs"),o=require("./EmbeddedRecordsMixin-CBvqNdgC.cjs"),r=require("./date-CRCe-9gf.cjs"),i=require("./CacheHandler-CXgY9IJo.cjs"),d=require("./JsonApiSerializer-CKB02AgP.cjs"),p=require("./ODataAdapter-DyyF1sdA.cjs");exports.ATTRIBUTES_META_KEY=a.ATTRIBUTES_META_KEY;exports.MODEL_NAME_META_KEY=a.MODEL_NAME_META_KEY;exports.RELATIONSHIPS_META_KEY=a.RELATIONSHIPS_META_KEY;exports.attr=n.attr;exports.belongsTo=n.belongsTo;exports.hasMany=n.hasMany;Object.defineProperty(exports,"SchemaService",{enumerable:!0,get:()=>c.SchemaService});exports.AsyncBelongsTo=e.AsyncBelongsTo;exports.AsyncHasMany=e.AsyncHasMany;Object.defineProperty(exports,"Errors",{enumerable:!0,get:()=>e.Errors});exports.ManyArray=e.ManyArray;exports.Model=e.Model;exports.Snapshot=e.Snapshot;exports.StateMachine=e.StateMachine;exports.AdapterPopulatedRecordArray=t.AdapterPopulatedRecordArray;exports.IdentityMap=t.IdentityMap;exports.RecordArray=t.RecordArray;Object.defineProperty(exports,"Store",{enumerable:!0,get:()=>t.Store});exports.Adapter=s.Adapter;Object.defineProperty(exports,"RestAdapter",{enumerable:!0,get:()=>s.RestAdapter});Object.defineProperty(exports,"MemoryAdapter",{enumerable:!0,get:()=>u.MemoryAdapter});exports.Serializer=l.Serializer;exports.EmbeddedRecordsMixin=o.EmbeddedRecordsMixin;Object.defineProperty(exports,"JsonSerializer",{enumerable:!0,get:()=>o.JsonSerializer});Object.defineProperty(exports,"RestSerializer",{enumerable:!0,get:()=>o.RestSerializer});exports.BaseTransform=r.BaseTransform;Object.defineProperty(exports,"BooleanTransform",{enumerable:!0,get:()=>r.BooleanTransform});Object.defineProperty(exports,"DateTransform",{enumerable:!0,get:()=>r.DateTransform});Object.defineProperty(exports,"NumberTransform",{enumerable:!0,get:()=>r.NumberTransform});Object.defineProperty(exports,"StringTransform",{enumerable:!0,get:()=>r.StringTransform});Object.defineProperty(exports,"CacheHandler",{enumerable:!0,get:()=>i.CacheHandler});Object.defineProperty(exports,"FetchHandler",{enumerable:!0,get:()=>i.FetchHandler});Object.defineProperty(exports,"RequestManager",{enumerable:!0,get:()=>i.RequestManager});Object.defineProperty(exports,"JsonApiAdapter",{enumerable:!0,get:()=>d.JsonApiAdapter});Object.defineProperty(exports,"JsonApiSerializer",{enumerable:!0,get:()=>d.JsonApiSerializer});Object.defineProperty(exports,"ODataAdapter",{enumerable:!0,get:()=>p.ODataAdapter});
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ export * from './schema/index.js';
2
+ export * from './model/index.js';
3
+ export { Store, type AdapterLike, type SerializerLike, type FindOptions, IdentityMap, RecordArray, AdapterPopulatedRecordArray, } from './store/index.js';
4
+ export * from './adapter/index.js';
5
+ export * from './serializer/index.js';
6
+ export * from './transforms/index.js';
7
+ export * from './request/index.js';
8
+ export * from './json-api/index.js';
9
+ export * from './odata/index.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EACL,KAAK,EACL,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,WAAW,EACX,WAAW,EACX,2BAA2B,GAC5B,MAAM,kBAAkB,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ import { A as e, M as s, R as o } from "./types-C9NB2gRj.js";
2
+ import { a as n, b as p, h as A } from "./decorators-Zr35qr6A.js";
3
+ import { S as f } from "./SchemaService-DZwkFgZu.js";
4
+ import { A as d, a as M, E as i, M as x, b as E, S as T, c as R } from "./relationships-BEXANmWg.js";
5
+ import { A as l, I as y, R as h, S as _ } from "./Store-CZ7Z-Nme.js";
6
+ import { A as B, R as I } from "./RestAdapter-B4aRvs4m.js";
7
+ import { M as g } from "./MemoryAdapter-Bx1e7ndV.js";
8
+ import { S as D } from "./Serializer-FxJbsZ50.js";
9
+ import { E as N, J as O, R as u } from "./EmbeddedRecordsMixin-VoHluHCT.js";
10
+ import { B as Y, a as C, D as F, N as L, S as P } from "./date-Bj4O2W1F.js";
11
+ import { C as v, F as U, R as j } from "./CacheHandler-BTU_rYkv.js";
12
+ import { J as w, a as G } from "./JsonApiSerializer-CC5HXp4b.js";
13
+ import { O as V } from "./ODataAdapter-C4IHK4BK.js";
14
+ export {
15
+ e as ATTRIBUTES_META_KEY,
16
+ B as Adapter,
17
+ l as AdapterPopulatedRecordArray,
18
+ d as AsyncBelongsTo,
19
+ M as AsyncHasMany,
20
+ Y as BaseTransform,
21
+ C as BooleanTransform,
22
+ v as CacheHandler,
23
+ F as DateTransform,
24
+ N as EmbeddedRecordsMixin,
25
+ i as Errors,
26
+ U as FetchHandler,
27
+ y as IdentityMap,
28
+ w as JsonApiAdapter,
29
+ G as JsonApiSerializer,
30
+ O as JsonSerializer,
31
+ s as MODEL_NAME_META_KEY,
32
+ x as ManyArray,
33
+ g as MemoryAdapter,
34
+ E as Model,
35
+ L as NumberTransform,
36
+ V as ODataAdapter,
37
+ o as RELATIONSHIPS_META_KEY,
38
+ h as RecordArray,
39
+ j as RequestManager,
40
+ I as RestAdapter,
41
+ u as RestSerializer,
42
+ f as SchemaService,
43
+ D as Serializer,
44
+ T as Snapshot,
45
+ R as StateMachine,
46
+ _ as Store,
47
+ P as StringTransform,
48
+ n as attr,
49
+ p as belongsTo,
50
+ A as hasMany
51
+ };
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Adapter that implements the [JSON:API](https://jsonapi.org) specification.
3
+ *
4
+ * Extends `RestAdapter` with the following differences:
5
+ *
6
+ * - **MIME types** — `Accept` and `Content-Type` headers are set to
7
+ * `application/vnd.api+json` as required by the spec.
8
+ * - **PATCH for updates** — `updateRecord` uses `PATCH` instead of `PUT`.
9
+ * - **`coalesceFindRequests: true`** — the store coalesces separate
10
+ * `findRecord` calls into a single `findMany` request.
11
+ *
12
+ * URL construction is inherited from `RestAdapter` / `Adapter` unchanged;
13
+ * override `pathForType` or `urlFor*` methods to customize.
14
+ */
15
+ import { RestAdapter, type AdapterSnapshot } from '@mobx-data/adapter';
16
+ export declare class JsonApiAdapter extends RestAdapter {
17
+ /** Always coalesce `findRecord` calls into a single `findMany` request. */
18
+ coalesceFindRequests: boolean;
19
+ /** Returns JSON:API `Accept` header alongside any custom headers. */
20
+ defaultHeaders(): Record<string, string>;
21
+ /** Returns JSON:API `Content-Type` header for mutation requests. */
22
+ mutationHeaders(): Record<string, string>;
23
+ /**
24
+ * Sends a PATCH request to update a record (JSON:API mandates PATCH, not PUT).
25
+ */
26
+ updateRecord(_store: unknown, modelName: string, snapshot: AdapterSnapshot): Promise<unknown>;
27
+ /**
28
+ * Sends a PATCH request with only the changed attributes (partial update).
29
+ * Produces a JSON:API document with only the dirty attribute keys.
30
+ */
31
+ patchRecord(_store: unknown, modelName: string, snapshot: AdapterSnapshot): Promise<unknown>;
32
+ /**
33
+ * Extracts the raw data object from the snapshot for use as the PATCH body.
34
+ * Subclasses may override this to produce a full JSON:API `{ data: … }` document.
35
+ */
36
+ protected _serializeForUpdate(snapshot: AdapterSnapshot): Record<string, unknown>;
37
+ }
38
+ //# sourceMappingURL=JsonApiAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonApiAdapter.d.ts","sourceRoot":"","sources":["../../src/json-api/JsonApiAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEvE,qBACa,cAAe,SAAQ,WAAW;IAC7C,2EAA2E;IAClE,oBAAoB,UAAQ;IAErC,qEAAqE;IAC5D,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAOjD,oEAAoE;IAC3D,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAOlD;;OAEG;IACY,YAAY,CACzB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,CAAC;IASnB;;;OAGG;IACY,WAAW,CACxB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,CAAC;IAqBnB;;;OAGG;IACH,SAAS,CAAC,mBAAmB,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAIlF"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Serializer that implements the [JSON:API](https://jsonapi.org) specification.
3
+ *
4
+ * ## Normalization
5
+ *
6
+ * Parses a JSON:API compound document `{ data, included, meta, links }` into
7
+ * a `NormalizedDocument`.
8
+ *
9
+ * For each resource object:
10
+ * - `type` is converted from JSON:API plural form to model name via
11
+ * `modelNameFromPayloadKey` (singularization).
12
+ * - `id` is coerced to a string.
13
+ * - `attributes` are copied directly.
14
+ * - `relationships` data refs (`{ type, id }`) are normalized the same way.
15
+ *
16
+ * Side-loaded records in `included` are normalized individually, each using
17
+ * its own `type` as the model class placeholder.
18
+ *
19
+ * ## Serialization
20
+ *
21
+ * Produces a JSON:API resource object wrapped in `{ data: … }`:
22
+ *
23
+ * ```json
24
+ * {
25
+ * "data": {
26
+ * "type": "posts",
27
+ * "attributes": { "title": "Hello" },
28
+ * "relationships": {
29
+ * "author": { "data": { "type": "users", "id": "1" } }
30
+ * }
31
+ * }
32
+ * }
33
+ * ```
34
+ *
35
+ * `id` is included when `options.includeId` is `true`.
36
+ */
37
+ import { Serializer, type ModelClassMeta, type NormalizeRequestType, type NormalizedDocument, type NormalizedResource, type SerializerSnapshot } from '@mobx-data/serializer';
38
+ export declare class JsonApiSerializer extends Serializer {
39
+ /**
40
+ * Returns the plural JSON:API `type` string for a model name.
41
+ * e.g. `'post'` → `'posts'`
42
+ */
43
+ payloadKeyFromModelName(modelName: string): string;
44
+ /**
45
+ * Returns the model name for a JSON:API `type` string.
46
+ * e.g. `'posts'` → `'post'`
47
+ */
48
+ modelNameFromPayloadKey(key: string): string;
49
+ /**
50
+ * Normalizes a single JSON:API resource object into a `NormalizedResource`.
51
+ * Returns `null` for absent, non-object, or type-less payloads.
52
+ */
53
+ normalize(_store: unknown, _modelClass: ModelClassMeta, payload: unknown, _prop?: string): NormalizedResource | null;
54
+ /**
55
+ * Normalizes a full JSON:API compound document.
56
+ *
57
+ * - `data` (single or array) → primary resources
58
+ * - `included` → side-loaded resources pushed to `normalizedDoc.included`
59
+ * - `meta` and `links` → forwarded as-is
60
+ */
61
+ normalizeResponse(store: unknown, modelClass: ModelClassMeta, payload: unknown, _id: string | null, _requestType: NormalizeRequestType): NormalizedDocument;
62
+ /**
63
+ * Serializes a record snapshot to a JSON:API `{ data: … }` document.
64
+ *
65
+ * Attributes are placed in `data.attributes`; relationships are placed in
66
+ * `data.relationships` with proper `{ data: { type, id } }` structure.
67
+ * `id` is included in `data` when `options.includeId` is `true`.
68
+ */
69
+ serialize(snapshot: SerializerSnapshot, options?: {
70
+ includeId?: boolean;
71
+ }): Record<string, unknown>;
72
+ }
73
+ //# sourceMappingURL=JsonApiSerializer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonApiSerializer.d.ts","sourceRoot":"","sources":["../../src/json-api/JsonApiSerializer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAIH,OAAO,EACL,UAAU,EACV,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAe/B,qBACa,iBAAkB,SAAQ,UAAU;IAC/C;;;OAGG;IACH,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAIlD;;;OAGG;IACH,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAI5C;;;OAGG;IACM,SAAS,CAChB,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,cAAc,EAC3B,OAAO,EAAE,OAAO,EAChB,KAAK,CAAC,EAAE,MAAM,GACb,kBAAkB,GAAG,IAAI;IAyC5B;;;;;;OAMG;IACM,iBAAiB,CACxB,KAAK,EAAE,OAAO,EACd,UAAU,EAAE,cAAc,EAC1B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,MAAM,GAAG,IAAI,EAClB,YAAY,EAAE,oBAAoB,GACjC,kBAAkB;IA+CrB;;;;;;OAMG;IACM,SAAS,CAChB,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAChC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CA6C3B"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../JsonApiSerializer-CKB02AgP.cjs");Object.defineProperty(exports,"JsonApiAdapter",{enumerable:!0,get:()=>e.JsonApiAdapter});Object.defineProperty(exports,"JsonApiSerializer",{enumerable:!0,get:()=>e.JsonApiSerializer});
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export { JsonApiAdapter } from './JsonApiAdapter.js';
2
+ export { JsonApiSerializer } from './JsonApiSerializer.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/json-api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { J as e, a as i } from "../JsonApiSerializer-CC5HXp4b.js";
2
+ export {
3
+ e as JsonApiAdapter,
4
+ i as JsonApiSerializer
5
+ };
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Observable collection of validation error messages keyed by attribute name.
3
+ *
4
+ * `Errors` is attached to every `Model` instance as `record.errors`. It
5
+ * mirrors Ember Data's `DS.Errors` API: each attribute can hold multiple
6
+ * `ErrorMessage` objects, and the map is MobX-observable so templates / computed
7
+ * properties that read `isEmpty` or `length` react automatically when errors
8
+ * are added or cleared.
9
+ *
10
+ * Typical lifecycle:
11
+ * 1. Server returns a 422; the serializer calls `store.errors.add(…)`.
12
+ * 2. The UI reads `record.errors.get('email')` to display messages.
13
+ * 3. The user corrects the field; `record.errors.remove('email')` clears it.
14
+ * 4. A successful save calls `record.errors.clear()` to wipe all messages.
15
+ */
16
+ /** A single validation error for one attribute. */
17
+ export interface ErrorMessage {
18
+ /** Attribute name the error belongs to. */
19
+ attribute: string;
20
+ /** Human-readable error message. */
21
+ message: string;
22
+ }
23
+ export declare class Errors implements Iterable<[string, ErrorMessage[]]> {
24
+ private _errors;
25
+ constructor();
26
+ /** `true` when there are no validation errors. */
27
+ get isEmpty(): boolean;
28
+ /** Total number of error messages across all attributes. */
29
+ get length(): number;
30
+ /** Returns all error messages for `attribute`, or an empty array. */
31
+ get(attribute: string): ErrorMessage[];
32
+ /** Returns `true` when `attribute` has at least one error message. */
33
+ has(attribute: string): boolean;
34
+ /**
35
+ * Appends one or more error messages for `attribute`.
36
+ * Existing messages are preserved — this is an additive operation.
37
+ */
38
+ add(attribute: string, message: string | string[]): void;
39
+ /** Removes all error messages for `attribute`. */
40
+ remove(attribute: string): void;
41
+ /** Removes all error messages for every attribute. */
42
+ clear(): void;
43
+ /** Iterates `[attributeName, ErrorMessage[]]` pairs. */
44
+ [Symbol.iterator](): Iterator<[string, ErrorMessage[]]>;
45
+ }
46
+ //# sourceMappingURL=Errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../../src/model/Errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,mDAAmD;AACnD,MAAM,WAAW,YAAY;IAC3B,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBACa,MAAO,YAAW,QAAQ,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;IAC/D,OAAO,CAAC,OAAO,CAA0C;;IAazD,kDAAkD;IAClD,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,4DAA4D;IAC5D,IAAI,MAAM,IAAI,MAAM,CAMnB;IAED,qEAAqE;IACrE,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,EAAE;IAItC,sEAAsE;IACtE,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAK/B;;;OAGG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;IAUxD,kDAAkD;IAClD,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAI/B,sDAAsD;IACtD,KAAK,IAAI,IAAI;IAIb,wDAAwD;IACtD,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;CAK1D"}
@@ -0,0 +1,226 @@
1
+ /**
2
+ * Base class for all mobx-data model records.
3
+ *
4
+ * `Model` is an abstract MobX-observable class that manages the complete
5
+ * lifecycle of a server-side resource. Subclasses declare their schema using
6
+ * `@attr`, `@belongsTo`, and `@hasMany` decorators; `Model` automatically
7
+ * installs observable getters/setters for each declaration the first time the
8
+ * class is instantiated.
9
+ *
10
+ * ## State machine
11
+ * Every record progresses through the states tracked by `StateMachine`:
12
+ * - **empty** → initial placeholder state
13
+ * - **loading** → adapter request in flight
14
+ * - **loaded.saved** → clean, persisted record
15
+ * - **loaded.created.uncommitted** → new, unsaved record
16
+ * - **loaded.updated.uncommitted** → dirty, unsaved changes
17
+ * - **deleted.*** → record marked for / undergoing deletion
18
+ * - **error** → adapter threw a non-validation error
19
+ *
20
+ * ## Lifecycle hooks
21
+ * Override `didLoad`, `didCreate`, `didUpdate`, `didDelete`, `willSave`,
22
+ * `didSave`, `becameInvalid`, and `becameError` to react to state transitions.
23
+ *
24
+ * ## Store integration
25
+ * Records are normally created and loaded through a `Store` instance. The
26
+ * `store` property is set by the store after instantiation so that `save()`,
27
+ * `reload()`, and `destroyRecord()` can delegate back to it.
28
+ */
29
+ import 'reflect-metadata';
30
+ import { type RelationshipDef } from '@mobx-data/schema';
31
+ import { Errors } from './Errors.js';
32
+ import { StateMachine, type RecordState, type RecordEvent } from './StateMachine.js';
33
+ import { Snapshot } from './Snapshot.js';
34
+ /**
35
+ * Raw relationship reference stored on the record.
36
+ * Contains either a single `{ type, id }` object (belongsTo),
37
+ * an array of them (hasMany), or `null`.
38
+ */
39
+ export interface RelationshipRef {
40
+ data: {
41
+ type: string;
42
+ id: string;
43
+ } | Array<{
44
+ type: string;
45
+ id: string;
46
+ }> | null;
47
+ }
48
+ /**
49
+ * Minimal store interface that `Model` uses to delegate persistence operations.
50
+ * The full `Store` class satisfies this interface.
51
+ */
52
+ export interface SaveOptions {
53
+ patch?: boolean;
54
+ adapterOptions?: Record<string, unknown>;
55
+ }
56
+ export interface ModelStoreLike {
57
+ saveRecord?<T extends Model>(record: T, options?: SaveOptions): Promise<T>;
58
+ deleteRecord?<T extends Model>(record: T): Promise<T>;
59
+ reloadRecord?<T extends Model>(record: T): Promise<T>;
60
+ unloadRecord?(record: Model): void;
61
+ peekRecord?<T extends Model = Model>(type: string, id: string): T | null;
62
+ findRecord?<T extends Model = Model>(type: string, id: string, options?: unknown): Promise<T>;
63
+ onRelationshipSet?(record: Model, relName: string, ref: RelationshipRef): void;
64
+ resolveRelationship?(record: Model, name: string, meta: RelationshipDef): unknown;
65
+ setRelationshipValue?(record: Model, name: string, meta: RelationshipDef, value: unknown): void;
66
+ }
67
+ /** Options accepted by the `Model` constructor. */
68
+ export interface ModelConstructorOptions {
69
+ /** Server-assigned id, or `null` / `undefined` for new records. */
70
+ id?: string | null;
71
+ /** Initial attribute data. */
72
+ data?: Record<string, unknown>;
73
+ /** Initial relationship references. */
74
+ relationships?: Record<string, RelationshipRef>;
75
+ /** Store instance injected so records can delegate persistence. */
76
+ store?: ModelStoreLike;
77
+ }
78
+ /** Options accepted by the static `Model.push` factory method. */
79
+ export interface PushOptions {
80
+ id: string;
81
+ data: Record<string, unknown>;
82
+ relationships?: Record<string, RelationshipRef>;
83
+ store?: ModelStoreLike;
84
+ }
85
+ export declare abstract class Model {
86
+ /** Registered model name — must be set as a static property on subclasses. */
87
+ static modelName: string;
88
+ /**
89
+ * Factory method that creates an instance in the `root.loaded.saved` state
90
+ * (i.e. as if freshly loaded from the server) and calls `didLoad()`.
91
+ *
92
+ * Used internally by `Store.pushResource` to avoid exposing the internal
93
+ * `__initialState` option.
94
+ */
95
+ static push<T extends typeof Model>(this: T, opts: PushOptions): InstanceType<T>;
96
+ /** Current attribute values. Deep-observable so nested mutations are tracked. */
97
+ protected _data: Record<string, unknown>;
98
+ /** Snapshot of attribute values as last received from the server (dirty tracking baseline). */
99
+ protected _originalData: Record<string, unknown>;
100
+ /** Raw relationship references keyed by relationship name. */
101
+ protected _relationships: Map<string, RelationshipRef>;
102
+ /** Server-assigned id, or `null` for new records. */
103
+ protected _id: string | null;
104
+ /** Internal lifecycle state machine. */
105
+ protected _stateMachine: StateMachine;
106
+ /** Observable validation error collection. */
107
+ readonly errors: Errors;
108
+ /** Reference to the owning store, injected at construction. */
109
+ store?: ModelStoreLike;
110
+ constructor(options?: ModelConstructorOptions);
111
+ /** Server-assigned id, or `null` for new records. */
112
+ get id(): string | null;
113
+ set id(v: string | null);
114
+ /** Returns the static `modelName` from the concrete subclass constructor. */
115
+ get modelName(): string;
116
+ /** Current state-machine state string. */
117
+ get currentState(): RecordState;
118
+ /** `true` while an adapter request to fetch this record is in flight. */
119
+ get isLoading(): boolean;
120
+ /** `true` when the record has been loaded (any `root.loaded.*` state). */
121
+ get isLoaded(): boolean;
122
+ /** `true` while a create or update request is in flight. */
123
+ get isSaving(): boolean;
124
+ /** `true` when the record was created locally and has never been saved. */
125
+ get isNew(): boolean;
126
+ /** `true` when `deleteRecord()` has been called (regardless of server state). */
127
+ get isDeleted(): boolean;
128
+ /** `true` when the record is in the `root.error` state. */
129
+ get isError(): boolean;
130
+ /** `true` when the record is in the `root.empty` placeholder state. */
131
+ get isEmpty(): boolean;
132
+ /** `true` when any attribute differs from its last-saved value. */
133
+ get hasDirtyAttributes(): boolean;
134
+ /**
135
+ * `true` when the record needs to be saved — new, deleted (not yet
136
+ * confirmed), or has dirty attributes.
137
+ */
138
+ get isDirty(): boolean;
139
+ /** `true` when `errors.isEmpty` — i.e. no validation errors are present. */
140
+ get isValid(): boolean;
141
+ /**
142
+ * Returns a `{ [key]: [original, current] }` map of attributes that differ
143
+ * from the last server-received snapshot.
144
+ */
145
+ changedAttributes(): Record<string, [unknown, unknown]>;
146
+ /**
147
+ * Resets all attributes to their original server values and clears
148
+ * validation errors. For new records the record is transitioned to
149
+ * `root.empty` and unloaded from the store.
150
+ */
151
+ rollbackAttributes(): void;
152
+ /**
153
+ * Persists the record to the server. No-ops if the record is not dirty.
154
+ * Delegates to `store.saveRecord`.
155
+ *
156
+ * @throws when no store is attached.
157
+ */
158
+ save(options?: SaveOptions): Promise<this>;
159
+ /**
160
+ * Reloads the record from the server.
161
+ * @throws when no store is attached.
162
+ */
163
+ reload(): Promise<this>;
164
+ /**
165
+ * Marks the record for deletion. The record moves to
166
+ * `root.deleted.uncommitted` but is not yet removed from the server.
167
+ * Call `destroyRecord()` to also issue the DELETE request.
168
+ */
169
+ deleteRecord(): void;
170
+ /**
171
+ * Marks the record for deletion and immediately sends a DELETE request.
172
+ * @throws when no store is attached.
173
+ */
174
+ destroyRecord(): Promise<this>;
175
+ /** Removes the record from the store's identity map without a server call. */
176
+ unloadRecord(): void;
177
+ /** Creates a frozen `Snapshot` of the current record state. */
178
+ createSnapshot(): Snapshot<this>;
179
+ /** Returns a plain-object representation of the current attribute data. */
180
+ serialize(_options?: {
181
+ includeId?: boolean;
182
+ }): Record<string, unknown>;
183
+ /** Returns `{ id, ...attributes }` — used by `JSON.stringify`. */
184
+ toJSON(): Record<string, unknown>;
185
+ /** Called after the record is loaded from the server. */
186
+ didLoad(): void;
187
+ /** Called after a new record is successfully persisted. */
188
+ didCreate(): void;
189
+ /** Called after an existing record is successfully updated. */
190
+ didUpdate(): void;
191
+ /** Called after a record is successfully deleted. */
192
+ didDelete(): void;
193
+ /** Called immediately before a save request is issued. */
194
+ willSave(): void;
195
+ /** Called after any successful save (create or update). */
196
+ didSave(): void;
197
+ /** Called when the server returns a 422-style validation error. */
198
+ becameInvalid(): void;
199
+ /** Called when the server returns a non-validation error. */
200
+ becameError(): void;
201
+ /** Called by generated attribute setters. */
202
+ protected _setAttribute(key: string, value: unknown): void;
203
+ /**
204
+ * Transitions to `updated.uncommitted` when the record becomes dirty, or
205
+ * back to `saved` when all changes are rolled back.
206
+ */
207
+ protected _transitionIfClean(): void;
208
+ /** Directly sets the state machine's current state (bypasses transition validation). */
209
+ protected _setState(state: RecordState): void;
210
+ /** Fires a state-machine transition event. */
211
+ protected _transition(event: RecordEvent): void;
212
+ /** Used by Store to apply server data after save, making record clean again. */
213
+ protected _applyServerData(id: string | null, data: Record<string, unknown>, relationships?: Record<string, RelationshipRef>): void;
214
+ /** Relationship data (reference only). Resolution to records lives in Store. */
215
+ protected _getRelationshipRef(name: string): RelationshipRef | null;
216
+ /** Stores a raw relationship reference without triggering store logic. */
217
+ protected _setRelationshipRef(name: string, ref: RelationshipRef): void;
218
+ /**
219
+ * Delegates relationship resolution to the store.
220
+ * Returns `null` when no store is attached (e.g. in unit tests).
221
+ */
222
+ protected _resolveRelationship(name: string, meta: RelationshipDef): unknown;
223
+ /** Delegates relationship mutation to the store (which also handles inverse sync). */
224
+ protected _setRelationship(name: string, meta: RelationshipDef, value: unknown): void;
225
+ }
226
+ //# sourceMappingURL=Model.d.ts.map