Skip to content

Commit

Permalink
feat: make setKeyInfoForResource public (#9352)
Browse files Browse the repository at this point in the history
* fix: make setKeyInfoForResource public

* fix export
  • Loading branch information
runspired authored Apr 12, 2024
1 parent 8d0688f commit 3e2ef9d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
8 changes: 1 addition & 7 deletions packages/store/src/-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ export { recordIdentifierFor } from './-private/caches/instance-cache';

export { CacheHandler, type LifetimesService } from './-private/cache-handler';

export {
setIdentifierGenerationMethod,
setIdentifierUpdateMethod,
setIdentifierForgetMethod,
setIdentifierResetMethod,
isStableIdentifier,
} from './-private/caches/identifier-cache';
export { isStableIdentifier } from './-private/caches/identifier-cache';

export { default as constructResource } from './-private/utils/construct-resource';

Expand Down
9 changes: 3 additions & 6 deletions packages/store/src/-private/caches/identifier-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import type { ExistingResourceObject, ResourceIdentifierObject } from '@warp-dri
import type {
ForgetMethod,
GenerationMethod,
KeyInfo,
KeyInfoMethod,
ResetMethod,
ResourceData,
UpdateMethod,
Expand Down Expand Up @@ -76,19 +78,14 @@ type TypeMap = { [key: string]: KeyOptions };
// type IdentifierTypeLookup = { all: Set<StableRecordIdentifier>; id: Map<string, StableRecordIdentifier> };
// type IdentifiersByType = Map<string, IdentifierTypeLookup>;
type IdentifierMap = Map<string, StableRecordIdentifier>;
type KeyInfo = {
id: string | null;
type: string;
};

type StableCache = {
resources: IdentifierMap;
documents: Map<string, StableDocumentIdentifier>;
resourcesByType: TypeMap;
polymorphicLidBackMap: Map<string, string[]>;
};

export type KeyInfoMethod = (resource: unknown, known: StableRecordIdentifier | null) => KeyInfo;

export type MergeMethod = (
targetIdentifier: StableRecordIdentifier,
matchedIdentifier: StableRecordIdentifier,
Expand Down
25 changes: 25 additions & 0 deletions packages/store/src/-types/q/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,28 @@ export type ForgetMethod = (identifier: StableIdentifier | StableRecordIdentifie
@static
*/
export type ResetMethod = () => void;

/**
Configure a callback for when the identifier cache is generating a new
StableRecordIdentifier for a resource.
This method controls the `type` and `id` that will be assigned to the
`StableRecordIdentifier` that is created.
This configuration MUST occur prior to the store instance being created.
```js
import { setKeyInfoForResource } from '@ember-data/store';
```
@method setKeyInfoForResource
@for @ember-data/store
@param method
@public
@static
*/
export type KeyInfo = {
id: string | null;
type: string;
};
export type KeyInfoMethod = (resource: unknown, known: StableRecordIdentifier | null) => KeyInfo;
10 changes: 7 additions & 3 deletions packages/store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,14 @@ export {
CacheHandler,
type LifetimesService,
type StoreRequestInput,
recordIdentifierFor,
storeFor,
} from './-private';

export {
setIdentifierGenerationMethod,
setIdentifierUpdateMethod,
setIdentifierForgetMethod,
setIdentifierResetMethod,
recordIdentifierFor,
storeFor,
} from './-private';
setKeyInfoForResource,
} from './-private/caches/identifier-cache';
1 change: 1 addition & 0 deletions tests/docs/fixtures/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ module.exports = {
'(public) @ember-data/store @ember-data/store#setIdentifierGenerationMethod',
'(public) @ember-data/store @ember-data/store#setIdentifierResetMethod',
'(public) @ember-data/store @ember-data/store#setIdentifierUpdateMethod',
'(public) @ember-data/store @ember-data/store#setKeyInfoForResource',
'(public) @ember-data/store CacheManager#changedAttrs',
'(public) @ember-data/store CacheManager#clientDidCreate',
'(public) @ember-data/store CacheManager#commitWasRejected',
Expand Down

0 comments on commit 3e2ef9d

Please sign in to comment.