@sprucelabs/spruce-cli 14.21.14 → 14.21.18
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/CHANGELOG.md +32 -0
- package/build/__tests__/behavioral/skill/UpgradingASkill4.test.d.ts +1 -0
- package/build/__tests__/behavioral/skill/UpgradingASkill4.test.js +73 -8
- package/build/__tests__/behavioral/skill/UpgradingASkill4.test.js.map +1 -1
- package/build/features/schema/SchemaFeature.d.ts +1 -0
- package/build/features/schema/SchemaFeature.js +75 -17
- package/build/features/schema/SchemaFeature.js.map +1 -1
- package/build/features/schema/stores/SchemaStore.d.ts +2 -0
- package/build/features/schema/stores/SchemaStore.js +109 -49
- package/build/features/schema/stores/SchemaStore.js.map +1 -1
- package/package.json +28 -28
- package/src/__tests__/behavioral/skill/UpgradingASkill4.test.ts +41 -0
- package/src/features/schema/SchemaFeature.ts +30 -0
- package/src/features/schema/stores/SchemaStore.ts +15 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [14.21.18](https://github.com/sprucelabsai/spruce-cli-workspace/compare/v14.21.17...v14.21.18) (2021-10-15)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @sprucelabs/spruce-cli
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [14.21.17](https://github.com/sprucelabsai/spruce-cli-workspace/compare/v14.21.16...v14.21.17) (2021-10-15)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @sprucelabs/spruce-cli
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [14.21.16](https://github.com/sprucelabsai/spruce-cli-workspace/compare/v14.21.15...v14.21.16) (2021-10-14)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @sprucelabs/spruce-cli
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [14.21.15](https://github.com/sprucelabsai/spruce-cli-workspace/compare/v14.21.14...v14.21.15) (2021-10-13)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @sprucelabs/spruce-cli
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
6
38
|
## [14.21.14](https://github.com/sprucelabsai/spruce-cli-workspace/compare/v14.21.13...v14.21.14) (2021-10-13)
|
|
7
39
|
|
|
8
40
|
**Note:** Version bump only for package @sprucelabs/spruce-cli
|
|
@@ -2,6 +2,7 @@ import AbstractCliTest from '../../../tests/AbstractCliTest';
|
|
|
2
2
|
export default class UpgradingASkill4Test extends AbstractCliTest {
|
|
3
3
|
protected static upgradeResetsEventCache(): Promise<void>;
|
|
4
4
|
protected static doesNotResetEventCacheWithOtherAction(): Promise<void>;
|
|
5
|
+
protected static shouldSyncSchemasIfSchemasIsInstalledAndSchemaFolderExists(shouldCreateSchema: boolean): Promise<void>;
|
|
5
6
|
private static installSetListenerCacheAndBlockExecute;
|
|
6
7
|
private static Settings;
|
|
7
8
|
}
|
|
@@ -25,15 +25,17 @@ var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/
|
|
|
25
25
|
|
|
26
26
|
var _test = require("@sprucelabs/test");
|
|
27
27
|
|
|
28
|
+
var _CommandService = _interopRequireDefault(require("../../../services/CommandService"));
|
|
29
|
+
|
|
28
30
|
var _AbstractCliTest2 = _interopRequireDefault(require("../../../tests/AbstractCliTest"));
|
|
29
31
|
|
|
30
|
-
var _dec, _dec2, _class;
|
|
32
|
+
var _dec, _dec2, _dec3, _dec4, _class;
|
|
31
33
|
|
|
32
34
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
33
35
|
|
|
34
36
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
35
37
|
|
|
36
|
-
var UpgradingASkill4Test = (_dec = (0, _test.test)(), _dec2 = (0, _test.test)(), (_class = /*#__PURE__*/function (_AbstractCliTest) {
|
|
38
|
+
var UpgradingASkill4Test = (_dec = (0, _test.test)(), _dec2 = (0, _test.test)(), _dec3 = (0, _test.test)('syncs schemas when schemas installed and schemas folder exists', true), _dec4 = (0, _test.test)('does not syncs schemas when schemas installed but schemas folder does not exist', false), (_class = /*#__PURE__*/function (_AbstractCliTest) {
|
|
37
39
|
(0, _inherits2["default"])(UpgradingASkill4Test, _AbstractCliTest);
|
|
38
40
|
|
|
39
41
|
var _super = _createSuper(UpgradingASkill4Test);
|
|
@@ -124,15 +126,78 @@ var UpgradingASkill4Test = (_dec = (0, _test.test)(), _dec2 = (0, _test.test)(),
|
|
|
124
126
|
return doesNotResetEventCacheWithOtherAction;
|
|
125
127
|
}()
|
|
126
128
|
}, {
|
|
127
|
-
key: "
|
|
129
|
+
key: "shouldSyncSchemasIfSchemasIsInstalledAndSchemaFolderExists",
|
|
128
130
|
value: function () {
|
|
129
|
-
var
|
|
130
|
-
var
|
|
131
|
+
var _shouldSyncSchemasIfSchemasIsInstalledAndSchemaFolderExists = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(shouldCreateSchema) {
|
|
132
|
+
var emitter, wasHit;
|
|
131
133
|
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
132
134
|
while (1) {
|
|
133
135
|
switch (_context3.prev = _context3.next) {
|
|
134
136
|
case 0:
|
|
135
137
|
_context3.next = 2;
|
|
138
|
+
return this.FeatureFixture().installCachedFeatures('schemas');
|
|
139
|
+
|
|
140
|
+
case 2:
|
|
141
|
+
_CommandService["default"].setMockResponse(new RegExp(/yarn/gi), {
|
|
142
|
+
code: 0
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (!shouldCreateSchema) {
|
|
146
|
+
_context3.next = 6;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
_context3.next = 6;
|
|
151
|
+
return this.Action('schema', 'create').execute({
|
|
152
|
+
nameReadable: 'Test schema!',
|
|
153
|
+
namePascal: 'AnotherTest',
|
|
154
|
+
nameCamel: 'anotherTest',
|
|
155
|
+
description: 'this is so great!'
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
case 6:
|
|
159
|
+
emitter = this.getEmitter();
|
|
160
|
+
wasHit = false;
|
|
161
|
+
_context3.next = 10;
|
|
162
|
+
return emitter.on('feature.will-execute', function (payload) {
|
|
163
|
+
if (payload.featureCode === 'schema' && payload.actionCode === 'sync') {
|
|
164
|
+
wasHit = true;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return {};
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
case 10:
|
|
171
|
+
_context3.next = 12;
|
|
172
|
+
return this.Action('node', 'upgrade').execute({});
|
|
173
|
+
|
|
174
|
+
case 12:
|
|
175
|
+
_test.assert.isTrue(wasHit === shouldCreateSchema);
|
|
176
|
+
|
|
177
|
+
case 13:
|
|
178
|
+
case "end":
|
|
179
|
+
return _context3.stop();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}, _callee3, this);
|
|
183
|
+
}));
|
|
184
|
+
|
|
185
|
+
function shouldSyncSchemasIfSchemasIsInstalledAndSchemaFolderExists(_x) {
|
|
186
|
+
return _shouldSyncSchemasIfSchemasIsInstalledAndSchemaFolderExists.apply(this, arguments);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return shouldSyncSchemasIfSchemasIsInstalledAndSchemaFolderExists;
|
|
190
|
+
}()
|
|
191
|
+
}, {
|
|
192
|
+
key: "installSetListenerCacheAndBlockExecute",
|
|
193
|
+
value: function () {
|
|
194
|
+
var _installSetListenerCacheAndBlockExecute = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
|
|
195
|
+
var settings, emitter;
|
|
196
|
+
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
197
|
+
while (1) {
|
|
198
|
+
switch (_context4.prev = _context4.next) {
|
|
199
|
+
case 0:
|
|
200
|
+
_context4.next = 2;
|
|
136
201
|
return this.FeatureFixture().installCachedFeatures('events');
|
|
137
202
|
|
|
138
203
|
case 2:
|
|
@@ -147,10 +212,10 @@ var UpgradingASkill4Test = (_dec = (0, _test.test)(), _dec2 = (0, _test.test)(),
|
|
|
147
212
|
|
|
148
213
|
case 6:
|
|
149
214
|
case "end":
|
|
150
|
-
return
|
|
215
|
+
return _context4.stop();
|
|
151
216
|
}
|
|
152
217
|
}
|
|
153
|
-
},
|
|
218
|
+
}, _callee4, this);
|
|
154
219
|
}));
|
|
155
220
|
|
|
156
221
|
function installSetListenerCacheAndBlockExecute() {
|
|
@@ -166,6 +231,6 @@ var UpgradingASkill4Test = (_dec = (0, _test.test)(), _dec2 = (0, _test.test)(),
|
|
|
166
231
|
}
|
|
167
232
|
}]);
|
|
168
233
|
return UpgradingASkill4Test;
|
|
169
|
-
}(_AbstractCliTest2["default"]), ((0, _applyDecoratedDescriptor2["default"])(_class, "upgradeResetsEventCache", [_dec], Object.getOwnPropertyDescriptor(_class, "upgradeResetsEventCache"), _class), (0, _applyDecoratedDescriptor2["default"])(_class, "doesNotResetEventCacheWithOtherAction", [_dec2], Object.getOwnPropertyDescriptor(_class, "doesNotResetEventCacheWithOtherAction"), _class)), _class));
|
|
234
|
+
}(_AbstractCliTest2["default"]), ((0, _applyDecoratedDescriptor2["default"])(_class, "upgradeResetsEventCache", [_dec], Object.getOwnPropertyDescriptor(_class, "upgradeResetsEventCache"), _class), (0, _applyDecoratedDescriptor2["default"])(_class, "doesNotResetEventCacheWithOtherAction", [_dec2], Object.getOwnPropertyDescriptor(_class, "doesNotResetEventCacheWithOtherAction"), _class), (0, _applyDecoratedDescriptor2["default"])(_class, "shouldSyncSchemasIfSchemasIsInstalledAndSchemaFolderExists", [_dec3, _dec4], Object.getOwnPropertyDescriptor(_class, "shouldSyncSchemasIfSchemasIsInstalledAndSchemaFolderExists"), _class)), _class));
|
|
170
235
|
exports["default"] = UpgradingASkill4Test;
|
|
171
236
|
//# sourceMappingURL=UpgradingASkill4.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/__tests__/behavioral/skill/UpgradingASkill4.test.ts"],"names":["UpgradingASkill4Test","installSetListenerCacheAndBlockExecute","assert","doesThrowAsync","Action","execute","value","Settings","getListenerCache","isFalsy","isEqualDeep","shouldBeDeleted","FeatureFixture","installCachedFeatures","
|
|
1
|
+
{"version":3,"sources":["../../../../src/__tests__/behavioral/skill/UpgradingASkill4.test.ts"],"names":["UpgradingASkill4Test","installSetListenerCacheAndBlockExecute","assert","doesThrowAsync","Action","execute","value","Settings","getListenerCache","isFalsy","isEqualDeep","shouldBeDeleted","shouldCreateSchema","FeatureFixture","installCachedFeatures","CommandService","setMockResponse","RegExp","code","nameReadable","namePascal","nameCamel","description","emitter","getEmitter","wasHit","on","payload","featureCode","actionCode","isTrue","settings","setListenerCache","Error","Service","AbstractCliTest"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;;;IAEqBA,oB,WACnB,iB,UAYA,iB,UAUA,gBAAK,gEAAL,EAAuE,IAAvE,C,UACA,gBACA,iFADA,EAEA,KAFA,C;;;;;;;;;;;;;mHAvBD;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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A;;;EA7EgDC,4B","sourcesContent":["import { test, assert } from '@sprucelabs/test'\nimport CommandService from '../../../services/CommandService'\nimport AbstractCliTest from '../../../tests/AbstractCliTest'\n\nexport default class UpgradingASkill4Test extends AbstractCliTest {\n\t@test()\n\tprotected static async upgradeResetsEventCache() {\n\t\tawait this.installSetListenerCacheAndBlockExecute()\n\n\t\tawait assert.doesThrowAsync(() =>\n\t\t\tthis.Action('node', 'upgrade').execute({})\n\t\t)\n\n\t\tconst value = this.Settings().getListenerCache()\n\t\tassert.isFalsy(value)\n\t}\n\n\t@test()\n\tprotected static async doesNotResetEventCacheWithOtherAction() {\n\t\tawait this.installSetListenerCacheAndBlockExecute()\n\n\t\tawait assert.doesThrowAsync(() => this.Action('schema', 'sync').execute({}))\n\n\t\tconst value = this.Settings().getListenerCache()\n\t\tassert.isEqualDeep(value, { shouldBeDeleted: true })\n\t}\n\n\t@test('syncs schemas when schemas installed and schemas folder exists', true)\n\t@test(\n\t\t'does not syncs schemas when schemas installed but schemas folder does not exist',\n\t\tfalse\n\t)\n\tprotected static async shouldSyncSchemasIfSchemasIsInstalledAndSchemaFolderExists(\n\t\tshouldCreateSchema: boolean\n\t) {\n\t\tawait this.FeatureFixture().installCachedFeatures('schemas')\n\n\t\tCommandService.setMockResponse(new RegExp(/yarn/gis), {\n\t\t\tcode: 0,\n\t\t})\n\n\t\tif (shouldCreateSchema) {\n\t\t\tawait this.Action('schema', 'create').execute({\n\t\t\t\tnameReadable: 'Test schema!',\n\t\t\t\tnamePascal: 'AnotherTest',\n\t\t\t\tnameCamel: 'anotherTest',\n\t\t\t\tdescription: 'this is so great!',\n\t\t\t})\n\t\t}\n\n\t\tconst emitter = this.getEmitter()\n\n\t\tlet wasHit = false\n\n\t\tawait emitter.on('feature.will-execute', (payload) => {\n\t\t\tif (payload.featureCode === 'schema' && payload.actionCode === 'sync') {\n\t\t\t\twasHit = true\n\t\t\t}\n\n\t\t\treturn {}\n\t\t})\n\n\t\tawait this.Action('node', 'upgrade').execute({})\n\n\t\tassert.isTrue(wasHit === shouldCreateSchema)\n\t}\n\n\tprivate static async installSetListenerCacheAndBlockExecute() {\n\t\tawait this.FeatureFixture().installCachedFeatures('events')\n\n\t\tconst settings = this.Settings()\n\t\tsettings.setListenerCache({ shouldBeDeleted: true })\n\n\t\tconst emitter = this.getEmitter()\n\t\tvoid emitter.on('feature.will-execute', () => {\n\t\t\tthrow new Error('Stop!')\n\t\t})\n\t}\n\n\tprivate static Settings() {\n\t\treturn this.Service('eventSettings')\n\t}\n}\n"],"file":"UpgradingASkill4.test.js"}
|
|
@@ -18,6 +18,7 @@ export default class SchemaFeature extends AbstractFeature {
|
|
|
18
18
|
actionsDir: string;
|
|
19
19
|
constructor(options: FeatureOptions);
|
|
20
20
|
private handleWillExecute;
|
|
21
|
+
private handleDidExecute;
|
|
21
22
|
afterPackageInstall(): Promise<InstallResults>;
|
|
22
23
|
private writePlugin;
|
|
23
24
|
}
|
|
@@ -59,10 +59,13 @@ var SchemaFeature = /*#__PURE__*/function (_AbstractFeature) {
|
|
|
59
59
|
}, {
|
|
60
60
|
name: '@sprucelabs/resolve-path-aliases@latest',
|
|
61
61
|
isDev: true
|
|
62
|
+
}, {
|
|
63
|
+
name: '@sprucelabs/spruce-skill-utils'
|
|
62
64
|
}]);
|
|
63
65
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "code", 'schema');
|
|
64
66
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "actionsDir", _spruceSkillUtils.diskUtil.resolvePath(__dirname, 'actions'));
|
|
65
67
|
void _this.emitter.on('feature.will-execute', _this.handleWillExecute.bind((0, _assertThisInitialized2["default"])(_this)));
|
|
68
|
+
void _this.emitter.on('feature.did-execute', _this.handleDidExecute.bind((0, _assertThisInitialized2["default"])(_this)));
|
|
66
69
|
return _this;
|
|
67
70
|
}
|
|
68
71
|
|
|
@@ -118,43 +121,98 @@ var SchemaFeature = /*#__PURE__*/function (_AbstractFeature) {
|
|
|
118
121
|
return handleWillExecute;
|
|
119
122
|
}()
|
|
120
123
|
}, {
|
|
121
|
-
key: "
|
|
124
|
+
key: "handleDidExecute",
|
|
122
125
|
value: function () {
|
|
123
|
-
var
|
|
124
|
-
var
|
|
126
|
+
var _handleDidExecute = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(payload) {
|
|
127
|
+
var isInstalled, hasLocalSchemas, results;
|
|
125
128
|
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
126
129
|
while (1) {
|
|
127
130
|
switch (_context2.prev = _context2.next) {
|
|
128
131
|
case 0:
|
|
129
132
|
_context2.next = 2;
|
|
133
|
+
return this.featureInstaller.isInstalled('schema');
|
|
134
|
+
|
|
135
|
+
case 2:
|
|
136
|
+
isInstalled = _context2.sent;
|
|
137
|
+
|
|
138
|
+
if (!(payload.featureCode === 'node' && payload.actionCode === 'upgrade' && isInstalled)) {
|
|
139
|
+
_context2.next = 12;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
_context2.next = 6;
|
|
144
|
+
return this.Store('schema').hasLocalSchemas();
|
|
145
|
+
|
|
146
|
+
case 6:
|
|
147
|
+
hasLocalSchemas = _context2.sent;
|
|
148
|
+
|
|
149
|
+
if (!hasLocalSchemas) {
|
|
150
|
+
_context2.next = 12;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
_context2.next = 10;
|
|
155
|
+
return this.Action('schema', 'sync').execute({});
|
|
156
|
+
|
|
157
|
+
case 10:
|
|
158
|
+
results = _context2.sent;
|
|
159
|
+
return _context2.abrupt("return", results);
|
|
160
|
+
|
|
161
|
+
case 12:
|
|
162
|
+
return _context2.abrupt("return", {});
|
|
163
|
+
|
|
164
|
+
case 13:
|
|
165
|
+
case "end":
|
|
166
|
+
return _context2.stop();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}, _callee2, this);
|
|
170
|
+
}));
|
|
171
|
+
|
|
172
|
+
function handleDidExecute(_x2) {
|
|
173
|
+
return _handleDidExecute.apply(this, arguments);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return handleDidExecute;
|
|
177
|
+
}()
|
|
178
|
+
}, {
|
|
179
|
+
key: "afterPackageInstall",
|
|
180
|
+
value: function () {
|
|
181
|
+
var _afterPackageInstall = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
|
|
182
|
+
var isSkillInstalled, files;
|
|
183
|
+
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
184
|
+
while (1) {
|
|
185
|
+
switch (_context3.prev = _context3.next) {
|
|
186
|
+
case 0:
|
|
187
|
+
_context3.next = 2;
|
|
130
188
|
return this.featureInstaller.isInstalled('skill');
|
|
131
189
|
|
|
132
190
|
case 2:
|
|
133
|
-
isSkillInstalled =
|
|
191
|
+
isSkillInstalled = _context3.sent;
|
|
134
192
|
|
|
135
193
|
if (isSkillInstalled) {
|
|
136
|
-
|
|
194
|
+
_context3.next = 5;
|
|
137
195
|
break;
|
|
138
196
|
}
|
|
139
197
|
|
|
140
|
-
return
|
|
198
|
+
return _context3.abrupt("return", {});
|
|
141
199
|
|
|
142
200
|
case 5:
|
|
143
|
-
|
|
201
|
+
_context3.next = 7;
|
|
144
202
|
return this.writePlugin();
|
|
145
203
|
|
|
146
204
|
case 7:
|
|
147
|
-
files =
|
|
148
|
-
return
|
|
205
|
+
files = _context3.sent;
|
|
206
|
+
return _context3.abrupt("return", {
|
|
149
207
|
files: files
|
|
150
208
|
});
|
|
151
209
|
|
|
152
210
|
case 9:
|
|
153
211
|
case "end":
|
|
154
|
-
return
|
|
212
|
+
return _context3.stop();
|
|
155
213
|
}
|
|
156
214
|
}
|
|
157
|
-
},
|
|
215
|
+
}, _callee3, this);
|
|
158
216
|
}));
|
|
159
217
|
|
|
160
218
|
function afterPackageInstall() {
|
|
@@ -166,19 +224,19 @@ var SchemaFeature = /*#__PURE__*/function (_AbstractFeature) {
|
|
|
166
224
|
}, {
|
|
167
225
|
key: "writePlugin",
|
|
168
226
|
value: function () {
|
|
169
|
-
var _writePlugin = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
170
|
-
return _regenerator["default"].wrap(function
|
|
227
|
+
var _writePlugin = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
|
|
228
|
+
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
171
229
|
while (1) {
|
|
172
|
-
switch (
|
|
230
|
+
switch (_context4.prev = _context4.next) {
|
|
173
231
|
case 0:
|
|
174
|
-
return
|
|
232
|
+
return _context4.abrupt("return", this.Writer('schema').writePlugin(this.cwd));
|
|
175
233
|
|
|
176
234
|
case 1:
|
|
177
235
|
case "end":
|
|
178
|
-
return
|
|
236
|
+
return _context4.stop();
|
|
179
237
|
}
|
|
180
238
|
}
|
|
181
|
-
},
|
|
239
|
+
}, _callee4, this);
|
|
182
240
|
}));
|
|
183
241
|
|
|
184
242
|
function writePlugin() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/schema/SchemaFeature.ts"],"names":["SchemaFeature","options","code","isRequired","name","isDev","diskUtil","resolvePath","__dirname","emitter","on","handleWillExecute","bind","payload","featureInstaller","isInstalled","isSkillInstalled","featureCode","actionCode","writePlugin","files","Writer","cwd","AbstractFeature"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;;;;;IAiBqBA,a;;;;;
|
|
1
|
+
{"version":3,"sources":["../../../src/features/schema/SchemaFeature.ts"],"names":["SchemaFeature","options","code","isRequired","name","isDev","diskUtil","resolvePath","__dirname","emitter","on","handleWillExecute","bind","handleDidExecute","payload","featureInstaller","isInstalled","isSkillInstalled","featureCode","actionCode","writePlugin","files","Store","hasLocalSchemas","Action","execute","results","Writer","cwd","AbstractFeature"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;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AAA;AAAA;AAAA;AAAA,O;;;;;;;;;;;uGAcA;AAAA;AAAA;AAAA;AAAA;AAAA,kDACQ,KAAKM,MAAL,CAAY,QAAZ,EAAsBP,WAAtB,CAAkC,KAAKQ,GAAvC,CADR;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;EA9F0CC,4B","sourcesContent":["import { diskUtil } from '@sprucelabs/spruce-skill-utils'\nimport { NpmPackage } from '../../types/cli.types'\nimport AbstractFeature, {\n\tFeatureDependency,\n\tFeatureOptions,\n\tInstallResults,\n} from '../AbstractFeature'\nimport { FeatureCode } from '../features.types'\n\ndeclare module '../../features/features.types' {\n\tinterface FeatureMap {\n\t\tschema: SchemaFeature\n\t}\n\n\tinterface FeatureOptionsMap {\n\t\tschema: undefined\n\t}\n}\n\nexport default class SchemaFeature extends AbstractFeature {\n\tpublic nameReadable = 'Schema'\n\tpublic description = 'Define, validate, and normalize everything.'\n\tpublic dependencies: FeatureDependency[] = [\n\t\t{ code: 'skill', isRequired: false },\n\t\t{ code: 'node', isRequired: true },\n\t]\n\tpublic packageDependencies: NpmPackage[] = [\n\t\t{\n\t\t\tname: '@sprucelabs/schema@latest',\n\t\t},\n\t\t{\n\t\t\tname: '@sprucelabs/spruce-core-schemas@latest',\n\t\t},\n\t\t{ name: '@sprucelabs/resolve-path-aliases@latest', isDev: true },\n\t\t{\n\t\t\tname: '@sprucelabs/spruce-skill-utils',\n\t\t},\n\t]\n\n\tpublic code: FeatureCode = 'schema'\n\n\tpublic actionsDir = diskUtil.resolvePath(__dirname, 'actions')\n\n\tpublic constructor(options: FeatureOptions) {\n\t\tsuper(options)\n\n\t\tvoid this.emitter.on(\n\t\t\t'feature.will-execute',\n\t\t\tthis.handleWillExecute.bind(this)\n\t\t)\n\n\t\tvoid this.emitter.on(\n\t\t\t'feature.did-execute',\n\t\t\tthis.handleDidExecute.bind(this)\n\t\t)\n\t}\n\n\tprivate async handleWillExecute(payload: {\n\t\tactionCode: string\n\t\tfeatureCode: string\n\t}) {\n\t\tconst isInstalled = await this.featureInstaller.isInstalled('schema')\n\t\tconst isSkillInstalled = await this.featureInstaller.isInstalled('skill')\n\n\t\tif (\n\t\t\tpayload.featureCode === 'node' &&\n\t\t\tpayload.actionCode === 'upgrade' &&\n\t\t\tisInstalled &&\n\t\t\tisSkillInstalled\n\t\t) {\n\t\t\tconst files = await this.writePlugin()\n\t\t\treturn { files }\n\t\t}\n\n\t\treturn {}\n\t}\n\n\tprivate async handleDidExecute(payload: {\n\t\tactionCode: string\n\t\tfeatureCode: string\n\t}) {\n\t\tconst isInstalled = await this.featureInstaller.isInstalled('schema')\n\n\t\tif (\n\t\t\tpayload.featureCode === 'node' &&\n\t\t\tpayload.actionCode === 'upgrade' &&\n\t\t\tisInstalled\n\t\t) {\n\t\t\tconst hasLocalSchemas = await this.Store('schema').hasLocalSchemas()\n\t\t\tif (hasLocalSchemas) {\n\t\t\t\tconst results = await this.Action('schema', 'sync').execute({})\n\n\t\t\t\treturn results\n\t\t\t}\n\t\t}\n\n\t\treturn {}\n\t}\n\n\tpublic async afterPackageInstall(): Promise<InstallResults> {\n\t\tconst isSkillInstalled = await this.featureInstaller.isInstalled('skill')\n\n\t\tif (!isSkillInstalled) {\n\t\t\treturn {}\n\t\t}\n\n\t\tconst files = await this.writePlugin()\n\n\t\treturn {\n\t\t\tfiles,\n\t\t}\n\t}\n\n\tprivate async writePlugin() {\n\t\treturn this.Writer('schema').writePlugin(this.cwd)\n\t}\n}\n"],"file":"SchemaFeature.js"}
|
|
@@ -32,7 +32,9 @@ export default class SchemaStore extends AbstractStore {
|
|
|
32
32
|
}): Promise<FetchSchemasResults>;
|
|
33
33
|
private emitDidFetchSchemasAndMixinResults;
|
|
34
34
|
private mixinSchemaOrThrowIfExists;
|
|
35
|
+
hasLocalSchemas(): Promise<boolean>;
|
|
35
36
|
private loadLocalSchemas;
|
|
37
|
+
private globbyLocalBuilders;
|
|
36
38
|
private resolveLocalVersion;
|
|
37
39
|
private prepareLocalSchema;
|
|
38
40
|
fetchFields(options?: {
|
|
@@ -59,6 +59,8 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
59
59
|
|
|
60
60
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
61
61
|
|
|
62
|
+
var DEFAULT_LOCAL_SCHEMA_DIR = 'src/schemas';
|
|
63
|
+
|
|
62
64
|
var SchemaStore = /*#__PURE__*/function (_AbstractStore) {
|
|
63
65
|
(0, _inherits2["default"])(SchemaStore, _AbstractStore);
|
|
64
66
|
|
|
@@ -88,7 +90,7 @@ var SchemaStore = /*#__PURE__*/function (_AbstractStore) {
|
|
|
88
90
|
while (1) {
|
|
89
91
|
switch (_context.prev = _context.next) {
|
|
90
92
|
case 0:
|
|
91
|
-
_ref = options || {}, _ref$localSchemaLooku = _ref.localSchemaLookupDir, localSchemaDir = _ref$localSchemaLooku === void 0 ?
|
|
93
|
+
_ref = options || {}, _ref$localSchemaLooku = _ref.localSchemaLookupDir, localSchemaDir = _ref$localSchemaLooku === void 0 ? DEFAULT_LOCAL_SCHEMA_DIR : _ref$localSchemaLooku, _ref$shouldFetchLocal = _ref.shouldFetchLocalSchemas, shouldFetchLocalSchemas = _ref$shouldFetchLocal === void 0 ? true : _ref$shouldFetchLocal, _ref$shouldFetchRemot = _ref.shouldFetchRemoteSchemas, shouldFetchRemoteSchemas = _ref$shouldFetchRemot === void 0 ? true : _ref$shouldFetchRemot, _ref$shouldEnableVers = _ref.shouldEnableVersioning, shouldEnableVersioning = _ref$shouldEnableVers === void 0 ? true : _ref$shouldEnableVers, localNamespace = _ref.localNamespace, _ref$shouldFetchCoreS = _ref.shouldFetchCoreSchemas, shouldFetchCoreSchemas = _ref$shouldFetchCoreS === void 0 ? true : _ref$shouldFetchCoreS, didUpdateHandler = _ref.didUpdateHandler, moduleToImportFromWhenRemote = _ref.moduleToImportFromWhenRemote;
|
|
92
94
|
results = {
|
|
93
95
|
errors: [],
|
|
94
96
|
schemasByNamespace: {}
|
|
@@ -223,30 +225,60 @@ var SchemaStore = /*#__PURE__*/function (_AbstractStore) {
|
|
|
223
225
|
}
|
|
224
226
|
}
|
|
225
227
|
}, {
|
|
226
|
-
key: "
|
|
228
|
+
key: "hasLocalSchemas",
|
|
227
229
|
value: function () {
|
|
228
|
-
var
|
|
229
|
-
var
|
|
230
|
-
|
|
230
|
+
var _hasLocalSchemas = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
|
|
231
|
+
var matches;
|
|
231
232
|
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
232
233
|
while (1) {
|
|
233
234
|
switch (_context3.prev = _context3.next) {
|
|
234
235
|
case 0:
|
|
235
236
|
_context3.next = 2;
|
|
236
|
-
return
|
|
237
|
+
return this.globbyLocalBuilders(DEFAULT_LOCAL_SCHEMA_DIR);
|
|
238
|
+
|
|
239
|
+
case 2:
|
|
240
|
+
matches = _context3.sent;
|
|
241
|
+
return _context3.abrupt("return", matches.length > 0);
|
|
242
|
+
|
|
243
|
+
case 4:
|
|
244
|
+
case "end":
|
|
245
|
+
return _context3.stop();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}, _callee3, this);
|
|
249
|
+
}));
|
|
250
|
+
|
|
251
|
+
function hasLocalSchemas() {
|
|
252
|
+
return _hasLocalSchemas.apply(this, arguments);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return hasLocalSchemas;
|
|
256
|
+
}()
|
|
257
|
+
}, {
|
|
258
|
+
key: "loadLocalSchemas",
|
|
259
|
+
value: function () {
|
|
260
|
+
var _loadLocalSchemas = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(localLookupDir, localNamespace, shouldEnableVersioning, didUpdateHandler) {
|
|
261
|
+
var localMatches, errors, schemas, importer, imported, c, local, schema, version, _err$options$file, _err$options, _err$originalError, _err$options$file2, _err$options2, _err$originalError2;
|
|
262
|
+
|
|
263
|
+
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
264
|
+
while (1) {
|
|
265
|
+
switch (_context4.prev = _context4.next) {
|
|
266
|
+
case 0:
|
|
267
|
+
_context4.next = 2;
|
|
268
|
+
return this.globbyLocalBuilders(localLookupDir);
|
|
237
269
|
|
|
238
270
|
case 2:
|
|
239
|
-
localMatches =
|
|
271
|
+
localMatches = _context4.sent;
|
|
240
272
|
errors = [];
|
|
241
273
|
schemas = [];
|
|
242
274
|
didUpdateHandler === null || didUpdateHandler === void 0 ? void 0 : didUpdateHandler("Starting import of ".concat(localMatches.length, " schema builders..."));
|
|
243
|
-
|
|
275
|
+
_context4.prev = 6;
|
|
244
276
|
importer = this.Service('import');
|
|
245
|
-
|
|
277
|
+
_context4.next = 10;
|
|
246
278
|
return importer.bulkImport(localMatches);
|
|
247
279
|
|
|
248
280
|
case 10:
|
|
249
|
-
imported =
|
|
281
|
+
imported = _context4.sent;
|
|
250
282
|
|
|
251
283
|
for (c = 0; c < localMatches.length; c++) {
|
|
252
284
|
try {
|
|
@@ -267,30 +299,30 @@ var SchemaStore = /*#__PURE__*/function (_AbstractStore) {
|
|
|
267
299
|
}
|
|
268
300
|
}
|
|
269
301
|
|
|
270
|
-
|
|
302
|
+
_context4.next = 17;
|
|
271
303
|
break;
|
|
272
304
|
|
|
273
305
|
case 14:
|
|
274
|
-
|
|
275
|
-
|
|
306
|
+
_context4.prev = 14;
|
|
307
|
+
_context4.t0 = _context4["catch"](6);
|
|
276
308
|
throw new _SpruceError["default"]({
|
|
277
309
|
code: 'SCHEMA_FAILED_TO_IMPORT',
|
|
278
|
-
file: (_err$options$file2 =
|
|
279
|
-
originalError: (_err$originalError2 =
|
|
310
|
+
file: (_err$options$file2 = _context4.t0 === null || _context4.t0 === void 0 ? void 0 : (_err$options2 = _context4.t0.options) === null || _err$options2 === void 0 ? void 0 : _err$options2.file) !== null && _err$options$file2 !== void 0 ? _err$options$file2 : '**UNKWOWN**',
|
|
311
|
+
originalError: (_err$originalError2 = _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.originalError) !== null && _err$originalError2 !== void 0 ? _err$originalError2 : _context4.t0
|
|
280
312
|
});
|
|
281
313
|
|
|
282
314
|
case 17:
|
|
283
|
-
return
|
|
315
|
+
return _context4.abrupt("return", {
|
|
284
316
|
schemas: schemas,
|
|
285
317
|
errors: errors
|
|
286
318
|
});
|
|
287
319
|
|
|
288
320
|
case 18:
|
|
289
321
|
case "end":
|
|
290
|
-
return
|
|
322
|
+
return _context4.stop();
|
|
291
323
|
}
|
|
292
324
|
}
|
|
293
|
-
},
|
|
325
|
+
}, _callee4, this, [[6, 14]]);
|
|
294
326
|
}));
|
|
295
327
|
|
|
296
328
|
function loadLocalSchemas(_x4, _x5, _x6, _x7) {
|
|
@@ -299,6 +331,34 @@ var SchemaStore = /*#__PURE__*/function (_AbstractStore) {
|
|
|
299
331
|
|
|
300
332
|
return loadLocalSchemas;
|
|
301
333
|
}()
|
|
334
|
+
}, {
|
|
335
|
+
key: "globbyLocalBuilders",
|
|
336
|
+
value: function () {
|
|
337
|
+
var _globbyLocalBuilders = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(localLookupDir) {
|
|
338
|
+
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
339
|
+
while (1) {
|
|
340
|
+
switch (_context5.prev = _context5.next) {
|
|
341
|
+
case 0:
|
|
342
|
+
_context5.next = 2;
|
|
343
|
+
return (0, _globby["default"])(_spruceSkillUtils.diskUtil.resolvePath(this.cwd, localLookupDir, '**/*.builder.[t|j]s'));
|
|
344
|
+
|
|
345
|
+
case 2:
|
|
346
|
+
return _context5.abrupt("return", _context5.sent);
|
|
347
|
+
|
|
348
|
+
case 3:
|
|
349
|
+
case "end":
|
|
350
|
+
return _context5.stop();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}, _callee5, this);
|
|
354
|
+
}));
|
|
355
|
+
|
|
356
|
+
function globbyLocalBuilders(_x8) {
|
|
357
|
+
return _globbyLocalBuilders.apply(this, arguments);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return globbyLocalBuilders;
|
|
361
|
+
}()
|
|
302
362
|
}, {
|
|
303
363
|
key: "resolveLocalVersion",
|
|
304
364
|
value: function resolveLocalVersion(shouldEnableVersioning, local, errors) {
|
|
@@ -347,14 +407,14 @@ var SchemaStore = /*#__PURE__*/function (_AbstractStore) {
|
|
|
347
407
|
}, {
|
|
348
408
|
key: "fetchFields",
|
|
349
409
|
value: function () {
|
|
350
|
-
var _fetchFields = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
410
|
+
var _fetchFields = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(options) {
|
|
351
411
|
var _this3 = this;
|
|
352
412
|
|
|
353
413
|
var _ref2, localAddonsDir, coreAddons, localErrors, localAddons, allFields;
|
|
354
414
|
|
|
355
|
-
return _regenerator["default"].wrap(function
|
|
415
|
+
return _regenerator["default"].wrap(function _callee7$(_context7) {
|
|
356
416
|
while (1) {
|
|
357
|
-
switch (
|
|
417
|
+
switch (_context7.prev = _context7.next) {
|
|
358
418
|
case 0:
|
|
359
419
|
_ref2 = options || {}, localAddonsDir = _ref2.localAddonsDir;
|
|
360
420
|
coreAddons = _schema.fieldRegistrations.map(function (registration) {
|
|
@@ -366,87 +426,87 @@ var SchemaStore = /*#__PURE__*/function (_AbstractStore) {
|
|
|
366
426
|
localErrors = [];
|
|
367
427
|
|
|
368
428
|
if (localAddonsDir) {
|
|
369
|
-
|
|
429
|
+
_context7.next = 7;
|
|
370
430
|
break;
|
|
371
431
|
}
|
|
372
432
|
|
|
373
|
-
|
|
374
|
-
|
|
433
|
+
_context7.t0 = [];
|
|
434
|
+
_context7.next = 14;
|
|
375
435
|
break;
|
|
376
436
|
|
|
377
437
|
case 7:
|
|
378
|
-
|
|
379
|
-
|
|
438
|
+
_context7.t1 = Promise;
|
|
439
|
+
_context7.next = 10;
|
|
380
440
|
return (0, _globby["default"])([_path["default"].join(localAddonsDir, '/*Field.addon.[t|j]s')]);
|
|
381
441
|
|
|
382
442
|
case 10:
|
|
383
|
-
|
|
384
|
-
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
443
|
+
_context7.t2 = _context7.sent.map( /*#__PURE__*/function () {
|
|
444
|
+
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(file) {
|
|
385
445
|
var importService, registration;
|
|
386
|
-
return _regenerator["default"].wrap(function
|
|
446
|
+
return _regenerator["default"].wrap(function _callee6$(_context6) {
|
|
387
447
|
while (1) {
|
|
388
|
-
switch (
|
|
448
|
+
switch (_context6.prev = _context6.next) {
|
|
389
449
|
case 0:
|
|
390
|
-
|
|
450
|
+
_context6.prev = 0;
|
|
391
451
|
importService = _this3.Service('import');
|
|
392
|
-
|
|
452
|
+
_context6.next = 4;
|
|
393
453
|
return importService.importDefault(file);
|
|
394
454
|
|
|
395
455
|
case 4:
|
|
396
|
-
registration =
|
|
397
|
-
return
|
|
456
|
+
registration = _context6.sent;
|
|
457
|
+
return _context6.abrupt("return", {
|
|
398
458
|
path: file,
|
|
399
459
|
registration: registration,
|
|
400
460
|
isLocal: true
|
|
401
461
|
});
|
|
402
462
|
|
|
403
463
|
case 8:
|
|
404
|
-
|
|
405
|
-
|
|
464
|
+
_context6.prev = 8;
|
|
465
|
+
_context6.t0 = _context6["catch"](0);
|
|
406
466
|
localErrors.push(new _SpruceError["default"]({
|
|
407
467
|
code: 'FAILED_TO_IMPORT',
|
|
408
468
|
file: file,
|
|
409
|
-
originalError:
|
|
469
|
+
originalError: _context6.t0
|
|
410
470
|
}));
|
|
411
|
-
return
|
|
471
|
+
return _context6.abrupt("return", false);
|
|
412
472
|
|
|
413
473
|
case 12:
|
|
414
474
|
case "end":
|
|
415
|
-
return
|
|
475
|
+
return _context6.stop();
|
|
416
476
|
}
|
|
417
477
|
}
|
|
418
|
-
},
|
|
478
|
+
}, _callee6, null, [[0, 8]]);
|
|
419
479
|
}));
|
|
420
480
|
|
|
421
|
-
return function (
|
|
481
|
+
return function (_x10) {
|
|
422
482
|
return _ref3.apply(this, arguments);
|
|
423
483
|
};
|
|
424
484
|
}());
|
|
425
|
-
|
|
426
|
-
return
|
|
485
|
+
_context7.next = 13;
|
|
486
|
+
return _context7.t1.all.call(_context7.t1, _context7.t2);
|
|
427
487
|
|
|
428
488
|
case 13:
|
|
429
|
-
|
|
489
|
+
_context7.t0 = _context7.sent;
|
|
430
490
|
|
|
431
491
|
case 14:
|
|
432
|
-
localAddons =
|
|
492
|
+
localAddons = _context7.t0;
|
|
433
493
|
allFields = (0, _lodash.uniqBy)([].concat((0, _toConsumableArray2["default"])(coreAddons), (0, _toConsumableArray2["default"])(localAddons.filter(function (addon) {
|
|
434
494
|
return !!addon;
|
|
435
495
|
}))), 'registration.type');
|
|
436
|
-
return
|
|
496
|
+
return _context7.abrupt("return", {
|
|
437
497
|
fields: allFields,
|
|
438
498
|
errors: localErrors
|
|
439
499
|
});
|
|
440
500
|
|
|
441
501
|
case 17:
|
|
442
502
|
case "end":
|
|
443
|
-
return
|
|
503
|
+
return _context7.stop();
|
|
444
504
|
}
|
|
445
505
|
}
|
|
446
|
-
},
|
|
506
|
+
}, _callee7);
|
|
447
507
|
}));
|
|
448
508
|
|
|
449
|
-
function fetchFields(
|
|
509
|
+
function fetchFields(_x9) {
|
|
450
510
|
return _fetchFields.apply(this, arguments);
|
|
451
511
|
}
|
|
452
512
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/features/schema/stores/SchemaStore.ts"],"names":["SchemaStore","options","localSchemaLookupDir","localSchemaDir","shouldFetchLocalSchemas","shouldFetchRemoteSchemas","shouldEnableVersioning","localNamespace","shouldFetchCoreSchemas","didUpdateHandler","moduleToImportFromWhenRemote","results","errors","schemasByNamespace","CORE_NAMESPACE","Object","values","coreSchemas","map","schema","namespace","loadLocalSchemas","locals","schemas","forEach","local","push","emitDidFetchSchemasAndMixinResults","emitter","emit","remoteResults","eventResponseUtil","getAllResponsePayloadsAndErrors","SpruceError","payloads","length","payload","mixinSchemaOrThrowIfExists","idWithVersion","match","find","s","localLookupDir","diskUtil","resolvePath","cwd","localMatches","importer","Service","bulkImport","imported","c","version","resolveLocalVersion","prepareLocalSchema","err","code","file","originalError","undefined","versionUtil","extractVersion","constValue","friendlyMessage","generateVersion","dirValue","SchemaError","schemaId","id","localAddonsDir","coreAddons","fieldRegistrations","registration","isLocal","localErrors","Promise","pathUtil","join","importService","importDefault","path","all","localAddons","allFields","filter","addon","fields","AbstractStore"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAOA;;AACA;;AACA;;AAGA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;IA4BqBA,W;;;;;;;;;;;;;;;6FACG,Q;;;;;;;wGAEvB,iBAA0BC,OAA1B;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA,uBAmBKA,OAAO,IAAI,EAnBhB,+BAWEC,oBAXF,EAWwBC,cAXxB,sCAWyC,aAXzC,uDAYEC,uBAZF,EAYEA,uBAZF,sCAY4B,IAZ5B,uDAaEC,wBAbF,EAaEA,wBAbF,sCAa6B,IAb7B,uDAcEC,sBAdF,EAcEA,sBAdF,sCAc2B,IAd3B,0BAeEC,cAfF,QAeEA,cAfF,+BAgBEC,sBAhBF,EAgBEA,sBAhBF,sCAgB2B,IAhB3B,0BAiBEC,gBAjBF,QAiBEA,gBAjBF,EAkBEC,4BAlBF,QAkBEA,4BAlBF;AAqBOC,gBAAAA,OArBP,GAqBsC;AACpCC,kBAAAA,MAAM,EAAE,EAD4B;AAEpCC,kBAAAA,kBAAkB,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AA;AAAA,O;;;;;;;;;;EA/OwCa,0B","sourcesContent":["import pathUtil from 'path'\nimport {\n\tSchema,\n\tFieldRegistration,\n\tfieldRegistrations,\n\tnormalizeSchemaToIdWithVersion,\n\tSchemaError,\n} from '@sprucelabs/schema'\nimport * as coreSchemas from '@sprucelabs/spruce-core-schemas'\nimport { eventResponseUtil } from '@sprucelabs/spruce-event-utils'\nimport { versionUtil } from '@sprucelabs/spruce-skill-utils'\nimport { diskUtil } from '@sprucelabs/spruce-skill-utils'\nimport { CORE_NAMESPACE } from '@sprucelabs/spruce-skill-utils'\nimport globby from 'globby'\nimport { isEqual, uniqBy } from 'lodash'\nimport SpruceError from '../../../errors/SpruceError'\nimport AbstractStore from '../../../stores/AbstractStore'\nimport { InternalUpdateHandler } from '../../../types/cli.types'\n\ninterface AddonItem {\n\tpath: string\n\tregistration: FieldRegistration\n\tisLocal: boolean\n}\n\nexport interface SchemasByNamespace {\n\t[namespace: string]: Schema[]\n}\n\ninterface FetchSchemasResults {\n\tschemasByNamespace: SchemasByNamespace\n\terrors: SpruceError[]\n}\nexport interface FetchedField {\n\tpath?: string\n\tregistration: FieldRegistration\n\tisLocal: boolean\n}\n\ninterface FetchFieldsResults {\n\terrors: SpruceError[]\n\tfields: FetchedField[]\n}\n\nexport default class SchemaStore extends AbstractStore {\n\tpublic readonly name = 'schema'\n\n\tpublic async fetchSchemas(options: {\n\t\tlocalSchemaLookupDir?: string\n\t\tshouldFetchRemoteSchemas?: boolean\n\t\tshouldEnableVersioning?: boolean\n\t\tlocalNamespace: string\n\t\tshouldFetchCoreSchemas?: boolean\n\t\tmoduleToImportFromWhenRemote?: string\n\t\tshouldFetchLocalSchemas?: boolean\n\t\tdidUpdateHandler?: InternalUpdateHandler\n\t}): Promise<FetchSchemasResults> {\n\t\tconst {\n\t\t\tlocalSchemaLookupDir: localSchemaDir = 'src/schemas',\n\t\t\tshouldFetchLocalSchemas = true,\n\t\t\tshouldFetchRemoteSchemas = true,\n\t\t\tshouldEnableVersioning = true,\n\t\t\tlocalNamespace,\n\t\t\tshouldFetchCoreSchemas = true,\n\t\t\tdidUpdateHandler,\n\t\t\tmoduleToImportFromWhenRemote,\n\t\t} = options || {}\n\n\t\tconst results: FetchSchemasResults = {\n\t\t\terrors: [],\n\t\t\tschemasByNamespace: {},\n\t\t}\n\n\t\tif (shouldFetchCoreSchemas) {\n\t\t\tresults.schemasByNamespace[CORE_NAMESPACE] = Object.values(\n\t\t\t\tcoreSchemas\n\t\t\t).map((schema) => ({\n\t\t\t\t...schema,\n\t\t\t\tnamespace: CORE_NAMESPACE,\n\t\t\t}))\n\t\t}\n\n\t\tif (shouldFetchLocalSchemas) {\n\t\t\tconst locals = await this.loadLocalSchemas(\n\t\t\t\tlocalSchemaDir,\n\t\t\t\tlocalNamespace,\n\t\t\t\tshouldEnableVersioning,\n\t\t\t\tdidUpdateHandler\n\t\t\t)\n\n\t\t\tif (moduleToImportFromWhenRemote) {\n\t\t\t\tlocals.schemas.forEach((local) => {\n\t\t\t\t\tlocal.moduleToImportFromWhenRemote = moduleToImportFromWhenRemote\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tresults.schemasByNamespace[localNamespace] = locals.schemas\n\t\t\tresults.errors.push(...locals.errors)\n\t\t}\n\n\t\tif (shouldFetchRemoteSchemas) {\n\t\t\tawait this.emitDidFetchSchemasAndMixinResults(localNamespace, results)\n\t\t}\n\n\t\treturn results\n\t}\n\n\tprivate async emitDidFetchSchemasAndMixinResults(\n\t\tlocalNamespace: string,\n\t\tresults: FetchSchemasResults\n\t) {\n\t\tconst schemas: Schema[] = []\n\t\tfor (const namespace in results.schemasByNamespace) {\n\t\t\tschemas.push(...results.schemasByNamespace[namespace])\n\t\t}\n\n\t\tconst remoteResults = await this.emitter.emit('schema.did-fetch-schemas', {\n\t\t\tschemas,\n\t\t})\n\n\t\tconst { payloads, errors } =\n\t\t\teventResponseUtil.getAllResponsePayloadsAndErrors(\n\t\t\t\tremoteResults,\n\t\t\t\tSpruceError\n\t\t\t)\n\n\t\tif (errors && errors.length > 0) {\n\t\t\tresults.errors.push(...errors)\n\t\t} else {\n\t\t\tpayloads.forEach((payload) => {\n\t\t\t\tpayload?.schemas?.forEach((schema: Schema) => {\n\t\t\t\t\tthis.mixinSchemaOrThrowIfExists(schema, localNamespace, results)\n\t\t\t\t})\n\t\t\t})\n\t\t}\n\t}\n\n\tprivate mixinSchemaOrThrowIfExists(\n\t\tschema: Schema,\n\t\tlocalNamespace: string,\n\t\tresults: FetchSchemasResults\n\t) {\n\t\tconst namespace = schema.namespace ?? localNamespace\n\n\t\tif (!results.schemasByNamespace[namespace]) {\n\t\t\tresults.schemasByNamespace[namespace] = []\n\t\t}\n\n\t\tconst idWithVersion = normalizeSchemaToIdWithVersion(schema)\n\t\tconst match = results.schemasByNamespace[namespace].find((s) =>\n\t\t\tisEqual(normalizeSchemaToIdWithVersion(s), idWithVersion)\n\t\t)\n\n\t\tif (!match) {\n\t\t\tresults.schemasByNamespace[namespace].push(schema)\n\t\t}\n\t}\n\n\tprivate async loadLocalSchemas(\n\t\tlocalLookupDir: string,\n\t\tlocalNamespace: string,\n\t\tshouldEnableVersioning?: boolean,\n\t\tdidUpdateHandler?: InternalUpdateHandler\n\t) {\n\t\tconst localMatches = await globby(\n\t\t\tdiskUtil.resolvePath(this.cwd, localLookupDir, '**/*.builder.[t|j]s')\n\t\t)\n\n\t\tconst errors: SpruceError[] = []\n\t\tconst schemas: Schema[] = []\n\n\t\tdidUpdateHandler?.(\n\t\t\t`Starting import of ${localMatches.length} schema builders...`\n\t\t)\n\n\t\ttry {\n\t\t\tconst importer = this.Service('import')\n\t\t\tconst imported = await importer.bulkImport(localMatches)\n\n\t\t\tfor (let c = 0; c < localMatches.length; c++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst local = localMatches[c]\n\t\t\t\t\tlet schema = imported[c]\n\n\t\t\t\t\tlet version: undefined | string = this.resolveLocalVersion(\n\t\t\t\t\t\tshouldEnableVersioning,\n\t\t\t\t\t\tlocal,\n\t\t\t\t\t\terrors\n\t\t\t\t\t)\n\t\t\t\t\tif (version || shouldEnableVersioning === false) {\n\t\t\t\t\t\tschema = this.prepareLocalSchema(\n\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\tlocalNamespace,\n\t\t\t\t\t\t\tversion,\n\t\t\t\t\t\t\tdidUpdateHandler\n\t\t\t\t\t\t)\n\t\t\t\t\t\tschemas.push(schema)\n\t\t\t\t\t}\n\t\t\t\t} catch (err: any) {\n\t\t\t\t\terrors.push(\n\t\t\t\t\t\tnew SpruceError({\n\t\t\t\t\t\t\tcode: 'SCHEMA_FAILED_TO_IMPORT',\n\t\t\t\t\t\t\tfile: err?.options?.file ?? '**UNKWOWN**',\n\t\t\t\t\t\t\toriginalError: err?.originalError ?? err,\n\t\t\t\t\t\t})\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (err: any) {\n\t\t\tthrow new SpruceError({\n\t\t\t\tcode: 'SCHEMA_FAILED_TO_IMPORT',\n\t\t\t\tfile: err?.options?.file ?? '**UNKWOWN**',\n\t\t\t\toriginalError: err?.originalError ?? err,\n\t\t\t})\n\t\t}\n\n\t\treturn {\n\t\t\tschemas,\n\t\t\terrors,\n\t\t}\n\t}\n\n\tprivate resolveLocalVersion(\n\t\tshouldEnableVersioning: boolean | undefined,\n\t\tlocal: string,\n\t\terrors: SpruceError[]\n\t) {\n\t\tlet version: undefined | string\n\n\t\ttry {\n\t\t\tversion =\n\t\t\t\tshouldEnableVersioning === false\n\t\t\t\t\t? undefined\n\t\t\t\t\t: versionUtil.extractVersion(this.cwd, local).constValue\n\t\t} catch (err) {\n\t\t\terrors.push(\n\t\t\t\tnew SpruceError({\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tcode: 'VERSION_MISSING',\n\t\t\t\t\tfriendlyMessage: `It looks like your schema's are not versioned. Make sure schemas are in a directory like src/schemas/${\n\t\t\t\t\t\tversionUtil.generateVersion().dirValue\n\t\t\t\t\t}/*.ts`,\n\t\t\t\t})\n\t\t\t)\n\t\t}\n\t\treturn version\n\t}\n\n\tprivate prepareLocalSchema(\n\t\tschema: Schema,\n\t\tlocalNamespace: string,\n\t\tversion: string | undefined,\n\t\tdidUpdateHandler: InternalUpdateHandler | undefined\n\t) {\n\t\tlet errors: string[] = []\n\n\t\tif (schema.version) {\n\t\t\terrors.push('version_should_not_be_set')\n\t\t}\n\n\t\tif (schema.namespace) {\n\t\t\terrors.push('namespace_should_not_be_set')\n\t\t}\n\n\t\tschema.namespace = localNamespace\n\n\t\tif (errors.length > 0) {\n\t\t\tthrow new SchemaError({\n\t\t\t\tcode: 'INVALID_SCHEMA',\n\t\t\t\tschemaId: schema.id,\n\t\t\t\terrors,\n\t\t\t\tfriendlyMessage:\n\t\t\t\t\t'You should not set a namespace nor version in your schema builder.',\n\t\t\t})\n\t\t}\n\n\t\tschema.version = version\n\n\t\tdidUpdateHandler?.(`Imported ${schema.id} builder.`)\n\n\t\treturn schema\n\t}\n\n\tpublic async fetchFields(options?: {\n\t\tlocalAddonsDir?: string\n\t}): Promise<FetchFieldsResults> {\n\t\tconst { localAddonsDir } = options || {}\n\n\t\tconst coreAddons = fieldRegistrations.map((registration) => {\n\t\t\treturn {\n\t\t\t\tregistration,\n\t\t\t\tisLocal: false,\n\t\t\t}\n\t\t})\n\n\t\tconst localErrors: SpruceError[] = []\n\n\t\tconst localAddons = !localAddonsDir\n\t\t\t? []\n\t\t\t: await Promise.all(\n\t\t\t\t\t(\n\t\t\t\t\t\tawait globby([\n\t\t\t\t\t\t\tpathUtil.join(localAddonsDir, '/*Field.addon.[t|j]s'),\n\t\t\t\t\t\t])\n\t\t\t\t\t).map(async (file: string) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst importService = this.Service('import')\n\t\t\t\t\t\t\tconst registration =\n\t\t\t\t\t\t\t\tawait importService.importDefault<FieldRegistration>(file)\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tpath: file,\n\t\t\t\t\t\t\t\tregistration,\n\t\t\t\t\t\t\t\tisLocal: true,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (err: any) {\n\t\t\t\t\t\t\tlocalErrors.push(\n\t\t\t\t\t\t\t\tnew SpruceError({\n\t\t\t\t\t\t\t\t\tcode: 'FAILED_TO_IMPORT',\n\t\t\t\t\t\t\t\t\tfile,\n\t\t\t\t\t\t\t\t\toriginalError: err,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t )\n\n\t\tconst allFields = uniqBy(\n\t\t\t[\n\t\t\t\t...coreAddons,\n\t\t\t\t...(localAddons.filter((addon) => !!addon) as AddonItem[]),\n\t\t\t],\n\t\t\t'registration.type'\n\t\t)\n\n\t\treturn {\n\t\t\tfields: allFields,\n\t\t\terrors: localErrors,\n\t\t}\n\t}\n}\n"],"file":"SchemaStore.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/features/schema/stores/SchemaStore.ts"],"names":["DEFAULT_LOCAL_SCHEMA_DIR","SchemaStore","options","localSchemaLookupDir","localSchemaDir","shouldFetchLocalSchemas","shouldFetchRemoteSchemas","shouldEnableVersioning","localNamespace","shouldFetchCoreSchemas","didUpdateHandler","moduleToImportFromWhenRemote","results","errors","schemasByNamespace","CORE_NAMESPACE","Object","values","coreSchemas","map","schema","namespace","loadLocalSchemas","locals","schemas","forEach","local","push","emitDidFetchSchemasAndMixinResults","emitter","emit","remoteResults","eventResponseUtil","getAllResponsePayloadsAndErrors","SpruceError","payloads","length","payload","mixinSchemaOrThrowIfExists","idWithVersion","match","find","s","globbyLocalBuilders","matches","localLookupDir","localMatches","importer","Service","bulkImport","imported","c","version","resolveLocalVersion","prepareLocalSchema","err","code","file","originalError","diskUtil","resolvePath","cwd","undefined","versionUtil","extractVersion","constValue","friendlyMessage","generateVersion","dirValue","SchemaError","schemaId","id","localAddonsDir","coreAddons","fieldRegistrations","registration","isLocal","localErrors","Promise","pathUtil","join","importService","importDefault","path","all","localAddons","allFields","filter","addon","fields","AbstractStore"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAOA;;AACA;;AACA;;AAGA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;AA4BA,IAAMA,wBAAwB,GAAG,aAAjC;;IAEqBC,W;;;;;;;;;;;;;;;6FACG,Q;;;;;;;wGAEvB,iBAA0BC,OAA1B;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA,uBAmBKA,OAAO,IAAI,EAnBhB,+BAWEC,oBAXF,EAWwBC,cAXxB,sCAWyCJ,wBAXzC,uDAYEK,uBAZF,EAYEA,uBAZF,sCAY4B,IAZ5B,uDAaEC,wBAbF,EAaEA,wBAbF,sCAa6B,IAb7B,uDAcEC,sBAdF,EAcEA,sBAdF,sCAc2B,IAd3B,0BAeEC,cAfF,QAeEA,cAfF,+BAgBEC,sBAhBF,EAgBEA,sBAhBF,sCAgB2B,IAhB3B,0BAiBEC,gBAjBF,QAiBEA,gBAjBF,EAkBEC,4BAlBF,QAkBEA,4BAlBF;AAqBOC,gBAAAA,OArBP,GAqBsC;AACpCC,kBAAAA,MAAM,EAAE,EAD4B;AAEpCC,kBAAAA,kBAAkB,EAAE;AAFgB,iBArBtC;;AA0BC,oBAAIL,sBAAJ,EAA4B;AAC3BG,kBAAAA,OAAO,CAACE,kBAAR,CAA2BC,gCAA3B,IAA6CC,MAAM,CAACC,MAAP,CAC5CC,WAD4C,EAE3CC,GAF2C,CAEvC,UAACC,MAAD;AAAA,2DACFA,MADE;AAELC,sBAAAA,SAAS,EAAEN;AAFN;AAAA,mBAFuC,CAA7C;AAMA;;AAjCF,qBAmCKV,uBAnCL;AAAA;AAAA;AAAA;;AAAA;AAAA,uBAoCuB,KAAKiB,gBAAL,CACpBlB,cADoB,EAEpBI,cAFoB,EAGpBD,sBAHoB,EAIpBG,gBAJoB,CApCvB;;AAAA;AA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0B","sourcesContent":["import pathUtil from 'path'\nimport {\n\tSchema,\n\tFieldRegistration,\n\tfieldRegistrations,\n\tnormalizeSchemaToIdWithVersion,\n\tSchemaError,\n} from '@sprucelabs/schema'\nimport * as coreSchemas from '@sprucelabs/spruce-core-schemas'\nimport { eventResponseUtil } from '@sprucelabs/spruce-event-utils'\nimport { versionUtil } from '@sprucelabs/spruce-skill-utils'\nimport { diskUtil } from '@sprucelabs/spruce-skill-utils'\nimport { CORE_NAMESPACE } from '@sprucelabs/spruce-skill-utils'\nimport globby from 'globby'\nimport { isEqual, uniqBy } from 'lodash'\nimport SpruceError from '../../../errors/SpruceError'\nimport AbstractStore from '../../../stores/AbstractStore'\nimport { InternalUpdateHandler } from '../../../types/cli.types'\n\ninterface AddonItem {\n\tpath: string\n\tregistration: FieldRegistration\n\tisLocal: boolean\n}\n\nexport interface SchemasByNamespace {\n\t[namespace: string]: Schema[]\n}\n\ninterface FetchSchemasResults {\n\tschemasByNamespace: SchemasByNamespace\n\terrors: SpruceError[]\n}\nexport interface FetchedField {\n\tpath?: string\n\tregistration: FieldRegistration\n\tisLocal: boolean\n}\n\ninterface FetchFieldsResults {\n\terrors: SpruceError[]\n\tfields: FetchedField[]\n}\n\nconst DEFAULT_LOCAL_SCHEMA_DIR = 'src/schemas'\n\nexport default class SchemaStore extends AbstractStore {\n\tpublic readonly name = 'schema'\n\n\tpublic async fetchSchemas(options: {\n\t\tlocalSchemaLookupDir?: string\n\t\tshouldFetchRemoteSchemas?: boolean\n\t\tshouldEnableVersioning?: boolean\n\t\tlocalNamespace: string\n\t\tshouldFetchCoreSchemas?: boolean\n\t\tmoduleToImportFromWhenRemote?: string\n\t\tshouldFetchLocalSchemas?: boolean\n\t\tdidUpdateHandler?: InternalUpdateHandler\n\t}): Promise<FetchSchemasResults> {\n\t\tconst {\n\t\t\tlocalSchemaLookupDir: localSchemaDir = DEFAULT_LOCAL_SCHEMA_DIR,\n\t\t\tshouldFetchLocalSchemas = true,\n\t\t\tshouldFetchRemoteSchemas = true,\n\t\t\tshouldEnableVersioning = true,\n\t\t\tlocalNamespace,\n\t\t\tshouldFetchCoreSchemas = true,\n\t\t\tdidUpdateHandler,\n\t\t\tmoduleToImportFromWhenRemote,\n\t\t} = options || {}\n\n\t\tconst results: FetchSchemasResults = {\n\t\t\terrors: [],\n\t\t\tschemasByNamespace: {},\n\t\t}\n\n\t\tif (shouldFetchCoreSchemas) {\n\t\t\tresults.schemasByNamespace[CORE_NAMESPACE] = Object.values(\n\t\t\t\tcoreSchemas\n\t\t\t).map((schema) => ({\n\t\t\t\t...schema,\n\t\t\t\tnamespace: CORE_NAMESPACE,\n\t\t\t}))\n\t\t}\n\n\t\tif (shouldFetchLocalSchemas) {\n\t\t\tconst locals = await this.loadLocalSchemas(\n\t\t\t\tlocalSchemaDir,\n\t\t\t\tlocalNamespace,\n\t\t\t\tshouldEnableVersioning,\n\t\t\t\tdidUpdateHandler\n\t\t\t)\n\n\t\t\tif (moduleToImportFromWhenRemote) {\n\t\t\t\tlocals.schemas.forEach((local) => {\n\t\t\t\t\tlocal.moduleToImportFromWhenRemote = moduleToImportFromWhenRemote\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tresults.schemasByNamespace[localNamespace] = locals.schemas\n\t\t\tresults.errors.push(...locals.errors)\n\t\t}\n\n\t\tif (shouldFetchRemoteSchemas) {\n\t\t\tawait this.emitDidFetchSchemasAndMixinResults(localNamespace, results)\n\t\t}\n\n\t\treturn results\n\t}\n\n\tprivate async emitDidFetchSchemasAndMixinResults(\n\t\tlocalNamespace: string,\n\t\tresults: FetchSchemasResults\n\t) {\n\t\tconst schemas: Schema[] = []\n\t\tfor (const namespace in results.schemasByNamespace) {\n\t\t\tschemas.push(...results.schemasByNamespace[namespace])\n\t\t}\n\n\t\tconst remoteResults = await this.emitter.emit('schema.did-fetch-schemas', {\n\t\t\tschemas,\n\t\t})\n\n\t\tconst { payloads, errors } =\n\t\t\teventResponseUtil.getAllResponsePayloadsAndErrors(\n\t\t\t\tremoteResults,\n\t\t\t\tSpruceError\n\t\t\t)\n\n\t\tif (errors && errors.length > 0) {\n\t\t\tresults.errors.push(...errors)\n\t\t} else {\n\t\t\tpayloads.forEach((payload) => {\n\t\t\t\tpayload?.schemas?.forEach((schema: Schema) => {\n\t\t\t\t\tthis.mixinSchemaOrThrowIfExists(schema, localNamespace, results)\n\t\t\t\t})\n\t\t\t})\n\t\t}\n\t}\n\n\tprivate mixinSchemaOrThrowIfExists(\n\t\tschema: Schema,\n\t\tlocalNamespace: string,\n\t\tresults: FetchSchemasResults\n\t) {\n\t\tconst namespace = schema.namespace ?? localNamespace\n\n\t\tif (!results.schemasByNamespace[namespace]) {\n\t\t\tresults.schemasByNamespace[namespace] = []\n\t\t}\n\n\t\tconst idWithVersion = normalizeSchemaToIdWithVersion(schema)\n\t\tconst match = results.schemasByNamespace[namespace].find((s) =>\n\t\t\tisEqual(normalizeSchemaToIdWithVersion(s), idWithVersion)\n\t\t)\n\n\t\tif (!match) {\n\t\t\tresults.schemasByNamespace[namespace].push(schema)\n\t\t}\n\t}\n\n\tpublic async hasLocalSchemas() {\n\t\tconst matches = await this.globbyLocalBuilders(DEFAULT_LOCAL_SCHEMA_DIR)\n\t\treturn matches.length > 0\n\t}\n\n\tprivate async loadLocalSchemas(\n\t\tlocalLookupDir: string,\n\t\tlocalNamespace: string,\n\t\tshouldEnableVersioning?: boolean,\n\t\tdidUpdateHandler?: InternalUpdateHandler\n\t) {\n\t\tconst localMatches = await this.globbyLocalBuilders(localLookupDir)\n\n\t\tconst errors: SpruceError[] = []\n\t\tconst schemas: Schema[] = []\n\n\t\tdidUpdateHandler?.(\n\t\t\t`Starting import of ${localMatches.length} schema builders...`\n\t\t)\n\n\t\ttry {\n\t\t\tconst importer = this.Service('import')\n\t\t\tconst imported = await importer.bulkImport(localMatches)\n\n\t\t\tfor (let c = 0; c < localMatches.length; c++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst local = localMatches[c]\n\t\t\t\t\tlet schema = imported[c]\n\n\t\t\t\t\tlet version: undefined | string = this.resolveLocalVersion(\n\t\t\t\t\t\tshouldEnableVersioning,\n\t\t\t\t\t\tlocal,\n\t\t\t\t\t\terrors\n\t\t\t\t\t)\n\t\t\t\t\tif (version || shouldEnableVersioning === false) {\n\t\t\t\t\t\tschema = this.prepareLocalSchema(\n\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\tlocalNamespace,\n\t\t\t\t\t\t\tversion,\n\t\t\t\t\t\t\tdidUpdateHandler\n\t\t\t\t\t\t)\n\t\t\t\t\t\tschemas.push(schema)\n\t\t\t\t\t}\n\t\t\t\t} catch (err: any) {\n\t\t\t\t\terrors.push(\n\t\t\t\t\t\tnew SpruceError({\n\t\t\t\t\t\t\tcode: 'SCHEMA_FAILED_TO_IMPORT',\n\t\t\t\t\t\t\tfile: err?.options?.file ?? '**UNKWOWN**',\n\t\t\t\t\t\t\toriginalError: err?.originalError ?? err,\n\t\t\t\t\t\t})\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (err: any) {\n\t\t\tthrow new SpruceError({\n\t\t\t\tcode: 'SCHEMA_FAILED_TO_IMPORT',\n\t\t\t\tfile: err?.options?.file ?? '**UNKWOWN**',\n\t\t\t\toriginalError: err?.originalError ?? err,\n\t\t\t})\n\t\t}\n\n\t\treturn {\n\t\t\tschemas,\n\t\t\terrors,\n\t\t}\n\t}\n\n\tprivate async globbyLocalBuilders(localLookupDir: string) {\n\t\treturn await globby(\n\t\t\tdiskUtil.resolvePath(this.cwd, localLookupDir, '**/*.builder.[t|j]s')\n\t\t)\n\t}\n\n\tprivate resolveLocalVersion(\n\t\tshouldEnableVersioning: boolean | undefined,\n\t\tlocal: string,\n\t\terrors: SpruceError[]\n\t) {\n\t\tlet version: undefined | string\n\n\t\ttry {\n\t\t\tversion =\n\t\t\t\tshouldEnableVersioning === false\n\t\t\t\t\t? undefined\n\t\t\t\t\t: versionUtil.extractVersion(this.cwd, local).constValue\n\t\t} catch (err) {\n\t\t\terrors.push(\n\t\t\t\tnew SpruceError({\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tcode: 'VERSION_MISSING',\n\t\t\t\t\tfriendlyMessage: `It looks like your schema's are not versioned. Make sure schemas are in a directory like src/schemas/${\n\t\t\t\t\t\tversionUtil.generateVersion().dirValue\n\t\t\t\t\t}/*.ts`,\n\t\t\t\t})\n\t\t\t)\n\t\t}\n\t\treturn version\n\t}\n\n\tprivate prepareLocalSchema(\n\t\tschema: Schema,\n\t\tlocalNamespace: string,\n\t\tversion: string | undefined,\n\t\tdidUpdateHandler: InternalUpdateHandler | undefined\n\t) {\n\t\tlet errors: string[] = []\n\n\t\tif (schema.version) {\n\t\t\terrors.push('version_should_not_be_set')\n\t\t}\n\n\t\tif (schema.namespace) {\n\t\t\terrors.push('namespace_should_not_be_set')\n\t\t}\n\n\t\tschema.namespace = localNamespace\n\n\t\tif (errors.length > 0) {\n\t\t\tthrow new SchemaError({\n\t\t\t\tcode: 'INVALID_SCHEMA',\n\t\t\t\tschemaId: schema.id,\n\t\t\t\terrors,\n\t\t\t\tfriendlyMessage:\n\t\t\t\t\t'You should not set a namespace nor version in your schema builder.',\n\t\t\t})\n\t\t}\n\n\t\tschema.version = version\n\n\t\tdidUpdateHandler?.(`Imported ${schema.id} builder.`)\n\n\t\treturn schema\n\t}\n\n\tpublic async fetchFields(options?: {\n\t\tlocalAddonsDir?: string\n\t}): Promise<FetchFieldsResults> {\n\t\tconst { localAddonsDir } = options || {}\n\n\t\tconst coreAddons = fieldRegistrations.map((registration) => {\n\t\t\treturn {\n\t\t\t\tregistration,\n\t\t\t\tisLocal: false,\n\t\t\t}\n\t\t})\n\n\t\tconst localErrors: SpruceError[] = []\n\n\t\tconst localAddons = !localAddonsDir\n\t\t\t? []\n\t\t\t: await Promise.all(\n\t\t\t\t\t(\n\t\t\t\t\t\tawait globby([\n\t\t\t\t\t\t\tpathUtil.join(localAddonsDir, '/*Field.addon.[t|j]s'),\n\t\t\t\t\t\t])\n\t\t\t\t\t).map(async (file: string) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst importService = this.Service('import')\n\t\t\t\t\t\t\tconst registration =\n\t\t\t\t\t\t\t\tawait importService.importDefault<FieldRegistration>(file)\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tpath: file,\n\t\t\t\t\t\t\t\tregistration,\n\t\t\t\t\t\t\t\tisLocal: true,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (err: any) {\n\t\t\t\t\t\t\tlocalErrors.push(\n\t\t\t\t\t\t\t\tnew SpruceError({\n\t\t\t\t\t\t\t\t\tcode: 'FAILED_TO_IMPORT',\n\t\t\t\t\t\t\t\t\tfile,\n\t\t\t\t\t\t\t\t\toriginalError: err,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t )\n\n\t\tconst allFields = uniqBy(\n\t\t\t[\n\t\t\t\t...coreAddons,\n\t\t\t\t...(localAddons.filter((addon) => !!addon) as AddonItem[]),\n\t\t\t],\n\t\t\t'registration.type'\n\t\t)\n\n\t\treturn {\n\t\t\tfields: allFields,\n\t\t\terrors: localErrors,\n\t\t}\n\t}\n}\n"],"file":"SchemaStore.js"}
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
]
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
|
-
"version": "14.21.
|
|
20
|
+
"version": "14.21.18",
|
|
21
21
|
"bin": {
|
|
22
22
|
"spruce": "./build/index.js"
|
|
23
23
|
},
|
|
@@ -75,19 +75,19 @@
|
|
|
75
75
|
"@babel/plugin-proposal-decorators": "^7.15.8",
|
|
76
76
|
"@babel/runtime": "^7.15.4",
|
|
77
77
|
"@jest/reporters": "^27.2.5",
|
|
78
|
-
"@sprucelabs/error": "^5.0.
|
|
79
|
-
"@sprucelabs/heartwood-view-controllers": "^33.0.
|
|
80
|
-
"@sprucelabs/jest-json-reporter": "^6.0.
|
|
81
|
-
"@sprucelabs/mercury-client": "^16.13.
|
|
82
|
-
"@sprucelabs/mercury-event-emitter": "^16.13.
|
|
83
|
-
"@sprucelabs/mercury-types": "^26.1.
|
|
84
|
-
"@sprucelabs/schema": "^25.3.
|
|
85
|
-
"@sprucelabs/spruce-core-schemas": "^22.5.
|
|
86
|
-
"@sprucelabs/spruce-event-plugin": "^5.4.
|
|
87
|
-
"@sprucelabs/spruce-event-utils": "^16.0.
|
|
88
|
-
"@sprucelabs/spruce-skill-booter": "^5.4.
|
|
89
|
-
"@sprucelabs/spruce-skill-utils": "^20.6.
|
|
90
|
-
"@sprucelabs/spruce-templates": "^14.21.
|
|
78
|
+
"@sprucelabs/error": "^5.0.232",
|
|
79
|
+
"@sprucelabs/heartwood-view-controllers": "^33.0.611",
|
|
80
|
+
"@sprucelabs/jest-json-reporter": "^6.0.206",
|
|
81
|
+
"@sprucelabs/mercury-client": "^16.13.26",
|
|
82
|
+
"@sprucelabs/mercury-event-emitter": "^16.13.26",
|
|
83
|
+
"@sprucelabs/mercury-types": "^26.1.397",
|
|
84
|
+
"@sprucelabs/schema": "^25.3.308",
|
|
85
|
+
"@sprucelabs/spruce-core-schemas": "^22.5.386",
|
|
86
|
+
"@sprucelabs/spruce-event-plugin": "^5.4.147",
|
|
87
|
+
"@sprucelabs/spruce-event-utils": "^16.0.398",
|
|
88
|
+
"@sprucelabs/spruce-skill-booter": "^5.4.147",
|
|
89
|
+
"@sprucelabs/spruce-skill-utils": "^20.6.249",
|
|
90
|
+
"@sprucelabs/spruce-templates": "^14.21.18",
|
|
91
91
|
"cfonts": "^2.10.0",
|
|
92
92
|
"chalk": "^4.1.2",
|
|
93
93
|
"chokidar": "^3.5.2",
|
|
@@ -116,16 +116,16 @@
|
|
|
116
116
|
"uuid": "^8.3.2"
|
|
117
117
|
},
|
|
118
118
|
"devDependencies": {
|
|
119
|
-
"@sprucelabs/data-stores": "^6.1.
|
|
120
|
-
"@sprucelabs/jest-sheets-reporter": "^1.2.
|
|
121
|
-
"@sprucelabs/mercury-core-events": "^1.2.
|
|
122
|
-
"@sprucelabs/resolve-path-aliases": "^1.0.
|
|
123
|
-
"@sprucelabs/spruce-conversation-plugin": "^5.4.
|
|
124
|
-
"@sprucelabs/spruce-deploy-plugin": "^5.4.
|
|
125
|
-
"@sprucelabs/spruce-store-plugin": "^5.4.
|
|
126
|
-
"@sprucelabs/spruce-test-fixtures": "^5.4.
|
|
127
|
-
"@sprucelabs/test": "^7.7.
|
|
128
|
-
"@sprucelabs/test-utils": "^3.0.
|
|
119
|
+
"@sprucelabs/data-stores": "^6.1.299",
|
|
120
|
+
"@sprucelabs/jest-sheets-reporter": "^1.2.215",
|
|
121
|
+
"@sprucelabs/mercury-core-events": "^1.2.475",
|
|
122
|
+
"@sprucelabs/resolve-path-aliases": "^1.0.213",
|
|
123
|
+
"@sprucelabs/spruce-conversation-plugin": "^5.4.147",
|
|
124
|
+
"@sprucelabs/spruce-deploy-plugin": "^5.4.147",
|
|
125
|
+
"@sprucelabs/spruce-store-plugin": "^5.4.147",
|
|
126
|
+
"@sprucelabs/spruce-test-fixtures": "^5.4.147",
|
|
127
|
+
"@sprucelabs/test": "^7.7.194",
|
|
128
|
+
"@sprucelabs/test-utils": "^3.0.203",
|
|
129
129
|
"@types/blessed": "^0.1.19",
|
|
130
130
|
"@types/eslint": "^7.28.1",
|
|
131
131
|
"@types/fs-extra": "^9.0.13",
|
|
@@ -135,7 +135,7 @@
|
|
|
135
135
|
"@types/lodash": "^4.14.175",
|
|
136
136
|
"@types/md5": "^2.3.1",
|
|
137
137
|
"@types/mkdirp": "^1.0.2",
|
|
138
|
-
"@types/node": "^16.
|
|
138
|
+
"@types/node": "^16.11.0",
|
|
139
139
|
"@types/promise.allsettled": "^1.0.3",
|
|
140
140
|
"@types/ps-node": "^0.1.1",
|
|
141
141
|
"@types/rimraf": "^3.0.2",
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
"concurrently": "^6.3.0",
|
|
150
150
|
"conventional-changelog-sprucelabs": "^1.1.2",
|
|
151
151
|
"dotenv": "^10.0.0",
|
|
152
|
-
"eslint": "^8.0.
|
|
152
|
+
"eslint": "^8.0.1",
|
|
153
153
|
"eslint-config-spruce": "^10.10.15",
|
|
154
154
|
"find-process": "^1.4.5",
|
|
155
155
|
"jest": "^27.2.5",
|
|
@@ -159,7 +159,7 @@
|
|
|
159
159
|
"prettier": "^2.4.1",
|
|
160
160
|
"ps-node": "^0.1.6",
|
|
161
161
|
"rimraf": "^3.0.2",
|
|
162
|
-
"ts-jest": "^27.0.
|
|
162
|
+
"ts-jest": "^27.0.6",
|
|
163
163
|
"ts-node": "^10.3.0",
|
|
164
164
|
"tsc-watch": "^4.5.0",
|
|
165
165
|
"tsconfig-paths": "^3.11.0",
|
|
@@ -591,5 +591,5 @@
|
|
|
591
591
|
"ora"
|
|
592
592
|
]
|
|
593
593
|
},
|
|
594
|
-
"gitHead": "
|
|
594
|
+
"gitHead": "1064c7152886b301fe8aa9d527319ec2f296561b"
|
|
595
595
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { test, assert } from '@sprucelabs/test'
|
|
2
|
+
import CommandService from '../../../services/CommandService'
|
|
2
3
|
import AbstractCliTest from '../../../tests/AbstractCliTest'
|
|
3
4
|
|
|
4
5
|
export default class UpgradingASkill4Test extends AbstractCliTest {
|
|
@@ -24,6 +25,46 @@ export default class UpgradingASkill4Test extends AbstractCliTest {
|
|
|
24
25
|
assert.isEqualDeep(value, { shouldBeDeleted: true })
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
@test('syncs schemas when schemas installed and schemas folder exists', true)
|
|
29
|
+
@test(
|
|
30
|
+
'does not syncs schemas when schemas installed but schemas folder does not exist',
|
|
31
|
+
false
|
|
32
|
+
)
|
|
33
|
+
protected static async shouldSyncSchemasIfSchemasIsInstalledAndSchemaFolderExists(
|
|
34
|
+
shouldCreateSchema: boolean
|
|
35
|
+
) {
|
|
36
|
+
await this.FeatureFixture().installCachedFeatures('schemas')
|
|
37
|
+
|
|
38
|
+
CommandService.setMockResponse(new RegExp(/yarn/gis), {
|
|
39
|
+
code: 0,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
if (shouldCreateSchema) {
|
|
43
|
+
await this.Action('schema', 'create').execute({
|
|
44
|
+
nameReadable: 'Test schema!',
|
|
45
|
+
namePascal: 'AnotherTest',
|
|
46
|
+
nameCamel: 'anotherTest',
|
|
47
|
+
description: 'this is so great!',
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const emitter = this.getEmitter()
|
|
52
|
+
|
|
53
|
+
let wasHit = false
|
|
54
|
+
|
|
55
|
+
await emitter.on('feature.will-execute', (payload) => {
|
|
56
|
+
if (payload.featureCode === 'schema' && payload.actionCode === 'sync') {
|
|
57
|
+
wasHit = true
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {}
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
await this.Action('node', 'upgrade').execute({})
|
|
64
|
+
|
|
65
|
+
assert.isTrue(wasHit === shouldCreateSchema)
|
|
66
|
+
}
|
|
67
|
+
|
|
27
68
|
private static async installSetListenerCacheAndBlockExecute() {
|
|
28
69
|
await this.FeatureFixture().installCachedFeatures('events')
|
|
29
70
|
|
|
@@ -32,6 +32,9 @@ export default class SchemaFeature extends AbstractFeature {
|
|
|
32
32
|
name: '@sprucelabs/spruce-core-schemas@latest',
|
|
33
33
|
},
|
|
34
34
|
{ name: '@sprucelabs/resolve-path-aliases@latest', isDev: true },
|
|
35
|
+
{
|
|
36
|
+
name: '@sprucelabs/spruce-skill-utils',
|
|
37
|
+
},
|
|
35
38
|
]
|
|
36
39
|
|
|
37
40
|
public code: FeatureCode = 'schema'
|
|
@@ -45,6 +48,11 @@ export default class SchemaFeature extends AbstractFeature {
|
|
|
45
48
|
'feature.will-execute',
|
|
46
49
|
this.handleWillExecute.bind(this)
|
|
47
50
|
)
|
|
51
|
+
|
|
52
|
+
void this.emitter.on(
|
|
53
|
+
'feature.did-execute',
|
|
54
|
+
this.handleDidExecute.bind(this)
|
|
55
|
+
)
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
private async handleWillExecute(payload: {
|
|
@@ -67,6 +75,28 @@ export default class SchemaFeature extends AbstractFeature {
|
|
|
67
75
|
return {}
|
|
68
76
|
}
|
|
69
77
|
|
|
78
|
+
private async handleDidExecute(payload: {
|
|
79
|
+
actionCode: string
|
|
80
|
+
featureCode: string
|
|
81
|
+
}) {
|
|
82
|
+
const isInstalled = await this.featureInstaller.isInstalled('schema')
|
|
83
|
+
|
|
84
|
+
if (
|
|
85
|
+
payload.featureCode === 'node' &&
|
|
86
|
+
payload.actionCode === 'upgrade' &&
|
|
87
|
+
isInstalled
|
|
88
|
+
) {
|
|
89
|
+
const hasLocalSchemas = await this.Store('schema').hasLocalSchemas()
|
|
90
|
+
if (hasLocalSchemas) {
|
|
91
|
+
const results = await this.Action('schema', 'sync').execute({})
|
|
92
|
+
|
|
93
|
+
return results
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {}
|
|
98
|
+
}
|
|
99
|
+
|
|
70
100
|
public async afterPackageInstall(): Promise<InstallResults> {
|
|
71
101
|
const isSkillInstalled = await this.featureInstaller.isInstalled('skill')
|
|
72
102
|
|
|
@@ -42,6 +42,8 @@ interface FetchFieldsResults {
|
|
|
42
42
|
fields: FetchedField[]
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
const DEFAULT_LOCAL_SCHEMA_DIR = 'src/schemas'
|
|
46
|
+
|
|
45
47
|
export default class SchemaStore extends AbstractStore {
|
|
46
48
|
public readonly name = 'schema'
|
|
47
49
|
|
|
@@ -56,7 +58,7 @@ export default class SchemaStore extends AbstractStore {
|
|
|
56
58
|
didUpdateHandler?: InternalUpdateHandler
|
|
57
59
|
}): Promise<FetchSchemasResults> {
|
|
58
60
|
const {
|
|
59
|
-
localSchemaLookupDir: localSchemaDir =
|
|
61
|
+
localSchemaLookupDir: localSchemaDir = DEFAULT_LOCAL_SCHEMA_DIR,
|
|
60
62
|
shouldFetchLocalSchemas = true,
|
|
61
63
|
shouldFetchRemoteSchemas = true,
|
|
62
64
|
shouldEnableVersioning = true,
|
|
@@ -156,15 +158,18 @@ export default class SchemaStore extends AbstractStore {
|
|
|
156
158
|
}
|
|
157
159
|
}
|
|
158
160
|
|
|
161
|
+
public async hasLocalSchemas() {
|
|
162
|
+
const matches = await this.globbyLocalBuilders(DEFAULT_LOCAL_SCHEMA_DIR)
|
|
163
|
+
return matches.length > 0
|
|
164
|
+
}
|
|
165
|
+
|
|
159
166
|
private async loadLocalSchemas(
|
|
160
167
|
localLookupDir: string,
|
|
161
168
|
localNamespace: string,
|
|
162
169
|
shouldEnableVersioning?: boolean,
|
|
163
170
|
didUpdateHandler?: InternalUpdateHandler
|
|
164
171
|
) {
|
|
165
|
-
const localMatches = await
|
|
166
|
-
diskUtil.resolvePath(this.cwd, localLookupDir, '**/*.builder.[t|j]s')
|
|
167
|
-
)
|
|
172
|
+
const localMatches = await this.globbyLocalBuilders(localLookupDir)
|
|
168
173
|
|
|
169
174
|
const errors: SpruceError[] = []
|
|
170
175
|
const schemas: Schema[] = []
|
|
@@ -220,6 +225,12 @@ export default class SchemaStore extends AbstractStore {
|
|
|
220
225
|
}
|
|
221
226
|
}
|
|
222
227
|
|
|
228
|
+
private async globbyLocalBuilders(localLookupDir: string) {
|
|
229
|
+
return await globby(
|
|
230
|
+
diskUtil.resolvePath(this.cwd, localLookupDir, '**/*.builder.[t|j]s')
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
|
|
223
234
|
private resolveLocalVersion(
|
|
224
235
|
shouldEnableVersioning: boolean | undefined,
|
|
225
236
|
local: string,
|