Schemas#

Types#

ds_schema_lifecycle_t#

typedef enum { DS_SCHEMA_LIFECYCLE_LOGICAL = 0, DS_SCHEMA_LIFECYCLE_TTL = 1, DS_SCHEMA_LIFECYCLE_INTERNAL = 2 } ds_schema_lifecycle_t;

How a fact of a schema leaves working memory.

Member

Meaning

DS_SCHEMA_LIFECYCLE_LOGICAL

the fact stays until it is retracted: by ds_engine_retract, by a rule’s retract action, or by truth maintenance when a logical justifier ends. ttl_ns is 0

DS_SCHEMA_LIFECYCLE_TTL

the fact carries a deadline, and the pump’s sweep retracts it once the deadline passes. ttl_ns is above 0

DS_SCHEMA_LIFECYCLE_INTERNAL

a schema the engine owns and asserts itself: the built-in fault schemas ComputationError and TypeError

A schema the artefact declares explicit, logical or activation reads as DS_SCHEMA_LIFECYCLE_LOGICAL. An internal schema is told from a program’s own by this value, and not by its name.

(libds.h: ds_schema_lifecycle_t, Spec: [NFCT.4.1], [NFCT.4.5], [NDBG.2.2])

ds_slot_type_t#

typedef enum { … } ds_slot_type_t;

A slot’s schema-declared type.

Member

Meaning

DS_SLOT_TYPE_INT

an integer

DS_SLOT_TYPE_FLOAT

a float

DS_SLOT_TYPE_STRING

a string

DS_SLOT_TYPE_BOOL

a boolean

DS_SLOT_TYPE_JSON

a ds_json_t tree

DS_SLOT_TYPE_SCHEMA

a reference to a fact; schema_ref is non-NULL

DS_SLOT_TYPE_BYTES

binary

DS_SLOT_TYPE_TIME

an instant’s nanoseconds since the epoch, UTC, with no zone

DS_SLOT_TYPE_DATE

days since the epoch

DS_SLOT_TYPE_DURATION

nanoseconds; also a slot declared a time unit or time

The value kind each type takes is in Slot value kinds.

(libds.h: ds_slot_type_t, Spec: [RDSC.5.5.8])

ds_identity_role_t#

typedef enum { DS_IDENTITY_UNSPECIFIED = 0, DS_IDENTITY_KEY = 1, DS_IDENTITY_MUTABLE = 2, DS_IDENTITY_ENGINE = 3 } ds_identity_role_t;

A slot’s identity role.

Member

Meaning

DS_IDENTITY_UNSPECIFIED

a slot of a schema that is not logical

DS_IDENTITY_KEY

the slot is in the schema’s identity key

DS_IDENTITY_MUTABLE

the slot is payload

DS_IDENTITY_ENGINE

the slot is ts, outside the identity key and the no-op comparison

What the key does at an assert is in Reassertion.

(libds.h: ds_identity_role_t, ds_slot_desc_t, Spec: [NFCT.1.4.1])

ds_slot_desc_t#

typedef struct ds_slot_desc { const char *name; ds_slot_type_t type; const ds_schema_t *schema_ref; bool sampled; bool retained; bool has_tolerance; double tolerance; const char *docstring; bool hydration_eligible; ds_identity_role_t identity_role; bool nullable; } ds_slot_desc_t;

One slot of a loaded schema.

Member

Holds

name

the slot’s name, the engine’s own string, valid for the engine’s life

type

the declared type

schema_ref

a borrow of the referenced schema; non-NULL exactly when type is DS_SLOT_TYPE_SCHEMA

sampled, retained

per-slot markers the author declared

has_tolerance, tolerance

whether a tolerance was declared, and its value as a double; has_tolerance tells tolerance 0 from none

docstring

an optional docstring, engine-owned like name; may be NULL

hydration_eligible

true when a Hydration atom in the artefact names the slot; false otherwise

identity_role

the slot’s identity role

nullable

the slot was declared T?

A slot’s index among its schema’s descriptors is its position in an assert. The layout is in Data model.

(libds.h: ds_slot_desc_t, Spec: [NFCT.1.4.1], [IDAT.5.3], [IDAT.5.4])

Registry#

Schema registry#

An engine’s schemas are those a load registered, with the engine’s built-in internal schemas among them.

A ds_schema_t pointer from any of these calls is a borrow, valid for the engine’s lifetime.

(libds.h: Schema registry, ds_engine_schema_at, Spec: [NFCT.1.1], [NDBG.2.2], [IDAT.5.1])

ds_engine_schema_count#

ds_result_t ds_engine_schema_count(ds_engine_t *engine, size_t *out);

Reads the number of schemas registered on this engine.

Errors: DS_ERR_INVAL for a NULL engine or out; DS_ERR_STATE under Re-entry; DS_ERR_ENGINE_HALTED.

(libds.h: ds_engine_schema_count, Spec: [NDBG.2.2], Source: runtime/src/libds/schema.c)

ds_engine_schema_find#

ds_result_t ds_engine_schema_find(ds_engine_t *engine, const char *type_name, const ds_schema_t **out);

Looks a schema up by its own name.

type_name is the own name, plant.sensors.Reading for a schema of that library, and never an alias.

The status is DS_OK on a hit and on a miss, and *out is NULL on a miss. Errors: DS_ERR_INVAL for a NULL engine, type_name or out; DS_ERR_STATE under Re-entry; DS_ERR_ENGINE_HALTED.

(libds.h: ds_engine_schema_find, Spec: [IDAT.5.5], [NFCT.1.4.2], Source: runtime/src/libds/schema.c)

ds_engine_schema_at#

ds_result_t ds_engine_schema_at(ds_engine_t *engine, size_t index, const ds_schema_t **out);

Reads the schema at index, from 0 to the count less one.

Errors: DS_ERR_NOT_FOUND for an index out of range; DS_ERR_INVAL for a NULL engine or out; DS_ERR_STATE under Re-entry; DS_ERR_ENGINE_HALTED.

(libds.h: ds_engine_schema_at, Source: runtime/src/libds/schema.c)

Accessors#

Schema accessors#

The ds_schema_get_* calls read a ds_schema_t handle.

Each returns DS_OK with its out-pointers set. Strings are engine-owned, and valid for the engine’s lifetime. Each returns DS_ERR_INVAL for a NULL schema or a required out-pointer. After a halt, each answers as Handle reads after a halt states.

(libds.h: Schema introspection, Source: runtime/src/libds/schema.c)

ds_schema_get_name#

ds_result_t ds_schema_get_name(const ds_schema_t *schema, const char **out);

Reads the schema’s own name.

(libds.h: ds_schema_get_name, Spec: [NDBG.2.2], [NFCT.1.4.2])

ds_schema_get_lifecycle#

ds_result_t ds_schema_get_lifecycle(const ds_schema_t *schema, ds_schema_lifecycle_t *out);

Reads the schema’s lifecycle.

(libds.h: ds_schema_get_lifecycle, Spec: [NDBG.2.2])

ds_schema_get_ttl_ns#

ds_result_t ds_schema_get_ttl_ns(const ds_schema_t *schema, uint64_t *out);

Reads the schema’s TTL, in nanoseconds.

(libds.h: ds_schema_get_ttl_ns, Spec: [NDBG.2.2])

ds_schema_get_slot_count#

ds_result_t ds_schema_get_slot_count(const ds_schema_t *schema, uint32_t *out);

Reads the number of slots the schema declares.

(libds.h: ds_schema_get_slot_count, Spec: [NDBG.2.2])

ds_schema_get_slot#

ds_result_t ds_schema_get_slot(const ds_schema_t *schema, uint32_t index, ds_slot_desc_t *out);

Copies the descriptor of slot index into *out.

It also returns DS_ERR_NOT_FOUND for an index out of range.

(libds.h: ds_schema_get_slot, Spec: [NFCT.1.4.2], Source: runtime/src/libds/schema.c)

ds_schema_get_source#

ds_result_t ds_schema_get_source(const ds_schema_t *schema, const char **out_file, uint32_t *out_line, uint32_t *out_col);

Reads the schema’s source location, from the artefact’s SchemaSource atom.

All three out-pointers may be NULL. *out_file is NULL when the artefact has no SchemaSource for the schema.

(libds.h: ds_schema_get_source)

ds_schema_get_proto_source#

ds_result_t ds_schema_get_proto_source(const ds_schema_t *schema, const char **out_text, size_t *out_len);

Reads the schema’s generated .proto definition, from the artefact’s SchemaDef atom.

*out_text is NULL when the artefact has no SchemaDef for the schema. *out_len, if out_len is non-NULL, is the byte length excluding the NUL terminator.

(libds.h: ds_schema_get_proto_source)

Unit conversion#

ds_schema_slot_to_stored#

ds_result_t ds_schema_slot_to_stored(const ds_schema_t *schema, uint32_t index, const ds_slot_value_t *in, ds_slot_value_t *out);

Writes to *out the stored number of in, a number in the unit slot index names.

It computes what x::<unit> computes. in and *out are of the kind Slot value kinds pairs with the slot’s type. A slot names a unit when its declared type is a unit symbol. It is answered as Unit conversion results states.

(libds.h: ds_schema_slot_to_stored, Spec: [NFCT.1.4.6], [RDSC.5.5.9], [LUNI.8.5], Source: runtime/src/libds/engine_rete_adapters.c)

ds_schema_slot_from_stored#

ds_result_t ds_schema_slot_from_stored(const ds_schema_t *schema, uint32_t index, const ds_slot_value_t *in, ds_slot_value_t *out);

Writes to *out the stored number in expressed in the unit slot index names.

It computes what a kwarg of that unit receives. in and *out are of the kind Slot value kinds pairs with the slot’s type. It is answered as Unit conversion results states.

(libds.h: ds_schema_slot_from_stored, Spec: [NFCT.1.4.6], [RDSC.5.5.9], Source: runtime/src/libds/engine_rete_adapters.c)

Unit conversion results#

ds_schema_slot_to_stored and ds_schema_slot_from_stored change nothing in the engine, record no event and assert no fault fact, save for an EngineError the conversion raises, which halts the engine as any public call that raises one does.

Neither is a ds_engine_* call, and a callback may make either. Each returns the status of the first of these that holds, and writes *out only on DS_OK:

Order

Code

Condition

1

DS_ERR_INVAL

a NULL pointer

2

DS_ERR_ENGINE_HALTED

an EngineError has halted the engine

3

DS_ERR_NOT_FOUND

index names no slot of the schema

4

DS_ERR_INVAL

the slot names no unit

5

DS_ERR_SLOT_TYPE_MISMATCH

in’s kind is not the slot’s

6

DS_ERR_NAN_REJECTED

in is a NaN

7

DS_ERR_ENGINE_HALTED

the conversion raises an EngineError

8

DS_ERR_NOT_REPRESENTABLE

the conversion raises any other fault where a rule’s evaluation would, or its result is NaN

(libds.h: ds_schema_slot_to_stored, ds_schema_slot_from_stored, DS_ERR_NOT_REPRESENTABLE, DS_ERR_ENGINE_HALTED, Spec: [NFCT.1.4.6], [NCBK.2.9], [RARC.13.16], Source: runtime/src/libds/engine_rete_adapters.c)