@evolu/svelte 2.3.0 → 3.0.0-next.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/README.md +2 -2
- package/dist/index.svelte.d.ts +16 -9
- package/dist/index.svelte.d.ts.map +1 -0
- package/dist/index.svelte.js +21 -15
- package/package.json +21 -22
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Evolu for Svelte
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package provides Evolu for [Svelte](https://svelte.dev).
|
|
4
4
|
|
|
5
5
|
## Documentation
|
|
6
6
|
|
|
@@ -12,4 +12,4 @@ The Evolu community is on [GitHub Discussions](https://github.com/evoluhq/evolu/
|
|
|
12
12
|
|
|
13
13
|
To chat with other community members, you can join the [Evolu Discord](https://discord.gg/2J8yyyyxtZ).
|
|
14
14
|
|
|
15
|
-
[](https://x.com/evoluhq)
|
package/dist/index.svelte.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* This file needs to be named .svelte.ts to be recognized by the Svelte
|
|
3
3
|
* compiler in the app itself.
|
|
4
4
|
*/
|
|
5
|
-
import type { AppOwner, Evolu,
|
|
6
|
-
export declare const evoluSvelteDeps: EvoluDeps;
|
|
5
|
+
import type { AppOwner, Evolu, EvoluSchema, InferRow, Query, Row } from "@evolu/common/local-first";
|
|
6
|
+
export declare const evoluSvelteDeps: import("@evolu/common/local-first").EvoluDeps;
|
|
7
7
|
/**
|
|
8
8
|
* Load and subscribe to the Query, and return an object with `rows` property
|
|
9
9
|
* that are automatically updated when data changes.
|
|
@@ -12,7 +12,9 @@ export declare const evoluSvelteDeps: EvoluDeps;
|
|
|
12
12
|
*
|
|
13
13
|
* ```ts
|
|
14
14
|
* // Create your query
|
|
15
|
-
* const allTodos = evolu.createQuery((db) =>
|
|
15
|
+
* const allTodos = evolu.createQuery((db) =>
|
|
16
|
+
* db.selectFrom("todo").selectAll(),
|
|
17
|
+
* );
|
|
16
18
|
*
|
|
17
19
|
* // Get all rows.
|
|
18
20
|
* const allTodosState = queryState(evolu, () => allTodos);
|
|
@@ -22,10 +24,14 @@ export declare const evoluSvelteDeps: EvoluDeps;
|
|
|
22
24
|
*
|
|
23
25
|
* ```ts
|
|
24
26
|
* // some kind of state
|
|
25
|
-
* let someKindOfState = $state(
|
|
27
|
+
* let someKindOfState = $state("someId");
|
|
26
28
|
*
|
|
27
29
|
* // derive your query based other props
|
|
28
|
-
* const allTodos = $derived(
|
|
30
|
+
* const allTodos = $derived(
|
|
31
|
+
* evolu.createQuery((db) =>
|
|
32
|
+
* db.selectFrom("todo").where("id", "=", someKindOfState).selectAll(),
|
|
33
|
+
* ),
|
|
34
|
+
* );
|
|
29
35
|
*
|
|
30
36
|
* // Get all rows, once someKindOfState changes, this allTodosState will be updated with the evolu query result
|
|
31
37
|
* const allTodosState = queryState(evolu, () => allTodos);
|
|
@@ -33,14 +39,14 @@ export declare const evoluSvelteDeps: EvoluDeps;
|
|
|
33
39
|
* // use allTodosState.rows in further calculations / UI
|
|
34
40
|
* ```
|
|
35
41
|
*/
|
|
36
|
-
export declare
|
|
42
|
+
export declare const queryState: <R extends Row, Schema extends EvoluSchema, MappedRow = InferRow<Query<Schema, R>>>(evolu: Evolu<Schema>,
|
|
37
43
|
/**
|
|
38
44
|
* Can be a normal query or a derived query.
|
|
39
45
|
*
|
|
40
46
|
* Svelte reactivity: it needs to be a callback, if the query is $derived this
|
|
41
47
|
* will re-trigger the load/subscription based on the new query.
|
|
42
48
|
*/
|
|
43
|
-
observedQuery: () => Query<R> | undefined, options?: {
|
|
49
|
+
observedQuery: () => Query<Schema, R> | undefined, options?: {
|
|
44
50
|
/**
|
|
45
51
|
* This is a little helper so that you can map the results instead of using
|
|
46
52
|
* a $derive operation.
|
|
@@ -48,7 +54,7 @@ observedQuery: () => Query<R> | undefined, options?: {
|
|
|
48
54
|
* @param row
|
|
49
55
|
*/
|
|
50
56
|
mapping?: (row: R) => MappedRow;
|
|
51
|
-
})
|
|
57
|
+
}) => {
|
|
52
58
|
readonly rows: Array<MappedRow>;
|
|
53
59
|
};
|
|
54
60
|
/**
|
|
@@ -65,6 +71,7 @@ observedQuery: () => Query<R> | undefined, options?: {
|
|
|
65
71
|
* // it will be undefined initially and set once the promise resolves
|
|
66
72
|
* ```
|
|
67
73
|
*/
|
|
68
|
-
export declare
|
|
74
|
+
export declare const appOwnerState: <Schema extends EvoluSchema>(evolu: Evolu<Schema>) => {
|
|
69
75
|
readonly current: AppOwner | undefined;
|
|
70
76
|
};
|
|
77
|
+
//# sourceMappingURL=index.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.svelte.d.ts","sourceRoot":"","sources":["../src/lib/index.svelte.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,KAAK,EACL,WAAW,EACX,QAAQ,EACR,KAAK,EAEL,GAAG,EACJ,MAAM,2BAA2B,CAAC;AAKnC,eAAO,MAAM,eAAe,+CAAoB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,UAAU,GACrB,CAAC,SAAS,GAAG,EACb,MAAM,SAAS,WAAW,EAC1B,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAEtC,OAAO,KAAK,CAAC,MAAM,CAAC;AACpB;;;;;GAKG;AACH,eAAe,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,EACjD,UAAU;IACR;;;;;OAKG;IACH,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,SAAS,CAAC;CACjC,KACA;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;CA2CnC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,SAAS,WAAW,EACtD,OAAO,KAAK,CAAC,MAAM,CAAC,KACnB;IACD,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,SAAS,CAAC;CAkBxC,CAAC"}
|
package/dist/index.svelte.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* This file needs to be named .svelte.ts to be recognized by the Svelte
|
|
3
3
|
* compiler in the app itself.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { createEvoluDeps } from "@evolu/web";
|
|
6
6
|
// just in case we need to add some svelte specific deps
|
|
7
|
-
|
|
7
|
+
// eslint-disable-next-line evolu/require-pure-annotation
|
|
8
|
+
export const evoluSvelteDeps = createEvoluDeps();
|
|
8
9
|
/**
|
|
9
10
|
* Load and subscribe to the Query, and return an object with `rows` property
|
|
10
11
|
* that are automatically updated when data changes.
|
|
@@ -13,7 +14,9 @@ export const evoluSvelteDeps = Object.assign({}, evoluWebDeps);
|
|
|
13
14
|
*
|
|
14
15
|
* ```ts
|
|
15
16
|
* // Create your query
|
|
16
|
-
* const allTodos = evolu.createQuery((db) =>
|
|
17
|
+
* const allTodos = evolu.createQuery((db) =>
|
|
18
|
+
* db.selectFrom("todo").selectAll(),
|
|
19
|
+
* );
|
|
17
20
|
*
|
|
18
21
|
* // Get all rows.
|
|
19
22
|
* const allTodosState = queryState(evolu, () => allTodos);
|
|
@@ -23,10 +26,14 @@ export const evoluSvelteDeps = Object.assign({}, evoluWebDeps);
|
|
|
23
26
|
*
|
|
24
27
|
* ```ts
|
|
25
28
|
* // some kind of state
|
|
26
|
-
* let someKindOfState = $state(
|
|
29
|
+
* let someKindOfState = $state("someId");
|
|
27
30
|
*
|
|
28
31
|
* // derive your query based other props
|
|
29
|
-
* const allTodos = $derived(
|
|
32
|
+
* const allTodos = $derived(
|
|
33
|
+
* evolu.createQuery((db) =>
|
|
34
|
+
* db.selectFrom("todo").where("id", "=", someKindOfState).selectAll(),
|
|
35
|
+
* ),
|
|
36
|
+
* );
|
|
30
37
|
*
|
|
31
38
|
* // Get all rows, once someKindOfState changes, this allTodosState will be updated with the evolu query result
|
|
32
39
|
* const allTodosState = queryState(evolu, () => allTodos);
|
|
@@ -34,18 +41,18 @@ export const evoluSvelteDeps = Object.assign({}, evoluWebDeps);
|
|
|
34
41
|
* // use allTodosState.rows in further calculations / UI
|
|
35
42
|
* ```
|
|
36
43
|
*/
|
|
37
|
-
export
|
|
44
|
+
export const queryState = (evolu,
|
|
38
45
|
/**
|
|
39
46
|
* Can be a normal query or a derived query.
|
|
40
47
|
*
|
|
41
48
|
* Svelte reactivity: it needs to be a callback, if the query is $derived this
|
|
42
49
|
* will re-trigger the load/subscription based on the new query.
|
|
43
50
|
*/
|
|
44
|
-
observedQuery, options) {
|
|
51
|
+
observedQuery, options) => {
|
|
45
52
|
{
|
|
46
53
|
// writing to this variable - svelte's compiler will track it
|
|
47
54
|
let writableState = $state([]);
|
|
48
|
-
|
|
55
|
+
const updateState = (rows) => {
|
|
49
56
|
if (options === null || options === void 0 ? void 0 : options.mapping) {
|
|
50
57
|
// re-assigning because somehow typescript thinks its still nullable here
|
|
51
58
|
// remove again once no issue anymore
|
|
@@ -53,7 +60,7 @@ observedQuery, options) {
|
|
|
53
60
|
writableState = rows.map((row) => mapper(row));
|
|
54
61
|
}
|
|
55
62
|
writableState = rows;
|
|
56
|
-
}
|
|
63
|
+
};
|
|
57
64
|
$effect(() => {
|
|
58
65
|
const query = observedQuery();
|
|
59
66
|
if (!query) {
|
|
@@ -76,7 +83,7 @@ observedQuery, options) {
|
|
|
76
83
|
},
|
|
77
84
|
};
|
|
78
85
|
}
|
|
79
|
-
}
|
|
86
|
+
};
|
|
80
87
|
/**
|
|
81
88
|
* Get the {@link AppOwner} promise that resolves when available.
|
|
82
89
|
*
|
|
@@ -91,14 +98,13 @@ observedQuery, options) {
|
|
|
91
98
|
* // it will be undefined initially and set once the promise resolves
|
|
92
99
|
* ```
|
|
93
100
|
*/
|
|
94
|
-
export
|
|
101
|
+
export const appOwnerState = (evolu) => {
|
|
95
102
|
{
|
|
96
103
|
// writing to this variable - svelte's compiler will track it
|
|
97
104
|
let writableState = $state(undefined);
|
|
98
105
|
$effect(() => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
106
|
+
// TODO: Review, it was promise, it isn't anymore.
|
|
107
|
+
writableState = evolu.appOwner;
|
|
102
108
|
});
|
|
103
109
|
return {
|
|
104
110
|
// Svelte reactivity: it needs to be a getter
|
|
@@ -107,4 +113,4 @@ export function appOwnerState(evolu) {
|
|
|
107
113
|
},
|
|
108
114
|
};
|
|
109
115
|
}
|
|
110
|
-
}
|
|
116
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evolu/svelte",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-next.0",
|
|
4
4
|
"description": "Evolu for Svelte",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"evolu",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"repository": "evoluhq/evolu",
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"sideEffects":
|
|
15
|
+
"sideEffects": false,
|
|
16
16
|
"type": "module",
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
@@ -27,31 +27,30 @@
|
|
|
27
27
|
"!dist/**/*.test.*",
|
|
28
28
|
"!dist/**/*.spec.*"
|
|
29
29
|
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc --build && npm run package",
|
|
32
|
+
"prepack": "npm run build",
|
|
33
|
+
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
34
|
+
"package": "svelte-package",
|
|
35
|
+
"prepublishOnly": "npm run package",
|
|
36
|
+
"preview": "vite preview"
|
|
37
|
+
},
|
|
30
38
|
"devDependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"svelte
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"@evolu/tsconfig": "0.0.2"
|
|
39
|
+
"@evolu/common": "8.0.0-next.0",
|
|
40
|
+
"@evolu/typescript-config": "*",
|
|
41
|
+
"@evolu/web": "3.0.0-next.0",
|
|
42
|
+
"@sveltejs/package": "^2.5.7",
|
|
43
|
+
"@tsconfig/svelte": "^5.0.6",
|
|
44
|
+
"svelte": "^5.48.2",
|
|
45
|
+
"svelte-check": "^4.3.6",
|
|
46
|
+
"typescript": "^5.9.3"
|
|
40
47
|
},
|
|
41
48
|
"peerDependencies": {
|
|
42
|
-
"@evolu/common": "^
|
|
43
|
-
"@evolu/web": "^
|
|
49
|
+
"@evolu/common": "^8.0.0-next.0",
|
|
50
|
+
"@evolu/web": "^3.0.0-next.0",
|
|
44
51
|
"svelte": ">=5"
|
|
45
52
|
},
|
|
46
53
|
"publishConfig": {
|
|
47
54
|
"access": "public"
|
|
48
|
-
},
|
|
49
|
-
"scripts": {
|
|
50
|
-
"build": "shx rm -rf dist && tsc && pnpm run package",
|
|
51
|
-
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
52
|
-
"clean": "shx rm -rf .turbo .svelte-kit node_modules dist",
|
|
53
|
-
"dev": "tsc --watch",
|
|
54
|
-
"package": "svelte-package",
|
|
55
|
-
"preview": "vite preview"
|
|
56
55
|
}
|
|
57
|
-
}
|
|
56
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Evolu
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|