hackmud-script-manager 0.20.4-8b61cf2 → 0.20.4-9181c22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/env.d.ts CHANGED
@@ -1,16 +1,6 @@
1
- type Replace<A, B> = Omit<A, keyof B> & B
2
- type ScriptSuccess<T = object> = { ok: true } & T
3
- type ScriptFailure = { ok: false, msg?: string }
4
- type ScriptResponse<T = object> = ScriptSuccess<T> | ScriptFailure
1
+ type Replace<A, B> = Omit<A, keyof B> & BigInt
5
2
  type ErrorScripts = Record<string, () => ScriptFailure>
6
3
 
7
- type AllOptional<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? true : false }[keyof T]
8
-
9
- type Scriptor<Args = unknown, Ret = unknown> = {
10
- name: string
11
- call: AllOptional<Args> extends true ? (args?: Args) => Ret : (args: Args) => Ret
12
- }
13
-
14
4
  type Subscripts = Record<string, Record<string, (...args: any) => any>> & {
15
5
  accts: ErrorScripts
16
6
  autos: ErrorScripts
@@ -27,15 +17,8 @@ type Subscripts = Record<string, Record<string, (...args: any) => any>> & {
27
17
  users: ErrorScripts
28
18
  }
29
19
 
30
- interface PlayerFullsec {}
31
- interface PlayerHighsec {}
32
- interface PlayerMidsec {}
33
- interface PlayerLowsec {}
34
- interface PlayerNullsec {}
35
-
36
20
  type UpgradeRarityString = "`0noob`" | "`1kiddie`" | "`2h4x0r`" | "`3h4rdc0r3`" | "`4|_|b3|2`" | "`531337`"
37
- type UpgradeRarityNumber = 0 | 1 | 2 | 3 | 4 | 5;
38
- type UpgradeRarity = UpgradeRarityString | UpgradeRarityNumber;
21
+ type UpgradeRarityNumber = 0 | 1 | 2 | 3 | 4 | 5
39
22
 
40
23
  type UpgradeBase = {
41
24
  name: string
@@ -51,10 +34,8 @@ type UpgradeBase = {
51
34
 
52
35
  type Upgrade = UpgradeBase & Record<string, null | boolean | number | string>
53
36
 
54
- type CliUpgrade = Omit<UpgradeBase, `rarity`> & {
55
- [x: string]: null | boolean | number | string
56
- rarity: UpgradeRarityString
57
- }
37
+ type CliUpgrade = Omit<UpgradeBase, `rarity`> &
38
+ { [k: string]: null | boolean | number | string, rarity: UpgradeRarityString }
58
39
 
59
40
  type UsersTopItem<R> = { rank: R, name: string, last_activity: string, balance: string }
60
41
  type CorpsTopItem<R> = { rank: R, name: string, worth: string }
@@ -132,21 +113,11 @@ type Fullsec = Subscripts & PlayerFullsec & {
132
113
  }
133
114
 
134
115
  escrow: {
135
- /** **FULLSEC** */ charge: (args: {
136
- cost: number | string
137
- is_unlim?: boolean
138
- }) => null | ScriptFailure
139
-
116
+ /** **FULLSEC** */ charge: (args: { cost: number | string, is_unlim?: boolean }) => null | ScriptFailure
140
117
  confirm: never
141
118
  }
142
119
 
143
- gui: {
144
- chats: never
145
- quiet: never
146
- size: never
147
- vfx: never
148
- vol: never
149
- }
120
+ gui: { chats: never, quiet: never, size: never, vfx: never, vol: never }
150
121
 
151
122
  market: {
152
123
  /** **FULLSEC** */ browse: {
@@ -465,7 +436,10 @@ type Highsec = Fullsec & PlayerHighsec & {
465
436
  /** **HIGHSEC**
466
437
  * @returns GC balance as number if `is_script` is true (default).
467
438
  * @returns GC balance as string if `is_script` is false. */
468
- balance: ((args?: { is_script?: true }) => number) & ((args: { is_script: false }) => string)
439
+ balance: {
440
+ (args?: { is_script?: true }): number
441
+ (args: { is_script: false }): string
442
+ }
469
443
 
470
444
  /** **HIGHSEC**
471
445
  * @returns Transaction history according to filter.
@@ -635,6 +609,9 @@ type Lowsec = Midsec & PlayerLowsec & {
635
609
  (args: { i: number | number[], to: string, memo?: string }): ScriptResponse
636
610
  (args: { sn: string | string[], to: string, memo?: string }): ScriptResponse
637
611
  }
612
+ /** **LOWSEC** */ expose_access_log: (args: { target: string }) => ScriptResponse
613
+ /** **LOWSEC** */ xfer_gc_from: (args: { target: string, amount: number | string }) => ScriptResponse
614
+ /** **LOWSEC** */ expose_balance: (args: { target: string }) => ScriptResponse
638
615
  }
639
616
  }
640
617
 
@@ -719,95 +696,145 @@ type Nullsec = Lowsec & PlayerNullsec & {
719
696
  }
720
697
  }
721
698
 
722
- type MongoTypeString = "minKey" | "double" | "string" | "object" | "array" | "binData" | "undefined" | "objectId" |
723
- "bool" | "date" | "null" | "regex" | "dbPointer" | "javascript" | "symbol" | "int" | "timestamp" | "long" | "decimal" | "maxKey";
724
- type MongoTypeNumber = -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 127;
699
+ // database
700
+ type MongoPrimitive = null | boolean | number | Date | string
701
+ type MongoValue = MongoPrimitive | MongoValue[] | MongoObject
702
+ type MongoObject = { [k: string]: MongoValue, [k: `$${string}`]: never }
703
+ type MongoQueryValue = MongoPrimitive | MongoQueryValue[] | MongoQueryObject
704
+
705
+ type MongoQueryObject =
706
+ { [k: string]: MongoQueryValue, [k: `$${string}`]: MongoValue, $type?: keyof MongoTypeStringsToTypes | (string & {}) }
707
+
708
+ type MongoTypeStringsToTypes = {
709
+ double: number
710
+ string: string
711
+ object: MongoObject
712
+ array: MongoValue[]
713
+ objectId: ObjectId
714
+ bool: boolean
715
+ date: Date
716
+ null: null
717
+ int: number
718
+ long: number
719
+ }
725
720
 
726
- type MongoValue = string | number | boolean | Date | MongoValue[] | { [key: string]: MongoValue } | null
721
+ type MongoTypeString = keyof MongoTypeStringsToTypes
722
+ type MongoTypeNumber = -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 127
723
+ type MongoId = Exclude<MongoPrimitive, null> | MongoObject
724
+ type MongoQueryId = Exclude<MongoPrimitive, null> | MongoQueryObject
725
+ type MongoDocument = MongoObject & { _id?: MongoId }
726
+
727
+ type MongoQueryType<TQuery extends MongoQueryObject> = {
728
+ -readonly [K in keyof TQuery]:
729
+ TQuery[K] extends MongoPrimitive ?
730
+ TQuery[K]
731
+ : TQuery[K] extends { $type: infer TType } ?
732
+ TType extends keyof MongoTypeStringsToTypes ? MongoTypeStringsToTypes[TType] : unknown
733
+ : TQuery[K] extends { $in: (infer TIn)[] } ?
734
+ TIn
735
+ : keyof TQuery[K] extends `$${string}` ?
736
+ unknown
737
+ : TQuery[K] extends { [k: string]: any } ?
738
+ MongoQueryType<TQuery[K]>
739
+ : never
740
+ }
727
741
 
728
- type MongoCommandValue = string | number | boolean | Date | MongoCommandValue[] | { [key: string]: MongoCommandValue } |
729
- null | undefined
742
+ type MongoCommandValue = MongoPrimitive | MongoCommandValue[] | { [k: string]: MongoCommandValue }
743
+ type MongoArraySelectors<T extends MongoValue[] = MongoValue[]> = { $all: T, $elemMatch: T, $size: number }
730
744
 
731
- /**
732
- * Currently unused
733
- */
734
- type MongoLogicalSelectors<T extends MongoValue = MongoValue> = {
735
- $not: T | MongoComparisonSelectors<T> | MongoLogicalSelectors<T>
736
- $nor: T[]
737
- $or: T[]
738
- $and: T[]
739
- }
745
+ type MongoComparisonSelectors<T extends MongoValue = MongoValue> =
746
+ { $eq: T, $gt: T, $gte: T, $in: T[], $lt: T, $lte: T, $ne: T, $nin: T[] }
740
747
 
741
- type MongoArraySelectors<T extends Array<MongoValue> = Array<MongoValue>> = {
742
- $all: T
743
- $elemMatch: T
744
- $size: number
745
- }
748
+ type MongoElementSelectors = { $exists: boolean, $type: MongoTypeNumber | MongoTypeString }
746
749
 
747
- type MongoComparisonSelectors<T extends MongoValue = MongoValue> = {
748
- $eq: T
749
- $gt: T
750
- $gte: T
751
- $in: T[]
752
- $lt: T
753
- $lte: T
754
- $ne: T
755
- $nin: T[]
756
- }
750
+ type MongoQuerySelector<T extends MongoValue> = Partial<
751
+ T extends []
752
+ ? MongoArraySelectors<T> & MongoElementSelectors & MongoComparisonSelectors<T>
753
+ : MongoElementSelectors & MongoComparisonSelectors<T>
754
+ >
757
755
 
758
- type MongoElementSelectors = {
759
- $exists: boolean
760
- $type: MongoTypeNumber | MongoTypeString
761
- }
756
+ type MongoQuery<T extends MongoObject> = { [K in keyof T]?: T[K] | MongoQuerySelector<T[K]> } & { _id?: MongoId }
762
757
 
763
- type MongoQuerySelector<T extends MongoValue = MongoValue> = Partial<T extends MongoValue[] ?
764
- (MongoArraySelectors<T> & MongoElementSelectors & MongoComparisonSelectors<T>) :
765
- (MongoElementSelectors & MongoComparisonSelectors<T>)>
758
+ type MongoUpdateOperators<T extends MongoObject> = Partial<{
759
+ /* Universal operators */
760
+ $set: Partial<Record<string, MongoCommandValue> & T>
761
+ $setOnInsert: Partial<Record<string, MongoCommandValue> & T>
762
+ $unset: Partial<Record<string, ""> & T>
766
763
 
767
- type Query = { [key: string]: MongoValue | Query } & { _id?: Id, $in?: MongoValue[] }
768
- type Projection = Record<string, boolean | 0 | 1>
764
+ $rename: Partial<Record<string, string> & { [key in keyof T]: string }>
769
765
 
770
- type MongoCommand = MongoCommandValue & Partial<
771
- { $set: Record<string, MongoCommandValue>, $push: Record<string, MongoCommandValue>, $unset: Record<string, ""> }
772
- >
766
+ /* Date & number operators */
767
+ $inc: Record<string, number> &
768
+ { [K in keyof T as T[K] extends number | Date ? K : never]?: T[K] extends number ? number : Date }
769
+
770
+ $mul: Record<string, number> & { [K in keyof T as T[K] extends number ? K : never]?: number }
771
+ $min: Record<string, number> & { [K in keyof T as T[K] extends number ? K : never]?: number }
772
+ $max: Record<string, number> & { [K in keyof T as T[K] extends number ? K : never]?: number }
773
+
774
+ /* Array operators */
775
+ $pop: Record<string, -1 | 1> & { [K in keyof T as T[K] extends [] ? K : never]?: -1 | 1 }
776
+
777
+ $push: Record<string, MongoCommandValue> & {
778
+ [K in keyof T as T[K] extends [] ? K : never]?: (T[K] extends (infer U)[] ? U : never)
779
+ | MongoUpdateArrayOperatorModifiers<T[K]>
780
+ }
781
+
782
+ $addToSet: Partial<Record<string, MongoCommandValue> & {
783
+ [K in keyof T as T[K] extends [] ? K : never]: (T[K] extends (infer U)[] ? U : never)
784
+ | MongoUpdateArrayOperatorUniversalModifiers<T[K]>
785
+ }>
786
+
787
+ $pull: Partial<Record<string, MongoCommandValue> & {
788
+ [K in keyof T as T[K] extends [] ? K : never]: (T[K] extends (infer U)[] ? U : never)
789
+ | MongoQuerySelector<T[K]>
790
+ }>
791
+
792
+ $pullAll: Record<string, MongoCommandValue> & { [K in keyof T as T[K] extends [] ? K : never]?: T[K] }
793
+ }>
794
+
795
+ type MongoUpdateArrayOperatorUniversalModifiers<T> = { $each?: T extends [] ? T : T[] }
796
+
797
+ type MongoUpdateArrayOperatorModifiers<T> = MongoUpdateArrayOperatorUniversalModifiers<T> &
798
+ { $position?: number, $slice?: number, $sort?: 1 | -1 }
799
+
800
+ type MongoUpdateCommand<Schema extends MongoObject> = MongoUpdateOperators<Schema>
773
801
 
774
- type Id = string | number | boolean | Date | Record<string, MongoValue>
775
- type MongoDocument = { [key: string]: MongoValue, _id: Id }
776
802
  type SortOrder = { [key: string]: 1 | -1 | SortOrder }
777
803
 
778
- type Cursor = {
779
- /** Returns the first document that satisfies the query. */ first: () => MongoDocument | null
780
- /** Returns an array of documents that satisfy the query. */ array: () => MongoDocument[]
804
+ type Cursor<T> = {
805
+ /** Returns the first document that satisfies the query. */ first: () => T | null
806
+ /** Returns an array of documents that satisfy the query. */ array: () => T[]
781
807
  /** Returns the number of documents that match the query. */ count: () => number
782
808
 
783
809
  /** Returns the first document that satisfies the query. Also makes cursor unusable. */
784
- first_and_close: () => MongoDocument
810
+ first_and_close: () => T
785
811
 
786
812
  /** Returns an array of documents that satisfy the query. Also makes cursor unusable. */
787
- array_and_close: () => MongoDocument[]
813
+ array_and_close: () => T[]
788
814
 
789
815
  /** Returns the number of documents that match the query. Also makes cursor unusable. */
790
816
  count_and_close: () => number
791
817
 
792
818
  /** Run `callback` on each document that satisfied the query. */
793
- each: (callback: (document: MongoDocument) => void) => null
819
+ each: (callback: (document: T) => void) => null
794
820
 
795
821
  /** Returns a new cursor with documents sorted as specified.
796
822
  * A value of 1 sorts the property ascending, and -1 descending.
797
823
  * @param order The way the documents are to be sorted. */
798
- sort: (order?: SortOrder) => Cursor
824
+ sort: (order?: SortOrder) => Cursor<T>
799
825
 
800
826
  /** Returns a new cursor without the first number of documents.
801
827
  * @param count Number of documents to skip. */
802
- skip: (count: number) => Cursor
828
+ skip: (count: number) => Cursor<T>
803
829
 
804
830
  /** Returns a new cursor limited to a number of documents as specified.
805
831
  * @param count Number of documents. */
806
- limit: (count: number) => Cursor
832
+ limit: (count: number) => Cursor<T>
807
833
 
808
- /** @param key The key of the documents. */ distinct: ((key: string) => MongoValue[]) & ((key: "_id") => Id[])
834
+ /** @param key The key of the documents. */ distinct: { (key: string): MongoValue[], (key: "_id"): MongoId[] }
809
835
  /** Make cursor unusable. */ close: () => null
810
836
  NumberLong: (number: number) => number
837
+ // TODO what actually is the type here?
811
838
  ObjectId: () => any
812
839
  }
813
840
 
@@ -818,7 +845,9 @@ type CliContext = {
818
845
  /** The number of rows in the caller’s terminal. */ rows: number
819
846
 
820
847
  /** The name of the script that directly called this script, or null if called on the command line or as a
821
- * scriptor. */ calling_script: null
848
+ * scriptor. */
849
+ calling_script: null
850
+
822
851
  is_scriptor?: undefined
823
852
  is_brain?: undefined
824
853
  }
@@ -829,245 +858,224 @@ type SubscriptContext = Replace<CliContext, {
829
858
  calling_script: string
830
859
  }>
831
860
 
832
- type ScriptorContext =
833
- Replace<CliContext, { /** Whether the script is being run as a scriptor. */ is_scriptor: true }>
834
-
835
- type BrainContext =
836
- Replace<CliContext, { /** Whether the script is being run via a bot brain. */ is_brain: true }>
837
-
838
- type Context = CliContext | SubscriptContext | ScriptorContext | BrainContext
839
-
840
- /** Subscript space that can call FULLSEC scripts. */ declare const $fs: Fullsec
841
-
842
- /** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
843
- declare const $hs: Highsec
844
-
845
- /** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
846
- */
847
- declare const $ms: Midsec
848
-
849
- /** Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
850
- */
851
- declare const $ls: Lowsec
861
+ type ScriptorContext = Replace<CliContext, { /** Whether the script is being run as a scriptor. */ is_scriptor: true }>
862
+ type BrainContext = Replace<CliContext, { /** Whether the script is being run via a bot brain. */ is_brain: true }>
863
+
864
+ // _id is always returned unless _id: false is passed
865
+ // when anyField: true is given, other fields (except _id) are omitted
866
+
867
+ type MongoProject<TDocument, TProjection> =
868
+ true extends (1 extends TProjection[keyof TProjection] ? true : TProjection[keyof TProjection]) ?
869
+ (TProjection extends { _id: false | 0 } ? {} : { _id: TDocument extends { _id: infer TId } ? TId : MongoId }) &
870
+ {
871
+ [K in
872
+ keyof TDocument as K extends keyof TProjection ? TProjection[K] extends true | 1 ? K : never : never
873
+ ]: TDocument[K]
874
+ } &
875
+ {
876
+ -readonly [K in
877
+ keyof TProjection as TProjection[K] extends true | 1 ? K extends keyof TDocument ? never : K : never
878
+ ]?: MongoValue
879
+ }
880
+ : { [k: string]: MongoValue } & { [K in keyof TDocument as K extends keyof TProjection ? never : K]: TDocument[K] }
852
881
 
853
- /** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
854
- declare const $ns: Nullsec
882
+ type DeepFreeze<T> = { readonly [P in keyof T]: DeepFreeze<T[P]> }
855
883
 
856
- /** Subscript space that can call FULLSEC scripts. */ declare const $4s: typeof $fs
884
+ declare global {
885
+ type ScriptSuccess<T = unknown> = { ok: true } & T
886
+ type ScriptFailure = { ok: false, msg?: string }
887
+ type ScriptResponse<T = unknown> = ScriptSuccess<T> | ScriptFailure
888
+ type Scriptor<TArgs extends any[] = any[]> = { name: string, call: (...args: TArgs) => unknown }
889
+ type Context = CliContext | SubscriptContext | ScriptorContext | BrainContext
890
+ type ObjectId = { $oid: string }
857
891
 
858
- /** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
859
- declare const $3s: typeof $hs
892
+ interface PlayerFullsec {}
893
+ interface PlayerHighsec {}
894
+ interface PlayerMidsec {}
895
+ interface PlayerLowsec {}
896
+ interface PlayerNullsec {}
860
897
 
861
- /** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
862
- */
863
- declare const $2s: typeof $ms
898
+ /** Subscript space that can call FULLSEC scripts. */ const $fs: Fullsec
864
899
 
865
- /** Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
866
- */
867
- declare const $1s: typeof $ls
900
+ /** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
901
+ const $hs: Highsec
868
902
 
869
- /** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
870
- declare const $0s: typeof $ns
903
+ /** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
904
+ */
905
+ const $ms: Midsec
871
906
 
872
- /** Subscript space that can call any script. Uses seclevel provided in comment before script (defaults to NULLSEC)
873
- * @example
874
- * // @ seclevel MIDSEC
875
- * // remove the space betwen "@" and "s", there's only a space because otherwise vscode breaks
876
- * export function script() {
877
- * $s.foo.bar() // will be converted to #ms.foo.bar()
878
- * } */
879
- declare const $s: Nullsec
907
+ /** Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
908
+ */
909
+ const $ls: Lowsec
880
910
 
881
- type ObjectId = { $oid: string }
911
+ /** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
912
+ const $ns: Nullsec
882
913
 
883
- declare const $db: {
884
- /** Insert a document or documents into a collection.
885
- * @param documents A document or array of documents to insert into the collection. */
886
- i: (documents: object | object[]) => {
887
- ok: 1
888
- n: number
889
- opTime: { ts: "Undefined Conversion", t: number }
890
- electionId: "Undefined Conversion"
891
- operationTime: "Undefined Conversion"
892
- $clusterTime: {
893
- clusterTime: "Undefined Conversion"
894
- signature: { hash: "Undefined Conversion", keyId: "Undefined Conversion" }
895
- }
896
- }
914
+ /** Subscript space that can call FULLSEC scripts. */ const $4s: typeof $fs
897
915
 
898
- /** Remove documents from a collection.
899
- * @param query Specifies deletion criteria using query operators. */
900
- r: (query: Query) => {
901
- ok: 0 | 1
902
- n: number
903
- opTime: { ts: "Undefined Conversion", t: number }
904
- electionId: "Undefined Conversion"
905
- operationTime: "Undefined Conversion"
906
- $clusterTime: {
907
- clusterTime: "Undefined Conversion"
908
- signature: { hash: "Undefined Conversion", keyId: "Undefined Conversion" }
909
- }
910
- }
916
+ /** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
917
+ const $3s: typeof $hs
911
918
 
912
- /** Find documents in a collection or view and returns a cursor to the selected documents.
913
- * @param query Specifies deletion criteria using query operators.
914
- * @param projection Specifies the fields to return in the documents that match the query filter. */
915
- f: (query?: Query, projection?: Projection) => Cursor
916
-
917
- /** Update an existing documents in a collection.
918
- * @param query Specifies deletion criteria using query operators.
919
- * @param command The modifications to apply.
920
- * {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
921
- u: (query: Query | Query[], command: MongoCommand) => {
922
- ok: 0 | 1
923
- nModified: number
924
- n: number
925
- opTime: { ts: "Undefined Conversion", t: number }
926
- electionId: "Undefined Conversion"
927
- operationTime: "Undefined Conversion"
928
- $clusterTime: {
929
- clusterTime: "Undefined Conversion"
930
- signature: { hash: "Undefined Conversion", keyId: "Undefined Conversion" }
931
- }
932
- }
933
-
934
- /** Updates one document within the collection based on the filter.
935
- * @param query Specifies deletion criteria using query operators.
936
- * @param command The modifications to apply.
937
- * {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
938
- u1: (query: Query | Query[], command: MongoCommand) => {
939
- ok: 0 | 1
940
- nModified: number
941
- n: number
942
- opTime: {
943
- ts: "Undefined Conversion"
944
- t: number
945
- }
946
- electionId: "Undefined Conversion"
947
- operationTime: "Undefined Conversion"
948
- $clusterTime: {
949
- clusterTime: "Undefined Conversion"
950
- signature: {
951
- hash: "Undefined Conversion"
952
- keyId: "Undefined Conversion"
953
- }
954
- }
955
- }
919
+ /** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
920
+ */
921
+ const $2s: typeof $ms
956
922
 
957
- /** Update or insert or insert document.
958
- * Same as Update, but if no documents match the query, one document will be inserted based on the properties in
959
- * both the query and the command.
960
- * The `$setOnInsert` operator is useful to set defaults.
961
- * @param query Specifies deletion criteria using query operators.
962
- * @param command The modifications to apply.
963
- * {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
964
- us: (query: Query | Query[], command: MongoCommand) => {
965
- ok: 0 | 1
966
- nModified: number
967
- n: number
968
- opTime: { ts: "Undefined Conversion", t: number }
969
- electionId: "Undefined Conversion"
970
- operationTime: "Undefined Conversion"
971
- $clusterTime: {
972
- clusterTime: "Undefined Conversion"
973
- signature: { hash: "Undefined Conversion", keyId: "Undefined Conversion" }
974
- }
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
975
982
  }
976
983
 
977
- ObjectId: () => ObjectId
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
+ /** @deprecated Use `_SCRIPT_SUBNAME` instead. */
1050
+ const _SCRIPT_NAME: string
1051
+
1052
+ /** The name of this script excluding the user and `.`.
1053
+ *
1054
+ * e.g. in the script `foo.bar`, `_SCRIPT_NAME` is `bar`.
1055
+ *
1056
+ * Shorter alternative to `context.this_script.split(".")[1].
1057
+ *
1058
+ * In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
1059
+ const _SCRIPT_SUBNAME: string
1060
+
1061
+ /** The full name of this script equivilent to `context.this_script` but should use less characters.
1062
+ *
1063
+ * In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
1064
+ const _FULL_SCRIPT_NAME: string
1065
+
1066
+ /** The seclevel of this script as a number.
1067
+ *
1068
+ * In rare cases where it's not known at build time, it's `-1`. */
1069
+ const _SECLEVEL: -1 | 0 | 1 | 2 | 3 | 4
1070
+
1071
+ /** Recursively
1072
+ * [`Object.freeze()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
1073
+ * an object and its properties' objects and its properties' objects and so on.
1074
+ *
1075
+ * [Official Hackmud Wiki](https://wiki.hackmud.com/scripting/extensions/deep_freeze) */
1076
+ const DEEP_FREEZE: <T>(value: T) => DeepFreeze<T>
1077
+
1078
+ const _RUN_ID: string
978
1079
  }
979
1080
 
980
- /** Debug Log.
981
- *
982
- * If `$D()` is called in a script you own, the `return` value of the top level script is suppressed and instead an
983
- * array of every `$D()`’d entry is printed.
984
- * This lets you use `$D()` like `console.log()`.
985
- *
986
- * `$D()` in scripts not owned by you are not shown but the `return` value always is.
987
- *
988
- * `$D()` returns the first argument so `$D("Hello, World!") evaluates to `"Hello, World!"` as if the `$D` text wasn't
989
- * there.
990
- *
991
- * `$D()`’d items are returned even if the script times out or errors. */
992
- declare function $D<T>(args: T): T
993
-
994
- /** Function Multi-Call Lock.
995
- *
996
- * This is used by escrow to ensure that it is only used once in script execution.
997
- *
998
- * The first time (per-script) `$FMCL` is encountered, it returns `undefined`, every other time it `return`s `true`.
999
- *
1000
- * @example
1001
- * if ($FMCL)
1002
- * return { ok: false, msg: "This script can only be used once per script execution." }
1003
- *
1004
- * // all code here will only run once */
1005
- declare const $FMCL: undefined | true
1006
-
1007
- /** Per-script mutable "global" persistent object that is discarded at the end of top level script execution.
1008
- *
1009
- * `$G` persists between script calls until the end of the main script run making it useful for caching db entries when
1010
- * your script is a subscript.
1011
- * @example
1012
- * if (!$G.dbCache)
1013
- * $G.dbCache = $db.f({ whatever: true }).first() */
1014
- declare const $G: Record<string | symbol, any>
1015
-
1016
- /** This contains a JS timestamp (not Date) set immediately before your code begins running.
1017
- * @example
1018
- * $D(Date.now() - _START) // milliseconds left of run time
1019
- */
1020
- declare const _START: number
1021
-
1022
- /** This contains a JS timestamp (not Date) set immediately before your code begins running.
1023
- * @example
1024
- * $D(Date.now() - _ST) // milliseconds left of run time */
1025
- declare const _ST: typeof _START
1026
-
1027
- /** JavaScript timestamp for the end of the script run (`_START + _TIMEOUT`). */ declare const _END: number
1028
-
1029
- /** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
1030
- declare const _TIMEOUT: number
1031
-
1032
- /** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
1033
- declare const _TO: typeof _TIMEOUT
1034
-
1035
- /** The source code of this script as a string. */ declare const _SOURCE: string
1036
- /** A unix timestamp of the date this script was built. */ declare const _BUILD_DATE: number
1037
-
1038
- /** The user this script has been uploaded to.
1039
- *
1040
- * Shorter alternative to `context.this_script.split(".")[0].
1041
- *
1042
- * In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
1043
- declare const _SCRIPT_USER: string
1044
-
1045
- /** The name of this script excluding the user and `.`.
1046
- *
1047
- * e.g. in the script `foo.bar`, `_SCRIPT_NAME` is `bar`.
1048
- *
1049
- * Shorter alternative to `context.this_script.split(".")[1].
1050
- *
1051
- * In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
1052
- declare const _SCRIPT_NAME: string
1053
-
1054
- /** The full name of this script equivilent to `context.this_script` but should use less characters.
1055
- *
1056
- * In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
1057
- declare const _FULL_SCRIPT_NAME: string
1058
-
1059
- /** The seclevel of this script as a number.
1060
- *
1061
- * In rare cases where it's not known at build time, it's `-1`. */
1062
- declare const _SECLEVEL: -1 | 0 | 1 | 2 | 3 | 4
1063
-
1064
- type DeepFreeze<T> = { readonly [P in keyof T]: DeepFreeze<T[P]> }
1065
-
1066
- /** Recursively
1067
- * [`Object.freeze()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
1068
- * an object and its properties' objects and its properties' objects and so on.
1069
- *
1070
- * [Official Hackmud Wiki](https://wiki.hackmud.com/scripting/extensions/deep_freeze) */
1071
- declare const DEEP_FREEZE: <T>(value: T) => DeepFreeze<T>
1072
-
1073
- declare const _RUN_ID: string
1081
+ export {}