@blujosi/rivetkit-svelte 2.3.7 → 2.3.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.
|
@@ -40,19 +40,19 @@ export interface CrudTransformOptions<T> {
|
|
|
40
40
|
* - **Array:** appends the incoming item; duplicates (same key) are ignored.
|
|
41
41
|
* - **Single item:** replaces the current value with the incoming item.
|
|
42
42
|
*/
|
|
43
|
-
export declare function createTransform<T>(opts?: CrudTransformOptions<T>): <C extends T[] | T>(current: C, incoming:
|
|
43
|
+
export declare function createTransform<T>(opts?: CrudTransformOptions<T>): <C extends T[] | T>(current: C, incoming: CrudEvent<T>) => C;
|
|
44
44
|
/**
|
|
45
45
|
* Transform for an **update** event.
|
|
46
46
|
* - **Array:** replaces the matching item in-place; returns unchanged if no match.
|
|
47
47
|
* - **Single item:** replaces the current value with the incoming item.
|
|
48
48
|
*/
|
|
49
|
-
export declare function updateTransform<T>(opts?: CrudTransformOptions<T>): <C extends T[] | T>(current: C, incoming:
|
|
49
|
+
export declare function updateTransform<T>(opts?: CrudTransformOptions<T>): <C extends T[] | T>(current: C, incoming: CrudEvent<T>) => C;
|
|
50
50
|
/**
|
|
51
51
|
* Transform for a **delete** event.
|
|
52
52
|
* - **Array:** removes the matching item. `incoming` can be the full item or just the key value.
|
|
53
53
|
* - **Single item:** returns the current value unchanged (cannot delete a scalar).
|
|
54
54
|
*/
|
|
55
|
-
export declare function deleteTransform<T>(opts?: CrudTransformOptions<T>): <C extends T[] | T>(current: C, incoming:
|
|
55
|
+
export declare function deleteTransform<T>(opts?: CrudTransformOptions<T>): <C extends T[] | T>(current: C, incoming: CrudEvent<T>) => C;
|
|
56
56
|
/**
|
|
57
57
|
* A single transform that handles create, update, and delete events.
|
|
58
58
|
*
|
|
@@ -32,7 +32,7 @@ function getKey(item, key) {
|
|
|
32
32
|
export function createTransform(opts = {}) {
|
|
33
33
|
const keyProp = opts.key ?? "id";
|
|
34
34
|
return ((current, incoming) => {
|
|
35
|
-
const item = incoming;
|
|
35
|
+
const item = incoming.data;
|
|
36
36
|
if (Array.isArray(current)) {
|
|
37
37
|
const id = getKey(item, keyProp);
|
|
38
38
|
if (current.some((c) => getKey(c, keyProp) === id))
|
|
@@ -50,7 +50,7 @@ export function createTransform(opts = {}) {
|
|
|
50
50
|
export function updateTransform(opts = {}) {
|
|
51
51
|
const keyProp = opts.key ?? "id";
|
|
52
52
|
return ((current, incoming) => {
|
|
53
|
-
const item = incoming;
|
|
53
|
+
const item = incoming.data;
|
|
54
54
|
if (Array.isArray(current)) {
|
|
55
55
|
const id = getKey(item, keyProp);
|
|
56
56
|
const idx = current.findIndex((c) => getKey(c, keyProp) === id);
|
|
@@ -72,9 +72,9 @@ export function deleteTransform(opts = {}) {
|
|
|
72
72
|
const keyProp = opts.key ?? "id";
|
|
73
73
|
return ((current, incoming) => {
|
|
74
74
|
if (Array.isArray(current)) {
|
|
75
|
-
const id = typeof incoming === "object" && incoming !== null
|
|
76
|
-
? getKey(incoming, keyProp)
|
|
77
|
-
: incoming;
|
|
75
|
+
const id = typeof incoming.data === "object" && incoming.data !== null
|
|
76
|
+
? getKey(incoming.data, keyProp)
|
|
77
|
+
: incoming.data;
|
|
78
78
|
return current.filter((c) => getKey(c, keyProp) !== id);
|
|
79
79
|
}
|
|
80
80
|
return current;
|
|
@@ -115,11 +115,11 @@ export function crudTransform(opts = {}) {
|
|
|
115
115
|
return ((current, incoming) => {
|
|
116
116
|
switch (incoming.type) {
|
|
117
117
|
case "created":
|
|
118
|
-
return create(current, incoming
|
|
118
|
+
return create(current, incoming);
|
|
119
119
|
case "updated":
|
|
120
|
-
return update(current, incoming
|
|
120
|
+
return update(current, incoming);
|
|
121
121
|
case "deleted":
|
|
122
|
-
return del(current, incoming
|
|
122
|
+
return del(current, incoming);
|
|
123
123
|
default:
|
|
124
124
|
return current;
|
|
125
125
|
}
|
|
@@ -32,7 +32,7 @@ export interface RivetLoadOptions<T = unknown> {
|
|
|
32
32
|
/** Optional input data for actor creation. */
|
|
33
33
|
createWithInput?: unknown;
|
|
34
34
|
/** Transform incoming event data into the new value. Default: full replacement. */
|
|
35
|
-
transform?: (current: T, incoming:
|
|
35
|
+
transform?: (current: T, incoming: any) => T;
|
|
36
36
|
}
|
|
37
37
|
/** Marker class for transport.encode to recognize. */
|
|
38
38
|
export declare class RivetLoadResult<T = unknown> {
|