Skip to content

Commit

Permalink
feat: add 'as const' for object to keep the type checking ability of …
Browse files Browse the repository at this point in the history
…enmu
  • Loading branch information
echoontheway committed Oct 14, 2021
1 parent 6ad2796 commit 8ae581c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ export const CloudProviderValues = {
AZURE: 'azure',
/** Google Cloud Platform. */
GCP: 'gcp',
}
} as const
export type CloudProviderValues = typeof CloudProviderValues[keyof typeof CloudProviderValues]



Expand Down Expand Up @@ -526,7 +527,8 @@ export const CloudPlatformValues = {
GCP_CLOUD_FUNCTIONS: 'gcp_cloud_functions',
/** Google Cloud App Engine (GAE). */
GCP_APP_ENGINE: 'gcp_app_engine',
}
} as const
export type CloudPlatformValues = typeof CloudPlatformValues[keyof typeof CloudPlatformValues]



Expand All @@ -536,7 +538,8 @@ export const AwsEcsLaunchtypeValues = {
EC2: 'ec2',
/** fargate. */
FARGATE: 'fargate',
}
} as const
export type AwsEcsLaunchtypeValues = typeof AwsEcsLaunchtypeValues[keyof typeof AwsEcsLaunchtypeValues]



Expand All @@ -556,7 +559,8 @@ export const HostArchValues = {
PPC64: 'ppc64',
/** 32-bit x86. */
X86: 'x86',
}
} as const
export type HostArchValues = typeof HostArchValues[keyof typeof HostArchValues]



Expand Down Expand Up @@ -584,7 +588,8 @@ export const OsTypeValues = {
SOLARIS: 'solaris',
/** IBM z/OS. */
Z_OS: 'z_os',
}
} as const
export type OsTypeValues = typeof OsTypeValues[keyof typeof OsTypeValues]



Expand All @@ -610,5 +615,6 @@ export const TelemetrySdkLanguageValues = {
RUBY: 'ruby',
/** webjs. */
WEBJS: 'webjs',
}
} as const
export type TelemetrySdkLanguageValues = typeof TelemetrySdkLanguageValues[keyof typeof TelemetrySdkLanguageValues]

Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,8 @@ export const DbSystemValues = {
MEMCACHED: 'memcached',
/** CockroachDB. */
COCKROACHDB: 'cockroachdb',
}
} as const
export type DbSystemValues = typeof DbSystemValues[keyof typeof DbSystemValues]



Expand Down Expand Up @@ -847,7 +848,8 @@ export const DbCassandraConsistencyLevelValues = {
SERIAL: 'serial',
/** local_serial. */
LOCAL_SERIAL: 'local_serial',
}
} as const
export type DbCassandraConsistencyLevelValues = typeof DbCassandraConsistencyLevelValues[keyof typeof DbCassandraConsistencyLevelValues]



Expand All @@ -863,7 +865,8 @@ export const FaasTriggerValues = {
TIMER: 'timer',
/** If none of the others apply. */
OTHER: 'other',
}
} as const
export type FaasTriggerValues = typeof FaasTriggerValues[keyof typeof FaasTriggerValues]



Expand All @@ -875,7 +878,8 @@ export const FaasDocumentOperationValues = {
EDIT: 'edit',
/** When an object is deleted. */
DELETE: 'delete',
}
} as const
export type FaasDocumentOperationValues = typeof FaasDocumentOperationValues[keyof typeof FaasDocumentOperationValues]



Expand All @@ -889,7 +893,8 @@ export const FaasInvokedProviderValues = {
AZURE: 'azure',
/** Google Cloud Platform. */
GCP: 'gcp',
}
} as const
export type FaasInvokedProviderValues = typeof FaasInvokedProviderValues[keyof typeof FaasInvokedProviderValues]



Expand All @@ -909,7 +914,8 @@ export const NetTransportValues = {
INPROC: 'inproc',
/** Something else (non IP-based). */
OTHER: 'other',
}
} as const
export type NetTransportValues = typeof NetTransportValues[keyof typeof NetTransportValues]



Expand All @@ -925,7 +931,8 @@ export const NetHostConnectionTypeValues = {
UNAVAILABLE: 'unavailable',
/** unknown. */
UNKNOWN: 'unknown',
}
} as const
export type NetHostConnectionTypeValues = typeof NetHostConnectionTypeValues[keyof typeof NetHostConnectionTypeValues]



Expand Down Expand Up @@ -973,7 +980,8 @@ export const NetHostConnectionSubtypeValues = {
NRNSA: 'nrnsa',
/** LTE CA. */
LTE_CA: 'lte_ca',
}
} as const
export type NetHostConnectionSubtypeValues = typeof NetHostConnectionSubtypeValues[keyof typeof NetHostConnectionSubtypeValues]



Expand All @@ -989,7 +997,8 @@ export const HttpFlavorValues = {
SPDY: 'SPDY',
/** QUIC protocol. */
QUIC: 'QUIC',
}
} as const
export type HttpFlavorValues = typeof HttpFlavorValues[keyof typeof HttpFlavorValues]



Expand All @@ -999,7 +1008,8 @@ export const MessagingDestinationKindValues = {
QUEUE: 'queue',
/** A message sent to a topic. */
TOPIC: 'topic',
}
} as const
export type MessagingDestinationKindValues = typeof MessagingDestinationKindValues[keyof typeof MessagingDestinationKindValues]



Expand All @@ -1009,7 +1019,8 @@ export const MessagingOperationValues = {
RECEIVE: 'receive',
/** process. */
PROCESS: 'process',
}
} as const
export type MessagingOperationValues = typeof MessagingOperationValues[keyof typeof MessagingOperationValues]



Expand Down Expand Up @@ -1049,7 +1060,8 @@ export const RpcGrpcStatusCodeValues = {
DATA_LOSS: 15,
/** UNAUTHENTICATED. */
UNAUTHENTICATED: 16,
}
} as const
export type RpcGrpcStatusCodeValues = typeof RpcGrpcStatusCodeValues[keyof typeof RpcGrpcStatusCodeValues]



Expand All @@ -1059,5 +1071,6 @@ export const MessageTypeValues = {
SENT: 'SENT',
/** received. */
RECEIVED: 'RECEIVED',
}
} as const
export type MessageTypeValues = typeof MessageTypeValues[keyof typeof MessageTypeValues]

3 changes: 2 additions & 1 deletion scripts/semconv/templates/SemanticAttributes.ts.j2
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export const {{class_name}} = {
/** {% filter escape %}{{member.brief | to_doc_brief}}.{% endfilter %} */
{{ member.member_id | to_const_name }}: {{ print_value(type, member.value) }},
{%- endfor %}
}
} as const
export type {{class_name}} = typeof {{class_name}}[keyof typeof {{class_name}}]
{% endif %}
{% endif %}

Expand Down

0 comments on commit 8ae581c

Please sign in to comment.