dwelldelta-mcp 0.10.1 → 0.12.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/LICENSE +4 -1
- package/README.md +63 -13
- package/area-rents-tool.mjs +110 -31
- package/output-schemas.mjs +24 -3
- package/package.json +5 -3
- package/pages.mjs +87 -0
- package/place-tool.mjs +361 -0
- package/register-tools.mjs +85 -21
- package/sale-prices-tool.mjs +29 -9
- package/server.mjs +4 -4
- package/tools.mjs +21 -3
- package/vendor/indicators.json +89 -43
- package/vendor/rents-index.json +26 -17
- package/vendor/sa-rents.json +5418 -0
package/LICENSE
CHANGED
|
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
21
21
|
SOFTWARE.
|
|
22
22
|
|
|
23
23
|
The data files in vendor/ (rents-index.json, indicators.json, nsw-suburbs.json, vic-rents.json,
|
|
24
|
-
nsw-rents.json, qld-rents.json, wa-rents.json, nsw-sales.json) are
|
|
24
|
+
nsw-rents.json, qld-rents.json, wa-rents.json, sa-rents.json, nsw-sales.json) are
|
|
25
25
|
not covered by this licence. Each figure keeps its source's own licence and
|
|
26
26
|
attribution, which the data files and every answer state (for example, ABS data:
|
|
27
27
|
CC BY 4.0, "Based on Australian Bureau of Statistics data"; the NSW suburb list:
|
|
@@ -30,5 +30,8 @@ NSW rents: CC BY 4.0, State of New South Wales (Department of Communities and
|
|
|
30
30
|
Justice); Queensland rents: CC BY 4.0, The State of Queensland (Residential
|
|
31
31
|
Tenancies Authority); WA rents: based on WA Rental Bonds Data, CC BY 4.0,
|
|
32
32
|
Government of Western Australia, with medians calculated by DwellDelta;
|
|
33
|
+
SA rents: South Australian Housing Trust, Government of South Australia,
|
|
34
|
+
Private Rent Report, whose own page states no licence - the national
|
|
35
|
+
catalogues list CC BY 4.0 and CC BY 3.0 AU;
|
|
33
36
|
NSW sale prices: CC BY 4.0, State of New South Wales (Department of
|
|
34
37
|
Communities and Justice)).
|
package/README.md
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
# dwelldelta-mcp - is an Australian rent fair?
|
|
2
2
|
|
|
3
3
|
An MCP server that lets an AI assistant check a weekly rent against the ABS rents index, look up median rents
|
|
4
|
-
by area in
|
|
4
|
+
by area in five states and NSW median sale prices, and quote sourced Australian property and lending indicators. From
|
|
5
5
|
[DwellDelta](https://dwelldelta.com.au/), a service of Xcelerent Pty Ltd, built on public data.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Seven read-only tools, and one that adds the user's own rent when they ask:
|
|
8
8
|
|
|
9
9
|
| Tool | What it answers |
|
|
10
10
|
|---|---|
|
|
11
|
-
| `rent_check` | a weekly rent, and any proposed new rent, against the ABS rents index for the capital city since the lease began (the same arithmetic as the rent check at tools.dwelldelta.com.au) |
|
|
11
|
+
| `rent_check` | a weekly rent, and any proposed new rent, against the ABS rents index for the capital city since the lease began (the same arithmetic as the rent check at tools.dwelldelta.com.au); or, given a `place` instead of a lease start, against that place's median of new bonds or leases, and its quartiles where published (from 0.12.0) |
|
|
12
|
+
| `property_rents` | the rents of a place asked with no state - a suburb, locality or postcode - answered from the state that holds it (NSW, Victoria, Queensland, WA or SA); an NSW suburb is answered for its postcode, and a name held in more than one state is listed, not chosen (from 0.12.0) |
|
|
12
13
|
| `market_indicators` | the latest RBA cash rate, unemployment, wage growth, rents for all eight capitals, NSW lending, lending standards and arrears, approvals and completions - each with period, source, licence and limits; filter by `geography` |
|
|
13
14
|
| `vic_rents` | Victorian rents by suburb group from Homes Victoria's Rental Report: the median weekly rent of new leases, the lease count and the change on a year before, for 146 suburb groups and 13 regions; filter by `suburb_group` or `region` (from 0.5.0) |
|
|
14
|
-
| `area_rents` | median weekly rent of new bonds, all dwellings together, with the bond count and the change on a year before, for one state per call: NSW by postcode or council (NSW Department of Communities and Justice), Queensland by suburb or council (Residential Tenancies Authority), WA by locality (calculated by DwellDelta from the Government of Western Australia's bond records); each CC BY 4.0 (from 0.6.0) |
|
|
15
|
+
| `area_rents` | median weekly rent of new bonds, all dwellings together, with the bond count and the change on a year before, for one state per call: NSW by postcode or council (NSW Department of Communities and Justice), Queensland by suburb or council (Residential Tenancies Authority), WA by locality (calculated by DwellDelta from the Government of Western Australia's bond records), SA by suburb (SA Housing Trust, Private Rent Report; its publisher's page states no licence, and the national catalogues list CC BY); each file states CC BY 4.0 (from 0.6.0; SA from 0.11.0) |
|
|
15
16
|
| `nsw_sale_prices` | NSW median sale prices by postcode or council from the NSW Department of Communities and Justice's Rent and Sales Report (CC BY 4.0): the median, the quartiles, the number of sales and the change on a year before, each for all dwellings, houses (non-strata) and units and town houses (strata). Medians of homes sold - never what any one home sold for; a line set by a few very large sales or by many sales at one identical price is marked UNUSUAL (from 0.7.0), and is not a going price |
|
|
16
17
|
| `data_sources` | the sources, their licences, and what DwellDelta cannot answer |
|
|
17
18
|
| `contribute_rent` | adds the user's own rent, anonymously, to DwellDelta's suburb benchmarks - only when the user asks, and only after they have read and agreed to the consent wording (from 0.5.0) |
|
|
@@ -70,15 +71,22 @@ median rent of new leases in postcode 2148?" or "What is NSW unemployment doing?
|
|
|
70
71
|
|
|
71
72
|
## Rents by area (from 0.6.0)
|
|
72
73
|
|
|
73
|
-
`area_rents` answers for one state at a time, because the
|
|
74
|
+
`area_rents` answers for one state at a time, because the four publishers measure in their own ways and the WA
|
|
74
75
|
medians are DwellDelta's own calculation from the Government's one-record-per-bond data. They must not be added
|
|
75
76
|
or ranked as one series. Every answer carries that state's quarter, its source line, what DwellDelta selected or
|
|
76
77
|
calculated, and its limits. These are medians of new bonds, all dwellings together - not advertised rents, not
|
|
77
78
|
what sitting tenants pay, and not the rent of a home of a given size. Where a publisher reports nothing for a
|
|
78
79
|
small area the answer says so; it never shows a zero. The feeds are public at
|
|
79
|
-
https://tools.dwelldelta.com.au/market/nsw-rents.json, `qld-rents.json` and `
|
|
80
|
-
at start the way it reads the indicators, and `DWELLDELTA_STATE_RENTS_DIR` points it at a folder of
|
|
81
|
-
Victoria, measured differently again, stays in `vic_rents`.
|
|
80
|
+
https://tools.dwelldelta.com.au/market/nsw-rents.json, `qld-rents.json`, `wa-rents.json` and `sa-rents.json`; the
|
|
81
|
+
server reads them at start the way it reads the indicators, and `DWELLDELTA_STATE_RENTS_DIR` points it at a folder of
|
|
82
|
+
copies. Victoria, measured differently again, stays in `vic_rents`.
|
|
83
|
+
|
|
84
|
+
South Australia's file holds one quarter today, so its `compared_with`, year-ago medians and changes are null and no
|
|
85
|
+
answer names a year it is compared with. Its counts of bonds are rounded to the nearest 5 (the SA Housing Trust's note says so of its totals;
|
|
86
|
+
every count in the file is a multiple of 5), and the publisher
|
|
87
|
+
prints a median where it shows the count as `*` (1 to 5 bonds; the file's `new_bonds_range`): that median is
|
|
88
|
+
refused, never given. The publisher's own page states no licence; the file's `licence_note` says which licence the
|
|
89
|
+
national catalogues list.
|
|
82
90
|
|
|
83
91
|
### By dwelling type and bedrooms (from 0.8.0)
|
|
84
92
|
|
|
@@ -89,7 +97,8 @@ every type. A combination with no published median is said to have none; it is n
|
|
|
89
97
|
all-dwellings figure, a neighbouring area or a wider group. Many of these figures rest on few bonds, and each
|
|
90
98
|
small sample is marked. The Residential Tenancies Authority does not define its labels: reading "Flat 2" as a
|
|
91
99
|
two-bedroom flat is DwellDelta's reading, and every Queensland answer says so. WA's bond records carry neither
|
|
92
|
-
dwelling type nor bedrooms, so WA has no such figures
|
|
100
|
+
dwelling type nor bedrooms, so WA has no such figures; DwellDelta publishes South Australia's rents for all
|
|
101
|
+
dwellings together only. DCJ's largest size is "4 or more Bedrooms": a number above
|
|
93
102
|
four is answered under that label, and the answer says it is not for that number alone. A number followed by a
|
|
94
103
|
plus means "or more", which only that one size has; anything else with a plus is refused, not answered as exactly
|
|
95
104
|
that many.
|
|
@@ -125,6 +134,45 @@ copy city by city (each city's series starts no later and ends no earlier than i
|
|
|
125
134
|
later than the current one; otherwise, or with `DWELLDELTA_OFFLINE=1`, the bundled copy answers.
|
|
126
135
|
`data_as_of` and the `Cite:` line's period say which month the answer runs to.
|
|
127
136
|
|
|
137
|
+
### Answers on the first call, pages and citations (from 0.12.0)
|
|
138
|
+
|
|
139
|
+
- A NSW suburb's name is answered on the first call where the NSW suburb list (NSW Spatial Services, CC BY 3.0 AU)
|
|
140
|
+
places it in exactly one postcode, counted across the whole list, and the file holds that postcode: the answer is
|
|
141
|
+
that whole postcode's, and its first line says so and credits the list. A name in several postcodes is refused
|
|
142
|
+
with the ones to try, and names any the file has no row for.
|
|
143
|
+
- `area_rents` and `nsw_sale_prices` answers gain new fields: `place_note`, `page_url` (the place's page on
|
|
144
|
+
tools.dwelldelta.com.au, the state's page for the state's own figure, else null), `pages` and `cite_as` (null when
|
|
145
|
+
every figure is refused); the text gains `Page:` and `Cite as:` lines. Results stay text only, readable by clients
|
|
146
|
+
on every protocol version the server accepts. No earlier field changes.
|
|
147
|
+
- The server sends `instructions` in its initialize result: what it holds, when it applies, how to cite it, its limits.
|
|
148
|
+
- A URL in an answer's text is never followed by punctuation run into it: one that would be is written `<...>`. This
|
|
149
|
+
changes the `Cite:` line's text: its URLs now read `<https://...>` where a `;` or `.` follows them.
|
|
150
|
+
|
|
151
|
+
### Asking by place, and a rent against the local median (from 0.12.0)
|
|
152
|
+
|
|
153
|
+
- `rent_check` without `lease_start`: give `place` (a suburb, locality or postcode in NSW, Victoria, Queensland, WA
|
|
154
|
+
or SA; a state may follow, as "Richmond, VIC") with `current_rent` (and `proposed_rent`, `dwelling_type` and
|
|
155
|
+
`bedrooms` where the state publishes them), and the answer places the rent against that place's median of new
|
|
156
|
+
bonds: the dollars and per cent from the median and, where the publisher gives quartiles (DCJ, NSW), between which
|
|
157
|
+
of them, in the web rent check's words. It is information, not a judgement of the rent. `result` is null in this
|
|
158
|
+
mode and `local` holds the placement; the place's own answer follows, with its limits and source. A figure the
|
|
159
|
+
publisher marks small, or whose count it withholds, opens with the web card's caution, and `local.small_sample`,
|
|
160
|
+
`local.n` and `local.n_band` say so; a median that is not a number in the data file is refused as no median. With
|
|
161
|
+
`lease_start`, `rent_check` is unchanged (and `city` is needed with it); an argument of the other mode is named in
|
|
162
|
+
a first line, "Not used: ...", and in `ignored`.
|
|
163
|
+
- `property_rents(place, dwelling_type?, bedrooms?)` (place-tool.mjs) answers a place with no state: the place is
|
|
164
|
+
found by its exact name in every file held and answered by `area_rents` or `vic_rents` for that state. A name held
|
|
165
|
+
in more than one state ("Richmond": NSW, SA, VIC) is listed with each, never chosen. A trailing state word is
|
|
166
|
+
the state where the rest is held there ("East Perth WA"); otherwise a held name is read whole ("Mount Victoria" is
|
|
167
|
+
NSW's), and "Mt" and "Mount" are one. A postcode
|
|
168
|
+
given with a name is used only where the NSW suburb list gives it for that name ("Alison 2259"); a NSW postcode it
|
|
169
|
+
does not give is refused, naming both; outside NSW, whose feeds are by name, it only says the state. A postcode
|
|
170
|
+
alone is looked for in DCJ's file first (it reports 2611 and 2900, in Australia Post's ACT ranges, as NSW's).
|
|
171
|
+
Tasmania, the ACT, the Northern Territory and New Zealand are otherwise said to be not held. Both servers list it
|
|
172
|
+
from 0.12.0, and the server's instructions say what it takes.
|
|
173
|
+
- tools/list: a field copied from a data file is now declared `{}` (any value) rather than `anyOf [type, {}]`, which
|
|
174
|
+
accepts exactly the same values; this made room for the above under the 32,000-character cap.
|
|
175
|
+
|
|
128
176
|
### Checkable provenance (from 0.9.0)
|
|
129
177
|
|
|
130
178
|
Every answer that gives a figure ends with a `Cite:` line to quote with it: the source, the period, the licence id
|
|
@@ -134,7 +182,8 @@ published data file. The structured result says the same, in new fields; every f
|
|
|
134
182
|
|
|
135
183
|
- each entry of `sources` adds `licence_id`, `licence_url`, `source_url`, `source_notice_url`, `feed_url` and
|
|
136
184
|
`period`. `source_url` is only ever an address of the data's own page that the data file itself holds: for WA
|
|
137
|
-
the National Housing Data Exchange dataset page, for
|
|
185
|
+
the National Housing Data Exchange dataset page, for SA the data.sa.gov.au dataset page, for Victoria the DataVic
|
|
186
|
+
page in its source line. It is null
|
|
138
187
|
where the file holds none - DCJ's files (NSW rents, rents by type, sale prices), the RTA's (Queensland), the ABS
|
|
139
188
|
rents index and the indicators snapshot. DCJ's and the RTA's files name only a copyright notice
|
|
140
189
|
(https://dcj.nsw.gov.au/statements/copyright-and-disclaimer.html, which DCJ's attribution also names, and
|
|
@@ -158,8 +207,9 @@ published data file. The structured result says the same, in new fields; every f
|
|
|
158
207
|
- A figure that rests on too few records is a refusal, never a weak number: `{ refused: true, type:
|
|
159
208
|
"too_few_records", reason, n, n_band, unit, min_n, rule }` (`type` is `not_published` for a combination the
|
|
160
209
|
publisher does not list). The rules are each file's own: DCJ reports nothing for 10 or fewer bonds or sales
|
|
161
|
-
(`min_n` 11), a WA locality needs 10 bonds,
|
|
162
|
-
|
|
210
|
+
(`min_n` 11), a WA locality needs 10 bonds, the RTA and Homes Victoria withhold small medians without stating a
|
|
211
|
+
number, and an SA median whose count the publisher shows as `*` (1 to 5 bonds) is refused (`min_n` null: the
|
|
212
|
+
publisher's counts are rounded to the nearest 5, so no number is a cut-off). A median the file gives below its rule is refused in the text as well; the file's own figure
|
|
163
213
|
is left as it is in the structured rows.
|
|
164
214
|
- Each structured row says on itself whether the text refused its figure (from 0.9.0; additions only - no field a
|
|
165
215
|
row had is changed or removed): `refused: true` and `refusal_type` (`too_few_records` or `not_published`, the same
|
|
@@ -179,7 +229,7 @@ answer states - for example ABS data is CC BY 4.0, "Based on Australian Bureau o
|
|
|
179
229
|
|
|
180
230
|
## Development
|
|
181
231
|
|
|
182
|
-
`npm test` here starts the server and calls the
|
|
232
|
+
`npm test` here starts the server and calls the seven read-only tools, and the first (consent) call of
|
|
183
233
|
`contribute_rent`, over MCP, and `test/provenance.test.mjs` holds the provenance above on the vendored files and
|
|
184
234
|
fixtures; the repository's root `npm test` holds the
|
|
185
235
|
tool answers themselves and checks that `vendor/` matches its sources. `npm pack` runs `scripts/vendor.mjs` first.
|
package/area-rents-tool.mjs
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* area_rents (0.6.0, 2026-10-10): rents by area for NSW (postcodes and councils, NSW Department of Communities and
|
|
3
|
-
* Justice), Queensland (suburbs and councils, Residential Tenancies Authority)
|
|
4
|
-
* calculated by DwellDelta from the Government's bond records),
|
|
5
|
-
* tools.dwelldelta.com.au/market/{nsw,qld,wa}-rents.json -
|
|
3
|
+
* Justice), Queensland (suburbs and councils, Residential Tenancies Authority), Western Australia (localities,
|
|
4
|
+
* calculated by DwellDelta from the Government's bond records) and, from 2026-11-01, South Australia (suburbs, the SA
|
|
5
|
+
* Housing Trust's Private Rent Report), as published at tools.dwelldelta.com.au/market/{nsw,qld,wa,sa}-rents.json -
|
|
6
|
+
* each CC BY 4.0, republishable with attribution; SA's licence is the one the national catalogues list, which its
|
|
7
|
+
* publisher's own page does not state (the file's licence_note).
|
|
8
|
+
*
|
|
9
|
+
* SA's file may hold one quarter only: then compared_with is null, and no answer names a quarter it is compared with.
|
|
6
10
|
*
|
|
7
11
|
* One state per call, never pooled: each publisher measures in its own way, and the WA medians are our own
|
|
8
12
|
* calculation, so every answer carries that state's own source line, what was changed, and its limits.
|
|
9
13
|
*
|
|
10
|
-
* Loaded like vic_rents: DWELLDELTA_STATE_RENTS_DIR (a folder holding the
|
|
14
|
+
* Loaded like vic_rents: DWELLDELTA_STATE_RENTS_DIR (a folder holding the four files), else the owner's live store,
|
|
11
15
|
* else the published file (fetched once at start - one public file each; nothing about the user or their questions is
|
|
12
16
|
* sent - and used if well formed, for the right state, and not older than the bundled copy), else the copy bundled at
|
|
13
17
|
* pack time. DWELLDELTA_OFFLINE=1 never fetches. The data changes once a quarter, so every answer states its quarter.
|
|
@@ -22,6 +26,7 @@ import { loadJson, envelope, ToolError, FOOTER, FETCH_TIMEOUT_MS, feedSource, CA
|
|
|
22
26
|
figureFields, nWords, citeLine, staleNote, flagged, refusalMark, isRecord, passes, readChecked, quiet,
|
|
23
27
|
warnPublished, fromCopy } from "./tools.mjs";
|
|
24
28
|
import { quarterKey } from "./vic-rents-tool.mjs";
|
|
29
|
+
import { rentPage, citeFields, withPlace } from "./pages.mjs";
|
|
25
30
|
|
|
26
31
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
27
32
|
const LIVE_DIR = join(HERE, "..", "..", "dwelldelta-data", "market");
|
|
@@ -38,9 +43,14 @@ export const STATES = {
|
|
|
38
43
|
WA: { file: "wa-rents.json", name: "Western Australia", notice_is_data: true,
|
|
39
44
|
hint: "WA rents are by locality (area: \"Fremantle\"; part of a name works). There are no councils in the " +
|
|
40
45
|
"bond records." },
|
|
46
|
+
// SA's source_notice is the dataset's own page on data.sa.gov.au, so it is the source's URL.
|
|
47
|
+
SA: { file: "sa-rents.json", name: "South Australia", notice_is_data: true,
|
|
48
|
+
hint: "South Australian rents are by suburb, as the SA Housing Trust names it (area: \"Mount Gambier\"; part " +
|
|
49
|
+
"of a name works). There are no councils in this file." },
|
|
41
50
|
};
|
|
42
51
|
/** Each state's small-sample rule (tools.mjs SAMPLE_RULES): below it a figure is refused, never given. */
|
|
43
|
-
export const RULES = { NSW: SAMPLE_RULES.NSW_RENTS, QLD: SAMPLE_RULES.QLD_RENTS, WA: SAMPLE_RULES.WA_RENTS
|
|
52
|
+
export const RULES = { NSW: SAMPLE_RULES.NSW_RENTS, QLD: SAMPLE_RULES.QLD_RENTS, WA: SAMPLE_RULES.WA_RENTS,
|
|
53
|
+
SA: SAMPLE_RULES.SA_RENTS };
|
|
44
54
|
/** Rows shown in one answer; a wider match says how many more there are instead of dropping them silently. */
|
|
45
55
|
export const MAX_ROWS = 25;
|
|
46
56
|
|
|
@@ -78,7 +88,7 @@ export async function loadAreaRents(state, { env = process.env, fetchImpl = glob
|
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
/**
|
|
81
|
-
* Every state's feed, loaded together at start: { NSW: feed-with-origin | null, QLD: ..., WA: ... }. A state whose copy
|
|
91
|
+
* Every state's feed, loaded together at start: { NSW: feed-with-origin | null, QLD: ..., WA: ..., SA: ... }. A state whose copy
|
|
82
92
|
* was refused is named, with that copy, in its refused property - not enumerable, so the states are all there is to
|
|
83
93
|
* list - for the tool to say that copy could not be used (withRefused).
|
|
84
94
|
*/
|
|
@@ -105,9 +115,16 @@ export const signed = (v) => `${v >= 0 ? "+" : ""}${v}%`;
|
|
|
105
115
|
const whyNone = (r) => r.withheld ?? (r.new_bonds == null ? "too few bonds"
|
|
106
116
|
: `${r.new_bonds} new bond${r.new_bonds === 1 ? "" : "s"} - too few for a median`);
|
|
107
117
|
|
|
108
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* One figure's sample and, if it rests on too few bonds, its refusal (see judgeFigure in tools.mjs). A count the
|
|
120
|
+
* publisher withholds is in new_bonds_band (DCJ's "10 to 30") or, for SA, new_bonds_range ("1 to 5": the SA Housing
|
|
121
|
+
* Trust's '*'); either is the figure's n_band.
|
|
122
|
+
*/
|
|
109
123
|
export const rentFigure = (r, name, rule) => judgeFigure(r, { name, median: "median_weekly_rent_aud", count: "new_bonds",
|
|
110
|
-
band:
|
|
124
|
+
band: r?.new_bonds_range != null ? "new_bonds_range" : "new_bonds_band", rule,
|
|
125
|
+
why: r && r.median_weekly_rent_aud == null ? whyNone(r) : null });
|
|
126
|
+
/** "Quarter: Jun 2026, against Jun 2025." - or, where no year-before figures are held (SA, one quarter), says so. */
|
|
127
|
+
const against = (f) => (f.compared_with ? `, against ${f.compared_with}` : " (no figures for a year before are held)");
|
|
111
128
|
|
|
112
129
|
function line(r, name, rule = null) {
|
|
113
130
|
if (r.median_weekly_rent_aud == null) return `${name}: no median (${whyNone(r)}).`;
|
|
@@ -133,17 +150,55 @@ export function match(rows, key, wanted) {
|
|
|
133
150
|
return exact.length ? exact : real.filter((r) => norm(r[key]).includes(norm(wanted)));
|
|
134
151
|
}
|
|
135
152
|
|
|
153
|
+
/** Where the place note's pairing of a suburb with a postcode comes from, named in every answer that rests on it. */
|
|
154
|
+
export const SUBURB_LIST_CREDIT = "NSW suburb list: NSW Spatial Services, CC BY 3.0 AU";
|
|
155
|
+
|
|
136
156
|
/**
|
|
137
|
-
* People ask NSW by suburb, and DCJ reports by postcode. For a name
|
|
138
|
-
* in the NSW suburb list ("Parramatta (2150)", already shipped for contribute_rent), with the postcodes
|
|
139
|
-
* holds
|
|
157
|
+
* People ask NSW by suburb, and DCJ reports by postcode. For a name the call does not answer (nswResolve): the suburbs
|
|
158
|
+
* of that name in the NSW suburb list ("Parramatta (2150)", already shipped for contribute_rent), with the postcodes
|
|
159
|
+
* this feed holds, offered as the next step. Where the exact name is also in postcodes this feed holds no row for,
|
|
160
|
+
* they are named as such, so a name in two postcodes is never read as being in one. With no held postcode to offer,
|
|
161
|
+
* nothing is said of the list: a postcode with no row would send the agent to a second failure.
|
|
140
162
|
*/
|
|
141
163
|
export function nswPostcodes(wanted, suburbs, feed) {
|
|
142
|
-
const held = new Set(feed.areas.filter(isRecord).map((r) => r.area));
|
|
143
|
-
const
|
|
164
|
+
const held = new Set(feed.areas.filter(isRecord).map((r) => String(r.area)));
|
|
165
|
+
const all = suburbs.map((s) => /^(.*) \((\d{4})\)$/.exec(s)).filter(Boolean);
|
|
166
|
+
const named = all.filter((m) => held.has(m[2]));
|
|
144
167
|
const exact = named.filter((m) => norm(m[1]) === norm(wanted));
|
|
145
168
|
const found = exact.length ? exact : named.filter((m) => norm(m[1]).includes(norm(wanted)));
|
|
146
|
-
|
|
169
|
+
const lines = found.slice(0, 5).map((m) => `${m[1]} is in postcode ${m[2]}`);
|
|
170
|
+
const elsewhere = exact.length ? [...new Set(all.filter((m) => !held.has(m[2]) && norm(m[1]) === norm(wanted))
|
|
171
|
+
.map((m) => m[2]))] : [];
|
|
172
|
+
if (elsewhere.length) {
|
|
173
|
+
lines.push(`the list also places ${exact[0][1]} in postcode${elsewhere.length > 1 ? "s" : ""} ${elsewhere.join(", ")}, ` +
|
|
174
|
+
"which this file has no row for");
|
|
175
|
+
}
|
|
176
|
+
return lines;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* A suburb's name answered on the first call (0.12.0, 2026-11-03: a model asking "Parramatta" was refused, told the
|
|
181
|
+
* postcode, and often went no further). Where the NSW suburb list places that exact name in ONE postcode - counted
|
|
182
|
+
* across the whole list, not only the postcodes this feed holds (review of #74: "Maryland" is in 2287 and 4377, and
|
|
183
|
+
* the rents feed holds only 2287) - and the feed holds it, the answer is that postcode's row, with a note saying the
|
|
184
|
+
* figure is the whole postcode's and where the pairing comes from. A name in several postcodes, in one the feed has
|
|
185
|
+
* no row for, or matching only in part, is not resolved (null): the call refuses with the postcodes to try.
|
|
186
|
+
*/
|
|
187
|
+
export function nswResolve(wanted, suburbs, feed) {
|
|
188
|
+
const held = new Set(feed.areas.filter(isRecord).map((r) => String(r.area)));
|
|
189
|
+
const exact = suburbs.map((s) => /^(.*) \((\d{4})\)$/.exec(s)).filter((m) => m && norm(m[1]) === norm(wanted));
|
|
190
|
+
const codes = [...new Set(exact.map((m) => m[2]))];
|
|
191
|
+
if (codes.length !== 1 || !held.has(codes[0])) return null;
|
|
192
|
+
const suburb = exact[0][1], postcode = codes[0];
|
|
193
|
+
return { suburb, postcode,
|
|
194
|
+
note: `${suburb} is in postcode ${postcode} (${SUBURB_LIST_CREDIT}). These figures are for the whole ` +
|
|
195
|
+
`postcode, not ${suburb} alone.` };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** The note when a resolved suburb's name is also a council's: the council's figure is a call of its own. */
|
|
199
|
+
export function councilToo(wanted, councils) {
|
|
200
|
+
const c = (councils ?? []).filter(isRecord).find((r) => norm(r.council) === norm(wanted));
|
|
201
|
+
return c ? ` ${c.council} is also a council; its figure is answered with council: ${JSON.stringify(c.council)}.` : "";
|
|
147
202
|
}
|
|
148
203
|
|
|
149
204
|
/**
|
|
@@ -156,8 +211,8 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
|
|
|
156
211
|
const info = STATES[state];
|
|
157
212
|
if (!info) {
|
|
158
213
|
throw new ToolError(`No area rents for ${JSON.stringify(state)}.`,
|
|
159
|
-
`Call area_rents with state NSW, QLD or
|
|
160
|
-
`
|
|
214
|
+
`Call area_rents with state NSW, QLD, WA or SA. Victoria is in vic_rents; Tasmania, the ACT and the Northern ` +
|
|
215
|
+
`Territory are not covered.`);
|
|
161
216
|
}
|
|
162
217
|
const feed = feeds[state];
|
|
163
218
|
if (!feed && feeds.refused?.[state]) {
|
|
@@ -170,8 +225,16 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
|
|
|
170
225
|
}
|
|
171
226
|
const kind = feed.area_kind;
|
|
172
227
|
let areas = [], councils = [], regions = [];
|
|
228
|
+
let resolved = null;
|
|
173
229
|
if (area != null && String(area).trim()) {
|
|
174
230
|
areas = match(feed.areas, "area", area);
|
|
231
|
+
if (!areas.length && state === "NSW") {
|
|
232
|
+
resolved = nswResolve(area, nswSuburbs, feed);
|
|
233
|
+
if (resolved) {
|
|
234
|
+
areas = match(feed.areas, "area", resolved.postcode);
|
|
235
|
+
resolved.note += council == null || !String(council).trim() ? councilToo(area, feed.councils) : "";
|
|
236
|
+
}
|
|
237
|
+
}
|
|
175
238
|
if (!areas.length) {
|
|
176
239
|
const named = state === "NSW" ? nswPostcodes(area, nswSuburbs, feed) : [];
|
|
177
240
|
throw new ToolError(`No ${info.name} ${kind} matches ${JSON.stringify(area)}.`,
|
|
@@ -188,9 +251,23 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
|
|
|
188
251
|
}
|
|
189
252
|
}
|
|
190
253
|
const whole = !areas.length && !councils.length;
|
|
254
|
+
// The page and citation fields (pages.mjs), and the resolved suburb's note, added to whichever answer is given.
|
|
255
|
+
const finish = (res, byKind) => {
|
|
256
|
+
const shownAreas = areas.slice(0, byKind ? MAX_TYPE_PLACES : MAX_ROWS);
|
|
257
|
+
const places = shownAreas.map((r) => ({ name: r.area, url: rentPage(state, feed.areas, r) }));
|
|
258
|
+
const label = shownAreas.length === 1 && !councils.length ? `${shownAreas[0].area} (${kind}), ${info.name}`
|
|
259
|
+
: whole ? info.name : `${info.name}, ${shownAreas.length + councils.length} places`;
|
|
260
|
+
const cite = citeFields({ state, places: councils.length ? [] : places, whole,
|
|
261
|
+
what: `Median weekly rent of new bonds${byKind ? " by dwelling type" : ""}, ${label}`, period: feed.quarter,
|
|
262
|
+
by: feed.rights_holder ?? feed.source, licence: feed.licence, allRefused: res.structured.all_refused === true });
|
|
263
|
+
if (councils.length) cite.pages = places.filter((p) => p.url).map((p) => ({ place: p.name, url: p.url }));
|
|
264
|
+
const note = resolved?.note ?? null;
|
|
265
|
+
return { text: withPlace(res.text, { note, ...cite }, FOOTER),
|
|
266
|
+
structured: { ...res.structured, place_note: note, ...cite } };
|
|
267
|
+
};
|
|
191
268
|
if (wantsByType({ dwelling_type, bedrooms })) {
|
|
192
|
-
return byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file: byType[state],
|
|
193
|
-
|
|
269
|
+
return finish(byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file: byType[state],
|
|
270
|
+
refusedFile: byType.refused?.[state] ?? null, hosted }, now), true);
|
|
194
271
|
}
|
|
195
272
|
if (whole) regions = feed.regions.filter(isRecord);
|
|
196
273
|
const dropped = [];
|
|
@@ -214,7 +291,7 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
|
|
|
214
291
|
const marked = (r) => ({ ...r, ...refusalMark(judged.get(r)) });
|
|
215
292
|
const text = [
|
|
216
293
|
...staleNote(env),
|
|
217
|
-
`${feed.what}. Quarter: ${feed.quarter}
|
|
294
|
+
`${feed.what}. Quarter: ${feed.quarter}${against(feed)}.`,
|
|
218
295
|
"",
|
|
219
296
|
...shown.map(([name, r]) => line(r, name, rule)),
|
|
220
297
|
...dropped,
|
|
@@ -227,17 +304,17 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
|
|
|
227
304
|
"",
|
|
228
305
|
`Source: ${feed.attribution}`,
|
|
229
306
|
`What DwellDelta changed: ${feed.changes_made}`,
|
|
230
|
-
citeLine({ source: feed.source, period: `${feed.quarter} (against ${feed.compared_with})
|
|
231
|
-
n: nWords(figures, rule.unit), url: env.sources[0].source_url,
|
|
232
|
-
feedUrl, stale: flagged(env) }),
|
|
307
|
+
citeLine({ source: feed.source, period: feed.compared_with ? `${feed.quarter} (against ${feed.compared_with})` : feed.quarter,
|
|
308
|
+
licence: feed.licence, n: nWords(figures, rule.unit), url: env.sources[0].source_url,
|
|
309
|
+
notice: env.sources[0].source_notice_url, feedUrl, stale: flagged(env) }),
|
|
233
310
|
FOOTER,
|
|
234
311
|
].join("\n");
|
|
235
|
-
return { text, structured: { ...env, state, state_name: info.name, area_kind: kind, quarter: feed.quarter,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
312
|
+
return finish({ text, structured: { ...env, state, state_name: info.name, area_kind: kind, quarter: feed.quarter,
|
|
313
|
+
compared_with: feed.compared_with, derived: feed.derived === true,
|
|
314
|
+
state_total: whole ? marked(feed.state_total) : null, regions: regions.map(marked),
|
|
315
|
+
councils: councils.map(marked), areas: areas.map(marked),
|
|
316
|
+
truncated: dropped.length > 0, limits: feed.limits, changes_made: feed.changes_made,
|
|
317
|
+
...figureFields(figures), sample_rule: rule } }, false);
|
|
241
318
|
}
|
|
242
319
|
|
|
243
320
|
// --- by dwelling type and bedrooms --------------------------------------------------------------------------------
|
|
@@ -440,9 +517,11 @@ function qldAsked(file, dwelling_type, bedrooms) {
|
|
|
440
517
|
function byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file, refusedFile = null,
|
|
441
518
|
hosted = false }, now) {
|
|
442
519
|
if (!BY_TYPE[state]) {
|
|
443
|
-
throw new ToolError(`${info.name} rents are not published by dwelling type or bedrooms.`,
|
|
444
|
-
"WA's bond records carry neither. Call area_rents for WA without dwelling_type and bedrooms: every WA figure " +
|
|
445
|
-
|
|
520
|
+
throw new ToolError(`${info.name} rents are not published by dwelling type or bedrooms.`, state === "WA"
|
|
521
|
+
? "WA's bond records carry neither. Call area_rents for WA without dwelling_type and bedrooms: every WA figure " +
|
|
522
|
+
"is all dwellings together."
|
|
523
|
+
: `DwellDelta publishes ${info.name}'s rents for all dwellings together only. Call area_rents for ${state} ` +
|
|
524
|
+
`without dwelling_type and bedrooms: every ${state} figure is all dwellings together.`);
|
|
446
525
|
}
|
|
447
526
|
// On the hosted server (hosted: remote/endpoint.mjs) the user can set no variable on it: the error says the server
|
|
448
527
|
// could not load the file, and what to ask instead.
|
package/output-schemas.mjs
CHANGED
|
@@ -32,9 +32,12 @@ const obj = (shape) => z.looseObject(shape);
|
|
|
32
32
|
const opt = (s) => s.optional();
|
|
33
33
|
/**
|
|
34
34
|
* A field copied from a data file: it may be missing, null or of another type than today's file gives it (s), and is
|
|
35
|
-
* answered as it stands. In tools/list:
|
|
35
|
+
* answered as it stands. In tools/list: {} - any value. Until 0.12.0 it was anyOf [s, {}], which accepts exactly the
|
|
36
|
+
* same values (the {} branch takes everything) and spent about 34 characters a field saying what today's file holds:
|
|
37
|
+
* 123 such fields, some 4,100 characters, which the place-first tool and rent_check's local mode needed under the
|
|
38
|
+
* 32,000 cap. Nothing is checked differently. s stays in the code, for the reader: what the field holds today.
|
|
36
39
|
*/
|
|
37
|
-
const fromFile = (s) => z.
|
|
40
|
+
const fromFile = (s) => z.unknown().optional();
|
|
38
41
|
/** A place's name from a data file: a postcode, read as a string or a number. */
|
|
39
42
|
const placeName = z.union([z.string(), z.number()]);
|
|
40
43
|
|
|
@@ -158,6 +161,9 @@ const salePlace = obj({
|
|
|
158
161
|
/** The source's limits, as its data file states them. */
|
|
159
162
|
const fileLimits = fromFile(z.array(str));
|
|
160
163
|
|
|
164
|
+
// Only page_url and cite_as are declared: place_note and pages are allowed as every unnamed key is (tools/list's size).
|
|
165
|
+
const cited = { page_url: opt(nstr), cite_as: opt(nstr) };
|
|
166
|
+
|
|
161
167
|
export const OUTPUT_SCHEMAS = {
|
|
162
168
|
// result: the comparison - the ABS rents index's move from startUsed to latest, and the rent it tracks to. Every
|
|
163
169
|
// field of it, and the limits, are the rent check's own (vendor/rent-check.mjs), not a data file's.
|
|
@@ -167,7 +173,12 @@ export const OUTPUT_SCHEMAS = {
|
|
|
167
173
|
city: str, leaseStart: str, startUsed: str, latest: str, truncated: z.boolean(),
|
|
168
174
|
indexPct: z.number(), currentRent: z.number(), trackedRent: z.number(),
|
|
169
175
|
proposedRent: opt(z.number()), proposedPct: opt(z.number()), gapPoints: opt(z.number()), gapDollars: opt(z.number()),
|
|
170
|
-
}),
|
|
176
|
+
}).nullable(),
|
|
177
|
+
// New in 0.12.0, the local mode (no lease_start; place-tool.mjs rentCheckLocal): result is null, and local places
|
|
178
|
+
// the rent against the median of new bonds for one place - diff_dollars and diff_pct from the median, position in
|
|
179
|
+
// words. The place's answer's other fields (its rows, page_url, cite_as) are allowed as every unnamed key is.
|
|
180
|
+
local: opt(obj({ place: str, state: str, median: z.number(), n_unit: str, small_sample: z.boolean(),
|
|
181
|
+
current: obj({ rent: z.number(), diff_dollars: z.number(), diff_pct: z.number(), position: str }) })),
|
|
171
182
|
limits: z.array(str),
|
|
172
183
|
sample_size: z.null(),
|
|
173
184
|
sample_size_note: str,
|
|
@@ -203,6 +214,9 @@ export const OUTPUT_SCHEMAS = {
|
|
|
203
214
|
...figures,
|
|
204
215
|
}),
|
|
205
216
|
|
|
217
|
+
// New in 0.12.0 (pages.mjs), on area_rents and nsw_sale_prices: place_note, the note when a suburb's name was
|
|
218
|
+
// answered for its whole postcode; page_url, the answer's one page on tools.dwelldelta.com.au, or null; pages, every
|
|
219
|
+
// shown place with a page; cite_as, a line to quote with a figure from the answer.
|
|
206
220
|
// Two kinds of answer: all dwellings together (state_total, regions, councils, areas), or by dwelling type and
|
|
207
221
|
// bedrooms (asked, rows) - so the keys of each kind are optional. area_kind: postcode, suburb or locality, from the
|
|
208
222
|
// file. derived: the medians are DwellDelta's own calculation from the bond records (WA). A row's figure is the
|
|
@@ -234,6 +248,7 @@ export const OUTPUT_SCHEMAS = {
|
|
|
234
248
|
limits: fileLimits,
|
|
235
249
|
changes_made: fromFile(str),
|
|
236
250
|
...figures,
|
|
251
|
+
...cited,
|
|
237
252
|
}),
|
|
238
253
|
|
|
239
254
|
// unit: the unit of every price field, thousands of Australian dollars, as the file states it.
|
|
@@ -255,8 +270,14 @@ export const OUTPUT_SCHEMAS = {
|
|
|
255
270
|
limits: fileLimits,
|
|
256
271
|
changes_made: fromFile(str),
|
|
257
272
|
...figures,
|
|
273
|
+
...cited,
|
|
258
274
|
}),
|
|
259
275
|
|
|
276
|
+
// property_rents (0.12.0, place-tool.mjs): the answer of area_rents or vic_rents for the state that holds the
|
|
277
|
+
// place, as that tool gives it (allowed as every unnamed key is), and resolved_state and resolved_place: the state
|
|
278
|
+
// and the place in words the question was read as.
|
|
279
|
+
property_rents: obj({ ...envelope, resolved_state: str, resolved_place: str }),
|
|
280
|
+
|
|
260
281
|
// Two answers: the consent text and token (stored: false), or the deletion code once the rent is added (stored:
|
|
261
282
|
// true). stored: whether a rent was added by this call.
|
|
262
283
|
contribute_rent: obj({
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dwelldelta-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.12.0",
|
|
4
|
+
"description": "Australian rents by area for five states, asked by place with no state, a rent placed against its local median, NSW median sale prices, an ABS rents index check, and sourced property and lending indicators, for AI agents.",
|
|
5
5
|
"mcpName": "au.com.dwelldelta/dwelldelta",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://dwelldelta.com.au/",
|
|
@@ -27,13 +27,15 @@
|
|
|
27
27
|
"vic-rents-tool.mjs",
|
|
28
28
|
"area-rents-tool.mjs",
|
|
29
29
|
"sale-prices-tool.mjs",
|
|
30
|
+
"pages.mjs",
|
|
31
|
+
"place-tool.mjs",
|
|
30
32
|
"vendor/",
|
|
31
33
|
"LICENSE",
|
|
32
34
|
"README.md"
|
|
33
35
|
],
|
|
34
36
|
"scripts": {
|
|
35
37
|
"prepack": "node scripts/vendor.mjs",
|
|
36
|
-
"test": "node --test test/*.test.mjs"
|
|
38
|
+
"test": "node --test --test-timeout=120000 --test-force-exit test/*.test.mjs"
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
39
41
|
"@modelcontextprotocol/sdk": "^1.30.1",
|
package/pages.mjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tools site's page for a place, so an answer can name a page a person (or a model citing it) can open (2026-11-03,
|
|
3
|
+
* the agent-usage review: answers cited raw JSON files and copyright notices, never a page). The addresses are the
|
|
4
|
+
* ones tools/render-area-pages.mjs gives, worked out the same way here because the npm package cannot import outside
|
|
5
|
+
* its own folder; tests/mcp-pages.test.mjs holds the two to one rule, page for page, across every published file.
|
|
6
|
+
*
|
|
7
|
+
* A page is named only where the site builds one: a place with a median (a South Australian suburb with a count too),
|
|
8
|
+
* an NSW postcode with a rent or a sale median, and each state's own page. A council has no page of its own; neither
|
|
9
|
+
* does a place whose median is withheld. Where it is not known that a page exists, the answer names none.
|
|
10
|
+
*/
|
|
11
|
+
import { isRecord } from "./tools.mjs";
|
|
12
|
+
|
|
13
|
+
export const SITE = "https://tools.dwelldelta.com.au";
|
|
14
|
+
/** The states the area pages cover (render-area-pages.mjs, area/lookup.mjs STATES). */
|
|
15
|
+
export const PAGE_STATES = ["NSW", "VIC", "QLD", "WA", "SA"];
|
|
16
|
+
|
|
17
|
+
/** The site's own slug: lower case, accents folded, every run of other characters one hyphen. */
|
|
18
|
+
export const slug = (s) => String(s).toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
19
|
+
|
|
20
|
+
export const statePage = (state) => (PAGE_STATES.includes(state) ? `${SITE}/area/${state.toLowerCase()}/` : null);
|
|
21
|
+
|
|
22
|
+
// Addresses are given across EVERY place in a file, in an order of the names alone, the later of two clashing names
|
|
23
|
+
// taking the next free "-2", "-3" (render-area-pages.mjs places()). Worked out once per list of places.
|
|
24
|
+
const memo = new WeakMap();
|
|
25
|
+
function addresses(names) {
|
|
26
|
+
const rows = [...new Set(names.map(String))].map((name) => ({ name, slug: slug(name) }));
|
|
27
|
+
const byName = rows.sort((a, b) => (a.slug < b.slug ? -1 : a.slug > b.slug ? 1 : a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
28
|
+
const seen = new Set(), out = new Map();
|
|
29
|
+
for (const p of byName) {
|
|
30
|
+
if (!p.slug) continue;
|
|
31
|
+
let s = p.slug;
|
|
32
|
+
for (let n = 2; seen.has(s); n++) s = `${p.slug}-${n}`;
|
|
33
|
+
seen.add(s);
|
|
34
|
+
out.set(p.name, s);
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function addressBook(rows) {
|
|
40
|
+
if (!memo.has(rows)) memo.set(rows, addresses(rows.filter(isRecord).map((r) => r.area)));
|
|
41
|
+
return memo.get(rows);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The page of one rents row (a postcode, suburb, locality or Victorian suburb group): its address, or null where the
|
|
46
|
+
* site builds no page for it. rows: every place row of the file the row came from (the addresses are given across all
|
|
47
|
+
* of them).
|
|
48
|
+
*/
|
|
49
|
+
export function rentPage(state, rows, row) {
|
|
50
|
+
if (!PAGE_STATES.includes(state) || !isRecord(row) || row.median_weekly_rent_aud == null) return null;
|
|
51
|
+
if (state === "SA" && row.new_bonds == null) return null;
|
|
52
|
+
if (state === "NSW") return `${SITE}/area/nsw/${slug(row.area)}/`;
|
|
53
|
+
const s = addressBook(rows).get(String(row.area));
|
|
54
|
+
return s ? `${SITE}/area/${state.toLowerCase()}/${s}/` : null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The page of one NSW sale-price postcode row: the site builds a page for a postcode with a sale median. */
|
|
58
|
+
export function salePage(row) {
|
|
59
|
+
return isRecord(row) && isRecord(row.total) && row.total.median_price_k_aud != null
|
|
60
|
+
? `${SITE}/area/nsw/${slug(row.area)}/` : null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The fields an answer gains (new in 0.12.0; no earlier field changes): page_url, the one page for the answer (the
|
|
65
|
+
* place's own when one place is shown, the state's when the state's own figure is), else null; pages, every shown
|
|
66
|
+
* place that has a page; cite_as, a line to quote with a figure from the answer - null when the answer gives no
|
|
67
|
+
* figure to quote (every one refused, allRefused: review of #74).
|
|
68
|
+
*/
|
|
69
|
+
export function citeFields({ state, places, whole, what, period, by, licence, allRefused = false }) {
|
|
70
|
+
const pages = places.filter((p) => p.url).map((p) => ({ place: p.name, url: p.url }));
|
|
71
|
+
const pageUrl = whole && !places.length ? statePage(state) : places.length === 1 ? places[0].url ?? null : null;
|
|
72
|
+
const where = pageUrl ?? statePage(state) ?? SITE;
|
|
73
|
+
const citeAs = allRefused ? null : `${what}, ${period}. Source: ${String(by ?? "").replace(/[.\s]+$/, "")}` +
|
|
74
|
+
`${licence ? `, ${licence}` : ""}. Via DwellDelta: ${where}`;
|
|
75
|
+
return { page_url: pageUrl, pages, cite_as: citeAs };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* An answer's text with its place note first and its page and citation lines just before the footer. URLs stand
|
|
80
|
+
* alone, never with punctuation glued to them (unglue in register-tools.mjs).
|
|
81
|
+
*/
|
|
82
|
+
export function withPlace(text, { note = null, page_url = null, cite_as = null } = {}, footer) {
|
|
83
|
+
const lines = text.split("\n");
|
|
84
|
+
const end = lines.length && lines[lines.length - 1] === footer ? lines.length - 1 : lines.length;
|
|
85
|
+
const tail = [...(page_url ? [`Page: ${page_url}`] : []), ...(cite_as ? [`Cite as: ${cite_as}`] : [])];
|
|
86
|
+
return [...(note ? [note, ""] : []), ...lines.slice(0, end), ...tail, ...lines.slice(end)].join("\n");
|
|
87
|
+
}
|