@triplit/react 0.0.35 → 0.0.37

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @triplit/react
2
2
 
3
+ ## 0.0.37
4
+
5
+ ### Patch Changes
6
+
7
+ - af14ded: - Add fetch policy options
8
+ - Bug fixes
9
+ - Performance improvements
10
+ - Updated dependencies [af14ded]
11
+ - Updated dependencies [dfa258c]
12
+ - Updated dependencies [af14ded]
13
+ - @triplit/client@0.0.37
14
+
15
+ ## 0.0.36
16
+
17
+ ### Patch Changes
18
+
19
+ - 6df3de6: Update CLI to support HTTPS
20
+ - Updated dependencies [6df3de6]
21
+ - @triplit/client@0.0.36
22
+
3
23
  ## 0.0.32
4
24
 
5
25
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { FetchResult, TriplitClient, ClientQuery, toBuilder, Models, CollectionNameFromModels } from "@triplit/client";
2
- export function useQuery<CQ extends ClientQuery<any>>(client: TriplitClient<any>, query: toBuilder<CQ>): {
3
- fetchingLocal: boolean;
1
+ import { FetchResult, TriplitClient, ClientQuery, ClientQueryBuilder, SubscriptionOptions, Models, CollectionNameFromModels } from "@triplit/client";
2
+ export function useQuery<CQ extends ClientQuery<any>>(client: TriplitClient<any>, query: ClientQueryBuilder<CQ>, options?: SubscriptionOptions): {
3
+ fetching: boolean;
4
4
  results: FetchResult<CQ> | undefined;
5
5
  error: any;
6
6
  };
7
- export function useEntity<M extends Models<any, any> | undefined, CN extends CollectionNameFromModels<M>>(client: TriplitClient<M>, collectionName: CN, id: string): {
8
- fetchingLocal: boolean;
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
9
  results: any;
10
10
  error: any;
11
11
  };
@@ -1 +1 @@
1
- {"mappings":";AAQA,yBAAyB,EAAE,SAAS,YAAY,GAAG,CAAC,EAClD,MAAM,EAAE,cAAc,GAAG,CAAC,EAC1B,KAAK,EAAE,UAAU,EAAE,CAAC;;;;EAwCrB;AC3CD,0BACE,CAAC,SAAS,OAAO,GAAG,EAAE,GAAG,CAAC,GAAG,SAAS,EACtC,EAAE,SAAS,yBAAyB,CAAC,CAAC,EACtC,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM;;;;EAUzD","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"}
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 CHANGED
@@ -23,25 +23,24 @@ var $8789f74c7c312f3c$exports = {};
23
23
 
24
24
  $parcel$export($8789f74c7c312f3c$exports, "useQuery", () => $8789f74c7c312f3c$export$dd0a697e1782aedd);
25
25
 
26
- function $8789f74c7c312f3c$export$dd0a697e1782aedd(client, query) {
26
+ function $8789f74c7c312f3c$export$dd0a697e1782aedd(client, query, options) {
27
27
  const [results, setResults] = (0, $2yxZb$react.useState)(undefined);
28
- const [fetchingLocal, setFetchingLocal] = (0, $2yxZb$react.useState)(false);
28
+ const [fetching, setFetching] = (0, $2yxZb$react.useState)(true);
29
29
  const [error, setError] = (0, $2yxZb$react.useState)(undefined);
30
- // const [fetchingRemote, setFetchingRemote] = useState(false);
31
30
  const builtQuery = query && query.build();
32
31
  const stringifiedQuery = builtQuery && JSON.stringify(builtQuery);
33
32
  (0, $2yxZb$react.useEffect)(()=>{
34
33
  if (!client) return;
35
34
  setResults(undefined);
36
- setFetchingLocal(true);
35
+ setFetching(true);
37
36
  const unsubscribe = client.subscribe(builtQuery, (localResults)=>{
38
- setFetchingLocal(false);
37
+ setFetching(false);
39
38
  setError(undefined);
40
- setResults(localResults);
39
+ setResults(new Map(localResults));
41
40
  }, (error)=>{
42
- setFetchingLocal(false);
41
+ setFetching(false);
43
42
  setError(error);
44
- });
43
+ }, options);
45
44
  return ()=>{
46
45
  unsubscribe();
47
46
  };
@@ -50,9 +49,8 @@ function $8789f74c7c312f3c$export$dd0a697e1782aedd(client, query) {
50
49
  client
51
50
  ]);
52
51
  return {
53
- fetchingLocal: fetchingLocal,
54
- results: // fetchingRemote,
55
- results,
52
+ fetching: fetching,
53
+ results: results,
56
54
  error: error
57
55
  };
58
56
  }
@@ -62,10 +60,11 @@ var $6ea15837a6dcd4eb$exports = {};
62
60
 
63
61
  $parcel$export($6ea15837a6dcd4eb$exports, "useEntity", () => $6ea15837a6dcd4eb$export$fab329b658bf30c7);
64
62
 
65
- function $6ea15837a6dcd4eb$export$fab329b658bf30c7(client, collectionName, id) {
66
- const { fetchingLocal: fetchingLocal, results: results, error: error } = (0, $8789f74c7c312f3c$export$dd0a697e1782aedd)(client, client.query(collectionName).entityId(id));
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);
67
66
  return {
68
- fetchingLocal: fetchingLocal,
67
+ fetching: fetching,
69
68
  results: results ? results.get(id) : undefined,
70
69
  error: error
71
70
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;ACQM,SAAU,0CACd,MAA0B,EAC1B,KAAoB;IAEpB,MAAM,CAAC,SAAS,WAAW,GAAG,CAAA,GAAA,qBAAA,EAC5B;IAEF,MAAM,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,qBAAA,EAAS;IACnD,MAAM,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,qBAAA,EAAc;IACxC,+DAA+D;IAE/D,MAAM,aAAa,SAAS,MAAM;IAClC,MAAM,mBAAmB,cAAc,KAAK,UAAU;IAEtD,CAAA,GAAA,sBAAA,EAAU;QACR,IAAI,CAAC,QAAQ;QACb,WAAW;QACX,iBAAiB;QACjB,MAAM,cAAc,OAAO,UACzB,YACA,CAAC;YACC,iBAAiB;YACjB,SAAS;YACT,WAAW;QACb,GACA,CAAC;YACC,iBAAiB;YACjB,SAAS;QACX;QAGF,OAAO;YACL;QACF;IACF,GAAG;QAAC;QAAkB;KAAO;IAE7B,OAAO;uBACL;iBAEA,AADA,kBAAkB;QAClB;eACA;IACD;AACH;;;;;;;AC3CM,SAAU,0CAGd,MAAwB,EAAE,cAAkB,EAAE,EAAU;IACxD,MAAM,iBAAE,aAAa,WAAE,OAAO,SAAE,KAAK,EAAE,GAAG,CAAA,GAAA,yCAAA,EACxC,QACA,OAAO,MAAM,gBAAgB,SAAS;IAExC,OAAO;uBACL;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 toBuilder,\n} from '@triplit/client';\n\nexport function useQuery<CQ extends ClientQuery<any>>(\n client: TriplitClient<any>,\n query: toBuilder<CQ>\n) {\n const [results, setResults] = useState<FetchResult<CQ> | undefined>(\n undefined\n );\n const [fetchingLocal, setFetchingLocal] = useState(false);\n const [error, setError] = useState<any>(undefined);\n // const [fetchingRemote, setFetchingRemote] = useState(false);\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 setFetchingLocal(true);\n const unsubscribe = client.subscribe(\n builtQuery,\n (localResults) => {\n setFetchingLocal(false);\n setError(undefined);\n setResults(localResults);\n },\n (error) => {\n setFetchingLocal(false);\n setError(error);\n }\n );\n\n return () => {\n unsubscribe();\n };\n }, [stringifiedQuery, client]);\n\n return {\n fetchingLocal,\n // fetchingRemote,\n results,\n error,\n };\n}\n","import {\n TriplitClient,\n Models,\n CollectionNameFromModels,\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>(client: TriplitClient<M>, collectionName: CN, id: string) {\n const { fetchingLocal, results, error } = useQuery(\n client,\n client.query(collectionName).entityId(id)\n );\n return {\n fetchingLocal,\n results: results ? results.get(id) : undefined,\n error,\n };\n}\n"],"names":[],"version":3,"file":"index.js.map"}
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 CHANGED
@@ -7,25 +7,24 @@ var $c765280007267fba$exports = {};
7
7
 
8
8
  $parcel$export($c765280007267fba$exports, "useQuery", () => $c765280007267fba$export$dd0a697e1782aedd);
9
9
 
10
- function $c765280007267fba$export$dd0a697e1782aedd(client, query) {
10
+ function $c765280007267fba$export$dd0a697e1782aedd(client, query, options) {
11
11
  const [results, setResults] = (0, $3QJOh$useState)(undefined);
12
- const [fetchingLocal, setFetchingLocal] = (0, $3QJOh$useState)(false);
12
+ const [fetching, setFetching] = (0, $3QJOh$useState)(true);
13
13
  const [error, setError] = (0, $3QJOh$useState)(undefined);
14
- // const [fetchingRemote, setFetchingRemote] = useState(false);
15
14
  const builtQuery = query && query.build();
16
15
  const stringifiedQuery = builtQuery && JSON.stringify(builtQuery);
17
16
  (0, $3QJOh$useEffect)(()=>{
18
17
  if (!client) return;
19
18
  setResults(undefined);
20
- setFetchingLocal(true);
19
+ setFetching(true);
21
20
  const unsubscribe = client.subscribe(builtQuery, (localResults)=>{
22
- setFetchingLocal(false);
21
+ setFetching(false);
23
22
  setError(undefined);
24
- setResults(localResults);
23
+ setResults(new Map(localResults));
25
24
  }, (error)=>{
26
- setFetchingLocal(false);
25
+ setFetching(false);
27
26
  setError(error);
28
- });
27
+ }, options);
29
28
  return ()=>{
30
29
  unsubscribe();
31
30
  };
@@ -34,9 +33,8 @@ function $c765280007267fba$export$dd0a697e1782aedd(client, query) {
34
33
  client
35
34
  ]);
36
35
  return {
37
- fetchingLocal: fetchingLocal,
38
- results: // fetchingRemote,
39
- results,
36
+ fetching: fetching,
37
+ results: results,
40
38
  error: error
41
39
  };
42
40
  }
@@ -46,10 +44,11 @@ var $8f8fbf6d34fed11e$exports = {};
46
44
 
47
45
  $parcel$export($8f8fbf6d34fed11e$exports, "useEntity", () => $8f8fbf6d34fed11e$export$fab329b658bf30c7);
48
46
 
49
- function $8f8fbf6d34fed11e$export$fab329b658bf30c7(client, collectionName, id) {
50
- const { fetchingLocal: fetchingLocal, results: results, error: error } = (0, $c765280007267fba$export$dd0a697e1782aedd)(client, client.query(collectionName).entityId(id));
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);
51
50
  return {
52
- fetchingLocal: fetchingLocal,
51
+ fetching: fetching,
53
52
  results: results ? results.get(id) : undefined,
54
53
  error: error
55
54
  };
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;ACQM,SAAU,0CACd,MAA0B,EAC1B,KAAoB;IAEpB,MAAM,CAAC,SAAS,WAAW,GAAG,CAAA,GAAA,eAAA,EAC5B;IAEF,MAAM,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,eAAA,EAAS;IACnD,MAAM,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,eAAA,EAAc;IACxC,+DAA+D;IAE/D,MAAM,aAAa,SAAS,MAAM;IAClC,MAAM,mBAAmB,cAAc,KAAK,UAAU;IAEtD,CAAA,GAAA,gBAAA,EAAU;QACR,IAAI,CAAC,QAAQ;QACb,WAAW;QACX,iBAAiB;QACjB,MAAM,cAAc,OAAO,UACzB,YACA,CAAC;YACC,iBAAiB;YACjB,SAAS;YACT,WAAW;QACb,GACA,CAAC;YACC,iBAAiB;YACjB,SAAS;QACX;QAGF,OAAO;YACL;QACF;IACF,GAAG;QAAC;QAAkB;KAAO;IAE7B,OAAO;uBACL;iBAEA,AADA,kBAAkB;QAClB;eACA;IACD;AACH;;;;;;;AC3CM,SAAU,0CAGd,MAAwB,EAAE,cAAkB,EAAE,EAAU;IACxD,MAAM,iBAAE,aAAa,WAAE,OAAO,SAAE,KAAK,EAAE,GAAG,CAAA,GAAA,yCAAA,EACxC,QACA,OAAO,MAAM,gBAAgB,SAAS;IAExC,OAAO;uBACL;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 toBuilder,\n} from '@triplit/client';\n\nexport function useQuery<CQ extends ClientQuery<any>>(\n client: TriplitClient<any>,\n query: toBuilder<CQ>\n) {\n const [results, setResults] = useState<FetchResult<CQ> | undefined>(\n undefined\n );\n const [fetchingLocal, setFetchingLocal] = useState(false);\n const [error, setError] = useState<any>(undefined);\n // const [fetchingRemote, setFetchingRemote] = useState(false);\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 setFetchingLocal(true);\n const unsubscribe = client.subscribe(\n builtQuery,\n (localResults) => {\n setFetchingLocal(false);\n setError(undefined);\n setResults(localResults);\n },\n (error) => {\n setFetchingLocal(false);\n setError(error);\n }\n );\n\n return () => {\n unsubscribe();\n };\n }, [stringifiedQuery, client]);\n\n return {\n fetchingLocal,\n // fetchingRemote,\n results,\n error,\n };\n}\n","import {\n TriplitClient,\n Models,\n CollectionNameFromModels,\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>(client: TriplitClient<M>, collectionName: CN, id: string) {\n const { fetchingLocal, results, error } = useQuery(\n client,\n client.query(collectionName).entityId(id)\n );\n return {\n fetchingLocal,\n results: results ? results.get(id) : undefined,\n error,\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@triplit/react",
3
3
  "packageManager": "yarn@3.4.1",
4
- "version": "0.0.35",
4
+ "version": "0.0.37",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/module.js",
@@ -17,14 +17,14 @@
17
17
  "/dist"
18
18
  ],
19
19
  "dependencies": {
20
- "@triplit/client": "^0.0.35"
20
+ "@triplit/client": "^0.0.37"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@parcel/config-default": "^2.9.3",
24
24
  "@parcel/transformer-typescript-tsc": "^2.9.3",
25
25
  "@types/react": "^18.2.0",
26
26
  "parcel": "^2.9.3",
27
- "typescript": "^5.0.2"
27
+ "typescript": "^5.2.2"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "react": "*",