@uniformdev/canvas 11.0.1-alpha.83 → 11.0.1-alpha.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/arraySyncEngineDataSource.d.ts +4 -3
- package/dist/cjs/cli/arraySyncEngineDataSource.js +1 -1
- package/dist/cjs/cli/commands/component/_util.d.ts +3 -0
- package/dist/cjs/cli/commands/component/_util.js +1 -0
- package/dist/cjs/cli/commands/component/pull.d.ts +2 -2
- package/dist/cjs/cli/commands/component/pull.js +1 -1
- package/dist/cjs/cli/commands/component/push.d.ts +2 -2
- package/dist/cjs/cli/commands/component/push.js +1 -1
- package/dist/cjs/cli/commands/composition/_util.d.ts +3 -0
- package/dist/cjs/cli/commands/composition/_util.js +1 -0
- package/dist/cjs/cli/commands/composition/pull.d.ts +2 -2
- package/dist/cjs/cli/commands/composition/pull.js +1 -1
- package/dist/cjs/cli/commands/composition/push.d.ts +2 -2
- package/dist/cjs/cli/commands/composition/push.js +1 -1
- package/dist/cjs/cli/componentDefinitionEngineDataSource.js +1 -1
- package/dist/cjs/cli/componentInstanceEngineDataSource.js +1 -1
- package/dist/cjs/cli/fileSyncEngineDataSource.d.ts +4 -3
- package/dist/cjs/cli/fileSyncEngineDataSource.js +1 -1
- package/dist/cjs/cli/syncEngine.d.ts +5 -2
- package/dist/cjs/cli/syncEngine.js +1 -1
- package/dist/cjs/cli/syncEngineConsoleLogger.d.ts +4 -1
- package/dist/cjs/cli/syncEngineConsoleLogger.js +1 -1
- package/dist/cjs/cli/util.d.ts +7 -0
- package/dist/cjs/cli/util.js +1 -1
- package/dist/esm/cli/arraySyncEngineDataSource.d.ts +4 -3
- package/dist/esm/cli/arraySyncEngineDataSource.js +1 -1
- package/dist/esm/cli/commands/component/_util.d.ts +3 -0
- package/dist/esm/cli/commands/component/_util.js +1 -0
- package/dist/esm/cli/commands/component/pull.d.ts +2 -2
- package/dist/esm/cli/commands/component/pull.js +1 -1
- package/dist/esm/cli/commands/component/push.d.ts +2 -2
- package/dist/esm/cli/commands/component/push.js +1 -1
- package/dist/esm/cli/commands/composition/_util.d.ts +3 -0
- package/dist/esm/cli/commands/composition/_util.js +1 -0
- package/dist/esm/cli/commands/composition/pull.d.ts +2 -2
- package/dist/esm/cli/commands/composition/pull.js +1 -1
- package/dist/esm/cli/commands/composition/push.d.ts +2 -2
- package/dist/esm/cli/commands/composition/push.js +1 -1
- package/dist/esm/cli/componentDefinitionEngineDataSource.js +1 -1
- package/dist/esm/cli/componentInstanceEngineDataSource.js +1 -1
- package/dist/esm/cli/fileSyncEngineDataSource.d.ts +4 -3
- package/dist/esm/cli/fileSyncEngineDataSource.js +1 -1
- package/dist/esm/cli/syncEngine.d.ts +5 -2
- package/dist/esm/cli/syncEngine.js +1 -1
- package/dist/esm/cli/syncEngineConsoleLogger.d.ts +4 -1
- package/dist/esm/cli/syncEngineConsoleLogger.js +1 -1
- package/dist/esm/cli/util.d.ts +7 -0
- package/dist/esm/cli/util.js +1 -1
- package/package.json +11 -5
@@ -1,9 +1,10 @@
|
|
1
|
-
import { SyncEngineDataSource
|
1
|
+
import { SyncEngineDataSource } from './syncEngine';
|
2
2
|
export declare type CreateArraySyncEngineDataSourceOptions<TObject> = {
|
3
3
|
objects: Array<TObject>;
|
4
|
-
selectIdentifier: (object:
|
4
|
+
selectIdentifier: (object: TObject) => string;
|
5
|
+
selectDisplayName?: (object: TObject) => string;
|
5
6
|
onSyncComplete?: (isTarget: boolean, result: Array<TObject>) => Promise<void>;
|
6
7
|
};
|
7
|
-
export declare function createArraySyncEngineDataSource<TObject>({ objects, selectIdentifier, onSyncComplete, }: CreateArraySyncEngineDataSourceOptions<TObject>): Promise<SyncEngineDataSource<TObject> & {
|
8
|
+
export declare function createArraySyncEngineDataSource<TObject>({ objects, selectIdentifier, selectDisplayName, onSyncComplete, }: CreateArraySyncEngineDataSourceOptions<TObject>): Promise<SyncEngineDataSource<TObject> & {
|
8
9
|
extractCurrent: () => Array<TObject>;
|
9
10
|
}>;
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,i,u,c){return new(u=u||Promise)(function(n,t){function r(e){try{a(c.next(e))}catch(e){t(e)}}function o(e){try{a(c.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?n(e.value):((t=e.value)instanceof u?t:new u(function(e){e(t)})).then(r,o)}a((c=c.apply(e,i||[])).next())})},__generator=this&&this.__generator||function(n,r){var o,a,i,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[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(;u;)try{if(o=1,a&&(i=2&t[0]?a.return:t[0]?a.throw||((i=a.return)&&i.call(a),0):a.next)&&!(i=i.call(a,t[1])).done)return i;switch(a=0,(t=i?[2&t[0],i.value]:t)[0]){case 0:case 1:i=t;break;case 4:return u.label++,{value:t[1],done:!1};case 5:u.label++,a=t[1],t=[0];continue;case 7:t=u.ops.pop(),u.trys.pop();continue;default:if(!(i=0<(i=u.trys).length&&i[i.length-1])&&(6===t[0]||2===t[0])){u=0;continue}if(3===t[0]&&(!i||t[1]>i[0]&&t[1]<i[3])){u.label=t[1];break}if(6===t[0]&&u.label<i[1]){u.label=i[1],i=t;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(t);break}i[2]&&u.ops.pop(),u.trys.pop();continue}t=r.call(n,u)}catch(e){t=[6,e],a=0}finally{o=i=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}},__await=this&&this.__await||function(e){return this instanceof __await?(this.v=e,this):new __await(e)},__asyncGenerator=this&&this.__asyncGenerator||function(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o=n.apply(e,t||[]),a=[],i={};return r("next"),r("throw"),r("return"),i[Symbol.asyncIterator]=function(){return this},i;function r(r){o[r]&&(i[r]=function(n){return new Promise(function(e,t){1<a.push([r,n,e,t])||u(r,n)})})}function u(e,t){try{(n=o[e](t)).value instanceof __await?Promise.resolve(n.value.v).then(c,s):l(a[0][2],n)}catch(e){l(a[0][3],e)}var n}function c(e){u("next",e)}function s(e){u("throw",e)}function l(e,t){e(t),a.shift(),a.length&&u(a[0][0],a[0][1])}},__values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return{value:(e=e&&r>=e.length?void 0:e)&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};function createArraySyncEngineDataSource(e){var n=e.objects,o=e.selectIdentifier,t=e.selectDisplayName,a=void 0===t?o:t,u=e.onSyncComplete;return __awaiter(this,void 0,void 0,function(){function t(){return Object.entries(i).sort(function(e,t){return e[0].localeCompare(t[0])}).map(function(e){return e[1].object})}var i,r=this;return __generator(this,function(e){return i=n.reduce(function(e,t){var n=o(t);if(e[n])throw new Error("Identifier "+n+" was not unique.");return e[n]={id:n,object:t,providerId:n,displayName:a(t)},e},{}),[2,{objects:function(){return __asyncGenerator(this,arguments,function(){var t,n,r,o,a;return __generator(this,function(e){switch(e.label){case 0:e.trys.push([0,6,7,8]),t=__values(Object.values(i)),n=t.next(),e.label=1;case 1:return n.done?[3,5]:(r=n.value,[4,__await(r)]);case 2:return[4,e.sent()];case 3:e.sent(),e.label=4;case 4:return n=t.next(),[3,1];case 5:return[3,8];case 6:return o=e.sent(),o={error:o},[3,8];case 7:try{n&&!n.done&&(a=t.return)&&a.call(t)}finally{if(o)throw o.error}return[7];case 8:return[2]}})})}(),deleteObject:function(t){return __awaiter(r,void 0,void 0,function(){return __generator(this,function(e){return delete i[t],[2]})})},writeObject:function(n){return __awaiter(r,void 0,void 0,function(){var t;return __generator(this,function(e){return t=o(n.object),i[t]=n,[2]})})},extractCurrent:t,onSyncComplete:u?function(e){return u(e,t())}:void 0}]})})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.createArraySyncEngineDataSource=void 0,exports.createArraySyncEngineDataSource=createArraySyncEngineDataSource;
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.selectDisplayName=exports.selectIdentifier=void 0;var selectIdentifier=function(e){return e.id};exports.selectIdentifier=selectIdentifier;var selectDisplayName=function(e){return e.name+" (pid: "+e.id+")"};exports.selectDisplayName=selectDisplayName;
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { CommandModule } from 'yargs';
|
2
|
-
import { ApiArgs, ProjectArgs } from '../../util';
|
2
|
+
import { ApiArgs, DiffArgs, ProjectArgs } from '../../util';
|
3
3
|
declare type PullComponentArgs = {
|
4
4
|
directory: string;
|
5
5
|
format: 'yaml' | 'json';
|
6
6
|
whatIf: boolean;
|
7
7
|
mode: 'mirror' | 'createOrUpdate' | 'create';
|
8
|
-
} & ApiArgs & ProjectArgs;
|
8
|
+
} & ApiArgs & ProjectArgs & DiffArgs;
|
9
9
|
export declare const ComponentPullModule: CommandModule<PullComponentArgs, PullComponentArgs>;
|
10
10
|
export {};
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,c,l){return new(c=c||Promise)(function(n,t){function i(e){try{a(l.next(e))}catch(e){t(e)}}function r(e){try{a(l.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?n(e.value):((t=e.value)instanceof c?t:new c(function(e){e(t)})).then(i,r)}a((l=l.apply(e,o||[])).next())})},__generator=this&&this.__generator||function(n,i){var r,a,o,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(r)throw new TypeError("Generator is already executing.");for(;c;)try{if(r=1,a&&(o=2&t[0]?a.return:t[0]?a.throw||((o=a.return)&&o.call(a),0):a.next)&&!(o=o.call(a,t[1])).done)return o;switch(a=0,(t=o?[2&t[0],o.value]:t)[0]){case 0:case 1:o=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,a=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!(o=0<(o=c.trys).length&&o[o.length-1])&&(6===t[0]||2===t[0])){c=0;continue}if(3===t[0]&&(!o||t[1]>o[0]&&t[1]<o[3])){c.label=t[1];break}if(6===t[0]&&c.label<o[1]){c.label=o[1],o=t;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(t);break}o[2]&&c.ops.pop(),c.trys.pop();continue}t=i.call(n,c)}catch(e){t=[6,e],a=0}finally{r=o=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ComponentPullModule=void 0;var CanvasClient_1=require("../../../CanvasClient"),util_1=require("../../util"),isomorphic_unfetch_1=__importDefault(require("isomorphic-unfetch")),syncEngine_1=require("../../syncEngine"),fileSyncEngineDataSource_1=require("../../fileSyncEngineDataSource"),componentDefinitionEngineDataSource_1=require("../../componentDefinitionEngineDataSource"),syncEngineConsoleLogger_1=require("../../syncEngineConsoleLogger"),package_1=require("../../package"),arraySyncEngineDataSource_1=require("../../arraySyncEngineDataSource"),_util_1=require("./_util");exports.ComponentPullModule={command:"pull <directory>",describe:"Pulls all component definitions to local files in a directory",builder:function(e){return(0,util_1.withApiOptions)((0,util_1.withProjectOptions)((0,util_1.withDiffOptions)(e.positional("directory",{describe:"Directory to save the component definitions to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"}))))},handler:function(e){var a=e.apiHost,o=e.apiKey,c=e.directory,l=e.format,u=e.mode,s=e.whatIf,f=e.project,p=e.diff;return __awaiter(void 0,void 0,void 0,function(){var t,n,i,r;return __generator(this,function(e){switch(e.label){case 0:return(r=new CanvasClient_1.CanvasClient({apiKey:o,apiHost:a,fetch:isomorphic_unfetch_1.default,projectId:f,limitPolicy:util_1.limitPolicy}),t=(0,componentDefinitionEngineDataSource_1.createComponentDefinitionEngineDataSource)({client:r}),(0,util_1.isPathAPackageFile)(c))?(i=(0,package_1.readCanvasPackage)(c,!1),[4,(0,arraySyncEngineDataSource_1.createArraySyncEngineDataSource)({objects:null!==(r=i.components)&&void 0!==r?r:[],selectIdentifier:_util_1.selectIdentifier,selectDisplayName:_util_1.selectDisplayName,onSyncComplete:function(e,t){return __awaiter(void 0,void 0,void 0,function(){return __generator(this,function(e){return i.components=t,(0,package_1.writeCanvasPackage)(c,i),[2]})})}})]):[3,2];case 1:return n=e.sent(),[3,4];case 2:return[4,(0,fileSyncEngineDataSource_1.createFileSyncEngineDataSource)({directory:c,selectIdentifier:_util_1.selectIdentifier,selectDisplayName:_util_1.selectDisplayName,format:l})];case 3:n=e.sent(),e.label=4;case 4:return[4,(0,syncEngine_1.syncEngine)({source:t,target:n,mode:u,whatIf:s,log:(0,syncEngineConsoleLogger_1.createSyncEngineConsoleLogger)({diffMode:p})})];case 5:return e.sent(),[2]}})})}};
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { CommandModule } from 'yargs';
|
2
|
-
import { ApiArgs, ProjectArgs } from '../../util';
|
2
|
+
import { ApiArgs, DiffArgs, ProjectArgs } from '../../util';
|
3
3
|
declare type PushComponentArgs = {
|
4
4
|
directory: string;
|
5
5
|
whatIf: boolean;
|
6
6
|
mode: 'mirror' | 'createOrUpdate' | 'create';
|
7
|
-
} & ApiArgs & ProjectArgs;
|
7
|
+
} & ApiArgs & ProjectArgs & DiffArgs;
|
8
8
|
export declare const ComponentPushModule: CommandModule<PushComponentArgs, PushComponentArgs>;
|
9
9
|
export {};
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,c,u){return new(c=c||Promise)(function(n,t){function i(e){try{a(u.next(e))}catch(e){t(e)}}function r(e){try{a(u.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?n(e.value):((t=e.value)instanceof c?t:new c(function(e){e(t)})).then(i,r)}a((u=u.apply(e,o||[])).next())})},__generator=this&&this.__generator||function(n,i){var r,a,o,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(r)throw new TypeError("Generator is already executing.");for(;c;)try{if(r=1,a&&(o=2&t[0]?a.return:t[0]?a.throw||((o=a.return)&&o.call(a),0):a.next)&&!(o=o.call(a,t[1])).done)return o;switch(a=0,(t=o?[2&t[0],o.value]:t)[0]){case 0:case 1:o=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,a=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!(o=0<(o=c.trys).length&&o[o.length-1])&&(6===t[0]||2===t[0])){c=0;continue}if(3===t[0]&&(!o||t[1]>o[0]&&t[1]<o[3])){c.label=t[1];break}if(6===t[0]&&c.label<o[1]){c.label=o[1],o=t;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(t);break}o[2]&&c.ops.pop(),c.trys.pop();continue}t=i.call(n,c)}catch(e){t=[6,e],a=0}finally{r=o=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ComponentPushModule=void 0;var CanvasClient_1=require("../../../CanvasClient"),util_1=require("../../util"),isomorphic_unfetch_1=__importDefault(require("isomorphic-unfetch")),componentDefinitionEngineDataSource_1=require("../../componentDefinitionEngineDataSource"),syncEngine_1=require("../../syncEngine"),syncEngineConsoleLogger_1=require("../../syncEngineConsoleLogger"),fileSyncEngineDataSource_1=require("../../fileSyncEngineDataSource"),package_1=require("../../package"),arraySyncEngineDataSource_1=require("../../arraySyncEngineDataSource"),_util_1=require("./_util");exports.ComponentPushModule={command:"push <directory>",describe:"Pushes all component definitions from files in a directory to Uniform Optimize",builder:function(e){return(0,util_1.withApiOptions)((0,util_1.withProjectOptions)((0,util_1.withDiffOptions)(e.positional("directory",{describe:"Directory to read the component definitions from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"}))))},handler:function(e){var r=e.apiHost,a=e.apiKey,o=e.directory,c=e.mode,u=e.whatIf,l=e.project,s=e.diff;return __awaiter(void 0,void 0,void 0,function(){var t,n,i;return __generator(this,function(e){switch(e.label){case 0:return(t=new CanvasClient_1.CanvasClient({apiKey:a,apiHost:r,fetch:isomorphic_unfetch_1.default,projectId:l,limitPolicy:util_1.limitPolicy}),(0,util_1.isPathAPackageFile)(o))?(i=(0,package_1.readCanvasPackage)(o,!0),[4,(0,arraySyncEngineDataSource_1.createArraySyncEngineDataSource)({objects:null!==(i=i.components)&&void 0!==i?i:[],selectIdentifier:_util_1.selectIdentifier,selectDisplayName:_util_1.selectDisplayName})]):[3,2];case 1:return n=e.sent(),[3,4];case 2:return[4,(0,fileSyncEngineDataSource_1.createFileSyncEngineDataSource)({directory:o,selectIdentifier:_util_1.selectIdentifier,selectDisplayName:_util_1.selectDisplayName})];case 3:n=e.sent(),e.label=4;case 4:return i=(0,componentDefinitionEngineDataSource_1.createComponentDefinitionEngineDataSource)({client:t}),[4,(0,syncEngine_1.syncEngine)({source:n,target:i,mode:c,whatIf:u,log:(0,syncEngineConsoleLogger_1.createSyncEngineConsoleLogger)({diffMode:s})})];case 5:return e.sent(),[2]}})})}};
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.selectDisplayName=exports.selectIdentifier=void 0;var selectIdentifier=function(e){return e.composition._id};exports.selectIdentifier=selectIdentifier;var selectDisplayName=function(e){var i;return(null!==(i=null!==(i=e.composition._name)&&void 0!==i?i:e.composition._slug)&&void 0!==i?i:e.composition._id)+" (pid: "+e.composition._id+")"};exports.selectDisplayName=selectDisplayName;
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { CommandModule } from 'yargs';
|
2
|
-
import { ApiArgs, ProjectArgs, StateArgs } from '../../util';
|
2
|
+
import { ApiArgs, DiffArgs, ProjectArgs, StateArgs } from '../../util';
|
3
3
|
declare type PullCompositionArgs = {
|
4
4
|
directory: string;
|
5
5
|
format: 'yaml' | 'json';
|
6
6
|
whatIf: boolean;
|
7
7
|
mode: 'mirror' | 'createOrUpdate' | 'create';
|
8
|
-
} & ApiArgs & StateArgs & ProjectArgs;
|
8
|
+
} & ApiArgs & StateArgs & ProjectArgs & DiffArgs;
|
9
9
|
export declare const CompositionPullModule: CommandModule<PullCompositionArgs, PullCompositionArgs>;
|
10
10
|
export {};
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,c,l){return new(c=c||Promise)(function(n,t){function i(e){try{a(l.next(e))}catch(e){t(e)}}function r(e){try{a(l.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?n(e.value):((t=e.value)instanceof c?t:new c(function(e){e(t)})).then(i,r)}a((l=l.apply(e,o||[])).next())})},__generator=this&&this.__generator||function(n,i){var r,a,o,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(r)throw new TypeError("Generator is already executing.");for(;c;)try{if(r=1,a&&(o=2&t[0]?a.return:t[0]?a.throw||((o=a.return)&&o.call(a),0):a.next)&&!(o=o.call(a,t[1])).done)return o;switch(a=0,(t=o?[2&t[0],o.value]:t)[0]){case 0:case 1:o=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,a=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!(o=0<(o=c.trys).length&&o[o.length-1])&&(6===t[0]||2===t[0])){c=0;continue}if(3===t[0]&&(!o||t[1]>o[0]&&t[1]<o[3])){c.label=t[1];break}if(6===t[0]&&c.label<o[1]){c.label=o[1],o=t;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(t);break}o[2]&&c.ops.pop(),c.trys.pop();continue}t=i.call(n,c)}catch(e){t=[6,e],a=0}finally{r=o=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CompositionPullModule=void 0;var CanvasClient_1=require("../../../CanvasClient"),util_1=require("../../util"),isomorphic_unfetch_1=__importDefault(require("isomorphic-unfetch")),syncEngine_1=require("../../syncEngine"),fileSyncEngineDataSource_1=require("../../fileSyncEngineDataSource"),componentInstanceEngineDataSource_1=require("../../componentInstanceEngineDataSource"),syncEngineConsoleLogger_1=require("../../syncEngineConsoleLogger"),package_1=require("../../package"),arraySyncEngineDataSource_1=require("../../arraySyncEngineDataSource"),_util_1=require("./_util");exports.CompositionPullModule={command:"pull <directory>",describe:"Pulls all compositions to local files in a directory",builder:function(e){return(0,util_1.withApiOptions)((0,util_1.withProjectOptions)((0,util_1.withStateOptions)((0,util_1.withDiffOptions)(e.positional("directory",{describe:"Directory to save the component definitions to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))))},handler:function(e){var a=e.apiHost,o=e.apiKey,c=e.directory,l=e.format,s=e.mode,u=e.whatIf,f=e.state,p=e.project,d=e.diff;return __awaiter(void 0,void 0,void 0,function(){var t,n,i,r;return __generator(this,function(e){switch(e.label){case 0:return(r=new CanvasClient_1.CanvasClient({apiKey:o,apiHost:a,fetch:isomorphic_unfetch_1.default,projectId:p,limitPolicy:util_1.limitPolicy}),t=(0,componentInstanceEngineDataSource_1.createComponentInstanceEngineDataSource)({client:r,state:f}),(0,util_1.isPathAPackageFile)(c))?(i=(0,package_1.readCanvasPackage)(c,!1),[4,(0,arraySyncEngineDataSource_1.createArraySyncEngineDataSource)({objects:null!==(r=null==i?void 0:i.compositions)&&void 0!==r?r:[],selectIdentifier:_util_1.selectIdentifier,selectDisplayName:_util_1.selectDisplayName,onSyncComplete:function(e,t){return __awaiter(void 0,void 0,void 0,function(){return __generator(this,function(e){return i.compositions=t,(0,package_1.writeCanvasPackage)(c,i),[2]})})}})]):[3,2];case 1:return n=e.sent(),[3,4];case 2:return[4,(0,fileSyncEngineDataSource_1.createFileSyncEngineDataSource)({directory:c,selectIdentifier:_util_1.selectIdentifier,selectDisplayName:_util_1.selectDisplayName,format:l})];case 3:n=e.sent(),e.label=4;case 4:return[4,(0,syncEngine_1.syncEngine)({source:t,target:n,mode:s,whatIf:u,log:(0,syncEngineConsoleLogger_1.createSyncEngineConsoleLogger)({diffMode:d})})];case 5:return e.sent(),[2]}})})}};
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { CommandModule } from 'yargs';
|
2
|
-
import { ApiArgs, ProjectArgs, StateArgs } from '../../util';
|
2
|
+
import { ApiArgs, DiffArgs, ProjectArgs, StateArgs } from '../../util';
|
3
3
|
declare type PushCompositionArgs = {
|
4
4
|
directory: string;
|
5
5
|
whatIf: boolean;
|
6
6
|
mode: 'mirror' | 'createOrUpdate' | 'create';
|
7
|
-
} & ApiArgs & StateArgs & ProjectArgs;
|
7
|
+
} & ApiArgs & StateArgs & ProjectArgs & DiffArgs;
|
8
8
|
export declare const CompositionPushModule: CommandModule<PushCompositionArgs, PushCompositionArgs>;
|
9
9
|
export {};
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,c,s){return new(c=c||Promise)(function(n,t){function
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,c,s){return new(c=c||Promise)(function(n,t){function i(e){try{a(s.next(e))}catch(e){t(e)}}function r(e){try{a(s.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?n(e.value):((t=e.value)instanceof c?t:new c(function(e){e(t)})).then(i,r)}a((s=s.apply(e,o||[])).next())})},__generator=this&&this.__generator||function(n,i){var r,a,o,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(r)throw new TypeError("Generator is already executing.");for(;c;)try{if(r=1,a&&(o=2&t[0]?a.return:t[0]?a.throw||((o=a.return)&&o.call(a),0):a.next)&&!(o=o.call(a,t[1])).done)return o;switch(a=0,(t=o?[2&t[0],o.value]:t)[0]){case 0:case 1:o=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,a=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!(o=0<(o=c.trys).length&&o[o.length-1])&&(6===t[0]||2===t[0])){c=0;continue}if(3===t[0]&&(!o||t[1]>o[0]&&t[1]<o[3])){c.label=t[1];break}if(6===t[0]&&c.label<o[1]){c.label=o[1],o=t;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(t);break}o[2]&&c.ops.pop(),c.trys.pop();continue}t=i.call(n,c)}catch(e){t=[6,e],a=0}finally{r=o=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CompositionPushModule=void 0;var CanvasClient_1=require("../../../CanvasClient"),util_1=require("../../util"),isomorphic_unfetch_1=__importDefault(require("isomorphic-unfetch")),syncEngine_1=require("../../syncEngine"),syncEngineConsoleLogger_1=require("../../syncEngineConsoleLogger"),fileSyncEngineDataSource_1=require("../../fileSyncEngineDataSource"),componentInstanceEngineDataSource_1=require("../../componentInstanceEngineDataSource"),package_1=require("../../package"),arraySyncEngineDataSource_1=require("../../arraySyncEngineDataSource"),_util_1=require("./_util");exports.CompositionPushModule={command:"push <directory>",describe:"Pushes all compositions from files in a directory to Uniform Optimize",builder:function(e){return(0,util_1.withApiOptions)((0,util_1.withProjectOptions)((0,util_1.withStateOptions)((0,util_1.withDiffOptions)(e.positional("directory",{describe:"Directory to read the component definitions from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))))},handler:function(e){var r=e.apiHost,a=e.apiKey,o=e.directory,c=e.mode,s=e.whatIf,u=e.state,l=e.project,p=e.diff;return __awaiter(void 0,void 0,void 0,function(){var t,n,i;return __generator(this,function(e){switch(e.label){case 0:return(t=new CanvasClient_1.CanvasClient({apiKey:a,apiHost:r,fetch:isomorphic_unfetch_1.default,projectId:l,limitPolicy:util_1.limitPolicy}),(0,util_1.isPathAPackageFile)(o))?(i=(0,package_1.readCanvasPackage)(o,!0),[4,(0,arraySyncEngineDataSource_1.createArraySyncEngineDataSource)({objects:null!==(i=i.compositions)&&void 0!==i?i:[],selectIdentifier:_util_1.selectIdentifier,selectDisplayName:_util_1.selectDisplayName})]):[3,2];case 1:return n=e.sent(),[3,4];case 2:return[4,(0,fileSyncEngineDataSource_1.createFileSyncEngineDataSource)({directory:o,selectIdentifier:_util_1.selectIdentifier,selectDisplayName:_util_1.selectDisplayName})];case 3:n=e.sent(),e.label=4;case 4:return i=(0,componentInstanceEngineDataSource_1.createComponentInstanceEngineDataSource)({client:t,state:u}),[4,(0,syncEngine_1.syncEngine)({source:n,target:i,mode:c,whatIf:s,log:(0,syncEngineConsoleLogger_1.createSyncEngineConsoleLogger)({diffMode:p})})];case 5:return e.sent(),[2]}})})}};
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,a,c
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,a,u,c){return new(u=u||Promise)(function(n,t){function r(e){try{o(c.next(e))}catch(e){t(e)}}function i(e){try{o(c.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?n(e.value):((t=e.value)instanceof u?t:new u(function(e){e(t)})).then(r,i)}o((c=c.apply(e,a||[])).next())})},__generator=this&&this.__generator||function(n,r){var i,o,a,u={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(i)throw new TypeError("Generator is already executing.");for(;u;)try{if(i=1,o&&(a=2&t[0]?o.return:t[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,t[1])).done)return a;switch(o=0,(t=a?[2&t[0],a.value]:t)[0]){case 0:case 1:a=t;break;case 4:return u.label++,{value:t[1],done:!1};case 5:u.label++,o=t[1],t=[0];continue;case 7:t=u.ops.pop(),u.trys.pop();continue;default:if(!(a=0<(a=u.trys).length&&a[a.length-1])&&(6===t[0]||2===t[0])){u=0;continue}if(3===t[0]&&(!a||t[1]>a[0]&&t[1]<a[3])){u.label=t[1];break}if(6===t[0]&&u.label<a[1]){u.label=a[1],a=t;break}if(a&&u.label<a[2]){u.label=a[2],u.ops.push(t);break}a[2]&&u.ops.pop(),u.trys.pop();continue}t=r.call(n,u)}catch(e){t=[6,e],o=0}finally{i=a=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}},__asyncValues=this&&this.__asyncValues||function(a){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,t=a[Symbol.asyncIterator];return t?t.call(a):(a="function"==typeof __values?__values(a):a[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(o){e[o]=a[o]&&function(i){return new Promise(function(e,t){var n,r;i=a[o](i),n=e,e=t,r=i.done,t=i.value,Promise.resolve(t).then(function(e){n({value:e,done:r})},e)})}}},__await=this&&this.__await||function(e){return this instanceof __await?(this.v=e,this):new __await(e)},__asyncGenerator=this&&this.__asyncGenerator||function(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=n.apply(e,t||[]),o=[],a={};return r("next"),r("throw"),r("return"),a[Symbol.asyncIterator]=function(){return this},a;function r(r){i[r]&&(a[r]=function(n){return new Promise(function(e,t){1<o.push([r,n,e,t])||u(r,n)})})}function u(e,t){try{(n=i[e](t)).value instanceof __await?Promise.resolve(n.value.v).then(c,s):l(o[0][2],n)}catch(e){l(o[0][3],e)}var n}function c(e){u("next",e)}function s(e){u("throw",e)}function l(e,t){e(t),o.shift(),o.length&&u(o[0][0],o[0][1])}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createComponentDefinitionEngineDataSource=void 0;var util_1=require("./util"),_util_1=require("./commands/component/_util");function createComponentDefinitionEngineDataSource(e){var n=this,c=e.client;return{objects:function(){return __asyncGenerator(this,arguments,function(){var t,n,r,i,o,a,u=this;return __generator(this,function(e){switch(e.label){case 0:t=(0,util_1.paginateAsync)(function(t,n){return __awaiter(u,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return[4,c.getComponentDefinitions({limit:n,offset:t})];case 1:return[2,e.sent().componentDefinitions]}})})},{pageSize:100}),e.label=1;case 1:e.trys.push([1,8,9,14]),n=__asyncValues(t),e.label=2;case 2:return[4,__await(n.next())];case 3:return(r=e.sent()).done?[3,7]:(i=r.value,i={id:(0,_util_1.selectIdentifier)(i),displayName:(0,_util_1.selectDisplayName)(i),providerId:i.id,object:i},[4,__await(i)]);case 4:return[4,e.sent()];case 5:e.sent(),e.label=6;case 6:return[3,2];case 7:return[3,14];case 8:return o=e.sent(),o={error:o},[3,14];case 9:return e.trys.push([9,,12,13]),r&&!r.done&&(a=n.return)?[4,__await(a.call(n))]:[3,11];case 10:e.sent(),e.label=11;case 11:return[3,13];case 12:if(o)throw o.error;return[7];case 13:return[7];case 14:return[2]}})})}(),deleteObject:function(t){return __awaiter(n,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return[4,c.removeComponentDefinition({componentId:t})];case 1:return e.sent(),[2]}})})},writeObject:function(t){return __awaiter(n,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return[4,c.updateComponentDefinition({componentDefinition:t.object})];case 1:return e.sent(),[2]}})})}}}exports.createComponentDefinitionEngineDataSource=createComponentDefinitionEngineDataSource;
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";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)},__awaiter=this&&this.__awaiter||function(t,i,s,c){return new(s=s||Promise)(function(n,e){function r(t){try{a(c.next(t))}catch(t){e(t)}}function o(t){try{a(c.throw(t))}catch(t){e(t)}}function a(t){var e;t.done?n(t.value):((e=t.value)instanceof s?e:new s(function(t){t(e)})).then(r,o)}a((c=c.apply(t,i||[])).next())})},__generator=this&&this.__generator||function(n,r){var o,a,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[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,a&&(i=2&e[0]?a.return:e[0]?a.throw||((i=a.return)&&i.call(a),0):a.next)&&!(i=i.call(a,e[1])).done)return i;switch(a=0,(e=i?[2&e[0],i.value]:e)[0]){case 0:case 1:i=e;break;case 4:return s.label++,{value:e[1],done:!1};case 5:s.label++,a=e[1],e=[0];continue;case 7:e=s.ops.pop(),s.trys.pop();continue;default:if(!(i=0<(i=s.trys).length&&i[i.length-1])&&(6===e[0]||2===e[0])){s=0;continue}if(3===e[0]&&(!i||e[1]>i[0]&&e[1]<i[3])){s.label=e[1];break}if(6===e[0]&&s.label<i[1]){s.label=i[1],i=e;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(e);break}i[2]&&s.ops.pop(),s.trys.pop();continue}e=r.call(n,s)}catch(t){e=[6,t],a=0}finally{o=i=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}},__asyncValues=this&&this.__asyncValues||function(i){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,e=i[Symbol.asyncIterator];return e?e.call(i):(i="function"==typeof __values?__values(i):i[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(a){t[a]=i[a]&&function(o){return new Promise(function(t,e){var n,r;o=i[a](o),n=t,t=e,r=o.done,e=o.value,Promise.resolve(e).then(function(t){n({value:t,done:r})},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||[]),a=[],i={};return r("next"),r("throw"),r("return"),i[Symbol.asyncIterator]=function(){return this},i;function r(r){o[r]&&(i[r]=function(n){return new Promise(function(t,e){1<a.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(c,u):l(a[0][2],n)}catch(t){l(a[0][3],t)}var n}function c(t){s("next",t)}function u(t){s("throw",t)}function l(t,e){t(e),a.shift(),a.length&&s(a[0][0],a[0][1])}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createComponentInstanceEngineDataSource=void 0;var util_1=require("./util");function createComponentInstanceEngineDataSource(t){var n=this,
|
1
|
+
"use strict";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)},__awaiter=this&&this.__awaiter||function(t,i,s,c){return new(s=s||Promise)(function(n,e){function r(t){try{a(c.next(t))}catch(t){e(t)}}function o(t){try{a(c.throw(t))}catch(t){e(t)}}function a(t){var e;t.done?n(t.value):((e=t.value)instanceof s?e:new s(function(t){t(e)})).then(r,o)}a((c=c.apply(t,i||[])).next())})},__generator=this&&this.__generator||function(n,r){var o,a,i,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[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,a&&(i=2&e[0]?a.return:e[0]?a.throw||((i=a.return)&&i.call(a),0):a.next)&&!(i=i.call(a,e[1])).done)return i;switch(a=0,(e=i?[2&e[0],i.value]:e)[0]){case 0:case 1:i=e;break;case 4:return s.label++,{value:e[1],done:!1};case 5:s.label++,a=e[1],e=[0];continue;case 7:e=s.ops.pop(),s.trys.pop();continue;default:if(!(i=0<(i=s.trys).length&&i[i.length-1])&&(6===e[0]||2===e[0])){s=0;continue}if(3===e[0]&&(!i||e[1]>i[0]&&e[1]<i[3])){s.label=e[1];break}if(6===e[0]&&s.label<i[1]){s.label=i[1],i=e;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(e);break}i[2]&&s.ops.pop(),s.trys.pop();continue}e=r.call(n,s)}catch(t){e=[6,t],a=0}finally{o=i=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}},__asyncValues=this&&this.__asyncValues||function(i){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,e=i[Symbol.asyncIterator];return e?e.call(i):(i="function"==typeof __values?__values(i):i[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(a){t[a]=i[a]&&function(o){return new Promise(function(t,e){var n,r;o=i[a](o),n=t,t=e,r=o.done,e=o.value,Promise.resolve(e).then(function(t){n({value:t,done:r})},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||[]),a=[],i={};return r("next"),r("throw"),r("return"),i[Symbol.asyncIterator]=function(){return this},i;function r(r){o[r]&&(i[r]=function(n){return new Promise(function(t,e){1<a.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(c,u):l(a[0][2],n)}catch(t){l(a[0][3],t)}var n}function c(t){s("next",t)}function u(t){s("throw",t)}function l(t,e){t(e),a.shift(),a.length&&s(a[0][0],a[0][1])}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createComponentInstanceEngineDataSource=void 0;var util_1=require("./util"),_util_1=require("./commands/composition/_util");function createComponentInstanceEngineDataSource(t){var n=this,c=t.client,t=t.state,u=(0,util_1.convertCompositionState)(t);return{objects:function(){return __asyncGenerator(this,arguments,function(){var e,n,r,o,a,i,s=this;return __generator(this,function(t){switch(t.label){case 0:e=(0,util_1.paginateAsync)(function(e,n){return __awaiter(s,void 0,void 0,function(){return __generator(this,function(t){switch(t.label){case 0:return[4,c.getCompositionList({limit:n,offset:e,state:u})];case 1:return[2,t.sent().compositions]}})})},{pageSize:100}),t.label=1;case 1:t.trys.push([1,8,9,14]),n=__asyncValues(e),t.label=2;case 2:return[4,__await(n.next())];case 3:return(r=t.sent()).done?[3,7]:(o=r.value,o={id:(0,_util_1.selectIdentifier)(o),displayName:(0,_util_1.selectDisplayName)(o),providerId:o.composition._id,object:(0,util_1.prepCompositionForDisk)(o)},[4,__await(o)]);case 4:return[4,t.sent()];case 5:t.sent(),t.label=6;case 6:return[3,2];case 7:return[3,14];case 8:return a=t.sent(),a={error:a},[3,14];case 9:return t.trys.push([9,,12,13]),r&&!r.done&&(i=n.return)?[4,__await(i.call(n))]:[3,11];case 10:t.sent(),t.label=11;case 11:return[3,13];case 12:if(a)throw a.error;return[7];case 13:return[7];case 14:return[2]}})})}(),deleteObject:function(e){return __awaiter(n,void 0,void 0,function(){return __generator(this,function(t){switch(t.label){case 0:return[4,c.removeComposition({compositionId:e})];case 1:return t.sent(),[2]}})})},writeObject:function(e){return __awaiter(n,void 0,void 0,function(){return __generator(this,function(t){switch(t.label){case 0:return[4,c.updateComposition(__assign(__assign({},e.object),{state:u}))];case 1:return t.sent(),[2]}})})}}}exports.createComponentInstanceEngineDataSource=createComponentInstanceEngineDataSource;
|
@@ -1,8 +1,9 @@
|
|
1
|
-
import { SyncEngineDataSource
|
1
|
+
import { SyncEngineDataSource } from './syncEngine';
|
2
2
|
export declare type CreateFileSyncEngineDataSourceOptions<TObject> = {
|
3
3
|
directory: string;
|
4
|
-
selectIdentifier: (object:
|
4
|
+
selectIdentifier: (object: TObject) => string;
|
5
|
+
selectDisplayName?: (object: TObject) => string;
|
5
6
|
selectFilename?: (object: TObject) => string;
|
6
7
|
format?: 'json' | 'yaml';
|
7
8
|
};
|
8
|
-
export declare function createFileSyncEngineDataSource<TObject>({ directory, format, selectIdentifier, }: CreateFileSyncEngineDataSourceOptions<TObject>): Promise<SyncEngineDataSource<TObject>>;
|
9
|
+
export declare function createFileSyncEngineDataSource<TObject>({ directory, format, selectIdentifier, selectDisplayName, }: CreateFileSyncEngineDataSourceOptions<TObject>): Promise<SyncEngineDataSource<TObject>>;
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,u,
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,u,s){return new(u=u||Promise)(function(r,t){function n(e){try{a(s.next(e))}catch(e){t(e)}}function i(e){try{a(s.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?r(e.value):((t=e.value)instanceof u?t:new u(function(e){e(t)})).then(n,i)}a((s=s.apply(e,o||[])).next())})},__generator=this&&this.__generator||function(r,n){var i,a,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(i)throw new TypeError("Generator is already executing.");for(;u;)try{if(i=1,a&&(o=2&t[0]?a.return:t[0]?a.throw||((o=a.return)&&o.call(a),0):a.next)&&!(o=o.call(a,t[1])).done)return o;switch(a=0,(t=o?[2&t[0],o.value]:t)[0]){case 0:case 1:o=t;break;case 4:return u.label++,{value:t[1],done:!1};case 5:u.label++,a=t[1],t=[0];continue;case 7:t=u.ops.pop(),u.trys.pop();continue;default:if(!(o=0<(o=u.trys).length&&o[o.length-1])&&(6===t[0]||2===t[0])){u=0;continue}if(3===t[0]&&(!o||t[1]>o[0]&&t[1]<o[3])){u.label=t[1];break}if(6===t[0]&&u.label<o[1]){u.label=o[1],o=t;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(t);break}o[2]&&u.ops.pop(),u.trys.pop();continue}t=n.call(r,u)}catch(e){t=[6,e],a=0}finally{i=o=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}},__await=this&&this.__await||function(e){return this instanceof __await?(this.v=e,this):new __await(e)},__asyncGenerator=this&&this.__asyncGenerator||function(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=r.apply(e,t||[]),a=[],o={};return n("next"),n("throw"),n("return"),o[Symbol.asyncIterator]=function(){return this},o;function n(n){i[n]&&(o[n]=function(r){return new Promise(function(e,t){1<a.push([n,r,e,t])||u(n,r)})})}function u(e,t){try{(r=i[e](t)).value instanceof __await?Promise.resolve(r.value.v).then(s,c):l(a[0][2],r)}catch(e){l(a[0][3],e)}var r}function s(e){u("next",e)}function c(e){u("throw",e)}function l(e,t){e(t),a.shift(),a.length&&u(a[0][0],a[0][1])}},__values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.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(t?"Object is not iterable.":"Symbol.iterator is not defined.")},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFileSyncEngineDataSource=void 0;var chalk_1=__importDefault(require("chalk")),fs_1=require("fs"),promises_1=require("fs/promises"),path_1=require("path"),util_1=require("./util");function createFileSyncEngineDataSource(e){var s=e.directory,t=e.format,i=void 0===t?"yaml":t,c=e.selectIdentifier,e=e.selectDisplayName,l=void 0===e?c:e;return __awaiter(this,void 0,void 0,function(){var t,u,r,n=this;return __generator(this,function(e){switch(e.label){case 0:return(0,fs_1.existsSync)(s)||(0,fs_1.mkdirSync)(s,{recursive:!0}),[4,(0,promises_1.readdir)(s,"utf-8")];case 1:return t=e.sent(),u=new Set(t.filter(function(e){e=(0,path_1.extname)(e);return".json"===e||".yaml"===e||".yml"===e})),r=function(e){return(0,path_1.join)(s,e+"."+i)},[2,{objects:function(){return __asyncGenerator(this,arguments,function(){var t,r,n,i,a,o;return __generator(this,function(e){switch(e.label){case 0:e.trys.push([0,9,10,11]),t=__values(u),r=t.next(),e.label=1;case 1:if(r.done)return[3,8];n=r.value,n=(0,path_1.join)(s,n),e.label=2;case 2:return e.trys.push([2,6,,7]),[4,__await((0,util_1.readFileToObject)(n))];case 3:return i=e.sent(),i={id:c(i),displayName:l(i),providerId:n,object:i},[4,__await(i)];case 4:return[4,e.sent()];case 5:return e.sent(),[3,7];case 6:throw i=e.sent(),console.error(chalk_1.default.red("Failed to read "+n+", data is likely invalid.\n"+(null==i?void 0:i.message))),i;case 7:return r=t.next(),[3,1];case 8:return[3,11];case 9:return a=e.sent(),a={error:a},[3,11];case 10:try{r&&!r.done&&(o=t.return)&&o.call(t)}finally{if(a)throw a.error}return[7];case 11:return[2]}})})}(),deleteObject:function(t){return __awaiter(n,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return[4,(0,promises_1.unlink)(t)];case 1:return e.sent(),[2]}})})},writeObject:function(t){return __awaiter(n,void 0,void 0,function(){return __generator(this,function(e){return(0,util_1.emitWithFormat)(t.object,i,r(t.id)),[2]})})}}]}})})}exports.createFileSyncEngineDataSource=createFileSyncEngineDataSource;
|
@@ -1,11 +1,15 @@
|
|
1
|
+
import { Change } from 'diff';
|
1
2
|
export declare type SyncEngineLogOptions = {
|
2
3
|
id: string;
|
3
4
|
providerId: string;
|
4
5
|
displayName: string;
|
5
6
|
action: 'create' | 'update' | 'delete';
|
6
7
|
whatIf: boolean;
|
8
|
+
diff: Change[];
|
7
9
|
};
|
8
10
|
export declare type SyncEngineObject<TObject> = {
|
11
|
+
/** Unique ID that is identical across all providers */
|
12
|
+
id: string;
|
9
13
|
/** Provider specific ID. Value is provided to deleteObject() function (always the provider ID from the same provider that issued it). */
|
10
14
|
providerId: string;
|
11
15
|
/** Optional display name of the object for log messages. The providerId will be used if this is not set. */
|
@@ -34,7 +38,6 @@ export declare type SyncEngineDataSource<TObject> = {
|
|
34
38
|
export declare type SyncEngineOptions<TObject> = {
|
35
39
|
source: SyncEngineDataSource<TObject>;
|
36
40
|
target: SyncEngineDataSource<TObject>;
|
37
|
-
selectIdentifier: (object: SyncEngineObject<TObject>) => string;
|
38
41
|
compareContents?: (source: SyncEngineObject<TObject>, target: SyncEngineObject<TObject>) => boolean;
|
39
42
|
mode: 'mirror' | 'createOrUpdate' | 'create';
|
40
43
|
/** Compare sources, but do not execute actions */
|
@@ -43,4 +46,4 @@ export declare type SyncEngineOptions<TObject> = {
|
|
43
46
|
allowEmptySource?: boolean;
|
44
47
|
log?: (options: SyncEngineLogOptions) => void;
|
45
48
|
};
|
46
|
-
export declare function syncEngine<TObject>({ source, target,
|
49
|
+
export declare function syncEngine<TObject>({ source, target, compareContents, mode, allowEmptySource, whatIf, log, }: SyncEngineOptions<TObject>): Promise<void>;
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,s,u){return new(s=s||Promise)(function(t,r){function n(e){try{i(u.next(e))}catch(e){r(e)}}function a(e){try{i(u.throw(e))}catch(e){r(e)}}function i(e){var r;e.done?t(e.value):((r=e.value)instanceof s?r:new s(function(e){e(r)})).then(n,a)}i((u=u.apply(e,o||[])).next())})},__generator=this&&this.__generator||function(t,n){var a,i,o,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(;s;)try{if(a=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,(r=o?[2&r[0],o.value]:r)[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=0<(o=s.trys).length&&o[o.length-1])&&(6===r[0]||2===r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){s.label=r[1];break}if(6===r[0]&&s.label<o[1]){s.label=o[1],o=r;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(r);break}o[2]&&s.ops.pop(),s.trys.pop();continue}r=n.call(t,s)}catch(e){r=[6,e],i=0}finally{a=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,e])}}},__asyncValues=this&&this.__asyncValues||function(o){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,r=o[Symbol.asyncIterator];return r?r.call(o):(o="function"==typeof __values?__values(o):o[Symbol.iterator](),e={},t("next"),t("throw"),t("return"),e[Symbol.asyncIterator]=function(){return this},e);function t(i){e[i]=o[i]&&function(a){return new Promise(function(e,r){var t,n;a=o[i](a),t=e,e=r,n=a.done,r=a.value,Promise.resolve(r).then(function(e){t({value:e,done:n})},e)})}}},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.syncEngine=void 0;var diff_1=require("diff"),lodash_isequalwith_1=__importDefault(require("lodash.isequalwith"));function syncEngine(e){var v,_,p,y,b,w=e.source,m=e.target,r=e.compareContents,g=void 0===r?function(e,r){return(0,lodash_isequalwith_1.default)(e.object,r.object,function(e,r,t){return"created"===t||"updated"===t||void 0})}:r,I=e.mode,r=e.allowEmptySource,S=void 0!==r&&r,r=e.whatIf,j=void 0!==r&&r,e=e.log,x=void 0===e?function(){}:e;return __awaiter(this,void 0,void 0,function(){var r,t,n,a,i,o,s,u,c,l,d,f,h=this;return __generator(this,function(e){switch(e.label){case 0:r=new Map,e.label=1;case 1:e.trys.push([1,6,7,12]),t=__asyncValues(m.objects),e.label=2;case 2:return[4,t.next()];case 3:if((n=e.sent()).done)return[3,5];l=n.value,r.set(l.id,l),e.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return c=e.sent(),v={error:c},[3,12];case 7:return e.trys.push([7,,10,11]),n&&!n.done&&(_=t.return)?[4,_.call(t)]:[3,9];case 8:e.sent(),e.label=9;case 9:return[3,11];case 10:if(v)throw v.error;return[7];case 11:return[7];case 12:i=!(a=[]),e.label=13;case 13:e.trys.push([13,18,19,24]),o=__asyncValues(w.objects),e.label=14;case 14:return[4,o.next()];case 15:if((s=e.sent()).done)return[3,17];d=s.value,i=!0,u=d.id,(l=r.get(u))?(g(d,l)||"createOrUpdate"!==I&&"mirror"!==I||(c=function(t,n){return __awaiter(h,void 0,void 0,function(){var r;return __generator(this,function(e){switch(e.label){case 0:return j?[3,2]:[4,m.writeObject(t)];case 1:e.sent(),e.label=2;case 2:return x({action:"update",id:u,providerId:t.providerId,displayName:null!==(r=t.displayName)&&void 0!==r?r:t.providerId,whatIf:j,diff:(0,diff_1.diffJson)(n.object,t.object)}),[2]}})})},a.push(c(d,l))),r.delete(u)):(l=function(t,n){return __awaiter(h,void 0,void 0,function(){var r;return __generator(this,function(e){switch(e.label){case 0:return j?[3,2]:[4,m.writeObject(t)];case 1:e.sent(),e.label=2;case 2:return x({action:"create",id:n,providerId:n,displayName:null!==(r=t.displayName)&&void 0!==r?r:t.providerId,whatIf:j,diff:(0,diff_1.diffLines)("",JSON.stringify(t.object,null,2))}),[2]}})})},a.push(l(d,u))),e.label=16;case 16:return[3,14];case 17:return[3,24];case 18:return d=e.sent(),p={error:d},[3,24];case 19:return e.trys.push([19,,22,23]),s&&!s.done&&(y=o.return)?[4,y.call(o)]:[3,21];case 20:e.sent(),e.label=21;case 21:return[3,23];case 22:if(p)throw p.error;return[7];case 23:return[7];case 24:return[4,Promise.all(a)];case 25:if(e.sent(),"mirror"!==I)return[3,27];if(!i&&!S)throw new Error("Source is empty and mode is mirror. This would cause deletion of everything in the target, and most likely indicates an error in source definition.");return f=[],r.forEach(function(t){return __awaiter(h,void 0,void 0,function(){var r,n=this;return __generator(this,function(e){return r=function(t){return __awaiter(n,void 0,void 0,function(){var r;return __generator(this,function(e){switch(e.label){case 0:return j?[3,2]:[4,m.deleteObject(t.providerId)];case 1:e.sent(),e.label=2;case 2:return x({action:"delete",id:t.id,providerId:t.providerId,displayName:null!==(r=t.displayName)&&void 0!==r?r:t.providerId,whatIf:j,diff:(0,diff_1.diffLines)(JSON.stringify(t.object,null,2),"")}),[2]}})})},f.push(r(t)),[2]})})}),[4,Promise.all(f)];case 26:e.sent(),e.label=27;case 27:return[4,Promise.all([null===(b=w.onSyncComplete)||void 0===b?void 0:b.call(w,!1),null===(b=m.onSyncComplete)||void 0===b?void 0:b.call(m,!0)])];case 28:return e.sent(),[2]}})})}exports.syncEngine=syncEngine;
|
@@ -1,2 +1,5 @@
|
|
1
1
|
import { SyncEngineLogOptions } from './syncEngine';
|
2
|
-
export declare
|
2
|
+
export declare type DiffMode = 'off' | 'on' | 'update';
|
3
|
+
export declare function createSyncEngineConsoleLogger({ diffMode }: {
|
4
|
+
diffMode: DiffMode;
|
5
|
+
}): ({ action, displayName, whatIf, diff }: SyncEngineLogOptions) => void;
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createSyncEngineConsoleLogger=void 0;var chalk_1=__importDefault(require("chalk"));function createSyncEngineConsoleLogger(e){var l=e.diffMode;return function(e){var a=e.action,t=e.displayName,r=e.whatIf,n=e.diff,o="";switch(a){case"create":o=chalk_1.default.green("[A]");break;case"update":o=chalk_1.default.white("[U]");break;case"delete":o=chalk_1.default.yellow("[D]")}e="";("on"===l||"update"===l&&"update"===a)&&(e="\n"+n.map(function(e){return e.added?chalk_1.default.green(e.value):e.removed?chalk_1.default.red(e.value):e.value}).join("")),console.log(""+(r?chalk_1.default.gray("[WHATIF]"):"")+o+" "+t+e)}}exports.createSyncEngineConsoleLogger=createSyncEngineConsoleLogger;
|
package/dist/cjs/cli/util.d.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import { Argv } from 'yargs';
|
2
2
|
import { CompositionAPIResponse } from '../types/componentInstances';
|
3
|
+
import pLimit from 'p-limit';
|
4
|
+
import { DiffMode } from './syncEngineConsoleLogger';
|
3
5
|
export declare type ApiArgs = {
|
4
6
|
apiKey: string;
|
5
7
|
apiHost: string;
|
@@ -14,6 +16,10 @@ export declare type FormatArgs = {
|
|
14
16
|
filename?: string;
|
15
17
|
};
|
16
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>;
|
17
23
|
export declare function isPathAPackageFile(path: string): boolean;
|
18
24
|
export declare function emitWithFormat(object: any, format?: string, filename?: string): void;
|
19
25
|
export declare function readFileToObject<T = unknown>(filename: string): T;
|
@@ -33,3 +39,4 @@ export declare function paginateAsync<TResult>(fetchPage: (offset: number, limit
|
|
33
39
|
pageSize: number;
|
34
40
|
}): AsyncIterableIterator<TResult>;
|
35
41
|
export declare function convertCompositionState(state: CLICompositionState): number;
|
42
|
+
export declare const limitPolicy: pLimit.Limit;
|
package/dist/cjs/cli/util.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},__generator=this&&this.__generator||function(r,n){var o,i,s,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[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(;a;)try{if(o=1,i&&(s=2&e[0]?i.return:e[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,e[1])).done)return s;switch(i=0,(e=s?[2&e[0],s.value]:e)[0]){case 0:case 1:s=e;break;case 4:return a.label++,{value:e[1],done:!1};case 5:a.label++,i=e[1],e=[0];continue;case 7:e=a.ops.pop(),a.trys.pop();continue;default:if(!(s=0<(s=a.trys).length&&s[s.length-1])&&(6===e[0]||2===e[0])){a=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]<s[3])){a.label=e[1];break}if(6===e[0]&&a.label<s[1]){a.label=s[1],s=e;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(e);break}s[2]&&a.ops.pop(),a.trys.pop();continue}e=n.call(r,a)}catch(t){e=[6,t],i=0}finally{o=s=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,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o=r.apply(t,e||[]),i=[],s={};return n("next"),n("throw"),n("return"),s[Symbol.asyncIterator]=function(){return this},s;function n(n){o[n]&&(s[n]=function(r){return new Promise(function(t,e){1<i.push([n,r,t,e])||a(n,r)})})}function a(t,e){try{(r=o[t](e)).value instanceof __await?Promise.resolve(r.value.v).then(p,u):
|
1
|
+
"use strict";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},__generator=this&&this.__generator||function(r,n){var o,i,s,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[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(;a;)try{if(o=1,i&&(s=2&e[0]?i.return:e[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,e[1])).done)return s;switch(i=0,(e=s?[2&e[0],s.value]:e)[0]){case 0:case 1:s=e;break;case 4:return a.label++,{value:e[1],done:!1};case 5:a.label++,i=e[1],e=[0];continue;case 7:e=a.ops.pop(),a.trys.pop();continue;default:if(!(s=0<(s=a.trys).length&&s[s.length-1])&&(6===e[0]||2===e[0])){a=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]<s[3])){a.label=e[1];break}if(6===e[0]&&a.label<s[1]){a.label=s[1],s=e;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(e);break}s[2]&&a.ops.pop(),a.trys.pop();continue}e=n.call(r,a)}catch(t){e=[6,t],i=0}finally{o=s=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,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o=r.apply(t,e||[]),i=[],s={};return n("next"),n("throw"),n("return"),s[Symbol.asyncIterator]=function(){return this},s;function n(n){o[n]&&(s[n]=function(r){return new Promise(function(t,e){1<i.push([n,r,t,e])||a(n,r)})})}function a(t,e){try{(r=o[t](e)).value instanceof __await?Promise.resolve(r.value.v).then(p,u):l(i[0][2],r)}catch(t){l(i[0][3],t)}var r}function p(t){a("next",t)}function u(t){a("throw",t)}function l(t,e){t(e),i.shift(),i.length&&a(i[0][0],i[0][1])}},__values=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return{value:(t=t&&n>=t.length?void 0:t)&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},__importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.limitPolicy=exports.convertCompositionState=exports.paginateAsync=exports.withStateOptions=exports.prepCompositionForDisk=exports.readFileToObject=exports.emitWithFormat=exports.isPathAPackageFile=exports.withDiffOptions=exports.withFormatOptions=exports.withProjectOptions=exports.withApiOptions=void 0;var js_yaml_1=require("js-yaml"),fs_1=require("fs"),path_1=require("path"),fs_2=require("fs"),constants_1=require("../utils/constants"),p_limit_1=__importDefault(require("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=(0,path_1.extname)(t);return".yaml"===t||".yml"===t||".json"===t}function emitWithFormat(t,e,r){var n;if(r&&!e){var o=(0,path_1.extname)(r);".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":n=JSON.stringify(t,null,2);break;case"yaml":n=(0,js_yaml_1.dump)(t);break;default:throw new Error("Unsupported format: "+e)}r?(0,fs_1.writeFileSync)(r,n,"utf8"):console.log(n)}function readFileToObject(t){var e=(0,fs_2.readFileSync)(t,"utf8");return(0,js_yaml_1.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(u,l){return __asyncGenerator(this,arguments,function(){var e,r,n,o,i,s,a,p;return __generator(this,function(t){switch(t.label){case 0:e=l.pageSize||100,r=0,n=[],t.label=1;case 1:return[4,__await(u(r,e))];case 2:n=t.sent(),t.label=3;case 3:t.trys.push([3,9,10,11]),a=void 0,o=__values(n),i=o.next(),t.label=4;case 4:return i.done?[3,8]:(s=i.value,[4,__await(s)]);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 s=t.sent(),a={error:s},[3,11];case 10:try{i&&!i.done&&(p=o.return)&&p.call(o)}finally{if(a)throw a.error}return[7];case 11:r+=e,t.label=12;case 12:if(n.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 constants_1.CANVAS_PUBLISHED_STATE;if("string"!=typeof t)throw new Error('state must be "published", "preview", or a number');return"preview"===t?constants_1.CANVAS_DRAFT_STATE:constants_1.CANVAS_PUBLISHED_STATE}exports.withApiOptions=withApiOptions,exports.withProjectOptions=withProjectOptions,exports.withFormatOptions=withFormatOptions,exports.withDiffOptions=withDiffOptions,exports.isPathAPackageFile=isPathAPackageFile,exports.emitWithFormat=emitWithFormat,exports.readFileToObject=readFileToObject,exports.prepCompositionForDisk=prepCompositionForDisk,exports.withStateOptions=withStateOptions,exports.paginateAsync=paginateAsync,exports.convertCompositionState=convertCompositionState,exports.limitPolicy=(0,p_limit_1.default)(8);
|
@@ -1,9 +1,10 @@
|
|
1
|
-
import { SyncEngineDataSource
|
1
|
+
import { SyncEngineDataSource } from './syncEngine';
|
2
2
|
export declare type CreateArraySyncEngineDataSourceOptions<TObject> = {
|
3
3
|
objects: Array<TObject>;
|
4
|
-
selectIdentifier: (object:
|
4
|
+
selectIdentifier: (object: TObject) => string;
|
5
|
+
selectDisplayName?: (object: TObject) => string;
|
5
6
|
onSyncComplete?: (isTarget: boolean, result: Array<TObject>) => Promise<void>;
|
6
7
|
};
|
7
|
-
export declare function createArraySyncEngineDataSource<TObject>({ objects, selectIdentifier, onSyncComplete, }: CreateArraySyncEngineDataSourceOptions<TObject>): Promise<SyncEngineDataSource<TObject> & {
|
8
|
+
export declare function createArraySyncEngineDataSource<TObject>({ objects, selectIdentifier, selectDisplayName, onSyncComplete, }: CreateArraySyncEngineDataSourceOptions<TObject>): Promise<SyncEngineDataSource<TObject> & {
|
8
9
|
extractCurrent: () => Array<TObject>;
|
9
10
|
}>;
|
@@ -1 +1 @@
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(t,a,u,c){return new(u=u||Promise)(function(n,e){function r(t){try{i(c.next(t))}catch(t){e(t)}}function o(t){try{i(c.throw(t))}catch(t){e(t)}}function i(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(r,o)}i((c=c.apply(t,a||[])).next())})},__generator=this&&this.__generator||function(n,r){var o,i,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(o)throw new TypeError("Generator is already executing.");for(;u;)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 u.label++,{value:e[1],done:!1};case 5:u.label++,i=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=r.call(n,u)}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])||u(r,n)})})}function u(t,e){try{(n=o[t](e)).value instanceof __await?Promise.resolve(n.value.v).then(c,s):l(i[0][2],n)}catch(t){l(i[0][3],t)}var n}function c(t){u("next",t)}function s(t){u("throw",t)}function l(t,e){t(e),i.shift(),i.length&&u(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.")};function createArraySyncEngineDataSource(t){var n=t.objects,o=t.selectIdentifier,i=t.onSyncComplete;return __awaiter(this,void 0,void 0,function(){function e(){return Object.entries(a).sort(function(t,e){return t[0].localeCompare(e[0])}).map(function(t){return t[1].object})}var a,r=this;return __generator(this,function(t){return a=n.reduce(function(t,e
|
1
|
+
var __awaiter=this&&this.__awaiter||function(t,a,u,c){return new(u=u||Promise)(function(n,e){function r(t){try{i(c.next(t))}catch(t){e(t)}}function o(t){try{i(c.throw(t))}catch(t){e(t)}}function i(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(r,o)}i((c=c.apply(t,a||[])).next())})},__generator=this&&this.__generator||function(n,r){var o,i,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(o)throw new TypeError("Generator is already executing.");for(;u;)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 u.label++,{value:e[1],done:!1};case 5:u.label++,i=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=r.call(n,u)}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])||u(r,n)})})}function u(t,e){try{(n=o[t](e)).value instanceof __await?Promise.resolve(n.value.v).then(c,s):l(i[0][2],n)}catch(t){l(i[0][3],t)}var n}function c(t){u("next",t)}function s(t){u("throw",t)}function l(t,e){t(e),i.shift(),i.length&&u(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.")};function createArraySyncEngineDataSource(t){var n=t.objects,o=t.selectIdentifier,e=t.selectDisplayName,i=void 0===e?o:e,u=t.onSyncComplete;return __awaiter(this,void 0,void 0,function(){function e(){return Object.entries(a).sort(function(t,e){return t[0].localeCompare(e[0])}).map(function(t){return t[1].object})}var a,r=this;return __generator(this,function(t){return a=n.reduce(function(t,e){var n=o(e);if(t[n])throw new Error("Identifier "+n+" was not unique.");return t[n]={id:n,object:e,providerId:n,displayName:i(e)},t},{}),[2,{objects:function(){return __asyncGenerator(this,arguments,function(){var e,n,r,o,i;return __generator(this,function(t){switch(t.label){case 0:t.trys.push([0,6,7,8]),e=__values(Object.values(a)),n=e.next(),t.label=1;case 1:return n.done?[3,5]:(r=n.value,[4,__await(r)]);case 2:return[4,t.sent()];case 3:t.sent(),t.label=4;case 4:return n=e.next(),[3,1];case 5:return[3,8];case 6:return o=t.sent(),o={error:o},[3,8];case 7:try{n&&!n.done&&(i=e.return)&&i.call(e)}finally{if(o)throw o.error}return[7];case 8:return[2]}})})}(),deleteObject:function(e){return __awaiter(r,void 0,void 0,function(){return __generator(this,function(t){return delete a[e],[2]})})},writeObject:function(n){return __awaiter(r,void 0,void 0,function(){var e;return __generator(this,function(t){return e=o(n.object),a[e]=n,[2]})})},extractCurrent:e,onSyncComplete:u?function(t){return u(t,e())}:void 0}]})})}export{createArraySyncEngineDataSource};
|
@@ -0,0 +1 @@
|
|
1
|
+
var selectIdentifier=function(e){return e.id},selectDisplayName=function(e){return e.name+" (pid: "+e.id+")"};export{selectIdentifier,selectDisplayName};
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { CommandModule } from 'yargs';
|
2
|
-
import { ApiArgs, ProjectArgs } from '../../util';
|
2
|
+
import { ApiArgs, DiffArgs, ProjectArgs } from '../../util';
|
3
3
|
declare type PullComponentArgs = {
|
4
4
|
directory: string;
|
5
5
|
format: 'yaml' | 'json';
|
6
6
|
whatIf: boolean;
|
7
7
|
mode: 'mirror' | 'createOrUpdate' | 'create';
|
8
|
-
} & ApiArgs & ProjectArgs;
|
8
|
+
} & ApiArgs & ProjectArgs & DiffArgs;
|
9
9
|
export declare const ComponentPullModule: CommandModule<PullComponentArgs, PullComponentArgs>;
|
10
10
|
export {};
|
@@ -1 +1 @@
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(e,a,c,
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,a,c,l){return new(c=c||Promise)(function(n,t){function i(e){try{o(l.next(e))}catch(e){t(e)}}function r(e){try{o(l.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?n(e.value):((t=e.value)instanceof c?t:new c(function(e){e(t)})).then(i,r)}o((l=l.apply(e,a||[])).next())})},__generator=this&&this.__generator||function(n,i){var r,o,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(r)throw new TypeError("Generator is already executing.");for(;c;)try{if(r=1,o&&(a=2&t[0]?o.return:t[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,t[1])).done)return a;switch(o=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++,o=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=i.call(n,c)}catch(e){t=[6,e],o=0}finally{r=a=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}};import{CanvasClient}from"../../../CanvasClient";import{isPathAPackageFile,limitPolicy,withApiOptions,withDiffOptions,withProjectOptions}from"../../util";import fetch from"isomorphic-unfetch";import{syncEngine}from"../../syncEngine";import{createFileSyncEngineDataSource}from"../../fileSyncEngineDataSource";import{createComponentDefinitionEngineDataSource}from"../../componentDefinitionEngineDataSource";import{createSyncEngineConsoleLogger}from"../../syncEngineConsoleLogger";import{readCanvasPackage,writeCanvasPackage}from"../../package";import{createArraySyncEngineDataSource}from"../../arraySyncEngineDataSource";import{selectDisplayName,selectIdentifier}from"./_util";var ComponentPullModule={command:"pull <directory>",describe:"Pulls all component definitions to local files in a directory",builder:function(e){return withApiOptions(withProjectOptions(withDiffOptions(e.positional("directory",{describe:"Directory to save the component definitions to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"}))))},handler:function(e){var o=e.apiHost,a=e.apiKey,c=e.directory,l=e.format,s=e.mode,f=e.whatIf,u=e.project,p=e.diff;return __awaiter(void 0,void 0,void 0,function(){var t,n,i,r;return __generator(this,function(e){switch(e.label){case 0:return(r=new CanvasClient({apiKey:a,apiHost:o,fetch:fetch,projectId:u,limitPolicy:limitPolicy}),t=createComponentDefinitionEngineDataSource({client:r}),isPathAPackageFile(c))?(i=readCanvasPackage(c,!1),[4,createArraySyncEngineDataSource({objects:null!==(r=i.components)&&void 0!==r?r:[],selectIdentifier:selectIdentifier,selectDisplayName:selectDisplayName,onSyncComplete:function(e,t){return __awaiter(void 0,void 0,void 0,function(){return __generator(this,function(e){return i.components=t,writeCanvasPackage(c,i),[2]})})}})]):[3,2];case 1:return n=e.sent(),[3,4];case 2:return[4,createFileSyncEngineDataSource({directory:c,selectIdentifier:selectIdentifier,selectDisplayName:selectDisplayName,format:l})];case 3:n=e.sent(),e.label=4;case 4:return[4,syncEngine({source:t,target:n,mode:s,whatIf:f,log:createSyncEngineConsoleLogger({diffMode:p})})];case 5:return e.sent(),[2]}})})}};export{ComponentPullModule};
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { CommandModule } from 'yargs';
|
2
|
-
import { ApiArgs, ProjectArgs } from '../../util';
|
2
|
+
import { ApiArgs, DiffArgs, ProjectArgs } from '../../util';
|
3
3
|
declare type PushComponentArgs = {
|
4
4
|
directory: string;
|
5
5
|
whatIf: boolean;
|
6
6
|
mode: 'mirror' | 'createOrUpdate' | 'create';
|
7
|
-
} & ApiArgs & ProjectArgs;
|
7
|
+
} & ApiArgs & ProjectArgs & DiffArgs;
|
8
8
|
export declare const ComponentPushModule: CommandModule<PushComponentArgs, PushComponentArgs>;
|
9
9
|
export {};
|
@@ -1 +1 @@
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(e,a,c,s){return new(c=c||Promise)(function(n,t){function
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,a,c,s){return new(c=c||Promise)(function(n,t){function i(e){try{o(s.next(e))}catch(e){t(e)}}function r(e){try{o(s.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?n(e.value):((t=e.value)instanceof c?t:new c(function(e){e(t)})).then(i,r)}o((s=s.apply(e,a||[])).next())})},__generator=this&&this.__generator||function(n,i){var r,o,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(r)throw new TypeError("Generator is already executing.");for(;c;)try{if(r=1,o&&(a=2&t[0]?o.return:t[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,t[1])).done)return a;switch(o=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++,o=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=i.call(n,c)}catch(e){t=[6,e],o=0}finally{r=a=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}};import{CanvasClient}from"../../../CanvasClient";import{isPathAPackageFile,limitPolicy,withApiOptions,withDiffOptions,withProjectOptions}from"../../util";import fetch from"isomorphic-unfetch";import{createComponentDefinitionEngineDataSource}from"../../componentDefinitionEngineDataSource";import{syncEngine}from"../../syncEngine";import{createSyncEngineConsoleLogger}from"../../syncEngineConsoleLogger";import{createFileSyncEngineDataSource}from"../../fileSyncEngineDataSource";import{readCanvasPackage}from"../../package";import{createArraySyncEngineDataSource}from"../../arraySyncEngineDataSource";import{selectDisplayName,selectIdentifier}from"./_util";var ComponentPushModule={command:"push <directory>",describe:"Pushes all component definitions from files in a directory to Uniform Optimize",builder:function(e){return withApiOptions(withProjectOptions(withDiffOptions(e.positional("directory",{describe:"Directory to read the component definitions from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"}))))},handler:function(e){var r=e.apiHost,o=e.apiKey,a=e.directory,c=e.mode,s=e.whatIf,l=e.project,u=e.diff;return __awaiter(void 0,void 0,void 0,function(){var t,n,i;return __generator(this,function(e){switch(e.label){case 0:return(t=new CanvasClient({apiKey:o,apiHost:r,fetch:fetch,projectId:l,limitPolicy:limitPolicy}),isPathAPackageFile(a))?(i=readCanvasPackage(a,!0),[4,createArraySyncEngineDataSource({objects:null!==(i=i.components)&&void 0!==i?i:[],selectIdentifier:selectIdentifier,selectDisplayName:selectDisplayName})]):[3,2];case 1:return n=e.sent(),[3,4];case 2:return[4,createFileSyncEngineDataSource({directory:a,selectIdentifier:selectIdentifier,selectDisplayName:selectDisplayName})];case 3:n=e.sent(),e.label=4;case 4:return i=createComponentDefinitionEngineDataSource({client:t}),[4,syncEngine({source:n,target:i,mode:c,whatIf:s,log:createSyncEngineConsoleLogger({diffMode:u})})];case 5:return e.sent(),[2]}})})}};export{ComponentPushModule};
|
@@ -0,0 +1 @@
|
|
1
|
+
var selectIdentifier=function(i){return i.composition._id},selectDisplayName=function(i){var o;return(null!==(o=null!==(o=i.composition._name)&&void 0!==o?o:i.composition._slug)&&void 0!==o?o:i.composition._id)+" (pid: "+i.composition._id+")"};export{selectIdentifier,selectDisplayName};
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { CommandModule } from 'yargs';
|
2
|
-
import { ApiArgs, ProjectArgs, StateArgs } from '../../util';
|
2
|
+
import { ApiArgs, DiffArgs, ProjectArgs, StateArgs } from '../../util';
|
3
3
|
declare type PullCompositionArgs = {
|
4
4
|
directory: string;
|
5
5
|
format: 'yaml' | 'json';
|
6
6
|
whatIf: boolean;
|
7
7
|
mode: 'mirror' | 'createOrUpdate' | 'create';
|
8
|
-
} & ApiArgs & StateArgs & ProjectArgs;
|
8
|
+
} & ApiArgs & StateArgs & ProjectArgs & DiffArgs;
|
9
9
|
export declare const CompositionPullModule: CommandModule<PullCompositionArgs, PullCompositionArgs>;
|
10
10
|
export {};
|
@@ -1 +1 @@
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(e,a,c,s){return new(c=c||Promise)(function(n,t){function
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,a,c,s){return new(c=c||Promise)(function(n,t){function i(e){try{o(s.next(e))}catch(e){t(e)}}function r(e){try{o(s.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?n(e.value):((t=e.value)instanceof c?t:new c(function(e){e(t)})).then(i,r)}o((s=s.apply(e,a||[])).next())})},__generator=this&&this.__generator||function(n,i){var r,o,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(r)throw new TypeError("Generator is already executing.");for(;c;)try{if(r=1,o&&(a=2&t[0]?o.return:t[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,t[1])).done)return a;switch(o=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++,o=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=i.call(n,c)}catch(e){t=[6,e],o=0}finally{r=a=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}};import{CanvasClient}from"../../../CanvasClient";import{isPathAPackageFile,limitPolicy,withApiOptions,withDiffOptions,withProjectOptions,withStateOptions}from"../../util";import fetch from"isomorphic-unfetch";import{syncEngine}from"../../syncEngine";import{createFileSyncEngineDataSource}from"../../fileSyncEngineDataSource";import{createComponentInstanceEngineDataSource}from"../../componentInstanceEngineDataSource";import{createSyncEngineConsoleLogger}from"../../syncEngineConsoleLogger";import{readCanvasPackage,writeCanvasPackage}from"../../package";import{createArraySyncEngineDataSource}from"../../arraySyncEngineDataSource";import{selectDisplayName,selectIdentifier}from"./_util";var CompositionPullModule={command:"pull <directory>",describe:"Pulls all compositions to local files in a directory",builder:function(e){return withApiOptions(withProjectOptions(withStateOptions(withDiffOptions(e.positional("directory",{describe:"Directory to save the component definitions to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))))},handler:function(e){var o=e.apiHost,a=e.apiKey,c=e.directory,s=e.format,l=e.mode,u=e.whatIf,f=e.state,p=e.project,d=e.diff;return __awaiter(void 0,void 0,void 0,function(){var t,n,i,r;return __generator(this,function(e){switch(e.label){case 0:return(r=new CanvasClient({apiKey:a,apiHost:o,fetch:fetch,projectId:p,limitPolicy:limitPolicy}),t=createComponentInstanceEngineDataSource({client:r,state:f}),isPathAPackageFile(c))?(i=readCanvasPackage(c,!1),[4,createArraySyncEngineDataSource({objects:null!==(r=null==i?void 0:i.compositions)&&void 0!==r?r:[],selectIdentifier:selectIdentifier,selectDisplayName:selectDisplayName,onSyncComplete:function(e,t){return __awaiter(void 0,void 0,void 0,function(){return __generator(this,function(e){return i.compositions=t,writeCanvasPackage(c,i),[2]})})}})]):[3,2];case 1:return n=e.sent(),[3,4];case 2:return[4,createFileSyncEngineDataSource({directory:c,selectIdentifier:selectIdentifier,selectDisplayName:selectDisplayName,format:s})];case 3:n=e.sent(),e.label=4;case 4:return[4,syncEngine({source:t,target:n,mode:l,whatIf:u,log:createSyncEngineConsoleLogger({diffMode:d})})];case 5:return e.sent(),[2]}})})}};export{CompositionPullModule};
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { CommandModule } from 'yargs';
|
2
|
-
import { ApiArgs, ProjectArgs, StateArgs } from '../../util';
|
2
|
+
import { ApiArgs, DiffArgs, ProjectArgs, StateArgs } from '../../util';
|
3
3
|
declare type PushCompositionArgs = {
|
4
4
|
directory: string;
|
5
5
|
whatIf: boolean;
|
6
6
|
mode: 'mirror' | 'createOrUpdate' | 'create';
|
7
|
-
} & ApiArgs & StateArgs & ProjectArgs;
|
7
|
+
} & ApiArgs & StateArgs & ProjectArgs & DiffArgs;
|
8
8
|
export declare const CompositionPushModule: CommandModule<PushCompositionArgs, PushCompositionArgs>;
|
9
9
|
export {};
|
@@ -1 +1 @@
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(e,
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,o,c,s){return new(c=c||Promise)(function(n,t){function i(e){try{a(s.next(e))}catch(e){t(e)}}function r(e){try{a(s.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?n(e.value):((t=e.value)instanceof c?t:new c(function(e){e(t)})).then(i,r)}a((s=s.apply(e,o||[])).next())})},__generator=this&&this.__generator||function(n,i){var r,a,o,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(r)throw new TypeError("Generator is already executing.");for(;c;)try{if(r=1,a&&(o=2&t[0]?a.return:t[0]?a.throw||((o=a.return)&&o.call(a),0):a.next)&&!(o=o.call(a,t[1])).done)return o;switch(a=0,(t=o?[2&t[0],o.value]:t)[0]){case 0:case 1:o=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,a=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!(o=0<(o=c.trys).length&&o[o.length-1])&&(6===t[0]||2===t[0])){c=0;continue}if(3===t[0]&&(!o||t[1]>o[0]&&t[1]<o[3])){c.label=t[1];break}if(6===t[0]&&c.label<o[1]){c.label=o[1],o=t;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(t);break}o[2]&&c.ops.pop(),c.trys.pop();continue}t=i.call(n,c)}catch(e){t=[6,e],a=0}finally{r=o=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}};import{CanvasClient}from"../../../CanvasClient";import{isPathAPackageFile,limitPolicy,withApiOptions,withDiffOptions,withProjectOptions,withStateOptions}from"../../util";import fetch from"isomorphic-unfetch";import{syncEngine}from"../../syncEngine";import{createSyncEngineConsoleLogger}from"../../syncEngineConsoleLogger";import{createFileSyncEngineDataSource}from"../../fileSyncEngineDataSource";import{createComponentInstanceEngineDataSource}from"../../componentInstanceEngineDataSource";import{readCanvasPackage}from"../../package";import{createArraySyncEngineDataSource}from"../../arraySyncEngineDataSource";import{selectDisplayName,selectIdentifier}from"./_util";var CompositionPushModule={command:"push <directory>",describe:"Pushes all compositions from files in a directory to Uniform Optimize",builder:function(e){return withApiOptions(withProjectOptions(withStateOptions(withDiffOptions(e.positional("directory",{describe:"Directory to read the component definitions from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))))},handler:function(e){var r=e.apiHost,a=e.apiKey,o=e.directory,c=e.mode,s=e.whatIf,l=e.state,u=e.project,p=e.diff;return __awaiter(void 0,void 0,void 0,function(){var t,n,i;return __generator(this,function(e){switch(e.label){case 0:return(t=new CanvasClient({apiKey:a,apiHost:r,fetch:fetch,projectId:u,limitPolicy:limitPolicy}),isPathAPackageFile(o))?(i=readCanvasPackage(o,!0),[4,createArraySyncEngineDataSource({objects:null!==(i=i.compositions)&&void 0!==i?i:[],selectIdentifier:selectIdentifier,selectDisplayName:selectDisplayName})]):[3,2];case 1:return n=e.sent(),[3,4];case 2:return[4,createFileSyncEngineDataSource({directory:o,selectIdentifier:selectIdentifier,selectDisplayName:selectDisplayName})];case 3:n=e.sent(),e.label=4;case 4:return i=createComponentInstanceEngineDataSource({client:t,state:l}),[4,syncEngine({source:n,target:i,mode:c,whatIf:s,log:createSyncEngineConsoleLogger({diffMode:p})})];case 5:return e.sent(),[2]}})})}};export{CompositionPushModule};
|
@@ -1 +1 @@
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(e,
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,a,c,s){return new(c=c||Promise)(function(n,t){function r(e){try{i(s.next(e))}catch(e){t(e)}}function o(e){try{i(s.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((s=s.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])}}},__asyncValues=this&&this.__asyncValues||function(a){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,t=a[Symbol.asyncIterator];return t?t.call(a):(a="function"==typeof __values?__values(a):a[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(i){e[i]=a[i]&&function(o){return new Promise(function(e,t){var n,r;o=a[i](o),n=e,e=t,r=o.done,t=o.value,Promise.resolve(t).then(function(e){n({value:e,done:r})},e)})}}},__await=this&&this.__await||function(e){return this instanceof __await?(this.v=e,this):new __await(e)},__asyncGenerator=this&&this.__asyncGenerator||function(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o=n.apply(e,t||[]),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(e,t){1<i.push([r,n,e,t])||c(r,n)})})}function c(e,t){try{(n=o[e](t)).value instanceof __await?Promise.resolve(n.value.v).then(s,u):l(i[0][2],n)}catch(e){l(i[0][3],e)}var n}function s(e){c("next",e)}function u(e){c("throw",e)}function l(e,t){e(t),i.shift(),i.length&&c(i[0][0],i[0][1])}};import{paginateAsync}from"./util";import{selectDisplayName,selectIdentifier}from"./commands/component/_util";function createComponentDefinitionEngineDataSource(e){var n=this,s=e.client;return{objects:function(){return __asyncGenerator(this,arguments,function(){var t,n,r,o,i,a,c=this;return __generator(this,function(e){switch(e.label){case 0:t=paginateAsync(function(t,n){return __awaiter(c,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return[4,s.getComponentDefinitions({limit:n,offset:t})];case 1:return[2,e.sent().componentDefinitions]}})})},{pageSize:100}),e.label=1;case 1:e.trys.push([1,8,9,14]),n=__asyncValues(t),e.label=2;case 2:return[4,__await(n.next())];case 3:return(r=e.sent()).done?[3,7]:(o=r.value,o={id:selectIdentifier(o),displayName:selectDisplayName(o),providerId:o.id,object:o},[4,__await(o)]);case 4:return[4,e.sent()];case 5:e.sent(),e.label=6;case 6:return[3,2];case 7:return[3,14];case 8:return i=e.sent(),i={error:i},[3,14];case 9:return e.trys.push([9,,12,13]),r&&!r.done&&(a=n.return)?[4,__await(a.call(n))]:[3,11];case 10:e.sent(),e.label=11;case 11:return[3,13];case 12:if(i)throw i.error;return[7];case 13:return[7];case 14:return[2]}})})}(),deleteObject:function(t){return __awaiter(n,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return[4,s.removeComponentDefinition({componentId:t})];case 1:return e.sent(),[2]}})})},writeObject:function(t){return __awaiter(n,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return[4,s.updateComponentDefinition({componentDefinition:t.object})];case 1:return e.sent(),[2]}})})}}}export{createComponentDefinitionEngineDataSource};
|
@@ -1 +1 @@
|
|
1
|
-
var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var n
|
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)},__awaiter=this&&this.__awaiter||function(t,a,s,c){return new(s=s||Promise)(function(n,e){function r(t){try{i(c.next(t))}catch(t){e(t)}}function o(t){try{i(c.throw(t))}catch(t){e(t)}}function i(t){var e;t.done?n(t.value):((e=t.value)instanceof s?e:new s(function(t){t(e)})).then(r,o)}i((c=c.apply(t,a||[])).next())})},__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])}}},__asyncValues=this&&this.__asyncValues||function(a){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,e=a[Symbol.asyncIterator];return e?e.call(a):(a="function"==typeof __values?__values(a):a[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(i){t[i]=a[i]&&function(o){return new Promise(function(t,e){var n,r;o=a[i](o),n=t,t=e,r=o.done,e=o.value,Promise.resolve(e).then(function(t){n({value:t,done:r})},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(c,u):l(i[0][2],n)}catch(t){l(i[0][3],t)}var n}function c(t){s("next",t)}function u(t){s("throw",t)}function l(t,e){t(e),i.shift(),i.length&&s(i[0][0],i[0][1])}};import{convertCompositionState,paginateAsync,prepCompositionForDisk}from"./util";import{selectDisplayName,selectIdentifier}from"./commands/composition/_util";function createComponentInstanceEngineDataSource(t){var n=this,c=t.client,t=t.state,u=convertCompositionState(t);return{objects:function(){return __asyncGenerator(this,arguments,function(){var e,n,r,o,i,a,s=this;return __generator(this,function(t){switch(t.label){case 0:e=paginateAsync(function(e,n){return __awaiter(s,void 0,void 0,function(){return __generator(this,function(t){switch(t.label){case 0:return[4,c.getCompositionList({limit:n,offset:e,state:u})];case 1:return[2,t.sent().compositions]}})})},{pageSize:100}),t.label=1;case 1:t.trys.push([1,8,9,14]),n=__asyncValues(e),t.label=2;case 2:return[4,__await(n.next())];case 3:return(r=t.sent()).done?[3,7]:(o=r.value,o={id:selectIdentifier(o),displayName:selectDisplayName(o),providerId:o.composition._id,object:prepCompositionForDisk(o)},[4,__await(o)]);case 4:return[4,t.sent()];case 5:t.sent(),t.label=6;case 6:return[3,2];case 7:return[3,14];case 8:return i=t.sent(),i={error:i},[3,14];case 9:return t.trys.push([9,,12,13]),r&&!r.done&&(a=n.return)?[4,__await(a.call(n))]:[3,11];case 10:t.sent(),t.label=11;case 11:return[3,13];case 12:if(i)throw i.error;return[7];case 13:return[7];case 14:return[2]}})})}(),deleteObject:function(e){return __awaiter(n,void 0,void 0,function(){return __generator(this,function(t){switch(t.label){case 0:return[4,c.removeComposition({compositionId:e})];case 1:return t.sent(),[2]}})})},writeObject:function(e){return __awaiter(n,void 0,void 0,function(){return __generator(this,function(t){switch(t.label){case 0:return[4,c.updateComposition(__assign(__assign({},e.object),{state:u}))];case 1:return t.sent(),[2]}})})}}}export{createComponentInstanceEngineDataSource};
|
@@ -1,8 +1,9 @@
|
|
1
|
-
import { SyncEngineDataSource
|
1
|
+
import { SyncEngineDataSource } from './syncEngine';
|
2
2
|
export declare type CreateFileSyncEngineDataSourceOptions<TObject> = {
|
3
3
|
directory: string;
|
4
|
-
selectIdentifier: (object:
|
4
|
+
selectIdentifier: (object: TObject) => string;
|
5
|
+
selectDisplayName?: (object: TObject) => string;
|
5
6
|
selectFilename?: (object: TObject) => string;
|
6
7
|
format?: 'json' | 'yaml';
|
7
8
|
};
|
8
|
-
export declare function createFileSyncEngineDataSource<TObject>({ directory, format, selectIdentifier, }: CreateFileSyncEngineDataSourceOptions<TObject>): Promise<SyncEngineDataSource<TObject>>;
|
9
|
+
export declare function createFileSyncEngineDataSource<TObject>({ directory, format, selectIdentifier, selectDisplayName, }: CreateFileSyncEngineDataSourceOptions<TObject>): Promise<SyncEngineDataSource<TObject>>;
|
@@ -1 +1 @@
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,a,c,u){return new(c=c||Promise)(function(n,t){function r(e){try{o(u.next(e))}catch(e){t(e)}}function i(e){try{o(u.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?n(e.value):((t=e.value)instanceof c?t:new c(function(e){e(t)})).then(r,i)}o((u=u.apply(e,a||[])).next())})},__generator=this&&this.__generator||function(n,r){var i,o,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(i)throw new TypeError("Generator is already executing.");for(;c;)try{if(i=1,o&&(a=2&t[0]?o.return:t[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,t[1])).done)return a;switch(o=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++,o=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],o=0}finally{i=a=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}},__await=this&&this.__await||function(e){return this instanceof __await?(this.v=e,this):new __await(e)},__asyncGenerator=this&&this.__asyncGenerator||function(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=n.apply(e,t||[]),o=[],a={};return r("next"),r("throw"),r("return"),a[Symbol.asyncIterator]=function(){return this},a;function r(r){i[r]&&(a[r]=function(n){return new Promise(function(e,t){1<o.push([r,n,e,t])||c(r,n)})})}function c(e,t){try{(n=i[e](t)).value instanceof __await?Promise.resolve(n.value.v).then(u,s):l(o[0][2],n)}catch(e){l(o[0][3],e)}var n}function u(e){c("next",e)}function s(e){c("throw",e)}function l(e,t){e(t),o.shift(),o.length&&c(o[0][0],o[0][1])}},__values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return{value:(e=e&&r>=e.length?void 0:e)&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};import chalk from"chalk";import{existsSync,mkdirSync}from"fs";import{readdir,unlink}from"fs/promises";import{extname,join}from"path";import{emitWithFormat,readFileToObject}from"./util";function createFileSyncEngineDataSource(e){var u=e.directory,t=e.format,i=void 0===t?"yaml":t,s=e.selectIdentifier,e=e.selectDisplayName,l=void 0===e?s:e;return __awaiter(this,void 0,void 0,function(){var t,c,n,r=this;return __generator(this,function(e){switch(e.label){case 0:return existsSync(u)||mkdirSync(u,{recursive:!0}),[4,readdir(u,"utf-8")];case 1:return t=e.sent(),c=new Set(t.filter(function(e){e=extname(e);return".json"===e||".yaml"===e||".yml"===e})),n=function(e){return join(u,e+"."+i)},[2,{objects:function(){return __asyncGenerator(this,arguments,function(){var t,n,r,i,o,a;return __generator(this,function(e){switch(e.label){case 0:e.trys.push([0,9,10,11]),t=__values(c),n=t.next(),e.label=1;case 1:if(n.done)return[3,8];r=n.value,r=join(u,r),e.label=2;case 2:return e.trys.push([2,6,,7]),[4,__await(readFileToObject(r))];case 3:return i=e.sent(),i={id:s(i),displayName:l(i),providerId:r,object:i},[4,__await(i)];case 4:return[4,e.sent()];case 5:return e.sent(),[3,7];case 6:throw i=e.sent(),console.error(chalk.red("Failed to read "+r+", data is likely invalid.\n"+(null==i?void 0:i.message))),i;case 7:return n=t.next(),[3,1];case 8:return[3,11];case 9:return o=e.sent(),o={error:o},[3,11];case 10:try{n&&!n.done&&(a=t.return)&&a.call(t)}finally{if(o)throw o.error}return[7];case 11:return[2]}})})}(),deleteObject:function(t){return __awaiter(r,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return[4,unlink(t)];case 1:return e.sent(),[2]}})})},writeObject:function(t){return __awaiter(r,void 0,void 0,function(){return __generator(this,function(e){return emitWithFormat(t.object,i,n(t.id)),[2]})})}}]}})})}export{createFileSyncEngineDataSource};
|
@@ -1,11 +1,15 @@
|
|
1
|
+
import { Change } from 'diff';
|
1
2
|
export declare type SyncEngineLogOptions = {
|
2
3
|
id: string;
|
3
4
|
providerId: string;
|
4
5
|
displayName: string;
|
5
6
|
action: 'create' | 'update' | 'delete';
|
6
7
|
whatIf: boolean;
|
8
|
+
diff: Change[];
|
7
9
|
};
|
8
10
|
export declare type SyncEngineObject<TObject> = {
|
11
|
+
/** Unique ID that is identical across all providers */
|
12
|
+
id: string;
|
9
13
|
/** Provider specific ID. Value is provided to deleteObject() function (always the provider ID from the same provider that issued it). */
|
10
14
|
providerId: string;
|
11
15
|
/** Optional display name of the object for log messages. The providerId will be used if this is not set. */
|
@@ -34,7 +38,6 @@ export declare type SyncEngineDataSource<TObject> = {
|
|
34
38
|
export declare type SyncEngineOptions<TObject> = {
|
35
39
|
source: SyncEngineDataSource<TObject>;
|
36
40
|
target: SyncEngineDataSource<TObject>;
|
37
|
-
selectIdentifier: (object: SyncEngineObject<TObject>) => string;
|
38
41
|
compareContents?: (source: SyncEngineObject<TObject>, target: SyncEngineObject<TObject>) => boolean;
|
39
42
|
mode: 'mirror' | 'createOrUpdate' | 'create';
|
40
43
|
/** Compare sources, but do not execute actions */
|
@@ -43,4 +46,4 @@ export declare type SyncEngineOptions<TObject> = {
|
|
43
46
|
allowEmptySource?: boolean;
|
44
47
|
log?: (options: SyncEngineLogOptions) => void;
|
45
48
|
};
|
46
|
-
export declare function syncEngine<TObject>({ source, target,
|
49
|
+
export declare function syncEngine<TObject>({ source, target, compareContents, mode, allowEmptySource, whatIf, log, }: SyncEngineOptions<TObject>): Promise<void>;
|
@@ -1 +1 @@
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(e,
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,o,s,u){return new(s=s||Promise)(function(t,r){function n(e){try{i(u.next(e))}catch(e){r(e)}}function a(e){try{i(u.throw(e))}catch(e){r(e)}}function i(e){var r;e.done?t(e.value):((r=e.value)instanceof s?r:new s(function(e){e(r)})).then(n,a)}i((u=u.apply(e,o||[])).next())})},__generator=this&&this.__generator||function(t,n){var a,i,o,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(;s;)try{if(a=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,(r=o?[2&r[0],o.value]:r)[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=0<(o=s.trys).length&&o[o.length-1])&&(6===r[0]||2===r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){s.label=r[1];break}if(6===r[0]&&s.label<o[1]){s.label=o[1],o=r;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(r);break}o[2]&&s.ops.pop(),s.trys.pop();continue}r=n.call(t,s)}catch(e){r=[6,e],i=0}finally{a=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,e])}}},__asyncValues=this&&this.__asyncValues||function(o){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,r=o[Symbol.asyncIterator];return r?r.call(o):(o="function"==typeof __values?__values(o):o[Symbol.iterator](),e={},t("next"),t("throw"),t("return"),e[Symbol.asyncIterator]=function(){return this},e);function t(i){e[i]=o[i]&&function(a){return new Promise(function(e,r){var t,n;a=o[i](a),t=e,e=r,n=a.done,r=a.value,Promise.resolve(r).then(function(e){t({value:e,done:n})},e)})}}};import{diffJson,diffLines}from"diff";import isEqualWith from"lodash.isequalwith";function syncEngine(e){var v,p,y,b,_,w=e.source,m=e.target,r=e.compareContents,g=void 0===r?function(e,r){return isEqualWith(e.object,r.object,function(e,r,t){return"created"===t||"updated"===t||void 0})}:r,I=e.mode,r=e.allowEmptySource,S=void 0!==r&&r,r=e.whatIf,j=void 0!==r&&r,e=e.log,x=void 0===e?function(){}:e;return __awaiter(this,void 0,void 0,function(){var r,t,n,a,i,o,s,u,c,l,d,f,h=this;return __generator(this,function(e){switch(e.label){case 0:r=new Map,e.label=1;case 1:e.trys.push([1,6,7,12]),t=__asyncValues(m.objects),e.label=2;case 2:return[4,t.next()];case 3:if((n=e.sent()).done)return[3,5];l=n.value,r.set(l.id,l),e.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return c=e.sent(),v={error:c},[3,12];case 7:return e.trys.push([7,,10,11]),n&&!n.done&&(p=t.return)?[4,p.call(t)]:[3,9];case 8:e.sent(),e.label=9;case 9:return[3,11];case 10:if(v)throw v.error;return[7];case 11:return[7];case 12:i=!(a=[]),e.label=13;case 13:e.trys.push([13,18,19,24]),o=__asyncValues(w.objects),e.label=14;case 14:return[4,o.next()];case 15:if((s=e.sent()).done)return[3,17];d=s.value,i=!0,u=d.id,(l=r.get(u))?(g(d,l)||"createOrUpdate"!==I&&"mirror"!==I||(c=function(t,n){return __awaiter(h,void 0,void 0,function(){var r;return __generator(this,function(e){switch(e.label){case 0:return j?[3,2]:[4,m.writeObject(t)];case 1:e.sent(),e.label=2;case 2:return x({action:"update",id:u,providerId:t.providerId,displayName:null!==(r=t.displayName)&&void 0!==r?r:t.providerId,whatIf:j,diff:diffJson(n.object,t.object)}),[2]}})})},a.push(c(d,l))),r.delete(u)):(l=function(t,n){return __awaiter(h,void 0,void 0,function(){var r;return __generator(this,function(e){switch(e.label){case 0:return j?[3,2]:[4,m.writeObject(t)];case 1:e.sent(),e.label=2;case 2:return x({action:"create",id:n,providerId:n,displayName:null!==(r=t.displayName)&&void 0!==r?r:t.providerId,whatIf:j,diff:diffLines("",JSON.stringify(t.object,null,2))}),[2]}})})},a.push(l(d,u))),e.label=16;case 16:return[3,14];case 17:return[3,24];case 18:return d=e.sent(),y={error:d},[3,24];case 19:return e.trys.push([19,,22,23]),s&&!s.done&&(b=o.return)?[4,b.call(o)]:[3,21];case 20:e.sent(),e.label=21;case 21:return[3,23];case 22:if(y)throw y.error;return[7];case 23:return[7];case 24:return[4,Promise.all(a)];case 25:if(e.sent(),"mirror"!==I)return[3,27];if(!i&&!S)throw new Error("Source is empty and mode is mirror. This would cause deletion of everything in the target, and most likely indicates an error in source definition.");return f=[],r.forEach(function(t){return __awaiter(h,void 0,void 0,function(){var r,n=this;return __generator(this,function(e){return r=function(t){return __awaiter(n,void 0,void 0,function(){var r;return __generator(this,function(e){switch(e.label){case 0:return j?[3,2]:[4,m.deleteObject(t.providerId)];case 1:e.sent(),e.label=2;case 2:return x({action:"delete",id:t.id,providerId:t.providerId,displayName:null!==(r=t.displayName)&&void 0!==r?r:t.providerId,whatIf:j,diff:diffLines(JSON.stringify(t.object,null,2),"")}),[2]}})})},f.push(r(t)),[2]})})}),[4,Promise.all(f)];case 26:e.sent(),e.label=27;case 27:return[4,Promise.all([null===(_=w.onSyncComplete)||void 0===_?void 0:_.call(w,!1),null===(_=m.onSyncComplete)||void 0===_?void 0:_.call(m,!0)])];case 28:return e.sent(),[2]}})})}export{syncEngine};
|
@@ -1,2 +1,5 @@
|
|
1
1
|
import { SyncEngineLogOptions } from './syncEngine';
|
2
|
-
export declare
|
2
|
+
export declare type DiffMode = 'off' | 'on' | 'update';
|
3
|
+
export declare function createSyncEngineConsoleLogger({ diffMode }: {
|
4
|
+
diffMode: DiffMode;
|
5
|
+
}): ({ action, displayName, whatIf, diff }: SyncEngineLogOptions) => void;
|
@@ -1 +1 @@
|
|
1
|
-
import chalk from"chalk";function
|
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};
|
package/dist/esm/cli/util.d.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import { Argv } from 'yargs';
|
2
2
|
import { CompositionAPIResponse } from '../types/componentInstances';
|
3
|
+
import pLimit from 'p-limit';
|
4
|
+
import { DiffMode } from './syncEngineConsoleLogger';
|
3
5
|
export declare type ApiArgs = {
|
4
6
|
apiKey: string;
|
5
7
|
apiHost: string;
|
@@ -14,6 +16,10 @@ export declare type FormatArgs = {
|
|
14
16
|
filename?: string;
|
15
17
|
};
|
16
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>;
|
17
23
|
export declare function isPathAPackageFile(path: string): boolean;
|
18
24
|
export declare function emitWithFormat(object: any, format?: string, filename?: string): void;
|
19
25
|
export declare function readFileToObject<T = unknown>(filename: string): T;
|
@@ -33,3 +39,4 @@ export declare function paginateAsync<TResult>(fetchPage: (offset: number, limit
|
|
33
39
|
pageSize: number;
|
34
40
|
}): AsyncIterableIterator<TResult>;
|
35
41
|
export declare function convertCompositionState(state: CLICompositionState): number;
|
42
|
+
export declare const limitPolicy: pLimit.Limit;
|
package/dist/esm/cli/util.js
CHANGED
@@ -1 +1 @@
|
|
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";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 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}export{withApiOptions,withProjectOptions,withFormatOptions,isPathAPackageFile,emitWithFormat,readFileToObject,prepCompositionForDisk,withStateOptions,paginateAsync,convertCompositionState};
|
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};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@uniformdev/canvas",
|
3
|
-
"version": "11.0.1-alpha.
|
3
|
+
"version": "11.0.1-alpha.97+6d03c4d",
|
4
4
|
"description": "Common functionality and types for Uniform Canvas",
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
6
6
|
"main": "./dist/cjs/index.js",
|
@@ -41,12 +41,13 @@
|
|
41
41
|
"ci:build": "run-s clean build"
|
42
42
|
},
|
43
43
|
"devDependencies": {
|
44
|
+
"@types/diff": "5.0.1",
|
44
45
|
"@types/jest": "27.0.2",
|
45
46
|
"@types/js-yaml": "4.0.3",
|
46
47
|
"@types/lodash.isequalwith": "4.4.6",
|
47
48
|
"@types/node": "16.7.1",
|
48
49
|
"@types/yargs": "17.0.3",
|
49
|
-
"@uniformdev/cli": "^11.0.1-alpha.
|
50
|
+
"@uniformdev/cli": "^11.0.1-alpha.97+6d03c4d",
|
50
51
|
"eslint": "7.32.0",
|
51
52
|
"eslint-plugin-react": "7.26.0",
|
52
53
|
"eslint-plugin-react-hooks": "4.2.0",
|
@@ -60,12 +61,14 @@
|
|
60
61
|
"yargs": "^17.0.1"
|
61
62
|
},
|
62
63
|
"dependencies": {
|
63
|
-
"@uniformdev/optimize-common": "^11.0.1-alpha.
|
64
|
-
"@uniformdev/optimize-tracker-common": "^11.0.1-alpha.
|
64
|
+
"@uniformdev/optimize-common": "^11.0.1-alpha.97+6d03c4d",
|
65
|
+
"@uniformdev/optimize-tracker-common": "^11.0.1-alpha.97+6d03c4d",
|
65
66
|
"chalk": "^4.1.2",
|
67
|
+
"diff": "^5.0.0",
|
66
68
|
"isomorphic-unfetch": "^3.1.0",
|
67
69
|
"js-yaml": "^4.1.0",
|
68
70
|
"lodash.isequalwith": "^4.4.0",
|
71
|
+
"p-limit": "^3.1.0",
|
69
72
|
"p-retry": "^4.6.1",
|
70
73
|
"p-throttle": "^4.1.1",
|
71
74
|
"pusher-js": ">=7.0.3"
|
@@ -73,5 +76,8 @@
|
|
73
76
|
"files": [
|
74
77
|
"/dist"
|
75
78
|
],
|
76
|
-
"
|
79
|
+
"publishConfig": {
|
80
|
+
"access": "public"
|
81
|
+
},
|
82
|
+
"gitHead": "6d03c4d1c4ac2b8b9b4e3a62bed522361df8ba6d"
|
77
83
|
}
|