@colixsystems/widget-sdk 0.331.1 → 0.332.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 +17 -3
- package/dist/contract.cjs +12 -6
- package/dist/contract.js +12 -6
- package/dist/index.d.ts +7 -3
- package/dist/linter.cjs +53 -0
- package/dist/linter.js +53 -0
- package/dist/stats-hooks.js +5 -2
- package/package.json +1 -1
- package/src/contract.js +12 -6
package/README.md
CHANGED
|
@@ -91,7 +91,21 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
91
91
|
|
|
92
92
|
## Status
|
|
93
93
|
|
|
94
|
-
`v0.
|
|
94
|
+
`v0.332.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
|
|
95
|
+
|
|
96
|
+
### What's new in 0.332.0 (contract 1.271.0)
|
|
97
|
+
|
|
98
|
+
**Count rows per related row: `useDatastoreAggregate` groups by a relation column.** `groupBy` may now name a RELATION column, so "how many recipes per category" is one call. Each entry's `group` is the related row's id: match it to that table's `row.id` to show its name. A MANY_TO_MANY relation counts a row once per row it links to. Rows with no related row, or whose related row was deleted, form the `Uncategorized` group. Encrypted, array and file columns still cannot be grouped.
|
|
99
|
+
|
|
100
|
+
**New linter rule `aggregate-error-not-read` (severity `warning`).** A widget that reads an aggregate's `groups` or `buckets` but never its `error` shows a zero per group when the aggregate is refused or fails. Render `error.message` instead. Reading `error` under another name, or as `result.error`, satisfies it.
|
|
101
|
+
|
|
102
|
+
```jsx
|
|
103
|
+
const { groups, error } = useDatastoreAggregate(props.recipesTable, { groupBy: "category" });
|
|
104
|
+
const { data: categories } = useDatastoreQuery(props.categoriesTable);
|
|
105
|
+
if (error) return <Banner tone="error" message={error.message} />;
|
|
106
|
+
const countOf = (id) => groups.find((g) => g.group === id)?.count ?? 0;
|
|
107
|
+
// categories.map((c) => `${c.name}: ${countOf(c.id)}`)
|
|
108
|
+
```
|
|
95
109
|
|
|
96
110
|
### What's new in 0.331.1 (contract 1.270.0)
|
|
97
111
|
|
|
@@ -658,8 +672,8 @@ export default function DarkSwitch() {
|
|
|
658
672
|
**A themed chart: `<Chart>` and Design > Components > Charts.** `<Chart type data />` draws a bar (default), horizontal bar (`hbar`), line, area, donut or sparkline chart whose series colours, axis and gridline colours and bar corners come from the new `chart` theme scope; colours left unset follow the theme, primary first. It measures its own width, holds its place with a `Skeleton` while `loading`, shows an `EmptyState` when there is nothing to plot, adds a legend for a donut or several `series`, thins crowded labels, groups numbers for the app's language, and reads to a screen reader as one image with a summary and the values (`accessibilityLabel` replaces the summary, `moreText` translates its tail). `valueFormat="percent"` expects values already in percent. A chart type it does not draw (a scatter plot, a timeline) is still yours to draw with `react-native-svg`, in the same colours through `chartColors(theme)`.
|
|
659
673
|
|
|
660
674
|
```jsx
|
|
661
|
-
const { groups, loading } = useDatastoreAggregate(tableId, { groupBy: "city", sumColumn: "visits", order: "sum:desc", limit: 10 });
|
|
662
|
-
<Chart type="bar" loading={loading} valueFormat="compact"
|
|
675
|
+
const { groups, loading, error } = useDatastoreAggregate(tableId, { groupBy: "city", sumColumn: "visits", order: "sum:desc", limit: 10 });
|
|
676
|
+
error ? <Banner tone="error" message={error.message} /> : <Chart type="bar" loading={loading} valueFormat="compact"
|
|
663
677
|
data={groups.map((g) => ({ label: String(g.group), value: Number(g.sum) || 0 }))} />
|
|
664
678
|
```
|
|
665
679
|
|
package/dist/contract.cjs
CHANGED
|
@@ -2103,14 +2103,18 @@ const HOOKS = [
|
|
|
2103
2103
|
"(Monday) in `buckets`; `bucket` is \"day\" (default) or \"week\"; " +
|
|
2104
2104
|
"`from` / `to` are ISO dates (default: the 30 days, or 12 weeks, up to " +
|
|
2105
2105
|
"now), at most 31 buckets, empty ones as count 0 so a chart has no gaps. " +
|
|
2106
|
-
"BY A COLUMN (any other `groupBy`: a text, number, yes/no, date or
|
|
2107
|
-
"column): one entry per value in `groups`. A
|
|
2106
|
+
"BY A COLUMN (any other `groupBy`: a text, number, yes/no, date, user or " +
|
|
2107
|
+
"relation column): one entry per value in `groups`. A RELATION column's " +
|
|
2108
|
+
"`group` is the related row's id (match it to that table's row.id); a " +
|
|
2109
|
+
"MANY_TO_MANY row counts once per linked row. A USER column's `group` is the " +
|
|
2108
2110
|
"user id (resolve names with useDirectory({ ids })), so `order: \"count:desc\", " +
|
|
2109
2111
|
"limit: 10` ranks the ten people with the most rows. `order` is count, sum " +
|
|
2110
2112
|
"or group, then :asc or :desc (default: by value); `limit` is 1-1000. Rows " +
|
|
2111
2113
|
"with no value form one \"Uncategorized\" group; on a user column, leave " +
|
|
2112
|
-
"them out with a `nempty:` filter. Encrypted, array
|
|
2113
|
-
"
|
|
2114
|
+
"them out with a `nempty:` filter. Encrypted, array and file columns " +
|
|
2115
|
+
"cannot be grouped (VALIDATION). Check `error` first and render it: after " +
|
|
2116
|
+
"a refused or failed read `groups` may be empty or still hold the last " +
|
|
2117
|
+
"result, so never show it as a zero per group. `filter` takes the same shapes " +
|
|
2114
2118
|
"as useDatastoreQuery's, created_at ranges included. Pass null as the " +
|
|
2115
2119
|
"table until a bound table is known. `live: true` re-reads it when " +
|
|
2116
2120
|
"anyone else changes the table.",
|
|
@@ -2118,7 +2122,7 @@ const HOOKS = [
|
|
|
2118
2122
|
buckets:
|
|
2119
2123
|
"Array<{ date, count, sum }> // date = the bucket's start, YYYY-MM-DD; sum is 0 without sumColumn",
|
|
2120
2124
|
groups:
|
|
2121
|
-
"Array<{ group, count, sum }> // by a column; a USER column's group is the user id",
|
|
2125
|
+
"Array<{ group, count, sum }> // by a column; a USER column's group is the user id, a RELATION column's the related row id",
|
|
2122
2126
|
loading: "boolean",
|
|
2123
2127
|
fetching: "boolean",
|
|
2124
2128
|
error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
|
|
@@ -7067,7 +7071,9 @@ const CONTRACT = deepFreeze({
|
|
|
7067
7071
|
// 1.270.0: additive (sc-17197) — a `datastoreTemplate` column may declare
|
|
7068
7072
|
// `defaultOnCreate: true`: a create stamps its default over any client
|
|
7069
7073
|
// value, and an update may still change it.
|
|
7070
|
-
|
|
7074
|
+
// 1.271.0: additive (sc-17551) — `useDatastoreAggregate` groups by a
|
|
7075
|
+
// relation column; new warning lint `aggregate-error-not-read`.
|
|
7076
|
+
version: "1.271.0",
|
|
7071
7077
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7072
7078
|
hooks: HOOKS,
|
|
7073
7079
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -2098,14 +2098,18 @@ const HOOKS = [
|
|
|
2098
2098
|
"(Monday) in `buckets`; `bucket` is \"day\" (default) or \"week\"; " +
|
|
2099
2099
|
"`from` / `to` are ISO dates (default: the 30 days, or 12 weeks, up to " +
|
|
2100
2100
|
"now), at most 31 buckets, empty ones as count 0 so a chart has no gaps. " +
|
|
2101
|
-
"BY A COLUMN (any other `groupBy`: a text, number, yes/no, date or
|
|
2102
|
-
"column): one entry per value in `groups`. A
|
|
2101
|
+
"BY A COLUMN (any other `groupBy`: a text, number, yes/no, date, user or " +
|
|
2102
|
+
"relation column): one entry per value in `groups`. A RELATION column's " +
|
|
2103
|
+
"`group` is the related row's id (match it to that table's row.id); a " +
|
|
2104
|
+
"MANY_TO_MANY row counts once per linked row. A USER column's `group` is the " +
|
|
2103
2105
|
"user id (resolve names with useDirectory({ ids })), so `order: \"count:desc\", " +
|
|
2104
2106
|
"limit: 10` ranks the ten people with the most rows. `order` is count, sum " +
|
|
2105
2107
|
"or group, then :asc or :desc (default: by value); `limit` is 1-1000. Rows " +
|
|
2106
2108
|
"with no value form one \"Uncategorized\" group; on a user column, leave " +
|
|
2107
|
-
"them out with a `nempty:` filter. Encrypted, array
|
|
2108
|
-
"
|
|
2109
|
+
"them out with a `nempty:` filter. Encrypted, array and file columns " +
|
|
2110
|
+
"cannot be grouped (VALIDATION). Check `error` first and render it: after " +
|
|
2111
|
+
"a refused or failed read `groups` may be empty or still hold the last " +
|
|
2112
|
+
"result, so never show it as a zero per group. `filter` takes the same shapes " +
|
|
2109
2113
|
"as useDatastoreQuery's, created_at ranges included. Pass null as the " +
|
|
2110
2114
|
"table until a bound table is known. `live: true` re-reads it when " +
|
|
2111
2115
|
"anyone else changes the table.",
|
|
@@ -2113,7 +2117,7 @@ const HOOKS = [
|
|
|
2113
2117
|
buckets:
|
|
2114
2118
|
"Array<{ date, count, sum }> // date = the bucket's start, YYYY-MM-DD; sum is 0 without sumColumn",
|
|
2115
2119
|
groups:
|
|
2116
|
-
"Array<{ group, count, sum }> // by a column; a USER column's group is the user id",
|
|
2120
|
+
"Array<{ group, count, sum }> // by a column; a USER column's group is the user id, a RELATION column's the related row id",
|
|
2117
2121
|
loading: "boolean",
|
|
2118
2122
|
fetching: "boolean",
|
|
2119
2123
|
error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
|
|
@@ -7062,7 +7066,9 @@ const CONTRACT = deepFreeze({
|
|
|
7062
7066
|
// 1.270.0: additive (sc-17197) — a `datastoreTemplate` column may declare
|
|
7063
7067
|
// `defaultOnCreate: true`: a create stamps its default over any client
|
|
7064
7068
|
// value, and an update may still change it.
|
|
7065
|
-
|
|
7069
|
+
// 1.271.0: additive (sc-17551) — `useDatastoreAggregate` groups by a
|
|
7070
|
+
// relation column; new warning lint `aggregate-error-not-read`.
|
|
7071
|
+
version: "1.271.0",
|
|
7066
7072
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7067
7073
|
hooks: HOOKS,
|
|
7068
7074
|
primitives: PRIMITIVES,
|
package/dist/index.d.ts
CHANGED
|
@@ -1312,7 +1312,7 @@ export interface AggregateBucketSpec {
|
|
|
1312
1312
|
}
|
|
1313
1313
|
|
|
1314
1314
|
export interface AggregateGroupSpec {
|
|
1315
|
-
/** A text, number, yes/no, date or
|
|
1315
|
+
/** A text, number, yes/no, date, user or relation column. */
|
|
1316
1316
|
groupBy: string;
|
|
1317
1317
|
/** A plain number column to add up per group. */
|
|
1318
1318
|
sumColumn?: string;
|
|
@@ -1334,7 +1334,10 @@ export interface AggregateBucket {
|
|
|
1334
1334
|
}
|
|
1335
1335
|
|
|
1336
1336
|
export interface AggregateGroup {
|
|
1337
|
-
/**
|
|
1337
|
+
/**
|
|
1338
|
+
* The value; a user column's user id; a relation column's related row id
|
|
1339
|
+
* (match it to that table's `row.id`); "Uncategorized" for rows with none.
|
|
1340
|
+
*/
|
|
1338
1341
|
group: string;
|
|
1339
1342
|
count: number;
|
|
1340
1343
|
/** 0 unless `sumColumn` was given. */
|
|
@@ -5578,7 +5581,8 @@ export interface ChartSeries {
|
|
|
5578
5581
|
* for several series, and gives a screen reader a summary and the values.
|
|
5579
5582
|
*
|
|
5580
5583
|
* @example
|
|
5581
|
-
* const { groups, loading } = useDatastoreAggregate(tableId, { groupBy: "city", sumColumn: "visits" });
|
|
5584
|
+
* const { groups, loading, error } = useDatastoreAggregate(tableId, { groupBy: "city", sumColumn: "visits" });
|
|
5585
|
+
* if (error) return <Banner tone="error" message={error.message} />;
|
|
5582
5586
|
* <Chart type="bar" loading={loading}
|
|
5583
5587
|
* data={groups.map((g) => ({ label: String(g.group), value: Number(g.sum) || 0 }))} />
|
|
5584
5588
|
*/
|
package/dist/linter.cjs
CHANGED
|
@@ -2037,6 +2037,58 @@ function _readErrorHandlingRules(source) {
|
|
|
2037
2037
|
];
|
|
2038
2038
|
}
|
|
2039
2039
|
|
|
2040
|
+
// sc-17551 — soft warning: an aggregate a widget reads without its `error`
|
|
2041
|
+
// shows a zero per group, or stale counts, when the server refuses or fails it.
|
|
2042
|
+
// Reading `error` (renamed, as `agg.error`, or re-destructured from `agg`),
|
|
2043
|
+
// handing the whole result on, or a rest spread satisfies it. One pass indexes
|
|
2044
|
+
// the reads, so many bindings stay linear. Known limits: `.groups` read
|
|
2045
|
+
// straight off the call, `catch (error)`, and one file's two components.
|
|
2046
|
+
const AGGREGATE_BINDING_RE = /\b(?:const|let|var)\s+([\w$]+|\{[^{}]*\})\s*=\s*useDatastoreAggregate\s*\(/g;
|
|
2047
|
+
const IDENT = String.raw`[A-Za-z_$][\w$]*`;
|
|
2048
|
+
|
|
2049
|
+
function _aggregateErrorRules(source) {
|
|
2050
|
+
const code = _stripNonCode(source);
|
|
2051
|
+
const calls = [...code.matchAll(AGGREGATE_BINDING_RE)];
|
|
2052
|
+
if (calls.length === 0) return [];
|
|
2053
|
+
// Every hook destructure blanked: another hook's own `error`, and a
|
|
2054
|
+
// binding's own field names, are not reads.
|
|
2055
|
+
const body = code.replace(/\{[^{}]*\}\s*=\s*use\w+\s*\(/g, (m) => " ".repeat(m.length));
|
|
2056
|
+
const words = new Set(body.match(new RegExp(String.raw`(?<![\w$.])${IDENT}`, "g")));
|
|
2057
|
+
const members = new Set(
|
|
2058
|
+
[...body.matchAll(new RegExp(String.raw`(?<![\w$.])(${IDENT})\s*\??\.\s*(${IDENT})`, "g"))].map((m) => `${m[1]}.${m[2]}`),
|
|
2059
|
+
);
|
|
2060
|
+
// `={agg}`, `...agg`, or `= agg;` (an alias or a re-destructure).
|
|
2061
|
+
const handedOn = new Set(
|
|
2062
|
+
[
|
|
2063
|
+
...body.matchAll(
|
|
2064
|
+
new RegExp(String.raw`=\{\s*(${IDENT})\s*\}|\.\.\.\s*(${IDENT})|(?<![=!<>])=\s*(${IDENT})\s*(?:;|$)`, "gm"),
|
|
2065
|
+
),
|
|
2066
|
+
].map((m) => m[1] || m[2] || m[3]),
|
|
2067
|
+
);
|
|
2068
|
+
const findings = [];
|
|
2069
|
+
const lineAt = _lineCounter(code);
|
|
2070
|
+
const sourceLines = source.split(/\r?\n/);
|
|
2071
|
+
for (const call of calls) {
|
|
2072
|
+
const binding = call[1];
|
|
2073
|
+
if (binding.includes("...") || handedOn.has(binding)) continue;
|
|
2074
|
+
const locals = binding.startsWith("{") ? _destructuredLocals(binding) : null;
|
|
2075
|
+
const reads = (field) => (locals ? !!locals[field] && words.has(locals[field]) : members.has(`${binding}.${field}`));
|
|
2076
|
+
if ((!reads("groups") && !reads("buckets")) || reads("error")) continue;
|
|
2077
|
+
const line = lineAt(call.index);
|
|
2078
|
+
findings.push({
|
|
2079
|
+
rule: "aggregate-error-not-read",
|
|
2080
|
+
severity: "warning",
|
|
2081
|
+
label:
|
|
2082
|
+
`reads useDatastoreAggregate() without its error, so a refused or failed ` +
|
|
2083
|
+
`aggregate shows a zero per group. Render error.message (a Banner) in ` +
|
|
2084
|
+
`place of the counts when error is set.`,
|
|
2085
|
+
line,
|
|
2086
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2089
|
+
return findings;
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2040
2092
|
// sc-5206 — soft warning: a `useDatastoreQuery` argument built from a raw
|
|
2041
2093
|
// `const q = useMemo(() => ({...}), [...])` re-fetches in a loop the moment
|
|
2042
2094
|
// the deps array is wrong (sc-1579's volatile-query gate exists because of
|
|
@@ -3748,6 +3800,7 @@ function lintSource(source, options) {
|
|
|
3748
3800
|
findings.push(..._paymentErrorHandlingRules(source));
|
|
3749
3801
|
findings.push(..._datastoreErrorHandlingRules(source));
|
|
3750
3802
|
findings.push(..._readErrorHandlingRules(source));
|
|
3803
|
+
findings.push(..._aggregateErrorRules(source));
|
|
3751
3804
|
findings.push(..._bankIdOrderRules(source));
|
|
3752
3805
|
// sc-5206 — soft warnings steering a widget toward the two new hooks.
|
|
3753
3806
|
findings.push(..._rawUseMemoIntoDatastoreQueryRules(source));
|
package/dist/linter.js
CHANGED
|
@@ -2032,6 +2032,58 @@ function _readErrorHandlingRules(source) {
|
|
|
2032
2032
|
];
|
|
2033
2033
|
}
|
|
2034
2034
|
|
|
2035
|
+
// sc-17551 — soft warning: an aggregate a widget reads without its `error`
|
|
2036
|
+
// shows a zero per group, or stale counts, when the server refuses or fails it.
|
|
2037
|
+
// Reading `error` (renamed, as `agg.error`, or re-destructured from `agg`),
|
|
2038
|
+
// handing the whole result on, or a rest spread satisfies it. One pass indexes
|
|
2039
|
+
// the reads, so many bindings stay linear. Known limits: `.groups` read
|
|
2040
|
+
// straight off the call, `catch (error)`, and one file's two components.
|
|
2041
|
+
const AGGREGATE_BINDING_RE = /\b(?:const|let|var)\s+([\w$]+|\{[^{}]*\})\s*=\s*useDatastoreAggregate\s*\(/g;
|
|
2042
|
+
const IDENT = String.raw`[A-Za-z_$][\w$]*`;
|
|
2043
|
+
|
|
2044
|
+
function _aggregateErrorRules(source) {
|
|
2045
|
+
const code = _stripNonCode(source);
|
|
2046
|
+
const calls = [...code.matchAll(AGGREGATE_BINDING_RE)];
|
|
2047
|
+
if (calls.length === 0) return [];
|
|
2048
|
+
// Every hook destructure blanked: another hook's own `error`, and a
|
|
2049
|
+
// binding's own field names, are not reads.
|
|
2050
|
+
const body = code.replace(/\{[^{}]*\}\s*=\s*use\w+\s*\(/g, (m) => " ".repeat(m.length));
|
|
2051
|
+
const words = new Set(body.match(new RegExp(String.raw`(?<![\w$.])${IDENT}`, "g")));
|
|
2052
|
+
const members = new Set(
|
|
2053
|
+
[...body.matchAll(new RegExp(String.raw`(?<![\w$.])(${IDENT})\s*\??\.\s*(${IDENT})`, "g"))].map((m) => `${m[1]}.${m[2]}`),
|
|
2054
|
+
);
|
|
2055
|
+
// `={agg}`, `...agg`, or `= agg;` (an alias or a re-destructure).
|
|
2056
|
+
const handedOn = new Set(
|
|
2057
|
+
[
|
|
2058
|
+
...body.matchAll(
|
|
2059
|
+
new RegExp(String.raw`=\{\s*(${IDENT})\s*\}|\.\.\.\s*(${IDENT})|(?<![=!<>])=\s*(${IDENT})\s*(?:;|$)`, "gm"),
|
|
2060
|
+
),
|
|
2061
|
+
].map((m) => m[1] || m[2] || m[3]),
|
|
2062
|
+
);
|
|
2063
|
+
const findings = [];
|
|
2064
|
+
const lineAt = _lineCounter(code);
|
|
2065
|
+
const sourceLines = source.split(/\r?\n/);
|
|
2066
|
+
for (const call of calls) {
|
|
2067
|
+
const binding = call[1];
|
|
2068
|
+
if (binding.includes("...") || handedOn.has(binding)) continue;
|
|
2069
|
+
const locals = binding.startsWith("{") ? _destructuredLocals(binding) : null;
|
|
2070
|
+
const reads = (field) => (locals ? !!locals[field] && words.has(locals[field]) : members.has(`${binding}.${field}`));
|
|
2071
|
+
if ((!reads("groups") && !reads("buckets")) || reads("error")) continue;
|
|
2072
|
+
const line = lineAt(call.index);
|
|
2073
|
+
findings.push({
|
|
2074
|
+
rule: "aggregate-error-not-read",
|
|
2075
|
+
severity: "warning",
|
|
2076
|
+
label:
|
|
2077
|
+
`reads useDatastoreAggregate() without its error, so a refused or failed ` +
|
|
2078
|
+
`aggregate shows a zero per group. Render error.message (a Banner) in ` +
|
|
2079
|
+
`place of the counts when error is set.`,
|
|
2080
|
+
line,
|
|
2081
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2084
|
+
return findings;
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2035
2087
|
// sc-5206 — soft warning: a `useDatastoreQuery` argument built from a raw
|
|
2036
2088
|
// `const q = useMemo(() => ({...}), [...])` re-fetches in a loop the moment
|
|
2037
2089
|
// the deps array is wrong (sc-1579's volatile-query gate exists because of
|
|
@@ -3743,6 +3795,7 @@ export function lintSource(source, options) {
|
|
|
3743
3795
|
findings.push(..._paymentErrorHandlingRules(source));
|
|
3744
3796
|
findings.push(..._datastoreErrorHandlingRules(source));
|
|
3745
3797
|
findings.push(..._readErrorHandlingRules(source));
|
|
3798
|
+
findings.push(..._aggregateErrorRules(source));
|
|
3746
3799
|
findings.push(..._bankIdOrderRules(source));
|
|
3747
3800
|
// sc-5206 — soft warnings steering a widget toward the two new hooks.
|
|
3748
3801
|
findings.push(..._rawUseMemoIntoDatastoreQueryRules(source));
|
package/dist/stats-hooks.js
CHANGED
|
@@ -86,8 +86,11 @@ function useKeyedRead(read, identity, key, mapError, fetchStartRef) {
|
|
|
86
86
|
* (1–1000). Returns `{ buckets, groups, loading, fetching, error, refetch }`:
|
|
87
87
|
* by date, `buckets` is `[{ date, count, sum }]` with every bucket of the range
|
|
88
88
|
* present (empty ones as 0); by a column, `groups` is `[{ group, count, sum }]`,
|
|
89
|
-
* a user column's `group` being the user id
|
|
90
|
-
*
|
|
89
|
+
* a user column's `group` being the user id, a relation column's the related
|
|
90
|
+
* row's id (a MANY_TO_MANY row counts once per linked row), and rows with no
|
|
91
|
+
* value one "Uncategorized" group. Check `error` first: after a refused or
|
|
92
|
+
* failed read `groups` may be empty or still hold the last result. A falsy
|
|
93
|
+
* `table` settles to nothing.
|
|
91
94
|
*/
|
|
92
95
|
export function useDatastoreAggregate(table, spec) {
|
|
93
96
|
const ctx = useWidgetContextOrThrow("useDatastoreAggregate");
|
package/package.json
CHANGED
package/src/contract.js
CHANGED
|
@@ -2098,14 +2098,18 @@ const HOOKS = [
|
|
|
2098
2098
|
"(Monday) in `buckets`; `bucket` is \"day\" (default) or \"week\"; " +
|
|
2099
2099
|
"`from` / `to` are ISO dates (default: the 30 days, or 12 weeks, up to " +
|
|
2100
2100
|
"now), at most 31 buckets, empty ones as count 0 so a chart has no gaps. " +
|
|
2101
|
-
"BY A COLUMN (any other `groupBy`: a text, number, yes/no, date or
|
|
2102
|
-
"column): one entry per value in `groups`. A
|
|
2101
|
+
"BY A COLUMN (any other `groupBy`: a text, number, yes/no, date, user or " +
|
|
2102
|
+
"relation column): one entry per value in `groups`. A RELATION column's " +
|
|
2103
|
+
"`group` is the related row's id (match it to that table's row.id); a " +
|
|
2104
|
+
"MANY_TO_MANY row counts once per linked row. A USER column's `group` is the " +
|
|
2103
2105
|
"user id (resolve names with useDirectory({ ids })), so `order: \"count:desc\", " +
|
|
2104
2106
|
"limit: 10` ranks the ten people with the most rows. `order` is count, sum " +
|
|
2105
2107
|
"or group, then :asc or :desc (default: by value); `limit` is 1-1000. Rows " +
|
|
2106
2108
|
"with no value form one \"Uncategorized\" group; on a user column, leave " +
|
|
2107
|
-
"them out with a `nempty:` filter. Encrypted, array
|
|
2108
|
-
"
|
|
2109
|
+
"them out with a `nempty:` filter. Encrypted, array and file columns " +
|
|
2110
|
+
"cannot be grouped (VALIDATION). Check `error` first and render it: after " +
|
|
2111
|
+
"a refused or failed read `groups` may be empty or still hold the last " +
|
|
2112
|
+
"result, so never show it as a zero per group. `filter` takes the same shapes " +
|
|
2109
2113
|
"as useDatastoreQuery's, created_at ranges included. Pass null as the " +
|
|
2110
2114
|
"table until a bound table is known. `live: true` re-reads it when " +
|
|
2111
2115
|
"anyone else changes the table.",
|
|
@@ -2113,7 +2117,7 @@ const HOOKS = [
|
|
|
2113
2117
|
buckets:
|
|
2114
2118
|
"Array<{ date, count, sum }> // date = the bucket's start, YYYY-MM-DD; sum is 0 without sumColumn",
|
|
2115
2119
|
groups:
|
|
2116
|
-
"Array<{ group, count, sum }> // by a column; a USER column's group is the user id",
|
|
2120
|
+
"Array<{ group, count, sum }> // by a column; a USER column's group is the user id, a RELATION column's the related row id",
|
|
2117
2121
|
loading: "boolean",
|
|
2118
2122
|
fetching: "boolean",
|
|
2119
2123
|
error: "DatastoreError | null // { code, message, retryable } — offer Retry only when retryable; a signed-out viewer of a table only members read gets NOT_FOUND, retryable false",
|
|
@@ -7062,7 +7066,9 @@ const CONTRACT = deepFreeze({
|
|
|
7062
7066
|
// 1.270.0: additive (sc-17197) — a `datastoreTemplate` column may declare
|
|
7063
7067
|
// `defaultOnCreate: true`: a create stamps its default over any client
|
|
7064
7068
|
// value, and an update may still change it.
|
|
7065
|
-
|
|
7069
|
+
// 1.271.0: additive (sc-17551) — `useDatastoreAggregate` groups by a
|
|
7070
|
+
// relation column; new warning lint `aggregate-error-not-read`.
|
|
7071
|
+
version: "1.271.0",
|
|
7066
7072
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7067
7073
|
hooks: HOOKS,
|
|
7068
7074
|
primitives: PRIMITIVES,
|