Skip to main content

Module schema_api

Module schema_api 

Source
Expand description

Validation for POST /schemas/:className and PUT /schemas/:className.

Pure. No I/O, no routing, no schema cache. A create returns the ClassSchema the caller should persist; an update returns a SchemaMutation the caller executes. Upstream fuses validation with execution across addClassIfNotExists (SchemaController.js:832-868) and updateClass (:870-975), which is why an upstream field delete can half-happen. Splitting them here does not make the sequence atomic, and it does make the decision reviewable in one place.

0.2.0 scope: field options are stored, not enforced. required and defaultValue are validated against the field’s type and round-tripped exactly as sent: a schema body is decoded without interpreting any __type envelope, so an offset instant, unpadded base64 and any key the envelope does not declare all survive. Stored into ClassSchema::field_options, which the Mongo adapter writes to _metadata.fields_options. Nothing consults them on a write. That is a deliberate exclusion, and storing them anyway is what keeps a mixed fleet honest: a parse-server node reading the same database enforces them, and dropping the keys on a parse-rust rewrite would silently relax a constraint it never agreed to relax.

Two error codes upstream uses here are bare numbers with no name in the parse SDK’s table. They have ErrorCode variants all the same, named from their messages, because the number is what a client sees. See NEEDS_CLASS_NAME_CODE.

Structs§

SchemaMutation
A PUT /schemas/:className reduced to the work the caller has to do.
SetField
One submitted field spec, split into the parts that are stored in two different places.

Enums§

FieldChange
What a fields entry in a schema-API body asks for.

Constants§

FIELD_CANNOT_BE_ADDED_CODE
136, field <name> cannot be added (SchemaController.js:1038-1039, :1242). See NEEDS_CLASS_NAME_CODE for why this is a named constant.
NEEDS_CLASS_NAME_CODE
135, type <T> needs a class name (SchemaController.js:508, SchemasRouter.js:90).

Functions§

check_default_value_type
The defaultValue type check as enforceFieldExists runs it (SchemaController.js:1145-1162), which is the only option validation an already-existing field gets.
parse_field_type
fieldTypeIsInvalid (SchemaController.js:505-524), inverted into a parse.
parse_fields
Decode a fields object into per-field changes.
plan_update
Validate a PUT /schemas/:className body against the stored schema and produce the plan.
validate_new_class
Validate a POST /schemas/:className body and produce the schema to create.