Skip to content

Commit

Permalink
fix(Rust): Use strings for digests
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Aug 29, 2021
1 parent 586529a commit df07e95
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
19 changes: 11 additions & 8 deletions rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ pub struct CodeExecutable {
pub text: String,

/// The SHA-256 digest of the `text`, `programmingLanguage` and `mediaType` properties the last time the node was compiled.
pub compile_digest: Option<[u8; 32]>,
#[serde(skip)]
pub compile_digest: Option<String>,

/// Duration in seconds of the last execution of the code.
pub duration: Option<Number>,
Expand All @@ -183,7 +184,7 @@ pub struct CodeExecutable {
pub errors: Option<Vec<CodeError>>,

/// The SHA-256 digest of `compileDigest` and the `executeDigest`s of all dependencies, the last time the node was executed.
pub execute_digest: Option<[u8; 32]>,
pub execute_digest: Option<String>,

/// The identifier for this item.
pub id: Option<Box<String>>,
Expand Down Expand Up @@ -218,7 +219,8 @@ pub struct CodeChunk {
pub caption: Option<Box<CodeChunkCaption>>,

/// The SHA-256 digest of the `text`, `programmingLanguage` and `mediaType` properties the last time the node was compiled.
pub compile_digest: Option<[u8; 32]>,
#[serde(skip)]
pub compile_digest: Option<String>,

/// Duration in seconds of the last execution of the code.
pub duration: Option<Number>,
Expand All @@ -227,7 +229,7 @@ pub struct CodeChunk {
pub errors: Option<Vec<CodeError>>,

/// The SHA-256 digest of `compileDigest` and the `executeDigest`s of all dependencies, the last time the node was executed.
pub execute_digest: Option<[u8; 32]>,
pub execute_digest: Option<String>,

/// The identifier for this item.
pub id: Option<Box<String>>,
Expand Down Expand Up @@ -265,7 +267,8 @@ pub struct CodeExpression {
pub text: String,

/// The SHA-256 digest of the `text`, `programmingLanguage` and `mediaType` properties the last time the node was compiled.
pub compile_digest: Option<[u8; 32]>,
#[serde(skip)]
pub compile_digest: Option<String>,

/// Duration in seconds of the last execution of the code.
pub duration: Option<Number>,
Expand All @@ -274,7 +277,7 @@ pub struct CodeExpression {
pub errors: Option<Vec<CodeError>>,

/// The SHA-256 digest of `compileDigest` and the `executeDigest`s of all dependencies, the last time the node was executed.
pub execute_digest: Option<[u8; 32]>,
pub execute_digest: Option<String>,

/// The identifier for this item.
pub id: Option<Box<String>>,
Expand Down Expand Up @@ -2282,7 +2285,7 @@ pub struct Include {
pub source: String,

/// The SHA-256 digest of the `source` and `mediaType` properties the last time the node was built.
pub build_digest: Option<[u8; 32]>,
pub build_digest: Option<String>,

/// The structured content decoded from the source.
pub content: Option<Vec<BlockContent>>,
Expand Down Expand Up @@ -2766,7 +2769,7 @@ pub struct Parameter {
pub default: Option<Box<Node>>,

/// The SHA-256 digest of the `value` property the last time the node was executed.
pub execute_digest: Option<[u8; 32]>,
pub execute_digest: Option<String>,

/// The identifier for this item.
pub id: Option<Box<String>>,
Expand Down
16 changes: 11 additions & 5 deletions ts/bindings/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const propertyAttributes: Record<string, string[]> = {
],
// Skip serializing the compile digest since the results of compiling
// are not stored with the node (at present) and so always need recompiling.
// This is not true to `executeDigest`, for example `CodeChunk.outputs` are the
// result of execution.
'*.compileDigest': ['#[serde(skip)]'],
}

Expand All @@ -67,10 +69,11 @@ const propertyTypes: Record<string, string> = {
'ArrayValidator.maxItems': 'u32',
'StringValidator.minLength': 'u32',
'StringValidator.maxLength': 'u32',
// SHA-256 digests are most efficiently represented as 32 bytes
'*.compileDigest': '[u8; 32]',
'*.buildDigest': '[u8; 32]',
'*.executeDigest': '[u8; 32]',
// SHA-256 digests are most efficiently represented as 32 bytes but
// for readability when serialized we use a string.
'*.compileDigest': 'String',
'*.buildDigest': 'String',
'*.executeDigest': 'String',
}

// Types that should not get automatically boxed if the property is
Expand Down Expand Up @@ -258,7 +261,10 @@ export function interfaceSchemaToStruct(
pointerProperties.includes(propertyPath) ||
pointerProperties.includes(`*.${name}`)

let attrs = propertyAttributes[propertyPath] ?? []
let attrs =
propertyAttributes[propertyPath] ??
propertyAttributes[`*.${name}`] ??
[]
if (isPointer) attrs = [...attrs, '#[serde(skip)]']

let type = propertyTypes[propertyPath] ?? propertyTypes[`*.${name}`]
Expand Down

0 comments on commit df07e95

Please sign in to comment.