flowerbi-react 2.0.0 → 3.1.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/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAgC;AAChC,mDAAiC;AACjC,gDAA8B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,mDAAiC;AACjC,gDAA8B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flowerbi-react",
3
- "version": "2.0.0",
3
+ "version": "3.1.0",
4
4
  "author": "Daniel Earwicker <dan@earwicker.com>",
5
5
  "license": "MIT",
6
6
  "description": "React helpers for FlowerBI",
@@ -9,7 +9,7 @@
9
9
  "dependencies": {
10
10
  "@types/json-stable-stringify": "^1.0.32",
11
11
  "@types/react": "^16.9.0",
12
- "flowerbi": "2.0.0",
12
+ "flowerbi": "3.1.0",
13
13
  "json-stable-stringify": "^1.0.1"
14
14
  },
15
15
  "devDependencies": {
@@ -1,46 +0,0 @@
1
- import { Query, QueryFetch, QuerySelect, ExpandedQueryResult } from "flowerbi";
2
- export declare type UseQueryState = "init" | "ready" | "refresh" | "error";
3
- export interface UseQueryResult<S extends QuerySelect> extends ExpandedQueryResult<S> {
4
- /**
5
- * The state of the query operation:
6
- *
7
- * - `init` - no result has been downloaded yet
8
- * - `ready` - result has been downloaded
9
- * - `refresh` - a new result is being downloaded
10
- * - `error` - most recent query attempt failed
11
- */
12
- state: UseQueryState;
13
- }
14
- /**
15
- * Defines another query on which our query depends - for example a
16
- * first query may return the top 10 vendors, and a subsequent query
17
- * may then use an `in` filter to get details about those 10 vendors.
18
- */
19
- export declare type QueryDependency = {
20
- /**
21
- * The result of the query we depend on
22
- */
23
- dependency: UseQueryResult<QuerySelect>;
24
- /**
25
- * If true (default is false) then if the dependency query produces
26
- * an empty result, our query should also produce an empty result,
27
- * so there is no need to execute it.
28
- */
29
- nonEmpty?: boolean;
30
- };
31
- /**
32
- * A custom React hook that evaluates to the result of a
33
- * [Query](../flowerbi/interfaces/query.html), making it easy to perform a
34
- * query from within a component.
35
- *
36
- * The returned object has a strongly-typed `records` array, and optionally
37
- * a `totals` object. It has a `state` of type {@link UseQueryState} that
38
- * can be used to show a loading indicator.
39
- *
40
- * @param fetch The fetch function to use.
41
- * @param query The [Query](../flowerbi/interfaces/query.html) specification.
42
- * @param dependencies Optionally, a list of one or more other queries whose
43
- * results are used to build this query, so we wait for them before executing,
44
- * and optionally short-circuit to an empty result if the dependency is empty.
45
- */
46
- export declare function useQuery<S extends QuerySelect>(fetch: QueryFetch, query: Query<S>, dependencies?: QueryDependency[]): UseQueryResult<S>;
package/dist/useQuery.js DELETED
@@ -1,78 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.useQuery = void 0;
18
- var react_1 = require("react");
19
- var flowerbi_1 = require("flowerbi");
20
- var json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
21
- /**
22
- * A custom React hook that evaluates to the result of a
23
- * [Query](../flowerbi/interfaces/query.html), making it easy to perform a
24
- * query from within a component.
25
- *
26
- * The returned object has a strongly-typed `records` array, and optionally
27
- * a `totals` object. It has a `state` of type {@link UseQueryState} that
28
- * can be used to show a loading indicator.
29
- *
30
- * @param fetch The fetch function to use.
31
- * @param query The [Query](../flowerbi/interfaces/query.html) specification.
32
- * @param dependencies Optionally, a list of one or more other queries whose
33
- * results are used to build this query, so we wait for them before executing,
34
- * and optionally short-circuit to an empty result if the dependency is empty.
35
- */
36
- function useQuery(fetch, query, dependencies) {
37
- var queryJson = (0, flowerbi_1.jsonifyQuery)(query);
38
- var _a = (0, react_1.useState)("init"), state = _a[0], setState = _a[1];
39
- var _b = (0, react_1.useState)({ records: [] }), result = _b[0], setResult = _b[1];
40
- (0, react_1.useEffect)(function () {
41
- var disposed = false; // discard stale results
42
- if (dependencies === null || dependencies === void 0 ? void 0 : dependencies.length) {
43
- // if any not ready, neither are we
44
- if (dependencies.some(function (x) { return x.dependency.state !== "ready"; })) {
45
- if (state !== "init") {
46
- setState("refresh");
47
- }
48
- return;
49
- }
50
- // if any with option nonEmpty produced empty result, so do we
51
- if (dependencies.filter(function (x) { return !!x.nonEmpty; }).some(function (x) { return !x.dependency.records.length; })) {
52
- setState("ready");
53
- setResult({ records: [] });
54
- return;
55
- }
56
- }
57
- if (state !== "init") {
58
- setState("refresh");
59
- }
60
- fetch(queryJson).then(function (x) {
61
- if (!disposed) {
62
- setState("ready");
63
- setResult(x);
64
- }
65
- }, function () {
66
- if (!disposed) {
67
- setState("error");
68
- }
69
- });
70
- return function () {
71
- disposed = true;
72
- };
73
- // eslint-disable-next-line react-hooks/exhaustive-deps
74
- }, [fetch, (0, json_stable_stringify_1.default)(queryJson)]);
75
- return __assign(__assign({}, (0, flowerbi_1.expandQueryResult)(query.select, result)), { state: state });
76
- }
77
- exports.useQuery = useQuery;
78
- //# sourceMappingURL=useQuery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../src/useQuery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAAoD;AACpD,qCAAiI;AACjI,gFAAoD;AAkCpD;;;;;;;;;;;;;;GAcG;AACH,SAAgB,QAAQ,CAAwB,KAAiB,EAAE,KAAe,EAAE,YAAgC;IAChH,IAAM,SAAS,GAAG,IAAA,uBAAY,EAAC,KAAK,CAAC,CAAC;IAEhC,IAAA,KAAoB,IAAA,gBAAQ,EAAgB,MAAM,CAAC,EAAlD,KAAK,QAAA,EAAE,QAAQ,QAAmC,CAAC;IACpD,IAAA,KAAsB,IAAA,gBAAQ,EAAkB,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,EAA/D,MAAM,QAAA,EAAE,SAAS,QAA8C,CAAC;IAEvE,IAAA,iBAAS,EAAC;QACN,IAAI,QAAQ,GAAG,KAAK,CAAC,CAAC,wBAAwB;QAE9C,IAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,EAAE;YACtB,mCAAmC;YACnC,IAAI,YAAY,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,UAAU,CAAC,KAAK,KAAK,OAAO,EAA9B,CAA8B,CAAC,EAAE;gBACxD,IAAI,KAAK,KAAK,MAAM,EAAE;oBAClB,QAAQ,CAAC,SAAS,CAAC,CAAC;iBACvB;gBACD,OAAO;aACV;YAED,8DAA8D;YAC9D,IAAI,YAAY,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAZ,CAAY,CAAC,CAAC,IAAI,CAAC,UAAA,CAAC,I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