adaptivecards-templating
Advanced tools
Comparing version 2.2.0 to 2.3.0-beta.0
@@ -42,3 +42,8 @@ declare module 'adaptivecards-templating/template-engine' { | ||
*/ | ||
$root: any; | ||
$root?: any; | ||
/** | ||
* The host data object the template will bind to. Expressions that refer to $host in the template payload | ||
* map to this field. This allows a host process to supply additional context to the template. | ||
*/ | ||
$host?: any; | ||
} | ||
@@ -49,2 +54,3 @@ /** | ||
export class Template { | ||
private templateExpansionWarnings; | ||
private static prepare; | ||
@@ -154,2 +160,7 @@ private static internalTryEvaluateExpression; | ||
expand(context: IEvaluationContext): any; | ||
/** | ||
* Getter method for the array of warning strings | ||
* @returns An array storing any warnings that occurred while expanding the template | ||
*/ | ||
getLastTemplateExpansionWarnings(): string[]; | ||
} | ||
@@ -156,0 +167,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("adaptive-expressions")):"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ACData=t(require("adaptive-expressions")):e.ACData=t(e.AEL)}(this,(function(e){return(()=>{"use strict";var t={716:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),i(r(557),t),i(r(241),t)},241:function(e,t){var r=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))};function n(e,t,a){if("boolean"==typeof e)return null;switch(e.type){case"array":return Array.isArray(e.items)?function(e,t,o){var a,u;return Array.isArray(e.items)?{type:"Container",items:r(r([],i(e,0,o),!0),null!==(u=null===(a=e.items)||void 0===a?void 0:a.map((function(e,r){return n(e,t+"["+r+"]",o+1)})))&&void 0!==u?u:[],!0)}:null}(e,t,a):function(e,t,n){return{type:"Container",items:r([],i(e,0,n),!0)}}(e,0,a);case"object":return o(e,t,a);case"boolean":return function(e,t){return{type:"Input.Toggle",id:t,title:e.title,label:e.description,value:e.default}}(e,t);case"integer":case"number":return function(e,t){var r,n;return{type:"Input.Number",id:t,title:e.title,placeholder:e.description,value:e.default,min:null!==(r=e.exclusiveMinimum)&&void 0!==r?r:e.minimum,max:null!==(n=e.exclusiveMaximum)&&void 0!==n?n:e.maximum}}(e,t);case"string":return e.enum?function(e,t){return{type:"Input.ChoiceSet",id:t,title:e.title,choices:e.enum.map((function(e){return{title:e,value:e}})),placeholder:e.description,value:e.default}}(e,t):function(e,t){return{type:"Input.Text",id:t,title:e.title,placeholder:e.description,value:e.default,maxLength:e.maxLength,regex:e.pattern}}(e,t);case"date-time":case"time":case"date":return function(e,t){return{type:"Input.Time",id:t,title:e.title,placeholder:e.description,value:e.default}}(e,t);default:return null}}function i(e,t,r){return[e.title?{type:"TextBlock",size:void 0,text:e.title}:null,e.description?{type:"TextBlock",size:void 0,isSubtle:!0,wrap:!0,text:e.description}:null]}function o(e,t,o){var a,u;return{type:"Container",items:r(r([],i(e),!0),null!==(u=null===(a=e.required)||void 0===a?void 0:a.map((function(r){return n(e.properties[r],t+"."+function(e){return encodeURIComponent(e).replace(".","%2e")}(r),o+1)})))&&void 0!==u?u:[],!0)}}Object.defineProperty(t,"__esModule",{value:!0}),t.JSONSchemaCard=void 0,t.JSONSchemaCard=function(e){try{return{type:"AdaptiveCard",body:[o(e,"",0)]}}catch(e){return void console.error(e)}}},557:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Template=t.GlobalSettings=void 0;var n=r(248),i=function(){function e(e){this._stateStack=[],void 0!==e&&(this.$root=e.$root)}return e.prototype.isReservedField=function(t){return e._reservedFields.indexOf(t)>=0},e.prototype.saveState=function(){this._stateStack.push({$data:this.$data,$index:this.$index})},e.prototype.restoreLastState=function(){if(0===this._stateStack.length)throw new Error("There is no evaluation context state to restore.");var e=this._stateStack.pop();this.$data=e.$data,this.$index=e.$index},Object.defineProperty(e.prototype,"$data",{get:function(){return void 0!==this._$data?this._$data:this.$root},set:function(e){this._$data=e},enumerable:!1,configurable:!0}),e._reservedFields=["$data","$when","$root","$index"],e}(),o=function(){function e(){this._memory=new n.SimpleObjectMemory(this)}return e.prototype.getValue=function(e){var t=e.length>0&&"$"!==e[0]?"$data."+e:e;return this._memory.getValue(t)},e.prototype.setValue=function(e,t){this._memory.setValue(e,t)},e.prototype.version=function(){return this._memory.version()},e}(),a=function(){function e(){}return e.getUndefinedFieldValueSubstitutionString=void 0,e}();t.GlobalSettings=a;var u=function(){function e(t){this._preparedPayload=e.prepare(t)}return e.prepare=function(t){if("string"==typeof t)return e.parseInterpolatedString(t);if("object"==typeof t&&null!==t){if(Array.isArray(t)){for(var r=[],n=0,i=t;n<i.length;n++){var o=i[n];r.push(e.prepare(o))}return r}r={};for(var a=0,u=Object.keys(t);a<u.length;a++){var s=u[a];r[s]=e.prepare(t[s])}return r}return t},e.internalTryEvaluateExpression=function(e,t,r){var i=new o;i.$root=t.$root,i.$data=t.$data,i.$index=t.$index;var u=void 0;if(r&&((u=new n.Options).nullSubstitution=function(e){var t=void 0;return a.getUndefinedFieldValueSubstitutionString&&(t=a.getUndefinedFieldValueSubstitutionString(e)),t||"${"+e+"}"}),e.type===n.ExpressionType.Concat&&r){for(var s="",l=0,c=e.children;l<c.length;l++){var p=c[l],d=void 0;try{d=p.tryEvaluate(i,u)}catch(e){d={value:void 0,error:e}}d.error&&(d.value="${"+p.toString()+"}"),s+=d.value.toString()}return{value:s,error:void 0}}return e.tryEvaluate(i,u)},e.parseInterpolatedString=function(e){if(e.indexOf("${")>=0){var t=n.Expression.parse("`"+e+"`",(function(e){return n.ExpressionFunctions.standardFunctions.get(e)||new n.ExpressionEvaluator(e,(function(t,r,n){throw new Error("Unknown function "+e)}),n.ReturnType.String)}));if("concat"===t.type){if(!(1!==t.children.length||t.children[0]instanceof n.Constant))return t.children[0];if(2===t.children.length){var r=t.children[0];if(r instanceof n.Constant&&""===r.value&&!(t.children[1]instanceof n.Constant))return t.children[1]}return t}}return e},e.tryEvaluateExpression=function(t,r,n){return e.internalTryEvaluateExpression(t,new i(r),n)},e.prototype.expandSingleObject=function(e){for(var t={},r=0,n=Object.keys(e);r<n.length;r++){var i=n[r];if(!this._context.isReservedField(i)){var o=this.internalExpand(e[i]);void 0!==o&&(t[i]=o)}}return t},e.prototype.internalExpand=function(t){var r;if(this._context.saveState(),Array.isArray(t)){for(var i=[],o=0,a=t;o<a.length;o++){var u=a[o],s=this.internalExpand(u);null!==s&&(Array.isArray(s)?i=i.concat(s):i.push(s))}r=i}else if(t instanceof n.Expression){if((h=e.internalTryEvaluateExpression(t,this._context,!0)).error)throw new Error(h.error);r=h.value}else if("object"==typeof t&&null!==t){var l=t.$when,c=t.$data,p=!1,d=void 0;if(void 0===c)d=[void 0];else{if(c instanceof n.Expression){if((h=e.internalTryEvaluateExpression(c,this._context,!0)).error)throw new Error(h.error);c=h.value}Array.isArray(c)?(d=c,p=!0):d=[c]}r=[];for(var f=0;f<d.length;f++){p&&(this._context.$index=f),void 0!==d[f]&&(this._context.$data=d[f]);var v=!1;if(l instanceof n.Expression){var h,y=!1;(h=e.internalTryEvaluateExpression(l,this._context,!1)).error||(y="boolean"==typeof h.value&&h.value),v=!y}if(!v){var x=this.expandSingleObject(t);null!==x&&r.push(x)}}0===r.length?r=null:1===r.length&&(r=r[0])}else r=t;return this._context.restoreLastState(),r},e.prototype.expand=function(e){return this._context=new i(e),this.internalExpand(this._preparedPayload)},e}();t.Template=u},248:t=>{t.exports=e}},r={};return function e(n){var i=r[n];if(void 0!==i)return i.exports;var o=r[n]={exports:{}};return t[n].call(o.exports,o,o.exports,e),o.exports}(716)})()})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("adaptive-expressions")):"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ACData=t(require("adaptive-expressions")):e.ACData=t(e.AEL)}(this,(function(e){return(()=>{"use strict";var t={716:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),i(r(557),t),i(r(241),t)},241:function(e,t){var r=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var n,i=0,a=t.length;i<a;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))};function n(e,t,o){if("boolean"==typeof e)return null;switch(e.type){case"array":return Array.isArray(e.items)?function(e,t,a){var o,s;return Array.isArray(e.items)?{type:"Container",items:r(r([],i(e,0,a),!0),null!==(s=null===(o=e.items)||void 0===o?void 0:o.map((function(e,r){return n(e,t+"["+r+"]",a+1)})))&&void 0!==s?s:[],!0)}:null}(e,t,o):function(e,t,n){return{type:"Container",items:r([],i(e,0,n),!0)}}(e,0,o);case"object":return a(e,t,o);case"boolean":return function(e,t){return{type:"Input.Toggle",id:t,title:e.title,label:e.description,value:e.default}}(e,t);case"integer":case"number":return function(e,t){var r,n;return{type:"Input.Number",id:t,title:e.title,placeholder:e.description,value:e.default,min:null!==(r=e.exclusiveMinimum)&&void 0!==r?r:e.minimum,max:null!==(n=e.exclusiveMaximum)&&void 0!==n?n:e.maximum}}(e,t);case"string":return e.enum?function(e,t){return{type:"Input.ChoiceSet",id:t,title:e.title,choices:e.enum.map((function(e){return{title:e,value:e}})),placeholder:e.description,value:e.default}}(e,t):function(e,t){return{type:"Input.Text",id:t,title:e.title,placeholder:e.description,value:e.default,maxLength:e.maxLength,regex:e.pattern}}(e,t);case"date-time":case"time":case"date":return function(e,t){return{type:"Input.Time",id:t,title:e.title,placeholder:e.description,value:e.default}}(e,t);default:return null}}function i(e,t,r){return[e.title?{type:"TextBlock",size:void 0,text:e.title}:null,e.description?{type:"TextBlock",size:void 0,isSubtle:!0,wrap:!0,text:e.description}:null]}function a(e,t,a){var o,s;return{type:"Container",items:r(r([],i(e),!0),null!==(s=null===(o=e.required)||void 0===o?void 0:o.map((function(r){return n(e.properties[r],t+"."+function(e){return encodeURIComponent(e).replace(".","%2e")}(r),a+1)})))&&void 0!==s?s:[],!0)}}Object.defineProperty(t,"__esModule",{value:!0}),t.JSONSchemaCard=void 0,t.JSONSchemaCard=function(e){try{return{type:"AdaptiveCard",body:[a(e,"",0)]}}catch(e){return void console.error(e)}}},557:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Template=t.GlobalSettings=void 0;var n=r(949),i=r(147),a=function(){function e(e){this._stateStack=[],void 0!==e&&(this.$_acTemplateVersion=this.generateVersionJson(),this.$root=e.$root,this.$host=e.$host)}return e.prototype.isReservedField=function(t){return e._reservedFields.indexOf(t)>=0},e.prototype.saveState=function(){this._stateStack.push({$data:this.$data,$index:this.$index})},e.prototype.restoreLastState=function(){if(0===this._stateStack.length)throw new Error("There is no evaluation context state to restore.");var e=this._stateStack.pop();this.$data=e.$data,this.$index=e.$index},Object.defineProperty(e.prototype,"$data",{get:function(){return void 0!==this._$data?this._$data:this.$root},set:function(e){this._$data=e},enumerable:!1,configurable:!0}),e.prototype.generateVersionJson=function(){var e=i.version.split("."),t=[];return e[2]&&(t=e[2].split("-")),{major:parseInt(e[0]),minor:parseInt(e[1]),patch:parseInt(t[0]),suffix:t[1]||""}},e._reservedFields=["$data","$when","$root","$index","$host","$_acTemplateVersion"],e}(),o=function(){function e(){this._memory=new n.SimpleObjectMemory(this)}return e.prototype.getValue=function(e){var t=e.length>0&&"$"!==e[0]?"$data."+e:e;return this._memory.getValue(t)},e.prototype.setValue=function(e,t){this._memory.setValue(e,t)},e.prototype.version=function(){return this._memory.version()},e}(),s=function(){function e(){}return e.getUndefinedFieldValueSubstitutionString=void 0,e}();t.GlobalSettings=s;var p=function(){function e(t){this._preparedPayload=e.prepare(t)}return e.prepare=function(t){if("string"==typeof t)return e.parseInterpolatedString(t);if("object"==typeof t&&null!==t){if(Array.isArray(t)){for(var r=[],n=0,i=t;n<i.length;n++){var a=i[n];r.push(e.prepare(a))}return r}r={};for(var o=0,s=Object.keys(t);o<s.length;o++){var p=s[o];r[p]=e.prepare(t[p])}return r}return t},e.internalTryEvaluateExpression=function(e,t,r){var i=new o;i.$root=t.$root,i.$data=t.$data,i.$index=t.$index,i.$host=t.$host,i.$_acTemplateVersion=t.$_acTemplateVersion;var a=void 0;if(r&&((a=new n.Options).nullSubstitution=function(e){var t=void 0;return s.getUndefinedFieldValueSubstitutionString&&(t=s.getUndefinedFieldValueSubstitutionString(e)),t||"${"+e+"}"}),e.type===n.ExpressionType.Concat&&r){for(var p="",u=0,l=e.children;u<l.length;u++){var d=l[u],c=void 0;try{c=d.tryEvaluate(i,a)}catch(e){c={value:void 0,error:e}}c.error&&(c.value="${"+d.toString()+"}"),p+=c.value.toString()}return{value:p,error:void 0}}return e.tryEvaluate(i,a)},e.parseInterpolatedString=function(e){if(e.indexOf("${")>=0){var t=n.Expression.parse("`"+e+"`",(function(e){return n.ExpressionFunctions.standardFunctions.get(e)||new n.ExpressionEvaluator(e,(function(t,r,n){throw new Error("Unknown function "+e)}),n.ReturnType.String)}));if("concat"===t.type){if(!(1!==t.children.length||t.children[0]instanceof n.Constant))return t.children[0];if(2===t.children.length){var r=t.children[0];if(r instanceof n.Constant&&""===r.value&&!(t.children[1]instanceof n.Constant))return t.children[1]}return t}}return e},e.tryEvaluateExpression=function(t,r,n){return e.internalTryEvaluateExpression(t,new a(r),n)},e.prototype.expandSingleObject=function(e){for(var t={},r=0,n=Object.keys(e);r<n.length;r++){var i=n[r];if(!this._context.isReservedField(i)){var a=this.internalExpand(e[i]);void 0!==a&&(t[i]=a)}}return t},e.prototype.internalExpand=function(t){var r;if(this._context.saveState(),Array.isArray(t)){for(var i=[],a=0,o=t;a<o.length;a++){var s=o[a],p=this.internalExpand(s);null!==p&&(Array.isArray(p)?i=i.concat(p):i.push(p))}r=i}else if(t instanceof n.Expression){if((h=e.internalTryEvaluateExpression(t,this._context,!0)).error)throw new Error(h.error);r=h.value}else if("object"==typeof t&&null!==t){var u=t.$when,l=t.$data,d=!1,c=void 0;if(void 0===l)c=[void 0];else{if(l instanceof n.Expression){if((h=e.internalTryEvaluateExpression(l,this._context,!0)).error)throw new Error(h.error);l=h.value}Array.isArray(l)?(c=l,d=!0):c=[l]}r=[];for(var f=0;f<c.length;f++){d&&(this._context.$index=f),void 0!==c[f]&&(this._context.$data=c[f]);var v=!1;if(u instanceof n.Expression){var h,y=!1;(h=e.internalTryEvaluateExpression(u,this._context,!1)).error||(y="boolean"==typeof h.value&&h.value),h.value||this.templateExpansionWarnings.push("WARN: Unable to parse the Adaptive Expression "+u+". The $when condition has been set to false by default."),v=!y}else u&&(this.templateExpansionWarnings.push("WARN: "+u+" is not an Adaptive Expression. The $when condition has been set to false by default."),v=!0);if(!v){var m=this.expandSingleObject(t);null!==m&&r.push(m)}}0===r.length?r=null:1===r.length&&(r=r[0])}else r=t;return this._context.restoreLastState(),r},e.prototype.expand=function(e){return this.templateExpansionWarnings=[],this._context=new a(e),this.internalExpand(this._preparedPayload)},e.prototype.getLastTemplateExpansionWarnings=function(){return this.templateExpansionWarnings},e}();t.Template=p},949:t=>{t.exports=e},147:e=>{e.exports=JSON.parse('{"name":"adaptivecards-templating","version":"2.3.0-alpha.0","description":"Adaptive Card data binding and templating engine for JavaScript","author":"AdaptiveCards","license":"MIT","homepage":"https://adaptivecards.io","repository":{"type":"git","url":"https://github.com/microsoft/AdaptiveCards.git","directory":"source/nodejs/adaptivecards-templating"},"keywords":["adaptivecards","adaptive","cards","microsoft","bot"],"main":"lib/adaptivecards-templating.js","types":"lib/adaptivecards-templating.d.ts","files":["lib","dist","src"],"scripts":{"clean":"rimraf build lib dist","prebuild":"tsc","build":"webpack","watch":"webpack --watch","start":"webpack-dev-server --open","dts":"dts-generator --prefix adaptivecards-templating --project . --out dist/adaptivecards-templating.d.ts","lint":"eslint src/*.ts","release":"npm run build && webpack --mode=production && npm run dts","docs":"npx typedoc"},"devDependencies":{"@types/json-schema":"^7.0.8","adaptive-expressions":"^4.11.0","adaptivecards":"^3.0.0-beta.2","typedoc":"^0.22.5","typedoc-plugin-markdown":"^3.11.2"},"peerDependencies":{"adaptive-expressions":"^4.11.0"}}')}},r={};return function e(n){var i=r[n];if(void 0!==i)return i.exports;var a=r[n]={exports:{}};return t[n].call(a.exports,a,a.exports,e),a.exports}(716)})()})); | ||
//# sourceMappingURL=adaptivecards-templating.min.js.map |
export * from "./template-engine"; | ||
export * from "./json-schema-card"; |
@@ -0,0 +0,0 @@ "use strict"; |
export * from "./template-engine"; | ||
export * from "./json-schema-card"; |
import { IAdaptiveCard } from 'adaptivecards/src/schema'; | ||
import { JSONSchema7 } from 'json-schema'; | ||
export declare function JSONSchemaCard(schema: JSONSchema7): IAdaptiveCard | undefined; |
@@ -41,3 +41,8 @@ import * as AEL from "adaptive-expressions"; | ||
*/ | ||
$root: any; | ||
$root?: any; | ||
/** | ||
* The host data object the template will bind to. Expressions that refer to $host in the template payload | ||
* map to this field. This allows a host process to supply additional context to the template. | ||
*/ | ||
$host?: any; | ||
} | ||
@@ -48,2 +53,3 @@ /** | ||
export declare class Template { | ||
private templateExpansionWarnings; | ||
private static prepare; | ||
@@ -153,2 +159,7 @@ private static internalTryEvaluateExpression; | ||
expand(context: IEvaluationContext): any; | ||
/** | ||
* Getter method for the array of warning strings | ||
* @returns An array storing any warnings that occurred while expanding the template | ||
*/ | ||
getLastTemplateExpansionWarnings(): string[]; | ||
} |
@@ -10,5 +10,7 @@ export declare type Size = "auto" | "stretch" | "small" | "medium" | "large"; | ||
export declare type ImageStyle = "default" | "person"; | ||
export declare type ActionStyle = "default" | "positive" | "destructive"; | ||
export interface IAction { | ||
id: string; | ||
title?: string; | ||
style?: ActionStyle; | ||
} | ||
@@ -15,0 +17,0 @@ export interface ISubmitAction extends IAction { |
import { IAdaptiveCard } from 'adaptivecards/src/schema'; | ||
import { JSONSchema7 } from 'json-schema'; | ||
export declare function JSONSchemaCard(schema: JSONSchema7): IAdaptiveCard | undefined; |
"use strict"; | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
@@ -97,5 +101,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
type: "Container", | ||
items: __spreadArray(__spreadArray([], JSONSchemaFieldTitle(schema, path, depth)), (_b = (_a = schema.items) === null || _a === void 0 ? void 0 : _a.map(function (item, idx) { | ||
items: __spreadArray(__spreadArray([], JSONSchemaFieldTitle(schema, path, depth), true), (_b = (_a = schema.items) === null || _a === void 0 ? void 0 : _a.map(function (item, idx) { | ||
return JSONSchemaCardElement(item, path + "[" + idx + "]", depth + 1); | ||
})) !== null && _b !== void 0 ? _b : []), | ||
})) !== null && _b !== void 0 ? _b : [], true), | ||
}; | ||
@@ -106,3 +110,3 @@ } | ||
type: "Container", | ||
items: __spreadArray([], JSONSchemaFieldTitle(schema, path, depth)), | ||
items: __spreadArray([], JSONSchemaFieldTitle(schema, path, depth), true), | ||
}; | ||
@@ -114,5 +118,5 @@ } | ||
type: "Container", | ||
items: __spreadArray(__spreadArray([], JSONSchemaFieldTitle(schema, path, depth)), (_b = (_a = schema.required) === null || _a === void 0 ? void 0 : _a.map(function (property) { | ||
items: __spreadArray(__spreadArray([], JSONSchemaFieldTitle(schema, path, depth), true), (_b = (_a = schema.required) === null || _a === void 0 ? void 0 : _a.map(function (property) { | ||
return JSONSchemaCardElement(schema.properties[property], path + "." + encodeProperty(property), depth + 1); | ||
})) !== null && _b !== void 0 ? _b : []), | ||
})) !== null && _b !== void 0 ? _b : [], true), | ||
}; | ||
@@ -119,0 +123,0 @@ } |
@@ -41,3 +41,8 @@ import * as AEL from "adaptive-expressions"; | ||
*/ | ||
$root: any; | ||
$root?: any; | ||
/** | ||
* The host data object the template will bind to. Expressions that refer to $host in the template payload | ||
* map to this field. This allows a host process to supply additional context to the template. | ||
*/ | ||
$host?: any; | ||
} | ||
@@ -48,2 +53,3 @@ /** | ||
export declare class Template { | ||
private templateExpansionWarnings; | ||
private static prepare; | ||
@@ -153,2 +159,7 @@ private static internalTryEvaluateExpression; | ||
expand(context: IEvaluationContext): any; | ||
/** | ||
* Getter method for the array of warning strings | ||
* @returns An array storing any warnings that occurred while expanding the template | ||
*/ | ||
getLastTemplateExpansionWarnings(): string[]; | ||
} |
@@ -7,2 +7,3 @@ "use strict"; | ||
var AEL = require("adaptive-expressions"); | ||
var pkg = require('./../package.json'); | ||
var EvaluationContext = /** @class */ (function () { | ||
@@ -12,3 +13,5 @@ function EvaluationContext(context) { | ||
if (context !== undefined) { | ||
this.$_acTemplateVersion = this.generateVersionJson(); | ||
this.$root = context.$root; | ||
this.$host = context.$host; | ||
} | ||
@@ -43,3 +46,19 @@ } | ||
}); | ||
EvaluationContext._reservedFields = ["$data", "$when", "$root", "$index"]; | ||
EvaluationContext.prototype.generateVersionJson = function () { | ||
// Example version: 2.3.0-alpha | ||
var version = pkg.version; | ||
var versionSplit = version.split('.'); | ||
var patchSplit = []; | ||
var patchIndex = 2; | ||
if (versionSplit[patchIndex]) { | ||
patchSplit = versionSplit[patchIndex].split('-'); | ||
} | ||
return { | ||
"major": parseInt(versionSplit[0]), | ||
"minor": parseInt(versionSplit[1]), | ||
"patch": parseInt(patchSplit[0]), | ||
"suffix": patchSplit[1] || "", | ||
}; | ||
}; | ||
EvaluationContext._reservedFields = ["$data", "$when", "$root", "$index", "$host", "$_acTemplateVersion"]; | ||
return EvaluationContext; | ||
@@ -144,2 +163,4 @@ }()); | ||
memory.$index = context.$index; | ||
memory.$host = context.$host; | ||
memory.$_acTemplateVersion = context.$_acTemplateVersion; | ||
var options = undefined; | ||
@@ -325,4 +346,13 @@ if (allowSubstitutions) { | ||
} | ||
if (!evaluationResult.value) { | ||
// Value was not found, and we should warn the client that the Expression was invalid | ||
this.templateExpansionWarnings.push("WARN: Unable to parse the Adaptive Expression " + when + ". The $when condition has been set to false by default."); | ||
} | ||
dropObject = !whenValue; | ||
} | ||
else if (when) { | ||
// If $when was provided, but it is not an AEL.Expression, drop the object | ||
this.templateExpansionWarnings.push("WARN: " + when + " is not an Adaptive Expression. The $when condition has been set to false by default."); | ||
dropObject = true; | ||
} | ||
if (!dropObject) { | ||
@@ -416,5 +446,13 @@ var expandedObject = this.expandSingleObject(node); | ||
Template.prototype.expand = function (context) { | ||
this.templateExpansionWarnings = []; | ||
this._context = new EvaluationContext(context); | ||
return this.internalExpand(this._preparedPayload); | ||
}; | ||
/** | ||
* Getter method for the array of warning strings | ||
* @returns An array storing any warnings that occurred while expanding the template | ||
*/ | ||
Template.prototype.getLastTemplateExpansionWarnings = function () { | ||
return this.templateExpansionWarnings; | ||
}; | ||
return Template; | ||
@@ -421,0 +459,0 @@ }()); |
@@ -1,1 +0,48 @@ | ||
{"name":"adaptivecards-templating","version":"2.2.0","description":"Adaptive Card data binding and templating engine for JavaScript","author":"AdaptiveCards","license":"MIT","homepage":"https://adaptivecards.io","repository":{"type":"git","url":"https://github.com/microsoft/AdaptiveCards.git","directory":"source/nodejs/adaptivecards-templating"},"keywords":["adaptivecards","adaptive","cards","microsoft","bot"],"main":"lib/adaptivecards-templating.js","types":"lib/adaptivecards-templating.d.ts","files":["lib","dist","src"],"scripts":{"clean":"rimraf build lib dist","prebuild":"tsc","build":"webpack","watch":"webpack --watch","start":"webpack-dev-server --open","dts":"dts-generator --prefix adaptivecards-templating --project . --out dist/adaptivecards-templating.d.ts","lint":"eslint src/*.ts","release":"npm run build && webpack --mode=production && npm run dts","docs":"npx typedoc"},"devDependencies":{"@types/json-schema":"^7.0.8","@typescript-eslint/eslint-plugin":"^3.4.0","@typescript-eslint/parser":"^3.4.0","adaptive-expressions":"^4.11.0","adaptivecards":"^2.10.0","dts-generator":"^3.0.0","eslint":"^7.3.1","rimraf":"^3.0.2","typedoc":"^0.22.5","typedoc-plugin-markdown":"^3.11.2","typescript":"^4.2.3","webpack":"^5.47.0","webpack-cli":"^4.7.2","webpack-concat-plugin":"^3.0.0","webpack-dev-server":"^3.11.2"},"peerDependencies":{"adaptive-expressions":"^4.11.0"}} | ||
{ | ||
"name": "adaptivecards-templating", | ||
"version": "2.3.0-beta.0", | ||
"description": "Adaptive Card data binding and templating engine for JavaScript", | ||
"author": "AdaptiveCards", | ||
"license": "MIT", | ||
"homepage": "https://adaptivecards.io", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/microsoft/AdaptiveCards.git", | ||
"directory": "source/nodejs/adaptivecards-templating" | ||
}, | ||
"keywords": [ | ||
"adaptivecards", | ||
"adaptive", | ||
"cards", | ||
"microsoft", | ||
"bot" | ||
], | ||
"main": "lib/adaptivecards-templating.js", | ||
"types": "lib/adaptivecards-templating.d.ts", | ||
"files": [ | ||
"lib", | ||
"dist", | ||
"src" | ||
], | ||
"scripts": { | ||
"clean": "rimraf build lib dist", | ||
"prebuild": "tsc", | ||
"build": "webpack", | ||
"watch": "webpack --watch", | ||
"start": "webpack-dev-server --open", | ||
"dts": "dts-generator --prefix adaptivecards-templating --project . --out dist/adaptivecards-templating.d.ts", | ||
"lint": "eslint src/*.ts", | ||
"release": "npm run build && webpack --mode=production && npm run dts", | ||
"docs": "npx typedoc" | ||
}, | ||
"devDependencies": { | ||
"@types/json-schema": "^7.0.8", | ||
"adaptive-expressions": "^4.11.0", | ||
"adaptivecards": "^3.0.0-beta.2", | ||
"typedoc": "^0.22.5", | ||
"typedoc-plugin-markdown": "^3.11.2" | ||
}, | ||
"peerDependencies": { | ||
"adaptive-expressions": "^4.11.0" | ||
} | ||
} |
@@ -0,0 +0,0 @@ # Adaptive Card Templating for JavaScript |
@@ -0,0 +0,0 @@ // Copyright (c) Microsoft Corporation. All rights reserved. |
@@ -0,0 +0,0 @@ // Copyright (c) Microsoft Corporation. All rights reserved. |
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
import * as AEL from "adaptive-expressions"; | ||
const pkg = require('./../package.json'); | ||
class EvaluationContext { | ||
private static readonly _reservedFields = ["$data", "$when", "$root", "$index"]; | ||
private static readonly _reservedFields = ["$data", "$when", "$root", "$index", "$host", "$_acTemplateVersion"]; | ||
@@ -12,7 +13,12 @@ private _stateStack: Array<{ $data: any, $index: any }> = []; | ||
$root: any; | ||
$host: any; | ||
$index: number; | ||
$_acTemplateVersion: any; | ||
constructor(context?: IEvaluationContext) { | ||
if (context !== undefined) { | ||
this.$_acTemplateVersion = this.generateVersionJson(); | ||
this.$root = context.$root; | ||
this.$host = context.$host; | ||
} | ||
@@ -51,2 +57,21 @@ } | ||
} | ||
generateVersionJson() { | ||
// Example version: 2.3.0-alpha | ||
const version = pkg.version; | ||
const versionSplit = version.split('.'); | ||
let patchSplit = []; | ||
const patchIndex = 2; | ||
if (versionSplit[patchIndex]) { | ||
patchSplit = versionSplit[patchIndex].split('-'); | ||
} | ||
return { | ||
"major": parseInt(versionSplit[0]), | ||
"minor": parseInt(versionSplit[1]), | ||
"patch": parseInt(patchSplit[0]), | ||
"suffix": patchSplit[1] || "", | ||
} | ||
} | ||
} | ||
@@ -60,2 +85,4 @@ | ||
$index: any; | ||
$host: any; | ||
$_acTemplateVersion: any; | ||
@@ -90,6 +117,6 @@ constructor() { | ||
* behavior. | ||
* | ||
* | ||
* **Example** | ||
* Given this data object: | ||
* | ||
* | ||
* ```json | ||
@@ -100,6 +127,6 @@ * { | ||
* ``` | ||
* | ||
* | ||
* The expression `${firstName} ${lastName}` will evaluate to "David ${lastName}" because the `lastName` | ||
* field is undefined. | ||
* | ||
* | ||
* Now let's set the callback: | ||
@@ -109,3 +136,3 @@ * ```typescript | ||
* ``` | ||
* | ||
* | ||
* With that, the above expression will evaluate to "David <undefined value>" | ||
@@ -124,3 +151,8 @@ */ | ||
*/ | ||
$root: any | ||
$root?: any; | ||
/** | ||
* The host data object the template will bind to. Expressions that refer to $host in the template payload | ||
* map to this field. This allows a host process to supply additional context to the template. | ||
*/ | ||
$host?: any; | ||
} | ||
@@ -132,2 +164,5 @@ | ||
export class Template { | ||
private templateExpansionWarnings; | ||
private static prepare(node: any): any { | ||
@@ -168,2 +203,4 @@ if (typeof node === "string") { | ||
memory.$index = context.$index; | ||
memory.$host = context.$host; | ||
memory.$_acTemplateVersion = context.$_acTemplateVersion; | ||
@@ -178,5 +215,5 @@ let options: AEL.Options | undefined = undefined; | ||
if (GlobalSettings.getUndefinedFieldValueSubstitutionString) { | ||
substitutionValue = GlobalSettings.getUndefinedFieldValueSubstitutionString(path); | ||
substitutionValue = GlobalSettings.getUndefinedFieldValueSubstitutionString(path); | ||
} | ||
return substitutionValue ? substitutionValue : "${" + path + "}"; | ||
@@ -195,3 +232,3 @@ } | ||
let evaluationResult: { value: any; error: string }; | ||
try { | ||
@@ -217,3 +254,3 @@ evaluationResult = childExpression.tryEvaluate(memory, options); | ||
} | ||
return expression.tryEvaluate(memory, options); | ||
@@ -224,3 +261,3 @@ } | ||
* Parses an interpolated string into an Expression object ready to evaluate. | ||
* | ||
* | ||
* @param interpolatedString The interpolated string to parse. Example: "Hello ${name}" | ||
@@ -278,3 +315,3 @@ * @returns An Expression object if the provided interpolated string contained at least one expression (e.g. "${expression}"); the original string otherwise. | ||
* Tries to evaluate the provided expression using the provided context. | ||
* | ||
* | ||
* @param expression The expression to evaluate. | ||
@@ -391,3 +428,3 @@ * @param context The context (data) used to evaluate the expression. | ||
let whenValue: boolean = false; | ||
// If $when fails to evaluate or evaluates to anything but a boolean, consider it is false | ||
@@ -397,4 +434,13 @@ if (!evaluationResult.error) { | ||
} | ||
if (!evaluationResult.value) { | ||
// Value was not found, and we should warn the client that the Expression was invalid | ||
this.templateExpansionWarnings.push(`WARN: Unable to parse the Adaptive Expression ${when}. The $when condition has been set to false by default.`); | ||
} | ||
dropObject = !whenValue; | ||
} else if (when) { | ||
// If $when was provided, but it is not an AEL.Expression, drop the object | ||
this.templateExpansionWarnings.push(`WARN: ${when} is not an Adaptive Expression. The $when condition has been set to false by default.`); | ||
dropObject = true; | ||
} | ||
@@ -431,4 +477,4 @@ | ||
* in a loop. | ||
* | ||
* @param payload The template payload. | ||
* | ||
* @param payload The template payload. | ||
*/ | ||
@@ -443,5 +489,5 @@ constructor(payload: any) { | ||
* repeating (expanding) parts of that payload that are bound to arrays. | ||
* | ||
* | ||
* Example: | ||
* | ||
* | ||
* ```typescript | ||
@@ -458,3 +504,3 @@ * let context = { | ||
* } | ||
* | ||
* | ||
* let templatePayload = { | ||
@@ -475,10 +521,10 @@ * type: "AdaptiveCard", | ||
* } | ||
* | ||
* | ||
* let template = new Template(templatePayload); | ||
* | ||
* | ||
* let expandedTemplate = template.expand(context); | ||
* ``` | ||
* | ||
* | ||
* With the above code, the value of `expandedTemplate` will be | ||
* | ||
* | ||
* ```json | ||
@@ -504,3 +550,3 @@ * { | ||
* ``` | ||
* | ||
* | ||
* @param context The context to bind the template to. | ||
@@ -511,6 +557,14 @@ * @returns A value representing the expanded template. The type of that value | ||
expand(context: IEvaluationContext): any { | ||
this.templateExpansionWarnings = []; | ||
this._context = new EvaluationContext(context); | ||
return this.internalExpand(this._preparedPayload); | ||
} | ||
} | ||
/** | ||
* Getter method for the array of warning strings | ||
* @returns An array storing any warnings that occurred while expanding the template | ||
*/ | ||
public getLastTemplateExpansionWarnings(): string[] { | ||
return this.templateExpansionWarnings; | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
232362
5
2701
2
2