@triplit/react 0.0.37 → 0.0.38-beta.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.
- package/dist/index.d.ts +2 -13
- package/dist/index.js +2 -78
- package/dist/use-entity.d.ts +7 -0
- package/dist/use-entity.js +10 -0
- package/dist/use-query.d.ts +7 -0
- package/dist/use-query.js +33 -0
- package/package.json +18 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/module.js +0 -61
- package/dist/module.js.map +0 -1
package/dist/index.d.ts
CHANGED
@@ -1,13 +1,2 @@
|
|
1
|
-
|
2
|
-
export
|
3
|
-
fetching: boolean;
|
4
|
-
results: FetchResult<CQ> | undefined;
|
5
|
-
error: any;
|
6
|
-
};
|
7
|
-
export function useEntity<M extends Models<any, any> | undefined, CN extends CollectionNameFromModels<M>>(client: TriplitClient<M>, collectionName: CN, id: string, options?: SubscriptionOptions): {
|
8
|
-
fetching: boolean;
|
9
|
-
results: any;
|
10
|
-
error: any;
|
11
|
-
};
|
12
|
-
|
13
|
-
//# sourceMappingURL=index.d.ts.map
|
1
|
+
export * from './use-query.js';
|
2
|
+
export * from './use-entity.js';
|
package/dist/index.js
CHANGED
@@ -1,78 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
function $parcel$exportWildcard(dest, source) {
|
4
|
-
Object.keys(source).forEach(function(key) {
|
5
|
-
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
6
|
-
return;
|
7
|
-
}
|
8
|
-
|
9
|
-
Object.defineProperty(dest, key, {
|
10
|
-
enumerable: true,
|
11
|
-
get: function get() {
|
12
|
-
return source[key];
|
13
|
-
}
|
14
|
-
});
|
15
|
-
});
|
16
|
-
|
17
|
-
return dest;
|
18
|
-
}
|
19
|
-
function $parcel$export(e, n, v, s) {
|
20
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
21
|
-
}
|
22
|
-
var $8789f74c7c312f3c$exports = {};
|
23
|
-
|
24
|
-
$parcel$export($8789f74c7c312f3c$exports, "useQuery", () => $8789f74c7c312f3c$export$dd0a697e1782aedd);
|
25
|
-
|
26
|
-
function $8789f74c7c312f3c$export$dd0a697e1782aedd(client, query, options) {
|
27
|
-
const [results, setResults] = (0, $2yxZb$react.useState)(undefined);
|
28
|
-
const [fetching, setFetching] = (0, $2yxZb$react.useState)(true);
|
29
|
-
const [error, setError] = (0, $2yxZb$react.useState)(undefined);
|
30
|
-
const builtQuery = query && query.build();
|
31
|
-
const stringifiedQuery = builtQuery && JSON.stringify(builtQuery);
|
32
|
-
(0, $2yxZb$react.useEffect)(()=>{
|
33
|
-
if (!client) return;
|
34
|
-
setResults(undefined);
|
35
|
-
setFetching(true);
|
36
|
-
const unsubscribe = client.subscribe(builtQuery, (localResults)=>{
|
37
|
-
setFetching(false);
|
38
|
-
setError(undefined);
|
39
|
-
setResults(new Map(localResults));
|
40
|
-
}, (error)=>{
|
41
|
-
setFetching(false);
|
42
|
-
setError(error);
|
43
|
-
}, options);
|
44
|
-
return ()=>{
|
45
|
-
unsubscribe();
|
46
|
-
};
|
47
|
-
}, [
|
48
|
-
stringifiedQuery,
|
49
|
-
client
|
50
|
-
]);
|
51
|
-
return {
|
52
|
-
fetching: fetching,
|
53
|
-
results: results,
|
54
|
-
error: error
|
55
|
-
};
|
56
|
-
}
|
57
|
-
|
58
|
-
|
59
|
-
var $6ea15837a6dcd4eb$exports = {};
|
60
|
-
|
61
|
-
$parcel$export($6ea15837a6dcd4eb$exports, "useEntity", () => $6ea15837a6dcd4eb$export$fab329b658bf30c7);
|
62
|
-
|
63
|
-
function $6ea15837a6dcd4eb$export$fab329b658bf30c7(client, collectionName, id, options) {
|
64
|
-
const { fetching: fetching, results: results, error: error } = (0, $8789f74c7c312f3c$export$dd0a697e1782aedd)(client, // @ts-ignore TODO: generics getting weird with models and collection queries...probably worth refactoring when we have joins (as we'll need to redo some typing then anyway)
|
65
|
-
client.query(collectionName).entityId(id), options);
|
66
|
-
return {
|
67
|
-
fetching: fetching,
|
68
|
-
results: results ? results.get(id) : undefined,
|
69
|
-
error: error
|
70
|
-
};
|
71
|
-
}
|
72
|
-
|
73
|
-
|
74
|
-
$parcel$exportWildcard(module.exports, $8789f74c7c312f3c$exports);
|
75
|
-
$parcel$exportWildcard(module.exports, $6ea15837a6dcd4eb$exports);
|
76
|
-
|
77
|
-
|
78
|
-
//# sourceMappingURL=index.js.map
|
1
|
+
export * from './use-query.js';
|
2
|
+
export * from './use-entity.js';
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { TriplitClient, Models, CollectionNameFromModels, SubscriptionOptions } from '@triplit/client';
|
2
|
+
export declare function useEntity<M extends Models<any, any> | undefined, CN extends CollectionNameFromModels<M>>(client: TriplitClient<M>, collectionName: CN, id: string, options?: SubscriptionOptions): {
|
3
|
+
fetching: boolean;
|
4
|
+
fetchingRemote: boolean;
|
5
|
+
results: any;
|
6
|
+
error: any;
|
7
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { useQuery } from './use-query.js';
|
2
|
+
export function useEntity(client, collectionName, id, options) {
|
3
|
+
const { fetching, fetchingRemote, results, error } = useQuery(client, client.query(collectionName).entityId(id), options);
|
4
|
+
return {
|
5
|
+
fetching,
|
6
|
+
fetchingRemote,
|
7
|
+
results: results ? results.get(id) : undefined,
|
8
|
+
error,
|
9
|
+
};
|
10
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { TriplitClient, ClientQuery, ClientQueryBuilder, SubscriptionOptions, CollectionNameFromModels, Models } from '@triplit/client';
|
2
|
+
export declare function useQuery<M extends Models<any, any> | undefined, CN extends CollectionNameFromModels<M>>(client: TriplitClient<any>, query: ClientQueryBuilder<ClientQuery<M, CN>>, options?: SubscriptionOptions): {
|
3
|
+
fetching: boolean;
|
4
|
+
fetchingRemote: boolean;
|
5
|
+
results: (M extends Models<any, any> ? Map<string, import("packages/db/src/schema.js").ResultTypeFromModel<import("packages/db/src/db.js").ModelFromModels<M, CN>>> : M extends undefined ? Map<string, any> : never) | undefined;
|
6
|
+
error: any;
|
7
|
+
};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { useEffect, useState } from 'react';
|
2
|
+
export function useQuery(client, query, options) {
|
3
|
+
const [results, setResults] = useState(undefined);
|
4
|
+
const [fetching, setFetching] = useState(true);
|
5
|
+
const [fetchingRemote, setFetchingRemote] = useState(true);
|
6
|
+
const [error, setError] = useState(undefined);
|
7
|
+
const builtQuery = query && query.build();
|
8
|
+
const stringifiedQuery = builtQuery && JSON.stringify(builtQuery);
|
9
|
+
useEffect(() => {
|
10
|
+
if (!client)
|
11
|
+
return;
|
12
|
+
setResults(undefined);
|
13
|
+
setFetching(true);
|
14
|
+
const unsubscribe = client.subscribe(builtQuery, (localResults, { hasRemoteFulfilled }) => {
|
15
|
+
setFetching(false);
|
16
|
+
setError(undefined);
|
17
|
+
setFetchingRemote(!hasRemoteFulfilled);
|
18
|
+
setResults(new Map(localResults));
|
19
|
+
}, (error) => {
|
20
|
+
setFetching(false);
|
21
|
+
setError(error);
|
22
|
+
}, options);
|
23
|
+
return () => {
|
24
|
+
unsubscribe();
|
25
|
+
};
|
26
|
+
}, [stringifiedQuery, client]);
|
27
|
+
return {
|
28
|
+
fetching,
|
29
|
+
fetchingRemote,
|
30
|
+
results,
|
31
|
+
error,
|
32
|
+
};
|
33
|
+
}
|
package/package.json
CHANGED
@@ -1,23 +1,31 @@
|
|
1
1
|
{
|
2
2
|
"name": "@triplit/react",
|
3
3
|
"packageManager": "yarn@3.4.1",
|
4
|
-
"version": "0.0.
|
5
|
-
"source": "src/index.ts",
|
6
|
-
"main": "dist/index.js",
|
7
|
-
"module": "dist/
|
8
|
-
"types": "dist/index.d.ts",
|
4
|
+
"version": "0.0.38-beta.1",
|
5
|
+
"source": "./src/index.ts",
|
6
|
+
"main": "./dist/index.js",
|
7
|
+
"module": "./dist/index.js",
|
8
|
+
"types": "./dist/index.d.ts",
|
9
|
+
"type": "module",
|
10
|
+
"exports": {
|
11
|
+
".": {
|
12
|
+
"types": "./dist/index.d.ts",
|
13
|
+
"require": "./dist/index.js",
|
14
|
+
"import": "./dist/index.js",
|
15
|
+
"default": "./dist/index.js"
|
16
|
+
}
|
17
|
+
},
|
9
18
|
"scripts": {
|
10
|
-
"build": "
|
11
|
-
"build
|
12
|
-
"
|
13
|
-
"lint": "tsc",
|
19
|
+
"build": "tsc --build --force",
|
20
|
+
"lint:build": "npx publint",
|
21
|
+
"lint": "tsc --noEmit",
|
14
22
|
"publish-pkg": "node ../../scripts/npm-check-version-and-publish.js"
|
15
23
|
},
|
16
24
|
"files": [
|
17
25
|
"/dist"
|
18
26
|
],
|
19
27
|
"dependencies": {
|
20
|
-
"@triplit/client": "^0.0.
|
28
|
+
"@triplit/client": "^0.0.38-beta.1"
|
21
29
|
},
|
22
30
|
"devDependencies": {
|
23
31
|
"@parcel/config-default": "^2.9.3",
|
package/dist/index.d.ts.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"mappings":";AASA,yBAAyB,EAAE,SAAS,YAAY,GAAG,CAAC,EAClD,MAAM,EAAE,cAAc,GAAG,CAAC,EAC1B,KAAK,EAAE,mBAAmB,EAAE,CAAC,EAC7B,OAAO,CAAC,EAAE,mBAAmB;;;;EAuC9B;AC3CD,0BACE,CAAC,SAAS,OAAO,GAAG,EAAE,GAAG,CAAC,GAAG,SAAS,EACtC,EAAE,SAAS,yBAAyB,CAAC,CAAC,EAEtC,MAAM,EAAE,cAAc,CAAC,CAAC,EACxB,cAAc,EAAE,EAAE,EAClB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,mBAAmB;;;;EAa9B","sources":["packages/react/src/src/use-query.ts","packages/react/src/src/use-entity.ts","packages/react/src/src/index.ts","packages/react/src/index.ts"],"sourcesContent":[null,null,null,"export * from './use-query';\nexport * from './use-entity';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;ACSM,SAAU,0CACd,MAA0B,EAC1B,KAA6B,EAC7B,OAA6B;IAE7B,MAAM,CAAC,SAAS,WAAW,GAAG,CAAA,GAAA,qBAAA,EAC5B;IAEF,MAAM,CAAC,UAAU,YAAY,GAAG,CAAA,GAAA,qBAAA,EAAS;IACzC,MAAM,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,qBAAA,EAAc;IAExC,MAAM,aAAa,SAAS,MAAM;IAClC,MAAM,mBAAmB,cAAc,KAAK,UAAU;IAEtD,CAAA,GAAA,sBAAA,EAAU;QACR,IAAI,CAAC,QAAQ;QACb,WAAW;QACX,YAAY;QACZ,MAAM,cAAc,OAAO,UACzB,YACA,CAAC;YACC,YAAY;YACZ,SAAS;YACT,WAAW,IAAI,IAAI;QACrB,GACA,CAAC;YACC,YAAY;YACZ,SAAS;QACX,GACA;QAGF,OAAO;YACL;QACF;IACF,GAAG;QAAC;QAAkB;KAAO;IAE7B,OAAO;kBACL;iBACA;eACA;IACD;AACH;;;;;;;AC3CM,SAAU,0CAId,MAAwB,EACxB,cAAkB,EAClB,EAAU,EACV,OAA6B;IAE7B,MAAM,YAAE,QAAQ,WAAE,OAAO,SAAE,KAAK,EAAE,GAAG,CAAA,GAAA,yCAAA,EACnC,QACA,6KAA6K;IAC7K,OAAO,MAAM,gBAAgB,SAAS,KACtC;IAEF,OAAO;kBACL;QACA,SAAS,UAAU,QAAQ,IAAI,MAAM;eACrC;IACD;AACH;;","sources":["packages/react/src/index.ts","packages/react/src/use-query.ts","packages/react/src/use-entity.ts"],"sourcesContent":["export * from './use-query';\nexport * from './use-entity';\n","import { useEffect, useState } from 'react';\nimport {\n FetchResult,\n TriplitClient,\n ClientQuery,\n ClientQueryBuilder,\n SubscriptionOptions,\n} from '@triplit/client';\n\nexport function useQuery<CQ extends ClientQuery<any>>(\n client: TriplitClient<any>,\n query: ClientQueryBuilder<CQ>,\n options?: SubscriptionOptions\n) {\n const [results, setResults] = useState<FetchResult<CQ> | undefined>(\n undefined\n );\n const [fetching, setFetching] = useState(true);\n const [error, setError] = useState<any>(undefined);\n\n const builtQuery = query && query.build();\n const stringifiedQuery = builtQuery && JSON.stringify(builtQuery);\n\n useEffect(() => {\n if (!client) return;\n setResults(undefined);\n setFetching(true);\n const unsubscribe = client.subscribe(\n builtQuery,\n (localResults) => {\n setFetching(false);\n setError(undefined);\n setResults(new Map(localResults) as FetchResult<CQ>);\n },\n (error) => {\n setFetching(false);\n setError(error);\n },\n options\n );\n\n return () => {\n unsubscribe();\n };\n }, [stringifiedQuery, client]);\n\n return {\n fetching,\n results,\n error,\n };\n}\n","import {\n TriplitClient,\n Models,\n CollectionNameFromModels,\n SubscriptionOptions,\n} from '@triplit/client';\nimport { useQuery } from './use-query';\n\nexport function useEntity<\n M extends Models<any, any> | undefined,\n CN extends CollectionNameFromModels<M>\n>(\n client: TriplitClient<M>,\n collectionName: CN,\n id: string,\n options?: SubscriptionOptions\n) {\n const { fetching, results, error } = useQuery(\n client,\n // @ts-ignore TODO: generics getting weird with models and collection queries...probably worth refactoring when we have joins (as we'll need to redo some typing then anyway)\n client.query(collectionName).entityId(id),\n options\n );\n return {\n fetching,\n results: results ? results.get(id) : undefined,\n error,\n };\n}\n"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/module.js
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
import {useState as $3QJOh$useState, useEffect as $3QJOh$useEffect} from "react";
|
2
|
-
|
3
|
-
function $parcel$export(e, n, v, s) {
|
4
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
5
|
-
}
|
6
|
-
var $c765280007267fba$exports = {};
|
7
|
-
|
8
|
-
$parcel$export($c765280007267fba$exports, "useQuery", () => $c765280007267fba$export$dd0a697e1782aedd);
|
9
|
-
|
10
|
-
function $c765280007267fba$export$dd0a697e1782aedd(client, query, options) {
|
11
|
-
const [results, setResults] = (0, $3QJOh$useState)(undefined);
|
12
|
-
const [fetching, setFetching] = (0, $3QJOh$useState)(true);
|
13
|
-
const [error, setError] = (0, $3QJOh$useState)(undefined);
|
14
|
-
const builtQuery = query && query.build();
|
15
|
-
const stringifiedQuery = builtQuery && JSON.stringify(builtQuery);
|
16
|
-
(0, $3QJOh$useEffect)(()=>{
|
17
|
-
if (!client) return;
|
18
|
-
setResults(undefined);
|
19
|
-
setFetching(true);
|
20
|
-
const unsubscribe = client.subscribe(builtQuery, (localResults)=>{
|
21
|
-
setFetching(false);
|
22
|
-
setError(undefined);
|
23
|
-
setResults(new Map(localResults));
|
24
|
-
}, (error)=>{
|
25
|
-
setFetching(false);
|
26
|
-
setError(error);
|
27
|
-
}, options);
|
28
|
-
return ()=>{
|
29
|
-
unsubscribe();
|
30
|
-
};
|
31
|
-
}, [
|
32
|
-
stringifiedQuery,
|
33
|
-
client
|
34
|
-
]);
|
35
|
-
return {
|
36
|
-
fetching: fetching,
|
37
|
-
results: results,
|
38
|
-
error: error
|
39
|
-
};
|
40
|
-
}
|
41
|
-
|
42
|
-
|
43
|
-
var $8f8fbf6d34fed11e$exports = {};
|
44
|
-
|
45
|
-
$parcel$export($8f8fbf6d34fed11e$exports, "useEntity", () => $8f8fbf6d34fed11e$export$fab329b658bf30c7);
|
46
|
-
|
47
|
-
function $8f8fbf6d34fed11e$export$fab329b658bf30c7(client, collectionName, id, options) {
|
48
|
-
const { fetching: fetching, results: results, error: error } = (0, $c765280007267fba$export$dd0a697e1782aedd)(client, // @ts-ignore TODO: generics getting weird with models and collection queries...probably worth refactoring when we have joins (as we'll need to redo some typing then anyway)
|
49
|
-
client.query(collectionName).entityId(id), options);
|
50
|
-
return {
|
51
|
-
fetching: fetching,
|
52
|
-
results: results ? results.get(id) : undefined,
|
53
|
-
error: error
|
54
|
-
};
|
55
|
-
}
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
export {$c765280007267fba$export$dd0a697e1782aedd as useQuery, $8f8fbf6d34fed11e$export$fab329b658bf30c7 as useEntity};
|
61
|
-
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"mappings":";;;;;;;;;ACSM,SAAU,0CACd,MAA0B,EAC1B,KAA6B,EAC7B,OAA6B;IAE7B,MAAM,CAAC,SAAS,WAAW,GAAG,CAAA,GAAA,eAAA,EAC5B;IAEF,MAAM,CAAC,UAAU,YAAY,GAAG,CAAA,GAAA,eAAA,EAAS;IACzC,MAAM,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,eAAA,EAAc;IAExC,MAAM,aAAa,SAAS,MAAM;IAClC,MAAM,mBAAmB,cAAc,KAAK,UAAU;IAEtD,CAAA,GAAA,gBAAA,EAAU;QACR,IAAI,CAAC,QAAQ;QACb,WAAW;QACX,YAAY;QACZ,MAAM,cAAc,OAAO,UACzB,YACA,CAAC;YACC,YAAY;YACZ,SAAS;YACT,WAAW,IAAI,IAAI;QACrB,GACA,CAAC;YACC,YAAY;YACZ,SAAS;QACX,GACA;QAGF,OAAO;YACL;QACF;IACF,GAAG;QAAC;QAAkB;KAAO;IAE7B,OAAO;kBACL;iBACA;eACA;IACD;AACH;;;;;;;AC3CM,SAAU,0CAId,MAAwB,EACxB,cAAkB,EAClB,EAAU,EACV,OAA6B;IAE7B,MAAM,YAAE,QAAQ,WAAE,OAAO,SAAE,KAAK,EAAE,GAAG,CAAA,GAAA,yCAAA,EACnC,QACA,6KAA6K;IAC7K,OAAO,MAAM,gBAAgB,SAAS,KACtC;IAEF,OAAO;kBACL;QACA,SAAS,UAAU,QAAQ,IAAI,MAAM;eACrC;IACD;AACH;;","sources":["packages/react/src/index.ts","packages/react/src/use-query.ts","packages/react/src/use-entity.ts"],"sourcesContent":["export * from './use-query';\nexport * from './use-entity';\n","import { useEffect, useState } from 'react';\nimport {\n FetchResult,\n TriplitClient,\n ClientQuery,\n ClientQueryBuilder,\n SubscriptionOptions,\n} from '@triplit/client';\n\nexport function useQuery<CQ extends ClientQuery<any>>(\n client: TriplitClient<any>,\n query: ClientQueryBuilder<CQ>,\n options?: SubscriptionOptions\n) {\n const [results, setResults] = useState<FetchResult<CQ> | undefined>(\n undefined\n );\n const [fetching, setFetching] = useState(true);\n const [error, setError] = useState<any>(undefined);\n\n const builtQuery = query && query.build();\n const stringifiedQuery = builtQuery && JSON.stringify(builtQuery);\n\n useEffect(() => {\n if (!client) return;\n setResults(undefined);\n setFetching(true);\n const unsubscribe = client.subscribe(\n builtQuery,\n (localResults) => {\n setFetching(false);\n setError(undefined);\n setResults(new Map(localResults) as FetchResult<CQ>);\n },\n (error) => {\n setFetching(false);\n setError(error);\n },\n options\n );\n\n return () => {\n unsubscribe();\n };\n }, [stringifiedQuery, client]);\n\n return {\n fetching,\n results,\n error,\n };\n}\n","import {\n TriplitClient,\n Models,\n CollectionNameFromModels,\n SubscriptionOptions,\n} from '@triplit/client';\nimport { useQuery } from './use-query';\n\nexport function useEntity<\n M extends Models<any, any> | undefined,\n CN extends CollectionNameFromModels<M>\n>(\n client: TriplitClient<M>,\n collectionName: CN,\n id: string,\n options?: SubscriptionOptions\n) {\n const { fetching, results, error } = useQuery(\n client,\n // @ts-ignore TODO: generics getting weird with models and collection queries...probably worth refactoring when we have joins (as we'll need to redo some typing then anyway)\n client.query(collectionName).entityId(id),\n options\n );\n return {\n fetching,\n results: results ? results.get(id) : undefined,\n error,\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|