apollo-conn-gen 0.0.2

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 (146) hide show
  1. package/dist/cli/json.d.ts +1 -0
  2. package/dist/cli/json.js +70 -0
  3. package/dist/cli/json.js.map +1 -0
  4. package/dist/cli/oas-helpers/index.d.ts +4 -0
  5. package/dist/cli/oas-helpers/index.js +54 -0
  6. package/dist/cli/oas-helpers/index.js.map +1 -0
  7. package/dist/cli/oas.d.ts +1 -0
  8. package/dist/cli/oas.js +49 -0
  9. package/dist/cli/oas.js.map +1 -0
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.js +4 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/json/index.d.ts +4 -0
  14. package/dist/json/index.js +5 -0
  15. package/dist/json/index.js.map +1 -0
  16. package/dist/json/io/index.d.ts +1 -0
  17. package/dist/json/io/index.js +2 -0
  18. package/dist/json/io/index.js.map +1 -0
  19. package/dist/json/io/writer.d.ts +15 -0
  20. package/dist/json/io/writer.js +45 -0
  21. package/dist/json/io/writer.js.map +1 -0
  22. package/dist/json/walker/index.d.ts +2 -0
  23. package/dist/json/walker/index.js +3 -0
  24. package/dist/json/walker/index.js.map +1 -0
  25. package/dist/json/walker/jsonContext.d.ts +12 -0
  26. package/dist/json/walker/jsonContext.js +42 -0
  27. package/dist/json/walker/jsonContext.js.map +1 -0
  28. package/dist/json/walker/jsonGen.d.ts +19 -0
  29. package/dist/json/walker/jsonGen.js +209 -0
  30. package/dist/json/walker/jsonGen.js.map +1 -0
  31. package/dist/json/walker/log/trace.d.ts +3 -0
  32. package/dist/json/walker/log/trace.js +11 -0
  33. package/dist/json/walker/log/trace.js.map +1 -0
  34. package/dist/json/walker/naming.d.ts +8 -0
  35. package/dist/json/walker/naming.js +66 -0
  36. package/dist/json/walker/naming.js.map +1 -0
  37. package/dist/json/walker/types/index.d.ts +4 -0
  38. package/dist/json/walker/types/index.js +5 -0
  39. package/dist/json/walker/types/index.js.map +1 -0
  40. package/dist/json/walker/types/jsonArray.d.ts +13 -0
  41. package/dist/json/walker/types/jsonArray.js +70 -0
  42. package/dist/json/walker/types/jsonArray.js.map +1 -0
  43. package/dist/json/walker/types/jsonObj.d.ts +17 -0
  44. package/dist/json/walker/types/jsonObj.js +76 -0
  45. package/dist/json/walker/types/jsonObj.js.map +1 -0
  46. package/dist/json/walker/types/jsonScalar.d.ts +12 -0
  47. package/dist/json/walker/types/jsonScalar.js +39 -0
  48. package/dist/json/walker/types/jsonScalar.js.map +1 -0
  49. package/dist/json/walker/types/jsonType.d.ts +16 -0
  50. package/dist/json/walker/types/jsonType.js +30 -0
  51. package/dist/json/walker/types/jsonType.js.map +1 -0
  52. package/dist/oas/index.d.ts +14 -0
  53. package/dist/oas/index.js +15 -0
  54. package/dist/oas/index.js.map +1 -0
  55. package/dist/oas/io/writer.d.ts +25 -0
  56. package/dist/oas/io/writer.js +313 -0
  57. package/dist/oas/io/writer.js.map +1 -0
  58. package/dist/oas/log/trace.d.ts +3 -0
  59. package/dist/oas/log/trace.js +7 -0
  60. package/dist/oas/log/trace.js.map +1 -0
  61. package/dist/oas/nodes/arr.d.ts +15 -0
  62. package/dist/oas/nodes/arr.js +47 -0
  63. package/dist/oas/nodes/arr.js.map +1 -0
  64. package/dist/oas/nodes/circularRef.d.ts +13 -0
  65. package/dist/oas/nodes/circularRef.js +39 -0
  66. package/dist/oas/nodes/circularRef.js.map +1 -0
  67. package/dist/oas/nodes/comp.d.ts +18 -0
  68. package/dist/oas/nodes/comp.js +156 -0
  69. package/dist/oas/nodes/comp.js.map +1 -0
  70. package/dist/oas/nodes/en.d.ts +14 -0
  71. package/dist/oas/nodes/en.js +57 -0
  72. package/dist/oas/nodes/en.js.map +1 -0
  73. package/dist/oas/nodes/factory.d.ts +17 -0
  74. package/dist/oas/nodes/factory.js +174 -0
  75. package/dist/oas/nodes/factory.js.map +1 -0
  76. package/dist/oas/nodes/get.d.ts +24 -0
  77. package/dist/oas/nodes/get.js +167 -0
  78. package/dist/oas/nodes/get.js.map +1 -0
  79. package/dist/oas/nodes/obj.d.ts +15 -0
  80. package/dist/oas/nodes/obj.js +177 -0
  81. package/dist/oas/nodes/obj.js.map +1 -0
  82. package/dist/oas/nodes/param/param.d.ts +17 -0
  83. package/dist/oas/nodes/param/param.js +64 -0
  84. package/dist/oas/nodes/param/param.js.map +1 -0
  85. package/dist/oas/nodes/props/prop.d.ts +12 -0
  86. package/dist/oas/nodes/props/prop.js +33 -0
  87. package/dist/oas/nodes/props/prop.js.map +1 -0
  88. package/dist/oas/nodes/props/propArray.d.ts +15 -0
  89. package/dist/oas/nodes/props/propArray.js +75 -0
  90. package/dist/oas/nodes/props/propArray.js.map +1 -0
  91. package/dist/oas/nodes/props/propObj.d.ts +16 -0
  92. package/dist/oas/nodes/props/propObj.js +70 -0
  93. package/dist/oas/nodes/props/propObj.js.map +1 -0
  94. package/dist/oas/nodes/props/propRef.d.ts +19 -0
  95. package/dist/oas/nodes/props/propRef.js +108 -0
  96. package/dist/oas/nodes/props/propRef.js.map +1 -0
  97. package/dist/oas/nodes/props/propScalar.d.ts +16 -0
  98. package/dist/oas/nodes/props/propScalar.js +47 -0
  99. package/dist/oas/nodes/props/propScalar.js.map +1 -0
  100. package/dist/oas/nodes/props/referenceObject.d.ts +3 -0
  101. package/dist/oas/nodes/props/referenceObject.js +2 -0
  102. package/dist/oas/nodes/props/referenceObject.js.map +1 -0
  103. package/dist/oas/nodes/ref.d.ts +17 -0
  104. package/dist/oas/nodes/ref.js +70 -0
  105. package/dist/oas/nodes/ref.js.map +1 -0
  106. package/dist/oas/nodes/response.d.ts +14 -0
  107. package/dist/oas/nodes/response.js +48 -0
  108. package/dist/oas/nodes/response.js.map +1 -0
  109. package/dist/oas/nodes/scalar.d.ts +12 -0
  110. package/dist/oas/nodes/scalar.js +26 -0
  111. package/dist/oas/nodes/scalar.js.map +1 -0
  112. package/dist/oas/nodes/type.d.ts +43 -0
  113. package/dist/oas/nodes/type.js +107 -0
  114. package/dist/oas/nodes/type.js.map +1 -0
  115. package/dist/oas/nodes/union.d.ts +16 -0
  116. package/dist/oas/nodes/union.js +133 -0
  117. package/dist/oas/nodes/union.js.map +1 -0
  118. package/dist/oas/oasContext.d.ts +23 -0
  119. package/dist/oas/oasContext.js +73 -0
  120. package/dist/oas/oasContext.js.map +1 -0
  121. package/dist/oas/oasGen.d.ts +28 -0
  122. package/dist/oas/oasGen.js +166 -0
  123. package/dist/oas/oasGen.js.map +1 -0
  124. package/dist/oas/prompts/base/theme.d.ts +1 -0
  125. package/dist/oas/prompts/base/theme.js +50 -0
  126. package/dist/oas/prompts/base/theme.js.map +1 -0
  127. package/dist/oas/prompts/base/utils.d.ts +3 -0
  128. package/dist/oas/prompts/base/utils.js +8 -0
  129. package/dist/oas/prompts/base/utils.js.map +1 -0
  130. package/dist/oas/prompts/prompt.d.ts +19 -0
  131. package/dist/oas/prompts/prompt.js +176 -0
  132. package/dist/oas/prompts/prompt.js.map +1 -0
  133. package/dist/oas/prompts/theme.d.ts +126 -0
  134. package/dist/oas/prompts/theme.js +2 -0
  135. package/dist/oas/prompts/theme.js.map +1 -0
  136. package/dist/oas/utils/gql.d.ts +5 -0
  137. package/dist/oas/utils/gql.js +35 -0
  138. package/dist/oas/utils/gql.js.map +1 -0
  139. package/dist/oas/utils/naming.d.ts +16 -0
  140. package/dist/oas/utils/naming.js +143 -0
  141. package/dist/oas/utils/naming.js.map +1 -0
  142. package/dist/oas/utils/typeUtils.d.ts +6 -0
  143. package/dist/oas/utils/typeUtils.js +25 -0
  144. package/dist/oas/utils/typeUtils.js.map +1 -0
  145. package/package.json +77 -0
  146. package/readme.md +383 -0
@@ -0,0 +1,75 @@
1
+ import { trace } from '../../log/trace.js';
2
+ import { Naming } from '../../utils/naming.js';
3
+ import { Factory } from '../factory.js';
4
+ import { PropObj } from './propObj.js';
5
+ import { PropRef } from './propRef.js';
6
+ import { Prop } from '../props/prop.js';
7
+ export class PropArray extends Prop {
8
+ items;
9
+ get id() {
10
+ return `prop:array:#${this.name}`;
11
+ }
12
+ visit(context) {
13
+ if (this.visited) {
14
+ return;
15
+ }
16
+ context.enter(this);
17
+ trace(context, '-> [prop-array:visit]', 'in');
18
+ trace(context, ' [prop-array:visit]', 'type: ' + this.items);
19
+ this.items?.visit(context);
20
+ this.visited = true;
21
+ trace(context, '<- [prop:array:visit]', 'out');
22
+ context.leave(this);
23
+ }
24
+ setItems(items) {
25
+ this.items = items;
26
+ if (!this.children.includes(items)) {
27
+ this.add(items);
28
+ }
29
+ }
30
+ getValue(context) {
31
+ return `[${this.items.getValue(context)}]`;
32
+ }
33
+ add(child) {
34
+ const paths = this.ancestors();
35
+ const contains = paths.map((p) => p.id).includes(child.id);
36
+ trace(null, '-> [prop-array:add]', 'contains child? ' + contains);
37
+ if (contains) {
38
+ const ancestor = paths[paths.map((p) => p.id).indexOf(child.id)];
39
+ const wrapper = Factory.fromCircularRef(this, ancestor);
40
+ super.add(wrapper);
41
+ this.visited = true;
42
+ }
43
+ else {
44
+ super.add(child);
45
+ }
46
+ }
47
+ forPrompt(context) {
48
+ return `${this.name}: [${this.items.getValue(context)}]`;
49
+ }
50
+ select(context, writer, selection) {
51
+ trace(context, '-> [prop-array:select]', 'in: ' + this.name);
52
+ const fieldName = this.name;
53
+ const sanitised = Naming.sanitiseFieldForSelect(fieldName);
54
+ writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);
55
+ if (this.needsBrackets(this.items)) {
56
+ writer.append(' {');
57
+ writer.append('\n');
58
+ context.enter(this);
59
+ }
60
+ // Select each child of the items Prop.
61
+ for (const child of this.items.children) {
62
+ child.select(context, writer, selection);
63
+ }
64
+ if (this.needsBrackets(this.items)) {
65
+ context.leave(this);
66
+ writer.append(' '.repeat(context.indent + context.stack.length)).append('}');
67
+ }
68
+ writer.append('\n');
69
+ trace(context, '<- [prop:array:select]', 'out');
70
+ }
71
+ needsBrackets(child) {
72
+ return child instanceof PropRef || child instanceof PropObj;
73
+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../../log/trace.js';\nimport { OasContext } from '../../oasContext.js';\nimport { Writer } from '../../io/writer.js';\nimport { Naming } from '../../utils/naming.js';\nimport { Factory } from '../factory.js';\nimport { PropObj } from './propObj.js';\nimport { PropRef } from './propRef.js';\nimport { IType } from '../type.js';\nimport { Prop } from '../props/prop.js';\n\nexport class PropArray extends Prop {\n public items?: Prop;\n\n get id(): string {\n return `prop:array:#${this.name}`;\n }\n\n public override visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n trace(context, '-> [prop-array:visit]', 'in');\n\n trace(context, ' [prop-array:visit]', 'type: ' + this.items);\n this.items?.visit(context);\n this.visited = true;\n\n trace(context, '<- [prop:array:visit]', 'out');\n context.leave(this);\n }\n\n public setItems(items: Prop): void {\n this.items = items;\n if (!this.children.includes(items)) {\n this.add(items);\n }\n }\n\n public override getValue(context: OasContext): string {\n return `[${this.items!.getValue(context)}]`;\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 trace(null, '-> [prop-array:add]', 'contains child? ' + contains);\n\n if (contains) {\n const ancestor: IType = paths[paths.map((p) => p.id).indexOf(child.id)];\n const wrapper: IType = Factory.fromCircularRef(this, ancestor);\n super.add(wrapper);\n this.visited = true;\n } else {\n super.add(child);\n }\n }\n\n public forPrompt(context: OasContext): string {\n return `${this.name}: [${this.items!.getValue(context)}]`;\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [prop-array:select]', 'in: ' + this.name);\n\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.needsBrackets(this.items!)) {\n writer.append(' {');\n writer.append('\\n');\n context.enter(this);\n }\n\n // Select each child of the items Prop.\n for (const child of this.items!.children) {\n child.select(context, writer, selection);\n }\n\n if (this.needsBrackets(this.items!)) {\n context.leave(this);\n writer.append(' '.repeat(context.indent + context.stack.length)).append('}');\n }\n writer.append('\\n');\n\n trace(context, '<- [prop:array:select]', 'out');\n }\n\n public needsBrackets(child: IType): boolean {\n return child instanceof PropRef || child instanceof PropObj;\n }\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import { SchemaObject } from 'oas/types';
2
+ import { IType } from '../type.js';
3
+ import { OasContext } from '../../oasContext.js';
4
+ import { Writer } from '../../io/writer.js';
5
+ import { Prop } from './prop.js';
6
+ export declare class PropObj extends Prop {
7
+ schema: SchemaObject;
8
+ obj: IType;
9
+ constructor(parent: IType, name: string, schema: SchemaObject, obj: IType);
10
+ forPrompt(_context: OasContext): string;
11
+ get id(): string;
12
+ visit(context: OasContext): void;
13
+ getValue(context: OasContext): string;
14
+ select(context: OasContext, writer: Writer, selection: string[]): void;
15
+ private needsBrackets;
16
+ }
@@ -0,0 +1,70 @@
1
+ import _ from 'lodash';
2
+ import { trace } from '../../log/trace.js';
3
+ import { Composed } from '../comp.js';
4
+ import { Obj } from '../obj.js';
5
+ import { Union } from '../union.js';
6
+ import { Naming } from '../../utils/naming.js';
7
+ import { Prop } from './prop.js';
8
+ export class PropObj extends Prop {
9
+ schema;
10
+ obj;
11
+ constructor(parent, name, schema, obj) {
12
+ super(parent, name, schema);
13
+ this.schema = schema;
14
+ this.obj = obj;
15
+ if (!obj) {
16
+ throw new Error('obj parameter is required');
17
+ }
18
+ // TODO: check if reparenting is necessary?!?!
19
+ if (obj.parent !== this) {
20
+ obj.parent = this;
21
+ }
22
+ // this.updateName(parent);
23
+ }
24
+ forPrompt(_context) {
25
+ return _.lowerFirst(this.name) + ': ' + Naming.getRefName(this.obj.name) + ' (Obj)';
26
+ }
27
+ get id() {
28
+ return 'prop:obj:' + this.name;
29
+ }
30
+ visit(context) {
31
+ if (this.visited) {
32
+ return;
33
+ }
34
+ context.enter(this);
35
+ trace(context, '-> [prop-obj:visit]', 'in ' + this.name + ', obj: ' + this.obj.name);
36
+ this.obj.visit(context);
37
+ if (!this.children.includes(this.obj)) {
38
+ this.add(this.obj);
39
+ }
40
+ this.visited = true;
41
+ trace(context, '<- [prop-obj:visit]', 'out ' + this.name + ', obj: ' + this.obj.name);
42
+ context.leave(this);
43
+ }
44
+ getValue(context) {
45
+ return Naming.genTypeName(this.name);
46
+ }
47
+ select(context, writer, selection) {
48
+ trace(context, '-> [prop-obj:select]', 'in ' + this.name + ', obj: ' + this.obj.name);
49
+ const fieldName = this.name;
50
+ const sanitised = Naming.sanitiseFieldForSelect(fieldName);
51
+ writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);
52
+ if (this.needsBrackets(this.obj)) {
53
+ writer.append(' {').append('\n');
54
+ context.enter(this);
55
+ }
56
+ for (const child of this.children) {
57
+ child.select(context, writer, selection);
58
+ }
59
+ if (this.needsBrackets(this.obj)) {
60
+ context.leave(this);
61
+ writer.append(' '.repeat(context.indent + context.stack.length)).append('}');
62
+ writer.append('\n');
63
+ }
64
+ trace(context, '<- [prop-obj:select]', 'out ' + this.name + ', obj: ' + this.obj?.name);
65
+ }
66
+ needsBrackets(child) {
67
+ return child instanceof Obj || child instanceof Union || child instanceof Composed;
68
+ }
69
+ }
70
+ //# sourceMappingURL=propObj.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"propObj.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/propObj.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,OAAO,OAAQ,SAAQ,IAAI;IAItB;IACA;IAJT,YACE,MAA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,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC7E,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC;QAED,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,KAAK,YAAY,GAAG,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,YAAY,QAAQ,CAAC;IACrF,CAAC;CAqBF","sourcesContent":["import _ from 'lodash';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../../log/trace.js';\nimport { IType, Type } from '../type.js';\nimport { Composed } from '../comp.js';\nimport { Obj } from '../obj.js';\nimport { Union } from '../union.js';\nimport { OasContext } from '../../oasContext.js';\nimport { Writer } from '../../io/writer.js';\nimport { Naming } from '../../utils/naming.js';\nimport { Prop } from './prop.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 reparenting is necessary?!?!\n if (obj.parent !== this) {\n obj.parent = this;\n }\n\n // this.updateName(parent);\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 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 writer.append('\\n');\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;\n }\n\n /*\n private updateName(parent: IType): void {\n if (this.name === 'items') {\n const parentName = parent.name;\n // if the part is a ref, then use replace for the pointed object\n if (parent instanceof PropRef) {\n this.name = parentName.replace('ref:', 'obj:');\n }\n // if within an array, synthesize a name\n else if (parent.constructor.name === 'PropArray') {\n this.name = parentName + 'Item';\n }\n // create a anonymous name\n else {\n this.name = `[prop:obj:anonymous:${this.parent?.name}]`;\n }\n }\n }\n*/\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import { OasContext } from '../../oasContext.js';
2
+ import { Prop } from './prop.js';
3
+ import { SchemaObject } from 'oas/types';
4
+ import { IType } from '../type.js';
5
+ import { Writer } from '../../io/writer.js';
6
+ export declare class PropRef extends Prop {
7
+ schema: SchemaObject;
8
+ ref: string;
9
+ get id(): string;
10
+ refType?: IType;
11
+ constructor(parent: IType | undefined, name: string, schema: SchemaObject, ref: string);
12
+ add(child: IType): void;
13
+ visit(context: OasContext): void;
14
+ getValue(_context: OasContext): string;
15
+ forPrompt(context: OasContext): string;
16
+ select(context: OasContext, writer: Writer, selection: string[]): void;
17
+ protected generateValue(context: OasContext, writer: Writer): void;
18
+ private needsBrackets;
19
+ }
@@ -0,0 +1,108 @@
1
+ import { Prop } from './prop.js';
2
+ import _ from 'lodash';
3
+ import { trace } from '../../log/trace.js';
4
+ import { Naming } from '../../utils/naming.js';
5
+ import { Arr } from '../arr.js';
6
+ import { CircularRef } from '../circularRef.js';
7
+ import { Composed } from '../comp.js';
8
+ import { Factory } from '../factory.js';
9
+ import { Obj } from '../obj.js';
10
+ import { Union } from '../union.js';
11
+ export class PropRef extends Prop {
12
+ schema;
13
+ ref;
14
+ get id() {
15
+ return `prop:ref:#${this.name}`;
16
+ }
17
+ refType;
18
+ constructor(parent, name, schema, ref) {
19
+ super(parent, name, schema);
20
+ this.schema = schema;
21
+ this.ref = ref;
22
+ }
23
+ add(child) {
24
+ child.name = this.ref;
25
+ const paths = this.ancestors();
26
+ const contains = paths.map((p) => p.id).includes(child.id);
27
+ trace(null, '-> [prop-ref:add]', 'contains child? ' + contains);
28
+ if (contains) {
29
+ const ancestor = paths[paths.map((p) => p.id).indexOf(child.id)];
30
+ const wrapper = Factory.fromCircularRef(this, ancestor);
31
+ super.add(wrapper);
32
+ this.visited = true;
33
+ this.refType = wrapper;
34
+ }
35
+ else {
36
+ super.add(child);
37
+ }
38
+ }
39
+ visit(context) {
40
+ if (this.visited) {
41
+ return;
42
+ }
43
+ context.enter(this);
44
+ trace(context, '-> [prop-ref:visit]', 'in ' + this.name + ', ref: ' + this.ref);
45
+ const schema = context.lookupRef(this.ref);
46
+ if (!schema) {
47
+ throw new Error('Schema not found for ref: ' + this.ref);
48
+ }
49
+ const type = Factory.fromSchema(this, schema);
50
+ if (!this.refType) {
51
+ this.refType = type;
52
+ type.name = this.ref;
53
+ type.visit(context);
54
+ if (!this.children.includes(this.refType)) {
55
+ this.add(this.refType);
56
+ }
57
+ this.visited = true;
58
+ }
59
+ trace(context, '<- [prop-ref:visit]', 'out ' + this.name + ', ref: ' + this.ref);
60
+ context.leave(this);
61
+ }
62
+ getValue(_context) {
63
+ const type = this.refType;
64
+ const name = type ? type.name : this.ref;
65
+ return Naming.genTypeName(name);
66
+ }
67
+ forPrompt(context) {
68
+ return `${this.name}: ${Naming.getRefName(this.ref)} (Ref)`;
69
+ }
70
+ select(context, writer, selection) {
71
+ trace(context, '-> [prop-ref:select]', 'in ' + this.name + ', ref: ' + this.ref);
72
+ const fieldName = this.name;
73
+ const sanitised = Naming.sanitiseFieldForSelect(fieldName);
74
+ writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);
75
+ if (this.refType && this.needsBrackets(this.refType)) {
76
+ writer.append(' {').append('\n');
77
+ context.enter(this);
78
+ }
79
+ for (const child of this.children) {
80
+ child.select(context, writer, selection);
81
+ }
82
+ if (this.refType && this.needsBrackets(this.refType)) {
83
+ context.leave(this);
84
+ writer.append(' '.repeat(context.indent + context.stack.length)).append('}');
85
+ }
86
+ writer.append('\n');
87
+ trace(context, '<- [prop-ref:select]', 'out ' + this.name + ', ref: ' + this.ref);
88
+ }
89
+ generateValue(context, writer) {
90
+ const type = this.refType;
91
+ if (type && type instanceof Arr) {
92
+ writer.append('[');
93
+ const items = type.itemsType;
94
+ writer.append(_.upperFirst(items.name));
95
+ writer.append(']');
96
+ }
97
+ else {
98
+ writer.append(this.getValue(context));
99
+ }
100
+ }
101
+ needsBrackets(child) {
102
+ if (child instanceof Arr) {
103
+ return this.needsBrackets(child.itemsType);
104
+ }
105
+ return child instanceof Obj || child instanceof Union || child instanceof Composed || child instanceof CircularRef;
106
+ }
107
+ }
108
+ //# sourceMappingURL=propRef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"propRef.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/propRef.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAE,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,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 { Prop } from './prop.js';\n\nimport _ from 'lodash';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../../log/trace.js';\nimport { IType } from '../type.js';\nimport { Writer } from '../../io/writer.js';\nimport { Naming } from '../../utils/naming.js';\nimport { Arr } from '../arr.js';\nimport { CircularRef } from '../circularRef.js';\nimport { Composed } from '../comp.js';\nimport { Factory } from '../factory.js';\nimport { Obj } from '../obj.js';\nimport { Union } from '../union.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 return Naming.genTypeName(name!);\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"]}
@@ -0,0 +1,16 @@
1
+ import { SchemaObject } from 'oas/types';
2
+ import { OasContext } from '../../oasContext.js';
3
+ import { Writer } from '../../io/writer.js';
4
+ import { IType } from '../type.js';
5
+ import { Prop } from '../props/prop.js';
6
+ export declare class PropScalar extends Prop {
7
+ type: string;
8
+ schema: SchemaObject;
9
+ private propType?;
10
+ constructor(parent: IType, name: string, type: string, schema: SchemaObject);
11
+ get id(): string;
12
+ visit(context: OasContext): void;
13
+ getValue(context: OasContext): string;
14
+ forPrompt(context: OasContext): string;
15
+ select(context: OasContext, writer: Writer, selection: string[]): void;
16
+ }
@@ -0,0 +1,47 @@
1
+ import { trace } from '../../log/trace.js';
2
+ import { Naming } from '../../utils/naming.js';
3
+ import { Factory } from '../factory.js';
4
+ import { Prop } from '../props/prop.js';
5
+ export class PropScalar extends Prop {
6
+ type;
7
+ schema;
8
+ propType;
9
+ constructor(parent, name, type, schema) {
10
+ super(parent, name, schema);
11
+ this.type = type;
12
+ this.schema = schema;
13
+ }
14
+ get id() {
15
+ return `prop:scalar:${this.name}`;
16
+ }
17
+ visit(context) {
18
+ if (this.visited) {
19
+ return;
20
+ }
21
+ context.enter(this);
22
+ if (!this.propType) {
23
+ this.propType = Factory.fromSchema(this, this.schema);
24
+ // this.propType.visit(context);
25
+ this.visited = true;
26
+ }
27
+ context.leave(this);
28
+ }
29
+ getValue(context) {
30
+ return this.type;
31
+ }
32
+ forPrompt(context) {
33
+ return `${this.name}: ${this.type}`;
34
+ }
35
+ select(context, writer, selection) {
36
+ trace(context, ' [prop:select]', this.name);
37
+ const sanitised = Naming.sanitiseFieldForSelect(this.name);
38
+ writer
39
+ .append(' '.repeat(context.indent + context.stack.length))
40
+ .append(sanitised)
41
+ .append('\n');
42
+ for (const child of this.children) {
43
+ child.select(context, writer, selection);
44
+ }
45
+ }
46
+ }
47
+ //# sourceMappingURL=propScalar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"propScalar.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/propScalar.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC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,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;aACzD,MAAM,CAAC,SAAS,CAAC;aACjB,MAAM,CAAC,IAAI,CAAC,CAAC;QAEhB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;CACF","sourcesContent":["import { 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';\nimport { Factory } from '../factory.js';\nimport { IType } from '../type.js';\nimport { Prop } from '../props/prop.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\n .append(' '.repeat(context.indent + context.stack.length))\n .append(sanitised)\n .append('\\n');\n\n for (const child of this.children) {\n child.select(context, writer, selection);\n }\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export type ReferenceObject = {
2
+ $ref: string;
3
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=referenceObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"referenceObject.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/referenceObject.ts"],"names":[],"mappings":"","sourcesContent":["export type ReferenceObject = {\n $ref: string;\n};\n"]}
@@ -0,0 +1,17 @@
1
+ import { OasContext } from '../oasContext.js';
2
+ import { Writer } from '../io/writer.js';
3
+ import { Prop } from './props/prop.js';
4
+ import { IType, Type } from './type.js';
5
+ import { ReferenceObject } from './props/referenceObject.js';
6
+ export declare class Ref extends Type {
7
+ schema: ReferenceObject | null;
8
+ refType?: IType;
9
+ constructor(parent: IType | undefined, name: string, schema: ReferenceObject | null);
10
+ get id(): string;
11
+ get props(): Map<string, Prop>;
12
+ forPrompt(context: OasContext): string;
13
+ visit(context: OasContext): void;
14
+ generate(context: OasContext, writer: Writer, selection: string[]): void;
15
+ select(context: OasContext, writer: Writer, selection: string[]): void;
16
+ private firstChild;
17
+ }
@@ -0,0 +1,70 @@
1
+ import { trace } from '../log/trace.js';
2
+ import { Naming } from '../utils/naming.js';
3
+ import { Arr } from './arr.js';
4
+ import { Factory } from './factory.js';
5
+ import { Type } from './type.js';
6
+ export class Ref extends Type {
7
+ schema;
8
+ refType;
9
+ constructor(parent, name, schema) {
10
+ super(parent, name);
11
+ this.schema = schema;
12
+ }
13
+ get id() {
14
+ return 'ref:' + this.schema?.$ref;
15
+ }
16
+ get props() {
17
+ return this.refType?.props ?? new Map();
18
+ }
19
+ forPrompt(context) {
20
+ return `${Naming.getRefName(this.name)} (Ref)`;
21
+ }
22
+ visit(context) {
23
+ // console.log('schema', this.schema);
24
+ if (this.visited) {
25
+ return;
26
+ }
27
+ const ref = this.schema?.$ref ?? '';
28
+ context.enter(this);
29
+ trace(context, '-> [ref:visit]', 'in: ' + ref);
30
+ const schema = context.lookupRef(ref);
31
+ if (!schema) {
32
+ throw new Error('Schema not found for ref: ' + ref);
33
+ }
34
+ this.refType = Factory.fromSchema(this, schema);
35
+ // Set the name of the resolved type to the reference string.
36
+ this.refType.name = ref;
37
+ this.refType.visit(context);
38
+ this.visited = true;
39
+ trace(context, '<- [ref:visit]', 'out: ' + ref);
40
+ context.leave(this);
41
+ }
42
+ generate(context, writer, selection) {
43
+ context.enter(this);
44
+ trace(context, '-> [ref::generate]', `-> in: ${this.name}`);
45
+ // If we're in a Response context and the resolved type is an Arr,
46
+ // generate it with array notation.
47
+ if (context.inContextOf('Response', this) && this.refType instanceof Arr) {
48
+ writer.append('[').append(this.firstChild().name).append(']');
49
+ }
50
+ else {
51
+ // Rewrite terrible names to something more sensible.
52
+ const sanitised = Naming.genTypeName(this.name);
53
+ const refName = Naming.getRefName(this.name);
54
+ writer.write(sanitised === refName ? refName : sanitised);
55
+ }
56
+ trace(context, '<- [ref::generate]', `-> out: ${this.name}`);
57
+ context.leave(this);
58
+ }
59
+ select(context, writer, selection) {
60
+ trace(context, '-> [ref::select]', `-> in: ${this.name}`);
61
+ if (this.refType) {
62
+ this.refType.select(context, writer, selection);
63
+ }
64
+ trace(context, '<- [ref::select]', `-> out: ${this.name}`);
65
+ }
66
+ firstChild() {
67
+ return this.refType.children[0];
68
+ }
69
+ }
70
+ //# sourceMappingURL=ref.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/oas/nodes/ref.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAS,IAAI,EAAE,MAAM,WAAW,CAAC;AAIxC,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,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CAAC;IAEO,UAAU;QAChB,OAAO,IAAI,CAAC,OAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;CACF","sourcesContent":["import { 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';\nimport { Arr } from './arr.js';\nimport { Factory } from './factory.js';\nimport { Prop } from './props/prop.js';\nimport { IType, Type } from './type.js';\n\nimport { ReferenceObject } from './props/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"]}
@@ -0,0 +1,14 @@
1
+ import { SchemaObject } from 'oas/types';
2
+ import { OasContext } from '../oasContext.js';
3
+ import { Writer } from '../io/writer.js';
4
+ import { IType, Type } from './type.js';
5
+ export declare class Response extends Type {
6
+ schema: SchemaObject;
7
+ response?: IType;
8
+ constructor(parent: IType, name: string, schema: SchemaObject, response?: IType);
9
+ get id(): string;
10
+ visit(context: OasContext): void;
11
+ forPrompt(context: OasContext): string;
12
+ generate(context: OasContext, writer: Writer, selection: string[]): void;
13
+ select(context: OasContext, writer: Writer, selection: string[]): void;
14
+ }
@@ -0,0 +1,48 @@
1
+ import { trace } from '../log/trace.js';
2
+ import { Factory } from './factory.js';
3
+ import { Type } from './type.js';
4
+ export class Response extends Type {
5
+ schema;
6
+ response;
7
+ constructor(parent, name, schema, response) {
8
+ super(parent, name);
9
+ this.schema = schema;
10
+ this.response = response;
11
+ }
12
+ get id() {
13
+ return 'res:' + this.name;
14
+ }
15
+ visit(context) {
16
+ if (this.visited) {
17
+ trace(context, '-> [res:visit]', this.name + ' already visited.');
18
+ return;
19
+ }
20
+ context.enter(this);
21
+ trace(context, '-> [get:visit]', 'in ' + this.name);
22
+ this.response = Factory.fromSchema(this, this.schema);
23
+ trace(context, ' [get:visit]', 'array type: ' + this.response.id);
24
+ this.visited = true;
25
+ trace(context, '<- [get:visit]', 'out ' + this.name);
26
+ context.leave(this);
27
+ }
28
+ forPrompt(context) {
29
+ return 'Response';
30
+ }
31
+ generate(context, writer, selection) {
32
+ context.enter(this);
33
+ trace(context, '-> [response:generate]', `-> in: ${this.parent.name}`);
34
+ if (this.response) {
35
+ this.response.generate(context, writer, selection);
36
+ }
37
+ trace(context, '<- [response:generate]', `-> out: ${this.parent.name}`);
38
+ context.leave(this);
39
+ }
40
+ select(context, writer, selection) {
41
+ trace(context, '-> [response:select]', `-> in: ${this.parent.name}`);
42
+ if (this.response) {
43
+ this.response.select(context, writer, selection);
44
+ }
45
+ trace(context, '<- [response:select]', `-> out: ${this.parent.name}`);
46
+ }
47
+ }
48
+ //# sourceMappingURL=response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/oas/nodes/response.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAS,IAAI,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,OAAO,QAAS,SAAQ,IAAI;IACzB,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,IAAI,CAAC,QAAQ,GAAG,O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E,sBAAsB,EAAE,WAAW,IAAI,CAAC,MAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACzE,CAAC;CACF","sourcesContent":["import { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Factory } from './factory.js';\nimport { IType, Type } from './type.js';\n\nexport class Response 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, '-> [get:visit]', 'in ' + this.name);\n\n this.response = Factory.fromSchema(this, this.schema);\n trace(context, ' [get:visit]', 'array type: ' + this.response.id);\n this.visited = true;\n\n trace(context, '<- [get: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, '-> [response:generate]', `-> in: ${this.parent!.name}`);\n\n if (this.response) {\n this.response.generate(context, writer, selection);\n }\n\n trace(context, '<- [response:generate]', `-> out: ${this.parent!.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]): void {\n trace(context, '-> [response:select]', `-> in: ${this.parent!.name}`);\n\n if (this.response) {\n this.response.select(context, writer, selection);\n }\n\n trace(context, '<- [response:select]', `-> out: ${this.parent!.name}`);\n }\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import { SchemaObject } from 'oas/types';
2
+ import { OasContext } from '../oasContext.js';
3
+ import { Writer } from '../io/writer.js';
4
+ import { IType, Type } from './type.js';
5
+ export declare class Scalar extends Type {
6
+ schema: SchemaObject;
7
+ constructor(parent: IType | undefined, name: string, schema: SchemaObject);
8
+ visit(_context: OasContext): void;
9
+ forPrompt(_context: OasContext): string;
10
+ generate(context: OasContext, writer: Writer, selection: string[]): void;
11
+ select(context: OasContext, writer: Writer, selection: string[]): void;
12
+ }