@teambit/objects 0.0.683 → 0.0.685
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 -0
- package/dist/index.js.map +1 -1
- package/dist/objects/index.d.ts +1 -0
- package/dist/objects/index.js.map +1 -1
- package/dist/objects/object.d.ts +19 -0
- package/dist/objects/object.js +43 -0
- package/dist/objects/object.js.map +1 -1
- package/dist/objects/repository.d.ts +50 -2
- package/dist/objects/repository.js +122 -4
- package/dist/objects/repository.js.map +1 -1
- package/dist/objects/repository.spec.d.ts +1 -0
- package/dist/objects/repository.spec.js +159 -0
- package/dist/objects/repository.spec.js.map +1 -0
- package/objects/index.ts +1 -0
- package/objects/object.ts +40 -1
- package/objects/repository.spec.ts +92 -0
- package/objects/repository.ts +119 -7
- package/package.json +14 -14
- /package/dist/{preview-1790183760587.js → preview-1790261426827.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { ModelComponent, ScopeMeta, Source, Version, Symlink, Lane, ExportMetadata, VersionHistory, LaneHistory, } from './models';
|
|
2
2
|
export { BitObject, BitRawObject, Ref, Repository } from './objects';
|
|
3
|
+
export type { ObjectWithType, ObjectsWithType } from './objects';
|
|
3
4
|
export { ComponentLog, ScopeListItem, AddVersionOpts, ComponentProps, VERSION_ZERO } from './models/model-component';
|
|
4
5
|
export { ComponentItem, IndexType, LaneItem } from './objects/scope-index';
|
|
5
6
|
export { ObjectItem, ObjectList, ObjectItemsStream } from './objects/object-list';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_models","data","require","_objects","_modelComponent","_scopeIndex","_objectList","_bitObjectList","_lane","_dependenciesGraph","_version","_objectsReadableGenerator","_versionHistory","_laneHistory","_objectListToGraph","_objects2","_default","exports","default","ObjectsAspect"],"sources":["index.ts"],"sourcesContent":["export {\n ModelComponent,\n ScopeMeta,\n Source,\n Version,\n Symlink,\n Lane,\n ExportMetadata,\n VersionHistory,\n LaneHistory,\n} from './models';\nexport { BitObject, BitRawObject, Ref, Repository } from './objects';\nexport { ComponentLog, ScopeListItem, AddVersionOpts, ComponentProps, VERSION_ZERO } from './models/model-component';\nexport { ComponentItem, IndexType, LaneItem } from './objects/scope-index';\nexport { ObjectItem, ObjectList, ObjectItemsStream } from './objects/object-list';\nexport { BitObjectList } from './objects/bit-object-list';\nexport { LaneComponent, Log as LaneLog, LaneReadmeComponent } from './models/lane';\nexport {\n DependenciesGraph,\n type PackagesMap,\n type PackageAttributes,\n type DependencyEdge,\n type DependencyNeighbour,\n} from './models/dependencies-graph';\nexport { DepEdge, DepEdgeType, SourceFileModel, Log } from './models/version';\nexport { ComponentWithCollectOptions, ObjectsReadableGenerator } from './objects/objects-readable-generator';\nexport { ScopeIndex } from './objects/scope-index';\nexport { VersionHistoryGraph } from './models/version-history';\nexport { VersionParents, versionParentsToGraph } from './models/version-history';\nexport { HistoryItem } from './models/lane-history';\nexport { IdGraph, objectListToGraph, bitObjectListToGraph } from './objects/object-list-to-graph';\n\nimport { ObjectsAspect } from './objects.aspect';\n\nexport type { ObjectsMain } from './objects.main.runtime';\nexport default ObjectsAspect;\nexport { ObjectsAspect };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAWA,SAAAE,SAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,QAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;
|
|
1
|
+
{"version":3,"names":["_models","data","require","_objects","_modelComponent","_scopeIndex","_objectList","_bitObjectList","_lane","_dependenciesGraph","_version","_objectsReadableGenerator","_versionHistory","_laneHistory","_objectListToGraph","_objects2","_default","exports","default","ObjectsAspect"],"sources":["index.ts"],"sourcesContent":["export {\n ModelComponent,\n ScopeMeta,\n Source,\n Version,\n Symlink,\n Lane,\n ExportMetadata,\n VersionHistory,\n LaneHistory,\n} from './models';\nexport { BitObject, BitRawObject, Ref, Repository } from './objects';\nexport type { ObjectWithType, ObjectsWithType } from './objects';\nexport { ComponentLog, ScopeListItem, AddVersionOpts, ComponentProps, VERSION_ZERO } from './models/model-component';\nexport { ComponentItem, IndexType, LaneItem } from './objects/scope-index';\nexport { ObjectItem, ObjectList, ObjectItemsStream } from './objects/object-list';\nexport { BitObjectList } from './objects/bit-object-list';\nexport { LaneComponent, Log as LaneLog, LaneReadmeComponent } from './models/lane';\nexport {\n DependenciesGraph,\n type PackagesMap,\n type PackageAttributes,\n type DependencyEdge,\n type DependencyNeighbour,\n} from './models/dependencies-graph';\nexport { DepEdge, DepEdgeType, SourceFileModel, Log } from './models/version';\nexport { ComponentWithCollectOptions, ObjectsReadableGenerator } from './objects/objects-readable-generator';\nexport { ScopeIndex } from './objects/scope-index';\nexport { VersionHistoryGraph } from './models/version-history';\nexport { VersionParents, versionParentsToGraph } from './models/version-history';\nexport { HistoryItem } from './models/lane-history';\nexport { IdGraph, objectListToGraph, bitObjectListToGraph } from './objects/object-list-to-graph';\n\nimport { ObjectsAspect } from './objects.aspect';\n\nexport type { ObjectsMain } from './objects.main.runtime';\nexport default ObjectsAspect;\nexport { ObjectsAspect };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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kBAAA,YAAAA,CAAA;IAAA,OAAAR,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAOA,SAAAS,SAAA;EAAA,MAAAT,IAAA,GAAAC,OAAA;EAAAQ,QAAA,YAAAA,CAAA;IAAA,OAAAT,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAU,0BAAA;EAAA,MAAAV,IAAA,GAAAC,OAAA;EAAAS,yBAAA,YAAAA,CAAA;IAAA,OAAAV,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAW,gBAAA;EAAA,MAAAX,IAAA,GAAAC,OAAA;EAAAU,eAAA,YAAAA,CAAA;IAAA,OAAAX,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAY,aAAA;EAAA,MAAAZ,IAAA,GAAAC,OAAA;EAAAW,YAAA,YAAAA,CAAA;IAAA,OAAAZ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAa,mBAAA;EAAA,MAAAb,IAAA,GAAAC,OAAA;EAAAY,kBAAA,YAAAA,CAAA;IAAA,OAAAb,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAc,UAAA;EAAA,MAAAd,IAAA,GAAAC,OAAA;EAAAa,SAAA,YAAAA,CAAA;IAAA,OAAAd,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAiD,IAAAe,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGlCC,yBAAa","ignoreList":[]}
|
package/dist/objects/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_object","data","_interopRequireDefault","require","_rawObject","_ref","_repository","e","__esModule","default"],"sources":["index.ts"],"sourcesContent":["import BitObject from './object';\nimport BitRawObject from './raw-object';\nimport Ref from './ref';\nimport Repository from './repository';\n\nexport { BitObject, BitRawObject, Ref, Repository };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,WAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,UAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,KAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,IAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,YAAA;EAAA,MAAAL,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAG,WAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAsC,SAAAC,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_object","data","_interopRequireDefault","require","_rawObject","_ref","_repository","e","__esModule","default"],"sources":["index.ts"],"sourcesContent":["import BitObject from './object';\nimport BitRawObject from './raw-object';\nimport Ref from './ref';\nimport Repository from './repository';\n\nexport { BitObject, BitRawObject, Ref, Repository };\nexport type { ObjectWithType, ObjectsWithType } from './repository';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,WAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,UAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,KAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,IAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,YAAA;EAAA,MAAAL,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAG,WAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAsC,SAAAC,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
|
package/dist/objects/object.d.ts
CHANGED
|
@@ -27,6 +27,25 @@ export default class BitObject {
|
|
|
27
27
|
* the performance improvement is huge compare to "parseObject", as it doesn't parse the object if not needed.
|
|
28
28
|
*/
|
|
29
29
|
static parseObjectOnlyIfType(fileContents: Buffer, typeNames: string[], filePath?: string): Promise<BitObject | null>;
|
|
30
|
+
/**
|
|
31
|
+
* extract only the object type out of the first chunk of a compressed object file.
|
|
32
|
+
*
|
|
33
|
+
* the type is the first token of the header, which sits at the very beginning of the inflated
|
|
34
|
+
* buffer, so there's no need to inflate the entire object. `Z_SYNC_FLUSH` tells zlib to return
|
|
35
|
+
* whatever it managed to inflate instead of throwing on the truncated input.
|
|
36
|
+
* returns null when the header is not fully contained in the given chunk, in which case the
|
|
37
|
+
* caller should fall back to inflating the whole file. a header that is there but names a type
|
|
38
|
+
* nothing is registered under throws instead: reading it as a type of its own would let a
|
|
39
|
+
* damaged object pass for classified, and the caller acts on the inventory being complete.
|
|
40
|
+
*
|
|
41
|
+
* the chunk is a `Uint8Array` rather than a `Buffer` because newer `@types/node` make `Buffer`
|
|
42
|
+
* generic, which no longer matches zlib's `InputType` under the typescript version our envs ship.
|
|
43
|
+
*/
|
|
44
|
+
static parseObjectTypeFromChunk(chunk: Uint8Array): string | null;
|
|
45
|
+
/**
|
|
46
|
+
* same as `parseObjectTypeFromChunk`, only it gets the entire (inflated) object.
|
|
47
|
+
*/
|
|
48
|
+
static parseObjectType(fileContents: Buffer, filePath?: string): Promise<string>;
|
|
30
49
|
/**
|
|
31
50
|
* prefer using `this.parseObject()`, unless it must be sync.
|
|
32
51
|
*/
|
package/dist/objects/object.js
CHANGED
|
@@ -172,6 +172,49 @@ path: ${err.path}`);
|
|
|
172
172
|
return null;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
/**
|
|
176
|
+
* extract only the object type out of the first chunk of a compressed object file.
|
|
177
|
+
*
|
|
178
|
+
* the type is the first token of the header, which sits at the very beginning of the inflated
|
|
179
|
+
* buffer, so there's no need to inflate the entire object. `Z_SYNC_FLUSH` tells zlib to return
|
|
180
|
+
* whatever it managed to inflate instead of throwing on the truncated input.
|
|
181
|
+
* returns null when the header is not fully contained in the given chunk, in which case the
|
|
182
|
+
* caller should fall back to inflating the whole file. a header that is there but names a type
|
|
183
|
+
* nothing is registered under throws instead: reading it as a type of its own would let a
|
|
184
|
+
* damaged object pass for classified, and the caller acts on the inventory being complete.
|
|
185
|
+
*
|
|
186
|
+
* the chunk is a `Uint8Array` rather than a `Buffer` because newer `@types/node` make `Buffer`
|
|
187
|
+
* generic, which no longer matches zlib's `InputType` under the typescript version our envs ship.
|
|
188
|
+
*/
|
|
189
|
+
static parseObjectTypeFromChunk(chunk) {
|
|
190
|
+
let buffer;
|
|
191
|
+
try {
|
|
192
|
+
buffer = (0, _zlib().inflateSync)(chunk, {
|
|
193
|
+
finishFlush: _zlib().constants.Z_SYNC_FLUSH
|
|
194
|
+
});
|
|
195
|
+
} catch {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
const firstNullByteLocation = buffer.indexOf(_legacy().NULL_BYTE);
|
|
199
|
+
if (firstNullByteLocation === -1) return null;
|
|
200
|
+
const [type] = buffer.slice(0, firstNullByteLocation).toString().split(_legacy().SPACE_DELIMITER);
|
|
201
|
+
if (!type) return null;
|
|
202
|
+
if (!_legacy3().typesObj[type]) throw new (_legacy3().UnknownObjectType)(type);
|
|
203
|
+
return type;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* same as `parseObjectTypeFromChunk`, only it gets the entire (inflated) object.
|
|
208
|
+
*/
|
|
209
|
+
static async parseObjectType(fileContents, filePath) {
|
|
210
|
+
const buffer = await (0, _legacy2().inflate)(fileContents, filePath);
|
|
211
|
+
const {
|
|
212
|
+
type
|
|
213
|
+
} = extractHeaderAndContent(buffer);
|
|
214
|
+
if (!_legacy3().typesObj[type]) throw new (_legacy3().UnknownObjectType)(type);
|
|
215
|
+
return type;
|
|
216
|
+
}
|
|
217
|
+
|
|
175
218
|
/**
|
|
176
219
|
* prefer using `this.parseObject()`, unless it must be sync.
|
|
177
220
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_zlib","data","require","_legacy","_legacy2","_toolboxCrypto","_legacy3","_ref","_interopRequireDefault","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","parse","buffer","type","hash","contents","extractHeaderAndContent","types","UnknownObjectType","firstNullByteLocation","indexOf","NULL_BYTE","headers","slice","toString","split","SPACE_DELIMITER","length","BitObject","constructor","id","Error","toBuffer","pretty","refs","getType","name","getHeader","collectRefs","repo","refsCollection","objectType","objectId","addRefs","object","objs","Promise","all","map","ref","load","err","code","path","push","obj","collectRaw","loadManyRaw","asRaw","loadRaw","collect","objects","loadSync","forEach","Ref","makeHash","compress","deflate","serialize","Buffer","concat","from","parseObject","fileContents","filePath","inflate","parseObjectOnlyIfType","typeNames","includes","parseSync","inflateSync","str","sha1","exports"],"sources":["object.ts"],"sourcesContent":["import { inflateSync } from 'zlib';\n\nimport { NULL_BYTE, SPACE_DELIMITER } from '@teambit/legacy.constants';\nimport { deflate, inflate } from '@teambit/legacy.utils';\nimport { sha1 } from '@teambit/toolbox.crypto.sha1';\nimport { UnknownObjectType, typesObj as types } from '@teambit/legacy.scope';\nimport type { ObjectItem } from './object-list';\nimport Ref from './ref';\nimport type Repository from './repository';\n\nfunction parse(buffer: Buffer): BitObject {\n const { type, hash, contents } = extractHeaderAndContent(buffer);\n if (!types[type]) throw new UnknownObjectType(type);\n return types[type].parse(contents, hash);\n}\n\nfunction extractHeaderAndContent(buffer: Buffer): { type: string; hash: string; contents: Buffer } {\n const firstNullByteLocation = buffer.indexOf(NULL_BYTE);\n const headers = buffer.slice(0, firstNullByteLocation).toString();\n const [type, hash] = headers.split(SPACE_DELIMITER);\n const contents = buffer.slice(firstNullByteLocation + 1, buffer.length);\n return { type, hash, contents };\n}\n\nexport default class BitObject {\n validateBeforePersist = true; // validate the object before persisting\n id(): string | Buffer {\n throw new Error('id() was not implemented...');\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n toBuffer(pretty?: boolean): Buffer {\n throw new Error('toBuffer() was not implemented...');\n }\n\n refs(): Ref[] {\n return [];\n }\n\n getType(): string {\n return this.constructor.name;\n }\n\n getHeader(buffer: Buffer): string {\n return `${this.getType()} ${this.hash().toString()} ${buffer.toString().length}${NULL_BYTE}`;\n }\n\n async collectRefs(repo: Repository): Promise<Ref[]> {\n const refsCollection = [];\n const objectType = this.getType();\n const objectId = objectType === 'Component' ? `Component ${this.id()}` : objectType;\n\n async function addRefs(object: BitObject) {\n const refs = object.refs();\n let objs;\n try {\n objs = await Promise.all(refs.map((ref) => ref.load(repo, true)));\n } catch (err: any) {\n if (err.code === 'ENOENT') {\n throw new Error(`failed finding an object file required by ${object.constructor.name} object, originated from ${objectId}\npath: ${err.path}`);\n }\n throw err;\n }\n\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n refsCollection.push(...refs);\n await Promise.all(objs.map((obj) => addRefs(obj)));\n }\n\n await addRefs(this);\n return refsCollection;\n }\n\n async collectRaw(repo: Repository): Promise<ObjectItem[]> {\n const refs = await this.collectRefs(repo);\n return repo.loadManyRaw(refs);\n }\n\n asRaw(repo: Repository): Promise<Buffer> {\n return repo.loadRaw(this.hash());\n }\n\n collect(repo: Repository): BitObject[] {\n const objects: BitObject[] = [];\n\n function addRefs(object: BitObject) {\n const objs = object.refs().map((ref) => {\n return ref.loadSync(repo);\n });\n\n objects.push(...objs);\n objs.forEach((obj) => addRefs(obj));\n }\n\n addRefs(this);\n return objects;\n }\n\n /**\n * indexing method\n */\n hash(): Ref {\n // console.log(`sha ${sha1(this.id())}, id ${this.id()}`); // uncomment when debugging hash issues\n return new Ref(BitObject.makeHash(this.id()));\n }\n\n compress(): Promise<Buffer> {\n return deflate(this.serialize());\n }\n\n serialize(): Buffer {\n const buffer = this.toBuffer();\n return Buffer.concat([Buffer.from(this.getHeader(buffer)), buffer] as unknown as Uint8Array[]);\n }\n\n /**\n * see `this.parseSync` for the sync version\n */\n static async parseObject(fileContents: Buffer, filePath?: string): Promise<BitObject> {\n const buffer = await inflate(fileContents, filePath);\n return parse(buffer);\n }\n\n /**\n * same as `parseObject`, however, if the type is not one of the given \"typeNames\", it returns null.\n * the performance improvement is huge compare to \"parseObject\", as it doesn't parse the object if not needed.\n */\n static async parseObjectOnlyIfType(\n fileContents: Buffer,\n typeNames: string[],\n filePath?: string\n ): Promise<BitObject | null> {\n const buffer = await inflate(fileContents, filePath);\n const { type } = extractHeaderAndContent(buffer);\n if (typeNames.includes(type)) return parse(buffer);\n return null;\n }\n\n /**\n * prefer using `this.parseObject()`, unless it must be sync.\n */\n static parseSync(fileContents: Buffer): BitObject {\n // @ts-ignore todo: fix after merging #9359\n const buffer = inflateSync(fileContents);\n return parse(buffer);\n }\n\n static makeHash(str: string | Buffer): string {\n return sha1(str);\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,QAAA;EAAA,M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;IAC9B,OAAOqC,MAAM,CAACC,MAAM,CAAC,CAACD,MAAM,CAACE,IAAI,CAAC,IAAI,CAAClC,SAAS,CAACzB,MAAM,CAAC,CAAC,EAAEA,MAAM,CAA4B,CAAC;EAChG;;EAEA;AACF;AACA;EACE,aAAa4D,WAAWA,CAACC,YAAoB,EAAEC,QAAiB,EAAsB;IACpF,MAAM9D,MAAM,GAAG,MAAM,IAAA+D,kBAAO,EAACF,YAAY,EAAEC,QAAQ,CAAC;IACpD,OAAO/D,KAAK,CAACC,MAAM,CAAC;EACtB;;EAEA;AACF;AACA;AACA;EACE,aAAagE,qBAAqBA,CAChCH,YAAoB,EACpBI,SAAmB,EACnBH,QAAiB,EACU;IAC3B,MAAM9D,MAAM,GAAG,MAAM,IAAA+D,kBAAO,EAACF,YAAY,EAAEC,QAAQ,CAAC;IACpD,MAAM;MAAE7D;IAAK,CAAC,GAAGG,uBAAuB,CAACJ,MAAM,CAAC;IAChD,IAAIiE,SAAS,CAACC,QAAQ,CAACjE,IAAI,CAAC,EAAE,OAAOF,KAAK,CAACC,MAAM,CAAC;IAClD,OAAO,IAAI;EACb;;EAEA;AACF;AACA;EACE,OAAOmE,SAASA,CAACN,YAAoB,EAAa;IAChD;IACA,MAAM7D,MAAM,GAAG,IAAAoE,mBAAW,EAACP,YAAY,CAAC;IACxC,OAAO9D,KAAK,CAACC,MAAM,CAAC;EACtB;EAEA,OAAOqD,QAAQA,CAACgB,GAAoB,EAAU;IAC5C,OAAO,IAAAC,qBAAI,EAACD,GAAG,CAAC;EAClB;AACF;AAACE,OAAA,CAAA3F,OAAA,GAAAoC,SAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_zlib","data","require","_legacy","_legacy2","_toolboxCrypto","_legacy3","_ref","_interopRequireDefault","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","parse","buffer","type","hash","contents","extractHeaderAndContent","types","UnknownObjectType","firstNullByteLocation","indexOf","NULL_BYTE","headers","slice","toString","split","SPACE_DELIMITER","length","BitObject","constructor","id","Error","toBuffer","pretty","refs","getType","name","getHeader","collectRefs","repo","refsCollection","objectType","objectId","addRefs","object","objs","Promise","all","map","ref","load","err","code","path","push","obj","collectRaw","loadManyRaw","asRaw","loadRaw","collect","objects","loadSync","forEach","Ref","makeHash","compress","deflate","serialize","Buffer","concat","from","parseObject","fileContents","filePath","inflate","parseObjectOnlyIfType","typeNames","includes","parseObjectTypeFromChunk","chunk","inflateSync","finishFlush","constants","Z_SYNC_FLUSH","parseObjectType","parseSync","str","sha1","exports"],"sources":["object.ts"],"sourcesContent":["import { constants, inflateSync } from 'zlib';\n\nimport { NULL_BYTE, SPACE_DELIMITER } from '@teambit/legacy.constants';\nimport { deflate, inflate } from '@teambit/legacy.utils';\nimport { sha1 } from '@teambit/toolbox.crypto.sha1';\nimport { UnknownObjectType, typesObj as types } from '@teambit/legacy.scope';\nimport type { ObjectItem } from './object-list';\nimport Ref from './ref';\nimport type Repository from './repository';\n\nfunction parse(buffer: Buffer): BitObject {\n const { type, hash, contents } = extractHeaderAndContent(buffer);\n if (!types[type]) throw new UnknownObjectType(type);\n return types[type].parse(contents, hash);\n}\n\nfunction extractHeaderAndContent(buffer: Buffer): { type: string; hash: string; contents: Buffer } {\n const firstNullByteLocation = buffer.indexOf(NULL_BYTE);\n const headers = buffer.slice(0, firstNullByteLocation).toString();\n const [type, hash] = headers.split(SPACE_DELIMITER);\n const contents = buffer.slice(firstNullByteLocation + 1, buffer.length);\n return { type, hash, contents };\n}\n\nexport default class BitObject {\n validateBeforePersist = true; // validate the object before persisting\n id(): string | Buffer {\n throw new Error('id() was not implemented...');\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n toBuffer(pretty?: boolean): Buffer {\n throw new Error('toBuffer() was not implemented...');\n }\n\n refs(): Ref[] {\n return [];\n }\n\n getType(): string {\n return this.constructor.name;\n }\n\n getHeader(buffer: Buffer): string {\n return `${this.getType()} ${this.hash().toString()} ${buffer.toString().length}${NULL_BYTE}`;\n }\n\n async collectRefs(repo: Repository): Promise<Ref[]> {\n const refsCollection = [];\n const objectType = this.getType();\n const objectId = objectType === 'Component' ? `Component ${this.id()}` : objectType;\n\n async function addRefs(object: BitObject) {\n const refs = object.refs();\n let objs;\n try {\n objs = await Promise.all(refs.map((ref) => ref.load(repo, true)));\n } catch (err: any) {\n if (err.code === 'ENOENT') {\n throw new Error(`failed finding an object file required by ${object.constructor.name} object, originated from ${objectId}\npath: ${err.path}`);\n }\n throw err;\n }\n\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n refsCollection.push(...refs);\n await Promise.all(objs.map((obj) => addRefs(obj)));\n }\n\n await addRefs(this);\n return refsCollection;\n }\n\n async collectRaw(repo: Repository): Promise<ObjectItem[]> {\n const refs = await this.collectRefs(repo);\n return repo.loadManyRaw(refs);\n }\n\n asRaw(repo: Repository): Promise<Buffer> {\n return repo.loadRaw(this.hash());\n }\n\n collect(repo: Repository): BitObject[] {\n const objects: BitObject[] = [];\n\n function addRefs(object: BitObject) {\n const objs = object.refs().map((ref) => {\n return ref.loadSync(repo);\n });\n\n objects.push(...objs);\n objs.forEach((obj) => addRefs(obj));\n }\n\n addRefs(this);\n return objects;\n }\n\n /**\n * indexing method\n */\n hash(): Ref {\n // console.log(`sha ${sha1(this.id())}, id ${this.id()}`); // uncomment when debugging hash issues\n return new Ref(BitObject.makeHash(this.id()));\n }\n\n compress(): Promise<Buffer> {\n return deflate(this.serialize());\n }\n\n serialize(): Buffer {\n const buffer = this.toBuffer();\n return Buffer.concat([Buffer.from(this.getHeader(buffer)), buffer] as unknown as Uint8Array[]);\n }\n\n /**\n * see `this.parseSync` for the sync version\n */\n static async parseObject(fileContents: Buffer, filePath?: string): Promise<BitObject> {\n const buffer = await inflate(fileContents, filePath);\n return parse(buffer);\n }\n\n /**\n * same as `parseObject`, however, if the type is not one of the given \"typeNames\", it returns null.\n * the performance improvement is huge compare to \"parseObject\", as it doesn't parse the object if not needed.\n */\n static async parseObjectOnlyIfType(\n fileContents: Buffer,\n typeNames: string[],\n filePath?: string\n ): Promise<BitObject | null> {\n const buffer = await inflate(fileContents, filePath);\n const { type } = extractHeaderAndContent(buffer);\n if (typeNames.includes(type)) return parse(buffer);\n return null;\n }\n\n /**\n * extract only the object type out of the first chunk of a compressed object file.\n *\n * the type is the first token of the header, which sits at the very beginning of the inflated\n * buffer, so there's no need to inflate the entire object. `Z_SYNC_FLUSH` tells zlib to return\n * whatever it managed to inflate instead of throwing on the truncated input.\n * returns null when the header is not fully contained in the given chunk, in which case the\n * caller should fall back to inflating the whole file. a header that is there but names a type\n * nothing is registered under throws instead: reading it as a type of its own would let a\n * damaged object pass for classified, and the caller acts on the inventory being complete.\n *\n * the chunk is a `Uint8Array` rather than a `Buffer` because newer `@types/node` make `Buffer`\n * generic, which no longer matches zlib's `InputType` under the typescript version our envs ship.\n */\n static parseObjectTypeFromChunk(chunk: Uint8Array): string | null {\n let buffer: Buffer;\n try {\n buffer = inflateSync(chunk, { finishFlush: constants.Z_SYNC_FLUSH });\n } catch {\n return null;\n }\n const firstNullByteLocation = buffer.indexOf(NULL_BYTE);\n if (firstNullByteLocation === -1) return null;\n const [type] = buffer.slice(0, firstNullByteLocation).toString().split(SPACE_DELIMITER);\n if (!type) return null;\n if (!types[type]) throw new UnknownObjectType(type);\n return type;\n }\n\n /**\n * same as `parseObjectTypeFromChunk`, only it gets the entire (inflated) object.\n */\n static async parseObjectType(fileContents: Buffer, filePath?: string): Promise<string> {\n const buffer = await inflate(fileContents, filePath);\n const { type } = extractHeaderAndContent(buffer);\n if (!types[type]) throw new UnknownObjectType(type);\n return type;\n }\n\n /**\n * prefer using `this.parseObject()`, unless it must be sync.\n */\n static parseSync(fileContents: Buffer): BitObject {\n // @ts-ignore todo: fix after merging #9359\n const buffer = inflateSync(fileContents);\n return parse(buffer);\n }\n\n static makeHash(str: string | Buffer): string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O,CAACC,mBAAS,CAAC;IACvD,IAAIF,qBAAqB,KAAK,CAAC,CAAC,EAAE,OAAO,IAAI;IAC7C,MAAM,CAACN,IAAI,CAAC,GAAGD,MAAM,CAACW,KAAK,CAAC,CAAC,EAAEJ,qBAAqB,CAAC,CAACK,QAAQ,CAAC,CAAC,CAACC,KAAK,CAACC,yBAAe,CAAC;IACvF,IAAI,CAACb,IAAI,EAAE,OAAO,IAAI;IACtB,IAAI,CAACI,mBAAK,CAACJ,IAAI,CAAC,EAAE,MAAM,KAAIK,4BAAiB,EAACL,IAAI,CAAC;IACnD,OAAOA,IAAI;EACb;;EAEA;AACF;AACA;EACE,aAAawE,eAAeA,CAACZ,YAAoB,EAAEC,QAAiB,EAAmB;IACrF,MAAM9D,MAAM,GAAG,MAAM,IAAA+D,kBAAO,EAACF,YAAY,EAAEC,QAAQ,CAAC;IACpD,MAAM;MAAE7D;IAAK,CAAC,GAAGG,uBAAuB,CAACJ,MAAM,CAAC;IAChD,IAAI,CAACK,mBAAK,CAACJ,IAAI,CAAC,EAAE,MAAM,KAAIK,4BAAiB,EAACL,IAAI,CAAC;IACnD,OAAOA,IAAI;EACb;;EAEA;AACF;AACA;EACE,OAAOyE,SAASA,CAACb,YAAoB,EAAa;IAChD;IACA,MAAM7D,MAAM,GAAG,IAAAqE,mBAAW,EAACR,YAAY,CAAC;IACxC,OAAO9D,KAAK,CAACC,MAAM,CAAC;EACtB;EAEA,OAAOqD,QAAQA,CAACsB,GAAoB,EAAU;IAC5C,OAAO,IAAAC,qBAAI,EAACD,GAAG,CAAC;EAClB;AACF;AAACE,OAAA,CAAAjG,OAAA,GAAAoC,SAAA","ignoreList":[]}
|
|
@@ -12,6 +12,18 @@ import BitRawObject from './raw-object';
|
|
|
12
12
|
import Ref from './ref';
|
|
13
13
|
import type { InMemoryCache } from '@teambit/harmony.modules.in-memory-cache';
|
|
14
14
|
type ContentTransformer = (content: Buffer) => Buffer;
|
|
15
|
+
/** `mtimeMs` lets a caller tell an object that has been here a while from one just written */
|
|
16
|
+
export type ObjectWithType = {
|
|
17
|
+
ref: Ref;
|
|
18
|
+
type: string;
|
|
19
|
+
size: number;
|
|
20
|
+
mtimeMs: number;
|
|
21
|
+
};
|
|
22
|
+
/** `unreadable` holds the objects that couldn't be classified, so a caller can refuse to act on a partial inventory */
|
|
23
|
+
export type ObjectsWithType = {
|
|
24
|
+
objects: ObjectWithType[];
|
|
25
|
+
unreadable: Ref[];
|
|
26
|
+
};
|
|
15
27
|
export default class Repository {
|
|
16
28
|
objects: {
|
|
17
29
|
[key: string]: BitObject;
|
|
@@ -45,13 +57,21 @@ export default class Repository {
|
|
|
45
57
|
* Note: This function cannot be async because it's used by the synchronous `loadSync` method
|
|
46
58
|
* which needs to maintain sync behavior for compatibility with existing code.
|
|
47
59
|
*/
|
|
48
|
-
static onPreObjectPersist
|
|
60
|
+
static onPreObjectPersist?: (content: Buffer) => Buffer;
|
|
49
61
|
/**
|
|
50
62
|
* Hook for transforming content after objects are read from the filesystem.
|
|
51
63
|
* Note: This function cannot be async because it's used by the synchronous `loadSync` method
|
|
52
64
|
* which needs to maintain sync behavior for compatibility with existing code.
|
|
53
65
|
*/
|
|
54
|
-
static onPostObjectRead
|
|
66
|
+
static onPostObjectRead?: (content: Buffer) => Buffer;
|
|
67
|
+
/**
|
|
68
|
+
* whether `onPostObjectRead` actually transforms anything.
|
|
69
|
+
*
|
|
70
|
+
* the scope aspect installs the hook above unconditionally - it's a reduce over a slot that is
|
|
71
|
+
* usually empty - so the hook being set says nothing about whether object content is transformed.
|
|
72
|
+
* only a caller that can skip reading content altogether needs to tell the two apart.
|
|
73
|
+
*/
|
|
74
|
+
static hasPostObjectReadTransformer?: () => boolean;
|
|
55
75
|
reLoadScopeIndex(): Promise<void>;
|
|
56
76
|
/**
|
|
57
77
|
* current scope index difference with <scope_folder>/index.json content, reload it
|
|
@@ -73,6 +93,34 @@ export default class Repository {
|
|
|
73
93
|
* example usage: `this.list([ModelComponent, Symlink, Lane])`
|
|
74
94
|
*/
|
|
75
95
|
list(types: Types): Promise<BitObject[]>;
|
|
96
|
+
/**
|
|
97
|
+
* classify every object in the scope by its type, along with its size on the filesystem.
|
|
98
|
+
*
|
|
99
|
+
* needed by the garbage collector, which must know the type of each object but has no use for
|
|
100
|
+
* its content. inflating every object would mean inflating gigabytes of file-content (`Source`)
|
|
101
|
+
* objects, so only the first chunk of each file is read - enough to hold the header, which is
|
|
102
|
+
* where the type is. when a content transformer is registered (`onPostObjectRead`), it applies
|
|
103
|
+
* to the whole buffer, so in that case the file is read in full.
|
|
104
|
+
*/
|
|
105
|
+
listObjectsWithType(): Promise<ObjectsWithType>;
|
|
106
|
+
/**
|
|
107
|
+
* the objects that couldn't be classified are reported rather than skipped. a caller that acts on
|
|
108
|
+
* this inventory (the garbage collector) has to know that it's incomplete, because an object it
|
|
109
|
+
* can't see is one it can't reason about.
|
|
110
|
+
*/
|
|
111
|
+
private getObjectTypeGracefully;
|
|
112
|
+
private readObjectType;
|
|
113
|
+
/**
|
|
114
|
+
* whether object files have to go through `onPostObjectRead` before their header can be read.
|
|
115
|
+
* when there's no way to tell, assume they do. it's the slow answer, never the wrong one.
|
|
116
|
+
*/
|
|
117
|
+
private isContentTransformed;
|
|
118
|
+
/**
|
|
119
|
+
* the type an object file names in its header, read from the first chunk of the file only.
|
|
120
|
+
* null when that chunk doesn't hold the whole header, in which case the file has to be read in
|
|
121
|
+
* full. throws `UnknownObjectType` when the header names a type nothing is registered under.
|
|
122
|
+
*/
|
|
123
|
+
private readTypeFromHeader;
|
|
76
124
|
loadRefDeleteIfInvalid(ref: Ref): Promise<BitObject | undefined>;
|
|
77
125
|
loadRefOnlyIfType(ref: Ref, types: Types): Promise<BitObject | null>;
|
|
78
126
|
listRefs(cwd?: string): Promise<Array<Ref>>;
|
|
@@ -158,6 +158,18 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
158
158
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
159
159
|
const OBJECTS_BACKUP_DIR = `${_legacy().OBJECTS_DIR}.bak`;
|
|
160
160
|
const TRASH_DIR = 'trash';
|
|
161
|
+
/**
|
|
162
|
+
* how much of an object file to read when all that's needed is its header. the header holds the
|
|
163
|
+
* type and is a few dozen bytes, which 512 compressed bytes always cover - and every byte past it
|
|
164
|
+
* is inflated for nothing (4KB inflates ten times as much, across every object in the scope). a
|
|
165
|
+
* chunk that falls short anyway is read in full.
|
|
166
|
+
*/
|
|
167
|
+
const OBJECT_HEADER_CHUNK_SIZE = 512;
|
|
168
|
+
|
|
169
|
+
/** `mtimeMs` lets a caller tell an object that has been here a while from one just written */
|
|
170
|
+
|
|
171
|
+
/** `unreadable` holds the objects that couldn't be classified, so a caller can refuse to act on a partial inventory */
|
|
172
|
+
|
|
161
173
|
class Repository {
|
|
162
174
|
constructor(scopePath, scopeJson) {
|
|
163
175
|
_defineProperty(this, "objects", {});
|
|
@@ -356,6 +368,92 @@ class Repository {
|
|
|
356
368
|
});
|
|
357
369
|
return objects;
|
|
358
370
|
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* classify every object in the scope by its type, along with its size on the filesystem.
|
|
374
|
+
*
|
|
375
|
+
* needed by the garbage collector, which must know the type of each object but has no use for
|
|
376
|
+
* its content. inflating every object would mean inflating gigabytes of file-content (`Source`)
|
|
377
|
+
* objects, so only the first chunk of each file is read - enough to hold the header, which is
|
|
378
|
+
* where the type is. when a content transformer is registered (`onPostObjectRead`), it applies
|
|
379
|
+
* to the whole buffer, so in that case the file is read in full.
|
|
380
|
+
*/
|
|
381
|
+
async listObjectsWithType() {
|
|
382
|
+
const refs = await this.listRefs();
|
|
383
|
+
const concurrency = (0, _harmonyModules().concurrentIOLimit)();
|
|
384
|
+
_legacy2().logger.debug(`Repository.listObjectsWithType, classifying ${refs.length} objects`);
|
|
385
|
+
const results = await (0, _toolboxPromise().pMapPool)(refs, ref => this.getObjectTypeGracefully(ref), {
|
|
386
|
+
concurrency
|
|
387
|
+
});
|
|
388
|
+
const objects = (0, _lodash().compact)(results.map(result => result.object));
|
|
389
|
+
const unreadable = (0, _lodash().compact)(results.map(result => result.unreadable));
|
|
390
|
+
if (unreadable.length) {
|
|
391
|
+
_legacy2().logger.warn(`Repository.listObjectsWithType, unable to classify ${unreadable.length} objects`);
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
objects,
|
|
395
|
+
unreadable
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* the objects that couldn't be classified are reported rather than skipped. a caller that acts on
|
|
401
|
+
* this inventory (the garbage collector) has to know that it's incomplete, because an object it
|
|
402
|
+
* can't see is one it can't reason about.
|
|
403
|
+
*/
|
|
404
|
+
async getObjectTypeGracefully(ref) {
|
|
405
|
+
const objectPath = this.objectPath(ref);
|
|
406
|
+
try {
|
|
407
|
+
const stat = await _fsExtra().default.stat(objectPath);
|
|
408
|
+
const type = await this.readObjectType(objectPath);
|
|
409
|
+
return {
|
|
410
|
+
object: {
|
|
411
|
+
ref,
|
|
412
|
+
type,
|
|
413
|
+
size: stat.size,
|
|
414
|
+
mtimeMs: stat.mtimeMs
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
} catch (err) {
|
|
418
|
+
_legacy2().logger.warn(`Repository.listObjectsWithType, failed reading ${objectPath}. Error: ${err.message}`);
|
|
419
|
+
return {
|
|
420
|
+
unreadable: ref
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
async readObjectType(objectPath) {
|
|
425
|
+
const readInFull = async () => _object().default.parseObjectType(this.onRead(await _fsExtra().default.readFile(objectPath)), objectPath);
|
|
426
|
+
if (this.isContentTransformed()) return readInFull();
|
|
427
|
+
return (await this.readTypeFromHeader(objectPath)) || readInFull();
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* whether object files have to go through `onPostObjectRead` before their header can be read.
|
|
432
|
+
* when there's no way to tell, assume they do. it's the slow answer, never the wrong one.
|
|
433
|
+
*/
|
|
434
|
+
isContentTransformed() {
|
|
435
|
+
return Repository.hasPostObjectReadTransformer ? Repository.hasPostObjectReadTransformer() : Boolean(Repository.onPostObjectRead);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* the type an object file names in its header, read from the first chunk of the file only.
|
|
440
|
+
* null when that chunk doesn't hold the whole header, in which case the file has to be read in
|
|
441
|
+
* full. throws `UnknownObjectType` when the header names a type nothing is registered under.
|
|
442
|
+
*/
|
|
443
|
+
async readTypeFromHeader(objectPath) {
|
|
444
|
+
// `Uint8Array` rather than `Buffer` - see `parseObjectTypeFromChunk`
|
|
445
|
+
const chunk = new Uint8Array(OBJECT_HEADER_CHUNK_SIZE);
|
|
446
|
+
const fileDescriptor = await _fsExtra().default.open(objectPath, 'r');
|
|
447
|
+
let bytesRead;
|
|
448
|
+
try {
|
|
449
|
+
({
|
|
450
|
+
bytesRead
|
|
451
|
+
} = await _fsExtra().default.read(fileDescriptor, chunk, 0, chunk.length, 0));
|
|
452
|
+
} finally {
|
|
453
|
+
await _fsExtra().default.close(fileDescriptor);
|
|
454
|
+
}
|
|
455
|
+
return _object().default.parseObjectTypeFromChunk(chunk.subarray(0, bytesRead));
|
|
456
|
+
}
|
|
359
457
|
async loadRefDeleteIfInvalid(ref) {
|
|
360
458
|
try {
|
|
361
459
|
return await this.load(ref, true);
|
|
@@ -372,11 +470,23 @@ class Repository {
|
|
|
372
470
|
}
|
|
373
471
|
async loadRefOnlyIfType(ref, types) {
|
|
374
472
|
const objectPath = this.objectPath(ref);
|
|
375
|
-
const fileContentsRaw = await _fsExtra().default.readFile(objectPath);
|
|
376
|
-
const fileContents = this.onRead(fileContentsRaw);
|
|
377
473
|
const typeNames = types.map(type => type.name);
|
|
378
|
-
|
|
379
|
-
|
|
474
|
+
// most of a scope is file contents, which callers of this never ask for. the header says
|
|
475
|
+
// whether an object is wanted, so the rest of the file is only read and inflated when it is.
|
|
476
|
+
// transformed content has no header to read on its own, so it keeps to the single full read.
|
|
477
|
+
if (!this.isContentTransformed()) {
|
|
478
|
+
let type;
|
|
479
|
+
try {
|
|
480
|
+
type = await this.readTypeFromHeader(objectPath);
|
|
481
|
+
} catch (err) {
|
|
482
|
+
// an unregistered type is not one of the types asked for - the same answer the full read gives
|
|
483
|
+
if (err instanceof _legacy4().UnknownObjectType) return null;
|
|
484
|
+
throw err;
|
|
485
|
+
}
|
|
486
|
+
if (type && !typeNames.includes(type)) return null;
|
|
487
|
+
}
|
|
488
|
+
const fileContents = this.onRead(await _fsExtra().default.readFile(objectPath));
|
|
489
|
+
return _object().default.parseObjectOnlyIfType(fileContents, typeNames, objectPath);
|
|
380
490
|
}
|
|
381
491
|
async listRefs(cwd = this.getPath()) {
|
|
382
492
|
const matches = await (0, _glob().glob)(path().join('*', '*'), {
|
|
@@ -820,6 +930,14 @@ _defineProperty(Repository, "onPreObjectPersist", void 0);
|
|
|
820
930
|
* which needs to maintain sync behavior for compatibility with existing code.
|
|
821
931
|
*/
|
|
822
932
|
_defineProperty(Repository, "onPostObjectRead", void 0);
|
|
933
|
+
/**
|
|
934
|
+
* whether `onPostObjectRead` actually transforms anything.
|
|
935
|
+
*
|
|
936
|
+
* the scope aspect installs the hook above unconditionally - it's a reduce over a slot that is
|
|
937
|
+
* usually empty - so the hook being set says nothing about whether object content is transformed.
|
|
938
|
+
* only a caller that can skip reading content altogether needs to tell the two apart.
|
|
939
|
+
*/
|
|
940
|
+
_defineProperty(Repository, "hasPostObjectReadTransformer", void 0);
|
|
823
941
|
async function removeFile(filePath, propagateDirs = false) {
|
|
824
942
|
try {
|
|
825
943
|
await _fsExtra().default.unlink(filePath);
|