/** * Construct an instance of SpeechClient. * * @param {object} [options] - The configuration object. See the subsequent * parameters for more details. * @param {object} [options.credentials] - Credentials object. * @param {string} [options.credentials.client_email] * @param {string} [options.credentials.private_key] * @param {string} [options.email] - Account email address. Required when * using a .pem or .p12 keyFilename. * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or * .p12 key downloaded from the Google Developers Console. If you provide * a path to a JSON file, the projectId option below is not necessary. * NOTE: .pem and .p12 require you to specify options.email as well. * @param {number} [options.port] - The port on which to connect to * the remote host. * @param {string} [options.projectId] - The project ID from the Google * Developer's Console, e.g. 'grape-spaceship-123'. We will also check * the environment variable GCLOUD_PROJECT for your project ID. If your * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. * @param {function} [options.promise] - Custom promise module to use instead * of native Promises. * @param {string} [options.servicePath] - The domain name of the * API remote host. */ constructor(opts) { this._descriptors = {}; // Ensure that options include the service address and port. opts = Object.assign( { clientConfig: {}, port: this.constructor.port, servicePath: this.constructor.servicePath, }, opts ); // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = this.constructor.scopes; var gaxGrpc = gax.grpc(opts); // Save the auth object to the client, for use by other methods. this.auth = gaxGrpc.auth; // Determine the client header string. var clientHeader = [ `gl-node/${process.version.node}`, `grpc/${gaxGrpc.grpcVersion}`, `gax/${gax.version}`, `gapic/${VERSION}`, ]; if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); } // Load the applicable protos. var protos = merge( {}, gaxGrpc.loadProto( path.join(__dirname, '..', '..', 'protos'), 'google/cloud/speech/v1p1beta1/cloud_speech.proto' ) ); // Some of the methods on this service provide streaming responses. // Provide descriptors for these. this._descriptors.stream = { streamingRecognize: new gax.StreamDescriptor( gax.StreamType.BIDI_STREAMING ), }; var protoFilesRoot = new gax.grpc.GoogleProtoFilesRoot(); protoFilesRoot = protobuf.loadSync( path.join( __dirname, '..', '..', 'protos', 'google/cloud/speech/v1p1beta1/cloud_speech.proto' ), protoFilesRoot ); // This API contains "long-running operations", which return a // an Operation object that allows for tracking of the operation, // rather than holding a request open. this.operationsClient = new gax.lro({ auth: gaxGrpc.auth, grpc: gaxGrpc.grpc, }).operationsClient(opts); var longRunningRecognizeResponse = protoFilesRoot.lookup( 'google.cloud.speech.v1p1beta1.LongRunningRecognizeResponse' ); var longRunningRecognizeMetadata = protoFilesRoot.lookup( 'google.cloud.speech.v1p1beta1.LongRunningRecognizeMetadata' ); this._descriptors.longrunning = { longRunningRecognize: new gax.LongrunningDescriptor( this.operationsClient, longRunningRecognizeResponse.decode.bind(longRunningRecognizeResponse), longRunningRecognizeMetadata.decode.bind(longRunningRecognizeMetadata) ), }; // Put together the default options sent with requests. var defaults = gaxGrpc.constructSettings( 'google.cloud.speech.v1p1beta1.Speech', gapicConfig, opts.clientConfig, {'x-goog-api-client': clientHeader.join(' ')} ); // Set up a dictionary of "inner API calls"; the core implementation // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; // Put together the "service stub" for // google.cloud.speech.v1p1beta1.Speech. var speechStub = gaxGrpc.createStub( protos.google.cloud.speech.v1p1beta1.Speech, opts ); // Iterate over each of the methods that the service provides // and create an API call method for each. var speechStubMethods = [ 'recognize', 'longRunningRecognize', 'streamingRecognize', ]; for (let methodName of speechStubMethods) { this._innerApiCalls[methodName] = gax.createApiCall( speechStub.then( stub => function() { var args = Array.prototype.slice.call(arguments, 0); return stub[methodName].apply(stub, args); } ), defaults[methodName], this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] ); } }
const webpack = require('webpack') const merge = require('lodash.merge') const commonConfig = require('./webpack-common') const karmaConfig = require('./karma.conf') const eslintDev = require('./eslint-dev.json') const eslintCommon = require('./eslint-common.json') const eslintConfig = merge(eslintCommon, eslintDev) const includes = [/\/jsx\//, /\/es6\//] module.exports = function(entries, output) { const devConfig = merge(commonConfig(entries, output, includes), karmaConfig, { environment: 'dev', module: { preLoaders: [{ test: /\.jsx?$/, loader: "eslint", query: eslintConfig, include: includes }] }, devServer: { contentBase: output, historyApiFallback: true, hot: true, inline: true, progress: true, stats: 'errors-only', host: process.env.HOST || "localhost", port: process.env.PORT || 8011
const clientConfig = merge({}, config, { entry: { main: ['./src/Index.js'] }, output: { path: path.join(__dirname, '../build'), filename: DEBUG ? '[name].js?[hash]' : '[name].[hash].js', }, // Choose a developer tool to enhance debugging // http://webpack.github.io/docs/configuration.html#devtool devtool: DEBUG ? 'cheap-module-eval-source-map' : false, plugins: [ new ExtractTextPlugin(DEBUG ? '[name].css?[contenthash]' : '[name].[contenthash].css'), new HtmlWebpackPlugin({ title: 'IT服务助手', template: 'entries/index.html', inject: 'body', filename: 'index.html', jsapi: '//www.fxiaoke.com/open/jsapi/1.0.0/jsapi.min.js', files: { adaptiveScrtipt: [(DEBUG ? '' : PUBLICPATH) + 'adaptor.js'], }, chunks: ['main'], }), new webpack.DefinePlugin(GLOBALS), new AppCachePlugin({ output: 'manifest.appcache' }), ...(!DEBUG ? [ new webpack.optimize.DedupePlugin(), new webpack.optimize.UglifyJsPlugin({ minimize: true, compress: { screw_ie8: true, warnings: VERBOSE }, output: { comments: false } }), new webpack.optimize.AggressiveMergingPlugin(), ] : [ new AssetsPlugin({ path: path.join(__dirname, '../build/public'), filename: 'assets.js', processOutput: x => `module.exports = ${JSON.stringify(x)};`, }), ]), ], });
import merge from 'lodash.merge'; import rootResolvers from './root'; export default merge(rootResolvers);
availableFilters: [], // 可用的 filters 列表 isSearchOptionsOpen: false, // 可用來控制搜尋表單的開關 searchOptions: {} // 搜尋選項,物件內容須依需要自行 override } }, computed: { currentPath() { return window.location.pathname }, currentOptions() { return merge({ pageNumber: this.currentPage, pageSize: this.pageSize, sort: this.sortOrderValue, filter: this.availableFilters[this.currentFilter], search: this.searchOptions }, this.additionalOptions) }, // 可自行定義額外的 options additionalOptions() { // return { // example: this.exampleValue // } return {} }, /** * 計算出 `sort` 這個 key 的值。根據 JSONAPI 的規範,API 需要提供自訂排序的功能,在
]).then(function (_result) { //console.log(_result); return _.merge.apply(_, _result); });
.catch(BrowsertimeError, (e) => { log.error('%s generated the following error in Browsertime %s', url, e); queue.postMessage(make('error', e.message, merge({url}, e.extra))); });
'use strict'; /** * Webpack frontend test configuration. */ var path = require('path'); var merge = require('lodash.merge'); var prodCfg = require('./webpack.config'); // Replace with `__dirname` if using in project root. var ROOT = process.cwd(); module.exports = { cache: true, context: path.join(ROOT, 'test/client'), entry: './main', output: { filename: 'main.js', publicPath: '/assets/' }, resolve: merge({}, prodCfg.resolve, { alias: { // Allow root import of `src/FOO` from ROOT/src. src: path.join(ROOT, 'src') } }), module: prodCfg.module, devtool: 'source-map' };
function post(args, cb) { if (arguments.length === 1) return get({}, arguments[0]) request(merge({ method: 'POST'}, options.request, args), cb) }
module.exports = function(_options, postProcessors) { var options = merge({}, { mandatory: true, watch: false, request: { json: true, timeout: 10000, gzip: true, forever: false, headers: {} } }, _options) var exists = false var allowedResponseCodes = [200].concat(options.mandatory ? [] : 404) var checksum var emitter = new EventEmitter() return function(confabulous, cb) { debug('running') setImmediate(function() { async.waterfall([validate, authenticate, watch, load], function(err, result) { if (err) return cb(err) async.seq.apply(async, postProcessors)(result, cb) }) }) return emitter function validate(cb) { debug('validate: %s', JSON.stringify(options)) if (options.mandatory && !options.url) return cb(new Error('url is required')) if (options.mandatory && !options.path) return cb(new Error('path is required')) if (options.mandatory && !options.method) return cb(new Error('method is required')) if (options.method === 'app-id' && !options.appId) return cb(new Error('appId is required')) if (options.method === 'app-id' && !options.userId) return cb(new Error('userId is required')) if (options.watch && !options.watch.interval) return cb(new Error('watch interval is required')) cb(!options.url || !options.path || !options.method) } function authenticate(cb) { debug('authenticate: method=%s url=%s', options.method, options.url) switch (options.method) { case 'app-id': { var loginUrl = options.url + '/v1/auth/app-id/login' post({ url: loginUrl, body: { app_id: options.appId, user_id: options.userId }}, function(err, res, body) { if (err) return cb(err) if (res.statusCode !== 200) return cb(new Error(format('%s returned %d', options.url, res.statusCode))) options.request.headers['X-Vault-Token'] = body.auth.client_token cb() }) break; } default: { cb(new Error(format('Unsupported authentication method: %s', options.method))) } } } function watch(cb) { var configUrl = options.url + '/v1/' + options.path debug('watch: %s, interval:%s', configUrl, options.watch.interval) if (!options.watch) return cb() var watcher = setInterval(function() { debug('checking for changes to: %s', options.url) get({ url : configUrl }, function(err, res) { if (!watcher) return if (err) return emitter.emit('error', err) if (!contains(allowedResponseCodes, res.statusCode)) return emitter.emit('error', new Error(format('%s returned %d', configUrl, res.statusCode))) if (res.statusCode === 404 && exists || res.statusCode === 200 && (!exists || isModified(res))) emitter.emit('change') }) }, duration(options.watch.interval)) watcher.unref() confabulous.on('reloading', function() { clearInterval(watcher) watcher = null }) return cb() } function load(cb) { var configUrl = options.url + '/v1/' + options.path debug('load: %s', configUrl) exists = false get({ url: configUrl }, function(err, res, body) { if (err) return cb(err) if (!contains(allowedResponseCodes, res.statusCode)) return cb(new Error(format('%s returned %d', configUrl, res.statusCode))) if (res.statusCode === 404) return cb(true) exists = true checksum = generateChecksum(res.body.data) cb(err, body.data) }) } function get(args, cb) { if (arguments.length === 1) return get({}, arguments[0]) request(merge({ method: 'GET'}, options.request, args), cb) } function post(args, cb) { if (arguments.length === 1) return get({}, arguments[0]) request(merge({ method: 'POST'}, options.request, args), cb) } function isModified(res) { var newChecksum = generateChecksum(res.body.data) var modified = checksum !== newChecksum checksum = newChecksum return modified } function generateChecksum(data) { return crypto.createHash('md5').update(JSON.stringify(data)).digest("hex") } } }