@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.
Files changed (123) hide show
  1. package/artifacts/__bit_junit.xml +68 -0
  2. package/artifacts/preview/teambit_scope_objects-preview.js +1 -0
  3. package/dist/fixtures/version-model-extended.json +48 -0
  4. package/dist/fixtures/version-model-object.json +87 -0
  5. package/dist/index.d.ts +19 -0
  6. package/dist/index.js +371 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/models/dependencies-graph.d.ts +45 -0
  9. package/dist/models/dependencies-graph.js +106 -0
  10. package/dist/models/dependencies-graph.js.map +1 -0
  11. package/dist/models/detach-heads.d.ts +25 -0
  12. package/dist/models/detach-heads.js +84 -0
  13. package/dist/models/detach-heads.js.map +1 -0
  14. package/dist/models/export-metadata.d.ts +24 -0
  15. package/dist/models/export-metadata.js +76 -0
  16. package/dist/models/export-metadata.js.map +1 -0
  17. package/dist/models/index.d.ts +10 -0
  18. package/dist/models/index.js +125 -0
  19. package/dist/models/index.js.map +1 -0
  20. package/dist/models/lane-history.d.ts +40 -0
  21. package/dist/models/lane-history.js +117 -0
  22. package/dist/models/lane-history.js.map +1 -0
  23. package/dist/models/lane.d.ts +124 -0
  24. package/dist/models/lane.js +463 -0
  25. package/dist/models/lane.js.map +1 -0
  26. package/dist/models/model-component.d.ts +317 -0
  27. package/dist/models/model-component.js +1365 -0
  28. package/dist/models/model-component.js.map +1 -0
  29. package/dist/models/model-component.spec.d.ts +1 -0
  30. package/dist/models/model-component.spec.js +71 -0
  31. package/dist/models/model-component.spec.js.map +1 -0
  32. package/dist/models/scopeMeta.d.ts +20 -0
  33. package/dist/models/scopeMeta.js +71 -0
  34. package/dist/models/scopeMeta.js.map +1 -0
  35. package/dist/models/source.d.ts +10 -0
  36. package/dist/models/source.js +43 -0
  37. package/dist/models/source.js.map +1 -0
  38. package/dist/models/symlink.d.ts +30 -0
  39. package/dist/models/symlink.js +91 -0
  40. package/dist/models/symlink.js.map +1 -0
  41. package/dist/models/version-history.d.ts +59 -0
  42. package/dist/models/version-history.js +285 -0
  43. package/dist/models/version-history.js.map +1 -0
  44. package/dist/models/version.d.ts +279 -0
  45. package/dist/models/version.js +777 -0
  46. package/dist/models/version.js.map +1 -0
  47. package/dist/models/version.spec.d.ts +1 -0
  48. package/dist/models/version.spec.js +340 -0
  49. package/dist/models/version.spec.js.map +1 -0
  50. package/dist/objects/bit-object-list.d.ts +24 -0
  51. package/dist/objects/bit-object-list.js +65 -0
  52. package/dist/objects/bit-object-list.js.map +1 -0
  53. package/dist/objects/index.d.ts +5 -0
  54. package/dist/objects/index.js +60 -0
  55. package/dist/objects/index.js.map +1 -0
  56. package/dist/objects/object-list-to-graph.d.ts +13 -0
  57. package/dist/objects/object-list-to-graph.js +93 -0
  58. package/dist/objects/object-list-to-graph.js.map +1 -0
  59. package/dist/objects/object-list.d.ts +52 -0
  60. package/dist/objects/object-list.js +369 -0
  61. package/dist/objects/object-list.js.map +1 -0
  62. package/dist/objects/object.d.ts +35 -0
  63. package/dist/objects/object.js +190 -0
  64. package/dist/objects/object.js.map +1 -0
  65. package/dist/objects/objects-readable-generator.d.ts +31 -0
  66. package/dist/objects/objects-readable-generator.js +192 -0
  67. package/dist/objects/objects-readable-generator.js.map +1 -0
  68. package/dist/objects/raw-object.d.ts +23 -0
  69. package/dist/objects/raw-object.js +155 -0
  70. package/dist/objects/raw-object.js.map +1 -0
  71. package/dist/objects/ref.d.ts +14 -0
  72. package/dist/objects/ref.js +45 -0
  73. package/dist/objects/ref.js.map +1 -0
  74. package/dist/objects/repository-hooks.d.ts +4 -0
  75. package/dist/objects/repository-hooks.js +56 -0
  76. package/dist/objects/repository-hooks.js.map +1 -0
  77. package/dist/objects/repository.d.ts +148 -0
  78. package/dist/objects/repository.js +842 -0
  79. package/dist/objects/repository.js.map +1 -0
  80. package/dist/objects/scope-index.d.ts +73 -0
  81. package/dist/objects/scope-index.js +251 -0
  82. package/dist/objects/scope-index.js.map +1 -0
  83. package/dist/objects/scope-index.spec.d.ts +1 -0
  84. package/dist/objects/scope-index.spec.js +152 -0
  85. package/dist/objects/scope-index.spec.js.map +1 -0
  86. package/dist/objects.aspect.d.ts +2 -0
  87. package/dist/objects.aspect.js +18 -0
  88. package/dist/objects.aspect.js.map +1 -0
  89. package/dist/objects.main.runtime.d.ts +7 -0
  90. package/dist/objects.main.runtime.js +36 -0
  91. package/dist/objects.main.runtime.js.map +1 -0
  92. package/dist/preview-1736824735631.js +7 -0
  93. package/fixtures/version-model-extended.json +48 -0
  94. package/fixtures/version-model-object.json +87 -0
  95. package/models/dependencies-graph.ts +119 -0
  96. package/models/detach-heads.ts +79 -0
  97. package/models/export-metadata.ts +57 -0
  98. package/models/index.ts +11 -0
  99. package/models/lane-history.ts +106 -0
  100. package/models/lane.ts +367 -0
  101. package/models/model-component.spec.ts +55 -0
  102. package/models/model-component.ts +1367 -0
  103. package/models/scopeMeta.ts +60 -0
  104. package/models/source.ts +32 -0
  105. package/models/symlink.ts +66 -0
  106. package/models/version-history.ts +266 -0
  107. package/models/version.spec.ts +288 -0
  108. package/models/version.ts +818 -0
  109. package/objects/bit-object-list.ts +59 -0
  110. package/objects/index.ts +6 -0
  111. package/objects/object-list-to-graph.ts +69 -0
  112. package/objects/object-list.ts +313 -0
  113. package/objects/object.ts +153 -0
  114. package/objects/objects-readable-generator.ts +167 -0
  115. package/objects/raw-object.ts +142 -0
  116. package/objects/ref.ts +45 -0
  117. package/objects/repository-hooks.ts +42 -0
  118. package/objects/repository.ts +753 -0
  119. package/objects/scope-index.spec.ts +95 -0
  120. package/objects/scope-index.ts +192 -0
  121. package/package.json +98 -0
  122. package/types/asset.d.ts +41 -0
  123. package/types/style.d.ts +42 -0
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_uuid","data","require","_legacy","_harmonyModules","_objects","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","LaneHistory","BitObject","constructor","props","name","scope","laneHash","history","id","fromLaneObject","laneObject","hash","toString","toObject","pretty","args","getStringifyArgs","JSON","stringify","toBuffer","Buffer","from","getHistory","addHistory","laneObj","msg","log","getBasicLog","message","components","toComponentIds","toStringArray","deleted","c","isDeleted","map","changeVersion","head","v4","merge","laneHistory","create","parse","contents","parsed","exports"],"sources":["lane-history.ts"],"sourcesContent":["import { v4 } from 'uuid';\nimport { getStringifyArgs } from '@teambit/legacy.utils';\nimport { getBasicLog } from '@teambit/harmony.modules.get-basic-log';\nimport { BitObject } from '../objects';\nimport Lane from './lane';\n\ntype Log = { date: string; username?: string; email?: string; message?: string };\n\nexport type HistoryItem = {\n log: Log;\n components: string[];\n deleted?: string[];\n};\n\ntype History = { [uuid: string]: HistoryItem };\n\ntype LaneHistoryProps = {\n name: string;\n scope: string;\n laneHash: string;\n history: History;\n};\n\nexport class LaneHistory extends BitObject {\n private name: string;\n private scope: string;\n private laneHash: string;\n private history: History;\n\n constructor(props: LaneHistoryProps) {\n super();\n this.name = props.name;\n this.scope = props.scope;\n this.laneHash = props.laneHash;\n this.history = props.history;\n }\n\n id() {\n return `${this.laneHash}:${LaneHistory.name}`;\n }\n\n static fromLaneObject(laneObject: Lane): LaneHistory {\n return new LaneHistory({\n scope: laneObject.scope,\n name: laneObject.name,\n laneHash: laneObject.hash().toString(),\n history: {},\n });\n }\n\n toObject(): Record<string, any> {\n return {\n name: this.name,\n scope: this.scope,\n laneHash: this.laneHash,\n history: this.history,\n };\n }\n\n toString(pretty: boolean): string {\n const args = getStringifyArgs(pretty);\n return JSON.stringify(this.toObject(), ...args);\n }\n\n toBuffer(pretty): Buffer {\n return Buffer.from(this.toString(pretty));\n }\n\n getHistory(): History {\n return this.history;\n }\n\n async addHistory(laneObj: Lane, msg?: string) {\n const log: Log = await getBasicLog();\n if (msg) log.message = msg;\n const components = laneObj.toComponentIds().toStringArray();\n const deleted = laneObj.components\n .filter((c) => c.isDeleted)\n .map((c) => c.id.changeVersion(c.head.toString()).toString());\n this.history[v4()] = { log, components, ...(deleted.length && { deleted }) };\n }\n\n merge(laneHistory: LaneHistory) {\n this.history = { ...this.history, ...laneHistory.history };\n }\n\n static create(name: string, scope: string, laneHash: string) {\n return new LaneHistory({\n name,\n scope,\n laneHash,\n history: {},\n });\n }\n\n static parse(contents: string): LaneHistory {\n const parsed = JSON.parse(contents);\n const props: LaneHistoryProps = {\n name: parsed.name,\n scope: parsed.scope,\n laneHash: parsed.laneHash,\n history: parsed.history,\n };\n return new LaneHistory(props);\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,KAAA,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;AACA,SAAAG,gBAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,eAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,SAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,QAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAuC,SAAAK,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MA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gB,EAAE;IAC3D,OAAO,IAAIN,WAAW,CAAC;MACrBI,IAAI;MACJC,KAAK;MACLC,QAAQ;MACRC,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;EACJ;EAEA,OAAOmC,KAAKA,CAACC,QAAgB,EAAe;IAC1C,MAAMC,MAAM,GAAG3B,IAAI,CAACyB,KAAK,CAACC,QAAQ,CAAC;IACnC,MAAMxC,KAAuB,GAAG;MAC9BC,IAAI,EAAEwC,MAAM,CAACxC,IAAI;MACjBC,KAAK,EAAEuC,MAAM,CAACvC,KAAK;MACnBC,QAAQ,EAAEsC,MAAM,CAACtC,QAAQ;MACzBC,OAAO,EAAEqC,MAAM,CAACrC;IAClB,CAAC;IACD,OAAO,IAAIP,WAAW,CAACG,KAAK,CAAC;EAC/B;AACF;AAAC0C,OAAA,CAAA7C,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -0,0 +1,124 @@
1
+ import { ComponentID, ComponentIdList } from '@teambit/component-id';
2
+ import { LaneId } from '@teambit/lane-id';
3
+ import { Scope } from '@teambit/legacy.scope';
4
+ import { BitObject, Ref, Repository } from '../objects';
5
+ export type Log = {
6
+ date: string;
7
+ username?: string;
8
+ email?: string;
9
+ profileImage?: string;
10
+ };
11
+ export type LaneProps = {
12
+ name: string;
13
+ scope: string;
14
+ log: Log;
15
+ components?: LaneComponent[];
16
+ hash: string;
17
+ schema?: string;
18
+ readmeComponent?: LaneReadmeComponent;
19
+ forkedFrom?: LaneId;
20
+ updateDependents?: ComponentID[];
21
+ overrideUpdateDependents?: boolean;
22
+ };
23
+ export type LaneComponent = {
24
+ id: ComponentID;
25
+ head: Ref;
26
+ isDeleted?: boolean;
27
+ };
28
+ export type LaneReadmeComponent = {
29
+ id: ComponentID;
30
+ head: Ref | null;
31
+ };
32
+ export default class Lane extends BitObject {
33
+ name: string;
34
+ scope: string;
35
+ components: LaneComponent[];
36
+ log: Log;
37
+ schema: string;
38
+ readmeComponent?: LaneReadmeComponent;
39
+ forkedFrom?: LaneId;
40
+ _hash: string;
41
+ isNew: boolean;
42
+ hasChanged: boolean;
43
+ /**
44
+ * populated when a user clicks on "update" in the UI. it's a list of components that are dependents on the
45
+ * components in the lane. their dependencies are updated according to the lane.
46
+ * from the CLI perspective, it's added by "bit _snap" and merged by "bit _merge-lane".
47
+ * otherwise, the user is not aware of it. it's not imported to the workspace and the objects are not fetched.
48
+ */
49
+ updateDependents?: ComponentID[];
50
+ private overrideUpdateDependents?;
51
+ constructor(props: LaneProps);
52
+ id(): string;
53
+ hash(): Ref;
54
+ changeName(name: string): void;
55
+ changeScope(scope: string): void;
56
+ refs(): Ref[];
57
+ validateBeforePersisting(str: string): void;
58
+ toObject(): import("lodash").Dictionary<string | boolean | string[] | {
59
+ scope: string;
60
+ name: string;
61
+ } | Log | {
62
+ isDeleted?: true | undefined;
63
+ id: {
64
+ scope: string;
65
+ name: string;
66
+ };
67
+ head: string;
68
+ }[] | {
69
+ id: {
70
+ scope: string;
71
+ name: string;
72
+ };
73
+ head: string | null;
74
+ } | undefined>;
75
+ static from(props: LaneProps): Lane;
76
+ static create(name: string, scope: string, forkedFrom?: LaneId, bitCloudUser?: {
77
+ username?: string;
78
+ email?: string;
79
+ profileImage?: string;
80
+ }): Lane;
81
+ static parse(contents: string, hash: string): Lane;
82
+ toBuffer(pretty?: boolean): Buffer;
83
+ addComponent(component: LaneComponent): void;
84
+ removeComponentFromUpdateDependentsIfExist(componentId: ComponentID): void;
85
+ addComponentToUpdateDependents(componentId: ComponentID): void;
86
+ removeAllUpdateDependents(): void;
87
+ shouldOverrideUpdateDependents(): boolean | undefined;
88
+ /**
89
+ * !!! important !!!
90
+ * this should get called only on a "temp lane", such as running "bit _snap", which the scope gets destroys after the
91
+ * command is done. when _scope exports the lane, this "overrideUpdateDependents" is not saved to the remote-scope.
92
+ *
93
+ * on a user local lane object, this prop should never be true. otherwise, it'll override the remote-scope data.
94
+ */
95
+ setOverrideUpdateDependents(overrideUpdateDependents: boolean): void;
96
+ removeComponent(id: ComponentID): boolean;
97
+ getComponent(id: ComponentID): LaneComponent | undefined;
98
+ getComponentHead(bitId: ComponentID): Ref | null;
99
+ setLaneComponents(laneComponents: LaneComponent[]): void;
100
+ setReadmeComponent(id?: ComponentID): void;
101
+ isFullyMerged(scope: Scope): Promise<boolean>;
102
+ getMergedAndUnmergedIds(scope: Scope): Promise<{
103
+ merged: ComponentID[];
104
+ unmerged: ComponentID[];
105
+ }>;
106
+ /**
107
+ * @deprecated use toComponentIds instead
108
+ */
109
+ toBitIds(): ComponentIdList;
110
+ toComponentIds(): ComponentIdList;
111
+ toComponentIdsIncludeUpdateDependents(): ComponentIdList;
112
+ toLaneId(): LaneId;
113
+ collectObjectsById(repo: Repository): Promise<Array<{
114
+ id: ComponentID;
115
+ objects: BitObject[];
116
+ }>>;
117
+ includeDeletedData(): boolean;
118
+ setSchemaToSupportDeletedData(): void;
119
+ setSchemaToNotSupportDeletedData(): void;
120
+ getCompHeadIncludeUpdateDependents(componentId: ComponentID): Ref | undefined;
121
+ validate(): void;
122
+ isEqual(lane: Lane): boolean;
123
+ clone(): Lane;
124
+ }
@@ -0,0 +1,463 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function _uuid() {
8
+ const data = require("uuid");
9
+ _uuid = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _semver() {
15
+ const data = require("semver");
16
+ _semver = 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 _bitError() {
29
+ const data = require("@teambit/bit-error");
30
+ _bitError = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _componentId() {
36
+ const data = require("@teambit/component-id");
37
+ _componentId = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ function _componentVersion() {
43
+ const data = require("@teambit/component-version");
44
+ _componentVersion = function () {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
49
+ function _laneId() {
50
+ const data = require("@teambit/lane-id");
51
+ _laneId = function () {
52
+ return data;
53
+ };
54
+ return data;
55
+ }
56
+ function _legacy() {
57
+ const data = require("@teambit/legacy.constants");
58
+ _legacy = function () {
59
+ return data;
60
+ };
61
+ return data;
62
+ }
63
+ function _legacyCli() {
64
+ const data = require("@teambit/legacy.cli.error");
65
+ _legacyCli = function () {
66
+ return data;
67
+ };
68
+ return data;
69
+ }
70
+ function _legacy2() {
71
+ const data = require("@teambit/legacy.logger");
72
+ _legacy2 = function () {
73
+ return data;
74
+ };
75
+ return data;
76
+ }
77
+ function _legacy3() {
78
+ const data = require("@teambit/legacy.utils");
79
+ _legacy3 = function () {
80
+ return data;
81
+ };
82
+ return data;
83
+ }
84
+ function _toolboxCrypto() {
85
+ const data = require("@teambit/toolbox.crypto.sha1");
86
+ _toolboxCrypto = function () {
87
+ return data;
88
+ };
89
+ return data;
90
+ }
91
+ function _component() {
92
+ const data = require("@teambit/component.snap-distance");
93
+ _component = function () {
94
+ return data;
95
+ };
96
+ return data;
97
+ }
98
+ function _objects() {
99
+ const data = require("../objects");
100
+ _objects = function () {
101
+ return data;
102
+ };
103
+ return data;
104
+ }
105
+ function globalConfig() {
106
+ const data = _interopRequireWildcard(require("@teambit/legacy.global-config"));
107
+ globalConfig = function () {
108
+ return data;
109
+ };
110
+ return data;
111
+ }
112
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
113
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
114
+ 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; }
115
+ 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; }
116
+ 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; }
117
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
118
+ 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); }
119
+ const OLD_LANE_SCHEMA = '0.0.0';
120
+ const SCHEMA_INCLUDING_DELETED_COMPONENTS_DATA = '1.0.0';
121
+ const CURRENT_LANE_SCHEMA = SCHEMA_INCLUDING_DELETED_COMPONENTS_DATA;
122
+ class Lane extends _objects().BitObject {
123
+ constructor(props) {
124
+ super();
125
+ _defineProperty(this, "name", void 0);
126
+ _defineProperty(this, "scope", void 0);
127
+ _defineProperty(this, "components", void 0);
128
+ _defineProperty(this, "log", void 0);
129
+ _defineProperty(this, "schema", void 0);
130
+ _defineProperty(this, "readmeComponent", void 0);
131
+ _defineProperty(this, "forkedFrom", void 0);
132
+ _defineProperty(this, "_hash", void 0);
133
+ // reason for the underscore prefix is that we already have hash as a method
134
+ _defineProperty(this, "isNew", false);
135
+ // doesn't get saved in the object. only needed for in-memory instance
136
+ _defineProperty(this, "hasChanged", false);
137
+ // doesn't get saved in the object. only needed for in-memory instance
138
+ /**
139
+ * populated when a user clicks on "update" in the UI. it's a list of components that are dependents on the
140
+ * components in the lane. their dependencies are updated according to the lane.
141
+ * from the CLI perspective, it's added by "bit _snap" and merged by "bit _merge-lane".
142
+ * otherwise, the user is not aware of it. it's not imported to the workspace and the objects are not fetched.
143
+ */
144
+ _defineProperty(this, "updateDependents", void 0);
145
+ _defineProperty(this, "overrideUpdateDependents", void 0);
146
+ if (!props.name) throw new TypeError('Lane constructor expects to get a name parameter');
147
+ this.name = props.name;
148
+ this.scope = props.scope;
149
+ this.components = props.components || [];
150
+ this.log = props.log || {
151
+ date: Date.now().toString()
152
+ };
153
+ this._hash = props.hash;
154
+ this.readmeComponent = props.readmeComponent;
155
+ this.forkedFrom = props.forkedFrom;
156
+ this.schema = props.schema || OLD_LANE_SCHEMA;
157
+ this.updateDependents = props.updateDependents;
158
+ this.overrideUpdateDependents = props.overrideUpdateDependents;
159
+ }
160
+ id() {
161
+ return this.scope + _laneId().LANE_REMOTE_DELIMITER + this.name;
162
+ }
163
+ hash() {
164
+ if (!this._hash) {
165
+ throw new Error('hash is missing from a Lane object');
166
+ }
167
+ return new (_objects().Ref)(this._hash);
168
+ }
169
+ changeName(name) {
170
+ this.name = name;
171
+ this.hasChanged = true;
172
+ }
173
+ changeScope(scope) {
174
+ this.scope = scope;
175
+ this.hasChanged = true;
176
+ }
177
+ refs() {
178
+ return this.components.map(c => c.head);
179
+ }
180
+ validateBeforePersisting(str) {
181
+ _legacy2().logger.debug(`validating lane object: ${this.hash().toString()} ${this.id()}`);
182
+ const lane = Lane.parse(str, this.hash().toString());
183
+ lane.validate();
184
+ }
185
+ toObject() {
186
+ const obj = (0, _lodash().pickBy)({
187
+ name: this.name,
188
+ scope: this.scope,
189
+ components: this.components.map(component => _objectSpread({
190
+ id: {
191
+ scope: component.id.scope,
192
+ name: component.id.fullName
193
+ },
194
+ head: component.head.toString()
195
+ }, component.isDeleted && {
196
+ isDeleted: component.isDeleted
197
+ })),
198
+ log: this.log,
199
+ readmeComponent: this.readmeComponent && {
200
+ id: {
201
+ scope: this.readmeComponent.id.scope,
202
+ name: this.readmeComponent.id.fullName
203
+ },
204
+ head: this.readmeComponent.head?.toString() ?? null
205
+ },
206
+ forkedFrom: this.forkedFrom && this.forkedFrom.toObject(),
207
+ schema: this.schema,
208
+ updateDependents: this.updateDependents?.map(c => c.toString()),
209
+ overrideUpdateDependents: this.overrideUpdateDependents
210
+ }, val => !!val);
211
+ return obj;
212
+ }
213
+ static from(props) {
214
+ return new Lane(props);
215
+ }
216
+ static create(name, scope, forkedFrom, bitCloudUser) {
217
+ const log = {
218
+ date: Date.now().toString(),
219
+ username: bitCloudUser?.username || globalConfig().getSync(_legacy().CFG_USER_NAME_KEY),
220
+ email: bitCloudUser?.email || globalConfig().getSync(_legacy().CFG_USER_EMAIL_KEY),
221
+ profileImage: bitCloudUser?.profileImage
222
+ };
223
+ const lane = new Lane({
224
+ name,
225
+ scope,
226
+ hash: (0, _toolboxCrypto().sha1)((0, _uuid().v4)()),
227
+ log,
228
+ forkedFrom,
229
+ schema: CURRENT_LANE_SCHEMA
230
+ });
231
+ lane.isNew = true;
232
+ lane.hasChanged = true;
233
+ return lane;
234
+ }
235
+ static parse(contents, hash) {
236
+ const laneObject = JSON.parse(contents);
237
+ return Lane.from({
238
+ name: laneObject.name,
239
+ scope: laneObject.scope,
240
+ log: laneObject.log,
241
+ components: laneObject.components.map(component => ({
242
+ id: _componentId().ComponentID.fromObject({
243
+ scope: component.id.scope,
244
+ name: component.id.name
245
+ }),
246
+ head: new (_objects().Ref)(component.head),
247
+ isDeleted: component.isDeleted
248
+ })),
249
+ readmeComponent: laneObject.readmeComponent && {
250
+ id: _componentId().ComponentID.fromObject({
251
+ scope: laneObject.readmeComponent.id.scope,
252
+ name: laneObject.readmeComponent.id.name
253
+ }),
254
+ head: laneObject.readmeComponent.head && new (_objects().Ref)(laneObject.readmeComponent.head)
255
+ },
256
+ forkedFrom: laneObject.forkedFrom && _laneId().LaneId.from(laneObject.forkedFrom.name, laneObject.forkedFrom.scope),
257
+ updateDependents: laneObject.updateDependents?.map(c => _componentId().ComponentID.fromString(c)),
258
+ overrideUpdateDependents: laneObject.overrideUpdateDependents,
259
+ hash: laneObject.hash || hash,
260
+ schema: laneObject.schema
261
+ });
262
+ }
263
+ toBuffer(pretty) {
264
+ const args = (0, _legacy3().getStringifyArgs)(pretty);
265
+ const obj = this.toObject();
266
+ const str = JSON.stringify(obj, ...args);
267
+ if (this.validateBeforePersist) this.validateBeforePersisting(str);
268
+ return Buffer.from(str);
269
+ }
270
+ addComponent(component) {
271
+ const existsComponent = this.getComponent(component.id);
272
+ if (existsComponent) {
273
+ if (!existsComponent.head.isEqual(component.head)) this.hasChanged = true;
274
+ existsComponent.id = component.id;
275
+ existsComponent.head = component.head;
276
+ existsComponent.isDeleted = component.isDeleted;
277
+ } else {
278
+ _legacy2().logger.debug(`Lane.addComponent, adding component ${component.id.toString()} to lane ${this.id()}`);
279
+ this.components.push(component);
280
+ this.hasChanged = true;
281
+ }
282
+ }
283
+ removeComponentFromUpdateDependentsIfExist(componentId) {
284
+ const updateDependentsList = _componentId().ComponentIdList.fromArray(this.updateDependents || []);
285
+ const exist = updateDependentsList.searchWithoutVersion(componentId);
286
+ if (!exist) return;
287
+ this.updateDependents = updateDependentsList.removeIfExist(exist);
288
+ if (!this.updateDependents.length) this.updateDependents = undefined;
289
+ this.hasChanged = true;
290
+ }
291
+ addComponentToUpdateDependents(componentId) {
292
+ this.removeComponentFromUpdateDependentsIfExist(componentId);
293
+ (this.updateDependents ||= []).push(componentId);
294
+ this.hasChanged = true;
295
+ }
296
+ removeAllUpdateDependents() {
297
+ if (this.updateDependents?.length) return;
298
+ this.updateDependents = undefined;
299
+ this.hasChanged = true;
300
+ }
301
+ shouldOverrideUpdateDependents() {
302
+ return this.overrideUpdateDependents;
303
+ }
304
+ /**
305
+ * !!! important !!!
306
+ * this should get called only on a "temp lane", such as running "bit _snap", which the scope gets destroys after the
307
+ * command is done. when _scope exports the lane, this "overrideUpdateDependents" is not saved to the remote-scope.
308
+ *
309
+ * on a user local lane object, this prop should never be true. otherwise, it'll override the remote-scope data.
310
+ */
311
+ setOverrideUpdateDependents(overrideUpdateDependents) {
312
+ this.overrideUpdateDependents = overrideUpdateDependents;
313
+ this.hasChanged = true;
314
+ }
315
+ removeComponent(id) {
316
+ const existsComponent = this.getComponent(id);
317
+ if (!existsComponent) return false;
318
+ this.components = this.components.filter(c => !c.id.isEqualWithoutVersion(id));
319
+ this.hasChanged = true;
320
+ return true;
321
+ }
322
+ getComponent(id) {
323
+ return this.components.find(c => c.id.isEqualWithoutVersion(id));
324
+ }
325
+ getComponentHead(bitId) {
326
+ const found = this.components.find(c => c.id.isEqual(bitId));
327
+ if (found) return found.head;
328
+ return null;
329
+ }
330
+ setLaneComponents(laneComponents) {
331
+ // this gets called when adding lane-components from other lanes/remotes, so it's better to
332
+ // clone the objects to not change the original data.
333
+ this.components = laneComponents.map(c => ({
334
+ id: c.id.clone(),
335
+ head: c.head.clone()
336
+ }));
337
+ this.hasChanged = true;
338
+ }
339
+ setReadmeComponent(id) {
340
+ const previousReadme = this.readmeComponent;
341
+ if (!id) {
342
+ this.readmeComponent = undefined;
343
+ if (previousReadme) this.hasChanged = true;
344
+ return;
345
+ }
346
+ const readmeComponent = this.getComponent(id);
347
+ if (!readmeComponent) {
348
+ this.readmeComponent = {
349
+ id,
350
+ head: null
351
+ };
352
+ } else {
353
+ this.readmeComponent = readmeComponent;
354
+ }
355
+ if (!previousReadme || !previousReadme.id.isEqual(id) || previousReadme.head?.toString() !== this.readmeComponent.head?.toString()) {
356
+ this.hasChanged = true;
357
+ }
358
+ }
359
+ async isFullyMerged(scope) {
360
+ const {
361
+ unmerged
362
+ } = await this.getMergedAndUnmergedIds(scope);
363
+ return unmerged.length === 0;
364
+ }
365
+ async getMergedAndUnmergedIds(scope) {
366
+ const merged = [];
367
+ const unmerged = [];
368
+ await Promise.all(this.components.map(async component => {
369
+ const modelComponent = await scope.getModelComponentIfExist(component.id);
370
+ if (!modelComponent) {
371
+ unmerged.push(component.id);
372
+ return;
373
+ }
374
+ const startTraverseFrom = modelComponent.getHead() || null; // it's important to have it as null and not as undefined, see hasVersionByRef
375
+ const headExist = await (0, _component().hasVersionByRef)(modelComponent, component.head, scope.objects, startTraverseFrom);
376
+ if (headExist) merged.push(component.id);else unmerged.push(component.id);
377
+ }));
378
+ return {
379
+ merged,
380
+ unmerged
381
+ };
382
+ }
383
+ /**
384
+ * @deprecated use toComponentIds instead
385
+ */
386
+ toBitIds() {
387
+ return this.toComponentIds();
388
+ }
389
+ toComponentIds() {
390
+ return _componentId().ComponentIdList.fromArray(this.components.map(c => c.id.changeVersion(c.head.toString())));
391
+ }
392
+ toComponentIdsIncludeUpdateDependents() {
393
+ return _componentId().ComponentIdList.fromArray(this.toComponentIds().concat(this.updateDependents || []));
394
+ }
395
+ toLaneId() {
396
+ return new (_laneId().LaneId)({
397
+ scope: this.scope,
398
+ name: this.name
399
+ });
400
+ }
401
+ collectObjectsById(repo) {
402
+ return Promise.all(this.components.map(async component => {
403
+ const headVersion = await component.head.load(repo);
404
+ const objects = [headVersion, ...headVersion.collect(repo)];
405
+ return {
406
+ id: component.id,
407
+ objects
408
+ };
409
+ }));
410
+ }
411
+ includeDeletedData() {
412
+ return (0, _semver().gte)(this.schema, SCHEMA_INCLUDING_DELETED_COMPONENTS_DATA);
413
+ }
414
+ setSchemaToSupportDeletedData() {
415
+ this.schema = SCHEMA_INCLUDING_DELETED_COMPONENTS_DATA;
416
+ this.hasChanged = true;
417
+ }
418
+ setSchemaToNotSupportDeletedData() {
419
+ this.schema = OLD_LANE_SCHEMA;
420
+ this.hasChanged = true;
421
+ }
422
+ getCompHeadIncludeUpdateDependents(componentId) {
423
+ const comp = this.getComponent(componentId);
424
+ if (comp) return comp.head;
425
+ const fromUpdateDependents = this.updateDependents?.find(c => c.isEqualWithoutVersion(componentId));
426
+ if (fromUpdateDependents) return _objects().Ref.from(fromUpdateDependents.version);
427
+ return undefined;
428
+ }
429
+ validate() {
430
+ const message = `unable to save Lane object "${this.id()}"`;
431
+ const bitIds = this.toComponentIds();
432
+ this.components.forEach(component => {
433
+ if (bitIds.filterWithoutVersion(component.id).length > 1) {
434
+ throw new (_legacyCli().ValidationError)(`${message}, the following component is duplicated "${component.id.fullName}"`);
435
+ }
436
+ if (!(0, _componentVersion().isSnap)(component.head.hash)) {
437
+ throw new (_legacyCli().ValidationError)(`${message}, lane component ${component.id.toStringWithoutVersion()} head should be a hash, got ${component.head.hash}`);
438
+ }
439
+ });
440
+ if (this.name === _laneId().DEFAULT_LANE) {
441
+ throw new (_bitError().BitError)(`${message}, this name is reserved as the default lane`);
442
+ }
443
+ if (this.name === _legacy().PREVIOUS_DEFAULT_LANE) {
444
+ throw new (_bitError().BitError)(`${message}, this name is reserved as the old default lane`);
445
+ }
446
+ }
447
+ isEqual(lane) {
448
+ if (this.id() !== lane.id()) return false;
449
+ const thisComponents = this.toComponentIds().toStringArray().sort();
450
+ const otherComponents = lane.toComponentIds().toStringArray().sort();
451
+ return (0, _lodash().isEqual)(thisComponents, otherComponents);
452
+ }
453
+ clone() {
454
+ return new Lane(_objectSpread(_objectSpread({}, this), {}, {
455
+ hash: this._hash,
456
+ overrideUpdateDependents: this.overrideUpdateDependents,
457
+ components: (0, _lodash().cloneDeep)(this.components)
458
+ }));
459
+ }
460
+ }
461
+ exports.default = Lane;
462
+
463
+ //# sourceMappingURL=lane.js.map