muya 2.1.3 → 2.2.0

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 +1 @@
1
- import{createScheduler as k}from"../scheduler";import{shallow as R}from"../utils/shallow";import{selectSql as v}from"./select-sql";import{createTable as M,DEFAULT_STEP_SIZE as O}from"./table/table";const f=k();let C=0;function E(){return C++}function B(g){const x=E();function l(e){return`state-${x}-search-${e}`}let m;async function o(){return m||(m=await M(g)),m}const c=new Map,i=new Map,h=new Map;async function p(e,n){const t=h.get(e),{options:a={}}=n,{stepSize:s=O}=a;if(!t)return!1;const r=[];for(let d=0;d<s;d++){const y=await t.next();if(y.done){h.delete(e);break}r.push(y.value.document),n.keys.add(String(y.value.rowId))}return r.length===0||R(n.items,r)?!1:(n.items=[...n.items,...r],!0)}function b(e){const n=i.get(e);n&&n()}async function T(e){const n=await o(),t=c.get(e);if(!t)return;const{options:a}=t,s=n.search({...a,select:(r,{rowId:d})=>({document:r,rowId:d})});h.set(e,s),t.keys=new Set,t.items=[],await p(e,t)}async function S(e){await T(e),b(e)}function P(e){const{key:n,op:t}=e,a=new Set;for(const[s,{keys:r}]of c)switch(t){case"delete":case"update":{r.has(String(n))&&a.add(s);break}case"insert":{a.add(s);break}}return a}async function u(e){const n=new Set;for(const t of e){const a=P(t);for(const s of a)n.add(s)}for(const t of n){const a=l(t);f.schedule(a,{searchId:t})}}const w=new Set;function D(e,n){c.has(e)||(c.set(e,{items:[],options:n,keys:new Set}),n&&S(e));const t=c.get(e);return n&&(t.options=n),t}const I={async set(e){const t=await(await o()).set(e);return await u([t]),t},async batchSet(e){const t=await(await o()).batchSet(e);return await u(t),t},async delete(e){const t=await(await o()).delete(e);return t&&await u([t]),t},async deleteBy(e){const t=await(await o()).deleteBy(e);return await u(t),t},async get(e,n){return(await o()).get(e,n)},async*search(e={}){const n=await o();for await(const t of n.search(e))yield t},async count(e){return await(await o()).count(e)},updateSearchOptions(e,n){const t=D(e,n);t.options=n;const a=l(e);f.schedule(a,{searchId:e})},subscribe(e,n){const t=l(e),a=f.add(t,{onScheduleDone(){S(e)}});return w.add(a),i.has(e)||i.set(e,n),()=>{i.delete(e),a(),c.delete(e)}},getSnapshot(e){return D(e).items},refresh:S,destroy(){for(const e of w)e();c.clear(),i.clear()},async next(e){const n=c.get(e);if(n){const t=await p(e,n);return t&&b(e),t}return!1},select(e){return v(I,e)}};return I}export{B as createSqliteState};
1
+ import{createScheduler as P}from"../scheduler";import{shallow as R}from"../utils/shallow";import{selectSql as M}from"./select-sql";import{createTable as O,DEFAULT_STEP_SIZE as v}from"./table/table";const f=P();let C=0;function E(){return C++}function N(g){const T=E();function l(e){return`state-${T}-search-${e}`}let m;async function o(){return m||(m=await O(g)),m}const c=new Map,i=new Map,h=new Map;async function p(e,n){const t=h.get(e),{options:a={}}=n,{stepSize:s=v}=a;if(!t)return!1;const r=[];for(let d=0;d<s;d++){const y=await t.next();if(y.done){h.delete(e);break}r.push(y.value.document),n.keys.add(String(y.value.rowId))}return r.length===0||R(n.items,r)?!1:(n.items=[...n.items,...r],!0)}function b(e){const n=i.get(e);n&&n()}async function k(e){const n=await o(),t=c.get(e);if(!t)return;const{options:a}=t,s=n.search({...a,select:(r,{rowId:d})=>({document:r,rowId:d})});h.set(e,s),t.keys=new Set,t.items=[],await p(e,t)}async function S(e){await k(e),b(e)}function x(e){const{key:n,op:t}=e,a=new Set;for(const[s,{keys:r}]of c)switch(t){case"delete":case"update":{r.has(String(n))&&a.add(s);break}case"insert":{a.add(s);break}}return a}async function u(e){const n=new Set;for(const t of e){const a=x(t);for(const s of a)n.add(s)}for(const t of n){const a=l(t);f.schedule(a,{searchId:t})}}const w=new Set;function D(e,n){c.has(e)||(c.set(e,{items:[],options:n,keys:new Set}),n&&S(e));const t=c.get(e);return n&&(t.options=n),t}const I={async set(e){const t=await(await o()).set(e);return await u([t]),t},async batchSet(e){const t=await(await o()).batchSet(e);return await u(t),t},async delete(e){const t=await(await o()).delete(e);return t&&await u([t]),t},async deleteBy(e){const t=await(await o()).deleteBy(e);return await u(t),t},async get(e,n){return(await o()).get(e,n)},async*search(e={}){const n=await o();for await(const t of n.search(e))yield t},async count(e){return await(await o()).count(e)},updateSearchOptions(e,n){const t=D(e,n);t.options=n;const a=l(e);f.schedule(a,{searchId:e})},subscribe(e,n){const t=l(e),a=f.add(t,{onScheduleDone(){S(e)}});return w.add(a),i.has(e)||i.set(e,n),()=>{i.delete(e),a(),c.delete(e)}},getSnapshot(e){return D(e).items},refresh:S,destroy(){for(const e of w)e();c.clear(),i.clear()},async next(e){const n=c.get(e);if(n){const t=await p(e,n);return t&&b(e),t}return!1},select(e){return M(I,e)}};return I}export{N as createSqliteState};
@@ -0,0 +1 @@
1
+ export*from"./create-sqlite";export*from"./table";export*from"./select-sql";export*from"./use-sqlite";
@@ -0,0 +1 @@
1
+ export*from"./backend";export*from"./table.types";export*from"./where";export*from"./table";export*from"./map-deque";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muya",
3
- "version": "2.1.3",
3
+ "version": "2.2.0",
4
4
  "author": "samuel.gjabel@gmail.com",
5
5
  "repository": "https://github.com/samuelgjabel/muya",
6
6
  "main": "cjs/index.js",
@@ -16,10 +16,6 @@ function getStateId() {
16
16
  return stateId++
17
17
  }
18
18
 
19
- export interface SqLiteActions {
20
- readonly next: () => Promise<boolean>
21
- readonly reset: () => Promise<void>
22
- }
23
19
  export interface SyncTable<Document extends DocType> {
24
20
  // readonly registerSearch: <Selected = Document>(searchId: SearchId, options: SearchOptions<Document, Selected>) => () => void
25
21
  readonly updateSearchOptions: <Selected = Document>(searchId: SearchId, options: SearchOptions<Document, Selected>) => void
@@ -0,0 +1,4 @@
1
+ export * from './create-sqlite'
2
+ export * from './table'
3
+ export * from './select-sql'
4
+ export * from './use-sqlite'
@@ -0,0 +1,5 @@
1
+ export * from './backend'
2
+ export * from './table.types'
3
+ export * from './where'
4
+ export * from './table'
5
+ export * from './map-deque'
@@ -2,10 +2,6 @@ import { type CreateState } from './select-sql';
2
2
  import type { DbOptions, DocType, Key, MutationResult, SearchOptions } from './table/table.types';
3
3
  import type { Where } from './table/where';
4
4
  type SearchId = string;
5
- export interface SqLiteActions {
6
- readonly next: () => Promise<boolean>;
7
- readonly reset: () => Promise<void>;
8
- }
9
5
  export interface SyncTable<Document extends DocType> {
10
6
  readonly updateSearchOptions: <Selected = Document>(searchId: SearchId, options: SearchOptions<Document, Selected>) => void;
11
7
  readonly subscribe: (searchId: SearchId, listener: () => void) => () => void;
@@ -0,0 +1,4 @@
1
+ export * from './create-sqlite';
2
+ export * from './table';
3
+ export * from './select-sql';
4
+ export * from './use-sqlite';
@@ -0,0 +1,5 @@
1
+ export * from './backend';
2
+ export * from './table.types';
3
+ export * from './where';
4
+ export * from './table';
5
+ export * from './map-deque';