@htilabs/platform-common-models 0.1.0-beta.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 (48) hide show
  1. package/dist/constants/index.cjs +1379 -0
  2. package/dist/constants/index.cjs.map +1 -0
  3. package/dist/constants/index.d.cts +528 -0
  4. package/dist/constants/index.d.ts +528 -0
  5. package/dist/constants/index.js +1252 -0
  6. package/dist/constants/index.js.map +1 -0
  7. package/dist/index.cjs +2138 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.d.cts +5 -0
  10. package/dist/index.d.ts +5 -0
  11. package/dist/index.js +1986 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/models/index.cjs +661 -0
  14. package/dist/models/index.cjs.map +1 -0
  15. package/dist/models/index.d.cts +204 -0
  16. package/dist/models/index.d.ts +204 -0
  17. package/dist/models/index.js +636 -0
  18. package/dist/models/index.js.map +1 -0
  19. package/dist/schemas/index.cjs +1405 -0
  20. package/dist/schemas/index.cjs.map +1 -0
  21. package/dist/schemas/index.d.cts +312 -0
  22. package/dist/schemas/index.d.ts +312 -0
  23. package/dist/schemas/index.js +1353 -0
  24. package/dist/schemas/index.js.map +1 -0
  25. package/dist/scoring-rule-BOkG46I3.d.cts +1179 -0
  26. package/dist/scoring-rule-BOkG46I3.d.ts +1179 -0
  27. package/dist/types/index.cjs +19 -0
  28. package/dist/types/index.cjs.map +1 -0
  29. package/dist/types/index.d.cts +1 -0
  30. package/dist/types/index.d.ts +1 -0
  31. package/dist/types/index.js +1 -0
  32. package/dist/types/index.js.map +1 -0
  33. package/package.json +81 -0
  34. package/src/constants/ic.ts +1630 -0
  35. package/src/constants/index.ts +11 -0
  36. package/src/index.ts +30 -0
  37. package/src/models/formModel.ts +30 -0
  38. package/src/models/index.ts +72 -0
  39. package/src/models/questionModel.ts +30 -0
  40. package/src/models/scoringRuleModel.ts +33 -0
  41. package/src/models/sectionModel.ts +30 -0
  42. package/src/schemas/common.ts +118 -0
  43. package/src/schemas/form.ts +125 -0
  44. package/src/schemas/index.ts +70 -0
  45. package/src/schemas/question.ts +297 -0
  46. package/src/schemas/scoring-rule.ts +169 -0
  47. package/src/schemas/section.ts +158 -0
  48. package/src/types/index.ts +47 -0
@@ -0,0 +1,661 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/models/index.ts
21
+ var models_exports = {};
22
+ __export(models_exports, {
23
+ createPlatformModels: () => createPlatformModels,
24
+ formModel: () => formModel_exports,
25
+ questionModel: () => questionModel_exports,
26
+ scoringRuleModel: () => scoringRuleModel_exports,
27
+ sectionModel: () => sectionModel_exports
28
+ });
29
+ module.exports = __toCommonJS(models_exports);
30
+
31
+ // src/models/formModel.ts
32
+ var formModel_exports = {};
33
+ __export(formModel_exports, {
34
+ buildSchema: () => buildFormSchema,
35
+ compileModel: () => compileModel
36
+ });
37
+
38
+ // src/schemas/form.ts
39
+ var import_mongoose = require("mongoose");
40
+ var formSectionRefSchema = new import_mongoose.Schema(
41
+ {
42
+ sectionId: { type: String, required: true },
43
+ sectionVersion: { type: String, required: true },
44
+ index: { type: Number, required: true },
45
+ isStep: { type: Boolean, default: false },
46
+ wizardStep: { type: Number },
47
+ label: { type: String },
48
+ presetsType: { type: String }
49
+ },
50
+ { _id: false }
51
+ );
52
+ var formSchemaDefinition = {
53
+ _schemaVersion: {
54
+ type: Number,
55
+ required: true,
56
+ default: 1
57
+ },
58
+ // Audit fields
59
+ createdUser: {
60
+ type: import_mongoose.Schema.Types.ObjectId,
61
+ required: true,
62
+ index: true
63
+ },
64
+ updatedUser: {
65
+ type: import_mongoose.Schema.Types.ObjectId,
66
+ index: true
67
+ },
68
+ // Versioning
69
+ key: {
70
+ type: String,
71
+ required: true
72
+ },
73
+ version: {
74
+ type: String,
75
+ required: true
76
+ },
77
+ // Form info
78
+ name: {
79
+ type: String,
80
+ required: true
81
+ },
82
+ description: {
83
+ type: String
84
+ },
85
+ formType: {
86
+ type: String,
87
+ index: true
88
+ },
89
+ appScope: {
90
+ type: [String],
91
+ enum: ["thread", "pave", "both"],
92
+ default: []
93
+ },
94
+ // Ordered sections
95
+ sections: {
96
+ type: [formSectionRefSchema],
97
+ default: []
98
+ },
99
+ // Lifecycle
100
+ status: {
101
+ type: String,
102
+ required: true,
103
+ enum: ["draft", "active", "deprecated"],
104
+ default: "draft",
105
+ index: true
106
+ },
107
+ supersedes: {
108
+ type: String
109
+ }
110
+ };
111
+ var formSchemaOptions = {
112
+ timestamps: {
113
+ createdAt: "createdTime",
114
+ updatedAt: "updatedTime"
115
+ },
116
+ collection: "forms"
117
+ };
118
+ function buildFormSchema() {
119
+ const schema = new import_mongoose.Schema(formSchemaDefinition, formSchemaOptions);
120
+ schema.index({ key: 1, version: 1 }, { unique: true });
121
+ schema.index(
122
+ { key: 1 },
123
+ { unique: true, partialFilterExpression: { status: "active" } }
124
+ );
125
+ return schema;
126
+ }
127
+ var _formSchema = buildFormSchema();
128
+
129
+ // src/models/formModel.ts
130
+ function compileModel(connection, schema = buildFormSchema()) {
131
+ return connection.model("Form", schema);
132
+ }
133
+
134
+ // src/models/sectionModel.ts
135
+ var sectionModel_exports = {};
136
+ __export(sectionModel_exports, {
137
+ buildSchema: () => buildSectionSchema,
138
+ compileModel: () => compileModel2
139
+ });
140
+
141
+ // src/schemas/section.ts
142
+ var import_mongoose2 = require("mongoose");
143
+ var sectionQuestionRefSchema = new import_mongoose2.Schema(
144
+ {
145
+ questionId: { type: String, required: true },
146
+ questionVersion: { type: String, required: true },
147
+ index: { type: Number, required: true }
148
+ },
149
+ { _id: false }
150
+ );
151
+ var guidanceSchema = new import_mongoose2.Schema(
152
+ {
153
+ type: {
154
+ type: String,
155
+ required: true,
156
+ enum: ["tip", "warning", "prompt"]
157
+ },
158
+ text: { type: String, required: true }
159
+ },
160
+ { _id: false }
161
+ );
162
+ var sectionSchemaDefinition = {
163
+ _schemaVersion: {
164
+ type: Number,
165
+ required: true,
166
+ default: 1
167
+ },
168
+ // Audit fields
169
+ createdUser: {
170
+ type: import_mongoose2.Schema.Types.ObjectId,
171
+ required: true,
172
+ index: true
173
+ },
174
+ updatedUser: {
175
+ type: import_mongoose2.Schema.Types.ObjectId,
176
+ index: true
177
+ },
178
+ // Versioning
179
+ key: {
180
+ type: String,
181
+ required: true
182
+ },
183
+ version: {
184
+ type: String,
185
+ required: true
186
+ },
187
+ // Section info
188
+ name: {
189
+ type: String,
190
+ required: true
191
+ },
192
+ directions: {
193
+ type: String
194
+ },
195
+ // Typed guidance items
196
+ guidance: {
197
+ type: [guidanceSchema],
198
+ default: []
199
+ },
200
+ // Ordered question refs
201
+ questions: {
202
+ type: [sectionQuestionRefSchema],
203
+ default: []
204
+ },
205
+ // Template visibility
206
+ templateScope: {
207
+ type: [String],
208
+ default: void 0
209
+ },
210
+ collapsible: {
211
+ type: Boolean,
212
+ default: false
213
+ },
214
+ defaultCollapsed: {
215
+ type: Boolean,
216
+ default: false
217
+ },
218
+ // Lifecycle
219
+ status: {
220
+ type: String,
221
+ required: true,
222
+ enum: ["draft", "active", "deprecated"],
223
+ default: "draft",
224
+ index: true
225
+ },
226
+ supersedes: {
227
+ type: String
228
+ },
229
+ // PAVE-aligned optional fields
230
+ rephrasing: {
231
+ type: String
232
+ },
233
+ script: {
234
+ type: String
235
+ }
236
+ };
237
+ var sectionSchemaOptions = {
238
+ timestamps: {
239
+ createdAt: "createdTime",
240
+ updatedAt: "updatedTime"
241
+ },
242
+ collection: "sections"
243
+ };
244
+ function buildSectionSchema() {
245
+ const schema = new import_mongoose2.Schema(sectionSchemaDefinition, sectionSchemaOptions);
246
+ schema.index({ key: 1, version: 1 }, { unique: true });
247
+ schema.index(
248
+ { key: 1 },
249
+ { unique: true, partialFilterExpression: { status: "active" } }
250
+ );
251
+ return schema;
252
+ }
253
+ var _sectionSchema = buildSectionSchema();
254
+
255
+ // src/models/sectionModel.ts
256
+ function compileModel2(connection, schema = buildSectionSchema()) {
257
+ return connection.model("Section", schema);
258
+ }
259
+
260
+ // src/models/questionModel.ts
261
+ var questionModel_exports = {};
262
+ __export(questionModel_exports, {
263
+ buildSchema: () => buildQuestionSchema,
264
+ compileModel: () => compileModel3
265
+ });
266
+
267
+ // src/schemas/question.ts
268
+ var import_mongoose3 = require("mongoose");
269
+ var choiceSchema = new import_mongoose3.Schema(
270
+ {
271
+ val: { type: import_mongoose3.Schema.Types.Mixed, required: true },
272
+ text: { type: String, required: true },
273
+ tip: { type: String },
274
+ trigger: { type: [String] }
275
+ },
276
+ { _id: false }
277
+ );
278
+ var visibilityRuleSchema = new import_mongoose3.Schema(
279
+ {
280
+ dependsOn: { type: String, required: true },
281
+ condition: {
282
+ type: String,
283
+ required: true,
284
+ enum: ["equals", "not_equals", "any_of", "in_range"]
285
+ },
286
+ values: { type: [import_mongoose3.Schema.Types.Mixed], required: true },
287
+ source: {
288
+ type: String,
289
+ enum: ["form", "session"],
290
+ default: "form"
291
+ }
292
+ },
293
+ { _id: false }
294
+ );
295
+ var layoutSchema = new import_mongoose3.Schema(
296
+ {
297
+ columns: { type: Number, default: 1, min: 1, max: 4 },
298
+ collapsible: { type: Boolean, default: false },
299
+ groupKey: { type: String }
300
+ },
301
+ { _id: false }
302
+ );
303
+ var questionSchemaDefinition = {
304
+ _schemaVersion: {
305
+ type: Number,
306
+ required: true,
307
+ default: 1
308
+ },
309
+ // Audit fields
310
+ createdUser: {
311
+ type: import_mongoose3.Schema.Types.ObjectId,
312
+ required: true,
313
+ index: true
314
+ },
315
+ updatedUser: {
316
+ type: import_mongoose3.Schema.Types.ObjectId,
317
+ index: true
318
+ },
319
+ // Versioning
320
+ key: {
321
+ type: String,
322
+ required: true
323
+ },
324
+ version: {
325
+ type: String,
326
+ required: true
327
+ },
328
+ // Question definition
329
+ index: {
330
+ type: Number,
331
+ required: true
332
+ },
333
+ text: {
334
+ type: String,
335
+ required: true
336
+ },
337
+ format: {
338
+ type: String,
339
+ required: true
340
+ },
341
+ sectionId: {
342
+ type: String,
343
+ required: true
344
+ },
345
+ required: {
346
+ type: Boolean,
347
+ default: false
348
+ },
349
+ allowMultiple: {
350
+ type: Boolean,
351
+ default: false
352
+ },
353
+ // Nesting
354
+ isNested: {
355
+ type: Boolean,
356
+ default: false
357
+ },
358
+ nested: {
359
+ type: [String],
360
+ default: []
361
+ },
362
+ // Trigger logic
363
+ isTriggered: {
364
+ type: Boolean,
365
+ default: false
366
+ },
367
+ triggersWhenAnswered: {
368
+ type: [String],
369
+ default: []
370
+ },
371
+ // Display
372
+ header: { type: String },
373
+ directions: { type: String },
374
+ tip: { type: String },
375
+ // Dynamic choices
376
+ hasDynamicChoices: {
377
+ type: Boolean,
378
+ default: false
379
+ },
380
+ dynamicChoiceSet: { type: String },
381
+ group: { type: String },
382
+ // Static choices
383
+ choices: {
384
+ type: [choiceSchema],
385
+ default: []
386
+ },
387
+ // UI rendering hints
388
+ componentProps: {
389
+ type: import_mongoose3.Schema.Types.Mixed
390
+ },
391
+ // Autofill
392
+ autofillRules: {
393
+ type: import_mongoose3.Schema.Types.Mixed,
394
+ default: []
395
+ },
396
+ // Classification
397
+ formType: {
398
+ type: [String],
399
+ enum: ["screening", "intake", "assessment", "demographics"],
400
+ default: []
401
+ },
402
+ icCode: {
403
+ type: String
404
+ },
405
+ // Lifecycle
406
+ status: {
407
+ type: String,
408
+ required: true,
409
+ enum: ["draft", "active", "deprecated"],
410
+ default: "draft",
411
+ index: true
412
+ },
413
+ supersedes: {
414
+ type: String
415
+ },
416
+ // Entity mapping (dual-write bridge)
417
+ targetEntity: {
418
+ type: String,
419
+ enum: [
420
+ "caseSession",
421
+ "protectedPerson",
422
+ "perpetratorPerson",
423
+ "personnelPerson",
424
+ "caseRecord",
425
+ "serviceInstance"
426
+ ]
427
+ },
428
+ targetField: {
429
+ type: String
430
+ },
431
+ // Conditional visibility
432
+ visibilityRule: {
433
+ type: visibilityRuleSchema
434
+ },
435
+ // Layout hints
436
+ layout: {
437
+ type: layoutSchema
438
+ },
439
+ microcopy: {
440
+ type: String
441
+ },
442
+ sensitivity: {
443
+ type: String,
444
+ enum: ["standard", "sensitive", "highly_sensitive"]
445
+ },
446
+ // Scoring group
447
+ scoringGroup: {
448
+ type: String
449
+ },
450
+ // PAVE-aligned optional fields
451
+ groups: {
452
+ type: [String],
453
+ default: void 0
454
+ },
455
+ rephrasingSelector: {
456
+ type: import_mongoose3.Schema.Types.Mixed
457
+ },
458
+ textSelector: {
459
+ type: import_mongoose3.Schema.Types.Mixed
460
+ },
461
+ tipSelector: {
462
+ type: import_mongoose3.Schema.Types.Mixed
463
+ },
464
+ sortChoices: {
465
+ type: Boolean
466
+ },
467
+ isAllRequired: {
468
+ type: Boolean
469
+ },
470
+ itemLabel: {
471
+ type: String
472
+ },
473
+ prompts: {
474
+ type: [String],
475
+ default: void 0
476
+ },
477
+ rephrasing: {
478
+ type: String
479
+ },
480
+ dynamicChoiceTrigger: {
481
+ type: String
482
+ }
483
+ };
484
+ var questionSchemaOptions = {
485
+ timestamps: {
486
+ createdAt: "createdTime",
487
+ updatedAt: "updatedTime"
488
+ },
489
+ collection: "questions"
490
+ };
491
+ function buildQuestionSchema() {
492
+ const schema = new import_mongoose3.Schema(questionSchemaDefinition, questionSchemaOptions);
493
+ schema.index({ key: 1, version: 1 }, { unique: true });
494
+ schema.index(
495
+ { key: 1 },
496
+ { unique: true, partialFilterExpression: { status: "active" } }
497
+ );
498
+ schema.index({ sectionId: 1, index: 1 });
499
+ schema.index({ icCode: 1 }, { sparse: true });
500
+ return schema;
501
+ }
502
+ var _questionSchema = buildQuestionSchema();
503
+
504
+ // src/models/questionModel.ts
505
+ function compileModel3(connection, schema = buildQuestionSchema()) {
506
+ return connection.model("Question", schema);
507
+ }
508
+
509
+ // src/models/scoringRuleModel.ts
510
+ var scoringRuleModel_exports = {};
511
+ __export(scoringRuleModel_exports, {
512
+ buildSchema: () => buildScoringRuleSchema,
513
+ compileModel: () => compileModel4
514
+ });
515
+
516
+ // src/schemas/scoring-rule.ts
517
+ var import_mongoose4 = require("mongoose");
518
+ var scoringConditionSchema = new import_mongoose4.Schema(
519
+ {
520
+ questionKey: { type: String, required: true },
521
+ operator: {
522
+ type: String,
523
+ required: true,
524
+ enum: ["eq", "ne", "in", "not_in", "gt", "gte", "lt", "lte"]
525
+ },
526
+ value: { type: import_mongoose4.Schema.Types.Mixed, required: true },
527
+ weight: { type: Number, required: true }
528
+ },
529
+ { _id: false }
530
+ );
531
+ var scoringThresholdSchema = new import_mongoose4.Schema(
532
+ {
533
+ minScore: { type: Number, required: true },
534
+ maxScore: { type: Number, required: true },
535
+ riskLevel: { type: String, required: true },
536
+ label: { type: String, required: true }
537
+ },
538
+ { _id: false }
539
+ );
540
+ var scoringRecommendationSchema = new import_mongoose4.Schema(
541
+ {
542
+ riskLevel: { type: String, required: true },
543
+ action: { type: String, required: true },
544
+ description: { type: String, required: true }
545
+ },
546
+ { _id: false }
547
+ );
548
+ var scoringRuleSchemaDefinition = {
549
+ _schemaVersion: {
550
+ type: Number,
551
+ required: true,
552
+ default: 1
553
+ },
554
+ // Audit fields
555
+ createdUser: {
556
+ type: import_mongoose4.Schema.Types.ObjectId,
557
+ required: true,
558
+ index: true
559
+ },
560
+ updatedUser: {
561
+ type: import_mongoose4.Schema.Types.ObjectId,
562
+ index: true
563
+ },
564
+ // Reference to Form (cross-db string, not ObjectId)
565
+ formId: {
566
+ type: String,
567
+ required: true
568
+ },
569
+ formVersion: {
570
+ type: String,
571
+ required: true
572
+ },
573
+ // Rule info
574
+ name: {
575
+ type: String,
576
+ required: true
577
+ },
578
+ version: {
579
+ type: String,
580
+ required: true
581
+ },
582
+ appScope: {
583
+ type: [String],
584
+ enum: ["thread", "pave", "both"],
585
+ default: []
586
+ },
587
+ // Lifecycle
588
+ status: {
589
+ type: String,
590
+ required: true,
591
+ enum: ["draft", "active", "deprecated"],
592
+ default: "draft",
593
+ index: true
594
+ },
595
+ effectiveDate: {
596
+ type: Date
597
+ },
598
+ deprecatedDate: {
599
+ type: Date
600
+ },
601
+ replacedBy: {
602
+ type: String
603
+ },
604
+ // Scoring logic
605
+ conditions: {
606
+ type: [scoringConditionSchema],
607
+ default: []
608
+ },
609
+ thresholds: {
610
+ type: [scoringThresholdSchema],
611
+ default: []
612
+ },
613
+ recommendations: {
614
+ type: [scoringRecommendationSchema],
615
+ default: []
616
+ }
617
+ };
618
+ var scoringRuleSchemaOptions = {
619
+ timestamps: {
620
+ createdAt: "createdTime",
621
+ updatedAt: "updatedTime"
622
+ },
623
+ collection: "scoringrules"
624
+ };
625
+ function buildScoringRuleSchema() {
626
+ const schema = new import_mongoose4.Schema(
627
+ scoringRuleSchemaDefinition,
628
+ scoringRuleSchemaOptions
629
+ );
630
+ schema.index(
631
+ { formId: 1, formVersion: 1, version: 1, name: 1 },
632
+ { unique: true }
633
+ );
634
+ schema.index({ formId: 1, formVersion: 1, status: 1 });
635
+ return schema;
636
+ }
637
+ var _scoringRuleSchema = buildScoringRuleSchema();
638
+
639
+ // src/models/scoringRuleModel.ts
640
+ function compileModel4(connection, schema = buildScoringRuleSchema()) {
641
+ return connection.model("ScoringRule", schema);
642
+ }
643
+
644
+ // src/models/index.ts
645
+ function createPlatformModels(connection) {
646
+ return {
647
+ FormModel: compileModel(connection),
648
+ SectionModel: compileModel2(connection),
649
+ QuestionModel: compileModel3(connection),
650
+ ScoringRuleModel: compileModel4(connection)
651
+ };
652
+ }
653
+ // Annotate the CommonJS export names for ESM import in node:
654
+ 0 && (module.exports = {
655
+ createPlatformModels,
656
+ formModel,
657
+ questionModel,
658
+ scoringRuleModel,
659
+ sectionModel
660
+ });
661
+ //# sourceMappingURL=index.cjs.map