@player-ui/data-filter-plugin 0.0.1-next.1
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/dist/index.cjs.js +49 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.esm.js +40 -0
- package/package.json +19 -0
- package/src/index.ts +64 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var get = require('dlv');
|
|
6
|
+
var timm = require('timm');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
|
|
11
|
+
|
|
12
|
+
function omitIn(obj, path) {
|
|
13
|
+
if (typeof path === "string") {
|
|
14
|
+
return timm.omit(obj, path);
|
|
15
|
+
}
|
|
16
|
+
if (path.length === 1) {
|
|
17
|
+
return timm.omit(obj, path[0]);
|
|
18
|
+
}
|
|
19
|
+
const parentPath = [...path];
|
|
20
|
+
const attr = parentPath.pop();
|
|
21
|
+
if (!attr) {
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
const parentObj = get__default["default"](obj, parentPath);
|
|
25
|
+
return timm.setIn(obj, parentPath, timm.omit(parentObj, attr));
|
|
26
|
+
}
|
|
27
|
+
class DataFilterPlugin {
|
|
28
|
+
constructor(options = {}) {
|
|
29
|
+
this.name = "data-filter";
|
|
30
|
+
this.options = options;
|
|
31
|
+
}
|
|
32
|
+
apply(player) {
|
|
33
|
+
player.hooks.dataController.tap(this.name, (dataController) => {
|
|
34
|
+
dataController.hooks.serialize.tap(this.name, (serializedModel) => {
|
|
35
|
+
var _a;
|
|
36
|
+
let updatedModel = serializedModel;
|
|
37
|
+
(_a = this.options.paths) == null ? void 0 : _a.forEach((path) => {
|
|
38
|
+
const arrPath = Array.isArray(path) ? path : path.split(".");
|
|
39
|
+
updatedModel = omitIn(updatedModel, arrPath);
|
|
40
|
+
});
|
|
41
|
+
return updatedModel;
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exports.DataFilterPlugin = DataFilterPlugin;
|
|
48
|
+
exports.omitIn = omitIn;
|
|
49
|
+
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PlayerPlugin, Player } from '@player-ui/player';
|
|
2
|
+
|
|
3
|
+
interface DataFilterPluginOptions {
|
|
4
|
+
/** Paths in the model that should be omitted from the serialized result */
|
|
5
|
+
paths?: Array<string | Array<string>>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Similar to timm's omit, but for deeper paths
|
|
9
|
+
*/
|
|
10
|
+
declare function omitIn(obj: Record<string, unknown>, path: string | Array<string>): unknown;
|
|
11
|
+
/**
|
|
12
|
+
* A plugin to manage constant strings across flows
|
|
13
|
+
* It allows for runtime extensions/overrides through a `constants` property in the flow
|
|
14
|
+
*/
|
|
15
|
+
declare class DataFilterPlugin implements PlayerPlugin {
|
|
16
|
+
name: string;
|
|
17
|
+
private readonly options;
|
|
18
|
+
constructor(options?: DataFilterPluginOptions);
|
|
19
|
+
apply(player: Player): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { DataFilterPlugin, DataFilterPluginOptions, omitIn };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import get from 'dlv';
|
|
2
|
+
import { omit, setIn } from 'timm';
|
|
3
|
+
|
|
4
|
+
function omitIn(obj, path) {
|
|
5
|
+
if (typeof path === "string") {
|
|
6
|
+
return omit(obj, path);
|
|
7
|
+
}
|
|
8
|
+
if (path.length === 1) {
|
|
9
|
+
return omit(obj, path[0]);
|
|
10
|
+
}
|
|
11
|
+
const parentPath = [...path];
|
|
12
|
+
const attr = parentPath.pop();
|
|
13
|
+
if (!attr) {
|
|
14
|
+
return obj;
|
|
15
|
+
}
|
|
16
|
+
const parentObj = get(obj, parentPath);
|
|
17
|
+
return setIn(obj, parentPath, omit(parentObj, attr));
|
|
18
|
+
}
|
|
19
|
+
class DataFilterPlugin {
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
this.name = "data-filter";
|
|
22
|
+
this.options = options;
|
|
23
|
+
}
|
|
24
|
+
apply(player) {
|
|
25
|
+
player.hooks.dataController.tap(this.name, (dataController) => {
|
|
26
|
+
dataController.hooks.serialize.tap(this.name, (serializedModel) => {
|
|
27
|
+
var _a;
|
|
28
|
+
let updatedModel = serializedModel;
|
|
29
|
+
(_a = this.options.paths) == null ? void 0 : _a.forEach((path) => {
|
|
30
|
+
const arrPath = Array.isArray(path) ? path : path.split(".");
|
|
31
|
+
updatedModel = omitIn(updatedModel, arrPath);
|
|
32
|
+
});
|
|
33
|
+
return updatedModel;
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { DataFilterPlugin, omitIn };
|
|
40
|
+
//# sourceMappingURL=index.esm.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@player-ui/data-filter-plugin",
|
|
3
|
+
"version": "0.0.1-next.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"registry": "https://registry.npmjs.org"
|
|
7
|
+
},
|
|
8
|
+
"peerDependencies": {
|
|
9
|
+
"@player-ui/binding-grammar": "0.0.1-next.1"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"timm": "^1.6.2",
|
|
13
|
+
"dlv": "^1.1.3",
|
|
14
|
+
"@babel/runtime": "7.15.4"
|
|
15
|
+
},
|
|
16
|
+
"main": "dist/index.cjs.js",
|
|
17
|
+
"module": "dist/index.esm.js",
|
|
18
|
+
"typings": "dist/index.d.ts"
|
|
19
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Player, PlayerPlugin } from '@player-ui/player';
|
|
2
|
+
import get from 'dlv';
|
|
3
|
+
import { omit, setIn } from 'timm';
|
|
4
|
+
|
|
5
|
+
export interface DataFilterPluginOptions {
|
|
6
|
+
/** Paths in the model that should be omitted from the serialized result */
|
|
7
|
+
paths?: Array<string | Array<string>>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Similar to timm's omit, but for deeper paths
|
|
12
|
+
*/
|
|
13
|
+
export function omitIn(
|
|
14
|
+
obj: Record<string, unknown>,
|
|
15
|
+
path: string | Array<string>
|
|
16
|
+
): unknown {
|
|
17
|
+
if (typeof path === 'string') {
|
|
18
|
+
return omit(obj, path);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (path.length === 1) {
|
|
22
|
+
return omit(obj, path[0]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const parentPath = [...path];
|
|
26
|
+
const attr = parentPath.pop();
|
|
27
|
+
|
|
28
|
+
if (!attr) {
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const parentObj = get(obj, parentPath);
|
|
33
|
+
|
|
34
|
+
return setIn(obj, parentPath, omit(parentObj, attr));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A plugin to manage constant strings across flows
|
|
39
|
+
* It allows for runtime extensions/overrides through a `constants` property in the flow
|
|
40
|
+
*/
|
|
41
|
+
export class DataFilterPlugin implements PlayerPlugin {
|
|
42
|
+
name = 'data-filter';
|
|
43
|
+
|
|
44
|
+
private readonly options: DataFilterPluginOptions;
|
|
45
|
+
|
|
46
|
+
constructor(options: DataFilterPluginOptions = {}) {
|
|
47
|
+
this.options = options;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
apply(player: Player) {
|
|
51
|
+
player.hooks.dataController.tap(this.name, (dataController) => {
|
|
52
|
+
dataController.hooks.serialize.tap(this.name, (serializedModel) => {
|
|
53
|
+
let updatedModel = serializedModel;
|
|
54
|
+
|
|
55
|
+
this.options.paths?.forEach((path) => {
|
|
56
|
+
const arrPath = Array.isArray(path) ? path : path.split('.');
|
|
57
|
+
updatedModel = omitIn(updatedModel, arrPath);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return updatedModel;
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|