forked from RoxCian/TheAsphyxiaOfEternity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasphyxia-core.d.ts
1111 lines (1038 loc) · 29.6 KB
/
asphyxia-core.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
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
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/// <reference types="node" />
///// <reference types="lodash" />
/**
* Version string of Asphyxia CORE, for example "v1.19"
*/
declare const CORE_VERSION: string;
/**
* Major version of Asphyxia CORE, for version `v1.19`, this number is 1.
*/
declare const CORE_VERSION_MAJOR: number;
/**
* Minor version of Asphyxia CORE, for version `v1.19`, this number is 19.
*/
declare const CORE_VERSION_MINOR: number;
declare type KNumberType =
| 's8'
| 'u8'
| 's16'
| 'u16'
| 's32'
| 'u32'
| 'time'
| 'ip4'
| 'float'
| 'double'
| 'bool';
declare type KBigIntType = 's64' | 'u64';
declare type KNumberGroupType =
| '2s8'
| '2u8'
| '2s16'
| '2u16'
| '2s32'
| '2u32'
| '2f'
| '2d'
| '3s8'
| '3u8'
| '3s16'
| '3u16'
| '3s32'
| '3u32'
| '3f'
| '3d'
| '4s8'
| '4u8'
| '4s16'
| '4u16'
| '4s32'
| '4u32'
| '4f'
| '4d'
| '2b'
| '3b'
| '4b'
| 'vb';
declare type KBigIntGroupType =
| '2s64'
| '2u64'
| '3s64'
| '3u64'
| '4s64'
| '4u64'
| 'vs8'
| 'vu8'
| 'vs16'
| 'vu16';
/**
* Attribute object
*/
declare type KAttrMap = { [key: string]: string };
/**
* Supported response encoding
*/
declare type KEncoding = 'shift_jis' | 'utf8' | 'euc-jp' | 'ascii' | 'iso-8859-1';
/**
* Information about requester
*/
declare interface EamuseInfo {
module: string;
method: string;
model: string;
}
/**
* Details of a config
*/
declare interface ConfigOption {
/** Provide a name to display in WebUI. If not provided, WebUI will use key as the name. */
name?: string;
/** Provide a description for the option */
desc?: string;
/** Type of the option */
type: 'string' | 'integer' | 'float' | 'boolean';
/** Only applies to 'integer' and 'float' */
range?: [number, number];
/** Validator for notify user about invalid values. return `true` to pass the validation. return a string to send a error message to WebUI. */
validator?: (data: string) => true | string;
/** Only applies to 'string', provide options in a dropdown menu. */
options?: string[];
/** Indicate whether user need to restart CORE to see changes. */
needRestart?: boolean;
/** Default value of the option */
default: any;
}
/**
* Details of a data file
*/
declare interface FileOption {
/** Provide a name to display in WebUI. If not provided, WebUI will use filename as the label. */
name?: string;
/** Provide a description for the entry */
desc?: string;
/** The accept attribute of the file input element. See [[https://www.w3schools.com/tags/att_input_accept.asp]] */
accept?: string;
/**
* Whether the file is required for the plugin to work, defaults to false.
*
* Note that this only provides visual hint for the file in WebUI.
*/
required?: boolean;
}
/**
* Response options
*/
declare interface EamuseSendOption {
status?: number;
/**
* Encode response with specified encoding
* Default: 'SHIFT_JIS'
*/
encoding?: KEncoding;
/**
* Replace response root tag name.
* Default to child tag name of request <call> tag,
* which is usually the case and don't need to be replaced.
*/
rootName?: string;
compress?: boolean;
kencode?: boolean;
encrypt?: boolean;
}
declare interface EamuseSend {
/**
* Send empty response with status code 0
*/
success: (options?: EamuseSendOption) => Promise<void>;
/**
* Send empty response with status code 1
*/
deny: (options?: EamuseSendOption) => Promise<void>;
/**
* Send empty response with custom status code
*/
status: (code: number, options?: EamuseSendOption) => Promise<void>;
/**
* Send plain javascript object.
* When constructing objects, make sure to use helper [[K]]:
* ```
* {
* outer: K.ATTR({ status: "1" }, {
* inner: K.ITEM("s32", 1)
* })
* }
* ```
*
* Or follow xml-like format manually:
* ```
* {
* outer: {
* "@attr": { status: "1" },
* inner: {
* "@attr": { __type: "s32" },
* "@content": [1]
* }
* }
* }
* ```
* @param res xml-like formatted javascript object
* @param options Response options. See: [[EamuseSendOption]]
*/
object: (res: any, options?: EamuseSendOption) => Promise<void>;
/**
* Send xml data using ejs template system.
*
* @param res xml string as the template
* @param data Render template with specified data,
* pass null or undefined to render static xml
* @param options Response options. See: [[EamuseSendOption]]
*/
xml: (res: string, data?: any, options?: EamuseSendOption) => Promise<void>;
/**
* Send xml data using pug template system.
*
* @param res pug string as the template
* @param data Render template with specified data,
* pass null or undefined to render static xml
* @param options Response options. See: [[EamuseSendOption]]
*/
pug: (res: string, data?: any, options?: EamuseSendOption) => Promise<void>;
/**
* Render and send ejs template from a file
*
* @param file Filename of the template
* @param data Render template with specified data,
* pass null or undefined to render static xml
* @param options Response options. See: [[EamuseSendOption]]
*/
xmlFile: (file: string, data?: any, options?: EamuseSendOption) => Promise<void>;
/**
* Render and send pug template from a file
*
* @param file Filename of the template
* @param data Render template with specified data,
* pass null or undefined to render static xml
* @param options Response options. See: [[EamuseSendOption]]
*/
pugFile: (file: string, data?: any, options?: EamuseSendOption) => Promise<void>;
}
/**
* Helper type for typing your custom route.
*/
declare type EamusePluginRoute = (req: EamuseInfo, data: any, send: EamuseSend) => Promise<any>;
/**
* Helper type for typing your custom route.
*
* Alias for [[EamusePluginRoute]]
*/
declare type EPR = EamusePluginRoute;
/**
* R stands for `Register`
*
* These functions can only be called in plugins' `register()` function.
*/
declare namespace R {
/**
* Register your custom route.
*
* You should only call this from your plugin's `register()` function.
*
* @param method Method name of your target route,
* usually looks like `"module.get"`
* @param handler Your custom route function/method following the type [[EamusePluginRoute]].
* A boolean can be passed if you don't need any processing:
* - `true`: Sending empty response with status code 0
* - `false`: Sending empty response with status code 1
*/
function Route(method: string, handler: EamusePluginRoute | boolean): void;
/**
* Register all unhandled routes for a game.
*
* You should only call this from your plugin's `register()` function.
*
* @param handler Your custom route function/method following the type [[EamusePluginRoute]].
* If undefined, the router will apply a default handler that prints method names.
*/
function Unhandled(handler?: EamusePluginRoute): void;
/**
* Register a target game code to your plugin for checking savedata.
*
* You should only call this from your plugin's `register()` function.
*
* @param code Model code of your target machine,
* usually __three capital letters__
*
*/
function GameCode(code: string): void;
/**
* Register a contributor.
*
* Contributors will show up in WebUI.
*
* @param name Contributor's name
* @param link Contributor's homepage
*/
function Contributor(name: string, link?: string): void;
/**
* Register a configuration option.
*
* @param key config key
* @param options See [[ConfigOption]]
*
* __NOTE__: `options.validator` will only notify user about invalid value. It wouldn't stop user from saving invalid value.
*/
function Config(key: string, options: ConfigOption): void;
/**
* Register a data file upload entry.
*
* @param path a path (with filename) where the uploaded file will be saved to.
* @param options See [[FileOption]]
*
*/
function DataFile(path: string, options?: FileOption): void;
/**
* Register a WebUI event callback
*
* Which can be called in WebUI using `emit(event)` function or a post message to `/emit/<event>`
*
* Callback can be async function if you want to use await for your DB operations.
*/
function WebUIEvent(event: string, callback: (data: any) => void | Promise<void>): void;
}
/**
* A wrapper of javascript object for reading xml-like formatted data.
*/
declare class KDataReader {
/**
* Wrapped javascript object
*/
public obj: any;
constructor(obj: any);
/**
* Get attributes for a tag
*
* Example:
* ```xml
* <data>
* <tag status="1">
* <inner __type="s32">1</inner>
* <inner __type="s32">2</inner>
* </tag>
* </data>
* ```
* ```javascript
* const data = {
* tag: K.ATTR({ status: "1" }, {
* inner: [
* K.ITEM("s32", 1),
* K.ITEM("s32", 2)
* ]
* })
* }
* ```
*
* Eval:
* ```javascript
* $(data).attr("tag") // { status: "1" }
* $(data).element("tag").attr().status // "1"
* $(data).attr("tag.inner.0").__type // "s32"
* ```
*/
attr(path?: string): KAttrMap;
/**
* Get a bigint value from a tag, convert to bigint if applicable.
*
* Example:
* ```xml
* <data>
* <inner __type="s64">1</inner>
* <inner __type="s32">2</inner>
* <invalid __type="str">abc</invalid>
* </data>
* ```
* ```javascript
* const data = {
* inner: [
* K.ITEM("s64", 1n),
* K.ITEM("s32", 2)
* ],
* invalid: K.ITEM("str", "abc")
* }
* ```
*
* Eval:
* ```javascript
* $(data).element("inner").bigint() // 1n
* $(data).bigint("inner.1") // 2n
* $(data).bigint("invalid", 3n) // 3n
* ```
*
* @param def Default return value when target path does
* not exists or is not valid.
*/
bigint(path: string, def?: bigint): bigint;
/**
* Get a bigint array from a tag. Only returns valid arrays
* when target tag has a type of [[KBigIntType]] or [[KBigIntGroupType]]
*
* Example:
* ```xml
* <data>
* <inner __type="s64" __count="2">1 2</inner>
* <invalid __type="s32" __count="2">3 4</invalid>
* </data>
* ```
* ```javascript
* const data = {
* inner: K.ARRAY("s64", [1n, 2n]),
* invalid: K.ARRAY("s32", [3, 4])
* }
* ```
*
* Eval:
* ```javascript
* $(data).bigints("inner") // [1n, 2n]
* $(data).bigints("invalid") // undefined
* ```
*/
bigints(path: string, def?: bigint[]): bigint[];
/**
* Get a boolean value from a tag, return true only if value in the tag is number and **greater than zero**
*
* Example:
* ```xml
* <data>
* <inner __type="bool">0</inner>
* <inner __type="s32">2</inner>
* </data>
* ```
* ```javascript
* const data = {
* inner: [
* K.ITEM("bool", false),
* K.ITEM("s32", 2)
* ]
* }
* ```
*
* Eval:
* ```javascript
* $(data).bool("inner.0") // false
* $(data).bool("inner.1") // true
* $(data).bool("invalid") // false
* ```
*/
bool(path: string): boolean;
/**
* Get a Buffer object from a tag, Only returns valid Buffer
* when target tag has a type of "bin"
*
* Example:
* ```xml
* <data>
* <inner __type="bin">00ff</inner>
* <invalid __type="u8" __count="3">1 2 3</invalid>
* </data>
* ```
* ```javascript
* const data = {
* inner: K.ITEM("bin", Buffer.from([0x00, 0xff])),
* invalid: K.ARRAY("u8", [1, 2, 3])
* }
* ```
*
* Eval:
* ```javascript
* $(data).buffer("inner") // <Buffer 00 ff>
* $(data).buffer("invalid") // undefined
* ```
*/
buffer(path: string, def?: Buffer): Buffer;
/**
* Get raw content representation regardless of tag type
*
* Example:
* ```xml
* <data>
* <number __type="s32">1</number>
* <array __type="u8" __count="3">1 2 3</array>
* <string __type="str">abc</string>
* </data>
* ```
* ```javascript
* const data = {
* number: K.ITEM("s32", 1),
* array: K.ARRAY("u8", [1, 2, 3]),
* string: K.ITEM("str", "abc")
* }
* ```
*
* Eval:
* ```javascript
* $(data).content("number") // [1]
* $(data).content("array") // [1, 2, 3]
* $(data).content("string") // "abc"
* ```
*/
content(path: string, def?: any): any;
/**
* Get first element named **path** inside a tag
*
* Example:
* ```xml
* <data>
* <inner>
* <id __type="s32">1</id>
* </inner>
* <inner>
* <id __type="s32">1</id>
* </inner>
* </data>
* ```
* ```javascript
* const data = {
* inner: [
* { id: K.ITEM("s32", 1) },
* { id: K.ITEM("s32", 2) }
* ]
* }
* ```
*
* Eval:
* ```javascript
* $(data).element("inner") // <KDataReader>
* $(data).element("inner").obj // { id: [object] }
* $(data).element("inner").number("id") // 1
* ```
*/
element(path: string): KDataReader;
/**
* Get array of all elements named **path** inside a tag
*
* Example:
* ```xml
* <data>
* <inner>
* <id __type="s32">1</id>
* </inner>
* <inner>
* <id __type="s32">1</id>
* </inner>
* </data>
* ```
* ```javascript
* const data = {
* inner: [
* { id: K.ITEM("s32", 1) },
* { id: K.ITEM("s32", 2) }
* ]
* }
* ```
*
* Eval:
* ```javascript
* $(data).elements("inner") // [<KDataReader>, <KDataReader>]
* $(data).elements("inner")[1].number("id") // 2
* ```
*/
elements(path: string): KDataReader[];
/**
* Get a number value from a tag, convert to number if applicable.
*
* Example:
* ```xml
* <data>
* <inner __type="s64">1</inner>
* <inner __type="s32">2</inner>
* <invalid __type="str">abc</invalid>
* </data>
* ```
* ```javascript
* const data = {
* inner: [
* K.ITEM("s64", 1n),
* K.ITEM("s32", 2)
* ],
* invalid: K.ITEM("str", "abc")
* }
* ```
*
* Eval:
* ```javascript
* $(data).element("inner").number() // 1
* $(data).number("inner.1") // 2
* $(data).number("invalid", 3) // 3
* ```
*
* @param def Default return value when target path does
* not exists or is not valid.
*/
number(path: string, def?: number): number;
/**
* Get a number array from a tag. Only returns valid arrays
* when target tag has a type of [[KNumberType]] or [[KNumberGroupType]]
*
* Example:
* ```xml
* <data>
* <inner __type="s64" __count="2">1 2</inner>
* <invalid __type="s32" __count="2">3 4</invalid>
* </data>
* ```
* ```javascript
* const data = {
* invalid: K.ARRAY("s64", [1n, 2n]),
* inner: K.ARRAY("s32", [3, 4])
* }
* ```
*
* Eval:
* ```javascript
* $(data).bigints("invalid") // undefined
* $(data).bigints("inner") // [3, 4]
* ```
*/
numbers(path: string, def?: number[]): number[];
/**
* Get a string from a tag, Only returns valid string
* when target tag has a type of "str"
*
* Example:
* ```xml
* <data>
* <inner __type="str">abc</inner>
* <invalid __type="s32">1</invalid>
* </data>
* ```
* ```javascript
* const data = {
* inner: K.ITEM("str", "abc"),
* invalid: K.ITEM("s32", 1)
* }
* ```
*
* Eval:
* ```javascript
* $(data).str("inner") // "abc"
* $(data).str("invalid") // undefined
* ```
*/
str(path: string, def?: string): string;
}
/**
* Helper for reading xml-like formatted data.
*/
declare function $(data: any): KDataReader;
declare namespace $ {
function ATTR(data: any, path?: string): KAttrMap;
function BIGINT(data: any, path: string, def?: bigint): bigint;
function BIGINTS(data: any, path: string, def?: bigint[]): bigint[];
function BOOL(data: any, path: string): boolean;
function BUFFER(data: any, path: string, def?: Buffer): Buffer;
function CONTENT(data: any, path: string, def?: any): any;
function ELEMENT(data: any, path: string, def?: any): any;
function ELEMENTS(data: any, path: string, def?: any): any;
function NUMBER(data: any, path: string, def?: number): number;
function NUMBERS(data: any, path: string, def?: number[]): number[];
function STR(data: any, path: string, def?: string): string;
}
/** @ignore */
declare interface KITEM<
S extends
| KNumberType
| KBigIntType
| KNumberGroupType
| KBigIntGroupType
| 'str'
| 'bool'
| 'bin'
| 'ip4'
> {
'@attr': {
__type: S;
};
'@content': S extends 'str'
? string
: S extends 'bin'
? Buffer
: S extends KNumberType | 'ip4' | 'bool'
? [number]
: S extends KBigIntType
? [bigint]
: S extends KNumberGroupType
? number[]
: S extends KBigIntGroupType
? bigint[]
: unknown;
}
/** @ignore */
declare interface KARRAY<S extends KNumberType | KBigIntType> {
'@attr': {
__count: number;
__type: S;
};
'@content': S extends KNumberType ? number[] : S extends KBigIntType ? bigint[] : unknown;
}
/** @ignore */
declare interface KATTR<M> {
'@attr': M;
}
/**
* K stands for `Konstruct`
*
* Helper for constructing xml-like javascript object.
*/
declare namespace K {
/**
* Example:
* ```
* {
* tag: K.ATTR({attr: "1"}, {
* inner: [{}, {}]
* })
* }
* ```
* Represents:
* ```
* <tag attr="1">
* <inner/>
* <inner/>
* </tag>
* ```
* @param attr Attribute map
* @param inner Inner tag/data
*/
function ATTR<M extends KAttrMap, T>(attr: M, inner?: T): KATTR<M> & T;
/**
* Example:
* ```
* {
* tag: K.ITEM('s32', 1, {attr: "2"})
* }
* ```
* Represents:
* ```
* <tag __type="s32" attr="2">1</tag>
* ```
* @param type ____type__ attribute, which is used during encoding and compression
* @param content data of specified type
* @param attr attribute map in addition to **__type**
*/
function ITEM(type: 'str', content: string, attr?: KAttrMap): KITEM<'str'>;
function ITEM(type: 'bin', content: Buffer, attr?: KAttrMap): KITEM<'bin'>;
function ITEM(type: 'ip4', content: string, attr?: KAttrMap): KITEM<'ip4'>;
function ITEM(type: 'bool', content: boolean, attr?: KAttrMap): KITEM<'bool'>;
function ITEM<S extends KNumberType>(type: S, content: number, attr?: KAttrMap): KITEM<S>;
function ITEM<S extends KBigIntType>(type: S, content: bigint, attr?: KAttrMap): KITEM<S>;
function ITEM<S extends KNumberGroupType>(type: S, content: number[], attr?: KAttrMap): KITEM<S>;
function ITEM<S extends KBigIntGroupType>(type: S, content: bigint[], attr?: KAttrMap): KITEM<S>;
/**
* Example:
* ```
* {
* tag: K.ARRAY('s32', [1, 2, 3], {attr: "4"})
* }
* ```
* Represents:
* ```
* <tag __type="s32" __count="3" attr="2">1 2 3</tag>
* ```
* @param type ____type__ attribute, which is used during encoding and compression
* @param content array of data, ____count__ attribute will be automatically set to `content.length`
* @param attr attribute map in addition to **__type** and **__count**
*/
function ARRAY<S extends 'u8' | 's8'>(type: S, content: Buffer, attr?: KAttrMap): KARRAY<S>;
function ARRAY<S extends KNumberType>(type: S, content: number[], attr?: KAttrMap): KARRAY<S>;
function ARRAY<S extends KBigIntType>(type: S, content: bigint[], attr?: KAttrMap): KARRAY<S>;
}
/**
* Filesystem IO
*
* These are designed to match nodejs `fs` module.
*
* __DO NOT__ use IO for savedata. Please use [[DB]] namespace so your data can be managed by WebUI.
*
* Also, due to difference between operating systems, you should always prepare your files using ascii path.
* Both UTF-8 and local encodings will have cross-platform compatibility issues.
*/
declare namespace IO {
/**
* Resolve a relative path starting from your plugin directory to an absolute path.
*/
function Resolve(path: string): string;
/**
* Synchronously tests whether or not the given path exists by checking with the file system.
* @param path
* A path to a file or directory. If a URL is provided, it must use the file: protocol. URL support is experimental.
*/
function Exists(path: string): boolean;
/**
* Asynchronously read a directory.
* @param path A path to a directory.
*/
function ReadDir(path: string): Promise<{ name: string; type: 'file' | 'dir' | 'unsupported' }[]>;
/**
* Asynchronously writes data to a file, replacing the file if it already exists.
* @param path A path to a file.
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
* @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
* @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
* If `encoding` is not supplied, the default of `'utf8'` is used.
* If `mode` is not supplied, the default of `0o666` is used.
* If `mode` is a string, it is parsed as an octal integer.
* If `flag` is not supplied, the default of `'w'` is used.
*/
function WriteFile(
path: string,
data: any,
options: { encoding?: string | null; mode?: number | string; flag?: string } | string | null
): Promise<void>;
/**
* Asynchronously writes data to a file, replacing the file if it already exists.
* @param path A path to a file.
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
* @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
*/
function WriteFile(path: string, data: any): Promise<void>;
/**
* Asynchronously reads the entire contents of a file.
* @param path A path to a file.
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
* @param options An object that may contain an optional flag.
* If a flag is not provided, it defaults to `'r'`.
*
* Returns null if any error occurs while reading a file
*/
function ReadFile(
path: string,
options: { encoding?: null; flag?: string } | undefined | null
): Promise<Buffer | null>;
/**
* Asynchronously reads the entire contents of a file.
* @param path A path to a file.
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
* @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
* If a flag is not provided, it defaults to `'r'`.
*
* Returns null if any error occurs while reading a file
*/
function ReadFile(
path: string,
options: { encoding: string; flag?: string } | string
): Promise<string | null>;
/**
* Asynchronously reads the entire contents of a file.
* @param path A path to a file.
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
* @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
* If a flag is not provided, it defaults to `'r'`.
*
* Returns null if any error occurs while reading a file
*/
function ReadFile(
path: string,
options: { encoding?: string | null; flag?: string } | string | undefined | null
): Promise<string | Buffer | null>;
/**
* Asynchronously reads the entire contents of a file.
* @param path A path to a file.
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
*
* Returns null if any error occurs while reading a file.
*/
function ReadFile(path: string): Promise<Buffer | null>;
}
/**
* U stands for `Utilities`
*
* You can find miscellaneous helpers here
*/
declare namespace U {
/**
* Convert json data to xml string.
*
* @param data xml-like javascript object
*/
function toXML(data: any): string;
/**
* Convert xml string to javascript object. Output will always be plain javascript string.
*
* @param xml xml string
* @param simplify if true, the parser will ignore attributes and only generate string values. (default: true)
*/
function parseXML(xml: string, simplify?: boolean): any;
/**
* Get config from user configuration file.
* @param key
*/
function GetConfig(key: string): any;
/**
* Convert Card Number / Data Transfer Number to NFC serial
*
* returns null if the card number is invalid
* @param card Card Number / Data Transfer Number
*/
function Card2NFC(card: string): string | null;
/**
* Convert NFC serial to Card Number or Data Transfer Number
*
* returns null if the nfc serial is invalid
* @param card Card Number or Data Transfer Number
*/
function NFC2Card(nfc: string): string | null;
}
/** @ignore */
type Doc<T> = { _id?: string } & T;
/** @ignore */
type ProfileDoc<T> = { _id?: string; __refid?: string } & T;
/** @ignore */
type Query<T> = {
[P in keyof T]?:
| T[P]
| (T[P] extends Array<infer E>
? { $elemMatch: Query<E[]> } | { $size: number }
: T[P] extends number | string
?
| { $lt: T[P] }
| { $lte: T[P] }
| { $gt: T[P] }
| { $gte: T[P] }
| { $in: T[P][] }
| { $ne: any }
| { $nin: any[] }
| { $regex: RegExp }
: T[P] extends object
? Query<T[P]>
: T[P])
| { $exists: boolean };
} & {
$or?: Query<T>[];
$and?: Query<T>[];
$not?: Query<T>;
$where?: (this: T) => boolean;
_id?: string;
[path: string]: any;
};
/** @ignore */
type Operators = '$exists' | '$lt' | '$lte' | '$gt' | '$gte' | '$in' | '$ne' | '$nin' | '$regex';
/** @ignore */
type PickyOperator<T, C, F> = Pick<
{
[P in keyof T]?: T[P] extends C ? F : Omit<T[P], Operators>;
},
{
[P in keyof T]: T[P] extends C ? P : never;
}[keyof T]
>;
/** @ignore */
type ArrayPushOperator<T> = Pick<
{
[P in keyof T]?: T[P] extends Array<infer E> ? E | { $each?: E[]; $slice?: number } : never;
},
{ [P in keyof T]: T[P] extends Array<any> ? P : never }[keyof T]
> & { [path: string]: any | { $each?: any[]; $slice?: number } };
/** @ignore */
type ArraySetOperator<T> = Pick<