GithubHelp home page GithubHelp logo

wisembly / basil.js Goto Github PK

View Code? Open in Web Editor NEW
2.0K 2.0K 63.0 723 KB

The missing Javascript smart persistent layer

Home Page: https://wisembly.github.io/basil.js

License: Other

JavaScript 98.26% HTML 1.74%

basil.js's Introduction

Wisembly

This repo is the code of wisembly website, made on top of Wisembly silexCMS.

Install

  • clone repository

git clone git://github.com/Wisembly/wisembly.git

  • initialise submodules (Twitter bootstrap, jQuery..)

git submodule update --init

  • get composer

  • install vendors

php composer.php install

  • duplicate every .dist file in app/config/, web/fr|en/ and tweak them as need

  • import bin/database_structure.sql

That's it!

Licence

MIT Licence

Authors

  • @nicolaschenet
  • @arcanis
  • @guillaumepotier

basil.js's People

Contributors

aaronjensen avatar arbitrix avatar blainsmith avatar codeburke avatar dependabot[bot] avatar gmajoulet avatar guillaumepotier avatar kkirsche avatar loicbourg avatar mikejwis avatar re5et avatar sorrycc avatar timgates42 avatar tk120404 avatar tonyseek avatar zethussuen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

basil.js's Issues

base64 option

Can you add base64 option,so it will be more safe.

escaping keys caused namespaced cookie names to change

This isn't a problem for us because our site isn't live yet, but I just wanted you all to be aware that #30 changed the name of namespaced cookies because the : gets escaped to %3A.

You might consider changing the namespace separator to . as that won't get escaped. It'd still be a breaking change though. The other option would be to escape the namespace and the key separately, which would leave the : in there, which may or may be valid in all browsers--it's hard to tell from the rfc what is actually valid in a cookie name.

Delimiter is not configurable

Our project has been using 0.4.1 for quite a while. We attempted to update to 0.4.4 (latest) and ran into the breaking : to . key delimiter change (#35) .

Instead of hardcoding a delimiter I propose that we expose keyDelimiter as a Basil.option.

Safari private browsing, QUOTA_EXCEEDED_ERR: DOM Exception 22

Getting exceptions in our tracker with the message QUOTA_EXCEEDED_ERR: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota. So far it has come from Safari versions 5.x in private browsing mode. Looking at the Basil code I don't see how this could happen. Maybe it's coming from a browser plugin?

cookie without secure attribute warning

Firefox (v100.0.2 64 bit) console show this warning:

Cookie “smarket-manager.currentWebPackBundleHash” will be soon rejected because it has the “SameSite” attribute set to “None” or an invalid value, without the “secure” attribute. To know more about the “SameSite“ attribute, read https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite

[basil.min.js:1:3750]

(https://cdn.jsdelivr.net/npm/[email protected]/build/basil.min.js)

I'm using basil with this code:

window.smarket.storage = new window.Basil({
          namespace: 'smarket-manager',
          storages: ['local', 'cookie', 'session', 'memory'],
          storage: 'local',
          expireDays: 3650
        });
        window.smarket.storage.set('currentWebPackBundleHash', initialState.currentBundleHash);

Doesn't work with Jest?

Hello, I don't know if this is the right place for this but I was hoping you could point me in the right direction. I have a thin wrapper around basil called StorageUtils (it just extracts the usage into a module that I prefer basically but uses Basil under the hood). When I test StorageUtils in mocha it works perfectly fine.

I'm now converting my tests to use Jest and it no longer works. Even something as simple as this returns null (not even a real test):

describe('Storage utils', () => {
    StorageUtils.set('name', 'Jest');
    console.log('~~~~', StorageUtils.get('name'));
});

I am at a loss as to why this is happening but was hoping maybe it would trigger something in your mind to help lead me down the right path. Any help would be greatly appreciated.

force storage document

document states this:

// force storage on the go through basil
// set 'bar' value under 'foo' key in localStorage
basil.set('foo', 'bar', { 'storage': 'local' });

I am not sure if basil ever use storage in options, it seem to only look at storages, and I am not sure why it's desirable to set value on all available storage.

            set: function (name, value, options) {
                if (!(name = _toStoredKey(this.options.namespace, name)))
                    return;
                value = _toStoredValue(value);
                options = Basil.utils.extend({
                    expireDays: this.options.expireDays
                }, options);

                var storages = _toStoragesArray(options.storages) || [this.defaultStorage];
                for (var i = 0; i < storages.length; i++) {
                    if (!this.check(storages[i]))
                        continue;
                    _storages[storages[i]].set(name, value, options);
                }
            },

basil.reset() Doesn't clean cookies set with basel when invoked

I set basil with options:

var options = {
namespace: 'userData',
storages: [ 'sessionStorage' ,'cookie'],
storage: 'sessionStorage',
expireDays: 1
};

After I invoke one of these , basil doesn't clean the cookies that created and basil.keys() keeps keys of the data that was set:
basil.reset({'namespace': 'userData'});
basil.reset({'namespace': 'userData' , 'storages': [ 'sessionStorage' ,'cookie']});
basil.reset();

PS
Thank you for this library!

Issue in Basil plugin architecture

If you add two plugins then in the second plugin Basil doesn't point to the initial class because it is overridden in the first.

For example, we have following in basil.list.js:

var BasilList = function (options) {
        return new Basil.utils.extend(Basil.Storage().init(options), Basil.List(options));
};

and

var BasilList = function (options) {
        return new Basil.utils.extend(Basil.Storage().init(options), Basil.Set(options));
};

in basil.set.js.

Let's say basil.list.js is included before basil.set.js, now basil.list.js will get the correct class as Basil still points to the original class, but basil.set.js will get

function (options) {
        return new Basil.utils.extend(Basil.Storage().init(options), Basil.List(options));
}

as the value for "Basil" and since Basil is already overridden in basil.list.js this fails as the original class is lost.

handling path

hello,

in current version cookie path is fixed to the value "/"

how about render it dynamic? something like this:

if (options.path) {
    cookie += '; path=' + options.path;
}
document.cookie = cookie + ';';

thank you
lorenzo

Questions about stability

How stable is basil.js for production and what are the browser compatibility/fallbacks like?

Also can this be used both client/server side and do they communicate?

Issue with namespace "reset" logic

Steps to reproduce -

  • Create two namespaces for the same application namely - "namespace" and "namespacePersistent".
  • Try to reset "namespace".
  • Observe that even "namespacePersistent" gets reset.

I went through the code and observed that the way the "reset" function is implemented

reset: function (namespace) {
				for (var i = 0, key; i < window[this.engine].length; i++) {
					key = window[this.engine].key(i);
					if (!namespace || key.indexOf(namespace) === 0) {
						this.remove(key);
						i--;
					}
				}
	}

In this case key.indexOf(namespace) === 0 for namespace and namespacePersistent will be true and hence will reset both the namespaces.

Solution :
We can use a combination of namespace and delimiter for finding the index.
Considering the default delimiter as ' . ' a namespace delimiter combination will not return 0

let key = 'namespacePersistent.key1' ;
key.indexOf("namespace.") === 0 // false since index returned will be -1.

We can pass the namespace and delimiter combination from the callee.

reset: function (options) {
				options = Basil.utils.extend({}, this.options, options);
				Basil.utils.tryEach(_toStoragesArray(options.storages), function (storage) {
                                           let namespaceStr = options.namespace+(options.keyDelimiter || '.'); 
					_storages[storage].reset(namespaceStr);
				}, null, this);
			},

If this solution is looks fine I can raise a PR for the same.

SameSite property on cookies not supported

It looks like basil does not support use of the SameSite property. Is basil still being maintained and do you plan on adding support for SameSite? I'm happy to submit a PR for this if you'd like.

Publish 0.4.4 to npm?

I was grabbing Basil today and noticed 0.4.4 is not on npm. Latest on npm is 0.4.3. Could you please publish 0.4.4? Thanks!

Using with react

Apparently this library conflicts with some internal react process due to its globally defined context.

If connecting this library and using an undefined variable in some of the React components I get error like this:
Warning: Exception thrown by hook while handling onSetChildren: Invariant Violation: Expected onMountComponent() to fire for the child before its parent includes it in onSetChildren(). Invariant Violation: Expected onMountComponent() to fire for the child before its parent includes it in onSetChildren().
The normal error is something like foo is not defined with file and location on the right side. But instead I get an very strange error from react's warning.js file that leads me to nowhere.

expireDays only works for cookies

It'd be pretty cool if we could expire localStorage items as well. I know there's no native way of doing it, but we could check if the item is expired when loading the item from localStorage

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.