hackmud-script-manager 0.21.1-e4e0fd4 → 0.21.1-ef961a0

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,3 +1,5 @@
1
+ /* eslint-disable jsdoc/no-multi-asterisks, ts/no-empty-object-type */
2
+ /* eslint style/quotes: [ "warn", "double" ], */
1
3
  type Replace<A, B> = Omit<A, keyof B> & B
2
4
  type ErrorScripts = Record<string, () => ScriptFailure>
3
5
 
@@ -34,7 +36,7 @@ type UpgradeBase = {
34
36
 
35
37
  type Upgrade = UpgradeBase & Record<string, null | boolean | number | string>
36
38
 
37
- type CliUpgrade = Omit<UpgradeBase, `rarity`> &
39
+ type CliUpgrade = Omit<UpgradeBase, "rarity"> &
38
40
  { [k: string]: null | boolean | number | string, rarity: UpgradeRarityString }
39
41
 
40
42
  type UsersTopItem<R> = { rank: R, name: string, last_activity: string, balance: string }
@@ -42,7 +44,7 @@ type CorpsTopItem<R> = { rank: R, name: string, worth: string }
42
44
 
43
45
  type CorpsTop = [
44
46
  CorpsTopItem<1>, CorpsTopItem<2>, CorpsTopItem<3>, CorpsTopItem<4>, CorpsTopItem<5>,
45
- CorpsTopItem<6>,CorpsTopItem<7>, CorpsTopItem<8>, CorpsTopItem<9>, CorpsTopItem<10>
47
+ CorpsTopItem<6>, CorpsTopItem<7>, CorpsTopItem<8>, CorpsTopItem<9>, CorpsTopItem<10>
46
48
  ]
47
49
 
48
50
  type Fullsec = Subscripts & PlayerFullsec & {
@@ -77,12 +79,14 @@ type Fullsec = Subscripts & PlayerFullsec & {
77
79
  }
78
80
 
79
81
  chats: {
80
- /** **FULLSEC**
81
- * @summary Create a new chat channel.
82
- * @description This script lets you create a new chat channel.
83
- * You cannot create a channel that already exists (including any of the default ports from `0000` to `FFFF`).
84
- * If you do not supply a password, anyone can join your channel (but the channel name is not displayed
85
- * anywhere, so they would have to discover it in some way first). */
82
+ /**
83
+ * **FULLSEC**
84
+ * @summary Create a new chat channel.
85
+ * @description This script lets you create a new chat channel.
86
+ * You cannot create a channel that already exists (including any of the default ports from `0000` to `FFFF`).
87
+ * If you do not supply a password, anyone can join your channel (but the channel name is not displayed
88
+ * anywhere, so they would have to discover it in some way first).
89
+ */
86
90
  create: ((args: {
87
91
  /** The name of the channel to create. */ name: string
88
92
  /** The password to secure the channel with. */ password?: string
@@ -91,21 +95,25 @@ type Fullsec = Subscripts & PlayerFullsec & {
91
95
  /** The password to secure the channel with. */ password?: string
92
96
  }) => ScriptResponse)
93
97
 
94
- /** **FULLSEC**
95
- * @summary Send a chat message to a channel.
96
- * @description This script lets you send a message to the specified channel.
97
- * You must have joined the channel, and you will see your own message (unlike chats.tell). */
98
+ /**
99
+ * **FULLSEC**
100
+ * @summary Send a chat message to a channel.
101
+ * @description This script lets you send a message to the specified channel.
102
+ * You must have joined the channel, and you will see your own message (unlike chats.tell).
103
+ */
98
104
  send: (args: {
99
105
  /** The channel to send the message to. */ channel: string
100
106
  /** The message to send. */ msg: string
101
107
  }) => ScriptResponse
102
108
 
103
- /** **FULLSEC**
104
- * @summary Send a chat message to a specific user.
105
- * @description This script lets you send a message to the specified user directly.
106
- * You can message any user, you only need their username.
107
- * Note that you will not be able to see your message after it is sent (though many chat scripts based on
108
- * chats.tell also send the message to you to work around this limitation). */
109
+ /**
110
+ * **FULLSEC**
111
+ * @summary Send a chat message to a specific user.
112
+ * @description This script lets you send a message to the specified user directly.
113
+ * You can message any user, you only need their username.
114
+ * Note that you will not be able to see your message after it is sent (though many chat scripts based on
115
+ * chats.tell also send the message to you to work around this limitation).
116
+ */
109
117
  tell: (args: {
110
118
  /** The username to send the message to. */ to: string
111
119
  /** The message to send. */ msg: string
@@ -121,18 +129,16 @@ type Fullsec = Subscripts & PlayerFullsec & {
121
129
 
122
130
  market: {
123
131
  /** **FULLSEC** */ browse: {
124
- (args:
125
- Partial<{
126
- seller: string | MongoQuerySelector<string>,
127
- listed_before: number | MongoQuerySelector<number>,
128
- listed_after: number,
129
- cost: number | MongoQuerySelector<number> | string,
130
- rarity: UpgradeRarityNumber | MongoQuerySelector<UpgradeRarityNumber>,
131
- name: string | MongoQuerySelector<string>
132
- } & Omit<{
133
- [k in keyof CliUpgrade]: CliUpgrade[k] | MongoQuerySelector<CliUpgrade[k]>
134
- }, "rarity">>
135
- ): { i: string, name: string, rarity: Upgrade["rarity"], cost: number }[] | ScriptFailure
132
+ (args: Partial<{
133
+ seller: string | MongoQuerySelector<string>
134
+ listed_before: number | MongoQuerySelector<number>
135
+ listed_after: number
136
+ cost: number | MongoQuerySelector<number> | string
137
+ rarity: UpgradeRarityNumber | MongoQuerySelector<UpgradeRarityNumber>
138
+ name: string | MongoQuerySelector<string>
139
+ } & Omit<{
140
+ [k in keyof CliUpgrade]: CliUpgrade[k] | MongoQuerySelector<CliUpgrade[k]>
141
+ }, "rarity">>): { i: string, name: string, rarity: Upgrade["rarity"], cost: number }[] | ScriptFailure
136
142
 
137
143
  <I extends string>(args: { i: I }): {
138
144
  i: I
@@ -168,8 +174,10 @@ type Fullsec = Subscripts & PlayerFullsec & {
168
174
  /** **FULLSEC** */ nullsec: Fullsec["scripts"]["fullsec"]
169
175
  /** **FULLSEC** */ trust: () => string[]
170
176
 
171
- /** FULLSEC
172
- * @returns A code library containing useful helper functions you can use in your scripts. */
177
+ /**
178
+ * **FULLSEC*
179
+ * @returns A code library containing useful helper functions you can use in your scripts.
180
+ */
173
181
  lib: () => {
174
182
  ok: () => ScriptSuccess
175
183
  not_impl: () => { ok: false, msg: "Not Implemented." }
@@ -177,22 +185,28 @@ type Fullsec = Subscripts & PlayerFullsec & {
177
185
  /** @returns All messages added using `scripts.lib().log` during this script run. */ get_log: () => string[]
178
186
 
179
187
  /** @returns A random integer in the range [min, max) generated using `rng` (defaults to `Math.random`). */
180
- rand_int: (min: number, max: number, rng?:()=>number) => number
188
+ rand_int: (min: number, max: number, rng?: () => number) => number
181
189
 
182
- /** @returns `floor` if `value` is less than `floor`, `ceil` if `value` is more than `ceil`, otherwise
183
- * `value`. */
190
+ /**
191
+ * @returns `floor` if `value` is less than `floor`, `ceil` if `value` is more than `ceil`, otherwise
192
+ * `value`.
193
+ */
184
194
  clamp: (value: number, floor: number, ceil: number) => number
185
195
 
186
- /** Linear interpolation function.
187
- * @returns A number between `start` and `stop` using `amount` as a percent. */
196
+ /**
197
+ * Linear interpolation function.
198
+ * @returns A number between `start` and `stop` using `amount` as a percent.
199
+ */
188
200
  lerp: (amount: number, start: number, stop: number) => number
189
201
 
190
- /** @returns A random element from `array`, selected with a random number generated using `rng`
191
- * (defaults to `Math.random`). */
192
- sample: (array: any[], rng?: ()=>number) => any
202
+ /**
203
+ * @returns A random element from `array`, selected with a random number generated using `rng`
204
+ * (defaults to `Math.random`).
205
+ */
206
+ sample: <T>(array: T[], rng?: () => number) => T
193
207
 
194
208
  /** @returns Whether two MongoDB `ObjectId`s are equivalent. */ are_ids_eq: (id1: any, id2: any) => boolean
195
- /** Convert a MongoDB `ObjectId` to a string. */ id_to_str: (id: string | {$oid: string}) => any
209
+ /** Convert a MongoDB `ObjectId` to a string. */ id_to_str: (id: string | { $oid: string }) => any
196
210
  /** @returns Whether `value` is a boolean primitive. */ is_bool: (value: any) => value is boolean
197
211
  /** @returns Whether `value` is an object or `null`. */
198
212
  is_obj: (value: any) => value is Record<string, unknown> | null
@@ -239,8 +253,10 @@ type Fullsec = Subscripts & PlayerFullsec & {
239
253
 
240
254
  corruption_chars: "¡¢Á¤Ã¦§¨©ª"
241
255
 
242
- /** A list of unique color codes to be used with hackmud's color formatting syntax.
243
- * Does not include numeric codes, which are duplicates of some alphabetic codes. */
256
+ /**
257
+ * A list of unique color codes to be used with hackmud's color formatting syntax.
258
+ * Does not include numeric codes, which are duplicates of some alphabetic codes.
259
+ */
244
260
  colors: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
245
261
 
246
262
  /** Used by `$fs.scripts.lib().corrupt()` to determine the frequency of corruption. */
@@ -249,8 +265,10 @@ type Fullsec = Subscripts & PlayerFullsec & {
249
265
  /** Adds colored corruption characters to `text`, with frequency determined by `amount`. */
250
266
  corrupt: (text: string | string[], amount: 0 | 1 | 2 | 3 | 4) => string
251
267
 
252
- /** @returns The first `length` characters of `string`, or the original string if it is shorter than
253
- * `length`. */
268
+ /**
269
+ * @returns The first `length` characters of `string`, or the original string if it is shorter than
270
+ * `length`.
271
+ */
254
272
  cap_str_len: (string: string, length: number) => string
255
273
 
256
274
  /** Applies `callback` to each element in `array` and returns the original array. */
@@ -265,21 +283,25 @@ type Fullsec = Subscripts & PlayerFullsec & {
265
283
  /** @returns The first element in `array` for which `callback` returns `true`. */
266
284
  select_one: <T>(array: T[], callback: (index: number, value: T) => boolean) => T
267
285
 
268
- /** @returns A new array composed of the result of applying `callback` to each element of the original array
269
- * in order. */
286
+ /**
287
+ * @returns A new array composed of the result of applying `callback` to each element of the original array
288
+ * in order.
289
+ */
270
290
  map: <T, U>(array: T[], callback: (index: number, value: T) => U) => U[]
271
291
 
272
292
  /** @returns A new object derived from `obj` with only the keys specified in `keys`. */
273
- pick: (obj: object, keys: string[]) => any
293
+ pick: <TObj extends object, TKeys extends keyof TObj>(obj: TObj, keys: TKeys[]) => { [K in TKeys]: TObj[K] }
274
294
 
275
295
  /** @returns An array with the elements from `array` in a random order. */ shuffle: <T>(array: T[]) => T[]
276
296
 
277
- /** Comparison function for sorting arbitrary values in ascending order using builtin comparison operators.
278
- */
297
+ /**
298
+ Comparison function for sorting arbitrary values in ascending order using builtin comparison operators.
299
+ */
279
300
  sort_asc: (one: any, two: any) => 1 | -1 | 0
280
301
 
281
- /** Comparison function for sorting arbitrary values in descending order using builtin comparison operators.
282
- */
302
+ /**
303
+ Comparison function for sorting arbitrary values in descending order using builtin comparison operators.
304
+ */
283
305
  sort_desc: (one: any, two: any) => 1 | -1 | 0
284
306
 
285
307
  /** Comparison function for sorting numbers in ascending order. */
@@ -298,17 +320,20 @@ type Fullsec = Subscripts & PlayerFullsec & {
298
320
  security_level_names: [ "NULLSEC", "LOWSEC", "MIDSEC", "HIGHSEC", "FULLSEC" ]
299
321
 
300
322
  /** @returns The string name of a numeric security level. */
301
- get_security_level_name: (security_level: number) => any
302
-
303
- /** @param result The return value of a call to `$db.i()` or `$db.r()`.
304
- * @param nModified The expected value of `result.nModified`.
305
- * @returns Whether the database operation failed. */
306
- dbu_result_failed: (result: ReturnType<typeof $db.u | typeof $db.u1 | typeof $db.us>, nModified?: number) =>
307
- boolean
308
-
309
- /** @param result The return value of a call to `$db.i()` or `$db.r()`.
310
- * @param n The expected value of `result.n`.
311
- * @returns Whether the database operation failed. */
323
+ get_security_level_name: (security_level: number) => string
324
+
325
+ /**
326
+ * @param result The return value of a call to `$db.i()` or `$db.r()`.
327
+ * @param nModified The expected value of `result.nModified`.
328
+ * @returns Whether the database operation failed.
329
+ */
330
+ dbu_result_failed: (result: ReturnType<typeof $db.u | typeof $db.u1 | typeof $db.us>, nModified?: number) => boolean
331
+
332
+ /**
333
+ * @param result The return value of a call to `$db.i()` or `$db.r()`.
334
+ * @param n The expected value of `result.n`.
335
+ * @returns Whether the database operation failed.
336
+ */
312
337
  dbir_result_failed: (result: ReturnType<typeof $db.i | typeof $db.r>, n?: number) => boolean
313
338
 
314
339
  /** @returns A random string of length `length` using lowercase letters and numbers. */
@@ -320,19 +345,23 @@ type Fullsec = Subscripts & PlayerFullsec & {
320
345
  /** @returns The script half `y` of a fully-qualified script name `x.y`. */
321
346
  get_scriptname_from_script: (name: string) => string
322
347
 
323
- /** Determines whether to treat this run as a subscript, based either on the presence of `calling_script` in
324
- * `context`, or the explicit passing of `is_script: true` in `args`. */
348
+ /**
349
+ * Determines whether to treat this run as a subscript, based either on the presence of `calling_script` in
350
+ * `context`, or the explicit passing of `is_script: true` in `args`.
351
+ */
325
352
  is_script: (context: Context, args: any) => boolean
326
353
 
327
354
  /** @returns Whether the script is being called by its owner. */
328
355
  caller_is_owner: (context: Context) => boolean
329
356
 
330
- /** Removes consecutive duplicate elements from an array.
331
- * @example
332
- * const { uniq } = $fs.scripts.lib()
333
- * const arr = [ 1, 2, 2, 3, 2 ]
334
- *
335
- * $D(uniq(arr)) // [ 1, 2, 3, 2 ] */
357
+ /**
358
+ * Removes consecutive duplicate elements from an array.
359
+ * @example
360
+ * const { uniq } = $fs.scripts.lib()
361
+ * const arr = [ 1, 2, 2, 3, 2 ]
362
+ *
363
+ * $D(uniq(arr)) // [ 1, 2, 3, 2 ]
364
+ */
336
365
  uniq: <T>(array: T[]) => T[]
337
366
 
338
367
  /** Sorts an array of numbers or number-coercible strings in descending order. */
@@ -344,29 +373,35 @@ type Fullsec = Subscripts & PlayerFullsec & {
344
373
  /** Add characters from `pad_char` to the left of `input` until it reaches length `length`. */
345
374
  rjust: (input: string, length: number, pad_char?: string) => string
346
375
 
347
- /** @returns A string with the entries from `strings` split into evenly spaced columns, organized donward
348
- * and then rightward, to fit the current user's terminal. */
376
+ /**
377
+ * @returns A string with the entries from `strings` split into evenly spaced columns, organized donward
378
+ * and then rightward, to fit the current user's terminal.
379
+ */
349
380
  columnize: (strings: string[]) => string
350
381
 
351
- /** Takes two newline-separated strings and formats a new string where they appear in columns, separated by
352
- * `space`.
353
- * @example
354
- * const { side_by_side } = $fs.scripts.lib()
355
- * const str1 = "one\ntwo\nthree"
356
- * const str2 = "four\nfive\nsix"
357
- *
358
- * $D(side_by_side(str1, str2, "|"))
359
- * // one|four\n
360
- * // two|five\n
361
- * // three|six */
382
+ /**
383
+ * Takes two newline-separated strings and formats a new string where they appear in columns, separated by
384
+ * `space`.
385
+ * @example
386
+ * const { side_by_side } = $fs.scripts.lib()
387
+ * const str1 = "one\ntwo\nthree"
388
+ * const str2 = "four\nfive\nsix"
389
+ *
390
+ * $D(side_by_side(str1, str2, "|"))
391
+ * // one|four\n
392
+ * // two|five\n
393
+ * // three|six
394
+ */
362
395
  side_by_side: (str1: string, str2: string, space?: string) => string
363
396
 
364
397
  /** @returns Whether enough time remains in the script execution window to satisfy `time_left`. */
365
398
  can_continue_execution: (time_left: number) => boolean
366
399
 
367
- /** @returns A human-readable error object when not enough time remains in the script execution window to
368
- * satisfy `time_left`. */
369
- can_continue_execution_error: (time_left: number, name?: string) => { ok:false, msg: string }
400
+ /**
401
+ * @returns A human-readable error object when not enough time remains in the script execution window to
402
+ * satisfy `time_left`.
403
+ */
404
+ can_continue_execution_error: (time_left: number, name?: string) => { ok: false, msg: string }
370
405
 
371
406
  /** @returns Current date, equivalent to `new Date()`. */ get_date: () => Date
372
407
  /** @returns time since the epoch, equivalent to `Date.now()`. */ get_date_utcsecs: () => number
@@ -415,8 +450,7 @@ type Fullsec = Subscripts & PlayerFullsec & {
415
450
  }
416
451
 
417
452
  /** **FULLSEC** */
418
- xfer_upgrade_to_caller: (args: ({ i: number | number[] } | { sn: string | string[] }) & { memo?: string }) =>
419
- ScriptResponse
453
+ xfer_upgrade_to_caller: (args: ({ i: number | number[] } | { sn: string | string[] }) & { memo?: string }) => ScriptResponse
420
454
  }
421
455
 
422
456
  users: {
@@ -433,19 +467,23 @@ type Fullsec = Subscripts & PlayerFullsec & {
433
467
 
434
468
  type Highsec = Fullsec & PlayerHighsec & {
435
469
  accts: {
436
- /** **HIGHSEC**
437
- * @returns GC balance as number if `is_script` is true (default).
438
- * @returns GC balance as string if `is_script` is false. */
470
+ /**
471
+ * **HIGHSEC**
472
+ * @returns GC balance as number if `is_script` is true (default).
473
+ * @returns GC balance as string if `is_script` is false.
474
+ */
439
475
  balance: {
440
476
  (args?: { is_script?: true }): number
441
477
  (args: { is_script: false }): string
442
478
  }
443
479
 
444
- /** **HIGHSEC**
480
+ /**
481
+ * **HIGHSEC**
445
482
  * @returns Transaction history according to filter.
446
483
  * @returns If `is_script` is true (default), time property as Date object.
447
484
  * @returns Wraps transactions in object with msg, time property as string (game date format e.g. 201028.2147)
448
- * if `is_script` is false. */
485
+ * if `is_script` is false.
486
+ */
449
487
  transactions: {
450
488
  (args?: { count?: number | "all", to?: string, from?: string, script?: string, is_script?: true }): {
451
489
  time: Date
@@ -502,16 +540,14 @@ type Highsec = Fullsec & PlayerHighsec & {
502
540
  Record<string, null | boolean | number | string>
503
541
  )[] | ScriptFailure
504
542
 
505
- <F extends Partial<Upgrade & { loaded: boolean }> = object>(args?:
506
- { filter?: F, is_script?: true, full: true }
507
- ): (Omit<UpgradeBase, keyof F> & F & Record<string, null | boolean | number | string>)[] | ScriptFailure
543
+ <F extends Partial<Upgrade & { loaded: boolean }> = object>(args?: { filter?: F, is_script?: true, full: true }): (Omit<UpgradeBase, keyof F> & F & Record<string, null | boolean | number | string>)[] | ScriptFailure
508
544
 
509
545
  (args?: { filter?: Partial<Upgrade & { loaded: boolean }>, is_script: false, full?: false }):
510
546
  { msg: string, upgrades: string[] } | ScriptFailure
511
547
 
512
548
  <F extends Partial<Upgrade & { loaded: boolean }> = object>(
513
549
  args?: { filter?: F, is_script: false, full: true }
514
- ): (Omit<UpgradeBase, keyof F | `rarity`> & F & {
550
+ ): (Omit<UpgradeBase, keyof F | "rarity"> & F & {
515
551
  [x: string]: null | boolean | number | string
516
552
  rarity: UpgradeRarityString
517
553
  })[] | ScriptFailure
@@ -623,8 +659,7 @@ type Nullsec = Lowsec & PlayerNullsec & {
623
659
  /** **NULLSEC** */ manage: {
624
660
  (args: { command: "list" }): { name: string, is_admin: boolean }[] | ScriptFailure
625
661
 
626
- (args: { command: "demote" | "promote", name: string } | { command: "fire", name: string, confirm: true }):
627
- ScriptResponse
662
+ (args: { command: "demote" | "promote", name: string } | { command: "fire", name: string, confirm: true }): ScriptResponse
628
663
  }
629
664
 
630
665
  /** **NULLSEC** */ offers: {
@@ -699,7 +734,7 @@ type Nullsec = Lowsec & PlayerNullsec & {
699
734
  // database
700
735
  type MongoPrimitive = null | boolean | number | Date | string
701
736
  type MongoValue = MongoPrimitive | MongoValue[] | MongoObject
702
- type MongoObject = { [k: string]: MongoValue, [k: `$${string}`]: never }
737
+ type MongoObject = { [k: string]: MongoValue }
703
738
  type MongoQueryValue = MongoPrimitive | MongoQueryValue[] | MongoQueryObject
704
739
 
705
740
  type MongoQueryObject =
@@ -755,11 +790,16 @@ type MongoQuerySelector<T extends MongoValue> = Partial<
755
790
 
756
791
  type MongoQuery<T extends MongoObject> = { [K in keyof T]?: T[K] | MongoQuerySelector<T[K]> } & { _id?: MongoId }
757
792
 
758
- type MongoUpdateOperators<T extends MongoObject> = Partial<{
793
+ type MongoUpdateArrayOperatorUniversalModifiers<T> = { $each?: T extends [] ? T : T[] }
794
+
795
+ type MongoUpdateArrayOperatorModifiers<T> = MongoUpdateArrayOperatorUniversalModifiers<T> &
796
+ { $position?: number, $slice?: number, $sort?: 1 | -1 }
797
+
798
+ type MongoUpdateCommand<T extends MongoObject> = Partial<{
759
799
  /* Universal operators */
760
- $set: Partial<Record<string, MongoCommandValue> & T>
761
- $setOnInsert: Partial<Record<string, MongoCommandValue> & T>
762
- $unset: Partial<Record<string, ""> & T>
800
+ $set: Partial<Record<(string & {}) | keyof T, MongoCommandValue>>
801
+ $setOnInsert: Partial<Record<(string & {}) | keyof T, MongoCommandValue>>
802
+ $unset: Partial<Record<(string & {}) | keyof T, "">>
763
803
 
764
804
  $rename: Partial<Record<string, string> & { [key in keyof T]: string }>
765
805
 
@@ -792,13 +832,6 @@ type MongoUpdateOperators<T extends MongoObject> = Partial<{
792
832
  $pullAll: Record<string, MongoCommandValue> & { [K in keyof T as T[K] extends [] ? K : never]?: T[K] }
793
833
  }>
794
834
 
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>
801
-
802
835
  type SortOrder = { [key: string]: 1 | -1 | SortOrder }
803
836
 
804
837
  type Cursor<T> = {
@@ -818,17 +851,23 @@ type Cursor<T> = {
818
851
  /** Run `callback` on each document that satisfied the query. */
819
852
  each: (callback: (document: T) => void) => null
820
853
 
821
- /** Returns a new cursor with documents sorted as specified.
822
- * A value of 1 sorts the property ascending, and -1 descending.
823
- * @param order The way the documents are to be sorted. */
854
+ /**
855
+ * Returns a new cursor with documents sorted as specified.
856
+ * A value of 1 sorts the property ascending, and -1 descending.
857
+ * @param order The way the documents are to be sorted.
858
+ */
824
859
  sort: (order?: SortOrder) => Cursor<T>
825
860
 
826
- /** Returns a new cursor without the first number of documents.
827
- * @param count Number of documents to skip. */
861
+ /**
862
+ * Returns a new cursor without the first number of documents.
863
+ * @param count Number of documents to skip.
864
+ */
828
865
  skip: (count: number) => Cursor<T>
829
866
 
830
- /** Returns a new cursor limited to a number of documents as specified.
831
- * @param count Number of documents. */
867
+ /**
868
+ * Returns a new cursor limited to a number of documents as specified.
869
+ * @param count Number of documents.
870
+ */
832
871
  limit: (count: number) => Cursor<T>
833
872
 
834
873
  /** @param key The key of the documents. */ distinct: { (key: string): MongoValue[], (key: "_id"): MongoId[] }
@@ -844,8 +883,10 @@ type CliContext = {
844
883
  /** The number of columns in the caller’s terminal. */ cols: number
845
884
  /** The number of rows in the caller’s terminal. */ rows: number
846
885
 
847
- /** The name of the script that directly called this script, or null if called on the command line or as a
848
- * scriptor. */
886
+ /**
887
+ * The name of the script that directly called this script, or null if called on the command line or as a
888
+ * scriptor.
889
+ */
849
890
  calling_script: null
850
891
 
851
892
  is_scriptor?: undefined
@@ -853,8 +894,9 @@ type CliContext = {
853
894
  }
854
895
 
855
896
  type SubscriptContext = Replace<CliContext, {
856
- /** The name of the script that directly called this script, or null if called on the command line or as a scriptor.
857
- */
897
+ /**
898
+ The name of the script that directly called this script, or null if called on the command line or as a scriptor.
899
+ */
858
900
  calling_script: string
859
901
  }>
860
902
 
@@ -868,13 +910,13 @@ type MongoProject<TDocument, TProjection> =
868
910
  (TProjection extends { _id: false | 0 } ? {} : { _id: TDocument extends { _id: infer TId } ? TId : MongoId }) & (
869
911
  true extends (1 extends TProjection[keyof TProjection] ? true : TProjection[keyof TProjection]) ?
870
912
  {
871
- [K in
872
- keyof TDocument as K extends keyof TProjection ? TProjection[K] extends true | 1 ? K : never : never
913
+ [K in keyof TDocument as K extends
914
+ keyof TProjection ? TProjection[K] extends true | 1 ? K : never : never
873
915
  ]: TDocument[K]
874
916
  } &
875
917
  {
876
- -readonly [K in
877
- keyof TProjection as TProjection[K] extends true | 1 ? K extends keyof TDocument ? never : K : never
918
+ -readonly [K in keyof TProjection as TProjection[K] extends
919
+ true | 1 ? K extends keyof TDocument ? never : K : never
878
920
  ]?: MongoValue
879
921
  }
880
922
  : { [k: string]: MongoValue } & { [K in keyof TDocument as K extends keyof TProjection ? never : K]: TDocument[K] }
@@ -890,192 +932,205 @@ declare global {
890
932
  type Context = CliContext | SubscriptContext | ScriptorContext | BrainContext
891
933
  type MongoObjectId = { $oid: string }
892
934
 
935
+ /* eslint-disable ts/consistent-type-definitions */
893
936
  interface PlayerFullsec {}
894
937
  interface PlayerHighsec {}
895
938
  interface PlayerMidsec {}
896
939
  interface PlayerLowsec {}
897
940
  interface PlayerNullsec {}
941
+ /* eslint-enable ts/consistent-type-definitions */
898
942
 
899
943
  /** Subscript space that can call FULLSEC scripts. */ const $fs: Fullsec
900
-
901
944
  /** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
902
945
  const $hs: Highsec
903
-
904
- /** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
905
- */
946
+ /**
947
+ Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
948
+ */
906
949
  const $ms: Midsec
907
-
908
- /** Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
909
- */
950
+ /**
951
+ Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
952
+ */
910
953
  const $ls: Lowsec
911
-
912
954
  /** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
913
955
  const $ns: Nullsec
914
-
915
956
  /** Subscript space that can call FULLSEC scripts. */ const $4s: typeof $fs
916
-
917
957
  /** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
918
958
  const $3s: typeof $hs
919
-
920
- /** Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
921
- */
959
+ /**
960
+ Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
961
+ */
922
962
  const $2s: typeof $ms
923
-
924
- /** Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
925
- */
963
+ /**
964
+ Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
965
+ */
926
966
  const $1s: typeof $ls
927
-
928
967
  /** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
929
968
  const $0s: typeof $ns
930
-
931
- /** Subscript space that can call any script. Uses seclevel provided in comment before script (defaults to NULLSEC)
932
- * @example
933
- * // @​seclevel MIDSEC
934
- * // note, do NOT copy paste the above line because there is a zero-width space inserted between "@" and "s"
935
- * export function script() {
936
- * $s.foo.bar() // will be converted to #ms.foo.bar()
937
- * } */
969
+ /* eslint-disable no-irregular-whitespace */
970
+ /**
971
+ * Subscript space that can call any script. Uses seclevel provided in comment before script (defaults to NULLSEC)
972
+ * @example
973
+ * // @​seclevel MIDSEC
974
+ * // note, do NOT copy paste the above line because there is a zero-width space inserted between "@" and "s"
975
+ * export function script() {
976
+ * $s.foo.bar() // will be converted to #ms.foo.bar()
977
+ * }
978
+ */
938
979
  const $s: Nullsec
980
+ /* eslint-enable no-irregular-whitespace */
939
981
 
940
982
  const $db: {
941
- /** Insert a document or documents into a collection.
942
- * @param documents A document or array of documents to insert into the collection. */
943
- i: <T extends MongoDocument>(documents: (T & { _id?: MongoId }) | (T & { _id?: MongoId })[]) =>
944
- { n: number, opTime: { t: number }, ok: 0 | 1 }[]
945
-
946
- /** Remove documents from a collection.
947
- * @param query Specifies deletion criteria using query operators. */
983
+ /**
984
+ * Insert a document or documents into a collection.
985
+ * @param documents A document or array of documents to insert into the collection.
986
+ */
987
+ i: <T extends MongoDocument>(documents: (T & { _id?: MongoId }) | (T & { _id?: MongoId })[]) => { n: number, opTime: { t: number }, ok: 0 | 1 }[]
988
+
989
+ /**
990
+ * Remove documents from a collection.
991
+ * @param query Specifies deletion criteria using query operators.
992
+ */
948
993
  r: <T extends MongoDocument>(query: MongoQuery<T>) => { n: number, opTime: { t: number }, ok: 0 | 1 }[]
949
994
 
950
- /** Find documents in a collection or view and returns a cursor to the selected documents.
951
- * @param query Specifies deletion criteria using query operators.
952
- * @param projection Specifies the fields to return in the documents that match the query filter. */
995
+ /**
996
+ * Find documents in a collection or view and returns a cursor to the selected documents.
997
+ * @param query Specifies deletion criteria using query operators.
998
+ * @param projection Specifies the fields to return in the documents that match the query filter.
999
+ */
953
1000
  f: <
954
1001
  const TQuery extends MongoQueryObject & { _id?: MongoQueryId },
955
1002
  const TProjection extends { [k: string]: boolean | 0 | 1 } = {}
956
1003
  >(query: TQuery, projection?: TProjection) => Cursor<MongoProject<MongoQueryType<TQuery>, TProjection>>
957
1004
 
958
- /** Update existing documents in a collection.
959
- * @param query Specifies deletion criteria using query operators.
960
- * @param command The modifications to apply.
961
- * {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
962
- u: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) =>
963
- { n: number, opTime: { t: number }, ok: 0 | 1, nModified: number }[]
964
-
965
- /** Updates one document within the collection based on the filter.
966
- * @param query Specifies deletion criteria using query operators.
967
- * @param command The modifications to apply.
968
- * {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
969
- u1: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) =>
970
- { n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
971
-
972
- /** Update or insert document.
973
- * Same as Update, but if no documents match the query, one document will be inserted based on the properties in
974
- * both the query and the command.
975
- * The `$setOnInsert` operator is useful to set defaults.
976
- * @param query Specifies deletion criteria using query operators.
977
- * @param command The modifications to apply.
978
- * {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters} */
979
- us: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) =>
980
- { n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
1005
+ /**
1006
+ * Update existing documents in a collection.
1007
+ * @param query Specifies deletion criteria using query operators.
1008
+ * @param command The modifications to apply.
1009
+ * {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters}
1010
+ */
1011
+ u: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) => { n: number, opTime: { t: number }, ok: 0 | 1, nModified: number }[]
1012
+
1013
+ /**
1014
+ * Updates one document within the collection based on the filter.
1015
+ * @param query Specifies deletion criteria using query operators.
1016
+ * @param command The modifications to apply.
1017
+ * {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters}
1018
+ */
1019
+ u1: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) => { n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
1020
+
1021
+ /**
1022
+ * Update or insert document.
1023
+ * Same as Update, but if no documents match the query, one document will be inserted based on the properties in
1024
+ * both the query and the command.
1025
+ * The `$setOnInsert` operator is useful to set defaults.
1026
+ * @param query Specifies deletion criteria using query operators.
1027
+ * @param command The modifications to apply.
1028
+ * {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters}
1029
+ */
1030
+ us: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) => { n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
981
1031
 
982
1032
  ObjectId: () => MongoObjectId
983
1033
  }
984
1034
 
985
- /** Debug Log.
986
- *
987
- * If `$D()` is called in a script you own, the `return` value of the top level script is suppressed and instead an
988
- * array of every `$D()`’d entry is printed.
989
- * This lets you use `$D()` like `console.log()`.
990
- *
991
- * `$D()` in scripts not owned by you are not shown but the `return` value always is.
992
- *
993
- * `$D()` returns the first argument so `$D("Hello, World!") evaluates to `"Hello, World!"` as if the `$D` text wasn't
994
- * there.
995
- *
996
- * `$D()`’d items are returned even if the script times out or errors. */
1035
+ /**
1036
+ * Debug Log.
1037
+ *
1038
+ * If `$D()` is called in a script you own, the `return` value of the top level script is suppressed and instead an
1039
+ * array of every `$D()`’d entry is printed.
1040
+ * This lets you use `$D()` like `console.log()`.
1041
+ *
1042
+ * `$D()` in scripts not owned by you are not shown but the `return` value always is.
1043
+ *
1044
+ * `$D()` returns the first argument so `$D("Hello, World!") evaluates to `"Hello, World!"` as if the `$D` text wasn't
1045
+ * there.
1046
+ *
1047
+ * `$D()`’d items are returned even if the script times out or errors.
1048
+ */
997
1049
  function $D<T>(args: T): T
998
1050
 
999
- /** Function Multi-Call Lock.
1000
- *
1001
- * This is used by escrow to ensure that it is only used once in script execution.
1002
- *
1003
- * The first time (per-script) `$FMCL` is encountered, it returns `undefined`, every other time it `return`s `true`.
1004
- *
1005
- * @example
1006
- * if ($FMCL)
1007
- * return { ok: false, msg: "This script can only be used once per script execution." }
1008
- *
1009
- * // all code here will only run once */
1051
+ /**
1052
+ * Function Multi-Call Lock.
1053
+ *
1054
+ * This is used by escrow to ensure that it is only used once in script execution.
1055
+ *
1056
+ * The first time (per-script) `$FMCL` is encountered, it returns `undefined`, every other time it `return`s `true`.
1057
+ *
1058
+ * @example
1059
+ * if ($FMCL)
1060
+ * return { ok: false, msg: "This script can only be used once per script execution." }
1061
+ *
1062
+ * // all code here will only run once
1063
+ */
1010
1064
  const $FMCL: undefined | true
1011
-
1012
- /** Per-script mutable "global" persistent object that is discarded at the end of top level script execution.
1013
- *
1014
- * `$G` persists between script calls until the end of the main script run making it useful for caching db entries when
1015
- * your script is a subscript.
1016
- * @example
1017
- * if (!$G.dbCache)
1018
- * $G.dbCache = $db.f({ whatever: true }).first() */
1065
+ /**
1066
+ * Per-script mutable "global" persistent object that is discarded at the end of top level script execution.
1067
+ *
1068
+ * `$G` persists between script calls until the end of the main script run making it useful for caching db entries when
1069
+ * your script is a subscript.
1070
+ * @example
1071
+ * if (!$G.dbCache)
1072
+ * $G.dbCache = $db.f({ whatever: true }).first()
1073
+ */
1019
1074
  const $G: Record<string | symbol, any>
1020
-
1021
- /** This contains a JS timestamp (not Date) set immediately before your code begins running.
1022
- * @example
1023
- * $D(Date.now() - _START) // milliseconds left of run time
1024
- */
1075
+ /**
1076
+ * This contains a JS timestamp (not Date) set immediately before your code begins running.
1077
+ * @example
1078
+ * $D(Date.now() - _START) // milliseconds left of run time
1079
+ */
1025
1080
  const _START: number
1026
-
1027
- /** This contains a JS timestamp (not Date) set immediately before your code begins running.
1028
- * @example
1029
- * $D(Date.now() - _ST) // milliseconds left of run time */
1081
+ /**
1082
+ * This contains a JS timestamp (not Date) set immediately before your code begins running.
1083
+ * @example
1084
+ * $D(Date.now() - _ST) // milliseconds left of run time
1085
+ */
1030
1086
  const _ST: typeof _START
1031
-
1032
1087
  /** JavaScript timestamp for the end of the script run (`_START + _TIMEOUT`). */ const _END: number
1033
-
1034
1088
  /** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
1035
1089
  const _TIMEOUT: number
1036
-
1037
1090
  /** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
1038
1091
  const _TO: typeof _TIMEOUT
1039
-
1040
1092
  /** The source code of this script as a string. */ const _SOURCE: string
1041
1093
  /** A unix timestamp of the date this script was built. */ const _BUILD_DATE: number
1042
-
1043
- /** The user this script has been uploaded to.
1044
- *
1045
- * Shorter alternative to `context.this_script.split(".")[0].
1046
- *
1047
- * In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
1094
+ /**
1095
+ * The user this script has been uploaded to.
1096
+ *
1097
+ * Shorter alternative to `context.this_script.split(".")[0].
1098
+ *
1099
+ * In rare cases where it's not known at build time, it's `"UNKNOWN"`.
1100
+ */
1048
1101
  const _SCRIPT_USER: string
1049
-
1050
1102
  /** @deprecated Use `_SCRIPT_SUBNAME` instead. */
1051
1103
  const _SCRIPT_NAME: string
1052
-
1053
- /** The name of this script excluding the user and `.`.
1054
- *
1055
- * e.g. in the script `foo.bar`, `_SCRIPT_NAME` is `bar`.
1056
- *
1057
- * Shorter alternative to `context.this_script.split(".")[1].
1058
- *
1059
- * In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
1104
+ /**
1105
+ * The name of this script excluding the user and `.`.
1106
+ *
1107
+ * e.g. in the script `foo.bar`, `_SCRIPT_NAME` is `bar`.
1108
+ *
1109
+ * Shorter alternative to `context.this_script.split(".")[1].
1110
+ *
1111
+ * In rare cases where it's not known at build time, it's `"UNKNOWN"`.
1112
+ */
1060
1113
  const _SCRIPT_SUBNAME: string
1061
-
1062
- /** The full name of this script equivilent to `context.this_script` but should use less characters.
1063
- *
1064
- * In rare cases where it's not known at build time, it's `"UNKNOWN"`. */
1114
+ /**
1115
+ * The full name of this script equivilent to `context.this_script` but should use less characters.
1116
+ *
1117
+ * In rare cases where it's not known at build time, it's `"UNKNOWN"`.
1118
+ */
1065
1119
  const _FULL_SCRIPT_NAME: string
1066
-
1067
- /** The seclevel of this script as a number.
1068
- *
1069
- * In rare cases where it's not known at build time, it's `-1`. */
1120
+ /**
1121
+ * The seclevel of this script as a number.
1122
+ *
1123
+ * In rare cases where it's not known at build time, it's `-1`.
1124
+ */
1070
1125
  const _SECLEVEL: -1 | 0 | 1 | 2 | 3 | 4
1071
-
1072
- /** Recursively
1073
- * [`Object.freeze()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
1074
- * an object and its properties' objects and its properties' objects and so on.
1075
- *
1076
- * [Official Hackmud Wiki](https://wiki.hackmud.com/scripting/extensions/deep_freeze) */
1126
+ /**
1127
+ * Recursively
1128
+ * [`Object.freeze()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
1129
+ * an object and its properties' objects and its properties' objects and so on.
1130
+ *
1131
+ * [Official Hackmud Wiki](https://wiki.hackmud.com/scripting/extensions/deep_freeze)
1132
+ */
1077
1133
  const DEEP_FREEZE: <T>(value: T) => DeepFreeze<T>
1078
-
1079
1134
  const _RUN_ID: string
1080
1135
  }
1081
1136