From 23760814efd356ac2d46c6060266f3aeffcd92a2 Mon Sep 17 00:00:00 2001 From: Giovanni Abbatepaolo <30571828+bbtgnn@users.noreply.github.com> Date: Thu, 7 Mar 2024 11:57:42 +0100 Subject: [PATCH] feat: update db logic --- src/__cms/dao/db.ts | 11 +++++++++-- src/__cms/fields.ts | 4 ++-- src/routes/+page.svelte | 3 +++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/__cms/dao/db.ts b/src/__cms/dao/db.ts index f5eadff..6009665 100644 --- a/src/__cms/dao/db.ts +++ b/src/__cms/dao/db.ts @@ -57,14 +57,14 @@ export function create( export function get_document( collection_name: C, document_name: DocumentName -): Document | Error { +): Document | undefined { return pipe( Effect.all([ get_base_document(`${collection_name}/${document_name}`), get_collection_schema(collection_name) ]), Effect.flatMap(([base_document, schema]) => parse_base_document(base_document, schema)), - Effect.catchAll((e) => Effect.succeed(e)), + Effect.catchAll(() => Effect.succeed(undefined)), Effect.runSync ); } @@ -80,6 +80,13 @@ export function get_collection( ]), Effect.flatMap(([documents, schema]) => parse_base_documents(documents, schema)), Effect.map((documents) => sort_documents(documents, options.sort)), + Effect.match({ + onFailure: (e) => { + console.log(e); + return []; + }, + onSuccess: (a) => a + }), Effect.runSync ); } diff --git a/src/__cms/fields.ts b/src/__cms/fields.ts index 6ec352f..68fba45 100644 --- a/src/__cms/fields.ts +++ b/src/__cms/fields.ts @@ -3,7 +3,7 @@ import { Type as T, type StaticDecode } from '@sinclair/typebox'; import { database_index, database_index_schema } from './database_index'; import type { CollectionName } from './database'; -import { db } from '.'; +import { get_document } from '.'; // @@ -72,7 +72,7 @@ export function Relation(collection_name: C) { .Decode((document) => ({ collection: collection_name, document, - get: () => db.get_document(collection_name, document) + get: () => get_document(collection_name, document) })) .Encode((field) => field.document); } diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 6a2c9c8..e2e48a0 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1 +1,4 @@ + + Home page