@resconet/qp-bridge 0.0.1-alpha.11 → 0.0.1-alpha.13
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 +52 -6
- package/index.js +1 -1
- package/index.mjs +350 -318
- package/lib/qp-bridge-types.d.ts +58 -0
- package/lib/qp-bridge.d.ts +35 -11
- package/package.json +1 -1
package/lib/qp-bridge-types.d.ts
CHANGED
|
@@ -310,6 +310,46 @@ export declare const getGroupSuccessResponseMessageSchema: z.ZodObject<z.objectU
|
|
|
310
310
|
};
|
|
311
311
|
id?: string | undefined;
|
|
312
312
|
}>;
|
|
313
|
+
export declare const setGroupRequestMessageSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
314
|
+
type: z.ZodLiteral<"qp-bridge">;
|
|
315
|
+
id: z.ZodOptional<z.ZodString>;
|
|
316
|
+
}, {
|
|
317
|
+
action: z.ZodLiteral<"setGroup">;
|
|
318
|
+
group: z.ZodString;
|
|
319
|
+
groupData: z.ZodObject<{
|
|
320
|
+
label: z.ZodOptional<z.ZodString>;
|
|
321
|
+
hidden: z.ZodOptional<z.ZodBoolean>;
|
|
322
|
+
collapsed: z.ZodOptional<z.ZodBoolean>;
|
|
323
|
+
}, "strip", z.ZodTypeAny, {
|
|
324
|
+
label?: string | undefined;
|
|
325
|
+
hidden?: boolean | undefined;
|
|
326
|
+
collapsed?: boolean | undefined;
|
|
327
|
+
}, {
|
|
328
|
+
label?: string | undefined;
|
|
329
|
+
hidden?: boolean | undefined;
|
|
330
|
+
collapsed?: boolean | undefined;
|
|
331
|
+
}>;
|
|
332
|
+
}>, "strip", z.ZodTypeAny, {
|
|
333
|
+
type: "qp-bridge";
|
|
334
|
+
action: "setGroup";
|
|
335
|
+
group: string;
|
|
336
|
+
groupData: {
|
|
337
|
+
label?: string | undefined;
|
|
338
|
+
hidden?: boolean | undefined;
|
|
339
|
+
collapsed?: boolean | undefined;
|
|
340
|
+
};
|
|
341
|
+
id?: string | undefined;
|
|
342
|
+
}, {
|
|
343
|
+
type: "qp-bridge";
|
|
344
|
+
action: "setGroup";
|
|
345
|
+
group: string;
|
|
346
|
+
groupData: {
|
|
347
|
+
label?: string | undefined;
|
|
348
|
+
hidden?: boolean | undefined;
|
|
349
|
+
collapsed?: boolean | undefined;
|
|
350
|
+
};
|
|
351
|
+
id?: string | undefined;
|
|
352
|
+
}>;
|
|
313
353
|
export declare const setAnswerRequestMessageSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
314
354
|
type: z.ZodLiteral<"qp-bridge">;
|
|
315
355
|
id: z.ZodOptional<z.ZodString>;
|
|
@@ -358,6 +398,20 @@ export declare const busyIndicatorEndRequestMessageSchema: z.ZodObject<z.objectU
|
|
|
358
398
|
action: "busyIndicatorEnd";
|
|
359
399
|
id?: string | undefined;
|
|
360
400
|
}>;
|
|
401
|
+
export declare const saveQuestionnaireRequestMessageSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
402
|
+
type: z.ZodLiteral<"qp-bridge">;
|
|
403
|
+
id: z.ZodOptional<z.ZodString>;
|
|
404
|
+
}, {
|
|
405
|
+
action: z.ZodLiteral<"saveQuestionnaire">;
|
|
406
|
+
}>, "strip", z.ZodTypeAny, {
|
|
407
|
+
type: "qp-bridge";
|
|
408
|
+
action: "saveQuestionnaire";
|
|
409
|
+
id?: string | undefined;
|
|
410
|
+
}, {
|
|
411
|
+
type: "qp-bridge";
|
|
412
|
+
action: "saveQuestionnaire";
|
|
413
|
+
id?: string | undefined;
|
|
414
|
+
}>;
|
|
361
415
|
export type QpBridgeMessage = z.infer<typeof qpBridgeMessageSchema>;
|
|
362
416
|
export type ResponseSuccessMessage = z.infer<typeof responseSuccessMessageSchema>;
|
|
363
417
|
export type ResponseErrorMessage = z.infer<typeof responseErrorMessageSchema>;
|
|
@@ -372,8 +426,10 @@ export type SetAnswerRequestMessage = z.infer<typeof setAnswerRequestMessageSche
|
|
|
372
426
|
export type GetQuestionRequestMessage = z.infer<typeof getQuestionRequestMessageSchema>;
|
|
373
427
|
export type GetGroupRequestMessage = z.infer<typeof getGroupRequestMessageSchema>;
|
|
374
428
|
export type SetQuestionRequestMessage = z.infer<typeof setQuestionRequestMessageSchema>;
|
|
429
|
+
export type SetGroupRequestMessage = z.infer<typeof setGroupRequestMessageSchema>;
|
|
375
430
|
export type BusyIndicatorStartRequestMessage = z.infer<typeof busyIndicatorStartRequestMessageSchema>;
|
|
376
431
|
export type BusyIndicatorEndRequestMessage = z.infer<typeof busyIndicatorEndRequestMessageSchema>;
|
|
432
|
+
export type SaveQuestionnaireRequestMessage = z.infer<typeof saveQuestionnaireRequestMessageSchema>;
|
|
377
433
|
export type WithBusyIndicatorRequestMessage = BusyIndicatorStartRequestMessage | BusyIndicatorEndRequestMessage;
|
|
378
434
|
export declare function isOnAnswerChangeMessage(data: unknown): data is OnAnswerChangeMessage;
|
|
379
435
|
export declare function isQpBridgeMessage(data: unknown): data is QpBridgeMessage;
|
|
@@ -383,8 +439,10 @@ export declare function isGetQuestionRequestMessage(data: unknown): data is GetQ
|
|
|
383
439
|
export declare function isGetQuestionSuccessResponseMessage(data: unknown): data is GetQuestionSuccessResponseMessage;
|
|
384
440
|
export declare function isSetAnswerRequestMessage(data: unknown): data is SetAnswerRequestMessage;
|
|
385
441
|
export declare function isSetQuestionRequestMessage(data: unknown): data is SetQuestionRequestMessage;
|
|
442
|
+
export declare function isSetGroupRequestMessage(data: unknown): data is SetGroupRequestMessage;
|
|
386
443
|
export declare function isGetGroupRequestMessage(data: unknown): data is GetGroupRequestMessage;
|
|
387
444
|
export declare function isGetGroupSuccessResponseMessage(data: unknown): data is GetGroupSuccessResponseMessage;
|
|
388
445
|
export declare function isBusyIndicatorStartRequestMessage(data: unknown): data is BusyIndicatorStartRequestMessage;
|
|
389
446
|
export declare function isBusyIndicatorEndRequestMessage(data: unknown): data is BusyIndicatorEndRequestMessage;
|
|
447
|
+
export declare function isSaveQuestionnaireRequestMessage(data: unknown): data is SaveQuestionnaireRequestMessage;
|
|
390
448
|
export declare function isWithBusyIndicatorRequestMessage(data: unknown): data is WithBusyIndicatorRequestMessage;
|
package/lib/qp-bridge.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Group, Question, QuestionOptional } from './qp-bridge-types';
|
|
1
|
+
import { Group, GroupOptional, Question, QuestionOptional } from './qp-bridge-types';
|
|
2
2
|
/**
|
|
3
3
|
* Sets the answer for a specific question in the questionnaire.
|
|
4
4
|
*
|
|
5
5
|
* @param {string} questionName - Name of the question for which the answer is being set.
|
|
6
6
|
* @param {*} answer - The answer to set for the question. Can be any type.
|
|
7
7
|
* @returns {Promise<void>} A promise that resolves when the answer has been successfully set.
|
|
8
|
-
* @throws {Error} Throws if the
|
|
8
|
+
* @throws {Error} Throws if the operation fails.
|
|
9
9
|
* @example
|
|
10
10
|
* ```typescript
|
|
11
11
|
* await setAnswer('favoriteColor', 'blue');
|
|
@@ -18,7 +18,7 @@ export declare function setAnswer(questionName: string, answer: unknown): Promis
|
|
|
18
18
|
*
|
|
19
19
|
* @param {string} name - The name of the question to retrieve.
|
|
20
20
|
* @returns {Promise<Question>} A promise that resolves to the question object.
|
|
21
|
-
* @throws {Error} Throws if the
|
|
21
|
+
* @throws {Error} Throws if the question is not found or the operation fails.
|
|
22
22
|
* @example
|
|
23
23
|
* ```typescript
|
|
24
24
|
* const question = await getQuestion('favoriteColor');
|
|
@@ -32,7 +32,7 @@ export declare function getQuestion(name: string): Promise<Question>;
|
|
|
32
32
|
* @param {string} name - The name of the question to update. This is a unique identifier and cannot be changed.
|
|
33
33
|
* @param {QuestionOptional} questionData - The updated question data excluding the name property.
|
|
34
34
|
* @returns {Promise<void>} A promise that resolves when the question has been successfully updated.
|
|
35
|
-
* @throws {Error} Throws if the
|
|
35
|
+
* @throws {Error} Throws if the question is not found or the operation fails.
|
|
36
36
|
* @example
|
|
37
37
|
* ```typescript
|
|
38
38
|
* await setQuestion('favoriteColor', { label: 'What is your favorite color?' });
|
|
@@ -44,7 +44,7 @@ export declare function setQuestion(name: string, questionData: QuestionOptional
|
|
|
44
44
|
*
|
|
45
45
|
* @param {string} name - The name of the group to retrieve.
|
|
46
46
|
* @returns {Promise<Group>} A promise that resolves to the group object.
|
|
47
|
-
* @throws {Error} Throws if the
|
|
47
|
+
* @throws {Error} Throws if the group is not found or the operation fails.
|
|
48
48
|
* @example
|
|
49
49
|
* ```typescript
|
|
50
50
|
* const group = await getGroup('personalInfo');
|
|
@@ -54,16 +54,28 @@ export declare function setQuestion(name: string, questionData: QuestionOptional
|
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
56
|
export declare function getGroup(name: string): Promise<Group>;
|
|
57
|
+
/**
|
|
58
|
+
* Updates a group in the questionnaire.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} name - The name of the group to update. This is a unique identifier and cannot be changed.
|
|
61
|
+
* @param {GroupOptional} groupData - The updated group data excluding the name property.
|
|
62
|
+
* @returns {Promise<void>} A promise that resolves when the group has been successfully updated.
|
|
63
|
+
* @throws {Error} Throws if the group is not found or the operation fails.
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* await setGroup('personalInfo', { label: 'Personal Information', hidden: false, collapsed: true });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function setGroup(name: string, groupData: GroupOptional): Promise<void>;
|
|
57
70
|
/**
|
|
58
71
|
* Subscribes to changes in answers for questions.
|
|
59
|
-
*
|
|
60
|
-
* and invokes the provided listener whenever an answer changes.
|
|
72
|
+
* Calls the provided listener whenever an answer changes in the questionnaire.
|
|
61
73
|
* @param listener - A function that will be called with the question name and the new answer whenever an answer changes.
|
|
62
74
|
* @return An object with a `cancelSubscription` method to stop listening for changes.
|
|
63
75
|
* @example
|
|
64
76
|
* ```typescript
|
|
65
77
|
* import { onAnswerChange } from 'qp-bridge';
|
|
66
|
-
* const {
|
|
78
|
+
* const { cancelSubscription } = onAnswerChange((question, answer) => {
|
|
67
79
|
* console.log(`Answer for ${question} changed to:`, answer);
|
|
68
80
|
* });
|
|
69
81
|
*
|
|
@@ -76,9 +88,8 @@ export declare function onAnswerChange(listener: (question: string, answer: unkn
|
|
|
76
88
|
};
|
|
77
89
|
/**
|
|
78
90
|
* Wraps an asynchronous action with a busy indicator in the host application.
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* action rejects (finally semantics), ensuring the UI is not left in a busy state.
|
|
91
|
+
* Shows a loading indicator during the execution of the provided action,
|
|
92
|
+
* ensuring the UI reflects the busy state appropriately.
|
|
82
93
|
*
|
|
83
94
|
* @typeParam T - The resolved type of the provided async action.
|
|
84
95
|
* @param action - A function returning a promise whose execution should be wrapped.
|
|
@@ -94,3 +105,16 @@ export declare function onAnswerChange(listener: (question: string, answer: unkn
|
|
|
94
105
|
* ```
|
|
95
106
|
*/
|
|
96
107
|
export declare function withBusyIndicator<T>(action: () => Promise<T>): Promise<T>;
|
|
108
|
+
/**
|
|
109
|
+
* Saves the current questionnaire state.
|
|
110
|
+
* Triggers a save operation for the questionnaire data.
|
|
111
|
+
*
|
|
112
|
+
* @returns {Promise<void>} A promise that resolves when the questionnaire has been successfully saved.
|
|
113
|
+
* @throws {Error} Throws if the save operation fails.
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* await saveQuestionnaire();
|
|
117
|
+
* console.log('Questionnaire saved successfully');
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare function saveQuestionnaire(): Promise<void>;
|