@tanstack/db 0.5.0 → 0.5.1
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.
|
@@ -2,26 +2,29 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const asyncQueuer = require("@tanstack/pacer/async-queuer");
|
|
4
4
|
function queueStrategy(options) {
|
|
5
|
-
const queuer = new asyncQueuer.AsyncQueuer(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
const queuer = new asyncQueuer.AsyncQueuer(
|
|
6
|
+
async (fn) => {
|
|
7
|
+
const transaction = fn();
|
|
8
|
+
await transaction.isPersisted.promise;
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
concurrency: 1,
|
|
12
|
+
// Process one at a time to ensure serialization
|
|
13
|
+
wait: options?.wait,
|
|
14
|
+
maxSize: options?.maxSize,
|
|
15
|
+
addItemsTo: options?.addItemsTo ?? `back`,
|
|
16
|
+
// Default FIFO: add to back
|
|
17
|
+
getItemsFrom: options?.getItemsFrom ?? `front`,
|
|
18
|
+
// Default FIFO: get from front
|
|
19
|
+
started: true
|
|
20
|
+
// Start processing immediately
|
|
21
|
+
}
|
|
22
|
+
);
|
|
17
23
|
return {
|
|
18
24
|
_type: `queue`,
|
|
19
25
|
options,
|
|
20
26
|
execute: (fn) => {
|
|
21
|
-
queuer.addItem(
|
|
22
|
-
const transaction = fn();
|
|
23
|
-
await transaction.isPersisted.promise;
|
|
24
|
-
});
|
|
27
|
+
queuer.addItem(fn);
|
|
25
28
|
},
|
|
26
29
|
cleanup: () => {
|
|
27
30
|
queuer.stop();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queueStrategy.cjs","sources":["../../../src/strategies/queueStrategy.ts"],"sourcesContent":["import { AsyncQueuer } from \"@tanstack/pacer/async-queuer\"\nimport type { QueueStrategy, QueueStrategyOptions } from \"./types\"\nimport type { Transaction } from \"../transactions\"\n\n/**\n * Creates a queue strategy that processes all mutations in order with proper serialization.\n *\n * Unlike other strategies that may drop executions, queue ensures every\n * mutation is processed sequentially. Each transaction commit completes before\n * the next one starts. Useful when data consistency is critical and\n * every operation must complete in order.\n *\n * @param options - Configuration for queue behavior (FIFO/LIFO, timing, size limits)\n * @returns A queue strategy instance\n *\n * @example\n * ```ts\n * // FIFO queue - process in order received\n * const mutate = usePacedMutations({\n * mutationFn: async ({ transaction }) => {\n * await api.save(transaction.mutations)\n * },\n * strategy: queueStrategy({\n * wait: 200,\n * addItemsTo: 'back',\n * getItemsFrom: 'front'\n * })\n * })\n * ```\n *\n * @example\n * ```ts\n * // LIFO queue - process most recent first\n * const mutate = usePacedMutations({\n * mutationFn: async ({ transaction }) => {\n * await api.save(transaction.mutations)\n * },\n * strategy: queueStrategy({\n * wait: 200,\n * addItemsTo: 'back',\n * getItemsFrom: 'back'\n * })\n * })\n * ```\n */\nexport function queueStrategy(options?: QueueStrategyOptions): QueueStrategy {\n const queuer = new AsyncQueuer<
|
|
1
|
+
{"version":3,"file":"queueStrategy.cjs","sources":["../../../src/strategies/queueStrategy.ts"],"sourcesContent":["import { AsyncQueuer } from \"@tanstack/pacer/async-queuer\"\nimport type { QueueStrategy, QueueStrategyOptions } from \"./types\"\nimport type { Transaction } from \"../transactions\"\n\n/**\n * Creates a queue strategy that processes all mutations in order with proper serialization.\n *\n * Unlike other strategies that may drop executions, queue ensures every\n * mutation is processed sequentially. Each transaction commit completes before\n * the next one starts. Useful when data consistency is critical and\n * every operation must complete in order.\n *\n * @param options - Configuration for queue behavior (FIFO/LIFO, timing, size limits)\n * @returns A queue strategy instance\n *\n * @example\n * ```ts\n * // FIFO queue - process in order received\n * const mutate = usePacedMutations({\n * mutationFn: async ({ transaction }) => {\n * await api.save(transaction.mutations)\n * },\n * strategy: queueStrategy({\n * wait: 200,\n * addItemsTo: 'back',\n * getItemsFrom: 'front'\n * })\n * })\n * ```\n *\n * @example\n * ```ts\n * // LIFO queue - process most recent first\n * const mutate = usePacedMutations({\n * mutationFn: async ({ transaction }) => {\n * await api.save(transaction.mutations)\n * },\n * strategy: queueStrategy({\n * wait: 200,\n * addItemsTo: 'back',\n * getItemsFrom: 'back'\n * })\n * })\n * ```\n */\nexport function queueStrategy(options?: QueueStrategyOptions): QueueStrategy {\n const queuer = new AsyncQueuer<() => Transaction>(\n async (fn) => {\n const transaction = fn()\n // Wait for the transaction to be persisted before processing next item\n // Note: fn() already calls commit(), we just wait for it to complete\n await transaction.isPersisted.promise\n },\n {\n concurrency: 1, // Process one at a time to ensure serialization\n wait: options?.wait,\n maxSize: options?.maxSize,\n addItemsTo: options?.addItemsTo ?? `back`, // Default FIFO: add to back\n getItemsFrom: options?.getItemsFrom ?? `front`, // Default FIFO: get from front\n started: true, // Start processing immediately\n }\n )\n\n return {\n _type: `queue`,\n options,\n execute: <T extends object = Record<string, unknown>>(\n fn: () => Transaction<T>\n ) => {\n // Add the transaction-creating function to the queue\n queuer.addItem(fn as () => Transaction)\n },\n cleanup: () => {\n queuer.stop()\n queuer.clear()\n },\n }\n}\n"],"names":["AsyncQueuer"],"mappings":";;;AA6CO,SAAS,cAAc,SAA+C;AAC3E,QAAM,SAAS,IAAIA,YAAAA;AAAAA,IACjB,OAAO,OAAO;AACZ,YAAM,cAAc,GAAA;AAGpB,YAAM,YAAY,YAAY;AAAA,IAChC;AAAA,IACA;AAAA,MACE,aAAa;AAAA;AAAA,MACb,MAAM,SAAS;AAAA,MACf,SAAS,SAAS;AAAA,MAClB,YAAY,SAAS,cAAc;AAAA;AAAA,MACnC,cAAc,SAAS,gBAAgB;AAAA;AAAA,MACvC,SAAS;AAAA;AAAA,IAAA;AAAA,EACX;AAGF,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,IACA,SAAS,CACP,OACG;AAEH,aAAO,QAAQ,EAAuB;AAAA,IACxC;AAAA,IACA,SAAS,MAAM;AACb,aAAO,KAAA;AACP,aAAO,MAAA;AAAA,IACT;AAAA,EAAA;AAEJ;;"}
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import { AsyncQueuer } from "@tanstack/pacer/async-queuer";
|
|
2
2
|
function queueStrategy(options) {
|
|
3
|
-
const queuer = new AsyncQueuer(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
const queuer = new AsyncQueuer(
|
|
4
|
+
async (fn) => {
|
|
5
|
+
const transaction = fn();
|
|
6
|
+
await transaction.isPersisted.promise;
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
concurrency: 1,
|
|
10
|
+
// Process one at a time to ensure serialization
|
|
11
|
+
wait: options?.wait,
|
|
12
|
+
maxSize: options?.maxSize,
|
|
13
|
+
addItemsTo: options?.addItemsTo ?? `back`,
|
|
14
|
+
// Default FIFO: add to back
|
|
15
|
+
getItemsFrom: options?.getItemsFrom ?? `front`,
|
|
16
|
+
// Default FIFO: get from front
|
|
17
|
+
started: true
|
|
18
|
+
// Start processing immediately
|
|
19
|
+
}
|
|
20
|
+
);
|
|
15
21
|
return {
|
|
16
22
|
_type: `queue`,
|
|
17
23
|
options,
|
|
18
24
|
execute: (fn) => {
|
|
19
|
-
queuer.addItem(
|
|
20
|
-
const transaction = fn();
|
|
21
|
-
await transaction.isPersisted.promise;
|
|
22
|
-
});
|
|
25
|
+
queuer.addItem(fn);
|
|
23
26
|
},
|
|
24
27
|
cleanup: () => {
|
|
25
28
|
queuer.stop();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queueStrategy.js","sources":["../../../src/strategies/queueStrategy.ts"],"sourcesContent":["import { AsyncQueuer } from \"@tanstack/pacer/async-queuer\"\nimport type { QueueStrategy, QueueStrategyOptions } from \"./types\"\nimport type { Transaction } from \"../transactions\"\n\n/**\n * Creates a queue strategy that processes all mutations in order with proper serialization.\n *\n * Unlike other strategies that may drop executions, queue ensures every\n * mutation is processed sequentially. Each transaction commit completes before\n * the next one starts. Useful when data consistency is critical and\n * every operation must complete in order.\n *\n * @param options - Configuration for queue behavior (FIFO/LIFO, timing, size limits)\n * @returns A queue strategy instance\n *\n * @example\n * ```ts\n * // FIFO queue - process in order received\n * const mutate = usePacedMutations({\n * mutationFn: async ({ transaction }) => {\n * await api.save(transaction.mutations)\n * },\n * strategy: queueStrategy({\n * wait: 200,\n * addItemsTo: 'back',\n * getItemsFrom: 'front'\n * })\n * })\n * ```\n *\n * @example\n * ```ts\n * // LIFO queue - process most recent first\n * const mutate = usePacedMutations({\n * mutationFn: async ({ transaction }) => {\n * await api.save(transaction.mutations)\n * },\n * strategy: queueStrategy({\n * wait: 200,\n * addItemsTo: 'back',\n * getItemsFrom: 'back'\n * })\n * })\n * ```\n */\nexport function queueStrategy(options?: QueueStrategyOptions): QueueStrategy {\n const queuer = new AsyncQueuer<
|
|
1
|
+
{"version":3,"file":"queueStrategy.js","sources":["../../../src/strategies/queueStrategy.ts"],"sourcesContent":["import { AsyncQueuer } from \"@tanstack/pacer/async-queuer\"\nimport type { QueueStrategy, QueueStrategyOptions } from \"./types\"\nimport type { Transaction } from \"../transactions\"\n\n/**\n * Creates a queue strategy that processes all mutations in order with proper serialization.\n *\n * Unlike other strategies that may drop executions, queue ensures every\n * mutation is processed sequentially. Each transaction commit completes before\n * the next one starts. Useful when data consistency is critical and\n * every operation must complete in order.\n *\n * @param options - Configuration for queue behavior (FIFO/LIFO, timing, size limits)\n * @returns A queue strategy instance\n *\n * @example\n * ```ts\n * // FIFO queue - process in order received\n * const mutate = usePacedMutations({\n * mutationFn: async ({ transaction }) => {\n * await api.save(transaction.mutations)\n * },\n * strategy: queueStrategy({\n * wait: 200,\n * addItemsTo: 'back',\n * getItemsFrom: 'front'\n * })\n * })\n * ```\n *\n * @example\n * ```ts\n * // LIFO queue - process most recent first\n * const mutate = usePacedMutations({\n * mutationFn: async ({ transaction }) => {\n * await api.save(transaction.mutations)\n * },\n * strategy: queueStrategy({\n * wait: 200,\n * addItemsTo: 'back',\n * getItemsFrom: 'back'\n * })\n * })\n * ```\n */\nexport function queueStrategy(options?: QueueStrategyOptions): QueueStrategy {\n const queuer = new AsyncQueuer<() => Transaction>(\n async (fn) => {\n const transaction = fn()\n // Wait for the transaction to be persisted before processing next item\n // Note: fn() already calls commit(), we just wait for it to complete\n await transaction.isPersisted.promise\n },\n {\n concurrency: 1, // Process one at a time to ensure serialization\n wait: options?.wait,\n maxSize: options?.maxSize,\n addItemsTo: options?.addItemsTo ?? `back`, // Default FIFO: add to back\n getItemsFrom: options?.getItemsFrom ?? `front`, // Default FIFO: get from front\n started: true, // Start processing immediately\n }\n )\n\n return {\n _type: `queue`,\n options,\n execute: <T extends object = Record<string, unknown>>(\n fn: () => Transaction<T>\n ) => {\n // Add the transaction-creating function to the queue\n queuer.addItem(fn as () => Transaction)\n },\n cleanup: () => {\n queuer.stop()\n queuer.clear()\n },\n }\n}\n"],"names":[],"mappings":";AA6CO,SAAS,cAAc,SAA+C;AAC3E,QAAM,SAAS,IAAI;AAAA,IACjB,OAAO,OAAO;AACZ,YAAM,cAAc,GAAA;AAGpB,YAAM,YAAY,YAAY;AAAA,IAChC;AAAA,IACA;AAAA,MACE,aAAa;AAAA;AAAA,MACb,MAAM,SAAS;AAAA,MACf,SAAS,SAAS;AAAA,MAClB,YAAY,SAAS,cAAc;AAAA;AAAA,MACnC,cAAc,SAAS,gBAAgB;AAAA;AAAA,MACvC,SAAS;AAAA;AAAA,IAAA;AAAA,EACX;AAGF,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,IACA,SAAS,CACP,OACG;AAEH,aAAO,QAAQ,EAAuB;AAAA,IACxC;AAAA,IACA,SAAS,MAAM;AACb,aAAO,KAAA;AACP,aAAO,MAAA;AAAA,IACT;AAAA,EAAA;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/db",
|
|
3
3
|
"description": "A reactive client store for building super fast apps on sync",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@standard-schema/spec": "^1.0.0",
|
|
7
|
-
"@tanstack/pacer": "^0.
|
|
7
|
+
"@tanstack/pacer": "^0.16.3",
|
|
8
8
|
"@tanstack/db-ivm": "0.1.13"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@vitest/coverage-istanbul": "^3.2.4",
|
|
12
|
-
"arktype": "^2.1.
|
|
12
|
+
"arktype": "^2.1.27",
|
|
13
13
|
"superjson": "^2.2.5",
|
|
14
14
|
"temporal-polyfill": "^0.3.0"
|
|
15
15
|
},
|
|
@@ -44,14 +44,22 @@ import type { Transaction } from "../transactions"
|
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
46
|
export function queueStrategy(options?: QueueStrategyOptions): QueueStrategy {
|
|
47
|
-
const queuer = new AsyncQueuer<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
const queuer = new AsyncQueuer<() => Transaction>(
|
|
48
|
+
async (fn) => {
|
|
49
|
+
const transaction = fn()
|
|
50
|
+
// Wait for the transaction to be persisted before processing next item
|
|
51
|
+
// Note: fn() already calls commit(), we just wait for it to complete
|
|
52
|
+
await transaction.isPersisted.promise
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
concurrency: 1, // Process one at a time to ensure serialization
|
|
56
|
+
wait: options?.wait,
|
|
57
|
+
maxSize: options?.maxSize,
|
|
58
|
+
addItemsTo: options?.addItemsTo ?? `back`, // Default FIFO: add to back
|
|
59
|
+
getItemsFrom: options?.getItemsFrom ?? `front`, // Default FIFO: get from front
|
|
60
|
+
started: true, // Start processing immediately
|
|
61
|
+
}
|
|
62
|
+
)
|
|
55
63
|
|
|
56
64
|
return {
|
|
57
65
|
_type: `queue`,
|
|
@@ -59,13 +67,8 @@ export function queueStrategy(options?: QueueStrategyOptions): QueueStrategy {
|
|
|
59
67
|
execute: <T extends object = Record<string, unknown>>(
|
|
60
68
|
fn: () => Transaction<T>
|
|
61
69
|
) => {
|
|
62
|
-
//
|
|
63
|
-
queuer.addItem(
|
|
64
|
-
const transaction = fn()
|
|
65
|
-
// Wait for the transaction to be persisted before processing next item
|
|
66
|
-
// Note: fn() already calls commit(), we just wait for it to complete
|
|
67
|
-
await transaction.isPersisted.promise
|
|
68
|
-
})
|
|
70
|
+
// Add the transaction-creating function to the queue
|
|
71
|
+
queuer.addItem(fn as () => Transaction)
|
|
69
72
|
},
|
|
70
73
|
cleanup: () => {
|
|
71
74
|
queuer.stop()
|