<commit_before>import http from "http";
import { it, describe, before, after } from "mocha";
import { createStore, combineReducers, applyMiddleware } from "redux";
import PhenylHttpServer from "@phenyl/http-server";
import PhenylRestApi from "@phenyl/rest-api";
import PhenylHttpClient from "@phenyl/http-client";
import {
  GeneralTypeMap,
  KvsClient,
  Session,
  GeneralAction,
  LocalState,
  GetCommandResult,
  ReqRes
} from "../..//interfaces";
import { createEntityClient } from "@phenyl/memory-db";
import { StandardUserDefinition } from "@phenyl/standards";
import assert from "assert";

import { PhenylRedux, LocalStateFinder } from "../src";
import { PhenylReduxModule } from "../src/phenyl-redux-module";

type PlainPatient = {
  id: string;
  name: string;
  email: string;
  password: string;
};

type PatientRequest = {
  id: string;
  name: string;
  email: string;
  password: string;
};

type PatientResponse = {
  id: string;
  name: string;
  email: string;
};

type Credentials = {
  email: string;
  password: string;
};

type MyAuthSetting = {
  credentials: Credentials;
  options: {};
};

type MyEntityMap = {
  patient: PlainPatient;
};
type MyGeneralReqResEntityMap = {
  patient: ReqRes<PatientRequest, PatientResponse>;
};

type MyAuthCommandMap = {
  patient: MyAuthSetting;
};

type MemberSessionValue = { externalId: string; ttl: number };

interface MyTypeMap extends GeneralTypeMap {
  entities: MyGeneralReqResEntityMap;
  customQueries: {};
  customCommands: {};
  auths: {
    patient: MyAuthSetting;
  };
}

const memoryClient = createEntityClient<MyEntityMap>();
const sessionClient = memoryClient.createSessionClient() as KvsClient<
  Session<"patient", MemberSessionValue>
>;

class PatientDefinition extends StandardUserDefinition<
  MyEntityMap,
  MyAuthSetting
> {
  constructor() {
    super({
      accountPropName: "email",
      passwordPropName: "password",
      entityClient: memoryClient,
      ttl: 24 * 3600
    });
  }

  authorize() {
    return Promise.resolve(true);
  }
}

const functionalGroup = {
  customQueries: {},
  customCommands: {},
  users: {
    patient: new PatientDefinition()
  },
  nonUsers: {}
};

const phenylRedux: PhenylRedux<MyTypeMap> = new PhenylRedux();
const { reducer } = phenylRedux;
const httpClient: PhenylHttpClient<MyTypeMap> = new PhenylHttpClient({
  url: "http://localhost:8080"
});

type Store = {
  phenyl: LocalState<MyGeneralReqResEntityMap, MyAuthCommandMap>;
};

const store = createStore<Store, GeneralAction, {}, {}>(
  combineReducers({ phenyl: reducer }),
  applyMiddleware(
    phenylRedux.createMiddleware({
      client: httpClient,
      storeKey: "phenyl"
    })
  )
);

let server: PhenylHttpServer;
before(() => {
  const restApiHandler: PhenylRestApi<MyTypeMap> = new PhenylRestApi(
    functionalGroup,
    {
      entityClient: memoryClient
    }
  );

  server = new PhenylHttpServer(http.createServer(), {
    restApiHandler
  });<commit_msg>fix(redux): Fix the way to use StandardUserDefinition<commit_after>import http from "http";
import { it, describe, before, after } from "mocha";
import { createStore, combineReducers, applyMiddleware } from "redux";
import PhenylHttpServer from "@phenyl/http-server";
import PhenylRestApi from "@phenyl/rest-api";
import PhenylHttpClient from "@phenyl/http-client";
import {
  GeneralTypeMap,
  GeneralAction,
  LocalState,
  GetCommandResult,
  AuthCommandMapOf,
  ResponseEntityMapOf
} from "../..//interfaces";
import { createEntityClient } from "@phenyl/memory-db";
import { StandardUserDefinition } from "@phenyl/standards";
import assert from "assert";

import { PhenylRedux, LocalStateFinder } from "../src";
import { PhenylReduxModule } from "../src/phenyl-redux-module";

type PlainPatient = {
  id: string;
  name: string;
  email: string;
  password: string;
};

type PatientRequest = PlainPatient;

type PatientResponse = PlainPatient;

type MyGeneralReqResEntityMap = {
  patient: {
    request: PatientRequest;
    response: PatientResponse;
  };
};

interface MyTypeMap extends GeneralTypeMap {
  entities: MyGeneralReqResEntityMap;
  customQueries: {};
  customCommands: {};
  auths: {
    patient: {
      credentials: {
        email: string;
        password: string;
      };
      session: { externalId: string; ttl: number };
    };
  };
}

const memoryClient = createEntityClient<ResponseEntityMapOf<MyTypeMap>>();
const sessionClient = memoryClient.createSessionClient<
  AuthCommandMapOf<MyTypeMap>
>();

class PatientDefinition extends StandardUserDefinition {
  constructor() {
    super({
      accountPropName: "email",
      passwordPropName: "password",
      entityClient: memoryClient,
      ttl: 24 * 3600
    });
  }

  authorize() {
    return Promise.resolve(true);
  }
}

const functionalGroup = {
  customQueries: {},
  customCommands: {},
  users: {
    patient: new PatientDefinition()
  },
  nonUsers: {}
};

const phenylRedux: PhenylRedux<MyTypeMap> = new PhenylRedux();
const { reducer } = phenylRedux;
const httpClient: PhenylHttpClient<MyTypeMap> = new PhenylHttpClient({
  url: "http://localhost:8080"
});

type Store = {
  phenyl: LocalState<MyGeneralReqResEntityMap, AuthCommandMapOf<MyTypeMap>>;
};

const store = createStore<Store, GeneralAction, {}, {}>(
  combineReducers({ phenyl: reducer }),
  applyMiddleware(
    phenylRedux.createMiddleware({
      client: httpClient,
      storeKey: "phenyl"
    })
  )
);

let server: PhenylHttpServer;
before(() => {
  const restApiHandler: PhenylRestApi<MyTypeMap> = new PhenylRestApi(
    functionalGroup,
    {
      entityClient: memoryClient
    }
  );

  server = new PhenylHttpServer(http.createServer(), {
    restApiHandler
  });
{'fraction_non_alphanumeric': 0.12141978562642769, 'fraction_numerical': 0.003514320857494289, 'mean_word_length': 4.329588014981273, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5614022', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1742, 'n_words': 408}