Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/console/console.did
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 15 additions & 1 deletion src/console/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -187,18 +188,31 @@ fn init_metadata(name: &Option<String>) -> Metadata {
}

impl Segment {
fn get_next_version(current_segment: &Option<Segment>) -> Version {
next_version(current_segment)
}

pub fn from(segment_id: &SegmentId, name: &Option<String>) -> 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<Version> {
self.version
}
}

impl SegmentKey {
pub fn from(user: &UserId, segment_id: &SegmentId, segment_type: SegmentType) -> Self {
Self {
Expand Down
3 changes: 2 additions & 1 deletion src/console/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -143,6 +143,7 @@ pub mod state {
pub struct Segment {
pub segment_id: SegmentId,
pub metadata: Metadata,
pub version: Option<Version>,
pub created_at: Timestamp,
pub updated_at: Timestamp,
}
Expand Down
1 change: 1 addition & 0 deletions src/declarations/console/console.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ export interface Segment {
metadata: Array<[string, string]>;
segment_id: Principal;
created_at: bigint;
version: [] | [bigint];
}
export interface SegmentKey {
user: Principal;
Expand Down
3 changes: 2 additions & 1 deletion src/declarations/console/console.factory.certified.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion src/declarations/console/console.factory.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion src/declarations/console/console.factory.did.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading