2.0.12 â€Ē Published 8 months ago

@magicapply/retool-typebox-client v2.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@magicapply/retool-typebox-client

Typed âœĻ. Minimal ðŸŠķ. Retool-ready 🛠ïļ.
Turn remote TypeMap syntax strings into fully-typed validators inside Retool Workflows & Node.


Why this package?

Retool Workflows runs on Node.js 20 and lets you pipe data between blocks, but lacks built-in helpers for TypeBox schema validation.

This package bridges that gap by providing:

  • One-liner fetchers – download remote {version, schemas} JSON files containing TypeMap syntax strings, or transform them into [key, JSONSchema][] entries.
  • Zero-config validator – compile TypeMap syntax strings (like { id: string, tags: string[] }) lazily into TypeBox validators with convenient check | validate | assert helpers.
  • First-class TypeScript – generics & JSDoc types provide autocompletion without needing .ts files inside Retool.
  • Retool-specific utilities – strip Retool's _selector metadata keys and infer registry types from tuple entries.

Everything is packaged in ~0.4 MB of bundled CommonJS code optimized for Retool's Node.js 20 runtime.


Installation

npm install @magicapply/retool-typebox-client

This package is CommonJS-only (type: "commonjs") to match Retool's Node.js 20 runtime environment.


Quick start (two-block pipeline)

import { getSchemaEntries } from '@magicapply/retool-typebox-client'

// Fetch and compile TypeMap syntax strings to JSON schemas
return await getSchemaEntries(
  'https://api.example.com/schemas'
)
// @ts-check
import {
  fetchSchemas,
  createValidator,
  RegistryFromEntries
} from '@magicapply/retool-typebox-client'

// Get entries from previous block
const entries = /** @type {const} */ (input.data)

// Fetch raw TypeMap syntax strings for validation
const { schemas } = await fetchSchemas('https://api.example.com/schemas')

// Create validator from syntax strings
const validator = createValidator(schemas)

// Validate with autocompletion âœĻ
validator.assert('user.profile', { 
  id: '42', 
  name: 'Jane',
  tags: ['admin', 'verified']
})

API Reference

Function / TypeDescription
fetchSchemas(url, fetchFn?)Fetch { version, schemas } where schemas is a Record<string, string> of TypeMap syntax strings.
getSchemaEntries(url, fetchFn?)Fetch and compile syntax strings into [key, JSONSchema] pairs.
createValidator(registry)Compile TypeMap syntax strings lazily into validators with:check → boolean, validate → {value|issues}, assert → throws.Includes value re-export from @sinclair/typebox/value.
RegistryFromEntries<Entries>Infer a typed registry from [key, JSONSchema][] entries.
SchemaOf<Entries, Key>Extract a single schema type from entries.
ValidatorFromRegistry<Registry>Capture the return type of createValidator.
RemoteSchemas<T>Strip Retool's _selector metadata from fetched schemas.

TypeMap Syntax Examples

The syntax strings use TypeMap's TypeScript-like DSL:

const schemas = {
  'user.profile': '{ id: string, name: string, tags: string[] }',
  'user.settings': '{ theme: "light" | "dark", notifications: boolean }',
  'api.response': '{ data: any, status: number, error?: string }'
}

Advanced usage

1. Custom fetch implementation

Retool Cloud may lack global fetch in some contexts. Pass a compatible implementation:

import { getSchemaEntries } from '@magicapply/retool-typebox-client'
import fetch from 'node-fetch'

const entries = await getSchemaEntries(url, fetch)

2. Skip compilation for performance

If you only need raw TypeMap syntax strings (for createValidator), use fetchSchemas directly:

const { schemas } = await fetchSchemas(url)
const validator = createValidator(schemas) // Pass strings, not compiled schemas

3. Strip Retool metadata

Use RemoteSchemas<T> to remove _selector properties that Retool injects:

const raw = await fetchSchemas(url)
/** @type {RemoteSchemas<typeof raw.schemas>} */
const clean = raw.schemas
const validator = createValidator(clean)

Compatibility matrix

EnvironmentStatus
Retool Workflows (Node 20)✅ Primary target
Node.js â‰Ĩ 16✅
Bun â‰Ĩ 1.1✅ (used in tests)
Browsers✅ (with fetch polyfill)

Contributing

  1. bun install
  2. bun run test – runs unit tests with Bun and type-tests with tsd
  3. Submit a PR — focused contributions welcome!

License

MIT ÂĐ Magic Apply

2.0.12

8 months ago

2.0.11

8 months ago

2.0.10

8 months ago

2.0.9

8 months ago

2.0.8

8 months ago

2.0.7

8 months ago

2.0.0

8 months ago

2.0.5

8 months ago

2.0.4

8 months ago

2.0.3

8 months ago

2.0.2

8 months ago

2.0.1

8 months ago

1.1.32

8 months ago

1.1.31

8 months ago

1.1.30

8 months ago

1.1.29

8 months ago

1.1.28

8 months ago

1.1.27

8 months ago

1.1.26

8 months ago

1.1.25

8 months ago

1.1.24

8 months ago

1.1.23

8 months ago

1.1.22

8 months ago

1.1.21

8 months ago

1.1.20

8 months ago

1.1.19

8 months ago

1.1.18

8 months ago

1.1.17

8 months ago

1.1.16

8 months ago

1.1.15

8 months ago

1.1.14

8 months ago

1.1.13

8 months ago

1.1.12

8 months ago

1.1.11

8 months ago

1.1.10

8 months ago

1.1.9

8 months ago

1.1.8

8 months ago

1.1.7

8 months ago

1.1.6

8 months ago

1.1.4

8 months ago

1.1.2

8 months ago

1.0.14

8 months ago

1.0.13

8 months ago

1.0.11

8 months ago

1.0.9

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago