From f603e86d2827c66219321f9df400049e76b78c21 Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Thu, 28 Dec 2023 15:59:35 +0330 Subject: [PATCH] feat(engine/demo): collection with new api --- .../{src/demo-col.ts => demo/demo-col.mjs} | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) rename packages/engine/{src/demo-col.ts => demo/demo-col.mjs} (74%) diff --git a/packages/engine/src/demo-col.ts b/packages/engine/demo/demo-col.mjs similarity index 74% rename from packages/engine/src/demo-col.ts rename to packages/engine/demo/demo-col.mjs index 311b0b27..43904273 100644 --- a/packages/engine/src/demo-col.ts +++ b/packages/engine/demo/demo-col.mjs @@ -1,7 +1,6 @@ import {createLogger} from '@alwatr/logger'; -import {AlwatrStore} from './alwatr-store.js'; -import {Region, StoreFileTTL} from './type.js'; +import {AlwatrStore, Region, StoreFileId, StoreFileExtension, StoreFileType} from '@alwatr/store-engine'; const logger = createLogger('AlwatrStore/Demo', true); logger.banner('AlwatrStore/Demo'); @@ -12,14 +11,12 @@ const alwatrStore = new AlwatrStore({ saveDebounce: 5_000, // for demo }); -interface Post { - [P: string]: string; - title: string; - body: string; -} - async function quickstart() { - const postsCollectionId = 'post-list'; + const postsCollectionId = { + name: 'post', + region: Region.PerUser, + ownerId: 'user_123' + }; logger.logProperty?.('collectionId', postsCollectionId); @@ -34,15 +31,12 @@ async function quickstart() { } // Create a new collection. - await alwatrStore.defineCollection({ - id: postsCollectionId, - region: Region.Public, - ttl: StoreFileTTL.veryShort, // for demo + alwatrStore.defineStoreFile({ + ...postsCollectionId, + type: StoreFileType.Collection, + extension: StoreFileExtension.Json, }); - // Check the collection stat. - logger.logProperty?.('stat', alwatrStore.stat(postsCollectionId)); - // Get a collection reference. const postsCollection = await alwatrStore.collection(postsCollectionId); @@ -56,7 +50,7 @@ async function quickstart() { }); // Read the collection item meta information. - logger.logProperty?.('collection.meta', postsCollection.meta(post1Id)); + logger.logProperty?.('collection.meta', postsCollection.metaItem(post1Id)); // Read the collection item. logger.logProperty?.('context1', postsCollection.get(post1Id)); @@ -75,8 +69,8 @@ async function quickstart() { }); logger.logProperty?.('context2', postsCollection.get(post1Id)); - logger.logProperty?.('collection.meta1', postsCollection.meta(post1Id)); - logger.logProperty?.('collection.meta2', postsCollection.meta(post2Id)); + logger.logProperty?.('collection.meta1', postsCollection.metaItem(post1Id)); + logger.logProperty?.('collection.meta2', postsCollection.metaItem(post2Id)); // Unload the collection from memory. alwatrStore.unload(postsCollectionId);