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