Skip to content

Commit 4579f5e

Browse files
committed
Add implementation for getShortId
1 parent 38ea1a5 commit 4579f5e

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/AsyncStore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface AsyncStore {
1212
find: (key: string) => any;
1313
isInitialized: () => boolean;
1414
getId: () => string | undefined;
15+
getShortId: () => string | undefined;
1516
}
1617

1718
export default AsyncStore;

src/impl/domain.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,18 @@ export function getId(): string | undefined {
234234
return activeDomain && activeDomain[ID_KEY];
235235
}
236236

237+
/**
238+
* Gets the short unique domain id created for the current context / scope.
239+
*
240+
* @returns {(string | undefined)}
241+
*/
242+
export function getShortId(): string | undefined {
243+
const activeDomain = getActiveDomain();
244+
const id = activeDomain && activeDomain[ID_KEY];
245+
246+
return id && id.substring(0, 8);
247+
}
248+
237249
/**
238250
* Get the store from the active domain.
239251
*

src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ export function getId(): string | undefined {
199199
return initializedAdapter && getInstance(initializedAdapter).getId();
200200
}
201201

202+
/**
203+
* Gets the short unique domain id created for the current context / scope.
204+
*
205+
* @returns {(string | undefined)}
206+
*/
207+
export function getShortId(): string | undefined {
208+
return initializedAdapter && getInstance(initializedAdapter).getShortId();
209+
}
210+
202211
/**
203212
* Get the adapter instance based on adapter type.
204213
*

0 commit comments

Comments
 (0)