From edbde7e62e7c4b11f2b157805306f33ad8a8d506 Mon Sep 17 00:00:00 2001 From: Amar kumar singh Date: Sat, 18 Dec 2021 02:12:44 +0530 Subject: [PATCH 1/4] Update version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 69cd99f..bf7ccad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ostro/session", - "version": "0.0.0-alpha.0", + "version": "0.0.0-alpha.1", "description": "Session module for OstroJS", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" @@ -36,4 +36,4 @@ "url": "https://github.com/ostrojs/session/issues" }, "homepage": "https://github.com/ostrojs/session#readme" -} \ No newline at end of file +} From db3bf7992dc8db6a9141c981a1c280a89da86fbe Mon Sep 17 00:00:00 2001 From: Amar kumar singh Date: Sat, 18 Dec 2021 04:39:20 +0530 Subject: [PATCH 2/4] Create npm-publish.yml --- .github/workflows/npm-publish.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/npm-publish.yml diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..118cf52 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,22 @@ +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created +# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages + +name: Node.js Package + +on: + release: + types: [created] + +jobs: + + publish-npm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: 14 + registry-url: https://registry.npmjs.org/ + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.npm_token}} From 042689d4d4b18aca0b0f23b411b31868268ef4ae Mon Sep 17 00:00:00 2001 From: ostrojs Date: Mon, 20 Dec 2021 22:34:55 +0530 Subject: [PATCH 3/4] npmignore --- .npmignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..96bcd9e --- /dev/null +++ b/.npmignore @@ -0,0 +1,3 @@ +.github +.npmignore +.gitignore \ No newline at end of file From e99542d2b79ba3dd97e1738da01e2a512f44ee8e Mon Sep 17 00:00:00 2001 From: ostrojs Date: Sun, 26 Dec 2021 15:22:52 +0530 Subject: [PATCH 4/4] test application from documention and fixed missing feature and bugs --- console/sessionTableCommand.js | 10 +++------- console/stubs/database.stub | 10 ++++------ session.js | 36 ++++++++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/console/sessionTableCommand.js b/console/sessionTableCommand.js index bee1315..0659027 100644 --- a/console/sessionTableCommand.js +++ b/console/sessionTableCommand.js @@ -2,14 +2,10 @@ const Command = require('@ostro/console/command') class SessionTableCommand extends Command { - get $signature() { - return 'session:table'; - } + $signature = 'session:table'; + + $description = 'Create a migration for the session database table'; - get $description() { - return 'Create a migration for the session database table' - }; - $files; constructor($files) { diff --git a/console/stubs/database.stub b/console/stubs/database.stub index 0213e31..05b1320 100644 --- a/console/stubs/database.stub +++ b/console/stubs/database.stub @@ -3,9 +3,8 @@ const Migration = require('@ostro/database/migration') class CreateSessionsTable extends Migration { - up() - { - Schema.create('sessions', function ($table) { + async up() { + await Schema.create('sessions', function ($table) { $table.string('id').primary(); $table.foreignId('user_id').nullable().index(); $table.string('ip_address', 45).nullable(); @@ -15,9 +14,8 @@ class CreateSessionsTable extends Migration { }); } - down() - { - Schema.dropIfExists('sessions'); + async down() { + await Schema.dropIfExists('sessions'); } } diff --git a/session.js b/session.js index 800f791..eea3c00 100644 --- a/session.js +++ b/session.js @@ -1,4 +1,4 @@ -const { isPlainObject, merge, get, set, isObject, omit, uniq, difference, isArray } = require('lodash') +const { isPlainObject, merge, get, set, isObject, omit, uniq, difference, isArray, intersection } = require('lodash') const SessionInterface = require('@ostro/contracts/session/session') const uid = require('uid-safe').sync const kAttributes = Symbol('attributes') @@ -23,9 +23,15 @@ class Session extends SessionInterface { [kResponse]: { value: response }, - existed: { value: Boolean(__attributes) } + existed: { + value: Boolean(__attributes) + } + + }); + Object.defineProperty(this, 'touched', { + value: Boolean((this.get('__flash.__old')).length), + writable: true }) - Object.defineProperty(this, 'touched', { value: Boolean((this.get('__flash.__old')).length), writable: true }) } getId() { @@ -132,10 +138,32 @@ class Session extends SessionInterface { }; } this.put(key); - this.put('__flash.__new', (this.get('__flash.__new', [])).concat(Object.keys(key))); + this.put('__flash.__new', uniq(this.get('__flash.__new', []).concat(Object.keys(key)))); this.put('__flash.__old', difference(this.get('__flash.__old', []), Object.keys(key))); } + flashOnly(keys) { + keys = Array.isArray(keys) ? keys : arguments; + let onlyKeys = intersection(this.get('__flash.__new', []), keys) + let exceptKeys = difference(this.get('__flash.__new', []), keys) + for (let except of exceptKeys) { + this.forget(except) + } + this.put('__flash.__new', onlyKeys); + this.put('__flash.__old', difference(this.get('__flash.__old', []), keys)); + } + + flashExcept(keys) { + keys = Array.isArray(keys) ? keys : arguments; + let exceptKeys = intersection(this.get('__flash.__new', []), keys) + let onlyKeys = difference(this.get('__flash.__new', []), keys) + for (let except of exceptKeys) { + this.forget(except) + } + this.put('__flash.__new', onlyKeys); + this.put('__flash.__old', difference(this.get('__flash.__old', []), keys)); + } + reflash() { this.put('__flash.__new', uniq((this.get('__flash.__new', [])).concat(this.get('__flash.__old', []))));; this.put('__flash.__old', []);