Browse Source

Merge pull request #268 from zilliztech/refactor

Support import sever module in client
ryjiang 1 year ago
parent
commit
a8c9abf32b

+ 20 - 0
.github/workflows/ci.yml

@@ -0,0 +1,20 @@
+name: Attu docker build test
+
+on:
+  pull_request:
+    branches:
+      - main
+    types: [opened, synchronize]
+
+jobs:
+  publish:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - name: Setup Node.js
+        uses: actions/setup-node@v3
+        with:
+          node-version: 18
+
+      - name: Docker Build
+        run: docker build -t zilliz/attu:dev --build-arg VERSION=dev .

+ 2 - 1
client/src/components/layout/GlobalEffect.tsx

@@ -1,7 +1,8 @@
 import React, { useContext } from 'react';
 import axiosInstance from '@/http/Axios';
 import { rootContext, authContext } from '@/context';
-import { HTTP_STATUS_CODE, MILVUS_ADDRESS } from '@/consts';
+import { MILVUS_ADDRESS } from '@/consts';
+import { HTTP_STATUS_CODE } from '@server/utils/Const';
 
 let axiosResInterceptor: number | null = null;
 // let timer: Record<string, ReturnType<typeof setTimeout> | number>[] = [];

+ 0 - 61
client/src/consts/Http.ts

@@ -1,61 +0,0 @@
-export enum HTTP_STATUS_CODE {
-  CONTINUE = 100,
-  SWITCHING_PROTOCOLS = 101,
-  PROCESSING = 102,
-  EARLYHINTS = 103,
-  OK = 200,
-  CREATED = 201,
-  ACCEPTED = 202,
-  NON_AUTHORITATIVE_INFORMATION = 203,
-  NO_CONTENT = 204,
-  RESET_CONTENT = 205,
-  PARTIAL_CONTENT = 206,
-  AMBIGUOUS = 300,
-  MOVED_PERMANENTLY = 301,
-  FOUND = 302,
-  SEE_OTHER = 303,
-  NOT_MODIFIED = 304,
-  TEMPORARY_REDIRECT = 307,
-  PERMANENT_REDIRECT = 308,
-  BAD_REQUEST = 400,
-  UNAUTHORIZED = 401,
-  PAYMENT_REQUIRED = 402,
-  FORBIDDEN = 403,
-  NOT_FOUND = 404,
-  METHOD_NOT_ALLOWED = 405,
-  NOT_ACCEPTABLE = 406,
-  PROXY_AUTHENTICATION_REQUIRED = 407,
-  REQUEST_TIMEOUT = 408,
-  CONFLICT = 409,
-  GONE = 410,
-  LENGTH_REQUIRED = 411,
-  PRECONDITION_FAILED = 412,
-  PAYLOAD_TOO_LARGE = 413,
-  URI_TOO_LONG = 414,
-  UNSUPPORTED_MEDIA_TYPE = 415,
-  REQUESTED_RANGE_NOT_SATISFIABLE = 416,
-  EXPECTATION_FAILED = 417,
-  I_AM_A_TEAPOT = 418,
-  MISDIRECTED = 421,
-  UNPROCESSABLE_ENTITY = 422,
-  FAILED_DEPENDENCY = 424,
-  TOO_MANY_REQUESTS = 429,
-  INTERNAL_SERVER_ERROR = 500,
-  NOT_IMPLEMENTED = 501,
-  BAD_GATEWAY = 502,
-  SERVICE_UNAVAILABLE = 503,
-  GATEWAY_TIMEOUT = 504,
-  HTTP_VERSION_NOT_SUPPORTED = 505,
-}
-
-
-export const START_LOADING_TIME = 350;
-
-export enum WS_EVENTS {
-  COLLECTION = 'COLLECTION',
-}
-
-export enum WS_EVENTS_TYPE {
-  START,
-  STOP,
-}

+ 0 - 1
client/src/consts/index.ts

@@ -1,4 +1,3 @@
-export * from './Http';
 export * from './Insert';
 export * from './Localstorage';
 export * from './Milvus';

+ 1 - 1
client/src/context/WebSocket.tsx

@@ -1,11 +1,11 @@
 import { createContext, useContext, useEffect, useState, useRef } from 'react';
 import { io, Socket } from 'socket.io-client';
-import { WS_EVENTS, WS_EVENTS_TYPE } from '@/consts';
 import { authContext } from '@/context';
 import { url, CollectionHttp, MilvusHttp } from '@/http';
 import { CollectionView } from '@/pages/collections/Types';
 import { checkIndexBuilding, checkLoading } from '@/utils';
 import { WebSocketType } from './Types';
+import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const';
 
 export const webSocketContext = createContext<WebSocketType>({
   collections: [],

+ 1 - 1
client/src/http/Milvus.ts

@@ -1,4 +1,4 @@
-import { WS_EVENTS, WS_EVENTS_TYPE } from '@/consts';
+import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const';
 import BaseModel from './BaseModel';
 
 export class MilvusHttp extends BaseModel {

+ 2 - 1
client/src/pages/collections/Collections.tsx

@@ -29,7 +29,8 @@ import DropCollectionDialog from '../dialogs/DropCollectionDialog';
 import RenameCollectionDialog from '../dialogs/RenameCollectionDialog';
 import InsertDialog from '../dialogs/insert/Dialog';
 import ImportSampleDialog from '../dialogs/ImportSampleDialog';
-import { LOADING_STATE, WS_EVENTS, WS_EVENTS_TYPE } from '@/consts';
+import { LOADING_STATE } from '@/consts';
+import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const';
 import { checkIndexBuilding, checkLoading } from '@/utils';
 import Aliases from './Aliases';
 

+ 2 - 6
client/src/pages/overview/Overview.tsx

@@ -13,12 +13,8 @@ import dayjs from 'dayjs';
 import { rootContext, webSocketContext, dataContext } from '@/context';
 import EmptyCard from '@/components/cards/EmptyCard';
 import icons from '@/components/icons/Icons';
-import {
-  WS_EVENTS,
-  WS_EVENTS_TYPE,
-  LOADING_STATE,
-  MILVUS_DEPLOY_MODE,
-} from '@/consts';
+import { LOADING_STATE, MILVUS_DEPLOY_MODE } from '@/consts';
+import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const';
 import { useNavigationHook } from '@/hooks';
 import { CollectionHttp, MilvusHttp } from '@/http';
 import { ALL_ROUTER_TYPES } from '@/router/Types';

+ 2 - 1
client/tsconfig.json

@@ -10,7 +10,8 @@
     ],
     "baseUrl": "./",
     "paths": {
-      "@/*": ["src/*"]
+      "@/*": ["src/*"],
+      "@server/*": ["../server/src/*"]
     },
     "allowJs": true,
     "skipLibCheck": true,

+ 2 - 0
client/vite.config.ts

@@ -27,6 +27,8 @@ export default defineConfig({
     // extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"],
     alias: {
       '@': path.resolve(__dirname, './src'),
+      // be careful to include server modules in the client
+      '@server': path.resolve(__dirname, './../server/src'),
     },
   },
 });

+ 3 - 3
server/src/app.ts

@@ -21,13 +21,13 @@ import {
   ErrorMiddleware,
   ReqHeaderMiddleware,
 } from './middleware';
-import { EXPIRED_TIME, INSIGHT_CACHE } from './utils/Const';
+import { EXPIRED_TIME, CACHE_KEY } from './utils';
 import { getIp } from './utils/Network';
 // initialize express app
 export const app = express();
 
 // initialize cache store
-const insightCache = new LruCache({
+const cache = new LruCache({
   maxAge: EXPIRED_TIME,
   updateAgeOnGet: true,
 });
@@ -54,7 +54,7 @@ const server = http.createServer(app);
 const PORT = 3000;
 // setup middlewares
 // use cache
-app.set(INSIGHT_CACHE, insightCache);
+app.set(CACHE_KEY, cache);
 // use cors https://expressjs.com/en/resources/middleware/cors.html
 app.use(cors());
 // use helmet https://github.com/helmetjs/helmet

+ 4 - 4
server/src/collections/collections.controller.ts

@@ -84,8 +84,8 @@ export class CollectionController {
     );
 
     // segments
-    this.router.get('/:name/psegments', this.getPSegement.bind(this));
-    this.router.get('/:name/qsegments', this.getQSegement.bind(this));
+    this.router.get('/:name/psegments', this.getPSegment.bind(this));
+    this.router.get('/:name/qsegments', this.getQSegment.bind(this));
 
     this.router.put('/:name/compact', this.compact.bind(this));
     return this.router;
@@ -335,7 +335,7 @@ export class CollectionController {
     }
   }
 
-  async getPSegement(req: Request, res: Response, next: NextFunction) {
+  async getPSegment(req: Request, res: Response, next: NextFunction) {
     const name = req.params?.name;
     try {
       const result = await this.collectionsService.getPersistentSegmentInfo({
@@ -347,7 +347,7 @@ export class CollectionController {
     }
   }
 
-  async getQSegement(req: Request, res: Response, next: NextFunction) {
+  async getQSegment(req: Request, res: Response, next: NextFunction) {
     const name = req.params?.name;
     try {
       const result = await this.collectionsService.getQuerySegmentInfo({

+ 4 - 6
server/src/collections/collections.service.ts

@@ -21,13 +21,11 @@ import {
   GePersistentSegmentInfoReq,
   CompactReq,
 } from '@zilliz/milvus2-sdk-node';
-import { throwErrorFromSDK } from '../utils/Error';
-import { findKeyValue, genRows } from '../utils/Helper';
-import { ROW_COUNT } from '../utils/Const';
+import { throwErrorFromSDK, findKeyValue, genRows, ROW_COUNT } from '../utils';
 import { QueryDto, ImportSampleDto, GetReplicasDto } from './dto';
 
 export class CollectionsService {
-  constructor(private milvusService: MilvusService) {}
+  constructor(private milvusService: MilvusService) { }
 
   async getCollections(data?: ShowCollectionsReq) {
     const res = await this.milvusService.client.showCollections(data);
@@ -189,8 +187,8 @@ export class CollectionsService {
         try {
           replicas = loadCollection
             ? await this.getReplicas({
-                collectionID: collectionInfo.collectionID,
-              })
+              collectionID: collectionInfo.collectionID,
+            })
             : replicas;
         } catch (e) {
           console.log('ignore getReplica');

+ 0 - 247
server/src/collections/swagger.yml

@@ -1,247 +0,0 @@
-paths:
-  /collections:
-    get:
-      tags: 
-        - Collection
-      description: Get all or loaded collection
-      parameters:
-        - in: query
-          name: type
-          type: number
-          description: If type is 1 return loaded collections, otherwise return all collections.
-      responses:
-        200:
-          description: CollectionList
-          schema:
-            type: object
-    post:
-      tags: 
-        - Collection
-      description: Create collection in milvus
-      requestBody:
-        description: Create collection request body
-        required: true
-        content:
-          application/json:
-            schema:
-              $ref: '#/definitions/CreateCollection'
-         
-      responses:
-        200:
-          schema:
-            type: object
-  /collections/statistics:
-    get:
-      tags: 
-        - Collection
-      description: Get all collections statistics like row count
-      responses:
-        200:
-          schema:
-            type: object
-
-  /collections/{name}/statistics:
-    get:
-      tags: 
-        - Collection
-      description: Get single collection statistics like row count
-      parameters:
-        - $ref: '#/definitions/CollectionName'
-
-      responses:
-        200:
-          schema:
-            type: object
-  /collections/indexes/status:
-    get:
-      tags: 
-        - Collection
-      description: Get all collections index status
-
-      responses:
-        200:
-          schema:
-            type: object
-
-  /collections/{name}:
-    delete:
-      tags: 
-        - Collection
-      description: Delete collection by name
-      parameters:
-        - $ref: '#/definitions/CollectionName'
-      responses:
-        200:
-          schema:
-            type: object
-    get:
-      tags: 
-        - Collection
-      description: Get single collection informations like schema, name, id
-      parameters:
-        - $ref: '#/definitions/CollectionName'
-      responses:
-        200:
-          schema:
-            type: object
-  /collections/{name}/load:
-    put:
-      tags: 
-        - Collection
-      description: Load data to cache
-      parameters:
-        - $ref: '#/definitions/CollectionName'
-      responses:
-        200:
-          schema:
-            type: object
-  /collections/{name}/release:
-    put:
-      tags: 
-        - Collection
-      description: Release data from cache
-      parameters:
-        - $ref: '#/definitions/CollectionName'
-      responses:
-        200:
-          schema:
-            type: object
-  /collections/{name}/insert:
-    post:
-      tags: 
-        - Collection
-      description: Insert data into collection
-      parameters:
-        - $ref: '#/definitions/CollectionName'
-      requestBody:
-        description: Insert data into collection
-        required: true
-        content:
-          application/json:
-            schema:
-              $ref: '#/definitions/Insert'
-      responses:
-        200:
-          schema:
-            type: object
-            
-  /collections/{name}/search:
-    post:
-      tags: 
-        - Collection
-      description: Vector search 
-      parameters:
-        - $ref: '#/definitions/CollectionName'
-      requestBody:
-        description: Do vector search
-        required: true
-        content:
-          application/json:
-            schema:
-              $ref: '#/definitions/Search'
-      responses:
-        200:
-          schema:
-            type: object
-
-  /collections/{name}/query:
-    post:
-      tags: 
-        - Collection
-      description: query data
-      parameters:
-        - $ref: '#/definitions/CollectionName'
-      requestBody:
-        description: query data body
-        required: true
-        content:
-          application/json:
-            schema:
-              type: object
-              required:
-                - "expr"
-              properties:
-                expr:
-                  type: string
-                  example: id in [1]
-      responses:
-        200:
-          schema:
-            type: object      
-
-/collections/{name}/alias:
-    post:
-      tags: 
-        - Collection
-      description: Create alias for collection
-      parameters:
-        - $ref: '#/definitions/CollectionName'
-      requestBody:
-        description: alias name
-        required: true
-        content:
-          application/json:
-            schema:
-              type: object
-              required:
-                - "alias"
-              properties:
-                alias:
-                  type: string
-                  example: collection_alias
-      responses:
-        200:
-          schema:
-            type: object                   
-
-
-definitions:
-  CollectionName:
-    in: path
-    name: name
-    type: string
-    description: Collection name
-  CreateCollection:
-    type: object
-    required:
-      - "collection_name"
-      - "fields"
-    properties:
-      collection_name:
-        type: string
-        example: collection_01
-      fields:
-        type: array
-        example: []
-  Insert:
-    type: object
-    required:
-      - "fields_data"
-    properties:
-      partition_name:
-        type: string
-        example: _default
-      fields_data:
-        type: array
-        example: []
-      hash_keys:
-        type: array
-        example: []
-  Search:
-    type: object
-    required:
-      - "vectors"
-      - "vector_type"
-      - "search_params"
-    properties:
-      vectors:
-        type: array
-        example: []
-        
-      vector_type:
-        description: BinaryVector - 100 , FloatVector - 101
-        type: number
-        example: 100 
-      search_params:
-        type: object
-        example: {"anns_field":"","topk":10,"metric_type":"L2","params":""}

+ 1 - 1
server/src/crons/crons.controller.ts

@@ -3,7 +3,7 @@ import { dtoValidationMiddleware } from '../middleware/validation';
 import { CronsService, SchedulerRegistry } from './crons.service';
 import { collectionsService } from '../collections';
 import { ToggleCronJobByNameDto } from './dto';
-import { MILVUS_ADDRESS } from '../utils/Const';
+import { MILVUS_ADDRESS } from '../utils';
 
 export class CronsController {
   private router: Router;

+ 2 - 2
server/src/crons/crons.service.ts

@@ -1,6 +1,6 @@
-import { CollectionsService } from '../collections/collections.service';
-import { WS_EVENTS, WS_EVENTS_TYPE } from '../utils/Const';
 import { schedule, ScheduledTask } from 'node-cron';
+import { CollectionsService } from '../collections/collections.service';
+import { WS_EVENTS, WS_EVENTS_TYPE } from '../utils';
 import { pubSub } from '../events';
 
 export class CronsService {

+ 1 - 1
server/src/crons/dto.ts

@@ -1,5 +1,5 @@
 import { IsEnum, IsString } from "class-validator";
-import { WS_EVENTS_TYPE } from "../utils/Const";
+import { WS_EVENTS_TYPE } from "../utils";
 
 export class ToggleCronJobByNameDto {
   @IsString()

+ 0 - 28
server/src/crons/swagger.yml

@@ -1,28 +0,0 @@
-paths:
-  /crons:
-    put:
-      tags: 
-        - Crons
-      description: Toggle cronjob status
-      requestBody:
-        description: Cron job name, status(start->0, stop->1)
-        required: true
-        content:
-          application/json:
-            schema:
-              type: object
-              required:
-                - "name"
-              properties:
-                name:
-                  type: string
-                  example: COLLECTION
-                type:
-                  type: number
-                  example: 0
-      responses:
-        200:
-          schema:
-            type: object
-
- 

+ 4 - 5
server/src/middleware/index.ts

@@ -2,9 +2,8 @@ import { Request, Response, NextFunction } from 'express';
 import morgan from 'morgan';
 import chalk from 'chalk';
 import { MilvusService } from '../milvus/milvus.service';
-import { INSIGHT_CACHE, MILVUS_ADDRESS } from '../utils/Const';
+import { CACHE_KEY, MILVUS_ADDRESS, HTTP_STATUS_CODE } from '../utils';
 import { HttpError } from 'http-errors';
-import { HTTP_STATUS_CODE } from '../utils/Error';
 import HttpErrors from 'http-errors';
 
 export const ReqHeaderMiddleware = (
@@ -12,7 +11,7 @@ export const ReqHeaderMiddleware = (
   res: Response,
   next: NextFunction
 ) => {
-  const insightCache = req.app.get(INSIGHT_CACHE);
+  const cache = req.app.get(CACHE_KEY);
   // all ape requests need set milvus address in header.
   // server will set active address in milvus service.
   const milvusAddress = (req.headers[MILVUS_ADDRESS] as string) || '';
@@ -21,10 +20,10 @@ export const ReqHeaderMiddleware = (
   //  only api request has MILVUS_ADDRESS.
   //  When client run in express, we dont need static files like: xx.js run this logic.
   //  Otherwise will cause 401 error.
-  if (milvusAddress && insightCache.has(milvusAddress)) {
+  if (milvusAddress && cache.has(milvusAddress)) {
     MilvusService.activeAddress = milvusAddress;
     // insight cache will update expire time when use insightCache.get
-    MilvusService.activeMilvusClient = insightCache.get(milvusAddress);
+    MilvusService.activeMilvusClient = cache.get(milvusAddress);
   }
 
   const CONNECT_URL = `/api/v1/milvus/connect`;

+ 5 - 8
server/src/milvus/milvus.controller.ts

@@ -2,7 +2,7 @@ import { NextFunction, Request, Response, Router } from 'express';
 import { dtoValidationMiddleware } from '../middleware/validation';
 import { MilvusService } from './milvus.service';
 import { ConnectMilvusDto, FlushDto, UseDatabaseDto } from './dto';
-import { INSIGHT_CACHE } from '../utils/Const';
+import { CACHE_KEY } from '../utils';
 import packageJson from '../../package.json';
 
 export class MilvusController {
@@ -44,11 +44,11 @@ export class MilvusController {
 
   async connectMilvus(req: Request, res: Response, next: NextFunction) {
     const { address, username, password } = req.body;
-    const insightCache = req.app.get(INSIGHT_CACHE);
+    const cache = req.app.get(CACHE_KEY);
     try {
       const result = await this.milvusService.connectMilvus(
         { address, username, password },
-        insightCache
+        cache
       );
 
       res.send(result);
@@ -60,13 +60,10 @@ export class MilvusController {
 
   async checkConnect(req: Request, res: Response, next: NextFunction) {
     const address = '' + req.query?.address;
-    const insightCache = req.app.get(INSIGHT_CACHE);
+    const cache = req.app.get(CACHE_KEY);
 
     try {
-      const result = await this.milvusService.checkConnect(
-        address,
-        insightCache
-      );
+      const result = await this.milvusService.checkConnect(address, cache);
       res.send(result);
     } catch (error) {
       next(error);

+ 2 - 2
server/src/milvus/milvus.service.ts

@@ -5,8 +5,8 @@ import {
 } from '@zilliz/milvus2-sdk-node';
 import HttpErrors from 'http-errors';
 import LruCache from 'lru-cache';
-import { HTTP_STATUS_CODE } from '../utils/Error';
-import { DEFAULT_MILVUS_PORT } from '../utils/Const';
+import { HTTP_STATUS_CODE } from '../utils/Const';
+import { DEFAULT_MILVUS_PORT } from '../utils';
 import { connectivityState } from '@grpc/grpc-js';
 
 export class MilvusService {

+ 0 - 80
server/src/milvus/swagger.yml

@@ -1,80 +0,0 @@
-paths:
-  /milvus/connect:
-    post:
-      tags:
-        - Milvus
-      description: Connect to milvus server
-      requestBody:
-        description: Milvus address
-        required: true
-        content:
-          application/json:
-            schema:
-              type: object
-              required:
-                - 'address'
-              properties:
-                address:
-                  type: string
-                  example: 127.0.0.1:19530
-      responses:
-        200:
-          schema:
-            type: object
-
-  /milvus/disconnect:
-    post:
-      tags:
-        - Milvus
-      description: Disconnect to milvus server
-      responses:
-        200:
-          schema:
-            type: object
-
-  /milvus/check:
-    get:
-      tags:
-        - Milvus
-      description: Check milvus alive or not.
-      parameters:
-        - in: query
-          name: address
-          description: Milvus address
-      responses:
-        200:
-          schema:
-            type: object
-
-  /milvus/metrics:
-    get:
-      tags:
-        - Milvus
-      description: Get milvus metrics
-      responses:
-        200:
-          schema:
-            type: object
-
-  /milvus/flush:
-    post:
-      tags:
-        - Milvus
-      description: Flush data in milvus
-      requestBody:
-        description: The collection names you want to flush
-        required: true
-        content:
-          application/json:
-            schema:
-              type: object
-              required:
-                - 'collection_names'
-              properties:
-                collection_names:
-                  type: array
-                  example: [collectionName]
-      responses:
-        200:
-          schema:
-            type: object

+ 1 - 1
server/src/partitions/partitions.service.ts

@@ -9,7 +9,7 @@ import {
 } from '@zilliz/milvus2-sdk-node';
 import { throwErrorFromSDK } from '../utils/Error';
 import { findKeyValue } from '../utils/Helper';
-import { ROW_COUNT } from '../utils/Const';
+import { ROW_COUNT } from '../utils';
 
 export class PartitionsService {
   constructor(private milvusService: MilvusService) {}

+ 0 - 97
server/src/partitions/swagger.yml

@@ -1,97 +0,0 @@
-paths:
-  /partitions:
-    get:
-      tags: 
-        - Partition
-      description: Get all partitions information
-      parameters:
-        - in: query
-          name: collection_name
-          type: string
-          description: Collection name
-      responses:
-        200:
-          schema:
-            type: object
-  
-    post:
-      tags: 
-        - Partition
-      description: Create or delete partition excepte _default
-      requestBody:
-        description: Manage partition req body
-        required: true
-        content:
-          application/json:
-            schema:
-              type: object
-              required:
-                - type
-                - collection_name
-                - partition_name
-              properties:
-                type:
-                  type: string
-                  example: create
-                collection_name:
-                  type: string
-                  example: ''
-                partition_name:
-                  type: string
-                  example: ''
-      responses:
-        200:
-          schema:
-            type: object
-
-  /partitions/load:
-    put:
-      tags: 
-        - Partition
-      description: Load partition to cache
-      requestBody:
-        required: true
-        content:
-          application/json:
-            schema:
-              type: object
-              required:
-                - collection_name
-                - partition_name
-              properties:
-                collection_name:
-                  type: string
-                  example: ''
-                partition_names:
-                  type: array
-                  example: []
-      responses:
-        200:
-          schema:
-            type: object
-  /partitions/release:
-    put:
-      tags: 
-        - Partition
-      description: Release partition from cache
-      requestBody:
-        required: true
-        content:
-          application/json:
-            schema:
-              type: object
-              required:
-                - collection_name
-                - partition_name
-              properties:
-                collection_name:
-                  type: string
-                  example: ''
-                partition_names:
-                  type: array
-                  example: []
-      responses:
-        200:
-          schema:
-            type: object
- 

+ 0 - 78
server/src/schema/swagger.yml

@@ -1,78 +0,0 @@
-paths:
-  /schema/index:
-    get:
-      tags: 
-        - Schema
-      description: Get index information
-      parameters:
-        - $ref: '#/definitions/CollectionName'
-      responses:
-        200:
-          schema:
-            type: object
-  
-    post:
-      tags: 
-        - Schema
-      description: Create or delete index in collection
-      requestBody:
-        description: Only type is create need extra_params
-        required: true
-        content:
-          application/json:
-            schema:
-              type: object
-              required:
-                - type
-                - collection_name
-                - field_name
-              properties:
-                type:
-                  type: string
-                  example: create
-                collection_name:
-                  type: string
-                  example: ''
-                field_name:
-                  type: string
-                  example: 'vector field'
-                extra_params:
-                  type: object
-                  example: {"index_type":"","metric_type":"","params":""}
-      responses:
-        200:
-          schema:
-            type: object
-
-  /schema/index/progress:
-    get:
-      tags: 
-        - Schema
-      description: Get index building progress percentage
-      parameters:
-        - $ref: '#/definitions/CollectionName'
-      responses:
-        200:
-          schema:
-            type: object
-
-  /schema/index/state:
-    get:
-      tags: 
-        - Schema
-      description: Get index state 
-      parameters:
-        - $ref: '#/definitions/CollectionName'
-      responses:
-        200:
-          schema:
-            type: object
- 
-
-
-definitions:
-  CollectionName:
-    in: query
-    name: collection_name
-    type: string
-    description: Collection name

+ 52 - 1
server/src/utils/Const.ts

@@ -1,10 +1,11 @@
+// note, this module will be shared between server and client, so please don't import server only module here
 export const ROW_COUNT = 'row_count';
 
 // use in req header
 export const MILVUS_ADDRESS = 'milvus-address';
 
 // for lru cache
-export const INSIGHT_CACHE = 'insight_cache';
+export const CACHE_KEY = 'insight_cache';
 export const EXPIRED_TIME = 1000 * 60 * 60 * 24;
 
 export enum LOADING_STATE {
@@ -23,3 +24,53 @@ export enum WS_EVENTS_TYPE {
 }
 
 export const DEFAULT_MILVUS_PORT = 19530;
+
+export enum HTTP_STATUS_CODE {
+  CONTINUE = 100,
+  SWITCHING_PROTOCOLS = 101,
+  PROCESSING = 102,
+  EARLYHINTS = 103,
+  OK = 200,
+  CREATED = 201,
+  ACCEPTED = 202,
+  NON_AUTHORITATIVE_INFORMATION = 203,
+  NO_CONTENT = 204,
+  RESET_CONTENT = 205,
+  PARTIAL_CONTENT = 206,
+  AMBIGUOUS = 300,
+  MOVED_PERMANENTLY = 301,
+  FOUND = 302,
+  SEE_OTHER = 303,
+  NOT_MODIFIED = 304,
+  TEMPORARY_REDIRECT = 307,
+  PERMANENT_REDIRECT = 308,
+  BAD_REQUEST = 400,
+  UNAUTHORIZED = 401,
+  PAYMENT_REQUIRED = 402,
+  FORBIDDEN = 403,
+  NOT_FOUND = 404,
+  METHOD_NOT_ALLOWED = 405,
+  NOT_ACCEPTABLE = 406,
+  PROXY_AUTHENTICATION_REQUIRED = 407,
+  REQUEST_TIMEOUT = 408,
+  CONFLICT = 409,
+  GONE = 410,
+  LENGTH_REQUIRED = 411,
+  PRECONDITION_FAILED = 412,
+  PAYLOAD_TOO_LARGE = 413,
+  URI_TOO_LONG = 414,
+  UNSUPPORTED_MEDIA_TYPE = 415,
+  REQUESTED_RANGE_NOT_SATISFIABLE = 416,
+  EXPECTATION_FAILED = 417,
+  I_AM_A_TEAPOT = 418,
+  MISDIRECTED = 421,
+  UNPROCESSABLE_ENTITY = 422,
+  FAILED_DEPENDENCY = 424,
+  TOO_MANY_REQUESTS = 429,
+  INTERNAL_SERVER_ERROR = 500,
+  NOT_IMPLEMENTED = 501,
+  BAD_GATEWAY = 502,
+  SERVICE_UNAVAILABLE = 503,
+  GATEWAY_TIMEOUT = 504,
+  HTTP_VERSION_NOT_SUPPORTED = 505,
+}

+ 0 - 50
server/src/utils/Error.ts

@@ -8,53 +8,3 @@ export const throwErrorFromSDK = (res: ResStatus) => {
     throw res.reason;
   }
 };
-
-export enum HTTP_STATUS_CODE {
-  CONTINUE = 100,
-  SWITCHING_PROTOCOLS = 101,
-  PROCESSING = 102,
-  EARLYHINTS = 103,
-  OK = 200,
-  CREATED = 201,
-  ACCEPTED = 202,
-  NON_AUTHORITATIVE_INFORMATION = 203,
-  NO_CONTENT = 204,
-  RESET_CONTENT = 205,
-  PARTIAL_CONTENT = 206,
-  AMBIGUOUS = 300,
-  MOVED_PERMANENTLY = 301,
-  FOUND = 302,
-  SEE_OTHER = 303,
-  NOT_MODIFIED = 304,
-  TEMPORARY_REDIRECT = 307,
-  PERMANENT_REDIRECT = 308,
-  BAD_REQUEST = 400,
-  UNAUTHORIZED = 401,
-  PAYMENT_REQUIRED = 402,
-  FORBIDDEN = 403,
-  NOT_FOUND = 404,
-  METHOD_NOT_ALLOWED = 405,
-  NOT_ACCEPTABLE = 406,
-  PROXY_AUTHENTICATION_REQUIRED = 407,
-  REQUEST_TIMEOUT = 408,
-  CONFLICT = 409,
-  GONE = 410,
-  LENGTH_REQUIRED = 411,
-  PRECONDITION_FAILED = 412,
-  PAYLOAD_TOO_LARGE = 413,
-  URI_TOO_LONG = 414,
-  UNSUPPORTED_MEDIA_TYPE = 415,
-  REQUESTED_RANGE_NOT_SATISFIABLE = 416,
-  EXPECTATION_FAILED = 417,
-  I_AM_A_TEAPOT = 418,
-  MISDIRECTED = 421,
-  UNPROCESSABLE_ENTITY = 422,
-  FAILED_DEPENDENCY = 424,
-  TOO_MANY_REQUESTS = 429,
-  INTERNAL_SERVER_ERROR = 500,
-  NOT_IMPLEMENTED = 501,
-  BAD_GATEWAY = 502,
-  SERVICE_UNAVAILABLE = 503,
-  GATEWAY_TIMEOUT = 504,
-  HTTP_VERSION_NOT_SUPPORTED = 505,
-}

+ 12 - 7
server/src/utils/index.ts

@@ -1,12 +1,12 @@
-import glob from "glob";
-import fs from "fs";
+import glob from 'glob';
+import fs from 'fs';
 
 // Utils: read files under specified directories
 export const getDirectories = (
   src: string,
   callback: (err: Error, res: string[]) => void
 ) => {
-  glob(src + "/**/*", callback);
+  glob(src + '/**/*', callback);
 };
 
 // sync: read files under specified directories
@@ -15,7 +15,7 @@ export const getDirectoriesSync = (
   callback: (err: Error, res: string[]) => void
 ) => {
   try {
-    const results = glob.sync(src + "/**/*");
+    const results = glob.sync(src + '/**/*');
     callback(undefined, results);
   } catch (error) {
     callback(error, []);
@@ -28,12 +28,12 @@ export const generateCfgs = (
   isSrcPlugin: boolean = true
 ) => {
   dirRes.forEach((item: string) => {
-    if (item.endsWith("/config.json")) {
+    if (item.endsWith('/config.json')) {
       const fileData = fs.readFileSync(item);
       const jsonData = JSON.parse(fileData.toString());
       const apiPath = jsonData?.server?.api;
-      const dirName = item.split("/config.json").shift().split("/").pop();
-      const dir = item.split("/config.json").shift();
+      const dirName = item.split('/config.json').shift().split('/').pop();
+      const dir = item.split('/config.json').shift();
       const cfg = {
         path: item,
         dir,
@@ -48,3 +48,8 @@ export const generateCfgs = (
     }
   });
 };
+
+export * from './Const';
+export * from './Error';
+export * from './Helper';
+export * from './Network';