Skip to content

Commit

Permalink
Merge pull request #3 from amarksingh/master
Browse files Browse the repository at this point in the history
test application from documention and fixed missing feature and bugs
  • Loading branch information
amarksingh authored Dec 26, 2021
2 parents 8cced39 + e99542d commit 6f16321
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 19 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -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}}
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.github
.npmignore
.gitignore
10 changes: 3 additions & 7 deletions console/sessionTableCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 4 additions & 6 deletions console/stubs/database.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -15,9 +14,8 @@ class CreateSessionsTable extends Migration {
});
}

down()
{
Schema.dropIfExists('sessions');
async down() {
await Schema.dropIfExists('sessions');
}
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -36,4 +36,4 @@
"url": "https://github.com/ostrojs/session/issues"
},
"homepage": "https://github.com/ostrojs/session#readme"
}
}
36 changes: 32 additions & 4 deletions session.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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() {
Expand Down Expand Up @@ -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', []);
Expand Down

0 comments on commit 6f16321

Please sign in to comment.