@sprucelabs/spruce-cli 18.0.0 → 18.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/build/__tests__/behavioral/EnablingAndDisablingCache.test.js +1 -1
  3. package/build/__tests__/behavioral/EnablingAndDisablingCache.test.js.map +1 -1
  4. package/build/__tests__/behavioral/RememberingUpgradeSelections.test.js +1 -1
  5. package/build/__tests__/behavioral/RememberingUpgradeSelections.test.js.map +1 -1
  6. package/build/__tests__/behavioral/SettingUpSchemasForModuleDistribution.test.js +4 -4
  7. package/build/__tests__/behavioral/SettingUpSchemasForModuleDistribution.test.js.map +1 -1
  8. package/build/__tests__/behavioral/WatchingSkillViews.test.js +3 -3
  9. package/build/__tests__/behavioral/WatchingSkillViews.test.js.map +1 -1
  10. package/build/__tests__/behavioral/errors/SettingUpErrors.test.js +1 -1
  11. package/build/__tests__/behavioral/errors/SettingUpErrors.test.js.map +1 -1
  12. package/build/__tests__/behavioral/events/CreatingAListener.test.d.ts +2 -0
  13. package/build/__tests__/behavioral/events/CreatingAListener.test.js +118 -59
  14. package/build/__tests__/behavioral/events/CreatingAListener.test.js.map +1 -1
  15. package/build/__tests__/behavioral/events/EverythingInstalledInstaller.d.ts +17 -0
  16. package/build/__tests__/behavioral/events/EverythingInstalledInstaller.js +137 -0
  17. package/build/__tests__/behavioral/events/EverythingInstalledInstaller.js.map +1 -0
  18. package/build/__tests__/behavioral/onboard/StartingOnboarding.test.js +46 -45
  19. package/build/__tests__/behavioral/onboard/StartingOnboarding.test.js.map +1 -1
  20. package/build/__tests__/behavioral/tests/CreatingATest.test.js +1 -1
  21. package/build/__tests__/behavioral/tests/CreatingATest.test.js.map +1 -1
  22. package/build/__tests__/behavioral/tests/SelectingAnAbstractTestClass.test.js +4 -4
  23. package/build/__tests__/behavioral/tests/SelectingAnAbstractTestClass.test.js.map +1 -1
  24. package/build/__tests__/behavioral/upgrading/UpdatingDependencies2.test.js +2 -2
  25. package/build/__tests__/behavioral/upgrading/UpdatingDependencies2.test.js.map +1 -1
  26. package/build/__tests__/behavioral/upgrading/UpgradingANodeModule.test.js +2 -2
  27. package/build/__tests__/behavioral/upgrading/UpgradingANodeModule.test.js.map +1 -1
  28. package/build/__tests__/behavioral/upgrading/UpgradingASkill5.test.js +2 -2
  29. package/build/__tests__/behavioral/upgrading/UpgradingASkill5.test.js.map +1 -1
  30. package/build/__tests__/behavioral/upgrading/UpgradingWithListeners.test.js +2 -2
  31. package/build/__tests__/behavioral/upgrading/UpgradingWithListeners.test.js.map +1 -1
  32. package/build/__tests__/behavioral/views/CreatingASkillView.test.js +1 -1
  33. package/build/__tests__/behavioral/views/CreatingASkillView.test.js.map +1 -1
  34. package/build/__tests__/behavioral/views/CreatingATheme.test.js +1 -1
  35. package/build/__tests__/behavioral/views/CreatingATheme.test.js.map +1 -1
  36. package/build/__tests__/behavioral/watchers/WatchingForChanges.test.d.ts +3 -3
  37. package/build/__tests__/behavioral/watchers/WatchingForChanges.test.js +153 -156
  38. package/build/__tests__/behavioral/watchers/WatchingForChanges.test.js.map +1 -1
  39. package/build/__tests__/implementation/ActionExecuter.test.js +2 -2
  40. package/build/__tests__/implementation/ActionExecuter.test.js.map +1 -1
  41. package/build/__tests__/implementation/ActionExecuter2.test.js +1 -1
  42. package/build/__tests__/implementation/ActionExecuter2.test.js.map +1 -1
  43. package/build/__tests__/implementation/ActionExecuter4.test.js +1 -1
  44. package/build/__tests__/implementation/ActionExecuter4.test.js.map +1 -1
  45. package/build/__tests__/implementation/FeatureInstaller.test.js +8 -4
  46. package/build/__tests__/implementation/FeatureInstaller.test.js.map +1 -1
  47. package/build/__tests__/implementation/GlobalEmitter.d.ts +1 -1
  48. package/build/__tests__/implementation/GlobalEmitter.js +9 -10
  49. package/build/__tests__/implementation/GlobalEmitter.js.map +1 -1
  50. package/build/__tests__/implementation/SettingUpANodeModule.test.js +1 -1
  51. package/build/__tests__/implementation/SettingUpANodeModule.test.js.map +1 -1
  52. package/build/__tests__/implementation/SkillStore.test.d.ts +3 -1
  53. package/build/__tests__/implementation/SkillStore.test.js +67 -50
  54. package/build/__tests__/implementation/SkillStore.test.js.map +1 -1
  55. package/build/__tests__/implementation/StoreFeature.test.js +1 -1
  56. package/build/__tests__/implementation/StoreFeature.test.js.map +1 -1
  57. package/build/cli.js +3 -3
  58. package/build/cli.js.map +1 -1
  59. package/build/features/AbstractAction.d.ts +2 -2
  60. package/build/features/AbstractAction.js.map +1 -1
  61. package/build/features/AbstractFeature.d.ts +22 -22
  62. package/build/features/AbstractFeature.js.map +1 -1
  63. package/build/features/ActionExecuter.d.ts +8 -8
  64. package/build/features/ActionExecuter.js.map +1 -1
  65. package/build/features/FeatureInstaller.d.ts +15 -2
  66. package/build/features/FeatureInstaller.js +36 -36
  67. package/build/features/FeatureInstaller.js.map +1 -1
  68. package/build/features/FeatureInstallerFactory.d.ts +12 -10
  69. package/build/features/FeatureInstallerFactory.js +2 -2
  70. package/build/features/FeatureInstallerFactory.js.map +1 -1
  71. package/build/features/OverrideActionDecorator.js +4 -5
  72. package/build/features/OverrideActionDecorator.js.map +1 -1
  73. package/build/features/event/actions/ListenAction.js.map +1 -1
  74. package/build/features/event/actions/SetRemoteAction.d.ts +1 -0
  75. package/build/features/event/actions/SetRemoteAction.js +2 -1
  76. package/build/features/event/actions/SetRemoteAction.js.map +1 -1
  77. package/build/features/event/actions/SyncListenersAction.js.map +1 -1
  78. package/build/features/node/NodeFeature.js.map +1 -1
  79. package/build/features/skill/SkillFeature.js.map +1 -1
  80. package/build/features/skill/stores/SkillStore.d.ts +4 -1
  81. package/build/features/skill/stores/SkillStore.js +127 -100
  82. package/build/features/skill/stores/SkillStore.js.map +1 -1
  83. package/build/features/watch/WatchFeature.js +1 -1
  84. package/build/features/watch/WatchFeature.js.map +1 -1
  85. package/build/interfaces/SpyInterface.d.ts +2 -0
  86. package/build/interfaces/SpyInterface.js +16 -4
  87. package/build/interfaces/SpyInterface.js.map +1 -1
  88. package/build/stores/AbstractStore.d.ts +9 -7
  89. package/build/stores/AbstractStore.js.map +1 -1
  90. package/build/stores/StoreFactory.d.ts +19 -13
  91. package/build/stores/StoreFactory.js +15 -13
  92. package/build/stores/StoreFactory.js.map +1 -1
  93. package/build/tests/AbstractCliTest.d.ts +9 -6
  94. package/build/tests/AbstractCliTest.js +53 -45
  95. package/build/tests/AbstractCliTest.js.map +1 -1
  96. package/build/tests/AbstractSchemaTest.js +18 -20
  97. package/build/tests/AbstractSchemaTest.js.map +1 -1
  98. package/build/utilities/action.utility.js +3 -1
  99. package/build/utilities/action.utility.js.map +1 -1
  100. package/node_modules/@typescript-eslint/parser/package.json +5 -5
  101. package/node_modules/@typescript-eslint/scope-manager/package.json +5 -5
  102. package/node_modules/@typescript-eslint/types/package.json +2 -2
  103. package/node_modules/@typescript-eslint/typescript-estree/package.json +5 -5
  104. package/node_modules/@typescript-eslint/visitor-keys/package.json +3 -3
  105. package/package.json +32 -90
  106. package/src/__tests__/behavioral/EnablingAndDisablingCache.test.ts +1 -1
  107. package/src/__tests__/behavioral/RememberingUpgradeSelections.test.ts +1 -1
  108. package/src/__tests__/behavioral/SettingUpSchemasForModuleDistribution.test.ts +4 -4
  109. package/src/__tests__/behavioral/WatchingSkillViews.test.ts +3 -3
  110. package/src/__tests__/behavioral/errors/SettingUpErrors.test.ts +1 -1
  111. package/src/__tests__/behavioral/events/CreatingAListener.test.ts +41 -14
  112. package/src/__tests__/behavioral/events/EverythingInstalledInstaller.ts +46 -0
  113. package/src/__tests__/behavioral/onboard/StartingOnboarding.test.ts +10 -5
  114. package/src/__tests__/behavioral/tests/CreatingATest.test.ts +1 -1
  115. package/src/__tests__/behavioral/tests/SelectingAnAbstractTestClass.test.ts +4 -4
  116. package/src/__tests__/behavioral/upgrading/UpdatingDependencies2.test.ts +2 -2
  117. package/src/__tests__/behavioral/upgrading/UpgradingANodeModule.test.ts +2 -2
  118. package/src/__tests__/behavioral/upgrading/UpgradingASkill5.test.ts +2 -2
  119. package/src/__tests__/behavioral/upgrading/UpgradingWithListeners.test.ts +2 -2
  120. package/src/__tests__/behavioral/views/CreatingASkillView.test.ts +1 -1
  121. package/src/__tests__/behavioral/views/CreatingATheme.test.ts +1 -1
  122. package/src/__tests__/behavioral/watchers/WatchingForChanges.test.ts +35 -35
  123. package/src/__tests__/implementation/ActionExecuter.test.ts +2 -2
  124. package/src/__tests__/implementation/ActionExecuter2.test.ts +1 -1
  125. package/src/__tests__/implementation/ActionExecuter4.test.ts +1 -1
  126. package/src/__tests__/implementation/FeatureInstaller.test.ts +8 -1
  127. package/src/__tests__/implementation/GlobalEmitter.ts +2 -4
  128. package/src/__tests__/implementation/SettingUpANodeModule.test.ts +1 -1
  129. package/src/__tests__/implementation/SkillStore.test.ts +23 -24
  130. package/src/__tests__/implementation/StoreFeature.test.ts +1 -1
  131. package/src/cli.ts +7 -3
  132. package/src/features/AbstractAction.ts +3 -3
  133. package/src/features/AbstractFeature.ts +26 -26
  134. package/src/features/ActionExecuter.ts +9 -9
  135. package/src/features/FeatureInstaller.ts +32 -12
  136. package/src/features/FeatureInstallerFactory.ts +17 -13
  137. package/src/features/OverrideActionDecorator.ts +2 -5
  138. package/src/features/event/actions/ListenAction.ts +1 -0
  139. package/src/features/event/actions/SetRemoteAction.ts +2 -1
  140. package/src/features/event/actions/SyncListenersAction.ts +0 -1
  141. package/src/features/node/NodeFeature.ts +3 -1
  142. package/src/features/skill/SkillFeature.ts +3 -3
  143. package/src/features/skill/stores/SkillStore.ts +18 -11
  144. package/src/features/watch/WatchFeature.ts +1 -1
  145. package/src/interfaces/SpyInterface.ts +10 -0
  146. package/src/stores/AbstractStore.ts +14 -8
  147. package/src/stores/StoreFactory.ts +56 -44
  148. package/src/tests/AbstractCliTest.ts +53 -45
  149. package/src/tests/AbstractSchemaTest.ts +1 -3
  150. package/src/utilities/action.utility.ts +3 -1
  151. package/.DS_Store +0 -0
  152. package/.env +0 -25
  153. package/.eslintcache +0 -1
  154. package/build/.spruce/tmp/cached-skills.json +0 -3
  155. package/junit.xml +0 -7
  156. package/src/.DS_Store +0 -0
  157. package/src/.spruce/tmp/cached-skills.json +0 -3
  158. package/yarn-error.log +0 -12174
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports["default"] = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
11
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
12
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -25,13 +26,10 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
25
26
  var SkillStore = /*#__PURE__*/function (_AbstractStore) {
26
27
  (0, _inherits2["default"])(SkillStore, _AbstractStore);
27
28
  var _super = _createSuper(SkillStore);
28
- function SkillStore() {
29
+ function SkillStore(options) {
29
30
  var _this;
30
31
  (0, _classCallCheck2["default"])(this, SkillStore);
31
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
32
- args[_key] = arguments[_key];
33
- }
34
- _this = _super.call.apply(_super, [this].concat(args));
32
+ _this = _super.call(this, options);
35
33
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "name", 'skill');
36
34
  return _this;
37
35
  }
@@ -45,13 +43,20 @@ var SkillStore = /*#__PURE__*/function (_AbstractStore) {
45
43
  switch (_context.prev = _context.next) {
46
44
  case 0:
47
45
  isRegisteringCurrentSkill = (options === null || options === void 0 ? void 0 : options.isRegisteringCurrentSkill) !== false;
48
- isRegisteringCurrentSkill && this.assertInSkill();
49
- name = values.name, slug = values.slug, description = values.description, isPublished = values.isPublished;
46
+ _context.t0 = isRegisteringCurrentSkill;
47
+ if (!_context.t0) {
48
+ _context.next = 5;
49
+ break;
50
+ }
50
51
  _context.next = 5;
51
- return this.connectToApi();
52
+ return this.assertInSkill();
52
53
  case 5:
53
- client = _context.sent;
54
+ name = values.name, slug = values.slug, description = values.description, isPublished = values.isPublished;
54
55
  _context.next = 8;
56
+ return this.connectToApi();
57
+ case 8:
58
+ client = _context.sent;
59
+ _context.next = 11;
55
60
  return client.emit('register-skill::v2020_12_25', {
56
61
  payload: {
57
62
  name: name,
@@ -60,20 +65,20 @@ var SkillStore = /*#__PURE__*/function (_AbstractStore) {
60
65
  isPublished: isPublished
61
66
  }
62
67
  });
63
- case 8:
68
+ case 11:
64
69
  results = _context.sent;
65
70
  _eventResponseUtil$ge = _spruceEventUtils.eventResponseUtil.getFirstResponseOrThrow(results), skill = _eventResponseUtil$ge.skill;
66
71
  if (!isRegisteringCurrentSkill) {
67
- _context.next = 14;
72
+ _context.next = 17;
68
73
  break;
69
74
  }
70
- _context.next = 13;
75
+ _context.next = 16;
71
76
  return this.setCurrentSkillsNamespace(skill.slug);
72
- case 13:
77
+ case 16:
73
78
  this.Service('auth').updateCurrentSkill(skill);
74
- case 14:
79
+ case 17:
75
80
  return _context.abrupt("return", skill);
76
- case 15:
81
+ case 18:
77
82
  case "end":
78
83
  return _context.stop();
79
84
  }
@@ -87,69 +92,90 @@ var SkillStore = /*#__PURE__*/function (_AbstractStore) {
87
92
  }()
88
93
  }, {
89
94
  key: "assertInSkill",
90
- value: function assertInSkill() {
91
- var isInstalled = this.Service('settings').isMarkedAsInstalled('skill');
92
- if (!isInstalled) {
93
- throw new _SpruceError["default"]({
94
- code: 'DIRECTORY_NOT_SKILL'
95
- });
95
+ value: function () {
96
+ var _assertInSkill = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
97
+ var isInstalled;
98
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
99
+ while (1) {
100
+ switch (_context2.prev = _context2.next) {
101
+ case 0:
102
+ isInstalled = this.Service('settings').isMarkedAsInstalled('skill');
103
+ if (isInstalled) {
104
+ _context2.next = 3;
105
+ break;
106
+ }
107
+ throw new _SpruceError["default"]({
108
+ code: 'DIRECTORY_NOT_SKILL'
109
+ });
110
+ case 3:
111
+ case "end":
112
+ return _context2.stop();
113
+ }
114
+ }
115
+ }, _callee2, this);
116
+ }));
117
+ function assertInSkill() {
118
+ return _assertInSkill.apply(this, arguments);
96
119
  }
97
- }
120
+ return assertInSkill;
121
+ }()
98
122
  }, {
99
123
  key: "loadCurrentSkill",
100
124
  value: function () {
101
- var _loadCurrentSkill = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
125
+ var _loadCurrentSkill = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
102
126
  var currentSkill, client, response, _eventResponseUtil$ge2, skill;
103
- return _regenerator["default"].wrap(function _callee2$(_context2) {
127
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
104
128
  while (1) {
105
- switch (_context2.prev = _context2.next) {
129
+ switch (_context3.prev = _context3.next) {
106
130
  case 0:
107
131
  if (!SkillStore.currentSkill) {
108
- _context2.next = 2;
132
+ _context3.next = 2;
109
133
  break;
110
134
  }
111
- return _context2.abrupt("return", SkillStore.currentSkill);
135
+ return _context3.abrupt("return", SkillStore.currentSkill);
112
136
  case 2:
113
- this.assertInSkill();
137
+ _context3.next = 4;
138
+ return this.assertInSkill();
139
+ case 4:
114
140
  currentSkill = this.Service('auth').getCurrentSkill();
115
141
  if (!currentSkill) {
116
- _context2.next = 14;
142
+ _context3.next = 15;
117
143
  break;
118
144
  }
119
- _context2.next = 7;
145
+ _context3.next = 8;
120
146
  return this.connectToApi({
121
147
  shouldAuthAsCurrentSkill: true
122
148
  });
123
- case 7:
124
- client = _context2.sent;
125
- _context2.next = 10;
149
+ case 8:
150
+ client = _context3.sent;
151
+ _context3.next = 11;
126
152
  return client.emit('get-skill::v2020_12_25', {
127
153
  target: {
128
154
  skillId: currentSkill.id
129
155
  }
130
156
  });
131
- case 10:
132
- response = _context2.sent;
157
+ case 11:
158
+ response = _context3.sent;
133
159
  _eventResponseUtil$ge2 = _spruceEventUtils.eventResponseUtil.getFirstResponseOrThrow(response), skill = _eventResponseUtil$ge2.skill;
134
160
  SkillStore.currentSkill = _objectSpread(_objectSpread({}, skill), {}, {
135
161
  namespacePascal: _spruceSkillUtils.namesUtil.toPascal(skill.slug),
136
162
  isRegistered: true,
137
163
  apiKey: currentSkill.apiKey
138
164
  });
139
- return _context2.abrupt("return", SkillStore.currentSkill);
140
- case 14:
141
- return _context2.abrupt("return", {
165
+ return _context3.abrupt("return", SkillStore.currentSkill);
166
+ case 15:
167
+ return _context3.abrupt("return", {
142
168
  name: this.getNamespaceFromPkg(),
143
169
  namespacePascal: this.getEventNamespaceForNotRegistered(),
144
170
  description: this.getSkillDescriptionFromPkg(),
145
171
  isRegistered: false
146
172
  });
147
- case 15:
173
+ case 16:
148
174
  case "end":
149
- return _context2.stop();
175
+ return _context3.stop();
150
176
  }
151
177
  }
152
- }, _callee2, this);
178
+ }, _callee3, this);
153
179
  }));
154
180
  function loadCurrentSkill() {
155
181
  return _loadCurrentSkill.apply(this, arguments);
@@ -159,23 +185,23 @@ var SkillStore = /*#__PURE__*/function (_AbstractStore) {
159
185
  }, {
160
186
  key: "isCurrentSkillRegistered",
161
187
  value: function () {
162
- var _isCurrentSkillRegistered = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
188
+ var _isCurrentSkillRegistered = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
163
189
  var skill;
164
- return _regenerator["default"].wrap(function _callee3$(_context3) {
190
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
165
191
  while (1) {
166
- switch (_context3.prev = _context3.next) {
192
+ switch (_context4.prev = _context4.next) {
167
193
  case 0:
168
- _context3.next = 2;
194
+ _context4.next = 2;
169
195
  return this.loadCurrentSkill();
170
196
  case 2:
171
- skill = _context3.sent;
172
- return _context3.abrupt("return", skill.isRegistered);
197
+ skill = _context4.sent;
198
+ return _context4.abrupt("return", skill.isRegistered);
173
199
  case 4:
174
200
  case "end":
175
- return _context3.stop();
201
+ return _context4.stop();
176
202
  }
177
203
  }
178
- }, _callee3, this);
204
+ }, _callee4, this);
179
205
  }));
180
206
  function isCurrentSkillRegistered() {
181
207
  return _isCurrentSkillRegistered.apply(this, arguments);
@@ -195,30 +221,30 @@ var SkillStore = /*#__PURE__*/function (_AbstractStore) {
195
221
  }, {
196
222
  key: "loadCurrentSkillsNamespace",
197
223
  value: function () {
198
- var _loadCurrentSkillsNamespace = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
224
+ var _loadCurrentSkillsNamespace = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() {
199
225
  var fallback, _current$slug, current;
200
- return _regenerator["default"].wrap(function _callee4$(_context4) {
226
+ return _regenerator["default"].wrap(function _callee5$(_context5) {
201
227
  while (1) {
202
- switch (_context4.prev = _context4.next) {
228
+ switch (_context5.prev = _context5.next) {
203
229
  case 0:
204
230
  fallback = _spruceSkillUtils.namesUtil.toPascal(this.getNamespaceFromPkg());
205
231
  if (!this.Service('auth').getCurrentSkill()) {
206
- _context4.next = 6;
232
+ _context5.next = 6;
207
233
  break;
208
234
  }
209
- _context4.next = 4;
235
+ _context5.next = 4;
210
236
  return this.loadCurrentSkill();
211
237
  case 4:
212
- current = _context4.sent;
213
- return _context4.abrupt("return", _spruceSkillUtils.namesUtil.toPascal((_current$slug = current.slug) !== null && _current$slug !== void 0 ? _current$slug : fallback));
238
+ current = _context5.sent;
239
+ return _context5.abrupt("return", _spruceSkillUtils.namesUtil.toPascal((_current$slug = current.slug) !== null && _current$slug !== void 0 ? _current$slug : fallback));
214
240
  case 6:
215
- return _context4.abrupt("return", fallback);
241
+ return _context5.abrupt("return", fallback);
216
242
  case 7:
217
243
  case "end":
218
- return _context4.stop();
244
+ return _context5.stop();
219
245
  }
220
246
  }
221
- }, _callee4, this);
247
+ }, _callee5, this);
222
248
  }));
223
249
  function loadCurrentSkillsNamespace() {
224
250
  return _loadCurrentSkillsNamespace.apply(this, arguments);
@@ -228,26 +254,26 @@ var SkillStore = /*#__PURE__*/function (_AbstractStore) {
228
254
  }, {
229
255
  key: "setCurrentSkillsNamespace",
230
256
  value: function () {
231
- var _setCurrentSkillsNamespace = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(namespace) {
257
+ var _setCurrentSkillsNamespace = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(namespace) {
232
258
  var isRegistered;
233
- return _regenerator["default"].wrap(function _callee5$(_context5) {
259
+ return _regenerator["default"].wrap(function _callee6$(_context6) {
234
260
  while (1) {
235
- switch (_context5.prev = _context5.next) {
261
+ switch (_context6.prev = _context6.next) {
236
262
  case 0:
237
263
  isRegistered = false;
238
- _context5.prev = 1;
239
- _context5.next = 4;
264
+ _context6.prev = 1;
265
+ _context6.next = 4;
240
266
  return this.isCurrentSkillRegistered();
241
267
  case 4:
242
- isRegistered = _context5.sent;
243
- _context5.next = 9;
268
+ isRegistered = _context6.sent;
269
+ _context6.next = 9;
244
270
  break;
245
271
  case 7:
246
- _context5.prev = 7;
247
- _context5.t0 = _context5["catch"](1);
272
+ _context6.prev = 7;
273
+ _context6.t0 = _context6["catch"](1);
248
274
  case 9:
249
275
  if (!isRegistered) {
250
- _context5.next = 11;
276
+ _context6.next = 11;
251
277
  break;
252
278
  }
253
279
  throw new _SpruceError["default"]({
@@ -258,10 +284,10 @@ var SkillStore = /*#__PURE__*/function (_AbstractStore) {
258
284
  this.Service('auth').updateCurrentSkillNamespace(namespace);
259
285
  case 12:
260
286
  case "end":
261
- return _context5.stop();
287
+ return _context6.stop();
262
288
  }
263
289
  }
264
- }, _callee5, this, [[1, 7]]);
290
+ }, _callee6, this, [[1, 7]]);
265
291
  }));
266
292
  function setCurrentSkillsNamespace(_x3) {
267
293
  return _setCurrentSkillsNamespace.apply(this, arguments);
@@ -282,25 +308,25 @@ var SkillStore = /*#__PURE__*/function (_AbstractStore) {
282
308
  }, {
283
309
  key: "unregisterSkill",
284
310
  value: function () {
285
- var _unregisterSkill = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(skillId) {
311
+ var _unregisterSkill = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(skillId) {
286
312
  var _SkillStore$currentSk;
287
313
  var client, response;
288
- return _regenerator["default"].wrap(function _callee6$(_context6) {
314
+ return _regenerator["default"].wrap(function _callee7$(_context7) {
289
315
  while (1) {
290
- switch (_context6.prev = _context6.next) {
316
+ switch (_context7.prev = _context7.next) {
291
317
  case 0:
292
- _context6.next = 2;
318
+ _context7.next = 2;
293
319
  return this.connectToApi();
294
320
  case 2:
295
- client = _context6.sent;
296
- _context6.next = 5;
321
+ client = _context7.sent;
322
+ _context7.next = 5;
297
323
  return client.emit('unregister-skill::v2020_12_25', {
298
324
  target: {
299
325
  skillId: skillId
300
326
  }
301
327
  });
302
328
  case 5:
303
- response = _context6.sent;
329
+ response = _context7.sent;
304
330
  _spruceEventUtils.eventResponseUtil.getFirstResponseOrThrow(response);
305
331
  if (((_SkillStore$currentSk = SkillStore.currentSkill) === null || _SkillStore$currentSk === void 0 ? void 0 : _SkillStore$currentSk.id) === skillId) {
306
332
  SkillStore.currentSkill = undefined;
@@ -308,10 +334,10 @@ var SkillStore = /*#__PURE__*/function (_AbstractStore) {
308
334
  }
309
335
  case 8:
310
336
  case "end":
311
- return _context6.stop();
337
+ return _context7.stop();
312
338
  }
313
339
  }
314
- }, _callee6, this);
340
+ }, _callee7, this);
315
341
  }));
316
342
  function unregisterSkill(_x4) {
317
343
  return _unregisterSkill.apply(this, arguments);
@@ -321,20 +347,20 @@ var SkillStore = /*#__PURE__*/function (_AbstractStore) {
321
347
  }, {
322
348
  key: "fetchMySkills",
323
349
  value: function () {
324
- var _fetchMySkills = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7() {
325
- return _regenerator["default"].wrap(function _callee7$(_context7) {
350
+ var _fetchMySkills = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() {
351
+ return _regenerator["default"].wrap(function _callee8$(_context8) {
326
352
  while (1) {
327
- switch (_context7.prev = _context7.next) {
353
+ switch (_context8.prev = _context8.next) {
328
354
  case 0:
329
- return _context7.abrupt("return", this.fetchAllSkills({
355
+ return _context8.abrupt("return", this.fetchAllSkills({
330
356
  shouldOnlyShowMine: true
331
357
  }));
332
358
  case 1:
333
359
  case "end":
334
- return _context7.stop();
360
+ return _context8.stop();
335
361
  }
336
362
  }
337
- }, _callee7, this);
363
+ }, _callee8, this);
338
364
  }));
339
365
  function fetchMySkills() {
340
366
  return _fetchMySkills.apply(this, arguments);
@@ -344,30 +370,31 @@ var SkillStore = /*#__PURE__*/function (_AbstractStore) {
344
370
  }, {
345
371
  key: "fetchAllSkills",
346
372
  value: function () {
347
- var _fetchAllSkills = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(query) {
348
- var client, response, _eventResponseUtil$ge3, skills;
349
- return _regenerator["default"].wrap(function _callee8$(_context8) {
373
+ var _fetchAllSkills = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(query) {
374
+ var client, _yield$client$emitAnd, _yield$client$emitAnd2, skills;
375
+ return _regenerator["default"].wrap(function _callee9$(_context9) {
350
376
  while (1) {
351
- switch (_context8.prev = _context8.next) {
377
+ switch (_context9.prev = _context9.next) {
352
378
  case 0:
353
- _context8.next = 2;
379
+ _context9.next = 2;
354
380
  return this.connectToApi();
355
381
  case 2:
356
- client = _context8.sent;
357
- _context8.next = 5;
358
- return client.emit('list-skills::v2020_12_25', {
382
+ client = _context9.sent;
383
+ _context9.next = 5;
384
+ return client.emitAndFlattenResponses('list-skills::v2020_12_25', {
359
385
  payload: _objectSpread({}, query)
360
386
  });
361
387
  case 5:
362
- response = _context8.sent;
363
- _eventResponseUtil$ge3 = _spruceEventUtils.eventResponseUtil.getFirstResponseOrThrow(response), skills = _eventResponseUtil$ge3.skills;
364
- return _context8.abrupt("return", skills);
365
- case 8:
388
+ _yield$client$emitAnd = _context9.sent;
389
+ _yield$client$emitAnd2 = (0, _slicedToArray2["default"])(_yield$client$emitAnd, 1);
390
+ skills = _yield$client$emitAnd2[0].skills;
391
+ return _context9.abrupt("return", skills);
392
+ case 9:
366
393
  case "end":
367
- return _context8.stop();
394
+ return _context9.stop();
368
395
  }
369
396
  }
370
- }, _callee8, this);
397
+ }, _callee9, this);
371
398
  }));
372
399
  function fetchAllSkills(_x5) {
373
400
  return _fetchAllSkills.apply(this, arguments);
@@ -1 +1 @@
1
- {"version":3,"file":"SkillStore.js","names":["SkillStore","values","options","isRegisteringCurrentSkill","assertInSkill","name","slug","description","isPublished","connectToApi","client","emit","payload","results","eventResponseUtil","getFirstResponseOrThrow","skill","setCurrentSkillsNamespace","Service","updateCurrentSkill","isInstalled","isMarkedAsInstalled","SpruceError","code","currentSkill","getCurrentSkill","shouldAuthAsCurrentSkill","target","skillId","id","response","namespacePascal","namesUtil","toPascal","isRegistered","apiKey","getNamespaceFromPkg","getEventNamespaceForNotRegistered","getSkillDescriptionFromPkg","loadCurrentSkill","pkg","nameFromPackage","get","Error","fallback","current","namespace","isCurrentSkillRegistered","friendlyMessage","updateCurrentSkillNamespace","undefined","logoutCurrentSkill","fetchAllSkills","shouldOnlyShowMine","query","skills","AbstractStore"],"sources":["../../../../src/features/skill/stores/SkillStore.ts"],"sourcesContent":["import { eventResponseUtil } from '@sprucelabs/spruce-event-utils'\nimport { namesUtil } from '@sprucelabs/spruce-skill-utils'\nimport SpruceError from '../../../errors/SpruceError'\nimport AbstractStore from '../../../stores/AbstractStore'\nimport { CurrentSkill, RegisteredSkill } from '../../../types/cli.types'\n\nexport default class SkillStore extends AbstractStore {\n\tpublic readonly name = 'skill'\n\tprivate static currentSkill?: CurrentSkill\n\n\tpublic static clearCurrentSkill() {\n\t\tthis.currentSkill = undefined\n\t}\n\n\tpublic async register(\n\t\tvalues: CreateSkill,\n\t\toptions?: RegisterSkillOptions\n\t): Promise<RegisteredSkill> {\n\t\tconst isRegisteringCurrentSkill =\n\t\t\toptions?.isRegisteringCurrentSkill !== false\n\n\t\tisRegisteringCurrentSkill && this.assertInSkill()\n\n\t\tconst { name, slug, description, isPublished } = values\n\t\tconst client = await this.connectToApi()\n\n\t\tconst results = await client.emit('register-skill::v2020_12_25', {\n\t\t\tpayload: {\n\t\t\t\tname,\n\t\t\t\tslug,\n\t\t\t\tdescription,\n\t\t\t\tisPublished,\n\t\t\t},\n\t\t})\n\n\t\tconst { skill } = eventResponseUtil.getFirstResponseOrThrow(results)\n\n\t\tif (isRegisteringCurrentSkill) {\n\t\t\tawait this.setCurrentSkillsNamespace(skill.slug)\n\t\t\tthis.Service('auth').updateCurrentSkill(skill)\n\t\t}\n\n\t\treturn skill\n\t}\n\n\tprivate assertInSkill() {\n\t\tconst isInstalled = this.Service('settings').isMarkedAsInstalled('skill')\n\n\t\tif (!isInstalled) {\n\t\t\tthrow new SpruceError({ code: 'DIRECTORY_NOT_SKILL' })\n\t\t}\n\t}\n\n\tpublic async loadCurrentSkill(): Promise<CurrentSkill> {\n\t\tif (SkillStore.currentSkill) {\n\t\t\treturn SkillStore.currentSkill\n\t\t}\n\n\t\tthis.assertInSkill()\n\n\t\tconst currentSkill = this.Service('auth').getCurrentSkill()\n\n\t\tif (currentSkill) {\n\t\t\tconst client = await this.connectToApi({ shouldAuthAsCurrentSkill: true })\n\n\t\t\tconst response = await client.emit('get-skill::v2020_12_25', {\n\t\t\t\ttarget: {\n\t\t\t\t\tskillId: currentSkill.id,\n\t\t\t\t},\n\t\t\t})\n\n\t\t\tconst { skill } = eventResponseUtil.getFirstResponseOrThrow(response)\n\n\t\t\tSkillStore.currentSkill = {\n\t\t\t\t...skill,\n\t\t\t\tnamespacePascal: namesUtil.toPascal(skill.slug),\n\t\t\t\tisRegistered: true,\n\t\t\t\tapiKey: currentSkill.apiKey,\n\t\t\t}\n\n\t\t\treturn SkillStore.currentSkill as CurrentSkill\n\t\t}\n\n\t\treturn {\n\t\t\tname: this.getNamespaceFromPkg(),\n\t\t\tnamespacePascal: this.getEventNamespaceForNotRegistered(),\n\t\t\tdescription: this.getSkillDescriptionFromPkg(),\n\t\t\tisRegistered: false,\n\t\t}\n\t}\n\n\tpublic async isCurrentSkillRegistered() {\n\t\tconst skill = await this.loadCurrentSkill()\n\t\treturn skill.isRegistered\n\t}\n\n\tprivate getNamespaceFromPkg() {\n\t\tconst pkg = this.Service('pkg')\n\t\tconst nameFromPackage = pkg.get('skill.namespace')\n\t\tif (!nameFromPackage) {\n\t\t\tthrow new Error(\n\t\t\t\t'You need need to set skill.namespace in the package.json'\n\t\t\t)\n\t\t}\n\t\treturn nameFromPackage\n\t}\n\n\tpublic async loadCurrentSkillsNamespace() {\n\t\tconst fallback = namesUtil.toPascal(this.getNamespaceFromPkg())\n\n\t\tif (this.Service('auth').getCurrentSkill()) {\n\t\t\tconst current = await this.loadCurrentSkill()\n\t\t\treturn namesUtil.toPascal(current.slug ?? fallback)\n\t\t}\n\n\t\treturn fallback\n\t}\n\n\tpublic async setCurrentSkillsNamespace(namespace: string) {\n\t\tlet isRegistered = false\n\t\ttry {\n\t\t\tisRegistered = await this.isCurrentSkillRegistered()\n\t\t\t// eslint-disable-next-line no-empty\n\t\t} catch {}\n\n\t\tif (isRegistered) {\n\t\t\tthrow new SpruceError({\n\t\t\t\tcode: 'GENERIC',\n\t\t\t\tfriendlyMessage: `You can't set the namespace of a skill that is registered.`,\n\t\t\t})\n\t\t}\n\n\t\tthis.Service('auth').updateCurrentSkillNamespace(namespace)\n\t}\n\n\tprivate getEventNamespaceForNotRegistered() {\n\t\treturn namesUtil.toPascal(this.getNamespaceFromPkg())\n\t}\n\n\tprivate getSkillDescriptionFromPkg() {\n\t\tconst pkg = this.Service('pkg')\n\t\treturn pkg.get('description')\n\t}\n\n\tpublic async unregisterSkill(skillId: string) {\n\t\tconst client = await this.connectToApi()\n\n\t\tconst response = await client.emit('unregister-skill::v2020_12_25', {\n\t\t\ttarget: {\n\t\t\t\tskillId,\n\t\t\t},\n\t\t})\n\n\t\teventResponseUtil.getFirstResponseOrThrow(response)\n\n\t\tif (SkillStore.currentSkill?.id === skillId) {\n\t\t\tSkillStore.currentSkill = undefined\n\t\t\tthis.Service('auth').logoutCurrentSkill()\n\t\t}\n\t}\n\n\tpublic async fetchMySkills() {\n\t\treturn this.fetchAllSkills({ shouldOnlyShowMine: true })\n\t}\n\n\tpublic async fetchAllSkills(query?: {\n\t\tshouldOnlyShowMine?: boolean\n\t\tnamespaces?: string[]\n\t}) {\n\t\tconst client = await this.connectToApi()\n\n\t\tconst response = await client.emit('list-skills::v2020_12_25', {\n\t\t\tpayload: {\n\t\t\t\t...query,\n\t\t\t},\n\t\t})\n\n\t\tconst { skills } = eventResponseUtil.getFirstResponseOrThrow(response)\n\n\t\treturn skills\n\t}\n}\n\nexport interface CreateSkill {\n\tname: string\n\tslug?: string\n\tdescription?: string\n\tisPublished?: boolean\n}\n\nexport interface RegisterSkillOptions {\n\tisRegisteringCurrentSkill?: boolean\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AAAyD;AAAA;AAAA;AAAA;AAAA,IAGpCA,UAAU;EAAA;EAAA;EAAA;IAAA;IAAA;IAAA;MAAA;IAAA;IAAA;IAAA,yFACP,OAAO;IAAA;EAAA;EAAA;IAAA;IAAA;MAAA,8FAO9B,iBACCC,MAAmB,EACnBC,OAA8B;QAAA;QAAA;UAAA;YAAA;cAAA;gBAExBC,yBAAyB,GAC9B,CAAAD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,yBAAyB,MAAK,KAAK;gBAE7CA,yBAAy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AA;IAAA;EAAA;IAAA;IAAA;MAAA,oGAED,kBAA4BC,KAG3B;QAAA;QAAA;UAAA;YAAA;cAAA;gBAAA;gBAAA,OACqB,IAAI,CAAC7C,YAAY,EAAE;cAAA;gBAAlCC,MAAM;gBAAA;gBAAA,OAEWA,MAAM,CAACC,IAAI,CAAC,0BAA0B,EAAE;kBAC9DC,OAAO,oBACH0C,KAAK;gBAEV,CAAC,CAAC;cAAA;gBAJIxB,QAAQ;gBAAA,yBAMKhB,mCAAiB,CAACC,uBAAuB,CAACe,QAAQ,CAAC,EAA9DyB,MAAM,0BAANA,MAAM;gBAAA,kCAEPA,MAAM;cAAA;cAAA;gBAAA;YAAA;UAAA;QAAA;MAAA,CACb;MAAA;QAAA;MAAA;MAAA;IAAA;EAAA;IAAA;IAAA,OA1KD,6BAAkC;MACjC,IAAI,CAAC/B,YAAY,GAAG0B,SAAS;IAC9B;EAAC;EAAA;AAAA,EANsCM,0BAAa;AAAA;AAAA,iCAAhCxD,UAAU"}
1
+ {"version":3,"file":"SkillStore.js","names":["SkillStore","options","values","isRegisteringCurrentSkill","assertInSkill","name","slug","description","isPublished","connectToApi","client","emit","payload","results","eventResponseUtil","getFirstResponseOrThrow","skill","setCurrentSkillsNamespace","Service","updateCurrentSkill","isInstalled","isMarkedAsInstalled","SpruceError","code","currentSkill","getCurrentSkill","shouldAuthAsCurrentSkill","target","skillId","id","response","namespacePascal","namesUtil","toPascal","isRegistered","apiKey","getNamespaceFromPkg","getEventNamespaceForNotRegistered","getSkillDescriptionFromPkg","loadCurrentSkill","pkg","nameFromPackage","get","Error","fallback","current","namespace","isCurrentSkillRegistered","friendlyMessage","updateCurrentSkillNamespace","undefined","logoutCurrentSkill","fetchAllSkills","shouldOnlyShowMine","query","emitAndFlattenResponses","skills","AbstractStore"],"sources":["../../../../src/features/skill/stores/SkillStore.ts"],"sourcesContent":["import { eventResponseUtil } from '@sprucelabs/spruce-event-utils'\nimport { namesUtil } from '@sprucelabs/spruce-skill-utils'\nimport SpruceError from '../../../errors/SpruceError'\nimport AbstractStore, { StoreOptions } from '../../../stores/AbstractStore'\nimport { CurrentSkill, RegisteredSkill } from '../../../types/cli.types'\n\nexport default class SkillStore extends AbstractStore {\n\tpublic readonly name = 'skill'\n\tprivate static currentSkill?: CurrentSkill\n\n\tpublic constructor(options: StoreOptions<SkillStoreOptions>) {\n\t\tsuper(options)\n\t}\n\n\tpublic static clearCurrentSkill() {\n\t\tthis.currentSkill = undefined\n\t}\n\n\tpublic async register(\n\t\tvalues: CreateSkill,\n\t\toptions?: RegisterSkillOptions\n\t): Promise<RegisteredSkill> {\n\t\tconst isRegisteringCurrentSkill =\n\t\t\toptions?.isRegisteringCurrentSkill !== false\n\n\t\tisRegisteringCurrentSkill && (await this.assertInSkill())\n\n\t\tconst { name, slug, description, isPublished } = values\n\t\tconst client = await this.connectToApi()\n\n\t\tconst results = await client.emit('register-skill::v2020_12_25', {\n\t\t\tpayload: {\n\t\t\t\tname,\n\t\t\t\tslug,\n\t\t\t\tdescription,\n\t\t\t\tisPublished,\n\t\t\t},\n\t\t})\n\n\t\tconst { skill } = eventResponseUtil.getFirstResponseOrThrow(results)\n\n\t\tif (isRegisteringCurrentSkill) {\n\t\t\tawait this.setCurrentSkillsNamespace(skill.slug)\n\t\t\tthis.Service('auth').updateCurrentSkill(skill)\n\t\t}\n\n\t\treturn skill\n\t}\n\n\tprivate async assertInSkill() {\n\t\tconst isInstalled = this.Service('settings').isMarkedAsInstalled('skill')\n\n\t\tif (!isInstalled) {\n\t\t\tthrow new SpruceError({ code: 'DIRECTORY_NOT_SKILL' })\n\t\t}\n\t}\n\n\tpublic async loadCurrentSkill(): Promise<CurrentSkill> {\n\t\tif (SkillStore.currentSkill) {\n\t\t\treturn SkillStore.currentSkill\n\t\t}\n\n\t\tawait this.assertInSkill()\n\n\t\tconst currentSkill = this.Service('auth').getCurrentSkill()\n\n\t\tif (currentSkill) {\n\t\t\tconst client = await this.connectToApi({ shouldAuthAsCurrentSkill: true })\n\n\t\t\tconst response = await client.emit('get-skill::v2020_12_25', {\n\t\t\t\ttarget: {\n\t\t\t\t\tskillId: currentSkill.id,\n\t\t\t\t},\n\t\t\t})\n\n\t\t\tconst { skill } = eventResponseUtil.getFirstResponseOrThrow(response)\n\n\t\t\tSkillStore.currentSkill = {\n\t\t\t\t...skill,\n\t\t\t\tnamespacePascal: namesUtil.toPascal(skill.slug),\n\t\t\t\tisRegistered: true,\n\t\t\t\tapiKey: currentSkill.apiKey,\n\t\t\t}\n\n\t\t\treturn SkillStore.currentSkill as CurrentSkill\n\t\t}\n\n\t\treturn {\n\t\t\tname: this.getNamespaceFromPkg(),\n\t\t\tnamespacePascal: this.getEventNamespaceForNotRegistered(),\n\t\t\tdescription: this.getSkillDescriptionFromPkg(),\n\t\t\tisRegistered: false,\n\t\t}\n\t}\n\n\tpublic async isCurrentSkillRegistered() {\n\t\tconst skill = await this.loadCurrentSkill()\n\t\treturn skill.isRegistered\n\t}\n\n\tprivate getNamespaceFromPkg() {\n\t\tconst pkg = this.Service('pkg')\n\t\tconst nameFromPackage = pkg.get('skill.namespace')\n\t\tif (!nameFromPackage) {\n\t\t\tthrow new Error(\n\t\t\t\t'You need need to set skill.namespace in the package.json'\n\t\t\t)\n\t\t}\n\t\treturn nameFromPackage\n\t}\n\n\tpublic async loadCurrentSkillsNamespace() {\n\t\tconst fallback = namesUtil.toPascal(this.getNamespaceFromPkg())\n\n\t\tif (this.Service('auth').getCurrentSkill()) {\n\t\t\tconst current = await this.loadCurrentSkill()\n\t\t\treturn namesUtil.toPascal(current.slug ?? fallback)\n\t\t}\n\n\t\treturn fallback\n\t}\n\n\tpublic async setCurrentSkillsNamespace(namespace: string) {\n\t\tlet isRegistered = false\n\t\ttry {\n\t\t\tisRegistered = await this.isCurrentSkillRegistered()\n\t\t\t// eslint-disable-next-line no-empty\n\t\t} catch {}\n\n\t\tif (isRegistered) {\n\t\t\tthrow new SpruceError({\n\t\t\t\tcode: 'GENERIC',\n\t\t\t\tfriendlyMessage: `You can't set the namespace of a skill that is registered.`,\n\t\t\t})\n\t\t}\n\n\t\tthis.Service('auth').updateCurrentSkillNamespace(namespace)\n\t}\n\n\tprivate getEventNamespaceForNotRegistered() {\n\t\treturn namesUtil.toPascal(this.getNamespaceFromPkg())\n\t}\n\n\tprivate getSkillDescriptionFromPkg() {\n\t\tconst pkg = this.Service('pkg')\n\t\treturn pkg.get('description')\n\t}\n\n\tpublic async unregisterSkill(skillId: string) {\n\t\tconst client = await this.connectToApi()\n\n\t\tconst response = await client.emit('unregister-skill::v2020_12_25', {\n\t\t\ttarget: {\n\t\t\t\tskillId,\n\t\t\t},\n\t\t})\n\n\t\teventResponseUtil.getFirstResponseOrThrow(response)\n\n\t\tif (SkillStore.currentSkill?.id === skillId) {\n\t\t\tSkillStore.currentSkill = undefined\n\t\t\tthis.Service('auth').logoutCurrentSkill()\n\t\t}\n\t}\n\n\tpublic async fetchMySkills() {\n\t\treturn this.fetchAllSkills({ shouldOnlyShowMine: true })\n\t}\n\n\tpublic async fetchAllSkills(query?: {\n\t\tshouldOnlyShowMine?: boolean\n\t\tnamespaces?: string[]\n\t}) {\n\t\tconst client = await this.connectToApi()\n\n\t\tconst [{ skills }] = await client.emitAndFlattenResponses(\n\t\t\t'list-skills::v2020_12_25',\n\t\t\t{\n\t\t\t\tpayload: {\n\t\t\t\t\t...query,\n\t\t\t\t},\n\t\t\t}\n\t\t)\n\n\t\treturn skills\n\t}\n}\n\nexport interface CreateSkill {\n\tname: string\n\tslug?: string\n\tdescription?: string\n\tisPublished?: boolean\n}\n\nexport interface RegisterSkillOptions {\n\tisRegisteringCurrentSkill?: boolean\n}\n\nexport interface SkillStoreOptions {}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AAA2E;AAAA;AAAA;AAAA;AAAA,IAGtDA,UAAU;EAAA;EAAA;EAI9B,oBAAmBC,OAAwC,EAAE;IAAA;IAAA;IAC5D,0BAAMA,OAAO;IAAC,yFAJQ,OA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5C5B,UAAU,CAACwB,YAAY,GAAG0B,SAAS;kBACnC,IAAI,CAAChC,OAAO,CAAC,MAAM,CAAC,CAACiC,kBAAkB,EAAE;gBAC1C;cAAC;cAAA;gBAAA;YAAA;UAAA;QAAA;MAAA,CACD;MAAA;QAAA;MAAA;MAAA;IAAA;EAAA;IAAA;IAAA;MAAA,mGAED;QAAA;UAAA;YAAA;cAAA;gBAAA,kCACQ,IAAI,CAACC,cAAc,CAAC;kBAAEC,kBAAkB,EAAE;gBAAK,CAAC,CAAC;cAAA;cAAA;gBAAA;YAAA;UAAA;QAAA;MAAA,CACxD;MAAA;QAAA;MAAA;MAAA;IAAA;EAAA;IAAA;IAAA;MAAA,oGAED,kBAA4BC,KAG3B;QAAA;QAAA;UAAA;YAAA;cAAA;gBAAA;gBAAA,OACqB,IAAI,CAAC7C,YAAY,EAAE;cAAA;gBAAlCC,MAAM;gBAAA;gBAAA,OAEeA,MAAM,CAAC6C,uBAAuB,CACxD,0BAA0B,EAC1B;kBACC3C,OAAO,oBACH0C,KAAK;gBAEV,CAAC,CACD;cAAA;gBAAA;gBAAA;gBAPQE,MAAM,6BAANA,MAAM;gBAAA,kCASRA,MAAM;cAAA;cAAA;gBAAA;YAAA;UAAA;QAAA;MAAA,CACb;MAAA;QAAA;MAAA;MAAA;IAAA;EAAA;IAAA;IAAA,OA3KD,6BAAkC;MACjC,IAAI,CAAChC,YAAY,GAAG0B,SAAS;IAC9B;EAAC;EAAA;AAAA,EAVsCO,0BAAa;AAAA;AAAA,iCAAhCzD,UAAU"}
@@ -164,7 +164,7 @@ var WatchFeature = /*#__PURE__*/function (_AbstractFeature) {
164
164
  changes = this.changesSinceLastChange;
165
165
  this.changesSinceLastChange = [];
166
166
  _context5.next = 4;
167
- return this.emitter.emit('watcher.did-detect-change', {
167
+ return this.emitter.emitAndFlattenResponses('watcher.did-detect-change', {
168
168
  changes: changes
169
169
  });
170
170
  case 4:
@@ -1 +1 @@
1
- {"version":3,"file":"WatchFeature.js","names":["WatchFeature","_isWatching","options","watchDir","diskUtil","resolvePath","cwd","sourceDir","watcher","chokidar","watch","ignoreInitial","startsWith","on","action","path","changesSinceLastChange","push","schemaId","mapChokidarActionToSchemaId","version","values","mapChokidarActionToGeneratedAction","name","pathUtil","basename","timeoutId","clearTimeout","setTimeout","fireChange","delay","search","map","add","addDir","change","unlink","unlinkDir","changes","emitter","emit","close","AbstractFeature"],"sources":["../../../src/features/watch/WatchFeature.ts"],"sourcesContent":["import pathUtil from 'path'\nimport { diskUtil } from '@sprucelabs/spruce-skill-utils'\nimport chokidar from 'chokidar'\nimport { GeneratedFile, GeneratedFileOrDir } from '../../types/cli.types'\nimport AbstractFeature from '../AbstractFeature'\nimport { FeatureCode } from '../features.types'\n\ntype ChokidarAction = 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir'\n\ndeclare module '../../features/features.types' {\n\tinterface FeatureMap {\n\t\twatch: WatchFeature\n\t}\n\n\tinterface FeatureOptionsMap {\n\t\twatch: undefined\n\t}\n}\n\nexport default class WatchFeature extends AbstractFeature {\n\tpublic description =\n\t\t'Watches for changes on the file system and emits app level events for other features to respond to.'\n\tpublic code: FeatureCode = 'watch'\n\tpublic nameReadable = 'Watch'\n\n\tprivate _isWatching = false\n\tprivate watcher?: chokidar.FSWatcher\n\t// eslint-disable-next-line no-undef\n\tprivate timeoutId?: NodeJS.Timeout\n\tprivate changesSinceLastChange: GeneratedFileOrDir[] = []\n\n\tpublic async isWatching() {\n\t\treturn this._isWatching\n\t}\n\n\tpublic async startWatching(options?: { delay?: number; sourceDir?: string }) {\n\t\tthis._isWatching = true\n\n\t\tconst watchDir = diskUtil.resolvePath(this.cwd, options?.sourceDir ?? '')\n\n\t\tthis.watcher = chokidar.watch(watchDir, {\n\t\t\tignoreInitial: true,\n\t\t})\n\n\t\tconst startsWith = diskUtil.resolvePath(watchDir, 'build')\n\n\t\tthis.watcher.on('all', async (action, path) => {\n\t\t\tif (path.startsWith(startsWith)) {\n\t\t\t\tthis.changesSinceLastChange.push({\n\t\t\t\t\tschemaId: this.mapChokidarActionToSchemaId(action),\n\t\t\t\t\tversion: 'v2020_07_22',\n\t\t\t\t\tvalues: {\n\t\t\t\t\t\taction: this.mapChokidarActionToGeneratedAction(action),\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\tname: pathUtil.basename(path),\n\t\t\t\t\t},\n\t\t\t\t})\n\n\t\t\t\tif (this.timeoutId) {\n\t\t\t\t\tclearTimeout(this.timeoutId)\n\t\t\t\t}\n\n\t\t\t\tthis.timeoutId = setTimeout(async () => {\n\t\t\t\t\tawait this.fireChange()\n\t\t\t\t}, options?.delay ?? 500)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate mapChokidarActionToSchemaId(\n\t\taction: ChokidarAction\n\t): GeneratedFileOrDir['schemaId'] {\n\t\treturn action.search(/dir/gi) > -1 ? 'generatedDir' : 'generatedFile'\n\t}\n\n\tprivate mapChokidarActionToGeneratedAction(chokidar: ChokidarAction) {\n\t\tconst map = {\n\t\t\tadd: 'generated',\n\t\t\taddDir: 'generated',\n\t\t\tchange: 'updated',\n\t\t\tunlink: 'deleted',\n\t\t\tunlinkDir: 'deleted',\n\t\t}\n\n\t\treturn map[chokidar] as GeneratedFile['action']\n\t}\n\n\tprivate async fireChange() {\n\t\tconst changes = this.changesSinceLastChange\n\t\tthis.changesSinceLastChange = []\n\n\t\tawait this.emitter.emit('watcher.did-detect-change', {\n\t\t\tchanges,\n\t\t})\n\t}\n\n\tpublic async stopWatching() {\n\t\tthis._isWatching = false\n\t\tawait this.watcher?.close()\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;AACA;AAEA;AAAgD;AAAA;AAAA,IAe3BA,YAAY;EAAA;EAAA;EAAA;IAAA;IAAA;IAAA;MAAA;IAAA;IAAA;IAAA,gGAE/B,qGAAqG;IAAA,yFAC3E,OAAO;IAAA,iGACZ,OAAO;IAAA,gGAEP,KAAK;IAAA;IAAA;IAAA,2GAI4B,EAAE;IA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rC,WAAW,GAAG,KAAK;gBAAA;gBAAA,wBAClB,IAAI,CAACO,OAAO,kDAAZ,cAAciC,KAAK,EAAE;cAAA;cAAA;gBAAA;YAAA;UAAA;QAAA;MAAA,CAC3B;MAAA;QAAA;MAAA;MAAA;IAAA;EAAA;EAAA;AAAA,EAhFwCC,4BAAe;AAAA"}
1
+ {"version":3,"file":"WatchFeature.js","names":["WatchFeature","_isWatching","options","watchDir","diskUtil","resolvePath","cwd","sourceDir","watcher","chokidar","watch","ignoreInitial","startsWith","on","action","path","changesSinceLastChange","push","schemaId","mapChokidarActionToSchemaId","version","values","mapChokidarActionToGeneratedAction","name","pathUtil","basename","timeoutId","clearTimeout","setTimeout","fireChange","delay","search","map","add","addDir","change","unlink","unlinkDir","changes","emitter","emitAndFlattenResponses","close","AbstractFeature"],"sources":["../../../src/features/watch/WatchFeature.ts"],"sourcesContent":["import pathUtil from 'path'\nimport { diskUtil } from '@sprucelabs/spruce-skill-utils'\nimport chokidar from 'chokidar'\nimport { GeneratedFile, GeneratedFileOrDir } from '../../types/cli.types'\nimport AbstractFeature from '../AbstractFeature'\nimport { FeatureCode } from '../features.types'\n\ntype ChokidarAction = 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir'\n\ndeclare module '../../features/features.types' {\n\tinterface FeatureMap {\n\t\twatch: WatchFeature\n\t}\n\n\tinterface FeatureOptionsMap {\n\t\twatch: undefined\n\t}\n}\n\nexport default class WatchFeature extends AbstractFeature {\n\tpublic description =\n\t\t'Watches for changes on the file system and emits app level events for other features to respond to.'\n\tpublic code: FeatureCode = 'watch'\n\tpublic nameReadable = 'Watch'\n\n\tprivate _isWatching = false\n\tprivate watcher?: chokidar.FSWatcher\n\t// eslint-disable-next-line no-undef\n\tprivate timeoutId?: NodeJS.Timeout\n\tprivate changesSinceLastChange: GeneratedFileOrDir[] = []\n\n\tpublic async isWatching() {\n\t\treturn this._isWatching\n\t}\n\n\tpublic async startWatching(options?: { delay?: number; sourceDir?: string }) {\n\t\tthis._isWatching = true\n\n\t\tconst watchDir = diskUtil.resolvePath(this.cwd, options?.sourceDir ?? '')\n\n\t\tthis.watcher = chokidar.watch(watchDir, {\n\t\t\tignoreInitial: true,\n\t\t})\n\n\t\tconst startsWith = diskUtil.resolvePath(watchDir, 'build')\n\n\t\tthis.watcher.on('all', async (action, path) => {\n\t\t\tif (path.startsWith(startsWith)) {\n\t\t\t\tthis.changesSinceLastChange.push({\n\t\t\t\t\tschemaId: this.mapChokidarActionToSchemaId(action),\n\t\t\t\t\tversion: 'v2020_07_22',\n\t\t\t\t\tvalues: {\n\t\t\t\t\t\taction: this.mapChokidarActionToGeneratedAction(action),\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\tname: pathUtil.basename(path),\n\t\t\t\t\t},\n\t\t\t\t})\n\n\t\t\t\tif (this.timeoutId) {\n\t\t\t\t\tclearTimeout(this.timeoutId)\n\t\t\t\t}\n\n\t\t\t\tthis.timeoutId = setTimeout(async () => {\n\t\t\t\t\tawait this.fireChange()\n\t\t\t\t}, options?.delay ?? 500)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate mapChokidarActionToSchemaId(\n\t\taction: ChokidarAction\n\t): GeneratedFileOrDir['schemaId'] {\n\t\treturn action.search(/dir/gi) > -1 ? 'generatedDir' : 'generatedFile'\n\t}\n\n\tprivate mapChokidarActionToGeneratedAction(chokidar: ChokidarAction) {\n\t\tconst map = {\n\t\t\tadd: 'generated',\n\t\t\taddDir: 'generated',\n\t\t\tchange: 'updated',\n\t\t\tunlink: 'deleted',\n\t\t\tunlinkDir: 'deleted',\n\t\t}\n\n\t\treturn map[chokidar] as GeneratedFile['action']\n\t}\n\n\tprivate async fireChange() {\n\t\tconst changes = this.changesSinceLastChange\n\t\tthis.changesSinceLastChange = []\n\n\t\tawait this.emitter.emitAndFlattenResponses('watcher.did-detect-change', {\n\t\t\tchanges,\n\t\t})\n\t}\n\n\tpublic async stopWatching() {\n\t\tthis._isWatching = false\n\t\tawait this.watcher?.close()\n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AA;gBAAA,OAE1B,IAAI,CAACuB,OAAO,CAACC,uBAAuB,CAAC,2BAA2B,EAAE;kBACvEF,OAAO,EAAPA;gBACD,CAAC,CAAC;cAAA;cAAA;gBAAA;YAAA;UAAA;QAAA;MAAA,CACF;MAAA;QAAA;MAAA;MAAA;IAAA;EAAA;IAAA;IAAA;MAAA,kGAED;QAAA;QAAA;UAAA;YAAA;cAAA;gBACC,IAAI,CAACrC,WAAW,GAAG,KAAK;gBAAA;gBAAA,wBAClB,IAAI,CAACO,OAAO,kDAAZ,cAAciC,KAAK,EAAE;cAAA;cAAA;gBAAA;YAAA;UAAA;QAAA;MAAA,CAC3B;MAAA;QAAA;MAAA;MAAA;IAAA;EAAA;EAAA;AAAA,EAhFwCC,4BAAe;AAAA"}
@@ -15,6 +15,7 @@ export default class SpyInterface implements GraphicsInterface {
15
15
  private term?;
16
16
  private startTime;
17
17
  private promptTimeout?;
18
+ private error?;
18
19
  constructor();
19
20
  private shouldRenderTestLogs;
20
21
  renderWarning(message: string, effects?: GraphicsTextEffect[] | undefined): void;
@@ -22,6 +23,7 @@ export default class SpyInterface implements GraphicsInterface {
22
23
  private trackInvocation;
23
24
  isWaitingForInput(): boolean;
24
25
  reset(): void;
26
+ setError(err: Error): void;
25
27
  getLastInvocation(): {
26
28
  command: string;
27
29
  options?: any;
@@ -31,6 +31,7 @@ var SpyInterface = /*#__PURE__*/function () {
31
31
  (0, _defineProperty2["default"])(this, "term", void 0);
32
32
  (0, _defineProperty2["default"])(this, "startTime", void 0);
33
33
  (0, _defineProperty2["default"])(this, "promptTimeout", void 0);
34
+ (0, _defineProperty2["default"])(this, "error", void 0);
34
35
  this.startTime = new Date().getTime();
35
36
  this.term = this.shouldRenderTestLogs() ? new _TerminalInterface["default"](process.cwd(), true, function () {
36
37
  for (var _len = arguments.length, strs = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -87,6 +88,11 @@ var SpyInterface = /*#__PURE__*/function () {
87
88
  this.waitForEnterResolver = undefined;
88
89
  clearTimeout(this.promptTimeout);
89
90
  }
91
+ }, {
92
+ key: "setError",
93
+ value: function setError(err) {
94
+ this.error = err;
95
+ }
90
96
  }, {
91
97
  key: "getLastInvocation",
92
98
  value: function getLastInvocation() {
@@ -375,7 +381,7 @@ var SpyInterface = /*#__PURE__*/function () {
375
381
  lastWriteCount = this.invocations.length;
376
382
  case 4:
377
383
  if (this.isWaitingForInput()) {
378
- _context5.next = 12;
384
+ _context5.next = 14;
379
385
  break;
380
386
  }
381
387
  if (loops-- === 0) {
@@ -389,14 +395,20 @@ var SpyInterface = /*#__PURE__*/function () {
389
395
  _test["default"].log('waitForInput timeout reset because of new output.');
390
396
  }
391
397
  }
392
- _context5.next = 10;
398
+ if (!this.error) {
399
+ _context5.next = 10;
400
+ break;
401
+ }
402
+ throw this.error;
403
+ case 10:
404
+ _context5.next = 12;
393
405
  return new Promise(function (resolve) {
394
406
  return setTimeout(resolve, checkInterval);
395
407
  });
396
- case 10:
408
+ case 12:
397
409
  _context5.next = 4;
398
410
  break;
399
- case 12:
411
+ case 14:
400
412
  case "end":
401
413
  return _context5.stop();
402
414
  }