diff --git a/examples/benchmark/normalizr.js b/examples/benchmark/normalizr.js index 7e1f80e5b8f6..a8ac0c991ca0 100644 --- a/examples/benchmark/normalizr.js +++ b/examples/benchmark/normalizr.js @@ -36,7 +36,7 @@ const queryInfer = queryMemo.buildQueryKey( let githubState = normalize(User, userData); -const date = Date.now() +const date = Date.now(); const actionMeta = { fetchedAt: date, date, @@ -55,8 +55,10 @@ export default function addNormlizrSuite(suite) { let curState = initialState; return suite .add('normalizeLong', () => { - normalize(ProjectSchema, data, [], curState, actionMeta); - curState = { ...initialState, entities: {}, endpoints: {} }; + normalize(ProjectSchema, data, [], initialState, actionMeta); + }) + .add('normalizeLong with merge', () => { + curState = normalize(ProjectSchema, data, [], curState, actionMeta); }) .add('infer All', () => { return new MemoCache().buildQueryKey( diff --git a/packages/endpoint/src/SnapshotInterface.ts b/packages/endpoint/src/SnapshotInterface.ts index f297a8aef95f..0c34bc13b6da 100644 --- a/packages/endpoint/src/SnapshotInterface.ts +++ b/packages/endpoint/src/SnapshotInterface.ts @@ -3,36 +3,30 @@ import type { EndpointInterface, Queryable } from './interface.js'; import type { DenormalizeNullable, SchemaArgs } from './normal.js'; export interface SnapshotInterface { - readonly fetchedAt: number; - readonly abort: Error; - /** * Gets the (globally referentially stable) response for a given endpoint/args pair from state given. * @see https://dataclient.io/docs/api/Snapshot#getResponse */ - getResponse( - endpoint: E, - ...args: readonly [null] - ): { - data: DenormalizeNullable; - expiryStatus: ExpiryStatusInterface; - expiresAt: number; - }; - - getResponse( + getResponse< + E extends Pick, + >( endpoint: E, - ...args: readonly [...Parameters] + ...args: readonly any[] ): { data: DenormalizeNullable; expiryStatus: ExpiryStatusInterface; expiresAt: number; }; - getResponse< + /** + * Gets the (globally referentially stable) response for a given endpoint/args pair from state given. + * @see https://dataclient.io/docs/api/Snapshot#getResponseMeta + */ + getResponseMeta< E extends Pick, >( endpoint: E, - ...args: readonly [...Parameters] | readonly [null] + ...args: readonly any[] ): { data: DenormalizeNullable; expiryStatus: ExpiryStatusInterface; @@ -40,24 +34,34 @@ export interface SnapshotInterface { }; /** @see https://dataclient.io/docs/api/Snapshot#getError */ - getError( - endpoint: E, - ...args: readonly [...Parameters] | readonly [null] - ): ErrorTypes | undefined; - - getError>( + getError: < + E extends Pick, + Args extends readonly [...Parameters], + >( endpoint: E, - ...args: readonly [...Parameters] | readonly [null] - ): ErrorTypes | undefined; + ...args: Args + ) => ErrorTypes | undefined; /** * Retrieved memoized value for any Querable schema * @see https://dataclient.io/docs/api/Snapshot#get */ - get( + get(schema: S, ...args: readonly any[]): any; + + /** + * Queries the store for a Querable schema; providing related metadata + * @see https://dataclient.io/docs/api/Snapshot#getQueryMeta + */ + getQueryMeta( schema: S, - ...args: SchemaArgs - ): DenormalizeNullable | undefined; + ...args: readonly any[] + ): { + data: any; + countRef: () => () => void; + }; + + readonly fetchedAt: number; + readonly abort: Error; } // looser version to allow for cross-package version compatibility