@htilabs/platform-common-models 0.2.0-beta.3 → 0.3.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/dist/constants/index.cjs +0 -140
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.d.cts +146 -5
- package/dist/constants/index.d.ts +146 -5
- package/dist/constants/index.js +0 -128
- package/dist/constants/index.js.map +1 -1
- package/dist/{platform-role-AHv1l5Og.d.cts → cvcEntry-wqktWfzE.d.cts} +231 -37
- package/dist/{platform-role-AHv1l5Og.d.ts → cvcEntry-wqktWfzE.d.ts} +231 -37
- package/dist/cvcs/index.cjs +2184 -0
- package/dist/cvcs/index.cjs.map +1 -0
- package/dist/cvcs/index.d.cts +2384 -0
- package/dist/cvcs/index.d.ts +2384 -0
- package/dist/cvcs/index.js +2154 -0
- package/dist/cvcs/index.js.map +1 -0
- package/dist/index--NCIPluF.d.cts +378 -0
- package/dist/index-CFOrHA8l.d.ts +378 -0
- package/dist/index.cjs +2962 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +217 -3
- package/dist/index.d.ts +217 -3
- package/dist/index.js +2934 -128
- package/dist/index.js.map +1 -1
- package/dist/models/index.cjs +211 -0
- package/dist/models/index.cjs.map +1 -1
- package/dist/models/index.d.cts +3 -292
- package/dist/models/index.d.ts +3 -292
- package/dist/models/index.js +209 -0
- package/dist/models/index.js.map +1 -1
- package/dist/{platform-auth-DHSJP7XP.d.cts → platform-auth-C-G2qeGM.d.cts} +1 -36
- package/dist/{platform-auth-DHSJP7XP.d.ts → platform-auth-C-G2qeGM.d.ts} +1 -36
- package/dist/schemas/index.cjs +195 -116
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.d.cts +11 -11
- package/dist/schemas/index.d.ts +11 -11
- package/dist/schemas/index.js +189 -116
- package/dist/schemas/index.js.map +1 -1
- package/dist/services/index.cjs +1442 -0
- package/dist/services/index.cjs.map +1 -0
- package/dist/services/index.d.cts +305 -0
- package/dist/services/index.d.ts +305 -0
- package/dist/services/index.js +1417 -0
- package/dist/services/index.js.map +1 -0
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/validation/index.cjs +261 -0
- package/dist/validation/index.cjs.map +1 -0
- package/dist/validation/index.d.cts +251 -0
- package/dist/validation/index.d.ts +251 -0
- package/dist/validation/index.js +228 -0
- package/dist/validation/index.js.map +1 -0
- package/package.json +36 -12
- package/src/__tests__/__snapshots__/cvc-sot.snap +22 -0
- package/src/__tests__/cvc-sot-snapshot.test.ts +184 -0
- package/src/__tests__/cvc-structural.test.ts +130 -0
- package/src/constants/ic.ts +0 -154
- package/src/constants/service-catalog.ts +146 -4
- package/src/cvcs/index.ts +31 -0
- package/src/cvcs/missingness.v1.0.0.json +50 -0
- package/src/cvcs/serviceCategories.v1.0.0.json +1947 -0
- package/src/cvcs/serviceMechanisms.v1.0.0.json +47 -0
- package/src/cvcs/serviceStates.v1.0.0.json +106 -0
- package/src/generated/cvc-enums.ts +215 -0
- package/src/index.ts +61 -1
- package/src/models/cvcEntryModel.ts +32 -0
- package/src/models/cvcRegistryModel.ts +35 -0
- package/src/models/index.ts +8 -0
- package/src/schemas/cvcEntry.ts +158 -0
- package/src/schemas/cvcRegistry.ts +149 -0
- package/src/schemas/index.ts +16 -0
- package/src/services/__tests__/cvcRegistryService.test.ts +614 -0
- package/src/services/cvcRegistryService.ts +729 -0
- package/src/services/index.ts +21 -0
- package/src/validation/cvc.ts +414 -0
- package/src/validation/index.ts +15 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — CVC Entry Schema
|
|
3
|
+
*
|
|
4
|
+
* Persistent storage for individual Controlled Vocabulary (CVC) entries.
|
|
5
|
+
* Every entry is keyed by `(domain, version, code)` so that multiple
|
|
6
|
+
* versions of a domain can coexist in the same collection — registries
|
|
7
|
+
* pin which (domain, version) tuples are active for a given scope.
|
|
8
|
+
*
|
|
9
|
+
* Locked spec reference:
|
|
10
|
+
* §9.1.2 — `cvc_entries` collection shape
|
|
11
|
+
* §3 — Positional 7-segment code format
|
|
12
|
+
* §3.2 — Stable machine key format
|
|
13
|
+
* /gt/docs/data/cvcs/CVC Implementation Spec 2780449faf8045258c67daab0f1c5569.md
|
|
14
|
+
*
|
|
15
|
+
* The Zod equivalents in `validation/cvc.ts` enforce the same shapes at the
|
|
16
|
+
* application boundary; the Mongoose constraints below are the persistence
|
|
17
|
+
* layer's defense in depth so that bad inserts fail loudly even if a caller
|
|
18
|
+
* skipped Zod validation.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { Schema } from "mongoose";
|
|
22
|
+
import type { InferRawDocType } from "mongoose";
|
|
23
|
+
|
|
24
|
+
// ─── Shared validators ───────────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Positional 7-segment CVC code: `XX-XX-XX-XX-XX-XX-XX`. Mirrors
|
|
28
|
+
* `CvcCodeSchema` in `validation/cvc.ts`. See locked spec §3.
|
|
29
|
+
*/
|
|
30
|
+
const CVC_CODE_PATTERN = /^\d{2}(-\d{2}){6}$/;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Stable machine key for a CVC entry. Mirrors `CvcKeySchema` in
|
|
34
|
+
* `validation/cvc.ts`. See locked spec §3.2.
|
|
35
|
+
*/
|
|
36
|
+
const CVC_KEY_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
37
|
+
|
|
38
|
+
// ─── CVC Entry Schema ────────────────────────────────────────────────────────
|
|
39
|
+
|
|
40
|
+
export const cvcEntrySchemaDefinition = {
|
|
41
|
+
// Compound identity: (domain, version, code) uniquely identifies an entry.
|
|
42
|
+
// `domain` is the SOT family (e.g. "service_categories"); `version` is the
|
|
43
|
+
// semantic version of the SOT JSON file the entry was loaded from.
|
|
44
|
+
domain: {
|
|
45
|
+
type: String,
|
|
46
|
+
required: true,
|
|
47
|
+
},
|
|
48
|
+
version: {
|
|
49
|
+
type: String,
|
|
50
|
+
required: true,
|
|
51
|
+
},
|
|
52
|
+
code: {
|
|
53
|
+
type: String,
|
|
54
|
+
required: true,
|
|
55
|
+
match: CVC_CODE_PATTERN,
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
// Stable machine key for cross-CVC references (e.g. `relevantMechanisms`
|
|
59
|
+
// in service_categories points at service_mechanisms entries by `key`).
|
|
60
|
+
key: {
|
|
61
|
+
type: String,
|
|
62
|
+
required: true,
|
|
63
|
+
match: CVC_KEY_PATTERN,
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
// Display fields
|
|
67
|
+
title: {
|
|
68
|
+
type: String,
|
|
69
|
+
required: true,
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
// `selectable` distinguishes leaf entries (selectable) from structural
|
|
73
|
+
// grouping rows (not selectable). Required because the seed CLI must
|
|
74
|
+
// populate it explicitly — there is no sane default.
|
|
75
|
+
selectable: {
|
|
76
|
+
type: Boolean,
|
|
77
|
+
required: true,
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
// Tree structure. `parentCode` is `null` for root rows; `childCodes` is
|
|
81
|
+
// empty for leaves. We give `parentCode` a `default: null` (rather than
|
|
82
|
+
// marking it required) because Mongoose's `required` validator rejects
|
|
83
|
+
// `null` outright — the default ensures the field is always present on
|
|
84
|
+
// disk while still allowing the documented `string | null` shape. The
|
|
85
|
+
// `match` validator is skipped by Mongoose when the value is null.
|
|
86
|
+
parentCode: {
|
|
87
|
+
type: String,
|
|
88
|
+
default: null,
|
|
89
|
+
match: CVC_CODE_PATTERN,
|
|
90
|
+
},
|
|
91
|
+
childCodes: {
|
|
92
|
+
type: [String],
|
|
93
|
+
required: true,
|
|
94
|
+
default: [],
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
// Long-form definition. Same `default: null` treatment as `parentCode`
|
|
98
|
+
// above — every row reaches disk with `definition` set to either a
|
|
99
|
+
// string or an explicit null.
|
|
100
|
+
definition: {
|
|
101
|
+
type: String,
|
|
102
|
+
default: null,
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
// Domain-specific extension bag. Used for fields that only apply to a
|
|
106
|
+
// particular CVC family — e.g. `relevantMechanisms` on service_categories
|
|
107
|
+
// entries (a cross-CVC reference into service_mechanisms by key).
|
|
108
|
+
meta: {
|
|
109
|
+
type: Schema.Types.Mixed,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const cvcEntrySchemaOptions = {
|
|
114
|
+
timestamps: true,
|
|
115
|
+
collection: "cvc_entities",
|
|
116
|
+
// `parentCode` defaults to null but Mongoose strips required-with-default
|
|
117
|
+
// null assignments unless we keep minimize off.
|
|
118
|
+
minimize: false,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Build the CvcEntry schema with its full set of indexes.
|
|
123
|
+
*
|
|
124
|
+
* Indexes:
|
|
125
|
+
* 1. `{ domain, version, code }` unique — primary identity. The seed CLI
|
|
126
|
+
* uses this for upsert keys.
|
|
127
|
+
* 2. `{ domain, version, key }` unique — secondary lookup target for
|
|
128
|
+
* cross-CVC references like `relevantMechanisms`.
|
|
129
|
+
* 3. `{ domain, version, parentCode }` non-unique — supports tree walks
|
|
130
|
+
* ("give me the children of this code at this version").
|
|
131
|
+
*
|
|
132
|
+
* @returns Mongoose Schema for CvcEntry
|
|
133
|
+
*/
|
|
134
|
+
export function buildCvcEntrySchema(): Schema {
|
|
135
|
+
const schema = new Schema(cvcEntrySchemaDefinition, cvcEntrySchemaOptions);
|
|
136
|
+
|
|
137
|
+
// Primary identity
|
|
138
|
+
schema.index(
|
|
139
|
+
{ domain: 1, version: 1, code: 1 },
|
|
140
|
+
{ unique: true },
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
// Secondary lookup for cross-CVC references by stable key
|
|
144
|
+
schema.index(
|
|
145
|
+
{ domain: 1, version: 1, key: 1 },
|
|
146
|
+
{ unique: true },
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
// Tree walks
|
|
150
|
+
schema.index({ domain: 1, version: 1, parentCode: 1 });
|
|
151
|
+
|
|
152
|
+
return schema;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Pre-built schema for type inference
|
|
156
|
+
const _cvcEntrySchema = buildCvcEntrySchema();
|
|
157
|
+
|
|
158
|
+
export type CvcEntry = InferRawDocType<typeof _cvcEntrySchema>;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — CVC Registry Schema
|
|
3
|
+
*
|
|
4
|
+
* A CVC Registry is a configuration bundle that pins specific versions of
|
|
5
|
+
* each Controlled Vocabulary (CVC) domain for a given application/agency
|
|
6
|
+
* scope. Consumers resolve "which entries should I use right now?" by
|
|
7
|
+
* looking up the active registry for their scope, then loading the pinned
|
|
8
|
+
* versions from `cvc_entries`.
|
|
9
|
+
*
|
|
10
|
+
* Locked spec reference:
|
|
11
|
+
* §9.1 — Generalized CVC data layer in platform-common-models
|
|
12
|
+
* /gt/docs/data/cvcs/CVC Implementation Spec 2780449faf8045258c67daab0f1c5569.md
|
|
13
|
+
*
|
|
14
|
+
* Scope hierarchy (most specific wins at lookup time):
|
|
15
|
+
* 1. (application, agencyId) — agency-specific override for an app
|
|
16
|
+
* 2. (application, null) — app-wide default
|
|
17
|
+
* 3. (null, null) — platform-wide default
|
|
18
|
+
*
|
|
19
|
+
* Lifecycle: a registry begins in `draft`, transitions to `active` (at most
|
|
20
|
+
* one active per scope), and is eventually `deprecated` when superseded.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { Schema } from "mongoose";
|
|
24
|
+
import type { InferRawDocType } from "mongoose";
|
|
25
|
+
|
|
26
|
+
// ─── CVC Registry Schema ─────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
export const cvcRegistrySchemaDefinition = {
|
|
29
|
+
// Versioning — semantic version of this registry bundle
|
|
30
|
+
version: {
|
|
31
|
+
type: String,
|
|
32
|
+
required: true,
|
|
33
|
+
match: /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/,
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
// Human-readable name (e.g. "PAVE production registry")
|
|
37
|
+
name: {
|
|
38
|
+
type: String,
|
|
39
|
+
required: true,
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
// Scope keys. `null` widens scope: a null `application` means platform-wide;
|
|
43
|
+
// a null `agencyId` means all agencies within `application`.
|
|
44
|
+
application: {
|
|
45
|
+
type: String,
|
|
46
|
+
default: null,
|
|
47
|
+
},
|
|
48
|
+
agencyId: {
|
|
49
|
+
type: Schema.Types.ObjectId,
|
|
50
|
+
default: null,
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
// Lifecycle
|
|
54
|
+
status: {
|
|
55
|
+
type: String,
|
|
56
|
+
required: true,
|
|
57
|
+
enum: ["draft", "active", "deprecated"],
|
|
58
|
+
default: "draft",
|
|
59
|
+
index: true,
|
|
60
|
+
},
|
|
61
|
+
dateActivated: {
|
|
62
|
+
type: Date,
|
|
63
|
+
},
|
|
64
|
+
dateDeactivated: {
|
|
65
|
+
type: Date,
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
// Pinned domain versions: { service_categories: "1.0.0", ... }
|
|
69
|
+
// Stored as a Map<string, string> so individual domains can be added or
|
|
70
|
+
// bumped without re-validating the whole document shape.
|
|
71
|
+
cvcVersions: {
|
|
72
|
+
type: Map,
|
|
73
|
+
of: String,
|
|
74
|
+
required: true,
|
|
75
|
+
default: () => new Map(),
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
// Selective inclusion/exclusion lists. Both contain CVC entry codes
|
|
79
|
+
// (positional 7-segment, e.g. "01-02-00-00-00-00-00"). The runtime
|
|
80
|
+
// applies excludes after includes when resolving the effective set.
|
|
81
|
+
excludedEntries: {
|
|
82
|
+
type: [String],
|
|
83
|
+
default: [],
|
|
84
|
+
},
|
|
85
|
+
includedEntries: {
|
|
86
|
+
type: [String],
|
|
87
|
+
default: [],
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
// Inheritance pointer — when set, this registry inherits cvcVersions /
|
|
91
|
+
// include / exclude lists from its base before applying its own overrides.
|
|
92
|
+
// Indexed below so a base-version bump can find every dependent registry.
|
|
93
|
+
basedOn: {
|
|
94
|
+
type: Schema.Types.ObjectId,
|
|
95
|
+
default: null,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const cvcRegistrySchemaOptions = {
|
|
100
|
+
timestamps: true,
|
|
101
|
+
collection: "cvc_registries",
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Build the CvcRegistry schema with its full set of indexes.
|
|
106
|
+
*
|
|
107
|
+
* Indexes:
|
|
108
|
+
* 1. `{ application, agencyId, version }` unique — primary identity. Two
|
|
109
|
+
* registries in the same scope cannot share a version number.
|
|
110
|
+
* 2. `{ application, agencyId, status }` partial — at most one `active`
|
|
111
|
+
* registry per scope (enforced by the `status: "active"` partial filter).
|
|
112
|
+
* 3. `{ basedOn }` — fast lookup of dependent registries when a base
|
|
113
|
+
* registry is bumped or deprecated.
|
|
114
|
+
*
|
|
115
|
+
* @returns Mongoose Schema for CvcRegistry
|
|
116
|
+
*/
|
|
117
|
+
export function buildCvcRegistrySchema(): Schema {
|
|
118
|
+
const schema = new Schema(
|
|
119
|
+
cvcRegistrySchemaDefinition,
|
|
120
|
+
cvcRegistrySchemaOptions,
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
// Primary identity: one (application, agencyId, version) tuple per registry
|
|
124
|
+
schema.index(
|
|
125
|
+
{ application: 1, agencyId: 1, version: 1 },
|
|
126
|
+
{ unique: true },
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// At most one `active` registry per scope. The partial filter ensures the
|
|
130
|
+
// uniqueness constraint only applies to active rows; draft and deprecated
|
|
131
|
+
// rows are unindexed by this index.
|
|
132
|
+
schema.index(
|
|
133
|
+
{ application: 1, agencyId: 1, status: 1 },
|
|
134
|
+
{
|
|
135
|
+
unique: true,
|
|
136
|
+
partialFilterExpression: { status: "active" },
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
// Reverse-lookup for inheritance: "what registries inherit from me?"
|
|
141
|
+
schema.index({ basedOn: 1 });
|
|
142
|
+
|
|
143
|
+
return schema;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Pre-built schema for type inference
|
|
147
|
+
const _cvcRegistrySchema = buildCvcRegistrySchema();
|
|
148
|
+
|
|
149
|
+
export type CvcRegistry = InferRawDocType<typeof _cvcRegistrySchema>;
|
package/src/schemas/index.ts
CHANGED
|
@@ -84,3 +84,19 @@ export {
|
|
|
84
84
|
platformRoleSchemaOptions,
|
|
85
85
|
type PlatformRole,
|
|
86
86
|
} from "./platform-role.js";
|
|
87
|
+
|
|
88
|
+
// CVC Registry schema
|
|
89
|
+
export {
|
|
90
|
+
buildCvcRegistrySchema,
|
|
91
|
+
cvcRegistrySchemaDefinition,
|
|
92
|
+
cvcRegistrySchemaOptions,
|
|
93
|
+
type CvcRegistry,
|
|
94
|
+
} from "./cvcRegistry.js";
|
|
95
|
+
|
|
96
|
+
// CVC Entry schema
|
|
97
|
+
export {
|
|
98
|
+
buildCvcEntrySchema,
|
|
99
|
+
cvcEntrySchemaDefinition,
|
|
100
|
+
cvcEntrySchemaOptions,
|
|
101
|
+
type CvcEntry,
|
|
102
|
+
} from "./cvcEntry.js";
|