@player-ui/computed-properties-plugin 0.15.3-next.1 → 0.15.3-next.2

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.
@@ -52,20 +52,20 @@ var ComputedPropertiesPlugin = function() {
52
52
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
53
53
  var __getOwnPropNames = Object.getOwnPropertyNames;
54
54
  var __hasOwnProp = Object.prototype.hasOwnProperty;
55
- var __export = function(target, all) {
55
+ var __export = function __export(target, all) {
56
56
  for(var name in all)__defProp(target, name, {
57
57
  get: all[name],
58
58
  enumerable: true
59
59
  });
60
60
  };
61
- var __copyProps = function(to, from, except, desc) {
61
+ var __copyProps = function __copyProps(to, from, except, desc) {
62
62
  if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
63
63
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
64
64
  try {
65
65
  var _loop = function() {
66
66
  var key = _step.value;
67
67
  if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
68
- get: function() {
68
+ get: function get() {
69
69
  return from[key];
70
70
  },
71
71
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
@@ -89,7 +89,7 @@ var ComputedPropertiesPlugin = function() {
89
89
  }
90
90
  return to;
91
91
  };
92
- var __toCommonJS = function(mod) {
92
+ var __toCommonJS = function __toCommonJS(mod) {
93
93
  return __copyProps(__defProp({}, "__esModule", {
94
94
  value: true
95
95
  }), mod);
@@ -97,7 +97,7 @@ var ComputedPropertiesPlugin = function() {
97
97
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/computed-properties/core/src/index.ts
98
98
  var src_exports = {};
99
99
  __export(src_exports, {
100
- ComputedPropertiesPlugin: function() {
100
+ ComputedPropertiesPlugin: function ComputedPropertiesPlugin1() {
101
101
  return ComputedPropertiesPlugin;
102
102
  }
103
103
  });
@@ -113,7 +113,7 @@ var ComputedPropertiesPlugin = function() {
113
113
  var _this = this;
114
114
  var schemaController;
115
115
  var expressionEvaluator;
116
- var getExpressionType = function(binding) {
116
+ var getExpressionType = function getExpressionType(binding) {
117
117
  var dataType = schemaController === null || schemaController === void 0 ? void 0 : schemaController.getType(binding);
118
118
  if ((dataType === null || dataType === void 0 ? void 0 : dataType.type) === "Expression") {
119
119
  return dataType;
@@ -131,6 +131,7 @@ var ComputedPropertiesPlugin = function() {
131
131
  return next === null || next === void 0 ? void 0 : next.get(binding, options);
132
132
  },
133
133
  set: function set(transaction, options, next) {
134
+ var _ref;
134
135
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
135
136
  try {
136
137
  for(var _iterator = transaction[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -153,8 +154,7 @@ var ComputedPropertiesPlugin = function() {
153
154
  }
154
155
  }
155
156
  }
156
- var _next_set;
157
- return (_next_set = next === null || next === void 0 ? void 0 : next.set(transaction, options)) !== null && _next_set !== void 0 ? _next_set : [];
157
+ return (_ref = next === null || next === void 0 ? void 0 : next.set(transaction, options)) !== null && _ref !== void 0 ? _ref : [];
158
158
  },
159
159
  delete: function _delete(binding, options, next) {
160
160
  if (getExpressionType(binding)) {
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2505/execroot/_main/bazel-out/k8-fastbuild/bin/plugins/computed-properties/core/dist/index.global.js","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/computed-properties/core/src/index.ts"],"names":["ComputedPropertiesPlugin","__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","src_exports","apply","player","schemaController","expressionEvaluator","getExpressionType","binding","dataType","getType","type","computedPropertyMiddleware","options","next","expType","exp","result","evaluate","context","default","set","transaction","setOperation","Error","asString","delete","hooks","dataController","tap","resolveDataStages","dataPipeline","schema","evaluator"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAIA,2BAA2B,AAAC;IAC9B,IAAIC,YAAYC,OAAOC,cAAc;IACrC,IAAIC,mBAAmBF,OAAOG,wBAAwB;IACtD,IAAIC,oBAAoBJ,OAAOK,mBAAmB;IAClD,IAAIC,eAAeN,OAAOO,SAAS,CAACC,cAAc;IAClD,IAAIC,WAAW,SAACC,QAAQC;QACtB,IAAK,IAAIC,QAAQD,IACfZ,UAAUW,QAAQE,MAAM;YAAEC,KAAKF,GAAG,CAACC,KAAK;YAAEE,YAAY;QAAK;IAC/D;IACA,IAAIC,cAAc,SAACC,IAAIC,MAAMC,QAAQC;QACnC,IAAIF,QAAQ,CAAA,OAAOA,qCAAP,SAAOA,KAAG,MAAM,YAAY,OAAOA,SAAS,YAAY;gBAC7D,kCAAA,2BAAA;;;oBAAA,IAAIG,MAAJ;oBACH,IAAI,CAACd,aAAae,IAAI,CAACL,IAAII,QAAQA,QAAQF,QACzCnB,UAAUiB,IAAII,KAAK;wBAAEP,KAAK;mCAAMI,IAAI,CAACG,IAAI;;wBAAEN,YAAY,CAAEK,CAAAA,OAAOjB,iBAAiBe,MAAMG,IAAG,KAAMD,KAAKL,UAAU;oBAAC;;gBAFpH,QAAK,YAAWV,kBAAkBa,0BAA7B,SAAA,6BAAA,QAAA,yBAAA;;gBAAA;gBAAA;;;yBAAA,6BAAA;wBAAA;;;wBAAA;8BAAA;;;;QAGP;QACA,OAAOD;IACT;IACA,IAAIM,eAAe,SAACC;eAAQR,YAAYhB,UAAU,CAAC,GAAG,cAAc;YAAEyB,OAAO;QAAK,IAAID;;IAEtF,2HAA2H;ICpB7H,IAAAE,cAAA,CAAA;IAAAhB,SAAA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O,GAAA,CAAIC,aAAaT,sBAAvBC,uBAAAA,YAAmC,EAAC;wBAC7C;wBACAY,QAAAA,SAAAA,QAAOlB,OAAA,EAASK,OAAA,EAASC,IAAA;4BACvB,IAAIP,kBAAkBC,UAAU;gCAC9B,MAAM,IAAIgB,MACR,oDAAsE,OAAlBhB,QAAQiB,QAAA;4BAEhE;4BAEA,OAAOX,iBAAAA,2BAAAA,KAAMY,MAAA,CAAOlB,SAASK;wBAC/B;oBACF;oBAEAT,OAAOuB,KAAA,CAAMC,cAAA,CAAeC,GAAA,CAAI,IAAA,CAAKxC,IAAA,EAAM,SAACuC;wBAC1CA,eAAeD,KAAA,CAAMG,iBAAA,CAAkBD,GAAA,CAAI,MAAKxC,IAAA,EAAM,SAAC0C;4BACrD,OAAO,AAAC,qBAAGA,qBAAJ;gCAAkBnB;6BAA0B;wBACrD;oBACF;oBAEAR,OAAOuB,KAAA,CAAMK,MAAA,CAAOH,GAAA,CAAI,IAAA,CAAKxC,IAAA,EAAM,SAAC2C;wBAClC3B,mBAAmB2B;oBACrB;oBAEA5B,OAAOuB,KAAA,CAAMrB,mBAAA,CAAoBuB,GAAA,CAAI,IAAA,CAAKxC,IAAA,EAAM,SAAC4C;wBAC/C3B,sBAAsB2B;oBACxB;gBACF;;;;;IDZA,OAAOlC,aAAaG;AACtB","sourcesContent":["\"use strict\";\nvar ComputedPropertiesPlugin = (() => {\n var __defProp = Object.defineProperty;\n var __getOwnPropDesc = Object.getOwnPropertyDescriptor;\n var __getOwnPropNames = Object.getOwnPropertyNames;\n var __hasOwnProp = Object.prototype.hasOwnProperty;\n var __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n };\n var __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n };\n var __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/computed-properties/core/src/index.ts\n var src_exports = {};\n __export(src_exports, {\n ComputedPropertiesPlugin: () => ComputedPropertiesPlugin\n });\n var ComputedPropertiesPlugin = class {\n constructor() {\n this.name = \"ComputedProperties\";\n }\n apply(player) {\n let schemaController;\n let expressionEvaluator;\n const getExpressionType = (binding) => {\n const dataType = schemaController?.getType(binding);\n if (dataType?.type === \"Expression\") {\n return dataType;\n }\n };\n const computedPropertyMiddleware = {\n name: this.name,\n get(binding, options, next) {\n const expType = getExpressionType(binding);\n if (expType) {\n const { exp } = expType;\n const result = exp && expressionEvaluator?.evaluate(exp, options?.context);\n return result ?? expType.default;\n }\n return next?.get(binding, options);\n },\n set(transaction, options, next) {\n for (const setOperation of transaction) {\n if (getExpressionType(setOperation[0])) {\n throw new Error(\n `Invalid 'set' operation on computed property: ${setOperation[0].asString()}`\n );\n }\n }\n return next?.set(transaction, options) ?? [];\n },\n delete(binding, options, next) {\n if (getExpressionType(binding)) {\n throw new Error(\n `Invalid 'delete' operation on computed property: ${binding.asString()}`\n );\n }\n return next?.delete(binding, options);\n }\n };\n player.hooks.dataController.tap(this.name, (dataController) => {\n dataController.hooks.resolveDataStages.tap(this.name, (dataPipeline) => {\n return [...dataPipeline, computedPropertyMiddleware];\n });\n });\n player.hooks.schema.tap(this.name, (schema) => {\n schemaController = schema;\n });\n player.hooks.expressionEvaluator.tap(this.name, (evaluator) => {\n expressionEvaluator = evaluator;\n });\n }\n };\n return __toCommonJS(src_exports);\n})();\n","import type {\n Player,\n PlayerPlugin,\n ExpressionEvaluator,\n Schema,\n Expression,\n DataModelMiddleware,\n Updates,\n SchemaController,\n BindingInstance,\n} from \"@player-ui/player\";\n\nexport interface ExpressionDataType extends Schema.DataType<\"Expression\"> {\n /** The expression to evaluate to compute the value of this node */\n exp?: Expression;\n}\n\n/**\n * A player plugin to manage beacon events.\n * It automatically keeps track of the current user's view, and adds additional metaData to each beacon event.\n */\nexport class ComputedPropertiesPlugin implements PlayerPlugin {\n name = \"ComputedProperties\";\n\n apply(player: Player) {\n // Inject a middleware into the data-model to intercept any calls to an expression type in the schema\n // Calls to `set` throw an error. Calls to `get` compute the value and return if or default\n\n let schemaController: SchemaController | undefined;\n let expressionEvaluator: ExpressionEvaluator | undefined;\n\n /** Look up the data-type of the binding, and check for an Expression type */\n const getExpressionType = (\n binding: BindingInstance,\n ): ExpressionDataType | undefined => {\n // Check to see if the data-type of the binding is an `Expression`\n const dataType = schemaController?.getType(binding);\n\n if (dataType?.type === \"Expression\") {\n return dataType as ExpressionDataType;\n }\n };\n\n const computedPropertyMiddleware: DataModelMiddleware = {\n name: this.name,\n get(binding, options, next) {\n const expType = getExpressionType(binding);\n\n if (expType) {\n const { exp } = expType;\n const result =\n exp && expressionEvaluator?.evaluate(exp, options?.context);\n\n return result ?? expType.default;\n }\n\n return next?.get(binding, options);\n },\n set(transaction, options, next): Updates {\n for (const setOperation of transaction) {\n if (getExpressionType(setOperation[0])) {\n throw new Error(\n `Invalid 'set' operation on computed property: ${setOperation[0].asString()}`,\n );\n }\n }\n\n return next?.set(transaction, options) ?? [];\n },\n delete(binding, options, next) {\n if (getExpressionType(binding)) {\n throw new Error(\n `Invalid 'delete' operation on computed property: ${binding.asString()}`,\n );\n }\n\n return next?.delete(binding, options);\n },\n };\n\n player.hooks.dataController.tap(this.name, (dataController) => {\n dataController.hooks.resolveDataStages.tap(this.name, (dataPipeline) => {\n return [...dataPipeline, computedPropertyMiddleware];\n });\n });\n\n player.hooks.schema.tap(this.name, (schema) => {\n schemaController = schema;\n });\n\n player.hooks.expressionEvaluator.tap(this.name, (evaluator) => {\n expressionEvaluator = evaluator;\n });\n }\n}\n"]}
1
+ {"version":3,"sources":["/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2513/execroot/_main/bazel-out/k8-fastbuild/bin/plugins/computed-properties/core/dist/index.global.js","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/computed-properties/core/src/index.ts"],"names":["ComputedPropertiesPlugin","__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","src_exports","apply","player","schemaController","expressionEvaluator","getExpressionType","binding","dataType","getType","type","computedPropertyMiddleware","options","next","expType","exp","result","evaluate","context","default","set","transaction","setOperation","Error","asString","delete","hooks","dataController","tap","resolveDataStages","dataPipeline","schema","evaluator"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAIA,2BAA2B,AAAC;IAC9B,IAAIC,YAAYC,OAAOC,cAAc;IACrC,IAAIC,mBAAmBF,OAAOG,wBAAwB;IACtD,IAAIC,oBAAoBJ,OAAOK,mBAAmB;IAClD,IAAIC,eAAeN,OAAOO,SAAS,CAACC,cAAc;IAClD,IAAIC,WAAW,kBAACC,QAAQC;QACtB,IAAK,IAAIC,QAAQD,IACfZ,UAAUW,QAAQE,MAAM;YAAEC,KAAKF,GAAG,CAACC,KAAK;YAAEE,YAAY;QAAK;IAC/D;IACA,IAAIC,cAAc,qBAACC,IAAIC,MAAMC,QAAQC;QACnC,IAAIF,QAAQ,CAAA,OAAOA,qCAAP,SAAOA,KAAG,MAAM,YAAY,OAAOA,SAAS,YAAY;gBAC7D,kCAAA,2BAAA;;;oBAAA,IAAIG,MAAJ;oBACH,IAAI,CAACd,aAAae,IAAI,CAACL,IAAII,QAAQA,QAAQF,QACzCnB,UAAUiB,IAAII,KAAK;wBAAEP,KAAK,SAALA;mCAAWI,IAAI,CAACG,IAAI;;wBAAEN,YAAY,CAAEK,CAAAA,OAAOjB,iBAAiBe,MA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AAA;;gCAAA,QAAA,YAA2BQ,gCAA3B,SAAA,6BAAA,QAAA,yBAAA,iCAAwC;oCAAxC,IAAWC,eAAX;oCACE,IAAIhB,kBAAkBgB,YAAA,CAAa,EAAE,GAAG;wCACtC,MAAM,IAAIC,MACR,iDAA2E,OAA1BD,YAAA,CAAa,EAAC,CAAEE,QAAA;oCAErE;gCACF;;gCANA;gCAAA;;;yCAAA,6BAAA;wCAAA;;;wCAAA;8CAAA;;;;4BAQA,eAAOX,iBAAAA,2BAAAA,KAAMO,GAAA,CAAIC,aAAaT,+CAAY,EAAC;wBAC7C;wBACAa,QAAAA,SAAAA,QAAOlB,OAAA,EAASK,OAAA,EAASC,IAAA;4BACvB,IAAIP,kBAAkBC,UAAU;gCAC9B,MAAM,IAAIgB,MACR,oDAAsE,OAAlBhB,QAAQiB,QAAA;4BAEhE;4BAEA,OAAOX,iBAAAA,2BAAAA,KAAMY,MAAA,CAAOlB,SAASK;wBAC/B;oBACF;oBAEAT,OAAOuB,KAAA,CAAMC,cAAA,CAAeC,GAAA,CAAI,IAAA,CAAKxC,IAAA,EAAM,SAACuC;wBAC1CA,eAAeD,KAAA,CAAMG,iBAAA,CAAkBD,GAAA,CAAI,MAAKxC,IAAA,EAAM,SAAC0C;4BACrD,OAAO,AAAC,qBAAGA,qBAAJ;gCAAkBnB;6BAA0B;wBACrD;oBACF;oBAEAR,OAAOuB,KAAA,CAAMK,MAAA,CAAOH,GAAA,CAAI,IAAA,CAAKxC,IAAA,EAAM,SAAC2C;wBAClC3B,mBAAmB2B;oBACrB;oBAEA5B,OAAOuB,KAAA,CAAMrB,mBAAA,CAAoBuB,GAAA,CAAI,IAAA,CAAKxC,IAAA,EAAM,SAAC4C;wBAC/C3B,sBAAsB2B;oBACxB;gBACF;;;;;IDZA,OAAOlC,aAAaG;AACtB","sourcesContent":["\"use strict\";\nvar ComputedPropertiesPlugin = (() => {\n var __defProp = Object.defineProperty;\n var __getOwnPropDesc = Object.getOwnPropertyDescriptor;\n var __getOwnPropNames = Object.getOwnPropertyNames;\n var __hasOwnProp = Object.prototype.hasOwnProperty;\n var __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n };\n var __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n };\n var __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/computed-properties/core/src/index.ts\n var src_exports = {};\n __export(src_exports, {\n ComputedPropertiesPlugin: () => ComputedPropertiesPlugin\n });\n var ComputedPropertiesPlugin = class {\n constructor() {\n this.name = \"ComputedProperties\";\n }\n apply(player) {\n let schemaController;\n let expressionEvaluator;\n const getExpressionType = (binding) => {\n const dataType = schemaController?.getType(binding);\n if (dataType?.type === \"Expression\") {\n return dataType;\n }\n };\n const computedPropertyMiddleware = {\n name: this.name,\n get(binding, options, next) {\n const expType = getExpressionType(binding);\n if (expType) {\n const { exp } = expType;\n const result = exp && expressionEvaluator?.evaluate(exp, options?.context);\n return result ?? expType.default;\n }\n return next?.get(binding, options);\n },\n set(transaction, options, next) {\n for (const setOperation of transaction) {\n if (getExpressionType(setOperation[0])) {\n throw new Error(\n `Invalid 'set' operation on computed property: ${setOperation[0].asString()}`\n );\n }\n }\n return next?.set(transaction, options) ?? [];\n },\n delete(binding, options, next) {\n if (getExpressionType(binding)) {\n throw new Error(\n `Invalid 'delete' operation on computed property: ${binding.asString()}`\n );\n }\n return next?.delete(binding, options);\n }\n };\n player.hooks.dataController.tap(this.name, (dataController) => {\n dataController.hooks.resolveDataStages.tap(this.name, (dataPipeline) => {\n return [...dataPipeline, computedPropertyMiddleware];\n });\n });\n player.hooks.schema.tap(this.name, (schema) => {\n schemaController = schema;\n });\n player.hooks.expressionEvaluator.tap(this.name, (evaluator) => {\n expressionEvaluator = evaluator;\n });\n }\n };\n return __toCommonJS(src_exports);\n})();\n","import type {\n Player,\n PlayerPlugin,\n ExpressionEvaluator,\n Schema,\n Expression,\n DataModelMiddleware,\n Updates,\n SchemaController,\n BindingInstance,\n} from \"@player-ui/player\";\n\nexport interface ExpressionDataType extends Schema.DataType<\"Expression\"> {\n /** The expression to evaluate to compute the value of this node */\n exp?: Expression;\n}\n\n/**\n * A player plugin to manage beacon events.\n * It automatically keeps track of the current user's view, and adds additional metaData to each beacon event.\n */\nexport class ComputedPropertiesPlugin implements PlayerPlugin {\n name = \"ComputedProperties\";\n\n apply(player: Player) {\n // Inject a middleware into the data-model to intercept any calls to an expression type in the schema\n // Calls to `set` throw an error. Calls to `get` compute the value and return if or default\n\n let schemaController: SchemaController | undefined;\n let expressionEvaluator: ExpressionEvaluator | undefined;\n\n /** Look up the data-type of the binding, and check for an Expression type */\n const getExpressionType = (\n binding: BindingInstance,\n ): ExpressionDataType | undefined => {\n // Check to see if the data-type of the binding is an `Expression`\n const dataType = schemaController?.getType(binding);\n\n if (dataType?.type === \"Expression\") {\n return dataType as ExpressionDataType;\n }\n };\n\n const computedPropertyMiddleware: DataModelMiddleware = {\n name: this.name,\n get(binding, options, next) {\n const expType = getExpressionType(binding);\n\n if (expType) {\n const { exp } = expType;\n const result =\n exp && expressionEvaluator?.evaluate(exp, options?.context);\n\n return result ?? expType.default;\n }\n\n return next?.get(binding, options);\n },\n set(transaction, options, next): Updates {\n for (const setOperation of transaction) {\n if (getExpressionType(setOperation[0])) {\n throw new Error(\n `Invalid 'set' operation on computed property: ${setOperation[0].asString()}`,\n );\n }\n }\n\n return next?.set(transaction, options) ?? [];\n },\n delete(binding, options, next) {\n if (getExpressionType(binding)) {\n throw new Error(\n `Invalid 'delete' operation on computed property: ${binding.asString()}`,\n );\n }\n\n return next?.delete(binding, options);\n },\n };\n\n player.hooks.dataController.tap(this.name, (dataController) => {\n dataController.hooks.resolveDataStages.tap(this.name, (dataPipeline) => {\n return [...dataPipeline, computedPropertyMiddleware];\n });\n });\n\n player.hooks.schema.tap(this.name, (schema) => {\n schemaController = schema;\n });\n\n player.hooks.expressionEvaluator.tap(this.name, (evaluator) => {\n expressionEvaluator = evaluator;\n });\n }\n}\n"]}
package/package.json CHANGED
@@ -6,10 +6,10 @@
6
6
  "types"
7
7
  ],
8
8
  "name": "@player-ui/computed-properties-plugin",
9
- "version": "0.15.3-next.1",
9
+ "version": "0.15.3-next.2",
10
10
  "main": "dist/cjs/index.cjs",
11
11
  "peerDependencies": {
12
- "@player-ui/player": "0.15.3-next.1"
12
+ "@player-ui/player": "0.15.3-next.2"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@player-ui/asset-transform-plugin": "workspace:^",