hackmud-script-manager 0.20.4-c524114 → 0.20.4-c85594c
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -0
- package/bin/hsm.js +285 -260
- package/env.d.ts +353 -282
- package/generateTypeDeclaration.js +2 -1
- package/index.js +2 -1
- package/package.json +38 -38
- package/processScript/index.js +3 -3
- package/processScript/minify.js +14 -19
- package/processScript/postprocess.d.ts +1 -1
- package/processScript/postprocess.js +3 -3
- package/processScript/preprocess.js +5 -3
- package/processScript/transform.js +102 -96
- package/push.d.ts +9 -1
- package/push.js +36 -14
- package/watch.js +12 -9
package/env.d.ts
CHANGED
@@ -1,20 +1,9 @@
|
|
1
|
-
type Replace<
|
2
|
-
type ScriptSuccess<T =
|
1
|
+
type Replace<A, B> = Omit<A, keyof B> & B
|
2
|
+
type ScriptSuccess<T = unknown> = { ok: true } & T
|
3
3
|
type ScriptFailure = { ok: false, msg?: string }
|
4
|
-
type ScriptResponse<T =
|
4
|
+
type ScriptResponse<T = unknown> = ScriptSuccess<T> | ScriptFailure
|
5
5
|
type ErrorScripts = Record<string, () => ScriptFailure>
|
6
6
|
|
7
|
-
type AllOptional<T> = {
|
8
|
-
[K in keyof T]-?: {} extends Pick<T, K> ? true : false
|
9
|
-
}[keyof T]
|
10
|
-
|
11
|
-
type Scriptor<Args = unknown, Ret = unknown> = {
|
12
|
-
name: string,
|
13
|
-
call: AllOptional<Args> extends true
|
14
|
-
? (args?: Args) => Ret
|
15
|
-
: (args: Args) => Ret
|
16
|
-
}
|
17
|
-
|
18
7
|
type Subscripts = Record<string, Record<string, (...args: any) => any>> & {
|
19
8
|
accts: ErrorScripts
|
20
9
|
autos: ErrorScripts
|
@@ -38,10 +27,9 @@ interface PlayerLowsec {}
|
|
38
27
|
interface PlayerNullsec {}
|
39
28
|
|
40
29
|
type UpgradeRarityString = "`0noob`" | "`1kiddie`" | "`2h4x0r`" | "`3h4rdc0r3`" | "`4|_|b3|2`" | "`531337`"
|
41
|
-
type UpgradeRarityNumber = 0 | 1 | 2 | 3 | 4 | 5
|
42
|
-
type UpgradeRarity = UpgradeRarityString | UpgradeRarityNumber;
|
30
|
+
type UpgradeRarityNumber = 0 | 1 | 2 | 3 | 4 | 5
|
43
31
|
|
44
|
-
type
|
32
|
+
type UpgradeBase = {
|
45
33
|
name: string
|
46
34
|
type: "lock" | "script_space" | "chat" | "script" | "tool" | "bot_brain" | "glam"
|
47
35
|
up_class?: -1 | 0 | 1 | 2 | 3
|
@@ -53,12 +41,10 @@ type UpgradeCore = {
|
|
53
41
|
description: string
|
54
42
|
}
|
55
43
|
|
56
|
-
type Upgrade =
|
44
|
+
type Upgrade = UpgradeBase & Record<string, null | boolean | number | string>
|
57
45
|
|
58
|
-
type
|
59
|
-
[
|
60
|
-
rarity: UpgradeRarityString
|
61
|
-
}
|
46
|
+
type CliUpgrade = Omit<UpgradeBase, `rarity`> &
|
47
|
+
{ [k: string]: null | boolean | number | string, rarity: UpgradeRarityString }
|
62
48
|
|
63
49
|
type UsersTopItem<R> = { rank: R, name: string, last_activity: string, balance: string }
|
64
50
|
type CorpsTopItem<R> = { rank: R, name: string, worth: string }
|
@@ -136,26 +122,25 @@ type Fullsec = Subscripts & PlayerFullsec & {
|
|
136
122
|
}
|
137
123
|
|
138
124
|
escrow: {
|
139
|
-
/** **FULLSEC** */ charge: (args: {
|
140
|
-
cost: number | string
|
141
|
-
is_unlim?: boolean
|
142
|
-
}) => null | ScriptFailure
|
143
|
-
|
125
|
+
/** **FULLSEC** */ charge: (args: { cost: number | string, is_unlim?: boolean }) => null | ScriptFailure
|
144
126
|
confirm: never
|
145
127
|
}
|
146
128
|
|
147
|
-
gui: {
|
148
|
-
chats: never
|
149
|
-
quiet: never
|
150
|
-
size: never
|
151
|
-
vfx: never
|
152
|
-
vol: never
|
153
|
-
}
|
129
|
+
gui: { chats: never, quiet: never, size: never, vfx: never, vol: never }
|
154
130
|
|
155
131
|
market: {
|
156
132
|
/** **FULLSEC** */ browse: {
|
157
133
|
(args:
|
158
|
-
Partial<{
|
134
|
+
Partial<{
|
135
|
+
seller: string | MongoQuerySelector<string>,
|
136
|
+
listed_before: number | MongoQuerySelector<number>,
|
137
|
+
listed_after: number,
|
138
|
+
cost: number | MongoQuerySelector<number> | string,
|
139
|
+
rarity: UpgradeRarityNumber | MongoQuerySelector<UpgradeRarityNumber>,
|
140
|
+
name: string | MongoQuerySelector<string>
|
141
|
+
} & Omit<{
|
142
|
+
[k in keyof CliUpgrade]: CliUpgrade[k] | MongoQuerySelector<CliUpgrade[k]>
|
143
|
+
}, "rarity">>
|
159
144
|
): { i: string, name: string, rarity: Upgrade["rarity"], cost: number }[] | ScriptFailure
|
160
145
|
|
161
146
|
<I extends string>(args: { i: I }): {
|
@@ -357,7 +342,7 @@ type Fullsec = Subscripts & PlayerFullsec & {
|
|
357
342
|
* const arr = [ 1, 2, 2, 3, 2 ]
|
358
343
|
*
|
359
344
|
* $D(uniq(arr)) // [ 1, 2, 3, 2 ] */
|
360
|
-
uniq: (array: T[]) => T[]
|
345
|
+
uniq: <T>(array: T[]) => T[]
|
361
346
|
|
362
347
|
/** Sorts an array of numbers or number-coercible strings in descending order. */
|
363
348
|
u_sort_num_arr_desc: <T>(array: T[]) => T[]
|
@@ -424,17 +409,17 @@ type Fullsec = Subscripts & PlayerFullsec & {
|
|
424
409
|
upgrades_of_owner: {
|
425
410
|
<F extends Partial<Upgrade & { loaded: boolean }> = object>(args?: { filter?: F, full?: false }): (
|
426
411
|
Omit<
|
427
|
-
Pick<
|
412
|
+
Pick<UpgradeBase, "tier" | "rarity" | "name" | "type" | "i" | "loaded">,
|
428
413
|
keyof F
|
429
414
|
> & Pick<F, "tier" | "rarity" | "name" | "type" | "i" | "loaded">
|
430
415
|
)[] | ScriptFailure
|
431
416
|
|
432
417
|
<F extends Partial<Upgrade & { loaded: boolean }> = object>(args: { filter?: F, full: true }): (
|
433
|
-
Omit<
|
418
|
+
Omit<UpgradeBase, keyof F> & F & Record<string, null | boolean | number | string>
|
434
419
|
)[] | ScriptFailure
|
435
420
|
|
436
421
|
<I extends number>(args: { i: I }): (
|
437
|
-
Omit<
|
422
|
+
Omit<UpgradeBase, "i"> & { [x: string]: null | boolean | number | string, i: I }
|
438
423
|
) | ScriptFailure
|
439
424
|
}
|
440
425
|
|
@@ -460,7 +445,10 @@ type Highsec = Fullsec & PlayerHighsec & {
|
|
460
445
|
/** **HIGHSEC**
|
461
446
|
* @returns GC balance as number if `is_script` is true (default).
|
462
447
|
* @returns GC balance as string if `is_script` is false. */
|
463
|
-
balance:
|
448
|
+
balance: {
|
449
|
+
(args?: { is_script?: true }): number
|
450
|
+
(args: { is_script: false }): string
|
451
|
+
}
|
464
452
|
|
465
453
|
/** **HIGHSEC**
|
466
454
|
* @returns Transaction history according to filter.
|
@@ -511,7 +499,7 @@ type Highsec = Fullsec & PlayerHighsec & {
|
|
511
499
|
/** **HIGHSEC** */
|
512
500
|
upgrades: {
|
513
501
|
<I extends number>(args: { i: I }): (
|
514
|
-
Omit<
|
502
|
+
Omit<UpgradeBase, "i"> & { [x: string]: null | boolean | number | string, i: I }
|
515
503
|
) | ScriptFailure
|
516
504
|
|
517
505
|
<F extends Partial<Upgrade & { loaded: boolean }> = object>(args?: {
|
@@ -519,20 +507,20 @@ type Highsec = Fullsec & PlayerHighsec & {
|
|
519
507
|
is_script?: true
|
520
508
|
full?: false
|
521
509
|
}): (
|
522
|
-
Omit<Pick<
|
510
|
+
Omit<Pick<UpgradeBase, "tier" | "rarity" | "name" | "type" | "i" | "loaded">, keyof F> & F &
|
523
511
|
Record<string, null | boolean | number | string>
|
524
512
|
)[] | ScriptFailure
|
525
513
|
|
526
514
|
<F extends Partial<Upgrade & { loaded: boolean }> = object>(args?:
|
527
515
|
{ filter?: F, is_script?: true, full: true }
|
528
|
-
): (Omit<
|
516
|
+
): (Omit<UpgradeBase, keyof F> & F & Record<string, null | boolean | number | string>)[] | ScriptFailure
|
529
517
|
|
530
518
|
(args?: { filter?: Partial<Upgrade & { loaded: boolean }>, is_script: false, full?: false }):
|
531
519
|
{ msg: string, upgrades: string[] } | ScriptFailure
|
532
520
|
|
533
521
|
<F extends Partial<Upgrade & { loaded: boolean }> = object>(
|
534
522
|
args?: { filter?: F, is_script: false, full: true }
|
535
|
-
): (Omit<
|
523
|
+
): (Omit<UpgradeBase, keyof F | `rarity`> & F & {
|
536
524
|
[x: string]: null | boolean | number | string
|
537
525
|
rarity: UpgradeRarityString
|
538
526
|
})[] | ScriptFailure
|
@@ -630,6 +618,9 @@ type Lowsec = Midsec & PlayerLowsec & {
|
|
630
618
|
(args: { i: number | number[], to: string, memo?: string }): ScriptResponse
|
631
619
|
(args: { sn: string | string[], to: string, memo?: string }): ScriptResponse
|
632
620
|
}
|
621
|
+
/** **LOWSEC** */ expose_access_log: (args: { target: string }) => ScriptResponse
|
622
|
+
/** **LOWSEC** */ xfer_gc_from: (args: { target: string, amount: number | string }) => ScriptResponse
|
623
|
+
/** **LOWSEC** */ expose_balance: (args: { target: string }) => ScriptResponse
|
633
624
|
}
|
634
625
|
}
|
635
626
|
|
@@ -714,294 +705,374 @@ type Nullsec = Lowsec & PlayerNullsec & {
|
|
714
705
|
}
|
715
706
|
}
|
716
707
|
|
717
|
-
|
708
|
+
// database
|
709
|
+
type MongoPrimitive = null | boolean | number | Date | string
|
710
|
+
type MongoValue = MongoPrimitive | MongoValue[] | MongoObject
|
711
|
+
type MongoObject = { [k: string]: MongoValue, [k: `$${string}`]: never }
|
712
|
+
type MongoQueryValue = MongoPrimitive | MongoQueryValue[] | MongoQueryObject
|
713
|
+
|
714
|
+
type MongoQueryObject =
|
715
|
+
{ [k: string]: MongoQueryValue, [k: `$${string}`]: MongoValue, $type?: keyof MongoTypeStringsToTypes | (string & {}) }
|
716
|
+
|
717
|
+
type MongoTypeStringsToTypes = {
|
718
|
+
double: number
|
719
|
+
string: string
|
720
|
+
object: MongoObject
|
721
|
+
array: MongoValue[]
|
722
|
+
objectId: ObjectId
|
723
|
+
bool: boolean
|
724
|
+
date: Date
|
725
|
+
null: null
|
726
|
+
int: number
|
727
|
+
long: number
|
728
|
+
}
|
729
|
+
|
730
|
+
type MongoTypeString = keyof MongoTypeStringsToTypes
|
731
|
+
type MongoTypeNumber = -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 127
|
732
|
+
type MongoId = Exclude<MongoPrimitive, null> | MongoObject
|
733
|
+
type MongoQueryId = Exclude<MongoPrimitive, null> | MongoQueryObject
|
734
|
+
type MongoDocument = MongoObject & { _id?: MongoId }
|
735
|
+
|
736
|
+
type MongoQueryType<TQuery extends MongoQueryObject> = {
|
737
|
+
-readonly [K in keyof TQuery]:
|
738
|
+
TQuery[K] extends MongoPrimitive ?
|
739
|
+
TQuery[K]
|
740
|
+
: TQuery[K] extends { $type: infer TType } ?
|
741
|
+
TType extends keyof MongoTypeStringsToTypes ? MongoTypeStringsToTypes[TType] : unknown
|
742
|
+
: TQuery[K] extends { $in: (infer TIn)[] } ?
|
743
|
+
TIn
|
744
|
+
: keyof TQuery[K] extends `$${string}` ?
|
745
|
+
unknown
|
746
|
+
: TQuery[K] extends { [k: string]: any } ?
|
747
|
+
MongoQueryType<TQuery[K]>
|
748
|
+
: never
|
749
|
+
}
|
718
750
|
|
719
|
-
type MongoCommandValue =
|
720
|
-
|
751
|
+
type MongoCommandValue = MongoPrimitive | MongoCommandValue[] | { [k: string]: MongoCommandValue }
|
752
|
+
type MongoArraySelectors<T extends MongoValue[] = MongoValue[]> = { $all: T, $elemMatch: T, $size: number }
|
721
753
|
|
722
|
-
type
|
723
|
-
|
754
|
+
type MongoComparisonSelectors<T extends MongoValue = MongoValue> =
|
755
|
+
{ $eq: T, $gt: T, $gte: T, $in: T[], $lt: T, $lte: T, $ne: T, $nin: T[] }
|
724
756
|
|
725
|
-
type
|
726
|
-
|
757
|
+
type MongoElementSelectors = { $exists: boolean, $type: MongoTypeNumber | MongoTypeString }
|
758
|
+
|
759
|
+
type MongoQuerySelector<T extends MongoValue> = Partial<
|
760
|
+
T extends []
|
761
|
+
? MongoArraySelectors<T> & MongoElementSelectors & MongoComparisonSelectors<T>
|
762
|
+
: MongoElementSelectors & MongoComparisonSelectors<T>
|
727
763
|
>
|
728
764
|
|
729
|
-
type
|
730
|
-
|
765
|
+
type MongoQuery<T extends MongoObject> = { [K in keyof T]?: T[K] | MongoQuerySelector<T[K]> } & { _id?: MongoId }
|
766
|
+
|
767
|
+
type MongoUpdateOperators<T extends MongoObject> = Partial<{
|
768
|
+
/* Universal operators */
|
769
|
+
$set: Partial<Record<string, MongoCommandValue> & T>
|
770
|
+
$setOnInsert: Partial<Record<string, MongoCommandValue> & T>
|
771
|
+
$unset: Partial<Record<string, ""> & T>
|
772
|
+
|
773
|
+
$rename: Partial<Record<string, string> & { [key in keyof T]: string }>
|
774
|
+
|
775
|
+
/* Date & number operators */
|
776
|
+
$inc: Record<string, number> &
|
777
|
+
{ [K in keyof T as T[K] extends number | Date ? K : never]?: T[K] extends number ? number : Date }
|
778
|
+
|
779
|
+
$mul: Record<string, number> & { [K in keyof T as T[K] extends number ? K : never]?: number }
|
780
|
+
$min: Record<string, number> & { [K in keyof T as T[K] extends number ? K : never]?: number }
|
781
|
+
$max: Record<string, number> & { [K in keyof T as T[K] extends number ? K : never]?: number }
|
782
|
+
|
783
|
+
/* Array operators */
|
784
|
+
$pop: Record<string, -1 | 1> & { [K in keyof T as T[K] extends [] ? K : never]?: -1 | 1 }
|
785
|
+
|
786
|
+
$push: Record<string, MongoCommandValue> & {
|
787
|
+
[K in keyof T as T[K] extends [] ? K : never]?: (T[K] extends (infer U)[] ? U : never)
|
788
|
+
| MongoUpdateArrayOperatorModifiers<T[K]>
|
789
|
+
}
|
790
|
+
|
791
|
+
$addToSet: Partial<Record<string, MongoCommandValue> & {
|
792
|
+
[K in keyof T as T[K] extends [] ? K : never]: (T[K] extends (infer U)[] ? U : never)
|
793
|
+
| MongoUpdateArrayOperatorUniversalModifiers<T[K]>
|
794
|
+
}>
|
795
|
+
|
796
|
+
$pull: Partial<Record<string, MongoCommandValue> & {
|
797
|
+
[K in keyof T as T[K] extends [] ? K : never]: (T[K] extends (infer U)[] ? U : never)
|
798
|
+
| MongoQuerySelector<T[K]>
|
799
|
+
}>
|
800
|
+
|
801
|
+
$pullAll: Record<string, MongoCommandValue> & { [K in keyof T as T[K] extends [] ? K : never]?: T[K] }
|
802
|
+
}>
|
803
|
+
|
804
|
+
type MongoUpdateArrayOperatorUniversalModifiers<T> = { $each?: T extends [] ? T : T[] }
|
805
|
+
|
806
|
+
type MongoUpdateArrayOperatorModifiers<T> = MongoUpdateArrayOperatorUniversalModifiers<T> &
|
807
|
+
{ $position?: number, $slice?: number, $sort?: 1 | -1 }
|
808
|
+
|
809
|
+
type MongoUpdateCommand<Schema extends MongoObject> = MongoUpdateOperators<Schema>
|
810
|
+
|
731
811
|
type SortOrder = { [key: string]: 1 | -1 | SortOrder }
|
732
812
|
|
733
|
-
type Cursor = {
|
734
|
-
/** Returns the first document that satisfies the query. */ first: () =>
|
735
|
-
/** Returns an array of documents that satisfy the query. */ array: () =>
|
813
|
+
type Cursor<T> = {
|
814
|
+
/** Returns the first document that satisfies the query. */ first: () => T | null
|
815
|
+
/** Returns an array of documents that satisfy the query. */ array: () => T[]
|
736
816
|
/** Returns the number of documents that match the query. */ count: () => number
|
737
817
|
|
738
818
|
/** Returns the first document that satisfies the query. Also makes cursor unusable. */
|
739
|
-
first_and_close: () =>
|
819
|
+
first_and_close: () => T
|
740
820
|
|
741
821
|
/** Returns an array of documents that satisfy the query. Also makes cursor unusable. */
|
742
|
-
array_and_close: () =>
|
822
|
+
array_and_close: () => T[]
|
743
823
|
|
744
824
|
/** Returns the number of documents that match the query. Also makes cursor unusable. */
|
745
825
|
count_and_close: () => number
|
746
826
|
|
747
827
|
/** Run `callback` on each document that satisfied the query. */
|
748
|
-
each: (callback: (document:
|
828
|
+
each: (callback: (document: T) => void) => null
|
749
829
|
|
750
830
|
/** Returns a new cursor with documents sorted as specified.
|
751
831
|
* A value of 1 sorts the property ascending, and -1 descending.
|
752
832
|
* @param order The way the documents are to be sorted. */
|
753
|
-
sort: (order?: SortOrder) => Cursor
|
833
|
+
sort: (order?: SortOrder) => Cursor<T>
|
754
834
|
|
755
835
|
/** Returns a new cursor without the first number of documents.
|
756
836
|
* @param count Number of documents to skip. */
|
757
|
-
skip: (count: number) => Cursor
|
837
|
+
skip: (count: number) => Cursor<T>
|
758
838
|
|
759
839
|
/** Returns a new cursor limited to a number of documents as specified.
|
760
840
|
* @param count Number of documents. */
|
761
|
-
limit: (count: number) => Cursor
|
841
|
+
limit: (count: number) => Cursor<T>
|
762
842
|
|
763
|
-
/** @param key The key of the documents. */ distinct: (
|
843
|
+
/** @param key The key of the documents. */ distinct: { (key: string): MongoValue[], (key: "_id"): MongoId[] }
|
764
844
|
/** Make cursor unusable. */ close: () => null
|
765
845
|
NumberLong: (number: number) => number
|
846
|
+
// TODO what actually is the type here?
|
766
847
|
ObjectId: () => any
|
767
848
|
}
|
768
849
|
|
769
|
-
type
|
850
|
+
type CliContext = {
|
770
851
|
/** The name of the user who is calling the script. */ caller: string
|
771
852
|
/** The name of this script. */ this_script: string
|
772
853
|
/** The number of columns in the caller’s terminal. */ cols: number
|
773
854
|
/** The number of rows in the caller’s terminal. */ rows: number
|
774
855
|
|
775
856
|
/** The name of the script that directly called this script, or null if called on the command line or as a
|
776
|
-
* scriptor. */
|
857
|
+
* scriptor. */
|
858
|
+
calling_script: null
|
859
|
+
|
860
|
+
is_scriptor?: undefined
|
861
|
+
is_brain?: undefined
|
777
862
|
}
|
778
863
|
|
779
|
-
type SubscriptContext = Replace<
|
864
|
+
type SubscriptContext = Replace<CliContext, {
|
780
865
|
/** The name of the script that directly called this script, or null if called on the command line or as a scriptor.
|
781
866
|
*/
|
782
867
|
calling_script: string
|
783
868
|
}>
|
784
869
|
|
785
|
-
type ScriptorContext =
|
786
|
-
type BrainContext =
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
/** Subscript space that can call FULLSEC scripts. */ declare const $4s: typeof $fs
|
806
|
-
|
807
|
-
/** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
|
808
|
-
declare const $3s: typeof $hs
|
809
|
-
|
810
|
-
/** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
|
811
|
-
*/
|
812
|
-
declare const $2s: typeof $ms
|
813
|
-
|
814
|
-
/** Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
|
815
|
-
*/
|
816
|
-
declare const $1s: typeof $ls
|
817
|
-
|
818
|
-
/** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
|
819
|
-
declare const $0s: typeof $ns
|
820
|
-
|
821
|
-
/** Subscript space that can call any script. Uses seclevel provided in comment before script (defaults to NULLSEC)
|
822
|
-
* @example
|
823
|
-
* // @ seclevel MIDSEC
|
824
|
-
* // remove the space betwen "@" and "s", there's only a space because otherwise vscode breaks
|
825
|
-
* export function script() {
|
826
|
-
* $s.foo.bar() // will be converted to #ms.foo.bar()
|
827
|
-
* } */
|
828
|
-
declare const $s: Nullsec
|
829
|
-
|
830
|
-
declare const $db: {
|
831
|
-
/** Insert a document or documents into a collection.
|
832
|
-
* @param documents A document or array of documents to insert into the collection. */
|
833
|
-
i: (documents: object | object[]) => {
|
834
|
-
ok: 1
|
835
|
-
n: number
|
836
|
-
opTime: { ts: "Undefined Conversion", t: number }
|
837
|
-
electionId: "Undefined Conversion"
|
838
|
-
operationTime: "Undefined Conversion"
|
839
|
-
$clusterTime: {
|
840
|
-
clusterTime: "Undefined Conversion"
|
841
|
-
signature: { hash: "Undefined Conversion", keyId: "Undefined Conversion" }
|
842
|
-
}
|
843
|
-
}
|
870
|
+
type ScriptorContext = Replace<CliContext, { /** Whether the script is being run as a scriptor. */ is_scriptor: true }>
|
871
|
+
type BrainContext = Replace<CliContext, { /** Whether the script is being run via a bot brain. */ is_brain: true }>
|
872
|
+
|
873
|
+
// _id is always returned unless _id: false is passed
|
874
|
+
// when anyField: true is given, other fields (except _id) are omitted
|
875
|
+
|
876
|
+
type MongoProject<TDocument, TProjection> =
|
877
|
+
true extends (1 extends TProjection[keyof TProjection] ? true : TProjection[keyof TProjection]) ?
|
878
|
+
(TProjection extends { _id: false | 0 } ? {} : { _id: TDocument extends { _id: infer TId } ? TId : MongoId }) &
|
879
|
+
{
|
880
|
+
[K in
|
881
|
+
keyof TDocument as K extends keyof TProjection ? TProjection[K] extends true | 1 ? K : never : never
|
882
|
+
]: TDocument[K]
|
883
|
+
} &
|
884
|
+
{
|
885
|
+
-readonly [K in
|
886
|
+
keyof TProjection as TProjection[K] extends true | 1 ? K extends keyof TDocument ? never : K : never
|
887
|
+
]?: MongoValue
|
888
|
+
}
|
889
|
+
: { [k: string]: MongoValue } & { [K in keyof TDocument as K extends keyof TProjection ? never : K]: TDocument[K] }
|
844
890
|
|
845
|
-
|
846
|
-
* @param query Specifies deletion criteria using query operators. */
|
847
|
-
r: (query: Query) => {
|
848
|
-
ok: 0 | 1
|
849
|
-
n: number
|
850
|
-
opTime: { ts: "Undefined Conversion", t: number }
|
851
|
-
electionId: "Undefined Conversion"
|
852
|
-
operationTime: "Undefined Conversion"
|
853
|
-
$clusterTime: {
|
854
|
-
clusterTime: "Undefined Conversion"
|
855
|
-
signature: { hash: "Undefined Conversion", keyId: "Undefined Conversion" }
|
856
|
-
}
|
857
|
-
}
|
891
|
+
type DeepFreeze<T> = { readonly [P in keyof T]: DeepFreeze<T[P]> }
|
858
892
|
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
/** Update an existing documents in a collection.
|
865
|
-
* @param query Specifies deletion criteria using query operators.
|
866
|
-
* @param command The modifications to apply.
|
867
|
-
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
|
868
|
-
u: (query: Query | Query[], command: MongoCommand) => {
|
869
|
-
ok: 0 | 1
|
870
|
-
nModified: number
|
871
|
-
n: number
|
872
|
-
opTime: { ts: "Undefined Conversion", t: number }
|
873
|
-
electionId: "Undefined Conversion"
|
874
|
-
operationTime: "Undefined Conversion"
|
875
|
-
$clusterTime: {
|
876
|
-
clusterTime: "Undefined Conversion"
|
877
|
-
signature: { hash: "Undefined Conversion", keyId: "Undefined Conversion" }
|
878
|
-
}
|
879
|
-
}
|
893
|
+
declare global {
|
894
|
+
type Scriptor<TArgs extends any[] = any[]> = { name: string, call: (...args: TArgs) => unknown }
|
895
|
+
type Context = CliContext | SubscriptContext | ScriptorContext | BrainContext
|
896
|
+
type ObjectId = { $oid: string }
|
880
897
|
|
881
|
-
/**
|
882
|
-
* @param query Specifies deletion criteria using query operators.
|
883
|
-
* @param command The modifications to apply.
|
884
|
-
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
|
885
|
-
u1: (query: Query | Query[], command: MongoCommand) => {
|
886
|
-
ok: 0 | 1
|
887
|
-
nModified: number
|
888
|
-
n: number
|
889
|
-
opTime: {
|
890
|
-
ts: "Undefined Conversion"
|
891
|
-
t: number
|
892
|
-
}
|
893
|
-
electionId: "Undefined Conversion"
|
894
|
-
operationTime: "Undefined Conversion"
|
895
|
-
$clusterTime: {
|
896
|
-
clusterTime: "Undefined Conversion"
|
897
|
-
signature: {
|
898
|
-
hash: "Undefined Conversion"
|
899
|
-
keyId: "Undefined Conversion"
|
900
|
-
}
|
901
|
-
}
|
902
|
-
}
|
898
|
+
/** Subscript space that can call FULLSEC scripts. */ const $fs: Fullsec
|
903
899
|
|
904
|
-
/**
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
900
|
+
/** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
|
901
|
+
const $hs: Highsec
|
902
|
+
|
903
|
+
/** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
|
904
|
+
*/
|
905
|
+
const $ms: Midsec
|
906
|
+
|
907
|
+
/** Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
|
908
|
+
*/
|
909
|
+
const $ls: Lowsec
|
910
|
+
|
911
|
+
/** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
|
912
|
+
const $ns: Nullsec
|
913
|
+
|
914
|
+
/** Subscript space that can call FULLSEC scripts. */ const $4s: typeof $fs
|
915
|
+
|
916
|
+
/** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
|
917
|
+
const $3s: typeof $hs
|
918
|
+
|
919
|
+
/** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
|
920
|
+
*/
|
921
|
+
const $2s: typeof $ms
|
922
|
+
|
923
|
+
/** Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
|
924
|
+
*/
|
925
|
+
const $1s: typeof $ls
|
926
|
+
|
927
|
+
/** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
|
928
|
+
const $0s: typeof $ns
|
929
|
+
|
930
|
+
/** Subscript space that can call any script. Uses seclevel provided in comment before script (defaults to NULLSEC)
|
931
|
+
* @example
|
932
|
+
* // @seclevel MIDSEC
|
933
|
+
* // note, do NOT copy paste the above line because there is a zero-width space inserted between "@" and "s"
|
934
|
+
* export function script() {
|
935
|
+
* $s.foo.bar() // will be converted to #ms.foo.bar()
|
936
|
+
* } */
|
937
|
+
const $s: Nullsec
|
938
|
+
|
939
|
+
const $db: {
|
940
|
+
/** Insert a document or documents into a collection.
|
941
|
+
* @param documents A document or array of documents to insert into the collection. */
|
942
|
+
i: <T extends MongoDocument>(documents: (T & { _id?: MongoId }) | (T & { _id?: MongoId })[]) =>
|
943
|
+
{ n: number, opTime: { t: number }, ok: 0 | 1 }[]
|
944
|
+
|
945
|
+
/** Remove documents from a collection.
|
946
|
+
* @param query Specifies deletion criteria using query operators. */
|
947
|
+
r: <T extends MongoDocument>(query: MongoQuery<T>) => { n: number, opTime: { t: number }, ok: 0 | 1 }[]
|
948
|
+
|
949
|
+
/** Find documents in a collection or view and returns a cursor to the selected documents.
|
950
|
+
* @param query Specifies deletion criteria using query operators.
|
951
|
+
* @param projection Specifies the fields to return in the documents that match the query filter. */
|
952
|
+
f: <
|
953
|
+
const TQuery extends MongoQueryObject & { _id?: MongoQueryId },
|
954
|
+
const TProjection extends { [k: string]: boolean | 0 | 1 } = {}
|
955
|
+
>(query: TQuery, projection?: TProjection) => Cursor<MongoProject<MongoQueryType<TQuery>, TProjection>>
|
956
|
+
|
957
|
+
/** Update existing documents in a collection.
|
958
|
+
* @param query Specifies deletion criteria using query operators.
|
959
|
+
* @param command The modifications to apply.
|
960
|
+
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
|
961
|
+
u: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) =>
|
962
|
+
{ n: number, opTime: { t: number }, ok: 0 | 1, nModified: number }[]
|
963
|
+
|
964
|
+
/** Updates one document within the collection based on the filter.
|
965
|
+
* @param query Specifies deletion criteria using query operators.
|
966
|
+
* @param command The modifications to apply.
|
967
|
+
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
|
968
|
+
u1: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) =>
|
969
|
+
{ n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
|
970
|
+
|
971
|
+
/** Update or insert document.
|
972
|
+
* Same as Update, but if no documents match the query, one document will be inserted based on the properties in
|
973
|
+
* both the query and the command.
|
974
|
+
* The `$setOnInsert` operator is useful to set defaults.
|
975
|
+
* @param query Specifies deletion criteria using query operators.
|
976
|
+
* @param command The modifications to apply.
|
977
|
+
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
|
978
|
+
us: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) =>
|
979
|
+
{ n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
|
980
|
+
|
981
|
+
ObjectId: () => ObjectId
|
922
982
|
}
|
983
|
+
|
984
|
+
/** Debug Log.
|
985
|
+
*
|
986
|
+
* If `$D()` is called in a script you own, the `return` value of the top level script is suppressed and instead an
|
987
|
+
* array of every `$D()`’d entry is printed.
|
988
|
+
* This lets you use `$D()` like `console.log()`.
|
989
|
+
*
|
990
|
+
* `$D()` in scripts not owned by you are not shown but the `return` value always is.
|
991
|
+
*
|
992
|
+
* `$D()` returns the first argument so `$D("Hello, World!") evaluates to `"Hello, World!"` as if the `$D` text wasn't
|
993
|
+
* there.
|
994
|
+
*
|
995
|
+
* `$D()`’d items are returned even if the script times out or errors. */
|
996
|
+
function $D<T>(args: T): T
|
997
|
+
|
998
|
+
/** Function Multi-Call Lock.
|
999
|
+
*
|
1000
|
+
* This is used by escrow to ensure that it is only used once in script execution.
|
1001
|
+
*
|
1002
|
+
* The first time (per-script) `$FMCL` is encountered, it returns `undefined`, every other time it `return`s `true`.
|
1003
|
+
*
|
1004
|
+
* @example
|
1005
|
+
* if ($FMCL)
|
1006
|
+
* return { ok: false, msg: "This script can only be used once per script execution." }
|
1007
|
+
*
|
1008
|
+
* // all code here will only run once */
|
1009
|
+
const $FMCL: undefined | true
|
1010
|
+
|
1011
|
+
/** Per-script mutable "global" persistent object that is discarded at the end of top level script execution.
|
1012
|
+
*
|
1013
|
+
* `$G` persists between script calls until the end of the main script run making it useful for caching db entries when
|
1014
|
+
* your script is a subscript.
|
1015
|
+
* @example
|
1016
|
+
* if (!$G.dbCache)
|
1017
|
+
* $G.dbCache = $db.f({ whatever: true }).first() */
|
1018
|
+
const $G: Record<string | symbol, any>
|
1019
|
+
|
1020
|
+
/** This contains a JS timestamp (not Date) set immediately before your code begins running.
|
1021
|
+
* @example
|
1022
|
+
* $D(Date.now() - _START) // milliseconds left of run time
|
1023
|
+
*/
|
1024
|
+
const _START: number
|
1025
|
+
|
1026
|
+
/** This contains a JS timestamp (not Date) set immediately before your code begins running.
|
1027
|
+
* @example
|
1028
|
+
* $D(Date.now() - _ST) // milliseconds left of run time */
|
1029
|
+
const _ST: typeof _START
|
1030
|
+
|
1031
|
+
/** JavaScript timestamp for the end of the script run (`_START + _TIMEOUT`). */ const _END: number
|
1032
|
+
|
1033
|
+
/** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
|
1034
|
+
const _TIMEOUT: number
|
1035
|
+
|
1036
|
+
/** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
|
1037
|
+
const _TO: typeof _TIMEOUT
|
1038
|
+
|
1039
|
+
/** The source code of this script as a string. */ const _SOURCE: string
|
1040
|
+
/** A unix timestamp of the date this script was built. */ const _BUILD_DATE: number
|
1041
|
+
|
1042
|
+
/** The user this script has been uploaded to.
|
1043
|
+
*
|
1044
|
+
* Shorter alternative to `context.this_script.split(".")[0].
|
1045
|
+
*
|
1046
|
+
* In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
|
1047
|
+
const _SCRIPT_USER: string
|
1048
|
+
|
1049
|
+
/** The name of this script excluding the user and `.`.
|
1050
|
+
*
|
1051
|
+
* e.g. in the script `foo.bar`, `_SCRIPT_NAME` is `bar`.
|
1052
|
+
*
|
1053
|
+
* Shorter alternative to `context.this_script.split(".")[1].
|
1054
|
+
*
|
1055
|
+
* In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
|
1056
|
+
const _SCRIPT_NAME: string
|
1057
|
+
|
1058
|
+
/** The full name of this script equivilent to `context.this_script` but should use less characters.
|
1059
|
+
*
|
1060
|
+
* In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
|
1061
|
+
const _FULL_SCRIPT_NAME: string
|
1062
|
+
|
1063
|
+
/** The seclevel of this script as a number.
|
1064
|
+
*
|
1065
|
+
* In rare cases where it's not known at build time, it's `-1`. */
|
1066
|
+
const _SECLEVEL: -1 | 0 | 1 | 2 | 3 | 4
|
1067
|
+
|
1068
|
+
/** Recursively
|
1069
|
+
* [`Object.freeze()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
|
1070
|
+
* an object and its properties' objects and its properties' objects and so on.
|
1071
|
+
*
|
1072
|
+
* [Official Hackmud Wiki](https://wiki.hackmud.com/scripting/extensions/deep_freeze) */
|
1073
|
+
const DEEP_FREEZE: <T>(value: T) => DeepFreeze<T>
|
1074
|
+
|
1075
|
+
const _RUN_ID: string
|
923
1076
|
}
|
924
1077
|
|
925
|
-
|
926
|
-
*
|
927
|
-
* If `$D()` is called in a script you own, the `return` value of the top level script is suppressed and instead an
|
928
|
-
* array of every `$D()`’d entry is printed.
|
929
|
-
* This lets you use `$D()` like `console.log()`.
|
930
|
-
*
|
931
|
-
* `$D()` in scripts not owned by you are not shown but the `return` value always is.
|
932
|
-
*
|
933
|
-
* `$D()` returns the first argument so `$D("Hello, World!") evaluates to `"Hello, World!"` as if the `$D` text wasn't
|
934
|
-
* there.
|
935
|
-
*
|
936
|
-
* `$D()`’d items are returned even if the script times out or errors. */
|
937
|
-
declare function $D<T>(args: T): T
|
938
|
-
|
939
|
-
/** Function Multi-Call Lock.
|
940
|
-
*
|
941
|
-
* This is used by escrow to ensure that it is only used once in script execution.
|
942
|
-
*
|
943
|
-
* The first time (per-script) `$FMCL` is encountered, it returns `undefined`, every other time it `return`s `true`.
|
944
|
-
*
|
945
|
-
* @example
|
946
|
-
* if ($FMCL)
|
947
|
-
* return { ok: false, msg: "This script can only be used once per script execution." }
|
948
|
-
*
|
949
|
-
* // all code here will only run once */
|
950
|
-
declare const $FMCL: undefined | true
|
951
|
-
|
952
|
-
/** Per-script mutable "global" persistent object that is discarded at the end of top level script execution.
|
953
|
-
*
|
954
|
-
* `$G` persists between script calls until the end of the main script run making it useful for caching db entries when
|
955
|
-
* your script is a subscript.
|
956
|
-
* @example
|
957
|
-
* if (!$G.dbCache)
|
958
|
-
* $G.dbCache = $db.f({ whatever: true }).first() */
|
959
|
-
declare const $G: any
|
960
|
-
|
961
|
-
/** This contains a JS timestamp (not Date) set immediately before your code begins running.
|
962
|
-
* @example
|
963
|
-
* $D(Date.now() - _START) // milliseconds left of run time
|
964
|
-
*/
|
965
|
-
declare const _START: number
|
966
|
-
|
967
|
-
/** This contains a JS timestamp (not Date) set immediately before your code begins running.
|
968
|
-
* @example
|
969
|
-
* $D(Date.now() - _ST) // milliseconds left of run time */
|
970
|
-
declare const _ST: typeof _START
|
971
|
-
|
972
|
-
/** JavaScript timestamp for the end of the script run (`_START + _TIMEOUT`). */ declare const _END: number
|
973
|
-
|
974
|
-
/** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
|
975
|
-
declare const _TIMEOUT: number
|
976
|
-
|
977
|
-
/** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
|
978
|
-
declare const _TO: typeof _TIMEOUT
|
979
|
-
|
980
|
-
/** The source code of this script as a string. */ declare const _SOURCE: string
|
981
|
-
/** A unix timestamp of the date this script was built. */ declare const _BUILD_DATE: number
|
982
|
-
|
983
|
-
/** The user this script has been uploaded to.
|
984
|
-
*
|
985
|
-
* Shorter alternative to `context.this_script.split(".")[0].
|
986
|
-
*
|
987
|
-
* In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
|
988
|
-
declare const _SCRIPT_USER: string
|
989
|
-
|
990
|
-
/** The name of this script excluding the user and `.`.
|
991
|
-
*
|
992
|
-
* e.g. in the script `foo.bar`, `_SCRIPT_NAME` is `bar`.
|
993
|
-
*
|
994
|
-
* Shorter alternative to `context.this_script.split(".")[1].
|
995
|
-
*
|
996
|
-
* In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
|
997
|
-
declare const _SCRIPT_NAME: string
|
998
|
-
|
999
|
-
/** The full name of this script equivilent to `context.this_script` but should use less characters.
|
1000
|
-
*
|
1001
|
-
* In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
|
1002
|
-
declare const _FULL_SCRIPT_NAME: string
|
1003
|
-
|
1004
|
-
/** The seclevel of this script as a number.
|
1005
|
-
*
|
1006
|
-
* In rare cases where it's not known at build time, it's `-1`. */
|
1007
|
-
declare const _SECLEVEL: -1 | 0 | 1 | 2 | 3 | 4
|
1078
|
+
export {}
|