@donotdev/crud 0.2.2 → 0.2.3

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 (224) hide show
  1. package/dist/CrudService.bulk.d.ts +8 -6
  2. package/dist/CrudService.bulk.d.ts.map +1 -1
  3. package/dist/CrudService.bulk.js +1 -1
  4. package/dist/CrudService.bulkAcross.d.ts +4 -2
  5. package/dist/CrudService.bulkAcross.d.ts.map +1 -1
  6. package/dist/CrudService.bulkAcross.js +1 -1
  7. package/dist/CrudService.cache.d.ts +21 -2
  8. package/dist/CrudService.cache.d.ts.map +1 -1
  9. package/dist/CrudService.cache.js +1 -1
  10. package/dist/CrudService.d.ts +7 -5
  11. package/dist/CrudService.d.ts.map +1 -1
  12. package/dist/CrudService.internal.d.ts +3 -2
  13. package/dist/CrudService.internal.d.ts.map +1 -1
  14. package/dist/CrudService.internal.js +2 -2
  15. package/dist/CrudService.queries.d.ts.map +1 -1
  16. package/dist/CrudService.queries.js +1 -1
  17. package/dist/CrudService.subscriptions.d.ts.map +1 -1
  18. package/dist/CrudService.subscriptions.js +1 -1
  19. package/dist/CrudStore.js +1 -1
  20. package/dist/adapters/FunctionsAdapter.d.ts.map +1 -1
  21. package/dist/adapters/FunctionsAdapter.js +1 -1
  22. package/dist/components/CrudButton.js +1 -1
  23. package/dist/components/CrudCard.d.ts +2 -2
  24. package/dist/components/CrudCard.d.ts.map +1 -1
  25. package/dist/components/CrudCard.js +1 -1
  26. package/dist/components/DateFilter.js +1 -1
  27. package/dist/components/DisplayFieldRenderer.d.ts +5 -2
  28. package/dist/components/DisplayFieldRenderer.d.ts.map +1 -1
  29. package/dist/components/DisplayFieldRenderer.js +1 -1
  30. package/dist/components/DisplayThumbnail.d.ts.map +1 -1
  31. package/dist/components/DisplayThumbnail.js +1 -1
  32. package/dist/components/EntityFilters.d.ts +4 -1
  33. package/dist/components/EntityFilters.d.ts.map +1 -1
  34. package/dist/components/EntityFilters.js +1 -1
  35. package/dist/components/FormFieldRenderer.d.ts +0 -8
  36. package/dist/components/FormFieldRenderer.d.ts.map +1 -1
  37. package/dist/components/FormFieldRenderer.js +1 -1
  38. package/dist/components/FormLayout.js +1 -1
  39. package/dist/components/YearFilter.js +1 -1
  40. package/dist/components/controlled/complex/ControlledAddressField.d.ts.map +1 -1
  41. package/dist/components/controlled/complex/ControlledAddressField.js +1 -1
  42. package/dist/components/controlled/complex/ControlledDateField.d.ts.map +1 -1
  43. package/dist/components/controlled/complex/ControlledFieldArrayField.d.ts.map +1 -1
  44. package/dist/components/controlled/complex/ControlledGeoPointField.d.ts.map +1 -1
  45. package/dist/components/controlled/complex/ControlledMapField.d.ts.map +1 -1
  46. package/dist/components/controlled/complex/ControlledMultiInputField.d.ts.map +1 -1
  47. package/dist/components/controlled/complex/ControlledRichTextField.d.ts.map +1 -1
  48. package/dist/components/controlled/complex/ControlledTimestampField.d.ts.map +1 -1
  49. package/dist/components/controlled/fieldOptions.d.ts +39 -0
  50. package/dist/components/controlled/fieldOptions.d.ts.map +1 -0
  51. package/dist/components/controlled/fieldOptions.js +1 -0
  52. package/dist/components/controlled/file/ControlledDocumentField.js +1 -1
  53. package/dist/components/controlled/file/ControlledFileField.js +1 -1
  54. package/dist/components/controlled/file/ControlledImageField.d.ts.map +1 -1
  55. package/dist/components/controlled/file/ControlledImageField.js +1 -1
  56. package/dist/components/controlled/file/ControlledMultiDocumentField.d.ts.map +1 -1
  57. package/dist/components/controlled/file/ControlledMultiDocumentField.js +1 -1
  58. package/dist/components/controlled/file/ControlledMultiFileField.d.ts.map +1 -1
  59. package/dist/components/controlled/file/ControlledMultiFileField.js +1 -1
  60. package/dist/components/controlled/file/ControlledMultiImageField.d.ts.map +1 -1
  61. package/dist/components/controlled/file/ControlledMultiImageField.js +1 -1
  62. package/dist/components/controlled/input/ControlledCheckboxField.d.ts.map +1 -1
  63. package/dist/components/controlled/input/ControlledCurrencyField.d.ts.map +1 -1
  64. package/dist/components/controlled/input/ControlledDurationField.d.ts.map +1 -1
  65. package/dist/components/controlled/input/ControlledGdprConsentField.d.ts.map +1 -1
  66. package/dist/components/controlled/input/ControlledGdprConsentField.js +1 -1
  67. package/dist/components/controlled/input/ControlledNumberField.d.ts.map +1 -1
  68. package/dist/components/controlled/input/ControlledPasswordField.d.ts.map +1 -1
  69. package/dist/components/controlled/input/ControlledPhoneField.d.ts.map +1 -1
  70. package/dist/components/controlled/input/ControlledPriceField.d.ts.map +1 -1
  71. package/dist/components/controlled/input/ControlledRangeField.d.ts.map +1 -1
  72. package/dist/components/controlled/input/ControlledRangeField.js +1 -1
  73. package/dist/components/controlled/input/ControlledRatingField.d.ts.map +1 -1
  74. package/dist/components/controlled/input/ControlledSwitchField.d.ts.map +1 -1
  75. package/dist/components/controlled/input/ControlledSwitchField.js +1 -1
  76. package/dist/components/controlled/input/ControlledTextField.d.ts.map +1 -1
  77. package/dist/components/controlled/input/ControlledTextField.js +1 -1
  78. package/dist/components/controlled/input/ControlledTextareaField.js +1 -1
  79. package/dist/components/controlled/select/ControlledComboboxField.d.ts.map +1 -1
  80. package/dist/components/controlled/select/ControlledDropdownField.d.ts.map +1 -1
  81. package/dist/components/controlled/select/ControlledMultiDropdownField.d.ts.map +1 -1
  82. package/dist/components/controlled/select/ControlledRadioField.d.ts.map +1 -1
  83. package/dist/components/controlled/select/ControlledReferenceField.d.ts.map +1 -1
  84. package/dist/components/controlled/select/ControlledReferenceField.js +1 -1
  85. package/dist/components/controlled/select/ControlledYearField.d.ts.map +1 -1
  86. package/dist/components/controlled/types.d.ts.map +1 -1
  87. package/dist/components/fields/display/AvatarFieldDisplay.d.ts.map +1 -1
  88. package/dist/components/fields/display/AvatarFieldDisplay.js +1 -1
  89. package/dist/components/fields/display/BadgeFieldDisplay.d.ts.map +1 -1
  90. package/dist/components/fields/display/BadgeFieldDisplay.js +1 -1
  91. package/dist/components/fields/display/ButtonFieldDisplay.d.ts.map +1 -1
  92. package/dist/components/fields/display/CheckboxFieldDisplay.d.ts.map +1 -1
  93. package/dist/components/fields/display/CheckboxFieldDisplay.js +1 -1
  94. package/dist/components/fields/display/DateFieldDisplay.d.ts.map +1 -1
  95. package/dist/components/fields/display/DateFieldDisplay.js +1 -1
  96. package/dist/components/fields/display/DropdownDisplay.d.ts.map +1 -1
  97. package/dist/components/fields/display/FileFieldDisplay.d.ts.map +1 -1
  98. package/dist/components/fields/display/FileFieldDisplay.js +1 -1
  99. package/dist/components/fields/display/GeoPointFieldDisplay.d.ts.map +1 -1
  100. package/dist/components/fields/display/HiddenFieldDisplay.d.ts.map +1 -1
  101. package/dist/components/fields/display/ImageFieldDisplay.d.ts.map +1 -1
  102. package/dist/components/fields/display/LinkFieldDisplay.d.ts.map +1 -1
  103. package/dist/components/fields/display/LinkFieldDisplay.js +1 -1
  104. package/dist/components/fields/display/MapFieldDisplay.d.ts.map +1 -1
  105. package/dist/components/fields/display/MapFieldDisplay.js +1 -1
  106. package/dist/components/fields/display/MultiDropdownDisplay.d.ts.map +1 -1
  107. package/dist/components/fields/display/MultiInputTextFieldDisplay.d.ts.map +1 -1
  108. package/dist/components/fields/display/NumberFieldDisplay.d.ts.map +1 -1
  109. package/dist/components/fields/display/NumberFieldDisplay.js +1 -1
  110. package/dist/components/fields/display/PasswordFieldDisplay.d.ts.map +1 -1
  111. package/dist/components/fields/display/PasswordFieldDisplay.js +1 -1
  112. package/dist/components/fields/display/PhoneNumberDisplay.d.ts.map +1 -1
  113. package/dist/components/fields/display/RadioFieldDisplay.d.ts.map +1 -1
  114. package/dist/components/fields/display/RangeFieldDisplay.d.ts.map +1 -1
  115. package/dist/components/fields/display/ReferenceFieldDisplay.d.ts.map +1 -1
  116. package/dist/components/fields/display/ReferenceFieldDisplay.js +1 -1
  117. package/dist/components/fields/display/RichTextDisplay.d.ts.map +1 -1
  118. package/dist/components/fields/display/TextAreaDisplay.d.ts.map +1 -1
  119. package/dist/components/fields/display/TextAreaDisplay.js +1 -1
  120. package/dist/components/fields/display/TextFieldDisplay.d.ts.map +1 -1
  121. package/dist/components/fields/display/TextFieldDisplay.js +1 -1
  122. package/dist/components/fields/display/TimestampFieldDisplay.d.ts.map +1 -1
  123. package/dist/components/form/fields/AddressFieldComponent.d.ts.map +1 -1
  124. package/dist/components/form/fields/AddressFieldComponent.js +1 -1
  125. package/dist/components/form/fields/AvatarFieldComponent.d.ts.map +1 -1
  126. package/dist/components/form/fields/AvatarFieldComponent.js +1 -1
  127. package/dist/components/form/fields/BadgeFieldComponent.d.ts.map +1 -1
  128. package/dist/components/form/fields/BadgeFieldComponent.js +1 -1
  129. package/dist/components/form/fields/ButtonFieldComponent.js +1 -1
  130. package/dist/components/form/fields/CheckboxFieldComponent.d.ts.map +1 -1
  131. package/dist/components/form/fields/CheckboxFieldComponent.js +1 -1
  132. package/dist/components/form/fields/ComboboxComponent.js +1 -1
  133. package/dist/components/form/fields/CurrencyFieldComponent.js +1 -1
  134. package/dist/components/form/fields/DateFieldComponent.js +1 -1
  135. package/dist/components/form/fields/DocumentFieldComponent.js +1 -1
  136. package/dist/components/form/fields/DropdownComponent.js +1 -1
  137. package/dist/components/form/fields/DurationFieldComponent.js +1 -1
  138. package/dist/components/form/fields/FileFieldComponent.js +1 -1
  139. package/dist/components/form/fields/GdprConsentFieldComponent.d.ts.map +1 -1
  140. package/dist/components/form/fields/GdprConsentFieldComponent.js +1 -1
  141. package/dist/components/form/fields/GeoPointFieldComponent.js +1 -1
  142. package/dist/components/form/fields/ImageFieldComponent.js +1 -1
  143. package/dist/components/form/fields/MapFieldComponent.d.ts.map +1 -1
  144. package/dist/components/form/fields/MultiDropdownComponent.js +1 -1
  145. package/dist/components/form/fields/MultiInputTextFieldComponent.js +1 -1
  146. package/dist/components/form/fields/NumberFieldComponent.js +1 -1
  147. package/dist/components/form/fields/PasswordFieldComponent.js +1 -1
  148. package/dist/components/form/fields/PhoneNumberComponent.js +1 -1
  149. package/dist/components/form/fields/PriceFieldComponent.js +1 -1
  150. package/dist/components/form/fields/RangeFieldComponent.js +1 -1
  151. package/dist/components/form/fields/RatingFieldComponent.js +1 -1
  152. package/dist/components/form/fields/ReferenceFieldComponent.js +1 -1
  153. package/dist/components/form/fields/RichTextComponent.js +1 -1
  154. package/dist/components/form/fields/SwitchFieldComponent.d.ts.map +1 -1
  155. package/dist/components/form/fields/SwitchFieldComponent.js +1 -1
  156. package/dist/components/form/fields/TextAreaComponent.js +1 -1
  157. package/dist/components/form/fields/TextFieldComponent.js +1 -1
  158. package/dist/components/form/fields/TimestampFieldComponent.js +1 -1
  159. package/dist/components/form/fields/internal/InlineFieldRow.d.ts +24 -0
  160. package/dist/components/form/fields/internal/InlineFieldRow.d.ts.map +1 -0
  161. package/dist/components/form/fields/internal/InlineFieldRow.js +1 -0
  162. package/dist/components/form/fields/internal/TiptapEditor.d.ts.map +1 -1
  163. package/dist/components/form/fields/internal/TiptapEditor.js +2 -2
  164. package/dist/components/form/internal/ImageViewerDialog.js +1 -1
  165. package/dist/fieldTypeRegistry.store.js +1 -1
  166. package/dist/fieldTypeRegistry.types.d.ts.map +1 -1
  167. package/dist/forms/hooks/useController.js +1 -1
  168. package/dist/forms/hooks/useEntityField.d.ts.map +1 -1
  169. package/dist/forms/hooks/useEntityField.js +1 -1
  170. package/dist/forms/hooks/useEntityForm.d.ts.map +1 -1
  171. package/dist/forms/hooks/useEntityForm.js +1 -1
  172. package/dist/forms/utils/buildInitialValues.js +1 -1
  173. package/dist/forms/utils/isFieldEditable.js +1 -1
  174. package/dist/forms/utils/translateFieldLabel.d.ts +1 -9
  175. package/dist/forms/utils/translateFieldLabel.d.ts.map +1 -1
  176. package/dist/forms/utils/translateFieldLabel.js +1 -1
  177. package/dist/forms/utils/validateEntity.js +1 -1
  178. package/dist/hooks/useCrudFilters.js +1 -1
  179. package/dist/hooks/useCrudPageSize.js +1 -1
  180. package/dist/hooks/useEntityFavorites.js +1 -1
  181. package/dist/hooks/useFileUpload.js +1 -1
  182. package/dist/hooks/useReferenceResolver.d.ts.map +1 -1
  183. package/dist/hooks/useReferenceResolver.js +1 -1
  184. package/dist/hooks/useRelatedItems.js +1 -1
  185. package/dist/registerBuiltinFieldTypes.d.ts +2 -2
  186. package/dist/registerBuiltinFieldTypes.d.ts.map +1 -1
  187. package/dist/registerBuiltinFieldTypes.js +1 -1
  188. package/dist/stores/FormStore.js +1 -1
  189. package/dist/stores/UploadStore.js +1 -1
  190. package/dist/symbol-index.json +1 -1
  191. package/dist/tsconfig.tsbuildinfo +1 -1
  192. package/dist/types.d.ts +2 -1
  193. package/dist/types.d.ts.map +1 -1
  194. package/dist/useBaseCrudList.d.ts.map +1 -1
  195. package/dist/useBaseCrudList.js +1 -1
  196. package/dist/useCrud.d.ts +13 -4
  197. package/dist/useCrud.d.ts.map +1 -1
  198. package/dist/useCrud.js +1 -1
  199. package/dist/useCrudCardList.js +1 -1
  200. package/dist/useCrudDoc.d.ts.map +1 -1
  201. package/dist/useCrudDoc.js +1 -1
  202. package/dist/useCrudList.js +1 -1
  203. package/dist/utils/clientListProcessing.d.ts.map +1 -1
  204. package/dist/utils/clientListProcessing.js +1 -1
  205. package/dist/utils/collections.js +1 -1
  206. package/dist/utils/imageProcessing.js +1 -1
  207. package/dist/utils/matchesFilter.d.ts.map +1 -1
  208. package/dist/utils/matchesFilter.js +1 -1
  209. package/dist/utils/referenceEntity.d.ts +11 -0
  210. package/dist/utils/referenceEntity.d.ts.map +1 -0
  211. package/dist/utils/referenceEntity.js +1 -0
  212. package/dist/utils/uploadValidation.js +1 -1
  213. package/dist/utils/useRowTranslator.d.ts +21 -0
  214. package/dist/utils/useRowTranslator.d.ts.map +1 -0
  215. package/dist/utils/useRowTranslator.js +1 -0
  216. package/dist/workflows/defineWorkflow.js +1 -1
  217. package/dist/workflows/useEntityWorkflow.js +1 -1
  218. package/guidelines/COMPONENTS.md +6 -0
  219. package/guidelines/CRUD.md +96 -12
  220. package/guidelines/GOTCHAS.md +2 -0
  221. package/package.json +8 -8
  222. package/dist/builtinFieldTypes.d.ts +0 -23
  223. package/dist/builtinFieldTypes.d.ts.map +0 -1
  224. package/dist/builtinFieldTypes.js +0 -1
@@ -17,11 +17,13 @@ export interface BulkSchemas<T extends Record<string, unknown>> {
17
17
  update?: dndevSchema<T>;
18
18
  }
19
19
  /**
20
- * Transactional bulk CRUD: inserts + updates + deletes in one round-trip.
20
+ * Bulk CRUD: inserts + updates + deletes in one adapter call, partial success.
21
21
  *
22
- * Atomically applies optimistic state, calls the adapter under timeout + retry,
23
- * then either confirms all three buckets or rolls them back together. Emits a
24
- * single audit entry, a single rate-limit check, and at most one success toast.
22
+ * Applies optimistic state, calls the adapter under timeout + retry, then
23
+ * confirms the rows the adapter wrote and reverts only the rows it reports in
24
+ * `failed` (written rows are never undone). If the adapter throws (batch not
25
+ * attempted), every optimistic op is reverted. Emits a single audit entry, a
26
+ * single rate-limit check, and one toast (error when some rows failed).
25
27
  *
26
28
  * **Concurrency contract.** `bulk()` does not acquire the per-(collection,id)
27
29
  * locks used by single-row mutations (`runSerializedMutation`). A concurrent
@@ -35,10 +37,10 @@ export interface BulkSchemas<T extends Record<string, unknown>> {
35
37
  * @param ops - Bulk operations. Empty payload short-circuits with no side effects.
36
38
  * @param schemas - Schemas for insert validation + PII resolution.
37
39
  * @param options - Optional mutation options (toast suppression).
38
- * @returns Server-echoed ids, order-preserved per bucket.
40
+ * @returns Written ids per bucket (input order) and the rows that failed.
39
41
  * @throws {BulkCollisionError} Same id in two mutually-exclusive buckets.
40
42
  * Surfaced **before** any side effect (no rate-limit, no optimistic, no adapter call).
41
- * @throws {Error} Wrapped adapter errors — surfaced after rollback.
43
+ * @throws {Error} Wrapped adapter errors (batch not attempted) — surfaced after rollback.
42
44
  *
43
45
  * @example
44
46
  * ```typescript
@@ -1 +1 @@
1
- {"version":3,"file":"CrudService.bulk.d.ts","sourceRoot":"","sources":["../src/CrudService.bulk.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EAEV,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAsBx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AAC,CAAC,CAAC,CAAC;CACzB;AA2DD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAsB,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9D,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,EACtB,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,EACvB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,UAAU,CAAC,CAwVrB"}
@@ -1 +1 @@
1
- import{toast as v}from"@donotdev/components";import{BulkCollisionError as L,detectBulkCollisions as j,DEFAULT_STATUS_VALUE as R,generateUUID as _,getI18nInstance as T,handleError as F,validateWithSchema as N}from"@donotdev/core";import{updateListCaches as h}from"./CrudService.cache";import{assertCanAccess as b,ensureAdapter as Q,getEntityName as C,getPiiFields as O,rateLimitKey as $,shouldShowSuccessToast as B,withResilience as K}from"./CrudService.internal";import{CRUD_OPERATION as m}from"./types";function M(t,e,p){const i=t.getQueryClient(),y=new Map;if(p.length===0)return y;const S=i.getQueriesData({queryKey:["crud",e]});for(const c of p){const g=i.getQueryData(["crud",e,"get",c]);if(g!=null){y.set(c,g);continue}let f=null;for(const[,E]of S){const D=E&&typeof E=="object"&&"items"in E?E.items:null;if(!D)continue;const w=D.find(A=>A?.id===c);if(w){f=w;break}}y.set(c,f)}return y}async function q(t,e,p,i,y){const S=j({inserts:p.inserts,updates:p.updates,deletes:p.deletes});if(S.where!==null)throw new L(S.collisions,S.where);const c=p.inserts??[],g=p.updates??[],f=p.deletes??[];if(c.length===0&&g.length===0&&f.length===0)return{insertedIds:[],updatedIds:[],deletedIds:[]};await Q(t),t.store&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null)),i.create?b(t.adapter,e,i.create):i.update&&b(t.adapter,e,i.update),t.security&&await t.security.checkRateLimit($(t,e),"write");const E=O(i.create??i.draft),D=O(i.update??i.create),w=c.map(d=>{const n=d,a=n.status===void 0||n.status===null?{...n,status:R}:n,u=a.status==="draft"&&i.draft?i.draft:i.create??i.draft,s=u?N(u,a,"CrudService.bulk.insert"):a;return E.length>0&&t.security?t.security.encryptPii(s,E):s}),A=g.map(({id:d,patch:n})=>{const a=n,u=D.length>0&&t.security?t.security.encryptPii(a,D):n;return{id:d,patch:u}}),I={inserts:[],updates:[],deletes:[]},P=[...g.map(d=>d.id),...f],U=M(t,e,P),k=c.map(()=>`temp_${_()}`);try{if(c.forEach((s,r)=>{const o=k[r],l={...s,id:o};t.store&&t.store.getState().addOptimistic(e,o,l),h(t,e,o,l,m.ADD),I.inserts.push({tempId:o,data:l})}),g.forEach(({id:s,patch:r})=>{const o=U.get(s)??null,l=o?{...o,...r}:{...r,id:s};t.store&&t.store.getState().updateOptimistic(e,s,l,o??null),h(t,e,s,l,m.UPDATE),I.updates.push({id:s,prev:o,merged:l})}),f.forEach(s=>{const r=U.get(s)??null;t.store&&r&&t.store.getState().deleteOptimistic(e,s,r),h(t,e,s,null,m.DELETE),I.deletes.push({id:s,prev:r})}),!t.adapter)throw new Error(`[dndev] Adapter not initialized for "${e}" bulk().`);const d=t.adapter,n={inserts:w,updates:A,deletes:f},a=await K(()=>d.bulk(e,n)),u=a.insertedIds??[];if(k.forEach((s,r)=>{const o=u[r];if(!o)return;const l=c[r];h(t,e,s,null,m.DELETE),h(t,e,o,l,m.ADD),t.store&&t.store.getState().confirmOptimistic(e,s,o,l)}),(a.updatedIds??[]).forEach(s=>{t.store&&t.store.getState().confirmUpdate(e,s)}),(a.deletedIds??[]).forEach(s=>{t.store&&t.store.getState().confirmDelete(e,s)}),t.security&&(t.security.audit({type:"crud.bulk",collection:e,userId:t.currentUserId??void 0,metadata:{inserts:c.length,updates:g.length,deletes:f.length}}),f.length>0&&t.security.recordAnomaly?.("bulk.deletes",t.currentUserId??void 0)),u.length+(a.updatedIds?.length??0)+(a.deletedIds?.length??0)>0&&B(t,y)){const s=T(),r=C(e);v("success",s.t("messages.updateSuccess",{ns:"crud",entity:r}))}return{insertedIds:u,updatedIds:a.updatedIds??[],deletedIds:a.deletedIds??[]}}catch(d){for(const{id:s,prev:r}of I.deletes)r&&h(t,e,s,r,m.ADD),t.store&&t.store.getState().rejectDelete(e,s);for(const{id:s,prev:r}of I.updates)r?h(t,e,s,r,m.UPDATE):t.invalidateCollection(e),t.store&&t.store.getState().rejectUpdate(e,s);for(const{tempId:s}of I.inserts)h(t,e,s,null,m.DELETE),t.store&&t.store.getState().rejectOptimistic(e,s);if(d instanceof L)throw t.store&&t.store.getState().setError(e,d),d;const n=F(d,{userMessage:`Failed to bulk-write ${e}`,showNotification:!0}),a=T(),u=C(e);throw v("error",a.t("messages.updateError",{ns:"crud",entity:u})),t.store&&t.store.getState().setError(e,n),n}finally{t.store&&t.store.getState().setLoading(e,!1)}}export{q as bulkImpl};
1
+ import{toast as b}from"@donotdev/components";import{BulkCollisionError as R,detectBulkCollisions as B,DEFAULT_STATUS_VALUE as K,generateUUID as M,getI18nInstance as L,handleError as q,validateWithSchema as z}from"@donotdev/core";import{updateListCaches as E}from"./CrudService.cache";import{assertCanAccess as _,ensureAdapter as V,getEntityName as x,getPiiFields as F,rateLimitKey as W,shouldShowSuccessToast as G,withResilience as H}from"./CrudService.internal";import{CRUD_OPERATION as y}from"./types";function J(t,r,p){const d=t.getQueryClient(),w=new Map;if(p.length===0)return w;const I=d.getQueriesData({queryKey:["crud",r]});for(const l of p){const g=d.getQueryData(["crud",r,"get",l]);if(g!=null){w.set(l,g);continue}let f=null;for(const[,S]of I){const D=S&&typeof S=="object"&&"items"in S?S.items:null;if(!D)continue;const A=D.find(k=>k?.id===l);if(A){f=A;break}}w.set(l,f)}return w}async function X(t,r,p,d,w){const I=B({inserts:p.inserts,updates:p.updates,deletes:p.deletes});if(I.where!==null)throw new R(I.collisions,I.where);const l=p.inserts??[],g=p.updates??[],f=p.deletes??[];if(l.length===0&&g.length===0&&f.length===0)return{insertedIds:[],updatedIds:[],deletedIds:[],failed:[]};await V(t),t.store&&(t.store.getState().setLoading(r,!0),t.store.getState().setError(r,null)),d.create?_(t.adapter,r,d.create):d.update&&_(t.adapter,r,d.update),t.security&&await t.security.checkRateLimit(W(t,r),"write");const S=F(d.create??d.draft),D=F(d.update??d.create),A=l.map(s=>{const i=s,a=i.status===void 0||i.status===null?{...i,status:K}:i,m=a.status==="draft"&&d.draft?d.draft:d.create??d.draft,c=m?z(m,a,"CrudService.bulk.insert"):a;return S.length>0&&t.security?t.security.encryptPii(c,S):c}),k=g.map(({id:s,patch:i})=>{const a=i,m=D.length>0&&t.security?t.security.encryptPii(a,D):i;return{id:s,patch:m}}),h={inserts:[],updates:[],deletes:[]},N=[...g.map(s=>s.id),...f],T=J(t,r,N),C=l.map(()=>`temp_${M()}`),O=s=>{E(t,r,s,null,y.DELETE),t.store&&t.store.getState().rejectOptimistic(r,s)},P=(s,i)=>{i?E(t,r,s,i,y.UPDATE):t.invalidateCollection(r),t.store&&t.store.getState().rejectUpdate(r,s)},j=(s,i)=>{i&&E(t,r,s,i,y.ADD),t.store&&t.store.getState().rejectDelete(r,s)};try{if(l.forEach((e,o)=>{const n=C[o],u={...e,id:n};t.store&&t.store.getState().addOptimistic(r,n,u),E(t,r,n,u,y.ADD),h.inserts.push({tempId:n,data:u})}),g.forEach(({id:e,patch:o})=>{const n=T.get(e)??null,u=n?{...n,...o}:{...o,id:e};t.store&&t.store.getState().updateOptimistic(r,e,u,n??null),E(t,r,e,u,y.UPDATE),h.updates.push({id:e,prev:n,merged:u})}),f.forEach(e=>{const o=T.get(e)??null;t.store&&o&&t.store.getState().deleteOptimistic(r,e,o),E(t,r,e,null,y.DELETE),h.deletes.push({id:e,prev:o})}),!t.adapter)throw new Error(`[dndev] Adapter not initialized for "${r}" bulk().`);const s=t.adapter,i={inserts:A,updates:k,deletes:f},a=await H(()=>s.bulk(r,i)),m=new Set(a.failed.filter(e=>e.op==="insert"&&e.index!==void 0).map(e=>e.index)),c=new Set(a.failed.filter(e=>e.op==="update").map(e=>e.id)),v=new Set(a.failed.filter(e=>e.op==="delete").map(e=>e.id)),U=a.insertedIds;let Q=0;C.forEach((e,o)=>{if(m.has(o)){O(e);return}const n=U[Q++];if(!n)return;const u=l[o];E(t,r,e,null,y.DELETE),E(t,r,n,u,y.ADD),t.store&&t.store.getState().confirmOptimistic(r,e,n,u)});for(const{id:e,prev:o}of h.updates)c.has(e)?P(e,o):t.store&&t.store.getState().confirmUpdate(r,e);for(const{id:e,prev:o}of h.deletes)v.has(e)?j(e,o):t.store&&t.store.getState().confirmDelete(r,e);t.security&&(t.security.audit({type:"crud.bulk",collection:r,userId:t.currentUserId??void 0,metadata:{inserts:l.length,updates:g.length,deletes:f.length}}),f.length>0&&t.security.recordAnomaly?.("bulk.deletes",t.currentUserId??void 0));const $=U.length+a.updatedIds.length+a.deletedIds.length>0;if(a.failed.length>0){const e=L();b("error",e.t("messages.bulkPartialError",{ns:"crud",count:a.failed.length}))}else if($&&G(t,w)){const e=L(),o=x(r);b("success",e.t("messages.updateSuccess",{ns:"crud",entity:o}))}return{insertedIds:U,updatedIds:a.updatedIds,deletedIds:a.deletedIds,failed:a.failed}}catch(s){for(const{id:c,prev:v}of h.deletes)j(c,v);for(const{id:c,prev:v}of h.updates)P(c,v);for(const{tempId:c}of h.inserts)O(c);if(s instanceof R)throw t.store&&t.store.getState().setError(r,s),s;const i=q(s,{userMessage:`Failed to bulk-write ${r}`,showNotification:!0}),a=L(),m=x(r);throw b("error",a.t("messages.updateError",{ns:"crud",entity:m})),t.store&&t.store.getState().setError(r,i),i}finally{t.store&&t.store.getState().setLoading(r,!1)}}export{X as bulkImpl};
@@ -2,10 +2,12 @@ import type { BulkAcrossBatch, BulkAcrossResult } from '@donotdev/core';
2
2
  import type { CrudServiceInternal, MutationOptions } from './types';
3
3
  type AnyBatch = BulkAcrossBatch<Record<string, unknown>>;
4
4
  /**
5
- * Cross-collection atomic bulk write.
5
+ * Cross-collection bulk write.
6
6
  *
7
7
  * One optimistic pass across all collections, adapter writes in topological
8
- * order, one toast. Any wave failure rolls back ALL collections' optimistic ops.
8
+ * order, one toast. A wave that throws or reports rows not written stops the
9
+ * chain: optimistic ops are rolled back and the collections refetched (rows
10
+ * already written by earlier waves stay written).
9
11
  *
10
12
  * @param self - CrudService instance.
11
13
  * @param batches - Per-collection operations. Each carries its own schemas.
@@ -1 +1 @@
1
- {"version":3,"file":"CrudService.bulkAcross.d.ts","sourceRoot":"","sources":["../src/CrudService.bulkAcross.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAEjB,MAAM,gBAAgB,CAAC;AAsBxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEpE,KAAK,QAAQ,GAAG,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AA0GzD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,mBAAmB,EACzB,OAAO,EAAE,QAAQ,EAAE,EACnB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,gBAAgB,CAAC,CAuW3B"}
1
+ {"version":3,"file":"CrudService.bulkAcross.d.ts","sourceRoot":"","sources":["../src/CrudService.bulkAcross.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAEjB,MAAM,gBAAgB,CAAC;AAsBxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEpE,KAAK,QAAQ,GAAG,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AA0GzD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,mBAAmB,EACzB,OAAO,EAAE,QAAQ,EAAE,EACnB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,gBAAgB,CAAC,CAoX3B"}
@@ -1 +1 @@
1
- import{toast as A}from"@donotdev/components";import{BulkAcrossCycleError as U,BulkCollisionError as T,DEFAULT_STATUS_VALUE as L,detectBulkCollisions as O,generateUUID as C,getI18nInstance as v,handleError as P,validateWithSchema as _}from"@donotdev/core";import{updateListCaches as I}from"./CrudService.cache";import{assertCanAccess as j,ensureAdapter as M,getPiiFields as k,rateLimitKey as R,shouldShowSuccessToast as $,withResilience as B}from"./CrudService.internal";import{CRUD_OPERATION as b}from"./types";function F(t,y,h){const d=t.getQueryClient(),m=new Map;if(h.length===0)return m;const u=d.getQueriesData({queryKey:["crud",y]});for(const n of h){const e=d.getQueryData(["crud",y,"get",n]);if(e!=null){m.set(n,e);continue}let a=null;for(const[,r]of u){const o=r&&typeof r=="object"&&"items"in r?r.items:null;if(!o)continue;const i=o.find(s=>s?.id===n);if(i){a=i;break}}m.set(n,a)}return m}function Q(t){const y=new Map,h=new Map,d=new Map;for(const n of t){y.set(n.collection,n),h.set(n.collection,(n.dependsOn??[]).length);for(const e of n.dependsOn??[])d.has(e)||d.set(e,[]),d.get(e).push(n.collection)}const m=[];let u=[...h.entries()].filter(([,n])=>n===0).map(([n])=>n);for(;u.length>0;){m.push(u.map(e=>y.get(e)));const n=[];for(const e of u)for(const a of d.get(e)??[]){const r=(h.get(a)??0)-1;h.set(a,r),r===0&&n.push(a)}u=n}if(m.reduce((n,e)=>n+e.length,0)!==t.length){const n=[...h.entries()].filter(([,e])=>e>0).map(([e])=>e);throw new U(n)}return m}async function q(t,y,h){for(const e of y){const a=O({inserts:e.inserts,updates:e.updates,deletes:e.deletes});if(a.where!==null)throw new T(a.collisions,a.where)}const d=y.filter(e=>(e.inserts?.length??0)+(e.updates?.length??0)+(e.deletes?.length??0)>0);if(d.length===0)return{results:{}};const m=Q(d);await M(t);for(const e of d)t.store&&(t.store.getState().setLoading(e.collection,!0),t.store.getState().setError(e.collection,null));for(const e of d)j(t.adapter,e.collection,e.schemas.create??e.schemas.update);t.security&&await t.security.checkRateLimit(R(t,d[0].collection),"write");const u=d.map(e=>{const a=k(e.schemas.create??e.schemas.draft),r=k(e.schemas.update??e.schemas.create),o=(e.inserts??[]).map(s=>{const c=s,f=c.status==null?{...c,status:L}:c,p=f.status==="draft"&&e.schemas.draft?e.schemas.draft:e.schemas.create??e.schemas.draft,E=p?_(p,f,"CrudService.bulkAcross.insert"):f;return a.length>0&&t.security?t.security.encryptPii(E,a):E}),i=(e.updates??[]).map(({id:s,patch:c})=>{const f=c;return{id:s,patch:r.length>0&&t.security?t.security.encryptPii(f,r):f}});return{batch:e,encryptedInserts:o,encryptedUpdates:i}}),n=new Map;try{for(const{batch:r,encryptedInserts:o,encryptedUpdates:i}of u){const{collection:s,deletes:c=[]}=r,f=o.map(()=>`temp_${C()}`),p=[...(r.updates??[]).map(l=>l.id),...c],E=F(t,s,p),w={insertTempIds:f,inserts:[],updates:[],deletes:[]};o.forEach((l,S)=>{const g=f[S],D={...l,id:g};t.store&&t.store.getState().addOptimistic(s,g,D),I(t,s,g,D,b.ADD),w.inserts.push({tempId:g,originalRow:l})}),i.forEach(({id:l,patch:S})=>{const g=E.get(l)??null,D=g?{...g,...S}:{...S,id:l};t.store&&t.store.getState().updateOptimistic(s,l,D,g),I(t,s,l,D,b.UPDATE),w.updates.push({id:l,prev:g})}),c.forEach(l=>{const S=E.get(l)??null;t.store&&S&&t.store.getState().deleteOptimistic(s,l,S),I(t,s,l,null,b.DELETE),w.deletes.push({id:l,prev:S})}),n.set(s,w)}if(!t.adapter)throw new Error("[dndev] Adapter not initialized for bulkAcross().");const e=t.adapter,a={};for(const r of m){const o=r.map(s=>u.find(c=>c.batch.collection===s.collection)),i=await Promise.all(o.map(({batch:s,encryptedInserts:c,encryptedUpdates:f})=>B(()=>e.bulk(s.collection,{inserts:c,updates:f,deletes:s.deletes})).then(p=>({collection:s.collection,result:p}))));for(const{collection:s,result:c}of i)a[s]=c}for(const{batch:r,encryptedInserts:o}of u){const{collection:i}=r,s=a[i];if(!s)continue;const c=n.get(i),f=s.insertedIds??[];c.insertTempIds.forEach((p,E)=>{const w=f[E];if(!w)return;const l=o[E];I(t,i,p,null,b.DELETE),I(t,i,w,l,b.ADD),t.store&&t.store.getState().confirmOptimistic(i,p,w,l)}),(s.updatedIds??[]).forEach(p=>{t.store&&t.store.getState().confirmUpdate(i,p)}),(s.deletedIds??[]).forEach(p=>{t.store&&t.store.getState().confirmDelete(i,p)})}if(t.security){const r={};for(const{batch:o}of u)r[`${o.collection}_inserts`]=(o.inserts??[]).length,r[`${o.collection}_updates`]=(o.updates??[]).length,r[`${o.collection}_deletes`]=(o.deletes??[]).length;t.security.audit({type:"crud.bulk",collection:d.map(o=>o.collection).join(","),userId:t.currentUserId??void 0,metadata:r})}if(Object.values(a).some(r=>(r.insertedIds?.length??0)+(r.updatedIds?.length??0)+(r.deletedIds?.length??0)>0)&&$(t,h)){const r=v();A("success",r.t("messages.updateSuccess",{ns:"crud",entity:""}))}return{results:a}}catch(e){for(const[o,i]of n){for(const{id:s,prev:c}of i.deletes)c&&I(t,o,s,c,b.ADD),t.store&&t.store.getState().rejectDelete(o,s);for(const{id:s,prev:c}of i.updates)c?I(t,o,s,c,b.UPDATE):t.invalidateCollection(o),t.store&&t.store.getState().rejectUpdate(o,s);for(const{tempId:s}of i.inserts)I(t,o,s,null,b.DELETE),t.store&&t.store.getState().rejectOptimistic(o,s)}if(e instanceof T||e instanceof U){for(const{batch:o}of u)t.store&&t.store.getState().setError(o.collection,e);throw e}const a=P(e,{userMessage:"Failed to save across collections",showNotification:!0}),r=v();A("error",r.t("messages.updateError",{ns:"crud",entity:""}));for(const{batch:o}of u)t.store&&t.store.getState().setError(o.collection,a);throw a}finally{for(const{batch:e}of u)t.store&&t.store.getState().setLoading(e.collection,!1)}}export{q as bulkAcrossImpl};
1
+ import{toast as D}from"@donotdev/components";import{BulkAcrossCycleError as U,BulkCollisionError as v,DEFAULT_STATUS_VALUE as C,detectBulkCollisions as L,generateUUID as O,getI18nInstance as T,handleError as j,validateWithSchema as P}from"@donotdev/core";import{updateListCaches as S}from"./CrudService.cache";import{assertCanAccess as _,ensureAdapter as $,getPiiFields as k,rateLimitKey as M,shouldShowSuccessToast as R,withResilience as B}from"./CrudService.internal";import{CRUD_OPERATION as b}from"./types";function F(t,E,h){const u=t.getQueryClient(),g=new Map;if(h.length===0)return g;const f=u.getQueriesData({queryKey:["crud",E]});for(const c of h){const e=u.getQueryData(["crud",E,"get",c]);if(e!=null){g.set(c,e);continue}let a=null;for(const[,r]of f){const s=r&&typeof r=="object"&&"items"in r?r.items:null;if(!s)continue;const i=s.find(o=>o?.id===c);if(i){a=i;break}}g.set(c,a)}return g}function Q(t){const E=new Map,h=new Map,u=new Map;for(const c of t){E.set(c.collection,c),h.set(c.collection,(c.dependsOn??[]).length);for(const e of c.dependsOn??[])u.has(e)||u.set(e,[]),u.get(e).push(c.collection)}const g=[];let f=[...h.entries()].filter(([,c])=>c===0).map(([c])=>c);for(;f.length>0;){g.push(f.map(e=>E.get(e)));const c=[];for(const e of f)for(const a of u.get(e)??[]){const r=(h.get(a)??0)-1;h.set(a,r),r===0&&c.push(a)}f=c}if(g.reduce((c,e)=>c+e.length,0)!==t.length){const c=[...h.entries()].filter(([,e])=>e>0).map(([e])=>e);throw new U(c)}return g}async function q(t,E,h){for(const e of E){const a=L({inserts:e.inserts,updates:e.updates,deletes:e.deletes});if(a.where!==null)throw new v(a.collisions,a.where)}const u=E.filter(e=>(e.inserts?.length??0)+(e.updates?.length??0)+(e.deletes?.length??0)>0);if(u.length===0)return{results:{}};const g=Q(u);await $(t);for(const e of u)t.store&&(t.store.getState().setLoading(e.collection,!0),t.store.getState().setError(e.collection,null));for(const e of u)_(t.adapter,e.collection,e.schemas.create??e.schemas.update);t.security&&await t.security.checkRateLimit(M(t,u[0].collection),"write");const f=u.map(e=>{const a=k(e.schemas.create??e.schemas.draft),r=k(e.schemas.update??e.schemas.create),s=(e.inserts??[]).map(o=>{const n=o,l=n.status==null?{...n,status:C}:n,p=l.status==="draft"&&e.schemas.draft?e.schemas.draft:e.schemas.create??e.schemas.draft,m=p?P(p,l,"CrudService.bulkAcross.insert"):l;return a.length>0&&t.security?t.security.encryptPii(m,a):m}),i=(e.updates??[]).map(({id:o,patch:n})=>{const l=n;return{id:o,patch:r.length>0&&t.security?t.security.encryptPii(l,r):l}});return{batch:e,encryptedInserts:s,encryptedUpdates:i}}),c=new Map;try{for(const{batch:r,encryptedInserts:s,encryptedUpdates:i}of f){const{collection:o,deletes:n=[]}=r,l=s.map(()=>`temp_${O()}`),p=[...(r.updates??[]).map(d=>d.id),...n],m=F(t,o,p),w={insertTempIds:l,inserts:[],updates:[],deletes:[]};s.forEach((d,I)=>{const y=l[I],A={...d,id:y};t.store&&t.store.getState().addOptimistic(o,y,A),S(t,o,y,A,b.ADD),w.inserts.push({tempId:y,originalRow:d})}),i.forEach(({id:d,patch:I})=>{const y=m.get(d)??null,A=y?{...y,...I}:{...I,id:d};t.store&&t.store.getState().updateOptimistic(o,d,A,y),S(t,o,d,A,b.UPDATE),w.updates.push({id:d,prev:y})}),n.forEach(d=>{const I=m.get(d)??null;t.store&&I&&t.store.getState().deleteOptimistic(o,d,I),S(t,o,d,null,b.DELETE),w.deletes.push({id:d,prev:I})}),c.set(o,w)}if(!t.adapter)throw new Error("[dndev] Adapter not initialized for bulkAcross().");const e=t.adapter,a={};for(const r of g){const s=r.map(n=>f.find(l=>l.batch.collection===n.collection)),i=await Promise.all(s.map(({batch:n,encryptedInserts:l,encryptedUpdates:p})=>B(()=>e.bulk(n.collection,{inserts:l,updates:p,deletes:n.deletes})).then(m=>({collection:n.collection,result:m}))));for(const{collection:n,result:l}of i)a[n]=l;const o=i.filter(({result:n})=>n.failed.length>0);if(o.length>0)throw new Error(`bulkAcross: rows not written in ${o.map(({collection:n,result:l})=>`${n} (${l.failed.length})`).join(", ")}`)}for(const{batch:r,encryptedInserts:s}of f){const{collection:i}=r,o=a[i];if(!o)continue;const n=c.get(i),l=o.insertedIds??[];n.insertTempIds.forEach((p,m)=>{const w=l[m];if(!w)return;const d=s[m];S(t,i,p,null,b.DELETE),S(t,i,w,d,b.ADD),t.store&&t.store.getState().confirmOptimistic(i,p,w,d)}),(o.updatedIds??[]).forEach(p=>{t.store&&t.store.getState().confirmUpdate(i,p)}),(o.deletedIds??[]).forEach(p=>{t.store&&t.store.getState().confirmDelete(i,p)})}if(t.security){const r={};for(const{batch:s}of f)r[`${s.collection}_inserts`]=(s.inserts??[]).length,r[`${s.collection}_updates`]=(s.updates??[]).length,r[`${s.collection}_deletes`]=(s.deletes??[]).length;t.security.audit({type:"crud.bulk",collection:u.map(s=>s.collection).join(","),userId:t.currentUserId??void 0,metadata:r})}if(Object.values(a).some(r=>(r.insertedIds?.length??0)+(r.updatedIds?.length??0)+(r.deletedIds?.length??0)>0)&&R(t,h)){const r=T();D("success",r.t("messages.updateSuccess",{ns:"crud",entity:""}))}return{results:a}}catch(e){for(const[s,i]of c){t.invalidateCollection(s);for(const{id:o,prev:n}of i.deletes)n&&S(t,s,o,n,b.ADD),t.store&&t.store.getState().rejectDelete(s,o);for(const{id:o,prev:n}of i.updates)n?S(t,s,o,n,b.UPDATE):t.invalidateCollection(s),t.store&&t.store.getState().rejectUpdate(s,o);for(const{tempId:o}of i.inserts)S(t,s,o,null,b.DELETE),t.store&&t.store.getState().rejectOptimistic(s,o)}if(e instanceof v||e instanceof U){for(const{batch:s}of f)t.store&&t.store.getState().setError(s.collection,e);throw e}const a=j(e,{userMessage:"Failed to save across collections",showNotification:!0}),r=T();D("error",r.t("messages.updateError",{ns:"crud",entity:""}));for(const{batch:s}of f)t.store&&t.store.getState().setError(s.collection,a);throw a}finally{for(const{batch:e}of f)t.store&&t.store.getState().setLoading(e.collection,!1)}}export{q as bulkAcrossImpl};
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * Cache keys:
7
7
  * - `['crud', collection, 'get', id]` single document
8
- * - `['crud', collection, 'query', JSON(opts)]` list + listCard (shared)
8
+ * - `['crud', collection, 'query', JSON(opts)]` list + listCard (shared, full visible rows)
9
9
  *
10
10
  * Prefix `['crud', collection]` fans out across both — used when a mutation
11
11
  * must refresh every derived view.
@@ -14,8 +14,27 @@
14
14
  * @since 0.0.1
15
15
  * @author AMBROISE PARK Consulting
16
16
  */
17
- import type { dndevSchema } from '@donotdev/core';
17
+ import type { dndevSchema, QueryClient, QueryOptions } from '@donotdev/core';
18
18
  import type { CrudOperation, CrudServiceInternal } from './types';
19
+ /**
20
+ * Cache key of one list query, shared by list and listCard: both read the full
21
+ * visible record (`schemas.get`), and `listFields` / `listCardFields` only choose
22
+ * what each view displays. One network read serves both views and the doc cache.
23
+ */
24
+ export declare function listQueryKey(collection: string, options: QueryOptions): readonly ['crud', string, 'query', string];
25
+ /**
26
+ * The freshest cached list row of one document. List reads hold the full visible
27
+ * record (same read as `get`), so a document already listed opens without a request:
28
+ * the doc query starts from this row (`initialData`) and refetches only once the
29
+ * list entry it came from is stale.
30
+ *
31
+ * @param queryClient - The client that renders (request-scoped on the server)
32
+ * @returns The row and its list entry's `dataUpdatedAt`, or undefined when not listed
33
+ */
34
+ export declare function cachedListRow<T>(queryClient: QueryClient, collection: string, id: string): {
35
+ data: T;
36
+ updatedAt: number;
37
+ } | undefined;
19
38
  /**
20
39
  * Update single document GET cache after mutation.
21
40
  * Key format: ['crud', collection, 'get', id]
@@ -1 +1 @@
1
- {"version":3,"file":"CrudService.cache.d.ts","sourceRoot":"","sources":["../src/CrudService.cache.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAQlE;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,IAAI,EA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,EAC7B,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,GACT;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAkB5C;AAQD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,CAAC,GAAG,IAAI,EACd,SAAS,EAAE,aAAa,GACvB,IAAI,CAmCN;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,CAAC,GAAG,IAAI,EACd,SAAS,EAAE,aAAa,GACvB,IAAI,CA2GN;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EACxC,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GACrB,MAAM,GAAG,IAAI,CA0Ef;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,GACT,CAAC,GAAG,IAAI,CAcV;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAKf"}
@@ -1 +1 @@
1
- import{handleError as g}from"@donotdev/core";import{CRUD_OPERATION as a}from"./types";function d(l,c,n,s,r){const o=l.getQueryClient(),t=["crud",c,"get",n];if(r===a.DELETE){const e=o.getQueryCache().find({queryKey:t,exact:!0});if(!e)return;if(e.getObserversCount()===0){o.removeQueries({queryKey:t,exact:!0});return}o.setQueryData(t,null),o.invalidateQueries({queryKey:t,exact:!0,refetchType:"none"})}else r===a.SET&&s?o.setQueryData(t,s):(r===a.UPDATE||r===a.ADD)&&s&&o.setQueryData(t,e=>e?{...e,...s}:s)}function D(l,c,n,s,r){const o=l.getQueryClient();d(l,c,n,s,r),o.setQueriesData({queryKey:["crud",c]},t=>{if(t&&typeof t=="object"&&"items"in t){const e=t;let i=e.items;return r===a.DELETE?(i=e.items.filter(u=>u!=null&&typeof u=="object"&&u.id!==n),{...e,items:i,total:Math.max(0,(e.total??i.length)-1)}):r===a.ADD&&s?(i=[...e.items,{...s,id:n}],{...e,items:i,total:(e.total??e.items.length)+1}):(r===a.UPDATE||r===a.SET)&&s&&e.items.some(u=>u!=null&&typeof u=="object"&&u.id===n)?(i=e.items.map(u=>u==null||typeof u!="object"||u.id!==n?u:r===a.SET?{...s,id:n}:{...u,...s}),{...e,items:i}):t}if(Array.isArray(t)){if(r===a.DELETE)return t.filter(e=>e.id!==n);if(r===a.ADD&&s)return[...t,{...s,id:n}];if((r===a.UPDATE||r===a.SET)&&s)return t.some(e=>e!=null&&typeof e=="object"&&e.id===n)?t.map(e=>e==null||typeof e!="object"||e.id!==n?e:r===a.SET?{...s,id:n}:{...e,...s}):t}return t})}function E(l,c,n,s){const r=s.metadata?.uniqueKeys;if(!r||r.length===0)return null;const o=l.getQueryClient().getQueriesData({queryKey:["crud",c]}),t=[];for(const[,i]of o)i&&typeof i=="object"&&"items"in i?t.push(...i.items):Array.isArray(i)&&t.push(...i);if(t.length===0)return null;const e=n;for(const i of r){if(!i.fields.every(f=>e[f]!=null&&e[f]!==""))continue;const u=t.find(f=>i.fields.every(y=>{const m=typeof e[y]=="string"?e[y].toLowerCase():e[y],p=typeof f[y]=="string"?f[y].toLowerCase():f[y];return m===p}));if(u){if(i.findOrCreate)return u.id;const f=i.fields.join(" + ");throw g(new Error(i.errorMessage||`Duplicate ${f}`),{userMessage:i.errorMessage||`A record with this ${f} already exists`,showNotification:!0})}}return null}function h(l,c,n){const s=l.getQueryClient().getQueriesData({queryKey:["crud",c]});for(const[,r]of s)if(r?.items){const o=r.items.find(t=>t.id===n);if(o)return o}return null}async function C(l,c){await l.getQueryClient().invalidateQueries({queryKey:["crud",c]})}export{E as checkUniquenessFromCache,h as getItemFromListCache,C as invalidateCollectionImpl,d as updateGetCache,D as updateListCaches};
1
+ import{handleError as g}from"@donotdev/core";import{CRUD_OPERATION as l}from"./types";function h(a,c){return["crud",a,"query",JSON.stringify(c)]}function D(a,c,o){let s;for(const r of a.getQueryCache().findAll({queryKey:["crud",c,"query"]})){const n=r.state.data?.items?.find(t=>t!=null&&typeof t=="object"&&t.id===o);n&&(!s||r.state.dataUpdatedAt>s.updatedAt)&&(s={data:n,updatedAt:r.state.dataUpdatedAt})}return s}function d(a,c,o,s,r){const n=a.getQueryClient(),t=["crud",c,"get",o];if(r===l.DELETE){const e=n.getQueryCache().find({queryKey:t,exact:!0});if(!e)return;if(e.getObserversCount()===0){n.removeQueries({queryKey:t,exact:!0});return}n.setQueryData(t,null),n.invalidateQueries({queryKey:t,exact:!0,refetchType:"none"})}else r===l.SET&&s?n.setQueryData(t,s):(r===l.UPDATE||r===l.ADD)&&s&&n.setQueryData(t,e=>e?{...e,...s}:s)}function E(a,c,o,s,r){const n=a.getQueryClient();d(a,c,o,s,r),n.setQueriesData({queryKey:["crud",c]},t=>{if(t&&typeof t=="object"&&"items"in t){const e=t;let i=e.items;return r===l.DELETE?(i=e.items.filter(u=>u!=null&&typeof u=="object"&&u.id!==o),{...e,items:i,total:Math.max(0,(e.total??i.length)-1)}):r===l.ADD&&s?(i=[...e.items,{...s,id:o}],{...e,items:i,total:(e.total??e.items.length)+1}):(r===l.UPDATE||r===l.SET)&&s&&e.items.some(u=>u!=null&&typeof u=="object"&&u.id===o)?(i=e.items.map(u=>u==null||typeof u!="object"||u.id!==o?u:r===l.SET?{...s,id:o}:{...u,...s}),{...e,items:i}):t}if(Array.isArray(t)){if(r===l.DELETE)return t.filter(e=>e.id!==o);if(r===l.ADD&&s)return[...t,{...s,id:o}];if((r===l.UPDATE||r===l.SET)&&s)return t.some(e=>e!=null&&typeof e=="object"&&e.id===o)?t.map(e=>e==null||typeof e!="object"||e.id!==o?e:r===l.SET?{...s,id:o}:{...e,...s}):t}return t})}function A(a,c,o,s){const r=s.metadata?.uniqueKeys;if(!r||r.length===0)return null;const n=a.getQueryClient().getQueriesData({queryKey:["crud",c]}),t=[];for(const[,i]of n)i&&typeof i=="object"&&"items"in i?t.push(...i.items):Array.isArray(i)&&t.push(...i);if(t.length===0)return null;const e=o;for(const i of r){if(!i.fields.every(f=>e[f]!=null&&e[f]!==""))continue;const u=t.find(f=>i.fields.every(y=>{const m=typeof e[y]=="string"?e[y].toLowerCase():e[y],p=typeof f[y]=="string"?f[y].toLowerCase():f[y];return m===p}));if(u){if(i.findOrCreate)return u.id;const f=i.fields.join(" + ");throw g(new Error(i.errorMessage||`Duplicate ${f}`),{userMessage:i.errorMessage||`A record with this ${f} already exists`,showNotification:!0})}}return null}function C(a,c,o){const s=a.getQueryClient().getQueriesData({queryKey:["crud",c]});for(const[,r]of s)if(r?.items){const n=r.items.find(t=>t.id===o);if(n)return n}return null}async function Q(a,c){await a.getQueryClient().invalidateQueries({queryKey:["crud",c]})}export{D as cachedListRow,A as checkUniquenessFromCache,C as getItemFromListCache,Q as invalidateCollectionImpl,h as listQueryKey,d as updateGetCache,E as updateListCaches};
@@ -30,8 +30,9 @@
30
30
  * - Toast notifications
31
31
  *
32
32
  * **Caching strategy (aggressive / optimal):**
33
- * - One cache key per (collection, queryOptions): `['crud', collection, 'query', JSON.stringify(queryOptions)]`.
34
- * list and listCard share that same key — one network read, both views get data.
33
+ * - One cache key per (collection, queryOptions): `listQueryKey()` in CrudService.cache.ts.
34
+ * list and listCard share it — both read the full visible record (`schemas.get`); one network
35
+ * read, both views get data, and the doc cache starts from those rows.
35
36
  * - Create/Update/Delete update both the GET cache `['crud', collection, 'get', id]` and all
36
37
  * list caches via `updateListCaches` so the UI stays in sync without any refetch.
37
38
  * - `subscribeToCollection` writes to the same list cache key; real-time updates and mutations
@@ -160,10 +161,11 @@ export declare class CrudService implements CrudServiceInternal {
160
161
  delete(collection: string, id: string, options?: MutationOptions): Promise<void>;
161
162
  add<T extends Record<string, unknown>>(collection: string, data: CrudCreateInput<T>, schema: dndevSchema<T>, options?: MutationOptions): Promise<string>;
162
163
  /**
163
- * Execute a transactional bulk CRUD operation.
164
+ * Execute a bulk CRUD operation (partial success).
164
165
  *
165
- * All three buckets commit atomically in one adapter round-trip. Emits one
166
- * audit entry, one rate-limit hit, one toast. Collisions (same id in two
166
+ * All three buckets go to the adapter in one call. Rows that are written stay
167
+ * written; rows that fail are returned in `BulkResult.failed` and only those
168
+ * are reverted in the cache. Emits one audit entry, one rate-limit hit, one toast. Collisions (same id in two
167
169
  * mutually-exclusive buckets) reject up-front with `BulkCollisionError`
168
170
  * before any optimistic mutation. Empty payloads short-circuit without
169
171
  * hitting the adapter.
@@ -1 +1 @@
1
- {"version":3,"file":"CrudService.d.ts","sourceRoot":"","sources":["../src/CrudService.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,eAAe,EACf,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACd,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AA0BtD,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,eAAe,EAChB,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,YAAY,EAAE,CAAC;AAE7B;;;;;;;;;;;;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,CAAC,CAAC,EACT,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,EACjD,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GACrB,MAAM,IAAI;IAIb,qBAAqB,CAAC,CAAC,EACrB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,EAC5C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GACrB,MAAM,IAAI;IAcb,aAAa,CAAC,CAAC,SAAS;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,EACrC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,CAAC,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAI9B,gBAAgB,CAAC,CAAC,EAChB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,CAAC,CAAC;IAIb,gBAAgB,CACd,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,IAAI,CAAC;CAGjB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,mBAE1B,CAAC"}
@@ -23,7 +23,8 @@ import type { CrudServiceInternal, MutationOptions } from './types';
23
23
  */
24
24
  export declare function shouldShowSuccessToast(self: CrudServiceInternal, options?: MutationOptions): boolean;
25
25
  /**
26
- * Resolve PII fields for a collection from the schema metadata (if available).
26
+ * Resolve PII fields for a collection from `schema.metadata.security.piiFields`
27
+ * (copied from `entity.security` by createSchemas).
27
28
  * Returns empty array when no security config or piiFields defined.
28
29
  */
29
30
  export declare function getPiiFields(schema?: dndevSchema<unknown>): string[];
@@ -33,7 +34,7 @@ export declare function getPiiFields(schema?: dndevSchema<unknown>): string[];
33
34
  * reactive query descriptors, subscriptions), so cached rows are always plaintext.
34
35
  *
35
36
  * @param self - CrudService (its security context; none = no decryption)
36
- * @param schema - Schema carrying `security.piiFields`
37
+ * @param schema - Schema carrying `metadata.security.piiFields`
37
38
  * @param row - Row as returned by the adapter
38
39
  * @returns The row with PII fields decrypted
39
40
  */
@@ -1 +1 @@
1
- {"version":3,"file":"CrudService.internal.d.ts","sourceRoot":"","sources":["../src/CrudService.internal.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAUhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEpE;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,mBAAmB,EACzB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAKT;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,MAAM,EAAE,CAIpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,IAAI,EAAE,mBAAmB,EACzB,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,SAAS,EACxC,GAAG,EAAE,CAAC,GACL,CAAC,CAQH;AAED;;;GAGG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,mBAAmB,EACzB,IAAI,EAAE,aAAa,GAAG,WAAW,GAAG,aAAa,GAAG,aAAa,EACjE,UAAU,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,CAAC,CAWZ;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAgBxD;AAED,4DAA4D;AAC5D,wBAAsB,aAAa,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG5E;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,YAAY,GAAG,IAAI,EAC5B,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,GAC5B,IAAI,CAiBN;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmB7E;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAKrE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAmCxD;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,CAAC,EAC3C,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACpB,OAAO,CAAC,CAAC,CAAC,CAeZ"}
@@ -1,4 +1,4 @@
1
- import{getI18nInstance as p,hasProvider as u,getProvider as m,hasRestrictedVisibility as y,withTimeout as o,DEFAULT_CRUD_TIMEOUT as h}from"@donotdev/core";function w(e,r){return r?.showSuccessToast===!0?!0:r?.showSuccessToast===!1?!1:!e.store?.getState().hideSuccessToasts}function c(e){return e?.security?.piiFields??[]}function g(e,r,t){if(!e.security)return t;const i=c(r);return i.length===0?t:e.security.decryptPii(t,i)}function v(e,r,t,i,s){e.security&&e.security.audit({type:r,collection:t,docId:i,userId:s??e.currentUserId??void 0})}function S(e,r){return e.currentUserId?`${e.currentUserId}:${r}`:r}function d(e,r){return`${e}:${r}`}async function b(e,r=h){try{return await o(e(),r)}catch(t){if(l(t))return await new Promise(i=>setTimeout(i,2e3)),await o(e(),r);throw t}}function l(e){if(e instanceof Error){if(e.name==="TimeoutError"||e.message.includes("Failed to fetch")||e.message.includes("NetworkError")||e.message.includes("network"))return!0;const r=e.message.match(/(?:status|code)\s*:?\s*(\d{3})/i);if(r?.[1]&&parseInt(r[1])>=500)return!0}return!1}async function A(e){e.adapter||await e.initialize()}function F(e,r,t){if(e&&t&&y(t)&&!e.serverSideOnly&&!e.dbLevelSecurity)throw new Error(`[dndev] Direct adapter cannot access "${r}": entity has restricted field visibility. Use a server-side adapter (FunctionsAdapter for Firebase, or SupabaseCrudAdapter with RLS enabled) to enforce field-level security (serverSideOnly = true | dbLevelSecurity = true).`)}async function P(e){if(f(e)){e.store&&e.store.getState().setCrudService(e);return}if(!u("crud"))throw new Error(`[dndev] No CRUD adapter configured. Call configureProviders({ crud: yourAdapter }) at app startup.
1
+ import{getI18nInstance as p,hasProvider as u,getProvider as m,hasRestrictedVisibility as y,withTimeout as o,DEFAULT_CRUD_TIMEOUT as h}from"@donotdev/core";function w(e,r){return r?.showSuccessToast===!0?!0:r?.showSuccessToast===!1?!1:!e.store?.getState().hideSuccessToasts}function c(e){return e?.metadata.security?.piiFields??[]}function g(e,r,t){if(!e.security)return t;const i=c(r);return i.length===0?t:e.security.decryptPii(t,i)}function v(e,r,t,i,a){e.security&&e.security.audit({type:r,collection:t,docId:i,userId:a??e.currentUserId??void 0})}function S(e,r){return e.currentUserId?`${e.currentUserId}:${r}`:r}function d(e,r){return`${e}:${r}`}async function b(e,r=h){try{return await o(e(),r)}catch(t){if(l(t))return await new Promise(i=>setTimeout(i,2e3)),await o(e(),r);throw t}}function l(e){if(e instanceof Error){if(e.name==="TimeoutError"||e.message.includes("Failed to fetch")||e.message.includes("NetworkError")||e.message.includes("network"))return!0;const r=e.message.match(/(?:status|code)\s*:?\s*(\d{3})/i);if(r?.[1]&&parseInt(r[1])>=500)return!0}return!1}async function A(e){e.adapter||await e.initialize()}function F(e,r,t){if(e&&t&&y(t)&&!e.serverSideOnly&&!e.dbLevelSecurity)throw new Error(`[dndev] Direct adapter cannot access "${r}": entity has restricted field visibility. Use a server-side adapter (FunctionsAdapter for Firebase, or SupabaseCrudAdapter with RLS enabled) to enforce field-level security (serverSideOnly = true | dbLevelSecurity = true).`)}async function P(e){if(f(e)){e.store&&e.store.getState().setCrudService(e);return}if(!u("crud"))throw new Error(`[dndev] No CRUD adapter configured. Call configureProviders({ crud: yourAdapter }) at app startup.
2
2
  Examples:
3
3
  import { FirestoreAdapter } from "@donotdev/firebase";
4
4
  import { FunctionsAdapter } from "@donotdev/crud";
@@ -6,4 +6,4 @@ Examples:
6
6
 
7
7
  configureProviders({ crud: new FirestoreAdapter() }) // Firebase direct
8
8
  configureProviders({ crud: new FunctionsAdapter() }) // via callable functions
9
- configureProviders({ crud: new SupabaseCrudAdapter(sb) }) // Supabase direct (RLS)`)}function f(e){return e.adapter?!0:u("crud")?(e.adapter=m("crud"),!0):!1}function T(e){const r=p();let t=`entity-${e}`,i=r.t("name",{ns:t,defaultValue:null});return i&&i!=="name"&&i!==`${t}:name`||e.endsWith("s")&&e.length>1&&(t=`entity-${e.slice(0,-1)}`,i=r.t("name",{ns:t,defaultValue:null}),i&&i!=="name"&&i!==`${t}:name`)?i:e}async function E(e,r,t,i){const s=d(r,t),n=e._inflightMutations.get(s);n&&await n.catch(()=>{});const a=i();e._inflightMutations.set(s,a);try{return await a}finally{e._inflightMutations.get(s)===a&&e._inflightMutations.delete(s)}}export{F as assertCanAccess,f as attachProviderImpl,v as auditCrud,g as decryptPiiRow,A as ensureAdapter,T as getEntityName,c as getPiiFields,P as initializeImpl,l as isTransientError,d as mutationKey,S as rateLimitKey,E as runSerializedMutation,w as shouldShowSuccessToast,b as withResilience};
9
+ configureProviders({ crud: new SupabaseCrudAdapter(sb) }) // Supabase direct (RLS)`)}function f(e){return e.adapter?!0:u("crud")?(e.adapter=m("crud"),!0):!1}function T(e){const r=p();let t=`entity-${e}`,i=r.t("name",{ns:t,defaultValue:null});return i&&i!=="name"&&i!==`${t}:name`||e.endsWith("s")&&e.length>1&&(t=`entity-${e.slice(0,-1)}`,i=r.t("name",{ns:t,defaultValue:null}),i&&i!=="name"&&i!==`${t}:name`)?i:e}async function E(e,r,t,i){const a=d(r,t),n=e._inflightMutations.get(a);n&&await n.catch(()=>{});const s=i();e._inflightMutations.set(a,s);try{return await s}finally{e._inflightMutations.get(a)===s&&e._inflightMutations.delete(a)}}export{F as assertCanAccess,f as attachProviderImpl,v as auditCrud,g as decryptPiiRow,A as ensureAdapter,T as getEntityName,c as getPiiFields,P as initializeImpl,l as isTransientError,d as mutationKey,S as rateLimitKey,E as runSerializedMutation,w as shouldShowSuccessToast,b as withResilience};
@@ -1 +1 @@
1
- {"version":3,"file":"CrudService.queries.d.ts","sourceRoot":"","sources":["../src/CrudService.queries.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EAEb,WAAW,EACX,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACf,MAAM,gBAAgB,CAAC;AASxB,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAYjE;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,mBAAmB,EACzB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAClB,OAAO,CAMT;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EACvC,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAC5B,YAAY,CAAC,EAAE,YAAY,EAC3B,UAAU,GAAE,cAAsC,GACjD,aAAa,CAAC,CAAC,CAAC,CAwBlB;AA4CD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,IAA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AW,CAAC,OAAO,CAAC,EAC5B,YAAY,CAAC,EAAE,YAAY,EAC3B,UAAU,GAAE,cAAsC,GACjD,aAAa,CAAC,CAAC,CAAC,CAkBlB;AA4CD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAC5B,YAAY,CAAC,EAAE,YAAY,GAC1B,YAAY,CAAC,CAAC,CAAC,CAWjB;AAED,wBAAsB,OAAO,CAAC,CAAC,EAC7B,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CA6CnB;AAsCD,wBAAsB,SAAS,CAAC,CAAC,EAC/B,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,YAAY,CAAC,EAAE,YAAY,EAC3B,UAAU,GAAE,cAAsC,GACjD,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAiDlC"}
@@ -1 +1 @@
1
- import{LIST_SCHEMA_TYPE as g,handleError as c}from"@donotdev/core";import{assertCanAccess as d,decryptPiiRow as f,ensureAdapter as u,withResilience as w}from"./CrudService.internal";const l=1/0,y=new WeakMap;function q(t,e,r){if(y.has(e))return!0;const o=t.adapter?.forAccessToken?.(r);return o?(y.set(e,o),!0):!1}function E(t,e,r,o,a,n=g.LIST){return{queryKey:["crud",e,"query",JSON.stringify(r)],queryFn:async({client:s})=>{if(await u(t),!t.adapter)throw new Error("Adapter not initialized");const i=y.get(s)??t.adapter;return h(t,i,e,r,o,n)},staleTime:a?.staleTime??l}}async function p(t,e,r,o,a){d(e,r,a);const n=await w(()=>e.get(r,o,a));return n?f(t,a,n):null}async function h(t,e,r,o,a,n){d(e,r,a);const s=await w(()=>e.query(r,o,a,n));return{...s,items:s.items.map(i=>f(t,a,i))}}function T(t,e,r,o,a){return{queryKey:["crud",e,"get",r],queryFn:async({client:n})=>{if(await u(t),!t.adapter)throw new Error("Adapter not initialized");const s=y.get(n)??t.adapter;return p(t,s,e,r,o)},staleTime:a?.staleTime??l}}async function L(t,e,r,o,a){if(await u(t),a?.noCache)return S(t,e,r,o);t.store&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null));try{return await t.getQueryClient().fetchQuery({queryKey:["crud",e,"get",r],queryFn:()=>S(t,e,r,o,!1),staleTime:a?.staleTime??l})}catch(n){const s=c(n,{userMessage:`Failed to fetch ${e}`,showNotification:!0});throw t.store&&t.store.getState().setError(e,s),s}finally{t.store&&t.store.getState().setLoading(e,!1)}}async function S(t,e,r,o,a=!0){t.store&&a&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null));try{if(!t.adapter)throw new Error("Adapter not initialized");return await p(t,t.adapter,e,r,o)}catch(n){const s=c(n,{userMessage:`Failed to fetch ${e}`,showNotification:!0});throw t.store&&t.store.getState().setError(e,s),s}finally{t.store&&a&&t.store.getState().setLoading(e,!1)}}async function A(t,e,r,o,a,n=g.LIST){if(await u(t),a?.noCache)return m(t,e,r,o,!0,n);t.store&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null));try{return await t.getQueryClient().fetchQuery({queryKey:["crud",e,"query",JSON.stringify(r)],queryFn:()=>m(t,e,r,o,!1,n),staleTime:a?.staleTime??l})}catch(s){const i=c(s,{userMessage:`Failed to query ${e}`,showNotification:!0});throw t.store&&t.store.getState().setError(e,i),i}finally{t.store&&t.store.getState().setLoading(e,!1)}}async function m(t,e,r,o,a=!0,n=g.LIST){t.store&&a&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null));try{if(!t.adapter)throw new Error("Adapter not initialized");return await h(t,t.adapter,e,r,o,n)}catch(s){const i=c(s,{userMessage:`Failed to query ${e}`,showNotification:!0});throw t.store&&t.store.getState().setError(e,i),i}finally{t.store&&a&&t.store.getState().setLoading(e,!1)}}export{q as bindRequestAccessToken,T as getDocQueryOptionsImpl,L as getImpl,E as getListQueryOptionsImpl,A as queryImpl};
1
+ import{LIST_SCHEMA_TYPE as y,handleError as c}from"@donotdev/core";import{assertCanAccess as g,decryptPiiRow as f,ensureAdapter as u,withResilience as w}from"./CrudService.internal";import{cachedListRow as T,listQueryKey as p}from"./CrudService.cache";const l=1/0,d=new WeakMap;function L(t,e,r){if(d.has(e))return!0;const s=t.adapter?.forAccessToken?.(r);return s?(d.set(e,s),!0):!1}function q(t,e,r,s,a,o=y.LIST){return{queryKey:p(e,r),queryFn:async({client:i})=>{if(await u(t),!t.adapter)throw new Error("Adapter not initialized");const n=d.get(i)??t.adapter;return m(t,n,e,r,s,o)},staleTime:a?.staleTime??l}}async function h(t,e,r,s,a){g(e,r,a);const o=await w(()=>e.get(r,s,a));return o?f(t,a,o):null}async function m(t,e,r,s,a,o){g(e,r,a);const i=await w(()=>e.query(r,s,a,o));return{...i,items:i.items.map(n=>f(t,a,n))}}function A(t,e,r,s,a){return{queryKey:["crud",e,"get",r],queryFn:async({client:o})=>{if(await u(t),!t.adapter)throw new Error("Adapter not initialized");const i=d.get(o)??t.adapter;return h(t,i,e,r,s)},staleTime:a?.staleTime??l}}async function F(t,e,r,s,a){if(await u(t),a?.noCache)return S(t,e,r,s);t.store&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null));try{const o=t.getQueryClient(),i=T(o,e,r);return await o.fetchQuery({queryKey:["crud",e,"get",r],...i&&{initialData:i.data,initialDataUpdatedAt:i.updatedAt},queryFn:()=>S(t,e,r,s,!1),staleTime:a?.staleTime??l})}catch(o){const i=c(o,{userMessage:`Failed to fetch ${e}`,showNotification:!0});throw t.store&&t.store.getState().setError(e,i),i}finally{t.store&&t.store.getState().setLoading(e,!1)}}async function S(t,e,r,s,a=!0){t.store&&a&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null));try{if(!t.adapter)throw new Error("Adapter not initialized");return await h(t,t.adapter,e,r,s)}catch(o){const i=c(o,{userMessage:`Failed to fetch ${e}`,showNotification:!0});throw t.store&&t.store.getState().setError(e,i),i}finally{t.store&&a&&t.store.getState().setLoading(e,!1)}}async function I(t,e,r,s,a,o=y.LIST){if(await u(t),a?.noCache)return E(t,e,r,s,!0,o);t.store&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null));try{return await t.getQueryClient().fetchQuery({queryKey:p(e,r),queryFn:()=>E(t,e,r,s,!1,o),staleTime:a?.staleTime??l})}catch(i){const n=c(i,{userMessage:`Failed to query ${e}`,showNotification:!0});throw t.store&&t.store.getState().setError(e,n),n}finally{t.store&&t.store.getState().setLoading(e,!1)}}async function E(t,e,r,s,a=!0,o=y.LIST){t.store&&a&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null));try{if(!t.adapter)throw new Error("Adapter not initialized");return await m(t,t.adapter,e,r,s,o)}catch(i){const n=c(i,{userMessage:`Failed to query ${e}`,showNotification:!0});throw t.store&&t.store.getState().setError(e,n),n}finally{t.store&&a&&t.store.getState().setLoading(e,!1)}}export{L as bindRequestAccessToken,A as getDocQueryOptionsImpl,F as getImpl,q as getListQueryOptionsImpl,I as queryImpl};
@@ -1 +1 @@
1
- {"version":3,"file":"CrudService.subscriptions.d.ts","sourceRoot":"","sources":["../src/CrudService.subscriptions.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EAEb,MAAM,gBAAgB,CAAC;AAQxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,wBAAgB,aAAa,CAAC,CAAC,EAC7B,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,QA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import{handleError as l}from"@donotdev/core";import{assertCanAccess as p,decryptPiiRow as d,ensureAdapter as b}from"./CrudService.internal";function y(e,n,u,t,i){if(!e.adapter){let r=!1,c=null;return b(e).then(()=>{r||(c=f(e,n,u,t,i))}).catch(o=>{r||t(null,l(o))}),()=>{r=!0,c?.()}}return f(e,n,u,t,i)}function f(e,n,u,t,i){try{const r=e.adapter;return r?r.subscribe?(p(e.adapter,n,i),r.subscribe(n,u,(c,o)=>{const a=c&&d(e,i,c);a&&e.getQueryClient().setQueryData(["crud",n,"get",u],a),t(a,o)},i)):()=>{}:(t(null,new Error("Adapter not initialized")),()=>{})}catch(r){return t(null,l(r)),()=>{}}}function h(e,n,u,t,i){if(!e.adapter){let r=!1,c=null;return b(e).then(()=>{r||(c=m(e,n,u,t,i))}).catch(o=>{r||t([],l(o))}),()=>{r=!0,c?.()}}return m(e,n,u,t,i)}function m(e,n,u,t,i){try{const r=e.adapter;return r?r.subscribeToCollection?(p(e.adapter,n,i),r.subscribeToCollection(n,u,(c,o)=>{const a=c?.map(s=>d(e,i,s));a&&e.getQueryClient().setQueryData(["crud",n,"query",JSON.stringify(u)],s=>s?{...s,items:a}:{items:a}),t(a,o)},i)):()=>{}:(t([],new Error("Adapter not initialized")),()=>{})}catch(r){return t([],l(r)),()=>{}}}export{y as subscribeImpl,h as subscribeToCollectionImpl};
1
+ import{handleError as l}from"@donotdev/core";import{assertCanAccess as p,decryptPiiRow as d,ensureAdapter as b}from"./CrudService.internal";import{listQueryKey as y}from"./CrudService.cache";function h(e,n,c,t,i){if(!e.adapter){let r=!1,o=null;return b(e).then(()=>{r||(o=m(e,n,c,t,i))}).catch(a=>{r||t(null,l(a))}),()=>{r=!0,o?.()}}return m(e,n,c,t,i)}function m(e,n,c,t,i){try{const r=e.adapter;return r?r.subscribe?(p(e.adapter,n,i),r.subscribe(n,c,(o,a)=>{const u=o&&d(e,i,o);u&&e.getQueryClient().setQueryData(["crud",n,"get",c],u),t(u,a)},i)):()=>{}:(t(null,new Error("Adapter not initialized")),()=>{})}catch(r){return t(null,l(r)),()=>{}}}function C(e,n,c,t,i){if(!e.adapter){let r=!1,o=null;return b(e).then(()=>{r||(o=f(e,n,c,t,i))}).catch(a=>{r||t([],l(a))}),()=>{r=!0,o?.()}}return f(e,n,c,t,i)}function f(e,n,c,t,i){try{const r=e.adapter;return r?r.subscribeToCollection?(p(e.adapter,n,i),r.subscribeToCollection(n,c,(o,a)=>{const u=o?.map(s=>d(e,i,s));u&&e.getQueryClient().setQueryData(y(n,c),s=>s?{...s,items:u}:{items:u}),t(u,a)},i)):()=>{}:(t([],new Error("Adapter not initialized")),()=>{})}catch(r){return t([],l(r)),()=>{}}}export{h as subscribeImpl,C as subscribeToCollectionImpl};
package/dist/CrudStore.js CHANGED
@@ -1 +1 @@
1
- import{createDoNotDevStore as g,isClient as f}from"@donotdev/core";import{OPTIMISTIC_STATUSES as d,CRUD_OPERATION as u}from"./types";let m=null;const a="f_";function S(s){if(!f())return;const l=new URLSearchParams(location.search);[...l.keys()].filter(i=>i.startsWith(a)).forEach(i=>l.delete(i));for(const[i,o]of Object.entries(s))typeof o=="string"?l.set(`${a}${i}`,o):Array.isArray(o)?l.set(`${a}${i}`,o.join(",")):(o.min&&l.set(`${a}${i}_min`,o.min),o.max&&l.set(`${a}${i}_max`,o.max));const t=l.toString();history.replaceState(null,"",`${location.pathname}${t?`?${t}`:""}`)}function h(){if(!f())return{};const s=new URLSearchParams(location.search),l={},t=new Map;return s.forEach((i,o)=>{if(!o.startsWith(a))return;const e=o.slice(a.length);if(e.endsWith("_min")){const c=e.slice(0,-4),n=t.get(c)??{};n.min=i,t.set(c,n)}else if(e.endsWith("_max")){const c=e.slice(0,-4),n=t.get(c)??{};n.max=i,t.set(c,n)}else i.includes(",")?l[e]=i.split(","):l[e]=i}),t.forEach((i,o)=>{l[o]=i}),l}const E={filters:{},showFavoritesOnly:!1};function r(){return{loading:!1,error:null,lastUpdated:0,optimistic:{},ui:{...E}}}const O={crudService:null,hideSuccessToasts:!1,collections:{}},U=g({name:"crud-store",createStore:(s,l)=>({...O,setCrudService:t=>{s({crudService:t})},setHideSuccessToasts:t=>{s({hideSuccessToasts:t})},setLoading:(t,i)=>{s(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,loading:i}}}})},setError:(t,i)=>{s(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,error:i,loading:!1}}}})},setFilters:(t,i)=>{s(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,ui:{...e.ui,filters:i}}}}}),m&&clearTimeout(m),m=setTimeout(()=>{m=null,S(i)},500)},setShowFavoritesOnly:(t,i)=>{s(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,ui:{...e.ui,showFavoritesOnly:i}}}}})},getFilters:t=>{const i=l().collections[t]?.ui?.filters;if(i)return i;const o=h();return Object.keys(o).length>0?(s(e=>{const c=e.collections[t]||r();return{collections:{...e.collections,[t]:{...c,ui:{...c.ui,filters:o}}}}}),o):{}},getShowFavoritesOnly:t=>l().collections[t]?.ui?.showFavoritesOnly||!1,setPageSize:(t,i)=>{s(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,ui:{...e.ui,pageSize:i}}}}})},getPageSize:t=>l().collections[t]?.ui?.pageSize,clearCollection:t=>{s(i=>{const{[t]:o,...e}=i.collections;return{collections:e}})},clearError:t=>{s(i=>{const o=i.collections[t];return o?{collections:{...i.collections,[t]:{...o,error:null}}}:i})},addOptimistic:(t,i,o)=>{s(e=>{const c=e.collections[t]||r();return{collections:{...e.collections,[t]:{...c,optimistic:{...c.optimistic,[i]:{tempId:i,originalData:null,optimisticData:o,status:d.PENDING,operation:u.ADD}},lastUpdated:Date.now()}}}})},confirmOptimistic:(t,i,o,e)=>{s(c=>{const n=c.collections[t];if(!n)return c;const{[i]:p,...D}=n.optimistic;return{collections:{...c.collections,[t]:{...n,optimistic:D,lastUpdated:Date.now()}}}})},rejectOptimistic:(t,i)=>{s(o=>{const e=o.collections[t];if(!e)return o;const{[i]:c,...n}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:n,lastUpdated:Date.now()}}}})},updateOptimistic:(t,i,o,e)=>{s(c=>{const n=c.collections[t]||r();return{collections:{...c.collections,[t]:{...n,optimistic:{...n.optimistic,[i]:{tempId:i,originalData:e,optimisticData:o,status:d.PENDING,operation:u.UPDATE}},lastUpdated:Date.now()}}}})},confirmUpdate:(t,i)=>{s(o=>{const e=o.collections[t];if(!e)return o;const{[i]:c,...n}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:n}}}})},rejectUpdate:(t,i)=>{s(o=>{const e=o.collections[t];if(!e)return o;const c=e.optimistic[i];if(!c||c.operation!==u.UPDATE)return o;const{[i]:n,...p}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:p,lastUpdated:Date.now()}}}})},deleteOptimistic:(t,i,o)=>{s(e=>{const c=e.collections[t];return c?{collections:{...e.collections,[t]:{...c,optimistic:{...c.optimistic,[i]:{tempId:i,originalData:o,optimisticData:null,status:d.PENDING,operation:u.DELETE}},lastUpdated:Date.now()}}}:e})},confirmDelete:(t,i)=>{s(o=>{const e=o.collections[t];if(!e)return o;const{[i]:c,...n}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:n}}}})},rejectDelete:(t,i)=>{s(o=>{const e=o.collections[t];if(!e)return o;const c=e.optimistic[i];if(!c||c.operation!==u.DELETE)return o;const{[i]:n,...p}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:p,lastUpdated:Date.now()}}}})},getLoading:t=>l().collections[t]?.loading||!1,getError:t=>l().collections[t]?.error||null,isOptimistic:(t,i)=>l().collections[t]?.optimistic[i]?.status==="pending",getOptimisticStatus:(t,i)=>l().collections[t]?.optimistic[i]?.status??null,getOptimisticData:(t,i)=>l().collections[t]?.optimistic[i]?.optimisticData??null})});export{U as useCrudStore};
1
+ import{createDoNotDevStore as g,isClient as f}from"@donotdev/core";import{OPTIMISTIC_STATUSES as d,CRUD_OPERATION as u}from"./types";let m=null;const a="f_";function S(n){if(!f())return;const s=new URLSearchParams(location.search);[...s.keys()].filter(i=>i.startsWith(a)).forEach(i=>s.delete(i));for(const[i,e]of Object.entries(n))typeof e=="string"?s.set(`${a}${i}`,e):Array.isArray(e)?s.set(`${a}${i}`,e.join(",")):(e.min&&s.set(`${a}${i}_min`,e.min),e.max&&s.set(`${a}${i}_max`,e.max));const t=s.toString();history.replaceState(null,"",`${location.pathname}${t?`?${t}`:""}`)}function h(){if(!f())return{};const n=new URLSearchParams(location.search),s={},t=new Map;return n.forEach((i,e)=>{if(!e.startsWith(a))return;const o=e.slice(a.length);if(o.endsWith("_min")){const c=o.slice(0,-4),l=t.get(c)??{};l.min=i,t.set(c,l)}else if(o.endsWith("_max")){const c=o.slice(0,-4),l=t.get(c)??{};l.max=i,t.set(c,l)}else i.includes(",")?s[o]=i.split(","):s[o]=i}),t.forEach((i,e)=>{s[e]=i}),s}const E={filters:{},showFavoritesOnly:!1};function r(){return{loading:!1,error:null,lastUpdated:0,optimistic:{},ui:{...E}}}const O={crudService:null,hideSuccessToasts:!1,collections:{}},U=g({name:"crud-store",createStore:(n,s)=>({...O,setCrudService:t=>{n({crudService:t})},setHideSuccessToasts:t=>{n({hideSuccessToasts:t})},setLoading:(t,i)=>{n(e=>{const o=e.collections[t]||r();return{collections:{...e.collections,[t]:{...o,loading:i}}}})},setError:(t,i)=>{n(e=>{const o=e.collections[t]||r();return{collections:{...e.collections,[t]:{...o,error:i,loading:!1}}}})},setFilters:(t,i)=>{n(e=>{const o=e.collections[t]||r();return{collections:{...e.collections,[t]:{...o,ui:{...o.ui,filters:i}}}}}),m&&clearTimeout(m),m=setTimeout(()=>{m=null,S(i)},500)},setShowFavoritesOnly:(t,i)=>{n(e=>{const o=e.collections[t]||r();return{collections:{...e.collections,[t]:{...o,ui:{...o.ui,showFavoritesOnly:i}}}}})},getFilters:t=>{const i=s().collections[t]?.ui?.filters;if(i)return i;const e=h();return Object.keys(e).length>0?(n(o=>{const c=o.collections[t]||r();return{collections:{...o.collections,[t]:{...c,ui:{...c.ui,filters:e}}}}}),e):{}},getShowFavoritesOnly:t=>s().collections[t]?.ui?.showFavoritesOnly||!1,setPageSize:(t,i)=>{n(e=>{const o=e.collections[t]||r();return{collections:{...e.collections,[t]:{...o,ui:{...o.ui,pageSize:i}}}}})},getPageSize:t=>s().collections[t]?.ui?.pageSize,clearCollection:t=>{n(i=>{const{[t]:e,...o}=i.collections;return{collections:o}})},clearError:t=>{n(i=>{const e=i.collections[t];return e?{collections:{...i.collections,[t]:{...e,error:null}}}:i})},addOptimistic:(t,i,e)=>{n(o=>{const c=o.collections[t]||r();return{collections:{...o.collections,[t]:{...c,optimistic:{...c.optimistic,[i]:{tempId:i,originalData:null,optimisticData:e,status:d.PENDING,operation:u.ADD}},lastUpdated:Date.now()}}}})},confirmOptimistic:(t,i,e,o)=>{n(c=>{const l=c.collections[t];if(!l)return c;const{[i]:p,...D}=l.optimistic;return{collections:{...c.collections,[t]:{...l,optimistic:D,lastUpdated:Date.now()}}}})},rejectOptimistic:(t,i)=>{n(e=>{const o=e.collections[t];if(!o)return e;const{[i]:c,...l}=o.optimistic;return{collections:{...e.collections,[t]:{...o,optimistic:l,lastUpdated:Date.now()}}}})},updateOptimistic:(t,i,e,o)=>{n(c=>{const l=c.collections[t]||r();return{collections:{...c.collections,[t]:{...l,optimistic:{...l.optimistic,[i]:{tempId:i,originalData:o,optimisticData:e,status:d.PENDING,operation:u.UPDATE}},lastUpdated:Date.now()}}}})},confirmUpdate:(t,i)=>{n(e=>{const o=e.collections[t];if(!o)return e;const{[i]:c,...l}=o.optimistic;return{collections:{...e.collections,[t]:{...o,optimistic:l}}}})},rejectUpdate:(t,i)=>{n(e=>{const o=e.collections[t];if(!o)return e;const c=o.optimistic[i];if(!c||c.operation!==u.UPDATE)return e;const{[i]:l,...p}=o.optimistic;return{collections:{...e.collections,[t]:{...o,optimistic:p,lastUpdated:Date.now()}}}})},deleteOptimistic:(t,i,e)=>{n(o=>{const c=o.collections[t];return c?{collections:{...o.collections,[t]:{...c,optimistic:{...c.optimistic,[i]:{tempId:i,originalData:e,optimisticData:null,status:d.PENDING,operation:u.DELETE}},lastUpdated:Date.now()}}}:o})},confirmDelete:(t,i)=>{n(e=>{const o=e.collections[t];if(!o)return e;const{[i]:c,...l}=o.optimistic;return{collections:{...e.collections,[t]:{...o,optimistic:l}}}})},rejectDelete:(t,i)=>{n(e=>{const o=e.collections[t];if(!o)return e;const c=o.optimistic[i];if(!c||c.operation!==u.DELETE)return e;const{[i]:l,...p}=o.optimistic;return{collections:{...e.collections,[t]:{...o,optimistic:p,lastUpdated:Date.now()}}}})},getLoading:t=>s().collections[t]?.loading||!1,getError:t=>s().collections[t]?.error||null,isOptimistic:(t,i)=>s().collections[t]?.optimistic[i]?.status==="pending",getOptimisticStatus:(t,i)=>s().collections[t]?.optimistic[i]?.status??null,getOptimisticData:(t,i)=>s().collections[t]?.optimistic[i]?.optimisticData??null})});export{U as useCrudStore};
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionsAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/FunctionsAdapter.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EACV,cAAc,EAGd,UAAU,EACV,oBAAoB,EACpB,WAAW,EAEX,YAAY,EACZ,cAAc,EACd,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAaxB;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACnE,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/D,KAAK,CAAC,EAAE,M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AAqB,EAC9B,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAC5B,UAAU,GAAE,cAAsC,GACjD,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAqEnC,SAAS,CAAC,CAAC,KAAK,MAAM,IAAI;IAS1B,qBAAqB,CAAC,CAAC,KAAK,MAAM,IAAI;CAQvC"}
@@ -1 +1 @@
1
- import*as h from"valibot";import{BulkCollisionError as y,BulkRequestSchema as g,BulkResponseSchema as A,detectBulkCollisions as m,DoNotDevError as b,getProvider as C,validateWithSchema as p,wrapCrudError as l}from"@donotdev/core";import{LIST_SCHEMA_TYPE as f}from"@donotdev/core";class E{serverSideOnly=!0;getCallable(){return C("callable")}async getCallableFn(a){const t=this.getCallable();return async s=>({data:await t.call(a,s)})}async get(a,t,s){const i=`get_${a}`,n=await this.getCallableFn(i);try{const e=(await n({id:t})).data;return s?{...p(s,e,"FunctionsAdapter.get"),id:t}:{...e,id:t}}catch(e){throw l(e,"FunctionsAdapter","get",a,t)}}async set(a,t,s,i){const n=i?p(i,s,"FunctionsAdapter.set"):s,e=`update_${a}`,o=await this.getCallableFn(e);try{await o({id:t,payload:n})}catch(r){throw l(r,"FunctionsAdapter","set",a,t)}}async update(a,t,s){const i=`update_${a}`,n=await this.getCallableFn(i);try{await n({id:t,payload:s})}catch(e){throw l(e,"FunctionsAdapter","update",a,t)}}async delete(a,t){const s=`delete_${a}`,i=await this.getCallableFn(s);try{await i({id:t})}catch(n){throw l(n,"FunctionsAdapter","delete",a,t)}}async bulk(a,t,s,i){const n=m({inserts:t.inserts,updates:t.updates,deletes:t.deletes});if(n.where!==null)throw new y(n.collisions,n.where);const e=t.inserts??[],o=t.updates??[],r=t.deletes??[];if(e.length===0&&o.length===0&&r.length===0)return{insertedIds:[],updatedIds:[],deletedIds:[]};let w;try{w=h.parse(g,{inserts:e,updates:o,deletes:r})}catch(d){throw new b(`FunctionsAdapter.bulk(${a}): invalid bulk request payload`,"validation-failed",{details:{issues:d instanceof h.ValiError?d.issues:void 0},source:"validation",originalError:d instanceof Error?d:new Error(String(d))})}const F=await this.getCallableFn(`bulk_${a}`);try{const d=await F(w);if(!d.data)throw l(new Error("Bulk function returned no data"),"FunctionsAdapter","bulk",a);let u;try{u=h.parse(A,d.data)}catch(c){throw new b(`FunctionsAdapter.bulk(${a}): malformed server response`,"validation-failed",{details:{issues:c instanceof h.ValiError?c.issues:void 0,response:d.data},source:"validation",originalError:c instanceof Error?c:new Error(String(c))})}return{insertedIds:u.insertedIds,updatedIds:u.updatedIds,deletedIds:u.deletedIds}}catch(d){throw d instanceof y?d:l(d,"FunctionsAdapter","bulk",a)}}async add(a,t,s){const i=s?p(s,t,"FunctionsAdapter.add"):t,n=`create_${a}`,e=await this.getCallableFn(n);try{const o=await e({payload:i});if(!o.data)throw l(new Error("Create function returned no data"),"FunctionsAdapter","add",a);return{id:o.data.id,data:o.data}}catch(o){throw l(o,"FunctionsAdapter","add",a)}}async query(a,t,s,i=f.LIST){const n=i===f.LIST_CARD?`listCard_${a}`:`list_${a}`,e={};t.where&&(e.where=t.where.map(r=>[r.field,r.operator,r.value])),t.orderBy&&(e.orderBy=t.orderBy.map(r=>[r.field,r.direction||"asc"])),t.limit&&(e.limit=t.limit),t.startAfter&&(e.startAfterId=t.startAfter);const o=await this.getCallableFn(n);try{const r=await o(e);if(!r.data)throw l(new Error("Query function returned no data"),"FunctionsAdapter","query",a);return{items:r.data.items,total:r.data.count,hasMore:r.data.hasMore,lastVisible:r.data.lastVisible}}catch(r){throw l(r,"FunctionsAdapter","query",a)}}subscribe(){return()=>{}}subscribeToCollection(){return()=>{}}}export{E as FunctionsAdapter};
1
+ import*as h from"valibot";import{BulkCollisionError as y,BulkRequestSchema as g,BulkResponseSchema as A,detectBulkCollisions as m,DoNotDevError as f,getProvider as C,validateWithSchema as p,wrapCrudError as l}from"@donotdev/core";import{LIST_SCHEMA_TYPE as b}from"@donotdev/core";class E{serverSideOnly=!0;getCallable(){return C("callable")}async getCallableFn(e){const t=this.getCallable();return async s=>({data:await t.call(e,s)})}async get(e,t,s){const n=`get_${e}`,i=await this.getCallableFn(n);try{const a=(await i({id:t})).data;return s?{...p(s,a,"FunctionsAdapter.get"),id:t}:{...a,id:t}}catch(a){throw l(a,"FunctionsAdapter","get",e,t)}}async set(e,t,s,n){const i=n?p(n,s,"FunctionsAdapter.set"):s,a=`update_${e}`,o=await this.getCallableFn(a);try{await o({id:t,payload:i})}catch(r){throw l(r,"FunctionsAdapter","set",e,t)}}async update(e,t,s){const n=`update_${e}`,i=await this.getCallableFn(n);try{await i({id:t,payload:s})}catch(a){throw l(a,"FunctionsAdapter","update",e,t)}}async delete(e,t){const s=`delete_${e}`,n=await this.getCallableFn(s);try{await n({id:t})}catch(i){throw l(i,"FunctionsAdapter","delete",e,t)}}async bulk(e,t,s,n){const i=m({inserts:t.inserts,updates:t.updates,deletes:t.deletes});if(i.where!==null)throw new y(i.collisions,i.where);const a=t.inserts??[],o=t.updates??[],r=t.deletes??[];if(a.length===0&&o.length===0&&r.length===0)return{insertedIds:[],updatedIds:[],deletedIds:[],failed:[]};let w;try{w=h.parse(g,{inserts:a,updates:o,deletes:r})}catch(d){throw new f(`FunctionsAdapter.bulk(${e}): invalid bulk request payload`,"validation-failed",{details:{issues:d instanceof h.ValiError?d.issues:void 0},source:"validation",originalError:d instanceof Error?d:new Error(String(d))})}const F=await this.getCallableFn(`bulk_${e}`);try{const d=await F(w);if(!d.data)throw l(new Error("Bulk function returned no data"),"FunctionsAdapter","bulk",e);let u;try{u=h.parse(A,d.data)}catch(c){throw new f(`FunctionsAdapter.bulk(${e}): malformed server response`,"validation-failed",{details:{issues:c instanceof h.ValiError?c.issues:void 0,response:d.data},source:"validation",originalError:c instanceof Error?c:new Error(String(c))})}return{insertedIds:u.insertedIds,updatedIds:u.updatedIds,deletedIds:u.deletedIds,failed:[]}}catch(d){throw d instanceof y?d:l(d,"FunctionsAdapter","bulk",e)}}async add(e,t,s){const n=s?p(s,t,"FunctionsAdapter.add"):t,i=`create_${e}`,a=await this.getCallableFn(i);try{const o=await a({payload:n});if(!o.data)throw l(new Error("Create function returned no data"),"FunctionsAdapter","add",e);return{id:o.data.id,data:o.data}}catch(o){throw l(o,"FunctionsAdapter","add",e)}}async query(e,t,s,n=b.LIST){const i=n===b.LIST_CARD?`listCard_${e}`:`list_${e}`,a={};t.where&&(a.where=t.where.map(r=>[r.field,r.operator,r.value])),t.orderBy&&(a.orderBy=t.orderBy.map(r=>[r.field,r.direction||"asc"])),t.limit&&(a.limit=t.limit),t.startAfter&&(a.startAfterId=t.startAfter);const o=await this.getCallableFn(i);try{const r=await o(a);if(!r.data)throw l(new Error("Query function returned no data"),"FunctionsAdapter","query",e);return{items:r.data.items,total:r.data.count,hasMore:r.data.hasMore,lastVisible:r.data.lastVisible}}catch(r){throw l(r,"FunctionsAdapter","query",e)}}subscribe(){return()=>{}}subscribeToCollection(){return()=>{}}}export{E as FunctionsAdapter};
@@ -1 +1 @@
1
- "use client";import{jsx as d}from"react/jsx-runtime";import{ActionButton as n}from"@donotdev/components";import{useCrudStore as a}from"../CrudStore";function c({requiresAuth:r=!0,user:e,disabled:t=!1,children:s,...i}){const o=a(u=>!!u.crudService);return d(n,{...i,disabled:t||!o||r&&!e,children:s})}var l=c;export{l as default};
1
+ "use client";import{jsx as d}from"react/jsx-runtime";import{ActionButton as n}from"@donotdev/components";import{useCrudStore as a}from"../CrudStore";function c({requiresAuth:r=!0,user:e,disabled:t=!1,children:o,...i}){const s=a(u=>!!u.crudService);return d(n,{...i,disabled:t||!s||r&&!e,children:o})}var l=c;export{l as default};
@@ -1,8 +1,8 @@
1
1
  import type { CrudCardProps } from '@donotdev/core';
2
2
  /**
3
3
  * CrudCard — Presentational card from entity + item + field slots.
4
- * No routing: use onClick for interaction. Parent wraps with Link if needed.
4
+ * Navigation: `href` renders a real link (router-aware); `onClick` for other interactions.
5
5
  */
6
- export declare function CrudCard({ item, entity, onClick, titleFields: titleFieldsProp, subtitleFields: subtitleFieldsProp, contentFields: contentFieldsProp, footerFields: footerFieldsProp, showDelete, renderActions, renderOverlay, className, }: CrudCardProps): import("react").JSX.Element;
6
+ export declare function CrudCard({ item, entity, onClick, href, titleFields: titleFieldsProp, subtitleFields: subtitleFieldsProp, contentFields: contentFieldsProp, footerFields: footerFieldsProp, showDelete, renderActions, renderOverlay, className, }: CrudCardProps): import("react").JSX.Element;
7
7
  export default CrudCard;
8
8
  //# sourceMappingURL=CrudCard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CrudCard.d.ts","sourceRoot":"","sources":["../../src/components/CrudCard.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAA2B,MAAM,gBAAgB,CAAC;AA4C7E;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,MAAM,EACN,OAAO,EACP,WAAW,EAAE,eAAe,EAC5B,cAAc,EAAE,kBAAkB,EAClC,aAAa,EAAE,iBAAiB,EAChC,YAAY,EAAE,gBAAgB,EAC9B,UAAkB,EAClB,aAAa,EACb,aAAa,EACb,SAAS,GACV,EAAE,aAAa,+BA6Mf;AAED,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"CrudCard.d.ts","sourceRoot":"","sources":["../../src/components/CrudCard.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAAW,MAAM,gBAAgB,CAAC;AA2C7D;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,MAAM,EACN,OAAO,EACP,IAAI,EACJ,WAAW,EAAE,eAAe,EAC5B,cAAc,EAAE,kBAAkB,EAClC,aAAa,EAAE,iBAAiB,EAChC,YAAY,EAAE,gBAAgB,EAC9B,UAAkB,EAClB,aAAa,EACb,aAAa,EACb,SAAS,GACV,EAAE,aAAa,+BAkNf;AAED,eAAe,QAAQ,CAAC"}
@@ -1 +1 @@
1
- import{jsx as a,jsxs as k}from"react/jsx-runtime";import{Trash2 as z}from"lucide-react";import{useMemo as y}from"react";import{Card as G,Stack as w,Text as V,ActionButton as H}from"@donotdev/components";import{useTranslation as B,getListCardFieldNames as J}from"@donotdev/core";import{formatValue as F}from"./DisplayFieldRenderer";import{DisplayThumbnail as P}from"./DisplayThumbnail";import{translateFieldLabel as K}from"../forms/utils/translateFieldLabel";import{useCrud as Q}from"../useCrud";function d(e){return e==="image"||e==="images"}function U(e){return y(()=>{const i=e.listCardFields;if(i&&!Array.isArray(i)){const s=i;return{titleFields:s.title??[],subtitleFields:s.subtitle??[],contentFields:s.content??[],footerFields:s.footer??[]}}const f=J(e),m=f.filter(s=>!d(e.fields[s]?.type)),C=f.filter(s=>d(e.fields[s]?.type)),b=m.length>0?[m[0]]:[],x=[...m.slice(1,4),...C];return{titleFields:b,subtitleFields:[],contentFields:x,footerFields:[]}},[e])}function I({item:e,entity:i,onClick:f,titleFields:m,subtitleFields:C,contentFields:b,footerFields:x,showDelete:s=!1,renderActions:j,renderOverlay:M,className:N}){const{t:o}=B([i.namespace,"crud"]),{t:p}=B("crud"),h=U(i),S=m??h.titleFields,A=C??h.subtitleFields,D=b??h.contentFields,g=x??h.footerFields,u=e,T=y(()=>{if(!S?.length)return e.id??"";const r=S.filter(t=>typeof t=="string").filter(t=>!d(i.fields[t]?.type)).map(t=>{const n=i.fields[t],v=e[t],c=n?F(v,n,o,{compact:!0,asString:!0,item:u}):v;return typeof c=="string"?c:String(c??"")}).filter(Boolean),l=!Array.isArray(i.listCardFields)&&i.listCardFields?.titleSeparator!=null?i.listCardFields.titleSeparator:" ";return r.join(l)||String(e.id??"")},[e,i.fields,S,i.listCardFields,o]),O=y(()=>A?.length&&A.filter(r=>typeof r=="string").filter(r=>!d(i.fields[r]?.type)).map(r=>{const l=i.fields[r],t=e[r],n=l?F(t,l,o,{compact:!0,asString:!0,item:u}):t;return typeof n=="string"?n:String(n??"")}).filter(Boolean).join(" ")||void 0,[e,i.fields,A,o]),R=y(()=>{if(!D?.length)return null;const r=D.map(l=>{const t=i.fields[l];if(!t||t.options?.displayValue?.(e[l],u,o)===null)return null;if(d(t.type)){const n=e[l];return n==null?null:a(P,{pictures:n,alt:String(T),aspectRatio:"16/9"},l)}return k("div",{children:[a(V,{level:"small",variant:"muted",children:K(l,t,o)}),a(V,{children:F(e[l],t,o,{compact:!0,item:u})})]},l)}).filter(Boolean);return r.length>0?a(w,{direction:"column",gap:"tight",children:r}):null},[e,i.fields,D,T,o]),E=y(()=>{if(!g?.length)return;if(g.some(l=>d(i.fields[l]?.type))){const l=g.map(t=>{const n=i.fields[t];if(!n)return null;if(d(n.type)){const c=e[t];return c==null?null:a(P,{pictures:c,alt:"",aspectRatio:"1"},t)}const v=F(e[t],n,o,{compact:!0,item:u});return a("span",{children:v},t)});return a(w,{direction:"row",gap:"tight",align:"center",children:l.filter(Boolean)})}const r=g.map(l=>{const t=i.fields[l];return t?F(e[l],t,o,{compact:!0,item:u}):e[l]});return a(V,{level:"small",children:r.join(" \xB7 ")})},[e,i.fields,g,o]),L=Q(i).delete,q=j||s?k("div",{style:{display:"flex",alignItems:"flex-start",gap:"var(--gap-xs)",pointerEvents:"auto"},onClick:r=>r.stopPropagation(),onMouseDown:r=>r.stopPropagation(),children:[j,s&&a(H,{action:async()=>{await L(e.id)},confirmText:p("delete.confirm",{defaultValue:"Are you sure you want to delete this item?"}),confirmTitle:p("delete.title",{defaultValue:"Delete Item"}),loadingText:p("delete.loading",{defaultValue:"Deleting..."}),variant:"destructive",icon:z,"aria-label":p("delete",{defaultValue:"Delete"}),children:p("delete",{defaultValue:"Delete"})})]}):null;return a(G,{title:String(T??""),subtitle:O,content:R??void 0,footer:E,clickable:!0,elevated:!0,onClick:f?()=>f(e.id):void 0,className:N,overlay:q??void 0,overlayPosition:"top-right",fullOverlay:M??void 0})}var W=I;export{I as CrudCard,W as default};
1
+ import{jsx as o,jsxs as L}from"react/jsx-runtime";import{Trash2 as G}from"lucide-react";import{useMemo as y}from"react";import{Card as H,Stack as k,Text as j,ActionButton as J}from"@donotdev/components";import{useTranslation as D,getListCardFieldNames as K}from"@donotdev/core";import{formatValue as h}from"./DisplayFieldRenderer";import{DisplayThumbnail as P}from"./DisplayThumbnail";import{translateFieldLabel as Q}from"../forms/utils/translateFieldLabel";import{useCrud as U}from"../useCrud";function d(e){return e==="image"||e==="images"}function W(e){return y(()=>{const t=e.listCardFields;if(t&&!Array.isArray(t))return{titleFields:t.title??[],subtitleFields:t.subtitle??[],contentFields:t.content??[],footerFields:t.footer??[]};const f=K(e),m=f.filter(p=>!d(e.fields[p]?.type)),C=f.filter(p=>d(e.fields[p]?.type)),b=m.length>0?[m[0]]:[],x=[...m.slice(1,4),...C];return{titleFields:b,subtitleFields:[],contentFields:x,footerFields:[]}},[e])}function I({item:e,entity:t,onClick:f,href:m,titleFields:C,subtitleFields:b,contentFields:x,footerFields:p,showDelete:w=!1,renderActions:V,renderOverlay:M,className:N}){const{t:s}=D([t.namespace,"crud"]),{t:a}=D("crud"),F=W(t),S=C??F.titleFields,A=b??F.subtitleFields,T=x??F.contentFields,g=p??F.footerFields,c=e,B=y(()=>{if(!S?.length)return e.id??"";const r=S.filter(i=>typeof i=="string").filter(i=>!d(t.fields[i]?.type)).map(i=>{const n=t.fields[i],v=e[i],u=n?h(v,n,s,{compact:!0,asString:!0,item:c}):v;return typeof u=="string"?u:String(u??"")}).filter(Boolean),l=!Array.isArray(t.listCardFields)&&t.listCardFields?.titleSeparator!=null?t.listCardFields.titleSeparator:" ";return r.join(l)||String(e.id??"")},[e,t.fields,S,t.listCardFields,s]),R=y(()=>A?.length&&A.filter(r=>typeof r=="string").filter(r=>!d(t.fields[r]?.type)).map(r=>{const l=t.fields[r],i=e[r],n=l?h(i,l,s,{compact:!0,asString:!0,item:c}):i;return typeof n=="string"?n:String(n??"")}).filter(Boolean).join(" ")||void 0,[e,t.fields,A,s]),E=y(()=>{if(!T?.length)return null;const r=T.map(l=>{const i=t.fields[l];if(!i||i.options?.displayValue?.(e[l],c,s)===null)return null;if(d(i.type)){const n=e[l];return n==null?null:o(P,{pictures:n,alt:String(B),aspectRatio:"16/9"},l)}return L("div",{children:[o(j,{level:"small",variant:"muted",children:Q(l,i,s)}),o(j,{children:h(e[l],i,s,{compact:!0,item:c})})]},l)}).filter(Boolean);return r.length>0?o(k,{direction:"column",gap:"tight",children:r}):null},[e,t.fields,T,B,s]),O=y(()=>{if(!g?.length)return;if(g.some(l=>d(t.fields[l]?.type))){const l=g.map(i=>{const n=t.fields[i];if(!n)return null;if(d(n.type)){const u=e[i];return u==null?null:o(P,{pictures:u,alt:"",aspectRatio:"1"},i)}const v=h(e[i],n,s,{compact:!0,item:c});return o("span",{children:v},i)});return o(k,{direction:"row",gap:"tight",align:"center",children:l.filter(Boolean)})}const r=g.map(l=>{const i=t.fields[l];return i?h(e[l],i,s,{compact:!0,item:c}):e[l]});return o(j,{level:"small",children:r.join(" \xB7 ")})},[e,t.fields,g,s]),q=U(t).delete,z=V||w?L("div",{style:{display:"flex",alignItems:"flex-start",gap:"var(--gap-xs)",pointerEvents:"auto"},onClick:r=>r.stopPropagation(),onMouseDown:r=>r.stopPropagation(),children:[V,w&&o(J,{action:async()=>{await q(e.id)},confirmText:a("delete.confirm",{defaultValue:"Are you sure you want to delete this item?"}),confirmTitle:a("delete.title",{defaultValue:"Delete Item"}),loadingText:a("delete.loading",{defaultValue:"Deleting..."}),confirmLabel:a("actions.delete"),cancelLabel:a("actions.cancel"),variant:"destructive",icon:G,"aria-label":a("actions.delete"),children:a("actions.delete")})]}):null;return o(H,{title:String(B??""),subtitle:R,content:E??void 0,footer:O,clickable:!0,elevated:!0,href:m,onClick:f?()=>f(e.id):void 0,className:N,overlay:z??void 0,overlayPosition:"top-right",fullOverlay:M??void 0})}var X=I;export{I as CrudCard,X as default};
@@ -1 +1 @@
1
- "use client";import{jsx as e,jsxs as j,Fragment as ct}from"react/jsx-runtime";import{X as ht}from"lucide-react";import{useState as k}from"react";import{Button as x,Calendar as St,FloatingLabel as Dt,Sheet as T,Text as M}from"@donotdev/components";import{formatDate as ft}from"@donotdev/core";function $t({label:S,fieldType:xt,value:o,onChange:D,tCrud:l,locale:N="en"}){const[F,i]=k(!1),[C,f]=k(null),O=o?typeof o=="object"&&o!==null&&"min"in o?{min:o.min||"",max:o.max||""}:{min:"",max:""}:{min:"",max:""},Y=t=>{if(!t)return"";try{const n=new Date(t+"T00:00:00");return ft(n,N)}catch{return t}},W=()=>{const t=new Date;t.setHours(0,0,0,0);const n=t.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),g=`${n}-${s}-${r}`,d=new Date(t);d.setDate(d.getDate()-1);const v=d.getFullYear(),$=String(d.getMonth()+1).padStart(2,"0"),B=String(d.getDate()).padStart(2,"0"),H=`${v}-${$}-${B}`,m=new Date(t);m.setDate(m.getDate()+1);const L=m.getFullYear(),X=String(m.getMonth()+1).padStart(2,"0"),q=String(m.getDate()).padStart(2,"0"),z=`${L}-${X}-${q}`,p=new Date(t);p.setDate(p.getDate()-7);const A=p.getFullYear(),G=String(p.getMonth()+1).padStart(2,"0"),J=String(p.getDate()).padStart(2,"0"),K=`${A}-${G}-${J}`,u=new Date(t);u.setDate(u.getDate()-30);const P=u.getFullYear(),Q=String(u.getMonth()+1).padStart(2,"0"),R=String(u.getDate()).padStart(2,"0"),U=`${P}-${Q}-${R}`,c=new Date(t);c.setDate(c.getDate()+7);const Z=c.getFullYear(),_=String(c.getMonth()+1).padStart(2,"0"),tt=String(c.getDate()).padStart(2,"0"),et=`${Z}-${_}-${tt}`,h=new Date(t);h.setDate(h.getDate()+30);const at=h.getFullYear(),nt=String(h.getMonth()+1).padStart(2,"0"),rt=String(h.getDate()).padStart(2,"0"),lt=`${at}-${nt}-${rt}`,y=new Date(t.getFullYear(),t.getMonth(),1),it=y.getFullYear(),dt=String(y.getMonth()+1).padStart(2,"0"),ot=String(y.getDate()).padStart(2,"0"),st=`${it}-${dt}-${ot}`,w=new Date(t.getFullYear(),t.getMonth()+1,0),gt=w.getFullYear(),mt=String(w.getMonth()+1).padStart(2,"0"),pt=String(w.getDate()).padStart(2,"0"),ut=`${gt}-${mt}-${pt}`;return{today:g,yesterday:H,tomorrow:z,last7Days:K,last30Days:U,next7Days:et,next30Days:lt,thisMonthStart:st,thisMonthEnd:ut}},a=O,E=W(),I=!!(a?.min||a?.max),b=t=>{const n=t==="start",s=n?a?.min:a?.max;return e("div",{style:{padding:"var(--gap-md)"},children:j("div",{style:{display:"flex",flexDirection:"column",gap:"var(--gap-md)"},children:[e("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--gap-tight)"},children:(n?["today","yesterday","last7Days","last30Days","thisMonthStart"]:["today","tomorrow","next7Days","next30Days","thisMonthEnd"]).map(r=>{const g=E[r];return e(x,{variant:"outline",onClick:()=>{D({min:n?g:a?.min||"",max:n?a?.max||"":g}),i(!1)},children:l(`filter.${r}`,{defaultValue:r})},r)})}),e(St,{selected:s?new Date(s+"T00:00:00"):void 0,mode:"single",onSelect:r=>{if(!r)return;const g=r.getFullYear(),d=String(r.getMonth()+1).padStart(2,"0"),v=String(r.getDate()).padStart(2,"0"),$=`${g}-${d}-${v}`;D({min:n?$:a?.min||"",max:n?a?.max||"":$}),i(!1)},defaultMonth:s?new Date(s+"T00:00:00"):new Date}),e(x,{variant:"ghost",display:"compact",onClick:()=>{D({min:n?"":a?.min||"",max:n&&a?.max||""}),i(!1)},children:l("filter.clear",{defaultValue:"Clear"})})]})})},V=j(ct,{children:[e(T,{trigger:e(x,{variant:"ghost",onClick:()=>{f("start"),i(!0)},style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",paddingInlineStart:"var(--gap-md)",justifyContent:"flex-start"},children:a?.min?Y(a.min):e(M,{as:"span",level:"small",variant:"muted",children:l("filter.min",{defaultValue:"Min"})})}),title:`${S} - ${l("filter.min",{defaultValue:"Min"})}`,open:F&&C==="start",onOpenChange:t=>{i(t),t||f(null)},children:b("start")}),e(M,{level:"small",variant:"muted",className:"dndev-range-input-separator",children:"\u2013"}),e(T,{trigger:e(x,{variant:"ghost",onClick:()=>{f("end"),i(!0)},style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",paddingInlineStart:"var(--gap-md)",justifyContent:"flex-start"},children:a?.max?Y(a.max):e(M,{as:"span",level:"small",variant:"muted",children:l("filter.max",{defaultValue:"Max"})})}),title:`${S} - ${l("filter.max",{defaultValue:"Max"})}`,open:F&&C==="end",onOpenChange:t=>{i(t),t||f(null)},children:b("end")}),e("button",{type:"button",className:"dndev-inline-action-btn",onClick:()=>{D(void 0)},disabled:!I,"aria-label":l("filter.clear",{defaultValue:"Clear"}),children:e(ht,{})})]});return S?e(Dt,{label:S,children:e("div",{className:"dndev-range-input",children:V})}):e("div",{className:"dndev-range-input",children:V})}export{$t as DateFilter};
1
+ "use client";import{jsx as e,jsxs as j,Fragment as ct}from"react/jsx-runtime";import{X as ht}from"lucide-react";import{useState as k}from"react";import{Button as x,Calendar as St,FloatingLabel as Dt,Sheet as T,Text as M}from"@donotdev/components";import{formatDate as ft}from"@donotdev/core";function $t({label:S,fieldType:xt,value:s,onChange:D,tCrud:l,locale:O="en"}){const[F,i]=k(!1),[C,f]=k(null),N=s?typeof s=="object"&&s!==null&&"min"in s?{min:s.min||"",max:s.max||""}:{min:"",max:""}:{min:"",max:""},Y=t=>{if(!t)return"";try{const n=new Date(t+"T00:00:00");return ft(n,O)}catch{return t}},W=()=>{const t=new Date;t.setHours(0,0,0,0);const n=t.getFullYear(),g=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),o=`${n}-${g}-${r}`,d=new Date(t);d.setDate(d.getDate()-1);const v=d.getFullYear(),$=String(d.getMonth()+1).padStart(2,"0"),B=String(d.getDate()).padStart(2,"0"),H=`${v}-${$}-${B}`,m=new Date(t);m.setDate(m.getDate()+1);const L=m.getFullYear(),X=String(m.getMonth()+1).padStart(2,"0"),q=String(m.getDate()).padStart(2,"0"),z=`${L}-${X}-${q}`,p=new Date(t);p.setDate(p.getDate()-7);const A=p.getFullYear(),G=String(p.getMonth()+1).padStart(2,"0"),J=String(p.getDate()).padStart(2,"0"),K=`${A}-${G}-${J}`,u=new Date(t);u.setDate(u.getDate()-30);const P=u.getFullYear(),Q=String(u.getMonth()+1).padStart(2,"0"),R=String(u.getDate()).padStart(2,"0"),U=`${P}-${Q}-${R}`,c=new Date(t);c.setDate(c.getDate()+7);const Z=c.getFullYear(),_=String(c.getMonth()+1).padStart(2,"0"),tt=String(c.getDate()).padStart(2,"0"),et=`${Z}-${_}-${tt}`,h=new Date(t);h.setDate(h.getDate()+30);const at=h.getFullYear(),nt=String(h.getMonth()+1).padStart(2,"0"),rt=String(h.getDate()).padStart(2,"0"),lt=`${at}-${nt}-${rt}`,y=new Date(t.getFullYear(),t.getMonth(),1),it=y.getFullYear(),dt=String(y.getMonth()+1).padStart(2,"0"),st=String(y.getDate()).padStart(2,"0"),gt=`${it}-${dt}-${st}`,w=new Date(t.getFullYear(),t.getMonth()+1,0),ot=w.getFullYear(),mt=String(w.getMonth()+1).padStart(2,"0"),pt=String(w.getDate()).padStart(2,"0"),ut=`${ot}-${mt}-${pt}`;return{today:o,yesterday:H,tomorrow:z,last7Days:K,last30Days:U,next7Days:et,next30Days:lt,thisMonthStart:gt,thisMonthEnd:ut}},a=N,E=W(),I=!!(a?.min||a?.max),b=t=>{const n=t==="start",g=n?a?.min:a?.max;return e("div",{style:{padding:"var(--gap-md)"},children:j("div",{style:{display:"flex",flexDirection:"column",gap:"var(--gap-md)"},children:[e("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--gap-tight)"},children:(n?["today","yesterday","last7Days","last30Days","thisMonthStart"]:["today","tomorrow","next7Days","next30Days","thisMonthEnd"]).map(r=>{const o=E[r];return e(x,{variant:"outline",onClick:()=>{D({min:n?o:a?.min||"",max:n?a?.max||"":o}),i(!1)},children:l(`filter.${r}`,{defaultValue:r})},r)})}),e(St,{selected:g?new Date(g+"T00:00:00"):void 0,mode:"single",onSelect:r=>{if(!r)return;const o=r.getFullYear(),d=String(r.getMonth()+1).padStart(2,"0"),v=String(r.getDate()).padStart(2,"0"),$=`${o}-${d}-${v}`;D({min:n?$:a?.min||"",max:n?a?.max||"":$}),i(!1)},defaultMonth:g?new Date(g+"T00:00:00"):new Date}),e(x,{variant:"ghost",display:"compact",onClick:()=>{D({min:n?"":a?.min||"",max:n&&a?.max||""}),i(!1)},children:l("filter.clear",{defaultValue:"Clear"})})]})})},V=j(ct,{children:[e(T,{trigger:e(x,{variant:"ghost",onClick:()=>{f("start"),i(!0)},style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",paddingInlineStart:"var(--gap-md)",justifyContent:"flex-start"},children:a?.min?Y(a.min):e(M,{as:"span",level:"small",variant:"muted",children:l("filter.min",{defaultValue:"Min"})})}),title:`${S} - ${l("filter.min",{defaultValue:"Min"})}`,open:F&&C==="start",onOpenChange:t=>{i(t),t||f(null)},children:b("start")}),e(M,{level:"small",variant:"muted",className:"dndev-range-input-separator",children:"\u2013"}),e(T,{trigger:e(x,{variant:"ghost",onClick:()=>{f("end"),i(!0)},style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",paddingInlineStart:"var(--gap-md)",justifyContent:"flex-start"},children:a?.max?Y(a.max):e(M,{as:"span",level:"small",variant:"muted",children:l("filter.max",{defaultValue:"Max"})})}),title:`${S} - ${l("filter.max",{defaultValue:"Max"})}`,open:F&&C==="end",onOpenChange:t=>{i(t),t||f(null)},children:b("end")}),e("button",{type:"button",className:"dndev-inline-action-btn",onClick:()=>{D(void 0)},disabled:!I,"aria-label":l("filter.clear",{defaultValue:"Clear"}),children:e(ht,{})})]});return S?e(Dt,{label:S,children:e("div",{className:"dndev-range-input",children:V})}):e("div",{className:"dndev-range-input",children:V})}export{$t as DateFilter};
@@ -8,7 +8,7 @@
8
8
  * @author AMBROISE PARK Consulting
9
9
  */
10
10
  import type { ReactElement } from 'react';
11
- import type { FieldType, EntityField } from '@donotdev/core';
11
+ import type { EntityField, FieldType } from '@donotdev/core';
12
12
  import type { DisplayFormatterOptions } from '../fieldTypeRegistry';
13
13
  /** Props for {@link DisplayFieldRenderer}, renders a field value as read-only text. */
14
14
  export interface DisplayFieldRendererProps<T extends FieldType = FieldType> {
@@ -22,7 +22,10 @@ export interface DisplayFieldRendererProps<T extends FieldType = FieldType> {
22
22
  t: (key: string, options?: Record<string, any>) => string;
23
23
  }
24
24
  /**
25
- * Formats a value for display based on field type
25
+ * Formats a value for display based on field type.
26
+ * Text output (`asString`, `displayKey`, `displayValue`) is `formatFieldText` from
27
+ * `@donotdev/core`, the same text entity SEO uses; other output is the registered
28
+ * display formatter's (React).
26
29
  *
27
30
  * @param value - Field value to format
28
31
  * @param config - Field configuration
@@ -1 +1 @@
1
- {"version":3,"file":"DisplayFieldRenderer.d.ts","sourceRoot":"","sources":["../../src/components/DisplayFieldRenderer.tsx"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAI1C,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAGpE,uFAAuF;AACvF,MAAM,WAAW,yBAAyB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IACxE,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACvB,0BAA0B;IAC1B,KAAK,EAAE,GAAG,CAAC;IACX,2BAA2B;IAC3B,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC;CAC3D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,G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