88#include < sourcemeta/blaze/output.h>
99
1010#include < sourcemeta/one/shared.h>
11- #include < sourcemeta/one/storage.h>
1211
1312#include " helpers.h"
1413#include " request.h"
1514#include " response.h"
1615
1716#include < cassert> // assert
17+ #include < filesystem> // std::filesystem::path
1818#include < sstream> // std::ostringstream
19- #include < string> // std::string
2019#include < string_view> // std::string_view
2120#include < type_traits> // std::underlying_type_t
2221#include < utility> // std::move
@@ -25,14 +24,14 @@ namespace {
2524
2625auto trace (sourcemeta::blaze::Evaluator &evaluator,
2726 const sourcemeta::blaze::Template &schema_template,
28- const std::string &instance, const sourcemeta::one::Storage &storage,
29- const sourcemeta::one::Storage::Key template_key )
27+ const std::string &instance,
28+ const std::filesystem::path &template_path )
3029 -> sourcemeta::core::JSON {
3130 auto steps{sourcemeta::core::JSON::make_array ()};
3231
32+ auto locations_path{template_path.parent_path () / " locations.metapack" };
3333 // TODO: Cache this across runs?
34- const auto locations{
35- storage.read_sibling_json (template_key, " locations.metapack" )};
34+ const auto locations{sourcemeta::one::read_json (locations_path)};
3635 assert (locations.defines (" static" ));
3736 const auto &static_locations{locations.at (" static" )};
3837
@@ -121,13 +120,15 @@ namespace sourcemeta::one {
121120
122121enum class EvaluateType { Standard, Trace };
123122
124- auto evaluate (const Storage &storage, const Storage::Key template_key ,
123+ auto evaluate (const std::filesystem::path &template_path ,
125124 const std::string &instance, const EvaluateType type)
126125 -> sourcemeta::core::JSON {
126+ assert (std::filesystem::exists (template_path));
127+
127128 // TODO: Cache this conversion across runs, potentially using the schema file
128129 // "checksum" as the cache key. This is important as the template might be
129130 // compressed
130- const auto template_json{storage. read_json (template_key )};
131+ const auto template_json{read_json (template_path )};
131132 const auto schema_template{sourcemeta::blaze::from_json (template_json)};
132133 assert (schema_template.has_value ());
133134
@@ -140,8 +141,7 @@ auto evaluate(const Storage &storage, const Storage::Key template_key,
140141 sourcemeta::core::parse_json (instance),
141142 sourcemeta::blaze::StandardOutput::Basic);
142143 case EvaluateType::Trace:
143- return trace (evaluator, schema_template.value (), instance, storage,
144- template_key);
144+ return trace (evaluator, schema_template.value (), instance, template_path);
145145 default :
146146 // We should never get here
147147 assert (false );
@@ -151,13 +151,12 @@ auto evaluate(const Storage &storage, const Storage::Key template_key,
151151
152152} // namespace sourcemeta::one
153153
154- static auto action_jsonschema_evaluate_callback (
155- const sourcemeta::one::Storage &storage,
156- const sourcemeta::one::Storage::Key template_key,
157- const sourcemeta::one::EvaluateType mode,
158- sourcemeta::one::HTTPRequest &request,
159- sourcemeta::one::HTTPResponse &response, std::string &&body, bool too_big)
160- -> void {
154+ static auto
155+ action_jsonschema_evaluate_callback (const std::filesystem::path &template_path,
156+ const sourcemeta::one::EvaluateType mode,
157+ sourcemeta::one::HTTPRequest &request,
158+ sourcemeta::one::HTTPResponse &response,
159+ std::string &&body, bool too_big) -> void {
161160 if (too_big) {
162161 json_error (request, response, sourcemeta::one::STATUS_PAYLOAD_TOO_LARGE,
163162 " payload-too-large" , " The request body is too large" );
@@ -171,8 +170,7 @@ static auto action_jsonschema_evaluate_callback(
171170 }
172171
173172 try {
174- const auto result{
175- sourcemeta::one::evaluate (storage, template_key, body, mode)};
173+ const auto result{sourcemeta::one::evaluate (template_path, body, mode)};
176174 response.write_status (sourcemeta::one::STATUS_OK);
177175 response.write_header (" Content-Type" , " application/json" );
178176 response.write_header (" Access-Control-Allow-Origin" , " *" );
@@ -194,7 +192,7 @@ static auto action_jsonschema_evaluate_callback(
194192 }
195193}
196194
197- static auto action_jsonschema_evaluate (const sourcemeta::one::Storage &storage ,
195+ static auto action_jsonschema_evaluate (const std::filesystem::path &base ,
198196 const std::string_view &path,
199197 sourcemeta::one::HTTPRequest &request,
200198 sourcemeta::one::HTTPResponse &response,
@@ -209,10 +207,13 @@ static auto action_jsonschema_evaluate(const sourcemeta::one::Storage &storage,
209207 response.write_header (" Access-Control-Max-Age" , " 3600" );
210208 send_response (sourcemeta::one::STATUS_NO_CONTENT, request, response);
211209 } else if (request.method () == " post" ) {
212- const auto template_key{sourcemeta::one::Storage::key (
213- " schemas" , path, SENTINEL, " blaze-exhaustive.metapack" )};
214- if (!storage.exists (template_key)) {
215- if (storage.sibling_exists (template_key, " schema.metapack" )) {
210+ auto template_path{base / " schemas" };
211+ template_path /= path;
212+ template_path /= SENTINEL;
213+ template_path /= " blaze-exhaustive.metapack" ;
214+ if (!std::filesystem::exists (template_path)) {
215+ const auto schema_path{template_path.parent_path () / " schema.metapack" };
216+ if (std::filesystem::exists (schema_path)) {
216217 json_error (request, response,
217218 sourcemeta::one::STATUS_METHOD_NOT_ALLOWED, " no-template" ,
218219 " This schema was not precompiled for schema evaluation" );
@@ -225,12 +226,12 @@ static auto action_jsonschema_evaluate(const sourcemeta::one::Storage &storage,
225226 }
226227
227228 request.body (
228- [mode, &storage,
229- template_key]( sourcemeta::one::HTTPRequest &callback_request,
230- sourcemeta::one::HTTPResponse &callback_response,
231- std::string &&body, bool too_big) {
229+ [mode, template_path = std::move (template_path)](
230+ sourcemeta::one::HTTPRequest &callback_request,
231+ sourcemeta::one::HTTPResponse &callback_response,
232+ std::string &&body, bool too_big) {
232233 action_jsonschema_evaluate_callback (
233- storage, template_key , mode, callback_request, callback_response,
234+ template_path , mode, callback_request, callback_response,
234235 std::move (body), too_big);
235236 },
236237 [](sourcemeta::one::HTTPRequest &callback_request,
0 commit comments