map-transform 0.3.12 → 0.4.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +573 -98
- package/dist/functions/compare.d.ts +6 -5
- package/dist/functions/compare.js +21 -16
- package/dist/functions/compare.js.map +1 -1
- package/dist/functions/explode.d.ts +6 -0
- package/dist/functions/explode.js +45 -0
- package/dist/functions/explode.js.map +1 -0
- package/dist/functions/get.d.ts +2 -2
- package/dist/functions/get.js +4 -2
- package/dist/functions/get.js.map +1 -1
- package/dist/functions/index.d.ts +13 -5
- package/dist/functions/index.js +14 -6
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/join.d.ts +2 -2
- package/dist/functions/join.js +1 -1
- package/dist/functions/join.js.map +1 -1
- package/dist/functions/joinSplit.d.ts +8 -0
- package/dist/functions/joinSplit.js +33 -0
- package/dist/functions/joinSplit.js.map +1 -0
- package/dist/functions/logical.d.ts +7 -0
- package/dist/functions/logical.js +28 -0
- package/dist/functions/logical.js.map +1 -0
- package/dist/functions/map.d.ts +8 -0
- package/dist/functions/map.js +43 -0
- package/dist/functions/map.js.map +1 -0
- package/dist/functions/not.d.ts +2 -2
- package/dist/functions/not.js.map +1 -1
- package/dist/functions/template.d.ts +7 -0
- package/dist/functions/template.js +29 -0
- package/dist/functions/template.js.map +1 -0
- package/dist/functions/validate.d.ts +2 -2
- package/dist/functions/validate.js +1 -1
- package/dist/functions/validate.js.map +1 -1
- package/dist/functions/value.d.ts +4 -0
- package/dist/functions/value.js +20 -0
- package/dist/functions/value.js.map +1 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +29 -12
- package/dist/index.js.map +1 -1
- package/dist/operations/alt.js +4 -9
- package/dist/operations/alt.js.map +1 -1
- package/dist/operations/apply.d.ts +2 -0
- package/dist/operations/apply.js +15 -0
- package/dist/operations/apply.js.map +1 -0
- package/dist/operations/concat.js +4 -4
- package/dist/operations/concat.js.map +1 -1
- package/dist/operations/directionals.d.ts +1 -1
- package/dist/operations/directionals.js +5 -5
- package/dist/operations/directionals.js.map +1 -1
- package/dist/operations/filter.d.ts +2 -2
- package/dist/operations/filter.js +6 -3
- package/dist/operations/filter.js.map +1 -1
- package/dist/operations/fixed.d.ts +2 -2
- package/dist/operations/fixed.js +5 -1
- package/dist/operations/fixed.js.map +1 -1
- package/dist/operations/getSet.js +17 -24
- package/dist/operations/getSet.js.map +1 -1
- package/dist/operations/ifelse.d.ts +2 -0
- package/dist/operations/ifelse.js +18 -0
- package/dist/operations/ifelse.js.map +1 -0
- package/dist/operations/iterate.d.ts +2 -0
- package/dist/operations/iterate.js +23 -0
- package/dist/operations/iterate.js.map +1 -0
- package/dist/operations/lookup.js +3 -3
- package/dist/operations/lookup.js.map +1 -1
- package/dist/operations/merge.d.ts +2 -0
- package/dist/operations/merge.js +20 -0
- package/dist/operations/merge.js.map +1 -0
- package/dist/operations/modify.d.ts +2 -0
- package/dist/operations/modify.js +18 -0
- package/dist/operations/modify.js.map +1 -0
- package/dist/operations/mutate.js +48 -8
- package/dist/operations/mutate.js.map +1 -1
- package/dist/operations/pipe.js +9 -5
- package/dist/operations/pipe.js.map +1 -1
- package/dist/operations/plug.js +1 -1
- package/dist/operations/plug.js.map +1 -1
- package/dist/operations/root.js +2 -2
- package/dist/operations/root.js.map +1 -1
- package/dist/operations/transform.js +2 -2
- package/dist/operations/transform.js.map +1 -1
- package/dist/operations/value.d.ts +2 -2
- package/dist/operations/value.js +5 -1
- package/dist/operations/value.js.map +1 -1
- package/dist/types.d.ts +46 -21
- package/dist/utils/definitionHelpers.d.ts +7 -8
- package/dist/utils/definitionHelpers.js +60 -43
- package/dist/utils/definitionHelpers.js.map +1 -1
- package/dist/utils/functional.d.ts +2 -0
- package/dist/utils/functional.js +8 -0
- package/dist/utils/functional.js.map +1 -0
- package/dist/utils/is.d.ts +1 -0
- package/dist/utils/is.js +6 -0
- package/dist/utils/is.js.map +1 -0
- package/dist/utils/pathGetter.d.ts +2 -2
- package/dist/utils/pathGetter.js +23 -9
- package/dist/utils/pathGetter.js.map +1 -1
- package/dist/utils/pathSetter.d.ts +3 -3
- package/dist/utils/pathSetter.js +19 -22
- package/dist/utils/pathSetter.js.map +1 -1
- package/dist/utils/stateHelpers.d.ts +7 -36
- package/dist/utils/stateHelpers.js +21 -11
- package/dist/utils/stateHelpers.js.map +1 -1
- package/package.json +17 -54
- package/dist/functions/alt.d.ts +0 -6
- package/dist/functions/alt.js +0 -10
- package/dist/functions/alt.js.map +0 -1
- package/dist/functions/exclude.d.ts +0 -7
- package/dist/functions/exclude.js +0 -16
- package/dist/functions/exclude.js.map +0 -1
- package/dist/utils/objectToMapFunction.d.ts +0 -2
- package/dist/utils/objectToMapFunction.js +0 -34
- package/dist/utils/objectToMapFunction.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipe.js","sourceRoot":"","sources":["../../src/operations/pipe.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"pipe.js","sourceRoot":"","sources":["../../src/operations/pipe.ts"],"names":[],"mappings":";;AACA,oDAA6D;AAC7D,wDAAyD;AACzD,kEAA+D;AAE/D,MAAM,SAAS,GAAG,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC;IACnC,GAAG,KAAK;IACR,OAAO,EAAE,KAAK,CAAC,KAAK;CACrB,CAAC,CAAA;AAEF,SAAwB,IAAI,CAAC,IAAa;IACxC,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,sCAAkB,EAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAA;QAC/D,MAAM,OAAO,GAAG,IAAA,iBAAM,EAAC,GAAG,GAAG,CAAC,CAAA;QAC9B,MAAM,UAAU,GAAG,IAAA,oBAAO,EAAC,GAAG,GAAG,CAAC,CAAA;QAElC,OAAO,CAAC,KAAK,EAAE,EAAE,CACf,IAAA,gCAAiB,EACf,KAAK,EACL,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CACrE,CAAA;IACL,CAAC,CAAA;AACH,CAAC;AAZD,uBAYC"}
|
package/dist/operations/plug.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const stateHelpers_1 = require("../utils/stateHelpers");
|
|
4
4
|
function plug() {
|
|
5
|
-
return () => (state) => stateHelpers_1.setStateValue(state, undefined);
|
|
5
|
+
return () => (state) => (0, stateHelpers_1.setStateValue)(state, undefined);
|
|
6
6
|
}
|
|
7
7
|
exports.default = plug;
|
|
8
8
|
//# sourceMappingURL=plug.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plug.js","sourceRoot":"","sources":["../../src/operations/plug.ts"],"names":[],"mappings":";;AACA,wDAAqD;AAErD,SAAwB,IAAI;IAC1B,OAAO,GAAG,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"plug.js","sourceRoot":"","sources":["../../src/operations/plug.ts"],"names":[],"mappings":";;AACA,wDAAqD;AAErD,SAAwB,IAAI;IAC1B,OAAO,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,4BAAa,EAAC,KAAK,EAAE,SAAS,CAAC,CAAA;AACzD,CAAC;AAFD,uBAEC"}
|
package/dist/operations/root.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const definitionHelpers_1 = require("../utils/definitionHelpers");
|
|
4
4
|
function default_1(def) {
|
|
5
5
|
return (options) => {
|
|
6
|
-
const pipeline = definitionHelpers_1.mapFunctionFromDef(def
|
|
7
|
-
return (state) => pipeline(
|
|
6
|
+
const pipeline = (0, definitionHelpers_1.mapFunctionFromDef)(def)(options);
|
|
7
|
+
return (state) => pipeline({ ...state, value: state.root });
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
exports.default = default_1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.js","sourceRoot":"","sources":["../../src/operations/root.ts"],"names":[],"mappings":";;AACA,kEAA+D;AAE/D,mBAAyB,GAAkB;IACzC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"root.js","sourceRoot":"","sources":["../../src/operations/root.ts"],"names":[],"mappings":";;AACA,kEAA+D;AAE/D,mBAAyB,GAAkB;IACzC,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,QAAQ,GAAG,IAAA,sCAAkB,EAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAA;QAEjD,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;IAC7D,CAAC,CAAA;AACH,CAAC;AAND,4BAMC"}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ramda_1 = require("ramda");
|
|
4
4
|
const stateHelpers_1 = require("../utils/stateHelpers");
|
|
5
|
-
const callTransformFn = (fn) => (state) => stateHelpers_1.setStateValue(state, fn(stateHelpers_1.getStateValue(state), stateHelpers_1.contextFromState(state)));
|
|
5
|
+
const callTransformFn = (fn) => (state) => (0, stateHelpers_1.setStateValue)(state, fn((0, stateHelpers_1.getStateValue)(state), (0, stateHelpers_1.contextFromState)(state)));
|
|
6
6
|
function transform(fn, revFn) {
|
|
7
7
|
const fwdTransform = typeof fn === 'function' ? callTransformFn(fn) : ramda_1.identity;
|
|
8
8
|
const revTransform = typeof revFn === 'function' ? callTransformFn(revFn) : fwdTransform;
|
|
9
|
-
return () => state =>
|
|
9
|
+
return (_options) => (state) => state.rev ? revTransform(state) : fwdTransform(state);
|
|
10
10
|
}
|
|
11
11
|
exports.default = transform;
|
|
12
12
|
//# sourceMappingURL=transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/operations/transform.ts"],"names":[],"mappings":";;AAAA,iCAAgC;AAEhC,wDAI8B;AAE9B,MAAM,eAAe,GAAG,CAAC,EAAc,EAAE,EAAE,CAAC,CAAC,KAAY,EAAE,EAAE,CAC3D,4BAAa,
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/operations/transform.ts"],"names":[],"mappings":";;AAAA,iCAAgC;AAEhC,wDAI8B;AAE9B,MAAM,eAAe,GAAG,CAAC,EAAc,EAAE,EAAE,CAAC,CAAC,KAAY,EAAE,EAAE,CAC3D,IAAA,4BAAa,EAAC,KAAK,EAAE,EAAE,CAAC,IAAA,4BAAa,EAAC,KAAK,CAAC,EAAE,IAAA,+BAAgB,EAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAEzE,SAAwB,SAAS,CAC/B,EAAc,EACd,KAAkB;IAElB,MAAM,YAAY,GAAG,OAAO,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,gBAAQ,CAAA;IAC9E,MAAM,YAAY,GAChB,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAA;IAErE,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,CAC7B,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;AACzD,CAAC;AAVD,4BAUC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function value(val:
|
|
1
|
+
import { Operation } from '../types';
|
|
2
|
+
export default function value(val: unknown): Operation;
|
package/dist/operations/value.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const value_1 = require("../functions/value");
|
|
3
4
|
function value(val) {
|
|
4
|
-
return () => (state) => (
|
|
5
|
+
return () => (state) => ({
|
|
6
|
+
...state,
|
|
7
|
+
value: state.onlyMapped ? undefined : (0, value_1.extractValue)(val),
|
|
8
|
+
});
|
|
5
9
|
}
|
|
6
10
|
exports.default = value;
|
|
7
11
|
//# sourceMappingURL=value.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../src/operations/value.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../src/operations/value.ts"],"names":[],"mappings":";;AACA,8CAAiD;AAEjD,SAAwB,KAAK,CAAC,GAAY;IACxC,OAAO,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvB,GAAG,KAAK;QACR,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,oBAAY,EAAC,GAAG,CAAC;KACxD,CAAC,CAAA;AACJ,CAAC;AALD,wBAKC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,43 +1,64 @@
|
|
|
1
|
-
export interface ObjectWithProps {
|
|
2
|
-
[key: string]: Data;
|
|
3
|
-
}
|
|
4
|
-
export declare type Prop = string | number | boolean | object | null | undefined | ObjectWithProps;
|
|
5
|
-
export declare type Data = Prop | Prop[];
|
|
6
1
|
export declare type Path = string;
|
|
2
|
+
export declare type DictionaryValue = string | number | boolean | null | undefined;
|
|
3
|
+
export declare type DictionaryTuple = readonly [DictionaryValue, DictionaryValue];
|
|
4
|
+
export declare type Dictionary = DictionaryTuple[];
|
|
5
|
+
export interface Dictionaries {
|
|
6
|
+
[key: string]: Dictionary;
|
|
7
|
+
}
|
|
8
|
+
export interface ValueFunction {
|
|
9
|
+
(): any;
|
|
10
|
+
}
|
|
7
11
|
export interface Operands {
|
|
8
|
-
[key: string]:
|
|
12
|
+
[key: string]: any | ValueFunction;
|
|
9
13
|
}
|
|
10
14
|
export interface Context {
|
|
11
15
|
rev: boolean;
|
|
12
16
|
onlyMappedValues: boolean;
|
|
13
17
|
}
|
|
14
|
-
export interface DataMapper
|
|
15
|
-
(data:
|
|
18
|
+
export interface DataMapper {
|
|
19
|
+
(data: unknown, context: Context): any;
|
|
16
20
|
}
|
|
17
|
-
export interface CustomFunction<T = Operands
|
|
18
|
-
(operands: T): DataMapper
|
|
19
|
-
}
|
|
20
|
-
export interface CustomFunctions {
|
|
21
|
-
[key: string]: CustomFunction;
|
|
21
|
+
export interface CustomFunction<T = Operands> {
|
|
22
|
+
(operands: T, options: Options): DataMapper;
|
|
22
23
|
}
|
|
23
24
|
export interface State {
|
|
24
|
-
root:
|
|
25
|
-
context:
|
|
26
|
-
value:
|
|
25
|
+
root: unknown;
|
|
26
|
+
context: unknown;
|
|
27
|
+
value: unknown;
|
|
27
28
|
rev?: boolean;
|
|
28
29
|
onlyMapped?: boolean;
|
|
29
30
|
arr?: boolean;
|
|
30
31
|
}
|
|
31
32
|
export interface Options {
|
|
32
|
-
|
|
33
|
+
functions?: {
|
|
34
|
+
[key: string]: CustomFunction;
|
|
35
|
+
};
|
|
36
|
+
pipelines?: {
|
|
37
|
+
[key: string]: MapDefinition;
|
|
38
|
+
};
|
|
39
|
+
dictionaries?: Dictionaries;
|
|
40
|
+
mutateNull?: boolean;
|
|
33
41
|
}
|
|
34
42
|
export interface TransformObject extends Operands {
|
|
35
43
|
$transform: string;
|
|
44
|
+
$iterate?: boolean;
|
|
45
|
+
$direction?: string;
|
|
36
46
|
}
|
|
37
47
|
export interface FilterObject extends Operands {
|
|
38
48
|
$filter: string;
|
|
49
|
+
$direction?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface ApplyObject extends Operands {
|
|
52
|
+
$apply: string;
|
|
53
|
+
$iterate?: boolean;
|
|
54
|
+
$direction?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface AltObject extends Operands {
|
|
57
|
+
$alt: string;
|
|
58
|
+
$iterate?: boolean;
|
|
59
|
+
$direction?: string;
|
|
39
60
|
}
|
|
40
|
-
export declare type OperationObject = TransformObject | FilterObject;
|
|
61
|
+
export declare type OperationObject = TransformObject | FilterObject | ApplyObject | AltObject;
|
|
41
62
|
export interface StateMapper {
|
|
42
63
|
(state: State): State;
|
|
43
64
|
}
|
|
@@ -50,14 +71,18 @@ export interface MapFunction {
|
|
|
50
71
|
declare type MapPipeSimple = (MapObject | Operation | OperationObject | Path)[];
|
|
51
72
|
export declare type MapPipe = (MapObject | Operation | OperationObject | Path | MapPipeSimple)[];
|
|
52
73
|
export interface MapObject {
|
|
53
|
-
[key: string]: MapDefinition | undefined;
|
|
74
|
+
[key: string]: MapDefinition | undefined | boolean;
|
|
75
|
+
$iterate?: boolean;
|
|
76
|
+
$flip?: boolean;
|
|
54
77
|
$transform?: undefined;
|
|
55
78
|
$filter?: undefined;
|
|
79
|
+
$apply?: undefined;
|
|
80
|
+
$alt?: undefined;
|
|
56
81
|
}
|
|
57
82
|
export declare type MapDefinition = MapObject | Operation | OperationObject | MapPipe | Path | null;
|
|
58
83
|
export interface MapTransformWithOnlyMappedValues {
|
|
59
|
-
(data:
|
|
60
|
-
onlyMappedValues: (data:
|
|
84
|
+
(data: unknown): any;
|
|
85
|
+
onlyMappedValues: (data: unknown) => any;
|
|
61
86
|
}
|
|
62
87
|
export interface MapTransform extends MapTransformWithOnlyMappedValues {
|
|
63
88
|
rev: MapTransformWithOnlyMappedValues;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Operation,
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const hasFilterProp: (def: MapObject | OperationObject) => def is FilterObject;
|
|
1
|
+
import { Operation, MapDefinition, MapObject, MapPipe, OperationObject } from '../types';
|
|
2
|
+
export declare const isOperationType: <T extends OperationObject>(def: MapObject | OperationObject, prop: string) => def is T;
|
|
4
3
|
export declare const hasOperationProps: (def: MapObject | OperationObject) => def is OperationObject;
|
|
5
|
-
export declare const isPath: (def:
|
|
6
|
-
export declare const isMapObject: (def:
|
|
7
|
-
export declare const isMapPipe: (def:
|
|
8
|
-
export declare const isOperation: (def:
|
|
9
|
-
export declare const mapFunctionFromDef: (def
|
|
4
|
+
export declare const isPath: (def: unknown) => def is string;
|
|
5
|
+
export declare const isMapObject: (def: unknown) => def is MapObject;
|
|
6
|
+
export declare const isMapPipe: (def: unknown) => def is MapPipe;
|
|
7
|
+
export declare const isOperation: (def: unknown) => def is Operation;
|
|
8
|
+
export declare const mapFunctionFromDef: (def?: MapDefinition | undefined) => Operation;
|
|
@@ -1,61 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.mapFunctionFromDef = exports.isOperation = exports.isMapPipe = exports.isMapObject = exports.isPath = exports.hasOperationProps = exports.
|
|
3
|
+
exports.mapFunctionFromDef = exports.isOperation = exports.isMapPipe = exports.isMapObject = exports.isPath = exports.hasOperationProps = exports.isOperationType = void 0;
|
|
15
4
|
const ramda_1 = require("ramda");
|
|
16
5
|
const getSet_1 = require("../operations/getSet");
|
|
17
6
|
const mutate_1 = require("../operations/mutate");
|
|
7
|
+
const iterate_1 = require("../operations/iterate");
|
|
18
8
|
const pipe_1 = require("../operations/pipe");
|
|
19
9
|
const transform_1 = require("../operations/transform");
|
|
20
10
|
const filter_1 = require("../operations/filter");
|
|
11
|
+
const apply_1 = require("../operations/apply");
|
|
12
|
+
const alt_1 = require("../operations/alt");
|
|
13
|
+
const directionals_1 = require("../operations/directionals");
|
|
14
|
+
const altOperation = (fn) => (0, alt_1.default)((0, transform_1.default)(fn));
|
|
21
15
|
const isObject = (def) => typeof def === 'object' && def !== null && !Array.isArray(def);
|
|
22
|
-
|
|
23
|
-
exports.
|
|
24
|
-
|
|
25
|
-
exports.
|
|
26
|
-
exports.
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
16
|
+
const isOperationType = (def, prop) => typeof def[prop] !== 'undefined';
|
|
17
|
+
exports.isOperationType = isOperationType;
|
|
18
|
+
const hasOperationProps = (def) => (0, exports.isOperationType)(def, '$transform') ||
|
|
19
|
+
(0, exports.isOperationType)(def, '$filter') ||
|
|
20
|
+
(0, exports.isOperationType)(def, '$apply') ||
|
|
21
|
+
(0, exports.isOperationType)(def, '$alt');
|
|
22
|
+
exports.hasOperationProps = hasOperationProps;
|
|
23
|
+
const isPath = (def) => typeof def === 'string';
|
|
24
|
+
exports.isPath = isPath;
|
|
25
|
+
const isMapObject = (def) => isObject(def) && !(0, exports.hasOperationProps)(def);
|
|
26
|
+
exports.isMapObject = isMapObject;
|
|
27
|
+
const isMapPipe = (def) => Array.isArray(def);
|
|
28
|
+
exports.isMapPipe = isMapPipe;
|
|
29
|
+
const isOperation = (def) => typeof def === 'function';
|
|
30
|
+
exports.isOperation = isOperation;
|
|
31
|
+
const iterateIf = (fn, should) => should ? (0, iterate_1.default)(fn) : fn;
|
|
32
|
+
const wrapFromDefinition = (fn, def) => {
|
|
33
|
+
const fnIterated = iterateIf(fn, def.$iterate === true);
|
|
34
|
+
return def.$direction === 'rev'
|
|
35
|
+
? (0, directionals_1.rev)(fnIterated)
|
|
36
|
+
: def.$direction === 'fwd'
|
|
37
|
+
? (0, directionals_1.fwd)(fnIterated)
|
|
38
|
+
: fnIterated;
|
|
39
|
+
};
|
|
40
|
+
const createOperation = (operationFn, fnProp, def) => (options) => {
|
|
41
|
+
const { [fnProp]: fnId, ...operands } = def;
|
|
42
|
+
const fn = options.functions && options.functions[fnId];
|
|
43
|
+
return typeof fn === 'function'
|
|
44
|
+
? wrapFromDefinition(operationFn(fn(operands, options)), def)(options)
|
|
39
45
|
: ramda_1.identity;
|
|
40
46
|
};
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
const createApplyOperation = (operationFn, def) => {
|
|
48
|
+
const pipelineId = def.$apply;
|
|
49
|
+
return wrapFromDefinition(operationFn(pipelineId), def);
|
|
50
|
+
};
|
|
51
|
+
const operationFromObject = (def) => {
|
|
52
|
+
if ((0, exports.isOperationType)(def, '$transform')) {
|
|
53
|
+
return createOperation(transform_1.default, '$transform', def);
|
|
54
|
+
}
|
|
55
|
+
else if ((0, exports.isOperationType)(def, '$filter')) {
|
|
56
|
+
return createOperation(filter_1.default, '$filter', def);
|
|
57
|
+
}
|
|
58
|
+
else if ((0, exports.isOperationType)(def, '$apply')) {
|
|
59
|
+
return createApplyOperation(apply_1.default, def);
|
|
44
60
|
}
|
|
45
|
-
else if (exports.
|
|
46
|
-
return createOperation(
|
|
61
|
+
else if ((0, exports.isOperationType)(def, '$alt')) {
|
|
62
|
+
return createOperation(altOperation, '$alt', def);
|
|
47
63
|
}
|
|
48
64
|
else {
|
|
49
|
-
return mutate_1.default(def)
|
|
65
|
+
return (0, mutate_1.default)(def);
|
|
50
66
|
}
|
|
51
67
|
};
|
|
52
|
-
|
|
53
|
-
? pipe_1.default(def)
|
|
68
|
+
const mapFunctionFromDef = (def) => (0, exports.isMapPipe)(def)
|
|
69
|
+
? (0, pipe_1.default)(def)
|
|
54
70
|
: isObject(def)
|
|
55
|
-
? operationFromObject(def
|
|
56
|
-
: exports.isPath(def)
|
|
57
|
-
? getSet_1.get(def)
|
|
58
|
-
: exports.isOperation(def)
|
|
59
|
-
? def
|
|
60
|
-
: ramda_1.identity;
|
|
71
|
+
? operationFromObject(def)
|
|
72
|
+
: (0, exports.isPath)(def)
|
|
73
|
+
? (0, getSet_1.get)(def)
|
|
74
|
+
: (0, exports.isOperation)(def)
|
|
75
|
+
? def
|
|
76
|
+
: (_options) => ramda_1.identity;
|
|
77
|
+
exports.mapFunctionFromDef = mapFunctionFromDef;
|
|
61
78
|
//# sourceMappingURL=definitionHelpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitionHelpers.js","sourceRoot":"","sources":["../../src/utils/definitionHelpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"definitionHelpers.js","sourceRoot":"","sources":["../../src/utils/definitionHelpers.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAehC,iDAA0C;AAC1C,iDAAyC;AACzC,mDAA2C;AAC3C,6CAAqC;AACrC,uDAA+C;AAC/C,iDAAyC;AACzC,+CAAuC;AACvC,2CAAmC;AACnC,6DAAqD;AAErD,MAAM,YAAY,GAAG,CAAC,EAAc,EAAE,EAAE,CAAC,IAAA,aAAG,EAAC,IAAA,mBAAS,EAAC,EAAE,CAAC,CAAC,CAAA;AAE3D,MAAM,QAAQ,GAAG,CAAC,GAAY,EAAsC,EAAE,CACpE,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;AAEzD,MAAM,eAAe,GAAG,CAC7B,GAAgC,EAChC,IAAY,EACF,EAAE,CAAC,OAAO,GAAG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AAG,EAAE,QAAQ,CAAC,EAAE;QACtD,OAAO,oBAAoB,CAAC,eAAK,EAAE,GAAG,CAAC,CAAA;KACxC;SAAM,IAAI,IAAA,uBAAe,EAAY,GAAG,EAAE,MAAM,CAAC,EAAE;QAClD,OAAO,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;KAClD;SAAM;QACL,OAAO,IAAA,gBAAM,EAAC,GAAG,CAAC,CAAA;KACnB;AACH,CAAC,CAAA;AAEM,MAAM,kBAAkB,GAAG,CAAC,GAAmB,EAAa,EAAE,CACnE,IAAA,iBAAS,EAAC,GAAG,CAAC;IACZ,CAAC,CAAC,IAAA,cAAI,EAAC,GAAG,CAAC;IACX,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;QACf,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC;QAC1B,CAAC,CAAC,IAAA,cAAM,EAAC,GAAG,CAAC;YACb,CAAC,CAAC,IAAA,YAAG,EAAC,GAAG,CAAC;YACV,CAAC,CAAC,IAAA,mBAAW,EAAC,GAAG,CAAC;gBAClB,CAAC,CAAC,GAAG;gBACL,CAAC,CAAC,CAAC,QAAiB,EAAE,EAAE,CAAC,gBAAQ,CAAA;AATxB,QAAA,kBAAkB,sBASM"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pipe = exports.compose = void 0;
|
|
4
|
+
const compose = (...fns) => fns.reduceRight((f, g) => (...args) => g(f(...args)));
|
|
5
|
+
exports.compose = compose;
|
|
6
|
+
const pipe = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
|
|
7
|
+
exports.pipe = pipe;
|
|
8
|
+
//# sourceMappingURL=functional.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functional.js","sourceRoot":"","sources":["../../src/utils/functional.ts"],"names":[],"mappings":";;;AAIO,MAAM,OAAO,GAAG,CAAI,GAAG,GAAoB,EAAiB,EAAE,CACnE,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;AAD1C,QAAA,OAAO,WACmC;AAEhD,MAAM,IAAI,GAAG,CAAI,GAAG,GAAoB,EAAiB,EAAE,CAChE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;AADrC,QAAA,IAAI,QACiC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isObject: (value: unknown) => value is Record<string, unknown>;
|
package/dist/utils/is.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is.js","sourceRoot":"","sources":["../../src/utils/is.ts"],"names":[],"mappings":";;;AAAO,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CAC3E,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAAA;AADhD,QAAA,QAAQ,YACwC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare type GetFunction = (object?:
|
|
1
|
+
import { Path } from '../types';
|
|
2
|
+
export declare type GetFunction = (object?: unknown) => any;
|
|
3
3
|
export default function pathGetter(path: Path | null): GetFunction;
|
package/dist/utils/pathGetter.js
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const R = require("ramda");
|
|
4
|
+
const definitionHelpers_1 = require("./definitionHelpers");
|
|
5
|
+
const is_1 = require("../utils/is");
|
|
4
6
|
const numberOrString = (val) => {
|
|
5
7
|
const num = Number.parseInt(val, 10);
|
|
6
|
-
return
|
|
8
|
+
return Number.isNaN(num) ? val : num;
|
|
7
9
|
};
|
|
8
|
-
const split = (str) => str
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
10
|
+
const split = (str) => str
|
|
11
|
+
.split(/\[|]?\.|]/)
|
|
12
|
+
.filter((str) => str !== '')
|
|
13
|
+
.map(numberOrString);
|
|
14
|
+
const getProp = (prop) => (object) => (0, is_1.isObject)(object) ? object[prop] : undefined;
|
|
15
|
+
const getArrayIndex = (index) => (arr) => Array.isArray(arr) ? arr[index] : undefined;
|
|
16
|
+
const getObjectOrArray = (fn) => (object) => Array.isArray(object) ? R.flatten(object.map(fn)) : fn(object);
|
|
17
|
+
const getter = (prop) => typeof prop === 'number'
|
|
18
|
+
? getArrayIndex(prop)
|
|
19
|
+
: getObjectOrArray(getProp(prop));
|
|
13
20
|
const getGetters = R.compose(R.ifElse(R.isEmpty, R.always(R.identity), R.apply(R.pipe)), R.map(getter), split);
|
|
21
|
+
const ensureArray = (value) => Array.isArray(value)
|
|
22
|
+
? value
|
|
23
|
+
: value === null || typeof value === 'undefined'
|
|
24
|
+
? []
|
|
25
|
+
: [value];
|
|
14
26
|
function pathGetter(path) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
if ((0, definitionHelpers_1.isPath)(path)) {
|
|
28
|
+
const fn = getGetters(path);
|
|
29
|
+
return path.includes('[]') ? R.compose(ensureArray, fn) : fn;
|
|
30
|
+
}
|
|
31
|
+
return R.identity;
|
|
18
32
|
}
|
|
19
33
|
exports.default = pathGetter;
|
|
20
34
|
//# sourceMappingURL=pathGetter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathGetter.js","sourceRoot":"","sources":["../../src/utils/pathGetter.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"pathGetter.js","sourceRoot":"","sources":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,IAAI,KAAK,QAAQ;IACtB,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC;IACrB,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;AAErC,MAAM,UAAU,GAAG,CAAC,CAAC,OAAO,CAC1B,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAC1D,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EACb,KAAK,CACN,CAAA;AAED,MAAM,WAAW,GAAG,CAAC,KAAc,EAAE,EAAE,CACrC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;IAClB,CAAC,CAAC,KAAK;IACP,CAAC,CAAC,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,WAAW;QAChD,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;AAab,SAAwB,UAAU,CAAC,IAAiB;IAClD,IAAI,IAAA,0BAAM,EAAC,IAAI,CAAC,EAAE;QAChB,MAAM,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;QAC3B,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;KAC7D;IACD,OAAO,CAAC,CAAC,QAAQ,CAAA;AACnB,CAAC;AAND,6BAMC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare
|
|
3
|
-
export declare type SetFunction = (value:
|
|
1
|
+
import { Path } from '../types';
|
|
2
|
+
export declare function mergeExisting<T, U>(left: T[], right: U | U[]): U | (U | T | (U & T))[];
|
|
3
|
+
export declare type SetFunction = (value: unknown, object?: unknown) => any;
|
|
4
4
|
export default function pathSetter(path: Path): SetFunction;
|
package/dist/utils/pathSetter.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.mergeExisting = void 0;
|
|
4
4
|
const ramda_1 = require("ramda");
|
|
5
|
+
const functional_1 = require("./functional");
|
|
5
6
|
const preparePathPart = (part, isAfterOpenArray) => isAfterOpenArray ? `]${part}` : part;
|
|
6
7
|
const pathSplitter = function* (path) {
|
|
7
8
|
const regEx = /([^[\].]+|\[\w*])/g;
|
|
@@ -16,8 +17,10 @@ const pathSplitter = function* (path) {
|
|
|
16
17
|
} while (match !== null);
|
|
17
18
|
};
|
|
18
19
|
const split = (path) => [...pathSplitter(path)];
|
|
19
|
-
const setOnObject = (prop) => (value) => ({
|
|
20
|
-
|
|
20
|
+
const setOnObject = (prop) => (value) => ({
|
|
21
|
+
[prop]: value,
|
|
22
|
+
});
|
|
23
|
+
const setOnOpenArray = (value) => Array.isArray(value) ? value : typeof value === 'undefined' ? [] : [value];
|
|
21
24
|
const setOnArrayIndex = (index, value) => {
|
|
22
25
|
const arr = [];
|
|
23
26
|
arr[index] = value;
|
|
@@ -38,31 +41,25 @@ const setter = (prop) => {
|
|
|
38
41
|
return setOnObject(prop);
|
|
39
42
|
}
|
|
40
43
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}, left);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
: right
|
|
52
|
-
: Array.isArray(right)
|
|
53
|
-
? mergeArrays(ensureArray(left), right)
|
|
54
|
-
: isObject(right)
|
|
55
|
-
? ramda_1.mergeDeepWith(mergeExisting, left, right)
|
|
56
|
-
: right;
|
|
44
|
+
function mergeExisting(left, right) {
|
|
45
|
+
if (Array.isArray(right)) {
|
|
46
|
+
return right.reduce((arr, value, index) => {
|
|
47
|
+
arr[index] = (0, ramda_1.mergeDeepWith)(mergeExisting, left[index], value);
|
|
48
|
+
return arr;
|
|
49
|
+
}, left);
|
|
50
|
+
}
|
|
51
|
+
return right;
|
|
52
|
+
}
|
|
53
|
+
exports.mergeExisting = mergeExisting;
|
|
57
54
|
function pathSetter(path) {
|
|
58
55
|
const setters = split(path).map(setter);
|
|
59
56
|
if (setters.length === 0) {
|
|
60
57
|
return ramda_1.identity;
|
|
61
58
|
}
|
|
62
|
-
const setterFn =
|
|
63
|
-
return (value, object) => {
|
|
59
|
+
const setterFn = (0, functional_1.compose)(...setters);
|
|
60
|
+
return (value, object = null) => {
|
|
64
61
|
const data = setterFn(value);
|
|
65
|
-
return
|
|
62
|
+
return object ? (0, ramda_1.mergeDeepWith)(mergeExisting, object, data) : data;
|
|
66
63
|
};
|
|
67
64
|
}
|
|
68
65
|
exports.default = pathSetter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathSetter.js","sourceRoot":"","sources":["../../src/utils/pathSetter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"pathSetter.js","sourceRoot":"","sources":["../../src/utils/pathSetter.ts"],"names":[],"mappings":";;;AACA,iCAA+C;AAC/C,6CAAsC;AAGtC,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,gBAAyB,EAAE,EAAE,CAClE,gBAAgB,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AAEtC,MAAM,YAAY,GAAG,QAAQ,CAAC,EAAE,IAAU;IACxC,MAAM,KAAK,GAAG,oBAAoB,CAAA;IAClC,IAAI,KAAK,CAAA;IACT,IAAI,gBAAgB,GAAG,KAAK,CAAA;IAC5B,GAAG;QACD,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACxB,IAAI,KAAK,EAAE;YACT,MAAM,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,gBAAgB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a,EAAC,aAAa,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IACnE,CAAC,CAAA;AACH,CAAC;AAZD,6BAYC"}
|
|
@@ -1,36 +1,7 @@
|
|
|
1
|
-
import { State,
|
|
2
|
-
export declare const setStateValue: (state: State, value:
|
|
3
|
-
export declare const getStateValue: (state: State) =>
|
|
4
|
-
export declare const setValueFromState: (state: State, { value }: State) =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
rev?: boolean | undefined;
|
|
9
|
-
onlyMapped?: boolean | undefined;
|
|
10
|
-
arr?: boolean | undefined;
|
|
11
|
-
};
|
|
12
|
-
export declare const liftState: (state: State) => {
|
|
13
|
-
context: Data;
|
|
14
|
-
value: undefined;
|
|
15
|
-
arr: boolean;
|
|
16
|
-
root: Data;
|
|
17
|
-
rev?: boolean | undefined;
|
|
18
|
-
onlyMapped?: boolean | undefined;
|
|
19
|
-
};
|
|
20
|
-
export declare const lowerState: (state: State) => {
|
|
21
|
-
value: Data;
|
|
22
|
-
root: Data;
|
|
23
|
-
context: Data;
|
|
24
|
-
rev?: boolean | undefined;
|
|
25
|
-
onlyMapped?: boolean | undefined;
|
|
26
|
-
arr?: boolean | undefined;
|
|
27
|
-
};
|
|
28
|
-
export declare const contextFromState: ({ rev, onlyMapped }: State) => {
|
|
29
|
-
rev: boolean;
|
|
30
|
-
onlyMappedValues: boolean;
|
|
31
|
-
};
|
|
32
|
-
export declare const pipeMapFns: (fns: StateMapper[]) => (state: State) => State;
|
|
33
|
-
export declare const populateState: ({ rev, onlyMapped }: {
|
|
34
|
-
rev?: boolean | undefined;
|
|
35
|
-
onlyMapped?: boolean | undefined;
|
|
36
|
-
}) => (data: Data) => State;
|
|
1
|
+
import { State, Options, Context } from '../types';
|
|
2
|
+
export declare const setStateValue: (state: State, value: unknown) => State;
|
|
3
|
+
export declare const getStateValue: (state: State) => any;
|
|
4
|
+
export declare const setValueFromState: (state: State, { value }: State) => State;
|
|
5
|
+
export declare const contextFromState: ({ rev, onlyMapped, }: State) => Context;
|
|
6
|
+
export declare const populateState: ({ rev, onlyMapped, }: Partial<State>) => (data: unknown) => State;
|
|
7
|
+
export declare const shouldSkipMutation: ({ mutateNull }: Options) => (state: State) => boolean;
|