Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/fix-exports-minor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@aokiapp/tlv": minor
---

Expand public API: expose parser schema types to consumers.

Changes:
- Add public exports for parser schema types to support direct typing in user code.
- Update tests to use package-level path aliases resolved by Vite plugin and tests/tsconfig.json.
- Enhance test runner script to compile declarations for tests before running Vitest.
- Update Vitest config for path alias resolution and coverage improvements; remove 'dist' from coverage exclude.

No runtime behavior changes; semver-minor due to expanded public API surface.
53 changes: 51 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"typecheck": "tsc --noEmit",
"lint": "eslint .",
"format": "prettier --write .",
"test": "vitest run",
"test": "tsc -p tests/tsconfig.json --emitDeclarationOnly && vitest run",
"prepack": "npm run build",
"changelog": "changeset",
"version": "changeset version",
Expand Down Expand Up @@ -69,6 +69,7 @@
"rimraf": "^5.0.5",
"typescript": "^5.8.3",
"typescript-eslint": "^8.29.0",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^3.1.1"
}
}
}
10 changes: 5 additions & 5 deletions src/parser/schema-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type OptionalFlag<O extends SchemaOptions | undefined> = {
/**
* Base interface for a TLV schema object.
*/
interface TLVSchemaBase<N extends string = string> {
export interface TLVSchemaBase<N extends string = string> {
readonly name: N;
readonly tagClass: TagClass;
readonly tagNumber: number;
Expand All @@ -31,7 +31,7 @@ interface TLVSchemaBase<N extends string = string> {
* Interface for defining a primitive TLV schema.
* @template DecodedType - The type after decoding.
*/
interface PrimitiveTLVSchema<
export interface PrimitiveTLVSchema<
N extends string = string,
DecodedType = DefaultDecodeType,
> extends TLVSchemaBase<N> {
Expand All @@ -46,7 +46,7 @@ interface PrimitiveTLVSchema<
* Interface for defining a constructed TLV schema.
* @template F - The array of child field schemas.
*/
interface ConstructedTLVSchema<
export interface ConstructedTLVSchema<
N extends string = string,
F extends readonly TLVSchema[] = readonly TLVSchema[],
> extends TLVSchemaBase<N> {
Expand All @@ -55,14 +55,14 @@ interface ConstructedTLVSchema<
}

// Describes a repeated TLV schema entry (e.g. SET/SEQUENCE OF).
interface RepeatedTLVSchema<
export interface RepeatedTLVSchema<
N extends string = string,
Item extends TLVSchema = TLVSchema,
> extends TLVSchemaBase<N> {
readonly item: Item;
}

type TLVSchema<N extends string = string, D = unknown> =
export type TLVSchema<N extends string = string, D = unknown> =
| PrimitiveTLVSchema<N, D>
| ConstructedTLVSchema<N, readonly TLVSchema[]>
| RepeatedTLVSchema<N, TLVSchema>;
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Schema, TagClass } from "../../src/parser";
import { Schema, TagClass } from "@aokiapp/tlv/parser";
import { decodeOffsets, decodePublicKey, decodeText } from "../helpers/utils";

export const schemaCertificate = Schema.constructed(
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BasicTLVParser } from "../../src/parser";
import { BasicTLVParser } from "@aokiapp/tlv/parser";

function arrayBufferToBase64url(buffer: ArrayBuffer): string {
if (typeof Buffer !== "undefined") {
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/schema/roundtrip.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// tests/integration/schema/roundtrip.test.ts
import { describe, it } from "vitest";
import assert from "assert";
import { Schema as BSchema, SchemaBuilder } from "../../../src/builder";
import { Schema as PSchema, SchemaParser } from "../../../src/parser";
import { TagClass } from "../../../src/common/types";
import { toHex } from "../../../src/common/codecs";
import { Schema as BSchema, SchemaBuilder } from "@aokiapp/tlv/builder";
import { Schema as PSchema, SchemaParser } from "@aokiapp/tlv/parser";
import { TagClass } from "@aokiapp/tlv/common";
import { toHex } from "@aokiapp/tlv/common";
import { fromHexString } from "../../helpers/utils";

describe("Integration: constructed build→parse round-trip preserves data shape", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Schema, TagClass } from "../src/parser";
import { Schema, TagClass } from "@aokiapp/tlv/parser";
import { decodeOffsets, decodePublicKey, decodeText } from "./utils";

export const schemaCertificate = Schema.constructed(
Expand Down
19 changes: 19 additions & 0 deletions tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "esnext",
"moduleResolution": "bundler",
"declaration": true,
"noEmit": true,
"strict": false,
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"@aokiapp/tlv": ["../src/index.ts"],
"@aokiapp/tlv/parser": ["../src/parser/index.ts"],
"@aokiapp/tlv/builder": ["../src/builder/index.ts"],
"@aokiapp/tlv/common": ["../src/common/index.ts"]
}
},
"include": ["**/*.ts"]
}
2 changes: 1 addition & 1 deletion tests/types/build.types.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tests/types/build.types.test.ts
import { describe, it } from "vitest";
import { Schema as BSchema, SchemaBuilder } from "../../src/builder";
import { Schema as BSchema, SchemaBuilder } from "@aokiapp/tlv/builder";
import { AssertTypeCompatible, assertTypeTrue } from "../helpers/utils";

describe("build-only type test (single large constructed schema)", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/types/parse.types.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tests/types/parse.types.test.ts
import { describe, it } from "vitest";
import { Schema as PSchema, SchemaParser } from "../../src/parser";
import { Schema as PSchema, SchemaParser } from "@aokiapp/tlv/parser";
import { AssertTypeCompatible, assertTypeTrue } from "../helpers/utils";

describe("parse-only type test (single large constructed schema)", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/common/codecs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
decodeOID,
decodeBitStringHex,
encodeBitString,
} from "../../../src/common/codecs";
} from "@aokiapp/tlv/common";

describe("codecs: buffer and hex helpers", () => {
it("bufferToArrayBuffer converts Buffer to ArrayBuffer", () => {
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/schema/builder.core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
Schema as BSchema,
SchemaBuilder,
BasicTLVBuilder,
} from "../../../src/builder";
import { TagClass } from "../../../src/common/types";
import { identity, toHex } from "../../../src/common/codecs";
} from "@aokiapp/tlv/builder";
import { TagClass } from "@aokiapp/tlv/common";
import { identity, toHex } from "@aokiapp/tlv/common";

function toHexBuf(buf: ArrayBuffer): string {
return toHex(new Uint8Array(buf));
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/schema/parser.additional-coverage.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// tests/unit/schema/parser.additional-coverage.test.ts
import { describe, it, expect } from "vitest";
import assert from "assert";
import { Schema as PSchema, SchemaParser } from "../../../src/parser";
import { Schema as PSchema, SchemaParser } from "@aokiapp/tlv/parser";
import { fromHexString } from "../../helpers/utils";
import { identity } from "../../../src/common";
import { identity } from "@aokiapp/tlv/common";

describe("SEQUENCE: tail optional skip when content ends", () => {
it("skips trailing optional field at end-of-content", () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/schema/parser.sequence-set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
Schema as PSchema,
SchemaParser,
BasicTLVParser,
} from "../../../src/parser";
import { TagClass } from "../../../src/common/types";
} from "@aokiapp/tlv/parser";
import { TagClass } from "@aokiapp/tlv/common";
import { fromHexString } from "../../helpers/utils";

describe("SchemaParser primitive: trailing bytes strict gating", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/tlv/basic-tlv.length-exceed.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tests/unit/tlv/basic-tlv.length-exceed.test.ts
import { describe, it } from "vitest";
import assert from "assert";
import { BasicTLVParser } from "../../../src/parser";
import { BasicTLVParser } from "@aokiapp/tlv/parser";
import { fromHexString } from "../../helpers/utils";

describe("BasicTLVParser.readValue: declared length exceeds available bytes", () => {
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/tlv/basic-tlv.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// tests/unit/tlv/basic-tlv.test.ts
import { describe, it } from "vitest";
import assert from "assert";
import { BasicTLVParser } from "../../../src/parser";
import { TagClass } from "../../../src/common/types";
import { BasicTLVBuilder } from "../../../src/builder";
import { toHex } from "../../../src/common/codecs";
import { BasicTLVParser } from "@aokiapp/tlv/parser";
import { TagClass } from "@aokiapp/tlv/common";
import { BasicTLVBuilder } from "@aokiapp/tlv/builder";
import { toHex } from "@aokiapp/tlv/common";
import { fromHexString } from "../../helpers/utils";

describe("BasicTLVParser: length and tag-number forms", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BasicTLVParser } from "../src/parser";
import { BasicTLVParser } from "@aokiapp/tlv/parser";

function arrayBufferToBase64url(buffer: ArrayBuffer): string {
if (typeof Buffer !== "undefined") {
Expand Down
19 changes: 18 additions & 1 deletion vitest.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
import { defineConfig } from "vitest/config";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
// Resolve @aokiapp/tlv/* via tests/tsconfig.json without changing test imports
plugins: [
tsconfigPaths({
projects: ["./tests/tsconfig.json"],
}),
],
test: {
globals: true,
environment: "node",
include: ["tests/**/*.test.ts"],
exclude: ["tests/_migrated/**"],
// Inline the package entrypoints so Vite transforms & instruments source for coverage
server: {
deps: {
inline: [
"@aokiapp/tlv",
"@aokiapp/tlv/parser",
"@aokiapp/tlv/builder",
"@aokiapp/tlv/common",
],
},
},
coverage: {
enabled: true,
provider: "istanbul",
Expand All @@ -14,7 +32,6 @@ export default defineConfig({
exclude: [
"tests/**",
"examples/**",
"dist/**",
".changeset/**",
"**/*.d.ts",
],
Expand Down
Loading