@stonecrop/stonecrop 0.35.0 → 0.36.0
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/dist/stonecrop.d.ts +7 -9
- package/dist/stonecrop.js +15 -20
- package/dist/stonecrop.js.map +1 -1
- package/package.json +4 -4
package/dist/stonecrop.d.ts
CHANGED
|
@@ -46,6 +46,8 @@ export declare type ActionDispatchResult = {
|
|
|
46
46
|
success: boolean;
|
|
47
47
|
data: unknown;
|
|
48
48
|
error: string | null;
|
|
49
|
+
/** The record as a read returns it after the action; null when it failed or targets no record. */
|
|
50
|
+
record: Record<string, unknown> | null;
|
|
49
51
|
};
|
|
50
52
|
|
|
51
53
|
/**
|
|
@@ -2032,21 +2034,17 @@ export declare class Stonecrop {
|
|
|
2032
2034
|
* client and its server handlers, not something this layer may parse. Dropping the stale key
|
|
2033
2035
|
* and moving the route therefore stay with `useClientAction`, which knows both ids.
|
|
2034
2036
|
*
|
|
2035
|
-
*
|
|
2036
|
-
*
|
|
2037
|
-
*
|
|
2037
|
+
* What is filed is the result's `record`, the server's read of the record after the action, and
|
|
2038
|
+
* never its `data`, which is whatever the action's handler returned. A result with no `record`
|
|
2039
|
+
* leaves the stored copy alone.
|
|
2038
2040
|
*
|
|
2039
2041
|
* @param doctype - The doctype
|
|
2040
2042
|
* @param action - Action name to execute (e.g., 'SUBMIT', 'APPROVE', 'save')
|
|
2041
2043
|
* @param args - Action arguments (typically record ID and/or form data)
|
|
2042
|
-
* @returns Action result with success status,
|
|
2044
|
+
* @returns Action result with success status, the handler's data, any error, and the record
|
|
2043
2045
|
* @throws Error if no data client has been configured
|
|
2044
2046
|
*/
|
|
2045
|
-
dispatchAction(doctype: Doctype, action: string, args?: unknown[]): Promise<
|
|
2046
|
-
success: boolean;
|
|
2047
|
-
data: unknown;
|
|
2048
|
-
error: string | null;
|
|
2049
|
-
}>;
|
|
2047
|
+
dispatchAction(doctype: Doctype, action: string, args?: unknown[]): Promise<ActionDispatchResult>;
|
|
2050
2048
|
/**
|
|
2051
2049
|
* Ensure doctype section exists in HST store
|
|
2052
2050
|
* @param slug - The doctype slug
|
package/dist/stonecrop.js
CHANGED
|
@@ -1573,21 +1573,21 @@ var Stonecrop = class Stonecrop {
|
|
|
1573
1573
|
* client and its server handlers, not something this layer may parse. Dropping the stale key
|
|
1574
1574
|
* and moving the route therefore stay with `useClientAction`, which knows both ids.
|
|
1575
1575
|
*
|
|
1576
|
-
*
|
|
1577
|
-
*
|
|
1578
|
-
*
|
|
1576
|
+
* What is filed is the result's `record`, the server's read of the record after the action, and
|
|
1577
|
+
* never its `data`, which is whatever the action's handler returned. A result with no `record`
|
|
1578
|
+
* leaves the stored copy alone.
|
|
1579
1579
|
*
|
|
1580
1580
|
* @param doctype - The doctype
|
|
1581
1581
|
* @param action - Action name to execute (e.g., 'SUBMIT', 'APPROVE', 'save')
|
|
1582
1582
|
* @param args - Action arguments (typically record ID and/or form data)
|
|
1583
|
-
* @returns Action result with success status,
|
|
1583
|
+
* @returns Action result with success status, the handler's data, any error, and the record
|
|
1584
1584
|
* @throws Error if no data client has been configured
|
|
1585
1585
|
*/
|
|
1586
1586
|
async dispatchAction(doctype, action, args) {
|
|
1587
1587
|
if (!this._client) throw new Error("No data client configured. Call setClient() with a DataClient implementation (e.g., StonecropClient from @stonecrop/graphql-client) before dispatching actions.");
|
|
1588
1588
|
const result = await this._client.runAction(doctype, action, args);
|
|
1589
|
-
|
|
1590
|
-
|
|
1589
|
+
const { record } = result;
|
|
1590
|
+
if (result.success && record) {
|
|
1591
1591
|
if (record[doctype.recordIdField] !== void 0) {
|
|
1592
1592
|
const settledId = doctype.getRecordId(record);
|
|
1593
1593
|
if (settledId !== void 0) this.addRecord(doctype, settledId, record);
|
|
@@ -2055,13 +2055,10 @@ function updateNestedObject(obj, path, value) {
|
|
|
2055
2055
|
//#endregion
|
|
2056
2056
|
//#region src/client-action.ts
|
|
2057
2057
|
/**
|
|
2058
|
-
* The identity
|
|
2058
|
+
* The identity an action's `record` settled on, or `undefined` when it states none.
|
|
2059
2059
|
*
|
|
2060
2060
|
* Deliberately stricter than `getRecordId`: that falls back to `id` when the declared key is
|
|
2061
|
-
* absent, which
|
|
2062
|
-
* natural-keyed doctype) look like a rename and relocate the record to a key the adapter cannot
|
|
2063
|
-
* look up. An action whose result carries no identity at all — a `{ state }` outcome — leaves the
|
|
2064
|
-
* record exactly where it is.
|
|
2061
|
+
* absent, which would relocate a natural-keyed record to a key the adapter cannot look up.
|
|
2065
2062
|
*/
|
|
2066
2063
|
function settledRecordId(doctype, record) {
|
|
2067
2064
|
if (record[doctype.recordIdField] === void 0) return void 0;
|
|
@@ -2124,13 +2121,15 @@ function useClientAction(options = {}) {
|
|
|
2124
2121
|
if (!sc) return {
|
|
2125
2122
|
success: false,
|
|
2126
2123
|
data: null,
|
|
2127
|
-
error: "Stonecrop is not initialized"
|
|
2124
|
+
error: "Stonecrop is not initialized",
|
|
2125
|
+
record: null
|
|
2128
2126
|
};
|
|
2129
2127
|
const doctype = sc.registry.getDoctype(doctypeSlug);
|
|
2130
2128
|
if (!doctype) return {
|
|
2131
2129
|
success: false,
|
|
2132
2130
|
data: null,
|
|
2133
|
-
error: `Unknown doctype: ${doctypeSlug}
|
|
2131
|
+
error: `Unknown doctype: ${doctypeSlug}`,
|
|
2132
|
+
record: null
|
|
2134
2133
|
};
|
|
2135
2134
|
const isDraft = isDraftRecordId(recordId);
|
|
2136
2135
|
const result = await sc.dispatchAction(doctype, action, buildArgs({
|
|
@@ -2141,14 +2140,10 @@ function useClientAction(options = {}) {
|
|
|
2141
2140
|
data,
|
|
2142
2141
|
extra
|
|
2143
2142
|
}));
|
|
2144
|
-
|
|
2145
|
-
|
|
2143
|
+
const { record } = result;
|
|
2144
|
+
if (result.success && record) {
|
|
2146
2145
|
const settledId = settledRecordId(doctype, record);
|
|
2147
|
-
if (settledId
|
|
2148
|
-
if (!isDraft) sc.addRecord(doctypeSlug, recordId, record);
|
|
2149
|
-
return result;
|
|
2150
|
-
}
|
|
2151
|
-
if (recordId !== settledId) {
|
|
2146
|
+
if (settledId !== void 0 && recordId !== settledId) {
|
|
2152
2147
|
sc.removeRecord(doctypeSlug, recordId);
|
|
2153
2148
|
await followRecord({
|
|
2154
2149
|
doctype: doctypeSlug,
|