@salesforce/lds-drafts 1.171.0 → 1.172.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/ldsDrafts.js
CHANGED
|
@@ -264,9 +264,14 @@ function buildLuvioOverrideForDraftAdapters(luvio, handler, extractTargetIdFromC
|
|
|
264
264
|
if (options.forDeleteAdapter === true) {
|
|
265
265
|
// delete adapters attempt to evict the record on successful network response,
|
|
266
266
|
// since draft-aware delete adapters do soft-delete (record stays in cache
|
|
267
|
-
// with a "drafts.deleted" property) we want
|
|
268
|
-
|
|
269
|
-
|
|
267
|
+
// with a "drafts.deleted" property) we just want to let the environment know so it can
|
|
268
|
+
// decrement its ref count for the record
|
|
269
|
+
const storeEvict = function (key) {
|
|
270
|
+
const softEvict = luvio.environment.softEvict;
|
|
271
|
+
if (softEvict === undefined) {
|
|
272
|
+
throw Error('DraftAwareEnvironment not configured correctly');
|
|
273
|
+
}
|
|
274
|
+
softEvict(key);
|
|
270
275
|
};
|
|
271
276
|
return create(luvio, {
|
|
272
277
|
dispatchResourceRequest: { value: dispatchResourceRequest },
|
|
@@ -1720,29 +1725,46 @@ function makeEnvironmentDraftAware(luvio, env, durableStore, handlers, draftQueu
|
|
|
1720
1725
|
};
|
|
1721
1726
|
const storePublish = function (key, data) {
|
|
1722
1727
|
const draftMetadataForKey = draftMetadata[key];
|
|
1728
|
+
let handled = false;
|
|
1723
1729
|
for (const handler of handlers) {
|
|
1724
1730
|
if (handler.canHandlePublish(key)) {
|
|
1731
|
+
handled = true;
|
|
1725
1732
|
handler.applyDraftsToIncomingData(key, data, draftMetadataForKey && draftMetadataForKey.metadata, env.storePublish);
|
|
1726
|
-
|
|
1733
|
+
// deletes the draft metadata once it is published and has 0 ref.
|
|
1734
|
+
if (draftMetadataForKey &&
|
|
1735
|
+
draftMetadataForKey.metadata &&
|
|
1736
|
+
draftMetadataForKey.refCount === 0) {
|
|
1737
|
+
delete draftMetadata[key];
|
|
1738
|
+
}
|
|
1739
|
+
break;
|
|
1727
1740
|
}
|
|
1728
1741
|
}
|
|
1742
|
+
decrementRefCount(key);
|
|
1743
|
+
// no handler could handle it so publish
|
|
1744
|
+
if (!handled) {
|
|
1745
|
+
env.storePublish(key, data);
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
const decrementRefCount = function (key) {
|
|
1749
|
+
const draftMetadataForKey = draftMetadata[key];
|
|
1729
1750
|
if (draftMetadataForKey !== undefined) {
|
|
1730
|
-
//
|
|
1731
|
-
// fields get published before the root record.
|
|
1751
|
+
// metadata is needed for a once-draft record to create ref link for spanning fields.
|
|
1732
1752
|
if (draftMetadataForKey.refCount === 1) {
|
|
1733
|
-
|
|
1734
|
-
}
|
|
1735
|
-
else {
|
|
1736
|
-
draftMetadataForKey.refCount--;
|
|
1753
|
+
draftMetadata[key].metadata.recordOperations = [];
|
|
1737
1754
|
}
|
|
1755
|
+
draftMetadataForKey.refCount--;
|
|
1738
1756
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1757
|
+
};
|
|
1758
|
+
// when a record is soft deleted it won't be published so won't decrement the ref count
|
|
1759
|
+
// this is a backdoor to decrement the ref count
|
|
1760
|
+
const softEvict = function (key) {
|
|
1761
|
+
decrementRefCount(key);
|
|
1741
1762
|
};
|
|
1742
1763
|
// note the makeEnvironmentUiApiRecordDraftAware will eventually go away once the adapters become draft aware
|
|
1743
1764
|
return create(env, {
|
|
1744
1765
|
storePublish: { value: storePublish },
|
|
1745
1766
|
handleSuccessResponse: { value: handleSuccessResponse },
|
|
1767
|
+
softEvict: { value: softEvict },
|
|
1746
1768
|
});
|
|
1747
1769
|
}
|
|
1748
1770
|
|
package/dist/types/main.d.ts
CHANGED
|
@@ -11,5 +11,6 @@ export type { CustomActionResult } from './actionHandlers/CustomActionHandler';
|
|
|
11
11
|
export { CustomActionResultType, CustomActionExecutor } from './actionHandlers/CustomActionHandler';
|
|
12
12
|
export { AbstractResourceRequestActionHandler, ResponseIngestionEntry, } from './actionHandlers/AbstractResourceRequestActionHandler';
|
|
13
13
|
export { makeEnvironmentDraftAware } from './makeEnvironmentDraftAware';
|
|
14
|
+
export type { DraftAwareEnvironment } from './makeEnvironmentDraftAware';
|
|
14
15
|
export * from './DraftFetchResponse';
|
|
15
16
|
export { DraftSynthesisErrorType, DraftSynthesisError, isDraftSynthesisError, } from './DraftSynthesisError';
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { Luvio, ResourceRequest } from '@luvio/engine';
|
|
2
2
|
import type { DurableEnvironment, DurableStore } from '@luvio/environments';
|
|
3
3
|
import type { ActionHandler, DraftQueue } from './main';
|
|
4
|
-
export
|
|
4
|
+
export interface DraftAwareEnvironment extends DurableEnvironment {
|
|
5
|
+
softEvict: (key: string) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function makeEnvironmentDraftAware(luvio: Luvio, env: DurableEnvironment, durableStore: DurableStore, handlers: ActionHandler<ResourceRequest, any, any>[], draftQueue: DraftQueue): DraftAwareEnvironment;
|