hackmud-script-manager 0.21.1-ea9322a → 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/README.md +46 -38
- package/bin/hsm.js +252 -246
- package/env.d.ts +301 -244
- package/generateTypeDeclaration.js +24 -23
- package/index.js +2 -3
- package/package.json +26 -25
- package/processScript/index.d.ts +12 -9
- package/processScript/index.js +95 -73
- package/processScript/minify.d.ts +11 -8
- package/processScript/minify.js +10 -10
- package/processScript/preprocess.d.ts +4 -2
- package/processScript/preprocess.js +7 -7
- package/processScript/transform.d.ts +8 -6
- package/processScript/transform.js +102 -23
- package/pull.d.ts +6 -4
- package/pull.js +1 -1
- package/push.d.ts +23 -18
- package/push.js +6 -6
- package/syncMacros.js +14 -15
- package/watch.d.ts +11 -7
- package/watch.js +6 -7
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,
|
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
|
-
/**
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
-
/**
|
95
|
-
|
96
|
-
|
97
|
-
|
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
|
-
/**
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|
-
/**
|
172
|
-
|
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
|
-
/**
|
183
|
-
|
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
|
-
/**
|
187
|
-
|
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
|
-
/**
|
191
|
-
|
192
|
-
|
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
|
-
/**
|
243
|
-
|
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
|
-
/**
|
253
|
-
|
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,8 +283,10 @@ 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
|
-
/**
|
269
|
-
|
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`. */
|
@@ -274,12 +294,14 @@ type Fullsec = Subscripts & PlayerFullsec & {
|
|
274
294
|
|
275
295
|
/** @returns An array with the elements from `array` in a random order. */ shuffle: <T>(array: T[]) => T[]
|
276
296
|
|
277
|
-
/**
|
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
|
-
/**
|
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. */
|
@@ -300,15 +322,18 @@ type Fullsec = Subscripts & PlayerFullsec & {
|
|
300
322
|
/** @returns The string name of a numeric security level. */
|
301
323
|
get_security_level_name: (security_level: number) => string
|
302
324
|
|
303
|
-
/**
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
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
|
-
/**
|
324
|
-
|
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
|
-
/**
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
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
|
-
/**
|
348
|
-
|
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
|
-
/**
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
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
|
-
/**
|
368
|
-
|
369
|
-
|
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
|
-
/**
|
437
|
-
|
438
|
-
|
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
|
-
/**
|
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 |
|
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: {
|
@@ -816,17 +851,23 @@ type Cursor<T> = {
|
|
816
851
|
/** Run `callback` on each document that satisfied the query. */
|
817
852
|
each: (callback: (document: T) => void) => null
|
818
853
|
|
819
|
-
/**
|
820
|
-
|
821
|
-
|
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
|
+
*/
|
822
859
|
sort: (order?: SortOrder) => Cursor<T>
|
823
860
|
|
824
|
-
/**
|
825
|
-
|
861
|
+
/**
|
862
|
+
* Returns a new cursor without the first number of documents.
|
863
|
+
* @param count Number of documents to skip.
|
864
|
+
*/
|
826
865
|
skip: (count: number) => Cursor<T>
|
827
866
|
|
828
|
-
/**
|
829
|
-
|
867
|
+
/**
|
868
|
+
* Returns a new cursor limited to a number of documents as specified.
|
869
|
+
* @param count Number of documents.
|
870
|
+
*/
|
830
871
|
limit: (count: number) => Cursor<T>
|
831
872
|
|
832
873
|
/** @param key The key of the documents. */ distinct: { (key: string): MongoValue[], (key: "_id"): MongoId[] }
|
@@ -842,8 +883,10 @@ type CliContext = {
|
|
842
883
|
/** The number of columns in the caller’s terminal. */ cols: number
|
843
884
|
/** The number of rows in the caller’s terminal. */ rows: number
|
844
885
|
|
845
|
-
/**
|
846
|
-
|
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
|
+
*/
|
847
890
|
calling_script: null
|
848
891
|
|
849
892
|
is_scriptor?: undefined
|
@@ -851,8 +894,9 @@ type CliContext = {
|
|
851
894
|
}
|
852
895
|
|
853
896
|
type SubscriptContext = Replace<CliContext, {
|
854
|
-
/**
|
855
|
-
|
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
|
+
*/
|
856
900
|
calling_script: string
|
857
901
|
}>
|
858
902
|
|
@@ -866,13 +910,13 @@ type MongoProject<TDocument, TProjection> =
|
|
866
910
|
(TProjection extends { _id: false | 0 } ? {} : { _id: TDocument extends { _id: infer TId } ? TId : MongoId }) & (
|
867
911
|
true extends (1 extends TProjection[keyof TProjection] ? true : TProjection[keyof TProjection]) ?
|
868
912
|
{
|
869
|
-
[K in
|
870
|
-
keyof
|
913
|
+
[K in keyof TDocument as K extends
|
914
|
+
keyof TProjection ? TProjection[K] extends true | 1 ? K : never : never
|
871
915
|
]: TDocument[K]
|
872
916
|
} &
|
873
917
|
{
|
874
|
-
-readonly [K in
|
875
|
-
|
918
|
+
-readonly [K in keyof TProjection as TProjection[K] extends
|
919
|
+
true | 1 ? K extends keyof TDocument ? never : K : never
|
876
920
|
]?: MongoValue
|
877
921
|
}
|
878
922
|
: { [k: string]: MongoValue } & { [K in keyof TDocument as K extends keyof TProjection ? never : K]: TDocument[K] }
|
@@ -888,192 +932,205 @@ declare global {
|
|
888
932
|
type Context = CliContext | SubscriptContext | ScriptorContext | BrainContext
|
889
933
|
type MongoObjectId = { $oid: string }
|
890
934
|
|
935
|
+
/* eslint-disable ts/consistent-type-definitions */
|
891
936
|
interface PlayerFullsec {}
|
892
937
|
interface PlayerHighsec {}
|
893
938
|
interface PlayerMidsec {}
|
894
939
|
interface PlayerLowsec {}
|
895
940
|
interface PlayerNullsec {}
|
941
|
+
/* eslint-enable ts/consistent-type-definitions */
|
896
942
|
|
897
943
|
/** Subscript space that can call FULLSEC scripts. */ const $fs: Fullsec
|
898
|
-
|
899
944
|
/** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
|
900
945
|
const $hs: Highsec
|
901
|
-
|
902
|
-
|
903
|
-
|
946
|
+
/**
|
947
|
+
Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
|
948
|
+
*/
|
904
949
|
const $ms: Midsec
|
905
|
-
|
906
|
-
|
907
|
-
|
950
|
+
/**
|
951
|
+
Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
|
952
|
+
*/
|
908
953
|
const $ls: Lowsec
|
909
|
-
|
910
954
|
/** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
|
911
955
|
const $ns: Nullsec
|
912
|
-
|
913
956
|
/** Subscript space that can call FULLSEC scripts. */ const $4s: typeof $fs
|
914
|
-
|
915
957
|
/** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
|
916
958
|
const $3s: typeof $hs
|
917
|
-
|
918
|
-
|
919
|
-
|
959
|
+
/**
|
960
|
+
Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
|
961
|
+
*/
|
920
962
|
const $2s: typeof $ms
|
921
|
-
|
922
|
-
|
923
|
-
|
963
|
+
/**
|
964
|
+
Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
|
965
|
+
*/
|
924
966
|
const $1s: typeof $ls
|
925
|
-
|
926
967
|
/** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
|
927
968
|
const $0s: typeof $ns
|
928
|
-
|
929
|
-
/**
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
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
|
+
*/
|
936
979
|
const $s: Nullsec
|
980
|
+
/* eslint-enable no-irregular-whitespace */
|
937
981
|
|
938
982
|
const $db: {
|
939
|
-
/**
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
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
|
+
*/
|
946
993
|
r: <T extends MongoDocument>(query: MongoQuery<T>) => { n: number, opTime: { t: number }, ok: 0 | 1 }[]
|
947
994
|
|
948
|
-
/**
|
949
|
-
|
950
|
-
|
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
|
+
*/
|
951
1000
|
f: <
|
952
1001
|
const TQuery extends MongoQueryObject & { _id?: MongoQueryId },
|
953
1002
|
const TProjection extends { [k: string]: boolean | 0 | 1 } = {}
|
954
1003
|
>(query: TQuery, projection?: TProjection) => Cursor<MongoProject<MongoQueryType<TQuery>, TProjection>>
|
955
1004
|
|
956
|
-
/**
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
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 }[]
|
979
1031
|
|
980
1032
|
ObjectId: () => MongoObjectId
|
981
1033
|
}
|
982
1034
|
|
983
|
-
/**
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
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
|
+
*/
|
995
1049
|
function $D<T>(args: T): T
|
996
1050
|
|
997
|
-
/**
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
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
|
+
*/
|
1008
1064
|
const $FMCL: undefined | true
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
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
|
+
*/
|
1017
1074
|
const $G: Record<string | symbol, any>
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
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
|
+
*/
|
1023
1080
|
const _START: number
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
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
|
+
*/
|
1028
1086
|
const _ST: typeof _START
|
1029
|
-
|
1030
1087
|
/** JavaScript timestamp for the end of the script run (`_START + _TIMEOUT`). */ const _END: number
|
1031
|
-
|
1032
1088
|
/** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
|
1033
1089
|
const _TIMEOUT: number
|
1034
|
-
|
1035
1090
|
/** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
|
1036
1091
|
const _TO: typeof _TIMEOUT
|
1037
|
-
|
1038
1092
|
/** The source code of this script as a string. */ const _SOURCE: string
|
1039
1093
|
/** A unix timestamp of the date this script was built. */ const _BUILD_DATE: number
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
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
|
+
*/
|
1046
1101
|
const _SCRIPT_USER: string
|
1047
|
-
|
1048
1102
|
/** @deprecated Use `_SCRIPT_SUBNAME` instead. */
|
1049
1103
|
const _SCRIPT_NAME: string
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
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
|
+
*/
|
1058
1113
|
const _SCRIPT_SUBNAME: string
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
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
|
+
*/
|
1063
1119
|
const _FULL_SCRIPT_NAME: string
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
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
|
+
*/
|
1068
1125
|
const _SECLEVEL: -1 | 0 | 1 | 2 | 3 | 4
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
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
|
+
*/
|
1075
1133
|
const DEEP_FREEZE: <T>(value: T) => DeepFreeze<T>
|
1076
|
-
|
1077
1134
|
const _RUN_ID: string
|
1078
1135
|
}
|
1079
1136
|
|