@teambit/objects 0.0.19
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/artifacts/__bit_junit.xml +68 -0
- package/artifacts/preview/teambit_scope_objects-preview.js +1 -0
- package/dist/fixtures/version-model-extended.json +48 -0
- package/dist/fixtures/version-model-object.json +87 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +371 -0
- package/dist/index.js.map +1 -0
- package/dist/models/dependencies-graph.d.ts +45 -0
- package/dist/models/dependencies-graph.js +106 -0
- package/dist/models/dependencies-graph.js.map +1 -0
- package/dist/models/detach-heads.d.ts +25 -0
- package/dist/models/detach-heads.js +84 -0
- package/dist/models/detach-heads.js.map +1 -0
- package/dist/models/export-metadata.d.ts +24 -0
- package/dist/models/export-metadata.js +76 -0
- package/dist/models/export-metadata.js.map +1 -0
- package/dist/models/index.d.ts +10 -0
- package/dist/models/index.js +125 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/lane-history.d.ts +40 -0
- package/dist/models/lane-history.js +117 -0
- package/dist/models/lane-history.js.map +1 -0
- package/dist/models/lane.d.ts +124 -0
- package/dist/models/lane.js +463 -0
- package/dist/models/lane.js.map +1 -0
- package/dist/models/model-component.d.ts +317 -0
- package/dist/models/model-component.js +1365 -0
- package/dist/models/model-component.js.map +1 -0
- package/dist/models/model-component.spec.d.ts +1 -0
- package/dist/models/model-component.spec.js +71 -0
- package/dist/models/model-component.spec.js.map +1 -0
- package/dist/models/scopeMeta.d.ts +20 -0
- package/dist/models/scopeMeta.js +71 -0
- package/dist/models/scopeMeta.js.map +1 -0
- package/dist/models/source.d.ts +10 -0
- package/dist/models/source.js +43 -0
- package/dist/models/source.js.map +1 -0
- package/dist/models/symlink.d.ts +30 -0
- package/dist/models/symlink.js +91 -0
- package/dist/models/symlink.js.map +1 -0
- package/dist/models/version-history.d.ts +59 -0
- package/dist/models/version-history.js +285 -0
- package/dist/models/version-history.js.map +1 -0
- package/dist/models/version.d.ts +279 -0
- package/dist/models/version.js +777 -0
- package/dist/models/version.js.map +1 -0
- package/dist/models/version.spec.d.ts +1 -0
- package/dist/models/version.spec.js +340 -0
- package/dist/models/version.spec.js.map +1 -0
- package/dist/objects/bit-object-list.d.ts +24 -0
- package/dist/objects/bit-object-list.js +65 -0
- package/dist/objects/bit-object-list.js.map +1 -0
- package/dist/objects/index.d.ts +5 -0
- package/dist/objects/index.js +60 -0
- package/dist/objects/index.js.map +1 -0
- package/dist/objects/object-list-to-graph.d.ts +13 -0
- package/dist/objects/object-list-to-graph.js +93 -0
- package/dist/objects/object-list-to-graph.js.map +1 -0
- package/dist/objects/object-list.d.ts +52 -0
- package/dist/objects/object-list.js +369 -0
- package/dist/objects/object-list.js.map +1 -0
- package/dist/objects/object.d.ts +35 -0
- package/dist/objects/object.js +190 -0
- package/dist/objects/object.js.map +1 -0
- package/dist/objects/objects-readable-generator.d.ts +31 -0
- package/dist/objects/objects-readable-generator.js +192 -0
- package/dist/objects/objects-readable-generator.js.map +1 -0
- package/dist/objects/raw-object.d.ts +23 -0
- package/dist/objects/raw-object.js +155 -0
- package/dist/objects/raw-object.js.map +1 -0
- package/dist/objects/ref.d.ts +14 -0
- package/dist/objects/ref.js +45 -0
- package/dist/objects/ref.js.map +1 -0
- package/dist/objects/repository-hooks.d.ts +4 -0
- package/dist/objects/repository-hooks.js +56 -0
- package/dist/objects/repository-hooks.js.map +1 -0
- package/dist/objects/repository.d.ts +148 -0
- package/dist/objects/repository.js +842 -0
- package/dist/objects/repository.js.map +1 -0
- package/dist/objects/scope-index.d.ts +73 -0
- package/dist/objects/scope-index.js +251 -0
- package/dist/objects/scope-index.js.map +1 -0
- package/dist/objects/scope-index.spec.d.ts +1 -0
- package/dist/objects/scope-index.spec.js +152 -0
- package/dist/objects/scope-index.spec.js.map +1 -0
- package/dist/objects.aspect.d.ts +2 -0
- package/dist/objects.aspect.js +18 -0
- package/dist/objects.aspect.js.map +1 -0
- package/dist/objects.main.runtime.d.ts +7 -0
- package/dist/objects.main.runtime.js +36 -0
- package/dist/objects.main.runtime.js.map +1 -0
- package/dist/preview-1736824735631.js +7 -0
- package/fixtures/version-model-extended.json +48 -0
- package/fixtures/version-model-object.json +87 -0
- package/models/dependencies-graph.ts +119 -0
- package/models/detach-heads.ts +79 -0
- package/models/export-metadata.ts +57 -0
- package/models/index.ts +11 -0
- package/models/lane-history.ts +106 -0
- package/models/lane.ts +367 -0
- package/models/model-component.spec.ts +55 -0
- package/models/model-component.ts +1367 -0
- package/models/scopeMeta.ts +60 -0
- package/models/source.ts +32 -0
- package/models/symlink.ts +66 -0
- package/models/version-history.ts +266 -0
- package/models/version.spec.ts +288 -0
- package/models/version.ts +818 -0
- package/objects/bit-object-list.ts +59 -0
- package/objects/index.ts +6 -0
- package/objects/object-list-to-graph.ts +69 -0
- package/objects/object-list.ts +313 -0
- package/objects/object.ts +153 -0
- package/objects/objects-readable-generator.ts +167 -0
- package/objects/raw-object.ts +142 -0
- package/objects/ref.ts +45 -0
- package/objects/repository-hooks.ts +42 -0
- package/objects/repository.ts +753 -0
- package/objects/scope-index.spec.ts +95 -0
- package/objects/scope-index.ts +192 -0
- package/package.json +98 -0
- package/types/asset.d.ts +41 -0
- package/types/style.d.ts +42 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_models","data","require","BitObjectList","constructor","objects","getComponents","filter","object","ModelComponent","getVersions","Version","getLanes","Lane","getVersionHistories","VersionHistory","getLaneHistories","LaneHistory","getAll","excludeTypes","types","includes","getType","getExportMetadata","find","ExportMetadata","getObjectsRequireMerge","typeRequireMerge","objectTypesRequireMerge","some","ObjClass","getObjectsNotRequireMerge","every","exports"],"sources":["bit-object-list.ts"],"sourcesContent":["import BitObject from './object';\nimport { ExportMetadata, Lane, LaneHistory, ModelComponent, Version, VersionHistory } from '../models';\n\nexport class BitObjectList {\n constructor(private objects: BitObject[]) {}\n\n getComponents(): ModelComponent[] {\n return this.objects.filter((object) => object instanceof ModelComponent) as ModelComponent[];\n }\n\n getVersions(): Version[] {\n return this.objects.filter((object) => object instanceof Version) as Version[];\n }\n\n getLanes(): Lane[] {\n return this.objects.filter((object) => object instanceof Lane) as Lane[];\n }\n\n getVersionHistories(): VersionHistory[] {\n return this.objects.filter((object) => object instanceof VersionHistory) as VersionHistory[];\n }\n\n getLaneHistories(): LaneHistory[] {\n return this.objects.filter((object) => object instanceof LaneHistory) as LaneHistory[];\n }\n\n getAll(): BitObject[] {\n return this.objects;\n }\n\n excludeTypes(types: string[]): BitObject[] {\n return this.objects.filter((object) => !types.includes(object.getType()));\n }\n\n getExportMetadata(): ExportMetadata | undefined {\n return this.objects.find((object) => object instanceof ExportMetadata) as ExportMetadata | undefined;\n }\n\n /**\n * object that needs merge operation before saving them into the scope, such as ModelComponent\n */\n getObjectsRequireMerge() {\n const typeRequireMerge = this.objectTypesRequireMerge();\n return this.objects.filter((object) => typeRequireMerge.some((ObjClass) => object instanceof ObjClass));\n }\n\n /**\n * object that don't need merge operation and can be saved immediately into the scope.\n * such as Source or Version\n */\n getObjectsNotRequireMerge() {\n const typeRequireMerge = this.objectTypesRequireMerge();\n return this.objects.filter((object) => typeRequireMerge.every((ObjClass) => !(object instanceof ObjClass)));\n }\n\n private objectTypesRequireMerge() {\n return [ModelComponent, Lane, VersionHistory, LaneHistory];\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,MAAME,aAAa,CAAC;EACzBC,WAAWA,CAASC,OAAoB,EAAE;IAAA,KAAtBA,OAAoB,GAApBA,OAAoB;EAAG;EAE3CC,aAAaA,CAAA,EAAqB;IAChC,OAAO,IAAI,CAACD,OAAO,CAACE,MAAM,CAAEC,MAAM,IAAKA,MAAM,YAAYC,wBAAc,CAAC;EAC1E;EAEAC,WAAWA,CAAA,EAAc;IACvB,OAAO,IAAI,CAAC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AM,IAAKmB,gBAAgB,CAACK,KAAK,CAAEF,QAAQ,IAAK,EAAEtB,MAAM,YAAYsB,QAAQ,CAAC,CAAC,CAAC;EAC7G;EAEQF,uBAAuBA,CAAA,EAAG;IAChC,OAAO,CAACnB,wBAAc,EAAEI,cAAI,EAAEE,wBAAc,EAAEE,qBAAW,CAAC;EAC5D;AACF;AAACgB,OAAA,CAAA9B,aAAA,GAAAA,aAAA","ignoreList":[]}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
Object.defineProperty(exports, "BitObject", {
|
7
|
+
enumerable: true,
|
8
|
+
get: function () {
|
9
|
+
return _object().default;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
Object.defineProperty(exports, "BitRawObject", {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _rawObject().default;
|
16
|
+
}
|
17
|
+
});
|
18
|
+
Object.defineProperty(exports, "Ref", {
|
19
|
+
enumerable: true,
|
20
|
+
get: function () {
|
21
|
+
return _ref().default;
|
22
|
+
}
|
23
|
+
});
|
24
|
+
Object.defineProperty(exports, "Repository", {
|
25
|
+
enumerable: true,
|
26
|
+
get: function () {
|
27
|
+
return _repository().default;
|
28
|
+
}
|
29
|
+
});
|
30
|
+
function _object() {
|
31
|
+
const data = _interopRequireDefault(require("./object"));
|
32
|
+
_object = function () {
|
33
|
+
return data;
|
34
|
+
};
|
35
|
+
return data;
|
36
|
+
}
|
37
|
+
function _rawObject() {
|
38
|
+
const data = _interopRequireDefault(require("./raw-object"));
|
39
|
+
_rawObject = function () {
|
40
|
+
return data;
|
41
|
+
};
|
42
|
+
return data;
|
43
|
+
}
|
44
|
+
function _ref() {
|
45
|
+
const data = _interopRequireDefault(require("./ref"));
|
46
|
+
_ref = function () {
|
47
|
+
return data;
|
48
|
+
};
|
49
|
+
return data;
|
50
|
+
}
|
51
|
+
function _repository() {
|
52
|
+
const data = _interopRequireDefault(require("./repository"));
|
53
|
+
_repository = function () {
|
54
|
+
return data;
|
55
|
+
};
|
56
|
+
return data;
|
57
|
+
}
|
58
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
59
|
+
|
60
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +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":[]}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { Graph, Node, Edge } from '@teambit/graph.cleargraph';
|
2
|
+
import { ComponentID } from '@teambit/component-id';
|
3
|
+
import type { ObjectList } from './object-list';
|
4
|
+
import { BitObjectList } from './bit-object-list';
|
5
|
+
import { Dependency } from '@teambit/graph';
|
6
|
+
type BitIdNode = Node<ComponentID>;
|
7
|
+
type DependencyEdge = Edge<Dependency>;
|
8
|
+
export declare class IdGraph extends Graph<ComponentID, Dependency> {
|
9
|
+
constructor(nodes?: BitIdNode[], edges?: DependencyEdge[]);
|
10
|
+
}
|
11
|
+
export declare function objectListToGraph(objectList: ObjectList): Promise<IdGraph>;
|
12
|
+
export declare function bitObjectListToGraph(bitObjectsList: BitObjectList): Promise<IdGraph>;
|
13
|
+
export {};
|
@@ -0,0 +1,93 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.IdGraph = void 0;
|
7
|
+
exports.bitObjectListToGraph = bitObjectListToGraph;
|
8
|
+
exports.objectListToGraph = objectListToGraph;
|
9
|
+
function _graph() {
|
10
|
+
const data = require("@teambit/graph.cleargraph");
|
11
|
+
_graph = function () {
|
12
|
+
return data;
|
13
|
+
};
|
14
|
+
return data;
|
15
|
+
}
|
16
|
+
function _lodash() {
|
17
|
+
const data = require("lodash");
|
18
|
+
_lodash = function () {
|
19
|
+
return data;
|
20
|
+
};
|
21
|
+
return data;
|
22
|
+
}
|
23
|
+
function _component() {
|
24
|
+
const data = require("@teambit/component.snap-distance");
|
25
|
+
_component = function () {
|
26
|
+
return data;
|
27
|
+
};
|
28
|
+
return data;
|
29
|
+
}
|
30
|
+
function _graph2() {
|
31
|
+
const data = require("@teambit/graph");
|
32
|
+
_graph2 = function () {
|
33
|
+
return data;
|
34
|
+
};
|
35
|
+
return data;
|
36
|
+
}
|
37
|
+
class IdGraph extends _graph().Graph {
|
38
|
+
constructor(nodes = [], edges = []) {
|
39
|
+
super(nodes, edges);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
exports.IdGraph = IdGraph;
|
43
|
+
async function objectListToGraph(objectList) {
|
44
|
+
const bitObjectsList = await objectList.toBitObjects();
|
45
|
+
return bitObjectListToGraph(bitObjectsList);
|
46
|
+
}
|
47
|
+
async function bitObjectListToGraph(bitObjectsList) {
|
48
|
+
const exportMetadata = bitObjectsList.getExportMetadata();
|
49
|
+
const components = bitObjectsList.getComponents();
|
50
|
+
const versions = bitObjectsList.getVersions();
|
51
|
+
const nodes = [];
|
52
|
+
const edges = [];
|
53
|
+
await Promise.all(components.map(async component => {
|
54
|
+
const compFromMetadata = exportMetadata?.exportVersions.find(c => c.id.isEqualWithoutVersion(component.toComponentId()));
|
55
|
+
const startFrom = compFromMetadata?.head;
|
56
|
+
const versionsInfo = await (0, _component().getAllVersionsInfo)({
|
57
|
+
modelComponent: component,
|
58
|
+
versionObjects: versions,
|
59
|
+
startFrom,
|
60
|
+
throws: false
|
61
|
+
});
|
62
|
+
versionsInfo.forEach(versionInfo => {
|
63
|
+
const id = component.toComponentId().changeVersion(versionInfo.tag || versionInfo.ref.toString());
|
64
|
+
const idStr = id.toString();
|
65
|
+
nodes.push(new (_graph().Node)(idStr, id));
|
66
|
+
if (!versionInfo.version) {
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
const {
|
70
|
+
dependencies,
|
71
|
+
devDependencies,
|
72
|
+
peerDependencies,
|
73
|
+
extensionDependencies
|
74
|
+
} = versionInfo.version.depsIdsGroupedByType;
|
75
|
+
const addDep = (depId, edge) => {
|
76
|
+
const depIdStr = depId.toString();
|
77
|
+
nodes.push(new (_graph().Node)(depIdStr, depId));
|
78
|
+
edges.push(new (_graph().Edge)(idStr, depIdStr, edge));
|
79
|
+
};
|
80
|
+
const runTime = new (_graph2().Dependency)('runtime');
|
81
|
+
const dev = new (_graph2().Dependency)('dev');
|
82
|
+
const peer = new (_graph2().Dependency)('peer');
|
83
|
+
dependencies.forEach(depId => addDep(depId, runTime));
|
84
|
+
[...devDependencies, ...extensionDependencies].forEach(depId => addDep(depId, dev));
|
85
|
+
peerDependencies.forEach(depId => addDep(depId, peer));
|
86
|
+
});
|
87
|
+
}));
|
88
|
+
const uniqNodes = (0, _lodash().uniqBy)(nodes, 'id');
|
89
|
+
const idGraph = new IdGraph(uniqNodes, edges);
|
90
|
+
return idGraph;
|
91
|
+
}
|
92
|
+
|
93
|
+
//# sourceMappingURL=object-list-to-graph.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_graph","data","require","_lodash","_component","_graph2","IdGraph","Graph","constructor","nodes","edges","exports","objectListToGraph","objectList","bitObjectsList","toBitObjects","bitObjectListToGraph","exportMetadata","getExportMetadata","components","getComponents","versions","getVersions","Promise","all","map","component","compFromMetadata","exportVersions","find","c","id","isEqualWithoutVersion","toComponentId","startFrom","head","versionsInfo","getAllVersionsInfo","modelComponent","versionObjects","throws","forEach","versionInfo","changeVersion","tag","ref","toString","idStr","push","Node","version","dependencies","devDependencies","peerDependencies","extensionDependencies","depsIdsGroupedByType","addDep","depId","edge","depIdStr","Edge","runTime","Dependency","dev","peer","uniqNodes","uniqBy","idGraph"],"sources":["object-list-to-graph.ts"],"sourcesContent":["import { Graph, Node, Edge } from '@teambit/graph.cleargraph';\nimport { uniqBy } from 'lodash';\nimport { ComponentID } from '@teambit/component-id';\nimport type { ObjectList } from './object-list';\nimport { BitObjectList } from './bit-object-list';\nimport { getAllVersionsInfo } from '@teambit/component.snap-distance';\nimport { Dependency } from '@teambit/graph';\n\ntype BitIdNode = Node<ComponentID>;\ntype DependencyEdge = Edge<Dependency>;\n\nexport class IdGraph extends Graph<ComponentID, Dependency> {\n constructor(nodes: BitIdNode[] = [], edges: DependencyEdge[] = []) {\n super(nodes, edges);\n }\n}\n\nexport async function objectListToGraph(objectList: ObjectList): Promise<IdGraph> {\n const bitObjectsList = await objectList.toBitObjects();\n\n return bitObjectListToGraph(bitObjectsList);\n}\n\nexport async function bitObjectListToGraph(bitObjectsList: BitObjectList): Promise<IdGraph> {\n const exportMetadata = bitObjectsList.getExportMetadata();\n const components = bitObjectsList.getComponents();\n const versions = bitObjectsList.getVersions();\n const nodes: BitIdNode[] = [];\n const edges: DependencyEdge[] = [];\n await Promise.all(\n components.map(async (component) => {\n const compFromMetadata = exportMetadata?.exportVersions.find((c) =>\n c.id.isEqualWithoutVersion(component.toComponentId())\n );\n const startFrom = compFromMetadata?.head;\n const versionsInfo = await getAllVersionsInfo({\n modelComponent: component,\n versionObjects: versions,\n startFrom,\n throws: false,\n });\n versionsInfo.forEach((versionInfo) => {\n const id = component.toComponentId().changeVersion(versionInfo.tag || versionInfo.ref.toString());\n const idStr = id.toString();\n nodes.push(new Node(idStr, id));\n if (!versionInfo.version) {\n return;\n }\n const { dependencies, devDependencies, peerDependencies, extensionDependencies } =\n versionInfo.version.depsIdsGroupedByType;\n const addDep = (depId: ComponentID, edge: Dependency) => {\n const depIdStr = depId.toString();\n nodes.push(new Node(depIdStr, depId));\n edges.push(new Edge(idStr, depIdStr, edge));\n };\n const runTime = new Dependency('runtime');\n const dev = new Dependency('dev');\n const peer = new Dependency('peer');\n dependencies.forEach((depId) => addDep(depId, runTime));\n [...devDependencies, ...extensionDependencies].forEach((depId) => addDep(depId, dev));\n peerDependencies.forEach((depId) => addDep(depId, peer));\n });\n })\n );\n const uniqNodes = uniqBy(nodes, 'id');\n const idGraph = new IdGraph(uniqNodes, edges);\n\n return idGraph;\n}\n"],"mappings":";;;;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAIA,SAAAG,WAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,UAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OA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,gBAAgB,CAACZ,OAAO,CAAEgB,KAAK,IAAKD,MAAM,CAACC,KAAK,EAAEO,IAAI,CAAC,CAAC;IAC1D,CAAC,CAAC;EACJ,CAAC,CACH,CAAC;EACD,MAAMC,SAAS,GAAG,IAAAC,gBAAM,EAACzD,KAAK,EAAE,IAAI,CAAC;EACrC,MAAM0D,OAAO,GAAG,IAAI7D,OAAO,CAAC2D,SAAS,EAAEvD,KAAK,CAAC;EAE7C,OAAOyD,OAAO;AAChB","ignoreList":[]}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { Readable } from 'stream';
|
2
|
+
import BitObject from './object';
|
3
|
+
import { BitObjectList } from './bit-object-list';
|
4
|
+
import Ref from './ref';
|
5
|
+
export type ObjectItem = {
|
6
|
+
ref: Ref;
|
7
|
+
buffer: Buffer;
|
8
|
+
type?: string;
|
9
|
+
scope?: string;
|
10
|
+
};
|
11
|
+
export declare const FETCH_FORMAT_OBJECT_LIST = "ObjectList";
|
12
|
+
/**
|
13
|
+
* Stream.Readable that operates with objectMode, while each 'data' event emits one ObjectItem object.
|
14
|
+
*/
|
15
|
+
export type ObjectItemsStream = Readable;
|
16
|
+
export declare class ObjectList {
|
17
|
+
objects: ObjectItem[];
|
18
|
+
constructor(objects?: ObjectItem[]);
|
19
|
+
count(): number;
|
20
|
+
static mergeMultipleInstances(objectLists: ObjectList[]): ObjectList;
|
21
|
+
mergeObjectList(objectList: ObjectList): void;
|
22
|
+
static fromJsonString(jsonStr: string): ObjectList;
|
23
|
+
toJsonString(): string;
|
24
|
+
toTar(): NodeJS.ReadableStream;
|
25
|
+
toReadableStream(): ObjectItemsStream;
|
26
|
+
static fromTar(packStream: NodeJS.ReadableStream): Promise<ObjectList>;
|
27
|
+
static fromTarToObjectStream(packStream: NodeJS.ReadableStream): ObjectItemsStream;
|
28
|
+
static fromObjectStreamToTar(readable: Readable, scopeName: string): any;
|
29
|
+
static fromReadableStream(readable: ObjectItemsStream): Promise<ObjectList>;
|
30
|
+
/**
|
31
|
+
* the opposite of this.combineScopeAndHash
|
32
|
+
*/
|
33
|
+
static extractScopeAndHash(name: string): {
|
34
|
+
scope?: string;
|
35
|
+
ref: Ref;
|
36
|
+
};
|
37
|
+
/**
|
38
|
+
* the opposite of this.extractScopeAndHash
|
39
|
+
*/
|
40
|
+
static combineScopeAndHash(objectItem: ObjectItem): string;
|
41
|
+
addIfNotExist(objectItems: ObjectItem[]): void;
|
42
|
+
toBitObjects(throwForUnknownTypes?: boolean): Promise<BitObjectList>;
|
43
|
+
static fromBitObjects(bitObjects: BitObject[]): Promise<ObjectList>;
|
44
|
+
addScopeName(scopeName: string): void;
|
45
|
+
splitByScopeName(): {
|
46
|
+
[scopeName: string]: ObjectList;
|
47
|
+
};
|
48
|
+
/**
|
49
|
+
* helps debugging
|
50
|
+
*/
|
51
|
+
toConsoleLog(): void;
|
52
|
+
}
|
@@ -0,0 +1,369 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.ObjectList = exports.FETCH_FORMAT_OBJECT_LIST = void 0;
|
7
|
+
function _tarStream() {
|
8
|
+
const data = _interopRequireDefault(require("tar-stream"));
|
9
|
+
_tarStream = function () {
|
10
|
+
return data;
|
11
|
+
};
|
12
|
+
return data;
|
13
|
+
}
|
14
|
+
function _toolboxPromise() {
|
15
|
+
const data = require("@teambit/toolbox.promise.map-pool");
|
16
|
+
_toolboxPromise = function () {
|
17
|
+
return data;
|
18
|
+
};
|
19
|
+
return data;
|
20
|
+
}
|
21
|
+
function _lodash() {
|
22
|
+
const data = require("lodash");
|
23
|
+
_lodash = function () {
|
24
|
+
return data;
|
25
|
+
};
|
26
|
+
return data;
|
27
|
+
}
|
28
|
+
function _stream() {
|
29
|
+
const data = require("stream");
|
30
|
+
_stream = function () {
|
31
|
+
return data;
|
32
|
+
};
|
33
|
+
return data;
|
34
|
+
}
|
35
|
+
function _object() {
|
36
|
+
const data = _interopRequireDefault(require("./object"));
|
37
|
+
_object = function () {
|
38
|
+
return data;
|
39
|
+
};
|
40
|
+
return data;
|
41
|
+
}
|
42
|
+
function _bitObjectList() {
|
43
|
+
const data = require("./bit-object-list");
|
44
|
+
_bitObjectList = function () {
|
45
|
+
return data;
|
46
|
+
};
|
47
|
+
return data;
|
48
|
+
}
|
49
|
+
function _ref() {
|
50
|
+
const data = _interopRequireDefault(require("./ref"));
|
51
|
+
_ref = function () {
|
52
|
+
return data;
|
53
|
+
};
|
54
|
+
return data;
|
55
|
+
}
|
56
|
+
function _legacy() {
|
57
|
+
const data = require("@teambit/legacy.logger");
|
58
|
+
_legacy = function () {
|
59
|
+
return data;
|
60
|
+
};
|
61
|
+
return data;
|
62
|
+
}
|
63
|
+
function _harmonyModules() {
|
64
|
+
const data = require("@teambit/harmony.modules.concurrency");
|
65
|
+
_harmonyModules = function () {
|
66
|
+
return data;
|
67
|
+
};
|
68
|
+
return data;
|
69
|
+
}
|
70
|
+
function _models() {
|
71
|
+
const data = require("../models");
|
72
|
+
_models = function () {
|
73
|
+
return data;
|
74
|
+
};
|
75
|
+
return data;
|
76
|
+
}
|
77
|
+
function _legacy2() {
|
78
|
+
const data = require("@teambit/legacy.scope");
|
79
|
+
_legacy2 = function () {
|
80
|
+
return data;
|
81
|
+
};
|
82
|
+
return data;
|
83
|
+
}
|
84
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
85
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
86
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
87
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
88
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
89
|
+
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); }
|
90
|
+
/**
|
91
|
+
* when error occurred during streaming between HTTP server and client, there is no good way to
|
92
|
+
* indicate this other than sending a new file with a special name and the error message.
|
93
|
+
*/
|
94
|
+
const TAR_STREAM_ERROR_FILENAME = '.BIT.ERROR';
|
95
|
+
/**
|
96
|
+
* schema 1.0.0 - added the start and end file with basic info
|
97
|
+
*/
|
98
|
+
const OBJECT_LIST_CURRENT_SCHEMA = '1.0.0';
|
99
|
+
const TAR_STREAM_START_FILENAME = '.BIT.START';
|
100
|
+
const TAR_STREAM_END_FILENAME = '.BIT.END';
|
101
|
+
const FETCH_FORMAT_OBJECT_LIST = exports.FETCH_FORMAT_OBJECT_LIST = 'ObjectList';
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Stream.Readable that operates with objectMode, while each 'data' event emits one ObjectItem object.
|
105
|
+
*/
|
106
|
+
|
107
|
+
class ObjectList {
|
108
|
+
constructor(objects = []) {
|
109
|
+
this.objects = objects;
|
110
|
+
}
|
111
|
+
count() {
|
112
|
+
return this.objects.length;
|
113
|
+
}
|
114
|
+
static mergeMultipleInstances(objectLists) {
|
115
|
+
const objectList = new ObjectList();
|
116
|
+
objectLists.forEach(objList => objectList.mergeObjectList(objList));
|
117
|
+
return objectList;
|
118
|
+
}
|
119
|
+
mergeObjectList(objectList) {
|
120
|
+
this.addIfNotExist(objectList.objects);
|
121
|
+
}
|
122
|
+
static fromJsonString(jsonStr) {
|
123
|
+
const jsonParsed = JSON.parse(jsonStr);
|
124
|
+
if (!Array.isArray(jsonParsed)) {
|
125
|
+
throw new Error(`fromJsonString expect an array, got ${typeof jsonParsed}`);
|
126
|
+
}
|
127
|
+
jsonParsed.forEach(obj => {
|
128
|
+
obj.ref = new (_ref().default)(obj.ref.hash);
|
129
|
+
obj.buffer = Buffer.from(obj.buffer);
|
130
|
+
});
|
131
|
+
return new ObjectList(jsonParsed);
|
132
|
+
}
|
133
|
+
toJsonString() {
|
134
|
+
return JSON.stringify(this.objects);
|
135
|
+
}
|
136
|
+
toTar() {
|
137
|
+
const pack = _tarStream().default.pack();
|
138
|
+
this.objects.forEach(obj => {
|
139
|
+
pack.entry({
|
140
|
+
name: ObjectList.combineScopeAndHash(obj)
|
141
|
+
}, obj.buffer);
|
142
|
+
});
|
143
|
+
pack.finalize();
|
144
|
+
return pack;
|
145
|
+
}
|
146
|
+
toReadableStream() {
|
147
|
+
return _stream().Readable.from(this.objects);
|
148
|
+
}
|
149
|
+
static async fromTar(packStream) {
|
150
|
+
const extract = _tarStream().default.extract();
|
151
|
+
const objectItems = await new Promise((resolve, reject) => {
|
152
|
+
const objects = [];
|
153
|
+
extract.on('entry', (header, stream, next) => {
|
154
|
+
const data = [];
|
155
|
+
stream.on('data', chunk => {
|
156
|
+
data.push(chunk);
|
157
|
+
});
|
158
|
+
stream.on('end', () => {
|
159
|
+
objects.push(_objectSpread(_objectSpread({}, ObjectList.extractScopeAndHash(header.name)), {}, {
|
160
|
+
buffer: Buffer.concat(data)
|
161
|
+
}));
|
162
|
+
next(); // ready for next entry
|
163
|
+
});
|
164
|
+
stream.on('error', err => reject(err));
|
165
|
+
stream.resume(); // just auto drain the stream
|
166
|
+
});
|
167
|
+
extract.on('finish', () => {
|
168
|
+
resolve(objects);
|
169
|
+
});
|
170
|
+
packStream.pipe(extract);
|
171
|
+
});
|
172
|
+
return new ObjectList(objectItems);
|
173
|
+
}
|
174
|
+
static fromTarToObjectStream(packStream) {
|
175
|
+
const passThrough = new (_stream().PassThrough)({
|
176
|
+
objectMode: true
|
177
|
+
});
|
178
|
+
const extract = _tarStream().default.extract();
|
179
|
+
let startData;
|
180
|
+
let endData;
|
181
|
+
extract.on('entry', (header, stream, next) => {
|
182
|
+
const data = [];
|
183
|
+
stream.on('data', chunk => {
|
184
|
+
data.push(chunk);
|
185
|
+
});
|
186
|
+
stream.on('end', () => {
|
187
|
+
const allData = Buffer.concat(data);
|
188
|
+
if (header.name === TAR_STREAM_ERROR_FILENAME) {
|
189
|
+
passThrough.emit('error', new Error(allData.toString()));
|
190
|
+
return;
|
191
|
+
}
|
192
|
+
if (header.name === TAR_STREAM_START_FILENAME) {
|
193
|
+
startData = JSON.parse(allData.toString());
|
194
|
+
_legacy().logger.debug('fromTarToObjectStream, start getting data', startData);
|
195
|
+
next();
|
196
|
+
return;
|
197
|
+
}
|
198
|
+
if (header.name === TAR_STREAM_END_FILENAME) {
|
199
|
+
endData = JSON.parse(allData.toString());
|
200
|
+
_legacy().logger.debug('fromTarToObjectStream, finished getting data', endData);
|
201
|
+
next();
|
202
|
+
return;
|
203
|
+
}
|
204
|
+
passThrough.write(_objectSpread(_objectSpread({}, ObjectList.extractScopeAndHash(header.name)), {}, {
|
205
|
+
buffer: allData
|
206
|
+
}));
|
207
|
+
next(); // ready for next entry
|
208
|
+
});
|
209
|
+
stream.on('error', err => {
|
210
|
+
passThrough.emit('error', err);
|
211
|
+
});
|
212
|
+
stream.resume(); // just auto drain the stream
|
213
|
+
});
|
214
|
+
|
215
|
+
// not sure if needed
|
216
|
+
extract.on('error', err => {
|
217
|
+
passThrough.emit('error', err);
|
218
|
+
});
|
219
|
+
extract.on('finish', () => {
|
220
|
+
if (startData?.schema === OBJECT_LIST_CURRENT_SCHEMA && !endData) {
|
221
|
+
// wasn't able to find a better way to indicate whether the server aborted the request
|
222
|
+
// see https://github.com/node-fetch/node-fetch/issues/1117
|
223
|
+
passThrough.emit('error', new Error(`server terminated the stream unexpectedly (metadata: ${JSON.stringify(startData)})`));
|
224
|
+
}
|
225
|
+
passThrough.end();
|
226
|
+
});
|
227
|
+
(0, _stream().pipeline)(packStream, extract, err => {
|
228
|
+
if (err) {
|
229
|
+
_legacy().logger.error('fromTarToObjectStream, pipeline', err);
|
230
|
+
passThrough.emit('error', err);
|
231
|
+
} else {
|
232
|
+
_legacy().logger.debug('fromTarToObjectStream, pipeline is completed');
|
233
|
+
}
|
234
|
+
});
|
235
|
+
return passThrough;
|
236
|
+
}
|
237
|
+
static fromObjectStreamToTar(readable, scopeName) {
|
238
|
+
const pack = _tarStream().default.pack();
|
239
|
+
const startFile = {
|
240
|
+
schema: OBJECT_LIST_CURRENT_SCHEMA,
|
241
|
+
scopeName
|
242
|
+
};
|
243
|
+
_legacy().logger.debug('fromObjectStreamToTar, start sending data', startFile);
|
244
|
+
pack.entry({
|
245
|
+
name: TAR_STREAM_START_FILENAME
|
246
|
+
}, JSON.stringify(startFile));
|
247
|
+
let numOfFiles = 0;
|
248
|
+
readable.on('data', obj => {
|
249
|
+
numOfFiles += 1;
|
250
|
+
pack.entry({
|
251
|
+
name: ObjectList.combineScopeAndHash(obj)
|
252
|
+
}, obj.buffer);
|
253
|
+
});
|
254
|
+
readable.on('end', () => {
|
255
|
+
const endFile = {
|
256
|
+
numOfFiles,
|
257
|
+
scopeName
|
258
|
+
};
|
259
|
+
_legacy().logger.debug('fromObjectStreamToTar, finished sending data', endFile);
|
260
|
+
pack.entry({
|
261
|
+
name: TAR_STREAM_END_FILENAME
|
262
|
+
}, JSON.stringify(endFile));
|
263
|
+
pack.finalize();
|
264
|
+
});
|
265
|
+
readable.on('error', err => {
|
266
|
+
const errorMessage = err.message || `unexpected error (${err.name})`;
|
267
|
+
_legacy().logger.error(`ObjectList.fromObjectStreamToTar, streaming an error as a file`, err);
|
268
|
+
pack.entry({
|
269
|
+
name: TAR_STREAM_ERROR_FILENAME
|
270
|
+
}, errorMessage);
|
271
|
+
pack.finalize();
|
272
|
+
});
|
273
|
+
return pack;
|
274
|
+
}
|
275
|
+
static async fromReadableStream(readable) {
|
276
|
+
const objectItems = [];
|
277
|
+
for await (const obj of readable) {
|
278
|
+
objectItems.push(obj);
|
279
|
+
}
|
280
|
+
return new ObjectList(objectItems);
|
281
|
+
}
|
282
|
+
|
283
|
+
/**
|
284
|
+
* the opposite of this.combineScopeAndHash
|
285
|
+
*/
|
286
|
+
static extractScopeAndHash(name) {
|
287
|
+
const nameSplit = name.split('/');
|
288
|
+
const hasScope = nameSplit.length > 1;
|
289
|
+
return {
|
290
|
+
scope: hasScope ? nameSplit[0] : undefined,
|
291
|
+
ref: new (_ref().default)(hasScope ? nameSplit[1] : nameSplit[0])
|
292
|
+
};
|
293
|
+
}
|
294
|
+
/**
|
295
|
+
* the opposite of this.extractScopeAndHash
|
296
|
+
*/
|
297
|
+
static combineScopeAndHash(objectItem) {
|
298
|
+
const scope = objectItem.scope ? `${objectItem.scope}/` : '';
|
299
|
+
return `${scope}${objectItem.ref.hash}`;
|
300
|
+
}
|
301
|
+
addIfNotExist(objectItems) {
|
302
|
+
objectItems.forEach(objectItem => {
|
303
|
+
const exists = this.objects.find(object => object.ref.isEqual(objectItem.ref) && object.scope === objectItem.scope);
|
304
|
+
if (!exists) {
|
305
|
+
this.objects.push(objectItem);
|
306
|
+
}
|
307
|
+
});
|
308
|
+
}
|
309
|
+
async toBitObjects(throwForUnknownTypes = false) {
|
310
|
+
const concurrency = (0, _harmonyModules().concurrentIOLimit)();
|
311
|
+
const bitObjects = await (0, _toolboxPromise().pMapPool)(this.objects, async object => {
|
312
|
+
try {
|
313
|
+
return await _object().default.parseObject(object.buffer);
|
314
|
+
} catch (err) {
|
315
|
+
if (throwForUnknownTypes || !(err instanceof _legacy2().UnknownObjectType)) {
|
316
|
+
throw err;
|
317
|
+
}
|
318
|
+
_legacy().logger.error(`toBitObjects, unable to parse object of type ${err.type}, ignoring it. please update your bit version`);
|
319
|
+
return null;
|
320
|
+
}
|
321
|
+
}, {
|
322
|
+
concurrency
|
323
|
+
});
|
324
|
+
return new (_bitObjectList().BitObjectList)((0, _lodash().compact)(bitObjects));
|
325
|
+
}
|
326
|
+
static async fromBitObjects(bitObjects) {
|
327
|
+
const concurrency = (0, _harmonyModules().concurrentIOLimit)();
|
328
|
+
const objectItems = await (0, _toolboxPromise().pMapPool)(bitObjects, async obj => ({
|
329
|
+
ref: obj.hash(),
|
330
|
+
buffer: await obj.compress(),
|
331
|
+
type: obj.getType()
|
332
|
+
}), {
|
333
|
+
concurrency
|
334
|
+
});
|
335
|
+
return new ObjectList(objectItems);
|
336
|
+
}
|
337
|
+
addScopeName(scopeName) {
|
338
|
+
this.objects.forEach(object => {
|
339
|
+
object.scope = scopeName;
|
340
|
+
});
|
341
|
+
}
|
342
|
+
splitByScopeName() {
|
343
|
+
const objectListPerScope = {};
|
344
|
+
this.objects.forEach(obj => {
|
345
|
+
if (obj.type === _models().ExportMetadata.name) {
|
346
|
+
return; // no scope for this type. it's general for all export data from all scopes
|
347
|
+
}
|
348
|
+
if (!obj.scope) {
|
349
|
+
throw new Error(`ObjectList: unable to split by scopeName, the scopeName is missing for ${obj.ref.hash}`);
|
350
|
+
}
|
351
|
+
if (objectListPerScope[obj.scope]) {
|
352
|
+
objectListPerScope[obj.scope].addIfNotExist([obj]);
|
353
|
+
} else {
|
354
|
+
objectListPerScope[obj.scope] = new ObjectList([obj]);
|
355
|
+
}
|
356
|
+
});
|
357
|
+
return objectListPerScope;
|
358
|
+
}
|
359
|
+
|
360
|
+
/**
|
361
|
+
* helps debugging
|
362
|
+
*/
|
363
|
+
toConsoleLog() {
|
364
|
+
console.log(this.objects.map(o => o.ref.hash).join('\n')); // eslint-disable-line no-console
|
365
|
+
}
|
366
|
+
}
|
367
|
+
exports.ObjectList = ObjectList;
|
368
|
+
|
369
|
+
//# sourceMappingURL=object-list.js.map
|