@casomoltd/nhs-pay 0.26.0 → 0.28.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.
Files changed (47) hide show
  1. package/dist/additional-pension.js +57 -33
  2. package/dist/additional-pension.js.map +1 -1
  3. package/dist/dates.d.ts +2 -0
  4. package/dist/dates.js +17 -3
  5. package/dist/dates.js.map +1 -1
  6. package/dist/factor-basis.d.ts +1 -10
  7. package/dist/factor-basis.js +1 -10
  8. package/dist/factor-basis.js.map +1 -1
  9. package/dist/index.d.ts +5 -4
  10. package/dist/index.js +4 -4
  11. package/dist/index.js.map +1 -1
  12. package/dist/iso-date.d.ts +4 -9
  13. package/dist/iso-date.js +10 -11
  14. package/dist/iso-date.js.map +1 -1
  15. package/dist/member/benefits.d.ts +11 -0
  16. package/dist/member/benefits.js +179 -0
  17. package/dist/member/benefits.js.map +1 -0
  18. package/dist/member/index.d.ts +9 -0
  19. package/dist/member/index.js +9 -0
  20. package/dist/member/index.js.map +1 -0
  21. package/dist/member/service.d.ts +65 -0
  22. package/dist/member/service.js +166 -0
  23. package/dist/member/service.js.map +1 -0
  24. package/dist/{member-benefits.d.ts → member/types.d.ts} +30 -41
  25. package/dist/member/types.js +46 -0
  26. package/dist/member/types.js.map +1 -0
  27. package/dist/member/valuation.d.ts +67 -0
  28. package/dist/member/valuation.js +157 -0
  29. package/dist/member/valuation.js.map +1 -0
  30. package/dist/pension/ages.d.ts +105 -0
  31. package/dist/pension/ages.js +138 -0
  32. package/dist/pension/ages.js.map +1 -0
  33. package/dist/sections/section-1995.js +2 -1
  34. package/dist/sections/section-1995.js.map +1 -1
  35. package/dist/sections/section-2008.js +2 -1
  36. package/dist/sections/section-2008.js.map +1 -1
  37. package/dist/sections/section-2015.js +1 -1
  38. package/dist/sections/section-2015.js.map +1 -1
  39. package/dist/sources.d.ts +19 -2
  40. package/dist/sources.js +37 -3
  41. package/dist/sources.js.map +1 -1
  42. package/package.json +3 -3
  43. package/dist/member-benefits.js +0 -462
  44. package/dist/member-benefits.js.map +0 -1
  45. package/dist/npa.d.ts +0 -28
  46. package/dist/npa.js +0 -60
  47. package/dist/npa.js.map +0 -1
@@ -0,0 +1,179 @@
1
+ /**
2
+ * A member's benefits across every section they hold: built once from
3
+ * what the member told us, then asked one question per set of
4
+ * retirement choices.
5
+ *
6
+ * Everything ABOUT the member goes in once, when the owner is built;
7
+ * each method takes only the question. So a caller never assembles the
8
+ * member again per option, and no section, pay path or ledger is a
9
+ * thing it has to build.
10
+ *
11
+ * Rules come in two tiers. Each section's own — denominator, pay
12
+ * measure, pension age, lump sum, factors — belong to that section;
13
+ * the ones a caller reads are the legacy section's, through
14
+ * `MemberBenefits.legacy`. The rules over the whole set live
15
+ * here: which sections a member holds and whether their service is
16
+ * eligible for the McCloud remedy, then, at the drawing, summing every
17
+ * award into one pension and one automatic lump sum and taking cash
18
+ * across that one total.
19
+ *
20
+ * Its parts sit beside it: the vocabulary in `types.ts`, the service
21
+ * check and the remedy's dates in `service.ts`, and each section's award
22
+ * in `valuation.ts`. This module owns the member; `index.ts` is the door
23
+ * a caller comes through.
24
+ */
25
+ import { cashAt, nhsCommutationLimits } from '../commutation.js';
26
+ import { BenefitNotModelled, NOT_MODELLED } from '../errors.js';
27
+ import { isoToDate } from '../iso-date.js';
28
+ import { drawingTest, firstJoinedOf, mayDrawOn, memberMinimumPensionAge, normalPensionAge, } from '../pension/ages.js';
29
+ import { buildPayPath } from '../pay-path.js';
30
+ import { npaDate } from '../dates.js';
31
+ import { sumMoney } from '../pension/money.js';
32
+ import { createPrices, createPublishedPrices, TODAYS_MONEY_CPI, } from '../pension/prices.js';
33
+ import { seedFromJoinDate } from '../pension/seed.js';
34
+ import { legacyPeriodsOf, periodsOf, REMEDY, servicePeriods, } from './service.js';
35
+ import { careerAward, holdings, legacyAward, RULES, section2015, seed2015, } from './valuation.js';
36
+ import { PAST_YEARS, REMEDY_BASES, SECTIONS } from './types.js';
37
+ /** The price series each reading of the past is priced on. Total over
38
+ * `PastYears`, so a new reading fails the build until it has one. */
39
+ const CASH_SERIES = {
40
+ [PAST_YEARS.assumed]: createPrices,
41
+ [PAST_YEARS.published]: createPublishedPrices,
42
+ };
43
+ /**
44
+ * Build a member's benefits. Throws `PayPathUnavailable` where there
45
+ * is no current pay to build pay from, `BenefitNotModelled` for service
46
+ * the library does not model, and RangeError for a declaration that
47
+ * cannot be true.
48
+ *
49
+ * `today` is required because it decides which answer comes back: it
50
+ * is the date the figures are as at, so a figure reproduces as at it.
51
+ */
52
+ export function memberBenefits(member, assumptions, today) {
53
+ const held = servicePeriods(member.service);
54
+ const { legacy, ordinary2015 } = held;
55
+ const remedy = legacy !== null && legacy.window !== null;
56
+ refuseUnmodelled(member, remedy, legacy);
57
+ const born = isoToDate(member.dateOfBirth);
58
+ const history = {
59
+ born: member.dateOfBirth, firstJoined: firstJoinedOf(member),
60
+ };
61
+ const built = {
62
+ member,
63
+ history,
64
+ today,
65
+ born,
66
+ npaOn: npaDate(born, normalPensionAge(born)),
67
+ payPath: buildPayPath(member.dateOfBirth, member.pay),
68
+ legacy,
69
+ ordinary2015,
70
+ cashPrices: CASH_SERIES[assumptions.pastYears](assumptions.assumedCpi, today),
71
+ todaysPrices: createPrices(TODAYS_MONEY_CPI, today),
72
+ };
73
+ return {
74
+ periods: periodsOf(held),
75
+ remedy,
76
+ legacy: legacy === null ? null : legacyOf(legacy.section),
77
+ payPath: built.payPath,
78
+ minimumPensionAgeOn: (drawing) => memberMinimumPensionAge(history, drawing),
79
+ mayDrawOn: (drawing) => mayDrawOn(history, drawing),
80
+ now: () => holdings(built),
81
+ at: (choices) => position(built, remedy, choices),
82
+ };
83
+ }
84
+ /** Every section's award at one set of choices, summed, with cash taken
85
+ * across the total. */
86
+ function position(b, remedy, choices) {
87
+ const dates = checked(b, remedy, choices);
88
+ const awards = b.legacy === null
89
+ ? []
90
+ : legacyAwards(b, b.legacy, choices, dates);
91
+ const own = careerAward(b, {
92
+ section: SECTIONS.s2015,
93
+ window: b.ordinary2015,
94
+ seedFor: (prices) => seed2015(b, dates, prices),
95
+ }, dates);
96
+ awards.push(own.award);
97
+ const pension = sumMoney(awards.map((a) => a.pension), dates.drawing);
98
+ const automaticLumpSum = sumMoney(awards.map((a) => a.automaticLumpSum), dates.drawing);
99
+ return {
100
+ choices,
101
+ awards,
102
+ crystallised: { pension, automaticLumpSum },
103
+ cash: cashAt(pension, automaticLumpSum, choices.cash, nhsCommutationLimits(b.cashPrices)),
104
+ prices: b.cashPrices,
105
+ ...section2015(b, own, dates),
106
+ };
107
+ }
108
+ /** The legacy section's awards: on the legacy basis every legacy period
109
+ * is final salary; on the 2015 basis the remedy window leaves it for a
110
+ * career average walk, paid from the legacy section. */
111
+ function legacyAwards(b, legacy, choices, dates) {
112
+ const { own, window } = legacy;
113
+ // `checked` refused a 2015 basis for a member with no window.
114
+ const onThe2015Basis = choices.remedy.kind === REMEDY_BASES.section2015;
115
+ if (!onThe2015Basis || window === null) {
116
+ return [legacyAward(b, legacy, legacyPeriodsOf(legacy), dates)];
117
+ }
118
+ return [
119
+ legacyAward(b, legacy, [own], dates),
120
+ careerAward(b, {
121
+ section: legacy.section,
122
+ window,
123
+ seedFor: () => seedFromJoinDate(isoToDate(window.from)),
124
+ }, dates).award,
125
+ ];
126
+ }
127
+ /** Refuse a member whose service the library does not yet value. */
128
+ function refuseUnmodelled(member, remedy, legacy) {
129
+ // Deferred until the split of a pre-rollback balance is read:
130
+ // https://github.com/casomoltd/nhs-pay/issues/20
131
+ if (remedy && member.statement !== null
132
+ && isoToDate(member.statement.asAt) < isoToDate(REMEDY.rollback)) {
133
+ throw new BenefitNotModelled(NOT_MODELLED.statementBeforeRollback, 'a statement from before rollback on 1 October 2023, which '
134
+ + 'counts the remedy years in the 2015 Section');
135
+ }
136
+ // Deferred until part-time final-salary membership is modelled:
137
+ // https://github.com/casomoltd/nhs-pay/issues/26
138
+ if (member.pay.partTime === true && legacy !== null) {
139
+ throw new BenefitNotModelled(NOT_MODELLED.partTimeLegacy, 'part-time pay with 1995 or 2008 Section service, which counts '
140
+ + 'part-time membership pro rata on whole-time final pay');
141
+ }
142
+ }
143
+ /** A legacy section's rules, as `MemberBenefits.legacy` states them. */
144
+ function legacyOf(section) {
145
+ const rules = RULES[section];
146
+ return {
147
+ section,
148
+ pensionAge: rules.pensionAge,
149
+ denominator: rules.denominator,
150
+ automaticLumpSum: rules.automaticLumpSum?.multiple ?? null,
151
+ lateUplift: rules.lateUplift,
152
+ };
153
+ }
154
+ /** Refuse choices that cannot be valued, and return their dates. */
155
+ function checked(b, remedy, choices) {
156
+ const leaving = isoToDate(choices.leaving);
157
+ const drawing = isoToDate(choices.drawing);
158
+ if (drawing < leaving) {
159
+ throw new RangeError('at: drawn before leaving');
160
+ }
161
+ if (b.ordinary2015.to !== null && isoToDate(b.ordinary2015.to) < leaving) {
162
+ throw new RangeError(`at: leaving after the member already left, on ${b.ordinary2015.to}`);
163
+ }
164
+ const elects = choices.remedy.kind !== REMEDY_BASES.none;
165
+ const electionMismatch = remedy !== elects;
166
+ if (electionMismatch) {
167
+ throw new RangeError(remedy
168
+ ? 'at: a remedy member needs an election'
169
+ : 'at: an election for a member with no remediable service');
170
+ }
171
+ // The scheme pays nothing before the minimum pension age outside ill
172
+ // health, so a figure there would be one no member could draw.
173
+ const { mayDraw, minimumAge } = drawingTest(b.history, choices.drawing);
174
+ if (!mayDraw) {
175
+ throw new RangeError(`at: drawn before the minimum pension age, ${minimumAge}`);
176
+ }
177
+ return { leaving, drawing };
178
+ }
179
+ //# sourceMappingURL=benefits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"benefits.js","sourceRoot":"","sources":["../../src/member/benefits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAC,MAAM,EAAE,oBAAoB,EAAC,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAC,kBAAkB,EAAE,YAAY,EAAC,MAAM,cAAc,CAAC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IACD,qEAAqE;IACrE,+DAA+D;IAC/D,MAAM,EAAC,OAAO,EAAE,UAAU,EAAC,GAAG,WAAW,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACtE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,UAAU,CAClB,6CAA6C,UAAU,EAAE,CAC1D,CAAC;IACJ,CAAC;IACD,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * A member's benefits across every section they hold: the directory's
3
+ * door. `memberBenefits` builds them (`benefits.ts`); the vocabulary is
4
+ * `types.ts`'s, and the remedy's dates are `service.ts`'s.
5
+ */
6
+ export { memberBenefits } from './benefits.js';
7
+ export { ACCRUALS, PAST_YEARS, PERIOD_KINDS, REMEDY_BASES, SECTIONS, } from './types.js';
8
+ export type { Assumptions, Award, DeclaredPeriod, Holdings, LegacyRules, LegacySectionId, Member, MemberBenefits, PastYears, Position, RemedyBasis, RemedyElection, RetirementChoices, SectionId, ServicePeriod, } from './types.js';
9
+ export { REMEDY, SECTION_OPENED } from './service.js';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * A member's benefits across every section they hold: the directory's
3
+ * door. `memberBenefits` builds them (`benefits.ts`); the vocabulary is
4
+ * `types.ts`'s, and the remedy's dates are `service.ts`'s.
5
+ */
6
+ export { memberBenefits } from './benefits.js';
7
+ export { ACCRUALS, PAST_YEARS, PERIOD_KINDS, REMEDY_BASES, SECTIONS, } from './types.js';
8
+ export { REMEDY, SECTION_OPENED } from './service.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/member/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAC7C,OAAO,EACL,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,GAC3D,MAAM,YAAY,CAAC;AAOpB,OAAO,EAAC,MAAM,EAAE,cAAc,EAAC,MAAM,cAAc,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { DeclaredPeriod, LegacySectionId, ServicePeriod } from './types.js';
2
+ /** A legacy holding: its section, its own service, and the remedy window
3
+ * held in it after that service where the member has one. */
4
+ export interface LegacyHolding {
5
+ readonly section: LegacySectionId;
6
+ /** Its own service: to the day before the 2015 Section opened where a
7
+ * remedy window follows, else to the declared leaving. */
8
+ readonly own: ServicePeriod;
9
+ /** The McCloud remedy window; null where the member has none, which is
10
+ * the one record of whether they do. */
11
+ readonly window: ServicePeriod | null;
12
+ }
13
+ /** What a member holds: a legacy holding, if any, and the 2015 Section's
14
+ * own service after it. */
15
+ interface Held {
16
+ readonly legacy: LegacyHolding | null;
17
+ readonly ordinary2015: ServicePeriod;
18
+ }
19
+ /**
20
+ * The dates the McCloud remedy turns on, for a caller that has to read
21
+ * a member's answers against them before it can declare their service.
22
+ */
23
+ export declare const REMEDY: {
24
+ readonly eligibleBy: import("../iso-date.js").IsoDate;
25
+ readonly from: import("../iso-date.js").IsoDate;
26
+ readonly to: import("../iso-date.js").IsoDate;
27
+ readonly rollback: import("../iso-date.js").IsoDate;
28
+ };
29
+ /**
30
+ * The day each later section opened: the 2008 Section to new joiners
31
+ * under SI 2008/653, and the 2015 Section, which every member moved to
32
+ * for service from that day, under SI 2015/94. The 1995 Section is
33
+ * absent: no answer a member gives turns on its opening.
34
+ */
35
+ export declare const SECTION_OPENED: {
36
+ readonly "section-2008": import("../iso-date.js").IsoDate;
37
+ readonly "section-2015": import("../iso-date.js").IsoDate;
38
+ };
39
+ /**
40
+ * The periods a member holds, derived from what they declared and
41
+ * refused where it describes something the library does not model.
42
+ *
43
+ * Service is taken as continuous. A break — a gap between one period
44
+ * and the next — decides whether remedy service qualifies, and how a
45
+ * member comes to hold both legacy sections; both are deferred, so a
46
+ * declared break is refused rather than priced as though it were
47
+ * continuous: https://github.com/casomoltd/nhs-pay/issues/16
48
+ *
49
+ * A member with no 2015 Section service after rollback is refused
50
+ * too: https://github.com/casomoltd/nhs-pay/issues/19
51
+ *
52
+ * A declaration that cannot be true — nothing declared, leaving
53
+ * before joining, periods that overlap — is a caller's mistake and
54
+ * throws RangeError.
55
+ */
56
+ export declare function servicePeriods(declared: readonly DeclaredPeriod[]): Held;
57
+ /** Every period a member holds, in date order. */
58
+ export declare function periodsOf({ legacy, ordinary2015 }: Held): ServicePeriod[];
59
+ /** A legacy holding's periods in date order: its own service, then any
60
+ * remedy window. */
61
+ export declare function legacyPeriodsOf({ own, window }: LegacyHolding): ServicePeriod[];
62
+ /** The last day a period is valued to: its own end, or the leaving
63
+ * date where that comes first or the period is still open. */
64
+ export declare function until(p: ServicePeriod, leaving: Date): Date;
65
+ export {};
@@ -0,0 +1,166 @@
1
+ /**
2
+ * A member's service, checked: the periods they hold, derived from what
3
+ * they declared, with the McCloud remedy window split out of a legacy
4
+ * section where they have one, and the dates the remedy turns on.
5
+ */
6
+ import { dayAfter, dayBefore } from '../dates.js';
7
+ import { BenefitNotModelled, invariant, NOT_MODELLED } from '../errors.js';
8
+ import { isoDate, isoDateOf, isoToDate } from '../iso-date.js';
9
+ import { PERIOD_KINDS, SECTIONS } from './types.js';
10
+ /** The remedy period, 1 April 2015 to 31 March 2022, as PSPJOA 2022
11
+ * s.1 defines it. The days either side are derived from it. */
12
+ const REMEDY_FROM = isoDate('2015-04-01');
13
+ const REMEDY_TO = isoDate('2022-03-31');
14
+ /** PSPJOA 2022 s.1: in pensionable service "on 31 March 2012 or any
15
+ * earlier day". */
16
+ const ELIGIBLE_BY = isoDate('2012-03-31');
17
+ /** Rollback put remedy service back in the legacy section on this
18
+ * date (SI 2023/985), so a statement before it counts the remedy
19
+ * years in the 2015 Section. */
20
+ const ROLLBACK = isoDate('2023-10-01');
21
+ /**
22
+ * The dates the McCloud remedy turns on, for a caller that has to read
23
+ * a member's answers against them before it can declare their service.
24
+ */
25
+ export const REMEDY = {
26
+ eligibleBy: ELIGIBLE_BY,
27
+ from: REMEDY_FROM,
28
+ to: REMEDY_TO,
29
+ rollback: ROLLBACK,
30
+ };
31
+ /**
32
+ * The day each later section opened: the 2008 Section to new joiners
33
+ * under SI 2008/653, and the 2015 Section, which every member moved to
34
+ * for service from that day, under SI 2015/94. The 1995 Section is
35
+ * absent: no answer a member gives turns on its opening.
36
+ */
37
+ export const SECTION_OPENED = {
38
+ [SECTIONS.s2008]: isoDate('2008-04-01'),
39
+ [SECTIONS.s2015]: REMEDY_FROM,
40
+ };
41
+ const LAST_BEFORE_2015 = isoDateOf(dayBefore(isoToDate(REMEDY_FROM)));
42
+ const AFTER_REMEDY = isoDateOf(dayAfter(isoToDate(REMEDY_TO)));
43
+ /**
44
+ * The periods a member holds, derived from what they declared and
45
+ * refused where it describes something the library does not model.
46
+ *
47
+ * Service is taken as continuous. A break — a gap between one period
48
+ * and the next — decides whether remedy service qualifies, and how a
49
+ * member comes to hold both legacy sections; both are deferred, so a
50
+ * declared break is refused rather than priced as though it were
51
+ * continuous: https://github.com/casomoltd/nhs-pay/issues/16
52
+ *
53
+ * A member with no 2015 Section service after rollback is refused
54
+ * too: https://github.com/casomoltd/nhs-pay/issues/19
55
+ *
56
+ * A declaration that cannot be true — nothing declared, leaving
57
+ * before joining, periods that overlap — is a caller's mistake and
58
+ * throws RangeError.
59
+ */
60
+ export function servicePeriods(declared) {
61
+ const sections = sectionsOf(contiguous(declared));
62
+ const remedy = remedyApplies(sections);
63
+ return {
64
+ legacy: legacyHolding(sections.legacy, remedy),
65
+ ordinary2015: {
66
+ section: SECTIONS.s2015,
67
+ from: remedy ? AFTER_REMEDY : sections.current.joined,
68
+ to: sections.current.left,
69
+ kind: PERIOD_KINDS.ordinary,
70
+ },
71
+ };
72
+ }
73
+ /** Every period a member holds, in date order. */
74
+ export function periodsOf({ legacy, ordinary2015 }) {
75
+ return [...(legacy === null ? [] : legacyPeriodsOf(legacy)), ordinary2015];
76
+ }
77
+ /** A legacy holding's periods in date order: its own service, then any
78
+ * remedy window. */
79
+ export function legacyPeriodsOf({ own, window }) {
80
+ return window === null ? [own] : [own, window];
81
+ }
82
+ /** The last day a period is valued to: its own end, or the leaving
83
+ * date where that comes first or the period is still open. */
84
+ export function until(p, leaving) {
85
+ return p.to === null || isoToDate(p.to) > leaving ? leaving : isoToDate(p.to);
86
+ }
87
+ /** The declared periods in date order, each running into the next. */
88
+ function contiguous(declared) {
89
+ if (declared.length === 0) {
90
+ throw new RangeError('member: no service declared');
91
+ }
92
+ const sorted = [...declared].sort((a, b) => isoToDate(a.joined).getTime() - isoToDate(b.joined).getTime());
93
+ sorted.forEach((p, i) => {
94
+ checkFollowedBy(p, sorted.at(i + 1));
95
+ });
96
+ return sorted;
97
+ }
98
+ /** Refuse a period that cannot be true, or that leaves a gap before
99
+ * the one after it. */
100
+ function checkFollowedBy(p, next) {
101
+ if (p.left !== null && isoToDate(p.left) < isoToDate(p.joined)) {
102
+ throw new RangeError(`member: ${p.section} left before it was joined`);
103
+ }
104
+ if (next === undefined)
105
+ return;
106
+ if (p.left === null || isoToDate(next.joined) <= isoToDate(p.left)) {
107
+ throw new RangeError(`member: ${p.section} overlaps the next period`);
108
+ }
109
+ if (dayAfter(isoToDate(p.left)).getTime() !== isoToDate(next.joined).getTime()) {
110
+ throw new BenefitNotModelled(NOT_MODELLED.breakInService, 'a break in pensionable service');
111
+ }
112
+ }
113
+ /** At most one legacy period and exactly one 2015 Section period, or
114
+ * the service is not one the library models. */
115
+ function sectionsOf(sorted) {
116
+ const legacy = sorted.filter((p) => isLegacy(p.section));
117
+ const reformed = sorted.filter((p) => p.section === SECTIONS.s2015);
118
+ if (legacy.length > 1) {
119
+ throw new BenefitNotModelled(NOT_MODELLED.bothLegacySections, 'service in both legacy sections');
120
+ }
121
+ const current = reformed.at(0);
122
+ if (current === undefined || reformed.length > 1) {
123
+ throw new BenefitNotModelled(NOT_MODELLED.no2015Section, 'service without the 2015 Section');
124
+ }
125
+ return { legacy: legacy.at(0), current };
126
+ }
127
+ /** Whether the member has a remedy window: legacy service by the
128
+ * eligibility date, and 2015 Section service into the remedy period. */
129
+ function remedyApplies({ legacy, current }) {
130
+ const end = current.left;
131
+ const remedy = legacy !== undefined
132
+ && isoToDate(legacy.joined) <= isoToDate(ELIGIBLE_BY)
133
+ && (end === null || isoToDate(end) >= isoToDate(REMEDY_FROM));
134
+ if (remedy && end !== null && isoToDate(end) <= isoToDate(REMEDY_TO)) {
135
+ throw new BenefitNotModelled(NOT_MODELLED.remedyMemberLeftEarly, 'a remedy member who left before 1 April 2022');
136
+ }
137
+ return remedy;
138
+ }
139
+ /** The legacy section's periods: its own service, and the remedy
140
+ * window after it where the member has one. */
141
+ function legacyHolding(held, remedy) {
142
+ if (held === undefined || !isLegacy(held.section))
143
+ return null;
144
+ // A legacy period before a 2015 one has a leaving date: the
145
+ // contiguity check refused an open one.
146
+ invariant(held.left !== null, 'a legacy period with no end');
147
+ return {
148
+ section: held.section,
149
+ own: {
150
+ section: held.section,
151
+ from: held.joined,
152
+ to: remedy ? LAST_BEFORE_2015 : held.left,
153
+ kind: PERIOD_KINDS.ordinary,
154
+ },
155
+ window: remedy
156
+ ? {
157
+ section: held.section, from: REMEDY_FROM, to: REMEDY_TO,
158
+ kind: PERIOD_KINDS.remedyWindow,
159
+ }
160
+ : null,
161
+ };
162
+ }
163
+ function isLegacy(section) {
164
+ return section !== SECTIONS.s2015;
165
+ }
166
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/member/service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAC,MAAM,aAAa,CAAC;AAChD,OAAO,EAAC,kBAAkB,EAAE,SAAS,EAAE,YAAY,EAAC,MAAM,cAAc,CAAC;AACzE,OAAO,EAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAC,MAAM,gBAA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B,IAAgC,EAChC,MAAe;IAEf,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/D,4DAA4D;IAC5D,wCAAwC;IACxC,SAAS,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,6BAA6B,CAAC,CAAC;IAC7D,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,GAAG,EAAE;YACH,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,MAAM;YACjB,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI;YACzC,IAAI,EAAE,YAAY,CAAC,QAAQ;SAC5B;QACD,MAAM,EAAE,MAAM;YACZ,CAAC,CAAC;gBACA,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,SAAS;gBACvD,IAAI,EAAE,YAAY,CAAC,YAAY;aAChC;YACD,CAAC,CAAC,IAAI;KACT,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,OAAkB;IAClC,OAAO,OAAO,KAAK,QAAQ,CAAC,KAAK,CAAC;AACpC,CAAC"}
@@ -1,13 +1,19 @@
1
- import type { CashChoice, CommutationResult } from './commutation.js';
2
- import type { FactorOutcome } from './factor-basis.js';
3
- import type { IsoDate } from './iso-date.js';
4
- import type { MemberPay, PayPath } from './pay-path.js';
5
- import type { ProjectionPoint } from './pension/curve.js';
6
- import type { MemberLedger } from './pension/ledger.js';
7
- import type { EstimatedHistory } from './pension/history.js';
8
- import type { ProjectionMoney } from './pension/money.js';
9
- import type { Prices } from './pension/prices.js';
10
- import type { FinalSalaryRules, PayMeasure } from './sections/final-salary.js';
1
+ /**
2
+ * The vocabulary of a member's benefits: what a caller tells the library
3
+ * about a member and their choices, and the shapes it answers with. Types
4
+ * and the ids they are keyed by only, so the service check, the valuation
5
+ * and the owner in `benefits.ts` all read one definition.
6
+ */
7
+ import type { CashChoice, CommutationResult } from '../commutation.js';
8
+ import type { FactorOutcome } from '../factor-basis.js';
9
+ import type { IsoDate } from '../iso-date.js';
10
+ import type { MemberPay, PayPath } from '../pay-path.js';
11
+ import type { ProjectionPoint } from '../pension/curve.js';
12
+ import type { EstimatedHistory } from '../pension/history.js';
13
+ import type { MemberLedger } from '../pension/ledger.js';
14
+ import type { ProjectionMoney } from '../pension/money.js';
15
+ import type { Prices } from '../pension/prices.js';
16
+ import type { FinalSalaryRules, PayMeasure } from '../sections/final-salary.js';
11
17
  /**
12
18
  * One scheme, the NHS Pension Scheme, in three sections. "Scheme" only
13
19
  * ever means the whole; each part is a section, as a member's own
@@ -215,38 +221,21 @@ export interface MemberBenefits {
215
221
  readonly legacy: LegacyRules | null;
216
222
  /** The pay every section reads, built once for the member. */
217
223
  readonly payPath: PayPath;
224
+ /** The earliest age this member may draw every section they hold on
225
+ * `drawing`, other than through ill health: the law's minimum pension
226
+ * age on that day, or the protected age they keep. A 1995 Section age
227
+ * below it is that section's alone and is not modelled
228
+ * (docs/how-it-works.md#minimum-pension-age). `at()` refuses a drawing
229
+ * before they reach it. */
230
+ minimumPensionAgeOn(drawing: IsoDate): number;
231
+ /** Whether this member may draw on `drawing`, other than through ill
232
+ * health: on or after the birthday at which they reach
233
+ * `minimumPensionAgeOn(drawing)`. `at()` refuses a drawing this
234
+ * refuses. */
235
+ mayDrawOn(drawing: IsoDate): boolean;
218
236
  /** Worth today, before any drawing. */
219
237
  now(): Holdings;
220
- /** Worth when drawn, for one set of choices. */
238
+ /** Worth when drawn, for one set of choices. Throws RangeError for a
239
+ * drawing before the member reaches `minimumPensionAgeOn(drawing)`. */
221
240
  at(choices: RetirementChoices): Position;
222
241
  }
223
- /**
224
- * The dates the McCloud remedy turns on, for a caller that has to read
225
- * a member's answers against them before it can declare their service.
226
- */
227
- export declare const REMEDY: {
228
- readonly eligibleBy: IsoDate;
229
- readonly from: IsoDate;
230
- readonly to: IsoDate;
231
- readonly rollback: IsoDate;
232
- };
233
- /**
234
- * The day each later section opened: the 2008 Section to new joiners
235
- * under SI 2008/653, and the 2015 Section, which every member moved to
236
- * for service from that day, under SI 2015/94. The 1995 Section is
237
- * absent: no answer a member gives turns on its opening.
238
- */
239
- export declare const SECTION_OPENED: {
240
- readonly "section-2008": IsoDate;
241
- readonly "section-2015": IsoDate;
242
- };
243
- /**
244
- * Build a member's benefits. Throws `PayPathUnavailable` where there
245
- * is no current pay to build pay from, `BenefitNotModelled` for service
246
- * the library does not model, and RangeError for a declaration that
247
- * cannot be true.
248
- *
249
- * `today` is required because it decides which answer comes back: it
250
- * is the date the figures are as at, so a figure reproduces as at it.
251
- */
252
- export declare function memberBenefits(member: Member, assumptions: Assumptions, today: Date): MemberBenefits;
@@ -0,0 +1,46 @@
1
+ // ── Vocabulary ──────────────────────────────────────
2
+ /**
3
+ * One scheme, the NHS Pension Scheme, in three sections. "Scheme" only
4
+ * ever means the whole; each part is a section, as a member's own
5
+ * Annual Benefit Statement prints it.
6
+ */
7
+ export const SECTIONS = {
8
+ s1995: 'section-1995',
9
+ s2008: 'section-2008',
10
+ s2015: 'section-2015',
11
+ };
12
+ /** How the cash ruler reads the years behind the run date. */
13
+ export const PAST_YEARS = {
14
+ /** The assumption throughout, as for the years ahead. */
15
+ assumed: 'assumed',
16
+ /** The published record: each year's Revaluation Order, and pay
17
+ * carried into each year's cash by the same Orders' CPI, an
18
+ * approximation to the pay awards — the ledger an Annual Benefit
19
+ * Statement prints. See `createPublishedPrices`. */
20
+ published: 'published',
21
+ };
22
+ /**
23
+ * How the remedy window is valued, for a member who has one: as more
24
+ * service in their legacy section, or under the 2015 Section's rules
25
+ * while still paid from the legacy section. There is no default and no
26
+ * preferred answer: which pays more depends on the choices a caller
27
+ * compares, and the library cannot see them.
28
+ */
29
+ export const REMEDY_BASES = {
30
+ none: 'none',
31
+ legacy: 'legacy-basis',
32
+ section2015: 'section-2015-basis',
33
+ };
34
+ // ── What the library answers with ───────────────────
35
+ /** What a period is: service in its own right, or the McCloud remedy
36
+ * window, held in the legacy section and valued on either basis. */
37
+ export const PERIOD_KINDS = {
38
+ ordinary: 'ordinary',
39
+ remedyWindow: 'remedy-window',
40
+ };
41
+ /** How a section accrues: on final salary, or on a career average. */
42
+ export const ACCRUALS = {
43
+ finalSalary: 'final-salary',
44
+ careerAverage: 'career-average',
45
+ };
46
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/member/types.ts"],"names":[],"mappings":"AAiBA,uDAAuD;AAEvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,KAAK,EAAE,cAAc;IACrB,KAAK,EAAE,cAAc;IACrB,KAAK,EAAE,cAAc;CACb,CAAC;AA+BX,8DAA8D;AAC9D,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,yDAAyD;IACzD,OAAO,EAAE,SAAS;IAClB;;;yDAGqD;IACrD,SAAS,EAAE,WAAW;CACd,CAAC;AAcX;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,cAAc;IACtB,WAAW,EAAE,oBAAoB;CACzB,CAAC;AAmBX,uDAAuD;AAEvD;qEACqE;AACrE,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,QAAQ,EAAE,UAAU;IACpB,YAAY,EAAE,eAAe;CACrB,CAAC;AAYX,sEAAsE;AACtE,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,WAAW,EAAE,cAAc;IAC3B,aAAa,EAAE,gBAAgB;CACvB,CAAC"}