diff --git a/src/frontend/src/lib/api/satellites.api.ts b/src/frontend/src/lib/api/satellites.api.ts index 4a759f88b..a7a177ca3 100644 --- a/src/frontend/src/lib/api/satellites.api.ts +++ b/src/frontend/src/lib/api/satellites.api.ts @@ -8,8 +8,7 @@ import type { RulesType, SetRule } from '$declarations/satellite/satellite.did'; -import type { MemoryText, PermissionText } from '$lib/constants/rules.constants'; -import { MemoryHeap } from '$lib/constants/rules.constants'; +import { MemoryStable, type MemoryText, type PermissionText } from '$lib/constants/rules.constants'; import type { CustomDomains } from '$lib/types/custom-domain'; import type { OptionIdentity } from '$lib/types/itentity'; import type { ListParams } from '$lib/types/list'; @@ -90,7 +89,9 @@ export const setRule = async ({ write: permissionFromText(write), updated_at: isNullish(rule) ? [] : [rule.updated_at], max_size: toNullable(nonNullish(maxSize) && maxSize > 0 ? BigInt(maxSize) : undefined), - memory: isNullish(rule) ? [memoryFromText(memory)] : [fromNullable(rule.memory) ?? MemoryHeap], + memory: isNullish(rule) + ? [memoryFromText(memory)] + : [fromNullable(rule.memory) ?? MemoryStable], mutable_permissions: toNullable(mutablePermissions) }; diff --git a/src/frontend/src/lib/components/collections/CollectionEdit.svelte b/src/frontend/src/lib/components/collections/CollectionEdit.svelte index 4b42bbb60..8cd8a4451 100644 --- a/src/frontend/src/lib/components/collections/CollectionEdit.svelte +++ b/src/frontend/src/lib/components/collections/CollectionEdit.svelte @@ -44,10 +44,7 @@ const initMemory = (text: MemoryText) => (memory = text); $: initMemory( // Before the introduction of the stable memory, the memory used was "Heap". That's why we fallback for display purpose on Stable only if new to support old satellites - memoryToText( - fromNullable(rule?.memory ?? []) ?? - (typeStorage && mode === 'new' ? MemoryStable : MemoryHeap) - ) + memoryToText(fromNullable(rule?.memory ?? []) ?? (mode === 'new' ? MemoryStable : MemoryHeap)) ); let currentImmutable: boolean; @@ -165,8 +162,8 @@ {$i18n.collections.memory} diff --git a/src/libs/satellite/src/impls.rs b/src/libs/satellite/src/impls.rs index d9995d46a..de9deb4e5 100644 --- a/src/libs/satellite/src/impls.rs +++ b/src/libs/satellite/src/impls.rs @@ -36,7 +36,7 @@ impl Default for HeapState { Rule { read: rule.read, write: rule.write, - memory: Some(rule.memory.unwrap_or(Memory::Heap)), + memory: Some(rule.memory.unwrap_or(Memory::Stable)), mutable_permissions: Some(rule.mutable_permissions.unwrap_or(false)), max_size: rule.max_size, created_at: now, diff --git a/src/libs/satellite/src/rules/constants.rs b/src/libs/satellite/src/rules/constants.rs index 25cdd04e2..a2092620d 100644 --- a/src/libs/satellite/src/rules/constants.rs +++ b/src/libs/satellite/src/rules/constants.rs @@ -9,7 +9,7 @@ pub const DEFAULT_DB_COLLECTIONS: [(&str, SetRule); 1] = [( SetRule { read: Managed, write: Managed, - memory: Some(Memory::Heap), + memory: Some(Memory::Stable), mutable_permissions: Some(false), max_size: None, updated_at: None, diff --git a/src/libs/satellite/src/rules/store.rs b/src/libs/satellite/src/rules/store.rs index 4037c18f6..e2c341a79 100644 --- a/src/libs/satellite/src/rules/store.rs +++ b/src/libs/satellite/src/rules/store.rs @@ -33,26 +33,18 @@ pub fn set_rule_db(collection: CollectionKey, rule: SetRule) -> Result<(), Strin set_rule_impl( collection.clone(), rule.clone(), - Memory::Heap, &mut state.borrow_mut().heap.db.rules, ) })?; // If the collection does not exist yet we initialize it - init_collection_store(&collection, &rule.memory.unwrap_or(Memory::Heap)); + init_collection_store(&collection, &rule.memory.unwrap_or(Memory::Stable)); Ok(()) } pub fn set_rule_storage(collection: CollectionKey, rule: SetRule) -> Result<(), String> { - STATE.with(|state| { - set_rule_impl( - collection, - rule, - Memory::Stable, - &mut state.borrow_mut().heap.storage.rules, - ) - }) + STATE.with(|state| set_rule_impl(collection, rule, &mut state.borrow_mut().heap.storage.rules)) } pub fn del_rule_db(collection: CollectionKey, rule: DelRule) -> Result<(), String> { @@ -80,7 +72,6 @@ pub fn del_rule_storage(collection: CollectionKey, rule: DelRule) -> Result<(), fn set_rule_impl( collection: CollectionKey, user_rule: SetRule, - default_memory: Memory, rules: &mut Rules, ) -> Result<(), String> { let current_rule = rules.get(&collection); @@ -103,7 +94,7 @@ fn set_rule_impl( updated_at, read: user_rule.read, write: user_rule.write, - memory: Some(user_rule.memory.unwrap_or(default_memory)), + memory: Some(user_rule.memory.unwrap_or(Memory::Stable)), mutable_permissions: Some(user_rule.mutable_permissions.unwrap_or(true)), max_size: user_rule.max_size, }; diff --git a/src/libs/satellite/src/rules/types.rs b/src/libs/satellite/src/rules/types.rs index 6dbe8c6b4..d6f105ef2 100644 --- a/src/libs/satellite/src/rules/types.rs +++ b/src/libs/satellite/src/rules/types.rs @@ -21,8 +21,8 @@ pub mod rules { #[derive(CandidType, Serialize, Deserialize, Default, Clone, Debug)] pub enum Memory { - #[default] Heap, + #[default] Stable, } diff --git a/src/tests/satellite.spec.ts b/src/tests/satellite.spec.ts index dfd0ac366..24e7db013 100644 --- a/src/tests/satellite.spec.ts +++ b/src/tests/satellite.spec.ts @@ -64,7 +64,7 @@ describe('Satellite', () => { }); expect(collection).toEqual('test'); - expect(memory).toEqual(toNullable({ Heap: null })); + expect(memory).toEqual(toNullable({ Stable: null })); expect(read).toEqual({ Managed: null }); expect(write).toEqual({ Managed: null }); expect(created_at).toBeGreaterThan(0n); @@ -82,7 +82,7 @@ describe('Satellite', () => { ] = await list_rules({ Db: null }); expect(collection).toEqual('test'); - expect(memory).toEqual(toNullable({ Heap: null })); + expect(memory).toEqual(toNullable({ Stable: null })); expect(read).toEqual({ Managed: null }); expect(write).toEqual({ Managed: null }); expect(mutable_permissions).toEqual([true]); diff --git a/src/tests/satellite.upgrade.spec.ts b/src/tests/satellite.upgrade.spec.ts index f9bd355c7..3a96e831a 100644 --- a/src/tests/satellite.upgrade.spec.ts +++ b/src/tests/satellite.upgrade.spec.ts @@ -123,4 +123,32 @@ describe('satellite upgrade v0.0.16', () => { await testUsers([...users, ...moreUsers]); }); + + it('should keep listing existing heap collections as such', async () => { + const { set_rule, list_rules } = actor; + + await set_rule({ Db: null }, 'test', { + memory: toNullable({ Heap: null }), + updated_at: toNullable(), + max_size: toNullable(), + read: { Managed: null }, + mutable_permissions: toNullable(), + write: { Managed: null } + }); + + const testCollection = async () => { + const [[collection, { memory }], _] = await list_rules({ + Db: null + }); + + expect(collection).toEqual('test'); + expect(memory).toEqual(toNullable({ Heap: null })); + }; + + await testCollection(); + + await upgrade(); + + await testCollection(); + }); });