@teambit/objects 0.0.0-dd184ac0a6078a34baedf005a0276dc5717f53a1 → 0.0.0-dd672fbe0add5e00d519ca6f3680e6aa82a54326

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/models/dependencies-graph.d.ts +1 -1
  2. package/dist/models/dependencies-graph.js.map +1 -1
  3. package/dist/models/export-metadata.js +0 -2
  4. package/dist/models/export-metadata.js.map +1 -1
  5. package/dist/models/lane-history.d.ts +1 -1
  6. package/dist/models/lane-history.js.map +1 -1
  7. package/dist/models/lane.d.ts +6 -5
  8. package/dist/models/lane.js.map +1 -1
  9. package/dist/models/model-component.d.ts +10 -8
  10. package/dist/models/model-component.js +22 -5
  11. package/dist/models/model-component.js.map +1 -1
  12. package/dist/models/scopeMeta.d.ts +1 -1
  13. package/dist/models/scopeMeta.js +0 -3
  14. package/dist/models/scopeMeta.js.map +1 -1
  15. package/dist/models/source.d.ts +2 -2
  16. package/dist/models/source.js +0 -1
  17. package/dist/models/source.js.map +1 -1
  18. package/dist/models/symlink.d.ts +1 -1
  19. package/dist/models/version-history.d.ts +1 -1
  20. package/dist/models/version-history.js.map +1 -1
  21. package/dist/models/version.d.ts +11 -9
  22. package/dist/models/version.js +1 -13
  23. package/dist/models/version.js.map +1 -1
  24. package/dist/models/version.spec.js +4 -12
  25. package/dist/models/version.spec.js.map +1 -1
  26. package/dist/objects/bit-object-list.d.ts +1 -1
  27. package/dist/objects/bit-object-list.js.map +1 -1
  28. package/dist/objects/object-list-to-graph.d.ts +2 -2
  29. package/dist/objects/object-list-to-graph.js.map +1 -1
  30. package/dist/objects/object-list.d.ts +6 -0
  31. package/dist/objects/object-list.js +47 -4
  32. package/dist/objects/object-list.js.map +1 -1
  33. package/dist/objects/object.d.ts +2 -2
  34. package/dist/objects/object.js +0 -1
  35. package/dist/objects/object.js.map +1 -1
  36. package/dist/objects/objects-readable-generator.d.ts +4 -4
  37. package/dist/objects/objects-readable-generator.js.map +1 -1
  38. package/dist/objects/raw-object.d.ts +2 -2
  39. package/dist/objects/raw-object.js +1 -11
  40. package/dist/objects/raw-object.js.map +1 -1
  41. package/dist/objects/ref.d.ts +2 -2
  42. package/dist/objects/ref.js.map +1 -1
  43. package/dist/objects/repository.d.ts +23 -7
  44. package/dist/objects/repository.js +23 -12
  45. package/dist/objects/repository.js.map +1 -1
  46. package/dist/objects/scope-index.d.ts +2 -2
  47. package/dist/objects/scope-index.js +0 -1
  48. package/dist/objects/scope-index.js.map +1 -1
  49. package/models/dependencies-graph.ts +1 -1
  50. package/models/export-metadata.ts +0 -1
  51. package/models/lane-history.ts +1 -1
  52. package/models/lane.ts +4 -3
  53. package/models/model-component.ts +36 -16
  54. package/models/scopeMeta.ts +1 -3
  55. package/models/source.ts +0 -1
  56. package/models/version-history.ts +1 -1
  57. package/models/version.spec.ts +4 -12
  58. package/models/version.ts +10 -21
  59. package/objects/bit-object-list.ts +1 -1
  60. package/objects/object-list-to-graph.ts +2 -2
  61. package/objects/object-list.ts +53 -5
  62. package/objects/object.ts +2 -3
  63. package/objects/objects-readable-generator.ts +6 -6
  64. package/objects/raw-object.ts +2 -12
  65. package/objects/ref.ts +2 -2
  66. package/objects/repository.ts +30 -18
  67. package/objects/scope-index.ts +2 -3
  68. package/package.json +38 -38
  69. package/dist/objects/repository-hooks.d.ts +0 -4
  70. package/dist/objects/repository-hooks.js +0 -56
  71. package/dist/objects/repository-hooks.js.map +0 -1
  72. package/objects/repository-hooks.ts +0 -42
  73. /package/dist/{preview-1752249630271.js → preview-1765462803517.js} +0 -0
@@ -7,7 +7,7 @@ import Ref from '../objects/ref';
7
7
  import { BitObject } from '../objects';
8
8
  import type Version from './version';
9
9
  import { getVersionParentsFromVersion } from '@teambit/component.snap-distance';
10
- import ModelComponent from './model-component';
10
+ import type ModelComponent from './model-component';
11
11
 
12
12
  export type VersionParents = {
13
13
  hash: Ref;
@@ -67,21 +67,13 @@ describe('Version', () => {
67
67
  it('dependencies should be an array', () => {
68
68
  expect(dependencies).to.be.an('array').and.have.lengthOf(1);
69
69
  });
70
- it('dependencies should have properties id and relativePaths only', () => {
70
+ it('dependencies should have id property only (relativePaths removed)', () => {
71
71
  expect(dependencies[0]).to.haveOwnProperty('id');
72
- expect(dependencies[0]).to.haveOwnProperty('relativePaths');
72
+ expect(dependencies[0]).to.not.haveOwnProperty('relativePaths');
73
73
  expect(dependencies[0]).to.not.haveOwnProperty('nonExistProperty');
74
- expect(Object.keys(dependencies[0])).to.have.lengthOf(2);
75
- });
76
- it('relativePaths should be an array', () => {
77
- expect(dependencies[0].relativePaths).to.be.an('array').and.have.lengthOf(1);
78
- });
79
- it('relativePaths should have properties sourceRelativePath and destinationRelativePath only', () => {
80
- expect(dependencies[0].relativePaths[0]).to.haveOwnProperty('sourceRelativePath');
81
- expect(dependencies[0].relativePaths[0]).to.haveOwnProperty('destinationRelativePath');
82
- expect(dependencies[0].relativePaths[0]).to.not.haveOwnProperty('nonExistProperty');
83
- expect(Object.keys(dependencies[0].relativePaths[0])).to.have.lengthOf(2);
74
+ expect(Object.keys(dependencies[0])).to.have.lengthOf(1);
84
75
  });
76
+ // relativePaths tests removed - no longer included in Version.id() hash for Harmony components
85
77
  });
86
78
  });
87
79
  describe('hash()', () => {
package/models/version.ts CHANGED
@@ -3,24 +3,27 @@ import { isSnap } from '@teambit/component-version';
3
3
  import { ComponentID, ComponentIdList } from '@teambit/component-id';
4
4
  import { LaneId } from '@teambit/lane-id';
5
5
  import { v4 } from 'uuid';
6
- import { BuildStatus, DEFAULT_BUNDLE_FILENAME, Extensions } from '@teambit/legacy.constants';
6
+ import type { BuildStatus } from '@teambit/legacy.constants';
7
+ import { DEFAULT_BUNDLE_FILENAME, Extensions } from '@teambit/legacy.constants';
8
+ import type { ConsumerComponent } from '@teambit/legacy.consumer-component';
7
9
  import {
8
10
  isSchemaSupport,
9
11
  SchemaFeature,
10
12
  SchemaName,
11
13
  Dependencies,
12
14
  Dependency,
13
- ConsumerComponent,
14
15
  } from '@teambit/legacy.consumer-component';
15
16
  import { getRefsFromExtensions, SourceFile } from '@teambit/component.sources';
16
- import { ComponentOverridesData } from '@teambit/legacy.consumer-config';
17
+ import type { ComponentOverridesData } from '@teambit/legacy.consumer-config';
17
18
  import { ExtensionDataEntry, ExtensionDataList } from '@teambit/legacy.extension-data';
18
19
  import type { Doclet } from '@teambit/semantics.doc-parser';
19
20
  import { logger } from '@teambit/legacy.logger';
20
- import { getStringifyArgs, PathLinux, pathNormalizeToLinux } from '@teambit/legacy.utils';
21
+ import type { PathLinux } from '@teambit/legacy.utils';
22
+ import { getStringifyArgs, pathNormalizeToLinux } from '@teambit/legacy.utils';
21
23
  import { sha1 } from '@teambit/toolbox.crypto.sha1';
22
- import { BitObject, Ref, Repository } from '../objects';
23
- import { ObjectItem } from '../objects/object-list';
24
+ import type { Repository } from '../objects';
25
+ import { BitObject, Ref } from '../objects';
26
+ import type { ObjectItem } from '../objects/object-list';
24
27
  import { BitIdCompIdError, VersionInvalid, validateVersionInstance } from '@teambit/legacy.scope';
25
28
  import Source from './source';
26
29
  import { DependenciesGraph } from './dependencies-graph';
@@ -67,11 +70,8 @@ export type VersionProps = {
67
70
  flattenedEdges?: DepEdge[];
68
71
  flattenedEdgesRef?: Ref;
69
72
  dependenciesGraphRef?: Ref;
70
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
71
73
  packageDependencies?: { [key: string]: string };
72
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
73
74
  devPackageDependencies?: { [key: string]: string };
74
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
75
75
  peerPackageDependencies?: { [key: string]: string };
76
76
  bindingPrefix: string;
77
77
  schema?: string;
@@ -120,7 +120,6 @@ export default class Version extends BitObject {
120
120
  * (around August 2023 should be safe)
121
121
  */
122
122
  private flattenedEdges: DepEdge[];
123
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
124
123
  packageDependencies: { [key: string]: string };
125
124
  devPackageDependencies: { [key: string]: string };
126
125
  peerPackageDependencies: { [key: string]: string };
@@ -232,19 +231,11 @@ export default class Version extends BitObject {
232
231
  id() {
233
232
  const obj = this.toObject();
234
233
 
235
- // @todo: remove the entire dependencies.relativePaths from the ID (it's going to be a breaking change)
236
234
  const getDependencies = (deps: Dependencies) => {
237
235
  const clonedDependencies = deps.cloneAsString();
238
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
239
- return clonedDependencies.map((dependency: Dependency) => {
236
+ return clonedDependencies.map((dependency) => {
240
237
  return {
241
238
  id: dependency.id,
242
- relativePaths: dependency.relativePaths.map((relativePath) => {
243
- return {
244
- sourceRelativePath: relativePath.sourceRelativePath,
245
- destinationRelativePath: relativePath.destinationRelativePath,
246
- };
247
- }),
248
239
  };
249
240
  });
250
241
  };
@@ -697,7 +688,6 @@ export default class Version extends BitObject {
697
688
  files: files.map(parseFile),
698
689
  bindingPrefix: component.bindingPrefix,
699
690
  log: component.log as Log,
700
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
701
691
  docs: component.docs,
702
692
  dependencies: component.dependencies.get(),
703
693
  devDependencies: component.devDependencies.get(),
@@ -711,7 +701,6 @@ export default class Version extends BitObject {
711
701
  flattenedEdgesRef: flattenedEdges?.hash(),
712
702
  schema: component.schema,
713
703
  overrides: component.overrides.componentOverridesData,
714
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
715
704
  packageJsonChangedProps: component.packageJsonChangedProps,
716
705
  extensions: component.extensions,
717
706
  buildStatus: component.buildStatus,
@@ -1,4 +1,4 @@
1
- import BitObject from './object';
1
+ import type BitObject from './object';
2
2
  import { ExportMetadata, Lane, LaneHistory, ModelComponent, Version, VersionHistory } from '../models';
3
3
 
4
4
  export class BitObjectList {
@@ -1,8 +1,8 @@
1
1
  import { Graph, Node, Edge } from '@teambit/graph.cleargraph';
2
2
  import { uniqBy } from 'lodash';
3
- import { ComponentID } from '@teambit/component-id';
3
+ import type { ComponentID } from '@teambit/component-id';
4
4
  import type { ObjectList } from './object-list';
5
- import { BitObjectList } from './bit-object-list';
5
+ import type { BitObjectList } from './bit-object-list';
6
6
  import { getAllVersionsInfo } from '@teambit/component.snap-distance';
7
7
  import { Dependency } from '@teambit/graph';
8
8
 
@@ -2,6 +2,7 @@ import tarStream from 'tar-stream';
2
2
  import { pMapPool } from '@teambit/toolbox.promise.map-pool';
3
3
  import { compact } from 'lodash';
4
4
  import { Readable, PassThrough, pipeline } from 'stream';
5
+ import crypto from 'crypto';
5
6
  import BitObject from './object';
6
7
  import { BitObjectList } from './bit-object-list';
7
8
  import Ref from './ref';
@@ -52,6 +53,19 @@ export class ObjectList {
52
53
  return this.objects.length;
53
54
  }
54
55
 
56
+ /**
57
+ * Generates a SHA1 hash from all object buffers.
58
+ * Used to identify duplicate export requests during retries.
59
+ * Performance wise, it's not too bad. ~98ms for 150 components on CircleCI.
60
+ */
61
+ getSha1Hash(): string {
62
+ const hash = crypto.createHash('sha1');
63
+ for (const obj of this.objects) {
64
+ hash.update(new Uint8Array(obj.buffer));
65
+ }
66
+ return hash.digest('hex');
67
+ }
68
+
55
69
  static mergeMultipleInstances(objectLists: ObjectList[]): ObjectList {
56
70
  const objectList = new ObjectList();
57
71
  objectLists.forEach((objList) => objectList.mergeObjectList(objList));
@@ -120,7 +134,10 @@ export class ObjectList {
120
134
  const extract = tarStream.extract();
121
135
  let startData: StartFile | undefined;
122
136
  let endData: EndFile | undefined;
137
+ let entriesReceived = 0;
138
+
123
139
  extract.on('entry', (header, stream, next) => {
140
+ entriesReceived += 1;
124
141
  const data: Buffer[] = [];
125
142
  stream.on('data', (chunk) => {
126
143
  data.push(chunk);
@@ -154,24 +171,40 @@ export class ObjectList {
154
171
  });
155
172
 
156
173
  // not sure if needed
157
- extract.on('error', (err) => {
158
- passThrough.emit('error', err);
174
+ extract.on('error', (err: any) => {
175
+ logger.error(`fromTarToObjectStream tar extraction error after receiving ${entriesReceived} entries`, err);
176
+
177
+ // Enhanced error message for tar corruption with entry count
178
+ if (err.message?.includes('invalid tar header') || err.message?.includes('Invalid tar header')) {
179
+ const enhancedError = new Error(
180
+ `Invalid tar header after receiving ${entriesReceived} entries. Possible causes: 1) Server aborted request mid-stream, 2) Network corruption during transfer. Original error: ${err.message}`
181
+ );
182
+ enhancedError.stack = err.stack;
183
+ passThrough.emit('error', enhancedError);
184
+ } else {
185
+ passThrough.emit('error', err);
186
+ }
159
187
  });
160
188
 
161
189
  extract.on('finish', () => {
162
190
  if (startData?.schema === OBJECT_LIST_CURRENT_SCHEMA && !endData) {
163
191
  // wasn't able to find a better way to indicate whether the server aborted the request
164
192
  // see https://github.com/node-fetch/node-fetch/issues/1117
193
+ logger.error(
194
+ `fromTarToObjectStream, server terminated the stream unexpectedly. Start: ${JSON.stringify(startData)}, entries received: ${entriesReceived}`
195
+ );
165
196
  passThrough.emit(
166
197
  'error',
167
- new Error(`server terminated the stream unexpectedly (metadata: ${JSON.stringify(startData)})`)
198
+ new Error(
199
+ `server terminated the stream unexpectedly (metadata: ${JSON.stringify(startData)}, entries received: ${entriesReceived})`
200
+ )
168
201
  );
169
202
  }
170
203
  passThrough.end();
171
204
  });
172
205
  pipeline(packStream, extract, (err) => {
173
206
  if (err) {
174
- logger.error('fromTarToObjectStream, pipeline', err);
207
+ logger.error(`fromTarToObjectStream, pipeline error after ${entriesReceived} entries`, err);
175
208
  passThrough.emit('error', err);
176
209
  } else {
177
210
  logger.debug('fromTarToObjectStream, pipeline is completed');
@@ -187,19 +220,34 @@ export class ObjectList {
187
220
  logger.debug('fromObjectStreamToTar, start sending data', startFile);
188
221
  pack.entry({ name: TAR_STREAM_START_FILENAME }, JSON.stringify(startFile));
189
222
  let numOfFiles = 0;
223
+ let isFinalized = false;
224
+
190
225
  readable.on('data', (obj: ObjectItem) => {
191
226
  numOfFiles += 1;
192
227
  pack.entry({ name: ObjectList.combineScopeAndHash(obj) }, obj.buffer);
193
228
  });
194
229
  readable.on('end', () => {
230
+ if (isFinalized) {
231
+ logger.warn(`fromObjectStreamToTar (${scopeName}), received 'end' event but pack already finalized`);
232
+ return;
233
+ }
234
+ isFinalized = true;
195
235
  const endFile: EndFile = { numOfFiles, scopeName };
196
236
  logger.debug('fromObjectStreamToTar, finished sending data', endFile);
197
237
  pack.entry({ name: TAR_STREAM_END_FILENAME }, JSON.stringify(endFile));
198
238
  pack.finalize();
199
239
  });
200
240
  readable.on('error', (err) => {
241
+ if (isFinalized) {
242
+ logger.error(
243
+ `ObjectList.fromObjectStreamToTar, received error but pack already finalized. Files sent: ${numOfFiles}`,
244
+ err
245
+ );
246
+ return;
247
+ }
248
+ isFinalized = true;
201
249
  const errorMessage = err.message || `unexpected error (${err.name})`;
202
- logger.error(`ObjectList.fromObjectStreamToTar, streaming an error as a file`, err);
250
+ logger.error(`ObjectList.fromObjectStreamToTar, streaming an error as a file after ${numOfFiles} files`, err);
203
251
  pack.entry({ name: TAR_STREAM_ERROR_FILENAME }, errorMessage);
204
252
  pack.finalize();
205
253
  });
package/objects/object.ts CHANGED
@@ -4,9 +4,9 @@ import { NULL_BYTE, SPACE_DELIMITER } from '@teambit/legacy.constants';
4
4
  import { deflate, inflate } from '@teambit/legacy.utils';
5
5
  import { sha1 } from '@teambit/toolbox.crypto.sha1';
6
6
  import { UnknownObjectType, typesObj as types } from '@teambit/legacy.scope';
7
- import { ObjectItem } from './object-list';
7
+ import type { ObjectItem } from './object-list';
8
8
  import Ref from './ref';
9
- import Repository from './repository';
9
+ import type Repository from './repository';
10
10
 
11
11
  function parse(buffer: Buffer): BitObject {
12
12
  const { type, hash, contents } = extractHeaderAndContent(buffer);
@@ -147,7 +147,6 @@ path: ${err.path}`);
147
147
  }
148
148
 
149
149
  static makeHash(str: string | Buffer): string {
150
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
151
150
  return sha1(str);
152
151
  }
153
152
  }
@@ -1,14 +1,14 @@
1
1
  import pMapSeries from 'p-map-series';
2
2
  import { BitError } from '@teambit/bit-error';
3
3
  import { Readable } from 'stream';
4
- import BitObject from './object';
5
- import Repository from './repository';
6
- import Ref from './ref';
7
- import { Scope } from '@teambit/legacy.scope';
4
+ import type BitObject from './object';
5
+ import type Repository from './repository';
6
+ import type Ref from './ref';
7
+ import type { Scope } from '@teambit/legacy.scope';
8
8
  import { logger } from '@teambit/legacy.logger';
9
9
  import { getAllVersionHashesMemoized } from '@teambit/component.snap-distance';
10
- import { Lane, LaneHistory, ModelComponent, Version } from '../models';
11
- import { ObjectItem } from './object-list';
10
+ import type { Lane, LaneHistory, ModelComponent, Version } from '../models';
11
+ import type { ObjectItem } from './object-list';
12
12
 
13
13
  export type ComponentWithCollectOptions = {
14
14
  component: ModelComponent;
@@ -1,14 +1,13 @@
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 BitObject from './object';
4
+ import type BitObject from './object';
5
5
  import { clone } from 'lodash';
6
6
 
7
7
  export default class BitRawObject {
8
8
  headers: string[];
9
9
  type: string;
10
10
  content: Buffer;
11
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
12
11
  parsedContent: any;
13
12
  _ref: string;
14
13
 
@@ -17,7 +16,6 @@ export default class BitRawObject {
17
16
  ref: string | null | undefined,
18
17
  type: string | null | undefined,
19
18
  content: Buffer | null | undefined,
20
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
21
19
  parsedContent: any | null | undefined
22
20
  ) {
23
21
  let headers;
@@ -72,17 +70,14 @@ export default class BitRawObject {
72
70
  }
73
71
  }
74
72
 
75
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
76
73
  set ref(ref: string) {
77
74
  this._ref = ref;
78
75
  }
79
76
 
80
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
81
77
  get ref(): string {
82
78
  return this._ref;
83
79
  }
84
80
 
85
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
86
81
  get id(): string {
87
82
  switch (this.type) {
88
83
  case 'Version':
@@ -114,11 +109,7 @@ export default class BitRawObject {
114
109
  return [];
115
110
  }
116
111
 
117
- static async fromDeflatedBuffer(
118
- fileContents: Buffer,
119
- ref: string | null | undefined
120
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
121
- ): Promise<BitObject> {
112
+ static async fromDeflatedBuffer(fileContents: Buffer, ref: string | null | undefined): Promise<BitObject> {
122
113
  // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
123
114
  return inflate(fileContents).then((buffer) => new BitRawObject(buffer, ref));
124
115
  }
@@ -129,7 +120,6 @@ export default class BitRawObject {
129
120
  * @param {Any} parsedContent
130
121
  */
131
122
  toRealObject() {
132
- // @ts-ignore
133
123
  return types[this.type].from(this.parsedContent || this.getParsedContent(), this.headers[1]);
134
124
  }
135
125
 
package/objects/ref.ts CHANGED
@@ -1,5 +1,5 @@
1
- import BitObject from './object';
2
- import Repository from './repository';
1
+ import type BitObject from './object';
2
+ import type Repository from './repository';
3
3
 
4
4
  export default class Ref {
5
5
  hash: string;
@@ -3,37 +3,35 @@ import uidNumber from 'uid-number';
3
3
  import { Mutex } from 'async-mutex';
4
4
  import { compact, uniqBy, differenceWith, isEqual } from 'lodash';
5
5
  import { BitError } from '@teambit/bit-error';
6
- import { ComponentID } from '@teambit/component-id';
6
+ import type { ComponentID } from '@teambit/component-id';
7
7
  import { HASH_SIZE, isSnap } from '@teambit/component-version';
8
8
  import * as path from 'path';
9
9
  import { pMapPool } from '@teambit/toolbox.promise.map-pool';
10
10
  import { OBJECTS_DIR } from '@teambit/legacy.constants';
11
11
  import { logger } from '@teambit/legacy.logger';
12
- import { glob, writeFile, ChownOptions, PathOsBasedAbsolute } from '@teambit/legacy.utils';
12
+ import type { ChownOptions, PathOsBasedAbsolute } from '@teambit/legacy.utils';
13
+ import { writeFile } from '@teambit/legacy.utils';
14
+ import { glob } from 'glob';
13
15
  import { removeEmptyDir } from '@teambit/toolbox.fs.remove-empty-dir';
14
16
  import { concurrentIOLimit } from '@teambit/harmony.modules.concurrency';
15
- import {
16
- Types,
17
- HashNotFound,
18
- OutdatedIndexJson,
19
- ScopeJson,
20
- UnmergedComponents,
21
- RemoteLanes,
22
- } from '@teambit/legacy.scope';
23
- import { ScopeIndex, IndexType, IndexItem } from './scope-index';
17
+ import type { Types, ScopeJson } from '@teambit/legacy.scope';
18
+ import { HashNotFound, OutdatedIndexJson, UnmergedComponents, RemoteLanes } from '@teambit/legacy.scope';
19
+ import type { IndexType, IndexItem } from './scope-index';
20
+ import { ScopeIndex } from './scope-index';
24
21
  import BitObject from './object';
25
- import { ObjectItem, ObjectList } from './object-list';
22
+ import type { ObjectItem } from './object-list';
23
+ import { ObjectList } from './object-list';
26
24
  import BitRawObject from './raw-object';
27
25
  import Ref from './ref';
28
- import { ContentTransformer, onPersist, onRead } from './repository-hooks';
29
- import { getMaxSizeForObjects, InMemoryCache, createInMemoryCache } from '@teambit/harmony.modules.in-memory-cache';
26
+ import type { InMemoryCache } from '@teambit/harmony.modules.in-memory-cache';
27
+ import { getMaxSizeForObjects, createInMemoryCache } from '@teambit/harmony.modules.in-memory-cache';
30
28
  import { ScopeMeta, Lane, ModelComponent } from '../models';
31
29
 
30
+ type ContentTransformer = (content: Buffer) => Buffer;
32
31
  const OBJECTS_BACKUP_DIR = `${OBJECTS_DIR}.bak`;
33
32
  const TRASH_DIR = 'trash';
34
33
 
35
34
  export default class Repository {
36
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
37
35
  objects: { [key: string]: BitObject } = {};
38
36
  objectsToRemove: Ref[] = [];
39
37
  scopeJson: ScopeJson;
@@ -44,12 +42,12 @@ export default class Repository {
44
42
  protected cache: InMemoryCache<BitObject>;
45
43
  remoteLanes!: RemoteLanes;
46
44
  unmergedComponents!: UnmergedComponents;
47
- _persistMutex?: Mutex;
45
+ _persistMutex?: Mutex;
48
46
  constructor(scopePath: string, scopeJson: ScopeJson) {
49
47
  this.scopePath = scopePath;
50
48
  this.scopeJson = scopeJson;
51
- this.onRead = onRead(scopePath, scopeJson);
52
- this.onPersist = onPersist(scopePath, scopeJson);
49
+ this.onRead = (content: Buffer) => Repository.onPostObjectRead?.(content) || content;
50
+ this.onPersist = (content: Buffer) => Repository.onPreObjectPersist?.(content) || content;
53
51
  this.cache = createInMemoryCache({ maxSize: getMaxSizeForObjects() });
54
52
  }
55
53
 
@@ -92,6 +90,20 @@ export default class Repository {
92
90
 
93
91
  static onPostObjectsPersist: () => Promise<void>;
94
92
 
93
+ /**
94
+ * Hook for transforming content before objects are persisted to the filesystem.
95
+ * Note: This function cannot be async because it's used by the synchronous `loadSync` method
96
+ * which needs to maintain sync behavior for compatibility with existing code.
97
+ */
98
+ static onPreObjectPersist: (content: Buffer) => Buffer;
99
+
100
+ /**
101
+ * Hook for transforming content after objects are read from the filesystem.
102
+ * Note: This function cannot be async because it's used by the synchronous `loadSync` method
103
+ * which needs to maintain sync behavior for compatibility with existing code.
104
+ */
105
+ static onPostObjectRead: (content: Buffer) => Buffer;
106
+
95
107
  async reLoadScopeIndex() {
96
108
  this.scopeIndex = await this.loadOptionallyCreateScopeIndex();
97
109
  }
@@ -7,8 +7,8 @@ import { logger } from '@teambit/legacy.logger';
7
7
  import { InvalidIndexJson } from '@teambit/legacy.scope';
8
8
  import { ModelComponent, Symlink } from '../models';
9
9
  import Lane from '../models/lane';
10
- import BitObject from './object';
11
- import Ref from './ref';
10
+ import type BitObject from './object';
11
+ import type Ref from './ref';
12
12
  import { difference } from 'lodash';
13
13
 
14
14
  const COMPONENTS_INDEX_FILENAME = 'index.json';
@@ -111,7 +111,6 @@ export class ScopeIndex {
111
111
  }
112
112
 
113
113
  getHashes(indexType: IndexType): string[] {
114
- // @ts-ignore how to tell TS that all this.index.prop are array?
115
114
  return this.index[indexType].map((indexItem: IndexItem) => indexItem.hash);
116
115
  }
117
116
  getHashesByQuery(indexType: IndexType, filter: Function): string[] {
package/package.json CHANGED
@@ -1,67 +1,67 @@
1
1
  {
2
2
  "name": "@teambit/objects",
3
- "version": "0.0.0-dd184ac0a6078a34baedf005a0276dc5717f53a1",
3
+ "version": "0.0.0-dd672fbe0add5e00d519ca6f3680e6aa82a54326",
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": "dd184ac0a6078a34baedf005a0276dc5717f53a1"
9
+ "version": "dd672fbe0add5e00d519ca6f3680e6aa82a54326"
10
10
  },
11
11
  "dependencies": {
12
+ "@pnpm/dependency-path": "1001.1.7",
13
+ "@pnpm/lockfile.types": "^1002.0.6",
14
+ "semver": "7.7.1",
12
15
  "lodash": "4.17.21",
13
- "tar-stream": "2.2.0",
14
- "p-map-series": "2.1.0",
15
- "is-relative-path": "2.0.0",
16
+ "uuid": "8.3.2",
16
17
  "async-mutex": "0.3.1",
18
+ "p-map-series": "2.1.0",
19
+ "tar-stream": "2.2.0",
17
20
  "fs-extra": "10.0.0",
21
+ "glob": "13.0.0",
18
22
  "uid-number": "0.0.6",
19
- "@pnpm/dependency-path": "1001.0.1",
20
- "@pnpm/lockfile.types": "^1001.0.8",
21
- "semver": "7.7.1",
22
- "uuid": "8.3.2",
23
23
  "@teambit/harmony": "0.4.7",
24
+ "@teambit/cli": "0.0.1290",
24
25
  "@teambit/component-id": "1.2.4",
25
- "@teambit/graph.cleargraph": "0.0.11",
26
+ "@teambit/legacy.utils": "0.0.30",
27
+ "@teambit/harmony.modules.get-basic-log": "0.0.91",
26
28
  "@teambit/bit-error": "0.0.404",
27
29
  "@teambit/component-version": "1.0.4",
30
+ "@teambit/component.snap-distance": "0.0.91",
31
+ "@teambit/config-store": "0.0.170",
28
32
  "@teambit/lane-id": "0.0.312",
33
+ "@teambit/legacy.cli.error": "0.0.31",
34
+ "@teambit/legacy.constants": "0.0.20",
35
+ "@teambit/legacy.logger": "0.0.31",
36
+ "@teambit/legacy.scope": "0.0.90",
37
+ "@teambit/toolbox.crypto.sha1": "0.0.11",
38
+ "@teambit/component.sources": "0.0.142",
29
39
  "@teambit/legacy-bit-id": "1.1.3",
30
- "@teambit/cli": "0.0.0-fb057adf99925d2d44186453ee00564120be99f9",
31
- "@teambit/component.snap-distance": "0.0.55",
32
- "@teambit/graph": "0.0.0-c2c6ef91e5ba9f968d781d2114aa435e8c0f9b33",
33
- "@teambit/harmony.modules.concurrency": "0.0.13",
34
- "@teambit/legacy.logger": "0.0.20",
35
- "@teambit/legacy.scope": "0.0.54",
36
- "@teambit/toolbox.promise.map-pool": "0.0.6",
37
- "@teambit/legacy.constants": "0.0.12",
38
- "@teambit/legacy.utils": "0.0.21",
39
- "@teambit/toolbox.crypto.sha1": "0.0.7",
40
- "@teambit/harmony.modules.in-memory-cache": "0.0.14",
41
- "@teambit/toolbox.fs.remove-empty-dir": "0.0.5",
42
- "@teambit/harmony.modules.get-basic-log": "0.0.55",
43
- "@teambit/config-store": "0.0.0-75a3eb7000d166a9f53df59ab8da95df6470a018",
44
- "@teambit/legacy.cli.error": "0.0.20",
45
- "@teambit/component.sources": "0.0.106",
46
- "@teambit/legacy-component-log": "0.0.407",
47
- "@teambit/legacy.consumer-component": "0.0.55",
48
- "@teambit/legacy.consumer-config": "0.0.54",
49
- "@teambit/legacy.extension-data": "0.0.56",
50
- "@teambit/pkg.modules.semver-helper": "0.0.0-af442e0c38f9c8603398dc1aa22b217eb5a7c834",
40
+ "@teambit/legacy-component-log": "0.0.413",
41
+ "@teambit/legacy.consumer-component": "0.0.91",
42
+ "@teambit/legacy.consumer-config": "0.0.90",
43
+ "@teambit/legacy.extension-data": "0.0.92",
44
+ "@teambit/pkg.modules.semver-helper": "0.0.18",
51
45
  "@teambit/toolbox.array.duplications-finder": "0.0.3",
52
- "@teambit/bit.get-bit-version": "0.0.5",
53
- "@teambit/semantics.doc-parser": "0.0.62"
46
+ "@teambit/graph.cleargraph": "0.0.11",
47
+ "@teambit/bit.get-bit-version": "0.0.11",
48
+ "@teambit/semantics.doc-parser": "0.0.98",
49
+ "@teambit/harmony.modules.concurrency": "0.0.21",
50
+ "@teambit/toolbox.promise.map-pool": "0.0.10",
51
+ "@teambit/harmony.modules.in-memory-cache": "0.0.24",
52
+ "@teambit/toolbox.fs.remove-empty-dir": "0.0.9",
53
+ "@teambit/graph": "0.0.0-d8f2d0b20be32b4205d0d2e93ec9fe9d2d704333"
54
54
  },
55
55
  "devDependencies": {
56
- "@types/lodash": "4.14.165",
57
- "@types/fs-extra": "9.0.7",
58
56
  "@types/semver": "7.5.8",
57
+ "@types/lodash": "4.14.165",
59
58
  "@types/uuid": "8.3.4",
60
- "@teambit/harmony.envs.core-aspect-env": "0.0.69"
59
+ "@types/fs-extra": "9.0.7",
60
+ "@teambit/harmony.envs.core-aspect-env": "0.0.80"
61
61
  },
62
62
  "peerDependencies": {
63
- "chai": "4.3.0",
64
- "@types/chai": "4.3.19"
63
+ "chai": "5.2.1",
64
+ "@types/chai": "5.2.2"
65
65
  },
66
66
  "license": "Apache-2.0",
67
67
  "optionalDependencies": {},
@@ -1,4 +0,0 @@
1
- import { ScopeJson } from '@teambit/legacy.scope';
2
- export type ContentTransformer = (content: Buffer) => Buffer;
3
- export declare function onPersist(scopePath: string, scopeJson: ScopeJson): ContentTransformer;
4
- export declare function onRead(scopePath: string, scopeJson: ScopeJson): ContentTransformer;
@@ -1,56 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.onPersist = onPersist;
7
- exports.onRead = onRead;
8
- function _isRelativePath() {
9
- const data = _interopRequireDefault(require("is-relative-path"));
10
- _isRelativePath = function () {
11
- return data;
12
- };
13
- return data;
14
- }
15
- function _path() {
16
- const data = _interopRequireDefault(require("path"));
17
- _path = function () {
18
- return data;
19
- };
20
- return data;
21
- }
22
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
23
- function loadHooks(scopePath, scopeJson) {
24
- const hooksPath = scopeJson.hooksPath;
25
- if (hooksPath) {
26
- const hooksFinalPath = (0, _isRelativePath().default)(hooksPath) ? _path().default.join(scopePath, hooksPath) : hooksPath;
27
- // eslint-disable-next-line global-require, import/no-dynamic-require
28
- const hooks = require(hooksFinalPath);
29
- return hooks;
30
- }
31
- return undefined;
32
- }
33
- function onPersist(scopePath, scopeJson) {
34
- const defaultFunc = content => content;
35
- const hooks = loadHooks(scopePath, scopeJson);
36
- if (hooks) {
37
- const onReadFunction = hooks.onPersist;
38
- if (onReadFunction) {
39
- return onReadFunction;
40
- }
41
- }
42
- return defaultFunc;
43
- }
44
- function onRead(scopePath, scopeJson) {
45
- const defaultFunc = content => content;
46
- const hooks = loadHooks(scopePath, scopeJson);
47
- if (hooks) {
48
- const onReadFunction = hooks.onRead;
49
- if (onReadFunction) {
50
- return onReadFunction;
51
- }
52
- }
53
- return defaultFunc;
54
- }
55
-
56
- //# sourceMappingURL=repository-hooks.js.map