@teambit/objects 0.0.0-15acf3f9b295a985a00bf4c313c939bf7adc1310

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 (121) hide show
  1. package/dist/fixtures/version-model-extended.json +48 -0
  2. package/dist/fixtures/version-model-object.json +87 -0
  3. package/dist/index.d.ts +19 -0
  4. package/dist/index.js +371 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/models/dependencies-graph.d.ts +46 -0
  7. package/dist/models/dependencies-graph.js +105 -0
  8. package/dist/models/dependencies-graph.js.map +1 -0
  9. package/dist/models/detach-heads.d.ts +25 -0
  10. package/dist/models/detach-heads.js +84 -0
  11. package/dist/models/detach-heads.js.map +1 -0
  12. package/dist/models/export-metadata.d.ts +24 -0
  13. package/dist/models/export-metadata.js +76 -0
  14. package/dist/models/export-metadata.js.map +1 -0
  15. package/dist/models/index.d.ts +10 -0
  16. package/dist/models/index.js +125 -0
  17. package/dist/models/index.js.map +1 -0
  18. package/dist/models/lane-history.d.ts +40 -0
  19. package/dist/models/lane-history.js +117 -0
  20. package/dist/models/lane-history.js.map +1 -0
  21. package/dist/models/lane.d.ts +124 -0
  22. package/dist/models/lane.js +461 -0
  23. package/dist/models/lane.js.map +1 -0
  24. package/dist/models/model-component.d.ts +318 -0
  25. package/dist/models/model-component.js +1375 -0
  26. package/dist/models/model-component.js.map +1 -0
  27. package/dist/models/model-component.spec.d.ts +1 -0
  28. package/dist/models/model-component.spec.js +71 -0
  29. package/dist/models/model-component.spec.js.map +1 -0
  30. package/dist/models/scopeMeta.d.ts +20 -0
  31. package/dist/models/scopeMeta.js +71 -0
  32. package/dist/models/scopeMeta.js.map +1 -0
  33. package/dist/models/source.d.ts +10 -0
  34. package/dist/models/source.js +43 -0
  35. package/dist/models/source.js.map +1 -0
  36. package/dist/models/symlink.d.ts +30 -0
  37. package/dist/models/symlink.js +91 -0
  38. package/dist/models/symlink.js.map +1 -0
  39. package/dist/models/version-history.d.ts +59 -0
  40. package/dist/models/version-history.js +287 -0
  41. package/dist/models/version-history.js.map +1 -0
  42. package/dist/models/version.d.ts +284 -0
  43. package/dist/models/version.js +786 -0
  44. package/dist/models/version.js.map +1 -0
  45. package/dist/models/version.spec.d.ts +1 -0
  46. package/dist/models/version.spec.js +340 -0
  47. package/dist/models/version.spec.js.map +1 -0
  48. package/dist/objects/bit-object-list.d.ts +24 -0
  49. package/dist/objects/bit-object-list.js +65 -0
  50. package/dist/objects/bit-object-list.js.map +1 -0
  51. package/dist/objects/index.d.ts +5 -0
  52. package/dist/objects/index.js +60 -0
  53. package/dist/objects/index.js.map +1 -0
  54. package/dist/objects/object-list-to-graph.d.ts +13 -0
  55. package/dist/objects/object-list-to-graph.js +93 -0
  56. package/dist/objects/object-list-to-graph.js.map +1 -0
  57. package/dist/objects/object-list.d.ts +52 -0
  58. package/dist/objects/object-list.js +369 -0
  59. package/dist/objects/object-list.js.map +1 -0
  60. package/dist/objects/object.d.ts +35 -0
  61. package/dist/objects/object.js +190 -0
  62. package/dist/objects/object.js.map +1 -0
  63. package/dist/objects/objects-readable-generator.d.ts +31 -0
  64. package/dist/objects/objects-readable-generator.js +192 -0
  65. package/dist/objects/objects-readable-generator.js.map +1 -0
  66. package/dist/objects/raw-object.d.ts +23 -0
  67. package/dist/objects/raw-object.js +155 -0
  68. package/dist/objects/raw-object.js.map +1 -0
  69. package/dist/objects/ref.d.ts +14 -0
  70. package/dist/objects/ref.js +45 -0
  71. package/dist/objects/ref.js.map +1 -0
  72. package/dist/objects/repository-hooks.d.ts +4 -0
  73. package/dist/objects/repository-hooks.js +56 -0
  74. package/dist/objects/repository-hooks.js.map +1 -0
  75. package/dist/objects/repository.d.ts +149 -0
  76. package/dist/objects/repository.js +847 -0
  77. package/dist/objects/repository.js.map +1 -0
  78. package/dist/objects/scope-index.d.ts +74 -0
  79. package/dist/objects/scope-index.js +256 -0
  80. package/dist/objects/scope-index.js.map +1 -0
  81. package/dist/objects/scope-index.spec.d.ts +1 -0
  82. package/dist/objects/scope-index.spec.js +152 -0
  83. package/dist/objects/scope-index.spec.js.map +1 -0
  84. package/dist/objects.aspect.d.ts +2 -0
  85. package/dist/objects.aspect.js +18 -0
  86. package/dist/objects.aspect.js.map +1 -0
  87. package/dist/objects.main.runtime.d.ts +7 -0
  88. package/dist/objects.main.runtime.js +36 -0
  89. package/dist/objects.main.runtime.js.map +1 -0
  90. package/dist/preview-1752106620913.js +7 -0
  91. package/fixtures/version-model-extended.json +48 -0
  92. package/fixtures/version-model-object.json +87 -0
  93. package/models/dependencies-graph.ts +120 -0
  94. package/models/detach-heads.ts +79 -0
  95. package/models/export-metadata.ts +57 -0
  96. package/models/index.ts +11 -0
  97. package/models/lane-history.ts +106 -0
  98. package/models/lane.ts +367 -0
  99. package/models/model-component.spec.ts +55 -0
  100. package/models/model-component.ts +1387 -0
  101. package/models/scopeMeta.ts +60 -0
  102. package/models/source.ts +32 -0
  103. package/models/symlink.ts +66 -0
  104. package/models/version-history.ts +271 -0
  105. package/models/version.spec.ts +288 -0
  106. package/models/version.ts +826 -0
  107. package/objects/bit-object-list.ts +59 -0
  108. package/objects/index.ts +6 -0
  109. package/objects/object-list-to-graph.ts +69 -0
  110. package/objects/object-list.ts +313 -0
  111. package/objects/object.ts +153 -0
  112. package/objects/objects-readable-generator.ts +167 -0
  113. package/objects/raw-object.ts +142 -0
  114. package/objects/ref.ts +45 -0
  115. package/objects/repository-hooks.ts +42 -0
  116. package/objects/repository.ts +760 -0
  117. package/objects/scope-index.spec.ts +95 -0
  118. package/objects/scope-index.ts +198 -0
  119. package/package.json +97 -0
  120. package/types/asset.d.ts +41 -0
  121. package/types/style.d.ts +42 -0
@@ -0,0 +1,318 @@
1
+ import * as semver from 'semver';
2
+ import { LaneId } from '@teambit/lane-id';
3
+ import { ComponentID } from '@teambit/component-id';
4
+ import { LegacyComponentLog } from '@teambit/legacy-component-log';
5
+ import { BitId } from '@teambit/legacy-bit-id';
6
+ import { ConsumerComponent } from '@teambit/legacy.consumer-component';
7
+ import { SnapsDistance } from '@teambit/component.snap-distance';
8
+ import { ComponentObjects, ComponentVersion } from '@teambit/legacy.scope';
9
+ import { Repository, BitObject, Ref } from '../objects';
10
+ import Lane from './lane';
11
+ import Version from './version';
12
+ import VersionHistory, { VersionParents } from './version-history';
13
+ import { ObjectItem } from '../objects/object-list';
14
+ import type { Scope } from '@teambit/legacy.scope';
15
+ import { DetachedHeads } from './detach-heads';
16
+ type State = {
17
+ versions?: {
18
+ [version: string]: {
19
+ local?: boolean;
20
+ };
21
+ };
22
+ };
23
+ export type AddVersionOpts = {
24
+ addToUpdateDependentsInLane?: boolean;
25
+ /**
26
+ * kind of rebase.
27
+ * if true, set the head as the parent of the new version.
28
+ * by default, the parent is the currently used version in .bitmap.
29
+ * (this prop takes affect only when the component is checked out to an older version)
30
+ */
31
+ setHeadAsParent?: boolean;
32
+ detachHead?: boolean;
33
+ overrideHead?: boolean;
34
+ };
35
+ type Versions = {
36
+ [version: string]: Ref;
37
+ };
38
+ export type ScopeListItem = {
39
+ url: string;
40
+ name: string;
41
+ date: string;
42
+ };
43
+ export type ComponentLog = LegacyComponentLog;
44
+ export type ComponentProps = {
45
+ scope: string;
46
+ name: string;
47
+ versions?: Versions;
48
+ orphanedVersions?: Versions;
49
+ lang: string;
50
+ deprecated: boolean;
51
+ bindingPrefix: string;
52
+ state?: State;
53
+ scopesList?: ScopeListItem[];
54
+ head?: Ref;
55
+ schema?: string | undefined;
56
+ detachedHeads?: DetachedHeads;
57
+ };
58
+ export declare const VERSION_ZERO = "0.0.0";
59
+ /**
60
+ * we can't rename the class as ModelComponent because old components are already saved in the model
61
+ * with 'Component' in their headers. see object-registrar.types()
62
+ */
63
+ export default class Component extends BitObject {
64
+ scope: string;
65
+ name: string;
66
+ versions: Versions;
67
+ orphanedVersions: Versions;
68
+ lang: string;
69
+ /**
70
+ * @deprecated moved to the Version object inside teambit/deprecation aspect
71
+ */
72
+ deprecated: boolean;
73
+ bindingPrefix: string;
74
+ /**
75
+ * @deprecated since 0.12.6 (long long ago :) probably can be removed)
76
+ */
77
+ local: boolean | null | undefined;
78
+ state: State;
79
+ scopesList: ScopeListItem[];
80
+ head?: Ref;
81
+ remoteHead?: Ref | null;
82
+ /**
83
+ * doesn't get saved in the scope, used to easier access the local snap head data
84
+ * when checked out to a lane, this prop is either Ref or null. otherwise (when on main), this prop is undefined.
85
+ */
86
+ laneHeadLocal?: Ref | null;
87
+ /**
88
+ * doesn't get saved in the scope, used to easier access the remote snap head data
89
+ * when checked out to a lane, this prop is either Ref or null. otherwise (when on main), this prop is undefined.
90
+ */
91
+ laneHeadRemote?: Ref | null;
92
+ /**
93
+ * when checked out to a lane, calculate what should be the head on the remote.
94
+ * if the laneHeadRemote is null, for example, when the lane is new, then used the the lane it was forked from.
95
+ * it no head is found on the lane/forked, then use the component.head.
96
+ */
97
+ calculatedRemoteHeadWhenOnLane?: Ref | null;
98
+ laneId?: LaneId;
99
+ laneDataIsPopulated: boolean;
100
+ schema: string | undefined;
101
+ detachedHeads: DetachedHeads;
102
+ private divergeData?;
103
+ private _populateVersionHistoryMutex?;
104
+ constructor(props: ComponentProps);
105
+ private get populateVersionHistoryMutex();
106
+ get versionArray(): Ref[];
107
+ setVersion(tag: string, ref: Ref): void;
108
+ setOrphanedVersion(tag: string, ref: Ref): void;
109
+ getRef(version: string): Ref | null;
110
+ getHeadStr(): string | null;
111
+ getHead(): Ref | undefined;
112
+ /**
113
+ * returns the head hash. regardless of whether current lane is the default or not.
114
+ * if on a lane, it returns the head of the component on the lane.
115
+ */
116
+ getHeadRegardlessOfLane(): Ref | undefined;
117
+ getHeadAsTagIfExist(): string | undefined;
118
+ hasHead(): boolean;
119
+ setHead(head: Ref | undefined): void;
120
+ listVersions(sort?: 'ASC' | 'DESC'): string[];
121
+ listVersionsIncludeOrphaned(sort?: 'ASC' | 'DESC'): string[];
122
+ hasVersion(version: string, repo: Repository, includeOrphaned?: boolean): Promise<boolean>;
123
+ hasTag(version: string): boolean;
124
+ get versionsIncludeOrphaned(): Versions;
125
+ hasTagIncludeOrphaned(version: string): boolean;
126
+ /**
127
+ * whether the head is a snap (not a tag)
128
+ */
129
+ isHeadSnap(): boolean | undefined;
130
+ /**
131
+ * add a new remote if it is not there already
132
+ */
133
+ addScopeListItem(scopeListItem: ScopeListItem): void;
134
+ /**
135
+ * on main - it checks local-head (or .bitmap version if given) vs remote-head.
136
+ * on lane - it checks local-head on lane vs remote-head on lane.
137
+ * however, to get an accurate `divergeData.snapsOnSourceOnly`, the above is not enough.
138
+ * for example, comp-a@snap-x from lane-a is merged into lane-b. we don't want this snap-x to be "local", because
139
+ * then, bit-status will show it as "staged" and bit-reset will remove it unexpectedly.
140
+ * if we only check by the local-head and remote-head on lane, it'll be local because the remote-head of lane-b is empty.
141
+ * to address this, we search all remote-refs files for this bit-id and during the local history traversal, if a hash
142
+ * is found there, it'll stop the traversal and not mark it as remote.
143
+ * in this example, during the merge, lane-a was fetched, and the remote-ref of this lane has snap-x as the head.
144
+ */
145
+ setDivergeData(repo: Repository, throws?: boolean, fromCache?: boolean, workspaceId?: ComponentID): Promise<void>;
146
+ isOnLane(): boolean;
147
+ /**
148
+ * this is used (among others) by `bit status` to check whether snaps are local (staged), for `bit reset` to remove them
149
+ * and for `bit export` to push them. for "merge pending" status, use `this.getDivergeDataForMergePending()`.
150
+ */
151
+ getDivergeData(): SnapsDistance;
152
+ /**
153
+ * don't use modelComponent.getDivergeData() because in some scenarios when on a lane, it compares the head
154
+ * on the lane against the head on the main, which could show the component as diverged incorrectly.
155
+ */
156
+ getDivergeDataForMergePending(repo: Repository): Promise<SnapsDistance>;
157
+ populateLocalAndRemoteHeads(repo: Repository, lane?: Lane): Promise<void>;
158
+ setLaneHeadLocal(lane?: Lane): void;
159
+ /**
160
+ * returns only the versions that exist in both components (regardless whether the hash are the same)
161
+ * e.g. this.component = [0.0.1, 0.0.2, 0.0.3], other component = [0.0.3, 0.0.4]. it returns only [0.0.3].
162
+ * also, in case it is coming from 'bit import', the version must be locally changed.
163
+ * otherwise, it doesn't matter whether the hashes are different.
164
+ */
165
+ _getComparableVersionsObjects(otherComponent: Component, // in case of merging, the otherComponent is the existing component, and "this" is the incoming component
166
+ local: boolean): {
167
+ thisComponentVersions: Versions;
168
+ otherComponentVersions: Versions;
169
+ };
170
+ compatibleWith(component: Component, local: boolean): boolean;
171
+ diffWith(component: Component, local: boolean): string[];
172
+ isEmpty(): boolean;
173
+ /**
174
+ * on main return main head, on lane, return lane head.
175
+ * if the head is also a tag, return the tag, otherwise, return the hash.
176
+ */
177
+ getHeadRegardlessOfLaneAsTagOrHash(returnVersionZeroForNoHead?: boolean): string;
178
+ /**
179
+ * get the recent head. if locally is ahead, return the local head. otherwise, return the remote head.
180
+ *
181
+ * a user can be checked out to a lane, in which case, `this.laneHeadLocal` and `this.laneHeadRemote`
182
+ * may be populated.
183
+ * `this.head` may not be populated, e.g. when a component was created on
184
+ * this lane and never got snapped on main.
185
+ * it's impossible that `this.head.isEqual(this.laneHeadLocal)`, because when snapping it's either
186
+ * on main, which goes to this.head OR on a lane, which goes to this.laneHeadLocal.
187
+ */
188
+ headIncludeRemote(repo: Repository): Promise<string>;
189
+ getRefOfAncestor(repo: Repository, generationsToGoBack: number): Promise<Ref>;
190
+ latestVersion(): string;
191
+ latestVersionIfExist(): string | undefined;
192
+ isLatestGreaterThan(version: string | null | undefined): boolean;
193
+ /**
194
+ * Return the lateset version which actuall exists in the scope
195
+ * (exists means the object itself exists)
196
+ * This relevant for cases when the component version array has few versions
197
+ * but we don't have all the refs in the object
198
+ *
199
+ * @returns {number}
200
+ * @memberof Component
201
+ */
202
+ latestExisting(repository: Repository): string;
203
+ /**
204
+ * get component log and sort by the timestamp in ascending order (from the earliest to the latest)
205
+ */
206
+ collectLogs(scope: Scope, shortHash?: boolean, startFrom?: Ref): Promise<ComponentLog[]>;
207
+ collectVersions(repo: Repository): Promise<ConsumerComponent[]>;
208
+ getTagOfRefIfExists(ref: Ref, allTags?: Versions): string | undefined;
209
+ getTag(version: string): string | undefined;
210
+ switchHashesWithTagsIfExist(refs: Ref[]): string[];
211
+ /**
212
+ * if exactVersion is defined, add exact version instead of using the semver mechanism
213
+ */
214
+ getVersionToAdd(releaseType?: semver.ReleaseType, exactVersion?: string | null, incrementBy?: number, preReleaseId?: string): string;
215
+ isEqual(component: Component, considerOrphanedVersions?: boolean): boolean;
216
+ addVersion(version: Version, versionToAdd: string, lane?: Lane, previouslyUsedVersion?: string, { addToUpdateDependentsInLane, setHeadAsParent, detachHead, overrideHead }?: AddVersionOpts): string;
217
+ version(releaseType?: semver.ReleaseType, incrementBy?: number, preReleaseId?: string): string;
218
+ id(): string;
219
+ /**
220
+ * @deprecated use toComponentId() instead
221
+ */
222
+ toBitId(): BitId;
223
+ toComponentId(): ComponentID;
224
+ /**
225
+ * @deprecated use toComponentIdWithLatestVersion() instead
226
+ */
227
+ toBitIdWithLatestVersion(): BitId;
228
+ toComponentIdWithLatestVersion(): ComponentID;
229
+ toComponentIdWithHead(): ComponentID;
230
+ toBitIdWithLatestVersionAllowNull(): ComponentID;
231
+ toObject(): {
232
+ name: string;
233
+ scope: string;
234
+ versions: {};
235
+ lang: string;
236
+ deprecated: boolean;
237
+ bindingPrefix: string;
238
+ remotes: ScopeListItem[];
239
+ schema: string | undefined;
240
+ detachedHeads: {
241
+ heads?: string[];
242
+ deleted?: string[];
243
+ current?: string;
244
+ } | undefined;
245
+ };
246
+ loadVersion(versionStr: string, repository: Repository, throws?: boolean): Promise<Version>;
247
+ loadVersionSync(version: string, repository: Repository, throws?: boolean): Version;
248
+ collectVersionsObjects(repo: Repository, versions: string[], throwForMissingLocalArtifacts?: boolean, workspaceId?: ComponentID): Promise<ObjectItem[]>;
249
+ collectObjects(repo: Repository): Promise<ComponentObjects>;
250
+ /**
251
+ * to delete a version from a component, don't call this method directly. Instead, use sources.removeVersion()
252
+ */
253
+ removeVersion(version: string): Ref;
254
+ toComponentVersion(versionStr?: string): ComponentVersion;
255
+ /**
256
+ * if no "specificVersion" is given, it returns according to the head
257
+ */
258
+ isDeprecated(repo: Repository, specificVersion?: string): Promise<boolean | null>;
259
+ isRemoved(repo: Repository, specificVersion?: string): Promise<boolean | null>;
260
+ isLaneReadmeOf(repo: Repository): Promise<string[]>;
261
+ /**
262
+ * convert a ModelComponent of a specific version to ConsumerComponent
263
+ * @see sources.consumerComponentToVersion() for the opposite action.
264
+ */
265
+ toConsumerComponent(versionStr: string, scopeName: string, repository: Repository): Promise<ConsumerComponent>;
266
+ private addDepsInfoFromDepsResolver;
267
+ refs(): Ref[];
268
+ validateBeforePersisting(componentStr: string): void;
269
+ toBuffer(pretty: boolean): Buffer;
270
+ /**
271
+ * Clear data that is relevant only for the local scope and should not be moved to the remote scope
272
+ */
273
+ clearStateData(): void;
274
+ markVersionAsLocal(version: string): void;
275
+ /**
276
+ * local versions that are not exported on the main lane.
277
+ * @see `this.getLocalTagsOrHashes()`, to get local snaps on the current lane
278
+ */
279
+ getLocalVersions(): string[];
280
+ hasLocalTag(tag: string): boolean;
281
+ getLocalTagsOrHashes(repo: Repository, workspaceId?: ComponentID): Promise<string[]>;
282
+ getLocalHashes(repo: Repository, workspaceId?: ComponentID): Promise<Ref[]>;
283
+ /**
284
+ * for most cases, use `isLocallyChanged`, which takes into account lanes.
285
+ * this is for cases when we only care about the versions exist in the `state` prop.
286
+ */
287
+ isLocallyChangedRegardlessOfLanes(): boolean;
288
+ /**
289
+ * whether the component was locally changed, either by adding a new snap/tag or by merging
290
+ * components from different lanes.
291
+ */
292
+ isLocallyChanged(repo: Repository, lane?: Lane | null, workspaceId?: ComponentID): Promise<boolean>;
293
+ getVersionHistory(repo: Repository): Promise<VersionHistory>;
294
+ getAndPopulateVersionHistory(repo: Repository, head: Ref): Promise<VersionHistory>;
295
+ /**
296
+ * careful! the `versions` passed here can belong to other components, not necessarily to this one.
297
+ * that's why it checks whether the version-hash exists in the VersionHistory, and if it's not,
298
+ * it won't update it.
299
+ */
300
+ updateRebasedVersionHistory(repo: Repository, versions: Version[]): Promise<VersionHistory | undefined>;
301
+ updateVersionHistory(repo: Repository, versions: Version[]): Promise<VersionHistory>;
302
+ populateVersionHistoryIfMissingGracefully(repo: Repository, versionHistory: VersionHistory, head: Ref,
303
+ /**
304
+ * during traversal, if a hash is found in the VersionHistory it probably means that it has all history until this
305
+ * point, so we can stop there for better performance. In some rare cases (e.g. the export was interrupted), we
306
+ * need the ability of full traversal to repair the VersionHistory.
307
+ */
308
+ exitWhenFind?: boolean): Promise<{
309
+ err?: Error;
310
+ added?: VersionParents[];
311
+ }>;
312
+ static parse(contents: string): Component;
313
+ static from(props: ComponentProps): Component;
314
+ static fromBitId(bitId: ComponentID): Component;
315
+ get isLegacy(): boolean;
316
+ validate(): void;
317
+ }
318
+ export {};