Socket
Socket
Sign inDemoInstall

@nanostores/logger

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nanostores/logger - npm Package Compare versions

Comparing version 0.2.4 to 0.3.0

.idea/codeStyles/codeStyleConfig.xml

38

build-logger/index.d.ts

@@ -5,7 +5,2 @@ import type { AnyStore, Store, StoreValue } from 'nanostores'

/**
* Disable action logs.
*/
action?: boolean
/**
* Disable change logs.

@@ -28,7 +23,2 @@ */

/**
* Disable logs of actions with a specific name.
*/
ignoreActions?: string[]
/**
* Disable specific types of logs.

@@ -44,4 +34,2 @@ */

interface EventChangePayload extends EventPayloadBase {
actionId?: number
actionName?: string
changed?: keyof StoreValue<Store>

@@ -53,7 +41,2 @@ newValue: any

interface EventActionPayload extends EventPayloadBase {
actionId: number
actionName: string
}
interface EventActionStartPayload extends EventActionPayload {

@@ -68,7 +51,2 @@ args: any[]

interface BuildLoggerEvents {
action?: {
end?: (payload: EventActionPayload) => void
error?: (payload: EventActionErrorPayload) => void
start?: (payload: EventActionStartPayload) => void
}
change?: (payload: EventChangePayload) => void

@@ -102,18 +80,2 @@ mount?: (payload: EventPayloadBase) => void

* console.log(message, valueMessage)
* },
*
* action: {
* start: ({ actionName, args }) => {
* let message = `${actionName} was started`
* if (args.length) message += 'with arguments'
* console.log(message, args)
* },
*
* error: ({ actionName, error }) => {
* console.log(`${actionName} was failed`, error)
* },
*
* end: ({ actionName }) => {
* console.log(`${actionName} was ended`)
* }
* }

@@ -120,0 +82,0 @@ * ```

42

build-logger/index.js

@@ -1,9 +0,2 @@

import {
actionId,
lastAction,
onAction,
onMount,
onNotify,
onSet
} from 'nanostores'
import { onMount, onNotify, onSet } from 'nanostores'

@@ -26,26 +19,4 @@ const isAtom = store => store.setKey === undefined

function handleAction(store, storeName, ignoreActions, events) {
return onAction(store, ({ actionName, args, id, onEnd, onError }) => {
if (ignoreActions && ignoreActions.includes(actionName)) return
events.action.start({ actionId: id, actionName, args, storeName })
onError(({ error }) => {
events.action.error({ actionId: id, actionName, error, storeName })
})
onEnd(() => {
events.action.end({ actionId: id, actionName, storeName })
})
})
}
function handleSet(store, storeName, messages, ignoreActions, events) {
function handleSet(store, storeName, events) {
return onSet(store, ({ changed }) => {
let currentActionId = store[actionId]
let currentActionName = store[lastAction]
if (messages.action === false && currentActionId) return
if (ignoreActions && ignoreActions.includes(currentActionName)) return
let oldValue = isAtom(store) ? store.value : { ...store.value }

@@ -61,4 +32,2 @@ oldValue = isDeepMapKey(changed) ? structuredClone(oldValue) : oldValue

events.change({
actionId: currentActionId,
actionName: currentActionName,
changed,

@@ -77,3 +46,2 @@ newValue,

export function buildLogger(store, storeName, events, opts = {}) {
let ignoreActions = opts.ignoreActions
let messages = opts.messages || {}

@@ -86,8 +54,4 @@ let unbind = []

if (messages.action !== false) {
unbind.push(handleAction(store, storeName, ignoreActions, events))
}
if (messages.change !== false) {
unbind.push(handleSet(store, storeName, messages, ignoreActions, events))
unbind.push(handleSet(store, storeName, events))
}

@@ -94,0 +58,0 @@

@@ -5,4 +5,2 @@ import { buildLogger } from '../build-logger/index.js'

function createLogger(store, storeName, opts) {
let queue = {}
return buildLogger(

@@ -12,56 +10,5 @@ store,

{
action: {
end: ({ actionId }) => {
for (let i of queue[actionId]) i()
delete queue[actionId]
groupEnd()
},
error: ({ actionId, actionName, error }) => {
queue[actionId].push(() =>
log({
message: [
['bold', storeName],
['regular', 'store handled error in action'],
['bold', actionName]
],
type: 'error',
value: {
message: error.message
}
})
)
},
start: ({ actionId, actionName, args }) => {
queue[actionId] = []
let message = [
['bold', storeName],
['regular', 'store was changed by action'],
['bold', actionName]
]
queue[actionId].push(() =>
group({
logo: true,
message,
type: 'action'
})
)
if (args.length > 0) {
message.push(['regular', 'with arguments'])
queue[actionId].push(() =>
log({
type: 'arguments',
value: args
})
)
}
}
},
change: ({ actionId, changed, newValue, oldValue, valueMessage }) => {
change: ({ changed, newValue, oldValue, valueMessage }) => {
let groupLog = {
logo: typeof actionId === 'undefined',
logo: true,
message: [

@@ -80,29 +27,20 @@ ['bold', storeName],

}
let run = () => {
group(groupLog)
if (valueMessage) {
log({
message: valueMessage,
type: 'value'
})
}
group(groupLog)
if (valueMessage) {
log({
type: 'new',
value: newValue
message: valueMessage,
type: 'value'
})
if (oldValue) {
log({
type: 'old',
value: oldValue
})
}
groupEnd()
}
if (actionId) {
queue[actionId].push(run)
} else {
run()
log({
type: 'new',
value: newValue
})
if (oldValue) {
log({
type: 'old',
value: oldValue
})
}
groupEnd()
},

@@ -109,0 +47,0 @@

{
"name": "@nanostores/logger",
"version": "0.2.4",
"version": "0.3.0",
"description": "Pretty logger of lifecycles, changes and actions for Nano Stores",

@@ -27,10 +27,4 @@ "keywords": [

"peerDependencies": {
"nanostores": ">=0.9.2"
},
"nano-staged": {
"*.{js,ts}": [
"prettier --write",
"eslint --fix"
]
"nanostores": ">=0.10.2"
}
}
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