onnxruntime
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
25/**
26* create a new object from the given attribute, and add a cacheKey property to it
27*/
28export const createAttributeWithCacheKey = <T extends Record<string, unknown>>(29attribute: T,30): T & AttributeWithCacheKey => new AttributeWithCacheKeyImpl(attribute) as unknown as T & AttributeWithCacheKey;31