Skip to main content

SurveyJS Adapter

Convert between SurveyJS form schemas and eSheet FormDefinition. Useful for leveraging AI models that have better training data for SurveyJS output, then converting to eSheet format.

Functions

FunctionSignatureDescription
importFromSurveyJS(schema: SurveyJSSchema) => FormDefinitionImport SurveyJS to eSheet
convertSurveyJSAlias for importFromSurveyJS
convertSurveyJSToESheetAlias for importFromSurveyJS
exportToSurveyJS(form: FormDefinition) => SurveyJSSchemaExport eSheet to SurveyJS
isSurveyJSSchema(value: unknown) => value is SurveyJSDetectionSchemaType guard for detection

Import from SurveyJS

import { importFromSurveyJS } from '@esheet/adapters';

const surveyJSSchema = {
title: 'Customer Feedback',
pages: [
{
name: 'page1',
elements: [
{ type: 'text', name: 'name', title: 'Your Name', isRequired: true },
{
type: 'rating',
name: 'satisfaction',
title: 'How satisfied are you?',
},
],
},
],
};

const formDefinition = importFromSurveyJS(surveyJSSchema);

All three function names are equivalent:

  • importFromSurveyJS — Named export matching MCP convention
  • convertSurveyJS — Alias
  • convertSurveyJSToESheet — Primary implementation

Export to SurveyJS

import { exportToSurveyJS } from '@esheet/adapters';

const surveyJSSchema = exportToSurveyJS(formDefinition);

Preserves original metadata from _sourceData for lossless round-trip when possible.

Type Guard

import { isSurveyJSSchema, importFromSurveyJS } from '@esheet/adapters';

if (isSurveyJSSchema(unknownSchema)) {
const form = importFromSurveyJS(unknownSchema);
}

Returns true if value has pages or elements array but NOT eSheet's fields property.

AI System Prompt

For AI-assisted SurveyJS schema generation:

import { SURVEYJS_SYSTEM_PROMPT } from '@esheet/adapters';

// Use in your AI system prompt configuration

The prompt instructs AI to:

  • Output valid SurveyJS JSON (raw, without markdown fences)
  • Use proper field type selection
  • Structure forms with pages and elements
  • Follow common SurveyJS patterns

Field Type Mapping

SurveyJS → eSheet

SurveyJS TypeeSheet Field Type
texttext
commentlongtext
radiogroupradio
checkboxcheck
dropdowndropdown
tagboxmultiselectdropdown
booleanboolean
ratingrating
rankingranking
matrixsinglematrix
matrixdropdown / matrixdynamicmultimatrix
signaturepadsignature
imageimage
html / expressionhtml
imagepickerradio
filetext
panel / paneldynamicsection
multipletextmultitext

Input Type Mapping

SurveyJS text field inputType maps to eSheet TextInputType:

SurveyJS inputTypeeSheet inputType
emailemail
teltel
urlurl
datedate
datetime-localdatetime-local
timetime
numbernumber
passwordpassword

Conditional Logic Conversion

SurveyJS conditional properties convert to eSheet rules:

SurveyJS PropertyeSheet Rule Effect
visibleIfvisible
enableIfenable
requiredIfrequired

Simple Expressions

// SurveyJS: { visibleIf: "{country} = 'USA'" }
// Converts to eSheet rule:
{
effect: 'visible',
logic: 'AND',
conditions: [{ conditionType: 'field', targetId: 'country', operator: 'equals', expected: 'USA' }]
}

Complex Expressions

Expressions with arithmetic or multiple fields convert to expression conditions:

// SurveyJS: { visibleIf: "{price} * {quantity} > 100" }
// Converts to eSheet rule:
{
effect: 'visible',
logic: 'AND',
conditions: [{
conditionType: 'expression',
expression: '{price} * {quantity} > 100'
}]
}

Round-Trip Fidelity

Original SurveyJS metadata is preserved in _sourceData:

const form = importFromSurveyJS(surveyJSSchema);
// form.fields[0]._sourceData = { elementType: 'text', name: 'q1', ... }

const exported = exportToSurveyJS(form);
// Original element type, name, and expressions restored

Types

TypeDescription
SurveyJSDetectionSchemaMinimal schema shape for detection: { pages?: unknown[]; elements?: unknown[] }