@teambit/objects 0.0.709 → 0.0.711
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/index.d.ts +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/models/model-component.js +3 -2
- package/dist/models/model-component.js.map +1 -1
- package/dist/models/version.d.ts +48 -13
- package/dist/models/version.js +162 -44
- package/dist/models/version.js.map +1 -1
- package/dist/models/version.spec.js +128 -0
- package/dist/models/version.spec.js.map +1 -1
- package/dist/objects/bit-object-list.d.ts +11 -1
- package/dist/objects/bit-object-list.js +15 -1
- package/dist/objects/bit-object-list.js.map +1 -1
- package/dist/objects/object-list.js +3 -1
- package/dist/objects/object-list.js.map +1 -1
- package/dist/objects/repository.d.ts +4 -0
- package/dist/objects/repository.js +7 -0
- package/dist/objects/repository.js.map +1 -1
- package/models/model-component.ts +4 -2
- package/models/version.spec.ts +115 -0
- package/models/version.ts +178 -46
- package/objects/bit-object-list.ts +18 -1
- package/objects/object-list.ts +3 -1
- package/objects/repository.ts +7 -0
- package/package.json +20 -20
- /package/dist/{preview-1791321635614.js → preview-1791474723254.js} +0 -0
package/models/version.ts
CHANGED
|
@@ -29,6 +29,57 @@ import Source from './source';
|
|
|
29
29
|
import { DependenciesGraph } from './dependencies-graph';
|
|
30
30
|
import { getBitVersion } from '@teambit/bit.get-bit-version';
|
|
31
31
|
|
|
32
|
+
// the same flattened dependencies repeat across versions. in a typical scope, hundreds of thousands of entries are a
|
|
33
|
+
// few thousand unique ids. ids are immutable, so the versions share them instead of each holding its own copies.
|
|
34
|
+
// an id object is looked up by its parts (scope, then name, then version). building a key string for each entry instead
|
|
35
|
+
// is slower than creating a new id.
|
|
36
|
+
const flattenedIdsCache = new Map<string, Map<string, Map<string, ComponentID>>>();
|
|
37
|
+
const flattenedIdStrsCache = new Map<string, ComponentID>();
|
|
38
|
+
const MAX_CACHED_FLATTENED_IDS = 100_000;
|
|
39
|
+
let cachedFlattenedIds = 0;
|
|
40
|
+
|
|
41
|
+
function countCachedFlattenedId() {
|
|
42
|
+
if (cachedFlattenedIds >= MAX_CACHED_FLATTENED_IDS) {
|
|
43
|
+
flattenedIdsCache.clear();
|
|
44
|
+
flattenedIdStrsCache.clear();
|
|
45
|
+
cachedFlattenedIds = 0;
|
|
46
|
+
}
|
|
47
|
+
cachedFlattenedIds += 1;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getFlattenedId(dep: string | Record<string, any>): ComponentID {
|
|
51
|
+
if (typeof dep === 'string') {
|
|
52
|
+
let id = flattenedIdStrsCache.get(dep);
|
|
53
|
+
if (!id) {
|
|
54
|
+
countCachedFlattenedId();
|
|
55
|
+
id = ComponentID.fromString(dep);
|
|
56
|
+
flattenedIdStrsCache.set(dep, id);
|
|
57
|
+
}
|
|
58
|
+
return id;
|
|
59
|
+
}
|
|
60
|
+
if (dep.box) return ComponentID.fromObject(dep as any); // legacy ids, rare. not worth another level.
|
|
61
|
+
let byName = flattenedIdsCache.get(dep.scope);
|
|
62
|
+
if (!byName) {
|
|
63
|
+
byName = new Map();
|
|
64
|
+
flattenedIdsCache.set(dep.scope, byName);
|
|
65
|
+
}
|
|
66
|
+
let byVersion = byName.get(dep.name);
|
|
67
|
+
if (!byVersion) {
|
|
68
|
+
byVersion = new Map();
|
|
69
|
+
byName.set(dep.name, byVersion);
|
|
70
|
+
}
|
|
71
|
+
let id = byVersion.get(dep.version);
|
|
72
|
+
if (!id) {
|
|
73
|
+
countCachedFlattenedId();
|
|
74
|
+
id = ComponentID.fromObject(dep as any);
|
|
75
|
+
byVersion.set(dep.version, id);
|
|
76
|
+
}
|
|
77
|
+
return id;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// the deprecated `Version.flattenedDependencies` getter warns only once per process.
|
|
81
|
+
let warnedFlattenedDependenciesGetter = false;
|
|
82
|
+
|
|
32
83
|
export type SourceFileModel = {
|
|
33
84
|
name: string;
|
|
34
85
|
relativePath: PathLinux;
|
|
@@ -50,6 +101,9 @@ export type Log = {
|
|
|
50
101
|
email: string | undefined;
|
|
51
102
|
};
|
|
52
103
|
|
|
104
|
+
// anything objects can be loaded from by their ref: the scope repository, or the objects received from a remote.
|
|
105
|
+
export type ObjectsLoader = { load(ref: Ref, throws?: boolean): Promise<BitObject | undefined> };
|
|
106
|
+
|
|
53
107
|
export type DepEdgeType = 'prod' | 'dev' | 'peer' | 'ext';
|
|
54
108
|
export type DepEdge = { source: ComponentID; target: ComponentID; type: DepEdgeType };
|
|
55
109
|
|
|
@@ -66,6 +120,7 @@ export type VersionProps = {
|
|
|
66
120
|
devDependencies?: Dependency[];
|
|
67
121
|
peerDependencies?: Dependency[];
|
|
68
122
|
flattenedDependencies?: ComponentIdList;
|
|
123
|
+
flattenedDependenciesRef?: Ref;
|
|
69
124
|
_flattenedEdges?: DepEdge[];
|
|
70
125
|
flattenedEdges?: DepEdge[];
|
|
71
126
|
flattenedEdgesRef?: Ref;
|
|
@@ -102,23 +157,23 @@ export default class Version extends BitObject {
|
|
|
102
157
|
dependencies: Dependencies;
|
|
103
158
|
devDependencies: Dependencies;
|
|
104
159
|
peerDependencies: Dependencies;
|
|
105
|
-
|
|
160
|
+
private _flattenedDependencies?: ComponentIdList;
|
|
161
|
+
// the flattened dependencies of a parsed Version. the list is built on first access, most commands never read it.
|
|
162
|
+
private flattenedDependencyIds?: ComponentID[];
|
|
163
|
+
/**
|
|
164
|
+
* ref to a Source object with the flattened dependencies, as a JSON array of id strings. when it's set, the Version
|
|
165
|
+
* itself has no flattened dependencies, and they have to be loaded with `loadFlattenedDependencies()`.
|
|
166
|
+
*/
|
|
167
|
+
flattenedDependenciesRef?: Ref;
|
|
106
168
|
dependenciesGraphRef?: Ref;
|
|
107
169
|
_dependenciesGraph?: DependenciesGraph; // caching for the dependencies graph
|
|
108
170
|
flattenedEdgesRef?: Ref; // ref to a BitObject Source file, which is a JSON object containing the flattened edge
|
|
109
171
|
_flattenedEdges?: DepEdge[]; // caching for the flattenedEdges
|
|
110
172
|
/**
|
|
111
173
|
* @deprecated
|
|
112
|
-
* to get the flattenedEdges, please use `this.getFlattenedEdges()
|
|
113
|
-
* this
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* the reason this is left here is not for backward compatibility, but for forward compatibility. meaning, if a
|
|
117
|
-
* Version object created by the new version is parsed by an old version that doesn't support the flattenedEdgesRef,
|
|
118
|
-
* then, it'll be able to still get the flattenedEdges by this prop.
|
|
119
|
-
* this is causing duplication currently. the data is kept in both, `this.flattenedEdges` and the file stored in `flattenedEdgesRef`.
|
|
120
|
-
* so it'll be best to delete this prop as soon as all scopes are deployed with the new version.
|
|
121
|
-
* (around August 2023 should be safe)
|
|
174
|
+
* to get the flattenedEdges, please use `this.getFlattenedEdges()`, which supports both formats.
|
|
175
|
+
* this holds the edges of old Versions, which were saved inside the Version, before `flattenedEdgesRef` was
|
|
176
|
+
* introduced. Versions that have `flattenedEdgesRef` don't save the edges here (see `toObject()`).
|
|
122
177
|
*/
|
|
123
178
|
private flattenedEdges: DepEdge[];
|
|
124
179
|
packageDependencies: { [key: string]: string };
|
|
@@ -154,7 +209,8 @@ export default class Version extends BitObject {
|
|
|
154
209
|
this.devDependencies = new Dependencies(props.devDependencies);
|
|
155
210
|
this.peerDependencies = new Dependencies(props.peerDependencies);
|
|
156
211
|
this.docs = props.docs;
|
|
157
|
-
this.flattenedDependencies = props.flattenedDependencies
|
|
212
|
+
if (props.flattenedDependencies) this.flattenedDependencies = props.flattenedDependencies;
|
|
213
|
+
this.flattenedDependenciesRef = props.flattenedDependenciesRef;
|
|
158
214
|
this.flattenedEdges = props.flattenedEdges || [];
|
|
159
215
|
this.flattenedEdgesRef = props.flattenedEdgesRef;
|
|
160
216
|
this.dependenciesGraphRef = props.dependenciesGraphRef;
|
|
@@ -306,8 +362,101 @@ export default class Version extends BitObject {
|
|
|
306
362
|
return this.modified[this.modified.length - 1].date;
|
|
307
363
|
}
|
|
308
364
|
|
|
309
|
-
|
|
310
|
-
|
|
365
|
+
/**
|
|
366
|
+
* @deprecated use `await version.loadFlattenedDependencies(repo)`, which supports both formats. this getter throws
|
|
367
|
+
* when the flattened dependencies are stored in a separate object (`flattenedDependenciesRef`) and weren't loaded.
|
|
368
|
+
* bit doesn't write this format yet, so until it does (around Oct 2027), the getter keeps working.
|
|
369
|
+
*/
|
|
370
|
+
get flattenedDependencies(): ComponentIdList {
|
|
371
|
+
if (!warnedFlattenedDependenciesGetter) {
|
|
372
|
+
warnedFlattenedDependenciesGetter = true;
|
|
373
|
+
logger.warn(
|
|
374
|
+
`Version.flattenedDependencies is deprecated and will throw for newer versions, use "await version.loadFlattenedDependencies(repo)" instead`,
|
|
375
|
+
new Error().stack
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
return this.getLoadedFlattenedDependencies();
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* the flattened dependencies, when they're stored in the Version itself or were loaded already. throws otherwise,
|
|
383
|
+
* when they're stored in a separate object (`flattenedDependenciesRef`), use `loadFlattenedDependencies()`.
|
|
384
|
+
*/
|
|
385
|
+
getLoadedFlattenedDependencies(): ComponentIdList {
|
|
386
|
+
if (!this._flattenedDependencies) {
|
|
387
|
+
if (this.flattenedDependenciesRef) {
|
|
388
|
+
throw new Error(
|
|
389
|
+
`the flattened dependencies of version ${this._hash} are stored in the object ${this.flattenedDependenciesRef.toString()}, load them with loadFlattenedDependencies()`
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
this._flattenedDependencies = ComponentIdList.fromArray(this.flattenedDependencyIds || []);
|
|
393
|
+
this.flattenedDependencyIds = undefined;
|
|
394
|
+
}
|
|
395
|
+
return this._flattenedDependencies;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* a new list is saved in the Version itself, so a ref to a separate object, if there was one, is dropped.
|
|
400
|
+
*/
|
|
401
|
+
set flattenedDependencies(flattenedDependencies: ComponentIdList) {
|
|
402
|
+
this._flattenedDependencies = flattenedDependencies;
|
|
403
|
+
this.flattenedDependencyIds = undefined;
|
|
404
|
+
this.flattenedDependenciesRef = undefined;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* the flattened dependencies, if they're available without loading a separate object. otherwise, undefined.
|
|
409
|
+
*/
|
|
410
|
+
getFlattenedDependenciesIfLoaded(): ComponentIdList | undefined {
|
|
411
|
+
if (this.flattenedDependenciesRef && !this._flattenedDependencies) return undefined;
|
|
412
|
+
return this.getLoadedFlattenedDependencies();
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* use this to get the flattened dependencies. it supports both formats: stored in the Version itself, or stored in
|
|
417
|
+
* a separate Source object (`flattenedDependenciesRef`). `objects` is usually the scope repository, but can be any
|
|
418
|
+
* container of the objects, such as the objects received from a remote.
|
|
419
|
+
*/
|
|
420
|
+
async loadFlattenedDependencies(objects: ObjectsLoader): Promise<ComponentIdList> {
|
|
421
|
+
if (this._flattenedDependencies || !this.flattenedDependenciesRef) return this.getLoadedFlattenedDependencies();
|
|
422
|
+
const source = (await objects.load(this.flattenedDependenciesRef, false)) as Source | undefined;
|
|
423
|
+
return this.setFlattenedDependenciesFromSource(source);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* same as `loadFlattenedDependencies()`, for code that can't be async.
|
|
428
|
+
*/
|
|
429
|
+
loadFlattenedDependenciesSync(repo: Repository): ComponentIdList {
|
|
430
|
+
if (this._flattenedDependencies || !this.flattenedDependenciesRef) return this.getLoadedFlattenedDependencies();
|
|
431
|
+
// objects added during tag, or fetched from a remote without being imported, are only in memory, not on the disk.
|
|
432
|
+
const source = (repo.getFromMemory(this.flattenedDependenciesRef) ||
|
|
433
|
+
repo.loadSync(this.flattenedDependenciesRef, false)) as Source | undefined;
|
|
434
|
+
return this.setFlattenedDependenciesFromSource(source);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
private setFlattenedDependenciesFromSource(source?: Source): ComponentIdList {
|
|
438
|
+
if (!source) {
|
|
439
|
+
// unlike the flattened edges, there is no fallback here. an empty list would be wrong, not just less efficient.
|
|
440
|
+
throw new Error(
|
|
441
|
+
`unable to find the object ${this.flattenedDependenciesRef?.toString()} with the flattened dependencies of version ${this._hash}`
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
const ids: string[] = JSON.parse(source.contents.toString());
|
|
445
|
+
// not by the setter, which would drop the ref.
|
|
446
|
+
this._flattenedDependencies = ComponentIdList.fromArray(ids.map(getFlattenedId));
|
|
447
|
+
this.flattenedDependencyIds = undefined;
|
|
448
|
+
return this._flattenedDependencies;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* moves the flattened dependencies out of this Version into a new Source object, which the caller has to persist.
|
|
453
|
+
*/
|
|
454
|
+
moveFlattenedDependenciesToSource(): Source | undefined {
|
|
455
|
+
const flattenedDependencies = this.getLoadedFlattenedDependencies();
|
|
456
|
+
if (!flattenedDependencies.length) return undefined;
|
|
457
|
+
const source = Source.from(Buffer.from(JSON.stringify(flattenedDependencies.map((id) => id.toString()))));
|
|
458
|
+
this.flattenedDependenciesRef = source.hash();
|
|
459
|
+
return source;
|
|
311
460
|
}
|
|
312
461
|
|
|
313
462
|
getAllDependencies(): Dependency[] {
|
|
@@ -346,17 +495,6 @@ export default class Version extends BitObject {
|
|
|
346
495
|
return ComponentIdList.fromArray([...this.dependencies.getAllIds(), ...this.devDependencies.getAllIds()]);
|
|
347
496
|
}
|
|
348
497
|
|
|
349
|
-
updateFlattenedDependency(currentId: ComponentID, newId: ComponentID) {
|
|
350
|
-
const getUpdated = (flattenedDependencies: ComponentIdList): ComponentIdList => {
|
|
351
|
-
const updatedIds = flattenedDependencies.map((depId) => {
|
|
352
|
-
if (depId.isEqual(currentId)) return newId;
|
|
353
|
-
return depId;
|
|
354
|
-
});
|
|
355
|
-
return ComponentIdList.fromArray(updatedIds);
|
|
356
|
-
};
|
|
357
|
-
this.flattenedDependencies = getUpdated(this.flattenedDependencies);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
498
|
refs(): Ref[] {
|
|
361
499
|
return this.refsWithOptions();
|
|
362
500
|
}
|
|
@@ -378,6 +516,7 @@ export default class Version extends BitObject {
|
|
|
378
516
|
}
|
|
379
517
|
if (this.flattenedEdgesRef) allRefs.push(this.flattenedEdgesRef);
|
|
380
518
|
if (this.dependenciesGraphRef) allRefs.push(this.dependenciesGraphRef);
|
|
519
|
+
if (this.flattenedDependenciesRef) allRefs.push(this.flattenedDependenciesRef);
|
|
381
520
|
return allRefs;
|
|
382
521
|
}
|
|
383
522
|
|
|
@@ -467,9 +606,10 @@ export default class Version extends BitObject {
|
|
|
467
606
|
docs: this.docs,
|
|
468
607
|
dependencies: this.dependencies.cloneAsObject(),
|
|
469
608
|
devDependencies: this.devDependencies.cloneAsObject(),
|
|
470
|
-
flattenedDependencies: this.
|
|
471
|
-
|
|
472
|
-
|
|
609
|
+
flattenedDependencies: this.flattenedDependenciesRef
|
|
610
|
+
? undefined
|
|
611
|
+
: this.getLoadedFlattenedDependencies().map((dep) => dep.toObject()),
|
|
612
|
+
flattenedDependenciesRef: this.flattenedDependenciesRef?.toString(),
|
|
473
613
|
flattenedEdges: this.flattenedEdgesRef ? undefined : this.flattenedEdges.map((f) => Version.depEdgeToObject(f)),
|
|
474
614
|
flattenedEdgesRef: this.flattenedEdgesRef?.toString(),
|
|
475
615
|
dependenciesGraphRef: this.dependenciesGraphRef?.toString(),
|
|
@@ -529,6 +669,7 @@ export default class Version extends BitObject {
|
|
|
529
669
|
devDependencies,
|
|
530
670
|
flattenedDependencies,
|
|
531
671
|
flattenedDevDependencies,
|
|
672
|
+
flattenedDependenciesRef,
|
|
532
673
|
flattenedEdges,
|
|
533
674
|
flattenedEdgesRef,
|
|
534
675
|
dependenciesGraphRef,
|
|
@@ -577,21 +718,6 @@ export default class Version extends BitObject {
|
|
|
577
718
|
});
|
|
578
719
|
};
|
|
579
720
|
|
|
580
|
-
// Accept both string[] and object[] for backward compatibility
|
|
581
|
-
const parseFlattenedDeps = (deps = []): ComponentID[] => {
|
|
582
|
-
if (!deps.length) return [];
|
|
583
|
-
if (typeof deps[0] === 'string') return deps.map((dep) => ComponentID.fromString(dep));
|
|
584
|
-
return deps.map((dep) => ComponentID.fromObject(dep));
|
|
585
|
-
};
|
|
586
|
-
|
|
587
|
-
const _groupFlattenedDependencies = () => {
|
|
588
|
-
// support backward compatibility. until v15, there was both flattenedDependencies and
|
|
589
|
-
// flattenedDevDependencies. since then, these both were grouped to one flattenedDependencies
|
|
590
|
-
const flattenedDeps = parseFlattenedDeps(flattenedDependencies);
|
|
591
|
-
const flattenedDevDeps = parseFlattenedDeps(flattenedDevDependencies);
|
|
592
|
-
return ComponentIdList.fromArray([...flattenedDeps, ...flattenedDevDeps]);
|
|
593
|
-
};
|
|
594
|
-
|
|
595
721
|
const parseFile = (file) => {
|
|
596
722
|
return {
|
|
597
723
|
file: Ref.from(file.file),
|
|
@@ -622,7 +748,7 @@ export default class Version extends BitObject {
|
|
|
622
748
|
return new ExtensionDataList();
|
|
623
749
|
};
|
|
624
750
|
|
|
625
|
-
|
|
751
|
+
const version = new Version({
|
|
626
752
|
mainFile,
|
|
627
753
|
files: files.map(parseFile),
|
|
628
754
|
bindingPrefix,
|
|
@@ -638,11 +764,11 @@ export default class Version extends BitObject {
|
|
|
638
764
|
docs,
|
|
639
765
|
dependencies: _getDependencies(dependencies),
|
|
640
766
|
devDependencies: _getDependencies(devDependencies),
|
|
641
|
-
flattenedDependencies: _groupFlattenedDependencies(),
|
|
642
767
|
// backward compatibility. before introducing `flattenedEdgesRef`, we only had `flattenedEdges`. see getFlattenedEdges() for more info.
|
|
643
768
|
flattenedEdges: flattenedEdgesRef ? [] : flattenedEdges?.map((f) => Version.depEdgeFromObject(f)) || [],
|
|
644
769
|
flattenedEdgesRef: flattenedEdgesRef ? Ref.from(flattenedEdgesRef) : undefined,
|
|
645
770
|
dependenciesGraphRef: dependenciesGraphRef ? Ref.from(dependenciesGraphRef) : undefined,
|
|
771
|
+
flattenedDependenciesRef: flattenedDependenciesRef ? Ref.from(flattenedDependenciesRef) : undefined,
|
|
646
772
|
devPackageDependencies,
|
|
647
773
|
peerPackageDependencies,
|
|
648
774
|
packageDependencies,
|
|
@@ -662,6 +788,12 @@ export default class Version extends BitObject {
|
|
|
662
788
|
hidden,
|
|
663
789
|
batchId,
|
|
664
790
|
});
|
|
791
|
+
// until v15, there were both flattenedDependencies and flattenedDevDependencies. since then, they're grouped into
|
|
792
|
+
// flattenedDependencies. an entry is either an id string or an id object.
|
|
793
|
+
version.flattenedDependencyIds = [...(flattenedDependencies || []), ...(flattenedDevDependencies || [])].map(
|
|
794
|
+
getFlattenedId
|
|
795
|
+
);
|
|
796
|
+
return version;
|
|
665
797
|
}
|
|
666
798
|
|
|
667
799
|
/**
|
|
@@ -709,7 +841,7 @@ export default class Version extends BitObject {
|
|
|
709
841
|
peerPackageDependencies: component.peerPackageDependencies,
|
|
710
842
|
dependenciesGraphRef: dependenciesGraph?.hash(),
|
|
711
843
|
flattenedDependencies: component.flattenedDependencies,
|
|
712
|
-
//
|
|
844
|
+
// not saved in the Version when `flattenedEdgesRef` is set, see `toObject()`.
|
|
713
845
|
flattenedEdges: component.flattenedEdges,
|
|
714
846
|
flattenedEdgesRef: flattenedEdges?.hash(),
|
|
715
847
|
schema: component.schema,
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import type BitObject from './object';
|
|
2
|
+
import type Ref from './ref';
|
|
2
3
|
import { ExportMetadata, Lane, LaneHistory, ModelComponent, Version, VersionHistory } from '../models';
|
|
3
4
|
|
|
4
5
|
export class BitObjectList {
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* `objectsByRef` maps the refs the objects were received with, so finding an object doesn't need hashing them all.
|
|
8
|
+
*/
|
|
9
|
+
constructor(
|
|
10
|
+
private objects: BitObject[],
|
|
11
|
+
private objectsByRef = new Map<string, BitObject>()
|
|
12
|
+
) {}
|
|
6
13
|
|
|
7
14
|
getComponents(): ModelComponent[] {
|
|
8
15
|
return this.objects.filter((object) => object instanceof ModelComponent) as ModelComponent[];
|
|
@@ -28,6 +35,16 @@ export class BitObjectList {
|
|
|
28
35
|
return this.objects;
|
|
29
36
|
}
|
|
30
37
|
|
|
38
|
+
/**
|
|
39
|
+
* finds an object of this list by its ref. it has the same signature as `Repository.load()`, so these objects can be
|
|
40
|
+
* used where a repository is expected, e.g. `Version.loadFlattenedDependencies()`.
|
|
41
|
+
*/
|
|
42
|
+
async load(ref: Ref): Promise<BitObject | undefined> {
|
|
43
|
+
const object = this.objectsByRef.get(ref.toString());
|
|
44
|
+
// a received ref is not trusted, the found object is hashed to verify it.
|
|
45
|
+
return object?.hash().isEqual(ref) ? object : undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
31
48
|
excludeTypes(types: string[]): BitObject[] {
|
|
32
49
|
return this.objects.filter((object) => !types.includes(object.getType()));
|
|
33
50
|
}
|
package/objects/object-list.ts
CHANGED
|
@@ -290,11 +290,13 @@ export class ObjectList {
|
|
|
290
290
|
): Promise<{ bitObjectList: BitObjectList; rawSources: RawObjectsMap }> {
|
|
291
291
|
const concurrency = concurrentIOLimit();
|
|
292
292
|
const rawSources: RawObjectsMap = new Map();
|
|
293
|
+
const objectsByRef = new Map<string, BitObject>();
|
|
293
294
|
const bitObjects = await pMapPool(
|
|
294
295
|
this.objects,
|
|
295
296
|
async (object) => {
|
|
296
297
|
try {
|
|
297
298
|
const { object: bitObject, inflatedSize } = await BitObject.parseObjectWithSize(object.buffer);
|
|
299
|
+
objectsByRef.set(object.ref.toString(), bitObject);
|
|
298
300
|
if (collectRawSources && bitObject.getType() === 'Source') {
|
|
299
301
|
if (bitObject.hash().isEqual(object.ref)) {
|
|
300
302
|
rawSources.set(bitObject, { buffer: object.buffer, inflatedSize, ref: object.ref });
|
|
@@ -313,7 +315,7 @@ export class ObjectList {
|
|
|
313
315
|
},
|
|
314
316
|
{ concurrency }
|
|
315
317
|
);
|
|
316
|
-
return { bitObjectList: new BitObjectList(compact(bitObjects)), rawSources };
|
|
318
|
+
return { bitObjectList: new BitObjectList(compact(bitObjects), objectsByRef), rawSources };
|
|
317
319
|
}
|
|
318
320
|
|
|
319
321
|
static async fromBitObjects(bitObjects: BitObject[]): Promise<ObjectList> {
|
package/objects/repository.ts
CHANGED
|
@@ -579,6 +579,13 @@ export default class Repository {
|
|
|
579
579
|
return this;
|
|
580
580
|
}
|
|
581
581
|
|
|
582
|
+
/**
|
|
583
|
+
* the object, if it's in memory: added during tag but not persisted yet, or cached. same lookup as `load()`.
|
|
584
|
+
*/
|
|
585
|
+
getFromMemory(ref: Ref): BitObject | undefined {
|
|
586
|
+
return this.objects[ref.hash.toString()] || this.getCache(ref);
|
|
587
|
+
}
|
|
588
|
+
|
|
582
589
|
/**
|
|
583
590
|
* an object evicted from the cache is still returned as long as it's in use elsewhere (see `LiveObjects`).
|
|
584
591
|
*/
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/objects",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.711",
|
|
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.711"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@pnpm/lockfile.types": "1100.0.19",
|
|
13
13
|
"semver": "7.7.1",
|
|
14
|
-
"lodash": "4.
|
|
14
|
+
"lodash": "4.18.1",
|
|
15
15
|
"uuid": "8.3.2",
|
|
16
16
|
"async-mutex": "0.3.1",
|
|
17
17
|
"p-map-series": "2.1.0",
|
|
@@ -20,34 +20,34 @@
|
|
|
20
20
|
"glob": "13.0.0",
|
|
21
21
|
"@teambit/harmony": "0.4.12",
|
|
22
22
|
"@teambit/harmony.modules.runtimes": "0.0.4",
|
|
23
|
-
"@teambit/component-id": "1.2.
|
|
24
|
-
"@teambit/legacy.utils": "0.0.
|
|
25
|
-
"@teambit/harmony.modules.get-basic-log": "0.0.179",
|
|
23
|
+
"@teambit/component-id": "1.2.5",
|
|
24
|
+
"@teambit/legacy.utils": "0.0.56",
|
|
26
25
|
"@teambit/bit-error": "0.0.404",
|
|
27
26
|
"@teambit/component-version": "1.0.4",
|
|
28
|
-
"@teambit/component.snap-distance": "0.0.179",
|
|
29
|
-
"@teambit/config-store": "0.0.290",
|
|
30
27
|
"@teambit/lane-id": "0.0.312",
|
|
31
|
-
"@teambit/legacy.cli.error": "0.0.
|
|
28
|
+
"@teambit/legacy.cli.error": "0.0.67",
|
|
32
29
|
"@teambit/legacy.constants": "0.0.49",
|
|
33
|
-
"@teambit/legacy.logger": "0.0.
|
|
34
|
-
"@teambit/legacy.scope": "0.0.178",
|
|
30
|
+
"@teambit/legacy.logger": "0.0.67",
|
|
35
31
|
"@teambit/toolbox.crypto.sha1": "0.0.24",
|
|
36
|
-
"@teambit/component.sources": "0.0.230",
|
|
37
32
|
"@teambit/harmony.modules.concurrency": "0.0.50",
|
|
38
|
-
"@teambit/legacy-bit-id": "1.1.
|
|
33
|
+
"@teambit/legacy-bit-id": "1.1.4",
|
|
39
34
|
"@teambit/legacy-component-log": "0.0.434",
|
|
40
|
-
"@teambit/legacy.consumer-component": "0.0.179",
|
|
41
|
-
"@teambit/legacy.consumer-config": "0.0.178",
|
|
42
|
-
"@teambit/legacy.extension-data": "0.0.180",
|
|
43
35
|
"@teambit/pkg.modules.semver-helper": "0.0.38",
|
|
44
|
-
"@teambit/toolbox.array.duplications-finder": "0.0.
|
|
45
|
-
"@teambit/toolbox.promise.map-pool": "0.0.
|
|
36
|
+
"@teambit/toolbox.array.duplications-finder": "0.0.19",
|
|
37
|
+
"@teambit/toolbox.promise.map-pool": "0.0.24",
|
|
46
38
|
"@teambit/graph.cleargraph": "0.0.11",
|
|
47
39
|
"@teambit/bit.get-bit-version": "0.0.31",
|
|
48
|
-
"@teambit/semantics.doc-parser": "0.0.186",
|
|
49
40
|
"@teambit/harmony.modules.in-memory-cache": "0.0.54",
|
|
50
|
-
"@teambit/toolbox.fs.remove-empty-dir": "0.0.22"
|
|
41
|
+
"@teambit/toolbox.fs.remove-empty-dir": "0.0.22",
|
|
42
|
+
"@teambit/harmony.modules.get-basic-log": "0.0.181",
|
|
43
|
+
"@teambit/component.snap-distance": "0.0.181",
|
|
44
|
+
"@teambit/config-store": "0.0.292",
|
|
45
|
+
"@teambit/legacy.scope": "0.0.180",
|
|
46
|
+
"@teambit/component.sources": "0.0.232",
|
|
47
|
+
"@teambit/legacy.consumer-component": "0.0.181",
|
|
48
|
+
"@teambit/legacy.consumer-config": "0.0.180",
|
|
49
|
+
"@teambit/legacy.extension-data": "0.0.182",
|
|
50
|
+
"@teambit/semantics.doc-parser": "0.0.188"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/semver": "7.5.8",
|
|
File without changes
|