From d5e09eaedd17931ed969b32bac4ab839d15bdd6c Mon Sep 17 00:00:00 2001 From: Ulad Kasach Date: Mon, 7 Aug 2023 04:01:56 -0700 Subject: [PATCH] feat(wrap): add withDomainDrivenGets cache wrapper --- .husky/check.commit.sh | 0 .husky/check.lockfile.sh | 0 .husky/commit-msg | 0 .husky/post-checkout | 0 .husky/post-merge | 0 .husky/post-rewrite | 0 src/index.ts | 1 + src/logic/withDomainDrivenGets.ts | 23 +++++++++++++++++++++++ 8 files changed, 24 insertions(+) mode change 100644 => 100755 .husky/check.commit.sh mode change 100644 => 100755 .husky/check.lockfile.sh mode change 100644 => 100755 .husky/commit-msg mode change 100644 => 100755 .husky/post-checkout mode change 100644 => 100755 .husky/post-merge mode change 100644 => 100755 .husky/post-rewrite create mode 100644 src/logic/withDomainDrivenGets.ts diff --git a/.husky/check.commit.sh b/.husky/check.commit.sh old mode 100644 new mode 100755 diff --git a/.husky/check.lockfile.sh b/.husky/check.lockfile.sh old mode 100644 new mode 100755 diff --git a/.husky/commit-msg b/.husky/commit-msg old mode 100644 new mode 100755 diff --git a/.husky/post-checkout b/.husky/post-checkout old mode 100644 new mode 100755 diff --git a/.husky/post-merge b/.husky/post-merge old mode 100644 new mode 100755 diff --git a/.husky/post-rewrite b/.husky/post-rewrite old mode 100644 new mode 100755 diff --git a/src/index.ts b/src/index.ts index a920461..8dbd363 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ export { ref } from './logic/ref/ref'; export { withMutationEffects } from './logic/withMutationEffects'; export { withQueryCaching } from './logic/withQueryCaching'; +export { withDomainDrivenGets } from './logic/withDomainDrivenGets'; export * from './domain/DomainDrivenQueryDependency'; export * from './domain/DomainDrivenQueryDependsOn'; diff --git a/src/logic/withDomainDrivenGets.ts b/src/logic/withDomainDrivenGets.ts new file mode 100644 index 0000000..dc39f7e --- /dev/null +++ b/src/logic/withDomainDrivenGets.ts @@ -0,0 +1,23 @@ +import { withoutSet } from 'simple-lambda-client'; +import { + withDenormalization, + withSerialization, +} from 'with-cache-normalization'; +import { SerializableObject } from 'with-cache-normalization/dist/domain/NormalizeCacheValueMethod'; +import { SimpleCache } from 'with-simple-caching'; + +/** + * a method which makes it easy to get from a domain-driven cache, without access to the query logic itself + * + * specifically + * - adds withoutSet to the cache, since only the withQueryCaching wrapped method should be calling that + * - adds withSerialization to the cache, to make it compatible with normalization + * - adds withDenormalization to the cache, to enable it to denormalize the normalized cached query outputs + * + * usecase + * - accessing outputs .set by a lambda server, at the lambda client (e.g., with [simple-lambda-client](https://github.com/ehmpathy/simple-lambda-client)) + */ +export const withDomainDrivenGets = ( + cache: SimpleCache, +): SimpleCache => + withoutSet(withDenormalization(withSerialization(cache)));