UNPKG

@temporalio/common

Version:

Common library for code that's used across the Client, Worker, and/or Workflow

40 lines 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ENHANCED_STACK_TRACE_QUERY_NAME = exports.STACK_TRACE_QUERY_NAME = exports.TEMPORAL_RESERVED_PREFIX = void 0; exports.throwIfReservedName = throwIfReservedName; exports.TEMPORAL_RESERVED_PREFIX = '__temporal_'; exports.STACK_TRACE_QUERY_NAME = '__stack_trace'; exports.ENHANCED_STACK_TRACE_QUERY_NAME = '__enhanced_stack_trace'; /** * Wire identifiers used by first-party SDK contrib packages. Each entry pairs * a name with the entity type it's allowed to register as; that pair bypasses * the {@link TEMPORAL_RESERVED_PREFIX} check at registration time. Registering * the same name as a different entity type is still rejected. */ const INTERNAL_RESERVED_NAME_ALLOWLIST = new Map([ // @temporalio/workflow-streams ['__temporal_workflow_stream_publish', 'signal'], ['__temporal_workflow_stream_poll', 'update'], ['__temporal_workflow_stream_offset', 'query'], // @temporalio/openai-agents ['__temporal_openai_agents_tracing', 'sink'], // @temporalio/langsmith ['__temporal_langsmith', 'sink'], ]); /** * Validates if the provided name contains any reserved prefixes or matches any reserved names. * Throws a TypeError if validation fails, with a specific message indicating whether the issue * is with a reserved prefix or an exact match to a reserved name. * * @param type The entity type being checked * @param name The name to check against reserved prefixes/names */ function throwIfReservedName(type, name) { if (name.startsWith(exports.TEMPORAL_RESERVED_PREFIX) && INTERNAL_RESERVED_NAME_ALLOWLIST.get(name) !== type) { throw new TypeError(`Cannot use ${type} name: '${name}', with reserved prefix: '${exports.TEMPORAL_RESERVED_PREFIX}'`); } if (name === exports.STACK_TRACE_QUERY_NAME || name === exports.ENHANCED_STACK_TRACE_QUERY_NAME) { throw new TypeError(`Cannot use ${type} name: '${name}', which is a reserved name`); } } //# sourceMappingURL=reserved.js.map