From 8ee0ebcdd7a992e9e560b9e08ce21e9acd2501fa Mon Sep 17 00:00:00 2001 From: Miroir Framework Date: Thu, 15 Aug 2024 19:05:52 +0200 Subject: [PATCH] create basic elements for Miroir Action Script (MAS), migrate Tools.submit to MAS #28. Use in-memory ExtractorRunner.handleQuery for indexedDb, filesystem and postgres implementations. Some refactorings / renamings around DomainController, PersistenceReduxSaga, PersistenceStoreController, PersistenceStoreControllerManager. --- .../2_domain/DomainControllerInterface.ts | 4 +- .../2_domain/ExtractorRunnerInterface.ts | 3 +- .../4-services/PersistenceInterface.ts | 4 +- .../PersistenceStoreControllerInterface.ts | 9 +- ...sistenceStoreControllerManagerInterface.ts | 6 +- .../src/3_controllers/DomainController.ts | 22 +- .../3_controllers/ErrorHandling/CallUtils.ts | 4 +- .../4_services/PersistenceStoreController.ts | 33 +- .../PersistenceStoreControllerManager.ts | 66 ++- .../miroir-core/src/4_services/RestServer.ts | 4 +- packages/miroir-core/src/index.ts | 2 +- .../createReduxStoreAndPersistenceClient.ts | 52 -- .../persistence/PersistenceReduxSaga.ts | 41 +- packages/miroir-localcache-redux/src/index.ts | 3 - ....timestamp-1722514361412-c9132a1310962.mjs | 49 -- ....timestamp-1722769013725-781c3066241f9.mjs | 49 -- .../src/RestServerStub.ts | 12 +- packages/miroir-server/src/server.ts | 12 +- packages/miroir-server/tsconfig.json | 2 + packages/miroir-standalone-app/src/index.tsx | 13 +- .../4_view/components/RootComponent.tsx | 7 +- .../PersistenceStoreController.integ.test.tsx | 22 +- .../PersistenceStoreExtractorRunner.test.tsx | 168 +++--- .../tests/utils/tests-utils.tsx | 80 ++- ....timestamp-1722514361413-ec6adbb4300c9.mjs | 55 -- ....timestamp-1722769013725-eed2911aeb028.mjs | 55 -- packages/miroir-store-filesystem/package.json | 2 +- .../4_services/FileSystemExtractorRunner.ts | 512 ++++++++++++++++++ .../FileSystemInstanceStoreSectionMixin.ts | 17 +- .../src/4_services/FileSystemStore.ts | 2 +- .../src/4_services/FileSystemStoreSection.ts | 4 +- .../miroir-store-filesystem/tsconfig.json | 6 +- .../miroir-store-filesystem/tsup.config.ts | 9 + packages/miroir-store-indexedDb/package.json | 8 +- .../src/4_services/IndexedDb.ts | 13 - .../4_services/IndexedDbExtractorRunner.ts | 20 +- .../IndexedDbInstanceStoreSectionMixin.ts | 24 +- .../4_services/IndexedDbModelStoreSection.ts | 16 +- .../miroir-store-indexedDb/src/startup.ts | 1 + .../miroir-store-indexedDb/tsup.config.ts | 9 + .../src/4_services/SqlDbExtractorRunner.ts | 85 ++- .../sqlDbInstanceStoreSectionMixin.ts | 15 + 42 files changed, 959 insertions(+), 561 deletions(-) delete mode 100644 packages/miroir-localcache-redux/src/4_services/createReduxStoreAndPersistenceClient.ts delete mode 100644 packages/miroir-localcache-redux/vite.config.js.timestamp-1722514361412-c9132a1310962.mjs delete mode 100644 packages/miroir-localcache-redux/vite.config.js.timestamp-1722769013725-781c3066241f9.mjs delete mode 100644 packages/miroir-standalone-app/vite.config.js.timestamp-1722514361413-ec6adbb4300c9.mjs delete mode 100644 packages/miroir-standalone-app/vite.config.js.timestamp-1722769013725-eed2911aeb028.mjs create mode 100644 packages/miroir-store-filesystem/src/4_services/FileSystemExtractorRunner.ts create mode 100644 packages/miroir-store-filesystem/tsup.config.ts create mode 100644 packages/miroir-store-indexedDb/tsup.config.ts diff --git a/packages/miroir-core/src/0_interfaces/2_domain/DomainControllerInterface.ts b/packages/miroir-core/src/0_interfaces/2_domain/DomainControllerInterface.ts index 8da1fcd8..88ff8e95 100644 --- a/packages/miroir-core/src/0_interfaces/2_domain/DomainControllerInterface.ts +++ b/packages/miroir-core/src/0_interfaces/2_domain/DomainControllerInterface.ts @@ -12,7 +12,7 @@ import { QueryAction, TransactionalInstanceAction } from "../1_core/preprocessor-generated/miroirFundamentalType.js"; -import { PersistenceInterface } from "../4-services/PersistenceInterface.js"; +import { PersistenceStoreLocalOrRemoteInterface } from "../4-services/PersistenceInterface.js"; // ############################################################################################# @@ -122,6 +122,6 @@ export interface DomainControllerInterface { // TODO: currentTransaction should not depend on localCache types?! Use DomainActions instead? currentTransaction(): (TransactionalInstanceAction | ModelAction)[], currentLocalCacheInfo(): LocalCacheInfo, - getRemoteStore(): PersistenceInterface, + getRemoteStore(): PersistenceStoreLocalOrRemoteInterface, } diff --git a/packages/miroir-core/src/0_interfaces/2_domain/ExtractorRunnerInterface.ts b/packages/miroir-core/src/0_interfaces/2_domain/ExtractorRunnerInterface.ts index bca7837d..64b32a23 100644 --- a/packages/miroir-core/src/0_interfaces/2_domain/ExtractorRunnerInterface.ts +++ b/packages/miroir-core/src/0_interfaces/2_domain/ExtractorRunnerInterface.ts @@ -95,7 +95,8 @@ export type ExtractorRunnerMap = AsyncExtractorRunnerMap | // ################################################################################################ export interface PersistenceStoreExtractorRunner { - handleQuery(section: ApplicationSection, query: QueryAction): Promise; + // handleQuery(section: ApplicationSection, query: QueryAction): Promise; + handleQuery(query: QueryAction): Promise; extractEntityInstance:AsyncExtractorRunner< ExtractorForSingleObject, any, DomainElementEntityInstanceOrFailed >; diff --git a/packages/miroir-core/src/0_interfaces/4-services/PersistenceInterface.ts b/packages/miroir-core/src/0_interfaces/4-services/PersistenceInterface.ts index 213cf9c0..88306bbb 100644 --- a/packages/miroir-core/src/0_interfaces/4-services/PersistenceInterface.ts +++ b/packages/miroir-core/src/0_interfaces/4-services/PersistenceInterface.ts @@ -89,10 +89,10 @@ export default {}; /** * Decorator to the Redux Store, handing specific Miroir entity slices */ -export declare interface PersistenceInterface { +export declare interface PersistenceStoreLocalOrRemoteInterface { handlePersistenceAction( action: PersistenceAction ): Promise; } -export interface StoreInterface extends LocalCacheInterface, PersistenceInterface {}; +export interface StoreInterface extends LocalCacheInterface, PersistenceStoreLocalOrRemoteInterface {}; diff --git a/packages/miroir-core/src/0_interfaces/4-services/PersistenceStoreControllerInterface.ts b/packages/miroir-core/src/0_interfaces/4-services/PersistenceStoreControllerInterface.ts index 6f16c447..0864e7c9 100644 --- a/packages/miroir-core/src/0_interfaces/4-services/PersistenceStoreControllerInterface.ts +++ b/packages/miroir-core/src/0_interfaces/4-services/PersistenceStoreControllerInterface.ts @@ -75,17 +75,17 @@ export interface StorageSpaceHandlerInterface { } // ########################################################################################### -export interface PersistenceStoreInstanceSectionAbstractInterface { +export interface PersistenceStoreInstanceSectionAbstractInterface extends PersistenceStoreAbstractSectionInterface{ getInstance(parentUuid: string, uuid: string): Promise; getInstances(parentUuid: string): Promise; - // handleQuery(query: QueryAction): Promise; // TODO: polymorphize function with return type depending on query type? + handleQuery(query: QueryAction): Promise; // TODO: polymorphize function with return type depending on query type? upsertInstance(parentUuid:string, instance:EntityInstance):Promise; deleteInstances(parentUuid:string, instances:EntityInstance[]):Promise; deleteInstance(parentUuid:string, instance:EntityInstance):Promise; } // ########################################################################################### -export interface PersistenceStoreEntitySectionAbstractInterface { +export interface PersistenceStoreEntitySectionAbstractInterface extends PersistenceStoreAbstractSectionInterface { existsEntity(entityUuid:string):boolean; createEntity( @@ -183,9 +183,10 @@ export interface PersistenceStoreControllerInterface getDataState(): Promise<{ [uuid: string]: EntityInstanceCollection }>; // used only for testing purposes! // // instance interface differs from the one in PersistenceStoreInstanceSectionAbstractInterface: it has an ApplicationSection as first parameter + handleQuery(section: ApplicationSection, query: QueryAction): Promise; + getInstance(section: ApplicationSection, parentUuid: string, uuid: Uuid): Promise; getInstances(section: ApplicationSection, parentUuid: string): Promise; - // handleQuery(section: ApplicationSection, query: QueryAction): Promise; upsertInstance(section: ApplicationSection, instance: EntityInstance): Promise; deleteInstance(section: ApplicationSection, instance: EntityInstance): Promise; deleteInstances(section: ApplicationSection, instance: EntityInstance[]): Promise; diff --git a/packages/miroir-core/src/0_interfaces/4-services/PersistenceStoreControllerManagerInterface.ts b/packages/miroir-core/src/0_interfaces/4-services/PersistenceStoreControllerManagerInterface.ts index eb085616..9d43f3b2 100644 --- a/packages/miroir-core/src/0_interfaces/4-services/PersistenceStoreControllerManagerInterface.ts +++ b/packages/miroir-core/src/0_interfaces/4-services/PersistenceStoreControllerManagerInterface.ts @@ -2,7 +2,7 @@ import { Uuid } from "../1_core/EntityDefinition.js"; import { ActionReturnType, StoreUnitConfiguration } from "../1_core/preprocessor-generated/miroirFundamentalType.js"; import { DomainControllerInterface } from "../2_domain/DomainControllerInterface.js"; import { LocalCacheInterface } from "./LocalCacheInterface.js"; -import { PersistenceInterface } from "./PersistenceInterface.js"; +import { PersistenceStoreLocalOrRemoteInterface } from "./PersistenceInterface.js"; import { InitApplicationParameters, PersistenceStoreControllerInterface } from "./PersistenceStoreControllerInterface.js"; @@ -13,9 +13,9 @@ export interface PersistenceStoreControllerManagerInterface { ): Promise; // getReduxStore(): LocalCacheInterface; - getPersistenceStore(): PersistenceInterface; + getPersistenceStoreLocalOrRemote(): PersistenceStoreLocalOrRemoteInterface; getLocalCache(): LocalCacheInterface; - getDomainController(): DomainControllerInterface; + getServerDomainController(): DomainControllerInterface; getPersistenceStoreControllers(): string[]; getPersistenceStoreController(deploymentUuid: Uuid): PersistenceStoreControllerInterface | undefined; diff --git a/packages/miroir-core/src/3_controllers/DomainController.ts b/packages/miroir-core/src/3_controllers/DomainController.ts index 9461ff37..eae19220 100644 --- a/packages/miroir-core/src/3_controllers/DomainController.ts +++ b/packages/miroir-core/src/3_controllers/DomainController.ts @@ -11,7 +11,7 @@ import { MiroirContextInterface } from '../0_interfaces/3_controllers/MiroirCont import { LocalCacheInterface } from "../0_interfaces/4-services/LocalCacheInterface.js"; -import { PersistenceInterface } from '../0_interfaces/4-services/PersistenceInterface.js'; +import { PersistenceStoreLocalOrRemoteInterface } from '../0_interfaces/4-services/PersistenceInterface.js'; import adminConfigurationDeploymentMiroir from "../assets/admin_data/7959d814-400c-4e80-988f-a00fe582ab98/10ff36f2-50a3-48d8-b80f-e48e5d13af8e.json"; @@ -127,16 +127,17 @@ export class DomainController implements DomainControllerInterface { private callUtil: CallUtils; constructor( - private hasDirectAccessToPersistenceStore: boolean, + private domainControllerIsDeployedOn: "server" | "client", private miroirContext: MiroirContextInterface, private localCache: LocalCacheInterface, - private persistenceStore: PersistenceInterface, // instance of PersistenceReduxSaga + private persistenceStore: PersistenceStoreLocalOrRemoteInterface, // instance of PersistenceReduxSaga private endpoint: Endpoint, ) { this.callUtil = new CallUtils(miroirContext.errorLogService, localCache, persistenceStore); } - getRemoteStore(): PersistenceInterface { + // TODO: remove? only used in commented code in index.tsx + getRemoteStore(): PersistenceStoreLocalOrRemoteInterface { return this.persistenceStore; } // ############################################################################################## @@ -254,12 +255,13 @@ export class DomainController implements DomainControllerInterface { try { switch (modelAction.actionName) { case "remoteLocalCacheRollback": { - if (this.hasDirectAccessToPersistenceStore) { + if (this.domainControllerIsDeployedOn == "server") { + // if the domain controller is deployed on the server, we refresh the local cache from the remote store log.info("handleModelAction reloading current configuration from local PersistenceStore!"); await this.loadConfigurationFromPersistenceStore(deploymentUuid); log.info("handleModelAction reloading current configuration from local PersistenceStore DONE!"); } else { - // send action to (remote) persistence action interface handler. + // if the domain controller is deployed on the client, we send the "remoteLocalCacheRollback" action to the server await this.callUtil.callPersistenceAction( {}, // context {}, // context update @@ -733,13 +735,7 @@ export class DomainController implements DomainControllerInterface { JSON.stringify((queryAction as any)["objects"], null, 2) ); - // if (queryAction.query.queryType == "domainModelSingleExtractor" ) { - // // if (["domainModelSingleExtractor","extractorForRecordOfExtractors"].includes(queryAction.query.queryType) ) { - // log.info("handleQuery queryAction", queryAction); - // throw new Error("DomainController handleQuery queryAction not implemented for queryType " + queryAction.query.queryType); - // } - - if (this.hasDirectAccessToPersistenceStore) { + if (this.domainControllerIsDeployedOn == "server") { /** * we're on the server side. Shall we execute the query on the localCache or on the persistentStore? */ diff --git a/packages/miroir-core/src/3_controllers/ErrorHandling/CallUtils.ts b/packages/miroir-core/src/3_controllers/ErrorHandling/CallUtils.ts index 95cd6137..300ba87b 100644 --- a/packages/miroir-core/src/3_controllers/ErrorHandling/CallUtils.ts +++ b/packages/miroir-core/src/3_controllers/ErrorHandling/CallUtils.ts @@ -6,13 +6,13 @@ import { } from "../../0_interfaces/1_core/preprocessor-generated/miroirFundamentalType.js"; import { ErrorLogServiceInterface, MError } from "../../0_interfaces/3_controllers/ErrorLogServiceInterface.js"; import { LocalCacheInterface } from "../../0_interfaces/4-services/LocalCacheInterface.js"; -import { PersistenceInterface } from "../../0_interfaces/4-services/PersistenceInterface.js"; +import { PersistenceStoreLocalOrRemoteInterface } from "../../0_interfaces/4-services/PersistenceInterface.js"; export class CallUtils { constructor( private errorLogService: ErrorLogServiceInterface, private localCache: LocalCacheInterface, - private persistenceStore: PersistenceInterface + private persistenceStore: PersistenceStoreLocalOrRemoteInterface ) {} // ###################################################################################### diff --git a/packages/miroir-core/src/4_services/PersistenceStoreController.ts b/packages/miroir-core/src/4_services/PersistenceStoreController.ts index 474f8911..2f8e9476 100644 --- a/packages/miroir-core/src/4_services/PersistenceStoreController.ts +++ b/packages/miroir-core/src/4_services/PersistenceStoreController.ts @@ -39,6 +39,7 @@ import { cleanLevel } from "./constants.js"; import { ACTION_OK } from "../1_core/constants.js"; import entityEntity from "../assets/miroir_model/16dbfe28-e1d7-4f20-9ba4-c1a9873202ad/16dbfe28-e1d7-4f20-9ba4-c1a9873202ad.json"; import entityEntityDefinition from "../assets/miroir_model/16dbfe28-e1d7-4f20-9ba4-c1a9873202ad/54b9c72f-d4f3-4db9-9e0e-0dc840b530bd.json"; +import { ExtractorRunner, PersistenceStoreExtractorRunner } from "../0_interfaces/2_domain/ExtractorRunnerInterface.js"; const loggerName: string = getLoggerName(packageName, cleanLevel,"PersistenceStoreController"); let log:LoggerInterface = console as any as LoggerInterface; @@ -89,6 +90,7 @@ export async function storeSectionFactory ( // ####################################################################################################################### export class PersistenceStoreController implements PersistenceStoreControllerInterface { private logHeader: string; + // private adminExtractorRunner: PersistenceStoreExtractorRunner; constructor( private adminStore: PersistenceStoreAdminSectionInterface, @@ -96,6 +98,7 @@ export class PersistenceStoreController implements PersistenceStoreControllerInt private dataStoreSection: PersistenceStoreDataSectionInterface, ){ this.logHeader = 'PersistenceStoreController '+ modelStoreSection.getStoreName(); + // this.adminExtractorRunner = new E } // ######################################################################################### @@ -103,6 +106,21 @@ export class PersistenceStoreController implements PersistenceStoreControllerInt return this.modelStoreSection.getStoreName(); } + // ############################################################################################# + async handleQuery(section: ApplicationSection, query: QueryAction): Promise { + // TODO: fix applicationSection!!! + log.info(this.logHeader,'handleQuery','section',section,'query',query); + log.info(this.logHeader,'this.dataStoreSection',this.dataStoreSection); + log.info(this.logHeader,'this.modelStoreSection',this.modelStoreSection); + + const currentStore: PersistenceStoreDataSectionInterface | PersistenceStoreModelSectionInterface = + section == "data" ? this.dataStoreSection : this.modelStoreSection; + const result: ActionReturnType = await currentStore.handleQuery(query); + + log.info(this.logHeader,'handleQuery','section',section,'query',query, "result", result); + return result; + } + // ############################################################################################# async handleAction(persistenceStoreControllerAction: PersistenceStoreControllerAction): Promise { switch (persistenceStoreControllerAction.actionType) { @@ -567,21 +585,6 @@ export class PersistenceStoreController implements PersistenceStoreControllerInt return result; } - // // ############################################################################################# - // async handleQuery(section: ApplicationSection, query: QueryAction): Promise { - // // TODO: fix applicationSection!!! - // log.info(this.logHeader,'handleQuery','section',section,'query',query); - // log.info(this.logHeader,'this.dataStoreSection',this.dataStoreSection); - // log.info(this.logHeader,'this.modelStoreSection',this.modelStoreSection); - - // const currentStore: PersistenceStoreDataSectionInterface | PersistenceStoreModelSectionInterface = - // section == "data" ? this.dataStoreSection : this.modelStoreSection; - // // const result: ActionReturnType = await currentStore.handleQuery(query); - - // log.info(this.logHeader,'handleQuery','section',section,'query',query, "result", result); - // return result; - // } - // ############################################################################################## async upsertInstance(section: ApplicationSection, instance:EntityInstance):Promise{ log.info( diff --git a/packages/miroir-core/src/4_services/PersistenceStoreControllerManager.ts b/packages/miroir-core/src/4_services/PersistenceStoreControllerManager.ts index 79f7d2ce..cc424b8e 100644 --- a/packages/miroir-core/src/4_services/PersistenceStoreControllerManager.ts +++ b/packages/miroir-core/src/4_services/PersistenceStoreControllerManager.ts @@ -20,7 +20,7 @@ import { packageName } from "../constants.js"; import { getLoggerName } from "../tools.js"; import { MiroirLoggerFactory } from "./Logger.js"; import { cleanLevel } from "./constants.js"; -import { PersistenceInterface } from "../0_interfaces/4-services/PersistenceInterface.js"; +import { PersistenceStoreLocalOrRemoteInterface } from "../0_interfaces/4-services/PersistenceInterface.js"; import { LocalCacheInterface } from "../0_interfaces/4-services/LocalCacheInterface.js"; import { DomainControllerInterface } from "../0_interfaces/2_domain/DomainControllerInterface.js"; import { DomainController } from "../3_controllers/DomainController.js"; @@ -38,7 +38,7 @@ MiroirLoggerFactory.asyncCreateLogger(loggerName).then( // ################################################################################################ export class PersistenceStoreControllerManager implements PersistenceStoreControllerManagerInterface { private persistenceStoreControllers: { [deploymentUuid: Uuid]: PersistenceStoreControllerInterface } = {}; - private persistenceStore: PersistenceInterface | undefined; // receives instance of PersistenceReduxSaga + private persistenceStoreLocalOrRemote: PersistenceStoreLocalOrRemoteInterface | undefined; // receives instance of PersistenceReduxSaga private localCache: LocalCacheInterface | undefined; private domainController: DomainController | undefined; @@ -49,16 +49,20 @@ export class PersistenceStoreControllerManager implements PersistenceStoreContro ) {} // ################################################################################################ - setPersistenceStore(persistenceStore: PersistenceInterface) { - this.persistenceStore = persistenceStore; + /** + * this is like prop drilling, this is not directly used by this class, but by the created DomainController (this.domainController) + * @param persistenceStore + */ + setPersistenceStoreLocalOrRemote(persistenceStore: PersistenceStoreLocalOrRemoteInterface) { + this.persistenceStoreLocalOrRemote = persistenceStore; } // ################################################################################################ - getPersistenceStore(): PersistenceInterface { - if (this.persistenceStore) { - return this.persistenceStore; + getPersistenceStoreLocalOrRemote(): PersistenceStoreLocalOrRemoteInterface { + if (this.persistenceStoreLocalOrRemote) { + return this.persistenceStoreLocalOrRemote; } else { - throw new Error("PersistenceStoreControllerManager getPersistenceStore no persistenceStore yet!"); + throw new Error("PersistenceStoreControllerManager getPersistenceStoreLocalOrRemote no persistenceStore yet!"); } } @@ -78,11 +82,34 @@ export class PersistenceStoreControllerManager implements PersistenceStoreContro } // ################################################################################################ - getDomainController(): DomainControllerInterface { + /** + * USED ONLY ON THE SERVER SIDE, INCLUDING EMULATED SIDE, FOR NOW. + * @returns + */ + getServerDomainController(): DomainControllerInterface { if (this.domainController) { return this.domainController; } else { - throw new Error("PersistenceStoreControllerManager getDomainController no domainController yet!"); + if (!this.localCache || !this.persistenceStoreLocalOrRemote) { + throw new Error( + "PersistenceStoreControllerManager getLocalCache no localCache or persitenceStore yet! localCache=" + + this.localCache + + " persistenceStore=" + + this.persistenceStoreLocalOrRemote + ); + } + + // TODO: domainController instance is also created in index.tsx and test-utils.tsx (the overall setup sequence). Isn't it redundant? + // TODO: THIS IS OVERLOADED BY EACH CALL TO addPersistenceStoreController! + this.domainController = new DomainController( + "server", // we are on the server, use localCache for queries upon receiving "remoteLocalCacheRollback" action + new MiroirContext(), + this.localCache, // implements LocalCacheInterface + this.persistenceStoreLocalOrRemote, // implements PersistenceStoreLocalOrRemoteInterface, instance of PersistenceReduxSaga + new Endpoint(this.localCache) + ); + return this.domainController; + // throw new Error("PersistenceStoreControllerManager getServerDomainController no domainController yet!"); } } @@ -99,25 +126,6 @@ export class PersistenceStoreControllerManager implements PersistenceStoreContro JSON.stringify({ storageType: config.admin.emulatedServerType }) ); - if (!this.localCache || !this.persistenceStore) { - throw new Error( - "PersistenceStoreControllerManager getLocalCache no localCache or persitenceStore yet! localCache=" + - this.localCache + - " persistenceStore=" + - this.persistenceStore - ); - } - - // TODO: domainController instance is also created in index.tsx and test-utils.tsx (the overall setup sequence). Isn't it redundant? - this.domainController = new DomainController( - true, // we are on the server, use localCache for queries upon receiving "remoteLocalCacheRollback" action - new MiroirContext(), - this.localCache, // implements LocalCacheInterface - this.persistenceStore, // implements PersistenceInterface, instance of PersistenceReduxSaga - new Endpoint(this.localCache) - ); - - if (!adminStoreFactory) { log.info( "addPersistenceStoreController no admin store factory found for", diff --git a/packages/miroir-core/src/4_services/RestServer.ts b/packages/miroir-core/src/4_services/RestServer.ts index 5b46928e..44ca4f83 100644 --- a/packages/miroir-core/src/4_services/RestServer.ts +++ b/packages/miroir-core/src/4_services/RestServer.ts @@ -221,7 +221,7 @@ export async function restActionHandler( case "modelAction": case "instanceAction": { const localPersistenceStoreController = persistenceStoreControllerManager.getPersistenceStoreController(action.deploymentUuid); - const domainController = persistenceStoreControllerManager.getDomainController(); + const domainController = persistenceStoreControllerManager.getServerDomainController(); if (!localPersistenceStoreController) { throw new Error("could not find controller for deployment: " + action.deploymentUuid); } @@ -280,7 +280,7 @@ export async function queryHandler( const localPersistenceStoreController = persistenceStoreControllerManager.getPersistenceStoreController( deploymentUuid ); - const domainController = persistenceStoreControllerManager.getDomainController(); + const domainController = persistenceStoreControllerManager.getServerDomainController(); if (!localPersistenceStoreController) { throw new Error("RestServer could not find controller for deployment:" + deploymentUuid); } diff --git a/packages/miroir-core/src/index.ts b/packages/miroir-core/src/index.ts index 8f303e69..7da2569a 100644 --- a/packages/miroir-core/src/index.ts +++ b/packages/miroir-core/src/index.ts @@ -391,7 +391,7 @@ export { export { HttpRequestBodyFormat, HttpResponseBodyFormat, - PersistenceInterface, + PersistenceStoreLocalOrRemoteInterface, RemoteStoreActionReturnType, RestPersistenceClientAndRestClientInterface, RestClientCallReturnType, diff --git a/packages/miroir-localcache-redux/src/4_services/createReduxStoreAndPersistenceClient.ts b/packages/miroir-localcache-redux/src/4_services/createReduxStoreAndPersistenceClient.ts deleted file mode 100644 index f79979af..00000000 --- a/packages/miroir-localcache-redux/src/4_services/createReduxStoreAndPersistenceClient.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { - LoggerInterface, - MiroirLoggerFactory, - RestClient, - PersistenceStoreControllerManagerInterface, - getLoggerName -} from "miroir-core"; - -import { packageName } from "../constants.js"; -import { LocalCache } from "./LocalCache.js"; -import { cleanLevel } from "./constants.js"; -import { PersistenceReduxSaga } from "./persistence/PersistenceReduxSaga.js"; -import RestPersistenceClientAndRestClient from "./persistence/RestPersistenceClientAndRestClient.js"; - - -const loggerName: string = getLoggerName(packageName, cleanLevel,"createReduxStoreAndPersistenceClient"); -let log:LoggerInterface = console as any as LoggerInterface; -MiroirLoggerFactory.asyncCreateLogger(loggerName).then((value: LoggerInterface) => { - log = value; -}); - -// ############################################################################################# -export function createReduxStoreAndPersistenceClient( - rootApiUrl: string, - fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise, - persistenceStoreControllerManager?: PersistenceStoreControllerManagerInterface -):{ - localCache: LocalCache, -} { - const client: RestClient = new RestClient(fetch); - const persistenceClientAndRestClient = new RestPersistenceClientAndRestClient(rootApiUrl, client); - - // let instanceSagas: PersistenceReduxSaga - // if (persistenceStoreControllerManager) { - // instanceSagas = new PersistenceReduxSaga( - // undefined, - // persistenceStoreControllerManager - // ); - // } else { - // instanceSagas = new PersistenceReduxSaga( - // persistenceClientAndRestClient - // ); - // } - - // const localCache: LocalCache = new LocalCache(instanceSagas); - const localCache: LocalCache = new LocalCache(); - // localCache.run(); - - - return { localCache } - -} \ No newline at end of file diff --git a/packages/miroir-localcache-redux/src/4_services/persistence/PersistenceReduxSaga.ts b/packages/miroir-localcache-redux/src/4_services/persistence/PersistenceReduxSaga.ts index 00dc29de..e3a1ca01 100644 --- a/packages/miroir-localcache-redux/src/4_services/persistence/PersistenceReduxSaga.ts +++ b/packages/miroir-localcache-redux/src/4_services/persistence/PersistenceReduxSaga.ts @@ -13,7 +13,7 @@ import { LoggerInterface, MiroirLoggerFactory, PersistenceAction, - PersistenceInterface, + PersistenceStoreLocalOrRemoteInterface, PersistenceStoreControllerAction, PersistenceStoreControllerManagerInterface, RestClientCallReturnType, @@ -53,6 +53,14 @@ export function getPersistenceActionReduxEventNames(persistenceActionNames:strin //######################################################################################### //# SLICE //######################################################################################### +export type PersistenceReduxSagaParams = { + persistenceStoreAccessMode: "local", + localPersistenceStoreControllerManager: PersistenceStoreControllerManagerInterface +} | { + persistenceStoreAccessMode: "remote", + remotePersistenceStoreRestClient: RestPersistenceClientAndRestClientInterface +}; + /** * handles calls to the persistence store, either local or remote * @@ -61,14 +69,13 @@ export function getPersistenceActionReduxEventNames(persistenceActionNames:strin * which may have side-effects on the local cache / redux store (data is loaded this way from the Persistent store). * */ -export class PersistenceReduxSaga implements PersistenceInterface { +export class PersistenceReduxSaga implements PersistenceStoreLocalOrRemoteInterface { // TODO:!!!!!!!!!!! Model instances or data instances? They must be treated differently regarding to caching, transactions, undo/redo, etc. // TODO: do not use client directly, it is a dependence on implementation. Use an interface to hide Rest/graphql implementation. private localCache: LocalCache | undefined; constructor( // TODO: either remoteStoreNetworkClient or persistenceStoreControllerManager must be defined, not both! Force this distinction in the constructor. - private remotePersistenceStoreRestClient: RestPersistenceClientAndRestClientInterface | undefined, - private localPersistenceStoreControllerManager?: PersistenceStoreControllerManagerInterface | undefined + private params: PersistenceReduxSagaParams, ) {} //######################################################################################### @@ -134,9 +141,9 @@ export class PersistenceReduxSaga implements PersistenceInterface { ): Generator | CallEffect> { const { action } = p.payload; try { - if (this.localPersistenceStoreControllerManager) { + if (this.params.persistenceStoreAccessMode == "local") { // direct access to store controller, action is executed locally - + const localParams = this.params as { persistenceStoreAccessMode: "local"; localPersistenceStoreControllerManager: PersistenceStoreControllerManagerInterface }; switch (action.actionType) { case "storeManagementAction": case "bundleAction": { @@ -144,7 +151,7 @@ export class PersistenceReduxSaga implements PersistenceInterface { storeActionOrBundleActionStoreRunner( action.actionName, action, - this.localPersistenceStoreControllerManager as PersistenceStoreControllerManagerInterface + localParams.localPersistenceStoreControllerManager ) ); break; @@ -152,7 +159,7 @@ export class PersistenceReduxSaga implements PersistenceInterface { case "instanceAction": case "modelAction": { const localPersistenceStoreController = - this.localPersistenceStoreControllerManager.getPersistenceStoreController(action.deploymentUuid); + localParams.localPersistenceStoreControllerManager.getPersistenceStoreController(action.deploymentUuid); if (!localPersistenceStoreController) { throw new Error( @@ -164,7 +171,7 @@ export class PersistenceReduxSaga implements PersistenceInterface { } case "LocalPersistenceAction": { const localPersistenceStoreController = - this.localPersistenceStoreControllerManager.getPersistenceStoreController(action.deploymentUuid); + localParams.localPersistenceStoreControllerManager.getPersistenceStoreController(action.deploymentUuid); if (!localPersistenceStoreController) { throw new Error( @@ -225,12 +232,14 @@ export class PersistenceReduxSaga implements PersistenceInterface { return yield ACTION_OK; } - if (this.remotePersistenceStoreRestClient != undefined) { + // if this.access == "local" then function has returned already + if (this.params.persistenceStoreAccessMode == "remote") { + const localParams = this.params as { persistenceStoreAccessMode: "remote"; remotePersistenceStoreRestClient: RestPersistenceClientAndRestClientInterface }; // indirect access to a remote storeController through the network // log.info("handlePersistenceAction calling remoteStoreNetworkClient on action",JSON.stringify(action)); const clientResult: RestClientCallReturnType = yield* call(() => ( - this.remotePersistenceStoreRestClient as RestPersistenceClientAndRestClientInterface + localParams.remotePersistenceStoreRestClient ).handleNetworkPersistenceAction(action) ); log.debug("handlePersistenceAction from remoteStoreNetworkClient received clientResult", clientResult); @@ -276,12 +285,12 @@ export class PersistenceReduxSaga implements PersistenceInterface { break; } } - } else { - throw new Error( - "persistenceReduxSaga persistenceActionReduxSaga found neither remoteStoreNetworkClient nor persistenceStoreControllerManager for action " + - JSON.stringify(action) - ); } + + throw new Error( // this should never happen + "persistenceReduxSaga persistenceActionReduxSaga found neither remoteStoreNetworkClient nor persistenceStoreControllerManager for action " + + JSON.stringify(action) + ); } catch (e: any) { log.error("handlePersistenceAction exception", e); const result: ActionReturnType = { diff --git a/packages/miroir-localcache-redux/src/index.ts b/packages/miroir-localcache-redux/src/index.ts index 4b180d22..37412127 100644 --- a/packages/miroir-localcache-redux/src/index.ts +++ b/packages/miroir-localcache-redux/src/index.ts @@ -1,8 +1,5 @@ export { LocalCache } from "./4_services/LocalCache.js"; // export { } from "./4_services/LocalCache/LocalCacheSlice"; -export { - createReduxStoreAndPersistenceClient, -} from "./4_services/createReduxStoreAndPersistenceClient.js"; export { getLocalCacheKeysDeploymentSectionEntitiesList, getDeploymentUuidListFromLocalCacheKeys, diff --git a/packages/miroir-localcache-redux/vite.config.js.timestamp-1722514361412-c9132a1310962.mjs b/packages/miroir-localcache-redux/vite.config.js.timestamp-1722514361412-c9132a1310962.mjs deleted file mode 100644 index 8d146df0..00000000 --- a/packages/miroir-localcache-redux/vite.config.js.timestamp-1722514361412-c9132a1310962.mjs +++ /dev/null @@ -1,49 +0,0 @@ -// packages/miroir-localcache-redux/vite.config.js -import { defineConfig } from "file:///C:/Users/nono/Documents/devhome/miroir-app-dev/packages/miroir-localcache-redux/node_modules/vite/dist/node/index.js"; -import react from "file:///C:/Users/nono/Documents/devhome/miroir-app-dev/node_modules/@vitejs/plugin-react/dist/index.mjs"; -import { nodePolyfills } from "file:///C:/Users/nono/Documents/devhome/miroir-app-dev/node_modules/vite-plugin-node-polyfills/dist/index.js"; -var vite_config_default = defineConfig({ - root: "src", - build: { - // Relative to the root - outDir: "../dist" - }, - // resolve: { - // alias: { - // src: path.resolve(__dirname, 'src'), - // } - // }, - plugins: [ - nodePolyfills({ - // To add only specific polyfills, add them here. If no option is passed, adds all polyfills - // include: ['crypto'], - // To exclude specific polyfills, add them to this list. Note: if include is provided, this has no effect - // exclude: [ - // 'http', // Excludes the polyfill for `http` and `node:http`. - // ], - // // Whether to polyfill specific globals. - // globals: { - // Buffer: true, // can also be 'build', 'dev', or false - // global: true, - // process: true, - // }, - // // Whether to polyfill `node:` protocol imports. - // protocolImports: true, - }), - react({ - // Use React plugin in all *.jsx and *.tsx files - include: "../src/**/*.{jsx,tsx}" - }) - ], - test: { - root: "tests", - globals: true, - watch: false, - environment: "happy-dom", - setupFiles: ["./setup.ts"] - } -}); -export { - vite_config_default as default -}; -//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsicGFja2FnZXMvbWlyb2lyLWxvY2FsY2FjaGUtcmVkdXgvdml0ZS5jb25maWcuanMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF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git a/packages/miroir-localcache-redux/vite.config.js.timestamp-1722769013725-781c3066241f9.mjs b/packages/miroir-localcache-redux/vite.config.js.timestamp-1722769013725-781c3066241f9.mjs deleted file mode 100644 index 8d146df0..00000000 --- a/packages/miroir-localcache-redux/vite.config.js.timestamp-1722769013725-781c3066241f9.mjs +++ /dev/null @@ -1,49 +0,0 @@ -// packages/miroir-localcache-redux/vite.config.js -import { defineConfig } from "file:///C:/Users/nono/Documents/devhome/miroir-app-dev/packages/miroir-localcache-redux/node_modules/vite/dist/node/index.js"; -import react from "file:///C:/Users/nono/Documents/devhome/miroir-app-dev/node_modules/@vitejs/plugin-react/dist/index.mjs"; -import { nodePolyfills } from "file:///C:/Users/nono/Documents/devhome/miroir-app-dev/node_modules/vite-plugin-node-polyfills/dist/index.js"; -var vite_config_default = defineConfig({ - root: "src", - build: { - // Relative to the root - outDir: "../dist" - }, - // resolve: { - // alias: { - // src: path.resolve(__dirname, 'src'), - // } - // }, - plugins: [ - nodePolyfills({ - // To add only specific polyfills, add them here. If no option is passed, adds all polyfills - // include: ['crypto'], - // To exclude specific polyfills, add them to this list. Note: if include is provided, this has no effect - // exclude: [ - // 'http', // Excludes the polyfill for `http` and `node:http`. - // ], - // // Whether to polyfill specific globals. - // globals: { - // Buffer: true, // can also be 'build', 'dev', or false - // global: true, - // process: true, - // }, - // // Whether to polyfill `node:` protocol imports. - // protocolImports: true, - }), - react({ - // Use React plugin in all *.jsx and *.tsx files - include: "../src/**/*.{jsx,tsx}" - }) - ], - test: { - root: "tests", - globals: true, - watch: false, - environment: "happy-dom", - setupFiles: ["./setup.ts"] - } -}); -export { - vite_config_default as default -}; -//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsicGFja2FnZXMvbWlyb2lyLWxvY2FsY2FjaGUtcmVkdXgvdml0ZS5jb25maWcuanMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcml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Cg== diff --git a/packages/miroir-server-msw-stub/src/RestServerStub.ts b/packages/miroir-server-msw-stub/src/RestServerStub.ts index 619b1f0a..c7977250 100644 --- a/packages/miroir-server-msw-stub/src/RestServerStub.ts +++ b/packages/miroir-server-msw-stub/src/RestServerStub.ts @@ -45,29 +45,29 @@ export class RestServerStub { this.handlers = restServerHandlers.map( - (h:RestServiceHandler)=> (http as any)[h.method](this.rootApiUrl + h.url, + (restService:RestServiceHandler)=> (http as any)[restService.method](this.rootApiUrl + restService.url, async (p:{ request: any/* StrictRequest */, params: any /*PathParams*/}) => { const { request, params} = p; // log.info("RestServerStub received request",h.method, h.rootApiUrl + h.url,"request", request, "params", params); let body: HttpRequestBodyFormat = {} - if (h.method !== "get") { + if (restService.method !== "get") { try { body = (await request.json()) as HttpRequestBodyFormat; } catch (e) { - log.error("RestServerStub could not read body for", h.method,h.url,":",e); + log.error("RestServerStub could not read body for", restService.method,restService.url,":",e); } } // log.info("RestServerStub received request",h.method, h.rootApiUrl + h.url, "body", body); try { - const result = await h.handler( + const result = await restService.handler( false, // useDomainControllerToHandleModelAndInstanceActions: since we're emulating the REST server, we have direct access the persistenceStore, do not use the domainController (response: any) => (localData: any) => HttpResponse.json(localData), undefined /* response object provided by Express Rest interface, which is not needed by MSW, that uses class HttpResponse*/, persistenceStoreControllerManager, localCache, - h.method /* method */, - this.rootApiUrl + h.url, + restService.method /* method */, + this.rootApiUrl + restService.url, body, // body params ); diff --git a/packages/miroir-server/src/server.ts b/packages/miroir-server/src/server.ts index 72fef9bf..197c5681 100644 --- a/packages/miroir-server/src/server.ts +++ b/packages/miroir-server/src/server.ts @@ -1,6 +1,6 @@ import express, { Request } from 'express'; -import { fetch } from 'cross-fetch'; +// import { fetch } from 'cross-fetch'; import { ConfigurationService, @@ -86,7 +86,7 @@ miroirPostgresStoreSectionStartup(); -const client: RestClient = new RestClient(fetch); +// const client: RestClient = new RestClient(fetch); // const persistenceClientAndRestClient = new RestPersistenceClientAndRestClient("", client); const localCache: LocalCache = new LocalCache(); @@ -98,13 +98,15 @@ const persistenceStoreControllerManager = new PersistenceStoreControllerManager( ); const persistenceSaga: PersistenceReduxSaga = new PersistenceReduxSaga( - undefined, - persistenceStoreControllerManager + { + persistenceStoreAccessMode: "local", + localPersistenceStoreControllerManager: persistenceStoreControllerManager, + } ); persistenceSaga.run(localCache) -persistenceStoreControllerManager.setPersistenceStore(persistenceSaga); // useless? +persistenceStoreControllerManager.setPersistenceStoreLocalOrRemote(persistenceSaga); // useless? persistenceStoreControllerManager.setLocalCache(localCache); // open all configured stores diff --git a/packages/miroir-server/tsconfig.json b/packages/miroir-server/tsconfig.json index 2e9a1b15..b87cb048 100644 --- a/packages/miroir-server/tsconfig.json +++ b/packages/miroir-server/tsconfig.json @@ -4,6 +4,8 @@ "outDir": "./dist", "rootDir": "./", "baseUrl": "./", + "target": "ESNext", + "module": "NodeNext", }, "exclude": ["./node_modules/**","./src/**/*.spec.js", "./src/**/*.spec.jsx", "./src/**/*.spec.ts", "./src/**/*.spec.tsx"], "include": ["./src/**/*.json", "./src/**/*.js", "./src/**/*.jsx", "./src/**/*.ts", "./src/**/*.tsx"] diff --git a/packages/miroir-standalone-app/src/index.tsx b/packages/miroir-standalone-app/src/index.tsx index 404b0a05..083383ea 100644 --- a/packages/miroir-standalone-app/src/index.tsx +++ b/packages/miroir-standalone-app/src/index.tsx @@ -24,7 +24,7 @@ import { MiroirContext, miroirCoreStartup, MiroirLoggerFactory, - PersistenceInterface, + PersistenceStoreLocalOrRemoteInterface, RestClient, restServerDefaultHandlers, SpecificLoggerOptionsMap, @@ -275,17 +275,20 @@ async function start(root:Root) { ); const persistenceSaga: PersistenceReduxSaga = new PersistenceReduxSaga( - persistenceClientAndRestClient - ); + { + persistenceStoreAccessMode: "remote", + remotePersistenceStoreRestClient: persistenceClientAndRestClient + } + ); persistenceSaga.run(localCache) // TODO: domainController instance is also created in PersistenceStoreControllerManager. Isn't it redundant? const domainController: DomainControllerInterface = new DomainController( - false, // we are on the client, we have to send "remoteLocalCacheRollback" actions to the (remote) persistenceStore + "client", // we are on the client, we have to send "remoteLocalCacheRollback" actions to the (remote) persistenceStore miroirContext, localCache, // implements LocalCacheInterface - persistenceSaga, // implements PersistenceInterface + persistenceSaga, // implements PersistenceStoreLocalOrRemoteInterface new Endpoint(localCache) ); diff --git a/packages/miroir-standalone-app/src/miroir-fwk/4_view/components/RootComponent.tsx b/packages/miroir-standalone-app/src/miroir-fwk/4_view/components/RootComponent.tsx index a14b4109..fa05c232 100644 --- a/packages/miroir-standalone-app/src/miroir-fwk/4_view/components/RootComponent.tsx +++ b/packages/miroir-standalone-app/src/miroir-fwk/4_view/components/RootComponent.tsx @@ -44,7 +44,7 @@ import { MiroirLoggerFactory, modelEndpointV1, persistenceEndpointVersionV1, - PersistenceInterface, + PersistenceStoreLocalOrRemoteInterface, queryEndpointVersionV1, storeManagementEndpoint, StoreOrBundleAction, @@ -229,7 +229,6 @@ export const RootComponent = (props: RootComponentProps) => {