@terreno/syncdb 57.9.0 → 57.11.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.
- package/dist/client.d.ts +20 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +53 -1
- package/dist/client.js.map +1 -1
- package/dist/codegen/emitSdk.d.ts.map +1 -1
- package/dist/codegen/emitSdk.js +2 -0
- package/dist/codegen/emitSdk.js.map +1 -1
- package/dist/codegen/generate.test.js +2 -0
- package/dist/codegen/generate.test.js.map +1 -1
- package/dist/codegen/hookNames.d.ts +2 -1
- package/dist/codegen/hookNames.d.ts.map +1 -1
- package/dist/codegen/hookNames.js +2 -1
- package/dist/codegen/hookNames.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/query/localQuery.d.ts +22 -0
- package/dist/query/localQuery.d.ts.map +1 -0
- package/dist/query/localQuery.js +38 -0
- package/dist/query/localQuery.js.map +1 -0
- package/dist/query/queryWindows.d.ts +128 -0
- package/dist/query/queryWindows.d.ts.map +1 -0
- package/dist/query/queryWindows.edge.test.d.ts +2 -0
- package/dist/query/queryWindows.edge.test.d.ts.map +1 -0
- package/dist/query/queryWindows.edge.test.js +196 -0
- package/dist/query/queryWindows.edge.test.js.map +1 -0
- package/dist/query/queryWindows.js +621 -0
- package/dist/query/queryWindows.js.map +1 -0
- package/dist/query/queryWindows.test.d.ts +2 -0
- package/dist/query/queryWindows.test.d.ts.map +1 -0
- package/dist/query/queryWindows.test.js +565 -0
- package/dist/query/queryWindows.test.js.map +1 -0
- package/dist/query/rangePlan.d.ts +23 -0
- package/dist/query/rangePlan.d.ts.map +1 -0
- package/dist/query/rangePlan.js +20 -0
- package/dist/query/rangePlan.js.map +1 -0
- package/dist/query/sort.d.ts +13 -0
- package/dist/query/sort.d.ts.map +1 -0
- package/dist/query/sort.js +84 -0
- package/dist/query/sort.js.map +1 -0
- package/dist/query/where.d.ts +41 -0
- package/dist/query/where.d.ts.map +1 -0
- package/dist/query/where.js +243 -0
- package/dist/query/where.js.map +1 -0
- package/dist/query/where.test.d.ts +2 -0
- package/dist/query/where.test.d.ts.map +1 -0
- package/dist/query/where.test.js +130 -0
- package/dist/query/where.test.js.map +1 -0
- package/dist/react/collectionHooks.d.ts +6 -1
- package/dist/react/collectionHooks.d.ts.map +1 -1
- package/dist/react/collectionHooks.js +3 -1
- package/dist/react/collectionHooks.js.map +1 -1
- package/dist/react/hooks.d.ts +66 -2
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/hooks.js +91 -24
- package/dist/react/hooks.js.map +1 -1
- package/dist/react/windowHooks.test.d.ts +2 -0
- package/dist/react/windowHooks.test.d.ts.map +1 -0
- package/dist/react/windowHooks.test.js +132 -0
- package/dist/react/windowHooks.test.js.map +1 -0
- package/dist/storage/schema.d.ts.map +1 -1
- package/dist/storage/schema.js +13 -1
- package/dist/storage/schema.js.map +1 -1
- package/dist/storage/types.d.ts +5 -0
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/storage/types.js +5 -0
- package/dist/storage/types.js.map +1 -1
- package/dist/sync/httpChannel.d.ts +40 -1
- package/dist/sync/httpChannel.d.ts.map +1 -1
- package/dist/sync/httpChannel.js +89 -0
- package/dist/sync/httpChannel.js.map +1 -1
- package/dist/sync/httpChannel.test.js +45 -1
- package/dist/sync/httpChannel.test.js.map +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +70 -1
- package/src/codegen/emitSdk.ts +2 -0
- package/src/codegen/generate.test.ts +2 -0
- package/src/codegen/hookNames.ts +3 -1
- package/src/index.ts +18 -0
- package/src/query/localQuery.ts +60 -0
- package/src/query/queryWindows.edge.test.ts +250 -0
- package/src/query/queryWindows.test.ts +665 -0
- package/src/query/queryWindows.ts +848 -0
- package/src/query/rangePlan.ts +39 -0
- package/src/query/sort.ts +101 -0
- package/src/query/where.test.ts +155 -0
- package/src/query/where.ts +290 -0
- package/src/react/collectionHooks.ts +16 -2
- package/src/react/hooks.ts +184 -26
- package/src/react/windowHooks.test.tsx +172 -0
- package/src/storage/schema.ts +13 -0
- package/src/storage/types.ts +6 -0
- package/src/sync/httpChannel.test.ts +65 -1
- package/src/sync/httpChannel.ts +142 -0
- package/src/types.ts +11 -0
package/src/index.ts
CHANGED
|
@@ -65,6 +65,21 @@ export type {
|
|
|
65
65
|
SyncSubscribed,
|
|
66
66
|
} from "./types";
|
|
67
67
|
|
|
68
|
+
// --- Queries and server windows ------------------------------------------
|
|
69
|
+
// `where`/`sort` share one syntax across local `useQuery`, server windows
|
|
70
|
+
// (`client.queryWindows` / `useWindowQuery`), and `modelRouter` list params.
|
|
71
|
+
|
|
72
|
+
export type {QuerySort} from "./query/localQuery";
|
|
73
|
+
export {
|
|
74
|
+
DEFAULT_WINDOW_PAGE_SIZE,
|
|
75
|
+
type QueryWindowState,
|
|
76
|
+
type QueryWindows,
|
|
77
|
+
type WindowFetchStatus,
|
|
78
|
+
type WindowQuery,
|
|
79
|
+
} from "./query/queryWindows";
|
|
80
|
+
export type {SortDirection, SortSpec} from "./query/sort";
|
|
81
|
+
export {compileWhere, type WhereFilter, type WhereOperators} from "./query/where";
|
|
82
|
+
|
|
68
83
|
// --- Local store and outbox (read surface) -------------------------------
|
|
69
84
|
// `client.store` is typed as SyncStore and `client.outbox` as Outbox;
|
|
70
85
|
// OUTBOX_TABLE names the table to pass to `client.store.raw.getTable(...)` when
|
|
@@ -135,6 +150,8 @@ export {
|
|
|
135
150
|
type FetchSnapshotPageArgs,
|
|
136
151
|
type HttpChannel,
|
|
137
152
|
type HttpChannelConfig,
|
|
153
|
+
ListRequestError,
|
|
154
|
+
QueryFieldNotAllowedError,
|
|
138
155
|
} from "./sync/httpChannel";
|
|
139
156
|
export {createSocketTransport, type SocketTransportConfig} from "./sync/socketTransport";
|
|
140
157
|
export {
|
|
@@ -145,6 +162,7 @@ export {
|
|
|
145
162
|
type SyncTransport,
|
|
146
163
|
type TransportStatus,
|
|
147
164
|
} from "./sync/transport";
|
|
165
|
+
export type {ListResponse} from "./types";
|
|
148
166
|
|
|
149
167
|
// --- Debug log ------------------------------------------------------------
|
|
150
168
|
// Enabled with `SyncDbConfig.debug`, read through `client.debug` or the React
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type {SyncEntity} from "../storage/types";
|
|
2
|
+
import {compileSort, type SortSpec} from "./sort";
|
|
3
|
+
import {compileWhere, type WhereFilter} from "./where";
|
|
4
|
+
|
|
5
|
+
/** A comparator, or a `modelRouter`-style sort spec (`"-created"`, `{created: "descending"}`). */
|
|
6
|
+
export type QuerySort<TData> = SortSpec | ((a: TData, b: TData) => number);
|
|
7
|
+
|
|
8
|
+
export const resolveComparator = <TData>(
|
|
9
|
+
sort: QuerySort<TData> | undefined
|
|
10
|
+
): ((a: TData, b: TData) => number) | undefined => {
|
|
11
|
+
if (sort === undefined) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
if (typeof sort === "function") {
|
|
15
|
+
return sort;
|
|
16
|
+
}
|
|
17
|
+
return compileSort<TData>(sort);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export interface LocalQueryOptions<TData> {
|
|
21
|
+
/** Mongo-style filter evaluated against decoded data. */
|
|
22
|
+
where?: WhereFilter;
|
|
23
|
+
/** Arbitrary predicate, applied after `where`. */
|
|
24
|
+
filter?: (data: TData) => boolean;
|
|
25
|
+
sort?: QuerySort<TData>;
|
|
26
|
+
/** Keep only the first N results (after sort). */
|
|
27
|
+
limit?: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Filter/sort/limit entities that are already in the local store. Used by
|
|
32
|
+
* `useQuery`/`useEntityIds` for fully-synced collections. A `where` that cannot be
|
|
33
|
+
* evaluated locally (e.g. `$search`) throws — only server windows can run it.
|
|
34
|
+
*/
|
|
35
|
+
export const applyLocalQuery = <TData>(
|
|
36
|
+
entities: SyncEntity<TData>[],
|
|
37
|
+
{where, filter, sort, limit}: LocalQueryOptions<TData>
|
|
38
|
+
): SyncEntity<TData>[] => {
|
|
39
|
+
let results = entities.filter((entity) => entity.data !== null);
|
|
40
|
+
if (where) {
|
|
41
|
+
const {match} = compileWhere(where);
|
|
42
|
+
if (!match) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
"useQuery `where` uses an operator syncdb cannot evaluate locally; use useWindowQuery"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
results = results.filter((entity) => match(entity.data));
|
|
48
|
+
}
|
|
49
|
+
if (filter) {
|
|
50
|
+
results = results.filter((entity) => filter(entity.data));
|
|
51
|
+
}
|
|
52
|
+
const comparator = resolveComparator(sort);
|
|
53
|
+
if (comparator) {
|
|
54
|
+
results = [...results].sort((a, b) => comparator(a.data, b.data));
|
|
55
|
+
}
|
|
56
|
+
if (limit !== undefined && limit >= 0) {
|
|
57
|
+
results = results.slice(0, limit);
|
|
58
|
+
}
|
|
59
|
+
return results;
|
|
60
|
+
};
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {createSyncStore} from "../storage/store";
|
|
4
|
+
import {QUERY_WINDOWS_TABLE} from "../storage/types";
|
|
5
|
+
import type {ListResponse, SyncEntitiesResponse} from "../types";
|
|
6
|
+
import {
|
|
7
|
+
createQueryWindows,
|
|
8
|
+
type QueryWindows,
|
|
9
|
+
selectWindowView,
|
|
10
|
+
type WindowQuery,
|
|
11
|
+
windowKeyFor,
|
|
12
|
+
} from "./queryWindows";
|
|
13
|
+
|
|
14
|
+
interface Row {
|
|
15
|
+
_id?: string | number;
|
|
16
|
+
id?: string;
|
|
17
|
+
_syncSeq?: number;
|
|
18
|
+
rank?: number;
|
|
19
|
+
group?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const COLLECTION = "items";
|
|
23
|
+
|
|
24
|
+
const makeWindows = ({
|
|
25
|
+
respond,
|
|
26
|
+
entities = async (): Promise<SyncEntitiesResponse> => ({entities: []}),
|
|
27
|
+
hasFetchList = true,
|
|
28
|
+
onError,
|
|
29
|
+
epoch = (): string => "e1",
|
|
30
|
+
}: {
|
|
31
|
+
respond?: (params: Record<string, unknown>) => ListResponse | Promise<ListResponse>;
|
|
32
|
+
entities?: (ids: string[]) => Promise<SyncEntitiesResponse>;
|
|
33
|
+
hasFetchList?: boolean;
|
|
34
|
+
onError?: (error: unknown) => void;
|
|
35
|
+
epoch?: () => string;
|
|
36
|
+
} = {}): {
|
|
37
|
+
windows: QueryWindows;
|
|
38
|
+
store: ReturnType<typeof createSyncStore>;
|
|
39
|
+
calls: Array<Record<string, unknown>>;
|
|
40
|
+
} => {
|
|
41
|
+
const store = createSyncStore({collections: [COLLECTION]});
|
|
42
|
+
const calls: Array<Record<string, unknown>> = [];
|
|
43
|
+
const windows = createQueryWindows({
|
|
44
|
+
getChannel: () => ({
|
|
45
|
+
fetchEntities: ({ids}) => entities(ids),
|
|
46
|
+
...(hasFetchList
|
|
47
|
+
? {
|
|
48
|
+
fetchList: async ({params}): Promise<ListResponse> => {
|
|
49
|
+
calls.push(params);
|
|
50
|
+
return (await respond?.(params)) ?? {data: [], more: false};
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
: {}),
|
|
54
|
+
}),
|
|
55
|
+
getEpoch: epoch,
|
|
56
|
+
getListPath: () => "/items",
|
|
57
|
+
now: () => "2026-10-04T00:00:00.000Z",
|
|
58
|
+
onError,
|
|
59
|
+
store,
|
|
60
|
+
});
|
|
61
|
+
return {calls, store, windows};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
describe("query windows edge cases", () => {
|
|
65
|
+
it("skips rows without an id and stringifies numeric ids", async () => {
|
|
66
|
+
const {windows} = makeWindows({
|
|
67
|
+
respond: () => ({
|
|
68
|
+
data: [{rank: 1}, {_id: 7, _syncSeq: 1}, {_syncSeq: 1, id: "x"}],
|
|
69
|
+
more: false,
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
72
|
+
const state = await windows.fetchWindow({query: {collection: COLLECTION}});
|
|
73
|
+
expect(state.ids).toEqual(["7", "x"]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("does not request a next page when the window has no more", async () => {
|
|
77
|
+
const {calls, windows} = makeWindows({
|
|
78
|
+
respond: () => ({data: [{_id: "a", _syncSeq: 1}], more: false}),
|
|
79
|
+
});
|
|
80
|
+
const query: WindowQuery = {collection: COLLECTION};
|
|
81
|
+
await windows.fetchWindow({query});
|
|
82
|
+
const state = await windows.fetchWindow({nextPage: true, query});
|
|
83
|
+
expect(calls).toHaveLength(1);
|
|
84
|
+
expect(state.ids).toEqual(["a"]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("rejects when the channel cannot fetch lists", async () => {
|
|
88
|
+
const {windows} = makeWindows({hasFetchList: false});
|
|
89
|
+
await expect(windows.fetchWindow({query: {collection: COLLECTION}})).rejects.toThrow(
|
|
90
|
+
/require an HTTP channel/
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("keeps optimistic rows while canonical seqs load", async () => {
|
|
95
|
+
const {store, windows} = makeWindows({
|
|
96
|
+
entities: async () => ({
|
|
97
|
+
entities: [{data: {_id: "a", rank: 9}, deleted: false, id: "a", seq: 4}],
|
|
98
|
+
}),
|
|
99
|
+
respond: () => ({data: [{_id: "a", rank: 1}], more: false}),
|
|
100
|
+
});
|
|
101
|
+
store.upsertEntity({
|
|
102
|
+
collection: COLLECTION,
|
|
103
|
+
data: {_id: "a", rank: 5},
|
|
104
|
+
id: "a",
|
|
105
|
+
pendingMutationId: "m1",
|
|
106
|
+
});
|
|
107
|
+
await windows.fetchWindow({query: {collection: COLLECTION}});
|
|
108
|
+
expect(store.getEntity<Row>({collection: COLLECTION, id: "a"})?.data.rank).toBe(5);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("stops applying canonical seqs once the lifecycle moves on", async () => {
|
|
112
|
+
let epoch = "e1";
|
|
113
|
+
const {store, windows} = makeWindows({
|
|
114
|
+
entities: async () => {
|
|
115
|
+
epoch = "e2";
|
|
116
|
+
return {entities: [{data: {_id: "a"}, deleted: false, id: "a", seq: 4}]};
|
|
117
|
+
},
|
|
118
|
+
epoch: () => epoch,
|
|
119
|
+
respond: () => ({data: [{_id: "a"}], more: false}),
|
|
120
|
+
});
|
|
121
|
+
await windows.fetchWindow({query: {collection: COLLECTION}});
|
|
122
|
+
expect(store.getEntity({collection: COLLECTION, id: "a"})?.seq).toBe(0);
|
|
123
|
+
expect(store.raw.getTable(QUERY_WINDOWS_TABLE)).toEqual({});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("reports refetch failures through onError and keeps going", async () => {
|
|
127
|
+
const errors: unknown[] = [];
|
|
128
|
+
const {windows} = makeWindows({
|
|
129
|
+
onError: (error) => errors.push(error),
|
|
130
|
+
respond: () => {
|
|
131
|
+
throw new Error("boom");
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
const release = windows.retain({collection: COLLECTION});
|
|
135
|
+
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
136
|
+
await windows.refetchRetained();
|
|
137
|
+
expect(errors.length).toBeGreaterThanOrEqual(2);
|
|
138
|
+
release();
|
|
139
|
+
release();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("notifies subscribers until they unsubscribe", async () => {
|
|
143
|
+
const {windows} = makeWindows({respond: () => ({data: [], more: false})});
|
|
144
|
+
let calls = 0;
|
|
145
|
+
const unsubscribe = windows.subscribe(() => {
|
|
146
|
+
calls += 1;
|
|
147
|
+
});
|
|
148
|
+
await windows.fetchWindow({query: {collection: COLLECTION}});
|
|
149
|
+
const seen = calls;
|
|
150
|
+
expect(seen).toBeGreaterThan(0);
|
|
151
|
+
unsubscribe();
|
|
152
|
+
await windows.fetchWindow({query: {collection: COLLECTION, pageSize: 5}});
|
|
153
|
+
expect(calls).toBe(seen);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("prunes every unretained window on demand", async () => {
|
|
157
|
+
const {windows} = makeWindows({respond: () => ({data: [], more: false})});
|
|
158
|
+
await windows.fetchWindow({query: {collection: COLLECTION}});
|
|
159
|
+
const release = windows.retain({collection: COLLECTION, pageSize: 3});
|
|
160
|
+
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
161
|
+
expect(windows.pruneUnretained()).toBe(1);
|
|
162
|
+
expect(windows.getWindow({collection: COLLECTION, pageSize: 3})).toBeDefined();
|
|
163
|
+
release();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("treats corrupt persisted membership as empty", () => {
|
|
167
|
+
const {store, windows} = makeWindows();
|
|
168
|
+
const query: WindowQuery = {collection: COLLECTION};
|
|
169
|
+
store.raw.setRow(QUERY_WINDOWS_TABLE, windows.keyFor(query), {
|
|
170
|
+
collection: COLLECTION,
|
|
171
|
+
excluded: "[1]",
|
|
172
|
+
fetchedAt: "",
|
|
173
|
+
hasMore: false,
|
|
174
|
+
ids: "{not json",
|
|
175
|
+
pages: 1,
|
|
176
|
+
total: -1,
|
|
177
|
+
});
|
|
178
|
+
expect(windows.getWindow(query)).toMatchObject({excludedSeqs: {}, ids: [], total: undefined});
|
|
179
|
+
store.raw.setCell(QUERY_WINDOWS_TABLE, windows.keyFor(query), "excluded", "{not json");
|
|
180
|
+
store.raw.setCell(QUERY_WINDOWS_TABLE, windows.keyFor(query), "ids", "");
|
|
181
|
+
expect(windows.getWindow(query)).toMatchObject({excludedSeqs: {}, ids: []});
|
|
182
|
+
store.raw.setCell(QUERY_WINDOWS_TABLE, windows.keyFor(query), "excluded", '{"a":1,"b":"x"}');
|
|
183
|
+
expect(windows.getWindow(query)?.excludedSeqs).toEqual({a: 1});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("keys windows by value, including dates", () => {
|
|
187
|
+
const base = {collection: COLLECTION, where: {created: {$gte: new Date(0)}}};
|
|
188
|
+
expect(windowKeyFor(base)).toBe(
|
|
189
|
+
windowKeyFor({...base, sort: undefined, where: {created: {$gte: new Date(0)}}})
|
|
190
|
+
);
|
|
191
|
+
expect(windowKeyFor(base)).toContain("1970-01-01T00:00:00.000Z");
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe("selectWindowView edge cases", () => {
|
|
196
|
+
const seed = (
|
|
197
|
+
store: ReturnType<typeof createSyncStore>,
|
|
198
|
+
rows: Array<{id: string; rank: number; group: string; pending?: string}>
|
|
199
|
+
): void => {
|
|
200
|
+
for (const row of rows) {
|
|
201
|
+
store.upsertEntity({
|
|
202
|
+
collection: COLLECTION,
|
|
203
|
+
data: {group: row.group, rank: row.rank},
|
|
204
|
+
id: row.id,
|
|
205
|
+
pendingMutationId: row.pending ?? "",
|
|
206
|
+
seq: 1,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const windowState = (ids: string[], hasMore: boolean) => ({
|
|
212
|
+
collection: COLLECTION,
|
|
213
|
+
excludedSeqs: {},
|
|
214
|
+
hasMore,
|
|
215
|
+
ids,
|
|
216
|
+
key: "k",
|
|
217
|
+
pages: 1,
|
|
218
|
+
status: "idle" as const,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("admits only local creates when more pages exist and there is no sort", () => {
|
|
222
|
+
const store = createSyncStore({collections: [COLLECTION]});
|
|
223
|
+
seed(store, [
|
|
224
|
+
{group: "g", id: "a", rank: 1},
|
|
225
|
+
{group: "g", id: "b", rank: 2},
|
|
226
|
+
{group: "g", id: "c", pending: "m1", rank: 3},
|
|
227
|
+
]);
|
|
228
|
+
const view = selectWindowView<Row>({
|
|
229
|
+
query: {collection: COLLECTION, where: {group: "g"}},
|
|
230
|
+
store,
|
|
231
|
+
window: windowState(["a"], true),
|
|
232
|
+
});
|
|
233
|
+
expect(view.map((entity) => entity.id)).toEqual(["a", "c"]);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("orders equal sort keys by server membership", () => {
|
|
237
|
+
const store = createSyncStore({collections: [COLLECTION]});
|
|
238
|
+
seed(store, [
|
|
239
|
+
{group: "g", id: "b", rank: 1},
|
|
240
|
+
{group: "g", id: "a", rank: 1},
|
|
241
|
+
{group: "g", id: "z", rank: 1},
|
|
242
|
+
]);
|
|
243
|
+
const view = selectWindowView<Row>({
|
|
244
|
+
query: {collection: COLLECTION, sort: "rank", where: {group: "g"}},
|
|
245
|
+
store,
|
|
246
|
+
window: windowState(["b", "a"], false),
|
|
247
|
+
});
|
|
248
|
+
expect(view.map((entity) => entity.id)).toEqual(["b", "a", "z"]);
|
|
249
|
+
});
|
|
250
|
+
});
|