diff --git a/README.md b/README.md index 3ee4f14..d1e4669 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,11 @@ The code-generation process is highly customizable and almost all the defaults ( - Global installation (`npm i -g ts-sql-codegen`) can be convenient, but is preferrable to have ts-sql-codegen as a project dependency to avoid versioning issues. -## Usage (CLI): +## Usage (CLI): After every database schema change: -**Step 1:** Generate yaml schema file from database using tbls +**Step 1:** Generate yaml schema file from database using tbls **Example:** `tbls out postgres://postgres:password@localhost:5432/testdb -t yaml -o schema.yaml` @@ -44,14 +44,14 @@ After every database schema change: **Example:** `ts-sql-codegen --schema ./schema.yaml --output-dir ./src/generated --connection-source ./src/db/connection-source` -### Note: +### Note: - All paths are relative to cwd - Above options are default, so you can also just run ts-sql-codegen ## Usage (Programmatic): -Programmatic usage enables a wider set of customization options. +Programmatic usage enables a wider set of customization options. **Example:** @@ -70,7 +70,7 @@ Refer to [Generator](./docs/classes/Generator.md) and [GeneratorOpts](./docs/int The [test suite](./test/test.ts) also has examples of more complex customizations. -For advanced use-cases (eg. custom templates, pre/post processing of generated code +For advanced use-cases (eg. custom templates, pre/post processing of generated code and custom logic for table/column/field mapping) it is recommended to extend the Generator class in project. We intend to keep the customization options that the constructor accepts focussed on primary common use-cases. @@ -112,7 +112,7 @@ const options = { } ``` -:warning: We don't do anything to ensure that database operations will succeed with included columns. Eg. if any omitted columns are mandatory they will cause inserts to fail. +:warning: We don't do anything to ensure that database operations will succeed with included columns. Eg. if any omitted columns are mandatory they will cause inserts to fail. ### Custom DB types @@ -126,7 +126,7 @@ const options = { connectionSourcePath: './connection-source.ts', fieldMappings: [ { - // Field matching criteria: + // Field matching criteria: // // Match any column of any table where column type in database // is the class_participation_policy custom type @@ -134,11 +134,11 @@ const options = { // For fields matched by above criteria, // use the ClassParticipationPolicyAdapter type adapter - // which you will have to implement. - // + // which you will have to implement. + // // The import paths are resolved relative to cwd, and converted // to relative paths wrt the generated file - // + // // Generated code will include an import like this: // import { ClassParticipationPolicyAdapter, ClassParticipationPolicy } from '../adapters'; generatedField: { @@ -179,7 +179,7 @@ You can simply run ts-sql-codegen multiple times for different databases/differe #### Filtering tables by schema -The tbls schema dump contains table names with schema prefix. We can target this prefix in table inclusion criteria: +The tbls schema dump contains table names with schema prefix. We can target this prefix in table inclusion criteria: ```ts const options = { @@ -203,7 +203,7 @@ const options = { } ``` -With this option the output looks like: +With this option the output looks like: ```ts export class AuthorsTable extends Table { @@ -230,7 +230,7 @@ const options = { } ``` -With this option the output looks like: +With this option the output looks like: ```ts export class AuthorsTable extends Table { @@ -256,7 +256,7 @@ This option will override the id prefix derived from schema name if `tableMappin Thanks for your interest in contributing to this project. Pull requests and feature enhancements are welcome. -This utility is being used in projects with many tables, so backward incompatible changes in generated code are highly undesirable. +This utility is being used in projects with many tables, so backward incompatible changes in generated code are highly undesirable. Feature flags are recommended for aspects which are not beneficial to all/most users. diff --git a/docs/README.md b/docs/README.md index c06f4bf..08d527b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -36,4 +36,4 @@ Matching criteria specified as string or regex #### Defined in -[src/field-mappings.ts:8](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L8) +[src/field-mappings.ts:8](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L8) diff --git a/docs/classes/Generator.md b/docs/classes/Generator.md index 7399580..f041c0d 100644 --- a/docs/classes/Generator.md +++ b/docs/classes/Generator.md @@ -35,6 +35,7 @@ and custom logic for table/column/field mapping. - [logger](Generator.md#logger) - [naming](Generator.md#naming) - [opts](Generator.md#opts) +- [writtenFiles](Generator.md#writtenfiles) ### Methods @@ -82,7 +83,7 @@ and custom logic for table/column/field mapping. #### Defined in -[src/generator.ts:75](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L75) +[src/generator.ts:79](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L79) ## Properties @@ -92,17 +93,17 @@ and custom logic for table/column/field mapping. #### Defined in -[src/generator.ts:88](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L88) +[src/generator.ts:92](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L92) ___ ### getFieldMappings -• `Protected` **getFieldMappings**: () => { `columnName`: `undefined` \| ``null`` \| `string` \| `RegExp` ; `columnType`: `undefined` \| ``null`` \| `string` \| `RegExp` ; `generatedField`: ``false`` \| { type?: { kind?: "custom" \| "customComparable" \| "enum" \| null \| undefined; dbType?: { name: string; } \| null \| undefined; tsType?: { importPath?: string \| null \| undefined; isDefault?: boolean \| ... 1 more ... \| undefined; isRelative?: boolean \| ... 1 more ... \| undefined; name: string; } \| null \| undefined; adapt... ; `tableName`: `undefined` \| ``null`` \| `string` \| `RegExp` }[] & `MemoizedFunction` +• `Protected` **getFieldMappings**: () => { `columnName`: `undefined` \| ``null`` \| `string` \| `RegExp` ; `columnType`: `undefined` \| ``null`` \| `string` \| `RegExp` ; `generatedField`: `Object` ; `tableName`: `undefined` \| ``null`` \| `string` \| `RegExp` }[] & `MemoizedFunction` #### Defined in -[src/generator.ts:80](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L80) +[src/generator.ts:84](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L84) ___ @@ -112,7 +113,7 @@ ___ #### Defined in -[src/generator.ts:84](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L84) +[src/generator.ts:88](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L88) ___ @@ -122,7 +123,7 @@ ___ #### Defined in -[src/generator.ts:73](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L73) +[src/generator.ts:77](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L77) ___ @@ -132,7 +133,7 @@ ___ #### Defined in -[src/generator.ts:72](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L72) +[src/generator.ts:74](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L74) ___ @@ -142,7 +143,17 @@ ___ #### Defined in -[src/generator.ts:71](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L71) +[src/generator.ts:73](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L73) + +___ + +### writtenFiles + +• `Private` **writtenFiles**: `Set`<`string`\> + +#### Defined in + +[src/generator.ts:76](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L76) ## Methods @@ -163,7 +174,7 @@ ___ #### Defined in -[src/generator.ts:313](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L313) +[src/generator.ts:318](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L318) ___ @@ -189,7 +200,7 @@ ___ #### Defined in -[src/generator.ts:473](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L473) +[src/generator.ts:478](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L478) ___ @@ -202,9 +213,9 @@ ___ | Name | Type | | :------ | :------ | | `table` | `Object` | -| `table.columns` | { nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; type: string; name: string; }[] | +| `table.columns` | { type: string; name: string; nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; }[] | | `table.comment` | `undefined` \| ``null`` \| `string` | -| `table.constraints` | { comment?: string \| null \| undefined; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; type: string; name: string; table: string; columns: string[]; }[] | +| `table.constraints` | { type: string; name: string; table: string; columns: string[]; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; comment?: string \| null \| undefined; }[] | | `table.name` | `string` | | `table.type` | `string` | @@ -214,7 +225,7 @@ ___ #### Defined in -[src/generator.ts:560](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L560) +[src/generator.ts:565](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L565) ___ @@ -234,7 +245,7 @@ ___ #### Defined in -[src/generator.ts:271](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L271) +[src/generator.ts:276](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L276) ___ @@ -248,7 +259,7 @@ ___ #### Defined in -[src/generator.ts:93](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L93) +[src/generator.ts:97](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L97) ___ @@ -261,9 +272,9 @@ ___ | Name | Type | | :------ | :------ | | `table` | `Object` | -| `table.columns` | { nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; type: string; name: string; }[] | +| `table.columns` | { type: string; name: string; nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; }[] | | `table.comment` | `undefined` \| ``null`` \| `string` | -| `table.constraints` | { comment?: string \| null \| undefined; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; type: string; name: string; table: string; columns: string[]; }[] | +| `table.constraints` | { type: string; name: string; table: string; columns: string[]; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; comment?: string \| null \| undefined; }[] | | `table.name` | `string` | | `table.type` | `string` | @@ -273,7 +284,7 @@ ___ #### Defined in -[src/generator.ts:137](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L137) +[src/generator.ts:141](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L141) ___ @@ -294,7 +305,7 @@ ___ #### Defined in -[src/generator.ts:374](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L374) +[src/generator.ts:379](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L379) ___ @@ -315,7 +326,7 @@ ___ #### Defined in -[src/generator.ts:294](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L294) +[src/generator.ts:299](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L299) ___ @@ -335,7 +346,7 @@ ___ #### Defined in -[src/generator.ts:442](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L442) +[src/generator.ts:447](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L447) ___ @@ -356,7 +367,7 @@ ___ #### Defined in -[src/generator.ts:402](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L402) +[src/generator.ts:407](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L407) ___ @@ -377,7 +388,7 @@ ___ #### Defined in -[src/generator.ts:422](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L422) +[src/generator.ts:427](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L427) ___ @@ -397,7 +408,7 @@ ___ #### Defined in -[src/generator.ts:283](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L283) +[src/generator.ts:288](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L288) ___ @@ -423,7 +434,7 @@ ___ #### Defined in -[src/generator.ts:504](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L504) +[src/generator.ts:509](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L509) ___ @@ -449,7 +460,7 @@ ___ #### Defined in -[src/generator.ts:518](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L518) +[src/generator.ts:523](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L523) ___ @@ -462,9 +473,9 @@ ___ | Name | Type | | :------ | :------ | | `table` | `Object` | -| `table.columns` | { nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; type: string; name: string; }[] | +| `table.columns` | { type: string; name: string; nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; }[] | | `table.comment` | `undefined` \| ``null`` \| `string` | -| `table.constraints` | { comment?: string \| null \| undefined; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; type: string; name: string; table: string; columns: string[]; }[] | +| `table.constraints` | { type: string; name: string; table: string; columns: string[]; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; comment?: string \| null \| undefined; }[] | | `table.name` | `string` | | `table.type` | `string` | @@ -474,7 +485,7 @@ ___ #### Defined in -[src/generator.ts:259](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L259) +[src/generator.ts:264](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L264) ___ @@ -496,7 +507,7 @@ ___ #### Defined in -[src/generator.ts:360](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L360) +[src/generator.ts:365](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L365) ___ @@ -517,7 +528,7 @@ ___ #### Defined in -[src/generator.ts:414](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L414) +[src/generator.ts:419](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L419) ___ @@ -530,9 +541,9 @@ ___ | Name | Type | | :------ | :------ | | `table` | `Object` | -| `table.columns` | { nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; type: string; name: string; }[] | +| `table.columns` | { type: string; name: string; nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; }[] | | `table.comment` | `undefined` \| ``null`` \| `string` | -| `table.constraints` | { comment?: string \| null \| undefined; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; type: string; name: string; table: string; columns: string[]; }[] | +| `table.constraints` | { type: string; name: string; table: string; columns: string[]; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; comment?: string \| null \| undefined; }[] | | `table.name` | `string` | | `table.type` | `string` | | `tableKind` | `TableKind` | @@ -543,7 +554,7 @@ ___ #### Defined in -[src/generator.ts:556](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L556) +[src/generator.ts:561](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L561) ___ @@ -556,9 +567,9 @@ ___ | Name | Type | | :------ | :------ | | `table` | `Object` | -| `table.columns` | { nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; type: string; name: string; }[] | +| `table.columns` | { type: string; name: string; nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; }[] | | `table.comment` | `undefined` \| ``null`` \| `string` | -| `table.constraints` | { comment?: string \| null \| undefined; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; type: string; name: string; table: string; columns: string[]; }[] | +| `table.constraints` | { type: string; name: string; table: string; columns: string[]; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; comment?: string \| null \| undefined; }[] | | `table.name` | `string` | | `table.type` | `string` | | `tableKind` | `TableKind` | @@ -569,7 +580,7 @@ ___ #### Defined in -[src/generator.ts:551](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L551) +[src/generator.ts:556](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L556) ___ @@ -589,7 +600,7 @@ ___ #### Defined in -[src/generator.ts:438](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L438) +[src/generator.ts:443](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L443) ___ @@ -609,7 +620,7 @@ ___ #### Defined in -[src/generator.ts:410](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L410) +[src/generator.ts:415](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L415) ___ @@ -622,9 +633,9 @@ ___ | Name | Type | | :------ | :------ | | `table` | `Object` | -| `table.columns` | { nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; type: string; name: string; }[] | +| `table.columns` | { type: string; name: string; nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; }[] | | `table.comment` | `undefined` \| ``null`` \| `string` | -| `table.constraints` | { comment?: string \| null \| undefined; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; type: string; name: string; table: string; columns: string[]; }[] | +| `table.constraints` | { type: string; name: string; table: string; columns: string[]; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; comment?: string \| null \| undefined; }[] | | `table.name` | `string` | | `table.type` | `string` | @@ -634,7 +645,7 @@ ___ #### Defined in -[src/generator.ts:129](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L129) +[src/generator.ts:133](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L133) ___ @@ -655,7 +666,7 @@ ___ #### Defined in -[src/generator.ts:333](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L333) +[src/generator.ts:338](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L338) ___ @@ -681,7 +692,7 @@ ___ #### Defined in -[src/generator.ts:489](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L489) +[src/generator.ts:494](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L494) ___ @@ -707,7 +718,7 @@ ___ #### Defined in -[src/generator.ts:446](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L446) +[src/generator.ts:451](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L451) ___ @@ -733,7 +744,7 @@ ___ #### Defined in -[src/generator.ts:457](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L457) +[src/generator.ts:462](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L462) ___ @@ -747,9 +758,9 @@ ___ | :------ | :------ | | `output` | `string` | | `_table` | `Object` | -| `_table.columns` | { nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; type: string; name: string; }[] | +| `_table.columns` | { type: string; name: string; nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; }[] | | `_table.comment` | `undefined` \| ``null`` \| `string` | -| `_table.constraints` | { comment?: string \| null \| undefined; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; type: string; name: string; table: string; columns: string[]; }[] | +| `_table.constraints` | { type: string; name: string; table: string; columns: string[]; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; comment?: string \| null \| undefined; }[] | | `_table.name` | `string` | | `_table.type` | `string` | @@ -759,7 +770,7 @@ ___ #### Defined in -[src/generator.ts:398](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L398) +[src/generator.ts:403](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L403) ___ @@ -779,7 +790,7 @@ ___ #### Defined in -[src/generator.ts:394](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L394) +[src/generator.ts:399](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L399) ___ @@ -792,9 +803,9 @@ ___ | Name | Type | | :------ | :------ | | `table` | `Object` | -| `table.columns` | { nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; type: string; name: string; }[] | +| `table.columns` | { type: string; name: string; nullable?: boolean \| undefined; default?: any; comment?: string \| null \| undefined; }[] | | `table.comment` | `undefined` \| ``null`` \| `string` | -| `table.constraints` | { comment?: string \| null \| undefined; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; type: string; name: string; table: string; columns: string[]; }[] | +| `table.constraints` | { type: string; name: string; table: string; columns: string[]; referencedTable?: string \| null \| undefined; referencedColumns?: string[] \| null \| undefined; comment?: string \| null \| undefined; }[] | | `table.name` | `string` | | `table.type` | `string` | @@ -804,4 +815,4 @@ ___ #### Defined in -[src/generator.ts:108](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator.ts#L108) +[src/generator.ts:113](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator.ts#L113) diff --git a/docs/interfaces/CommonCustomTypesOptions.md b/docs/interfaces/CommonCustomTypesOptions.md index d23fef0..308692d 100644 --- a/docs/interfaces/CommonCustomTypesOptions.md +++ b/docs/interfaces/CommonCustomTypesOptions.md @@ -30,4 +30,6 @@ z.TypeOf.importPath #### Defined in -[src/generator-options.ts:241](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L241) +[src/generator-options.ts:241](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L241) + +[src/generator-options.ts:241](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L241) diff --git a/docs/interfaces/CommonOptions.md b/docs/interfaces/CommonOptions.md index 03b4a41..51cd9b7 100644 --- a/docs/interfaces/CommonOptions.md +++ b/docs/interfaces/CommonOptions.md @@ -32,7 +32,7 @@ z.TypeOf.customTypes #### Defined in -[src/generator-options.ts:249](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L249) +[src/generator-options.ts:249](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L249) ___ @@ -50,7 +50,7 @@ z.TypeOf.primaryKey #### Defined in -[src/generator-options.ts:255](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L255) +[src/generator-options.ts:255](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L255) ___ @@ -68,4 +68,4 @@ z.TypeOf.typeAdapter #### Defined in -[src/generator-options.ts:252](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L252) +[src/generator-options.ts:252](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L252) diff --git a/docs/interfaces/CommonPrimaryKeyOptions.md b/docs/interfaces/CommonPrimaryKeyOptions.md index 6641b14..de456eb 100644 --- a/docs/interfaces/CommonPrimaryKeyOptions.md +++ b/docs/interfaces/CommonPrimaryKeyOptions.md @@ -29,7 +29,7 @@ z.TypeOf.isAutoGenerated #### Defined in -[src/generator-options.ts:229](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L229) +[src/generator-options.ts:229](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L229) ___ @@ -45,4 +45,4 @@ z.TypeOf.name #### Defined in -[src/generator-options.ts:225](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L225) +[src/generator-options.ts:225](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L225) diff --git a/docs/interfaces/CommonTypeAdapterOptions.md b/docs/interfaces/CommonTypeAdapterOptions.md index 9c5e55d..43d6902 100644 --- a/docs/interfaces/CommonTypeAdapterOptions.md +++ b/docs/interfaces/CommonTypeAdapterOptions.md @@ -29,4 +29,6 @@ z.TypeOf.importPath #### Defined in -[src/generator-options.ts:201](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L201) +[src/generator-options.ts:201](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L201) + +[src/generator-options.ts:201](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L201) diff --git a/docs/interfaces/ExportOptions.md b/docs/interfaces/ExportOptions.md index 6e40a2c..682a94b 100644 --- a/docs/interfaces/ExportOptions.md +++ b/docs/interfaces/ExportOptions.md @@ -26,7 +26,7 @@ Additionally export the extracted columns (Useful for select * queries etc.) -Example: +Example: export const tUserCols = extractColumnsFrom(tUser) #### Inherited from @@ -35,7 +35,9 @@ z.TypeOf.extractedColumns #### Defined in -[src/generator-options.ts:90](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L90) +[src/generator-options.ts:90](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L90) + +[src/generator-options.ts:90](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L90) ___ @@ -68,7 +70,9 @@ z.TypeOf.rowTypes #### Defined in -[src/generator-options.ts:59](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L59) +[src/generator-options.ts:59](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L59) + +[src/generator-options.ts:59](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L59) ___ @@ -87,7 +91,9 @@ z.TypeOf.tableClasses #### Defined in -[src/generator-options.ts:36](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L36) +[src/generator-options.ts:36](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L36) + +[src/generator-options.ts:36](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L36) ___ @@ -108,7 +114,9 @@ z.TypeOf.tableInstances #### Defined in -[src/generator-options.ts:28](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L28) +[src/generator-options.ts:28](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L28) + +[src/generator-options.ts:28](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L28) ___ @@ -141,4 +149,6 @@ z.TypeOf.valuesTypes #### Defined in -[src/generator-options.ts:82](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L82) +[src/generator-options.ts:82](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L82) + +[src/generator-options.ts:82](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L82) diff --git a/docs/interfaces/FieldMapping.md b/docs/interfaces/FieldMapping.md index 08bab2f..75b2759 100644 --- a/docs/interfaces/FieldMapping.md +++ b/docs/interfaces/FieldMapping.md @@ -31,7 +31,7 @@ z.TypeOf.columnName #### Defined in -[src/field-mappings.ts:105](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L105) +[src/field-mappings.ts:105](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L105) ___ @@ -50,13 +50,13 @@ z.TypeOf.columnType #### Defined in -[src/field-mappings.ts:116](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L116) +[src/field-mappings.ts:116](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L116) ___ ### generatedField -• **generatedField**: ``false`` \| { `hasDefault`: `undefined` \| ``null`` \| `boolean` ; `isComputed`: `undefined` \| ``null`` \| `boolean` ; `isOptional`: `undefined` \| ``null`` \| `boolean` ; `name`: `undefined` \| ``null`` \| `string` ; `type`: `undefined` \| ``null`` \| { kind?: "custom" \| "customComparable" \| "enum" \| null \| undefined; dbType?: { name: string; } \| null \| undefined; tsType?: { importPath?: string \| null \| undefined; isDefault?: boolean \| null \| undefined; isRelative?: boolean \| ... 1 more ... \| undefined; name: string; } \| null \| undefined; adapter?: { ...; } \| ...... } +• **generatedField**: `Object` Can be used to customize the field name or type mapping in the generated field. @@ -69,7 +69,9 @@ z.TypeOf.generatedField #### Defined in -[src/field-mappings.ts:124](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L124) +[src/field-mappings.ts:124](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L124) + +[src/field-mappings.ts:124](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L124) ___ @@ -85,4 +87,4 @@ z.TypeOf.tableName #### Defined in -[src/field-mappings.ts:108](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L108) +[src/field-mappings.ts:108](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L108) diff --git a/docs/interfaces/GeneratedField.md b/docs/interfaces/GeneratedField.md index bb6be44..5398a4a 100644 --- a/docs/interfaces/GeneratedField.md +++ b/docs/interfaces/GeneratedField.md @@ -34,7 +34,7 @@ z.TypeOf.hasDefault #### Defined in -[src/field-mappings.ts:93](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L93) +[src/field-mappings.ts:93](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L93) ___ @@ -48,7 +48,7 @@ z.TypeOf.isComputed #### Defined in -[src/field-mappings.ts:91](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L91) +[src/field-mappings.ts:91](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L91) ___ @@ -62,7 +62,7 @@ z.TypeOf.isOptional #### Defined in -[src/field-mappings.ts:92](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L92) +[src/field-mappings.ts:92](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L92) ___ @@ -76,13 +76,13 @@ z.TypeOf.name #### Defined in -[src/field-mappings.ts:90](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L90) +[src/field-mappings.ts:90](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L90) ___ ### type -• **type**: `undefined` \| ``null`` \| { `adapter`: `undefined` \| ``null`` \| { importPath?: string \| null \| undefined; isDefault?: boolean \| null \| undefined; isRelative?: boolean \| null \| undefined; name: string; } ; `dbType`: `undefined` \| ``null`` \| { name: string; } ; `kind`: `undefined` \| ``null`` \| ``"custom"`` \| ``"customComparable"`` \| ``"enum"`` ; `tsType`: `undefined` \| ``null`` \| { importPath?: string \| null \| undefined; isDefault?: boolean \| null \| undefined; isRelative?: boolean \| null \| undefined; name: string; } } +• **type**: `undefined` \| ``null`` \| { `adapter`: `undefined` \| ``null`` \| { name: string; importPath?: string \| null \| undefined; isDefault?: boolean \| null \| undefined; isRelative?: boolean \| null \| undefined; } ; `dbType`: `undefined` \| ``null`` \| { name: string; } ; `kind`: `undefined` \| ``null`` \| ``"custom"`` \| ``"customComparable"`` \| ``"enum"`` ; `tsType`: `undefined` \| ``null`` \| { name: string; importPath?: string \| null \| undefined; isDefault?: boolean \| null \| undefined; isRelative?: boolean \| null \| undefined; } } #### Inherited from @@ -90,4 +90,4 @@ z.TypeOf.type #### Defined in -[src/field-mappings.ts:89](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L89) +[src/field-mappings.ts:89](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L89) diff --git a/docs/interfaces/GeneratedFieldType.md b/docs/interfaces/GeneratedFieldType.md index e37e2ea..cdf80cb 100644 --- a/docs/interfaces/GeneratedFieldType.md +++ b/docs/interfaces/GeneratedFieldType.md @@ -33,7 +33,7 @@ z.TypeOf.adapter #### Defined in -[src/field-mappings.ts:82](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L82) +[src/field-mappings.ts:82](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L82) ___ @@ -51,7 +51,7 @@ z.TypeOf.dbType #### Defined in -[src/field-mappings.ts:66](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L66) +[src/field-mappings.ts:66](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L66) ___ @@ -67,7 +67,7 @@ z.TypeOf.kind #### Defined in -[src/field-mappings.ts:60](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L60) +[src/field-mappings.ts:60](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L60) ___ @@ -87,4 +87,4 @@ z.TypeOf.tsType #### Defined in -[src/field-mappings.ts:75](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L75) +[src/field-mappings.ts:75](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L75) diff --git a/docs/interfaces/GeneratorOpts.md b/docs/interfaces/GeneratorOpts.md index c5f7fcb..0c26f9d 100644 --- a/docs/interfaces/GeneratorOpts.md +++ b/docs/interfaces/GeneratorOpts.md @@ -22,6 +22,7 @@ Generator options - [includeDBTypeWhenIsOptional](GeneratorOpts.md#includedbtypewhenisoptional) - [naming](GeneratorOpts.md#naming) - [outputDirPath](GeneratorOpts.md#outputdirpath) +- [removeExtraneous](GeneratorOpts.md#removeextraneous) - [schemaPath](GeneratorOpts.md#schemapath) - [tableMapping](GeneratorOpts.md#tablemapping) - [tables](GeneratorOpts.md#tables) @@ -43,7 +44,7 @@ z.TypeOf.common #### Defined in -[src/generator-options.ts:317](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L317) +[src/generator-options.ts:317](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L317) ___ @@ -59,7 +60,9 @@ z.TypeOf.connectionSourcePath #### Defined in -[src/generator-options.ts:271](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L271) +[src/generator-options.ts:271](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L271) + +[src/generator-options.ts:271](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L271) ___ @@ -75,7 +78,7 @@ z.TypeOf.dryRun #### Defined in -[src/generator-options.ts:262](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L262) +[src/generator-options.ts:262](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L262) ___ @@ -95,13 +98,13 @@ z.TypeOf.export #### Defined in -[src/generator-options.ts:309](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L309) +[src/generator-options.ts:309](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L309) ___ ### fieldMappings -• **fieldMappings**: `undefined` \| ``null`` \| { `columnName`: `undefined` \| ``null`` \| `string` \| `RegExp` ; `columnType`: `undefined` \| ``null`` \| `string` \| `RegExp` ; `generatedField`: ``false`` \| { type?: { kind?: "custom" \| "customComparable" \| "enum" \| null \| undefined; dbType?: { name: string; } \| null \| undefined; tsType?: { importPath?: string \| null \| undefined; isDefault?: boolean \| ... 1 more ... \| undefined; isRelative?: boolean \| ... 1 more ... \| undefined; name: string; } \| null \| undefined; adapt... ; `tableName`: `undefined` \| ``null`` \| `string` \| `RegExp` }[] +• **fieldMappings**: `undefined` \| ``null`` \| { `columnName`: `undefined` \| ``null`` \| `string` \| `RegExp` ; `columnType`: `undefined` \| ``null`` \| `string` \| `RegExp` ; `generatedField`: `Object` ; `tableName`: `undefined` \| ``null`` \| `string` \| `RegExp` }[] Customize how table columns are mapped to typescript fields @@ -115,7 +118,7 @@ z.TypeOf.fieldMappings #### Defined in -[src/generator-options.ts:287](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L287) +[src/generator-options.ts:287](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L287) ___ @@ -133,7 +136,7 @@ z.TypeOf.includeDBTypeWhenIsOptional #### Defined in -[src/generator-options.ts:331](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L331) +[src/generator-options.ts:331](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L331) ___ @@ -151,7 +154,7 @@ z.TypeOf.naming #### Defined in -[src/generator-options.ts:324](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L324) +[src/generator-options.ts:324](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L324) ___ @@ -167,7 +170,30 @@ z.TypeOf.outputDirPath #### Defined in -[src/generator-options.ts:277](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L277) +[src/generator-options.ts:277](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L277) + +[src/generator-options.ts:277](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L277) + +___ + +### removeExtraneous + +• **removeExtraneous**: `undefined` \| ``null`` \| ``"never"`` \| ``"interactively"`` \| ``"all"`` + +Remove extraneous files after code generation completes - this prevents you from +having to manually clean up files after eg. any table has been deleted, but it is +your responsibility to ensure that the outputDir used solely for files generated through +this utility and all files are written as part of single run. + +Defauls to retaining all extraneous files. + +#### Inherited from + +z.TypeOf.removeExtraneous + +#### Defined in + +[src/generator-options.ts:341](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L341) ___ @@ -183,7 +209,9 @@ z.TypeOf.schemaPath #### Defined in -[src/generator-options.ts:265](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L265) +[src/generator-options.ts:265](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L265) + +[src/generator-options.ts:265](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L265) ___ @@ -203,7 +231,7 @@ z.TypeOf.tableMapping #### Defined in -[src/generator-options.ts:294](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L294) +[src/generator-options.ts:294](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L294) ___ @@ -224,4 +252,4 @@ z.TypeOf.tables #### Defined in -[src/generator-options.ts:302](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L302) +[src/generator-options.ts:302](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L302) diff --git a/docs/interfaces/ImportedItem.md b/docs/interfaces/ImportedItem.md index 68958b4..25d5b2e 100644 --- a/docs/interfaces/ImportedItem.md +++ b/docs/interfaces/ImportedItem.md @@ -50,7 +50,7 @@ z.TypeOf.importPath #### Defined in -[src/field-mappings.ts:16](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L16) +[src/field-mappings.ts:16](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L16) ___ @@ -70,7 +70,7 @@ z.TypeOf.isDefault #### Defined in -[src/field-mappings.ts:23](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L23) +[src/field-mappings.ts:23](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L23) ___ @@ -90,7 +90,7 @@ z.TypeOf.isRelative #### Defined in -[src/field-mappings.ts:30](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L30) +[src/field-mappings.ts:30](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L30) ___ @@ -106,4 +106,6 @@ z.TypeOf.name #### Defined in -[src/field-mappings.ts:13](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/field-mappings.ts#L13) +[src/field-mappings.ts:13](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L13) + +[src/field-mappings.ts:13](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/field-mappings.ts#L13) diff --git a/docs/interfaces/TableInclusion.md b/docs/interfaces/TableInclusion.md index 85a0b52..34d26af 100644 --- a/docs/interfaces/TableInclusion.md +++ b/docs/interfaces/TableInclusion.md @@ -30,7 +30,7 @@ z.TypeOf.exclude #### Defined in -[src/generator-options.ts:14](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L14) +[src/generator-options.ts:14](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L14) ___ @@ -47,4 +47,4 @@ z.TypeOf.include #### Defined in -[src/generator-options.ts:9](https://github.com/lorefnon/ts-sql-codegen/blob/d38c7e4/src/generator-options.ts#L9) +[src/generator-options.ts:9](https://github.com/lorefnon/ts-sql-codegen/blob/fc68de2/src/generator-options.ts#L9) diff --git a/package.json b/package.json index 195665c..eddd758 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "build:docs": "typedoc --readme none src/index.ts", "copy:templates": "recursive-copy -w src dist -f \"*.hbs\"", "clean": "rimraf dist test/generated", - "test": "mocha -r ts-node/register -r mocha-snap \"./test/**/*.ts\"" + "test": "mocha -r ts-node/register -r mocha-snap --extensions ts,js \"./test/**/*.ts\"" }, "files": [ "dist/**/*" @@ -32,22 +32,24 @@ "license": "MIT", "devDependencies": { "@types/fs-extra": "^11.0.1", + "@types/glob": "^8.1.0", "@types/js-yaml": "^4.0.5", "@types/lodash": "^4.14.191", "@types/minimist": "^1.2.2", "@types/mocha": "^10.0.1", - "@types/node": "^18.11.19", + "@types/node": "^18.15.0", "@types/pg": "^8.6.6", + "@types/prompts": "^2.4.2", "@types/rimraf": "^3.0.2", - "better-sqlite3": "^8.0.1", + "better-sqlite3": "^8.2.0", "mocha": "^10.2.0", "mocha-snap": "^4.3.0", - "pg": "^8.9.0", + "pg": "^8.10.0", "recursive-copy-cli": "^1.0.20", - "rimraf": "^4.1.2", + "rimraf": "^4.4.0", "ts-node": "^10.9.1", - "ts-sql-query": "^1.48.0", - "typedoc": "^0.23.24", + "ts-sql-query": "^1.50.0", + "typedoc": "^0.23.26", "typedoc-plugin-markdown": "^3.14.0", "typescript": "^4.9.5" }, @@ -56,12 +58,14 @@ }, "dependencies": { "fs-extra": "^11.1.0", + "glob": "^9.2.1", "handlebars": "^4.7.7", "hbs-dedent-helper": "^0.3.0", "js-yaml": "^4.1.0", "lodash": "^4.17.21", - "minimist": "^1.2.7", - "ts-pattern": "^4.1.3", - "zod": "^3.20.2" + "minimist": "^1.2.8", + "prompts": "^2.4.2", + "ts-pattern": "^4.2.1", + "zod": "^3.21.4" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ceb4408..124f075 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2,62 +2,70 @@ lockfileVersion: 5.4 specifiers: '@types/fs-extra': ^11.0.1 + '@types/glob': ^8.1.0 '@types/js-yaml': ^4.0.5 '@types/lodash': ^4.14.191 '@types/minimist': ^1.2.2 '@types/mocha': ^10.0.1 - '@types/node': ^18.11.19 + '@types/node': ^18.15.0 '@types/pg': ^8.6.6 + '@types/prompts': ^2.4.2 '@types/rimraf': ^3.0.2 - better-sqlite3: ^8.0.1 + better-sqlite3: ^8.2.0 fs-extra: ^11.1.0 + glob: ^9.2.1 handlebars: ^4.7.7 hbs-dedent-helper: ^0.3.0 js-yaml: ^4.1.0 lodash: ^4.17.21 - minimist: ^1.2.7 + minimist: ^1.2.8 mocha: ^10.2.0 mocha-snap: ^4.3.0 - pg: ^8.9.0 + pg: ^8.10.0 + prompts: ^2.4.2 recursive-copy-cli: ^1.0.20 - rimraf: ^4.1.2 + rimraf: ^4.4.0 ts-node: ^10.9.1 - ts-pattern: ^4.1.3 - ts-sql-query: ^1.48.0 - typedoc: ^0.23.24 + ts-pattern: ^4.2.1 + ts-sql-query: ^1.50.0 + typedoc: ^0.23.26 typedoc-plugin-markdown: ^3.14.0 typescript: ^4.9.5 - zod: ^3.20.2 + zod: ^3.21.4 dependencies: fs-extra: 11.1.0 + glob: 9.2.1 handlebars: 4.7.7 hbs-dedent-helper: 0.3.0_handlebars@4.7.7 js-yaml: 4.1.0 lodash: 4.17.21 - minimist: 1.2.7 - ts-pattern: 4.1.3 - zod: 3.20.2 + minimist: 1.2.8 + prompts: 2.4.2 + ts-pattern: 4.2.1 + zod: 3.21.4 devDependencies: '@types/fs-extra': 11.0.1 + '@types/glob': 8.1.0 '@types/js-yaml': 4.0.5 '@types/lodash': 4.14.191 '@types/minimist': 1.2.2 '@types/mocha': 10.0.1 - '@types/node': 18.11.19 + '@types/node': 18.15.0 '@types/pg': 8.6.6 + '@types/prompts': 2.4.2 '@types/rimraf': 3.0.2 - better-sqlite3: 8.0.1 + better-sqlite3: 8.2.0 mocha: 10.2.0 mocha-snap: 4.3.0 - pg: 8.9.0 + pg: 8.10.0 recursive-copy-cli: 1.0.20 - rimraf: 4.1.2 - ts-node: 10.9.1_qqdszkrtcshgbphghj7vnvrrby - ts-sql-query: 1.48.0 - typedoc: 0.23.24_typescript@4.9.5 - typedoc-plugin-markdown: 3.14.0_typedoc@0.23.24 + rimraf: 4.4.0 + ts-node: 10.9.1_lwgqdwokjtwlohdqtbb6s252kq + ts-sql-query: 1.50.0 + typedoc: 0.23.26_typescript@4.9.5 + typedoc-plugin-markdown: 3.14.0_typedoc@0.23.26 typescript: 4.9.5 packages: @@ -69,20 +77,20 @@ packages: '@jridgewell/trace-mapping': 0.3.9 dev: true - /@jridgewell/resolve-uri/3.0.7: - resolution: {integrity: sha512-8cXDaBBHOr2pQ7j77Y6Vp5VDT2sIqWyWQ56TjEq4ih/a4iST3dItRe8Q9fp0rrIl9DoKhWQtUQz/YpOxLkXbNA==} + /@jridgewell/resolve-uri/3.1.0: + resolution: {integrity: sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==} engines: {node: '>=6.0.0'} dev: true - /@jridgewell/sourcemap-codec/1.4.13: - resolution: {integrity: sha512-GryiOJmNcWbovBxTfZSF71V/mXbgcV3MewDe3kIMCLyIh5e7SKAeUZs+rMnJ8jkMolZ/4/VsdBmMrw3l+VdZ3w==} + /@jridgewell/sourcemap-codec/1.4.14: + resolution: {integrity: sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==} dev: true /@jridgewell/trace-mapping/0.3.9: resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==} dependencies: - '@jridgewell/resolve-uri': 3.0.7 - '@jridgewell/sourcemap-codec': 1.4.13 + '@jridgewell/resolve-uri': 3.1.0 + '@jridgewell/sourcemap-codec': 1.4.14 dev: true /@nodelib/fs.scandir/2.1.5: @@ -106,34 +114,34 @@ packages: fastq: 1.13.0 dev: true - /@tsconfig/node10/1.0.8: - resolution: {integrity: sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==} + /@tsconfig/node10/1.0.9: + resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==} dev: true - /@tsconfig/node12/1.0.9: - resolution: {integrity: sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw==} + /@tsconfig/node12/1.0.11: + resolution: {integrity: sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==} dev: true - /@tsconfig/node14/1.0.1: - resolution: {integrity: sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg==} + /@tsconfig/node14/1.0.3: + resolution: {integrity: sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==} dev: true - /@tsconfig/node16/1.0.2: - resolution: {integrity: sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==} + /@tsconfig/node16/1.0.3: + resolution: {integrity: sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==} dev: true /@types/fs-extra/11.0.1: resolution: {integrity: sha512-MxObHvNl4A69ofaTRU8DFqvgzzv8s9yRtaPPm5gud9HDNvpB3GPQFvNuTWAI59B9huVGV5jXYJwbCsmBsOGYWA==} dependencies: '@types/jsonfile': 6.1.1 - '@types/node': 18.11.19 + '@types/node': 18.15.0 dev: true - /@types/glob/7.2.0: - resolution: {integrity: sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==} + /@types/glob/8.1.0: + resolution: {integrity: sha512-IO+MJPVhoqz+28h1qLAcBEH2+xHMK6MTyHJc7MTnnYb6wsoLR29POVGJ7LycmVXIqyy/4/2ShP5sUwTXuOwb/w==} dependencies: - '@types/minimatch': 3.0.5 - '@types/node': 18.11.19 + '@types/minimatch': 5.1.2 + '@types/node': 18.15.0 dev: true /@types/js-yaml/4.0.5: @@ -143,15 +151,15 @@ packages: /@types/jsonfile/6.1.1: resolution: {integrity: sha512-GSgiRCVeapDN+3pqA35IkQwasaCh/0YFH5dEF6S88iDvEn901DjOeH3/QPY+XYP1DFzDZPvIvfeEgk+7br5png==} dependencies: - '@types/node': 18.11.19 + '@types/node': 18.15.0 dev: true /@types/lodash/4.14.191: resolution: {integrity: sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==} dev: true - /@types/minimatch/3.0.5: - resolution: {integrity: sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==} + /@types/minimatch/5.1.2: + resolution: {integrity: sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==} dev: true /@types/minimist/1.2.2: @@ -162,23 +170,30 @@ packages: resolution: {integrity: sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==} dev: true - /@types/node/18.11.19: - resolution: {integrity: sha512-YUgMWAQBWLObABqrvx8qKO1enAvBUdjZOAWQ5grBAkp5LQv45jBvYKZ3oFS9iKRCQyFjqw6iuEa1vmFqtxYLZw==} + /@types/node/18.15.0: + resolution: {integrity: sha512-z6nr0TTEOBGkzLGmbypWOGnpSpSIBorEhC4L+4HeQ2iezKCi4f77kyslRwvHeNitymGQ+oFyIWGP96l/DPSV9w==} dev: true /@types/pg/8.6.6: resolution: {integrity: sha512-O2xNmXebtwVekJDD+02udOncjVcMZQuTEQEMpKJ0ZRf5E7/9JJX3izhKUcUifBkyKpljyUM6BTgy2trmviKlpw==} dependencies: - '@types/node': 18.11.19 + '@types/node': 18.15.0 pg-protocol: 1.5.0 pg-types: 2.2.0 dev: true + /@types/prompts/2.4.2: + resolution: {integrity: sha512-TwNx7qsjvRIUv/BCx583tqF5IINEVjCNqg9ofKHRlSoUHE62WBHrem4B1HGXcIrG511v29d1kJ9a/t2Esz7MIg==} + dependencies: + '@types/node': 18.15.0 + kleur: 3.0.3 + dev: true + /@types/rimraf/3.0.2: resolution: {integrity: sha512-F3OznnSLAUxFrCEu/L5PY8+ny8DtcFRjx7fZZ9bycvXRi3KPTRS9HOitGZwvPg0juRhXFWIeKX58cnX5YqLohQ==} dependencies: - '@types/glob': 7.2.0 - '@types/node': 18.11.19 + '@types/glob': 8.1.0 + '@types/node': 18.15.0 dev: true /acorn-walk/8.2.0: @@ -186,8 +201,8 @@ packages: engines: {node: '>=0.4.0'} dev: true - /acorn/8.7.1: - resolution: {integrity: sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==} + /acorn/8.8.2: + resolution: {integrity: sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==} engines: {node: '>=0.4.0'} hasBin: true dev: true @@ -202,6 +217,10 @@ packages: engines: {node: '>=8'} dev: true + /ansi-sequence-parser/1.1.0: + resolution: {integrity: sha512-lEm8mt52to2fT8GhciPCGeCXACSz2UwIN4X2e2LJSnZ5uAbn2/dsYdOmUXq0AtWS5cpAupysIneExOgH0Vd2TQ==} + dev: true + /ansi-styles/4.3.0: resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} engines: {node: '>=8'} @@ -209,8 +228,8 @@ packages: color-convert: 2.0.1 dev: true - /anymatch/3.1.2: - resolution: {integrity: sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==} + /anymatch/3.1.3: + resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==} engines: {node: '>= 8'} dependencies: normalize-path: 3.0.0 @@ -252,14 +271,13 @@ packages: /balanced-match/1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} - dev: true /base64-js/1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} dev: true - /better-sqlite3/8.0.1: - resolution: {integrity: sha512-JhTZjpyapA1icCEjIZB4TSSgkGdFgpWZA2Wszg7Cf4JwJwKQmbvuNnJBeR+EYG/Z29OXvR4G//Rbg31BW/Z7Yg==} + /better-sqlite3/8.2.0: + resolution: {integrity: sha512-8eTzxGk9535SB3oSNu0tQ6I4ZffjVCBUjKHN9QeeIFtphBX0sEd0NxAuglBNR9TO5ThnxBB7GqzfcYo9kjadJQ==} requiresBuild: true dependencies: bindings: 1.5.0 @@ -296,7 +314,6 @@ packages: resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} dependencies: balanced-match: 1.0.2 - dev: true /braces/3.0.2: resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==} @@ -342,7 +359,7 @@ packages: resolution: {integrity: sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==} engines: {node: '>= 8.10.0'} dependencies: - anymatch: 3.1.2 + anymatch: 3.1.3 braces: 3.0.2 glob-parent: 5.1.2 is-binary-path: 2.1.0 @@ -517,7 +534,6 @@ packages: /fs.realpath/1.0.0: resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==} - dev: true /fsevents/2.3.2: resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==} @@ -554,6 +570,15 @@ packages: path-is-absolute: 1.0.1 dev: true + /glob/9.2.1: + resolution: {integrity: sha512-Pxxgq3W0HyA3XUvSXcFhRSs+43Jsx0ddxcFrbjxNGkL2Ak5BAUBxLqI5G6ADDeCHLfzzXFhe0b1yYcctGmytMA==} + engines: {node: '>=16 || 14 >=14.17'} + dependencies: + fs.realpath: 1.0.0 + minimatch: 7.4.2 + minipass: 4.2.4 + path-scurry: 1.6.1 + /graceful-fs/4.2.10: resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==} @@ -562,7 +587,7 @@ packages: engines: {node: '>=0.4.7'} hasBin: true dependencies: - minimist: 1.2.7 + minimist: 1.2.8 neo-async: 2.6.2 source-map: 0.6.1 wordwrap: 1.0.0 @@ -582,7 +607,7 @@ packages: handlebars: 4.7.7 lodash.isempty: 4.4.0 lodash.repeat: 4.1.0 - ts-pattern: 4.1.3 + ts-pattern: 4.2.1 dev: false /he/1.2.0: @@ -677,6 +702,10 @@ packages: engines: {node: '>=0.10.0'} dev: true + /kleur/3.0.3: + resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} + engines: {node: '>=6'} + /locate-path/6.0.0: resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==} engines: {node: '>=10'} @@ -710,6 +739,10 @@ packages: yallist: 4.0.0 dev: true + /lru-cache/7.18.3: + resolution: {integrity: sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==} + engines: {node: '>=12'} + /lunr/2.3.9: resolution: {integrity: sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==} dev: true @@ -765,15 +798,18 @@ packages: brace-expansion: 2.0.1 dev: true - /minimatch/5.1.6: - resolution: {integrity: sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==} + /minimatch/7.4.2: + resolution: {integrity: sha512-xy4q7wou3vUoC9k1xGTXc+awNdGaGVHtFUaey8tiX4H1QRc04DZ/rmDFwNm2EBsuYEhAZ6SgMmYf3InGY6OauA==} engines: {node: '>=10'} dependencies: brace-expansion: 2.0.1 - dev: true - /minimist/1.2.7: - resolution: {integrity: sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==} + /minimist/1.2.8: + resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} + + /minipass/4.2.4: + resolution: {integrity: sha512-lwycX3cBMTvcejsHITUgYj6Gy6A7Nh4Q6h9NP4sTHY1ccJlC7yKzDmiShEHsJ16Jf1nKGDEaiHxiltsJEvk0nQ==} + engines: {node: '>=8'} /mkdirp-classic/0.5.3: resolution: {integrity: sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==} @@ -783,7 +819,7 @@ packages: resolution: {integrity: sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==} hasBin: true dependencies: - minimist: 1.2.7 + minimist: 1.2.8 dev: true /mocha-snap/4.3.0: @@ -895,6 +931,13 @@ packages: resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} dev: true + /path-scurry/1.6.1: + resolution: {integrity: sha512-OW+5s+7cw6253Q4E+8qQ/u1fVvcJQCJo/VFD8pje+dbJCF1n5ZRMV2AEHbGp+5Q7jxQIYJxkHopnj6nzdGeZLA==} + engines: {node: '>=14'} + dependencies: + lru-cache: 7.18.3 + minipass: 4.2.4 + /pg-connection-string/2.5.0: resolution: {integrity: sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ==} dev: true @@ -904,12 +947,12 @@ packages: engines: {node: '>=4.0.0'} dev: true - /pg-pool/3.5.2_pg@8.9.0: - resolution: {integrity: sha512-His3Fh17Z4eg7oANLob6ZvH8xIVen3phEZh2QuyrIl4dQSDVEabNducv6ysROKpDNPSD+12tONZVWfSgMvDD9w==} + /pg-pool/3.6.0_pg@8.10.0: + resolution: {integrity: sha512-clFRf2ksqd+F497kWFyM21tMjeikn60oGDmqMT8UBrynEwVEX/5R5xd2sdvdo1cZCFlguORNpVuqxIj+aK4cfQ==} peerDependencies: pg: '>=8.0' dependencies: - pg: 8.9.0 + pg: 8.10.0 dev: true /pg-protocol/1.5.0: @@ -931,8 +974,8 @@ packages: postgres-interval: 1.2.0 dev: true - /pg/8.9.0: - resolution: {integrity: sha512-ZJM+qkEbtOHRuXjmvBtOgNOXOtLSbxiMiUVMgE4rV6Zwocy03RicCVvDXgx8l4Biwo8/qORUnEqn2fdQzV7KCg==} + /pg/8.10.0: + resolution: {integrity: sha512-ke7o7qSTMb47iwzOSaZMfeR7xToFdkE71ifIipOAAaLIM0DYzfOAXlgFFmYUIE2BcJtvnVlGCID84ZzCegE8CQ==} engines: {node: '>= 8.0.0'} peerDependencies: pg-native: '>=3.0.1' @@ -943,7 +986,7 @@ packages: buffer-writer: 2.0.0 packet-reader: 1.0.0 pg-connection-string: 2.5.0 - pg-pool: 3.5.2_pg@8.9.0 + pg-pool: 3.6.0_pg@8.10.0 pg-protocol: 1.6.0 pg-types: 2.2.0 pgpass: 1.0.5 @@ -995,7 +1038,7 @@ packages: detect-libc: 2.0.1 expand-template: 2.0.3 github-from-package: 0.0.0 - minimist: 1.2.7 + minimist: 1.2.8 mkdirp-classic: 0.5.3 napi-build-utils: 1.0.2 node-abi: 3.22.0 @@ -1012,6 +1055,14 @@ packages: asap: 2.0.6 dev: true + /prompts/2.4.2: + resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==} + engines: {node: '>= 6'} + dependencies: + kleur: 3.0.3 + sisteransi: 1.0.5 + dev: false + /prr/1.0.1: resolution: {integrity: sha512-yPw4Sng1gWghHQWj0B3ZggWUm4qVbPwPFcRG8KyxiU7J2OHFSoEHKS+EZ3fv5l1t9CyCiop6l/ZYeWbrgoQejw==} dev: true @@ -1039,7 +1090,7 @@ packages: dependencies: deep-extend: 0.6.0 ini: 1.3.8 - minimist: 1.2.7 + minimist: 1.2.8 strip-json-comments: 2.0.1 dev: true @@ -1117,10 +1168,12 @@ packages: glob: 7.2.0 dev: true - /rimraf/4.1.2: - resolution: {integrity: sha512-BlIbgFryTbw3Dz6hyoWFhKk+unCcHMSkZGrTFVAx2WmttdBSonsdtRlwiuTbDqTKr+UlXIUqJVS4QT5tUzGENQ==} + /rimraf/4.4.0: + resolution: {integrity: sha512-X36S+qpCUR0HjXlkDe4NAOhS//aHH0Z+h8Ckf2auGJk3PTnx5rLmrHkwNdbVQuCSUhOyFrlRvFEllZOYE+yZGQ==} engines: {node: '>=14'} hasBin: true + dependencies: + glob: 9.2.1 dev: true /run-parallel/1.2.0: @@ -1147,9 +1200,10 @@ packages: randombytes: 2.1.0 dev: true - /shiki/0.12.1: - resolution: {integrity: sha512-aieaV1m349rZINEBkjxh2QbBvFFQOlgqYTNtCal82hHj4dDZ76oMlQIX+C7ryerBTDiga3e5NfH6smjdJ02BbQ==} + /shiki/0.14.1: + resolution: {integrity: sha512-+Jz4nBkCBe0mEDqo1eKRcCdjRtrCjozmcbTUjbPTX7OOJfEbTZzlUWlZtGe3Gb5oV1/jnojhG//YZc3rs9zSEw==} dependencies: + ansi-sequence-parser: 1.1.0 jsonc-parser: 3.2.0 vscode-oniguruma: 1.7.0 vscode-textmate: 8.0.0 @@ -1167,6 +1221,10 @@ packages: simple-concat: 1.0.1 dev: true + /sisteransi/1.0.5: + resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} + dev: false + /slash/1.0.0: resolution: {integrity: sha512-3TYDR7xWt4dIqV2JauJr+EJeW356RXijHeUlO+8djJ+uBXPn8/2dpzBc8yQhh583sVvc9CvFAeQVgijsH+PNNg==} engines: {node: '>=0.10.0'} @@ -1258,7 +1316,7 @@ packages: resolution: {integrity: sha512-4+uTpL5eqo/xfYdclDF43IPuflNqzysBH7LJ4ohufjZZAtnEPSS0GOszPEQS1+lg5rXujhAqQ1lAnF6QPCcz5Q==} dev: true - /ts-node/10.9.1_qqdszkrtcshgbphghj7vnvrrby: + /ts-node/10.9.1_lwgqdwokjtwlohdqtbb6s252kq: resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true peerDependencies: @@ -1273,12 +1331,12 @@ packages: optional: true dependencies: '@cspotcode/source-map-support': 0.8.1 - '@tsconfig/node10': 1.0.8 - '@tsconfig/node12': 1.0.9 - '@tsconfig/node14': 1.0.1 - '@tsconfig/node16': 1.0.2 - '@types/node': 18.11.19 - acorn: 8.7.1 + '@tsconfig/node10': 1.0.9 + '@tsconfig/node12': 1.0.11 + '@tsconfig/node14': 1.0.3 + '@tsconfig/node16': 1.0.3 + '@types/node': 18.15.0 + acorn: 8.8.2 acorn-walk: 8.2.0 arg: 4.1.3 create-require: 1.1.1 @@ -1289,12 +1347,12 @@ packages: yn: 3.1.1 dev: true - /ts-pattern/4.1.3: - resolution: {integrity: sha512-8beXMWTGEv1JfDjSxfNhe4uT5jKYdhmEUKzt4gZW9dmHlquq3b+IbEyA7vX9LjBfzHmvKnM4HiomAUCyaW2Pew==} + /ts-pattern/4.2.1: + resolution: {integrity: sha512-lXCmHZb01QOM9HdCLvisCGUH9ATdKPON9UaUvwe007gJAhuSBhRWIAIowys5QqNxEq6odWctfMIdI96vzjnOMQ==} dev: false - /ts-sql-query/1.48.0: - resolution: {integrity: sha512-URTdjHukD6UC6WQPpc3/Bl34bj9eS14of/LzCStbvqDKpPWwNl3j2yu/NvyniHRX3uxgAxwnkv/EQwhGjLvYlw==} + /ts-sql-query/1.50.0: + resolution: {integrity: sha512-WypR5K6kZkrNb5ggKPyCsggVNfM7dFlufG6iJVb+Yb+C7Uj3IOGKpXlLjOY3AmNuza+akNU0zbi1A8TjA02ypw==} dependencies: chained-error: 1.0.0 ts-extended-types: 1.1.0 @@ -1306,17 +1364,17 @@ packages: safe-buffer: 5.2.1 dev: true - /typedoc-plugin-markdown/3.14.0_typedoc@0.23.24: + /typedoc-plugin-markdown/3.14.0_typedoc@0.23.26: resolution: {integrity: sha512-UyQLkLRkfTFhLdhSf3RRpA3nNInGn+k6sll2vRXjflaMNwQAAiB61SYbisNZTg16t4K1dt1bPQMMGLrxS0GZ0Q==} peerDependencies: typedoc: '>=0.23.0' dependencies: handlebars: 4.7.7 - typedoc: 0.23.24_typescript@4.9.5 + typedoc: 0.23.26_typescript@4.9.5 dev: true - /typedoc/0.23.24_typescript@4.9.5: - resolution: {integrity: sha512-bfmy8lNQh+WrPYcJbtjQ6JEEsVl/ce1ZIXyXhyW+a1vFrjO39t6J8sL/d6FfAGrJTc7McCXgk9AanYBSNvLdIA==} + /typedoc/0.23.26_typescript@4.9.5: + resolution: {integrity: sha512-5m4KwR5tOLnk0OtMaRn9IdbeRM32uPemN9kur7YK9wFqx8U0CYrvO9aVq6ysdZSV1c824BTm+BuQl2Ze/k1HtA==} engines: {node: '>= 14.14'} hasBin: true peerDependencies: @@ -1324,8 +1382,8 @@ packages: dependencies: lunr: 2.3.9 marked: 4.2.12 - minimatch: 5.1.6 - shiki: 0.12.1 + minimatch: 7.4.2 + shiki: 0.14.1 typescript: 4.9.5 dev: true @@ -1348,7 +1406,7 @@ packages: dev: false /util-deprecate/1.0.2: - resolution: {integrity: sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=} + resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} dev: true /v8-compile-cache-lib/3.0.1: @@ -1453,6 +1511,6 @@ packages: engines: {node: '>=10'} dev: true - /zod/3.20.2: - resolution: {integrity: sha512-1MzNQdAvO+54H+EaK5YpyEy0T+Ejo/7YLHS93G3RnYWh5gaotGHwGeN/ZO687qEDU2y4CdStQYXVHIgrUl5UVQ==} + /zod/3.21.4: + resolution: {integrity: sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==} dev: false diff --git a/src/cli.ts b/src/cli.ts index 38b1e9c..1664398 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -30,6 +30,7 @@ async function main() { schemaPath: argv["schema"] ?? argv["s"], connectionSourcePath: argv["connection-source"] ?? argv["c"], outputDirPath: argv["output-dir"] ?? argv["o"], + removeExtraneous: argv["remove-extraneous"] ?? "never" }); await generator.generate(); } diff --git a/src/file-remover.ts b/src/file-remover.ts new file mode 100644 index 0000000..75075f4 --- /dev/null +++ b/src/file-remover.ts @@ -0,0 +1,53 @@ +import fs from "fs-extra"; +import { glob } from "glob"; +import path from "path/posix"; +import prompts from "prompts"; +import { GeneratorOpts } from "./generator-options"; + +export class FileRemover { + constructor(private opts: GeneratorOpts, private writtenFiles: Set) { } + public async removeExtraneousFiles() { + if (!this.opts.removeExtraneous || this.opts.removeExtraneous === 'never') { + return; + } + const paths = await glob('*', { + cwd: path.resolve(this.opts.outputDirPath) + }); + const extraneousPaths = paths.filter(p => !this.writtenFiles.has(p)) + if (!extraneousPaths.length) { + return + } + let pathsToDelete: string[] = [] + if (this.opts.removeExtraneous === 'all') { + pathsToDelete = extraneousPaths + } + else if (this.opts.removeExtraneous === 'interactively') { + const { selection } = await prompts({ + type: 'select', + name: 'selection', + message: `${extraneousPaths.length} extraneous files found after code generation. Select ones to delete:`, + choices: [ + { title: 'All', value: '$all' }, + { title: 'None', value: '$none' }, + { title: 'Select Individually', value: '$pick' } + ] + }) + switch (selection) { + case '$all': { + pathsToDelete = extraneousPaths + } + case '$pick': { + const { candidates } = await prompts({ + type: 'multiselect', + name: 'candidates', + message: `Select files to delete:`, + choices: extraneousPaths.map(value => ({ title: value, value })), + hint: '- Space to select. Return to submit' + }) + pathsToDelete.push(...candidates) + } + } + } + await Promise.all(pathsToDelete.map(fs.remove)) + } +} \ No newline at end of file diff --git a/src/generator-options.ts b/src/generator-options.ts index 63ca19a..d8e2638 100644 --- a/src/generator-options.ts +++ b/src/generator-options.ts @@ -84,7 +84,7 @@ export const ExportOptionsSchema = z.object({ /** * Additionally export the extracted columns (Useful for select * queries etc.) * - * Example: + * Example: * export const tUserCols = extractColumnsFrom(tUser) */ extractedColumns: z.boolean().default(false) @@ -318,17 +318,31 @@ export const GeneratorOptsSchema = z.object({ /** * Customize the naming rules of the generated items - * + * * See NamingOptions */ naming: NamingOptionsSchema.partial().nullish(), - /** + /** * The fields marked as "custom", "customComparable" or "enum" receive a second generic * argument that need to be the same of the db type in the database or redefined for the field * If you set to true this property that second generic argument will be generated. */ includeDBTypeWhenIsOptional: z.boolean().nullish(), + + /** + * Remove extraneous files after code generation completes - this prevents you from + * having to manually clean up files after eg. any table has been deleted, but it is + * your responsibility to ensure that the outputDir used solely for files generated through + * this utility and all files are written as part of single run. + * + * Defauls to retaining all extraneous files. + */ + removeExtraneous: z.enum([ + 'never', + 'interactively', + 'all' + ]).nullish() }); /** diff --git a/src/generator.ts b/src/generator.ts index e408279..8cc0ebb 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -2,17 +2,19 @@ import fs from "fs-extra"; import Handlebars from "handlebars"; import { register } from "hbs-dedent-helper"; import yaml from "js-yaml"; +import { camelCase, isEmpty, last, memoize, upperFirst } from "lodash"; import path from "path/posix"; -import { camelCase, memoize, upperFirst, last, isEmpty } from "lodash"; -import { GeneratorOpts, GeneratorOptsSchema, NamingOptions, NamingOptionsSchema } from "./generator-options"; +import { match } from "ts-pattern"; import { fieldMappings, GeneratedField, GeneratedFieldType, - ImportedItem, + ImportedItem } from "./field-mappings"; +import { FileRemover } from "./file-remover"; +import { GeneratorOpts, GeneratorOptsSchema, NamingOptions, NamingOptionsSchema } from "./generator-options"; +import { doesMatchNameOrPattern } from "./matcher"; import { Column, Table, TblsSchema } from "./tbls-types"; -import { match } from "ts-pattern"; type Logger = Record< "debug" | "info" | "warn" | "error", @@ -70,6 +72,8 @@ interface ImportTmplInput { export class Generator { protected opts: GeneratorOpts; protected naming: NamingOptions; + + private writtenFiles = new Set() public logger: Logger = console; constructor(opts: GeneratorOpts) { @@ -103,6 +107,7 @@ export class Generator { } }) ); + await new FileRemover(this.opts, this.writtenFiles).removeExtraneousFiles() } protected shouldProcess(table: Table) { @@ -125,7 +130,6 @@ export class Generator { } return true; } - protected getTableKind(table: Table): TableKind | null { return match(table.type.toLowerCase()) .with("base table", () => "Table" as const) @@ -252,6 +256,7 @@ export class Generator { this.logger.info("---"); } else { this.logger.info(`Writing ${filePath}`); + this.writtenFiles.add(filePath); await fs.writeFile(filePath, output); } } @@ -575,25 +580,5 @@ export class Generator { } } -const doesMatchNameOrPattern = ( - matcher: undefined | null | string | RegExp, - target: string -) => { - if (matcher == null) return true; - if (typeof matcher === "string") { - const matcherParts = matcher.split("."); - const targetParts = target.split("."); - for (let i = 0; i < matcherParts.length; i++) { - if ( - targetParts[targetParts.length - 1 - i] !== - matcherParts[matcherParts.length - 1 - i] - ) { - return false; - } - } - return true; - } - return target.match(matcher); -}; type TableKind = "Table" | "View" \ No newline at end of file diff --git a/src/matcher.ts b/src/matcher.ts new file mode 100644 index 0000000..574e21d --- /dev/null +++ b/src/matcher.ts @@ -0,0 +1,20 @@ +export const doesMatchNameOrPattern = ( + matcher: undefined | null | string | RegExp, + target: string +) => { + if (matcher == null) return true; + if (typeof matcher === "string") { + const matcherParts = matcher.split("."); + const targetParts = target.split("."); + for (let i = 0; i < matcherParts.length; i++) { + if ( + targetParts[targetParts.length - 1 - i] !== + matcherParts[matcherParts.length - 1 - i] + ) { + return false; + } + } + return true; + } + return target.match(matcher); +}; diff --git a/test/test.ts b/test/test.ts index 103226c..2725c90 100644 --- a/test/test.ts +++ b/test/test.ts @@ -44,13 +44,20 @@ const fieldMappings: FieldMapping[] = [ }, ]; -describe("Generator", () => { + +describe("Generator", function () { + this.timeout(10_1000) + beforeEach(async () => { await fs.remove(outputDirPath); }); afterEach(async () => { - await fs.remove(outputDirPath); + try { + await fs.remove(outputDirPath); + } catch (e) { + console.error(e) + } }); [undefined, true, false].forEach((useQualifiedTableName) => { @@ -61,7 +68,7 @@ describe("Generator", () => { outputDirPath, fieldMappings, tableMapping: useQualifiedTableName ? { - useQualifiedTableName + useQualifiedTableName } : undefined }); await generator.generate(); @@ -72,10 +79,10 @@ describe("Generator", () => { .transaction(async () => { // prettier-ignore // @ts-ignore - const { AuthorsTable } = await import( "./generated/AuthorsTable"); + const { AuthorsTable } = await import("./generated/AuthorsTable"); // prettier-ignore // @ts-ignore - const { BooksTable } = await import( "./generated/BooksTable"); + const { BooksTable } = await import("./generated/BooksTable"); const authorsTable = new AuthorsTable(); const { id } = await conn .insertInto(authorsTable) @@ -97,10 +104,10 @@ describe("Generator", () => { .executeInsert(); // prettier-ignore // @ts-ignore - const { AuthorBooksTable } = await import( "./generated/AuthorBooksTable"); + const { AuthorBooksTable } = await import("./generated/AuthorBooksTable"); // prettier-ignore // @ts-ignore - const { ChaptersTable } = await import( "./generated/ChaptersTable"); + const { ChaptersTable } = await import("./generated/ChaptersTable"); const authorBooksTable = new AuthorBooksTable(); const authorBooks = await conn .selectFrom(authorBooksTable) @@ -238,6 +245,29 @@ describe("Generator", () => { await snap(await readAllGenerated()); }); + it.only("supports removal of extraneous files", async () => { + const exPath = path.resolve(path.join(outputDirPath, 'test.md')) + await fs.ensureDir(path.dirname(exPath)) + await fs.writeFile(exPath, 'test') + const generator = new Generator({ + schemaPath, + connectionSourcePath, + outputDirPath, + tables: { + include: ["authors"], + }, + export: { + rowTypes: true + }, + removeExtraneous: 'all' + }); + await generator.generate().catch(e => { + console.error(e) + }); + const doesExist = await fs.exists(exPath) + assert(!doesExist, 'Extraneous file should not exist after generation') + }) + it("allows non-relative and default import paths", async () => { const generator = new Generator({ schemaPath, @@ -446,7 +476,7 @@ describe("Generator", () => { await generator.generate(); await snap(await readAllGenerated()); }); - + it("custom comparable field with db type name", async () => { const generator = new Generator({ schemaPath, diff --git a/tsconfig.json b/tsconfig.json index 96db274..6e7ed31 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -101,4 +101,7 @@ "skipLibCheck": true /* Skip type checking all .d.ts files. */ }, "include": ["./src/**/*.ts"], + "ts-node": { + "transpileOnly": true + } }