apollo-conn-gen 0.1.1 → 0.2.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.
- package/dist/oas/io/writer.d.ts +1 -1
- package/dist/oas/io/writer.js +8 -43
- package/dist/oas/io/writer.js.map +1 -1
- package/dist/oas/nodes/comp.d.ts +1 -1
- package/dist/oas/nodes/comp.js +7 -5
- package/dist/oas/nodes/comp.js.map +1 -1
- package/dist/oas/nodes/factory.js +21 -3
- package/dist/oas/nodes/factory.js.map +1 -1
- package/dist/oas/nodes/get.js +3 -1
- package/dist/oas/nodes/get.js.map +1 -1
- package/dist/oas/nodes/internal.d.ts +1 -0
- package/dist/oas/nodes/internal.js +1 -0
- package/dist/oas/nodes/internal.js.map +1 -1
- package/dist/oas/nodes/propArray.d.ts +1 -1
- package/dist/oas/nodes/propArray.js +12 -4
- package/dist/oas/nodes/propArray.js.map +1 -1
- package/dist/oas/nodes/propComp.d.ts +16 -0
- package/dist/oas/nodes/propComp.js +73 -0
- package/dist/oas/nodes/propComp.js.map +1 -0
- package/dist/oas/nodes/propObj.js +4 -0
- package/dist/oas/nodes/propObj.js.map +1 -1
- package/dist/oas/nodes/propScalar.js +3 -0
- package/dist/oas/nodes/propScalar.js.map +1 -1
- package/dist/oas/nodes/response.js +11 -3
- package/dist/oas/nodes/response.js.map +1 -1
- package/dist/oas/nodes/typeUtils.d.ts +2 -0
- package/dist/oas/nodes/typeUtils.js +11 -2
- package/dist/oas/nodes/typeUtils.js.map +1 -1
- package/dist/oas/nodes/union.d.ts +4 -1
- package/dist/oas/nodes/union.js +111 -56
- package/dist/oas/nodes/union.js.map +1 -1
- package/dist/oas/oasContext.d.ts +6 -1
- package/dist/oas/oasContext.js +10 -4
- package/dist/oas/oasContext.js.map +1 -1
- package/dist/tests/runners.js +3 -2
- package/dist/tests/runners.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/oas/nodes/internal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/oas/nodes/internal.ts"],"names":[],"mappings":"AA8BA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["// -- internal.js --\nimport { IType } from './iType.js';\nimport { Type } from './type.js';\nimport { Prop } from './prop.js';\nimport { Param } from './param.js';\nimport { PropArray } from './propArray.js';\nimport { PropObj } from './propObj.js';\nimport { PropComp } from './propComp.js';\nimport { PropRef } from './propRef.js';\nimport { PropScalar } from './propScalar.js';\nimport { ReferenceObject } from './referenceObject.js';\nimport { Arr } from './arr.js';\nimport { CircularRef } from './circularRef.js';\nimport { Composed } from './comp.js';\nimport { En } from './en.js';\nimport { Factory } from './factory.js';\nimport { Get } from './get.js';\nimport { Post } from './post.js';\nimport { Put } from './put.js';\nimport { Patch } from './patch.js';\nimport { Delete } from './delete.js';\nimport { Body } from './body.js';\nimport { Obj } from './obj.js';\nimport { Ref } from './ref.js';\nimport { Response } from './response.js';\nimport { Scalar } from './scalar.js';\nimport { Union } from './union.js';\nimport { T } from './typeUtils.js';\nimport { Op } from './op.js';\n\nexport * from './iType.js';\nexport { Type } from './type.js';\nexport { type ReferenceObject } from './referenceObject.js';\nexport { Prop } from './prop.js';\nexport { Param } from './param.js';\nexport { Arr } from './arr.js';\nexport { CircularRef } from './circularRef.js';\nexport { Composed } from './comp.js';\nexport { En } from './en.js';\nexport { Factory } from './factory.js';\nexport { Get } from './get.js';\nexport { Post } from './post.js';\nexport { Put } from './put.js';\nexport { Patch } from './patch.js';\nexport { Delete } from './delete.js';\nexport { Body } from './body.js';\nexport { Obj } from './obj.js';\nexport { Ref } from './ref.js';\nexport { Response } from './response.js';\nexport { Scalar } from './scalar.js';\nexport { Union } from './union.js';\nexport { PropArray } from './propArray.js';\nexport { PropObj } from './propObj.js';\nexport { PropComp } from './propComp.js';\nexport { PropRef } from './propRef.js';\nexport { PropScalar } from './propScalar.js';\nexport { T } from './typeUtils.js';\nexport { type Op } from './op.js';\n"]}
|
|
@@ -10,5 +10,5 @@ export declare class PropArray extends Prop {
|
|
|
10
10
|
add(child: IType): void;
|
|
11
11
|
forPrompt(context: OasContext): string;
|
|
12
12
|
select(context: OasContext, writer: Writer, selection: string[]): void;
|
|
13
|
-
needsBrackets(child
|
|
13
|
+
needsBrackets(child?: IType): boolean;
|
|
14
14
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Factory, Prop, PropObj, PropRef } from './internal.js';
|
|
1
|
+
import { Factory, Prop, PropComp, PropObj, PropRef } from './internal.js';
|
|
2
2
|
import { trace } from '../log/trace.js';
|
|
3
3
|
import { Naming } from '../utils/naming.js';
|
|
4
4
|
export class PropArray extends Prop {
|
|
@@ -55,18 +55,26 @@ export class PropArray extends Prop {
|
|
|
55
55
|
context.enter(this);
|
|
56
56
|
}
|
|
57
57
|
// Select each child of the items Prop.
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
if (this.needsBrackets(this.items)) {
|
|
59
|
+
for (const child of this.items.children) {
|
|
60
|
+
child.select(context, writer, selection);
|
|
61
|
+
}
|
|
60
62
|
}
|
|
61
63
|
if (this.needsBrackets(this.items)) {
|
|
62
64
|
context.leave(this);
|
|
63
65
|
writer.append(' '.repeat(context.indent + context.stack.length)).append('}');
|
|
64
66
|
}
|
|
67
|
+
// writer.append('\n');
|
|
68
|
+
if (context.generateOptions.debugParentInSelection) {
|
|
69
|
+
writer.append(' # ').append(Naming.getRefName(this.parent.name));
|
|
70
|
+
}
|
|
65
71
|
writer.append('\n');
|
|
66
72
|
trace(context, '<- [prop:array:select]', 'out');
|
|
67
73
|
}
|
|
68
74
|
needsBrackets(child) {
|
|
69
|
-
|
|
75
|
+
if (!child)
|
|
76
|
+
return false;
|
|
77
|
+
return child instanceof PropRef || child instanceof PropObj || child instanceof PropComp;
|
|
70
78
|
}
|
|
71
79
|
}
|
|
72
80
|
//# sourceMappingURL=propArray.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propArray.js","sourceRoot":"","sources":["../../../src/oas/nodes/propArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"propArray.js","sourceRoot":"","sources":["../../../src/oas/nodes/propArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAU,MAAM,eAAe,CAAC;AACzF,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,OAAO,SAAU,SAAQ,IAAI;IAC1B,KAAK,CAAQ;IAEpB,IAAI,EAAE;QACJ,OAAO,eAAe,IAAI,CAAC,IAAI,EAAE,CAAC;IACpC,CAAC;IAEe,KAAK,CAAC,OAAmB;QACvC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO;QACT,CAAC;QAED,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpB,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,IAAI,CAAC,CAAC;QAE9C,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/D,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QAEpB,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,KAAK,CAAC,CAAC;QAC/C,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAEM,QAAQ,CAAC,KAAW;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,K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AU,CAAC,IAAI,CAAC,MAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEpB,KAAK,CAAC,OAAO,EAAE,wBAAwB,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC;IAEM,aAAa,CAAC,KAAa;QAChC,IAAI,CAAC,KAAK;YAAE,OAAO,KAAK,CAAC;QACzB,OAAO,KAAK,YAAY,OAAO,IAAI,KAAK,YAAY,OAAO,IAAI,KAAK,YAAY,QAAQ,CAAC;IAC3F,CAAC;CACF","sourcesContent":["import { Factory, IType, Prop, PropComp, PropObj, PropRef, Scalar } from './internal.js';\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 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 if (this.needsBrackets(this.items)) {\n for (const child of this.items!.children) {\n child.select(context, writer, selection);\n }\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 if (context.generateOptions.debugParentInSelection) {\n writer.append(' # ').append(Naming.getRefName(this.parent!.name));\n }\n\n writer.append('\\n');\n\n trace(context, '<- [prop:array:select]', 'out');\n }\n\n public needsBrackets(child?: IType): boolean {\n if (!child) return false;\n return child instanceof PropRef || child instanceof PropObj || child instanceof PropComp;\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IType } from './internal.js';
|
|
2
|
+
import { Prop } from './prop.js';
|
|
3
|
+
import { SchemaObject } from 'oas/types';
|
|
4
|
+
import { OasContext } from '../oasContext.js';
|
|
5
|
+
import { Writer } from '../io/writer.js';
|
|
6
|
+
export declare class PropComp extends Prop {
|
|
7
|
+
schema: SchemaObject;
|
|
8
|
+
comp?: IType;
|
|
9
|
+
constructor(parent: IType, name: string, schema: SchemaObject);
|
|
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,73 @@
|
|
|
1
|
+
import { Obj, Union } from './internal.js';
|
|
2
|
+
import { Prop } from './prop.js';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import { trace } from '../log/trace.js';
|
|
5
|
+
import { Composed } from './comp.js';
|
|
6
|
+
import { Naming } from '../utils/naming.js';
|
|
7
|
+
export class PropComp extends Prop {
|
|
8
|
+
schema;
|
|
9
|
+
comp;
|
|
10
|
+
constructor(parent, name, schema) {
|
|
11
|
+
super(parent, name, schema);
|
|
12
|
+
this.schema = schema;
|
|
13
|
+
}
|
|
14
|
+
forPrompt(_context) {
|
|
15
|
+
const type = this.schema.oneOf ? 'One Of' : this.schema.allOf ? 'All Of' : 'Unknown';
|
|
16
|
+
return _.lowerFirst(this.name) + ': ' + Naming.getRefName(this.comp.name) + ` (${type})`;
|
|
17
|
+
}
|
|
18
|
+
get id() {
|
|
19
|
+
return 'prop:comp:' + this.name;
|
|
20
|
+
}
|
|
21
|
+
visit(context) {
|
|
22
|
+
if (this.visited) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
context.enter(this);
|
|
26
|
+
const comp = this.comp;
|
|
27
|
+
trace(context, '-> [prop-comp:visit]', 'in ' + this.name + ', obj: ' + comp.name);
|
|
28
|
+
comp.visit(context);
|
|
29
|
+
if (!this.children.includes(comp)) {
|
|
30
|
+
this.add(comp);
|
|
31
|
+
}
|
|
32
|
+
this.visited = true;
|
|
33
|
+
trace(context, '<- [prop-comp:visit]', 'out ' + this.name + ', obj: ' + comp.name);
|
|
34
|
+
context.leave(this);
|
|
35
|
+
}
|
|
36
|
+
getValue(_context) {
|
|
37
|
+
// we'll make an assumption here: that if the child obj has no properties,
|
|
38
|
+
// then it's a free-form JSON payload. not sure if the right one, but it will
|
|
39
|
+
// compose for now.
|
|
40
|
+
if (_.isEmpty(this.comp?.props))
|
|
41
|
+
return 'JSON';
|
|
42
|
+
// return Naming.genTypeName(this.name);
|
|
43
|
+
return Naming.genTypeName(this.comp.name) + this.comp.nameSuffix();
|
|
44
|
+
}
|
|
45
|
+
select(context, writer, selection) {
|
|
46
|
+
const comp = this.comp;
|
|
47
|
+
trace(context, '-> [prop-comp:select]', 'in ' + this.name + ', obj: ' + comp.name);
|
|
48
|
+
const fieldName = this.name;
|
|
49
|
+
const sanitised = Naming.sanitiseFieldForSelect(fieldName);
|
|
50
|
+
writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);
|
|
51
|
+
if (this.needsBrackets(comp)) {
|
|
52
|
+
writer.append(' {').append('\n');
|
|
53
|
+
context.enter(this);
|
|
54
|
+
}
|
|
55
|
+
for (const child of this.children) {
|
|
56
|
+
child.select(context, writer, selection);
|
|
57
|
+
}
|
|
58
|
+
if (this.needsBrackets(comp)) {
|
|
59
|
+
context.leave(this);
|
|
60
|
+
writer.append(' '.repeat(context.indent + context.stack.length)).append('}');
|
|
61
|
+
}
|
|
62
|
+
// writer.append('\n');
|
|
63
|
+
if (context.generateOptions.debugParentInSelection) {
|
|
64
|
+
writer.append(' # ').append(Naming.getRefName(this.parent.name));
|
|
65
|
+
}
|
|
66
|
+
writer.append('\n');
|
|
67
|
+
trace(context, '<- [prop-comp:select]', 'out ' + this.name + ', obj: ' + comp?.name);
|
|
68
|
+
}
|
|
69
|
+
needsBrackets(child) {
|
|
70
|
+
return (child instanceof Obj || child instanceof Union || child instanceof Composed) && !_.isEmpty(child.props);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=propComp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propComp.js","sourceRoot":"","sources":["../../../src/oas/nodes/propComp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,GAAG,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,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,QAAS,SAAQ,IA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M,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QAC3C,CAAC;QAED,IAAI,IAAI,CAAC,aAAa,CAAC,IAAK,CAAC,EAAE,CAAC;YAC9B,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACpB,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;QAC/E,CAAC;QACD,uBAAuB;QACvB,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;QAEpB,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,MAAM,GAAG,IAAI,CAAC,IAAI,GAAG,SAAS,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC;IACvF,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 } from './internal.js';\nimport { Prop } from './prop.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 PropComp extends Prop {\n public comp?: IType;\n\n constructor(\n parent: IType,\n name: string,\n public schema: SchemaObject,\n ) {\n super(parent, name, schema);\n }\n\n public forPrompt(_context: OasContext): string {\n const type: string = this.schema.oneOf ? 'One Of' : this.schema.allOf ? 'All Of' : 'Unknown';\n return _.lowerFirst(this.name) + ': ' + Naming.getRefName(this.comp!.name) + ` (${type})`;\n }\n\n get id(): string {\n return 'prop:comp:' + this.name;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n const comp = this.comp!;\n trace(context, '-> [prop-comp:visit]', 'in ' + this.name + ', obj: ' + comp.name);\n\n comp.visit(context);\n if (!this.children.includes(comp)) {\n this.add(comp);\n }\n this.visited = true;\n\n trace(context, '<- [prop-comp:visit]', 'out ' + this.name + ', obj: ' + comp.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.comp?.props)) return 'JSON';\n\n // return Naming.genTypeName(this.name);\n return Naming.genTypeName(this.comp!.name!) + (this.comp as Composed).nameSuffix();\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n const comp = this.comp!;\n trace(context, '-> [prop-comp:select]', 'in ' + this.name + ', obj: ' + comp.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(comp!)) {\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(comp!)) {\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-comp:select]', 'out ' + this.name + ', obj: ' + comp?.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"]}
|
|
@@ -63,6 +63,10 @@ export class PropObj extends Prop {
|
|
|
63
63
|
context.leave(this);
|
|
64
64
|
writer.append(' '.repeat(context.indent + context.stack.length)).append('}');
|
|
65
65
|
}
|
|
66
|
+
// writer.append('\n');
|
|
67
|
+
if (context.generateOptions.debugParentInSelection) {
|
|
68
|
+
writer.append(' # ').append(Naming.getRefName(this.parent.name));
|
|
69
|
+
}
|
|
66
70
|
writer.append('\n');
|
|
67
71
|
trace(context, '<- [prop-obj:select]', 'out ' + this.name + ', obj: ' + this.obj?.name);
|
|
68
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propObj.js","sourceRoot":"","sources":["../../../src/oas/nodes/propObj.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,GAAG,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,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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AE,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 } 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\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,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,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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AG,CAAC,CAAC;QAC/E,CAAC;QACD,uBAAuB;QACvB,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;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 } 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"]}
|
|
@@ -39,6 +39,9 @@ export class PropScalar extends Prop {
|
|
|
39
39
|
for (const child of this.children) {
|
|
40
40
|
child.select(context, writer, selection);
|
|
41
41
|
}
|
|
42
|
+
if (context.generateOptions.debugParentInSelection) {
|
|
43
|
+
writer.append(' # ').append(Naming.getRefName(this.parent.name));
|
|
44
|
+
}
|
|
42
45
|
writer.append('\n');
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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AAE,MAAc,EAAE,SAAmB;QACpE,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,IAAI,CAAC,IAAI,CAAC,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,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 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,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;YACjB,OAAO;QACT,CAAC;QAED,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YACtD,gCAAgC;YAChC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAEM,QAAQ,CAAC,OAAmB;QACjC,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAEM,SAAS,CAAC,OAAmB;QAClC,OAAO,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;IACtC,CAAC;IAEM,MAAM,CAAC,OAAmB,EAAE,MAAc,EAAE,SAAmB;QACpE,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,IAAI,CAAC,IAAI,CAAC,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 } 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,4 +1,4 @@
|
|
|
1
|
-
import { Factory, Type } from './internal.js';
|
|
1
|
+
import { Factory, Type, T } from './internal.js';
|
|
2
2
|
import { trace } from '../log/trace.js';
|
|
3
3
|
export class Response extends Type {
|
|
4
4
|
schema;
|
|
@@ -38,8 +38,16 @@ export class Response extends Type {
|
|
|
38
38
|
}
|
|
39
39
|
select(context, writer, selection) {
|
|
40
40
|
trace(context, '-> [res:select]', `-> in: ${this.parent.name}`);
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const response = this.response;
|
|
42
|
+
if (response) {
|
|
43
|
+
if (T.isScalar(response)) {
|
|
44
|
+
// best attempt to just copy the value that comes out of the service. most likely the
|
|
45
|
+
// value will have to be replaced by a GQL type. In fact, we could potentially use SYN_ here but
|
|
46
|
+
// it will have to do for now.
|
|
47
|
+
writer.append(' '.repeat(context.indent)).append('$\n');
|
|
48
|
+
}
|
|
49
|
+
else
|
|
50
|
+
response.select(context, writer, selection);
|
|
43
51
|
}
|
|
44
52
|
trace(context, '<- [res:select]', `-> out: ${this.parent.name}`);
|
|
45
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/oas/nodes/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,IAAI,EAAE,MAAM,eAAe,CA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AAC,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 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, '-> [res:visit]', 'in ' + this.name);\n\n this.response = Factory.fromSchema(this, this.schema);\n trace(context, ' [res:visit]', 'array type: ' + this.response.id);\n this.visited = true;\n\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"]}
|
|
@@ -4,4 +4,6 @@ export declare class T {
|
|
|
4
4
|
static isPropScalar(type: IType): boolean;
|
|
5
5
|
static traverse(node: IType, callback: (node: IType) => void): void;
|
|
6
6
|
static isMutationType(type: IType): boolean;
|
|
7
|
+
static isScalar(type: IType): boolean;
|
|
8
|
+
static containers(node: IType): IType[];
|
|
7
9
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { CircularRef, En, Obj, PropArray, PropScalar } from './internal.js';
|
|
1
|
+
import { CircularRef, En, Obj, Prop, PropArray, PropScalar, Scalar } from './internal.js';
|
|
2
2
|
import _ from 'lodash';
|
|
3
3
|
export class T {
|
|
4
4
|
static isLeaf(type) {
|
|
5
|
-
return (type instanceof
|
|
5
|
+
return (type instanceof Scalar ||
|
|
6
|
+
type instanceof PropScalar ||
|
|
6
7
|
type instanceof En ||
|
|
7
8
|
type instanceof CircularRef ||
|
|
8
9
|
(type instanceof PropArray && type.items instanceof PropScalar) ||
|
|
@@ -26,5 +27,13 @@ export class T {
|
|
|
26
27
|
type.id.startsWith('patch:') ||
|
|
27
28
|
type.id.startsWith('del:'));
|
|
28
29
|
}
|
|
30
|
+
static isScalar(type) {
|
|
31
|
+
return type.id.startsWith('scalar:');
|
|
32
|
+
}
|
|
33
|
+
static containers(node) {
|
|
34
|
+
return Array.from(node.children.values())
|
|
35
|
+
.filter((child) => !(child instanceof Prop))
|
|
36
|
+
.map((child) => (child.id.startsWith('ref:') ? child.refType : child));
|
|
37
|
+
}
|
|
29
38
|
}
|
|
30
39
|
//# 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,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
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,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ACvC,CAAC;IAEM,MAAM,CAAC,UAAU,CAAC,IAAW;QAClC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;aACtC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,CAAC;aAC3C,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"]}
|
|
@@ -4,13 +4,16 @@ import { OasContext } from '../oasContext.js';
|
|
|
4
4
|
import { Writer } from '../io/writer.js';
|
|
5
5
|
export declare class Union extends Type {
|
|
6
6
|
consolidated: boolean;
|
|
7
|
-
get id(): string;
|
|
8
7
|
schemas: SchemaObject[];
|
|
8
|
+
discriminator?: string;
|
|
9
9
|
constructor(parent: IType, name: string, schemas: SchemaObject[], consolidated?: boolean);
|
|
10
|
+
get id(): string;
|
|
10
11
|
forPrompt(_context: OasContext): string;
|
|
11
12
|
visit(context: OasContext): void;
|
|
12
13
|
generate(context: OasContext, writer: Writer, selection: string[]): void;
|
|
13
14
|
select(context: OasContext, writer: Writer, selection: string[]): void;
|
|
14
15
|
consolidate(selection: string[]): Set<string>;
|
|
16
|
+
private updatePropName;
|
|
15
17
|
private visitProperties;
|
|
18
|
+
private updateName;
|
|
16
19
|
}
|
package/dist/oas/nodes/union.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { Factory,
|
|
1
|
+
import { Factory, Ref, T, Type } from './internal.js';
|
|
2
2
|
import { trace } from '../log/trace.js';
|
|
3
3
|
import { Naming } from '../utils/naming.js';
|
|
4
|
+
import _ from 'lodash';
|
|
4
5
|
export class Union extends Type {
|
|
5
6
|
consolidated;
|
|
6
|
-
get id() {
|
|
7
|
-
return `union:${this.name}`;
|
|
8
|
-
}
|
|
9
7
|
schemas;
|
|
8
|
+
discriminator;
|
|
10
9
|
constructor(parent, name, schemas, consolidated = false) {
|
|
11
10
|
super(parent, name);
|
|
12
11
|
this.consolidated = consolidated;
|
|
13
12
|
this.schemas = schemas;
|
|
13
|
+
this.discriminator = _.get(parent.schema, 'discriminator')?.propertyName;
|
|
14
|
+
this.updateName();
|
|
15
|
+
}
|
|
16
|
+
get id() {
|
|
17
|
+
return `union:${this.name}`;
|
|
14
18
|
}
|
|
15
19
|
forPrompt(_context) {
|
|
16
20
|
return `${Naming.getRefName(this.name)} (Union)`;
|
|
@@ -51,81 +55,132 @@ export class Union extends Type {
|
|
|
51
55
|
child.generate(context, writer, selection);
|
|
52
56
|
}
|
|
53
57
|
}
|
|
58
|
+
// generate traditional union
|
|
54
59
|
else {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
60
|
+
const name = _.upperFirst(Naming.getRefName(this.name));
|
|
61
|
+
if (!context.generateOptions.consolidateUnion) {
|
|
62
|
+
this.children.forEach((child) => {
|
|
63
|
+
if (child instanceof Ref) {
|
|
64
|
+
child.refType?.generate(context, writer, selection);
|
|
65
|
+
}
|
|
66
|
+
else
|
|
67
|
+
child.generate(context, writer, selection);
|
|
68
|
+
});
|
|
69
|
+
// const selected = this.selectedProps(selection);
|
|
70
|
+
writer
|
|
71
|
+
.append('union ')
|
|
72
|
+
.append(name)
|
|
73
|
+
.append(this.nameSuffix())
|
|
74
|
+
.append(' = ')
|
|
75
|
+
.append(this.children.map((child) => Naming.getRefName(child.name)).join(' | '))
|
|
76
|
+
.append('\n\n');
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// When generating this union in GQL it might look like:
|
|
80
|
+
// union MyUnion = Type1 | Type2 | Type3
|
|
81
|
+
writer.append('#### NOT SUPPORTED YET BY CONNECTORS!!! union ').append(name).append(' = ');
|
|
82
|
+
const childrenNames = this.children.map((child) => Naming.getRefName(child.name)).join(' | ');
|
|
83
|
+
writer.append(childrenNames).append('\n\n');
|
|
84
|
+
trace(context, ' [union::generate]', `[union] -> object: ${this.name}`);
|
|
85
|
+
writer
|
|
86
|
+
.append(this.kind + ' ')
|
|
87
|
+
.append(name)
|
|
88
|
+
.append(this.nameSuffix())
|
|
89
|
+
.append(' { #### replacement for Union ')
|
|
90
|
+
.append(name)
|
|
91
|
+
.append('\n');
|
|
92
|
+
const selected = this.selectedProps(selection);
|
|
93
|
+
for (const prop of selected) {
|
|
94
|
+
trace(context, ' [union::generate]', `-> property: ${prop.name} (parent: ${prop.parent.name})`);
|
|
95
|
+
prop.generate(context, writer, selection);
|
|
96
|
+
}
|
|
97
|
+
writer.append('} \n### End replacement for ').append(this.name).append('\n\n');
|
|
75
98
|
}
|
|
76
|
-
writer.append('} \n### End replacement for ').append(this.name).append('\n\n');
|
|
77
99
|
}
|
|
78
100
|
trace(context, '<- [union::generate]', 'out: ' + schemas);
|
|
79
101
|
context.leave(this);
|
|
80
102
|
}
|
|
81
103
|
select(context, writer, selection) {
|
|
82
104
|
trace(context, '-> [union::select]', `-> in: ${this.name}`);
|
|
83
|
-
if (
|
|
84
|
-
this.
|
|
105
|
+
if (context.generateOptions.consolidateUnion) {
|
|
106
|
+
if (!this.consolidated) {
|
|
107
|
+
this.consolidate(selection);
|
|
108
|
+
}
|
|
109
|
+
const selected = this.selectedProps(selection);
|
|
110
|
+
for (const prop of selected) {
|
|
111
|
+
prop.select(context, writer, selection);
|
|
112
|
+
}
|
|
85
113
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
114
|
+
else {
|
|
115
|
+
// collect all property names from children and write them here
|
|
116
|
+
this.children.forEach((child) => {
|
|
117
|
+
child.select(context, writer, selection);
|
|
118
|
+
});
|
|
89
119
|
}
|
|
120
|
+
/* TODO:
|
|
121
|
+
dataPoints: dataFormat->match(
|
|
122
|
+
["raw", $.dataPoints],
|
|
123
|
+
["normal", $.dataPoints {
|
|
124
|
+
priceDateTime
|
|
125
|
+
# all other fields
|
|
126
|
+
}],
|
|
127
|
+
[@, $ { # optimized
|
|
128
|
+
priceDateTime
|
|
129
|
+
# all other fields
|
|
130
|
+
}
|
|
131
|
+
])
|
|
132
|
+
*/
|
|
90
133
|
trace(context, '<- [union::select]', `-> out: ${this.name}`);
|
|
91
134
|
}
|
|
92
135
|
consolidate(selection) {
|
|
93
136
|
const ids = new Set();
|
|
94
|
-
|
|
95
|
-
const
|
|
137
|
+
const props = [];
|
|
138
|
+
const discriminator = this.discriminator;
|
|
139
|
+
const queue = T.containers(this);
|
|
96
140
|
while (queue.length > 0) {
|
|
97
141
|
const node = queue.shift();
|
|
98
|
-
ids.add(node
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
142
|
+
ids.add(node.id);
|
|
143
|
+
// process each prop, renaming the ones that have a name clash with others. if a selection
|
|
144
|
+
// is passed, then only add those, otherwise add all.
|
|
145
|
+
for (const prop of _.isEmpty(selection)
|
|
146
|
+
? Array.from(node.props.values()) // include all
|
|
147
|
+
: Array.from(node.props.values())
|
|
148
|
+
.filter((i) => selection.find((s) => s.startsWith(i.path()))) // include selected only
|
|
149
|
+
.filter((i) => i.name !== discriminator)) {
|
|
150
|
+
// remove discriminator props
|
|
151
|
+
// rename every prop there is if there's a conflict, then add it to props
|
|
152
|
+
this.updatePropName(prop, props, selection);
|
|
153
|
+
props.push(prop);
|
|
108
154
|
}
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
const children = Array.from(node.children.values()).filter((child) => !(child instanceof Prop));
|
|
112
|
-
queue.push(...children);
|
|
155
|
+
// find the other containers and add them to the queue
|
|
156
|
+
queue.push(...T.containers(node));
|
|
113
157
|
}
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
|
|
158
|
+
// add the discriminator, if we have one
|
|
159
|
+
if (discriminator)
|
|
160
|
+
props.push(this.children[0].props.get(discriminator));
|
|
161
|
+
// and finally sort the props and copy them to our original
|
|
162
|
+
props.sort((a, b) => a.name.localeCompare(b.name)).forEach((prop) => this.props.set(prop.name, prop));
|
|
117
163
|
// and return the types.ts we've used
|
|
164
|
+
this.consolidated = true;
|
|
118
165
|
return ids;
|
|
119
166
|
}
|
|
167
|
+
updatePropName(prop, props, selection) {
|
|
168
|
+
let name = prop.name;
|
|
169
|
+
let counter = 0;
|
|
170
|
+
while (props.find((p) => p.name === name)) {
|
|
171
|
+
name = `${prop.name}${++counter}`;
|
|
172
|
+
}
|
|
173
|
+
if (name !== prop.name) {
|
|
174
|
+
prop.name = name;
|
|
175
|
+
// we need to extend the selection too, because a new property has been created
|
|
176
|
+
selection.push(prop.path());
|
|
177
|
+
}
|
|
178
|
+
}
|
|
120
179
|
visitProperties(_context) {
|
|
121
180
|
// do nothing?
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
//
|
|
126
|
-
// if (!this.children.includes(prop))
|
|
127
|
-
// this.add(prop);
|
|
128
|
-
// }
|
|
181
|
+
}
|
|
182
|
+
updateName() {
|
|
183
|
+
this.name = this.parent.name + `Union`;
|
|
129
184
|
}
|
|
130
185
|
}
|
|
131
186
|
//# sourceMappingURL=union.js.map
|