@twin.org/logging-models 0.0.1-next.2

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 (34) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +21 -0
  3. package/dist/cjs/index.cjs +159 -0
  4. package/dist/esm/index.mjs +154 -0
  5. package/dist/types/connectors/multiLoggingConnector.d.ts +57 -0
  6. package/dist/types/connectors/silentLoggingConnector.d.ts +46 -0
  7. package/dist/types/factories/loggingConnectorFactory.d.ts +6 -0
  8. package/dist/types/helpers/logEntryHelper.d.ts +12 -0
  9. package/dist/types/index.d.ts +12 -0
  10. package/dist/types/models/ILogEntry.d.ts +33 -0
  11. package/dist/types/models/ILoggingComponent.d.ts +36 -0
  12. package/dist/types/models/ILoggingConnector.d.ts +38 -0
  13. package/dist/types/models/ILoggingLevelsConfig.d.ts +10 -0
  14. package/dist/types/models/api/ILoggingCreateRequest.d.ts +10 -0
  15. package/dist/types/models/api/ILoggingListRequest.d.ts +35 -0
  16. package/dist/types/models/api/ILoggingListResponse.d.ts +19 -0
  17. package/dist/types/models/logLevel.d.ts +4 -0
  18. package/docs/changelog.md +5 -0
  19. package/docs/examples.md +1 -0
  20. package/docs/reference/classes/LogEntryHelper.md +33 -0
  21. package/docs/reference/classes/MultiLoggingConnector.md +134 -0
  22. package/docs/reference/classes/SilentLoggingConnector.md +118 -0
  23. package/docs/reference/index.md +25 -0
  24. package/docs/reference/interfaces/ILogEntry.md +55 -0
  25. package/docs/reference/interfaces/ILoggingComponent.md +84 -0
  26. package/docs/reference/interfaces/ILoggingConnector.md +80 -0
  27. package/docs/reference/interfaces/ILoggingCreateRequest.md +11 -0
  28. package/docs/reference/interfaces/ILoggingLevelsConfig.md +11 -0
  29. package/docs/reference/interfaces/ILoggingListRequest.md +47 -0
  30. package/docs/reference/interfaces/ILoggingListResponse.md +23 -0
  31. package/docs/reference/type-aliases/LogLevel.md +5 -0
  32. package/docs/reference/variables/LoggingConnectorFactory.md +5 -0
  33. package/locales/en.json +3 -0
  34. package/package.json +65 -0
@@ -0,0 +1,33 @@
1
+ import type { IError } from "@twin.org/core";
2
+ import type { LogLevel } from "./logLevel";
3
+ /**
4
+ * Interface describing a log entry.
5
+ */
6
+ export interface ILogEntry {
7
+ /**
8
+ * The level of the error being logged.
9
+ */
10
+ level: LogLevel;
11
+ /**
12
+ * The source of the log entry.
13
+ */
14
+ source: string;
15
+ /**
16
+ * The timestamp of the log entry, if left blank will be populated by the connector.
17
+ */
18
+ ts?: number;
19
+ /**
20
+ * The message.
21
+ */
22
+ message: string;
23
+ /**
24
+ * Optional error details.
25
+ */
26
+ error?: IError;
27
+ /**
28
+ * Optional data for the message.
29
+ */
30
+ data?: {
31
+ [key: string]: unknown;
32
+ };
33
+ }
@@ -0,0 +1,36 @@
1
+ import type { IComponent } from "@twin.org/core";
2
+ import type { ILogEntry } from "./ILogEntry";
3
+ import type { LogLevel } from "./logLevel";
4
+ /**
5
+ * Interface describing a logging contract.
6
+ */
7
+ export interface ILoggingComponent extends IComponent {
8
+ /**
9
+ * Log an entry to the component.
10
+ * @param logEntry The entry to log.
11
+ * @returns Nothing.
12
+ */
13
+ log(logEntry: ILogEntry): Promise<void>;
14
+ /**
15
+ * Query the log entries.
16
+ * @param level The level of the log entries.
17
+ * @param source The source of the log entries.
18
+ * @param timeStart The inclusive time as the start of the log entries.
19
+ * @param timeEnd The inclusive time as the end of the log entries.
20
+ * @param cursor The cursor to request the next page of entities.
21
+ * @param pageSize The maximum number of entities in a page.
22
+ * @returns All the entities for the storage matching the conditions,
23
+ * and a cursor which can be used to request more entities.
24
+ * @throws NotImplementedError if the implementation does not support retrieval.
25
+ */
26
+ query(level?: LogLevel, source?: string, timeStart?: number, timeEnd?: number, cursor?: string, pageSize?: number): Promise<{
27
+ /**
28
+ * The entities, which can be partial if a limited keys list was provided.
29
+ */
30
+ entities: ILogEntry[];
31
+ /**
32
+ * An optional cursor, when defined can be used to call find to get more entities.
33
+ */
34
+ cursor?: string;
35
+ }>;
36
+ }
@@ -0,0 +1,38 @@
1
+ import type { IComponent } from "@twin.org/core";
2
+ import type { EntityCondition, SortDirection } from "@twin.org/entity";
3
+ import type { ILogEntry } from "./ILogEntry";
4
+ /**
5
+ * Interface describing a logging connector.
6
+ */
7
+ export interface ILoggingConnector extends IComponent {
8
+ /**
9
+ * Log an entry to the connector.
10
+ * @param logEntry The entry to log.
11
+ * @returns Nothing.
12
+ */
13
+ log(logEntry: ILogEntry): Promise<void>;
14
+ /**
15
+ * Query the log entries.
16
+ * @param conditions The conditions to match for the entities.
17
+ * @param sortProperties The optional sort order.
18
+ * @param properties The optional keys to return, defaults to all.
19
+ * @param cursor The cursor to request the next page of entities.
20
+ * @param pageSize The maximum number of entities in a page.
21
+ * @returns All the entities for the storage matching the conditions,
22
+ * and a cursor which can be used to request more entities.
23
+ * @throws NotImplementedError if the implementation does not support retrieval.
24
+ */
25
+ query(conditions?: EntityCondition<ILogEntry>, sortProperties?: {
26
+ property: keyof Omit<ILogEntry, "error" | "data">;
27
+ sortDirection: SortDirection;
28
+ }[], properties?: (keyof ILogEntry)[], cursor?: string, pageSize?: number): Promise<{
29
+ /**
30
+ * The entities, which can be partial if a limited keys list was provided.
31
+ */
32
+ entities: Partial<ILogEntry>[];
33
+ /**
34
+ * An optional cursor, when defined can be used to call find to get more entities.
35
+ */
36
+ cursor?: string;
37
+ }>;
38
+ }
@@ -0,0 +1,10 @@
1
+ import type { LogLevel } from "./logLevel";
2
+ /**
3
+ * Configuration for the logging connectors to specify the levels to display.
4
+ */
5
+ export interface ILoggingLevelsConfig {
6
+ /**
7
+ * The log levels to display, will default to all.
8
+ */
9
+ levels?: LogLevel[];
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { ILogEntry } from "../ILogEntry";
2
+ /**
3
+ * Create a new log entry.
4
+ */
5
+ export interface ILoggingCreateRequest {
6
+ /**
7
+ * The data to be used in the create.
8
+ */
9
+ body: ILogEntry;
10
+ }
@@ -0,0 +1,35 @@
1
+ import type { LogLevel } from "../logLevel";
2
+ /**
3
+ * Get the a list of the log entries.
4
+ */
5
+ export interface ILoggingListRequest {
6
+ /**
7
+ * The query parameters.
8
+ */
9
+ query: {
10
+ /**
11
+ * The level of the log entries to retrieve.
12
+ */
13
+ level?: LogLevel;
14
+ /**
15
+ * The source of the log entries to retrieve.
16
+ */
17
+ source?: string;
18
+ /**
19
+ * The start time of the metrics to retrieve as a timestamp in ms.
20
+ */
21
+ timeStart?: number;
22
+ /**
23
+ * The end time of the metrics to retrieve as a timestamp in ms.
24
+ */
25
+ timeEnd?: number;
26
+ /**
27
+ * The optional cursor to get next chunk.
28
+ */
29
+ cursor?: string;
30
+ /**
31
+ * The maximum number of entities in a page.
32
+ */
33
+ pageSize?: number;
34
+ };
35
+ }
@@ -0,0 +1,19 @@
1
+ import type { ILogEntry } from "../ILogEntry";
2
+ /**
3
+ * Response for log entry list request.
4
+ */
5
+ export interface ILoggingListResponse {
6
+ /**
7
+ * The response payload.
8
+ */
9
+ body: {
10
+ /**
11
+ * The entities, which can be partial if a limited keys list was provided.
12
+ */
13
+ entities: ILogEntry[];
14
+ /**
15
+ * An optional cursor, when defined can be used to call find to get more entities.
16
+ */
17
+ cursor?: string;
18
+ };
19
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Log level.
3
+ */
4
+ export type LogLevel = "info" | "error" | "warn" | "trace" | "debug";
@@ -0,0 +1,5 @@
1
+ # @twin.org/logging-models - Changelog
2
+
3
+ ## v0.0.1-next.2
4
+
5
+ - Initial Release
@@ -0,0 +1 @@
1
+ # @twin.org/logging-models - Examples
@@ -0,0 +1,33 @@
1
+ # Class: LogEntryHelper
2
+
3
+ Helper class for log entry operations.
4
+
5
+ ## Constructors
6
+
7
+ ### new LogEntryHelper()
8
+
9
+ > **new LogEntryHelper**(): [`LogEntryHelper`](LogEntryHelper.md)
10
+
11
+ #### Returns
12
+
13
+ [`LogEntryHelper`](LogEntryHelper.md)
14
+
15
+ ## Methods
16
+
17
+ ### translate()
18
+
19
+ > `static` **translate**(`logEntry`): `undefined` \| `string`
20
+
21
+ Translate the log entry.
22
+
23
+ #### Parameters
24
+
25
+ • **logEntry**: [`ILogEntry`](../interfaces/ILogEntry.md)
26
+
27
+ The log entry.
28
+
29
+ #### Returns
30
+
31
+ `undefined` \| `string`
32
+
33
+ The translated log entry if a translation can be found.
@@ -0,0 +1,134 @@
1
+ # Class: MultiLoggingConnector
2
+
3
+ Class for performing logging operations on multiple connectors.
4
+
5
+ ## Implements
6
+
7
+ - [`ILoggingConnector`](../interfaces/ILoggingConnector.md)
8
+
9
+ ## Constructors
10
+
11
+ ### new MultiLoggingConnector()
12
+
13
+ > **new MultiLoggingConnector**(`options`): [`MultiLoggingConnector`](MultiLoggingConnector.md)
14
+
15
+ Create a new instance of MultiLoggingConnector.
16
+
17
+ #### Parameters
18
+
19
+ • **options**
20
+
21
+ The options for the connector.
22
+
23
+ • **options.loggingConnectorTypes**: `string`[]
24
+
25
+ The logging connectors to multiplex.
26
+
27
+ • **options.config?**: [`ILoggingLevelsConfig`](../interfaces/ILoggingLevelsConfig.md)
28
+
29
+ The configuration for the logging connector.
30
+
31
+ #### Returns
32
+
33
+ [`MultiLoggingConnector`](MultiLoggingConnector.md)
34
+
35
+ ## Properties
36
+
37
+ ### NAMESPACE
38
+
39
+ > `readonly` `static` **NAMESPACE**: `string` = `"multi"`
40
+
41
+ The namespace for the logging connector.
42
+
43
+ ***
44
+
45
+ ### CLASS\_NAME
46
+
47
+ > `readonly` **CLASS\_NAME**: `string`
48
+
49
+ Runtime name for the class.
50
+
51
+ #### Implementation of
52
+
53
+ `ILoggingConnector.CLASS_NAME`
54
+
55
+ ## Methods
56
+
57
+ ### log()
58
+
59
+ > **log**(`logEntry`): `Promise`\<`void`\>
60
+
61
+ Log an entry to the connector.
62
+
63
+ #### Parameters
64
+
65
+ • **logEntry**: [`ILogEntry`](../interfaces/ILogEntry.md)
66
+
67
+ The entry to log.
68
+
69
+ #### Returns
70
+
71
+ `Promise`\<`void`\>
72
+
73
+ Nothing.
74
+
75
+ #### Implementation of
76
+
77
+ [`ILoggingConnector`](../interfaces/ILoggingConnector.md).[`log`](../interfaces/ILoggingConnector.md#log)
78
+
79
+ ***
80
+
81
+ ### query()
82
+
83
+ > **query**(`conditions`?, `sortProperties`?, `properties`?, `cursor`?, `pageSize`?): `Promise`\<`object`\>
84
+
85
+ Query the log entries.
86
+
87
+ #### Parameters
88
+
89
+ • **conditions?**: `EntityCondition`\<[`ILogEntry`](../interfaces/ILogEntry.md)\>
90
+
91
+ The conditions to match for the entities.
92
+
93
+ • **sortProperties?**: `object`[]
94
+
95
+ The optional sort order.
96
+
97
+ • **properties?**: keyof [`ILogEntry`](../interfaces/ILogEntry.md)[]
98
+
99
+ The optional keys to return, defaults to all.
100
+
101
+ • **cursor?**: `string`
102
+
103
+ The cursor to request the next page of entities.
104
+
105
+ • **pageSize?**: `number`
106
+
107
+ The maximum number of entities in a page.
108
+
109
+ #### Returns
110
+
111
+ `Promise`\<`object`\>
112
+
113
+ All the entities for the storage matching the conditions,
114
+ and a cursor which can be used to request more entities.
115
+
116
+ ##### entities
117
+
118
+ > **entities**: `Partial`\<[`ILogEntry`](../interfaces/ILogEntry.md)\>[]
119
+
120
+ The entities, which can be partial if a limited keys list was provided.
121
+
122
+ ##### cursor?
123
+
124
+ > `optional` **cursor**: `string`
125
+
126
+ An optional cursor, when defined can be used to call find to get more entities.
127
+
128
+ #### Throws
129
+
130
+ NotImplementedError if the implementation does not support retrieval.
131
+
132
+ #### Implementation of
133
+
134
+ [`ILoggingConnector`](../interfaces/ILoggingConnector.md).[`query`](../interfaces/ILoggingConnector.md#query)
@@ -0,0 +1,118 @@
1
+ # Class: SilentLoggingConnector
2
+
3
+ Class for performing logging operations to nowhere.
4
+
5
+ ## Implements
6
+
7
+ - [`ILoggingConnector`](../interfaces/ILoggingConnector.md)
8
+
9
+ ## Constructors
10
+
11
+ ### new SilentLoggingConnector()
12
+
13
+ > **new SilentLoggingConnector**(): [`SilentLoggingConnector`](SilentLoggingConnector.md)
14
+
15
+ #### Returns
16
+
17
+ [`SilentLoggingConnector`](SilentLoggingConnector.md)
18
+
19
+ ## Properties
20
+
21
+ ### NAMESPACE
22
+
23
+ > `readonly` `static` **NAMESPACE**: `string` = `"silent"`
24
+
25
+ The namespace for the logging connector.
26
+
27
+ ***
28
+
29
+ ### CLASS\_NAME
30
+
31
+ > `readonly` **CLASS\_NAME**: `string`
32
+
33
+ Runtime name for the class.
34
+
35
+ #### Implementation of
36
+
37
+ `ILoggingConnector.CLASS_NAME`
38
+
39
+ ## Methods
40
+
41
+ ### log()
42
+
43
+ > **log**(`logEntry`): `Promise`\<`void`\>
44
+
45
+ Log an entry to the connector.
46
+
47
+ #### Parameters
48
+
49
+ • **logEntry**: [`ILogEntry`](../interfaces/ILogEntry.md)
50
+
51
+ The entry to log.
52
+
53
+ #### Returns
54
+
55
+ `Promise`\<`void`\>
56
+
57
+ Nothing.
58
+
59
+ #### Implementation of
60
+
61
+ [`ILoggingConnector`](../interfaces/ILoggingConnector.md).[`log`](../interfaces/ILoggingConnector.md#log)
62
+
63
+ ***
64
+
65
+ ### query()
66
+
67
+ > **query**(`conditions`?, `sortProperties`?, `properties`?, `cursor`?, `pageSize`?): `Promise`\<`object`\>
68
+
69
+ Query the log entries.
70
+
71
+ #### Parameters
72
+
73
+ • **conditions?**: `EntityCondition`\<[`ILogEntry`](../interfaces/ILogEntry.md)\>
74
+
75
+ The conditions to match for the entities.
76
+
77
+ • **sortProperties?**: `object`[]
78
+
79
+ The optional sort order.
80
+
81
+ • **properties?**: keyof [`ILogEntry`](../interfaces/ILogEntry.md)[]
82
+
83
+ The optional keys to return, defaults to all.
84
+
85
+ • **cursor?**: `string`
86
+
87
+ The cursor to request the next page of entities.
88
+
89
+ • **pageSize?**: `number`
90
+
91
+ The maximum number of entities in a page.
92
+
93
+ #### Returns
94
+
95
+ `Promise`\<`object`\>
96
+
97
+ All the entities for the storage matching the conditions,
98
+ and a cursor which can be used to request more entities.
99
+
100
+ ##### entities
101
+
102
+ > **entities**: `Partial`\<[`ILogEntry`](../interfaces/ILogEntry.md)\>[]
103
+
104
+ The entities, which can be partial if a limited keys list was provided.
105
+
106
+ ##### cursor?
107
+
108
+ > `optional` **cursor**: `string`
109
+
110
+ An optional cursor, when defined can be used to call find to get more entities.
111
+
112
+ #### Throws
113
+
114
+ NotImplementedError if the implementation does not support retrieval.
115
+
116
+ #### Implementation of
117
+
118
+ [`ILoggingConnector`](../interfaces/ILoggingConnector.md).[`query`](../interfaces/ILoggingConnector.md#query)
@@ -0,0 +1,25 @@
1
+ # @twin.org/logging-models
2
+
3
+ ## Classes
4
+
5
+ - [MultiLoggingConnector](classes/MultiLoggingConnector.md)
6
+ - [SilentLoggingConnector](classes/SilentLoggingConnector.md)
7
+ - [LogEntryHelper](classes/LogEntryHelper.md)
8
+
9
+ ## Interfaces
10
+
11
+ - [ILogEntry](interfaces/ILogEntry.md)
12
+ - [ILoggingComponent](interfaces/ILoggingComponent.md)
13
+ - [ILoggingConnector](interfaces/ILoggingConnector.md)
14
+ - [ILoggingLevelsConfig](interfaces/ILoggingLevelsConfig.md)
15
+ - [ILoggingCreateRequest](interfaces/ILoggingCreateRequest.md)
16
+ - [ILoggingListRequest](interfaces/ILoggingListRequest.md)
17
+ - [ILoggingListResponse](interfaces/ILoggingListResponse.md)
18
+
19
+ ## Type Aliases
20
+
21
+ - [LogLevel](type-aliases/LogLevel.md)
22
+
23
+ ## Variables
24
+
25
+ - [LoggingConnectorFactory](variables/LoggingConnectorFactory.md)
@@ -0,0 +1,55 @@
1
+ # Interface: ILogEntry
2
+
3
+ Interface describing a log entry.
4
+
5
+ ## Properties
6
+
7
+ ### level
8
+
9
+ > **level**: [`LogLevel`](../type-aliases/LogLevel.md)
10
+
11
+ The level of the error being logged.
12
+
13
+ ***
14
+
15
+ ### source
16
+
17
+ > **source**: `string`
18
+
19
+ The source of the log entry.
20
+
21
+ ***
22
+
23
+ ### ts?
24
+
25
+ > `optional` **ts**: `number`
26
+
27
+ The timestamp of the log entry, if left blank will be populated by the connector.
28
+
29
+ ***
30
+
31
+ ### message
32
+
33
+ > **message**: `string`
34
+
35
+ The message.
36
+
37
+ ***
38
+
39
+ ### error?
40
+
41
+ > `optional` **error**: `IError`
42
+
43
+ Optional error details.
44
+
45
+ ***
46
+
47
+ ### data?
48
+
49
+ > `optional` **data**: `object`
50
+
51
+ Optional data for the message.
52
+
53
+ #### Index Signature
54
+
55
+ \[`key`: `string`\]: `unknown`
@@ -0,0 +1,84 @@
1
+ # Interface: ILoggingComponent
2
+
3
+ Interface describing a logging contract.
4
+
5
+ ## Extends
6
+
7
+ - `IComponent`
8
+
9
+ ## Methods
10
+
11
+ ### log()
12
+
13
+ > **log**(`logEntry`): `Promise`\<`void`\>
14
+
15
+ Log an entry to the component.
16
+
17
+ #### Parameters
18
+
19
+ • **logEntry**: [`ILogEntry`](ILogEntry.md)
20
+
21
+ The entry to log.
22
+
23
+ #### Returns
24
+
25
+ `Promise`\<`void`\>
26
+
27
+ Nothing.
28
+
29
+ ***
30
+
31
+ ### query()
32
+
33
+ > **query**(`level`?, `source`?, `timeStart`?, `timeEnd`?, `cursor`?, `pageSize`?): `Promise`\<`object`\>
34
+
35
+ Query the log entries.
36
+
37
+ #### Parameters
38
+
39
+ • **level?**: [`LogLevel`](../type-aliases/LogLevel.md)
40
+
41
+ The level of the log entries.
42
+
43
+ • **source?**: `string`
44
+
45
+ The source of the log entries.
46
+
47
+ • **timeStart?**: `number`
48
+
49
+ The inclusive time as the start of the log entries.
50
+
51
+ • **timeEnd?**: `number`
52
+
53
+ The inclusive time as the end of the log entries.
54
+
55
+ • **cursor?**: `string`
56
+
57
+ The cursor to request the next page of entities.
58
+
59
+ • **pageSize?**: `number`
60
+
61
+ The maximum number of entities in a page.
62
+
63
+ #### Returns
64
+
65
+ `Promise`\<`object`\>
66
+
67
+ All the entities for the storage matching the conditions,
68
+ and a cursor which can be used to request more entities.
69
+
70
+ ##### entities
71
+
72
+ > **entities**: [`ILogEntry`](ILogEntry.md)[]
73
+
74
+ The entities, which can be partial if a limited keys list was provided.
75
+
76
+ ##### cursor?
77
+
78
+ > `optional` **cursor**: `string`
79
+
80
+ An optional cursor, when defined can be used to call find to get more entities.
81
+
82
+ #### Throws
83
+
84
+ NotImplementedError if the implementation does not support retrieval.