diff --git a/.changeset/dry-carrots-hammer.md b/.changeset/dry-carrots-hammer.md new file mode 100644 index 000000000000..8eaca7d83390 --- /dev/null +++ b/.changeset/dry-carrots-hammer.md @@ -0,0 +1,6 @@ +--- +'@data-client/test': patch +--- + +Support [actionTypes](https://dataclient.io/docs/api/Actions) without \_TYPE suffix + diff --git a/.changeset/nasty-roses-ring.md b/.changeset/nasty-roses-ring.md new file mode 100644 index 000000000000..6d91020f4471 --- /dev/null +++ b/.changeset/nasty-roses-ring.md @@ -0,0 +1,48 @@ +--- +'@data-client/react': patch +'@data-client/core': patch +--- + +Add [actionTypes](https://dataclient.io/docs/api/Actions) without \_TYPE suffix + +(Not breaking - we keep the old actionTypes name as well.) + +```ts title="Before" +import type { Manager, Middleware } from '@data-client/react'; +import { actionTypes } from '@data-client/react'; + +export default class LoggingManager implements Manager { + middleware: Middleware = controller => next => async action => { + switch (action.type) { + case actionTypes.SET_RESPONSE_TYPE: + console.info( + `${action.endpoint.name} ${JSON.stringify(action.response)}`, + ); + default: + return next(action); + } + }; + + cleanup() {} +} +``` + +```ts title="After" +import type { Manager, Middleware } from '@data-client/react'; +import { actionTypes } from '@data-client/react'; + +export default class LoggingManager implements Manager { + middleware: Middleware = controller => next => async action => { + switch (action.type) { + case actionTypes.SET_RESPONSE: + console.info( + `${action.endpoint.name} ${JSON.stringify(action.response)}`, + ); + default: + return next(action); + } + }; + + cleanup() {} +} +``` diff --git a/docs/core/api/Actions.md b/docs/core/api/Actions.md index 28d592ed8150..cbd936ed0f5e 100644 --- a/docs/core/api/Actions.md +++ b/docs/core/api/Actions.md @@ -30,7 +30,7 @@ interface FetchMeta { } interface FetchAction { - type: typeof FETCH_TYPE; + type: typeof actionTypes.FETCH; endpoint: Endpoint; args: readonly [...Parameters]; key: string; @@ -45,7 +45,7 @@ Comes from [Controller.fetch()](./Controller.md#fetch), [Controller.fetchIfStale ```ts interface SetAction { - type: typeof SET_TYPE; + type: typeof actionTypes.SET; schema: Queryable; args: readonly any[]; meta: ActionMeta; @@ -59,7 +59,7 @@ Comes from [Controller.set()](./Controller.md#set) ```ts interface SetResponseAction { - type: typeof SET_RESPONSE_TYPE; + type: typeof actionTypes.SET_RESPONSE; endpoint: Endpoint; args: readonly any[]; key: string; @@ -75,7 +75,7 @@ Comes from [Controller.setResponse()](./Controller.md#setResponse), [NetworkMana ```ts interface ResetAction { - type: typeof RESET_TYPE; + type: typeof actionTypes.RESET; date: number; } ``` @@ -86,7 +86,7 @@ Comes from [Controller.resetEntireStore()](./Controller.md#resetEntireStore) ```ts interface SubscribeAction { - type: typeof SUBSCRIBE_TYPE; + type: typeof actionTypes.SUBSCRIBE; endpoint: Endpoint; args: readonly any[]; key: string; @@ -99,7 +99,7 @@ Comes from [Controller.subscribe()](./Controller.md#subscribe), [useSubscription ```ts interface UnsubscribeAction { - type: typeof UNSUBSCRIBE_TYPE; + type: typeof actionTypes.UNSUBSCRIBE; endpoint: Endpoint; args: readonly any[]; key: string; @@ -112,7 +112,7 @@ Comes from [Controller.unsubscribe()](./Controller.md#unsubscribe), [useSubscrip ```ts interface InvalidateAction { - type: typeof INVALIDATE_TYPE; + type: typeof actionTypes.INVALIDATE; key: string; } ``` @@ -123,7 +123,7 @@ Comes from [Controller.invalidate()](./Controller.md#invalidate) ```ts interface InvalidateAllAction { - type: typeof INVALIDATEALL_TYPE; + type: typeof actionTypes.INVALIDATEALL; testKey: (key: string) => boolean; } ``` @@ -134,7 +134,7 @@ Comes from [Controller.invalidateAll()](./Controller.md#invalidateAll) ```ts interface ExpireAllAction { - type: typeof EXPIREALL_TYPE; + type: typeof actionTypes.EXPIREALL; testKey: (key: string) => boolean; } ``` diff --git a/docs/core/api/Controller.md b/docs/core/api/Controller.md index 565e17d033d4..546f5936a416 100644 --- a/docs/core/api/Controller.md +++ b/docs/core/api/Controller.md @@ -556,7 +556,7 @@ import type { EndpointInterface } from '@data-client/endpoint'; export default class MyManager implements Manager { middleware: Middleware = controller => { return next => async action => { - if (action.type === actionTypes.FETCH_TYPE) { + if (action.type === actionTypes.FETCH) { console.log('The existing response of the requested fetch'); console.log( controller.getResponse( diff --git a/docs/core/api/Manager.md b/docs/core/api/Manager.md index 21ced6542eca..1321ee19c352 100644 --- a/docs/core/api/Manager.md +++ b/docs/core/api/Manager.md @@ -272,7 +272,7 @@ import { actionTypes } from '@data-client/react'; export default class LoggingManager implements Manager { middleware: Middleware = controller => next => async action => { switch (action.type) { - case actionTypes.SET_RESPONSE_TYPE: + case actionTypes.SET_RESPONSE: if (action.endpoint.sideEffect) { console.info( `${action.endpoint.name} ${JSON.stringify(action.response)}`, @@ -326,12 +326,12 @@ export default class CustomSubsManager implements Manager { middleware: Middleware = controller => next => async action => { switch (action.type) { - case actionTypes.SUBSCRIBE_TYPE: - case actionTypes.UNSUBSCRIBE_TYPE: + case actionTypes.SUBSCRIBE: + case actionTypes.UNSUBSCRIBE: const { schema } = action.endpoint; // only process registered entities if (schema && isEntity(schema) && schema.key in this.entities) { - if (action.type === actionTypes.SUBSCRIBE_TYPE) { + if (action.type === actionTypes.SUBSCRIBE) { this.subscribe(schema.key, action.args[0]?.product_id); } else { this.unsubscribe(schema.key, action.args[0]?.product_id); @@ -357,5 +357,5 @@ export default class CustomSubsManager implements Manager { By `return Promise.resolve();` instead of calling `next(action)`, we prevent managers listed after this one from seeing that [action](./Actions.md). -Types: `FETCH_TYPE`, `SET_TYPE`, `SET_RESPONSE_TYPE`, `RESET_TYPE`, `SUBSCRIBE_TYPE`, -`UNSUBSCRIBE_TYPE`, `INVALIDATE_TYPE`, `INVALIDATEALL_TYPE`, `EXPIREALL_TYPE` +Types: `FETCH`, `SET`, `SET_RESPONSE`, `RESET`, `SUBSCRIBE`, +`UNSUBSCRIBE`, `INVALIDATE`, `INVALIDATEALL`, `EXPIREALL` diff --git a/docs/core/api/NetworkManager.md b/docs/core/api/NetworkManager.md index e2dc17fe319d..946d9adf4128 100644 --- a/docs/core/api/NetworkManager.md +++ b/docs/core/api/NetworkManager.md @@ -50,7 +50,7 @@ Default: ```ts skipLogging(action: ActionTypes) { - return action.type === FETCH_TYPE && action.meta.key in this.fetched; + return action.type === FETCH && action.meta.key in this.fetched; } ``` diff --git a/docs/core/concepts/managers.md b/docs/core/concepts/managers.md index aa0e174b909e..8c207c531276 100644 --- a/docs/core/concepts/managers.md +++ b/docs/core/concepts/managers.md @@ -78,8 +78,7 @@ we can maintain fresh data when the data updates are independent of user action. price, or a real-time collaborative editor. ```typescript -import type { Manager, Middleware, ActionTypes } from '@data-client/react'; -import { Controller, actionTypes } from '@data-client/react'; +import { type Manager, type Middleware, Controller } from '@data-client/react'; import type { Entity } from '@data-client/rest'; export default class StreamManager implements Manager { diff --git a/packages/core/src/actionTypes.ts b/packages/core/src/actionTypes.ts index dfc8e80fe40b..6a67d41f49c9 100644 --- a/packages/core/src/actionTypes.ts +++ b/packages/core/src/actionTypes.ts @@ -1,11 +1,23 @@ -export const FETCH_TYPE = 'rdc/fetch' as const; -export const SET_TYPE = 'rdc/set' as const; -export const SET_RESPONSE_TYPE = 'rdc/setresponse' as const; -export const OPTIMISTIC_TYPE = 'rdc/optimistic' as const; -export const RESET_TYPE = 'rdc/reset' as const; -export const SUBSCRIBE_TYPE = 'rdc/subscribe' as const; -export const UNSUBSCRIBE_TYPE = 'rdc/unsubscribe' as const; -export const INVALIDATE_TYPE = 'rdc/invalidate' as const; -export const INVALIDATEALL_TYPE = 'rdc/invalidateall' as const; -export const EXPIREALL_TYPE = 'rdc/expireall' as const; -export const GC_TYPE = 'rdc/gc' as const; +export const FETCH = 'rdc/fetch' as const; +export const SET = 'rdc/set' as const; +export const SET_RESPONSE = 'rdc/setresponse' as const; +export const OPTIMISTIC = 'rdc/optimistic' as const; +export const RESET = 'rdc/reset' as const; +export const SUBSCRIBE = 'rdc/subscribe' as const; +export const UNSUBSCRIBE = 'rdc/unsubscribe' as const; +export const INVALIDATE = 'rdc/invalidate' as const; +export const INVALIDATEALL = 'rdc/invalidateall' as const; +export const EXPIREALL = 'rdc/expireall' as const; +export const GC = 'rdc/gc' as const; + +export const FETCH_TYPE = FETCH; +export const SET_TYPE = SET; +export const SET_RESPONSE_TYPE = SET_RESPONSE; +export const OPTIMISTIC_TYPE = OPTIMISTIC; +export const RESET_TYPE = RESET; +export const SUBSCRIBE_TYPE = SUBSCRIBE; +export const UNSUBSCRIBE_TYPE = UNSUBSCRIBE; +export const INVALIDATE_TYPE = INVALIDATE; +export const INVALIDATEALL_TYPE = INVALIDATEALL; +export const EXPIREALL_TYPE = EXPIREALL; +export const GC_TYPE = GC; diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index 154e47ec35d5..fc346d328c76 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -7,17 +7,17 @@ import type { } from '@data-client/normalizr'; import type { - SET_TYPE, - RESET_TYPE, - FETCH_TYPE, - SUBSCRIBE_TYPE, - UNSUBSCRIBE_TYPE, - INVALIDATE_TYPE, - GC_TYPE, - OPTIMISTIC_TYPE, - INVALIDATEALL_TYPE, - EXPIREALL_TYPE, - SET_RESPONSE_TYPE, + SET, + RESET, + FETCH, + SUBSCRIBE, + UNSUBSCRIBE, + INVALIDATE, + GC, + OPTIMISTIC, + INVALIDATEALL, + EXPIREALL, + SET_RESPONSE, } from './actionTypes.js'; import type { EndpointUpdateFunction } from './controller/types.js'; @@ -37,7 +37,7 @@ export interface ActionMeta { /** Action for Controller.set() */ export interface SetAction { - type: typeof SET_TYPE; + type: typeof SET; schema: S; args: readonly any[]; meta: ActionMeta; @@ -48,7 +48,7 @@ export interface SetAction { export interface SetResponseActionBase< E extends EndpointAndUpdate = EndpointDefault, > { - type: typeof SET_RESPONSE_TYPE; + type: typeof SET_RESPONSE; endpoint: E; args: readonly any[]; key: string; @@ -81,7 +81,7 @@ export interface FetchMeta { /** Action for Controller.fetch() */ export interface FetchAction = EndpointDefault> { - type: typeof FETCH_TYPE; + type: typeof FETCH; endpoint: E; args: readonly [...Parameters]; key: string; @@ -93,7 +93,7 @@ export interface FetchAction = EndpointDefault> { export interface OptimisticAction< E extends EndpointAndUpdate = EndpointDefault, > { - type: typeof OPTIMISTIC_TYPE; + type: typeof OPTIMISTIC; endpoint: E; args: readonly any[]; key: string; @@ -106,7 +106,7 @@ export interface OptimisticAction< export interface SubscribeAction< E extends EndpointAndUpdate = EndpointDefault, > { - type: typeof SUBSCRIBE_TYPE; + type: typeof SUBSCRIBE; endpoint: E; args: readonly any[]; key: string; @@ -116,7 +116,7 @@ export interface SubscribeAction< export interface UnsubscribeAction< E extends EndpointAndUpdate = EndpointDefault, > { - type: typeof UNSUBSCRIBE_TYPE; + type: typeof UNSUBSCRIBE; endpoint: E; args: readonly any[]; key: string; @@ -124,30 +124,30 @@ export interface UnsubscribeAction< /* EXPIRY */ export interface ExpireAllAction { - type: typeof EXPIREALL_TYPE; + type: typeof EXPIREALL; testKey: (key: string) => boolean; } /* INVALIDATE */ export interface InvalidateAllAction { - type: typeof INVALIDATEALL_TYPE; + type: typeof INVALIDATEALL; testKey: (key: string) => boolean; } export interface InvalidateAction { - type: typeof INVALIDATE_TYPE; + type: typeof INVALIDATE; key: string; } /* RESET */ export interface ResetAction { - type: typeof RESET_TYPE; + type: typeof RESET; date: number; } /* GC */ export interface GCAction { - type: typeof GC_TYPE; + type: typeof GC; entities: [string, string][]; endpoints: string[]; } diff --git a/packages/core/src/controller/actions/createExpireAll.ts b/packages/core/src/controller/actions/createExpireAll.ts index 6f948014344b..5640372a32e5 100644 --- a/packages/core/src/controller/actions/createExpireAll.ts +++ b/packages/core/src/controller/actions/createExpireAll.ts @@ -1,11 +1,11 @@ -import { EXPIREALL_TYPE } from '../../actionTypes.js'; +import { EXPIREALL } from '../../actionTypes.js'; import type { ExpireAllAction } from '../../types.js'; export function createExpireAll( testKey: (key: string) => boolean, ): ExpireAllAction { return { - type: EXPIREALL_TYPE, + type: EXPIREALL, testKey, }; } diff --git a/packages/core/src/controller/actions/createFetch.ts b/packages/core/src/controller/actions/createFetch.ts index 6d10107113c7..8abfe3104604 100644 --- a/packages/core/src/controller/actions/createFetch.ts +++ b/packages/core/src/controller/actions/createFetch.ts @@ -1,6 +1,6 @@ import type { EndpointInterface, NI } from '@data-client/normalizr'; -import { FETCH_TYPE } from '../../actionTypes.js'; +import { FETCH } from '../../actionTypes.js'; import type { FetchAction, FetchMeta } from '../../types.js'; import { EndpointUpdateFunction } from '../types.js'; @@ -26,7 +26,7 @@ export function createFetch< }; return { - type: FETCH_TYPE, + type: FETCH, key: endpoint.key(...args), args, endpoint, diff --git a/packages/core/src/controller/actions/createInvalidate.ts b/packages/core/src/controller/actions/createInvalidate.ts index 635c838fb277..a6b108b5edc9 100644 --- a/packages/core/src/controller/actions/createInvalidate.ts +++ b/packages/core/src/controller/actions/createInvalidate.ts @@ -1,6 +1,6 @@ import type { EndpointInterface } from '@data-client/normalizr'; -import { INVALIDATE_TYPE } from '../../actionTypes.js'; +import { INVALIDATE } from '../../actionTypes.js'; import type { InvalidateAction } from '../../types.js'; export function createInvalidate( @@ -8,7 +8,7 @@ export function createInvalidate( { args }: { args: readonly [...Parameters] }, ): InvalidateAction { return { - type: INVALIDATE_TYPE, + type: INVALIDATE, key: endpoint.key(...args), }; } diff --git a/packages/core/src/controller/actions/createInvalidateAll.ts b/packages/core/src/controller/actions/createInvalidateAll.ts index 018e4b96a18c..06e287111924 100644 --- a/packages/core/src/controller/actions/createInvalidateAll.ts +++ b/packages/core/src/controller/actions/createInvalidateAll.ts @@ -1,11 +1,11 @@ -import { INVALIDATEALL_TYPE } from '../../actionTypes.js'; +import { INVALIDATEALL } from '../../actionTypes.js'; import type { InvalidateAllAction } from '../../types.js'; export function createInvalidateAll( testKey: (key: string) => boolean, ): InvalidateAllAction { return { - type: INVALIDATEALL_TYPE, + type: INVALIDATEALL, testKey, }; } diff --git a/packages/core/src/controller/actions/createOptimistic.ts b/packages/core/src/controller/actions/createOptimistic.ts index b2c116b4ddb5..c798f0d8f9b6 100644 --- a/packages/core/src/controller/actions/createOptimistic.ts +++ b/packages/core/src/controller/actions/createOptimistic.ts @@ -1,7 +1,7 @@ import type { EndpointInterface } from '@data-client/normalizr'; import { createMeta } from './createMeta.js'; -import { OPTIMISTIC_TYPE } from '../../actionTypes.js'; +import { OPTIMISTIC } from '../../actionTypes.js'; import type { OptimisticAction } from '../../types.js'; import type { EndpointUpdateFunction } from '../types.js'; @@ -23,7 +23,7 @@ export function createOptimistic< } return { - type: OPTIMISTIC_TYPE, + type: OPTIMISTIC, key: endpoint.key(...args), args, endpoint, diff --git a/packages/core/src/controller/actions/createReset.ts b/packages/core/src/controller/actions/createReset.ts index 9050f20fff30..cc19f52ea1ab 100644 --- a/packages/core/src/controller/actions/createReset.ts +++ b/packages/core/src/controller/actions/createReset.ts @@ -1,9 +1,9 @@ -import { RESET_TYPE } from '../../actionTypes.js'; +import { RESET } from '../../actionTypes.js'; import type { ResetAction } from '../../types.js'; export function createReset(): ResetAction { return { - type: RESET_TYPE, + type: RESET, date: Date.now(), }; } diff --git a/packages/core/src/controller/actions/createSet.ts b/packages/core/src/controller/actions/createSet.ts index a45c1752e72b..1123028835ea 100644 --- a/packages/core/src/controller/actions/createSet.ts +++ b/packages/core/src/controller/actions/createSet.ts @@ -5,7 +5,7 @@ import type { } from '@data-client/normalizr'; import { createMeta } from './createMeta.js'; -import { SET_TYPE } from '../../actionTypes.js'; +import { SET } from '../../actionTypes.js'; import type { SetAction } from '../../types.js'; import ensurePojo from '../ensurePojo.js'; @@ -22,7 +22,7 @@ export function createSet( }, ): SetAction { return { - type: SET_TYPE, + type: SET, value, args: args.map(ensurePojo) as SchemaArgs, schema, diff --git a/packages/core/src/controller/actions/createSetResponse.ts b/packages/core/src/controller/actions/createSetResponse.ts index ea187f072192..11473a5df41c 100644 --- a/packages/core/src/controller/actions/createSetResponse.ts +++ b/packages/core/src/controller/actions/createSetResponse.ts @@ -1,7 +1,7 @@ import type { EndpointInterface, ResolveType } from '@data-client/normalizr'; import { createMeta } from './createMeta.js'; -import { SET_RESPONSE_TYPE } from '../../actionTypes.js'; +import { SET_RESPONSE } from '../../actionTypes.js'; import type { SetResponseAction } from '../../types.js'; import ensurePojo from '../ensurePojo.js'; import { EndpointUpdateFunction } from '../types.js'; @@ -62,7 +62,7 @@ export function createSetResponse< } return { - type: SET_RESPONSE_TYPE, + type: SET_RESPONSE, key: endpoint.key(...args), response, args: args.map(ensurePojo), diff --git a/packages/core/src/controller/actions/createSubscription.ts b/packages/core/src/controller/actions/createSubscription.ts index 5a4cdfad0151..5c93cf5e8238 100644 --- a/packages/core/src/controller/actions/createSubscription.ts +++ b/packages/core/src/controller/actions/createSubscription.ts @@ -1,6 +1,6 @@ import type { EndpointInterface } from '@data-client/normalizr'; -import { SUBSCRIBE_TYPE, UNSUBSCRIBE_TYPE } from '../../actionTypes.js'; +import { SUBSCRIBE, UNSUBSCRIBE } from '../../actionTypes.js'; import type { SubscribeAction, UnsubscribeAction } from '../../types.js'; export function createSubscription( @@ -8,7 +8,7 @@ export function createSubscription( { args }: { args: readonly [...Parameters] }, ): SubscribeAction { return { - type: SUBSCRIBE_TYPE, + type: SUBSCRIBE, endpoint, args, key: endpoint.key(...args), @@ -20,7 +20,7 @@ export function createUnsubscription( { args }: { args: readonly [...Parameters] }, ): UnsubscribeAction { return { - type: UNSUBSCRIBE_TYPE, + type: UNSUBSCRIBE, key: endpoint.key(...args), args, endpoint, diff --git a/packages/core/src/manager/LogoutManager.ts b/packages/core/src/manager/LogoutManager.ts index 5d4e5b461abd..45e05eeb3317 100644 --- a/packages/core/src/manager/LogoutManager.ts +++ b/packages/core/src/manager/LogoutManager.ts @@ -1,4 +1,4 @@ -import { SET_RESPONSE_TYPE } from '../actionTypes.js'; +import { SET_RESPONSE } from '../actionTypes.js'; import type Controller from '../controller/Controller.js'; import { UnknownError } from '../index.js'; import type { Manager, Middleware } from '../types.js'; @@ -16,7 +16,7 @@ export default class LogoutManager implements Manager { middleware: Middleware = controller => next => async action => { await next(action); if ( - action.type === SET_RESPONSE_TYPE && + action.type === SET_RESPONSE && action.error && this.shouldLogout(action.response) ) { diff --git a/packages/core/src/manager/NetworkManager.ts b/packages/core/src/manager/NetworkManager.ts index 7d13706ebd15..d260bf5328f1 100644 --- a/packages/core/src/manager/NetworkManager.ts +++ b/packages/core/src/manager/NetworkManager.ts @@ -1,4 +1,4 @@ -import { SET_RESPONSE_TYPE, FETCH_TYPE, RESET_TYPE } from '../actionTypes.js'; +import { SET_RESPONSE, FETCH, RESET } from '../actionTypes.js'; import { createSetResponse } from '../controller/actions/index.js'; import Controller from '../controller/Controller.js'; import type { @@ -46,7 +46,7 @@ export default class NetworkManager implements Manager { this.controller = controller; return next => action => { switch (action.type) { - case FETCH_TYPE: + case FETCH: this.handleFetch(action); // This is the only case that causes any state change // It's important to intercept other fetches as we don't want to trigger reducers during @@ -58,7 +58,7 @@ export default class NetworkManager implements Manager { return next(action); } return Promise.resolve(); - case SET_RESPONSE_TYPE: + case SET_RESPONSE: // only set after new state is computed return next(action).then(() => { if (action.key in this.fetched) { @@ -79,7 +79,7 @@ export default class NetworkManager implements Manager { } } }); - case RESET_TYPE: { + case RESET: { const rejectors = { ...this.rejectors }; this.clearAll(); @@ -112,7 +112,7 @@ export default class NetworkManager implements Manager { /** Used by DevtoolsManager to determine whether to log an action */ skipLogging(action: ActionTypes) { /* istanbul ignore next */ - return action.type === FETCH_TYPE && action.key in this.fetched; + return action.type === FETCH && action.key in this.fetched; } allSettled() { diff --git a/packages/core/src/manager/SubscriptionManager.ts b/packages/core/src/manager/SubscriptionManager.ts index 156c7ff8a4ad..574b7e130431 100644 --- a/packages/core/src/manager/SubscriptionManager.ts +++ b/packages/core/src/manager/SubscriptionManager.ts @@ -1,4 +1,4 @@ -import { SUBSCRIBE_TYPE, UNSUBSCRIBE_TYPE } from '../actionTypes.js'; +import { SUBSCRIBE, UNSUBSCRIBE } from '../actionTypes.js'; import Controller from '../controller/Controller.js'; import type { Manager, @@ -51,14 +51,14 @@ export default class SubscriptionManager< this.controller = controller; return next => action => { switch (action.type) { - case SUBSCRIBE_TYPE: + case SUBSCRIBE: try { this.handleSubscribe(action); } catch (e) { console.error(e); } return Promise.resolve(); - case UNSUBSCRIBE_TYPE: + case UNSUBSCRIBE: this.handleUnsubscribe(action); return Promise.resolve(); default: diff --git a/packages/core/src/manager/__tests__/logoutManager.ts b/packages/core/src/manager/__tests__/logoutManager.ts index afee96909061..4363dc6e259b 100644 --- a/packages/core/src/manager/__tests__/logoutManager.ts +++ b/packages/core/src/manager/__tests__/logoutManager.ts @@ -1,7 +1,7 @@ import { CoolerArticleResource } from '__tests__/new'; import { Controller, initialState } from '../..'; -import { FETCH_TYPE, RESET_TYPE } from '../../actionTypes'; +import { FETCH, RESET } from '../../actionTypes'; import { createSetResponse } from '../../controller/actions'; import LogoutManager from '../LogoutManager.js'; @@ -73,7 +73,7 @@ describe('LogoutManager', () => { await manager.middleware(API)(next)(action); expect(dispatch.mock.calls.length).toBe(1); - expect(dispatch.mock.calls[0][0]?.type).toBe(RESET_TYPE); + expect(dispatch.mock.calls[0][0]?.type).toBe(RESET); }); it('should call custom handleLogout', async () => { @@ -97,7 +97,7 @@ describe('LogoutManager', () => { }); it('should let other actions pass through', async () => { - const action = { type: FETCH_TYPE }; + const action = { type: FETCH }; next.mockReset(); await manager.middleware(API)(next)(action as any); diff --git a/packages/core/src/manager/__tests__/networkManager.ts b/packages/core/src/manager/__tests__/networkManager.ts index bd6de8227ccc..6e6ace650666 100644 --- a/packages/core/src/manager/__tests__/networkManager.ts +++ b/packages/core/src/manager/__tests__/networkManager.ts @@ -1,7 +1,7 @@ import { Endpoint } from '@data-client/endpoint'; import { Article, ArticleResource } from '__tests__/new'; -import { SET_RESPONSE_TYPE } from '../../actionTypes'; +import { SET_RESPONSE } from '../../actionTypes'; import { createFetch } from '../../controller/actions'; import Controller from '../../controller/Controller'; import NetworkManager from '../../manager/NetworkManager'; @@ -159,7 +159,7 @@ describe('NetworkManager', () => { await new Promise(resolve => setTimeout(resolve, 0)); const action: SetResponseAction = { - type: SET_RESPONSE_TYPE, + type: SET_RESPONSE, endpoint: fetchResolveAction.endpoint, response, args: fetchResolveAction.args, @@ -195,7 +195,7 @@ describe('NetworkManager', () => { await new Promise(resolve => setTimeout(resolve, 0)); const action: SetResponseAction = { - type: SET_RESPONSE_TYPE, + type: SET_RESPONSE, endpoint: fetchSetWithUpdatersAction.endpoint, response, args: fetchSetWithUpdatersAction.args, @@ -231,7 +231,7 @@ describe('NetworkManager', () => { await new Promise(resolve => setTimeout(resolve, 0)); const action: SetResponseAction = { - type: SET_RESPONSE_TYPE, + type: SET_RESPONSE, endpoint: fetchRpcWithUpdatersAction.endpoint, response, args: fetchRpcWithUpdatersAction.args, @@ -267,7 +267,7 @@ describe('NetworkManager', () => { // mutations resolve before dispatch, so we must wait for next tick to see set await new Promise(resolve => setTimeout(resolve, 0)); expect(dispatch).toHaveBeenCalledWith({ - type: SET_RESPONSE_TYPE, + type: SET_RESPONSE, endpoint: fetchRpcWithUpdatersAndOptimisticAction.endpoint, response, args: fetchRpcWithUpdatersAndOptimisticAction.args, @@ -338,7 +338,7 @@ describe('NetworkManager', () => { } catch (error) { expect(next).not.toHaveBeenCalled(); expect(dispatch).toHaveBeenCalledWith({ - type: SET_RESPONSE_TYPE, + type: SET_RESPONSE, response: error, key: fetchRejectAction.key, meta: { diff --git a/packages/core/src/manager/__tests__/subscriptionManager.ts b/packages/core/src/manager/__tests__/subscriptionManager.ts index fc1b132d3576..1aa0afa253fd 100644 --- a/packages/core/src/manager/__tests__/subscriptionManager.ts +++ b/packages/core/src/manager/__tests__/subscriptionManager.ts @@ -4,7 +4,7 @@ import { actionTypes, Controller, initialState } from '../..'; import { SubscribeAction, UnsubscribeAction } from '../../types'; import SubscriptionManager, { Subscription } from '../SubscriptionManager.js'; -const { UNSUBSCRIBE_TYPE, SUBSCRIBE_TYPE, SET_RESPONSE_TYPE } = actionTypes; +const { UNSUBSCRIBE, SUBSCRIBE, SET_RESPONSE } = actionTypes; function onError(e: any) { e.preventDefault(); @@ -55,7 +55,7 @@ describe('SubscriptionManager', () => { () => Promise.reject(new Error('Failed')) : () => Promise.resolve(response); return { - type: SUBSCRIBE_TYPE, + type: SUBSCRIBE, endpoint: PollingArticleResource.get.extend({ fetch }), args: [{ id: response.id }], key: PollingArticleResource.get.key({ id: response.id }), @@ -65,7 +65,7 @@ describe('SubscriptionManager', () => { response: Record, ): UnsubscribeAction { return { - type: UNSUBSCRIBE_TYPE, + type: UNSUBSCRIBE, endpoint: PollingArticleResource.get, key: PollingArticleResource.get.key({ id: response.id }), args: [{ id: response.id }], @@ -185,7 +185,7 @@ describe('SubscriptionManager', () => { }); it('should let other actions pass through', () => { - const action = { type: SET_RESPONSE_TYPE }; + const action = { type: SET_RESPONSE }; next.mockReset(); manager.middleware(API)(next)(action as any); diff --git a/packages/core/src/state/__tests__/reducer.ts b/packages/core/src/state/__tests__/reducer.ts index 688a4cc63229..c3a7ff523d06 100644 --- a/packages/core/src/state/__tests__/reducer.ts +++ b/packages/core/src/state/__tests__/reducer.ts @@ -3,12 +3,12 @@ import { ArticleResource, Article, PaginatedArticle } from '__tests__/new'; import { Controller } from '../..'; import { - INVALIDATE_TYPE, - FETCH_TYPE, - RESET_TYPE, - GC_TYPE, - SET_RESPONSE_TYPE, - SET_TYPE, + INVALIDATE, + FETCH, + RESET, + GC, + SET_RESPONSE, + SET, } from '../../actionTypes'; import { State, @@ -36,7 +36,7 @@ describe('reducer', () => { const id = 20; const response = { id, title: 'hi', content: 'this is the content' }; const action: SetResponseAction = { - type: SET_RESPONSE_TYPE, + type: SET_RESPONSE, response, endpoint: ArticleResource.get, args: [{ id }], @@ -215,7 +215,7 @@ describe('reducer', () => { static key = 'Counter'; } const action: SetAction = { - type: SET_TYPE, + type: SET, value, schema: Counter, args: [{ id }], @@ -242,7 +242,7 @@ describe('reducer', () => { static key = 'Counter'; } const action: SetAction = { - type: SET_TYPE, + type: SET, value, schema: Counter, args: [{ id }], @@ -270,7 +270,7 @@ describe('reducer', () => { const id = 20; const value = { id, title: 'hi', content: 'this is the content' }; const action: SetAction = { - type: SET_TYPE, + type: SET, value, schema: Article, args: [{ id }], @@ -292,7 +292,7 @@ describe('reducer', () => { const id = 20; const value = { id, title: 'hi', content: 'this is the content' }; const action: SetAction = { - type: SET_TYPE, + type: SET, value, schema: Article, args: [{ id }], @@ -314,7 +314,7 @@ describe('reducer', () => { const id = 20; const response = { id, title: 'hi', content: 'this is the content' }; const action: SetResponseAction = { - type: SET_RESPONSE_TYPE, + type: SET_RESPONSE, response, endpoint: ArticleResource.get, args: [{ id }], @@ -335,7 +335,7 @@ describe('reducer', () => { it('purge should delete entities', () => { const id = 20; const action: SetResponseAction = { - type: SET_RESPONSE_TYPE, + type: SET_RESPONSE, response: { id }, endpoint: ArticleResource.delete, args: [{ id }], @@ -485,7 +485,7 @@ describe('reducer', () => { it('invalidates resources correctly', () => { const id = 20; const action: InvalidateAction = { - type: INVALIDATE_TYPE, + type: INVALIDATE, key: id.toString(), }; const iniState: any = { @@ -522,7 +522,7 @@ describe('reducer', () => { const id = 20; const error = new Error('hi'); const action: SetResponseAction = { - type: SET_RESPONSE_TYPE, + type: SET_RESPONSE, response: error, endpoint: ArticleResource.get, args: [{ id }], @@ -542,7 +542,7 @@ describe('reducer', () => { const id = 20; const error = new Error('hi'); const action: SetResponseAction = { - type: SET_RESPONSE_TYPE, + type: SET_RESPONSE, response: error, endpoint: ArticleResource.get, args: [{ id }], @@ -563,7 +563,7 @@ describe('reducer', () => { const id = 20; const error = new Error('hi'); const action: SetResponseAction = { - type: SET_RESPONSE_TYPE, + type: SET_RESPONSE, response: error, endpoint: ArticleResource.delete, args: [{ id }], @@ -595,7 +595,7 @@ describe('reducer', () => { .mockImplementation(() => {}); try { const action: FetchAction = { - type: FETCH_TYPE, + type: FETCH, endpoint: ArticleResource.get, args: [{ id: 5 }], key: ArticleResource.get.url({ id: 5 }), @@ -640,7 +640,7 @@ describe('reducer', () => { it('reset should delete all entries', () => { const action: ResetAction = { - type: RESET_TYPE, + type: RESET, date: Date.now(), }; const iniState: any = { @@ -697,7 +697,7 @@ describe('reducer', () => { it('empty targets should do nothing', () => { const action: GCAction = { - type: GC_TYPE, + type: GC, entities: [], endpoints: [], }; @@ -710,7 +710,7 @@ describe('reducer', () => { it('empty deleting entities should work', () => { const action: GCAction = { - type: GC_TYPE, + type: GC, entities: [ [Article.key, '10'], [Article.key, '250'], @@ -729,7 +729,7 @@ describe('reducer', () => { it('empty deleting nonexistant things should passthrough', () => { const action: GCAction = { - type: GC_TYPE, + type: GC, entities: [ [Article.key, '100000000'], ['sillythings', '10'], diff --git a/packages/core/src/state/reducer/createReducer.ts b/packages/core/src/state/reducer/createReducer.ts index e2eacf0d049d..56a6f418a16a 100644 --- a/packages/core/src/state/reducer/createReducer.ts +++ b/packages/core/src/state/reducer/createReducer.ts @@ -4,15 +4,15 @@ import { invalidateReducer } from './invalidateReducer.js'; import { setReducer } from './setReducer.js'; import { setResponseReducer } from './setResponseReducer.js'; import { - SET_TYPE, - INVALIDATE_TYPE, - RESET_TYPE, - FETCH_TYPE, - GC_TYPE, - OPTIMISTIC_TYPE, - INVALIDATEALL_TYPE, - EXPIREALL_TYPE, - SET_RESPONSE_TYPE, + SET, + INVALIDATE, + RESET, + FETCH, + GC, + OPTIMISTIC, + INVALIDATEALL, + EXPIREALL, + SET_RESPONSE, } from '../../actionTypes.js'; import type Controller from '../../controller/Controller.js'; import type { ActionTypes, State } from '../../types.js'; @@ -24,7 +24,7 @@ export default function createReducer(controller: Controller): ReducerType { ): State { if (!state) state = initialState; switch (action.type) { - case GC_TYPE: + case GC: // inline deletes are fine as these should have 0 refcounts action.entities.forEach(([key, pk]) => { delete (state as any).entities[key]?.[pk]; @@ -35,25 +35,25 @@ export default function createReducer(controller: Controller): ReducerType { delete (state as any).meta[fetchKey]; }); return state; - case FETCH_TYPE: + case FETCH: return fetchReducer(state, action); - case OPTIMISTIC_TYPE: + case OPTIMISTIC: // eslint-disable-next-line no-fallthrough - case SET_RESPONSE_TYPE: + case SET_RESPONSE: return setResponseReducer(state, action, controller); - case SET_TYPE: + case SET: return setReducer(state, action, controller); - case INVALIDATEALL_TYPE: - case INVALIDATE_TYPE: + case INVALIDATEALL: + case INVALIDATE: return invalidateReducer(state, action); - case EXPIREALL_TYPE: + case EXPIREALL: return expireReducer(state, action); - case RESET_TYPE: + case RESET: return { ...initialState, lastReset: action.date }; default: diff --git a/packages/core/src/state/reducer/invalidateReducer.ts b/packages/core/src/state/reducer/invalidateReducer.ts index a4d333327412..9e8ad8ff2d0d 100644 --- a/packages/core/src/state/reducer/invalidateReducer.ts +++ b/packages/core/src/state/reducer/invalidateReducer.ts @@ -1,4 +1,4 @@ -import { INVALIDATE_TYPE } from '../../actionTypes.js'; +import { INVALIDATE } from '../../actionTypes.js'; import type { State, InvalidateAllAction, @@ -21,7 +21,7 @@ export function invalidateReducer( delete itemMeta.error; meta[key] = itemMeta; }; - if (action.type === INVALIDATE_TYPE) { + if (action.type === INVALIDATE) { invalidateKey(action.key); } else { Object.keys(endpoints).forEach(key => { diff --git a/packages/core/src/state/reducer/setResponseReducer.ts b/packages/core/src/state/reducer/setResponseReducer.ts index ff10da19c7b9..fdcad67a57e9 100644 --- a/packages/core/src/state/reducer/setResponseReducer.ts +++ b/packages/core/src/state/reducer/setResponseReducer.ts @@ -1,6 +1,6 @@ import { normalize } from '@data-client/normalizr'; -import { OPTIMISTIC_TYPE } from '../../actionTypes.js'; +import { OPTIMISTIC } from '../../actionTypes.js'; import AbortOptimistic from '../../controller/AbortOptimistic.js'; import type Controller from '../../controller/Controller.js'; import type { @@ -20,7 +20,7 @@ export function setResponseReducer( try { let response: any; // for true set's response is contained in action - if (action.type === OPTIMISTIC_TYPE) { + if (action.type === OPTIMISTIC) { // this should never happen /* istanbul ignore if */ if (!action.endpoint.getOptimisticResponse) return state; @@ -142,7 +142,7 @@ function filterOptimistic( return state.optimistic.filter( optimisticAction => optimisticAction.key !== resolvingAction.key || - (optimisticAction.type === OPTIMISTIC_TYPE ? + (optimisticAction.type === OPTIMISTIC ? optimisticAction.meta.fetchedAt !== resolvingAction.meta.fetchedAt : optimisticAction.meta.date > resolvingAction.meta.date), ); diff --git a/packages/react/src/__tests__/hooks-endpoint.web.tsx b/packages/react/src/__tests__/hooks-endpoint.web.tsx index 656e565c562e..d3494e739792 100644 --- a/packages/react/src/__tests__/hooks-endpoint.web.tsx +++ b/packages/react/src/__tests__/hooks-endpoint.web.tsx @@ -17,7 +17,7 @@ import { ControllerContext, StateContext } from '../context'; import { useController, useSuspense } from '../hooks'; import { articlesPages, createPayload, payload } from '../test-fixtures'; -const { INVALIDATE_TYPE, RESET_TYPE } = actionTypes; +const { INVALIDATE, RESET } = actionTypes; async function testDispatchFetch( Component: React.FunctionComponent, @@ -243,7 +243,7 @@ describe('useController().invalidate', () => { ); invalidate(PaginatedArticleResource.getList); expect(dispatch).toHaveBeenCalledWith({ - type: INVALIDATE_TYPE, + type: INVALIDATE, key: PaginatedArticleResource.getList.key(), }); }); @@ -286,7 +286,7 @@ describe('useController().reset', () => { ); await act(reset); expect(dispatch).toHaveBeenCalledWith({ - type: RESET_TYPE, + type: RESET, date: Date.now(), }); }); diff --git a/packages/react/src/components/__tests__/provider.native.tsx b/packages/react/src/components/__tests__/provider.native.tsx index c959adbacc9c..2f9d80ad736c 100644 --- a/packages/react/src/components/__tests__/provider.native.tsx +++ b/packages/react/src/components/__tests__/provider.native.tsx @@ -16,7 +16,7 @@ import { useController, useSuspense } from '../../hooks'; import { payload } from '../../test-fixtures'; import DataProvider from '../DataProvider'; -const { SET_RESPONSE_TYPE } = actionTypes; +const { SET_RESPONSE } = actionTypes; describe('', () => { let warnspy: jest.SpyInstance; @@ -138,7 +138,7 @@ describe('', () => { expect(dispatch).toBeDefined(); expect(state).toBeDefined(); const action: SetResponseAction = { - type: SET_RESPONSE_TYPE, + type: SET_RESPONSE, response: { id: 5, title: 'hi', content: 'more things here' }, endpoint: CoolerArticleResource.get, args: [{ id: 5 }], diff --git a/packages/react/src/components/__tests__/provider.tsx b/packages/react/src/components/__tests__/provider.tsx index 52f0bb1be27d..1a86483e0872 100644 --- a/packages/react/src/components/__tests__/provider.tsx +++ b/packages/react/src/components/__tests__/provider.tsx @@ -18,7 +18,7 @@ import { payload } from '../../test-fixtures'; import DataProvider from '../DataProvider'; import { getDefaultManagers } from '../getDefaultManagers'; -const { SET_RESPONSE_TYPE } = actionTypes; +const { SET_RESPONSE } = actionTypes; describe('', () => { let warnspy: jest.SpyInstance; @@ -138,7 +138,7 @@ describe('', () => { expect(dispatch).toBeDefined(); expect(state).toBeDefined(); const action: SetResponseAction = { - type: SET_RESPONSE_TYPE, + type: SET_RESPONSE, response: { id: 5, title: 'hi', content: 'more things here' }, endpoint: CoolerArticleResource.get, args: [{ id: 5 }], diff --git a/packages/react/src/hooks/__tests__/subscriptions.native.tsx b/packages/react/src/hooks/__tests__/subscriptions.native.tsx index d198da3d3857..d0415e396d96 100644 --- a/packages/react/src/hooks/__tests__/subscriptions.native.tsx +++ b/packages/react/src/hooks/__tests__/subscriptions.native.tsx @@ -229,10 +229,8 @@ describe.each([ rerender({ id: null }); } expect(fakeDispatch.mock.calls.length).toBe(2); - expect(fakeDispatch.mock.calls[0][0].type).toBe(actionTypes.SUBSCRIBE_TYPE); - expect(fakeDispatch.mock.calls[1][0].type).toBe( - actionTypes.UNSUBSCRIBE_TYPE, - ); + expect(fakeDispatch.mock.calls[0][0].type).toBe(actionTypes.SUBSCRIBE); + expect(fakeDispatch.mock.calls[1][0].type).toBe(actionTypes.UNSUBSCRIBE); expect(fakeDispatch.mock.calls[1][0].key).toBe( fakeDispatch.mock.calls[0][0].key, ); diff --git a/packages/react/src/hooks/__tests__/subscriptions.tsx b/packages/react/src/hooks/__tests__/subscriptions.tsx index 7e6dece59291..3c6cf6fea2bf 100644 --- a/packages/react/src/hooks/__tests__/subscriptions.tsx +++ b/packages/react/src/hooks/__tests__/subscriptions.tsx @@ -233,10 +233,8 @@ describe.each([ rerender({ id: null }); } expect(fakeDispatch.mock.calls.length).toBe(2); - expect(fakeDispatch.mock.calls[0][0].type).toBe(actionTypes.SUBSCRIBE_TYPE); - expect(fakeDispatch.mock.calls[1][0].type).toBe( - actionTypes.UNSUBSCRIBE_TYPE, - ); + expect(fakeDispatch.mock.calls[0][0].type).toBe(actionTypes.SUBSCRIBE); + expect(fakeDispatch.mock.calls[1][0].type).toBe(actionTypes.UNSUBSCRIBE); expect(fakeDispatch.mock.calls[1][0].key).toBe( fakeDispatch.mock.calls[0][0].key, ); diff --git a/packages/react/src/hooks/__tests__/useSuspense.native.tsx b/packages/react/src/hooks/__tests__/useSuspense.native.tsx index 506017c374ad..7e275f0c8489 100644 --- a/packages/react/src/hooks/__tests__/useSuspense.native.tsx +++ b/packages/react/src/hooks/__tests__/useSuspense.native.tsx @@ -64,7 +64,7 @@ async function testDispatchFetch( expect(dispatch.mock.calls.length).toBe(payloads.length); let i = 0; for (const call of dispatch.mock.calls as any) { - expect(call[0].type).toBe(actionTypes.FETCH_TYPE); + expect(call[0].type).toBe(actionTypes.FETCH); delete call[0]?.meta?.fetchedAt; delete call[0]?.meta?.promise; expect(call[0]).toMatchSnapshot(); diff --git a/packages/react/src/hooks/__tests__/useSuspense.web.tsx b/packages/react/src/hooks/__tests__/useSuspense.web.tsx index 4d371bf5fd46..fb07b53ba722 100644 --- a/packages/react/src/hooks/__tests__/useSuspense.web.tsx +++ b/packages/react/src/hooks/__tests__/useSuspense.web.tsx @@ -67,7 +67,7 @@ async function testDispatchFetch( expect(dispatch.mock.calls.length).toBe(payloads.length); let i = 0; for (const call of dispatch.mock.calls as any) { - expect(call[0].type).toBe(actionTypes.FETCH_TYPE); + expect(call[0].type).toBe(actionTypes.FETCH); delete call[0]?.meta?.fetchedAt; delete call[0]?.meta?.promise; expect(call[0]).toMatchSnapshot(); diff --git a/packages/test/src/createControllerInterceptor.tsx b/packages/test/src/createControllerInterceptor.tsx index 40f33195bf8b..e32cb7ce75ab 100644 --- a/packages/test/src/createControllerInterceptor.tsx +++ b/packages/test/src/createControllerInterceptor.tsx @@ -12,7 +12,8 @@ export function createControllerInterceptor( ) { const interceptorData = getInitialInterceptorData(); const dispatchInterceptor = function (action: ActionTypes) { - if (action.type === actionTypes.FETCH_TYPE) { + // support legacy that has _TYPE suffix + if (action.type === (actionTypes.FETCH ?? actionTypes.FETCH_TYPE)) { // eslint-disable-next-line prefer-const let { key, args } = action; let fixture: Fixture | Interceptor | undefined; @@ -123,7 +124,10 @@ export function createControllerInterceptor( }`, ); } - } else if (action.type === actionTypes.SUBSCRIBE_TYPE) { + } else if ( + // support legacy that has _TYPE suffix + action.type === (actionTypes.SUBSCRIBE ?? actionTypes.SUBSCRIBE_TYPE) + ) { const { key } = action; if (Object.hasOwn(fixtureMap, key)) { return Promise.resolve(); diff --git a/website/src/components/Playground/editor-types/@data-client/core.d.ts b/website/src/components/Playground/editor-types/@data-client/core.d.ts index ef076d2d7d84..932a19791d37 100644 --- a/website/src/components/Playground/editor-types/@data-client/core.d.ts +++ b/website/src/components/Playground/editor-types/@data-client/core.d.ts @@ -248,6 +248,17 @@ type EndpointUpdateFunction Updaters[K]; }; +declare const FETCH: "rdc/fetch"; +declare const SET: "rdc/set"; +declare const SET_RESPONSE: "rdc/setresponse"; +declare const OPTIMISTIC: "rdc/optimistic"; +declare const RESET: "rdc/reset"; +declare const SUBSCRIBE: "rdc/subscribe"; +declare const UNSUBSCRIBE: "rdc/unsubscribe"; +declare const INVALIDATE: "rdc/invalidate"; +declare const INVALIDATEALL: "rdc/invalidateall"; +declare const EXPIREALL: "rdc/expireall"; +declare const GC: "rdc/gc"; declare const FETCH_TYPE: "rdc/fetch"; declare const SET_TYPE: "rdc/set"; declare const SET_RESPONSE_TYPE: "rdc/setresponse"; @@ -260,6 +271,17 @@ declare const INVALIDATEALL_TYPE: "rdc/invalidateall"; declare const EXPIREALL_TYPE: "rdc/expireall"; declare const GC_TYPE: "rdc/gc"; +declare const actionTypes_d_FETCH: typeof FETCH; +declare const actionTypes_d_SET: typeof SET; +declare const actionTypes_d_SET_RESPONSE: typeof SET_RESPONSE; +declare const actionTypes_d_OPTIMISTIC: typeof OPTIMISTIC; +declare const actionTypes_d_RESET: typeof RESET; +declare const actionTypes_d_SUBSCRIBE: typeof SUBSCRIBE; +declare const actionTypes_d_UNSUBSCRIBE: typeof UNSUBSCRIBE; +declare const actionTypes_d_INVALIDATE: typeof INVALIDATE; +declare const actionTypes_d_INVALIDATEALL: typeof INVALIDATEALL; +declare const actionTypes_d_EXPIREALL: typeof EXPIREALL; +declare const actionTypes_d_GC: typeof GC; declare const actionTypes_d_FETCH_TYPE: typeof FETCH_TYPE; declare const actionTypes_d_SET_TYPE: typeof SET_TYPE; declare const actionTypes_d_SET_RESPONSE_TYPE: typeof SET_RESPONSE_TYPE; @@ -273,6 +295,17 @@ declare const actionTypes_d_EXPIREALL_TYPE: typeof EXPIREALL_TYPE; declare const actionTypes_d_GC_TYPE: typeof GC_TYPE; declare namespace actionTypes_d { export { + actionTypes_d_FETCH as FETCH, + actionTypes_d_SET as SET, + actionTypes_d_SET_RESPONSE as SET_RESPONSE, + actionTypes_d_OPTIMISTIC as OPTIMISTIC, + actionTypes_d_RESET as RESET, + actionTypes_d_SUBSCRIBE as SUBSCRIBE, + actionTypes_d_UNSUBSCRIBE as UNSUBSCRIBE, + actionTypes_d_INVALIDATE as INVALIDATE, + actionTypes_d_INVALIDATEALL as INVALIDATEALL, + actionTypes_d_EXPIREALL as EXPIREALL, + actionTypes_d_GC as GC, actionTypes_d_FETCH_TYPE as FETCH_TYPE, actionTypes_d_SET_TYPE as SET_TYPE, actionTypes_d_SET_RESPONSE_TYPE as SET_RESPONSE_TYPE, @@ -301,14 +334,14 @@ interface ActionMeta { } /** Action for Controller.set() */ interface SetAction { - type: typeof SET_TYPE; + type: typeof SET; schema: S; args: readonly any[]; meta: ActionMeta; value: {} | ((previousValue: Denormalize) => {}); } interface SetResponseActionBase = EndpointDefault> { - type: typeof SET_RESPONSE_TYPE; + type: typeof SET_RESPONSE; endpoint: E; args: readonly any[]; key: string; @@ -332,7 +365,7 @@ interface FetchMeta { } /** Action for Controller.fetch() */ interface FetchAction = EndpointDefault> { - type: typeof FETCH_TYPE; + type: typeof FETCH; endpoint: E; args: readonly [...Parameters]; key: string; @@ -340,7 +373,7 @@ interface FetchAction = EndpointDefault> { } /** Action for Endpoint.getOptimisticResponse() */ interface OptimisticAction = EndpointDefault> { - type: typeof OPTIMISTIC_TYPE; + type: typeof OPTIMISTIC; endpoint: E; args: readonly any[]; key: string; @@ -349,36 +382,36 @@ interface OptimisticAction = EndpointDefault> { } /** Action for Controller.subscribe() */ interface SubscribeAction = EndpointDefault> { - type: typeof SUBSCRIBE_TYPE; + type: typeof SUBSCRIBE; endpoint: E; args: readonly any[]; key: string; } /** Action for Controller.unsubscribe() */ interface UnsubscribeAction = EndpointDefault> { - type: typeof UNSUBSCRIBE_TYPE; + type: typeof UNSUBSCRIBE; endpoint: E; args: readonly any[]; key: string; } interface ExpireAllAction { - type: typeof EXPIREALL_TYPE; + type: typeof EXPIREALL; testKey: (key: string) => boolean; } interface InvalidateAllAction { - type: typeof INVALIDATEALL_TYPE; + type: typeof INVALIDATEALL; testKey: (key: string) => boolean; } interface InvalidateAction { - type: typeof INVALIDATE_TYPE; + type: typeof INVALIDATE; key: string; } interface ResetAction { - type: typeof RESET_TYPE; + type: typeof RESET; date: number; } interface GCAction { - type: typeof GC_TYPE; + type: typeof GC; entities: [string, string][]; endpoints: string[]; }