当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript strands.Strands类代码示例

本文整理汇总了TypeScript中strands.Strands的典型用法代码示例。如果您正苦于以下问题:TypeScript Strands类的具体用法?TypeScript Strands怎么用?TypeScript Strands使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Strands类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: toParamsFunction

 private toParamsFunction(child: NestedResource, client: string, isChild: boolean, attach?: string) {
   const className = `${this.currentPath.join('.')}.${uppercamelcase(child.methodName)}`;
   const func2Return = new Strands();
   const path = isChild ? 'this.path + ' : '';
   func2Return.multiline(`(uriParams) => new ${className}(
     ${client},
     ${path}template(${javascriptStringify(child.relativeUri)},
       Object.assign(${javascriptStringify(getDefaultParameters(child.uriParameters))}, uriParams))
   ),${attach}`);
   return func2Return.toString();
 }
开发者ID:mulesoft-labs,项目名称:raml-javascript-generator,代码行数:11,代码来源:index.js.ts

示例2: toParamsMethod

  private toParamsMethod(child: NestedResource, client: string, isChild: boolean) {
    const className = this.currentPath.concat([uppercamelcase(child.methodName)]).join('.');
    const func2Return = new Strands();
    const path = isChild ? 'this.path + ' : '';

    func2Return.multiline(`(uriParams) {
    return new ${className}(
      ${client},
      ${path}template(${javascriptStringify(child.relativeUri)},
        Object.assign(${this.formatJSON(getDefaultParameters(child.uriParameters), 2, 8)}, uriParams))
    );
  }`);
    return func2Return.toString();
  }
开发者ID:mulesoft-labs,项目名称:raml-javascript-generator,代码行数:14,代码来源:index.js.ts

示例3: createThisResources

  private createThisResources(withParams: KeyedNestedResources, noParams: KeyedNestedResources, client: string, isChild = true) {
    for (const key of Object.keys(noParams)) {
      const child = noParams[key];
      let constructor;
      let path: string;
      if (isChild) {
        path = `\`\${this.path}${child.relativeUri}\``;
      } else {
        path = `'${child.relativeUri}'`;
      }
      if (this.currentPath.length === 0) {
        constructor = `new ${uppercamelcase(child.methodName)}(${client}, ${path})`;
      } else {
        constructor = `new ${this.currentPath.join('.')}.` +
          `${uppercamelcase(child.methodName)}(${client}, ${path})`;
      }

      if (withParams[key] == null) {
        this.buffer.line(`    this.${child.methodName} = ${constructor};`);
      } else {
        this.buffer.line();
        this.buffer.append(`    this.${child.methodName} = Object.setPrototypeOf(` +
          `${this.toParamsFunction(withParams[key], client, isChild, ` ${constructor});`)}`);
      }
    }
  }
开发者ID:mulesoft-labs,项目名称:raml-javascript-generator,代码行数:26,代码来源:index.js.ts

示例4: 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();

  }
开发者ID:mulesoft-labs,项目名称:raml-javascript-generator,代码行数:35,代码来源:index.js.ts

示例5: createProtoResources

  // Create prototype resources.
  private createProtoResources(withParams: KeyedNestedResources, noParams: KeyedNestedResources) {
    for (const key of Object.keys(withParams)) {
      const child = withParams[key];

      // Skip inlined entries.
      if (noParams[key] != null) {
        continue;
      }

      this.buffer.append(`\n`);
      this.buffer.append(`  ${child.methodName}${this.toParamsMethod(child, 'this.client', true)}`);
    }
  }
开发者ID:mulesoft-labs,项目名称:raml-javascript-generator,代码行数:14,代码来源:index.js.ts

示例6: getClient

 public getClient() {
   this.generateRequiresAndGlobalFunctions();
   this.createClientClass();
   this.createChildren();
   this.generateStaticMethodsAndExport();
   return this.buffer.toString();
 }
开发者ID:mulesoft-labs,项目名称:raml-javascript-generator,代码行数:7,代码来源:index.js.ts

示例7: generateStaticMethodsAndExport

  private generateStaticMethodsAndExport() {
    this.buffer.line(`Client.version = ${javascriptStringify(this.api.version)};`);
    this.buffer.line('Client.Security = {');

    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}`);
      }
    });
    this.buffer.line('};');
    this.buffer.line(`module.exports = Client;`);
  }
开发者ID:mulesoft-labs,项目名称:raml-javascript-generator,代码行数:20,代码来源:index.js.ts

示例8: 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}`);
      }
    });
开发者ID:mulesoft-labs,项目名称:raml-javascript-generator,代码行数:13,代码来源:index.js.ts

示例9: generateRequiresAndGlobalFunctions

  private generateRequiresAndGlobalFunctions() {
    this.buffer.line(`/* eslint no-use-before-define: 0 */`);

    if (hasSecurity(this.api, 'OAuth 2.0')) {
      this.buffer.line(`const ClientOAuth2 = require('client-oauth2');`);
    }

    this.buffer.multiline(`const rp = require('request-promise');
const queryString = require('query-string');
const debuglog = require('util').debuglog('${this.api.title}');

const TEMPLATE_REGEXP = /\{\\+?([^\{\}]+)\}/g;

const template = (string, interpolate) => string.replace(TEMPLATE_REGEXP, (match, key) => {
  if (interpolate[key] != null) {
    return encodeURIComponent(interpolate[key]);
  }

  return '';
});

const request = (client, method, path, opts) => {
  const headers = opts.headers ? Object.assign(
    {}, client.options.headers, opts.headers
  ) : client.options.headers;
  const options = Object.assign({}, client.options, opts);
  const baseUri = template(options.baseUri, options.baseUriParameters);

  if (typeof options.query === 'string') {
    options.query = queryString.parse(options.query);
  }

  let reqOpts = {
    url: baseUri.replace(/\\/$/, '') + template(path, options.uriParameters),
    json: !Buffer.isBuffer(options.body),
    method,
    headers,
    formData: options.formData,
    body: options.body,
    qs: options.query,
    options: options.options,
    resolveWithFullResponse: true
  };

  if (options.options !== undefined) {
    reqOpts = Object.assign(reqOpts, options.options);
  }

  if (options.user && typeof options.user.sign === 'function') {
    reqOpts = options.user.sign(reqOpts);
  }

  debuglog(\`[REQUEST]: \${JSON.stringify(reqOpts, null, 2)}\`);

  return rp(reqOpts)
    .then((response) => {
      const responseLog = {
        headers: response.headers,
        body: response.body,
        statusCode: response.statusCode
      };
      debuglog(\`[RESPONSE]: \${JSON.stringify(responseLog, null, 2)}\`);

      // adding backward compatibility
      response.status = response.statusCode;
      return response;
    })
    .catch((error) => {
      debuglog(\`[RESPONSE]: \${JSON.stringify(error, null, 2)}\`);

      // rethrow the error so that the returned promise is rejected
      throw error;
    });
};`);
  }
开发者ID:mulesoft-labs,项目名称:raml-javascript-generator,代码行数:75,代码来源:index.js.ts

示例10: 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(`}`);
  }
开发者ID:mulesoft-labs,项目名称:raml-javascript-generator,代码行数:100,代码来源:index.js.ts


注:本文中的strands.Strands类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。