@confighub/rtk-query 0.1.1 → 0.1.2

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.
package/README.md CHANGED
@@ -45,6 +45,54 @@ function Spaces() {
45
45
  }
46
46
  ```
47
47
 
48
+ ## Configuration data
49
+
50
+ A Unit's configuration is not a field of the Unit. `Unit`, `Revision` and `Release` carry
51
+ `DataHash` and `DataSize`; the document itself has its own endpoints, and its own hooks:
52
+
53
+ ```tsx
54
+ const { data: config } = useDownloadUnitDataQuery({ spaceId, unitId }); // a string
55
+ const [uploadUnitData] = useUploadUnitDataMutation();
56
+
57
+ await uploadUnitData({
58
+ spaceId,
59
+ unitId,
60
+ body: edited, // the document, not a JSON envelope
61
+ lastChangeDescription: 'raise replicas',
62
+ include: 'ConfigData', // the configuration the write produced
63
+ }).unwrap();
64
+ ```
65
+
66
+ `useGetUnitMutationSourcesQuery` reads what set each value. For a list, use the bulk
67
+ queries — `useSearchUnitDataQuery`, `useSearchRevisionDataQuery`,
68
+ `useSearchUnitMutationSourcesQuery`, `useSearchRevisionMutationSourcesQuery` — each of
69
+ which takes a `where` clause and answers for many Units in one request. One request per
70
+ Unit is what taking the configuration off the entity was meant to avoid.
71
+
72
+ Three things to know, none of which the type checker enforces:
73
+
74
+ - **These endpoints serve `application/octet-stream`.** The base query sets
75
+ `responseHandler: 'content-type'` for exactly this reason: RTK Query's default `'json'`
76
+ handler `JSON.parse`s every body, which fails on YAML and surfaces as a parse error with
77
+ no data — an empty editor and nothing to say why. If you build your own base query,
78
+ carry that setting over.
79
+ - **A write answers with the operation's result, not the entity.** `useCreateUnitMutation`,
80
+ `useUpdateUnitMutation`, `usePatchUnitMutation`, `useUploadUnitDataMutation` and the bulk
81
+ forms return `UnitCreateOrUpdateResponse`; the Unit is in its `Unit` field. For a
82
+ `dryRun`, `include: 'ConfigData,MutationSources'` is the only way to see what the
83
+ operation produced, since nothing was stored.
84
+ - **An empty configuration is a configuration** — emptying a Unit is how its resources are
85
+ withdrawn — so never guard the upload with `if (body)`.
86
+
87
+ Every parameter describing how the configuration should land goes on
88
+ `uploadUnitData`, not on a metadata update before it: `mergeExternalSource`, `mergeBase`,
89
+ `mergeEnableSubtraction`, `protect`, `clearance`, `tag`, `subgroup`, `changeSetId`,
90
+ `lastChangeDescription` and `dryRun`. A metadata call changes no configuration, so
91
+ anything sent there is silently dropped.
92
+
93
+ Naming `Data` or `MutationSources` in a `select` is a 400 rather than a silently absent
94
+ field. There is one content hash, `DataHash`; `ContentHash` and `RevisionHash` are gone.
95
+
48
96
  ## Notes
49
97
 
50
98
  - `baseUrl` is the instance origin; the client targets `{baseUrl}/api`. Same value as