MCPcopy Create free account
hub / github.com/adonisjs/session / ValuesStore

Class ValuesStore

src/values_store.ts:135–276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133 * const hasData = store.hasBeenModified
134 */
135export class ValuesStore extends ReadOnlyValuesStore {
136 /**
137 * Flag to track if the store has been modified
138 */
139 #modified: boolean = false
140
141 /**
142 * Creates a new values store
143 *
144 * @param values - Initial session data or null
145 */
146 constructor(values: SessionData | null) {
147 super(values)
148 }
149
150 /**
151 * Returns true if the store has been modified
152 */
153 get hasBeenModified(): boolean {
154 return this.#modified
155 }
156
157 /**
158 * Sets a key/value pair in the store
159 *
160 * @param key - The key or key path to set
161 * @param value - The value to set
162 *
163 * @example
164 * store.set('username', 'john')
165 * store.set(['user', 'preferences'], { theme: 'dark' })
166 */
167 set(key: string | string[], value: AllowedSessionValues): void {
168 this.#modified = true
169 lodash.set(this.values, key, value)
170 }
171
172 /**
173 * Removes a key from the store
174 *
175 * @param key - The key or key path to remove
176 *
177 * @example
178 * store.unset('temp_data')
179 * store.unset(['user', 'cache'])
180 */
181 unset(key: string | string[]): void {
182 this.#modified = true
183 lodash.unset(this.values, key)
184 }
185
186 /**
187 * Pulls value from the store. Same as calling store.get then store.unset.
188 *
189 * @param key - The key or key path to pull
190 * @param defaultValue - Default value if key doesn't exist
191 *
192 * @example

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected