Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make setKeyInfoForResource public #9352

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading