@surveystudio/node-registery 1.0.1 → 1.0.2
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 +12 -0
- package/dist/builder.d.mts +4 -3
- package/dist/{types-Bsz6x6iU.d.mts → coreTypes-D-1hYIe5.d.mts} +13 -53
- package/dist/logic.d.mts +4 -3
- package/dist/logic.mjs +13 -6
- package/dist/runner.d.mts +2 -1
- package/dist/types-BpvjaHAP.d.mts +51 -0
- package/dist/{types-HCD7-TAw.d.mts → types-D78Zx0gX.d.mts} +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,6 +16,18 @@ Use `/logic` for Worker, export, and server runtimes. It is intentionally React-
|
|
|
16
16
|
|
|
17
17
|
Use `/runner` and `/builder` only in React runtimes. React is a peer dependency and is not bundled.
|
|
18
18
|
|
|
19
|
+
## Logic Pipeline
|
|
20
|
+
|
|
21
|
+
Every node logic module should expose the same pure, Worker-safe pipeline:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const value = logicRegistry.plainText.normalizeValue(rawAnswer, node.data, context);
|
|
25
|
+
const validation = logicRegistry.plainText.validate(value, node.data, context);
|
|
26
|
+
const columns = logicRegistry.plainText.extractValue(value, node.data, context);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Runner APIs should persist and queue normalized values. Export/projection APIs should read normalized values through `extractValue`.
|
|
30
|
+
|
|
19
31
|
## Current Status
|
|
20
32
|
|
|
21
33
|
Migrated nodes:
|
package/dist/builder.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export { B as BuilderRegistry, c as CompleteBuilderRegistry, e as NodeBuilder, f as NodeBuilderProps, g as NodeCanvasProps, Q as QuestionNodeDefinition, h as defineBuilderRegistry, d as defineQuestionNode } from './types-BpvjaHAP.mjs';
|
|
2
|
+
import { J as JsonValue } from './coreTypes-D-1hYIe5.mjs';
|
|
3
|
+
export { f as NodeManifest, P as PropertyField, g as PropertyFieldType, S as SelectOption } from './coreTypes-D-1hYIe5.mjs';
|
|
4
|
+
import { P as PlainTextData } from './types-D78Zx0gX.mjs';
|
|
4
5
|
import 'react';
|
|
5
6
|
|
|
6
7
|
declare const plainTextBuilder: {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ReactNode, ComponentType } from 'react';
|
|
2
|
-
|
|
3
1
|
declare const QUESTION_NODE_TYPES: readonly ["textInput", "numberInput", "emailInput", "dateInput", "multiInput", "zipCodeInput", "singleChoice", "multipleChoice", "dropdown", "ranking", "cascadingChoice", "matrixChoice", "rating", "slider", "consent", "captcha", "image", "video", "audio", "plainText", "emojiRating"];
|
|
4
2
|
declare const FLOW_NODE_TYPES: readonly ["start", "end", "branch", "validation"];
|
|
5
3
|
type QuestionNodeType = (typeof QUESTION_NODE_TYPES)[number];
|
|
@@ -43,6 +41,14 @@ interface ValidationResult {
|
|
|
43
41
|
readonly valid: boolean;
|
|
44
42
|
readonly error?: string;
|
|
45
43
|
}
|
|
44
|
+
interface NodeLogicContext<TType extends SurveyNodeType = SurveyNodeType> {
|
|
45
|
+
readonly nodeId: string;
|
|
46
|
+
readonly nodeType: TType;
|
|
47
|
+
readonly answerKey?: string;
|
|
48
|
+
}
|
|
49
|
+
interface ValidationContext<TType extends SurveyNodeType = SurveyNodeType> extends NodeLogicContext<TType> {
|
|
50
|
+
readonly mode?: "LIVE" | "TEST";
|
|
51
|
+
}
|
|
46
52
|
interface ExtractedValue {
|
|
47
53
|
readonly questionId?: string;
|
|
48
54
|
readonly columnKey?: string;
|
|
@@ -56,9 +62,7 @@ interface ExtractedValue {
|
|
|
56
62
|
readonly objectValue?: Readonly<Record<string, JsonValue>>;
|
|
57
63
|
readonly metadata?: Readonly<Record<string, JsonValue>>;
|
|
58
64
|
}
|
|
59
|
-
interface ExtractionContext<TType extends SurveyNodeType = SurveyNodeType> {
|
|
60
|
-
readonly nodeId: string;
|
|
61
|
-
readonly nodeType: TType;
|
|
65
|
+
interface ExtractionContext<TType extends SurveyNodeType = SurveyNodeType> extends NodeLogicContext<TType> {
|
|
62
66
|
readonly questionLabel?: string;
|
|
63
67
|
}
|
|
64
68
|
interface NodeLogic<TType extends SurveyNodeType = SurveyNodeType, TData extends NodeData = NodeData, TValue extends NodeValue = NodeValue> {
|
|
@@ -66,60 +70,16 @@ interface NodeLogic<TType extends SurveyNodeType = SurveyNodeType, TData extends
|
|
|
66
70
|
readonly dataType: DataType;
|
|
67
71
|
readonly defaultData: Readonly<TData>;
|
|
68
72
|
readonly defaultValue?: TValue;
|
|
69
|
-
|
|
73
|
+
normalizeValue(rawValue: unknown, nodeData: Readonly<TData>, context: NodeLogicContext<TType>): TValue;
|
|
74
|
+
validate(value: TValue, nodeData: Readonly<TData>, context: ValidationContext<TType>): ValidationResult;
|
|
70
75
|
extractValue(value: TValue, nodeData: Readonly<TData>, context: ExtractionContext<TType>): readonly ExtractedValue[];
|
|
71
76
|
}
|
|
72
|
-
interface NodeRunnerProps<TData extends NodeData = NodeData, TValue extends NodeValue = NodeValue> {
|
|
73
|
-
readonly data: Readonly<TData>;
|
|
74
|
-
readonly value: TValue;
|
|
75
|
-
readonly onChange: (newValue: TValue) => void;
|
|
76
|
-
readonly onNext?: () => void;
|
|
77
|
-
readonly error?: string;
|
|
78
|
-
readonly isActive?: boolean;
|
|
79
|
-
}
|
|
80
|
-
interface NodeRunner<TType extends SurveyNodeType = SurveyNodeType, TData extends NodeData = NodeData, TValue extends NodeValue = NodeValue> {
|
|
81
|
-
readonly type: TType;
|
|
82
|
-
readonly Component?: ComponentType<NodeRunnerProps<TData, TValue>>;
|
|
83
|
-
}
|
|
84
|
-
interface NodeBuilderProps<TData extends NodeData = NodeData> {
|
|
85
|
-
readonly data: Readonly<TData>;
|
|
86
|
-
readonly onChange: (newData: TData) => void;
|
|
87
|
-
}
|
|
88
|
-
interface NodeCanvasProps<TData extends NodeData = NodeData> {
|
|
89
|
-
readonly id: string;
|
|
90
|
-
readonly type: SurveyNodeType;
|
|
91
|
-
readonly data: Readonly<TData>;
|
|
92
|
-
readonly selected?: boolean;
|
|
93
|
-
}
|
|
94
|
-
interface NodeBuilder<TType extends SurveyNodeType = SurveyNodeType, TData extends NodeData = NodeData> {
|
|
95
|
-
readonly type: TType;
|
|
96
|
-
readonly label: string;
|
|
97
|
-
readonly icon?: ReactNode;
|
|
98
|
-
readonly SettingsComponent?: ComponentType<NodeBuilderProps<TData>>;
|
|
99
|
-
readonly CanvasComponent?: ComponentType<NodeCanvasProps<TData>>;
|
|
100
|
-
}
|
|
101
|
-
interface QuestionNodeDefinition<TType extends QuestionNodeType = QuestionNodeType, TData extends NodeData = NodeData, TValue extends NodeValue = NodeValue> {
|
|
102
|
-
readonly manifest: NodeManifest<TType, TData>;
|
|
103
|
-
readonly logic: NodeLogic<TType, TData, TValue>;
|
|
104
|
-
readonly builder: NodeBuilder<TType, TData>;
|
|
105
|
-
readonly runner: NodeRunner<TType, TData, TValue>;
|
|
106
|
-
}
|
|
107
77
|
type CompleteLogicRegistry<TType extends QuestionNodeType = QuestionNodeType> = Readonly<Record<TType, NodeLogic<TType, NodeData, NodeValue>>>;
|
|
108
|
-
type CompleteBuilderRegistry<TType extends QuestionNodeType = QuestionNodeType> = Readonly<Record<TType, NodeBuilder<TType, NodeData>>>;
|
|
109
|
-
type CompleteRunnerRegistry<TType extends QuestionNodeType = QuestionNodeType> = Readonly<Record<TType, NodeRunner<TType, NodeData, NodeValue>>>;
|
|
110
78
|
type LogicRegistry<TType extends SurveyNodeType = SurveyNodeType> = Readonly<Partial<{
|
|
111
79
|
[K in TType]: NodeLogic<K, NodeData, NodeValue>;
|
|
112
80
|
}>>;
|
|
113
|
-
type BuilderRegistry<TType extends SurveyNodeType = SurveyNodeType> = Readonly<Partial<{
|
|
114
|
-
[K in TType]: NodeBuilder<K, NodeData>;
|
|
115
|
-
}>>;
|
|
116
|
-
type RunnerRegistry<TType extends SurveyNodeType = SurveyNodeType> = Readonly<Partial<{
|
|
117
|
-
[K in TType]: NodeRunner<K, NodeData, NodeValue>;
|
|
118
|
-
}>>;
|
|
119
|
-
declare function defineQuestionNode<const TType extends QuestionNodeType, TData extends NodeData, TValue extends NodeValue>(definition: QuestionNodeDefinition<TType, TData, TValue>): QuestionNodeDefinition<TType, TData, TValue>;
|
|
120
81
|
type RegistryKeySet = Readonly<Partial<Record<SurveyNodeType, unknown>>>;
|
|
121
82
|
declare function defineLogicRegistry<const TRegistry extends RegistryKeySet>(registry: TRegistry): TRegistry;
|
|
122
|
-
declare function
|
|
123
|
-
declare function defineRunnerRegistry<const TRegistry extends RegistryKeySet>(registry: TRegistry): TRegistry;
|
|
83
|
+
declare function createInitialData<TData extends NodeData>(manifest: NodeManifest<SurveyNodeType, TData>): TData;
|
|
124
84
|
|
|
125
|
-
export { type
|
|
85
|
+
export { type CompleteLogicRegistry as C, type DataType as D, type ExtractedValue as E, type JsonValue as J, type LogicRegistry as L, type NodeLogic as N, type PropertyField as P, type QuestionNodeType as Q, type SelectOption as S, type ValidationContext as V, type ExtractionContext as a, type NodeLogicContext as b, type ValidationResult as c, createInitialData as d, defineLogicRegistry as e, type NodeManifest as f, type PropertyFieldType as g, type NodeData as h, type SurveyNodeType as i, type NodeValue as j };
|
package/dist/logic.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { P as PlainTextData, a as PlainTextValue } from './types-
|
|
2
|
-
export { C as CompleteLogicRegistry, D as DataType, E as ExtractedValue, a as ExtractionContext, L as LogicRegistry, N as NodeLogic,
|
|
3
|
-
import 'react';
|
|
1
|
+
import { P as PlainTextData, a as PlainTextValue } from './types-D78Zx0gX.mjs';
|
|
2
|
+
export { C as CompleteLogicRegistry, D as DataType, E as ExtractedValue, a as ExtractionContext, L as LogicRegistry, N as NodeLogic, b as NodeLogicContext, V as ValidationContext, c as ValidationResult, d as createInitialData, e as defineLogicRegistry } from './coreTypes-D-1hYIe5.mjs';
|
|
4
3
|
|
|
5
4
|
declare const plainTextLogic: {
|
|
6
5
|
type: "plainText";
|
|
@@ -9,6 +8,7 @@ declare const plainTextLogic: {
|
|
|
9
8
|
defaultValue: {
|
|
10
9
|
viewed: false;
|
|
11
10
|
};
|
|
11
|
+
normalizeValue: (value: unknown) => PlainTextValue;
|
|
12
12
|
validate: () => {
|
|
13
13
|
valid: true;
|
|
14
14
|
};
|
|
@@ -27,6 +27,7 @@ declare const logicRegistry: {
|
|
|
27
27
|
defaultValue: {
|
|
28
28
|
viewed: false;
|
|
29
29
|
};
|
|
30
|
+
normalizeValue: (value: unknown) => PlainTextValue;
|
|
30
31
|
validate: () => {
|
|
31
32
|
valid: true;
|
|
32
33
|
};
|
package/dist/logic.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
function defineQuestionNode(definition) {
|
|
3
|
-
return definition;
|
|
4
|
-
}
|
|
1
|
+
// src/coreTypes.ts
|
|
5
2
|
function defineLogicRegistry(registry) {
|
|
6
3
|
return registry;
|
|
7
4
|
}
|
|
5
|
+
function createInitialData(manifest) {
|
|
6
|
+
return { ...manifest.defaultData };
|
|
7
|
+
}
|
|
8
8
|
|
|
9
9
|
// src/nodes/plainText/manifest.ts
|
|
10
10
|
var plainTextDefaultData = {
|
|
@@ -45,17 +45,24 @@ var plainTextManifest = {
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
// src/nodes/plainText/logic.ts
|
|
48
|
+
var normalizePlainTextValue = (value) => {
|
|
49
|
+
if (!value || typeof value !== "object") {
|
|
50
|
+
return { viewed: false };
|
|
51
|
+
}
|
|
52
|
+
return { viewed: Boolean(value.viewed) };
|
|
53
|
+
};
|
|
48
54
|
var plainTextLogic = {
|
|
49
55
|
type: "plainText",
|
|
50
56
|
dataType: "none",
|
|
51
57
|
defaultData: plainTextDefaultData,
|
|
52
58
|
defaultValue: { viewed: false },
|
|
59
|
+
normalizeValue: (value) => normalizePlainTextValue(value),
|
|
53
60
|
validate: () => ({ valid: true }),
|
|
54
61
|
extractValue: (value) => [
|
|
55
62
|
{
|
|
56
63
|
columnKey: "viewed",
|
|
57
64
|
columnLabel: "Viewed",
|
|
58
|
-
booleanValue: Boolean(value
|
|
65
|
+
booleanValue: Boolean(value.viewed)
|
|
59
66
|
}
|
|
60
67
|
]
|
|
61
68
|
};
|
|
@@ -65,8 +72,8 @@ var logicRegistry = defineLogicRegistry({
|
|
|
65
72
|
plainText: plainTextLogic
|
|
66
73
|
});
|
|
67
74
|
export {
|
|
75
|
+
createInitialData,
|
|
68
76
|
defineLogicRegistry,
|
|
69
|
-
defineQuestionNode,
|
|
70
77
|
logicRegistry,
|
|
71
78
|
plainTextLogic
|
|
72
79
|
};
|
package/dist/runner.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { C as CompleteRunnerRegistry, N as NodeRunner, a as NodeRunnerProps, Q as QuestionNodeDefinition, R as RunnerRegistry, d as defineQuestionNode, b as defineRunnerRegistry } from './types-BpvjaHAP.mjs';
|
|
2
2
|
import 'react';
|
|
3
|
+
import './coreTypes-D-1hYIe5.mjs';
|
|
3
4
|
|
|
4
5
|
declare const plainTextRunner: {
|
|
5
6
|
type: "plainText";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from 'react';
|
|
2
|
+
import { Q as QuestionNodeType, i as SurveyNodeType, h as NodeData, j as NodeValue, f as NodeManifest, N as NodeLogic } from './coreTypes-D-1hYIe5.mjs';
|
|
3
|
+
|
|
4
|
+
interface NodeRunnerProps<TData extends NodeData = NodeData, TValue extends NodeValue = NodeValue> {
|
|
5
|
+
readonly data: Readonly<TData>;
|
|
6
|
+
readonly value: TValue;
|
|
7
|
+
readonly onChange: (newValue: TValue) => void;
|
|
8
|
+
readonly onNext?: () => void;
|
|
9
|
+
readonly error?: string;
|
|
10
|
+
readonly isActive?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface NodeRunner<TType extends SurveyNodeType = SurveyNodeType, TData extends NodeData = NodeData, TValue extends NodeValue = NodeValue> {
|
|
13
|
+
readonly type: TType;
|
|
14
|
+
readonly Component?: ComponentType<NodeRunnerProps<TData, TValue>>;
|
|
15
|
+
}
|
|
16
|
+
interface NodeBuilderProps<TData extends NodeData = NodeData> {
|
|
17
|
+
readonly data: Readonly<TData>;
|
|
18
|
+
readonly onChange: (newData: TData) => void;
|
|
19
|
+
}
|
|
20
|
+
interface NodeCanvasProps<TData extends NodeData = NodeData> {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly type: SurveyNodeType;
|
|
23
|
+
readonly data: Readonly<TData>;
|
|
24
|
+
readonly selected?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface NodeBuilder<TType extends SurveyNodeType = SurveyNodeType, TData extends NodeData = NodeData> {
|
|
27
|
+
readonly type: TType;
|
|
28
|
+
readonly label: string;
|
|
29
|
+
readonly icon?: ReactNode;
|
|
30
|
+
readonly SettingsComponent?: ComponentType<NodeBuilderProps<TData>>;
|
|
31
|
+
readonly CanvasComponent?: ComponentType<NodeCanvasProps<TData>>;
|
|
32
|
+
}
|
|
33
|
+
interface QuestionNodeDefinition<TType extends QuestionNodeType = QuestionNodeType, TData extends NodeData = NodeData, TValue extends NodeValue = NodeValue> {
|
|
34
|
+
readonly manifest: NodeManifest<TType, TData>;
|
|
35
|
+
readonly logic: NodeLogic<TType, TData, TValue>;
|
|
36
|
+
readonly builder: NodeBuilder<TType, TData>;
|
|
37
|
+
readonly runner: NodeRunner<TType, TData, TValue>;
|
|
38
|
+
}
|
|
39
|
+
type CompleteBuilderRegistry<TType extends QuestionNodeType = QuestionNodeType> = Readonly<Record<TType, NodeBuilder<TType, NodeData>>>;
|
|
40
|
+
type CompleteRunnerRegistry<TType extends QuestionNodeType = QuestionNodeType> = Readonly<Record<TType, NodeRunner<TType, NodeData, NodeValue>>>;
|
|
41
|
+
type BuilderRegistry<TType extends SurveyNodeType = SurveyNodeType> = Readonly<Partial<{
|
|
42
|
+
[K in TType]: NodeBuilder<K, NodeData>;
|
|
43
|
+
}>>;
|
|
44
|
+
type RunnerRegistry<TType extends SurveyNodeType = SurveyNodeType> = Readonly<Partial<{
|
|
45
|
+
[K in TType]: NodeRunner<K, NodeData, NodeValue>;
|
|
46
|
+
}>>;
|
|
47
|
+
declare function defineQuestionNode<const TType extends QuestionNodeType, TData extends NodeData, TValue extends NodeValue>(definition: QuestionNodeDefinition<TType, TData, TValue>): QuestionNodeDefinition<TType, TData, TValue>;
|
|
48
|
+
declare function defineBuilderRegistry<const TRegistry extends Readonly<Partial<Record<SurveyNodeType, unknown>>>>(registry: TRegistry): TRegistry;
|
|
49
|
+
declare function defineRunnerRegistry<const TRegistry extends Readonly<Partial<Record<SurveyNodeType, unknown>>>>(registry: TRegistry): TRegistry;
|
|
50
|
+
|
|
51
|
+
export { type BuilderRegistry as B, type CompleteRunnerRegistry as C, type NodeRunner as N, type QuestionNodeDefinition as Q, type RunnerRegistry as R, type NodeRunnerProps as a, defineRunnerRegistry as b, type CompleteBuilderRegistry as c, defineQuestionNode as d, type NodeBuilder as e, type NodeBuilderProps as f, type NodeCanvasProps as g, defineBuilderRegistry as h };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@surveystudio/node-registery",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Typed survey question node registry with split builder, runner, and logic entrypoints.",
|
|
5
5
|
"main": "./dist/logic.mjs",
|
|
6
6
|
"types": "./dist/logic.d.mts",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"react-dom": "^19.2.3"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
|
-
"test": "node --test test/*.test.mjs",
|
|
49
|
+
"test": "pnpm build && node --test test/*.test.mjs",
|
|
50
50
|
"typecheck": "tsc --noEmit",
|
|
51
51
|
"build": "tsup",
|
|
52
52
|
"prepack": "pnpm build",
|