@contember/cli 2.0.0-alpha.17 → 2.0.0-alpha.19
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/development/src/commands/project/ProjectPrintSchemaCommand.cjs +13 -2
- package/dist/development/src/commands/project/ProjectPrintSchemaCommand.cjs.map +1 -1
- package/dist/development/src/commands/project/ProjectPrintSchemaCommand.js +14 -3
- package/dist/development/src/commands/project/ProjectPrintSchemaCommand.js.map +1 -1
- package/dist/production/src/commands/project/ProjectPrintSchemaCommand.cjs +13 -2
- package/dist/production/src/commands/project/ProjectPrintSchemaCommand.cjs.map +1 -1
- package/dist/production/src/commands/project/ProjectPrintSchemaCommand.js +14 -3
- package/dist/production/src/commands/project/ProjectPrintSchemaCommand.js.map +1 -1
- package/dist/types/commands/project/ProjectPrintSchemaCommand.d.ts +4 -0
- package/dist/types/commands/project/ProjectPrintSchemaCommand.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -13
- package/src/commands/project/ProjectPrintSchemaCommand.ts +19 -3
|
@@ -18,16 +18,27 @@ class ProjectPrintSchemaCommand extends cliCommon.Command {
|
|
|
18
18
|
configuration.option("source").valueRequired().description("migrations|definition");
|
|
19
19
|
configuration.option("role").valueArray();
|
|
20
20
|
configuration.option("normalize").valueNone();
|
|
21
|
+
configuration.option("omit-acl").valueNone();
|
|
22
|
+
configuration.option("omit-validation").valueNone();
|
|
23
|
+
configuration.option("omit-actions").valueNone();
|
|
24
|
+
configuration.option("omit-settings").valueNone();
|
|
21
25
|
}
|
|
22
26
|
async execute(input) {
|
|
23
27
|
const format = input.getOption("format") || "graphql";
|
|
24
28
|
const schema$1 = input.getOption("source") === "migrations" ? await this.schemaVersionBuilder.buildSchema() : await this.schemaLoader.loadSchema();
|
|
25
|
-
|
|
29
|
+
const filteredSchema = {
|
|
30
|
+
model: schema$1.model,
|
|
31
|
+
acl: input.getOption("omit-acl") ? schemaUtils.emptySchema.acl : schema$1.acl,
|
|
32
|
+
validation: input.getOption("omit-validation") ? schemaUtils.emptySchema.validation : schema$1.validation,
|
|
33
|
+
actions: input.getOption("omit-actions") ? schemaUtils.emptySchema.actions : schema$1.actions,
|
|
34
|
+
settings: input.getOption("omit-settings") ? schemaUtils.emptySchema.settings : schema$1.settings
|
|
35
|
+
};
|
|
36
|
+
if (!SchemaValidationHelper.validateSchemaAndPrintErrors(filteredSchema, "Defined schema is invalid:")) {
|
|
26
37
|
return 1;
|
|
27
38
|
}
|
|
28
39
|
const permissionFactory = new engineContentApi.PermissionFactory();
|
|
29
40
|
const inputRoles = input.getOption("role");
|
|
30
|
-
const schemaNormalized = input.getOption("normalize") ? schemaUtils.normalizeSchema(
|
|
41
|
+
const schemaNormalized = input.getOption("normalize") ? schemaUtils.normalizeSchema(filteredSchema) : filteredSchema;
|
|
31
42
|
const permissions = permissionFactory.create(schemaNormalized, inputRoles || ["admin"]);
|
|
32
43
|
const schemaBuilderFactory = new engineContentApi.GraphQlSchemaBuilderFactory();
|
|
33
44
|
const authorizator = new engineContentApi.Authorizator(permissions, schemaNormalized.acl.customPrimary ?? false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectPrintSchemaCommand.cjs","sources":["../../../../../../packages/cli/src/commands/project/ProjectPrintSchemaCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport {\n\tAuthorizator,\n\tEntityRulesResolver,\n\tGraphQlSchemaBuilderFactory,\n\tIntrospectionSchemaDefinitionFactory,\n\tIntrospectionSchemaFactory,\n\tPermissionFactory,\n} from '@contember/engine-content-api'\nimport { printSchema } from 'graphql'\nimport { mergeSchemas } from '@graphql-tools/schema'\nimport { normalizeSchema } from '@contember/schema-utils'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader'\nimport { SchemaVersionBuilder } from '@contember/migrations-client'\nimport { validateSchemaAndPrintErrors } from '../../lib/schema/SchemaValidationHelper'\n\ntype Args = {\n}\n\ntype Options = {\n\trole?: string[]\n\tnormalize?: boolean\n\tformat?: 'graphql' | 'introspection' | 'schema'\n\tsource?: 'migrations' | 'definition'\n}\n\nexport class ProjectPrintSchemaCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Prints project schema')\n\t\tconfiguration.option('format').valueRequired().description('graphql|introspection|schema')\n\t\tconfiguration.option('source').valueRequired().description('migrations|definition')\n\t\tconfiguration.option('role').valueArray()\n\t\tconfiguration.option('normalize').valueNone()\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<number> {\n\t\tconst format = input.getOption('format') || 'graphql'\n\n\n\t\tconst schema = input.getOption('source') === 'migrations'\n\t\t\t? await this.schemaVersionBuilder.buildSchema()\n\t\t\t: await this.schemaLoader.loadSchema()\n\n\t\tif (!validateSchemaAndPrintErrors(
|
|
1
|
+
{"version":3,"file":"ProjectPrintSchemaCommand.cjs","sources":["../../../../../../packages/cli/src/commands/project/ProjectPrintSchemaCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport {\n\tAuthorizator,\n\tEntityRulesResolver,\n\tGraphQlSchemaBuilderFactory,\n\tIntrospectionSchemaDefinitionFactory,\n\tIntrospectionSchemaFactory,\n\tPermissionFactory,\n} from '@contember/engine-content-api'\nimport { printSchema } from 'graphql'\nimport { mergeSchemas } from '@graphql-tools/schema'\nimport { emptySchema, normalizeSchema } from '@contember/schema-utils'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader'\nimport { SchemaVersionBuilder } from '@contember/migrations-client'\nimport { validateSchemaAndPrintErrors } from '../../lib/schema/SchemaValidationHelper'\n\ntype Args = {\n}\n\ntype Options = {\n\trole?: string[]\n\tnormalize?: boolean\n\tformat?: 'graphql' | 'introspection' | 'schema'\n\tsource?: 'migrations' | 'definition'\n\t['omit-acl']?: boolean\n\t['omit-validation']?: boolean\n\t['omit-actions']?: boolean\n\t['omit-settings']?: boolean\n}\n\nexport class ProjectPrintSchemaCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Prints project schema')\n\t\tconfiguration.option('format').valueRequired().description('graphql|introspection|schema')\n\t\tconfiguration.option('source').valueRequired().description('migrations|definition')\n\t\tconfiguration.option('role').valueArray()\n\t\tconfiguration.option('normalize').valueNone()\n\t\tconfiguration.option('omit-acl').valueNone()\n\t\tconfiguration.option('omit-validation').valueNone()\n\t\tconfiguration.option('omit-actions').valueNone()\n\t\tconfiguration.option('omit-settings').valueNone()\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<number> {\n\t\tconst format = input.getOption('format') || 'graphql'\n\n\n\t\tconst schema = input.getOption('source') === 'migrations'\n\t\t\t? await this.schemaVersionBuilder.buildSchema()\n\t\t\t: await this.schemaLoader.loadSchema()\n\n\t\tconst filteredSchema = {\n\t\t\tmodel: schema.model,\n\t\t\tacl: input.getOption('omit-acl') ? emptySchema.acl : schema.acl,\n\t\t\tvalidation: input.getOption('omit-validation') ? emptySchema.validation : schema.validation,\n\t\t\tactions: input.getOption('omit-actions') ? emptySchema.actions : schema.actions,\n\t\t\tsettings: input.getOption('omit-settings') ? emptySchema.settings : schema.settings,\n\t\t}\n\n\t\tif (!validateSchemaAndPrintErrors(filteredSchema, 'Defined schema is invalid:')) {\n\t\t\treturn 1\n\t\t}\n\n\t\tconst permissionFactory = new PermissionFactory()\n\t\tconst inputRoles = input.getOption('role')\n\t\tconst schemaNormalized = input.getOption('normalize') ? normalizeSchema(filteredSchema) : filteredSchema\n\t\tconst permissions = permissionFactory.create(schemaNormalized, inputRoles || ['admin'])\n\t\tconst schemaBuilderFactory = new GraphQlSchemaBuilderFactory()\n\t\tconst authorizator = new Authorizator(permissions, schemaNormalized.acl.customPrimary ?? false)\n\t\tconst introspection = new IntrospectionSchemaFactory(\n\t\t\tschemaNormalized.model,\n\t\t\tnew EntityRulesResolver(schemaNormalized.validation, schemaNormalized.model),\n\t\t\tauthorizator,\n\t\t)\n\n\t\tconst printByLine = (out: string) => {\n\t\t\tout.split('\\n').forEach(line => {\n\t\t\t\tprocess.stdout.write(line + '\\n')\n\t\t\t})\n\t\t}\n\t\tif (format === 'schema') {\n\t\t\tif (inputRoles) {\n\t\t\t\tthrow `--roles option is not supported for \"schema\" format`\n\t\t\t}\n\t\t\tconst jsonString = JSON.stringify(schemaNormalized, null, '\\t')\n\t\t\tprintByLine(jsonString)\n\t\t} else if (format === 'introspection') {\n\t\t\tprintByLine(JSON.stringify(introspection.create(), null, '\\t'))\n\t\t} else if (format === 'graphql') {\n\t\t\tconst contentSchema = schemaBuilderFactory.create(schemaNormalized.model, authorizator).build()\n\t\t\tconst introspectionSchemaFactory = new IntrospectionSchemaDefinitionFactory(introspection)\n\t\t\tconst introspectionSchema = introspectionSchemaFactory.create()\n\t\t\tconst gqlSchema = mergeSchemas({\n\t\t\t\tschemas: [contentSchema, introspectionSchema],\n\t\t\t})\n\t\t\tgqlSchema.description = '' // this enforces schema definition print\n\t\t\tconst printedSchema = printSchema(gqlSchema).replace('\"\"\"\"\"\"\\n', '') // remove empty comment\n\t\t\tprintByLine(printedSchema)\n\t\t} else {\n\t\t\tthrow `Unknown format ${format}`\n\t\t}\n\n\t\treturn 0\n\t}\n}\n"],"names":["Command","schema","emptySchema","validateSchemaAndPrintErrors","PermissionFactory","normalizeSchema","GraphQlSchemaBuilderFactory","Authorizator","IntrospectionSchemaFactory","EntityRulesResolver","IntrospectionSchemaDefinitionFactory","mergeSchemas","printSchema"],"mappings":";;;;;;;;AA8BO,MAAM,kCAAkCA,UAAAA,Q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, IntrospectionSchemaFactory, EntityRulesResolver, IntrospectionSchemaDefinitionFactory } from "@contember/engine-content-api";
|
|
3
3
|
import { printSchema } from "graphql";
|
|
4
4
|
import { mergeSchemas } from "@graphql-tools/schema";
|
|
5
|
-
import { normalizeSchema } from "@contember/schema-utils";
|
|
5
|
+
import { emptySchema, normalizeSchema } from "@contember/schema-utils";
|
|
6
6
|
import { validateSchemaAndPrintErrors } from "../../lib/schema/SchemaValidationHelper.js";
|
|
7
7
|
class ProjectPrintSchemaCommand extends Command {
|
|
8
8
|
constructor(schemaLoader, schemaVersionBuilder) {
|
|
@@ -16,16 +16,27 @@ class ProjectPrintSchemaCommand extends Command {
|
|
|
16
16
|
configuration.option("source").valueRequired().description("migrations|definition");
|
|
17
17
|
configuration.option("role").valueArray();
|
|
18
18
|
configuration.option("normalize").valueNone();
|
|
19
|
+
configuration.option("omit-acl").valueNone();
|
|
20
|
+
configuration.option("omit-validation").valueNone();
|
|
21
|
+
configuration.option("omit-actions").valueNone();
|
|
22
|
+
configuration.option("omit-settings").valueNone();
|
|
19
23
|
}
|
|
20
24
|
async execute(input) {
|
|
21
25
|
const format = input.getOption("format") || "graphql";
|
|
22
26
|
const schema = input.getOption("source") === "migrations" ? await this.schemaVersionBuilder.buildSchema() : await this.schemaLoader.loadSchema();
|
|
23
|
-
|
|
27
|
+
const filteredSchema = {
|
|
28
|
+
model: schema.model,
|
|
29
|
+
acl: input.getOption("omit-acl") ? emptySchema.acl : schema.acl,
|
|
30
|
+
validation: input.getOption("omit-validation") ? emptySchema.validation : schema.validation,
|
|
31
|
+
actions: input.getOption("omit-actions") ? emptySchema.actions : schema.actions,
|
|
32
|
+
settings: input.getOption("omit-settings") ? emptySchema.settings : schema.settings
|
|
33
|
+
};
|
|
34
|
+
if (!validateSchemaAndPrintErrors(filteredSchema, "Defined schema is invalid:")) {
|
|
24
35
|
return 1;
|
|
25
36
|
}
|
|
26
37
|
const permissionFactory = new PermissionFactory();
|
|
27
38
|
const inputRoles = input.getOption("role");
|
|
28
|
-
const schemaNormalized = input.getOption("normalize") ? normalizeSchema(
|
|
39
|
+
const schemaNormalized = input.getOption("normalize") ? normalizeSchema(filteredSchema) : filteredSchema;
|
|
29
40
|
const permissions = permissionFactory.create(schemaNormalized, inputRoles || ["admin"]);
|
|
30
41
|
const schemaBuilderFactory = new GraphQlSchemaBuilderFactory();
|
|
31
42
|
const authorizator = new Authorizator(permissions, schemaNormalized.acl.customPrimary ?? false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectPrintSchemaCommand.js","sources":["../../../../../../packages/cli/src/commands/project/ProjectPrintSchemaCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport {\n\tAuthorizator,\n\tEntityRulesResolver,\n\tGraphQlSchemaBuilderFactory,\n\tIntrospectionSchemaDefinitionFactory,\n\tIntrospectionSchemaFactory,\n\tPermissionFactory,\n} from '@contember/engine-content-api'\nimport { printSchema } from 'graphql'\nimport { mergeSchemas } from '@graphql-tools/schema'\nimport { normalizeSchema } from '@contember/schema-utils'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader'\nimport { SchemaVersionBuilder } from '@contember/migrations-client'\nimport { validateSchemaAndPrintErrors } from '../../lib/schema/SchemaValidationHelper'\n\ntype Args = {\n}\n\ntype Options = {\n\trole?: string[]\n\tnormalize?: boolean\n\tformat?: 'graphql' | 'introspection' | 'schema'\n\tsource?: 'migrations' | 'definition'\n}\n\nexport class ProjectPrintSchemaCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Prints project schema')\n\t\tconfiguration.option('format').valueRequired().description('graphql|introspection|schema')\n\t\tconfiguration.option('source').valueRequired().description('migrations|definition')\n\t\tconfiguration.option('role').valueArray()\n\t\tconfiguration.option('normalize').valueNone()\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<number> {\n\t\tconst format = input.getOption('format') || 'graphql'\n\n\n\t\tconst schema = input.getOption('source') === 'migrations'\n\t\t\t? await this.schemaVersionBuilder.buildSchema()\n\t\t\t: await this.schemaLoader.loadSchema()\n\n\t\tif (!validateSchemaAndPrintErrors(
|
|
1
|
+
{"version":3,"file":"ProjectPrintSchemaCommand.js","sources":["../../../../../../packages/cli/src/commands/project/ProjectPrintSchemaCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport {\n\tAuthorizator,\n\tEntityRulesResolver,\n\tGraphQlSchemaBuilderFactory,\n\tIntrospectionSchemaDefinitionFactory,\n\tIntrospectionSchemaFactory,\n\tPermissionFactory,\n} from '@contember/engine-content-api'\nimport { printSchema } from 'graphql'\nimport { mergeSchemas } from '@graphql-tools/schema'\nimport { emptySchema, normalizeSchema } from '@contember/schema-utils'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader'\nimport { SchemaVersionBuilder } from '@contember/migrations-client'\nimport { validateSchemaAndPrintErrors } from '../../lib/schema/SchemaValidationHelper'\n\ntype Args = {\n}\n\ntype Options = {\n\trole?: string[]\n\tnormalize?: boolean\n\tformat?: 'graphql' | 'introspection' | 'schema'\n\tsource?: 'migrations' | 'definition'\n\t['omit-acl']?: boolean\n\t['omit-validation']?: boolean\n\t['omit-actions']?: boolean\n\t['omit-settings']?: boolean\n}\n\nexport class ProjectPrintSchemaCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Prints project schema')\n\t\tconfiguration.option('format').valueRequired().description('graphql|introspection|schema')\n\t\tconfiguration.option('source').valueRequired().description('migrations|definition')\n\t\tconfiguration.option('role').valueArray()\n\t\tconfiguration.option('normalize').valueNone()\n\t\tconfiguration.option('omit-acl').valueNone()\n\t\tconfiguration.option('omit-validation').valueNone()\n\t\tconfiguration.option('omit-actions').valueNone()\n\t\tconfiguration.option('omit-settings').valueNone()\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<number> {\n\t\tconst format = input.getOption('format') || 'graphql'\n\n\n\t\tconst schema = input.getOption('source') === 'migrations'\n\t\t\t? await this.schemaVersionBuilder.buildSchema()\n\t\t\t: await this.schemaLoader.loadSchema()\n\n\t\tconst filteredSchema = {\n\t\t\tmodel: schema.model,\n\t\t\tacl: input.getOption('omit-acl') ? emptySchema.acl : schema.acl,\n\t\t\tvalidation: input.getOption('omit-validation') ? emptySchema.validation : schema.validation,\n\t\t\tactions: input.getOption('omit-actions') ? emptySchema.actions : schema.actions,\n\t\t\tsettings: input.getOption('omit-settings') ? emptySchema.settings : schema.settings,\n\t\t}\n\n\t\tif (!validateSchemaAndPrintErrors(filteredSchema, 'Defined schema is invalid:')) {\n\t\t\treturn 1\n\t\t}\n\n\t\tconst permissionFactory = new PermissionFactory()\n\t\tconst inputRoles = input.getOption('role')\n\t\tconst schemaNormalized = input.getOption('normalize') ? normalizeSchema(filteredSchema) : filteredSchema\n\t\tconst permissions = permissionFactory.create(schemaNormalized, inputRoles || ['admin'])\n\t\tconst schemaBuilderFactory = new GraphQlSchemaBuilderFactory()\n\t\tconst authorizator = new Authorizator(permissions, schemaNormalized.acl.customPrimary ?? false)\n\t\tconst introspection = new IntrospectionSchemaFactory(\n\t\t\tschemaNormalized.model,\n\t\t\tnew EntityRulesResolver(schemaNormalized.validation, schemaNormalized.model),\n\t\t\tauthorizator,\n\t\t)\n\n\t\tconst printByLine = (out: string) => {\n\t\t\tout.split('\\n').forEach(line => {\n\t\t\t\tprocess.stdout.write(line + '\\n')\n\t\t\t})\n\t\t}\n\t\tif (format === 'schema') {\n\t\t\tif (inputRoles) {\n\t\t\t\tthrow `--roles option is not supported for \"schema\" format`\n\t\t\t}\n\t\t\tconst jsonString = JSON.stringify(schemaNormalized, null, '\\t')\n\t\t\tprintByLine(jsonString)\n\t\t} else if (format === 'introspection') {\n\t\t\tprintByLine(JSON.stringify(introspection.create(), null, '\\t'))\n\t\t} else if (format === 'graphql') {\n\t\t\tconst contentSchema = schemaBuilderFactory.create(schemaNormalized.model, authorizator).build()\n\t\t\tconst introspectionSchemaFactory = new IntrospectionSchemaDefinitionFactory(introspection)\n\t\t\tconst introspectionSchema = introspectionSchemaFactory.create()\n\t\t\tconst gqlSchema = mergeSchemas({\n\t\t\t\tschemas: [contentSchema, introspectionSchema],\n\t\t\t})\n\t\t\tgqlSchema.description = '' // this enforces schema definition print\n\t\t\tconst printedSchema = printSchema(gqlSchema).replace('\"\"\"\"\"\"\\n', '') // remove empty comment\n\t\t\tprintByLine(printedSchema)\n\t\t} else {\n\t\t\tthrow `Unknown format ${format}`\n\t\t}\n\n\t\treturn 0\n\t}\n}\n"],"names":[],"mappings":";;;;;;AA8BO,MAAM,kCAAkC,QAAuB;AAAA,EACrE,YACkB,cACA,sBAChB;AACK;AAHW,SAAA,eAAA;AACA,SAAA,uBAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,uBAAuB;AACjD,kBAAc,OAAO,QAAQ,EAAE,cAAc,EAAE,YAAY,8BAA8B;AACzF,kBAAc,OAAO,QAAQ,EAAE,cAAc,EAAE,YAAY,uBAAuB;AACpE,kBAAA,OAAO,MAAM,EAAE,WAAW;AAC1B,kBAAA,OAAO,WAAW,EAAE,UAAU;AAC9B,kBAAA,OAAO,UAAU,EAAE,UAAU;AAC7B,kBAAA,OAAO,iBAAiB,EAAE,UAAU;AACpC,kBAAA,OAAO,cAAc,EAAE,UAAU;AACjC,kBAAA,OAAO,eAAe,EAAE,UAAU;AAAA,EACjD;AAAA,EAEA,MAAgB,QAAQ,OAA8C;AACrE,UAAM,SAAS,MAAM,UAAU,QAAQ,KAAK;AAG5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,cAAc,UAAU,MAAM,GAAI,CAAC;AAAA,IAAA,WACpD,WAAW,WAAW;AAChC,YAAM,gBAAgB,qBAAqB,OAAO,iBAAiB,OAAO,YAAY,EAAE;AAClF,YAAA,6BAA6B,IAAI,qCAAqC,aAAa;AACnF,YAAA,sBAAsB,2BAA2B;AACvD,YAAM,YAAY,aAAa;AAAA,QAC9B,SAAS,CAAC,eAAe,mBAAmB;AAAA,MAAA,CAC5C;AACD,gBAAU,cAAc;AACxB,YAAM,gBAAgB,YAAY,SAAS,EAAE,QAAQ,YAAY,EAAE;AACnE,kBAAY,aAAa;AAAA,IAAA,OACnB;AACN,YAAM,kBAAkB,MAAM;AAAA,IAC/B;AAEO,WAAA;AAAA,EACR;AACD;"}
|
|
@@ -18,16 +18,27 @@ class ProjectPrintSchemaCommand extends cliCommon.Command {
|
|
|
18
18
|
configuration.option("source").valueRequired().description("migrations|definition");
|
|
19
19
|
configuration.option("role").valueArray();
|
|
20
20
|
configuration.option("normalize").valueNone();
|
|
21
|
+
configuration.option("omit-acl").valueNone();
|
|
22
|
+
configuration.option("omit-validation").valueNone();
|
|
23
|
+
configuration.option("omit-actions").valueNone();
|
|
24
|
+
configuration.option("omit-settings").valueNone();
|
|
21
25
|
}
|
|
22
26
|
async execute(input) {
|
|
23
27
|
const format = input.getOption("format") || "graphql";
|
|
24
28
|
const schema$1 = input.getOption("source") === "migrations" ? await this.schemaVersionBuilder.buildSchema() : await this.schemaLoader.loadSchema();
|
|
25
|
-
|
|
29
|
+
const filteredSchema = {
|
|
30
|
+
model: schema$1.model,
|
|
31
|
+
acl: input.getOption("omit-acl") ? schemaUtils.emptySchema.acl : schema$1.acl,
|
|
32
|
+
validation: input.getOption("omit-validation") ? schemaUtils.emptySchema.validation : schema$1.validation,
|
|
33
|
+
actions: input.getOption("omit-actions") ? schemaUtils.emptySchema.actions : schema$1.actions,
|
|
34
|
+
settings: input.getOption("omit-settings") ? schemaUtils.emptySchema.settings : schema$1.settings
|
|
35
|
+
};
|
|
36
|
+
if (!SchemaValidationHelper.validateSchemaAndPrintErrors(filteredSchema, "Defined schema is invalid:")) {
|
|
26
37
|
return 1;
|
|
27
38
|
}
|
|
28
39
|
const permissionFactory = new engineContentApi.PermissionFactory();
|
|
29
40
|
const inputRoles = input.getOption("role");
|
|
30
|
-
const schemaNormalized = input.getOption("normalize") ? schemaUtils.normalizeSchema(
|
|
41
|
+
const schemaNormalized = input.getOption("normalize") ? schemaUtils.normalizeSchema(filteredSchema) : filteredSchema;
|
|
31
42
|
const permissions = permissionFactory.create(schemaNormalized, inputRoles || ["admin"]);
|
|
32
43
|
const schemaBuilderFactory = new engineContentApi.GraphQlSchemaBuilderFactory();
|
|
33
44
|
const authorizator = new engineContentApi.Authorizator(permissions, schemaNormalized.acl.customPrimary ?? false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectPrintSchemaCommand.cjs","sources":["../../../../../../packages/cli/src/commands/project/ProjectPrintSchemaCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport {\n\tAuthorizator,\n\tEntityRulesResolver,\n\tGraphQlSchemaBuilderFactory,\n\tIntrospectionSchemaDefinitionFactory,\n\tIntrospectionSchemaFactory,\n\tPermissionFactory,\n} from '@contember/engine-content-api'\nimport { printSchema } from 'graphql'\nimport { mergeSchemas } from '@graphql-tools/schema'\nimport { normalizeSchema } from '@contember/schema-utils'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader'\nimport { SchemaVersionBuilder } from '@contember/migrations-client'\nimport { validateSchemaAndPrintErrors } from '../../lib/schema/SchemaValidationHelper'\n\ntype Args = {\n}\n\ntype Options = {\n\trole?: string[]\n\tnormalize?: boolean\n\tformat?: 'graphql' | 'introspection' | 'schema'\n\tsource?: 'migrations' | 'definition'\n}\n\nexport class ProjectPrintSchemaCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Prints project schema')\n\t\tconfiguration.option('format').valueRequired().description('graphql|introspection|schema')\n\t\tconfiguration.option('source').valueRequired().description('migrations|definition')\n\t\tconfiguration.option('role').valueArray()\n\t\tconfiguration.option('normalize').valueNone()\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<number> {\n\t\tconst format = input.getOption('format') || 'graphql'\n\n\n\t\tconst schema = input.getOption('source') === 'migrations'\n\t\t\t? await this.schemaVersionBuilder.buildSchema()\n\t\t\t: await this.schemaLoader.loadSchema()\n\n\t\tif (!validateSchemaAndPrintErrors(
|
|
1
|
+
{"version":3,"file":"ProjectPrintSchemaCommand.cjs","sources":["../../../../../../packages/cli/src/commands/project/ProjectPrintSchemaCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport {\n\tAuthorizator,\n\tEntityRulesResolver,\n\tGraphQlSchemaBuilderFactory,\n\tIntrospectionSchemaDefinitionFactory,\n\tIntrospectionSchemaFactory,\n\tPermissionFactory,\n} from '@contember/engine-content-api'\nimport { printSchema } from 'graphql'\nimport { mergeSchemas } from '@graphql-tools/schema'\nimport { emptySchema, normalizeSchema } from '@contember/schema-utils'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader'\nimport { SchemaVersionBuilder } from '@contember/migrations-client'\nimport { validateSchemaAndPrintErrors } from '../../lib/schema/SchemaValidationHelper'\n\ntype Args = {\n}\n\ntype Options = {\n\trole?: string[]\n\tnormalize?: boolean\n\tformat?: 'graphql' | 'introspection' | 'schema'\n\tsource?: 'migrations' | 'definition'\n\t['omit-acl']?: boolean\n\t['omit-validation']?: boolean\n\t['omit-actions']?: boolean\n\t['omit-settings']?: boolean\n}\n\nexport class ProjectPrintSchemaCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Prints project schema')\n\t\tconfiguration.option('format').valueRequired().description('graphql|introspection|schema')\n\t\tconfiguration.option('source').valueRequired().description('migrations|definition')\n\t\tconfiguration.option('role').valueArray()\n\t\tconfiguration.option('normalize').valueNone()\n\t\tconfiguration.option('omit-acl').valueNone()\n\t\tconfiguration.option('omit-validation').valueNone()\n\t\tconfiguration.option('omit-actions').valueNone()\n\t\tconfiguration.option('omit-settings').valueNone()\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<number> {\n\t\tconst format = input.getOption('format') || 'graphql'\n\n\n\t\tconst schema = input.getOption('source') === 'migrations'\n\t\t\t? await this.schemaVersionBuilder.buildSchema()\n\t\t\t: await this.schemaLoader.loadSchema()\n\n\t\tconst filteredSchema = {\n\t\t\tmodel: schema.model,\n\t\t\tacl: input.getOption('omit-acl') ? emptySchema.acl : schema.acl,\n\t\t\tvalidation: input.getOption('omit-validation') ? emptySchema.validation : schema.validation,\n\t\t\tactions: input.getOption('omit-actions') ? emptySchema.actions : schema.actions,\n\t\t\tsettings: input.getOption('omit-settings') ? emptySchema.settings : schema.settings,\n\t\t}\n\n\t\tif (!validateSchemaAndPrintErrors(filteredSchema, 'Defined schema is invalid:')) {\n\t\t\treturn 1\n\t\t}\n\n\t\tconst permissionFactory = new PermissionFactory()\n\t\tconst inputRoles = input.getOption('role')\n\t\tconst schemaNormalized = input.getOption('normalize') ? normalizeSchema(filteredSchema) : filteredSchema\n\t\tconst permissions = permissionFactory.create(schemaNormalized, inputRoles || ['admin'])\n\t\tconst schemaBuilderFactory = new GraphQlSchemaBuilderFactory()\n\t\tconst authorizator = new Authorizator(permissions, schemaNormalized.acl.customPrimary ?? false)\n\t\tconst introspection = new IntrospectionSchemaFactory(\n\t\t\tschemaNormalized.model,\n\t\t\tnew EntityRulesResolver(schemaNormalized.validation, schemaNormalized.model),\n\t\t\tauthorizator,\n\t\t)\n\n\t\tconst printByLine = (out: string) => {\n\t\t\tout.split('\\n').forEach(line => {\n\t\t\t\tprocess.stdout.write(line + '\\n')\n\t\t\t})\n\t\t}\n\t\tif (format === 'schema') {\n\t\t\tif (inputRoles) {\n\t\t\t\tthrow `--roles option is not supported for \"schema\" format`\n\t\t\t}\n\t\t\tconst jsonString = JSON.stringify(schemaNormalized, null, '\\t')\n\t\t\tprintByLine(jsonString)\n\t\t} else if (format === 'introspection') {\n\t\t\tprintByLine(JSON.stringify(introspection.create(), null, '\\t'))\n\t\t} else if (format === 'graphql') {\n\t\t\tconst contentSchema = schemaBuilderFactory.create(schemaNormalized.model, authorizator).build()\n\t\t\tconst introspectionSchemaFactory = new IntrospectionSchemaDefinitionFactory(introspection)\n\t\t\tconst introspectionSchema = introspectionSchemaFactory.create()\n\t\t\tconst gqlSchema = mergeSchemas({\n\t\t\t\tschemas: [contentSchema, introspectionSchema],\n\t\t\t})\n\t\t\tgqlSchema.description = '' // this enforces schema definition print\n\t\t\tconst printedSchema = printSchema(gqlSchema).replace('\"\"\"\"\"\"\\n', '') // remove empty comment\n\t\t\tprintByLine(printedSchema)\n\t\t} else {\n\t\t\tthrow `Unknown format ${format}`\n\t\t}\n\n\t\treturn 0\n\t}\n}\n"],"names":["Command","schema","emptySchema","validateSchemaAndPrintErrors","PermissionFactory","normalizeSchema","GraphQlSchemaBuilderFactory","Authorizator","IntrospectionSchemaFactory","EntityRulesResolver","IntrospectionSchemaDefinitionFactory","mergeSchemas","printSchema"],"mappings":";;;;;;;;AA8BO,MAAM,kCAAkCA,UAAAA,QAAuB;AAAA,EACrE,YACkB,cACA,sBAChB;AACK;AAHW,SAAA,eAAA;AACA,SAAA,uBAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,uBAAuB;AACjD,kBAAc,OAAO,QAAQ,EAAE,cAAc,EAAE,YAAY,8BAA8B;AACzF,kBAAc,OA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,iBAAiB;AAAA,MACjB,IAAIC,iBAAA,oBAAoB,iBAAiB,YAAY,iBAAiB,KAAK;AAAA,MAC3E;AAAA,IAAA;AAGK,UAAA,cAAc,CAAC,QAAgB;AACpC,UAAI,MAAM,IAAI,EAAE,QAAQ,CAAQ,SAAA;AACvB,gBAAA,OAAO,MAAM,OAAO,IAAI;AAAA,MAAA,CAChC;AAAA,IAAA;AAEF,QAAI,WAAW,UAAU;AACxB,UAAI,YAAY;AACT,cAAA;AAAA,MACP;AACA,YAAM,aAAa,KAAK,UAAU,kBAAkB,MAAM,GAAI;AAC9D,kBAAY,UAAU;AAAA,IAAA,WACZ,WAAW,iBAAiB;AACtC,kBAAY,KAAK,UAAU,cAAc,UAAU,MAAM,GAAI,CAAC;AAAA,IAAA,WACpD,WAAW,WAAW;AAChC,YAAM,gBAAgB,qBAAqB,OAAO,iBAAiB,OAAO,YAAY,EAAE;AAClF,YAAA,6BAA6B,IAAIC,sDAAqC,aAAa;AACnF,YAAA,sBAAsB,2BAA2B;AACvD,YAAM,YAAYC,OAAAA,aAAa;AAAA,QAC9B,SAAS,CAAC,eAAe,mBAAmB;AAAA,MAAA,CAC5C;AACD,gBAAU,cAAc;AACxB,YAAM,gBAAgBC,QAAAA,YAAY,SAAS,EAAE,QAAQ,YAAY,EAAE;AACnE,kBAAY,aAAa;AAAA,IAAA,OACnB;AACN,YAAM,kBAAkB,MAAM;AAAA,IAC/B;AAEO,WAAA;AAAA,EACR;AACD;;"}
|
|
@@ -2,7 +2,7 @@ import { Command } from "@contember/cli-common";
|
|
|
2
2
|
import { PermissionFactory, GraphQlSchemaBuilderFactory, Authorizator, IntrospectionSchemaFactory, EntityRulesResolver, IntrospectionSchemaDefinitionFactory } from "@contember/engine-content-api";
|
|
3
3
|
import { printSchema } from "graphql";
|
|
4
4
|
import { mergeSchemas } from "@graphql-tools/schema";
|
|
5
|
-
import { normalizeSchema } from "@contember/schema-utils";
|
|
5
|
+
import { emptySchema, normalizeSchema } from "@contember/schema-utils";
|
|
6
6
|
import { validateSchemaAndPrintErrors } from "../../lib/schema/SchemaValidationHelper.js";
|
|
7
7
|
class ProjectPrintSchemaCommand extends Command {
|
|
8
8
|
constructor(schemaLoader, schemaVersionBuilder) {
|
|
@@ -16,16 +16,27 @@ class ProjectPrintSchemaCommand extends Command {
|
|
|
16
16
|
configuration.option("source").valueRequired().description("migrations|definition");
|
|
17
17
|
configuration.option("role").valueArray();
|
|
18
18
|
configuration.option("normalize").valueNone();
|
|
19
|
+
configuration.option("omit-acl").valueNone();
|
|
20
|
+
configuration.option("omit-validation").valueNone();
|
|
21
|
+
configuration.option("omit-actions").valueNone();
|
|
22
|
+
configuration.option("omit-settings").valueNone();
|
|
19
23
|
}
|
|
20
24
|
async execute(input) {
|
|
21
25
|
const format = input.getOption("format") || "graphql";
|
|
22
26
|
const schema = input.getOption("source") === "migrations" ? await this.schemaVersionBuilder.buildSchema() : await this.schemaLoader.loadSchema();
|
|
23
|
-
|
|
27
|
+
const filteredSchema = {
|
|
28
|
+
model: schema.model,
|
|
29
|
+
acl: input.getOption("omit-acl") ? emptySchema.acl : schema.acl,
|
|
30
|
+
validation: input.getOption("omit-validation") ? emptySchema.validation : schema.validation,
|
|
31
|
+
actions: input.getOption("omit-actions") ? emptySchema.actions : schema.actions,
|
|
32
|
+
settings: input.getOption("omit-settings") ? emptySchema.settings : schema.settings
|
|
33
|
+
};
|
|
34
|
+
if (!validateSchemaAndPrintErrors(filteredSchema, "Defined schema is invalid:")) {
|
|
24
35
|
return 1;
|
|
25
36
|
}
|
|
26
37
|
const permissionFactory = new PermissionFactory();
|
|
27
38
|
const inputRoles = input.getOption("role");
|
|
28
|
-
const schemaNormalized = input.getOption("normalize") ? normalizeSchema(
|
|
39
|
+
const schemaNormalized = input.getOption("normalize") ? normalizeSchema(filteredSchema) : filteredSchema;
|
|
29
40
|
const permissions = permissionFactory.create(schemaNormalized, inputRoles || ["admin"]);
|
|
30
41
|
const schemaBuilderFactory = new GraphQlSchemaBuilderFactory();
|
|
31
42
|
const authorizator = new Authorizator(permissions, schemaNormalized.acl.customPrimary ?? false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectPrintSchemaCommand.js","sources":["../../../../../../packages/cli/src/commands/project/ProjectPrintSchemaCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport {\n\tAuthorizator,\n\tEntityRulesResolver,\n\tGraphQlSchemaBuilderFactory,\n\tIntrospectionSchemaDefinitionFactory,\n\tIntrospectionSchemaFactory,\n\tPermissionFactory,\n} from '@contember/engine-content-api'\nimport { printSchema } from 'graphql'\nimport { mergeSchemas } from '@graphql-tools/schema'\nimport { normalizeSchema } from '@contember/schema-utils'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader'\nimport { SchemaVersionBuilder } from '@contember/migrations-client'\nimport { validateSchemaAndPrintErrors } from '../../lib/schema/SchemaValidationHelper'\n\ntype Args = {\n}\n\ntype Options = {\n\trole?: string[]\n\tnormalize?: boolean\n\tformat?: 'graphql' | 'introspection' | 'schema'\n\tsource?: 'migrations' | 'definition'\n}\n\nexport class ProjectPrintSchemaCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Prints project schema')\n\t\tconfiguration.option('format').valueRequired().description('graphql|introspection|schema')\n\t\tconfiguration.option('source').valueRequired().description('migrations|definition')\n\t\tconfiguration.option('role').valueArray()\n\t\tconfiguration.option('normalize').valueNone()\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<number> {\n\t\tconst format = input.getOption('format') || 'graphql'\n\n\n\t\tconst schema = input.getOption('source') === 'migrations'\n\t\t\t? await this.schemaVersionBuilder.buildSchema()\n\t\t\t: await this.schemaLoader.loadSchema()\n\n\t\tif (!validateSchemaAndPrintErrors(
|
|
1
|
+
{"version":3,"file":"ProjectPrintSchemaCommand.js","sources":["../../../../../../packages/cli/src/commands/project/ProjectPrintSchemaCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport {\n\tAuthorizator,\n\tEntityRulesResolver,\n\tGraphQlSchemaBuilderFactory,\n\tIntrospectionSchemaDefinitionFactory,\n\tIntrospectionSchemaFactory,\n\tPermissionFactory,\n} from '@contember/engine-content-api'\nimport { printSchema } from 'graphql'\nimport { mergeSchemas } from '@graphql-tools/schema'\nimport { emptySchema, normalizeSchema } from '@contember/schema-utils'\nimport { SchemaLoader } from '../../lib/schema/SchemaLoader'\nimport { SchemaVersionBuilder } from '@contember/migrations-client'\nimport { validateSchemaAndPrintErrors } from '../../lib/schema/SchemaValidationHelper'\n\ntype Args = {\n}\n\ntype Options = {\n\trole?: string[]\n\tnormalize?: boolean\n\tformat?: 'graphql' | 'introspection' | 'schema'\n\tsource?: 'migrations' | 'definition'\n\t['omit-acl']?: boolean\n\t['omit-validation']?: boolean\n\t['omit-actions']?: boolean\n\t['omit-settings']?: boolean\n}\n\nexport class ProjectPrintSchemaCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly schemaLoader: SchemaLoader,\n\t\tprivate readonly schemaVersionBuilder: SchemaVersionBuilder,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Prints project schema')\n\t\tconfiguration.option('format').valueRequired().description('graphql|introspection|schema')\n\t\tconfiguration.option('source').valueRequired().description('migrations|definition')\n\t\tconfiguration.option('role').valueArray()\n\t\tconfiguration.option('normalize').valueNone()\n\t\tconfiguration.option('omit-acl').valueNone()\n\t\tconfiguration.option('omit-validation').valueNone()\n\t\tconfiguration.option('omit-actions').valueNone()\n\t\tconfiguration.option('omit-settings').valueNone()\n\t}\n\n\tprotected async execute(input: Input<Args, Options>): Promise<number> {\n\t\tconst format = input.getOption('format') || 'graphql'\n\n\n\t\tconst schema = input.getOption('source') === 'migrations'\n\t\t\t? await this.schemaVersionBuilder.buildSchema()\n\t\t\t: await this.schemaLoader.loadSchema()\n\n\t\tconst filteredSchema = {\n\t\t\tmodel: schema.model,\n\t\t\tacl: input.getOption('omit-acl') ? emptySchema.acl : schema.acl,\n\t\t\tvalidation: input.getOption('omit-validation') ? emptySchema.validation : schema.validation,\n\t\t\tactions: input.getOption('omit-actions') ? emptySchema.actions : schema.actions,\n\t\t\tsettings: input.getOption('omit-settings') ? emptySchema.settings : schema.settings,\n\t\t}\n\n\t\tif (!validateSchemaAndPrintErrors(filteredSchema, 'Defined schema is invalid:')) {\n\t\t\treturn 1\n\t\t}\n\n\t\tconst permissionFactory = new PermissionFactory()\n\t\tconst inputRoles = input.getOption('role')\n\t\tconst schemaNormalized = input.getOption('normalize') ? normalizeSchema(filteredSchema) : filteredSchema\n\t\tconst permissions = permissionFactory.create(schemaNormalized, inputRoles || ['admin'])\n\t\tconst schemaBuilderFactory = new GraphQlSchemaBuilderFactory()\n\t\tconst authorizator = new Authorizator(permissions, schemaNormalized.acl.customPrimary ?? false)\n\t\tconst introspection = new IntrospectionSchemaFactory(\n\t\t\tschemaNormalized.model,\n\t\t\tnew EntityRulesResolver(schemaNormalized.validation, schemaNormalized.model),\n\t\t\tauthorizator,\n\t\t)\n\n\t\tconst printByLine = (out: string) => {\n\t\t\tout.split('\\n').forEach(line => {\n\t\t\t\tprocess.stdout.write(line + '\\n')\n\t\t\t})\n\t\t}\n\t\tif (format === 'schema') {\n\t\t\tif (inputRoles) {\n\t\t\t\tthrow `--roles option is not supported for \"schema\" format`\n\t\t\t}\n\t\t\tconst jsonString = JSON.stringify(schemaNormalized, null, '\\t')\n\t\t\tprintByLine(jsonString)\n\t\t} else if (format === 'introspection') {\n\t\t\tprintByLine(JSON.stringify(introspection.create(), null, '\\t'))\n\t\t} else if (format === 'graphql') {\n\t\t\tconst contentSchema = schemaBuilderFactory.create(schemaNormalized.model, authorizator).build()\n\t\t\tconst introspectionSchemaFactory = new IntrospectionSchemaDefinitionFactory(introspection)\n\t\t\tconst introspectionSchema = introspectionSchemaFactory.create()\n\t\t\tconst gqlSchema = mergeSchemas({\n\t\t\t\tschemas: [contentSchema, introspectionSchema],\n\t\t\t})\n\t\t\tgqlSchema.description = '' // this enforces schema definition print\n\t\t\tconst printedSchema = printSchema(gqlSchema).replace('\"\"\"\"\"\"\\n', '') // remove empty comment\n\t\t\tprintByLine(printedSchema)\n\t\t} else {\n\t\t\tthrow `Unknown format ${format}`\n\t\t}\n\n\t\treturn 0\n\t}\n}\n"],"names":[],"mappings":";;;;;;AA8BO,MAAM,kCAAkC,QAAuB;AAAA,EACrE,YACkB,cACA,sBAChB;AACK;AAHW,SAAA,eAAA;AACA,SAAA,uBAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,uBAAuB;AACjD,kBAAc,OAAO,QAAQ,EAAE,cAAc,EAAE,YAAY,8BAA8B;AACzF,kBAAc,OAAO,QAAQ,EAAE,cAAc,EAAE,YAAY,uBAAuB;AACpE,kBAAA,OAAO,MAAM,EAAE,WAAW;AAC1B,kBAAA,OAAO,WAAW,EAAE,UAAU;AAC9B,kBAAA,OAAO,UAAU,EAAE,UAAU;AAC7B,kBAAA,OAAO,iBAAiB,EAAE,UAAU;AACpC,kBAAA,OAAO,cAAc,EAAE,UAAU;AACjC,kBAAA,OAAO,eAAe,EAAE,UAAU;AAAA,EACjD;AAAA,EAEA,MAAgB,QAAQ,OAA8C;AACrE,UAAM,SAAS,MAAM,UAAU,QAAQ,KAAK;AAG5C,UAAM,SAAS,MAAM,UAAU,QAAQ,MAAM,eAC1C,MAAM,KAAK,qBAAqB,YAAY,IAC5C,MAAM,KAAK,aAAa,WAAW;AAEtC,UAAM,iBAAiB;AAAA,MACtB,OAAO,OAAO;AAAA,MACd,KAAK,MAAM,UAAU,UAAU,IAAI,YAAY,MAAM,OAAO;AAAA,MAC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AA,QAC9B,SAAS,CAAC,eAAe,mBAAmB;AAAA,MAAA,CAC5C;AACD,gBAAU,cAAc;AACxB,YAAM,gBAAgB,YAAY,SAAS,EAAE,QAAQ,YAAY,EAAE;AACnE,kBAAY,aAAa;AAAA,IAAA,OACnB;AACN,YAAM,kBAAkB,MAAM;AAAA,IAC/B;AAEO,WAAA;AAAA,EACR;AACD;"}
|
|
@@ -7,6 +7,10 @@ type Options = {
|
|
|
7
7
|
normalize?: boolean;
|
|
8
8
|
format?: 'graphql' | 'introspection' | 'schema';
|
|
9
9
|
source?: 'migrations' | 'definition';
|
|
10
|
+
['omit-acl']?: boolean;
|
|
11
|
+
['omit-validation']?: boolean;
|
|
12
|
+
['omit-actions']?: boolean;
|
|
13
|
+
['omit-settings']?: boolean;
|
|
10
14
|
};
|
|
11
15
|
export declare class ProjectPrintSchemaCommand extends Command<Args, Options> {
|
|
12
16
|
private readonly schemaLoader;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectPrintSchemaCommand.d.ts","sourceRoot":"","sources":["../../../../src/commands/project/ProjectPrintSchemaCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAY5E,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AAGnE,KAAK,IAAI,GAAG,EACX,CAAA;AAED,KAAK,OAAO,GAAG;IACd,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,MAAM,CAAC,EAAE,SAAS,GAAG,eAAe,GAAG,QAAQ,CAAA;IAC/C,MAAM,CAAC,EAAE,YAAY,GAAG,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"ProjectPrintSchemaCommand.d.ts","sourceRoot":"","sources":["../../../../src/commands/project/ProjectPrintSchemaCommand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