How to use deps method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

index.ts

Source:index.ts Github

copy

Full Screen

1import { EventEmitter } from 'events'2import { Server } from 'http'3import createLogger from 'pino'4import { knex } from 'knex'5import { Model } from 'objection'6import { Ioc, IocContract } from '@adonisjs/fold'7import Redis from 'ioredis'8import { createClient } from 'tigerbeetle-node'9import { App, AppServices } from './app'10import { Config } from './config/app'11import { createRatesService } from './rates/service'12import { createQuoteRoutes } from './open_payments/quote/routes'13import { createQuoteService } from './open_payments/quote/service'14import { createOutgoingPaymentRoutes } from './open_payments/payment/outgoing/routes'15import { createOutgoingPaymentService } from './open_payments/payment/outgoing/service'16import {17 createIlpPlugin,18 IlpPlugin,19 IlpPluginOptions20} from './shared/ilp_plugin'21import { createHttpTokenService } from './httpToken/service'22import { createAssetService } from './asset/service'23import { createAccountingService } from './accounting/service'24import { createPeerService } from './peer/service'25import { createAuthService } from './open_payments/auth/service'26import { createPaymentPointerService } from './open_payments/payment_pointer/service'27import { createSPSPRoutes } from './spsp/routes'28import { createClientKeysRoutes } from './clientKeys/routes'29import { createPaymentPointerRoutes } from './open_payments/payment_pointer/routes'30import { createIncomingPaymentRoutes } from './open_payments/payment/incoming/routes'31import { createIncomingPaymentService } from './open_payments/payment/incoming/service'32import { StreamServer } from '@interledger/stream-receiver'33import { createWebhookService } from './webhook/service'34import { createConnectorService } from './connector'35import { createSessionService } from './session/service'36import { createApiKeyService } from './apiKey/service'37import { createOpenAPI } from 'openapi'38import { createConnectionService } from './open_payments/connection/service'39import { createConnectionRoutes } from './open_payments/connection/routes'40import { createClientKeysService } from './clientKeys/service'41import { createClientService } from './clients/service'42BigInt.prototype.toJSON = function () {43 return this.toString()44}45const container = initIocContainer(Config)46const app = new App(container)47let connectorServer: Server48export function initIocContainer(49 config: typeof Config50): IocContract<AppServices> {51 const container: IocContract<AppServices> = new Ioc()52 container.singleton('config', async () => config)53 container.singleton('logger', async (deps: IocContract<AppServices>) => {54 const config = await deps.use('config')55 const logger = createLogger()56 logger.level = config.logLevel57 return logger58 })59 container.singleton('knex', async (deps: IocContract<AppServices>) => {60 const logger = await deps.use('logger')61 const config = await deps.use('config')62 logger.info({ msg: 'creating knex' })63 const db = knex({64 client: 'postgresql',65 connection: config.databaseUrl,66 pool: {67 min: 2,68 max: 1069 },70 migrations: {71 directory: './',72 tableName: 'knex_migrations'73 }74 })75 // node pg defaults to returning bigint as string. This ensures it parses to bigint76 db.client.driver.types.setTypeParser(77 db.client.driver.types.builtins.INT8,78 'text',79 BigInt80 )81 return db82 })83 container.singleton('closeEmitter', async () => new EventEmitter())84 container.singleton('redis', async (deps): Promise<Redis> => {85 const config = await deps.use('config')86 return new Redis(config.redisUrl, { tls: config.redisTls })87 })88 container.singleton('streamServer', async (deps) => {89 const config = await deps.use('config')90 return new StreamServer({91 serverSecret: config.streamSecret,92 serverAddress: config.ilpAddress93 })94 })95 container.singleton('tigerbeetle', async (deps) => {96 const config = await deps.use('config')97 return createClient({98 cluster_id: config.tigerbeetleClusterId,99 replica_addresses: config.tigerbeetleReplicaAddresses100 })101 })102 container.singleton('openApi', async (deps) => {103 const config = await deps.use('config')104 return await createOpenAPI(config.openPaymentsSpec)105 })106 container.singleton('authOpenApi', async (deps) => {107 const config = await deps.use('config')108 return await createOpenAPI(config.authServerSpec)109 })110 /**111 * Add services to the container.112 */113 container.singleton('httpTokenService', async (deps) => {114 const logger = await deps.use('logger')115 const knex = await deps.use('knex')116 return await createHttpTokenService({117 logger: logger,118 knex: knex119 })120 })121 container.singleton('assetService', async (deps) => {122 const logger = await deps.use('logger')123 const knex = await deps.use('knex')124 return await createAssetService({125 logger: logger,126 knex: knex,127 accountingService: await deps.use('accountingService')128 })129 })130 container.singleton('accountingService', async (deps) => {131 const logger = await deps.use('logger')132 const knex = await deps.use('knex')133 const tigerbeetle = await deps.use('tigerbeetle')134 return await createAccountingService({135 logger: logger,136 knex: knex,137 tigerbeetle,138 withdrawalThrottleDelay: config.withdrawalThrottleDelay139 })140 })141 container.singleton('peerService', async (deps) => {142 return await createPeerService({143 knex: await deps.use('knex'),144 logger: await deps.use('logger'),145 accountingService: await deps.use('accountingService'),146 assetService: await deps.use('assetService'),147 httpTokenService: await deps.use('httpTokenService')148 })149 })150 container.singleton('authService', async (deps) => {151 const config = await deps.use('config')152 return await createAuthService({153 logger: await deps.use('logger'),154 authServerIntrospectionUrl: config.authServerIntrospectionUrl,155 authOpenApi: await deps.use('authOpenApi')156 })157 })158 container.singleton('paymentPointerService', async (deps) => {159 const logger = await deps.use('logger')160 const assetService = await deps.use('assetService')161 return await createPaymentPointerService({162 knex: await deps.use('knex'),163 logger: logger,164 accountingService: await deps.use('accountingService'),165 assetService: assetService166 })167 })168 container.singleton('spspRoutes', async (deps) => {169 const logger = await deps.use('logger')170 const streamServer = await deps.use('streamServer')171 return await createSPSPRoutes({172 logger: logger,173 streamServer: streamServer174 })175 })176 container.singleton('webhookService', async (deps) => {177 return createWebhookService({178 config: await deps.use('config'),179 knex: await deps.use('knex'),180 logger: await deps.use('logger')181 })182 })183 container.singleton('incomingPaymentService', async (deps) => {184 return await createIncomingPaymentService({185 logger: await deps.use('logger'),186 knex: await deps.use('knex'),187 accountingService: await deps.use('accountingService'),188 paymentPointerService: await deps.use('paymentPointerService')189 })190 })191 container.singleton('incomingPaymentRoutes', async (deps) => {192 return createIncomingPaymentRoutes({193 config: await deps.use('config'),194 logger: await deps.use('logger'),195 incomingPaymentService: await deps.use('incomingPaymentService'),196 connectionService: await deps.use('connectionService')197 })198 })199 container.singleton('paymentPointerRoutes', async (deps) => {200 return createPaymentPointerRoutes({201 config: await deps.use('config')202 })203 })204 container.singleton('clientKeysRoutes', async (deps) => {205 return createClientKeysRoutes({206 clientKeysService: await deps.use('clientKeysService'),207 clientService: await deps.use('clientService')208 })209 })210 container.singleton('connectionService', async (deps) => {211 return await createConnectionService({212 logger: await deps.use('logger'),213 streamServer: await deps.use('streamServer')214 })215 })216 container.singleton('connectionRoutes', async (deps) => {217 return createConnectionRoutes({218 config: await deps.use('config'),219 logger: await deps.use('logger'),220 incomingPaymentService: await deps.use('incomingPaymentService'),221 connectionService: await deps.use('connectionService')222 })223 })224 container.singleton('ratesService', async (deps) => {225 const config = await deps.use('config')226 return createRatesService({227 logger: await deps.use('logger'),228 pricesUrl: config.pricesUrl,229 pricesLifetime: config.pricesLifetime230 })231 })232 container.singleton('clientKeysService', async (deps) => {233 return createClientKeysService({234 logger: await deps.use('logger'),235 knex: await deps.use('knex')236 })237 })238 container.singleton('clientService', async (deps) => {239 return createClientService({240 logger: await deps.use('logger'),241 knex: await deps.use('knex')242 })243 })244 container.singleton('makeIlpPlugin', async (deps) => {245 const connectorApp = await deps.use('connectorApp')246 return ({247 sourceAccount,248 unfulfillable = false249 }: IlpPluginOptions): IlpPlugin => {250 return createIlpPlugin((data: Buffer): Promise<Buffer> => {251 return connectorApp.handleIlpData(sourceAccount, unfulfillable, data)252 })253 }254 })255 container.singleton('quoteService', async (deps) => {256 const config = await deps.use('config')257 return await createQuoteService({258 slippage: config.slippage,259 quoteLifespan: config.quoteLifespan,260 quoteUrl: config.quoteUrl,261 signatureSecret: config.signatureSecret,262 signatureVersion: config.signatureVersion,263 logger: await deps.use('logger'),264 knex: await deps.use('knex'),265 makeIlpPlugin: await deps.use('makeIlpPlugin'),266 paymentPointerService: await deps.use('paymentPointerService'),267 ratesService: await deps.use('ratesService')268 })269 })270 container.singleton('quoteRoutes', async (deps) => {271 return createQuoteRoutes({272 config: await deps.use('config'),273 logger: await deps.use('logger'),274 quoteService: await deps.use('quoteService')275 })276 })277 container.singleton('outgoingPaymentService', async (deps) => {278 const config = await deps.use('config')279 return await createOutgoingPaymentService({280 logger: await deps.use('logger'),281 knex: await deps.use('knex'),282 accountingService: await deps.use('accountingService'),283 makeIlpPlugin: await deps.use('makeIlpPlugin'),284 peerService: await deps.use('peerService'),285 publicHost: config.publicHost286 })287 })288 container.singleton('outgoingPaymentRoutes', async (deps) => {289 return createOutgoingPaymentRoutes({290 config: await deps.use('config'),291 logger: await deps.use('logger'),292 outgoingPaymentService: await deps.use('outgoingPaymentService')293 })294 })295 container.singleton('sessionService', async (deps) => {296 const logger = await deps.use('logger')297 const redis = await deps.use('redis')298 return await createSessionService({299 logger: logger,300 redis: redis,301 sessionLength: config.sessionLength302 })303 })304 container.singleton('apiKeyService', async (deps) => {305 const logger = await deps.use('logger')306 const knex = await deps.use('knex')307 const sessionService = await deps.use('sessionService')308 return await createApiKeyService({309 logger: logger,310 knex: knex,311 sessionService: sessionService312 })313 })314 container.singleton('connectorApp', async (deps) => {315 const config = await deps.use('config')316 return await createConnectorService({317 logger: await deps.use('logger'),318 redis: await deps.use('redis'),319 accountingService: await deps.use('accountingService'),320 paymentPointerService: await deps.use('paymentPointerService'),321 incomingPaymentService: await deps.use('incomingPaymentService'),322 peerService: await deps.use('peerService'),323 ratesService: await deps.use('ratesService'),324 streamServer: await deps.use('streamServer'),325 ilpAddress: config.ilpAddress326 })327 })328 return container329}330export const gracefulShutdown = async (331 container: IocContract<AppServices>,332 app: App333): Promise<void> => {334 const logger = await container.use('logger')335 logger.info('shutting down.')336 await app.shutdown()337 if (connectorServer) {338 await new Promise((resolve, reject) => {339 connectorServer.close((err?: Error) =>340 err ? reject(err) : resolve(null)341 )342 })343 }344 const knex = await container.use('knex')345 await knex.destroy()346 const tigerbeetle = await container.use('tigerbeetle')347 await tigerbeetle.destroy()348 const redis = await container.use('redis')349 await redis.disconnect()350}351export const start = async (352 container: IocContract<AppServices>,353 app: App354): Promise<void> => {355 let shuttingDown = false356 const logger = await container.use('logger')357 process.on('SIGINT', async (): Promise<void> => {358 logger.info('received SIGINT attempting graceful shutdown')359 try {360 if (shuttingDown) {361 logger.warn(362 'received second SIGINT during graceful shutdown, exiting forcefully.'363 )364 process.exit(1)365 }366 shuttingDown = true367 // Graceful shutdown368 await gracefulShutdown(container, app)369 logger.info('completed graceful shutdown.')370 process.exit(0)371 } catch (err) {372 const errInfo =373 err && typeof err === 'object' && err.stack ? err.stack : err374 logger.error({ error: errInfo }, 'error while shutting down')375 process.exit(1)376 }377 })378 process.on('SIGTERM', async (): Promise<void> => {379 logger.info('received SIGTERM attempting graceful shutdown')380 try {381 // Graceful shutdown382 await gracefulShutdown(container, app)383 logger.info('completed graceful shutdown.')384 process.exit(0)385 } catch (err) {386 const errInfo =387 err && typeof err === 'object' && err.stack ? err.stack : err388 logger.error({ error: errInfo }, 'error while shutting down')389 process.exit(1)390 }391 })392 // Do migrations393 const knex = await container.use('knex')394 // Needs a wrapped inline function395 await callWithRetry(async () => {396 await knex.migrate.latest({397 directory: __dirname + '/../migrations'398 })399 })400 Model.knex(knex)401 const config = await container.use('config')402 await app.boot()403 await app.startAdminServer(config.adminPort)404 await app.startOpenPaymentsServer(config.openPaymentsPort)405 logger.info(`Admin listening on ${app.getAdminPort()}`)406 logger.info(`Open Payments listening on ${app.getOpenPaymentsPort()}`)407 const connectorApp = await container.use('connectorApp')408 connectorServer = connectorApp.listenPublic(config.connectorPort)409 logger.info(`Connector listening on ${config.connectorPort}`)410 logger.info('🐒 has 🚀. Get ready for 🍌🍌🍌🍌🍌')411}412// If this script is run directly, start the server413if (!module.parent) {414 start(container, app).catch(async (e): Promise<void> => {415 const errInfo = e && typeof e === 'object' && e.stack ? e.stack : e416 const logger = await container.use('logger')417 logger.error(errInfo)418 })419}420// Used for running migrations in a try loop with exponential backoff421const callWithRetry = async (fn, depth = 0) => {422 const wait = (ms) => new Promise((res) => setTimeout(res, ms))423 try {424 return await fn()425 } catch (e) {426 if (depth > 7) {427 throw e428 }429 await wait(2 ** depth * 30)430 return callWithRetry(fn, depth + 1)431 }...

Full Screen

Full Screen

38.js

Source:38.js Github

copy

Full Screen

1'use strict';2var esprima = require('esprima');3var estraverse = require('estraverse');4var escope = require('escope');5var _ = require('lodash');6var config = require('./config');7var UserError = require('./error/UserError');8////////9module.exports = parse;10////////11function parse(source) {12 var ast;13 try {14 ast = esprima.parse(source);15 } catch (err) {16 throw new UserError('Source file is not valid.', err);17 }18 var scopeManager = escope.analyze(ast);19 // global scope20 var currentScope = scopeManager.acquire(ast);21 var calls = [];22 estraverse.traverse(ast, {23 enter: function (node) {24 // find all call expressions, because all angular unit types are25 // defined as function calls: .controller(), .service(), etc26 if (node.type === 'CallExpression') {27 var calleeProp = _.get(node, 'callee.property', {});28 if (_.contains(config.units.process, calleeProp.name)) {29 // save matching node with an appropriate scope30 calls.push({31 node: node,32 scope: currentScope33 });34 }35 }36 // update current scope while traversing37 // taken from original repository: https://github.com/estools/escope38 if (/Function/.test(node.type)) {39 currentScope = scopeManager.acquire(node);40 }41 },42 leave: function (node) {43 if (/Function/.test(node.type)) {44 currentScope = currentScope.upper;45 }46 }47 });48 var units = [];49 _.forEach(calls, function (call) {50 // for now use only completely parsed units51 var name = findName(return extractVariableDeps(depsArg.name, scope);, call.scope);52 if (_.isUndefined(name)) {53 return;54 }55 var type = findType(call.node, call.scope);56 if (_.isUndefined(type)) {57 return;58 }59 var module = findModule(call.node, call.scope);60 if (_.isUndefined(module.name)) {61 return;62 }63 var deps = findDeps(call.node, call.scope, type);64 // Angular should not allow having circular dependency, but if65 // there is any in a source code, do not continue execution66 if (_.findWhere(deps, { name: name })) {67 throw new UserError('Circular dependency for ' + type + ' "' + name + '".');68 }69 var unit = {70 name: name,71 type: type,72 module: module,73 deps: deps74 };75 units.unshift(unit);76 });77 return units;78}79////////80function findName(callExpression) {81 var name;82 var nameArg = _.get(callExpression, 'arguments[0]', {});83 if (nameArg.type === 'Literal') {84 name = nameArg.value;85 }86 return name;87}88function findType(callExpression) {89 return _.get(callExpression, 'callee.property.name');90}91// TODO: multiple variable definitions92function findModule(callExpression, scope) {93 var module = {};94 var calleeObj = _.get(callExpression, 'callee.object', {}), calleeProp = _.get(callExpression, 'callee.property', {});95 if (calleeObj.type === 'CallExpression') {96 // recursive find module, usually when units are chained97 return findModule(calleeObj, scope);98 } else if (calleeObj.type === 'Identifier') {99 // when reaching module variable it can be in a form of "angular.module(..)"100 if (calleeProp.name === 'module' && calleeObj.name === 'angular') {101 module.name = _.get(callExpression, 'arguments[0].value'); // or module can be stored in variable; find this variable then102 } else if (_.contains(config.units.process, calleeProp.name)) {103 var varName = calleeObj.name;104 var varNode = findVariable(varName, scope);105 if (varNode) {106 module.name = _.get(varNode, 'init.arguments[0].value');107 }108 }109 }110 return module;111}112// TODO: multiple variable definitions113function findDeps(callExpression, scope, type) {114 var cantHaveDeps = [115 'filter',116 'value',117 'constant'118 ];119 if (_.contains(cantHaveDeps, type)) {120 return [];121 }122 // first argument is a name of the unit, second - usually has deps123 var depsArg = _.get(callExpression, 'arguments[1]', {});124 var deps = [];125 // component differs in a way that an object is used to describe it126 // when other unit types use functions for instantiation127 if (type === 'component') {128 return findComponentDeps(depsArg, scope);129 }130 // deps can be provided explicitly as an array131 // in this case a body of the unit is the last array element132 if (depsArg.type === 'ArrayExpression') {133 var lastDepsArg = _.last(depsArg.elements) || {};134 if (lastDepsArg.type === 'FunctionExpression') {135 return extractDeps(lastDepsArg.params);136 }137 }138 // deps in a form of function expression can be stored in variable139 if (depsArg.type === 'Identifier') {140 return extractVariableDeps(depsArg.name, scope);141 }142 // deps in a form of function expression143 if (depsArg.type === 'FunctionExpression') {144 // everything except provider usually stores deps as function arguments145 if (type !== 'provider') {146 return extractDeps(depsArg.params);147 }148 // provider has a lot more complex structure because of $get construct149 // it may vary a lot, covering common cases150 return findProviderDeps(depsArg);151 }152 return deps;153}154function findComponentDeps(object, scope) {155 // covers { controller: someVar }156 if (object.type === 'Identifier') {157 object = _.get(findVariable(object.name, scope), 'init', {});158 }159 // if not object - not sure what to do with it160 if (object.type !== 'ObjectExpression') {161 return [];162 }163 return extractObjectPropertyDeps(object, 'controller', scope);164}165function findProviderDeps(depsFn) {166 // function must have it's body167 var depsFnBody = _.get(depsFn, 'body', {});168 if (depsFnBody.type !== 'BlockStatement') {169 return [];170 }171 // find a scope of provider body172 var depsFnScope = findScope(depsFn);173 var deps = [];174 // iterate over all body expressions in provider175 var depsFnBodyExpressions = _.get(depsFnBody, 'body');176 _.some(depsFnBodyExpressions, function (bodyExpression) {177 var type = _.get(bodyExpression, 'type');178 var expression = _.get(bodyExpression, 'expression', {});179 var leftProp = _.get(expression, 'left.property', {});180 var right = _.get(expression, 'right', {});181 // covers "this.$get = ..."182 if (type === 'ExpressionStatement' && leftProp.name === '$get') {183 // covers "this.$get = function (...) { ... };"184 if (right.type === 'FunctionExpression') {185 deps = extractDeps(right.params);186 return true; // exit loop187 }188 // covert "this.$get = someVar;"189 if (right.type === 'Identifier') {190 deps = extractVariableDeps(right.name, depsFnScope);191 return true; // exit loop192 }193 }194 var argument = _.get(bodyExpression, 'argument', {});195 // covers "return ...;"196 if (type === 'ReturnStatement') {197 // covers "return { $get: function () {} };"198 // covers "return { $get: someVar };"199 if (argument.type === 'ObjectExpression') {200 deps = extractObjectPropertyDeps(argument, '$get', depsFnScope);201 return true;202 }203 // covers "return someVar;"204 if (argument.type === 'Identifier') {205 var varNode = findVariable(argument.name, depsFnScope);206 if (varNode && _.get(varNode, 'init.type') === 'ObjectExpression') {207 deps = extractObjectPropertyDeps(varNode.init, '$get', depsFnScope);208 return true;209 }210 }211 }212 });213 return deps;214}215function extractDeps(params) {216 if (!_.isArray(params)) {217 return [];218 }219 var deps = [];220 _.forEach(params, function (param) {221 if (param.type === 'Identifier') {222 var dep = { name: param.name };223 deps.push(dep);224 }225 });226 return deps;227}228function findVariable(varName, scope) {229 var variable;230 var currentScope = scope;231 while (!variable && currentScope) {232 variable = _.findWhere(currentScope.variables, { name: varName });233 currentScope = currentScope.upper;234 }235 if (_.isUndefined(variable)) {236 return variable;237 }238 var node = _.get(variable, 'defs[0].node');239 return node;240}241function extractVariableDeps(varName, scope) {242 var varNode = findVariable(varName, scope);243 if (!varNode) {244 return [];245 }246 var params = [];247 var varType = _.get(varNode, 'type');248 // covers "function someVar() {}"249 if (varType === 'FunctionDeclaration') {250 params = _.get(varNode, 'params', []);251 }252 // covers "var someVar = ...";253 if (varType === 'VariableDeclarator') {254 params = _.get(varNode, 'init.params', []);255 }256 var deps = extractDeps(params);257 return deps;258}259function extractObjectPropertyDeps(object, propName, scope) {260 var prop = _.find(object.properties, function (property) {261 return _.get(property, 'key.name') === propName;262 });263 if (!prop) {264 return [];265 }266 var value = _.get(prop, 'value', {});267 var deps = [];268 // covers "{ key: function () {} }"269 if (value.type === 'FunctionExpression') {270 deps = extractDeps(value.params);271 }272 // covers "{ key: someVar }"273 if (value.type === 'Identifier') {274 deps = extractVariableDeps(value.name, scope);275 }276 return deps;277}278function findScope(ast) {279 var scopeManager = escope.analyze(ast);280 var scope = scopeManager.acquire(ast);281 return scope;...

Full Screen

Full Screen

41.js

Source:41.js Github

copy

Full Screen

1'use strict';2var esprima = require('esprima');3var estraverse = require('estraverse');4var escope = require('escope');5var _ = require('lodash');6var config = require('./config');7var UserError = require('./error/UserError');8////////9module.exports = parse;10////////11function parse(source) {12 var ast;13 try {14 ast = esprima.parse(source);15 } catch (err) {16 throw new UserError('Source file is not valid.', err);17 }18 var scopeManager = escope.analyze(ast);19 // global scope20 var currentScope = scopeManager.acquire(ast);21 var calls = [];22 estraverse.traverse(ast);23 var units = [];24 _.forEach(calls, function (call) {25 // for now use only completely parsed units26 var name = findName(call.node, call.scope);27 if (_.isUndefined(name)) {28 return;29 }30 var type = findType(call.node, call.scope);31 if (_.isUndefined(type)) {32 return;33 }34 var module = findModule(call.node, call.scope);35 if (_.isUndefined(module.name)) {36 return;37 }38 var deps = findDeps(call.node, call.scope, type);39 // Angular should not allow having circular dependency, but if40 // there is any in a source code, do not continue execution41 if (_.findWhere(deps, { name: name })) {42 throw new UserError('Circular dependency for ' + type + ' "' + name + '".');43 }44 var unit = {45 name: name,46 type: type,47 module: module,48 deps: deps49 };50 units.unshift(unit);51 });52 return units;53}54////////55function findName(callExpression) {56 var name;57 var nameArg = _.get(callExpression, 'arguments[0]', {});58 if (nameArg.type === 'Literal') {59 name = nameArg.value;60 }61 return name;62}63function findType(callExpression) {64 return _.get(callExpression, 'callee.property.name');65}66// TODO: multiple variable definitions67function findModule(callExpression, scope) {68 var module = {};69 var calleeObj = _.get(callExpression, 'callee.object', {}), calleeProp = _.get(callExpression, 'callee.property', {});70 if (calleeObj.type === 'CallExpression') {71 // recursive find module, usually when units are chained72 return findModule(calleeObj, scope);73 } else if (calleeObj.type === 'Identifier') {74 // when reaching module variable it can be in a form of "angular.module(..)"75 if (calleeProp.name === 'module' && calleeObj.name === 'angular') {76 module.name = _.get(callExpression, 'arguments[0].value'); // or module can be stored in variable; find this variable then77 } else if (_.contains(config.units.process, calleeProp.name)) {78 var varName = calleeObj.name;79 var varNode = findVariable(varName, scope);80 if (varNode) {81 module.name = _.get(varNode, 'init.arguments[0].value');82 }83 }84 }85 return module;86}87// TODO: multiple variable definitions88function findDeps(callExpression, scope, type) {89 var cantHaveDeps = [90 'filter',91 'value',92 'constant'93 ];94 if (_.contains(cantHaveDeps, type)) {95 return [];96 }97 // first argument is a name of the unit, second - usually has deps98 var depsArg = _.get(callExpression, 'arguments[1]', {});99 var deps = [];100 // component differs in a way that an object is used to describe it101 // when other unit types use functions for instantiation102 if (type === 'component') {103 return findComponentDeps(depsArg, scope);104 }105 // deps can be provided explicitly as an array106 // in this case a body of the unit is the last array element107 if (depsArg.type === 'ArrayExpression') {108 var lastDepsArg = _.last(depsArg.elements) || {};109 if (lastDepsArg.type === 'FunctionExpression') {110 return extractDeps(lastDepsArg.params);111 }112 }113 // deps in a form of function expression can be stored in variable114 if (depsArg.type === 'Identifier') {115 return extractVariableDeps(depsArg.name, scope);116 }117 // deps in a form of function expression118 if (depsArg.type === 'FunctionExpression') {119 // everything except provider usually stores deps as function arguments120 if (type !== 'provider') {121 return extractDeps(depsArg.params);122 }123 // provider has a lot more complex structure because of $get construct124 // it may vary a lot, covering common cases125 return findProviderDeps(depsArg);126 }127 return deps;128}129function findComponentDeps(object, scope) {130 // covers { controller: someVar }131 if (object.type === 'Identifier') {132 object = _.get(findVariable(object.name, scope), 'init', {});133 }134 // if not object - not sure what to do with it135 if (object.type !== 'ObjectExpression') {136 return [];137 }138 return extractObjectPropertyDeps(object, 'controller', scope);139}140function findProviderDeps(depsFn) {141 // function must have it's body142 var depsFnBody = _.get(depsFn, 'body', {});143 if (depsFnBody.type !== 'BlockStatement') {144 return;145 }146 // find a scope of provider body147 var depsFnScope = findScope(depsFn);148 var deps = [];149 // iterate over all body expressions in provider150 var depsFnBodyExpressions = _.get(depsFnBody, 'body');151 _.some(depsFnBodyExpressions, function (bodyExpression) {152 var type = _.get(bodyExpression, 'type');153 var expression = _.get(bodyExpression, 'expression', {});154 var leftProp = _.get(expression, 'left.property', {});155 var right = _.get(expression, 'right', {});156 // covers "this.$get = ..."157 if (type === 'ExpressionStatement' && leftProp.name === '$get') {158 // covers "this.$get = function (...) { ... };"159 if (right.type === 'FunctionExpression') {160 deps = extractDeps(right.params);161 return true; // exit loop162 }163 // covert "this.$get = someVar;"164 if (right.type === 'Identifier') {165 deps = extractVariableDeps(right.name, depsFnScope);166 return true; // exit loop167 }168 }169 var argument = _.get(bodyExpression, 'argument', {});170 // covers "return ...;"171 if (type === 'ReturnStatement') {172 // covers "return { $get: function () {} };"173 // covers "return { $get: someVar };"174 if (argument.type === 'ObjectExpression') {175 deps = extractObjectPropertyDeps(argument, '$get', depsFnScope);176 return true;177 }178 // covers "return someVar;"179 if (argument.type === 'Identifier') {180 var varNode = findVariable(argument.name, depsFnScope);181 if (varNode && _.get(varNode, 'init.type') === 'ObjectExpression') {182 deps = extractObjectPropertyDeps(varNode.init, '$get', depsFnScope);183 return true;184 }185 }186 }187 });188 return deps;189}190function extractDeps(params) {191 if (!_.isArray(params)) {192 return [];193 }194 var deps = [];195 _.forEach(params, function (param) {196 if (param.type === 'Identifier') {197 var dep = { name: param.name };198 deps.push(dep);199 }200 });201 return deps;202}203function findVariable(varName, scope) {204 var variable;205 var currentScope = scope;206 while (!variable && currentScope) {207 variable = _.findWhere(currentScope.variables, { name: varName });208 currentScope = currentScope.upper;209 }210 if (_.isUndefined(variable)) {211 return variable;212 }213 var node = _.get(variable, 'defs[0].node');214 return node;215}216function extractVariableDeps(varName, scope) {217 var varNode = findVariable(varName, scope);218 if (!varNode) {219 return [];220 }221 var params = [];222 var varType = _.get(varNode, 'type');223 // covers "function someVar() {}"224 if (varType === 'FunctionDeclaration') {225 params = _.get(varNode, 'params', []);226 }227 // covers "var someVar = ...";228 if (varType === 'VariableDeclarator') {229 params = _.get(varNode, 'init.params', []);230 }231 var deps = extractDeps(params);232 return deps;233}234function extractObjectPropertyDeps(object, propName, scope) {235 var prop = _.find(object.properties, function (property) {236 return _.get(property, 'key.name') === propName;237 });238 if (!prop) {239 return [];240 }241 var value = _.get(prop, 'value', {});242 var deps = [];243 // covers "{ key: function () {} }"244 if (value.type === 'FunctionExpression') {245 deps = extractDeps(value.params);246 }247 // covers "{ key: someVar }"248 if (value.type === 'Identifier') {249 deps = extractVariableDeps(value.name, scope);250 }251 return deps;252}253function findScope(ast) {254 var scopeManager = escope.analyze(ast);255 var scope = scopeManager.acquire(ast);256 return scope;...

Full Screen

Full Screen

20.js

Source:20.js Github

copy

Full Screen

1'use strict';2var esprima = require('esprima');3var estraverse = require('estraverse');4var escope = require('escope');5var _ = require('lodash');6var config = require('./config');7var UserError = require('./error/UserError');8////////9module.exports = parse;10////////11function parse(source) {12 var ast;13 try {14 ast = esprima.parse(source);15 } catch (err) {16 throw new UserError('Source file is not valid.', err);17 }18 var scopeManager = escope.analyze(ast);19 // global scope20 var currentScope = scopeManager.acquire(ast);21 var calls = [];22 estraverse.traverse(ast, {23 enter: function (node) {24 // find all call expressions, because all angular unit types are25 // defined as function calls: .controller(), .service(), etc26 if (node.type === 'CallExpression') {27 var calleeProp = _.get(node, 'callee.property', {});28 if (_.contains(config.units.process)) {29 // save matching node with an appropriate scope30 calls.push({31 node: node,32 scope: currentScope33 });34 }35 }36 // update current scope while traversing37 // taken from original repository: https://github.com/estools/escope38 if (/Function/.test(node.type)) {39 currentScope = scopeManager.acquire(node);40 }41 },42 leave: function (node) {43 if (/Function/.test(node.type)) {44 currentScope = currentScope.upper;45 }46 }47 });48 var units = [];49 _.forEach(calls, function (call) {50 // for now use only completely parsed units51 var name = findName(call.node, call.scope);52 if (_.isUndefined(name)) {53 return;54 }55 var type = findType(call.node, call.scope);56 if (_.isUndefined(type)) {57 return;58 }59 var module = findModule(call.node, call.scope);60 if (_.isUndefined(module.name)) {61 return;62 }63 var deps = findDeps(call.node, call.scope, type);64 // Angular should not allow having circular dependency, but if65 // there is any in a source code, do not continue execution66 if (_.findWhere(deps, { name: name })) {67 throw new UserError('Circular dependency for ' + type + ' "' + name + '".');68 }69 var unit = {70 name: name,71 type: type,72 module: module,73 deps: deps74 };75 });76 return units;77}78////////79function findName(callExpression) {80 var name;81 var nameArg = _.get(callExpression, 'arguments[0]', {});82 if (nameArg.type === 'Literal') {83 name = nameArg.value;84 }85 return name;86}87// TODO: multiple variable definitions88function findDeps(callExpression, scope, type) {89 var cantHaveDeps = [90 'filter',91 'value',92 'constant'93 ];94 if (_.contains(cantHaveDeps, type)) {95 return [];96 }97 // first argument is a name of the unit, second - usually has deps98 var depsArg = _.get(callExpression, 'arguments[1]', {});99 var deps = [];100 // component differs in a way that an object is used to describe it101 // when other unit types use functions for instantiation102 if (type === 'component') {103 return findComponentDeps(depsArg, scope);104 }105 // deps can be provided explicitly as an array106 // in this case a body of the unit is the last array element107 if (depsArg.type === 'ArrayExpression') {108 var lastDepsArg = _.last(depsArg.elements) || {};109 if (lastDepsArg.type === 'FunctionExpression') {110 return extractDeps(lastDepsArg.params);111 }112 }113 // deps in a form of function expression can be stored in variable114 if (depsArg.type === 'Identifier') {115 return extractVariableDeps(depsArg.name, scope);116 }117 // deps in a form of function expression118 if (depsArg.type === 'FunctionExpression') {119 // everything except provider usually stores deps as function arguments120 if (type !== 'provider') {121 return extractDeps(depsArg.params);122 }123 // provider has a lot more complex structure because of $get construct124 // it may vary a lot, covering common cases125 return findProviderDeps(depsArg);126 }127 return deps;128}129function findComponentDeps(object, scope) {130 // covers { controller: someVar }131 if (object.type === 'Identifier') {132 object = _.get(findVariable(object.name, scope), 'init', {});133 }134 // if not object - not sure what to do with it135 if (object.type !== 'ObjectExpression') {136 return [];137 }138 return extractObjectPropertyDeps(object, 'controller', scope);139}140function findProviderDeps(depsFn) {141 // function must have it's body142 var depsFnBody = _.get(depsFn, 'body', {});143 if (depsFnBody.type !== 'BlockStatement') {144 return [];145 }146 // find a scope of provider body147 var depsFnScope = findScope(depsFn);148 var deps = [];149 // iterate over all body expressions in provider150 var depsFnBodyExpressions = _.get(depsFnBody, 'body');151 _.some(depsFnBodyExpressions, function (bodyExpression) {152 var type = _.get(bodyExpression, 'type');153 var expression = _.get(bodyExpression, 'expression', {});154 var leftProp = _.get(expression, 'left.property', {});155 var right = _.get(expression, 'right', {});156 // covers "this.$get = ..."157 if (type === 'ExpressionStatement' && leftProp.name === '$get') {158 // covers "this.$get = function (...) { ... };"159 if (right.type === 'FunctionExpression') {160 deps = extractDeps(right.params);161 return true; // exit loop162 }163 }164 var argument = _.get(bodyExpression, 'argument', {});165 // covers "return ...;"166 if (type === 'ReturnStatement') {167 // covers "return { $get: function () {} };"168 // covers "return { $get: someVar };"169 if (argument.type === 'ObjectExpression') {170 deps = extractObjectPropertyDeps(argument, '$get');171 return true;172 }173 // covers "return someVar;"174 if (argument.type === 'Identifier') {175 var varNode = findVariable(argument.name, depsFnScope);176 if (varNode && _.get(varNode, 'init.type') === 'ObjectExpression') {177 deps = extractObjectPropertyDeps(varNode.init, '$get', depsFnScope);178 return true;179 }180 }181 }182 });183 return deps;184}185function extractDeps(params) {186 if (!_.isArray(params)) {187 return [];188 }189 var deps = [];190 _.forEach(params, function (param) {191 if (param.type === 'Identifier') {192 var dep = { name: param.name };193 deps.push(dep);194 }195 });196 return deps;197}198function findVariable(varName, scope) {199 var variable;200 var currentScope = scope;201 while (!variable && currentScope) {202 variable = _.findWhere(currentScope.variables, { name: varName });203 currentScope = currentScope.upper;204 }205 if (_.isUndefined(variable)) {206 return variable;207 }208 var node = _.get(variable, 'defs[0].node');209 return node;210}211function extractVariableDeps(varName, scope) {212 var varNode = findVariable(varName, scope);213 if (!varNode) {214 return [];215 }216 var params = [];217 var varType = _.get(varNode, 'type');218 // covers "function someVar() {}"219 if (varType === 'FunctionDeclaration') {220 params = _.get(varNode, 'params', []);221 }222 // covers "var someVar = ...";223 if (varType === 'VariableDeclarator') {224 params = _.get(varNode, 'init.params', []);225 }226 var deps = extractDeps(params);227 return deps;228}229function extractObjectPropertyDeps(object, propName, scope) {230 var prop = _.find(object.properties, function (property) {231 return _.get(property, 'key.name') === propName;232 });233 if (!prop) {234 return [];235 }236 var value = _.get(prop, 'value', {});237 var deps = [];238 // covers "{ key: function () {} }"239 if (value.type === 'FunctionExpression') {240 deps = extractDeps(value.params);241 }242 // covers "{ key: someVar }"243 if (value.type === 'Identifier') {244 deps = extractVariableDeps(value.name, scope);245 }246 return deps;247}248function findScope(ast) {249 var scopeManager = escope.analyze(ast);250 var scope = scopeManager.acquire(ast);251 return scope;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { deps } = require('fast-check-monorepo');2const { deps } = require('fast-check');3const { deps } = require('fast-check-monorepo');4const { deps } = require('fast-check');5const { deps } = require('fast-check-monorepo');6const { deps } = require('fast-check');7const { deps } = require('fast-check-monorepo');8const { deps } = require('fast-check');9const { deps } = require('fast-check-monorepo');10const { deps } = require('fast-check');11const { deps } = require('fast-check-monorepo');12const { deps } = require('fast-check');13const { deps } = require('fast-check-monorepo');14const { deps } = require('fast-check');15const { deps } = require('fast-check-monorepo');16const { deps } = require('fast-check');17const { deps } = require('fast-check-monorepo');18const { deps } = require('fast-check');19const { deps } = require('fast-check-monorepo');20const { deps } = require('fast-check');21const { deps } = require('fast-check-monorepo');22const { deps } = require('fast-check');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { deps } from 'fast-check-monorepo';2console.log(deps());3import { deps } from 'fast-check-monorepo';4console.log(deps());5import { deps } from 'fast-check-monorepo';6console.log(deps());7import { deps } from 'fast-check-monorepo';8console.log(deps());9import { deps } from 'fast-check-monorepo';10console.log(deps());11import { deps } from 'fast-check-monorepo';12console.log(deps());13import { deps } from 'fast-check-monorepo';14console.log(deps());15import { deps } from 'fast-check-monorepo';16console.log(deps());17import { deps } from 'fast-check-monorepo';18console.log(deps());19import { deps } from 'fast-check-monorepo';20console.log(deps());21import { deps } from 'fast-check-monorepo';22console.log(deps());23import { deps } from 'fast-check-monorepo';24console.log(deps());25import { deps } from 'fast-check-monorepo';26console.log(deps());27import { deps } from 'fast-check-monorepo';28console.log(deps());

Full Screen

Using AI Code Generation

copy

Full Screen

1const { deps } = require('fast-check-monorepo');2const { deps } = require('fast-check-monorepo');3const { deps } = require('fast-check-monorepo');4const { deps } = require('fast-check-monorepo');5const { deps } = require('fast-check-monorepo');6const { deps } = require('fast-check-monorepo');7const { deps } = require('fast-check-monorepo');8const { deps } = require('fast-check-monorepo');9const { deps } = require('fast-check-monorepo');10const { deps } = require('fast-check-monorepo');11const { deps } = require('fast-check-monorepo');12const { deps

Full Screen

Using AI Code Generation

copy

Full Screen

1const { deps } = require('fast-check-monorepo');2const { fc } = deps;3const arb = fc.integer(1, 100);4const arb2 = fc.integer(1, 100);5fc.assert(6 fc.property(arb, arb2, (a, b) => a + b >= a),7 { numRuns: 1000 }8);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { deps } = fc;3const { deps } = require('fast-check');4const { deps } = require('fast-check');5const { deps } = require('fast-check');6const { deps } = require('fast-check');7const { deps } = require('fast-check');8const { deps } = require('fast-check');9const { deps } = require('fast-check');10const { deps } = require('fast-check');11const { deps } = require('fast-check');12const { deps } = require('fast-check');13const { deps } = require('fast-check');14const { deps } = require('fast-check');15const { deps } = require('fast-check');16const { deps } = require('fast-check');17const { deps } = require('fast-check');18const { deps } = require('fast-check');19const { deps } = require('fast-check');20const { deps } = require('fast-check');21const { deps } = require('fast-check');22const { deps } = require('fast-check');23const { deps } = require('fast-check');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { fc } = require('fast-check')2const { deps } = require('fast-check-monorepo')3const { a, b, c } = deps('a', 'b', 'c')4fc.assert(5 fc.property(fc.integer(), fc.integer(), fc.integer(), (a, b, c) => {6 })

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const {deps} = require("fast-check-monorepo");3const {foo} = deps;4fc.assert(5 fc.property(6 fc.integer(),7 fc.integer(),8 (a, b) => {9 return foo(a, b) === a + b;10 }11);12const fc = require("fast-check");13const {deps} = require("fast-check-monorepo");14const {foo} = deps;15fc.assert(16 fc.property(17 fc.integer(),18 fc.integer(),19 (a, b) => {20 return foo(a, b) === a + b;21 }22);23const fc = require("fast-check");24const {deps} = require("fast-check-monorepo");25const {foo} = deps;26fc.assert(27 fc.property(28 fc.integer(),29 fc.integer(),30 (a, b) => {31 return foo(a, b) === a + b;32 }33);34const fc = require("fast-check");35const {deps} = require("fast-check-monorepo");36const {foo} = deps;37fc.assert(38 fc.property(39 fc.integer(),40 fc.integer(),41 (a, b) => {42 return foo(a, b) === a + b;43 }44);45const fc = require("fast-check");46const {deps} = require("fast-check-monorepo");47const {foo} = deps;48fc.assert(49 fc.property(50 fc.integer(),51 fc.integer(),52 (a, b) => {53 return foo(a, b) === a + b;54 }55);56const fc = require("fast-check");57const {deps} = require("fast-check-monorepo");58const {foo} = deps;59fc.assert(60 fc.property(61 fc.integer(),62 fc.integer(),63 (a, b) => {64 return foo(a, b)

Full Screen

Using AI Code Generation

copy

Full Screen

1interface Property<Ts> {2 (...vs: Ts): boolean | void | Promise<boolean | void>;3}4interface Arbitrary<T> {5 generate(mrng: Random): T;6 shrink(value: T): Stream<T>;7}8interface Random {9 nextInt(min: number, max: number): number;10 nextDouble(): number;11 nextBoolean(): boolean;12 nextArray<T>(generator: () => T): T[];13 nextString(): string;14}15interface Stream<T> {16 generate(mrng: Random): T;17 shrink(value: T): Stream<T>;18}19interface Property<Ts> {20 (...vs: Ts): boolean | void | Promise<boolean | void>;21}22interface Arbitrary<T> {23 generate(mrng: Random): T;24 shrink(value: T): Stream<T>;25}26interface Random {27 nextInt(min: number, max: number): number;28 nextDouble(): number;29 nextBoolean(): boolean;30 nextArray<T>(generator: () => T): T[];31 nextString(): string;32}33interface Stream<T> {34 generate(mrng: Random): T;35 shrink(value: T): Stream<T>;36}37interface Property<Ts> {38 (...vs:

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful