@@ -13,9 +13,12 @@ use std::ptr;
1313
1414use alloc:: boxed:: Box ;
1515
16+ use spacetimedb_primitives:: { ColId , TableId } ;
17+
1618/// Provides a raw set of sys calls which abstractions can be built atop of.
1719pub mod raw {
1820 use core:: mem:: ManuallyDrop ;
21+ use spacetimedb_primitives:: { ColId , TableId } ;
1922
2023 // this module identifier determines the abi version that modules built with this crate depend
2124 // on. Any non-breaking additions to the abi surface should be put in a new `extern {}` block
@@ -33,7 +36,7 @@ pub mod raw {
3336 name_len: usize,
3437 schema: *const u8,
3538 schema_len: usize,
36- out: *mut u32 ,
39+ out: *mut TableId ,
3740 ) -> u16;
3841 */
3942
@@ -47,7 +50,7 @@ pub mod raw {
4750 /// - the slice `(name, name_len)` is not valid UTF-8
4851 /// - `name + name_len` overflows a 64-bit address.
4952 /// - writing to `out` overflows a 32-bit integer
50- pub fn _get_table_id ( name : * const u8 , name_len : usize , out : * mut u32 ) -> u16 ;
53+ pub fn _get_table_id ( name : * const u8 , name_len : usize , out : * mut TableId ) -> u16 ;
5154
5255 /// Creates an index with the name `index_name` and type `index_type`,
5356 /// on a product of the given columns in `col_ids`
@@ -69,7 +72,7 @@ pub mod raw {
6972 pub fn _create_index (
7073 index_name : * const u8 ,
7174 index_name_len : usize ,
72- table_id : u32 ,
75+ table_id : TableId ,
7376 index_type : u8 ,
7477 col_ids : * const u8 ,
7578 col_len : usize ,
@@ -92,7 +95,13 @@ pub mod raw {
9295 /// - `(val, val_len)` cannot be decoded to an `AlgebraicValue`
9396 /// typed at the `AlgebraicType` of the column,
9497 /// - `val + val_len` overflows a 64-bit integer
95- pub fn _iter_by_col_eq ( table_id : u32 , col_id : u32 , val : * const u8 , val_len : usize , out : * mut Buffer ) -> u16 ;
98+ pub fn _iter_by_col_eq (
99+ table_id : TableId ,
100+ col_id : ColId ,
101+ val : * const u8 ,
102+ val_len : usize ,
103+ out : * mut Buffer ,
104+ ) -> u16 ;
96105
97106 /// Inserts a row into the table identified by `table_id`,
98107 /// where the row is read from the byte slice `row` in WASM memory,
@@ -109,7 +118,7 @@ pub mod raw {
109118 /// - `row + row_len` overflows a 64-bit integer
110119 /// - `(row, row_len)` doesn't decode from BSATN to a `ProductValue`
111120 /// according to the `ProductType` that the table's schema specifies.
112- pub fn _insert ( table_id : u32 , row : * mut u8 , row_len : usize ) -> u16 ;
121+ pub fn _insert ( table_id : TableId , row : * mut u8 , row_len : usize ) -> u16 ;
113122
114123 /// Deletes all rows in the table identified by `table_id`
115124 /// where the column identified by `col_id` matches the byte string,
@@ -128,7 +137,13 @@ pub mod raw {
128137 /// according to the `AlgebraicType` that the table's schema specifies for `col_id`.
129138 /// - `value + value_len` overflows a 64-bit integer
130139 /// - writing to `out` would overflow a 32-bit integer
131- pub fn _delete_by_col_eq ( table_id : u32 , col_id : u32 , value : * const u8 , value_len : usize , out : * mut u32 ) -> u16 ;
140+ pub fn _delete_by_col_eq (
141+ table_id : TableId ,
142+ col_id : ColId ,
143+ value : * const u8 ,
144+ value_len : usize ,
145+ out : * mut u32 ,
146+ ) -> u16 ;
132147
133148 /// Start iteration on each row, as bytes, of a table identified by `table_id`.
134149 ///
@@ -137,7 +152,7 @@ pub mod raw {
137152 ///
138153 /// Returns an error if
139154 /// - a table with the provided `table_id` doesn't exist
140- pub fn _iter_start ( table_id : u32 , out : * mut BufferIter ) -> u16 ;
155+ pub fn _iter_start ( table_id : TableId , out : * mut BufferIter ) -> u16 ;
141156
142157 /// Like [`_iter_start`], start iteration on each row,
143158 /// as bytes, of a table identified by `table_id`.
@@ -152,7 +167,12 @@ pub mod raw {
152167 /// - a table with the provided `table_id` doesn't exist
153168 /// - `(filter, filter_len)` doesn't decode to a filter expression
154169 /// - `filter + filter_len` overflows a 64-bit integer
155- pub fn _iter_start_filtered ( table_id : u32 , filter : * const u8 , filter_len : usize , out : * mut BufferIter ) -> u16 ;
170+ pub fn _iter_start_filtered (
171+ table_id : TableId ,
172+ filter : * const u8 ,
173+ filter_len : usize ,
174+ out : * mut BufferIter ,
175+ ) -> u16 ;
156176
157177 /// Advances the registered iterator with the index given by `iter_key`.
158178 ///
@@ -471,7 +491,7 @@ unsafe fn call<T>(f: impl FnOnce(*mut T) -> u16) -> Result<T, Errno> {
471491///
472492/// Returns an error if the table does not exist.
473493#[ inline]
474- pub fn get_table_id ( name : & str ) -> Result < u32 , Errno > {
494+ pub fn get_table_id ( name : & str ) -> Result < TableId , Errno > {
475495 unsafe { call ( |out| raw:: _get_table_id ( name. as_ptr ( ) , name. len ( ) , out) ) }
476496}
477497
@@ -488,7 +508,7 @@ pub fn get_table_id(name: &str) -> Result<u32, Errno> {
488508///
489509/// Traps if `index_type == 1` or `col_ids.len() != 1`.
490510#[ inline]
491- pub fn create_index ( index_name : & str , table_id : u32 , index_type : u8 , col_ids : & [ u8 ] ) -> Result < ( ) , Errno > {
511+ pub fn create_index ( index_name : & str , table_id : TableId , index_type : u8 , col_ids : & [ u8 ] ) -> Result < ( ) , Errno > {
492512 cvt ( unsafe {
493513 raw:: _create_index (
494514 index_name. as_ptr ( ) ,
@@ -518,7 +538,7 @@ pub fn create_index(index_name: &str, table_id: u32, index_type: u8, col_ids: &[
518538/// - `val` cannot be BSATN-decoded to an `AlgebraicValue`
519539/// typed at the `AlgebraicType` of the column
520540#[ inline]
521- pub fn iter_by_col_eq ( table_id : u32 , col_id : u32 , val : & [ u8 ] ) -> Result < Buffer , Errno > {
541+ pub fn iter_by_col_eq ( table_id : TableId , col_id : ColId , val : & [ u8 ] ) -> Result < Buffer , Errno > {
522542 unsafe { call ( |out| raw:: _iter_by_col_eq ( table_id, col_id, val. as_ptr ( ) , val. len ( ) , out) ) }
523543}
524544
@@ -535,7 +555,7 @@ pub fn iter_by_col_eq(table_id: u32, col_id: u32, val: &[u8]) -> Result<Buffer,
535555/// - `row` doesn't decode from BSATN to a `ProductValue`
536556/// according to the `ProductType` that the table's schema specifies.
537557#[ inline]
538- pub fn insert ( table_id : u32 , row : & mut [ u8 ] ) -> Result < ( ) , Errno > {
558+ pub fn insert ( table_id : TableId , row : & mut [ u8 ] ) -> Result < ( ) , Errno > {
539559 cvt ( unsafe { raw:: _insert ( table_id, row. as_mut_ptr ( ) , row. len ( ) ) } )
540560}
541561
@@ -552,7 +572,7 @@ pub fn insert(table_id: u32, row: &mut [u8]) -> Result<(), Errno> {
552572/// - no columns were deleted
553573/// - `col_id` does not identify a column of the table
554574#[ inline]
555- pub fn delete_by_col_eq ( table_id : u32 , col_id : u32 , value : & [ u8 ] ) -> Result < u32 , Errno > {
575+ pub fn delete_by_col_eq ( table_id : TableId , col_id : ColId , value : & [ u8 ] ) -> Result < u32 , Errno > {
556576 unsafe { call ( |out| raw:: _delete_by_col_eq ( table_id, col_id, value. as_ptr ( ) , value. len ( ) , out) ) }
557577}
558578
@@ -568,7 +588,7 @@ pub fn delete_by_col_eq(table_id: u32, col_id: u32, value: &[u8]) -> Result<u32,
568588/// - a table with the provided `table_id` doesn't exist
569589/// - `Some(filter)` doesn't decode to a filter expression
570590#[ inline]
571- pub fn iter ( table_id : u32 , filter : Option < & [ u8 ] > ) -> Result < BufferIter , Errno > {
591+ pub fn iter ( table_id : TableId , filter : Option < & [ u8 ] > ) -> Result < BufferIter , Errno > {
572592 unsafe {
573593 call ( |out| match filter {
574594 None => raw:: _iter_start ( table_id, out) ,
0 commit comments