← Back to Skills

core-type-mapping

majiayu000
Updated Yesterday
58
9
58
View on GitHub
Developmentapi

About

This skill provides mappings between OpenAPI string formats and TypeScript type classes for consistent type handling. Developers use it when creating OpenAPI specs, performing data transformations, and writing type assertions in tests. Key features include support for string conversion and clear import guidelines from specific packages.

Quick Install

Claude Code

Recommended
Plugin CommandRecommended
/plugin add https://github.com/majiayu000/claude-skill-registry
Git CloneAlternative
git clone https://github.com/majiayu000/claude-skill-registry.git ~/.claude/skills/core-type-mapping

Copy and paste this command in Claude Code to install this skill

Documentation

Core Type Mapping Guide

Overview

This guide provides the mapping between OpenAPI string formats and their corresponding TypeScript type classes for use in Tasks 5, 7, 8, and 9.

🚨 Critical Usage Rules

  • Task 5: Use these mappings when creating OpenAPI specifications - set the correct format field
  • Task 7: Use these mappings in data transformation and validation
  • Task 8 & 9: Use these mappings for type assertions in tests (e.g., instanceof Email, instanceof UUID)
  • String Conversion: All types support .toString() method and template literal interpolation
  • Import Sources: Import types from the specified packages, not from Node.js built-ins

AWS Types (@zerobias-org/types-amazon-js)

String FormatTypeScript TypeUsage Example
arnArntoEnum(Arn, value) or new Arn(value)
awsPartitionAwsPartitiontoEnum(AwsPartition, value)
awsServiceAwsServicetoEnum(AwsService, value)
awsImageIdAwsImageIdtoEnum(AwsImageId, value)
awsAccessPolicyAwsAccessPolicynew AwsAccessPolicy(value)
awsAccessPolicyStatementAwsAccessPolicyStatementnew AwsAccessPolicyStatement(value)
awsAccessPolicyStatementConditionAwsAccessPolicyStatementConditionnew AwsAccessPolicyStatementCondition(value)
awsAccessPolicyStatementEffectAwsAccessPolicyStatementEffecttoEnum(AwsAccessPolicyStatementEffect, value)
awsAccessPolicyStatementOperatorAwsAccessPolicyStatementOperatortoEnum(AwsAccessPolicyStatementOperator, value)

Microsoft Azure Types (@zerobias-org/types-microsoft-js)

String FormatTypeScript TypeUsage Example
azureVmSizeAzureVmSizetoEnum(AzureVmSize, value)
azureResourceProviderAzureResourceProvidertoEnum(AzureResourceProvider, value)
azureResourceAzureResourcenew AzureResource(value)
azureResourceInfoAzureResourceInfonew AzureResourceInfo(value)
azureResourceTypeAzureResourceTypetoEnum(AzureResourceType, value)
azureResourcePlanAzureResourcePlannew AzureResourcePlan(value)
azureResourceSkuAzureResourceSkunew AzureResourceSku(value)
azureResourceSkuTierAzureResourceSkuTiertoEnum(AzureResourceSkuTier, value)
azureResourceIdentityAzureResourceIdentitynew AzureResourceIdentity(value)
azureResourceIdentityTypeAzureResourceIdentityTypetoEnum(AzureResourceIdentityType, value)

Google Cloud Types (@zerobias-org/types-google-js)

String FormatTypeScript TypeUsage Example
gcpAccessPolicyGcpAccessPolicynew GcpAccessPolicy(value)
gcpAccessPolicyAuditConfigGcpAccessPolicyAuditConfignew GcpAccessPolicyAuditConfig(value)
gcpAccessPolicyAuditLogConfigGcpAccessPolicyAuditLogConfignew GcpAccessPolicyAuditLogConfig(value)
gcpAccessPolicyAuditLogConfigTypeGcpAccessPolicyAuditLogConfigTypetoEnum(GcpAccessPolicyAuditLogConfigType, value)
gcpAccessPolicyBindingGcpAccessPolicyBindingnew GcpAccessPolicyBinding(value)
gcpAccessPolicyBindingConditionGcpAccessPolicyBindingConditionnew GcpAccessPolicyBindingCondition(value)
gcpAccessPolicyVersionGcpAccessPolicyVersiontoEnum(GcpAccessPolicyVersion, value)

Core Types (@zerobias-org/types-core-js)

Binary/Encoding

String FormatTypeScript TypeUsage Example
byteBytenew Byte(value)
b64Bytenew Byte(value)
base64Bytenew Byte(value)

Networking

String FormatTypeScript TypeUsage Example
cidrCidrnew Cidr(value)
ipAddressIpAddressnew IpAddress(value)
ipIpAddressnew IpAddress(value)
ipv4IpAddressnew IpAddress(value)
ipv6IpAddressnew IpAddress(value)
macMacAddressnew MacAddress(value)
macaddrMacAddressnew MacAddress(value)
macAddressMacAddressnew MacAddress(value)
hostnameHostnamenew Hostname(value)

Date/Time

String FormatTypeScript TypeUsage Example
date-timeDatenew Date(value)
timeDatenew Date(value)
timestampDatenew Date(value)
dateDatenew Date(value)
durationDurationnew Duration(value)

Numeric

String FormatTypeScript TypeUsage Example
doublenumberNumber(value)
floatnumberNumber(value)
int32numberNumber(value)
int64numberNumber(value)
integernumberNumber(value)

Communication/Identity

String FormatTypeScript TypeUsage Example
emailEmailnew Email(value)
phoneNumberPhoneNumbernew PhoneNumber(value)
phonePhoneNumbernew PhoneNumber(value)
urlURLnew URL(value)
uriURLnew URL(value)

Identifiers

String FormatTypeScript TypeUsage Example
uuidUUIDnew UUID(value)
guidUUIDnew UUID(value)
objectIdObjectIdnew ObjectId(value)

Security

String FormatTypeScript TypeUsage Example
passwordstringDirect string usage
secretstringDirect string usage
tokenstringDirect string usage
apiKeystringDirect string usage

Geographic

String FormatTypeScript TypeUsage Example
latitudeLatitudenew Latitude(value)
longitudeLongitudenew Longitude(value)
geoPointGeoPointnew GeoPoint(lat, lon)
countryCountrytoEnum(Country, value)
countryCodeCountrytoEnum(Country, value)
languageLanguagetoEnum(Language, value)
languageCodeLanguagetoEnum(Language, value)
currencyCurrencytoEnum(Currency, value)
currencyCodeCurrencytoEnum(Currency, value)

File/Media

String FormatTypeScript TypeUsage Example
mimeTypeMimeTypetoEnum(MimeType, value)
fileExtensionFileExtensiontoEnum(FileExtension, value)
pathPathnew Path(value)
filePathPathnew Path(value)

Business/Domain

String FormatTypeScript TypeUsage Example
ssnSsnnew Ssn(value)
tinTinnew Tin(value)
ibanIbannew Iban(value)
creditCardCreditCardnew CreditCard(value)
postalCodePostalCodenew PostalCode(value)
zipCodePostalCodenew PostalCode(value)

Complete Type Mapping Reference Table

Consolidated Quick Reference

FormatPackageTypeConstructor Pattern
uuid@zerobias-org/types-core-jsUUIDmap(UUID, value)
email@zerobias-org/types-core-jsEmailmap(Email, value)
url@zerobias-org/types-core-jsURLmap(URL, value)
date-timeNativeDatemap(Date, value)
ipAddress@zerobias-org/types-core-jsIpAddressmap(IpAddress, value)
phoneNumber@zerobias-org/types-core-jsPhoneNumbermap(PhoneNumber, value)
arn@zerobias-org/types-amazon-jsArnmap(Arn, value)
cidr@zerobias-org/types-core-jsCidrmap(Cidr, value)
duration@zerobias-org/types-core-jsDurationmap(Duration, value)
base64@zerobias-org/types-core-jsBytemap(Byte, value)

Usage Patterns by Task

Task 5: OpenAPI Specification

# Use format field to specify type
properties:
  id:
    type: string
    format: uuid  # β†’ Will generate UUID type
  email:
    type: string
    format: email  # β†’ Will generate Email type
  createdAt:
    type: string
    format: date-time  # β†’ Will generate Date type

Task 7: Implementation (Mappers)

import { map, toEnum } from '@zerobias-org/util-hub-module-utils';
import { UUID, Email, URL } from '@zerobias-org/types-core-js';  // NEVER from Node.js!

export function toUserInfo(raw: any): UserInfo {
  return {
    id: map(UUID, raw.id),
    email: map(Email, raw.email),
    website: map(URL, raw.website_url),
    createdAt: map(Date, raw.created_at),
    status: toEnum(StatusEnum, raw.status)
  };
}

Task 8 & 9: Testing

import { UUID, Email } from '@zerobias-org/types-core-js';

it('should return user with correct types', () => {
  const user = await getUser('123');

  expect(user.id).to.be.instanceof(UUID);
  expect(user.email).to.be.instanceof(Email);
  expect(user.createdAt).to.be.instanceof(Date);
});

String Conversion Support

All custom types support string conversion:

const email = new Email('user@example.com');

// Direct toString()
const emailString = email.toString();  // "user@example.com"

// Template literal (automatic conversion)
const message = `User email: ${email}`;  // "User email: user@example.com"

// JSON serialization
JSON.stringify({ email });  // {"email":"user@example.com"}

Package Import Requirements

Required Dependencies

{
  "dependencies": {
    "@zerobias-org/types-core-js": "*",
    "@zerobias-org/util-hub-module-utils": "*"
  },
  "devDependencies": {
    "@zerobias-org/types-amazon-js": "*",  // If using AWS
    "@zerobias-org/types-microsoft-js": "*",  // If using Azure
    "@zerobias-org/types-google-js": "*"  // If using GCP
  }
}

Common Mistakes to Avoid

❌ WRONG - Using Node.js built-ins

import { URL } from 'url';  // WRONG!
import { URL } from 'node:url';  // WRONG!

βœ… CORRECT - Using core types

import { URL } from '@zerobias-org/types-core-js';  // CORRECT!

❌ WRONG - Direct enum instantiation

const status = new StatusEnum('active');  // WRONG - constructor is private!

βœ… CORRECT - Using toEnum

const status = toEnum(StatusEnum, 'active');  // CORRECT!

❌ WRONG - Manual type conversion

const uuid = raw.id as UUID;  // WRONG - no validation!

βœ… CORRECT - Using map function

const uuid = map(UUID, raw.id);  // CORRECT - validates and converts!

Priority Rules

  1. Always use core types over native JavaScript types when available
  2. Import from correct package - never from Node.js built-ins
  3. Use map() for type conversion - provides validation
  4. Use toEnum() for enums - never instantiate directly
  5. All types support .toString() - use for string conversion
String FormatTypeScript TypeUsage Example
emailEmailnew Email(value)
phoneNumberPhoneNumbernew PhoneNumber(value)
phonePhoneNumbernew PhoneNumber(value)

Web/Protocol

String FormatTypeScript TypeUsage Example
urlURLnew URL(value)
uriURLnew URL(value)
uuidUUIDnew UUID(value)
mimeTypeMimeTypenew MimeType(value)

Versioning

String FormatTypeScript TypeUsage Example
semverSemvernew Semver(value)
versionRangeVersionRangenew VersionRange(value)

Misc

String FormatTypeScript TypeUsage Example
nmtokenNmtokennew Nmtoken(value)
passwordstringString(value)

Usage Patterns

Task 5: OpenAPI Specification

properties:
  email_address:
    type: string
    format: email  # Maps to Email type
  website_url:
    type: string
    format: url    # Maps to URL type
  user_id:
    type: string
    format: uuid   # Maps to UUID type

Task 7: Data Transformation

import { Email, URL, UUID } from '@zerobias-org/types-core-js';
import { map } from '@zerobias-org/util-hub-module-utils';

function mapUser(raw: any): User {
  return {
    id: map(UUID, raw.user_id),
    email: map(Email, raw.email_address),
    website: map(URL, raw.website_url)
  };
}

Task 8 & 9: Test Assertions

import { Email, URL, UUID } from '@zerobias-org/types-core-js';

// Test assertions
expect(user.id).to.be.instanceof(UUID);
expect(user.email).to.be.instanceof(Email);
expect(user.website).to.be.instanceof(URL);

String Conversion Examples

// All types support toString() and template literals
const email = new Email('user@example.com');
const emailString = email.toString();
const message = `User email: ${email}`;

const uuid = new UUID('123e4567-e89b-12d3-a456-426614174000');
const uuidString = uuid.toString();
const log = `Processing user ${uuid}`;

Package Import Requirements

🚨 CRITICAL: Always import from the specified packages:

// Core types - ALWAYS import from @zerobias-org/types-core-js
import { URL, UUID, Email, IpAddress } from '@zerobias-org/types-core-js';

// AWS types
import { Arn, AwsService } from '@zerobias-org/types-amazon-js';

// Azure types  
import { AzureVmSize, AzureResource } from '@zerobias-org/types-microsoft-js';

// Google Cloud types
import { GcpAccessPolicy } from '@zerobias-org/types-google-js';

// NEVER import URL from Node.js built-ins
// ❌ import { URL } from 'url';  // WRONG
// βœ… import { URL } from '@zerobias-org/types-core-js';  // CORRECT

Validation and Error Handling

All typed values can be validated and will throw appropriate errors for invalid formats:

try {
  const email = new Email('invalid-email');  // Throws validation error
} catch (error) {
  // Handle validation error
}

// Safe validation with try-catch in mappers
function safeMapEmail(raw: string): Email | null {
  try {
    return new Email(raw);
  } catch {
    return null;  // Or handle as appropriate for your use case
  }
}

GitHub Repository

majiayu000/claude-skill-registry
Path: skills/core-type-mapping

Related Skills

creating-opencode-plugins

Meta

This skill provides the structure and API specifications for creating OpenCode plugins that hook into 25+ event types like commands, files, and LSP operations. It offers implementation patterns for JavaScript/TypeScript modules that intercept and extend the AI assistant's lifecycle. Use it when you need to build event-driven plugins for monitoring, custom handling, or extending OpenCode's capabilities.

View skill

evaluating-llms-harness

Testing

This Claude Skill runs the lm-evaluation-harness to benchmark LLMs across 60+ standardized academic tasks like MMLU and GSM8K. It's designed for developers to compare model quality, track training progress, or report academic results. The tool supports various backends including HuggingFace and vLLM models.

View skill

langchain

Meta

LangChain is a framework for building LLM applications using agents, chains, and RAG pipelines. It supports multiple LLM providers, offers 500+ integrations, and includes features like tool calling and memory management. Use it for rapid prototyping and deploying production systems like chatbots, autonomous agents, and question-answering services.

View skill

cloudflare-turnstile

Meta

This skill provides comprehensive guidance for implementing Cloudflare Turnstile as a CAPTCHA-alternative bot protection system. It covers integration for forms, login pages, API endpoints, and frameworks like React/Next.js/Hono, while handling invisible challenges that maintain user experience. Use it when migrating from reCAPTCHA, debugging error codes, or implementing token validation and E2E tests.

View skill