apollo-conn-gen 0.4.2 → 0.4.4

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 (55) hide show
  1. package/dist/cli/oas.js +2 -2
  2. package/dist/cli/oas.js.map +1 -1
  3. package/dist/oas/generator/typesCollector.d.ts +9 -0
  4. package/dist/oas/generator/typesCollector.js +147 -0
  5. package/dist/oas/generator/typesCollector.js.map +1 -0
  6. package/dist/oas/io/writer.d.ts +2 -2
  7. package/dist/oas/io/writer.js +14 -74
  8. package/dist/oas/io/writer.js.map +1 -1
  9. package/dist/oas/nodes/circularRef.js +0 -1
  10. package/dist/oas/nodes/circularRef.js.map +1 -1
  11. package/dist/oas/nodes/comp.d.ts +0 -1
  12. package/dist/oas/nodes/comp.js +9 -21
  13. package/dist/oas/nodes/comp.js.map +1 -1
  14. package/dist/oas/nodes/obj.d.ts +2 -0
  15. package/dist/oas/nodes/obj.js +15 -2
  16. package/dist/oas/nodes/obj.js.map +1 -1
  17. package/dist/oas/nodes/propArray.d.ts +2 -1
  18. package/dist/oas/nodes/propArray.js +17 -9
  19. package/dist/oas/nodes/propArray.js.map +1 -1
  20. package/dist/oas/nodes/propScalar.js +7 -3
  21. package/dist/oas/nodes/propScalar.js.map +1 -1
  22. package/dist/oas/nodes/typeUtils.d.ts +3 -0
  23. package/dist/oas/nodes/typeUtils.js +16 -2
  24. package/dist/oas/nodes/typeUtils.js.map +1 -1
  25. package/dist/oas/nodes/union.d.ts +3 -2
  26. package/dist/oas/nodes/union.js +60 -22
  27. package/dist/oas/nodes/union.js.map +1 -1
  28. package/dist/oas/oasContext.d.ts +2 -0
  29. package/dist/oas/oasContext.js +11 -0
  30. package/dist/oas/oasContext.js.map +1 -1
  31. package/dist/oas/oasGen.d.ts +3 -0
  32. package/dist/oas/oasGen.js +15 -1
  33. package/dist/oas/oasGen.js.map +1 -1
  34. package/dist/oas/utils/naming.d.ts +2 -1
  35. package/dist/oas/utils/naming.js +12 -5
  36. package/dist/oas/utils/naming.js.map +1 -1
  37. package/dist/oas/visitor/GeneratorVisitor.d.ts +39 -0
  38. package/dist/oas/visitor/GeneratorVisitor.js +310 -0
  39. package/dist/oas/visitor/GeneratorVisitor.js.map +1 -0
  40. package/dist/oas/visitor/NodeVisitor.d.ts +30 -0
  41. package/dist/oas/visitor/NodeVisitor.js +2 -0
  42. package/dist/oas/visitor/NodeVisitor.js.map +1 -0
  43. package/dist/oas/visitor/example.d.ts +17 -0
  44. package/dist/oas/visitor/example.js +28 -0
  45. package/dist/oas/visitor/example.js.map +1 -0
  46. package/dist/oas/visitor/index.d.ts +2 -0
  47. package/dist/oas/visitor/index.js +2 -0
  48. package/dist/oas/visitor/index.js.map +1 -0
  49. package/dist/tests/runners.js +2 -1
  50. package/dist/tests/runners.js.map +1 -1
  51. package/dist/tsconfig.tsbuildinfo +1 -1
  52. package/package.json +1 -1
  53. package/dist/oas/io/pathCollector.d.ts +0 -11
  54. package/dist/oas/io/pathCollector.js +0 -95
  55. package/dist/oas/io/pathCollector.js.map +0 -1
@@ -1,95 +0,0 @@
1
- import _ from 'lodash';
2
- import { Composed, Prop, PropArray, Scalar, T } from '../nodes/internal.js';
3
- export class PathCollector {
4
- gen;
5
- constructor(gen) {
6
- this.gen = gen;
7
- }
8
- static findNonPropParent(type) {
9
- let parent = type;
10
- while (parent instanceof Prop) {
11
- parent = parent.parent;
12
- }
13
- return parent;
14
- }
15
- static progressiveSplits(input) {
16
- const parts = input.split('>');
17
- const results = [];
18
- for (let i = 1; i <= parts.length; i++) {
19
- results.push(parts.slice(0, i).join('>'));
20
- }
21
- return results;
22
- }
23
- collectPaths(path, collection) {
24
- const stack = [];
25
- let current;
26
- let last;
27
- let i = 0;
28
- const parts = path.split('>');
29
- do {
30
- const part = parts[i].replace(/#\/c\/s/g, '#/components/schemas');
31
- current = collection.find((t) => t.id === part);
32
- if (!current) {
33
- throw new Error('Could not find type: ' + part + ' from ' + path + ', last: ' + last?.pathToRoot());
34
- }
35
- // make sure we expand it before we move on to the next part
36
- this.gen.expand(current);
37
- last = current;
38
- collection = Array.from(current.children.values()) || Array.from(current.props.values()) || [];
39
- stack.push(current);
40
- i++;
41
- } while (i < parts.length);
42
- return stack;
43
- }
44
- collectExpandedPaths(selection) {
45
- const newSelection = new Set();
46
- const expands = selection.filter((p) => p.endsWith('>**'));
47
- const filtered = expands.map((p) => p.replace('>**', ''));
48
- const paths = Array.from(this.gen.paths.values());
49
- const nodes = filtered.map((p) => this.collectPaths(p, paths));
50
- nodes.forEach((stack) => {
51
- const root = _.last(stack);
52
- T.traverse(root, (child) => {
53
- if (T.isPropScalar(child) || (child instanceof PropArray && child.items instanceof Scalar)) {
54
- newSelection.add(child.path());
55
- }
56
- else {
57
- this.gen.expand(child);
58
- }
59
- });
60
- });
61
- // finally remove the expanded paths from the selection
62
- return [...newSelection, ...selection.filter((p) => !expands.includes(p))];
63
- }
64
- traverseTree(current, selection, pending) {
65
- // we might be in a node far from the root, so we need to traverse upwards
66
- // as well and add the props that we can find on the way
67
- const source = current;
68
- source
69
- .ancestors()
70
- .filter((t) => t instanceof Prop)
71
- .map((p) => PathCollector.findNonPropParent(p))
72
- .forEach((parent) => pending.set(parent.id, parent));
73
- T.traverse(source, (child) => {
74
- if (T.isLeaf(child)) {
75
- // this is a weird take but if the child is an array of scalars
76
- // then we want to avoid adding it twice
77
- if (T.isLeaf(child.parent)) {
78
- return;
79
- }
80
- selection.push(child.path());
81
- const parentType = PathCollector.findNonPropParent(child);
82
- if (!pending.has(parentType.id)) {
83
- pending.set(parentType.id, parentType);
84
- }
85
- }
86
- else {
87
- this.gen.expand(child);
88
- if (child instanceof Composed) {
89
- child.consolidate(selection);
90
- }
91
- }
92
- });
93
- }
94
- }
95
- //# sourceMappingURL=pathCollector.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pathCollector.js","sourceRoot":"","sources":["../../../src/oas/io/pathCollector.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAA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MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;YAC3B,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBACpB,+DAA+D;gBAC/D,wCAAwC;gBACxC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,MAAO,CAAC,EAAE,CAAC;oBAC5B,OAAO;gBACT,CAAC;gBACD,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;gBAE7B,MAAM,UAAU,GAAG,aAAa,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;gBAC1D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;oBAChC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;gBACzC,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAEvB,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;oBAC9B,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;gBAC/B,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import _ from 'lodash';\nimport { OasGen } from '../oasGen.js';\nimport { Composed, IType, Prop, PropArray, Scalar, Type, T } from '../nodes/internal.js';\nimport { Writer } from './writer.js';\n\nexport class PathCollector {\n constructor(private gen: OasGen) {}\n\n public static findNonPropParent(type: IType) {\n let parent = type;\n while (parent instanceof Prop) {\n parent = parent.parent!;\n }\n return parent;\n }\n\n public static progressiveSplits(input: string): string[] {\n const parts = input.split('>');\n const results: string[] = [];\n for (let i = 1; i <= parts.length; i++) {\n results.push(parts.slice(0, i).join('>'));\n }\n return results;\n }\n\n public collectPaths(path: string, collection: IType[]): IType[] {\n const stack: IType[] = [];\n let current: IType | undefined;\n let last: IType | undefined;\n\n let i = 0;\n const parts = path.split('>');\n do {\n const part = parts[i].replace(/#\\/c\\/s/g, '#/components/schemas');\n\n current = collection.find((t) => t.id === part);\n if (!current) {\n throw new Error('Could not find type: ' + part + ' from ' + path + ', last: ' + last?.pathToRoot());\n }\n\n // make sure we expand it before we move on to the next part\n this.gen.expand(current);\n last = current;\n\n collection = Array.from(current!.children.values()) || Array.from(current!.props.values()) || [];\n\n stack.push(current);\n i++;\n } while (i < parts.length);\n\n return stack;\n }\n\n public collectExpandedPaths(selection: string[]) {\n const newSelection = new Set<string>();\n const expands = selection.filter((p) => p.endsWith('>**'));\n const filtered = expands.map((p) => p.replace('>**', ''));\n\n const paths = Array.from(this.gen.paths.values());\n const nodes = filtered.map((p) => this.collectPaths(p, paths));\n\n nodes.forEach((stack) => {\n const root = _.last(stack)!;\n T.traverse(root, (child) => {\n if (T.isPropScalar(child) || (child instanceof PropArray && child.items instanceof Scalar)) {\n newSelection.add(child.path());\n } else {\n this.gen.expand(child);\n }\n });\n });\n\n // finally remove the expanded paths from the selection\n return [...newSelection, ...selection.filter((p) => !expands.includes(p))];\n }\n\n public traverseTree(current: IType, selection: string[], pending: Map<string, IType>) {\n // we might be in a node far from the root, so we need to traverse upwards\n // as well and add the props that we can find on the way\n const source = current as Type;\n\n source\n .ancestors()\n .filter((t) => t instanceof Prop)\n .map((p) => PathCollector.findNonPropParent(p))\n .forEach((parent) => pending.set(parent.id, parent));\n\n T.traverse(source, (child) => {\n if (T.isLeaf(child)) {\n // this is a weird take but if the child is an array of scalars\n // then we want to avoid adding it twice\n if (T.isLeaf(child.parent!)) {\n return;\n }\n selection.push(child.path());\n\n const parentType = PathCollector.findNonPropParent(child);\n if (!pending.has(parentType.id)) {\n pending.set(parentType.id, parentType);\n }\n } else {\n this.gen.expand(child);\n\n if (child instanceof Composed) {\n child.consolidate(selection);\n }\n }\n });\n }\n}\n"]}