map-transform-cjs
Version:
MapTransform with CJS support
1 lines • 4.5 kB
Source Map (JSON)
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["// Dictionary types\n\nexport type DictionaryValue = string | number | boolean | null | undefined\n\nexport type DictionaryTuple = readonly [DictionaryValue, DictionaryValue]\nexport type Dictionary = DictionaryTuple[]\n\nexport interface Dictionaries {\n [key: string]: Dictionary\n}\n\n// State type\n\nexport interface InitialState {\n target?: unknown\n rev?: boolean\n noDefaults?: boolean\n}\n\nexport interface State extends InitialState {\n context: unknown[]\n value: unknown\n flip?: boolean\n arr?: boolean\n iterate?: boolean\n index?: number\n untouched?: boolean\n}\n\n// MapTransform options type\n\nexport interface Options {\n transformers?: {\n [key: string | symbol]: Transformer | AsyncTransformer\n }\n pipelines?: {\n [key: string | symbol]: TransformDefinition\n }\n dictionaries?: Dictionaries\n nonvalues?: unknown[]\n fwdAlias?: string\n revAlias?: string\n modifyOperationObject?: (\n operation: Record<string, unknown>,\n ) => Record<string, unknown>\n modifyGetValue?: (value: unknown, state: State, options: Options) => unknown\n}\n\n// Data mapper types\n\nexport interface DataMapper<T extends InitialState | undefined = State> {\n (data: unknown, state?: T): Promise<unknown>\n}\n\nexport interface AsyncDataMapperWithState {\n (data: unknown, state: State): Promise<unknown>\n}\n\nexport interface DataMapperWithState {\n (data: unknown, state: State): unknown\n}\n\nexport interface AsyncDataMapperWithOptions {\n (options: Options): AsyncDataMapperWithState\n}\n\nexport interface DataMapperWithOptions {\n (options: Options): DataMapperWithState\n}\n\n// Operation types\n\nexport interface StateMapper {\n (state: State): Promise<State>\n}\n\nexport interface NextStateMapper {\n (next: StateMapper): StateMapper\n}\n\nexport interface Operation {\n (options: Options): NextStateMapper\n}\n\n// Transformer types\n\nexport type TransformerProps = Record<string, unknown>\n\nexport interface Transformer<T = TransformerProps> {\n (props: T): DataMapperWithOptions\n}\n\nexport interface AsyncTransformer<T = TransformerProps> {\n (props: T): AsyncDataMapperWithOptions\n}\n\n// Transform definition types\n\nexport type Path = string\n\nexport interface TransformOperation extends TransformerProps {\n $transform:\n | string\n | symbol\n | DataMapperWithOptions\n | AsyncDataMapperWithOptions\n $iterate?: boolean\n $direction?: string\n}\n\nexport interface FilterOperation extends TransformerProps {\n $filter: string | symbol\n $direction?: string\n}\n\nexport interface IfOperation extends TransformerProps {\n $if: TransformDefinition\n $direction?: string\n then?: TransformDefinition\n else?: TransformDefinition\n}\n\nexport interface ApplyOperation extends TransformerProps {\n $apply: string | symbol\n $iterate?: boolean\n $direction?: string\n}\n\nexport interface AltOperation extends TransformerProps {\n $alt: TransformDefinition[]\n $iterate?: boolean\n $direction?: string\n $undefined?: unknown[]\n}\n\nexport interface ConcatOperation extends TransformerProps {\n $concat: TransformDefinition[]\n}\n\nexport interface ConcatRevOperation extends TransformerProps {\n $concatRev: TransformDefinition[]\n}\n\nexport interface LookupOperation extends TransformerProps {\n $lookup: Path\n path: Path\n}\n\nexport interface LookdownOperation extends TransformerProps {\n $lookdown: Path\n path: Path\n}\n\nexport type OperationObject =\n | TransformOperation\n | FilterOperation\n | IfOperation\n | ApplyOperation\n | AltOperation\n | ConcatOperation\n | ConcatRevOperation\n | LookupOperation\n | LookdownOperation\n\nexport type Pipeline = (\n | TransformObject\n | Operation\n | OperationObject\n | Path\n | Pipeline\n)[]\n\n// Note: We need to accept `unknown` on all unspecified keys, to support\n// custom Operators that may add their own $-prefixed keys.\n// We would ideally like to type all keys _not_ starting with $ as\n// `TransformDefinition | undefined | boolean`, but that's not possible as far\n// as I know.\nexport interface TransformObject extends Record<string, unknown> {\n $iterate?: boolean\n $modify?: boolean | Path\n $noDefaults?: boolean\n $flip?: boolean\n $direction?: string\n}\n\nexport type TransformDefinition =\n | TransformObject\n | Operation\n | OperationObject\n | Pipeline\n | Path\n | null\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}