type-crafter 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -0
- package/dist/generators/generic.d.ts +2 -0
- package/dist/generators/helpers.d.ts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19801 -0
- package/dist/runtime.d.ts +24 -0
- package/dist/templates/index.d.ts +1 -0
- package/dist/templates/typescript/exporter-module-syntax.hbs +3 -0
- package/dist/templates/typescript/index.d.ts +2 -0
- package/dist/templates/typescript/object-syntax.hbs +5 -0
- package/dist/templates/typescript/types-file-syntax.hbs +5 -0
- package/dist/types/decoders.d.ts +5 -0
- package/dist/types/index.d.ts +100 -0
- package/dist/utils/error-handler.d.ts +16 -0
- package/dist/utils/file-system.d.ts +8 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/logger.d.ts +4 -0
- package/dist/writer/helpers.d.ts +3 -0
- package/dist/writer/index.d.ts +2 -0
- package/package.json +75 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Configuration, ExporterModuleTemplateInput, ObjectTemplateInput, SpecFileData, TypeFilePath, TypesFileTemplateInput } from '$types';
|
|
2
|
+
declare function setConfig(newConfig: Configuration): void;
|
|
3
|
+
declare function getConfig(): Configuration;
|
|
4
|
+
declare function setSpecFileData(newSpecFileData: SpecFileData): void;
|
|
5
|
+
declare function getSpecFileData(): SpecFileData;
|
|
6
|
+
declare function compileTemplates(): void;
|
|
7
|
+
declare function getObjectTemplate(): HandlebarsTemplateDelegate<ObjectTemplateInput>;
|
|
8
|
+
declare function getExporterModuleTemplate(): HandlebarsTemplateDelegate<ExporterModuleTemplateInput>;
|
|
9
|
+
declare function getTypesFileTemplate(): HandlebarsTemplateDelegate<TypesFileTemplateInput>;
|
|
10
|
+
declare function setExpectedOutputFiles(newExpectedOutputFiles: Map<string, TypeFilePath>): void;
|
|
11
|
+
declare function getExpectedOutputFiles(): Map<string, TypeFilePath>;
|
|
12
|
+
declare const _default: {
|
|
13
|
+
getConfig: typeof getConfig;
|
|
14
|
+
setConfig: typeof setConfig;
|
|
15
|
+
setSpecFileData: typeof setSpecFileData;
|
|
16
|
+
setExpectedOutputFiles: typeof setExpectedOutputFiles;
|
|
17
|
+
getSpecFileData: typeof getSpecFileData;
|
|
18
|
+
getObjectTemplate: typeof getObjectTemplate;
|
|
19
|
+
getExporterModuleTemplate: typeof getExporterModuleTemplate;
|
|
20
|
+
getTypesFileTemplate: typeof getTypesFileTemplate;
|
|
21
|
+
getExpectedOutputFiles: typeof getExpectedOutputFiles;
|
|
22
|
+
compileTemplates: typeof compileTemplates;
|
|
23
|
+
};
|
|
24
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as typescript from './typescript';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { GroupedTypesWriterMode, ObjectTemplateInputProperties, SpecFileData, TypesWriterMode } from '.';
|
|
2
|
+
export declare function decodeGroupedTypesWriterMode(rawInput: unknown): GroupedTypesWriterMode | null;
|
|
3
|
+
export declare function decodeTypesWriterMode(rawInput: unknown): TypesWriterMode | null;
|
|
4
|
+
export declare function decodeSpecFileData(rawInput: unknown): SpecFileData | null;
|
|
5
|
+
export declare function decodeObjectTemplateInputProperties(rawInput: unknown): ObjectTemplateInputProperties | null;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export * from './decoders';
|
|
2
|
+
export type Configuration = {
|
|
3
|
+
input: string;
|
|
4
|
+
output: OutputConfig;
|
|
5
|
+
template: Template;
|
|
6
|
+
language: LanguageConfig;
|
|
7
|
+
};
|
|
8
|
+
export type OutputConfig = {
|
|
9
|
+
cleanWrite: boolean;
|
|
10
|
+
fileExtension: string;
|
|
11
|
+
directory: string;
|
|
12
|
+
writerMode: {
|
|
13
|
+
groupedTypes: GroupedTypesWriterMode;
|
|
14
|
+
types: TypesWriterMode;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export type GroupedTypesWriterMode = 'FolderWithFiles' | 'SingleFile';
|
|
18
|
+
export type TypesWriterMode = 'SingleFile' | 'Files';
|
|
19
|
+
export type Template = {
|
|
20
|
+
objectSyntax: string;
|
|
21
|
+
exporterModuleSyntax: string;
|
|
22
|
+
typesFileSyntax: string;
|
|
23
|
+
};
|
|
24
|
+
export type LanguageConfig = {
|
|
25
|
+
exporterModuleName: string;
|
|
26
|
+
typeMapper: LanguageTypeMapper;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* @description Mappers for all the types supported by OpenAPI 3.0.0
|
|
30
|
+
* @see https://swagger.io/docs/specification/data-models/data-types/
|
|
31
|
+
*/
|
|
32
|
+
export type LanguageTypeMapper = Record<TypeDataType, FormatType | string>;
|
|
33
|
+
export type FormatType = {
|
|
34
|
+
default: string;
|
|
35
|
+
[format: string]: string | undefined;
|
|
36
|
+
};
|
|
37
|
+
export type SpecFileData = {
|
|
38
|
+
info: SpecInfo;
|
|
39
|
+
groupedTypes: GroupedTypes | null;
|
|
40
|
+
types: Types | null;
|
|
41
|
+
};
|
|
42
|
+
export type SpecInfo = {
|
|
43
|
+
version: string;
|
|
44
|
+
title: string;
|
|
45
|
+
};
|
|
46
|
+
type GroupName = string;
|
|
47
|
+
export type GroupedTypes = Record<GroupName, Types>;
|
|
48
|
+
type TypeName = string;
|
|
49
|
+
export type Types = Record<TypeName, TypeInfo>;
|
|
50
|
+
export type TypeInfo = {
|
|
51
|
+
required: string[] | null;
|
|
52
|
+
type: TypeDataType | null;
|
|
53
|
+
format: string | null;
|
|
54
|
+
items: TypeInfo | null;
|
|
55
|
+
properties: TypeProperties | null;
|
|
56
|
+
$ref: string | null;
|
|
57
|
+
};
|
|
58
|
+
type PropertyName = string;
|
|
59
|
+
export type TypeProperties = Record<PropertyName, TypeInfo>;
|
|
60
|
+
export type TypeDataType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'unknown';
|
|
61
|
+
export type ObjectTemplateInput = {
|
|
62
|
+
typeName: string;
|
|
63
|
+
properties: ObjectTemplateInputProperties;
|
|
64
|
+
};
|
|
65
|
+
export type ObjectTemplateInputProperties = Record<PropertyName, ObjectTemplateInputProperty>;
|
|
66
|
+
export type ObjectTemplateInputProperty = {
|
|
67
|
+
type: string;
|
|
68
|
+
required: boolean;
|
|
69
|
+
referenced: boolean;
|
|
70
|
+
};
|
|
71
|
+
export type ExporterModuleTemplateInput = {
|
|
72
|
+
modules: string[];
|
|
73
|
+
};
|
|
74
|
+
export type TypesFileTemplateInput = {
|
|
75
|
+
referencedTypes: string[];
|
|
76
|
+
primitives: string[];
|
|
77
|
+
typesContent: string;
|
|
78
|
+
writtenAt: string;
|
|
79
|
+
};
|
|
80
|
+
export type ReferencedModule = {
|
|
81
|
+
modulePath: string;
|
|
82
|
+
moduleRelativePath: string;
|
|
83
|
+
referencedTypes: string[];
|
|
84
|
+
};
|
|
85
|
+
export type GenerationResult = {
|
|
86
|
+
groupedTypes: GroupedTypesOutput;
|
|
87
|
+
types: GeneratedTypes;
|
|
88
|
+
};
|
|
89
|
+
export type GeneratedType = {
|
|
90
|
+
content: string;
|
|
91
|
+
references: Set<string>;
|
|
92
|
+
primitives: Set<string>;
|
|
93
|
+
};
|
|
94
|
+
export type GroupedTypesOutput = Record<GroupName, GeneratedTypes>;
|
|
95
|
+
export type GeneratedTypes = Record<TypeName, GeneratedType>;
|
|
96
|
+
export type TypeFilePath = {
|
|
97
|
+
modulePath: string;
|
|
98
|
+
filePath: string;
|
|
99
|
+
extension: string;
|
|
100
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class LanguageNotSupportedError extends Error {
|
|
2
|
+
constructor(language: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class InvalidParamError extends Error {
|
|
5
|
+
constructor(key: string, value: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class InvalidSpecFileError extends Error {
|
|
8
|
+
constructor(param: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class RuntimeError extends Error {
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class UnsupportedFeatureError extends Error {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
export declare function handleErrors(error: unknown): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function resolveFilePath(filePath: string): string;
|
|
2
|
+
export declare function readFile(filePath: string): Promise<string>;
|
|
3
|
+
export declare function createFolderWithBasePath(basePath: string, folderName: string): Promise<void>;
|
|
4
|
+
export declare function createFolder(folderPath: string): Promise<void>;
|
|
5
|
+
export declare function deleteFolder(folderPath: string): Promise<void>;
|
|
6
|
+
export declare function getCompleteFolderPath(folderName: string): Promise<string>;
|
|
7
|
+
export declare function getExpectedWrittenPath(basePath: string, fileName: string): Promise<string>;
|
|
8
|
+
export declare function writeFile(basePath: string, fileName: string, content: string): Promise<void>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type JSONObject } from 'type-decoder';
|
|
2
|
+
export * from './file-system';
|
|
3
|
+
export * from './logger';
|
|
4
|
+
export declare function addValuesToMappedSet(map: Map<string, Set<string>>, key: string, values: string[]): void;
|
|
5
|
+
export declare function getOptionalKeys(object: unknown): string[];
|
|
6
|
+
export declare function getReferencedTypes(object: unknown): string[];
|
|
7
|
+
export declare function getReferencedTypeModules(_referencedTypes: unknown, _writtenAt: string): unknown[];
|
|
8
|
+
export declare function toPascalCase(input: string): string;
|
|
9
|
+
export declare function registerTemplateHelpers(): void;
|
|
10
|
+
export declare function readNestedValue(json: JSONObject, keyPath: string[]): JSONObject;
|
|
11
|
+
export declare function generateRelativePath(fromPath: string, toPath: string): string;
|
|
12
|
+
export declare function stripPrefix(value: string, prefix: string): string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function logError(header: string, message?: string | null): void;
|
|
2
|
+
export declare function logWarning(header: string, message: string): void;
|
|
3
|
+
export declare function logSuccess(header: string, message: string): void;
|
|
4
|
+
export declare function greeting(): void;
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "type-crafter",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A tool to generate types from a yaml schema for any language",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"type-crafter": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"!dist/**/*.test.*",
|
|
13
|
+
"!dist/**/*.spec.*",
|
|
14
|
+
"scripts/postinstall.js"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"dev": "tsc --watch",
|
|
18
|
+
"format:all": "npx prettier --write .",
|
|
19
|
+
"lint:all": "eslint . --ext .ts",
|
|
20
|
+
"clean:output": "rm -rf dist",
|
|
21
|
+
"build": "npm run clean:output && rollup --config rollup.config.js",
|
|
22
|
+
"publish": "node scripts/publish.js",
|
|
23
|
+
"changeset:version": "changeset version && git add --all"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"type-crafter",
|
|
27
|
+
"types",
|
|
28
|
+
"crafter",
|
|
29
|
+
"generation",
|
|
30
|
+
"generator",
|
|
31
|
+
"typescript"
|
|
32
|
+
],
|
|
33
|
+
"author": "Sahil Sinha",
|
|
34
|
+
"license": "ISC",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"import": "./dist/index.js",
|
|
38
|
+
"require": "./dist/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/sinha-sahil/type-crafter.git"
|
|
44
|
+
},
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/sinha-sahil/type-crafter/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/sinha-sahil/type-crafter#readme",
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@changesets/cli": "^2.26.2",
|
|
51
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
52
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
53
|
+
"@rollup/plugin-replace": "^5.0.5",
|
|
54
|
+
"@rollup/plugin-typescript": "^11.1.5",
|
|
55
|
+
"@types/node": "^20.8.4",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^6.7.5",
|
|
57
|
+
"@typescript-eslint/parser": "^6.7.5",
|
|
58
|
+
"commander": "^11.1.0",
|
|
59
|
+
"eslint": "^8.51.0",
|
|
60
|
+
"eslint-config-prettier": "^9.0.0",
|
|
61
|
+
"eslint-config-standard-with-typescript": "^39.1.1",
|
|
62
|
+
"eslint-plugin-import": "^2.25.2",
|
|
63
|
+
"eslint-plugin-n": "^15.0.0 || ^16.0.0 ",
|
|
64
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
65
|
+
"handlebars": "^4.7.8",
|
|
66
|
+
"husky": "^8.0.3",
|
|
67
|
+
"prettier": "^3.0.3",
|
|
68
|
+
"rollup": "^4.5.1",
|
|
69
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
70
|
+
"tslib": "^2.6.2",
|
|
71
|
+
"type-decoder": "^1.2.0",
|
|
72
|
+
"typescript": "^5.2.2",
|
|
73
|
+
"yaml": "^2.3.2"
|
|
74
|
+
}
|
|
75
|
+
}
|