@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.
Files changed (136) hide show
  1. package/dist/aspect-entry.js +3 -16
  2. package/dist/aspect-entry.js.map +1 -1
  3. package/dist/aspect-list.js +6 -35
  4. package/dist/aspect-list.js.map +1 -1
  5. package/dist/aspect.section.js +0 -16
  6. package/dist/aspect.section.js.map +1 -1
  7. package/dist/component-fs.js +2 -25
  8. package/dist/component-fs.js.map +1 -1
  9. package/dist/component-map/component-map.js +10 -26
  10. package/dist/component-map/component-map.js.map +1 -1
  11. package/dist/component-map/index.js +0 -3
  12. package/dist/component-map/index.js.map +1 -1
  13. package/dist/component-meta.js +1 -14
  14. package/dist/component-meta.js.map +1 -1
  15. package/dist/component.aspect.js +0 -5
  16. package/dist/component.aspect.js.map +1 -1
  17. package/dist/component.composition.js +0 -6
  18. package/dist/component.composition.js.map +1 -1
  19. package/dist/component.graphql.js +2 -26
  20. package/dist/component.graphql.js.map +1 -1
  21. package/dist/component.js +19 -90
  22. package/dist/component.js.map +1 -1
  23. package/dist/component.main.runtime.js +6 -64
  24. package/dist/component.main.runtime.js.map +1 -1
  25. package/dist/component.route.js +2 -14
  26. package/dist/component.route.js.map +1 -1
  27. package/dist/component.ui.runtime.js +3 -83
  28. package/dist/component.ui.runtime.js.map +1 -1
  29. package/dist/config.js +0 -3
  30. package/dist/config.js.map +1 -1
  31. package/dist/dependencies/dependencies.js +7 -32
  32. package/dist/dependencies/dependencies.js.map +1 -1
  33. package/dist/dependencies/index.js +0 -3
  34. package/dist/dependencies/index.js.map +1 -1
  35. package/dist/exceptions/could-not-find-latest.js +0 -4
  36. package/dist/exceptions/could-not-find-latest.js.map +1 -1
  37. package/dist/exceptions/host-not-found.js +0 -4
  38. package/dist/exceptions/host-not-found.js.map +1 -1
  39. package/dist/exceptions/index.js +0 -13
  40. package/dist/exceptions/index.js.map +1 -1
  41. package/dist/exceptions/main-file-not-found.js +0 -4
  42. package/dist/exceptions/main-file-not-found.js.map +1 -1
  43. package/dist/exceptions/nothing-to-snap.js +0 -2
  44. package/dist/exceptions/nothing-to-snap.js.map +1 -1
  45. package/dist/history-graph.js +0 -2
  46. package/dist/history-graph.js.map +1 -1
  47. package/dist/host/component-host-model.js +0 -7
  48. package/dist/host/component-host-model.js.map +1 -1
  49. package/dist/host/index.js +0 -5
  50. package/dist/host/index.js.map +1 -1
  51. package/dist/host/use-component-host.js +0 -14
  52. package/dist/host/use-component-host.js.map +1 -1
  53. package/dist/index.js +0 -63
  54. package/dist/index.js.map +1 -1
  55. package/dist/section/index.js +0 -3
  56. package/dist/section/index.js.map +1 -1
  57. package/dist/show/extensions.fragment.js +0 -8
  58. package/dist/show/extensions.fragment.js.map +1 -1
  59. package/dist/show/files.fragment.js +0 -11
  60. package/dist/show/files.fragment.js.map +1 -1
  61. package/dist/show/id.fragment.js +0 -10
  62. package/dist/show/id.fragment.js.map +1 -1
  63. package/dist/show/index.js +0 -24
  64. package/dist/show/index.js.map +1 -1
  65. package/dist/show/main-file.fragment.js +0 -9
  66. package/dist/show/main-file.fragment.js.map +1 -1
  67. package/dist/show/name.fragment.js +0 -9
  68. package/dist/show/name.fragment.js.map +1 -1
  69. package/dist/show/scope.fragment.js +0 -10
  70. package/dist/show/scope.fragment.js.map +1 -1
  71. package/dist/show/show.cmd.js +1 -33
  72. package/dist/show/show.cmd.js.map +1 -1
  73. package/dist/snap/index.js +0 -6
  74. package/dist/snap/index.js.map +1 -1
  75. package/dist/snap/snap.js +0 -5
  76. package/dist/snap/snap.js.map +1 -1
  77. package/dist/state.js +6 -24
  78. package/dist/state.js.map +1 -1
  79. package/dist/store.js +0 -5
  80. package/dist/store.js.map +1 -1
  81. package/dist/tag/index.js +0 -3
  82. package/dist/tag/index.js.map +1 -1
  83. package/dist/tag/tag.js +1 -9
  84. package/dist/tag/tag.js.map +1 -1
  85. package/dist/tag-map.js +4 -28
  86. package/dist/tag-map.js.map +1 -1
  87. package/dist/ui/aspect-page/aspect-page.js +2 -35
  88. package/dist/ui/aspect-page/aspect-page.js.map +1 -1
  89. package/dist/ui/aspect-page/index.js +0 -3
  90. package/dist/ui/aspect-page/index.js.map +1 -1
  91. package/dist/ui/component-error/component-error.js +0 -14
  92. package/dist/ui/component-error/component-error.js.map +1 -1
  93. package/dist/ui/component-error/index.js +0 -3
  94. package/dist/ui/component-error/index.js.map +1 -1
  95. package/dist/ui/component-model/component-model.js +2 -21
  96. package/dist/ui/component-model/component-model.js.map +1 -1
  97. package/dist/ui/component-model/index.js +0 -3
  98. package/dist/ui/component-model/index.js.map +1 -1
  99. package/dist/ui/component-searcher/component-result.js +0 -20
  100. package/dist/ui/component-searcher/component-result.js.map +1 -1
  101. package/dist/ui/component-searcher/component-searcher.js +0 -22
  102. package/dist/ui/component-searcher/component-searcher.js.map +1 -1
  103. package/dist/ui/component-searcher/index.js +0 -3
  104. package/dist/ui/component-searcher/index.js.map +1 -1
  105. package/dist/ui/component.js +5 -40
  106. package/dist/ui/component.js.map +1 -1
  107. package/dist/ui/context/component-context.js +0 -9
  108. package/dist/ui/context/component-context.js.map +1 -1
  109. package/dist/ui/context/component-provider.js +0 -9
  110. package/dist/ui/context/component-provider.js.map +1 -1
  111. package/dist/ui/context/index.js +0 -6
  112. package/dist/ui/context/index.js.map +1 -1
  113. package/dist/ui/index.js +0 -21
  114. package/dist/ui/index.js.map +1 -1
  115. package/dist/ui/menu/index.js +0 -3
  116. package/dist/ui/menu/index.js.map +1 -1
  117. package/dist/ui/menu/menu-nav.js +4 -23
  118. package/dist/ui/menu/menu-nav.js.map +1 -1
  119. package/dist/ui/menu/menu.js +0 -70
  120. package/dist/ui/menu/menu.js.map +1 -1
  121. package/dist/ui/menu/mobile-menu-nav.js +6 -49
  122. package/dist/ui/menu/mobile-menu-nav.js.map +1 -1
  123. package/dist/ui/top-bar-nav/index.js +0 -2
  124. package/dist/ui/top-bar-nav/index.js.map +1 -1
  125. package/dist/ui/top-bar-nav/top-bar-nav.js +8 -32
  126. package/dist/ui/top-bar-nav/top-bar-nav.js.map +1 -1
  127. package/dist/ui/use-component-from-location.js +0 -9
  128. package/dist/ui/use-component-from-location.js.map +1 -1
  129. package/dist/ui/use-component-query.js +12 -60
  130. package/dist/ui/use-component-query.js.map +1 -1
  131. package/dist/ui/use-component.js +0 -11
  132. package/dist/ui/use-component.js.map +1 -1
  133. package/package-tar/teambit-component-0.0.882.tgz +0 -0
  134. package/package.json +12 -12
  135. package/{preview-1666409808293.js → preview-1666496165706.js} +2 -2
  136. package/package-tar/teambit-component-0.0.881.tgz +0 -0
package/dist/component.js CHANGED
@@ -1,76 +1,52 @@
1
1
  "use strict";
2
2
 
3
3
  require("core-js/modules/es.symbol.description.js");
4
-
5
4
  require("core-js/modules/es.symbol.async-iterator.js");
6
-
7
5
  require("core-js/modules/es.array.iterator.js");
8
-
9
6
  require("core-js/modules/es.array.sort.js");
10
-
11
7
  require("core-js/modules/es.promise.js");
12
-
13
8
  require("core-js/modules/es.regexp.exec.js");
14
-
15
9
  Object.defineProperty(exports, "__esModule", {
16
10
  value: true
17
11
  });
18
12
  exports.Component = void 0;
19
-
20
13
  function _toolboxString() {
21
14
  const data = require("@teambit/toolbox.string.capitalize");
22
-
23
15
  _toolboxString = function () {
24
16
  return data;
25
17
  };
26
-
27
18
  return data;
28
19
  }
29
-
30
20
  function _bitError() {
31
21
  const data = require("@teambit/bit-error");
32
-
33
22
  _bitError = function () {
34
23
  return data;
35
24
  };
36
-
37
25
  return data;
38
26
  }
39
-
40
27
  function _lodash() {
41
28
  const data = require("lodash");
42
-
43
29
  _lodash = function () {
44
30
  return data;
45
31
  };
46
-
47
32
  return data;
48
33
  }
49
-
50
34
  function _tagMap() {
51
35
  const data = require("./tag-map");
52
-
53
36
  _tagMap = function () {
54
37
  return data;
55
38
  };
56
-
57
39
  return data;
58
40
  }
59
-
60
41
  function _exceptions() {
61
42
  const data = require("./exceptions");
62
-
63
43
  _exceptions = function () {
64
44
  return data;
65
45
  };
66
-
67
46
  return data;
68
47
  }
69
-
70
48
  function _asyncIterator(iterable) { var method, async, sync, retry = 2; for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) { if (async && null != (method = iterable[async])) return method.call(iterable); if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable)); async = "@@asyncIterator", sync = "@@iterator"; } throw new TypeError("Object is not async iterable"); }
71
-
72
49
  function AsyncFromSyncIterator(s) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var done = r.done; return Promise.resolve(r.value).then(function (value) { return { value: value, done: done }; }); } return AsyncFromSyncIterator = function (s) { this.s = s, this.n = s.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function () { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, return: function (value) { var ret = this.s.return; return void 0 === ret ? Promise.resolve({ value: value, done: !0 }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments)); }, throw: function (value) { var thr = this.s.return; return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(s); }
73
-
74
50
  /**
75
51
  * in-memory representation of a component.
76
52
  */
@@ -102,72 +78,59 @@ class Component {
102
78
  this.tags = tags;
103
79
  this.factory = factory;
104
80
  }
105
-
106
81
  get mainFile() {
107
82
  return this.state.mainFile;
108
83
  }
109
-
110
84
  get state() {
111
85
  return this._state;
112
86
  }
113
-
114
87
  set state(state) {
115
88
  this._state = state;
116
89
  }
90
+
117
91
  /**
118
92
  * component configuration which is later generated to a component `package.json` and `bit.json`.
119
93
  */
120
-
121
-
122
94
  get config() {
123
95
  return this.state.config;
124
96
  }
97
+
125
98
  /**
126
99
  * in-memory representation of the component current filesystem.
127
100
  */
128
-
129
-
130
101
  get filesystem() {
131
102
  return this.state.filesystem;
132
103
  }
104
+
133
105
  /**
134
106
  * build status of the component
135
107
  */
136
-
137
-
138
108
  get buildStatus() {
139
109
  return this._state._consumer.buildStatus;
140
110
  }
141
-
142
111
  get headTag() {
143
112
  if (!this.head) return undefined;
144
113
  return this.tags.byHash(this.head.hash);
145
114
  }
146
-
147
115
  get latest() {
148
116
  if (!this.head) return undefined;
149
-
150
117
  try {
151
118
  return this.tags.getLatest();
152
119
  } catch (err) {
153
120
  if (err instanceof _exceptions().CouldNotFindLatest) {
154
121
  return this.head.hash;
155
122
  }
156
-
157
123
  throw err;
158
124
  }
159
125
  }
126
+
160
127
  /**
161
128
  * get aspect data from current state.
162
129
  */
163
-
164
-
165
130
  get(id) {
166
131
  var _this$state$aspects$g;
167
-
168
132
  return (_this$state$aspects$g = this.state.aspects.get(id)) === null || _this$state$aspects$g === void 0 ? void 0 : _this$state$aspects$g.serialize();
169
133
  }
170
-
171
134
  async getLogs(filter) {
172
135
  const allLogs = await this.factory.getLogs(this.id, false, filter === null || filter === void 0 ? void 0 : filter.head);
173
136
  if (!filter) return allLogs;
@@ -177,122 +140,105 @@ class Component {
177
140
  offset,
178
141
  sort
179
142
  } = filter;
180
-
181
143
  const typeFilter = snap => {
182
144
  if (type === 'tag') return snap.tag;
183
145
  if (type === 'snap') return !snap.tag;
184
146
  return true;
185
147
  };
186
-
187
148
  let filteredLogs = type && allLogs.filter(typeFilter) || allLogs;
188
149
  if (sort !== 'asc') filteredLogs = filteredLogs.reverse();
189
-
190
150
  if (limit) {
191
151
  filteredLogs = (0, _lodash().slice)(filteredLogs, offset, limit + (offset || 0));
192
152
  }
193
-
194
153
  return filteredLogs;
195
154
  }
196
-
197
155
  stringify() {
198
156
  return JSON.stringify({
199
157
  id: this.id,
200
158
  head: this.head
201
159
  });
202
160
  }
161
+
203
162
  /**
204
163
  * record component changes in the `Scope`.
205
164
  */
206
165
  // snap(author: Author, message = '') {
207
166
  // if (!this.isModified()) throw new NothingToSnap();
208
167
  // const snap = new Snap(this, author, message);
168
+
209
169
  // return new Component(this.id, snap, snap.state);
210
170
  // }
211
171
 
212
172
  /**
213
173
  * display name of the component.
214
174
  */
215
-
216
-
217
175
  get displayName() {
218
176
  const tokens = this.id.name.split('-').map(token => (0, _toolboxString().capitalize)(token));
219
177
  return tokens.join(' ');
220
178
  }
179
+
221
180
  /**
222
181
  * tag a component `Snap` with a semantic version. we follow SemVer specs as defined [here](https://semver.org/)).
223
182
  */
224
183
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
225
-
226
-
227
- tag(version) {// const snap = this.snap();
184
+ tag(version) {
185
+ // const snap = this.snap();
228
186
  // const tag = new Tag(version, snap);
229
187
  // this.tags.set(tag);
230
188
  }
189
+
231
190
  /**
232
191
  * determines whether this component is modified in the workspace.
233
192
  */
234
-
235
-
236
193
  isModified() {
237
194
  return this.factory.isModified(this);
238
195
  }
196
+
239
197
  /**
240
198
  * is component isOutdated
241
199
  */
242
-
243
-
244
200
  isOutdated() {
245
201
  var _this$head;
246
-
247
202
  if (!this.latest) return false;
248
203
  const latestTag = this.tags.byVersion(this.latest);
249
204
  if (!latestTag) return false;
250
205
  if (((_this$head = this.head) === null || _this$head === void 0 ? void 0 : _this$head.hash) !== (latestTag === null || latestTag === void 0 ? void 0 : latestTag.hash)) return true;
251
206
  return false;
252
207
  }
208
+
253
209
  /**
254
210
  * determines whether this component is new.
255
211
  */
256
-
257
-
258
212
  isNew() {
259
213
  return Promise.resolve(this.head === null);
260
- } // TODO: @david after snap we need to make sure to refactor here.
261
-
214
+ }
262
215
 
216
+ // TODO: @david after snap we need to make sure to refactor here.
263
217
  loadState(snapId) {
264
218
  return this.factory.getState(this.id, snapId);
265
219
  }
266
-
267
220
  loadSnap(snapId) {
268
221
  var _this$head2;
269
-
270
222
  const snapToGet = snapId || ((_this$head2 = this.head) === null || _this$head2 === void 0 ? void 0 : _this$head2.hash);
271
-
272
223
  if (!snapToGet) {
273
224
  throw new (_bitError().BitError)('could not load snap for new components');
274
225
  }
275
-
276
226
  return this.factory.getSnap(this.id, snapToGet);
277
227
  }
228
+
278
229
  /**
279
230
  * Get iterable which iterate over snap parents lazily
280
231
  * @param snapId
281
232
  * @param options
282
233
  */
283
-
284
-
285
234
  snapsIterable(snapId, options = {}) {
286
235
  var _this$head3;
287
-
288
236
  const snapToStart = snapId || ((_this$head3 = this.head) === null || _this$head3 === void 0 ? void 0 : _this$head3.hash);
289
237
  let nextSnaps = [snapToStart];
290
238
  let done;
291
-
292
239
  if (!snapToStart) {
293
240
  done = true;
294
241
  }
295
-
296
242
  const iterator = {
297
243
  next: async () => {
298
244
  if (done) {
@@ -301,10 +247,8 @@ class Component {
301
247
  done
302
248
  };
303
249
  }
304
-
305
250
  const currSnapId = nextSnaps.shift();
306
251
  const snap = await this.loadSnap(currSnapId);
307
-
308
252
  if (snap.parents && snap.parents.length) {
309
253
  if (options.firstParentOnly) {
310
254
  nextSnaps.push(snap.parents[0]);
@@ -312,13 +256,11 @@ class Component {
312
256
  nextSnaps = nextSnaps.concat(snap.parents);
313
257
  }
314
258
  }
315
-
316
259
  if (!nextSnaps.length) {
317
260
  done = true;
318
261
  } else if (options.stopFn) {
319
262
  done = await options.stopFn(snap);
320
263
  }
321
-
322
264
  return {
323
265
  value: snap,
324
266
  done: undefined
@@ -329,23 +271,19 @@ class Component {
329
271
  [Symbol.asyncIterator]: () => iterator
330
272
  };
331
273
  }
274
+
332
275
  /**
333
276
  * traverse recursively from the provided snap (or head) upwards until it finds a tag
334
277
  * @param snapToStartFrom
335
278
  */
336
-
337
-
338
279
  async getClosestTag(snapToStartFrom) {
339
280
  const tagsHashMap = this.tags.getHashMap();
340
-
341
281
  const stopFn = async snap => {
342
282
  if (tagsHashMap.has(snap.hash)) {
343
283
  return true;
344
284
  }
345
-
346
285
  return false;
347
286
  };
348
-
349
287
  const iterable = this.snapsIterable(snapToStartFrom, {
350
288
  firstParentOnly: true,
351
289
  stopFn
@@ -353,9 +291,7 @@ class Component {
353
291
  const snaps = [];
354
292
  var _iteratorAbruptCompletion = false;
355
293
  var _didIteratorError = false;
356
-
357
294
  var _iteratorError;
358
-
359
295
  try {
360
296
  for (var _iterator = _asyncIterator(iterable), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
361
297
  const snap = _step.value;
@@ -375,21 +311,19 @@ class Component {
375
311
  }
376
312
  }
377
313
  }
378
-
379
314
  if (snaps.length) {
380
315
  const hashOfLastSnap = snaps[snaps.length - 1].hash;
381
316
  return tagsHashMap.get(hashOfLastSnap);
382
317
  }
383
-
384
318
  return undefined;
385
319
  }
320
+
386
321
  /**
387
322
  * checkout the component to a different version in its working tree.
388
323
  */
389
324
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
390
-
391
-
392
325
  checkout(version) {}
326
+
393
327
  /**
394
328
  * examine difference between two components.
395
329
  */
@@ -406,9 +340,8 @@ class Component {
406
340
  * @param fs instance of any fs to use.
407
341
  */
408
342
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
409
-
410
-
411
343
  write(path, fs) {}
344
+
412
345
  /**
413
346
  *
414
347
  * Check if 2 components are equal
@@ -417,14 +350,10 @@ class Component {
417
350
  * @memberof Component
418
351
  */
419
352
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
420
-
421
-
422
353
  equals(component) {
423
354
  return component.id.toString() === this.id.toString();
424
355
  }
425
-
426
356
  }
427
-
428
357
  exports.Component = Component;
429
358
 
430
359
  //# sourceMappingURL=component.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Component","constructor","id","head","_state","tags","TagMap","factory","mainFile","state","config","filesystem","buildStatus","_consumer","headTag","undefined","byHash","hash","latest","getLatest","err","CouldNotFindLatest","get","aspects","serialize","getLogs","filter","allLogs","type","limit","offset","sort","typeFilter","snap","tag","filteredLogs","reverse","slice","stringify","JSON","displayName","tokens","name","split","map","token","capitalize","join","version","isModified","isOutdated","latestTag","byVersion","isNew","Promise","resolve","loadState","snapId","getState","loadSnap","snapToGet","BitError","getSnap","snapsIterable","options","snapToStart","nextSnaps","done","iterator","next","value","currSnapId","shift","parents","length","firstParentOnly","push","concat","stopFn","Symbol","asyncIterator","getClosestTag","snapToStartFrom","tagsHashMap","getHashMap","has","iterable","snaps","hashOfLastSnap","checkout","write","path","fs","equals","component","toString"],"sources":["component.ts"],"sourcesContent":["import { AnyFS } from '@teambit/any-fs';\nimport { capitalize } from '@teambit/toolbox.string.capitalize';\nimport { SemVer } from 'semver';\nimport { ComponentID } from '@teambit/component-id';\nimport { BitError } from '@teambit/bit-error';\nimport { BuildStatus } from '@teambit/legacy/dist/constants';\n\nimport { slice } from 'lodash';\nimport { ComponentFactory } from './component-factory';\nimport ComponentFS from './component-fs';\n// import { NothingToSnap } from './exceptions';\nimport ComponentConfig from './config';\n// eslint-disable-next-line import/no-cycle\nimport { Snap } from './snap';\nimport { State } from './state';\nimport { TagMap } from './tag-map';\nimport { Tag } from './tag';\nimport { CouldNotFindLatest } from './exceptions';\nimport { IComponent, RawComponentMetadata } from './component-interface';\n// import { Author } from './types';\n\ntype SnapsIterableOpts = {\n firstParentOnly?: boolean;\n stopFn?: (snap: Snap) => Promise<boolean>;\n};\n\nexport type InvalidComponent = { id: ComponentID; err: Error };\n\n/**\n * in-memory representation of a component.\n */\nexport class Component implements IComponent {\n constructor(\n /**\n * component ID represented by the `ComponentId` type.\n */\n readonly id: ComponentID,\n\n /**\n * head version of the component. can be `null` for new components.\n */\n readonly head: Snap | null = null,\n\n /**\n * state of the component.\n */\n private _state: State,\n\n /**\n * tags of the component.\n */\n readonly tags: TagMap = new TagMap(),\n\n /**\n * the component factory\n */\n private factory: ComponentFactory\n ) {}\n\n get mainFile() {\n return this.state.mainFile;\n }\n\n get state(): State {\n return this._state;\n }\n\n set state(state: State) {\n this._state = state;\n }\n\n /**\n * component configuration which is later generated to a component `package.json` and `bit.json`.\n */\n get config(): ComponentConfig {\n return this.state.config;\n }\n\n /**\n * in-memory representation of the component current filesystem.\n */\n get filesystem(): ComponentFS {\n return this.state.filesystem;\n }\n\n /**\n * build status of the component\n */\n get buildStatus(): BuildStatus {\n return this._state._consumer.buildStatus;\n }\n\n get headTag() {\n if (!this.head) return undefined;\n return this.tags.byHash(this.head.hash);\n }\n\n get latest(): string | undefined {\n if (!this.head) return undefined;\n try {\n return this.tags.getLatest();\n } catch (err: any) {\n if (err instanceof CouldNotFindLatest) {\n return this.head.hash;\n }\n throw err;\n }\n }\n\n /**\n * get aspect data from current state.\n */\n get(id: string): RawComponentMetadata | undefined {\n return this.state.aspects.get(id)?.serialize();\n }\n\n async getLogs(filter?: { type?: string; offset?: number; limit?: number; head?: string; sort?: string }) {\n const allLogs = await this.factory.getLogs(this.id, false, filter?.head);\n\n if (!filter) return allLogs;\n\n const { type, limit, offset, sort } = filter;\n\n const typeFilter = (snap) => {\n if (type === 'tag') return snap.tag;\n if (type === 'snap') return !snap.tag;\n return true;\n };\n\n let filteredLogs = (type && allLogs.filter(typeFilter)) || allLogs;\n if (sort !== 'asc') filteredLogs = filteredLogs.reverse();\n\n if (limit) {\n filteredLogs = slice(filteredLogs, offset, limit + (offset || 0));\n }\n\n return filteredLogs;\n }\n\n stringify(): string {\n return JSON.stringify({\n id: this.id,\n head: this.head,\n });\n }\n\n /**\n * record component changes in the `Scope`.\n */\n // snap(author: Author, message = '') {\n // if (!this.isModified()) throw new NothingToSnap();\n // const snap = new Snap(this, author, message);\n\n // return new Component(this.id, snap, snap.state);\n // }\n\n /**\n * display name of the component.\n */\n get displayName() {\n const tokens = this.id.name.split('-').map((token) => capitalize(token));\n return tokens.join(' ');\n }\n\n /**\n * tag a component `Snap` with a semantic version. we follow SemVer specs as defined [here](https://semver.org/)).\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n tag(version: SemVer) {\n // const snap = this.snap();\n // const tag = new Tag(version, snap);\n // this.tags.set(tag);\n }\n\n /**\n * determines whether this component is modified in the workspace.\n */\n isModified(): Promise<boolean> {\n return this.factory.isModified(this);\n }\n\n /**\n * is component isOutdated\n */\n isOutdated(): boolean {\n if (!this.latest) return false;\n const latestTag = this.tags.byVersion(this.latest);\n if (!latestTag) return false;\n if (this.head?.hash !== latestTag?.hash) return true;\n return false;\n }\n\n /**\n * determines whether this component is new.\n */\n isNew(): Promise<boolean> {\n return Promise.resolve(this.head === null);\n }\n\n // TODO: @david after snap we need to make sure to refactor here.\n loadState(snapId: string): Promise<State> {\n return this.factory.getState(this.id, snapId);\n }\n\n loadSnap(snapId?: string): Promise<Snap> {\n const snapToGet = snapId || this.head?.hash;\n if (!snapToGet) {\n throw new BitError('could not load snap for new components');\n }\n return this.factory.getSnap(this.id, snapToGet);\n }\n\n /**\n * Get iterable which iterate over snap parents lazily\n * @param snapId\n * @param options\n */\n snapsIterable(snapId?: string, options: SnapsIterableOpts = {}): AsyncIterable<Snap> {\n const snapToStart = snapId || this.head?.hash;\n let nextSnaps = [snapToStart];\n let done;\n if (!snapToStart) {\n done = true;\n }\n\n const iterator: AsyncIterator<Snap> = {\n next: async () => {\n if (done) {\n return { value: undefined, done };\n }\n const currSnapId = nextSnaps.shift();\n const snap = await this.loadSnap(currSnapId);\n if (snap.parents && snap.parents.length) {\n if (options.firstParentOnly) {\n nextSnaps.push(snap.parents[0]);\n } else {\n nextSnaps = nextSnaps.concat(snap.parents);\n }\n }\n if (!nextSnaps.length) {\n done = true;\n } else if (options.stopFn) {\n done = await options.stopFn(snap);\n }\n return { value: snap, done: undefined };\n },\n };\n return {\n [Symbol.asyncIterator]: () => iterator,\n };\n }\n\n /**\n * traverse recursively from the provided snap (or head) upwards until it finds a tag\n * @param snapToStartFrom\n */\n async getClosestTag(snapToStartFrom?: string): Promise<Tag | undefined> {\n const tagsHashMap = this.tags.getHashMap();\n const stopFn = async (snap: Snap) => {\n if (tagsHashMap.has(snap.hash)) {\n return true;\n }\n return false;\n };\n const iterable = this.snapsIterable(snapToStartFrom, { firstParentOnly: true, stopFn });\n const snaps: Snap[] = [];\n for await (const snap of iterable) {\n snaps.push(snap);\n }\n if (snaps.length) {\n const hashOfLastSnap = snaps[snaps.length - 1].hash;\n return tagsHashMap.get(hashOfLastSnap);\n }\n return undefined;\n }\n\n /**\n * checkout the component to a different version in its working tree.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n checkout(version: SemVer) {}\n\n /**\n * examine difference between two components.\n */\n // diff(other: Component): Difference {}\n\n /**\n * merge two different components\n */\n // merge(other: Component): Component {}\n\n /**\n * write a component to a given file system.\n * @param path root path to write the component\n * @param fs instance of any fs to use.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n write(path: string, fs?: AnyFS) {}\n\n /**\n *\n * Check if 2 components are equal\n * @param {Component} component\n * @returns {boolean}\n * @memberof Component\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n equals(component: Component): boolean {\n return component.id.toString() === this.id.toString();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAQA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;;;AAWA;AACA;AACA;AACO,MAAMA,SAAN,CAAsC;EAC3CC,WAAW;EACT;AACJ;AACA;EACaC,EAJA;EAMT;AACJ;AACA;EACaC,IAAiB,GAAG,IATpB;EAWT;AACJ;AACA;EACYC,MAdC;EAgBT;AACJ;AACA;EACaC,IAAY,GAAG,KAAIC,gBAAJ,GAnBf;EAqBT;AACJ;AACA;EACYC,OAxBC,EAyBT;IAAA,KArBSL,EAqBT,GArBSA,EAqBT;IAAA,KAhBSC,IAgBT,GAhBSA,IAgBT;IAAA,KAXQC,MAWR,GAXQA,MAWR;IAAA,KANSC,IAMT,GANSA,IAMT;IAAA,KADQE,OACR,GADQA,OACR;EAAE;;EAEQ,IAARC,QAAQ,GAAG;IACb,OAAO,KAAKC,KAAL,CAAWD,QAAlB;EACD;;EAEQ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MACD;;MACD,OAAO,KAAP;IACD,CALD;;IAMA,MAAMqE,QAAQ,GAAG,KAAKvB,aAAL,CAAmBmB,eAAnB,EAAoC;MAAEP,eAAe,EAAE,IAAnB;MAAyBG;IAAzB,CAApC,CAAjB;IACA,MAAMS,KAAa,GAAG,EAAtB;IATsE;IAAA;;IAAA;;IAAA;MAUtE,oCAAyBD,QAAzB,iHAAmC;QAAA,MAAlBrD,IAAkB;QACjCsD,KAAK,CAACX,IAAN,CAAW3C,IAAX;MACD;IAZqE;MAAA;MAAA;IAAA;MAAA;QAAA;UAAA;QAAA;MAAA;QAAA;UAAA;QAAA;MAAA;IAAA;;IAatE,IAAIsD,KAAK,CAACb,MAAV,EAAkB;MAChB,MAAMc,cAAc,GAAGD,KAAK,CAACA,KAAK,CAACb,MAAN,GAAe,CAAhB,CAAL,CAAwBzD,IAA/C;MACA,OAAOkE,WAAW,CAAC7D,GAAZ,CAAgBkE,cAAhB,CAAP;IACD;;IACD,OAAOzE,SAAP;EACD;EAED;AACF;AACA;EACE;;;EACA0E,QAAQ,CAACzC,OAAD,EAAkB,CAAE;EAE5B;AACF;AACA;EACE;;EAEA;AACF;AACA;EACE;;EAEA;AACF;AACA;AACA;AACA;EACE;;;EACA0C,KAAK,CAACC,IAAD,EAAeC,EAAf,EAA2B,CAAE;EAElC;AACF;AACA;AACA;AACA;AACA;AACA;EACE;;;EACAC,MAAM,CAACC,SAAD,EAAgC;IACpC,OAAOA,SAAS,CAAC5F,EAAV,CAAa6F,QAAb,OAA4B,KAAK7F,EAAL,CAAQ6F,QAAR,EAAnC;EACD;;AAvR0C"}
1
+ {"version":3,"names":["Component","constructor","id","head","_state","tags","TagMap","factory","mainFile","state","config","filesystem","buildStatus","_consumer","headTag","undefined","byHash","hash","latest","getLatest","err","CouldNotFindLatest","get","aspects","serialize","getLogs","filter","allLogs","type","limit","offset","sort","typeFilter","snap","tag","filteredLogs","reverse","slice","stringify","JSON","displayName","tokens","name","split","map","token","capitalize","join","version","isModified","isOutdated","latestTag","byVersion","isNew","Promise","resolve","loadState","snapId","getState","loadSnap","snapToGet","BitError","getSnap","snapsIterable","options","snapToStart","nextSnaps","done","iterator","next","value","currSnapId","shift","parents","length","firstParentOnly","push","concat","stopFn","Symbol","asyncIterator","getClosestTag","snapToStartFrom","tagsHashMap","getHashMap","has","iterable","snaps","hashOfLastSnap","checkout","write","path","fs","equals","component","toString"],"sources":["component.ts"],"sourcesContent":["import { AnyFS } from '@teambit/any-fs';\nimport { capitalize } from '@teambit/toolbox.string.capitalize';\nimport { SemVer } from 'semver';\nimport { ComponentID } from '@teambit/component-id';\nimport { BitError } from '@teambit/bit-error';\nimport { BuildStatus } from '@teambit/legacy/dist/constants';\n\nimport { slice } from 'lodash';\nimport { ComponentFactory } from './component-factory';\nimport ComponentFS from './component-fs';\n// import { NothingToSnap } from './exceptions';\nimport ComponentConfig from './config';\n// eslint-disable-next-line import/no-cycle\nimport { Snap } from './snap';\nimport { State } from './state';\nimport { TagMap } from './tag-map';\nimport { Tag } from './tag';\nimport { CouldNotFindLatest } from './exceptions';\nimport { IComponent, RawComponentMetadata } from './component-interface';\n// import { Author } from './types';\n\ntype SnapsIterableOpts = {\n firstParentOnly?: boolean;\n stopFn?: (snap: Snap) => Promise<boolean>;\n};\n\nexport type InvalidComponent = { id: ComponentID; err: Error };\n\n/**\n * in-memory representation of a component.\n */\nexport class Component implements IComponent {\n constructor(\n /**\n * component ID represented by the `ComponentId` type.\n */\n readonly id: ComponentID,\n\n /**\n * head version of the component. can be `null` for new components.\n */\n readonly head: Snap | null = null,\n\n /**\n * state of the component.\n */\n private _state: State,\n\n /**\n * tags of the component.\n */\n readonly tags: TagMap = new TagMap(),\n\n /**\n * the component factory\n */\n private factory: ComponentFactory\n ) {}\n\n get mainFile() {\n return this.state.mainFile;\n }\n\n get state(): State {\n return this._state;\n }\n\n set state(state: State) {\n this._state = state;\n }\n\n /**\n * component configuration which is later generated to a component `package.json` and `bit.json`.\n */\n get config(): ComponentConfig {\n return this.state.config;\n }\n\n /**\n * in-memory representation of the component current filesystem.\n */\n get filesystem(): ComponentFS {\n return this.state.filesystem;\n }\n\n /**\n * build status of the component\n */\n get buildStatus(): BuildStatus {\n return this._state._consumer.buildStatus;\n }\n\n get headTag() {\n if (!this.head) return undefined;\n return this.tags.byHash(this.head.hash);\n }\n\n get latest(): string | undefined {\n if (!this.head) return undefined;\n try {\n return this.tags.getLatest();\n } catch (err: any) {\n if (err instanceof CouldNotFindLatest) {\n return this.head.hash;\n }\n throw err;\n }\n }\n\n /**\n * get aspect data from current state.\n */\n get(id: string): RawComponentMetadata | undefined {\n return this.state.aspects.get(id)?.serialize();\n }\n\n async getLogs(filter?: { type?: string; offset?: number; limit?: number; head?: string; sort?: string }) {\n const allLogs = await this.factory.getLogs(this.id, false, filter?.head);\n\n if (!filter) return allLogs;\n\n const { type, limit, offset, sort } = filter;\n\n const typeFilter = (snap) => {\n if (type === 'tag') return snap.tag;\n if (type === 'snap') return !snap.tag;\n return true;\n };\n\n let filteredLogs = (type && allLogs.filter(typeFilter)) || allLogs;\n if (sort !== 'asc') filteredLogs = filteredLogs.reverse();\n\n if (limit) {\n filteredLogs = slice(filteredLogs, offset, limit + (offset || 0));\n }\n\n return filteredLogs;\n }\n\n stringify(): string {\n return JSON.stringify({\n id: this.id,\n head: this.head,\n });\n }\n\n /**\n * record component changes in the `Scope`.\n */\n // snap(author: Author, message = '') {\n // if (!this.isModified()) throw new NothingToSnap();\n // const snap = new Snap(this, author, message);\n\n // return new Component(this.id, snap, snap.state);\n // }\n\n /**\n * display name of the component.\n */\n get displayName() {\n const tokens = this.id.name.split('-').map((token) => capitalize(token));\n return tokens.join(' ');\n }\n\n /**\n * tag a component `Snap` with a semantic version. we follow SemVer specs as defined [here](https://semver.org/)).\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n tag(version: SemVer) {\n // const snap = this.snap();\n // const tag = new Tag(version, snap);\n // this.tags.set(tag);\n }\n\n /**\n * determines whether this component is modified in the workspace.\n */\n isModified(): Promise<boolean> {\n return this.factory.isModified(this);\n }\n\n /**\n * is component isOutdated\n */\n isOutdated(): boolean {\n if (!this.latest) return false;\n const latestTag = this.tags.byVersion(this.latest);\n if (!latestTag) return false;\n if (this.head?.hash !== latestTag?.hash) return true;\n return false;\n }\n\n /**\n * determines whether this component is new.\n */\n isNew(): Promise<boolean> {\n return Promise.resolve(this.head === null);\n }\n\n // TODO: @david after snap we need to make sure to refactor here.\n loadState(snapId: string): Promise<State> {\n return this.factory.getState(this.id, snapId);\n }\n\n loadSnap(snapId?: string): Promise<Snap> {\n const snapToGet = snapId || this.head?.hash;\n if (!snapToGet) {\n throw new BitError('could not load snap for new components');\n }\n return this.factory.getSnap(this.id, snapToGet);\n }\n\n /**\n * Get iterable which iterate over snap parents lazily\n * @param snapId\n * @param options\n */\n snapsIterable(snapId?: string, options: SnapsIterableOpts = {}): AsyncIterable<Snap> {\n const snapToStart = snapId || this.head?.hash;\n let nextSnaps = [snapToStart];\n let done;\n if (!snapToStart) {\n done = true;\n }\n\n const iterator: AsyncIterator<Snap> = {\n next: async () => {\n if (done) {\n return { value: undefined, done };\n }\n const currSnapId = nextSnaps.shift();\n const snap = await this.loadSnap(currSnapId);\n if (snap.parents && snap.parents.length) {\n if (options.firstParentOnly) {\n nextSnaps.push(snap.parents[0]);\n } else {\n nextSnaps = nextSnaps.concat(snap.parents);\n }\n }\n if (!nextSnaps.length) {\n done = true;\n } else if (options.stopFn) {\n done = await options.stopFn(snap);\n }\n return { value: snap, done: undefined };\n },\n };\n return {\n [Symbol.asyncIterator]: () => iterator,\n };\n }\n\n /**\n * traverse recursively from the provided snap (or head) upwards until it finds a tag\n * @param snapToStartFrom\n */\n async getClosestTag(snapToStartFrom?: string): Promise<Tag | undefined> {\n const tagsHashMap = this.tags.getHashMap();\n const stopFn = async (snap: Snap) => {\n if (tagsHashMap.has(snap.hash)) {\n return true;\n }\n return false;\n };\n const iterable = this.snapsIterable(snapToStartFrom, { firstParentOnly: true, stopFn });\n const snaps: Snap[] = [];\n for await (const snap of iterable) {\n snaps.push(snap);\n }\n if (snaps.length) {\n const hashOfLastSnap = snaps[snaps.length - 1].hash;\n return tagsHashMap.get(hashOfLastSnap);\n }\n return undefined;\n }\n\n /**\n * checkout the component to a different version in its working tree.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n checkout(version: SemVer) {}\n\n /**\n * examine difference between two components.\n */\n // diff(other: Component): Difference {}\n\n /**\n * merge two different components\n */\n // merge(other: Component): Component {}\n\n /**\n * write a component to a given file system.\n * @param path root path to write the component\n * @param fs instance of any fs to use.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n write(path: string, fs?: AnyFS) {}\n\n /**\n *\n * Check if 2 components are equal\n * @param {Component} component\n * @returns {boolean}\n * @memberof Component\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n equals(component: Component): boolean {\n return component.id.toString() === this.id.toString();\n }\n}\n"],"mappings":";;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAQA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAkD;AAAA;AAWlD;AACA;AACA;AACO,MAAMA,SAAS,CAAuB;EAC3CC,WAAW;EACT;AACJ;AACA;EACaC,EAAe;EAExB;AACJ;AACA;EACaC,IAAiB,GAAG,IAAI;EAEjC;AACJ;AACA;EACYC,MAAa;EAErB;AACJ;AACA;EACaC,IAAY,GAAG,KAAIC,gBAAM,GAAE;EAEpC;AACJ;AACA;EACYC,OAAyB,EACjC;IAAA,KArBSL,EAAe,GAAfA,EAAe;IAAA,KAKfC,IAAiB,GAAjBA,IAAiB;IAAA,KAKlBC,MAAa,GAAbA,MAAa;IAAA,KAKZC,IAAY,GAAZA,IAAY;IAAA,KAKbE,OAAyB,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