@contember/schema-utils 1.3.0-alpha.7 → 1.3.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/SchemaDatabaseMetadata.d.ts +40 -0
- package/dist/src/SchemaDatabaseMetadata.d.ts.map +1 -0
- package/dist/src/SchemaDatabaseMetadata.js +20 -0
- package/dist/src/SchemaDatabaseMetadata.js.map +1 -0
- package/dist/src/definition-generator/DefinitionCodeGenerator.d.ts.map +1 -1
- package/dist/src/definition-generator/DefinitionCodeGenerator.js +4 -12
- package/dist/src/definition-generator/DefinitionCodeGenerator.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/lax/LaxSchemaConverter.js +2 -2
- package/dist/src/model/index.d.ts +0 -1
- package/dist/src/model/index.d.ts.map +1 -1
- package/dist/src/model/index.js +0 -1
- package/dist/src/model/index.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/type-schema/model.d.ts +4 -6
- package/dist/src/type-schema/model.d.ts.map +1 -1
- package/dist/src/type-schema/model.js +5 -6
- package/dist/src/type-schema/model.js.map +1 -1
- package/dist/src/validation/ModelValidator.d.ts.map +1 -1
- package/dist/src/validation/ModelValidator.js +2 -28
- package/dist/src/validation/ModelValidator.js.map +1 -1
- package/dist/tests/cases/unit/modelValidator.test.js +6 -72
- package/dist/tests/cases/unit/modelValidator.test.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -6
- package/src/SchemaDatabaseMetadata.ts +66 -0
- package/src/definition-generator/DefinitionCodeGenerator.ts +5 -14
- package/src/index.ts +1 -0
- package/src/lax/LaxSchemaConverter.ts +2 -2
- package/src/model/index.ts +0 -1
- package/src/type-schema/model.ts +20 -8
- package/src/validation/ModelValidator.ts +2 -26
- package/tests/cases/unit/__snapshots__/laxSchemaConverter.test.ts.snap +14 -14
- package/tests/cases/unit/modelValidator.test.ts +6 -73
- package/dist/src/model/NamingHelper.d.ts +0 -9
- package/dist/src/model/NamingHelper.d.ts.map +0 -1
- package/dist/src/model/NamingHelper.js +0 -44
- package/dist/src/model/NamingHelper.js.map +0 -1
- package/src/model/NamingHelper.ts +0 -41
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export type GetForeignKeyConstraintNameArgs = {
|
|
2
|
+
fromTable: string
|
|
3
|
+
fromColumn: string
|
|
4
|
+
toTable: string
|
|
5
|
+
toColumn: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type GetUniqueConstraintNameArgs = {
|
|
9
|
+
tableName: string
|
|
10
|
+
columnNames: string[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type GetIndexNameArgs = {
|
|
14
|
+
tableName: string
|
|
15
|
+
columnNames: string[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IndexMetadata {
|
|
19
|
+
indexName: string
|
|
20
|
+
tableName: string
|
|
21
|
+
columnNames: string[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface UniqueConstraintMetadata {
|
|
25
|
+
constraintName: string
|
|
26
|
+
tableName: string
|
|
27
|
+
columnNames: string[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ForeignKeyConstraintMetadata {
|
|
31
|
+
constraintName: string
|
|
32
|
+
fromTable: string
|
|
33
|
+
fromColumn: string
|
|
34
|
+
toTable: string
|
|
35
|
+
toColumn: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface SchemaDatabaseMetadata {
|
|
39
|
+
getUniqueConstraint(tableName: string, constraintName: string): UniqueConstraintMetadata | null
|
|
40
|
+
|
|
41
|
+
getForeignKeyConstraint(tableName: string, constraintName: string): ForeignKeyConstraintMetadata | null
|
|
42
|
+
|
|
43
|
+
getForeignKeyConstraintNames({ fromTable, fromColumn, toTable, toColumn }: GetForeignKeyConstraintNameArgs): string[]
|
|
44
|
+
|
|
45
|
+
getUniqueConstraintNames({ tableName, columnNames }: GetUniqueConstraintNameArgs): string[]
|
|
46
|
+
|
|
47
|
+
getIndexNames({ tableName, columnNames }: GetIndexNameArgs): string[]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
export const dummySchemaDatabaseMetadata: SchemaDatabaseMetadata = {
|
|
52
|
+
getForeignKeyConstraint(): ForeignKeyConstraintMetadata | null {
|
|
53
|
+
return null
|
|
54
|
+
}, getUniqueConstraint(): UniqueConstraintMetadata | null {
|
|
55
|
+
return null
|
|
56
|
+
},
|
|
57
|
+
getForeignKeyConstraintNames: ({ toColumn, toTable, fromColumn, fromTable }) => {
|
|
58
|
+
return [`fk_${fromTable}_${fromColumn}_${toTable}_${toColumn}`]
|
|
59
|
+
},
|
|
60
|
+
getUniqueConstraintNames: ({ columnNames, tableName }) => {
|
|
61
|
+
return [`uniq_${tableName}_${columnNames.join('_')}`]
|
|
62
|
+
},
|
|
63
|
+
getIndexNames: ({ columnNames, tableName }) => {
|
|
64
|
+
return [`idx_${tableName}_${columnNames.join('_')}`]
|
|
65
|
+
},
|
|
66
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Model, Schema, Writable } from '@contember/schema'
|
|
2
2
|
import {
|
|
3
3
|
acceptFieldVisitor,
|
|
4
4
|
DefaultNamingConventions,
|
|
5
5
|
isInverseRelation,
|
|
6
6
|
NamingConventions,
|
|
7
|
-
NamingHelper,
|
|
8
7
|
resolveDefaultColumnType,
|
|
9
8
|
} from '../model'
|
|
10
9
|
import { printJsValue } from '../utils/printJsValue'
|
|
@@ -57,21 +56,13 @@ ${Object.values(entity.fields).map(field => this.generateField({ field, entity,
|
|
|
57
56
|
entity: Model.Entity
|
|
58
57
|
constraint: Model.UniqueConstraint
|
|
59
58
|
}): string {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const fieldsList = `${constraint.fields.map(it => printJsValue(it)).join(', ')}`
|
|
63
|
-
return `@def.Unique(${fieldsList})`
|
|
64
|
-
}
|
|
65
|
-
return `@def.Unique(${printJsValue(constraint)})`
|
|
59
|
+
const fieldsList = `${constraint.fields.map(it => printJsValue(it)).join(', ')}`
|
|
60
|
+
return `@def.Unique(${fieldsList})`
|
|
66
61
|
}
|
|
67
62
|
|
|
68
63
|
private generateIndex({ entity, index }: { entity: Model.Entity; index: Model.Index }): string {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const fieldsList = `${index.fields.map(it => printJsValue(it)).join(', ')}`
|
|
72
|
-
return `@def.Index(${fieldsList})`
|
|
73
|
-
}
|
|
74
|
-
return `@def.Index(${printJsValue(index)})`
|
|
64
|
+
const fieldsList = `${index.fields.map(it => printJsValue(it)).join(', ')}`
|
|
65
|
+
return `@def.Index(${fieldsList})`
|
|
75
66
|
}
|
|
76
67
|
|
|
77
68
|
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { aclSchema, modelSchema, validationSchema, settingsSchema } from './type
|
|
|
5
5
|
import { actionsSchema } from './type-schema/actions'
|
|
6
6
|
|
|
7
7
|
export * from './definition-generator'
|
|
8
|
+
export * from './SchemaDatabaseMetadata'
|
|
8
9
|
export * from './lax'
|
|
9
10
|
export * from './model'
|
|
10
11
|
export * from './acl'
|
|
@@ -192,8 +192,8 @@ class LaxSchemaBuilder {
|
|
|
192
192
|
private getEntity(entityName: string): Model.Entity {
|
|
193
193
|
return this.entities[entityName] ??= {
|
|
194
194
|
name: entityName,
|
|
195
|
-
unique:
|
|
196
|
-
indexes:
|
|
195
|
+
unique: [],
|
|
196
|
+
indexes: [],
|
|
197
197
|
primary: 'id',
|
|
198
198
|
primaryColumn: 'id',
|
|
199
199
|
tableName: this.conventions.getTableName(entityName),
|
package/src/model/index.ts
CHANGED
package/src/type-schema/model.ts
CHANGED
|
@@ -148,10 +148,22 @@ const viewSchemaCheck: Typesafe.Equals<Model.View, ReturnType<typeof viewSchemaI
|
|
|
148
148
|
const viewSchema: Typesafe.Type<Model.View> = viewSchemaInner
|
|
149
149
|
|
|
150
150
|
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
})
|
|
151
|
+
const indexLike: Typesafe.Type<{readonly fields: readonly string[]; readonly name?: string | undefined}> = Typesafe.intersection(
|
|
152
|
+
Typesafe.object({
|
|
153
|
+
fields: Typesafe.array(Typesafe.string),
|
|
154
|
+
}),
|
|
155
|
+
Typesafe.partial({
|
|
156
|
+
name: Typesafe.string,
|
|
157
|
+
}),
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
const indexesSchema = Typesafe.coalesce<Model.Indexes, Model.Indexes>(
|
|
161
|
+
Typesafe.preprocess(
|
|
162
|
+
Typesafe.array(indexLike),
|
|
163
|
+
it => it?.constructor === Object ? Object.values(it) : it,
|
|
164
|
+
),
|
|
165
|
+
[],
|
|
166
|
+
)
|
|
155
167
|
|
|
156
168
|
const entitySchema = Typesafe.intersection(
|
|
157
169
|
Typesafe.object({
|
|
@@ -160,10 +172,10 @@ const entitySchema = Typesafe.intersection(
|
|
|
160
172
|
primaryColumn: Typesafe.string,
|
|
161
173
|
tableName: Typesafe.string,
|
|
162
174
|
fields: Typesafe.record(Typesafe.string, fieldSchema),
|
|
163
|
-
unique: Typesafe.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
175
|
+
unique: Typesafe.preprocess(
|
|
176
|
+
Typesafe.array(indexLike),
|
|
177
|
+
it => it?.constructor === Object ? Object.values(it) : it,
|
|
178
|
+
),
|
|
167
179
|
indexes: indexesSchema,
|
|
168
180
|
eventLog: eventLogSchema,
|
|
169
181
|
}),
|
|
@@ -54,15 +54,10 @@ export class ModelValidator {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
private validateUniqueConstraints(uniqueConstraints: Model.Entity['unique'], fields: Set<string>, errors: ErrorBuilder): void {
|
|
57
|
-
for (const
|
|
58
|
-
const uniqueErrors = errors.for(constraintName)
|
|
59
|
-
if (constraint.name !== constraintName) {
|
|
60
|
-
uniqueErrors.add('MODEL_NAME_MISMATCH', `Constraint name ${constraint.name} does not match the name in a map "${constraintName}"`)
|
|
61
|
-
continue
|
|
62
|
-
}
|
|
57
|
+
for (const constraint of uniqueConstraints) {
|
|
63
58
|
for (const field of constraint.fields) {
|
|
64
59
|
if (!fields.has(field)) {
|
|
65
|
-
|
|
60
|
+
errors.add('MODEL_UNDEFINED_FIELD', `Referenced field ${field} in a constraint does not exists`)
|
|
66
61
|
}
|
|
67
62
|
}
|
|
68
63
|
}
|
|
@@ -266,25 +261,6 @@ export class ModelValidator {
|
|
|
266
261
|
visitManyHasOne: () => { },
|
|
267
262
|
})
|
|
268
263
|
}
|
|
269
|
-
for (const entity of entities) {
|
|
270
|
-
const entityErrorBuilder = errorBuilder.for(entity.name)
|
|
271
|
-
for (const index of Object.values(entity.indexes)) {
|
|
272
|
-
const description = `index name ${index.name} of entity ${entity.name}`
|
|
273
|
-
if (relationNames[index.name]) {
|
|
274
|
-
entityErrorBuilder.add('MODEL_NAME_COLLISION', `${description} collides with ${relationNames[index.name]}`)
|
|
275
|
-
} else {
|
|
276
|
-
relationNames[index.name] = description
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
for (const unique of Object.values(entity.unique)) {
|
|
280
|
-
const description = `unique index name ${unique.name} of entity ${entity.name}`
|
|
281
|
-
if (relationNames[unique.name]) {
|
|
282
|
-
entityErrorBuilder.add('MODEL_NAME_COLLISION', `${description} collides with ${relationNames[unique.name]}`)
|
|
283
|
-
} else {
|
|
284
|
-
relationNames[unique.name] = description
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
264
|
}
|
|
289
265
|
}
|
|
290
266
|
|
|
@@ -45,12 +45,12 @@ exports[`lax schema converter basic 1`] = `
|
|
|
45
45
|
"type": "String",
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
|
-
"indexes":
|
|
48
|
+
"indexes": [],
|
|
49
49
|
"name": "Article",
|
|
50
50
|
"primary": "id",
|
|
51
51
|
"primaryColumn": "id",
|
|
52
52
|
"tableName": "article",
|
|
53
|
-
"unique":
|
|
53
|
+
"unique": [],
|
|
54
54
|
},
|
|
55
55
|
},
|
|
56
56
|
"enums": {
|
|
@@ -117,12 +117,12 @@ exports[`lax schema converter many-has-many 1`] = `
|
|
|
117
117
|
"type": "String",
|
|
118
118
|
},
|
|
119
119
|
},
|
|
120
|
-
"indexes":
|
|
120
|
+
"indexes": [],
|
|
121
121
|
"name": "Article",
|
|
122
122
|
"primary": "id",
|
|
123
123
|
"primaryColumn": "id",
|
|
124
124
|
"tableName": "article",
|
|
125
|
-
"unique":
|
|
125
|
+
"unique": [],
|
|
126
126
|
},
|
|
127
127
|
"Tag": {
|
|
128
128
|
"eventLog": {
|
|
@@ -143,12 +143,12 @@ exports[`lax schema converter many-has-many 1`] = `
|
|
|
143
143
|
"type": "Uuid",
|
|
144
144
|
},
|
|
145
145
|
},
|
|
146
|
-
"indexes":
|
|
146
|
+
"indexes": [],
|
|
147
147
|
"name": "Tag",
|
|
148
148
|
"primary": "id",
|
|
149
149
|
"primaryColumn": "id",
|
|
150
150
|
"tableName": "tag",
|
|
151
|
-
"unique":
|
|
151
|
+
"unique": [],
|
|
152
152
|
},
|
|
153
153
|
},
|
|
154
154
|
"enums": {},
|
|
@@ -200,12 +200,12 @@ exports[`lax schema converter one-has-many 1`] = `
|
|
|
200
200
|
"type": "String",
|
|
201
201
|
},
|
|
202
202
|
},
|
|
203
|
-
"indexes":
|
|
203
|
+
"indexes": [],
|
|
204
204
|
"name": "Article",
|
|
205
205
|
"primary": "id",
|
|
206
206
|
"primaryColumn": "id",
|
|
207
207
|
"tableName": "article",
|
|
208
|
-
"unique":
|
|
208
|
+
"unique": [],
|
|
209
209
|
},
|
|
210
210
|
"Category": {
|
|
211
211
|
"eventLog": {
|
|
@@ -226,12 +226,12 @@ exports[`lax schema converter one-has-many 1`] = `
|
|
|
226
226
|
"type": "Uuid",
|
|
227
227
|
},
|
|
228
228
|
},
|
|
229
|
-
"indexes":
|
|
229
|
+
"indexes": [],
|
|
230
230
|
"name": "Category",
|
|
231
231
|
"primary": "id",
|
|
232
232
|
"primaryColumn": "id",
|
|
233
233
|
"tableName": "category",
|
|
234
|
-
"unique":
|
|
234
|
+
"unique": [],
|
|
235
235
|
},
|
|
236
236
|
},
|
|
237
237
|
"enums": {},
|
|
@@ -283,12 +283,12 @@ exports[`lax schema converter one-has-one 1`] = `
|
|
|
283
283
|
"type": "String",
|
|
284
284
|
},
|
|
285
285
|
},
|
|
286
|
-
"indexes":
|
|
286
|
+
"indexes": [],
|
|
287
287
|
"name": "Article",
|
|
288
288
|
"primary": "id",
|
|
289
289
|
"primaryColumn": "id",
|
|
290
290
|
"tableName": "article",
|
|
291
|
-
"unique":
|
|
291
|
+
"unique": [],
|
|
292
292
|
},
|
|
293
293
|
"Content": {
|
|
294
294
|
"eventLog": {
|
|
@@ -310,12 +310,12 @@ exports[`lax schema converter one-has-one 1`] = `
|
|
|
310
310
|
"type": "Uuid",
|
|
311
311
|
},
|
|
312
312
|
},
|
|
313
|
-
"indexes":
|
|
313
|
+
"indexes": [],
|
|
314
314
|
"name": "Content",
|
|
315
315
|
"primary": "id",
|
|
316
316
|
"primaryColumn": "id",
|
|
317
317
|
"tableName": "content",
|
|
318
|
-
"unique":
|
|
318
|
+
"unique": [],
|
|
319
319
|
},
|
|
320
320
|
},
|
|
321
321
|
"enums": {},
|
|
@@ -4,73 +4,6 @@ import { ModelValidator } from '../../../src'
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
test('index name collision', () => {
|
|
8
|
-
const model: Model.Schema = {
|
|
9
|
-
enums: {},
|
|
10
|
-
entities: {
|
|
11
|
-
Foo: {
|
|
12
|
-
fields: {
|
|
13
|
-
id: {
|
|
14
|
-
columnName: 'id',
|
|
15
|
-
name: 'id',
|
|
16
|
-
nullable: false,
|
|
17
|
-
type: Model.ColumnType.Uuid,
|
|
18
|
-
columnType: 'uuid',
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
name: 'Foo',
|
|
22
|
-
primary: 'id',
|
|
23
|
-
primaryColumn: 'id',
|
|
24
|
-
tableName: 'foo',
|
|
25
|
-
unique: {},
|
|
26
|
-
eventLog: {
|
|
27
|
-
enabled: true,
|
|
28
|
-
},
|
|
29
|
-
indexes: {
|
|
30
|
-
test: { fields: ['id'], name: 'test' },
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
Bar: {
|
|
34
|
-
fields: {
|
|
35
|
-
id: {
|
|
36
|
-
columnName: 'id',
|
|
37
|
-
name: 'id',
|
|
38
|
-
nullable: false,
|
|
39
|
-
type: Model.ColumnType.Uuid,
|
|
40
|
-
columnType: 'uuid',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
name: 'Bar',
|
|
44
|
-
primary: 'id',
|
|
45
|
-
primaryColumn: 'id',
|
|
46
|
-
tableName: 'bar',
|
|
47
|
-
unique: {
|
|
48
|
-
test: { fields: ['id'], name: 'test' },
|
|
49
|
-
},
|
|
50
|
-
eventLog: {
|
|
51
|
-
enabled: true,
|
|
52
|
-
},
|
|
53
|
-
indexes: {
|
|
54
|
-
foo: { fields: ['id'], name: 'foo' },
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
}
|
|
59
|
-
const validator = new ModelValidator(model)
|
|
60
|
-
assert.deepStrictEqual(validator.validate(), [
|
|
61
|
-
{
|
|
62
|
-
code: 'MODEL_NAME_COLLISION',
|
|
63
|
-
message: 'index name foo of entity Bar collides with table name foo of entity Foo',
|
|
64
|
-
path: ['entities', 'Bar'],
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
code: 'MODEL_NAME_COLLISION',
|
|
68
|
-
message: 'unique index name test of entity Bar collides with index name test of entity Foo',
|
|
69
|
-
path: ['entities', 'Bar'],
|
|
70
|
-
},
|
|
71
|
-
])
|
|
72
|
-
})
|
|
73
|
-
|
|
74
7
|
|
|
75
8
|
test('"meta" collision', () => {
|
|
76
9
|
const model: Model.Schema = {
|
|
@@ -90,9 +23,9 @@ test('"meta" collision', () => {
|
|
|
90
23
|
primary: 'id',
|
|
91
24
|
primaryColumn: 'id',
|
|
92
25
|
tableName: 'foo',
|
|
93
|
-
unique:
|
|
26
|
+
unique: [],
|
|
94
27
|
eventLog: { enabled: true },
|
|
95
|
-
indexes:
|
|
28
|
+
indexes: [],
|
|
96
29
|
},
|
|
97
30
|
FooMeta: {
|
|
98
31
|
fields: {
|
|
@@ -108,9 +41,9 @@ test('"meta" collision', () => {
|
|
|
108
41
|
primary: 'id',
|
|
109
42
|
primaryColumn: 'id',
|
|
110
43
|
tableName: 'foo_meta',
|
|
111
|
-
unique:
|
|
44
|
+
unique: [],
|
|
112
45
|
eventLog: { enabled: true },
|
|
113
|
-
indexes:
|
|
46
|
+
indexes: [],
|
|
114
47
|
},
|
|
115
48
|
BarMeta: {
|
|
116
49
|
fields: {
|
|
@@ -126,9 +59,9 @@ test('"meta" collision', () => {
|
|
|
126
59
|
primary: 'id',
|
|
127
60
|
primaryColumn: 'id',
|
|
128
61
|
tableName: 'bar',
|
|
129
|
-
unique:
|
|
62
|
+
unique: [],
|
|
130
63
|
eventLog: { enabled: true },
|
|
131
|
-
indexes:
|
|
64
|
+
indexes: [],
|
|
132
65
|
},
|
|
133
66
|
},
|
|
134
67
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare class NamingHelper {
|
|
2
|
-
static createForeignKeyIndexName(tableName: string, column: string): string;
|
|
3
|
-
static createJunctionTablePrimaryConstraintName(tableName: string): string;
|
|
4
|
-
static createForeignKeyName(fromTable: string, fromColumn: string, toTable: string, toColumn: string): string;
|
|
5
|
-
static createIndexName: (entityName: string, fields: readonly string[]) => string;
|
|
6
|
-
static createUniqueConstraintName: (entityName: string, fields: readonly string[]) => string;
|
|
7
|
-
private static createUniqueSuffix;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=NamingHelper.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NamingHelper.d.ts","sourceRoot":"","sources":["../../../src/model/NamingHelper.ts"],"names":[],"mappings":"AAIA,qBAAa,YAAY;WACV,yBAAyB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;WAK3D,wCAAwC,CAAC,SAAS,EAAE,MAAM;WAK1D,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAOpH,OAAc,eAAe,eAAgB,MAAM,UAAU,SAAS,MAAM,EAAE,KAAG,MAAM,CAKtF;IAED,OAAc,0BAA0B,eAAgB,MAAM,UAAU,SAAS,MAAM,EAAE,KAAG,MAAM,CAKjG;IAED,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAGhC;CACD"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
var _a;
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.NamingHelper = void 0;
|
|
8
|
-
const sha256_1 = __importDefault(require("crypto-js/sha256"));
|
|
9
|
-
const enc_hex_1 = __importDefault(require("crypto-js/enc-hex"));
|
|
10
|
-
class NamingHelper {
|
|
11
|
-
static createForeignKeyIndexName(tableName, column) {
|
|
12
|
-
// format matches https://github.com/salsita/node-pg-migrate/blob/9331f6fda98795e3f3733461f9b71345168b99d8/src/operations/indexes.ts#L21
|
|
13
|
-
return `${tableName}_${column}_index`;
|
|
14
|
-
}
|
|
15
|
-
static createJunctionTablePrimaryConstraintName(tableName) {
|
|
16
|
-
// format matches https://github.com/salsita/node-pg-migrate/blob/9331f6fda98795e3f3733461f9b71345168b99d8/src/operations/tables.ts#L204
|
|
17
|
-
return `${tableName}_pkey`;
|
|
18
|
-
}
|
|
19
|
-
static createForeignKeyName(fromTable, fromColumn, toTable, toColumn) {
|
|
20
|
-
return 'fk_'
|
|
21
|
-
+ fromTable + '_'
|
|
22
|
-
+ fromColumn + '_'
|
|
23
|
-
+ this.createUniqueSuffix([fromTable, fromColumn, toTable, toColumn]);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.NamingHelper = NamingHelper;
|
|
27
|
-
_a = NamingHelper;
|
|
28
|
-
NamingHelper.createIndexName = (entityName, fields) => {
|
|
29
|
-
return 'idx_'
|
|
30
|
-
+ entityName + '_'
|
|
31
|
-
+ fields.join('_') + '_'
|
|
32
|
-
+ _a.createUniqueSuffix([entityName, ...fields]);
|
|
33
|
-
};
|
|
34
|
-
NamingHelper.createUniqueConstraintName = (entityName, fields) => {
|
|
35
|
-
return 'unique_'
|
|
36
|
-
+ entityName + '_'
|
|
37
|
-
+ fields.join('_') + '_'
|
|
38
|
-
+ _a.createUniqueSuffix([entityName, ...fields]);
|
|
39
|
-
};
|
|
40
|
-
NamingHelper.createUniqueSuffix = (values) => {
|
|
41
|
-
const uniqueSuffix = (0, sha256_1.default)(JSON.stringify(values)).toString(enc_hex_1.default);
|
|
42
|
-
return uniqueSuffix.slice(0, 6);
|
|
43
|
-
};
|
|
44
|
-
//# sourceMappingURL=NamingHelper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NamingHelper.js","sourceRoot":"","sources":["../../../src/model/NamingHelper.ts"],"names":[],"mappings":";;;;;;;AAAA,8DAAqC;AACrC,gEAAsC;AAGtC,MAAa,YAAY;IACjB,MAAM,CAAC,yBAAyB,CAAC,SAAiB,EAAE,MAAc;QACxE,wIAAwI;QACxI,OAAO,GAAG,SAAS,IAAI,MAAM,QAAQ,CAAA;IACtC,CAAC;IAEM,MAAM,CAAC,wCAAwC,CAAC,SAAiB;QACvE,wIAAwI;QACxI,OAAO,GAAG,SAAS,OAAO,CAAA;IAC3B,CAAC;IAEM,MAAM,CAAC,oBAAoB,CAAC,SAAiB,EAAE,UAAkB,EAAE,OAAe,EAAE,QAAgB;QAC1G,OAAO,KAAK;cACT,SAAS,GAAG,GAAG;cACf,UAAU,GAAG,GAAG;cAChB,IAAI,CAAC,kBAAkB,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAA;IACvE,CAAC;;AAhBF,oCAoCC;;AAlBc,4BAAe,GAAG,CAAC,UAAkB,EAAE,MAAyB,EAAU,EAAE;IACzF,OAAO,MAAM;UACV,UAAU,GAAG,GAAG;UAChB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG;UACtB,EAAI,CAAC,kBAAkB,CAAC,CAAC,UAAU,EAAE,GAAG,MAAM,CAAC,CAAC,CAAA;AACpD,CAAC,CAAA;AAEa,uCAA0B,GAAG,CAAC,UAAkB,EAAE,MAAyB,EAAU,EAAE;IACpG,OAAO,SAAS;UACb,UAAU,GAAG,GAAG;UAChB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG;UACtB,EAAI,CAAC,kBAAkB,CAAC,CAAC,UAAU,EAAE,GAAG,MAAM,CAAC,CAAC,CAAA;AACpD,CAAC,CAAA;AAEc,+BAAkB,GAAG,CAAC,MAAgB,EAAU,EAAE;IAChE,MAAM,YAAY,GAAG,IAAA,gBAAM,EAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,iBAAM,CAAC,CAAA;IACpE,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AAChC,CAAC,CAAA"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import Sha256 from 'crypto-js/sha256'
|
|
2
|
-
import EncHex from 'crypto-js/enc-hex'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export class NamingHelper {
|
|
6
|
-
public static createForeignKeyIndexName(tableName: string, column: string) {
|
|
7
|
-
// format matches https://github.com/salsita/node-pg-migrate/blob/9331f6fda98795e3f3733461f9b71345168b99d8/src/operations/indexes.ts#L21
|
|
8
|
-
return `${tableName}_${column}_index`
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public static createJunctionTablePrimaryConstraintName(tableName: string) {
|
|
12
|
-
// format matches https://github.com/salsita/node-pg-migrate/blob/9331f6fda98795e3f3733461f9b71345168b99d8/src/operations/tables.ts#L204
|
|
13
|
-
return `${tableName}_pkey`
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public static createForeignKeyName(fromTable: string, fromColumn: string, toTable: string, toColumn: string): string {
|
|
17
|
-
return 'fk_'
|
|
18
|
-
+ fromTable + '_'
|
|
19
|
-
+ fromColumn + '_'
|
|
20
|
-
+ this.createUniqueSuffix([fromTable, fromColumn, toTable, toColumn])
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public static createIndexName = (entityName: string, fields: readonly string[]): string => {
|
|
24
|
-
return 'idx_'
|
|
25
|
-
+ entityName + '_'
|
|
26
|
-
+ fields.join('_') + '_'
|
|
27
|
-
+ this.createUniqueSuffix([entityName, ...fields])
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public static createUniqueConstraintName = (entityName: string, fields: readonly string[]): string => {
|
|
31
|
-
return 'unique_'
|
|
32
|
-
+ entityName + '_'
|
|
33
|
-
+ fields.join('_') + '_'
|
|
34
|
-
+ this.createUniqueSuffix([entityName, ...fields])
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
private static createUniqueSuffix = (values: string[]): string => {
|
|
38
|
-
const uniqueSuffix = Sha256(JSON.stringify(values)).toString(EncHex)
|
|
39
|
-
return uniqueSuffix.slice(0, 6)
|
|
40
|
-
}
|
|
41
|
-
}
|