apollo-conn-gen 0.0.4 → 0.0.7
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.d.ts +1 -1
- package/dist/cli/oas-helpers/index.js.map +1 -1
- package/dist/oas/index.d.ts +1 -13
- package/dist/oas/index.js +1 -13
- package/dist/oas/index.js.map +1 -1
- package/dist/oas/io/writer.d.ts +1 -1
- package/dist/oas/io/writer.js.map +1 -1
- package/dist/oas/nodes/arr.d.ts +1 -1
- package/dist/oas/nodes/arr.js +1 -1
- package/dist/oas/nodes/arr.js.map +1 -1
- package/dist/oas/nodes/circularRef.d.ts +1 -1
- package/dist/oas/nodes/circularRef.js +1 -1
- package/dist/oas/nodes/circularRef.js.map +1 -1
- package/dist/oas/nodes/comp.d.ts +1 -1
- package/dist/oas/nodes/comp.js +1 -4
- package/dist/oas/nodes/comp.js.map +1 -1
- package/dist/oas/nodes/en.d.ts +1 -1
- package/dist/oas/nodes/en.js +1 -1
- package/dist/oas/nodes/en.js.map +1 -1
- package/dist/oas/nodes/factory.d.ts +1 -4
- package/dist/oas/nodes/factory.js +1 -14
- package/dist/oas/nodes/factory.js.map +1 -1
- package/dist/oas/nodes/get.d.ts +1 -2
- package/dist/oas/nodes/get.js +1 -2
- package/dist/oas/nodes/get.js.map +1 -1
- package/dist/oas/nodes/iType.d.ts +21 -0
- package/dist/oas/nodes/iType.js +2 -0
- package/dist/oas/nodes/iType.js.map +1 -0
- package/dist/oas/nodes/internal.d.ts +20 -0
- package/dist/oas/nodes/internal.js +22 -0
- package/dist/oas/nodes/internal.js.map +1 -0
- package/dist/oas/nodes/obj.d.ts +2 -2
- package/dist/oas/nodes/obj.js +2 -2
- package/dist/oas/nodes/obj.js.map +1 -1
- package/dist/oas/nodes/param/param.d.ts +1 -1
- package/dist/oas/nodes/param/param.js +1 -2
- package/dist/oas/nodes/param/param.js.map +1 -1
- package/dist/oas/nodes/props/internal.d.ts +6 -0
- package/dist/oas/nodes/props/internal.js +7 -0
- package/dist/oas/nodes/props/internal.js.map +1 -0
- package/dist/oas/nodes/props/prop.d.ts +1 -1
- package/dist/oas/nodes/props/prop.js +1 -1
- package/dist/oas/nodes/props/prop.js.map +1 -1
- package/dist/oas/nodes/props/propArray.d.ts +2 -2
- package/dist/oas/nodes/props/propArray.js +2 -4
- package/dist/oas/nodes/props/propArray.js.map +1 -1
- package/dist/oas/nodes/props/propObj.d.ts +2 -2
- package/dist/oas/nodes/props/propObj.js +2 -3
- package/dist/oas/nodes/props/propObj.js.map +1 -1
- package/dist/oas/nodes/props/propRef.d.ts +2 -2
- package/dist/oas/nodes/props/propRef.js +2 -7
- package/dist/oas/nodes/props/propRef.js.map +1 -1
- package/dist/oas/nodes/props/propScalar.d.ts +2 -2
- package/dist/oas/nodes/props/propScalar.js +2 -2
- package/dist/oas/nodes/props/propScalar.js.map +1 -1
- package/dist/oas/nodes/ref.d.ts +3 -4
- package/dist/oas/nodes/ref.js +3 -5
- package/dist/oas/nodes/ref.js.map +1 -1
- package/dist/oas/nodes/response.d.ts +1 -1
- package/dist/oas/nodes/response.js +1 -2
- package/dist/oas/nodes/response.js.map +1 -1
- package/dist/oas/nodes/scalar.d.ts +2 -2
- package/dist/oas/nodes/scalar.js +2 -2
- package/dist/oas/nodes/scalar.js.map +1 -1
- package/dist/oas/nodes/type.d.ts +1 -18
- package/dist/oas/nodes/type.js.map +1 -1
- package/dist/oas/nodes/union.d.ts +1 -1
- package/dist/oas/nodes/union.js +1 -4
- package/dist/oas/nodes/union.js.map +1 -1
- package/dist/oas/oasContext.d.ts +1 -1
- package/dist/oas/oasContext.js.map +1 -1
- package/dist/oas/oasGen.d.ts +1 -1
- package/dist/oas/oasGen.js.map +1 -1
- package/dist/oas/prompts/prompt.d.ts +1 -1
- package/dist/oas/prompts/prompt.js.map +1 -1
- package/dist/oas/prompts/theme.d.ts +1 -1
- package/dist/oas/prompts/theme.js.map +1 -1
- package/dist/oas/utils/typeUtils.d.ts +1 -1
- package/dist/oas/utils/typeUtils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/readme.md +6 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../../src/oas/nodes/get.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAS,IAAI,EAAE,MAAM,WAAW,CAAC;AAIxC,MAAM,OAAO,GAAI,SAAQ,IAAI;IAMlB;IALF,UAAU,CAAS;IACnB,MAAM,GAAY,EAAE,CAAC;IAE5B,YACE,IAAY,EACL,SAAoB;QAE3B,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAFhB,cAAS,GAAT,SAAS,CAAW;IAG7B,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,OAAmB;QAC9B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC,CAAC;YAClE,OAAO;QACT,CAAC;QAED,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpB,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpD,mBAAmB;QACnB,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAE9B,qBAAqB;QACrB,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QAEpB,KAAK,CAAC,OAAO,EAAE,g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AAC,GAAG,CAAC,CAAC;IACrB,CAAC;IAEO,cAAc,CAAC,OAAmB,EAAE,MAAY,EAAE,CAAkB;QAC1E,KAAK,CAAC,OAAO,EAAE,oBAAoB,EAAE,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;QAEzD,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QACpD,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAErB,KAAK,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;QACvD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["import { Operation } from 'oas/operation';\nimport { MediaTypeObject, ParameterObject, ResponseObject, SchemaObject } from 'oas/types';\n\nimport { trace, warn } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\nimport { Factory } from './factory.js';\nimport { Param } from './param/param.js';\nimport { IType, Type } from './type.js';\n\nimport { ReferenceObject } from './props/referenceObject.js';\n\nexport class Get extends Type {\n public resultType?: IType;\n public params: Param[] = [];\n\n constructor(\n name: string,\n public operation: Operation,\n ) {\n super(undefined, name);\n }\n\n get id(): string {\n return `get:${this.name}`;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n trace(context, '-> [get:visit]', this.name + ' already visited.');\n return;\n }\n\n context.enter(this);\n trace(context, '-> [get:visit]', 'in ' + this.name);\n\n // 1. Visit params.\n this.visitParameters(context);\n\n // 2. Visit responses\n this.visitResponses(context);\n this.visited = true;\n\n trace(context, '<- [get:visit]', 'out ' + this.name);\n context.leave(this);\n }\n\n public forPrompt(_context: OasContext): string {\n return `[GET] ${this.name}`;\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n context.enter(this);\n trace(context, '-> [get::generate]', `-> in: ${this.name}`);\n\n const summary = this.operation.getSummary();\n const originalPath = this.operation.path;\n\n if (summary || originalPath) {\n writer.append(' \"\"\"\\n').append(' ');\n if (summary) {\n writer.append(summary).append(' ');\n }\n if (originalPath) {\n writer.append('(').append(originalPath).append(')');\n }\n writer.append('\\n \"\"\"\\n');\n }\n\n writer.append(' ').append(this.getGqlOpName());\n this.generateParameters(context, writer, selection);\n\n if (this.resultType) {\n writer.append(': ');\n this.resultType.generate(context, writer, selection);\n }\n\n writer.append('\\n');\n trace(context, '<- [get::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public select(_context: OasContext, _writer: Writer, _selection: string[]) {\n // do nothing\n }\n\n public getGqlOpName(): string {\n return Naming.genOperationName(this.operation.path, this.operation);\n }\n\n private visitParameters(context: OasContext): void {\n trace(context, '-> [get::params]', 'in: ' + this.name);\n\n const parameters = this.operation.getParameters();\n\n if (parameters && parameters.length > 0) {\n this.params = parameters\n .filter((p) => !p.in || (p.in && (p.in as string).toLowerCase() !== 'header'))\n .map((p: ParameterObject) => this.visitParameter(context, this, p));\n } else {\n this.params = [];\n }\n\n trace(context, '<- [get::params]', 'out: ' + this.name);\n }\n\n private visitResponses = (context: OasContext) => {\n const statusCodes = this.operation.getResponseStatusCodes();\n\n if (!statusCodes.includes('200') && !statusCodes.includes('default')) {\n throw new Error('Could not find a valid 200 response');\n }\n\n const responses = this.operation.schema.responses;\n if (responses!['200']) {\n this.visitResponse(context, '200', responses!['200'] as ResponseObject);\n } else if (responses!.default) {\n this.visitResponse(context, 'default', responses!.default as ResponseObject);\n } else {\n throw new Error(\"Could not find a '200' or 'default' response\");\n }\n };\n\n private visitResponse(context: OasContext, code: string, response: ResponseObject): void {\n const content = response.content as MediaTypeObject;\n\n if ('$ref' in response) {\n this.visitResponseRef(context, response as ReferenceObject);\n }\n // If the response has a content property, we need to find the JSON content.\n else if (content) {\n const json = response.content!['application/json']!;\n if (!json) {\n warn(context, ` [${code}]`, 'no entry found for content application/json!');\n } else {\n this.visitResponseContent(context, code, json);\n }\n } else if (code === 'default') {\n // there is no response for this operation\n // TODO: should we synthesize one?\n } else {\n throw new Error('Not yet implemented for: ' + JSON.stringify(response));\n }\n }\n\n private visitResponseContent(context: OasContext, _code: string, media: MediaTypeObject): void {\n trace(context, '-> [get::responses::content]', 'in ' + this.name);\n const schema = media!.schema as SchemaObject;\n\n if (!schema) {\n throw new Error('No schema content found!');\n }\n\n this.resultType = Factory.fromResponse(context, this, schema);\n // PENDING: do not visit anymore\n // if (this.resultType) {\n // this.resultType.visit(context);\n // }\n\n if (this.resultType && !this.children.includes(this.resultType)) {\n this.add(this.resultType);\n }\n\n trace(context, '<- [get::responses::content]', 'out ' + this.name);\n }\n\n private visitResponseRef(context: OasContext, ref: ReferenceObject): void {\n trace(context, '-> [get::responses::ref]', `in: ${this.name}, ref: ${ref.$ref}`);\n\n const lookup = context.lookupResponse(ref.$ref!);\n if (!lookup) {\n throw new Error('Could not find a response with ref: ' + ref.$ref);\n }\n\n if ('$ref' in lookup) {\n throw new Error('Not yet implemented for nested refs');\n }\n\n this.visitResponse(context, ref.$ref!, lookup as ResponseObject);\n trace(context, '<- [get::responses::ref]', `out: ${this.name}, ref: ${ref.$ref}`);\n }\n\n private generateParameters(context: OasContext, writer: Writer, selection: string[]): void {\n const sorted = this.params.sort((a, b) => (b.required ? 1 : 0) - (a.required ? 1 : 0));\n\n if (sorted.length === 0) {\n return;\n }\n\n writer.append('(');\n\n sorted.forEach((parameter, index) => {\n if (index > 0) {\n writer.append(', ');\n }\n parameter.generate(context, writer, selection);\n });\n\n writer.append(')');\n }\n\n private visitParameter(context: OasContext, parent: Type, p: ParameterObject): Param {\n trace(context, '->[visitParameter]', 'begin: ' + p.name);\n\n const param = Factory.fromParam(context, parent, p);\n param.visit(context);\n\n trace(context, '<-[visitParameter]', 'end: ' + p.name);\n return param;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../../src/oas/nodes/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,IAAI,E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D,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAErB,KAAK,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;QACvD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["import { IType, Type, Param, ReferenceObject, Factory } from './internal.js';\nimport { Operation } from 'oas/operation';\nimport { MediaTypeObject, ParameterObject, ResponseObject, SchemaObject } from 'oas/types';\n\nimport { trace, warn } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nexport class Get extends Type {\n public resultType?: IType;\n public params: Param[] = [];\n\n constructor(\n name: string,\n public operation: Operation,\n ) {\n super(undefined, name);\n }\n\n get id(): string {\n return `get:${this.name}`;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n trace(context, '-> [get:visit]', this.name + ' already visited.');\n return;\n }\n\n context.enter(this);\n trace(context, '-> [get:visit]', 'in ' + this.name);\n\n // 1. Visit params.\n this.visitParameters(context);\n\n // 2. Visit responses\n this.visitResponses(context);\n this.visited = true;\n\n trace(context, '<- [get:visit]', 'out ' + this.name);\n context.leave(this);\n }\n\n public forPrompt(_context: OasContext): string {\n return `[GET] ${this.name}`;\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n context.enter(this);\n trace(context, '-> [get::generate]', `-> in: ${this.name}`);\n\n const summary = this.operation.getSummary();\n const originalPath = this.operation.path;\n\n if (summary || originalPath) {\n writer.append(' \"\"\"\\n').append(' ');\n if (summary) {\n writer.append(summary).append(' ');\n }\n if (originalPath) {\n writer.append('(').append(originalPath).append(')');\n }\n writer.append('\\n \"\"\"\\n');\n }\n\n writer.append(' ').append(this.getGqlOpName());\n this.generateParameters(context, writer, selection);\n\n if (this.resultType) {\n writer.append(': ');\n this.resultType.generate(context, writer, selection);\n }\n\n writer.append('\\n');\n trace(context, '<- [get::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public select(_context: OasContext, _writer: Writer, _selection: string[]) {\n // do nothing\n }\n\n public getGqlOpName(): string {\n return Naming.genOperationName(this.operation.path, this.operation);\n }\n\n private visitParameters(context: OasContext): void {\n trace(context, '-> [get::params]', 'in: ' + this.name);\n\n const parameters = this.operation.getParameters();\n\n if (parameters && parameters.length > 0) {\n this.params = parameters\n .filter((p) => !p.in || (p.in && (p.in as string).toLowerCase() !== 'header'))\n .map((p: ParameterObject) => this.visitParameter(context, this, p));\n } else {\n this.params = [];\n }\n\n trace(context, '<- [get::params]', 'out: ' + this.name);\n }\n\n private visitResponses = (context: OasContext) => {\n const statusCodes = this.operation.getResponseStatusCodes();\n\n if (!statusCodes.includes('200') && !statusCodes.includes('default')) {\n throw new Error('Could not find a valid 200 response');\n }\n\n const responses = this.operation.schema.responses;\n if (responses!['200']) {\n this.visitResponse(context, '200', responses!['200'] as ResponseObject);\n } else if (responses!.default) {\n this.visitResponse(context, 'default', responses!.default as ResponseObject);\n } else {\n throw new Error(\"Could not find a '200' or 'default' response\");\n }\n };\n\n private visitResponse(context: OasContext, code: string, response: ResponseObject): void {\n const content = response.content as MediaTypeObject;\n\n if ('$ref' in response) {\n this.visitResponseRef(context, response as ReferenceObject);\n }\n // If the response has a content property, we need to find the JSON content.\n else if (content) {\n const json = response.content!['application/json']!;\n if (!json) {\n warn(context, ` [${code}]`, 'no entry found for content application/json!');\n } else {\n this.visitResponseContent(context, code, json);\n }\n } else if (code === 'default') {\n // there is no response for this operation\n // TODO: should we synthesize one?\n } else {\n throw new Error('Not yet implemented for: ' + JSON.stringify(response));\n }\n }\n\n private visitResponseContent(context: OasContext, _code: string, media: MediaTypeObject): void {\n trace(context, '-> [get::responses::content]', 'in ' + this.name);\n const schema = media!.schema as SchemaObject;\n\n if (!schema) {\n throw new Error('No schema content found!');\n }\n\n this.resultType = Factory.fromResponse(context, this, schema);\n // PENDING: do not visit anymore\n // if (this.resultType) {\n // this.resultType.visit(context);\n // }\n\n if (this.resultType && !this.children.includes(this.resultType)) {\n this.add(this.resultType);\n }\n\n trace(context, '<- [get::responses::content]', 'out ' + this.name);\n }\n\n private visitResponseRef(context: OasContext, ref: ReferenceObject): void {\n trace(context, '-> [get::responses::ref]', `in: ${this.name}, ref: ${ref.$ref}`);\n\n const lookup = context.lookupResponse(ref.$ref!);\n if (!lookup) {\n throw new Error('Could not find a response with ref: ' + ref.$ref);\n }\n\n if ('$ref' in lookup) {\n throw new Error('Not yet implemented for nested refs');\n }\n\n this.visitResponse(context, ref.$ref!, lookup as ResponseObject);\n trace(context, '<- [get::responses::ref]', `out: ${this.name}, ref: ${ref.$ref}`);\n }\n\n private generateParameters(context: OasContext, writer: Writer, selection: string[]): void {\n const sorted = this.params.sort((a, b) => (b.required ? 1 : 0) - (a.required ? 1 : 0));\n\n if (sorted.length === 0) {\n return;\n }\n\n writer.append('(');\n\n sorted.forEach((parameter, index) => {\n if (index > 0) {\n writer.append(', ');\n }\n parameter.generate(context, writer, selection);\n });\n\n writer.append(')');\n }\n\n private visitParameter(context: OasContext, parent: Type, p: ParameterObject): Param {\n trace(context, '->[visitParameter]', 'begin: ' + p.name);\n\n const param = Factory.fromParam(context, parent, p);\n param.visit(context);\n\n trace(context, '<-[visitParameter]', 'end: ' + p.name);\n return param;\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Prop } from './props/prop.js';
|
|
2
|
+
import { OasContext } from '../oasContext.js';
|
|
3
|
+
import { Writer } from '../io/writer.js';
|
|
4
|
+
export interface IType {
|
|
5
|
+
name: string;
|
|
6
|
+
parent?: IType;
|
|
7
|
+
children: IType[];
|
|
8
|
+
circularRef?: IType;
|
|
9
|
+
props: Map<string, Prop>;
|
|
10
|
+
id: string;
|
|
11
|
+
forPrompt(context: OasContext): string;
|
|
12
|
+
add(child: IType): void;
|
|
13
|
+
ancestors(): IType[];
|
|
14
|
+
visit(context: OasContext): void;
|
|
15
|
+
generate(context: OasContext, writer: Writer, selection: string[]): void;
|
|
16
|
+
pathToRoot(): string;
|
|
17
|
+
path(): string;
|
|
18
|
+
expand(context: OasContext): IType[];
|
|
19
|
+
find(path: string, collection: IType[]): IType | boolean;
|
|
20
|
+
select(context: OasContext, writer: Writer, selection: string[]): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iType.js","sourceRoot":"","sources":["../../../src/oas/nodes/iType.ts"],"names":[],"mappings":"","sourcesContent":["import { Prop } from './props/prop.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\n\nexport interface IType {\n name: string;\n parent?: IType;\n children: IType[];\n circularRef?: IType;\n props: Map<string, Prop>;\n id: string;\n\n forPrompt(context: OasContext): string;\n\n add(child: IType): void;\n\n ancestors(): IType[];\n\n visit(context: OasContext): void;\n\n generate(context: OasContext, writer: Writer, selection: string[]): void;\n\n pathToRoot(): string;\n\n path(): string;\n\n expand(context: OasContext): IType[];\n\n find(path: string, collection: IType[]): IType | boolean;\n\n select(context: OasContext, writer: Writer, selection: string[]): void;\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from './iType.js';
|
|
2
|
+
export * from './type.js';
|
|
3
|
+
export * from './arr.js';
|
|
4
|
+
export * from './circularRef.js';
|
|
5
|
+
export * from './comp.js';
|
|
6
|
+
export * from './en.js';
|
|
7
|
+
export * from './factory.js';
|
|
8
|
+
export * from './get.js';
|
|
9
|
+
export * from './obj.js';
|
|
10
|
+
export * from './ref.js';
|
|
11
|
+
export * from './response.js';
|
|
12
|
+
export * from './scalar.js';
|
|
13
|
+
export * from './union.js';
|
|
14
|
+
export * from './props/prop.js';
|
|
15
|
+
export * from './props/propArray.js';
|
|
16
|
+
export * from './props/propObj.js';
|
|
17
|
+
export * from './props/propRef.js';
|
|
18
|
+
export * from './props/propScalar.js';
|
|
19
|
+
export * from './props/referenceObject.js';
|
|
20
|
+
export * from './param/param.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// -- internal.js --
|
|
2
|
+
export * from './iType.js';
|
|
3
|
+
export * from './type.js';
|
|
4
|
+
export * from './arr.js';
|
|
5
|
+
export * from './circularRef.js';
|
|
6
|
+
export * from './comp.js';
|
|
7
|
+
export * from './en.js';
|
|
8
|
+
export * from './factory.js';
|
|
9
|
+
export * from './get.js';
|
|
10
|
+
export * from './obj.js';
|
|
11
|
+
export * from './ref.js';
|
|
12
|
+
export * from './response.js';
|
|
13
|
+
export * from './scalar.js';
|
|
14
|
+
export * from './union.js';
|
|
15
|
+
export * from './props/prop.js';
|
|
16
|
+
export * from './props/propArray.js';
|
|
17
|
+
export * from './props/propObj.js';
|
|
18
|
+
export * from './props/propRef.js';
|
|
19
|
+
export * from './props/propScalar.js';
|
|
20
|
+
export * from './props/referenceObject.js';
|
|
21
|
+
export * from './param/param.js';
|
|
22
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/oas/nodes/internal.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC","sourcesContent":["// -- internal.js --\nexport * from './iType.js';\nexport * from './type.js';\nexport * from './arr.js';\nexport * from './circularRef.js';\nexport * from './comp.js';\nexport * from './en.js';\nexport * from './factory.js';\nexport * from './get.js';\nexport * from './obj.js';\nexport * from './ref.js';\nexport * from './response.js';\nexport * from './scalar.js';\nexport * from './union.js';\nexport * from './props/prop.js';\nexport * from './props/propArray.js';\nexport * from './props/propObj.js';\nexport * from './props/propRef.js';\nexport * from './props/propScalar.js';\nexport * from './props/referenceObject.js';\nexport * from './param/param.js';\n"]}
|
package/dist/oas/nodes/obj.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { IType, Type } from './internal.js';
|
|
1
2
|
import { SchemaObject } from 'oas/types';
|
|
2
3
|
import { OasContext } from '../oasContext.js';
|
|
3
4
|
import { Writer } from '../io/writer.js';
|
|
4
|
-
import { IType, Type } from './type.js';
|
|
5
5
|
export declare class Obj extends Type {
|
|
6
6
|
schema: SchemaObject;
|
|
7
7
|
constructor(parent: IType | undefined, name: string, schema: SchemaObject);
|
|
8
|
-
forPrompt(
|
|
8
|
+
forPrompt(_context: OasContext): string;
|
|
9
9
|
get id(): string;
|
|
10
10
|
visit(context: OasContext): void;
|
|
11
11
|
generate(context: OasContext, writer: Writer, selection: string[]): void;
|
package/dist/oas/nodes/obj.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Type } from './internal.js';
|
|
1
2
|
import { trace } from '../log/trace.js';
|
|
2
3
|
import { Naming } from '../utils/naming.js';
|
|
3
4
|
import { Arr } from './arr.js';
|
|
@@ -5,7 +6,6 @@ import { Factory } from './factory.js';
|
|
|
5
6
|
import { PropArray } from './props/propArray.js';
|
|
6
7
|
import { Ref } from './ref.js';
|
|
7
8
|
import { Response } from './response.js';
|
|
8
|
-
import { Type } from './type.js';
|
|
9
9
|
export class Obj extends Type {
|
|
10
10
|
schema;
|
|
11
11
|
constructor(parent, name, schema) {
|
|
@@ -13,7 +13,7 @@ export class Obj extends Type {
|
|
|
13
13
|
this.schema = schema;
|
|
14
14
|
this.updateName();
|
|
15
15
|
}
|
|
16
|
-
forPrompt(
|
|
16
|
+
forPrompt(_context) {
|
|
17
17
|
return `${Naming.getRefName(this.name)} (Obj)`;
|
|
18
18
|
}
|
|
19
19
|
get id() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"obj.js","sourceRoot":"","sources":["../../../src/oas/nodes/obj.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAS,IAAI,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,OAAO,GAAI,SAAQ,IAAI;IAIlB;IAHT,YACE,MAAyB,EACzB,IAAY,EACL,MAAoB;QAE3B,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAFb,WAAM,GAAN,MAAM,CAAc;QAG3B,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAEM,SAAS,CAAC,OAAmB;QAClC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;IACjD,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5B,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,KAAK,CAAC,OAAO,EAAE,gBAA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C,IAAI;QACJ,EAAE;QACF,SAAS;QACT,aAAa;QACb,uBAAuB;QACvB,sEAAsE;QACtE,KAAK;QACL,EAAE;QACF,iBAAiB;QACjB,4CAA4C;QAC5C,0CAA0C;QAC1C,qBAAqB;QACrB,8FAA8F;QAC9F,QAAQ;QACR,aAAa;QACb,EAAE;QACF,0CAA0C;QAC1C,2DAA2D;QAC3D,yCAAyC;QACzC,iBAAiB;QACjB,cAAc;QACd,sBAAsB;QACtB,uBAAuB;QACvB,SAAS;QACT,WAAW;QACX,0BAA0B;QAC1B,qCAAqC;QACrC,uBAAuB;QACvB,oDAAoD;QACpD,WAAW;QACX,UAAU;QACV,4DAA4D;QAC5D,4CAA4C;QAC5C,6CAA6C;QAC7C,0BAA0B;QAC1B,UAAU;QACV,QAAQ;QACR,MAAM;QACN,IAAI;QACJ,EAAE;QACF,iCAAiC;QACjC,KAAK,CAAC,OAAO,EAAE,iBAAiB,EAAE,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpE,CAAC;CACF","sourcesContent":["import { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\nimport { Arr } from './arr.js';\nimport { Factory } from './factory.js';\nimport { Get } from './get.js';\nimport { PropArray } from './props/propArray.js';\nimport { Ref } from './ref.js';\nimport { Response } from './response.js';\nimport { IType, Type } from './type.js';\n\nexport class Obj extends Type {\n constructor(\n parent: IType | undefined,\n name: string,\n public schema: SchemaObject,\n ) {\n super(parent, name);\n this.updateName();\n }\n\n public forPrompt(context: OasContext): string {\n return `${Naming.getRefName(this.name)} (Obj)`;\n }\n\n get id(): string {\n return `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, '-> [obj:visit]', 'in ' + this.name);\n\n if (!context.inContextOf('Composed', this)) {\n trace(context, '[obj]', 'In object: ' + (this.name ? this.name : this.parent?.name));\n }\n\n this.visitProperties(context);\n this.visited = true;\n\n if (this.name) {\n context.store(this.name, this);\n }\n\n trace(context, '<- [obj:visit]', 'out ' + this.name);\n context.leave(this);\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n if (this.props.size === 0) {\n return;\n }\n\n if (context.inContextOf('Response', this)) {\n writer.append(Naming.genTypeName(this.name));\n return;\n }\n\n context.enter(this);\n trace(context, '-> [obj::generate]', `-> in: ${this.name}`);\n\n const sanitised = Naming.genTypeName(this.name);\n const refName = Naming.getRefName(this.name);\n\n writer\n .append('type ')\n .append(sanitised === refName ? refName : sanitised)\n .append(' {\\n');\n\n const selected = this.selectedProps(selection);\n for (const prop of selected) {\n trace(context, '-> [obj::generate]', `-> property: ${prop.name} (parent: ${prop.parent!.name})`);\n prop.generate(context, writer, selection);\n }\n\n writer.append('}\\n\\n');\n\n trace(context, '<- [obj::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [obj::select]', `-> in: ${this.name}`);\n\n const selected = this.selectedProps(selection);\n for (const prop of selected) {\n prop.select(context, writer, selection);\n }\n\n trace(context, '<- [obj::select]', `-> out: ${this.name}`);\n }\n\n private updateName(): void {\n let name = this.name;\n // If we are an inline object named \"items\", try to create a better name.\n if (!name || name === 'items') {\n const parent = this.parent;\n const parentName = parent!.name;\n\n // if the parent is a reference, we can use the name of the obj itself\n if (parent instanceof Ref) {\n name = parentName.replace('ref:', 'obj:');\n }\n // else is our parent an array?\n else if (parent instanceof Arr || parent instanceof PropArray) {\n // if so, synthesize a name based on the parent name\n name = Naming.genTypeName(Naming.getRefName(parentName) + 'Item');\n }\n // if the parent is a response, we can use the operation name and append \"Response\"\n else if (parent instanceof Response) {\n const op = parent.parent as Get;\n name = op.getGqlOpName() + 'Response';\n }\n // if the parent is an object then we can use the parent name\n else if (parent instanceof Obj) {\n name = parentName + 'Obj';\n }\n // extreme case -- we synthesize an anonymous name\n else {\n name = `[anonymous:${this.parent!.name}]`;\n }\n }\n\n this.name = name;\n }\n\n private visitProperties(context: OasContext): void {\n if (!this.schema.properties) {\n return;\n }\n\n const properties = this.schema.properties as Record<string, SchemaObject>;\n const propKeys = Object.keys(properties);\n trace(context, '-> [obj::props]', 'in props ' + (propKeys.length === 0 ? '0' : propKeys.length.toString()));\n\n if (propKeys.length === 0) {\n trace(context, '<- [obj::props]', 'no props ' + this.props.size);\n return;\n }\n\n const sorted = Object.entries(properties).sort((a, b) => a[0].toLowerCase().localeCompare(b[0].toLowerCase()));\n\n for (const [key, schemaValue] of sorted) {\n const prop = Factory.fromProp(context, this, key, schemaValue);\n this.props.set(prop.name, prop);\n\n // TODO: we should not be adding this twice\n if (!this.children.includes(prop)) {\n this.add(prop);\n }\n }\n\n // const propertiesNames = Array.from(collected.values())\n // .map((p) => p.forPrompt(context))\n // .join(',\\n - ');\n //\n // const inCompose = context.inContextOf(Composed, this);\n // const inComposeIdx = Type.findAncestorOf(this, Composed);\n // const inArrayIdx = Type.findAncestorOf(this, PropArray);\n //\n // if (!inCompose || inArrayIdx > inComposeIdx) {\n // console.log('Obj.visitProperties HERE');\n // }\n //\n // trace(\n // context,\n // ' [obj::props]',\n // `${this.getSimpleName()} is within compose context? ${inCompose}`\n // );\n //\n // const addAll =\n // !inCompose || inArrayIdx > inComposeIdx\n // ? await context.prompt.yesNoSelect(\n // this.path(),\n // ` -> Add all properties from [object] ${this.getOwner()}?: \\n - ${propertiesNames}\\n`\n // )\n // : 'y';\n //\n // if (addAll === 'y' || addAll === 's') {\n // for (const [propertyName, propertySchema] of sorted) {\n // const prop = Factory.fromProperty(\n // context,\n // this,\n // propertyName,\n // propertySchema\n // );\n // if (\n // addAll === 'y' ||\n // (await context.prompt.yesNo(\n // prop.path(),\n // `Add field '${prop.forPrompt(context)}'?`\n // ))\n // ) {\n // trace(context, ' [obj::props]', 'prop: ' + prop);\n // this.props.set(propertyName, prop);\n // if (!this.children.includes(prop)) {\n // this.add(prop);\n // }\n // }\n // }\n // }\n //\n // this.addDependencies(context);\n trace(context, '<- [obj::props]', 'out props ' + this.props.size);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"obj.js","sourceRoot":"","sources":["../../../src/oas/nodes/obj.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,IAAI,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,OAAO,GAAI,SAAQ,IAAI;IAIlB;IAHT,YACE,MAAyB,EACzB,IAAY,EACL,MAAoB;QAE3B,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAFb,WAAM,GAAN,MAAM,CAAc;QAG3B,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAEM,SAAS,CAAC,QAAoB;QACnC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;IACjD,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5B,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,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;Q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B;QACvB,sEAAsE;QACtE,KAAK;QACL,EAAE;QACF,iBAAiB;QACjB,4CAA4C;QAC5C,0CAA0C;QAC1C,qBAAqB;QACrB,8FAA8F;QAC9F,QAAQ;QACR,aAAa;QACb,EAAE;QACF,0CAA0C;QAC1C,2DAA2D;QAC3D,yCAAyC;QACzC,iBAAiB;QACjB,cAAc;QACd,sBAAsB;QACtB,uBAAuB;QACvB,SAAS;QACT,WAAW;QACX,0BAA0B;QAC1B,qCAAqC;QACrC,uBAAuB;QACvB,oDAAoD;QACpD,WAAW;QACX,UAAU;QACV,4DAA4D;QAC5D,4CAA4C;QAC5C,6CAA6C;QAC7C,0BAA0B;QAC1B,UAAU;QACV,QAAQ;QACR,MAAM;QACN,IAAI;QACJ,EAAE;QACF,iCAAiC;QACjC,KAAK,CAAC,OAAO,EAAE,iBAAiB,EAAE,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpE,CAAC;CACF","sourcesContent":["import { IType, 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';\nimport { Arr } from './arr.js';\nimport { Factory } from './factory.js';\nimport { Get } from './get.js';\nimport { PropArray } from './props/propArray.js';\nimport { Ref } from './ref.js';\nimport { Response } from './response.js';\n\nexport class Obj extends Type {\n constructor(\n parent: IType | undefined,\n name: string,\n public schema: SchemaObject,\n ) {\n super(parent, name);\n this.updateName();\n }\n\n public forPrompt(_context: OasContext): string {\n return `${Naming.getRefName(this.name)} (Obj)`;\n }\n\n get id(): string {\n return `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, '-> [obj:visit]', 'in ' + this.name);\n\n if (!context.inContextOf('Composed', this)) {\n trace(context, '[obj]', 'In object: ' + (this.name ? this.name : this.parent?.name));\n }\n\n this.visitProperties(context);\n this.visited = true;\n\n if (this.name) {\n context.store(this.name, this);\n }\n\n trace(context, '<- [obj:visit]', 'out ' + this.name);\n context.leave(this);\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n if (this.props.size === 0) {\n return;\n }\n\n if (context.inContextOf('Response', this)) {\n writer.append(Naming.genTypeName(this.name));\n return;\n }\n\n context.enter(this);\n trace(context, '-> [obj::generate]', `-> in: ${this.name}`);\n\n const sanitised = Naming.genTypeName(this.name);\n const refName = Naming.getRefName(this.name);\n\n writer\n .append('type ')\n .append(sanitised === refName ? refName : sanitised)\n .append(' {\\n');\n\n const selected = this.selectedProps(selection);\n for (const prop of selected) {\n trace(context, '-> [obj::generate]', `-> property: ${prop.name} (parent: ${prop.parent!.name})`);\n prop.generate(context, writer, selection);\n }\n\n writer.append('}\\n\\n');\n\n trace(context, '<- [obj::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [obj::select]', `-> in: ${this.name}`);\n\n const selected = this.selectedProps(selection);\n for (const prop of selected) {\n prop.select(context, writer, selection);\n }\n\n trace(context, '<- [obj::select]', `-> out: ${this.name}`);\n }\n\n private updateName(): void {\n let name = this.name;\n // If we are an inline object named \"items\", try to create a better name.\n if (!name || name === 'items') {\n const parent = this.parent;\n const parentName = parent!.name;\n\n // if the parent is a reference, we can use the name of the obj itself\n if (parent instanceof Ref) {\n name = parentName.replace('ref:', 'obj:');\n }\n // else is our parent an array?\n else if (parent instanceof Arr || parent instanceof PropArray) {\n // if so, synthesize a name based on the parent name\n name = Naming.genTypeName(Naming.getRefName(parentName) + 'Item');\n }\n // if the parent is a response, we can use the operation name and append \"Response\"\n else if (parent instanceof Response) {\n const op = parent.parent as Get;\n name = op.getGqlOpName() + 'Response';\n }\n // if the parent is an object then we can use the parent name\n else if (parent instanceof Obj) {\n name = parentName + 'Obj';\n }\n // extreme case -- we synthesize an anonymous name\n else {\n name = `[anonymous:${this.parent!.name}]`;\n }\n }\n\n this.name = name;\n }\n\n private visitProperties(context: OasContext): void {\n if (!this.schema.properties) {\n return;\n }\n\n const properties = this.schema.properties as Record<string, SchemaObject>;\n const propKeys = Object.keys(properties);\n trace(context, '-> [obj::props]', 'in props ' + (propKeys.length === 0 ? '0' : propKeys.length.toString()));\n\n if (propKeys.length === 0) {\n trace(context, '<- [obj::props]', 'no props ' + this.props.size);\n return;\n }\n\n const sorted = Object.entries(properties).sort((a, b) => a[0].toLowerCase().localeCompare(b[0].toLowerCase()));\n\n for (const [key, schemaValue] of sorted) {\n const prop = Factory.fromProp(context, this, key, schemaValue);\n this.props.set(prop.name, prop);\n\n // TODO: we should not be adding this twice\n if (!this.children.includes(prop)) {\n this.add(prop);\n }\n }\n\n // const propertiesNames = Array.from(collected.values())\n // .map((p) => p.forPrompt(context))\n // .join(',\\n - ');\n //\n // const inCompose = context.inContextOf(Composed, this);\n // const inComposeIdx = Type.findAncestorOf(this, Composed);\n // const inArrayIdx = Type.findAncestorOf(this, PropArray);\n //\n // if (!inCompose || inArrayIdx > inComposeIdx) {\n // console.log('Obj.visitProperties HERE');\n // }\n //\n // trace(\n // context,\n // ' [obj::props]',\n // `${this.getSimpleName()} is within compose context? ${inCompose}`\n // );\n //\n // const addAll =\n // !inCompose || inArrayIdx > inComposeIdx\n // ? await context.prompt.yesNoSelect(\n // this.path(),\n // ` -> Add all properties from [object] ${this.getOwner()}?: \\n - ${propertiesNames}\\n`\n // )\n // : 'y';\n //\n // if (addAll === 'y' || addAll === 's') {\n // for (const [propertyName, propertySchema] of sorted) {\n // const prop = Factory.fromProperty(\n // context,\n // this,\n // propertyName,\n // propertySchema\n // );\n // if (\n // addAll === 'y' ||\n // (await context.prompt.yesNo(\n // prop.path(),\n // `Add field '${prop.forPrompt(context)}'?`\n // ))\n // ) {\n // trace(context, ' [obj::props]', 'prop: ' + prop);\n // this.props.set(propertyName, prop);\n // if (!this.children.includes(prop)) {\n // this.add(prop);\n // }\n // }\n // }\n // }\n //\n // this.addDependencies(context);\n trace(context, '<- [obj::props]', 'out props ' + this.props.size);\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { IType, Type } from '../internal.js';
|
|
1
2
|
import { ParameterObject, SchemaObject } from 'oas/types';
|
|
2
3
|
import { OasContext } from '../../oasContext.js';
|
|
3
4
|
import { Writer } from '../../io/writer.js';
|
|
4
|
-
import { IType, Type } from '../type.js';
|
|
5
5
|
export declare class Param extends Type {
|
|
6
6
|
schema: SchemaObject;
|
|
7
7
|
required: boolean;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { Factory, Type } from '../internal.js';
|
|
1
2
|
import { trace } from '../../log/trace.js';
|
|
2
3
|
import { Naming } from '../../utils/naming.js';
|
|
3
|
-
import { Factory } from '../factory.js';
|
|
4
|
-
import { Type } from '../type.js';
|
|
5
4
|
export class Param extends Type {
|
|
6
5
|
schema;
|
|
7
6
|
required;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"param.js","sourceRoot":"","sources":["../../../../src/oas/nodes/param/param.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"param.js","sourceRoot":"","sources":["../../../../src/oas/nodes/param/param.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,MAAM,OAAO,KAAM,SAAQ,IAAI;IAMpB;IACA;IACA;IACA;IARF,UAAU,CAAS;IAE1B,YACE,MAAa,EACb,IAAY,EACL,MAAoB,EACpB,QAAiB,EACjB,YAAqB,EACrB,SAA0B;QAEjC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QALb,WAAM,GAAN,MAAM,CAAc;QACpB,aAAQ,GAAR,QAAQ,CAAS;QACjB,iBAAY,GAAZ,YAAY,CAAS;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I,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YAClE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,sBAAsB,EAAE,WAAW,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC/D,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAEM,SAAS,CAAC,OAAmB;QAClC,OAAO,eAAe,IAAI,CAAC,IAAI,cAAc,IAAI,CAAC,QAAQ,kBAAkB,IAAI,CAAC,YAAY,WAAW,IAAI,CAAC,KAAK,gBAAgB,IAAI,CAAC,UAAU,IAAI,CAAC;IACxJ,CAAC;IAEM,MAAM,CAAC,OAAmB,EAAE,MAAc,EAAE,SAAmB;QACpE,aAAa;IACf,CAAC;IAEO,iBAAiB,CAAC,MAAc;QACtC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACpB,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC;QAEhC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjC,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAClB,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAC5B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;CACF","sourcesContent":["import { Factory, IType, Type } from '../internal.js';\nimport { ParameterObject, 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 Param extends Type {\n public resultType!: IType;\n\n constructor(\n parent: IType,\n name: string,\n public schema: SchemaObject,\n public required: boolean,\n public defaultValue: unknown,\n public parameter: ParameterObject,\n ) {\n super(parent, name);\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n trace(context, '-> [param:visit]', 'in: ' + this.name);\n\n this.resultType = Factory.fromSchema(this, this.schema);\n trace(context, ' [param:visit]', 'type: ' + this.resultType);\n this.resultType.visit(context);\n\n trace(context, '<- [param:visit]', 'out: ' + this.name);\n context.leave(this);\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n context.enter(this);\n trace(context, '-> [param::generate]', `-> in: ${this.name}`);\n\n writer.write(Naming.genParamName(this.name));\n writer.write(': ');\n\n this.resultType.generate(context, writer, selection);\n\n if (this.required) {\n writer.write('!');\n }\n\n if (this.defaultValue !== null && this.defaultValue !== undefined) {\n this.writeDefaultValue(writer);\n }\n\n trace(context, '<- [param::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public forPrompt(context: OasContext): string {\n return `Param{ name=${this.name}, required=${this.required}, defaultValue=${this.defaultValue}, props=${this.props}, resultType=${this.resultType} }`;\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n // do nothing\n }\n\n private writeDefaultValue(writer: Writer): void {\n writer.write(' = ');\n const value = this.defaultValue;\n\n if (typeof value === 'number') {\n writer.write(value.toString());\n } else if (typeof value === 'string') {\n writer.write('\"');\n writer.write(String(value));\n writer.write('\"');\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/internal.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC","sourcesContent":["export * from './prop.js';\nexport * from './propArray.js';\nexport * from './propObj.js';\nexport * from './propRef.js';\nexport * from './propScalar.js';\nexport * from './referenceObject.js';\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { IType, Type } from '../internal.js';
|
|
1
2
|
import { SchemaObject } from 'oas/types';
|
|
2
3
|
import { OasContext } from '../../oasContext.js';
|
|
3
4
|
import { Writer } from '../../io/writer.js';
|
|
4
|
-
import { IType, Type } from '../type.js';
|
|
5
5
|
export declare abstract class Prop extends Type {
|
|
6
6
|
schema: SchemaObject;
|
|
7
7
|
required: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prop.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/prop.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prop.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/prop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAI7C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,MAAM,OAAgB,IAAK,SAAQ,IAAI;IAM5B;IALF,QAAQ,GAAY,KAAK,CAAC;IAEjC,YACE,MAAyB,EACzB,IAAY,EACL,MAAoB;QAE3B,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAFb,WAAM,GAAN,MAAM,CAAc;IAG7B,CAAC;IAEM,QAAQ,CAAC,OAAmB,EAAE,MAAc,EAAE,SAAmB;QACtE,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QAC5C,IAAI,WAAW,IAAI,IAAI,EAAE,CAAC;YACxB,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC1F,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAChF,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEzE,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAEpC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;QAED,eAAe;QACf,4CAA4C;QAE5C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAIS,aAAa,CAAC,OAAmB,EAAE,MAAc;QACzD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import { IType, Type } from '../internal.js';\nimport { SchemaObject } from 'oas/types';\nimport { OasContext } from '../../oasContext.js';\nimport { Writer } from '../../io/writer.js';\nimport { Naming } from '../../utils/naming.js';\n\nexport abstract class Prop extends Type {\n public required: boolean = false;\n\n constructor(\n parent: IType | undefined,\n name: string,\n public schema: SchemaObject,\n ) {\n super(parent, name);\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n const description = this.schema.description;\n if (description != null) {\n if (description.includes('\\n') || description.includes('\\r') || description.includes('\"')) {\n writer.append(' \"\"\"\\n').append(' ').append(description).append('\\n \"\"\"\\n');\n } else {\n writer.append(' \"').append(description).append('\"\\n');\n }\n }\n\n writer.append(' ').append(Naming.sanitiseField(this.name)).append(': ');\n\n this.generateValue(context, writer);\n\n if (this.required) {\n writer.append('!');\n }\n\n // TODO: source\n // writer.append(\" # \").append(this.parent);\n\n writer.append('\\n');\n }\n\n public abstract getValue(context: OasContext): string;\n\n protected generateValue(context: OasContext, writer: Writer): void {\n writer.append(this.getValue(context));\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { IType } from '../internal.js';
|
|
2
|
+
import { Prop } from './internal.js';
|
|
1
3
|
import { OasContext } from '../../oasContext.js';
|
|
2
4
|
import { Writer } from '../../io/writer.js';
|
|
3
|
-
import { IType } from '../type.js';
|
|
4
|
-
import { Prop } from '../props/prop.js';
|
|
5
5
|
export declare class PropArray extends Prop {
|
|
6
6
|
items?: Prop;
|
|
7
7
|
get id(): string;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import { Factory } from '../internal.js';
|
|
2
|
+
import { Prop, PropObj, PropRef } from './internal.js';
|
|
1
3
|
import { trace } from '../../log/trace.js';
|
|
2
4
|
import { Naming } from '../../utils/naming.js';
|
|
3
|
-
import { Factory } from '../factory.js';
|
|
4
|
-
import { PropObj } from './propObj.js';
|
|
5
|
-
import { PropRef } from './propRef.js';
|
|
6
|
-
import { Prop } from '../props/prop.js';
|
|
7
5
|
export class PropArray extends Prop {
|
|
8
6
|
items;
|
|
9
7
|
get id() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propArray.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/propArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"propArray.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/propArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C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M,CAAC,IAAI,CAAC,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC;QAED,uCAAuC;QACvC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAM,CAAC,QAAQ,EAAE,CAAC;YACzC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QAC3C,CAAC;QAED,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAM,CAAC,EAAE,CAAC;YACpC,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,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEpB,KAAK,CAAC,OAAO,EAAE,wBAAwB,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC;IAEM,aAAa,CAAC,KAAY;QAC/B,OAAO,KAAK,YAAY,OAAO,IAAI,KAAK,YAAY,OAAO,CAAC;IAC9D,CAAC;CACF","sourcesContent":["import { Factory, IType } from '../internal.js';\nimport { Prop, PropObj, PropRef } 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 for (const child of this.items!.children) {\n child.select(context, writer, selection);\n }\n\n if (this.needsBrackets(this.items!)) {\n context.leave(this);\n writer.append(' '.repeat(context.indent + context.stack.length)).append('}');\n }\n writer.append('\\n');\n\n trace(context, '<- [prop:array:select]', 'out');\n }\n\n public needsBrackets(child: IType): boolean {\n return child instanceof PropRef || child instanceof PropObj;\n }\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { IType } from '../internal.js';
|
|
2
|
+
import { Prop } from './internal.js';
|
|
1
3
|
import { SchemaObject } from 'oas/types';
|
|
2
|
-
import { IType } from '../type.js';
|
|
3
4
|
import { OasContext } from '../../oasContext.js';
|
|
4
5
|
import { Writer } from '../../io/writer.js';
|
|
5
|
-
import { Prop } from './prop.js';
|
|
6
6
|
export declare class PropObj extends Prop {
|
|
7
7
|
schema: SchemaObject;
|
|
8
8
|
obj: IType;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import { Obj, Union } from '../internal.js';
|
|
2
|
+
import { Prop } from './internal.js';
|
|
1
3
|
import _ from 'lodash';
|
|
2
4
|
import { trace } from '../../log/trace.js';
|
|
3
5
|
import { Composed } from '../comp.js';
|
|
4
|
-
import { Obj } from '../obj.js';
|
|
5
|
-
import { Union } from '../union.js';
|
|
6
6
|
import { Naming } from '../../utils/naming.js';
|
|
7
|
-
import { Prop } from './prop.js';
|
|
8
7
|
export class PropObj extends Prop {
|
|
9
8
|
schema;
|
|
10
9
|
obj;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propObj.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/propObj.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"propObj.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/propObj.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,GAAG,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,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,8CAA8C;QAC9C,IAAI,GAAG,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YACxB,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CAAC,CAAC;IAC1F,CAAC;IAEO,aAAa,CAAC,KAAY;QAChC,OAAO,KAAK,YAAY,GAAG,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,YAAY,QAAQ,CAAC;IACrF,CAAC;CAqBF","sourcesContent":["import { 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 reparenting is necessary?!?!\n if (obj.parent !== this) {\n obj.parent = this;\n }\n\n // this.updateName(parent);\n }\n\n public forPrompt(_context: OasContext): string {\n return _.lowerFirst(this.name) + ': ' + Naming.getRefName(this.obj.name) + ' (Obj)';\n }\n\n get id(): string {\n return 'prop:obj:' + this.name;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n trace(context, '-> [prop-obj:visit]', 'in ' + this.name + ', obj: ' + this.obj.name);\n\n this.obj.visit(context);\n if (!this.children.includes(this.obj)) {\n this.add(this.obj);\n }\n this.visited = true;\n\n trace(context, '<- [prop-obj:visit]', 'out ' + this.name + ', obj: ' + this.obj.name);\n context.leave(this);\n }\n\n public getValue(context: OasContext): string {\n return Naming.genTypeName(this.name);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [prop-obj:select]', 'in ' + this.name + ', obj: ' + this.obj.name);\n\n const fieldName = this.name;\n const sanitised = Naming.sanitiseFieldForSelect(fieldName);\n\n writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);\n\n if (this.needsBrackets(this.obj!)) {\n writer.append(' {').append('\\n');\n context.enter(this);\n }\n\n for (const child of this.children) {\n child.select(context, writer, selection);\n }\n\n if (this.needsBrackets(this.obj!)) {\n context.leave(this);\n writer.append(' '.repeat(context.indent + context.stack.length)).append('}');\n writer.append('\\n');\n }\n\n trace(context, '<- [prop-obj:select]', 'out ' + this.name + ', obj: ' + this.obj?.name);\n }\n\n private needsBrackets(child: IType): boolean {\n return child instanceof Obj || child instanceof Union || child instanceof Composed;\n }\n\n /*\n private updateName(parent: IType): void {\n if (this.name === 'items') {\n const parentName = parent.name;\n // if the part is a ref, then use replace for the pointed object\n if (parent instanceof PropRef) {\n this.name = parentName.replace('ref:', 'obj:');\n }\n // if within an array, synthesize a name\n else if (parent.constructor.name === 'PropArray') {\n this.name = parentName + 'Item';\n }\n // create a anonymous name\n else {\n this.name = `[prop:obj:anonymous:${this.parent?.name}]`;\n }\n }\n }\n*/\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OasContext } from '../../oasContext.js';
|
|
2
|
-
import {
|
|
2
|
+
import { IType } from '../internal.js';
|
|
3
|
+
import { Prop } from './internal.js';
|
|
3
4
|
import { SchemaObject } from 'oas/types';
|
|
4
|
-
import { IType } from '../type.js';
|
|
5
5
|
import { Writer } from '../../io/writer.js';
|
|
6
6
|
export declare class PropRef extends Prop {
|
|
7
7
|
schema: SchemaObject;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Arr, CircularRef, Composed, Factory, Obj, Union } from '../internal.js';
|
|
2
|
+
import { Prop } from './internal.js';
|
|
2
3
|
import _ from 'lodash';
|
|
3
4
|
import { trace } from '../../log/trace.js';
|
|
4
5
|
import { Naming } from '../../utils/naming.js';
|
|
5
|
-
import { Arr } from '../arr.js';
|
|
6
|
-
import { CircularRef } from '../circularRef.js';
|
|
7
|
-
import { Composed } from '../comp.js';
|
|
8
|
-
import { Factory } from '../factory.js';
|
|
9
|
-
import { Obj } from '../obj.js';
|
|
10
|
-
import { Union } from '../union.js';
|
|
11
6
|
export class PropRef extends Prop {
|
|
12
7
|
schema;
|
|
13
8
|
ref;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propRef.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/propRef.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"propRef.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/propRef.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAS,GAAG,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACxF,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,MAAM,OAAO,OAAQ,SAAQ,IAAI;IAStB;IACA;IATT,IAAI,EAAE;QACJ,OAAO,aAAa,IAAI,CAAC,IAAI,EAAE,CAAC;IAClC,CAAC;IACM,OAAO,CAAS;IAEvB,YACE,MAAyB,EACzB,IAAY,EACL,MAAoB,EACpB,GAAW;QAElB,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAHrB,WAAM,GAAN,MAAM,CAAc;QACpB,QAAG,GAAH,GAAG,CAAQ;IAGpB,CAAC;IAEe,GAAG,CAAC,KAAY;QAC9B,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC;QACtB,MAAM,KAAK,GAAY,IAAI,CAAC,SAAS,EAAE,CAAC;QACxC,MAAM,QAAQ,GAAY,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAEpE,KAAK,CAAC,IAAI,EAAE,mBAAmB,EAAE,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,CAAC,IAAI,CAAC,CAAC,CAAC;YACzC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAEO,aAAa,CAAC,KAAY;QAChC,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,SAAU,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,KAAK,YAAY,GAAG,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,YAAY,QAAQ,IAAI,KAAK,YAAY,WAAW,CAAC;IACrH,CAAC;CACF","sourcesContent":["import { OasContext } from '../../oasContext.js';\nimport { Arr, CircularRef, Composed, Factory, IType, Obj, Union } from '../internal.js';\nimport { Prop } from './internal.js';\nimport _ from 'lodash';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../../log/trace.js';\nimport { Writer } from '../../io/writer.js';\nimport { Naming } from '../../utils/naming.js';\n\nexport class PropRef extends Prop {\n get id(): string {\n return `prop:ref:#${this.name}`;\n }\n public refType?: IType;\n\n constructor(\n parent: IType | undefined,\n name: string,\n public schema: SchemaObject,\n public ref: string,\n ) {\n super(parent, name, schema);\n }\n\n public override add(child: IType): void {\n child.name = this.ref;\n const paths: IType[] = this.ancestors();\n const contains: boolean = paths.map((p) => p.id).includes(child.id);\n\n trace(null, '-> [prop-ref:add]', 'contains child? ' + contains);\n if (contains) {\n const ancestor: IType = paths[paths.map((p) => p.id).indexOf(child.id)];\n const wrapper = Factory.fromCircularRef(this, ancestor);\n super.add(wrapper);\n this.visited = true;\n this.refType = wrapper;\n } else {\n super.add(child);\n }\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n context.enter(this);\n trace(context, '-> [prop-ref:visit]', 'in ' + this.name + ', ref: ' + this.ref);\n\n const schema = context.lookupRef(this.ref);\n if (!schema) {\n throw new Error('Schema not found for ref: ' + this.ref);\n }\n\n const type = Factory.fromSchema(this, schema);\n if (!this.refType) {\n this.refType = type;\n type.name = this.ref;\n type.visit(context);\n\n if (!this.children.includes(this.refType!)) {\n this.add(this.refType!);\n }\n\n this.visited = true;\n }\n trace(context, '<- [prop-ref:visit]', 'out ' + this.name + ', ref: ' + this.ref);\n context.leave(this);\n }\n\n public getValue(_context: OasContext): string {\n const type = this.refType!;\n const name = type ? type.name : this.ref;\n return Naming.genTypeName(name!);\n }\n\n public forPrompt(context: OasContext): string {\n return `${this.name}: ${Naming.getRefName(this.ref)} (Ref)`;\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [prop-ref:select]', 'in ' + this.name + ', ref: ' + this.ref);\n const fieldName = this.name;\n const sanitised = Naming.sanitiseFieldForSelect(fieldName);\n writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);\n\n if (this.refType && this.needsBrackets(this.refType)) {\n writer.append(' {').append('\\n');\n context.enter(this);\n }\n\n for (const child of this.children) {\n child.select(context, writer, selection);\n }\n\n if (this.refType && this.needsBrackets(this.refType)) {\n context.leave(this);\n writer.append(' '.repeat(context.indent + context.stack.length)).append('}');\n }\n\n writer.append('\\n');\n trace(context, '<- [prop-ref:select]', 'out ' + this.name + ', ref: ' + this.ref);\n }\n\n protected generateValue(context: OasContext, writer: Writer): void {\n const type = this.refType;\n\n if (type && (type as IType) instanceof Arr) {\n writer.append('[');\n const items = (type as Arr).itemsType;\n writer.append(_.upperFirst(items!.name));\n writer.append(']');\n } else {\n writer.append(this.getValue(context));\n }\n }\n\n private needsBrackets(child: IType): boolean {\n if (child instanceof Arr) {\n return this.needsBrackets(child.itemsType!);\n }\n return child instanceof Obj || child instanceof Union || child instanceof Composed || child instanceof CircularRef;\n }\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { IType } from '../internal.js';
|
|
2
|
+
import { Prop } from './internal.js';
|
|
1
3
|
import { SchemaObject } from 'oas/types';
|
|
2
4
|
import { OasContext } from '../../oasContext.js';
|
|
3
5
|
import { Writer } from '../../io/writer.js';
|
|
4
|
-
import { IType } from '../type.js';
|
|
5
|
-
import { Prop } from '../props/prop.js';
|
|
6
6
|
export declare class PropScalar extends Prop {
|
|
7
7
|
type: string;
|
|
8
8
|
schema: SchemaObject;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Factory } from '../internal.js';
|
|
2
|
+
import { Prop } from './internal.js';
|
|
1
3
|
import { trace } from '../../log/trace.js';
|
|
2
4
|
import { Naming } from '../../utils/naming.js';
|
|
3
|
-
import { Factory } from '../factory.js';
|
|
4
|
-
import { Prop } from '../props/prop.js';
|
|
5
5
|
export class PropScalar extends Prop {
|
|
6
6
|
type;
|
|
7
7
|
schema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propScalar.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/propScalar.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"propScalar.js","sourceRoot":"","sources":["../../../../src/oas/nodes/props/propScalar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,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,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Object } 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\n .append(' '.repeat(context.indent + context.stack.length))\n .append(sanitised)\n .append('\\n');\n\n for (const child of this.children) {\n child.select(context, writer, selection);\n }\n }\n}\n"]}
|