-
Notifications
You must be signed in to change notification settings - Fork 7
/
webinizer.d.ts
1551 lines (1462 loc) · 44.9 KB
/
webinizer.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
/*-------------------------------------------------------------------------------------------------
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* Licensed under the Apache License 2.0. See LICENSE in the project root for license information.
* SPDX-License-Identifier: Apache-2.0
*-----------------------------------------------------------------------------------------------*/
declare module "webinizer" {
/**
* Initialize all the modules and extensions of webinizer.
*/
export function init(): Promise<void>;
/**
* Initialize modules from directories.
* @param dir The directory for modules to load from.
*/
export function loadAllModulesInDirctory(dir: string): Promise<void>;
/**
* Create the logger object.
*
* @example
* ```ts
* const log = getLogger("demo");
* log.info("This is a test for logger.");
* ```
*
* @param category The name of the logger.
* @returns The logging utilities.
*/
export function getLogger(category: string): ILogger;
/**
* The logging utilities with different logging levels, a replacement for `console`.
*/
export interface ILogger {
debug(...args: any[]): void;
/**
* Log with the info level. Use this for basic logging.
*/
info(...args: any[]): void;
warn(...args: any[]): void;
error(...args: any[]): void;
}
/**
* An object that manages project configurations and build process.
*/
export class Project {
/**
* The absolute path to the project root.
*/
readonly root: string;
/**
* The project config object.
*/
readonly config: IProjectConfig;
/**
* The project log object.
*/
readonly log: IProjectLog;
/**
* The file change manager object to manage all {@link FileChangeAction}.
*/
readonly fileChangeManager: IFileChangeManager;
/**
* The build step change manager object to manage all {@link BuildStepChangeAction}.
*/
readonly buildStepChangeManager: IBuildStepChangeManager;
/**
* Whether the project is a root project (`true`) or a dependency (`false`).
*/
readonly isRootProject: boolean;
/**
* The available template literals constants.
*/
readonly constant: Record<ProjectConstType, string>;
/**
* Create the `Project` object.
* @param root The absolute path to the project root.
* @param isRoot Whether the project is a root project (`true`) or a dependency (`false`).
*/
constructor(root: string, isRoot?: boolean);
/**
* Get available template literals and corresponding value.
* @param withMarkdown Whether format the output string in markdown format or not. The default value is false.
* @returns The array of each template literal, in the format of `${projectRoot} = /path/tp/project/root`.
*/
getTemplateLiterals(withMarkdown?: boolean): string[];
/**
* Get the actual value of a string containing template literals.
* @param s The string that contains template literal.
* @returns The string of actual value.
*/
evalTemplateLiterals(s: string): string;
/**
* Validate the template literals in a string.
* @param s The string that contains template literal.
* @returns The array of invalid template literal.
*/
validateTemplateLiterals(s: string): string[];
/**
* Backup the config files.
*/
backupConfigFiles(): void;
/**
* Restore the config files.
*/
restoreConfigsFromBackupFiles(): void;
/**
* Cleanup the backup config files.
*/
cleanBackupFiles(): void;
/**
* Build the project.
* @param res Recipes to apply to the build.
* @returns Recipes generated in the build.
*/
build(res: Recipe[] | null): Promise<Recipe[]>;
}
/**
* The available template literals used in project configuration.
*
* - `projectDist`: represents the project distribution directory.
* - `projectRoot`: represents the absolute project root path.
* - `projectPool`: represents the project pool directory.
*/
export type ProjectConstType = "projectDist" | "projectRoot" | "projectPool";
/**
* An object represents the project build log.
*/
export interface IProjectLog extends IToJson {
/**
* Get the log content.
* @returns The log content.
*/
getContent(): string;
/**
* Update the log content.
* @param content The content to be updated to the log file.
*/
update(content: string): void;
}
/**
* An object represents the project configs.
*/
export interface IProjectConfig extends IToJson {
/**
* The absolute path to the config file.
*/
readonly path: string;
/**
* A reference to the {@link Project} object.
*/
readonly proj: Project;
/**
* The project name.
*/
readonly name: string | undefined;
/**
* The project version.
*/
readonly version: string | undefined;
/**
* The project description.
*/
readonly desc: string | undefined;
/**
* The project icon.
*/
readonly img: IProjectIcon | undefined;
/**
* The project keywords.
*/
readonly keywords: string[] | undefined;
/**
* The project homepage address.
*/
readonly homepage: string | undefined;
/**
* The project's issue tracker address.
*/
readonly bugs: string | undefined;
/**
* The project license.
*/
readonly license: string | undefined;
/**
* The project author.
*/
readonly author: IProjectPerson | undefined;
/**
* The project repository address.
*/
readonly repository: IProjectRepository | undefined;
/**
* The build target for the project. Currently we only support value `static` and `shared`.
*
* - `static` build target means to build your project with static linking. All dependent libraries will be built into
* Wasm archive files (.a), and then linked to the main project to get a standalone Wasm module with no external
* dependencies.
*
* - `shared` build target means to build your project with dynamic linking. All dependent libraries will be built into
* Wasm binary files (.wasm/.so) as side modules (using flag -sSIDE_MODULE), whose exports will be dynamically imported
* into the context of main project's Wasm module (using flag -sMAIN_MODULE) by JavaScript glue code.
*/
readonly target: string | undefined;
/**
* Whether the project is a library or not (an application).
*/
readonly isLibrary: boolean | undefined;
/**
* The overall environment variables (compiler flags and linker flags) aggregated from this project and its dependent project(s).
*/
readonly overallEnvs: ProjectEnv | undefined;
/**
* The project raw dependencies, in the format of `{ foo: "^1.0.0" }`, represents the
* `dependencies` field in the config.
*/
readonly rawDependencies: { [k: string]: string } | undefined;
/**
* The packages that depends on this project, in the format of `{ foo: "^1.0.0" }`,
* which denotes the opposite of `dependencies` field in the config.
*/
readonly requiredBy: { [k: string]: string } | undefined;
/**
* Get a specific overall environment variable.
* @param key The environment variable name.
* @returns The value of this environment variable.
*/
getOverallEnv(key: EnvType): string;
/**
* Get the `ProjectBuildConfig` object for a specific build target.
* @param target The build target.
* @returns The `ProjectBuildConfig` object for the target.
*/
getBuildConfigForTarget(target: string | undefined): IProjectBuildConfig;
/**
* Update the overall environment variables value from the environment variables update of this project.
* @param envs The environment variables of this project.
*/
updateOverallEnvsFromSelf(envs: ProjectEnv | undefined): void;
/**
* Update the overall environment variables value from the dependent project(s).
*/
updateOverallEnvsFromDeps(): Promise<void>;
/**
* Update the config file.
* @param jsonParts The to be updated config fields and corresponding values.
*/
updateRawJson(jsonParts: { [k: string]: unknown }): Promise<void>;
/**
* Conver the config file to the metadata file.
*/
convertToRegMetaFromConfig(): void;
/**
* Convert the config file to the metadata file for publish. More fields are converted in this method
* compared to those of {@link convertToRegMetaFromConfig}, such as `toolchain`, etc.
*/
convertToRegMetaForPublish(): Promise<void>;
/**
* Convert the metadata file to the config file.
* @param diffContent The metadata fields to be converted. The default value is the whole metadata fields
* in `package.json`.
*/
convertFromRegMeta(diffContent?: { [k: string]: unknown }): Promise<void>;
}
/**
* The environment variables type.
*
* - `cflags` - the compiler flags.
* - `ldflags` - the linker flags.
*/
export type EnvType = "cflags" | "ldflags";
/**
* An object represents the project environment variables.
*/
export type ProjectEnv = Record<EnvType, string>;
/**
* The package configuration properties.
*/
export type PkgConfigType = "prefix" | EnvType;
/**
* An object represents the package configurations of a library project. Explainations for each property are:
*
* - `prefix`: The install prefix of the library.
* - `cflags`: The compiler flags that will be acquired by the main project depending on this library to
* search for the header files (i.e., the `-I` options).
* - `ldflags`: The linker flags that will be acquired by the main project depending on this library to
* search for and identify the library files (i.e., the `-L`, `-l` options).
*/
export type ProjectPkgConfig = {
[k in PkgConfigType]: string;
};
/**
* An object represents the project icon.
*/
export interface IProjectIcon {
/**
* Icon name.
*/
name: string;
/**
* The flag whether this icon is uploaded.
*/
isUploaded: boolean;
}
/**
* An object represents a person.
*/
export interface IProjectPerson {
/**
* Person name.
*/
name: string;
/**
* Email address.
*/
email?: string;
/**
* Peronal homepage address.
*/
url?: string;
}
/**
* An object represents the project repository.
*/
export interface IProjectRepository {
/**
* Repository type, i.e., git.
*/
type: string;
/**
* The URL to the project repository.
*/
url: string;
}
/**
* An object represents the project build options.
*/
export interface IProjectBuildOptions {
/**
* Option for support on infinite main loop.
*/
needMainLoop?: boolean;
/**
* Option for support on pthread.
*/
needPthread?: boolean;
/**
* Options for support on C++ exception catching.
*/
needCppException?: boolean;
/**
* Option for support on Wasm SIMD.
*/
needSimd?: boolean;
/**
* Option for support on generating modularized JS glue code.
*/
needModularize?: boolean;
}
/**
* The build option type.
*/
export type BuildOptionType = keyof IProjectBuildOptions;
/**
* Options for updating build config.
*/
export interface IBuildConfigUpdateOptions {
/**
* The array of updated environment variable name. The default value is the
* array contains all environment variable names `["cflags", "ldflags"]`.
*/
updateEnvParts?: EnvType[];
/**
* The array of updated options name. The default value is the array contains
* all options names.
*/
updateOptParts?: BuildOptionType[];
/**
* Whether to refresh the build config based on the updated data or not after
* updating the build config JSON data. The default is true to refresh.
*/
refresh?: boolean;
}
/**
* An object represents the build config for a build {@link IProjectConfig.target}.
*/
export interface IProjectBuildConfig {
/**
* The build target that this `ProjectBuildConfig` object corresponding to.
* Details for a build target is explained in {@link IProjectConfig.target}.
*/
readonly target: string;
/**
* The `builders` field JSON data in config file.
*/
readonly rawBuilders: IJsonObject[] | undefined;
/**
* The IBuilders object array created from the {@link rawBuilders}.
*/
readonly builders: IBuilder[] | null;
/**
* A string array of file paths to preload.
*/
readonly preloadFiles: string[] | undefined;
/**
* A string of exported native function names, separated by comma.
*/
readonly exportedFuncs: string | undefined;
/**
* A string of exported runtime methods in JavaScript glue code from Emscripten,
* separated by comma.
*/
readonly exportedRuntimeMethods: string | undefined;
/**
* The environment variables object defined for build, containing keys `cflags`
* and `ldflags`.
*/
readonly envs: ProjectEnv | undefined;
/**
* The options object defined for build.
*/
readonly rawOptions: IProjectBuildOptions | null;
/**
* The disabled advisors object. The key should be a advisor type {@link IAdvisor.type}, the value `true`
* means the corresponding advisor is disabled.
*/
disabledAdvisors: { [k: string]: boolean } | null;
/**
* The package configurations of the project. This field must be defined for a library project.
*/
pkgConfig: ProjectPkgConfig | undefined;
/**
* Get a environment variable value.
* @param key The environment variable name.
* @returns The environment variable value.
*/
getEnv(key: EnvType): string;
/**
* Get an option value
* @param key The option name.
* @returns The option value.
*/
getOption(key: BuildOptionType): boolean | undefined;
/**
* Get a disabled advisor value.
* @param key The advisor name.
* @returns The status of the advisor. True means `disabled` and vise versa.
*/
getDisabledAdvisorFlag<T>(key: string): T | undefined;
/**
* Set a disabled advisor value.
* @param key The advisor name.
* @param value The status of the advisor to set. True means `disabled` and vise versa.
*/
setDisabledAdvisorFlag<T>(key: string, value: T): void;
/**
* Reset the status of all the advisors to `enable`.
*/
resetAdvisors(): void;
/**
* Get a package configuration value.
* @param key The package configuration name.
* @returns The package configuration value.
*/
getPkgConfigEnv(key: PkgConfigType): string;
/**
* Set a package configuration value.
* @param key The package configuration name.
* @param value The package configuration value to set.
*/
setPkgConfigEnv(key: PkgConfigType, value: string): void;
/**
* Update the build config data. This is the general entry for all config related updates.
*
* @param jsonParts The to be updated config data.
* @param options The update options.
*/
updateBuildConfig(
jsonParts: { [k: string]: unknown },
options?: IBuildConfigUpdateOptions
): void;
/**
* Reset the build config data to default.
*/
resetBuildConfig(): void;
/**
* Convert the build config data to metadata format.
*
* @param convertParts The array of the fields to be converted. The default value
* is `["envs", "builders", "pkgConfig"]` which converts all the related fields.
*/
convertBuildTargetToMeta(convertParts?: ("envs" | "builders" | "pkgConfig")[]): void;
}
/**
* An object represents a recipe from Webinizer.
*/
export class Recipe {
/**
* Create a `Recipe` object.
* @param proj The Project instance.
* @param desc The description of the recipe.
* @param advisor The advisor that generates this recipe.
* @param requests The requests that generate this recipe.
* @param actions The actions provided by this recipe.
* @param showNoAdvisor Whether we can dismiss the recipe from the advisor. The default is false.
*/
constructor(
proj: Project,
desc: string,
advisor: IAdvisor,
requests: IAdviseRequest | IAdviseRequest[],
actions: IAction | IAction[],
showNoAdvisor?: boolean
);
/**
* The Project instance.
*/
readonly proj: Project;
/**
* The description of the recipe.
*/
readonly desc: string;
/**
* The advisor that generates this recipe.
*/
readonly advisor: IAdvisor;
/**
* The requests that generate this recipe.
*/
readonly requests: IAdviseRequest[];
/**
* The actions provided by this recipe.
*/
readonly actions: IAction[];
/**
* Whether we can dismiss the recipe from the advisor. The default is false.
*/
readonly showNoAdvisor: boolean;
/**
* Apply the recipe.
* @returns Whether the recipe is applied successfully or not.
*/
apply(): Promise<boolean>;
/**
* Convert the recipe to a plain JSON object.
* @returns A plain JSON object represents this recipe.
*/
toJson(): IJsonObject;
}
/**
* An object represents the JSON object of a Builder.
*/
export interface IBuilderJson extends IJsonObject {
/**
* The builder ID. This is the same as the index of the builder in a builder array and
* is a unique identifier for builders in a single Project.
*/
id: number;
/**
* The description of the builder.
*/
desc: string;
/**
* The pre-defined command of the builder, used for build.
*/
command: string;
/**
* The overall arguments string of the builder.
*/
args: string;
/**
* The working directory of the builder.
*/
rootBuildFilePath: string;
}
/**
* An object represents a Builder. A builder contains all the information needed to run a build command.
*/
export interface IBuilder extends IToJson {
/**
* The type of the Builder. This should be the same as the class name of the builder.
*/
type: string;
/**
* The description of the builder.
*/
desc: string;
/**
* The pre-defined command of the builder, used for build.
*/
command: string;
/**
* The arguments array of the builder. Each element in the array is a argument.
*/
args: string[];
/**
* The builder ID. This is the same as the index of the builder in a builder array and
* is a unique identifier for builders in a single Project.
*/
id: number;
/**
* Run the build command defined by the builder.
* @param adviseManager The advise manager object.
* @returns Whether the build command is ran successfully.
*/
build(adviseManager: AdviseManager): Promise<boolean>;
/**
* Convert the builder object to a plain JSON object.
* @returns The JSON object of the builder.
*/
toJson(): IBuilderJson;
}
/**
* An object represent a builder factory.
*/
export interface IBuilderFactory extends IFromJson<IBuilder> {
/**
* The name of the builder factory.
*/
name: string;
/**
* The description of the builder factory.
*/
desc: string;
/**
* Detect a builder to use for the project.
* @param proj The project instance.
* @returns The detected builder or null (no builder detected).
*/
detect(proj: Project): IBuilder | null;
/**
* Create a default builder object from the factory.
* @param proj The project instance.
* @param args The arguments of the builder.
* @returns A builder object.
*/
createDefault(proj: Project, args?: string): IBuilder;
}
/**
* An object contains all the builder factories.
*/
export const ALL_BUILDER_FACTORIES: IJsonFactories<IBuilder, IBuilderFactory>;
/**
* Check if all the previous builders run native build commands.
* @param proj The project instance.
* @param idx The builder idx to check.
* @returns `true` if all the previous builders run native build commands.
*/
export function isPrevBuildersAllNative(proj: Project, idx: number): boolean;
/**
* Find the first builder with type `builder` in the poject's builders array.
* @param proj The Project instance.
* @param builder The builder type ({@link IBuilder.type}) string.
* @returns The builder index if found one. `-1` means not found.
*/
export function findFirstBuilder(proj: Project, builder: string): number;
/**
* An object represents an advise request.
*/
export interface IAdviseRequest extends IToJson {
/**
* The tags array of the request.
*/
tags: string[];
}
/**
* An object represents the advise request.
*/
export interface IAdviseResult {
/**
* Whether this request is handled by advisors or not.
*/
handled: boolean;
/**
* The recipe generated by advisors.
*/
recipe?: Recipe;
/**
* Whether continues to ask other advisors to handle this request or not.
*/
needPropagation?: boolean;
/**
* Whether needs to replace the current request queue with it if defined.
*/
newRequestQueue?: IAdviseRequest[];
}
/**
* An object represents an advisor.
*/
export interface IAdvisor {
/**
* The type of the advisor. This should be the same as the advisor class name.
*/
type: string;
/**
* The description of the advisor.
*/
desc: string;
/**
* Advise on the request.
* @param proj The project instance.
* @param req The request that needs to be advised.
* @param requestList The queued request list.
* @returns The advise result object.
*/
advise(
proj: Project,
req: IAdviseRequest,
requestList: ReadonlyArray<IAdviseRequest>
): Promise<IAdviseResult>;
}
/**
* An object represents advisor factory.
*/
export interface IAdvisorFactory {
/**
* Name of the advisor factory.
*/
name: string;
/**
* The description of the advisor factory.
*/
desc: string;
/**
* Create advisor object from the factory.
* @param args The arguments used to create the advisor object.
*/
createAdvisor(args?: string): IAdvisor;
}
/**
* An object that manages advise requests and generate recipes.
*/
export class AdviseManager {
/**
* The project instance.
*/
readonly proj: Project;
/**
* Create an `AdviseManager` object.
* @param proj the project instance.
*/
constructor(proj: Project);
/**
* Queue the request to the request list.
* @param req the request to be queued.
*/
queueRequest(req: IAdviseRequest): void;
/**
* Advise on the request.
* @returns The recipes generated for all the requests.
*/
advise(): Promise<Recipe[]>;
}
/**
* Register an advisor factory.
* @param type The type of the advisor.
* @param factory The factory object of the advisor.
*/
export function registerAdvisorFactory(type: string, factory: IAdvisorFactory): void;
/**
* Get an advisor factory object with `type`.
* @param type The type of the advisor.
* @returns The advisor factory object. `null` if the advisor factory is not available.
*/
export function advisorFactoryFromType(type: string): IAdvisorFactory | null;
/**
* Represents an request generated from build errors.
*/
export class ErrorAdviseRequest implements IAdviseRequest {
/**
* Create an `ErrorAdviseRequest` object.
* @param tags The tags of the request.
* @param error The error messages.
* @param location The file location for the error.
* @param builderID The ID of the builder that generates the request.
*/
constructor(
tags: string | string[],
error: string,
location: FileLocation | null,
builderID: number
);
/**
* The tags array of the request.
*/
readonly tags: string[];
/**
* The error messages.
*/
readonly error: string;
/**
* The file location for the error.
*/
readonly location: FileLocation | null;
/**
* The ID of the builder that generates the request.
*/
readonly builderID: number;
/**
* Convert the request to a plain JSON object.
*/
toJson(): IJsonObject;
/**
* Create a request object from a plain JSON object.
* @param proj The project instance.
* @param o The plain JSON object.
* @returns A created `ErrorAdviseRequest` object.
*/
static fromJson(proj: Project, o: IJsonObject): ErrorAdviseRequest;
}
/**
* Represents other requests with plain JSON data.
*/
export class PlainAdviseRequest implements IAdviseRequest {
/**
* Create a `PlainAdviseRequest` object.
* @param tags The tags of the request.
* @param plainData The request data.
*/
constructor(tags: string | string[], plainData: unknown);
/**
* The tags array of the request.
*/
readonly tags: string[];
/**
* The request data itself is a kind of JSON so easy to fromJson() and toJson().
*/
readonly plainData: unknown;
/**
* Convert the request to a plain JSON object.
*/
toJson(): IJsonObject;
/**
* Create a request object from a JSON object.
* @param proj The project instance.
* @param o The plain JSON object.
* @returns A created `PlainAdviseRequest` object.
*/
static fromJson(proj: Project, o: IJsonObject): PlainAdviseRequest;
}
/**
* An object represents a plain JSON object.
*/
export interface IJsonObject {
/**
* This should be the class name that this JSON object is converted from.
*/
__type__: string;
[key: string]: unknown;
}
/**
* Check the JSON object type.
* @param type The type to be checked.
* @param o The JSON object to be checked.
*/
export function checkJsonType(type: string, o: IJsonObject): void;
/**
* An object that can be converted to a plain JSON object (`IJsonObject`).
*/
export interface IToJson {
toJson(): IJsonObject;
}
/**
* An object that can be converted from a plain JSON object (`IJsonObject`).
*/
export interface IFromJson<T> {
fromJson: FromJsonMethod<T>;
}
/**
* Represents the function type of a `fromJson` method.
* The JSON itself only contains static informaiton, but the object to restore
* may need to contain the current content where proj is the root of all such
* context (session) informaiton, so we need it for deserialization too.
*/
export type FromJsonMethod<T> = (proj: Project, o: IJsonObject, index: number) => T | null;
/**
* A template class for Json Factories.
*/
export interface IJsonFactories<
T,
X extends IFromJson<T> | FromJsonMethod<T> = IFromJson<T> | FromJsonMethod<T>
> {
/**
* The name of the factories.
*/
readonly name: string;
/**
* Create the factory from JSON object.
* @param proj The project instance.
* @param o The plain JSON object.
* @param index The index of the JSON object in an array.
* @returns The factory converted from JSON object.
*/
fromJson(proj: Project, o: IJsonObject, index: number): T | null;
/**
* Register a factory or method to the Json factories map.
* @param type The type of the factory or `fromJson` method.
* @param method_or_factory The factory object of the `fromJson` method for the `type`.
*/
register(type: string, method_or_factory: X): void;
/**
* Get the factories map.
*/
factoriesMap(): Map<string, X>;
/**
* Create an array of objects from an array of JSON objects.
* @param proj The project instance.
* @param arr The array of JSON objects.
*/
fromJsonArray(proj: Project, arr: IJsonObject[]): T[];
}
/**
* An object represents an action.
*/
export interface IAction extends IToJson {
/**
* The type of the action. This should be the same as the actual action class name.
*/
type: string;
/**
* The description of the action.
*/
desc: string;
/**
* Apply the action.
* @returns Whether the action is applied successfully or not.
*/
apply(): Promise<boolean>;
}
/**
* An object contains all the action factories, used to create an new action object.
*/
export const ALL_ACTION_FACTORIES: IJsonFactories<IAction>;
/**
* File change action - An action to change the file content
*/
export class FileChangeAction implements IAction {
/**
* Create a `FileChangeAction`.
* @param manager The `FileChangeManager` object. This should be passed from Project object as
* {@link Project.fileChangeManager} rather than `new` one here.
* @param desc The action decription.
* @param region The file region to change.
* @param content The file content to change.
*/
constructor(
manager: IFileChangeManager,
desc: string,