Skip to content

Add types package #150 - #151

Open
rymsha wants to merge 1 commit into
masterfrom
add-types-package-150
Open

Add types package #150#151
rymsha wants to merge 1 commit into
masterfrom
add-types-package-150

Conversation

@rymsha

@rymsha rymsha commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Publishes a TypeScript types package for lib-text-encoding so consumers stop hand-maintaining local /lib/text-encoding declarations (e.g. app-features currently ships its own copy). Follows the scaffolding pattern established for lib-mustache in enonic/lib-mustache#66.

Changes

  • types/index.d.ts — ambient module declaration for /lib/text-encoding covering all 32 exports (encoders, decoders, escapers, hashes, HMACs). Types authored from src/main/resources/lib/text-encoding.js and verified against the underlying Java bean handlers.
  • types/package.json@enonic-types/lib-text-encoding manifest (version substituted at build time).
  • build.gradleassembleTypes Copy task builds build/types with project.version injected; jar.dependsOn assembleTypes.
  • .github/workflows/enonic-gradle.ymlnpmPublish: true on build-and-publish + id-token: write for OIDC trusted publishing.

Exports typed (all 32)

Base64 / Base64Url / Base32 / Hex: base64Encode, base64Decode, base64UrlEncode, base64UrlDecode, base32Encode, base32Decode, hexEncode, hexDecode.
Charset: charsetDecode, charsetEncode.
Escaping: urlEscape, urlUnescape, htmlEscape, htmlUnescape, xmlEscape, xmlUnescape.
Hashes: md5, md5AsStream, sha1, sha1AsStream, sha256, sha256AsStream, sha512, sha512AsStream.
HMAC: hmacSha1AsHex, hmacSha1AsStream, hmacSha256AsHex, hmacSha256AsStream, hmacSha512AsHex, hmacSha512AsStream.
Named type: StreamInput (the union accepted by encoders/hashers/HMACs).

Corrections vs the app-features local declaration

The app-features types/text-encoding.d.ts was a starting reference only. Fixed against the actual JS + Java bean:

  1. charset parameters are optional. charsetDecode(stream, charset?) and charsetEncode(text, charset?) — the JS defaults to UTF-8 when the arg is omitted (__.nullOrValue + Java null check → StandardCharsets.UTF_8). app-features had charset: string (required).
  2. Decoders can return null on invalid input. base64Decode, base64UrlDecode, base32Decode, hexDecode return ByteSource | nullBaseEncoding.decode(...) throws IllegalArgumentException on malformed input and the Java handlers catch it and return null, which surfaces to JS as null. app-features had them as ByteSource.
  3. stream accepts number and boolean too. CommonHandler.toByteSource(...) handles String | Boolean | Number (plus ByteSource pass-through and returns empty for anything else). Exposed as a named StreamInput = ByteSource | string | number | boolean union so consumers can reference it. app-features had ByteSource | string.

Verification

  • LANG=C.utf8 LC_ALL=C.utf8 ./gradlew build — green; build/types/ contains index.d.ts + package.json with version: "3.0.0-SNAPSHOT" substituted.
  • Type-check with @enonic-types/core@8.0.0-B4 + typescript@5.7 under strict: true, moduleResolution: "Bundler": exercised every export in a positive smoke test (all 32 functions + StreamInput) plus two negative @ts-expect-error cases (passing {} to base64Encode, passing a number to charsetEncode(text: string, ...)). All expected.

Notes

Closes #150

🤖 Generated with Claude Code

Publishes @enonic-types/lib-text-encoding so consumers no longer
hand-maintain local declarations for /lib/text-encoding.

- types/index.d.ts: ambient module declaration for /lib/text-encoding,
  covering all 32 exports (encoders, decoders, escapers, hashes, HMACs)
  verified against the JS surface and the underlying Java bean handlers.
  Corrections vs the app-features local copy: charset parameters are
  optional (default UTF-8); decode functions return ByteSource | null
  (may return null on invalid input); stream accepts the full set the
  bean handles (ByteSource | string | number | boolean, exposed as a
  named StreamInput type).
- types/package.json: @enonic-types/lib-text-encoding manifest.
- build.gradle: assembleTypes Copy task -> build/types with
  project.version substituted; jar.dependsOn assembleTypes.
- workflow: npmPublish: true on build-and-publish + id-token permission
  for OIDC trusted publishing.

Closes #150

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.57%. Comparing base (cf5989f) to head (daae750).

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #151   +/-   ##
=========================================
  Coverage     96.57%   96.57%           
  Complexity       75       75           
=========================================
  Files            11       11           
  Lines           146      146           
  Branches          4        4           
=========================================
  Hits            141      141           
  Partials          5        5           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Publishes a dedicated npm TypeScript types package (@enonic-types/lib-text-encoding) so XP consumers can rely on maintained declarations for /lib/text-encoding instead of copying local .d.ts files.

Changes:

  • Added an ambient TypeScript declaration module for /lib/text-encoding, including StreamInput and all exported functions.
  • Added a types/package.json manifest for the types package.
  • Wired a Gradle assembleTypes task (with version injection) into the build and enabled CI trusted publishing (OIDC) via workflow updates.

Reviewed changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated no comments.

File Description
types/package.json Defines the npm package metadata and dependency on @enonic-types/core.
types/index.d.ts Adds ambient module typings for /lib/text-encoding (32 exports + StreamInput).
build.gradle Adds assembleTypes Copy task to produce build/types and inject project.version.
.github/workflows/enonic-gradle.yml Enables npm trusted publishing and sets required GitHub token permissions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create @enonic-types/lib-text-encoding types package

2 participants