apollo-conn-gen 0.2.1 → 0.3.1
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/cli/oas-helpers/index.js +5 -5
- package/dist/cli/oas-helpers/index.js.map +1 -1
- package/dist/cli/oas.js +5 -0
- package/dist/cli/oas.js.map +1 -1
- package/dist/oas/index.d.ts +2 -2
- package/dist/oas/index.js +2 -2
- package/dist/oas/index.js.map +1 -1
- package/dist/oas/io/writer.d.ts +1 -2
- package/dist/oas/io/writer.js +14 -17
- package/dist/oas/io/writer.js.map +1 -1
- package/dist/oas/nodes/arr.js +1 -1
- package/dist/oas/nodes/arr.js.map +1 -1
- package/dist/oas/nodes/body.js +3 -1
- package/dist/oas/nodes/body.js.map +1 -1
- package/dist/oas/nodes/circularRef.d.ts +1 -1
- package/dist/oas/nodes/circularRef.js.map +1 -1
- package/dist/oas/nodes/comp.d.ts +2 -0
- package/dist/oas/nodes/comp.js +44 -7
- package/dist/oas/nodes/comp.js.map +1 -1
- package/dist/oas/nodes/en.d.ts +1 -1
- package/dist/oas/nodes/en.js +3 -3
- package/dist/oas/nodes/en.js.map +1 -1
- package/dist/oas/nodes/factory.d.ts +6 -3
- package/dist/oas/nodes/factory.js +149 -105
- package/dist/oas/nodes/factory.js.map +1 -1
- package/dist/oas/nodes/iType.d.ts +2 -2
- package/dist/oas/nodes/iType.js.map +1 -1
- package/dist/oas/nodes/internal.d.ts +3 -3
- package/dist/oas/nodes/internal.js +3 -3
- package/dist/oas/nodes/internal.js.map +1 -1
- package/dist/oas/nodes/obj.d.ts +1 -1
- package/dist/oas/nodes/obj.js +35 -44
- package/dist/oas/nodes/obj.js.map +1 -1
- package/dist/oas/nodes/param.js +3 -1
- package/dist/oas/nodes/param.js.map +1 -1
- package/dist/oas/nodes/prop.d.ts +1 -1
- package/dist/oas/nodes/prop.js +4 -1
- package/dist/oas/nodes/prop.js.map +1 -1
- package/dist/oas/nodes/propArray.d.ts +2 -3
- package/dist/oas/nodes/propArray.js +13 -19
- package/dist/oas/nodes/propArray.js.map +1 -1
- package/dist/oas/nodes/propCircRef.d.ts +14 -0
- package/dist/oas/nodes/propCircRef.js +35 -0
- package/dist/oas/nodes/propCircRef.js.map +1 -0
- package/dist/oas/nodes/propComp.d.ts +1 -2
- package/dist/oas/nodes/propComp.js +5 -12
- package/dist/oas/nodes/propComp.js.map +1 -1
- package/dist/oas/nodes/propEn.d.ts +15 -0
- package/dist/oas/nodes/propEn.js +38 -0
- package/dist/oas/nodes/propEn.js.map +1 -0
- package/dist/oas/nodes/propObj.d.ts +1 -2
- package/dist/oas/nodes/propObj.js +4 -5
- package/dist/oas/nodes/propObj.js.map +1 -1
- package/dist/oas/nodes/propRef.d.ts +5 -4
- package/dist/oas/nodes/propRef.js +27 -21
- package/dist/oas/nodes/propRef.js.map +1 -1
- package/dist/oas/nodes/propScalar.d.ts +2 -3
- package/dist/oas/nodes/propScalar.js +11 -7
- package/dist/oas/nodes/propScalar.js.map +1 -1
- package/dist/oas/nodes/ref.d.ts +3 -0
- package/dist/oas/nodes/ref.js +8 -3
- package/dist/oas/nodes/ref.js.map +1 -1
- package/dist/oas/nodes/{response.d.ts → res.d.ts} +1 -1
- package/dist/oas/nodes/{response.js → res.js} +6 -4
- package/dist/oas/nodes/res.js.map +1 -0
- package/dist/oas/nodes/type.d.ts +2 -3
- package/dist/oas/nodes/type.js +3 -18
- package/dist/oas/nodes/type.js.map +1 -1
- package/dist/oas/nodes/typeUtils.d.ts +3 -0
- package/dist/oas/nodes/typeUtils.js +23 -4
- package/dist/oas/nodes/typeUtils.js.map +1 -1
- package/dist/oas/nodes/union.d.ts +0 -1
- package/dist/oas/nodes/union.js +62 -60
- package/dist/oas/nodes/union.js.map +1 -1
- package/dist/oas/oasContext.d.ts +3 -3
- package/dist/oas/oasContext.js +4 -7
- package/dist/oas/oasContext.js.map +1 -1
- package/dist/oas/oasGen.d.ts +5 -2
- package/dist/oas/oasGen.js +9 -6
- package/dist/oas/oasGen.js.map +1 -1
- package/dist/oas/prompts/prompt.js +11 -3
- package/dist/oas/prompts/prompt.js.map +1 -1
- package/dist/tests/runners.js +7 -3
- package/dist/tests/runners.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/oas/nodes/response.js.map +0 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Prop } from './internal.js';
|
|
2
|
+
import { Naming } from '../utils/naming.js';
|
|
3
|
+
import { trace } from '../log/trace.js';
|
|
4
|
+
export class PropEn extends Prop {
|
|
5
|
+
type;
|
|
6
|
+
constructor(parent, name, type, schema) {
|
|
7
|
+
super(parent, name, schema);
|
|
8
|
+
this.type = type;
|
|
9
|
+
}
|
|
10
|
+
get id() {
|
|
11
|
+
return 'prop:enum:' + this.name;
|
|
12
|
+
}
|
|
13
|
+
generate(context, writer, _selection) {
|
|
14
|
+
super.generate(context, writer, _selection);
|
|
15
|
+
}
|
|
16
|
+
visit(context) {
|
|
17
|
+
// do nothing
|
|
18
|
+
}
|
|
19
|
+
forPrompt(context) {
|
|
20
|
+
return `[prop] enum: ${Naming.getRefName(this.type)}`;
|
|
21
|
+
}
|
|
22
|
+
getValue(_context) {
|
|
23
|
+
return Naming.getRefName(this.type);
|
|
24
|
+
}
|
|
25
|
+
dependencies() {
|
|
26
|
+
return Array.from(this.children.values());
|
|
27
|
+
}
|
|
28
|
+
select(context, writer, selection) {
|
|
29
|
+
trace(context, ' [prop:select]', this.name);
|
|
30
|
+
const sanitised = Naming.sanitiseFieldForSelect(this.name);
|
|
31
|
+
writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);
|
|
32
|
+
if (context.generateOptions.showParentInSelections) {
|
|
33
|
+
writer.append(' # ').append(Naming.getRefName(this.parent.name));
|
|
34
|
+
}
|
|
35
|
+
writer.append('\n');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=propEn.js.map
|
|
@@ -0,0 +1 @@
|
|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AAI,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,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 { SchemaObject } from 'oas/types';\nimport { IType, Prop } from './internal.js';\nimport { Writer } from '../io/writer.js';\nimport { OasContext } from '../oasContext.js';\nimport { Naming } from '../utils/naming.js';\nimport { trace } from '../log/trace.js';\n\nexport class PropEn extends Prop {\n private type: string;\n\n constructor(parent: IType, name: string, type: string, schema: SchemaObject) {\n super(parent, name, schema);\n this.type = type;\n }\n\n get id(): string {\n return 'prop:enum:' + this.name;\n }\n\n generate(context: OasContext, writer: Writer, _selection: string[]) {\n super.generate(context, writer, _selection);\n }\n\n public visit(context: OasContext): void {\n // do nothing\n }\n\n public forPrompt(context: OasContext): string {\n return `[prop] enum: ${Naming.getRefName(this.type)}`;\n }\n\n public getValue(_context: OasContext): string {\n return Naming.getRefName(this.type);\n }\n\n dependencies(): IType[] {\n return Array.from(this.children.values());\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]): void {\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 if (context.generateOptions.showParentInSelections) {\n writer.append(' # ').append(Naming.getRefName(this.parent!.name));\n }\n\n writer.append('\\n');\n }\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Obj, Union } from './internal.js';
|
|
2
|
-
import { Prop } from './internal.js';
|
|
1
|
+
import { Obj, Union, Prop } from './internal.js';
|
|
3
2
|
import _ from 'lodash';
|
|
4
3
|
import { trace } from '../log/trace.js';
|
|
5
4
|
import { Composed } from './comp.js';
|
|
@@ -20,7 +19,7 @@ export class PropObj extends Prop {
|
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
forPrompt(_context) {
|
|
23
|
-
return _.lowerFirst(this.name) + ': ' + Naming.getRefName(this.obj.name) + ' (Obj)';
|
|
22
|
+
return '[prop] ' + _.lowerFirst(this.name) + ': ' + Naming.getRefName(this.obj.name) + ' (Obj)';
|
|
24
23
|
}
|
|
25
24
|
get id() {
|
|
26
25
|
return 'prop:obj:' + this.name;
|
|
@@ -45,7 +44,7 @@ export class PropObj extends Prop {
|
|
|
45
44
|
// compose for now.
|
|
46
45
|
if (_.isEmpty(this.obj?.props))
|
|
47
46
|
return 'JSON';
|
|
48
|
-
return Naming.genTypeName(this.name);
|
|
47
|
+
return Naming.genTypeName(this.obj.name) + this.obj.nameSuffix();
|
|
49
48
|
}
|
|
50
49
|
select(context, writer, selection) {
|
|
51
50
|
trace(context, '-> [prop-obj:select]', 'in ' + this.name + ', obj: ' + this.obj.name);
|
|
@@ -64,7 +63,7 @@ export class PropObj extends Prop {
|
|
|
64
63
|
writer.append(' '.repeat(context.indent + context.stack.length)).append('}');
|
|
65
64
|
}
|
|
66
65
|
// writer.append('\n');
|
|
67
|
-
if (context.generateOptions.
|
|
66
|
+
if (context.generateOptions.showParentInSelections) {
|
|
68
67
|
writer.append(' # ').append(Naming.getRefName(this.parent.name));
|
|
69
68
|
}
|
|
70
69
|
writer.append('\n');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propObj.js","sourceRoot":"","sources":["../../../src/oas/nodes/propObj.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,GAAG,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3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AK,YAAY,KAAK,IAAI,KAAK,YAAY,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClH,CAAC;CACF","sourcesContent":["import { IType, Obj, Union, Prop } from './internal.js';\nimport _ from 'lodash';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { Composed } from './comp.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nexport class PropObj extends Prop {\n constructor(\n parent: IType,\n name: string,\n public schema: SchemaObject,\n public obj: IType,\n ) {\n super(parent, name, schema);\n if (!obj) {\n throw new Error('obj parameter is required');\n }\n\n // TODO: check if re-parenting is necessary?!?!\n if (obj.parent !== this) {\n obj.parent = this;\n }\n }\n\n public forPrompt(_context: OasContext): string {\n return '[prop] ' + _.lowerFirst(this.name) + ': ' + Naming.getRefName(this.obj.name) + ' (Obj)';\n }\n\n get id(): string {\n return 'prop:obj:' + this.name;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n trace(context, '-> [prop-obj:visit]', 'in ' + this.name + ', obj: ' + this.obj.name);\n\n this.obj.visit(context);\n if (!this.children.includes(this.obj)) {\n this.add(this.obj);\n }\n this.visited = true;\n\n trace(context, '<- [prop-obj:visit]', 'out ' + this.name + ', obj: ' + this.obj.name);\n context.leave(this);\n }\n\n public getValue(context: OasContext): string {\n // we'll make an assumption here: that if the child obj has no properties,\n // then it's a free-form JSON payload. not sure if the right one, but it will\n // compose for now.\n if (_.isEmpty(this.obj?.props)) return 'JSON';\n\n return Naming.genTypeName(this.obj!.name!) + (this.obj as Obj).nameSuffix();\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [prop-obj:select]', 'in ' + this.name + ', obj: ' + this.obj.name);\n\n const fieldName = this.name;\n const sanitised = Naming.sanitiseFieldForSelect(fieldName);\n\n writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);\n\n if (this.needsBrackets(this.obj!)) {\n writer.append(' {').append('\\n');\n context.enter(this);\n }\n\n for (const child of this.children) {\n child.select(context, writer, selection);\n }\n\n if (this.needsBrackets(this.obj!)) {\n context.leave(this);\n writer.append(' '.repeat(context.indent + context.stack.length)).append('}');\n }\n // writer.append('\\n');\n if (context.generateOptions.showParentInSelections) {\n writer.append(' # ').append(Naming.getRefName(this.parent!.name));\n }\n\n writer.append('\\n');\n\n trace(context, '<- [prop-obj:select]', 'out ' + this.name + ', obj: ' + this.obj?.name);\n }\n\n private needsBrackets(child: IType): boolean {\n return (child instanceof Obj || child instanceof Union || child instanceof Composed) && !_.isEmpty(child.props);\n }\n}\n"]}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { OasContext } from '../oasContext.js';
|
|
2
|
-
import { IType } from './internal.js';
|
|
3
|
-
import { Prop } from './internal.js';
|
|
2
|
+
import { Prop, IType } from './internal.js';
|
|
4
3
|
import { SchemaObject } from 'oas/types';
|
|
5
4
|
import { Writer } from '../io/writer.js';
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated No longer used
|
|
7
|
+
*/
|
|
6
8
|
export declare class PropRef extends Prop {
|
|
7
9
|
schema: SchemaObject;
|
|
8
10
|
ref: string;
|
|
9
11
|
get id(): string;
|
|
10
12
|
refType?: IType;
|
|
11
13
|
constructor(parent: IType | undefined, name: string, schema: SchemaObject, ref: string);
|
|
12
|
-
add(child: IType): void;
|
|
13
14
|
visit(context: OasContext): void;
|
|
14
15
|
getValue(_context: OasContext): string;
|
|
15
16
|
forPrompt(context: OasContext): string;
|
|
16
17
|
select(context: OasContext, writer: Writer, selection: string[]): void;
|
|
17
|
-
|
|
18
|
+
generateValue(context: OasContext, writer: Writer): void;
|
|
18
19
|
private needsBrackets;
|
|
19
20
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Arr,
|
|
2
|
-
import { Prop } from './internal.js';
|
|
1
|
+
import { Arr, Prop, Composed, Factory, Obj, Union } from './internal.js';
|
|
3
2
|
import _ from 'lodash';
|
|
4
3
|
import { trace } from '../log/trace.js';
|
|
5
4
|
import { Naming } from '../utils/naming.js';
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated No longer used
|
|
7
|
+
*/
|
|
6
8
|
export class PropRef extends Prop {
|
|
7
9
|
schema;
|
|
8
10
|
ref;
|
|
@@ -15,22 +17,25 @@ export class PropRef extends Prop {
|
|
|
15
17
|
this.schema = schema;
|
|
16
18
|
this.ref = ref;
|
|
17
19
|
}
|
|
18
|
-
add(child) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
20
|
+
/* public override add(child: IType): IType {
|
|
21
|
+
child.name = this.ref;
|
|
22
|
+
const paths: IType[] = this.ancestors();
|
|
23
|
+
const contains: boolean = paths.map((p) => p.id).includes(child.id);
|
|
24
|
+
|
|
25
|
+
trace(null, '-> [prop-ref:add]', 'contains child? ' + contains);
|
|
26
|
+
let added: IType = child;
|
|
27
|
+
if (contains) {
|
|
28
|
+
const ancestor: IType = paths[paths.map((p) => p.id).indexOf(child.id)];
|
|
29
|
+
const wrapper = Factory.fromCircularRef(this, ancestor);
|
|
30
|
+
added = super.add(wrapper);
|
|
31
|
+
this.visited = true;
|
|
32
|
+
this.refType = wrapper;
|
|
33
|
+
} else {
|
|
34
|
+
added = super.add(child);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return added;
|
|
38
|
+
}*/
|
|
34
39
|
visit(context) {
|
|
35
40
|
if (this.visited) {
|
|
36
41
|
return;
|
|
@@ -41,8 +46,9 @@ export class PropRef extends Prop {
|
|
|
41
46
|
if (!schema) {
|
|
42
47
|
throw new Error('Schema not found for ref: ' + this.ref);
|
|
43
48
|
}
|
|
44
|
-
const type = Factory.fromSchema(this, schema);
|
|
49
|
+
const type = Factory.fromSchema(context, this, schema);
|
|
45
50
|
if (!this.refType) {
|
|
51
|
+
this.add(type);
|
|
46
52
|
this.refType = type;
|
|
47
53
|
type.name = this.ref;
|
|
48
54
|
type.visit(context);
|
|
@@ -60,7 +66,7 @@ export class PropRef extends Prop {
|
|
|
60
66
|
return Naming.genTypeName(name) + this.nameSuffix();
|
|
61
67
|
}
|
|
62
68
|
forPrompt(context) {
|
|
63
|
-
return
|
|
69
|
+
return `[prop] ${this.name}: ${Naming.getRefName(this.ref)} (Ref)`;
|
|
64
70
|
}
|
|
65
71
|
select(context, writer, selection) {
|
|
66
72
|
trace(context, '-> [prop-ref:select]', 'in ' + this.name + ', ref: ' + this.ref);
|
|
@@ -97,7 +103,7 @@ export class PropRef extends Prop {
|
|
|
97
103
|
if (child instanceof Arr) {
|
|
98
104
|
return this.needsBrackets(child.itemsType);
|
|
99
105
|
}
|
|
100
|
-
return child instanceof Obj || child instanceof Union || child instanceof Composed
|
|
106
|
+
return child instanceof Obj || child instanceof Union || child instanceof Composed;
|
|
101
107
|
}
|
|
102
108
|
}
|
|
103
109
|
//# sourceMappingURL=propRef.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propRef.js","sourceRoot":"","sources":["../../../src/oas/nodes/propRef.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"propRef.js","sourceRoot":"","sources":["../../../src/oas/nodes/propRef.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAS,GAAG,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;GAEG;A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CAAC;aAAM,CAAC;YACN,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAEO,aAAa,CAAC,KAAY;QAChC,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,SAAU,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,KAAK,YAAY,GAAG,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,YAAY,QAAQ,CAAC;IACrF,CAAC;CACF","sourcesContent":["import { OasContext } from '../oasContext.js';\nimport { Arr, Prop, Composed, Factory, IType, Obj, Union } from './internal.js';\nimport _ from 'lodash';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\n/**\n * @deprecated No longer used\n */\nexport class PropRef extends Prop {\n get id(): string {\n return `prop:ref:#${this.name}`;\n }\n public refType?: IType;\n\n constructor(\n parent: IType | undefined,\n name: string,\n public schema: SchemaObject,\n public ref: string,\n ) {\n super(parent, name, schema);\n }\n\n /* public override add(child: IType): IType {\n child.name = this.ref;\n const paths: IType[] = this.ancestors();\n const contains: boolean = paths.map((p) => p.id).includes(child.id);\n\n trace(null, '-> [prop-ref:add]', 'contains child? ' + contains);\n let added: IType = child;\n if (contains) {\n const ancestor: IType = paths[paths.map((p) => p.id).indexOf(child.id)];\n const wrapper = Factory.fromCircularRef(this, ancestor);\n added = super.add(wrapper);\n this.visited = true;\n this.refType = wrapper;\n } else {\n added = super.add(child);\n }\n\n return added;\n }*/\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n context.enter(this);\n trace(context, '-> [prop-ref:visit]', 'in ' + this.name + ', ref: ' + this.ref);\n\n const schema = context.lookupRef(this.ref);\n if (!schema) {\n throw new Error('Schema not found for ref: ' + this.ref);\n }\n\n const type = Factory.fromSchema(context, this, schema);\n if (!this.refType) {\n this.add(type);\n this.refType = type;\n type.name = this.ref;\n type.visit(context);\n\n if (!this.children.includes(this.refType!)) {\n this.add(this.refType!);\n }\n\n this.visited = true;\n }\n trace(context, '<- [prop-ref:visit]', 'out ' + this.name + ', ref: ' + this.ref);\n context.leave(this);\n }\n\n public getValue(_context: OasContext): string {\n const type = this.refType!;\n const name = type ? type.name : this.ref;\n\n return Naming.genTypeName(name!) + this.nameSuffix();\n }\n\n public forPrompt(context: OasContext): string {\n return `[prop] ${this.name}: ${Naming.getRefName(this.ref)} (Ref)`;\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [prop-ref:select]', 'in ' + this.name + ', ref: ' + this.ref);\n const fieldName = this.name;\n const sanitised = Naming.sanitiseFieldForSelect(fieldName);\n writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);\n\n if (this.refType && this.needsBrackets(this.refType)) {\n writer.append(' {').append('\\n');\n context.enter(this);\n }\n\n for (const child of this.children) {\n child.select(context, writer, selection);\n }\n\n if (this.refType && this.needsBrackets(this.refType)) {\n context.leave(this);\n writer.append(' '.repeat(context.indent + context.stack.length)).append('}');\n }\n\n writer.append('\\n');\n trace(context, '<- [prop-ref:select]', 'out ' + this.name + ', ref: ' + this.ref);\n }\n\n generateValue(context: OasContext, writer: Writer): void {\n const type = this.refType;\n\n if (type && (type as IType) instanceof Arr) {\n writer.append('[');\n const items = (type as Arr).itemsType;\n writer.append(_.upperFirst(items!.name));\n writer.append(']');\n } else {\n writer.append(this.getValue(context));\n }\n }\n\n private needsBrackets(child: IType): boolean {\n if (child instanceof Arr) {\n return this.needsBrackets(child.itemsType!);\n }\n return child instanceof Obj || child instanceof Union || child instanceof Composed;\n }\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { IType } from './internal.js';
|
|
2
|
-
import { Prop } from './internal.js';
|
|
1
|
+
import { IType, Prop } from './internal.js';
|
|
3
2
|
import { SchemaObject } from 'oas/types';
|
|
4
3
|
import { OasContext } from '../oasContext.js';
|
|
5
4
|
import { Writer } from '../io/writer.js';
|
|
@@ -10,7 +9,7 @@ export declare class PropScalar extends Prop {
|
|
|
10
9
|
constructor(parent: IType, name: string, type: string, schema: SchemaObject);
|
|
11
10
|
get id(): string;
|
|
12
11
|
visit(context: OasContext): void;
|
|
13
|
-
getValue(
|
|
12
|
+
getValue(_context: OasContext): string;
|
|
14
13
|
forPrompt(context: OasContext): string;
|
|
15
14
|
select(context: OasContext, writer: Writer, selection: string[]): void;
|
|
16
15
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Factory } from './internal.js';
|
|
2
|
-
import { Prop } from './internal.js';
|
|
1
|
+
import { Factory, Prop } from './internal.js';
|
|
3
2
|
import { trace } from '../log/trace.js';
|
|
4
3
|
import { Naming } from '../utils/naming.js';
|
|
5
4
|
export class PropScalar extends Prop {
|
|
@@ -20,17 +19,22 @@ export class PropScalar extends Prop {
|
|
|
20
19
|
}
|
|
21
20
|
context.enter(this);
|
|
22
21
|
if (!this.propType) {
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const type = Factory.fromSchema(context, this, this.schema);
|
|
23
|
+
this.add(type);
|
|
24
|
+
this.propType = type;
|
|
25
25
|
this.visited = true;
|
|
26
26
|
}
|
|
27
27
|
context.leave(this);
|
|
28
28
|
}
|
|
29
|
-
getValue(
|
|
29
|
+
getValue(_context) {
|
|
30
30
|
return this.type;
|
|
31
31
|
}
|
|
32
32
|
forPrompt(context) {
|
|
33
|
-
|
|
33
|
+
let result = `[prop] ${this.name}: ${this.type}`;
|
|
34
|
+
if (context.generateOptions.showParentInSelections) {
|
|
35
|
+
result = result + ` (${Naming.getRefName(this.parent.name)})`;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
34
38
|
}
|
|
35
39
|
select(context, writer, selection) {
|
|
36
40
|
trace(context, ' [prop:select]', this.name);
|
|
@@ -39,7 +43,7 @@ export class PropScalar extends Prop {
|
|
|
39
43
|
for (const child of this.children) {
|
|
40
44
|
child.select(context, writer, selection);
|
|
41
45
|
}
|
|
42
|
-
if (context.generateOptions.
|
|
46
|
+
if (context.generateOptions.showParentInSelections) {
|
|
43
47
|
writer.append(' # ').append(Naming.getRefName(this.parent.name));
|
|
44
48
|
}
|
|
45
49
|
writer.append('\n');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propScalar.js","sourceRoot":"","sources":["../../../src/oas/nodes/propScalar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,
|
|
1
|
+
{"version":3,"file":"propScalar.js","sourceRoot":"","sources":["../../../src/oas/nodes/propScalar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,IAAI,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,OAAO,UAAW,SAAQ,IAAI;IAMzB;IACA;IAND,QAAQ,CAAS;IAEzB,YACE,MAAa,EACb,IAAY,EACL,IAAY,EACZ,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,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAC5D,IAAI,CAAC,GA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IAAI,CAAC,MAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;CACF","sourcesContent":["import { Factory, IType, Prop } from './internal.js';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nexport class PropScalar extends Prop {\n private propType?: IType;\n\n constructor(\n parent: IType,\n name: string,\n public type: string,\n public schema: SchemaObject,\n ) {\n super(parent, name, schema);\n }\n\n get id(): string {\n return `prop:scalar:${this.name}`;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n if (!this.propType) {\n const type = Factory.fromSchema(context, this, this.schema);\n this.add(type);\n this.propType = type;\n this.visited = true;\n }\n context.leave(this);\n }\n\n public getValue(_context: OasContext): string {\n return this.type;\n }\n\n public forPrompt(context: OasContext): string {\n let result = `[prop] ${this.name}: ${this.type}`;\n\n if (context.generateOptions.showParentInSelections) {\n result = result + ` (${Naming.getRefName(this.parent!.name)})`;\n }\n\n return result;\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, ' [prop:select]', this.name);\n const sanitised = Naming.sanitiseFieldForSelect(this.name);\n writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);\n\n for (const child of this.children) {\n child.select(context, writer, selection);\n }\n\n if (context.generateOptions.showParentInSelections) {\n writer.append(' # ').append(Naming.getRefName(this.parent!.name));\n }\n\n writer.append('\\n');\n }\n}\n"]}
|
package/dist/oas/nodes/ref.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { IType, Prop, Type } from './internal.js';
|
|
|
2
2
|
import { OasContext } from '../oasContext.js';
|
|
3
3
|
import { Writer } from '../io/writer.js';
|
|
4
4
|
import { ReferenceObject } from './referenceObject.js';
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated This class is deprecated and should not be used in new code.
|
|
7
|
+
*/
|
|
5
8
|
export declare class Ref extends Type {
|
|
6
9
|
schema: ReferenceObject | null;
|
|
7
10
|
refType?: IType;
|
package/dist/oas/nodes/ref.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Arr, Factory, Type } from './internal.js';
|
|
2
2
|
import { trace } from '../log/trace.js';
|
|
3
3
|
import { Naming } from '../utils/naming.js';
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated This class is deprecated and should not be used in new code.
|
|
6
|
+
*/
|
|
4
7
|
export class Ref extends Type {
|
|
5
8
|
schema;
|
|
6
9
|
refType;
|
|
@@ -15,7 +18,7 @@ export class Ref extends Type {
|
|
|
15
18
|
return this.refType?.props ?? new Map();
|
|
16
19
|
}
|
|
17
20
|
forPrompt(_context) {
|
|
18
|
-
return
|
|
21
|
+
return `[ref] ${Naming.getRefName(this.name)}`;
|
|
19
22
|
}
|
|
20
23
|
visit(context) {
|
|
21
24
|
// console.log('schema', this.schema);
|
|
@@ -29,7 +32,9 @@ export class Ref extends Type {
|
|
|
29
32
|
if (!schema) {
|
|
30
33
|
throw new Error('Schema not found for ref: ' + ref);
|
|
31
34
|
}
|
|
32
|
-
|
|
35
|
+
const type = Factory.fromSchema(context, this, schema);
|
|
36
|
+
this.add(type);
|
|
37
|
+
this.refType = type;
|
|
33
38
|
// Set the name of the resolved type to the reference string.
|
|
34
39
|
this.refType.name = ref;
|
|
35
40
|
this.refType.visit(context);
|
|
@@ -42,7 +47,7 @@ export class Ref extends Type {
|
|
|
42
47
|
trace(context, '-> [ref::generate]', `-> in: ${this.name}`);
|
|
43
48
|
// If we're in a Response context and the resolved type is an Arr,
|
|
44
49
|
// generate it with array notation.
|
|
45
|
-
if (context.inContextOf('
|
|
50
|
+
if (context.inContextOf('Res', this) && this.refType instanceof Arr) {
|
|
46
51
|
writer.append('[').append(this.firstChild().name).append(']');
|
|
47
52
|
}
|
|
48
53
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/oas/nodes/ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAe,IAAI,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAI5C,MAAM,OAAO,GAAI,SAAQ,IAAI;IAMlB;IALF,OAAO,CAAS;IAEvB,YACE,MAAyB,EACzB,IAAY,EACL,MAA8B;QAErC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAFb,WAAM,GAAN,MAAM,CAAwB;IAGvC,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC;IACpC,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,OAAO,EAAE,KAAK,IAAI,IAAI,GAAG,EAAE,CAAC;IAC1C,CAAC;IAEM,SAAS,CAAC,QAAoB;QACnC,OAAO,
|
|
1
|
+
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/oas/nodes/ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAe,IAAI,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAI5C;;GAEG;AACH,MAAM,OAAO,GAAI,SAAQ,IAAI;IAMlB;IALF,OAAO,CAAS;IAEvB,YACE,MAAyB,EACzB,IAAY,EACL,MAA8B;QAErC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAFb,WAAM,GAAN,MAAM,CAAwB;IAGvC,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC;IACpC,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E,CAAC,CAAC;IAC7D,CAAC;IAEO,UAAU;QAChB,OAAO,IAAI,CAAC,OAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;CACF","sourcesContent":["import { Arr, Factory, IType, Prop, Type } from './internal.js';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nimport { ReferenceObject } from './referenceObject.js';\n\n/**\n * @deprecated This class is deprecated and should not be used in new code.\n */\nexport class Ref extends Type {\n public refType?: IType;\n\n constructor(\n parent: IType | undefined,\n name: string,\n public schema: ReferenceObject | null,\n ) {\n super(parent, name);\n }\n\n get id(): string {\n return 'ref:' + this.schema?.$ref;\n }\n\n get props(): Map<string, Prop> {\n return this.refType?.props ?? new Map();\n }\n\n public forPrompt(_context: OasContext): string {\n return `[ref] ${Naming.getRefName(this.name)}`;\n }\n\n public visit(context: OasContext): void {\n // console.log('schema', this.schema);\n if (this.visited) {\n return;\n }\n const ref = this.schema?.$ref ?? '';\n\n context.enter(this);\n trace(context, '-> [ref:visit]', 'in: ' + ref);\n\n const schema: SchemaObject | null = context.lookupRef(ref);\n if (!schema) {\n throw new Error('Schema not found for ref: ' + ref);\n }\n\n const type = Factory.fromSchema(context, this, schema);\n this.add(type);\n this.refType = type;\n // Set the name of the resolved type to the reference string.\n this.refType.name = ref;\n this.refType.visit(context);\n\n this.visited = true;\n trace(context, '<- [ref:visit]', 'out: ' + ref);\n context.leave(this);\n }\n\n public generate(context: OasContext, writer: Writer, _selection: string[]): void {\n context.enter(this);\n trace(context, '-> [ref::generate]', `-> in: ${this.name}`);\n\n // If we're in a Response context and the resolved type is an Arr,\n // generate it with array notation.\n if (context.inContextOf('Res', this) && this.refType instanceof Arr) {\n writer.append('[').append(this.firstChild().name).append(']');\n } else {\n // Rewrite terrible names to something more sensible.\n const sanitised = Naming.genTypeName(this.name);\n const refName = Naming.getRefName(this.name);\n writer.write(sanitised === refName ? refName : sanitised);\n }\n\n trace(context, '<- [ref::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [ref::select]', `-> in: ${this.name}`);\n if (this.refType) {\n this.refType.select(context, writer, selection);\n }\n trace(context, '<- [ref::select]', `-> out: ${this.name}`);\n }\n\n private firstChild() {\n return this.refType!.children[0];\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import { IType, Type } from './internal.js';
|
|
|
2
2
|
import { SchemaObject } from 'oas/types';
|
|
3
3
|
import { OasContext } from '../oasContext.js';
|
|
4
4
|
import { Writer } from '../io/writer.js';
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class Res extends Type {
|
|
6
6
|
schema: SchemaObject;
|
|
7
7
|
response?: IType;
|
|
8
8
|
constructor(parent: IType, name: string, schema: SchemaObject, response?: IType);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Factory, Type, T } from './internal.js';
|
|
2
2
|
import { trace } from '../log/trace.js';
|
|
3
|
-
export class
|
|
3
|
+
export class Res extends Type {
|
|
4
4
|
schema;
|
|
5
5
|
response;
|
|
6
6
|
constructor(parent, name, schema, response) {
|
|
@@ -18,8 +18,10 @@ export class Response extends Type {
|
|
|
18
18
|
}
|
|
19
19
|
context.enter(this);
|
|
20
20
|
trace(context, '-> [res:visit]', 'in ' + this.name);
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const type = Factory.fromSchema(context, this, this.schema);
|
|
22
|
+
this.add(type);
|
|
23
|
+
this.response = type;
|
|
24
|
+
trace(context, ' [res:visit]', 'response type: ' + this.response.id);
|
|
23
25
|
this.visited = true;
|
|
24
26
|
trace(context, '<- [res:visit]', 'out ' + this.name);
|
|
25
27
|
context.leave(this);
|
|
@@ -52,4 +54,4 @@ export class Response extends Type {
|
|
|
52
54
|
trace(context, '<- [res:select]', `-> out: ${this.parent.name}`);
|
|
53
55
|
}
|
|
54
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AK,CAAC,CAAC;YAC1D,CAAC;;gBAAM,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QACrD,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,iBAAiB,EAAE,WAAW,IAAI,CAAC,MAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACpE,CAAC;CACF","sourcesContent":["import { Factory, IType, Type, T } from './internal.js';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\n\nexport class Res extends Type {\n public schema: SchemaObject;\n public response?: IType;\n\n constructor(parent: IType, name: string, schema: SchemaObject, response?: IType) {\n super(parent, name);\n this.schema = schema;\n this.response = response;\n }\n\n get id(): string {\n return 'res:' + this.name;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n trace(context, '-> [res:visit]', this.name + ' already visited.');\n return;\n }\n\n context.enter(this);\n trace(context, '-> [res:visit]', 'in ' + this.name);\n\n const type = Factory.fromSchema(context, this, this.schema);\n this.add(type);\n\n this.response = type;\n trace(context, ' [res:visit]', 'response type: ' + this.response.id);\n\n this.visited = true;\n trace(context, '<- [res:visit]', 'out ' + this.name);\n context.leave(this);\n }\n\n public forPrompt(context: OasContext): string {\n return 'Response';\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n context.enter(this);\n trace(context, '-> [res:generate]', `-> in: ${this.parent!.name}`);\n\n if (this.response) {\n this.response.generate(context, writer, selection);\n }\n\n trace(context, '<- [res:generate]', `-> out: ${this.parent!.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]): void {\n trace(context, '-> [res:select]', `-> in: ${this.parent!.name}`);\n\n const response = this.response;\n if (response) {\n if (T.isScalar(response)) {\n // best attempt to just copy the value that comes out of the service. most likely the\n // value will have to be replaced by a GQL type. In fact, we could potentially use SYN_ here but\n // it will have to do for now.\n writer.append(' '.repeat(context.indent)).append('$\\n');\n } else response.select(context, writer, selection);\n }\n\n trace(context, '<- [res:select]', `-> out: ${this.parent!.name}`);\n }\n}\n"]}
|
package/dist/oas/nodes/type.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { IType, Kind } from './internal.js';
|
|
1
|
+
import { IType, Kind, Prop } from './internal.js';
|
|
2
2
|
import { OasContext } from '../oasContext.js';
|
|
3
3
|
import { Writer } from '../io/writer.js';
|
|
4
|
-
import { Prop } from './internal.js';
|
|
5
4
|
export declare abstract class Type implements IType {
|
|
6
5
|
parent?: IType;
|
|
7
6
|
name: string;
|
|
@@ -22,7 +21,7 @@ export declare abstract class Type implements IType {
|
|
|
22
21
|
ancestors(): IType[];
|
|
23
22
|
path(): string;
|
|
24
23
|
pathToRoot(): string;
|
|
25
|
-
add(child: IType):
|
|
24
|
+
add(child: IType): IType;
|
|
26
25
|
selectedProps(selection: string[]): Prop[];
|
|
27
26
|
nameSuffix(): string;
|
|
28
27
|
}
|
package/dist/oas/nodes/type.js
CHANGED
|
@@ -74,34 +74,19 @@ export class Type {
|
|
|
74
74
|
add(child) {
|
|
75
75
|
const paths = this.ancestors();
|
|
76
76
|
const contains = paths.map((p) => p.id).includes(child.id);
|
|
77
|
+
let pushed = child;
|
|
77
78
|
if (contains) {
|
|
78
79
|
trace(null, '-> [type:add]', 'already contains child: ' + child.id);
|
|
79
80
|
const ancestor = paths[paths.map((p) => p.id).indexOf(child.id)];
|
|
80
81
|
const wrapper = Factory.fromCircularRef(this, ancestor);
|
|
81
82
|
this.children.push(wrapper);
|
|
83
|
+
pushed = wrapper;
|
|
82
84
|
}
|
|
83
85
|
else {
|
|
84
86
|
this.children.push(child);
|
|
85
87
|
}
|
|
88
|
+
return pushed;
|
|
86
89
|
}
|
|
87
|
-
/*
|
|
88
|
-
remove = (value: IType): void => {
|
|
89
|
-
const index = this.children.findIndex(child => child === value);
|
|
90
|
-
if (index !== -1) {
|
|
91
|
-
this.children.splice(index, 1);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
*/
|
|
96
|
-
/*traverseB(callback: (node: IType) => void): void {
|
|
97
|
-
const queue: IType[] = [this];
|
|
98
|
-
|
|
99
|
-
while (queue.length > 0) {
|
|
100
|
-
const node = queue.shift()!;
|
|
101
|
-
callback(node);
|
|
102
|
-
queue.push(...node.children);
|
|
103
|
-
}
|
|
104
|
-
}*/
|
|
105
90
|
selectedProps(selection) {
|
|
106
91
|
return Array.from(this.props.values()).filter((prop) => selection.find((s) => s.startsWith(prop.path())));
|
|
107
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/oas/nodes/type.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/oas/nodes/type.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,OAAgB,IAAI;IACjB,MAAM,CAAS;IACf,IAAI,CAAS;IACb,QAAQ,CAAU;IAClB,WAAW,CAAS;IACpB,IAAI,CAAO;IACX,OAAO,CAAU;IAEP,MAAM,CAAoB;IAE3C,YAAsB,MAAyB,EAAE,IAAY;QAC3D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAgB,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,MAAM,EAAE,IAAI,IAAI,MAAM,CAAC;IACrC,CAAC;IAQM,IA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AAM,GAAG,KAAK,CAAC;QAEnB,IAAI,QAAQ,EAAE,CAAC;YACb,KAAK,CAAC,IAAI,EAAE,eAAe,EAAE,0BAA0B,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;YACpE,MAAM,QAAQ,GAAU,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;YACxE,MAAM,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YACxD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC5B,MAAM,GAAG,OAAO,CAAC;QACnB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,aAAa,CAAC,SAAmB;QACtC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC5G,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9C,CAAC;CACF","sourcesContent":["import { IType, Kind, Prop } from './internal.js';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Factory } from './factory.js';\n\nexport abstract class Type implements IType {\n public parent?: IType;\n public name: string;\n public children: IType[];\n public circularRef?: IType;\n public kind: Kind;\n public visited: boolean;\n\n private readonly _props: Map<string, Prop>;\n\n protected constructor(parent: IType | undefined, name: string) {\n this.parent = parent;\n this.name = name;\n this.children = [];\n this.visited = false;\n this._props = new Map<string, Prop>();\n this.kind = parent?.kind || 'type';\n }\n\n public abstract visit(context: OasContext): void;\n\n public abstract forPrompt(context: OasContext): string;\n\n public abstract select(context: OasContext, writer: Writer, selection: string[]): void;\n\n public find(path: string, collection: IType[]): IType | boolean {\n const parts = path.split('>');\n let current: IType | undefined;\n\n let i = 0;\n do {\n const part = parts[i];\n\n current = collection.find((t) => t.id === part);\n if (!current) {\n return false;\n }\n\n collection = Array.from(current!.children.values()) || Array.from(current!.props.values()) || [];\n // console.log(\"found\", current);\n\n i++;\n } while (i < parts.length);\n\n return current || false;\n }\n\n public expand(context: OasContext): IType[] {\n trace(context, '-> [expand]', `in: path: ${this.path()}`);\n if (!this.visited) {\n this.visit(context);\n }\n\n trace(context, '<- [expand]', `out: path: ${this.path()}`);\n\n // TODO:\n // if ((type instanceof Composed || type instanceof Union) && !type.getProps().isEmpty()) {\n // return type.props?.values() || [];\n // }\n // else {\n return this.children;\n // }\n }\n\n public abstract generate(context: OasContext, writer: Writer, selection: string[]): void;\n\n get id() {\n return this.name;\n }\n\n get props() {\n return this._props;\n }\n\n public ancestors(): IType[] {\n return this.parent ? [...this.parent.ancestors(), this] : [this];\n }\n\n public path(): string {\n const ancestors = this.ancestors();\n return ancestors\n .map((t) => t.id)\n .join('>')\n .replace(/#\\/components\\/schemas/g, '#/c/s');\n }\n\n public pathToRoot(): string {\n let builder = '';\n let indent = 0;\n\n const ancestors = this.ancestors();\n for (let i = 0; i < ancestors.length; i++) {\n builder += ' <- ' + ' '.repeat(indent++) + ancestors[i].id + ' (' + ancestors[i].constructor.name + ')\\n';\n }\n\n return builder;\n }\n\n public add(child: IType): IType {\n const paths: IType[] = this.ancestors();\n const contains: boolean = paths.map((p) => p.id).includes(child.id);\n let pushed = child;\n\n if (contains) {\n trace(null, '-> [type:add]', 'already contains child: ' + child.id);\n const ancestor: IType = paths[paths.map((p) => p.id).indexOf(child.id)];\n const wrapper = Factory.fromCircularRef(this, ancestor);\n this.children.push(wrapper);\n pushed = wrapper;\n } else {\n this.children.push(child);\n }\n\n return pushed;\n }\n\n public selectedProps(selection: string[]) {\n return Array.from(this.props.values()).filter((prop) => selection.find((s) => s.startsWith(prop.path())));\n }\n\n nameSuffix(): string {\n return this.kind === 'input' ? 'Input' : '';\n }\n}\n"]}
|
|
@@ -6,4 +6,7 @@ export declare class T {
|
|
|
6
6
|
static isMutationType(type: IType): boolean;
|
|
7
7
|
static isScalar(type: IType): boolean;
|
|
8
8
|
static containers(node: IType): IType[];
|
|
9
|
+
static isContainer(node: IType): boolean;
|
|
10
|
+
static composables(node: IType): IType[];
|
|
11
|
+
static print(node: IType, prefix?: string, isLast?: boolean): string;
|
|
9
12
|
}
|