@teambit/lanes 1.0.108 → 1.0.110

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/lanes.graphql.ts DELETED
@@ -1,290 +0,0 @@
1
- import { Schema } from '@teambit/graphql';
2
- import { LaneId } from '@teambit/lane-id';
3
- import Fuse from 'fuse.js';
4
- import { LaneData } from '@teambit/legacy/dist/scope/lanes/lanes';
5
- import gql from 'graphql-tag';
6
- import { flatten, slice } from 'lodash';
7
- import { LaneComponentDiffStatus, LaneDiffStatus, LaneDiffStatusOptions, LanesMain } from './lanes.main.runtime';
8
-
9
- export function lanesSchema(lanesMainRuntime: LanesMain): Schema {
10
- return {
11
- typeDefs: gql`
12
- type FileDiff {
13
- filePath: String!
14
- diffOutput: String
15
- }
16
-
17
- type SnapDistance {
18
- onSource: [String!]!
19
- onTarget: [String!]!
20
- common: String
21
- }
22
-
23
- type FieldsDiff {
24
- fieldName: String!
25
- diffOutput: String
26
- }
27
-
28
- type DiffResults {
29
- id: String
30
- hasDiff: Boolean
31
- filesDiff: [FileDiff]
32
- fieldsDiff: [FieldsDiff]
33
- }
34
-
35
- type GetDiffResult {
36
- newComps: [String]
37
- compsWithNoChanges: [String]
38
- toLaneName: String
39
- compsWithDiff: [DiffResults]
40
- }
41
-
42
- input DiffOptions {
43
- color: Boolean
44
- }
45
-
46
- input DiffStatusOptions {
47
- skipChanges: Boolean
48
- skipUpToDate: Boolean
49
- }
50
-
51
- type LaneId {
52
- name: String!
53
- scope: String!
54
- }
55
-
56
- type LaneComponentDiffStatus {
57
- """
58
- for apollo caching - component id
59
- """
60
- id: String!
61
- sourceHead: String!
62
- targetHead: String
63
- componentId: ComponentID!
64
- changeType: String @deprecated(reason: "Use changes")
65
- """
66
- list of all change types - Source Code, Dependency, Aspects, etc
67
- """
68
- changes: [String!]
69
- upToDate: Boolean
70
- snapsDistance: SnapDistance
71
- unrelated: Boolean
72
- }
73
-
74
- type LaneDiffStatus {
75
- """
76
- for apollo caching - source + target
77
- """
78
- id: String!
79
- source: LaneId!
80
- target: LaneId!
81
- componentsStatus: [LaneComponentDiffStatus!]!
82
- }
83
-
84
- type LaneOwner {
85
- name: String
86
- username: String
87
- displayName: String
88
- email: String
89
- profileImage: String
90
- }
91
-
92
- type Lane {
93
- id: LaneId!
94
- hash: String
95
- laneComponentIds: [ComponentID!]!
96
- components(offset: Int, limit: Int): [Component!]!
97
- readmeComponent: Component
98
- createdBy: LaneOwner
99
- createdAt: String
100
- updatedBy: LaneOwner
101
- updatedAt: String
102
- }
103
-
104
- input LaneSort {
105
- by: String
106
- direction: String
107
- }
108
-
109
- # Lane API
110
- type Lanes {
111
- id: String!
112
- list(ids: [String!], offset: Int, limit: Int, sort: LaneSort, search: String): [Lane!]!
113
- default: Lane
114
- diff(from: String!, to: String!, options: DiffOptions): GetDiffResult
115
- diffStatus(source: String!, target: String, options: DiffStatusOptions): LaneDiffStatus!
116
- current: Lane
117
- }
118
-
119
- type Query {
120
- lanes: Lanes
121
- }
122
- `,
123
- resolvers: {
124
- Lanes: {
125
- // need this for Apollo InMemory Caching
126
- id: () => 'lanes',
127
- list: async (
128
- lanesMain: LanesMain,
129
- {
130
- ids,
131
- limit,
132
- offset,
133
- sort: { by = 'createdAt', direction = 'desc' } = { by: 'createdAt', direction: 'desc' },
134
- search,
135
- }: {
136
- ids?: string[];
137
- offset?: number;
138
- limit?: number;
139
- sort?: {
140
- by?: string;
141
- direction?: string;
142
- };
143
- search?: string;
144
- }
145
- ) => {
146
- let lanes: LaneData[] = [];
147
-
148
- if (!ids || ids.length === 0) {
149
- lanes = await lanesMain.getLanes({ showDefaultLane: true });
150
- } else {
151
- lanes = flatten(
152
- await Promise.all(
153
- ids.map((id) => {
154
- if (id === lanesMain.getDefaultLaneId().name) {
155
- return lanesMain.getLanes({ showDefaultLane: true, name: id });
156
- }
157
- return lanesMain.getLanes({ name: LaneId.parse(id).name });
158
- })
159
- )
160
- );
161
- }
162
-
163
- if (search) {
164
- const fuseOptions = {
165
- keys: ['id.name', 'id.scope', 'log.username', 'log.email', 'log.displayName'],
166
- threshold: search.length === 1 ? 0 : 0.3,
167
- findAllMatches: true,
168
- location: 0,
169
- distance: search.length === 1 ? 0 : 100,
170
- minMatchCharLength: 1,
171
- ignoreLocation: true,
172
- shouldSort: false,
173
- includeScore: true,
174
- };
175
- const fuse = new Fuse(lanes, fuseOptions);
176
- lanes = fuse.search(search).map((result) => result.item);
177
- }
178
-
179
- lanes = lanes.sort((a, b) => {
180
- switch (by) {
181
- default: {
182
- if (!a[by] || !b[by]) return 0;
183
-
184
- if (a[by] < b[by]) return direction === 'asc' ? -1 : 1;
185
- if (a[by] > b[by]) return direction === 'asc' ? -1 : 1;
186
- return 0;
187
- }
188
- case 'createdAt':
189
- case 'updatedAt': {
190
- const aDate = a.log?.date;
191
- const bDate = b.log?.date;
192
-
193
- if (!aDate || !bDate) return 0;
194
-
195
- if (+aDate < +bDate) return direction === 'asc' ? -1 : 1;
196
- if (+aDate > +bDate) return direction === 'asc' ? 1 : -1;
197
- return 0;
198
- }
199
- case 'id': {
200
- const aId = a[by].toString();
201
- const bId = b[by].toString();
202
-
203
- if (aId < bId) return direction === 'asc' ? -1 : 1;
204
- if (aId > bId) return direction === 'asc' ? -1 : 1;
205
- return 0;
206
- }
207
- }
208
- });
209
-
210
- if (limit || offset) {
211
- lanes = slice(lanes, offset, limit && limit + (offset || 0));
212
- }
213
-
214
- return lanes;
215
- },
216
- default: async (lanesMain: LanesMain) => {
217
- const [defaultLane] = await lanesMain.getLanes({
218
- showDefaultLane: true,
219
- name: lanesMain.getDefaultLaneId().name,
220
- });
221
- return defaultLane;
222
- },
223
- current: async (lanesMain: LanesMain) => {
224
- const currentLaneName = lanesMain.getCurrentLaneName();
225
- if (!currentLaneName) return undefined;
226
- const [currentLane] = await lanesMain.getLanes({ name: currentLaneName });
227
- return currentLane;
228
- },
229
- diff: async (
230
- lanesMain: LanesMain,
231
- { from, to, options }: { to: string; from: string; options: { color?: boolean } }
232
- ) => {
233
- const getDiffResults = await lanesMain.getDiff([from, to], options);
234
- return {
235
- ...getDiffResults,
236
- compsWithDiff: getDiffResults.compsWithDiff.map((item) => ({ ...item, id: item.id.toString() })),
237
- };
238
- },
239
- diffStatus: async (
240
- lanesMain: LanesMain,
241
- { source, target, options }: { source: string; target?: string; options?: LaneDiffStatusOptions }
242
- ) => {
243
- const sourceLaneId = LaneId.parse(source);
244
- const targetLaneId = target ? LaneId.parse(target) : undefined;
245
- return lanesMain.diffStatus(sourceLaneId, targetLaneId, options);
246
- },
247
- },
248
- LaneDiffStatus: {
249
- id: (diffStatus: LaneDiffStatus) => `${diffStatus.source.toString()}-${diffStatus.target.toString()}`,
250
- },
251
- LaneComponentDiffStatus: {
252
- id: (diffCompStatus: LaneComponentDiffStatus) =>
253
- `${diffCompStatus.componentId.toStringWithoutVersion()}-${diffCompStatus.sourceHead}-${
254
- diffCompStatus.targetHead
255
- }`,
256
- componentId: (diffCompStatus: LaneComponentDiffStatus) => diffCompStatus.componentId.toObject(),
257
- },
258
- Lane: {
259
- id: (lane: LaneData) => lane.id.toObject(),
260
- laneComponentIds: async (lane: LaneData) => {
261
- const componentIds = await lanesMainRuntime.getLaneComponentIds(lane);
262
- return componentIds.map((componentId) => componentId.toObject());
263
- },
264
- components: async (lane: LaneData) => {
265
- const laneComponents = await lanesMainRuntime.getLaneComponentModels(lane);
266
- return laneComponents;
267
- },
268
- readmeComponent: async (lane: LaneData) => {
269
- const laneReadmeComponent = await lanesMainRuntime.getLaneReadmeComponent(lane);
270
- return laneReadmeComponent;
271
- },
272
- createdAt: async (lane: LaneData) => {
273
- return lane.log?.date;
274
- },
275
- createdBy: async (lane: LaneData) => {
276
- return {
277
- name: lane.log?.username,
278
- email: lane.log?.email,
279
- profileImage: lane.log?.profileImage,
280
- displayName: lane.log?.username,
281
- username: lane.log?.username,
282
- };
283
- },
284
- },
285
- Query: {
286
- lanes: () => lanesMainRuntime,
287
- },
288
- },
289
- };
290
- }