refactor: remove lodash
This commit is contained in:
parent
22fc5f98f8
commit
49d0da3a6d
@ -501,9 +501,6 @@ importers:
|
||||
jsonwebtoken:
|
||||
specifier: ^9.0.2
|
||||
version: 9.0.2
|
||||
lodash:
|
||||
specifier: ^4.17.21
|
||||
version: 4.17.21
|
||||
lodash-es:
|
||||
specifier: ^4.17.21
|
||||
version: 4.17.21
|
||||
@ -592,9 +589,6 @@ importers:
|
||||
'@types/jsonwebtoken':
|
||||
specifier: ^9.0.5
|
||||
version: 9.0.5
|
||||
'@types/lodash':
|
||||
specifier: ^4.14.198
|
||||
version: 4.14.198
|
||||
'@types/lodash-es':
|
||||
specifier: ^4.17.12
|
||||
version: 4.17.12
|
||||
|
4
src/server/cache/index.ts
vendored
4
src/server/cache/index.ts
vendored
@ -1,5 +1,5 @@
|
||||
import { caching, MemoryCache } from 'cache-manager';
|
||||
import _ from 'lodash';
|
||||
import { uniqueId } from 'lodash-es';
|
||||
|
||||
let _cacheManager: MemoryCache;
|
||||
export async function getCacheManager() {
|
||||
@ -20,7 +20,7 @@ export async function getCacheManager() {
|
||||
export function buildQueryWithCache<T, Args extends any[]>(
|
||||
fetchFn: (...args: Args) => Promise<T>
|
||||
) {
|
||||
const id = _.uniqueId('cache-query');
|
||||
const id = uniqueId('cache-query');
|
||||
|
||||
const get = async (...args: Args): Promise<T> => {
|
||||
const key = [id, ...args.map((a) => JSON.stringify(a))].join('|');
|
||||
|
@ -6,9 +6,9 @@ import { FeedChannelNotifyFrequency, Prisma } from '@prisma/client';
|
||||
import { env } from '../utils/env.js';
|
||||
import { sendNotification } from '../model/notification/index.js';
|
||||
import { token } from '../model/notification/token/index.js';
|
||||
import _ from 'lodash';
|
||||
import pMap from 'p-map';
|
||||
import { sendFeedEventsNotify } from '../model/feed/event.js';
|
||||
import { get } from 'lodash-es';
|
||||
|
||||
type WebsiteEventCountSqlReturn = {
|
||||
workspace_id: string;
|
||||
@ -368,7 +368,7 @@ async function dailyHTTPCertCheckNotify() {
|
||||
continue;
|
||||
}
|
||||
|
||||
const content = `[${m.name}][${_.get(m.payload, 'url')}] Certificate will be expired in ${daysRemaining} days`;
|
||||
const content = `[${m.name}][${get(m.payload, 'url')}] Certificate will be expired in ${daysRemaining} days`;
|
||||
|
||||
try {
|
||||
await sendNotification(n, content, [token.text(content)]).catch(
|
||||
|
@ -17,9 +17,9 @@ import { createTransport } from 'nodemailer';
|
||||
import { Theme } from '@auth/core/types';
|
||||
import { generateSMTPHTML } from '../utils/smtp.js';
|
||||
import { SYSTEM_ROLES } from '@tianji/shared';
|
||||
import _ from 'lodash';
|
||||
import { IncomingMessage } from 'http';
|
||||
import { type Session } from '@auth/express';
|
||||
import { compact, set } from 'lodash-es';
|
||||
|
||||
export interface UserAuthPayload {
|
||||
id: string;
|
||||
@ -31,7 +31,7 @@ export const authConfig: Omit<AuthConfig, 'raw'> = {
|
||||
debug: env.isProd ? false : true,
|
||||
basePath: '/api/auth',
|
||||
trustHost: true,
|
||||
providers: _.compact([
|
||||
providers: compact([
|
||||
Credentials({
|
||||
id: 'account',
|
||||
name: 'Account',
|
||||
@ -103,8 +103,8 @@ export const authConfig: Omit<AuthConfig, 'raw'> = {
|
||||
};
|
||||
},
|
||||
session({ session, token, user }) {
|
||||
_.set(session, ['user', 'id'], token.sub);
|
||||
_.set(session, ['user', 'role'], token.role);
|
||||
set(session, ['user', 'id'], token.sub);
|
||||
set(session, ['user', 'role'], token.role);
|
||||
|
||||
return session;
|
||||
},
|
||||
|
@ -2,7 +2,6 @@ import { z } from 'zod';
|
||||
import { MonitorProvider } from './type.js';
|
||||
import axios from 'axios';
|
||||
import { saveMonitorStatus } from './_utils.js';
|
||||
import _ from 'lodash';
|
||||
|
||||
const openaiCreditGrantsSchema = z.object({
|
||||
object: z.string(),
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { ServerStatusInfo } from '../../types/index.js';
|
||||
import { createSubscribeInitializer, subscribeEventBus } from '../ws/shared.js';
|
||||
import _ from 'lodash';
|
||||
import { isServerOnline } from '@tianji/shared';
|
||||
|
||||
const serverMap: Record<
|
||||
|
@ -50,7 +50,6 @@
|
||||
"is-localhost-ip": "^2.0.0",
|
||||
"isolated-vm": "^4.7.2",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"lodash": "^4.17.21",
|
||||
"lodash-es": "^4.17.21",
|
||||
"maxmind": "^4.3.18",
|
||||
"md5": "^2.3.0",
|
||||
@ -82,7 +81,6 @@
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/fs-extra": "^11.0.3",
|
||||
"@types/jsonwebtoken": "^9.0.5",
|
||||
"@types/lodash": "^4.14.198",
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"@types/md5": "^2.3.5",
|
||||
"@types/morgan": "^1.9.5",
|
||||
|
@ -13,7 +13,6 @@ import {
|
||||
FeedEventModelSchema,
|
||||
} from '../../../prisma/zod/index.js';
|
||||
import { prisma } from '../../../model/_client.js';
|
||||
import _ from 'lodash';
|
||||
import {
|
||||
buildFeedPublicOpenapi,
|
||||
feedIntegrationRouter,
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { z } from 'zod';
|
||||
import { OpenApiMetaInfo, publicProcedure, router } from '../../trpc.js';
|
||||
import { prisma } from '../../../model/_client.js';
|
||||
import _ from 'lodash';
|
||||
import { OpenApiMeta } from 'trpc-openapi';
|
||||
import { OPENAPI_TAG } from '../../../utils/const.js';
|
||||
import { createFeedEvent } from '../../../model/feed/event.js';
|
||||
import { tencentCloudAlarmSchema } from '../../../model/_schema/feed.js';
|
||||
import { logger } from '../../../utils/logger.js';
|
||||
import { get, map } from 'lodash-es';
|
||||
|
||||
export const feedIntegrationRouter = router({
|
||||
github: publicProcedure
|
||||
@ -45,17 +45,17 @@ export const feedIntegrationRouter = router({
|
||||
}
|
||||
|
||||
if (eventType === 'push') {
|
||||
const pusherName = _.get(data, 'pusher.name');
|
||||
const pusherEmail = _.get(data, 'pusher.email');
|
||||
const commits = _.map(_.get(data, 'commits') as any[], (val) =>
|
||||
const pusherName = get(data, 'pusher.name');
|
||||
const pusherEmail = get(data, 'pusher.email');
|
||||
const commits = map(get(data, 'commits') as any[], (val) =>
|
||||
String(val.id).substring(0, 9)
|
||||
).join(', ');
|
||||
const fullName = _.get(data, 'repository.full_name');
|
||||
const repoUrl = _.get(data, 'repository.html_url');
|
||||
const ref = String(_.get(data, 'ref'));
|
||||
const senderId = String(_.get(data, 'sender.id'));
|
||||
const senderName = String(_.get(data, 'sender.login'));
|
||||
const url = String(_.get(data, 'compare'));
|
||||
const fullName = get(data, 'repository.full_name');
|
||||
const repoUrl = get(data, 'repository.html_url');
|
||||
const ref = String(get(data, 'ref'));
|
||||
const senderId = String(get(data, 'sender.id'));
|
||||
const senderName = String(get(data, 'sender.login'));
|
||||
const url = String(get(data, 'compare'));
|
||||
|
||||
await createFeedEvent(workspaceId, {
|
||||
channelId: channelId,
|
||||
@ -71,13 +71,13 @@ export const feedIntegrationRouter = router({
|
||||
|
||||
return 'ok';
|
||||
} else if (eventType === 'star') {
|
||||
const starCount = _.get(data, 'repository.stargazers_count');
|
||||
const fullName = _.get(data, 'repository.full_name');
|
||||
const repoUrl = _.get(data, 'repository.html_url');
|
||||
const senderId = String(_.get(data, 'sender.id'));
|
||||
const senderName = String(_.get(data, 'sender.login'));
|
||||
const senderUrl = String(_.get(data, 'sender.html_url'));
|
||||
const url = String(_.get(data, 'compare'));
|
||||
const starCount = get(data, 'repository.stargazers_count');
|
||||
const fullName = get(data, 'repository.full_name');
|
||||
const repoUrl = get(data, 'repository.html_url');
|
||||
const senderId = String(get(data, 'sender.id'));
|
||||
const senderName = String(get(data, 'sender.login'));
|
||||
const senderUrl = String(get(data, 'sender.html_url'));
|
||||
const url = String(get(data, 'compare'));
|
||||
|
||||
await createFeedEvent(workspaceId, {
|
||||
channelId: channelId,
|
||||
@ -93,14 +93,14 @@ export const feedIntegrationRouter = router({
|
||||
|
||||
return 'ok';
|
||||
} else if (eventType === 'issues') {
|
||||
const action = _.get(data, 'action') as 'opened' | 'closed';
|
||||
const starCount = _.get(data, 'repository.stargazers_count');
|
||||
const fullName = _.get(data, 'repository.full_name');
|
||||
const repoUrl = _.get(data, 'repository.html_url');
|
||||
const senderId = String(_.get(data, 'sender.id'));
|
||||
const senderName = String(_.get(data, 'sender.login'));
|
||||
const url = String(_.get(data, 'issue.url'));
|
||||
const title = String(_.get(data, 'issue.title'));
|
||||
const action = get(data, 'action') as 'opened' | 'closed';
|
||||
const starCount = get(data, 'repository.stargazers_count');
|
||||
const fullName = get(data, 'repository.full_name');
|
||||
const repoUrl = get(data, 'repository.html_url');
|
||||
const senderId = String(get(data, 'sender.id'));
|
||||
const senderName = String(get(data, 'sender.login'));
|
||||
const url = String(get(data, 'issue.url'));
|
||||
const title = String(get(data, 'issue.title'));
|
||||
|
||||
let eventName = eventType;
|
||||
let eventContent = '';
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { initTRPC, inferAsyncReturnType, TRPCError } from '@trpc/server';
|
||||
import _ from 'lodash';
|
||||
import { z } from 'zod';
|
||||
import { jwtVerify } from '../middleware/auth.js';
|
||||
import { getWorkspaceUser } from '../model/workspace.js';
|
||||
@ -8,6 +7,7 @@ import type { Request } from 'express';
|
||||
import { OpenApiMeta } from 'trpc-openapi';
|
||||
import { getSession } from '@auth/express';
|
||||
import { authConfig } from '../model/auth.js';
|
||||
import { get } from 'lodash-es';
|
||||
|
||||
export async function createContext({ req }: { req: Request }) {
|
||||
const authorization = req.headers['authorization'] ?? '';
|
||||
@ -97,7 +97,7 @@ function createWorkspacePermissionMiddleware(roles: ROLES[] = []) {
|
||||
return isUser.unstable_pipe(async (opts) => {
|
||||
const { ctx, input } = opts;
|
||||
|
||||
const workspaceId = _.get(input, 'workspaceId', '');
|
||||
const workspaceId = get(input, 'workspaceId', '');
|
||||
if (!workspaceId) {
|
||||
throw new TRPCError({
|
||||
code: 'INTERNAL_SERVER_ERROR',
|
||||
|
@ -5,7 +5,6 @@ import { DynamicDataType } from './types.js';
|
||||
import dayjs from 'dayjs';
|
||||
import minMax from 'dayjs/plugin/minMax.js';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import _ from 'lodash';
|
||||
import { getWorkspaceWebsiteDateRange } from '../model/workspace.js';
|
||||
import { isCuid } from '@paralleldrive/cuid2';
|
||||
import { getMinimumUnit } from '@tianji/shared';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { v1 as uuid } from 'uuid';
|
||||
import md5 from 'md5';
|
||||
import _ from 'lodash';
|
||||
import { compact } from 'lodash-es';
|
||||
|
||||
const jwtSecret =
|
||||
!process.env.JWT_SECRET ||
|
||||
@ -14,7 +14,7 @@ export const env = {
|
||||
jwtSecret,
|
||||
port: Number(process.env.PORT || 12345),
|
||||
auth: {
|
||||
provider: _.compact([
|
||||
provider: compact([
|
||||
!!process.env.EMAIL_SERVER && 'email',
|
||||
!!process.env.AUTH_GITHUB_ID && 'github',
|
||||
!!process.env.AUTH_GOOGLE_ID && 'google',
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { Prisma } from '@prisma/client';
|
||||
import dayjs from 'dayjs';
|
||||
import _ from 'lodash';
|
||||
import { loadWebsite } from '../model/website.js';
|
||||
import { maxDate } from './common.js';
|
||||
import { FILTER_COLUMNS, OPERATORS, SESSION_COLUMNS } from './const.js';
|
||||
import { loadTelemetry } from '../model/telemetry.js';
|
||||
import { get } from 'lodash-es';
|
||||
|
||||
const POSTGRESQL_DATE_FORMATS = {
|
||||
minute: 'YYYY-MM-DD HH24:MI:00',
|
||||
@ -136,7 +136,7 @@ export function getWebsiteFilterQuery(
|
||||
const query = Object.keys(filters).reduce<string[]>((arr, name) => {
|
||||
const value: any = filters[name as keyof WebsiteQueryFilters];
|
||||
const operator = value?.filter ?? OPERATORS.equals;
|
||||
const column = _.get(FILTER_COLUMNS, name, options?.columns?.[name]);
|
||||
const column = get(FILTER_COLUMNS, name, options?.columns?.[name]);
|
||||
|
||||
// TODO
|
||||
|
||||
@ -163,7 +163,7 @@ export function getTelemetryFilterQuery(
|
||||
const query = Object.keys(filters).reduce<string[]>((arr, name) => {
|
||||
const value: any = filters[name as keyof BaseQueryFilters];
|
||||
const operator = value?.filter ?? OPERATORS.equals;
|
||||
const column = _.get(FILTER_COLUMNS, name, options?.columns?.[name]);
|
||||
const column = get(FILTER_COLUMNS, name, options?.columns?.[name]);
|
||||
|
||||
// TODO
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user