@@ -8,6 +8,9 @@ import type {
88 ExtendSimulationSelectorsInput ,
99 TableOutput ,
1010 AnyState ,
11+ ExtendSimulationActionsInputLoose ,
12+ ExtendSimulationSelectorsInputLoose ,
13+ ExtendStoreConfig ,
1114} from "@simulacrum/foundation-simulator" ;
1215import {
1316 convertInitialStateToStoreState ,
@@ -25,10 +28,14 @@ export type ExtendedSchema = ({ slice }: ExtendSimulationSchema) => {
2528} ;
2629type ExtendActions = typeof inputActions ;
2730type ExtendSelectors = typeof inputSelectors ;
31+ export type Auth0Schema = ReturnType < ExtendedSchema > ;
32+ export type Auth0Actions = ReturnType < ExtendActions > ;
33+ export type Auth0Selectors = ReturnType < ExtendSelectors > ;
34+
2835export type ExtendedSimulationStore = SimulationStore <
29- ReturnType < ExtendedSchema > ,
30- ReturnType < ExtendActions > ,
31- ReturnType < ExtendSelectors >
36+ Auth0Schema ,
37+ Auth0Actions ,
38+ Auth0Selectors
3239> ;
3340
3441const inputSchema =
@@ -56,49 +63,63 @@ const inputSchema =
5663 return slices ;
5764 } ;
5865
59- const inputActions = ( args : ExtendSimulationActions < ExtendedSchema > ) => {
60- return { } ;
66+ const inputActions = ( _args : ExtendSimulationActions < ExtendedSchema > ) => {
67+ return { } as ExtendSimulationActions < ExtendedSchema > ;
6168} ;
6269
6370const extendActions =
64- ( extendedActions ?: ExtendSimulationActionsInput < any , ExtendedSchema > ) =>
71+ (
72+ extendedActions ?: ExtendSimulationActionsInputLoose <
73+ Auth0Actions ,
74+ Auth0Schema
75+ >
76+ ) =>
6577 ( args : ExtendSimulationActions < ExtendedSchema > ) => {
66- return extendedActions
67- ? // @ts -expect-error schema is cyclical, ignore extension for now
68- { ...inputActions ( args ) , ...extendedActions ( args ) }
69- : inputActions ( args ) ;
78+ const base = inputActions ( args ) ;
79+ if ( ! extendedActions ) return base ;
80+ const extResult = extendedActions ( args ) ;
81+ return {
82+ ...( base as object ) ,
83+ ...( extResult as object ) ,
84+ } as Auth0Actions ;
7085 } ;
7186
72- const inputSelectors = ( args : ExtendSimulationSelectors < ExtendedSchema > ) => {
73- const { createSelector, schema } = args ;
74- return { } ;
87+ const inputSelectors = ( _args : ExtendSimulationSelectors < ExtendedSchema > ) => {
88+ return { } as ExtendSimulationSelectors < ExtendedSchema > ;
7589} ;
7690
7791const extendSelectors =
78- ( extendedSelectors ?: ExtendSimulationSelectorsInput < any , ExtendedSchema > ) =>
92+ (
93+ extendedSelectors ?: ExtendSimulationSelectorsInputLoose <
94+ Auth0Selectors ,
95+ Auth0Schema
96+ >
97+ ) =>
7998 ( args : ExtendSimulationSelectors < ExtendedSchema > ) => {
80- return extendedSelectors
81- ? // @ts -expect-error schema is cyclical, ignore extension for now
82- { ...inputSelectors ( args ) , ...extendedSelectors ( args ) }
83- : inputSelectors ( args ) ;
99+ const base = inputSelectors ( args ) ;
100+ if ( ! extendedSelectors ) return base ;
101+ const extResult = extendedSelectors ( args ) ;
102+ return {
103+ ...( base as object ) ,
104+ ...( extResult as object ) ,
105+ } as Auth0Selectors ;
84106 } ;
85107
86- export const extendStore = < T > (
108+ export type Auth0ExtendStoreInput = ExtendStoreConfig <
109+ Auth0Schema ,
110+ Auth0Actions ,
111+ Auth0Selectors
112+ > ;
113+
114+ export const extendStore = (
87115 initialState : Auth0InitialStore | undefined ,
88- extended :
89- | {
90- actions : ExtendSimulationActionsInput <
91- any ,
92- ExtendSimulationSchemaInput < T >
93- > ;
94- selectors : ExtendSimulationSelectorsInput <
95- any ,
96- ExtendSimulationSchemaInput < T >
97- > ;
98- schema ?: ExtendSimulationSchemaInput < T > ;
99- }
100- | undefined
101- ) => ( {
116+ extended ?: Auth0ExtendStoreInput
117+ ) : {
118+ schema : ExtendSimulationSchemaInput < Auth0Schema > ;
119+ actions ?: ExtendSimulationActionsInput < Auth0Actions , Auth0Schema > ;
120+ selectors ?: ExtendSimulationSelectorsInput < Auth0Selectors , Auth0Schema > ;
121+ logs ?: boolean ;
122+ } => ( {
102123 actions : extendActions ( extended ?. actions ) ,
103124 selectors : extendSelectors ( extended ?. selectors ) ,
104125 schema : inputSchema ( initialState , extended ?. schema ) ,
0 commit comments