apollo-conn-gen 0.2.1 → 0.3.0

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 (86) hide show
  1. package/dist/cli/oas-helpers/index.js +5 -5
  2. package/dist/cli/oas-helpers/index.js.map +1 -1
  3. package/dist/cli/oas.js +5 -0
  4. package/dist/cli/oas.js.map +1 -1
  5. package/dist/oas/index.d.ts +2 -2
  6. package/dist/oas/index.js +2 -2
  7. package/dist/oas/index.js.map +1 -1
  8. package/dist/oas/io/writer.d.ts +1 -2
  9. package/dist/oas/io/writer.js +14 -17
  10. package/dist/oas/io/writer.js.map +1 -1
  11. package/dist/oas/nodes/arr.js +1 -1
  12. package/dist/oas/nodes/arr.js.map +1 -1
  13. package/dist/oas/nodes/body.js +3 -1
  14. package/dist/oas/nodes/body.js.map +1 -1
  15. package/dist/oas/nodes/circularRef.d.ts +1 -1
  16. package/dist/oas/nodes/circularRef.js.map +1 -1
  17. package/dist/oas/nodes/comp.d.ts +2 -0
  18. package/dist/oas/nodes/comp.js +44 -7
  19. package/dist/oas/nodes/comp.js.map +1 -1
  20. package/dist/oas/nodes/en.d.ts +1 -1
  21. package/dist/oas/nodes/en.js +3 -3
  22. package/dist/oas/nodes/en.js.map +1 -1
  23. package/dist/oas/nodes/factory.d.ts +6 -3
  24. package/dist/oas/nodes/factory.js +149 -105
  25. package/dist/oas/nodes/factory.js.map +1 -1
  26. package/dist/oas/nodes/iType.d.ts +2 -2
  27. package/dist/oas/nodes/iType.js.map +1 -1
  28. package/dist/oas/nodes/internal.d.ts +3 -3
  29. package/dist/oas/nodes/internal.js +3 -3
  30. package/dist/oas/nodes/internal.js.map +1 -1
  31. package/dist/oas/nodes/obj.d.ts +1 -1
  32. package/dist/oas/nodes/obj.js +35 -44
  33. package/dist/oas/nodes/obj.js.map +1 -1
  34. package/dist/oas/nodes/param.js +3 -1
  35. package/dist/oas/nodes/param.js.map +1 -1
  36. package/dist/oas/nodes/prop.d.ts +1 -1
  37. package/dist/oas/nodes/prop.js +4 -1
  38. package/dist/oas/nodes/prop.js.map +1 -1
  39. package/dist/oas/nodes/propArray.d.ts +2 -3
  40. package/dist/oas/nodes/propArray.js +12 -18
  41. package/dist/oas/nodes/propArray.js.map +1 -1
  42. package/dist/oas/nodes/propCircRef.d.ts +14 -0
  43. package/dist/oas/nodes/propCircRef.js +35 -0
  44. package/dist/oas/nodes/propCircRef.js.map +1 -0
  45. package/dist/oas/nodes/propComp.d.ts +1 -2
  46. package/dist/oas/nodes/propComp.js +4 -11
  47. package/dist/oas/nodes/propComp.js.map +1 -1
  48. package/dist/oas/nodes/propEn.d.ts +15 -0
  49. package/dist/oas/nodes/propEn.js +38 -0
  50. package/dist/oas/nodes/propEn.js.map +1 -0
  51. package/dist/oas/nodes/propObj.d.ts +1 -2
  52. package/dist/oas/nodes/propObj.js +3 -4
  53. package/dist/oas/nodes/propObj.js.map +1 -1
  54. package/dist/oas/nodes/propRef.d.ts +5 -4
  55. package/dist/oas/nodes/propRef.js +27 -21
  56. package/dist/oas/nodes/propRef.js.map +1 -1
  57. package/dist/oas/nodes/propScalar.d.ts +2 -3
  58. package/dist/oas/nodes/propScalar.js +10 -6
  59. package/dist/oas/nodes/propScalar.js.map +1 -1
  60. package/dist/oas/nodes/ref.d.ts +3 -0
  61. package/dist/oas/nodes/ref.js +8 -3
  62. package/dist/oas/nodes/ref.js.map +1 -1
  63. package/dist/oas/nodes/{response.d.ts → res.d.ts} +1 -1
  64. package/dist/oas/nodes/{response.js → res.js} +6 -4
  65. package/dist/oas/nodes/res.js.map +1 -0
  66. package/dist/oas/nodes/type.d.ts +2 -3
  67. package/dist/oas/nodes/type.js +3 -18
  68. package/dist/oas/nodes/type.js.map +1 -1
  69. package/dist/oas/nodes/typeUtils.d.ts +3 -0
  70. package/dist/oas/nodes/typeUtils.js +23 -4
  71. package/dist/oas/nodes/typeUtils.js.map +1 -1
  72. package/dist/oas/nodes/union.d.ts +0 -1
  73. package/dist/oas/nodes/union.js +61 -59
  74. package/dist/oas/nodes/union.js.map +1 -1
  75. package/dist/oas/oasContext.js +2 -5
  76. package/dist/oas/oasContext.js.map +1 -1
  77. package/dist/oas/oasGen.d.ts +1 -0
  78. package/dist/oas/oasGen.js +2 -1
  79. package/dist/oas/oasGen.js.map +1 -1
  80. package/dist/oas/prompts/prompt.js +11 -3
  81. package/dist/oas/prompts/prompt.js.map +1 -1
  82. package/dist/tests/runners.js +2 -2
  83. package/dist/tests/runners.js.map +1 -1
  84. package/dist/tsconfig.tsbuildinfo +1 -1
  85. package/package.json +1 -1
  86. package/dist/oas/nodes/response.js.map +0 -1
@@ -1,5 +1,4 @@
1
- import { IType } from './internal.js';
2
- import { Prop } from './internal.js';
1
+ import { IType, Prop } from './internal.js';
3
2
  import { SchemaObject } from 'oas/types';
4
3
  import { OasContext } from '../oasContext.js';
5
4
  import { Writer } from '../io/writer.js';
@@ -1,5 +1,4 @@
1
- import { Obj, Union } from './internal.js';
2
- import { Prop } from './internal.js';
1
+ import { Obj, Union, Prop } from './internal.js';
3
2
  import _ from 'lodash';
4
3
  import { trace } from '../log/trace.js';
5
4
  import { Composed } from './comp.js';
@@ -20,7 +19,7 @@ export class PropObj extends Prop {
20
19
  }
21
20
  }
22
21
  forPrompt(_context) {
23
- return _.lowerFirst(this.name) + ': ' + Naming.getRefName(this.obj.name) + ' (Obj)';
22
+ return '[prop] ' + _.lowerFirst(this.name) + ': ' + Naming.getRefName(this.obj.name) + ' (Obj)';
24
23
  }
25
24
  get id() {
26
25
  return 'prop:obj:' + this.name;
@@ -45,7 +44,7 @@ export class PropObj extends Prop {
45
44
  // compose for now.
46
45
  if (_.isEmpty(this.obj?.props))
47
46
  return 'JSON';
48
- return Naming.genTypeName(this.name);
47
+ return Naming.genTypeName(this.obj.name) + this.obj.nameSuffix();
49
48
  }
50
49
  select(context, writer, selection) {
51
50
  trace(context, '-> [prop-obj:select]', 'in ' + this.name + ', obj: ' + this.obj.name);
@@ -1 +1 @@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,KAAK,YAAY,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClH,CAAC;CACF","sourcesContent":["import { IType, Obj, Union } from './internal.js';\nimport { Prop } from './internal.js';\nimport _ from 'lodash';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { Composed } from './comp.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nexport class PropObj extends Prop {\n constructor(\n parent: IType,\n name: string,\n public schema: SchemaObject,\n public obj: IType,\n ) {\n super(parent, name, schema);\n if (!obj) {\n throw new Error('obj parameter is required');\n }\n\n // TODO: check if re-parenting is necessary?!?!\n if (obj.parent !== this) {\n obj.parent = this;\n }\n }\n\n public forPrompt(_context: OasContext): string {\n return _.lowerFirst(this.name) + ': ' + Naming.getRefName(this.obj.name) + ' (Obj)';\n }\n\n get id(): string {\n return 'prop:obj:' + this.name;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n trace(context, '-> [prop-obj:visit]', 'in ' + this.name + ', obj: ' + this.obj.name);\n\n this.obj.visit(context);\n if (!this.children.includes(this.obj)) {\n this.add(this.obj);\n }\n this.visited = true;\n\n trace(context, '<- [prop-obj:visit]', 'out ' + this.name + ', obj: ' + this.obj.name);\n context.leave(this);\n }\n\n public getValue(context: OasContext): string {\n // we'll make an assumption here: that if the child obj has no properties,\n // then it's a free-form JSON payload. not sure if the right one, but it will\n // compose for now.\n if (_.isEmpty(this.obj?.props)) return 'JSON';\n\n return Naming.genTypeName(this.name);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [prop-obj:select]', 'in ' + this.name + ', obj: ' + this.obj.name);\n\n const fieldName = this.name;\n const sanitised = Naming.sanitiseFieldForSelect(fieldName);\n\n writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);\n\n if (this.needsBrackets(this.obj!)) {\n writer.append(' {').append('\\n');\n context.enter(this);\n }\n\n for (const child of this.children) {\n child.select(context, writer, selection);\n }\n\n if (this.needsBrackets(this.obj!)) {\n context.leave(this);\n writer.append(' '.repeat(context.indent + context.stack.length)).append('}');\n }\n // writer.append('\\n');\n if (context.generateOptions.debugParentInSelection) {\n writer.append(' # ').append(Naming.getRefName(this.parent!.name));\n }\n\n writer.append('\\n');\n\n trace(context, '<- [prop-obj:select]', 'out ' + this.name + ', obj: ' + this.obj?.name);\n }\n\n private needsBrackets(child: IType): boolean {\n return (child instanceof Obj || child instanceof Union || child instanceof Composed) && !_.isEmpty(child.props);\n }\n}\n"]}
1
+ {"version":3,"file":"propObj.js","sourceRoot":"","sources":["../../../src/oas/nodes/propObj.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGrC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,OAAO,OAAQ,SAAQ,IAAI;IAItB;IACA;IAJT,YACE,MAAa,EACb,IAAY,EACL,MAAoB,EACpB,GAAU;QAEjB,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAHrB,WAAM,GAAN,MAAM,CAAc;QACpB,QAAG,GAAH,GAAG,CAAO;QAGjB,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,CAAC;QAED,+CAA+C;QAC/C,IAAI,GAAG,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YACxB,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC;QACpB,CAAC;IACH,CAAC;IAEM,SAAS,CAAC,QAAoB;Q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AE,CAAC;YACnD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,MAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEpB,KAAK,CAAC,OAAO,EAAE,sBAAsB,EAAE,MAAM,GAAG,IAAI,CAAC,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC1F,CAAC;IAEO,aAAa,CAAC,KAAY;QAChC,OAAO,CAAC,KAAK,YAAY,GAAG,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,YAAY,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClH,CAAC;CACF","sourcesContent":["import { IType, Obj, Union, Prop } from './internal.js';\nimport _ from 'lodash';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { Composed } from './comp.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nexport class PropObj extends Prop {\n constructor(\n parent: IType,\n name: string,\n public schema: SchemaObject,\n public obj: IType,\n ) {\n super(parent, name, schema);\n if (!obj) {\n throw new Error('obj parameter is required');\n }\n\n // TODO: check if re-parenting is necessary?!?!\n if (obj.parent !== this) {\n obj.parent = this;\n }\n }\n\n public forPrompt(_context: OasContext): string {\n return '[prop] ' + _.lowerFirst(this.name) + ': ' + Naming.getRefName(this.obj.name) + ' (Obj)';\n }\n\n get id(): string {\n return 'prop:obj:' + this.name;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n trace(context, '-> [prop-obj:visit]', 'in ' + this.name + ', obj: ' + this.obj.name);\n\n this.obj.visit(context);\n if (!this.children.includes(this.obj)) {\n this.add(this.obj);\n }\n this.visited = true;\n\n trace(context, '<- [prop-obj:visit]', 'out ' + this.name + ', obj: ' + this.obj.name);\n context.leave(this);\n }\n\n public getValue(context: OasContext): string {\n // we'll make an assumption here: that if the child obj has no properties,\n // then it's a free-form JSON payload. not sure if the right one, but it will\n // compose for now.\n if (_.isEmpty(this.obj?.props)) return 'JSON';\n\n return Naming.genTypeName(this.obj!.name!) + (this.obj as Obj).nameSuffix();\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [prop-obj:select]', 'in ' + this.name + ', obj: ' + this.obj.name);\n\n const fieldName = this.name;\n const sanitised = Naming.sanitiseFieldForSelect(fieldName);\n\n writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);\n\n if (this.needsBrackets(this.obj!)) {\n writer.append(' {').append('\\n');\n context.enter(this);\n }\n\n for (const child of this.children) {\n child.select(context, writer, selection);\n }\n\n if (this.needsBrackets(this.obj!)) {\n context.leave(this);\n writer.append(' '.repeat(context.indent + context.stack.length)).append('}');\n }\n // writer.append('\\n');\n if (context.generateOptions.debugParentInSelection) {\n writer.append(' # ').append(Naming.getRefName(this.parent!.name));\n }\n\n writer.append('\\n');\n\n trace(context, '<- [prop-obj:select]', 'out ' + this.name + ', obj: ' + this.obj?.name);\n }\n\n private needsBrackets(child: IType): boolean {\n return (child instanceof Obj || child instanceof Union || child instanceof Composed) && !_.isEmpty(child.props);\n }\n}\n"]}
@@ -1,19 +1,20 @@
1
1
  import { OasContext } from '../oasContext.js';
2
- import { IType } from './internal.js';
3
- import { Prop } from './internal.js';
2
+ import { Prop, IType } from './internal.js';
4
3
  import { SchemaObject } from 'oas/types';
5
4
  import { Writer } from '../io/writer.js';
5
+ /**
6
+ * @deprecated No longer used
7
+ */
6
8
  export declare class PropRef extends Prop {
7
9
  schema: SchemaObject;
8
10
  ref: string;
9
11
  get id(): string;
10
12
  refType?: IType;
11
13
  constructor(parent: IType | undefined, name: string, schema: SchemaObject, ref: string);
12
- add(child: IType): void;
13
14
  visit(context: OasContext): void;
14
15
  getValue(_context: OasContext): string;
15
16
  forPrompt(context: OasContext): string;
16
17
  select(context: OasContext, writer: Writer, selection: string[]): void;
17
- protected generateValue(context: OasContext, writer: Writer): void;
18
+ generateValue(context: OasContext, writer: Writer): void;
18
19
  private needsBrackets;
19
20
  }
@@ -1,8 +1,10 @@
1
- import { Arr, CircularRef, Composed, Factory, Obj, Union } from './internal.js';
2
- import { Prop } from './internal.js';
1
+ import { Arr, Prop, Composed, Factory, Obj, Union } from './internal.js';
3
2
  import _ from 'lodash';
4
3
  import { trace } from '../log/trace.js';
5
4
  import { Naming } from '../utils/naming.js';
5
+ /**
6
+ * @deprecated No longer used
7
+ */
6
8
  export class PropRef extends Prop {
7
9
  schema;
8
10
  ref;
@@ -15,22 +17,25 @@ export class PropRef extends Prop {
15
17
  this.schema = schema;
16
18
  this.ref = ref;
17
19
  }
18
- add(child) {
19
- child.name = this.ref;
20
- const paths = this.ancestors();
21
- const contains = paths.map((p) => p.id).includes(child.id);
22
- trace(null, '-> [prop-ref:add]', 'contains child? ' + contains);
23
- if (contains) {
24
- const ancestor = paths[paths.map((p) => p.id).indexOf(child.id)];
25
- const wrapper = Factory.fromCircularRef(this, ancestor);
26
- super.add(wrapper);
27
- this.visited = true;
28
- this.refType = wrapper;
29
- }
30
- else {
31
- super.add(child);
32
- }
33
- }
20
+ /* public override add(child: IType): IType {
21
+ child.name = this.ref;
22
+ const paths: IType[] = this.ancestors();
23
+ const contains: boolean = paths.map((p) => p.id).includes(child.id);
24
+
25
+ trace(null, '-> [prop-ref:add]', 'contains child? ' + contains);
26
+ let added: IType = child;
27
+ if (contains) {
28
+ const ancestor: IType = paths[paths.map((p) => p.id).indexOf(child.id)];
29
+ const wrapper = Factory.fromCircularRef(this, ancestor);
30
+ added = super.add(wrapper);
31
+ this.visited = true;
32
+ this.refType = wrapper;
33
+ } else {
34
+ added = super.add(child);
35
+ }
36
+
37
+ return added;
38
+ }*/
34
39
  visit(context) {
35
40
  if (this.visited) {
36
41
  return;
@@ -41,8 +46,9 @@ export class PropRef extends Prop {
41
46
  if (!schema) {
42
47
  throw new Error('Schema not found for ref: ' + this.ref);
43
48
  }
44
- const type = Factory.fromSchema(this, schema);
49
+ const type = Factory.fromSchema(context, this, schema);
45
50
  if (!this.refType) {
51
+ this.add(type);
46
52
  this.refType = type;
47
53
  type.name = this.ref;
48
54
  type.visit(context);
@@ -60,7 +66,7 @@ export class PropRef extends Prop {
60
66
  return Naming.genTypeName(name) + this.nameSuffix();
61
67
  }
62
68
  forPrompt(context) {
63
- return `${this.name}: ${Naming.getRefName(this.ref)} (Ref)`;
69
+ return `[prop] ${this.name}: ${Naming.getRefName(this.ref)} (Ref)`;
64
70
  }
65
71
  select(context, writer, selection) {
66
72
  trace(context, '-> [prop-ref:select]', 'in ' + this.name + ', ref: ' + this.ref);
@@ -97,7 +103,7 @@ export class PropRef extends Prop {
97
103
  if (child instanceof Arr) {
98
104
  return this.needsBrackets(child.itemsType);
99
105
  }
100
- return child instanceof Obj || child instanceof Union || child instanceof Composed || child instanceof CircularRef;
106
+ return child instanceof Obj || child instanceof Union || child instanceof Composed;
101
107
  }
102
108
  }
103
109
  //# sourceMappingURL=propRef.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"propRef.js","sourceRoot":"","sources":["../../../src/oas/nodes/propRef.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAS,GAAG,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACvF,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,OAAO,OAAQ,SAAQ,IAAI;IAStB;IACA;IATT,IAAI,EAAE;QACJ,OAAO,aAAa,IAAI,CAAC,IAAI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AC,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC/E,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpB,KAAK,CAAC,OAAO,EAAE,sBAAsB,EAAE,MAAM,GAAG,IAAI,CAAC,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACpF,CAAC;IAES,aAAa,CAAC,OAAmB,EAAE,MAAc;QACzD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC;QAE1B,IAAI,IAAI,IAAK,IAAc,YAAY,GAAG,EAAE,CAAC;YAC3C,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACnB,MAAM,KAAK,GAAI,IAAY,CAAC,SAAS,CAAC;YACtC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,KAAM,CAAC,IAAI,CAAC,CAAC,CAAC;YACzC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAEO,aAAa,CAAC,KAAY;QAChC,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,SAAU,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,KAAK,YAAY,GAAG,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,YAAY,QAAQ,IAAI,KAAK,YAAY,WAAW,CAAC;IACrH,CAAC;CACF","sourcesContent":["import { OasContext } from '../oasContext.js';\nimport { Arr, CircularRef, Composed, Factory, IType, Obj, Union } from './internal.js';\nimport { Prop } from './internal.js';\nimport _ from 'lodash';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nexport class PropRef extends Prop {\n get id(): string {\n return `prop:ref:#${this.name}`;\n }\n public refType?: IType;\n\n constructor(\n parent: IType | undefined,\n name: string,\n public schema: SchemaObject,\n public ref: string,\n ) {\n super(parent, name, schema);\n }\n\n public override add(child: IType): void {\n child.name = this.ref;\n const paths: IType[] = this.ancestors();\n const contains: boolean = paths.map((p) => p.id).includes(child.id);\n\n trace(null, '-> [prop-ref:add]', 'contains child? ' + contains);\n if (contains) {\n const ancestor: IType = paths[paths.map((p) => p.id).indexOf(child.id)];\n const wrapper = Factory.fromCircularRef(this, ancestor);\n super.add(wrapper);\n this.visited = true;\n this.refType = wrapper;\n } else {\n super.add(child);\n }\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n context.enter(this);\n trace(context, '-> [prop-ref:visit]', 'in ' + this.name + ', ref: ' + this.ref);\n\n const schema = context.lookupRef(this.ref);\n if (!schema) {\n throw new Error('Schema not found for ref: ' + this.ref);\n }\n\n const type = Factory.fromSchema(this, schema);\n if (!this.refType) {\n this.refType = type;\n type.name = this.ref;\n type.visit(context);\n\n if (!this.children.includes(this.refType!)) {\n this.add(this.refType!);\n }\n\n this.visited = true;\n }\n trace(context, '<- [prop-ref:visit]', 'out ' + this.name + ', ref: ' + this.ref);\n context.leave(this);\n }\n\n public getValue(_context: OasContext): string {\n const type = this.refType!;\n const name = type ? type.name : this.ref;\n\n return Naming.genTypeName(name!) + this.nameSuffix();\n }\n\n public forPrompt(context: OasContext): string {\n return `${this.name}: ${Naming.getRefName(this.ref)} (Ref)`;\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [prop-ref:select]', 'in ' + this.name + ', ref: ' + this.ref);\n const fieldName = this.name;\n const sanitised = Naming.sanitiseFieldForSelect(fieldName);\n writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);\n\n if (this.refType && this.needsBrackets(this.refType)) {\n writer.append(' {').append('\\n');\n context.enter(this);\n }\n\n for (const child of this.children) {\n child.select(context, writer, selection);\n }\n\n if (this.refType && this.needsBrackets(this.refType)) {\n context.leave(this);\n writer.append(' '.repeat(context.indent + context.stack.length)).append('}');\n }\n\n writer.append('\\n');\n trace(context, '<- [prop-ref:select]', 'out ' + this.name + ', ref: ' + this.ref);\n }\n\n protected generateValue(context: OasContext, writer: Writer): void {\n const type = this.refType;\n\n if (type && (type as IType) instanceof Arr) {\n writer.append('[');\n const items = (type as Arr).itemsType;\n writer.append(_.upperFirst(items!.name));\n writer.append(']');\n } else {\n writer.append(this.getValue(context));\n }\n }\n\n private needsBrackets(child: IType): boolean {\n if (child instanceof Arr) {\n return this.needsBrackets(child.itemsType!);\n }\n return child instanceof Obj || child instanceof Union || child instanceof Composed || child instanceof CircularRef;\n }\n}\n"]}
1
+ {"version":3,"file":"propRef.js","sourceRoot":"","sources":["../../../src/oas/nodes/propRef.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAS,GAAG,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,OAAQ,SAAQ,IAAI;IAStB;IACA;IATT,IAAI,EAAE;QACJ,OAAO,aAAa,IAAI,CAAC,IAAI,EAAE,CAAC;IAClC,CAAC;IACM,OAAO,CAAS;IAEvB,YACE,MAAyB,EACzB,IAAY,EACL,MAAoB,EACpB,GAAW;QAElB,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAHrB,WAAM,GAAN,MAAM,CAAc;QACpB,QAAG,GAAH,GAAG,CAAQ;IAGpB,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IAEI,KAAK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import { OasContext } from '../oasContext.js';\nimport { Arr, Prop, Composed, Factory, IType, Obj, Union } from './internal.js';\nimport _ from 'lodash';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\n/**\n * @deprecated No longer used\n */\nexport class PropRef extends Prop {\n get id(): string {\n return `prop:ref:#${this.name}`;\n }\n public refType?: IType;\n\n constructor(\n parent: IType | undefined,\n name: string,\n public schema: SchemaObject,\n public ref: string,\n ) {\n super(parent, name, schema);\n }\n\n /* public override add(child: IType): IType {\n child.name = this.ref;\n const paths: IType[] = this.ancestors();\n const contains: boolean = paths.map((p) => p.id).includes(child.id);\n\n trace(null, '-> [prop-ref:add]', 'contains child? ' + contains);\n let added: IType = child;\n if (contains) {\n const ancestor: IType = paths[paths.map((p) => p.id).indexOf(child.id)];\n const wrapper = Factory.fromCircularRef(this, ancestor);\n added = super.add(wrapper);\n this.visited = true;\n this.refType = wrapper;\n } else {\n added = super.add(child);\n }\n\n return added;\n }*/\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n context.enter(this);\n trace(context, '-> [prop-ref:visit]', 'in ' + this.name + ', ref: ' + this.ref);\n\n const schema = context.lookupRef(this.ref);\n if (!schema) {\n throw new Error('Schema not found for ref: ' + this.ref);\n }\n\n const type = Factory.fromSchema(context, this, schema);\n if (!this.refType) {\n this.add(type);\n this.refType = type;\n type.name = this.ref;\n type.visit(context);\n\n if (!this.children.includes(this.refType!)) {\n this.add(this.refType!);\n }\n\n this.visited = true;\n }\n trace(context, '<- [prop-ref:visit]', 'out ' + this.name + ', ref: ' + this.ref);\n context.leave(this);\n }\n\n public getValue(_context: OasContext): string {\n const type = this.refType!;\n const name = type ? type.name : this.ref;\n\n return Naming.genTypeName(name!) + this.nameSuffix();\n }\n\n public forPrompt(context: OasContext): string {\n return `[prop] ${this.name}: ${Naming.getRefName(this.ref)} (Ref)`;\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [prop-ref:select]', 'in ' + this.name + ', ref: ' + this.ref);\n const fieldName = this.name;\n const sanitised = Naming.sanitiseFieldForSelect(fieldName);\n writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);\n\n if (this.refType && this.needsBrackets(this.refType)) {\n writer.append(' {').append('\\n');\n context.enter(this);\n }\n\n for (const child of this.children) {\n child.select(context, writer, selection);\n }\n\n if (this.refType && this.needsBrackets(this.refType)) {\n context.leave(this);\n writer.append(' '.repeat(context.indent + context.stack.length)).append('}');\n }\n\n writer.append('\\n');\n trace(context, '<- [prop-ref:select]', 'out ' + this.name + ', ref: ' + this.ref);\n }\n\n generateValue(context: OasContext, writer: Writer): void {\n const type = this.refType;\n\n if (type && (type as IType) instanceof Arr) {\n writer.append('[');\n const items = (type as Arr).itemsType;\n writer.append(_.upperFirst(items!.name));\n writer.append(']');\n } else {\n writer.append(this.getValue(context));\n }\n }\n\n private needsBrackets(child: IType): boolean {\n if (child instanceof Arr) {\n return this.needsBrackets(child.itemsType!);\n }\n return child instanceof Obj || child instanceof Union || child instanceof Composed;\n }\n}\n"]}
@@ -1,5 +1,4 @@
1
- import { IType } from './internal.js';
2
- import { Prop } from './internal.js';
1
+ import { IType, Prop } from './internal.js';
3
2
  import { SchemaObject } from 'oas/types';
4
3
  import { OasContext } from '../oasContext.js';
5
4
  import { Writer } from '../io/writer.js';
@@ -10,7 +9,7 @@ export declare class PropScalar extends Prop {
10
9
  constructor(parent: IType, name: string, type: string, schema: SchemaObject);
11
10
  get id(): string;
12
11
  visit(context: OasContext): void;
13
- getValue(context: OasContext): string;
12
+ getValue(_context: OasContext): string;
14
13
  forPrompt(context: OasContext): string;
15
14
  select(context: OasContext, writer: Writer, selection: string[]): void;
16
15
  }
@@ -1,5 +1,4 @@
1
- import { Factory } from './internal.js';
2
- import { Prop } from './internal.js';
1
+ import { Factory, Prop } from './internal.js';
3
2
  import { trace } from '../log/trace.js';
4
3
  import { Naming } from '../utils/naming.js';
5
4
  export class PropScalar extends Prop {
@@ -20,17 +19,22 @@ export class PropScalar extends Prop {
20
19
  }
21
20
  context.enter(this);
22
21
  if (!this.propType) {
23
- this.propType = Factory.fromSchema(this, this.schema);
24
- // this.propType.visit(context);
22
+ const type = Factory.fromSchema(context, this, this.schema);
23
+ this.add(type);
24
+ this.propType = type;
25
25
  this.visited = true;
26
26
  }
27
27
  context.leave(this);
28
28
  }
29
- getValue(context) {
29
+ getValue(_context) {
30
30
  return this.type;
31
31
  }
32
32
  forPrompt(context) {
33
- return `${this.name}: ${this.type}`;
33
+ let result = `[prop] ${this.name}: ${this.type}`;
34
+ if (context.generateOptions.debugParentInSelection) {
35
+ result = result + ` (${Naming.getRefName(this.parent.name)})`;
36
+ }
37
+ return result;
34
38
  }
35
39
  select(context, writer, selection) {
36
40
  trace(context, ' [prop:select]', this.name);
@@ -1 +1 @@
1
- {"version":3,"file":"propScalar.js","sourceRoot":"","sources":["../../../src/oas/nodes/propScalar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,OAAO,UAAW,SAAQ,IAAI;IAMzB;IACA;IAND,QAAQ,CAAS;IAEzB,YACE,MAAa,EACb,IAAY,EACL,IAAY,EACZ,MAAoB;QAE3B,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAHrB,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAc;IAG7B,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,eAAe,IAAI,CAAC,IAAI,EAAE,CAAC;IACpC,CAAC;IAEM,KAAK,CAAC,OAAmB;QAC9B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;Y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,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;CACF","sourcesContent":["import { Factory, IType } from './internal.js';\nimport { Prop } from './internal.js';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nexport class PropScalar extends Prop {\n private propType?: IType;\n\n constructor(\n parent: IType,\n name: string,\n public type: string,\n public schema: SchemaObject,\n ) {\n super(parent, name, schema);\n }\n\n get id(): string {\n return `prop:scalar:${this.name}`;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n if (!this.propType) {\n this.propType = Factory.fromSchema(this, this.schema);\n // this.propType.visit(context);\n this.visited = true;\n }\n context.leave(this);\n }\n\n public getValue(context: OasContext): string {\n return this.type;\n }\n\n public forPrompt(context: OasContext): string {\n return `${this.name}: ${this.type}`;\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, ' [prop:select]', this.name);\n const sanitised = Naming.sanitiseFieldForSelect(this.name);\n writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);\n\n for (const child of this.children) {\n child.select(context, writer, selection);\n }\n\n if (context.generateOptions.debugParentInSelection) {\n writer.append(' # ').append(Naming.getRefName(this.parent!.name));\n }\n\n writer.append('\\n');\n }\n}\n"]}
1
+ {"version":3,"file":"propScalar.js","sourceRoot":"","sources":["../../../src/oas/nodes/propScalar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,IAAI,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,OAAO,UAAW,SAAQ,IAAI;IAMzB;IACA;IAND,QAAQ,CAAS;IAEzB,YACE,MAAa,EACb,IAAY,EACL,IAAY,EACZ,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,CAAC;QAC9C,MAAM,SAAS,GAAG,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3D,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAEnF,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QAC3C,CAAC;QAED,IAAI,OAAO,CAAC,eAAe,CAAC,sBAAsB,EAAE,CAAC;YACnD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,MAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;CACF","sourcesContent":["import { Factory, IType, Prop } from './internal.js';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nexport class PropScalar extends Prop {\n private propType?: IType;\n\n constructor(\n parent: IType,\n name: string,\n public type: string,\n public schema: SchemaObject,\n ) {\n super(parent, name, schema);\n }\n\n get id(): string {\n return `prop:scalar:${this.name}`;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n if (!this.propType) {\n const type = Factory.fromSchema(context, this, this.schema);\n this.add(type);\n this.propType = type;\n this.visited = true;\n }\n context.leave(this);\n }\n\n public getValue(_context: OasContext): string {\n return this.type;\n }\n\n public forPrompt(context: OasContext): string {\n let result = `[prop] ${this.name}: ${this.type}`;\n\n if (context.generateOptions.debugParentInSelection) {\n result = result + ` (${Naming.getRefName(this.parent!.name)})`;\n }\n\n return result;\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, ' [prop:select]', this.name);\n const sanitised = Naming.sanitiseFieldForSelect(this.name);\n writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);\n\n for (const child of this.children) {\n child.select(context, writer, selection);\n }\n\n if (context.generateOptions.debugParentInSelection) {\n writer.append(' # ').append(Naming.getRefName(this.parent!.name));\n }\n\n writer.append('\\n');\n }\n}\n"]}
@@ -2,6 +2,9 @@ import { IType, Prop, Type } from './internal.js';
2
2
  import { OasContext } from '../oasContext.js';
3
3
  import { Writer } from '../io/writer.js';
4
4
  import { ReferenceObject } from './referenceObject.js';
5
+ /**
6
+ * @deprecated This class is deprecated and should not be used in new code.
7
+ */
5
8
  export declare class Ref extends Type {
6
9
  schema: ReferenceObject | null;
7
10
  refType?: IType;
@@ -1,6 +1,9 @@
1
1
  import { Arr, Factory, Type } from './internal.js';
2
2
  import { trace } from '../log/trace.js';
3
3
  import { Naming } from '../utils/naming.js';
4
+ /**
5
+ * @deprecated This class is deprecated and should not be used in new code.
6
+ */
4
7
  export class Ref extends Type {
5
8
  schema;
6
9
  refType;
@@ -15,7 +18,7 @@ export class Ref extends Type {
15
18
  return this.refType?.props ?? new Map();
16
19
  }
17
20
  forPrompt(_context) {
18
- return `${Naming.getRefName(this.name)} (Ref)`;
21
+ return `[ref] ${Naming.getRefName(this.name)}`;
19
22
  }
20
23
  visit(context) {
21
24
  // console.log('schema', this.schema);
@@ -29,7 +32,9 @@ export class Ref extends Type {
29
32
  if (!schema) {
30
33
  throw new Error('Schema not found for ref: ' + ref);
31
34
  }
32
- this.refType = Factory.fromSchema(this, schema);
35
+ const type = Factory.fromSchema(context, this, schema);
36
+ this.add(type);
37
+ this.refType = type;
33
38
  // Set the name of the resolved type to the reference string.
34
39
  this.refType.name = ref;
35
40
  this.refType.visit(context);
@@ -42,7 +47,7 @@ export class Ref extends Type {
42
47
  trace(context, '-> [ref::generate]', `-> in: ${this.name}`);
43
48
  // If we're in a Response context and the resolved type is an Arr,
44
49
  // generate it with array notation.
45
- if (context.inContextOf('Response', this) && this.refType instanceof Arr) {
50
+ if (context.inContextOf('Res', this) && this.refType instanceof Arr) {
46
51
  writer.append('[').append(this.firstChild().name).append(']');
47
52
  }
48
53
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/oas/nodes/ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAe,IAAI,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAI5C,MAAM,OAAO,GAAI,SAAQ,IAAI;IAMlB;IALF,OAAO,CAAS;IAEvB,YACE,MAAyB,EACzB,IAAY,EACL,MAA8B;QAErC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAFb,WAAM,GAAN,MAAM,CAAwB;IAGvC,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC;IACpC,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,OAAO,EAAE,KAAK,IAAI,IAAI,GAAG,EAAE,CAAC;IAC1C,CAAC;IAEM,SAAS,CAAC,QAAoB;QACnC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;IACjD,CAAC;IAEM,KAAK,CAAC,OAAmB;QAC9B,sCAAsC;QACtC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO;QACT,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;QAEpC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpB,KAAK,CAAC,OAAO,EAAE,gB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U,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC7C,MAAM,CAAC,KAAK,CAAC,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC5D,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,oBAAoB,EAAE,WAAW,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7D,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAEM,MAAM,CAAC,OAAmB,EAAE,MAAc,EAAE,SAAmB;QACpE,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,UAAU,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1D,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QAClD,CAAC;QACD,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,WAAW,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;IAEO,UAAU;QAChB,OAAO,IAAI,CAAC,OAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;CACF","sourcesContent":["import { Arr, Factory, IType, Prop, Type } from './internal.js';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nimport { ReferenceObject } from './referenceObject.js';\n\nexport class Ref extends Type {\n public refType?: IType;\n\n constructor(\n parent: IType | undefined,\n name: string,\n public schema: ReferenceObject | null,\n ) {\n super(parent, name);\n }\n\n get id(): string {\n return 'ref:' + this.schema?.$ref;\n }\n\n get props(): Map<string, Prop> {\n return this.refType?.props ?? new Map();\n }\n\n public forPrompt(_context: OasContext): string {\n return `${Naming.getRefName(this.name)} (Ref)`;\n }\n\n public visit(context: OasContext): void {\n // console.log('schema', this.schema);\n if (this.visited) {\n return;\n }\n const ref = this.schema?.$ref ?? '';\n\n context.enter(this);\n trace(context, '-> [ref:visit]', 'in: ' + ref);\n\n const schema: SchemaObject | null = context.lookupRef(ref);\n if (!schema) {\n throw new Error('Schema not found for ref: ' + ref);\n }\n\n this.refType = Factory.fromSchema(this, schema);\n // Set the name of the resolved type to the reference string.\n this.refType.name = ref;\n this.refType.visit(context);\n\n this.visited = true;\n trace(context, '<- [ref:visit]', 'out: ' + ref);\n context.leave(this);\n }\n\n public generate(context: OasContext, writer: Writer, _selection: string[]): void {\n context.enter(this);\n trace(context, '-> [ref::generate]', `-> in: ${this.name}`);\n\n // If we're in a Response context and the resolved type is an Arr,\n // generate it with array notation.\n if (context.inContextOf('Response', this) && this.refType instanceof Arr) {\n writer.append('[').append(this.firstChild().name).append(']');\n } else {\n // Rewrite terrible names to something more sensible.\n const sanitised = Naming.genTypeName(this.name);\n const refName = Naming.getRefName(this.name);\n writer.write(sanitised === refName ? refName : sanitised);\n }\n\n trace(context, '<- [ref::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [ref::select]', `-> in: ${this.name}`);\n if (this.refType) {\n this.refType.select(context, writer, selection);\n }\n trace(context, '<- [ref::select]', `-> out: ${this.name}`);\n }\n\n private firstChild() {\n return this.refType!.children[0];\n }\n}\n"]}
1
+ {"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/oas/nodes/ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAe,IAAI,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAI5C;;GAEG;AACH,MAAM,OAAO,GAAI,SAAQ,IAAI;IAMlB;IALF,OAAO,CAAS;IAEvB,YACE,MAAyB,EACzB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AI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QAClD,CAAC;QACD,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,WAAW,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;IAEO,UAAU;QAChB,OAAO,IAAI,CAAC,OAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;CACF","sourcesContent":["import { Arr, Factory, IType, Prop, Type } from './internal.js';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nimport { ReferenceObject } from './referenceObject.js';\n\n/**\n * @deprecated This class is deprecated and should not be used in new code.\n */\nexport class Ref extends Type {\n public refType?: IType;\n\n constructor(\n parent: IType | undefined,\n name: string,\n public schema: ReferenceObject | null,\n ) {\n super(parent, name);\n }\n\n get id(): string {\n return 'ref:' + this.schema?.$ref;\n }\n\n get props(): Map<string, Prop> {\n return this.refType?.props ?? new Map();\n }\n\n public forPrompt(_context: OasContext): string {\n return `[ref] ${Naming.getRefName(this.name)}`;\n }\n\n public visit(context: OasContext): void {\n // console.log('schema', this.schema);\n if (this.visited) {\n return;\n }\n const ref = this.schema?.$ref ?? '';\n\n context.enter(this);\n trace(context, '-> [ref:visit]', 'in: ' + ref);\n\n const schema: SchemaObject | null = context.lookupRef(ref);\n if (!schema) {\n throw new Error('Schema not found for ref: ' + ref);\n }\n\n const type = Factory.fromSchema(context, this, schema);\n this.add(type);\n this.refType = type;\n // Set the name of the resolved type to the reference string.\n this.refType.name = ref;\n this.refType.visit(context);\n\n this.visited = true;\n trace(context, '<- [ref:visit]', 'out: ' + ref);\n context.leave(this);\n }\n\n public generate(context: OasContext, writer: Writer, _selection: string[]): void {\n context.enter(this);\n trace(context, '-> [ref::generate]', `-> in: ${this.name}`);\n\n // If we're in a Response context and the resolved type is an Arr,\n // generate it with array notation.\n if (context.inContextOf('Res', this) && this.refType instanceof Arr) {\n writer.append('[').append(this.firstChild().name).append(']');\n } else {\n // Rewrite terrible names to something more sensible.\n const sanitised = Naming.genTypeName(this.name);\n const refName = Naming.getRefName(this.name);\n writer.write(sanitised === refName ? refName : sanitised);\n }\n\n trace(context, '<- [ref::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [ref::select]', `-> in: ${this.name}`);\n if (this.refType) {\n this.refType.select(context, writer, selection);\n }\n trace(context, '<- [ref::select]', `-> out: ${this.name}`);\n }\n\n private firstChild() {\n return this.refType!.children[0];\n }\n}\n"]}
@@ -2,7 +2,7 @@ import { IType, Type } from './internal.js';
2
2
  import { SchemaObject } from 'oas/types';
3
3
  import { OasContext } from '../oasContext.js';
4
4
  import { Writer } from '../io/writer.js';
5
- export declare class Response extends Type {
5
+ export declare class Res extends Type {
6
6
  schema: SchemaObject;
7
7
  response?: IType;
8
8
  constructor(parent: IType, name: string, schema: SchemaObject, response?: IType);
@@ -1,6 +1,6 @@
1
1
  import { Factory, Type, T } from './internal.js';
2
2
  import { trace } from '../log/trace.js';
3
- export class Response extends Type {
3
+ export class Res extends Type {
4
4
  schema;
5
5
  response;
6
6
  constructor(parent, name, schema, response) {
@@ -18,8 +18,10 @@ export class Response extends Type {
18
18
  }
19
19
  context.enter(this);
20
20
  trace(context, '-> [res:visit]', 'in ' + this.name);
21
- this.response = Factory.fromSchema(this, this.schema);
22
- trace(context, ' [res:visit]', 'array type: ' + this.response.id);
21
+ const type = Factory.fromSchema(context, this, this.schema);
22
+ this.add(type);
23
+ this.response = type;
24
+ trace(context, ' [res:visit]', 'response type: ' + this.response.id);
23
25
  this.visited = true;
24
26
  trace(context, '<- [res:visit]', 'out ' + this.name);
25
27
  context.leave(this);
@@ -52,4 +54,4 @@ export class Response extends Type {
52
54
  trace(context, '<- [res:select]', `-> out: ${this.parent.name}`);
53
55
  }
54
56
  }
55
- //# sourceMappingURL=response.js.map
57
+ //# sourceMappingURL=res.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"res.js","sourceRoot":"","sources":["../../../src/oas/nodes/res.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,IAAI,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAIxC,MAAM,OAAO,GAAI,SAAQ,IAAI;IACpB,MAAM,CAAe;IACrB,QAAQ,CAAS;IAExB,YAAY,MAAa,EAAE,IAAY,EAAE,MAAoB,EAAE,QAAgB;QAC7E,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,OAAmB;QAC9B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC,CAAC;YAClE,OAAO;QACT,CAAC;QAED,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpB,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpD,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5D,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAEf,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,iB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C,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC1D,CAAC;;gBAAM,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QACrD,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,iBAAiB,EAAE,WAAW,IAAI,CAAC,MAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACpE,CAAC;CACF","sourcesContent":["import { Factory, IType, Type, T } from './internal.js';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\n\nexport class Res extends Type {\n public schema: SchemaObject;\n public response?: IType;\n\n constructor(parent: IType, name: string, schema: SchemaObject, response?: IType) {\n super(parent, name);\n this.schema = schema;\n this.response = response;\n }\n\n get id(): string {\n return 'res:' + this.name;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n trace(context, '-> [res:visit]', this.name + ' already visited.');\n return;\n }\n\n context.enter(this);\n trace(context, '-> [res:visit]', 'in ' + this.name);\n\n const type = Factory.fromSchema(context, this, this.schema);\n this.add(type);\n\n this.response = type;\n trace(context, ' [res:visit]', 'response type: ' + this.response.id);\n\n this.visited = true;\n trace(context, '<- [res:visit]', 'out ' + this.name);\n context.leave(this);\n }\n\n public forPrompt(context: OasContext): string {\n return 'Response';\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n context.enter(this);\n trace(context, '-> [res:generate]', `-> in: ${this.parent!.name}`);\n\n if (this.response) {\n this.response.generate(context, writer, selection);\n }\n\n trace(context, '<- [res:generate]', `-> out: ${this.parent!.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]): void {\n trace(context, '-> [res:select]', `-> in: ${this.parent!.name}`);\n\n const response = this.response;\n if (response) {\n if (T.isScalar(response)) {\n // best attempt to just copy the value that comes out of the service. most likely the\n // value will have to be replaced by a GQL type. In fact, we could potentially use SYN_ here but\n // it will have to do for now.\n writer.append(' '.repeat(context.indent)).append('$\\n');\n } else response.select(context, writer, selection);\n }\n\n trace(context, '<- [res:select]', `-> out: ${this.parent!.name}`);\n }\n}\n"]}
@@ -1,7 +1,6 @@
1
- import { IType, Kind } from './internal.js';
1
+ import { IType, Kind, Prop } from './internal.js';
2
2
  import { OasContext } from '../oasContext.js';
3
3
  import { Writer } from '../io/writer.js';
4
- import { Prop } from './internal.js';
5
4
  export declare abstract class Type implements IType {
6
5
  parent?: IType;
7
6
  name: string;
@@ -22,7 +21,7 @@ export declare abstract class Type implements IType {
22
21
  ancestors(): IType[];
23
22
  path(): string;
24
23
  pathToRoot(): string;
25
- add(child: IType): void;
24
+ add(child: IType): IType;
26
25
  selectedProps(selection: string[]): Prop[];
27
26
  nameSuffix(): string;
28
27
  }
@@ -74,34 +74,19 @@ export class Type {
74
74
  add(child) {
75
75
  const paths = this.ancestors();
76
76
  const contains = paths.map((p) => p.id).includes(child.id);
77
+ let pushed = child;
77
78
  if (contains) {
78
79
  trace(null, '-> [type:add]', 'already contains child: ' + child.id);
79
80
  const ancestor = paths[paths.map((p) => p.id).indexOf(child.id)];
80
81
  const wrapper = Factory.fromCircularRef(this, ancestor);
81
82
  this.children.push(wrapper);
83
+ pushed = wrapper;
82
84
  }
83
85
  else {
84
86
  this.children.push(child);
85
87
  }
88
+ return pushed;
86
89
  }
87
- /*
88
- remove = (value: IType): void => {
89
- const index = this.children.findIndex(child => child === value);
90
- if (index !== -1) {
91
- this.children.splice(index, 1);
92
- }
93
- };
94
-
95
- */
96
- /*traverseB(callback: (node: IType) => void): void {
97
- const queue: IType[] = [this];
98
-
99
- while (queue.length > 0) {
100
- const node = queue.shift()!;
101
- callback(node);
102
- queue.push(...node.children);
103
- }
104
- }*/
105
90
  selectedProps(selection) {
106
91
  return Array.from(this.props.values()).filter((prop) => selection.find((s) => s.startsWith(prop.path())));
107
92
  }
@@ -1 +1 @@
1
- {"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/oas/nodes/type.ts"],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AC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC5G,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9C,CAAC;CACF","sourcesContent":["import { IType, Kind } from './internal.js';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Factory } from './factory.js';\nimport { Prop } from './internal.js';\n\nexport abstract class Type implements IType {\n public parent?: IType;\n public name: string;\n public children: IType[];\n public circularRef?: IType;\n public kind: Kind;\n public visited: boolean;\n\n private readonly _props: Map<string, Prop>;\n\n protected constructor(parent: IType | undefined, name: string) {\n this.parent = parent;\n this.name = name;\n this.children = [];\n this.visited = false;\n this._props = new Map<string, Prop>();\n this.kind = parent?.kind || 'type';\n }\n\n public abstract visit(context: OasContext): void;\n\n public abstract forPrompt(context: OasContext): string;\n\n public abstract select(context: OasContext, writer: Writer, selection: string[]): void;\n\n public find(path: string, collection: IType[]): IType | boolean {\n const parts = path.split('>');\n let current: IType | undefined;\n\n let i = 0;\n do {\n const part = parts[i];\n\n current = collection.find((t) => t.id === part);\n if (!current) {\n return false;\n }\n\n collection = Array.from(current!.children.values()) || Array.from(current!.props.values()) || [];\n // console.log(\"found\", current);\n\n i++;\n } while (i < parts.length);\n\n return current || false;\n }\n\n public expand(context: OasContext): IType[] {\n trace(context, '-> [expand]', `in: path: ${this.path()}`);\n if (!this.visited) {\n this.visit(context);\n }\n\n trace(context, '<- [expand]', `out: path: ${this.path()}`);\n\n // TODO:\n // if ((type instanceof Composed || type instanceof Union) && !type.getProps().isEmpty()) {\n // return type.props?.values() || [];\n // }\n // else {\n return this.children;\n // }\n }\n\n public abstract generate(context: OasContext, writer: Writer, selection: string[]): void;\n\n get id() {\n return this.name;\n }\n get props() {\n return this._props;\n }\n\n public ancestors(): IType[] {\n return this.parent ? [...this.parent.ancestors(), this] : [this];\n }\n\n public path(): string {\n const ancestors = this.ancestors();\n return ancestors\n .map((t) => t.id)\n .join('>')\n .replace(/#\\/components\\/schemas/g, '#/c/s');\n }\n\n public pathToRoot(): string {\n let builder = '';\n let indent = 0;\n\n const ancestors = this.ancestors();\n for (let i = 0; i < ancestors.length; i++) {\n builder += ' <- ' + ' '.repeat(indent++) + ancestors[i].id + ' (' + ancestors[i].constructor.name + ')\\n';\n }\n\n return builder;\n }\n\n public add(child: IType): void {\n const paths: IType[] = this.ancestors();\n const contains: boolean = paths.map((p) => p.id).includes(child.id);\n\n if (contains) {\n trace(null, '-> [type:add]', 'already contains child: ' + child.id);\n const ancestor: IType = paths[paths.map((p) => p.id).indexOf(child.id)];\n const wrapper = Factory.fromCircularRef(this, ancestor);\n this.children.push(wrapper);\n } else {\n this.children.push(child);\n }\n }\n\n /*\n remove = (value: IType): void => {\n const index = this.children.findIndex(child => child === value);\n if (index !== -1) {\n this.children.splice(index, 1);\n }\n };\n\n*/\n\n /*traverseB(callback: (node: IType) => void): void {\n const queue: IType[] = [this];\n\n while (queue.length > 0) {\n const node = queue.shift()!;\n callback(node);\n queue.push(...node.children);\n }\n }*/\n\n public selectedProps(selection: string[]) {\n return Array.from(this.props.values()).filter((prop) => selection.find((s) => s.startsWith(prop.path())));\n }\n\n nameSuffix(): string {\n return this.kind === 'input' ? 'Input' : '';\n }\n}\n"]}
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/oas/nodes/type.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,OAAgB,IAAI;I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AAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC5G,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9C,CAAC;CACF","sourcesContent":["import { IType, Kind, Prop } from './internal.js';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Factory } from './factory.js';\n\nexport abstract class Type implements IType {\n public parent?: IType;\n public name: string;\n public children: IType[];\n public circularRef?: IType;\n public kind: Kind;\n public visited: boolean;\n\n private readonly _props: Map<string, Prop>;\n\n protected constructor(parent: IType | undefined, name: string) {\n this.parent = parent;\n this.name = name;\n this.children = [];\n this.visited = false;\n this._props = new Map<string, Prop>();\n this.kind = parent?.kind || 'type';\n }\n\n public abstract visit(context: OasContext): void;\n\n public abstract forPrompt(context: OasContext): string;\n\n public abstract select(context: OasContext, writer: Writer, selection: string[]): void;\n\n public find(path: string, collection: IType[]): IType | boolean {\n const parts = path.split('>');\n let current: IType | undefined;\n\n let i = 0;\n do {\n const part = parts[i];\n\n current = collection.find((t) => t.id === part);\n if (!current) {\n return false;\n }\n\n collection = Array.from(current!.children.values()) || Array.from(current!.props.values()) || [];\n // console.log(\"found\", current);\n\n i++;\n } while (i < parts.length);\n\n return current || false;\n }\n\n public expand(context: OasContext): IType[] {\n trace(context, '-> [expand]', `in: path: ${this.path()}`);\n if (!this.visited) {\n this.visit(context);\n }\n\n trace(context, '<- [expand]', `out: path: ${this.path()}`);\n\n // TODO:\n // if ((type instanceof Composed || type instanceof Union) && !type.getProps().isEmpty()) {\n // return type.props?.values() || [];\n // }\n // else {\n return this.children;\n // }\n }\n\n public abstract generate(context: OasContext, writer: Writer, selection: string[]): void;\n\n get id() {\n return this.name;\n }\n\n get props() {\n return this._props;\n }\n\n public ancestors(): IType[] {\n return this.parent ? [...this.parent.ancestors(), this] : [this];\n }\n\n public path(): string {\n const ancestors = this.ancestors();\n return ancestors\n .map((t) => t.id)\n .join('>')\n .replace(/#\\/components\\/schemas/g, '#/c/s');\n }\n\n public pathToRoot(): string {\n let builder = '';\n let indent = 0;\n\n const ancestors = this.ancestors();\n for (let i = 0; i < ancestors.length; i++) {\n builder += ' <- ' + ' '.repeat(indent++) + ancestors[i].id + ' (' + ancestors[i].constructor.name + ')\\n';\n }\n\n return builder;\n }\n\n public add(child: IType): IType {\n const paths: IType[] = this.ancestors();\n const contains: boolean = paths.map((p) => p.id).includes(child.id);\n let pushed = child;\n\n if (contains) {\n trace(null, '-> [type:add]', 'already contains child: ' + child.id);\n const ancestor: IType = paths[paths.map((p) => p.id).indexOf(child.id)];\n const wrapper = Factory.fromCircularRef(this, ancestor);\n this.children.push(wrapper);\n pushed = wrapper;\n } else {\n this.children.push(child);\n }\n\n return pushed;\n }\n\n public selectedProps(selection: string[]) {\n return Array.from(this.props.values()).filter((prop) => selection.find((s) => s.startsWith(prop.path())));\n }\n\n nameSuffix(): string {\n return this.kind === 'input' ? 'Input' : '';\n }\n}\n"]}
@@ -6,4 +6,7 @@ export declare class T {
6
6
  static isMutationType(type: IType): boolean;
7
7
  static isScalar(type: IType): boolean;
8
8
  static containers(node: IType): IType[];
9
+ static isContainer(node: IType): boolean;
10
+ static composables(node: IType): IType[];
11
+ static print(node: IType, prefix?: string, isLast?: boolean): string;
9
12
  }
@@ -1,12 +1,13 @@
1
- import { CircularRef, En, Obj, Prop, PropArray, PropScalar, Scalar } from './internal.js';
1
+ import { CircularRef, En, Obj, Prop, PropArray, PropEn, PropScalar, Scalar } from './internal.js';
2
2
  import _ from 'lodash';
3
3
  export class T {
4
4
  static isLeaf(type) {
5
5
  return (type instanceof Scalar ||
6
6
  type instanceof PropScalar ||
7
7
  type instanceof En ||
8
+ type instanceof PropEn ||
8
9
  type instanceof CircularRef ||
9
- (type instanceof PropArray && type.items instanceof PropScalar) ||
10
+ (type instanceof PropArray && type.items instanceof Scalar) ||
10
11
  (type instanceof Obj && _.isEmpty(type.props)));
11
12
  }
12
13
  static isPropScalar(type) {
@@ -32,8 +33,26 @@ export class T {
32
33
  }
33
34
  static containers(node) {
34
35
  return Array.from(node.children.values())
35
- .filter((child) => !(child instanceof Prop))
36
- .map((child) => (child.id.startsWith('ref:') ? child.refType : child));
36
+ .filter((child) => !(child instanceof Prop) && T.isContainer(child))
37
+ .map((child) => child);
38
+ }
39
+ static isContainer(node) {
40
+ return node.id.startsWith('obj:') || node.id.startsWith('comp:') || node.id.startsWith('union:');
41
+ }
42
+ static composables(node) {
43
+ return _.filter(T.containers(node), (e) => e.id.startsWith('comp:')); // || e.id.startsWith('union:'));
44
+ }
45
+ static print(node, prefix = '', isLast = true) {
46
+ // Build the current line with the appropriate connector.
47
+ const connector = prefix === '' ? '' : isLast ? '└─ ' : '├─ ';
48
+ let result = prefix + connector + node.id + '\n';
49
+ // Prepare the prefix for the children.
50
+ const childPrefix = prefix + (isLast ? ' ' : '│ ');
51
+ node.children.forEach((child, index) => {
52
+ const last = index === node.children.length - 1;
53
+ result += T.print(child, childPrefix, last);
54
+ });
55
+ return result;
37
56
  }
38
57
  }
39
58
  //# sourceMappingURL=typeUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typeUtils.js","sourceRoot":"","sources":["../../../src/oas/nodes/typeUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAO,MAAM,EAAE,MAAM,eAAe,CAAC;AAG/F,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,MAAM,OAAO,CAAC;IACL,MAAM,CAAC,MAAM,CAAC,IAAW;QAC9B,OAAO,CACL,IAAI,YAAY,MAAM;YACtB,IAAI,YAAY,UAAU;YAC1B,IAAI,YAAY,EAAE;Y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C,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAE,KAAa,CAAC,OAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IACrF,CAAC;CACF","sourcesContent":["import { CircularRef, En, Obj, Prop, PropArray, PropScalar, Ref, Scalar } from './internal.js';\n\nimport { IType } from './internal.js';\nimport _ from 'lodash';\n\nexport class T {\n public static isLeaf(type: IType): boolean {\n return (\n type instanceof Scalar ||\n type instanceof PropScalar ||\n type instanceof En ||\n type instanceof CircularRef ||\n (type instanceof PropArray && type.items instanceof PropScalar) ||\n (type instanceof Obj && _.isEmpty(type.props))\n );\n }\n\n public static isPropScalar(type: IType): boolean {\n return type instanceof PropScalar;\n }\n\n public static traverse(node: IType, callback: (node: IType) => void): void {\n const traverseNode = (n: IType): void => {\n callback(n);\n\n for (const c of n.children) {\n traverseNode(c);\n }\n };\n\n traverseNode(node);\n }\n\n static isMutationType(type: IType): boolean {\n return (\n type.id.startsWith('post:') ||\n type.id.startsWith('put:') ||\n type.id.startsWith('patch:') ||\n type.id.startsWith('del:')\n );\n }\n\n static isScalar(type: IType): boolean {\n return type.id.startsWith('scalar:');\n }\n\n public static containers(node: IType) {\n return Array.from(node.children.values())\n .filter((child) => !(child instanceof Prop))\n .map((child) => (child.id.startsWith('ref:') ? (child as Ref).refType! : child));\n }\n}\n"]}
1
+ {"version":3,"file":"typeUtils.js","sourceRoot":"","sources":["../../../src/oas/nodes/typeUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGlG,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,MAAM,OAAO,CAAC;IACL,MAAM,CAAC,MAAM,CAAC,IAAW;QAC9B,OAAO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IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;YAChD,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import { CircularRef, En, Obj, Prop, PropArray, PropEn, PropScalar, Scalar } from './internal.js';\n\nimport { IType } from './internal.js';\nimport _ from 'lodash';\n\nexport class T {\n public static isLeaf(type: IType): boolean {\n return (\n type instanceof Scalar ||\n type instanceof PropScalar ||\n type instanceof En ||\n type instanceof PropEn ||\n type instanceof CircularRef ||\n (type instanceof PropArray && type.items instanceof Scalar) ||\n (type instanceof Obj && _.isEmpty(type.props))\n );\n }\n\n public static isPropScalar(type: IType): boolean {\n return type instanceof PropScalar;\n }\n\n public static traverse(node: IType, callback: (node: IType) => void): void {\n const traverseNode = (n: IType): void => {\n callback(n);\n\n for (const c of n.children) {\n traverseNode(c);\n }\n };\n\n traverseNode(node);\n }\n\n static isMutationType(type: IType): boolean {\n return (\n type.id.startsWith('post:') ||\n type.id.startsWith('put:') ||\n type.id.startsWith('patch:') ||\n type.id.startsWith('del:')\n );\n }\n\n static isScalar(type: IType): boolean {\n return type.id.startsWith('scalar:');\n }\n\n public static containers(node: IType) {\n return Array.from(node.children.values())\n .filter((child) => !(child instanceof Prop) && T.isContainer(child))\n .map((child) => child);\n }\n\n public static isContainer(node: IType): boolean {\n return node.id.startsWith('obj:') || node.id.startsWith('comp:') || node.id.startsWith('union:');\n }\n\n static composables(node: IType): IType[] {\n return _.filter(T.containers(node), (e: IType) => e.id.startsWith('comp:')); // || e.id.startsWith('union:'));\n }\n\n public static print(node: IType, prefix: string = '', isLast: boolean = true): string {\n // Build the current line with the appropriate connector.\n const connector = prefix === '' ? '' : isLast ? '└─ ' : '├─ ';\n let result = prefix + connector + node.id + '\\n';\n\n // Prepare the prefix for the children.\n const childPrefix = prefix + (isLast ? ' ' : '│ ');\n\n node.children.forEach((child, index) => {\n const last = index === node.children.length - 1;\n result += T.print(child, childPrefix, last);\n });\n\n return result;\n }\n}\n"]}
@@ -13,7 +13,6 @@ export declare class Union extends Type {
13
13
  generate(context: OasContext, writer: Writer, selection: string[]): void;
14
14
  select(context: OasContext, writer: Writer, selection: string[]): void;
15
15
  consolidate(selection: string[]): Set<string>;
16
- private updatePropName;
17
16
  private visitProperties;
18
17
  private updateName;
19
18
  }