Skip to content

Commit

Permalink
refactor(server): update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Oct 21, 2024
1 parent c9c071f commit 57d4097
Show file tree
Hide file tree
Showing 12 changed files with 2,489 additions and 1,668 deletions.
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ RUN apt-get update \
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /root/.gnupg /tmp/library-scripts

# Enable PNPM
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
RUN sudo corepack enable \
&& corepack prepare pnpm@latest --activate

Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
# Update 'VARIANT' to pick an LTS version of Node.js: 18, 16, 14, 12.
# Append -bullseye or -buster to pin to an OS version.
# Use -bullseye variants on local arm64/Apple Silicon.
VARIANT: 18-bullseye
VARIANT: 20-bullseye

volumes:
- ..:/workspace
Expand Down
15 changes: 8 additions & 7 deletions blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
"author": "Nicolas Giard",
"license": "AGPL-3.0",
"dependencies": {
"lit": "2.8.0"
"lit": "3.2.1"
},
"devDependencies": {
"@rollup/plugin-graphql": "2.0.4",
"@rollup/plugin-node-resolve": "15.2.2",
"@rollup/plugin-graphql": "2.0.5",
"@rollup/plugin-node-resolve": "15.3.0",
"@rollup/plugin-terser": "0.4.4",
"glob": "10.3.10",
"rollup": "3.29.4",
"rollup-plugin-summary": "2.0.0"
}
"glob": "11.0.0",
"rollup": "4.24.0",
"rollup-plugin-summary": "2.0.1"
},
"packageManager": "[email protected]+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228"
}
508 changes: 355 additions & 153 deletions blocks/pnpm-lock.yaml

Large diffs are not rendered by default.

21 changes: 0 additions & 21 deletions server/.eslintrc.yml

This file was deleted.

19 changes: 19 additions & 0 deletions server/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import neostandard from 'neostandard'

export default neostandard({
globals: {
document: false,
navigator: false,
window: false,
WIKI: true
},
ignores: [
'**/node_modules/**',
'**/*.min.js',
'coverage/**',
'repo/**',
'data/**',
'logs/**',
'locales/**'
]
})
2 changes: 1 addition & 1 deletion server/graph/resolvers/authentication.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { generateError, generateSuccess } from '../../helpers/graph.mjs'
import jwt from 'jsonwebtoken'
import ms from 'ms'
import { DateTime } from 'luxon'
import base64 from '@hexagon/base64'
import { base64 } from '@hexagon/base64'
import {
generateRegistrationOptions,
verifyRegistrationResponse,
Expand Down
107 changes: 56 additions & 51 deletions server/models/pages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import he from 'he'
import CleanCSS from 'clean-css'
import TurndownService from 'turndown'
import { gfm as turndownPluginGfm } from '@joplin/turndown-plugin-gfm'
import cheerio from 'cheerio'
import * as cheerio from 'cheerio'
import matter from 'gray-matter'

import { PageLink } from './pageLinks.mjs'
Expand All @@ -29,37 +29,37 @@ const frontmatterRegex = {
* Pages model
*/
export class Page extends Model {
static get tableName() { return 'pages' }
static get tableName () { return 'pages' }

static get jsonSchema () {
return {
type: 'object',
required: ['path', 'title'],

properties: {
id: {type: 'string'},
path: {type: 'string'},
hash: {type: 'string'},
title: {type: 'string'},
description: {type: 'string'},
publishState: {type: 'string'},
publishStartDate: {type: 'string'},
publishEndDate: {type: 'string'},
content: {type: 'string'},
contentType: {type: 'string'},
render: {type: 'string'},
siteId: {type: 'string'},
createdAt: {type: 'string'},
updatedAt: {type: 'string'}
id: { type: 'string' },
path: { type: 'string' },
hash: { type: 'string' },
title: { type: 'string' },
description: { type: 'string' },
publishState: { type: 'string' },
publishStartDate: { type: 'string' },
publishEndDate: { type: 'string' },
content: { type: 'string' },
contentType: { type: 'string' },
render: { type: 'string' },
siteId: { type: 'string' },
createdAt: { type: 'string' },
updatedAt: { type: 'string' }
}
}
}

static get jsonAttributes() {
static get jsonAttributes () {
return ['config', 'historyData', 'relations', 'scripts', 'toc']
}

static get relationMappings() {
static get relationMappings () {
return {
// tags: {
// relation: Model.ManyToManyRelation,
Expand Down Expand Up @@ -100,26 +100,29 @@ export class Page extends Model {
}
}

$beforeUpdate() {
$beforeUpdate () {
this.updatedAt = new Date().toISOString()
}
$beforeInsert() {

$beforeInsert () {
this.createdAt = new Date().toISOString()
this.updatedAt = new Date().toISOString()
}

/**
* Solving the violates foreign key constraint using cascade strategy
* using static hooks
* @see https://vincit.github.io/objection.js/api/types/#type-statichookarguments
*/
static async beforeDelete({ asFindQuery }) {
static async beforeDelete ({ asFindQuery }) {
const page = await asFindQuery().select('id')
await WIKI.db.comments.query().delete().where('pageId', page[0].id)
}

/**
* Cache Schema
*/
static get cacheSchema() {
static get cacheSchema () {
return new JSBinType({
id: 'string',
authorId: 'string',
Expand Down Expand Up @@ -163,7 +166,7 @@ export class Page extends Model {
*
* @returns {string} File Extension
*/
getFileExtension() {
getFileExtension () {
return getFileExtension(this.contentType)
}

Expand Down Expand Up @@ -212,7 +215,7 @@ export class Page extends Model {
* @param {Object} opts Page Properties
* @returns {Promise} Promise of the Page Model Instance
*/
static async createPage(opts) {
static async createPage (opts) {
// -> Validate site
if (!WIKI.sites[opts.siteId]) {
throw new Error('ERR_INVALID_SITE')
Expand Down Expand Up @@ -399,7 +402,7 @@ export class Page extends Model {
* @param {Object} opts Page Properties
* @returns {Promise} Promise of the Page Model Instance
*/
static async updatePage(opts) {
static async updatePage (opts) {
// -> Fetch original page
const ogPage = await WIKI.db.pages.query().findById(opts.id)
if (!ogPage) {
Expand Down Expand Up @@ -627,7 +630,7 @@ export class Page extends Model {
authorId: opts.user.id,
historyData
}).where('id', ogPage.id)
let page = await WIKI.db.pages.getPageFromDb(ogPage.id)
const page = await WIKI.db.pages.getPageFromDb(ogPage.id)

// -> Render page to HTML
if (opts.patch.content) {
Expand Down Expand Up @@ -717,7 +720,7 @@ export class Page extends Model {
* @param {Object} opts Page Properties
* @returns {Promise} Promise of the Page Model Instance
*/
static async convertPage(opts) {
static async convertPage (opts) {
// -> Fetch original page
const ogPage = await WIKI.db.pages.query().findById(opts.id)
if (!ogPage) {
Expand All @@ -738,7 +741,7 @@ export class Page extends Model {

// -> Check content type
const sourceContentType = ogPage.contentType
const targetContentType = get(find(WIKI.data.editors, ['key', opts.editor]), `contentType`, 'text')
const targetContentType = get(find(WIKI.data.editors, ['key', opts.editor]), 'contentType', 'text')
const shouldConvert = sourceContentType !== targetContentType
let convertedContent = null

Expand Down Expand Up @@ -884,7 +887,7 @@ export class Page extends Model {
* @param {Object} opts Page Properties
* @returns {Promise} Promise with no value
*/
static async movePage(opts) {
static async movePage (opts) {
let page
if (has(opts, 'id')) {
page = await WIKI.db.pages.query().findById(opts.id)
Expand Down Expand Up @@ -1009,7 +1012,7 @@ export class Page extends Model {
* @param {Object} opts Page Properties
* @returns {Promise} Promise with no value
*/
static async deletePage(opts) {
static async deletePage (opts) {
const page = await WIKI.db.pages.getPageFromDb(has(opts, 'id') ? opts.id : opts)
if (!page) {
throw new WIKI.Error.PageNotFound()
Expand Down Expand Up @@ -1067,7 +1070,7 @@ export class Page extends Model {
return
// TODO: fix this
const pageHref = `/${opts.locale}/${opts.path}`
let replaceArgs = {
const replaceArgs = {
from: '',
to: ''
}
Expand Down Expand Up @@ -1138,7 +1141,7 @@ export class Page extends Model {
* @param {Object} page Page Model Instance
* @returns {Promise} Promise with no value
*/
static async renderPage(page) {
static async renderPage (page) {
const renderJob = await WIKI.scheduler.addJob({
task: 'render-page',
payload: {
Expand All @@ -1156,7 +1159,7 @@ export class Page extends Model {
* @param {Object} opts Page Properties
* @returns {Promise} Promise of the Page Model Instance
*/
static async getPage(opts) {
static async getPage (opts) {
return WIKI.db.pages.getPageFromDb(opts)

// -> Get from cache first
Expand Down Expand Up @@ -1184,7 +1187,7 @@ export class Page extends Model {
* @param {Object} opts Page Properties
* @returns {Promise} Promise of the Page Model Instance
*/
static async getPageFromDb(opts) {
static async getPageFromDb (opts) {
const queryModeID = typeof opts === 'string'
try {
return WIKI.db.pages.query()
Expand All @@ -1202,13 +1205,15 @@ export class Page extends Model {
.joinRelated('author')
.joinRelated('creator')
.leftJoin('tree', 'pages.id', 'tree.id')
.where(queryModeID ? {
'pages.id': opts
} : {
'pages.siteId': opts.siteId,
'pages.path': opts.path,
'pages.locale': opts.locale
})
.where(queryModeID
? {
'pages.id': opts
}
: {
'pages.siteId': opts.siteId,
'pages.path': opts.path,
'pages.locale': opts.locale
})
// .andWhere(builder => {
// if (queryModeID) return
// builder.where({
Expand All @@ -1231,7 +1236,7 @@ export class Page extends Model {
* @param {Object} page Page Model Instance
* @returns {Promise} Promise with no value
*/
static async savePageToCache(page) {
static async savePageToCache (page) {
const cachePath = path.resolve(WIKI.ROOTPATH, WIKI.config.dataPath, `cache/${page.hash}.bin`)
await fse.outputFile(cachePath, WIKI.db.pages.cacheSchema.encode({
id: page.id,
Expand Down Expand Up @@ -1264,13 +1269,13 @@ export class Page extends Model {
* @param {Object} opts Page Properties
* @returns {Promise} Promise of the Page Model Instance
*/
static async getPageFromCache(opts) {
static async getPageFromCache (opts) {
const pageHash = generateHash({ path: opts.path, locale: opts.locale })
const cachePath = path.resolve(WIKI.ROOTPATH, WIKI.config.dataPath, `cache/${pageHash}.bin`)

try {
const pageBuffer = await fse.readFile(cachePath)
let page = WIKI.db.pages.cacheSchema.decode(pageBuffer)
const page = WIKI.db.pages.cacheSchema.decode(pageBuffer)
return {
...page,
path: opts.path,
Expand All @@ -1291,15 +1296,15 @@ export class Page extends Model {
* @param {String} page Page Unique Hash
* @returns {Promise} Promise with no value
*/
static async deletePageFromCache(hash) {
static async deletePageFromCache (hash) {
return fse.remove(path.resolve(WIKI.ROOTPATH, WIKI.config.dataPath, `cache/${hash}.bin`))
}

/**
* Flush the contents of the Cache
*/
static async flushCache() {
return fse.emptyDir(path.resolve(WIKI.ROOTPATH, WIKI.config.dataPath, `cache`))
static async flushCache () {
return fse.emptyDir(path.resolve(WIKI.ROOTPATH, WIKI.config.dataPath, 'cache'))
}

/**
Expand All @@ -1310,15 +1315,15 @@ export class Page extends Model {
* @param {string} opts.targetLocale Target Locale Code
* @returns {Promise} Promise with no value
*/
static async migrateToLocale({ sourceLocale, targetLocale }) {
static async migrateToLocale ({ sourceLocale, targetLocale }) {
return WIKI.db.pages.query()
.patch({
locale: targetLocale
})
.where({
locale: sourceLocale
})
.whereNotExists(function() {
.whereNotExists(function () {
this.select('id').from('pages AS pagesm').where('pagesm.locale', targetLocale).andWhereRaw('pagesm.path = pages.path')
})
}
Expand All @@ -1329,7 +1334,7 @@ export class Page extends Model {
* @param {string} rawHTML Raw HTML
* @returns {string} Cleaned Content Text
*/
static cleanHTML(rawHTML = '') {
static cleanHTML (rawHTML = '') {
const data = striptags(rawHTML || '', [], ' ')
.replace(emojiRegex(), '')
return he.decode(data)
Expand All @@ -1340,7 +1345,7 @@ export class Page extends Model {
/**
* Subscribe to HA propagation events
*/
static subscribeToEvents() {
static subscribeToEvents () {
WIKI.events.inbound.on('deletePageFromCache', hash => {
WIKI.db.pages.deletePageFromCache(hash)
})
Expand Down
Loading

0 comments on commit 57d4097

Please sign in to comment.