@@ -46,30 +46,111 @@ extern "C" {
4646// Enumerations for Data Types and Attributes
4747// *****************************************************************************
4848
49- // ===========================================================
50- // NoShell Error Codes
51- // ===========================================================
49+ /* *
50+ * ===========================================================
51+ * NoShell Error Codes
52+ * ===========================================================
53+ * Enumerates all possible error codes returned by NoShell API functions.
54+ * These codes represent various failure and success states encountered
55+ * during database operations such as file handling, queries, concurrency,
56+ * permissions, backup/restore, and parsing.
57+ */
5258typedef enum {
53- FOSSIL_NOSHELL_ERROR_SUCCESS = 0 ,
54- FOSSIL_NOSHELL_ERROR_INVALID_FILE,
55- FOSSIL_NOSHELL_ERROR_FILE_NOT_FOUND,
56- FOSSIL_NOSHELL_ERROR_IO,
57- FOSSIL_NOSHELL_ERROR_INVALID_QUERY,
58- FOSSIL_NOSHELL_ERROR_CONCURRENCY,
59- FOSSIL_NOSHELL_ERROR_NOT_FOUND,
60- FOSSIL_NOSHELL_ERROR_PERMISSION_DENIED,
61- FOSSIL_NOSHELL_ERROR_CORRUPTED,
62- FOSSIL_NOSHELL_ERROR_OUT_OF_MEMORY,
63- FOSSIL_NOSHELL_ERROR_UNSUPPORTED,
64- FOSSIL_NOSHELL_ERROR_LOCKED,
65- FOSSIL_NOSHELL_ERROR_TIMEOUT,
66- FOSSIL_NOSHELL_ERROR_ALREADY_EXISTS,
67- FOSSIL_NOSHELL_ERROR_BACKUP_FAILED,
68- FOSSIL_NOSHELL_ERROR_PARSE_FAILED,
69- FOSSIL_NOSHELL_ERROR_RESTORE_FAILED,
70- FOSSIL_NOSHELL_ERROR_UNKNOWN
59+ FOSSIL_NOSHELL_ERROR_SUCCESS = 0 , /* *< Operation completed successfully. */
60+ FOSSIL_NOSHELL_ERROR_INVALID_FILE, /* *< The specified file is invalid or corrupt. */
61+ FOSSIL_NOSHELL_ERROR_FILE_NOT_FOUND, /* *< The requested file was not found. */
62+ FOSSIL_NOSHELL_ERROR_IO, /* *< Input/output error occurred during operation. */
63+ FOSSIL_NOSHELL_ERROR_INVALID_QUERY, /* *< The query provided is invalid or malformed. */
64+ FOSSIL_NOSHELL_ERROR_CONCURRENCY, /* *< Concurrency conflict detected (e.g., locked resource). */
65+ FOSSIL_NOSHELL_ERROR_NOT_FOUND, /* *< Requested key or record not found in database. */
66+ FOSSIL_NOSHELL_ERROR_PERMISSION_DENIED, /* *< Operation denied due to insufficient permissions. */
67+ FOSSIL_NOSHELL_ERROR_CORRUPTED, /* *< Database or file is corrupted. */
68+ FOSSIL_NOSHELL_ERROR_OUT_OF_MEMORY, /* *< Memory allocation failed. */
69+ FOSSIL_NOSHELL_ERROR_UNSUPPORTED, /* *< Operation or feature is not supported. */
70+ FOSSIL_NOSHELL_ERROR_LOCKED, /* *< Resource is locked and cannot be accessed. */
71+ FOSSIL_NOSHELL_ERROR_TIMEOUT, /* *< Operation timed out. */
72+ FOSSIL_NOSHELL_ERROR_ALREADY_EXISTS, /* *< Resource already exists (e.g., duplicate key). */
73+ FOSSIL_NOSHELL_ERROR_BACKUP_FAILED, /* *< Backup operation failed. */
74+ FOSSIL_NOSHELL_ERROR_PARSE_FAILED, /* *< Parsing of input or file failed. */
75+ FOSSIL_NOSHELL_ERROR_RESTORE_FAILED, /* *< Restore operation failed. */
76+ FOSSIL_NOSHELL_ERROR_LOCK_FAILED, /* *< Failed to acquire or release lock. */
77+ FOSSIL_NOSHELL_ERROR_SCHEMA_MISMATCH, /* *< Schema or format mismatch between versions. */
78+ FOSSIL_NOSHELL_ERROR_VERSION_UNSUPPORTED, /* *< Database created with unsupported version. */
79+ FOSSIL_NOSHELL_ERROR_INDEX_CORRUPTED, /* *< Index structure corrupted or unreadable. */
80+ FOSSIL_NOSHELL_ERROR_INTEGRITY, /* *< Data integrity check failed (hash mismatch). */
81+ FOSSIL_NOSHELL_ERROR_TRANSACTION_FAILED, /* *< Transaction aborted or rolled back. */
82+ FOSSIL_NOSHELL_ERROR_CAPACITY_EXCEEDED, /* *< Reached maximum size or record capacity. */
83+ FOSSIL_NOSHELL_ERROR_BUFFER_TOO_SMALL, /* *< Provided buffer is too small for operation. */
84+ FOSSIL_NOSHELL_ERROR_INVALID_TYPE, /* *< Invalid or unrecognized data type specified. */
85+ FOSSIL_NOSHELL_ERROR_CONFIG_INVALID, /* *< Invalid configuration or options. */
86+ FOSSIL_NOSHELL_ERROR_UNKNOWN /* *< Unknown or unspecified error occurred. */
7187} fossil_bluecrab_noshell_error_t ;
7288
89+ // ============================================================================
90+ // FSON v2 compatible value representation (local to NoShell)
91+ // ============================================================================
92+ typedef enum {
93+ NOSHELL_FSON_TYPE_NULL = 0 ,
94+ NOSHELL_FSON_TYPE_BOOL,
95+
96+ // Scalars
97+ NOSHELL_FSON_TYPE_I8,
98+ NOSHELL_FSON_TYPE_I16,
99+ NOSHELL_FSON_TYPE_I32,
100+ NOSHELL_FSON_TYPE_I64,
101+ NOSHELL_FSON_TYPE_U8,
102+ NOSHELL_FSON_TYPE_U16,
103+ NOSHELL_FSON_TYPE_U32,
104+ NOSHELL_FSON_TYPE_U64,
105+ NOSHELL_FSON_TYPE_F32,
106+ NOSHELL_FSON_TYPE_F64,
107+
108+ // Literals
109+ NOSHELL_FSON_TYPE_OCT,
110+ NOSHELL_FSON_TYPE_HEX,
111+ NOSHELL_FSON_TYPE_BIN,
112+
113+ // Strings
114+ NOSHELL_FSON_TYPE_CHAR,
115+ NOSHELL_FSON_TYPE_CSTR,
116+
117+ // Composite
118+ NOSHELL_FSON_TYPE_ARRAY,
119+ NOSHELL_FSON_TYPE_OBJECT,
120+
121+ // v2 Additions
122+ NOSHELL_FSON_TYPE_ENUM,
123+ NOSHELL_FSON_TYPE_DATETIME,
124+ NOSHELL_FSON_TYPE_DURATION
125+ } fossil_bluecrab_noshell_fson_type_t ;
126+
127+ typedef struct {
128+ fossil_bluecrab_noshell_fson_type_t type;
129+ union {
130+ bool b;
131+ int8_t i8 ;
132+ int16_t i16 ;
133+ int32_t i32 ;
134+ int64_t i64 ;
135+ uint8_t u8 ;
136+ uint16_t u16 ;
137+ uint32_t u32 ;
138+ uint64_t u64 ;
139+ float f32 ;
140+ double f64 ;
141+ char *oct;
142+ char *hex;
143+ char *bin;
144+ char c;
145+ char *cstr;
146+ char *array;
147+ char *object;
148+ char *enum_symbol;
149+ char *datetime;
150+ char *duration;
151+ } as;
152+ } fossil_bluecrab_noshell_fson_value_t ;
153+
73154// ===========================================================
74155// Document CRUD Operations
75156// ===========================================================
@@ -79,20 +160,24 @@ typedef enum {
79160 *
80161 * @param file_name The database file name (.crabdb enforced).
81162 * @param document The document string to insert.
163+ * @param param_list Optional FSON parameter list for structured data (can be NULL).
164+ * @param type Document type as string parameter.
82165 * @return FOSSIL_NOSHELL_ERROR_SUCCESS on success, otherwise error code.
83166 */
84- fossil_bluecrab_noshell_error_t fossil_bluecrab_noshell_insert (const char *file_name, const char *document);
167+ fossil_bluecrab_noshell_error_t fossil_bluecrab_noshell_insert (const char *file_name, const char *document, const char *param_list, const char *type );
85168
86169/* *
87170 * @brief Inserts a document and returns a unique internal ID.
88171 *
89172 * @param file_name The database file name (.crabdb enforced).
90173 * @param document The document string to insert.
174+ * @param param_list Optional FSON parameter list for structured data (can be NULL).
175+ * @param type Document type as string parameter.
91176 * @param out_id Buffer to store generated document ID.
92177 * @param id_size Size of the buffer.
93178 * @return FOSSIL_NOSHELL_ERROR_SUCCESS on success, otherwise error code.
94179 */
95- fossil_bluecrab_noshell_error_t fossil_bluecrab_noshell_insert_with_id (const char *file_name, const char *document, char *out_id, size_t id_size);
180+ fossil_bluecrab_noshell_error_t fossil_bluecrab_noshell_insert_with_id (const char *file_name, const char *document, const char *param_list, const char *type, char *out_id, size_t id_size);
96181
97182/* *
98183 * @brief Finds a document based on a query string.
@@ -101,9 +186,10 @@ fossil_bluecrab_noshell_error_t fossil_bluecrab_noshell_insert_with_id(const cha
101186 * @param query The query string to search.
102187 * @param result Buffer to store the matching document.
103188 * @param buffer_size Size of the buffer.
189+ * @param type_id Optional type id parameter.
104190 * @return FOSSIL_NOSHELL_ERROR_SUCCESS on success, otherwise error code.
105191 */
106- fossil_bluecrab_noshell_error_t fossil_bluecrab_noshell_find (const char *file_name, const char *query, char *result, size_t buffer_size);
192+ fossil_bluecrab_noshell_error_t fossil_bluecrab_noshell_find (const char *file_name, const char *query, char *result, size_t buffer_size, const char *type_id );
107193
108194/* *
109195 * @brief Finds documents using a callback filter function.
@@ -121,9 +207,11 @@ fossil_bluecrab_noshell_error_t fossil_bluecrab_noshell_find_cb(const char *file
121207 * @param file_name The database file name.
122208 * @param query Query string to locate document(s).
123209 * @param new_document New document content to replace matching documents.
210+ * @param param_list Optional FSON parameter list for structured data (can be NULL).
211+ * @param type_id Optional type id parameter.
124212 * @return FOSSIL_NOSHELL_ERROR_SUCCESS on success, otherwise error code.
125213 */
126- fossil_bluecrab_noshell_error_t fossil_bluecrab_noshell_update (const char *file_name, const char *query, const char *new_document);
214+ fossil_bluecrab_noshell_error_t fossil_bluecrab_noshell_update (const char *file_name, const char *query, const char *new_document, const char *param_list, const char *type_id );
127215
128216/* *
129217 * @brief Removes a document from the database based on a query string.
@@ -303,22 +391,30 @@ namespace fossil {
303391 * @brief Inserts a new document into the database.
304392 * @param file_name The database file name (.crabdb enforced).
305393 * @param document The document string to insert.
394+ * @param param_list Optional FSON parameter list for structured data (can be empty).
395+ * @param type Document type as string parameter (can be empty).
306396 * @return FOSSIL_NOSHELL_ERROR_SUCCESS on success, otherwise error code.
307397 */
308- static fossil_bluecrab_noshell_error_t insert (const std::string& file_name, const std::string& document) {
309- return fossil_bluecrab_noshell_insert (file_name.c_str (), document.c_str ());
398+ static fossil_bluecrab_noshell_error_t insert (const std::string& file_name, const std::string& document, const std::string& param_list = " " , const std::string& type = " " ) {
399+ const char * param = param_list.empty () ? nullptr : param_list.c_str ();
400+ const char * type_str = type.empty () ? nullptr : type.c_str ();
401+ return fossil_bluecrab_noshell_insert (file_name.c_str (), document.c_str (), param, type_str);
310402 }
311403
312404 /* *
313405 * @brief Inserts a document and returns a unique internal ID.
314406 * @param file_name The database file name (.crabdb enforced).
315407 * @param document The document string to insert.
408+ * @param param_list Optional FSON parameter list for structured data (can be empty).
409+ * @param type Document type as string parameter (can be empty).
316410 * @param out_id Reference to a string to store the generated document ID.
317411 * @return FOSSIL_NOSHELL_ERROR_SUCCESS on success, otherwise error code.
318412 */
319- static fossil_bluecrab_noshell_error_t insert_with_id (const std::string& file_name, const std::string& document, std::string& out_id) {
413+ static fossil_bluecrab_noshell_error_t insert_with_id (const std::string& file_name, const std::string& document, const std::string& param_list, const std::string& type, std::string& out_id) {
320414 char buffer[128 ] = {0 };
321- fossil_bluecrab_noshell_error_t err = fossil_bluecrab_noshell_insert_with_id (file_name.c_str (), document.c_str (), buffer, sizeof (buffer));
415+ const char * param = param_list.empty () ? nullptr : param_list.c_str ();
416+ const char * type_str = type.empty () ? nullptr : type.c_str ();
417+ fossil_bluecrab_noshell_error_t err = fossil_bluecrab_noshell_insert_with_id (file_name.c_str (), document.c_str (), param, type_str, buffer, sizeof (buffer));
322418 if (err == FOSSIL_NOSHELL_ERROR_SUCCESS) {
323419 out_id = buffer;
324420 }
@@ -330,11 +426,13 @@ namespace fossil {
330426 * @param file_name The database file name.
331427 * @param query The query string to search.
332428 * @param result Reference to a string to store the matching document.
429+ * @param type_id Optional type id parameter (can be empty).
333430 * @return FOSSIL_NOSHELL_ERROR_SUCCESS on success, otherwise error code.
334431 */
335- static fossil_bluecrab_noshell_error_t find (const std::string& file_name, const std::string& query, std::string& result) {
432+ static fossil_bluecrab_noshell_error_t find (const std::string& file_name, const std::string& query, std::string& result, const std::string& type_id = " " ) {
336433 char buffer[4096 ] = {0 };
337- fossil_bluecrab_noshell_error_t err = fossil_bluecrab_noshell_find (file_name.c_str (), query.c_str (), buffer, sizeof (buffer));
434+ const char * type_str = type_id.empty () ? nullptr : type_id.c_str ();
435+ fossil_bluecrab_noshell_error_t err = fossil_bluecrab_noshell_find (file_name.c_str (), query.c_str (), buffer, sizeof (buffer), type_str);
338436 if (err == FOSSIL_NOSHELL_ERROR_SUCCESS) {
339437 result = buffer;
340438 }
@@ -346,10 +444,14 @@ namespace fossil {
346444 * @param file_name The database file name.
347445 * @param query Query string to locate document(s).
348446 * @param new_document New document content to replace matching documents.
447+ * @param param_list Optional FSON parameter list for structured data (can be empty).
448+ * @param type_id Optional type id parameter (can be empty).
349449 * @return FOSSIL_NOSHELL_ERROR_SUCCESS on success, otherwise error code.
350450 */
351- static fossil_bluecrab_noshell_error_t update (const std::string& file_name, const std::string& query, const std::string& new_document) {
352- return fossil_bluecrab_noshell_update (file_name.c_str (), query.c_str (), new_document.c_str ());
451+ static fossil_bluecrab_noshell_error_t update (const std::string& file_name, const std::string& query, const std::string& new_document, const std::string& param_list = " " , const std::string& type_id = " " ) {
452+ const char * param = param_list.empty () ? nullptr : param_list.c_str ();
453+ const char * type_str = type_id.empty () ? nullptr : type_id.c_str ();
454+ return fossil_bluecrab_noshell_update (file_name.c_str (), query.c_str (), new_document.c_str (), param, type_str);
353455 }
354456
355457 /* *
0 commit comments