Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apicase

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apicase - npm Package Compare versions

Comparing version 0.1.10 to 0.1.11

123

container.js

@@ -1,84 +0,67 @@

import pick from 'lodash/pick'
import * as Utils from './utils'
import createService from './service.js'
import get from 'lodash/get'
import set from 'lodash/set'
import omit from 'lodash/omit'
import assign from 'lodash/assign'
import isArray from 'lodash/isArray'
import flip from 'lodash/flip'
import merge from 'lodash/merge'
import forEach from 'lodash/forEach'
import isString from 'lodash/isString'
import mapValues from 'lodash/mapValues'
import mergeWith from 'lodash/mergeWith'
import isFunction from 'lodash/isFunction'
import isPlainObject from 'lodash/isPlainObject'
export const normalizeMixin = function (mixin) {
if (isFunction(mixin)) {
return {
get: mixin,
enumerable: true,
configurable: false
export default function createContainer (config) {
let result = {
base: '',
mixins: {},
headers: {},
services: {},
headers: {},
hooks: {
before: [],
success: [],
error: [],
finished: []
},
addMixin (name, mixin) {
this.mixins[name] = Utils.normalizeMixin(mixin)
},
addHook (name, hook) {
this.hooks[name].push(Utils.normalizeHook(hook))
},
addHooks (list) {
merge(this.hooks, Utils.normalizeHooks(list))
},
addService (name, service) {
this.services[name] = createService(service, result)
set(this.services, name, createService(service, result))
},
async go (name, data, options = {}) {
return await this.services[name].go(data, options)
}
}
if (!isPlainObject(mixin)) {
throw new TypeError(`Mixin must be declared as a function or a plain object`)
}
return assign({
enumerable: true,
configurable: false
}, pick(mixin, ['get', 'set']))
}
export const normalizeHook = function (hook) {
if (isFunction(hook)) {
return {
name: 'Anonymous hook',
handler: hook
}
if (config.services) {
result.services = mapValues(
Utils.flatServices(config.services),
service => createService(service, result)
)
}
if (!isPlainObject(hook)) {
throw new TypeError(`Hook must be declared as a function or a plain object`)
if (config.hooks) {
result.addHooks(config.hooks)
}
return {
name: (isString(hook.name) ? hook.name : 'Anonymous hook') || 'Anonymous hook',
handler: hook.handler
if (config.mixins) {
forEach(config.mixins, (mixin, name) => {
result.addMixin(name, mixin)
})
}
}
if (config.headers) {
result.headers = config.headers
}
if (config.base) {
result.base = config.base
}
export const normalizeHooks = function (hooks) {
return mapValues(
pick(hooks, ['before', 'success', 'error', 'finished']),
(hooks, hookType) =>
isArray(hooks)
? hooks.map(normalizeHook)
: [hooks].map(normalizeHook)
)
}
export const mergeHooksList = function (...lists) {
return mergeWith(
{ before: [], success: [], error: [], finished: [] },
...lists,
(a, b) => a.concat(b)
)
}
export const flatServices = function (services, alias = '') {
let result = {}
forEach(services, (service, name) => {
result[`${alias}${name}`] = omit(service, 'children')
if (service.children) {
assign(result, flatServices(service.children, `${alias}${name}/`))
}
})
return result
}
export const jsonToQueryString = json => {
return !isPlainObject(json) || !Object.keys(json).length
? ''
: '?' +
values(
mapValues(
json,
(value, key) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
)
).join('&')
}
{
"name": "apicase",
"version": "0.1.10",
"version": "0.1.11",
"description": "Create, group and manage your APIs with json declaration",

@@ -5,0 +5,0 @@ "author": "kelin2025",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc