From 776b0e4c7c425768e3d686b7424d691b44bc365a Mon Sep 17 00:00:00 2001 From: ZeRiix Date: Mon, 8 Jun 2026 22:49:44 +0200 Subject: [PATCH 1/2] fix(08): recursive type input --- .../toDataParser/__snapshots__/recursive.gen.ts | 6 +++--- scripts/toDataParser/printer.ts | 5 ++++- tests/toDataParser/__snapshots__/render.test.ts.snap | 10 +++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/integration/toDataParser/__snapshots__/recursive.gen.ts b/integration/toDataParser/__snapshots__/recursive.gen.ts index 8d072f4..52c923a 100644 --- a/integration/toDataParser/__snapshots__/recursive.gen.ts +++ b/integration/toDataParser/__snapshots__/recursive.gen.ts @@ -23,14 +23,14 @@ export type RecursiveType4 = { export type $recursive0DataParser = RecursiveType4; -export const recursive1DataParser: DP.DataParser<$recursive1DataParser> = DP.object({ +export const recursive1DataParser: DP.DataParser<$recursive1DataParser, unknown> = DP.object({ id: DP.string(), replies: DP.array(DP.lazy(() => recursive1DataParser)) }); -export const recursive2DataParser: DP.DataParser<$recursive2DataParser> = DP.tuple([DP.string(), DP.array(DP.lazy(() => recursive2DataParser))]); +export const recursive2DataParser: DP.DataParser<$recursive2DataParser, unknown> = DP.tuple([DP.string(), DP.array(DP.lazy(() => recursive2DataParser))]); -export const recursive0DataParser: DP.DataParser<$recursive0DataParser> = DP.object({ +export const recursive0DataParser: DP.DataParser<$recursive0DataParser, unknown> = DP.object({ name: DP.string(), children: DP.array(DP.lazy(() => recursive0DataParser)), comment: DP.lazy(() => recursive1DataParser), diff --git a/scripts/toDataParser/printer.ts b/scripts/toDataParser/printer.ts index 22f492e..2b277fe 100644 --- a/scripts/toDataParser/printer.ts +++ b/scripts/toDataParser/printer.ts @@ -25,7 +25,10 @@ export function printer(params: BuildedContext) { factory.createIdentifier(params.importMode === "extended" ? "DPE" : "DP"), factory.createIdentifier(params.importMode === "extended" ? "DataParserExtended" : "DataParser"), ), - [factory.createTypeReferenceNode(contextValue.typeIdentifier)], + [ + factory.createTypeReferenceNode(contextValue.typeIdentifier), + factory.createKeywordTypeNode(SyntaxKind.UnknownKeyword), + ], ) : undefined, contextValue.expression, diff --git a/tests/toDataParser/__snapshots__/render.test.ts.snap b/tests/toDataParser/__snapshots__/render.test.ts.snap index 0f4ea32..fc220ff 100644 --- a/tests/toDataParser/__snapshots__/render.test.ts.snap +++ b/tests/toDataParser/__snapshots__/render.test.ts.snap @@ -9,7 +9,7 @@ export type RecursiveType0 = { export type $recursive0DataParser = RecursiveType0; -export const recursive0DataParser: DP.DataParser<$recursive0DataParser> = DP.object({ +export const recursive0DataParser: DP.DataParser<$recursive0DataParser, unknown> = DP.object({ next: DP.lazy(() => recursive0DataParser) }); @@ -81,20 +81,20 @@ export type $recursive2DataParser = RecursiveType2; export type $recursive0DataParser = RecursiveType1; -export const recursive1DataParser: DP.DataParser<$recursive1DataParser> = DP.array(DP.union([ +export const recursive1DataParser: DP.DataParser<$recursive1DataParser, unknown> = DP.array(DP.union([ DP.string(), DP.lazy(() => recursive1DataParser), DP.lazy(() => recursive0DataParser) ])); -export const recursive3DataParser: DP.DataParser<$recursive3DataParser> = DP.union([ +export const recursive3DataParser: DP.DataParser<$recursive3DataParser, unknown> = DP.union([ DP.string(), DP.lazy(() => recursive0DataParser), DP.lazy(() => recursive2DataParser), DP.array(DP.lazy(() => recursive3DataParser)) ]); -export const recursive2DataParser: DP.DataParser<$recursive2DataParser> = DP.tuple([ +export const recursive2DataParser: DP.DataParser<$recursive2DataParser, unknown> = DP.tuple([ DP.string(), DP.lazy(() => recursive0DataParser), DP.array(DP.union([ @@ -104,7 +104,7 @@ export const recursive2DataParser: DP.DataParser<$recursive2DataParser> = DP.tup ])) ]); -export const recursive0DataParser: DP.DataParser<$recursive0DataParser> = DP.object({ +export const recursive0DataParser: DP.DataParser<$recursive0DataParser, unknown> = DP.object({ recursiveProp: DP.object({ self: DP.lazy(() => recursive0DataParser), array: recursive1DataParser, From be11982ed38675aa511cd00aa1eea291e1f73692 Mon Sep 17 00:00:00 2001 From: ZeRiix Date: Mon, 8 Jun 2026 23:11:57 +0200 Subject: [PATCH 2/2] fix(08): export TS lib --- integration/typescript/index.test.ts | 12 ++++++++++++ package.json | 5 +++++ scripts/index.ts | 2 ++ scripts/typescript/index.ts | 4 ++++ tests/typescript/export.test.ts | 8 ++++++++ tsconfig.build.json | 9 ++++++++- 6 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 integration/typescript/index.test.ts create mode 100644 scripts/typescript/index.ts create mode 100644 tests/typescript/export.test.ts diff --git a/integration/typescript/index.test.ts b/integration/typescript/index.test.ts new file mode 100644 index 0000000..ef7226b --- /dev/null +++ b/integration/typescript/index.test.ts @@ -0,0 +1,12 @@ +import { Typescript } from "@duplojs/data-parser-tools/typescript"; +import * as ts from "typescript"; + +describe("typescript integration", () => { + it("exports the TypeScript package namespace from the built subpath", () => { + const identifier = Typescript.factory.createIdentifier("value"); + + expect(Typescript).toBe(ts); + expect(identifier.kind).toBe(ts.SyntaxKind.Identifier); + expect(identifier.text).toBe("value"); + }); +}); diff --git a/package.json b/package.json index 48354e1..ed40fd5 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,11 @@ "import": "./dist/finder/index.mjs", "require": "./dist/finder/index.cjs", "types": "./dist/finder/index.d.ts" + }, + "./typescript": { + "import": "./dist/typescript/index.mjs", + "require": "./dist/typescript/index.cjs", + "types": "./dist/typescript/index.d.ts" } }, "files": [ diff --git a/scripts/index.ts b/scripts/index.ts index 94b8ca6..052e7a7 100644 --- a/scripts/index.ts +++ b/scripts/index.ts @@ -4,3 +4,5 @@ export * as DataParserToDataParser from "./toDataParser"; export * as DataParserFinder from "./finder"; export * from "./utils"; + +export * from "./typescript"; diff --git a/scripts/typescript/index.ts b/scripts/typescript/index.ts new file mode 100644 index 0000000..ef77286 --- /dev/null +++ b/scripts/typescript/index.ts @@ -0,0 +1,4 @@ +import * as Typescript from "typescript"; + +export { Typescript }; + diff --git a/tests/typescript/export.test.ts b/tests/typescript/export.test.ts new file mode 100644 index 0000000..d4d2633 --- /dev/null +++ b/tests/typescript/export.test.ts @@ -0,0 +1,8 @@ +import { Typescript } from "@scripts/typescript"; +import * as ts from "typescript"; + +describe("toTypescript exports", () => { + it("exports the TypeScript factory", () => { + expect(Typescript).toBe(ts); + }); +}); diff --git a/tsconfig.build.json b/tsconfig.build.json index a341b3f..e07e8b5 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -7,4 +7,11 @@ "declarationDir": "dist", "types": null, }, -} \ No newline at end of file + "tsc-alias": { + "replacers": { + "base-url": { + "enabled": false + } + } + } +}