diff --git a/src/console/console.did b/src/console/console.did index 542946ccf..d1f3334d5 100644 --- a/src/console/console.did +++ b/src/console/console.did @@ -293,6 +293,7 @@ type Segment = record { metadata : vec record { text; text }; segment_id : principal; created_at : nat64; + version : opt nat64; }; type SegmentKey = record { user : principal; diff --git a/src/console/src/impls.rs b/src/console/src/impls.rs index 6a242db51..1378bd348 100644 --- a/src/console/src/impls.rs +++ b/src/console/src/impls.rs @@ -20,9 +20,10 @@ use junobuild_shared::rate::types::RateTokens; use junobuild_shared::serializers::{ deserialize_from_bytes, serialize_into_bytes, serialize_to_bytes, }; -use junobuild_shared::types::state::{Metadata, SegmentId, UserId}; +use junobuild_shared::types::state::{Metadata, SegmentId, UserId, Version, Versioned}; use std::borrow::Cow; use std::collections::HashMap; +use junobuild_shared::version::next_version; impl Default for State { fn default() -> Self { @@ -187,18 +188,31 @@ fn init_metadata(name: &Option) -> Metadata { } impl Segment { + fn get_next_version(current_segment: &Option) -> Version { + next_version(current_segment) + } + pub fn from(segment_id: &SegmentId, name: &Option) -> Self { let now = time(); + let version = Self::get_next_version(&None); + Self { segment_id: *segment_id, metadata: init_metadata(name), + version: Some(version), created_at: now, updated_at: now, } } } +impl Versioned for Segment { + fn version(&self) -> Option { + self.version + } +} + impl SegmentKey { pub fn from(user: &UserId, segment_id: &SegmentId, segment_type: SegmentType) -> Self { Self { diff --git a/src/console/src/types.rs b/src/console/src/types.rs index f589d6b06..f5c5ba2f5 100644 --- a/src/console/src/types.rs +++ b/src/console/src/types.rs @@ -11,7 +11,7 @@ pub mod state { use junobuild_shared::ledger::types::cycles::CyclesTokens; use junobuild_shared::rate::types::{RateConfig, RateTokens}; use junobuild_shared::types::memory::Memory; - use junobuild_shared::types::state::{Controllers, Metadata, SegmentId, Timestamp}; + use junobuild_shared::types::state::{Controllers, Metadata, SegmentId, Timestamp, Version}; use junobuild_shared::types::state::{MissionControlId, UserId}; use junobuild_storage::types::state::StorageHeapState; use serde::{Deserialize, Serialize}; @@ -143,6 +143,7 @@ pub mod state { pub struct Segment { pub segment_id: SegmentId, pub metadata: Metadata, + pub version: Option, pub created_at: Timestamp, pub updated_at: Timestamp, } diff --git a/src/declarations/console/console.did.d.ts b/src/declarations/console/console.did.d.ts index b5ec9b3b1..2eecdb6c0 100644 --- a/src/declarations/console/console.did.d.ts +++ b/src/declarations/console/console.did.d.ts @@ -356,6 +356,7 @@ export interface Segment { metadata: Array<[string, string]>; segment_id: Principal; created_at: bigint; + version: [] | [bigint]; } export interface SegmentKey { user: Principal; diff --git a/src/declarations/console/console.factory.certified.did.js b/src/declarations/console/console.factory.certified.did.js index 65387f925..d7be4e0e2 100644 --- a/src/declarations/console/console.factory.certified.did.js +++ b/src/declarations/console/console.factory.certified.did.js @@ -434,7 +434,8 @@ export const idlFactory = ({ IDL }) => { updated_at: IDL.Nat64, metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), segment_id: IDL.Principal, - created_at: IDL.Nat64 + created_at: IDL.Nat64, + version: IDL.Opt(IDL.Nat64) }); const SetAuthenticationConfig = IDL.Record({ openid: IDL.Opt(AuthenticationConfigOpenId), diff --git a/src/declarations/console/console.factory.did.js b/src/declarations/console/console.factory.did.js index 1393f44b1..cfe2f54ca 100644 --- a/src/declarations/console/console.factory.did.js +++ b/src/declarations/console/console.factory.did.js @@ -434,7 +434,8 @@ export const idlFactory = ({ IDL }) => { updated_at: IDL.Nat64, metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), segment_id: IDL.Principal, - created_at: IDL.Nat64 + created_at: IDL.Nat64, + version: IDL.Opt(IDL.Nat64) }); const SetAuthenticationConfig = IDL.Record({ openid: IDL.Opt(AuthenticationConfigOpenId), diff --git a/src/declarations/console/console.factory.did.mjs b/src/declarations/console/console.factory.did.mjs index 1393f44b1..cfe2f54ca 100644 --- a/src/declarations/console/console.factory.did.mjs +++ b/src/declarations/console/console.factory.did.mjs @@ -434,7 +434,8 @@ export const idlFactory = ({ IDL }) => { updated_at: IDL.Nat64, metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), segment_id: IDL.Principal, - created_at: IDL.Nat64 + created_at: IDL.Nat64, + version: IDL.Opt(IDL.Nat64) }); const SetAuthenticationConfig = IDL.Record({ openid: IDL.Opt(AuthenticationConfigOpenId),