@nanostores/logger 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <code_scheme name="Project" version="173">
3
+ <HTMLCodeStyleSettings>
4
+ <option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
5
+ </HTMLCodeStyleSettings>
6
+ <JSCodeStyleSettings version="0">
7
+ <option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
8
+ <option name="FORCE_SEMICOLON_STYLE" value="true" />
9
+ <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
10
+ <option name="USE_DOUBLE_QUOTES" value="false" />
11
+ <option name="FORCE_QUOTE_STYlE" value="true" />
12
+ <option name="ENFORCE_TRAILING_COMMA" value="Remove" />
13
+ <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
14
+ <option name="SPACES_WITHIN_IMPORTS" value="true" />
15
+ </JSCodeStyleSettings>
16
+ <TypeScriptCodeStyleSettings version="0">
17
+ <option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
18
+ <option name="FORCE_SEMICOLON_STYLE" value="true" />
19
+ <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
20
+ <option name="USE_DOUBLE_QUOTES" value="false" />
21
+ <option name="FORCE_QUOTE_STYlE" value="true" />
22
+ <option name="ENFORCE_TRAILING_COMMA" value="Remove" />
23
+ <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
24
+ <option name="SPACES_WITHIN_IMPORTS" value="true" />
25
+ </TypeScriptCodeStyleSettings>
26
+ <VueCodeStyleSettings>
27
+ <option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
28
+ <option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
29
+ </VueCodeStyleSettings>
30
+ <codeStyleSettings language="HTML">
31
+ <option name="SOFT_MARGINS" value="80" />
32
+ <indentOptions>
33
+ <option name="INDENT_SIZE" value="2" />
34
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
35
+ <option name="TAB_SIZE" value="2" />
36
+ </indentOptions>
37
+ </codeStyleSettings>
38
+ <codeStyleSettings language="JavaScript">
39
+ <option name="IF_BRACE_FORCE" value="1" />
40
+ <option name="DOWHILE_BRACE_FORCE" value="1" />
41
+ <option name="WHILE_BRACE_FORCE" value="1" />
42
+ <option name="FOR_BRACE_FORCE" value="1" />
43
+ <option name="SOFT_MARGINS" value="80" />
44
+ <indentOptions>
45
+ <option name="INDENT_SIZE" value="2" />
46
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
47
+ <option name="TAB_SIZE" value="2" />
48
+ </indentOptions>
49
+ </codeStyleSettings>
50
+ <codeStyleSettings language="TypeScript">
51
+ <option name="IF_BRACE_FORCE" value="1" />
52
+ <option name="DOWHILE_BRACE_FORCE" value="1" />
53
+ <option name="WHILE_BRACE_FORCE" value="1" />
54
+ <option name="FOR_BRACE_FORCE" value="1" />
55
+ <option name="SOFT_MARGINS" value="80" />
56
+ <indentOptions>
57
+ <option name="INDENT_SIZE" value="2" />
58
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
59
+ <option name="TAB_SIZE" value="2" />
60
+ </indentOptions>
61
+ </codeStyleSettings>
62
+ <codeStyleSettings language="Vue">
63
+ <option name="SOFT_MARGINS" value="80" />
64
+ <indentOptions>
65
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
66
+ </indentOptions>
67
+ </codeStyleSettings>
68
+ </code_scheme>
69
+ </component>
@@ -0,0 +1,5 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="USE_PER_PROJECT_SETTINGS" value="true" />
4
+ </state>
5
+ </component>
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
5
+ </profile>
6
+ </component>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/logger.iml" filepath="$PROJECT_DIR$/.idea/logger.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
@@ -1,11 +1,6 @@
1
1
  import type { AnyStore, Store, StoreValue } from 'nanostores'
2
2
 
3
3
  interface LoggerOptionsMessages {
4
- /**
5
- * Disable action logs.
6
- */
7
- action?: boolean
8
-
9
4
  /**
10
5
  * Disable change logs.
11
6
  */
@@ -23,11 +18,6 @@ interface LoggerOptionsMessages {
23
18
  }
24
19
 
25
20
  export interface LoggerOptions {
26
- /**
27
- * Disable logs of actions with a specific name.
28
- */
29
- ignoreActions?: string[]
30
-
31
21
  /**
32
22
  * Disable specific types of logs.
33
23
  */
@@ -39,19 +29,12 @@ interface EventPayloadBase {
39
29
  }
40
30
 
41
31
  interface EventChangePayload extends EventPayloadBase {
42
- actionId?: number
43
- actionName?: string
44
32
  changed?: keyof StoreValue<Store>
45
33
  newValue: any
46
34
  oldValue?: any
47
35
  valueMessage?: string
48
36
  }
49
37
 
50
- interface EventActionPayload extends EventPayloadBase {
51
- actionId: number
52
- actionName: string
53
- }
54
-
55
38
  interface EventActionStartPayload extends EventActionPayload {
56
39
  args: any[]
57
40
  }
@@ -61,11 +44,6 @@ interface EventActionErrorPayload extends EventActionPayload {
61
44
  }
62
45
 
63
46
  interface BuildLoggerEvents {
64
- action?: {
65
- end?: (payload: EventActionPayload) => void
66
- error?: (payload: EventActionErrorPayload) => void
67
- start?: (payload: EventActionStartPayload) => void
68
- }
69
47
  change?: (payload: EventChangePayload) => void
70
48
  mount?: (payload: EventPayloadBase) => void
71
49
  unmount?: (payload: EventPayloadBase) => void
@@ -94,22 +72,6 @@ interface BuildLoggerEvents {
94
72
  * message += `to ${newValue}`
95
73
  * if (actionName) message += `by action ${actionName}`
96
74
  * console.log(message, valueMessage)
97
- * },
98
- *
99
- * action: {
100
- * start: ({ actionName, args }) => {
101
- * let message = `${actionName} was started`
102
- * if (args.length) message += 'with arguments'
103
- * console.log(message, args)
104
- * },
105
- *
106
- * error: ({ actionName, error }) => {
107
- * console.log(`${actionName} was failed`, error)
108
- * },
109
- *
110
- * end: ({ actionName }) => {
111
- * console.log(`${actionName} was ended`)
112
- * }
113
75
  * }
114
76
  * ```
115
77
  *
@@ -1,11 +1,4 @@
1
- import {
2
- actionId,
3
- lastAction,
4
- onAction,
5
- onMount,
6
- onNotify,
7
- onSet
8
- } from 'nanostores'
1
+ import { onMount, onNotify, onSet } from 'nanostores'
9
2
 
10
3
  const isAtom = store => store.setKey === undefined
11
4
  const isDeepMapKey = key => /.+(\..+|\[\d+\.*])/.test(key)
@@ -23,30 +16,8 @@ function handleMount(store, storeName, messages, events) {
23
16
  })
24
17
  }
25
18
 
26
- function handleAction(store, storeName, ignoreActions, events) {
27
- return onAction(store, ({ actionName, args, id, onEnd, onError }) => {
28
- if (ignoreActions && ignoreActions.includes(actionName)) return
29
-
30
- events.action.start({ actionId: id, actionName, args, storeName })
31
-
32
- onError(({ error }) => {
33
- events.action.error({ actionId: id, actionName, error, storeName })
34
- })
35
-
36
- onEnd(() => {
37
- events.action.end({ actionId: id, actionName, storeName })
38
- })
39
- })
40
- }
41
-
42
- function handleSet(store, storeName, messages, ignoreActions, events) {
19
+ function handleSet(store, storeName, events) {
43
20
  return onSet(store, ({ changed }) => {
44
- let currentActionId = store[actionId]
45
- let currentActionName = store[lastAction]
46
-
47
- if (messages.action === false && currentActionId) return
48
- if (ignoreActions && ignoreActions.includes(currentActionName)) return
49
-
50
21
  let oldValue = isAtom(store) ? store.value : { ...store.value }
51
22
  oldValue = isDeepMapKey(changed) ? structuredClone(oldValue) : oldValue
52
23
  let unbindNotify = onNotify(store, () => {
@@ -57,8 +28,6 @@ function handleSet(store, storeName, messages, ignoreActions, events) {
57
28
  }
58
29
 
59
30
  events.change({
60
- actionId: currentActionId,
61
- actionName: currentActionName,
62
31
  changed,
63
32
  newValue,
64
33
  oldValue,
@@ -72,7 +41,6 @@ function handleSet(store, storeName, messages, ignoreActions, events) {
72
41
  }
73
42
 
74
43
  export function buildLogger(store, storeName, events, opts = {}) {
75
- let ignoreActions = opts.ignoreActions
76
44
  let messages = opts.messages || {}
77
45
  let unbind = []
78
46
 
@@ -80,12 +48,8 @@ export function buildLogger(store, storeName, events, opts = {}) {
80
48
  unbind.push(handleMount(store, storeName, messages, events))
81
49
  }
82
50
 
83
- if (messages.action !== false) {
84
- unbind.push(handleAction(store, storeName, ignoreActions, events))
85
- }
86
-
87
51
  if (messages.change !== false) {
88
- unbind.push(handleSet(store, storeName, messages, ignoreActions, events))
52
+ unbind.push(handleSet(store, storeName, events))
89
53
  }
90
54
 
91
55
  return () => {
package/logger/index.js CHANGED
@@ -2,66 +2,13 @@ import { buildLogger } from '../build-logger/index.js'
2
2
  import { group, groupEnd, log } from '../printer/index.js'
3
3
 
4
4
  function createLogger(store, storeName, opts) {
5
- let queue = {}
6
-
7
5
  return buildLogger(
8
6
  store,
9
7
  storeName,
10
8
  {
11
- action: {
12
- end: ({ actionId }) => {
13
- for (let i of queue[actionId]) i()
14
- delete queue[actionId]
15
- groupEnd()
16
- },
17
-
18
- error: ({ actionId, actionName, error }) => {
19
- queue[actionId].push(() =>
20
- log({
21
- message: [
22
- ['bold', storeName],
23
- ['regular', 'store handled error in action'],
24
- ['bold', actionName]
25
- ],
26
- type: 'error',
27
- value: {
28
- message: error.message
29
- }
30
- })
31
- )
32
- },
33
-
34
- start: ({ actionId, actionName, args }) => {
35
- queue[actionId] = []
36
-
37
- let message = [
38
- ['bold', storeName],
39
- ['regular', 'store was changed by action'],
40
- ['bold', actionName]
41
- ]
42
-
43
- queue[actionId].push(() =>
44
- group({
45
- logo: true,
46
- message,
47
- type: 'action'
48
- })
49
- )
50
- if (args.length > 0) {
51
- message.push(['regular', 'with arguments'])
52
- queue[actionId].push(() =>
53
- log({
54
- type: 'arguments',
55
- value: args
56
- })
57
- )
58
- }
59
- }
60
- },
61
-
62
- change: ({ actionId, changed, newValue, oldValue, valueMessage }) => {
9
+ change: ({ changed, newValue, oldValue, valueMessage }) => {
63
10
  let groupLog = {
64
- logo: typeof actionId === 'undefined',
11
+ logo: true,
65
12
  message: [
66
13
  ['bold', storeName],
67
14
  ['regular', 'store was changed']
@@ -75,33 +22,24 @@ function createLogger(store, storeName, opts) {
75
22
  ['regular', 'key']
76
23
  )
77
24
  }
78
-
79
- let run = () => {
80
- group(groupLog)
81
- if (valueMessage) {
82
- log({
83
- message: valueMessage,
84
- type: 'value'
85
- })
86
- }
25
+ group(groupLog)
26
+ if (valueMessage) {
87
27
  log({
88
- type: 'new',
89
- value: newValue
28
+ message: valueMessage,
29
+ type: 'value'
90
30
  })
91
- if (oldValue) {
92
- log({
93
- type: 'old',
94
- value: oldValue
95
- })
96
- }
97
- groupEnd()
98
31
  }
99
-
100
- if (actionId) {
101
- queue[actionId].push(run)
102
- } else {
103
- run()
32
+ log({
33
+ type: 'new',
34
+ value: newValue
35
+ })
36
+ if (oldValue) {
37
+ log({
38
+ type: 'old',
39
+ value: oldValue
40
+ })
104
41
  }
42
+ groupEnd()
105
43
  },
106
44
 
107
45
  mount: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nanostores/logger",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "description": "Pretty logger of lifecycles, changes and actions for Nano Stores",
5
5
  "keywords": [
6
6
  "nanostores",
@@ -24,12 +24,6 @@
24
24
  "node": "^18.0.0 || >=20.0.0"
25
25
  },
26
26
  "peerDependencies": {
27
- "nanostores": ">=0.9.2"
28
- },
29
- "nano-staged": {
30
- "*.{js,ts}": [
31
- "prettier --write",
32
- "eslint --fix"
33
- ]
27
+ "nanostores": ">=0.10.2"
34
28
  }
35
29
  }