@uniformdev/canvas 12.0.1-alpha.98 → 12.2.1-alpha.122

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.
Files changed (196) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +5 -5
  3. package/dist/chunk-A4MBTKCQ.mjs +2 -0
  4. package/dist/cli/cli.d.ts +14 -0
  5. package/dist/cli/cli.js +4 -0
  6. package/dist/cli/cli.mjs +3 -0
  7. package/dist/createEventBus-ca90547e.d.ts +255 -0
  8. package/dist/index.d.ts +365 -0
  9. package/dist/index.esm.js +4 -0
  10. package/dist/index.js +5 -0
  11. package/dist/index.mjs +4 -0
  12. package/package.json +34 -34
  13. package/dist/cjs/CanvasClient.d.ts +0 -50
  14. package/dist/cjs/CanvasClient.js +0 -1
  15. package/dist/cjs/cli/arraySyncEngineDataSource.d.ts +0 -10
  16. package/dist/cjs/cli/arraySyncEngineDataSource.js +0 -1
  17. package/dist/cjs/cli/cli.d.ts +0 -3
  18. package/dist/cjs/cli/cli.js +0 -1
  19. package/dist/cjs/cli/commands/component/_util.d.ts +0 -3
  20. package/dist/cjs/cli/commands/component/_util.js +0 -1
  21. package/dist/cjs/cli/commands/component/get.d.ts +0 -7
  22. package/dist/cjs/cli/commands/component/get.js +0 -1
  23. package/dist/cjs/cli/commands/component/list.d.ts +0 -6
  24. package/dist/cjs/cli/commands/component/list.js +0 -1
  25. package/dist/cjs/cli/commands/component/pull.d.ts +0 -10
  26. package/dist/cjs/cli/commands/component/pull.js +0 -1
  27. package/dist/cjs/cli/commands/component/push.d.ts +0 -9
  28. package/dist/cjs/cli/commands/component/push.js +0 -1
  29. package/dist/cjs/cli/commands/component/remove.d.ts +0 -7
  30. package/dist/cjs/cli/commands/component/remove.js +0 -1
  31. package/dist/cjs/cli/commands/component/update.d.ts +0 -7
  32. package/dist/cjs/cli/commands/component/update.js +0 -1
  33. package/dist/cjs/cli/commands/component.d.ts +0 -2
  34. package/dist/cjs/cli/commands/component.js +0 -1
  35. package/dist/cjs/cli/commands/composition/_util.d.ts +0 -3
  36. package/dist/cjs/cli/commands/composition/_util.js +0 -1
  37. package/dist/cjs/cli/commands/composition/get.d.ts +0 -8
  38. package/dist/cjs/cli/commands/composition/get.js +0 -1
  39. package/dist/cjs/cli/commands/composition/list.d.ts +0 -8
  40. package/dist/cjs/cli/commands/composition/list.js +0 -1
  41. package/dist/cjs/cli/commands/composition/pull.d.ts +0 -10
  42. package/dist/cjs/cli/commands/composition/pull.js +0 -1
  43. package/dist/cjs/cli/commands/composition/push.d.ts +0 -9
  44. package/dist/cjs/cli/commands/composition/push.js +0 -1
  45. package/dist/cjs/cli/commands/composition/remove.d.ts +0 -7
  46. package/dist/cjs/cli/commands/composition/remove.js +0 -1
  47. package/dist/cjs/cli/commands/composition/update.d.ts +0 -7
  48. package/dist/cjs/cli/commands/composition/update.js +0 -1
  49. package/dist/cjs/cli/commands/composition.d.ts +0 -2
  50. package/dist/cjs/cli/commands/composition.js +0 -1
  51. package/dist/cjs/cli/componentDefinitionEngineDataSource.d.ts +0 -7
  52. package/dist/cjs/cli/componentDefinitionEngineDataSource.js +0 -1
  53. package/dist/cjs/cli/componentInstanceEngineDataSource.d.ts +0 -9
  54. package/dist/cjs/cli/componentInstanceEngineDataSource.js +0 -1
  55. package/dist/cjs/cli/fileSyncEngineDataSource.d.ts +0 -9
  56. package/dist/cjs/cli/fileSyncEngineDataSource.js +0 -1
  57. package/dist/cjs/cli/package.d.ts +0 -7
  58. package/dist/cjs/cli/package.js +0 -1
  59. package/dist/cjs/cli/syncEngine.d.ts +0 -49
  60. package/dist/cjs/cli/syncEngine.js +0 -1
  61. package/dist/cjs/cli/syncEngineConsoleLogger.d.ts +0 -5
  62. package/dist/cjs/cli/syncEngineConsoleLogger.js +0 -1
  63. package/dist/cjs/cli/util.d.ts +0 -43
  64. package/dist/cjs/cli/util.js +0 -1
  65. package/dist/cjs/enhancement/EnhancerBuilder.d.ts +0 -66
  66. package/dist/cjs/enhancement/EnhancerBuilder.js +0 -1
  67. package/dist/cjs/enhancement/UniqueBatchEntries.d.ts +0 -17
  68. package/dist/cjs/enhancement/UniqueBatchEntries.js +0 -1
  69. package/dist/cjs/enhancement/batchEnhancer.d.ts +0 -39
  70. package/dist/cjs/enhancement/batchEnhancer.js +0 -1
  71. package/dist/cjs/enhancement/compose.d.ts +0 -6
  72. package/dist/cjs/enhancement/compose.js +0 -1
  73. package/dist/cjs/enhancement/createLimitPolicy.d.ts +0 -8
  74. package/dist/cjs/enhancement/createLimitPolicy.js +0 -1
  75. package/dist/cjs/enhancement/enhance.d.ts +0 -18
  76. package/dist/cjs/enhancement/enhance.js +0 -1
  77. package/dist/cjs/enhancement/localize.d.ts +0 -11
  78. package/dist/cjs/enhancement/localize.js +0 -1
  79. package/dist/cjs/enhancement/walkComponentTree.d.ts +0 -14
  80. package/dist/cjs/enhancement/walkComponentTree.js +0 -1
  81. package/dist/cjs/index.d.ts +0 -17
  82. package/dist/cjs/index.js +0 -1
  83. package/dist/cjs/preview/EventNames.d.ts +0 -1
  84. package/dist/cjs/preview/EventNames.js +0 -1
  85. package/dist/cjs/preview/createEventBus.d.ts +0 -6
  86. package/dist/cjs/preview/createEventBus.js +0 -1
  87. package/dist/cjs/preview/getChannelName.d.ts +0 -1
  88. package/dist/cjs/preview/getChannelName.js +0 -1
  89. package/dist/cjs/preview/subscribeToComposition.d.ts +0 -13
  90. package/dist/cjs/preview/subscribeToComposition.js +0 -1
  91. package/dist/cjs/types/componentDefinitions.d.ts +0 -90
  92. package/dist/cjs/types/componentDefinitions.js +0 -1
  93. package/dist/cjs/types/componentInstances.d.ts +0 -104
  94. package/dist/cjs/types/componentInstances.js +0 -1
  95. package/dist/cjs/types/enhancement.d.ts +0 -79
  96. package/dist/cjs/types/enhancement.js +0 -1
  97. package/dist/cjs/types/index.d.ts +0 -3
  98. package/dist/cjs/types/index.js +0 -1
  99. package/dist/cjs/utils/constants.d.ts +0 -20
  100. package/dist/cjs/utils/constants.js +0 -1
  101. package/dist/cjs/utils/isSystemComponentDefinition.d.ts +0 -2
  102. package/dist/cjs/utils/isSystemComponentDefinition.js +0 -1
  103. package/dist/cjs/utils/mapSlotToPersonalizedVariations.d.ts +0 -7
  104. package/dist/cjs/utils/mapSlotToPersonalizedVariations.js +0 -1
  105. package/dist/esm/CanvasClient.d.ts +0 -50
  106. package/dist/esm/CanvasClient.js +0 -1
  107. package/dist/esm/cli/arraySyncEngineDataSource.d.ts +0 -10
  108. package/dist/esm/cli/arraySyncEngineDataSource.js +0 -1
  109. package/dist/esm/cli/cli.d.ts +0 -3
  110. package/dist/esm/cli/cli.js +0 -1
  111. package/dist/esm/cli/commands/component/_util.d.ts +0 -3
  112. package/dist/esm/cli/commands/component/_util.js +0 -1
  113. package/dist/esm/cli/commands/component/get.d.ts +0 -7
  114. package/dist/esm/cli/commands/component/get.js +0 -1
  115. package/dist/esm/cli/commands/component/list.d.ts +0 -6
  116. package/dist/esm/cli/commands/component/list.js +0 -1
  117. package/dist/esm/cli/commands/component/pull.d.ts +0 -10
  118. package/dist/esm/cli/commands/component/pull.js +0 -1
  119. package/dist/esm/cli/commands/component/push.d.ts +0 -9
  120. package/dist/esm/cli/commands/component/push.js +0 -1
  121. package/dist/esm/cli/commands/component/remove.d.ts +0 -7
  122. package/dist/esm/cli/commands/component/remove.js +0 -1
  123. package/dist/esm/cli/commands/component/update.d.ts +0 -7
  124. package/dist/esm/cli/commands/component/update.js +0 -1
  125. package/dist/esm/cli/commands/component.d.ts +0 -2
  126. package/dist/esm/cli/commands/component.js +0 -1
  127. package/dist/esm/cli/commands/composition/_util.d.ts +0 -3
  128. package/dist/esm/cli/commands/composition/_util.js +0 -1
  129. package/dist/esm/cli/commands/composition/get.d.ts +0 -8
  130. package/dist/esm/cli/commands/composition/get.js +0 -1
  131. package/dist/esm/cli/commands/composition/list.d.ts +0 -8
  132. package/dist/esm/cli/commands/composition/list.js +0 -1
  133. package/dist/esm/cli/commands/composition/pull.d.ts +0 -10
  134. package/dist/esm/cli/commands/composition/pull.js +0 -1
  135. package/dist/esm/cli/commands/composition/push.d.ts +0 -9
  136. package/dist/esm/cli/commands/composition/push.js +0 -1
  137. package/dist/esm/cli/commands/composition/remove.d.ts +0 -7
  138. package/dist/esm/cli/commands/composition/remove.js +0 -1
  139. package/dist/esm/cli/commands/composition/update.d.ts +0 -7
  140. package/dist/esm/cli/commands/composition/update.js +0 -1
  141. package/dist/esm/cli/commands/composition.d.ts +0 -2
  142. package/dist/esm/cli/commands/composition.js +0 -1
  143. package/dist/esm/cli/componentDefinitionEngineDataSource.d.ts +0 -7
  144. package/dist/esm/cli/componentDefinitionEngineDataSource.js +0 -1
  145. package/dist/esm/cli/componentInstanceEngineDataSource.d.ts +0 -9
  146. package/dist/esm/cli/componentInstanceEngineDataSource.js +0 -1
  147. package/dist/esm/cli/fileSyncEngineDataSource.d.ts +0 -9
  148. package/dist/esm/cli/fileSyncEngineDataSource.js +0 -1
  149. package/dist/esm/cli/package.d.ts +0 -7
  150. package/dist/esm/cli/package.js +0 -1
  151. package/dist/esm/cli/syncEngine.d.ts +0 -49
  152. package/dist/esm/cli/syncEngine.js +0 -1
  153. package/dist/esm/cli/syncEngineConsoleLogger.d.ts +0 -5
  154. package/dist/esm/cli/syncEngineConsoleLogger.js +0 -1
  155. package/dist/esm/cli/util.d.ts +0 -43
  156. package/dist/esm/cli/util.js +0 -1
  157. package/dist/esm/enhancement/EnhancerBuilder.d.ts +0 -66
  158. package/dist/esm/enhancement/EnhancerBuilder.js +0 -1
  159. package/dist/esm/enhancement/UniqueBatchEntries.d.ts +0 -17
  160. package/dist/esm/enhancement/UniqueBatchEntries.js +0 -1
  161. package/dist/esm/enhancement/batchEnhancer.d.ts +0 -39
  162. package/dist/esm/enhancement/batchEnhancer.js +0 -1
  163. package/dist/esm/enhancement/compose.d.ts +0 -6
  164. package/dist/esm/enhancement/compose.js +0 -1
  165. package/dist/esm/enhancement/createLimitPolicy.d.ts +0 -8
  166. package/dist/esm/enhancement/createLimitPolicy.js +0 -1
  167. package/dist/esm/enhancement/enhance.d.ts +0 -18
  168. package/dist/esm/enhancement/enhance.js +0 -1
  169. package/dist/esm/enhancement/localize.d.ts +0 -11
  170. package/dist/esm/enhancement/localize.js +0 -1
  171. package/dist/esm/enhancement/walkComponentTree.d.ts +0 -14
  172. package/dist/esm/enhancement/walkComponentTree.js +0 -1
  173. package/dist/esm/index.d.ts +0 -17
  174. package/dist/esm/index.js +0 -1
  175. package/dist/esm/preview/EventNames.d.ts +0 -1
  176. package/dist/esm/preview/EventNames.js +0 -0
  177. package/dist/esm/preview/createEventBus.d.ts +0 -6
  178. package/dist/esm/preview/createEventBus.js +0 -1
  179. package/dist/esm/preview/getChannelName.d.ts +0 -1
  180. package/dist/esm/preview/getChannelName.js +0 -1
  181. package/dist/esm/preview/subscribeToComposition.d.ts +0 -13
  182. package/dist/esm/preview/subscribeToComposition.js +0 -1
  183. package/dist/esm/types/componentDefinitions.d.ts +0 -90
  184. package/dist/esm/types/componentDefinitions.js +0 -0
  185. package/dist/esm/types/componentInstances.d.ts +0 -104
  186. package/dist/esm/types/componentInstances.js +0 -0
  187. package/dist/esm/types/enhancement.d.ts +0 -79
  188. package/dist/esm/types/enhancement.js +0 -0
  189. package/dist/esm/types/index.d.ts +0 -3
  190. package/dist/esm/types/index.js +0 -1
  191. package/dist/esm/utils/constants.d.ts +0 -20
  192. package/dist/esm/utils/constants.js +0 -1
  193. package/dist/esm/utils/isSystemComponentDefinition.d.ts +0 -2
  194. package/dist/esm/utils/isSystemComponentDefinition.js +0 -1
  195. package/dist/esm/utils/mapSlotToPersonalizedVariations.d.ts +0 -7
  196. package/dist/esm/utils/mapSlotToPersonalizedVariations.js +0 -1
@@ -1 +0,0 @@
1
- import chalk from"chalk";function createSyncEngineConsoleLogger(e){var l=e.diffMode;return function(e){var a=e.action,n=e.displayName,c=e.whatIf,o=e.diff,r="";switch(a){case"create":r=chalk.green("[A]");break;case"update":r=chalk.white("[U]");break;case"delete":r=chalk.yellow("[D]")}e="";("on"===l||"update"===l&&"update"===a)&&(e="\n"+o.map(function(e){return e.added?chalk.green(e.value):e.removed?chalk.red(e.value):e.value}).join("")),console.log(""+(c?chalk.gray("[WHATIF]"):"")+r+" "+n+e)}}export{createSyncEngineConsoleLogger};
@@ -1,43 +0,0 @@
1
- import { Argv } from 'yargs';
2
- import { CompositionAPIResponse } from '../types/componentInstances';
3
- import pLimit from 'p-limit';
4
- import { DiffMode } from './syncEngineConsoleLogger';
5
- export declare type ApiArgs = {
6
- apiKey: string;
7
- apiHost: string;
8
- };
9
- export declare function withApiOptions<T>(yargs: Argv<T>): Argv<T>;
10
- export declare type ProjectArgs = {
11
- project: string;
12
- };
13
- export declare function withProjectOptions<T>(yargs: Argv<T>): Argv<T>;
14
- export declare type FormatArgs = {
15
- format: 'json' | 'yaml';
16
- filename?: string;
17
- };
18
- export declare function withFormatOptions<T>(yargs: Argv<T>): Argv<T>;
19
- export declare type DiffArgs = {
20
- diff: DiffMode;
21
- };
22
- export declare function withDiffOptions<T>(yargs: Argv<T>): Argv<T>;
23
- export declare function isPathAPackageFile(path: string): boolean;
24
- export declare function emitWithFormat(object: any, format?: string, filename?: string): void;
25
- export declare function readFileToObject<T = unknown>(filename: string): T;
26
- export declare function prepCompositionForDisk(composition: CompositionAPIResponse): {
27
- state: number;
28
- projectId: string;
29
- composition: import("../types/componentInstances").RootComponentInstance;
30
- pattern: boolean;
31
- created?: string | undefined;
32
- modified?: string | undefined;
33
- };
34
- export declare type CLICompositionState = 'preview' | 'published' | number;
35
- export declare type StateArgs = {
36
- state: CLICompositionState;
37
- };
38
- export declare function withStateOptions<T>(yargs: Argv<T>): Argv<T>;
39
- export declare function paginateAsync<TResult>(fetchPage: (offset: number, limit: number) => Promise<TResult[]>, options: {
40
- pageSize: number;
41
- }): AsyncIterableIterator<TResult>;
42
- export declare function convertCompositionState(state: CLICompositionState): number;
43
- export declare const limitPolicy: pLimit.Limit;
@@ -1 +0,0 @@
1
- var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},__generator=this&&this.__generator||function(n,r){var o,i,a,s={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},t={next:e(0),throw:e(1),return:e(2)};return"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(o)throw new TypeError("Generator is already executing.");for(;s;)try{if(o=1,i&&(a=2&e[0]?i.return:e[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,e[1])).done)return a;switch(i=0,(e=a?[2&e[0],a.value]:e)[0]){case 0:case 1:a=e;break;case 4:return s.label++,{value:e[1],done:!1};case 5:s.label++,i=e[1],e=[0];continue;case 7:e=s.ops.pop(),s.trys.pop();continue;default:if(!(a=0<(a=s.trys).length&&a[a.length-1])&&(6===e[0]||2===e[0])){s=0;continue}if(3===e[0]&&(!a||e[1]>a[0]&&e[1]<a[3])){s.label=e[1];break}if(6===e[0]&&s.label<a[1]){s.label=a[1],a=e;break}if(a&&s.label<a[2]){s.label=a[2],s.ops.push(e);break}a[2]&&s.ops.pop(),s.trys.pop();continue}e=r.call(n,s)}catch(t){e=[6,t],i=0}finally{o=a=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}},__await=this&&this.__await||function(t){return this instanceof __await?(this.v=t,this):new __await(t)},__asyncGenerator=this&&this.__asyncGenerator||function(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o=n.apply(t,e||[]),i=[],a={};return r("next"),r("throw"),r("return"),a[Symbol.asyncIterator]=function(){return this},a;function r(r){o[r]&&(a[r]=function(n){return new Promise(function(t,e){1<i.push([r,n,t,e])||s(r,n)})})}function s(t,e){try{(n=o[t](e)).value instanceof __await?Promise.resolve(n.value.v).then(u,l):c(i[0][2],n)}catch(t){c(i[0][3],t)}var n}function u(t){s("next",t)}function l(t){s("throw",t)}function c(t,e){t(e),i.shift(),i.length&&s(i[0][0],i[0][1])}},__values=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return{value:(t=t&&r>=t.length?void 0:t)&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};import{dump,load}from"js-yaml";import{writeFileSync}from"fs";import{extname}from"path";import{readFileSync}from"fs";import{CANVAS_DRAFT_STATE,CANVAS_PUBLISHED_STATE}from"../utils/constants";import pLimit from"p-limit";function withApiOptions(t){return t.option("apiKey",{describe:"Uniform API key. Defaults to CANVAS_CLI_API_KEY or UNIFORM_API_KEY env. Supports dotenv.",default:null!==(t=null!==(t=process.env.CANVAS_CLI_API_KEY)&&void 0!==t?t:process.env.UPM_CLI_API_KEY)&&void 0!==t?t:process.env.UNIFORM_API_KEY,demandOption:!0,type:"string"}).option("apiHost",{describe:"Uniform host. Defaults to UNIFORM_CLI_BASE_URL env or https://uniform.app. Supports dotenv.",default:process.env.UNIFORM_CLI_BASE_URL||"https://uniform.app",demandOption:!0,type:"string"})}function withProjectOptions(t){return t.option("project",{describe:"Uniform project ID. Defaults to CANVAS_CLI_PROJECT_ID or UNIFORM_PROJECT_ID env. Supports dotenv.",default:null!==(t=null!==(t=process.env.CANVAS_CLI_PROJECT_ID)&&void 0!==t?t:process.env.UPM_CLI_PROJECT_ID)&&void 0!==t?t:process.env.UNIFORM_PROJECT_ID,demandOption:!0,type:"string",alias:["p"]})}function withFormatOptions(t){return t.option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("filename",{alias:["o"],describe:"Output filename. If not specified, write to stdout.",type:"string"})}function withDiffOptions(t){return t.option("diff",{describe:"Whether to show diffs in stdout. off = no diffs; update = on for updates; on = updates, creates, deletes",default:"off",type:"string",choices:["off","update","on"],alias:["d"]})}function isPathAPackageFile(t){t=extname(t);return".yaml"===t||".yml"===t||".json"===t}function emitWithFormat(t,e,n){var r;if(n&&!e){var o=extname(n);".yaml"===o||".yml"===o?e="yaml":".json"===o&&(e="json")}else if(!e)throw new Error("Format must be specified when no filename is passed");switch(e){case"json":r=JSON.stringify(t,null,2);break;case"yaml":r=dump(t);break;default:throw new Error("Unsupported format: "+e)}n?writeFileSync(n,r,"utf8"):console.log(r)}function readFileToObject(t){var e=readFileSync(t,"utf8");return load(e,{filename:t,json:!0})}function prepCompositionForDisk(t){t=__assign({},t);return delete t.projectId,delete t.state,t}function withStateOptions(t){return t.option("state",{type:"string",describe:"Composition state to fetch.",choices:["preview","published"],default:"preview"})}function paginateAsync(l,c){return __asyncGenerator(this,arguments,function(){var e,n,r,o,i,a,s,u;return __generator(this,function(t){switch(t.label){case 0:e=c.pageSize||100,n=0,r=[],t.label=1;case 1:return[4,__await(l(n,e))];case 2:r=t.sent(),t.label=3;case 3:t.trys.push([3,9,10,11]),s=void 0,o=__values(r),i=o.next(),t.label=4;case 4:return i.done?[3,8]:(a=i.value,[4,__await(a)]);case 5:return[4,t.sent()];case 6:t.sent(),t.label=7;case 7:return i=o.next(),[3,4];case 8:return[3,11];case 9:return a=t.sent(),s={error:a},[3,11];case 10:try{i&&!i.done&&(u=o.return)&&u.call(o)}finally{if(s)throw s.error}return[7];case 11:n+=e,t.label=12;case 12:if(r.length===e)return[3,1];t.label=13;case 13:return[2]}})})}function convertCompositionState(t){var e=Number(t);if(!isNaN(e))return e;if(!t)return CANVAS_PUBLISHED_STATE;if("string"!=typeof t)throw new Error('state must be "published", "preview", or a number');return"preview"===t?CANVAS_DRAFT_STATE:CANVAS_PUBLISHED_STATE}var limitPolicy=pLimit(8);export{withApiOptions,withProjectOptions,withFormatOptions,withDiffOptions,isPathAPackageFile,emitWithFormat,readFileToObject,prepCompositionForDisk,withStateOptions,paginateAsync,convertCompositionState,limitPolicy};
@@ -1,66 +0,0 @@
1
- import { ComponentEnhancer, ComponentEnhancerFunction, ComponentParameterEnhancer, ComponentParameterEnhancerFunction } from '../types';
2
- import { ComponentInstance, ComponentParameter } from '../types/componentInstances';
3
- /**
4
- * Builds a definition of the enhancers to run on Canvas components to add data from other systems.
5
- * Note that only the first matching enhancer will be run.
6
- */
7
- export declare class ChildEnhancerBuilder {
8
- private _paramMatches;
9
- private _dataMatches;
10
- /** Targets an enhancer to modify the value of any parameter */
11
- parameter(enhancer: ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction<any>): this;
12
- /** Targets an enhancer to modify the value of any parameter with a specific name */
13
- parameterName(name: string | readonly string[], enhancer: ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction<any>): this;
14
- /** Targets an enhancer to modify the value of any parameter with a specific type */
15
- parameterType(type: string | readonly string[], enhancer: ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction<any>): this;
16
- /**
17
- * Targets an enhancer to set a specific object key on the component's `data` property.
18
- * Note: an exception will be thrown if the same key is registered more than once.
19
- */
20
- data(name: string, enhancer: ComponentEnhancer<any> | ComponentEnhancerFunction<any>): this;
21
- /**
22
- * Resolves the parameter enhancer for a given parameter, if one exists.
23
- * The first matching enhancer by registration order is returned, if more than one could match.
24
- */
25
- resolveParameterEnhancer(parameterName: string, parameter: ComponentParameter): ComponentParameterEnhancer<unknown, unknown, import("../types").EnhancerContext> | undefined;
26
- /**
27
- * Resolves component enhancer(s) for a given component.
28
- * Returns a Map where the key is the name of the data property and the value is the enhancer.
29
- */
30
- resolveComponentEnhancers(): Map<string, ComponentEnhancer<unknown, import("../types").EnhancerContext>>;
31
- private _resolveParameterEnhancer;
32
- }
33
- /**
34
- * Builds a definition of the enhancers to run on Canvas components to add data from other systems.
35
- * Note that only the first matching enhancer will be run.
36
- */
37
- export declare class EnhancerBuilder {
38
- private _componentIndex;
39
- private _rootBuilder;
40
- /** Targets an enhancer to modify the value of any parameter */
41
- parameter(enhancer: ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction): this;
42
- /** Targets an enhancer to modify the value of any parameter with a specific name */
43
- parameterName(name: string | readonly string[], enhancer: ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction): this;
44
- /** Targets an enhancer to modify the value of any parameter with a specific type */
45
- parameterType(type: string | readonly string[], enhancer: ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction<any>): this;
46
- /**
47
- * Targets an enhancer to set a specific object key on the component's `data` property.
48
- * Note: an exception will be thrown if the same key is registered more than once.
49
- */
50
- data(name: string, enhancer: ComponentEnhancer<any> | ComponentEnhancerFunction<any>): this;
51
- /**
52
- * Targets a subset of enhancers at a specific component type.
53
- * Global enhancers will still be run if no matching enhancer is registered for this component's properties.
54
- */
55
- component(name: string | readonly string[], builder: (builder: ChildEnhancerBuilder) => void): EnhancerBuilder;
56
- /**
57
- * Resolves the parameter enhancer for a given parameter, if one exists.
58
- * The first matching enhancer by registration order is returned, if more than one could match.
59
- */
60
- resolveParameterEnhancer(component: ComponentInstance, parameterName: string, parameter: ComponentParameter): ComponentParameterEnhancer<unknown, unknown, import("../types").EnhancerContext> | undefined;
61
- /**
62
- * Resolves component enhancer(s) for a given component.
63
- * Returns a Map where the key is the name of the data property and the value is the enhancer.
64
- */
65
- resolveComponentEnhancers(component: ComponentInstance): Map<string, ComponentEnhancer<unknown, import("../types").EnhancerContext>>;
66
- }
@@ -1 +0,0 @@
1
- var __values=this&&this.__values||function(e){var r="function"==typeof Symbol&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return{value:(e=e&&n>=e.length?void 0:e)&&e[n++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")},__read=this&&this.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,a,o=t.call(e),i=[];try{for(;(void 0===r||0<r--)&&!(n=o.next()).done;)i.push(n.value)}catch(e){a={error:e}}finally{try{n&&!n.done&&(t=o.return)&&t.call(o)}finally{if(a)throw a.error}}return i},ChildEnhancerBuilder=function(){function e(){this._paramMatches=Array(),this._dataMatches=new Map}return e.prototype.parameter=function(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this},e.prototype.parameterName=function(e,r){var t=this;return(Array.isArray(e)?e:[e]).forEach(function(e){return t._paramMatches.push({name:e,enhancer:t._resolveParameterEnhancer(r)})}),this},e.prototype.parameterType=function(e,r){var t=this;return(Array.isArray(e)?e:[e]).forEach(function(e){return t._paramMatches.push({type:e,enhancer:t._resolveParameterEnhancer(r)})}),this},e.prototype.data=function(e,r){if(this._dataMatches.has(e))throw new Error(e+" enhancer data key has been used more than once. This will cause data loss.");return this._dataMatches.set(e,"function"==typeof r?{enhanceOne:r}:r),this},e.prototype.resolveParameterEnhancer=function(r,t){var e;return null===(e=this._paramMatches.find(function(e){return e.name&&e.name===r||e.type&&e.type===t.type||!e.type&&!e.name}))||void 0===e?void 0:e.enhancer},e.prototype.resolveComponentEnhancers=function(){return this._dataMatches},e.prototype._resolveParameterEnhancer=function(e){return"function"==typeof e?{enhanceOne:e}:e},e}(),EnhancerBuilder=function(){function e(){this._componentIndex={},this._rootBuilder=new ChildEnhancerBuilder}return e.prototype.parameter=function(e){return this._rootBuilder.parameter(e),this},e.prototype.parameterName=function(e,r){return this._rootBuilder.parameterName(e,r),this},e.prototype.parameterType=function(e,r){return this._rootBuilder.parameterType(e,r),this},e.prototype.data=function(e,r){return this._rootBuilder.data(e,r),this},e.prototype.component=function(e,r){var t=this;return(Array.isArray(e)?e:[e]).forEach(function(e){t._componentIndex[e]=t._componentIndex[e]||new ChildEnhancerBuilder,r(t._componentIndex[e])}),this},e.prototype.resolveParameterEnhancer=function(e,r,t){e=this._componentIndex[e.type];if(e){e=e.resolveParameterEnhancer(r,t);if(e)return e}return this._rootBuilder.resolveParameterEnhancer(r,t)},e.prototype.resolveComponentEnhancers=function(e){var r,t,n=this._rootBuilder.resolveComponentEnhancers(),e=this._componentIndex[e.type];if(e){n=new Map(n);try{for(var a=__values(e.resolveComponentEnhancers()),o=a.next();!o.done;o=a.next()){var i=__read(o.value,2),h=i[0],c=i[1];n.set(h,c)}}catch(e){r={error:e}}finally{try{o&&!o.done&&(t=a.return)&&t.call(a)}finally{if(r)throw r.error}}}return n},e}();export{ChildEnhancerBuilder,EnhancerBuilder};
@@ -1,17 +0,0 @@
1
- import { BatchEntry } from './batchEnhancer';
2
- /**
3
- * Given a batch of enhancements containing potentially duplicate entries (i.e. several components referencing the same thing),
4
- * group them together by some unique identifier and enable simpler batch processing.
5
- */
6
- export declare class UniqueBatchEntries<TArgs, TResult> {
7
- groups: Readonly<Record<string, ReadonlyArray<Readonly<BatchEntry<TArgs, TResult>>>>>;
8
- constructor(
9
- /** The batch queue being processed. */
10
- entries: ReadonlyArray<Readonly<BatchEntry<TArgs, TResult>>>,
11
- /** A function to select the unique identifier for a given batch entry. */
12
- uniqueKeySelector: (entry: Readonly<TArgs>) => string);
13
- /** Resolves all entries in a group key with the same result value. */
14
- resolveKey(key: string, result: TResult): void;
15
- /** Resolves all remaining entries that have not been otherwise resolved with a specific value */
16
- resolveRemaining(value: TResult): void;
17
- }
@@ -1 +0,0 @@
1
- var UniqueBatchEntries=function(){function r(r,t){this.groups=r.reduce(function(r,e){var n,o=t(e.args);return r[o]=null!==(n=r[o])&&void 0!==n?n:[],r[o].push(e),r},{})}return r.prototype.resolveKey=function(r,e){this.groups[r].forEach(function(r){return r.resolve(e)})},r.prototype.resolveRemaining=function(e){var n=this;Object.keys(this.groups).forEach(function(r){n.groups[r].forEach(function(r){r.isCompleted||r.resolve(e)})})},r}();export{UniqueBatchEntries};
@@ -1,39 +0,0 @@
1
- import { LimitPolicy } from '..';
2
- /** A single entry in a batch of queued enhancements. */
3
- export declare class BatchEntry<TArgs, TResult> {
4
- private _resolve;
5
- private _reject;
6
- args: TArgs;
7
- private _isCompleted;
8
- constructor(_resolve: (result: TResult) => void, _reject: (reason: any) => void, args: TArgs);
9
- /** Mark the batch entry as successfully completed. */
10
- resolve(result: TResult): void;
11
- /** Mark the batch entry as failed. */
12
- reject(reason: any): void;
13
- /** @return Whether the batch entry has been completed (resolved or rejected). */
14
- get isCompleted(): boolean;
15
- }
16
- /**
17
- * An enhancer that queues up promises for each component that needs enhancing,
18
- * and once all enhancements have been queued handles them all in a batch.
19
- * Note: this type is adaptable to both ComponentParameterEnhancer and ComponentEnhancer types.
20
- */
21
- export declare type BatchEnhancer<TArgs, TResult> = {
22
- /** Adds a promise to the enhancement queue. */
23
- enhanceOne: (args: TArgs) => Promise<TResult | undefined>;
24
- /** Calls the batch enhancer function for all queued promises and resolves them. Returns number of processed items. */
25
- completeAll: () => Promise<number>;
26
- limitPolicy?: LimitPolicy;
27
- };
28
- /**
29
- * Creates an enhancer that batches up all enhancements for a composition into a set of promises,
30
- * and then handles them all in a single batch. Used to reduce the number of HTTP requests
31
- * needed to fulfill layout enhancements when a layout uses many resources from other systems.
32
- */
33
- export declare function createBatchEnhancer<TArgs, TResult>({ handleBatch, shouldQueue, limitPolicy, }: {
34
- /** Function called to handle one or more batched up enhancements. (note: queue will never be an empty array) */
35
- handleBatch: (queue: ReadonlyArray<Readonly<BatchEntry<TArgs, TResult>>>) => Promise<void>;
36
- /** Function called to determine if a given enhancement should be queued, i.e. don't queue invalid or null/undefined values. */
37
- shouldQueue?: (args: TArgs) => boolean;
38
- limitPolicy?: LimitPolicy;
39
- }): BatchEnhancer<TArgs, TResult>;
@@ -1 +0,0 @@
1
- var __awaiter=this&&this.__awaiter||function(e,a,c,u){return new(c=c||Promise)(function(n,t){function r(e){try{i(u.next(e))}catch(e){t(e)}}function o(e){try{i(u.throw(e))}catch(e){t(e)}}function i(e){var t;e.done?n(e.value):((t=e.value)instanceof c?t:new c(function(e){e(t)})).then(r,o)}i((u=u.apply(e,a||[])).next())})},__generator=this&&this.__generator||function(n,r){var o,i,a,c={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},e={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(o)throw new TypeError("Generator is already executing.");for(;c;)try{if(o=1,i&&(a=2&t[0]?i.return:t[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,t[1])).done)return a;switch(i=0,(t=a?[2&t[0],a.value]:t)[0]){case 0:case 1:a=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,i=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!(a=0<(a=c.trys).length&&a[a.length-1])&&(6===t[0]||2===t[0])){c=0;continue}if(3===t[0]&&(!a||t[1]>a[0]&&t[1]<a[3])){c.label=t[1];break}if(6===t[0]&&c.label<a[1]){c.label=a[1],a=t;break}if(a&&c.label<a[2]){c.label=a[2],c.ops.push(t);break}a[2]&&c.ops.pop(),c.trys.pop();continue}t=r.call(n,c)}catch(e){t=[6,e],i=0}finally{o=a=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}},BatchEntry=function(){function e(e,t,n){this._resolve=e,this._reject=t,this.args=n,this._isCompleted=!1}return e.prototype.resolve=function(e){this._resolve(e),this._isCompleted=!0},e.prototype.reject=function(e){this._reject(e),this._isCompleted=!0},Object.defineProperty(e.prototype,"isCompleted",{get:function(){return this._isCompleted},enumerable:!1,configurable:!0}),e}();function createBatchEnhancer(e){var t=this,r=e.handleBatch,o=e.shouldQueue,e=e.limitPolicy,i=[];return{enhanceOne:function(n){return __awaiter(t,void 0,void 0,function(){return __generator(this,function(e){return!o||o(n)?[2,new Promise(function(e,t){i.push(new BatchEntry(e,t,n))})]:[2,void 0]})})},completeAll:function(){return __awaiter(t,void 0,void 0,function(){var t,n;return __generator(this,function(e){switch(e.label){case 0:if(!(0<i.length))return[3,5];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,r(i)];case 2:return e.sent(),[3,4];case 3:return t=e.sent(),i.forEach(function(e){return e.reject(t)}),[3,4];case 4:if(i.some(function(e){return!e.isCompleted}))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!");e.label=5;case 5:return n=i.length,i=[],[2,n]}})})},limitPolicy:e}}export{BatchEntry,createBatchEnhancer};
@@ -1,6 +0,0 @@
1
- import { ComponentParameterEnhancer, ComponentParameterEnhancerFunction } from '../types/enhancement';
2
- /**
3
- * Composes several enhancers into a synchronous chain. Can be used to modify the output of an enhancer.
4
- * NOTE: only the first enhancer in the chain may use batching (completeAll()).
5
- */
6
- export declare const compose: (input: ComponentParameterEnhancer<any, any>, ...composers: ReadonlyArray<ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction<any>>) => ComponentParameterEnhancer<any, any>;
@@ -1 +0,0 @@
1
- var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++)for(var o in n=arguments[r])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e}).apply(this,arguments)},__values=this&&this.__values||function(e){var n="function"==typeof Symbol&&Symbol.iterator,r=n&&e[n],t=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return{value:(e=e&&t>=e.length?void 0:e)&&e[t++],done:!e}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},compose=function(l){for(var a=[],e=1;e<arguments.length;e++)a[e-1]=arguments[e];return{enhanceOne:function(t){var n,e,o=l.enhanceOne(t);try{for(var r=__values(a),i=r.next();!i.done;i=r.next())!function(e){var n=isPromise(o)?o:Promise.resolve(o),r="enhanceOne"in e?e.enhanceOne:e;o=n.then(function(e){return r(__assign(__assign({},t),{parameter:{type:t.parameter.type,value:e}}))})}(i.value)}catch(e){n={error:e}}finally{try{i&&!i.done&&(e=r.return)&&e.call(r)}finally{if(n)throw n.error}}return o},completeAll:function(){var e,n;try{for(var r=__values(a),t=r.next();!t.done;t=r.next())if("completeAll"in t.value)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)")}catch(e){n={error:e}}finally{try{t&&!t.done&&(e=r.return)&&e.call(r)}finally{if(n)throw n.error}}return null!==(n=null===(n=l.completeAll)||void 0===n?void 0:n.call(l))&&void 0!==n?n:Promise.resolve(0)}}};function isPromise(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}export{compose};
@@ -1,8 +0,0 @@
1
- import { Options as ThrottleOptions } from 'p-throttle';
2
- import { Options as RetryOptions } from 'p-retry';
3
- export declare type LimitPolicy = <ReturnValue>(func: () => Promise<ReturnValue>) => Promise<ReturnValue>;
4
- export declare function createLimitPolicy({ throttle, retry, }: {
5
- throttle?: ThrottleOptions | false;
6
- retry?: RetryOptions | false;
7
- }): LimitPolicy;
8
- export declare const nullLimitPolicy: LimitPolicy;
@@ -1 +0,0 @@
1
- var __awaiter=this&&this.__awaiter||function(t,a,u,c){return new(u=u||Promise)(function(r,e){function n(t){try{o(c.next(t))}catch(t){e(t)}}function i(t){try{o(c.throw(t))}catch(t){e(t)}}function o(t){var e;t.done?r(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(n,i)}o((c=c.apply(t,a||[])).next())})},__generator=this&&this.__generator||function(r,n){var i,o,a,u={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},t={next:e(0),throw:e(1),return:e(2)};return"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;u;)try{if(i=1,o&&(a=2&e[0]?o.return:e[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,e[1])).done)return a;switch(o=0,(e=a?[2&e[0],a.value]:e)[0]){case 0:case 1:a=e;break;case 4:return u.label++,{value:e[1],done:!1};case 5:u.label++,o=e[1],e=[0];continue;case 7:e=u.ops.pop(),u.trys.pop();continue;default:if(!(a=0<(a=u.trys).length&&a[a.length-1])&&(6===e[0]||2===e[0])){u=0;continue}if(3===e[0]&&(!a||e[1]>a[0]&&e[1]<a[3])){u.label=e[1];break}if(6===e[0]&&u.label<a[1]){u.label=a[1],a=e;break}if(a&&u.label<a[2]){u.label=a[2],u.ops.push(e);break}a[2]&&u.ops.pop(),u.trys.pop();continue}e=n.call(r,u)}catch(t){e=[6,t],o=0}finally{i=a=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}};import pThrottle from"p-throttle";import pRetry from"p-retry";function createLimitPolicy(t){var e=t.throttle,e=void 0===e?{interval:1e3,limit:10}:e,t=t.retry,i=void 0===t?{retries:1,factor:1.66}:t,o=e?pThrottle(e):null;return function(e){var t,r=this,n=function(){return __awaiter(r,void 0,void 0,function(){return __generator(this,function(t){switch(t.label){case 0:return[4,e()];case 1:return[2,t.sent()]}})})};return o&&(n=o(n)),i&&(t=n,n=function(){return pRetry(t,i)}),n()}}var nullLimitPolicy=function(e){return __awaiter(void 0,void 0,void 0,function(){return __generator(this,function(t){switch(t.label){case 0:return[4,e()];case 1:return[2,t.sent()]}})})};export{createLimitPolicy,nullLimitPolicy};
@@ -1,18 +0,0 @@
1
- import { EnhancerContext } from '../types';
2
- import { ComponentInstance } from '../types/componentInstances';
3
- import { EnhancerBuilder } from './EnhancerBuilder';
4
- export declare type EnhancerError = {
5
- message: string;
6
- error: Error | string;
7
- };
8
- /**
9
- * Applies enhancer functions to a component tree.
10
- * IMPORTANT: the input composition object is mutated. Plan accordingly.
11
- * Want immutability? Grab immer :)
12
- */
13
- export declare function enhance<TContext extends EnhancerContext = EnhancerContext>({ composition, enhancers, context, onErrors, }: {
14
- composition: ComponentInstance;
15
- enhancers: EnhancerBuilder;
16
- context: TContext;
17
- onErrors?: (errors: EnhancerError[]) => void;
18
- }): Promise<void>;
@@ -1 +0,0 @@
1
- var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var a in r=arguments[t])Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e}).apply(this,arguments)},__awaiter=this&&this.__awaiter||function(e,i,c,l){return new(c=c||Promise)(function(t,r){function n(e){try{o(l.next(e))}catch(e){r(e)}}function a(e){try{o(l.throw(e))}catch(e){r(e)}}function o(e){var r;e.done?t(e.value):((r=e.value)instanceof c?r:new c(function(e){e(r)})).then(n,a)}o((l=l.apply(e,i||[])).next())})},__generator=this&&this.__generator||function(t,n){var a,o,i,c={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},e={next:r(0),throw:r(1),return:r(2)};return"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function r(r){return function(e){return function(r){if(a)throw new TypeError("Generator is already executing.");for(;c;)try{if(a=1,o&&(i=2&r[0]?o.return:r[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,r[1])).done)return i;switch(o=0,(r=i?[2&r[0],i.value]:r)[0]){case 0:case 1:i=r;break;case 4:return c.label++,{value:r[1],done:!1};case 5:c.label++,o=r[1],r=[0];continue;case 7:r=c.ops.pop(),c.trys.pop();continue;default:if(!(i=0<(i=c.trys).length&&i[i.length-1])&&(6===r[0]||2===r[0])){c=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){c.label=r[1];break}if(6===r[0]&&c.label<i[1]){c.label=i[1],i=r;break}if(i&&c.label<i[2]){c.label=i[2],c.ops.push(r);break}i[2]&&c.ops.pop(),c.trys.pop();continue}r=n.call(t,c)}catch(e){r=[6,e],o=0}finally{a=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,e])}}},__read=this&&this.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,a,o=t.call(e),i=[];try{for(;(void 0===r||0<r--)&&!(n=o.next()).done;)i.push(n.value)}catch(e){a={error:e}}finally{try{n&&!n.done&&(t=o.return)&&t.call(o)}finally{if(a)throw a.error}}return i},__spreadArray=this&&this.__spreadArray||function(e,r,t){if(t||2===arguments.length)for(var n,a=0,o=r.length;a<o;a++)!n&&a in r||((n=n||Array.prototype.slice.call(r,0,a))[a]=r[a]);return e.concat(n||Array.prototype.slice.call(r))};import{nullLimitPolicy}from"./createLimitPolicy";import{getComponentPath,walkComponentTree}from"./walkComponentTree";function enhance(e){var a=e.composition,c=e.enhancers,l=e.context,e=e.onErrors,u=void 0===e?function(e){throw new Error(e.map(function(e){return e.message+"\n "+("object"==typeof e.error&&"stack"in e.error?e.error.stack:e.error)}).join("\n\n"))}:e;return __awaiter(this,void 0,void 0,function(){var o,r,i,t,n=this;return __generator(this,function(e){switch(e.label){case 0:return o=[],r=new Set,i=new Set,walkComponentTree(a,function(n,a){Object.entries(null!==(e=n.parameters)&&void 0!==e?e:{}).forEach(function(e){var r=__read(e,2),t=r[0],e=r[1],r=c.resolveParameterEnhancer(n,t,e);r&&(i.add(r),o.push(enhanceParameter(n,a,t,e,r,l)))});var e=c.resolveComponentEnhancers(n);o.push(enhanceComponent(n,a,e,l)),r.add(e)}),o.push.apply(o,__spreadArray([],__read(Array.from(r).flatMap(function(e){return Array.from(e).map(function(e){var t=__read(e,2)[1];return __awaiter(n,void 0,void 0,function(){var r;return __generator(this,function(e){switch(e.label){case 0:return(e.trys.push([0,3,,4]),t.completeAll)?[4,(null!==(r=t.limitPolicy)&&void 0!==r?r:nullLimitPolicy)(function(){return t.completeAll()})]:[3,2];case 1:e.sent(),e.label=2;case 2:return[3,4];case 3:return[2,{error:e.sent(),message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}];case 4:return[2]}})})})})),!1)),o.push.apply(o,__spreadArray([],__read(Array.from(i).map(function(t){return __awaiter(n,void 0,void 0,function(){var r;return __generator(this,function(e){switch(e.label){case 0:return(e.trys.push([0,3,,4]),t.completeAll)?[4,(null!==(r=t.limitPolicy)&&void 0!==r?r:nullLimitPolicy)(function(){return t.completeAll()})]:[3,2];case 1:e.sent(),e.label=2;case 2:return[3,4];case 3:return[2,{error:e.sent(),message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}];case 4:return[2]}})})})),!1)),[4,Promise.all(o)];case 1:return(t=e.sent().flatMap(function(e){return Array.isArray(e)?e:[e]}).filter(function(e){return e})).length&&u(t),[2]}})})}function enhanceComponent(c,l,t,u){return __awaiter(this,void 0,void 0,function(){var r=this;return __generator(this,function(e){switch(e.label){case 0:return t.size&&(c.data={}),[4,Promise.all(Array.from(t).map(function(e){var e=__read(e,2),o=e[0],i=e[1];return __awaiter(r,void 0,void 0,function(){var r,t,n,a=this;return __generator(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,(!i.completeAll&&null!==(n=i.limitPolicy)&&void 0!==n?n:nullLimitPolicy)(function(){return __awaiter(a,void 0,void 0,function(){return __generator(this,function(e){return[2,i.enhanceOne({component:c,context:u})]})})})];case 1:return null!=(t=e.sent())&&(c.data[o]=t),[3,3];case 2:return r=e.sent(),t="Component "+getComponentPath(l)+" (type: "+c.type+"): data."+o+" enhancer threw exception. Data key will not be present.",delete c.data[o],[2,{message:t,error:r}];case 3:return[2]}})})}))];case 1:return[2,e.sent()]}})})}function enhanceParameter(a,o,i,c,l,u){var s;return __awaiter(this,void 0,void 0,function(){var r,t,n=this;return __generator(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,(!l.completeAll&&null!==(s=l.limitPolicy)&&void 0!==s?s:nullLimitPolicy)(function(){return __awaiter(n,void 0,void 0,function(){return __generator(this,function(e){return[2,l.enhanceOne({parameter:c,parameterName:i,component:a,context:u})]})})})];case 1:return null===(t=e.sent())?delete a.parameters[i]:a.parameters[i]=__assign(__assign({},c),void 0===t?{value:c.value}:{value:t}),[3,3];case 2:return r=e.sent(),t="Component "+getComponentPath(o)+" (type: "+a.type+"): enhancing parameter "+i+" (type: "+c.type+") threw exception. Parameter will be removed.",delete a.parameters[i],[2,{message:t,error:r}];case 3:return[2]}})})}export{enhance};
@@ -1,11 +0,0 @@
1
- import { ComponentInstance } from '../types/componentInstances';
2
- export declare function extractLocales({ component }: {
3
- component: ComponentInstance;
4
- }): Record<string, ComponentInstance>;
5
- export declare function localize({ composition, locale, }: {
6
- composition: ComponentInstance;
7
- locale: string | ((options: {
8
- component: Readonly<ComponentInstance>;
9
- locales: Readonly<Record<string, ComponentInstance>>;
10
- }) => string | undefined);
11
- }): void;
@@ -1 +0,0 @@
1
- import{walkComponentTree}from"./walkComponentTree";import{CANVAS_LOCALIZATION_TYPE,CANVAS_LOCALIZATION_SLOT,CANVAS_LOCALE_TAG_PARAM}from"../utils/constants";function extractLocales(o){var o=o.component,n={},o=null===(o=o.slots)||void 0===o?void 0:o[CANVAS_LOCALIZATION_SLOT];return null!=o&&o.forEach(function(o){var e=null===(e=o.parameters)||void 0===e?void 0:e[CANVAS_LOCALE_TAG_PARAM];null!=e&&e.value&&"string"==typeof e.value&&(n[e.value]=o)}),n}function localize(o){var e=o.composition,A=o.locale;walkComponentTree(e,function(o,e,n){var t,l;o.type===CANVAS_LOCALIZATION_TYPE&&(t=extractLocales({component:o}),l=void 0,(l=(o="string"==typeof A?A:A({component:o,locales:t}))?t[o]:l)?n.replaceComponent(l):n.removeComponent())})}export{extractLocales,localize};
@@ -1,14 +0,0 @@
1
- import { ComponentInstance } from '../types/componentInstances';
2
- export declare type ComponentLocationReference = {
3
- component: ComponentInstance;
4
- parentSlot?: string;
5
- parentSlotIndex?: number;
6
- };
7
- declare type WalkComponentTreeActions = {
8
- replaceComponent: (replacementComponent: ComponentInstance) => void;
9
- removeComponent: () => void;
10
- };
11
- /** Walks a composition's component tree, visiting each component instance depth-first, in order. */
12
- export declare function walkComponentTree(component: ComponentInstance, visitor: (component: ComponentInstance, ancestorsAndSelf: Array<ComponentLocationReference>, actions: WalkComponentTreeActions) => void): void;
13
- export declare function getComponentPath(ancestorsAndSelf: Array<ComponentLocationReference>): string;
14
- export {};
@@ -1 +0,0 @@
1
- var __read=this&&this.__read||function(n,e){var t="function"==typeof Symbol&&n[Symbol.iterator];if(!t)return n;var r,o,a=t.call(n),l=[];try{for(;(void 0===e||0<e--)&&!(r=a.next()).done;)l.push(r.value)}catch(n){o={error:n}}finally{try{r&&!r.done&&(t=a.return)&&t.call(a)}finally{if(o)throw o.error}}return l},__spreadArray=this&&this.__spreadArray||function(n,e,t){if(t||2===arguments.length)for(var r,o=0,a=e.length;o<a;o++)!r&&o in e||((r=r||Array.prototype.slice.call(e,0,o))[o]=e[o]);return n.concat(r||Array.prototype.slice.call(e))};function walkComponentTree(n,c){for(var s=[{ancestorsAndSelf:[{component:n,parentSlot:void 0,parentSlotIndex:void 0}]}];function(){var r=s.pop();if(!r)return;var t=r.ancestorsAndSelf[0];c(t.component,r.ancestorsAndSelf,{replaceComponent:function(e){Object.assign(t.component,e);["parameters","variant","slots","data","_pattern","_patternError"].forEach(function(n){e[n]||delete t.component[n]})},removeComponent:function(){var n=r.ancestorsAndSelf[0],e=n.parentSlot,t=n.parentSlotIndex,n=r.ancestorsAndSelf[1];if(!e||void 0===t)throw new Error("Unable to delete composition.");n.component.slots[e].splice(t,1)}});var n=t.component.slots;if(n)for(var e=Object.keys(n),o=e.length-1;0<=o;o--)for(var a=e[o],l=n[a],p=l.length-1;0<=p;p--)s.push({ancestorsAndSelf:__spreadArray([{component:l[p],parentSlot:a,parentSlotIndex:p}],__read(r.ancestorsAndSelf),!1)})}(),0<s.length;);}function getComponentPath(n){for(var e=[],t=n.length-1;0<=t;t--){var r=n[t],o=r.parentSlot,r=r.parentSlotIndex;o&&void 0!==r&&e.push(o+"["+r+"]")}return"."+e.join(".")}export{walkComponentTree,getComponentPath};
@@ -1,17 +0,0 @@
1
- export * from './types';
2
- export * from './enhancement/walkComponentTree';
3
- export * from './enhancement/UniqueBatchEntries';
4
- export * from './enhancement/EnhancerBuilder';
5
- export * from './enhancement/batchEnhancer';
6
- export * from './enhancement/enhance';
7
- export * from './enhancement/compose';
8
- export * from './enhancement/createLimitPolicy';
9
- export * from './CanvasClient';
10
- export * from './utils/constants';
11
- export * from './utils/isSystemComponentDefinition';
12
- export * from './utils/mapSlotToPersonalizedVariations';
13
- export * from './preview/createEventBus';
14
- export * from './preview/getChannelName';
15
- export * from './preview/subscribeToComposition';
16
- export * from './preview/EventNames';
17
- export * from './enhancement/localize';
package/dist/esm/index.js DELETED
@@ -1 +0,0 @@
1
- export*from"./types";export*from"./enhancement/walkComponentTree";export*from"./enhancement/UniqueBatchEntries";export*from"./enhancement/EnhancerBuilder";export*from"./enhancement/batchEnhancer";export*from"./enhancement/enhance";export*from"./enhancement/compose";export*from"./enhancement/createLimitPolicy";export*from"./CanvasClient";export*from"./utils/constants";export*from"./utils/isSystemComponentDefinition";export*from"./utils/mapSlotToPersonalizedVariations";export*from"./preview/createEventBus";export*from"./preview/getChannelName";export*from"./preview/subscribeToComposition";export*from"./preview/EventNames";export*from"./enhancement/localize";
@@ -1 +0,0 @@
1
- export declare type EventNames = 'updated';
File without changes
@@ -1,6 +0,0 @@
1
- import Pusher from 'pusher-js';
2
- export declare type PreviewEventBus = {
3
- client: Pusher;
4
- };
5
- /** Creates an event bus client to receive updates from Canvas */
6
- export declare function createEventBus(): PreviewEventBus;
@@ -1 +0,0 @@
1
- import Pusher from"pusher-js";function createEventBus(){return{client:new Pusher("7b5f5abd160fea549ffe",{cluster:"mt1"})}}export{createEventBus};
@@ -1 +0,0 @@
1
- export declare function getChannelName(projectId: string, compositionId: string, state: number): string;
@@ -1 +0,0 @@
1
- function getChannelName(e,n,t){return e+"."+n+"@"+t}export{getChannelName};
@@ -1,13 +0,0 @@
1
- import { PreviewEventBus } from './createEventBus';
2
- import { EventNames } from './EventNames';
3
- export declare type SubscribeToCompositionOptions = {
4
- projectId: string;
5
- compositionId: string;
6
- compositionState: number;
7
- callback: (data: any) => void;
8
- eventBus: PreviewEventBus;
9
- event: EventNames;
10
- };
11
- export declare type UnsubscribeCallback = () => void;
12
- /** Subscribes to a composition event */
13
- export declare function subscribeToComposition({ projectId, compositionId, compositionState, eventBus: { client }, callback, event, }: SubscribeToCompositionOptions): UnsubscribeCallback;
@@ -1 +0,0 @@
1
- import{getChannelName}from"./getChannelName";function subscribeToComposition(o){var e=o.projectId,n=o.compositionId,i=o.compositionState,t=void 0===i?0:i,s=o.eventBus.client,i=o.callback,o=o.event,c=void 0===o?"updated":o,t=getChannelName(e,n,t),a=s.subscribe(t);return console.log("[canvas] subscribed to "+c+" on "+t),a.bind(c,i),function(){a.unbind(),s.unsubscribe(c)}}export{subscribeToComposition};
@@ -1,90 +0,0 @@
1
- /** Shape of the GET response from /api/v1/canvas-definitions */
2
- export declare type ComponentDefinitionAPIResponse = {
3
- componentDefinitions: Array<ComponentDefinition>;
4
- };
5
- /** Shape of the PUT request body for /api/v1/canvas-definitions */
6
- export declare type ComponentDefinitionAPIPutRequest = {
7
- componentDefinition: CreatingComponentDefinition;
8
- projectId: string;
9
- };
10
- /** Shape of the DELETE request body for /api/v1/canvas-definitions */
11
- export declare type ComponentDefinitionAPIDeleteRequest = {
12
- /** Public ID of the component definition to delete */
13
- componentId: string;
14
- /** Project ID that the component definition lives on */
15
- projectId: string;
16
- };
17
- /** Query parameter options for GET /api/v1/canvas-definitions */
18
- export declare type ComponentDefinitionListAPIOptions = {
19
- /** Limit list to one result by ID (response remains an array) */
20
- componentId?: string;
21
- /** Number of records to skip */
22
- offset?: number;
23
- /** Max number of records to return (defaults to 100) */
24
- limit?: number;
25
- projectId: string;
26
- };
27
- /** The definition of a component parameter */
28
- export declare type ComponentDefinitionParameter<TConfig = unknown> = {
29
- /** Public ID of the parameter (used in code). Do not change after creation. */
30
- id: string;
31
- /** Friendly name of the parameter */
32
- name: string;
33
- /** Type name of the parameter (provided by a Uniform integration) */
34
- type: string;
35
- /** The configuration object for the type (type-specific) */
36
- typeConfig?: TConfig;
37
- };
38
- /** The definition of a component variant */
39
- export declare type ComponentDefinitionVariant = {
40
- /** Public ID of the variant (used in code). Do not change after creation. */
41
- id: string;
42
- /** Friendly name of the variant */
43
- name: string;
44
- };
45
- /** The definition of a named component slot that can contain other components */
46
- export declare type ComponentDefinitionSlot = {
47
- /** Public ID of the slot (used in code). Do not change after creation. */
48
- id: string;
49
- /** Friendly name of the slot */
50
- name: string;
51
- /** Whether this slot inherits its allowed components from the parent slot it lives in. If true, allowedComponents is irrelevant. */
52
- inheritAllowedComponents: boolean;
53
- /** A list of component definition public IDs that are allowed in this named slot */
54
- allowedComponents: Array<string>;
55
- /** Minimum valid number of components in this slot */
56
- minComponents?: number;
57
- /** Maximum valid number of components in this slot */
58
- maxComponents?: number;
59
- };
60
- /** Defines a component type that can live on a Composition */
61
- export declare type ComponentDefinition = {
62
- /** Public ID of the component (used in code). Do not change after creation. */
63
- id: string;
64
- /** Friendly name of the component definition */
65
- name: string;
66
- /** Icon name for the component definition (e.g. 'screen') */
67
- icon: string;
68
- /**
69
- * The public ID of the parameter whose value should be used to create a display title for this component in the UI.
70
- * The parameter type must support being used as a title parameter for this to work.
71
- */
72
- titleParameter?: string | null;
73
- /** Whether this component type can be the root of a composition. If false, this component is only used within slots on other components. */
74
- canBeComposition?: boolean;
75
- /** The parameters for this component. Parameters are key-value pairs that can be anything from text values to links to CMS entries. */
76
- parameters?: Array<ComponentDefinitionParameter>;
77
- /** The named slots for this component; placement areas where arrays of other components can be added. */
78
- slots?: Array<ComponentDefinitionSlot>;
79
- /** Named variants for this component; enables creation of visual variants that use the same parameter data/ */
80
- variants?: Array<ComponentDefinitionVariant>;
81
- /** Created date string for this definition */
82
- created?: string;
83
- /** Modified date string for this definition */
84
- modified?: string;
85
- };
86
- /** Defines a component type that can live on a Composition, when it is being created or updated */
87
- export declare type CreatingComponentDefinition = Omit<Partial<ComponentDefinition>, 'created' | 'modified' | 'id' | 'name'> & {
88
- id: string;
89
- name: string;
90
- };
File without changes
@@ -1,104 +0,0 @@
1
- /** @deprecated use CANVAS_DRAFT_STATE and CANVAS_PUBLISHED_STATE instead */
2
- export declare type CompositionFetchState = 'preview' | 'published' | number;
3
- /** The GET response from /api/v1/canvas when `component` or `slug` params are specified */
4
- export declare type CompositionAPIResponse = {
5
- /** The state of the layout. See CANVAS_DRAFT_STATE and CANVAS_PUBLISHED_STATE. */
6
- state: number;
7
- /** The project ID that this layout data is part of */
8
- projectId: string;
9
- /** Layout data being read or written */
10
- composition: RootComponentInstance;
11
- /** Whether this composition is a pattern (can be referenced by other compositions) */
12
- pattern: boolean;
13
- /** Created date string for this definition */
14
- created?: string;
15
- /** Modified date string for this definition */
16
- modified?: string;
17
- };
18
- /** Shape of the PUT request body for /api/v1/canvas */
19
- export declare type CompositionAPIPutRequest = Omit<CompositionAPIResponse, 'projectId'> & {
20
- projectId: string;
21
- };
22
- /** Shape of the DELETE request body for /api/v1/canvas */
23
- export declare type CompositionAPIDeleteRequest = {
24
- /** Public ID of the composition to delete */
25
- compositionId: string;
26
- /** Project ID that the composition lives on. */
27
- projectId: string;
28
- /** The state to delete. If unspecified, all states will be deleted. See CANVAS_DRAFT_STATE and CANVAS_PUBLISHED_STATE. */
29
- state?: number;
30
- };
31
- /** The GET response from /api/v1/canvas when `component` or `slug` are not specified */
32
- export declare type CompositionListAPIResponse = {
33
- compositions: Array<CompositionAPIResponse>;
34
- };
35
- /** Query parameter options for GET /api/v1/canvas */
36
- export declare type CompositionAPIOptions = {
37
- /** Specify a single composition ID to fetch. Changes response from list to single. */
38
- compositionId?: string;
39
- /** Specify a single composition to fetch by slug. Changes response from list to single. */
40
- slug?: string;
41
- /** The project the composition(s) are on. */
42
- projectId: string;
43
- /** The component type to filter by */
44
- type?: string;
45
- /** Number of records to skip */
46
- offset?: number;
47
- /** Max number of records to return (defaults to 100) */
48
- limit?: number;
49
- /** State of compositions to fetch. Default = 'published' */
50
- state?: number;
51
- /**
52
- * Signals a Canvas enhancer proxy to skip processing enhancements to the data and return raw data only.
53
- * This improves performance if you do not require enhanced component data.
54
- * If calling the Canvas API directly with no enhancer proxy, this has no effect.
55
- */
56
- skipEnhance?: boolean;
57
- /**
58
- * If true, any pattern references in the composition will be left unresolved.
59
- * This is appropriate if you intend to serialize the composition data without pattern
60
- * data embedded into it, and serialize the pattern data separately.
61
- */
62
- skipPatternResolution?: boolean;
63
- };
64
- export declare type ComponentParameter<TValue = unknown> = {
65
- /** The type of the parameter. Determines how it is displayed when editing, and tells the consumer how to process it. */
66
- type: string;
67
- /**
68
- * The value of the parameter.
69
- * Any JSON-serializable value is acceptable.
70
- */
71
- value: TValue;
72
- };
73
- /**
74
- * Defines the shape of a component instance served by the composition API.
75
- */
76
- export declare type ComponentInstance = {
77
- /** Type of the component instance (public_id of its definition) */
78
- type: string;
79
- /** Component parameter values for the component instance */
80
- parameters?: Record<string, ComponentParameter>;
81
- /** Public ID of alternate visual appearance for this component, if any selected */
82
- variant?: string;
83
- /** Slots containing any sub-components */
84
- slots?: Record<string, ComponentInstance[]>;
85
- /** Data for the component instance, provided by a component enhancer. Never set in unenhanced data. */
86
- data?: Record<string, unknown>;
87
- /** Indicates this component instance should be sourced from a pattern library pattern */
88
- _pattern?: string;
89
- /**
90
- * If an error occurs resolving a pattern reference, it is left unresolved and this property is set to indicate why.
91
- * CYCLIC: A cyclic pattern graph was detected, which could not be resolved because it would cause an infinite loop.
92
- * NOTFOUND: The pattern ID referenced could not be found. It may have been deleted, or not be published yet.
93
- */
94
- _patternError?: 'CYCLIC' | 'NOTFOUND';
95
- };
96
- /** Defines the shape of the root component in a composition */
97
- export declare type RootComponentInstance = ComponentInstance & {
98
- /** The public UUID of the composition. */
99
- _id?: string;
100
- /** Slug pattern of this component. */
101
- _slug?: string | null;
102
- /** Friendly name of this component. */
103
- _name?: string;
104
- };
File without changes