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

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,24 @@
1
1
  # Changelog
2
2
 
3
+ ## [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)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **context:** Synchronize repo versions
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/core bumped from 0.0.3-next.22 to 0.0.3-next.23
16
+ * @twin.org/nameof bumped from 0.0.3-next.22 to 0.0.3-next.23
17
+ * devDependencies
18
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.22 to 0.0.3-next.23
19
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.22 to 0.0.3-next.23
20
+ * @twin.org/validate-locales bumped from 0.0.3-next.22 to 0.0.3-next.23
21
+
3
22
  ## [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
23
 
5
24
 
@@ -433,4 +452,4 @@
433
452
  * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.0 to 0.0.3-next.1
434
453
  * @twin.org/validate-locales bumped from 0.0.3-next.0 to 0.0.3-next.1
435
454
 
436
- ## @twin.org/context - Changelog
455
+ ## 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
 
@@ -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
 
@@ -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
 
@@ -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
 
@@ -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
 
@@ -182,7 +182,7 @@ The context ID keys to get the short versions for.
182
182
 
183
183
  `string`[] | `undefined`
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
 
@@ -254,7 +254,7 @@ The context ID keys to get the short versions for.
254
254
 
255
255
  `string`[] | `undefined`
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`
@@ -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.23",
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.23",
18
+ "@twin.org/nameof": "0.0.3-next.23"
19
19
  },
20
20
  "main": "./dist/es/index.js",
21
21
  "types": "./dist/types/index.d.ts",