@twin.org/context 0.0.3-next.22 → 0.0.3-next.24

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TWIN Framework Context
2
2
 
3
- This package contains helper methods and classes for using contexts.
3
+ This package is part of the framework workspace and provides helper methods/classes for context handling to support consistent development workflows across the ecosystem.
4
4
 
5
5
  ## Installation
6
6
 
package/docs/changelog.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.24](https://github.com/twinfoundation/framework/compare/context-v0.0.3-next.23...context-v0.0.3-next.24) (2026-03-19)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * ensure __decorate is defined for decorators ([103a563](https://github.com/twinfoundation/framework/commit/103a563ce01ebdef6240d2e590e7b026e8692684))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/core bumped from 0.0.3-next.23 to 0.0.3-next.24
16
+ * @twin.org/nameof bumped from 0.0.3-next.23 to 0.0.3-next.24
17
+ * devDependencies
18
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.23 to 0.0.3-next.24
19
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.23 to 0.0.3-next.24
20
+ * @twin.org/validate-locales bumped from 0.0.3-next.23 to 0.0.3-next.24
21
+
22
+ ## [0.0.3-next.23](https://github.com/twinfoundation/framework/compare/context-v0.0.3-next.22...context-v0.0.3-next.23) (2026-03-17)
23
+
24
+
25
+ ### Miscellaneous Chores
26
+
27
+ * **context:** Synchronize repo versions
28
+
29
+
30
+ ### Dependencies
31
+
32
+ * The following workspace dependencies were updated
33
+ * dependencies
34
+ * @twin.org/core bumped from 0.0.3-next.22 to 0.0.3-next.23
35
+ * @twin.org/nameof bumped from 0.0.3-next.22 to 0.0.3-next.23
36
+ * devDependencies
37
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.22 to 0.0.3-next.23
38
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.22 to 0.0.3-next.23
39
+ * @twin.org/validate-locales bumped from 0.0.3-next.22 to 0.0.3-next.23
40
+
3
41
  ## [0.0.3-next.22](https://github.com/twinfoundation/framework/compare/context-v0.0.3-next.21...context-v0.0.3-next.22) (2026-02-26)
4
42
 
5
43
 
@@ -433,4 +471,4 @@
433
471
  * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.0 to 0.0.3-next.1
434
472
  * @twin.org/validate-locales bumped from 0.0.3-next.0 to 0.0.3-next.1
435
473
 
436
- ## @twin.org/context - Changelog
474
+ ## Changelog
package/docs/examples.md CHANGED
@@ -1 +1,57 @@
1
- # @twin.org/context - Examples
1
+ # Context Examples
2
+
3
+ Use these snippets to keep trace identifiers consistent across asynchronous operations and service boundaries.
4
+
5
+ ## ContextIdHelper
6
+
7
+ ```typescript
8
+ import { ContextIdHelper } from '@twin.org/context';
9
+
10
+ const traceContext = {
11
+ traceId: 'trc-0011223344556677',
12
+ spanId: 'spn-9a8b7c6d5e4f3210'
13
+ };
14
+
15
+ ContextIdHelper.short(traceContext.traceId); // '0011223344556677'
16
+ ContextIdHelper.shortAll(traceContext); // { traceId: '0011223344556677', spanId: '9a8b7c6d5e4f3210' }
17
+ ```
18
+
19
+ ```typescript
20
+ import { ContextIdHelper } from '@twin.org/context';
21
+
22
+ const contextIds = {
23
+ traceId: 'trace-1234',
24
+ spanId: 'span-5678',
25
+ requestId: 'req-90ab'
26
+ };
27
+
28
+ const combined = ContextIdHelper.shortCombined(contextIds); // '1234:5678:90ab'
29
+ ContextIdHelper.shortSplit(combined); // ['1234', '5678', '90ab']
30
+ ```
31
+
32
+ ## ContextIdStore
33
+
34
+ ```typescript
35
+ import { ContextIdStore } from '@twin.org/context';
36
+
37
+ await ContextIdStore.run({ traceId: 'trc-01', spanId: 'spn-02' }, async () => {
38
+ ContextIdStore.getContextIds(); // { traceId: 'trc-01', spanId: 'spn-02' }
39
+ });
40
+ ```
41
+
42
+ ## ContextIdHandlerFactory
43
+
44
+ ```typescript
45
+ import { ContextIdHandlerFactory } from '@twin.org/context';
46
+ import type { IContextIdHandler } from '@twin.org/context';
47
+
48
+ class RequestContextHandler implements IContextIdHandler {
49
+ public getContextIds() {
50
+ return { traceId: 'trc-1001', spanId: 'spn-2002' };
51
+ }
52
+ }
53
+
54
+ ContextIdHandlerFactory.register('request', () => new RequestContextHandler());
55
+ const handler = ContextIdHandlerFactory.create('request');
56
+ handler.getContextIds().traceId; // 'trc-1001'
57
+ ```
@@ -14,7 +14,7 @@ Class to help with context IDs.
14
14
 
15
15
  ## Properties
16
16
 
17
- ### CLASS\_NAME
17
+ ### CLASS\_NAME {#class_name}
18
18
 
19
19
  > `readonly` `static` **CLASS\_NAME**: `string`
20
20
 
@@ -22,7 +22,7 @@ Runtime name for the class.
22
22
 
23
23
  ## Methods
24
24
 
25
- ### guard()
25
+ ### guard() {#guard}
26
26
 
27
27
  > `static` **guard**\<`T`, `K`\>(`contextIds`, `key`): `asserts contextIds is T & { [P in string]: string }`
28
28
 
@@ -42,9 +42,9 @@ Perform a runtime guard on the provided context ID value.
42
42
 
43
43
  ##### contextIds
44
44
 
45
- The context IDs to guard.
45
+ `T` \| `undefined`
46
46
 
47
- `T` | `undefined`
47
+ The context IDs to guard.
48
48
 
49
49
  ##### key
50
50
 
@@ -62,7 +62,7 @@ Guard error if the value is invalid.
62
62
 
63
63
  ***
64
64
 
65
- ### short()
65
+ ### short() {#short}
66
66
 
67
67
  > `static` **short**(`contextIds`, `key`): `string`
68
68
 
@@ -72,9 +72,9 @@ Gets the short version of a context ID.
72
72
 
73
73
  ##### contextIds
74
74
 
75
- The context IDs to get the short version from.
75
+ [`IContextIds`](../interfaces/IContextIds.md) \| `undefined`
76
76
 
77
- [`IContextIds`](../interfaces/IContextIds.md) | `undefined`
77
+ The context IDs to get the short version from.
78
78
 
79
79
  ##### key
80
80
 
@@ -94,7 +94,7 @@ Guard error if the value is invalid.
94
94
 
95
95
  ***
96
96
 
97
- ### guardAll()
97
+ ### guardAll() {#guardall}
98
98
 
99
99
  > `static` **guardAll**\<`T`, `K`\>(`contextIds`, `keys`): `asserts contextIds is T & { [P in string]: string }`
100
100
 
@@ -114,15 +114,15 @@ Perform a runtime guard on the provided context ID values.
114
114
 
115
115
  ##### contextIds
116
116
 
117
- The context IDs to guard.
117
+ `T` \| `undefined`
118
118
 
119
- `T` | `undefined`
119
+ The context IDs to guard.
120
120
 
121
121
  ##### keys
122
122
 
123
- The context ID keys to guard.
123
+ readonly `K`[] \| `undefined`
124
124
 
125
- readonly `K`[] | `undefined`
125
+ The context ID keys to guard.
126
126
 
127
127
  #### Returns
128
128
 
@@ -134,7 +134,7 @@ Guard error if the value is invalid.
134
134
 
135
135
  ***
136
136
 
137
- ### shortAll()
137
+ ### shortAll() {#shortall}
138
138
 
139
139
  > `static` **shortAll**(`contextIds`, `keys`): [`IContextIds`](../interfaces/IContextIds.md)
140
140
 
@@ -144,15 +144,15 @@ Gets the short versions of multiple context IDs.
144
144
 
145
145
  ##### contextIds
146
146
 
147
- The context IDs to get the short versions from.
147
+ [`IContextIds`](../interfaces/IContextIds.md) \| `undefined`
148
148
 
149
- [`IContextIds`](../interfaces/IContextIds.md) | `undefined`
149
+ The context IDs to get the short versions from.
150
150
 
151
151
  ##### keys
152
152
 
153
- The context ID keys to get the short versions for.
153
+ `string`[] \| `undefined`
154
154
 
155
- `string`[] | `undefined`
155
+ The context ID keys to get the short versions for.
156
156
 
157
157
  #### Returns
158
158
 
@@ -162,9 +162,9 @@ The short versions of the context IDs.
162
162
 
163
163
  ***
164
164
 
165
- ### shortCombined()
165
+ ### shortCombined() {#shortcombined}
166
166
 
167
- > `static` **shortCombined**(`contextIds`, `keys`, `separator`): `string` \| `undefined`
167
+ > `static` **shortCombined**(`contextIds`, `keys`, `separator?`): `string` \| `undefined`
168
168
 
169
169
  Gets the combined short version.
170
170
 
@@ -172,17 +172,17 @@ Gets the combined short version.
172
172
 
173
173
  ##### contextIds
174
174
 
175
- The context IDs to get the short versions from.
175
+ [`IContextIds`](../interfaces/IContextIds.md) \| `undefined`
176
176
 
177
- [`IContextIds`](../interfaces/IContextIds.md) | `undefined`
177
+ The context IDs to get the short versions from.
178
178
 
179
179
  ##### keys
180
180
 
181
- The context ID keys to get the short versions for.
181
+ `string`[] \| `undefined`
182
182
 
183
- `string`[] | `undefined`
183
+ The context ID keys to get the short versions for.
184
184
 
185
- ##### separator
185
+ ##### separator?
186
186
 
187
187
  `string` = `"/"`
188
188
 
@@ -196,9 +196,9 @@ The short version combined.
196
196
 
197
197
  ***
198
198
 
199
- ### shortSplit()
199
+ ### shortSplit() {#shortsplit}
200
200
 
201
- > `static` **shortSplit**(`keys`, `combined`, `separator`): [`IContextIds`](../interfaces/IContextIds.md)
201
+ > `static` **shortSplit**(`keys`, `combined`, `separator?`): [`IContextIds`](../interfaces/IContextIds.md)
202
202
 
203
203
  Split a combined short version in to the separate context IDs.
204
204
 
@@ -216,7 +216,7 @@ The context ID keys to get the short versions for.
216
216
 
217
217
  The combined short version to separate.
218
218
 
219
- ##### separator
219
+ ##### separator?
220
220
 
221
221
  `string` = `"/"`
222
222
 
@@ -234,9 +234,9 @@ GeneralError if the number of parts does not match the number of keys.
234
234
 
235
235
  ***
236
236
 
237
- ### combinedContextKey()
237
+ ### combinedContextKey() {#combinedcontextkey}
238
238
 
239
- > `static` **combinedContextKey**(`contextIds`, `keys`, `separator`): `string` \| `undefined`
239
+ > `static` **combinedContextKey**(`contextIds`, `keys`, `separator?`): `string` \| `undefined`
240
240
 
241
241
  Create a combined key.
242
242
 
@@ -244,17 +244,17 @@ Create a combined key.
244
244
 
245
245
  ##### contextIds
246
246
 
247
- The context IDs to create the combined key for.
247
+ [`IContextIds`](../interfaces/IContextIds.md) \| `undefined`
248
248
 
249
- [`IContextIds`](../interfaces/IContextIds.md) | `undefined`
249
+ The context IDs to create the combined key for.
250
250
 
251
251
  ##### keys
252
252
 
253
- The context ID keys to get the short versions for.
253
+ `string`[] \| `undefined`
254
254
 
255
- `string`[] | `undefined`
255
+ The context ID keys to get the short versions for.
256
256
 
257
- ##### separator
257
+ ##### separator?
258
258
 
259
259
  `string` = `"/"`
260
260
 
@@ -268,7 +268,7 @@ The short version combined.
268
268
 
269
269
  ***
270
270
 
271
- ### pickKeysFromAvailable()
271
+ ### pickKeysFromAvailable() {#pickkeysfromavailable}
272
272
 
273
273
  > `static` **pickKeysFromAvailable**(`availableKeys?`, `desiredKeys?`): `string`[]
274
274
 
@@ -14,7 +14,7 @@ Class to maintain context ids and execute an async method.
14
14
 
15
15
  ## Properties
16
16
 
17
- ### CLASS\_NAME
17
+ ### CLASS\_NAME {#class_name}
18
18
 
19
19
  > `readonly` `static` **CLASS\_NAME**: `string`
20
20
 
@@ -22,7 +22,7 @@ Runtime name for the class.
22
22
 
23
23
  ## Methods
24
24
 
25
- ### run()
25
+ ### run() {#run}
26
26
 
27
27
  > `static` **run**\<`T`\>(`contextIds`, `asyncMethod`): `Promise`\<`T`\>
28
28
 
@@ -56,7 +56,7 @@ Nothing.
56
56
 
57
57
  ***
58
58
 
59
- ### getContextIds()
59
+ ### getContextIds() {#getcontextids}
60
60
 
61
61
  > `static` **getContextIds**(): `Promise`\<[`IContextIds`](../interfaces/IContextIds.md) \| `undefined`\>
62
62
 
@@ -70,7 +70,7 @@ The context IDs.
70
70
 
71
71
  ***
72
72
 
73
- ### getStorage()
73
+ ### getStorage() {#getstorage}
74
74
 
75
75
  > `static` **getStorage**(): `Promise`\<`AsyncLocalStorage`\<[`IContextIds`](../interfaces/IContextIds.md)\>\>
76
76
 
@@ -8,7 +8,7 @@ Interface describing a context ID handler.
8
8
 
9
9
  ## Methods
10
10
 
11
- ### short()?
11
+ ### short()? {#short}
12
12
 
13
13
  > `optional` **short**(`value`): `string`
14
14
 
@@ -30,7 +30,7 @@ The short form version of the context ID.
30
30
 
31
31
  ***
32
32
 
33
- ### guard()?
33
+ ### guard()? {#guard}
34
34
 
35
35
  > `optional` **guard**(`value`): `void`
36
36
 
@@ -51,3 +51,99 @@ The context ID value to guard.
51
51
  #### Throws
52
52
 
53
53
  Guard error if the value is invalid.
54
+
55
+ ***
56
+
57
+ ### className() {#classname}
58
+
59
+ > **className**(): `string`
60
+
61
+ Returns the class name of the component.
62
+
63
+ #### Returns
64
+
65
+ `string`
66
+
67
+ The class name of the component.
68
+
69
+ #### Inherited from
70
+
71
+ `IComponent.className`
72
+
73
+ ***
74
+
75
+ ### bootstrap()? {#bootstrap}
76
+
77
+ > `optional` **bootstrap**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
78
+
79
+ Bootstrap the component by creating and initializing any resources it needs.
80
+
81
+ #### Parameters
82
+
83
+ ##### nodeLoggingComponentType?
84
+
85
+ `string`
86
+
87
+ The node logging component type.
88
+
89
+ #### Returns
90
+
91
+ `Promise`\<`boolean`\>
92
+
93
+ True if the bootstrapping process was successful.
94
+
95
+ #### Inherited from
96
+
97
+ `IComponent.bootstrap`
98
+
99
+ ***
100
+
101
+ ### start()? {#start}
102
+
103
+ > `optional` **start**(`nodeLoggingComponentType?`): `Promise`\<`void`\>
104
+
105
+ The component needs to be started when the node is initialized.
106
+
107
+ #### Parameters
108
+
109
+ ##### nodeLoggingComponentType?
110
+
111
+ `string`
112
+
113
+ The node logging component type.
114
+
115
+ #### Returns
116
+
117
+ `Promise`\<`void`\>
118
+
119
+ Nothing.
120
+
121
+ #### Inherited from
122
+
123
+ `IComponent.start`
124
+
125
+ ***
126
+
127
+ ### stop()? {#stop}
128
+
129
+ > `optional` **stop**(`nodeLoggingComponentType?`): `Promise`\<`void`\>
130
+
131
+ The component needs to be stopped when the node is closed.
132
+
133
+ #### Parameters
134
+
135
+ ##### nodeLoggingComponentType?
136
+
137
+ `string`
138
+
139
+ The node logging component type.
140
+
141
+ #### Returns
142
+
143
+ `Promise`\<`void`\>
144
+
145
+ Nothing.
146
+
147
+ #### Inherited from
148
+
149
+ `IComponent.stop`
@@ -4,6 +4,6 @@ Interface describing context ids which can be accessed async from a request.
4
4
 
5
5
  ## Indexable
6
6
 
7
- \[`id`: `string`\]: `string` \| `undefined`
7
+ > \[`id`: `string`\]: `string` \| `undefined`
8
8
 
9
9
  The context id keys and values.
@@ -6,25 +6,25 @@ Default definition of some context keys.
6
6
 
7
7
  ## Type Declaration
8
8
 
9
- ### Node
9
+ ### Node {#node}
10
10
 
11
11
  > `readonly` **Node**: `"node"` = `"node"`
12
12
 
13
13
  Standard property type definition for node.
14
14
 
15
- ### Tenant
15
+ ### Tenant {#tenant}
16
16
 
17
17
  > `readonly` **Tenant**: `"tenant"` = `"tenant"`
18
18
 
19
19
  Standard property type definition for tenant.
20
20
 
21
- ### Organization
21
+ ### Organization {#organization}
22
22
 
23
23
  > `readonly` **Organization**: `"organization"` = `"organization"`
24
24
 
25
25
  Standard property type definition for organization.
26
26
 
27
- ### User
27
+ ### User {#user}
28
28
 
29
29
  > `readonly` **User**: `"user"` = `"user"`
30
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/context",
3
- "version": "0.0.3-next.22",
3
+ "version": "0.0.3-next.24",
4
4
  "description": "Helper methods/classes for context handling",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,8 +14,8 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/core": "0.0.3-next.22",
18
- "@twin.org/nameof": "0.0.3-next.22"
17
+ "@twin.org/core": "0.0.3-next.24",
18
+ "@twin.org/nameof": "0.0.3-next.24"
19
19
  },
20
20
  "main": "./dist/es/index.js",
21
21
  "types": "./dist/types/index.d.ts",