set() — astro Function Reference
Architecture documentation for the set() function in runtime.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 59668aee_368a_2af5_a60c_273e7404dc42["set()"] 91969197_292d_3b15_21c6_0e876968e961["AstroSession"] 59668aee_368a_2af5_a60c_273e7404dc42 -->|defined in| 91969197_292d_3b15_21c6_0e876968e961 6c13532b_bbe4_11a3_885d_e9996a51cbf6["VALID_COOKIE_REGEX()"] 6c13532b_bbe4_11a3_885d_e9996a51cbf6 -->|calls| 59668aee_368a_2af5_a60c_273e7404dc42 8249bedb_c4c6_d6ed_cd7e_2f629ae41af9["storage()"] 8249bedb_c4c6_d6ed_cd7e_2f629ae41af9 -->|calls| 59668aee_368a_2af5_a60c_273e7404dc42 6a37e7b5_7d47_0edc_22a0_f1b1f4a991bb["AstroSession()"] 6a37e7b5_7d47_0edc_22a0_f1b1f4a991bb -->|calls| 59668aee_368a_2af5_a60c_273e7404dc42 b8960b45_5233_5b43_3557_e134954c4977["unflatten()"] 59668aee_368a_2af5_a60c_273e7404dc42 -->|calls| b8960b45_5233_5b43_3557_e134954c4977 3459dc7b_97b3_22f8_91b9_dc3a8658682c["stringify()"] 59668aee_368a_2af5_a60c_273e7404dc42 -->|calls| 3459dc7b_97b3_22f8_91b9_dc3a8658682c style 59668aee_368a_2af5_a60c_273e7404dc42 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/core/session/runtime.ts lines 166–210
set<T = void, K extends string = keyof App.SessionData | (string & {})>(
key: K,
value: T extends void
? K extends keyof App.SessionData
? App.SessionData[K]
: any
: NoInfer<T>,
{ ttl }: { ttl?: number } = {},
) {
if (!key) {
throw new AstroError({
...SessionStorageSaveError,
message: 'The session key was not provided.',
});
}
// save a clone of the passed in object so later updates are not
// persisted into the store. Attempting to serialize also allows
// us to throw an error early if needed.
let cloned: T;
try {
cloned = unflatten(JSON.parse(stringify(value)));
} catch (err) {
throw new AstroError(
{
...SessionStorageSaveError,
message: `The session data for ${key} could not be serialized.`,
hint: 'See the devalue library for all supported types: https://github.com/rich-harris/devalue',
},
{ cause: err },
);
}
if (!this.#cookieSet) {
this.#setCookie();
this.#cookieSet = true;
}
this.#data ??= new Map();
const lifetime = ttl ?? this.#config.ttl;
// If ttl is numeric, it is the number of seconds until expiry. To get an expiry timestamp, we convert to milliseconds and add to the current time.
const expires = typeof lifetime === 'number' ? Date.now() + lifetime * 1000 : lifetime;
this.#data.set(key, {
data: cloned,
expires,
});
this.#dirty = true;
}
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does set() do?
set() is a function in the astro codebase, defined in packages/astro/src/core/session/runtime.ts.
Where is set() defined?
set() is defined in packages/astro/src/core/session/runtime.ts at line 166.
What does set() call?
set() calls 2 function(s): stringify, unflatten.
What calls set()?
set() is called by 3 function(s): AstroSession, VALID_COOKIE_REGEX, storage.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free