@teambit/component 0.0.881 → 0.0.882
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aspect-entry.js +3 -16
- package/dist/aspect-entry.js.map +1 -1
- package/dist/aspect-list.js +6 -35
- package/dist/aspect-list.js.map +1 -1
- package/dist/aspect.section.js +0 -16
- package/dist/aspect.section.js.map +1 -1
- package/dist/component-fs.js +2 -25
- package/dist/component-fs.js.map +1 -1
- package/dist/component-map/component-map.js +10 -26
- package/dist/component-map/component-map.js.map +1 -1
- package/dist/component-map/index.js +0 -3
- package/dist/component-map/index.js.map +1 -1
- package/dist/component-meta.js +1 -14
- package/dist/component-meta.js.map +1 -1
- package/dist/component.aspect.js +0 -5
- package/dist/component.aspect.js.map +1 -1
- package/dist/component.composition.js +0 -6
- package/dist/component.composition.js.map +1 -1
- package/dist/component.graphql.js +2 -26
- package/dist/component.graphql.js.map +1 -1
- package/dist/component.js +19 -90
- package/dist/component.js.map +1 -1
- package/dist/component.main.runtime.js +6 -64
- package/dist/component.main.runtime.js.map +1 -1
- package/dist/component.route.js +2 -14
- package/dist/component.route.js.map +1 -1
- package/dist/component.ui.runtime.js +3 -83
- package/dist/component.ui.runtime.js.map +1 -1
- package/dist/config.js +0 -3
- package/dist/config.js.map +1 -1
- package/dist/dependencies/dependencies.js +7 -32
- package/dist/dependencies/dependencies.js.map +1 -1
- package/dist/dependencies/index.js +0 -3
- package/dist/dependencies/index.js.map +1 -1
- package/dist/exceptions/could-not-find-latest.js +0 -4
- package/dist/exceptions/could-not-find-latest.js.map +1 -1
- package/dist/exceptions/host-not-found.js +0 -4
- package/dist/exceptions/host-not-found.js.map +1 -1
- package/dist/exceptions/index.js +0 -13
- package/dist/exceptions/index.js.map +1 -1
- package/dist/exceptions/main-file-not-found.js +0 -4
- package/dist/exceptions/main-file-not-found.js.map +1 -1
- package/dist/exceptions/nothing-to-snap.js +0 -2
- package/dist/exceptions/nothing-to-snap.js.map +1 -1
- package/dist/history-graph.js +0 -2
- package/dist/history-graph.js.map +1 -1
- package/dist/host/component-host-model.js +0 -7
- package/dist/host/component-host-model.js.map +1 -1
- package/dist/host/index.js +0 -5
- package/dist/host/index.js.map +1 -1
- package/dist/host/use-component-host.js +0 -14
- package/dist/host/use-component-host.js.map +1 -1
- package/dist/index.js +0 -63
- package/dist/index.js.map +1 -1
- package/dist/section/index.js +0 -3
- package/dist/section/index.js.map +1 -1
- package/dist/show/extensions.fragment.js +0 -8
- package/dist/show/extensions.fragment.js.map +1 -1
- package/dist/show/files.fragment.js +0 -11
- package/dist/show/files.fragment.js.map +1 -1
- package/dist/show/id.fragment.js +0 -10
- package/dist/show/id.fragment.js.map +1 -1
- package/dist/show/index.js +0 -24
- package/dist/show/index.js.map +1 -1
- package/dist/show/main-file.fragment.js +0 -9
- package/dist/show/main-file.fragment.js.map +1 -1
- package/dist/show/name.fragment.js +0 -9
- package/dist/show/name.fragment.js.map +1 -1
- package/dist/show/scope.fragment.js +0 -10
- package/dist/show/scope.fragment.js.map +1 -1
- package/dist/show/show.cmd.js +1 -33
- package/dist/show/show.cmd.js.map +1 -1
- package/dist/snap/index.js +0 -6
- package/dist/snap/index.js.map +1 -1
- package/dist/snap/snap.js +0 -5
- package/dist/snap/snap.js.map +1 -1
- package/dist/state.js +6 -24
- package/dist/state.js.map +1 -1
- package/dist/store.js +0 -5
- package/dist/store.js.map +1 -1
- package/dist/tag/index.js +0 -3
- package/dist/tag/index.js.map +1 -1
- package/dist/tag/tag.js +1 -9
- package/dist/tag/tag.js.map +1 -1
- package/dist/tag-map.js +4 -28
- package/dist/tag-map.js.map +1 -1
- package/dist/ui/aspect-page/aspect-page.js +2 -35
- package/dist/ui/aspect-page/aspect-page.js.map +1 -1
- package/dist/ui/aspect-page/index.js +0 -3
- package/dist/ui/aspect-page/index.js.map +1 -1
- package/dist/ui/component-error/component-error.js +0 -14
- package/dist/ui/component-error/component-error.js.map +1 -1
- package/dist/ui/component-error/index.js +0 -3
- package/dist/ui/component-error/index.js.map +1 -1
- package/dist/ui/component-model/component-model.js +2 -21
- package/dist/ui/component-model/component-model.js.map +1 -1
- package/dist/ui/component-model/index.js +0 -3
- package/dist/ui/component-model/index.js.map +1 -1
- package/dist/ui/component-searcher/component-result.js +0 -20
- package/dist/ui/component-searcher/component-result.js.map +1 -1
- package/dist/ui/component-searcher/component-searcher.js +0 -22
- package/dist/ui/component-searcher/component-searcher.js.map +1 -1
- package/dist/ui/component-searcher/index.js +0 -3
- package/dist/ui/component-searcher/index.js.map +1 -1
- package/dist/ui/component.js +5 -40
- package/dist/ui/component.js.map +1 -1
- package/dist/ui/context/component-context.js +0 -9
- package/dist/ui/context/component-context.js.map +1 -1
- package/dist/ui/context/component-provider.js +0 -9
- package/dist/ui/context/component-provider.js.map +1 -1
- package/dist/ui/context/index.js +0 -6
- package/dist/ui/context/index.js.map +1 -1
- package/dist/ui/index.js +0 -21
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/menu/index.js +0 -3
- package/dist/ui/menu/index.js.map +1 -1
- package/dist/ui/menu/menu-nav.js +4 -23
- package/dist/ui/menu/menu-nav.js.map +1 -1
- package/dist/ui/menu/menu.js +0 -70
- package/dist/ui/menu/menu.js.map +1 -1
- package/dist/ui/menu/mobile-menu-nav.js +6 -49
- package/dist/ui/menu/mobile-menu-nav.js.map +1 -1
- package/dist/ui/top-bar-nav/index.js +0 -2
- package/dist/ui/top-bar-nav/index.js.map +1 -1
- package/dist/ui/top-bar-nav/top-bar-nav.js +8 -32
- package/dist/ui/top-bar-nav/top-bar-nav.js.map +1 -1
- package/dist/ui/use-component-from-location.js +0 -9
- package/dist/ui/use-component-from-location.js.map +1 -1
- package/dist/ui/use-component-query.js +12 -60
- package/dist/ui/use-component-query.js.map +1 -1
- package/dist/ui/use-component.js +0 -11
- package/dist/ui/use-component.js.map +1 -1
- package/package-tar/teambit-component-0.0.882.tgz +0 -0
- package/package.json +12 -12
- package/{preview-1666409808293.js → preview-1666496165706.js} +2 -2
- package/package-tar/teambit-component-0.0.881.tgz +0 -0
|
@@ -1,136 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.array.iterator.js");
|
|
6
|
-
|
|
7
5
|
require("core-js/modules/es.promise.js");
|
|
8
|
-
|
|
9
6
|
Object.defineProperty(exports, "__esModule", {
|
|
10
7
|
value: true
|
|
11
8
|
});
|
|
12
9
|
exports.ComponentMain = void 0;
|
|
13
|
-
|
|
14
10
|
function _defineProperty2() {
|
|
15
11
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
-
|
|
17
12
|
_defineProperty2 = function () {
|
|
18
13
|
return data;
|
|
19
14
|
};
|
|
20
|
-
|
|
21
15
|
return data;
|
|
22
16
|
}
|
|
23
|
-
|
|
24
17
|
function _cli() {
|
|
25
18
|
const data = require("@teambit/cli");
|
|
26
|
-
|
|
27
19
|
_cli = function () {
|
|
28
20
|
return data;
|
|
29
21
|
};
|
|
30
|
-
|
|
31
22
|
return data;
|
|
32
23
|
}
|
|
33
|
-
|
|
34
24
|
function _express() {
|
|
35
25
|
const data = require("@teambit/express");
|
|
36
|
-
|
|
37
26
|
_express = function () {
|
|
38
27
|
return data;
|
|
39
28
|
};
|
|
40
|
-
|
|
41
29
|
return data;
|
|
42
30
|
}
|
|
43
|
-
|
|
44
31
|
function _graphql() {
|
|
45
32
|
const data = require("@teambit/graphql");
|
|
46
|
-
|
|
47
33
|
_graphql = function () {
|
|
48
34
|
return data;
|
|
49
35
|
};
|
|
50
|
-
|
|
51
36
|
return data;
|
|
52
37
|
}
|
|
53
|
-
|
|
54
38
|
function _harmony() {
|
|
55
39
|
const data = require("@teambit/harmony");
|
|
56
|
-
|
|
57
40
|
_harmony = function () {
|
|
58
41
|
return data;
|
|
59
42
|
};
|
|
60
|
-
|
|
61
43
|
return data;
|
|
62
44
|
}
|
|
63
|
-
|
|
64
45
|
function _lodash() {
|
|
65
46
|
const data = require("lodash");
|
|
66
|
-
|
|
67
47
|
_lodash = function () {
|
|
68
48
|
return data;
|
|
69
49
|
};
|
|
70
|
-
|
|
71
50
|
return data;
|
|
72
51
|
}
|
|
73
|
-
|
|
74
52
|
function _component() {
|
|
75
53
|
const data = require("./component.aspect");
|
|
76
|
-
|
|
77
54
|
_component = function () {
|
|
78
55
|
return data;
|
|
79
56
|
};
|
|
80
|
-
|
|
81
57
|
return data;
|
|
82
58
|
}
|
|
83
|
-
|
|
84
59
|
function _component2() {
|
|
85
60
|
const data = require("./component.graphql");
|
|
86
|
-
|
|
87
61
|
_component2 = function () {
|
|
88
62
|
return data;
|
|
89
63
|
};
|
|
90
|
-
|
|
91
64
|
return data;
|
|
92
65
|
}
|
|
93
|
-
|
|
94
66
|
function _component3() {
|
|
95
67
|
const data = require("./component.route");
|
|
96
|
-
|
|
97
68
|
_component3 = function () {
|
|
98
69
|
return data;
|
|
99
70
|
};
|
|
100
|
-
|
|
101
71
|
return data;
|
|
102
72
|
}
|
|
103
|
-
|
|
104
73
|
function _aspectList() {
|
|
105
74
|
const data = require("./aspect-list");
|
|
106
|
-
|
|
107
75
|
_aspectList = function () {
|
|
108
76
|
return data;
|
|
109
77
|
};
|
|
110
|
-
|
|
111
78
|
return data;
|
|
112
79
|
}
|
|
113
|
-
|
|
114
80
|
function _exceptions() {
|
|
115
81
|
const data = require("./exceptions");
|
|
116
|
-
|
|
117
82
|
_exceptions = function () {
|
|
118
83
|
return data;
|
|
119
84
|
};
|
|
120
|
-
|
|
121
85
|
return data;
|
|
122
86
|
}
|
|
123
|
-
|
|
124
87
|
function _show() {
|
|
125
88
|
const data = require("./show");
|
|
126
|
-
|
|
127
89
|
_show = function () {
|
|
128
90
|
return data;
|
|
129
91
|
};
|
|
130
|
-
|
|
131
92
|
return data;
|
|
132
93
|
}
|
|
133
|
-
|
|
134
94
|
class ComponentMain {
|
|
135
95
|
constructor(
|
|
136
96
|
/**
|
|
@@ -146,15 +106,15 @@ class ComponentMain {
|
|
|
146
106
|
this.showFragmentSlot = showFragmentSlot;
|
|
147
107
|
(0, _defineProperty2().default)(this, "_priorHost", void 0);
|
|
148
108
|
}
|
|
109
|
+
|
|
149
110
|
/**
|
|
150
111
|
* register a new component host.
|
|
151
112
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
154
113
|
registerHost(host) {
|
|
155
114
|
this.hostSlot.register(host);
|
|
156
115
|
return this;
|
|
157
116
|
}
|
|
117
|
+
|
|
158
118
|
/**
|
|
159
119
|
* important! avoid using this method.
|
|
160
120
|
* seems like this method was written to work around a very specific case when the ComponentID of the aspects are
|
|
@@ -165,16 +125,12 @@ class ComponentMain {
|
|
|
165
125
|
* to fix this possibly incorrect scope-name, the `workspace.resolveScopeAspectListIds()` checks whether the
|
|
166
126
|
* scope-name is the same as scope.name, and if so, resolve it to the correct scope-name.
|
|
167
127
|
*/
|
|
168
|
-
|
|
169
|
-
|
|
170
128
|
createAspectListFromLegacy(legacyExtensionDataList, scope) {
|
|
171
129
|
return _aspectList().AspectList.fromLegacyExtensions(legacyExtensionDataList, scope);
|
|
172
130
|
}
|
|
173
|
-
|
|
174
131
|
createAspectListFromEntries(entries) {
|
|
175
132
|
return new (_aspectList().AspectList)(entries);
|
|
176
133
|
}
|
|
177
|
-
|
|
178
134
|
registerRoute(routes) {
|
|
179
135
|
const routeEntries = routes.map(route => {
|
|
180
136
|
return new (_component3().ComponentRoute)(route, this);
|
|
@@ -183,69 +139,58 @@ class ComponentMain {
|
|
|
183
139
|
this.express.register(flattenRoutes);
|
|
184
140
|
return this;
|
|
185
141
|
}
|
|
142
|
+
|
|
186
143
|
/**
|
|
187
144
|
* set the prior host.
|
|
188
145
|
*/
|
|
189
|
-
|
|
190
|
-
|
|
191
146
|
setHostPriority(id) {
|
|
192
147
|
const host = this.hostSlot.get(id);
|
|
193
|
-
|
|
194
148
|
if (!host) {
|
|
195
149
|
throw new (_exceptions().HostNotFound)(id);
|
|
196
150
|
}
|
|
197
|
-
|
|
198
151
|
this._priorHost = host;
|
|
199
152
|
return this;
|
|
200
153
|
}
|
|
154
|
+
|
|
201
155
|
/**
|
|
202
156
|
* get component host by extension ID.
|
|
203
157
|
*/
|
|
204
|
-
|
|
205
|
-
|
|
206
158
|
getHost(id) {
|
|
207
159
|
if (id) {
|
|
208
160
|
const host = this.hostSlot.get(id);
|
|
209
161
|
if (!host) throw new (_exceptions().HostNotFound)(id);
|
|
210
162
|
return host;
|
|
211
163
|
}
|
|
212
|
-
|
|
213
164
|
return this.getPriorHost();
|
|
214
165
|
}
|
|
215
|
-
|
|
216
166
|
getRoute(id, routeName) {
|
|
217
167
|
return `/api/${id.toString()}/~aspect/${routeName}`;
|
|
218
168
|
}
|
|
169
|
+
|
|
219
170
|
/**
|
|
220
171
|
* get the prior host.
|
|
221
172
|
*/
|
|
222
|
-
|
|
223
|
-
|
|
224
173
|
getPriorHost() {
|
|
225
174
|
if (this._priorHost) return this._priorHost;
|
|
226
175
|
const hosts = this.hostSlot.values();
|
|
227
176
|
const priorityHost = hosts.find(host => host.priority);
|
|
228
177
|
return priorityHost || hosts[0];
|
|
229
178
|
}
|
|
230
|
-
|
|
231
179
|
getShowFragments() {
|
|
232
180
|
const fragments = (0, _lodash().orderBy)((0, _lodash().flatten)(this.showFragmentSlot.values()), ['weight', ['asc']]);
|
|
233
181
|
return fragments;
|
|
234
182
|
}
|
|
235
|
-
|
|
236
183
|
isHost(name) {
|
|
237
184
|
return !!this.hostSlot.get(name);
|
|
238
185
|
}
|
|
186
|
+
|
|
239
187
|
/**
|
|
240
188
|
* register a show fragment to display further information in the `bit show` command.
|
|
241
189
|
*/
|
|
242
|
-
|
|
243
|
-
|
|
244
190
|
registerShowFragments(showFragments) {
|
|
245
191
|
this.showFragmentSlot.register(showFragments);
|
|
246
192
|
return this;
|
|
247
193
|
}
|
|
248
|
-
|
|
249
194
|
static async provider([graphql, express, cli], config, [hostSlot, showFragmentSlot]) {
|
|
250
195
|
const componentExtension = new ComponentMain(hostSlot, express, showFragmentSlot);
|
|
251
196
|
cli.register(new (_show().ShowCmd)(componentExtension));
|
|
@@ -253,14 +198,11 @@ class ComponentMain {
|
|
|
253
198
|
graphql.register((0, _component2().componentSchema)(componentExtension));
|
|
254
199
|
return componentExtension;
|
|
255
200
|
}
|
|
256
|
-
|
|
257
201
|
}
|
|
258
|
-
|
|
259
202
|
exports.ComponentMain = ComponentMain;
|
|
260
203
|
(0, _defineProperty2().default)(ComponentMain, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType()]);
|
|
261
204
|
(0, _defineProperty2().default)(ComponentMain, "runtime", _cli().MainRuntime);
|
|
262
205
|
(0, _defineProperty2().default)(ComponentMain, "dependencies", [_graphql().GraphqlAspect, _express().ExpressAspect, _cli().CLIAspect]);
|
|
263
|
-
|
|
264
206
|
_component().ComponentAspect.addRuntime(ComponentMain);
|
|
265
207
|
|
|
266
208
|
//# sourceMappingURL=component.main.runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ComponentMain","constructor","hostSlot","express","showFragmentSlot","registerHost","host","register","createAspectListFromLegacy","legacyExtensionDataList","scope","AspectList","fromLegacyExtensions","createAspectListFromEntries","entries","registerRoute","routes","routeEntries","map","route","ComponentRoute","flattenRoutes","flatten","setHostPriority","id","get","HostNotFound","_priorHost","getHost","getPriorHost","getRoute","routeName","toString","hosts","values","priorityHost","find","priority","getShowFragments","fragments","orderBy","isHost","name","registerShowFragments","showFragments","provider","graphql","cli","config","componentExtension","ShowCmd","NameFragment","MainFileFragment","IDFragment","ScopeFragment","FilesFragment","ExtensionsFragment","componentSchema","Slot","withType","MainRuntime","GraphqlAspect","ExpressAspect","CLIAspect","ComponentAspect","addRuntime"],"sources":["component.main.runtime.ts"],"sourcesContent":["import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { ExpressAspect, ExpressMain, Route } from '@teambit/express';\nimport { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { ComponentID } from '@teambit/component-id';\nimport { flatten, orderBy } from 'lodash';\nimport { ExtensionDataList } from '@teambit/legacy/dist/consumer/config';\nimport { ComponentFactory } from './component-factory';\nimport { ComponentAspect } from './component.aspect';\nimport { componentSchema } from './component.graphql';\nimport { ComponentRoute } from './component.route';\nimport { AspectList } from './aspect-list';\nimport { HostNotFound } from './exceptions';\nimport { AspectEntry } from './aspect-entry';\nimport {\n ShowCmd,\n ShowFragment,\n NameFragment,\n MainFileFragment,\n IDFragment,\n ScopeFragment,\n FilesFragment,\n ExtensionsFragment,\n} from './show';\nimport { RegisteredComponentRoute } from '.';\n\nexport type ComponentHostSlot = SlotRegistry<ComponentFactory>;\n\nexport type ShowFragmentSlot = SlotRegistry<ShowFragment[]>;\n\nexport class ComponentMain {\n constructor(\n /**\n * slot for component hosts to register.\n */\n private hostSlot: ComponentHostSlot,\n\n /**\n * Express Extension\n */\n private express: ExpressMain,\n\n private showFragmentSlot: ShowFragmentSlot\n ) {}\n\n /**\n * register a new component host.\n */\n registerHost(host: ComponentFactory) {\n this.hostSlot.register(host);\n return this;\n }\n\n /**\n * important! avoid using this method.\n * seems like this method was written to work around a very specific case when the ComponentID of the aspects are\n * not available. in case of new components, to get the ComponentID, the workspace-aspect is needed to get the\n * default-scope. when this method is called from the scope, there is no way to get the real component-id.\n * instead, this method asks for the \"scope\", which when called by the scope-aspect is the current scope-name.\n * it may or may not be the real scope-name of the aspect.\n * to fix this possibly incorrect scope-name, the `workspace.resolveScopeAspectListIds()` checks whether the\n * scope-name is the same as scope.name, and if so, resolve it to the correct scope-name.\n */\n createAspectListFromLegacy(legacyExtensionDataList: ExtensionDataList, scope?: string) {\n return AspectList.fromLegacyExtensions(legacyExtensionDataList, scope);\n }\n\n createAspectListFromEntries(entries: AspectEntry[]) {\n return new AspectList(entries);\n }\n\n registerRoute(routes: RegisteredComponentRoute[]) {\n const routeEntries = routes.map((route: RegisteredComponentRoute) => {\n return new ComponentRoute(route, this);\n });\n\n const flattenRoutes = flatten(routeEntries) as any as Route[];\n\n this.express.register(flattenRoutes);\n return this;\n }\n\n /**\n * set the prior host.\n */\n setHostPriority(id: string) {\n const host = this.hostSlot.get(id);\n if (!host) {\n throw new HostNotFound(id);\n }\n\n this._priorHost = host;\n return this;\n }\n\n /**\n * get component host by extension ID.\n */\n getHost(id?: string): ComponentFactory {\n if (id) {\n const host = this.hostSlot.get(id);\n if (!host) throw new HostNotFound(id);\n return host;\n }\n\n return this.getPriorHost();\n }\n\n getRoute(id: ComponentID, routeName: string) {\n return `/api/${id.toString()}/~aspect/${routeName}`;\n }\n\n /**\n * get the prior host.\n */\n private getPriorHost() {\n if (this._priorHost) return this._priorHost;\n\n const hosts = this.hostSlot.values();\n const priorityHost = hosts.find((host) => host.priority);\n return priorityHost || hosts[0];\n }\n\n getShowFragments() {\n const fragments = orderBy(flatten(this.showFragmentSlot.values()), ['weight', ['asc']]);\n return fragments;\n }\n\n isHost(name: string) {\n return !!this.hostSlot.get(name);\n }\n\n /**\n * register a show fragment to display further information in the `bit show` command.\n */\n registerShowFragments(showFragments: ShowFragment[]) {\n this.showFragmentSlot.register(showFragments);\n return this;\n }\n\n private _priorHost: ComponentFactory | undefined;\n\n static slots = [Slot.withType<ComponentFactory>(), Slot.withType<Route[]>(), Slot.withType<ShowFragment[]>()];\n\n static runtime = MainRuntime;\n static dependencies = [GraphqlAspect, ExpressAspect, CLIAspect];\n\n static async provider(\n [graphql, express, cli]: [GraphqlMain, ExpressMain, CLIMain],\n config,\n [hostSlot, showFragmentSlot]: [ComponentHostSlot, ShowFragmentSlot]\n ) {\n const componentExtension = new ComponentMain(hostSlot, express, showFragmentSlot);\n cli.register(new ShowCmd(componentExtension));\n\n componentExtension.registerShowFragments([\n new NameFragment(),\n new MainFileFragment(),\n new IDFragment(),\n new ScopeFragment(),\n new FilesFragment(),\n new ExtensionsFragment(),\n ]);\n graphql.register(componentSchema(componentExtension));\n\n return componentExtension;\n }\n}\n\nComponentAspect.addRuntime(ComponentMain);\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["ComponentMain","constructor","hostSlot","express","showFragmentSlot","registerHost","host","register","createAspectListFromLegacy","legacyExtensionDataList","scope","AspectList","fromLegacyExtensions","createAspectListFromEntries","entries","registerRoute","routes","routeEntries","map","route","ComponentRoute","flattenRoutes","flatten","setHostPriority","id","get","HostNotFound","_priorHost","getHost","getPriorHost","getRoute","routeName","toString","hosts","values","priorityHost","find","priority","getShowFragments","fragments","orderBy","isHost","name","registerShowFragments","showFragments","provider","graphql","cli","config","componentExtension","ShowCmd","NameFragment","MainFileFragment","IDFragment","ScopeFragment","FilesFragment","ExtensionsFragment","componentSchema","Slot","withType","MainRuntime","GraphqlAspect","ExpressAspect","CLIAspect","ComponentAspect","addRuntime"],"sources":["component.main.runtime.ts"],"sourcesContent":["import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { ExpressAspect, ExpressMain, Route } from '@teambit/express';\nimport { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { ComponentID } from '@teambit/component-id';\nimport { flatten, orderBy } from 'lodash';\nimport { ExtensionDataList } from '@teambit/legacy/dist/consumer/config';\nimport { ComponentFactory } from './component-factory';\nimport { ComponentAspect } from './component.aspect';\nimport { componentSchema } from './component.graphql';\nimport { ComponentRoute } from './component.route';\nimport { AspectList } from './aspect-list';\nimport { HostNotFound } from './exceptions';\nimport { AspectEntry } from './aspect-entry';\nimport {\n ShowCmd,\n ShowFragment,\n NameFragment,\n MainFileFragment,\n IDFragment,\n ScopeFragment,\n FilesFragment,\n ExtensionsFragment,\n} from './show';\nimport { RegisteredComponentRoute } from '.';\n\nexport type ComponentHostSlot = SlotRegistry<ComponentFactory>;\n\nexport type ShowFragmentSlot = SlotRegistry<ShowFragment[]>;\n\nexport class ComponentMain {\n constructor(\n /**\n * slot for component hosts to register.\n */\n private hostSlot: ComponentHostSlot,\n\n /**\n * Express Extension\n */\n private express: ExpressMain,\n\n private showFragmentSlot: ShowFragmentSlot\n ) {}\n\n /**\n * register a new component host.\n */\n registerHost(host: ComponentFactory) {\n this.hostSlot.register(host);\n return this;\n }\n\n /**\n * important! avoid using this method.\n * seems like this method was written to work around a very specific case when the ComponentID of the aspects are\n * not available. in case of new components, to get the ComponentID, the workspace-aspect is needed to get the\n * default-scope. when this method is called from the scope, there is no way to get the real component-id.\n * instead, this method asks for the \"scope\", which when called by the scope-aspect is the current scope-name.\n * it may or may not be the real scope-name of the aspect.\n * to fix this possibly incorrect scope-name, the `workspace.resolveScopeAspectListIds()` checks whether the\n * scope-name is the same as scope.name, and if so, resolve it to the correct scope-name.\n */\n createAspectListFromLegacy(legacyExtensionDataList: ExtensionDataList, scope?: string) {\n return AspectList.fromLegacyExtensions(legacyExtensionDataList, scope);\n }\n\n createAspectListFromEntries(entries: AspectEntry[]) {\n return new AspectList(entries);\n }\n\n registerRoute(routes: RegisteredComponentRoute[]) {\n const routeEntries = routes.map((route: RegisteredComponentRoute) => {\n return new ComponentRoute(route, this);\n });\n\n const flattenRoutes = flatten(routeEntries) as any as Route[];\n\n this.express.register(flattenRoutes);\n return this;\n }\n\n /**\n * set the prior host.\n */\n setHostPriority(id: string) {\n const host = this.hostSlot.get(id);\n if (!host) {\n throw new HostNotFound(id);\n }\n\n this._priorHost = host;\n return this;\n }\n\n /**\n * get component host by extension ID.\n */\n getHost(id?: string): ComponentFactory {\n if (id) {\n const host = this.hostSlot.get(id);\n if (!host) throw new HostNotFound(id);\n return host;\n }\n\n return this.getPriorHost();\n }\n\n getRoute(id: ComponentID, routeName: string) {\n return `/api/${id.toString()}/~aspect/${routeName}`;\n }\n\n /**\n * get the prior host.\n */\n private getPriorHost() {\n if (this._priorHost) return this._priorHost;\n\n const hosts = this.hostSlot.values();\n const priorityHost = hosts.find((host) => host.priority);\n return priorityHost || hosts[0];\n }\n\n getShowFragments() {\n const fragments = orderBy(flatten(this.showFragmentSlot.values()), ['weight', ['asc']]);\n return fragments;\n }\n\n isHost(name: string) {\n return !!this.hostSlot.get(name);\n }\n\n /**\n * register a show fragment to display further information in the `bit show` command.\n */\n registerShowFragments(showFragments: ShowFragment[]) {\n this.showFragmentSlot.register(showFragments);\n return this;\n }\n\n private _priorHost: ComponentFactory | undefined;\n\n static slots = [Slot.withType<ComponentFactory>(), Slot.withType<Route[]>(), Slot.withType<ShowFragment[]>()];\n\n static runtime = MainRuntime;\n static dependencies = [GraphqlAspect, ExpressAspect, CLIAspect];\n\n static async provider(\n [graphql, express, cli]: [GraphqlMain, ExpressMain, CLIMain],\n config,\n [hostSlot, showFragmentSlot]: [ComponentHostSlot, ShowFragmentSlot]\n ) {\n const componentExtension = new ComponentMain(hostSlot, express, showFragmentSlot);\n cli.register(new ShowCmd(componentExtension));\n\n componentExtension.registerShowFragments([\n new NameFragment(),\n new MainFileFragment(),\n new IDFragment(),\n new ScopeFragment(),\n new FilesFragment(),\n new ExtensionsFragment(),\n ]);\n graphql.register(componentSchema(componentExtension));\n\n return componentExtension;\n }\n}\n\nComponentAspect.addRuntime(ComponentMain);\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAgBO,MAAMA,aAA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EAC5DC,MAAM,EACN,CAAC9C,QAAQ,EAAEE,gBAAgB,CAAwC,EACnE;IACA,MAAM6C,kBAAkB,GAAG,IAAIjD,aAAa,CAACE,QAAQ,EAAEC,OAAO,EAAEC,gBAAgB,CAAC;IACjF2C,GAAG,CAACxC,QAAQ,CAAC,KAAI2C,eAAO,EAACD,kBAAkB,CAAC,CAAC;IAE7CA,kBAAkB,CAACN,qBAAqB,CAAC,CACvC,KAAIQ,oBAAY,GAAE,EAClB,KAAIC,wBAAgB,GAAE,EACtB,KAAIC,kBAAU,GAAE,EAChB,KAAIC,qBAAa,GAAE,EACnB,KAAIC,qBAAa,GAAE,EACnB,KAAIC,0BAAkB,GAAE,CACzB,CAAC;IACFV,OAAO,CAACvC,QAAQ,CAAC,IAAAkD,6BAAe,EAACR,kBAAkB,CAAC,CAAC;IAErD,OAAOA,kBAAkB;EAC3B;AACF;AAAC;AAAA,gCAzIYjD,aAAa,WAgHT,CAAC0D,eAAI,CAACC,QAAQ,EAAoB,EAAED,eAAI,CAACC,QAAQ,EAAW,EAAED,eAAI,CAACC,QAAQ,EAAkB,CAAC;AAAA,gCAhHlG3D,aAAa,aAkHP4D,kBAAW;AAAA,gCAlHjB5D,aAAa,kBAmHF,CAAC6D,wBAAa,EAAEC,wBAAa,EAAEC,gBAAS,CAAC;AAwBjEC,4BAAe,CAACC,UAAU,CAACjE,aAAa,CAAC"}
|
package/dist/component.route.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.promise.js");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.ComponentRoute = void 0;
|
|
11
|
-
|
|
12
9
|
function _defineProperty2() {
|
|
13
10
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
|
|
15
11
|
_defineProperty2 = function () {
|
|
16
12
|
return data;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
return data;
|
|
20
15
|
}
|
|
21
|
-
|
|
22
16
|
class ComponentRoute {
|
|
23
17
|
constructor(registerRoute, componentExtension) {
|
|
24
18
|
this.registerRoute = registerRoute;
|
|
@@ -28,30 +22,24 @@ class ComponentRoute {
|
|
|
28
22
|
(0, _defineProperty2().default)(this, "method", this.registerRoute.method);
|
|
29
23
|
(0, _defineProperty2().default)(this, "middlewares", this.componentMiddlewares.concat(this.registerRoute.middlewares));
|
|
30
24
|
}
|
|
31
|
-
|
|
32
25
|
get componentMiddlewares() {
|
|
33
26
|
return [async (req, res, next) => {
|
|
34
27
|
var _this$registerRoute$r;
|
|
35
|
-
|
|
36
28
|
const resolveComponent = (_this$registerRoute$r = this.registerRoute.resolveComponent) !== null && _this$registerRoute$r !== void 0 ? _this$registerRoute$r : true;
|
|
37
|
-
|
|
38
29
|
if (resolveComponent) {
|
|
39
30
|
const {
|
|
40
31
|
componentId
|
|
41
32
|
} = req.params;
|
|
42
33
|
const host = this.componentExtension.getHost();
|
|
43
34
|
const compId = await host.resolveComponentId(componentId);
|
|
44
|
-
const component = await host.get(compId);
|
|
45
|
-
|
|
35
|
+
const component = await host.get(compId);
|
|
36
|
+
// @ts-ignore
|
|
46
37
|
req.component = component;
|
|
47
38
|
}
|
|
48
|
-
|
|
49
39
|
next();
|
|
50
40
|
}];
|
|
51
41
|
}
|
|
52
|
-
|
|
53
42
|
}
|
|
54
|
-
|
|
55
43
|
exports.ComponentRoute = ComponentRoute;
|
|
56
44
|
|
|
57
45
|
//# sourceMappingURL=component.route.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ComponentRoute","constructor","registerRoute","componentExtension","dynamicRouteRegex","route","method","componentMiddlewares","concat","middlewares","req","res","next","resolveComponent","componentId","params","host","getHost","compId","resolveComponentId","component","get"],"sources":["component.route.ts"],"sourcesContent":["import { NextFunction, Request, Response, Route } from '@teambit/express';\n\nimport { ComponentMain } from './component.main.runtime';\n\nexport type RegisteredComponentRoute = Route & {\n resolveComponent?: boolean;\n};\n\nexport type ComponentUrlParams = {\n componentId: string;\n};\n\nexport class ComponentRoute implements Route {\n constructor(private registerRoute: RegisteredComponentRoute, private componentExtension: ComponentMain) {}\n dynamicRouteRegex = '/?[^/@]+/[^~]*';\n readonly route = `/:componentId(${this.dynamicRouteRegex})/~aspect${this.registerRoute.route}`;\n\n get componentMiddlewares() {\n return [\n async (req: Request<ComponentUrlParams>, res: Response, next: NextFunction) => {\n const resolveComponent = this.registerRoute.resolveComponent ?? true;\n if (resolveComponent) {\n const { componentId } = req.params;\n const host = this.componentExtension.getHost();\n const compId = await host.resolveComponentId(componentId);\n const component = await host.get(compId);\n // @ts-ignore\n req.component = component;\n }\n next();\n },\n ];\n }\n\n method = this.registerRoute.method;\n // @ts-ignore\n middlewares = this.componentMiddlewares.concat(this.registerRoute.middlewares);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["ComponentRoute","constructor","registerRoute","componentExtension","dynamicRouteRegex","route","method","componentMiddlewares","concat","middlewares","req","res","next","resolveComponent","componentId","params","host","getHost","compId","resolveComponentId","component","get"],"sources":["component.route.ts"],"sourcesContent":["import { NextFunction, Request, Response, Route } from '@teambit/express';\n\nimport { ComponentMain } from './component.main.runtime';\n\nexport type RegisteredComponentRoute = Route & {\n resolveComponent?: boolean;\n};\n\nexport type ComponentUrlParams = {\n componentId: string;\n};\n\nexport class ComponentRoute implements Route {\n constructor(private registerRoute: RegisteredComponentRoute, private componentExtension: ComponentMain) {}\n dynamicRouteRegex = '/?[^/@]+/[^~]*';\n readonly route = `/:componentId(${this.dynamicRouteRegex})/~aspect${this.registerRoute.route}`;\n\n get componentMiddlewares() {\n return [\n async (req: Request<ComponentUrlParams>, res: Response, next: NextFunction) => {\n const resolveComponent = this.registerRoute.resolveComponent ?? true;\n if (resolveComponent) {\n const { componentId } = req.params;\n const host = this.componentExtension.getHost();\n const compId = await host.resolveComponentId(componentId);\n const component = await host.get(compId);\n // @ts-ignore\n req.component = component;\n }\n next();\n },\n ];\n }\n\n method = this.registerRoute.method;\n // @ts-ignore\n middlewares = this.componentMiddlewares.concat(this.registerRoute.middlewares);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAYO,MAAMA,cAAc,CAAkB;EAC3CC,WAAW,CAASC,aAAuC,EAAUC,kBAAiC,EAAE;IAAA,KAApFD,aAAuC,GAAvCA,aAAuC;IAAA,KAAUC,kBAAiC,GAAjCA,kBAAiC;IAAA,2DAClF,gBAAgB;IAAA,+CAClB,iBAAgB,IAAI,CAACC,iBAAkB,YAAW,IAAI,CAACF,aAAa,CAACG,KAAM,EAAC;IAAA,gDAmBrF,IAAI,CAACH,aAAa,CAACI,MAAM;IAAA,qDAEpB,IAAI,CAACC,oBAAoB,CAACC,MAAM,CAAC,IAAI,CAACN,aAAa,CAACO,WAAW,CAAC;EAvB2B;EAIzG,IAAIF,oBAAoB,GAAG;IACzB,OAAO,CACL,OAAOG,GAAgC,EAAEC,GAAa,EAAEC,IAAkB,KAAK;MAAA;MAC7E,MAAMC,gBAAgB,4BAAG,IAAI,CAACX,aAAa,CAACW,gBAAgB,yEAAI,IAAI;MACpE,IAAIA,gBAAgB,EAAE;QACpB,MAAM;UAAEC;QAAY,CAAC,GAAGJ,GAAG,CAACK,MAAM;QAClC,MAAMC,IAAI,GAAG,IAAI,CAACb,kBAAkB,CAACc,OAAO,EAAE;QAC9C,MAAMC,MAAM,GAAG,MAAMF,IAAI,CAACG,kBAAkB,CAACL,WAAW,CAAC;QACzD,MAAMM,SAAS,GAAG,MAAMJ,IAAI,CAACK,GAAG,CAACH,MAAM,CAAC;QACxC;QACAR,GAAG,CAACU,SAAS,GAAGA,SAAS;MAC3B;MACAR,IAAI,EAAE;IACR,CAAC,CACF;EACH;AAKF;AAAC"}
|