@signaldb/core 2.0.0-beta.7 → 2.0.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,6 @@
1
- import type { BaseItem } from './Collection';
2
- import type Collection from './Collection';
3
- import type DataAdapter from './DataAdapter';
4
- import type { CollectionBackend } from './DataAdapter';
5
- import type StorageAdapter from './types/StorageAdapter';
1
+ import { BaseItem, default as Collection } from './Collection';
2
+ import { default as DataAdapter, CollectionBackend } from './DataAdapter';
3
+ import { default as StorageAdapter } from './types/StorageAdapter';
6
4
  export interface AsyncDataAdapterOptions {
7
5
  /** Factory to obtain a StorageAdapter per collection name */
8
6
  storage: (name: string) => StorageAdapter<any, any>;
@@ -1,9 +1,7 @@
1
- import type { BaseItem } from './Collection';
2
- import type Collection from './Collection';
3
- import type DataAdapter from './DataAdapter';
4
- import type { CollectionBackend } from './DataAdapter';
5
- import type StorageAdapter from './types/StorageAdapter';
6
- import type Selector from './types/Selector';
1
+ import { BaseItem, default as Collection } from './Collection';
2
+ import { default as DataAdapter, CollectionBackend } from './DataAdapter';
3
+ import { default as StorageAdapter } from './types/StorageAdapter';
4
+ import { default as Selector } from './types/Selector';
7
5
  /**
8
6
  * AutoFetchDataAdapterOptions
9
7
  *
@@ -1,6 +1,6 @@
1
- import type ReactivityAdapter from '../types/ReactivityAdapter';
2
- import type { BaseItem, FindOptions, Transform } from './types';
3
- import type { ObserveCallbacks } from './Observer';
1
+ import { default as ReactivityAdapter } from '../types/ReactivityAdapter';
2
+ import { BaseItem, FindOptions, Transform } from './types';
3
+ import { ObserveCallbacks } from './Observer';
4
4
  /**
5
5
  * Checks if the current scope is reactive, considering the provided reactivity adapter.
6
6
  * @param reactivity - The reactivity adapter or a boolean indicating whether reactivity is enabled.
@@ -1,12 +1,11 @@
1
- import type ReactivityAdapter from '../types/ReactivityAdapter';
2
- import EventEmitter from '../utils/EventEmitter';
3
- import type Selector from '../types/Selector';
4
- import type Modifier from '../types/Modifier';
5
- import type DataAdapter from '../DataAdapter';
6
- import type { QueryOptions } from '../DataAdapter';
7
- import type StorageAdapter from '../types/StorageAdapter';
8
- import Cursor from './Cursor';
9
- import type { AsyncFindOptions, BaseItem, FindOptions, SyncFindOptions, Transform, TransformAll } from './types';
1
+ import { default as ReactivityAdapter } from '../types/ReactivityAdapter';
2
+ import { default as EventEmitter } from '../utils/EventEmitter';
3
+ import { default as Selector } from '../types/Selector';
4
+ import { default as Modifier } from '../types/Modifier';
5
+ import { default as DataAdapter, QueryOptions } from '../DataAdapter';
6
+ import { default as StorageAdapter } from '../types/StorageAdapter';
7
+ import { default as Cursor } from './Cursor';
8
+ import { AsyncFindOptions, BaseItem, FindOptions, SyncFindOptions, Transform, TransformAll } from './types';
10
9
  export type { AnyFindOptions, AsyncFindOptions, BaseItem, Transform, TransformAll, SortSpecifier, FieldSpecifier, FindOptions, SyncFindOptions, } from './types';
11
10
  export type { CursorOptions } from './Cursor';
12
11
  export type { ObserveCallbacks } from './Observer';
@@ -1,5 +1,5 @@
1
- import type { QueryOptions } from '../DataAdapter';
2
- import type ReactivityAdapter from '../types/ReactivityAdapter';
1
+ import { QueryOptions } from '../DataAdapter';
2
+ import { default as ReactivityAdapter } from '../types/ReactivityAdapter';
3
3
  export type BaseItem<I = any> = {
4
4
  id: I;
5
5
  } & Record<string, any>;
@@ -1,7 +1,6 @@
1
- import type { BaseItem, FieldSpecifier, SortSpecifier } from './Collection';
2
- import type Collection from './Collection';
3
- import type Modifier from './types/Modifier';
4
- import type Selector from './types/Selector';
1
+ import { BaseItem, FieldSpecifier, SortSpecifier, default as Collection } from './Collection';
2
+ import { default as Modifier } from './types/Modifier';
3
+ import { default as Selector } from './types/Selector';
5
4
  export interface QueryOptions<T extends BaseItem> {
6
5
  /** Sort order (default: natural order) */
7
6
  sort?: SortSpecifier<T> | undefined;
@@ -1,8 +1,6 @@
1
- import type { BaseItem } from './Collection';
2
- import type Collection from './Collection';
3
- import type DataAdapter from './DataAdapter';
4
- import type { CollectionBackend } from './DataAdapter';
5
- import type StorageAdapter from './types/StorageAdapter';
1
+ import { BaseItem, default as Collection } from './Collection';
2
+ import { default as DataAdapter, CollectionBackend } from './DataAdapter';
3
+ import { default as StorageAdapter } from './types/StorageAdapter';
6
4
  interface DefaultDataAdapterOptions {
7
5
  storage?: (name: string) => StorageAdapter<any, any> | undefined;
8
6
  onError?: (name: string, error: Error) => void;
@@ -1,7 +1,5 @@
1
- import type { BaseItem } from './Collection';
2
- import type Collection from './Collection';
3
- import type DataAdapter from './DataAdapter';
4
- import type { CollectionBackend } from './DataAdapter';
1
+ import { BaseItem, default as Collection } from './Collection';
2
+ import { default as DataAdapter, CollectionBackend } from './DataAdapter';
5
3
  interface WorkerDataAdapterOptions {
6
4
  id?: string;
7
5
  log?: (message: string, ...args: any[]) => void;
@@ -1,8 +1,8 @@
1
- import type { BaseItem } from './Collection';
2
- import type { QueryOptions } from './DataAdapter';
3
- import type Modifier from './types/Modifier';
4
- import type StorageAdapter from './types/StorageAdapter';
5
- import type Selector from './types/Selector';
1
+ import { BaseItem } from './Collection';
2
+ import { QueryOptions } from './DataAdapter';
3
+ import { default as Modifier } from './types/Modifier';
4
+ import { default as StorageAdapter } from './types/StorageAdapter';
5
+ import { default as Selector } from './types/Selector';
6
6
  interface WorkerContext {
7
7
  addEventListener: (type: 'message', listener: (event: MessageEvent) => any) => void;
8
8
  postMessage: (message: any) => void;
@@ -1,7 +1,7 @@
1
- import type { BaseItem } from './Collection/types';
1
+ import { BaseItem } from './Collection/types';
2
2
  /**
3
3
  * creates an index for a specific field
4
4
  * @param field name of the field
5
5
  * @returns an index provider to pass to the `indices` option of the collection constructor
6
6
  */
7
- export default function createIndex<T extends BaseItem<I> = BaseItem, I = any>(field: string): import("./types/IndexProvider").default<T, I>;
7
+ export default function createIndex<T extends BaseItem<I> = BaseItem, I = any>(field: string): import('./types/IndexProvider').default<T, I>;
@@ -1,5 +1,5 @@
1
- import type { BaseItem } from './Collection';
2
- import type IndexProvider from './types/IndexProvider';
1
+ import { BaseItem } from './Collection';
2
+ import { default as IndexProvider } from './types/IndexProvider';
3
3
  /**
4
4
  * Creates an IndexProvider based on the given definition.
5
5
  * @param definition - The definition of the IndexProvider.
@@ -1,5 +1,5 @@
1
- import type Dependency from './types/Dependency';
2
- import type ReactivityAdapter from './types/ReactivityAdapter';
1
+ import { default as Dependency } from './types/Dependency';
2
+ import { default as ReactivityAdapter } from './types/ReactivityAdapter';
3
3
  /**
4
4
  * Creates an ReactivityAdapter based on the given definition.
5
5
  * @param definition - The definition of the ReactivityAdapter.
@@ -1,4 +1,4 @@
1
- import type StorageAdapter from './types/StorageAdapter';
1
+ import { default as StorageAdapter } from './types/StorageAdapter';
2
2
  /**
3
3
  * Creates an StorageAdapter based on the given definition.
4
4
  * @param definition - The definition of the StorageAdapter.
@@ -1,7 +1,6 @@
1
- import type { AsynchronousQueryFunction, SynchronousQueryFunction } from './types/IndexProvider';
2
- import type { FlatSelector } from './types/Selector';
3
- import type Selector from './types/Selector';
4
- import type { BaseItem } from './Collection/types';
1
+ import { AsynchronousQueryFunction, SynchronousQueryFunction } from './types/IndexProvider';
2
+ import { FlatSelector, default as Selector } from './types/Selector';
3
+ import { BaseItem } from './Collection/types';
5
4
  type IndexInfo<T extends BaseItem<I> = BaseItem, I = any> = {
6
5
  matched: boolean;
7
6
  ids: I[];
@@ -56,11 +56,20 @@ var Collection = class Collection extends require_EventEmitter.default {
56
56
  const execute = () => Collection.collections.reduce((memo, collection) => () => {
57
57
  return collection.batch(memo);
58
58
  }, callback)();
59
- const maybePromise = execute();
60
59
  const afterBatch = () => {
61
60
  Collection.batchOperationInProgress = false;
62
61
  };
63
- if (maybePromise && typeof maybePromise.then === "function") return maybePromise.then(() => afterBatch());
62
+ let maybePromise;
63
+ try {
64
+ maybePromise = execute();
65
+ } catch (error) {
66
+ afterBatch();
67
+ throw error;
68
+ }
69
+ if (maybePromise && typeof maybePromise.then === "function") return maybePromise.then(() => afterBatch(), (error) => {
70
+ afterBatch();
71
+ throw error;
72
+ });
64
73
  else afterBatch();
65
74
  }
66
75
  name;
@@ -318,13 +327,22 @@ var Collection = class Collection extends require_EventEmitter.default {
318
327
  batch(callback) {
319
328
  if (this.batchOperationInProgress) return callback();
320
329
  this.batchOperationInProgress = true;
321
- const maybePromise = callback();
322
330
  const afterBatch = () => {
323
331
  this.batchOperationInProgress = false;
324
332
  this.postBatchCallbacks.forEach((callback_) => callback_());
325
333
  this.postBatchCallbacks.clear();
326
334
  };
327
- if (maybePromise && typeof maybePromise.then === "function") return maybePromise.then(() => afterBatch());
335
+ let maybePromise;
336
+ try {
337
+ maybePromise = callback();
338
+ } catch (error) {
339
+ afterBatch();
340
+ throw error;
341
+ }
342
+ if (maybePromise && typeof maybePromise.then === "function") return maybePromise.then(() => afterBatch(), (error) => {
343
+ afterBatch();
344
+ throw error;
345
+ });
328
346
  else afterBatch();
329
347
  }
330
348
  onPostBatch(callback) {
package/dist/index25.mjs CHANGED
@@ -56,11 +56,20 @@ var Collection = class Collection extends EventEmitter {
56
56
  const execute = () => Collection.collections.reduce((memo, collection) => () => {
57
57
  return collection.batch(memo);
58
58
  }, callback)();
59
- const maybePromise = execute();
60
59
  const afterBatch = () => {
61
60
  Collection.batchOperationInProgress = false;
62
61
  };
63
- if (maybePromise && typeof maybePromise.then === "function") return maybePromise.then(() => afterBatch());
62
+ let maybePromise;
63
+ try {
64
+ maybePromise = execute();
65
+ } catch (error) {
66
+ afterBatch();
67
+ throw error;
68
+ }
69
+ if (maybePromise && typeof maybePromise.then === "function") return maybePromise.then(() => afterBatch(), (error) => {
70
+ afterBatch();
71
+ throw error;
72
+ });
64
73
  else afterBatch();
65
74
  }
66
75
  name;
@@ -318,13 +327,22 @@ var Collection = class Collection extends EventEmitter {
318
327
  batch(callback) {
319
328
  if (this.batchOperationInProgress) return callback();
320
329
  this.batchOperationInProgress = true;
321
- const maybePromise = callback();
322
330
  const afterBatch = () => {
323
331
  this.batchOperationInProgress = false;
324
332
  this.postBatchCallbacks.forEach((callback_) => callback_());
325
333
  this.postBatchCallbacks.clear();
326
334
  };
327
- if (maybePromise && typeof maybePromise.then === "function") return maybePromise.then(() => afterBatch());
335
+ let maybePromise;
336
+ try {
337
+ maybePromise = callback();
338
+ } catch (error) {
339
+ afterBatch();
340
+ throw error;
341
+ }
342
+ if (maybePromise && typeof maybePromise.then === "function") return maybePromise.then(() => afterBatch(), (error) => {
343
+ afterBatch();
344
+ throw error;
345
+ });
328
346
  else afterBatch();
329
347
  }
330
348
  onPostBatch(callback) {
@@ -1,5 +1,5 @@
1
- import type { BaseItem } from '../Collection';
2
- import type { FlatSelector } from './Selector';
1
+ import { BaseItem } from '../Collection';
2
+ import { FlatSelector } from './Selector';
3
3
  export type IndexResult<IdType> = {
4
4
  ids: IdType[];
5
5
  fields: string[];
@@ -1,4 +1,4 @@
1
- import type { DotNotation, GetType } from './Selector';
1
+ import { DotNotation, GetType } from './Selector';
2
2
  type Dictionary<T> = Record<string, T>;
3
3
  type PartialMapTo<T, M> = Partial<Record<DotNotation<T>, M>> & Dictionary<M>;
4
4
  type OnlyElementsOfArrays<T> = T extends any[] ? Partial<T[0]> : never;
@@ -1,4 +1,4 @@
1
- import type Dependency from './Dependency';
1
+ import { default as Dependency } from './Dependency';
2
2
  export default interface ReactivityAdapter<T extends Dependency = Dependency> {
3
3
  create(): T;
4
4
  onDispose?(callback: () => void, Dependency: T): void;
@@ -1,5 +1,5 @@
1
- import type ReactivityAdapter from '../types/ReactivityAdapter';
2
- import type Signal from '../types/Signal';
1
+ import { default as ReactivityAdapter } from '../types/ReactivityAdapter';
2
+ import { default as Signal } from '../types/Signal';
3
3
  /**
4
4
  * Creates a reactive signal for managing state and triggering dependencies.
5
5
  * The signal holds a value and provides methods to get and set the value,
@@ -1,5 +1,5 @@
1
- import type { BaseItem } from '../Collection/types';
2
- import type { FlatSelector } from '../types/Selector';
1
+ import { BaseItem } from '../Collection/types';
2
+ import { FlatSelector } from '../types/Selector';
3
3
  type KeyResult = {
4
4
  include: (string | null)[] | null;
5
5
  exclude: (string | null)[] | null;
@@ -1,4 +1,4 @@
1
- import type { FieldExpression } from '../types/Selector';
1
+ import { FieldExpression } from '../types/Selector';
2
2
  /**
3
3
  * Determines whether a given object is a valid field expression.
4
4
  * A field expression is an object containing query operators supported by MongoDB-style queries.
@@ -1,4 +1,4 @@
1
- import type Selector from '../types/Selector';
1
+ import { default as Selector } from '../types/Selector';
2
2
  type BaseItem = Record<string, any>;
3
3
  /**
4
4
  * Tests whether a given item matches a specified selector.
@@ -1,4 +1,4 @@
1
- import type Modifier from '../types/Modifier';
1
+ import { default as Modifier } from '../types/Modifier';
2
2
  /**
3
3
  * Applies a modifier to an object and returns a new modified object.
4
4
  * @template T - The type of the object to be modified.
@@ -1,5 +1,5 @@
1
- import type { QueryOptions } from '../DataAdapter';
2
- import type Selector from '../types/Selector';
1
+ import { QueryOptions } from '../DataAdapter';
2
+ import { default as Selector } from '../types/Selector';
3
3
  /**
4
4
  * Generates a unique identifier for a query based on its selector and options.
5
5
  * @param selector - The selector object.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signaldb/core",
3
- "version": "2.0.0-beta.7",
3
+ "version": "2.0.0-beta.9",
4
4
  "description": "SignalDB is a client-side database that provides a simple MongoDB-like interface to the data with first-class typescript support to achieve an optimistic UI. Data persistence can be achieved by using storage providers that store the data through a JSON interface to places such as localStorage.",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && vite build",