hackmud-script-manager-ng 0.0.0-stage → 0.26.4
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/.envrc +1 -0
- package/.github/FUNDING.yml +14 -0
- package/.github/workflows/publish.yml +27 -0
- package/.github/workflows/test.yml +18 -0
- package/.vscode/settings.json +55 -0
- package/CONTRIBUTING.md +68 -0
- package/LICENSE +21 -0
- package/README.md +86 -2
- package/env.d.ts +1305 -0
- package/eslint.config.js +81 -0
- package/game-scripts-tests/array-rest-works.ts +6 -0
- package/game-scripts-tests/this_array_in_object.ts +16 -0
- package/game-scripts-tests/this_function_array.ts +9 -0
- package/game-scripts-tests/this_in_default_argument.ts +35 -0
- package/game-scripts-tests/this_in_lambda_in_object.ts +26 -0
- package/package.json +110 -3
- package/pnpm-workspace.yaml +2 -0
- package/rollup.config.js +69 -0
- package/scripts/dev.sh +3 -0
- package/scripts/emit-declarations.sh +3 -0
- package/scripts/emit-package-json.js +9 -0
- package/scripts/lint.sh +5 -0
- package/scripts/package.sh +7 -0
- package/scripts/update.sh +4 -0
- package/scripts/version-dev.js +14 -0
- package/src/bin/hsm.ts +754 -0
- package/src/constants.ts +2 -0
- package/src/env.d.ts +13 -0
- package/src/generateTypeDeclaration.ts +119 -0
- package/src/index.ts +13 -0
- package/src/processScript/__snapshots__/index.ts.snap +8 -0
- package/src/processScript/index.ts +474 -0
- package/src/processScript/minify.ts +594 -0
- package/src/processScript/postprocess.ts +19 -0
- package/src/processScript/preprocess.ts +130 -0
- package/src/processScript/shared.ts +33 -0
- package/src/processScript/transform.ts +978 -0
- package/src/pull.ts +20 -0
- package/src/push.ts +200 -0
- package/src/syncMacros.ts +53 -0
- package/src/tsconfig.json +14 -0
- package/src/watch.ts +258 -0
- package/tsconfig.json +23 -0
- package/vitest.config.ts +19 -0
package/env.d.ts
ADDED
|
@@ -0,0 +1,1305 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/no-multi-asterisks, ts/no-empty-object-type */
|
|
2
|
+
/* eslint style/quotes: [ "warn", "double" ], */
|
|
3
|
+
type Replace<A, B> = Omit<A, keyof B> & B
|
|
4
|
+
type ErrorScripts = Record<string, () => ScriptFailure>
|
|
5
|
+
|
|
6
|
+
type Subscripts = Record<string, Record<string, (...args: any) => any>> & {
|
|
7
|
+
accts: ErrorScripts
|
|
8
|
+
autos: ErrorScripts
|
|
9
|
+
bbs: ErrorScripts
|
|
10
|
+
chats: ErrorScripts
|
|
11
|
+
corps: ErrorScripts
|
|
12
|
+
escrow: ErrorScripts
|
|
13
|
+
gui: ErrorScripts
|
|
14
|
+
kernel: ErrorScripts
|
|
15
|
+
market: ErrorScripts
|
|
16
|
+
marks: ErrorScripts
|
|
17
|
+
scripts: ErrorScripts
|
|
18
|
+
sys: ErrorScripts
|
|
19
|
+
trust: ErrorScripts
|
|
20
|
+
users: ErrorScripts
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type Fullsec = Subscripts & PlayerFullsec & {
|
|
24
|
+
accts: {
|
|
25
|
+
/** **FULLSEC** @returns GC balance of script owner. */ balance_of_owner: () => number
|
|
26
|
+
|
|
27
|
+
/** **FULLSEC** */
|
|
28
|
+
xfer_gc_to_caller: (args: { amount: number | string, memo?: string | undefined }) => ScriptResponse
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
bbs: {
|
|
32
|
+
read: () => {
|
|
33
|
+
boards: { title: string, slug: string }[]
|
|
34
|
+
|
|
35
|
+
posts: {
|
|
36
|
+
vote_count: number
|
|
37
|
+
short_id: string
|
|
38
|
+
is_sticky: boolean
|
|
39
|
+
is_locked: boolean
|
|
40
|
+
is_archived: boolean
|
|
41
|
+
is_answered: boolean
|
|
42
|
+
is_implemented: boolean
|
|
43
|
+
title: string
|
|
44
|
+
slug: string
|
|
45
|
+
vote: boolean
|
|
46
|
+
username: string
|
|
47
|
+
time: string
|
|
48
|
+
}[]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
r: Fullsec["bbs"]["read"]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
chats: {
|
|
55
|
+
/**
|
|
56
|
+
* **FULLSEC**
|
|
57
|
+
* @summary Create a new chat channel.
|
|
58
|
+
* @description This script lets you create a new chat channel.
|
|
59
|
+
* You cannot create a channel that already exists (including any of the default ports from `0000` to `FFFF`).
|
|
60
|
+
* If you do not supply a password, anyone can join your channel (but the channel name is not displayed
|
|
61
|
+
* anywhere, so they would have to discover it in some way first).
|
|
62
|
+
*/
|
|
63
|
+
create: ((args: {
|
|
64
|
+
/** The name of the channel to create. */ name: string
|
|
65
|
+
/** The password to secure the channel with. */ password?: string
|
|
66
|
+
}) => ScriptResponse) & ((args: {
|
|
67
|
+
/** The name of the channel to create. */ c: string
|
|
68
|
+
/** The password to secure the channel with. */ password?: string
|
|
69
|
+
}) => ScriptResponse)
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* **FULLSEC**
|
|
73
|
+
* @summary Send a chat message to a channel.
|
|
74
|
+
* @description This script lets you send a message to the specified channel.
|
|
75
|
+
* You must have joined the channel, and you will see your own message (unlike chats.tell).
|
|
76
|
+
*/
|
|
77
|
+
send: ((args: {
|
|
78
|
+
/** The channel to send the message to. */ channel: string
|
|
79
|
+
/** The message to send. */ msg: string
|
|
80
|
+
}) => ScriptResponse) & ((args: {
|
|
81
|
+
/** The channel to send the message to. */ c: string
|
|
82
|
+
/** The message to send. */ msg: string
|
|
83
|
+
}) => ScriptResponse)
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* **FULLSEC**
|
|
87
|
+
* @summary Send a chat message to a specific user.
|
|
88
|
+
* @description This script lets you send a message to the specified user directly.
|
|
89
|
+
* You can message any user, you only need their username.
|
|
90
|
+
* Note that you will not be able to see your message after it is sent (though many chat scripts based on
|
|
91
|
+
* chats.tell also send the message to you to work around this limitation).
|
|
92
|
+
*/
|
|
93
|
+
tell: (args: {
|
|
94
|
+
/** The username to send the message to. */ to: string
|
|
95
|
+
/** The message to send. */ msg: string
|
|
96
|
+
}) => ScriptResponse
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
escrow: {
|
|
100
|
+
/** **FULLSEC** */ charge: (args: { cost: number | string, is_unlim?: boolean }) => null | ScriptFailure
|
|
101
|
+
confirm: never
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
gui: { chats: never, quiet: never, size: never, vfx: never, vol: never }
|
|
105
|
+
|
|
106
|
+
market: {
|
|
107
|
+
/** **FULLSEC** */ browse: {
|
|
108
|
+
(args: Partial<{
|
|
109
|
+
seller: string | MongoQuerySelector<string>
|
|
110
|
+
listed_before: number | MongoQuerySelector<number>
|
|
111
|
+
listed_after: number
|
|
112
|
+
cost: number | MongoQuerySelector<number> | string
|
|
113
|
+
rarity: UpgradeRarityNumber | MongoQuerySelector<UpgradeRarityNumber>
|
|
114
|
+
name: string | MongoQuerySelector<string>
|
|
115
|
+
} & Omit<{
|
|
116
|
+
[k in keyof CliUpgrade]: CliUpgrade[k] | MongoQuerySelector<CliUpgrade[k]>
|
|
117
|
+
}, "rarity">>): { i: string, name: string, rarity: Upgrade["rarity"], cost: number }[] | ScriptFailure
|
|
118
|
+
|
|
119
|
+
<I extends string>(args: { i: I }): {
|
|
120
|
+
i: I
|
|
121
|
+
seller: string
|
|
122
|
+
cost: number
|
|
123
|
+
count: number
|
|
124
|
+
description: string
|
|
125
|
+
upgrade: Upgrade
|
|
126
|
+
no_notify: boolean
|
|
127
|
+
} | ScriptFailure
|
|
128
|
+
|
|
129
|
+
<I extends string[]>(args: { i: I }): {
|
|
130
|
+
i: I
|
|
131
|
+
seller: string
|
|
132
|
+
cost: number
|
|
133
|
+
count: number
|
|
134
|
+
description: string
|
|
135
|
+
upgrade: Upgrade
|
|
136
|
+
no_notify: boolean
|
|
137
|
+
}[] | ScriptFailure
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
scripts: {
|
|
142
|
+
/** **FULLSEC** */ get_access_level: (args: { name: string }) =>
|
|
143
|
+
{ public: boolean, hidden: boolean, trust: boolean } | ScriptFailure
|
|
144
|
+
|
|
145
|
+
/** **FULLSEC** */ get_level: (args: { name: string }) => 0 | 1 | 2 | 3 | 4 | ScriptFailure
|
|
146
|
+
/** **FULLSEC** */ fullsec: { (): string[], (args: { sector: string }): string[] | ScriptFailure }
|
|
147
|
+
/** **FULLSEC** */ highsec: Fullsec["scripts"]["fullsec"]
|
|
148
|
+
/** **FULLSEC** */ lowsec: Fullsec["scripts"]["fullsec"]
|
|
149
|
+
/** **FULLSEC** */ midsec: Fullsec["scripts"]["fullsec"]
|
|
150
|
+
/** **FULLSEC** */ nullsec: Fullsec["scripts"]["fullsec"]
|
|
151
|
+
/** **FULLSEC** */ trust: () => string[]
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* **FULLSEC*
|
|
155
|
+
* @returns A code library containing useful helper functions you can use in your scripts.
|
|
156
|
+
*/
|
|
157
|
+
lib: () => {
|
|
158
|
+
ok: () => ScriptSuccess
|
|
159
|
+
not_impl: () => { ok: false, msg: "Not Implemented." }
|
|
160
|
+
/** Append `message` to the current script run's log. */ log: (message: any) => void
|
|
161
|
+
/** @returns All messages added using `scripts.lib().log` during this script run. */ get_log: () => string[]
|
|
162
|
+
|
|
163
|
+
/** @returns A random integer in the range [min, max) generated using `rng` (defaults to `Math.random`). */
|
|
164
|
+
rand_int: (min: number, max: number, rng?: () => number) => number
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @returns `floor` if `value` is less than `floor`, `ceil` if `value` is more than `ceil`, otherwise
|
|
168
|
+
* `value`.
|
|
169
|
+
*/
|
|
170
|
+
clamp: (value: number, floor: number, ceil: number) => number
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Linear interpolation function.
|
|
174
|
+
* @returns A number between `start` and `stop` using `amount` as a percent.
|
|
175
|
+
*/
|
|
176
|
+
lerp: (amount: number, start: number, stop: number) => number
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @returns A random element from `array`, selected with a random number generated using `rng`
|
|
180
|
+
* (defaults to `Math.random`).
|
|
181
|
+
*/
|
|
182
|
+
sample: <T>(array: T[], rng?: () => number) => T
|
|
183
|
+
|
|
184
|
+
/** @returns Whether two MongoDB `ObjectId`s are equivalent. */ are_ids_eq: (id1: any, id2: any) => boolean
|
|
185
|
+
/** Convert a MongoDB `ObjectId` to a string. */ id_to_str: (id: string | { $oid: string }) => any
|
|
186
|
+
/** @returns Whether `value` is a boolean primitive. */ is_bool: (value: any) => value is boolean
|
|
187
|
+
/** @returns Whether `value` is an object or `null`. */
|
|
188
|
+
is_obj: (value: any) => value is Record<string, unknown> | null
|
|
189
|
+
/** @returns Whether `value` is a string. */ is_str: (value: any) => value is string
|
|
190
|
+
/** @returns Whether `value` is a number. */ is_num: (value: any) => value is number
|
|
191
|
+
/** @returns Whether `value` is an integer. */ is_int: (value: any) => value is number
|
|
192
|
+
/** @returns Whether `value` is a negative number. */ is_neg: (value: any) => value is number
|
|
193
|
+
/** @returns Whether `value` is an array. */ is_arr: (value: any) => value is unknown[]
|
|
194
|
+
/** @returns Whether `value` is a function. */ is_func: (value: any) => value is (...args: any[]) => unknown
|
|
195
|
+
/** @returns Whether `value` is not `undefined`. */ is_def: (value: any) => boolean
|
|
196
|
+
/** @returns Whether `name` is a valid in-game username. */ is_valid_name: (name: string) => boolean
|
|
197
|
+
/** @returns The string representation of `value`. */ dump: (value: { toString: () => string }) => string
|
|
198
|
+
/** @returns A deep clone of `object`. */ clone: <T extends object>(object: T) => T
|
|
199
|
+
|
|
200
|
+
/** Applies all key-value pairs from `obj2` to `obj1`, overwriting if necessary. */
|
|
201
|
+
merge: <F extends object, S extends object>(obj1: F, obj2: S) => F & S
|
|
202
|
+
|
|
203
|
+
/** @returns An array of `object`'s values */ get_values: (object: object) => any[]
|
|
204
|
+
/** @returns A numeric hash of `string`. */ hash_code: (string: string) => number
|
|
205
|
+
|
|
206
|
+
/** @returns A numeric hash of `string`. */ xmur3: (string: string) => number
|
|
207
|
+
|
|
208
|
+
/** @returns Function that generates random floats in the range 0-1 based on the numerical seeds. */
|
|
209
|
+
sfc32: (seed1: number, seed2: number, seed3: number, seed4: number) => () => number
|
|
210
|
+
|
|
211
|
+
/** @returns Function that generates random floats in the range 0-1 based on the numerical seed. */
|
|
212
|
+
mulberry32: (seed: number) => () => number
|
|
213
|
+
|
|
214
|
+
/** @returns Function that generates random floats in the range 0-1 based on the numerical seeds. */
|
|
215
|
+
xoshiro128ss: (seed1: number, seed2: number, seed3: number, seed4: number) => () => number
|
|
216
|
+
|
|
217
|
+
/** @returns Function that generates random floats in the range 0-1 based on the numerical seed. */
|
|
218
|
+
JSF: (seed: number) => () => number
|
|
219
|
+
|
|
220
|
+
/** @returns Function that generates random floats in the range 0-1 based on the numerical seed. */
|
|
221
|
+
LCG: (seed: number) => () => number
|
|
222
|
+
|
|
223
|
+
/** Converts a number to a GC string of the form `"1M5K20GC"`. */ to_gc_str: (number: number) => string
|
|
224
|
+
|
|
225
|
+
/** Converts a string similar to `"1M5K20GC"` to an equivalent numerical representation. */
|
|
226
|
+
to_gc_num: (string: string) => number | ScriptFailure
|
|
227
|
+
|
|
228
|
+
/** @returns A string of the form YYMMDD.HHMM derived from `date`. */ to_game_timestr: (date: Date) => string
|
|
229
|
+
|
|
230
|
+
corruption_chars: "¡¢Á¤Ã¦§¨©ª"
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* A list of unique color codes to be used with hackmud's color formatting syntax.
|
|
234
|
+
* Does not include numeric codes, which are duplicates of some alphabetic codes.
|
|
235
|
+
*/
|
|
236
|
+
colors: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
237
|
+
|
|
238
|
+
/** Used by `$fs.scripts.lib().corrupt()` to determine the frequency of corruption. */
|
|
239
|
+
corruptions: [0, 1, 1.5, 2.5, 5]
|
|
240
|
+
|
|
241
|
+
/** Adds colored corruption characters to `text`, with frequency determined by `amount`. */
|
|
242
|
+
corrupt: (text: string | string[], amount: 0 | 1 | 2 | 3 | 4) => string
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @returns The first `length` characters of `string`, or the original string if it is shorter than
|
|
246
|
+
* `length`.
|
|
247
|
+
*/
|
|
248
|
+
cap_str_len: (string: string, length: number) => string
|
|
249
|
+
|
|
250
|
+
/** Applies `callback` to each element in `array` and returns the original array. */
|
|
251
|
+
each: <T>(array: T[], callback: (index: number, value: T) => void) => T[]
|
|
252
|
+
|
|
253
|
+
/** @returns A new array containing the elments of `array` for which `callback` returns `true`. */
|
|
254
|
+
select: <T>(array: T[], callback: (index: number, value: T) => boolean) => T[]
|
|
255
|
+
|
|
256
|
+
/** @returns The number of elements in `array` for which `callback` returns `true`. */
|
|
257
|
+
count: <T>(array: T[], callback: (index: number, value: T) => boolean) => number
|
|
258
|
+
|
|
259
|
+
/** @returns The first element in `array` for which `callback` returns `true`. */
|
|
260
|
+
select_one: <T>(array: T[], callback: (index: number, value: T) => boolean) => T
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @returns A new array composed of the result of applying `callback` to each element of the original array
|
|
264
|
+
* in order.
|
|
265
|
+
*/
|
|
266
|
+
map: <T, U>(array: T[], callback: (index: number, value: T) => U) => U[]
|
|
267
|
+
|
|
268
|
+
/** @returns A new object derived from `obj` with only the keys specified in `keys`. */
|
|
269
|
+
pick: <TObj extends object, TKeys extends keyof TObj>(obj: TObj, keys: TKeys[]) => { [K in TKeys]: TObj[K] }
|
|
270
|
+
|
|
271
|
+
/** @returns An array with the elements from `array` in a random order. */ shuffle: <T>(array: T[]) => T[]
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
Comparison function for sorting arbitrary values in ascending order using builtin comparison operators.
|
|
275
|
+
*/
|
|
276
|
+
sort_asc: (one: any, two: any) => 1 | -1 | 0
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
Comparison function for sorting arbitrary values in descending order using builtin comparison operators.
|
|
280
|
+
*/
|
|
281
|
+
sort_desc: (one: any, two: any) => 1 | -1 | 0
|
|
282
|
+
|
|
283
|
+
/** Comparison function for sorting numbers in ascending order. */
|
|
284
|
+
num_sort_asc: (one: number, two: number) => 1 | -1 | 0
|
|
285
|
+
|
|
286
|
+
/** Comparison function for sorting numbers in descending order. */
|
|
287
|
+
num_sort_desc: (one: number, two: number) => 1 | -1 | 0
|
|
288
|
+
|
|
289
|
+
/** @returns The value and the index of the largest number in `array`. */
|
|
290
|
+
max_val_index: (array: number[]) => [largestValue: number, index: number]
|
|
291
|
+
|
|
292
|
+
/** @returns A new `Date` equivalent to `date.getTime() + add_ms`. */
|
|
293
|
+
add_time: (date: Date, add_ms: number) => Date
|
|
294
|
+
|
|
295
|
+
/** Array of strings representing seclevels. */
|
|
296
|
+
security_level_names: ["NULLSEC", "LOWSEC", "MIDSEC", "HIGHSEC", "FULLSEC"]
|
|
297
|
+
|
|
298
|
+
/** @returns The string name of a numeric security level. */
|
|
299
|
+
get_security_level_name: (security_level: number) => string
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* @param result The return value of a call to `$db.i()` or `$db.r()`.
|
|
303
|
+
* @param nModified The expected value of `result.nModified`.
|
|
304
|
+
* @returns Whether the database operation failed.
|
|
305
|
+
*/
|
|
306
|
+
dbu_result_failed: (result: ReturnType<typeof $db.u | typeof $db.u1 | typeof $db.us>, nModified?: number) => boolean
|
|
307
|
+
|
|
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.
|
|
312
|
+
*/
|
|
313
|
+
dbir_result_failed: (result: ReturnType<typeof $db.i | typeof $db.r>, n?: number) => boolean
|
|
314
|
+
|
|
315
|
+
/** @returns A random string of length `length` using lowercase letters and numbers. */
|
|
316
|
+
create_rand_string: (length: number) => string
|
|
317
|
+
|
|
318
|
+
/** @returns The user half `x` of a fully-qualified script name `x.y`. */
|
|
319
|
+
get_user_from_script: (script_name: string) => string
|
|
320
|
+
|
|
321
|
+
/** @returns The script half `y` of a fully-qualified script name `x.y`. */
|
|
322
|
+
get_scriptname_from_script: (name: string) => string
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Determines whether to treat this run as a subscript, based either on the presence of `calling_script` in
|
|
326
|
+
* `context`, or the explicit passing of `is_script: true` in `args`.
|
|
327
|
+
*/
|
|
328
|
+
is_script: (context: Context, args: any) => boolean
|
|
329
|
+
|
|
330
|
+
/** @returns Whether the script is being called by its owner. */
|
|
331
|
+
caller_is_owner: (context: Context) => boolean
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Removes consecutive duplicate elements from an array.
|
|
335
|
+
* @example
|
|
336
|
+
* const { uniq } = $fs.scripts.lib()
|
|
337
|
+
* const arr = [ 1, 2, 2, 3, 2 ]
|
|
338
|
+
*
|
|
339
|
+
* $D(uniq(arr)) // [ 1, 2, 3, 2 ]
|
|
340
|
+
*/
|
|
341
|
+
uniq: <T>(array: T[]) => T[]
|
|
342
|
+
|
|
343
|
+
/** Sorts an array of numbers or number-coercible strings in descending order. */
|
|
344
|
+
u_sort_num_arr_desc: <T>(array: T[]) => T[]
|
|
345
|
+
|
|
346
|
+
/** BUGGED: Creates a new string of length `length` by repeating `pad_char`. */
|
|
347
|
+
ljust: (input: string, length: number, pad_char?: string) => string
|
|
348
|
+
|
|
349
|
+
/** Add characters from `pad_char` to the left of `input` until it reaches length `length`. */
|
|
350
|
+
rjust: (input: string, length: number, pad_char?: string) => string
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* @returns A string with the entries from `strings` split into evenly spaced columns, organized donward
|
|
354
|
+
* and then rightward, to fit the current user's terminal.
|
|
355
|
+
*/
|
|
356
|
+
columnize: (strings: string[]) => string
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Takes two newline-separated strings and formats a new string where they appear in columns, separated by
|
|
360
|
+
* `space`.
|
|
361
|
+
* @example
|
|
362
|
+
* const { side_by_side } = $fs.scripts.lib()
|
|
363
|
+
* const str1 = "one\ntwo\nthree"
|
|
364
|
+
* const str2 = "four\nfive\nsix"
|
|
365
|
+
*
|
|
366
|
+
* $D(side_by_side(str1, str2, "|"))
|
|
367
|
+
* // one|four\n
|
|
368
|
+
* // two|five\n
|
|
369
|
+
* // three|six
|
|
370
|
+
*/
|
|
371
|
+
side_by_side: (str1: string, str2: string, space?: string) => string
|
|
372
|
+
|
|
373
|
+
/** @returns Whether enough time remains in the script execution window to satisfy `time_left`. */
|
|
374
|
+
can_continue_execution: (time_left: number) => boolean
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* @returns A human-readable error object when not enough time remains in the script execution window to
|
|
378
|
+
* satisfy `time_left`.
|
|
379
|
+
*/
|
|
380
|
+
can_continue_execution_error: (time_left: number, name?: string) => { ok: false, msg: string }
|
|
381
|
+
|
|
382
|
+
/** @returns Current date, equivalent to `new Date()`. */ get_date: () => Date
|
|
383
|
+
/** @returns time since the epoch, equivalent to `Date.now()`. */ get_date_utcsecs: () => number
|
|
384
|
+
/** The amount of milliseconds in a single day. */ one_day_ms: 86_400_000
|
|
385
|
+
|
|
386
|
+
is_not_today: (date: Date) => boolean
|
|
387
|
+
|
|
388
|
+
/** @returns The number of days that have passed between `d2` and `d1` */
|
|
389
|
+
utc_day_diff: (d1: Date, d2: Date) => number
|
|
390
|
+
|
|
391
|
+
/** @returns The number of days elapsed since `date` as a string, e.g. "<n> days" */
|
|
392
|
+
utc_days_ago_str: (date: Date) => string
|
|
393
|
+
|
|
394
|
+
math: typeof Math
|
|
395
|
+
array: typeof Array
|
|
396
|
+
parse_int: typeof parseInt
|
|
397
|
+
parse_float: typeof parseFloat
|
|
398
|
+
json: typeof JSON
|
|
399
|
+
number: typeof Number
|
|
400
|
+
object: typeof Object
|
|
401
|
+
date: typeof Date
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** **FULLSEC** */ quine: () => string
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
sys: {
|
|
408
|
+
init: never
|
|
409
|
+
|
|
410
|
+
/** **FULLSEC** */
|
|
411
|
+
upgrades_of_owner: {
|
|
412
|
+
<F extends Partial<Upgrade & { loaded: boolean }> = object>(args: { filter?: F, full: true }): (
|
|
413
|
+
Omit<Upgrade, keyof F> & F
|
|
414
|
+
)[] | ScriptFailure
|
|
415
|
+
|
|
416
|
+
<F extends Partial<Upgrade & { loaded: boolean }> = object>(args?: { filter?: F, full?: boolean }): (
|
|
417
|
+
Upgrade
|
|
418
|
+
)[] | ScriptFailure
|
|
419
|
+
|
|
420
|
+
<I extends number>(args: { i: I }): Upgrade | ScriptFailure
|
|
421
|
+
|
|
422
|
+
<I extends number>(args: { i: I[] }): Upgrade[] | ScriptFailure
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** **FULLSEC** */
|
|
426
|
+
xfer_upgrade_to_caller: (args: ({ i: number | number[] } | { sn: string | string[] }) & { memo?: string }) => ScriptResponse
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
users: {
|
|
430
|
+
/** **FULLSEC** */ active: () => number
|
|
431
|
+
/** **FULLSEC** */ last_action: (args: { name: string | string[] }) => ({ n: string, t?: Date } | null)[]
|
|
432
|
+
|
|
433
|
+
/** **FULLSEC** */
|
|
434
|
+
top: () => [
|
|
435
|
+
UsersTopItem<1>, UsersTopItem<2>, UsersTopItem<3>, UsersTopItem<4>, UsersTopItem<5>,
|
|
436
|
+
UsersTopItem<6>, UsersTopItem<7>, UsersTopItem<8>, UsersTopItem<9>, UsersTopItem<10>
|
|
437
|
+
]
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
type Highsec = Fullsec & PlayerHighsec & {
|
|
442
|
+
accts: {
|
|
443
|
+
/**
|
|
444
|
+
* **HIGHSEC**
|
|
445
|
+
* @returns GC balance as number if `is_script` is true (default).
|
|
446
|
+
* @returns GC balance as string if `is_script` is false.
|
|
447
|
+
*/
|
|
448
|
+
balance: {
|
|
449
|
+
(args?: { is_script?: true }): number
|
|
450
|
+
(args: { is_script: false }): string
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* **HIGHSEC**
|
|
455
|
+
* @returns Transaction history according to filter.
|
|
456
|
+
* @returns If `is_script` is true (default), time property as Date object.
|
|
457
|
+
* @returns Wraps transactions in object with msg, time property as string (game date format e.g. 201028.2147)
|
|
458
|
+
* if `is_script` is false.
|
|
459
|
+
*/
|
|
460
|
+
transactions: {
|
|
461
|
+
(args?: { count?: number | "all", to?: string, from?: string, script?: string, is_script?: true }): {
|
|
462
|
+
time: Date
|
|
463
|
+
amount: number
|
|
464
|
+
sender: string
|
|
465
|
+
recipient: string
|
|
466
|
+
script: string | null
|
|
467
|
+
memo?: string
|
|
468
|
+
}[]
|
|
469
|
+
|
|
470
|
+
(args: { count?: number | "all", to?: string, from?: string, script?: string, is_script: false }): {
|
|
471
|
+
msg: string
|
|
472
|
+
transactions: {
|
|
473
|
+
time: string
|
|
474
|
+
amount: string
|
|
475
|
+
sender: string
|
|
476
|
+
recipient: string
|
|
477
|
+
script: string | null
|
|
478
|
+
memo?: string
|
|
479
|
+
}[]
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
marks: {
|
|
485
|
+
/** **HIGHSEC** */ available: () => string
|
|
486
|
+
/** **HIGHSEC** */ protocol: (args?: {
|
|
487
|
+
pos?: [number, number],
|
|
488
|
+
name?: string,
|
|
489
|
+
[foo: any]: any
|
|
490
|
+
}) => string
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
scripts: {
|
|
494
|
+
/** **HIGHSEC** */ sys: () => string | string[]
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
sys: {
|
|
498
|
+
/** **HIGHSEC** */ specs: () => string | ScriptFailure
|
|
499
|
+
/** **HIGHSEC** */ status: () => { hardline: number, tutorial: string, breach: boolean }
|
|
500
|
+
|
|
501
|
+
/** **HIGHSEC** */
|
|
502
|
+
upgrade_log: {
|
|
503
|
+
(args?: { is_script?: true, user?: string, run_id?: string, count?: number, start?: number }): { t: Date, u: string, r: string, msg: string }[] | ScriptFailure
|
|
504
|
+
|
|
505
|
+
(args: { is_script: false, user?: string, run_id?: string, count?: number, start?: number }):
|
|
506
|
+
string[] | ScriptFailure
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** **HIGHSEC** */
|
|
510
|
+
upgrades: {
|
|
511
|
+
<I extends number>(args: { i: I }): (
|
|
512
|
+
Omit<UpgradeBase, "i"> & { [x: string]: null | boolean | number | string, i: I }
|
|
513
|
+
) | ScriptFailure
|
|
514
|
+
|
|
515
|
+
<F extends Partial<Upgrade & { loaded: boolean }> = object>(args?: {
|
|
516
|
+
filter?: F
|
|
517
|
+
is_script?: true
|
|
518
|
+
full?: false
|
|
519
|
+
}): (
|
|
520
|
+
Omit<Pick<UpgradeBase, "tier" | "rarity" | "name" | "type" | "i" | "loaded">, keyof F> & F &
|
|
521
|
+
Record<string, null | boolean | number | string>
|
|
522
|
+
)[] | ScriptFailure
|
|
523
|
+
|
|
524
|
+
<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
|
|
525
|
+
|
|
526
|
+
(args?: { filter?: Partial<Upgrade & { loaded: boolean }>, is_script: false, full?: false }): { msg: string, upgrades: string[] } | ScriptFailure
|
|
527
|
+
|
|
528
|
+
<F extends Partial<Upgrade & { loaded: boolean }> = object>(
|
|
529
|
+
args?: { filter?: F, is_script: false, full: true }
|
|
530
|
+
): (Omit<UpgradeBase, keyof F | "rarity"> & F & {
|
|
531
|
+
[x: string]: null | boolean | number | string
|
|
532
|
+
rarity: UpgradeRarityString
|
|
533
|
+
})[] | ScriptFailure
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
users: {
|
|
538
|
+
/** **HIGHSEC** */ inspect: {
|
|
539
|
+
(args: { name: "trust", is_script?: boolean }): number
|
|
540
|
+
(args: { name: "risk", is_script?: boolean }): string
|
|
541
|
+
|
|
542
|
+
(args: { name: string, is_script?: true }): {
|
|
543
|
+
username: string
|
|
544
|
+
avatar: string
|
|
545
|
+
pronouns: string
|
|
546
|
+
user_age?: Date
|
|
547
|
+
bio?: string
|
|
548
|
+
title?: string
|
|
549
|
+
is_main: boolean
|
|
550
|
+
alt_of?: string
|
|
551
|
+
badges?: string[]
|
|
552
|
+
} | ScriptFailure
|
|
553
|
+
|
|
554
|
+
(args: { name: string, is_script: false }): string | ScriptFailure
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
type Midsec = Highsec & PlayerMidsec & {
|
|
560
|
+
accts: {
|
|
561
|
+
/** **MIDSEC** */ xfer_gc_to: (args: { to: string, amount: number | string, memo?: string }) => ScriptResponse
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
autos: { /** **MIDSEC** */ reset: () => ScriptSuccess }
|
|
565
|
+
|
|
566
|
+
chats: {
|
|
567
|
+
/** **MIDSEC** */ channels: () => string[]
|
|
568
|
+
/** **MIDSEC** */ join: (args: { channel: string, password?: string }) => ScriptResponse
|
|
569
|
+
/** **MIDSEC** */ leave: (args: { channel: string }) => ScriptResponse
|
|
570
|
+
/** **MIDSEC** */ users: (args: { channel: string }) => string[] | ScriptFailure
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
escrow: {
|
|
574
|
+
/** **MIDSEC** */ stats: () =>
|
|
575
|
+
{ scripts: string[], total: string, outstanding: string, open_escrow_count: number } | ScriptFailure
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
market: {
|
|
579
|
+
/** **MIDSEC** */ buy: (args: { i: string, count: number, confirm: true }) => ScriptResponse
|
|
580
|
+
|
|
581
|
+
/** **MIDSEC** */ stats: () =>
|
|
582
|
+
ScriptFailure | { total: string, outstanding: string, listed: number, sold: number }
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
scripts: { /** **MIDSEC** */ user: () => string[] }
|
|
586
|
+
|
|
587
|
+
sys: {
|
|
588
|
+
/** **MIDSEC** */
|
|
589
|
+
manage: {
|
|
590
|
+
(args: { unload?: number | number[], load?: number | number[] }): ScriptResponse
|
|
591
|
+
|
|
592
|
+
(args: { reorder?: ([number, number] | { from: number, to: number })[] | { from: number, to: number } }):
|
|
593
|
+
string[] | ScriptFailure
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
type Lowsec = Midsec & PlayerLowsec & {
|
|
599
|
+
kernel: { /** **LOWSEC** */ hardline: (args?: { activate?: boolean, dc?: boolean }) => ScriptResponse }
|
|
600
|
+
|
|
601
|
+
market: {
|
|
602
|
+
/** **LOWSEC** */ sell: (args: {
|
|
603
|
+
i: number
|
|
604
|
+
cost: number | string
|
|
605
|
+
description?: string
|
|
606
|
+
count?: number
|
|
607
|
+
no_notify?: boolean
|
|
608
|
+
confirm?: boolean
|
|
609
|
+
delist?: string
|
|
610
|
+
}) => ScriptResponse<{ token: string }>
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
sys: {
|
|
614
|
+
/** **LOWSEC** */ access_log: {
|
|
615
|
+
(args?: { user?: string, run_id?: string, is_script?: true, count?: number, start?: number }):
|
|
616
|
+
AccessLog[] | ScriptFailure
|
|
617
|
+
|
|
618
|
+
(args: { user?: string, run_id?: string, is_script: false, count?: number, start?: number }): string[]
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/** **LOWSEC** */ cull: (args: { i: number | number[], confirm: true }) => ScriptResponse
|
|
622
|
+
|
|
623
|
+
/** **LOWSEC** */ loc: () => string | ScriptFailure
|
|
624
|
+
|
|
625
|
+
/** **LOWSEC** */ xfer_upgrade_to: {
|
|
626
|
+
(args: { i: number | number[], to: string, memo?: string }): ScriptResponse
|
|
627
|
+
(args: { sn: string | string[], to: string, memo?: string }): ScriptResponse
|
|
628
|
+
}
|
|
629
|
+
/** **LOWSEC** */ expose_access_log: (args: { target: string }) => AccessLog[] | ScriptFailure
|
|
630
|
+
/** **LOWSEC** */ xfer_gc_from: (args: { target: string, amount: number | string }) => ScriptResponse
|
|
631
|
+
/** **LOWSEC** */ expose_balance: (args: { target: string }) => number | ScriptFailure
|
|
632
|
+
|
|
633
|
+
/** **LOWSEC** */ expose_upgrades: (args: { target: string }) => UpgradeBase[] | ScriptFailure
|
|
634
|
+
/** **LOWSEC** */ xfer_upgrade_from: (args: { target: string, i: number | number[] }) => ScriptResponse<{}>
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
type Nullsec = Lowsec & PlayerNullsec & {
|
|
639
|
+
binmat: {
|
|
640
|
+
/**
|
|
641
|
+
* **NULLSEC**
|
|
642
|
+
*/
|
|
643
|
+
connect: (args: { target: string, trace: Trace, brain?: string }) => ScriptResponse,
|
|
644
|
+
/**
|
|
645
|
+
* **NULLSEC**
|
|
646
|
+
*/
|
|
647
|
+
c: typeof $ns.binmat.connect,
|
|
648
|
+
/**
|
|
649
|
+
* **NULLSEC**
|
|
650
|
+
*/
|
|
651
|
+
xform: (args: { op: Op }) => ScriptResponse,
|
|
652
|
+
/**
|
|
653
|
+
* **NULLSEC**
|
|
654
|
+
*/
|
|
655
|
+
x: typeof $ns.binmat.xform
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
corps: {
|
|
659
|
+
/** **NULLSEC** */ create: (args: { name: string, confirm: true }) => ScriptResponse
|
|
660
|
+
/** **NULLSEC** */ hire: (args: { name: string }) => ScriptResponse
|
|
661
|
+
|
|
662
|
+
/** **NULLSEC** */ manage: {
|
|
663
|
+
(args: { command: "list" }): { name: string, is_admin: boolean }[] | ScriptFailure
|
|
664
|
+
|
|
665
|
+
(args: { command: "demote" | "promote", name: string } | { command: "fire", name: string, confirm: true }): ScriptResponse
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/** **NULLSEC** */ offers: {
|
|
669
|
+
(): { offers: string[], msg: string } | ScriptSuccess<{ msg: string, current_corp: string | null }>
|
|
670
|
+
(args: { accept: string }): ScriptResponse
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/** **NULLSEC** */ quit: (args: { confirm: true }) => ScriptResponse
|
|
674
|
+
/** **NULLSEC** */ top: () => CorpsTop | { top: CorpsTop, active: { name: string, worth: string } }
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
marks: { /** **NULLSEC** */ clone: (args?: { name?: string }) => ScriptResponse }
|
|
678
|
+
|
|
679
|
+
sys: { /** **NULLSEC** */ breach: (args: { confirm: true }) => ScriptResponse }
|
|
680
|
+
trust: { /** **NULLSEC** */ me: () => string }
|
|
681
|
+
|
|
682
|
+
users: {
|
|
683
|
+
/** **NULLSEC** */ config: {
|
|
684
|
+
(args: {
|
|
685
|
+
list: false
|
|
686
|
+
is_script?: true | null
|
|
687
|
+
avatar?: string | null
|
|
688
|
+
user_age?: boolean | null
|
|
689
|
+
account_age?: boolean | null
|
|
690
|
+
bio?: string | null
|
|
691
|
+
title?: string | null
|
|
692
|
+
pronouns?: string | null
|
|
693
|
+
corp?: boolean | null
|
|
694
|
+
alt_of?: string | null
|
|
695
|
+
badges?: string[] | null
|
|
696
|
+
}): ScriptResponse
|
|
697
|
+
|
|
698
|
+
(args: {
|
|
699
|
+
list: true
|
|
700
|
+
is_script?: true
|
|
701
|
+
avatar?: string | null
|
|
702
|
+
user_age?: boolean | null
|
|
703
|
+
account_age?: boolean | null
|
|
704
|
+
bio?: string | null
|
|
705
|
+
title?: string | null
|
|
706
|
+
pronouns?: string | null
|
|
707
|
+
corp?: boolean | null
|
|
708
|
+
alt_of?: string | null
|
|
709
|
+
badges?: string[] | null
|
|
710
|
+
}): {
|
|
711
|
+
avatar: string | null
|
|
712
|
+
user_age?: boolean
|
|
713
|
+
account_age?: boolean
|
|
714
|
+
bio: string | null
|
|
715
|
+
title: string | null
|
|
716
|
+
pronouns: string
|
|
717
|
+
corp?: boolean
|
|
718
|
+
alt_of: string | null
|
|
719
|
+
badges: string[]
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
(args: {
|
|
723
|
+
list: true
|
|
724
|
+
is_script: false
|
|
725
|
+
avatar?: string | null
|
|
726
|
+
user_age?: boolean | null
|
|
727
|
+
account_age?: boolean | null
|
|
728
|
+
bio?: string | null
|
|
729
|
+
title?: string | null
|
|
730
|
+
pronouns?: string | null
|
|
731
|
+
corp?: boolean | null
|
|
732
|
+
alt_of?: string | null
|
|
733
|
+
badges?: string[] | null
|
|
734
|
+
}): string
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
// database
|
|
740
|
+
type MongoPrimitive = null | boolean | number | Date | string
|
|
741
|
+
type MongoValue = MongoPrimitive | MongoValue[] | MongoObject
|
|
742
|
+
type MongoObject = { [k: string]: MongoValue }
|
|
743
|
+
type MongoQueryValue = MongoPrimitive | MongoQueryValue[] | MongoQueryObject
|
|
744
|
+
|
|
745
|
+
type MongoQueryObject =
|
|
746
|
+
{ [k: string]: MongoQueryValue, [k: `$${string}`]: MongoValue } & { $type?: keyof MongoTypeStringsToTypes | (string & {}) }
|
|
747
|
+
|
|
748
|
+
type MongoTypeStringsToTypes = {
|
|
749
|
+
double: number
|
|
750
|
+
string: string
|
|
751
|
+
object: MongoObject
|
|
752
|
+
array: MongoValue[]
|
|
753
|
+
objectId: MongoObjectId
|
|
754
|
+
bool: boolean
|
|
755
|
+
date: Date
|
|
756
|
+
null: null
|
|
757
|
+
int: number
|
|
758
|
+
long: number
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
type MongoTypeString = keyof MongoTypeStringsToTypes
|
|
762
|
+
type MongoTypeNumber = -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 127
|
|
763
|
+
type MongoId = Exclude<MongoPrimitive, null | false> | MongoObjectId | MongoObject
|
|
764
|
+
type MongoQueryId = Exclude<MongoPrimitive, null | false> | MongoObjectId | MongoQueryObject
|
|
765
|
+
type MongoDocument = MongoObject & { _id?: MongoId }
|
|
766
|
+
|
|
767
|
+
type MongoQueryType<TQuery extends MongoQueryObject> = {
|
|
768
|
+
-readonly [K in keyof TQuery]:
|
|
769
|
+
TQuery[K] extends MongoPrimitive ?
|
|
770
|
+
TQuery[K]
|
|
771
|
+
: TQuery[K] extends { $type: infer TType } ?
|
|
772
|
+
TType extends keyof MongoTypeStringsToTypes ? MongoTypeStringsToTypes[TType] : unknown
|
|
773
|
+
: TQuery[K] extends { $in: (infer TIn)[] } ?
|
|
774
|
+
TIn
|
|
775
|
+
: keyof TQuery[K] extends `$${string}` ?
|
|
776
|
+
unknown
|
|
777
|
+
: TQuery[K] extends { [k: string]: any } ?
|
|
778
|
+
MongoQueryType<TQuery[K]>
|
|
779
|
+
: never
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
type MongoCommandValue = MongoPrimitive | MongoCommandValue[] | { [k: string]: MongoCommandValue }
|
|
783
|
+
type MongoArraySelectors<T extends MongoValue[] = MongoValue[]> = { $all: T, $elemMatch: T, $size: number }
|
|
784
|
+
|
|
785
|
+
type MongoComparisonSelectors<T extends MongoValue = MongoValue> =
|
|
786
|
+
{ $eq: T, $gt: T, $gte: T, $in: T[], $lt: T, $lte: T, $ne: T, $nin: T[] }
|
|
787
|
+
|
|
788
|
+
type MongoElementSelectors = { $exists: boolean, $type: MongoTypeNumber | MongoTypeString }
|
|
789
|
+
|
|
790
|
+
type MongoQuerySelector<T extends MongoValue> = Partial<
|
|
791
|
+
T extends [] ?
|
|
792
|
+
MongoArraySelectors<T> & MongoElementSelectors & MongoComparisonSelectors<T>
|
|
793
|
+
: MongoElementSelectors & MongoComparisonSelectors<T>
|
|
794
|
+
>
|
|
795
|
+
|
|
796
|
+
type MongoQuery<T extends MongoObject> = { [K in keyof T]?: T[K] | MongoQuerySelector<T[K]> } & { _id?: MongoId }
|
|
797
|
+
|
|
798
|
+
type MongoUpdateArrayOperatorUniversalModifiers<T> = { $each?: T extends [] ? T : T[] }
|
|
799
|
+
|
|
800
|
+
type MongoUpdateArrayOperatorModifiers<T> = MongoUpdateArrayOperatorUniversalModifiers<T> &
|
|
801
|
+
{ $position?: number, $slice?: number, $sort?: 1 | -1 }
|
|
802
|
+
|
|
803
|
+
type MongoUpdateCommand<T extends MongoObject> = Partial<{
|
|
804
|
+
/* Universal operators */
|
|
805
|
+
$set: Partial<Record<(string & {}) | keyof T, MongoCommandValue>>
|
|
806
|
+
$setOnInsert: Partial<Record<(string & {}) | keyof T, MongoCommandValue>>
|
|
807
|
+
$unset: Partial<Record<(string & {}) | keyof T, "">>
|
|
808
|
+
|
|
809
|
+
$rename: Partial<Record<string, string> & { [key in keyof T]: string }>
|
|
810
|
+
|
|
811
|
+
/* Date & number operators */
|
|
812
|
+
$inc: Record<string, number> &
|
|
813
|
+
{ [K in keyof T as T[K] extends number | Date ? K : never]?: T[K] extends number ? number : Date }
|
|
814
|
+
|
|
815
|
+
$mul: Record<string, number> & { [K in keyof T as T[K] extends number ? K : never]?: number }
|
|
816
|
+
$min: Record<string, number> & { [K in keyof T as T[K] extends number ? K : never]?: number }
|
|
817
|
+
$max: Record<string, number> & { [K in keyof T as T[K] extends number ? K : never]?: number }
|
|
818
|
+
|
|
819
|
+
/* Array operators */
|
|
820
|
+
$pop: Record<string, -1 | 1> & { [K in keyof T as T[K] extends [] ? K : never]?: -1 | 1 }
|
|
821
|
+
|
|
822
|
+
$push: Record<string, MongoCommandValue> & {
|
|
823
|
+
[K in keyof T as T[K] extends [] ? K : never]?: (T[K] extends (infer U)[] ? U : never) |
|
|
824
|
+
MongoUpdateArrayOperatorModifiers<T[K]>
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
$addToSet: Partial<Record<string, MongoCommandValue> & {
|
|
828
|
+
[K in keyof T as T[K] extends [] ? K : never]: (T[K] extends (infer U)[] ? U : never) |
|
|
829
|
+
MongoUpdateArrayOperatorUniversalModifiers<T[K]>
|
|
830
|
+
}>
|
|
831
|
+
|
|
832
|
+
$pull: Partial<Record<string, MongoCommandValue> & {
|
|
833
|
+
[K in keyof T as T[K] extends [] ? K : never]: (T[K] extends (infer U)[] ? U : never) |
|
|
834
|
+
MongoQuerySelector<T[K]>
|
|
835
|
+
}>
|
|
836
|
+
|
|
837
|
+
$pullAll: Record<string, MongoCommandValue> & { [K in keyof T as T[K] extends [] ? K : never]?: T[K] }
|
|
838
|
+
}>
|
|
839
|
+
|
|
840
|
+
type SortOrder = { [key: string]: 1 | -1 | SortOrder }
|
|
841
|
+
|
|
842
|
+
type Cursor<T> = {
|
|
843
|
+
/** Returns the first document that satisfies the query. */
|
|
844
|
+
first: () => T | null
|
|
845
|
+
/** Returns an array of documents that satisfy the query. */
|
|
846
|
+
array: () => T[]
|
|
847
|
+
/** Returns the number of documents that match the query. */
|
|
848
|
+
count: () => number
|
|
849
|
+
|
|
850
|
+
/** Returns the first document that satisfies the query. Also makes cursor unusable. */
|
|
851
|
+
first_and_close: () => T
|
|
852
|
+
|
|
853
|
+
/** Returns the first document that satisfies the query. Keeps cursor open. */
|
|
854
|
+
first_and_keep_open: () => T
|
|
855
|
+
|
|
856
|
+
/** Returns an array of documents that satisfy the query. Also makes cursor unusable. */
|
|
857
|
+
array_and_close: () => T[]
|
|
858
|
+
|
|
859
|
+
/** Returns an array of documents that satisfy the query. Keeps cursor open. */
|
|
860
|
+
array_and_keep_open: () => T[]
|
|
861
|
+
|
|
862
|
+
/** Returns the number of documents that match the query. Also makes cursor unusable. */
|
|
863
|
+
count_and_close: () => number
|
|
864
|
+
|
|
865
|
+
/** Returns the number of documents that match the query. Keeps cursor open. */
|
|
866
|
+
count_and_keep_open: () => number
|
|
867
|
+
|
|
868
|
+
/** Run `callback` on each document that satisfied the query. */
|
|
869
|
+
each: (callback: (document: T) => void) => null
|
|
870
|
+
|
|
871
|
+
/** Run `callback` on each document that satisfied the query. Keeps cursor open */
|
|
872
|
+
each_and_keep_open: (callback: (document: T) => void) => null
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Returns a new cursor with documents sorted as specified.
|
|
876
|
+
* A value of 1 sorts the property ascending, and -1 descending.
|
|
877
|
+
* @param order The way the documents are to be sorted.
|
|
878
|
+
*/
|
|
879
|
+
sort: (order?: SortOrder) => Cursor<T>
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* Returns a new cursor without the first number of documents.
|
|
883
|
+
* @param count Number of documents to skip.
|
|
884
|
+
*/
|
|
885
|
+
skip: (count: number) => Cursor<T>
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Returns a new cursor limited to a number of documents as specified.
|
|
889
|
+
* @param count Number of documents.
|
|
890
|
+
*/
|
|
891
|
+
limit: (count: number) => Cursor<T>
|
|
892
|
+
|
|
893
|
+
/** @param key The key of the documents. Keeps cursor open */
|
|
894
|
+
distinct_and_keep_open: { (key: string): MongoValue[], (key: "_id"): MongoId[] }
|
|
895
|
+
|
|
896
|
+
/** @param key The key of the documents. */
|
|
897
|
+
distinct: { (key: string): MongoValue[], (key: "_id"): MongoId[] }
|
|
898
|
+
|
|
899
|
+
/** Make cursor unusable. */
|
|
900
|
+
close: () => null
|
|
901
|
+
|
|
902
|
+
NumberLong: (number: number) => number
|
|
903
|
+
// TODO what actually is the type here?
|
|
904
|
+
ObjectId: () => any
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
type CliContext = {
|
|
908
|
+
/** The name of the user who is calling the script. */ caller: string
|
|
909
|
+
/** The name of this script. */ this_script: string
|
|
910
|
+
/** The number of columns in the caller’s terminal. */ cols: number
|
|
911
|
+
/** The number of rows in the caller’s terminal. */ rows: number
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* The name of the script that directly called this script, or null if called on the command line or as a
|
|
915
|
+
* scriptor.
|
|
916
|
+
*/
|
|
917
|
+
calling_script: null
|
|
918
|
+
|
|
919
|
+
is_scriptor?: undefined
|
|
920
|
+
is_brain?: undefined
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
type SubscriptContext = Replace<CliContext, {
|
|
924
|
+
/**
|
|
925
|
+
The name of the script that directly called this script, or null if called on the command line or as a scriptor.
|
|
926
|
+
*/
|
|
927
|
+
calling_script: string
|
|
928
|
+
}>
|
|
929
|
+
|
|
930
|
+
type ScriptorContext = Replace<CliContext, { /** Whether the script is being run as a scriptor. */ is_scriptor: true }>
|
|
931
|
+
type BrainContext = Replace<CliContext, { /** Whether the script is being run via a bot brain. */ is_brain: true }>
|
|
932
|
+
|
|
933
|
+
// _id is always returned unless _id: false is passed
|
|
934
|
+
// when anyField: true is given, other fields (except _id) are omitted
|
|
935
|
+
|
|
936
|
+
type MongoProject<TDocument, TProjection> =
|
|
937
|
+
(TProjection extends { _id: false | 0 } ? {} : { _id: TDocument extends { _id: infer TId } ? TId : MongoId }) & (
|
|
938
|
+
true extends (1 extends TProjection[keyof TProjection] ? true : TProjection[keyof TProjection]) ?
|
|
939
|
+
{
|
|
940
|
+
[K in keyof TDocument as K extends
|
|
941
|
+
keyof TProjection ? TProjection[K] extends true | 1 ? K : never : never
|
|
942
|
+
]: TDocument[K]
|
|
943
|
+
} &
|
|
944
|
+
{
|
|
945
|
+
-readonly [K in keyof TProjection as TProjection[K] extends
|
|
946
|
+
true | 1 ? K extends keyof TDocument ? never : K : never
|
|
947
|
+
]?: MongoValue
|
|
948
|
+
}
|
|
949
|
+
: { [k: string]: MongoValue } & { [K in keyof TDocument as K extends keyof TProjection ? never : K]: TDocument[K] }
|
|
950
|
+
)
|
|
951
|
+
|
|
952
|
+
type DeepFreeze<T> = { readonly [P in keyof T]: DeepFreeze<T[P]> }
|
|
953
|
+
|
|
954
|
+
declare global {
|
|
955
|
+
type ScriptSuccess<T = unknown> = { ok: true } & T
|
|
956
|
+
type ScriptFailure = { ok: false, msg?: string }
|
|
957
|
+
type ScriptResponse<T = unknown> = ScriptSuccess<T> | ScriptFailure
|
|
958
|
+
type Scriptor<TArgs = any> = { name: string, call: (args: TArgs) => unknown }
|
|
959
|
+
type Context = CliContext | SubscriptContext | ScriptorContext | BrainContext
|
|
960
|
+
type MongoObjectId = { $oid: string }
|
|
961
|
+
|
|
962
|
+
type AccessLog = { t: Date, u: string | undefined, r: string | undefined, msg: string }
|
|
963
|
+
|
|
964
|
+
type UpgradeRarityString = "`0noob`" | "`1kiddie`" | "`2h4x0r`" | "`3h4rdc0r3`" | "`4|_|b3|2`" | "`531337`"
|
|
965
|
+
type UpgradeRarityNumber = 0 | 1 | 2 | 3 | 4 | 5
|
|
966
|
+
|
|
967
|
+
type UpgradeBase = {
|
|
968
|
+
name: string
|
|
969
|
+
type: "lock" | "script_space" | "chat" | "script" | "tool" | "bot_brain" | "glam"
|
|
970
|
+
up_class?: -1 | 0 | 1 | 2 | 3
|
|
971
|
+
tier: 1 | 2 | 3 | 4
|
|
972
|
+
rarity: UpgradeRarityNumber
|
|
973
|
+
i: number
|
|
974
|
+
loaded: boolean
|
|
975
|
+
sn: string
|
|
976
|
+
description: string
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
type Upgrade = UpgradeBase & Record<string, null | boolean | number | string>
|
|
980
|
+
|
|
981
|
+
type CliUpgrade = Omit<UpgradeBase, "rarity"> &
|
|
982
|
+
{ [k: string]: null | boolean | number | string, rarity: UpgradeRarityString }
|
|
983
|
+
|
|
984
|
+
type UsersTopItem<R> = { rank: R, name: string, last_activity: string, balance: string }
|
|
985
|
+
type CorpsTopItem<R> = { rank: R, name: string, worth: string }
|
|
986
|
+
|
|
987
|
+
type CorpsTop = [
|
|
988
|
+
CorpsTopItem<1>, CorpsTopItem<2>, CorpsTopItem<3>, CorpsTopItem<4>, CorpsTopItem<5>,
|
|
989
|
+
CorpsTopItem<6>, CorpsTopItem<7>, CorpsTopItem<8>, CorpsTopItem<9>, CorpsTopItem<10>
|
|
990
|
+
]
|
|
991
|
+
|
|
992
|
+
// BINMAT types
|
|
993
|
+
type Axiom = "%" | "&" | "+" | "!" | "^" | "#"
|
|
994
|
+
|
|
995
|
+
type CardValue = "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "a" | "*" | ">" | "?" | "@"
|
|
996
|
+
|
|
997
|
+
type Card = `${CardValue}${Axiom}`
|
|
998
|
+
|
|
999
|
+
type TeamHand = Card[]
|
|
1000
|
+
type EnemyHand = number
|
|
1001
|
+
type Hand = TeamHand | EnemyHand
|
|
1002
|
+
|
|
1003
|
+
type Deck = {
|
|
1004
|
+
c: number,
|
|
1005
|
+
t: Card | "X"
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
type Discard = `${Card}u`[]
|
|
1009
|
+
type AttackerDiscard = Card[]
|
|
1010
|
+
|
|
1011
|
+
type Stack = (Card | `${Card}u` | "X")[]
|
|
1012
|
+
|
|
1013
|
+
type GameState = {
|
|
1014
|
+
a?: Deck,
|
|
1015
|
+
a0?: Stack,
|
|
1016
|
+
a1?: Stack,
|
|
1017
|
+
a2?: Stack,
|
|
1018
|
+
a3?: Stack,
|
|
1019
|
+
a4?: Stack,
|
|
1020
|
+
a5?: Stack,
|
|
1021
|
+
d0?: Stack,
|
|
1022
|
+
d1?: Stack,
|
|
1023
|
+
d2?: Stack,
|
|
1024
|
+
d3?: Stack,
|
|
1025
|
+
d4?: Stack,
|
|
1026
|
+
d5?: Stack,
|
|
1027
|
+
ha0?: Hand,
|
|
1028
|
+
ha1?: Hand,
|
|
1029
|
+
ha2?: Hand,
|
|
1030
|
+
ha3?: Hand,
|
|
1031
|
+
ha4?: Hand,
|
|
1032
|
+
ha5?: Hand,
|
|
1033
|
+
ha6?: Hand,
|
|
1034
|
+
ha7?: Hand,
|
|
1035
|
+
ha8?: Hand,
|
|
1036
|
+
ha9?: Hand,
|
|
1037
|
+
haa?: Hand,
|
|
1038
|
+
hab?: Hand,
|
|
1039
|
+
hac?: Hand,
|
|
1040
|
+
had?: Hand,
|
|
1041
|
+
hae?: Hand,
|
|
1042
|
+
haf?: Hand,
|
|
1043
|
+
hd0?: Hand,
|
|
1044
|
+
hd1?: Hand,
|
|
1045
|
+
hd2?: Hand,
|
|
1046
|
+
hd3?: Hand,
|
|
1047
|
+
hd4?: Hand,
|
|
1048
|
+
hd5?: Hand,
|
|
1049
|
+
hd6?: Hand,
|
|
1050
|
+
hd7?: Hand,
|
|
1051
|
+
hd8?: Hand,
|
|
1052
|
+
hd9?: Hand,
|
|
1053
|
+
hda?: Hand,
|
|
1054
|
+
hdb?: Hand,
|
|
1055
|
+
hdc?: Hand,
|
|
1056
|
+
hdd?: Hand,
|
|
1057
|
+
hde?: Hand,
|
|
1058
|
+
hdf?: Hand,
|
|
1059
|
+
l0?: Deck
|
|
1060
|
+
l1?: Deck
|
|
1061
|
+
l2?: Deck
|
|
1062
|
+
l3?: Deck
|
|
1063
|
+
l4?: Deck
|
|
1064
|
+
l5?: Deck
|
|
1065
|
+
ord: number,
|
|
1066
|
+
turns: number,
|
|
1067
|
+
x0?: Discard,
|
|
1068
|
+
x1?: Discard,
|
|
1069
|
+
x2?: Discard,
|
|
1070
|
+
x3?: Discard,
|
|
1071
|
+
x4?: Discard,
|
|
1072
|
+
x5?: Discard,
|
|
1073
|
+
xa?: AttackerDiscard
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
type BINMATArgs = {
|
|
1077
|
+
ops: string[],
|
|
1078
|
+
plr: string,
|
|
1079
|
+
plrs: [string, string, string?][],
|
|
1080
|
+
s: GameState
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
type Lane = "0" | "1" | "2" | "3" | "4" | "5"
|
|
1084
|
+
|
|
1085
|
+
type POp = `p${CardValue | Card}${Lane}`
|
|
1086
|
+
type UOp = `u${CardValue | Card}${Lane}`
|
|
1087
|
+
type XOp = `x${CardValue | Card}${Lane | "a"}`
|
|
1088
|
+
|
|
1089
|
+
type DrawOp = `d${Lane | "a"}`
|
|
1090
|
+
type PlayOp = POp | UOp
|
|
1091
|
+
type DiscardOp = XOp
|
|
1092
|
+
type CombatOp = `c${Lane}`
|
|
1093
|
+
|
|
1094
|
+
type Op = DrawOp | PlayOp | DiscardOp | CombatOp
|
|
1095
|
+
|
|
1096
|
+
type TraceDefender = "100101111" // 303
|
|
1097
|
+
type TraceAttacker = "101000000" // 320
|
|
1098
|
+
type Trace = TraceDefender | TraceAttacker
|
|
1099
|
+
|
|
1100
|
+
/* eslint-disable ts/consistent-type-definitions */
|
|
1101
|
+
interface PlayerFullsec { }
|
|
1102
|
+
interface PlayerHighsec { }
|
|
1103
|
+
interface PlayerMidsec { }
|
|
1104
|
+
interface PlayerLowsec { }
|
|
1105
|
+
interface PlayerNullsec { }
|
|
1106
|
+
/* eslint-enable ts/consistent-type-definitions */
|
|
1107
|
+
|
|
1108
|
+
/** Subscript space that can call FULLSEC scripts. */
|
|
1109
|
+
const $fs: Fullsec
|
|
1110
|
+
/** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
|
|
1111
|
+
const $hs: Highsec
|
|
1112
|
+
/**
|
|
1113
|
+
Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
|
|
1114
|
+
*/
|
|
1115
|
+
const $ms: Midsec
|
|
1116
|
+
/**
|
|
1117
|
+
Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
|
|
1118
|
+
*/
|
|
1119
|
+
const $ls: Lowsec
|
|
1120
|
+
/** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
|
|
1121
|
+
const $ns: Nullsec
|
|
1122
|
+
/** Subscript space that can call FULLSEC scripts. */
|
|
1123
|
+
const $4s: typeof $fs
|
|
1124
|
+
/** Subscript space that can call HIGHSEC and above scripts. Makes your script HIGHSEC (overrides FULLSEC). */
|
|
1125
|
+
const $3s: typeof $hs
|
|
1126
|
+
/**
|
|
1127
|
+
Subscript space that can call MIDSEC and above scripts. Makes your script MIDSEC (overrides higher security levels).
|
|
1128
|
+
*/
|
|
1129
|
+
const $2s: typeof $ms
|
|
1130
|
+
/**
|
|
1131
|
+
Subscript space that can call LOWSEC and above scripts. Makes your script LOWSEC (overrides higher security levels).
|
|
1132
|
+
*/
|
|
1133
|
+
const $1s: typeof $ls
|
|
1134
|
+
/** Subscript space that can call any script. Makes your script NULLSEC (overrides higher security levels). */
|
|
1135
|
+
const $0s: typeof $ns
|
|
1136
|
+
/* eslint-disable no-irregular-whitespace */
|
|
1137
|
+
/**
|
|
1138
|
+
* Subscript space that can call any script. Uses seclevel provided in comment before script (defaults to NULLSEC)
|
|
1139
|
+
* @example
|
|
1140
|
+
* // @seclevel MIDSEC
|
|
1141
|
+
* // note, do NOT copy paste the above line because there is a zero-width space inserted between "@" and "s"
|
|
1142
|
+
* export function script() {
|
|
1143
|
+
* $s.foo.bar() // will be converted to #ms.foo.bar()
|
|
1144
|
+
* }
|
|
1145
|
+
*/
|
|
1146
|
+
const $s: Nullsec
|
|
1147
|
+
/* eslint-enable no-irregular-whitespace */
|
|
1148
|
+
|
|
1149
|
+
const $db: {
|
|
1150
|
+
/**
|
|
1151
|
+
* Insert a document or documents into a collection.
|
|
1152
|
+
* @param documents A document or array of documents to insert into the collection.
|
|
1153
|
+
*/
|
|
1154
|
+
i: <T extends MongoDocument>(documents: (T & { _id?: MongoId }) | (T & { _id?: MongoId })[]) => { n: number, opTime: { t: number }, ok: 0 | 1 }[]
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* Remove documents from a collection.
|
|
1158
|
+
* @param query Specifies deletion criteria using query operators.
|
|
1159
|
+
*/
|
|
1160
|
+
r: <T extends MongoDocument>(query: MongoQuery<T>) => { n: number, opTime: { t: number }, ok: 0 | 1 }[]
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* Find documents in a collection or view and returns a cursor to the selected documents.
|
|
1164
|
+
* @param query Specifies deletion criteria using query operators.
|
|
1165
|
+
* @param projection Specifies the fields to return in the documents that match the query filter.
|
|
1166
|
+
*/
|
|
1167
|
+
f: <
|
|
1168
|
+
const TQuery extends MongoQueryObject & { _id?: MongoQueryId },
|
|
1169
|
+
const TProjection extends { [k: string]: boolean | 0 | 1 } = {}
|
|
1170
|
+
>(query: TQuery, projection?: TProjection) => Cursor<MongoProject<MongoQueryType<TQuery>, TProjection>>
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* Update existing documents in a collection.
|
|
1174
|
+
* @param query Specifies deletion criteria using query operators.
|
|
1175
|
+
* @param command The modifications to apply.
|
|
1176
|
+
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters}
|
|
1177
|
+
*/
|
|
1178
|
+
u: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) => { n: number, opTime: { t: number }, ok: 0 | 1, nModified: number }[]
|
|
1179
|
+
|
|
1180
|
+
/**
|
|
1181
|
+
* Updates one document within the collection based on the filter.
|
|
1182
|
+
* @param query Specifies deletion criteria using query operators.
|
|
1183
|
+
* @param command The modifications to apply.
|
|
1184
|
+
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters}
|
|
1185
|
+
*/
|
|
1186
|
+
u1: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) => { n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
|
|
1187
|
+
|
|
1188
|
+
/**
|
|
1189
|
+
* Update or insert document.
|
|
1190
|
+
* Same as Update, but if no documents match the query, one document will be inserted based on the properties in
|
|
1191
|
+
* both the query and the command.
|
|
1192
|
+
* The `$setOnInsert` operator is useful to set defaults.
|
|
1193
|
+
* @param query Specifies deletion criteria using query operators.
|
|
1194
|
+
* @param command The modifications to apply.
|
|
1195
|
+
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.update/#parameters}
|
|
1196
|
+
*/
|
|
1197
|
+
us: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) => { n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
|
|
1198
|
+
|
|
1199
|
+
ObjectId: () => MongoObjectId
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
/**
|
|
1203
|
+
* Debug Log.
|
|
1204
|
+
*
|
|
1205
|
+
* If `$D()` is called in a script you own, the `return` value of the top level script is suppressed and instead an
|
|
1206
|
+
* array of every `$D()`’d entry is printed.
|
|
1207
|
+
* This lets you use `$D()` like `console.log()`.
|
|
1208
|
+
*
|
|
1209
|
+
* `$D()` in scripts not owned by you are not shown but the `return` value always is.
|
|
1210
|
+
*
|
|
1211
|
+
* `$D()` returns the first argument so `$D("Hello, World!") evaluates to `"Hello, World!"` as if the `$D` text wasn't
|
|
1212
|
+
* there.
|
|
1213
|
+
*
|
|
1214
|
+
* `$D()`’d items are returned even if the script times out or errors.
|
|
1215
|
+
*/
|
|
1216
|
+
function $D<T>(args: T): T
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
* Function Multi-Call Lock.
|
|
1220
|
+
*
|
|
1221
|
+
* This is used by escrow to ensure that it is only used once in script execution.
|
|
1222
|
+
*
|
|
1223
|
+
* The first time (per-script) `$FMCL` is encountered, it returns `undefined`, every other time it `return`s `true`.
|
|
1224
|
+
*
|
|
1225
|
+
* @example
|
|
1226
|
+
* if ($FMCL)
|
|
1227
|
+
* return { ok: false, msg: "This script can only be used once per script execution." }
|
|
1228
|
+
*
|
|
1229
|
+
* // all code here will only run once
|
|
1230
|
+
*/
|
|
1231
|
+
const $FMCL: undefined | true
|
|
1232
|
+
/**
|
|
1233
|
+
* Per-script mutable "global" persistent object that is discarded at the end of top level script execution.
|
|
1234
|
+
*
|
|
1235
|
+
* `$G` persists between script calls until the end of the main script run making it useful for caching db entries when
|
|
1236
|
+
* your script is a subscript.
|
|
1237
|
+
* @example
|
|
1238
|
+
* if (!$G.dbCache)
|
|
1239
|
+
* $G.dbCache = $db.f({ whatever: true }).first()
|
|
1240
|
+
*/
|
|
1241
|
+
const $G: Record<string | symbol, any>
|
|
1242
|
+
/**
|
|
1243
|
+
* This contains a JS timestamp (not Date) set immediately before your code begins running.
|
|
1244
|
+
* @example
|
|
1245
|
+
* $D(Date.now() - _START) // milliseconds left of run time
|
|
1246
|
+
*/
|
|
1247
|
+
const _START: number
|
|
1248
|
+
/**
|
|
1249
|
+
* This contains a JS timestamp (not Date) set immediately before your code begins running.
|
|
1250
|
+
* @example
|
|
1251
|
+
* $D(Date.now() - _ST) // milliseconds left of run time
|
|
1252
|
+
*/
|
|
1253
|
+
const _ST: typeof _START
|
|
1254
|
+
/** JavaScript timestamp for the end of the script run (`_START + _TIMEOUT`). */ const _END: number
|
|
1255
|
+
/** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
|
|
1256
|
+
const _TIMEOUT: number
|
|
1257
|
+
/** The number of milliseconds a script can run for. Normally `5000` though it has been known to change. */
|
|
1258
|
+
const _TO: typeof _TIMEOUT
|
|
1259
|
+
/** A function to deep-clone an object. */ const _CLONE: <T>(obj: T) => T
|
|
1260
|
+
/** The source code of this script as a string. */ const _SOURCE: string
|
|
1261
|
+
/** A unix timestamp of the date this script was built. */ const _BUILD_DATE: number
|
|
1262
|
+
/**
|
|
1263
|
+
* The user this script has been uploaded to.
|
|
1264
|
+
*
|
|
1265
|
+
* Shorter alternative to `context.this_script.split(".")[0].
|
|
1266
|
+
*
|
|
1267
|
+
* In rare cases where it's not known at build time, it's `"UNKNOWN"`.
|
|
1268
|
+
*/
|
|
1269
|
+
const _SCRIPT_USER: string
|
|
1270
|
+
/** @deprecated Use `_SCRIPT_SUBNAME` instead. */
|
|
1271
|
+
const _SCRIPT_NAME: string
|
|
1272
|
+
/**
|
|
1273
|
+
* The name of this script excluding the user and `.`.
|
|
1274
|
+
*
|
|
1275
|
+
* e.g. in the script `foo.bar`, `_SCRIPT_NAME` is `bar`.
|
|
1276
|
+
*
|
|
1277
|
+
* Shorter alternative to `context.this_script.split(".")[1].
|
|
1278
|
+
*
|
|
1279
|
+
* In rare cases where it's not known at build time, it's `"UNKNOWN"`.
|
|
1280
|
+
*/
|
|
1281
|
+
const _SCRIPT_SUBNAME: string
|
|
1282
|
+
/**
|
|
1283
|
+
* The full name of this script equivilent to `context.this_script` but should use less characters.
|
|
1284
|
+
*
|
|
1285
|
+
* In rare cases where it's not known at build time, it's `"UNKNOWN"`.
|
|
1286
|
+
*/
|
|
1287
|
+
const _FULL_SCRIPT_NAME: string
|
|
1288
|
+
/**
|
|
1289
|
+
* The seclevel of this script as a number.
|
|
1290
|
+
*
|
|
1291
|
+
* In rare cases where it's not known at build time, it's `-1`.
|
|
1292
|
+
*/
|
|
1293
|
+
const _SECLEVEL: -1 | 0 | 1 | 2 | 3 | 4
|
|
1294
|
+
/**
|
|
1295
|
+
* Recursively
|
|
1296
|
+
* [`Object.freeze()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
|
|
1297
|
+
* an object and its properties' objects and its properties' objects and so on.
|
|
1298
|
+
*
|
|
1299
|
+
* [Official Hackmud Wiki](https://wiki.hackmud.com/scripting/extensions/deep_freeze)
|
|
1300
|
+
*/
|
|
1301
|
+
const DEEP_FREEZE: <T>(value: T) => DeepFreeze<T>
|
|
1302
|
+
const _RUN_ID: string
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
export { }
|