注入全局的getRandomValues
This commit is contained in:
parent
9365aaf780
commit
785a2ed887
14
src/index.ts
14
src/index.ts
|
|
@ -22,8 +22,8 @@ class DebugRunningContext<ED extends EntityDict> extends Context<ED> implements
|
||||||
getApplication: () => Application;
|
getApplication: () => Application;
|
||||||
getToken: () => Token | undefined;
|
getToken: () => Token | undefined;
|
||||||
|
|
||||||
constructor(store: DebugStore<ED>, getRandomNumber: (length: number) => Promise<Uint8Array>, ga: () => Application, gt: () => Token | undefined) {
|
constructor(store: DebugStore<ED>, ga: () => Application, gt: () => Token | undefined) {
|
||||||
super(store, getRandomNumber);
|
super(store);
|
||||||
this.getApplication = ga;
|
this.getApplication = ga;
|
||||||
this.getToken = gt;
|
this.getToken = gt;
|
||||||
}
|
}
|
||||||
|
|
@ -37,7 +37,6 @@ function createAspectProxy<ED extends BaseEntityDict & EntityDict,
|
||||||
triggers: Array<Trigger<ED, keyof ED>>,
|
triggers: Array<Trigger<ED, keyof ED>>,
|
||||||
applicationId: string,
|
applicationId: string,
|
||||||
features: BasicFeatures<ED, AD> & FD,
|
features: BasicFeatures<ED, AD> & FD,
|
||||||
getRandomNumber: (length: number) => Promise<Uint8Array>,
|
|
||||||
aspectDict?: AD,
|
aspectDict?: AD,
|
||||||
initialData?: {
|
initialData?: {
|
||||||
[T in keyof ED]?: Array<ED[T]['OpSchema']>;
|
[T in keyof ED]?: Array<ED[T]['OpSchema']>;
|
||||||
|
|
@ -56,7 +55,7 @@ function createAspectProxy<ED extends BaseEntityDict & EntityDict,
|
||||||
|
|
||||||
const connectAspectToDebugStore = (aspect: Aspect<ED>): (p: Parameters<typeof aspect>[0], frontContext: FrontContext<ED>) => ReturnType<typeof aspect> => {
|
const connectAspectToDebugStore = (aspect: Aspect<ED>): (p: Parameters<typeof aspect>[0], frontContext: FrontContext<ED>) => ReturnType<typeof aspect> => {
|
||||||
return async (params: Parameters<typeof aspect>[0], frontContext: FrontContext<ED>) => {
|
return async (params: Parameters<typeof aspect>[0], frontContext: FrontContext<ED>) => {
|
||||||
const context2 = new Context(debugStore, getRandomNumber);
|
const context2 = new Context(debugStore);
|
||||||
|
|
||||||
const { result: [application] } = await debugStore.select('application', {
|
const { result: [application] } = await debugStore.select('application', {
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -89,7 +88,7 @@ function createAspectProxy<ED extends BaseEntityDict & EntityDict,
|
||||||
}
|
}
|
||||||
const getToken = () => token;
|
const getToken = () => token;
|
||||||
|
|
||||||
const runningContext = new DebugRunningContext(debugStore, getRandomNumber, getApplication, getToken)
|
const runningContext = new DebugRunningContext(debugStore, getApplication, getToken)
|
||||||
const result = aspect(params, runningContext);
|
const result = aspect(params, runningContext);
|
||||||
|
|
||||||
cacheStore.sync(runningContext.opRecords, frontContext);
|
cacheStore.sync(runningContext.opRecords, frontContext);
|
||||||
|
|
@ -108,7 +107,6 @@ export function initialize<ED extends EntityDict & BaseEntityDict, AD extends Re
|
||||||
storageSchema: StorageSchema<ED>,
|
storageSchema: StorageSchema<ED>,
|
||||||
applicationId: string,
|
applicationId: string,
|
||||||
createFeatures: (basicFeatures: BasicFeatures<ED, AD>) => FD,
|
createFeatures: (basicFeatures: BasicFeatures<ED, AD>) => FD,
|
||||||
getRandomNumber: (length: number) => Promise<Uint8Array>,
|
|
||||||
triggers?: Array<Trigger<ED, keyof ED>>,
|
triggers?: Array<Trigger<ED, keyof ED>>,
|
||||||
aspectDict?: AD,
|
aspectDict?: AD,
|
||||||
initialData?: {
|
initialData?: {
|
||||||
|
|
@ -127,7 +125,7 @@ export function initialize<ED extends EntityDict & BaseEntityDict, AD extends Re
|
||||||
|
|
||||||
// todo default triggers
|
// todo default triggers
|
||||||
const aspectProxy = createAspectProxy<ED, AD, FD>(cacheStore, storageSchema, triggers || [],
|
const aspectProxy = createAspectProxy<ED, AD, FD>(cacheStore, storageSchema, triggers || [],
|
||||||
applicationId, features, getRandomNumber, aspectDict, initialData);
|
applicationId, features, aspectDict, initialData);
|
||||||
|
|
||||||
keys(features).forEach(
|
keys(features).forEach(
|
||||||
ele => {
|
ele => {
|
||||||
|
|
@ -171,7 +169,7 @@ export function initialize<ED extends EntityDict & BaseEntityDict, AD extends Re
|
||||||
return {
|
return {
|
||||||
subscribe,
|
subscribe,
|
||||||
features,
|
features,
|
||||||
createContext: () => new FrontContext<ED>(cacheStore, getRandomNumber),
|
createContext: () => new FrontContext<ED>(cacheStore),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { pull } from 'lodash';
|
import { pull } from 'lodash';
|
||||||
import { Aspect } from 'oak-domain/lib/types/Aspect';
|
import { Aspect } from 'oak-domain/lib/types/Aspect';
|
||||||
import { EntityDict } from 'oak-domain/lib/types/Entity';
|
import { EntityDict } from 'oak-domain/lib/types/Entity';
|
||||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-domain/EntityDict';
|
|
||||||
import { aspectDict as basicAspectDict} from 'oak-general-business';
|
import { aspectDict as basicAspectDict} from 'oak-general-business';
|
||||||
import { FrontContext } from '../FrontContext';
|
import { FrontContext } from '../FrontContext';
|
||||||
import { AspectProxy } from './AspectProxy';
|
import { AspectProxy } from './AspectProxy';
|
||||||
|
|
|
||||||
|
|
@ -61,13 +61,9 @@
|
||||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||||
/* Advanced Options */
|
/* Advanced Options */
|
||||||
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||||
"typeRoots": [
|
|
||||||
"./src/typings"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [ "src/typings/**/*.ts" ],
|
||||||
"src/typings/**/*.ts" ],
|
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules",
|
"node_modules",
|
||||||
"**/*.spec.ts",
|
"**/*.spec.ts",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue