Code Monkey home page Code Monkey logo

diaspora's Introduction

Diaspora

Multi-source ORM for NodeJS & the browser

Build status

Fancy badges: Build Status Dependency Status Maintainability Test Coverage npm npm version GitHub commit activity the past year license Greenkeeper badge

Thanks to

Browserstack

for integration tests.

Installation

To install Diaspora, simply run one of the following commands:

# With NPM
npm install --save @diaspora/diaspora
# With Yarn
yarn add @diaspora/diaspora

Documentation & important notes

Welcome on the GitHub repository of Diaspora. Please visit the manual website, where you can find guides, tutorials, or the API tocumentation

Important note: Diaspora is very young and under heavy development. You are totally free to use it or contribute, but be aware that some important features are incomplete or absent:

  • Relations: Not implemented
  • Query language: Supported up to Specification level 2.
  • Multi sources: not tested

Diaspora extensions

Available adapters

Adapter Description Links Maintainer Platform Other infos
Node Browser
In memory
In Memory
A simple adapter that stores its data directly in the memory Built-in [QL] v2
Web API
WebApi
A customizable adapter that use HTTP APIs as data source. Convinient to query easily REST, SOAP or GraphQL apis.
Browser storage
WebStorage
A simple adapter that stores its data in the browser's local or session storage.
MongoDB
MongoDB
GitHub release
npm
yarn
GitHub followers [QL] v2
Redis
Redis
GitHub release
npm
yarn
GitHub followers [QL] v2

Other modules

plugin-server: a package to easily create APIs for Diaspora models

Compatibility

Diaspora requires:

  • Node >= 6.4.0
  • Browsers:
    • Edge >= 12
    • Firefox >= 18
    • Chrome >= 49
    • Safari & iOS Safari >=10
    • Chrome for Android >= 61
    • Samsung Internet >= 5

More briefly, Diaspora runs on all browsers & JavaScript engines that supports Proxies.

Notable incompatible browsers are

  • Internet Explorer (all versions)
  • Opera Mini
  • UC Browser for Android

API Overview

Need help getting started? We have a page on how to get started in 5 minutes.

Here is a short API overview. For a detailed API documentation, check the Diaspora API Documentation

Model methods

spawn([object props]) => Entity

Create an entity, defining its properties with provided props. The returned entity should be persisted later.

spawnMany([object[] props]) => Set

See spawn.

insert([object props]) => Promise(Entity)

Create an entity, defining its properties with provided props, and persist it immediately.

insertMany([object[] props]) => Promise(Set)

See insertMany.

find(object || Any query, [object options], [string source]) => Promise(Entity)

Retrieve an entity matching query. If query isn't an object, it is considered as an ID.

findMany(object || Any query, [object options], [string source]) => Promise(Set)

See find

delete(object || Any query, [object options], [string source]) => Promise(Entity)

Delete an entity matching query. If query isn't an object, it is considered as an ID. options can contain allowEmptyQuery.

deleteMany(object || Any query, [object options], [string source]) => Promise(Entity)

See delete

update(object || Any query, object newAttrs, [object options], [string source]) => Promise(Entity)

Update a single entity matching querywith attributes in newAttrs. If query isn't an object, it is considered as an ID. options can contain allowEmptyQuery.

updateMany(object || Any query, object newAttrs, [object options], [string source]) => Promise(Set)

See update

Entity/Set methods

destroy([string source]) => Promise(this)

Delete this entity from the specified source. Source hash object is set to undefined

persist([string source]) => Promise(this)

Save current entity to the specified source.

fetch([string source]) => Promise(this)

Reload entity from specified source.

Planned or unsure Diaspora behaviors/features

Manual change of properties

Unsure > Entity may change status to desync ?

P2P Adapter

Unsure > May be interesting... Check for possible problems about data modification, etc etc.

IndexedDB Adapter (browser)

Unsure > IndexedDB technology may be too immature. See MDN about IndexedDB. Note: Plan to show fallback implementations

Working with the development version

If you are having issues, or you want to participate to the development and create new features, you may have to use the development or staging version of Diaspora. Here is how you can do that:

# Clone the repository & go into it
git clone https://github.com/diaspora-orm/diaspora.git && cd diaspora
# Go on the staging branch (you can also use directly the `develop` branch, but it may be less stable)
git checkout staging
# The following command installs dependencies & compiles the package
npm run build
# Finally, expose your local build so that it can be used in other projects.
# You may need to run it with `sudo`.
npm link

# Go to your project
cd ~/myproject
# Ensure deps are installed
npm install
# And link the local version
npm link @diaspora/diaspora

Note that you may need to re-run npm link @diaspora/diaspora after every install (npm install) in your project.

diaspora's People

Contributors

greenkeeper[bot] avatar ikaroswilo avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

diaspora's Issues

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Rate Limited

These updates are currently rate limited. Click on a checkbox below to force their creation now.

  • Update dependency @types/jest to v23.3.14

Other Branches

These updates are pending. To force PRs open, click the checkbox below.

  • Update dependency https-proxy-agent to 2.2.3 [SECURITY]

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.


  • Check this box to trigger a request for Renovate to run again on this repository

An in-range update of ts-jest is breaking the build 🚨

The devDependency ts-jest was updated from 23.1.4 to 23.10.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ts-jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for 23.10.0

ts-jest, reloaded!

  • lots of new features including full type-checking and internal cache (see changelog)
  • improved performances
  • Babel not required anymore
  • improved (and growing) documentation
  • a ts-jest Slack community where you can find some instant help
  • end-to-end isolated testing over multiple jest, typescript and babel versions
Commits

The new version differs by 293 commits.

  • 0e5ffed chore(release): 23.10.0
  • 3665609 Merge pull request #734 from huafu/appveyor-optimizations
  • 45d44d1 Merge branch 'master' into appveyor-optimizations
  • 76e2fe5 ci(appveyor): cache npm versions as well
  • 191c464 ci(appveyor): try to improve appveyor's config
  • 0f31b42 Merge pull request #733 from huafu/fix-test-snap
  • 661853a Merge branch 'master' into fix-test-snap
  • aa7458a Merge pull request #731 from kulshekhar/dependabot/npm_and_yarn/tslint-plugin-prettier-2.0.0
  • 70775f1 ci(lint): run lint scripts in series instead of parallel
  • a18e919 style(fix): exclude package.json from tslint rules
  • 011b580 test(config): stop using snapshots for pkg versions
  • 7e5a3a1 build(deps-dev): bump tslint-plugin-prettier from 1.3.0 to 2.0.0
  • fbe90a9 Merge pull request #730 from kulshekhar/dependabot/npm_and_yarn/@types/node-10.10.1
  • a88456e build(deps-dev): bump @types/node from 10.9.4 to 10.10.1
  • 54fd239 Merge pull request #729 from kulshekhar/dependabot/npm_and_yarn/prettier-1.14.3

There are 250 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Can't build with babel

When running grunt build, following error is thrown:

Warning: Uglification failed.
Unexpected token: string (core-js/modules/es6.promise).
Line 13 in build/isolated/dist/diaspora.js
Use --force to continue.

Babelified file contains an import statement line 13:

import "core-js/modules/es6.promise";

Related to babel/babel#6601

Extend Diaspora API to generate watchers

Watchers are entities synced with their data source, and we need a way to generate them.

Proposal

Entity.watch(sourceName: string | string[] | True | undefined): WatchableEntity

Params

  • sourceName: string | string[] | True | undefined

    Represents sources to watch. If string or array of string are given, search sources with that name. True stands for all sources. undefined binds only default data source.

Returns

Returned value is the corresponding WatchableEntity

An in-range update of @types/node is breaking the build 🚨

The devDependency @types/node was updated from 10.9.4 to 10.10.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of ts-jest is breaking the build 🚨

The devDependency ts-jest was updated from 23.10.3 to 23.10.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ts-jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for 23.10.4 (2018-10-06)

Bug Fixes

  • cache: adds project's dep versions to cache key (6cacbea), closes #785
  • cli: change options to better reflect the new presets (68abcfb)
  • helpers: deprecate import from ts-jest, now ts-jest/utils (33ff29f), closes #782
  • typings: typo in presets definition file (53767ab)
  • typings: wrong import in preset typings + test (94dc4e7)
Commits

The new version differs by 22 commits.

  • ef89ee6 Merge pull request #795 from huafu/release/23.10.4
  • 82a930b chore(release): 23.10.4
  • 69b80ad Merge pull request #794 from huafu/fix-preset-typings
  • 94dc4e7 fix(typings): wrong import in preset typings + test
  • 53767ab fix(typings): typo in presets definition file
  • 90beca8 Merge pull request #787 from huafu/fix-testing-utils
  • 89ad06a style(cli): more readable code when setting defaults for init
  • b1eed98 docs(install): includes @types/jest in install script
  • b837acd test(typings): repalce jest.SpyInstance with MockInstance
  • 6cacbea fix(cache): adds project's dep versions to cache key
  • 7b2dd01 test(preset): fixes tests, doc and cli for presets
  • ec78757 docs(utils): updates docs related to moved helpers
  • 8d5a60a test(preset): updates tests related to presets
  • 68abcfb fix(cli): change options to better reflect the new presets
  • 33ff29f fix(helpers): deprecate import from ts-jest, now ts-jest/utils

There are 22 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Adapter capability

In order to help the user, the next adapter structure should allow developer to indicate which features are available, such as query operator, schemas, or pubsub (see #5). It may require each query operator to be casted using its own function.

Maybe a QL translator class may help, to translate from Diaspora QL & DB specific language.

But there are still some exceptions: Some adapters (such as In Memory, LocalStorage or WebAPI) should not translate query language from objects to string or objects. WebAPI should transfert the query "as is" and InMemory or LocalStorage may generate a matcher function to perform the query. The next adapters structure should support that

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Add methods on Set

For now, sets are only snapshots of the data source matching a precise query, but this approach lacks of possibilities to actually manipulate data persisted in store through a set or operate on the set content

Read

Some methods, such as find, findMany, or upcoming has, count or every methods (see #25) would be useful on Sets too, to perform checks or filters on already retrieved sets.

Create

It would be useful to allow the user to manually add arbitrary entities to a set without persisting the insertion. To persist at the same time that we add items, maybe we should also offer the possibility to insert items in the set and in the data source, but it may be redundant with an add followed by a persist of the set.

Update

Update is OK IMO:

  • To update some entities of the set, we can directly edit them then persist:
    mySet.entities[0].attributes.foo = 'bar';
    await mySet.persist();
  • To update all entities of the set, we can use the update method, optionaly followed by a persist call.

Delete

For now, we can only change the collection of entities in the set by modifying the entities property, which should be readonly by design. Filtering entities from an existing set is pretty important to keep the code clear and concise, as well as optimizing by doing several different operations on different sets extracted using a single data source search.


Seeing that, the set may evolve in a class implementing both interfaces defined by adapters (like insert, insertMany, has, all, count, etc etc) and entities (such as persist, destroy and fetch). So, maybe we can re-manipulate the set to be a special kind of temporary in-memory data source. Of course, most of the new features described above can be done using the lodash wrapper returned by the toChainable method, but it requires extra method calls and lose the ability to use the Diaspora's query language

Comments welcome, @IkarosWilo

An in-range update of logform is breaking the build 🚨

The dependency logform was updated from 1.9.1 to 1.10.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

logform is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 7 commits.

  • 9c826a2 [dist] Version bump. 1.10.0
  • d99c555 [fix dist] Use prepublishOnly to only run on prepublish and not on install.
  • d9d41c5 [refactor api] Update transpilation to opt-in only for browser applications using "browser" in package.json.
  • c904f9b precompile es syntax before publishing to npm
  • 4549134 routing info through splat logic regardless of whether tokens exist to ensure consistency in expected results
  • ca6e3cf Changes for splat when there are no tokens present (#46)
  • 4d560e7 Add types field in package.json (#52)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of prettier is breaking the build 🚨

The devDependency prettier was updated from 1.14.2 to 1.14.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

prettier is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for 1.14.3

🔗 Changelog

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Add methods to get matches count or existence

  • Add has method on adapter & model to check if at least entity matches the query. It could be polyfilled with a find method, returning true if an item is matched
  • Add count method on adapter & model to get the number of entities matching the query. It could be polyfilled with a findMany method, returning the count of matched items.
  • Add every method on adapter & model to check if every entities matches the query. It can be polyfilled by running a findMany with the query, and check if the number of matched entities is equal to the count of entities matched by a findMany without any criterion

Query Language: Allow Infix & Prefix input formats & determine normalized query format

In its final form, the query language should allow a wide variety of combinations, to makes queries as easy to write as they are to think. Diaspora should perform following query-to-assertion translations:

  • { "foo": { "==" { "bar": 2 }}} => entity.foo == {bar: 2}
  • { "foo": { "bar": 2, "baz": 3 }} => entity.foo.bar == 2 && entity.foo.baz == 3
  • { "foo" { "$contains": { "bar": 2, "baz": 3 }}} => entity.foo.bar == 2 && entity.foo.baz == 3
  • { "==": { "foo": 1 }} => entity.foo == 1
  • { "foo": { "||" [ 1, 2 ]}} => entity.foo == 1 || entity.foo == 2
  • { "foo": { "||": [ 1, 2, 3 ] }, "bar": { ">": 1 }} => (entity.foo == 1 || entity.foo == 2 || entity.foo == 3) && entity.bar > 1
  • { "||": [{ "foo": { "==": 1 }}, { "bar"; { "==" 2 }}]} => entity.foo == 1 || entity.bar == 2

Rules are that several operator properties are implicitly resolved as &&, and implicit { [field]: value} without operator will have different results depending on the type of the value.

  • If its a primitive, it will be resolved as { "==": { [field]: value }}
  • If its an object, it will be resolved as { "$contains": { [field]: value}}

We've seen with @IkarosWilo that operators at root set a "prefix" mode.
If it's a field name, the "infix" mode is enabled: it projects its left operand in a new operator child object.

About escaping

We have to support the case where a field is named the same way as an operator, like $equal or ||. Escaping query keys may be done with ., this way: { ".$equal": { ">": 1}}. The leading dot forces the key to be treated as a field name instead of an operator, and is removed in the resulting query.

To output a leading dot in the output query, 2 dots should be used: { "..$equal": { ">": 1}}

About fields relation

It may be relevant to support in-entity fields comparisons, like this assert: entity.a == entity.b. But how to mark the value as a field instead of a string ?

Relational model/entity query population

When running a query on a model or entity, the returned Promise should be replaced by a QueryPromise. This promise should expose methods to populate relations at resolution time.

An in-range update of rollup-plugin-commonjs is breaking the build 🚨

The devDependency rollup-plugin-commonjs was updated from 9.1.6 to 9.1.7.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup-plugin-commonjs is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Implement observable generic container

In order to implement relations, entity relation fields should be an observable field, that runs the correct query if required when trying to access a property.

Example use case:

const entity: Entity = await myModel.find({id: 1});
const subEntity = await entity.attributes.relationalT1Field;// subEntity is an Entity
const subSet = await entity.attributes.relationalTxField;// subSet is a Set

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Deprecate old package

I should deprecate the old Diaspora package

npm deprecate diaspora "\"diaspora\" was moved to \"@diaspora/diaspora\". Please consider running \"npm un diaspora && npm i @diaspora/diaspora\" to install new versions."

An in-range update of conventional-changelog-cli is breaking the build 🚨

The devDependency conventional-changelog-cli was updated from 2.0.5 to 2.0.7.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

conventional-changelog-cli is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of semantic-release is breaking the build 🚨

The devDependency semantic-release was updated from 15.9.15 to 15.9.16.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

semantic-release is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v15.9.16

15.9.16 (2018-09-19)

Bug Fixes

  • package: update env-ci to version 3.0.0 (b9ae7d2)
Commits

The new version differs by 2 commits.

  • b9ae7d2 fix(package): update env-ci to version 3.0.0
  • c27e18e chore(package): update nock to version 10.0.0

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Methods deprecation

Some methods are obsolete and should be deleted. To avoid too many refactors, mark them as deprecated.

  • Diaspora.createNamedDataSource => replaced with Diaspora.createDataSource

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.