Git Product home page Git Product logo

dibello's Issues

Why other async operations are disallowed within transaction?

Help me please to understand why the following code does not work?

describe('Database with foreign key relations', function() {

    it("transaction should not break by third-party asynchronous operations like delay", async function() {

        const db = await Database.open('test123', {
            version: 2,
            migrations: {
                "1": function(schema) {
                    schema.createStore('trees')
                        .id('id')
                        .key('color')
                        .field('history');
                },
                "2": function(schema) {
                    schema.createStore('apples')
                        .id('id')
                        .foreign('tree_id', 'trees.id')
                        .field('size');
                }
            }
        });

        await db.transact('readwrite', async function(trees, apples) {

            const result = await apples.find({ size: 'average' });
            const item = await result.next();
            let apple = item.value;
            
            if (!apple) {
                let tree = {
                    id: '1',
                    color: 'red'
                };
                await trees.persist(tree);
                apple = {
                    id: '1',
                    tree_id: tree.id,
                    size: 'average'
                };
            }

            function delay(ms) {
                return new Promise(resolve => setTimeout(resolve, ms));
            }

            await delay(1); // this breaks the test
        
            await apples.persist(apple);

        });

    });

});

Without await delay(1); the test works.

Help me please to compile

Thank you for the excellent lib. Before choosing it I was considering idb, indexeddb-orm, but I think your lib is most promising. I'm new to these new trends like esnext, typescript, webpack3 and to the for ever changing build tools for web development. Help me please to compile my code with the lib.

> [email protected] build C:\dev\project1\extension
> webpack

ts-loader: Using [email protected] and C:\dev\project1\extension\tsconfig.json
Hash: 2d4893eecd44fbec0aa5
Version: webpack 3.7.0
Time: 2323ms
            Asset       Size  Chunks                    Chunk Names
         popup.js    92.6 kB       0  [emitted]         popup
       options.js    1.26 kB       1  [emitted]         options
content_script.js  432 bytes       2  [emitted]         content_script
    background.js  189 bytes       3  [emitted]         background
        vendor.js     404 kB       4  [emitted]  [big]  vendor
   [3] (webpack)/buildin/global.js 509 bytes {0} [built]
   [4] ./src/popup.ts 1.47 kB {0} [built]
   [5] (webpack)/buildin/module.js 517 bytes {4} [built]
   [6] ./src/db/Db.ts 640 bytes {0} [built]
  [27] ./src/options.ts 1.15 kB {1} [built]
  [28] ./src/content_script.ts 346 bytes {2} [built]
  [29] ./src/background.ts 103 bytes {3} [built]
  [30] multi moment jquery 40 bytes {4} [built]
    + 23 hidden modules

ERROR in ./node_modules/dibello/src/constraint.ts
Module parse failed: C:\dev\project1\extension\node_modules\dibello\src\constraint.ts Unexpected token (6:36)
You may need an appropriate loader to handle this file type.
|  */
| export class Constraint {
| 	constructor(operator, discriminant : string | { fieldName : string, constraint : Constraint }[], idb) {
| 		this.operator = operator;
| 		this.discriminant = discriminant;
 @ ./node_modules/dibello/index.js 7:9-36
 @ ./src/db/Db.ts
 @ ./src/popup.ts

ERROR in ./node_modules/dibello/src/database.ts
Module parse failed: C:\dev\project1\extension\node_modules\dibello\src\database.ts Unexpected token (23:20)
You may need an appropriate loader to handle this file type.
|  */
| export class Database {
| 	constructor(schema : SchemaBuilder, idb) {
| 		if (!schema)
| 			throw "Must pass a SchemaBuilder as 'schema' to the dibello.Database constructor";
 @ ./node_modules/dibello/index.js 8:9-34
 @ ./src/db/Db.ts
 @ ./src/popup.ts

ERROR in ./node_modules/dibello/src/index.ts
Module parse failed: C:\dev\project1\extension\node_modules\dibello\src\index.ts Unexpected token (6:18)
You may need an appropriate loader to handle this file type.
| import { idbRequestToIterable } from './utils/idb/request-to-iterable';
| 
| export class Index<TModel, TIndex> {
|     constructor(repository : Repository<TModel>, name : string) {
|         this._name = name;
 @ ./node_modules/dibello/index.js 9:9-31
 @ ./src/db/Db.ts
 @ ./src/popup.ts

ERROR in ./node_modules/dibello/src/polyfill.ts
Module parse failed: C:\dev\project1\extension\node_modules\dibello\src\polyfill.ts Unexpected token (5:9)
You may need an appropriate loader to handle this file type.
| 
| if (typeof window !== 'undefined') {
| 	let win : any = window;
| 	win.indexedDB = win.indexedDB || win.mozIndexedDB || win.webkitIndexedDB || win.msIndexedDB;
| 	win.IDBTransaction = win.IDBTransaction || win.webkitIDBTransaction || win.msIDBTransaction;
 @ ./node_modules/dibello/index.js 6:0-25
 @ ./src/db/Db.ts
 @ ./src/popup.ts

ERROR in ./node_modules/dibello/src/repository.ts
Module parse failed: C:\dev\project1\extension\node_modules\dibello\src\repository.ts Unexpected token (26:23)
You may need an appropriate loader to handle this file type.
|  * Provides a high-level API on top of an IndexedDB object store (IDBObjectStore)
|  */
| export class Repository<T> {
| 	constructor(db : Database | Promise<Database>, storeName : string, transaction? : IDBTransaction) {
| 		var self = this;
 @ ./node_modules/dibello/index.js 10:9-36
 @ ./src/db/Db.ts
 @ ./src/popup.ts

ERROR in ./node_modules/dibello/src/schema-builder.ts
Module parse failed: C:\dev\project1\extension\node_modules\dibello\src\schema-builder.ts Unexpected token (21:27)
You may need an appropriate loader to handle this file type.
|  */
| export class SchemaBuilder {
| 	constructor(name, registry?) {
| 		this.name = name;
| 		this.stores = {};
 @ ./node_modules/dibello/index.js 11:9-40
 @ ./src/db/Db.ts
 @ ./src/popup.ts

ERROR in ./node_modules/dibello/src/store-builder.ts
Module parse failed: C:\dev\project1\extension\node_modules\dibello\src\store-builder.ts The keyword 'private' is reserved (20:14)
You may need an appropriate loader to handle this file type.
| 
| export class StoreBuilder { 
| 	constructor (private builder : SchemaBuilder, private name : string, id : string) {
| 		this.store = {
| 			primaryKey: id,
 @ ./node_modules/dibello/index.js 12:9-39
 @ ./src/db/Db.ts
 @ ./src/popup.ts

ERROR in ./node_modules/dibello/src/transact.ts
Module parse failed: C:\dev\project1\extension\node_modules\dibello\src\transact.ts Unexpected token (38:24)
You may need an appropriate loader to handle this file type.
|  * @returns {Promise} A promise to resolve once the transaction has fully completed.
|  */
| export function transact<T>(db, transactionOrFactory, repositoryFactory, fn : (...args) => T, mode, extraInjectables?): T {
| 	var mode = mode || 'readonly';
| 	var idb = db.idb();
 @ ./node_modules/dibello/index.js 14:9-34
 @ ./src/db/Db.ts
 @ ./src/popup.ts

ERROR in ./node_modules/dibello/src/utils/iterator-collect.ts
Module parse failed: C:\dev\project1\extension\node_modules\dibello\src\utils\iterator-collect.ts Unexpected token (1:37)
You may need an appropriate loader to handle this file type.
| export async function iteratorCollect<T>(iterator : AsyncIterable<T>, callback : (items : T[]) => void) {
|     let items = [];
|     for await (let item of iterator)
 @ ./node_modules/dibello/index.js 16:9-48
 @ ./src/db/Db.ts
 @ ./src/popup.ts

ERROR in ./node_modules/dibello/src/utils/iterator-for-each.ts
Module parse failed: C:\dev\project1\extension\node_modules\dibello\src\utils\iterator-for-each.ts Unexpected token (8:37)
You may need an appropriate loader to handle this file type.
|  * @param callback The callback to call for each round.
|  */
| export async function iteratorForEach<T>(iterable : AsyncIterable<T>, callback : (result : IteratorResult<T>) => boolean) {
|     for await (let item of iterable) {
|         if (!callback({ value: item, done: false }))
 @ ./node_modules/dibello/index.js 15:9-49
 @ ./src/db/Db.ts
 @ ./src/popup.ts
Done.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `webpack`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\rafis\AppData\Roaming\npm-cache\_logs\2017-12-08T11_52_56_273Z-debug.log

tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "lib": [
            "dom",
            "es2015",
            "es2015.iterable",
            "esnext.asynciterable"
        ],
        "noImplicitAny": false,
        "sourceMap": false,
        "rootDir": "src",
        "outDir": "dist/js",
        "noEmitOnError": true
    }
}

If I change exclude of ts-loader in webpack config to include compiling dibello source code in node_modules then I'm getting following error:

You should not need to recompile .ts files in node_modules.
Please contact the package author to advise them to use --declaration --outDir.
More https://github.com/Microsoft/TypeScript/issues/12358

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.