Rest API - Source Excerpt 03
Summary
This source excerpt preserves a bounded section of Spiralist/wp-content/plugins/ns12-manuscript/includes/rest-api.php so readers can inspect the evidence without opening the full source file.
**Source path:** Spiralist/wp-content/plugins/ns12-manuscript/includes/rest-api.php
'spec' => 'ns12-manuscript-kernel',
'version' => '1.0.0',
'statement' => 'Spiralism is a pattern-based system in which Spiralists participate by perceiving, interpreting, and transforming pattern.',
'identity' => spiralist_book_pages_get_spiralist_definition(),
'concepts' => [
'spiralism' => 'the system',
'spiral' => 'the recursive process',
'spiralist' => 'the participant',
],
'symbols' => spiralist_book_pages_get_symbols(),
'axioms' => spiralist_book_pages_get_axioms(),
'transformations' => spiralist_book_pages_get_symbol_transformations(),
'machineLinks' => spiralist_book_pages_get_primary_machine_endpoints(),
];
}
function spiralist_book_pages_rest_build_spec_payload(): array
{
return [
'spec' => 'ns12-manuscript-spec-reference',
'version' => '1.0.0',
'source' => [
'uri' => spiralist_book_pages_get_rest_url('spec'),
'title' => spiralist_book_pages_get_public_name() . ' API Reference',
'retrievedAt' => gmdate('c'),
],
'authority' => [
'host' => spiralist_book_pages_get_public_name(),
'uri' => spiralist_book_pages_get_rest_url(),
'role' => 'plugin-surface',
],
'machineLinks' => spiralist_book_pages_get_primary_machine_endpoints(),
'references' => [
['label' => 'Draft Library', 'url' => spiralist_book_pages_get_protocol5_library_url()],
['label' => 'Draft Schema', 'url' => spiralist_book_pages_get_uai_schema_url()],
['label' => 'Language Registry', 'url' => spiralist_book_pages_get_uai_registry_url()],
['label' => 'Symbol Registry Schema', 'url' => spiralist_book_pages_get_symbol_registry_schema_url()],
],
];
}
function spiralist_book_pages_rest_build_examples_payload(): array
{
$prompt_records = spiralist_book_pages_get_public_prompt_records(2);
$prompt_example = !empty($prompt_records[0]) ? $prompt_records[0] : new stdClass();
$symbol_payload = spiralist_book_pages_rest_build_symbols_payload();
return [
'spec' => 'ns12-manuscript-examples',
'version' => '1.0.0',
'source' => [
'uri' => spiralist_book_pages_get_rest_url('examples'),
'title' => spiralist_book_pages_get_public_name() . ' Example Payloads',
'retrievedAt' => gmdate('c'),
],
'examples' => [
[
'name' => 'site',
'endpoint' => spiralist_book_pages_get_rest_url('site'),
'contentType' => 'application/json',
'payload' => spiralist_book_pages_rest_build_site_payload(),
],
[
'name' => 'symbols',
'endpoint' => spiralist_book_pages_get_symbols_api_url(),
'contentType' => 'application/json',
'payload' => [
'axioms' => $symbol_payload['axioms'],
'symbols' => array_slice((array) $symbol_payload['symbols'], 0, 2),
'transformations' => $symbol_payload['transformations'],
],
],
[
'name' => 'prompt',
'endpoint' => spiralist_book_pages_get_prompts_api_url(),
'contentType' => 'application/json',
'payload' => $prompt_example,
],
],
];
}
function spiralist_book_pages_rest_get_site(WP_REST_Request $request): WP_REST_Response
{
return spiralist_book_pages_rest_response(
spiralist_book_pages_rest_build_site_payload(sanitize_key((string) $request->get_param('language')))
);
}
function spiralist_book_pages_rest_get_symbol_registry(): WP_REST_Response
{
return spiralist_book_pages_rest_response(spiralist_book_pages_rest_build_symbol_registry_payload());
}
function spiralist_book_pages_rest_get_axioms(): WP_REST_Response
{
return spiralist_book_pages_rest_response(
[
'count' => count(spiralist_book_pages_get_axioms()),
'axioms' => spiralist_book_pages_get_axioms(),
]
);
}
function spiralist_book_pages_rest_get_kernel(): WP_REST_Response
{
return spiralist_book_pages_rest_response(spiralist_book_pages_rest_build_kernel_payload());
}
function spiralist_book_pages_rest_get_symbols(): WP_REST_Response
{
return spiralist_book_pages_rest_response(spiralist_book_pages_rest_build_symbols_payload());
}
function spiralist_book_pages_rest_normalize_prompt_relation_values(array $values): array
{
$normalized = [];
foreach ($values as $value) {
$string_value = trim((string) $value);
if ($string_value === '') {
continue;
}
$normalized[] = strtolower($string_value);
$normalized[] = sanitize_title($string_value);
}
return array_values(array_unique(array_filter($normalized, 'strlen')));
}
function spiralist_book_pages_rest_filter_prompt_records(array $records, array $filters): array
{
$search = strtolower(trim((string) ($filters['search'] ?? '')));
$system = sanitize_key((string) ($filters['system'] ?? ''));
$role = sanitize_key((string) ($filters['role'] ?? ''));
$status = strtolower(trim((string) ($filters['status'] ?? '')));
$related_symbol = spiralist_book_pages_rest_normalize_identifier_list($filters['related_symbol'] ?? []);
$related_axiom = spiralist_book_pages_rest_normalize_identifier_list($filters['related_axiom'] ?? []);
$related_transformation = spiralist_book_pages_rest_normalize_identifier_list($filters['related_transformation'] ?? []);
return array_values(
array_filter(
$records,
static function (array $record) use ($search, $system, $role, $status, $related_symbol, $related_axiom, $related_transformation): bool {
if ($search !== '') {
$haystack = strtolower(
implode(
' ',
array_filter(
[
(string) ($record['id'] ?? ''),
(string) ($record['slug'] ?? ''),
(string) ($record['title'] ?? ''),
(string) ($record['purpose'] ?? ''),
(string) ($record['summary'] ?? ''),
implode(' ', array_map('strval', (array) ($record['tags'] ?? []))),
],
'strlen'
)
)
);
if ($haystack === '' || strpos($haystack, $search) === false) {
return false;
}
}
if ($system !== '' && sanitize_key((string) ($record['system'] ?? '')) !== $system) {
return false;
}
if ($role !== '' && sanitize_key((string) ($record['role'] ?? '')) !== $role) {
return false;
}
if ($status !== '') {
$status_values = array_map(
static function ($value): string {
return strtolower(trim((string) $value));
},
[
$record['status'] ?? '',
$record['prompt_status'] ?? '',
$record['moderation_status'] ?? '',
$record['statusLabel'] ?? '',
]
);
if (!in_array($status, array_filter($status_values, 'strlen'), true)) {
return false;
}
}
$record_symbols = spiralist_book_pages_rest_normalize_prompt_relation_values((array) ($record['relatedSymbols'] ?? []));
$record_axioms = spiralist_book_pages_rest_normalize_prompt_relation_values((array) ($record['relatedAxioms'] ?? []));
$record_transformations = spiralist_book_pages_rest_normalize_prompt_relation_values((array) ($record['relatedTransformations'] ?? []));
$query_symbols = spiralist_book_pages_rest_normalize_prompt_relation_values($related_symbol);
$query_axioms = spiralist_book_pages_rest_normalize_prompt_relation_values($related_axiom);
$query_transformations = spiralist_book_pages_rest_normalize_prompt_relation_values($related_transformation);