@teambit/api-server 0.0.0-e8287ed72e2b99e42d753c493df21297eff042bb → 0.0.0-e8938184c00c8a31108c548d2a737c4c0fabbff4

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/.npmignore ADDED
@@ -0,0 +1,18 @@
1
+ dist/tsconfig.tsbuildinfo
2
+ dist/tsconfig.json
3
+ /tsconfig.json
4
+
5
+ package-tar/
6
+ .bit-capsule-ready
7
+ /*.ts
8
+ artifacts/*
9
+ !artifacts/env-template
10
+ !artifacts/ui-bundle
11
+ !artifacts/preview-bundle
12
+ package-tar/
13
+ .bit-capsule-ready
14
+ /*.ts
15
+ artifacts/*
16
+ !artifacts/env-template
17
+ !artifacts/ui-bundle
18
+ !artifacts/preview-bundle
@@ -1,31 +1,60 @@
1
- import { CompFiles, Workspace, FilesStatus } from '@teambit/workspace';
2
- import { PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy.utils';
3
- import { SnappingMain } from '@teambit/snapping';
4
- import { LanesMain } from '@teambit/lanes';
5
- import { InstallMain } from '@teambit/install';
6
- import { ExportMain } from '@teambit/export';
7
- import { CheckoutMain } from '@teambit/checkout';
8
- import { ComponentLogMain, FileHashDiffFromParent } from '@teambit/component-log';
9
- import { LaneLog } from '@teambit/objects';
10
- import { ComponentCompareMain } from '@teambit/component-compare';
11
- import { GeneratorMain, PromptOption, PromptResults } from '@teambit/generator';
12
- import { RemoveMain } from '@teambit/remove';
13
- import { ConfigMain } from '@teambit/config';
14
- import { ApplicationMain } from '@teambit/application';
15
- import { DeprecationMain } from '@teambit/deprecation';
16
- import { EnvsMain } from '@teambit/envs';
17
- import { GraphMain } from '@teambit/graph';
18
- import { ScopeMain } from '@teambit/scope';
19
- import { ComponentMain } from '@teambit/component';
20
- import { SchemaMain } from '@teambit/schema';
21
- import { Logger } from '@teambit/logger';
1
+ import type { CompFiles, Workspace, FilesStatus } from '@teambit/workspace';
2
+ import type { PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy.utils';
3
+ import type { SnappingMain } from '@teambit/snapping';
4
+ import type { LanesMain } from '@teambit/lanes';
5
+ import type { InstallMain } from '@teambit/install';
6
+ import type { ExportMain } from '@teambit/export';
7
+ import type { CheckoutMain } from '@teambit/checkout';
8
+ import type { ComponentLogMain, FileHashDiffFromParent } from '@teambit/component-log';
9
+ import type { LaneLog } from '@teambit/objects';
10
+ import type { ComponentCompareMain } from '@teambit/component-compare';
11
+ import type { GenerateResult, GeneratorMain, PromptOption, PromptResults, TemplateDescriptor } from '@teambit/generator';
12
+ import type { RemoveMain } from '@teambit/remove';
13
+ import type { ConfigMain } from '@teambit/config';
14
+ import type { ApplicationMain } from '@teambit/application';
15
+ import type { DeprecationMain } from '@teambit/deprecation';
16
+ import type { EnvsMain } from '@teambit/envs';
17
+ import type { GraphMain } from '@teambit/graph';
18
+ import type { ScopeMain } from '@teambit/scope';
19
+ import type { ComponentMain, ComponentMap } from '@teambit/component';
20
+ import type { SchemaMain } from '@teambit/schema';
21
+ import type { Logger } from '@teambit/logger';
22
+ type LaneDiffForIDEResult = {
23
+ newCompsFrom: string[];
24
+ newCompsTo: string[];
25
+ compsWithDiff: {
26
+ id: string;
27
+ hasDiff: boolean;
28
+ filesDiff: {
29
+ filePath: string;
30
+ status: string;
31
+ fromContent?: string;
32
+ toContent?: string;
33
+ }[];
34
+ fieldsDiff?: {
35
+ fieldName: string;
36
+ diffOutput: string;
37
+ }[] | null;
38
+ }[];
39
+ compsWithNoChanges: string[];
40
+ toLaneName: string;
41
+ fromLaneName: string;
42
+ failures: {
43
+ id: string;
44
+ msg: string;
45
+ }[];
46
+ };
22
47
  type PathLinux = string;
23
48
  type PathFromLastSnap = {
24
49
  [relativeToWorkspace: PathLinux]: string;
25
50
  };
51
+ type ObjectPathsFromLastSnap = {
52
+ [relativeToWorkspace: PathLinux]: string;
53
+ };
26
54
  type InitSCMEntry = {
27
55
  filesStatus: FilesStatus;
28
56
  pathsFromLastSnap: PathFromLastSnap;
57
+ objectPathsFromLastSnap: ObjectPathsFromLastSnap;
29
58
  compDir: PathLinux;
30
59
  };
31
60
  type DataToInitSCM = {
@@ -128,8 +157,8 @@ export declare class APIForIDE {
128
157
  [relativePath: string]: string;
129
158
  }>;
130
159
  catObject(hash: string): Promise<string>;
131
- logFile(filePath: string): Promise<import("@teambit/component-log/component-log.main.runtime").FileLog[]>;
132
- blame(filePath: string): Promise<import("@teambit/component-log/component-log.main.runtime").BlameLineInfo[]>;
160
+ logFile(filePath: string): Promise<import("@teambit/component-log/dist/component-log.main.runtime").FileLog[]>;
161
+ blame(filePath: string): Promise<import("@teambit/component-log/dist/component-log.main.runtime").BlameLineInfo[]>;
133
162
  changedFilesFromParent(id: string): Promise<FileHashDiffFromParent[]>;
134
163
  getConfigForDiff(id: string): Promise<{
135
164
  version?: string;
@@ -141,9 +170,12 @@ export declare class APIForIDE {
141
170
  getCompFilesDirPathFromLastSnapUsingCompFiles(compFiles: CompFiles): Promise<{
142
171
  [relativePath: string]: string;
143
172
  }>;
173
+ getCompFileObjectPathsFromLastSnap(compFiles: CompFiles): {
174
+ [relativePath: string]: string;
175
+ };
144
176
  warmWorkspaceCache(): Promise<void>;
145
177
  clearCache(): Promise<void>;
146
- install(options?: {}, packages?: string[]): Promise<import("@teambit/component").ComponentMap<string>>;
178
+ install(options?: {}, packages?: string[]): Promise<ComponentMap<string>>;
147
179
  export(): Promise<{
148
180
  componentsIds: string[];
149
181
  removedIds: string[];
@@ -156,9 +188,10 @@ export declare class APIForIDE {
156
188
  skipped: string[] | undefined;
157
189
  failed: string[] | undefined;
158
190
  }>;
159
- getTemplates(): Promise<import("@teambit/generator/generator.main.runtime").TemplateDescriptor[]>;
191
+ importObjectsIfOutdatedAgainstBitmap(): Promise<void>;
192
+ getTemplates(): Promise<TemplateDescriptor[]>;
160
193
  getPromptOptionsForTemplate(templateName: string): Promise<PromptOption[] | undefined>;
161
- createComponent(templateName: string, idIncludeScope: string, promptResults?: PromptResults): Promise<import("@teambit/generator").GenerateResult[]>;
194
+ createComponent(templateName: string, idIncludeScope: string, promptResults?: PromptResults): Promise<GenerateResult[]>;
162
195
  removeComponent(componentsPattern: string): Promise<import("@teambit/legacy.scope").RemovedObjectSerialized>;
163
196
  deleteComponents(componentsPattern: string, opts: any): Promise<string[]>;
164
197
  deprecateComponent(id: string, newId?: string, range?: string): Promise<boolean>;
@@ -170,13 +203,30 @@ export declare class APIForIDE {
170
203
  }>;
171
204
  private adjustCheckoutResultsToIde;
172
205
  getModifiedByConfig(): Promise<ModifiedByConfig[]>;
173
- getDataToInitSCM(): Promise<DataToInitSCM>;
206
+ getDataToInitSCM(options?: {
207
+ useHashes?: boolean;
208
+ }): Promise<DataToInitSCM>;
174
209
  getFilesStatus(id: string): Promise<FilesStatus>;
175
210
  getCompFilesDirPathFromLastSnapForAllComps(): Promise<{
176
211
  [relativePath: string]: string;
177
212
  }>;
213
+ getLaneHistoryForIDE(laneName?: string): Promise<{
214
+ entries: {
215
+ id: string;
216
+ date: string;
217
+ username: string | undefined;
218
+ email: string | undefined;
219
+ message: string | undefined;
220
+ components: string[];
221
+ deleted: string[] | undefined;
222
+ }[];
223
+ isMain: boolean;
224
+ }>;
225
+ getLaneHistoryDiffForIDE(fromHistoryId: string, toHistoryId: string, laneName?: string): Promise<LaneDiffForIDEResult>;
226
+ getLaneDiffForIDE(): Promise<LaneDiffForIDEResult>;
227
+ private toLaneDiffForIDEResult;
178
228
  getCurrentLaneName(includeScope?: boolean): string;
179
- tagOrSnap(message?: string): Promise<import("@teambit/snapping").TagResults | import("@teambit/snapping").SnapResults | null>;
229
+ tagOrSnap(message?: string): Promise<import("@teambit/snapping").SnapResults | import("@teambit/snapping").TagResults | null>;
180
230
  tag(message?: string): Promise<string[]>;
181
231
  snap(message?: string): Promise<string[]>;
182
232
  getCompDetails(id: string, includeSchema?: boolean): Promise<Record<string, any>>;
@@ -81,6 +81,13 @@ function _componentModules() {
81
81
  };
82
82
  return data;
83
83
  }
84
+ function _lanesModules() {
85
+ const data = require("@teambit/lanes.modules.diff");
86
+ _lanesModules = function () {
87
+ return data;
88
+ };
89
+ return data;
90
+ }
84
91
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
85
92
  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
93
  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; }
@@ -390,6 +397,15 @@ class APIForIDE {
390
397
  }));
391
398
  return results;
392
399
  }
400
+ getCompFileObjectPathsFromLastSnap(compFiles) {
401
+ if (!compFiles.id.hasVersion()) return {}; // it's a new component.
402
+ const repo = this.workspace.scope.legacyScope.objects;
403
+ const results = {};
404
+ for (const modelFile of compFiles.modelFiles) {
405
+ results[(0, _legacy().pathJoinLinux)(compFiles.compDir, modelFile.relativePath)] = repo.objectPath(modelFile.file);
406
+ }
407
+ return results;
408
+ }
393
409
  async warmWorkspaceCache() {
394
410
  await this.workspace.warmCache();
395
411
  }
@@ -430,6 +446,9 @@ class APIForIDE {
430
446
  });
431
447
  return this.adjustCheckoutResultsToIde(results);
432
448
  }
449
+ async importObjectsIfOutdatedAgainstBitmap() {
450
+ return this.workspace.importObjectsIfOutdatedAgainstBitmap();
451
+ }
433
452
  async getTemplates() {
434
453
  const templates = await this.generator.listTemplates();
435
454
  return templates;
@@ -517,16 +536,25 @@ class APIForIDE {
517
536
  }));
518
537
  return (0, _lodash().compact)(results);
519
538
  }
520
- async getDataToInitSCM() {
539
+ async getDataToInitSCM(options) {
540
+ const useHashes = options?.useHashes;
541
+ if (useHashes) {
542
+ // clean up old materialized files since hash-based reads don't need them
543
+ const lastSnapDir = _path().default.join(this.workspace.scope.path, FILES_HISTORY_DIR, LAST_SNAP_DIR);
544
+ await _fsExtra().default.remove(lastSnapDir);
545
+ }
521
546
  const ids = this.workspace.listIds();
522
547
  const results = {};
523
548
  await (0, _pMap().default)(ids, async id => {
524
549
  const compFiles = await this.workspace.getFilesModification(id);
525
- const pathsFromLastSnap = await this.getCompFilesDirPathFromLastSnapUsingCompFiles(compFiles);
550
+ // only compute object paths when the extension supports direct object reads, otherwise materialize files to disk
551
+ const objectPathsFromLastSnap = useHashes ? this.getCompFileObjectPathsFromLastSnap(compFiles) : {};
552
+ const pathsFromLastSnap = useHashes ? {} : await this.getCompFilesDirPathFromLastSnapUsingCompFiles(compFiles);
526
553
  const idStr = id.toStringWithoutVersion();
527
554
  results[idStr] = {
528
555
  filesStatus: compFiles.getFilesStatus(),
529
556
  pathsFromLastSnap,
557
+ objectPathsFromLastSnap,
530
558
  compDir: compFiles.compDir
531
559
  };
532
560
  }, {
@@ -551,6 +579,81 @@ class APIForIDE {
551
579
  });
552
580
  return results;
553
581
  }
582
+ async getLaneHistoryForIDE(laneName) {
583
+ const laneId = laneName ? await this.lanes.parseLaneId(laneName) : this.workspace.getCurrentLaneId();
584
+ if (laneId.isDefault()) {
585
+ return {
586
+ entries: [],
587
+ isMain: true
588
+ };
589
+ }
590
+ await this.lanes.importLaneHistory(laneId);
591
+ const laneHistory = await this.lanes.getLaneHistory(laneId);
592
+ const historyIds = laneHistory.getHistoryIds();
593
+ const history = laneHistory.getHistory();
594
+ const entries = historyIds.map(id => {
595
+ const item = history[id];
596
+ return {
597
+ id,
598
+ date: item.log.date,
599
+ username: item.log.username,
600
+ email: item.log.email,
601
+ message: item.log.message,
602
+ components: item.components,
603
+ deleted: item.deleted
604
+ };
605
+ });
606
+ return {
607
+ entries,
608
+ isMain: false
609
+ };
610
+ }
611
+ async getLaneHistoryDiffForIDE(fromHistoryId, toHistoryId, laneName) {
612
+ const laneId = laneName ? await this.lanes.parseLaneId(laneName) : this.workspace.getCurrentLaneId();
613
+ if (laneId.isDefault()) {
614
+ throw new Error('lane history diff is not available on main');
615
+ }
616
+ await this.lanes.importLaneHistory(laneId);
617
+ const laneHistory = await this.lanes.getLaneHistory(laneId);
618
+ const laneObj = await this.lanes.loadLane(laneId);
619
+ if (!laneObj) throw new Error(`unable to find lane "${laneId.toString()}"`);
620
+ const diffGenerator = new (_lanesModules().LaneDiffGenerator)(this.workspace, this.scope, this.componentCompare);
621
+ const diffResults = await diffGenerator.generateDiffHistory(laneObj, laneHistory, fromHistoryId, toHistoryId);
622
+ return this.toLaneDiffForIDEResult(diffResults);
623
+ }
624
+ async getLaneDiffForIDE() {
625
+ const currentLaneId = this.workspace.getCurrentLaneId();
626
+ if (currentLaneId.isDefault()) {
627
+ throw new Error('lane diff is not available on main');
628
+ }
629
+ const diffGenerator = new (_lanesModules().LaneDiffGenerator)(this.workspace, this.scope, this.componentCompare);
630
+ const diffResults = await diffGenerator.generate([]);
631
+ return this.toLaneDiffForIDEResult(diffResults);
632
+ }
633
+ toLaneDiffForIDEResult(diffResults) {
634
+ return {
635
+ newCompsFrom: diffResults.newCompsFrom,
636
+ newCompsTo: diffResults.newCompsTo,
637
+ compsWithDiff: diffResults.compsWithDiff.map(d => ({
638
+ id: d.id.toString(),
639
+ hasDiff: d.hasDiff,
640
+ filesDiff: (d.filesDiff || []).map(f => ({
641
+ filePath: f.filePath,
642
+ status: f.status,
643
+ fromContent: f.status === 'UNCHANGED' ? undefined : f.fromContent,
644
+ toContent: f.status === 'UNCHANGED' ? undefined : f.toContent
645
+ })),
646
+ fieldsDiff: d.fieldsDiff
647
+ })),
648
+ compsWithNoChanges: diffResults.compsWithNoChanges,
649
+ toLaneName: diffResults.toLaneName,
650
+ fromLaneName: diffResults.fromLaneName,
651
+ failures: diffResults.failures.map(f => ({
652
+ id: f.id.toString(),
653
+ msg: f.msg
654
+ }))
655
+ };
656
+ }
554
657
  getCurrentLaneName(includeScope = false) {
555
658
  const currentLaneId = this.workspace.getCurrentLaneId();
556
659
  if (!includeScope) return currentLaneId.name;