Skip to content

Commit

Permalink
refactor: 在 storage 中将 types.d.ts 改为 types.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
LokiSharp committed Nov 5, 2023
1 parent b9b40d3 commit 0d8b48e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions storage/src/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Common } from "@neo-screeps/common";
import fs from "fs";
import _ from "lodash";
import Loki, { Collection } from "lokijs";
import { BulkData, CallBack, Data, FindOps, Method } from "@/types";

const common = new Common();
const config = common.configManager.config;
Expand Down
1 change: 1 addition & 0 deletions storage/src/PubSub.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import EventEmitter from "events";
import { CallBack } from "@/types";

export class PubSub {
private subs: [
Expand Down
1 change: 1 addition & 0 deletions storage/src/Queue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import EventEmitter from "events";
import { PubSub } from "@/PubSub";
import _ from "lodash";
import { CallBack, QueueName } from "@/types";

class QueueObj {
public pending: string[] = [];
Expand Down
26 changes: 15 additions & 11 deletions storage/src/types.d.ts → storage/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
type Data = {
import EventEmitter from "events";

export type Data = {
[propName: string]: DataType;
} & {
[op in keyof LokiOps]?: DataType;
} & {
$set?: { [key: string]: DataType };
$merge?: { [key: string]: DataType };
$inc?: { [key: string]: DataType };
Expand All @@ -9,33 +15,31 @@ type Data = {
$or?: [DataType, DataType];
$not?: [DataType, DataType];
_id?: string;
[op: keyof LokiOps]: DataType;
[propName: string]: DataType;
};

type CallBack = (
export type CallBack = (
message: string | null,
obj?: string | boolean | number | object,
) => void;

type DataType = object | number | string | null | Data;
export type DataType = object | number | string | null | Data;

type Method = "insert" | "find" | "findOne" | "count" | "removeWhere";
export type Method = "insert" | "find" | "findOne" | "count" | "removeWhere";

type BulkData = { op: BulkOp; id?: string; update?: Data; data?: Data };
export type BulkData = { op: BulkOp; id?: string; update?: Data; data?: Data };

type BulkOp = "update" | "insert" | "remove";
export type BulkOp = "update" | "insert" | "remove";

type FindOps = {
export type FindOps = {
sort?: { [data: string]: number };
offset?: number;
limit?: number;
};

type QueueObj = {
export type QueueObj = {
pending: [];
processing: [];
emitter: EventEmitter;
};

type QueueName = "usersLegacy" | "usersIvm" | "rooms";
export type QueueName = "usersLegacy" | "usersIvm" | "rooms";

0 comments on commit 0d8b48e

Please sign in to comment.