@cuser/store

0.0.36 • Public • Published

cuser logo

@cuser/store

Status

codecov npm npm-downloads

Store dedicated to manage the tree changes of cuser state

Stricted mutation system

In order to prevent bad insertions in dag tree, is necessary implement a stricted validations, delegates to do jsonschema the validations in combination with reducers

@cuser/proto

Index

Variables

Functions

Object literals

Variables

GraphType

GraphType: GraphType

Defined in store/reducers/content.js:9

Defined in store/reducers/message.js:10

Defined in store/reducers/topic.js:8

Defined in store/reducers/user.js:6


TYPE_ACTION_DEFAULT

TYPE_ACTION_DEFAULT: string

Defined in store/reducers/topics.js:14


TYPE_ACTION_DELETE_MESSAGE

TYPE_ACTION_DELETE_MESSAGE: string

Defined in store/reducers/message.js:14

Defined in store/reducers/topic.js:12

Defined in store/reducers/topics.js:13


TYPE_ACTION_PUBLISH_MESSAGE

TYPE_ACTION_PUBLISH_MESSAGE: string

Defined in store/reducers/content.js:10

Defined in store/reducers/data.js:5

Defined in store/reducers/message.js:12

Defined in store/reducers/topic.js:10

Defined in store/reducers/topics.js:11

Defined in store/reducers/user.js:8


TYPE_ACTION_REHYDRATE

TYPE_ACTION_REHYDRATE: string

Defined in store/enhancers/createSerializeEnhancer.js:11


TYPE_ACTION_SEAL

TYPE_ACTION_SEAL: string

Defined in store/enhancers/createSerializeEnhancer.js:12


TYPE_ACTION_UPDATE_MESSAGE

TYPE_ACTION_UPDATE_MESSAGE: string

Defined in store/reducers/content.js:10

Defined in store/reducers/data.js:5

Defined in store/reducers/message.js:13

Defined in store/reducers/topic.js:11

Defined in store/reducers/topics.js:12


TYPE_ERROR_INVALID_ACTION

TYPE_ERROR_INVALID_ACTION: "Invalid action format for "%s""

Defined in store/utils/wrapValidatorActionReducer.js:8


TYPE_ERROR_INVALID_STATE

TYPE_ERROR_INVALID_STATE: "Invalid state format for "%s""

Defined in store/utils/wrapValidatorStateReducer.js:8


TYPE_ERROR_MISSING_PREVIOUS_STATE

TYPE_ERROR_MISSING_PREVIOUS_STATE: "Previous state does't exists"

Defined in store/reducers/content.js:11


TYPE_ERROR_MISSING_RESOURCE_ID

TYPE_ERROR_MISSING_RESOURCE_ID: "%s with id "%s" doesn't exists"

Defined in store/reducers/message.js:18

Defined in store/reducers/topics.js:17


TYPE_ERROR_USER_MUST_BE_THE_OWNER

TYPE_ERROR_USER_MUST_BE_THE_OWNER: "User must be the owner of the %s"

Defined in store/reducers/message.js:17


actions

Const actions: "/Users/rubeniskov/Workspace/cuser/packages/store/types/actions" = require('../types/actions')

Defined in store/utils/createReducer.js:4


applyMiddleware

applyMiddleware: applyMiddleware

Defined in store/createStore.js:9


assert

Const assert: assert = require('@cuser/utils/assert')

Defined in store/reducers/content.js:7

Defined in store/reducers/message.js:8

Defined in store/reducers/topics.js:8


compose

compose: compose

Defined in store/createStore.js:9


contentReducer

Const contentReducer: Reducer = createReducer({ [TYPE_ACTION_PUBLISH_MESSAGE]: () => ({ type: GraphType.GRAPH_CONTENT, parent: null, revision: '@revision', cdate: '@timestamp', data: '@data', }), [TYPE_ACTION_UPDATE_MESSAGE]: (state) => { assert(state, TYPE_ERROR_MISSING_PREVIOUS_STATE); return { ...state, parent: state, revision: '@revision', cdate: '@timestamp', data: '@data', } }})

Defined in store/reducers/content.js:23

Content reducer for manage message data and its historical revisions, when update action, the current state will be swaped to parent in order to keep the tree changes

param

param


createIterator

createIterator: any

Defined in store/enhancers/createSerializeReducer.js:9


createReduxStore

createReduxStore: StoreCreator

Defined in store/createStore.js:9


dataReducer

Const dataReducer: Reducer = createReducer({ [TYPE_ACTION_PUBLISH_MESSAGE]: (_, { payload: { content: { data } } }) => data, [TYPE_ACTION_UPDATE_MESSAGE]: (state, { payload: { content: { data } } }) => data})

Defined in store/reducers/data.js:15

Data string state

param

param


debug

Const debug: Debugger = require('debug')('cuser:store:serializer')

Defined in store/enhancers/createSerializeEnhancer.js:9


format

format: format

Defined in store/utils/wrapValidatorActionReducer.js:6

Defined in store/utils/wrapValidatorStateReducer.js:6


isAlias

Const isAlias: isAlias = require('./isAlias')

Defined in store/utils/createResolveReducer.js:8


isPromise

Const isPromise: isPromise = require('@cuser/utils/isPromise')

Defined in store/reducers/recursive.js:7


isReducer

Const isReducer: isReducer = require('./isReducer')

Defined in store/utils/createResolveReducer.js:9


loggerMiddleware

Const loggerMiddleware: loggerMiddleware = require('./middlewares/loggerMiddleware')

Defined in store/createStore.js:11


messageReducer

Const messageReducer: Reducer = createReducer({ [TYPE_ACTION_PUBLISH_MESSAGE]: (state) => ({ type: GraphType.GRAPH_MESSAGE, parent: state || null, id: '@uuid', user: '@user', content: '@content', cdate: '@timestamp', mdate: '@timestamp', }), [TYPE_ACTION_UPDATE_MESSAGE]: recursiveReducer((state, { payload }) => { const { messageId } = payload; if (state && state.id === messageId) { assert(payload.user.peerId === state.user.peerId, TYPE_ERROR_USER_MUST_BE_THE_OWNER, 'message') return { ...state, content: '@content', mdate: '@timestamp', } } else { assert(state.parent, TYPE_ERROR_MISSING_RESOURCE_ID, 'Message', messageId) } }), [TYPE_ACTION_DELETE_MESSAGE]: recursiveReducer((state, { payload }) => { const { messageId } = payload; if (state && state.id === messageId) { assert(payload.user.peerId === state.user.peerId, TYPE_ERROR_USER_MUST_BE_THE_OWNER, 'message') return state.parent } else { assert(state.parent, TYPE_ERROR_MISSING_RESOURCE_ID, 'Message', messageId) } })})

Defined in store/reducers/message.js:31

Message reducer

param

param


minimatch

Const minimatch: M = require('minimatch')

Defined in store/enhancers/createSerializeReducer.js:8


monitorReducerEnhancer

Const monitorReducerEnhancer: monitorReducerEnhancer = require('./enhancers/monitorReducerEnhancer')

Defined in store/createStore.js:10


mutantJson

Const mutantJson: any = require('mutant-json')

Defined in store/utils/createResolveReducer.js:6


mutateJson

Const mutateJson: any = require('mutant-json')

Defined in store/enhancers/createSerializeReducer.js:6

Defined in store/reducers/recursive.js:6


rootReducer

Const rootReducer: (state: any, action: AnyAction) => any = require('./reducers')

Defined in store/configureStore.js:10


tap

Const tap: any = require('mutant-json/tap')

Defined in store/enhancers/createSerializeReducer.js:7

Defined in store/utils/createResolveReducer.js:7


topicReducer

Const topicReducer: Reducer = createReducer({ [TYPE_ACTION_PUBLISH_MESSAGE]: ({ count = 0 } = {}) => ({ type: GraphType.GRAPH_TOPIC, message: '@message', count: count + 1 }), [TYPE_ACTION_UPDATE_MESSAGE]: (state) => ({ ...state, message: '@message', }), [TYPE_ACTION_DELETE_MESSAGE]: (state) => ({ ...state, message: '@message', count: state.count - 1 })})

Defined in store/reducers/topic.js:23

Topic reducer

param

param


topicsReducer

Const topicsReducer: Reducer = createReducer({ [TYPE_ACTION_PUBLISH_MESSAGE]: (state, { payload: { topicId } }) => ({ ...state, [topicId]: '@topic' }), [TYPE_ACTION_UPDATE_MESSAGE]: (state, { payload: { topicId } }) => { assert(state && state[topicId], TYPE_ERROR_MISSING_RESOURCE_ID, 'Topic', topicId); return { ...state, [topicId]: '@topic' } }, [TYPE_ACTION_DELETE_MESSAGE]: (state, { payload: { topicId } }) => { assert(state && state[topicId], TYPE_ERROR_MISSING_RESOURCE_ID, 'Topic', topicId); return { ...state, [topicId]: '@topic' } }})

Defined in store/reducers/topics.js:28

Topic reducer

param

param


userReducer

Const userReducer: Reducer = createReducer({ // @ts-ignore [TYPE_ACTION_PUBLISH_MESSAGE]: (_, { payload: { user: { avatar, username, peerId } } = {} }) => ({ type: GraphType.GRAPH_USER, username, peerId, avatar })})

Defined in store/reducers/user.js:18

User reducer

param

param


validator

Const validator: createValidator = require('@cuser/validator')

Defined in store/utils/wrapValidatorActionReducer.js:5

Defined in store/utils/wrapValidatorStateReducer.js:5

Functions

configureStore

ConstconfigureStore(preloadedState: string | {} | Promise<string | {}>, opts: CuserSerializeEnhancerOptions): CuserStore

Defined in store/configureStore.js:21

Parameters:

Name Type
preloadedState string | {} | Promise<string | {}>
opts CuserSerializeEnhancerOptions

Returns: CuserStore


createReducer

ConstcreateReducer(mutations: Record<string, Reducer<any, AnyAction>>): Reducer<any, AnyAction>

Defined in store/utils/createReducer.js:12

Parameters:

Name Type
mutations Record<string, Reducer<any, AnyAction>>

Returns: Reducer<any, AnyAction>


createRehydrateReducer

ConstcreateRehydrateReducer(__namedParameters: { deserialize: (state: string) => Promise<any> ; deserializable: () => true }): rehydrateReducer

Defined in store/enhancers/createSerializeEnhancer.js:77

Parameters:

Name Type
__namedParameters { deserialize: (state: string) => Promise<any> ; deserializable: () => true }

Returns: rehydrateReducer


createResolveReducer

ConstcreateResolveReducer(rootReducer: Reducer<any, AnyAction>, opts: any): resolveReducer

Defined in store/utils/createResolveReducer.js:24

Parameters:

Name Type
rootReducer Reducer<any, AnyAction>
opts any

Returns: resolveReducer


createSealReducer

ConstcreateSealReducer(__namedParameters: { serialize: (state: any) => Promise<string> ; serializable: () => true }): sealReducer

Defined in store/enhancers/createSerializeEnhancer.js:94

Parameters:

Name Type
__namedParameters { serialize: (state: any) => Promise<string> ; serializable: () => true }

Returns: sealReducer


createSerializeEnhancer

ConstcreateSerializeEnhancer(patterns: string[], opts: CuserSerializeEnhancerOptions): (Anonymous function)

Defined in store/enhancers/createSerializeEnhancer.js:112

Parameters:

Name Type Description
patterns string[]
opts CuserSerializeEnhancerOptions

Returns: (Anonymous function)


createSerializeReducer

ConstcreateSerializeReducer(reducer: Reducer<any, AnyAction>, patterns: string[], opts: CuserStoreSerializeReducerOptions): serializeReducer

Defined in store/enhancers/createSerializeReducer.js:24

Parameters:

Name Type
reducer Reducer<any, AnyAction>
patterns string[]
opts CuserStoreSerializeReducerOptions

Returns: serializeReducer


createStore

ConstcreateStore(rootReducer: Reducer<any, AnyAction>, preloadedState: any, enhancer: Function): CuserStore

Defined in store/createStore.js:32

Parameters:

Name Type
rootReducer Reducer<any, AnyAction>
preloadedState any
enhancer Function

Returns: CuserStore


parseAliasReducer

ConstparseAliasReducer(reducer: any): any[]

Defined in store/utils/createResolveReducer.js:11

Parameters:

Name Type
reducer any

Returns: any[]


parseMapping

ConstparseMapping(mapping: string | any[]): any[]

Defined in store/utils/parseMapping.js:7

Parameters:

Name Type
mapping string | any[]

Returns: any[]


recursiveReducer

ConstrecursiveReducer(reducer: Reducer<any, AnyAction>, opts: any): (Anonymous function)

Defined in store/reducers/recursive.js:14

Creates a recursive reducer for a certain key by, default parent

Parameters:

Name Type Description
reducer Reducer<any, AnyAction>
opts any

Returns: (Anonymous function)


wrapReducerAction

ConstwrapReducerAction(schema: any, reducer?: Reducer<any, AnyAction>): actionValidateReducer

Defined in store/utils/wrapValidatorActionReducer.js:16

Creates a state validator reducer

Parameters:

Name Type Default value Description
schema any -
reducer Reducer<any, AnyAction> (state, action) => state

Returns: actionValidateReducer


wrapValidatorStateReducer

ConstwrapValidatorStateReducer(schema: any, reducer?: Reducer<any, AnyAction>): stateValidateReducer

Defined in store/utils/wrapValidatorStateReducer.js:16

Creates a state validator reducer

Parameters:

Name Type Default value Description
schema any -
reducer Reducer<any, AnyAction> (state, action) => state

Returns: stateValidateReducer

Object literals

phases

Const phases: object

Defined in store/enhancers/createSerializeEnhancer.js:16

Properties:

Name Type Value
IDLE number 0
REHYDRATING number 2
SEALING number 1

Readme

Keywords

none

Package Sidebar

Install

npm i @cuser/store

Weekly Downloads

1

Version

0.0.36

License

ISC

Unpacked Size

73.9 kB

Total Files

68

Last publish

Collaborators

  • rubeniskov