@teambit/component 1.0.199 → 1.0.200

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.
@@ -1659,6 +1659,69 @@
1659
1659
  "line": 314,
1660
1660
  "character": 3
1661
1661
  },
1662
+ "raw": "/**\n * in case a component is new, it returns undefined.\n * otherwise, it returns the Snap object (hash/parents/log) of the current component (according to the version in the id)\n */",
1663
+ "comment": "in case a component is new, it returns undefined.\notherwise, it returns the Snap object (hash/parents/log) of the current component (according to the version in the id)"
1664
+ },
1665
+ "signature": "(method) Component.getCurrentSnap(): Promise<Snap | undefined>",
1666
+ "name": "getCurrentSnap",
1667
+ "params": [],
1668
+ "returnType": {
1669
+ "__schema": "TypeRefSchema",
1670
+ "location": {
1671
+ "filePath": "component.ts",
1672
+ "line": 318,
1673
+ "character": 27
1674
+ },
1675
+ "name": "Promise",
1676
+ "typeArgs": [
1677
+ {
1678
+ "__schema": "TypeUnionSchema",
1679
+ "location": {
1680
+ "filePath": "component.ts",
1681
+ "line": 318,
1682
+ "character": 35
1683
+ },
1684
+ "types": [
1685
+ {
1686
+ "__schema": "TypeRefSchema",
1687
+ "location": {
1688
+ "filePath": "component.ts",
1689
+ "line": 318,
1690
+ "character": 35
1691
+ },
1692
+ "name": "Snap"
1693
+ },
1694
+ {
1695
+ "__schema": "KeywordTypeSchema",
1696
+ "location": {
1697
+ "filePath": "component.ts",
1698
+ "line": 318,
1699
+ "character": 42
1700
+ },
1701
+ "name": "undefined"
1702
+ }
1703
+ ]
1704
+ }
1705
+ ]
1706
+ },
1707
+ "modifiers": [
1708
+ "async"
1709
+ ]
1710
+ },
1711
+ {
1712
+ "__schema": "FunctionLikeSchema",
1713
+ "location": {
1714
+ "filePath": "component.ts",
1715
+ "line": 328,
1716
+ "character": 3
1717
+ },
1718
+ "doc": {
1719
+ "__schema": "DocSchema",
1720
+ "location": {
1721
+ "filePath": "component.ts",
1722
+ "line": 324,
1723
+ "character": 3
1724
+ },
1662
1725
  "raw": "/**\n * checkout the component to a different version in its working tree.\n */",
1663
1726
  "comment": "checkout the component to a different version in its working tree."
1664
1727
  },
@@ -1669,7 +1732,7 @@
1669
1732
  "__schema": "ParameterSchema",
1670
1733
  "location": {
1671
1734
  "filePath": "component.ts",
1672
- "line": 318,
1735
+ "line": 328,
1673
1736
  "character": 12
1674
1737
  },
1675
1738
  "name": "version",
@@ -1677,7 +1740,7 @@
1677
1740
  "__schema": "TypeRefSchema",
1678
1741
  "location": {
1679
1742
  "filePath": "component.ts",
1680
- "line": 318,
1743
+ "line": 328,
1681
1744
  "character": 21
1682
1745
  },
1683
1746
  "name": "SemVer",
@@ -1691,7 +1754,7 @@
1691
1754
  "__schema": "InferenceTypeSchema",
1692
1755
  "location": {
1693
1756
  "filePath": "component.ts",
1694
- "line": 318,
1757
+ "line": 328,
1695
1758
  "character": 3
1696
1759
  },
1697
1760
  "type": "void"
@@ -1702,14 +1765,14 @@
1702
1765
  "__schema": "FunctionLikeSchema",
1703
1766
  "location": {
1704
1767
  "filePath": "component.ts",
1705
- "line": 336,
1768
+ "line": 346,
1706
1769
  "character": 3
1707
1770
  },
1708
1771
  "doc": {
1709
1772
  "__schema": "DocSchema",
1710
1773
  "location": {
1711
1774
  "filePath": "component.ts",
1712
- "line": 320,
1775
+ "line": 330,
1713
1776
  "character": 3
1714
1777
  },
1715
1778
  "raw": "/**\n * examine difference between two components.\n */",
@@ -1722,7 +1785,7 @@
1722
1785
  "__schema": "ParameterSchema",
1723
1786
  "location": {
1724
1787
  "filePath": "component.ts",
1725
- "line": 336,
1788
+ "line": 346,
1726
1789
  "character": 9
1727
1790
  },
1728
1791
  "name": "path",
@@ -1730,7 +1793,7 @@
1730
1793
  "__schema": "KeywordTypeSchema",
1731
1794
  "location": {
1732
1795
  "filePath": "component.ts",
1733
- "line": 336,
1796
+ "line": 346,
1734
1797
  "character": 15
1735
1798
  },
1736
1799
  "name": "string"
@@ -1742,7 +1805,7 @@
1742
1805
  "__schema": "ParameterSchema",
1743
1806
  "location": {
1744
1807
  "filePath": "component.ts",
1745
- "line": 336,
1808
+ "line": 346,
1746
1809
  "character": 23
1747
1810
  },
1748
1811
  "name": "fs",
@@ -1750,7 +1813,7 @@
1750
1813
  "__schema": "TypeRefSchema",
1751
1814
  "location": {
1752
1815
  "filePath": "component.ts",
1753
- "line": 336,
1816
+ "line": 346,
1754
1817
  "character": 28
1755
1818
  },
1756
1819
  "name": "AnyFS",
@@ -1764,7 +1827,7 @@
1764
1827
  "__schema": "InferenceTypeSchema",
1765
1828
  "location": {
1766
1829
  "filePath": "component.ts",
1767
- "line": 336,
1830
+ "line": 346,
1768
1831
  "character": 3
1769
1832
  },
1770
1833
  "type": "void"
@@ -1775,14 +1838,14 @@
1775
1838
  "__schema": "FunctionLikeSchema",
1776
1839
  "location": {
1777
1840
  "filePath": "component.ts",
1778
- "line": 346,
1841
+ "line": 356,
1779
1842
  "character": 3
1780
1843
  },
1781
1844
  "doc": {
1782
1845
  "__schema": "DocSchema",
1783
1846
  "location": {
1784
1847
  "filePath": "component.ts",
1785
- "line": 338,
1848
+ "line": 348,
1786
1849
  "character": 3
1787
1850
  },
1788
1851
  "raw": "/**\n *\n * Check if 2 components are equal\n * @param {Component} component\n * @returns {boolean}\n * @memberof Component\n */",
@@ -1792,7 +1855,7 @@
1792
1855
  "__schema": "PropertyLikeTagSchema",
1793
1856
  "location": {
1794
1857
  "filePath": "component.ts",
1795
- "line": 341,
1858
+ "line": 351,
1796
1859
  "character": 6
1797
1860
  },
1798
1861
  "name": "component",
@@ -1801,7 +1864,7 @@
1801
1864
  "__schema": "TypeRefSchema",
1802
1865
  "location": {
1803
1866
  "filePath": "component.ts",
1804
- "line": 341,
1867
+ "line": 351,
1805
1868
  "character": 14
1806
1869
  },
1807
1870
  "name": "Component"
@@ -1811,7 +1874,7 @@
1811
1874
  "__schema": "ReturnTagSchema",
1812
1875
  "location": {
1813
1876
  "filePath": "component.ts",
1814
- "line": 342,
1877
+ "line": 352,
1815
1878
  "character": 6
1816
1879
  },
1817
1880
  "tagName": "return",
@@ -1819,7 +1882,7 @@
1819
1882
  "__schema": "KeywordTypeSchema",
1820
1883
  "location": {
1821
1884
  "filePath": "component.ts",
1822
- "line": 342,
1885
+ "line": 352,
1823
1886
  "character": 16
1824
1887
  },
1825
1888
  "name": "boolean"
@@ -1829,7 +1892,7 @@
1829
1892
  "__schema": "TagSchema",
1830
1893
  "location": {
1831
1894
  "filePath": "component.ts",
1832
- "line": 343,
1895
+ "line": 353,
1833
1896
  "character": 6
1834
1897
  },
1835
1898
  "tagName": "memberof",
@@ -1844,7 +1907,7 @@
1844
1907
  "__schema": "ParameterSchema",
1845
1908
  "location": {
1846
1909
  "filePath": "component.ts",
1847
- "line": 346,
1910
+ "line": 356,
1848
1911
  "character": 10
1849
1912
  },
1850
1913
  "name": "component",
@@ -1852,7 +1915,7 @@
1852
1915
  "__schema": "TypeRefSchema",
1853
1916
  "location": {
1854
1917
  "filePath": "component.ts",
1855
- "line": 346,
1918
+ "line": 356,
1856
1919
  "character": 21
1857
1920
  },
1858
1921
  "name": "Component"
@@ -1865,7 +1928,7 @@
1865
1928
  "__schema": "KeywordTypeSchema",
1866
1929
  "location": {
1867
1930
  "filePath": "component.ts",
1868
- "line": 346,
1931
+ "line": 356,
1869
1932
  "character": 33
1870
1933
  },
1871
1934
  "name": "boolean"
@@ -2439,7 +2502,7 @@
2439
2502
  "_legacy": {
2440
2503
  "scope": "teambit.component",
2441
2504
  "name": "component",
2442
- "version": "1.0.199"
2505
+ "version": "1.0.200"
2443
2506
  },
2444
2507
  "_scope": "teambit.component"
2445
2508
  }
@@ -8152,7 +8215,7 @@
8152
8215
  "_legacy": {
8153
8216
  "scope": "teambit.component",
8154
8217
  "name": "component",
8155
- "version": "1.0.199"
8218
+ "version": "1.0.200"
8156
8219
  },
8157
8220
  "_scope": "teambit.component"
8158
8221
  }
@@ -18176,6 +18239,69 @@
18176
18239
  "line": 314,
18177
18240
  "character": 3
18178
18241
  },
18242
+ "raw": "/**\n * in case a component is new, it returns undefined.\n * otherwise, it returns the Snap object (hash/parents/log) of the current component (according to the version in the id)\n */",
18243
+ "comment": "in case a component is new, it returns undefined.\notherwise, it returns the Snap object (hash/parents/log) of the current component (according to the version in the id)"
18244
+ },
18245
+ "signature": "(method) Component.getCurrentSnap(): Promise<Snap | undefined>",
18246
+ "name": "getCurrentSnap",
18247
+ "params": [],
18248
+ "returnType": {
18249
+ "__schema": "TypeRefSchema",
18250
+ "location": {
18251
+ "filePath": "component.ts",
18252
+ "line": 318,
18253
+ "character": 27
18254
+ },
18255
+ "name": "Promise",
18256
+ "typeArgs": [
18257
+ {
18258
+ "__schema": "TypeUnionSchema",
18259
+ "location": {
18260
+ "filePath": "component.ts",
18261
+ "line": 318,
18262
+ "character": 35
18263
+ },
18264
+ "types": [
18265
+ {
18266
+ "__schema": "TypeRefSchema",
18267
+ "location": {
18268
+ "filePath": "component.ts",
18269
+ "line": 318,
18270
+ "character": 35
18271
+ },
18272
+ "name": "Snap"
18273
+ },
18274
+ {
18275
+ "__schema": "KeywordTypeSchema",
18276
+ "location": {
18277
+ "filePath": "component.ts",
18278
+ "line": 318,
18279
+ "character": 42
18280
+ },
18281
+ "name": "undefined"
18282
+ }
18283
+ ]
18284
+ }
18285
+ ]
18286
+ },
18287
+ "modifiers": [
18288
+ "async"
18289
+ ]
18290
+ },
18291
+ {
18292
+ "__schema": "FunctionLikeSchema",
18293
+ "location": {
18294
+ "filePath": "component.ts",
18295
+ "line": 328,
18296
+ "character": 3
18297
+ },
18298
+ "doc": {
18299
+ "__schema": "DocSchema",
18300
+ "location": {
18301
+ "filePath": "component.ts",
18302
+ "line": 324,
18303
+ "character": 3
18304
+ },
18179
18305
  "raw": "/**\n * checkout the component to a different version in its working tree.\n */",
18180
18306
  "comment": "checkout the component to a different version in its working tree."
18181
18307
  },
@@ -18186,7 +18312,7 @@
18186
18312
  "__schema": "ParameterSchema",
18187
18313
  "location": {
18188
18314
  "filePath": "component.ts",
18189
- "line": 318,
18315
+ "line": 328,
18190
18316
  "character": 12
18191
18317
  },
18192
18318
  "name": "version",
@@ -18194,7 +18320,7 @@
18194
18320
  "__schema": "TypeRefSchema",
18195
18321
  "location": {
18196
18322
  "filePath": "component.ts",
18197
- "line": 318,
18323
+ "line": 328,
18198
18324
  "character": 21
18199
18325
  },
18200
18326
  "name": "SemVer",
@@ -18208,7 +18334,7 @@
18208
18334
  "__schema": "InferenceTypeSchema",
18209
18335
  "location": {
18210
18336
  "filePath": "component.ts",
18211
- "line": 318,
18337
+ "line": 328,
18212
18338
  "character": 3
18213
18339
  },
18214
18340
  "type": "void"
@@ -18219,14 +18345,14 @@
18219
18345
  "__schema": "FunctionLikeSchema",
18220
18346
  "location": {
18221
18347
  "filePath": "component.ts",
18222
- "line": 336,
18348
+ "line": 346,
18223
18349
  "character": 3
18224
18350
  },
18225
18351
  "doc": {
18226
18352
  "__schema": "DocSchema",
18227
18353
  "location": {
18228
18354
  "filePath": "component.ts",
18229
- "line": 320,
18355
+ "line": 330,
18230
18356
  "character": 3
18231
18357
  },
18232
18358
  "raw": "/**\n * examine difference between two components.\n */",
@@ -18239,7 +18365,7 @@
18239
18365
  "__schema": "ParameterSchema",
18240
18366
  "location": {
18241
18367
  "filePath": "component.ts",
18242
- "line": 336,
18368
+ "line": 346,
18243
18369
  "character": 9
18244
18370
  },
18245
18371
  "name": "path",
@@ -18247,7 +18373,7 @@
18247
18373
  "__schema": "KeywordTypeSchema",
18248
18374
  "location": {
18249
18375
  "filePath": "component.ts",
18250
- "line": 336,
18376
+ "line": 346,
18251
18377
  "character": 15
18252
18378
  },
18253
18379
  "name": "string"
@@ -18259,7 +18385,7 @@
18259
18385
  "__schema": "ParameterSchema",
18260
18386
  "location": {
18261
18387
  "filePath": "component.ts",
18262
- "line": 336,
18388
+ "line": 346,
18263
18389
  "character": 23
18264
18390
  },
18265
18391
  "name": "fs",
@@ -18267,7 +18393,7 @@
18267
18393
  "__schema": "TypeRefSchema",
18268
18394
  "location": {
18269
18395
  "filePath": "component.ts",
18270
- "line": 336,
18396
+ "line": 346,
18271
18397
  "character": 28
18272
18398
  },
18273
18399
  "name": "AnyFS",
@@ -18281,7 +18407,7 @@
18281
18407
  "__schema": "InferenceTypeSchema",
18282
18408
  "location": {
18283
18409
  "filePath": "component.ts",
18284
- "line": 336,
18410
+ "line": 346,
18285
18411
  "character": 3
18286
18412
  },
18287
18413
  "type": "void"
@@ -18292,14 +18418,14 @@
18292
18418
  "__schema": "FunctionLikeSchema",
18293
18419
  "location": {
18294
18420
  "filePath": "component.ts",
18295
- "line": 346,
18421
+ "line": 356,
18296
18422
  "character": 3
18297
18423
  },
18298
18424
  "doc": {
18299
18425
  "__schema": "DocSchema",
18300
18426
  "location": {
18301
18427
  "filePath": "component.ts",
18302
- "line": 338,
18428
+ "line": 348,
18303
18429
  "character": 3
18304
18430
  },
18305
18431
  "raw": "/**\n *\n * Check if 2 components are equal\n * @param {Component} component\n * @returns {boolean}\n * @memberof Component\n */",
@@ -18309,7 +18435,7 @@
18309
18435
  "__schema": "PropertyLikeTagSchema",
18310
18436
  "location": {
18311
18437
  "filePath": "component.ts",
18312
- "line": 341,
18438
+ "line": 351,
18313
18439
  "character": 6
18314
18440
  },
18315
18441
  "name": "component",
@@ -18318,7 +18444,7 @@
18318
18444
  "__schema": "TypeRefSchema",
18319
18445
  "location": {
18320
18446
  "filePath": "component.ts",
18321
- "line": 341,
18447
+ "line": 351,
18322
18448
  "character": 14
18323
18449
  },
18324
18450
  "name": "Component"
@@ -18328,7 +18454,7 @@
18328
18454
  "__schema": "ReturnTagSchema",
18329
18455
  "location": {
18330
18456
  "filePath": "component.ts",
18331
- "line": 342,
18457
+ "line": 352,
18332
18458
  "character": 6
18333
18459
  },
18334
18460
  "tagName": "return",
@@ -18336,7 +18462,7 @@
18336
18462
  "__schema": "KeywordTypeSchema",
18337
18463
  "location": {
18338
18464
  "filePath": "component.ts",
18339
- "line": 342,
18465
+ "line": 352,
18340
18466
  "character": 16
18341
18467
  },
18342
18468
  "name": "boolean"
@@ -18346,7 +18472,7 @@
18346
18472
  "__schema": "TagSchema",
18347
18473
  "location": {
18348
18474
  "filePath": "component.ts",
18349
- "line": 343,
18475
+ "line": 353,
18350
18476
  "character": 6
18351
18477
  },
18352
18478
  "tagName": "memberof",
@@ -18361,7 +18487,7 @@
18361
18487
  "__schema": "ParameterSchema",
18362
18488
  "location": {
18363
18489
  "filePath": "component.ts",
18364
- "line": 346,
18490
+ "line": 356,
18365
18491
  "character": 10
18366
18492
  },
18367
18493
  "name": "component",
@@ -18369,7 +18495,7 @@
18369
18495
  "__schema": "TypeRefSchema",
18370
18496
  "location": {
18371
18497
  "filePath": "component.ts",
18372
- "line": 346,
18498
+ "line": 356,
18373
18499
  "character": 21
18374
18500
  },
18375
18501
  "name": "Component"
@@ -18382,7 +18508,7 @@
18382
18508
  "__schema": "KeywordTypeSchema",
18383
18509
  "location": {
18384
18510
  "filePath": "component.ts",
18385
- "line": 346,
18511
+ "line": 356,
18386
18512
  "character": 33
18387
18513
  },
18388
18514
  "name": "boolean"
@@ -18993,7 +19119,7 @@
18993
19119
  "_legacy": {
18994
19120
  "scope": "teambit.component",
18995
19121
  "name": "component",
18996
- "version": "1.0.199"
19122
+ "version": "1.0.200"
18997
19123
  },
18998
19124
  "_scope": "teambit.component"
18999
19125
  }
@@ -24273,7 +24399,7 @@
24273
24399
  "_legacy": {
24274
24400
  "scope": "teambit.component",
24275
24401
  "name": "component",
24276
- "version": "1.0.199"
24402
+ "version": "1.0.200"
24277
24403
  },
24278
24404
  "_scope": "teambit.component"
24279
24405
  }
@@ -30749,7 +30875,7 @@
30749
30875
  "_legacy": {
30750
30876
  "scope": "teambit.component",
30751
30877
  "name": "component",
30752
- "version": "1.0.199"
30878
+ "version": "1.0.200"
30753
30879
  },
30754
30880
  "_scope": "teambit.component"
30755
30881
  }
@@ -33220,7 +33346,7 @@
33220
33346
  "componentId": {
33221
33347
  "scope": "teambit.component",
33222
33348
  "name": "component",
33223
- "version": "1.0.199"
33349
+ "version": "1.0.200"
33224
33350
  },
33225
33351
  "taggedModuleExports": []
33226
33352
  }
@@ -147,6 +147,11 @@ export declare class Component implements IComponent {
147
147
  * if it's a tag, find the hash it points to.
148
148
  */
149
149
  getSnapHash(): string | undefined;
150
+ /**
151
+ * in case a component is new, it returns undefined.
152
+ * otherwise, it returns the Snap object (hash/parents/log) of the current component (according to the version in the id)
153
+ */
154
+ getCurrentSnap(): Promise<Snap | undefined>;
150
155
  /**
151
156
  * checkout the component to a different version in its working tree.
152
157
  */
package/dist/component.js CHANGED
@@ -323,6 +323,16 @@ class Component {
323
323
  return this.id.version;
324
324
  }
325
325
 
326
+ /**
327
+ * in case a component is new, it returns undefined.
328
+ * otherwise, it returns the Snap object (hash/parents/log) of the current component (according to the version in the id)
329
+ */
330
+ async getCurrentSnap() {
331
+ const snap = this.getSnapHash();
332
+ if (!snap) return undefined;
333
+ return this.loadSnap(snap);
334
+ }
335
+
326
336
  /**
327
337
  * checkout the component to a different version in its working tree.
328
338
  */
@@ -1 +1 @@
1
- {"version":3,"names":["_toolboxString","data","require","_bitError","_lodash","_tagMap","_exceptions","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","isDeleted","isRemoved","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","getTag","currentVersion","getSnapHash","hasVersion","checkout","write","path","fs","equals","component","toString","exports"],"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';\nimport { ComponentLog } from '@teambit/legacy/dist/scope/models/model-component';\n\nimport { slice } from 'lodash';\nimport { ComponentFactory } from './component-factory';\nimport ComponentFS from './component-fs';\n// import { NothingToSnap } from './exceptions';\nimport { Config as 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 * if on main, returns the head on main.\n * if on a lane, returns the head on the lane.\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?: {\n type?: string;\n offset?: number;\n limit?: number;\n head?: string;\n sort?: string;\n }): Promise<ComponentLog[]> {\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 * whether a component is marked as deleted.\n */\n isDeleted(): boolean {\n return this.state._consumer.isRemoved();\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 * id.version can be either a tag or a hash.\n * if it's a hash, it may have a tag point to it. if it does, return the tag.\n */\n getTag(): Tag | undefined {\n const currentVersion = this.id.version;\n if (!currentVersion) return undefined;\n return this.tags.byVersion(currentVersion) || this.tags.byHash(currentVersion);\n }\n\n /**\n * id.version can be either a tag or a hash.\n * if it's a tag, find the hash it points to.\n */\n getSnapHash(): string | undefined {\n if (!this.id.hasVersion()) return undefined;\n const tag = this.tags.byVersion(this.id.version);\n if (tag) return tag.hash;\n return this.id.version;\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,SAAAA,eAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,cAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAE,UAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAIA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IA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AAQ,CAAC,CAAC;EACvD;AACF;AAACC,OAAA,CAAAtG,SAAA,GAAAA,SAAA","ignoreList":[]}
1
+ {"version":3,"names":["_toolboxString","data","require","_bitError","_lodash","_tagMap","_exceptions","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","isDeleted","isRemoved","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","getTag","currentVersion","getSnapHash","hasVersion","getCurrentSnap","checkout","write","path","fs","equals","component","toString","exports"],"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';\nimport { ComponentLog } from '@teambit/legacy/dist/scope/models/model-component';\n\nimport { slice } from 'lodash';\nimport { ComponentFactory } from './component-factory';\nimport ComponentFS from './component-fs';\n// import { NothingToSnap } from './exceptions';\nimport { Config as 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 * if on main, returns the head on main.\n * if on a lane, returns the head on the lane.\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?: {\n type?: string;\n offset?: number;\n limit?: number;\n head?: string;\n sort?: string;\n }): Promise<ComponentLog[]> {\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 * whether a component is marked as deleted.\n */\n isDeleted(): boolean {\n return this.state._consumer.isRemoved();\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 * id.version can be either a tag or a hash.\n * if it's a hash, it may have a tag point to it. if it does, return the tag.\n */\n getTag(): Tag | undefined {\n const currentVersion = this.id.version;\n if (!currentVersion) return undefined;\n return this.tags.byVersion(currentVersion) || this.tags.byHash(currentVersion);\n }\n\n /**\n * id.version can be either a tag or a hash.\n * if it's a tag, find the hash it points to.\n */\n getSnapHash(): string | undefined {\n if (!this.id.hasVersion()) return undefined;\n const tag = this.tags.byVersion(this.id.version);\n if (tag) return tag.hash;\n return this.id.version;\n }\n\n /**\n * in case a component is new, it returns undefined.\n * otherwise, it returns the Snap object (hash/parents/log) of the current component (according to the version in the id)\n */\n async getCurrentSnap(): Promise<Snap | undefined> {\n const snap = this.getSnapHash();\n if (!snap) return undefined;\n return this.loadSnap(snap);\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,SAAAA,eAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,cAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAE,UAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAIA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAQA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,OAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAK,YAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,WAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAPA;;AAEA;;AAOA;;AASA;AACA;AACA;AACO,MAAMM,SAAS,CAAuB;EAC3CC,WAAWA;EACT;AACJ;AACA;EACaC,EAAe;EAExB;AACJ;AACA;AACA;AACA;EACaC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