Skip to content

Commit

Permalink
chore: Update ts-standard to ^12.0.0
Browse files Browse the repository at this point in the history
openbeta-graphql uses typescript^4.9.5 and ts-standard^11.0.0. ts-standard in
turn depends on @typescript-eslint/eslint-plugin^4.26.1, which warns
that it is incompatible with typscript^4.9.5.

Avoid this warning by upgrading to ts-standard^12.0.0.

ts-standard^12.0.0 has a number of different lints that fail now. Fix
them with `yarn ts-standard --fix`.

Fixes #262
  • Loading branch information
musoke committed Apr 20, 2023
1 parent 7375cc5 commit dde4020
Show file tree
Hide file tree
Showing 24 changed files with 697 additions and 451 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"nock": "^13.3.0",
"supertest": "^6.3.3",
"ts-jest": "^29.0.5",
"ts-standard": "^11.0.0",
"ts-standard": "^12.0.0",
"typescript": "4.9.5"
},
"dependencies": {
Expand Down Expand Up @@ -57,7 +57,7 @@
},
"scripts": {
"lint": "yarn ts-standard",
"fix": "ts-standard --fix",
"fix": "yarn ts-standard --fix",
"test": "yarn build && cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --runInBand",
"build": "tsc -p tsconfig.json",
"build-release": "tsc -p tsconfig.release.json",
Expand Down
2 changes: 1 addition & 1 deletion src/db/ClimbHistoryType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ChangeEventType from './ChangeEventType'
import { ClimbType } from './ClimbTypes'
import { AreaType } from './AreaTypes'

export default interface ClimbHistoryType extends Document{
export default interface ClimbHistoryType extends Document {
uid: MUUID
actionType: ActionType
change: ChangeEventType<ClimbType>
Expand Down
2 changes: 1 addition & 1 deletion src/db/OrganizationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export interface OrganizationEditableFieldsType {
}

export enum OrgType {
localClimbingOrganization='LOCAL_CLIMBING_ORGANIZATION'
localClimbingOrganization = 'LOCAL_CLIMBING_ORGANIZATION'
}

/** The audit trail comprises a set of controlled events that may occur in relation
Expand Down
2 changes: 1 addition & 1 deletion src/db/export/Typesense/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function typesense (): Client | undefined {
* @param area
* @param op
*/
export const updateAreaIndex = async (area: AreaType|null, op: DBOperation): Promise<void> => {
export const updateAreaIndex = async (area: AreaType | null, op: DBOperation): Promise<void> => {
if (area == null) return
try {
if (Config.DEPLOYMENT_ENV !== 'production') {
Expand Down
6 changes: 3 additions & 3 deletions src/db/import/ClimbTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const transformClimbRecord = (row: any): ClimbType => {
font: grade.Font,
french: grade.French
},
gradeContext: gradeContext,
safety: safety,
gradeContext,
safety,
type: disciplines,
fa: fa,
fa,
metadata: {
lnglat: geometry('Point', parent_lnglat) as Point,
left_right_index: left_right_seq,
Expand Down
2 changes: 1 addition & 1 deletion src/db/import/usa/AreaTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const createAreas = async (root: AreaNode, areas: any[], areaModel: mongo
// Build a tree from each record in the state data file
const tree = new Tree(root)
areas.forEach(record => {
const { path }: {path: string} = record
const { path }: { path: string } = record
/* eslint-disable-next-line */
const fullPath = `${record.us_state}|${path}` // 'path' doesn't have a parent (a US state)
tree.insertMany(fullPath, record)
Expand Down
2 changes: 1 addition & 1 deletion src/db/import/usa/LinkClimbsWithCrags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const linkClimbsWithAreas = async (
climbModel: mongoose.Model<ClimbType>,
areaModel: mongoose.Model<AreaType>): Promise<void> => {
// Group all climbs by crag
const climbsGroupByCrag: Array<{_id: mongoose.Types.ObjectId, climbs: ClimbType[]}> = await climbModel.aggregate([
const climbsGroupByCrag: Array<{ _id: mongoose.Types.ObjectId, climbs: ClimbType[] }> = await climbModel.aggregate([
{ $group: { _id: '$metadata.areaRef', climbs: { $push: '$$ROOT._id' } } }
]).allowDiskUse(true)

Expand Down
4 changes: 2 additions & 2 deletions src/db/import/usa/USADay0Seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const main = async (): Promise<void> => {

const rootNode = await createRoot('US', 'USA')

const stats: Array<JobStats|any> = await Promise.all<Array<JobStats|any>>(US_STATES.map(async state => {
const stats: Array<JobStats | any> = await Promise.all<Array<JobStats | any>>(US_STATES.map(async state => {
const code = state.code.toLowerCase()
const fRoutes = `${contentDir}/${code}-routes.jsonlines`
const fAreas = `${contentDir}/${code}-areas.jsonlines`
Expand All @@ -51,7 +51,7 @@ const main = async (): Promise<void> => {
return await Promise.resolve()
}

const printStats = (stats: Array<JobStats|any>): void => {
const printStats = (stats: Array<JobStats | any>): void => {
logger.info('------------------ Summary -------------------')
const sums = { states: 0, climbs: 0, areas: 0 }
for (const entry of stats) {
Expand Down
2 changes: 1 addition & 1 deletion src/db/utils/jobs/CragUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const visitAllCrags = async (): Promise<void> => {
// Get all crags
const iterator = areaModel
.find({ 'metadata.leaf': true }).batchSize(10)
.populate<{climbs: ClimbType[]}>({ path: 'climbs', model: getClimbModel() })
.populate<{ climbs: ClimbType[] }>({ path: 'climbs', model: getClimbModel() })
.allowDiskUse(true)

// Calculate stats and bbox
Expand Down
6 changes: 3 additions & 3 deletions src/graphql/area/AreaQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { AreaType } from '../../db/AreaTypes'
import type AreaDataSource from '../../model/AreaDataSource'

const AreaQueries = {
cragsWithin: async (_, { filter }, { dataSources }): Promise<AreaType|null> => {
const { areas }: {areas: AreaDataSource} = dataSources
cragsWithin: async (_, { filter }, { dataSources }): Promise<AreaType | null> => {
const { areas }: { areas: AreaDataSource } = dataSources
const { bbox, zoom } = filter
return await areas.findCragsWithin(bbox, zoom)
},

countries: async (_, params, { dataSources }): Promise<AreaType[]> => {
const { areas }: {areas: AreaDataSource} = dataSources
const { areas }: { areas: AreaDataSource } = dataSources
return await areas.listAllCountries()
}

Expand Down
6 changes: 3 additions & 3 deletions src/graphql/media/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ const MediaQueries = {
/**
* Given a list of media IDs return all tags.
*/
getTagsByMediaIdList: async (_, { uuidList }: {uuidList: string[]}, { dataSources }) => {
getTagsByMediaIdList: async (_, { uuidList }: { uuidList: string[] }, { dataSources }) => {
const { media }: DataSourcesType = dataSources
return await media.getTagsByMediaIds(uuidList)
},

/**
* Return most recent tags
*/
getRecentTags: async (_, { userLimit = 10 }: {userLimit: number | undefined}, { dataSources }): Promise<MediaListByAuthorType[]> => {
getRecentTags: async (_, { userLimit = 10 }: { userLimit: number | undefined }, { dataSources }): Promise<MediaListByAuthorType[]> => {
const { media }: DataSourcesType = dataSources
return await media.getRecentTags(userLimit)
},

getTagsLeaderboard: async (_, { limit = 30 }: {limit: number}, { dataSources }): Promise<TagsLeaderboardType[]> => {
getTagsLeaderboard: async (_, { limit = 30 }: { limit: number }, { dataSources }): Promise<TagsLeaderboardType[]> => {
const { media }: DataSourcesType = dataSources
return await media.getTagsLeaderboard(limit)
}
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/posts/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GetPostsInputType } from '../../db/PostTypes'

const PostQueries = {
// Given a list of postIDs, return a list of post documents.
getPosts: async (_, { input }: {input: GetPostsInputType}) => {
getPosts: async (_, { input }: { input: GetPostsInputType }) => {
const PostModel = getPostModel()
const posts = await PostModel.find({ _id: { $in: input.postIds } })
return { posts }
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/tag/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TagType, RemoveTagInputType } from '../../db/TagTypes'
import { getTagModel } from '../../db/TagSchema.js'

const TagMutations = {
addTag: async (_: any, { input }: {input: TagType}) => {
addTag: async (_: any, { input }: { input: TagType }) => {
const TagModel = getTagModel()
const newTag = new TagModel({
...input,
Expand All @@ -14,7 +14,7 @@ const TagMutations = {
return { tagId: res.id }
},

deleteTag: async (_: any, { input }: {input: RemoveTagInputType}) => {
deleteTag: async (_: any, { input }: { input: RemoveTagInputType }) => {
const TagModel = getTagModel()
const res = await TagModel.deleteOne({ _id: input.tagId })
return { numDeleted: res.deletedCount }
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/tag/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GetTagsInputType } from '../../db/TagTypes.js'

const TagQueries = {
// Given a list of TagIds, return a list of Tag documents.
getTags: async (_, { input }: {input: GetTagsInputType}) => {
getTags: async (_, { input }: { input: GetTagsInputType }) => {
const TagModel = getTagModel()
const tag = await TagModel.find({ _id: { $in: input.tagIds } }).lean()
return { tag }
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/tick/TickMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const TickMutations = {
{ dataSources }) => {
const { ticks }: { ticks: TickDataSource } = dataSources
const res = await ticks.deleteTick(_id)
if (res?.deletedCount === 1) return { _id: _id, removed: true }
return { _id: _id, removed: false }
if (res?.deletedCount === 1) return { _id, removed: true }
return { _id, removed: false }
},
deleteAllTicks: async (
_,
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/xmedia/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GetXMediaInputType } from '../../db/XMediaTypes.js'

const XMediaQueries = {
// Given a list of xMediaIds, return a list of xMedia documents.
getXMedia: async (_, { input }: {input: GetXMediaInputType}) => {
getXMedia: async (_, { input }: { input: GetXMediaInputType }) => {
const xMediaModel = getXMediaModel()
const xMedia = await xMediaModel.find({ _id: { $in: input.xMediaIds } }).lean()
return { xMedia }
Expand Down
4 changes: 2 additions & 2 deletions src/model/AreaDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export default class AreaDataSource extends MongoDataSource<AreaType> {
* ```
* @param uuid climb uuid
*/
async findOneClimbByUUID (uuid: muuid.MUUID): Promise<ClimbGQLQueryType|null> {
async findOneClimbByUUID (uuid: muuid.MUUID): Promise<ClimbGQLQueryType | null> {
const rs = await this.climbModel
.aggregate([
{ $match: { _id: uuid } },
Expand Down Expand Up @@ -353,7 +353,7 @@ export default class AreaDataSource extends MongoDataSource<AreaType> {
{ $unset: 'crags.distance' }, // remove 'distance' field
{ $set: { 'crags.climbs': [] } }, // set to empty []
// this is a hack to add an arbitrary token to make the graphql result uniquely identifiable for Apollo client-side cache. Todo: look for a better way as this could be potential injection.
{ $addFields: { placeId: placeId } }])
{ $addFields: { placeId } }])
return rs
}

Expand Down
2 changes: 1 addition & 1 deletion src/model/ChangeLogDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class ChangeLogDataSource extends MongoDataSource<ChangeLogType>
* @param uuidList optional filter
* @returns change sets
*/
async getChangeSets (uuidList: MUUID[]): Promise<Array<AreaChangeLogType|ClimbChangeLogType>> {
async getChangeSets (uuidList: MUUID[]): Promise<Array<AreaChangeLogType | ClimbChangeLogType>> {
const rs = await this.changeLogModel.aggregate([
{
$sort: {
Expand Down
2 changes: 1 addition & 1 deletion src/model/ExperimentalUserDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class MediaDataSource extends MongoDataSource<ExperimentalUserTyp
* @param inputUrl
* @returns User UUID if successful. null otherwise.
*/
async updateUser (session: ClientSession, inputDisplayName: string, inputUrl: string): Promise<MUUID|null> {
async updateUser (session: ClientSession, inputDisplayName: string, inputUrl: string): Promise<MUUID | null> {
const url: string = inputUrl
let displayName = inputDisplayName != null ? inputDisplayName.trim().substring(0, 50) : ''
let uuid: MUUID
Expand Down
4 changes: 2 additions & 2 deletions src/model/MutableAreaDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@ export const newAreaHelper = (areaName: string, parentAncestors: string, parentP
leftRightIndex: -1,
ext_id: ''
},
ancestors: ancestors,
ancestors,
climbs: [],
pathTokens: pathTokens,
pathTokens,
gradeContext: parentGradeContext,
aggregate: {
byGrade: [],
Expand Down
10 changes: 5 additions & 5 deletions src/model/MutableOrganizationDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class MutableOrganizationDataSource extends OrganizationDataSourc
async _addOrganization (session, user: MUUID, displayName: string, orgType: OrgType): Promise<any> {
const change = await changelogDataSource.create(session, user, OperationType.addOrganization)
const newChangeMeta: ChangeRecordMetadataType = {
user: user,
user,
historyId: change._id,
operation: OperationType.addOrganization,
seq: 0
Expand Down Expand Up @@ -61,7 +61,7 @@ export default class MutableOrganizationDataSource extends OrganizationDataSourc
async updateOrganization (user: MUUID, orgId: MUUID, document: OrganizationEditableFieldsType): Promise<OrganizationType | null> {
const _updateOrganization = async (session: ClientSession, user: MUUID, orgId: MUUID, document: OrganizationEditableFieldsType): Promise<any> => {
const filter = {
orgId: orgId,
orgId,
deleting: { $ne: null }
}

Expand All @@ -76,12 +76,12 @@ export default class MutableOrganizationDataSource extends OrganizationDataSourc
if (associatedAreaIds != null && associatedAreaIds.length > 0) {
const missingAreaIds = await findNonexistantAreas(associatedAreaIds)
if (missingAreaIds.length > 0) throw new Error(`Organization update error. Reason: Associated areas not found: ${missingAreaIds.map(m => muuidToString(m)).toString()}`)
org.set({ associatedAreaIds: associatedAreaIds })
org.set({ associatedAreaIds })
}
if (excludedAreaIds != null && excludedAreaIds.length > 0) {
const missingAreaIds = await findNonexistantAreas(excludedAreaIds)
if (missingAreaIds.length > 0) throw new Error(`Organization update error. Reason: Excluded areas not found: ${missingAreaIds.map(m => muuidToString(m)).toString()}`)
org.set({ excludedAreaIds: excludedAreaIds })
org.set({ excludedAreaIds })
}
if (displayName != null) { org.set({ displayName: sanitizeStrict(displayName) }) }
if (website != null) { org.set({ 'content.website': sanitizeStrict(website) }) }
Expand Down Expand Up @@ -127,7 +127,7 @@ export default class MutableOrganizationDataSource extends OrganizationDataSourc
*/
const findNonexistantAreas = async (areaIds: MUUID[]): Promise<MUUID[]> => {
const AreaModel = getAreaModel()
type AreaQueryResp = Array<{_id: MUUID, metadata: {area_id: MUUID}}>
type AreaQueryResp = Array<{ _id: MUUID, metadata: { area_id: MUUID } }>
const foundAreas: AreaQueryResp = await AreaModel.find(
{ 'metadata.area_id': { $in: areaIds } }
).select('metadata.area_id').lean()
Expand Down
4 changes: 2 additions & 2 deletions src/model/TickDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class TickDataSource extends MongoDataSource<TickType> {
throw new Error('Failed to delete previously imported ticks, Reason: userId was not provided')
}
try {
const res = await this.tickModel.deleteMany({ userId: userId, source: 'MP' })
const res = await this.tickModel.deleteMany({ userId, source: 'MP' })
return res
} catch (e) {
throw new Error(e)
Expand All @@ -43,7 +43,7 @@ export default class TickDataSource extends MongoDataSource<TickType> {
throw new Error('Failed to delete previously imported ticks, Reason: userId was not provided')
}
try {
const res = await this.tickModel.deleteMany({ userId: userId })
const res = await this.tickModel.deleteMany({ userId })
return res
} catch (e) {
throw new Error(e)
Expand Down
2 changes: 1 addition & 1 deletion src/model/__tests__/ticks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('Ticks', () => {
}

await ticks.deleteAllTicks(userId)
const newTick = await tickModel.findOne({ userId: userId })
const newTick = await tickModel.findOne({ userId })
expect(newTick).toBeNull()
})

Expand Down
Loading

0 comments on commit dde4020

Please sign in to comment.