muya 2.3.0 → 2.3.2
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.
- package/cjs/index.js +1 -1
- package/esm/create-state.js +1 -1
- package/esm/sqlite/create-sqlite.js +1 -1
- package/esm/utils/id.js +1 -0
- package/package.json +1 -1
- package/src/create-state.ts +2 -11
- package/src/sqlite/__tests__/use-sqlite.test.tsx +10 -10
- package/src/sqlite/create-sqlite.ts +20 -31
- package/src/sqlite/select-sql.ts +2 -2
- package/src/sqlite/table/table.types.ts +2 -7
- package/src/types.ts +1 -1
- package/src/utils/id.ts +9 -0
- package/types/sqlite/select-sql.d.ts +2 -2
- package/types/sqlite/table/table.types.d.ts +2 -7
- package/types/types.d.ts +1 -1
- package/types/utils/id.d.ts +5 -0
package/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var V=Object.defineProperty;var
|
|
1
|
+
"use strict";var V=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var W=(e,r)=>{for(var o in r)V(e,o,{get:r[o],enumerable:!0})},J=(e,r,o,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of K(r))!Y.call(e,s)&&s!==o&&V(e,s,{get:()=>r[s],enumerable:!(i=N(r,s))||i.enumerable});return e};var Q=e=>J(V({},"__esModule",{value:!0}),e);var $={};W($,{EMPTY_SELECTOR:()=>v,create:()=>F,isAbortError:()=>I,isArray:()=>g,isEqualBase:()=>m,isError:()=>D,isFunction:()=>h,isMap:()=>x,isPromise:()=>f,isSet:()=>E,isSetValueFunction:()=>O,isState:()=>Z,isUndefined:()=>d,select:()=>P,shallow:()=>M,useValue:()=>C});module.exports=Q($);var p=class extends Error{static Error="AbortError"};function X(e,r){r&&r.abort();let o=new AbortController,{signal:i}=o;return{promise:new Promise((n,a)=>{i.addEventListener("abort",()=>{a(new p)}),e.then(n).catch(a)}),controller:o}}function y(e,r=m){if(!d(e.current)){if(!d(e.previous)&&r(e.current,e.previous))return!1;e.previous=e.current}return!0}function T(e,r){let{cache:o,emitter:{emit:i}}=e;if(!f(r))return r;o.abortController&&o.abortController.abort();let{promise:s,controller:n}=X(r,o.abortController);return o.abortController=n,s.then(a=>{o.current=a,i()}).catch(a=>{I(a)||(o.current=a,i())})}function f(e){return e instanceof Promise}function h(e){return typeof e=="function"}function x(e){return e instanceof Map}function E(e){return e instanceof Set}function g(e){return Array.isArray(e)}function m(e,r){return e===r?!0:!!Object.is(e,r)}function O(e){return typeof e=="function"}function I(e){return e instanceof p}function D(e){return e instanceof Error}function d(e){return e===void 0}function Z(e){return h(e)&&"get"in e&&"set"in e&&"isSet"in e&&e.isSet===!0}var v=e=>e;function U(){let e=new Map,r=new Set,o=performance.now(),i=!1;function s(){let a=performance.now(),t=a-o,{size:c}=r;if(t<.2&&c>0&&c<10){o=a,n();return}i||(i=!0,Promise.resolve().then(()=>{i=!1,o=performance.now(),n()}))}function n(){if(r.size===0)return;let a=new Set;for(let t of r){if(e.has(t.id)){a.add(t.id);let{onResolveItem:c}=e.get(t.id);c&&c(t.value)}r.delete(t)}if(r.size>0){s();return}for(let t of a)e.get(t)?.onScheduleDone()}return{add(a,t){return e.set(a,t),()=>{e.delete(a)}},schedule(a,t){r.add({value:t,id:a}),s()}}}function P(e,r,o){function i(){let u=!1,l=e.map(A=>{let w=A.get();return f(w)&&(u=!0),w});return u?new Promise((A,w)=>{Promise.all(l).then(G=>{if(G.some(_=>d(_)))return w(new p);let j=r(...G);A(j)})}):r(...l)}function s(){if(d(t.cache.current)){let u=i();t.cache.current=T(t,u)}return t.cache.current}function n(){if(d(t.cache.current)){let l=i();t.cache.current=T(t,l)}let{current:u}=t.cache;return f(u)?new Promise(l=>{u.then(S=>{if(d(S)){l(n());return}l(S)})}):t.cache.current}let a=[];for(let u of e){let l=u.emitter.subscribe(()=>{b.schedule(t.id,null)});a.push(l)}let t=k({destroy(){for(let u of a)u();c(),t.emitter.clear(),t.cache.current=void 0},get:n,getSnapshot:s}),c=b.add(t.id,{onScheduleDone(){let u=i();t.cache.current=T(t,u),y(t.cache,o)&&t.emitter.emit()}});return t}var R=require("react");var L=require("use-sync-external-store/shim/with-selector");function C(e,r=v){let{emitter:o}=e,i=(0,L.useSyncExternalStoreWithSelector)(e.emitter.subscribe,o.getSnapshot,o.getInitialSnapshot,r);if((0,R.useDebugValue)(i),f(i)||D(i))throw i;return i}function q(e,r){let o=new Set,i=[];return{clear:()=>{for(let s of i)s();o.clear()},subscribe:s=>(o.add(s),()=>{o.delete(s)}),emit:(...s)=>{for(let n of o)n(...s)},contains:s=>o.has(s),getSnapshot:e,getInitialSnapshot:r,getSize:()=>o.size,subscribeToOtherEmitter(s){let n=s.subscribe(()=>{this.emit()});i.push(n)}}}var H=0;function z(){return H++,H.toString(36)}function k(e){let{get:r,destroy:o,set:i,getSnapshot:s}=e,n=!!i,a={},t=function(c){return C(t,c)};return t.isSet=n,t.id=z(),t.emitter=q(s),t.destroy=o,t.listen=function(c){return this.emitter.subscribe(()=>{let u=r();f(u)||c(r())})},t.withName=function(c){return this.stateName=c,this},t.select=function(c,u=m){return P([t],c,u)},t.get=r,t.set=i,t.cache=a,t}var b=U();function F(e,r=m){function o(){try{if(d(n.cache.current)){let t=h(e)?e():e,c=T(n,t);return n.cache.current=c,n.cache.current}return n.cache.current}catch(t){n.cache.current=t}return n.cache.current}async function i(t,c){await t;let u=c(n.cache.current),l=T(n,u);n.cache.current=l}function s(t){let c=o(),u=O(t);if(u&&f(c)){i(c,t);return}n.cache.abortController&&n.cache.abortController.abort();let l=u?t(c):t,S=T(n,l);n.cache.current=S}let n=k({get:o,destroy(){o(),a(),n.emitter.clear(),n.cache.current=void 0},set(t){b.schedule(n.id,t)},getSnapshot:o}),a=b.add(n.id,{onScheduleDone(){n.cache.current=o(),y(n.cache,r)&&n.emitter.emit()},onResolveItem:s});return h(e)||o(),n}function M(e,r){if(e==r)return!0;if(typeof e!="object"||e==null||typeof r!="object"||r==null)return!1;if(x(e)&&x(r)){if(e.size!==r.size)return!1;for(let[s,n]of e)if(!Object.is(n,r.get(s)))return!1;return!0}if(E(e)&&E(r)){if(e.size!==r.size)return!1;for(let s of e)if(!r.has(s))return!1;return!0}if(g(e)&&g(r)){if(e.length!==r.length)return!1;for(let[s,n]of e.entries())if(!Object.is(n,r[s]))return!1;return!0}let o=Object.keys(e),i=Object.keys(r);if(o.length!==i.length)return!1;for(let s of o)if(!Object.prototype.hasOwnProperty.call(r,s)||!Object.is(e[s],r[s]))return!1;return!0}
|
package/esm/create-state.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{select as l}from"./select";import{useValue as
|
|
1
|
+
import{select as l}from"./select";import{useValue as m}from"./use-value";import{createEmitter as S}from"./utils/create-emitter";import{getId as T}from"./utils/id";import{isEqualBase as d,isPromise as p}from"./utils/is";function G(n){const{get:r,destroy:o,set:s,getSnapshot:i}=n,u=!!s,c={},t=function(e){return m(t,e)};return t.isSet=u,t.id=T(),t.emitter=S(i),t.destroy=o,t.listen=function(e){return this.emitter.subscribe(()=>{const a=r();p(a)||e(r())})},t.withName=function(e){return this.stateName=e,this},t.select=function(e,a=d){return l([t],e,a)},t.get=r,t.set=s,t.cache=c,t}export{G as createState};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{STATE_SCHEDULER as y}from"../create";import{getId as P}from"../utils/id";import{shallow as v}from"../utils/shallow";import{selectSql as O}from"./select-sql";import{createTable as R,DEFAULT_STEP_SIZE as M}from"./table/table";function K(g){const k=P();function m(e){return`state-${k}-search-${e}`}let h;async function o(){if(!h){const{backend:e,...n}=g,t=e instanceof Promise?await e:e;h=await R({backend:t,...n})}return h}const c=new Map,i=new Map,S=new Map;async function p(e,n){const t=S.get(e),{options:a={}}=n,{stepSize:s=M}=a;if(!t)return!1;const r=[];for(let u=0;u<s;u++){const l=await t.next();if(l.done){S.delete(e);break}n.keys.has(String(l.value.rowId))||(r.push(l.value.document),n.keys.add(String(l.value.rowId)))}return r.length===0||v(n.items,r)?!1:(n.items=[...n.items,...r],!0)}function b(e){const n=i.get(e);n&&n()}async function x(e){const n=await o(),t=c.get(e);if(!t)return;const{options:a}=t,s=n.search({...a,select:(r,{rowId:u})=>({document:r,rowId:u})});S.set(e,s),t.keys=new Set,t.items=[],await p(e,t)}async function f(e){await x(e),b(e)}function T(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 d(e){const n=new Set;for(const t of e){const a=T(t);for(const s of a)n.add(s)}for(const t of n){const a=m(t);y.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&&f(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 d([t]),t},async batchSet(e){const t=await(await o()).batchSet(e);return await d(t),t},async delete(e){const t=await(await o()).delete(e);return t&&await d([t]),t},async deleteBy(e){const t=await(await o()).deleteBy(e);return await d(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=m(e);y.schedule(a,{searchId:e})},subscribe(e,n){const t=m(e),a=y.add(t,{onScheduleDone(){f(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:f,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 O(I,e)}};return I}export{K as createSqliteState};
|
package/esm/utils/id.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let t=0;function e(){return t++,t.toString(36)}export{e as getId};
|
package/package.json
CHANGED
package/src/create-state.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { select } from './select'
|
|
|
2
2
|
import type { GetState, SetValue, State, Cache } from './types'
|
|
3
3
|
import { useValue } from './use-value'
|
|
4
4
|
import { createEmitter } from './utils/create-emitter'
|
|
5
|
+
import { getId } from './utils/id'
|
|
5
6
|
import { isEqualBase, isPromise } from './utils/is'
|
|
6
7
|
|
|
7
8
|
interface GetStateOptions<T> {
|
|
@@ -11,16 +12,6 @@ interface GetStateOptions<T> {
|
|
|
11
12
|
readonly getSnapshot: () => T
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
let stateId = 0
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Generate a unique state ID
|
|
18
|
-
* @returns A unique state ID
|
|
19
|
-
*/
|
|
20
|
-
function getStateId() {
|
|
21
|
-
return stateId++
|
|
22
|
-
}
|
|
23
|
-
|
|
24
15
|
type FullState<T> = GetStateOptions<T>['set'] extends undefined ? GetState<T> : State<T>
|
|
25
16
|
/**
|
|
26
17
|
* This is just utility function to create state base data
|
|
@@ -36,7 +27,7 @@ export function createState<T>(options: GetStateOptions<T>): FullState<T> {
|
|
|
36
27
|
return useValue(state, selector)
|
|
37
28
|
}
|
|
38
29
|
state.isSet = isSet as true
|
|
39
|
-
state.id =
|
|
30
|
+
state.id = getId()
|
|
40
31
|
state.emitter = createEmitter<T>(getSnapshot)
|
|
41
32
|
state.destroy = destroy
|
|
42
33
|
state.listen = function (listener) {
|
|
@@ -79,11 +79,11 @@ describe('use-sqlite-state', () => {
|
|
|
79
79
|
const { result } = renderHook(() => {
|
|
80
80
|
reRenders++
|
|
81
81
|
const [minAge, setMinAge] = useState(20)
|
|
82
|
-
return [useSqliteValue(sql, { where: { age: { gt: minAge } },
|
|
82
|
+
return [useSqliteValue(sql, { where: { age: { gt: minAge } }, sortBy: 'age' }, [minAge]), setMinAge] as const
|
|
83
83
|
})
|
|
84
84
|
|
|
85
85
|
await waitFor(() => {
|
|
86
|
-
expect(result.current[0][0].map((p) => p.name)).toEqual(['
|
|
86
|
+
expect(result.current[0][0].map((p) => p.name)).toEqual(['Bob', 'Alice', 'Carol'])
|
|
87
87
|
expect(reRenders).toBe(2)
|
|
88
88
|
})
|
|
89
89
|
|
|
@@ -132,17 +132,17 @@ describe('use-sqlite-state', () => {
|
|
|
132
132
|
{ id: '3', name: 'Carol', age: 40 },
|
|
133
133
|
])
|
|
134
134
|
const { result, rerender } = renderHook(
|
|
135
|
-
({ order, limit }) => useSqliteValue(sql, {
|
|
135
|
+
({ order, limit }) => useSqliteValue(sql, { sortBy: 'age', order, limit }, [order, limit]),
|
|
136
136
|
{ initialProps: { order: 'asc' as 'asc' | 'desc', limit: 2 } },
|
|
137
137
|
)
|
|
138
138
|
await waitFor(() => {
|
|
139
|
-
expect(result.current[0].map((p) => p.name)).toEqual(['
|
|
139
|
+
expect(result.current[0].map((p) => p.name)).toEqual(['Bob', 'Alice'])
|
|
140
140
|
})
|
|
141
141
|
act(() => {
|
|
142
142
|
rerender({ order: 'desc', limit: 2 })
|
|
143
143
|
})
|
|
144
144
|
await waitFor(() => {
|
|
145
|
-
expect(result.current[0].map((p) => p.name)).toEqual(['
|
|
145
|
+
expect(result.current[0].map((p) => p.name)).toEqual(['Carol', 'Alice'])
|
|
146
146
|
})
|
|
147
147
|
act(() => {
|
|
148
148
|
rerender({ order: 'desc', limit: 1 })
|
|
@@ -243,11 +243,11 @@ describe('use-sqlite-state', () => {
|
|
|
243
243
|
people.push({ id: index.toString(), name: `Person${index}`, age: 20 + (index % 50) })
|
|
244
244
|
}
|
|
245
245
|
await sql.batchSet(people)
|
|
246
|
-
const { result, rerender } = renderHook(({ order }) => useSqliteValue(sql, {
|
|
246
|
+
const { result, rerender } = renderHook(({ order }) => useSqliteValue(sql, { sortBy: 'age', order }, [order]), {
|
|
247
247
|
initialProps: { order: 'asc' as 'asc' | 'desc' },
|
|
248
248
|
})
|
|
249
249
|
await waitFor(() => {
|
|
250
|
-
expect(result.current[0][0].age).toBe(
|
|
250
|
+
expect(result.current[0][0].age).toBe(20)
|
|
251
251
|
})
|
|
252
252
|
act(() => {
|
|
253
253
|
rerender({ order: 'desc' })
|
|
@@ -268,14 +268,14 @@ describe('use-sqlite-state', () => {
|
|
|
268
268
|
useSqliteValue(
|
|
269
269
|
sql,
|
|
270
270
|
{
|
|
271
|
-
|
|
271
|
+
sortBy: 'age',
|
|
272
272
|
select: (d) => d.name,
|
|
273
273
|
},
|
|
274
274
|
[],
|
|
275
275
|
),
|
|
276
276
|
)
|
|
277
277
|
await waitFor(() => {
|
|
278
|
-
expect(result.current[0]).toEqual(['
|
|
278
|
+
expect(result.current[0]).toEqual(['Bob', 'Alice', 'Carol'])
|
|
279
279
|
})
|
|
280
280
|
})
|
|
281
281
|
it('should add 50 documents and then load with another hook', async () => {
|
|
@@ -286,7 +286,7 @@ describe('use-sqlite-state', () => {
|
|
|
286
286
|
return useSqliteValue(
|
|
287
287
|
sql,
|
|
288
288
|
{
|
|
289
|
-
|
|
289
|
+
sortBy: 'age',
|
|
290
290
|
order: 'desc',
|
|
291
291
|
},
|
|
292
292
|
[],
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* eslint-disable sonarjs/redundant-type-aliases */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { createScheduler } from '../scheduler'
|
|
2
|
+
import { STATE_SCHEDULER } from '../create'
|
|
3
|
+
import { getId } from '../utils/id'
|
|
5
4
|
import { shallow } from '../utils/shallow'
|
|
6
5
|
import { selectSql, type CreateState } from './select-sql'
|
|
7
6
|
import type { Backend } from './table'
|
|
@@ -10,16 +9,6 @@ import type { DbOptions, DocType, Key, MutationResult, SearchOptions, Table } fr
|
|
|
10
9
|
import type { Where } from './table/where'
|
|
11
10
|
|
|
12
11
|
type SearchId = string
|
|
13
|
-
const STATE_SCHEDULER = createScheduler()
|
|
14
|
-
|
|
15
|
-
let stateId = 0
|
|
16
|
-
/**
|
|
17
|
-
* Get a unique state ID
|
|
18
|
-
* @returns The unique state ID
|
|
19
|
-
*/
|
|
20
|
-
function getStateId() {
|
|
21
|
-
return stateId++
|
|
22
|
-
}
|
|
23
12
|
|
|
24
13
|
export interface CreateSqliteOptions<Document extends DocType> extends Omit<DbOptions<Document>, 'backend'> {
|
|
25
14
|
readonly backend: Backend | Promise<Backend>
|
|
@@ -60,7 +49,7 @@ interface DataItems<Document extends DocType> {
|
|
|
60
49
|
* @returns A SyncTable instance with methods to interact with the underlying Table and manage reactive searches
|
|
61
50
|
*/
|
|
62
51
|
export function createSqliteState<Document extends DocType>(options: CreateSqliteOptions<Document>): SyncTable<Document> {
|
|
63
|
-
const id =
|
|
52
|
+
const id = getId()
|
|
64
53
|
|
|
65
54
|
/**
|
|
66
55
|
* Get a unique schedule ID for a search ID
|
|
@@ -102,8 +91,8 @@ export function createSqliteState<Document extends DocType>(options: CreateSqlit
|
|
|
102
91
|
*/
|
|
103
92
|
async function next(searchId: SearchId, data: DataItems<Document>): Promise<boolean> {
|
|
104
93
|
const iterator = iterators.get(searchId)
|
|
105
|
-
const { options = {} } = data
|
|
106
|
-
const { stepSize = DEFAULT_STEP_SIZE } =
|
|
94
|
+
const { options: nextOptions = {} } = data
|
|
95
|
+
const { stepSize = DEFAULT_STEP_SIZE } = nextOptions
|
|
107
96
|
if (!iterator) return false
|
|
108
97
|
const newItems: Document[] = []
|
|
109
98
|
|
|
@@ -145,8 +134,8 @@ export function createSqliteState<Document extends DocType>(options: CreateSqlit
|
|
|
145
134
|
const table = await getTable()
|
|
146
135
|
const data = cachedData.get(searchId)
|
|
147
136
|
if (!data) return
|
|
148
|
-
const { options } = data
|
|
149
|
-
const iterator = table.search({ ...
|
|
137
|
+
const { options: refreshOptions } = data
|
|
138
|
+
const iterator = table.search({ ...refreshOptions, select: (document, { rowId }) => ({ document, rowId }) })
|
|
150
139
|
iterators.set(searchId, iterator)
|
|
151
140
|
data.keys = new Set()
|
|
152
141
|
data.items = []
|
|
@@ -214,19 +203,19 @@ export function createSqliteState<Document extends DocType>(options: CreateSqlit
|
|
|
214
203
|
/**
|
|
215
204
|
* Register data for a search ID
|
|
216
205
|
* @param searchId The search ID
|
|
217
|
-
* @param
|
|
206
|
+
* @param registerDataOptions Optional search options
|
|
218
207
|
* @returns The data items for the search ID
|
|
219
208
|
*/
|
|
220
|
-
function registerData(searchId: SearchId,
|
|
209
|
+
function registerData(searchId: SearchId, registerDataOptions?: SearchOptions<Document, unknown>) {
|
|
221
210
|
if (!cachedData.has(searchId)) {
|
|
222
|
-
cachedData.set(searchId, { items: [], options, keys: new Set() })
|
|
223
|
-
if (
|
|
211
|
+
cachedData.set(searchId, { items: [], options: registerDataOptions, keys: new Set() })
|
|
212
|
+
if (registerDataOptions) {
|
|
224
213
|
refresh(searchId)
|
|
225
214
|
}
|
|
226
215
|
}
|
|
227
216
|
const data = cachedData.get(searchId)!
|
|
228
|
-
if (
|
|
229
|
-
data.options =
|
|
217
|
+
if (registerDataOptions) {
|
|
218
|
+
data.options = registerDataOptions
|
|
230
219
|
}
|
|
231
220
|
return data
|
|
232
221
|
}
|
|
@@ -262,20 +251,20 @@ export function createSqliteState<Document extends DocType>(options: CreateSqlit
|
|
|
262
251
|
const table = await getTable()
|
|
263
252
|
return table.get(key, selector)
|
|
264
253
|
},
|
|
265
|
-
async *search(
|
|
254
|
+
async *search(searchOptions = {}) {
|
|
266
255
|
const table = await getTable()
|
|
267
|
-
for await (const item of table.search(
|
|
256
|
+
for await (const item of table.search(searchOptions)) {
|
|
268
257
|
yield item
|
|
269
258
|
}
|
|
270
259
|
},
|
|
271
|
-
async count(
|
|
260
|
+
async count(countOptions) {
|
|
272
261
|
const table = await getTable()
|
|
273
|
-
return await table.count(
|
|
262
|
+
return await table.count(countOptions)
|
|
274
263
|
},
|
|
275
264
|
|
|
276
|
-
updateSearchOptions(searchId,
|
|
277
|
-
const data = registerData(searchId,
|
|
278
|
-
data.options =
|
|
265
|
+
updateSearchOptions(searchId, updateSearchOptions) {
|
|
266
|
+
const data = registerData(searchId, updateSearchOptions)
|
|
267
|
+
data.options = updateSearchOptions
|
|
279
268
|
const scheduleId = getScheduleId(searchId)
|
|
280
269
|
STATE_SCHEDULER.schedule(scheduleId, { searchId })
|
|
281
270
|
},
|
package/src/sqlite/select-sql.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createState } from '../create-state'
|
|
2
2
|
import type { GetState } from '../types'
|
|
3
3
|
import type { SyncTable } from './create-sqlite'
|
|
4
|
-
import type { DocType } from './table/table.types'
|
|
4
|
+
import type { DocType, DotPath } from './table/table.types'
|
|
5
5
|
import type { Where } from './table/where'
|
|
6
6
|
|
|
7
7
|
export type CreateState<Document, Params extends unknown[]> = (...params: Params) => GetState<Document[]>
|
|
8
8
|
|
|
9
9
|
export interface SqlSeachOptions<Document extends DocType> {
|
|
10
|
-
readonly
|
|
10
|
+
readonly sortBy?: DotPath<Document>
|
|
11
11
|
readonly order?: 'asc' | 'desc'
|
|
12
12
|
readonly limit?: number
|
|
13
13
|
readonly offset?: number
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// table.types.ts
|
|
2
|
+
import type { SqlSeachOptions } from '../select-sql'
|
|
2
3
|
import type { Backend } from './backend'
|
|
3
4
|
import type { Where } from './where'
|
|
4
5
|
|
|
@@ -27,13 +28,7 @@ export interface DbOptions<Document extends DocType> {
|
|
|
27
28
|
readonly disablePragmaOptimization?: boolean
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
export interface SearchOptions<Document extends DocType, Selected = Document> {
|
|
31
|
-
readonly sortBy?: DotPath<Document>
|
|
32
|
-
readonly order?: 'asc' | 'desc'
|
|
33
|
-
readonly limit?: number
|
|
34
|
-
readonly offset?: number
|
|
35
|
-
readonly where?: Where<Document>
|
|
36
|
-
readonly stepSize?: number
|
|
31
|
+
export interface SearchOptions<Document extends DocType, Selected = Document> extends SqlSeachOptions<Document> {
|
|
37
32
|
readonly select?: (document: Document, meta: { rowId: number }) => Selected
|
|
38
33
|
}
|
|
39
34
|
|
package/src/types.ts
CHANGED
package/src/utils/id.ts
ADDED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { GetState } from '../types';
|
|
2
2
|
import type { SyncTable } from './create-sqlite';
|
|
3
|
-
import type { DocType } from './table/table.types';
|
|
3
|
+
import type { DocType, DotPath } from './table/table.types';
|
|
4
4
|
import type { Where } from './table/where';
|
|
5
5
|
export type CreateState<Document, Params extends unknown[]> = (...params: Params) => GetState<Document[]>;
|
|
6
6
|
export interface SqlSeachOptions<Document extends DocType> {
|
|
7
|
-
readonly
|
|
7
|
+
readonly sortBy?: DotPath<Document>;
|
|
8
8
|
readonly order?: 'asc' | 'desc';
|
|
9
9
|
readonly limit?: number;
|
|
10
10
|
readonly offset?: number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SqlSeachOptions } from '../select-sql';
|
|
1
2
|
import type { Backend } from './backend';
|
|
2
3
|
import type { Where } from './where';
|
|
3
4
|
export type DocType = {
|
|
@@ -16,13 +17,7 @@ export interface DbOptions<Document extends DocType> {
|
|
|
16
17
|
readonly key?: DotPath<Document>;
|
|
17
18
|
readonly disablePragmaOptimization?: boolean;
|
|
18
19
|
}
|
|
19
|
-
export interface SearchOptions<Document extends DocType, Selected = Document> {
|
|
20
|
-
readonly sortBy?: DotPath<Document>;
|
|
21
|
-
readonly order?: 'asc' | 'desc';
|
|
22
|
-
readonly limit?: number;
|
|
23
|
-
readonly offset?: number;
|
|
24
|
-
readonly where?: Where<Document>;
|
|
25
|
-
readonly stepSize?: number;
|
|
20
|
+
export interface SearchOptions<Document extends DocType, Selected = Document> extends SqlSeachOptions<Document> {
|
|
26
21
|
readonly select?: (document: Document, meta: {
|
|
27
22
|
rowId: number;
|
|
28
23
|
}) => Selected;
|
package/types/types.d.ts
CHANGED