@contember/engine-content-api 2.0.0 → 2.1.0-alpha.1

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.
Files changed (157) hide show
  1. package/dist/development/src/ExecutionContainer.cjs +1 -1
  2. package/dist/development/src/ExecutionContainer.cjs.map +1 -1
  3. package/dist/development/src/ExecutionContainer.js +1 -1
  4. package/dist/development/src/ExecutionContainer.js.map +1 -1
  5. package/dist/development/src/input-validation/ColumnValueResolver.cjs +1 -1
  6. package/dist/development/src/input-validation/ColumnValueResolver.cjs.map +1 -1
  7. package/dist/development/src/input-validation/ColumnValueResolver.js +1 -1
  8. package/dist/development/src/input-validation/ColumnValueResolver.js.map +1 -1
  9. package/dist/development/src/mapper/insert/Inserter.cjs +3 -2
  10. package/dist/development/src/mapper/insert/Inserter.cjs.map +1 -1
  11. package/dist/development/src/mapper/insert/Inserter.js +3 -2
  12. package/dist/development/src/mapper/insert/Inserter.js.map +1 -1
  13. package/dist/development/src/mapper/insert/SqlCreateInputProcessor.cjs +3 -2
  14. package/dist/development/src/mapper/insert/SqlCreateInputProcessor.cjs.map +1 -1
  15. package/dist/development/src/mapper/insert/SqlCreateInputProcessor.js +3 -2
  16. package/dist/development/src/mapper/insert/SqlCreateInputProcessor.js.map +1 -1
  17. package/dist/development/src/mapper/select/ConditionBuilder.cjs +9 -2
  18. package/dist/development/src/mapper/select/ConditionBuilder.cjs.map +1 -1
  19. package/dist/development/src/mapper/select/ConditionBuilder.js +10 -3
  20. package/dist/development/src/mapper/select/ConditionBuilder.js.map +1 -1
  21. package/dist/development/src/mapper/select/WhereBuilder.cjs +3 -3
  22. package/dist/development/src/mapper/select/WhereBuilder.cjs.map +1 -1
  23. package/dist/development/src/mapper/select/WhereBuilder.js +3 -3
  24. package/dist/development/src/mapper/select/WhereBuilder.js.map +1 -1
  25. package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs +3 -0
  26. package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
  27. package/dist/development/src/mapper/select/handlers/FieldsVisitor.js +3 -0
  28. package/dist/development/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
  29. package/dist/development/src/schema/ColumnTypeResolver.cjs +9 -0
  30. package/dist/development/src/schema/ColumnTypeResolver.cjs.map +1 -1
  31. package/dist/development/src/schema/ColumnTypeResolver.js +10 -1
  32. package/dist/development/src/schema/ColumnTypeResolver.js.map +1 -1
  33. package/dist/development/src/schema/ConditionTypeProvider.cjs +35 -23
  34. package/dist/development/src/schema/ConditionTypeProvider.cjs.map +1 -1
  35. package/dist/development/src/schema/ConditionTypeProvider.js +36 -24
  36. package/dist/development/src/schema/ConditionTypeProvider.js.map +1 -1
  37. package/dist/development/src/schema/CustomTypesProvider.cjs +30 -0
  38. package/dist/development/src/schema/CustomTypesProvider.cjs.map +1 -1
  39. package/dist/development/src/schema/CustomTypesProvider.js +30 -0
  40. package/dist/development/src/schema/CustomTypesProvider.js.map +1 -1
  41. package/dist/development/src/schema/OrderByTypeProvider.cjs +6 -1
  42. package/dist/development/src/schema/OrderByTypeProvider.cjs.map +1 -1
  43. package/dist/development/src/schema/OrderByTypeProvider.js +6 -1
  44. package/dist/development/src/schema/OrderByTypeProvider.js.map +1 -1
  45. package/dist/development/src/schema/WhereTypeProvider.cjs +1 -1
  46. package/dist/development/src/schema/WhereTypeProvider.cjs.map +1 -1
  47. package/dist/development/src/schema/WhereTypeProvider.js +1 -1
  48. package/dist/development/src/schema/WhereTypeProvider.js.map +1 -1
  49. package/dist/development/src/schema/entities/FieldTypeVisitor.cjs +3 -3
  50. package/dist/development/src/schema/entities/FieldTypeVisitor.cjs.map +1 -1
  51. package/dist/development/src/schema/entities/FieldTypeVisitor.js +3 -3
  52. package/dist/development/src/schema/entities/FieldTypeVisitor.js.map +1 -1
  53. package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.cjs +1 -1
  54. package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.cjs.map +1 -1
  55. package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.js +1 -1
  56. package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.js.map +1 -1
  57. package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs +1 -1
  58. package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs.map +1 -1
  59. package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.js +1 -1
  60. package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.js.map +1 -1
  61. package/dist/production/src/ExecutionContainer.cjs +1 -1
  62. package/dist/production/src/ExecutionContainer.cjs.map +1 -1
  63. package/dist/production/src/ExecutionContainer.js +1 -1
  64. package/dist/production/src/ExecutionContainer.js.map +1 -1
  65. package/dist/production/src/input-validation/ColumnValueResolver.cjs +1 -1
  66. package/dist/production/src/input-validation/ColumnValueResolver.cjs.map +1 -1
  67. package/dist/production/src/input-validation/ColumnValueResolver.js +1 -1
  68. package/dist/production/src/input-validation/ColumnValueResolver.js.map +1 -1
  69. package/dist/production/src/mapper/insert/Inserter.cjs +3 -2
  70. package/dist/production/src/mapper/insert/Inserter.cjs.map +1 -1
  71. package/dist/production/src/mapper/insert/Inserter.js +3 -2
  72. package/dist/production/src/mapper/insert/Inserter.js.map +1 -1
  73. package/dist/production/src/mapper/insert/SqlCreateInputProcessor.cjs +3 -2
  74. package/dist/production/src/mapper/insert/SqlCreateInputProcessor.cjs.map +1 -1
  75. package/dist/production/src/mapper/insert/SqlCreateInputProcessor.js +3 -2
  76. package/dist/production/src/mapper/insert/SqlCreateInputProcessor.js.map +1 -1
  77. package/dist/production/src/mapper/select/ConditionBuilder.cjs +9 -2
  78. package/dist/production/src/mapper/select/ConditionBuilder.cjs.map +1 -1
  79. package/dist/production/src/mapper/select/ConditionBuilder.js +10 -3
  80. package/dist/production/src/mapper/select/ConditionBuilder.js.map +1 -1
  81. package/dist/production/src/mapper/select/WhereBuilder.cjs +3 -3
  82. package/dist/production/src/mapper/select/WhereBuilder.cjs.map +1 -1
  83. package/dist/production/src/mapper/select/WhereBuilder.js +3 -3
  84. package/dist/production/src/mapper/select/WhereBuilder.js.map +1 -1
  85. package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs +3 -0
  86. package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
  87. package/dist/production/src/mapper/select/handlers/FieldsVisitor.js +3 -0
  88. package/dist/production/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
  89. package/dist/production/src/schema/ColumnTypeResolver.cjs +9 -0
  90. package/dist/production/src/schema/ColumnTypeResolver.cjs.map +1 -1
  91. package/dist/production/src/schema/ColumnTypeResolver.js +10 -1
  92. package/dist/production/src/schema/ColumnTypeResolver.js.map +1 -1
  93. package/dist/production/src/schema/ConditionTypeProvider.cjs +35 -23
  94. package/dist/production/src/schema/ConditionTypeProvider.cjs.map +1 -1
  95. package/dist/production/src/schema/ConditionTypeProvider.js +36 -24
  96. package/dist/production/src/schema/ConditionTypeProvider.js.map +1 -1
  97. package/dist/production/src/schema/CustomTypesProvider.cjs +30 -0
  98. package/dist/production/src/schema/CustomTypesProvider.cjs.map +1 -1
  99. package/dist/production/src/schema/CustomTypesProvider.js +30 -0
  100. package/dist/production/src/schema/CustomTypesProvider.js.map +1 -1
  101. package/dist/production/src/schema/OrderByTypeProvider.cjs +6 -1
  102. package/dist/production/src/schema/OrderByTypeProvider.cjs.map +1 -1
  103. package/dist/production/src/schema/OrderByTypeProvider.js +6 -1
  104. package/dist/production/src/schema/OrderByTypeProvider.js.map +1 -1
  105. package/dist/production/src/schema/WhereTypeProvider.cjs +1 -1
  106. package/dist/production/src/schema/WhereTypeProvider.cjs.map +1 -1
  107. package/dist/production/src/schema/WhereTypeProvider.js +1 -1
  108. package/dist/production/src/schema/WhereTypeProvider.js.map +1 -1
  109. package/dist/production/src/schema/entities/FieldTypeVisitor.cjs +3 -3
  110. package/dist/production/src/schema/entities/FieldTypeVisitor.cjs.map +1 -1
  111. package/dist/production/src/schema/entities/FieldTypeVisitor.js +3 -3
  112. package/dist/production/src/schema/entities/FieldTypeVisitor.js.map +1 -1
  113. package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.cjs +1 -1
  114. package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.cjs.map +1 -1
  115. package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.js +1 -1
  116. package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.js.map +1 -1
  117. package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs +1 -1
  118. package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs.map +1 -1
  119. package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.js +1 -1
  120. package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.js.map +1 -1
  121. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  122. package/dist/types/mapper/insert/Inserter.d.ts +4 -1
  123. package/dist/types/mapper/insert/Inserter.d.ts.map +1 -1
  124. package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts +4 -1
  125. package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts.map +1 -1
  126. package/dist/types/mapper/select/ConditionBuilder.d.ts +2 -2
  127. package/dist/types/mapper/select/ConditionBuilder.d.ts.map +1 -1
  128. package/dist/types/mapper/select/handlers/FieldsVisitor.d.ts.map +1 -1
  129. package/dist/types/schema/ColumnTypeResolver.d.ts +5 -5
  130. package/dist/types/schema/ColumnTypeResolver.d.ts.map +1 -1
  131. package/dist/types/schema/ConditionTypeProvider.d.ts +1 -0
  132. package/dist/types/schema/ConditionTypeProvider.d.ts.map +1 -1
  133. package/dist/types/schema/CustomTypesProvider.d.ts +1 -0
  134. package/dist/types/schema/CustomTypesProvider.d.ts.map +1 -1
  135. package/dist/types/schema/OrderByTypeProvider.d.ts.map +1 -1
  136. package/dist/types/schema/mutations/UpdateEntityInputFieldVisitor.d.ts +1 -1
  137. package/dist/types/tsconfig.tsbuildinfo +1 -1
  138. package/package.json +10 -10
  139. package/src/ExecutionContainer.ts +1 -1
  140. package/src/input-validation/ColumnValueResolver.ts +1 -1
  141. package/src/mapper/insert/Inserter.ts +2 -1
  142. package/src/mapper/insert/SqlCreateInputProcessor.ts +2 -1
  143. package/src/mapper/select/ConditionBuilder.ts +19 -5
  144. package/src/mapper/select/WhereBuilder.ts +3 -3
  145. package/src/mapper/select/handlers/FieldsVisitor.ts +3 -0
  146. package/src/schema/ColumnTypeResolver.ts +15 -3
  147. package/src/schema/ConditionTypeProvider.ts +40 -25
  148. package/src/schema/CustomTypesProvider.ts +37 -0
  149. package/src/schema/OrderByTypeProvider.ts +6 -1
  150. package/src/schema/WhereTypeProvider.ts +1 -1
  151. package/src/schema/entities/FieldTypeVisitor.ts +3 -3
  152. package/src/schema/mutations/CreateEntityInputFieldVisitor.ts +1 -1
  153. package/src/schema/mutations/UpdateEntityInputFieldVisitor.ts +1 -1
  154. package/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.ts +37 -1
  155. package/tests/cases/integration/graphQlSchema/schema-aliased-type.gql +6 -0
  156. package/tests/cases/integration/graphQlSchema/schema-array.gql +257 -0
  157. package/tests/cases/integration/graphQlSchema/schema-column-types.gql +420 -0
@@ -1,4 +1,4 @@
1
- import { GraphQLScalarType, GraphQLBoolean, GraphQLFloat, GraphQLString, GraphQLInt } from "graphql";
1
+ import { GraphQLScalarType, GraphQLList, GraphQLNonNull, GraphQLBoolean, GraphQLFloat, GraphQLString, GraphQLInt } from "graphql";
2
2
  import { Model } from "@contember/schema";
3
3
  import { ImplementationException } from "../exception.js";
4
4
  import { singletonFactory } from "../utils/singletonFactory.js";
@@ -29,6 +29,13 @@ class ColumnTypeResolver {
29
29
  };
30
30
  }
31
31
  getType(column) {
32
+ const baseType = this.getBaseType(column);
33
+ return [
34
+ column.list ? new GraphQLList(new GraphQLNonNull(baseType)) : baseType,
35
+ baseType
36
+ ];
37
+ }
38
+ getBaseType(column) {
32
39
  if (column.typeAlias) {
33
40
  if (column.type === Model.ColumnType.Enum) {
34
41
  throw new Error("GraphQL type alias cannot be specified for enum type");
@@ -66,6 +73,8 @@ class ColumnTypeResolver {
66
73
  return GraphQLBoolean;
67
74
  case Model.ColumnType.DateTime:
68
75
  return this.customTypeProvider.dateTimeType;
76
+ case Model.ColumnType.Time:
77
+ return this.customTypeProvider.timeType;
69
78
  case Model.ColumnType.Date:
70
79
  return this.customTypeProvider.dateType;
71
80
  case Model.ColumnType.Json:
@@ -1 +1 @@
1
- {"version":3,"file":"ColumnTypeResolver.js","sources":["../../../../../packages/engine-content-api/src/schema/ColumnTypeResolver.ts"],"sourcesContent":["import { GraphQLBoolean, GraphQLEnumType, GraphQLFloat, GraphQLInt, GraphQLScalarType, GraphQLString } from 'graphql'\nimport { Model } from '@contember/schema'\nimport { EnumsProvider } from './EnumsProvider'\nimport { CustomTypesProvider } from './CustomTypesProvider'\nimport { ImplementationException } from '../exception'\nimport { singletonFactory } from '../utils'\n\ntype ScalarType = Exclude<Model.ColumnType, Model.ColumnType.Enum>\n\nexport class ColumnTypeResolver {\n\tprivate schema: Model.Schema\n\tprivate enumsProvider: EnumsProvider\n\n\tprivate readonly aliasedTypes = singletonFactory<{ scalar: GraphQLScalarType; base: ScalarType }, string, ScalarType>(\n\t\tthis.createAliasedType.bind(this),\n\t)\n\n\tconstructor(\n\t\tschema: Model.Schema,\n\t\tenumsProvider: EnumsProvider,\n\t\tprivate readonly customTypeProvider: CustomTypesProvider,\n\t) {\n\t\tthis.schema = schema\n\t\tthis.enumsProvider = enumsProvider\n\t}\n\n\tprivate createAliasedType(name: string, baseType: ScalarType): { scalar: GraphQLScalarType; base: ScalarType } {\n\t\tconst baseGraphqlType = this.getScalarType(baseType)\n\t\treturn {\n\t\t\tscalar: new GraphQLScalarType({\n\t\t\t\t...baseGraphqlType.toConfig(),\n\t\t\t\tname,\n\t\t\t\tdescription: null,\n\t\t\t}),\n\t\t\tbase: baseType,\n\t\t}\n\t}\n\n\tpublic getType(column: Model.AnyColumn): GraphQLScalarType | GraphQLEnumType {\n\t\tif (column.typeAlias) {\n\t\t\tif (column.type === Model.ColumnType.Enum) {\n\t\t\t\tthrow new Error('GraphQL type alias cannot be specified for enum type')\n\t\t\t}\n\t\t\tconst { scalar, base } = this.aliasedTypes(column.typeAlias, column.type)\n\t\t\tif (base !== column.type) {\n\t\t\t\tthrow new Error('GraphQL type alias with different base type found')\n\t\t\t}\n\t\t\treturn scalar\n\t\t}\n\t\treturn this.resolveType(column)\n\t}\n\n\tprivate resolveType(column: Model.AnyColumn): GraphQLScalarType | GraphQLEnumType {\n\t\tswitch (column.type) {\n\t\t\tcase Model.ColumnType.Enum:\n\t\t\t\tif (this.enumsProvider.hasEnum(column.columnType)) {\n\t\t\t\t\treturn this.enumsProvider.getEnum(column.columnType)\n\t\t\t\t}\n\t\t\t\tthrow new Error(`Undefined enum ${column.columnType}`)\n\t\t\tdefault:\n\t\t\t\treturn this.getScalarType(column.type)\n\t\t}\n\t}\n\n\tpublic getScalarType(type: ScalarType): GraphQLScalarType {\n\t\tswitch (type) {\n\t\t\tcase Model.ColumnType.Int:\n\t\t\t\treturn GraphQLInt\n\t\t\tcase Model.ColumnType.String:\n\t\t\t\treturn GraphQLString\n\t\t\tcase Model.ColumnType.Uuid:\n\t\t\t\treturn this.customTypeProvider.uuidType\n\t\t\tcase Model.ColumnType.Double:\n\t\t\t\treturn GraphQLFloat\n\t\t\tcase Model.ColumnType.Bool:\n\t\t\t\treturn GraphQLBoolean\n\t\t\tcase Model.ColumnType.DateTime:\n\t\t\t\treturn this.customTypeProvider.dateTimeType\n\t\t\tcase Model.ColumnType.Date:\n\t\t\t\treturn this.customTypeProvider.dateType\n\t\t\tcase Model.ColumnType.Json:\n\t\t\t\treturn this.customTypeProvider.jsonType\n\t\t\tdefault:\n\t\t\t\t(({}: never): never => {\n\t\t\t\t\tthrow new ImplementationException('Invalid column type')\n\t\t\t\t})(type)\n\t\t}\n\t}\n}\n"],"names":[],"mapp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AAK,MAAM,WAAW;AACd,eAAA;AAAA,MACR,KAAK,MAAM,WAAW;AACd,eAAA;AAAA,MACR,KAAK,MAAM,WAAW;AACrB,eAAO,KAAK,mBAAmB;AAAA,MAChC,KAAK,MAAM,WAAW;AACd,eAAA;AAAA,MACR,KAAK,MAAM,WAAW;AACd,eAAA;AAAA,MACR,KAAK,MAAM,WAAW;AACrB,eAAO,KAAK,mBAAmB;AAAA,MAChC,KAAK,MAAM,WAAW;AACrB,eAAO,KAAK,mBAAmB;AAAA,MAChC,KAAK,MAAM,WAAW;AACrB,eAAO,KAAK,mBAAmB;AAAA,MAChC;AACE,SAAA,CAAC,CAAA,MAAqB;AAChB,gBAAA,IAAI,wBAAwB,qBAAqB;AAAA,WACrD,IAAI;AAAA,IAAA;AAAA,EACT;AAEF;"}
1
+ {"version":3,"file":"ColumnTypeResolver.js","sources":["../../../../../packages/engine-content-api/src/schema/ColumnTypeResolver.ts"],"sourcesContent":["import { GraphQLBoolean, GraphQLEnumType, GraphQLFloat, GraphQLInt, GraphQLList, GraphQLNonNull, GraphQLScalarType, GraphQLString } from 'graphql'\nimport { Model } from '@contember/schema'\nimport { EnumsProvider } from './EnumsProvider'\nimport { CustomTypesProvider } from './CustomTypesProvider'\nimport { ImplementationException } from '../exception'\nimport { singletonFactory } from '../utils'\n\ntype ScalarType = Exclude<Model.ColumnType, Model.ColumnType.Enum>\n\nexport type ColumnGraphQLType = GraphQLScalarType | GraphQLEnumType | GraphQLList<GraphQLNonNull<GraphQLScalarType | GraphQLEnumType>>\n\nexport class ColumnTypeResolver {\n\tprivate schema: Model.Schema\n\tprivate enumsProvider: EnumsProvider\n\n\tprivate readonly aliasedTypes = singletonFactory<{ scalar: GraphQLScalarType; base: ScalarType }, string, ScalarType>(\n\t\tthis.createAliasedType.bind(this),\n\t)\n\n\tconstructor(\n\t\tschema: Model.Schema,\n\t\tenumsProvider: EnumsProvider,\n\t\tprivate readonly customTypeProvider: CustomTypesProvider,\n\t) {\n\t\tthis.schema = schema\n\t\tthis.enumsProvider = enumsProvider\n\t}\n\n\tprivate createAliasedType(name: string, baseType: ScalarType): { scalar: GraphQLScalarType; base: ScalarType } {\n\t\tconst baseGraphqlType = this.getScalarType(baseType)\n\t\treturn {\n\t\t\tscalar: new GraphQLScalarType({\n\t\t\t\t...baseGraphqlType.toConfig(),\n\t\t\t\tname,\n\t\t\t\tdescription: null,\n\t\t\t}),\n\t\t\tbase: baseType,\n\t\t}\n\t}\n\n\tpublic getType(column: Model.AnyColumn): [type: ColumnGraphQLType, baseType: GraphQLScalarType | GraphQLEnumType] {\n\t\tconst baseType = this.getBaseType(column)\n\t\treturn [\n\t\t\tcolumn.list ? new GraphQLList(new GraphQLNonNull(baseType)) : baseType,\n\t\t\tbaseType,\n\t\t]\n\t}\n\n\tprivate getBaseType(column: Model.AnyColumn): GraphQLScalarType | GraphQLEnumType {\n\t\tif (column.typeAlias) {\n\t\t\tif (column.type === Model.ColumnType.Enum) {\n\t\t\t\tthrow new Error('GraphQL type alias cannot be specified for enum type')\n\t\t\t}\n\t\t\tconst { scalar, base } = this.aliasedTypes(column.typeAlias, column.type)\n\t\t\tif (base !== column.type) {\n\t\t\t\tthrow new Error('GraphQL type alias with different base type found')\n\t\t\t}\n\t\t\treturn scalar\n\t\t}\n\t\treturn this.resolveType(column)\n\t}\n\n\tprivate resolveType(column: Model.AnyColumn): GraphQLScalarType | GraphQLEnumType {\n\t\tswitch (column.type) {\n\t\t\tcase Model.ColumnType.Enum:\n\t\t\t\tif (this.enumsProvider.hasEnum(column.columnType)) {\n\t\t\t\t\treturn this.enumsProvider.getEnum(column.columnType)\n\t\t\t\t}\n\t\t\t\tthrow new Error(`Undefined enum ${column.columnType}`)\n\t\t\tdefault:\n\t\t\t\treturn this.getScalarType(column.type)\n\t\t}\n\t}\n\n\tprivate getScalarType(type: ScalarType): GraphQLScalarType {\n\t\tswitch (type) {\n\t\t\tcase Model.ColumnType.Int:\n\t\t\t\treturn GraphQLInt\n\t\t\tcase Model.ColumnType.String:\n\t\t\t\treturn GraphQLString\n\t\t\tcase Model.ColumnType.Uuid:\n\t\t\t\treturn this.customTypeProvider.uuidType\n\t\t\tcase Model.ColumnType.Double:\n\t\t\t\treturn GraphQLFloat\n\t\t\tcase Model.ColumnType.Bool:\n\t\t\t\treturn GraphQLBoolean\n\t\t\tcase Model.ColumnType.DateTime:\n\t\t\t\treturn this.customTypeProvider.dateTimeType\n\t\t\tcase Model.ColumnType.Time:\n\t\t\t\treturn this.customTypeProvider.timeType\n\t\t\tcase Model.ColumnType.Date:\n\t\t\t\treturn this.customTypeProvider.dateType\n\t\t\tcase Model.ColumnType.Json:\n\t\t\t\treturn this.customTypeProvider.jsonType\n\t\t\tdefault:\n\t\t\t\t(({}: never): never => {\n\t\t\t\t\tthrow new ImplementationException('Invalid column type')\n\t\t\t\t})(type)\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;AAWO,MAAM,mBAAmB;AAAA,EAQ/B,YACC,QACA,eACiB,oBAChB;AADgB,SAAA,qBAAA;AAVV,kBAAA,MAAA,QAAA;AACA,kBAAA,MAAA,eAAA;AAER,kBAAA,MAAiB,gBAAe;AAAA,MAC/B,KAAK,kBAAkB,KAAK,IAAI;AAAA,IAAA,CACjC;AAOC,SAAK,SAAS;AACd,SAAK,gBAAgB;AAAA,EAAA;AAAA,EAGd,kBAAkB,MAAc,UAAuE;AACxG,UAAA,kBAAkB,KAAK,cAAc,QAAQ;AAC5C,WAAA;AAAA,MACN,QAAQ,IAAI,kBAAkB;AAAA,QAC7B,GAAG,gBAAgB,SAAS;AAAA,QAC5B;AAAA,QACA,aAAa;AAAA,MAAA,CACb;AAAA,MACD,MAAM;AAAA,IACP;AAAA,EAAA;AAAA,EAGM,QAAQ,QAAmG;AAC3G,UAAA,WAAW,KAAK,YAAY,MAAM;AACjC,WAAA;AAAA,MACN,OAAO,OAAO,IAAI,YAAY,IAAI,eAAe,QAAQ,CAAC,IAAI;AAAA,MAC9D;AAAA,IACD;AA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AqB;AAAA,WACrD,IAAI;AAAA,IAAA;AAAA,EACT;AAEF;"}
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const schema = require("@contember/schema");
3
4
  const graphql = require("graphql");
4
5
  const singletonFactory = require("../utils/singletonFactory.cjs");
5
6
  require("@contember/schema-utils");
@@ -11,17 +12,22 @@ class ConditionTypeProvider {
11
12
  constructor(columnTypeResolver) {
12
13
  this.columnTypeResolver = columnTypeResolver;
13
14
  __publicField(this, "conditions", singletonFactory.singletonFactory(
14
- (name, type) => this.createCondition(type)
15
+ (name, [type, column]) => this.createCondition(name, column, type)
15
16
  ));
16
17
  }
17
18
  getCondition(column) {
18
- const basicType = this.columnTypeResolver.getType(column);
19
- return this.conditions(basicType.name, basicType);
19
+ const [graphqlType, baseType] = this.columnTypeResolver.getType(column);
20
+ const name = this.createName(column, baseType.name);
21
+ return this.conditions(name, [baseType, column]);
20
22
  }
21
- createCondition(type) {
22
- const suffix = typeof type === "object" && type.constructor && type.constructor.name === "GraphQLEnumType" ? "Enum" : "";
23
+ createName(column, typeName) {
24
+ const suffix = column.type === schema.Model.ColumnType.Enum ? "Enum" : "";
25
+ const arraySuffix = column.list ? "List" : "";
26
+ return utils.GqlTypeName`${typeName}${suffix}${arraySuffix}Condition`;
27
+ }
28
+ createCondition(name, column, type) {
23
29
  const condition = new graphql.GraphQLInputObjectType({
24
- name: utils.GqlTypeName`${type.name}${suffix}Condition`,
30
+ name,
25
31
  fields: () => {
26
32
  const conditions = {
27
33
  and: { type: new graphql.GraphQLList(new graphql.GraphQLNonNull(condition)) },
@@ -30,23 +36,29 @@ class ConditionTypeProvider {
30
36
  null: { type: graphql.GraphQLBoolean },
31
37
  isNull: { type: graphql.GraphQLBoolean }
32
38
  };
33
- if (type.name !== "Json") {
34
- conditions.eq = { type };
35
- conditions.notEq = { type };
36
- conditions.in = { type: new graphql.GraphQLList(new graphql.GraphQLNonNull(type)) };
37
- conditions.notIn = { type: new graphql.GraphQLList(new graphql.GraphQLNonNull(type)) };
38
- conditions.lt = { type };
39
- conditions.lte = { type };
40
- conditions.gt = { type };
41
- conditions.gte = { type };
42
- }
43
- if (type.name === "String") {
44
- conditions.contains = { type: graphql.GraphQLString };
45
- conditions.startsWith = { type: graphql.GraphQLString };
46
- conditions.endsWith = { type: graphql.GraphQLString };
47
- conditions.containsCI = { type: graphql.GraphQLString };
48
- conditions.startsWithCI = { type: graphql.GraphQLString };
49
- conditions.endsWithCI = { type: graphql.GraphQLString };
39
+ if (column.list) {
40
+ conditions.minLength = { type: graphql.GraphQLInt };
41
+ conditions.maxLength = { type: graphql.GraphQLInt };
42
+ conditions.includes = { type };
43
+ } else {
44
+ if (column.type !== schema.Model.ColumnType.Json) {
45
+ conditions.eq = { type };
46
+ conditions.notEq = { type };
47
+ conditions.in = { type: new graphql.GraphQLList(new graphql.GraphQLNonNull(type)) };
48
+ conditions.notIn = { type: new graphql.GraphQLList(new graphql.GraphQLNonNull(type)) };
49
+ conditions.lt = { type };
50
+ conditions.lte = { type };
51
+ conditions.gt = { type };
52
+ conditions.gte = { type };
53
+ }
54
+ if (column.type === schema.Model.ColumnType.String) {
55
+ conditions.contains = { type: graphql.GraphQLString };
56
+ conditions.startsWith = { type: graphql.GraphQLString };
57
+ conditions.endsWith = { type: graphql.GraphQLString };
58
+ conditions.containsCI = { type: graphql.GraphQLString };
59
+ conditions.startsWithCI = { type: graphql.GraphQLString };
60
+ conditions.endsWithCI = { type: graphql.GraphQLString };
61
+ }
50
62
  }
51
63
  return conditions;
52
64
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionTypeProvider.cjs","sources":["../../../../../packages/engine-content-api/src/schema/ConditionTypeProvider.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport {\n\tGraphQLBoolean,\n\tGraphQLEnumType,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType,\n\tGraphQLList,\n\tGraphQLNonNull,\n\tGraphQLScalarType,\n\tGraphQLString,\n} from 'graphql'\nimport { singletonFactory } from '../utils'\nimport { ColumnTypeResolver } from './ColumnTypeResolver'\nimport { GqlTypeName } from './utils'\n\nexport class ConditionTypeProvider {\n\tprivate conditions = singletonFactory<GraphQLInputObjectType, string, GraphQLScalarType | GraphQLEnumType>(\n\t\t(name, type) => this.createCondition(type),\n\t)\n\n\tconstructor(private readonly columnTypeResolver: ColumnTypeResolver) {}\n\n\tpublic getCondition(column: Model.AnyColumn): GraphQLInputObjectType {\n\t\tconst basicType = this.columnTypeResolver.getType(column)\n\t\treturn this.conditions(basicType.name, basicType)\n\t}\n\n\tprivate createCondition(type: GraphQLScalarType | GraphQLEnumType): GraphQLInputObjectType {\n\t\tconst suffix =\n\t\t\ttypeof type === 'object' && type.constructor && type.constructor.name === 'GraphQLEnumType' ? 'Enum' : ''\n\t\tconst condition: GraphQLInputObjectType = new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${type.name}${suffix}Condition`,\n\t\t\tfields: (): GraphQLInputFieldConfigMap => {\n\t\t\t\tconst conditions: GraphQLInputFieldConfigMap = {\n\t\t\t\t\tand: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tor: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tnot: { type: condition },\n\n\t\t\t\t\tnull: { type: GraphQLBoolean },\n\t\t\t\t\tisNull: { type: GraphQLBoolean },\n\t\t\t\t}\n\t\t\t\tif (type.name !== 'Json') {\n\t\t\t\t\tconditions.eq = { type }\n\t\t\t\t\tconditions.notEq = { type }\n\t\t\t\t\tconditions.in = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\tconditions.notIn = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\tconditions.lt = { type: type }\n\t\t\t\t\tconditions.lte = { type: type }\n\t\t\t\t\tconditions.gt = { type: type }\n\t\t\t\t\tconditions.gte = { type: type }\n\t\t\t\t}\n\t\t\t\tif (type.name === 'String') {\n\t\t\t\t\tconditions.contains = { type: GraphQLString }\n\t\t\t\t\tconditions.startsWith = { type: GraphQLString }\n\t\t\t\t\tconditions.endsWith = { type: GraphQLString }\n\n\t\t\t\t\tconditions.containsCI = { type: GraphQLString }\n\t\t\t\t\tconditions.startsWithCI = { type: GraphQLString }\n\t\t\t\t\tconditions.endsWithCI = { type: GraphQLString }\n\t\t\t\t}\n\t\t\t\treturn conditions\n\t\t\t},\n\t\t})\n\t\treturn condition\n\t}\n}\n"],"names":["singletonFactory","GraphQLInputObjectType","GqlTypeName","GraphQLList","GraphQLNonNull","GraphQLBoolean","GraphQLString"],"mappings":";;;;;;;;;AAeO,MAAM,sBAAsB;AAAA,EAKlC,YAA6B,oBAAwC;AAAxC,SAAA,qBAAA;AAJ7B,kBAAA,MAAQ,cAAaA,iBAAA;AAAA,MACpB,CAAC,MAAM,SAAS,KAAK,gBAAgB,IAAI;AAAA,IAAA,CAC1C;AAAA,EAAA;AAAA,EAIO,aAAa,QAAiD;AACpE,UAAM,YAAY,KAAK,mBAAmB,QAAQ,MAAM;AACxD,WAAO,KAAK,WAAW,UAAU,MAAM,SAAS;AAAA,EAAA;AAAA,EAGzC,gBAAgB,MAAmE;AACpF,UAAA,SACL,OAAO,SAAS,YAAY,KAAK,eAAe,KAAK,YAAY,SAAS,oBAAoB,SAAS;AAClG,UAAA,YAAoC,IAAIC,+BAAuB;AAAA,MACpE,MAAMC,MAAA,cAAc,KAAK,IAAI,GAAG,MAAM;AAAA,MACtC,QAAQ,MAAkC;AACzC,cAAM,aAAyC;AAAA,UAC9C,KAAK,EAAE,MAAM,IAAIC,QAAAA,YAAY,IAAIC,QAAA,eAAe,SAAS,CAAC,EAAE;AAAA,UAC5D,IAAI,EAAE,MAAM,IAAID,QAAAA,YAAY,IAAIC,QAAA,eAAe,SAAS,CAAC,EAAE;AAAA,UAC3D,KAAK,EAAE,MAAM,UAAU;AAAA,UAEvB,MAAM,EAAE,MAAMC,uBAAe;AAAA,UAC7B,QAAQ,EAAE,MAAMA,QAAe,eAAA;AAAA,QAChC;AACI,YAAA,KAAK,SAAS,QAAQ;AACd,qBAAA,KAAK,EAAE,KAAK;AACZ,qBAAA,QAAQ,EAAE,KAAK;AACf,qBAAA,KAAK,EAAE,MAAM,IAAIF,oBAAY,IAAIC,QAAA,eAAe,IAAI,CAAC,EAAE;AACvD,qBAAA,QAAQ,EAAE,MAAM,IAAID,oBAAY,IAAIC,QAAA,eAAe,IAAI,CAAC,EAAE;AAC1D,qBAAA,KAAK,EAAE,KAAW;AAClB,qBAAA,MAAM,EAAE,KAAW;AACnB,qBAAA,KAAK,EAAE,KAAW;AAClB,qBAAA,MAAM,EAAE,KAAW;AAAA,QAAA;AAE3B,YAAA,KAAK,SAAS,UAAU;AAChB,qBAAA,WAAW,EAAE,MAAME,sBAAc;AACjC,qBAAA,aAAa,EAAE,MAAMA,sBAAc;AACnC,qBAAA,WAAW,EAAE,MAAMA,sBAAc;AAEjC,qBAAA,aAAa,EAAE,MAAMA,sBAAc;AACnC,qBAAA,eAAe,EAAE,MAAMA,sBAAc;AACrC,qBAAA,aAAa,EAAE,MAAMA,sBAAc;AAAA,QAAA;AAExC,eAAA;AAAA,MAAA;AAAA,IACR,CACA;AACM,WAAA;AAAA,EAAA;AAET;;"}
1
+ {"version":3,"file":"ConditionTypeProvider.cjs","sources":["../../../../../packages/engine-content-api/src/schema/ConditionTypeProvider.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport {\n\tGraphQLBoolean,\n\tGraphQLEnumType,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType,\n\tGraphQLInt,\n\tGraphQLList,\n\tGraphQLNonNull,\n\tGraphQLScalarType,\n\tGraphQLString,\n} from 'graphql'\nimport { singletonFactory } from '../utils'\nimport { ColumnTypeResolver } from './ColumnTypeResolver'\nimport { GqlTypeName } from './utils'\nimport { ImplementationException } from '../exception'\n\nexport class ConditionTypeProvider {\n\tprivate conditions = singletonFactory<GraphQLInputObjectType, string, [GraphQLScalarType | GraphQLEnumType, Model.AnyColumn]>(\n\t\t(name, [type, column]) => this.createCondition(name, column, type),\n\t)\n\n\tconstructor(private readonly columnTypeResolver: ColumnTypeResolver) {}\n\n\tpublic getCondition(column: Model.AnyColumn): GraphQLInputObjectType {\n\t\tconst [graphqlType, baseType] = this.columnTypeResolver.getType(column)\n\t\tconst name = this.createName(column, baseType.name)\n\t\treturn this.conditions(name, [baseType, column])\n\t}\n\n\tprivate createName(column: Model.AnyColumn, typeName: string): string {\n\t\tconst suffix = column.type === Model.ColumnType.Enum ? 'Enum' : ''\n\t\tconst arraySuffix = column.list ? 'List' : ''\n\t\treturn GqlTypeName`${typeName}${suffix}${arraySuffix}Condition`\n\t}\n\n\tprivate createCondition(name: string, column: Model.AnyColumn, type: GraphQLScalarType | GraphQLEnumType): GraphQLInputObjectType {\n\t\tconst condition: GraphQLInputObjectType = new GraphQLInputObjectType({\n\t\t\tname: name,\n\t\t\tfields: (): GraphQLInputFieldConfigMap => {\n\t\t\t\tconst conditions: GraphQLInputFieldConfigMap = {\n\t\t\t\t\tand: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tor: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tnot: { type: condition },\n\n\t\t\t\t\tnull: { type: GraphQLBoolean },\n\t\t\t\t\tisNull: { type: GraphQLBoolean },\n\t\t\t\t}\n\t\t\t\tif (column.list) {\n\t\t\t\t\tconditions.minLength = { type: GraphQLInt }\n\t\t\t\t\tconditions.maxLength = { type: GraphQLInt }\n\t\t\t\t\tconditions.includes = { type: type }\n\t\t\t\t} else {\n\t\t\t\t\tif (column.type !== Model.ColumnType.Json) {\n\t\t\t\t\t\tconditions.eq = { type }\n\t\t\t\t\t\tconditions.notEq = { type }\n\t\t\t\t\t\tconditions.in = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\t\tconditions.notIn = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\t\tconditions.lt = { type: type }\n\t\t\t\t\t\tconditions.lte = { type: type }\n\t\t\t\t\t\tconditions.gt = { type: type }\n\t\t\t\t\t\tconditions.gte = { type: type }\n\t\t\t\t\t}\n\t\t\t\t\tif (column.type === Model.ColumnType.String) {\n\t\t\t\t\t\tconditions.contains = { type: GraphQLString }\n\t\t\t\t\t\tconditions.startsWith = { type: GraphQLString }\n\t\t\t\t\t\tconditions.endsWith = { type: GraphQLString }\n\n\t\t\t\t\t\tconditions.containsCI = { type: GraphQLString }\n\t\t\t\t\t\tconditions.startsWithCI = { type: GraphQLString }\n\t\t\t\t\t\tconditions.endsWithCI = { type: GraphQLString }\n\t\t\t\t\t}\n\t\t\t\t}\n\n\n\t\t\t\treturn conditions\n\t\t\t},\n\t\t})\n\t\treturn condition\n\t}\n}\n"],"names":["singletonFactory","Model","GqlTypeName","GraphQLInputObjectType","GraphQLList","GraphQLNonNull","GraphQLBoolean","GraphQLInt","GraphQLString"],"mappings":";;;;;;;;;;AAiBO,MAAM,sBAAsB;AAAA,EAKlC,YAA6B,oBAAwC;AAAxC,SAAA,qBAAA;AAJ7B,kBAAA,MAAQ,cAAaA,iBAAA;AAAA,MACpB,CAAC,MAAM,CAAC,MAAM,MAAM,MAAM,KAAK,gBAAgB,MAAM,QAAQ,IAAI;AAAA,IAAA,CAClE;AAAA,EAAA;AAAA,EAIO,aAAa,QAAiD;AACpE,UAAM,CAAC,aAAa,QAAQ,IAAI,KAAK,mBAAmB,QAAQ,MAAM;AACtE,UAAM,OAAO,KAAK,WAAW,QAAQ,SAAS,IAAI;AAClD,WAAO,KAAK,WAAW,MAAM,CAAC,UAAU,MAAM,CAAC;AAAA,EAAA;AAAA,EAGxC,WAAW,QAAyB,UAA0B;AACrE,UAAM,SAAS,OAAO,SAASC,OAAM,MAAA,WAAW,OAAO,SAAS;AAC1D,UAAA,cAAc,OAAO,OAAO,SAAS;AAC3C,WAAOC,MAAAA,cAAc,QAAQ,GAAG,MAAM,GAAG,WAAW;AAA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AAA,eAAe,EAAE,MAAMA,sBAAc;AACrC,uBAAA,aAAa,EAAE,MAAMA,sBAAc;AAAA,UAAA;AAAA,QAC/C;AAIM,eAAA;AAAA,MAAA;AAAA,IACR,CACA;AACM,WAAA;AAAA,EAAA;AAET;;"}
@@ -1,4 +1,5 @@
1
- import { GraphQLInputObjectType, GraphQLList, GraphQLNonNull, GraphQLBoolean, GraphQLString } from "graphql";
1
+ import { Model } from "@contember/schema";
2
+ import { GraphQLInputObjectType, GraphQLList, GraphQLNonNull, GraphQLBoolean, GraphQLInt, GraphQLString } from "graphql";
2
3
  import { singletonFactory } from "../utils/singletonFactory.js";
3
4
  import "@contember/schema-utils";
4
5
  import { GqlTypeName } from "./utils.js";
@@ -9,17 +10,22 @@ class ConditionTypeProvider {
9
10
  constructor(columnTypeResolver) {
10
11
  this.columnTypeResolver = columnTypeResolver;
11
12
  __publicField(this, "conditions", singletonFactory(
12
- (name, type) => this.createCondition(type)
13
+ (name, [type, column]) => this.createCondition(name, column, type)
13
14
  ));
14
15
  }
15
16
  getCondition(column) {
16
- const basicType = this.columnTypeResolver.getType(column);
17
- return this.conditions(basicType.name, basicType);
17
+ const [graphqlType, baseType] = this.columnTypeResolver.getType(column);
18
+ const name = this.createName(column, baseType.name);
19
+ return this.conditions(name, [baseType, column]);
18
20
  }
19
- createCondition(type) {
20
- const suffix = typeof type === "object" && type.constructor && type.constructor.name === "GraphQLEnumType" ? "Enum" : "";
21
+ createName(column, typeName) {
22
+ const suffix = column.type === Model.ColumnType.Enum ? "Enum" : "";
23
+ const arraySuffix = column.list ? "List" : "";
24
+ return GqlTypeName`${typeName}${suffix}${arraySuffix}Condition`;
25
+ }
26
+ createCondition(name, column, type) {
21
27
  const condition = new GraphQLInputObjectType({
22
- name: GqlTypeName`${type.name}${suffix}Condition`,
28
+ name,
23
29
  fields: () => {
24
30
  const conditions = {
25
31
  and: { type: new GraphQLList(new GraphQLNonNull(condition)) },
@@ -28,23 +34,29 @@ class ConditionTypeProvider {
28
34
  null: { type: GraphQLBoolean },
29
35
  isNull: { type: GraphQLBoolean }
30
36
  };
31
- if (type.name !== "Json") {
32
- conditions.eq = { type };
33
- conditions.notEq = { type };
34
- conditions.in = { type: new GraphQLList(new GraphQLNonNull(type)) };
35
- conditions.notIn = { type: new GraphQLList(new GraphQLNonNull(type)) };
36
- conditions.lt = { type };
37
- conditions.lte = { type };
38
- conditions.gt = { type };
39
- conditions.gte = { type };
40
- }
41
- if (type.name === "String") {
42
- conditions.contains = { type: GraphQLString };
43
- conditions.startsWith = { type: GraphQLString };
44
- conditions.endsWith = { type: GraphQLString };
45
- conditions.containsCI = { type: GraphQLString };
46
- conditions.startsWithCI = { type: GraphQLString };
47
- conditions.endsWithCI = { type: GraphQLString };
37
+ if (column.list) {
38
+ conditions.minLength = { type: GraphQLInt };
39
+ conditions.maxLength = { type: GraphQLInt };
40
+ conditions.includes = { type };
41
+ } else {
42
+ if (column.type !== Model.ColumnType.Json) {
43
+ conditions.eq = { type };
44
+ conditions.notEq = { type };
45
+ conditions.in = { type: new GraphQLList(new GraphQLNonNull(type)) };
46
+ conditions.notIn = { type: new GraphQLList(new GraphQLNonNull(type)) };
47
+ conditions.lt = { type };
48
+ conditions.lte = { type };
49
+ conditions.gt = { type };
50
+ conditions.gte = { type };
51
+ }
52
+ if (column.type === Model.ColumnType.String) {
53
+ conditions.contains = { type: GraphQLString };
54
+ conditions.startsWith = { type: GraphQLString };
55
+ conditions.endsWith = { type: GraphQLString };
56
+ conditions.containsCI = { type: GraphQLString };
57
+ conditions.startsWithCI = { type: GraphQLString };
58
+ conditions.endsWithCI = { type: GraphQLString };
59
+ }
48
60
  }
49
61
  return conditions;
50
62
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionTypeProvider.js","sources":["../../../../../packages/engine-content-api/src/schema/ConditionTypeProvider.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport {\n\tGraphQLBoolean,\n\tGraphQLEnumType,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType,\n\tGraphQLList,\n\tGraphQLNonNull,\n\tGraphQLScalarType,\n\tGraphQLString,\n} from 'graphql'\nimport { singletonFactory } from '../utils'\nimport { ColumnTypeResolver } from './ColumnTypeResolver'\nimport { GqlTypeName } from './utils'\n\nexport class ConditionTypeProvider {\n\tprivate conditions = singletonFactory<GraphQLInputObjectType, string, GraphQLScalarType | GraphQLEnumType>(\n\t\t(name, type) => this.createCondition(type),\n\t)\n\n\tconstructor(private readonly columnTypeResolver: ColumnTypeResolver) {}\n\n\tpublic getCondition(column: Model.AnyColumn): GraphQLInputObjectType {\n\t\tconst basicType = this.columnTypeResolver.getType(column)\n\t\treturn this.conditions(basicType.name, basicType)\n\t}\n\n\tprivate createCondition(type: GraphQLScalarType | GraphQLEnumType): GraphQLInputObjectType {\n\t\tconst suffix =\n\t\t\ttypeof type === 'object' && type.constructor && type.constructor.name === 'GraphQLEnumType' ? 'Enum' : ''\n\t\tconst condition: GraphQLInputObjectType = new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${type.name}${suffix}Condition`,\n\t\t\tfields: (): GraphQLInputFieldConfigMap => {\n\t\t\t\tconst conditions: GraphQLInputFieldConfigMap = {\n\t\t\t\t\tand: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tor: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tnot: { type: condition },\n\n\t\t\t\t\tnull: { type: GraphQLBoolean },\n\t\t\t\t\tisNull: { type: GraphQLBoolean },\n\t\t\t\t}\n\t\t\t\tif (type.name !== 'Json') {\n\t\t\t\t\tconditions.eq = { type }\n\t\t\t\t\tconditions.notEq = { type }\n\t\t\t\t\tconditions.in = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\tconditions.notIn = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\tconditions.lt = { type: type }\n\t\t\t\t\tconditions.lte = { type: type }\n\t\t\t\t\tconditions.gt = { type: type }\n\t\t\t\t\tconditions.gte = { type: type }\n\t\t\t\t}\n\t\t\t\tif (type.name === 'String') {\n\t\t\t\t\tconditions.contains = { type: GraphQLString }\n\t\t\t\t\tconditions.startsWith = { type: GraphQLString }\n\t\t\t\t\tconditions.endsWith = { type: GraphQLString }\n\n\t\t\t\t\tconditions.containsCI = { type: GraphQLString }\n\t\t\t\t\tconditions.startsWithCI = { type: GraphQLString }\n\t\t\t\t\tconditions.endsWithCI = { type: GraphQLString }\n\t\t\t\t}\n\t\t\t\treturn conditions\n\t\t\t},\n\t\t})\n\t\treturn condition\n\t}\n}\n"],"names":[],"mappings":";;;;;;;AAeO,MAAM,sBAAsB;AAAA,EAKlC,YAA6B,oBAAwC;AAAxC,SAAA,qBAAA;AAJ7B,kBAAA,MAAQ,cAAa;AAAA,MACpB,CAAC,MAAM,SAAS,KAAK,gBAAgB,IAAI;AAAA,IAAA,CAC1C;AAAA,EAAA;AAAA,EAIO,aAAa,QAAiD;AACpE,UAAM,YAAY,KAAK,mBAAmB,QAAQ,MAAM;AACxD,WAAO,KAAK,WAAW,UAAU,MAAM,SAAS;AAAA,EAAA;AAAA,EAGzC,gBAAgB,MAAmE;AACpF,UAAA,SACL,OAAO,SAAS,YAAY,KAAK,eAAe,KAAK,YAAY,SAAS,oBAAoB,SAAS;AAClG,UAAA,YAAoC,IAAI,uBAAuB;AAAA,MACpE,MAAM,cAAc,KAAK,IAAI,GAAG,MAAM;AAAA,MACtC,QAAQ,MAAkC;AACzC,cAAM,aAAyC;AAAA,UAC9C,KAAK,EAAE,MAAM,IAAI,YAAY,IAAI,eAAe,SAAS,CAAC,EAAE;AAAA,UAC5D,IAAI,EAAE,MAAM,IAAI,YAAY,IAAI,eAAe,SAAS,CAAC,EAAE;AAAA,UAC3D,KAAK,EAAE,MAAM,UAAU;AAAA,UAEvB,MAAM,EAAE,MAAM,eAAe;AAAA,UAC7B,QAAQ,EAAE,MAAM,eAAe;AAAA,QAChC;AACI,YAAA,KAAK,SAAS,QAAQ;AACd,qBAAA,KAAK,EAAE,KAAK;AACZ,qBAAA,QAAQ,EAAE,KAAK;AACf,qBAAA,KAAK,EAAE,MAAM,IAAI,YAAY,IAAI,eAAe,IAAI,CAAC,EAAE;AACvD,qBAAA,QAAQ,EAAE,MAAM,IAAI,YAAY,IAAI,eAAe,IAAI,CAAC,EAAE;AAC1D,qBAAA,KAAK,EAAE,KAAW;AAClB,qBAAA,MAAM,EAAE,KAAW;AACnB,qBAAA,KAAK,EAAE,KAAW;AAClB,qBAAA,MAAM,EAAE,KAAW;AAAA,QAAA;AAE3B,YAAA,KAAK,SAAS,UAAU;AAChB,qBAAA,WAAW,EAAE,MAAM,cAAc;AACjC,qBAAA,aAAa,EAAE,MAAM,cAAc;AACnC,qBAAA,WAAW,EAAE,MAAM,cAAc;AAEjC,qBAAA,aAAa,EAAE,MAAM,cAAc;AACnC,qBAAA,eAAe,EAAE,MAAM,cAAc;AACrC,qBAAA,aAAa,EAAE,MAAM,cAAc;AAAA,QAAA;AAExC,eAAA;AAAA,MAAA;AAAA,IACR,CACA;AACM,WAAA;AAAA,EAAA;AAET;"}
1
+ {"version":3,"file":"ConditionTypeProvider.js","sources":["../../../../../packages/engine-content-api/src/schema/ConditionTypeProvider.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport {\n\tGraphQLBoolean,\n\tGraphQLEnumType,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType,\n\tGraphQLInt,\n\tGraphQLList,\n\tGraphQLNonNull,\n\tGraphQLScalarType,\n\tGraphQLString,\n} from 'graphql'\nimport { singletonFactory } from '../utils'\nimport { ColumnTypeResolver } from './ColumnTypeResolver'\nimport { GqlTypeName } from './utils'\nimport { ImplementationException } from '../exception'\n\nexport class ConditionTypeProvider {\n\tprivate conditions = singletonFactory<GraphQLInputObjectType, string, [GraphQLScalarType | GraphQLEnumType, Model.AnyColumn]>(\n\t\t(name, [type, column]) => this.createCondition(name, column, type),\n\t)\n\n\tconstructor(private readonly columnTypeResolver: ColumnTypeResolver) {}\n\n\tpublic getCondition(column: Model.AnyColumn): GraphQLInputObjectType {\n\t\tconst [graphqlType, baseType] = this.columnTypeResolver.getType(column)\n\t\tconst name = this.createName(column, baseType.name)\n\t\treturn this.conditions(name, [baseType, column])\n\t}\n\n\tprivate createName(column: Model.AnyColumn, typeName: string): string {\n\t\tconst suffix = column.type === Model.ColumnType.Enum ? 'Enum' : ''\n\t\tconst arraySuffix = column.list ? 'List' : ''\n\t\treturn GqlTypeName`${typeName}${suffix}${arraySuffix}Condition`\n\t}\n\n\tprivate createCondition(name: string, column: Model.AnyColumn, type: GraphQLScalarType | GraphQLEnumType): GraphQLInputObjectType {\n\t\tconst condition: GraphQLInputObjectType = new GraphQLInputObjectType({\n\t\t\tname: name,\n\t\t\tfields: (): GraphQLInputFieldConfigMap => {\n\t\t\t\tconst conditions: GraphQLInputFieldConfigMap = {\n\t\t\t\t\tand: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tor: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tnot: { type: condition },\n\n\t\t\t\t\tnull: { type: GraphQLBoolean },\n\t\t\t\t\tisNull: { type: GraphQLBoolean },\n\t\t\t\t}\n\t\t\t\tif (column.list) {\n\t\t\t\t\tconditions.minLength = { type: GraphQLInt }\n\t\t\t\t\tconditions.maxLength = { type: GraphQLInt }\n\t\t\t\t\tconditions.includes = { type: type }\n\t\t\t\t} else {\n\t\t\t\t\tif (column.type !== Model.ColumnType.Json) {\n\t\t\t\t\t\tconditions.eq = { type }\n\t\t\t\t\t\tconditions.notEq = { type }\n\t\t\t\t\t\tconditions.in = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\t\tconditions.notIn = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\t\tconditions.lt = { type: type }\n\t\t\t\t\t\tconditions.lte = { type: type }\n\t\t\t\t\t\tconditions.gt = { type: type }\n\t\t\t\t\t\tconditions.gte = { type: type }\n\t\t\t\t\t}\n\t\t\t\t\tif (column.type === Model.ColumnType.String) {\n\t\t\t\t\t\tconditions.contains = { type: GraphQLString }\n\t\t\t\t\t\tconditions.startsWith = { type: GraphQLString }\n\t\t\t\t\t\tconditions.endsWith = { type: GraphQLString }\n\n\t\t\t\t\t\tconditions.containsCI = { type: GraphQLString }\n\t\t\t\t\t\tconditions.startsWithCI = { type: GraphQLString }\n\t\t\t\t\t\tconditions.endsWithCI = { type: GraphQLString }\n\t\t\t\t\t}\n\t\t\t\t}\n\n\n\t\t\t\treturn conditions\n\t\t\t},\n\t\t})\n\t\treturn condition\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;AAiBO,MAAM,sBAAsB;AAAA,EAKlC,YAA6B,oBAAwC;AAAxC,SAAA,qBAAA;AAJ7B,kBAAA,MAAQ,cAAa;AAAA,MACpB,CAAC,MAAM,CAAC,MAAM,MAAM,MAAM,KAAK,gBAAgB,MAAM,QAAQ,IAAI;AAAA,IAAA,CAClE;AAAA,EAAA;AAAA,EAIO,aAAa,QAAiD;AACpE,UAAM,CAAC,aAAa,QAAQ,IAAI,KAAK,mBAAmB,QAAQ,MAAM;AACtE,UAAM,OAAO,KAAK,WAAW,QAAQ,SAAS,IAAI;AAClD,WAAO,KAAK,WAAW,MAAM,CAAC,UAAU,MAAM,CAAC;AAAA,EAAA;AAAA,EAGxC,WAAW,QAAyB,UAA0B;AACrE,UAAM,SAAS,OAAO,SAAS,MAAM,WAAW,OAAO,SAAS;AAC1D,UAAA,cAAc,OAAO,OAAO,SAAS;AAC3C,WAAO,cAAc,QAAQ,GAAG,MAAM,GAAG,WAAW;AAAA,EAAA;AAAA,EAG7C,gBAAgB,MAAc,QAAyB,MAAmE;AAC3H,UAAA,YAAoC,IAAI,uBAAuB;AAAA,MACpE;AAAA,MACA,QAAQ,MAAkC;AACzC,cAAM,aAAyC;AAAA,UAC9C,KAAK,EAAE,MAAM,IAAI,YAAY,IAAI,eAAe,SAAS,CAAC,EAAE;AAAA,UAC5D,IAAI,EAAE,MAAM,IAAI,YAAY,IAAI,eAAe,SAAS,CAAC,EAAE;AAAA,UAC3D,KAAK,EAAE,MAAM,UAAU;AAAA,UAEvB,MAAM,EAAE,MAAM,eAAe;AAAA,UAC7B,QAAQ,EAAE,MAAM,eAAe;AAAA,QAChC;AACA,YAAI,OAAO,MAAM;AACL,qBAAA,YAAY,EAAE,MAAM,WAAW;AAC/B,qBAAA,YAAY,EAAE,MAAM,WAAW;AAC/B,qBAAA,WAAW,EAAE,KAAW;AAAA,QAAA,OAC7B;AACN,cAAI,OAAO,SAAS,MAAM,WAAW,MAAM;AAC/B,uBAAA,KAAK,EAAE,KAAK;AACZ,uBAAA,QAAQ,EAAE,KAAK;AACf,uBAAA,KAAK,EAAE,MAAM,IAAI,YAAY,IAAI,eAAe,IAAI,CAAC,EAAE;AACvD,uBAAA,QAAQ,EAAE,MAAM,IAAI,YAAY,IAAI,eAAe,IAAI,CAAC,EAAE;AAC1D,uBAAA,KAAK,EAAE,KAAW;AAClB,uBAAA,MAAM,EAAE,KAAW;AACnB,uBAAA,KAAK,EAAE,KAAW;AAClB,uBAAA,MAAM,EAAE,KAAW;AAAA,UAAA;AAE/B,cAAI,OAAO,SAAS,MAAM,WAAW,QAAQ;AACjC,uBAAA,WAAW,EAAE,MAAM,cAAc;AACjC,uBAAA,aAAa,EAAE,MAAM,cAAc;AACnC,uBAAA,WAAW,EAAE,MAAM,cAAc;AAEjC,uBAAA,aAAa,EAAE,MAAM,cAAc;AACnC,uBAAA,eAAe,EAAE,MAAM,cAAc;AACrC,uBAAA,aAAa,EAAE,MAAM,cAAc;AAAA,UAAA;AAAA,QAC/C;AAIM,eAAA;AAAA,MAAA;AAAA,IACR,CACA;AACM,WAAA;AAAA,EAAA;AAET;"}
@@ -5,6 +5,21 @@ const graphqlUtils = require("@contember/graphql-utils");
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
7
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+ const TIME_REGEX = /^([01]\d|2[0-3]):([0-5]\d)(?::([0-5]\d)(?:\.(\d+))?)?$/;
9
+ function validateTime(value) {
10
+ if (typeof value !== "string") {
11
+ throw new TypeError(`Time value must be a string, got: ${typeof value}`);
12
+ }
13
+ const match = TIME_REGEX.exec(value);
14
+ if (!match) {
15
+ throw new TypeError(`Value is not a valid time: ${value}`);
16
+ }
17
+ const hours = match[1];
18
+ const minutes = match[2];
19
+ const seconds = match[3] || "00";
20
+ const fraction = match[4] ? `.${match[4]}` : "";
21
+ return `${hours}:${minutes}:${seconds}${fraction}`;
22
+ }
8
23
  class CustomTypesProvider {
9
24
  constructor() {
10
25
  __publicField(this, "uuidType", graphqlUtils.UuidType);
@@ -16,6 +31,21 @@ class CustomTypesProvider {
16
31
  return ast.kind === graphql.Kind.STRING ? ast.value : void 0;
17
32
  }
18
33
  }));
34
+ __publicField(this, "timeType", new graphql.GraphQLScalarType({
35
+ name: "Time",
36
+ serialize(value) {
37
+ return validateTime(value);
38
+ },
39
+ parseValue(value) {
40
+ return validateTime(value);
41
+ },
42
+ parseLiteral(ast) {
43
+ if (ast.kind !== graphql.Kind.STRING) {
44
+ throw new TypeError(`Time scalar can only parse string values, got: ${ast.kind}`);
45
+ }
46
+ return validateTime(ast.value);
47
+ }
48
+ }));
19
49
  __publicField(this, "dateTimeType", new graphql.GraphQLScalarType({
20
50
  name: "DateTime",
21
51
  serialize: (str) => String(str),
@@ -1 +1 @@
1
- {"version":3,"file":"CustomTypesProvider.cjs","sources":["../../../../../packages/engine-content-api/src/schema/CustomTypesProvider.ts"],"sourcesContent":["import { GraphQLScalarType, Kind } from 'graphql'\nimport { JSONType, UuidType } from '@contember/graphql-utils'\n\n\nexport class CustomTypesProvider {\n\tpublic readonly uuidType: GraphQLScalarType = UuidType\n\n\t//todo: implement serialize, parseValue and parseLiteral properly\n\tpublic readonly dateType: GraphQLScalarType = new GraphQLScalarType({\n\t\tname: 'Date',\n\t\tserialize: str => String(str),\n\t\tparseValue: str => String(str),\n\t\tparseLiteral: function parseLiteral(ast) {\n\t\t\treturn ast.kind === Kind.STRING ? ast.value : undefined\n\t\t},\n\t})\n\tpublic readonly dateTimeType: GraphQLScalarType = new GraphQLScalarType({\n\t\tname: 'DateTime',\n\t\tserialize: str => String(str),\n\t\tparseValue: str => String(str),\n\t\tparseLiteral: function parseLiteral(ast) {\n\t\t\treturn ast.kind === Kind.STRING ? ast.value : undefined\n\t\t},\n\t})\n\tpublic readonly jsonType: GraphQLScalarType = JSONType\n}\n"],"names":["UuidType","GraphQLScalarType","Kind","JSONType"],"mappings":";;;;;;;AAIO,MAAM,oBAAoB;AAAA,EAA1B,cAAA;AACN,kBAAA,MAAgB,YAA8BA,qBAAA;AAG9B,kBAAA,MAAA,YAA8B,IAAIC,0BAAkB;AAAA,MACnE,MAAM;AAAA,MACN,WAAW,CAAO,QAAA,OAAO,GAAG;AAAA,MAC5B,YAAY,CAAO,QAAA,OAAO,GAAG;AAAA,MAC7B,cAAc,SAAS,aAAa,KAAK;AACxC,eAAO,IAAI,SAASC,QAAK,KAAA,SAAS,IAAI,QAAQ;AAAA,MAAA;AAAA,IAC/C,CACA,CAAA;AACe,kBAAA,MAAA,gBAAkC,IAAID,0BAAkB;AAAA,MACvE,MAAM;AAAA,MACN,WAAW,CAAO,QAAA,OAAO,GAAG;AAAA,MAC5B,YAAY,CAAO,QAAA,OAAO,GAAG;AAAA,MAC7B,cAAc,SAAS,aAAa,KAAK;AACxC,eAAO,IAAI,SAASC,QAAK,KAAA,SAAS,IAAI,QAAQ;AAAA,MAAA;AAAA,IAC/C,CACA,CAAA;AACD,kBAAA,MAAgB,YAA8BC,qBAAA;AAAA,EAAA;AAC/C;;"}
1
+ {"version":3,"file":"CustomTypesProvider.cjs","sources":["../../../../../packages/engine-content-api/src/schema/CustomTypesProvider.ts"],"sourcesContent":["import { GraphQLScalarType, Kind } from 'graphql'\nimport { JSONType, UuidType } from '@contember/graphql-utils'\n\nconst TIME_REGEX = /^([01]\\d|2[0-3]):([0-5]\\d)(?::([0-5]\\d)(?:\\.(\\d+))?)?$/\n\nfunction validateTime(value: unknown): string {\n\tif (typeof value !== 'string') {\n\t\tthrow new TypeError(`Time value must be a string, got: ${typeof value}`)\n\t}\n\tconst match = TIME_REGEX.exec(value)\n\tif (!match) {\n\t\tthrow new TypeError(`Value is not a valid time: ${value}`)\n\t}\n\n\tconst hours = match[1]\n\tconst minutes = match[2]\n\tconst seconds = match[3] || '00'\n\tconst fraction = match[4] ? `.${match[4]}` : ''\n\n\treturn `${hours}:${minutes}:${seconds}${fraction}`\n}\n\n\nexport class CustomTypesProvider {\n\tpublic readonly uuidType: GraphQLScalarType = UuidType\n\n\t//todo: implement serialize, parseValue and parseLiteral properly\n\n\tpublic readonly dateType: GraphQLScalarType = new GraphQLScalarType({\n\t\tname: 'Date',\n\t\tserialize: str => String(str),\n\t\tparseValue: str => String(str),\n\t\tparseLiteral: function parseLiteral(ast) {\n\t\t\treturn ast.kind === Kind.STRING ? ast.value : undefined\n\t\t},\n\t})\n\n\tpublic readonly timeType: GraphQLScalarType = new GraphQLScalarType({\n\t\tname: 'Time',\n\t\tserialize(value) {\n\t\t\treturn validateTime(value)\n\t\t},\n\t\tparseValue(value) {\n\t\t\treturn validateTime(value)\n\t\t},\n\t\tparseLiteral(ast) {\n\t\t\tif (ast.kind !== Kind.STRING) {\n\t\t\t\tthrow new TypeError(`Time scalar can only parse string values, got: ${ast.kind}`)\n\t\t\t}\n\t\t\treturn validateTime(ast.value)\n\t\t},\n\t})\n\n\tpublic readonly dateTimeType: GraphQLScalarType = new GraphQLScalarType({\n\t\tname: 'DateTime',\n\t\tserialize: str => String(str),\n\t\tparseValue: str => String(str),\n\t\tparseLiteral: function parseLiteral(ast) {\n\t\t\treturn ast.kind === Kind.STRING ? ast.value : undefined\n\t\t},\n\t})\n\tpublic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E1E,eAAA,aAAa,IAAI,KAAK;AAAA,MAAA;AAAA,IAC9B,CACA,CAAA;AAEe,kBAAA,MAAA,gBAAkC,IAAID,0BAAkB;AAAA,MACvE,MAAM;AAAA,MACN,WAAW,CAAO,QAAA,OAAO,GAAG;AAAA,MAC5B,YAAY,CAAO,QAAA,OAAO,GAAG;AAAA,MAC7B,cAAc,SAAS,aAAa,KAAK;AACxC,eAAO,IAAI,SAASC,QAAK,KAAA,SAAS,IAAI,QAAQ;AAAA,MAAA;AAAA,IAC/C,CACA,CAAA;AACD,kBAAA,MAAgB,YAA8BC,qBAAA;AAAA,EAAA;AAC/C;;"}
@@ -3,6 +3,21 @@ import { UuidType, JSONType } from "@contember/graphql-utils";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
5
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+ const TIME_REGEX = /^([01]\d|2[0-3]):([0-5]\d)(?::([0-5]\d)(?:\.(\d+))?)?$/;
7
+ function validateTime(value) {
8
+ if (typeof value !== "string") {
9
+ throw new TypeError(`Time value must be a string, got: ${typeof value}`);
10
+ }
11
+ const match = TIME_REGEX.exec(value);
12
+ if (!match) {
13
+ throw new TypeError(`Value is not a valid time: ${value}`);
14
+ }
15
+ const hours = match[1];
16
+ const minutes = match[2];
17
+ const seconds = match[3] || "00";
18
+ const fraction = match[4] ? `.${match[4]}` : "";
19
+ return `${hours}:${minutes}:${seconds}${fraction}`;
20
+ }
6
21
  class CustomTypesProvider {
7
22
  constructor() {
8
23
  __publicField(this, "uuidType", UuidType);
@@ -14,6 +29,21 @@ class CustomTypesProvider {
14
29
  return ast.kind === Kind.STRING ? ast.value : void 0;
15
30
  }
16
31
  }));
32
+ __publicField(this, "timeType", new GraphQLScalarType({
33
+ name: "Time",
34
+ serialize(value) {
35
+ return validateTime(value);
36
+ },
37
+ parseValue(value) {
38
+ return validateTime(value);
39
+ },
40
+ parseLiteral(ast) {
41
+ if (ast.kind !== Kind.STRING) {
42
+ throw new TypeError(`Time scalar can only parse string values, got: ${ast.kind}`);
43
+ }
44
+ return validateTime(ast.value);
45
+ }
46
+ }));
17
47
  __publicField(this, "dateTimeType", new GraphQLScalarType({
18
48
  name: "DateTime",
19
49
  serialize: (str) => String(str),
@@ -1 +1 @@
1
- {"version":3,"file":"CustomTypesProvider.js","sources":["../../../../../packages/engine-content-api/src/schema/CustomTypesProvider.ts"],"sourcesContent":["import { GraphQLScalarType, Kind } from 'graphql'\nimport { JSONType, UuidType } from '@contember/graphql-utils'\n\n\nexport class CustomTypesProvider {\n\tpublic readonly uuidType: GraphQLScalarType = UuidType\n\n\t//todo: implement serialize, parseValue and parseLiteral properly\n\tpublic readonly dateType: GraphQLScalarType = new GraphQLScalarType({\n\t\tname: 'Date',\n\t\tserialize: str => String(str),\n\t\tparseValue: str => String(str),\n\t\tparseLiteral: function parseLiteral(ast) {\n\t\t\treturn ast.kind === Kind.STRING ? ast.value : undefined\n\t\t},\n\t})\n\tpublic readonly dateTimeType: GraphQLScalarType = new GraphQLScalarType({\n\t\tname: 'DateTime',\n\t\tserialize: str => String(str),\n\t\tparseValue: str => String(str),\n\t\tparseLiteral: function parseLiteral(ast) {\n\t\t\treturn ast.kind === Kind.STRING ? ast.value : undefined\n\t\t},\n\t})\n\tpublic readonly jsonType: GraphQLScalarType = JSONType\n}\n"],"names":[],"mappings":";;;;;AAIO,MAAM,oBAAoB;AAAA,EAA1B,cAAA;AACN,kBAAA,MAAgB,YAA8B,QAAA;AAG9B,kBAAA,MAAA,YAA8B,IAAI,kBAAkB;AAAA,MACnE,MAAM;AAAA,MACN,WAAW,CAAO,QAAA,OAAO,GAAG;AAAA,MAC5B,YAAY,CAAO,QAAA,OAAO,GAAG;AAAA,MAC7B,cAAc,SAAS,aAAa,KAAK;AACxC,eAAO,IAAI,SAAS,KAAK,SAAS,IAAI,QAAQ;AAAA,MAAA;AAAA,IAC/C,CACA,CAAA;AACe,kBAAA,MAAA,gBAAkC,IAAI,kBAAkB;AAAA,MACvE,MAAM;AAAA,MACN,WAAW,CAAO,QAAA,OAAO,GAAG;AAAA,MAC5B,YAAY,CAAO,QAAA,OAAO,GAAG;AAAA,MAC7B,cAAc,SAAS,aAAa,KAAK;AACxC,eAAO,IAAI,SAAS,KAAK,SAAS,IAAI,QAAQ;AAAA,MAAA;AAAA,IAC/C,CACA,CAAA;AACD,kBAAA,MAAgB,YAA8B,QAAA;AAAA,EAAA;AAC/C;"}
1
+ {"version":3,"file":"CustomTypesProvider.js","sources":["../../../../../packages/engine-content-api/src/schema/CustomTypesProvider.ts"],"sourcesContent":["import { GraphQLScalarType, Kind } from 'graphql'\nimport { JSONType, UuidType } from '@contember/graphql-utils'\n\nconst TIME_REGEX = /^([01]\\d|2[0-3]):([0-5]\\d)(?::([0-5]\\d)(?:\\.(\\d+))?)?$/\n\nfunction validateTime(value: unknown): string {\n\tif (typeof value !== 'string') {\n\t\tthrow new TypeError(`Time value must be a string, got: ${typeof value}`)\n\t}\n\tconst match = TIME_REGEX.exec(value)\n\tif (!match) {\n\t\tthrow new TypeError(`Value is not a valid time: ${value}`)\n\t}\n\n\tconst hours = match[1]\n\tconst minutes = match[2]\n\tconst seconds = match[3] || '00'\n\tconst fraction = match[4] ? `.${match[4]}` : ''\n\n\treturn `${hours}:${minutes}:${seconds}${fraction}`\n}\n\n\nexport class CustomTypesProvider {\n\tpublic readonly uuidType: GraphQLScalarType = UuidType\n\n\t//todo: implement serialize, parseValue and parseLiteral properly\n\n\tpublic readonly dateType: GraphQLScalarType = new GraphQLScalarType({\n\t\tname: 'Date',\n\t\tserialize: str => String(str),\n\t\tparseValue: str => String(str),\n\t\tparseLiteral: function parseLiteral(ast) {\n\t\t\treturn ast.kind === Kind.STRING ? ast.value : undefined\n\t\t},\n\t})\n\n\tpublic readonly timeType: GraphQLScalarType = new GraphQLScalarType({\n\t\tname: 'Time',\n\t\tserialize(value) {\n\t\t\treturn validateTime(value)\n\t\t},\n\t\tparseValue(value) {\n\t\t\treturn validateTime(value)\n\t\t},\n\t\tparseLiteral(ast) {\n\t\t\tif (ast.kind !== Kind.STRING) {\n\t\t\t\tthrow new TypeError(`Time scalar can only parse string values, got: ${ast.kind}`)\n\t\t\t}\n\t\t\treturn validateTime(ast.value)\n\t\t},\n\t})\n\n\tpublic readonly dateTimeType: GraphQLScalarType = new GraphQLScalarType({\n\t\tname: 'DateTime',\n\t\tserialize: str => String(str),\n\t\tparseValue: str => String(str),\n\t\tparseLiteral: function parseLiteral(ast) {\n\t\t\treturn ast.kind === Kind.STRING ? ast.value : undefined\n\t\t},\n\t})\n\tpublic readonly jsonType: GraphQLScalarType = JSONType\n}\n"],"names":[],"mappings":";;;;;AAGA,MAAM,aAAa;AAEnB,SAAS,aAAa,OAAwB;AACzC,MAAA,OAAO,UAAU,UAAU;AAC9B,UAAM,IAAI,UAAU,qCAAqC,OAAO,KAAK,EAAE;AAAA,EAAA;AAElE,QAAA,QAAQ,WAAW,KAAK,KAAK;AACnC,MAAI,CAAC,OAAO;AACX,UAAM,IAAI,UAAU,8BAA8B,KAAK,EAAE;AAAA,EAAA;AAGpD,QAAA,QAAQ,MAAM,CAAC;AACf,QAAA,UAAU,MAAM,CAAC;AACjB,QAAA,UAAU,MAAM,CAAC,KAAK;AACtB,QAAA,WAAW,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,KAAK;AAE7C,SAAO,GAAG,KAAK,IAAI,OAAO,IAAI,OAAO,GAAG,QAAQ;AACjD;AAGO,MAAM,oBAAoB;AAAA,EAA1B,cAAA;AACN,kBAAA,MAAgB,YAA8B,QAAA;AAI9B,kBAAA,MAAA,YAA8B,IAAI,kBAAkB;AAAA,MACnE,MAAM;AAAA,MACN,WAAW,CAAO,QAAA,OAAO,GAAG;AAAA,MAC5B,YAAY,CAAO,QAAA,OAAO,GAAG;AAAA,MAC7B,cAAc,SAAS,aAAa,KAAK;AACxC,eAAO,IAAI,SAAS,KAAK,SAAS,IAAI,QAAQ;AAAA,MAAA;AAAA,IAC/C,CACA,CAAA;AAEe,kBAAA,MAAA,YAA8B,IAAI,kBAAkB;AAAA,MACnE,MAAM;AAAA,MACN,UAAU,OAAO;AAChB,eAAO,aAAa,KAAK;AAAA,MAC1B;AAAA,MACA,WAAW,OAAO;AACjB,eAAO,aAAa,KAAK;AAAA,MAC1B;AAAA,MACA,aAAa,KAAK;AACb,YAAA,IAAI,SAAS,KAAK,QAAQ;AAC7B,gBAAM,IAAI,UAAU,kDAAkD,IAAI,IAAI,EAAE;AAAA,QAAA;AAE1E,eAAA,aAAa,IAAI,KAAK;AAAA,MAAA;AAAA,IAC9B,CACA,CAAA;AAEe,kBAAA,MAAA,gBAAkC,IAAI,kBAAkB;AAAA,MACvE,MAAM;AAAA,MACN,WAAW,CAAO,QAAA,OAAO,GAAG;AAAA,MAC5B,YAAY,CAAO,QAAA,OAAO,GAAG;AAAA,MAC7B,cAAc,SAAS,aAAa,KAAK;AACxC,eAAO,IAAI,SAAS,KAAK,SAAS,IAAI,QAAQ;AAAA,MAAA;AAAA,IAC/C,CACA,CAAA;AACD,kBAAA,MAAgB,YAA8B,QAAA;AAAA,EAAA;AAC/C;"}
@@ -48,7 +48,12 @@ class OrderByTypeProvider {
48
48
  continue;
49
49
  }
50
50
  const field = schemaUtils.acceptFieldVisitor(this.schema, name, fieldName, {
51
- visitColumn: () => ({ type: this.orderDirectionEnum }),
51
+ visitColumn: ({ column }) => {
52
+ if (column.list) {
53
+ return void 0;
54
+ }
55
+ return { type: this.orderDirectionEnum };
56
+ },
52
57
  visitHasOne: ({ relation }) => ({ type: this.getEntityOrderByType(relation.target) }),
53
58
  visitHasMany: () => void 0
54
59
  });
@@ -1 +1 @@
1
- {"version":3,"file":"OrderByTypeProvider.cjs","sources":["../../../../../packages/engine-content-api/src/schema/OrderByTypeProvider.ts"],"sourcesContent":["import {\n\tGraphQLBoolean,\n\tGraphQLEnumType,\n\tGraphQLInputFieldConfig,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType,\n\tGraphQLInputType,\n\tGraphQLInt,\n} from 'graphql'\nimport { Acl, Model } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { singletonFactory } from '../utils'\nimport { GqlTypeName } from './utils'\nimport { Authorizator } from '../acl'\nimport { FieldAccessVisitor } from './FieldAccessVisitor'\n\nexport class OrderByTypeProvider {\n\tprivate orderBySingleton = singletonFactory(name => this.createEntityOrderByType(name))\n\n\tprivate orderDirectionEnum = new GraphQLEnumType({\n\t\tname: 'OrderDirection',\n\t\tvalues: {\n\t\t\tasc: { value: 'asc' },\n\t\t\tdesc: { value: 'desc' },\n\t\t\tascNullsFirst: { value: 'ascNullsFirst' },\n\t\t\tdescNullsLast: { value: 'descNullsLast' },\n\t\t},\n\t})\n\n\tconstructor(private readonly schema: Model.Schema, private readonly authorizator: Authorizator) {}\n\n\tpublic getEntityOrderByType(entityName: string): GraphQLInputType {\n\t\treturn this.orderBySingleton(entityName)\n\t}\n\n\tprivate createEntityOrderByType(entityName: string): GraphQLInputType {\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entityName}OrderBy`,\n\t\t\tfields: () => this.getEntityOrderByFields(entityName),\n\t\t})\n\t}\n\n\tprivate getEntityOrderByFields(name: string) {\n\t\tconst fields: GraphQLInputFieldConfigMap = {\n\t\t\t_random: { type: GraphQLBoolean },\n\t\t\t_randomSeeded: { type: GraphQLInt },\n\t\t}\n\t\tconst entity = this.schema.entities[name]\n\n\t\tfor (const fieldName in entity.fields) {\n\t\t\tif (!entity.fields.hasOwnProperty(fieldName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst accessVisitor = new FieldAccessVisitor(Acl.Operation.read, this.authorizator)\n\t\t\tif (!acceptFieldVisitor(this.schema, name, fieldName, accessVisitor)) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst field = acceptFieldVisitor(this.schema, name, fieldName, {\n\t\t\t\tvisitColumn: () => ({ type: this.orderDirectionEnum }),\n\t\t\t\tvisitHasOne: ({ relation }) => ({ type: this.getEntityOrderByType(relation.target) }),\n\t\t\t\tvisitHasMany: () => undefined,\n\t\t\t} as Model.FieldVisitor<GraphQLInputFieldConfig | undefined>)\n\n\t\t\tif (field !== undefined) {\n\t\t\t\tfields[fieldName] = field\n\t\t\t}\n\t\t}\n\n\t\treturn fields\n\t}\n}\n"],"names":["schema","singletonFactory","GraphQLEnumType","GraphQLInputObjectType","GqlTypeName","GraphQLBoolean","GraphQLInt","FieldAccessVisitor","Acl","acceptFieldVisitor"],"mappings":";;;;;;;;;;;AAgBO,MAAM,oBAAoB;AAAA,EAahC,YAA6BA,SAAuC,cAA4B;AAAnE,SAAA,SAAAA;AAAuC,SAAA,eAAA;AAZpE,kBAAA,MAAQ,oBAAmBC,kCAAiB,CAAA,SAAQ,KAAK,wBAAwB,IAAI,CAAC,CAAA;AAE9E,kBAAA,MAAA,sBAAqB,IAAIC,wBAAgB;AAAA,MAChD,MAAM;AAAA,MACN,QAAQ;AAAA,QACP,KAAK,EAAE,OAAO,MAAM;AAAA,QACpB,MAAM,EAAE,OAAO,OAAO;AAAA,QACtB,eAAe,EAAE,OAAO,gBAAgB;AAAA,QACxC,eAAe,EAAE,OAAO,gBAAgB;AAAA,MAAA;AAAA,IACzC,CACA,CAAA;AAAA,EAAA;AAAA,EAIM,qBAAqB,YAAsC;AAC1D,WAAA,KAAK,iBAAiB,UAAU;AAAA,EAAA;AAAA,EAGhC,wBAAwB,YAAsC;AACrE,WAAO,IAAIC,QAAAA,uBAAuB;AAAA,MACjC,MAAMC,oBAAc,UAAU;AAAA,MAC9B,QAAQ,MAAM,KAAK,uBAAuB,UAAU;AAAA,IAAA,CACpD;AAAA,EAAA;AAAA,EAGM,uBAAuB,MAAc;AAC5C,UAAM,SAAqC;AAAA,MAC1C,SAAS,EAAE,MAAMC,uBAAe;AAAA,MAChC,eAAe,EAAE,MAAMC,QAAW,WAAA;AAAA,IACnC;AACA,UAAM,SAAS,KAAK,OAAO,SAAS,IAAI;AAE7B,eAAA,aAAa,OAAO,QAAQ;AACtC,UAAI,CAAC,OAAO,OAAO,eAAe,SAAS,GAAG;AAC7C;AAAA,MAAA;AAED,YAAM,gBAAgB,IAAIC,sCAAmBC,OAAAA,IAAI,UAAU,MAAM,KAAK,YAAY;AAClF,UAAI,CAACC,YAAmB,mBAAA,KAAK,QAAQ,MAAM,WAAW,aAAa,GAAG;AACrE;AAAA,MAAA;AAGD,YAAM,QAAQA,YAAAA,mBAAmB,KAAK,QAAQ,MAAM,WAAW;AAAA,QAC9D,aAAa,OAAO,EAAE,MAAM,KAAK,mBAAmB;AAAA,QACpD,aAAa,CAAC,EAAE,SAAS,OAAO,EAAE,MAAM,KAAK,qBAAqB,SAAS,MAAM;QACjF,cAAc,MAAM;AAAA,MAAA,CACuC;AAE5D,UAAI,UAAU,QAAW;AACxB,eAAO,SAAS,IAAI;AAAA,MAAA;AAAA,IACrB;AAGM,WAAA;AAAA,EAAA;AAET;;"}
1
+ {"version":3,"file":"OrderByTypeProvider.cjs","sources":["../../../../../packages/engine-content-api/src/schema/OrderByTypeProvider.ts"],"sourcesContent":["import {\n\tGraphQLBoolean,\n\tGraphQLEnumType,\n\tGraphQLInputFieldConfig,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType,\n\tGraphQLInputType,\n\tGraphQLInt,\n} from 'graphql'\nimport { Acl, Model } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { singletonFactory } from '../utils'\nimport { GqlTypeName } from './utils'\nimport { Authorizator } from '../acl'\nimport { FieldAccessVisitor } from './FieldAccessVisitor'\n\nexport class OrderByTypeProvider {\n\tprivate orderBySingleton = singletonFactory(name => this.createEntityOrderByType(name))\n\n\tprivate orderDirectionEnum = new GraphQLEnumType({\n\t\tname: 'OrderDirection',\n\t\tvalues: {\n\t\t\tasc: { value: 'asc' },\n\t\t\tdesc: { value: 'desc' },\n\t\t\tascNullsFirst: { value: 'ascNullsFirst' },\n\t\t\tdescNullsLast: { value: 'descNullsLast' },\n\t\t},\n\t})\n\n\tconstructor(private readonly schema: Model.Schema, private readonly authorizator: Authorizator) {}\n\n\tpublic getEntityOrderByType(entityName: string): GraphQLInputType {\n\t\treturn this.orderBySingleton(entityName)\n\t}\n\n\tprivate createEntityOrderByType(entityName: string): GraphQLInputType {\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entityName}OrderBy`,\n\t\t\tfields: () => this.getEntityOrderByFields(entityName),\n\t\t})\n\t}\n\n\tprivate getEntityOrderByFields(name: string) {\n\t\tconst fields: GraphQLInputFieldConfigMap = {\n\t\t\t_random: { type: GraphQLBoolean },\n\t\t\t_randomSeeded: { type: GraphQLInt },\n\t\t}\n\t\tconst entity = this.schema.entities[name]\n\n\t\tfor (const fieldName in entity.fields) {\n\t\t\tif (!entity.fields.hasOwnProperty(fieldName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst accessVisitor = new FieldAccessVisitor(Acl.Operation.read, this.authorizator)\n\t\t\tif (!acceptFieldVisitor(this.schema, name, fieldName, accessVisitor)) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst field = acceptFieldVisitor(this.schema, name, fieldName, {\n\t\t\t\tvisitColumn: ({ column }) => {\n\t\t\t\t\tif (column.list) {\n\t\t\t\t\t\treturn undefined\n\t\t\t\t\t}\n\t\t\t\t\treturn ({ type: this.orderDirectionEnum })\n\t\t\t\t},\n\t\t\t\tvisitHasOne: ({ relation }) => ({ type: this.getEntityOrderByType(relation.target) }),\n\t\t\t\tvisitHasMany: () => undefined,\n\t\t\t} as Model.FieldVisitor<GraphQLInputFieldConfig | undefined>)\n\n\t\t\tif (field !== undefined) {\n\t\t\t\tfields[fieldName] = field\n\t\t\t}\n\t\t}\n\n\t\treturn fields\n\t}\n}\n"],"names":["schema","singletonFactory","GraphQ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G;AACrE;AAAA,MAAA;AAGD,YAAM,QAAQA,YAAAA,mBAAmB,KAAK,QAAQ,MAAM,WAAW;AAAA,QAC9D,aAAa,CAAC,EAAE,aAAa;AAC5B,cAAI,OAAO,MAAM;AACT,mBAAA;AAAA,UAAA;AAEA,iBAAA,EAAE,MAAM,KAAK,mBAAmB;AAAA,QACzC;AAAA,QACA,aAAa,CAAC,EAAE,SAAS,OAAO,EAAE,MAAM,KAAK,qBAAqB,SAAS,MAAM;QACjF,cAAc,MAAM;AAAA,MAAA,CACuC;AAE5D,UAAI,UAAU,QAAW;AACxB,eAAO,SAAS,IAAI;AAAA,MAAA;AAAA,IACrB;AAGM,WAAA;AAAA,EAAA;AAET;;"}
@@ -46,7 +46,12 @@ class OrderByTypeProvider {
46
46
  continue;
47
47
  }
48
48
  const field = acceptFieldVisitor(this.schema, name, fieldName, {
49
- visitColumn: () => ({ type: this.orderDirectionEnum }),
49
+ visitColumn: ({ column }) => {
50
+ if (column.list) {
51
+ return void 0;
52
+ }
53
+ return { type: this.orderDirectionEnum };
54
+ },
50
55
  visitHasOne: ({ relation }) => ({ type: this.getEntityOrderByType(relation.target) }),
51
56
  visitHasMany: () => void 0
52
57
  });
@@ -1 +1 @@
1
- {"version":3,"file":"OrderByTypeProvider.js","sources":["../../../../../packages/engine-content-api/src/schema/OrderByTypeProvider.ts"],"sourcesContent":["import {\n\tGraphQLBoolean,\n\tGraphQLEnumType,\n\tGraphQLInputFieldConfig,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType,\n\tGraphQLInputType,\n\tGraphQLInt,\n} from 'graphql'\nimport { Acl, Model } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { singletonFactory } from '../utils'\nimport { GqlTypeName } from './utils'\nimport { Authorizator } from '../acl'\nimport { FieldAccessVisitor } from './FieldAccessVisitor'\n\nexport class OrderByTypeProvider {\n\tprivate orderBySingleton = singletonFactory(name => this.createEntityOrderByType(name))\n\n\tprivate orderDirectionEnum = new GraphQLEnumType({\n\t\tname: 'OrderDirection',\n\t\tvalues: {\n\t\t\tasc: { value: 'asc' },\n\t\t\tdesc: { value: 'desc' },\n\t\t\tascNullsFirst: { value: 'ascNullsFirst' },\n\t\t\tdescNullsLast: { value: 'descNullsLast' },\n\t\t},\n\t})\n\n\tconstructor(private readonly schema: Model.Schema, private readonly authorizator: Authorizator) {}\n\n\tpublic getEntityOrderByType(entityName: string): GraphQLInputType {\n\t\treturn this.orderBySingleton(entityName)\n\t}\n\n\tprivate createEntityOrderByType(entityName: string): GraphQLInputType {\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entityName}OrderBy`,\n\t\t\tfields: () => this.getEntityOrderByFields(entityName),\n\t\t})\n\t}\n\n\tprivate getEntityOrderByFields(name: string) {\n\t\tconst fields: GraphQLInputFieldConfigMap = {\n\t\t\t_random: { type: GraphQLBoolean },\n\t\t\t_randomSeeded: { type: GraphQLInt },\n\t\t}\n\t\tconst entity = this.schema.entities[name]\n\n\t\tfor (const fieldName in entity.fields) {\n\t\t\tif (!entity.fields.hasOwnProperty(fieldName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst accessVisitor = new FieldAccessVisitor(Acl.Operation.read, this.authorizator)\n\t\t\tif (!acceptFieldVisitor(this.schema, name, fieldName, accessVisitor)) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst field = acceptFieldVisitor(this.schema, name, fieldName, {\n\t\t\t\tvisitColumn: () => ({ type: this.orderDirectionEnum }),\n\t\t\t\tvisitHasOne: ({ relation }) => ({ type: this.getEntityOrderByType(relation.target) }),\n\t\t\t\tvisitHasMany: () => undefined,\n\t\t\t} as Model.FieldVisitor<GraphQLInputFieldConfig | undefined>)\n\n\t\t\tif (field !== undefined) {\n\t\t\t\tfields[fieldName] = field\n\t\t\t}\n\t\t}\n\n\t\treturn fields\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;AAgBO,MAAM,oBAAoB;AAAA,E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AAM,KAAK,qBAAqB,SAAS,MAAM;QACjF,cAAc,MAAM;AAAA,MAAA,CACuC;AAE5D,UAAI,UAAU,QAAW;AACxB,eAAO,SAAS,IAAI;AAAA,MAAA;AAAA,IACrB;AAGM,WAAA;AAAA,EAAA;AAET;"}
1
+ {"version":3,"file":"OrderByTypeProvider.js","sources":["../../../../../packages/engine-content-api/src/schema/OrderByTypeProvider.ts"],"sourcesContent":["import {\n\tGraphQLBoolean,\n\tGraphQLEnumType,\n\tGraphQLInputFieldConfig,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType,\n\tGraphQLInputType,\n\tGraphQLInt,\n} from 'graphql'\nimport { Acl, Model } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { singletonFactory } from '../utils'\nimport { GqlTypeName } from './utils'\nimport { Authorizator } from '../acl'\nimport { FieldAccessVisitor } from './FieldAccessVisitor'\n\nexport class OrderByTypeProvider {\n\tprivate orderBySingleton = singletonFactory(name => this.createEntityOrderByType(name))\n\n\tprivate orderDirectionEnum = new GraphQLEnumType({\n\t\tname: 'OrderDirection',\n\t\tvalues: {\n\t\t\tasc: { value: 'asc' },\n\t\t\tdesc: { value: 'desc' },\n\t\t\tascNullsFirst: { value: 'ascNullsFirst' },\n\t\t\tdescNullsLast: { value: 'descNullsLast' },\n\t\t},\n\t})\n\n\tconstructor(private readonly schema: Model.Schema, private readonly authorizator: Authorizator) {}\n\n\tpublic getEntityOrderByType(entityName: string): GraphQLInputType {\n\t\treturn this.orderBySingleton(entityName)\n\t}\n\n\tprivate createEntityOrderByType(entityName: string): GraphQLInputType {\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entityName}OrderBy`,\n\t\t\tfields: () => this.getEntityOrderByFields(entityName),\n\t\t})\n\t}\n\n\tprivate getEntityOrderByFields(name: string) {\n\t\tconst fields: GraphQLInputFieldConfigMap = {\n\t\t\t_random: { type: GraphQLBoolean },\n\t\t\t_randomSeeded: { type: GraphQLInt },\n\t\t}\n\t\tconst entity = this.schema.entities[name]\n\n\t\tfor (const fieldName in entity.fields) {\n\t\t\tif (!entity.fields.hasOwnProperty(fieldName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst accessVisitor = new FieldAccessVisitor(Acl.Operation.read, this.authorizator)\n\t\t\tif (!acceptFieldVisitor(this.schema, name, fieldName, accessVisitor)) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst field = acceptFieldVisitor(this.schema, name, fieldName, {\n\t\t\t\tvisitColumn: ({ column }) => {\n\t\t\t\t\tif (column.list) {\n\t\t\t\t\t\treturn undefined\n\t\t\t\t\t}\n\t\t\t\t\treturn ({ type: this.orderDirectionEnum })\n\t\t\t\t},\n\t\t\t\tvisitHasOne: ({ relation }) => ({ type: this.getEntityOrderByType(relation.target) }),\n\t\t\t\tvisitHasMany: () => undefined,\n\t\t\t} as Model.FieldVisitor<GraphQLInputFieldConfig | undefined>)\n\n\t\t\tif (field !== undefined) {\n\t\t\t\tfields[fieldName] = field\n\t\t\t}\n\t\t}\n\n\t\treturn fields\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;AAgBO,MAAM,oBAAoB;AAAA,EAahC,YAA6B,QAAuC,cAA4B;AAAnE,SAAA,SAAA;AAAuC,SAAA,eAAA;AAZpE,kBAAA,MAAQ,oBAAmB,iBAAiB,CAAA,SAAQ,KAAK,wBAAwB,IAAI,CAAC,CAAA;AAE9E,kBAAA,MAAA,sBAAqB,IAAI,gBAAgB;AAAA,MAChD,MAAM;AAAA,MACN,QAAQ;AAAA,QACP,KAAK,EAAE,OAAO,MAAM;AAAA,QACpB,MAAM,EAAE,OAAO,OAAO;AAAA,QACtB,eAAe,EAAE,OAAO,gBAAgB;AAAA,QACxC,eAAe,EAAE,OAAO,gBAAgB;AAAA,MAAA;AAAA,IACzC,CACA,CAAA;AAAA,EAAA;AAAA,EAIM,qBAAqB,YAAsC;AAC1D,WAAA,KAAK,iBAAiB,UAAU;AAAA,EAAA;AAAA,EAGhC,wBAAwB,YAAsC;AACrE,WAAO,IAAI,uBAAuB;AAAA,MACjC,MAAM,cAAc,UAAU;AAAA,MAC9B,QAAQ,MAAM,KAAK,uBAAuB,UAAU;AAAA,IAAA,CACpD;AAAA,EAAA;AAAA,EAGM,uBAAuB,MAAc;AAC5C,UAAM,SAAqC;AAAA,MAC1C,SAAS,EAAE,MAAM,eAAe;AAAA,MAChC,eAAe,EAAE,MAAM,WAAW;AAAA,IACnC;AACA,UAAM,SAAS,KAAK,OAAO,SAAS,IAAI;AAE7B,eAAA,aAAa,OAAO,QAAQ;AACtC,UAAI,CAAC,OAAO,OAAO,eAAe,SAAS,GAAG;AAC7C;AAAA,MAAA;AAED,YAAM,gBAAgB,IAAI,mBAAmB,IAAI,UAAU,MAAM,KAAK,YAAY;AAClF,UAAI,CAAC,mBAAmB,KAAK,QAAQ,MAAM,WAAW,aAAa,GAAG;AACrE;AAAA,MAAA;AAGD,YAAM,QAAQ,mBAAmB,KAAK,QAAQ,MAAM,WAAW;AAAA,QAC9D,aAAa,CAAC,EAAE,aAAa;AAC5B,cAAI,OAAO,MAAM;AACT,mBAAA;AAAA,UAAA;AAEA,iBAAA,EAAE,MAAM,KAAK,mBAAmB;AAAA,QACzC;AAAA,QACA,aAAa,CAAC,EAAE,SAAS,OAAO,EAAE,MAAM,KAAK,qBAAqB,SAAS,MAAM;QACjF,cAAc,MAAM;AAAA,MAAA,CACuC;AAE5D,UAAI,UAAU,QAAW;AACxB,eAAO,SAAS,IAAI;AAAA,MAAA;AAAA,IACrB;AAGM,WAAA;AAAA,EAAA;AAET;"}
@@ -73,7 +73,7 @@ class WhereTypeProvider {
73
73
  }
74
74
  return { type: uniqueWhere };
75
75
  },
76
- visitColumn: ({ column }) => ({ type: this.columnTypeResolver.getType(column) })
76
+ visitColumn: ({ column }) => ({ type: this.columnTypeResolver.getType(column)[0] })
77
77
  });
78
78
  }
79
79
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WhereTypeProvider.cjs","sources":["../../../../../packages/engine-content-api/src/schema/WhereTypeProvider.ts"],"sourcesContent":["import { Acl, Model } from '@contember/schema'\nimport { acceptFieldVisitor, getEntity } from '@contember/schema-utils'\nimport { GraphQLInputFieldConfig, GraphQLInputFieldConfigMap, GraphQLInputObjectType, GraphQLList } from 'graphql'\nimport { capitalizeFirstLetter, getFieldsForUniqueWhere, singletonFactory } from '../utils'\nimport { ColumnTypeResolver } from './ColumnTypeResolver'\nimport { ConditionTypeProvider } from './ConditionTypeProvider'\nimport { GqlTypeName } from './utils'\nimport { Authorizator } from '../acl'\nimport { FieldAccessVisitor } from './FieldAccessVisitor'\nimport { ImplementationException } from '../exception'\n\nexport class WhereTypeProvider {\n\tprivate whereSingleton = singletonFactory(name => this.createEntityWhereType(name))\n\tprivate uniqueWhereSingleton = singletonFactory(name => this.createEntityUniqueWhereType(name))\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t\tprivate readonly columnTypeResolver: ColumnTypeResolver,\n\t\tprivate readonly conditionTypeProvider: ConditionTypeProvider,\n\t) {}\n\n\tpublic getEntityWhereType(entityName: string): GraphQLInputObjectType {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, entityName) === 'no') {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn this.whereSingleton(entityName)\n\t}\n\n\tpublic getEntityUniqueWhereType(entityName: string): undefined | GraphQLInputObjectType {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, entityName) === 'no') {\n\t\t\treturn undefined\n\t\t}\n\t\treturn this.uniqueWhereSingleton(entityName)\n\t}\n\n\tprivate createEntityWhereType(entityName: string) {\n\t\tconst where: GraphQLInputObjectType = new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entityName}Where`,\n\t\t\tfields: () => this.getEntityWhereFields(entityName, where),\n\t\t})\n\n\t\treturn where\n\t}\n\n\tprivate createEntityUniqueWhereType(entityName: string, withoutRelation?: string) {\n\t\tconst entity = getEntity(this.schema, entityName)\n\n\t\tconst combinations: string[] = []\n\n\t\tconst possibleUniqueWhereFields = getFieldsForUniqueWhere(this.schema, entity)\n\t\tconst uniqueKeys: (readonly string[])[] = possibleUniqueWhereFields.filter(uniqueKey =>\n\t\t\tuniqueKey.every(it =>\n\t\t\t\tacceptFieldVisitor(this.schema, entityName, it, new FieldAccessVisitor(Acl.Operation.read, this.authorizator)),\n\t\t\t),\n\t\t)\n\t\tfor (const uniqueKey of uniqueKeys) {\n\t\t\tcombinations.push(uniqueKey.join(', '))\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: capitalizeFirstLetter(entityName) + 'UniqueWhere',\n\t\t\t// description: `Valid combinations are: (${combinations.join('), (')})`, generates invalid schema file\n\t\t\tfields: () => this.getUniqueWhereFields(entity, uniqueKeys),\n\t\t})\n\t}\n\n\tpublic getUniqueWhereFields(entity: Model.Entity, uniqueKeys: (readonly string[])[]) {\n\t\tconst fields: GraphQLInputFieldConfigMap = {}\n\t\tfor (const uniqueKey of uniqueKeys) {\n\t\t\tfor (const field of uniqueKey) {\n\t\t\t\tif (fields[field] !== undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfields[field] = acceptFieldVisitor<GraphQLInputFieldConfig>(this.schema, entity, field, {\n\t\t\t\t\tvisitRelation: ({ targetEntity }) => {\n\t\t\t\t\t\t// if (!isIt<Model.JoiningColumnRelation>(relation, 'joiningColumn')) {\n\t\t\t\t\t\t// \tthrow new Error('Only column or owning relation can be a part of unique key')\n\t\t\t\t\t\t// }\n\t\t\t\t\t\tconst uniqueWhere = this.getEntityUniqueWhereType(targetEntity.name)\n\t\t\t\t\t\tif (!uniqueWhere) {\n\t\t\t\t\t\t\tthrow new ImplementationException()\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn { type: uniqueWhere }\n\t\t\t\t\t},\n\t\t\t\t\tvisitColumn: ({ column }) => ({ type: this.columnTypeResolver.getType(column) }),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn fields\n\t}\n\n\tprivate getEntityWhereFields(name: string, where: GraphQLInputObjectType) {\n\t\tconst fields: GraphQLInputFieldConfigMap = {}\n\t\tconst entity = this.schema.entities[name]\n\n\t\tfor (const fieldName in entity.fields) {\n\t\t\tif (!entity.fields.hasOwnProperty(fieldName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst accessVisitor = new FieldAccessVisitor(Acl.Operation.read, this.authorizator)\n\t\t\tif (!acceptFieldVisitor(this.schema, name, fieldName, accessVisitor)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfields[fieldName] = acceptFieldVisitor(this.schema, name, fieldName, {\n\t\t\t\tvisitColumn: ({ column }) => ({ type: this.conditionTypeProvider.getCondition(column) }),\n\t\t\t\tvisitRelation: ({ relation }) => ({ type: this.getEntityWhereType(relation.target) }),\n\t\t\t} as Model.FieldVisitor<GraphQLInputFieldConfig>)\n\t\t}\n\n\t\tfields.and = { type: new GraphQLList(where) }\n\t\tfields.or = { type: new GraphQLList(where) }\n\t\tfields.not = { type: where }\n\n\t\treturn fields\n\t}\n}\n"],"names":["schema","singletonFactory","Acl","ImplementationException","GraphQLInputObjectType","GqlTypeName","getEntity","getFieldsForUniqueWhere","acceptFieldVisitor","FieldAccessVisitor","capitalizeFirstLetter","GraphQLList"],"mappings":";;;;;;;;;;;;;;AAWO,MAAM,kBAAkB;AAAA,EAI9B,YACkBA,SACA,cACA,oBACA,uBAChB;AAJgB,SAAA,SAAAA;AACA,SAAA,eAAA;AACA,SAAA,qBAAA;AACA,SAAA,wBAAA;AAPlB,kBAAA,MAAQ,kBAAiBC,kCAAiB,CAAA,SAAQ,KAAK,sBAAsB,IAAI,CAAC,CAAA;AAClF,kBAAA,MAAQ,wBAAuBA,kCAAiB,CAAA,SAAQ,KAAK,4BAA4B,IAAI,CAAC,CAAA;AAAA,EAAA;AAAA,EASvF,mBAAmB,YAA4C;AACjE,QAAA,KA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AA,YAAY,KAAK,EAAE;AACpC,WAAA,MAAM,EAAE,MAAM,MAAM;AAEpB,WAAA;AAAA,EAAA;AAET;;"}
1
+ {"version":3,"file":"WhereTypeProvider.cjs","sources":["../../../../../packages/engine-content-api/src/schema/WhereTypeProvider.ts"],"sourcesContent":["import { Acl, Model } from '@contember/schema'\nimport { acceptFieldVisitor, getEntity } from '@contember/schema-utils'\nimport { GraphQLInputFieldConfig, GraphQLInputFieldConfigMap, GraphQLInputObjectType, GraphQLList } from 'graphql'\nimport { capitalizeFirstLetter, getFieldsForUniqueWhere, singletonFactory } from '../utils'\nimport { ColumnTypeResolver } from './ColumnTypeResolver'\nimport { ConditionTypeProvider } from './ConditionTypeProvider'\nimport { GqlTypeName } from './utils'\nimport { Authorizator } from '../acl'\nimport { FieldAccessVisitor } from './FieldAccessVisitor'\nimport { ImplementationException } from '../exception'\n\nexport class WhereTypeProvider {\n\tprivate whereSingleton = singletonFactory(name => this.createEntityWhereType(name))\n\tprivate uniqueWhereSingleton = singletonFactory(name => this.createEntityUniqueWhereType(name))\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t\tprivate readonly columnTypeResolver: ColumnTypeResolver,\n\t\tprivate readonly conditionTypeProvider: ConditionTypeProvider,\n\t) {}\n\n\tpublic getEntityWhereType(entityName: string): GraphQLInputObjectType {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, entityName) === 'no') {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn this.whereSingleton(entityName)\n\t}\n\n\tpublic getEntityUniqueWhereType(entityName: string): undefined | GraphQLInputObjectType {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, entityName) === 'no') {\n\t\t\treturn undefined\n\t\t}\n\t\treturn this.uniqueWhereSingleton(entityName)\n\t}\n\n\tprivate createEntityWhereType(entityName: string) {\n\t\tconst where: GraphQLInputObjectType = new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entityName}Where`,\n\t\t\tfields: () => this.getEntityWhereFields(entityName, where),\n\t\t})\n\n\t\treturn where\n\t}\n\n\tprivate createEntityUniqueWhereType(entityName: string, withoutRelation?: string) {\n\t\tconst entity = getEntity(this.schema, entityName)\n\n\t\tconst combinations: string[] = []\n\n\t\tconst possibleUniqueWhereFields = getFieldsForUniqueWhere(this.schema, entity)\n\t\tconst uniqueKeys: (readonly string[])[] = possibleUniqueWhereFields.filter(uniqueKey =>\n\t\t\tuniqueKey.every(it =>\n\t\t\t\tacceptFieldVisitor(this.schema, entityName, it, new FieldAccessVisitor(Acl.Operation.read, this.authorizator)),\n\t\t\t),\n\t\t)\n\t\tfor (const uniqueKey of uniqueKeys) {\n\t\t\tcombinations.push(uniqueKey.join(', '))\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: capitalizeFirstLetter(entityName) + 'UniqueWhere',\n\t\t\t// description: `Valid combinations are: (${combinations.join('), (')})`, generates invalid schema file\n\t\t\tfields: () => this.getUniqueWhereFields(entity, uniqueKeys),\n\t\t})\n\t}\n\n\tpublic getUniqueWhereFields(entity: Model.Entity, uniqueKeys: (readonly string[])[]) {\n\t\tconst fields: GraphQLInputFieldConfigMap = {}\n\t\tfor (const uniqueKey of uniqueKeys) {\n\t\t\tfor (const field of uniqueKey) {\n\t\t\t\tif (fields[field] !== undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfields[field] = acceptFieldVisitor<GraphQLInputFieldConfig>(this.schema, entity, field, {\n\t\t\t\t\tvisitRelation: ({ targetEntity }) => {\n\t\t\t\t\t\t// if (!isIt<Model.JoiningColumnRelation>(relation, 'joiningColumn')) {\n\t\t\t\t\t\t// \tthrow new Error('Only column or owning relation can be a part of unique key')\n\t\t\t\t\t\t// }\n\t\t\t\t\t\tconst uniqueWhere = this.getEntityUniqueWhereType(targetEntity.name)\n\t\t\t\t\t\tif (!uniqueWhere) {\n\t\t\t\t\t\t\tthrow new ImplementationException()\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn { type: uniqueWhere }\n\t\t\t\t\t},\n\t\t\t\t\tvisitColumn: ({ column }) => ({ type: this.columnTypeResolver.getType(column)[0] }),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn fields\n\t}\n\n\tprivate getEntityWhereFields(name: string, where: GraphQLInputObjectType) {\n\t\tconst fields: GraphQLInputFieldConfigMap = {}\n\t\tconst entity = this.schema.entities[name]\n\n\t\tfor (const fieldName in entity.fields) {\n\t\t\tif (!entity.fields.hasOwnProperty(fieldName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst accessVisitor = new FieldAccessVisitor(Acl.Operation.read, this.authorizator)\n\t\t\tif (!acceptFieldVisitor(this.schema, name, fieldName, accessVisitor)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfields[fieldName] = acceptFieldVisitor(this.schema, name, fieldName, {\n\t\t\t\tvisitColumn: ({ column }) => ({ type: this.conditionTypeProvider.getCondition(column) }),\n\t\t\t\tvisitRelation: ({ relation }) => ({ type: this.getEntityWhereType(relation.target) }),\n\t\t\t} as Model.FieldVisitor<GraphQLInputFieldConfig>)\n\t\t}\n\n\t\tfields.and = { type: new GraphQLList(where) }\n\t\tfields.or = { type: new GraphQLList(where) }\n\t\tfields.not = { type: where }\n\n\t\treturn fields\n\t}\n}\n"],"names":["schema","singletonFactory","Acl","ImplementationException","GraphQLInputObjectType","GqlTypeName","getEntity","getFieldsForUniqueWhere","acceptFieldVisitor","FieldAccessVisitor","capitalizeFirstLetter","GraphQLList"],"mappings":";;;;;;;;;;;;;;AAWO,MAAM,kBAAkB;AAAA,EAI9B,YACkBA,SACA,cACA,oBACA,uBAChB;AAJgB,SAAA,SAAAA;AACA,SAAA,eAAA;AACA,SAAA,qBAAA;AACA,SAAA,wBAAA;AAPlB,kBAAA,MAAQ,kBAAiBC,kCAAiB,CAAA,SAAQ,KAAK,sBAAsB,IAAI,CAAC,CAAA;AAClF,kBAAA,MAAQ,wB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AAA,CACpC;AAAA,IAAA;AAGjD,WAAO,MAAM,EAAE,MAAM,IAAIG,QAAA,YAAY,KAAK,EAAE;AAC5C,WAAO,KAAK,EAAE,MAAM,IAAIA,QAAA,YAAY,KAAK,EAAE;AACpC,WAAA,MAAM,EAAE,MAAM,MAAM;AAEpB,WAAA;AAAA,EAAA;AAET;;"}
@@ -71,7 +71,7 @@ class WhereTypeProvider {
71
71
  }
72
72
  return { type: uniqueWhere };
73
73
  },
74
- visitColumn: ({ column }) => ({ type: this.columnTypeResolver.getType(column) })
74
+ visitColumn: ({ column }) => ({ type: this.columnTypeResolver.getType(column)[0] })
75
75
  });
76
76
  }
77
77
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WhereTypeProvider.js","sources":["../../../../../packages/engine-content-api/src/schema/WhereTypeProvider.ts"],"sourcesContent":["import { Acl, Model } from '@contember/schema'\nimport { acceptFieldVisitor, getEntity } from '@contember/schema-utils'\nimport { GraphQLInputFieldConfig, GraphQLInputFieldConfigMap, GraphQLInputObjectType, GraphQLList } from 'graphql'\nimport { capitalizeFirstLetter, getFieldsForUniqueWhere, singletonFactory } from '../utils'\nimport { ColumnTypeResolver } from './ColumnTypeResolver'\nimport { ConditionTypeProvider } from './ConditionTypeProvider'\nimport { GqlTypeName } from './utils'\nimport { Authorizator } from '../acl'\nimport { FieldAccessVisitor } from './FieldAccessVisitor'\nimport { ImplementationException } from '../exception'\n\nexport class WhereTypeProvider {\n\tprivate whereSingleton = singletonFactory(name => this.createEntityWhereType(name))\n\tprivate uniqueWhereSingleton = singletonFactory(name => this.createEntityUniqueWhereType(name))\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t\tprivate readonly columnTypeResolver: ColumnTypeResolver,\n\t\tprivate readonly conditionTypeProvider: ConditionTypeProvider,\n\t) {}\n\n\tpublic getEntityWhereType(entityName: string): GraphQLInputObjectType {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, entityName) === 'no') {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn this.whereSingleton(entityName)\n\t}\n\n\tpublic getEntityUniqueWhereType(entityName: string): undefined | GraphQLInputObjectType {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, entityName) === 'no') {\n\t\t\treturn undefined\n\t\t}\n\t\treturn this.uniqueWhereSingleton(entityName)\n\t}\n\n\tprivate createEntityWhereType(entityName: string) {\n\t\tconst where: GraphQLInputObjectType = new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entityName}Where`,\n\t\t\tfields: () => this.getEntityWhereFields(entityName, where),\n\t\t})\n\n\t\treturn where\n\t}\n\n\tprivate createEntityUniqueWhereType(entityName: string, withoutRelation?: string) {\n\t\tconst entity = getEntity(this.schema, entityName)\n\n\t\tconst combinations: string[] = []\n\n\t\tconst possibleUniqueWhereFields = getFieldsForUniqueWhere(this.schema, entity)\n\t\tconst uniqueKeys: (readonly string[])[] = possibleUniqueWhereFields.filter(uniqueKey =>\n\t\t\tuniqueKey.every(it =>\n\t\t\t\tacceptFieldVisitor(this.schema, entityName, it, new FieldAccessVisitor(Acl.Operation.read, this.authorizator)),\n\t\t\t),\n\t\t)\n\t\tfor (const uniqueKey of uniqueKeys) {\n\t\t\tcombinations.push(uniqueKey.join(', '))\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: capitalizeFirstLetter(entityName) + 'UniqueWhere',\n\t\t\t// description: `Valid combinations are: (${combinations.join('), (')})`, generates invalid schema file\n\t\t\tfields: () => this.getUniqueWhereFields(entity, uniqueKeys),\n\t\t})\n\t}\n\n\tpublic getUniqueWhereFields(entity: Model.Entity, uniqueKeys: (readonly string[])[]) {\n\t\tconst fields: GraphQLInputFieldConfigMap = {}\n\t\tfor (const uniqueKey of uniqueKeys) {\n\t\t\tfor (const field of uniqueKey) {\n\t\t\t\tif (fields[field] !== undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfields[field] = acceptFieldVisitor<GraphQLInputFieldConfig>(this.schema, entity, field, {\n\t\t\t\t\tvisitRelation: ({ targetEntity }) => {\n\t\t\t\t\t\t// if (!isIt<Model.JoiningColumnRelation>(relation, 'joiningColumn')) {\n\t\t\t\t\t\t// \tthrow new Error('Only column or owning relation can be a part of unique key')\n\t\t\t\t\t\t// }\n\t\t\t\t\t\tconst uniqueWhere = this.getEntityUniqueWhereType(targetEntity.name)\n\t\t\t\t\t\tif (!uniqueWhere) {\n\t\t\t\t\t\t\tthrow new ImplementationException()\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn { type: uniqueWhere }\n\t\t\t\t\t},\n\t\t\t\t\tvisitColumn: ({ column }) => ({ type: this.columnTypeResolver.getType(column) }),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn fields\n\t}\n\n\tprivate getEntityWhereFields(name: string, where: GraphQLInputObjectType) {\n\t\tconst fields: GraphQLInputFieldConfigMap = {}\n\t\tconst entity = this.schema.entities[name]\n\n\t\tfor (const fieldName in entity.fields) {\n\t\t\tif (!entity.fields.hasOwnProperty(fieldName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst accessVisitor = new FieldAccessVisitor(Acl.Operation.read, this.authorizator)\n\t\t\tif (!acceptFieldVisitor(this.schema, name, fieldName, accessVisitor)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfields[fieldName] = acceptFieldVisitor(this.schema, name, fieldName, {\n\t\t\t\tvisitColumn: ({ column }) => ({ type: this.conditionTypeProvider.getCondition(column) }),\n\t\t\t\tvisitRelation: ({ relation }) => ({ type: this.getEntityWhereType(relation.target) }),\n\t\t\t} as Model.FieldVisitor<GraphQLInputFieldConfig>)\n\t\t}\n\n\t\tfields.and = { type: new GraphQLList(where) }\n\t\tfields.or = { type: new GraphQLList(where) }\n\t\tfields.not = { type: where }\n\n\t\treturn fields\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAWO,MAAM,kBAAkB;AAAA,EAI9B,YACkB,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E,SAAS,OAAO,EAAE,MAAM,KAAK,mBAAmB,SAAS,MAAM,EAAE;AAAA,MAAA,CACpC;AAAA,IAAA;AAGjD,WAAO,MAAM,EAAE,MAAM,IAAI,YAAY,KAAK,EAAE;AAC5C,WAAO,KAAK,EAAE,MAAM,IAAI,YAAY,KAAK,EAAE;AACpC,WAAA,MAAM,EAAE,MAAM,MAAM;AAEpB,WAAA;AAAA,EAAA;AAET;"}
1
+ {"version":3,"file":"WhereTypeProvider.js","sources":["../../../../../packages/engine-content-api/src/schema/WhereTypeProvider.ts"],"sourcesContent":["import { Acl, Model } from '@contember/schema'\nimport { acceptFieldVisitor, getEntity } from '@contember/schema-utils'\nimport { GraphQLInputFieldConfig, GraphQLInputFieldConfigMap, GraphQLInputObjectType, GraphQLList } from 'graphql'\nimport { capitalizeFirstLetter, getFieldsForUniqueWhere, singletonFactory } from '../utils'\nimport { ColumnTypeResolver } from './ColumnTypeResolver'\nimport { ConditionTypeProvider } from './ConditionTypeProvider'\nimport { GqlTypeName } from './utils'\nimport { Authorizator } from '../acl'\nimport { FieldAccessVisitor } from './FieldAccessVisitor'\nimport { ImplementationException } from '../exception'\n\nexport class WhereTypeProvider {\n\tprivate whereSingleton = singletonFactory(name => this.createEntityWhereType(name))\n\tprivate uniqueWhereSingleton = singletonFactory(name => this.createEntityUniqueWhereType(name))\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t\tprivate readonly columnTypeResolver: ColumnTypeResolver,\n\t\tprivate readonly conditionTypeProvider: ConditionTypeProvider,\n\t) {}\n\n\tpublic getEntityWhereType(entityName: string): GraphQLInputObjectType {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, entityName) === 'no') {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn this.whereSingleton(entityName)\n\t}\n\n\tpublic getEntityUniqueWhereType(entityName: string): undefined | GraphQLInputObjectType {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, entityName) === 'no') {\n\t\t\treturn undefined\n\t\t}\n\t\treturn this.uniqueWhereSingleton(entityName)\n\t}\n\n\tprivate createEntityWhereType(entityName: string) {\n\t\tconst where: GraphQLInputObjectType = new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entityName}Where`,\n\t\t\tfields: () => this.getEntityWhereFields(entityName, where),\n\t\t})\n\n\t\treturn where\n\t}\n\n\tprivate createEntityUniqueWhereType(entityName: string, withoutRelation?: string) {\n\t\tconst entity = getEntity(this.schema, entityName)\n\n\t\tconst combinations: string[] = []\n\n\t\tconst possibleUniqueWhereFields = getFieldsForUniqueWhere(this.schema, entity)\n\t\tconst uniqueKeys: (readonly string[])[] = possibleUniqueWhereFields.filter(uniqueKey =>\n\t\t\tuniqueKey.every(it =>\n\t\t\t\tacceptFieldVisitor(this.schema, entityName, it, new FieldAccessVisitor(Acl.Operation.read, this.authorizator)),\n\t\t\t),\n\t\t)\n\t\tfor (const uniqueKey of uniqueKeys) {\n\t\t\tcombinations.push(uniqueKey.join(', '))\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: capitalizeFirstLetter(entityName) + 'UniqueWhere',\n\t\t\t// description: `Valid combinations are: (${combinations.join('), (')})`, generates invalid schema file\n\t\t\tfields: () => this.getUniqueWhereFields(entity, uniqueKeys),\n\t\t})\n\t}\n\n\tpublic getUniqueWhereFields(entity: Model.Entity, uniqueKeys: (readonly string[])[]) {\n\t\tconst fields: GraphQLInputFieldConfigMap = {}\n\t\tfor (const uniqueKey of uniqueKeys) {\n\t\t\tfor (const field of uniqueKey) {\n\t\t\t\tif (fields[field] !== undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfields[field] = acceptFieldVisitor<GraphQLInputFieldConfig>(this.schema, entity, field, {\n\t\t\t\t\tvisitRelation: ({ targetEntity }) => {\n\t\t\t\t\t\t// if (!isIt<Model.JoiningColumnRelation>(relation, 'joiningColumn')) {\n\t\t\t\t\t\t// \tthrow new Error('Only column or owning relation can be a part of unique key')\n\t\t\t\t\t\t// }\n\t\t\t\t\t\tconst uniqueWhere = this.getEntityUniqueWhereType(targetEntity.name)\n\t\t\t\t\t\tif (!uniqueWhere) {\n\t\t\t\t\t\t\tthrow new ImplementationException()\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn { type: uniqueWhere }\n\t\t\t\t\t},\n\t\t\t\t\tvisitColumn: ({ column }) => ({ type: this.columnTypeResolver.getType(column)[0] }),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn fields\n\t}\n\n\tprivate getEntityWhereFields(name: string, where: GraphQLInputObjectType) {\n\t\tconst fields: GraphQLInputFieldConfigMap = {}\n\t\tconst entity = this.schema.entities[name]\n\n\t\tfor (const fieldName in entity.fields) {\n\t\t\tif (!entity.fields.hasOwnProperty(fieldName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst accessVisitor = new FieldAccessVisitor(Acl.Operation.read, this.authorizator)\n\t\t\tif (!acceptFieldVisitor(this.schema, name, fieldName, accessVisitor)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfields[fieldName] = acceptFieldVisitor(this.schema, name, fieldName, {\n\t\t\t\tvisitColumn: ({ column }) => ({ type: this.conditionTypeProvider.getCondition(column) }),\n\t\t\t\tvisitRelation: ({ relation }) => ({ type: this.getEntityWhereType(relation.target) }),\n\t\t\t} as Model.FieldVisitor<GraphQLInputFieldConfig>)\n\t\t}\n\n\t\tfields.and = { type: new GraphQLList(where) }\n\t\tfields.or = { type: new GraphQLList(where) }\n\t\tfields.not = { type: where }\n\n\t\treturn fields\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAWO,MAAM,kBAAkB;AAAA,EAI9B,YACkB,QACA,cACA,oBACA,uBAChB;AAJgB,SAAA,SAAA;AACA,SAAA,eAAA;AACA,SAAA,qBAAA;AACA,SAAA,wBAAA;AAPlB,kBAAA,MAAQ,kBAAiB,iBAAiB,CAAA,SAAQ,KAAK,sB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AAC5C,WAAO,KAAK,EAAE,MAAM,IAAI,YAAY,KAAK,EAAE;AACpC,WAAA,MAAM,EAAE,MAAM,MAAM;AAEpB,WAAA;AAAA,EAAA;AAET;"}
@@ -10,16 +10,16 @@ class FieldTypeVisitor {
10
10
  this.authorizator = authorizator;
11
11
  }
12
12
  visitColumn({ column, entity }) {
13
- const basicType = this.columnTypeResolver.getType(column);
13
+ const [type] = this.columnTypeResolver.getType(column);
14
14
  const fieldPredicate = this.authorizator.getFieldPredicate(schema.Acl.Operation.read, entity.name, column.name);
15
15
  const idPredicate = this.authorizator.getFieldPredicate(schema.Acl.Operation.read, entity.name, entity.primary);
16
16
  if (!fieldPredicate || !idPredicate) {
17
17
  throw new exception.ImplementationException();
18
18
  }
19
19
  if (!column.nullable && (fieldPredicate === true || fieldPredicate === idPredicate)) {
20
- return new graphql.GraphQLNonNull(basicType);
20
+ return new graphql.GraphQLNonNull(type);
21
21
  }
22
- return basicType;
22
+ return type;
23
23
  }
24
24
  visitHasMany({ relation }) {
25
25
  const entityType = this.entityTypeProvider.getEntity(relation.target);