@teambit/objects 0.0.731 → 0.0.733
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/models/model-component.js +8 -7
- package/dist/models/model-component.js.map +1 -1
- package/dist/models/model-component.spec.js +76 -0
- package/dist/models/model-component.spec.js.map +1 -1
- package/dist/models/version-history.js +2 -2
- package/dist/models/version-history.js.map +1 -1
- package/dist/models/version-history.spec.d.ts +1 -0
- package/dist/models/version-history.spec.js +79 -0
- package/dist/models/version-history.spec.js.map +1 -0
- package/dist/objects/object-list-to-graph.js +2 -2
- package/dist/objects/object-list-to-graph.js.map +1 -1
- package/models/model-component.spec.ts +69 -0
- package/models/model-component.ts +8 -7
- package/models/version-history.spec.ts +60 -0
- package/models/version-history.ts +2 -2
- package/objects/object-list-to-graph.ts +3 -3
- package/package.json +26 -26
- /package/dist/{preview-1793117184976.js → preview-1793136394048.js} +0 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import Ref from '../objects/ref';
|
|
3
|
+
import VersionHistory from './version-history';
|
|
4
|
+
import type { VersionParents } from './version-history';
|
|
5
|
+
|
|
6
|
+
const hash = (i: number) => i.toString(16).padStart(40, '0');
|
|
7
|
+
const ref = (i: number) => new Ref(hash(i));
|
|
8
|
+
const item = (i: number, parents: number[] = i > 0 ? [i - 1] : []): VersionParents => ({
|
|
9
|
+
hash: ref(i),
|
|
10
|
+
parents: parents.map(ref),
|
|
11
|
+
});
|
|
12
|
+
const linear = (from: number, to: number) => Array.from({ length: to - from }, (_, j) => item(from + j));
|
|
13
|
+
const create = (versions: VersionParents[]) => VersionHistory.create('button', 'acme.ui', versions);
|
|
14
|
+
const hashes = (versionHistory: VersionHistory) => versionHistory.versions.map((v) => v.hash.toString());
|
|
15
|
+
|
|
16
|
+
describe('VersionHistory', () => {
|
|
17
|
+
describe('merge', () => {
|
|
18
|
+
it('keeps the incoming versions, then the versions only the existing history has', () => {
|
|
19
|
+
const existing = create([...linear(0, 3), item(10, [2]), item(11, [10])]);
|
|
20
|
+
const incoming = create(linear(0, 5));
|
|
21
|
+
existing.merge(incoming);
|
|
22
|
+
expect(hashes(existing)).to.deep.equal([hash(0), hash(1), hash(2), hash(3), hash(4), hash(10), hash(11)]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('takes the incoming data of a version both histories have', () => {
|
|
26
|
+
const existing = create([item(0), item(1, [0]), item(2, [1])]);
|
|
27
|
+
const incoming = create([item(0), item(1, [0]), item(2, [0])]);
|
|
28
|
+
existing.merge(incoming);
|
|
29
|
+
expect(existing.getVersionData(ref(2))?.parents.map(String)).to.deep.equal([hash(0)]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('keeps the existing history when the incoming one is empty', () => {
|
|
33
|
+
const existing = create(linear(0, 3));
|
|
34
|
+
existing.merge(create([]));
|
|
35
|
+
expect(hashes(existing)).to.deep.equal(hashes(create(linear(0, 3))));
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('takes the incoming history when the existing one is empty', () => {
|
|
39
|
+
const existing = create([]);
|
|
40
|
+
existing.merge(create(linear(0, 3)));
|
|
41
|
+
expect(hashes(existing)).to.deep.equal(hashes(create(linear(0, 3))));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('stays the same when the incoming history is already part of the existing one', () => {
|
|
45
|
+
const existing = create([...linear(0, 4), item(20, [3])]);
|
|
46
|
+
existing.merge(create(linear(0, 4)));
|
|
47
|
+
expect(hashes(existing).sort()).to.deep.equal([hash(0), hash(1), hash(2), hash(3), hash(20)].sort());
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('stays fast when the existing history has thousands of versions the incoming one does not', () => {
|
|
51
|
+
const size = 20000;
|
|
52
|
+
const existing = create([...linear(0, size), ...Array.from({ length: size }, (_, j) => item(size + j, [j]))]);
|
|
53
|
+
const incoming = create(linear(0, size));
|
|
54
|
+
const start = Date.now();
|
|
55
|
+
existing.merge(incoming);
|
|
56
|
+
expect(existing.versions).to.have.length(size * 2);
|
|
57
|
+
expect(Date.now() - start).to.be.lessThan(2000);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -169,8 +169,8 @@ export default class VersionHistory extends BitObject {
|
|
|
169
169
|
merge(versionHistory: VersionHistory) {
|
|
170
170
|
const existingHashes = this.getAllHashesAsString();
|
|
171
171
|
const incomingHashes = versionHistory.getAllHashesAsString();
|
|
172
|
-
const hashesInExistingOnly = difference(existingHashes, incomingHashes);
|
|
173
|
-
const versionsDataOnExistingOnly = this.versions.filter((v) => hashesInExistingOnly.
|
|
172
|
+
const hashesInExistingOnly = new Set(difference(existingHashes, incomingHashes));
|
|
173
|
+
const versionsDataOnExistingOnly = this.versions.filter((v) => hashesInExistingOnly.has(v.hash.toString()));
|
|
174
174
|
const newVersions = [...versionHistory.versions, ...versionsDataOnExistingOnly];
|
|
175
175
|
this.versionsObj = this.versionParentsToObject(newVersions);
|
|
176
176
|
}
|
|
@@ -3,7 +3,7 @@ import { uniqBy } from 'lodash';
|
|
|
3
3
|
import type { ComponentID } from '@teambit/component-id';
|
|
4
4
|
import type { ObjectList } from './object-list';
|
|
5
5
|
import type { BitObjectList } from './bit-object-list';
|
|
6
|
-
import { getAllVersionsInfo } from '@teambit/component.snap-distance';
|
|
6
|
+
import { getAllVersionsInfo, indexVersionObjects } from '@teambit/component.snap-distance';
|
|
7
7
|
|
|
8
8
|
type BitIdNode = Node<ComponentID>;
|
|
9
9
|
type DependencyType = 'runtime' | 'dev' | 'peer';
|
|
@@ -24,7 +24,7 @@ export async function objectListToGraph(objectList: ObjectList): Promise<IdGraph
|
|
|
24
24
|
export async function bitObjectListToGraph(bitObjectsList: BitObjectList): Promise<IdGraph> {
|
|
25
25
|
const exportMetadata = bitObjectsList.getExportMetadata();
|
|
26
26
|
const components = bitObjectsList.getComponents();
|
|
27
|
-
const
|
|
27
|
+
const versionObjectsByHash = indexVersionObjects(bitObjectsList.getVersions());
|
|
28
28
|
const nodes: BitIdNode[] = [];
|
|
29
29
|
const edges: DependencyEdge[] = [];
|
|
30
30
|
await Promise.all(
|
|
@@ -35,7 +35,7 @@ export async function bitObjectListToGraph(bitObjectsList: BitObjectList): Promi
|
|
|
35
35
|
const startFrom = compFromMetadata?.head;
|
|
36
36
|
const versionsInfo = await getAllVersionsInfo({
|
|
37
37
|
modelComponent: component,
|
|
38
|
-
versionObjects:
|
|
38
|
+
versionObjects: versionObjectsByHash,
|
|
39
39
|
startFrom,
|
|
40
40
|
throws: false,
|
|
41
41
|
});
|
package/package.json
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/objects",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.733",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/scope/objects",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.scope",
|
|
8
8
|
"name": "objects",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.733"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@pnpm/lockfile.types": "1100.0.19",
|
|
13
|
-
"semver": "7.7.1",
|
|
14
12
|
"lodash": "4.18.1",
|
|
15
|
-
"uuid": "8.3.2",
|
|
16
|
-
"async-mutex": "0.3.1",
|
|
17
|
-
"p-map-series": "2.1.0",
|
|
18
13
|
"tar-stream": "2.2.0",
|
|
14
|
+
"p-map-series": "2.1.0",
|
|
15
|
+
"async-mutex": "0.3.1",
|
|
19
16
|
"fs-extra": "10.0.0",
|
|
20
17
|
"glob": "13.0.0",
|
|
18
|
+
"@pnpm/lockfile.types": "1100.0.19",
|
|
19
|
+
"semver": "7.7.1",
|
|
20
|
+
"uuid": "8.3.2",
|
|
21
21
|
"@teambit/harmony": "0.4.12",
|
|
22
22
|
"@teambit/harmony.modules.runtimes": "0.0.4",
|
|
23
23
|
"@teambit/component-id": "1.2.5",
|
|
24
|
+
"@teambit/graph.cleargraph": "0.0.11",
|
|
25
|
+
"@teambit/harmony.modules.concurrency": "0.0.51",
|
|
26
|
+
"@teambit/legacy.logger": "0.0.71",
|
|
27
|
+
"@teambit/toolbox.promise.map-pool": "0.0.24",
|
|
28
|
+
"@teambit/legacy.constants": "0.0.50",
|
|
24
29
|
"@teambit/legacy.utils": "0.0.56",
|
|
30
|
+
"@teambit/toolbox.crypto.sha1": "0.0.24",
|
|
25
31
|
"@teambit/bit-error": "0.0.404",
|
|
26
32
|
"@teambit/component-version": "1.0.4",
|
|
33
|
+
"@teambit/harmony.modules.in-memory-cache": "0.0.55",
|
|
34
|
+
"@teambit/toolbox.fs.remove-empty-dir": "0.0.22",
|
|
27
35
|
"@teambit/lane-id": "0.0.312",
|
|
28
36
|
"@teambit/legacy.cli.error": "0.0.72",
|
|
29
|
-
"@teambit/
|
|
30
|
-
"@teambit/legacy.logger": "0.0.71",
|
|
31
|
-
"@teambit/toolbox.crypto.sha1": "0.0.24",
|
|
32
|
-
"@teambit/harmony.modules.concurrency": "0.0.51",
|
|
37
|
+
"@teambit/component.sources": "0.0.245",
|
|
33
38
|
"@teambit/legacy-bit-id": "1.1.4",
|
|
34
39
|
"@teambit/legacy-component-log": "0.0.434",
|
|
35
|
-
"@teambit/pkg.modules.semver-helper": "0.0.38",
|
|
36
|
-
"@teambit/toolbox.array.duplications-finder": "0.0.19",
|
|
37
|
-
"@teambit/toolbox.promise.map-pool": "0.0.24",
|
|
38
|
-
"@teambit/graph.cleargraph": "0.0.11",
|
|
39
|
-
"@teambit/bit.get-bit-version": "0.0.31",
|
|
40
|
-
"@teambit/harmony.modules.in-memory-cache": "0.0.55",
|
|
41
|
-
"@teambit/toolbox.fs.remove-empty-dir": "0.0.22",
|
|
42
|
-
"@teambit/harmony.modules.get-basic-log": "0.0.197",
|
|
43
|
-
"@teambit/component.snap-distance": "0.0.193",
|
|
44
|
-
"@teambit/config-store": "0.0.308",
|
|
45
|
-
"@teambit/legacy.scope": "0.0.196",
|
|
46
|
-
"@teambit/component.sources": "0.0.245",
|
|
47
40
|
"@teambit/legacy.consumer-component": "0.0.194",
|
|
48
41
|
"@teambit/legacy.consumer-config": "0.0.193",
|
|
49
42
|
"@teambit/legacy.extension-data": "0.0.195",
|
|
50
|
-
"@teambit/
|
|
43
|
+
"@teambit/pkg.modules.semver-helper": "0.0.38",
|
|
44
|
+
"@teambit/toolbox.array.duplications-finder": "0.0.19",
|
|
45
|
+
"@teambit/bit.get-bit-version": "0.0.31",
|
|
46
|
+
"@teambit/semantics.doc-parser": "0.0.201",
|
|
47
|
+
"@teambit/component.snap-distance": "0.0.194",
|
|
48
|
+
"@teambit/legacy.scope": "0.0.197",
|
|
49
|
+
"@teambit/harmony.modules.get-basic-log": "0.0.198",
|
|
50
|
+
"@teambit/config-store": "0.0.309"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@types/semver": "7.5.8",
|
|
54
53
|
"@types/lodash": "4.14.165",
|
|
55
|
-
"@types/uuid": "8.3.4",
|
|
56
54
|
"@types/fs-extra": "9.0.7",
|
|
55
|
+
"@types/semver": "7.5.8",
|
|
56
|
+
"@types/uuid": "8.3.4",
|
|
57
57
|
"@teambit/harmony.envs.core-aspect-env": "2.1.2"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
File without changes
|