@axinom/mosaic-cli 0.14.2-rc.8 → 0.15.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -5
- package/src/cli/README.md +60 -0
- package/src/cli/index.ts +47 -0
- package/src/commands/apply-templates/apply-templates.spec.ts +623 -0
- package/src/commands/apply-templates/apply-templates.ts +494 -0
- package/src/commands/apply-templates/bitwarden-vault.ts +130 -0
- package/src/commands/apply-templates/index.ts +1 -0
- package/src/commands/create-extension-config/create-extension-config.ts +92 -0
- package/src/commands/create-extension-config/index.ts +23 -0
- package/src/commands/get-access-token/get-access-token-options.ts +9 -0
- package/src/commands/get-access-token/get-dev-access-token.ts +32 -0
- package/src/commands/get-access-token/index.ts +66 -0
- package/src/commands/graphql-diff.ts +143 -0
- package/src/commands/msg-codegen/codegen.ts +891 -0
- package/src/commands/msg-codegen/index.ts +48 -0
- package/src/commands/msg-codegen/lint.ts +84 -0
- package/src/commands/msg-codegen/message-codegen-options.ts +7 -0
- package/src/commands/msg-diff/asyncapi-override.ts +31 -0
- package/src/commands/msg-diff/git-checkout-tmp.ts +73 -0
- package/src/commands/msg-diff/index.ts +53 -0
- package/src/commands/msg-diff/message-diff-options.ts +7 -0
- package/src/commands/msg-diff/msg-diff.spec.ts +412 -0
- package/src/commands/msg-diff/msg-diff.ts +364 -0
- package/src/commands/msg-diff/test-resources/0/1-asyncapi.yml +38 -0
- package/src/commands/msg-diff/test-resources/0/2-asyncapi.yml +36 -0
- package/src/commands/msg-diff/test-resources/0/command.json +74 -0
- package/src/commands/msg-diff/test-resources/0/event.json +25 -0
- package/src/commands/msg-diff/test-resources/1/1-asyncapi.yml +25 -0
- package/src/commands/msg-diff/test-resources/1/moved-event.json +25 -0
- package/src/commands/msg-diff/test-resources/common.json +20 -0
- package/src/commands/pg-dump/README.md +21 -0
- package/src/commands/pg-dump/generate.ts +146 -0
- package/src/commands/pg-dump/index.ts +39 -0
- package/src/commands/pg-dump/pg-dump-options.ts +6 -0
- package/src/commands/publish-schema-to-db/README.md +130 -0
- package/src/commands/publish-schema-to-db/abstractions/base-smart-tags.ts +6 -0
- package/src/commands/publish-schema-to-db/abstractions/index.ts +5 -0
- package/src/commands/publish-schema-to-db/abstractions/pg-column.ts +31 -0
- package/src/commands/publish-schema-to-db/abstractions/pg-fk-column.ts +6 -0
- package/src/commands/publish-schema-to-db/abstractions/pg-table.ts +55 -0
- package/src/commands/publish-schema-to-db/abstractions/pg-type.ts +8 -0
- package/src/commands/publish-schema-to-db/content-entity-model.ts +93 -0
- package/src/commands/publish-schema-to-db/generate.ts +82 -0
- package/src/commands/publish-schema-to-db/index.ts +49 -0
- package/src/commands/publish-schema-to-db/jest.config.js +9 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/fk-column.spec.ts +42 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/fk-column.ts +41 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/index.ts +4 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/pk-column.spec.ts +47 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/pk-column.ts +34 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/primitive-column.spec.ts +65 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/primitive-column.ts +62 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/virtual-fk-column.spec.ts +24 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/virtual-fk-column.ts +34 -0
- package/src/commands/publish-schema-to-db/pg-models/json-schema-parse-utils.spec.ts +182 -0
- package/src/commands/publish-schema-to-db/pg-models/json-schema-parse-utils.ts +166 -0
- package/src/commands/publish-schema-to-db/pg-models/pg-sql-gen-utils.spec.ts +19 -0
- package/src/commands/publish-schema-to-db/pg-models/pg-sql-gen-utils.ts +237 -0
- package/src/commands/publish-schema-to-db/pg-models/pgl-utils.spec.ts +19 -0
- package/src/commands/publish-schema-to-db/pg-models/pgl-utils.ts +115 -0
- package/src/commands/publish-schema-to-db/pg-models/tables/content-entity-table.ts +104 -0
- package/src/commands/publish-schema-to-db/pg-models/tables/index.ts +3 -0
- package/src/commands/publish-schema-to-db/pg-models/tables/object-property-table.ts +113 -0
- package/src/commands/publish-schema-to-db/pg-models/tables/relations-table.ts +115 -0
- package/src/commands/publish-schema-to-db/postprocessors/collection-postprocessor.ts +33 -0
- package/src/commands/publish-schema-to-db/postprocessors/content-entity-model-postprocessor.ts +13 -0
- package/src/commands/publish-schema-to-db/postprocessors/episode-postprocessor.ts +37 -0
- package/src/commands/publish-schema-to-db/postprocessors/index.ts +6 -0
- package/src/commands/publish-schema-to-db/postprocessors/movie-postprocessor.ts +30 -0
- package/src/commands/publish-schema-to-db/postprocessors/postprocessing-utils.ts +21 -0
- package/src/commands/publish-schema-to-db/postprocessors/season-postprocessor.ts +37 -0
- package/src/commands/publish-schema-to-db/postprocessors/tvshow-postprocessor.ts +30 -0
- package/src/commands/publish-schema-to-db/publish-schema-to-db-options.ts +15 -0
- package/src/commands/publish-schema-to-db/types/sql-formatter.d.ts +10 -0
- package/src/exports.ts +2 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { JSONSchema4 } from 'json-schema';
|
|
2
|
+
import {
|
|
3
|
+
PgColumn,
|
|
4
|
+
PgFkColumn,
|
|
5
|
+
PgTable,
|
|
6
|
+
TableSmartTags,
|
|
7
|
+
} from '../../abstractions';
|
|
8
|
+
import { PublishSchemaToDbOptions } from '../../publish-schema-to-db-options';
|
|
9
|
+
import { FkColumn, PkColumn, PrimitiveColumn } from '../columns';
|
|
10
|
+
import { isPrimitiveProperty, mapToPgType } from '../json-schema-parse-utils';
|
|
11
|
+
import {
|
|
12
|
+
buildAdditionalTableStatements,
|
|
13
|
+
buildCreateTable,
|
|
14
|
+
buildDropTableIfExists,
|
|
15
|
+
buildFullTableName,
|
|
16
|
+
buildInsertUpdateGrants,
|
|
17
|
+
buildName,
|
|
18
|
+
buildSelectDeleteGrants,
|
|
19
|
+
} from '../pg-sql-gen-utils';
|
|
20
|
+
import {
|
|
21
|
+
buildAttributeSmartTags,
|
|
22
|
+
buildFkConstraintSmartTags,
|
|
23
|
+
snakeCaseToCamelCase,
|
|
24
|
+
} from '../pgl-utils';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Table model for storing complex/object properties (licensing, video streams etc.) of a root entity.
|
|
28
|
+
* It will have a FK relation to the root entity in the database.
|
|
29
|
+
*/
|
|
30
|
+
export class ObjectPropertyTable implements PgTable {
|
|
31
|
+
name: string;
|
|
32
|
+
displayName?: string;
|
|
33
|
+
readonly description?: string;
|
|
34
|
+
readonly pk: PgColumn;
|
|
35
|
+
readonly fks: PgFkColumn[] = [];
|
|
36
|
+
readonly virtualFks: PgFkColumn[] = [];
|
|
37
|
+
readonly columns: PgColumn[] = [];
|
|
38
|
+
private options: PublishSchemaToDbOptions;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Constructor for ObjectPropertyTable.
|
|
42
|
+
* @param propertyName - Name of the property.
|
|
43
|
+
* @param schema - DB schema where this table will be created.
|
|
44
|
+
* @param jsonSchema - JSON schema describing this object property.
|
|
45
|
+
* @param contentEntityPk - PK of the content entity this object property belongs to.
|
|
46
|
+
*/
|
|
47
|
+
constructor(
|
|
48
|
+
options: PublishSchemaToDbOptions,
|
|
49
|
+
propertyName: string,
|
|
50
|
+
jsonSchema: JSONSchema4,
|
|
51
|
+
contentEntityPk: PgColumn,
|
|
52
|
+
) {
|
|
53
|
+
const isArray = jsonSchema.type === 'array';
|
|
54
|
+
jsonSchema = isArray ? (jsonSchema?.items as JSONSchema4) : jsonSchema;
|
|
55
|
+
this.options = options;
|
|
56
|
+
this.name = buildName(contentEntityPk.table.name, propertyName);
|
|
57
|
+
this.displayName = snakeCaseToCamelCase(propertyName);
|
|
58
|
+
this.description = jsonSchema.description;
|
|
59
|
+
|
|
60
|
+
// 1. Create a synthetic PK for this table.
|
|
61
|
+
this.pk = new PkColumn(this, 'INTEGER');
|
|
62
|
+
|
|
63
|
+
// 2. Iterate over object properties, convert them to column definitions.
|
|
64
|
+
for (const key in jsonSchema.properties) {
|
|
65
|
+
if (options.ignoredProperties.includes(key)) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const propSchema = jsonSchema.properties[key] as JSONSchema4;
|
|
70
|
+
|
|
71
|
+
if (!isPrimitiveProperty(propSchema)) {
|
|
72
|
+
throw new TypeError(
|
|
73
|
+
`Unsupported property in object schema: ${propSchema}`,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
this.columns.push(
|
|
78
|
+
new PrimitiveColumn(key, mapToPgType(propSchema), this, {
|
|
79
|
+
description: propSchema.description,
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 3. Add FK(s).
|
|
85
|
+
this.fks.push(new FkColumn(contentEntityPk, this));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
buildFullName(): string {
|
|
89
|
+
return buildFullTableName(this.name, this.options.dbSchema);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
buildSmartTags(): TableSmartTags {
|
|
93
|
+
return {
|
|
94
|
+
description: this.description,
|
|
95
|
+
attribute: buildAttributeSmartTags(this.columns),
|
|
96
|
+
tags: {
|
|
97
|
+
omitFromQueryRoot: true,
|
|
98
|
+
omit: 'create,update,delete',
|
|
99
|
+
},
|
|
100
|
+
constraint: buildFkConstraintSmartTags(this.fks),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
buildStatements(): string[] {
|
|
105
|
+
return [
|
|
106
|
+
buildDropTableIfExists(this),
|
|
107
|
+
buildCreateTable(this),
|
|
108
|
+
...buildAdditionalTableStatements(this),
|
|
109
|
+
buildSelectDeleteGrants(this),
|
|
110
|
+
buildInsertUpdateGrants(this),
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PgColumn,
|
|
3
|
+
PgFkColumn,
|
|
4
|
+
PgTable,
|
|
5
|
+
PgType,
|
|
6
|
+
TableSmartTags,
|
|
7
|
+
} from '../../abstractions';
|
|
8
|
+
import { PublishSchemaToDbOptions } from '../../publish-schema-to-db-options';
|
|
9
|
+
import {
|
|
10
|
+
FkColumn,
|
|
11
|
+
PkColumn,
|
|
12
|
+
PrimitiveColumn,
|
|
13
|
+
PrimitiveColumnOptions,
|
|
14
|
+
VirtualFkColumn,
|
|
15
|
+
} from '../columns';
|
|
16
|
+
import {
|
|
17
|
+
buildAdditionalTableStatements,
|
|
18
|
+
buildCreateTable,
|
|
19
|
+
buildDropTableIfExists,
|
|
20
|
+
buildFullTableName,
|
|
21
|
+
buildInsertUpdateGrants,
|
|
22
|
+
buildName,
|
|
23
|
+
buildSelectDeleteGrants,
|
|
24
|
+
} from '../pg-sql-gen-utils';
|
|
25
|
+
import {
|
|
26
|
+
buildFkConstraintSmartTags,
|
|
27
|
+
buildVirtualFkSmartTags,
|
|
28
|
+
} from '../pgl-utils';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Configuration interface for creating additional columns in the relations table.
|
|
32
|
+
*/
|
|
33
|
+
export interface AdditionalColumnOptions {
|
|
34
|
+
/** Name of the column. */
|
|
35
|
+
name: string;
|
|
36
|
+
/** Type of the column. */
|
|
37
|
+
type: PgType;
|
|
38
|
+
/** Additional options. */
|
|
39
|
+
options?: PrimitiveColumnOptions;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Table model for maintaining arbitrary (soft/virtual) on-to-many relationships.
|
|
44
|
+
*/
|
|
45
|
+
export class RelationsTable implements PgTable {
|
|
46
|
+
name: string;
|
|
47
|
+
displayName?: string;
|
|
48
|
+
readonly description?: string;
|
|
49
|
+
readonly pk: PgColumn;
|
|
50
|
+
readonly fks: PgFkColumn[] = [];
|
|
51
|
+
readonly virtualFks: PgFkColumn[] = [];
|
|
52
|
+
readonly columns: PgColumn[] = [];
|
|
53
|
+
private options: PublishSchemaToDbOptions;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Constructor for RelationsTable.
|
|
57
|
+
* @param contentEntity - Content entity these relations are attached to.
|
|
58
|
+
* @param relatedEntities - Array of other content entities to create relations to.
|
|
59
|
+
* @param schema - DB schema where this table will be created.
|
|
60
|
+
* @param displayName - Display name of this table, used in the generated GQL API.
|
|
61
|
+
* @param additionalColumnOptions - Array of configuration objects for constructing additional PrimitiveColumn instances.
|
|
62
|
+
*/
|
|
63
|
+
constructor(
|
|
64
|
+
config: PublishSchemaToDbOptions,
|
|
65
|
+
contentEntity: PgTable,
|
|
66
|
+
relatedEntities: PgTable[],
|
|
67
|
+
displayName: string,
|
|
68
|
+
additionalColumnOptions?: AdditionalColumnOptions[],
|
|
69
|
+
description?: string,
|
|
70
|
+
) {
|
|
71
|
+
this.options = config;
|
|
72
|
+
this.displayName = displayName;
|
|
73
|
+
this.name = buildName(contentEntity.pk.table.name, displayName, 'relation');
|
|
74
|
+
this.description = description;
|
|
75
|
+
this.pk = new PkColumn(this, 'INTEGER');
|
|
76
|
+
this.fks.push(new FkColumn(contentEntity.pk, this));
|
|
77
|
+
if (additionalColumnOptions) {
|
|
78
|
+
this.columns.push(
|
|
79
|
+
...additionalColumnOptions.map(
|
|
80
|
+
(o) => new PrimitiveColumn(o.name, o.type, this, o.options),
|
|
81
|
+
),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
for (const relatedEntity of relatedEntities) {
|
|
86
|
+
this.virtualFks.push(new VirtualFkColumn(relatedEntity.pk, this));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
buildFullName(): string {
|
|
91
|
+
return buildFullTableName(this.name, this.options.dbSchema);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
buildSmartTags(): TableSmartTags {
|
|
95
|
+
return {
|
|
96
|
+
description: this.description,
|
|
97
|
+
tags: {
|
|
98
|
+
omitFromQueryRoot: true,
|
|
99
|
+
omit: 'create,update,delete',
|
|
100
|
+
foreignKey: buildVirtualFkSmartTags(this.virtualFks),
|
|
101
|
+
},
|
|
102
|
+
constraint: buildFkConstraintSmartTags(this.fks),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
buildStatements(): string[] {
|
|
107
|
+
return [
|
|
108
|
+
buildDropTableIfExists(this),
|
|
109
|
+
buildCreateTable(this),
|
|
110
|
+
...buildAdditionalTableStatements(this),
|
|
111
|
+
buildSelectDeleteGrants(this),
|
|
112
|
+
buildInsertUpdateGrants(this),
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RelationsTable } from '../pg-models/tables';
|
|
2
|
+
import { ContentEntityModelPostprocessor } from './content-entity-model-postprocessor';
|
|
3
|
+
import { findEntityModel } from './postprocessing-utils';
|
|
4
|
+
|
|
5
|
+
export const collectionPostprocessor: ContentEntityModelPostprocessor = (
|
|
6
|
+
mainModel,
|
|
7
|
+
otherModels,
|
|
8
|
+
options,
|
|
9
|
+
) => {
|
|
10
|
+
const relatedItemModels = ['movie', 'tvshow', 'season', 'episode'].map((n) =>
|
|
11
|
+
findEntityModel(otherModels, n),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
mainModel.relatedObjects.push(
|
|
15
|
+
new RelationsTable(
|
|
16
|
+
options,
|
|
17
|
+
mainModel.contentEntity,
|
|
18
|
+
relatedItemModels.map((m) => m.contentEntity),
|
|
19
|
+
'items',
|
|
20
|
+
[
|
|
21
|
+
{
|
|
22
|
+
name: 'order_no',
|
|
23
|
+
type: 'INTEGER',
|
|
24
|
+
options: { extraParams: 'NOT NULL DEFAULT 0', indexable: true },
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'relation_type',
|
|
28
|
+
type: 'TEXT',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
),
|
|
32
|
+
);
|
|
33
|
+
};
|
package/src/commands/publish-schema-to-db/postprocessors/content-entity-model-postprocessor.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ContentEntityModel } from '../content-entity-model';
|
|
2
|
+
import { PublishSchemaToDbOptions } from '../publish-schema-to-db-options';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Post processes a ContentEntityModel instance. Useful for implementing custom logic for different content types.
|
|
6
|
+
*/
|
|
7
|
+
export interface ContentEntityModelPostprocessor {
|
|
8
|
+
(
|
|
9
|
+
mainModel: ContentEntityModel,
|
|
10
|
+
otherModels: ContentEntityModel[],
|
|
11
|
+
options: PublishSchemaToDbOptions,
|
|
12
|
+
): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { VirtualFkColumn } from '../pg-models/columns';
|
|
2
|
+
import { applyNameOverrides } from '../pg-models/pg-sql-gen-utils';
|
|
3
|
+
import { RelationsTable } from '../pg-models/tables';
|
|
4
|
+
import { ContentEntityModelPostprocessor } from './content-entity-model-postprocessor';
|
|
5
|
+
import { findEntityModel, removeColumnByName } from './postprocessing-utils';
|
|
6
|
+
|
|
7
|
+
export const episodePostprocessor: ContentEntityModelPostprocessor = (
|
|
8
|
+
mainModel,
|
|
9
|
+
otherModels,
|
|
10
|
+
options,
|
|
11
|
+
) => {
|
|
12
|
+
const seasonModel = findEntityModel(otherModels, 'season');
|
|
13
|
+
const tvshowGenreModel = findEntityModel(otherModels, 'tvshow_genre');
|
|
14
|
+
applyNameOverrides(mainModel, {
|
|
15
|
+
cast: ['episode_cast', 'cast'],
|
|
16
|
+
});
|
|
17
|
+
removeColumnByName(mainModel.contentEntity.columns, 'season_id');
|
|
18
|
+
mainModel.contentEntity.virtualFks.push(
|
|
19
|
+
new VirtualFkColumn(seasonModel.contentEntity.pk, mainModel.contentEntity),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
mainModel.relatedObjects.push(
|
|
23
|
+
new RelationsTable(
|
|
24
|
+
options,
|
|
25
|
+
mainModel.contentEntity,
|
|
26
|
+
[tvshowGenreModel.contentEntity],
|
|
27
|
+
'genres',
|
|
28
|
+
[
|
|
29
|
+
{
|
|
30
|
+
name: 'order_no',
|
|
31
|
+
type: 'INTEGER',
|
|
32
|
+
options: { extraParams: 'NOT NULL DEFAULT 0', indexable: true },
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
),
|
|
36
|
+
);
|
|
37
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { applyNameOverrides } from '../pg-models/pg-sql-gen-utils';
|
|
2
|
+
import { RelationsTable } from '../pg-models/tables';
|
|
3
|
+
import { ContentEntityModelPostprocessor } from './content-entity-model-postprocessor';
|
|
4
|
+
import { findEntityModel } from './postprocessing-utils';
|
|
5
|
+
|
|
6
|
+
export const moviePostprocessor: ContentEntityModelPostprocessor = (
|
|
7
|
+
mainModel,
|
|
8
|
+
otherModels,
|
|
9
|
+
options,
|
|
10
|
+
) => {
|
|
11
|
+
const movieGenreModel = findEntityModel(otherModels, 'movie_genre');
|
|
12
|
+
applyNameOverrides(mainModel, {
|
|
13
|
+
cast: ['movie_cast', 'cast'],
|
|
14
|
+
});
|
|
15
|
+
mainModel.relatedObjects.push(
|
|
16
|
+
new RelationsTable(
|
|
17
|
+
options,
|
|
18
|
+
mainModel.contentEntity,
|
|
19
|
+
[movieGenreModel.contentEntity],
|
|
20
|
+
'genres',
|
|
21
|
+
[
|
|
22
|
+
{
|
|
23
|
+
name: 'order_no',
|
|
24
|
+
type: 'INTEGER',
|
|
25
|
+
options: { extraParams: 'NOT NULL DEFAULT 0', indexable: true },
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
),
|
|
29
|
+
);
|
|
30
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PgColumn } from '../abstractions';
|
|
2
|
+
import { ContentEntityModel } from '../content-entity-model';
|
|
3
|
+
|
|
4
|
+
export function findEntityModel(
|
|
5
|
+
models: ContentEntityModel[],
|
|
6
|
+
entityName: string,
|
|
7
|
+
): ContentEntityModel {
|
|
8
|
+
const entityModel = models.find((m) => m.contentEntity.name === entityName);
|
|
9
|
+
if (!entityModel) {
|
|
10
|
+
throw Error(`Content entity model for ${entityName} not found.`);
|
|
11
|
+
}
|
|
12
|
+
return entityModel;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function removeColumnByName(columns: PgColumn[], name: string): void {
|
|
16
|
+
columns.forEach((c, i) => {
|
|
17
|
+
if (c.name === name) {
|
|
18
|
+
columns.splice(i, 1);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { VirtualFkColumn } from '../pg-models/columns';
|
|
2
|
+
import { applyNameOverrides } from '../pg-models/pg-sql-gen-utils';
|
|
3
|
+
import { RelationsTable } from '../pg-models/tables';
|
|
4
|
+
import { ContentEntityModelPostprocessor } from './content-entity-model-postprocessor';
|
|
5
|
+
import { findEntityModel, removeColumnByName } from './postprocessing-utils';
|
|
6
|
+
|
|
7
|
+
export const seasonPostprocessor: ContentEntityModelPostprocessor = (
|
|
8
|
+
mainModel,
|
|
9
|
+
otherModels,
|
|
10
|
+
options,
|
|
11
|
+
) => {
|
|
12
|
+
const tvshowModel = findEntityModel(otherModels, 'tvshow');
|
|
13
|
+
const tvshowGenreModel = findEntityModel(otherModels, 'tvshow_genre');
|
|
14
|
+
applyNameOverrides(mainModel, {
|
|
15
|
+
cast: ['season_cast', 'cast'],
|
|
16
|
+
});
|
|
17
|
+
removeColumnByName(mainModel.contentEntity.columns, 'tvshow_id');
|
|
18
|
+
mainModel.contentEntity.virtualFks.push(
|
|
19
|
+
new VirtualFkColumn(tvshowModel.contentEntity.pk, mainModel.contentEntity),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
mainModel.relatedObjects.push(
|
|
23
|
+
new RelationsTable(
|
|
24
|
+
options,
|
|
25
|
+
mainModel.contentEntity,
|
|
26
|
+
[tvshowGenreModel.contentEntity],
|
|
27
|
+
'genres',
|
|
28
|
+
[
|
|
29
|
+
{
|
|
30
|
+
name: 'order_no',
|
|
31
|
+
type: 'INTEGER',
|
|
32
|
+
options: { extraParams: 'NOT NULL DEFAULT 0', indexable: true },
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
),
|
|
36
|
+
);
|
|
37
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { applyNameOverrides } from '../pg-models/pg-sql-gen-utils';
|
|
2
|
+
import { RelationsTable } from '../pg-models/tables';
|
|
3
|
+
import { ContentEntityModelPostprocessor } from './content-entity-model-postprocessor';
|
|
4
|
+
import { findEntityModel } from './postprocessing-utils';
|
|
5
|
+
|
|
6
|
+
export const tvshowPostprocessor: ContentEntityModelPostprocessor = (
|
|
7
|
+
mainModel,
|
|
8
|
+
otherModels,
|
|
9
|
+
options,
|
|
10
|
+
) => {
|
|
11
|
+
const tvshowGenreModel = findEntityModel(otherModels, 'tvshow_genre');
|
|
12
|
+
applyNameOverrides(mainModel, {
|
|
13
|
+
cast: ['tvshow_cast', 'cast'],
|
|
14
|
+
});
|
|
15
|
+
mainModel.relatedObjects.push(
|
|
16
|
+
new RelationsTable(
|
|
17
|
+
options,
|
|
18
|
+
mainModel.contentEntity,
|
|
19
|
+
[tvshowGenreModel.contentEntity],
|
|
20
|
+
'genres',
|
|
21
|
+
[
|
|
22
|
+
{
|
|
23
|
+
name: 'order_no',
|
|
24
|
+
type: 'INTEGER',
|
|
25
|
+
options: { extraParams: 'NOT NULL DEFAULT 0', indexable: true },
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
),
|
|
29
|
+
);
|
|
30
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI command options.
|
|
3
|
+
*/
|
|
4
|
+
export interface PublishSchemaToDbOptions {
|
|
5
|
+
/** Input glob pattern that selects input schemas. */
|
|
6
|
+
inputGlob: string;
|
|
7
|
+
/** Name of the ID key in JSON schema. */
|
|
8
|
+
idKey: string;
|
|
9
|
+
/** Array of ignored JSON schema properties. */
|
|
10
|
+
ignoredProperties: string[];
|
|
11
|
+
/** Name of the DB schema to be used in SQL generation. */
|
|
12
|
+
dbSchema: string;
|
|
13
|
+
/** Path to the target project root. */
|
|
14
|
+
outputRoot: string;
|
|
15
|
+
}
|
package/src/exports.ts
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { run } from './cli';
|