@player-ui/shared-constants-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.
@@ -0,0 +1,88 @@
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/shared-constants/core/src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ ConstantsPlugin: () => ConstantsPlugin
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+ var import_player = require("@player-ui/player");
37
+ var import_dlv = __toESM(require("dlv"));
38
+ var ConstantsPlugin = class {
39
+ /**
40
+ * Store the initial constants in the constant map
41
+ */
42
+ constructor(params) {
43
+ this.name = "constants";
44
+ /** Functions to update the constants within applied players */
45
+ this.updatePlayerConstants = /* @__PURE__ */ new Set();
46
+ this.data = params.data;
47
+ this.namespace = params.namespace ?? "constants";
48
+ this.dataPath = new import_player.BindingInstance(
49
+ params.dataPath ?? ["data", "constants"]
50
+ );
51
+ }
52
+ /**
53
+ * Grab constants from content then store them store them over after every content
54
+ */
55
+ apply(player) {
56
+ const updatePlayerConstants = () => player.constantsController.addConstants(this.data, this.namespace);
57
+ updatePlayerConstants();
58
+ player.hooks.onStart.tap(this.name, (flowObj) => {
59
+ this.updatePlayerConstants.add(updatePlayerConstants);
60
+ updatePlayerConstants();
61
+ const tempData = (0, import_dlv.default)(flowObj, this.dataPath.asString()) ?? {};
62
+ player.constantsController.clearTemporaryValues(this.namespace);
63
+ player.constantsController.setTemporaryValues(tempData, this.namespace);
64
+ });
65
+ player.hooks.onEnd.tap(this.name, () => {
66
+ player.constantsController.clearTemporaryValues(this.namespace);
67
+ this.updatePlayerConstants.delete(updatePlayerConstants);
68
+ });
69
+ }
70
+ /** Update constants for all active players */
71
+ updateConstants() {
72
+ this.updatePlayerConstants.forEach((update) => update());
73
+ }
74
+ /** Get constants for this namespace */
75
+ getConstants() {
76
+ return this.data;
77
+ }
78
+ /** Update constants for this namespace */
79
+ setConstants(data) {
80
+ this.data = data;
81
+ this.updateConstants();
82
+ }
83
+ };
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
86
+ ConstantsPlugin
87
+ });
88
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/shared-constants/core/src/index.ts"],"sourcesContent":["import type { Player, PlayerPlugin } from \"@player-ui/player\";\nimport { BindingInstance } from \"@player-ui/player\";\nimport get from \"dlv\";\n\nexport interface ConstantsPluginConfig {\n /** Constants defined in an Content */\n data: any;\n\n /** Namespace to store the constants under. If none is specified it defaults to constants */\n namespace?: string;\n\n /** Path to data in the content root to apply as temporary data */\n dataPath?: string;\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 ConstantsPlugin implements PlayerPlugin {\n name = \"constants\";\n\n /**\n * Namespace to store the constants under\n * If none is specified it defaults to constants\n */\n private namespace: string;\n\n /** Constants defined in an Content */\n private data: Record<string, any>;\n\n /** Path to data in the content root to apply as temporary data */\n private dataPath: BindingInstance;\n\n /** Functions to update the constants within applied players */\n private updatePlayerConstants: Set<() => void> = new Set();\n\n /**\n * Store the initial constants in the constant map\n */\n constructor(params: ConstantsPluginConfig) {\n this.data = params.data;\n this.namespace = params.namespace ?? \"constants\";\n this.dataPath = new BindingInstance(\n params.dataPath ?? [\"data\", \"constants\"],\n );\n }\n\n /**\n * Grab constants from content then store them store them over after every content\n */\n apply(player: Player) {\n /** Update constants for this player */\n const updatePlayerConstants = () =>\n player.constantsController.addConstants(this.data, this.namespace);\n updatePlayerConstants();\n\n // Setup hook to load latest constants and flow specific overrides to constants\n player.hooks.onStart.tap(this.name, (flowObj) => {\n this.updatePlayerConstants.add(updatePlayerConstants);\n updatePlayerConstants();\n\n const tempData = get(flowObj, this.dataPath.asString()) ?? {};\n player.constantsController.clearTemporaryValues(this.namespace);\n player.constantsController.setTemporaryValues(tempData, this.namespace);\n });\n // Clear flow specific overrides at the end of the flow and remove strong ref to player\n player.hooks.onEnd.tap(this.name, () => {\n player.constantsController.clearTemporaryValues(this.namespace);\n\n this.updatePlayerConstants.delete(updatePlayerConstants);\n });\n }\n\n /** Update constants for all active players */\n private updateConstants() {\n this.updatePlayerConstants.forEach((update) => update());\n }\n\n /** Get constants for this namespace */\n getConstants(): any {\n return this.data;\n }\n\n /** Update constants for this namespace */\n setConstants(data: any) {\n this.data = data;\n this.updateConstants();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAgC;AAChC,iBAAgB;AAiBT,IAAM,kBAAN,MAA8C;AAAA;AAAA;AAAA;AAAA,EAqBnD,YAAY,QAA+B;AApB3C,gBAAO;AAeP;AAAA,SAAQ,wBAAyC,oBAAI,IAAI;AAMvD,SAAK,OAAO,OAAO;AACnB,SAAK,YAAY,OAAO,aAAa;AACrC,SAAK,WAAW,IAAI;AAAA,MAClB,OAAO,YAAY,CAAC,QAAQ,WAAW;AAAA,IACzC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAgB;AAEpB,UAAM,wBAAwB,MAC5B,OAAO,oBAAoB,aAAa,KAAK,MAAM,KAAK,SAAS;AACnE,0BAAsB;AAGtB,WAAO,MAAM,QAAQ,IAAI,KAAK,MAAM,CAAC,YAAY;AAC/C,WAAK,sBAAsB,IAAI,qBAAqB;AACpD,4BAAsB;AAEtB,YAAM,eAAW,WAAAA,SAAI,SAAS,KAAK,SAAS,SAAS,CAAC,KAAK,CAAC;AAC5D,aAAO,oBAAoB,qBAAqB,KAAK,SAAS;AAC9D,aAAO,oBAAoB,mBAAmB,UAAU,KAAK,SAAS;AAAA,IACxE,CAAC;AAED,WAAO,MAAM,MAAM,IAAI,KAAK,MAAM,MAAM;AACtC,aAAO,oBAAoB,qBAAqB,KAAK,SAAS;AAE9D,WAAK,sBAAsB,OAAO,qBAAqB;AAAA,IACzD,CAAC;AAAA,EACH;AAAA;AAAA,EAGQ,kBAAkB;AACxB,SAAK,sBAAsB,QAAQ,CAAC,WAAW,OAAO,CAAC;AAAA,EACzD;AAAA;AAAA,EAGA,eAAoB;AAClB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,aAAa,MAAW;AACtB,SAAK,OAAO;AACZ,SAAK,gBAAgB;AAAA,EACvB;AACF;","names":["get"]}
@@ -1,31 +1,30 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var player = require('@player-ui/player');
6
- var get = require('dlv');
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
- class ConstantsPlugin {
1
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/shared-constants/core/src/index.ts
2
+ import { BindingInstance } from "@player-ui/player";
3
+ import get from "dlv";
4
+ var ConstantsPlugin = class {
5
+ /**
6
+ * Store the initial constants in the constant map
7
+ */
13
8
  constructor(params) {
14
9
  this.name = "constants";
15
- this.updatePlayerConstants = new Set();
16
- var _a, _b;
10
+ /** Functions to update the constants within applied players */
11
+ this.updatePlayerConstants = /* @__PURE__ */ new Set();
17
12
  this.data = params.data;
18
- this.namespace = (_a = params.namespace) != null ? _a : "constants";
19
- this.dataPath = new player.BindingInstance((_b = params.dataPath) != null ? _b : ["data", "constants"]);
13
+ this.namespace = params.namespace ?? "constants";
14
+ this.dataPath = new BindingInstance(
15
+ params.dataPath ?? ["data", "constants"]
16
+ );
20
17
  }
18
+ /**
19
+ * Grab constants from content then store them store them over after every content
20
+ */
21
21
  apply(player) {
22
22
  const updatePlayerConstants = () => player.constantsController.addConstants(this.data, this.namespace);
23
23
  updatePlayerConstants();
24
24
  player.hooks.onStart.tap(this.name, (flowObj) => {
25
- var _a;
26
25
  this.updatePlayerConstants.add(updatePlayerConstants);
27
26
  updatePlayerConstants();
28
- const tempData = (_a = get__default["default"](flowObj, this.dataPath.asString())) != null ? _a : {};
27
+ const tempData = get(flowObj, this.dataPath.asString()) ?? {};
29
28
  player.constantsController.clearTemporaryValues(this.namespace);
30
29
  player.constantsController.setTemporaryValues(tempData, this.namespace);
31
30
  });
@@ -34,17 +33,21 @@ class ConstantsPlugin {
34
33
  this.updatePlayerConstants.delete(updatePlayerConstants);
35
34
  });
36
35
  }
36
+ /** Update constants for all active players */
37
37
  updateConstants() {
38
38
  this.updatePlayerConstants.forEach((update) => update());
39
39
  }
40
+ /** Get constants for this namespace */
40
41
  getConstants() {
41
42
  return this.data;
42
43
  }
44
+ /** Update constants for this namespace */
43
45
  setConstants(data) {
44
46
  this.data = data;
45
47
  this.updateConstants();
46
48
  }
47
- }
48
-
49
- exports.ConstantsPlugin = ConstantsPlugin;
50
- //# sourceMappingURL=index.cjs.js.map
49
+ };
50
+ export {
51
+ ConstantsPlugin
52
+ };
53
+ //# sourceMappingURL=index.mjs.map
@@ -1,23 +1,30 @@
1
- import { BindingInstance } from '@player-ui/player';
2
- import get from 'dlv';
3
-
4
- class ConstantsPlugin {
1
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/shared-constants/core/src/index.ts
2
+ import { BindingInstance } from "@player-ui/player";
3
+ import get from "dlv";
4
+ var ConstantsPlugin = class {
5
+ /**
6
+ * Store the initial constants in the constant map
7
+ */
5
8
  constructor(params) {
6
9
  this.name = "constants";
7
- this.updatePlayerConstants = new Set();
8
- var _a, _b;
10
+ /** Functions to update the constants within applied players */
11
+ this.updatePlayerConstants = /* @__PURE__ */ new Set();
9
12
  this.data = params.data;
10
- this.namespace = (_a = params.namespace) != null ? _a : "constants";
11
- this.dataPath = new BindingInstance((_b = params.dataPath) != null ? _b : ["data", "constants"]);
13
+ this.namespace = params.namespace ?? "constants";
14
+ this.dataPath = new BindingInstance(
15
+ params.dataPath ?? ["data", "constants"]
16
+ );
12
17
  }
18
+ /**
19
+ * Grab constants from content then store them store them over after every content
20
+ */
13
21
  apply(player) {
14
22
  const updatePlayerConstants = () => player.constantsController.addConstants(this.data, this.namespace);
15
23
  updatePlayerConstants();
16
24
  player.hooks.onStart.tap(this.name, (flowObj) => {
17
- var _a;
18
25
  this.updatePlayerConstants.add(updatePlayerConstants);
19
26
  updatePlayerConstants();
20
- const tempData = (_a = get(flowObj, this.dataPath.asString())) != null ? _a : {};
27
+ const tempData = get(flowObj, this.dataPath.asString()) ?? {};
21
28
  player.constantsController.clearTemporaryValues(this.namespace);
22
29
  player.constantsController.setTemporaryValues(tempData, this.namespace);
23
30
  });
@@ -26,17 +33,21 @@ class ConstantsPlugin {
26
33
  this.updatePlayerConstants.delete(updatePlayerConstants);
27
34
  });
28
35
  }
36
+ /** Update constants for all active players */
29
37
  updateConstants() {
30
38
  this.updatePlayerConstants.forEach((update) => update());
31
39
  }
40
+ /** Get constants for this namespace */
32
41
  getConstants() {
33
42
  return this.data;
34
43
  }
44
+ /** Update constants for this namespace */
35
45
  setConstants(data) {
36
46
  this.data = data;
37
47
  this.updateConstants();
38
48
  }
39
- }
40
-
41
- export { ConstantsPlugin };
42
- //# sourceMappingURL=index.esm.js.map
49
+ };
50
+ export {
51
+ ConstantsPlugin
52
+ };
53
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/shared-constants/core/src/index.ts"],"sourcesContent":["import type { Player, PlayerPlugin } from \"@player-ui/player\";\nimport { BindingInstance } from \"@player-ui/player\";\nimport get from \"dlv\";\n\nexport interface ConstantsPluginConfig {\n /** Constants defined in an Content */\n data: any;\n\n /** Namespace to store the constants under. If none is specified it defaults to constants */\n namespace?: string;\n\n /** Path to data in the content root to apply as temporary data */\n dataPath?: string;\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 ConstantsPlugin implements PlayerPlugin {\n name = \"constants\";\n\n /**\n * Namespace to store the constants under\n * If none is specified it defaults to constants\n */\n private namespace: string;\n\n /** Constants defined in an Content */\n private data: Record<string, any>;\n\n /** Path to data in the content root to apply as temporary data */\n private dataPath: BindingInstance;\n\n /** Functions to update the constants within applied players */\n private updatePlayerConstants: Set<() => void> = new Set();\n\n /**\n * Store the initial constants in the constant map\n */\n constructor(params: ConstantsPluginConfig) {\n this.data = params.data;\n this.namespace = params.namespace ?? \"constants\";\n this.dataPath = new BindingInstance(\n params.dataPath ?? [\"data\", \"constants\"],\n );\n }\n\n /**\n * Grab constants from content then store them store them over after every content\n */\n apply(player: Player) {\n /** Update constants for this player */\n const updatePlayerConstants = () =>\n player.constantsController.addConstants(this.data, this.namespace);\n updatePlayerConstants();\n\n // Setup hook to load latest constants and flow specific overrides to constants\n player.hooks.onStart.tap(this.name, (flowObj) => {\n this.updatePlayerConstants.add(updatePlayerConstants);\n updatePlayerConstants();\n\n const tempData = get(flowObj, this.dataPath.asString()) ?? {};\n player.constantsController.clearTemporaryValues(this.namespace);\n player.constantsController.setTemporaryValues(tempData, this.namespace);\n });\n // Clear flow specific overrides at the end of the flow and remove strong ref to player\n player.hooks.onEnd.tap(this.name, () => {\n player.constantsController.clearTemporaryValues(this.namespace);\n\n this.updatePlayerConstants.delete(updatePlayerConstants);\n });\n }\n\n /** Update constants for all active players */\n private updateConstants() {\n this.updatePlayerConstants.forEach((update) => update());\n }\n\n /** Get constants for this namespace */\n getConstants(): any {\n return this.data;\n }\n\n /** Update constants for this namespace */\n setConstants(data: any) {\n this.data = data;\n this.updateConstants();\n }\n}\n"],"mappings":";AACA,SAAS,uBAAuB;AAChC,OAAO,SAAS;AAiBT,IAAM,kBAAN,MAA8C;AAAA;AAAA;AAAA;AAAA,EAqBnD,YAAY,QAA+B;AApB3C,gBAAO;AAeP;AAAA,SAAQ,wBAAyC,oBAAI,IAAI;AAMvD,SAAK,OAAO,OAAO;AACnB,SAAK,YAAY,OAAO,aAAa;AACrC,SAAK,WAAW,IAAI;AAAA,MAClB,OAAO,YAAY,CAAC,QAAQ,WAAW;AAAA,IACzC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAgB;AAEpB,UAAM,wBAAwB,MAC5B,OAAO,oBAAoB,aAAa,KAAK,MAAM,KAAK,SAAS;AACnE,0BAAsB;AAGtB,WAAO,MAAM,QAAQ,IAAI,KAAK,MAAM,CAAC,YAAY;AAC/C,WAAK,sBAAsB,IAAI,qBAAqB;AACpD,4BAAsB;AAEtB,YAAM,WAAW,IAAI,SAAS,KAAK,SAAS,SAAS,CAAC,KAAK,CAAC;AAC5D,aAAO,oBAAoB,qBAAqB,KAAK,SAAS;AAC9D,aAAO,oBAAoB,mBAAmB,UAAU,KAAK,SAAS;AAAA,IACxE,CAAC;AAED,WAAO,MAAM,MAAM,IAAI,KAAK,MAAM,MAAM;AACtC,aAAO,oBAAoB,qBAAqB,KAAK,SAAS;AAE9D,WAAK,sBAAsB,OAAO,qBAAqB;AAAA,IACzD,CAAC;AAAA,EACH;AAAA;AAAA,EAGQ,kBAAkB;AACxB,SAAK,sBAAsB,QAAQ,CAAC,WAAW,OAAO,CAAC;AAAA,EACzD;AAAA;AAAA,EAGA,eAAoB;AAClB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,aAAa,MAAW;AACtB,SAAK,OAAO;AACZ,SAAK,gBAAgB;AAAA,EACvB;AACF;","names":[]}
package/package.json CHANGED
@@ -1,67 +1,35 @@
1
1
  {
2
2
  "name": "@player-ui/shared-constants-plugin",
3
- "version": "0.8.0--canary.307.9621",
4
- "private": false,
5
- "publishConfig": {
6
- "registry": "https://registry.npmjs.org"
3
+ "version": "0.8.0-next.0",
4
+ "main": "dist/cjs/index.cjs",
5
+ "devDependencies": {
6
+ "@player-ui/common-types-plugin": "workspace:*",
7
+ "@player-ui/make-flow": "workspace:*"
7
8
  },
8
9
  "peerDependencies": {
9
- "@player-ui/player": "0.8.0--canary.307.9621"
10
+ "@player-ui/player": "0.8.0-next.0"
10
11
  },
11
- "dependencies": {
12
- "tapable-ts": "^0.2.3",
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",
12
+ "module": "dist/index.legacy-esm.js",
13
+ "types": "types/index.d.ts",
19
14
  "sideEffects": false,
20
- "license": "MIT",
21
- "repository": {
22
- "type": "git",
23
- "url": "https://github.com/player-ui/player-ui"
24
- },
25
- "bugs": {
26
- "url": "https://github.com/player-ui/player-ui/issues"
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"
15
+ "exports": {
16
+ "./package.json": "./package.json",
17
+ "./dist/index.css": "./dist/index.css",
18
+ ".": {
19
+ "types": "./types/index.d.ts",
20
+ "import": "./dist/index.mjs",
21
+ "default": "./dist/cjs/index.cjs"
65
22
  }
66
- ]
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "src",
27
+ "types"
28
+ ],
29
+ "dependencies": {
30
+ "@types/dlv": "^1.1.4",
31
+ "dlv": "^1.1.3",
32
+ "tapable-ts": "^0.2.3",
33
+ "tslib": "^2.6.2"
34
+ }
67
35
  }
@@ -0,0 +1,206 @@
1
+ import { vitest, test, describe, expect } from "vitest";
2
+ import type { InProgressState, Flow } from "@player-ui/player";
3
+ import { Player } from "@player-ui/player";
4
+ import { makeFlow } from "@player-ui/make-flow";
5
+ import { CommonTypesPlugin } from "@player-ui/common-types-plugin";
6
+ import { ConstantsPlugin } from "..";
7
+
8
+ test("basic value overriding", async () => {
9
+ const flow: Flow = makeFlow({
10
+ id: "view-1",
11
+ type: "view",
12
+ thing1: {
13
+ asset: {
14
+ id: "input-1",
15
+ type: "input",
16
+ binding: "person.name",
17
+ label: {
18
+ asset: {
19
+ id: "input-2-label",
20
+ type: "text",
21
+ value: "Name",
22
+ },
23
+ },
24
+ },
25
+ },
26
+ });
27
+
28
+ flow.schema = {
29
+ ROOT: {
30
+ person: {
31
+ type: "PersonType",
32
+ },
33
+ },
34
+ PersonType: {
35
+ name: {
36
+ type: "StringType",
37
+ validation: [
38
+ {
39
+ type: "length",
40
+ max: 20,
41
+ min: 5,
42
+ },
43
+ {
44
+ type: "string",
45
+ },
46
+ ],
47
+ },
48
+ },
49
+ };
50
+
51
+ flow.data = {
52
+ constants: {
53
+ validation: {
54
+ length: {
55
+ maximum: "This should be returned",
56
+ },
57
+ },
58
+ },
59
+ };
60
+
61
+ const constantsData = {
62
+ validation: {
63
+ length: {
64
+ minimum: "Way to short",
65
+ maximum: "This should not be returned",
66
+ },
67
+ },
68
+ };
69
+
70
+ const pluginConfig = {
71
+ data: constantsData,
72
+ namespace: "constants",
73
+ dataPath: "data.constants",
74
+ };
75
+ const player = new Player({
76
+ plugins: [new CommonTypesPlugin(), new ConstantsPlugin(pluginConfig)],
77
+ });
78
+
79
+ // Add tap to get validation information
80
+ player.hooks.viewController.tap("test", (vc) => {
81
+ vc.hooks.view.tap("test", (view) => {
82
+ view.hooks.resolver.tap("test", (resolver) => {
83
+ resolver.hooks.resolve.tap("test", (val, node, options) => {
84
+ if (val?.binding) {
85
+ options.validation?.track(val.binding);
86
+ const valObj = options.validation?.get(val.binding);
87
+
88
+ if (valObj) {
89
+ return {
90
+ ...val,
91
+ validation: valObj,
92
+ allValidations: options.validation?.getAll(),
93
+ };
94
+ }
95
+ }
96
+
97
+ return val;
98
+ });
99
+ });
100
+ });
101
+ });
102
+
103
+ player.start(flow);
104
+ let state = player.getState() as InProgressState;
105
+
106
+ /** Start of Tests */
107
+
108
+ // Test default error message
109
+ state.controllers.data.set([["person.name", 0]]);
110
+ expect(state.controllers.data.get("person.name")).toBe("");
111
+ await vitest.waitFor(() =>
112
+ expect(
113
+ state.controllers.view.currentView?.lastUpdate?.thing1.asset.validation
114
+ .message,
115
+ ).toBe("Value must be a string"),
116
+ );
117
+
118
+ // Test error message set in constants plugin
119
+ state.controllers.data.set([["person.name", "adam"]]);
120
+ expect(state.controllers.data.get("person.name")).toBe("");
121
+ await vitest.waitFor(() =>
122
+ expect(
123
+ state.controllers.view.currentView?.lastUpdate?.thing1.asset.validation
124
+ .message,
125
+ ).toBe("Way to short"),
126
+ );
127
+
128
+ // Test error message set in constants plugin but overridden in content
129
+ state.controllers.data.set([
130
+ [
131
+ "person.name",
132
+ "This is a really long name, like a really long name. Who would have a name this long",
133
+ ],
134
+ ]);
135
+ expect(state.controllers.data.get("person.name")).toBe("");
136
+ await vitest.waitFor(() =>
137
+ expect(
138
+ state.controllers.view.currentView?.lastUpdate?.thing1.asset.validation
139
+ .message,
140
+ ).toBe("This should be returned"),
141
+ );
142
+
143
+ // Restart Player and clear content data to make sure expected error messsage is returned
144
+
145
+ flow.data = {};
146
+ player.start(flow);
147
+ state = player.getState() as InProgressState;
148
+
149
+ // Make sure temp error message is reset
150
+ state.controllers.data.set([
151
+ ["person.name", "Superlongnamethatisovertwentycharacters"],
152
+ ]);
153
+ expect(state.controllers.data.get("person.name")).toBe("");
154
+ await vitest.waitFor(() =>
155
+ expect(
156
+ state.controllers.view.currentView?.lastUpdate?.thing1.asset.validation
157
+ .message,
158
+ ).toBe("This should not be returned"),
159
+ );
160
+ });
161
+
162
+ describe("can get and update constants", () => {
163
+ const flow: Flow = makeFlow({
164
+ id: "view-1",
165
+ type: "view",
166
+ });
167
+
168
+ test("can get all constants for namespace", () => {
169
+ const data = { one: 1 };
170
+ const plugin = new ConstantsPlugin({ data, namespace: "test" });
171
+
172
+ expect(plugin.getConstants()).toStrictEqual(data);
173
+ });
174
+
175
+ test("can get initial data", () => {
176
+ const plugin = new ConstantsPlugin({ data: { one: 1 }, namespace: "test" });
177
+ const player = new Player({ plugins: [plugin] });
178
+
179
+ expect(player.constantsController.getConstants("one", "test")).toBe(1);
180
+ });
181
+
182
+ test("can update data after instantiation", () => {
183
+ const plugin = new ConstantsPlugin({ data: { one: 1 }, namespace: "test" });
184
+ const player = new Player({ plugins: [plugin] });
185
+
186
+ plugin.setConstants({ one: 2 });
187
+
188
+ player.start(flow);
189
+
190
+ expect(player.constantsController.getConstants("one", "test")).toBe(2);
191
+ });
192
+
193
+ test("updates constants for multiple players", () => {
194
+ const plugin = new ConstantsPlugin({ data: { one: 1 }, namespace: "test" });
195
+ const player1 = new Player({ plugins: [plugin] });
196
+ const player2 = new Player({ plugins: [plugin] });
197
+
198
+ plugin.setConstants({ one: 2 });
199
+
200
+ player1.start(flow);
201
+ player2.start(flow);
202
+
203
+ expect(player1.constantsController.getConstants("one", "test")).toBe(2);
204
+ expect(player2.constantsController.getConstants("one", "test")).toBe(2);
205
+ });
206
+ });
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { Player, PlayerPlugin } from '@player-ui/player';
2
- import { BindingInstance } from '@player-ui/player';
3
- import get from 'dlv';
1
+ import type { Player, PlayerPlugin } from "@player-ui/player";
2
+ import { BindingInstance } from "@player-ui/player";
3
+ import get from "dlv";
4
4
 
5
5
  export interface ConstantsPluginConfig {
6
6
  /** Constants defined in an Content */
@@ -18,7 +18,7 @@ export interface ConstantsPluginConfig {
18
18
  * It allows for runtime extensions/overrides through a `constants` property in the flow
19
19
  */
20
20
  export class ConstantsPlugin implements PlayerPlugin {
21
- name = 'constants';
21
+ name = "constants";
22
22
 
23
23
  /**
24
24
  * Namespace to store the constants under
@@ -40,9 +40,9 @@ export class ConstantsPlugin implements PlayerPlugin {
40
40
  */
41
41
  constructor(params: ConstantsPluginConfig) {
42
42
  this.data = params.data;
43
- this.namespace = params.namespace ?? 'constants';
43
+ this.namespace = params.namespace ?? "constants";
44
44
  this.dataPath = new BindingInstance(
45
- params.dataPath ?? ['data', 'constants']
45
+ params.dataPath ?? ["data", "constants"],
46
46
  );
47
47
  }
48
48
 
@@ -1,6 +1,5 @@
1
- import { PlayerPlugin, Player } from '@player-ui/player';
2
-
3
- interface ConstantsPluginConfig {
1
+ import type { Player, PlayerPlugin } from "@player-ui/player";
2
+ export interface ConstantsPluginConfig {
4
3
  /** Constants defined in an Content */
5
4
  data: any;
6
5
  /** Namespace to store the constants under. If none is specified it defaults to constants */
@@ -12,7 +11,7 @@ interface ConstantsPluginConfig {
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 ConstantsPlugin implements PlayerPlugin {
14
+ export declare class ConstantsPlugin implements PlayerPlugin {
16
15
  name: string;
17
16
  /**
18
17
  * Namespace to store the constants under
@@ -40,5 +39,4 @@ declare class ConstantsPlugin implements PlayerPlugin {
40
39
  /** Update constants for this namespace */
41
40
  setConstants(data: any): void;
42
41
  }
43
-
44
- export { ConstantsPlugin, ConstantsPluginConfig };
42
+ //# sourceMappingURL=index.d.ts.map