UNPKG

waffle

Version:

シンプルなWEBアプリケーションフレームワークです。(ALL YOUR NODE ARE BELONG TO US)

113 lines (104 loc) 3.39 kB
/* * Copyright 2012 Katsunori Koyanagi * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ /** * @overview セッションの永続化のインターフェイスを提供します。 */ "use strict"; /** * セッションの永続化のインターフェイスを提供します。このクラスは直接セッションを永続化する機能は持ちません。 * 不正な値ではない場合に限り、引数のハンドラに対して移譲されます。 * <p> * ハンドラは以下のインターフェイスを持つ必要があります。 * </p> * <table> * <tr> * <th>メンバ名</th> * <th>引数</th> * <th>機能</th> * </tr> * <tr> * <td>clear</td> * <td>{@link SessionObject} session</td> * <td>セッションを保存先から削除する</td> * </tr> * <tr> * <td>store</td> * <td>{@link SessionObject} session, String values</td> * <td>シリアライズ済みの値を永続化する</td> * </tr> * <tr> * <td>restore</td> * <td>{@link SessionObject} session, Function callback</td> * <td>セッションのIDに基づきシリアライズ済みの値を取得してコールバックに渡す</td> * </tr> * </table> * * @class セッションの永続化のインターフェイスを提供します。 * @constructor * @param {Object} * handler ハンドラ * @param {Boolean} * header レスポンスヘッダの処理中にのみ保存できるかを示すフラグ、trueの場合はレスポンスヘッダの処理完了後は保存できません。 */ function SessionStore(handler, header) { this.handler = handler; this.header = header; } /** * セッションをクリアします。 * * @param {SessionObject} * session セッション */ SessionStore.prototype.clear = function(session) { if (!session || !session.sessionId) { return; } this.handler.clear(session); }; /** * セッションを保存します。 * * @param {SessionObject} * session セッション * @param {String} * values セッションのシリアライズ済みの値(JSON形式) */ SessionStore.prototype.store = function(session, values) { if (!session || !session.sessionId || !values) { return; } this.handler.store(session, values); }; /** * セッションを復元します。 * * @param {SessionObject} * session セッション * @param {Function} * callback セッションのシリアライズ済みの値(JSON形式)を受け取るコールバック関数 */ SessionStore.prototype.restore = function(session, callback) { if (!session || !session.sessionId) { callback(null); return; } this.handler.restore(session, callback); }; // // expose // module.exports = SessionStore;