@player-ui/stage-revert-data-plugin 0.7.4-next.3 → 0.7.5--canary.432.14776
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/StageRevertDataPlugin.native.js +7516 -0
- package/dist/StageRevertDataPlugin.native.js.map +1 -0
- package/dist/cjs/index.cjs +81 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{index.esm.js → index.legacy-esm.js} +21 -15
- package/dist/index.mjs +56 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +25 -58
- package/src/index.test.ts +208 -0
- package/src/index.ts +8 -8
- package/{dist → types}/index.d.ts +3 -5
- package/dist/index.cjs.js +0 -54
- package/dist/stage-revert-data-plugin.dev.js +0 -10634
- package/dist/stage-revert-data-plugin.prod.js +0 -2
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/stage-revert-data/core/src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
StageRevertDataPlugin: () => StageRevertDataPlugin
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
var import_player = require("@player-ui/player");
|
|
27
|
+
var StageRevertDataPlugin = class {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.name = "stage-revert-data-plugin";
|
|
30
|
+
}
|
|
31
|
+
apply(player) {
|
|
32
|
+
let dataController;
|
|
33
|
+
let commitTransitions;
|
|
34
|
+
let stageData;
|
|
35
|
+
let commitShadowModel = false;
|
|
36
|
+
const GatedDataMiddleware = new import_player.ValidationMiddleware(
|
|
37
|
+
() => commitShadowModel ? void 0 : {
|
|
38
|
+
message: "staging data",
|
|
39
|
+
severity: "error"
|
|
40
|
+
},
|
|
41
|
+
{ shouldIncludeInvalid: () => true }
|
|
42
|
+
);
|
|
43
|
+
player.hooks.dataController.tap(this.name, (dc) => {
|
|
44
|
+
dataController = dc;
|
|
45
|
+
dc.hooks.resolveDataStages.tap(this.name, (dataPipeline) => {
|
|
46
|
+
return stageData ? [...dataPipeline, GatedDataMiddleware] : [...dataPipeline];
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
player.hooks.flowController.tap(this.name, (flowController) => {
|
|
50
|
+
flowController.hooks.flow.tap(this.name, (flow) => {
|
|
51
|
+
flow.hooks.transition.tap(this.name, (from, to) => {
|
|
52
|
+
if (from) {
|
|
53
|
+
if (commitTransitions.includes(to.name)) {
|
|
54
|
+
commitShadowModel = true;
|
|
55
|
+
player.logger.debug(
|
|
56
|
+
"Shadow Model Data to be committed %s",
|
|
57
|
+
GatedDataMiddleware.shadowModelPaths
|
|
58
|
+
);
|
|
59
|
+
dataController.set(GatedDataMiddleware.shadowModelPaths);
|
|
60
|
+
}
|
|
61
|
+
commitShadowModel = false;
|
|
62
|
+
GatedDataMiddleware.shadowModelPaths.clear();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
player.hooks.viewController.tap(this.name, (vc) => {
|
|
68
|
+
vc.hooks.resolveView.intercept({
|
|
69
|
+
call: (view, id, state) => {
|
|
70
|
+
stageData = state?.attributes?.stageData;
|
|
71
|
+
commitTransitions = state?.attributes?.commitTransitions;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
StageRevertDataPlugin
|
|
80
|
+
});
|
|
81
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/stage-revert-data/core/src/index.ts"],"sourcesContent":["import type { Player, DataController, PlayerPlugin } from \"@player-ui/player\";\nimport { ValidationMiddleware } from \"@player-ui/player\";\n\n/**\n * this plugin is supposed to stage/store changes in a local object/cache, until a transition happens,\n * then changes are committed to the Data Model\n */\nexport class StageRevertDataPlugin implements PlayerPlugin {\n name = \"stage-revert-data-plugin\";\n\n apply(player: Player) {\n let dataController: DataController;\n let commitTransitions: string[];\n let stageData: string;\n let commitShadowModel = false;\n\n const GatedDataMiddleware = new ValidationMiddleware(\n () =>\n commitShadowModel\n ? undefined\n : {\n message: \"staging data\",\n severity: \"error\",\n },\n { shouldIncludeInvalid: () => true },\n );\n\n /**\n * Tapping into data controller hook to intercept data before it gets committed to data model,\n * we are using an instance of ValidationMiddleware when tapping the resolveDataStages hook on DataController\n */\n player.hooks.dataController.tap(this.name, (dc: DataController) => {\n dataController = dc;\n\n dc.hooks.resolveDataStages.tap(this.name, (dataPipeline) => {\n return stageData\n ? [...dataPipeline, GatedDataMiddleware]\n : [...dataPipeline];\n });\n });\n\n /**\n * Tapping into flow controller flow hook to detect transition, then proceed to commit to the data model from the shadowModelPaths\n * in the ValidationMiddleware, if transition has not happened then nothing happens, but if an invalid Next transition happens then\n * shadowModelPaths cache is cleared.\n */\n\n player.hooks.flowController.tap(this.name, (flowController) => {\n flowController.hooks.flow.tap(this.name, (flow) => {\n flow.hooks.transition.tap(this.name, (from, to) => {\n if (from) {\n if (commitTransitions.includes(to.name)) {\n commitShadowModel = true;\n player.logger.debug(\n \"Shadow Model Data to be committed %s\",\n GatedDataMiddleware.shadowModelPaths,\n );\n dataController.set(GatedDataMiddleware.shadowModelPaths);\n }\n\n commitShadowModel = false;\n GatedDataMiddleware.shadowModelPaths.clear();\n }\n });\n });\n });\n\n /**\n * Tapping the view controller to see if we want to intercept and cache data before model\n */\n player.hooks.viewController.tap(this.name, (vc) => {\n vc.hooks.resolveView.intercept({\n call: (view, id, state) => {\n stageData = state?.attributes?.stageData;\n commitTransitions = state?.attributes?.commitTransitions;\n },\n });\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAqC;AAM9B,IAAM,wBAAN,MAAoD;AAAA,EAApD;AACL,gBAAO;AAAA;AAAA,EAEP,MAAM,QAAgB;AACpB,QAAI;AACJ,QAAI;AACJ,QAAI;AACJ,QAAI,oBAAoB;AAExB,UAAM,sBAAsB,IAAI;AAAA,MAC9B,MACE,oBACI,SACA;AAAA,QACE,SAAS;AAAA,QACT,UAAU;AAAA,MACZ;AAAA,MACN,EAAE,sBAAsB,MAAM,KAAK;AAAA,IACrC;AAMA,WAAO,MAAM,eAAe,IAAI,KAAK,MAAM,CAAC,OAAuB;AACjE,uBAAiB;AAEjB,SAAG,MAAM,kBAAkB,IAAI,KAAK,MAAM,CAAC,iBAAiB;AAC1D,eAAO,YACH,CAAC,GAAG,cAAc,mBAAmB,IACrC,CAAC,GAAG,YAAY;AAAA,MACtB,CAAC;AAAA,IACH,CAAC;AAQD,WAAO,MAAM,eAAe,IAAI,KAAK,MAAM,CAAC,mBAAmB;AAC7D,qBAAe,MAAM,KAAK,IAAI,KAAK,MAAM,CAAC,SAAS;AACjD,aAAK,MAAM,WAAW,IAAI,KAAK,MAAM,CAAC,MAAM,OAAO;AACjD,cAAI,MAAM;AACR,gBAAI,kBAAkB,SAAS,GAAG,IAAI,GAAG;AACvC,kCAAoB;AACpB,qBAAO,OAAO;AAAA,gBACZ;AAAA,gBACA,oBAAoB;AAAA,cACtB;AACA,6BAAe,IAAI,oBAAoB,gBAAgB;AAAA,YACzD;AAEA,gCAAoB;AACpB,gCAAoB,iBAAiB,MAAM;AAAA,UAC7C;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH,CAAC;AAKD,WAAO,MAAM,eAAe,IAAI,KAAK,MAAM,CAAC,OAAO;AACjD,SAAG,MAAM,YAAY,UAAU;AAAA,QAC7B,MAAM,CAAC,MAAM,IAAI,UAAU;AACzB,sBAAY,OAAO,YAAY;AAC/B,8BAAoB,OAAO,YAAY;AAAA,QACzC;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/stage-revert-data/core/src/index.ts
|
|
2
|
+
import { ValidationMiddleware } from "@player-ui/player";
|
|
3
|
+
var StageRevertDataPlugin = class {
|
|
4
4
|
constructor() {
|
|
5
5
|
this.name = "stage-revert-data-plugin";
|
|
6
6
|
}
|
|
@@ -9,10 +9,13 @@ class StageRevertDataPlugin {
|
|
|
9
9
|
let commitTransitions;
|
|
10
10
|
let stageData;
|
|
11
11
|
let commitShadowModel = false;
|
|
12
|
-
const GatedDataMiddleware = new ValidationMiddleware(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const GatedDataMiddleware = new ValidationMiddleware(
|
|
13
|
+
() => commitShadowModel ? void 0 : {
|
|
14
|
+
message: "staging data",
|
|
15
|
+
severity: "error"
|
|
16
|
+
},
|
|
17
|
+
{ shouldIncludeInvalid: () => true }
|
|
18
|
+
);
|
|
16
19
|
player.hooks.dataController.tap(this.name, (dc) => {
|
|
17
20
|
dataController = dc;
|
|
18
21
|
dc.hooks.resolveDataStages.tap(this.name, (dataPipeline) => {
|
|
@@ -25,7 +28,10 @@ class StageRevertDataPlugin {
|
|
|
25
28
|
if (from) {
|
|
26
29
|
if (commitTransitions.includes(to.name)) {
|
|
27
30
|
commitShadowModel = true;
|
|
28
|
-
player.logger.debug(
|
|
31
|
+
player.logger.debug(
|
|
32
|
+
"Shadow Model Data to be committed %s",
|
|
33
|
+
GatedDataMiddleware.shadowModelPaths
|
|
34
|
+
);
|
|
29
35
|
dataController.set(GatedDataMiddleware.shadowModelPaths);
|
|
30
36
|
}
|
|
31
37
|
commitShadowModel = false;
|
|
@@ -37,14 +43,14 @@ class StageRevertDataPlugin {
|
|
|
37
43
|
player.hooks.viewController.tap(this.name, (vc) => {
|
|
38
44
|
vc.hooks.resolveView.intercept({
|
|
39
45
|
call: (view, id, state) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
commitTransitions = (_b = state == null ? void 0 : state.attributes) == null ? void 0 : _b.commitTransitions;
|
|
46
|
+
stageData = state?.attributes?.stageData;
|
|
47
|
+
commitTransitions = state?.attributes?.commitTransitions;
|
|
43
48
|
}
|
|
44
49
|
});
|
|
45
50
|
});
|
|
46
51
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
StageRevertDataPlugin
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/stage-revert-data/core/src/index.ts
|
|
2
|
+
import { ValidationMiddleware } from "@player-ui/player";
|
|
3
|
+
var StageRevertDataPlugin = class {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.name = "stage-revert-data-plugin";
|
|
6
|
+
}
|
|
7
|
+
apply(player) {
|
|
8
|
+
let dataController;
|
|
9
|
+
let commitTransitions;
|
|
10
|
+
let stageData;
|
|
11
|
+
let commitShadowModel = false;
|
|
12
|
+
const GatedDataMiddleware = new ValidationMiddleware(
|
|
13
|
+
() => commitShadowModel ? void 0 : {
|
|
14
|
+
message: "staging data",
|
|
15
|
+
severity: "error"
|
|
16
|
+
},
|
|
17
|
+
{ shouldIncludeInvalid: () => true }
|
|
18
|
+
);
|
|
19
|
+
player.hooks.dataController.tap(this.name, (dc) => {
|
|
20
|
+
dataController = dc;
|
|
21
|
+
dc.hooks.resolveDataStages.tap(this.name, (dataPipeline) => {
|
|
22
|
+
return stageData ? [...dataPipeline, GatedDataMiddleware] : [...dataPipeline];
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
player.hooks.flowController.tap(this.name, (flowController) => {
|
|
26
|
+
flowController.hooks.flow.tap(this.name, (flow) => {
|
|
27
|
+
flow.hooks.transition.tap(this.name, (from, to) => {
|
|
28
|
+
if (from) {
|
|
29
|
+
if (commitTransitions.includes(to.name)) {
|
|
30
|
+
commitShadowModel = true;
|
|
31
|
+
player.logger.debug(
|
|
32
|
+
"Shadow Model Data to be committed %s",
|
|
33
|
+
GatedDataMiddleware.shadowModelPaths
|
|
34
|
+
);
|
|
35
|
+
dataController.set(GatedDataMiddleware.shadowModelPaths);
|
|
36
|
+
}
|
|
37
|
+
commitShadowModel = false;
|
|
38
|
+
GatedDataMiddleware.shadowModelPaths.clear();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
player.hooks.viewController.tap(this.name, (vc) => {
|
|
44
|
+
vc.hooks.resolveView.intercept({
|
|
45
|
+
call: (view, id, state) => {
|
|
46
|
+
stageData = state?.attributes?.stageData;
|
|
47
|
+
commitTransitions = state?.attributes?.commitTransitions;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
StageRevertDataPlugin
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/stage-revert-data/core/src/index.ts"],"sourcesContent":["import type { Player, DataController, PlayerPlugin } from \"@player-ui/player\";\nimport { ValidationMiddleware } from \"@player-ui/player\";\n\n/**\n * this plugin is supposed to stage/store changes in a local object/cache, until a transition happens,\n * then changes are committed to the Data Model\n */\nexport class StageRevertDataPlugin implements PlayerPlugin {\n name = \"stage-revert-data-plugin\";\n\n apply(player: Player) {\n let dataController: DataController;\n let commitTransitions: string[];\n let stageData: string;\n let commitShadowModel = false;\n\n const GatedDataMiddleware = new ValidationMiddleware(\n () =>\n commitShadowModel\n ? undefined\n : {\n message: \"staging data\",\n severity: \"error\",\n },\n { shouldIncludeInvalid: () => true },\n );\n\n /**\n * Tapping into data controller hook to intercept data before it gets committed to data model,\n * we are using an instance of ValidationMiddleware when tapping the resolveDataStages hook on DataController\n */\n player.hooks.dataController.tap(this.name, (dc: DataController) => {\n dataController = dc;\n\n dc.hooks.resolveDataStages.tap(this.name, (dataPipeline) => {\n return stageData\n ? [...dataPipeline, GatedDataMiddleware]\n : [...dataPipeline];\n });\n });\n\n /**\n * Tapping into flow controller flow hook to detect transition, then proceed to commit to the data model from the shadowModelPaths\n * in the ValidationMiddleware, if transition has not happened then nothing happens, but if an invalid Next transition happens then\n * shadowModelPaths cache is cleared.\n */\n\n player.hooks.flowController.tap(this.name, (flowController) => {\n flowController.hooks.flow.tap(this.name, (flow) => {\n flow.hooks.transition.tap(this.name, (from, to) => {\n if (from) {\n if (commitTransitions.includes(to.name)) {\n commitShadowModel = true;\n player.logger.debug(\n \"Shadow Model Data to be committed %s\",\n GatedDataMiddleware.shadowModelPaths,\n );\n dataController.set(GatedDataMiddleware.shadowModelPaths);\n }\n\n commitShadowModel = false;\n GatedDataMiddleware.shadowModelPaths.clear();\n }\n });\n });\n });\n\n /**\n * Tapping the view controller to see if we want to intercept and cache data before model\n */\n player.hooks.viewController.tap(this.name, (vc) => {\n vc.hooks.resolveView.intercept({\n call: (view, id, state) => {\n stageData = state?.attributes?.stageData;\n commitTransitions = state?.attributes?.commitTransitions;\n },\n });\n });\n }\n}\n"],"mappings":";AACA,SAAS,4BAA4B;AAM9B,IAAM,wBAAN,MAAoD;AAAA,EAApD;AACL,gBAAO;AAAA;AAAA,EAEP,MAAM,QAAgB;AACpB,QAAI;AACJ,QAAI;AACJ,QAAI;AACJ,QAAI,oBAAoB;AAExB,UAAM,sBAAsB,IAAI;AAAA,MAC9B,MACE,oBACI,SACA;AAAA,QACE,SAAS;AAAA,QACT,UAAU;AAAA,MACZ;AAAA,MACN,EAAE,sBAAsB,MAAM,KAAK;AAAA,IACrC;AAMA,WAAO,MAAM,eAAe,IAAI,KAAK,MAAM,CAAC,OAAuB;AACjE,uBAAiB;AAEjB,SAAG,MAAM,kBAAkB,IAAI,KAAK,MAAM,CAAC,iBAAiB;AAC1D,eAAO,YACH,CAAC,GAAG,cAAc,mBAAmB,IACrC,CAAC,GAAG,YAAY;AAAA,MACtB,CAAC;AAAA,IACH,CAAC;AAQD,WAAO,MAAM,eAAe,IAAI,KAAK,MAAM,CAAC,mBAAmB;AAC7D,qBAAe,MAAM,KAAK,IAAI,KAAK,MAAM,CAAC,SAAS;AACjD,aAAK,MAAM,WAAW,IAAI,KAAK,MAAM,CAAC,MAAM,OAAO;AACjD,cAAI,MAAM;AACR,gBAAI,kBAAkB,SAAS,GAAG,IAAI,GAAG;AACvC,kCAAoB;AACpB,qBAAO,OAAO;AAAA,gBACZ;AAAA,gBACA,oBAAoB;AAAA,cACtB;AACA,6BAAe,IAAI,oBAAoB,gBAAgB;AAAA,YACzD;AAEA,gCAAoB;AACpB,gCAAoB,iBAAiB,MAAM;AAAA,UAC7C;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH,CAAC;AAKD,WAAO,MAAM,eAAe,IAAI,KAAK,MAAM,CAAC,OAAO;AACjD,SAAG,MAAM,YAAY,UAAU;AAAA,QAC7B,MAAM,CAAC,MAAM,IAAI,UAAU;AACzB,sBAAY,OAAO,YAAY;AAC/B,8BAAoB,OAAO,YAAY;AAAA,QACzC;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,67 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-ui/stage-revert-data-plugin",
|
|
3
|
-
"version": "0.7.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "0.7.5--canary.432.14776",
|
|
4
|
+
"main": "dist/cjs/index.cjs",
|
|
5
|
+
"devDependencies": {
|
|
6
|
+
"@player-ui/make-flow": "workspace:*",
|
|
7
|
+
"@player-ui/types": "workspace:*"
|
|
7
8
|
},
|
|
8
9
|
"peerDependencies": {
|
|
9
|
-
"@player-ui/player": "0.7.
|
|
10
|
+
"@player-ui/player": "0.7.5--canary.432.14776"
|
|
10
11
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
"main": "dist/index.cjs.js",
|
|
16
|
-
"module": "dist/index.esm.js",
|
|
17
|
-
"typings": "dist/index.d.ts",
|
|
12
|
+
"module": "dist/index.legacy-esm.js",
|
|
13
|
+
"types": "types/index.d.ts",
|
|
14
|
+
"bundle": "dist/StageRevertDataPlugin.native.js",
|
|
18
15
|
"sideEffects": false,
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
"homepage": "https://player-ui.github.io",
|
|
28
|
-
"contributors": [
|
|
29
|
-
{
|
|
30
|
-
"name": "Adam Dierkens",
|
|
31
|
-
"url": "https://github.com/adierkens"
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
"name": "Spencer Hamm",
|
|
35
|
-
"url": "https://github.com/spentacular"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"name": "Harris Borawski",
|
|
39
|
-
"url": "https://github.com/hborawski"
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"name": "Jeremiah Zucker",
|
|
43
|
-
"url": "https://github.com/sugarmanz"
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"name": "Ketan Reddy",
|
|
47
|
-
"url": "https://github.com/KetanReddy"
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"name": "Brocollie08",
|
|
51
|
-
"url": "https://github.com/brocollie08"
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
"name": "Kelly Harrop",
|
|
55
|
-
"url": "https://github.com/kharrop"
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
"name": "Alejandro Fimbres",
|
|
59
|
-
"url": "https://github.com/lexfm"
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
"name": "Rafael Campos",
|
|
63
|
-
"url": "https://github.com/rafbcampos"
|
|
16
|
+
"exports": {
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
"./dist/index.css": "./dist/index.css",
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./types/index.d.ts",
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"default": "./dist/cjs/index.cjs"
|
|
64
23
|
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"src",
|
|
28
|
+
"types"
|
|
65
29
|
],
|
|
66
|
-
"
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"tapable-ts": "^0.2.3",
|
|
32
|
+
"tslib": "^2.6.2"
|
|
33
|
+
}
|
|
67
34
|
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { describe, it, expect, vitest, beforeEach, beforeAll } from "vitest";
|
|
2
|
+
import type { DataController, InProgressState } from "@player-ui/player";
|
|
3
|
+
import { Player } from "@player-ui/player";
|
|
4
|
+
import type { Flow } from "@player-ui/types";
|
|
5
|
+
import { StageRevertDataPlugin } from "./index";
|
|
6
|
+
|
|
7
|
+
const dataChangeFlow: Flow = {
|
|
8
|
+
id: "test-flow",
|
|
9
|
+
data: {
|
|
10
|
+
name: {
|
|
11
|
+
first: "Alex",
|
|
12
|
+
last: "Fimbres",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
views: [
|
|
16
|
+
{
|
|
17
|
+
id: "view-1",
|
|
18
|
+
type: "view",
|
|
19
|
+
value: "{{name.first}}",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "view-2",
|
|
23
|
+
type: "view",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
navigation: {
|
|
27
|
+
BEGIN: "FLOW_1",
|
|
28
|
+
FLOW_1: {
|
|
29
|
+
startState: "VIEW_1",
|
|
30
|
+
VIEW_1: {
|
|
31
|
+
state_type: "VIEW",
|
|
32
|
+
ref: "view-1",
|
|
33
|
+
attributes: {
|
|
34
|
+
stageData: true,
|
|
35
|
+
commitTransitions: ["VIEW_2", "ACTION_2"],
|
|
36
|
+
},
|
|
37
|
+
transitions: {
|
|
38
|
+
next: "VIEW_2",
|
|
39
|
+
"*": "ACTION_1",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
ACTION_1: {
|
|
43
|
+
state_type: "ACTION",
|
|
44
|
+
exp: "",
|
|
45
|
+
transitions: {
|
|
46
|
+
"*": "VIEW_2",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
VIEW_2: {
|
|
50
|
+
state_type: "VIEW",
|
|
51
|
+
ref: "view-2",
|
|
52
|
+
transitions: {
|
|
53
|
+
"*": "ACTION_1",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
describe("Stage-Revert-Data plugin", () => {
|
|
61
|
+
let player: Player;
|
|
62
|
+
let dataController: DataController;
|
|
63
|
+
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
player = new Player({
|
|
66
|
+
plugins: [new StageRevertDataPlugin()],
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
player.hooks.dataController.tap("test", (dc) => {
|
|
70
|
+
dataController = dc;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
player.start(dataChangeFlow);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should have the original data model upon loading the component", () => {
|
|
77
|
+
const state = player.getState() as InProgressState;
|
|
78
|
+
|
|
79
|
+
expect(state.controllers.data.get("")).toBe(dataChangeFlow.data);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("Should get the cached data even before a transition occurs on the flow", () => {
|
|
83
|
+
const state = player.getState() as InProgressState;
|
|
84
|
+
dataController.set([["name.first", "Christopher"]]);
|
|
85
|
+
|
|
86
|
+
expect(state.controllers.data.get("name.first")).toStrictEqual(
|
|
87
|
+
"Christopher",
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("should not update data model if transission step is not included in the commitTransition list provided on attributes", async () => {
|
|
92
|
+
const state = player.getState() as InProgressState;
|
|
93
|
+
|
|
94
|
+
dataController.set([["name.first", "Christopher"]]);
|
|
95
|
+
|
|
96
|
+
state.controllers.flow.transition("action");
|
|
97
|
+
|
|
98
|
+
expect(state.controllers.data.get("name.first")).toBe("Alex");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("Should display the cached value on the view before transition", async () => {
|
|
102
|
+
const state = player.getState() as InProgressState;
|
|
103
|
+
|
|
104
|
+
dataController.set([["name.first", "Christopher"]]);
|
|
105
|
+
|
|
106
|
+
await vitest.waitFor(() => {
|
|
107
|
+
expect(
|
|
108
|
+
state.controllers.view.currentView?.lastUpdate?.value,
|
|
109
|
+
).toStrictEqual("Christopher");
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("should have committed to data model when a listed transition reference happened", () => {
|
|
114
|
+
const state = player.getState() as InProgressState;
|
|
115
|
+
|
|
116
|
+
dataController.set([
|
|
117
|
+
["name.first", "Christopher"],
|
|
118
|
+
["name.last", "Alvarez"],
|
|
119
|
+
["name.middle", "F"],
|
|
120
|
+
]);
|
|
121
|
+
|
|
122
|
+
state.controllers.flow.transition("next");
|
|
123
|
+
|
|
124
|
+
expect(state.controllers.data.get("")).toStrictEqual({
|
|
125
|
+
name: {
|
|
126
|
+
first: "Christopher",
|
|
127
|
+
last: "Alvarez",
|
|
128
|
+
middle: "F",
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("Testing without stageData flag on attribtues (Plugin not active on View)", () => {
|
|
134
|
+
const dataChangeFlow2: Flow = {
|
|
135
|
+
id: "test-flow",
|
|
136
|
+
data: {
|
|
137
|
+
name: {
|
|
138
|
+
first: "Alex",
|
|
139
|
+
last: "Fimbres",
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
views: [
|
|
143
|
+
{
|
|
144
|
+
id: "view-1",
|
|
145
|
+
type: "view",
|
|
146
|
+
value: "{{name.first}}",
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
id: "view-2",
|
|
150
|
+
type: "view",
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
navigation: {
|
|
154
|
+
BEGIN: "FLOW_1",
|
|
155
|
+
FLOW_1: {
|
|
156
|
+
startState: "VIEW_1",
|
|
157
|
+
VIEW_1: {
|
|
158
|
+
state_type: "VIEW",
|
|
159
|
+
ref: "view-1",
|
|
160
|
+
transitions: {
|
|
161
|
+
"*": "ACTION_1",
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
ACTION_1: {
|
|
165
|
+
state_type: "ACTION",
|
|
166
|
+
exp: "",
|
|
167
|
+
transitions: {
|
|
168
|
+
"*": "VIEW_2",
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
VIEW_2: {
|
|
172
|
+
state_type: "VIEW",
|
|
173
|
+
ref: "view-2",
|
|
174
|
+
transitions: {
|
|
175
|
+
"*": "END_DONE",
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
END_DONE: {
|
|
179
|
+
state_type: "END",
|
|
180
|
+
outcome: "done",
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
let playerNoPluginActive: Player;
|
|
186
|
+
let dcNoPluginActive: DataController;
|
|
187
|
+
|
|
188
|
+
beforeAll(() => {
|
|
189
|
+
playerNoPluginActive = new Player({
|
|
190
|
+
plugins: [new StageRevertDataPlugin()],
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
playerNoPluginActive.hooks.dataController.tap("test", (dc) => {
|
|
194
|
+
dcNoPluginActive = dc;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
playerNoPluginActive.start(dataChangeFlow2);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("Data model should have data committed as usual", () => {
|
|
201
|
+
dcNoPluginActive.set([["name.first", "Christopher"]]);
|
|
202
|
+
|
|
203
|
+
const state = playerNoPluginActive.getState() as InProgressState;
|
|
204
|
+
|
|
205
|
+
expect(state.controllers.data.get("name.first")).toBe("Christopher");
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { Player, DataController, PlayerPlugin } from
|
|
2
|
-
import { ValidationMiddleware } from
|
|
1
|
+
import type { Player, DataController, PlayerPlugin } from "@player-ui/player";
|
|
2
|
+
import { ValidationMiddleware } from "@player-ui/player";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* this plugin is supposed to stage/store changes in a local object/cache, until a transition happens,
|
|
6
6
|
* then changes are committed to the Data Model
|
|
7
7
|
*/
|
|
8
8
|
export class StageRevertDataPlugin implements PlayerPlugin {
|
|
9
|
-
name =
|
|
9
|
+
name = "stage-revert-data-plugin";
|
|
10
10
|
|
|
11
11
|
apply(player: Player) {
|
|
12
12
|
let dataController: DataController;
|
|
@@ -19,10 +19,10 @@ export class StageRevertDataPlugin implements PlayerPlugin {
|
|
|
19
19
|
commitShadowModel
|
|
20
20
|
? undefined
|
|
21
21
|
: {
|
|
22
|
-
message:
|
|
23
|
-
severity:
|
|
22
|
+
message: "staging data",
|
|
23
|
+
severity: "error",
|
|
24
24
|
},
|
|
25
|
-
{ shouldIncludeInvalid: () => true }
|
|
25
|
+
{ shouldIncludeInvalid: () => true },
|
|
26
26
|
);
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -52,8 +52,8 @@ export class StageRevertDataPlugin implements PlayerPlugin {
|
|
|
52
52
|
if (commitTransitions.includes(to.name)) {
|
|
53
53
|
commitShadowModel = true;
|
|
54
54
|
player.logger.debug(
|
|
55
|
-
|
|
56
|
-
GatedDataMiddleware.shadowModelPaths
|
|
55
|
+
"Shadow Model Data to be committed %s",
|
|
56
|
+
GatedDataMiddleware.shadowModelPaths,
|
|
57
57
|
);
|
|
58
58
|
dataController.set(GatedDataMiddleware.shadowModelPaths);
|
|
59
59
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { Player, PlayerPlugin } from "@player-ui/player";
|
|
3
2
|
/**
|
|
4
3
|
* this plugin is supposed to stage/store changes in a local object/cache, until a transition happens,
|
|
5
4
|
* then changes are committed to the Data Model
|
|
6
5
|
*/
|
|
7
|
-
declare class StageRevertDataPlugin implements PlayerPlugin {
|
|
6
|
+
export declare class StageRevertDataPlugin implements PlayerPlugin {
|
|
8
7
|
name: string;
|
|
9
8
|
apply(player: Player): void;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
export { StageRevertDataPlugin };
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.cjs.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var player = require('@player-ui/player');
|
|
6
|
-
|
|
7
|
-
class StageRevertDataPlugin {
|
|
8
|
-
constructor() {
|
|
9
|
-
this.name = "stage-revert-data-plugin";
|
|
10
|
-
}
|
|
11
|
-
apply(player$1) {
|
|
12
|
-
let dataController;
|
|
13
|
-
let commitTransitions;
|
|
14
|
-
let stageData;
|
|
15
|
-
let commitShadowModel = false;
|
|
16
|
-
const GatedDataMiddleware = new player.ValidationMiddleware(() => commitShadowModel ? void 0 : {
|
|
17
|
-
message: "staging data",
|
|
18
|
-
severity: "error"
|
|
19
|
-
}, { shouldIncludeInvalid: () => true });
|
|
20
|
-
player$1.hooks.dataController.tap(this.name, (dc) => {
|
|
21
|
-
dataController = dc;
|
|
22
|
-
dc.hooks.resolveDataStages.tap(this.name, (dataPipeline) => {
|
|
23
|
-
return stageData ? [...dataPipeline, GatedDataMiddleware] : [...dataPipeline];
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
player$1.hooks.flowController.tap(this.name, (flowController) => {
|
|
27
|
-
flowController.hooks.flow.tap(this.name, (flow) => {
|
|
28
|
-
flow.hooks.transition.tap(this.name, (from, to) => {
|
|
29
|
-
if (from) {
|
|
30
|
-
if (commitTransitions.includes(to.name)) {
|
|
31
|
-
commitShadowModel = true;
|
|
32
|
-
player$1.logger.debug("Shadow Model Data to be committed %s", GatedDataMiddleware.shadowModelPaths);
|
|
33
|
-
dataController.set(GatedDataMiddleware.shadowModelPaths);
|
|
34
|
-
}
|
|
35
|
-
commitShadowModel = false;
|
|
36
|
-
GatedDataMiddleware.shadowModelPaths.clear();
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
player$1.hooks.viewController.tap(this.name, (vc) => {
|
|
42
|
-
vc.hooks.resolveView.intercept({
|
|
43
|
-
call: (view, id, state) => {
|
|
44
|
-
var _a, _b;
|
|
45
|
-
stageData = (_a = state == null ? void 0 : state.attributes) == null ? void 0 : _a.stageData;
|
|
46
|
-
commitTransitions = (_b = state == null ? void 0 : state.attributes) == null ? void 0 : _b.commitTransitions;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
exports.StageRevertDataPlugin = StageRevertDataPlugin;
|
|
54
|
-
//# sourceMappingURL=index.cjs.js.map
|