HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/dev/nowruzgan/admin/node_modules/safevalues/internals/attribute_impl.mjs
/**
 * @license
 * SPDX-License-Identifier: Apache-2.0
 */
import '../environment/dev';
import { ensureTokenIsValid, secretToken } from './secrets';
/** A prefix with which an attribute is safe to set using plain strings. */
export class SafeAttributePrefix {
    // @ts-ignore: error TS6133: 'brand' is declared but its value is never read.
    brand; // To prevent structural typing.
}
/** Implementation for `SafeAttributePrefix` */
class AttributePrefixImpl extends SafeAttributePrefix {
    privateDoNotAccessOrElseWrappedAttrPrefix;
    constructor(attrPrefix, token) {
        super();
        if (process.env.NODE_ENV !== 'production') {
            ensureTokenIsValid(token);
        }
        this.privateDoNotAccessOrElseWrappedAttrPrefix = attrPrefix;
    }
    toString() {
        return this.privateDoNotAccessOrElseWrappedAttrPrefix;
    }
}
/**
 * Builds a new `SafeAttribute` from the given string, without enforcing
 * safety guarantees. This shouldn't be exposed to application developers, and
 * must only be used as a step towards safe builders or safe constants.
 */
export function createAttributePrefix(attrPrefix) {
    return new AttributePrefixImpl(attrPrefix, secretToken);
}
/**
 * Returns the string value of the passed `SafeAttributePrefix` object while
 * ensuring it has the correct type.
 */
export function unwrapAttributePrefix(value) {
    if (value instanceof AttributePrefixImpl) {
        return value.privateDoNotAccessOrElseWrappedAttrPrefix;
    }
    else {
        let message = '';
        if (process.env.NODE_ENV !== 'production') {
            message = 'Unexpected type when unwrapping SafeAttributePrefix';
        }
        throw new Error(message);
    }
}