Schemas
Schemas describe collection document shape. TeamPlay uses them for backend validation and TypeScript inference.
Define A Schema
Create one schema.ts per collection:
defineSchema() currently returns the schema unchanged at runtime. It marks the schema as intentionally defined and gives TypeScript the best literal inference without needing as const.
Plain exported schema objects still work, but defineSchema() is the conventional form.
Document Type
The generated teamplay-env.d.ts makes the schema module's default export usable as the document type:
You can still use FromJsonSchema manually when needed:
Validation
Enable schema validation on the backend:
Stored documents should use JSON values: strings, numbers, booleans, nulls, arrays, and plain objects. Prefer Date.now() numbers over Date instances.
Private Root Schemas
Public collection schemas describe one document in a database collection. Private root schemas are different: they describe the whole private value.
This makes $._session, $.session, and $.$session typed:
Private schemas are used for TypeScript and editor field metadata only. They are skipped by backend JSON-schema validation because private collections live on the client and are not stored as shared database collections.
Simplified Schema
Most TeamPlay apps use simplified schemas. If the root schema does not have type: 'object', TeamPlay treats the top-level object as the collection document's properties:
That means fields can be named title, description, type, required, properties, and other JSON Schema keywords.
Full JSON Schema
Use full JSON Schema when you need root-level JSON Schema keywords:
Labels And Descriptions
The type generator reads simple schema files and adds JSDoc for signal fields when it can statically find literal label and description values:
Then editor suggestions for $user.name and $user.$name can show the schema text.
This is best-effort. If the schema is built dynamically, TeamPlay still infers the document shape from TypeScript, but field JSDoc may be skipped.