@contello/client 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020-2026 entwico GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/cli.js CHANGED
@@ -4,7 +4,7 @@
4
4
  var command = process.argv[2];
5
5
  switch (command) {
6
6
  case "generate":
7
- await import("./generate-QAYD35FG.js");
7
+ await import("./generate-PEGBZG77.js");
8
8
  break;
9
9
  default:
10
10
  console.error(command ? `unknown command: ${command}` : "usage: contello-client <command>");
@@ -3,7 +3,7 @@
3
3
  // src/generate/index.ts
4
4
  import { mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
5
5
  import { glob } from "fs/promises";
6
- import { dirname, resolve as resolve2 } from "path";
6
+ import { dirname, relative, resolve as resolve2 } from "path";
7
7
  import { parse as parse2 } from "graphql";
8
8
 
9
9
  // src/generate/config.ts
@@ -149,6 +149,7 @@ async function introspectSchema(url, project, token) {
149
149
  // src/generate/operation-types.ts
150
150
  import {
151
151
  Kind as Kind2,
152
+ doTypesOverlap as checkTypesOverlap,
152
153
  isCompositeType,
153
154
  isEnumType,
154
155
  isInterfaceType,
@@ -314,6 +315,11 @@ ${nested.slice(2)}`);
314
315
  if (fragment?.selectionSet) {
315
316
  const fragmentType = schema.getType(fragment.typeCondition.name.value);
316
317
  if (fragmentType && isCompositeType(fragmentType)) {
318
+ if (!checkTypesOverlap(schema, parentType, fragmentType)) {
319
+ throw new Error(
320
+ `fragment "${fragmentName}" (on ${fragmentType.name}) cannot be spread on type "${parentType.name}"`
321
+ );
322
+ }
317
323
  const nextVisited = new Set(visited);
318
324
  nextVisited.add(fragmentName);
319
325
  const fragmentResult = resolveSelectionSet(
@@ -764,23 +770,33 @@ function transformFragment(schema, fragment, fragments) {
764
770
  }
765
771
 
766
772
  // src/generate/index.ts
773
+ var ctrlSeq = "\x1B[";
774
+ var styled = (s, pre, post) => `${ctrlSeq}${pre}${s}${ctrlSeq}${post}`;
775
+ var dim = (s) => styled(s, "2m", "22m");
776
+ var bold = (s) => styled(s, "1m", "22m");
777
+ var green = (s) => styled(s, "32m", "39m");
778
+ var yellow = (s) => styled(s, "33m", "39m");
779
+ var cyan = (s) => styled(s, "36m", "39m");
767
780
  async function main() {
768
781
  const cwd = process.cwd();
769
782
  const config = await loadConfig(cwd);
783
+ console.log("");
784
+ console.log(`${bold("@contello/client")} ${dim("generate")}`);
785
+ console.log("");
770
786
  for (const project of config.projects) {
771
- console.log(`generating types for project "${project.project}"...`);
787
+ const start = performance.now();
788
+ console.log(`${cyan("\u25CF")} ${bold(project.project)}`);
772
789
  rmSync(resolve2(cwd, project.output), { force: true });
773
790
  const schema = await introspectSchema(project.url, project.project, project.token);
774
791
  const patterns = Array.isArray(project.documents) ? project.documents : [project.documents];
775
792
  const documentPaths = (await Promise.all(patterns.map((p) => Array.fromAsync(glob(p, { cwd }))))).flat().sort();
776
793
  if (documentPaths.length === 0) {
777
- console.warn(` no documents found matching "${project.documents}"`);
794
+ console.warn(` ${yellow("\u26A0")} no documents found matching "${project.documents}"`);
778
795
  continue;
779
796
  }
780
797
  const documents = documentPaths.map((p) => parse2(readFileSync(resolve2(cwd, p), "utf-8")));
781
798
  const fragments = collectFragments(documents);
782
799
  const operations = collectOperations(documents);
783
- console.log(` found ${operations.length} operations, ${fragments.size} fragments`);
784
800
  const transformedFragments = new Map(
785
801
  [...fragments].map(([name, frag]) => [name, transformFragment(schema, frag, fragments)])
786
802
  );
@@ -811,9 +827,11 @@ ${indented}
811
827
  const outputPath = resolve2(cwd, project.output);
812
828
  mkdirSync(dirname(outputPath), { recursive: true });
813
829
  writeFileSync(outputPath, output, "utf-8");
814
- console.log(` wrote ${outputPath}`);
830
+ const elapsed = Math.round(performance.now() - start);
831
+ console.log(` ${green("\u2713")} ${relative(cwd, outputPath)} ${dim(`${elapsed}ms`)}`);
832
+ console.log(` ${dim("operations")} ${operations.length} ${dim("fragments")} ${fragments.size}`);
833
+ console.log("");
815
834
  }
816
- console.log("done");
817
835
  }
818
836
  main().catch((err) => {
819
837
  console.error(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contello/client",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "GraphQL client for Contello CMS with WebSocket transport, connection pooling, and built-in codegen",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -10,12 +10,6 @@
10
10
  "url": "https://github.com/entwico/contello-js",
11
11
  "directory": "packages/client"
12
12
  },
13
- "scripts": {
14
- "build": "tsup",
15
- "lint": "eslint .",
16
- "lint:fix": "eslint . --fix",
17
- "typecheck": "tsc --noEmit"
18
- },
19
13
  "dependencies": {
20
14
  "graphql": "^16.13.1",
21
15
  "graphql-ws": "^6.0.7"
@@ -42,5 +36,11 @@
42
36
  "publishConfig": {
43
37
  "access": "public",
44
38
  "registry": "https://registry.npmjs.org"
39
+ },
40
+ "scripts": {
41
+ "build": "tsup",
42
+ "lint": "eslint .",
43
+ "lint:fix": "eslint . --fix",
44
+ "typecheck": "tsc --noEmit"
45
45
  }
46
- }
46
+ }