projectionlab-mcp 1.2.2 → 1.3.1

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 (119) hide show
  1. package/HOW-IT-WORKS.md +5 -4
  2. package/MANUAL-SETUP.md +8 -4
  3. package/README.md +1 -1
  4. package/REFERENCE.md +25 -9
  5. package/SETUP-FOR-AGENTS.md +4 -4
  6. package/dist/bootstrap.js +15 -3
  7. package/dist/bootstrap.js.map +1 -1
  8. package/dist/bridge.d.ts +29 -6
  9. package/dist/config.d.ts +0 -1
  10. package/dist/config.js +0 -2
  11. package/dist/config.js.map +1 -1
  12. package/dist/currentFinances.d.ts +60 -0
  13. package/dist/currentFinances.js +117 -2
  14. package/dist/currentFinances.js.map +1 -1
  15. package/dist/dataModel.d.ts +37 -8
  16. package/dist/dataModel.js +1138 -15
  17. package/dist/dataModel.js.map +1 -1
  18. package/dist/diff.d.ts +26 -10
  19. package/dist/diff.js +163 -23
  20. package/dist/diff.js.map +1 -1
  21. package/dist/editAccess.d.ts +15 -0
  22. package/dist/editAccess.js +29 -0
  23. package/dist/editAccess.js.map +1 -0
  24. package/dist/errors.d.ts +1 -1
  25. package/dist/errors.js.map +1 -1
  26. package/dist/extensionBridge.d.ts +44 -8
  27. package/dist/extensionBridge.js +179 -30
  28. package/dist/extensionBridge.js.map +1 -1
  29. package/dist/index.js +2 -3
  30. package/dist/index.js.map +1 -1
  31. package/dist/instructions.d.ts +1 -1
  32. package/dist/instructions.js +1 -1
  33. package/dist/layout.d.ts +68 -0
  34. package/dist/layout.js +122 -0
  35. package/dist/layout.js.map +1 -0
  36. package/dist/linkedFields.d.ts +77 -0
  37. package/dist/linkedFields.js +191 -0
  38. package/dist/linkedFields.js.map +1 -0
  39. package/dist/pathPatch.d.ts +41 -3
  40. package/dist/pathPatch.js +162 -14
  41. package/dist/pathPatch.js.map +1 -1
  42. package/dist/planSettings.d.ts +21 -2
  43. package/dist/planSettings.js +30 -6
  44. package/dist/planSettings.js.map +1 -1
  45. package/dist/planVersion.d.ts +7 -2
  46. package/dist/planVersion.js +27 -11
  47. package/dist/planVersion.js.map +1 -1
  48. package/dist/plans.d.ts +46 -6
  49. package/dist/plans.js +152 -15
  50. package/dist/plans.js.map +1 -1
  51. package/dist/realEstate.d.ts +20 -0
  52. package/dist/realEstate.js +57 -0
  53. package/dist/realEstate.js.map +1 -1
  54. package/dist/redact.d.ts +20 -0
  55. package/dist/redact.js +62 -0
  56. package/dist/redact.js.map +1 -1
  57. package/dist/resources/dataModel.d.ts +6 -2
  58. package/dist/resources/dataModel.js +96 -16
  59. package/dist/resources/dataModel.js.map +1 -1
  60. package/dist/resources/knowledge.d.ts +7 -1
  61. package/dist/resources/knowledge.js +262 -14
  62. package/dist/resources/knowledge.js.map +1 -1
  63. package/dist/resources/layoutResource.d.ts +19 -0
  64. package/dist/resources/layoutResource.js +43 -0
  65. package/dist/resources/layoutResource.js.map +1 -0
  66. package/dist/resources/planData.js +1 -1
  67. package/dist/resources/planData.js.map +1 -1
  68. package/dist/snapshot.d.ts +2 -1
  69. package/dist/snapshot.js +3 -1
  70. package/dist/snapshot.js.map +1 -1
  71. package/dist/summary.d.ts +39 -2
  72. package/dist/summary.js +148 -31
  73. package/dist/summary.js.map +1 -1
  74. package/dist/tools/bootstrap.js +2 -1
  75. package/dist/tools/bootstrap.js.map +1 -1
  76. package/dist/tools/clonePlan.js +10 -9
  77. package/dist/tools/clonePlan.js.map +1 -1
  78. package/dist/tools/connection.js +8 -8
  79. package/dist/tools/connection.js.map +1 -1
  80. package/dist/tools/deletePlan.js +9 -8
  81. package/dist/tools/deletePlan.js.map +1 -1
  82. package/dist/tools/diff.js +54 -15
  83. package/dist/tools/diff.js.map +1 -1
  84. package/dist/tools/export.js +5 -5
  85. package/dist/tools/export.js.map +1 -1
  86. package/dist/tools/getCurrentFinances.js +80 -24
  87. package/dist/tools/getCurrentFinances.js.map +1 -1
  88. package/dist/tools/getPlan.js +7 -1
  89. package/dist/tools/getPlan.js.map +1 -1
  90. package/dist/tools/getPlanSection.js +27 -4
  91. package/dist/tools/getPlanSection.js.map +1 -1
  92. package/dist/tools/getPlanSettings.js +16 -4
  93. package/dist/tools/getPlanSettings.js.map +1 -1
  94. package/dist/tools/restore.d.ts +4 -3
  95. package/dist/tools/restore.js +82 -42
  96. package/dist/tools/restore.js.map +1 -1
  97. package/dist/tools/schema.js +100 -22
  98. package/dist/tools/schema.js.map +1 -1
  99. package/dist/tools/snapshots.js +39 -19
  100. package/dist/tools/snapshots.js.map +1 -1
  101. package/dist/tools/summary.js +34 -1
  102. package/dist/tools/summary.js.map +1 -1
  103. package/dist/tools/updateAccount.js +69 -26
  104. package/dist/tools/updateAccount.js.map +1 -1
  105. package/dist/tools/updatePlanEvent.js +62 -27
  106. package/dist/tools/updatePlanEvent.js.map +1 -1
  107. package/dist/tools/updatePlanSection.js +59 -12
  108. package/dist/tools/updatePlanSection.js.map +1 -1
  109. package/dist/tools/updatePlanSettings.js +33 -13
  110. package/dist/tools/updatePlanSettings.js.map +1 -1
  111. package/dist/tools/writeGuard.d.ts +11 -0
  112. package/dist/tools/writeGuard.js +17 -0
  113. package/dist/tools/writeGuard.js.map +1 -0
  114. package/dist/types/projectionlab.d.ts +4 -0
  115. package/dist/types/wire.d.ts +57 -8
  116. package/dist/types/wire.js +16 -2
  117. package/dist/types/wire.js.map +1 -1
  118. package/package.json +1 -1
  119. package/skills/projectionlab/SKILL.md +234 -18
@@ -0,0 +1,68 @@
1
+ import { ProjectionLabError } from "./errors.js";
2
+ import type { WireMethod } from "./types/wire.js";
3
+ /**
4
+ * ProjectionLab Plugin API contracts and export layouts.
5
+ *
6
+ * The Plugin API reports its contract major version as `api.version`: 2 on
7
+ * ProjectionLab 5, absent on ProjectionLab 4, so `api.version ?? 1` names the
8
+ * contract (ProjectionLab Plugin API reference, PluginAPI.version). The
9
+ * contract is independent of the app version and of the export schema.
10
+ *
11
+ * The two contracts export different layouts:
12
+ * - "v4" (contract 1): `{ meta, today, plans, settings, progress }`.
13
+ * - "v5" (contract 2): `{ schema, exportedAt, documents: { currentFinances,
14
+ * plans, settings, accountHistory, progress? } }`, each document carrying
15
+ * its own `schema`.
16
+ */
17
+ export type ApiContract = 1 | 2;
18
+ export type ExportLayout = "v4" | "v5";
19
+ /**
20
+ * Write methods allowed on contract 2, each verified against ProjectionLab
21
+ * 5's Plugin API. The write tools and the bridge refuse any other write
22
+ * method on contract 2. Contract 1 allows every write method.
23
+ *
24
+ * restoreProgress is absent: ProjectionLab 5's restoreProgress always
25
+ * throws, because the app records Progress history itself whenever a
26
+ * current value changes.
27
+ */
28
+ export declare const CONTRACT_2_WRITES: ReadonlySet<WireMethod>;
29
+ /** Whether `method` may write to a page offering `contract`. */
30
+ export declare function writeSupported(contract: ApiContract, method: WireMethod): boolean;
31
+ /** The refusal for a write method the page's contract does not offer. */
32
+ export declare function writeNotSupportedError(method: WireMethod): ProjectionLabError;
33
+ /** The contract named by a Plugin API `version` value. */
34
+ export declare function contractFromVersion(version: unknown): ApiContract;
35
+ export declare function layoutForContract(contract: ApiContract): ExportLayout;
36
+ /** The layout of a raw `exportData` result, from its shape. */
37
+ export declare function detectLayout(raw: unknown): ExportLayout;
38
+ /** An export's sections under one set of names, whichever layout it has. */
39
+ export interface ExportSections {
40
+ layout: ExportLayout;
41
+ /** Every plan document. */
42
+ plans: unknown[];
43
+ /** v4 `today`, v5 `documents.currentFinances`. */
44
+ currentFinances: unknown;
45
+ settings: unknown;
46
+ /** v4 `progress` (category totals). Absent from v5 unless the export
47
+ * carries older history; v5 keeps per-account history in `accountHistory`. */
48
+ progress: unknown;
49
+ /** v5 `documents.accountHistory`; undefined on v4. */
50
+ accountHistory: unknown;
51
+ }
52
+ /**
53
+ * Reads an export's sections. A v5 export without a plans array is refused
54
+ * rather than read as "no plans", since every v5 profile has a Main Plan and
55
+ * an empty list would pass plan conflict checks against a real one.
56
+ */
57
+ export declare function exportSections(raw: unknown): ExportSections;
58
+ /** One named section of an export. */
59
+ export declare function sectionOf(raw: unknown, section: string): unknown;
60
+ /**
61
+ * Refuses a rollback of a snapshot taken from one export layout onto an
62
+ * account that now exports the other. A snapshot without a recorded layout
63
+ * predates layout tracking and is "v4". ProjectionLab 5 has no API path for
64
+ * v4 data: v4 backups are restored only through the app's own Restore action
65
+ * (ProjectionLab Plugin API reference, restore methods).
66
+ */
67
+ export declare function assertSnapshotLayout(snapshotLayout: ExportLayout | undefined, live: ExportLayout): void;
68
+ export declare function layoutLabel(layout: ExportLayout): string;
package/dist/layout.js ADDED
@@ -0,0 +1,122 @@
1
+ import { ProjectionLabError } from "./errors.js";
2
+ /**
3
+ * Write methods allowed on contract 2, each verified against ProjectionLab
4
+ * 5's Plugin API. The write tools and the bridge refuse any other write
5
+ * method on contract 2. Contract 1 allows every write method.
6
+ *
7
+ * restoreProgress is absent: ProjectionLab 5's restoreProgress always
8
+ * throws, because the app records Progress history itself whenever a
9
+ * current value changes.
10
+ */
11
+ export const CONTRACT_2_WRITES = new Set([
12
+ // ProjectionLab 5's restorePlans(plans, { key }) replaces the whole plans
13
+ // list, as on ProjectionLab 4: a plan missing from the array is deleted.
14
+ "restorePlans",
15
+ // updateAccount(accountId, data, { key, force }) assigns `data` over the
16
+ // top-level fields of `currentFinances.accounts[accountId]`, as on
17
+ // ProjectionLab 4. It refuses a change of `id` or `kind`, an unsupported
18
+ // `type`/`subtype`, and, without `force`, a field the account lacks.
19
+ "updateAccount",
20
+ // restoreCurrentFinances(currentFinances, { key }) takes every non-account
21
+ // field from the submission, replaces each submitted account whole, and
22
+ // keeps any stored account the submission leaves out: it never deletes an
23
+ // account. Rolling back an account change through it is exact.
24
+ "restoreCurrentFinances",
25
+ // restoreSettings(settings, { key }) replaces the whole settings document,
26
+ // as on ProjectionLab 4, after ProjectionLab's own validation of the
27
+ // document, and marks it unsaved so the app saves it.
28
+ "restoreSettings",
29
+ ]);
30
+ /** Whether `method` may write to a page offering `contract`. */
31
+ export function writeSupported(contract, method) {
32
+ return contract !== 2 || CONTRACT_2_WRITES.has(method);
33
+ }
34
+ /** The refusal for a write method the page's contract does not offer. */
35
+ export function writeNotSupportedError(method) {
36
+ if (method === "restoreProgress") {
37
+ return new ProjectionLabError("WRITE_NOT_SUPPORTED", "ProjectionLab 5 removed restoreProgress", "ProjectionLab 5 records Progress history by itself whenever a current value changes, so Progress cannot be replaced. To bring back Progress from a backup file, use Restore in the ProjectionLab app. Nothing was written.");
38
+ }
39
+ return new ProjectionLabError("WRITE_NOT_SUPPORTED", `${method} is not available on ProjectionLab 5`, "Make the change in the ProjectionLab app. Nothing was written.");
40
+ }
41
+ /** The contract named by a Plugin API `version` value. */
42
+ export function contractFromVersion(version) {
43
+ if (version === undefined || version === null)
44
+ return 1;
45
+ if (version === 2)
46
+ return 2;
47
+ throw new ProjectionLabError("UNSUPPORTED_API_VERSION", `The ProjectionLab Plugin API reports contract version ${JSON.stringify(version)}, which this server does not support`, "Update projectionlab-mcp to a release that supports this ProjectionLab version. Nothing was read or written.");
48
+ }
49
+ export function layoutForContract(contract) {
50
+ return contract === 2 ? "v5" : "v4";
51
+ }
52
+ const isObj = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
53
+ /** The layout of a raw `exportData` result, from its shape. */
54
+ export function detectLayout(raw) {
55
+ return isObj(raw) && typeof raw.schema === "number" && isObj(raw.documents) ? "v5" : "v4";
56
+ }
57
+ /**
58
+ * Reads an export's sections. A v5 export without a plans array is refused
59
+ * rather than read as "no plans", since every v5 profile has a Main Plan and
60
+ * an empty list would pass plan conflict checks against a real one.
61
+ */
62
+ export function exportSections(raw) {
63
+ const layout = detectLayout(raw);
64
+ if (layout === "v5") {
65
+ const docs = raw.documents;
66
+ if (!Array.isArray(docs.plans)) {
67
+ throw new ProjectionLabError("UNKNOWN", "The ProjectionLab export has no plans list in documents.plans", "Reload the ProjectionLab tab and try again. If it persists, ProjectionLab's export format may have changed.");
68
+ }
69
+ return {
70
+ layout,
71
+ plans: docs.plans,
72
+ currentFinances: docs.currentFinances,
73
+ settings: docs.settings,
74
+ progress: docs.progress,
75
+ accountHistory: docs.accountHistory,
76
+ };
77
+ }
78
+ const data = isObj(raw) ? raw : {};
79
+ return {
80
+ layout,
81
+ plans: Array.isArray(data.plans) ? data.plans : [],
82
+ currentFinances: data.today,
83
+ settings: data.settings,
84
+ progress: data.progress,
85
+ accountHistory: undefined,
86
+ };
87
+ }
88
+ /** One named section of an export. */
89
+ export function sectionOf(raw, section) {
90
+ const sections = exportSections(raw);
91
+ switch (section) {
92
+ case "currentFinances":
93
+ return sections.currentFinances;
94
+ case "plans":
95
+ return sections.plans;
96
+ case "progress":
97
+ return sections.progress;
98
+ case "settings":
99
+ return sections.settings;
100
+ default:
101
+ return undefined;
102
+ }
103
+ }
104
+ /**
105
+ * Refuses a rollback of a snapshot taken from one export layout onto an
106
+ * account that now exports the other. A snapshot without a recorded layout
107
+ * predates layout tracking and is "v4". ProjectionLab 5 has no API path for
108
+ * v4 data: v4 backups are restored only through the app's own Restore action
109
+ * (ProjectionLab Plugin API reference, restore methods).
110
+ */
111
+ export function assertSnapshotLayout(snapshotLayout, live) {
112
+ const taken = snapshotLayout ?? "v4";
113
+ if (taken === live)
114
+ return;
115
+ throw new ProjectionLabError("LAYOUT_MISMATCH", `This snapshot was taken from ${layoutLabel(taken)}, but the account now uses ${layoutLabel(live)}`, live === "v5"
116
+ ? "ProjectionLab 5 cannot take ProjectionLab 4 data through the Plugin API. Restore a ProjectionLab 4 backup with the Restore action in the ProjectionLab app instead. Nothing was written."
117
+ : "Data from ProjectionLab 5 cannot be written to a ProjectionLab 4 account. Nothing was written.");
118
+ }
119
+ export function layoutLabel(layout) {
120
+ return layout === "v5" ? "ProjectionLab 5" : "ProjectionLab 4";
121
+ }
122
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.js","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC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item an event links
3
+ * to, so a value written to them in a plan does not stay.
4
+ *
5
+ * Source: the plan reconciliation in ProjectionLab's shipped web build,
6
+ * version DATA_MODEL_V5_PROJECTIONLAB_VERSION (`src/dataModel.ts`). Each time
7
+ * a plan is saved or opened, ProjectionLab copies these fields onto every
8
+ * linked event from its Current Finances account or asset, skipping a field
9
+ * only when the event lists its path in `_meta.overriddenFields`. A plan
10
+ * write that changes one of them is reverted by the next read. Live writes
11
+ * on ProjectionLab 5.0.0 confirm this for an account event's type, name,
12
+ * icon, balance, liquidity, owner, hidden and withdrawal terms, an asset
13
+ * event's name, value and hidden, and a priority's owner and icon.
14
+ *
15
+ * - An account event links by `accountId` to a Current Finances account or
16
+ * debt.
17
+ * - An asset event links by `assetId` to a Current Finances real asset.
18
+ * - A priority with `accountId` takes `owner` and `icon` from the account it
19
+ * routes to; a transfer priority takes only `owner`.
20
+ *
21
+ * The baseline plan (`settings.plan.baselineId`) keeps no overrides:
22
+ * ProjectionLab deletes `_meta.overriddenFields` from its events.
23
+ *
24
+ * ProjectionLab 4 plans have no such links.
25
+ */
26
+ import type { ExportLayout } from "./layout.js";
27
+ import type { PlanObj } from "./plans.js";
28
+ import { ProjectionLabError } from "./errors.js";
29
+ /** Account event fields copied from the linked Current Finances account. */
30
+ export declare const ACCOUNT_EVENT_LINKED_FIELDS: readonly string[];
31
+ /** Asset event fields copied from the linked Current Finances real asset. */
32
+ export declare const ASSET_EVENT_LINKED_FIELDS: readonly string[];
33
+ /** Priority fields copied from the account the priority routes to. */
34
+ export declare const PRIORITY_LINKED_FIELDS: readonly string[];
35
+ /** Transfer priority fields copied from the transfer's source account. */
36
+ export declare const TRANSFER_PRIORITY_LINKED_FIELDS: readonly string[];
37
+ export interface EventLink {
38
+ /** The event field holding the link: accountId or assetId. */
39
+ linkKey: "accountId" | "assetId";
40
+ /** The id the event links to. */
41
+ linkId: string;
42
+ /** What the event links to, for messages. */
43
+ target: "Current Finances account" | "Current Finances asset" | "account the priority routes to";
44
+ /** Top-level fields ProjectionLab copies onto the event. */
45
+ fields: readonly string[];
46
+ }
47
+ /** The link a plan event carries on ProjectionLab 5, or undefined. */
48
+ export declare function eventLink(section: string, event: unknown, layout: ExportLayout): EventLink | undefined;
49
+ /** The linked field a dot path falls under, or undefined. */
50
+ export declare function linkedFieldOf(path: string, fields: readonly string[]): string | undefined;
51
+ /** Whether the event keeps its own value for a field (a plan override). */
52
+ export declare function isOverridden(event: PlanObj, field: string): boolean;
53
+ /** The baseline plan id a ProjectionLab 5 export names, or undefined. */
54
+ export declare function baselinePlanId(settings: unknown): string | undefined;
55
+ /**
56
+ * The changed paths ProjectionLab would overwrite: those under a linked field
57
+ * the event does not override. On the baseline plan no override counts.
58
+ */
59
+ export declare function linkedPathsChanged(event: PlanObj, link: EventLink, changedPaths: readonly string[], isBaseline: boolean): string[];
60
+ /**
61
+ * The Current Finances id and record behind a link. A priority links to the
62
+ * plan's account event, so its id is that event's accountId.
63
+ */
64
+ export declare function linkedRecord(link: EventLink, plan: PlanObj, currentFinances: unknown): {
65
+ id?: string;
66
+ record?: PlanObj;
67
+ };
68
+ /**
69
+ * The refusal for a plan write to fields ProjectionLab copies from a link.
70
+ * A field the Current Finances record holds is changed there with
71
+ * projectionlab_update_account; one it lacks takes the account type's default,
72
+ * which the user changes on the account in ProjectionLab.
73
+ */
74
+ export declare function linkedFieldsError(eventName: string, link: EventLink, paths: readonly string[], linked: {
75
+ id?: string;
76
+ record?: PlanObj;
77
+ }): ProjectionLabError;
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Plan event fields that ProjectionLab 5 copies from the item an event links
3
+ * to, so a value written to them in a plan does not stay.
4
+ *
5
+ * Source: the plan reconciliation in ProjectionLab's shipped web build,
6
+ * version DATA_MODEL_V5_PROJECTIONLAB_VERSION (`src/dataModel.ts`). Each time
7
+ * a plan is saved or opened, ProjectionLab copies these fields onto every
8
+ * linked event from its Current Finances account or asset, skipping a field
9
+ * only when the event lists its path in `_meta.overriddenFields`. A plan
10
+ * write that changes one of them is reverted by the next read. Live writes
11
+ * on ProjectionLab 5.0.0 confirm this for an account event's type, name,
12
+ * icon, balance, liquidity, owner, hidden and withdrawal terms, an asset
13
+ * event's name, value and hidden, and a priority's owner and icon.
14
+ *
15
+ * - An account event links by `accountId` to a Current Finances account or
16
+ * debt.
17
+ * - An asset event links by `assetId` to a Current Finances real asset.
18
+ * - A priority with `accountId` takes `owner` and `icon` from the account it
19
+ * routes to; a transfer priority takes only `owner`.
20
+ *
21
+ * The baseline plan (`settings.plan.baselineId`) keeps no overrides:
22
+ * ProjectionLab deletes `_meta.overriddenFields` from its events.
23
+ *
24
+ * ProjectionLab 4 plans have no such links.
25
+ */
26
+ import { ProjectionLabError } from "./errors.js";
27
+ /** Account event fields copied from the linked Current Finances account. */
28
+ export const ACCOUNT_EVENT_LINKED_FIELDS = [
29
+ "type",
30
+ "subtype",
31
+ "name",
32
+ "icon",
33
+ "balance",
34
+ "costBasis",
35
+ "liquidity",
36
+ "investable",
37
+ "owner",
38
+ "recipient",
39
+ "notes",
40
+ "hidden",
41
+ "originalOwnerBirth",
42
+ "originalOwnerDeath",
43
+ "EWAge",
44
+ "hasEWPenalty",
45
+ "EWPenaltyRate",
46
+ "withdrawContribsFree",
47
+ ];
48
+ /** Asset event fields copied from the linked Current Finances real asset. */
49
+ export const ASSET_EVENT_LINKED_FIELDS = [
50
+ "name",
51
+ "type",
52
+ "subtype",
53
+ "owner",
54
+ "purchasePrice",
55
+ "value",
56
+ "liquidity",
57
+ "investable",
58
+ "initialBuildingValue",
59
+ "initialBuildingValueType",
60
+ "loans",
61
+ "notes",
62
+ "hidden",
63
+ "icon",
64
+ ];
65
+ /** Priority fields copied from the account the priority routes to. */
66
+ export const PRIORITY_LINKED_FIELDS = ["owner", "icon"];
67
+ /** Transfer priority fields copied from the transfer's source account. */
68
+ export const TRANSFER_PRIORITY_LINKED_FIELDS = ["owner"];
69
+ function linkValue(event, key) {
70
+ const value = event[key];
71
+ return typeof value === "string" && value.length > 0 ? value : undefined;
72
+ }
73
+ /** The link a plan event carries on ProjectionLab 5, or undefined. */
74
+ export function eventLink(section, event, layout) {
75
+ if (layout !== "v5" || !event || typeof event !== "object" || Array.isArray(event)) {
76
+ return undefined;
77
+ }
78
+ const obj = event;
79
+ if (section === "accounts") {
80
+ const linkId = linkValue(obj, "accountId");
81
+ return linkId
82
+ ? { linkKey: "accountId", linkId, target: "Current Finances account", fields: ACCOUNT_EVENT_LINKED_FIELDS }
83
+ : undefined;
84
+ }
85
+ if (section === "assets") {
86
+ const linkId = linkValue(obj, "assetId");
87
+ return linkId
88
+ ? { linkKey: "assetId", linkId, target: "Current Finances asset", fields: ASSET_EVENT_LINKED_FIELDS }
89
+ : undefined;
90
+ }
91
+ if (section === "priorities") {
92
+ const linkId = linkValue(obj, "accountId");
93
+ if (!linkId)
94
+ return undefined;
95
+ const transfer = obj.type === "transfer" || obj.goalIntent === "transfer";
96
+ return {
97
+ linkKey: "accountId",
98
+ linkId,
99
+ target: "account the priority routes to",
100
+ fields: transfer ? TRANSFER_PRIORITY_LINKED_FIELDS : PRIORITY_LINKED_FIELDS,
101
+ };
102
+ }
103
+ return undefined;
104
+ }
105
+ /** The linked field a dot path falls under, or undefined. */
106
+ export function linkedFieldOf(path, fields) {
107
+ return fields.find((field) => path === field || path.startsWith(`${field}.`));
108
+ }
109
+ /** Whether the event keeps its own value for a field (a plan override). */
110
+ export function isOverridden(event, field) {
111
+ const meta = event._meta;
112
+ if (!meta || typeof meta !== "object" || Array.isArray(meta))
113
+ return false;
114
+ const overridden = meta.overriddenFields;
115
+ if (!overridden || typeof overridden !== "object" || Array.isArray(overridden)) {
116
+ return false;
117
+ }
118
+ return overridden[field] === true;
119
+ }
120
+ /** The baseline plan id a ProjectionLab 5 export names, or undefined. */
121
+ export function baselinePlanId(settings) {
122
+ if (!settings || typeof settings !== "object")
123
+ return undefined;
124
+ const plan = settings.plan;
125
+ if (!plan || typeof plan !== "object")
126
+ return undefined;
127
+ const id = plan.baselineId;
128
+ return typeof id === "string" && id.length > 0 ? id : undefined;
129
+ }
130
+ /**
131
+ * The changed paths ProjectionLab would overwrite: those under a linked field
132
+ * the event does not override. On the baseline plan no override counts.
133
+ */
134
+ export function linkedPathsChanged(event, link, changedPaths, isBaseline) {
135
+ return changedPaths.filter((path) => {
136
+ const field = linkedFieldOf(path, link.fields);
137
+ if (field === undefined)
138
+ return false;
139
+ return isBaseline || !isOverridden(event, field);
140
+ });
141
+ }
142
+ /**
143
+ * The Current Finances id and record behind a link. A priority links to the
144
+ * plan's account event, so its id is that event's accountId.
145
+ */
146
+ export function linkedRecord(link, plan, currentFinances) {
147
+ let id = link.linkId;
148
+ if (link.target === "account the priority routes to") {
149
+ const accountEvents = plan.accounts?.events;
150
+ const routed = Array.isArray(accountEvents)
151
+ ? accountEvents.find((e) => e && typeof e === "object" && e.id === link.linkId)
152
+ : undefined;
153
+ id = routed ? linkValue(routed, "accountId") : undefined;
154
+ }
155
+ if (id === undefined)
156
+ return {};
157
+ const accounts = currentFinances?.accounts;
158
+ const record = accounts && typeof accounts === "object" && !Array.isArray(accounts)
159
+ ? accounts[id]
160
+ : undefined;
161
+ return record && typeof record === "object" ? { id, record } : { id };
162
+ }
163
+ /**
164
+ * The refusal for a plan write to fields ProjectionLab copies from a link.
165
+ * A field the Current Finances record holds is changed there with
166
+ * projectionlab_update_account; one it lacks takes the account type's default,
167
+ * which the user changes on the account in ProjectionLab.
168
+ */
169
+ export function linkedFieldsError(eventName, link, paths, linked) {
170
+ const where = link.target === "account the priority routes to"
171
+ ? `the account it routes to (plan account event "${link.linkId}")`
172
+ : `its ${link.target} (${link.linkKey} "${link.linkId}")`;
173
+ const held = paths.filter((path) => {
174
+ const field = linkedFieldOf(path, link.fields);
175
+ return (field !== undefined &&
176
+ linked.record !== undefined &&
177
+ Object.prototype.hasOwnProperty.call(linked.record, field));
178
+ });
179
+ const missing = paths.filter((path) => !held.includes(path));
180
+ const steps = [];
181
+ if (held.length > 0) {
182
+ steps.push(`Change ${held.join(", ")} with projectionlab_update_account on Current Finances id "${linked.id}"; every plan linked to it takes the new value`);
183
+ }
184
+ if (missing.length > 0) {
185
+ steps.push(linked.record === undefined
186
+ ? `Change ${missing.join(", ")} on the linked item in ProjectionLab; the export holds no Current Finances record for it`
187
+ : `The Current Finances record holds no ${missing.join(", ")}, so ProjectionLab fills ${missing.length === 1 ? "it" : "them"} from the account type's default; ask the user to change ${missing.length === 1 ? "it" : "them"} on the account in ProjectionLab`);
188
+ }
189
+ return new ProjectionLabError("INVALID_INPUT", `Event "${eventName}" takes ${paths.join(", ")} from ${where}; ProjectionLab overwrites a value written to it in the plan`, steps.join(". "));
190
+ }
191
+ //# sourceMappingURL=linkedFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linkedFields.js","sourceRoot":"","sources":["../src/linkedFields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,4EAA4E;AAC5E,MAAM,CAAC,MAAM,2BAA2B,GAAsB;IAC5D,MAAM;IACN,SAAS;IACT,MAAM;IACN,MAAM;IACN,SAAS;IACT,WAAW;IACX,WAAW;IACX,YAAY;IACZ,OAAO;IACP,WAAW;IACX,OAAO;IACP,QAAQ;IACR,oBAAoB;IACpB,oBAAoB;IACpB,OAAO;IACP,cAAc;IACd,eAAe;IACf,sBAAsB;CACvB,CAAC;AAEF,6EAA6E;AAC7E,MAAM,CAAC,MAAM,yBAAyB,GAAsB;IAC1D,MAAM;IACN,MAAM;IACN,SAAS;IACT,OAAO;IACP,eAAe;IACf,OAAO;IACP,WAAW;IACX,YAAY;IACZ,sBAAsB;IACtB,0BAA0B;IAC1B,OAAO;IACP,OAAO;IACP,QAAQ;IACR,MAAM;CACP,CAAC;AAEF,sEAAsE;AACtE,MAAM,CAAC,MAAM,sBAAsB,GAAsB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAE3E,0EA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AAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,KAAK,CAAC,IAAI,CACR,UAAU,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,8DAA8D,MAAM,CAAC,EAAE,gDAAgD,CACjJ,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,KAAK,CAAC,IAAI,CACR,MAAM,CAAC,MAAM,KAAK,SAAS;YACzB,CAAC,CAAC,UAAU,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,0FAA0F;YACxH,CAAC,CAAC,wCAAwC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,4BAA4B,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,4DAA4D,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,kCAAkC,CACjQ,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,kBAAkB,CAC3B,eAAe,EACf,UAAU,SAAS,WAAW,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,KAAK,8DAA8D,EAC1H,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CACjB,CAAC;AACJ,CAAC"}
@@ -1,3 +1,5 @@
1
+ import { ProjectionLabError } from "./errors.js";
2
+ import type { ExportLayout } from "./layout.js";
1
3
  import type { PlanObj } from "./plans.js";
2
4
  export interface AddressableValue {
3
5
  path: string;
@@ -22,15 +24,51 @@ export interface AddressableValueOptions {
22
24
  * their exact path is explicitly expanded.
23
25
  */
24
26
  export declare function listAddressableValues(data: unknown, prefix?: string, options?: AddressableValueOptions): AddressableValue[];
27
+ /**
28
+ * Refusal for a field a write adds, where the container holds nothing at
29
+ * `path` yet: every leaf of the new value counts as changed, arrays included.
30
+ */
31
+ export declare function enumRefusalForNewValue(scope: string, path: string, value: unknown, layout: ExportLayout): ProjectionLabError | undefined;
32
+ /**
33
+ * Whether writing `value` at `path` of `data` would change anything, compared
34
+ * by value rather than by JSON text. A patch leaf that already holds this
35
+ * value is not a write of that value, so the observed enums do not apply to
36
+ * it.
37
+ */
38
+ export declare function pathValueUnchanged(data: unknown, path: string, value: unknown): boolean;
25
39
  /**
26
40
  * Apply path-addressed changes immutably. Paths must already exist and values
27
41
  * must retain their JSON type. When `scope` names a group in the data model
28
42
  * registry (a settings section, event section, or Current Finances
29
- * collection), a string value outside an observed enum's choices is refused
30
- * with INVALID_INPUT.
43
+ * collection) of the `layout` data model, a string value outside an observed
44
+ * enum's choices is refused with INVALID_INPUT, at the addressed path and at
45
+ * every path nested inside a whole-object or whole-array value. A leaf is
46
+ * checked only when the write changes it, so an out-of-list value the stored
47
+ * object already holds does not block writing the fields beside it.
31
48
  */
32
- export declare function applyExistingPathChanges(data: unknown, incoming: Record<string, unknown>, context: PathPatchContext, scope?: string): {
49
+ export declare function applyExistingPathChanges(data: unknown, incoming: Record<string, unknown>, context: PathPatchContext, scope?: string, layout?: ExportLayout): {
33
50
  updated: PlanObj;
34
51
  changes: Record<string, PathValueChange>;
35
52
  };
53
+ /** A patched path whose stored value does not match what the write sent. */
54
+ export interface PathChangeMismatch {
55
+ path: string;
56
+ /** The value the caller asked to store. */
57
+ expected: unknown;
58
+ /** The value the plan holds now; `undefined` when the path is absent. */
59
+ stored: unknown;
60
+ /**
61
+ * `absent` means the path disappeared, `shape` means the stored value is a
62
+ * different kind of value than the one sent, and `value` means it is the
63
+ * right kind holding different contents.
64
+ */
65
+ reason: "absent" | "shape" | "value";
66
+ }
67
+ /**
68
+ * Report the patched paths the stored object does not carry.
69
+ *
70
+ * The reason splits the causes a boolean cannot: a path the app dropped, a
71
+ * value it changed the type of, and a value whose contents differ.
72
+ */
73
+ export declare function findPathChangeMismatches(data: unknown, expected: Record<string, PathValueChange>, context: PathPatchContext): PathChangeMismatch[];
36
74
  export declare function pathChangesApplied(data: unknown, expected: Record<string, PathValueChange>, context: PathPatchContext): boolean;