UNPKG

@teambit/lanes

Version:
350 lines (334 loc) 11.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.lanesSchema = lanesSchema; function _laneId() { const data = require("@teambit/lane-id"); _laneId = function () { return data; }; return data; } function _componentId() { const data = require("@teambit/component-id"); _componentId = function () { return data; }; return data; } function _fuse() { const data = _interopRequireDefault(require("fuse.js")); _fuse = function () { return data; }; return data; } function _graphqlTag() { const data = require("graphql-tag"); _graphqlTag = function () { return data; }; return data; } function _lodash() { const data = require("lodash"); _lodash = function () { return data; }; return data; } function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } 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; } 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; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function lanesSchema(lanesMainRuntime) { return { typeDefs: (0, _graphqlTag().gql)` type FileDiff { filePath: String! diffOutput: String } type SnapDistance { onSource: [String!]! onTarget: [String!]! common: String } type FieldsDiff { fieldName: String! diffOutput: String } type DiffResults { id: String hasDiff: Boolean filesDiff: [FileDiff] fieldsDiff: [FieldsDiff] } type GetDiffResult { newComps: [String] compsWithNoChanges: [String] toLaneName: String compsWithDiff: [DiffResults] } input DiffOptions { color: Boolean } input DiffStatusOptions { skipChanges: Boolean skipUpToDate: Boolean } type LaneId { name: String! scope: String! } type LaneComponentDiffStatus { """ for apollo caching - component id """ id: String! sourceHead: String! targetHead: String componentId: ComponentID! changeType: String @deprecated(reason: "Use changes") """ list of all change types - Source Code, Dependency, Aspects, etc """ changes: [String!] upToDate: Boolean snapsDistance: SnapDistance unrelated: Boolean } type LaneDiffStatus { """ for apollo caching - source + target """ id: String! source: LaneId! target: LaneId! componentsStatus: [LaneComponentDiffStatus!]! } type LaneOwner { name: String username: String displayName: String email: String profileImage: String } type Lane { id: LaneId! hash: String laneComponentIds: [ComponentID!]! components(offset: Int, limit: Int): [Component!]! """ IDs of hidden cascade entries (lane.updateDependents). Separate from \`laneComponentIds\` so workspace-facing consumers don't surface them by default. """ updateDependentIds: [ComponentID!]! """ Hidden cascade entries materialized as Components. Separate from \`components\` for the same reason — consumers opt in by selecting this field. """ updateDependentComponents(offset: Int, limit: Int): [Component!]! readmeComponent: Component createdBy: LaneOwner createdAt: String updatedBy: LaneOwner updatedAt: String } input LaneSort { by: String direction: String } # Lane API type Lanes { id: String! list(ids: [String!], offset: Int, limit: Int, sort: LaneSort, search: String): [Lane!]! default: Lane diff(from: String!, to: String!, options: DiffOptions): GetDiffResult diffStatus(source: String!, target: String, options: DiffStatusOptions): LaneDiffStatus! removeUpdateDependents(laneId: String!, ids: [String!]): Boolean current: Lane } type Query { lanes: Lanes } `, resolvers: { Lanes: { // need this for Apollo InMemory Caching id: () => 'lanes', list: async (lanesMain, { ids, limit, offset, sort: { by = 'createdAt', direction = 'desc' } = { by: 'createdAt', direction: 'desc' }, search }) => { let lanes = []; if (!ids || ids.length === 0) { lanes = await lanesMain.getLanes({ showDefaultLane: true }); } else { lanes = (0, _lodash().flatten)(await Promise.all(ids.map(id => { if (id === lanesMain.getDefaultLaneId().name) { return lanesMain.getLanes({ showDefaultLane: true, name: id }); } return lanesMain.getLanes({ name: _laneId().LaneId.parse(id).name }); }))); } if (search) { const fuseOptions = { keys: ['id.name', 'id.scope', 'log.username', 'log.email', 'log.displayName'], threshold: search.length === 1 ? 0 : 0.3, findAllMatches: true, location: 0, distance: search.length === 1 ? 0 : 100, minMatchCharLength: 1, ignoreLocation: true, shouldSort: false, includeScore: true }; const fuse = new (_fuse().default)(lanes, fuseOptions); lanes = fuse.search(search).map(result => result.item); } lanes = lanes.sort((a, b) => { switch (by) { default: { if (!a[by] || !b[by]) return 0; if (a[by] < b[by]) return direction === 'asc' ? -1 : 1; if (a[by] > b[by]) return direction === 'asc' ? -1 : 1; return 0; } case 'createdAt': case 'updatedAt': { const aDate = a.log?.date; const bDate = b.log?.date; if (!aDate || !bDate) return 0; if (+aDate < +bDate) return direction === 'asc' ? -1 : 1; if (+aDate > +bDate) return direction === 'asc' ? 1 : -1; return 0; } case 'id': { const aId = a[by].toString(); const bId = b[by].toString(); if (aId < bId) return direction === 'asc' ? -1 : 1; if (aId > bId) return direction === 'asc' ? -1 : 1; return 0; } } }); if (limit || offset) { lanes = (0, _lodash().slice)(lanes, offset, limit && limit + (offset || 0)); } return lanes; }, default: async lanesMain => { const [defaultLane] = await lanesMain.getLanes({ showDefaultLane: true, name: lanesMain.getDefaultLaneId().name }); return defaultLane; }, current: async lanesMain => { const currentLaneName = lanesMain.getCurrentLaneName(); if (!currentLaneName) return undefined; const [currentLane] = await lanesMain.getLanes({ name: currentLaneName }); return currentLane; }, diff: async (lanesMain, { from, to, options }) => { const getDiffResults = await lanesMain.getDiff([from, to], options); return _objectSpread(_objectSpread({}, getDiffResults), {}, { compsWithDiff: getDiffResults.compsWithDiff.map(item => _objectSpread(_objectSpread({}, item), {}, { id: item.id.toString() })) }); }, diffStatus: async (lanesMain, { source, target, options }) => { const sourceLaneId = _laneId().LaneId.parse(source); const targetLaneId = target ? _laneId().LaneId.parse(target) : undefined; return lanesMain.diffStatus(sourceLaneId, targetLaneId, options); }, removeUpdateDependents: async (lanesMain, { laneId, ids }) => { const laneIdParsed = _laneId().LaneId.parse(laneId); const compIds = ids?.map(id => _componentId().ComponentID.fromString(id)); return lanesMain.removeUpdateDependents(laneIdParsed, compIds); } }, LaneDiffStatus: { id: diffStatus => `${diffStatus.source.toString()}-${diffStatus.target.toString()}` }, LaneComponentDiffStatus: { id: diffCompStatus => `${diffCompStatus.componentId.toStringWithoutVersion()}-${diffCompStatus.sourceHead}-${diffCompStatus.targetHead}`, componentId: diffCompStatus => diffCompStatus.componentId.toObject() }, Lane: { id: lane => lane.id.toObject(), laneComponentIds: async lane => { const componentIds = await lanesMainRuntime.getLaneComponentIds(lane); return componentIds.map(componentId => componentId.toObject()); }, components: async lane => { const laneComponents = await lanesMainRuntime.getLaneComponentModels(lane); return laneComponents; }, updateDependentIds: async lane => { const ids = await lanesMainRuntime.getLaneUpdateDependentIds(lane); return ids.map(id => id.toObject()); }, updateDependentComponents: async lane => { return lanesMainRuntime.getLaneUpdateDependentComponents(lane); }, readmeComponent: async lane => { const laneReadmeComponent = await lanesMainRuntime.getLaneReadmeComponent(lane); return laneReadmeComponent; }, createdAt: async lane => { return lane.log?.date; }, createdBy: async lane => { return { name: lane.log?.username, email: lane.log?.email, profileImage: lane.log?.profileImage, displayName: lane.log?.username, username: lane.log?.username }; } }, Query: { lanes: () => lanesMainRuntime } } }; } //# sourceMappingURL=lanes.graphql.js.map