or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

colors.mddata-formats.mddate-time.mdfinancial.mdgeographic.mdidentifiers.mdindex.mdnetwork.mdnumeric.mdspecialized.mdstring-text.mdutilities.md
tile.json

specialized.mddocs/

Specialized Scalars

Specialized validation for books, classifications, versions, and other domain-specific formats. These scalars provide validation for specialized data types used in specific industries and use cases.

Capabilities

Library and Classification Scalars

ISBN Scalar

Validates International Standard Book Number format.

/**
 * GraphQL scalar for ISBN validation
 * Accepts both ISBN-10 and ISBN-13 formats with check digit validation
 */
const GraphQLISBN: GraphQLScalarType;

Example Values:

  • "978-0-13-110362-7" (ISBN-13 with hyphens)
  • "9780131103627" (ISBN-13 without hyphens)
  • "0-13-110362-8" (ISBN-10 with hyphens)
  • "0131103628" (ISBN-10 without hyphens)

DeweyDecimal Scalar

Validates Dewey Decimal Classification numbers.

/**
 * GraphQL scalar for Dewey Decimal Classification validation
 * Accepts DDC numbers in standard format (000-999 with optional decimal extensions)
 */
const GraphQLDeweyDecimal: GraphQLScalarType;

Example Values:

  • "004.678" (Computer programming)
  • "796.332" (American football)
  • "641.5" (Cooking)
  • "150" (Psychology)
  • "821.914" (Modern English poetry)

LCCSubclass Scalar

Validates Library of Congress Classification subclass codes.

/**
 * GraphQL scalar for Library of Congress Classification subclass validation
 * Accepts LCC subclass format (letter combinations followed by numbers)
 */
const GraphQLLCCSubclass: GraphQLScalarType;

Example Values:

  • "QA76.73" (Computer programming languages)
  • "PR6001" (English literature)
  • "TX714" (Cooking)
  • "BF121" (Psychology)
  • "Z695.1" (Library science)

IPCPatent Scalar

Validates International Patent Classification codes.

/**
 * GraphQL scalar for International Patent Classification validation
 * Accepts IPC format for patent classification
 */
const GraphQLIPCPatent: GraphQLScalarType;

Example Values:

  • "H04L29/06" (Network protocols)
  • "G06F21/62" (Computer security)
  • "A61K31/4427" (Pharmaceutical compounds)
  • "B60W30/14" (Vehicle control systems)

Version and Identification Scalars

SemVer Scalar

Validates Semantic Version format.

/**
 * GraphQL scalar for Semantic Version validation
 * Accepts semver format: MAJOR.MINOR.PATCH with optional pre-release and build metadata
 */
const GraphQLSemVer: GraphQLScalarType;

Example Values:

  • "1.0.0" (Basic version)
  • "2.1.3" (Patch version)
  • "1.0.0-alpha" (Pre-release)
  • "1.0.0-alpha.1" (Pre-release with number)
  • "1.0.0+20130313144700" (With build metadata)
  • "1.0.0-beta.2+exp.sha.5114f85" (Complex version)

SESSN Scalar

Validates Swedish Social Security Number format.

/**
 * GraphQL scalar for Swedish Social Security Number validation
 * Accepts Swedish personnummer format with check digit validation
 */
const GraphQLSESSN: GraphQLScalarType;

Example Values:

  • "121212-1212" (Standard format)
  • "19121212-1212" (With century)
  • "121212+1212" (Born before 1900, using + separator)

Special Purpose Scalars

Void Scalar

Represents void/null type for operations that return no meaningful value.

/**
 * GraphQL scalar for void/null type
 * Accepts null or undefined values only
 */
const GraphQLVoid: GraphQLScalarType;

Example Values:

  • null
  • undefined (serialized as null)

Usage Examples

import { 
  GraphQLISBN,
  GraphQLSemVer,
  GraphQLDeweyDecimal,
  GraphQLVoid
} from "graphql-scalars";

// In a GraphQL schema
const BookType = new GraphQLObjectType({
  name: "Book",
  fields: {
    isbn: { type: GraphQLISBN },
    deweyDecimal: { type: GraphQLDeweyDecimal },
    version: { type: GraphQLSemVer },
  },
});

const SoftwareType = new GraphQLObjectType({
  name: "Software",
  fields: {
    version: { type: GraphQLSemVer },
  },
});

// Using with type definitions
const typeDefs = `
  scalar ISBN
  scalar SemVer
  scalar DeweyDecimal
  scalar LCCSubclass
  scalar IPCPatent
  scalar SESSN
  scalar Void
  
  type Book {
    id: ID!
    title: String!
    isbn: ISBN
    deweyDecimal: DeweyDecimal
    lccSubclass: LCCSubclass
  }
  
  type Software {
    name: String!
    version: SemVer!
    previousVersion: SemVer
  }
  
  type Patent {
    id: ID!
    title: String!
    ipcClassification: IPCPatent
  }
  
  type Mutation {
    deleteItem(id: ID!): Void
  }
`;

GraphQL Operations:

query GetBook($isbn: ISBN!) {
  bookByISBN(isbn: $isbn) {
    id
    title
    isbn
    deweyDecimal
    lccSubclass
  }
}

query GetSoftwareVersions($name: String!) {
  software(name: $name) {
    name
    version
    releases {
      version
      releaseDate
    }
  }
}

mutation DeleteBook($id: ID!): Void {
  deleteBook(id: $id)
}

Variables:

{
  "isbn": "978-0-13-110362-7",
  "name": "my-awesome-library",
  "id": "book-123"
}

Validation Behavior

Each specialized scalar performs domain-specific validation:

  • ISBN: Validates format and check digits for both ISBN-10 and ISBN-13
  • SemVer: Validates semantic version format including pre-release and build metadata
  • DeweyDecimal: Validates DDC number format and ranges
  • LCCSubclass: Validates Library of Congress format structure
  • IPCPatent: Validates International Patent Classification format
  • SESSN: Validates Swedish social security number format and check digits
  • Void: Only accepts null/undefined values

Validation Examples:

// Valid specialized data
const validData = {
  isbn: "978-0-13-110362-7",      // Valid ISBN-13
  semver: "2.1.3-alpha.1",        // Valid semantic version
  dewey: "004.678",               // Valid DDC number
  lcc: "QA76.73",                 // Valid LCC subclass
  ipc: "H04L29/06",               // Valid IPC code
  sessn: "121212-1212",           // Valid Swedish SSN
  voidValue: null                 // Valid void value
};

// Invalid specialized data
const invalidData = {
  isbn: "978-0-13-110362-8",      // Invalid check digit
  semver: "2.1",                  // Missing patch version
  dewey: "1000.1",                // Invalid range (> 999)
  lcc: "INVALID123",              // Invalid format
  ipc: "INVALID/CODE",            // Invalid IPC format
  sessn: "999999-9999",           // Invalid Swedish SSN
  voidValue: "not-null"           // Invalid for void type
};

Domain-Specific Use Cases

Library Systems use these scalars for:

  • ISBN: Book identification and cataloging
  • DeweyDecimal: Book classification and shelving
  • LCCSubclass: Academic library organization

Software Development uses:

  • SemVer: Version management and dependency resolution
  • Void: APIs that perform actions without returning data

Patent Systems use:

  • IPCPatent: Patent classification and searching

Government/Identity Systems use:

  • SESSN: Swedish identity verification and records

Semantic Versioning Details

The SemVer scalar supports full semantic versioning specification:

Version Format: MAJOR.MINOR.PATCH[-PRERELEASE][+BUILD]

  • MAJOR: Incremented for incompatible API changes
  • MINOR: Incremented for backwards-compatible functionality
  • PATCH: Incremented for backwards-compatible bug fixes
  • PRERELEASE: Optional pre-release version (alpha, beta, rc.1)
  • BUILD: Optional build metadata

Precedence Rules:

  • 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1
  • 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-beta < 1.0.0

Type Definitions

// String constants for schema building
const ISBN: string;            // "scalar ISBN"
const SemVer: string;          // "scalar SemVer"
const DeweyDecimal: string;    // "scalar DeweyDecimal"
const LCCSubclass: string;     // "scalar LCCSubclass"
const IPCPatent: string;       // "scalar IPCPatent"
const SESSN: string;           // "scalar SESSN"
const Void: string;            // "scalar Void"

Mock Data

// Mock data generators for testing
const ISBNMock: () => string;
const SemVerMock: () => string;
const DeweyDecimalMock: () => string;
const LCCSubclassMock: () => string;
const IPCPatentMock: () => string;
const SESSNMock: () => string;
const VoidMock: () => null;

Practical Applications

These specialized scalars are particularly useful in:

  • Library Management Systems: Book cataloging and classification
  • Package Managers: Version dependency resolution
  • Patent Databases: Intellectual property classification
  • Government Systems: Identity verification and records
  • Academic Systems: Research classification and organization
  • API Design: Type-safe operations with proper return types