This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
@kopexa/krn is the TypeScript implementation of Kopexa Resource Names (KRN), following Google's Resource Name Design. This package is a port of the Go package at github.com/kopexa-grc/krn.
The Go package is the source of truth - any changes should be made there first, then ported here.
KRN Format:
//kopexa.com/{collection}/{resource-id}[/{collection}/{resource-id}][@{version}]
//{service}.kopexa.com/{collection}/{resource-id}[/{collection}/{resource-id}][@{version}]
Examples:
//kopexa.com/frameworks/iso27001- Simple KRN without service//catalog.kopexa.com/frameworks/iso27001/controls/5.1.1- With service and dot-notation control ID//isms.kopexa.com/tenants/acme-corp/workspaces/main@v1- With service and version
# Install dependencies
pnpm install
# Run all tests
pnpm test
# Run tests with coverage
pnpm test:coverage
# Run tests in watch mode
pnpm test:watch
# Build the package
pnpm build
# Lint
pnpm lint
# Fix linting issues
pnpm lint:fix
# Type check
pnpm typecheckSingle-file TypeScript library with zero runtime dependencies:
src/index.ts- Core implementation: KRN class, parse/tryParse, builder pattern, validationsrc/index.test.ts- Comprehensive tests including Go compatibility suite
KRN- The main class representing a Kopexa Resource NameSegment- A collection/resource-id pair interfaceKRNBuilder- Fluent API for constructing KRNsKRNError- Custom error class with error codesKRNErrorCode- Error code constants (matching Go package)
These error codes must be kept in sync with the Go package:
EMPTY_KRN→ Go:ErrEmptyKRNINVALID_KRN→ Go:ErrInvalidKRNINVALID_DOMAIN→ Go:ErrInvalidDomainINVALID_RESOURCE_ID→ Go:ErrInvalidResourceIDINVALID_VERSION→ Go:ErrInvalidVersionRESOURCE_NOT_FOUND→ Go:ErrResourceNotFound
Note: Invalid service names use INVALID_DOMAIN, not a separate error code (for Go compatibility).
- 90% test coverage enforced in CI (currently at 97%)
- All tests must pass
- No Biome linting errors
- Go compatibility tests must pass
The test file includes a "Go Compatibility" test suite that verifies:
- All parse test cases from Go pass
- Error codes match Go exactly
- Service preservation behavior matches Go
- String round-trip works identically
When updating this package, run the Go tests too to ensure parity:
cd ../krn && go test ./...Uses Google Release Please for automated releases. Push conventional commits to main:
feat:- New features (minor version bump)fix:- Bug fixes (patch version bump)chore:,docs:,test:- No version bump
Release Please creates PRs that, when merged, trigger npm publish with provenance.
Published to npm as @kopexa/krn with:
- Dual ESM/CJS builds
- TypeScript declarations
- npm provenance for supply chain security