@x-dome/joi-to-typescript 4.15.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.
Files changed (86) hide show
  1. package/.yarnrc.yml +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +343 -0
  4. package/SECURITY.md +9 -0
  5. package/dist/main/analyseSchemaFile.d.ts +12 -0
  6. package/dist/main/analyseSchemaFile.d.ts.map +1 -0
  7. package/dist/main/analyseSchemaFile.js +149 -0
  8. package/dist/main/convertFilesInDirectory.d.ts +7 -0
  9. package/dist/main/convertFilesInDirectory.d.ts.map +1 -0
  10. package/dist/main/convertFilesInDirectory.js +83 -0
  11. package/dist/main/index.d.ts +12 -0
  12. package/dist/main/index.d.ts.map +1 -0
  13. package/dist/main/index.js +68 -0
  14. package/dist/main/joiDescribeTypes.d.ts +92 -0
  15. package/dist/main/joiDescribeTypes.d.ts.map +1 -0
  16. package/dist/main/joiDescribeTypes.js +2 -0
  17. package/dist/main/joiUtils.d.ts +28 -0
  18. package/dist/main/joiUtils.d.ts.map +1 -0
  19. package/dist/main/joiUtils.js +115 -0
  20. package/dist/main/parse.d.ts +15 -0
  21. package/dist/main/parse.d.ts.map +1 -0
  22. package/dist/main/parse.js +666 -0
  23. package/dist/main/types.d.ts +281 -0
  24. package/dist/main/types.d.ts.map +1 -0
  25. package/dist/main/types.js +42 -0
  26. package/dist/main/utils.d.ts +16 -0
  27. package/dist/main/utils.d.ts.map +1 -0
  28. package/dist/main/utils.js +45 -0
  29. package/dist/main/write.d.ts +20 -0
  30. package/dist/main/write.d.ts.map +1 -0
  31. package/dist/main/write.js +122 -0
  32. package/dist/main/writeInterfaceFile.d.ts +8 -0
  33. package/dist/main/writeInterfaceFile.d.ts.map +1 -0
  34. package/dist/main/writeInterfaceFile.js +82 -0
  35. package/dist/module/analyseSchemaFile.d.ts +12 -0
  36. package/dist/module/analyseSchemaFile.d.ts.map +1 -0
  37. package/dist/module/analyseSchemaFile.js +109 -0
  38. package/dist/module/convertFilesInDirectory.d.ts +7 -0
  39. package/dist/module/convertFilesInDirectory.d.ts.map +1 -0
  40. package/dist/module/convertFilesInDirectory.js +77 -0
  41. package/dist/module/index.d.ts +12 -0
  42. package/dist/module/index.d.ts.map +1 -0
  43. package/dist/module/index.js +61 -0
  44. package/dist/module/joiDescribeTypes.d.ts +92 -0
  45. package/dist/module/joiDescribeTypes.d.ts.map +1 -0
  46. package/dist/module/joiDescribeTypes.js +1 -0
  47. package/dist/module/joiUtils.d.ts +28 -0
  48. package/dist/module/joiUtils.d.ts.map +1 -0
  49. package/dist/module/joiUtils.js +107 -0
  50. package/dist/module/parse.d.ts +15 -0
  51. package/dist/module/parse.d.ts.map +1 -0
  52. package/dist/module/parse.js +657 -0
  53. package/dist/module/types.d.ts +281 -0
  54. package/dist/module/types.d.ts.map +1 -0
  55. package/dist/module/types.js +36 -0
  56. package/dist/module/utils.d.ts +16 -0
  57. package/dist/module/utils.d.ts.map +1 -0
  58. package/dist/module/utils.js +40 -0
  59. package/dist/module/write.d.ts +20 -0
  60. package/dist/module/write.d.ts.map +1 -0
  61. package/dist/module/write.js +113 -0
  62. package/dist/module/writeInterfaceFile.d.ts +8 -0
  63. package/dist/module/writeInterfaceFile.d.ts.map +1 -0
  64. package/dist/module/writeInterfaceFile.js +76 -0
  65. package/dist/types/analyseSchemaFile.d.ts +12 -0
  66. package/dist/types/analyseSchemaFile.d.ts.map +1 -0
  67. package/dist/types/convertFilesInDirectory.d.ts +7 -0
  68. package/dist/types/convertFilesInDirectory.d.ts.map +1 -0
  69. package/dist/types/index.d.ts +12 -0
  70. package/dist/types/index.d.ts.map +1 -0
  71. package/dist/types/joiDescribeTypes.d.ts +92 -0
  72. package/dist/types/joiDescribeTypes.d.ts.map +1 -0
  73. package/dist/types/joiUtils.d.ts +28 -0
  74. package/dist/types/joiUtils.d.ts.map +1 -0
  75. package/dist/types/parse.d.ts +15 -0
  76. package/dist/types/parse.d.ts.map +1 -0
  77. package/dist/types/types.d.ts +281 -0
  78. package/dist/types/types.d.ts.map +1 -0
  79. package/dist/types/utils.d.ts +16 -0
  80. package/dist/types/utils.d.ts.map +1 -0
  81. package/dist/types/write.d.ts +20 -0
  82. package/dist/types/write.d.ts.map +1 -0
  83. package/dist/types/writeInterfaceFile.d.ts +8 -0
  84. package/dist/types/writeInterfaceFile.d.ts.map +1 -0
  85. package/joi-to-typescript-4.15.0.tgz +0 -0
  86. package/package.json +60 -0
@@ -0,0 +1,92 @@
1
+ import Joi from 'joi';
2
+ /**
3
+ * This file extends the TypeScript Types that are packaged as part of joi
4
+ */
5
+ /**
6
+ * Add extra typings that Joi Types does not include
7
+ */
8
+ export interface BaseDescribe extends Joi.Description {
9
+ flags?: {
10
+ /**
11
+ * https://joi.dev/api/#anyidid
12
+ */
13
+ id?: string;
14
+ /**
15
+ * https://joi.dev/api/#anylabelname
16
+ */
17
+ label?: string;
18
+ /**
19
+ * https://joi.dev/api/#anydescriptiondesc
20
+ */
21
+ description?: string;
22
+ /**
23
+ * https://joi.dev/api/#anypresencemode
24
+ */
25
+ presence?: 'optional' | 'required' | 'forbidden';
26
+ /**
27
+ * Default object value
28
+ */
29
+ default?: unknown;
30
+ /**
31
+ * Allow undefined values in array
32
+ */
33
+ sparse?: boolean;
34
+ /**
35
+ * https://joi.dev/api/#objectunknownallow
36
+ */
37
+ unknown?: boolean;
38
+ /**
39
+ * https://joi.dev/api/#anycastto
40
+ */
41
+ cast?: 'string' | 'number' | 'map' | 'set';
42
+ /**
43
+ * https://joi.dev/api/#anyonly
44
+ */
45
+ only?: boolean;
46
+ };
47
+ /**
48
+ * https://joi.dev/api/#objectpatternpattern-schema-options
49
+ */
50
+ patterns?: {
51
+ schema?: Describe;
52
+ regex?: string;
53
+ rule: Describe;
54
+ }[];
55
+ metas?: Meta[];
56
+ /**
57
+ * The fist item in this array could be this instead of a value { override?: boolean} or contain { ref : {}};
58
+ */
59
+ allow?: unknown[];
60
+ }
61
+ /**
62
+ * Meta is a custom object provided by Joi
63
+ * The values here are how this libarary uses it they are not standard Joi
64
+ */
65
+ export interface Meta {
66
+ className?: string;
67
+ unknownType?: string;
68
+ readonly?: boolean;
69
+ }
70
+ export interface ArrayDescribe extends BaseDescribe {
71
+ type: 'array';
72
+ items?: Describe[];
73
+ ordered?: Describe[];
74
+ }
75
+ export interface ObjectDescribe extends BaseDescribe {
76
+ type: 'object';
77
+ keys: Record<'string', Describe>;
78
+ }
79
+ export interface AlternativesDescribe extends BaseDescribe {
80
+ type: 'alternatives';
81
+ matches: {
82
+ schema: Describe;
83
+ }[];
84
+ }
85
+ export interface StringDescribe extends BaseDescribe {
86
+ type: 'string';
87
+ }
88
+ export interface BasicDescribe extends BaseDescribe {
89
+ type: 'any' | 'boolean' | 'date' | 'number';
90
+ }
91
+ export type Describe = ArrayDescribe | BasicDescribe | ObjectDescribe | AlternativesDescribe | StringDescribe;
92
+ //# sourceMappingURL=joiDescribeTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"joiDescribeTypes.d.ts","sourceRoot":"","sources":["../../src/joiDescribeTypes.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,GAAG,CAAC,WAAW;IACnD,KAAK,CAAC,EAAE;QACN;;WAEG;QACH,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ;;WAEG;QACH,KAAK,CAAC,EAAE,MAAM,CAAC;QACf;;WAEG;QACH,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB;;WAEG;QACH,QAAQ,CAAC,EAAE,UAAU,GAAG,UAAU,GAAG,WAAW,CAAC;QACjD;;WAEG;QACH,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB;;WAEG;QACH,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB;;WAEG;QACH,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB;;WAEG;QACH,IAAI,CAAC,EAAE,QAAQ,GAA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,0 +1,28 @@
1
+ import { Settings } from '.';
2
+ import { Describe } from './joiDescribeTypes';
3
+ /**
4
+ * Fetch the metadata values for a given field. Note that it is possible to have
5
+ * more than one metadata record for a given field hence it is possible to get
6
+ * back a list of values.
7
+ *
8
+ * @param field - the name of the metadata field to fetch
9
+ * @param details - the schema details
10
+ * @returns the values for the given field
11
+ */
12
+ export declare function getMetadataFromDetails(field: string, details: Describe): any[];
13
+ export declare function getIsReadonly(details: Describe): boolean | undefined;
14
+ export declare function getDisableDescription(details: Describe): boolean | undefined;
15
+ /**
16
+ * Get the interface name from the Joi
17
+ * @returns a string if it can find one
18
+ */
19
+ export declare function getInterfaceOrTypeName(settings: Settings, details: Describe): string | undefined;
20
+ /**
21
+ * Note: this is updating by reference
22
+ */
23
+ export declare function ensureInterfaceorTypeName(settings: Settings, details: Describe, interfaceOrTypeName: string): void;
24
+ /**
25
+ * Ensure values is an array and remove any junk
26
+ */
27
+ export declare function getAllowValues(allow: unknown[] | undefined): any[];
28
+ //# sourceMappingURL=joiUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"joiUtils.d.ts","sourceRoot":"","sources":["../../src/joiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C;;;;;;;;GAQG;AAEH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,GAAG,EAAE,CAI9E;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,CAUpE;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,CAQ5E;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAkBhG;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,GAAG,IAAI,CA2BlH;AAED;;GAEG;AAEH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,SAAS,GAAG,GAAG,EAAE,CAYlE"}
@@ -0,0 +1,15 @@
1
+ import { Settings, TypeContent } from './types';
2
+ import { Describe } from './joiDescribeTypes';
3
+ export declare const supportedJoiTypes: string[];
4
+ export declare function getAllCustomTypes(parsedSchema: TypeContent): string[];
5
+ export declare function typeContentToTs(settings: Settings, parsedSchema: TypeContent, doExport?: boolean): string;
6
+ /**
7
+ * Parses a joi schema into a TypeContent
8
+ * @param details: the joi schema
9
+ * @param settings: settings used for parsing
10
+ * @param useLabels if true and if a schema has a label we won't parse it and instead just reference the label in the outputted type
11
+ * @param ignoreLabels a list a label to ignore if found. Sometimes nested joi schemas will inherit the parents label so we want to ignore that
12
+ * @param rootSchema
13
+ */
14
+ export declare function parseSchema(details: Describe, settings: Settings, useLabels?: boolean, ignoreLabels?: string[], rootSchema?: boolean): TypeContent | undefined;
15
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/parse.ts"],"names":[],"mappings":"AACA,OAAO,EAAoD,QAAQ,EAAE,WAAW,EAAmB,MAAM,SAAS,CAAC;AACnH,OAAO,EAKL,QAAQ,EAGT,MAAM,oBAAoB,CAAC;AAY5B,eAAO,MAAM,iBAAiB,UAAoF,CAAC;AAkEnH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,WAAW,GAAG,MAAM,EAAE,CAQrE;AA2QD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,UAAQ,GAAG,MAAM,CAKvG;AA2BD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,QAAQ,EACjB,QAAQ,EAAE,QAAQ,EAClB,SAAS,UAAO,EAChB,YAAY,GAAE,MAAM,EAAO,EAC3B,UAAU,CAAC,EAAE,OAAO,GACnB,WAAW,GAAG,SAAS,CAwFzB"}
@@ -0,0 +1,281 @@
1
+ import Joi from 'joi';
2
+ /**
3
+ * Application settings
4
+ */
5
+ export interface Settings {
6
+ /**
7
+ * The input/schema directory
8
+ * Directory must exist
9
+ */
10
+ readonly schemaDirectory: string;
11
+ /**
12
+ * The output/type directory
13
+ * Will also attempt to create this directory
14
+ */
15
+ readonly typeOutputDirectory: string;
16
+ /**
17
+ * Use .label('InterfaceName') instead of .meta({className:'InterfaceName'}) for interface names
18
+ */
19
+ readonly useLabelAsInterfaceName: boolean;
20
+ /**
21
+ * If defined, when a schema name ends with "schema", replaces the ending in the generated type by default
22
+ * with this string.
23
+ * E.g. when this setting is "Interface", a `TestSchema` object generates a `TestInterface` type
24
+ */
25
+ readonly defaultInterfaceSuffix?: string;
26
+ /**
27
+ * Should interface properties be defaulted to optional or required
28
+ * @default false
29
+ */
30
+ readonly defaultToRequired: boolean;
31
+ /**
32
+ * What schema file name suffix will be removed when creating the interface file name
33
+ * @default "Schema"
34
+ * This ensures that an interface and Schema with the file name are not confused
35
+ */
36
+ readonly schemaFileSuffix: string;
37
+ /**
38
+ * If provided, appends this suffix to the generated interface filenames
39
+ * @default ""
40
+ */
41
+ readonly interfaceFileSuffix: string;
42
+ /**
43
+ * If `true` the console will include more information
44
+ * @default false
45
+ */
46
+ readonly debug: boolean;
47
+ /**
48
+ * File Header content for generated files
49
+ */
50
+ readonly fileHeader: string;
51
+ /**
52
+ * If true will sort properties on interface by name
53
+ * @default true
54
+ */
55
+ readonly sortPropertiesByName: boolean;
56
+ /**
57
+ * If true will not output to subDirectories in output/interface directory. It will flatten the structure.
58
+ */
59
+ readonly flattenTree: boolean;
60
+ /**
61
+ * If true will only read the files in the root directory of the input/schema directory. Will not parse through sub-directories.
62
+ */
63
+ readonly rootDirectoryOnly: boolean;
64
+ /**
65
+ * If true will write all exports *'s to root index.ts in output/interface directory.
66
+ */
67
+ readonly indexAllToRoot: boolean;
68
+ /**
69
+ * Comment every interface and property even with just a duplicate of the interface and property name
70
+ * @default false
71
+ */
72
+ readonly commentEverything: boolean;
73
+ /**
74
+ * List of files or folders that should be ignored from conversion. These can either be
75
+ * filenames (AddressSchema.ts) or filepaths postfixed with a / (addressSchemas/)
76
+ * @default []
77
+ */
78
+ readonly ignoreFiles: string[];
79
+ /**
80
+ * The indentation characters
81
+ * @default ' ' (two spaces)
82
+ */
83
+ readonly indentationChacters: string;
84
+ /**
85
+ * If set to true, will use double quotes for strings
86
+ * @default false
87
+ */
88
+ readonly doublequoteEscape: boolean;
89
+ /**
90
+ * If a field has a default and is optional, consider it as required
91
+ * @default false
92
+ */
93
+ readonly treatDefaultedOptionalAsRequired: boolean;
94
+ /**
95
+ * If a field has a default, modify the resulting field to equal
96
+ * `field: <default> | type` rather than `field: type`
97
+ * @default false
98
+ */
99
+ readonly supplyDefaultsInType: boolean;
100
+ /**
101
+ * If a field has a default value, add its stringified representation
102
+ * to the JsDoc using the @default annotation
103
+ * @default false
104
+ */
105
+ readonly supplyDefaultsInJsDoc: boolean;
106
+ /**
107
+ * Filter files you wish to parse
108
+ * The class `InputFileFilter` contains some default options
109
+ * @default *.ts files
110
+ */
111
+ readonly inputFileFilter: RegExp;
112
+ /**
113
+ * If true, skips the creation of index.ts files in the generated interface directories
114
+ * @default false
115
+ */
116
+ readonly omitIndexFiles: boolean;
117
+ /**
118
+ * If provided, prepends the content returned by the function to the
119
+ * generated interface/type code (including and JSDoc).
120
+ */
121
+ readonly tsContentHeader?: (type: ConvertedType) => string;
122
+ /**
123
+ * If provided, appends the content returned by the function to the
124
+ * generated interface/type code.
125
+ */
126
+ readonly tsContentFooter?: (type: ConvertedType) => string;
127
+ /**
128
+ * If defined, place every member of a union on a new line
129
+ */
130
+ readonly unionNewLine?: boolean;
131
+ /**
132
+ * If defined, place every member of a tuple on a new line
133
+ */
134
+ readonly tupleNewLine?: boolean;
135
+ }
136
+ export declare class InputFileFilter {
137
+ /**
138
+ * *.ts files
139
+ */
140
+ static readonly Default: RegExp;
141
+ /**
142
+ * *.ts files excluding index.ts files
143
+ */
144
+ static readonly ExcludeIndex: RegExp;
145
+ /**
146
+ * *.ts and *.js files
147
+ */
148
+ static readonly IncludeJavaScript: RegExp;
149
+ }
150
+ export interface ConvertedType {
151
+ schema: Joi.Schema;
152
+ interfaceOrTypeName: string;
153
+ content: string;
154
+ customTypes: string[];
155
+ location?: string;
156
+ }
157
+ export interface BaseTypeContent {
158
+ /**
159
+ * Interface name or type name (from id/label or key name)
160
+ */
161
+ interfaceOrTypeName?: string;
162
+ /**
163
+ * will add this to the jsDoc output
164
+ */
165
+ jsDoc?: JsDoc;
166
+ /**
167
+ * If this is an object property is it required
168
+ */
169
+ required?: boolean;
170
+ /**
171
+ * Default value
172
+ */
173
+ value?: unknown;
174
+ /**
175
+ * Is readonly
176
+ */
177
+ isReadonly?: boolean;
178
+ }
179
+ /**
180
+ * Holds multiple TypeContents that will be joined together
181
+ */
182
+ export interface TypeContentRoot extends BaseTypeContent {
183
+ __isRoot: true;
184
+ /**
185
+ * How to join the children types together
186
+ */
187
+ joinOperation: 'list' | 'tuple' | 'union' | 'intersection' | 'object' | 'objectWithUndefinedKeys';
188
+ /**
189
+ * Children types
190
+ */
191
+ children: TypeContent[];
192
+ }
193
+ /**
194
+ * A single type
195
+ */
196
+ export interface TypeContentChild extends BaseTypeContent {
197
+ __isRoot: false;
198
+ /**
199
+ * Other non-basic schemas referenced in this type
200
+ */
201
+ customTypes?: string[];
202
+ /**
203
+ * The typescript result ex: string, 'literalString', 42, SomeTypeName
204
+ */
205
+ content: string;
206
+ }
207
+ export declare function makeTypeContentChild({ content, customTypes, required, isReadonly, interfaceOrTypeName, jsDoc }: Omit<TypeContentChild, '__isRoot'>): TypeContentChild;
208
+ export declare function makeTypeContentRoot({ joinOperation, interfaceOrTypeName, children, required, isReadonly, jsDoc }: Omit<TypeContentRoot, '__isRoot'>): TypeContentRoot;
209
+ /**
210
+ * Holds information for conversion to ts
211
+ */
212
+ export type TypeContent = TypeContentRoot | TypeContentChild;
213
+ export interface Property {
214
+ /**
215
+ * The object key this schema was stored under
216
+ */
217
+ name: string;
218
+ /**
219
+ * number, string literals, Joi.meta({className:value}), etc
220
+ */
221
+ type: string;
222
+ /**
223
+ * Other schemas referenced in this schema
224
+ */
225
+ customTypes?: string[];
226
+ /**
227
+ * The typescript result
228
+ */
229
+ content: string;
230
+ }
231
+ export interface GenerateTypeFile {
232
+ /**
233
+ * External Types required by File
234
+ */
235
+ externalTypes: ConvertedType[];
236
+ /**
237
+ * Internal Types provided by File
238
+ */
239
+ internalTypes: ConvertedType[];
240
+ /**
241
+ * Contents of file exported.
242
+ */
243
+ fileContent: string;
244
+ /**
245
+ * File Name of file exported.
246
+ */
247
+ typeFileName: string;
248
+ /**
249
+ * File Location of where file is exported.
250
+ */
251
+ typeFileLocation: string;
252
+ }
253
+ export interface GenerateTypesDir {
254
+ /**
255
+ * Types generated in Directory/SubDirectory
256
+ */
257
+ types: GenerateTypeFile[];
258
+ /**
259
+ * FileNames of files exported.
260
+ */
261
+ typeFileNames: string[];
262
+ }
263
+ export interface JsDoc {
264
+ /**
265
+ * description value
266
+ */
267
+ description?: string;
268
+ /**
269
+ * @example example values
270
+ */
271
+ examples?: string[];
272
+ /**
273
+ * @default default value
274
+ */
275
+ default?: string;
276
+ /**
277
+ * If true, completely disables printing JsDoc
278
+ */
279
+ disable?: boolean;
280
+ }
281
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;;OAGG;IACH,QAAQ,CAAC,eAAe,EAAE,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,MAAM,CAAC;IACrB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
@@ -0,0 +1,16 @@
1
+ import { Describe } from 'joiDescribeTypes';
2
+ /**
3
+ * Applies the mapper over each element in the list.
4
+ * If the mapper returns undefined it will not show up in the result
5
+ *
6
+ * @param list - array to filter + map
7
+ * @param mapper - mapper func to apply to map
8
+ */
9
+ export declare function filterMap<T, K>(list: T[], mapper: (t: T) => K | undefined): K[];
10
+ /**
11
+ * Escape value so that it can be go into single quoted string literal.
12
+ * @param value
13
+ */
14
+ export declare function toStringLiteral(value: string, doublequoteEscape: boolean): string;
15
+ export declare function isDescribe(x: unknown): x is Describe;
16
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,SAAS,GAAG,CAAC,EAAE,CAQ/E;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,OAAO,GAAG,MAAM,CAWjF;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,QAAQ,CAUpD"}
@@ -0,0 +1,20 @@
1
+ import { JsDoc, Settings } from './types';
2
+ /**
3
+ * Write index.ts file
4
+ *
5
+ * @param settings - Settings Object
6
+ * @param fileNamesToExport - List of file names that will be added to the index.ts file
7
+ */
8
+ export declare function writeIndexFile(settings: Settings, fileNamesToExport: string[]): void;
9
+ export declare function getTypeFileNameFromSchema(schemaFileName: string, settings: Settings): string;
10
+ /**
11
+ * Get all indent characters for this indent level
12
+ * @param settings includes what the indent characters are
13
+ * @param indentLevel how many indent levels
14
+ */
15
+ export declare function getIndentStr(settings: Settings, indentLevel: number): string;
16
+ /**
17
+ * Get Interface jsDoc
18
+ */
19
+ export declare function getJsDocString(settings: Settings, name: string, jsDoc?: JsDoc, indentLevel?: number): string;
20
+ //# sourceMappingURL=write.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../src/write.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAAG,IAAI,CAQpF;AAED,wBAAgB,yBAAyB,CAAC,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAM5F;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAE5E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,WAAW,SAAI,GAAG,MAAM,CAyDvG"}
@@ -0,0 +1,8 @@
1
+ import { Settings, GenerateTypeFile } from './types';
2
+ /**
3
+ * Write interface file
4
+ *
5
+ * @returns The written file name
6
+ */
7
+ export declare function writeInterfaceFile(settings: Settings, typeFileName: string, generatedTypes: GenerateTypeFile[], fullPath: string): Promise<undefined | string>;
8
+ //# sourceMappingURL=writeInterfaceFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeInterfaceFile.d.ts","sourceRoot":"","sources":["../../src/writeInterfaceFile.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAErD;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,gBAAgB,EAAE,EAClC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,CAgF7B"}
Binary file
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@x-dome/joi-to-typescript",
3
+ "description": "Convert Joi Schemas to TypeScript interfaces",
4
+ "version": "4.15.0",
5
+ "author": "Jono Clarnette",
6
+ "keywords": [
7
+ "joi",
8
+ "ts",
9
+ "typescript",
10
+ "hapi",
11
+ "interface"
12
+ ],
13
+ "license": "MIT",
14
+ "repository": {
15
+ "url": "https://github.com/mrjono1/joi-to-typescript",
16
+ "type": "git"
17
+ },
18
+ "funding": "https://github.com/mrjono1/joi-to-typescript?sponsor=1",
19
+ "bugs": {
20
+ "url": "https://github.com/mrjono1/joi-to-typescript/issues"
21
+ },
22
+ "main": "./dist/main/index.js",
23
+ "module": "./dist/module/index.js",
24
+ "typings": "./dist/types/index.d.ts",
25
+ "exports": {
26
+ "import": "./dist/module/index.js",
27
+ "require": "./dist/main/index.js"
28
+ },
29
+ "scripts": {
30
+ "build:esm": "tsc --module es2020 --outDir ./dist/module",
31
+ "build:cjs": "tsc --module commonjs --outDir ./dist/main",
32
+ "build:dts": "tsc --declaration --emitDeclarationOnly --outDir ./dist/types",
33
+ "build": "yarn build:esm && yarn build:cjs && yarn build:dts",
34
+ "format": "prettier --write \"src/**/*.ts\"",
35
+ "lint": "eslint 'src/**'",
36
+ "test": "jest --config jest.config.cjs",
37
+ "coverage": "yarn test --coverage --silent",
38
+ "pub": "yarn build && yarn publish"
39
+ },
40
+ "devDependencies": {
41
+ "@types/jest": "29.5.14",
42
+ "@types/node": "20.12.2",
43
+ "@typescript-eslint/eslint-plugin": "7.18.0",
44
+ "@typescript-eslint/parser": "7.18.0",
45
+ "eslint": "8.57.0",
46
+ "eslint-config-prettier": "9.1.0",
47
+ "eslint-plugin-prettier": "5.2.1",
48
+ "jest": "29.7.0",
49
+ "joi": "17.13.3",
50
+ "prettier": "3.4.2",
51
+ "ts-jest": "29.2.5",
52
+ "typescript": "5.7.2"
53
+ },
54
+ "peerDependencies": {
55
+ "joi": "17.x"
56
+ },
57
+ "engines": {
58
+ "node": ">=14.0.0"
59
+ }
60
+ }