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)));