@teambit/component 0.0.669 → 0.0.672

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.
@@ -83,6 +83,8 @@ export declare class Component {
83
83
  type?: string;
84
84
  offset?: number;
85
85
  limit?: number;
86
+ head?: string;
87
+ sort?: string;
86
88
  }): Promise<import("@teambit/legacy/scopes/component/legacy-component-log").LegacyComponentLog[]>;
87
89
  stringify(): string;
88
90
  /**
@@ -32,7 +32,19 @@ export declare function componentSchema(componentExtension: ComponentMain): {
32
32
  type?: string | undefined;
33
33
  offset?: number | undefined;
34
34
  limit?: number | undefined;
35
- } | undefined) => Promise<import("@teambit/legacy/scopes/component/legacy-component-log").LegacyComponentLog[]>;
35
+ head?: string | undefined;
36
+ sort?: string | undefined;
37
+ } | undefined) => Promise<{
38
+ id: string;
39
+ message: string;
40
+ username?: string | undefined;
41
+ email?: string | undefined;
42
+ date?: string | undefined;
43
+ hash: string;
44
+ tag?: string | undefined;
45
+ parents: string[];
46
+ onLane?: boolean | undefined;
47
+ }[]>;
36
48
  };
37
49
  ComponentHost: {
38
50
  get: (host: ComponentFactory, { id }: {
@@ -9,6 +9,16 @@ Object.defineProperty(exports, "__esModule", {
9
9
  });
10
10
  exports.componentSchema = componentSchema;
11
11
 
12
+ function _defineProperty2() {
13
+ const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
+
15
+ _defineProperty2 = function () {
16
+ return data;
17
+ };
18
+
19
+ return data;
20
+ }
21
+
12
22
  function _stripAnsi() {
13
23
  const data = _interopRequireDefault(require("strip-ansi"));
14
24
 
@@ -49,6 +59,10 @@ function _utils() {
49
59
  return data;
50
60
  }
51
61
 
62
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
63
+
64
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
65
+
52
66
  function componentSchema(componentExtension) {
53
67
  return {
54
68
  typeDefs: (0, _graphqlTag().default)`
@@ -93,7 +107,7 @@ function componentSchema(componentExtension) {
93
107
  date: String
94
108
  hash: String!
95
109
  tag: String
96
- # id: String!
110
+ id: String!
97
111
  }
98
112
 
99
113
  type Author {
@@ -136,7 +150,7 @@ function componentSchema(componentExtension) {
136
150
  tags: [Tag]!
137
151
 
138
152
  # component logs
139
- logs(type: String, offset: Int, limit: Int): [LogEntry]!
153
+ logs(type: String, offset: Int, limit: Int, head: String, sort: String): [LogEntry]!
140
154
 
141
155
  aspects(include: [String]): [Aspect]
142
156
  }
@@ -209,7 +223,9 @@ function componentSchema(componentExtension) {
209
223
  return component.state.aspects.filter(include).serialize();
210
224
  },
211
225
  logs: async (component, filter) => {
212
- return component.getLogs(filter);
226
+ return (await component.getLogs(filter)).map(log => _objectSpread(_objectSpread({}, log), {}, {
227
+ id: log.hash
228
+ }));
213
229
  }
214
230
  },
215
231
  ComponentHost: {
@@ -1 +1 @@
1
- {"version":3,"sources":["component.graphql.ts"],"names":["componentSchema","componentExtension","typeDefs","resolvers","JSONObject","GraphQLJSONObject","Component","id","component","toObject","displayName","fs","state","filesystem","files","map","file","relative","getFile","path","maybeFile","find","undefined","contents","toString","mainFile","_consumer","headTag","latest","tags","toArray","tag","aspects","include","filter","serialize","logs","getLogs","ComponentHost","get","host","componentId","resolveComponentId","error","snaps","list","listInvalid","invalidComps","err","errorName","name","errorMessage","message","Query","getHost","componentExt"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAKO,SAASA,eAAT,CAAyBC,kBAAzB,EAA4D;AACjE,SAAO;AACLC,IAAAA,QAAQ,EAAE,0BAAI;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KA5HS;AA6HLC,IAAAA,SAAS,EAAE;AACTC,MAAAA,UAAU,EAAEC,oCADH;AAETC,MAAAA,SAAS,EAAE;AACTC,QAAAA,EAAE,EAAGC,SAAD,IAA0BA,SAAS,CAACD,EAAV,CAAaE,QAAb,EADrB;AAETC,QAAAA,WAAW,EAAGF,SAAD,IAA0BA,SAAS,CAACE,WAFxC;AAGTC,QAAAA,EAAE,EAAGH,SAAD,IAA0B;AAC5B,iBAAOA,SAAS,CAACI,KAAV,CAAgBC,UAAhB,CAA2BC,KAA3B,CAAiCC,GAAjC,CAAsCC,IAAD,IAAUA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AI,CAACU,IAAZ;AACD,SA5BY;AA6BbA,QAAAA,IAAI,EAAE,MAAOV,IAAP,IAAkC;AACtC,iBAAOA,IAAI,CAACU,IAAZ;AACD;AA/BY,OA/BN;AAgETG,MAAAA,KAAK,EAAE;AACLC,QAAAA,OAAO,EAAE,CAACC,YAAD,EAA8B;AAAEhD,UAAAA;AAAF,SAA9B,KAAyD;AAChE,iBAAON,kBAAkB,CAACqD,OAAnB,CAA2B/C,EAA3B,CAAP;AACD;AAHI;AAhEE;AA7HN,GAAP;AAoMD","sourcesContent":["import stripAnsi from 'strip-ansi';\nimport gql from 'graphql-tag';\nimport { GraphQLJSONObject } from 'graphql-type-json';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\nimport { Component } from './component';\nimport { ComponentFactory } from './component-factory';\nimport { ComponentMain } from './component.main.runtime';\n\nexport function componentSchema(componentExtension: ComponentMain) {\n return {\n typeDefs: gql`\n scalar JSON\n scalar JSONObject\n\n type ComponentID {\n name: String!\n version: String\n scope: String\n }\n\n type Tag {\n # semver assigned to the tag.\n version: String!\n\n # tag hash.\n hash: String!\n }\n\n type Snap {\n # hash of the snapshot.\n hash: String!\n\n # time of the snapshot.\n timestamp: String!\n\n # parents of the snap\n parents: [Snap]!\n\n # snapper\n author: Author!\n\n # snapshot message\n message: String\n }\n\n type LogEntry {\n message: String!\n username: String\n email: String\n date: String\n hash: String!\n tag: String\n # id: String!\n }\n\n type Author {\n # display name of the snapper.\n displayName: String!\n\n # author of the snapper.\n email: String!\n }\n\n type Component {\n # id of the component.\n id: ComponentID!\n\n # head snap of the component.\n head: Snap\n\n # head tag of the component.\n headTag: Tag\n\n # list of all relative component paths.\n fs: [String]\n\n # relative path to the main file of the component\n mainFile: String\n\n # return specific file contents by relative file path.\n getFile(path: String): String\n\n # latest version of the component.\n latest: String\n\n # display name of the component\n displayName: String!\n\n # component buildStatus\n buildStatus: String\n\n # list of component releases.\n tags: [Tag]!\n\n # component logs\n logs(type: String, offset: Int, limit: Int): [LogEntry]!\n\n aspects(include: [String]): [Aspect]\n }\n\n type Aspect {\n id: String!\n icon: String\n config: JSONObject\n data: JSONObject\n }\n\n type InvalidComponent {\n id: ComponentID!\n errorName: String!\n errorMessage: String!\n }\n\n type ComponentHost {\n id: ID!\n name: String!\n\n # load a component.\n get(id: String!, withState: Boolean): Component\n\n # list components\n list(offset: Int, limit: Int): [Component]!\n\n # list invalid components and their errors\n listInvalid: [InvalidComponent]!\n\n # get component logs(snaps) by component id\n snaps(id: String!): [LogEntry]! @deprecated(reason: \"Use the logs field on Component\")\n }\n\n type Query {\n getHost(id: String): ComponentHost\n }\n `,\n resolvers: {\n JSONObject: GraphQLJSONObject,\n Component: {\n id: (component: Component) => component.id.toObject(),\n displayName: (component: Component) => component.displayName,\n fs: (component: Component) => {\n return component.state.filesystem.files.map((file) => file.relative);\n },\n getFile: (component: Component, { path }: { path: string }) => {\n const maybeFile = component.state.filesystem.files.find(\n (file) => pathNormalizeToLinux(file.relative) === path\n );\n if (!maybeFile) return undefined;\n return maybeFile.contents.toString('utf-8');\n },\n mainFile: (component: Component) => {\n return component.state._consumer.mainFile;\n },\n headTag: (component: Component) => component.headTag?.toObject(),\n latest: (component: Component) => component.latest,\n tags: (component) => {\n // graphql doesn't support map types\n return component.tags.toArray().map((tag) => tag.toObject());\n },\n aspects: (component: Component, { include }: { include?: string[] }) => {\n return component.state.aspects.filter(include).serialize();\n },\n logs: async (component: Component, filter?: { type?: string; offset?: number; limit?: number }) => {\n return component.getLogs(filter);\n },\n },\n ComponentHost: {\n get: async (host: ComponentFactory, { id }: { id: string }) => {\n try {\n const componentId = await host.resolveComponentId(id);\n const component = await host.get(componentId);\n return component;\n } catch (error: any) {\n return null;\n }\n },\n snaps: async (host: ComponentFactory, { id }: { id: string }) => {\n const componentId = await host.resolveComponentId(id);\n // return (await host.getLogs(componentId)).map(log => ({...log, id: log.hash}))\n return host.getLogs(componentId);\n },\n list: async (host: ComponentFactory, filter?: { offset: number; limit: number }) => {\n return host.list(filter);\n },\n listInvalid: async (host: ComponentFactory) => {\n const invalidComps = await host.listInvalid();\n return invalidComps.map(({ id, err }) => ({\n id,\n errorName: err.name,\n errorMessage: err.message ? stripAnsi(err.message) : err.name,\n }));\n },\n id: async (host: ComponentFactory) => {\n return host.name;\n },\n name: async (host: ComponentFactory) => {\n return host.name;\n },\n },\n Query: {\n getHost: (componentExt: ComponentMain, { id }: { id: string }) => {\n return componentExtension.getHost(id);\n },\n },\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["component.graphql.ts"],"names":["componentSchema","componentExtension","typeDefs","resolvers","JSONObject","GraphQLJSONObject","Component","id","component","toObject","displayName","fs","state","filesystem","files","map","file","relative","getFile","path","maybeFile","find","undefined","contents","toString","mainFile","_consumer","headTag","latest","tags","toArray","tag","aspects","include","filter","serialize","logs","getLogs","log","hash","ComponentHost","get","host","componentId","resolveComponentId","error","snaps","list","listInvalid","invalidComps","err","errorName","name","errorMessage","message","Query","getHost","componentExt"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAKO,SAASA,eAAT,CAAyBC,kBAAzB,EAA4D;AACjE,SAAO;AACLC,IAAAA,QAAQ,EAAE,0BAAI;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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MoC,WAAW,GAAG,MAAMD,IAAI,CAACE,kBAAL,CAAwBrC,EAAxB,CAA1B,CAD+D,CAE/D;;AACA,iBAAOmC,IAAI,CAACL,OAAL,CAAaM,WAAb,CAAP;AACD,SAdY;AAebI,QAAAA,IAAI,EAAE,OAAOL,IAAP,EAA+BR,MAA/B,KAA8E;AAClF,iBAAOQ,IAAI,CAACK,IAAL,CAAUb,MAAV,CAAP;AACD,SAjBY;AAkBbc,QAAAA,WAAW,EAAE,MAAON,IAAP,IAAkC;AAC7C,gBAAMO,YAAY,GAAG,MAAMP,IAAI,CAACM,WAAL,EAA3B;AACA,iBAAOC,YAAY,CAAClC,GAAb,CAAiB,CAAC;AAAER,YAAAA,EAAF;AAAM2C,YAAAA;AAAN,WAAD,MAAkB;AACxC3C,YAAAA,EADwC;AAExC4C,YAAAA,SAAS,EAAED,GAAG,CAACE,IAFyB;AAGxCC,YAAAA,YAAY,EAAEH,GAAG,CAACI,OAAJ,GAAc,0BAAUJ,GAAG,CAACI,OAAd,CAAd,GAAuCJ,GAAG,CAACE;AAHjB,WAAlB,CAAjB,CAAP;AAKD,SAzBY;AA0Bb7C,QAAAA,EAAE,EAAE,MAAOmC,IAAP,IAAkC;AACpC,iBAAOA,IAAI,CAACU,IAAZ;AACD,SA5BY;AA6BbA,QAAAA,IAAI,EAAE,MAAOV,IAAP,IAAkC;AACtC,iBAAOA,IAAI,CAACU,IAAZ;AACD;AA/BY,OAlCN;AAmETG,MAAAA,KAAK,EAAE;AACLC,QAAAA,OAAO,EAAE,CAACC,YAAD,EAA8B;AAAElD,UAAAA;AAAF,SAA9B,KAAyD;AAChE,iBAAON,kBAAkB,CAACuD,OAAnB,CAA2BjD,EAA3B,CAAP;AACD;AAHI;AAnEE;AA7HN,GAAP;AAuMD","sourcesContent":["import stripAnsi from 'strip-ansi';\nimport gql from 'graphql-tag';\nimport { GraphQLJSONObject } from 'graphql-type-json';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\nimport { Component } from './component';\nimport { ComponentFactory } from './component-factory';\nimport { ComponentMain } from './component.main.runtime';\n\nexport function componentSchema(componentExtension: ComponentMain) {\n return {\n typeDefs: gql`\n scalar JSON\n scalar JSONObject\n\n type ComponentID {\n name: String!\n version: String\n scope: String\n }\n\n type Tag {\n # semver assigned to the tag.\n version: String!\n\n # tag hash.\n hash: String!\n }\n\n type Snap {\n # hash of the snapshot.\n hash: String!\n\n # time of the snapshot.\n timestamp: String!\n\n # parents of the snap\n parents: [Snap]!\n\n # snapper\n author: Author!\n\n # snapshot message\n message: String\n }\n\n type LogEntry {\n message: String!\n username: String\n email: String\n date: String\n hash: String!\n tag: String\n id: String!\n }\n\n type Author {\n # display name of the snapper.\n displayName: String!\n\n # author of the snapper.\n email: String!\n }\n\n type Component {\n # id of the component.\n id: ComponentID!\n\n # head snap of the component.\n head: Snap\n\n # head tag of the component.\n headTag: Tag\n\n # list of all relative component paths.\n fs: [String]\n\n # relative path to the main file of the component\n mainFile: String\n\n # return specific file contents by relative file path.\n getFile(path: String): String\n\n # latest version of the component.\n latest: String\n\n # display name of the component\n displayName: String!\n\n # component buildStatus\n buildStatus: String\n\n # list of component releases.\n tags: [Tag]!\n\n # component logs\n logs(type: String, offset: Int, limit: Int, head: String, sort: String): [LogEntry]!\n\n aspects(include: [String]): [Aspect]\n }\n\n type Aspect {\n id: String!\n icon: String\n config: JSONObject\n data: JSONObject\n }\n\n type InvalidComponent {\n id: ComponentID!\n errorName: String!\n errorMessage: String!\n }\n\n type ComponentHost {\n id: ID!\n name: String!\n\n # load a component.\n get(id: String!, withState: Boolean): Component\n\n # list components\n list(offset: Int, limit: Int): [Component]!\n\n # list invalid components and their errors\n listInvalid: [InvalidComponent]!\n\n # get component logs(snaps) by component id\n snaps(id: String!): [LogEntry]! @deprecated(reason: \"Use the logs field on Component\")\n }\n\n type Query {\n getHost(id: String): ComponentHost\n }\n `,\n resolvers: {\n JSONObject: GraphQLJSONObject,\n Component: {\n id: (component: Component) => component.id.toObject(),\n displayName: (component: Component) => component.displayName,\n fs: (component: Component) => {\n return component.state.filesystem.files.map((file) => file.relative);\n },\n getFile: (component: Component, { path }: { path: string }) => {\n const maybeFile = component.state.filesystem.files.find(\n (file) => pathNormalizeToLinux(file.relative) === path\n );\n if (!maybeFile) return undefined;\n return maybeFile.contents.toString('utf-8');\n },\n mainFile: (component: Component) => {\n return component.state._consumer.mainFile;\n },\n headTag: (component: Component) => component.headTag?.toObject(),\n latest: (component: Component) => component.latest,\n tags: (component) => {\n // graphql doesn't support map types\n return component.tags.toArray().map((tag) => tag.toObject());\n },\n aspects: (component: Component, { include }: { include?: string[] }) => {\n return component.state.aspects.filter(include).serialize();\n },\n logs: async (\n component: Component,\n filter?: { type?: string; offset?: number; limit?: number; head?: string; sort?: string }\n ) => {\n return (await component.getLogs(filter)).map((log) => ({ ...log, id: log.hash }));\n },\n },\n ComponentHost: {\n get: async (host: ComponentFactory, { id }: { id: string }) => {\n try {\n const componentId = await host.resolveComponentId(id);\n const component = await host.get(componentId);\n return component;\n } catch (error: any) {\n return null;\n }\n },\n snaps: async (host: ComponentFactory, { id }: { id: string }) => {\n const componentId = await host.resolveComponentId(id);\n // return (await host.getLogs(componentId)).map(log => ({...log, id: log.hash}))\n return host.getLogs(componentId);\n },\n list: async (host: ComponentFactory, filter?: { offset: number; limit: number }) => {\n return host.list(filter);\n },\n listInvalid: async (host: ComponentFactory) => {\n const invalidComps = await host.listInvalid();\n return invalidComps.map(({ id, err }) => ({\n id,\n errorName: err.name,\n errorMessage: err.message ? stripAnsi(err.message) : err.name,\n }));\n },\n id: async (host: ComponentFactory) => {\n return host.name;\n },\n name: async (host: ComponentFactory) => {\n return host.name;\n },\n },\n Query: {\n getHost: (componentExt: ComponentMain, { id }: { id: string }) => {\n return componentExtension.getHost(id);\n },\n },\n },\n };\n}\n"]}
package/dist/component.js CHANGED
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  require("core-js/modules/es.symbol.description.js");
4
6
 
5
7
  require("core-js/modules/es.symbol.async-iterator.js");
6
8
 
7
9
  require("core-js/modules/es.array.iterator.js");
8
10
 
11
+ require("core-js/modules/es.array.sort.js");
12
+
9
13
  require("core-js/modules/es.promise.js");
10
14
 
11
15
  require("core-js/modules/es.regexp.exec.js");
@@ -15,6 +19,16 @@ Object.defineProperty(exports, "__esModule", {
15
19
  });
16
20
  exports.Component = void 0;
17
21
 
22
+ function _defineProperty2() {
23
+ const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
24
+
25
+ _defineProperty2 = function () {
26
+ return data;
27
+ };
28
+
29
+ return data;
30
+ }
31
+
18
32
  function _toolboxString() {
19
33
  const data = require("@teambit/toolbox.string.capitalize");
20
34
 
@@ -25,6 +39,16 @@ function _toolboxString() {
25
39
  return data;
26
40
  }
27
41
 
42
+ function _componentId() {
43
+ const data = require("@teambit/component-id");
44
+
45
+ _componentId = function () {
46
+ return data;
47
+ };
48
+
49
+ return data;
50
+ }
51
+
28
52
  function _bitError() {
29
53
  const data = require("@teambit/bit-error");
30
54
 
@@ -65,6 +89,10 @@ function _exceptions() {
65
89
  return data;
66
90
  }
67
91
 
92
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
93
+
94
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
95
+
68
96
  function _asyncIterator(iterable) { var method, async, sync, retry = 2; for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) { if (async && null != (method = iterable[async])) return method.call(iterable); if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable)); async = "@@asyncIterator", sync = "@@iterator"; } throw new TypeError("Object is not async iterable"); }
69
97
 
70
98
  function AsyncFromSyncIterator(s) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var done = r.done; return Promise.resolve(r.value).then(function (value) { return { value: value, done: done }; }); } return AsyncFromSyncIterator = function (s) { this.s = s, this.n = s.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function () { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, return: function (value) { var ret = this.s.return; return void 0 === ret ? Promise.resolve({ value: value, done: !0 }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments)); }, throw: function (value) { var thr = this.s.return; return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(s); }
@@ -157,12 +185,17 @@ class Component {
157
185
  }
158
186
 
159
187
  async getLogs(filter) {
160
- const allLogs = await this.factory.getLogs(this.id);
188
+ const componentIdObj = this.id.toObject();
189
+ const id = !(filter !== null && filter !== void 0 && filter.head) ? await this.factory.resolveComponentId(this.id.toStringWithoutVersion()) : await this.factory.resolveComponentId(_componentId().ComponentID.fromObject(_objectSpread(_objectSpread({}, componentIdObj), {}, {
190
+ version: filter.head
191
+ })));
192
+ const allLogs = await this.factory.getLogs(id);
161
193
  if (!filter) return allLogs;
162
194
  const {
163
195
  type,
164
196
  limit,
165
- offset
197
+ offset,
198
+ sort
166
199
  } = filter;
167
200
 
168
201
  const typeFilter = snap => {
@@ -177,7 +210,8 @@ class Component {
177
210
  filteredLogs = (0, _lodash().slice)(filteredLogs, offset, limit + (offset || 0));
178
211
  }
179
212
 
180
- return filteredLogs;
213
+ if (sort && sort === 'asc') return filteredLogs;
214
+ return filteredLogs.reverse();
181
215
  }
182
216
 
183
217
  stringify() {
@@ -1 +1 @@
1
- {"version":3,"sources":["component.ts"],"names":["Component","constructor","id","head","_state","tags","TagMap","factory","mainFile","state","config","filesystem","buildStatus","_consumer","headTag","undefined","byHash","hash","latest","getLatest","err","CouldNotFindLatest","getLogs","filter","allLogs","type","limit","offset","typeFilter","snap","tag","filteredLogs","stringify","JSON","displayName","tokens","name","split","map","token","join","version","isModified","Promise","resolve","isOutdated","latestTag","byVersion","isNew","loadState","snapId","getState","loadSnap","snapToGet","BitError","getSnap","snapsIterable","options","snapToStart","nextSnaps","done","iterator","next","value","currSnapId","shift","parents","length","firstParentOnly","push","concat","stopFn","Symbol","asyncIterator","getClosestTag","snapToStartFrom","tagsHashMap","getHashMap","has","iterable","snaps","hashOfLastSnap","get","checkout","write","path","fs","equals","component","toString"],"mappings":";;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAQA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAUA;AACA;AACA;AACO,MAAMA,SAAN,CAAgB;AACrBC,EAAAA,WAAW;AACT;AACJ;AACA;AACaC,EAAAA,EAJA;AAMT;AACJ;AACA;AACaC,EAAAA,IAAiB,GAAG,IATpB;AAWT;AACJ;AACA;AACYC,EAAAA,MAdC;AAgBT;AACJ;AACA;AACaC,EAAAA,IAAY,GAAG,KAAIC,gBAAJ,GAnBf;AAqBT;AACJ;AACA;AACYC,EAAAA,OAxBC,EAyBT;AAAA,SArBSL,EAqBT,GArBSA,EAqBT;AAAA,SAhBSC,IAgBT,GAhBSA,IAgBT;AAAA,SAXQC,MAWR,GAXQA,MA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,GAAZ,CAAgBjD,IAAI,CAACZ,IAArB,CAAJ,EAAgC;AAC9B,eAAO,IAAP;AACD;;AACD,aAAO,KAAP;AACD,KALD;;AAMA,UAAM8D,QAAQ,GAAG,KAAKvB,aAAL,CAAmBmB,eAAnB,EAAoC;AAAEP,MAAAA,eAAe,EAAE,IAAnB;AAAyBG,MAAAA;AAAzB,KAApC,CAAjB;AACA,UAAMS,KAAa,GAAG,EAAtB;AATsE;AAAA;;AAAA;;AAAA;AAUtE,0CAAyBD,QAAzB,iHAAmC;AAAA,cAAlBlD,IAAkB;AACjCmD,QAAAA,KAAK,CAACX,IAAN,CAAWxC,IAAX;AACD;AAZqE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAatE,QAAImD,KAAK,CAACb,MAAV,EAAkB;AAChB,YAAMc,cAAc,GAAGD,KAAK,CAACA,KAAK,CAACb,MAAN,GAAe,CAAhB,CAAL,CAAwBlD,IAA/C;AACA,aAAO2D,WAAW,CAACM,GAAZ,CAAgBD,cAAhB,CAAP;AACD;;AACD,WAAOlE,SAAP;AACD;AAED;AACF;AACA;AACE;;;AACAoE,EAAAA,QAAQ,CAAC1C,OAAD,EAAkB,CAAE;AAE5B;AACF;AACA;AACE;;AAEA;AACF;AACA;AACE;;AAEA;AACF;AACA;AACA;AACA;AACE;;;AACA2C,EAAAA,KAAK,CAACC,IAAD,EAAeC,EAAf,EAA2B,CAAE;AAElC;AACF;AACA;AACA;AACA;AACA;AACA;AACE;;;AACAC,EAAAA,MAAM,CAACC,SAAD,EAAgC;AACpC,WAAOA,SAAS,CAACtF,EAAV,CAAauF,QAAb,OAA4B,KAAKvF,EAAL,CAAQuF,QAAR,EAAnC;AACD;;AA3QoB","sourcesContent":["import { AnyFS } from '@teambit/any-fs';\nimport { capitalize } from '@teambit/toolbox.string.capitalize';\nimport { SemVer } from 'semver';\nimport { ComponentID } from '@teambit/component-id';\nimport { BitError } from '@teambit/bit-error';\nimport { BuildStatus } from '@teambit/legacy/dist/constants';\n\nimport { slice } from 'lodash';\nimport { ComponentFactory } from './component-factory';\nimport ComponentFS from './component-fs';\n// import { NothingToSnap } from './exceptions';\nimport ComponentConfig from './config';\n// eslint-disable-next-line import/no-cycle\nimport { Snap } from './snap';\nimport { State } from './state';\nimport { TagMap } from './tag-map';\nimport { Tag } from './tag';\nimport { CouldNotFindLatest } from './exceptions';\n// import { Author } from './types';\n\ntype SnapsIterableOpts = {\n firstParentOnly?: boolean;\n stopFn?: (snap: Snap) => Promise<boolean>;\n};\n\nexport type InvalidComponent = { id: ComponentID; err: Error };\n\n/**\n * in-memory representation of a component.\n */\nexport class Component {\n constructor(\n /**\n * component ID represented by the `ComponentId` type.\n */\n readonly id: ComponentID,\n\n /**\n * head version of the component. can be `null` for new components.\n */\n readonly head: Snap | null = null,\n\n /**\n * state of the component.\n */\n private _state: State,\n\n /**\n * tags of the component.\n */\n readonly tags: TagMap = new TagMap(),\n\n /**\n * the component factory\n */\n private factory: ComponentFactory\n ) {}\n\n get mainFile() {\n return this.state.mainFile;\n }\n\n get state(): State {\n return this._state;\n }\n\n set state(state: State) {\n this._state = state;\n }\n\n /**\n * component configuration which is later generated to a component `package.json` and `bit.json`.\n */\n get config(): ComponentConfig {\n return this.state.config;\n }\n\n /**\n * in-memory representation of the component current filesystem.\n */\n get filesystem(): ComponentFS {\n return this.state.filesystem;\n }\n\n /**\n * build status of the component\n */\n get buildStatus(): BuildStatus {\n return this._state._consumer.buildStatus;\n }\n\n get headTag() {\n if (!this.head) return undefined;\n return this.tags.byHash(this.head.hash);\n }\n\n get latest(): string | undefined {\n if (!this.head) return undefined;\n try {\n return this.tags.getLatest();\n } catch (err: any) {\n if (err instanceof CouldNotFindLatest) {\n return this.head.hash;\n }\n throw err;\n }\n }\n\n async getLogs(filter?: { type?: string; offset?: number; limit?: number }) {\n const allLogs = await this.factory.getLogs(this.id);\n if (!filter) return allLogs;\n const { type, limit, offset } = filter;\n const typeFilter = (snap) => {\n if (type === 'tag') return snap.tag;\n if (type === 'snap') return !snap.tag;\n return true;\n };\n let filteredLogs = (type && allLogs.filter(typeFilter)) || allLogs;\n if (limit) {\n filteredLogs = slice(filteredLogs, offset, limit + (offset || 0));\n }\n return filteredLogs;\n }\n\n stringify(): string {\n return JSON.stringify({\n id: this.id,\n head: this.head,\n });\n }\n\n /**\n * record component changes in the `Scope`.\n */\n // snap(author: Author, message = '') {\n // if (!this.isModified()) throw new NothingToSnap();\n // const snap = new Snap(this, author, message);\n\n // return new Component(this.id, snap, snap.state);\n // }\n\n /**\n * display name of the component.\n */\n get displayName() {\n const tokens = this.id.name.split('-').map((token) => capitalize(token));\n return tokens.join(' ');\n }\n\n /**\n * tag a component `Snap` with a semantic version. we follow SemVer specs as defined [here](https://semver.org/)).\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n tag(version: SemVer) {\n // const snap = this.snap();\n // const tag = new Tag(version, snap);\n // this.tags.set(tag);\n }\n\n /**\n * determines whether this component is modified in the workspace.\n */\n isModified(): Promise<boolean> {\n if (!this.head) return Promise.resolve(true);\n return Promise.resolve(this.state.isModified);\n // return Promise.resolve(this.state.hash !== this.head.hash);\n }\n\n /**\n * is component isOutdated\n */\n isOutdated(): boolean {\n if (!this.latest) return false;\n const latestTag = this.tags.byVersion(this.latest);\n if (!latestTag) return false;\n if (this.head?.hash !== latestTag?.hash) return true;\n return false;\n }\n\n /**\n * determines whether this component is new.\n */\n isNew(): Promise<boolean> {\n return Promise.resolve(this.head === null);\n }\n\n // TODO: @david after snap we need to make sure to refactor here.\n loadState(snapId: string): Promise<State> {\n return this.factory.getState(this.id, snapId);\n }\n\n loadSnap(snapId?: string): Promise<Snap> {\n const snapToGet = snapId || this.head?.hash;\n if (!snapToGet) {\n throw new BitError('could not load snap for new components');\n }\n return this.factory.getSnap(this.id, snapToGet);\n }\n\n /**\n * Get iterable which iterate over snap parents lazily\n * @param snapId\n * @param options\n */\n snapsIterable(snapId?: string, options: SnapsIterableOpts = {}): AsyncIterable<Snap> {\n const snapToStart = snapId || this.head?.hash;\n let nextSnaps = [snapToStart];\n let done;\n if (!snapToStart) {\n done = true;\n }\n\n const iterator: AsyncIterator<Snap> = {\n next: async () => {\n if (done) {\n return { value: undefined, done };\n }\n const currSnapId = nextSnaps.shift();\n const snap = await this.loadSnap(currSnapId);\n if (snap.parents && snap.parents.length) {\n if (options.firstParentOnly) {\n nextSnaps.push(snap.parents[0]);\n } else {\n nextSnaps = nextSnaps.concat(snap.parents);\n }\n }\n if (!nextSnaps.length) {\n done = true;\n } else if (options.stopFn) {\n done = await options.stopFn(snap);\n }\n return { value: snap, done: undefined };\n },\n };\n return {\n [Symbol.asyncIterator]: () => iterator,\n };\n }\n\n /**\n * traverse recursively from the provided snap (or head) upwards until it finds a tag\n * @param snapToStartFrom\n */\n async getClosestTag(snapToStartFrom?: string): Promise<Tag | undefined> {\n const tagsHashMap = this.tags.getHashMap();\n const stopFn = async (snap: Snap) => {\n if (tagsHashMap.has(snap.hash)) {\n return true;\n }\n return false;\n };\n const iterable = this.snapsIterable(snapToStartFrom, { firstParentOnly: true, stopFn });\n const snaps: Snap[] = [];\n for await (const snap of iterable) {\n snaps.push(snap);\n }\n if (snaps.length) {\n const hashOfLastSnap = snaps[snaps.length - 1].hash;\n return tagsHashMap.get(hashOfLastSnap);\n }\n return undefined;\n }\n\n /**\n * checkout the component to a different version in its working tree.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n checkout(version: SemVer) {}\n\n /**\n * examine difference between two components.\n */\n // diff(other: Component): Difference {}\n\n /**\n * merge two different components\n */\n // merge(other: Component): Component {}\n\n /**\n * write a component to a given file system.\n * @param path root path to write the component\n * @param fs instance of any fs to use.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n write(path: string, fs?: AnyFS) {}\n\n /**\n *\n * Check if 2 components are equal\n * @param {Component} component\n * @returns {boolean}\n * @memberof Component\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n equals(component: Component): boolean {\n return component.id.toString() === this.id.toString();\n }\n}\n"]}
1
+ {"version":3,"sources":["component.ts"],"names":["Component","constructor","id","head","_state","tags","TagMap","factory","mainFile","state","config","filesystem","buildStatus","_consumer","headTag","undefined","byHash","hash","latest","getLatest","err","CouldNotFindLatest","getLogs","filter","componentIdObj","toObject","resolveComponentId","toStringWithoutVersion","ComponentID","fromObject","version","allLogs","type","limit","offset","sort","typeFilter","snap","tag","filteredLogs","reverse","stringify","JSON","displayName","tokens","name","split","map","token","join","isModified","Promise","resolve","isOutdated","latestTag","byVersion","isNew","loadState","snapId","getState","loadSnap","snapToGet","BitError","getSnap","snapsIterable","options","snapToStart","nextSnaps","done","iterator","next","value","currSnapId","shift","parents","length","firstParentOnly","push","concat","stopFn","Symbol","asyncIterator","getClosestTag","snapToStartFrom","tagsHashMap","getHashMap","has","iterable","snaps","hashOfLastSnap","get","checkout","write","path","fs","equals","component","toString"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAQA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;;;;;AAUA;AACA;AACA;AACO,MAAMA,SAAN,CAAgB;AACrBC,EAAAA,WAAW;AACT;AACJ;AACA;AACaC,EAAAA,EAJA;AAMT;AACJ;AACA;AACaC,EAAAA,IAAiB,GAAG,IATpB;AAWT;AACJ;AACA;AACYC,EAAAA,MAdC;AAgBT;AACJ;AACA;AACaC,EAAAA,IAAY,GAAG,KAAIC,gBAAJ,GAnBf;AAqBT;AACJ;AACA;AACYC,EAAAA,OAxBC,EAyBT;AAAA,SArBSL,EAqBT,GArBSA,E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,WAAO1E,SAAP;AACD;AAED;AACF;AACA;AACE;;;AACA4E,EAAAA,QAAQ,CAAC7D,OAAD,EAAkB,CAAE;AAE5B;AACF;AACA;AACE;;AAEA;AACF;AACA;AACE;;AAEA;AACF;AACA;AACA;AACA;AACE;;;AACA8D,EAAAA,KAAK,CAACC,IAAD,EAAeC,EAAf,EAA2B,CAAE;AAElC;AACF;AACA;AACA;AACA;AACA;AACA;AACE;;;AACAC,EAAAA,MAAM,CAACC,SAAD,EAAgC;AACpC,WAAOA,SAAS,CAAC9F,EAAV,CAAa+F,QAAb,OAA4B,KAAK/F,EAAL,CAAQ+F,QAAR,EAAnC;AACD;;AAxRoB","sourcesContent":["import { AnyFS } from '@teambit/any-fs';\nimport { capitalize } from '@teambit/toolbox.string.capitalize';\nimport { SemVer } from 'semver';\nimport { ComponentID } from '@teambit/component-id';\nimport { BitError } from '@teambit/bit-error';\nimport { BuildStatus } from '@teambit/legacy/dist/constants';\n\nimport { slice } from 'lodash';\nimport { ComponentFactory } from './component-factory';\nimport ComponentFS from './component-fs';\n// import { NothingToSnap } from './exceptions';\nimport ComponentConfig from './config';\n// eslint-disable-next-line import/no-cycle\nimport { Snap } from './snap';\nimport { State } from './state';\nimport { TagMap } from './tag-map';\nimport { Tag } from './tag';\nimport { CouldNotFindLatest } from './exceptions';\n// import { Author } from './types';\n\ntype SnapsIterableOpts = {\n firstParentOnly?: boolean;\n stopFn?: (snap: Snap) => Promise<boolean>;\n};\n\nexport type InvalidComponent = { id: ComponentID; err: Error };\n\n/**\n * in-memory representation of a component.\n */\nexport class Component {\n constructor(\n /**\n * component ID represented by the `ComponentId` type.\n */\n readonly id: ComponentID,\n\n /**\n * head version of the component. can be `null` for new components.\n */\n readonly head: Snap | null = null,\n\n /**\n * state of the component.\n */\n private _state: State,\n\n /**\n * tags of the component.\n */\n readonly tags: TagMap = new TagMap(),\n\n /**\n * the component factory\n */\n private factory: ComponentFactory\n ) {}\n\n get mainFile() {\n return this.state.mainFile;\n }\n\n get state(): State {\n return this._state;\n }\n\n set state(state: State) {\n this._state = state;\n }\n\n /**\n * component configuration which is later generated to a component `package.json` and `bit.json`.\n */\n get config(): ComponentConfig {\n return this.state.config;\n }\n\n /**\n * in-memory representation of the component current filesystem.\n */\n get filesystem(): ComponentFS {\n return this.state.filesystem;\n }\n\n /**\n * build status of the component\n */\n get buildStatus(): BuildStatus {\n return this._state._consumer.buildStatus;\n }\n\n get headTag() {\n if (!this.head) return undefined;\n return this.tags.byHash(this.head.hash);\n }\n\n get latest(): string | undefined {\n if (!this.head) return undefined;\n try {\n return this.tags.getLatest();\n } catch (err: any) {\n if (err instanceof CouldNotFindLatest) {\n return this.head.hash;\n }\n throw err;\n }\n }\n\n async getLogs(filter?: { type?: string; offset?: number; limit?: number; head?: string; sort?: string }) {\n const componentIdObj = this.id.toObject();\n\n const id = !filter?.head\n ? await this.factory.resolveComponentId(this.id.toStringWithoutVersion())\n : await this.factory.resolveComponentId(ComponentID.fromObject({ ...componentIdObj, version: filter.head }));\n\n const allLogs = await this.factory.getLogs(id);\n\n if (!filter) return allLogs;\n\n const { type, limit, offset, sort } = filter;\n\n const typeFilter = (snap) => {\n if (type === 'tag') return snap.tag;\n if (type === 'snap') return !snap.tag;\n return true;\n };\n\n let filteredLogs = (type && allLogs.filter(typeFilter)) || allLogs;\n if (limit) {\n filteredLogs = slice(filteredLogs, offset, limit + (offset || 0));\n }\n\n if (sort && sort === 'asc') return filteredLogs;\n\n return filteredLogs.reverse();\n }\n\n stringify(): string {\n return JSON.stringify({\n id: this.id,\n head: this.head,\n });\n }\n\n /**\n * record component changes in the `Scope`.\n */\n // snap(author: Author, message = '') {\n // if (!this.isModified()) throw new NothingToSnap();\n // const snap = new Snap(this, author, message);\n\n // return new Component(this.id, snap, snap.state);\n // }\n\n /**\n * display name of the component.\n */\n get displayName() {\n const tokens = this.id.name.split('-').map((token) => capitalize(token));\n return tokens.join(' ');\n }\n\n /**\n * tag a component `Snap` with a semantic version. we follow SemVer specs as defined [here](https://semver.org/)).\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n tag(version: SemVer) {\n // const snap = this.snap();\n // const tag = new Tag(version, snap);\n // this.tags.set(tag);\n }\n\n /**\n * determines whether this component is modified in the workspace.\n */\n isModified(): Promise<boolean> {\n if (!this.head) return Promise.resolve(true);\n return Promise.resolve(this.state.isModified);\n // return Promise.resolve(this.state.hash !== this.head.hash);\n }\n\n /**\n * is component isOutdated\n */\n isOutdated(): boolean {\n if (!this.latest) return false;\n const latestTag = this.tags.byVersion(this.latest);\n if (!latestTag) return false;\n if (this.head?.hash !== latestTag?.hash) return true;\n return false;\n }\n\n /**\n * determines whether this component is new.\n */\n isNew(): Promise<boolean> {\n return Promise.resolve(this.head === null);\n }\n\n // TODO: @david after snap we need to make sure to refactor here.\n loadState(snapId: string): Promise<State> {\n return this.factory.getState(this.id, snapId);\n }\n\n loadSnap(snapId?: string): Promise<Snap> {\n const snapToGet = snapId || this.head?.hash;\n if (!snapToGet) {\n throw new BitError('could not load snap for new components');\n }\n return this.factory.getSnap(this.id, snapToGet);\n }\n\n /**\n * Get iterable which iterate over snap parents lazily\n * @param snapId\n * @param options\n */\n snapsIterable(snapId?: string, options: SnapsIterableOpts = {}): AsyncIterable<Snap> {\n const snapToStart = snapId || this.head?.hash;\n let nextSnaps = [snapToStart];\n let done;\n if (!snapToStart) {\n done = true;\n }\n\n const iterator: AsyncIterator<Snap> = {\n next: async () => {\n if (done) {\n return { value: undefined, done };\n }\n const currSnapId = nextSnaps.shift();\n const snap = await this.loadSnap(currSnapId);\n if (snap.parents && snap.parents.length) {\n if (options.firstParentOnly) {\n nextSnaps.push(snap.parents[0]);\n } else {\n nextSnaps = nextSnaps.concat(snap.parents);\n }\n }\n if (!nextSnaps.length) {\n done = true;\n } else if (options.stopFn) {\n done = await options.stopFn(snap);\n }\n return { value: snap, done: undefined };\n },\n };\n return {\n [Symbol.asyncIterator]: () => iterator,\n };\n }\n\n /**\n * traverse recursively from the provided snap (or head) upwards until it finds a tag\n * @param snapToStartFrom\n */\n async getClosestTag(snapToStartFrom?: string): Promise<Tag | undefined> {\n const tagsHashMap = this.tags.getHashMap();\n const stopFn = async (snap: Snap) => {\n if (tagsHashMap.has(snap.hash)) {\n return true;\n }\n return false;\n };\n const iterable = this.snapsIterable(snapToStartFrom, { firstParentOnly: true, stopFn });\n const snaps: Snap[] = [];\n for await (const snap of iterable) {\n snaps.push(snap);\n }\n if (snaps.length) {\n const hashOfLastSnap = snaps[snaps.length - 1].hash;\n return tagsHashMap.get(hashOfLastSnap);\n }\n return undefined;\n }\n\n /**\n * checkout the component to a different version in its working tree.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n checkout(version: SemVer) {}\n\n /**\n * examine difference between two components.\n */\n // diff(other: Component): Difference {}\n\n /**\n * merge two different components\n */\n // merge(other: Component): Component {}\n\n /**\n * write a component to a given file system.\n * @param path root path to write the component\n * @param fs instance of any fs to use.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n write(path: string, fs?: AnyFS) {}\n\n /**\n *\n * Check if 2 components are equal\n * @param {Component} component\n * @returns {boolean}\n * @memberof Component\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n equals(component: Component): boolean {\n return component.id.toString() === this.id.toString();\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["component-context.ts"],"names":["ComponentContext","ComponentModel","empty","ComponentDescriptorContext","undefined","useComponentDescriptor"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,gBAA+C,gBAAG,4BAA8BC,iCAAeC,KAAf,EAA9B,CAAxD;;AACA,MAAMC,0BAA0E,gBAAG,4BAExFC,SAFwF,CAAnF;;;AAIA,MAAMC,sBAAsB,GAAG,MAAM,yBAAWF,0BAAX,CAArC","sourcesContent":["import { createContext, useContext } from 'react';\nimport type { ComponentDescriptor } from '@teambit/component-descriptor';\n\nimport { ComponentModel } from '../component-model';\n\nexport const ComponentContext: React.Context<ComponentModel> = createContext<ComponentModel>(ComponentModel.empty());\nexport const ComponentDescriptorContext: React.Context<ComponentDescriptor | undefined> = createContext<\n ComponentDescriptor | undefined\n>(undefined);\n\nexport const useComponentDescriptor = () => useContext(ComponentDescriptorContext)"]}
1
+ {"version":3,"sources":["component-context.ts"],"names":["ComponentContext","ComponentModel","empty","ComponentDescriptorContext","undefined","useComponentDescriptor"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,gBAA+C,gBAAG,4BAA8BC,iCAAeC,KAAf,EAA9B,CAAxD;;AACA,MAAMC,0BAA0E,gBAAG,4BAExFC,SAFwF,CAAnF;;;AAIA,MAAMC,sBAAsB,GAAG,MAAM,yBAAWF,0BAAX,CAArC","sourcesContent":["import { createContext, useContext } from 'react';\nimport type { ComponentDescriptor } from '@teambit/component-descriptor';\n\nimport { ComponentModel } from '../component-model';\n\nexport const ComponentContext: React.Context<ComponentModel> = createContext<ComponentModel>(ComponentModel.empty());\nexport const ComponentDescriptorContext: React.Context<ComponentDescriptor | undefined> = createContext<\n ComponentDescriptor | undefined\n>(undefined);\n\nexport const useComponentDescriptor = () => useContext(ComponentDescriptorContext);\n"]}
@@ -2,7 +2,15 @@ import { ComponentDescriptor } from '@teambit/component-descriptor';
2
2
  import { ComponentModel } from './component-model';
3
3
  import { ComponentError } from './component-error';
4
4
  /** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
5
- export declare function useComponentQuery(componentId: string, host: string): {
5
+ export declare function useComponentQuery(componentId: string, host: string, filters?: {
6
+ log?: {
7
+ logType?: string;
8
+ logOffset?: number;
9
+ logLimit?: number;
10
+ logHead?: string;
11
+ logSort?: string;
12
+ };
13
+ }): {
6
14
  componentDescriptor: ComponentDescriptor | undefined;
7
15
  component: ComponentModel | undefined;
8
16
  error: ComponentError | undefined;
@@ -103,7 +103,7 @@ const componentFields = (0, _client().gql)`
103
103
  id {
104
104
  ...componentIdFields
105
105
  }
106
- aspects(include: ["teambit.preview/preview", "teambit.pipelines/builder"]) {
106
+ aspects(include: ["teambit.preview/preview", "teambit.pipelines/builder", "teambit.envs/envs"]) {
107
107
  # 'id' property in gql refers to a *global* identifier and used for caching.
108
108
  # this makes aspect data cache under the same key, even when they are under different components.
109
109
  # renaming the property fixes that.
@@ -132,7 +132,8 @@ const componentFields = (0, _client().gql)`
132
132
  id
133
133
  icon
134
134
  }
135
- logs(type: $logType, offset: $logOffset, limit: $logLimit) {
135
+ logs(type: $logType, offset: $logOffset, limit: $logLimit, head: $logHead, sort: $logSort) {
136
+ id
136
137
  message
137
138
  username
138
139
  email
@@ -147,7 +148,15 @@ const componentFields = (0, _client().gql)`
147
148
  ${componentIdFields}
148
149
  `;
149
150
  const GET_COMPONENT = (0, _client().gql)`
150
- query Component($id: String!, $extensionId: String!, $logType: String, $logOffset: Int, $logLimit: Int) {
151
+ query Component(
152
+ $id: String!
153
+ $extensionId: String!
154
+ $logType: String
155
+ $logOffset: Int
156
+ $logLimit: Int
157
+ $logHead: String
158
+ $logSort: String
159
+ ) {
151
160
  getHost(id: $extensionId) {
152
161
  id # used for GQL caching
153
162
  get(id: $id) {
@@ -158,7 +167,7 @@ const GET_COMPONENT = (0, _client().gql)`
158
167
  ${componentFields}
159
168
  `;
160
169
  const SUB_SUBSCRIPTION_ADDED = (0, _client().gql)`
161
- subscription OnComponentAdded($logType: String, $logOffset: Int, $logLimit: Int) {
170
+ subscription OnComponentAdded($logType: String, $logOffset: Int, $logLimit: Int, $logHead: String, $logSort: String) {
162
171
  componentAdded {
163
172
  component {
164
173
  ...componentFields
@@ -168,7 +177,13 @@ const SUB_SUBSCRIPTION_ADDED = (0, _client().gql)`
168
177
  ${componentFields}
169
178
  `;
170
179
  const SUB_COMPONENT_CHANGED = (0, _client().gql)`
171
- subscription OnComponentChanged($logType: String, $logOffset: Int, $logLimit: Int) {
180
+ subscription OnComponentChanged(
181
+ $logType: String
182
+ $logOffset: Int
183
+ $logLimit: Int
184
+ $logHead: String
185
+ $logSort: String
186
+ ) {
172
187
  componentChanged {
173
188
  component {
174
189
  ...componentFields
@@ -189,7 +204,7 @@ const SUB_COMPONENT_REMOVED = (0, _client().gql)`
189
204
  `;
190
205
  /** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
191
206
 
192
- function useComponentQuery(componentId, host) {
207
+ function useComponentQuery(componentId, host, filters) {
193
208
  var _data$getHost;
194
209
 
195
210
  const idRef = (0, _react().useRef)(componentId);
@@ -200,10 +215,10 @@ function useComponentQuery(componentId, host) {
200
215
  loading,
201
216
  subscribeToMore
202
217
  } = (0, _uiFoundationUiHooks().useDataQuery)(GET_COMPONENT, {
203
- variables: {
218
+ variables: _objectSpread({
204
219
  id: componentId,
205
220
  extensionId: host
206
- }
221
+ }, (filters === null || filters === void 0 ? void 0 : filters.log) || {})
207
222
  });
208
223
  (0, _react().useEffect)(() => {
209
224
  // @TODO @Kutner fix subscription for scope
@@ -1 +1 @@
1
- {"version":3,"sources":["use-component-query.ts"],"names":["componentIdFields","componentFields","GET_COMPONENT","SUB_SUBSCRIPTION_ADDED","SUB_COMPONENT_CHANGED","SUB_COMPONENT_REMOVED","useComponentQuery","componentId","host","idRef","current","data","error","loading","subscribeToMore","variables","id","extensionId","unsubAddition","document","updateQuery","prev","subscriptionData","prevComponent","getHost","get","addedComponent","componentAdded","component","name","unsubChanges","updatedComponent","componentChanged","isUpdated","ComponentID","isEqualObj","unsubRemoval","removedIds","componentRemoved","componentIds","length","isRemoved","some","removedId","rawComponent","aspectList","entries","aspects","fromObject","componentDescriptor","ComponentDescriptor","toString","undefined","ComponentModel","from","ComponentError","message"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAEA,MAAMA,iBAAiB,GAAG,kBAAI;AAC9B;AACA;AACA;AACA;AACA;AACA,CANA;AAQA,MAAMC,eAAe,GAAG,kBAAI;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAID,iBAAkB;AACtB,CA/CA;AAiDA,MAAME,aAAa,GAAG,kBAAI;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAID,eAAgB;AACpB,CAVA;AAYA,MAAME,sBAAsB,GAAG,kBAAI;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIF,eAAgB;AACpB,CATA;AAWA,MAAMG,qBAAqB,GAAG,kBAAI;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIH,eAAgB;AACpB,CATA;AAWA,MAAMI,qBAAqB,GAAG,kBAAI;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIL,iBAAkB;AACtB,CATA;AAWA;;AACO,SAASM,iBAAT,CAA2BC,WAA3B,EAAgDC,IAAhD,EAA8D;AAAA;;AACnE,QAAMC,KAAK,GAAG,qBAAOF,WAAP,CAAd;AACAE,EAAAA,KAAK,CAACC,OAAN,GAAgBH,WAAhB;AACA,QAAM;AAAEI,IAAAA,IAAF;AAAQC,IAAAA,KAAR;AAAeC,IAAAA,OAAf;AAAwBC,IA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cesContent":["import { useMemo, useEffect, useRef } from 'react';\nimport { gql } from '@apollo/client';\nimport { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';\nimport { ComponentID, ComponentIdObj } from '@teambit/component-id';\nimport { ComponentDescriptor } from '@teambit/component-descriptor';\n\nimport { ComponentModel } from './component-model';\nimport { ComponentError } from './component-error';\n\nconst componentIdFields = gql`\n fragment componentIdFields on ComponentID {\n name\n version\n scope\n }\n`;\n\nconst componentFields = gql`\n fragment componentFields on Component {\n id {\n ...componentIdFields\n }\n aspects(include: [\"teambit.preview/preview\", \"teambit.pipelines/builder\"]) {\n # 'id' property in gql refers to a *global* identifier and used for caching.\n # this makes aspect data cache under the same key, even when they are under different components.\n # renaming the property fixes that.\n aspectId: id\n aspectData: data\n }\n packageName\n elementsUrl\n description\n labels\n displayName\n latest\n server {\n env\n url\n }\n buildStatus\n compositions {\n identifier\n displayName\n }\n tags {\n version\n }\n env {\n id\n icon\n }\n logs(type: $logType, offset: $logOffset, limit: $logLimit) {\n message\n username\n email\n date\n hash\n tag\n }\n preview {\n includesEnvTemplate\n }\n }\n ${componentIdFields}\n`;\n\nconst GET_COMPONENT = gql`\n query Component($id: String!, $extensionId: String!, $logType: String, $logOffset: Int, $logLimit: Int) {\n getHost(id: $extensionId) {\n id # used for GQL caching\n get(id: $id) {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_SUBSCRIPTION_ADDED = gql`\n subscription OnComponentAdded($logType: String, $logOffset: Int, $logLimit: Int) {\n componentAdded {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_CHANGED = gql`\n subscription OnComponentChanged($logType: String, $logOffset: Int, $logLimit: Int) {\n componentChanged {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_REMOVED = gql`\n subscription OnComponentRemoved {\n componentRemoved {\n componentIds {\n ...componentIdFields\n }\n }\n }\n ${componentIdFields}\n`;\n\n/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */\nexport function useComponentQuery(componentId: string, host: string) {\n const idRef = useRef(componentId);\n idRef.current = componentId;\n const { data, error, loading, subscribeToMore } = useDataQuery(GET_COMPONENT, {\n variables: { id: componentId, extensionId: host },\n });\n\n useEffect(() => {\n // @TODO @Kutner fix subscription for scope\n if (host !== 'teambit.workspace/workspace') {\n return () => {};\n }\n\n const unsubAddition = subscribeToMore({\n document: SUB_SUBSCRIPTION_ADDED,\n updateQuery: (prev, { subscriptionData }) => {\n const prevComponent = prev?.getHost?.get;\n const addedComponent = subscriptionData?.data?.componentAdded?.component;\n\n if (!addedComponent || prevComponent) return prev;\n\n if (idRef.current === addedComponent.id.name) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: addedComponent,\n },\n };\n }\n\n return prev;\n },\n });\n\n const unsubChanges = subscribeToMore({\n document: SUB_COMPONENT_CHANGED,\n updateQuery: (prev, { subscriptionData }) => {\n if (!subscriptionData.data) return prev;\n\n const prevComponent = prev?.getHost?.get;\n const updatedComponent = subscriptionData?.data?.componentChanged?.component;\n\n const isUpdated = updatedComponent && ComponentID.isEqualObj(prevComponent?.id, updatedComponent?.id);\n\n if (isUpdated) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: updatedComponent,\n },\n };\n }\n\n return prev;\n },\n });\n\n const unsubRemoval = subscribeToMore({\n document: SUB_COMPONENT_REMOVED,\n updateQuery: (prev, { subscriptionData }) => {\n if (!subscriptionData.data) return prev;\n\n const prevComponent = prev?.getHost?.get;\n const removedIds: ComponentIdObj[] | undefined = subscriptionData?.data?.componentRemoved?.componentIds;\n if (!prevComponent || !removedIds?.length) return prev;\n\n const isRemoved = removedIds.some((removedId) => ComponentID.isEqualObj(removedId, prevComponent.id));\n\n if (isRemoved) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: null,\n },\n };\n }\n\n return prev;\n },\n });\n\n return () => {\n unsubChanges();\n unsubAddition();\n unsubRemoval();\n };\n }, []);\n\n const rawComponent = data?.getHost?.get;\n return useMemo(() => {\n const aspectList = {\n entries: rawComponent?.aspects,\n };\n const id = rawComponent && ComponentID.fromObject(rawComponent.id);\n return {\n componentDescriptor: id ? ComponentDescriptor.fromObject({ id: id.toString(), aspectList }) : undefined,\n component: rawComponent ? ComponentModel.from({ ...rawComponent, host }) : undefined,\n // eslint-disable-next-line\n error: error\n ? new ComponentError(500, error.message)\n : !rawComponent && !loading\n ? new ComponentError(404)\n : undefined,\n };\n }, [rawComponent, host, error]);\n}\n"]}
1
+ {"version":3,"sources":["use-component-query.ts"],"names":["componentIdFields","componentFields","GET_COMPONENT","SUB_SUBSCRIPTION_ADDED","SUB_COMPONENT_CHANGED","SUB_COMPONENT_REMOVED","useComponentQuery","componentId","host","filters","idRef","current","data","error","loading","subscribeToMore","variables","id","extensionId","log","unsubAddition","document","updateQuery","prev","subscriptionData","prevComponent","getHost","get","addedComponent","componentAdded","component","name","unsubChanges","updatedComponent","componentChanged","isUpdated","ComponentID","isEqualObj","unsubRemoval","removedIds","componentRemoved","componentIds","length","isRemoved","some","removedId","rawComponent","aspectList","entries","aspects","fromObject","componentDescriptor","ComponentDescriptor","toString","undefined","ComponentModel","from","ComponentError","message"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAEA,MAAMA,iBAAiB,GAAG,kBAAI;AAC9B;AACA;AACA;AACA;AACA;AACA,CANA;AAQA,MAAMC,eAAe,GAAG,kBAAI;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAID,iBAAkB;AACtB,CAhDA;AAkDA,MAAME,aAAa,GAAG,kBAAI;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAID,eAAgB;AACpB,CAlBA;AAoBA,MAAME,sBAAsB,GAAG,kBAAI;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIF,eAAgB;AACpB,CATA;AAWA,MAAMG,qBAAqB,GAAG,kBAAI;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIH,eAAgB;AACpB,CAfA;AAiBA,MAAMI,qBAAqB,GAAG,kBAAI;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIL,iBAAkB;AACtB,CATA;AAWA;;AACO,SAASM,iBAAT,CACLC,WADK,EAELC,IAFK,EAGLC,OAHK,EAIL;AAAA;;AACA,QAAMC,KAAK,GAAG,qBAAOH,WAAP,CAAd;AACAG,EAAAA,KAAK,CAACC,OAAN,GAAgBJ,WAAhB;AACA,QAAM;AAAEK,IAAAA,IAAF;AAAQC,IAAAA,KAAR;AAAeC,IAAAA,OAAf;AAAwBC,IAAAA;AAAxB,MAA4C,yCAAab,aAAb,EAA4B;AAC5Ec,IAAAA,SAAS;AAAIC,MAAAA,EAAE,EAAEV,WAAR;AAAqBW,MAAAA,WAAW,EAAEV;AAAlC,OAA4C,CAAAC,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEU,GAAT,KAAgB,EAA5D;AADmE,GAA5B,CAAlD;AAIA,0BAAU,MAAM;AACd;AACA,QAAI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ApC;AAyBA,WAAO,MAAM;AACXS,MAAAA,YAAY;AACZZ,MAAAA,aAAa;AACbkB,MAAAA,YAAY;AACb,KAJD;AAKD,GAlFD,EAkFG,EAlFH;AAoFA,QAAMQ,YAAY,GAAGlC,IAAH,aAAGA,IAAH,wCAAGA,IAAI,CAAEc,OAAT,kDAAG,cAAeC,GAApC;AACA,SAAO,sBAAQ,MAAM;AACnB,UAAMoB,UAAU,GAAG;AACjBC,MAAAA,OAAO,EAAEF,YAAF,aAAEA,YAAF,uBAAEA,YAAY,CAAEG;AADN,KAAnB;;AAGA,UAAMhC,EAAE,GAAG6B,YAAY,IAAIV,2BAAYc,UAAZ,CAAuBJ,YAAY,CAAC7B,EAApC,CAA3B;;AACA,WAAO;AACLkC,MAAAA,mBAAmB,EAAElC,EAAE,GAAGmC,2CAAoBF,UAApB,CAA+B;AAAEjC,QAAAA,EAAE,EAAEA,EAAE,CAACoC,QAAH,EAAN;AAAqBN,QAAAA;AAArB,OAA/B,CAAH,GAAuEO,SADzF;AAELxB,MAAAA,SAAS,EAAEgB,YAAY,GAAGS,iCAAeC,IAAf,iCAAyBV,YAAzB;AAAuCtC,QAAAA;AAAvC,SAAH,GAAoD8C,SAFtE;AAGL;AACAzC,MAAAA,KAAK,EAAEA,KAAK,GACR,KAAI4C,gCAAJ,EAAmB,GAAnB,EAAwB5C,KAAK,CAAC6C,OAA9B,CADQ,GAER,CAACZ,YAAD,IAAiB,CAAChC,OAAlB,GACA,KAAI2C,gCAAJ,EAAmB,GAAnB,CADA,GAEAH;AARC,KAAP;AAUD,GAfM,EAeJ,CAACR,YAAD,EAAetC,IAAf,EAAqBK,KAArB,CAfI,CAAP;AAgBD","sourcesContent":["import { useMemo, useEffect, useRef } from 'react';\nimport { gql } from '@apollo/client';\nimport { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';\nimport { ComponentID, ComponentIdObj } from '@teambit/component-id';\nimport { ComponentDescriptor } from '@teambit/component-descriptor';\n\nimport { ComponentModel } from './component-model';\nimport { ComponentError } from './component-error';\n\nconst componentIdFields = gql`\n fragment componentIdFields on ComponentID {\n name\n version\n scope\n }\n`;\n\nconst componentFields = gql`\n fragment componentFields on Component {\n id {\n ...componentIdFields\n }\n aspects(include: [\"teambit.preview/preview\", \"teambit.pipelines/builder\", \"teambit.envs/envs\"]) {\n # 'id' property in gql refers to a *global* identifier and used for caching.\n # this makes aspect data cache under the same key, even when they are under different components.\n # renaming the property fixes that.\n aspectId: id\n aspectData: data\n }\n packageName\n elementsUrl\n description\n labels\n displayName\n latest\n server {\n env\n url\n }\n buildStatus\n compositions {\n identifier\n displayName\n }\n tags {\n version\n }\n env {\n id\n icon\n }\n logs(type: $logType, offset: $logOffset, limit: $logLimit, head: $logHead, sort: $logSort) {\n id\n message\n username\n email\n date\n hash\n tag\n }\n preview {\n includesEnvTemplate\n }\n }\n ${componentIdFields}\n`;\n\nconst GET_COMPONENT = gql`\n query Component(\n $id: String!\n $extensionId: String!\n $logType: String\n $logOffset: Int\n $logLimit: Int\n $logHead: String\n $logSort: String\n ) {\n getHost(id: $extensionId) {\n id # used for GQL caching\n get(id: $id) {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_SUBSCRIPTION_ADDED = gql`\n subscription OnComponentAdded($logType: String, $logOffset: Int, $logLimit: Int, $logHead: String, $logSort: String) {\n componentAdded {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_CHANGED = gql`\n subscription OnComponentChanged(\n $logType: String\n $logOffset: Int\n $logLimit: Int\n $logHead: String\n $logSort: String\n ) {\n componentChanged {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_REMOVED = gql`\n subscription OnComponentRemoved {\n componentRemoved {\n componentIds {\n ...componentIdFields\n }\n }\n }\n ${componentIdFields}\n`;\n\n/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */\nexport function useComponentQuery(\n componentId: string,\n host: string,\n filters?: { log?: { logType?: string; logOffset?: number; logLimit?: number; logHead?: string; logSort?: string } }\n) {\n const idRef = useRef(componentId);\n idRef.current = componentId;\n const { data, error, loading, subscribeToMore } = useDataQuery(GET_COMPONENT, {\n variables: { id: componentId, extensionId: host, ...(filters?.log || {}) },\n });\n\n useEffect(() => {\n // @TODO @Kutner fix subscription for scope\n if (host !== 'teambit.workspace/workspace') {\n return () => {};\n }\n\n const unsubAddition = subscribeToMore({\n document: SUB_SUBSCRIPTION_ADDED,\n updateQuery: (prev, { subscriptionData }) => {\n const prevComponent = prev?.getHost?.get;\n const addedComponent = subscriptionData?.data?.componentAdded?.component;\n\n if (!addedComponent || prevComponent) return prev;\n\n if (idRef.current === addedComponent.id.name) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: addedComponent,\n },\n };\n }\n\n return prev;\n },\n });\n\n const unsubChanges = subscribeToMore({\n document: SUB_COMPONENT_CHANGED,\n updateQuery: (prev, { subscriptionData }) => {\n if (!subscriptionData.data) return prev;\n\n const prevComponent = prev?.getHost?.get;\n const updatedComponent = subscriptionData?.data?.componentChanged?.component;\n\n const isUpdated = updatedComponent && ComponentID.isEqualObj(prevComponent?.id, updatedComponent?.id);\n\n if (isUpdated) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: updatedComponent,\n },\n };\n }\n\n return prev;\n },\n });\n\n const unsubRemoval = subscribeToMore({\n document: SUB_COMPONENT_REMOVED,\n updateQuery: (prev, { subscriptionData }) => {\n if (!subscriptionData.data) return prev;\n\n const prevComponent = prev?.getHost?.get;\n const removedIds: ComponentIdObj[] | undefined = subscriptionData?.data?.componentRemoved?.componentIds;\n if (!prevComponent || !removedIds?.length) return prev;\n\n const isRemoved = removedIds.some((removedId) => ComponentID.isEqualObj(removedId, prevComponent.id));\n\n if (isRemoved) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: null,\n },\n };\n }\n\n return prev;\n },\n });\n\n return () => {\n unsubChanges();\n unsubAddition();\n unsubRemoval();\n };\n }, []);\n\n const rawComponent = data?.getHost?.get;\n return useMemo(() => {\n const aspectList = {\n entries: rawComponent?.aspects,\n };\n const id = rawComponent && ComponentID.fromObject(rawComponent.id);\n return {\n componentDescriptor: id ? ComponentDescriptor.fromObject({ id: id.toString(), aspectList }) : undefined,\n component: rawComponent ? ComponentModel.from({ ...rawComponent, host }) : undefined,\n // eslint-disable-next-line\n error: error\n ? new ComponentError(500, error.message)\n : !rawComponent && !loading\n ? new ComponentError(404)\n : undefined,\n };\n }, [rawComponent, host, error]);\n}\n"]}
@@ -25,6 +25,16 @@ function _uiFoundationUiReactRouter() {
25
25
  return data;
26
26
  }
27
27
 
28
+ function _lanesUi() {
29
+ const data = require("@teambit/lanes.ui.lanes");
30
+
31
+ _lanesUi = function () {
32
+ return data;
33
+ };
34
+
35
+ return data;
36
+ }
37
+
28
38
  function _useComponentQuery() {
29
39
  const data = require("./use-component-query");
30
40
 
@@ -36,6 +46,8 @@ function _useComponentQuery() {
36
46
  }
37
47
 
38
48
  function useComponent(host, id) {
49
+ var _lanesContext$current, _lanesContext$current2;
50
+
39
51
  const {
40
52
  params: {
41
53
  componentId
@@ -43,11 +55,20 @@ function useComponent(host, id) {
43
55
  } = (0, _reactRouterDom().useRouteMatch)();
44
56
  const query = (0, _uiFoundationUiReactRouter().useQuery)();
45
57
  const version = query.get('version') || undefined;
58
+ const lanesContext = (0, _lanesUi().useLanesContext)();
46
59
  const targetId = (id === null || id === void 0 ? void 0 : id.toString({
47
60
  ignoreVersion: true
48
61
  })) || componentId;
49
62
  if (!targetId) throw new TypeError('useComponent received no component id');
50
- return (0, _useComponentQuery().useComponentQuery)(withVersion(targetId, version), host);
63
+ const currentLane = lanesContext === null || lanesContext === void 0 ? void 0 : lanesContext.currentLane; // when on a lane, always fetch all the logs starting from the 'head' version
64
+
65
+ const logHead = lanesContext === null || lanesContext === void 0 ? void 0 : (_lanesContext$current = lanesContext.currentLane) === null || _lanesContext$current === void 0 ? void 0 : (_lanesContext$current2 = _lanesContext$current.components.find(component => component.model.id.fullName === targetId)) === null || _lanesContext$current2 === void 0 ? void 0 : _lanesContext$current2.model.id.version;
66
+ const logFilters = currentLane ? {
67
+ log: {
68
+ logHead
69
+ }
70
+ } : undefined;
71
+ return (0, _useComponentQuery().useComponentQuery)(withVersion(targetId, version), host, logFilters);
51
72
  }
52
73
 
53
74
  function withVersion(id, version) {
@@ -1 +1 @@
1
- {"version":3,"sources":["use-component.tsx"],"names":["useComponent","host","id","params","componentId","query","version","get","undefined","targetId","toString","ignoreVersion","TypeError","withVersion","includes"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAYO,SAASA,YAAT,CAAsBC,IAAtB,EAAoCC,EAApC,EAAiE;AACtE,QAAM;AACJC,IAAAA,MAAM,EAAE;AAAEC,MAAAA;AAAF;AADJ,MAEF,sCAFJ;AAGA,QAAMC,KAAK,GAAG,4CAAd;AACA,QAAMC,OAAO,GAAGD,KAAK,CAACE,GAAN,CAAU,SAAV,KAAwBC,SAAxC;AAEA,QAAMC,QAAQ,GAAG,CAAAP,EAAE,SAAF,IAAAA,EAAE,WAAF,YAAAA,EAAE,CAAEQ,QAAJ,CAAa;AAAEC,IAAAA,aAAa,EAAE;AAAjB,GAAb,MAAyCP,WAA1D;AACA,MAAI,CAACK,QAAL,EAAe,MAAM,IAAIG,SAAJ,CAAc,uCAAd,CAAN;AACf,SAAO,4CAAkBC,WAAW,CAACJ,QAAD,EAAWH,OAAX,CAA7B,EAAkDL,IAAlD,CAAP;AACD;;AAED,SAASY,WAAT,CAAqBX,EAArB,EAAiCI,OAAjC,EAAmD;AACjD,MAAI,CAACA,OAAL,EAAc,OAAOJ,EAAP;AACd,MAAIA,EAAE,CAACY,QAAH,CAAY,GAAZ,CAAJ,EAAsB,OAAOZ,EAAP;AACtB,SAAQ,GAAEA,EAAG,IAAGI,OAAQ,EAAxB;AACD","sourcesContent":["import { useRouteMatch } from 'react-router-dom';\nimport { ComponentID } from '@teambit/component-id';\nimport { useQuery } from '@teambit/ui-foundation.ui.react-router.use-query';\nimport { ComponentDescriptor } from '@teambit/component-descriptor';\nimport { ComponentModel } from './component-model';\nimport { ComponentError } from './component-error';\nimport { useComponentQuery } from './use-component-query';\n\nexport type Component = {\n component?: ComponentModel;\n error?: ComponentError;\n componentDescriptor?: ComponentDescriptor;\n};\n\ntype ComponentRoute = {\n componentId?: string;\n};\n\nexport function useComponent(host: string, id?: ComponentID): Component {\n const {\n params: { componentId },\n } = useRouteMatch<ComponentRoute>();\n const query = useQuery();\n const version = query.get('version') || undefined;\n\n const targetId = id?.toString({ ignoreVersion: true }) || componentId;\n if (!targetId) throw new TypeError('useComponent received no component id');\n return useComponentQuery(withVersion(targetId, version), host);\n}\n\nfunction withVersion(id: string, version?: string) {\n if (!version) return id;\n if (id.includes('@')) return id;\n return `${id}@${version}`;\n}\n"]}
1
+ {"version":3,"sources":["use-component.tsx"],"names":["useComponent","host","id","params","componentId","query","version","get","undefined","lanesContext","targetId","toString","ignoreVersion","TypeError","currentLane","logHead","components","find","component","model","fullName","logFilters","log","withVersion","includes"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAYO,SAASA,YAAT,CAAsBC,IAAtB,EAAoCC,EAApC,EAAiE;AAAA;;AACtE,QAAM;AACJC,IAAAA,MAAM,EAAE;AAAEC,MAAAA;AAAF;AADJ,MAEF,sCAFJ;AAGA,QAAMC,KAAK,GAAG,4CAAd;AACA,QAAMC,OAAO,GAAGD,KAAK,CAACE,GAAN,CAAU,SAAV,KAAwBC,SAAxC;AACA,QAAMC,YAAY,GAAG,iCAArB;AACA,QAAMC,QAAQ,GAAG,CAAAR,EAAE,SAAF,IAAAA,EAAE,WAAF,YAAAA,EAAE,CAAES,QAAJ,CAAa;AAAEC,IAAAA,aAAa,EAAE;AAAjB,GAAb,MAAyCR,WAA1D;AACA,MAAI,CAACM,QAAL,EAAe,MAAM,IAAIG,SAAJ,CAAc,uCAAd,CAAN;AACf,QAAMC,WAAW,GAAGL,YAAH,aAAGA,YAAH,uBAAGA,YAAY,CAAEK,WAAlC,CATsE,CAUtE;;AACA,QAAMC,OAAO,GAAGN,YAAH,aAAGA,YAAH,gDAAGA,YAAY,CAAEK,WAAjB,oFAAG,sBAA2BE,UAA3B,CAAsCC,IAAtC,CAA4CC,SAAD,IAAeA,SAAS,CAACC,KAAV,CAAgBjB,EAAhB,CAAmBkB,QAAnB,KAAgCV,QAA1F,CAAH,2DAAG,uBACZS,KADY,CACNjB,EADM,CACHI,OADb;AAEA,QAAMe,UAAU,GAAGP,WAAW,GAC1B;AACEQ,IAAAA,GAAG,EAAE;AACHP,MAAAA;AADG;AADP,GAD0B,GAM1BP,SANJ;AAQA,SAAO,4CAAkBe,WAAW,CAACb,QAAD,EAAWJ,OAAX,CAA7B,EAAkDL,IAAlD,EAAwDoB,UAAxD,CAAP;AACD;;AAED,SAASE,WAAT,CAAqBrB,EAArB,EAAiCI,OAAjC,EAAmD;AACjD,MAAI,CAACA,OAAL,EAAc,OAAOJ,EAAP;AACd,MAAIA,EAAE,CAACsB,QAAH,CAAY,GAAZ,CAAJ,EAAsB,OAAOtB,EAAP;AACtB,SAAQ,GAAEA,EAAG,IAAGI,OAAQ,EAAxB;AACD","sourcesContent":["import { useRouteMatch } from 'react-router-dom';\nimport { ComponentID } from '@teambit/component-id';\nimport { useQuery } from '@teambit/ui-foundation.ui.react-router.use-query';\nimport { ComponentDescriptor } from '@teambit/component-descriptor';\nimport { useLanesContext } from '@teambit/lanes.ui.lanes';\nimport { ComponentModel } from './component-model';\nimport { ComponentError } from './component-error';\nimport { useComponentQuery } from './use-component-query';\n\nexport type Component = {\n component?: ComponentModel;\n error?: ComponentError;\n componentDescriptor?: ComponentDescriptor;\n};\n\ntype ComponentRoute = {\n componentId?: string;\n};\n\nexport function useComponent(host: string, id?: ComponentID): Component {\n const {\n params: { componentId },\n } = useRouteMatch<ComponentRoute>();\n const query = useQuery();\n const version = query.get('version') || undefined;\n const lanesContext = useLanesContext();\n const targetId = id?.toString({ ignoreVersion: true }) || componentId;\n if (!targetId) throw new TypeError('useComponent received no component id');\n const currentLane = lanesContext?.currentLane;\n // when on a lane, always fetch all the logs starting from the 'head' version\n const logHead = lanesContext?.currentLane?.components.find((component) => component.model.id.fullName === targetId)\n ?.model.id.version;\n const logFilters = currentLane\n ? {\n log: {\n logHead,\n },\n }\n : undefined;\n\n return useComponentQuery(withVersion(targetId, version), host, logFilters);\n}\n\nfunction withVersion(id: string, version?: string) {\n if (!version) return id;\n if (id.includes('@')) return id;\n return `${id}@${version}`;\n}\n"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/component",
3
- "version": "0.0.669",
3
+ "version": "0.0.672",
4
4
  "homepage": "https://bit.dev/teambit/component/component",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.component",
8
8
  "name": "component",
9
- "version": "0.0.669"
9
+ "version": "0.0.672"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/any-fs": "0.0.5",
@@ -29,37 +29,37 @@
29
29
  "@teambit/base-ui.routing.routing-provider": "1.0.0",
30
30
  "@teambit/component-id": "0.0.401",
31
31
  "@teambit/ui-foundation.ui.menu-widget-icon": "0.0.488",
32
- "@teambit/aspect-loader": "0.0.669",
32
+ "@teambit/aspect-loader": "0.0.672",
33
33
  "@teambit/legacy-bit-id": "0.0.398",
34
34
  "@teambit/toolbox.string.capitalize": "0.0.483",
35
- "@teambit/cli": "0.0.451",
36
- "@teambit/config": "0.0.464",
37
- "@teambit/express": "0.0.545",
38
- "@teambit/graphql": "0.0.669",
35
+ "@teambit/cli": "0.0.452",
36
+ "@teambit/config": "0.0.465",
37
+ "@teambit/express": "0.0.546",
38
+ "@teambit/graphql": "0.0.672",
39
39
  "@teambit/bit-error": "0.0.394",
40
- "@teambit/command-bar": "0.0.669",
41
- "@teambit/preview": "0.0.669",
42
- "@teambit/pubsub": "0.0.669",
40
+ "@teambit/command-bar": "0.0.672",
41
+ "@teambit/preview": "0.0.672",
42
+ "@teambit/pubsub": "0.0.672",
43
43
  "@teambit/ui-foundation.ui.is-browser": "0.0.486",
44
44
  "@teambit/ui-foundation.ui.main-dropdown": "0.0.486",
45
45
  "@teambit/ui-foundation.ui.react-router.slot-router": "0.0.488",
46
46
  "@teambit/ui-foundation.ui.use-box.menu": "0.0.111",
47
- "@teambit/ui": "0.0.669",
47
+ "@teambit/ui": "0.0.672",
48
48
  "@teambit/component-issues": "0.0.46",
49
49
  "@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.487",
50
50
  "@teambit/cli-table": "0.0.33",
51
- "@teambit/component-descriptor": "0.0.12",
51
+ "@teambit/component-descriptor": "0.0.13",
52
+ "@teambit/lanes.ui.lanes": "0.0.13",
52
53
  "@teambit/ui-foundation.ui.react-router.use-query": "0.0.486",
53
54
  "@teambit/design.ui.empty-box": "0.0.353",
54
55
  "@teambit/harmony.ui.aspect-box": "0.0.486",
55
56
  "@teambit/design.ui.pages.not-found": "0.0.353",
56
57
  "@teambit/design.ui.pages.server-error": "0.0.353",
57
- "@teambit/compositions": "0.0.669",
58
- "@teambit/deprecation": "0.0.669",
59
- "@teambit/envs": "0.0.669",
60
- "@teambit/legacy-component-log": "0.0.391",
61
- "@teambit/component.ui.version-dropdown": "0.0.495",
62
- "@teambit/lanes.ui.lanes": "0.0.11",
58
+ "@teambit/compositions": "0.0.672",
59
+ "@teambit/deprecation": "0.0.672",
60
+ "@teambit/envs": "0.0.672",
61
+ "@teambit/legacy-component-log": "0.0.392",
62
+ "@teambit/component.ui.version-dropdown": "0.0.498",
63
63
  "@teambit/ui-foundation.ui.full-loader": "0.0.486",
64
64
  "@teambit/ui-foundation.ui.use-box.dropdown": "0.0.111",
65
65
  "@teambit/ui-foundation.ui.react-router.extend-path": "0.0.486"
@@ -81,7 +81,7 @@
81
81
  },
82
82
  "peerDependencies": {
83
83
  "@apollo/client": "^3.0.0",
84
- "@teambit/legacy": "1.0.230",
84
+ "@teambit/legacy": "1.0.231",
85
85
  "react-dom": "^16.8.0 || ^17.0.0",
86
86
  "react": "^16.8.0 || ^17.0.0"
87
87
  },
@@ -109,7 +109,7 @@
109
109
  "react": "-"
110
110
  },
111
111
  "peerDependencies": {
112
- "@teambit/legacy": "1.0.230",
112
+ "@teambit/legacy": "1.0.231",
113
113
  "react-dom": "^16.8.0 || ^17.0.0",
114
114
  "react": "^16.8.0 || ^17.0.0"
115
115
  }
@@ -1 +1 @@
1
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.669/dist/component.docs.mdx')]
1
+ export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.672/dist/component.docs.mdx')]
@@ -8,4 +8,4 @@ export const ComponentDescriptorContext: React.Context<ComponentDescriptor | und
8
8
  ComponentDescriptor | undefined
9
9
  >(undefined);
10
10
 
11
- export const useComponentDescriptor = () => useContext(ComponentDescriptorContext)
11
+ export const useComponentDescriptor = () => useContext(ComponentDescriptorContext);
@@ -20,7 +20,7 @@ const componentFields = gql`
20
20
  id {
21
21
  ...componentIdFields
22
22
  }
23
- aspects(include: ["teambit.preview/preview", "teambit.pipelines/builder"]) {
23
+ aspects(include: ["teambit.preview/preview", "teambit.pipelines/builder", "teambit.envs/envs"]) {
24
24
  # 'id' property in gql refers to a *global* identifier and used for caching.
25
25
  # this makes aspect data cache under the same key, even when they are under different components.
26
26
  # renaming the property fixes that.
@@ -49,7 +49,8 @@ const componentFields = gql`
49
49
  id
50
50
  icon
51
51
  }
52
- logs(type: $logType, offset: $logOffset, limit: $logLimit) {
52
+ logs(type: $logType, offset: $logOffset, limit: $logLimit, head: $logHead, sort: $logSort) {
53
+ id
53
54
  message
54
55
  username
55
56
  email
@@ -65,7 +66,15 @@ const componentFields = gql`
65
66
  `;
66
67
 
67
68
  const GET_COMPONENT = gql`
68
- query Component($id: String!, $extensionId: String!, $logType: String, $logOffset: Int, $logLimit: Int) {
69
+ query Component(
70
+ $id: String!
71
+ $extensionId: String!
72
+ $logType: String
73
+ $logOffset: Int
74
+ $logLimit: Int
75
+ $logHead: String
76
+ $logSort: String
77
+ ) {
69
78
  getHost(id: $extensionId) {
70
79
  id # used for GQL caching
71
80
  get(id: $id) {
@@ -77,7 +86,7 @@ const GET_COMPONENT = gql`
77
86
  `;
78
87
 
79
88
  const SUB_SUBSCRIPTION_ADDED = gql`
80
- subscription OnComponentAdded($logType: String, $logOffset: Int, $logLimit: Int) {
89
+ subscription OnComponentAdded($logType: String, $logOffset: Int, $logLimit: Int, $logHead: String, $logSort: String) {
81
90
  componentAdded {
82
91
  component {
83
92
  ...componentFields
@@ -88,7 +97,13 @@ const SUB_SUBSCRIPTION_ADDED = gql`
88
97
  `;
89
98
 
90
99
  const SUB_COMPONENT_CHANGED = gql`
91
- subscription OnComponentChanged($logType: String, $logOffset: Int, $logLimit: Int) {
100
+ subscription OnComponentChanged(
101
+ $logType: String
102
+ $logOffset: Int
103
+ $logLimit: Int
104
+ $logHead: String
105
+ $logSort: String
106
+ ) {
92
107
  componentChanged {
93
108
  component {
94
109
  ...componentFields
@@ -110,11 +125,15 @@ const SUB_COMPONENT_REMOVED = gql`
110
125
  `;
111
126
 
112
127
  /** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
113
- export function useComponentQuery(componentId: string, host: string) {
128
+ export function useComponentQuery(
129
+ componentId: string,
130
+ host: string,
131
+ filters?: { log?: { logType?: string; logOffset?: number; logLimit?: number; logHead?: string; logSort?: string } }
132
+ ) {
114
133
  const idRef = useRef(componentId);
115
134
  idRef.current = componentId;
116
135
  const { data, error, loading, subscribeToMore } = useDataQuery(GET_COMPONENT, {
117
- variables: { id: componentId, extensionId: host },
136
+ variables: { id: componentId, extensionId: host, ...(filters?.log || {}) },
118
137
  });
119
138
 
120
139
  useEffect(() => {
@@ -2,6 +2,7 @@ import { useRouteMatch } from 'react-router-dom';
2
2
  import { ComponentID } from '@teambit/component-id';
3
3
  import { useQuery } from '@teambit/ui-foundation.ui.react-router.use-query';
4
4
  import { ComponentDescriptor } from '@teambit/component-descriptor';
5
+ import { useLanesContext } from '@teambit/lanes.ui.lanes';
5
6
  import { ComponentModel } from './component-model';
6
7
  import { ComponentError } from './component-error';
7
8
  import { useComponentQuery } from './use-component-query';
@@ -22,10 +23,22 @@ export function useComponent(host: string, id?: ComponentID): Component {
22
23
  } = useRouteMatch<ComponentRoute>();
23
24
  const query = useQuery();
24
25
  const version = query.get('version') || undefined;
25
-
26
+ const lanesContext = useLanesContext();
26
27
  const targetId = id?.toString({ ignoreVersion: true }) || componentId;
27
28
  if (!targetId) throw new TypeError('useComponent received no component id');
28
- return useComponentQuery(withVersion(targetId, version), host);
29
+ const currentLane = lanesContext?.currentLane;
30
+ // when on a lane, always fetch all the logs starting from the 'head' version
31
+ const logHead = lanesContext?.currentLane?.components.find((component) => component.model.id.fullName === targetId)
32
+ ?.model.id.version;
33
+ const logFilters = currentLane
34
+ ? {
35
+ log: {
36
+ logHead,
37
+ },
38
+ }
39
+ : undefined;
40
+
41
+ return useComponentQuery(withVersion(targetId, version), host, logFilters);
29
42
  }
30
43
 
31
44
  function withVersion(id: string, version?: string) {