@resconet/qp-bridge 0.0.1-alpha.12 → 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 +26 -6
- package/index.js +1 -1
- package/index.mjs +265 -251
- package/lib/qp-bridge-types.d.ts +16 -0
- package/lib/qp-bridge.d.ts +22 -11
- package/package.json +1 -1
package/lib/qp-bridge-types.d.ts
CHANGED
|
@@ -398,6 +398,20 @@ export declare const busyIndicatorEndRequestMessageSchema: z.ZodObject<z.objectU
|
|
|
398
398
|
action: "busyIndicatorEnd";
|
|
399
399
|
id?: string | undefined;
|
|
400
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
|
+
}>;
|
|
401
415
|
export type QpBridgeMessage = z.infer<typeof qpBridgeMessageSchema>;
|
|
402
416
|
export type ResponseSuccessMessage = z.infer<typeof responseSuccessMessageSchema>;
|
|
403
417
|
export type ResponseErrorMessage = z.infer<typeof responseErrorMessageSchema>;
|
|
@@ -415,6 +429,7 @@ export type SetQuestionRequestMessage = z.infer<typeof setQuestionRequestMessage
|
|
|
415
429
|
export type SetGroupRequestMessage = z.infer<typeof setGroupRequestMessageSchema>;
|
|
416
430
|
export type BusyIndicatorStartRequestMessage = z.infer<typeof busyIndicatorStartRequestMessageSchema>;
|
|
417
431
|
export type BusyIndicatorEndRequestMessage = z.infer<typeof busyIndicatorEndRequestMessageSchema>;
|
|
432
|
+
export type SaveQuestionnaireRequestMessage = z.infer<typeof saveQuestionnaireRequestMessageSchema>;
|
|
418
433
|
export type WithBusyIndicatorRequestMessage = BusyIndicatorStartRequestMessage | BusyIndicatorEndRequestMessage;
|
|
419
434
|
export declare function isOnAnswerChangeMessage(data: unknown): data is OnAnswerChangeMessage;
|
|
420
435
|
export declare function isQpBridgeMessage(data: unknown): data is QpBridgeMessage;
|
|
@@ -429,4 +444,5 @@ export declare function isGetGroupRequestMessage(data: unknown): data is GetGrou
|
|
|
429
444
|
export declare function isGetGroupSuccessResponseMessage(data: unknown): data is GetGroupSuccessResponseMessage;
|
|
430
445
|
export declare function isBusyIndicatorStartRequestMessage(data: unknown): data is BusyIndicatorStartRequestMessage;
|
|
431
446
|
export declare function isBusyIndicatorEndRequestMessage(data: unknown): data is BusyIndicatorEndRequestMessage;
|
|
447
|
+
export declare function isSaveQuestionnaireRequestMessage(data: unknown): data is SaveQuestionnaireRequestMessage;
|
|
432
448
|
export declare function isWithBusyIndicatorRequestMessage(data: unknown): data is WithBusyIndicatorRequestMessage;
|
package/lib/qp-bridge.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Group, GroupOptional, Question, QuestionOptional } from './qp-bridge-ty
|
|
|
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');
|
|
@@ -60,7 +60,7 @@ export declare function getGroup(name: string): Promise<Group>;
|
|
|
60
60
|
* @param {string} name - The name of the group to update. This is a unique identifier and cannot be changed.
|
|
61
61
|
* @param {GroupOptional} groupData - The updated group data excluding the name property.
|
|
62
62
|
* @returns {Promise<void>} A promise that resolves when the group has been successfully updated.
|
|
63
|
-
* @throws {Error} Throws if the
|
|
63
|
+
* @throws {Error} Throws if the group is not found or the operation fails.
|
|
64
64
|
* @example
|
|
65
65
|
* ```typescript
|
|
66
66
|
* await setGroup('personalInfo', { label: 'Personal Information', hidden: false, collapsed: true });
|
|
@@ -69,14 +69,13 @@ export declare function getGroup(name: string): Promise<Group>;
|
|
|
69
69
|
export declare function setGroup(name: string, groupData: GroupOptional): Promise<void>;
|
|
70
70
|
/**
|
|
71
71
|
* Subscribes to changes in answers for questions.
|
|
72
|
-
*
|
|
73
|
-
* and invokes the provided listener whenever an answer changes.
|
|
72
|
+
* Calls the provided listener whenever an answer changes in the questionnaire.
|
|
74
73
|
* @param listener - A function that will be called with the question name and the new answer whenever an answer changes.
|
|
75
74
|
* @return An object with a `cancelSubscription` method to stop listening for changes.
|
|
76
75
|
* @example
|
|
77
76
|
* ```typescript
|
|
78
77
|
* import { onAnswerChange } from 'qp-bridge';
|
|
79
|
-
* const {
|
|
78
|
+
* const { cancelSubscription } = onAnswerChange((question, answer) => {
|
|
80
79
|
* console.log(`Answer for ${question} changed to:`, answer);
|
|
81
80
|
* });
|
|
82
81
|
*
|
|
@@ -89,9 +88,8 @@ export declare function onAnswerChange(listener: (question: string, answer: unkn
|
|
|
89
88
|
};
|
|
90
89
|
/**
|
|
91
90
|
* Wraps an asynchronous action with a busy indicator in the host application.
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* 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.
|
|
95
93
|
*
|
|
96
94
|
* @typeParam T - The resolved type of the provided async action.
|
|
97
95
|
* @param action - A function returning a promise whose execution should be wrapped.
|
|
@@ -107,3 +105,16 @@ export declare function onAnswerChange(listener: (question: string, answer: unkn
|
|
|
107
105
|
* ```
|
|
108
106
|
*/
|
|
109
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>;
|