@teambit/objects 0.0.0-00042bc99514ea12d897f81bcd0181e2b034c615
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/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 +46 -0
- package/dist/models/dependencies-graph.js +105 -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 +74 -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 +43 -0
- package/dist/models/lane-history.js +131 -0
- package/dist/models/lane-history.js.map +1 -0
- package/dist/models/lane-history.spec.d.ts +1 -0
- package/dist/models/lane-history.spec.js +46 -0
- package/dist/models/lane-history.spec.js.map +1 -0
- package/dist/models/lane.d.ts +128 -0
- package/dist/models/lane.js +485 -0
- package/dist/models/lane.js.map +1 -0
- package/dist/models/model-component.d.ts +338 -0
- package/dist/models/model-component.js +1509 -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 +68 -0
- package/dist/models/scopeMeta.js.map +1 -0
- package/dist/models/source.d.ts +10 -0
- package/dist/models/source.js +42 -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 +296 -0
- package/dist/models/version-history.js.map +1 -0
- package/dist/models/version.d.ts +288 -0
- package/dist/models/version.js +780 -0
- package/dist/models/version.js.map +1 -0
- package/dist/models/version.spec.d.ts +1 -0
- package/dist/models/version.spec.js +332 -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 +58 -0
- package/dist/objects/object-list.js +389 -0
- package/dist/objects/object-list.js.map +1 -0
- package/dist/objects/object.d.ts +35 -0
- package/dist/objects/object.js +189 -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 +203 -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 +145 -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.d.ts +165 -0
- package/dist/objects/repository.js +866 -0
- package/dist/objects/repository.js.map +1 -0
- package/dist/objects/scope-index.d.ts +74 -0
- package/dist/objects/scope-index.js +255 -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-1781548568469.js +7 -0
- package/fixtures/version-model-extended.json +48 -0
- package/fixtures/version-model-object.json +87 -0
- package/models/dependencies-graph.ts +120 -0
- package/models/detach-heads.ts +79 -0
- package/models/export-metadata.ts +56 -0
- package/models/index.ts +11 -0
- package/models/lane-history.spec.ts +35 -0
- package/models/lane-history.ts +131 -0
- package/models/lane.ts +400 -0
- package/models/model-component.spec.ts +55 -0
- package/models/model-component.ts +1522 -0
- package/models/scopeMeta.ts +58 -0
- package/models/source.ts +31 -0
- package/models/symlink.ts +66 -0
- package/models/version-history.ts +283 -0
- package/models/version.spec.ts +280 -0
- package/models/version.ts +821 -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 +327 -0
- package/objects/object.ts +152 -0
- package/objects/objects-readable-generator.ts +174 -0
- package/objects/raw-object.ts +132 -0
- package/objects/ref.ts +45 -0
- package/objects/repository.ts +780 -0
- package/objects/scope-index.spec.ts +95 -0
- package/objects/scope-index.ts +197 -0
- package/package.json +97 -0
- package/types/asset.d.ts +41 -0
- package/types/style.d.ts +42 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { ComponentID, ComponentIdList } from '@teambit/component-id';
|
|
2
|
+
import { LaneId } from '@teambit/lane-id';
|
|
3
|
+
import type { Scope } from '@teambit/legacy.scope';
|
|
4
|
+
import type { Repository } from '../objects';
|
|
5
|
+
import { BitObject, Ref } from '../objects';
|
|
6
|
+
export type Log = {
|
|
7
|
+
date: string;
|
|
8
|
+
username?: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
profileImage?: string;
|
|
11
|
+
};
|
|
12
|
+
export type LaneProps = {
|
|
13
|
+
name: string;
|
|
14
|
+
scope: string;
|
|
15
|
+
log: Log;
|
|
16
|
+
components?: LaneComponent[];
|
|
17
|
+
hash: string;
|
|
18
|
+
schema?: string;
|
|
19
|
+
readmeComponent?: LaneReadmeComponent;
|
|
20
|
+
forkedFrom?: LaneId;
|
|
21
|
+
updateDependents?: ComponentID[];
|
|
22
|
+
overrideUpdateDependents?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type LaneComponent = {
|
|
25
|
+
id: ComponentID;
|
|
26
|
+
head: Ref;
|
|
27
|
+
isDeleted?: boolean;
|
|
28
|
+
};
|
|
29
|
+
export type LaneReadmeComponent = {
|
|
30
|
+
id: ComponentID;
|
|
31
|
+
head: Ref | null;
|
|
32
|
+
};
|
|
33
|
+
export default class Lane extends BitObject {
|
|
34
|
+
name: string;
|
|
35
|
+
scope: string;
|
|
36
|
+
components: LaneComponent[];
|
|
37
|
+
log: Log;
|
|
38
|
+
schema: string;
|
|
39
|
+
readmeComponent?: LaneReadmeComponent;
|
|
40
|
+
forkedFrom?: LaneId;
|
|
41
|
+
_hash: string;
|
|
42
|
+
isNew: boolean;
|
|
43
|
+
hasChanged: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* components that are dependents of components in the lane and need to be re-snapped against the
|
|
46
|
+
* lane's heads. populated by the bare-scope cascade producer (UI "snap updates" / `bit _snap`)
|
|
47
|
+
* and by `bit _merge-lane`. these entries are part of the lane's graph (Ripple CI builds them,
|
|
48
|
+
* merge engine refreshes them) but are intentionally hidden from workspace-facing flows
|
|
49
|
+
* (`bit status`, `bit compile`, `bit install`, the bitmap).
|
|
50
|
+
*/
|
|
51
|
+
updateDependents?: ComponentID[];
|
|
52
|
+
private overrideUpdateDependents?;
|
|
53
|
+
constructor(props: LaneProps);
|
|
54
|
+
id(): string;
|
|
55
|
+
hash(): Ref;
|
|
56
|
+
changeName(name: string): void;
|
|
57
|
+
changeScope(scope: string): void;
|
|
58
|
+
refs(): Ref[];
|
|
59
|
+
validateBeforePersisting(str: string): void;
|
|
60
|
+
toObject(): import("lodash").Dictionary<string | boolean | string[] | {
|
|
61
|
+
scope: string;
|
|
62
|
+
name: string;
|
|
63
|
+
} | {
|
|
64
|
+
isDeleted?: true | undefined;
|
|
65
|
+
id: {
|
|
66
|
+
scope: string;
|
|
67
|
+
name: string;
|
|
68
|
+
};
|
|
69
|
+
head: string;
|
|
70
|
+
}[] | Log | {
|
|
71
|
+
id: {
|
|
72
|
+
scope: string;
|
|
73
|
+
name: string;
|
|
74
|
+
};
|
|
75
|
+
head: string | null;
|
|
76
|
+
} | undefined>;
|
|
77
|
+
static from(props: LaneProps): Lane;
|
|
78
|
+
static create(name: string, scope: string, forkedFrom?: LaneId, bitCloudUser?: {
|
|
79
|
+
username?: string;
|
|
80
|
+
email?: string;
|
|
81
|
+
profileImage?: string;
|
|
82
|
+
}): Lane;
|
|
83
|
+
static parse(contents: string, hash: string): Lane;
|
|
84
|
+
toBuffer(pretty?: boolean): Buffer<ArrayBuffer>;
|
|
85
|
+
addComponent(component: LaneComponent): void;
|
|
86
|
+
findUpdateDependent(componentId: ComponentID): ComponentID | undefined;
|
|
87
|
+
getUpdateDependentAsLaneComponent(componentId: ComponentID): LaneComponent | undefined;
|
|
88
|
+
removeComponentFromUpdateDependentsIfExist(componentId: ComponentID): void;
|
|
89
|
+
addComponentToUpdateDependents(componentId: ComponentID): void;
|
|
90
|
+
removeAllUpdateDependents(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Signals an explicit `_snap --update-dependents` insertion. On export, the receiving scope
|
|
93
|
+
* gates its "add this new hidden entry" branch on this flag so a stale workspace lane can't
|
|
94
|
+
* resurrect entries the Cloud UI dropped. Workspace cascades — which only update existing
|
|
95
|
+
* entries — deliberately do NOT set the flag. The field is also serialized by `Lane.toObject`
|
|
96
|
+
* for older remotes that gate their pre-diverge-check override branch on it.
|
|
97
|
+
*/
|
|
98
|
+
setOverrideUpdateDependents(overrideUpdateDependents: boolean): void;
|
|
99
|
+
shouldOverrideUpdateDependents(): boolean;
|
|
100
|
+
removeComponent(id: ComponentID): boolean;
|
|
101
|
+
getComponent(id: ComponentID): LaneComponent | undefined;
|
|
102
|
+
getComponentHead(bitId: ComponentID): Ref | null;
|
|
103
|
+
setLaneComponents(laneComponents: LaneComponent[]): void;
|
|
104
|
+
setReadmeComponent(id?: ComponentID): void;
|
|
105
|
+
isFullyMerged(scope: Scope): Promise<boolean>;
|
|
106
|
+
getMergedAndUnmergedIds(scope: Scope): Promise<{
|
|
107
|
+
merged: ComponentID[];
|
|
108
|
+
unmerged: ComponentID[];
|
|
109
|
+
}>;
|
|
110
|
+
/**
|
|
111
|
+
* @deprecated use toComponentIds instead
|
|
112
|
+
*/
|
|
113
|
+
toBitIds(): ComponentIdList;
|
|
114
|
+
toComponentIds(): ComponentIdList;
|
|
115
|
+
toComponentIdsIncludeUpdateDependents(): ComponentIdList;
|
|
116
|
+
toLaneId(): LaneId;
|
|
117
|
+
collectObjectsById(repo: Repository): Promise<Array<{
|
|
118
|
+
id: ComponentID;
|
|
119
|
+
objects: BitObject[];
|
|
120
|
+
}>>;
|
|
121
|
+
includeDeletedData(): boolean;
|
|
122
|
+
setSchemaToSupportDeletedData(): void;
|
|
123
|
+
setSchemaToNotSupportDeletedData(): void;
|
|
124
|
+
getCompHeadIncludeUpdateDependents(componentId: ComponentID): Ref | undefined;
|
|
125
|
+
validate(): void;
|
|
126
|
+
isEqual(lane: Lane): boolean;
|
|
127
|
+
clone(): Lane;
|
|
128
|
+
}
|
|
@@ -0,0 +1,485 @@
|
|
|
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 _configStore() {
|
|
106
|
+
const data = require("@teambit/config-store");
|
|
107
|
+
_configStore = function () {
|
|
108
|
+
return data;
|
|
109
|
+
};
|
|
110
|
+
return data;
|
|
111
|
+
}
|
|
112
|
+
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; }
|
|
113
|
+
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; }
|
|
114
|
+
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; }
|
|
115
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
116
|
+
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); }
|
|
117
|
+
const OLD_LANE_SCHEMA = '0.0.0';
|
|
118
|
+
const SCHEMA_INCLUDING_DELETED_COMPONENTS_DATA = '1.0.0';
|
|
119
|
+
const CURRENT_LANE_SCHEMA = SCHEMA_INCLUDING_DELETED_COMPONENTS_DATA;
|
|
120
|
+
class Lane extends _objects().BitObject {
|
|
121
|
+
constructor(props) {
|
|
122
|
+
super();
|
|
123
|
+
_defineProperty(this, "name", void 0);
|
|
124
|
+
_defineProperty(this, "scope", void 0);
|
|
125
|
+
_defineProperty(this, "components", void 0);
|
|
126
|
+
_defineProperty(this, "log", void 0);
|
|
127
|
+
_defineProperty(this, "schema", void 0);
|
|
128
|
+
_defineProperty(this, "readmeComponent", void 0);
|
|
129
|
+
_defineProperty(this, "forkedFrom", void 0);
|
|
130
|
+
_defineProperty(this, "_hash", void 0);
|
|
131
|
+
// reason for the underscore prefix is that we already have hash as a method
|
|
132
|
+
_defineProperty(this, "isNew", false);
|
|
133
|
+
// doesn't get saved in the object. only needed for in-memory instance
|
|
134
|
+
_defineProperty(this, "hasChanged", false);
|
|
135
|
+
// doesn't get saved in the object. only needed for in-memory instance
|
|
136
|
+
/**
|
|
137
|
+
* components that are dependents of components in the lane and need to be re-snapped against the
|
|
138
|
+
* lane's heads. populated by the bare-scope cascade producer (UI "snap updates" / `bit _snap`)
|
|
139
|
+
* and by `bit _merge-lane`. these entries are part of the lane's graph (Ripple CI builds them,
|
|
140
|
+
* merge engine refreshes them) but are intentionally hidden from workspace-facing flows
|
|
141
|
+
* (`bit status`, `bit compile`, `bit install`, the bitmap).
|
|
142
|
+
*/
|
|
143
|
+
_defineProperty(this, "updateDependents", void 0);
|
|
144
|
+
_defineProperty(this, "overrideUpdateDependents", void 0);
|
|
145
|
+
if (!props.name) throw new TypeError('Lane constructor expects to get a name parameter');
|
|
146
|
+
this.name = props.name;
|
|
147
|
+
this.scope = props.scope;
|
|
148
|
+
this.components = props.components || [];
|
|
149
|
+
this.log = props.log || {
|
|
150
|
+
date: Date.now().toString()
|
|
151
|
+
};
|
|
152
|
+
this._hash = props.hash;
|
|
153
|
+
this.readmeComponent = props.readmeComponent;
|
|
154
|
+
this.forkedFrom = props.forkedFrom;
|
|
155
|
+
this.schema = props.schema || OLD_LANE_SCHEMA;
|
|
156
|
+
this.updateDependents = props.updateDependents;
|
|
157
|
+
this.overrideUpdateDependents = props.overrideUpdateDependents;
|
|
158
|
+
}
|
|
159
|
+
id() {
|
|
160
|
+
return this.scope + _laneId().LANE_REMOTE_DELIMITER + this.name;
|
|
161
|
+
}
|
|
162
|
+
hash() {
|
|
163
|
+
if (!this._hash) {
|
|
164
|
+
throw new Error('hash is missing from a Lane object');
|
|
165
|
+
}
|
|
166
|
+
return new (_objects().Ref)(this._hash);
|
|
167
|
+
}
|
|
168
|
+
changeName(name) {
|
|
169
|
+
this.name = name;
|
|
170
|
+
this.hasChanged = true;
|
|
171
|
+
}
|
|
172
|
+
changeScope(scope) {
|
|
173
|
+
this.scope = scope;
|
|
174
|
+
this.hasChanged = true;
|
|
175
|
+
}
|
|
176
|
+
refs() {
|
|
177
|
+
return this.components.map(c => c.head);
|
|
178
|
+
}
|
|
179
|
+
validateBeforePersisting(str) {
|
|
180
|
+
_legacy2().logger.debug(`validating lane object: ${this.hash().toString()} ${this.id()}`);
|
|
181
|
+
const lane = Lane.parse(str, this.hash().toString());
|
|
182
|
+
lane.validate();
|
|
183
|
+
}
|
|
184
|
+
toObject() {
|
|
185
|
+
const obj = (0, _lodash().pickBy)({
|
|
186
|
+
name: this.name,
|
|
187
|
+
scope: this.scope,
|
|
188
|
+
components: this.components.map(component => _objectSpread({
|
|
189
|
+
id: {
|
|
190
|
+
scope: component.id.scope,
|
|
191
|
+
name: component.id.fullName
|
|
192
|
+
},
|
|
193
|
+
head: component.head.toString()
|
|
194
|
+
}, component.isDeleted && {
|
|
195
|
+
isDeleted: component.isDeleted
|
|
196
|
+
})),
|
|
197
|
+
log: this.log,
|
|
198
|
+
readmeComponent: this.readmeComponent && {
|
|
199
|
+
id: {
|
|
200
|
+
scope: this.readmeComponent.id.scope,
|
|
201
|
+
name: this.readmeComponent.id.fullName
|
|
202
|
+
},
|
|
203
|
+
head: this.readmeComponent.head?.toString() ?? null
|
|
204
|
+
},
|
|
205
|
+
forkedFrom: this.forkedFrom && this.forkedFrom.toObject(),
|
|
206
|
+
schema: this.schema,
|
|
207
|
+
updateDependents: this.updateDependents?.map(c => c.toString()),
|
|
208
|
+
overrideUpdateDependents: this.overrideUpdateDependents
|
|
209
|
+
}, val => !!val);
|
|
210
|
+
return obj;
|
|
211
|
+
}
|
|
212
|
+
static from(props) {
|
|
213
|
+
return new Lane(props);
|
|
214
|
+
}
|
|
215
|
+
static create(name, scope, forkedFrom, bitCloudUser) {
|
|
216
|
+
const log = {
|
|
217
|
+
date: Date.now().toString(),
|
|
218
|
+
username: bitCloudUser?.username || (0, _configStore().getConfig)(_legacy().CFG_USER_NAME_KEY),
|
|
219
|
+
email: bitCloudUser?.email || (0, _configStore().getConfig)(_legacy().CFG_USER_EMAIL_KEY),
|
|
220
|
+
profileImage: bitCloudUser?.profileImage
|
|
221
|
+
};
|
|
222
|
+
const lane = new Lane({
|
|
223
|
+
name,
|
|
224
|
+
scope,
|
|
225
|
+
hash: (0, _toolboxCrypto().sha1)((0, _uuid().v4)()),
|
|
226
|
+
log,
|
|
227
|
+
forkedFrom,
|
|
228
|
+
schema: CURRENT_LANE_SCHEMA
|
|
229
|
+
});
|
|
230
|
+
lane.isNew = true;
|
|
231
|
+
lane.hasChanged = true;
|
|
232
|
+
return lane;
|
|
233
|
+
}
|
|
234
|
+
static parse(contents, hash) {
|
|
235
|
+
const laneObject = JSON.parse(contents);
|
|
236
|
+
return Lane.from({
|
|
237
|
+
name: laneObject.name,
|
|
238
|
+
scope: laneObject.scope,
|
|
239
|
+
log: laneObject.log,
|
|
240
|
+
components: laneObject.components.map(component => ({
|
|
241
|
+
id: _componentId().ComponentID.fromObject({
|
|
242
|
+
scope: component.id.scope,
|
|
243
|
+
name: component.id.name
|
|
244
|
+
}),
|
|
245
|
+
head: new (_objects().Ref)(component.head),
|
|
246
|
+
isDeleted: component.isDeleted
|
|
247
|
+
})),
|
|
248
|
+
readmeComponent: laneObject.readmeComponent && {
|
|
249
|
+
id: _componentId().ComponentID.fromObject({
|
|
250
|
+
scope: laneObject.readmeComponent.id.scope,
|
|
251
|
+
name: laneObject.readmeComponent.id.name
|
|
252
|
+
}),
|
|
253
|
+
head: laneObject.readmeComponent.head && new (_objects().Ref)(laneObject.readmeComponent.head)
|
|
254
|
+
},
|
|
255
|
+
forkedFrom: laneObject.forkedFrom && _laneId().LaneId.from(laneObject.forkedFrom.name, laneObject.forkedFrom.scope),
|
|
256
|
+
updateDependents: laneObject.updateDependents?.map(c => _componentId().ComponentID.fromString(c)),
|
|
257
|
+
overrideUpdateDependents: laneObject.overrideUpdateDependents,
|
|
258
|
+
hash: laneObject.hash || hash,
|
|
259
|
+
schema: laneObject.schema
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
toBuffer(pretty) {
|
|
263
|
+
const args = (0, _legacy3().getStringifyArgs)(pretty);
|
|
264
|
+
const obj = this.toObject();
|
|
265
|
+
const str = JSON.stringify(obj, ...args);
|
|
266
|
+
if (this.validateBeforePersist) this.validateBeforePersisting(str);
|
|
267
|
+
return Buffer.from(str);
|
|
268
|
+
}
|
|
269
|
+
addComponent(component) {
|
|
270
|
+
const existsComponent = this.getComponent(component.id);
|
|
271
|
+
if (existsComponent) {
|
|
272
|
+
if (!existsComponent.head.isEqual(component.head) || Boolean(existsComponent.isDeleted) !== Boolean(component.isDeleted)) {
|
|
273
|
+
this.hasChanged = true;
|
|
274
|
+
}
|
|
275
|
+
existsComponent.id = component.id;
|
|
276
|
+
existsComponent.head = component.head;
|
|
277
|
+
existsComponent.isDeleted = component.isDeleted;
|
|
278
|
+
} else {
|
|
279
|
+
_legacy2().logger.debug(`Lane.addComponent, adding component ${component.id.toString()} to lane ${this.id()}`);
|
|
280
|
+
this.components.push(component);
|
|
281
|
+
this.hasChanged = true;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
findUpdateDependent(componentId) {
|
|
285
|
+
return this.updateDependents?.find(c => c.isEqualWithoutVersion(componentId));
|
|
286
|
+
}
|
|
287
|
+
getUpdateDependentAsLaneComponent(componentId) {
|
|
288
|
+
const found = this.findUpdateDependent(componentId);
|
|
289
|
+
if (!found?.version) return undefined;
|
|
290
|
+
return {
|
|
291
|
+
id: found.changeVersion(undefined),
|
|
292
|
+
head: _objects().Ref.from(found.version)
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
removeComponentFromUpdateDependentsIfExist(componentId) {
|
|
296
|
+
if (!this.findUpdateDependent(componentId)) return;
|
|
297
|
+
this.updateDependents = this.updateDependents?.filter(c => !c.isEqualWithoutVersion(componentId));
|
|
298
|
+
if (!this.updateDependents?.length) this.updateDependents = undefined;
|
|
299
|
+
this.hasChanged = true;
|
|
300
|
+
}
|
|
301
|
+
addComponentToUpdateDependents(componentId) {
|
|
302
|
+
if (!componentId.hasVersion()) {
|
|
303
|
+
throw new (_legacyCli().ValidationError)(`Lane.addComponentToUpdateDependents: ${componentId.toString()} is missing a version`);
|
|
304
|
+
}
|
|
305
|
+
this.removeComponentFromUpdateDependentsIfExist(componentId);
|
|
306
|
+
(this.updateDependents ||= []).push(componentId);
|
|
307
|
+
this.hasChanged = true;
|
|
308
|
+
}
|
|
309
|
+
removeAllUpdateDependents() {
|
|
310
|
+
if (!this.updateDependents?.length) return;
|
|
311
|
+
this.updateDependents = undefined;
|
|
312
|
+
this.hasChanged = true;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Signals an explicit `_snap --update-dependents` insertion. On export, the receiving scope
|
|
316
|
+
* gates its "add this new hidden entry" branch on this flag so a stale workspace lane can't
|
|
317
|
+
* resurrect entries the Cloud UI dropped. Workspace cascades — which only update existing
|
|
318
|
+
* entries — deliberately do NOT set the flag. The field is also serialized by `Lane.toObject`
|
|
319
|
+
* for older remotes that gate their pre-diverge-check override branch on it.
|
|
320
|
+
*/
|
|
321
|
+
setOverrideUpdateDependents(overrideUpdateDependents) {
|
|
322
|
+
this.overrideUpdateDependents = overrideUpdateDependents;
|
|
323
|
+
this.hasChanged = true;
|
|
324
|
+
}
|
|
325
|
+
shouldOverrideUpdateDependents() {
|
|
326
|
+
return Boolean(this.overrideUpdateDependents);
|
|
327
|
+
}
|
|
328
|
+
removeComponent(id) {
|
|
329
|
+
const existsComponent = this.getComponent(id);
|
|
330
|
+
if (!existsComponent) return false;
|
|
331
|
+
this.components = this.components.filter(c => !c.id.isEqualWithoutVersion(id));
|
|
332
|
+
this.hasChanged = true;
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
getComponent(id) {
|
|
336
|
+
return this.components.find(c => c.id.isEqualWithoutVersion(id));
|
|
337
|
+
}
|
|
338
|
+
getComponentHead(bitId) {
|
|
339
|
+
const found = this.components.find(c => c.id.isEqual(bitId));
|
|
340
|
+
if (found) return found.head;
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
setLaneComponents(laneComponents) {
|
|
344
|
+
// this gets called when adding lane-components from other lanes/remotes, so it's better to
|
|
345
|
+
// clone the objects to not change the original data.
|
|
346
|
+
this.components = laneComponents.map(c => _objectSpread({
|
|
347
|
+
id: c.id.clone(),
|
|
348
|
+
head: c.head.clone()
|
|
349
|
+
}, c.isDeleted && {
|
|
350
|
+
isDeleted: c.isDeleted
|
|
351
|
+
}));
|
|
352
|
+
this.hasChanged = true;
|
|
353
|
+
}
|
|
354
|
+
setReadmeComponent(id) {
|
|
355
|
+
const previousReadme = this.readmeComponent;
|
|
356
|
+
if (!id) {
|
|
357
|
+
this.readmeComponent = undefined;
|
|
358
|
+
if (previousReadme) this.hasChanged = true;
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const readmeComponent = this.getComponent(id);
|
|
362
|
+
if (!readmeComponent) {
|
|
363
|
+
this.readmeComponent = {
|
|
364
|
+
id,
|
|
365
|
+
head: null
|
|
366
|
+
};
|
|
367
|
+
} else {
|
|
368
|
+
this.readmeComponent = readmeComponent;
|
|
369
|
+
}
|
|
370
|
+
if (!previousReadme || !previousReadme.id.isEqual(id) || previousReadme.head?.toString() !== this.readmeComponent.head?.toString()) {
|
|
371
|
+
this.hasChanged = true;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
async isFullyMerged(scope) {
|
|
375
|
+
const {
|
|
376
|
+
unmerged
|
|
377
|
+
} = await this.getMergedAndUnmergedIds(scope);
|
|
378
|
+
return unmerged.length === 0;
|
|
379
|
+
}
|
|
380
|
+
async getMergedAndUnmergedIds(scope) {
|
|
381
|
+
const merged = [];
|
|
382
|
+
const unmerged = [];
|
|
383
|
+
await Promise.all(this.components.map(async component => {
|
|
384
|
+
const modelComponent = await scope.getModelComponentIfExist(component.id);
|
|
385
|
+
if (!modelComponent) {
|
|
386
|
+
unmerged.push(component.id);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const startTraverseFrom = modelComponent.getHead() || null; // it's important to have it as null and not as undefined, see hasVersionByRef
|
|
390
|
+
const headExist = await (0, _component().hasVersionByRef)(modelComponent, component.head, scope.objects, startTraverseFrom);
|
|
391
|
+
if (headExist) merged.push(component.id);else unmerged.push(component.id);
|
|
392
|
+
}));
|
|
393
|
+
return {
|
|
394
|
+
merged,
|
|
395
|
+
unmerged
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* @deprecated use toComponentIds instead
|
|
400
|
+
*/
|
|
401
|
+
toBitIds() {
|
|
402
|
+
return this.toComponentIds();
|
|
403
|
+
}
|
|
404
|
+
toComponentIds() {
|
|
405
|
+
return _componentId().ComponentIdList.fromArray(this.components.map(c => c.id.changeVersion(c.head.toString())));
|
|
406
|
+
}
|
|
407
|
+
toComponentIdsIncludeUpdateDependents() {
|
|
408
|
+
return _componentId().ComponentIdList.fromArray(this.toComponentIds().concat(this.updateDependents || []));
|
|
409
|
+
}
|
|
410
|
+
toLaneId() {
|
|
411
|
+
return new (_laneId().LaneId)({
|
|
412
|
+
scope: this.scope,
|
|
413
|
+
name: this.name
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
collectObjectsById(repo) {
|
|
417
|
+
return Promise.all(this.components.map(async component => {
|
|
418
|
+
const headVersion = await component.head.load(repo);
|
|
419
|
+
const objects = [headVersion, ...headVersion.collect(repo)];
|
|
420
|
+
return {
|
|
421
|
+
id: component.id,
|
|
422
|
+
objects
|
|
423
|
+
};
|
|
424
|
+
}));
|
|
425
|
+
}
|
|
426
|
+
includeDeletedData() {
|
|
427
|
+
return (0, _semver().gte)(this.schema, SCHEMA_INCLUDING_DELETED_COMPONENTS_DATA);
|
|
428
|
+
}
|
|
429
|
+
setSchemaToSupportDeletedData() {
|
|
430
|
+
this.schema = SCHEMA_INCLUDING_DELETED_COMPONENTS_DATA;
|
|
431
|
+
this.hasChanged = true;
|
|
432
|
+
}
|
|
433
|
+
setSchemaToNotSupportDeletedData() {
|
|
434
|
+
this.schema = OLD_LANE_SCHEMA;
|
|
435
|
+
this.hasChanged = true;
|
|
436
|
+
}
|
|
437
|
+
getCompHeadIncludeUpdateDependents(componentId) {
|
|
438
|
+
const comp = this.getComponent(componentId);
|
|
439
|
+
if (comp) return comp.head;
|
|
440
|
+
return this.getUpdateDependentAsLaneComponent(componentId)?.head;
|
|
441
|
+
}
|
|
442
|
+
validate() {
|
|
443
|
+
const message = `unable to save Lane object "${this.id()}"`;
|
|
444
|
+
const bitIds = this.toComponentIds();
|
|
445
|
+
this.components.forEach(component => {
|
|
446
|
+
if (bitIds.filterWithoutVersion(component.id).length > 1) {
|
|
447
|
+
throw new (_legacyCli().ValidationError)(`${message}, the following component is duplicated "${component.id.fullName}"`);
|
|
448
|
+
}
|
|
449
|
+
if (!(0, _componentVersion().isSnap)(component.head.hash)) {
|
|
450
|
+
throw new (_legacyCli().ValidationError)(`${message}, lane component ${component.id.toStringWithoutVersion()} head should be a hash, got ${component.head.hash}`);
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
if (this.name === _laneId().DEFAULT_LANE) {
|
|
454
|
+
throw new (_bitError().BitError)(`${message}, this name is reserved as the default lane`);
|
|
455
|
+
}
|
|
456
|
+
if (this.name === _legacy().PREVIOUS_DEFAULT_LANE) {
|
|
457
|
+
throw new (_bitError().BitError)(`${message}, this name is reserved as the old default lane`);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
isEqual(lane) {
|
|
461
|
+
if (this.id() !== lane.id()) return false;
|
|
462
|
+
// include isDeleted in equality so a soft-delete flip with the same head still counts as a
|
|
463
|
+
// state change — `Lane.isEqual` is used by importers to decide whether to write a
|
|
464
|
+
// LaneHistory entry.
|
|
465
|
+
const normalize = l => l.components.map(c => ({
|
|
466
|
+
id: c.id.toStringWithoutVersion(),
|
|
467
|
+
head: c.head.toString(),
|
|
468
|
+
isDeleted: Boolean(c.isDeleted)
|
|
469
|
+
})).sort((a, b) => `${a.id}@${a.head}:${a.isDeleted ? 1 : 0}`.localeCompare(`${b.id}@${b.head}:${b.isDeleted ? 1 : 0}`));
|
|
470
|
+
const thisUpdDeps = (this.updateDependents || []).map(c => c.toString()).sort();
|
|
471
|
+
const otherUpdDeps = (lane.updateDependents || []).map(c => c.toString()).sort();
|
|
472
|
+
return (0, _lodash().isEqual)(normalize(this), normalize(lane)) && (0, _lodash().isEqual)(thisUpdDeps, otherUpdDeps);
|
|
473
|
+
}
|
|
474
|
+
clone() {
|
|
475
|
+
return new Lane(_objectSpread(_objectSpread({}, this), {}, {
|
|
476
|
+
hash: this._hash,
|
|
477
|
+
overrideUpdateDependents: this.overrideUpdateDependents,
|
|
478
|
+
components: (0, _lodash().cloneDeep)(this.components),
|
|
479
|
+
updateDependents: this.updateDependents ? (0, _lodash().cloneDeep)(this.updateDependents) : undefined
|
|
480
|
+
}));
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
exports.default = Lane;
|
|
484
|
+
|
|
485
|
+
//# sourceMappingURL=lane.js.map
|