Skip to content

Commit

Permalink
feat(wrap): add withDomainDrivenGets cache wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed Aug 7, 2023
1 parent 6a1d854 commit d5e09ea
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 0 deletions.
Empty file modified .husky/check.commit.sh
100644 → 100755
Empty file.
Empty file modified .husky/check.lockfile.sh
100644 → 100755
Empty file.
Empty file modified .husky/commit-msg
100644 → 100755
Empty file.
Empty file modified .husky/post-checkout
100644 → 100755
Empty file.
Empty file modified .husky/post-merge
100644 → 100755
Empty file.
Empty file modified .husky/post-rewrite
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
23 changes: 23 additions & 0 deletions src/logic/withDomainDrivenGets.ts
Original file line number Diff line number Diff line change
@@ -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<string>,
): SimpleCache<SerializableObject> =>
withoutSet(withDenormalization(withSerialization<SerializableObject>(cache)));

0 comments on commit d5e09ea

Please sign in to comment.