@rapidrest/core 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/LICENSE +23 -0
  2. package/README.rst +37 -0
  3. package/dist/lib/AlertUtils.js +239 -0
  4. package/dist/lib/AlertUtils.js.map +1 -0
  5. package/dist/lib/ApiError.js +34 -0
  6. package/dist/lib/ApiError.js.map +1 -0
  7. package/dist/lib/ClassLoader.js +159 -0
  8. package/dist/lib/ClassLoader.js.map +1 -0
  9. package/dist/lib/FileUtils.js +190 -0
  10. package/dist/lib/FileUtils.js.map +1 -0
  11. package/dist/lib/JWTUtils.js +111 -0
  12. package/dist/lib/JWTUtils.js.map +1 -0
  13. package/dist/lib/Logger.js +28 -0
  14. package/dist/lib/Logger.js.map +1 -0
  15. package/dist/lib/MessagingUtils.js +218 -0
  16. package/dist/lib/MessagingUtils.js.map +1 -0
  17. package/dist/lib/NotificationsUtils.js +52 -0
  18. package/dist/lib/NotificationsUtils.js.map +1 -0
  19. package/dist/lib/OASUtils.js +207 -0
  20. package/dist/lib/OASUtils.js.map +1 -0
  21. package/dist/lib/ObjectFactory.js +302 -0
  22. package/dist/lib/ObjectFactory.js.map +1 -0
  23. package/dist/lib/ObjectUtils.js +49 -0
  24. package/dist/lib/ObjectUtils.js.map +1 -0
  25. package/dist/lib/StringUtils.js +104 -0
  26. package/dist/lib/StringUtils.js.map +1 -0
  27. package/dist/lib/TelemetryUtils.js +159 -0
  28. package/dist/lib/TelemetryUtils.js.map +1 -0
  29. package/dist/lib/UserUtils.js +138 -0
  30. package/dist/lib/UserUtils.js.map +1 -0
  31. package/dist/lib/ValidationUtils.js +130 -0
  32. package/dist/lib/ValidationUtils.js.map +1 -0
  33. package/dist/lib/decorators/ObjectDecorators.js +95 -0
  34. package/dist/lib/decorators/ObjectDecorators.js.map +1 -0
  35. package/dist/lib/decorators/index.js +2 -0
  36. package/dist/lib/decorators/index.js.map +1 -0
  37. package/dist/lib/index.js +18 -0
  38. package/dist/lib/index.js.map +1 -0
  39. package/dist/lib/sleep.js +15 -0
  40. package/dist/lib/sleep.js.map +1 -0
  41. package/dist/lib/threads/ThreadLogger.js +43 -0
  42. package/dist/lib/threads/ThreadLogger.js.map +1 -0
  43. package/dist/lib/threads/ThreadPool.js +270 -0
  44. package/dist/lib/threads/ThreadPool.js.map +1 -0
  45. package/dist/lib/threads/ThreadWorker.js +25 -0
  46. package/dist/lib/threads/ThreadWorker.js.map +1 -0
  47. package/dist/lib/threads/ThreadWorkerEntry.js +77 -0
  48. package/dist/lib/threads/ThreadWorkerEntry.js.map +1 -0
  49. package/dist/lib/threads/index.js +3 -0
  50. package/dist/lib/threads/index.js.map +1 -0
  51. package/dist/types/AlertUtils.d.ts +132 -0
  52. package/dist/types/ApiError.d.ts +13 -0
  53. package/dist/types/ClassLoader.d.ts +87 -0
  54. package/dist/types/FileUtils.d.ts +46 -0
  55. package/dist/types/JWTUtils.d.ts +139 -0
  56. package/dist/types/Logger.d.ts +7 -0
  57. package/dist/types/MessagingUtils.d.ts +77 -0
  58. package/dist/types/NotificationsUtils.d.ts +32 -0
  59. package/dist/types/OASUtils.d.ts +54 -0
  60. package/dist/types/ObjectFactory.d.ts +77 -0
  61. package/dist/types/ObjectUtils.d.ts +17 -0
  62. package/dist/types/StringUtils.d.ts +52 -0
  63. package/dist/types/TelemetryUtils.d.ts +84 -0
  64. package/dist/types/UserUtils.d.ts +61 -0
  65. package/dist/types/ValidationUtils.d.ts +66 -0
  66. package/dist/types/decorators/ObjectDecorators.d.ts +55 -0
  67. package/dist/types/decorators/index.d.ts +1 -0
  68. package/dist/types/index.d.ts +17 -0
  69. package/dist/types/sleep.d.ts +5 -0
  70. package/dist/types/threads/ThreadLogger.d.ts +15 -0
  71. package/dist/types/threads/ThreadPool.d.ts +115 -0
  72. package/dist/types/threads/ThreadWorker.d.ts +41 -0
  73. package/dist/types/threads/ThreadWorkerEntry.d.ts +1 -0
  74. package/dist/types/threads/index.d.ts +2 -0
  75. package/docs/Makefile +20 -0
  76. package/docs/conf.py +58 -0
  77. package/docs/index.rst +17 -0
  78. package/docs/make.bat +35 -0
  79. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/README.md +21 -0
  80. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Config.md +47 -0
  81. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Destroy.md +27 -0
  82. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Init.md +33 -0
  83. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Inject.md +45 -0
  84. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Logger.md +27 -0
  85. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Nullable.md +27 -0
  86. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Validator.md +39 -0
  87. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/type-aliases/ValidatorFunction.md +31 -0
  88. package/docs/reference/README.md +73 -0
  89. package/docs/reference/classes/AlertUtils.md +158 -0
  90. package/docs/reference/classes/ApiError.md +263 -0
  91. package/docs/reference/classes/ClassLoader.md +224 -0
  92. package/docs/reference/classes/Event.md +109 -0
  93. package/docs/reference/classes/EventUtils.md +123 -0
  94. package/docs/reference/classes/FileUtils.md +193 -0
  95. package/docs/reference/classes/JWTUtils.md +91 -0
  96. package/docs/reference/classes/MessagingUtils.md +145 -0
  97. package/docs/reference/classes/OASUtils.md +213 -0
  98. package/docs/reference/classes/ObjectFactory.md +274 -0
  99. package/docs/reference/classes/ObjectUtils.md +60 -0
  100. package/docs/reference/classes/StringUtils.md +169 -0
  101. package/docs/reference/classes/ThreadPool.md +249 -0
  102. package/docs/reference/classes/ThreadWorker.md +91 -0
  103. package/docs/reference/classes/UserUtils.md +239 -0
  104. package/docs/reference/classes/ValidationUtils.md +294 -0
  105. package/docs/reference/enumerations/AlertPriority.md +61 -0
  106. package/docs/reference/enumerations/JWTUtilsCompressionMethods.md +21 -0
  107. package/docs/reference/enumerations/WorkerMessageType.md +43 -0
  108. package/docs/reference/functions/sleep.md +25 -0
  109. package/docs/reference/interfaces/Alert.md +101 -0
  110. package/docs/reference/interfaces/AlertAttachment.md +51 -0
  111. package/docs/reference/interfaces/AlertClose.md +31 -0
  112. package/docs/reference/interfaces/AlertUtilsAttachmentOptions.md +42 -0
  113. package/docs/reference/interfaces/AlertUtilsOptions.md +41 -0
  114. package/docs/reference/interfaces/InstanceOptions.md +35 -0
  115. package/docs/reference/interfaces/JWTPayload.md +143 -0
  116. package/docs/reference/interfaces/JWTUser.md +55 -0
  117. package/docs/reference/interfaces/JWTUtilsConfig.md +45 -0
  118. package/docs/reference/interfaces/JWTUtilsPayloadKeyOptions.md +68 -0
  119. package/docs/reference/interfaces/JWTUtilsPayloadOptions.md +40 -0
  120. package/docs/reference/interfaces/JWTUtilsPayloadPasswordOptions.md +78 -0
  121. package/docs/reference/interfaces/NewEvent.md +25 -0
  122. package/docs/reference/interfaces/OriginSettings.md +25 -0
  123. package/docs/reference/interfaces/SlackConfig.md +33 -0
  124. package/docs/reference/interfaces/SmtpAuth.md +25 -0
  125. package/docs/reference/interfaces/SmtpConfig.md +41 -0
  126. package/docs/reference/interfaces/Template.md +81 -0
  127. package/docs/reference/interfaces/TemplateMapBase.md +13 -0
  128. package/docs/reference/interfaces/TwilioConfig.md +33 -0
  129. package/docs/reference/interfaces/WorkerMessage.md +31 -0
  130. package/docs/reference/interfaces/WorkerOptions.md +61 -0
  131. package/docs/reference/type-aliases/BooleanFunc.md +23 -0
  132. package/docs/reference/type-aliases/TemplateMap.md +17 -0
  133. package/docs/reference/type-aliases/WorkerCallback.md +31 -0
  134. package/docs/reference/variables/Logger.md +21 -0
  135. package/package.json +96 -0
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Utilities for working with authenticated user objects. An user object is expected to have the following
3
+ * properties.
4
+ *
5
+ * * `uid` - Universally unique identifier for the user
6
+ * * `email` - Unique e-mail address for the user
7
+ * * `roles` - A list of unique names indicating the permissions of the user.
8
+ * * `verified` - Indicates if the user's e-mail address has been verified.
9
+ *
10
+ * @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
11
+ */
12
+ export declare class UserUtils {
13
+ /**
14
+ * Returns `true` if the given user object is a member of the organization with the specified uid, otherwise returns `false`.
15
+ * @param user The user object to inspect.
16
+ * @param organizationUid The universally unique identifier of the persona to search for.
17
+ */
18
+ static hasOrganization(user: any, organizationUid: string): boolean;
19
+ /**
20
+ * Returns `true` if the given user object contains is a member of an organization matching one of the uids in the specified list, otherwise returns `false`.
21
+ * @param user The user object to inspect.
22
+ * @param organizationUids The list of universally unique identifiers to search for.
23
+ */
24
+ static hasOrganizations(user: any, organizationUids?: string[]): boolean;
25
+ /**
26
+ * Returns `true` if the given user object contains a `Persona` object with the specified uid, otherwise returns `false`.
27
+ * @param user The user object to inspect.
28
+ * @param personaUid The universally unique identifier of the persona to search for.
29
+ */
30
+ static hasPersona(user: any, personaUid?: string): boolean;
31
+ /**
32
+ * Returns `true` if the given user object contains a `Persona` object matching one of the uids in the specified list, otherwise returns `false`.
33
+ * @param user The user object to inspect.
34
+ * @param personaUid The list of universally unique identifiers to search for.
35
+ */
36
+ static hasPersonas(user: any, personaUids?: string[]): boolean;
37
+ /**
38
+ * Returns the unique identifier of the specified type associated with the given user.
39
+ *
40
+ * @param user The user to retrieve the external id from.
41
+ * @param type The type of external provider to retrieve.
42
+ * @returns The unique id of the external provider for the given type if found, otherwise `undefined`.
43
+ */
44
+ static getExternalId(user: any, type: string): string | undefined;
45
+ /**
46
+ * Returns `true` if the given user object has a role with the specified name, otherwise returns `false`.
47
+ *
48
+ * @param user The user object to inspect.
49
+ * @param role The unique name of the role to search for.
50
+ * @param orgUid The unique identifier of an organization whose role will be verified.
51
+ */
52
+ static hasRole(user: any, role?: string, orgUid?: string): boolean;
53
+ /**
54
+ * Returns `true` if the given user object has at least one role from the specified list of names, otherwise returns `false`.
55
+ *
56
+ * @param user The user object to inspect.
57
+ * @param roles A list of unique names of the roles to search for.
58
+ * @param orgUid The unique identifier of an organization whose role will be verified.
59
+ */
60
+ static hasRoles(user: any, roles?: string[], orgUid?: string): boolean;
61
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * A simple validation function that returns a boolean success or fail.
3
+ */
4
+ export type BooleanFunc = (val: any) => boolean;
5
+ /**
6
+ * A collection of validation functions to use with the `@Validator()` decorator.
7
+ */
8
+ export declare class ValidationUtils {
9
+ /**
10
+ * A simple wrapper that calls the specified boolean validation function with the given value and returns the
11
+ * value as a result if the validation function passes. Otherwise throws an error.
12
+ *
13
+ * @param val The value to validate.
14
+ * @param func The boolean validation function to check the value.
15
+ * @throws Throws an error if the value fails the boolean validation test.
16
+ */
17
+ static check(val: any, func: BooleanFunc): any;
18
+ /**
19
+ * Validates that the provided string represents a ISO, RFC or UTC date or timestamp.
20
+ */
21
+ static checkDate(val: string): string;
22
+ /**
23
+ * Validates that the provided string represents a valid e-mail address.
24
+ */
25
+ static checkEmail(val: string): string;
26
+ /**
27
+ * Validates that the provided array is not empty.
28
+ */
29
+ static checkEmpty(val: Array<any>): Array<any>;
30
+ /**
31
+ * Validates that the provided string is a valid IP address.
32
+ */
33
+ static checkIP(val: string): string;
34
+ /**
35
+ * Validates that the provided string is valid JSON (note: uses `JSON.parse`).
36
+ */
37
+ static checkJSON(val: string): string;
38
+ /**
39
+ * Validates that the provided string matches the regexp pattern /[a-zA-Z0-9_\-\.@:\+]+/.
40
+ */
41
+ static checkName(val: string): string;
42
+ /**
43
+ * Validates that the provided object is not null or empty.
44
+ */
45
+ static checkNull(val: any): any;
46
+ /**
47
+ * Validates that the provided string represents a valid phone number.
48
+ */
49
+ static checkPhone(val: string): string;
50
+ /**
51
+ * Validates that the provided string represents a semantic version.
52
+ */
53
+ static checkSemVer(val: string): string;
54
+ /**
55
+ * Validates that the provided string is a valid URL.
56
+ */
57
+ static checkURL(val: string): string;
58
+ /**
59
+ * Validates that the provided string is a valid UUID.
60
+ */
61
+ static checkUUID(val: string): string;
62
+ /**
63
+ * Validates that the provided value is an entity `version` number (e.g. `value > 0`).
64
+ */
65
+ static checkVersion(val: any): number;
66
+ }
@@ -0,0 +1,55 @@
1
+ import "reflect-metadata";
2
+ import { InstanceOptions } from "../ObjectFactory.js";
3
+ /**
4
+ * Apply this to a class function to mark it as a destructor to be called by the `ObjectFactory` during cleanup.
5
+ */
6
+ export declare function Destroy(target: any, propertyKey: string): void;
7
+ /**
8
+ * Injects an object instance to the decorated property of the given name and type using the provided arguments
9
+ * if no object has been created yet.
10
+ * @param type The fully qualified name or type of the class to instantiate. If a type is given it's class name will be inferred
11
+ * via the constructor name.
12
+ * @param name The unique name to give the class instance. Set to `undefined` if you wish to force a new object is created.
13
+ * @param initialize Set to `true` to initialize the object after creation, otherwise set to `false`. Default is `true`.
14
+ * @param args The set of constructor arguments to use during construction
15
+ */
16
+ export declare function Inject(type: any, options?: InstanceOptions): (target: any, propertyKey: string | symbol) => void;
17
+ /**
18
+ * Apply this to a function to be executed once a new object instance has been created and all dependencies injected.
19
+ * Note: If the decorated function returns a Promise it is not gauranteed to finish execution before the object is
20
+ * returned during the instantiation process.
21
+ */
22
+ export declare function Init(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
23
+ /**
24
+ * Apply this to a property to have a configuration variable be injected at instantiation. If no path is given, the
25
+ * global configuration object is injected.
26
+ *
27
+ * @param path The path to the configuration variable to inject.
28
+ * @param defaultValue Set to the desired default value. If `undefined` is specified then an error is thrown if
29
+ * no config variable is found at the given path.
30
+ */
31
+ export declare function Config(path?: string, defaultValue?: any): (target: any, propertyKey: string | symbol) => void;
32
+ /**
33
+ * Apply this to a property to have the logger utility injected at instantiation.
34
+ */
35
+ export declare function Logger(target: any, propertyKey: string | symbol): void;
36
+ /**
37
+ * Apply this to a property to indicate that the value can be `null` or `undefined.`
38
+ *
39
+ * @param nullable Set to `true` to indicate that the property value can be `null`, otherwise set to `false`. Default is `false`.
40
+ */
41
+ export declare function Nullable(target: any, propertyKey: string | symbol): void;
42
+ /**
43
+ * A function used to validate a property value.
44
+ *
45
+ * @param value The value to validate.
46
+ * @returns The validated value to assign to the property.
47
+ * @throws An exception if the value cannot be validated.
48
+ */
49
+ export type ValidatorFunction = (value: any) => any;
50
+ /**
51
+ * Apply this to a property to specify the function that will be used to perform validation of the value.
52
+ *
53
+ * @param func The validation function to use for the given property.
54
+ */
55
+ export declare function Validator(func: ValidatorFunction): (target: any, propertyKey: string | symbol) => void;
@@ -0,0 +1 @@
1
+ export * as ObjectDecorators from "./ObjectDecorators.js";
@@ -0,0 +1,17 @@
1
+ export * from "./ApiError.js";
2
+ export * from "./AlertUtils.js";
3
+ export * from "./ClassLoader.js";
4
+ export * from "./decorators/index.js";
5
+ export * from "./FileUtils.js";
6
+ export * from "./JWTUtils.js";
7
+ export * from "./Logger.js";
8
+ export * from "./MessagingUtils.js";
9
+ export * from "./ObjectFactory.js";
10
+ export * from "./ObjectUtils.js";
11
+ export * from "./OASUtils.js";
12
+ export * from "./StringUtils.js";
13
+ export * from "./threads/index.js";
14
+ export * from "./sleep.js";
15
+ export * from "./TelemetryUtils.js";
16
+ export * from "./UserUtils.js";
17
+ export * from "./ValidationUtils.js";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Starts a timer to suspend execution for a given number of milliseconds.
3
+ * @param ms The number of milliseconds to suspend. Default is `1`.
4
+ */
5
+ export declare function sleep(ms?: number): Promise<void>;
@@ -0,0 +1,15 @@
1
+ export = ThreadLogger;
2
+ /**
3
+ * Provides a Winston transport for forwarding logs from this thread to the parent's logger instance.
4
+ *
5
+ * Constructor requires two properties to be set in the `opts` argument:
6
+ * - `parentPort`
7
+ * - `threadId`
8
+ */
9
+ declare class ThreadLogger {
10
+ log(data: any): void;
11
+ debug(message: any): void;
12
+ error(message: any): void;
13
+ info(message: any): void;
14
+ warn(message: any): void;
15
+ }
@@ -0,0 +1,115 @@
1
+ import { Worker } from "worker_threads";
2
+ /**
3
+ * Callback function for `ThreadPool` events.
4
+ *
5
+ * @param threadId The id of the thread that originated the event.
6
+ * @param msg The optional message data associated with the event.
7
+ */
8
+ export type WorkerCallback = (threadId: number, msg?: any) => void;
9
+ /**
10
+ * Describes the various options that can be used when creating worker threads.
11
+ */
12
+ export interface WorkerOptions {
13
+ /** The list of initialization arguments to pass into the worker thread. */
14
+ args?: any;
15
+ /** The path to the entry file create a worker thread from. Default is `ThreadWorkerEntry.js`. */
16
+ entry?: string;
17
+ /** Indicates if a worker thread should automatically be restarted on exit. */
18
+ restartOnExit?: boolean;
19
+ /** Set to `true` to enable support for importing TypeScript modules in the worker. Default is `true`. */
20
+ allowTs?: boolean;
21
+ /** The path to the worker file. This must be set when using `ThreadWorkerEntry` as the default entry file. */
22
+ worker?: string;
23
+ }
24
+ /**
25
+ * The `ThreadPool` class provides an interface for managing a pool of execution threads that can be used for parallel
26
+ * code execution. `ThreadPool` is a wrapper to the `worker_threads` API to add support for multiple `Worker` instances.
27
+ * By default, the pool will create *n* workers corresponding to the number of CPUs (physical + virtual) on the system.
28
+ *
29
+ * There are two ways to start worker threads with the pool.
30
+ *
31
+ * The first way is to set the `entry` option when calling the `start()` function. This will create a instance of the
32
+ * `worker_threads` APIs `Worker` class with the specified file as the entry point. Note that this file must be of
33
+ * type JavaScript (`.js` extension) as the underlying system does not support loading TypeScript. If the `args` option
34
+ * is set, the value will be passed in as the `workerData` to the entry file.
35
+ *
36
+ * The second way to start a worker thread is by setting the `worker` argument when calling the `start()` function. The
37
+ * specified `worker` file must contain a `default` export. The `default` export must be a class definition which
38
+ * extends the `ThreadWorker` abstract class interface. The file can be either JavaScript or TypeScript. When using
39
+ * this method the `start()` function will return only when all worker instances in each thread of the pool has
40
+ * successfully returned from its `start()` function. When the `args` option is set, the value(s) will be passed in to
41
+ * the constructor on instantiation by the thread executor.
42
+ *
43
+ * When the `restartOnExit` option is specified, the pool will automatically recreate and start a worker thread on
44
+ * the `exit event`.
45
+ *
46
+ * This class exposes worker messages via the `on()` callback handler function. Registering a callback handler via
47
+ * `on()` will propogate all messages from all underlying threads in the pool.
48
+ *
49
+ * @author Jean-Philippe Steinmetz
50
+ */
51
+ export declare class ThreadPool {
52
+ /** The map of event types to a list of callback functions. */
53
+ private callbacks;
54
+ /** The index of the last worker that was assigned work. */
55
+ private lastThread;
56
+ /** The instance of Winston logger to forward thread logs to. */
57
+ private logger?;
58
+ /** The maximum number of threads allowed. */
59
+ private maxThreads;
60
+ /** The list of active worker threads. */
61
+ readonly workers: Array<Worker>;
62
+ /** Used to indicate that the pool is shutting down. */
63
+ private shutdown;
64
+ /**
65
+ * The maximum number of threads that can be created by the pool.
66
+ */
67
+ get max(): number;
68
+ /**
69
+ * The number of active threads in the pool.
70
+ */
71
+ get size(): number;
72
+ /**
73
+ * Creates a new `ThreadPool` instance with the specified defaults.
74
+ *
75
+ * @param max The maximum number of threads to create. Default is `os.cpus().length`.
76
+ * @param logger The Winston logger instance to forward all worker thread logs to.
77
+ */
78
+ constructor(max?: number, logger?: any);
79
+ private createWorker;
80
+ /**
81
+ * Initializes the thread pool with the initial worker threads and begins execution.
82
+ *
83
+ * @param entry The path of the entry create a worker thread from. Default is `ThreadWorkerEntry.js`.
84
+ * @param options The options to use when creating the worker thread.
85
+ * @param num The number of initial threads to create, cannot be greater than max. Default is `max`.
86
+ */
87
+ start(options?: WorkerOptions, num?: number): Promise<void>;
88
+ /**
89
+ * Stops all running thread executions.
90
+ */
91
+ stop(): Promise<void>;
92
+ /**
93
+ * Registers a new callback function to be notified when the given event type is fired.
94
+ *
95
+ * @param type The event type to be notified of. Possible values are: `error`, `exit` and `message`.
96
+ * @param func The callback function to register.
97
+ */
98
+ on(type: string, func: WorkerCallback): void;
99
+ /**
100
+ * Sends the provided message to the next available worker thread. Messages are sent in a round-robin order.
101
+ * @param msg The message to send the next available worker thread.
102
+ */
103
+ send(msg: any): void;
104
+ /**
105
+ * Sends the provided message to all worker threads in the pool.
106
+ * @param msg The message to send to all workers.
107
+ */
108
+ sendAll(msg: any): void;
109
+ /**
110
+ * Sends the provided message to the worker thread with the specified id.
111
+ * @param id The id of the thread to send the message to.
112
+ * @param msg The message to send the next available worker thread.
113
+ */
114
+ sendTo(id: number, msg: any): void;
115
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Describes the types of messages passed between the parent thread pool manager and a worker thread.
3
+ */
4
+ export declare enum WorkerMessageType {
5
+ ERROR = "_WorkerError",
6
+ LOG = "_WorkerLog",
7
+ ONLINE = "_WorkerOnline",
8
+ STOP = "_StopWorker"
9
+ }
10
+ /**
11
+ * Describes a single message sent from the thread pool managger to a worker thread.
12
+ */
13
+ export interface WorkerMessage {
14
+ /** The data associated with the message. */
15
+ data?: any;
16
+ /** The type of message sent. */
17
+ type: WorkerMessageType;
18
+ }
19
+ /**
20
+ * Provides a simple abstract interface for creating thread workers when using the `ThreadPool` system.
21
+ *
22
+ * @author Jean-Philippe Steinmetz
23
+ */
24
+ export declare abstract class ThreadWorker {
25
+ protected logger: any;
26
+ constructor(logger: any);
27
+ /**
28
+ * Callback function when a message is received from the thread pool manager.
29
+ *
30
+ * @param msg The message that was received.
31
+ */
32
+ abstract onMessage(msg: WorkerMessage): void | Promise<void>;
33
+ /**
34
+ * Starts execution of the thread worker.
35
+ */
36
+ abstract start(): void | Promise<void>;
37
+ /**
38
+ * Stops execution of all work and shuts down the thread worker.
39
+ */
40
+ abstract stop(): void | Promise<void>;
41
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./ThreadPool.js";
2
+ export * from "./ThreadWorker.js";
package/docs/Makefile ADDED
@@ -0,0 +1,20 @@
1
+ # Minimal makefile for Sphinx documentation
2
+ #
3
+
4
+ # You can set these variables from the command line, and also
5
+ # from the environment for the first two.
6
+ SPHINXOPTS ?=
7
+ SPHINXBUILD ?= sphinx-build
8
+ SOURCEDIR = .
9
+ BUILDDIR = _build
10
+
11
+ # Put it first so that "make" without argument is like "make help".
12
+ help:
13
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14
+
15
+ .PHONY: help Makefile
16
+
17
+ # Catch-all target: route all unknown targets to Sphinx using the new
18
+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19
+ %: Makefile
20
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
package/docs/conf.py ADDED
@@ -0,0 +1,58 @@
1
+ # Configuration file for the Sphinx documentation builder.
2
+ #
3
+ # This file only contains a selection of the most common options. For a full
4
+ # list see the documentation:
5
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html
6
+
7
+ # -- Path setup --------------------------------------------------------------
8
+
9
+ # If extensions (or modules to document with autodoc) are in another directory,
10
+ # add these directories to sys.path here. If the directory is relative to the
11
+ # documentation root, use os.path.abspath to make it absolute, like shown here.
12
+ #
13
+ # import os
14
+ # import sys
15
+ # sys.path.insert(0, os.path.abspath('.'))
16
+ import recommonmark
17
+ from recommonmark.transform import AutoStructify
18
+
19
+ source_suffix = ['.rst', '.md']
20
+
21
+ # -- Project information -----------------------------------------------------
22
+
23
+ project = 'RapidREST: Core Library'
24
+ copyright = 'Jean-Philippe Steinmetz. All rights reserved.'
25
+ author = 'RapidREST <rapidrests@gmail.com>'
26
+
27
+ # -- General configuration ---------------------------------------------------
28
+
29
+ # Add any Sphinx extension module names here, as strings. They can be
30
+ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
31
+ # ones.
32
+ extensions = [
33
+ 'recommonmark',
34
+ 'sphinx.ext.autodoc',
35
+ ]
36
+
37
+ # List of patterns, relative to source directory, that match files and
38
+ # directories to ignore when looking for source files.
39
+ # This pattern also affects html_static_path and html_extra_path.
40
+ exclude_patterns = []
41
+
42
+ master_doc = 'index'
43
+
44
+ # Add any paths that contain custom static files (such as style sheets) here,
45
+ # relative to this directory. They are copied after the builtin static files,
46
+ # so a file named "default.css" will overwrite the builtin "default.css".
47
+ html_static_path = ['_static']
48
+
49
+ # app setup hook
50
+ def setup(app):
51
+ app.add_config_value('recommonmark_config', {
52
+ 'auto_toc_tree_section': 'Contents',
53
+ 'enable_math': False,
54
+ 'enable_inline_math': False,
55
+ 'enable_eval_rst': True,
56
+ 'enable_auto_doc_ref': True,
57
+ }, True)
58
+ app.add_transform(AutoStructify)
package/docs/index.rst ADDED
@@ -0,0 +1,17 @@
1
+ ===============================================================================
2
+ RapidREST: Core Library
3
+ ===============================================================================
4
+
5
+ Repository: ``git@github.com:rapidrest/core.git``
6
+
7
+ A collection of common utilities and core functionality for rapidly building RESTful applications.
8
+
9
+ .. toctree::
10
+ :caption: Project Info
11
+
12
+ ../README
13
+
14
+ .. toctree::
15
+ :caption: API Reference
16
+
17
+ reference/globals
package/docs/make.bat ADDED
@@ -0,0 +1,35 @@
1
+ @ECHO OFF
2
+
3
+ pushd %~dp0
4
+
5
+ REM Command file for Sphinx documentation
6
+
7
+ if "%SPHINXBUILD%" == "" (
8
+ set SPHINXBUILD=sphinx-build
9
+ )
10
+ set SOURCEDIR=.
11
+ set BUILDDIR=_build
12
+
13
+ if "%1" == "" goto help
14
+
15
+ %SPHINXBUILD% >NUL 2>NUL
16
+ if errorlevel 9009 (
17
+ echo.
18
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19
+ echo.installed, then set the SPHINXBUILD environment variable to point
20
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
21
+ echo.may add the Sphinx directory to PATH.
22
+ echo.
23
+ echo.If you don't have Sphinx installed, grab it from
24
+ echo.http://sphinx-doc.org/
25
+ exit /b 1
26
+ )
27
+
28
+ %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29
+ goto end
30
+
31
+ :help
32
+ %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33
+
34
+ :end
35
+ popd
@@ -0,0 +1,21 @@
1
+ [**@rapidrest/core**](../../../README.md)
2
+
3
+ ***
4
+
5
+ [@rapidrest/core](../../../README.md) / ObjectDecorators
6
+
7
+ # ObjectDecorators
8
+
9
+ ## Type Aliases
10
+
11
+ - [ValidatorFunction](type-aliases/ValidatorFunction.md)
12
+
13
+ ## Functions
14
+
15
+ - [Config](functions/Config.md)
16
+ - [Destroy](functions/Destroy.md)
17
+ - [Init](functions/Init.md)
18
+ - [Inject](functions/Inject.md)
19
+ - [Logger](functions/Logger.md)
20
+ - [Nullable](functions/Nullable.md)
21
+ - [Validator](functions/Validator.md)
@@ -0,0 +1,47 @@
1
+ [**@rapidrest/core**](../../../../README.md)
2
+
3
+ ***
4
+
5
+ [@rapidrest/core](../../../../README.md) / [ObjectDecorators](../README.md) / Config
6
+
7
+ # Function: Config()
8
+
9
+ > **Config**(`path?`, `defaultValue?`): (`target`, `propertyKey`) => `void`
10
+
11
+ Defined in: src/decorators/ObjectDecorators.ts:63
12
+
13
+ Apply this to a property to have a configuration variable be injected at instantiation. If no path is given, the
14
+ global configuration object is injected.
15
+
16
+ ## Parameters
17
+
18
+ ### path?
19
+
20
+ `string`
21
+
22
+ The path to the configuration variable to inject.
23
+
24
+ ### defaultValue?
25
+
26
+ `any` = `undefined`
27
+
28
+ Set to the desired default value. If `undefined` is specified then an error is thrown if
29
+ no config variable is found at the given path.
30
+
31
+ ## Returns
32
+
33
+ > (`target`, `propertyKey`): `void`
34
+
35
+ ### Parameters
36
+
37
+ #### target
38
+
39
+ `any`
40
+
41
+ #### propertyKey
42
+
43
+ `string` | `symbol`
44
+
45
+ ### Returns
46
+
47
+ `void`
@@ -0,0 +1,27 @@
1
+ [**@rapidrest/core**](../../../../README.md)
2
+
3
+ ***
4
+
5
+ [@rapidrest/core](../../../../README.md) / [ObjectDecorators](../README.md) / Destroy
6
+
7
+ # Function: Destroy()
8
+
9
+ > **Destroy**(`target`, `propertyKey`): `void`
10
+
11
+ Defined in: src/decorators/ObjectDecorators.ts:10
12
+
13
+ Apply this to a class function to mark it as a destructor to be called by the `ObjectFactory` during cleanup.
14
+
15
+ ## Parameters
16
+
17
+ ### target
18
+
19
+ `any`
20
+
21
+ ### propertyKey
22
+
23
+ `string`
24
+
25
+ ## Returns
26
+
27
+ `void`
@@ -0,0 +1,33 @@
1
+ [**@rapidrest/core**](../../../../README.md)
2
+
3
+ ***
4
+
5
+ [@rapidrest/core](../../../../README.md) / [ObjectDecorators](../README.md) / Init
6
+
7
+ # Function: Init()
8
+
9
+ > **Init**(`target`, `propertyKey`, `descriptor`): `void`
10
+
11
+ Defined in: src/decorators/ObjectDecorators.ts:51
12
+
13
+ Apply this to a function to be executed once a new object instance has been created and all dependencies injected.
14
+ Note: If the decorated function returns a Promise it is not gauranteed to finish execution before the object is
15
+ returned during the instantiation process.
16
+
17
+ ## Parameters
18
+
19
+ ### target
20
+
21
+ `any`
22
+
23
+ ### propertyKey
24
+
25
+ `string`
26
+
27
+ ### descriptor
28
+
29
+ `PropertyDescriptor`
30
+
31
+ ## Returns
32
+
33
+ `void`