@contember/client-content 2.1.0-alpha.36 → 2.1.0-alpha.39

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 (136) hide show
  1. package/dist/development/index.cjs +13 -0
  2. package/dist/development/index.cjs.map +1 -0
  3. package/dist/development/index.js +13 -0
  4. package/dist/development/index.js.map +1 -0
  5. package/dist/development/src/ContentClient.cjs +39 -0
  6. package/dist/development/src/ContentClient.cjs.map +1 -0
  7. package/dist/development/src/ContentClient.js +39 -0
  8. package/dist/development/src/ContentClient.js.map +1 -0
  9. package/dist/development/src/ContentQueryBuilder.cjs +185 -0
  10. package/dist/development/src/ContentQueryBuilder.cjs.map +1 -0
  11. package/dist/development/src/ContentQueryBuilder.js +185 -0
  12. package/dist/development/src/ContentQueryBuilder.js.map +1 -0
  13. package/dist/development/src/MutationFailedError.cjs +11 -0
  14. package/dist/development/src/MutationFailedError.cjs.map +1 -0
  15. package/dist/development/src/MutationFailedError.js +11 -0
  16. package/dist/development/src/MutationFailedError.js.map +1 -0
  17. package/dist/development/src/nodes/ContentEntitySelection.cjs +223 -0
  18. package/dist/development/src/nodes/ContentEntitySelection.cjs.map +1 -0
  19. package/dist/development/src/nodes/ContentEntitySelection.js +223 -0
  20. package/dist/development/src/nodes/ContentEntitySelection.js.map +1 -0
  21. package/dist/development/src/nodes/ContentOperation.cjs +16 -0
  22. package/dist/development/src/nodes/ContentOperation.cjs.map +1 -0
  23. package/dist/development/src/nodes/ContentOperation.js +16 -0
  24. package/dist/development/src/nodes/ContentOperation.js.map +1 -0
  25. package/dist/development/src/utils/ContentOperationSet.cjs +10 -0
  26. package/dist/development/src/utils/ContentOperationSet.cjs.map +1 -0
  27. package/dist/development/src/utils/ContentOperationSet.js +10 -0
  28. package/dist/development/src/utils/ContentOperationSet.js.map +1 -0
  29. package/dist/development/src/utils/createListArgs.cjs +24 -0
  30. package/dist/development/src/utils/createListArgs.cjs.map +1 -0
  31. package/dist/development/src/utils/createListArgs.js +24 -0
  32. package/dist/development/src/utils/createListArgs.js.map +1 -0
  33. package/dist/development/src/utils/createMutationOperationSet.cjs +39 -0
  34. package/dist/development/src/utils/createMutationOperationSet.cjs.map +1 -0
  35. package/dist/development/src/utils/createMutationOperationSet.js +39 -0
  36. package/dist/development/src/utils/createMutationOperationSet.js.map +1 -0
  37. package/dist/development/src/utils/createQueryOperationSet.cjs +19 -0
  38. package/dist/development/src/utils/createQueryOperationSet.cjs.map +1 -0
  39. package/dist/development/src/utils/createQueryOperationSet.js +19 -0
  40. package/dist/development/src/utils/createQueryOperationSet.js.map +1 -0
  41. package/dist/development/src/utils/createTypedArgs.cjs +17 -0
  42. package/dist/development/src/utils/createTypedArgs.cjs.map +1 -0
  43. package/dist/development/src/utils/createTypedArgs.js +17 -0
  44. package/dist/development/src/utils/createTypedArgs.js.map +1 -0
  45. package/dist/development/src/utils/mutationFragments.cjs +55 -0
  46. package/dist/development/src/utils/mutationFragments.cjs.map +1 -0
  47. package/dist/development/src/utils/mutationFragments.js +55 -0
  48. package/dist/development/src/utils/mutationFragments.js.map +1 -0
  49. package/dist/production/index.cjs +13 -0
  50. package/dist/production/index.cjs.map +1 -0
  51. package/dist/production/index.js +13 -0
  52. package/dist/production/index.js.map +1 -0
  53. package/dist/production/src/ContentClient.cjs +39 -0
  54. package/dist/production/src/ContentClient.cjs.map +1 -0
  55. package/dist/production/src/ContentClient.js +39 -0
  56. package/dist/production/src/ContentClient.js.map +1 -0
  57. package/dist/production/src/ContentQueryBuilder.cjs +185 -0
  58. package/dist/production/src/ContentQueryBuilder.cjs.map +1 -0
  59. package/dist/production/src/ContentQueryBuilder.js +185 -0
  60. package/dist/production/src/ContentQueryBuilder.js.map +1 -0
  61. package/dist/production/src/MutationFailedError.cjs +11 -0
  62. package/dist/production/src/MutationFailedError.cjs.map +1 -0
  63. package/dist/production/src/MutationFailedError.js +11 -0
  64. package/dist/production/src/MutationFailedError.js.map +1 -0
  65. package/dist/production/src/nodes/ContentEntitySelection.cjs +223 -0
  66. package/dist/production/src/nodes/ContentEntitySelection.cjs.map +1 -0
  67. package/dist/production/src/nodes/ContentEntitySelection.js +223 -0
  68. package/dist/production/src/nodes/ContentEntitySelection.js.map +1 -0
  69. package/dist/production/src/nodes/ContentOperation.cjs +16 -0
  70. package/dist/production/src/nodes/ContentOperation.cjs.map +1 -0
  71. package/dist/production/src/nodes/ContentOperation.js +16 -0
  72. package/dist/production/src/nodes/ContentOperation.js.map +1 -0
  73. package/dist/production/src/utils/ContentOperationSet.cjs +10 -0
  74. package/dist/production/src/utils/ContentOperationSet.cjs.map +1 -0
  75. package/dist/production/src/utils/ContentOperationSet.js +10 -0
  76. package/dist/production/src/utils/ContentOperationSet.js.map +1 -0
  77. package/dist/production/src/utils/createListArgs.cjs +24 -0
  78. package/dist/production/src/utils/createListArgs.cjs.map +1 -0
  79. package/dist/production/src/utils/createListArgs.js +24 -0
  80. package/dist/production/src/utils/createListArgs.js.map +1 -0
  81. package/dist/production/src/utils/createMutationOperationSet.cjs +39 -0
  82. package/dist/production/src/utils/createMutationOperationSet.cjs.map +1 -0
  83. package/dist/production/src/utils/createMutationOperationSet.js +39 -0
  84. package/dist/production/src/utils/createMutationOperationSet.js.map +1 -0
  85. package/dist/production/src/utils/createQueryOperationSet.cjs +19 -0
  86. package/dist/production/src/utils/createQueryOperationSet.cjs.map +1 -0
  87. package/dist/production/src/utils/createQueryOperationSet.js +19 -0
  88. package/dist/production/src/utils/createQueryOperationSet.js.map +1 -0
  89. package/dist/production/src/utils/createTypedArgs.cjs +17 -0
  90. package/dist/production/src/utils/createTypedArgs.cjs.map +1 -0
  91. package/dist/production/src/utils/createTypedArgs.js +17 -0
  92. package/dist/production/src/utils/createTypedArgs.js.map +1 -0
  93. package/dist/production/src/utils/mutationFragments.cjs +55 -0
  94. package/dist/production/src/utils/mutationFragments.cjs.map +1 -0
  95. package/dist/production/src/utils/mutationFragments.js +55 -0
  96. package/dist/production/src/utils/mutationFragments.js.map +1 -0
  97. package/dist/types/ContentClient.d.ts +27 -0
  98. package/dist/types/ContentClient.d.ts.map +1 -0
  99. package/dist/types/ContentQueryBuilder.d.ts +27 -0
  100. package/dist/types/ContentQueryBuilder.d.ts.map +1 -0
  101. package/dist/types/MutationFailedError.d.ts +13 -0
  102. package/dist/types/MutationFailedError.d.ts.map +1 -0
  103. package/dist/types/TypedContentQueryBuilder.d.ts +21 -0
  104. package/dist/types/TypedContentQueryBuilder.d.ts.map +1 -0
  105. package/dist/types/index.d.ts +7 -0
  106. package/dist/types/index.d.ts.map +1 -0
  107. package/dist/types/nodes/ContentEntitySelection.d.ts +62 -0
  108. package/dist/types/nodes/ContentEntitySelection.d.ts.map +1 -0
  109. package/dist/types/nodes/ContentOperation.d.ts +30 -0
  110. package/dist/types/nodes/ContentOperation.d.ts.map +1 -0
  111. package/dist/types/nodes/TypedEntitySelection.d.ts +54 -0
  112. package/dist/types/nodes/TypedEntitySelection.d.ts.map +1 -0
  113. package/dist/types/nodes/index.d.ts +4 -0
  114. package/dist/types/nodes/index.d.ts.map +1 -0
  115. package/dist/types/tsconfig.tsbuildinfo +1 -0
  116. package/dist/types/types/Input.d.ts +201 -0
  117. package/dist/types/types/Input.d.ts.map +1 -0
  118. package/dist/types/types/Result.d.ts +60 -0
  119. package/dist/types/types/Result.d.ts.map +1 -0
  120. package/dist/types/types/Schema.d.ts +46 -0
  121. package/dist/types/types/Schema.d.ts.map +1 -0
  122. package/dist/types/types/index.d.ts +4 -0
  123. package/dist/types/types/index.d.ts.map +1 -0
  124. package/dist/types/utils/ContentOperationSet.d.ts +13 -0
  125. package/dist/types/utils/ContentOperationSet.d.ts.map +1 -0
  126. package/dist/types/utils/createListArgs.d.ts +9 -0
  127. package/dist/types/utils/createListArgs.d.ts.map +1 -0
  128. package/dist/types/utils/createMutationOperationSet.d.ts +4 -0
  129. package/dist/types/utils/createMutationOperationSet.d.ts.map +1 -0
  130. package/dist/types/utils/createQueryOperationSet.d.ts +4 -0
  131. package/dist/types/utils/createQueryOperationSet.d.ts.map +1 -0
  132. package/dist/types/utils/createTypedArgs.d.ts +3 -0
  133. package/dist/types/utils/createTypedArgs.d.ts.map +1 -0
  134. package/dist/types/utils/mutationFragments.d.ts +3 -0
  135. package/dist/types/utils/mutationFragments.d.ts.map +1 -0
  136. package/package.json +5 -5
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const createListArgs = require("../utils/createListArgs.cjs");
4
+ const graphqlBuilder = require("@contember/graphql-builder");
5
+ class ContentEntitySelection {
6
+ /**
7
+ * @internal
8
+ */
9
+ constructor(context, selectionSet, transformFn) {
10
+ this.context = context;
11
+ this.selectionSet = selectionSet;
12
+ this.transformFn = transformFn;
13
+ }
14
+ $(field, argsOrSelection, selectionIn) {
15
+ const [args, selection] = typeof argsOrSelection === "function" || argsOrSelection instanceof ContentEntitySelection ? [{}, argsOrSelection] : [argsOrSelection ?? {}, selectionIn];
16
+ if (field === "__typename") {
17
+ return this.withField(new graphqlBuilder.GraphQlField(args.as ?? null, "__typename"));
18
+ }
19
+ const fieldInfo = this.context.entity.fields[field];
20
+ if (!fieldInfo) {
21
+ if ("by" in args && field.includes("By")) {
22
+ if (!selection) {
23
+ throw new Error(`Selection is required for ${this.context.entity.name}.${field}.`);
24
+ }
25
+ return this._manyBy(field, args, selection);
26
+ }
27
+ throw new Error(`Field ${this.context.entity.name}.${field} does not exist.`);
28
+ }
29
+ if (fieldInfo.type === "column") {
30
+ return this._column(field, args);
31
+ }
32
+ if (fieldInfo.type === "many") {
33
+ if (!selection) {
34
+ throw new Error(`Selection is required for ${this.context.entity.name}.${field}.`);
35
+ }
36
+ return this._many(field, args, selection);
37
+ }
38
+ if (fieldInfo.type === "one") {
39
+ if (!selection) {
40
+ throw new Error(`Selection is required for ${this.context.entity.name}.${field}.`);
41
+ }
42
+ return this._one(field, args, selection);
43
+ }
44
+ throw new Error(`Unknown field type ${fieldInfo.type}.`);
45
+ }
46
+ $$() {
47
+ const columns = this.context.entity.scalars;
48
+ const nodes = [
49
+ ...this.selectionSet,
50
+ ...columns.map((col) => new graphqlBuilder.GraphQlField(null, col))
51
+ ];
52
+ return new ContentEntitySelection(this.context, nodes);
53
+ }
54
+ omit(...fields) {
55
+ return new ContentEntitySelection(
56
+ this.context,
57
+ this.selectionSet.filter((it) => {
58
+ if (!(it instanceof graphqlBuilder.GraphQlField)) {
59
+ return true;
60
+ }
61
+ const alias = it.alias ?? it.name;
62
+ return !fields.includes(alias);
63
+ })
64
+ );
65
+ }
66
+ meta(field, flags) {
67
+ const metaField = this.selectionSet.find((it) => it instanceof graphqlBuilder.GraphQlField && it.name === "_meta");
68
+ const selectionWithoutMeta = metaField ? this.selectionSet.filter((it) => it !== metaField) : this.selectionSet;
69
+ const flagFields = [];
70
+ for (const flag of flags) {
71
+ flagFields.push(new graphqlBuilder.GraphQlField(null, flag));
72
+ }
73
+ return new ContentEntitySelection(this.context, [
74
+ ...selectionWithoutMeta,
75
+ new graphqlBuilder.GraphQlField(null, "_meta", void 0, [
76
+ ...metaField?.selectionSet ?? [],
77
+ new graphqlBuilder.GraphQlField(null, field, void 0, flagFields)
78
+ ])
79
+ ]);
80
+ }
81
+ transform(transform) {
82
+ return new ContentEntitySelection(
83
+ this.context,
84
+ this.selectionSet,
85
+ !this.transformFn ? transform : (value, ctx) => {
86
+ return transform(this.transformFn(value, ctx), ctx);
87
+ }
88
+ );
89
+ }
90
+ _column(name, args = {}) {
91
+ let fieldInfo = this.context.entity.fields[name];
92
+ if (!fieldInfo) {
93
+ throw new Error(`Field ${this.context.entity.name}.${name} does not exist.`);
94
+ }
95
+ if (fieldInfo?.type !== "column") {
96
+ throw new Error(`Field ${this.context.entity.name}.${name} is not a column.`);
97
+ }
98
+ const alias = args.as ?? name;
99
+ const field = new graphqlBuilder.GraphQlField(alias, name, {});
100
+ return this.withField(field);
101
+ }
102
+ _many(name, args, fields) {
103
+ const alias = args.as ?? name;
104
+ const fieldInfo = this.context.entity.fields[name];
105
+ if (!fieldInfo) {
106
+ throw new Error(`Field ${this.context.entity.name}.${name} does not exist.`);
107
+ }
108
+ if (fieldInfo?.type !== "many") {
109
+ throw new Error(`Field ${this.context.entity.name}.${name} is not a has-many relation.`);
110
+ }
111
+ const entity = this.context.schema.entities[fieldInfo.entity];
112
+ const newContext = {
113
+ entity,
114
+ schema: this.context.schema
115
+ };
116
+ const entitySelection = typeof fields === "function" ? fields(new ContentEntitySelection(newContext, [])) : fields;
117
+ const newObjectField = new graphqlBuilder.GraphQlField(
118
+ alias,
119
+ name,
120
+ createListArgs.createListArgs(entity, args),
121
+ entitySelection.selectionSet
122
+ );
123
+ const selectionWithField = this.withField(newObjectField);
124
+ const nestedTransform = entitySelection.transformFn;
125
+ if (!nestedTransform) {
126
+ return selectionWithField;
127
+ }
128
+ return selectionWithField.withFieldTransform(alias, (it) => it.map(nestedTransform));
129
+ }
130
+ _manyBy(name, args, fields) {
131
+ const alias = args.as ?? name;
132
+ const byField = Object.keys(args.by)[0];
133
+ const relationField = name.substring(0, name.length - byField.length - 2);
134
+ const field = this.context.entity.fields[relationField];
135
+ if (!field) {
136
+ throw new Error(`Field ${this.context.entity.name}.${relationField} does not exist.`);
137
+ }
138
+ if (field?.type !== "many") {
139
+ throw new Error(`Field ${this.context.entity.name}.${relationField} is not a has-many relation.`);
140
+ }
141
+ const entity = this.context.schema.entities[field.entity];
142
+ const newContext = {
143
+ entity,
144
+ schema: this.context.schema
145
+ };
146
+ const fieldUpperFirst = name.charAt(0).toUpperCase() + name.slice(1);
147
+ const argsWithType = {
148
+ filter: {
149
+ graphQlType: `${entity.name}Where`,
150
+ value: args.filter
151
+ },
152
+ by: {
153
+ graphQlType: `${this.context.entity.name}${fieldUpperFirst}UniqueWhere!`,
154
+ value: args.by
155
+ }
156
+ };
157
+ const entitySelection = typeof fields === "function" ? fields(new ContentEntitySelection(newContext, [])) : fields;
158
+ const newObjectField = new graphqlBuilder.GraphQlField(
159
+ alias,
160
+ name,
161
+ argsWithType,
162
+ entitySelection.selectionSet
163
+ );
164
+ const selectionWithField = this.withField(newObjectField);
165
+ const nestedTransform = entitySelection.transformFn;
166
+ if (!nestedTransform) {
167
+ return selectionWithField;
168
+ }
169
+ return selectionWithField.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null);
170
+ }
171
+ _one(name, args, fields) {
172
+ const alias = args.as ?? name;
173
+ const fieldInfo = this.context.entity.fields[name];
174
+ if (!fieldInfo) {
175
+ throw new Error(`Field ${this.context.entity.name}.${name} does not exist.`);
176
+ }
177
+ if (fieldInfo?.type !== "one") {
178
+ throw new Error(`Field ${this.context.entity.name}.${name} is not a has-one relation.`);
179
+ }
180
+ const entity = this.context.schema.entities[fieldInfo.entity];
181
+ const newContext = {
182
+ entity,
183
+ schema: this.context.schema
184
+ };
185
+ const argsWithType = {
186
+ filter: {
187
+ graphQlType: `${entity.name}Where`,
188
+ value: args.filter
189
+ }
190
+ };
191
+ const entitySelection = typeof fields === "function" ? fields(new ContentEntitySelection(newContext, [])) : fields;
192
+ const newObjectField = new graphqlBuilder.GraphQlField(
193
+ alias,
194
+ name,
195
+ argsWithType,
196
+ entitySelection.selectionSet
197
+ );
198
+ const selectionWithField = this.withField(newObjectField);
199
+ const nestedTransform = entitySelection.transformFn;
200
+ if (!nestedTransform) {
201
+ return selectionWithField;
202
+ }
203
+ return selectionWithField.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null);
204
+ }
205
+ withField(field) {
206
+ return new ContentEntitySelection(this.context, [
207
+ ...this.selectionSet,
208
+ field
209
+ ], this.transformFn);
210
+ }
211
+ withFieldTransform(alias, transform) {
212
+ return new ContentEntitySelection(this.context, this.selectionSet, (value, ctx) => {
213
+ const transformedValue = transform(value[alias], ctx);
214
+ const newValue = {
215
+ ...value,
216
+ [alias]: transformedValue
217
+ };
218
+ return this.transformFn ? this.transformFn(newValue, ctx) : newValue;
219
+ });
220
+ }
221
+ }
222
+ exports.ContentEntitySelection = ContentEntitySelection;
223
+ //# sourceMappingURL=ContentEntitySelection.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentEntitySelection.cjs","sources":["../../../../../packages/client-content/src/nodes/ContentEntitySelection.ts"],"sourcesContent":["import { createListArgs } from '../utils/createListArgs'\nimport { ContentClientInput, SchemaEntityNames, SchemaNames } from '../types'\nimport { Input } from '@contember/schema'\nimport { GraphQlField, GraphQlFieldTypedArgs, GraphQlSelectionSet } from '@contember/graphql-builder'\n\n/**\n * @internal\n */\nexport type ContentEntitySelectionContext<Name extends string> = {\n\tentity: SchemaEntityNames<Name>\n\tschema: SchemaNames\n}\n\nexport type ContentEntitySelectionCallback = (select: ContentEntitySelection) => ContentEntitySelection\n\nexport type EntitySelectionCommonInput<Alias extends string | null = string | null> = { as?: Alias }\nexport type EntitySelectionManyArgs<Alias extends string | null = string | null> =\n\t& ContentClientInput.AnyListQueryInput\n\t& EntitySelectionCommonInput<Alias>\nexport type EntitySelectionManyByArgs<Alias extends string | null = string | null> =\n\t& { by: Input.UniqueWhere; filter?: Input.Where }\n\t& EntitySelectionCommonInput<Alias>\nexport type EntitySelectionOneArgs<Alias extends string | null = string | null> = { filter?: Input.Where } & EntitySelectionCommonInput<Alias>\nexport type EntitySelectionColumnArgs<Alias extends string | null = string | null> = EntitySelectionCommonInput<Alias>\n\nexport type EntitySelectionAnyArgs =\n\t| EntitySelectionColumnArgs\n\t| EntitySelectionManyArgs\n\t| EntitySelectionManyByArgs\n\t| EntitySelectionOneArgs\n\nexport type ContentEntitySelectionOrCallback = ContentEntitySelectionCallback | ContentEntitySelection\n\nexport type ContentTransformContext = {\n\trootValue: unknown\n}\n\nexport class ContentEntitySelection {\n\t/**\n\t * @internal\n\t */\n\tconstructor(\n\t\t/** @internal */\n\t\tpublic readonly context: ContentEntitySelectionContext<string>,\n\t\t/** @internal */\n\t\tpublic readonly selectionSet: GraphQlSelectionSet,\n\t\t/** @internal */\n\t\tpublic readonly transformFn?: (value: any, ctx: ContentTransformContext) => any,\n\t) {\n\t}\n\n\t$(field: string, args?: EntitySelectionColumnArgs): ContentEntitySelection\n\t$(field: string, args: EntitySelectionManyArgs, selection: ContentEntitySelectionOrCallback): ContentEntitySelection\n\t$(field: string, args: EntitySelectionManyByArgs, selection: ContentEntitySelectionOrCallback): ContentEntitySelection\n\t$(field: string, args: EntitySelectionOneArgs, selection: ContentEntitySelectionOrCallback): ContentEntitySelection\n\t$(field: string, selection: ContentEntitySelectionOrCallback): ContentEntitySelection\n\n\t$(\n\t\tfield: string,\n\t\targsOrSelection?: EntitySelectionAnyArgs | ContentEntitySelectionOrCallback,\n\t\tselectionIn?: ContentEntitySelectionOrCallback,\n\t): ContentEntitySelection {\n\t\tconst [args, selection] = typeof argsOrSelection === 'function' || argsOrSelection instanceof ContentEntitySelection\n\t\t\t? [{}, argsOrSelection]\n\t\t\t: [argsOrSelection ?? {}, selectionIn]\n\t\tif (field === '__typename') {\n\t\t\treturn this.withField(new GraphQlField(args.as ?? null, '__typename'))\n\t\t}\n\t\tconst fieldInfo = this.context.entity.fields[field]\n\t\tif (!fieldInfo) {\n\t\t\tif ('by' in args && field.includes('By')) {\n\t\t\t\tif (!selection) {\n\t\t\t\t\tthrow new Error(`Selection is required for ${this.context.entity.name}.${field}.`)\n\t\t\t\t}\n\t\t\t\treturn this._manyBy(field, args as EntitySelectionManyByArgs, selection)\n\t\t\t}\n\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${field} does not exist.`)\n\t\t}\n\t\tif (fieldInfo.type === 'column') {\n\t\t\treturn this._column(field, args as EntitySelectionColumnArgs)\n\t\t}\n\t\tif (fieldInfo.type === 'many') {\n\t\t\tif (!selection) {\n\t\t\t\tthrow new Error(`Selection is required for ${this.context.entity.name}.${field}.`)\n\t\t\t}\n\t\t\treturn this._many(field, args as EntitySelectionManyArgs, selection)\n\t\t}\n\t\tif (fieldInfo.type === 'one') {\n\t\t\tif (!selection) {\n\t\t\t\tthrow new Error(`Selection is required for ${this.context.entity.name}.${field}.`)\n\t\t\t}\n\t\t\treturn this._one(field, args as EntitySelectionOneArgs, selection)\n\t\t}\n\t\tthrow new Error(`Unknown field type ${fieldInfo.type}.`)\n\t}\n\n\t$$(): ContentEntitySelection {\n\t\tconst columns = this.context.entity.scalars\n\t\tconst nodes = [\n\t\t\t...this.selectionSet,\n\t\t\t...columns.map(col => new GraphQlField(null, col)),\n\t\t]\n\t\treturn new ContentEntitySelection(this.context, nodes)\n\t}\n\n\tomit(...fields: string[]): ContentEntitySelection {\n\t\treturn new ContentEntitySelection(\n\t\t\tthis.context,\n\t\t\tthis.selectionSet.filter(it => {\n\t\t\t\tif (!(it instanceof GraphQlField)) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tconst alias = it.alias ?? it.name\n\t\t\t\treturn !fields.includes(alias)\n\t\t\t}),\n\t\t)\n\t}\n\n\tmeta(field: string, flags: ('readable' | 'updatable')[]): ContentEntitySelection {\n\t\tconst metaField = this.selectionSet.find((it): it is GraphQlField => it instanceof GraphQlField && it.name === '_meta')\n\t\tconst selectionWithoutMeta = metaField ? this.selectionSet.filter(it => it !== metaField) : this.selectionSet\n\n\t\tconst flagFields: GraphQlField[] = []\n\t\tfor (const flag of flags) {\n\t\t\tflagFields.push(new GraphQlField(null, flag))\n\t\t}\n\n\t\treturn new ContentEntitySelection(this.context, [\n\t\t\t...selectionWithoutMeta,\n\t\t\tnew GraphQlField(null, '_meta', undefined, [\n\t\t\t\t...metaField?.selectionSet ?? [],\n\t\t\t\tnew GraphQlField(null, field, undefined, flagFields),\n\t\t\t]),\n\t\t])\n\t}\n\n\ttransform(transform: (value: any, context: ContentTransformContext) => any): ContentEntitySelection {\n\t\treturn new ContentEntitySelection(\n\t\t\tthis.context,\n\t\t\tthis.selectionSet,\n\t\t\t!this.transformFn ? transform : (value, ctx) => {\n\t\t\t\treturn transform(this.transformFn!(value, ctx), ctx)\n\t\t\t},\n\t\t)\n\t}\n\n\tprivate _column(\n\t\tname: string,\n\t\targs: EntitySelectionCommonInput = {},\n\t): ContentEntitySelection {\n\t\tlet fieldInfo = this.context.entity.fields[name]\n\t\tif (!fieldInfo) {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${name} does not exist.`)\n\t\t}\n\t\tif (fieldInfo?.type !== 'column') {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${name} is not a column.`)\n\t\t}\n\n\t\tconst alias = args.as ?? name\n\n\t\tconst field = new GraphQlField(alias, name, {})\n\t\treturn this.withField(field)\n\t}\n\n\tprivate _many(\n\t\tname: string,\n\t\targs: EntitySelectionManyArgs,\n\t\tfields:\n\t\t\t| ContentEntitySelectionCallback\n\t\t\t| ContentEntitySelection,\n\t): ContentEntitySelection {\n\t\tconst alias = args.as ?? name\n\t\tconst fieldInfo = this.context.entity.fields[name]\n\t\tif (!fieldInfo) {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${name} does not exist.`)\n\t\t}\n\t\tif (fieldInfo?.type !== 'many') {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${name} is not a has-many relation.`)\n\t\t}\n\t\tconst entity = this.context.schema.entities[fieldInfo.entity]\n\n\t\tconst newContext = {\n\t\t\tentity: entity,\n\t\t\tschema: this.context.schema,\n\t\t}\n\n\t\tconst entitySelection = typeof fields === 'function' ? fields(new ContentEntitySelection(newContext, [])) : fields\n\t\tconst newObjectField = new GraphQlField(\n\t\t\talias,\n\t\t\tname,\n\t\t\tcreateListArgs(entity, args),\n\t\t\tentitySelection.selectionSet,\n\t\t)\n\t\tconst selectionWithField = this.withField(newObjectField)\n\t\tconst nestedTransform = entitySelection.transformFn\n\t\tif (!nestedTransform) {\n\t\t\treturn selectionWithField\n\t\t}\n\t\treturn selectionWithField.withFieldTransform(alias, it => it.map(nestedTransform))\n\t}\n\n\tprivate _manyBy(\n\t\tname: string,\n\t\targs: EntitySelectionManyByArgs,\n\t\tfields:\n\t\t\t| ContentEntitySelectionCallback\n\t\t\t| ContentEntitySelection,\n\t): ContentEntitySelection {\n\t\tconst alias = args.as ?? name\n\t\tconst byField = Object.keys(args.by)[0]\n\t\tconst relationField = name.substring(0, name.length - byField.length - 2)\n\n\t\tconst field = this.context.entity.fields[relationField]\n\t\tif (!field) {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${relationField} does not exist.`)\n\t\t}\n\t\tif (field?.type !== 'many') {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${relationField} is not a has-many relation.`)\n\t\t}\n\t\tconst entity = this.context.schema.entities[field.entity]\n\t\tconst newContext = {\n\t\t\tentity: entity,\n\t\t\tschema: this.context.schema,\n\t\t}\n\t\tconst fieldUpperFirst = name.charAt(0).toUpperCase() + name.slice(1)\n\n\t\tconst argsWithType: GraphQlFieldTypedArgs = {\n\t\t\tfilter: {\n\t\t\t\tgraphQlType: `${entity.name}Where`,\n\t\t\t\tvalue: args.filter,\n\t\t\t},\n\t\t\tby: {\n\t\t\t\tgraphQlType: `${this.context.entity.name}${fieldUpperFirst}UniqueWhere!`,\n\t\t\t\tvalue: args.by,\n\t\t\t},\n\t\t}\n\n\t\tconst entitySelection = typeof fields === 'function' ? fields(new ContentEntitySelection(newContext, []) as any) : fields\n\t\tconst newObjectField = new GraphQlField(\n\t\t\talias,\n\t\t\tname,\n\t\t\targsWithType,\n\t\t\tentitySelection.selectionSet,\n\t\t)\n\t\tconst selectionWithField = this.withField(newObjectField)\n\t\tconst nestedTransform = entitySelection.transformFn\n\t\tif (!nestedTransform) {\n\t\t\treturn selectionWithField\n\t\t}\n\t\treturn selectionWithField.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null)\n\t}\n\n\tprivate _one(\n\t\tname: string,\n\t\targs: EntitySelectionOneArgs,\n\t\tfields:\n\t\t\t| ContentEntitySelectionCallback\n\t\t\t| ContentEntitySelection,\n\t): ContentEntitySelection {\n\t\tconst alias = args.as ?? name\n\t\tconst fieldInfo = this.context.entity.fields[name]\n\t\tif (!fieldInfo) {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${name} does not exist.`)\n\t\t}\n\t\tif (fieldInfo?.type !== 'one') {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${name} is not a has-one relation.`)\n\t\t}\n\t\tconst entity = this.context.schema.entities[fieldInfo.entity]\n\n\t\tconst newContext: ContentEntitySelectionContext<(typeof entity)['name']> = {\n\t\t\tentity: entity,\n\t\t\tschema: this.context.schema,\n\t\t}\n\t\tconst argsWithType: GraphQlFieldTypedArgs = {\n\t\t\tfilter: {\n\t\t\t\tgraphQlType: `${entity.name}Where`,\n\t\t\t\tvalue: args.filter,\n\t\t\t},\n\t\t}\n\t\tconst entitySelection = typeof fields === 'function'\n\t\t\t? fields(new ContentEntitySelection(newContext, []) as any)\n\t\t\t: fields\n\t\tconst newObjectField = new GraphQlField(\n\t\t\talias,\n\t\t\tname,\n\t\t\targsWithType,\n\t\t\tentitySelection.selectionSet,\n\t\t)\n\t\tconst selectionWithField = this.withField(newObjectField)\n\t\tconst nestedTransform = entitySelection.transformFn\n\t\tif (!nestedTransform) {\n\t\t\treturn selectionWithField\n\t\t}\n\t\treturn selectionWithField.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null)\n\t}\n\n\tprivate withField(field: GraphQlField) {\n\t\treturn new ContentEntitySelection(this.context, [\n\t\t\t...this.selectionSet,\n\t\t\tfield,\n\t\t], this.transformFn)\n\t}\n\n\tprivate withFieldTransform(alias: string, transform: (value: any, ctx: ContentTransformContext) => any) {\n\t\treturn new ContentEntitySelection(this.context, this.selectionSet, (value, ctx) => {\n\t\t\tconst transformedValue = transform(value[alias], ctx)\n\t\t\tconst newValue = {\n\t\t\t\t...value,\n\t\t\t\t[alias]: transformedValue,\n\t\t\t}\n\t\t\treturn this.transformFn ? this.transformFn(newValue, ctx) : newValue\n\t\t})\n\t}\n}\n"],"names":["GraphQlField","createListArgs"],"mappings":";;;;AAqCO,MAAM,uBAAuB;AAAA;AAAA;AAAA;AAAA,EAInC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AAA,IACR;AACA,WAAO,mBAAmB,mBAAmB,OAAO,CAAC,IAAI,QAAQ,OAAO,OAAO,gBAAgB,IAAI,GAAG,IAAI,IAAI;AAAA,EAC/G;AAAA,EAEQ,UAAU,OAAqB;AACtC,WAAO,IAAI,uBAAuB,KAAK,SAAS;AAAA,MAC/C,GAAG,KAAK;AAAA,MACR;AAAA,IAAA,GACE,KAAK,WAAW;AAAA,EACpB;AAAA,EAEQ,mBAAmB,OAAe,WAA8D;AACvG,WAAO,IAAI,uBAAuB,KAAK,SAAS,KAAK,cAAc,CAAC,OAAO,QAAQ;AAClF,YAAM,mBAAmB,UAAU,MAAM,KAAK,GAAG,GAAG;AACpD,YAAM,WAAW;AAAA,QAChB,GAAG;AAAA,QACH,CAAC,KAAK,GAAG;AAAA,MAAA;AAEV,aAAO,KAAK,cAAc,KAAK,YAAY,UAAU,GAAG,IAAI;AAAA,IAC7D,CAAC;AAAA,EACF;AACD;;"}
@@ -0,0 +1,223 @@
1
+ import { createListArgs } from "../utils/createListArgs.js";
2
+ import { GraphQlField } from "@contember/graphql-builder";
3
+ class ContentEntitySelection {
4
+ /**
5
+ * @internal
6
+ */
7
+ constructor(context, selectionSet, transformFn) {
8
+ this.context = context;
9
+ this.selectionSet = selectionSet;
10
+ this.transformFn = transformFn;
11
+ }
12
+ $(field, argsOrSelection, selectionIn) {
13
+ const [args, selection] = typeof argsOrSelection === "function" || argsOrSelection instanceof ContentEntitySelection ? [{}, argsOrSelection] : [argsOrSelection ?? {}, selectionIn];
14
+ if (field === "__typename") {
15
+ return this.withField(new GraphQlField(args.as ?? null, "__typename"));
16
+ }
17
+ const fieldInfo = this.context.entity.fields[field];
18
+ if (!fieldInfo) {
19
+ if ("by" in args && field.includes("By")) {
20
+ if (!selection) {
21
+ throw new Error(`Selection is required for ${this.context.entity.name}.${field}.`);
22
+ }
23
+ return this._manyBy(field, args, selection);
24
+ }
25
+ throw new Error(`Field ${this.context.entity.name}.${field} does not exist.`);
26
+ }
27
+ if (fieldInfo.type === "column") {
28
+ return this._column(field, args);
29
+ }
30
+ if (fieldInfo.type === "many") {
31
+ if (!selection) {
32
+ throw new Error(`Selection is required for ${this.context.entity.name}.${field}.`);
33
+ }
34
+ return this._many(field, args, selection);
35
+ }
36
+ if (fieldInfo.type === "one") {
37
+ if (!selection) {
38
+ throw new Error(`Selection is required for ${this.context.entity.name}.${field}.`);
39
+ }
40
+ return this._one(field, args, selection);
41
+ }
42
+ throw new Error(`Unknown field type ${fieldInfo.type}.`);
43
+ }
44
+ $$() {
45
+ const columns = this.context.entity.scalars;
46
+ const nodes = [
47
+ ...this.selectionSet,
48
+ ...columns.map((col) => new GraphQlField(null, col))
49
+ ];
50
+ return new ContentEntitySelection(this.context, nodes);
51
+ }
52
+ omit(...fields) {
53
+ return new ContentEntitySelection(
54
+ this.context,
55
+ this.selectionSet.filter((it) => {
56
+ if (!(it instanceof GraphQlField)) {
57
+ return true;
58
+ }
59
+ const alias = it.alias ?? it.name;
60
+ return !fields.includes(alias);
61
+ })
62
+ );
63
+ }
64
+ meta(field, flags) {
65
+ const metaField = this.selectionSet.find((it) => it instanceof GraphQlField && it.name === "_meta");
66
+ const selectionWithoutMeta = metaField ? this.selectionSet.filter((it) => it !== metaField) : this.selectionSet;
67
+ const flagFields = [];
68
+ for (const flag of flags) {
69
+ flagFields.push(new GraphQlField(null, flag));
70
+ }
71
+ return new ContentEntitySelection(this.context, [
72
+ ...selectionWithoutMeta,
73
+ new GraphQlField(null, "_meta", void 0, [
74
+ ...metaField?.selectionSet ?? [],
75
+ new GraphQlField(null, field, void 0, flagFields)
76
+ ])
77
+ ]);
78
+ }
79
+ transform(transform) {
80
+ return new ContentEntitySelection(
81
+ this.context,
82
+ this.selectionSet,
83
+ !this.transformFn ? transform : (value, ctx) => {
84
+ return transform(this.transformFn(value, ctx), ctx);
85
+ }
86
+ );
87
+ }
88
+ _column(name, args = {}) {
89
+ let fieldInfo = this.context.entity.fields[name];
90
+ if (!fieldInfo) {
91
+ throw new Error(`Field ${this.context.entity.name}.${name} does not exist.`);
92
+ }
93
+ if (fieldInfo?.type !== "column") {
94
+ throw new Error(`Field ${this.context.entity.name}.${name} is not a column.`);
95
+ }
96
+ const alias = args.as ?? name;
97
+ const field = new GraphQlField(alias, name, {});
98
+ return this.withField(field);
99
+ }
100
+ _many(name, args, fields) {
101
+ const alias = args.as ?? name;
102
+ const fieldInfo = this.context.entity.fields[name];
103
+ if (!fieldInfo) {
104
+ throw new Error(`Field ${this.context.entity.name}.${name} does not exist.`);
105
+ }
106
+ if (fieldInfo?.type !== "many") {
107
+ throw new Error(`Field ${this.context.entity.name}.${name} is not a has-many relation.`);
108
+ }
109
+ const entity = this.context.schema.entities[fieldInfo.entity];
110
+ const newContext = {
111
+ entity,
112
+ schema: this.context.schema
113
+ };
114
+ const entitySelection = typeof fields === "function" ? fields(new ContentEntitySelection(newContext, [])) : fields;
115
+ const newObjectField = new GraphQlField(
116
+ alias,
117
+ name,
118
+ createListArgs(entity, args),
119
+ entitySelection.selectionSet
120
+ );
121
+ const selectionWithField = this.withField(newObjectField);
122
+ const nestedTransform = entitySelection.transformFn;
123
+ if (!nestedTransform) {
124
+ return selectionWithField;
125
+ }
126
+ return selectionWithField.withFieldTransform(alias, (it) => it.map(nestedTransform));
127
+ }
128
+ _manyBy(name, args, fields) {
129
+ const alias = args.as ?? name;
130
+ const byField = Object.keys(args.by)[0];
131
+ const relationField = name.substring(0, name.length - byField.length - 2);
132
+ const field = this.context.entity.fields[relationField];
133
+ if (!field) {
134
+ throw new Error(`Field ${this.context.entity.name}.${relationField} does not exist.`);
135
+ }
136
+ if (field?.type !== "many") {
137
+ throw new Error(`Field ${this.context.entity.name}.${relationField} is not a has-many relation.`);
138
+ }
139
+ const entity = this.context.schema.entities[field.entity];
140
+ const newContext = {
141
+ entity,
142
+ schema: this.context.schema
143
+ };
144
+ const fieldUpperFirst = name.charAt(0).toUpperCase() + name.slice(1);
145
+ const argsWithType = {
146
+ filter: {
147
+ graphQlType: `${entity.name}Where`,
148
+ value: args.filter
149
+ },
150
+ by: {
151
+ graphQlType: `${this.context.entity.name}${fieldUpperFirst}UniqueWhere!`,
152
+ value: args.by
153
+ }
154
+ };
155
+ const entitySelection = typeof fields === "function" ? fields(new ContentEntitySelection(newContext, [])) : fields;
156
+ const newObjectField = new GraphQlField(
157
+ alias,
158
+ name,
159
+ argsWithType,
160
+ entitySelection.selectionSet
161
+ );
162
+ const selectionWithField = this.withField(newObjectField);
163
+ const nestedTransform = entitySelection.transformFn;
164
+ if (!nestedTransform) {
165
+ return selectionWithField;
166
+ }
167
+ return selectionWithField.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null);
168
+ }
169
+ _one(name, args, fields) {
170
+ const alias = args.as ?? name;
171
+ const fieldInfo = this.context.entity.fields[name];
172
+ if (!fieldInfo) {
173
+ throw new Error(`Field ${this.context.entity.name}.${name} does not exist.`);
174
+ }
175
+ if (fieldInfo?.type !== "one") {
176
+ throw new Error(`Field ${this.context.entity.name}.${name} is not a has-one relation.`);
177
+ }
178
+ const entity = this.context.schema.entities[fieldInfo.entity];
179
+ const newContext = {
180
+ entity,
181
+ schema: this.context.schema
182
+ };
183
+ const argsWithType = {
184
+ filter: {
185
+ graphQlType: `${entity.name}Where`,
186
+ value: args.filter
187
+ }
188
+ };
189
+ const entitySelection = typeof fields === "function" ? fields(new ContentEntitySelection(newContext, [])) : fields;
190
+ const newObjectField = new GraphQlField(
191
+ alias,
192
+ name,
193
+ argsWithType,
194
+ entitySelection.selectionSet
195
+ );
196
+ const selectionWithField = this.withField(newObjectField);
197
+ const nestedTransform = entitySelection.transformFn;
198
+ if (!nestedTransform) {
199
+ return selectionWithField;
200
+ }
201
+ return selectionWithField.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null);
202
+ }
203
+ withField(field) {
204
+ return new ContentEntitySelection(this.context, [
205
+ ...this.selectionSet,
206
+ field
207
+ ], this.transformFn);
208
+ }
209
+ withFieldTransform(alias, transform) {
210
+ return new ContentEntitySelection(this.context, this.selectionSet, (value, ctx) => {
211
+ const transformedValue = transform(value[alias], ctx);
212
+ const newValue = {
213
+ ...value,
214
+ [alias]: transformedValue
215
+ };
216
+ return this.transformFn ? this.transformFn(newValue, ctx) : newValue;
217
+ });
218
+ }
219
+ }
220
+ export {
221
+ ContentEntitySelection
222
+ };
223
+ //# sourceMappingURL=ContentEntitySelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentEntitySelection.js","sources":["../../../../../packages/client-content/src/nodes/ContentEntitySelection.ts"],"sourcesContent":["import { createListArgs } from '../utils/createListArgs'\nimport { ContentClientInput, SchemaEntityNames, SchemaNames } from '../types'\nimport { Input } from '@contember/schema'\nimport { GraphQlField, GraphQlFieldTypedArgs, GraphQlSelectionSet } from '@contember/graphql-builder'\n\n/**\n * @internal\n */\nexport type ContentEntitySelectionContext<Name extends string> = {\n\tentity: SchemaEntityNames<Name>\n\tschema: SchemaNames\n}\n\nexport type ContentEntitySelectionCallback = (select: ContentEntitySelection) => ContentEntitySelection\n\nexport type EntitySelectionCommonInput<Alias extends string | null = string | null> = { as?: Alias }\nexport type EntitySelectionManyArgs<Alias extends string | null = string | null> =\n\t& ContentClientInput.AnyListQueryInput\n\t& EntitySelectionCommonInput<Alias>\nexport type EntitySelectionManyByArgs<Alias extends string | null = string | null> =\n\t& { by: Input.UniqueWhere; filter?: Input.Where }\n\t& EntitySelectionCommonInput<Alias>\nexport type EntitySelectionOneArgs<Alias extends string | null = string | null> = { filter?: Input.Where } & EntitySelectionCommonInput<Alias>\nexport type EntitySelectionColumnArgs<Alias extends string | null = string | null> = EntitySelectionCommonInput<Alias>\n\nexport type EntitySelectionAnyArgs =\n\t| EntitySelectionColumnArgs\n\t| EntitySelectionManyArgs\n\t| EntitySelectionManyByArgs\n\t| EntitySelectionOneArgs\n\nexport type ContentEntitySelectionOrCallback = ContentEntitySelectionCallback | ContentEntitySelection\n\nexport type ContentTransformContext = {\n\trootValue: unknown\n}\n\nexport class ContentEntitySelection {\n\t/**\n\t * @internal\n\t */\n\tconstructor(\n\t\t/** @internal */\n\t\tpublic readonly context: ContentEntitySelectionContext<string>,\n\t\t/** @internal */\n\t\tpublic readonly selectionSet: GraphQlSelectionSet,\n\t\t/** @internal */\n\t\tpublic readonly transformFn?: (value: any, ctx: ContentTransformContext) => any,\n\t) {\n\t}\n\n\t$(field: string, args?: EntitySelectionColumnArgs): ContentEntitySelection\n\t$(field: string, args: EntitySelectionManyArgs, selection: ContentEntitySelectionOrCallback): ContentEntitySelection\n\t$(field: string, args: EntitySelectionManyByArgs, selection: ContentEntitySelectionOrCallback): ContentEntitySelection\n\t$(field: string, args: EntitySelectionOneArgs, selection: ContentEntitySelectionOrCallback): ContentEntitySelection\n\t$(field: string, selection: ContentEntitySelectionOrCallback): ContentEntitySelection\n\n\t$(\n\t\tfield: string,\n\t\targsOrSelection?: EntitySelectionAnyArgs | ContentEntitySelectionOrCallback,\n\t\tselectionIn?: ContentEntitySelectionOrCallback,\n\t): ContentEntitySelection {\n\t\tconst [args, selection] = typeof argsOrSelection === 'function' || argsOrSelection instanceof ContentEntitySelection\n\t\t\t? [{}, argsOrSelection]\n\t\t\t: [argsOrSelection ?? {}, selectionIn]\n\t\tif (field === '__typename') {\n\t\t\treturn this.withField(new GraphQlField(args.as ?? null, '__typename'))\n\t\t}\n\t\tconst fieldInfo = this.context.entity.fields[field]\n\t\tif (!fieldInfo) {\n\t\t\tif ('by' in args && field.includes('By')) {\n\t\t\t\tif (!selection) {\n\t\t\t\t\tthrow new Error(`Selection is required for ${this.context.entity.name}.${field}.`)\n\t\t\t\t}\n\t\t\t\treturn this._manyBy(field, args as EntitySelectionManyByArgs, selection)\n\t\t\t}\n\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${field} does not exist.`)\n\t\t}\n\t\tif (fieldInfo.type === 'column') {\n\t\t\treturn this._column(field, args as EntitySelectionColumnArgs)\n\t\t}\n\t\tif (fieldInfo.type === 'many') {\n\t\t\tif (!selection) {\n\t\t\t\tthrow new Error(`Selection is required for ${this.context.entity.name}.${field}.`)\n\t\t\t}\n\t\t\treturn this._many(field, args as EntitySelectionManyArgs, selection)\n\t\t}\n\t\tif (fieldInfo.type === 'one') {\n\t\t\tif (!selection) {\n\t\t\t\tthrow new Error(`Selection is required for ${this.context.entity.name}.${field}.`)\n\t\t\t}\n\t\t\treturn this._one(field, args as EntitySelectionOneArgs, selection)\n\t\t}\n\t\tthrow new Error(`Unknown field type ${fieldInfo.type}.`)\n\t}\n\n\t$$(): ContentEntitySelection {\n\t\tconst columns = this.context.entity.scalars\n\t\tconst nodes = [\n\t\t\t...this.selectionSet,\n\t\t\t...columns.map(col => new GraphQlField(null, col)),\n\t\t]\n\t\treturn new ContentEntitySelection(this.context, nodes)\n\t}\n\n\tomit(...fields: string[]): ContentEntitySelection {\n\t\treturn new ContentEntitySelection(\n\t\t\tthis.context,\n\t\t\tthis.selectionSet.filter(it => {\n\t\t\t\tif (!(it instanceof GraphQlField)) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tconst alias = it.alias ?? it.name\n\t\t\t\treturn !fields.includes(alias)\n\t\t\t}),\n\t\t)\n\t}\n\n\tmeta(field: string, flags: ('readable' | 'updatable')[]): ContentEntitySelection {\n\t\tconst metaField = this.selectionSet.find((it): it is GraphQlField => it instanceof GraphQlField && it.name === '_meta')\n\t\tconst selectionWithoutMeta = metaField ? this.selectionSet.filter(it => it !== metaField) : this.selectionSet\n\n\t\tconst flagFields: GraphQlField[] = []\n\t\tfor (const flag of flags) {\n\t\t\tflagFields.push(new GraphQlField(null, flag))\n\t\t}\n\n\t\treturn new ContentEntitySelection(this.context, [\n\t\t\t...selectionWithoutMeta,\n\t\t\tnew GraphQlField(null, '_meta', undefined, [\n\t\t\t\t...metaField?.selectionSet ?? [],\n\t\t\t\tnew GraphQlField(null, field, undefined, flagFields),\n\t\t\t]),\n\t\t])\n\t}\n\n\ttransform(transform: (value: any, context: ContentTransformContext) => any): ContentEntitySelection {\n\t\treturn new ContentEntitySelection(\n\t\t\tthis.context,\n\t\t\tthis.selectionSet,\n\t\t\t!this.transformFn ? transform : (value, ctx) => {\n\t\t\t\treturn transform(this.transformFn!(value, ctx), ctx)\n\t\t\t},\n\t\t)\n\t}\n\n\tprivate _column(\n\t\tname: string,\n\t\targs: EntitySelectionCommonInput = {},\n\t): ContentEntitySelection {\n\t\tlet fieldInfo = this.context.entity.fields[name]\n\t\tif (!fieldInfo) {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${name} does not exist.`)\n\t\t}\n\t\tif (fieldInfo?.type !== 'column') {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${name} is not a column.`)\n\t\t}\n\n\t\tconst alias = args.as ?? name\n\n\t\tconst field = new GraphQlField(alias, name, {})\n\t\treturn this.withField(field)\n\t}\n\n\tprivate _many(\n\t\tname: string,\n\t\targs: EntitySelectionManyArgs,\n\t\tfields:\n\t\t\t| ContentEntitySelectionCallback\n\t\t\t| ContentEntitySelection,\n\t): ContentEntitySelection {\n\t\tconst alias = args.as ?? name\n\t\tconst fieldInfo = this.context.entity.fields[name]\n\t\tif (!fieldInfo) {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${name} does not exist.`)\n\t\t}\n\t\tif (fieldInfo?.type !== 'many') {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${name} is not a has-many relation.`)\n\t\t}\n\t\tconst entity = this.context.schema.entities[fieldInfo.entity]\n\n\t\tconst newContext = {\n\t\t\tentity: entity,\n\t\t\tschema: this.context.schema,\n\t\t}\n\n\t\tconst entitySelection = typeof fields === 'function' ? fields(new ContentEntitySelection(newContext, [])) : fields\n\t\tconst newObjectField = new GraphQlField(\n\t\t\talias,\n\t\t\tname,\n\t\t\tcreateListArgs(entity, args),\n\t\t\tentitySelection.selectionSet,\n\t\t)\n\t\tconst selectionWithField = this.withField(newObjectField)\n\t\tconst nestedTransform = entitySelection.transformFn\n\t\tif (!nestedTransform) {\n\t\t\treturn selectionWithField\n\t\t}\n\t\treturn selectionWithField.withFieldTransform(alias, it => it.map(nestedTransform))\n\t}\n\n\tprivate _manyBy(\n\t\tname: string,\n\t\targs: EntitySelectionManyByArgs,\n\t\tfields:\n\t\t\t| ContentEntitySelectionCallback\n\t\t\t| ContentEntitySelection,\n\t): ContentEntitySelection {\n\t\tconst alias = args.as ?? name\n\t\tconst byField = Object.keys(args.by)[0]\n\t\tconst relationField = name.substring(0, name.length - byField.length - 2)\n\n\t\tconst field = this.context.entity.fields[relationField]\n\t\tif (!field) {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${relationField} does not exist.`)\n\t\t}\n\t\tif (field?.type !== 'many') {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${relationField} is not a has-many relation.`)\n\t\t}\n\t\tconst entity = this.context.schema.entities[field.entity]\n\t\tconst newContext = {\n\t\t\tentity: entity,\n\t\t\tschema: this.context.schema,\n\t\t}\n\t\tconst fieldUpperFirst = name.charAt(0).toUpperCase() + name.slice(1)\n\n\t\tconst argsWithType: GraphQlFieldTypedArgs = {\n\t\t\tfilter: {\n\t\t\t\tgraphQlType: `${entity.name}Where`,\n\t\t\t\tvalue: args.filter,\n\t\t\t},\n\t\t\tby: {\n\t\t\t\tgraphQlType: `${this.context.entity.name}${fieldUpperFirst}UniqueWhere!`,\n\t\t\t\tvalue: args.by,\n\t\t\t},\n\t\t}\n\n\t\tconst entitySelection = typeof fields === 'function' ? fields(new ContentEntitySelection(newContext, []) as any) : fields\n\t\tconst newObjectField = new GraphQlField(\n\t\t\talias,\n\t\t\tname,\n\t\t\targsWithType,\n\t\t\tentitySelection.selectionSet,\n\t\t)\n\t\tconst selectionWithField = this.withField(newObjectField)\n\t\tconst nestedTransform = entitySelection.transformFn\n\t\tif (!nestedTransform) {\n\t\t\treturn selectionWithField\n\t\t}\n\t\treturn selectionWithField.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null)\n\t}\n\n\tprivate _one(\n\t\tname: string,\n\t\targs: EntitySelectionOneArgs,\n\t\tfields:\n\t\t\t| ContentEntitySelectionCallback\n\t\t\t| ContentEntitySelection,\n\t): ContentEntitySelection {\n\t\tconst alias = args.as ?? name\n\t\tconst fieldInfo = this.context.entity.fields[name]\n\t\tif (!fieldInfo) {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${name} does not exist.`)\n\t\t}\n\t\tif (fieldInfo?.type !== 'one') {\n\t\t\tthrow new Error(`Field ${this.context.entity.name}.${name} is not a has-one relation.`)\n\t\t}\n\t\tconst entity = this.context.schema.entities[fieldInfo.entity]\n\n\t\tconst newContext: ContentEntitySelectionContext<(typeof entity)['name']> = {\n\t\t\tentity: entity,\n\t\t\tschema: this.context.schema,\n\t\t}\n\t\tconst argsWithType: GraphQlFieldTypedArgs = {\n\t\t\tfilter: {\n\t\t\t\tgraphQlType: `${entity.name}Where`,\n\t\t\t\tvalue: args.filter,\n\t\t\t},\n\t\t}\n\t\tconst entitySelection = typeof fields === 'function'\n\t\t\t? fields(new ContentEntitySelection(newContext, []) as any)\n\t\t\t: fields\n\t\tconst newObjectField = new GraphQlField(\n\t\t\talias,\n\t\t\tname,\n\t\t\targsWithType,\n\t\t\tentitySelection.selectionSet,\n\t\t)\n\t\tconst selectionWithField = this.withField(newObjectField)\n\t\tconst nestedTransform = entitySelection.transformFn\n\t\tif (!nestedTransform) {\n\t\t\treturn selectionWithField\n\t\t}\n\t\treturn selectionWithField.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null)\n\t}\n\n\tprivate withField(field: GraphQlField) {\n\t\treturn new ContentEntitySelection(this.context, [\n\t\t\t...this.selectionSet,\n\t\t\tfield,\n\t\t], this.transformFn)\n\t}\n\n\tprivate withFieldTransform(alias: string, transform: (value: any, ctx: ContentTransformContext) => any) {\n\t\treturn new ContentEntitySelection(this.context, this.selectionSet, (value, ctx) => {\n\t\t\tconst transformedValue = transform(value[alias], ctx)\n\t\t\tconst newValue = {\n\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B,KAAK,UAAU,cAAc;AACxD,UAAM,kBAAkB,gBAAgB;AACxC,QAAI,CAAC,iBAAiB;AACrB,aAAO;AAAA,IACR;AACA,WAAO,mBAAmB,mBAAmB,OAAO,CAAC,IAAI,QAAQ,OAAO,OAAO,gBAAgB,IAAI,GAAG,IAAI,IAAI;AAAA,EAC/G;AAAA,EAEQ,UAAU,OAAqB;AACtC,WAAO,IAAI,uBAAuB,KAAK,SAAS;AAAA,MAC/C,GAAG,KAAK;AAAA,MACR;AAAA,IAAA,GACE,KAAK,WAAW;AAAA,EACpB;AAAA,EAEQ,mBAAmB,OAAe,WAA8D;AACvG,WAAO,IAAI,uBAAuB,KAAK,SAAS,KAAK,cAAc,CAAC,OAAO,QAAQ;AAClF,YAAM,mBAAmB,UAAU,MAAM,KAAK,GAAG,GAAG;AACpD,YAAM,WAAW;AAAA,QAChB,GAAG;AAAA,QACH,CAAC,KAAK,GAAG;AAAA,MAAA;AAEV,aAAO,KAAK,cAAc,KAAK,YAAY,UAAU,GAAG,IAAI;AAAA,IAC7D,CAAC;AAAA,EACF;AACD;"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ class ContentOperation {
4
+ /**
5
+ * @internal
6
+ */
7
+ constructor(type, fieldName, args = {}, selection, parse = (it) => it) {
8
+ this.type = type;
9
+ this.fieldName = fieldName;
10
+ this.args = args;
11
+ this.selection = selection;
12
+ this.parse = parse;
13
+ }
14
+ }
15
+ exports.ContentOperation = ContentOperation;
16
+ //# sourceMappingURL=ContentOperation.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentOperation.cjs","sources":["../../../../../packages/client-content/src/nodes/ContentOperation.ts"],"sourcesContent":["import { GraphQlFieldTypedArgs, GraphQlSelectionSet } from '@contember/graphql-builder'\n\nexport class ContentOperation<TValue, TType extends 'query' | 'mutation'> {\n\t/**\n\t * @internal\n\t */\n\tconstructor(\n\t\t/** @internal */\n\t\tpublic readonly type: TType,\n\t\t/** @internal */\n\t\tpublic readonly fieldName: string,\n\t\t/** @internal */\n\t\tpublic readonly args: GraphQlFieldTypedArgs = {},\n\t\t/** @internal */\n\t\tpublic readonly selection?: GraphQlSelectionSet,\n\t\t/** @internal */\n\t\tpublic readonly parse: (value: any) => TValue = it => it as TValue,\n\t) {\n\t}\n}\n\nexport type ContentQuery<TValue> = ContentOperation<TValue, 'query'>\nexport type ContentMutation<TValue> = ContentOperation<TValue, 'mutation'>\n"],"names":[],"mappings":";;AAEO,MAAM,iBAA6D;AAAA;AAAA;AAAA;AAAA,EAIzE,YAEiB,MAEA,WAEA,OAA8B,CAAA,GAE9B,WAEA,QAAgC,CAAA,OAAM,IACrD;AATe,SAAA,OAAA;AAEA,SAAA,YAAA;AAEA,SAAA,OAAA;AAEA,SAAA,YAAA;AAEA,SAAA,QAAA;AAAA,EAEjB;AACD;;"}
@@ -0,0 +1,16 @@
1
+ class ContentOperation {
2
+ /**
3
+ * @internal
4
+ */
5
+ constructor(type, fieldName, args = {}, selection, parse = (it) => it) {
6
+ this.type = type;
7
+ this.fieldName = fieldName;
8
+ this.args = args;
9
+ this.selection = selection;
10
+ this.parse = parse;
11
+ }
12
+ }
13
+ export {
14
+ ContentOperation
15
+ };
16
+ //# sourceMappingURL=ContentOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentOperation.js","sources":["../../../../../packages/client-content/src/nodes/ContentOperation.ts"],"sourcesContent":["import { GraphQlFieldTypedArgs, GraphQlSelectionSet } from '@contember/graphql-builder'\n\nexport class ContentOperation<TValue, TType extends 'query' | 'mutation'> {\n\t/**\n\t * @internal\n\t */\n\tconstructor(\n\t\t/** @internal */\n\t\tpublic readonly type: TType,\n\t\t/** @internal */\n\t\tpublic readonly fieldName: string,\n\t\t/** @internal */\n\t\tpublic readonly args: GraphQlFieldTypedArgs = {},\n\t\t/** @internal */\n\t\tpublic readonly selection?: GraphQlSelectionSet,\n\t\t/** @internal */\n\t\tpublic readonly parse: (value: any) => TValue = it => it as TValue,\n\t) {\n\t}\n}\n\nexport type ContentQuery<TValue> = ContentOperation<TValue, 'query'>\nexport type ContentMutation<TValue> = ContentOperation<TValue, 'mutation'>\n"],"names":[],"mappings":"AAEO,MAAM,iBAA6D;AAAA;AAAA;AAAA;AAAA,EAIzE,YAEiB,MAEA,WAEA,OAA8B,CAAA,GAE9B,WAEA,QAAgC,CAAA,OAAM,IACrD;AATe,SAAA,OAAA;AAEA,SAAA,YAAA;AAEA,SAAA,OAAA;AAEA,SAAA,YAAA;AAEA,SAAA,QAAA;AAAA,EAEjB;AACD;"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ class ContentOperationSet {
4
+ constructor(selection, parse = (it) => it) {
5
+ this.selection = selection;
6
+ this.parse = parse;
7
+ }
8
+ }
9
+ exports.ContentOperationSet = ContentOperationSet;
10
+ //# sourceMappingURL=ContentOperationSet.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentOperationSet.cjs","sources":["../../../../../packages/client-content/src/utils/ContentOperationSet.ts"],"sourcesContent":["import { GraphQlSelectionSet } from '@contember/graphql-builder'\n\nexport class ContentOperationSet<TValue> {\n\tconstructor(\n\t\t/** @internal */\n\t\tpublic readonly selection: GraphQlSelectionSet,\n\t\t/** @internal */\n\t\tpublic readonly parse: (value: any) => TValue = it => it as TValue,\n\t) {\n\t}\n}\n"],"names":[],"mappings":";;AAEO,MAAM,oBAA4B;AAAA,EACxC,YAEiB,WAEA,QAAgC,CAAA,OAAM,IACrD;AAHe,SAAA,YAAA;AAEA,SAAA,QAAA;AAAA,EAEjB;AACD;;"}
@@ -0,0 +1,10 @@
1
+ class ContentOperationSet {
2
+ constructor(selection, parse = (it) => it) {
3
+ this.selection = selection;
4
+ this.parse = parse;
5
+ }
6
+ }
7
+ export {
8
+ ContentOperationSet
9
+ };
10
+ //# sourceMappingURL=ContentOperationSet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentOperationSet.js","sources":["../../../../../packages/client-content/src/utils/ContentOperationSet.ts"],"sourcesContent":["import { GraphQlSelectionSet } from '@contember/graphql-builder'\n\nexport class ContentOperationSet<TValue> {\n\tconstructor(\n\t\t/** @internal */\n\t\tpublic readonly selection: GraphQlSelectionSet,\n\t\t/** @internal */\n\t\tpublic readonly parse: (value: any) => TValue = it => it as TValue,\n\t) {\n\t}\n}\n"],"names":[],"mappings":"AAEO,MAAM,oBAA4B;AAAA,EACxC,YAEiB,WAEA,QAAgC,CAAA,OAAM,IACrD;AAHe,SAAA,YAAA;AAEA,SAAA,QAAA;AAAA,EAEjB;AACD;"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const createListArgs = (entity, args, type = "list") => {
4
+ return {
5
+ filter: {
6
+ graphQlType: `${entity.name}Where`,
7
+ value: args.filter
8
+ },
9
+ orderBy: {
10
+ graphQlType: `[${entity.name}OrderBy!]`,
11
+ value: args.orderBy
12
+ },
13
+ [type === "list" ? "limit" : "first"]: {
14
+ graphQlType: "Int",
15
+ value: args.limit
16
+ },
17
+ [type === "list" ? "offset" : "skip"]: {
18
+ graphQlType: "Int",
19
+ value: args.offset
20
+ }
21
+ };
22
+ };
23
+ exports.createListArgs = createListArgs;
24
+ //# sourceMappingURL=createListArgs.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createListArgs.cjs","sources":["../../../../../packages/client-content/src/utils/createListArgs.ts"],"sourcesContent":["import { SchemaEntityNames } from '../types'\nimport { GraphQlFieldTypedArgs } from '@contember/graphql-builder'\n\nexport const createListArgs = (\n\tentity: SchemaEntityNames<string>,\n\targs: { filter?: any; orderBy?: any; limit?: number; offset?: number },\n\ttype: 'list' | 'paginate' = 'list',\n): GraphQlFieldTypedArgs => {\n\treturn {\n\t\tfilter: {\n\t\t\tgraphQlType: `${entity.name}Where`,\n\t\t\tvalue: args.filter,\n\t\t},\n\t\torderBy: {\n\t\t\tgraphQlType: `[${entity.name}OrderBy!]`,\n\t\t\tvalue: args.orderBy,\n\t\t},\n\t\t[type === 'list' ? 'limit' : 'first']: {\n\t\t\tgraphQlType: 'Int',\n\t\t\tvalue: args.limit,\n\t\t},\n\t\t[type === 'list' ? 'offset' : 'skip']: {\n\t\t\tgraphQlType: 'Int',\n\t\t\tvalue: args.offset,\n\t\t},\n\t}\n}\n"],"names":[],"mappings":";;AAGO,MAAM,iBAAiB,CAC7B,QACA,MACA,OAA4B,WACD;AAC3B,SAAO;AAAA,IACN,QAAQ;AAAA,MACP,aAAa,GAAG,OAAO,IAAI;AAAA,MAC3B,OAAO,KAAK;AAAA,IAAA;AAAA,IAEb,SAAS;AAAA,MACR,aAAa,IAAI,OAAO,IAAI;AAAA,MAC5B,OAAO,KAAK;AAAA,IAAA;AAAA,IAEb,CAAC,SAAS,SAAS,UAAU,OAAO,GAAG;AAAA,MACtC,aAAa;AAAA,MACb,OAAO,KAAK;AAAA,IAAA;AAAA,IAEb,CAAC,SAAS,SAAS,WAAW,MAAM,GAAG;AAAA,MACtC,aAAa;AAAA,MACb,OAAO,KAAK;AAAA,IAAA;AAAA,EACb;AAEF;;"}
@@ -0,0 +1,24 @@
1
+ const createListArgs = (entity, args, type = "list") => {
2
+ return {
3
+ filter: {
4
+ graphQlType: `${entity.name}Where`,
5
+ value: args.filter
6
+ },
7
+ orderBy: {
8
+ graphQlType: `[${entity.name}OrderBy!]`,
9
+ value: args.orderBy
10
+ },
11
+ [type === "list" ? "limit" : "first"]: {
12
+ graphQlType: "Int",
13
+ value: args.limit
14
+ },
15
+ [type === "list" ? "offset" : "skip"]: {
16
+ graphQlType: "Int",
17
+ value: args.offset
18
+ }
19
+ };
20
+ };
21
+ export {
22
+ createListArgs
23
+ };
24
+ //# sourceMappingURL=createListArgs.js.map