Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to initialize db with PartitioningAdapter + IndexedStorage #160

Open
damien-murphy opened this issue Jan 16, 2019 · 3 comments
Open

Comments

@damien-murphy
Copy link

damien-murphy commented Jan 16, 2019

I'm submitting a

[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request

Current behavior

Cannot pass PartitioningAdapter as an adapter to initializePersistence

Error:


Type 'PartitioningAdapter' is not assignable to type 'StorageAdapter'.
  Types of property 'exportDatabase' are incompatible.
    Type '(dbname: string, dbref: import("/xxx/angular-pwa/node_modules/@lokidb/partitioning-adapter/types/loki/src/loki").Loki) => Promise<void>' 

    is not assignable to type 
    '(dbname: string, dbref: import("/xxx/angular-pwa/node_modules/@lokidb/loki/types/loki/src/loki").Loki) => Promise<void>'.

Expected behavior

Can pass PartitioningAdapter as an adapter to initializePersistence

Minimal reproduction of the problem with instructions


    IndexedStorage.register();
    PartitioningAdapter.register();
    let idbAdapter = new IndexedStorage('test.db');
    let paAdapter = new PartitioningAdapter(
      idbAdapter, 
      { 
        paging: true, 
        pageSize:5*1024*1024 
      }
    );
    let options: Loki.Options = {
      env: 'BROWSER',
      serializationMethod: 'normal'
    };
    
    let db = new Loki('test.db', options);

    let persistenceOptions: Loki.PersistenceOptions = {
      adapter: paAdapter, <-- Issue is here
      autosave: false,
      autosaveInterval: 1000,
      autoload: false,
      throttledSaves: false,
      persistenceMethod: 'indexed-storage'
    };
    this.db.initializePersistence(persistenceOptions).then(err => {
      console.log('initializePersistence complete');
    });

What is the motivation / use case for changing the behavior?

Be able to use PartitioningAdapter

Environment


LokiDB version: 2.0.0-beta.8
Browser/Node version: Chrome 71.x

The issue is that there are two Loki type definitions one in Loki & one in PartitioningAdapter. PartitioningAdapter extends the StorageAdapter which references its own copy of Loki and not the root copy here @lokidb/loki

@lokidb/partitioning-adapter/types/loki/src/loki
@lokidb/loki

If I try to use the reference to @lokidb/partitioning-adapter/types/loki/src/loki instead of @lokidb/loki I can pass the paAdapter to the PersistenceOptions but i get another error

Module not found: Error: Can't resolve '@lokidb/partitioning-adapter/types/loki/src/loki'
@Viatorus
Copy link
Member

Viatorus commented Jan 16, 2019

Interesting fact. Does it work if you disable type checking via as any as workaround?

@damien-murphy
Copy link
Author

Yes partitioning starts working then

image

@jlarmstrongiv
Copy link

I also received that error, but with the fsAdapter:

Type 'PartitioningAdapter' is not assignable to type 'StorageAdapter'.
Types of property 'exportDatabase' are incompatible.
Type '(dbname: string, dbref: import("/…/node_modules/@lokidb/partitioning-adapter/types/loki/src/loki").Loki) => Promise<void>' is not assignable to type '(dbname: string, dbref: import("/…/node_modules/@lokidb/loki/types/loki/src/loki").Loki) => Promise<void>'.
Types of parameters 'dbref' and 'dbref' are incompatible.
Type 'import("/…/node_modules/@lokidb/loki/types/loki/src/loki").Loki' is not assignable to type 'import("/…/node_modules/@lokidb/partitioning-adapter/types/loki/src/loki").Loki'.
Types have separate declarations of a private property 'databaseVersion'.
The expected type comes from property 'adapter' which is declared here on type 'PersistenceOptions'

Thanks for the workaround! Changing adapter: paAdapter to adapter: paAdapter as any, lets it run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants