onnxruntime
27 строк · 774.0 Байт
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4class AttributeWithCacheKeyImpl {
5constructor(attribute: Record<string, unknown>) {
6Object.assign(this, attribute);
7}
8
9private key: string;
10public get cacheKey(): string {
11if (!this.key) {
12this.key = Object.getOwnPropertyNames(this)
13.sort()
14.map((name) => `${(this as Record<string, unknown>)[name]}`)
15.join(';');
16}
17return this.key;
18}
19}
20
21export interface AttributeWithCacheKey {
22readonly cacheKey: string;
23}
24
25export const createAttributeWithCacheKey = <T extends Record<string, unknown>>(
26attribute: T,
27): T & AttributeWithCacheKey => new AttributeWithCacheKeyImpl(attribute) as unknown as T & AttributeWithCacheKey;
28