Skip to content

Commit

Permalink
Merge branch 'release/v0.44.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Mar 30, 2024
2 parents 1e3bdd3 + f404166 commit 4bc9569
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 60 deletions.
9 changes: 5 additions & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import antfu from '@antfu/eslint-config'

export default antfu(
{
typescript: {
tsconfigPath: './tsconfig.json',
// ignores,
},
// typescript: {
// tsconfigPath: './tsconfig.json',
// // ignores,
// },
typescript: true,
vue: true,
ignores: [
'*.md',
Expand Down
28 changes: 13 additions & 15 deletions examples/oauth2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import type { NextFunction, Request, Response } from '@zerva/http'
import { useHttp } from '@zerva/http'
import session from 'express-session'
import type { LoggerInterface } from 'zeed'
import { Logger, encodeQuery, fetchJson, fetchOptionsJson, getTimestamp, isObject, isString, setupEnv, uuid } from 'zeed'
import { Logger, encodeQuery, fetchJson, fetchOptionsJson, getTimestamp, isString, setupEnv, uuid } from 'zeed'

interface AuthInfo {
// uuid?: string
// state?: string
timestamp?: number

access_token?: string

refresh_token?: string

/** The “expires_in” value is the number of seconds that the access token will be valid. */
expires_in?: number

token_type?: string
}

Expand Down Expand Up @@ -54,7 +54,7 @@ const {
OAUTH2_CALLBACK_URL: redirectUri = `http://localhost:8080${callbackPath}`,
OAUTH2_CLIENT_ID: clientId = '',
OAUTH2_CLIENT_SECRET: clientSecret = '',
OAUTH2_SCOPE: scope = 'user'
OAUTH2_SCOPE: scope = 'user',
} = process.env ?? {}

const authorizationUri = `${urlBase}/login/oauth/authorize`
Expand Down Expand Up @@ -128,7 +128,7 @@ on('httpInit', (info) => {
if (!req.session.authInfo?.access_token) {
log('requires login')
req.session.lastUrl = req.url
res.redirect(307, '/login')
res.redirect(307, '/login')
}
next()
}
Expand All @@ -151,10 +151,10 @@ on('httpInit', (info) => {
return 'no response'

req.session.authInfo = {
...authResponse as any,
timestamp: getTimestamp()
...authResponse as any,
timestamp: getTimestamp(),
}

// log.info('redirect', req.url, req.session.lastUrl)

res.redirect(307, req.session.lastUrl || '/')
Expand All @@ -165,14 +165,14 @@ on('httpInit', (info) => {
// https://www.oauth.com/oauth2-servers/accessing-data/authorization-request/

const state = uuid()
req.session.state = state
req.session.state = state

let query = encodeQuery({
const query = encodeQuery({
client_id: clientId,
redirect_uri: redirectUri,
response_type: 'code',
state,
scope
scope,
})

const uri = `${authorizationUri}?${query}`
Expand All @@ -186,16 +186,14 @@ on('httpInit', (info) => {
res.redirect(307, '/')
})


onGET('/protected',
oauth2,
async ({ req }) => {
log('/protected')
let user: any = ''

if (req.session.authInfo?.access_token) {
if (req.session.authInfo?.access_token)
user = await fetchJson(`${urlBase}/api/v1/user?access_token=${req.session.authInfo?.access_token}`)
}

return `<p>
This should be protected:
Expand All @@ -209,7 +207,7 @@ on('httpInit', (info) => {
</p>
`
}
},
)
})

Expand Down
9 changes: 5 additions & 4 deletions examples/vite-pwa/src/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// <reference types="vite/client" />

declare module '*.vue' {
import type { DefineComponent } from 'vue'
import type { ComponentOptions } from 'vue'

const component: DefineComponent<{}, {}, any>
// @ts-expect-error
export default component
const Component: ComponentOptions
export default Component
}
9 changes: 5 additions & 4 deletions examples/vite-serviceworker/src/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// <reference types="vite/client" />

declare module '*.vue' {
import type { DefineComponent } from 'vue'
import type { ComponentOptions } from 'vue'

const component: DefineComponent<{}, {}, any>
// @ts-expect-error
export default component
const Component: ComponentOptions
export default Component
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zerva/monorepo",
"version": "0.44.0",
"version": "0.44.1",
"private": true,
"scripts": {
"build": "pnpm -r --filter=@zerva/* build",
Expand Down
10 changes: 2 additions & 8 deletions zerva-bin/demo/shim-window.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
export {}

declare global {
module globalThis {
var TEST: boolean
namespace globalThis {
let TEST: boolean
}

// interface Window {
// TEST: boolean
// }
}
1 change: 0 additions & 1 deletion zerva-bin/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ export async function runMain(config: ZervaConf) {
void startNode()
})

// eslint-disable-next-line ts/no-misused-promises
build.onDispose(stopNode)
},
} as Plugin)
Expand Down
1 change: 0 additions & 1 deletion zerva-core/demo/zerva.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ onStart(() => {
next()
})

// eslint-disable-next-line ts/no-misused-promises
onStop(async () => {
log('stop')
await sleep(2000)
Expand Down
1 change: 0 additions & 1 deletion zerva-core/src/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ async function serverCheck() {
}
}

// eslint-disable-next-line ts/no-misused-promises
process.on('beforeExit', serverCheck)
// process.on('exit', serveStop)

Expand Down
1 change: 0 additions & 1 deletion zerva-http/demo/zerva.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ onStart(() => {
next()
})

// eslint-disable-next-line ts/no-misused-promises
onStop(async () => {
log('stop')
await sleep(2000)
Expand Down
1 change: 0 additions & 1 deletion zerva-http/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ export function useHttp(config?: {
suffix = /\.[a-z0-9]+$/.exec(path)?.[0]

for (const handler of handlers) {
// eslint-disable-next-line ts/no-misused-promises
app[mode](path, async (req: Request, res: Response, next: NextFunction) => {
try {
log(`${mode.toUpperCase()} ${path}`)
Expand Down
9 changes: 5 additions & 4 deletions zerva-openapi/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import { on, register } from '@zerva/core'
import '@zerva/http'
import { Logger } from 'zeed'

// @ts-ignore
import indexCss from './static/index.css.txt'
// @ts-ignore
import swaggerUiBundle from './static/swagger-ui-bundle.js.txt'
// @ts-ignore
import swaggerUiPreset from './static/swagger-ui-standalone-preset.js.txt'
// @ts-ignore
import swaggerUiCss from './static/swagger-ui.css.txt'

declare module '*.txt' {
const value: string // Add type definitions here if desired
export default value
}

const name = 'openapi'
const log = Logger(`zerva:${name}`)

Expand Down
20 changes: 10 additions & 10 deletions zerva-sqlite/src/database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore custom types
// @ts-expect-error custom types
import BetterSqlite3 from 'better-sqlite3'
import type { Primitive } from 'zeed'
import { Logger, arrayMinus, arraySorted, getTimestamp, isArray, isBoolean, isNumber, isPrimitive, isString, useDispose } from 'zeed'
Expand Down Expand Up @@ -108,7 +108,7 @@ export function useSqliteTable<
// Update table https://www.sqlite.org/lang_altertable.html
const missingFields = arrayMinus(Object.keys(creationFields), state.map((col: any) => col.name))
if (missingFields.length > 0) {
const fieldsList:string[] = []
const fieldsList: string[] = []
for (const field of missingFields)
fieldsList.push(`ALTER TABLE ${tableName} ADD COLUMN ${field} ${getAffinity((creationFields as any)[field])}`)
db.exec(fieldsList.join('; '))
Expand Down Expand Up @@ -146,8 +146,8 @@ export function useSqliteTable<
}

function findPrepare(cols?: Partial<ColFullType>, limit?: number, orderBy?: OrderByMany<string>) {
const fields:string[] = []
const values:Primitive[] = []
const fields: string[] = []
const values: Primitive[] = []
if (cols) {
for (const field of sortedFields) {
if (field in cols) {
Expand Down Expand Up @@ -219,8 +219,8 @@ export function useSqliteTable<

/** Update content `obj` of row with `id` */
function update(id: number | string, obj: Partial<ColFullType>): SqliteRunResult {
const fields:string[] = []
const values:Primitive[] = []
const fields: string[] = []
const values: Primitive[] = []
for (const field of sortedFields) {
if (field in obj) {
fields.push(`${field}=?`)
Expand All @@ -242,8 +242,8 @@ export function useSqliteTable<
throw new Error(`Field ${row} has to be part of object ${obj}`)
}

const fields:string[] = []
const values:Primitive[] = []
const fields: string[] = []
const values: Primitive[] = []
for (const field of sortedFields) {
if (field in obj) {
fields.push(field)
Expand All @@ -263,8 +263,8 @@ export function useSqliteTable<

/** Update multiple fields `where` condition */
function updateWhere(where: string, obj: Partial<ColType>): SqliteRunResult {
const fields:string[] = []
const values:Primitive[] = []
const fields: string[] = []
const values: Primitive[] = []
for (const field of sortedFields) {
if (field in obj) {
fields.push(`${field}=?`)
Expand Down
3 changes: 2 additions & 1 deletion zerva-websocket/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import type { LogLevelAliasType, LoggerInterface } from 'zeed'
import { Channel, Logger, createPromise, equalBinary, getTimestamp, isBrowser, useDispose, useEventListener } from 'zeed'
import { WebsocketData, getWebsocketUrlFromLocation, pingMessage, pongMessage, webSocketPath, wsReadyStateConnecting, wsReadyStateOpen } from './types'
import type { WebsocketData } from './types'
import { getWebsocketUrlFromLocation, pingMessage, pongMessage, webSocketPath, wsReadyStateConnecting, wsReadyStateOpen } from './types'

// See lib0 and y-websocket for initial implementation

Expand Down
6 changes: 2 additions & 4 deletions zerva-websocket/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import type { LogLevelAliasType, LoggerInterface, UseDispose } from 'zeed'
import { Channel, LogLevelInfo, Logger, equalBinary, uname, useDispose, uuid } from 'zeed'
import type { LogConfig } from '@zerva/core'
import { LoggerFromConfig, assertModules, emit, on, once, register } from '@zerva/core'
import { WebsocketData, pingMessage, pongMessage, websocketName, wsReadyStateConnecting, wsReadyStateOpen } from './types'
import type { WebsocketData } from './types'
import { pingMessage, pongMessage, websocketName, wsReadyStateConnecting, wsReadyStateOpen } from './types'

const moduleName = 'websocket'

Expand Down Expand Up @@ -105,7 +106,6 @@ export class WebsocketNodeConnection extends Channel {
isAlive = true
})

// eslint-disable-next-line ts/no-misused-promises
ws.on('message', async (data: ArrayBuffer) => {
try {
this.log(`onmessage length=${safeLength(data)} type=${safeType(data)}`)
Expand All @@ -131,7 +131,6 @@ export class WebsocketNodeConnection extends Channel {
// }
// }

// eslint-disable-next-line ts/no-misused-promises
ws.on('error', async (error) => {
this.log.error('onerror', error)
await this.dispose()
Expand All @@ -148,7 +147,6 @@ export class WebsocketNodeConnection extends Channel {
}
})

// eslint-disable-next-line ts/no-misused-promises
ws.on('close', async () => {
this.log('onclose')
await this.dispose()
Expand Down
2 changes: 2 additions & 0 deletions zerva-websocket/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import type { Channel, UseDispose } from 'zeed'

import 'ws'

export { }

export const websocketName = 'zerva-websocket'
Expand Down

0 comments on commit 4bc9569

Please sign in to comment.