Skip to content

Commit 22264f8

Browse files
committed
some changes
1 parent 12a66eb commit 22264f8

File tree

1 file changed

+67
-41
lines changed

1 file changed

+67
-41
lines changed

env.d.ts

Lines changed: 67 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ interface PlayerLowsec {}
2828
interface PlayerNullsec {}
2929

3030
type UpgradeRarityString = "`0noob`" | "`1kiddie`" | "`2h4x0r`" | "`3h4rdc0r3`" | "`4|_|b3|2`" | "`531337`"
31-
type UpgradeRarityNumber = 0 | 1 | 2 | 3 | 4 | 5;
32-
type UpgradeRarity = UpgradeRarityString | UpgradeRarityNumber;
31+
type UpgradeRarityNumber = 0 | 1 | 2 | 3 | 4 | 5
32+
type UpgradeRarity = UpgradeRarityString | UpgradeRarityNumber
3333

3434
type UpgradeBase = {
3535
name: string
@@ -45,10 +45,8 @@ type UpgradeBase = {
4545

4646
type Upgrade = UpgradeBase & Record<string, null | boolean | number | string>
4747

48-
type CliUpgrade = Omit<UpgradeBase, `rarity`> & {
49-
[x: string]: null | boolean | number | string
50-
rarity: UpgradeRarityString
51-
}
48+
type CliUpgrade = Omit<UpgradeBase, `rarity`> &
49+
{ [k: string]: null | boolean | number | string, rarity: UpgradeRarityString }
5250

5351
type UsersTopItem<R> = { rank: R, name: string, last_activity: string, balance: string }
5452
type CorpsTopItem<R> = { rank: R, name: string, worth: string }
@@ -126,21 +124,11 @@ type Fullsec = Subscripts & PlayerFullsec & {
126124
}
127125

128126
escrow: {
129-
/** **FULLSEC** */ charge: (args: {
130-
cost: number | string
131-
is_unlim?: boolean
132-
}) => null | ScriptFailure
133-
127+
/** **FULLSEC** */ charge: (args: { cost: number | string, is_unlim?: boolean }) => null | ScriptFailure
134128
confirm: never
135129
}
136130

137-
gui: {
138-
chats: never
139-
quiet: never
140-
size: never
141-
vfx: never
142-
vol: never
143-
}
131+
gui: { chats: never, quiet: never, size: never, vfx: never, vol: never }
144132

145133
market: {
146134
/** **FULLSEC** */ browse: {
@@ -459,7 +447,10 @@ type Highsec = Fullsec & PlayerHighsec & {
459447
/** **HIGHSEC**
460448
* @returns GC balance as number if `is_script` is true (default).
461449
* @returns GC balance as string if `is_script` is false. */
462-
balance: ((args?: { is_script?: true }) => number) & ((args: { is_script: false }) => string)
450+
balance: {
451+
(args?: { is_script?: true }): number
452+
(args: { is_script: false }): string
453+
}
463454

464455
/** **HIGHSEC**
465456
* @returns Transaction history according to filter.
@@ -716,14 +707,51 @@ type Nullsec = Lowsec & PlayerNullsec & {
716707
}
717708
}
718709

719-
type MongoTypeString = "minKey" | "double" | "string" | "object" | "array" | "binData" | "undefined" | "objectId" |
720-
"bool" | "date" | "null" | "regex" | "dbPointer" | "javascript" | "symbol" | "int" | "timestamp" | "long" |
721-
"decimal" | "maxKey"
722-
723-
type MongoTypeNumber = -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 127
710+
// database
724711
type MongoPrimitive = null | boolean | number | Date | string
725712
type MongoValue = MongoPrimitive | MongoValue[] | MongoObject
726713
type MongoObject = { [k: string]: MongoValue }
714+
715+
type MongoTypeStringsToTypes = {
716+
minKey: unknown
717+
double: unknown
718+
string: string
719+
object: MongoObject
720+
array: MongoValue[]
721+
binData: unknown
722+
undefined: unknown
723+
objectId: unknown
724+
bool: boolean
725+
date: Date
726+
null: null
727+
regex: unknown
728+
dbPointer: unknown
729+
javascript: unknown
730+
symbol: unknown
731+
int: unknown
732+
timestamp: unknown
733+
long: unknown
734+
decimal: unknown
735+
maxKey: unknown
736+
}
737+
738+
type MongoTypeString = keyof MongoTypeStringsToTypes
739+
type MongoTypeNumber = -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 127
740+
type MongoId = Exclude<MongoPrimitive, null> | MongoObject
741+
type MongoDocument = MongoObject & { _id?: MongoId }
742+
type MongoQuery = MongoObject & Record<string, { $type: MongoTypeString }>
743+
744+
type MongoQueryType<TQuery extends MongoQuery> = {
745+
[K in keyof TQuery]:
746+
TQuery[K] extends infer V
747+
? V extends MongoPrimitive ? V
748+
: V extends { $type: infer InferredTypeString } ? MongoTypeStringsToTypes[InferredTypeString]
749+
: V extends { [`$${string}`]: any } ? never
750+
: V extends MongoObject ? MongoQueryType<V>
751+
: never
752+
: never
753+
}
754+
727755
type MongoCommandValue = MongoPrimitive | MongoCommandValue[] | { [k: string]: MongoCommandValue }
728756
type MongoArraySelectors<T extends MongoValue[] = MongoValue[]> = { $all: T, $elemMatch: T, $size: number }
729757

@@ -785,39 +813,37 @@ type MongoUpdateArrayOperatorModifiers<T> = MongoUpdateArrayOperatorUniversalMod
785813

786814
type MongoUpdateCommand<Schema extends MongoObject> = MongoUpdateOperators<Schema>
787815

788-
type MongoId = Exclude<MongoPrimitive, null> | MongoObject
789-
type MongoDocument<T extends MongoObject> = T & { _id?: MongoId }
790816
type SortOrder = { [key: string]: 1 | -1 | SortOrder }
791817

792-
type Cursor<T extends MongoObject> = {
793-
/** Returns the first document that satisfies the query. */ first: () => MongoDocument<T> | null
794-
/** Returns an array of documents that satisfy the query. */ array: () => MongoDocument<T>[]
818+
type Cursor<TDocument extends MongoDocument> = {
819+
/** Returns the first document that satisfies the query. */ first: () => TDocument | null
820+
/** Returns an array of documents that satisfy the query. */ array: () => TDocument[]
795821
/** Returns the number of documents that match the query. */ count: () => number
796822

797823
/** Returns the first document that satisfies the query. Also makes cursor unusable. */
798-
first_and_close: () => MongoDocument<T>
824+
first_and_close: () => TDocument
799825

800826
/** Returns an array of documents that satisfy the query. Also makes cursor unusable. */
801-
array_and_close: () => MongoDocument<T>[]
827+
array_and_close: () => TDocument[]
802828

803829
/** Returns the number of documents that match the query. Also makes cursor unusable. */
804830
count_and_close: () => number
805831

806832
/** Run `callback` on each document that satisfied the query. */
807-
each: (callback: (document: MongoDocument<T>) => void) => null
833+
each: (callback: (document: TDocument) => void) => null
808834

809835
/** Returns a new cursor with documents sorted as specified.
810836
* A value of 1 sorts the property ascending, and -1 descending.
811837
* @param order The way the documents are to be sorted. */
812-
sort: (order?: SortOrder) => Cursor<T>
838+
sort: (order?: SortOrder) => Cursor<TDocument>
813839

814840
/** Returns a new cursor without the first number of documents.
815841
* @param count Number of documents to skip. */
816-
skip: (count: number) => Cursor<T>
842+
skip: (count: number) => Cursor<TDocument>
817843

818844
/** Returns a new cursor limited to a number of documents as specified.
819845
* @param count Number of documents. */
820-
limit: (count: number) => Cursor<T>
846+
limit: (count: number) => Cursor<TDocument>
821847

822848
/** @param key The key of the documents. */ distinct: { (key: string): MongoValue[], (key: "_id"): MongoId[] }
823849
/** Make cursor unusable. */ close: () => null
@@ -896,30 +922,30 @@ type ObjectId = { $oid: string }
896922
declare const $db: {
897923
/** Insert a document or documents into a collection.
898924
* @param documents A document or array of documents to insert into the collection. */
899-
i: <T extends MongoObject>(documents: (T & { _id?: MongoId }) | (T & { _id?: MongoId })[]) =>
925+
i: <T extends MongoDocument>(documents: (T & { _id?: MongoId }) | (T & { _id?: MongoId })[]) =>
900926
{ n: number, opTime: { t: number }, ok: 0 | 1 }[]
901927

902928
/** Remove documents from a collection.
903929
* @param query Specifies deletion criteria using query operators. */
904-
r: <T extends MongoObject>(query: Query<T>) => { n: number, opTime: { t: number }, ok: 0 | 1 }[]
930+
r: <T extends MongoDocument>(query: Query<T>) => { n: number, opTime: { t: number }, ok: 0 | 1 }[]
905931

906932
/** Find documents in a collection or view and returns a cursor to the selected documents.
907933
* @param query Specifies deletion criteria using query operators.
908934
* @param projection Specifies the fields to return in the documents that match the query filter. */
909-
f: <T extends MongoObject>(query?: Query<T>, projection?: Projection<T>) => Cursor<T>
935+
f: <T extends MongoDocument>(query?: Query<T>, projection?: Projection<T>) => Cursor<T>
910936

911937
/** Update existing documents in a collection.
912938
* @param query Specifies deletion criteria using query operators.
913939
* @param command The modifications to apply.
914940
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
915-
u: <T extends MongoObject>(query: Query<T> | Query<T>[], command: MongoUpdateCommand<MongoDocument<T>>) =>
941+
u: <T extends MongoDocument>(query: Query<T> | Query<T>[], command: MongoUpdateCommand<T>) =>
916942
{ n: number, opTime: { t: number }, ok: 0 | 1, nModified: number }[]
917943

918944
/** Updates one document within the collection based on the filter.
919945
* @param query Specifies deletion criteria using query operators.
920946
* @param command The modifications to apply.
921947
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
922-
u1: <T extends MongoObject>(query: Query<T> | Query<T>[], command: MongoUpdateCommand<MongoDocument<T>>) =>
948+
u1: <T extends MongoDocument>(query: Query<T> | Query<T>[], command: MongoUpdateCommand<T>) =>
923949
{ n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
924950

925951
/** Update or insert document.
@@ -929,7 +955,7 @@ declare const $db: {
929955
* @param query Specifies deletion criteria using query operators.
930956
* @param command The modifications to apply.
931957
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
932-
us: <T extends MongoObject>(query: Query<T> | Query<T>[], command: MongoUpdateCommand<MongoDocument<T>>) =>
958+
us: <T extends MongoDocument>(query: Query<T> | Query<T>[], command: MongoUpdateCommand<T>) =>
933959
{ n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
934960

935961
ObjectId: () => ObjectId

0 commit comments

Comments
 (0)