@htilabs/platform-common-models 0.85.0 → 0.86.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htilabs/platform-common-models",
3
- "version": "0.85.0",
3
+ "version": "0.86.0",
4
4
  "description": "Shared constants, types, and models for HTI Labs applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -58,7 +58,8 @@ describe("the stored names", () => {
58
58
 
59
59
  it("are declared by the Mongoose fragment and the row schema, after the existing keys", () => {
60
60
  const fragmentKeys = Object.keys(organizationProgramSchemaDefinition);
61
- expect(fragmentKeys.slice(-7)).toEqual([...PROGRAM_DETAIL_KEYS]);
61
+ // The seven details follow the nine keys published before 0.76.0 (the team link, 0.86.0, follows them).
62
+ expect(fragmentKeys.slice(9, 16)).toEqual([...PROGRAM_DETAIL_KEYS]);
62
63
  expect([...ORGANIZATION_PROGRAM_ROW_KEYS]).toEqual(fragmentKeys);
63
64
  // The nine keys published before 0.76.0 are unchanged and still first.
64
65
  expect(fragmentKeys.slice(0, 9)).toEqual([
@@ -0,0 +1,107 @@
1
+ /**
2
+ * The program's team link on `organizations.programs[]` (0.86.0): `teamId`
3
+ * (the first linked team) and `teamIds` (every linked team; one program may
4
+ * have several, Crysta 2026-10-18). Canon: the UDD Program object's
5
+ * `team_id` · `team_ids` (platform-prototype `src/agencyhub.jsx`
6
+ * `roElevateProgramToTeam`, `linkTeamToProgramH`), stored camelCase like the
7
+ * rest of the row.
8
+ */
9
+
10
+ import mongoose, { Schema } from "mongoose";
11
+ import { describe, expect, it } from "vitest";
12
+
13
+ import {
14
+ addOrganizationProgramsField,
15
+ organizationProgramSchemaDefinition,
16
+ } from "../../schemas/organization-program.js";
17
+ import { ORGANIZATION_PROGRAM_ROW_KEYS, OrganizationProgramRowSchema } from "../index.js";
18
+
19
+ const LINKED = {
20
+ programId: "prog-1",
21
+ name: "Crisis Shelter",
22
+ teamId: "65f000000000000000000001",
23
+ teamIds: ["65f000000000000000000001", "65f000000000000000000002"],
24
+ };
25
+
26
+ describe("the keys", () => {
27
+ it("the row keys list both, last, after every key published before", () => {
28
+ expect([...ORGANIZATION_PROGRAM_ROW_KEYS].slice(-2)).toEqual(["teamId", "teamIds"]);
29
+ expect([...ORGANIZATION_PROGRAM_ROW_KEYS]).toEqual(
30
+ Object.keys(organizationProgramSchemaDefinition),
31
+ );
32
+ });
33
+
34
+ it("the fragment declares them optional; the list does not default to empty", () => {
35
+ expect(organizationProgramSchemaDefinition.teamId).toEqual({ type: String, required: false });
36
+ expect(organizationProgramSchemaDefinition.teamIds).toEqual({
37
+ type: [String],
38
+ required: false,
39
+ default: undefined,
40
+ });
41
+ });
42
+ });
43
+
44
+ describe("the row schema", () => {
45
+ it("parses a row with the link, exactly as stored", () => {
46
+ const parsed = OrganizationProgramRowSchema.parse(LINKED);
47
+ expect(parsed.teamId).toBe(LINKED.teamId);
48
+ expect(parsed.teamIds).toEqual(LINKED.teamIds);
49
+ });
50
+
51
+ it("parses a row without them as no link", () => {
52
+ const parsed = OrganizationProgramRowSchema.parse({ programId: "p", name: "N" });
53
+ expect(parsed.teamId).toBeUndefined();
54
+ expect(parsed.teamIds).toBeUndefined();
55
+ });
56
+
57
+ it("a malformed link reads as not on record and never fails the row", () => {
58
+ const parsed = OrganizationProgramRowSchema.safeParse({
59
+ programId: "p",
60
+ name: "N",
61
+ teamId: 7,
62
+ teamIds: "t1",
63
+ });
64
+ expect(parsed.success).toBe(true);
65
+ const link = parsed.success ? [parsed.data.teamId, parsed.data.teamIds] : null;
66
+ expect(link).toEqual([undefined, undefined]);
67
+ });
68
+
69
+ it("still drops a key outside the fragment", () => {
70
+ const parsed = OrganizationProgramRowSchema.parse({
71
+ ...LINKED,
72
+ team_ids: ["t9"],
73
+ somethingElse: 1,
74
+ });
75
+ expect("team_ids" in parsed).toBe(false);
76
+ expect("somethingElse" in parsed).toBe(false);
77
+ });
78
+ });
79
+
80
+ describe("the Mongoose fragment", () => {
81
+ const schema = new Schema({ name: String });
82
+ addOrganizationProgramsField(schema);
83
+ const Org = mongoose.model("ProgramTeamLinkFragmentOrg", schema);
84
+ const storedPrograms = (doc: { toObject(): unknown }) =>
85
+ (doc.toObject() as { programs: Record<string, unknown>[] }).programs;
86
+
87
+ it("keeps the link on a cast (a program edit no longer erases it)", () => {
88
+ const doc = new Org({ name: "Org", programs: [LINKED] });
89
+ expect(doc.validateSync()).toBeUndefined();
90
+ const stored = storedPrograms(doc)[0]!;
91
+ expect([stored.teamId, stored.teamIds]).toEqual([LINKED.teamId, LINKED.teamIds]);
92
+ });
93
+
94
+ it("a row with no link stores neither key (absent, never an empty list)", () => {
95
+ const doc = new Org({ name: "Org", programs: [{ programId: "p", name: "N" }] });
96
+ const stored = storedPrograms(doc)[0]!;
97
+ expect("teamId" in stored).toBe(false);
98
+ expect("teamIds" in stored).toBe(false);
99
+ });
100
+
101
+ it("still drops the sheet's snake_case spelling", () => {
102
+ const snake = { programId: "p", name: "N", team_ids: ["t9"] };
103
+ const doc = new Org({ name: "Org", programs: [snake] });
104
+ const stored = storedPrograms(doc)[0]!;
105
+ expect("team_ids" in stored).toBe(false);
106
+ });
107
+ });
@@ -27,6 +27,8 @@ export const ORGANIZATION_PROGRAM_ROW_KEYS = Object.freeze([
27
27
  "operatingEndDate",
28
28
  "locationId",
29
29
  "notes",
30
+ "teamId",
31
+ "teamIds",
30
32
  ] as const);
31
33
 
32
34
  export type OrganizationProgramRowKey = (typeof ORGANIZATION_PROGRAM_ROW_KEYS)[number];
@@ -43,7 +45,8 @@ const detailText = z.string().nullish().catch(undefined);
43
45
  * One stored program row. `programId` + `name` are required; the rest are
44
46
  * optional and may be null. Unknown keys are stripped (a reader never relies
45
47
  * on a key outside the fragment). The seven Program-record detail keys
46
- * (`programType` … `notes`, 0.76.0) never fail the row.
48
+ * (`programType` … `notes`, 0.76.0) and the team link (`teamId`, `teamIds`,
49
+ * 0.86.0) never fail the row: a value of the wrong kind reads as not on record.
47
50
  */
48
51
  export const OrganizationProgramRowSchema = z.object({
49
52
  programId: z.string().min(1),
@@ -64,6 +67,10 @@ export const OrganizationProgramRowSchema = z.object({
64
67
  operatingEndDate: detailText,
65
68
  locationId: detailText,
66
69
  notes: detailText,
70
+ /** The first team that works for the program (canon `team_id`). */
71
+ teamId: detailText,
72
+ /** Every team that works for the program (canon `team_ids`). */
73
+ teamIds: z.array(z.string()).nullish().catch(undefined),
67
74
  });
68
75
 
69
76
  export type OrganizationProgramRow = z.infer<typeof OrganizationProgramRowSchema>;
@@ -71,9 +71,21 @@
71
71
  * type is offered, whose site a program may name) live with the pure reader
72
72
  * `../orgDirectory/programDetails.ts`.
73
73
  *
74
+ * ## The team link (0.86.0)
75
+ *
76
+ * `teamId` and `teamIds` are the UDD Program object's `team_id` · `team_ids`
77
+ * (canon platform-prototype `src/agencyhub.jsx` `roElevateProgramToTeam`,
78
+ * `linkTeamToProgramH`): which team or teams work for the program. One program
79
+ * may have several teams (Crysta 2026-10-18, "One program, two teams"):
80
+ * `teamIds` lists every linked team, `teamId` is the first of them. Both are
81
+ * optional; absent means no team is linked, as before. Stored camelCase like
82
+ * the rest of the row. Declaring them here is what keeps them: the strict
83
+ * sub-schema dropped them on cast, so a link written today was erased by the
84
+ * next program edit. Nothing reads them yet.
85
+ *
74
86
  * Still NOT on the row (UDD columns production does not store yet):
75
- * `agency_id`, `app`, `team_id` / `team_ids`, `grant_id` (derived from the
76
- * dated award link), `can_refer_to`, `enrollment_subtypes`.
87
+ * `agency_id`, `app`, `grant_id` (derived from the dated award link),
88
+ * `can_refer_to`, `enrollment_subtypes`.
77
89
  *
78
90
  * ## Who dedupes
79
91
  *
@@ -169,6 +181,17 @@ export const organizationProgramSchemaDefinition = {
169
181
  locationId: { type: String, required: false },
170
182
  /** The editor's notes. */
171
183
  notes: { type: String, required: false },
184
+ /**
185
+ * The first team that works for the program (`teams._id` as a string;
186
+ * canon `team_id`). Equal to `teamIds[0]` when both are written.
187
+ */
188
+ teamId: { type: String, required: false },
189
+ /**
190
+ * Every team that works for the program (canon `team_ids`; one program may
191
+ * have several teams). `default: undefined`, so a row with no link stores
192
+ * nothing and reads as absent, never as an empty list.
193
+ */
194
+ teamIds: { type: [String], required: false, default: undefined },
172
195
  } as const;
173
196
 
174
197
  /**