Skip to content

Commit

Permalink
feat: add db adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Aug 19, 2024
1 parent 4c91fba commit 0448a3f
Show file tree
Hide file tree
Showing 82 changed files with 658 additions and 191 deletions.
19 changes: 14 additions & 5 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import sitemap from '@astrojs/sitemap'
import svelte from '@astrojs/svelte'
import tailwind from '@astrojs/tailwind'
import { defineConfig } from 'astro/config'

import assetMinifier from '@playform/compress'
import imageCompressor from 'astro-better-image-service'
import assetCompressor from 'astro-compressor'
import metadata from 'astro-meta-tags'
import insights from 'astro-page-insight'
import purgecss from 'astro-purgecss'

import assetMinifier from '@playform/compress'
import { FontaineTransform } from 'fontaine'

/** @type {boolean} */
const isProd = process.env.NODE_ENV === 'production'

/** @type {object} */
/**
* @type {object}
* @todo Move this to a config file.
*/
const sitemapConfig = {
i18n: {
defaultLocale: 'fr',
Expand All @@ -32,10 +35,16 @@ const assetMinifierConfig = {
/** @type {number} */
const port = 4321

/** @type {string} */
/**
* @type {string}
* @todo Move this to a config file (at least the production URL).
*/
const site = isProd ? 'https://maisonquiroga.art' : `http://localhost:${port}`

/** @type {object} */
/**
* @type {object}
* @todo Move this to a config file.
*/
const vite = {
plugins: [
FontaineTransform.vite({
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import tailwind from 'eslint-plugin-tailwindcss'
import neostandard from 'neostandard'
import { parser } from 'typescript-eslint'

import restrictedImports from './src/config/imports-policy.mjs'

const standard = neostandard({
ignores: [
...neostandard.resolveIgnoresFromGitignore(),
Expand All @@ -24,6 +26,7 @@ export default [
...astro.configs.recommended,
...svelte.configs['flat/recommended'],
...svelte.configs['flat/prettier'],
...restrictedImports,
{
rules: {
'@stylistic/comma-dangle': 'off',
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@redtech/maisonquiroga",
"version": "0.1.0",
"type": "module",
"license": "AGPL-3.0-or-later",
"private": true,
"packageManager": "[email protected]",
Expand All @@ -15,6 +16,7 @@
"check:eslint": "eslint .",
"check:prettier": "prettylint .",
"check:stylelint": "stylelint '**/*.{css,astro,svelte}'",
"check:todo": "leasot src/**/*.ts",
"dev": "astro dev",
"format": "run-s format:eslint format:prettier format:stylelint",
"format:eslint": "yarn check:eslint --fix",
Expand Down Expand Up @@ -55,6 +57,8 @@
"eslint-plugin-tailwindcss": "^3.17.4",
"fontaine": "^0.5.0",
"husky": "^9.1.4",
"leasot": "^14.4.0",
"lowdb": "^7.0.1",
"neostandard": "^0.11.2",
"npm-run-all2": "^6.2.2",
"postcss": "^8.4.41",
Expand Down
62 changes: 6 additions & 56 deletions prettier.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/** @type {import('prettier').Config} */
import sortedImports from './src/config/imports-order.mjs'

/** @type {import('prettier').Config} */
export default {
// StandardJS
Expand All @@ -7,61 +10,6 @@ export default {
embeddedLanguageFormatting: 'auto',
endOfLine: 'lf',
htmlWhitespaceSensitivity: 'css',
importOrder: [
'<TYPES>',
'<TYPES>^(@astrojs/)',
'<TYPES>^(astro/)',
'<TYPES>^(astro:)',
'<TYPES>^(svelte)',
'<TYPES>^(@\\w)',
'<TYPES>^(\\w)',
'<TYPES>^([#])',
'<TYPES>^([~])',
'<TYPES>^([&])',
'<TYPES>^([$])',
'<TYPES>^([+])',
'<TYPES>^([^])',
'<TYPES>^([@])',
'<TYPES>^([%])',
'<TYPES>^([;])',
'<TYPES>^([./])',
'<TYPES>^([../])',
'',
'<BUILTIN_MODULES>',
'',
'<THIRD_PARTY_MODULES>',
'',
'^(@astrojs/)(.*)$',
'^(astro/)(.*)$',
'^(astro:)(.*)$',
'',
'^(svelte)(.*)$',
'',
'^(@\\w)(.*)$',
'^(\\w)(.*)$',
'',
'^[#/](.*)$',
'',
'^[~/](.*)$',
'',
'^[&/](.*)$',
'',
'^[$/](.*)$',
'',
'^[+/](.*)$',
'',
'^[\\^/](.*)$',
'',
'^[@/](.*)$',
'',
'^[%/](.*)$',
'',
'^[;/](.*)$',
'',
'^[./]',
'',
'^[../]'
],
insertPragma: false,
jsxSingleQuote: true,
printWidth: 80,
Expand All @@ -84,5 +32,7 @@ export default {
'prettier-plugin-sh',
'prettier-plugin-svelte',
'prettier-plugin-tailwindcss'
]
],
// Sorted imports
...sortedImports
}
71 changes: 71 additions & 0 deletions src/adapters/infrastructure/db/lowdb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Lowdb adapter
*
* @module lowdb
* @todo Move types to {@link to &/ports.ts}
*/

import type { Data, Load } from '&/ports.ts'

import { Low } from 'lowdb'
import { JSONFile } from 'lowdb/node'

import { map } from '$/utils/adt/maybe.ts'
import { compose } from '$/utils/fun/compose.ts'

/** Connection to a database. */
type Conn<A> = Low<A>

/**
* Generic connect function.
*
* @typeParam A
* @param {string} path - The path used to establish the connection.
* @returns The connection object of type Conn<A>.
*/
type Connect<A> = (path: string) => Conn<A>

/** Connect to a database. */
const connect: Connect<Data> = (path) => new Low<Data>(new JSONFile(path), {})

/**
* Read a value from a given connection.
*
* @typeParam A
* @param {Conn<A>} conn - The connection to read the value from.
* @returns A function that when called, returns a Promise.
* @todo {@link null} here is an implementation detail leaked from {@link Low}
*/
type Read<A> = (conn: Readonly<Conn<A>>) => () => Promise<A | null>

/** Read a value from a given connection. */
const read: Read<Data> = (conn) => async () => await conn.adapter.read()

/**
* An indeterminacy, returning a {@link Promise}.
*
* @note We may think of a {@link Indet} as a "fp-ts/Task" or an
* "effect-ts/Effect".For us, it is less about what is to be done, as to what
* is to be known. That is, how the future unfolds, so to speak.
* @see {@link https://fr.hegel.net/f111.htm}
* @todo Make this a generic type.
*
* @todo Implement for {@link Maybe}.
*
* @todo Implement for {@link Result} (alias Either).
*/
export type Indet<A> = () => Promise<A>

/** A determinacy, resolving an indeterminacy. */
export type Det<A, B, C> = (f: A) => (g: Indet<B>) => Indet<C>

/** A determinacy, resolving an indeterminacy. */
const det: Det<Read<Data>, Conn<Data>, Data | null> = (f) => (g) => {
return async () => {
const result = await g()
return result ? await f(result)() : null
}
}

/** Load data for the database. */
export const load: Load<Data> = map(compose([det, read, connect]))
24 changes: 24 additions & 0 deletions src/adapters/infrastructure/ports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Infrastructure ports.
*
* @module ports
*/

import type { Just, Maybe } from '$/types.ts'

/** Data read from a database. */
export type Data = {
[key: Readonly<string>]: {
[key: Readonly<string>]: {
[key: Readonly<string>]: Readonly<string>
}
}
}

/**
* Load data from a database.
*
* @param {Just<string>} path - The path from which to load the value.
* @returns {Maybe<Data>} - The value loaded from the database.
*/
export type Load<Data> = (path: Just<string>) => Maybe<Data>
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { Readable } from 'svelte/store'

import type { WithContext } from 'schema-dts'
import type { City } from '&/entities'

import type { City } from '^/entities'

import { get, readable } from 'svelte/store'

import { chili, france } from '$/stores/CountryStore'
import { chili, france } from '+/CountryStore'

export const paris: Readable<WithContext<City>> = readable({
'@context': 'https://schema.org',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Readable } from 'svelte/store'

import type { WithContext } from 'schema-dts'
import type { Country } from '&/entities'

import type { Country } from '^/entities'

import { readable } from 'svelte/store'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { Readable } from 'svelte/store'

import type { WithContext } from 'schema-dts'
import type { GeoCoordinates } from '&/entities'

import type { GeoCoordinates } from '^/entities'

import { get, readable } from 'svelte/store'

import { adresseMaisonQuiroga } from '$/stores/PostalAddressStore'
import { adresseMaisonQuiroga } from '+/PostalAddressStore'

const { name, url } = get(adresseMaisonQuiroga)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Readable } from 'svelte/store'

import type { WithContext } from 'schema-dts'
import type { PostalAddress } from '&/entities'

import type { PostalAddress } from '^/entities'

import { readable } from 'svelte/store'

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Image } from 'astro:assets'
import resolveConfig from 'tailwindcss/resolveConfig'
import tailwindConfig from '#/tailwind.config'
import tailwindConfig from '=/tailwind.config'
const { theme } = resolveConfig(tailwindConfig)
const { screens } = theme
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</script>
<script lang="ts">
import { geoMaisonQuiroga } from '$/stores/GeoCoordinatesStore'
import { adresseMaisonQuiroga } from '$/stores/PostalAddressStore'
import { geoMaisonQuiroga } from '+/GeoCoordinatesStore'
import { adresseMaisonQuiroga } from '+/PostalAddressStore'
const { addressCountry, latitude, longitude } = get(geoMaisonQuiroga)
const { streetAddress, addressLocality } = get(adresseMaisonQuiroga)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
---
/* eslint-disable astro/no-conflict-set-directives,astro/valid-compile */
import { getImage } from 'astro:assets'
import resolveConfig from 'tailwindcss/resolveConfig'
import ';/styles/global.css'
import tailwindConfig from '=/tailwind.config'
import tailwindConfig from '#/tailwind.config'
import MetaGeo from ';/blocks/Meta/MetaGeo.svelte'
import MetaGeo from '^/components/Meta/MetaGeo.svelte'
import css from ';/assets/styles/global.css'
const {
url,
Expand Down Expand Up @@ -102,3 +104,7 @@ const schema = {
type='application/ld+json'
/>
</head>

<style set:html={css}>
/* stylelint-disable no-empty-source */
</style>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import HeaderTitle from './HeaderTitle.svelte'
import Logo from './Logo.astro'
import Logo from ';/atoms/Logo.astro'
import HeaderTitle from ';/blocks/HeaderTitle.svelte'
const { logo } = Astro.props
const h1 = {
Expand Down
14 changes: 7 additions & 7 deletions src/ui/screens/Home.astro → src/adapters/ui/screens/Home.astro
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
import type { NavProps } from '~/types'
import type { NavProps } from '$/types'
import { get } from 'svelte/store'
import { adresseMaisonQuiroga } from '$/stores/PostalAddressStore'
import { adresseMaisonQuiroga } from '+/PostalAddressStore'
import Footer from '^/components/Footer.svelte'
import Head from '^/components/Head.astro'
import Header from '^/components/Header.astro'
import Nav from '^/components/Nav.svelte'
import Nav from ';/blocks/Nav.svelte'
import Footer from ';/prouns/Footer.svelte'
import Head from ';/prouns/Head.astro'
import Header from ';/prouns/Header.astro'
import coverImage from ';/images/logo.jpg'
import coverImage from ';/assets/images/logo.jpg'
const { profileImage } = Astro.props
const images = { coverImage, profileImage }
Expand Down
Loading

0 comments on commit 0448a3f

Please sign in to comment.