@teambit/objects 0.0.726 → 0.0.728

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.
@@ -4,7 +4,7 @@ import type Ref from '../objects/ref';
4
4
 
5
5
  type ScopeMetaProps = {
6
6
  name: string;
7
- license: string;
7
+ license?: string | null;
8
8
  };
9
9
 
10
10
  // TODO: fix parse
@@ -39,13 +39,11 @@ export default class ScopeMeta extends BitObject {
39
39
  }
40
40
 
41
41
  static fromScopeName(name: string): Ref {
42
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
43
42
  return ScopeMeta.fromObject({ name }).hash();
44
43
  }
45
44
 
46
45
  static parse(propsStr: string | Buffer): ScopeMeta {
47
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
48
- return this.fromObject(JSON.parse(propsStr));
46
+ return this.fromObject(JSON.parse(propsStr.toString()));
49
47
  }
50
48
 
51
49
  static fromObject(props: ScopeMetaProps): ScopeMeta {
@@ -119,6 +119,27 @@ describe('Version', () => {
119
119
  expect(first.getLoadedFlattenedDependencies()).to.not.equal(second.getLoadedFlattenedDependencies());
120
120
  expect(first.getLoadedFlattenedDependencies()[0]).to.equal(second.getLoadedFlattenedDependencies()[0]);
121
121
  });
122
+ it('should share the same id and edge instances for flattenedEdges', () => {
123
+ const edgeFromObj1 = Version.depEdgeFromObject({
124
+ source: { scope: 'my-scope', name: 'comp-a', version: '0.0.1' },
125
+ target: { scope: 'my-scope', name: 'is-type', version: '0.0.1' },
126
+ type: 'prod',
127
+ });
128
+ const edgeFromObj2 = Version.depEdgeFromObject({
129
+ source: { scope: 'my-scope', name: 'comp-a', version: '0.0.1' },
130
+ target: { scope: 'my-scope', name: 'is-type', version: '0.0.1' },
131
+ type: 'prod',
132
+ });
133
+ expect(edgeFromObj1).to.equal(edgeFromObj2);
134
+ expect(edgeFromObj1.source).to.equal(edgeFromObj2.source);
135
+ expect(edgeFromObj1.target).to.equal(edgeFromObj2.target);
136
+
137
+ const edgeFromArr1 = Version.depEdgeFromArray(['my-scope/comp-a@0.0.1', 'my-scope/is-type@0.0.1', 'prod']);
138
+ const edgeFromArr2 = Version.depEdgeFromArray(['my-scope/comp-a@0.0.1', 'my-scope/is-type@0.0.1', 'prod']);
139
+ expect(edgeFromArr1).to.equal(edgeFromArr2);
140
+ expect(edgeFromArr1.source).to.equal(edgeFromArr2.source);
141
+ expect(edgeFromArr1.target).to.equal(edgeFromArr2.target);
142
+ });
122
143
  it('should keep a list that was set, and serialize it', () => {
123
144
  const version = getVersionWithDepsFixture();
124
145
  version.flattenedDependencies = new ComponentIdList(ComponentID.fromString('my-scope/is-type@0.0.3'));
package/models/version.ts CHANGED
@@ -4,7 +4,7 @@ import { ComponentID, ComponentIdList } from '@teambit/component-id';
4
4
  import { LaneId } from '@teambit/lane-id';
5
5
  import { v4 } from 'uuid';
6
6
  import type { BuildStatus } from '@teambit/legacy.constants';
7
- import { DEFAULT_BUNDLE_FILENAME, Extensions } from '@teambit/legacy.constants';
7
+ import { Extensions } from '@teambit/legacy.constants';
8
8
  import type { ConsumerComponent } from '@teambit/legacy.consumer-component';
9
9
  import {
10
10
  isSchemaSupport,
@@ -37,12 +37,17 @@ const flattenedIdsCache = new Map<string, Map<string, Map<string, ComponentID>>>
37
37
  const flattenedIdStrsCache = new Map<string, ComponentID>();
38
38
  const MAX_CACHED_FLATTENED_IDS = 100_000;
39
39
  let cachedFlattenedIds = 0;
40
+ let flattenedEdgesCache = new WeakMap<ComponentID, Map<ComponentID, Map<DepEdgeType, DepEdge>>>();
41
+ const MAX_CACHED_FLATTENED_EDGES = 100_000;
42
+ let cachedFlattenedEdges = 0;
40
43
 
41
44
  function countCachedFlattenedId() {
42
45
  if (cachedFlattenedIds >= MAX_CACHED_FLATTENED_IDS) {
43
46
  flattenedIdsCache.clear();
44
47
  flattenedIdStrsCache.clear();
45
48
  cachedFlattenedIds = 0;
49
+ flattenedEdgesCache = new WeakMap();
50
+ cachedFlattenedEdges = 0;
46
51
  }
47
52
  cachedFlattenedIds += 1;
48
53
  }
@@ -77,6 +82,30 @@ function getFlattenedId(dep: string | Record<string, any>): ComponentID {
77
82
  return id;
78
83
  }
79
84
 
85
+ function getFlattenedEdge(source: ComponentID, target: ComponentID, type: DepEdgeType): DepEdge {
86
+ if (cachedFlattenedEdges >= MAX_CACHED_FLATTENED_EDGES) {
87
+ flattenedEdgesCache = new WeakMap();
88
+ cachedFlattenedEdges = 0;
89
+ }
90
+ let byTarget = flattenedEdgesCache.get(source);
91
+ if (!byTarget) {
92
+ byTarget = new Map();
93
+ flattenedEdgesCache.set(source, byTarget);
94
+ }
95
+ let byType = byTarget.get(target);
96
+ if (!byType) {
97
+ byType = new Map();
98
+ byTarget.set(target, byType);
99
+ }
100
+ let edge = byType.get(type);
101
+ if (!edge) {
102
+ cachedFlattenedEdges += 1;
103
+ edge = { source, target, type };
104
+ byType.set(type, edge);
105
+ }
106
+ return edge;
107
+ }
108
+
80
109
  // the deprecated `Version.flattenedDependencies` getter warns only once per process.
81
110
  let warnedFlattenedDependenciesGetter = false;
82
111
 
@@ -542,11 +571,7 @@ export default class Version extends BitObject {
542
571
  };
543
572
  }
544
573
  static depEdgeFromObject(depEdgeObj: Record<string, any>): DepEdge {
545
- return {
546
- source: ComponentID.fromObject(depEdgeObj.source),
547
- target: ComponentID.fromObject(depEdgeObj.target),
548
- type: depEdgeObj.type,
549
- };
574
+ return getFlattenedEdge(getFlattenedId(depEdgeObj.source), getFlattenedId(depEdgeObj.target), depEdgeObj.type);
550
575
  }
551
576
  /**
552
577
  * until 1.9.86, we used depEdgeToObject.
@@ -558,11 +583,7 @@ export default class Version extends BitObject {
558
583
  }
559
584
  static depEdgeFromArray(depEdgeArr: string[]): DepEdge {
560
585
  const [sourceStr, targetStr, type] = depEdgeArr;
561
- return {
562
- source: ComponentID.fromString(sourceStr),
563
- target: ComponentID.fromString(targetStr),
564
- type: type as DepEdgeType,
565
- };
586
+ return getFlattenedEdge(getFlattenedId(sourceStr), getFlattenedId(targetStr), type as DepEdgeType);
566
587
  }
567
588
  static flattenedEdgeToSource(flattenedEdges?: DepEdge[]): Source | undefined {
568
589
  if (!flattenedEdges) return undefined;
@@ -842,7 +863,7 @@ export default class Version extends BitObject {
842
863
  dependenciesGraphRef: dependenciesGraph?.hash(),
843
864
  flattenedDependencies: component.flattenedDependencies,
844
865
  // not saved in the Version when `flattenedEdgesRef` is set, see `toObject()`.
845
- flattenedEdges: component.flattenedEdges,
866
+ flattenedEdges: flattenedEdges ? [] : component.flattenedEdges,
846
867
  flattenedEdgesRef: flattenedEdges?.hash(),
847
868
  schema: component.schema,
848
869
  overrides: component.overrides.componentOverridesData,
@@ -882,16 +903,6 @@ export default class Version extends BitObject {
882
903
  : undefined;
883
904
  }
884
905
 
885
- setDist(dist: Source | undefined) {
886
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
887
- this.dist = dist
888
- ? {
889
- file: dist.hash(),
890
- name: DEFAULT_BUNDLE_FILENAME,
891
- }
892
- : null;
893
- }
894
-
895
906
  hasParent(ref: Ref) {
896
907
  return this.parents.find((p) => p.toString() === ref.toString());
897
908
  }
package/objects/object.ts CHANGED
@@ -46,7 +46,7 @@ export default class BitObject {
46
46
  }
47
47
 
48
48
  async collectRefs(repo: Repository): Promise<Ref[]> {
49
- const refsCollection = [];
49
+ const refsCollection: Ref[] = [];
50
50
  const objectType = this.getType();
51
51
  const objectId = objectType === 'Component' ? `Component ${this.id()}` : objectType;
52
52
 
@@ -63,7 +63,6 @@ path: ${err.path}`);
63
63
  throw err;
64
64
  }
65
65
 
66
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
67
66
  refsCollection.push(...refs);
68
67
  await Promise.all(objs.map((obj) => addRefs(obj)));
69
68
  }
@@ -1,7 +1,6 @@
1
1
  import { NULL_BYTE, SPACE_DELIMITER } from '@teambit/legacy.constants';
2
2
  import { getStringifyArgs, inflate } from '@teambit/legacy.utils';
3
3
  import { typesObj as types } from '@teambit/legacy.scope';
4
- import type BitObject from './object';
5
4
  import { clone } from 'lodash';
6
5
 
7
6
  export default class BitRawObject {
@@ -12,11 +11,11 @@ export default class BitRawObject {
12
11
  _ref: string;
13
12
 
14
13
  constructor(
15
- buffer: Buffer,
16
- ref: string | null | undefined,
17
- type: string | null | undefined,
18
- content: Buffer | null | undefined,
19
- parsedContent: any | null | undefined
14
+ buffer?: Buffer,
15
+ ref?: string | null,
16
+ type?: string | null,
17
+ content?: Buffer | null,
18
+ parsedContent?: any | null
20
19
  ) {
21
20
  let headers;
22
21
  let contentFromBuffer;
@@ -28,10 +27,8 @@ export default class BitRawObject {
28
27
  this.content = content || contentFromBuffer;
29
28
  this.headers = headers ? headers.split(SPACE_DELIMITER) : undefined;
30
29
  const typeFromHeader = this.headers ? this.headers[0] : undefined;
31
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
32
- this.type = type || typeFromHeader;
33
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
34
- this._ref = ref;
30
+ this.type = (type || typeFromHeader)!;
31
+ this._ref = ref!;
35
32
  this.parsedContent = parsedContent || this.getParsedContent();
36
33
  }
37
34
 
@@ -109,8 +106,7 @@ export default class BitRawObject {
109
106
  return [];
110
107
  }
111
108
 
112
- static async fromDeflatedBuffer(fileContents: Buffer, ref: string | null | undefined): Promise<BitObject> {
113
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
109
+ static async fromDeflatedBuffer(fileContents: Buffer, ref: string | null | undefined): Promise<BitRawObject> {
114
110
  return inflate(fileContents).then((buffer) => new BitRawObject(buffer, ref));
115
111
  }
116
112
 
@@ -126,7 +122,6 @@ export default class BitRawObject {
126
122
  clone() {
127
123
  const parsedContent = this.parsedContent ? clone(this.parsedContent) : undefined;
128
124
  // TODO: Should also clone the buffers (content)
129
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
130
125
  return new BitRawObject(undefined, this._ref, this.type, this.content, parsedContent);
131
126
  }
132
127
  }
@@ -31,7 +31,7 @@ import Ref from './ref';
31
31
  import { LiveObjects } from './live-objects';
32
32
  import type { InMemoryCache } from '@teambit/harmony.modules.in-memory-cache';
33
33
  import { getCacheOptionsForObjects, createInMemoryCache } from '@teambit/harmony.modules.in-memory-cache';
34
- import { ScopeMeta, Lane, ModelComponent } from '../models';
34
+ import { ScopeMeta, Lane, ModelComponent, type Source } from '../models';
35
35
 
36
36
  type ContentTransformer = (content: Buffer) => Buffer;
37
37
  const OBJECTS_BACKUP_DIR = `${OBJECTS_DIR}.bak`;
@@ -180,8 +180,7 @@ export default class Repository {
180
180
  return path.join(this.scopePath, TRASH_DIR);
181
181
  }
182
182
 
183
- getLicense(): Promise<string> {
184
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
183
+ getLicense(): Promise<string | null | undefined> {
185
184
  return this.scopeJson.getPopulatedLicense();
186
185
  }
187
186
 
@@ -564,7 +563,7 @@ export default class Repository {
564
563
  if (throws) {
565
564
  throw new HashNotFound(ref.toString());
566
565
  }
567
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
566
+ // @ts-expect-error @todo: it should return BitObject | null (same as `load()`)
568
567
  return null;
569
568
  }
570
569
  }
@@ -629,7 +628,8 @@ export default class Repository {
629
628
  // leave the following commented log message, it is very useful for debugging but too verbose when not needed.
630
629
  // logger.debug(`repository: adding object ${object.hash().toString()} which consist of the following id: ${object.id()}`);
631
630
  this.objects[object.hash().toString()] = object;
632
- this.setCache(object);
631
+ const size = (object as Source).contents?.byteLength;
632
+ this.setCache(object, size);
633
633
  return this;
634
634
  }
635
635
 
@@ -845,13 +845,12 @@ export default class Repository {
845
845
  await this.writeObjectFile(objectPath, transformedContent, options);
846
846
  // once written, the object is the up-to-date one. this also replaces the size-estimate of objects that
847
847
  // were cached by `add()`.
848
- if (this.cache.has(hash.toString())) this.cache.set(hash.toString(), object, inflatedSize);
849
- this.liveObjects.set(
850
- hash.toString(),
851
- object,
852
- inflatedSize,
853
- transformedContent.byteLength < MAX_COMPRESSED_SIZE_TO_CACHE
854
- );
848
+ const cacheable = transformedContent.byteLength < MAX_COMPRESSED_SIZE_TO_CACHE;
849
+ if (this.cache.has(hash.toString())) {
850
+ if (cacheable) this.cache.set(hash.toString(), object, inflatedSize);
851
+ else this.cache.delete(hash.toString());
852
+ }
853
+ this.liveObjects.set(hash.toString(), object, inflatedSize, cacheable);
855
854
  }
856
855
 
857
856
  async writeObjectsToPendingDir(objectList: ObjectList, pendingDir: PathOsBasedAbsolute) {
@@ -11,7 +11,6 @@ describe('ComponentsIndex', () => {
11
11
  scopeIndex = new ScopeIndex('scope-path');
12
12
  });
13
13
  it('should add to the index array', () => {
14
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
15
14
  const modelComponent = new ModelComponent({ scope: 'my-scope', name: 'is-string' });
16
15
  scopeIndex.addOne(modelComponent);
17
16
  const allItems = scopeIndex.getAll();
@@ -19,7 +18,6 @@ describe('ComponentsIndex', () => {
19
18
  expect(allItems[0].id).to.deep.equal({ scope: 'my-scope', name: 'is-string' });
20
19
  });
21
20
  it('should not add the same component multiple times', () => {
22
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
23
21
  const modelComponent = new ModelComponent({ scope: 'my-scope', name: 'is-string' });
24
22
  scopeIndex.addOne(modelComponent);
25
23
  scopeIndex.addOne(modelComponent);
@@ -27,8 +25,7 @@ describe('ComponentsIndex', () => {
27
25
  expect(scopeIndex.getAll()).to.have.lengthOf(1);
28
26
  });
29
27
  it('should not add BitObjects that are not Symlink nor ModelComponent', () => {
30
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
31
- const bitObject = new BitObject({ scope: 'my-scope', name: 'is-string' });
28
+ const bitObject = new BitObject();
32
29
  const result = scopeIndex.addOne(bitObject);
33
30
  expect(scopeIndex.getAll()).to.have.lengthOf(0);
34
31
  expect(result).to.be.false;
@@ -40,7 +37,6 @@ describe('ComponentsIndex', () => {
40
37
  scopeIndex = new ScopeIndex('scope-path');
41
38
  });
42
39
  it('should remove from the index array', () => {
43
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
44
40
  const modelComponent = new ModelComponent({ scope: 'my-scope', name: 'is-string' });
45
41
  scopeIndex.addOne(modelComponent);
46
42
  expect(scopeIndex.getAll()).to.have.lengthOf(1);
@@ -48,9 +44,7 @@ describe('ComponentsIndex', () => {
48
44
  expect(scopeIndex.getAll()).to.have.lengthOf(0);
49
45
  });
50
46
  it('should remove the correct one when there are multiple', () => {
51
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
52
47
  const isStringComponent = new ModelComponent({ scope: 'my-scope', name: 'is-string' });
53
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
54
48
  const isTypeComponent = new ModelComponent({ scope: 'my-scope', name: 'is-type' });
55
49
  scopeIndex.addOne(isStringComponent);
56
50
  scopeIndex.addOne(isTypeComponent);
@@ -68,9 +62,7 @@ describe('ComponentsIndex', () => {
68
62
  let isTypeComponent;
69
63
  beforeEach(() => {
70
64
  scopeIndex = new ScopeIndex('scope-path');
71
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
72
65
  isStringComponent = new ModelComponent({ scope: 'my-scope', name: 'is-string' });
73
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
74
66
  isTypeComponent = new ModelComponent({ scope: 'my-scope', name: 'is-type' });
75
67
  scopeIndex.addMany([isStringComponent, isTypeComponent]);
76
68
  expect(scopeIndex.getAll()).to.have.lengthOf(2);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/objects",
3
- "version": "0.0.726",
3
+ "version": "0.0.728",
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.726"
9
+ "version": "0.0.728"
10
10
  },
11
11
  "dependencies": {
12
12
  "@pnpm/lockfile.types": "1100.0.19",
@@ -26,28 +26,28 @@
26
26
  "@teambit/component-version": "1.0.4",
27
27
  "@teambit/component.snap-distance": "0.0.191",
28
28
  "@teambit/lane-id": "0.0.312",
29
+ "@teambit/legacy.cli.error": "0.0.71",
29
30
  "@teambit/legacy.constants": "0.0.50",
31
+ "@teambit/legacy.logger": "0.0.70",
30
32
  "@teambit/toolbox.crypto.sha1": "0.0.24",
33
+ "@teambit/component.sources": "0.0.243",
31
34
  "@teambit/harmony.modules.concurrency": "0.0.51",
32
35
  "@teambit/legacy-bit-id": "1.1.4",
33
36
  "@teambit/legacy-component-log": "0.0.434",
37
+ "@teambit/legacy.consumer-component": "0.0.192",
38
+ "@teambit/legacy.consumer-config": "0.0.191",
39
+ "@teambit/legacy.extension-data": "0.0.193",
34
40
  "@teambit/pkg.modules.semver-helper": "0.0.38",
35
41
  "@teambit/toolbox.array.duplications-finder": "0.0.19",
36
42
  "@teambit/toolbox.promise.map-pool": "0.0.24",
37
43
  "@teambit/graph.cleargraph": "0.0.11",
38
44
  "@teambit/bit.get-bit-version": "0.0.31",
45
+ "@teambit/semantics.doc-parser": "0.0.199",
39
46
  "@teambit/harmony.modules.in-memory-cache": "0.0.55",
40
47
  "@teambit/toolbox.fs.remove-empty-dir": "0.0.22",
41
- "@teambit/harmony.modules.get-basic-log": "0.0.193",
42
- "@teambit/config-store": "0.0.304",
43
- "@teambit/legacy.cli.error": "0.0.71",
44
- "@teambit/legacy.logger": "0.0.70",
45
- "@teambit/legacy.scope": "0.0.192",
46
- "@teambit/component.sources": "0.0.243",
47
- "@teambit/legacy.consumer-component": "0.0.192",
48
- "@teambit/legacy.consumer-config": "0.0.191",
49
- "@teambit/legacy.extension-data": "0.0.193",
50
- "@teambit/semantics.doc-parser": "0.0.199"
48
+ "@teambit/harmony.modules.get-basic-log": "0.0.194",
49
+ "@teambit/config-store": "0.0.305",
50
+ "@teambit/legacy.scope": "0.0.193"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/semver": "7.5.8",