@msbci/form-server 1.2.0 → 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.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { PrismaClient } from '../generated/prisma';
2
- import { z } from 'zod';
2
+ import { IFormDefinition } from '@msbci/form-core';
3
3
  export { IFormDefinition, IFormPage, IFormRoster, IFormVariable } from '@msbci/form-core';
4
+ import { z } from 'zod';
4
5
 
5
6
  /**
6
7
  * Auth middleware — injectable hook for the host application.
@@ -132,6 +133,7 @@ declare class FormService {
132
133
  pageSize: number;
133
134
  search?: string;
134
135
  tenantId?: string;
136
+ scopeId?: string;
135
137
  }): Promise<{
136
138
  items: ({
137
139
  formType: {
@@ -174,6 +176,11 @@ declare class FormService {
174
176
  createdAt: Date;
175
177
  updatedAt: Date;
176
178
  } | null;
179
+ scopes: {
180
+ order: number;
181
+ scopeId: string;
182
+ formId: string;
183
+ }[];
177
184
  pages: ({
178
185
  variables: {
179
186
  id: string;
@@ -187,7 +194,9 @@ declare class FormService {
187
194
  conditions: string | null;
188
195
  options: string | null;
189
196
  pageId: string | null;
197
+ templateOverrides: string | null;
190
198
  type: string;
199
+ rosterId: string | null;
191
200
  isRequired: boolean;
192
201
  isReadonly: boolean;
193
202
  isHidden: boolean;
@@ -198,7 +207,7 @@ declare class FormService {
198
207
  dataSourceId: string | null;
199
208
  dataSourceDependencies: string | null;
200
209
  style: string | null;
201
- rosterId: string | null;
210
+ templateId: string | null;
202
211
  }[];
203
212
  rosters: ({
204
213
  variables: {
@@ -213,7 +222,9 @@ declare class FormService {
213
222
  conditions: string | null;
214
223
  options: string | null;
215
224
  pageId: string | null;
225
+ templateOverrides: string | null;
216
226
  type: string;
227
+ rosterId: string | null;
217
228
  isRequired: boolean;
218
229
  isReadonly: boolean;
219
230
  isHidden: boolean;
@@ -224,7 +235,7 @@ declare class FormService {
224
235
  dataSourceId: string | null;
225
236
  dataSourceDependencies: string | null;
226
237
  style: string | null;
227
- rosterId: string | null;
238
+ templateId: string | null;
228
239
  }[];
229
240
  } & {
230
241
  id: string;
@@ -248,13 +259,13 @@ declare class FormService {
248
259
  createdAt: Date;
249
260
  updatedAt: Date;
250
261
  order: number;
262
+ formId: string;
251
263
  isRepeatable: boolean;
252
264
  repeatMinInstances: number | null;
253
265
  repeatMaxInstances: number | null;
254
266
  repeatControlVarCode: string | null;
255
267
  repeatInstanceLabel: string | null;
256
268
  conditions: string | null;
257
- formId: string;
258
269
  })[];
259
270
  } & {
260
271
  id: string;
@@ -279,6 +290,7 @@ declare class FormService {
279
290
  isPublished?: boolean;
280
291
  tenantId?: string;
281
292
  formTypeId?: string;
293
+ scopeIds?: string[];
282
294
  metadata?: Record<string, unknown>;
283
295
  }, ctx?: IRequestContext): Promise<{
284
296
  id: string;
@@ -302,8 +314,15 @@ declare class FormService {
302
314
  version: string;
303
315
  isPublished: boolean;
304
316
  formTypeId: string;
317
+ scopeIds: string[];
305
318
  metadata: Record<string, unknown>;
306
- }>, ctx?: IRequestContext): Promise<{
319
+ }>, ctx?: IRequestContext): Promise<({
320
+ scopes: {
321
+ order: number;
322
+ scopeId: string;
323
+ formId: string;
324
+ }[];
325
+ } & {
307
326
  id: string;
308
327
  code: string;
309
328
  name: string;
@@ -317,7 +336,14 @@ declare class FormService {
317
336
  formTypeId: string | null;
318
337
  createdBy: string | null;
319
338
  updatedBy: string | null;
320
- }>;
339
+ }) | null>;
340
+ /**
341
+ * Load a form by id and return it as a fully-resolved `IFormDefinition`
342
+ * (templates applied — Option B). Used by `GET /forms/:id/resolved` and
343
+ * `exportForm`. The original DB-include shape is still available via
344
+ * {@link getFormDefinition}.
345
+ */
346
+ getResolvedFormDefinition(id: string): Promise<IFormDefinition>;
321
347
  deleteFormDefinition(id: string): Promise<{
322
348
  id: string;
323
349
  code: string;
@@ -352,13 +378,13 @@ declare class FormService {
352
378
  createdAt: Date;
353
379
  updatedAt: Date;
354
380
  order: number;
381
+ formId: string;
355
382
  isRepeatable: boolean;
356
383
  repeatMinInstances: number | null;
357
384
  repeatMaxInstances: number | null;
358
385
  repeatControlVarCode: string | null;
359
386
  repeatInstanceLabel: string | null;
360
387
  conditions: string | null;
361
- formId: string;
362
388
  }>;
363
389
  updateFormPage(id: string, data: Partial<{
364
390
  code: string;
@@ -379,13 +405,13 @@ declare class FormService {
379
405
  createdAt: Date;
380
406
  updatedAt: Date;
381
407
  order: number;
408
+ formId: string;
382
409
  isRepeatable: boolean;
383
410
  repeatMinInstances: number | null;
384
411
  repeatMaxInstances: number | null;
385
412
  repeatControlVarCode: string | null;
386
413
  repeatInstanceLabel: string | null;
387
414
  conditions: string | null;
388
- formId: string;
389
415
  }>;
390
416
  deleteFormPage(id: string): Promise<{
391
417
  id: string;
@@ -395,13 +421,13 @@ declare class FormService {
395
421
  createdAt: Date;
396
422
  updatedAt: Date;
397
423
  order: number;
424
+ formId: string;
398
425
  isRepeatable: boolean;
399
426
  repeatMinInstances: number | null;
400
427
  repeatMaxInstances: number | null;
401
428
  repeatControlVarCode: string | null;
402
429
  repeatInstanceLabel: string | null;
403
430
  conditions: string | null;
404
- formId: string;
405
431
  }>;
406
432
  createFormRoster(pageId: string, data: {
407
433
  code: string;
@@ -484,6 +510,8 @@ declare class FormService {
484
510
  dataSourceDependencies?: Record<string, string>;
485
511
  style?: unknown;
486
512
  metadata?: Record<string, unknown>;
513
+ templateId?: string;
514
+ templateOverrides?: Record<string, unknown>;
487
515
  }): Promise<{
488
516
  id: string;
489
517
  code: string;
@@ -496,7 +524,9 @@ declare class FormService {
496
524
  conditions: string | null;
497
525
  options: string | null;
498
526
  pageId: string | null;
527
+ templateOverrides: string | null;
499
528
  type: string;
529
+ rosterId: string | null;
500
530
  isRequired: boolean;
501
531
  isReadonly: boolean;
502
532
  isHidden: boolean;
@@ -507,7 +537,7 @@ declare class FormService {
507
537
  dataSourceId: string | null;
508
538
  dataSourceDependencies: string | null;
509
539
  style: string | null;
510
- rosterId: string | null;
540
+ templateId: string | null;
511
541
  }>;
512
542
  updateFormVariable(id: string, data: Partial<{
513
543
  code: string;
@@ -528,6 +558,8 @@ declare class FormService {
528
558
  dataSourceDependencies: Record<string, string>;
529
559
  style: unknown;
530
560
  metadata: Record<string, unknown>;
561
+ templateId: string | null;
562
+ templateOverrides: Record<string, unknown> | null;
531
563
  }>): Promise<{
532
564
  id: string;
533
565
  code: string;
@@ -540,7 +572,9 @@ declare class FormService {
540
572
  conditions: string | null;
541
573
  options: string | null;
542
574
  pageId: string | null;
575
+ templateOverrides: string | null;
543
576
  type: string;
577
+ rosterId: string | null;
544
578
  isRequired: boolean;
545
579
  isReadonly: boolean;
546
580
  isHidden: boolean;
@@ -551,7 +585,7 @@ declare class FormService {
551
585
  dataSourceId: string | null;
552
586
  dataSourceDependencies: string | null;
553
587
  style: string | null;
554
- rosterId: string | null;
588
+ templateId: string | null;
555
589
  }>;
556
590
  deleteFormVariable(id: string): Promise<{
557
591
  id: string;
@@ -565,7 +599,9 @@ declare class FormService {
565
599
  conditions: string | null;
566
600
  options: string | null;
567
601
  pageId: string | null;
602
+ templateOverrides: string | null;
568
603
  type: string;
604
+ rosterId: string | null;
569
605
  isRequired: boolean;
570
606
  isReadonly: boolean;
571
607
  isHidden: boolean;
@@ -576,7 +612,7 @@ declare class FormService {
576
612
  dataSourceId: string | null;
577
613
  dataSourceDependencies: string | null;
578
614
  style: string | null;
579
- rosterId: string | null;
615
+ templateId: string | null;
580
616
  }>;
581
617
  getSubmissions(params: {
582
618
  formId: string;
@@ -654,9 +690,23 @@ declare class FormService {
654
690
  importForm(json: string, tenantId?: string): Promise<string>;
655
691
  /** Extract variable data for createFormVariable (omit `id` to let Prisma generate it) */
656
692
  private extractVariableData;
657
- /** Convert Prisma DB result to IFormDefinition */
693
+ /**
694
+ * Convert a Prisma DB result to a fully-resolved `IFormDefinition`.
695
+ *
696
+ * Templates referenced by `IFormVariable.templateId` are loaded in a
697
+ * single batch and applied via `resolveFormTemplates` (Option B —
698
+ * in-memory only, no mutation in DB). Pass `resolveTemplates = false`
699
+ * to obtain the raw shape (useful for editor tooling that wants to
700
+ * preserve `templateOverrides`).
701
+ */
658
702
  private dbToFormDefinition;
659
703
  private dbToVariable;
704
+ /**
705
+ * Convert a Prisma VariableTemplate row to the domain type. Duplicated
706
+ * locally (kept in sync with `ScopeService.dbToTemplate`) to avoid an
707
+ * import cycle between the two services.
708
+ */
709
+ private dbToTemplate;
660
710
  }
661
711
 
662
712
  /**
@@ -730,6 +780,7 @@ declare const createFormDefinitionSchema: z.ZodObject<{
730
780
  isPublished: z.ZodDefault<z.ZodBoolean>;
731
781
  tenantId: z.ZodOptional<z.ZodString>;
732
782
  formTypeId: z.ZodOptional<z.ZodString>;
783
+ scopeIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
733
784
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
734
785
  }, "strip", z.ZodTypeAny, {
735
786
  code: string;
@@ -740,6 +791,7 @@ declare const createFormDefinitionSchema: z.ZodObject<{
740
791
  metadata?: Record<string, unknown> | undefined;
741
792
  tenantId?: string | undefined;
742
793
  formTypeId?: string | undefined;
794
+ scopeIds?: string[] | undefined;
743
795
  }, {
744
796
  code: string;
745
797
  name: string;
@@ -749,6 +801,7 @@ declare const createFormDefinitionSchema: z.ZodObject<{
749
801
  version?: string | undefined;
750
802
  isPublished?: boolean | undefined;
751
803
  formTypeId?: string | undefined;
804
+ scopeIds?: string[] | undefined;
752
805
  }>;
753
806
  declare const updateFormDefinitionSchema: z.ZodObject<{
754
807
  code: z.ZodOptional<z.ZodString>;
@@ -758,6 +811,7 @@ declare const updateFormDefinitionSchema: z.ZodObject<{
758
811
  isPublished: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
759
812
  tenantId: z.ZodOptional<z.ZodOptional<z.ZodString>>;
760
813
  formTypeId: z.ZodOptional<z.ZodOptional<z.ZodString>>;
814
+ scopeIds: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
761
815
  metadata: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
762
816
  }, "strip", z.ZodTypeAny, {
763
817
  code?: string | undefined;
@@ -768,6 +822,7 @@ declare const updateFormDefinitionSchema: z.ZodObject<{
768
822
  version?: string | undefined;
769
823
  isPublished?: boolean | undefined;
770
824
  formTypeId?: string | undefined;
825
+ scopeIds?: string[] | undefined;
771
826
  }, {
772
827
  code?: string | undefined;
773
828
  name?: string | undefined;
@@ -777,6 +832,7 @@ declare const updateFormDefinitionSchema: z.ZodObject<{
777
832
  version?: string | undefined;
778
833
  isPublished?: boolean | undefined;
779
834
  formTypeId?: string | undefined;
835
+ scopeIds?: string[] | undefined;
780
836
  }>;
781
837
  declare const createFormPageSchema: z.ZodObject<{
782
838
  code: z.ZodString;
@@ -985,6 +1041,8 @@ declare const createFormVariableSchema: z.ZodObject<{
985
1041
  dataSourceDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
986
1042
  style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
987
1043
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1044
+ templateId: z.ZodOptional<z.ZodString>;
1045
+ templateOverrides: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
988
1046
  }, "strip", z.ZodTypeAny, {
989
1047
  code: string;
990
1048
  name: string;
@@ -1001,6 +1059,7 @@ declare const createFormVariableSchema: z.ZodObject<{
1001
1059
  metadata?: Record<string, unknown> | undefined;
1002
1060
  value?: unknown;
1003
1061
  }[] | undefined;
1062
+ templateOverrides?: Record<string, unknown> | undefined;
1004
1063
  defaultValue?: unknown;
1005
1064
  placeholder?: string | undefined;
1006
1065
  validationRules?: {
@@ -1012,6 +1071,7 @@ declare const createFormVariableSchema: z.ZodObject<{
1012
1071
  dataSourceId?: string | undefined;
1013
1072
  dataSourceDependencies?: Record<string, string> | undefined;
1014
1073
  style?: Record<string, unknown> | undefined;
1074
+ templateId?: string | undefined;
1015
1075
  }, {
1016
1076
  code: string;
1017
1077
  name: string;
@@ -1025,6 +1085,7 @@ declare const createFormVariableSchema: z.ZodObject<{
1025
1085
  metadata?: Record<string, unknown> | undefined;
1026
1086
  value?: unknown;
1027
1087
  }[] | undefined;
1088
+ templateOverrides?: Record<string, unknown> | undefined;
1028
1089
  isRequired?: boolean | undefined;
1029
1090
  isReadonly?: boolean | undefined;
1030
1091
  isHidden?: boolean | undefined;
@@ -1039,6 +1100,7 @@ declare const createFormVariableSchema: z.ZodObject<{
1039
1100
  dataSourceId?: string | undefined;
1040
1101
  dataSourceDependencies?: Record<string, string> | undefined;
1041
1102
  style?: Record<string, unknown> | undefined;
1103
+ templateId?: string | undefined;
1042
1104
  }>;
1043
1105
  declare const updateFormVariableSchema: z.ZodObject<{
1044
1106
  code: z.ZodOptional<z.ZodString>;
@@ -1083,6 +1145,8 @@ declare const updateFormVariableSchema: z.ZodObject<{
1083
1145
  dataSourceDependencies: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
1084
1146
  style: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
1085
1147
  metadata: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
1148
+ templateId: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1149
+ templateOverrides: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
1086
1150
  }, "strip", z.ZodTypeAny, {
1087
1151
  code?: string | undefined;
1088
1152
  name?: string | undefined;
@@ -1095,6 +1159,7 @@ declare const updateFormVariableSchema: z.ZodObject<{
1095
1159
  metadata?: Record<string, unknown> | undefined;
1096
1160
  value?: unknown;
1097
1161
  }[] | undefined;
1162
+ templateOverrides?: Record<string, unknown> | undefined;
1098
1163
  type?: string | undefined;
1099
1164
  isRequired?: boolean | undefined;
1100
1165
  isReadonly?: boolean | undefined;
@@ -1110,6 +1175,7 @@ declare const updateFormVariableSchema: z.ZodObject<{
1110
1175
  dataSourceId?: string | undefined;
1111
1176
  dataSourceDependencies?: Record<string, string> | undefined;
1112
1177
  style?: Record<string, unknown> | undefined;
1178
+ templateId?: string | undefined;
1113
1179
  }, {
1114
1180
  code?: string | undefined;
1115
1181
  name?: string | undefined;
@@ -1122,6 +1188,7 @@ declare const updateFormVariableSchema: z.ZodObject<{
1122
1188
  metadata?: Record<string, unknown> | undefined;
1123
1189
  value?: unknown;
1124
1190
  }[] | undefined;
1191
+ templateOverrides?: Record<string, unknown> | undefined;
1125
1192
  type?: string | undefined;
1126
1193
  isRequired?: boolean | undefined;
1127
1194
  isReadonly?: boolean | undefined;
@@ -1137,6 +1204,7 @@ declare const updateFormVariableSchema: z.ZodObject<{
1137
1204
  dataSourceId?: string | undefined;
1138
1205
  dataSourceDependencies?: Record<string, string> | undefined;
1139
1206
  style?: Record<string, unknown> | undefined;
1207
+ templateId?: string | undefined;
1140
1208
  }>;
1141
1209
  declare const createSubmissionSchema: z.ZodObject<{
1142
1210
  formId: z.ZodString;