本文整理汇总了TypeScript中strands.Strands.return方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Strands.return方法的具体用法?TypeScript Strands.return怎么用?TypeScript Strands.return使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类strands.Strands
的用法示例。
在下文中一共展示了Strands.return方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createResource
// Create nested resource instances.
private createResource(resource: NestedResource) {
this.currentPath.push(uppercamelcase(resource.methodName));
const { withParams, noParams } = separateChildren(resource);
const className = this.currentPath.join('.');
this.buffer.return();
// Check if this class is already there
if (this.classes.filter(x => x === className).length > 0) {
this.createProtoMethods(resource.methods, 'this.client', 'this.path', className);
} else {
this.classes.push(className);
if (className.indexOf('.') > 0) {
this.buffer.line(`${className} = class {`);
} else {
this.buffer.line(`class ${className} {`);
}
this.buffer.line(` constructor(client, path) {`);
this.buffer.line(` this.client = client;`);
this.buffer.line(` this.path = path;`);
this.createThisResources(withParams, noParams, 'this.client');
this.buffer.line(` }`);
this.createProtoResources(withParams, noParams);
this.createProtoMethods(resource.methods, 'this.client', 'this.path');
if (className.indexOf('.') > 0) {
this.buffer.line(`};`);
} else {
this.buffer.line(`}`);
}
this.createChildren(resource.children);
}
this.currentPath.pop();
}
示例2: camelCase
this.supportedSecuritySchemes.forEach((scheme: any, index: number, schemes: any[]) => {
const name = camelCase(scheme.name);
const trailing = index < schemes.length - 1 ? ',' : '';
if (scheme.type === 'OAuth 2.0') {
this.buffer.return();
this.buffer.line('// eslint-disable-next-line');
this.buffer.line(` ${name}: function ${name}(options) {`);
this.buffer.multiline(` const schemeSettings = ${this.formatJSON(scheme.settings, 2, 4)};`);
this.buffer.line(` return new ClientOAuth2(Object.assign(schemeSettings, options));`);
this.buffer.line(` }${trailing}`);
}
});
示例3: createClientClass
private createClientClass() {
this.buffer.multiline(`
class Client {
constructor(options) {
this.path = '';
this.options = Object.assign({
baseUri: ${javascriptStringify(this.api.baseUri)},
baseUriParameters: ${this.formatJSON(getDefaultParameters(this.api.baseUriParameters), 2, 6).split('\n').join('\n') },
headers: {}
}, options);
this.customRequest = (method, path, opts) => request(
this, method, path, opts
);\n
this.form = (payload) => {
const data = {
formData: payload,
append(key, value) {
if (typeof value !== 'string') {
this.formData.file = value;
} else {
data.formData[key] = value;
}
}
};
return data;
};\n`);
this.createThisResources(this.withParams, this.noParams, 'this', false);
this.buffer.line(` }\n`);
// Adding the extensibility point
this.buffer.multiline(` setHeaders(headers) {
this.options.headers = headers;`);
this.buffer.line(` }`);
this.buffer.multiline(`
use(name, module) {
const moduleType = typeof module;
if (Object.prototype.hasOwnProperty.call(this, name)) {
throw Error(\`The property \${name} already exists\`);
}
switch (moduleType) {
case 'string':
// eslint-disable-next-line
this[name] = require(module);
break;
case 'function':
this[name] = new module(); // eslint-disable-line new-cap
break;
case 'object':
this[name] = module;
break;
case 'undefined':
if (typeof name === 'string') {
// eslint-disable-next-line
this[name] = require(name);
break;
}
throw Error('Cannot create the extension point with the values provided');
default:
throw Error('Cannot create the extension point with the values provided');
}
}`);
for (const resource of this.flatTree) {
const { relativeUri, uriParameters } = resource;
for (const method of resource.methods) {
if (method.annotations && method.annotations['client.methodName']) {
const methodName = method.annotations['client.methodName'].structuredValue;
const type = isQueryMethod(method) ? 'query' : 'body';
const headers = getDefaultParameters(method.headers);
const headersText = Object.keys(headers).length === 0 ? '' : `, headers: ${javascriptStringify(headers)}`;
if (Object.keys(uriParameters).length) {
this.buffer.return();
this.buffer.line(` ${methodName}(uriParams, ${type}, opts) {`);
this.buffer.line(` const uriParameters = Object.assign(` +
`${javascriptStringify(getDefaultParameters(uriParameters))}, uriParams);`);
this.buffer.line(` const options = Object.assign({ ${type}, ` +
`uriParameters: uriParameters${headersText} }, opts);`);
this.buffer.line(` return request(this, ${javascriptStringify(method.method)}, ` +
`${javascriptStringify(relativeUri)}, options);`);
this.buffer.line(` }`);
} else {
this.buffer.return();
this.buffer.line(` ${methodName}(${type}, opts) {`);
this.buffer.line(` const options = Object.assign({ ${type}${headersText} }, opts);`);
this.buffer.line(` return request(this, ${javascriptStringify(method.method)}, ` +
`${javascriptStringify(relativeUri)}, options);`);
this.buffer.line(` }`);
}
}
}
}
this.createProtoMethods(this.nestedTree.methods, 'this', `''`);
this.createProtoResources(this.withParams, this.noParams);
this.buffer.line(`}`);
}