@databases/pg-config
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -15,2 +15,22 @@ "use strict"; | ||
pgUser: 'test-user' | ||
}, | ||
types: { | ||
directory: '__generated__', | ||
domainFileName: '_custom_types.ts', | ||
domainTypeMode: 'loose_brand', | ||
domainTypeName: '{{ TYPE_NAME | pascal-case }}', | ||
enumFileName: '_enums.ts', | ||
enumTypeMode: 'union_alias', | ||
enumTypeName: '{{ TYPE_NAME | pascal-case }}', | ||
primaryKeyFileName: '{{ TABLE_NAME }}.ts', | ||
primaryKeyTypeMode: 'inline_loose_brand', | ||
primaryKeyTypeName: '{{ TABLE_NAME | pascal-case }}_{{ COLUMN_NAME | pascal-case }}', | ||
schemaFileName: 'index.ts', | ||
schemaTypeName: 'DatabaseSchema', | ||
tableFileName: '{{ TABLE_NAME }}.ts', | ||
tableInsertParametersFileName: '{{ TABLE_NAME }}.ts', | ||
tableInsertParametersTypeName: '{{ TABLE_NAME | pascal-case }}_InsertParameters', | ||
tableTypeName: '{{ TABLE_NAME | pascal-case }}', | ||
columnTypeOverrides: {}, | ||
typeOverrides: {} | ||
} | ||
@@ -20,3 +40,3 @@ }); | ||
test('valid config', () => { | ||
expect(__1._testReadPgConfigSync(__dirname + '/fixtures/empty.json')).toEqual({ | ||
expect(__1.readPgConfigSync(__dirname + '/fixtures/empty.json')).toEqual({ | ||
connectionStringEnvironmentVariable: 'DATABASE_URL', | ||
@@ -30,5 +50,25 @@ test: { | ||
pgUser: 'test-user' | ||
}, | ||
types: { | ||
directory: '__generated__', | ||
domainFileName: '_custom_types.ts', | ||
domainTypeMode: 'loose_brand', | ||
domainTypeName: '{{ TYPE_NAME | pascal-case }}', | ||
enumFileName: '_enums.ts', | ||
enumTypeMode: 'union_alias', | ||
enumTypeName: '{{ TYPE_NAME | pascal-case }}', | ||
primaryKeyFileName: '{{ TABLE_NAME }}.ts', | ||
primaryKeyTypeMode: 'inline_loose_brand', | ||
primaryKeyTypeName: '{{ TABLE_NAME | pascal-case }}_{{ COLUMN_NAME | pascal-case }}', | ||
schemaFileName: 'index.ts', | ||
schemaTypeName: 'DatabaseSchema', | ||
tableFileName: '{{ TABLE_NAME }}.ts', | ||
tableInsertParametersFileName: '{{ TABLE_NAME }}.ts', | ||
tableInsertParametersTypeName: '{{ TABLE_NAME | pascal-case }}_InsertParameters', | ||
tableTypeName: '{{ TABLE_NAME | pascal-case }}', | ||
columnTypeOverrides: {}, | ||
typeOverrides: {} | ||
} | ||
}); | ||
expect(__1._testReadPgConfigSync(__dirname + '/fixtures/override.json')).toEqual({ | ||
expect(__1.readPgConfigSync(__dirname + '/fixtures/override.json')).toEqual({ | ||
connectionStringEnvironmentVariable: 'PG_CONNECTION', | ||
@@ -42,2 +82,26 @@ test: { | ||
pgUser: 'test-user' | ||
}, | ||
types: { | ||
directory: '__generated__', | ||
domainFileName: '_custom_types.ts', | ||
domainTypeMode: 'loose_brand', | ||
domainTypeName: '{{ TYPE_NAME | pascal-case }}', | ||
enumFileName: '_enums.ts', | ||
enumTypeMode: 'union_alias', | ||
enumTypeName: '{{ TYPE_NAME | pascal-case }}', | ||
primaryKeyFileName: '{{ TABLE_NAME }}.ts', | ||
primaryKeyTypeMode: 'inline_loose_brand', | ||
primaryKeyTypeName: '{{ TABLE_NAME | pascal-case }}_{{ COLUMN_NAME | pascal-case }}', | ||
schemaFileName: 'index.ts', | ||
schemaTypeName: 'DatabaseSchema', | ||
tableFileName: '{{ TABLE_NAME }}.ts', | ||
tableInsertParametersFileName: '{{ TABLE_NAME }}.ts', | ||
tableInsertParametersTypeName: '{{ TABLE_NAME | pascal-case }}_InsertParameters', | ||
tableTypeName: '{{ TABLE_NAME | pascal-case }}', | ||
columnTypeOverrides: { | ||
'my_table.my_column': "string & {__brand?: 'email'}" | ||
}, | ||
typeOverrides: { | ||
'114': 'unknown' | ||
} | ||
} | ||
@@ -47,4 +111,4 @@ }); | ||
test('invalid config', () => { | ||
expect(() => __1._testReadPgConfigSync(__dirname + '/fixtures/invalid.json')).toThrowError(/PgConfig.connectionStringEnvironmentVariable should be string/); | ||
expect(() => __1.readPgConfigSync(__dirname + '/fixtures/invalid.json')).toThrowError(/PgConfig.connectionStringEnvironmentVariable should be string/); | ||
}); | ||
//# sourceMappingURL=index.test.js.map |
import { PgConfig } from './PgConfig.validator'; | ||
export declare function getPgConfig(searchFrom?: string): Promise<PgConfig>; | ||
export declare function getPgConfigSync(searchFrom?: string): PgConfig; | ||
export declare function _testReadPgConfigSync(filename: string): PgConfig; | ||
export declare function readPgConfigSync(filename: string): PgConfig; | ||
export declare const DEFAULT_CONFIG: PgConfig; | ||
export default PgConfig; |
@@ -44,9 +44,10 @@ "use strict"; | ||
exports.getPgConfigSync = getPgConfigSync; | ||
function _testReadPgConfigSync(filename) { | ||
function readPgConfigSync(filename) { | ||
return parseResult(explorer.loadSync(filename)); | ||
} | ||
exports._testReadPgConfigSync = _testReadPgConfigSync; | ||
exports.readPgConfigSync = readPgConfigSync; | ||
function parseResult(result) { | ||
return PgConfig_validator_1.default(result ? result.config : {}); | ||
} | ||
exports.DEFAULT_CONFIG = PgConfig_validator_1.default({}); | ||
//# sourceMappingURL=index.js.map |
@@ -59,2 +59,124 @@ export interface TestConfig { | ||
} | ||
export interface TypesConfig { | ||
/** | ||
* The directory (relative to this config) to put the generated code in | ||
* | ||
* @default "__generated__" | ||
*/ | ||
directory: string; | ||
/** | ||
* What should be generated for custom types with constraints? | ||
* | ||
* @default "loose_brand" | ||
*/ | ||
domainTypeMode: 'strict_brand' | 'loose_brand' | 'alias' | 'inline'; | ||
/** | ||
* What should custom types be called (ignored for domainTypeMode="inline") | ||
* | ||
* @default "{{ TYPE_NAME | pascal-case }}" | ||
*/ | ||
domainTypeName: string; | ||
/** | ||
* Where should generated types for domains be put (ignored for domainTypeMode="inline") | ||
* | ||
* @default "_custom_types.ts" | ||
*/ | ||
domainFileName: string; | ||
/** | ||
* How should Postgres enums be represented in TypeScript? | ||
* | ||
* @default "union_alias" | ||
*/ | ||
enumTypeMode: 'enum' | 'union_alias' | 'union_alias_with_object' | 'inline'; | ||
/** | ||
* What should enums be called (ignored for enumTypeMode="inline") | ||
* | ||
* @default "{{ TYPE_NAME | pascal-case }}" | ||
*/ | ||
enumTypeName: string; | ||
/** | ||
* Where should generated types for enums be put (ignored for enumTypeMode="inline") | ||
* | ||
* @default "_enums.ts" | ||
*/ | ||
enumFileName: string; | ||
/** | ||
* Do you want to use branded types for primary keys? | ||
* | ||
* @default "inline_loose_brand" | ||
*/ | ||
primaryKeyTypeMode: 'strict_brand' | 'loose_brand' | 'inline_strict_brand' | 'inline_loose_brand' | 'inline_no_brand'; | ||
/** | ||
* What should types for primary keys be called (ignored for primaryKeyMode="inline_*") | ||
* | ||
* @default "{{ TABLE_NAME | pascal-case }}_{{ COLUMN_NAME | pascal-case }}" | ||
*/ | ||
primaryKeyTypeName: string; | ||
/** | ||
* Where should generated types for primary keys be put (ignored for primaryKeyMode="inline") | ||
* | ||
* @default "{{ TABLE_NAME }}.ts" | ||
*/ | ||
primaryKeyFileName: string; | ||
/** | ||
* What should TypeScript types for table records be called | ||
* | ||
* @default "{{ TABLE_NAME | pascal-case }}" | ||
*/ | ||
tableTypeName: string; | ||
/** | ||
* What filename do you want to use for tables | ||
* | ||
* @default "{{ TABLE_NAME }}.ts" | ||
*/ | ||
tableFileName: string; | ||
/** | ||
* What should TypeScript types for table insert parameters be called | ||
* | ||
* @default "{{ TABLE_NAME | pascal-case }}_InsertParameters" | ||
*/ | ||
tableInsertParametersTypeName: string; | ||
/** | ||
* What filename do you want to use for tables insert parameters | ||
* | ||
* @default "{{ TABLE_NAME }}.ts" | ||
*/ | ||
tableInsertParametersFileName: string; | ||
/** | ||
* What should the main generated "schema" type be called | ||
* | ||
* @default "DatabaseSchema" | ||
*/ | ||
schemaTypeName: string; | ||
/** | ||
* What filename do you want to use for the main generated "schema" type | ||
* | ||
* @default "index.ts" | ||
*/ | ||
schemaFileName: string; | ||
/** | ||
* Override column types for some columns. The name can be either: | ||
* | ||
* - "table_name.column_name" | ||
* - "schema_name.table_name.column_name" | ||
* | ||
* @default {} | ||
*/ | ||
columnTypeOverrides: { | ||
[name: string]: string; | ||
}; | ||
/** | ||
* Override generated TypeScript types for some types. The name can be either: | ||
* | ||
* - key of @databases/pg-data-type-id (e.g. "json") | ||
* - value of @databases/pg-data-type-id (e.g. 114) | ||
* - "custom_type_name" | ||
* - "schema_name.custom_type_name" | ||
* | ||
* @default {} | ||
*/ | ||
typeOverrides: { | ||
[name: string]: string; | ||
}; | ||
} | ||
interface PgConfig { | ||
@@ -69,2 +191,6 @@ /** | ||
/** | ||
* The directory containing migrations (when using @databases/pg-migrations) | ||
*/ | ||
migrationsDirectory?: string; | ||
/** | ||
* Config for pg-test | ||
@@ -75,3 +201,9 @@ * | ||
test: TestConfig; | ||
/** | ||
* Config for pg-schema-print-types | ||
* | ||
* @default {} | ||
*/ | ||
types: TypesConfig; | ||
} | ||
export default PgConfig; |
@@ -65,2 +65,110 @@ import Ajv = require('ajv'); | ||
}; | ||
TypesConfig: { | ||
defaultProperties: never[]; | ||
properties: { | ||
columnTypeOverrides: { | ||
additionalProperties: { | ||
type: string; | ||
}; | ||
default: {}; | ||
defaultProperties: never[]; | ||
description: string; | ||
type: string; | ||
}; | ||
directory: { | ||
default: string; | ||
description: string; | ||
type: string; | ||
}; | ||
domainFileName: { | ||
default: string; | ||
description: string; | ||
type: string; | ||
}; | ||
domainTypeMode: { | ||
default: string; | ||
description: string; | ||
enum: string[]; | ||
type: string; | ||
}; | ||
domainTypeName: { | ||
default: string; | ||
description: string; | ||
type: string; | ||
}; | ||
enumFileName: { | ||
default: string; | ||
description: string; | ||
type: string; | ||
}; | ||
enumTypeMode: { | ||
default: string; | ||
description: string; | ||
enum: string[]; | ||
type: string; | ||
}; | ||
enumTypeName: { | ||
default: string; | ||
description: string; | ||
type: string; | ||
}; | ||
primaryKeyFileName: { | ||
default: string; | ||
description: string; | ||
type: string; | ||
}; | ||
primaryKeyTypeMode: { | ||
default: string; | ||
description: string; | ||
enum: string[]; | ||
type: string; | ||
}; | ||
primaryKeyTypeName: { | ||
default: string; | ||
description: string; | ||
type: string; | ||
}; | ||
schemaFileName: { | ||
default: string; | ||
description: string; | ||
type: string; | ||
}; | ||
schemaTypeName: { | ||
default: string; | ||
description: string; | ||
type: string; | ||
}; | ||
tableFileName: { | ||
default: string; | ||
description: string; | ||
type: string; | ||
}; | ||
tableInsertParametersFileName: { | ||
default: string; | ||
description: string; | ||
type: string; | ||
}; | ||
tableInsertParametersTypeName: { | ||
default: string; | ||
description: string; | ||
type: string; | ||
}; | ||
tableTypeName: { | ||
default: string; | ||
description: string; | ||
type: string; | ||
}; | ||
typeOverrides: { | ||
additionalProperties: { | ||
type: string; | ||
}; | ||
default: {}; | ||
defaultProperties: never[]; | ||
description: string; | ||
type: string; | ||
}; | ||
}; | ||
required: string[]; | ||
type: string; | ||
}; | ||
}; | ||
@@ -73,2 +181,6 @@ properties: { | ||
}; | ||
migrationsDirectory: { | ||
description: string; | ||
type: string; | ||
}; | ||
test: { | ||
@@ -79,2 +191,7 @@ $ref: string; | ||
}; | ||
types: { | ||
$ref: string; | ||
default: {}; | ||
description: string; | ||
}; | ||
}; | ||
@@ -81,0 +198,0 @@ required: string[]; |
@@ -74,2 +74,110 @@ "use strict"; | ||
type: 'object' | ||
}, | ||
TypesConfig: { | ||
defaultProperties: [], | ||
properties: { | ||
columnTypeOverrides: { | ||
additionalProperties: { | ||
type: 'string' | ||
}, | ||
default: {}, | ||
defaultProperties: [], | ||
description: 'Override column types for some columns. The name can be either:\n\n- "table_name.column_name"\n- "schema_name.table_name.column_name"', | ||
type: 'object' | ||
}, | ||
directory: { | ||
default: '__generated__', | ||
description: 'The directory (relative to this config) to put the generated code in', | ||
type: 'string' | ||
}, | ||
domainFileName: { | ||
default: '_custom_types.ts', | ||
description: 'Where should generated types for domains be put (ignored for domainTypeMode="inline")', | ||
type: 'string' | ||
}, | ||
domainTypeMode: { | ||
default: 'loose_brand', | ||
description: 'What should be generated for custom types with constraints?', | ||
enum: ['alias', 'inline', 'loose_brand', 'strict_brand'], | ||
type: 'string' | ||
}, | ||
domainTypeName: { | ||
default: '{{ TYPE_NAME | pascal-case }}', | ||
description: 'What should custom types be called (ignored for domainTypeMode="inline")', | ||
type: 'string' | ||
}, | ||
enumFileName: { | ||
default: '_enums.ts', | ||
description: 'Where should generated types for enums be put (ignored for enumTypeMode="inline")', | ||
type: 'string' | ||
}, | ||
enumTypeMode: { | ||
default: 'union_alias', | ||
description: 'How should Postgres enums be represented in TypeScript?', | ||
enum: ['enum', 'inline', 'union_alias', 'union_alias_with_object'], | ||
type: 'string' | ||
}, | ||
enumTypeName: { | ||
default: '{{ TYPE_NAME | pascal-case }}', | ||
description: 'What should enums be called (ignored for enumTypeMode="inline")', | ||
type: 'string' | ||
}, | ||
primaryKeyFileName: { | ||
default: '{{ TABLE_NAME }}.ts', | ||
description: 'Where should generated types for primary keys be put (ignored for primaryKeyMode="inline")', | ||
type: 'string' | ||
}, | ||
primaryKeyTypeMode: { | ||
default: 'inline_loose_brand', | ||
description: 'Do you want to use branded types for primary keys?', | ||
enum: ['inline_loose_brand', 'inline_no_brand', 'inline_strict_brand', 'loose_brand', 'strict_brand'], | ||
type: 'string' | ||
}, | ||
primaryKeyTypeName: { | ||
default: '{{ TABLE_NAME | pascal-case }}_{{ COLUMN_NAME | pascal-case }}', | ||
description: 'What should types for primary keys be called (ignored for primaryKeyMode="inline_*")', | ||
type: 'string' | ||
}, | ||
schemaFileName: { | ||
default: 'index.ts', | ||
description: 'What filename do you want to use for the main generated "schema" type', | ||
type: 'string' | ||
}, | ||
schemaTypeName: { | ||
default: 'DatabaseSchema', | ||
description: 'What should the main generated "schema" type be called', | ||
type: 'string' | ||
}, | ||
tableFileName: { | ||
default: '{{ TABLE_NAME }}.ts', | ||
description: 'What filename do you want to use for tables', | ||
type: 'string' | ||
}, | ||
tableInsertParametersFileName: { | ||
default: '{{ TABLE_NAME }}.ts', | ||
description: 'What filename do you want to use for tables insert parameters', | ||
type: 'string' | ||
}, | ||
tableInsertParametersTypeName: { | ||
default: '{{ TABLE_NAME | pascal-case }}_InsertParameters', | ||
description: 'What should TypeScript types for table insert parameters be called', | ||
type: 'string' | ||
}, | ||
tableTypeName: { | ||
default: '{{ TABLE_NAME | pascal-case }}', | ||
description: 'What should TypeScript types for table records be called', | ||
type: 'string' | ||
}, | ||
typeOverrides: { | ||
additionalProperties: { | ||
type: 'string' | ||
}, | ||
default: {}, | ||
defaultProperties: [], | ||
description: 'Override generated TypeScript types for some types. The name can be either:\n\n- key of @databases/pg-data-type-id (e.g. "json")\n- value of @databases/pg-data-type-id (e.g. 114)\n- "custom_type_name"\n- "schema_name.custom_type_name"', | ||
type: 'object' | ||
} | ||
}, | ||
required: ['columnTypeOverrides', 'directory', 'domainFileName', 'domainTypeMode', 'domainTypeName', 'enumFileName', 'enumTypeMode', 'enumTypeName', 'primaryKeyFileName', 'primaryKeyTypeMode', 'primaryKeyTypeName', 'schemaFileName', 'schemaTypeName', 'tableFileName', 'tableInsertParametersFileName', 'tableInsertParametersTypeName', 'tableTypeName', 'typeOverrides'], | ||
type: 'object' | ||
} | ||
@@ -83,2 +191,6 @@ }, | ||
}, | ||
migrationsDirectory: { | ||
description: 'The directory containing migrations (when using @databases/pg-migrations)', | ||
type: 'string' | ||
}, | ||
test: { | ||
@@ -88,5 +200,10 @@ $ref: '#/definitions/TestConfig', | ||
description: 'Config for pg-test' | ||
}, | ||
types: { | ||
$ref: '#/definitions/TypesConfig', | ||
default: {}, | ||
description: 'Config for pg-schema-print-types' | ||
} | ||
}, | ||
required: ['connectionStringEnvironmentVariable', 'test'], | ||
required: ['connectionStringEnvironmentVariable', 'test', 'types'], | ||
type: 'object' | ||
@@ -93,0 +210,0 @@ }; |
{ | ||
"name": "@databases/pg-config", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38176
787