@player-ui/data-filter-plugin 0.8.0--canary.307.9621 → 0.8.0-next.0
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/cjs/index.cjs +77 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{index.esm.js → index.legacy-esm.js} +11 -10
- package/dist/index.mjs +41 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +26 -59
- package/src/index.test.ts +64 -0
- package/src/index.ts +7 -7
- package/{dist → types}/index.d.ts +5 -7
- package/dist/index.cjs.js +0 -49
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/data-filter/core/src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
DataFilterPlugin: () => DataFilterPlugin,
|
|
34
|
+
omitIn: () => omitIn
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
var import_dlv = __toESM(require("dlv"));
|
|
38
|
+
var import_timm = require("timm");
|
|
39
|
+
function omitIn(obj, path) {
|
|
40
|
+
if (typeof path === "string") {
|
|
41
|
+
return (0, import_timm.omit)(obj, path);
|
|
42
|
+
}
|
|
43
|
+
if (path.length === 1) {
|
|
44
|
+
return (0, import_timm.omit)(obj, path[0]);
|
|
45
|
+
}
|
|
46
|
+
const parentPath = [...path];
|
|
47
|
+
const attr = parentPath.pop();
|
|
48
|
+
if (!attr) {
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
51
|
+
const parentObj = (0, import_dlv.default)(obj, parentPath);
|
|
52
|
+
return (0, import_timm.setIn)(obj, parentPath, (0, import_timm.omit)(parentObj, attr));
|
|
53
|
+
}
|
|
54
|
+
var DataFilterPlugin = class {
|
|
55
|
+
constructor(options = {}) {
|
|
56
|
+
this.name = "data-filter";
|
|
57
|
+
this.options = options;
|
|
58
|
+
}
|
|
59
|
+
apply(player) {
|
|
60
|
+
player.hooks.dataController.tap(this.name, (dataController) => {
|
|
61
|
+
dataController.hooks.serialize.tap(this.name, (serializedModel) => {
|
|
62
|
+
let updatedModel = serializedModel;
|
|
63
|
+
this.options.paths?.forEach((path) => {
|
|
64
|
+
const arrPath = Array.isArray(path) ? path : path.split(".");
|
|
65
|
+
updatedModel = omitIn(updatedModel, arrPath);
|
|
66
|
+
});
|
|
67
|
+
return updatedModel;
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
DataFilterPlugin,
|
|
75
|
+
omitIn
|
|
76
|
+
});
|
|
77
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/data-filter/core/src/index.ts"],"sourcesContent":["import type { Player, PlayerPlugin } from \"@player-ui/player\";\nimport get from \"dlv\";\nimport { omit, setIn } from \"timm\";\n\nexport interface DataFilterPluginOptions {\n /** Paths in the model that should be omitted from the serialized result */\n paths?: Array<string | Array<string>>;\n}\n\n/**\n * Similar to timm's omit, but for deeper paths\n */\nexport function omitIn(\n obj: Record<string, unknown>,\n path: string | Array<string>,\n): unknown {\n if (typeof path === \"string\") {\n return omit(obj, path);\n }\n\n if (path.length === 1) {\n return omit(obj, path[0]);\n }\n\n const parentPath = [...path];\n const attr = parentPath.pop();\n\n if (!attr) {\n return obj;\n }\n\n const parentObj = get(obj, parentPath);\n\n return setIn(obj, parentPath, omit(parentObj, attr));\n}\n\n/**\n * A plugin to manage constant strings across flows\n * It allows for runtime extensions/overrides through a `constants` property in the flow\n */\nexport class DataFilterPlugin implements PlayerPlugin {\n name = \"data-filter\";\n\n private readonly options: DataFilterPluginOptions;\n\n constructor(options: DataFilterPluginOptions = {}) {\n this.options = options;\n }\n\n apply(player: Player) {\n player.hooks.dataController.tap(this.name, (dataController) => {\n dataController.hooks.serialize.tap(this.name, (serializedModel) => {\n let updatedModel = serializedModel;\n\n this.options.paths?.forEach((path) => {\n const arrPath = Array.isArray(path) ? path : path.split(\".\");\n updatedModel = omitIn(updatedModel, arrPath);\n });\n\n return updatedModel;\n });\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAAgB;AAChB,kBAA4B;AAUrB,SAAS,OACd,KACA,MACS;AACT,MAAI,OAAO,SAAS,UAAU;AAC5B,eAAO,kBAAK,KAAK,IAAI;AAAA,EACvB;AAEA,MAAI,KAAK,WAAW,GAAG;AACrB,eAAO,kBAAK,KAAK,KAAK,CAAC,CAAC;AAAA,EAC1B;AAEA,QAAM,aAAa,CAAC,GAAG,IAAI;AAC3B,QAAM,OAAO,WAAW,IAAI;AAE5B,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,QAAM,gBAAY,WAAAA,SAAI,KAAK,UAAU;AAErC,aAAO,mBAAM,KAAK,gBAAY,kBAAK,WAAW,IAAI,CAAC;AACrD;AAMO,IAAM,mBAAN,MAA+C;AAAA,EAKpD,YAAY,UAAmC,CAAC,GAAG;AAJnD,gBAAO;AAKL,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,QAAgB;AACpB,WAAO,MAAM,eAAe,IAAI,KAAK,MAAM,CAAC,mBAAmB;AAC7D,qBAAe,MAAM,UAAU,IAAI,KAAK,MAAM,CAAC,oBAAoB;AACjE,YAAI,eAAe;AAEnB,aAAK,QAAQ,OAAO,QAAQ,CAAC,SAAS;AACpC,gBAAM,UAAU,MAAM,QAAQ,IAAI,IAAI,OAAO,KAAK,MAAM,GAAG;AAC3D,yBAAe,OAAO,cAAc,OAAO;AAAA,QAC7C,CAAC;AAED,eAAO;AAAA,MACT,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":["get"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/data-filter/core/src/index.ts
|
|
2
|
+
import get from "dlv";
|
|
3
|
+
import { omit, setIn } from "timm";
|
|
4
4
|
function omitIn(obj, path) {
|
|
5
5
|
if (typeof path === "string") {
|
|
6
6
|
return omit(obj, path);
|
|
@@ -16,7 +16,7 @@ function omitIn(obj, path) {
|
|
|
16
16
|
const parentObj = get(obj, parentPath);
|
|
17
17
|
return setIn(obj, parentPath, omit(parentObj, attr));
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
var DataFilterPlugin = class {
|
|
20
20
|
constructor(options = {}) {
|
|
21
21
|
this.name = "data-filter";
|
|
22
22
|
this.options = options;
|
|
@@ -24,9 +24,8 @@ class DataFilterPlugin {
|
|
|
24
24
|
apply(player) {
|
|
25
25
|
player.hooks.dataController.tap(this.name, (dataController) => {
|
|
26
26
|
dataController.hooks.serialize.tap(this.name, (serializedModel) => {
|
|
27
|
-
var _a;
|
|
28
27
|
let updatedModel = serializedModel;
|
|
29
|
-
|
|
28
|
+
this.options.paths?.forEach((path) => {
|
|
30
29
|
const arrPath = Array.isArray(path) ? path : path.split(".");
|
|
31
30
|
updatedModel = omitIn(updatedModel, arrPath);
|
|
32
31
|
});
|
|
@@ -34,7 +33,9 @@ class DataFilterPlugin {
|
|
|
34
33
|
});
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
DataFilterPlugin,
|
|
39
|
+
omitIn
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/data-filter/core/src/index.ts
|
|
2
|
+
import get from "dlv";
|
|
3
|
+
import { omit, setIn } from "timm";
|
|
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
|
+
var DataFilterPlugin = class {
|
|
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
|
+
let updatedModel = serializedModel;
|
|
28
|
+
this.options.paths?.forEach((path) => {
|
|
29
|
+
const arrPath = Array.isArray(path) ? path : path.split(".");
|
|
30
|
+
updatedModel = omitIn(updatedModel, arrPath);
|
|
31
|
+
});
|
|
32
|
+
return updatedModel;
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
DataFilterPlugin,
|
|
39
|
+
omitIn
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/data-filter/core/src/index.ts"],"sourcesContent":["import type { Player, PlayerPlugin } from \"@player-ui/player\";\nimport get from \"dlv\";\nimport { omit, setIn } from \"timm\";\n\nexport interface DataFilterPluginOptions {\n /** Paths in the model that should be omitted from the serialized result */\n paths?: Array<string | Array<string>>;\n}\n\n/**\n * Similar to timm's omit, but for deeper paths\n */\nexport function omitIn(\n obj: Record<string, unknown>,\n path: string | Array<string>,\n): unknown {\n if (typeof path === \"string\") {\n return omit(obj, path);\n }\n\n if (path.length === 1) {\n return omit(obj, path[0]);\n }\n\n const parentPath = [...path];\n const attr = parentPath.pop();\n\n if (!attr) {\n return obj;\n }\n\n const parentObj = get(obj, parentPath);\n\n return setIn(obj, parentPath, omit(parentObj, attr));\n}\n\n/**\n * A plugin to manage constant strings across flows\n * It allows for runtime extensions/overrides through a `constants` property in the flow\n */\nexport class DataFilterPlugin implements PlayerPlugin {\n name = \"data-filter\";\n\n private readonly options: DataFilterPluginOptions;\n\n constructor(options: DataFilterPluginOptions = {}) {\n this.options = options;\n }\n\n apply(player: Player) {\n player.hooks.dataController.tap(this.name, (dataController) => {\n dataController.hooks.serialize.tap(this.name, (serializedModel) => {\n let updatedModel = serializedModel;\n\n this.options.paths?.forEach((path) => {\n const arrPath = Array.isArray(path) ? path : path.split(\".\");\n updatedModel = omitIn(updatedModel, arrPath);\n });\n\n return updatedModel;\n });\n });\n }\n}\n"],"mappings":";AACA,OAAO,SAAS;AAChB,SAAS,MAAM,aAAa;AAUrB,SAAS,OACd,KACA,MACS;AACT,MAAI,OAAO,SAAS,UAAU;AAC5B,WAAO,KAAK,KAAK,IAAI;AAAA,EACvB;AAEA,MAAI,KAAK,WAAW,GAAG;AACrB,WAAO,KAAK,KAAK,KAAK,CAAC,CAAC;AAAA,EAC1B;AAEA,QAAM,aAAa,CAAC,GAAG,IAAI;AAC3B,QAAM,OAAO,WAAW,IAAI;AAE5B,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,IAAI,KAAK,UAAU;AAErC,SAAO,MAAM,KAAK,YAAY,KAAK,WAAW,IAAI,CAAC;AACrD;AAMO,IAAM,mBAAN,MAA+C;AAAA,EAKpD,YAAY,UAAmC,CAAC,GAAG;AAJnD,gBAAO;AAKL,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,QAAgB;AACpB,WAAO,MAAM,eAAe,IAAI,KAAK,MAAM,CAAC,mBAAmB;AAC7D,qBAAe,MAAM,UAAU,IAAI,KAAK,MAAM,CAAC,oBAAoB;AACjE,YAAI,eAAe;AAEnB,aAAK,QAAQ,OAAO,QAAQ,CAAC,SAAS;AACpC,gBAAM,UAAU,MAAM,QAAQ,IAAI,IAAI,OAAO,KAAK,MAAM,GAAG;AAC3D,yBAAe,OAAO,cAAc,OAAO;AAAA,QAC7C,CAAC;AAED,eAAO;AAAA,MACT,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,67 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-ui/data-filter-plugin",
|
|
3
|
-
"version": "0.8.0
|
|
4
|
-
"
|
|
5
|
-
"publishConfig": {
|
|
6
|
-
"registry": "https://registry.npmjs.org"
|
|
7
|
-
},
|
|
3
|
+
"version": "0.8.0-next.0",
|
|
4
|
+
"main": "dist/cjs/index.cjs",
|
|
8
5
|
"peerDependencies": {
|
|
9
|
-
"@player-ui/player": "0.8.0
|
|
6
|
+
"@player-ui/player": "0.8.0-next.0"
|
|
10
7
|
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"dlv": "^1.1.3",
|
|
14
|
-
"@babel/runtime": "7.15.4"
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@player-ui/make-flow": "workspace:*"
|
|
15
10
|
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"typings": "dist/index.d.ts",
|
|
11
|
+
"module": "dist/index.legacy-esm.js",
|
|
12
|
+
"types": "types/index.d.ts",
|
|
19
13
|
"sideEffects": false,
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
"homepage": "https://player-ui.github.io",
|
|
29
|
-
"contributors": [
|
|
30
|
-
{
|
|
31
|
-
"name": "Adam Dierkens",
|
|
32
|
-
"url": "https://github.com/adierkens"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"name": "Spencer Hamm",
|
|
36
|
-
"url": "https://github.com/spentacular"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"name": "Harris Borawski",
|
|
40
|
-
"url": "https://github.com/hborawski"
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
"name": "Jeremiah Zucker",
|
|
44
|
-
"url": "https://github.com/sugarmanz"
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
"name": "Ketan Reddy",
|
|
48
|
-
"url": "https://github.com/KetanReddy"
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
"name": "Brocollie08",
|
|
52
|
-
"url": "https://github.com/brocollie08"
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"name": "Kelly Harrop",
|
|
56
|
-
"url": "https://github.com/kharrop"
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"name": "Alejandro Fimbres",
|
|
60
|
-
"url": "https://github.com/lexfm"
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"name": "Rafael Campos",
|
|
64
|
-
"url": "https://github.com/rafbcampos"
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": "./package.json",
|
|
16
|
+
"./dist/index.css": "./dist/index.css",
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./types/index.d.ts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"default": "./dist/cjs/index.cjs"
|
|
65
21
|
}
|
|
66
|
-
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"src",
|
|
26
|
+
"types"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@types/dlv": "^1.1.4",
|
|
30
|
+
"dlv": "^1.1.3",
|
|
31
|
+
"timm": "^1.6.2",
|
|
32
|
+
"tslib": "^2.6.2"
|
|
33
|
+
}
|
|
67
34
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { test, expect, describe } from "vitest";
|
|
2
|
+
import type { InProgressState } from "@player-ui/player";
|
|
3
|
+
import { Player } from "@player-ui/player";
|
|
4
|
+
import { makeFlow } from "@player-ui/make-flow";
|
|
5
|
+
import { DataFilterPlugin, omitIn } from ".";
|
|
6
|
+
|
|
7
|
+
test("removes top level keys", async () => {
|
|
8
|
+
const player = new Player({
|
|
9
|
+
plugins: [
|
|
10
|
+
new DataFilterPlugin({
|
|
11
|
+
paths: ["local", "other.nested", ["other", "array"]],
|
|
12
|
+
}),
|
|
13
|
+
],
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const basicFlow = makeFlow({ asset: { id: "test", type: "test" } });
|
|
17
|
+
const end = player.start(basicFlow);
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
controllers: { data, flow },
|
|
21
|
+
} = player.getState() as InProgressState;
|
|
22
|
+
|
|
23
|
+
data.set([
|
|
24
|
+
["local.foo", "bar"],
|
|
25
|
+
["notLocal.foo", "bar"],
|
|
26
|
+
["other.nested.prop", "bar"],
|
|
27
|
+
["other.array", []],
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
flow.transition("Next");
|
|
31
|
+
|
|
32
|
+
const response = await end;
|
|
33
|
+
|
|
34
|
+
expect(response.data).toStrictEqual({
|
|
35
|
+
notLocal: {
|
|
36
|
+
foo: "bar",
|
|
37
|
+
},
|
|
38
|
+
other: {},
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("omitIn", () => {
|
|
43
|
+
test("works for objects", () => {
|
|
44
|
+
expect(
|
|
45
|
+
omitIn(
|
|
46
|
+
{
|
|
47
|
+
foo: { bar: "baz" },
|
|
48
|
+
},
|
|
49
|
+
["foo", "bar"],
|
|
50
|
+
),
|
|
51
|
+
).toStrictEqual({
|
|
52
|
+
foo: {},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
expect(
|
|
56
|
+
omitIn({ foo: { bar: "baz", baz: "other" } }, ["foo", "bar"]),
|
|
57
|
+
).toStrictEqual({
|
|
58
|
+
foo: { baz: "other" },
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
expect(omitIn({ foo: { bar: "baz" } }, "foo")).toStrictEqual({});
|
|
62
|
+
expect(omitIn({ foo: { bar: "baz" } }, ["foo"])).toStrictEqual({});
|
|
63
|
+
});
|
|
64
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Player, PlayerPlugin } from
|
|
2
|
-
import get from
|
|
3
|
-
import { omit, setIn } from
|
|
1
|
+
import type { Player, PlayerPlugin } from "@player-ui/player";
|
|
2
|
+
import get from "dlv";
|
|
3
|
+
import { omit, setIn } from "timm";
|
|
4
4
|
|
|
5
5
|
export interface DataFilterPluginOptions {
|
|
6
6
|
/** Paths in the model that should be omitted from the serialized result */
|
|
@@ -12,9 +12,9 @@ export interface DataFilterPluginOptions {
|
|
|
12
12
|
*/
|
|
13
13
|
export function omitIn(
|
|
14
14
|
obj: Record<string, unknown>,
|
|
15
|
-
path: string | Array<string
|
|
15
|
+
path: string | Array<string>,
|
|
16
16
|
): unknown {
|
|
17
|
-
if (typeof path ===
|
|
17
|
+
if (typeof path === "string") {
|
|
18
18
|
return omit(obj, path);
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -39,7 +39,7 @@ export function omitIn(
|
|
|
39
39
|
* It allows for runtime extensions/overrides through a `constants` property in the flow
|
|
40
40
|
*/
|
|
41
41
|
export class DataFilterPlugin implements PlayerPlugin {
|
|
42
|
-
name =
|
|
42
|
+
name = "data-filter";
|
|
43
43
|
|
|
44
44
|
private readonly options: DataFilterPluginOptions;
|
|
45
45
|
|
|
@@ -53,7 +53,7 @@ export class DataFilterPlugin implements PlayerPlugin {
|
|
|
53
53
|
let updatedModel = serializedModel;
|
|
54
54
|
|
|
55
55
|
this.options.paths?.forEach((path) => {
|
|
56
|
-
const arrPath = Array.isArray(path) ? path : path.split(
|
|
56
|
+
const arrPath = Array.isArray(path) ? path : path.split(".");
|
|
57
57
|
updatedModel = omitIn(updatedModel, arrPath);
|
|
58
58
|
});
|
|
59
59
|
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
interface DataFilterPluginOptions {
|
|
1
|
+
import type { Player, PlayerPlugin } from "@player-ui/player";
|
|
2
|
+
export interface DataFilterPluginOptions {
|
|
4
3
|
/** Paths in the model that should be omitted from the serialized result */
|
|
5
4
|
paths?: Array<string | Array<string>>;
|
|
6
5
|
}
|
|
7
6
|
/**
|
|
8
7
|
* Similar to timm's omit, but for deeper paths
|
|
9
8
|
*/
|
|
10
|
-
declare function omitIn(obj: Record<string, unknown>, path: string | Array<string>): unknown;
|
|
9
|
+
export declare function omitIn(obj: Record<string, unknown>, path: string | Array<string>): unknown;
|
|
11
10
|
/**
|
|
12
11
|
* A plugin to manage constant strings across flows
|
|
13
12
|
* It allows for runtime extensions/overrides through a `constants` property in the flow
|
|
14
13
|
*/
|
|
15
|
-
declare class DataFilterPlugin implements PlayerPlugin {
|
|
14
|
+
export declare class DataFilterPlugin implements PlayerPlugin {
|
|
16
15
|
name: string;
|
|
17
16
|
private readonly options;
|
|
18
17
|
constructor(options?: DataFilterPluginOptions);
|
|
19
18
|
apply(player: Player): void;
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
export { DataFilterPlugin, DataFilterPluginOptions, omitIn };
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.cjs.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
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
|