@triplit/react 0.0.36 → 0.0.38-beta.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
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
+
3
15
  ## 0.0.36
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -1,30 +1,38 @@
1
1
  {
2
2
  "name": "@triplit/react",
3
3
  "packageManager": "yarn@3.4.1",
4
- "version": "0.0.36",
5
- "source": "src/index.ts",
6
- "main": "dist/index.js",
7
- "module": "dist/module.js",
8
- "types": "dist/index.d.ts",
4
+ "version": "0.0.38-beta.0",
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": "yarn build:setup && parcel build . --no-cache && yarn build:cleanup",
11
- "build:setup": "mv tsconfig.json tsconfig.tmp.json && mv tsconfig.build.json tsconfig.json",
12
- "build:cleanup": "mv tsconfig.json tsconfig.build.json && mv tsconfig.tmp.json tsconfig.json",
13
- "lint": "tsc",
19
+ "build": "tsc -b",
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.36"
28
+ "@triplit/client": "^0.0.38-beta.0"
21
29
  },
22
30
  "devDependencies": {
23
31
  "@parcel/config-default": "^2.9.3",
24
32
  "@parcel/transformer-typescript-tsc": "^2.9.3",
25
33
  "@types/react": "^18.2.0",
26
34
  "parcel": "^2.9.3",
27
- "typescript": "^5.0.2"
35
+ "typescript": "^5.2.2"
28
36
  },
29
37
  "peerDependencies": {
30
38
  "react": "*",
package/dist/index.d.ts DELETED
@@ -1,13 +0,0 @@
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;
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): {
8
- fetchingLocal: boolean;
9
- results: any;
10
- error: any;
11
- };
12
-
13
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
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"}
package/dist/index.js DELETED
@@ -1,79 +0,0 @@
1
- var $2yxZb$react = require("react");
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) {
27
- const [results, setResults] = (0, $2yxZb$react.useState)(undefined);
28
- const [fetchingLocal, setFetchingLocal] = (0, $2yxZb$react.useState)(false);
29
- const [error, setError] = (0, $2yxZb$react.useState)(undefined);
30
- // const [fetchingRemote, setFetchingRemote] = useState(false);
31
- const builtQuery = query && query.build();
32
- const stringifiedQuery = builtQuery && JSON.stringify(builtQuery);
33
- (0, $2yxZb$react.useEffect)(()=>{
34
- if (!client) return;
35
- setResults(undefined);
36
- setFetchingLocal(true);
37
- const unsubscribe = client.subscribe(builtQuery, (localResults)=>{
38
- setFetchingLocal(false);
39
- setError(undefined);
40
- setResults(localResults);
41
- }, (error)=>{
42
- setFetchingLocal(false);
43
- setError(error);
44
- });
45
- return ()=>{
46
- unsubscribe();
47
- };
48
- }, [
49
- stringifiedQuery,
50
- client
51
- ]);
52
- return {
53
- fetchingLocal: fetchingLocal,
54
- results: // fetchingRemote,
55
- results,
56
- error: error
57
- };
58
- }
59
-
60
-
61
- var $6ea15837a6dcd4eb$exports = {};
62
-
63
- $parcel$export($6ea15837a6dcd4eb$exports, "useEntity", () => $6ea15837a6dcd4eb$export$fab329b658bf30c7);
64
-
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));
67
- return {
68
- fetchingLocal: fetchingLocal,
69
- results: results ? results.get(id) : undefined,
70
- error: error
71
- };
72
- }
73
-
74
-
75
- $parcel$exportWildcard(module.exports, $8789f74c7c312f3c$exports);
76
- $parcel$exportWildcard(module.exports, $6ea15837a6dcd4eb$exports);
77
-
78
-
79
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
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"}
package/dist/module.js DELETED
@@ -1,62 +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) {
11
- const [results, setResults] = (0, $3QJOh$useState)(undefined);
12
- const [fetchingLocal, setFetchingLocal] = (0, $3QJOh$useState)(false);
13
- const [error, setError] = (0, $3QJOh$useState)(undefined);
14
- // const [fetchingRemote, setFetchingRemote] = useState(false);
15
- const builtQuery = query && query.build();
16
- const stringifiedQuery = builtQuery && JSON.stringify(builtQuery);
17
- (0, $3QJOh$useEffect)(()=>{
18
- if (!client) return;
19
- setResults(undefined);
20
- setFetchingLocal(true);
21
- const unsubscribe = client.subscribe(builtQuery, (localResults)=>{
22
- setFetchingLocal(false);
23
- setError(undefined);
24
- setResults(localResults);
25
- }, (error)=>{
26
- setFetchingLocal(false);
27
- setError(error);
28
- });
29
- return ()=>{
30
- unsubscribe();
31
- };
32
- }, [
33
- stringifiedQuery,
34
- client
35
- ]);
36
- return {
37
- fetchingLocal: fetchingLocal,
38
- results: // fetchingRemote,
39
- results,
40
- error: error
41
- };
42
- }
43
-
44
-
45
- var $8f8fbf6d34fed11e$exports = {};
46
-
47
- $parcel$export($8f8fbf6d34fed11e$exports, "useEntity", () => $8f8fbf6d34fed11e$export$fab329b658bf30c7);
48
-
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));
51
- return {
52
- fetchingLocal: fetchingLocal,
53
- results: results ? results.get(id) : undefined,
54
- error: error
55
- };
56
- }
57
-
58
-
59
-
60
-
61
- export {$c765280007267fba$export$dd0a697e1782aedd as useQuery, $8f8fbf6d34fed11e$export$fab329b658bf30c7 as useEntity};
62
- //# sourceMappingURL=module.js.map
@@ -1 +0,0 @@
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"}