diff --git a/.build.ps1 b/.build.ps1 index dd0bc0d..df0148d 100644 --- a/.build.ps1 +++ b/.build.ps1 @@ -1,17 +1,17 @@ '# required powershell modules' -Install-Module -Name Pode -Verbose # MIT -Install-Module -Name PSSQLite -Verbose # MIT +Install-Module -Name PSSQLite -MinimumVersion 1.1.0 -MaximumVersion 1.99.99 -Verbose # MIT +Install-Module -Name Pode -MinimumVersion 2.11.0 -MaximumVersion 2.99.99 -Verbose # MIT '# development powershell modules' -Install-Module -Name Pester -Verbose # Apache 2.0 -Install-Module -Name PSScriptAnalyzer -Verbose # MIT +Install-Module -Name Pester -MinimumVersion 5.6.1 -MaximumVersion 5.99.99 -Verbose # Apache 2.0 +Install-Module -Name PSScriptAnalyzer -MinimumVersion 1.23.0 -MaximumVersion 1.99.99 -Verbose # MIT '# required npm packages' npm install htmx.org@next htmx-ext-client-side-templates htmx-ext-debug htmx-ext-json-enc mustache npm install tailwindcss @tailwindcss/forms @tailwindcss/typography @tailwindcss/aspect-ratio '# development npm packages' -npm install -D eslint globals @eslint/js prettier prettier-plugin-tailwindcss prettier-plugin-sql +npm install -D eslint globals htmx-ext-debug @eslint/js prettier prettier-plugin-tailwindcss prettier-plugin-sql '# update packages' npm update @@ -23,9 +23,12 @@ npm run test npm run css '# copy distribution files' -Copy-Item -Path './node_modules/htmx.org/dist/htmx.min.js' -Destination './public/js/htmx.min.js' -Force -Verbose Copy-Item -Path './node_modules/htmx-ext-client-side-templates/client-side-templates.js' -Destination './public/js/client-side-templates.js' -Force -Verbose +Copy-Item -Path './node_modules/htmx-ext-debug/debug.js' -Destination './public/js/debug.js' -Force -Verbose Copy-Item -Path './node_modules/htmx-ext-json-enc/json-enc.js' -Destination './public/js/json-enc.js' -Force -Verbose +Copy-Item -Path './node_modules/htmx.org/dist/htmx.js' -Destination './public/js/htmx.js' -Force -Verbose +Copy-Item -Path './node_modules/htmx.org/dist/htmx.min.js' -Destination './public/js/htmx.min.js' -Force -Verbose +Copy-Item -Path './node_modules/mustache/mustache.js' -Destination './public/js/mustache.js' -Force -Verbose Copy-Item -Path './node_modules/mustache/mustache.min.js' -Destination './public/js/mustache.min.js' -Force -Verbose '# initialize database' diff --git a/api/crud/get.ps1 b/api/crud/get.ps1 index 46a1aa6..3b89b26 100644 --- a/api/crud/get.ps1 +++ b/api/crud/get.ps1 @@ -1,9 +1,11 @@ { $isHTMX = $($WebEvent.Request.Headers.'HX-Request') + $isJsonEnc = $($WebEvent.Request.Headers.'Content-Type') -eq 'application/json' + $db = (Get-PodeConfig).Podex.DBFile - Write-FormattedLog -tag 'api' -log "CRUD API: $($WebEvent.Method.ToUpper()) $($WebEvent.Path) `$isHTMX:$($isHTMX) Q: $($WebEvent.Query | ConvertTo-Json -Compress)" + Write-FormattedLog -tag 'api' -log "Items API: $($WebEvent.Method.ToUpper()) $($WebEvent.Path) `$isHTMX:$($isHTMX) Q: $($WebEvent.Query | ConvertTo-Json -Compress)" try { $tagFilter = $WebEvent.Query['tagFilter'] @@ -43,9 +45,7 @@ # Write-FormattedLog -tag 'database' -log "db: $($db); sqlx: $($sqlx); tagFilter: $tagFilter; search: $search; params: $($params | ConvertTo-Json -Compress)" $rs = (Invoke-SqliteQuery -DataSource $db -Query $sqlx -SqlParameters $params -As PSObject) - - # Write-FormattedLog -tag 'database' -log "db: $($db); countSqlx: $($countSqlx); tagFilter: $tagFilter; search: $search; params: $($params | ConvertTo-Json -Compress)" - $totalItems = (Invoke-SqliteQuery -DataSource $db -Query $countSqlx -SqlParameters $params -As PSObject).count + $totalItems = $rs.Count $tags = (Invoke-SqliteQuery -DataSource $db -Query "select [tag], case when [tag] = '$($tagFilter)' then 'selected' else '' end as [selected] from [tag] order by [tag] asc ;" -As PSObject) @@ -54,7 +54,6 @@ $totalPages = [Math]::Ceiling($totalItems / $pageSize) $hasPreviousPage = $page -gt 1 $hasNextPage = $page -lt $totalPages - $pages = @() for ($i = 1; $i -le $totalPages; $i++) { $pages += @{ @@ -64,7 +63,7 @@ } $response = @{ - features = $rs + rows = $rs tags = $tags startIndex = $startIndex endIndex = $endIndex @@ -77,23 +76,29 @@ currentPage = $page } - # Write-FormattedLog -tag 'debug' -log ($response | ConvertTo-Json -Depth 5 -Compress) -save $true + Write-FormattedLog -tag 'debug' -log ($response | ConvertTo-Json -Depth 5 -Compress) + if ((Get-PodeConfig).Podex.Debug) { + New-Item -Name "$($WebEvent.Method).json" -Path $PSScriptRoot -ItemType File -Value ($response | ConvertTo-Json -Depth 5) -Force + } - if ($isHTMX) { - Write-FormattedLog -tag 'debug' -log "CRUDs found: $($rs.Count)" - $response | ConvertTo-Json -Depth 5 | Write-PodeJsonResponse -StatusCode 200 - } else { - if ($response.features) { - Write-FormattedLog -tag 'debug' -log "CRUDs found: $($rs.Count)" + if ($response.rows) { + Write-FormattedLog -tag 'debug' -log "Items found: $($totalItems)" + if ($isJsonEnc) { $response | ConvertTo-Json -Depth 5 | Write-PodeJsonResponse -StatusCode 200 } else { - Write-FormattedLog -tag 'debug' -log "No features found" - Write-PodeJsonResponse -StatusCode 204 -Value @{ message = "No features found" } + $response | Write-PodeHtmlResponse -StatusCode 200 + } + } else { + Write-FormattedLog -tag 'debug' -log "No items found" + if ($isJsonEnc) { + Write-PodeJsonResponse -StatusCode 204 -Value @{ message = "No items found" } + } else { + Write-PodeHtmlResponse -StatusCode 204 -Value @{ message = "No items found" } } } } catch { - Write-FormattedLog -tag 'error' -log "Error retrieving features: $_" + Write-FormattedLog -tag 'error' -log "Error retrieving items: $($_.Exception.Message)" Write-PodeJsonResponse -StatusCode 500 -Value @{ message = "Internal server error" } } diff --git a/errors/404.html.pode b/errors/404.html.pode index 6a9a85b..540f971 100644 --- a/errors/404.html.pode +++ b/errors/404.html.pode @@ -8,10 +8,11 @@