Add types package #150 - #151
Open
rymsha wants to merge 1 commit into
Open
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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, includingStreamInputand all exported functions. - Added a
types/package.jsonmanifest for the types package. - Wired a Gradle
assembleTypestask (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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Publishes a TypeScript types package for lib-text-encoding so consumers stop hand-maintaining local
/lib/text-encodingdeclarations (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-encodingcovering all 32 exports (encoders, decoders, escapers, hashes, HMACs). Types authored fromsrc/main/resources/lib/text-encoding.jsand verified against the underlying Java bean handlers.types/package.json—@enonic-types/lib-text-encodingmanifest (version substituted at build time).build.gradle—assembleTypesCopy task buildsbuild/typeswithproject.versioninjected;jar.dependsOn assembleTypes..github/workflows/enonic-gradle.yml—npmPublish: trueon build-and-publish +id-token: writefor 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.tswas a starting reference only. Fixed against the actual JS + Java bean:charsetparameters are optional.charsetDecode(stream, charset?)andcharsetEncode(text, charset?)— the JS defaults toUTF-8when the arg is omitted (__.nullOrValue+ Java null check →StandardCharsets.UTF_8). app-features hadcharset: string(required).nullon invalid input.base64Decode,base64UrlDecode,base32Decode,hexDecodereturnByteSource | null—BaseEncoding.decode(...)throwsIllegalArgumentExceptionon malformed input and the Java handlers catch it and return null, which surfaces to JS as null. app-features had them asByteSource.streamaccepts number and boolean too.CommonHandler.toByteSource(...)handlesString | Boolean | Number(plusByteSourcepass-through and returns empty for anything else). Exposed as a namedStreamInput = ByteSource | string | number | booleanunion so consumers can reference it. app-features hadByteSource | string.Verification
LANG=C.utf8 LC_ALL=C.utf8 ./gradlew build— green;build/types/containsindex.d.ts+package.jsonwithversion: "3.0.0-SNAPSHOT"substituted.@enonic-types/core@8.0.0-B4+typescript@5.7understrict: true,moduleResolution: "Bundler": exercised every export in a positive smoke test (all 32 functions +StreamInput) plus two negative@ts-expect-errorcases (passing{}tobase64Encode, passing a number tocharsetEncode(text: string, ...)). All expected.Notes
@enonic-types/lib-text-encodingwill need npm trusted-publisher / package access configured org-side (same as lib-mustache).npmPublish) — merged.Closes #150
🤖 Generated with Claude Code