hackmud-script-manager 0.20.4-abe4703 → 0.20.4-ae3052c

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,7 +1,7 @@
1
1
  type Replace<A, B> = Omit<A, keyof B> & B
2
- type ScriptSuccess<T = object> = { ok: true } & T
2
+ type ScriptSuccess<T = unknown> = { ok: true } & T
3
3
  type ScriptFailure = { ok: false, msg?: string }
4
- type ScriptResponse<T = object> = ScriptSuccess<T> | ScriptFailure
4
+ type ScriptResponse<T = unknown> = ScriptSuccess<T> | ScriptFailure
5
5
  type ErrorScripts = Record<string, () => ScriptFailure>
6
6
 
7
7
  type Subscripts = Record<string, Record<string, (...args: any) => any>> & {
@@ -26,24 +26,25 @@ interface PlayerMidsec {}
26
26
  interface PlayerLowsec {}
27
27
  interface PlayerNullsec {}
28
28
 
29
- type UpgradeCore = {
29
+ type UpgradeRarityString = "`0noob`" | "`1kiddie`" | "`2h4x0r`" | "`3h4rdc0r3`" | "`4|_|b3|2`" | "`531337`"
30
+ type UpgradeRarityNumber = 0 | 1 | 2 | 3 | 4 | 5
31
+
32
+ type UpgradeBase = {
30
33
  name: string
31
34
  type: "lock" | "script_space" | "chat" | "script" | "tool" | "bot_brain" | "glam"
32
35
  up_class?: -1 | 0 | 1 | 2 | 3
33
36
  tier: 1 | 2 | 3 | 4
34
- rarity: 0 | 1 | 2 | 3 | 4 | 5
37
+ rarity: UpgradeRarityNumber
35
38
  i: number
36
39
  loaded: boolean
37
40
  sn: string
38
41
  description: string
39
42
  }
40
43
 
41
- type Upgrade = UpgradeCore & Record<string, null | boolean | number | string>
44
+ type Upgrade = UpgradeBase & Record<string, null | boolean | number | string>
42
45
 
43
- type CLIUpgrade = Omit<UpgradeCore, `rarity`> & {
44
- [x: string]: null | boolean | number | string
45
- rarity: "`0noob`" | "`1kiddie`" | "`2h4x0r`" | "`3h4rdc0r3`" | "`4|_|b3|2`" | "`531337`"
46
- }
46
+ type CliUpgrade = Omit<UpgradeBase, `rarity`> &
47
+ { [k: string]: null | boolean | number | string, rarity: UpgradeRarityString }
47
48
 
48
49
  type UsersTopItem<R> = { rank: R, name: string, last_activity: string, balance: string }
49
50
  type CorpsTopItem<R> = { rank: R, name: string, worth: string }
@@ -121,26 +122,25 @@ type Fullsec = Subscripts & PlayerFullsec & {
121
122
  }
122
123
 
123
124
  escrow: {
124
- /** **FULLSEC** */ charge: (args: {
125
- cost: number | string
126
- is_unlim?: boolean
127
- }) => null | ScriptFailure
128
-
125
+ /** **FULLSEC** */ charge: (args: { cost: number | string, is_unlim?: boolean }) => null | ScriptFailure
129
126
  confirm: never
130
127
  }
131
128
 
132
- gui: {
133
- chats: never
134
- quiet: never
135
- size: never
136
- vfx: never
137
- vol: never
138
- }
129
+ gui: { chats: never, quiet: never, size: never, vfx: never, vol: never }
139
130
 
140
131
  market: {
141
132
  /** **FULLSEC** */ browse: {
142
133
  (args:
143
- Partial<{ seller: string, listed_before: number, listed_after: number, cost: number | string } & Omit<CLIUpgrade, "rarity">>
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">>
144
144
  ): { i: string, name: string, rarity: Upgrade["rarity"], cost: number }[] | ScriptFailure
145
145
 
146
146
  <I extends string>(args: { i: I }): {
@@ -409,17 +409,17 @@ type Fullsec = Subscripts & PlayerFullsec & {
409
409
  upgrades_of_owner: {
410
410
  <F extends Partial<Upgrade & { loaded: boolean }> = object>(args?: { filter?: F, full?: false }): (
411
411
  Omit<
412
- Pick<UpgradeCore, "tier" | "rarity" | "name" | "type" | "i" | "loaded">,
412
+ Pick<UpgradeBase, "tier" | "rarity" | "name" | "type" | "i" | "loaded">,
413
413
  keyof F
414
414
  > & Pick<F, "tier" | "rarity" | "name" | "type" | "i" | "loaded">
415
415
  )[] | ScriptFailure
416
416
 
417
417
  <F extends Partial<Upgrade & { loaded: boolean }> = object>(args: { filter?: F, full: true }): (
418
- Omit<UpgradeCore, keyof F> & F & Record<string, null | boolean | number | string>
418
+ Omit<UpgradeBase, keyof F> & F & Record<string, null | boolean | number | string>
419
419
  )[] | ScriptFailure
420
420
 
421
421
  <I extends number>(args: { i: I }): (
422
- Omit<UpgradeCore, "i"> & { [x: string]: null | boolean | number | string, i: I }
422
+ Omit<UpgradeBase, "i"> & { [x: string]: null | boolean | number | string, i: I }
423
423
  ) | ScriptFailure
424
424
  }
425
425
 
@@ -445,7 +445,10 @@ type Highsec = Fullsec & PlayerHighsec & {
445
445
  /** **HIGHSEC**
446
446
  * @returns GC balance as number if `is_script` is true (default).
447
447
  * @returns GC balance as string if `is_script` is false. */
448
- balance: ((args?: { is_script?: true }) => number) & ((args: { is_script: false }) => string)
448
+ balance: {
449
+ (args?: { is_script?: true }): number
450
+ (args: { is_script: false }): string
451
+ }
449
452
 
450
453
  /** **HIGHSEC**
451
454
  * @returns Transaction history according to filter.
@@ -496,7 +499,7 @@ type Highsec = Fullsec & PlayerHighsec & {
496
499
  /** **HIGHSEC** */
497
500
  upgrades: {
498
501
  <I extends number>(args: { i: I }): (
499
- Omit<UpgradeCore, "i"> & { [x: string]: null | boolean | number | string, i: I }
502
+ Omit<UpgradeBase, "i"> & { [x: string]: null | boolean | number | string, i: I }
500
503
  ) | ScriptFailure
501
504
 
502
505
  <F extends Partial<Upgrade & { loaded: boolean }> = object>(args?: {
@@ -504,22 +507,22 @@ type Highsec = Fullsec & PlayerHighsec & {
504
507
  is_script?: true
505
508
  full?: false
506
509
  }): (
507
- Omit<Pick<UpgradeCore, "tier" | "rarity" | "name" | "type" | "i" | "loaded">, keyof F> & F &
510
+ Omit<Pick<UpgradeBase, "tier" | "rarity" | "name" | "type" | "i" | "loaded">, keyof F> & F &
508
511
  Record<string, null | boolean | number | string>
509
512
  )[] | ScriptFailure
510
513
 
511
514
  <F extends Partial<Upgrade & { loaded: boolean }> = object>(args?:
512
515
  { filter?: F, is_script?: true, full: true }
513
- ): (Omit<UpgradeCore, keyof F> & F & Record<string, null | boolean | number | string>)[] | ScriptFailure
516
+ ): (Omit<UpgradeBase, keyof F> & F & Record<string, null | boolean | number | string>)[] | ScriptFailure
514
517
 
515
518
  (args?: { filter?: Partial<Upgrade & { loaded: boolean }>, is_script: false, full?: false }):
516
519
  { msg: string, upgrades: string[] } | ScriptFailure
517
520
 
518
521
  <F extends Partial<Upgrade & { loaded: boolean }> = object>(
519
522
  args?: { filter?: F, is_script: false, full: true }
520
- ): (Omit<UpgradeCore, keyof F | `rarity`> & F & {
523
+ ): (Omit<UpgradeBase, keyof F | `rarity`> & F & {
521
524
  [x: string]: null | boolean | number | string
522
- rarity: "`0noob`" | "`1kiddie`" | "`2h4x0r`" | "`3h4rdc0r3`" | "`4|_|b3|2`" | "`531337`"
525
+ rarity: UpgradeRarityString
523
526
  })[] | ScriptFailure
524
527
  }
525
528
  }
@@ -615,6 +618,9 @@ type Lowsec = Midsec & PlayerLowsec & {
615
618
  (args: { i: number | number[], to: string, memo?: string }): ScriptResponse
616
619
  (args: { sn: string | string[], to: string, memo?: string }): ScriptResponse
617
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
618
624
  }
619
625
  }
620
626
 
@@ -699,294 +705,377 @@ type Nullsec = Lowsec & PlayerNullsec & {
699
705
  }
700
706
  }
701
707
 
702
- type MongoValue = string | number | boolean | Date | MongoValue[] | { [key: string]: MongoValue } | null
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
+ }
703
729
 
704
- type MongoCommandValue = string | number | boolean | Date | MongoCommandValue[] | { [key: string]: MongoCommandValue } |
705
- null | undefined
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
+ }
750
+
751
+ type MongoCommandValue = MongoPrimitive | MongoCommandValue[] | { [k: string]: MongoCommandValue }
752
+ type MongoArraySelectors<T extends MongoValue[] = MongoValue[]> = { $all: T, $elemMatch: T, $size: number }
753
+
754
+ type MongoComparisonSelectors<T extends MongoValue = MongoValue> =
755
+ { $eq: T, $gt: T, $gte: T, $in: T[], $lt: T, $lte: T, $ne: T, $nin: T[] }
706
756
 
707
- type Query = { [key: string]: MongoValue | Query } & { _id?: Id, $in?: MongoValue[] }
708
- type Projection = Record<string, boolean | 0 | 1>
757
+ type MongoElementSelectors = { $exists: boolean, $type: MongoTypeNumber | MongoTypeString }
709
758
 
710
- type MongoCommand = MongoCommandValue & Partial<
711
- { $set: Record<string, MongoCommandValue>, $push: Record<string, MongoCommandValue>, $unset: Record<string, ""> }
759
+ type MongoQuerySelector<T extends MongoValue> = Partial<
760
+ T extends []
761
+ ? MongoArraySelectors<T> & MongoElementSelectors & MongoComparisonSelectors<T>
762
+ : MongoElementSelectors & MongoComparisonSelectors<T>
712
763
  >
713
764
 
714
- type Id = string | number | boolean | Date | Record<string, MongoValue>
715
- type MongoDocument = { [key: string]: MongoValue, _id: Id }
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
+
716
811
  type SortOrder = { [key: string]: 1 | -1 | SortOrder }
717
812
 
718
- type Cursor = {
719
- /** Returns the first document that satisfies the query. */ first: () => MongoDocument | null
720
- /** Returns an array of documents that satisfy the query. */ array: () => MongoDocument[]
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[]
721
816
  /** Returns the number of documents that match the query. */ count: () => number
722
817
 
723
818
  /** Returns the first document that satisfies the query. Also makes cursor unusable. */
724
- first_and_close: () => MongoDocument
819
+ first_and_close: () => T
725
820
 
726
821
  /** Returns an array of documents that satisfy the query. Also makes cursor unusable. */
727
- array_and_close: () => MongoDocument[]
822
+ array_and_close: () => T[]
728
823
 
729
824
  /** Returns the number of documents that match the query. Also makes cursor unusable. */
730
825
  count_and_close: () => number
731
826
 
732
827
  /** Run `callback` on each document that satisfied the query. */
733
- each: (callback: (document: MongoDocument) => void) => null
828
+ each: (callback: (document: T) => void) => null
734
829
 
735
830
  /** Returns a new cursor with documents sorted as specified.
736
831
  * A value of 1 sorts the property ascending, and -1 descending.
737
832
  * @param order The way the documents are to be sorted. */
738
- sort: (order?: SortOrder) => Cursor
833
+ sort: (order?: SortOrder) => Cursor<T>
739
834
 
740
835
  /** Returns a new cursor without the first number of documents.
741
836
  * @param count Number of documents to skip. */
742
- skip: (count: number) => Cursor
837
+ skip: (count: number) => Cursor<T>
743
838
 
744
839
  /** Returns a new cursor limited to a number of documents as specified.
745
840
  * @param count Number of documents. */
746
- limit: (count: number) => Cursor
841
+ limit: (count: number) => Cursor<T>
747
842
 
748
- /** @param key The key of the documents. */ distinct: ((key: string) => MongoValue[]) & ((key: "_id") => Id[])
843
+ /** @param key The key of the documents. */ distinct: { (key: string): MongoValue[], (key: "_id"): MongoId[] }
749
844
  /** Make cursor unusable. */ close: () => null
750
845
  NumberLong: (number: number) => number
846
+ // TODO what actually is the type here?
751
847
  ObjectId: () => any
752
848
  }
753
849
 
754
- type CLIContext = {
850
+ type CliContext = {
755
851
  /** The name of the user who is calling the script. */ caller: string
756
852
  /** The name of this script. */ this_script: string
757
853
  /** The number of columns in the caller’s terminal. */ cols: number
758
854
  /** The number of rows in the caller’s terminal. */ rows: number
759
855
 
760
856
  /** The name of the script that directly called this script, or null if called on the command line or as a
761
- * scriptor. */ calling_script: null
857
+ * scriptor. */
858
+ calling_script: null
859
+
860
+ is_scriptor?: undefined
861
+ is_brain?: undefined
762
862
  }
763
863
 
764
- type SubscriptContext = Replace<CLIContext, {
864
+ type SubscriptContext = Replace<CliContext, {
765
865
  /** The name of the script that directly called this script, or null if called on the command line or as a scriptor.
766
866
  */
767
867
  calling_script: string
768
868
  }>
769
869
 
770
- type ScriptorContext = CLIContext & { /** Whether the script is being run as a scriptor. */ is_scriptor: true }
771
- type BrainContext = CLIContext & { /** Whether the script is being run via a bot brain. */ is_brain: true }
772
- type Context = CLIContext | SubscriptContext | ScriptorContext | BrainContext
773
-
774
- /** Subscript space that can call FULLSEC scripts. */ declare const $fs: Fullsec
775
-
776
- /** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
777
- declare const $hs: Highsec
778
-
779
- /** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
780
- */
781
- declare const $ms: Midsec
782
-
783
- /** Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
784
- */
785
- declare const $ls: Lowsec
786
-
787
- /** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
788
- declare const $ns: Nullsec
789
-
790
- /** Subscript space that can call FULLSEC scripts. */ declare const $4s: typeof $fs
791
-
792
- /** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
793
- declare const $3s: typeof $hs
794
-
795
- /** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
796
- */
797
- declare const $2s: typeof $ms
798
-
799
- /** Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
800
- */
801
- declare const $1s: typeof $ls
802
-
803
- /** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
804
- declare const $0s: typeof $ns
805
-
806
- /** Subscript space that can call any script. Uses seclevel provided in comment before script (defaults to NULLSEC)
807
- * @example
808
- * // @ seclevel MIDSEC
809
- * // remove the space betwen "@" and "s", there's only a space because otherwise vscode breaks
810
- * export function script() {
811
- * $s.foo.bar() // will be converted to #ms.foo.bar()
812
- * } */
813
- declare const $s: Nullsec
814
-
815
- declare const $db: {
816
- /** Insert a document or documents into a collection.
817
- * @param documents A document or array of documents to insert into the collection. */
818
- i: (documents: object | object[]) => {
819
- ok: 1
820
- n: number
821
- opTime: { ts: "Undefined Conversion", t: number }
822
- electionId: "Undefined Conversion"
823
- operationTime: "Undefined Conversion"
824
- $clusterTime: {
825
- clusterTime: "Undefined Conversion"
826
- signature: { hash: "Undefined Conversion", keyId: "Undefined Conversion" }
827
- }
828
- }
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] }
829
890
 
830
- /** Remove documents from a collection.
831
- * @param query Specifies deletion criteria using query operators. */
832
- r: (query: Query) => {
833
- ok: 0 | 1
834
- n: number
835
- opTime: { ts: "Undefined Conversion", t: number }
836
- electionId: "Undefined Conversion"
837
- operationTime: "Undefined Conversion"
838
- $clusterTime: {
839
- clusterTime: "Undefined Conversion"
840
- signature: { hash: "Undefined Conversion", keyId: "Undefined Conversion" }
841
- }
842
- }
891
+ type DeepFreeze<T> = { readonly [P in keyof T]: DeepFreeze<T[P]> }
843
892
 
844
- /** Find documents in a collection or view and returns a cursor to the selected documents.
845
- * @param query Specifies deletion criteria using query operators.
846
- * @param projection Specifies the fields to return in the documents that match the query filter. */
847
- f: (query?: Query, projection?: Projection) => Cursor
848
-
849
- /** Update an existing documents in a collection.
850
- * @param query Specifies deletion criteria using query operators.
851
- * @param command The modifications to apply.
852
- * {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
853
- u: (query: Query | Query[], command: MongoCommand) => {
854
- ok: 0 | 1
855
- nModified: number
856
- n: number
857
- opTime: { ts: "Undefined Conversion", t: number }
858
- electionId: "Undefined Conversion"
859
- operationTime: "Undefined Conversion"
860
- $clusterTime: {
861
- clusterTime: "Undefined Conversion"
862
- signature: { hash: "Undefined Conversion", keyId: "Undefined Conversion" }
863
- }
864
- }
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 }
865
897
 
866
- /** Updates one document within the collection based on the filter.
867
- * @param query Specifies deletion criteria using query operators.
868
- * @param command The modifications to apply.
869
- * {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
870
- u1: (query: Query | Query[], command: MongoCommand) => {
871
- ok: 0 | 1
872
- nModified: number
873
- n: number
874
- opTime: {
875
- ts: "Undefined Conversion"
876
- t: number
877
- }
878
- electionId: "Undefined Conversion"
879
- operationTime: "Undefined Conversion"
880
- $clusterTime: {
881
- clusterTime: "Undefined Conversion"
882
- signature: {
883
- hash: "Undefined Conversion"
884
- keyId: "Undefined Conversion"
885
- }
886
- }
887
- }
898
+ /** Subscript space that can call FULLSEC scripts. */ const $fs: Fullsec
888
899
 
889
- /** Update or insert or insert document.
890
- * Same as Update, but if no documents match the query, one document will be inserted based on the properties in
891
- * both the query and the command.
892
- * The `$setOnInsert` operator is useful to set defaults.
893
- * @param query Specifies deletion criteria using query operators.
894
- * @param command The modifications to apply.
895
- * {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
896
- us: (query: Query | Query[], command: MongoCommand) => {
897
- ok: 0 | 1
898
- nModified: number
899
- n: number
900
- opTime: { ts: "Undefined Conversion", t: number }
901
- electionId: "Undefined Conversion"
902
- operationTime: "Undefined Conversion"
903
- $clusterTime: {
904
- clusterTime: "Undefined Conversion"
905
- signature: { hash: "Undefined Conversion", keyId: "Undefined Conversion" }
906
- }
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
907
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
+ /** @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
908
1079
  }
909
1080
 
910
- /** Debug Log.
911
- *
912
- * If `$D()` is called in a script you own, the `return` value of the top level script is suppressed and instead an
913
- * array of every `$D()`’d entry is printed.
914
- * This lets you use `$D()` like `console.log()`.
915
- *
916
- * `$D()` in scripts not owned by you are not shown but the `return` value always is.
917
- *
918
- * `$D()` returns the first argument so `$D("Hello, World!") evaluates to `"Hello, World!"` as if the `$D` text wasn't
919
- * there.
920
- *
921
- * `$D()`’d items are returned even if the script times out or errors. */
922
- declare function $D<T>(args: T): T
923
-
924
- /** Function Multi-Call Lock.
925
- *
926
- * This is used by escrow to ensure that it is only used once in script execution.
927
- *
928
- * The first time (per-script) `$FMCL` is encountered, it returns `undefined`, every other time it `return`s `true`.
929
- *
930
- * @example
931
- * if ($FMCL)
932
- * return { ok: false, msg: "This script can only be used once per script execution." }
933
- *
934
- * // all code here will only run once */
935
- declare const $FMCL: undefined | true
936
-
937
- /** Per-script mutable "global" persistent object that is discarded at the end of top level script execution.
938
- *
939
- * `$G` persists between script calls until the end of the main script run making it useful for caching db entries when
940
- * your script is a subscript.
941
- * @example
942
- * if (!$G.dbCache)
943
- * $G.dbCache = $db.f({ whatever: true }).first() */
944
- declare const $G: any
945
-
946
- /** This contains a JS timestamp (not Date) set immediately before your code begins running.
947
- * @example
948
- * $D(Date.now() - _START) // milliseconds left of run time
949
- */
950
- declare const _START: number
951
-
952
- /** This contains a JS timestamp (not Date) set immediately before your code begins running.
953
- * @example
954
- * $D(Date.now() - _ST) // milliseconds left of run time */
955
- declare const _ST: typeof _START
956
-
957
- /** JavaScript timestamp for the end of the script run (`_START + _TIMEOUT`). */ declare const _END: number
958
-
959
- /** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
960
- declare const _TIMEOUT: number
961
-
962
- /** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
963
- declare const _TO: typeof _TIMEOUT
964
-
965
- /** The source code of this script as a string. */ declare const _SOURCE: string
966
- /** A unix timestamp of the date this script was built. */ declare const _BUILD_DATE: number
967
-
968
- /** The user this script has been uploaded to.
969
- *
970
- * Shorter alternative to `context.this_script.split(".")[0].
971
- *
972
- * In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
973
- declare const _SCRIPT_USER: string
974
-
975
- /** The name of this script excluding the user and `.`.
976
- *
977
- * e.g. in the script `foo.bar`, `_SCRIPT_NAME` is `bar`.
978
- *
979
- * Shorter alternative to `context.this_script.split(".")[1].
980
- *
981
- * In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
982
- declare const _SCRIPT_NAME: string
983
-
984
- /** The full name of this script equivilent to `context.this_script` but should use less characters.
985
- *
986
- * In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
987
- declare const _FULL_SCRIPT_NAME: string
988
-
989
- /** The seclevel of this script as a number.
990
- *
991
- * In rare cases where it's not known at build time, it's `-1`. */
992
- declare const _SECLEVEL: -1 | 0 | 1 | 2 | 3 | 4
1081
+ export {}