@angular-architects/ngrx-toolkit 20.0.3 → 20.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _ngrx_signals from '@ngrx/signals';
2
2
  import { StateSource, patchState as patchState$1, WritableStateSource, PartialStateUpdater, SignalStoreFeature, EmptyFeatureResult, SignalStoreFeatureResult, StateSignals } from '@ngrx/signals';
3
- import { ValueProvider, Signal, ProviderToken, WritableSignal } from '@angular/core';
3
+ import { ValueProvider, Signal, ProviderToken, WritableSignal, ResourceStatus, Resource, ResourceRef } from '@angular/core';
4
4
  import { Observable } from 'rxjs';
5
5
  import { EntityId, NamedEntityState } from '@ngrx/signals/entities';
6
6
 
@@ -941,5 +941,144 @@ type StoreForFactory<Input extends SignalStoreFeatureResult> = StateSignals<Inpu
941
941
  */
942
942
  declare function withFeatureFactory<Input extends SignalStoreFeatureResult, Output extends SignalStoreFeatureResult>(factoryFn: (store: StoreForFactory<Input>) => SignalStoreFeature<Input, Output>): SignalStoreFeature<Input, Output>;
943
943
 
944
- export { capitalize, createEffects, createPageArray, createReducer, deriveCallStateKeys, emptyFeature, firstPage, getCallStateKeys, getCollectionArray, getDataServiceKeys, getUndoRedoKeys, gotoPage, nextPage, noPayload, patchState, payload, previousPage, provideDevtoolsConfig, renameDevtoolsName, setError, setLoaded, setLoading, setMaxPageNavigationArrayItems, setPageSize, setResetState, updateState, withCallState, withConditional, withDataService, withDevToolsStub, withDevtools, withDisabledNameIndices, withFeatureFactory, withGlitchTracking, withImmutableState, withIndexedDB, withIndexedDB as withIndexeddb, withLocalStorage, withMapper, withPagination, withRedux, withReset, withSessionStorage, withStorageSync, withUndoRedo };
944
+ type ResourceResult<T> = {
945
+ state: {
946
+ value: T;
947
+ };
948
+ props: {
949
+ status: Signal<ResourceStatus>;
950
+ error: Signal<Error | undefined>;
951
+ isLoading: Signal<boolean>;
952
+ };
953
+ methods: {
954
+ hasValue(): this is Resource<Exclude<T, undefined>>;
955
+ _reload(): boolean;
956
+ };
957
+ };
958
+ type ResourceDictionary = Record<string, ResourceRef<unknown>>;
959
+ type NamedResourceResult<T extends ResourceDictionary> = {
960
+ state: {
961
+ [Prop in keyof T as `${Prop & string}Value`]: T[Prop]['value'] extends Signal<infer S> ? S : never;
962
+ };
963
+ props: {
964
+ [Prop in keyof T as `${Prop & string}Status`]: Signal<ResourceStatus>;
965
+ } & {
966
+ [Prop in keyof T as `${Prop & string}Error`]: Signal<Error | undefined>;
967
+ } & {
968
+ [Prop in keyof T as `${Prop & string}IsLoading`]: Signal<boolean>;
969
+ };
970
+ methods: {
971
+ [Prop in keyof T as `${Prop & string}HasValue`]: () => this is Resource<Exclude<T[Prop]['value'], undefined>>;
972
+ } & {
973
+ [Prop in keyof T as `_${Prop & string}Reload`]: () => boolean;
974
+ };
975
+ };
976
+ /**
977
+ * @experimental
978
+ * @description
979
+ *
980
+ * Integrates a `Resource` into the SignalStore and makes the store instance
981
+ * implement the `Resource` interface.
982
+ *
983
+ * The resource’s value is stored under the `value` key in the state
984
+ * and is exposed as a `DeepSignal`.
985
+ *
986
+ * It can also be updated via `patchState`.
987
+ *
988
+ * @usageNotes
989
+ *
990
+ * ```ts
991
+ * const UserStore = signalStore(
992
+ * withState({ userId: undefined as number | undefined }),
993
+ * withResource(({ userId }) =>
994
+ * httpResource<User>(() =>
995
+ * userId === undefined ? undefined : `/users/${userId}`
996
+ * )
997
+ * )
998
+ * );
999
+ *
1000
+ * const userStore = new UserStore();
1001
+ * userStore.value(); // User | undefined
1002
+ * ```
1003
+ *
1004
+ * @param resourceFactory A factory function that receives the store's state signals,
1005
+ * methods, and props. Needs to return a `ResourceRef`.
1006
+ */
1007
+ declare function withResource<Input extends SignalStoreFeatureResult, ResourceValue>(resourceFactory: (store: Input['props'] & Input['methods'] & StateSignals<Input['state']>) => ResourceRef<ResourceValue>): SignalStoreFeature<Input, ResourceResult<ResourceValue>>;
1008
+ /**
1009
+ * @experimental
1010
+ * @description
1011
+ *
1012
+ * Integrates multiple resources into the SignalStore. Each resource is
1013
+ * registered by name, which is used as a prefix when spreading the members
1014
+ * of `Resource` onto the store.
1015
+ *
1016
+ * Each resource’s value is part of the state, stored under the `value` key
1017
+ * with the resource name as prefix. Values are exposed as `DeepSignal`s and
1018
+ * can be updated via `patchState`.
1019
+ *
1020
+ * @usageNotes
1021
+ *
1022
+ * ```ts
1023
+ * const UserStore = signalStore(
1024
+ * withState({ userId: undefined as number | undefined }),
1025
+ * withResource(({ userId }) => ({
1026
+ * list: httpResource<User[]>(() => '/users', { defaultValue: [] }),
1027
+ * detail: httpResource<User>(() =>
1028
+ * userId === undefined ? undefined : `/users/${userId}`
1029
+ * ),
1030
+ * }))
1031
+ * );
1032
+ *
1033
+ * const userStore = new UserStore();
1034
+ * userStore.listValue(); // []
1035
+ * userStore.detailValue(); // User | undefined
1036
+ * ```
1037
+ *
1038
+ * @param resourceFactory A factory function that receives the store's props,
1039
+ * methods, and state signals. It must return a `Record<string, ResourceRef>`.
1040
+ */
1041
+ declare function withResource<Input extends SignalStoreFeatureResult, Dictionary extends ResourceDictionary>(resourceFactory: (store: Input['props'] & Input['methods'] & StateSignals<Input['state']>) => Dictionary): SignalStoreFeature<Input, NamedResourceResult<Dictionary>>;
1042
+ type NamedResource<Name extends string, T> = {
1043
+ [Prop in `${Name}Value`]: Signal<T>;
1044
+ } & {
1045
+ [Prop in `${Name}Status`]: Signal<ResourceStatus>;
1046
+ } & {
1047
+ [Prop in `${Name}Error`]: Signal<Error | undefined>;
1048
+ } & {
1049
+ [Prop in `${Name}IsLoading`]: Signal<boolean>;
1050
+ } & {
1051
+ [Prop in `${Name}HasValue`]: () => boolean;
1052
+ };
1053
+ type IsValidResourceName<Name extends string, Store extends Record<string, unknown>> = Store[`${Name}Value`] extends Signal<infer S> ? Store extends NamedResource<Name, S> ? true : false : false;
1054
+ type ResourceNames<Store extends Record<string, unknown>> = keyof {
1055
+ [Prop in keyof Store as Prop extends `${infer Name}Value` ? IsValidResourceName<Name, Store> extends true ? Name : never : never]: Store[Prop] extends Signal<infer S> ? S : never;
1056
+ };
1057
+ type MappedResource<Store extends Record<string, unknown>, Name extends string> = Resource<Store[`${Name}Value`] extends Signal<infer S> ? S : never>;
1058
+ /**
1059
+ * @experimental
1060
+ * @description
1061
+ *
1062
+ * Maps a named resource to type `Resource<T>`.
1063
+ *
1064
+ * @usageNotes
1065
+ *
1066
+ * ```ts
1067
+ * const store = signalStore(
1068
+ * withState({ userId: undefined as number | undefined }),
1069
+ * withResource(({ userId }) => ({
1070
+ * user: httpResource<User[]>(() => '/users', { defaultValue: [] }),
1071
+ * }))
1072
+ * );
1073
+ * const userResource = mapToResource(store, 'user');
1074
+ * userResource satisfies Resource<User[]>;
1075
+ * ```
1076
+ *
1077
+ * @param store The store instance to map the resource to.
1078
+ * @param name The name of the resource to map.
1079
+ * @returns `ResourceRef<T>`
1080
+ */
1081
+ declare function mapToResource<Name extends ResourceNames<Store>, Store extends Record<string, unknown>>(store: Store, name: Name): MappedResource<Store, Name>;
1082
+
1083
+ export { capitalize, createEffects, createPageArray, createReducer, deriveCallStateKeys, emptyFeature, firstPage, getCallStateKeys, getCollectionArray, getDataServiceKeys, getUndoRedoKeys, gotoPage, mapToResource, nextPage, noPayload, patchState, payload, previousPage, provideDevtoolsConfig, renameDevtoolsName, setError, setLoaded, setLoading, setMaxPageNavigationArrayItems, setPageSize, setResetState, updateState, withCallState, withConditional, withDataService, withDevToolsStub, withDevtools, withDisabledNameIndices, withFeatureFactory, withGlitchTracking, withImmutableState, withIndexedDB, withIndexedDB as withIndexeddb, withLocalStorage, withMapper, withPagination, withRedux, withReset, withResource, withSessionStorage, withStorageSync, withUndoRedo };
945
1084
  export type { CallState, CallStateSignals, CallStateSlice, DataService, DataServiceComputed, DataServiceMethods, DataServiceState, Entity, Filter, NamedCallStateSignals, NamedCallStateSlice, NamedDataServiceComputed, NamedDataServiceMethods, NamedDataServiceState, NamedPaginationServiceSignals, NamedPaginationServiceState, NormalizedUndoRedoOptions, Page, PaginationServiceSignals, PaginationServiceState, ReduxDevtoolsConfig, SetCallState, SetPaginationState, StackItem, SyncConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-architects/ngrx-toolkit",
3
- "version": "20.0.3",
3
+ "version": "20.1.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "GitHub",